UNPKG

waitlist-mailer

Version:

Modern, modular TypeScript library for managing waitlists with pluggable storage and mail providers. Supports MongoDB, SQL databases, and custom adapters with zero required dependencies for basic usage.

80 lines (76 loc) 2.68 kB
import { StorageProvider, WaitlistEntry, SearchOptions } from '../../types.mjs'; /** * MongoDB Mongoose storage adapter for waitlist-mailer. * Provides persistent storage using Mongoose ODM. * Requires: mongoose peer dependency */ interface MongooseStorageConfig { /** Mongoose model instance */ model: any; /** Whether to use lowercase for email normalization */ normalizeEmail?: boolean; } /** * Mongoose-based storage provider implementation. * Requires mongoose to be installed separately. * @template T - Optional metadata type */ declare class MongooseStorage<T = any> implements StorageProvider<T> { private model; private normalizeEmail; /** * Create a new MongooseStorage instance. * @param config - Configuration object with mongoose model * @throws {Error} If mongoose is not installed or model is invalid */ constructor(config: MongooseStorageConfig); private normalizeEmailAddress; /** * Add an email to MongoDB. * @param email - The email to add * @param data - Optional metadata * @throws {Error} If the email already exists or database operation fails */ add(email: string, data?: T): Promise<void>; /** * Remove an email from MongoDB. * @param email - The email to remove * @returns true if the email was found and removed */ remove(email: string): Promise<boolean>; /** * Check if an email exists in MongoDB. * @param email - The email to check * @returns true if the email exists */ exists(email: string): Promise<boolean>; /** * Retrieve all entries from MongoDB. * @returns Array of all WaitlistEntry objects */ getAll(): Promise<WaitlistEntry<T>[]>; /** * Count total entries in MongoDB. * @returns Number of entries */ count(): Promise<number>; /** * Clear all entries from MongoDB. */ clear(): Promise<void>; /** * Search entries by email pattern using MongoDB $regex. * Delegates filtering to MongoDB for optimal performance. * @param pattern - The pattern to search for * @param options - Optional search options * @returns Matching entries */ search(pattern: string, options?: SearchOptions): Promise<WaitlistEntry<T>[]>; /** * Iterate over entries using MongoDB cursor for memory-efficient streaming. * Uses Mongoose cursor to avoid loading all documents into memory. * @param batchSize - Number of entries per batch (default: 100) */ iterate(batchSize?: number): AsyncIterableIterator<WaitlistEntry<T>>; } export { MongooseStorage, type MongooseStorageConfig };