UNPKG

@elsikora/nestjs-crud-automator

Version:

A library for automating the creation of CRUD operations in NestJS.

38 lines (36 loc) 1.27 kB
const AUTO_DTO_CONTEXT_QUEUE = new WeakMap(); /** * Executes and clears all queued handlers that were waiting for the DTO context on the specified prototype. * @param {object} target - DTO prototype whose queued handlers should run. */ function FlushAutoDtoContextExecutions(target) { const queue = AUTO_DTO_CONTEXT_QUEUE.get(target); if (!queue) return; AUTO_DTO_CONTEXT_QUEUE.delete(target); for (const handler of queue.values()) { try { handler(); } catch { // ignore to avoid breaking other handlers } } } /** * Queues a handler to run once the DTO context becomes available for the specified prototype. * @param {object} target - DTO prototype awaiting context. * @param {() => void} handler - Callback to execute after context is defined. */ function QueueAutoDtoContextExecution(target, handler) { if (!target || typeof handler !== "function") return; let queue = AUTO_DTO_CONTEXT_QUEUE.get(target); if (!queue) { queue = new Set(); AUTO_DTO_CONTEXT_QUEUE.set(target, queue); } queue.add(handler); } export { FlushAutoDtoContextExecutions, QueueAutoDtoContextExecution }; //# sourceMappingURL=auto-dto-context-queue.utility.js.map