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.
66 lines (62 loc) • 2.11 kB
TypeScript
import { StorageProvider, WaitlistEntry, SearchOptions } from '../../types.js';
/**
* In-memory storage adapter for waitlist-mailer.
* Perfect for development, testing, and small-scale applications.
* Data is lost when the process terminates.
*/
/**
* Memory-based storage provider implementation.
* No external dependencies required. Ideal for development and testing.
* @template T - Optional metadata type
*/
declare class MemoryStorage<T = any> implements StorageProvider<T> {
private storage;
/**
* Add an email to memory storage.
* @param email - The email to add
* @param data - Optional metadata
* @throws {Error} If the email already exists
*/
add(email: string, data?: T): Promise<void>;
/**
* Remove an email from memory storage.
* @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 storage.
* @param email - The email to check
* @returns true if the email exists
*/
exists(email: string): Promise<boolean>;
/**
* Retrieve all entries from storage.
* @returns Array of all WaitlistEntry objects
*/
getAll(): Promise<WaitlistEntry<T>[]>;
/**
* Count total entries in storage.
* @returns Number of entries
*/
count(): Promise<number>;
/**
* Clear all entries from storage.
*/
clear(): Promise<void>;
/**
* Search entries by email pattern.
* For MemoryStorage, this filters the in-memory Map.
* @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 in batches.
* For MemoryStorage, yields entries from the in-memory Map.
* @param batchSize - Number of entries per batch (default: 100)
*/
iterate(batchSize?: number): AsyncIterableIterator<WaitlistEntry<T>>;
}
export { MemoryStorage };