@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
37 lines (34 loc) • 1.32 kB
JavaScript
import { AUTO_CONTEXT_DTO_CONSTANT } from '../../../../constant/dto/auto-context.constant.js';
import { GetRegisteredAutoDtoChildren } from '../../../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?.(AUTO_CONTEXT_DTO_CONSTANT.METADATA_KEY, target);
if (stack && stack.length > 0) {
stack.pop();
if (stack.length === 0) {
Reflect.deleteMetadata?.(AUTO_CONTEXT_DTO_CONSTANT.METADATA_KEY, target);
}
else {
Reflect.defineMetadata?.(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 = GetRegisteredAutoDtoChildren(target);
if (!children)
return;
for (const child of children) {
DtoAutoContextPop(child.prototype, visited);
}
}
export { DtoAutoContextPop };
//# sourceMappingURL=pop.utility.js.map