UNPKG

@elsikora/nestjs-crud-automator

Version:

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

50 lines (47 loc) 1.9 kB
import '../constant/decorator/api/function.constant.js'; import { PROPERTY_DESCRIBE_DECORATOR_API_CONSTANT } from '../constant/decorator/api/property-describe.constant.js'; class MetadataStorage { static instance; STORAGE = new Map(); static getInstance() { if (!MetadataStorage.instance) { MetadataStorage.instance = new MetadataStorage(); } return MetadataStorage.instance; } getAllEntitiesMetadata() { const result = {}; for (const [entityName, entityMetadata] of this.STORAGE.entries()) { result[entityName] = Object.fromEntries(entityMetadata); } return result; } getMetadata(entityName, propertyName, key) { const entityMetadata = this.STORAGE.get(entityName); if (!entityMetadata) return undefined; if (!propertyName) return Object.fromEntries(entityMetadata); const propertyMetadata = entityMetadata.get(propertyName); if (!propertyMetadata) return undefined; if (!key) return propertyMetadata; return propertyMetadata[key]; } setMetadata(entityName, propertyName, key, value) { if (!this.STORAGE.has(entityName)) { this.STORAGE.set(entityName, new Map()); } // eslint-disable-next-line @elsikora/typescript/no-non-null-assertion const entityMetadata = this.STORAGE.get(entityName); if (!entityMetadata.has(propertyName)) { entityMetadata.set(propertyName, { [PROPERTY_DESCRIBE_DECORATOR_API_CONSTANT.METADATA_KEY]: {} }); } // eslint-disable-next-line @elsikora/typescript/no-non-null-assertion const propertyMetadata = entityMetadata.get(propertyName); propertyMetadata[key] = value; } } export { MetadataStorage }; //# sourceMappingURL=metadata-storage.class.js.map