UNPKG

@allgemein/schema-api

Version:
50 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SchemaRef = void 0; const lodash_1 = require("lodash"); const AbstractRef_1 = require("./AbstractRef"); const Constants_1 = require("./Constants"); const RegistryFactory_1 = require("./registry/RegistryFactory"); class SchemaRef extends AbstractRef_1.AbstractRef { constructor(options = { name: 'default' }) { super(Constants_1.METATYPE_SCHEMA, options.name, null, options.namespace); this.setOptions(options); } id() { return this.name.toLowerCase(); } getRegistry() { return RegistryFactory_1.RegistryFactory.get(this.namespace); } getClassRefFor(object, type) { return this.getRegistry().getClassRefFor(object, type); } getEntityRefFor(value) { return this.getRegistry() .find(Constants_1.METATYPE_ENTITY, (b) => { let schemaCheck = false; if ((0, lodash_1.isString)(value)) { schemaCheck = b.name === value || b.getClassRef().name === value; } else if ((0, lodash_1.isFunction)(value)) { schemaCheck = b.getClass() === value; } if (schemaCheck) { let schemas = b.getOptions('schema'); schemas = schemas ? schemas : []; return schemas.includes(this.name); } return false; }); } getEntityRefs() { return this.getRegistry() .filter(Constants_1.METATYPE_ENTITY, (b) => { let schemas = b.getOptions('schema'); schemas = schemas ? schemas : []; return schemas.includes(this.name); }); } } exports.SchemaRef = SchemaRef; //# sourceMappingURL=SchemaRef.js.map