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.
64 lines (62 loc) • 1.48 kB
JavaScript
// lib/adapters/storage/MemoryStorage.ts
var MemoryStorage = class {
constructor() {
this.storage = /* @__PURE__ */ new Map();
}
/**
* Add an email to memory storage.
* @param email - The email to add
* @param data - Optional metadata
* @throws {Error} If the email already exists
*/
async add(email, data) {
const normalized = email.toLowerCase();
if (this.storage.has(normalized)) {
throw new Error(`Email already exists: ${email}`);
}
this.storage.set(normalized, {
email,
metadata: data,
createdAt: /* @__PURE__ */ new Date()
});
}
/**
* Remove an email from memory storage.
* @param email - The email to remove
* @returns true if the email was found and removed
*/
async remove(email) {
return this.storage.delete(email.toLowerCase());
}
/**
* Check if an email exists in storage.
* @param email - The email to check
* @returns true if the email exists
*/
async exists(email) {
return this.storage.has(email.toLowerCase());
}
/**
* Retrieve all entries from storage.
* @returns Array of all WaitlistEntry objects
*/
async getAll() {
return Array.from(this.storage.values());
}
/**
* Count total entries in storage.
* @returns Number of entries
*/
async count() {
return this.storage.size;
}
/**
* Clear all entries from storage.
*/
async clear() {
this.storage.clear();
}
};
export {
MemoryStorage
};