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.

112 lines 4.07 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.createMongooseAdapter = void 0; const createMongooseAdapter = (config) => { class LazyMongooseAdapter { cfg; _inner = null; _loading = null; constructor(cfg) { this.cfg = cfg; void this.ensureLoaded(); } async ensureLoaded() { if (this._inner != null) return; if (this._loading != null) { await this._loading; return; } this._loading = (async () => { try { const mod = await Promise.resolve().then(() => __importStar(require('./adapter'))); this._inner = new mod.MongooseAdapter(this.cfg); } catch (err) { const e = err instanceof Error ? err : new Error(String(err)); throw new Error(`Failed to load Mongoose adapter. Ensure 'mongoose' is installed. Original error: ${e.message}`); } })(); await this._loading; } get inner() { if (this._inner == null) { throw new Error('MongooseAdapter is not yet loaded. Await any async repository method (findById, create, etc.) before accessing the adapter directly.'); } return this._inner; } get model() { return this.inner.model; } async initialize() { await this.ensureLoaded(); const withInit = this.inner; await withInit.initialize(); } toLean(input) { if (this._inner != null) return this._inner.toLean(input); return null; } async findById(id) { await this.ensureLoaded(); return this.inner.findById(id); } async findMany(filter = {}) { await this.ensureLoaded(); return this.inner.findMany(filter); } async create(entity) { await this.ensureLoaded(); return this.inner.create(entity); } async update(id, update) { await this.ensureLoaded(); return this.inner.update(id, update); } async delete(id) { await this.ensureLoaded(); return this.inner.delete(id); } async exists(id) { await this.ensureLoaded(); return this.inner.exists(id); } } return new LazyMongooseAdapter(config); }; exports.createMongooseAdapter = createMongooseAdapter; //# sourceMappingURL=adapter-loader.js.map