UNPKG

@elsikora/nestjs-crud-automator

Version:

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

29 lines (26 loc) 1.35 kB
import { DeferPropertyDecoratorExecution } from './defer-property-decorator-execution.utility.js'; import { ErrorException } from './error/exception.utility.js'; import { TryResolvePropertyEntity } from './resolve/property-entity.utility.js'; /** * Executes the provided callback once the entity reference resolves. * If the entity cannot be resolved immediately, the callback runs in a microtask after modules finish loading. * @param {TApiPropertyEntity} entity - Entity reference or resolver. * @param {string} decoratorName - Decorator name for error context. * @param {(resolved: IApiBaseEntity | Type<IApiBaseEntity>) => void} onResolved - Callback executed with the resolved entity. */ function WithResolvedPropertyEntity(entity, decoratorName, onResolved) { const resolved = TryResolvePropertyEntity(entity); if (resolved) { onResolved(resolved); return; } DeferPropertyDecoratorExecution(() => { const deferredResolved = TryResolvePropertyEntity(entity); if (!deferredResolved) { throw ErrorException(`Entity for ${decoratorName} could not be resolved. Provide the entity class or a factory that returns it.`); } onResolved(deferredResolved); }); } export { WithResolvedPropertyEntity }; //# sourceMappingURL=with-resolved-property-entity.utility.js.map