UNPKG

@sentzunhat/zacatl

Version:

A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.

69 lines 2.52 kB
export const createSequelizeAdapter = (config) => { class LazySequelizeAdapter { cfg; model; loaded = null; constructor(cfg) { this.cfg = cfg; this.model = cfg.model; } async load() { if (this.loaded) return this.loaded; this.loaded = (async () => { try { const mod = await import('./adapter.js'); return new mod.SequelizeAdapter(this.cfg); } catch (err) { const e = err instanceof Error ? err : new Error(String(err)); throw new Error(`Failed to load Sequelize adapter. Ensure optional dependency 'sequelize' and its dialect packages are installed. Original error: ${e.message}`); } })(); return this.loaded; } toLean(input) { if (input == null) return null; const maybeWithGet = input; const plain = typeof maybeWithGet.get === 'function' ? maybeWithGet.get({ plain: true }) : input; const idValue = plain['id'] ?? plain['_id']; const createdAtValue = plain['createdAt']; const updatedAtValue = plain['updatedAt']; return { ...plain, id: idValue !== undefined && idValue !== null ? String(idValue) : '', createdAt: createdAtValue != null ? new Date(createdAtValue) : new Date(), updatedAt: updatedAtValue != null ? new Date(updatedAtValue) : new Date(), }; } async findById(id) { const real = await this.load(); return real.findById(id); } async findMany(filter = {}) { const real = await this.load(); return real.findMany(filter); } async create(entity) { const real = await this.load(); return real.create(entity); } async update(id, update) { const real = await this.load(); return real.update(id, update); } async delete(id) { const real = await this.load(); return real.delete(id); } async exists(id) { const real = await this.load(); return real.exists(id); } } return new LazySequelizeAdapter(config); }; //# sourceMappingURL=adapter-loader.js.map