@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
31 lines (27 loc) • 1.5 kB
JavaScript
;
var deferPropertyDecoratorExecution_utility = require('./defer-property-decorator-execution.utility.js');
var exception_utility = require('./error/exception.utility.js');
var propertyEntity_utility = require('./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 = propertyEntity_utility.TryResolvePropertyEntity(entity);
if (resolved) {
onResolved(resolved);
return;
}
deferPropertyDecoratorExecution_utility.DeferPropertyDecoratorExecution(() => {
const deferredResolved = propertyEntity_utility.TryResolvePropertyEntity(entity);
if (!deferredResolved) {
throw exception_utility.ErrorException(`Entity for ${decoratorName} could not be resolved. Provide the entity class or a factory that returns it.`);
}
onResolved(deferredResolved);
});
}
exports.WithResolvedPropertyEntity = WithResolvedPropertyEntity;
//# sourceMappingURL=with-resolved-property-entity.utility.js.map