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.
88 lines (84 loc) • 3.14 kB
text/typescript
import { StorageProvider, WaitlistEntry, SearchOptions } from '../../types.mjs';
/**
* Sequelize-based storage adapter for waitlist-mailer.
* Supports PostgreSQL, MySQL, and SQLite through Sequelize ORM.
* Requires: sequelize, mysql2 (for MySQL), or pg (for PostgreSQL) as peer dependencies
*/
interface SequelizeStorageConfig {
/** Sequelize model instance representing the waitlist table */
model: any;
/** Whether to use lowercase for email normalization */
normalizeEmail?: boolean;
}
/**
* Sequelize-based storage provider implementation.
* Works with PostgreSQL, MySQL, and SQLite.
* Requires sequelize to be installed separately.
* @template T - Optional metadata type
*/
declare class SequelizeStorage<T = any> implements StorageProvider<T> {
private model;
private normalizeEmail;
/**
* Create a new SequelizeStorage instance.
* @param config - Configuration object with sequelize model
* @throws {Error} If sequelize is not installed or model is invalid
*/
constructor(config: SequelizeStorageConfig);
private normalizeEmailAddress;
/**
* Add an email to the database.
* @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 the database.
* @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 the database.
* @param email - The email to check
* @returns true if the email exists
*/
exists(email: string): Promise<boolean>;
/**
* Retrieve all entries from the database.
* @returns Array of all WaitlistEntry objects
*/
getAll(): Promise<WaitlistEntry<T>[]>;
/**
* Count total entries in the database.
* @returns Number of entries
*/
count(): Promise<number>;
/**
* Clear all entries from the database.
*/
clear(): Promise<void>;
/**
* Search entries by email pattern using SQL LIKE/ILIKE.
* Delegates filtering to the database 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>[]>;
/**
* Safely parse metadata JSON with validation.
* Prevents potential issues from malformed or malicious JSON.
* @param metadata - Raw metadata string from database
* @returns Parsed metadata or undefined
*/
private safeParseMetadata;
/**
* Iterate over entries using Sequelize pagination for memory-efficient streaming.
* Uses limit/offset pagination to avoid loading all records into memory.
* @param batchSize - Number of entries per batch (default: 100)
*/
iterate(batchSize?: number): AsyncIterableIterator<WaitlistEntry<T>>;
}
export { SequelizeStorage, type SequelizeStorageConfig };