@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
39 lines (35 loc) • 1.44 kB
JavaScript
;
var autoContext_constant = require('../../../../constant/dto/auto-context.constant.js');
var registerAutoDtoChild_utility = require('../../../register-auto-dto-child.utility.js');
/**
* Pops DTO auto-context from the provided DTO prototype.
* @param {object} target - DTO prototype to update.
* @param {WeakSet<object>} [visited] - Set of visited prototypes to avoid infinite recursion.
*/
function DtoAutoContextPop(target, visited) {
if (!target)
return;
const stack = Reflect.getMetadata?.(autoContext_constant.AUTO_CONTEXT_DTO_CONSTANT.METADATA_KEY, target);
if (stack && stack.length > 0) {
stack.pop();
if (stack.length === 0) {
Reflect.deleteMetadata?.(autoContext_constant.AUTO_CONTEXT_DTO_CONSTANT.METADATA_KEY, target);
}
else {
Reflect.defineMetadata?.(autoContext_constant.AUTO_CONTEXT_DTO_CONSTANT.METADATA_KEY, stack, target);
}
}
visited ??= new WeakSet();
if (visited.has(target))
return;
visited.add(target);
// eslint-disable-next-line @elsikora/typescript/no-unsafe-function-type
const children = registerAutoDtoChild_utility.GetRegisteredAutoDtoChildren(target);
if (!children)
return;
for (const child of children) {
DtoAutoContextPop(child.prototype, visited);
}
}
exports.DtoAutoContextPop = DtoAutoContextPop;
//# sourceMappingURL=pop.utility.js.map