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.

106 lines 4.09 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.createSequelizeAdapter = void 0; 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 Promise.resolve().then(() => __importStar(require('./adapter'))); 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); }; exports.createSequelizeAdapter = createSequelizeAdapter; //# sourceMappingURL=adapter-loader.js.map