UNPKG

@allgemein/schema-api

Version:
143 lines 3.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractRegistry = void 0; const lodash_1 = require("lodash"); const Constants_1 = require("./../Constants"); const LookupRegistry_1 = require("../LookupRegistry"); const base_1 = require("@allgemein/base"); /** * Registry for metadata of classes and there properties */ class AbstractRegistry { constructor(namespace, options) { this.namespace = namespace; this.options = options || {}; } get lock() { if (!this._lock) { this._lock = base_1.LockFactory.$().semaphore(1); } return this._lock; } ready(timeout) { return this.lock.await(timeout).then(x => true).catch(x => false); } getOptions() { return this.options; } /** * Return all registered schema references * * @param ref * @return ISchemaRef[] */ getSchemaRefs(filter) { throw new base_1.NotSupportedError(''); } getSchemaRefsFor(ref) { throw new base_1.NotSupportedError(''); } /** * TODO * * @param filter */ getEntityRefs(filter) { return this.filter(Constants_1.METATYPE_ENTITY, filter); } /** * Can get get entity ref for function. * * @param fn */ getEntityRefFor(fn, skipNsCheck = true) { throw new base_1.NotSupportedError(''); } /** * Returns the used instance of lookup registry handler */ getLookupRegistry(namespace = null) { return LookupRegistry_1.LookupRegistry.$(namespace ? namespace : this.namespace); } /** * Method for returning class ref * * @param object * @param type */ getClassRefFor(object, type) { throw new base_1.NotSupportedError(''); } /** * Returns property by name for a given class or entity ref * * @param filter */ getPropertyRef(ref, name) { return this.getPropertyRefs(ref).find(x => (0, lodash_1.snakeCase)(x.name) === (0, lodash_1.snakeCase)(name)); } /** * Returns all properties for given class or entity ref * * @param ref */ getPropertyRefs(ref) { throw new base_1.NotSupportedError(''); } getPropertyRefsFor(fn) { throw new base_1.NotSupportedError(''); } list(type, filter) { return this.filter(type, filter); } listEntities(filter) { return this.getEntityRefs(filter); } listProperties(filter) { return this.filter(Constants_1.METATYPE_PROPERTY, filter); } create(context, options) { throw new base_1.NotSupportedError(''); } /** * TODO */ add(context, entry, ns) { return this.getLookupRegistry(ns).add(context, entry); } /** * TODO */ filter(context, search, ns) { return this.getLookupRegistry(ns).filter(context, search); } /** * TODO */ find(context, search, ns) { return this.getLookupRegistry(ns).find(context, search); } /** * TODO */ remove(context, search, ns) { return this.getLookupRegistry(ns).remove(context, search); } /** * reset current registry */ reset() { this.clear(); } /** * Remove namespace from LookupRegistry and also remove semaphore lock if exists */ clear() { if (this._lock) { base_1.LockFactory.$().remove(this._lock); } LookupRegistry_1.LookupRegistry.reset(this.namespace); } } exports.AbstractRegistry = AbstractRegistry; //# sourceMappingURL=AbstractRegistry.js.map