UNPKG

@allgemein/schema-api

Version:
60 lines 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DefaultEntityRef = void 0; const AbstractRef_1 = require("../AbstractRef"); const Constants_1 = require("../Constants"); const AnnotationsHelper_1 = require("../AnnotationsHelper"); const RegistryFactory_1 = require("./RegistryFactory"); class DefaultEntityRef extends AbstractRef_1.AbstractRef { constructor(options = {}) { super(Constants_1.METATYPE_ENTITY, options.name, options.target, options.namespace ? options.namespace : Constants_1.DEFAULT_NAMESPACE); AnnotationsHelper_1.AnnotationsHelper.merge(this.object, options); this.additionalProperties(options); this.setOptions(options); } additionalProperties(options) { const cls = this.getSourceRef().getClass(); if (cls) { Constants_1.DEFINED_PROPS_TO_OPTS.forEach(k => { const p = Object.getOwnPropertyDescriptor(cls, k); if (p) { options[k] = p.value; } }); } } getSchemaRefs() { return this.getRegistry().getSchemaRefsFor(this); } getRegistry() { return RegistryFactory_1.RegistryFactory.get(this.namespace); } build(instance, options) { return this.getClassRef().build(instance, options); } create(addinfo) { return this.getClassRef().create(addinfo); } getPropertyRef(name) { return this.getRegistry().getPropertyRef(this, name); } getPropertyRefs() { return this.getRegistry().getPropertyRefs(this); } id() { return [Constants_1.METATYPE_ENTITY, this.getClassRef().id()].join(Constants_1.XS_ID_SEPARATOR); } getClassRefFor(object, type) { return this.getRegistry().getClassRefFor(object, this.metaType); } /** * Check if an object / instance is of same type like this entity ref (same check as IClassRef.isOf). * * @param instance */ isOf(instance) { return this.getClassRef().isOf(instance); } } exports.DefaultEntityRef = DefaultEntityRef; //# sourceMappingURL=DefaultEntityRef.js.map