@allgemein/schema-api 1.5.0 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/ILookupRegistry.d.ts +1 -0
- package/api/ILookupRegistry.js +4 -4
- package/api/ILookupRegistry.js.map +1 -1
- package/decorators/Property.js +6 -6
- package/decorators/Property.js.map +1 -1
- package/decorators/PropertyOf.js +1 -1
- package/decorators/PropertyOf.js.map +1 -1
- package/decorators/validate/Hostname.js +3 -3
- package/decorators/validate/Hostname.js.map +1 -1
- package/decorators/validate/Ip4.js +3 -3
- package/decorators/validate/Ip4.js.map +1 -1
- package/decorators/validate/Ip6.js +3 -3
- package/decorators/validate/Ip6.js.map +1 -1
- package/decorators/validate/IsEmail.js +2 -2
- package/decorators/validate/IsEmail.js.map +1 -1
- package/decorators/validate/IsNotEmpty.js +5 -5
- package/decorators/validate/IsNotEmpty.js.map +1 -1
- package/decorators/validate/MaxLength.js +3 -3
- package/decorators/validate/MaxLength.js.map +1 -1
- package/decorators/validate/MinLength.js +3 -3
- package/decorators/validate/MinLength.js.map +1 -1
- package/decorators/validate/Regex.js +7 -4
- package/decorators/validate/Regex.js.map +1 -1
- package/decorators/validate/Required.js +3 -3
- package/decorators/validate/Required.js.map +1 -1
- package/lib/AbstractRef.js +9 -9
- package/lib/AbstractRef.js.map +1 -1
- package/lib/AnnotationsHelper.js +13 -13
- package/lib/AnnotationsHelper.js.map +1 -1
- package/lib/ClassRef.js +18 -18
- package/lib/ClassRef.js.map +1 -1
- package/lib/Constants.d.ts +4 -0
- package/lib/Constants.js +5 -1
- package/lib/Constants.js.map +1 -1
- package/lib/DataContainer.js +9 -9
- package/lib/DataContainer.js.map +1 -1
- package/lib/LookupRegistry.js +13 -13
- package/lib/LookupRegistry.js.map +1 -1
- package/lib/SchemaRef.js +2 -2
- package/lib/SchemaRef.js.map +1 -1
- package/lib/SchemaUtils.js +11 -11
- package/lib/SchemaUtils.js.map +1 -1
- package/lib/json-schema/IJsonSchemaSerializeOptions.d.ts +5 -0
- package/lib/json-schema/IJsonSchemaSerializeOptions.js.map +1 -1
- package/lib/json-schema/JsonSchema.js +6 -6
- package/lib/json-schema/JsonSchema.js.map +1 -1
- package/lib/json-schema/JsonSchema7Serializer.d.ts +1 -0
- package/lib/json-schema/JsonSchema7Serializer.js +46 -33
- package/lib/json-schema/JsonSchema7Serializer.js.map +1 -1
- package/lib/json-schema/JsonSchema7Unserializer.js +50 -50
- package/lib/json-schema/JsonSchema7Unserializer.js.map +1 -1
- package/lib/options/IPropertyOptions.d.ts +4 -0
- package/lib/options/IPropertyOptions.js.map +1 -1
- package/lib/registry/AbstractRegistry.d.ts +7 -1
- package/lib/registry/AbstractRegistry.js +10 -2
- package/lib/registry/AbstractRegistry.js.map +1 -1
- package/lib/registry/DefaultEntityRef.js +1 -1
- package/lib/registry/DefaultEntityRef.js.map +1 -1
- package/lib/registry/DefaultNamespacedRegistry.d.ts +10 -1
- package/lib/registry/DefaultNamespacedRegistry.js +135 -86
- package/lib/registry/DefaultNamespacedRegistry.js.map +1 -1
- package/lib/registry/DefaultPropertyRef.js +26 -20
- package/lib/registry/DefaultPropertyRef.js.map +1 -1
- package/lib/registry/IRegistryOptions.d.ts +8 -0
- package/lib/registry/IRegistryOptions.js +4 -0
- package/lib/registry/IRegistryOptions.js.map +1 -0
- package/lib/registry/MetadataRegistry.d.ts +14 -0
- package/lib/registry/MetadataRegistry.js +32 -18
- package/lib/registry/MetadataRegistry.js.map +1 -1
- package/lib/registry/RegistryFactory.d.ts +2 -1
- package/lib/registry/RegistryFactory.js +10 -10
- package/lib/registry/RegistryFactory.js.map +1 -1
- package/lib/validation/DefaultValidator.js +19 -19
- package/lib/validation/DefaultValidator.js.map +1 -1
- package/lib/validation/Validator.js +2 -2
- package/lib/validation/Validator.js.map +1 -1
- package/package.json +17 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/options/IPropertyOptions.ts"],"names":[],"mappings":"","file":"IPropertyOptions.js","sourcesContent":["import {JS_DATA_TYPES} from '../../lib/Constants';\nimport {IAbstractOptions} from './IAbstractOptions';\n\nexport interface IPropertyOptions extends IAbstractOptions {\n\n propertyName?: string;\n\n appended?: boolean;\n\n cardinality?: number | { min: number, max: number };\n\n format?: string;\n\n type?: JS_DATA_TYPES | any;\n\n /**\n * Mark if value is representation of unique identifier\n */\n identifier?: boolean;\n\n /**\n * Generate automatically values for identifier\n */\n generated?: boolean;\n\n /**\n * Mark if property is a pattern property\n */\n pattern?: boolean;\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/options/IPropertyOptions.ts"],"names":[],"mappings":"","file":"IPropertyOptions.js","sourcesContent":["import {JS_DATA_TYPES} from '../../lib/Constants';\nimport {IAbstractOptions} from './IAbstractOptions';\n\nexport interface IPropertyOptions extends IAbstractOptions {\n\n propertyName?: string;\n\n appended?: boolean;\n\n cardinality?: number | { min: number, max: number };\n\n format?: string;\n\n type?: JS_DATA_TYPES | any;\n\n /**\n * Mark if value is representation of unique identifier\n */\n identifier?: boolean;\n\n /**\n * Generate automatically values for identifier\n */\n generated?: boolean;\n\n /**\n * Mark if property is a pattern property\n */\n pattern?: boolean;\n\n\n /**\n * Mark if property is an array\n */\n array?: boolean;\n}\n"],"sourceRoot":"../.."}
|
|
@@ -6,13 +6,19 @@ import { IEntityRef } from '../../api/IEntityRef';
|
|
|
6
6
|
import { IClassRef } from '../../api/IClassRef';
|
|
7
7
|
import { IPropertyRef } from '../../api/IPropertyRef';
|
|
8
8
|
import { LookupRegistry } from '../LookupRegistry';
|
|
9
|
+
import { Semaphore } from '@allgemein/base';
|
|
9
10
|
import { ISchemaRef } from '../../api/ISchemaRef';
|
|
11
|
+
import { IRegistryOptions } from './IRegistryOptions';
|
|
10
12
|
/**
|
|
11
13
|
* Registry for metadata of classes and there properties
|
|
12
14
|
*/
|
|
13
15
|
export declare abstract class AbstractRegistry extends EventEmitter implements ILookupRegistry {
|
|
14
16
|
protected readonly namespace: string;
|
|
15
|
-
|
|
17
|
+
readonly lock: Semaphore;
|
|
18
|
+
readonly options: IRegistryOptions;
|
|
19
|
+
constructor(namespace: string, options?: IRegistryOptions);
|
|
20
|
+
ready(timeout?: number): Promise<boolean>;
|
|
21
|
+
getOptions(): IRegistryOptions;
|
|
16
22
|
/**
|
|
17
23
|
* Return all registered schema references
|
|
18
24
|
*
|
|
@@ -10,9 +10,14 @@ const base_1 = require("@allgemein/base");
|
|
|
10
10
|
* Registry for metadata of classes and there properties
|
|
11
11
|
*/
|
|
12
12
|
class AbstractRegistry extends events_1.EventEmitter {
|
|
13
|
-
constructor(namespace) {
|
|
13
|
+
constructor(namespace, options) {
|
|
14
14
|
super();
|
|
15
15
|
this.namespace = namespace;
|
|
16
|
+
this.options = options || {};
|
|
17
|
+
this.lock = base_1.LockFactory.$().semaphore(1);
|
|
18
|
+
}
|
|
19
|
+
ready(timeout) {
|
|
20
|
+
return this.lock.await(timeout).then(x => true).catch(x => false);
|
|
16
21
|
}
|
|
17
22
|
// /**
|
|
18
23
|
// * Initialize events for metadata changes on runtime
|
|
@@ -22,6 +27,9 @@ class AbstractRegistry extends events_1.EventEmitter {
|
|
|
22
27
|
// MetadataRegistry.$().on(C_EVENT_REMOVE, this.onRemove.bind(this));
|
|
23
28
|
// MetadataRegistry.$().on(C_EVENT_UPDATE, this.onUpdate.bind(this));
|
|
24
29
|
// }
|
|
30
|
+
getOptions() {
|
|
31
|
+
return this.options;
|
|
32
|
+
}
|
|
25
33
|
/**
|
|
26
34
|
* Return all registered schema references
|
|
27
35
|
*
|
|
@@ -71,7 +79,7 @@ class AbstractRegistry extends events_1.EventEmitter {
|
|
|
71
79
|
* @param filter
|
|
72
80
|
*/
|
|
73
81
|
getPropertyRef(ref, name) {
|
|
74
|
-
return this.getPropertyRefs(ref).find(x => lodash_1.snakeCase(x.name) === lodash_1.snakeCase(name));
|
|
82
|
+
return this.getPropertyRefs(ref).find(x => (0, lodash_1.snakeCase)(x.name) === (0, lodash_1.snakeCase)(name));
|
|
75
83
|
}
|
|
76
84
|
/**
|
|
77
85
|
* Returns all properties for given class or entity ref
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/registry/AbstractRegistry.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AACjC,mCAAoC;AACpC,8CAAiF;AAKjF,sDAAiD;AACjD,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/registry/AbstractRegistry.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AACjC,mCAAoC;AACpC,8CAAiF;AAKjF,sDAAiD;AACjD,0CAA0E;AAK1E;;GAEG;AACH,MAAsB,gBAAiB,SAAQ,qBAAY;IASzD,YAAY,SAAiB,EAAE,OAA0B;QACvD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,kBAAW,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,OAAgB;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC;IAED,MAAM;IACN,uDAAuD;IACvD,MAAM;IACN,cAAc;IACd,iEAAiE;IACjE,uEAAuE;IACvE,uEAAuE;IACvE,IAAI;IAGJ,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,aAAa,CAAuB,MAAmC;QACrE,MAAM,IAAI,wBAAiB,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;IASD,gBAAgB,CAAuB,GAAoC;QACzE,MAAM,IAAI,w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AE,MAAM,CAAC,CAAC;IAChD,CAAC;IAGD,MAAM,CAAI,OAAe,EAAE,OAAY;QACrC,MAAM,IAAI,wBAAiB,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,GAAG,CAAI,OAAe,EAAE,KAAQ;QAC9B,OAAO,IAAI,CAAC,iBAAiB,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAGD;;OAEG;IACH,MAAM,CAAI,OAAe,EAAE,MAAW;QACpC,OAAO,IAAI,CAAC,iBAAiB,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,IAAI,CAAI,OAAe,EAAE,MAAW;QAClC,OAAO,IAAI,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,MAAM,CAAI,OAAe,EAAE,MAAW;QACpC,OAAO,IAAI,CAAC,iBAAiB,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,KAAK;QACH,+BAAc,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;CAEF;AA/KD,4CA+KC","file":"AbstractRegistry.js","sourcesContent":["import {snakeCase} from 'lodash';\nimport {EventEmitter} from 'events';\nimport {METADATA_TYPE, METATYPE_ENTITY, METATYPE_PROPERTY} from './../Constants';\nimport {ILookupRegistry} from '../../api/ILookupRegistry';\nimport {IEntityRef} from '../../api/IEntityRef';\nimport {IClassRef} from '../../api/IClassRef';\nimport {IPropertyRef} from '../../api/IPropertyRef';\nimport {LookupRegistry} from '../LookupRegistry';\nimport {LockFactory, NotSupportedError, Semaphore} from '@allgemein/base';\nimport {ISchemaRef} from '../../api/ISchemaRef';\nimport {IRegistryOptions} from './IRegistryOptions';\n\n\n/**\n * Registry for metadata of classes and there properties\n */\nexport abstract class AbstractRegistry extends EventEmitter implements ILookupRegistry {\n\n protected readonly namespace: string;\n\n readonly lock: Semaphore;\n\n readonly options: IRegistryOptions;\n\n\n constructor(namespace: string, options?: IRegistryOptions) {\n super();\n this.namespace = namespace;\n this.options = options || {};\n this.lock = LockFactory.$().semaphore(1);\n }\n\n ready(timeout?: number): Promise<boolean> {\n return this.lock.await(timeout).then(x => true).catch(x => false);\n }\n\n // /**\n // * Initialize events for metadata changes on runtime\n // */\n // prepare() {\n // MetadataRegistry.$().on(C_EVENT_ADD, this.onAdd.bind(this));\n // MetadataRegistry.$().on(C_EVENT_REMOVE, this.onRemove.bind(this));\n // MetadataRegistry.$().on(C_EVENT_UPDATE, this.onUpdate.bind(this));\n // }\n\n\n getOptions(): IRegistryOptions {\n return this.options;\n }\n\n /**\n * Return all registered schema references\n *\n * @param ref\n * @return ISchemaRef[]\n */\n getSchemaRefs<T extends ISchemaRef>(filter?: (x: ISchemaRef) => boolean): (T | ISchemaRef)[] {\n throw new NotSupportedError('');\n }\n\n /**\n * Return schema references for an given entity or class reference\n *\n * @param ref\n * @return ISchemaRef[]\n */\n getSchemaRefsFor<T extends ISchemaRef>(ref: string): T | ISchemaRef;\n getSchemaRefsFor<T extends ISchemaRef>(ref: string | IEntityRef | IClassRef): T | ISchemaRef | (T | ISchemaRef)[] {\n throw new NotSupportedError('');\n }\n\n /**\n * TODO\n *\n * @param filter\n */\n getEntityRefs<T extends IEntityRef>(filter?: (x: IEntityRef) => boolean): (T | IEntityRef)[] {\n return this.filter(METATYPE_ENTITY, filter);\n }\n\n /**\n * Can get get entity ref for function.\n *\n * @param fn\n */\n getEntityRefFor<T extends IEntityRef>(fn: string | object | Function, skipNsCheck: boolean = true): (T | IEntityRef) {\n throw new NotSupportedError('');\n }\n\n\n /**\n * Returns the used instance of lookup registry handler\n */\n getLookupRegistry(): LookupRegistry {\n return LookupRegistry.$(this.namespace);\n }\n\n /**\n * Method for returning class ref\n *\n * @param object\n * @param type\n */\n getClassRefFor(object: string | Function | IClassRef, type: METADATA_TYPE): IClassRef {\n throw new NotSupportedError('');\n }\n\n /**\n * Returns property by name for a given class or entity ref\n *\n * @param filter\n */\n getPropertyRef<T extends IPropertyRef>(ref: IClassRef | IEntityRef, name: string): (T | IPropertyRef) {\n return this.getPropertyRefs<T>(ref).find(x => snakeCase(x.name) === snakeCase(name));\n }\n\n\n /**\n * Returns all properties for given class or entity ref\n *\n * @param ref\n */\n getPropertyRefs<T extends IPropertyRef>(ref: IClassRef | IEntityRef): (T | IPropertyRef)[] {\n throw new NotSupportedError('');\n }\n\n\n getPropertyRefsFor<T extends IPropertyRef>(fn: string | object | Function): (T | IPropertyRef)[] {\n throw new NotSupportedError('');\n }\n\n\n list<X>(type: METADATA_TYPE, filter?: (x: any) => boolean): X[] {\n return this.filter(type, filter);\n }\n\n\n listEntities(filter?: (x: IEntityRef) => boolean): IEntityRef[] {\n return this.getEntityRefs(filter);\n }\n\n\n listProperties(filter?: (x: IPropertyRef) => boolean): IPropertyRef[] {\n return this.filter(METATYPE_PROPERTY, filter);\n }\n\n\n create<T>(context: string, options: any): T {\n throw new NotSupportedError('');\n }\n\n /**\n * TODO\n */\n add<T>(context: string, entry: T): T {\n return this.getLookupRegistry().add(context, entry);\n }\n\n\n /**\n * TODO\n */\n filter<T>(context: string, search: any): T[] {\n return this.getLookupRegistry().filter(context, search);\n }\n\n /**\n * TODO\n */\n find<T>(context: string, search: any): T {\n return this.getLookupRegistry().find(context, search);\n }\n\n /**\n * TODO\n */\n remove<T>(context: string, search: any): T[] {\n return this.getLookupRegistry().remove(context, search);\n }\n\n /**\n * reset current registry\n */\n reset() {\n this.clear();\n }\n\n clear() {\n LookupRegistry.reset(this.namespace);\n }\n\n}\n"],"sourceRoot":"../.."}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/registry/Def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C,WAAW,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,CAAC;IACrC,CAAC;IAED,cAAc,CAAC,IAAY;QACzB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,EAAE;QACA,OAAO,CAAC,2BAAe,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,2BAAe,CAAC,CAAC;IAC1E,CAAC;IAED,cAAc,CAAC,MAAqC,EAAE,IAAmB;QACvE,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,QAAa;QAChB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACb,IAAI,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;SAClB;QACD,OAAO,IAAA,kBAAS,EAAC,IAAI,CAAC,CAAC;IACzB,CAAC;CAGF;AA/DD,4CA+DC","file":"DefaultEntityRef.js","sourcesContent":["import {IEntityRef} from '../../api/IEntityRef';\nimport {AbstractRef} from '../AbstractRef';\nimport {IBuildOptions} from '../../api/IBuildOptions';\nimport {IPropertyRef} from '../../api/IPropertyRef';\nimport {DEFAULT_NAMESPACE, METADATA_TYPE, METATYPE_ENTITY, XS_ID_SEPARATOR} from '../Constants';\nimport {IEntityOptions} from '../options/IEntityOptions';\nimport {IClassRef} from '../../api/IClassRef';\nimport {AnnotationsHelper} from '../AnnotationsHelper';\nimport {ILookupRegistry} from '../../api/ILookupRegistry';\nimport {RegistryFactory} from './RegistryFactory';\nimport {snakeCase} from 'lodash';\nimport {SchemaRef} from '../SchemaRef';\n\nexport class DefaultEntityRef extends AbstractRef implements IEntityRef {\n\n\n constructor(options: IEntityOptions = {}) {\n super(METATYPE_ENTITY, options.name, options.target, options.namespace ? options.namespace : DEFAULT_NAMESPACE);\n AnnotationsHelper.merge(this.object, options);\n this.setOptions(options);\n }\n\n\n getSchemaRefs(): SchemaRef | SchemaRef[] {\n return this.getRegistry().getSchemaRefsFor(this) as any;\n }\n\n getRegistry(): ILookupRegistry {\n return RegistryFactory.get(this.namespace);\n }\n\n build<T>(instance: any, options?: IBuildOptions): T {\n return this.getClassRef().build(instance, options);\n }\n\n create<T>(): T {\n return this.getClassRef().create();\n }\n\n getPropertyRef(name: string): IPropertyRef {\n return this.getRegistry().getPropertyRef(this, name);\n }\n\n getPropertyRefs(): IPropertyRef[] {\n return this.getRegistry().getPropertyRefs(this);\n }\n\n id(): string {\n return [METATYPE_ENTITY, this.getClassRef().id()].join(XS_ID_SEPARATOR);\n }\n\n getClassRefFor(object: string | Function | IClassRef, type: METADATA_TYPE): IClassRef {\n return this.getRegistry().getClassRefFor(object, this.metaType);\n }\n\n /**\n * Check if an object / instance is of same type like this entity ref (same check as IClassRef.isOf).\n *\n * @param instance\n */\n isOf(instance: any): boolean {\n return this.getClassRef().isOf(instance);\n }\n\n /**\n * Return machine compatible name for the entity in snake-case style.\n */\n get storingName() {\n let name = this.getOptions('name');\n if (!name) {\n name = this.name;\n }\n return snakeCase(name);\n }\n\n\n}\n"],"sourceRoot":"../.."}
|
|
@@ -11,6 +11,7 @@ import { ISchemaRef } from '../../api/ISchemaRef';
|
|
|
11
11
|
import { SchemaRef } from '../SchemaRef';
|
|
12
12
|
import { AbstractRegistry } from './AbstractRegistry';
|
|
13
13
|
import { IAbstractOptions } from '../options/IAbstractOptions';
|
|
14
|
+
import { IRegistryOptions } from './IRegistryOptions';
|
|
14
15
|
/**
|
|
15
16
|
* Registry which handles by default class, schema, embeddalbes and properties, which are not handled by a specialized registry.
|
|
16
17
|
*
|
|
@@ -26,11 +27,18 @@ import { IAbstractOptions } from '../options/IAbstractOptions';
|
|
|
26
27
|
*
|
|
27
28
|
*/
|
|
28
29
|
export declare class DefaultNamespacedRegistry extends AbstractRegistry {
|
|
30
|
+
constructor(namespace: string, options?: IRegistryOptions);
|
|
29
31
|
/**
|
|
30
32
|
* Initialize events for metadata changes on runtime
|
|
31
33
|
*/
|
|
32
34
|
prepare(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Apply already added entries to the metadata registry can be added to this registry
|
|
37
|
+
*/
|
|
33
38
|
drainAlreadyAdded(): void;
|
|
39
|
+
onMetadataAdd(context: METADATA_TYPE, options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions): Promise<void>;
|
|
40
|
+
onMetadataUpdate(context: METADATA_TYPE, options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions): Promise<void>;
|
|
41
|
+
onMetadataRemove(context: METADATA_TYPE, options: (IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions)[]): Promise<void>;
|
|
34
42
|
/**
|
|
35
43
|
* Check if object has the correct namespace for this registry handle
|
|
36
44
|
*
|
|
@@ -44,6 +52,7 @@ export declare class DefaultNamespacedRegistry extends AbstractRegistry {
|
|
|
44
52
|
* @param entries
|
|
45
53
|
*/
|
|
46
54
|
onAdd(context: METADATA_TYPE, options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions): void;
|
|
55
|
+
getOrCreateSchemaRefByName(options: ISchemaOptions): ISchemaRef;
|
|
47
56
|
addSchemaToEntityRef(schemaRef: string | ISchemaRef, entityRef: IEntityRef, options?: {
|
|
48
57
|
override?: boolean;
|
|
49
58
|
onlyDefault?: boolean;
|
|
@@ -61,7 +70,7 @@ export declare class DefaultNamespacedRegistry extends AbstractRegistry {
|
|
|
61
70
|
* @param context
|
|
62
71
|
* @param entries
|
|
63
72
|
*/
|
|
64
|
-
onUpdate(): void;
|
|
73
|
+
onUpdate(context: METADATA_TYPE, options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions): void;
|
|
65
74
|
/**
|
|
66
75
|
* Return all registered schema references
|
|
67
76
|
*
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DefaultNamespacedRegistry = void 0;
|
|
4
13
|
/**
|
|
@@ -32,16 +41,22 @@ const AbstractRegistry_1 = require("./AbstractRegistry");
|
|
|
32
41
|
*
|
|
33
42
|
*/
|
|
34
43
|
class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
44
|
+
constructor(namespace, options) {
|
|
45
|
+
super(namespace, (0, lodash_1.defaults)(options || {}, { detectUnannotatedProperties: true }));
|
|
46
|
+
}
|
|
35
47
|
/**
|
|
36
48
|
* Initialize events for metadata changes on runtime
|
|
37
49
|
*/
|
|
38
50
|
prepare() {
|
|
39
51
|
// apply listener
|
|
40
52
|
this.drainAlreadyAdded();
|
|
41
|
-
MetadataRegistry_1.MetadataRegistry.$().on(Constants_1.C_EVENT_ADD, this.
|
|
42
|
-
MetadataRegistry_1.MetadataRegistry.$().on(Constants_1.C_EVENT_REMOVE, this.
|
|
43
|
-
MetadataRegistry_1.MetadataRegistry.$().on(Constants_1.C_EVENT_UPDATE, this.
|
|
53
|
+
MetadataRegistry_1.MetadataRegistry.$().on(Constants_1.C_EVENT_ADD, this.onMetadataAdd.bind(this));
|
|
54
|
+
MetadataRegistry_1.MetadataRegistry.$().on(Constants_1.C_EVENT_REMOVE, this.onMetadataRemove.bind(this));
|
|
55
|
+
MetadataRegistry_1.MetadataRegistry.$().on(Constants_1.C_EVENT_UPDATE, this.onMetadataUpdate.bind(this));
|
|
44
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Apply already added entries to the metadata registry can be added to this registry
|
|
59
|
+
*/
|
|
45
60
|
drainAlreadyAdded() {
|
|
46
61
|
const alreadyFired = MetadataRegistry_1.MetadataRegistry.$().getMetadata().filter(x => {
|
|
47
62
|
const v = Object.getOwnPropertyDescriptor(x, Constants_1.K_TRIGGERED);
|
|
@@ -55,6 +70,33 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
55
70
|
}
|
|
56
71
|
}
|
|
57
72
|
}
|
|
73
|
+
onMetadataAdd(context, options) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
yield this.lock.acquire();
|
|
76
|
+
this.onAdd(context, options);
|
|
77
|
+
this.lock.release();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
onMetadataUpdate(context, options) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (!this.validNamespace(options)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
yield this.lock.acquire();
|
|
86
|
+
this.onUpdate(context, options);
|
|
87
|
+
this.lock.release();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
onMetadataRemove(context, options) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
if (!this.validNamespace(options)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
yield this.lock.acquire();
|
|
96
|
+
this.onRemove(context, options);
|
|
97
|
+
this.lock.release();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
58
100
|
/**
|
|
59
101
|
* Check if object has the correct namespace for this registry handle
|
|
60
102
|
*
|
|
@@ -93,15 +135,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
93
135
|
if (!this.validNamespace(options)) {
|
|
94
136
|
return;
|
|
95
137
|
}
|
|
96
|
-
// check namespace, if not given use this as default
|
|
97
|
-
// const find = this.find(METATYPE_E, (c: IEntityRef) =>
|
|
98
|
-
// c.getClassRef().getClass() === options.target
|
|
99
|
-
// );
|
|
100
138
|
if (context === Constants_1.METATYPE_PROPERTY) {
|
|
101
|
-
// if (!!this.processing.find(x => x.target === options.target && x.propertyName === options.propertyName)) {
|
|
102
|
-
// return;
|
|
103
|
-
// }
|
|
104
|
-
// this.processing.push(options);
|
|
105
139
|
const sourceEntry = this.find(Constants_1.METATYPE_CLASS_REF, (ref) => ref.getClass() === options.target);
|
|
106
140
|
if (sourceEntry) {
|
|
107
141
|
const find = this.find(context, (c) => c.getClassRef().getClass() === options.target &&
|
|
@@ -111,14 +145,13 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
111
145
|
this.create(context, options);
|
|
112
146
|
}
|
|
113
147
|
}
|
|
114
|
-
// remove(this.processing, x => x === options);
|
|
115
148
|
}
|
|
116
149
|
else if (context === Constants_1.METATYPE_ENTITY) {
|
|
117
150
|
const find = this.find(context, (c) => c.getClassRef().getClass() === options.target);
|
|
118
151
|
if (!find) {
|
|
119
152
|
const entityRef = this.create(context, options);
|
|
120
153
|
const properties = this.find(Constants_1.METATYPE_PROPERTY, (c) => c.getClassRef().getClass() === options.target);
|
|
121
|
-
if (lodash_1.isEmpty(properties)) {
|
|
154
|
+
if ((0, lodash_1.isEmpty)(properties)) {
|
|
122
155
|
// create properties only when non exists
|
|
123
156
|
this.createPropertiesForRef(entityRef.getClassRef());
|
|
124
157
|
}
|
|
@@ -131,48 +164,59 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
131
164
|
}
|
|
132
165
|
else {
|
|
133
166
|
const refOptions = find.getOptions();
|
|
134
|
-
lodash_1.defaults(refOptions, options);
|
|
167
|
+
(0, lodash_1.defaults)(refOptions, options);
|
|
135
168
|
}
|
|
136
169
|
}
|
|
137
170
|
else if (context === Constants_1.METATYPE_SCHEMA) {
|
|
138
|
-
let find = this
|
|
139
|
-
.find(context, (c) => c.name === options.name);
|
|
140
|
-
if (!find) {
|
|
141
|
-
find = this.create(context, options);
|
|
142
|
-
}
|
|
171
|
+
let find = this.getOrCreateSchemaRefByName(options);
|
|
143
172
|
if (options.target) {
|
|
144
|
-
let entityRef = this
|
|
145
|
-
.find(Constants_1.METATYPE_ENTITY, (c) => c.getClass() === options.target);
|
|
173
|
+
let entityRef = this.find(Constants_1.METATYPE_ENTITY, (c) => c.getClass() === options.target);
|
|
146
174
|
if (find && entityRef) {
|
|
147
175
|
this.addSchemaToEntityRef(find, entityRef);
|
|
148
176
|
}
|
|
149
177
|
}
|
|
150
178
|
}
|
|
151
179
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (entry) {
|
|
157
|
-
if (lodash_1.isArray(entry)) {
|
|
158
|
-
entry.push(name);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
entry = [entry, name];
|
|
162
|
-
}
|
|
180
|
+
getOrCreateSchemaRefByName(options) {
|
|
181
|
+
let find = this.find(Constants_1.METATYPE_SCHEMA, (c) => c.name === options.name);
|
|
182
|
+
if (!find) {
|
|
183
|
+
find = this.createSchemaForOptions(options);
|
|
163
184
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
return find;
|
|
186
|
+
}
|
|
187
|
+
addSchemaToEntityRef(schemaRef, entityRef, options = {}) {
|
|
188
|
+
if ((0, lodash_1.isString)(schemaRef)) {
|
|
189
|
+
schemaRef = this.getOrCreateSchemaRefByName({
|
|
190
|
+
metaType: Constants_1.METATYPE_SCHEMA,
|
|
191
|
+
name: schemaRef,
|
|
192
|
+
namespace: this.namespace,
|
|
193
|
+
target: entityRef.getClass()
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const name = schemaRef.name;
|
|
197
|
+
let entry = entityRef.getOptions(Constants_1.METATYPE_SCHEMA, []);
|
|
198
|
+
if (!entry.includes(name)) {
|
|
199
|
+
if (entry) {
|
|
200
|
+
if ((0, lodash_1.isArray)(entry)) {
|
|
201
|
+
entry.push(name);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
entry = [entry, name];
|
|
205
|
+
}
|
|
170
206
|
}
|
|
171
207
|
else {
|
|
172
208
|
entry = [name];
|
|
173
209
|
}
|
|
210
|
+
if ((0, lodash_1.get)(options, 'override', false)) {
|
|
211
|
+
if ((0, lodash_1.get)(options, 'onlyDefault', false)) {
|
|
212
|
+
(0, lodash_1.remove)(entry, x => x === base_1.C_DEFAULT);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
entry = [name];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
entityRef.setOption(Constants_1.METATYPE_SCHEMA, (0, lodash_1.uniq)(entry));
|
|
174
219
|
}
|
|
175
|
-
entityRef.setOption('schema', lodash_1.uniq(entry));
|
|
176
220
|
}
|
|
177
221
|
/**
|
|
178
222
|
* react on dynamically removed context
|
|
@@ -183,9 +227,9 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
183
227
|
onRemove(context, entries) {
|
|
184
228
|
if (context === Constants_1.METATYPE_ENTITY || context === Constants_1.METATYPE_CLASS_REF) {
|
|
185
229
|
const targets = entries.map(x => x.target);
|
|
186
|
-
this.getLookupRegistry().remove(
|
|
187
|
-
this.getLookupRegistry().remove(
|
|
188
|
-
this.getLookupRegistry().remove(
|
|
230
|
+
this.getLookupRegistry().remove(Constants_1.METATYPE_CLASS_REF, (x) => targets.includes(x.target));
|
|
231
|
+
this.getLookupRegistry().remove(Constants_1.METATYPE_ENTITY, (x) => targets.includes(x.target));
|
|
232
|
+
this.getLookupRegistry().remove(Constants_1.METATYPE_PROPERTY, (x) => targets.includes(x.target));
|
|
189
233
|
}
|
|
190
234
|
else if (context === Constants_1.METATYPE_PROPERTY) {
|
|
191
235
|
const targets = entries.map(x => [x.target, x.propertyName]);
|
|
@@ -202,7 +246,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
202
246
|
* @param context
|
|
203
247
|
* @param entries
|
|
204
248
|
*/
|
|
205
|
-
onUpdate() {
|
|
249
|
+
onUpdate(context, options) {
|
|
206
250
|
}
|
|
207
251
|
/**
|
|
208
252
|
* Return all registered schema references
|
|
@@ -215,8 +259,8 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
215
259
|
}
|
|
216
260
|
getSchemaRefsFor(ref) {
|
|
217
261
|
let lookup = [];
|
|
218
|
-
if (IEntityRef_1.isEntityRef(ref) || IClassRef_1.isClassRef(ref)) {
|
|
219
|
-
const schemas = ref.getOptions(
|
|
262
|
+
if ((0, IEntityRef_1.isEntityRef)(ref) || (0, IClassRef_1.isClassRef)(ref)) {
|
|
263
|
+
const schemas = ref.getOptions(Constants_1.METATYPE_SCHEMA, []);
|
|
220
264
|
for (const schema of schemas) {
|
|
221
265
|
let schemaRef = this.find(Constants_1.METATYPE_SCHEMA, (x) => x.name === schema);
|
|
222
266
|
if (!schemaRef) {
|
|
@@ -226,7 +270,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
226
270
|
}
|
|
227
271
|
lookup = this.getSchemaRefs((x) => schemas.includes(x.name));
|
|
228
272
|
}
|
|
229
|
-
else if (lodash_1.isString(ref)) {
|
|
273
|
+
else if ((0, lodash_1.isString)(ref)) {
|
|
230
274
|
let schemaRef = this.find(Constants_1.METATYPE_SCHEMA, (x) => x.name === ref);
|
|
231
275
|
if (!schemaRef) {
|
|
232
276
|
schemaRef = this.create(Constants_1.METATYPE_SCHEMA, { name: ref });
|
|
@@ -236,7 +280,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
236
280
|
else {
|
|
237
281
|
throw new base_1.NotSupportedError('passed value is not supported');
|
|
238
282
|
}
|
|
239
|
-
return lookup ? lodash_1.uniq(lookup) : null;
|
|
283
|
+
return lookup ? (0, lodash_1.uniq)(lookup) : null;
|
|
240
284
|
}
|
|
241
285
|
/**
|
|
242
286
|
* TODO
|
|
@@ -253,11 +297,11 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
253
297
|
*/
|
|
254
298
|
getEntityRefFor(fn, skipNsCheck = true) {
|
|
255
299
|
let lookup = fn;
|
|
256
|
-
if (!lodash_1.isFunction(fn) && !lodash_1.isString(fn) && lodash_1.isObjectLike(fn)) {
|
|
300
|
+
if (!(0, lodash_1.isFunction)(fn) && !(0, lodash_1.isString)(fn) && (0, lodash_1.isObjectLike)(fn)) {
|
|
257
301
|
lookup = base_1.ClassUtils.getFunction(fn);
|
|
258
302
|
}
|
|
259
303
|
let lookupFn = (x) => x.getClassRef().getClass() === lookup;
|
|
260
|
-
if (lodash_1.isString(fn)) {
|
|
304
|
+
if ((0, lodash_1.isString)(fn)) {
|
|
261
305
|
lookupFn = (x) => x.getClassRef().name === lookup || x.name === lookup;
|
|
262
306
|
}
|
|
263
307
|
const entityRefExists = this.find(Constants_1.METATYPE_ENTITY, lookupFn);
|
|
@@ -276,7 +320,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
276
320
|
* @param filter
|
|
277
321
|
*/
|
|
278
322
|
getPropertyRef(ref, name) {
|
|
279
|
-
return this.getPropertyRefs(ref).find(x => lodash_1.snakeCase(x.name) === lodash_1.snakeCase(name));
|
|
323
|
+
return this.getPropertyRefs(ref).find(x => (0, lodash_1.snakeCase)(x.name) === (0, lodash_1.snakeCase)(name));
|
|
280
324
|
}
|
|
281
325
|
/**
|
|
282
326
|
* Returns all properties for given class or entity ref
|
|
@@ -284,7 +328,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
284
328
|
* @param ref
|
|
285
329
|
*/
|
|
286
330
|
getPropertyRefs(ref) {
|
|
287
|
-
const clsRef = IEntityRef_1.isEntityRef(ref) ? ref.getClassRef() : ref;
|
|
331
|
+
const clsRef = (0, IEntityRef_1.isEntityRef)(ref) ? ref.getClassRef() : ref;
|
|
288
332
|
// Return existing
|
|
289
333
|
const clsRefExists = this.find(Constants_1.METATYPE_CLASS_REF, (x) => x === clsRef);
|
|
290
334
|
let properties = [];
|
|
@@ -301,30 +345,35 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
301
345
|
*/
|
|
302
346
|
createPropertiesForRef(clsRef) {
|
|
303
347
|
const cls = clsRef.getClass(true);
|
|
304
|
-
const jsonSchema = JsonSchema_1.JsonSchema.serialize(cls, { appendTarget: true });
|
|
305
348
|
const propOptions = [];
|
|
306
349
|
const metaPropOptions = MetadataRegistry_1.MetadataRegistry.$().getByContextAndTarget(Constants_1.METATYPE_PROPERTY, cls);
|
|
307
|
-
if (
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
const
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
350
|
+
if (this.getOptions().detectUnannotatedProperties) {
|
|
351
|
+
const jsonSchema = JsonSchema_1.JsonSchema.serialize(cls, { appendTarget: true });
|
|
352
|
+
if ((0, JsonSchema7_1.hasClassPropertiesInDefinition)(clsRef.name, jsonSchema)) {
|
|
353
|
+
const properties = jsonSchema.definitions[clsRef.name].properties;
|
|
354
|
+
for (const k of (0, lodash_1.keys)(properties)) {
|
|
355
|
+
const property = properties[k];
|
|
356
|
+
const opts = {
|
|
357
|
+
metaType: Constants_1.METATYPE_PROPERTY,
|
|
358
|
+
namespace: clsRef.getNamespace(),
|
|
359
|
+
type: property.$target ? property.$target : property.type,
|
|
360
|
+
propertyName: k,
|
|
361
|
+
target: cls
|
|
362
|
+
};
|
|
363
|
+
if (property.default) {
|
|
364
|
+
opts.default = property.default;
|
|
365
|
+
}
|
|
366
|
+
const propMetadata = (0, lodash_1.remove)(metaPropOptions, x => x.propertyName === k);
|
|
367
|
+
if (!(0, lodash_1.isEmpty)(propMetadata)) {
|
|
368
|
+
for (const p of propMetadata) {
|
|
369
|
+
// clean namespace
|
|
370
|
+
const copy = (0, lodash_1.clone)(p);
|
|
371
|
+
delete copy.namespace;
|
|
372
|
+
(0, lodash_1.assign)(opts, copy);
|
|
373
|
+
}
|
|
325
374
|
}
|
|
375
|
+
propOptions.push(opts);
|
|
326
376
|
}
|
|
327
|
-
propOptions.push(opts);
|
|
328
377
|
}
|
|
329
378
|
}
|
|
330
379
|
const propertyOptions = propOptions.concat(metaPropOptions)
|
|
@@ -334,7 +383,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
334
383
|
// .filter(x => !this.processing.find((z: IPropertyOptions) => z.propertyName === x.propertyName && z.target === x.target))
|
|
335
384
|
.map(p => {
|
|
336
385
|
// change namespace of properties namespace
|
|
337
|
-
const copy = lodash_1.clone(p);
|
|
386
|
+
const copy = (0, lodash_1.clone)(p);
|
|
338
387
|
copy.namespace = clsRef.getNamespace();
|
|
339
388
|
copy.skipNsCheck = true;
|
|
340
389
|
return copy;
|
|
@@ -347,7 +396,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
347
396
|
* @param options
|
|
348
397
|
*/
|
|
349
398
|
createPropertyForOptions(options) {
|
|
350
|
-
if (lodash_1.keys(options).length === 0) {
|
|
399
|
+
if ((0, lodash_1.keys)(options).length === 0) {
|
|
351
400
|
throw new Error('can\'t create property for empty options');
|
|
352
401
|
}
|
|
353
402
|
options.namespace = this.namespace;
|
|
@@ -385,7 +434,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
385
434
|
// if (!options.name) {
|
|
386
435
|
// options.name = ClassRef.getClassName(options.target);
|
|
387
436
|
// }
|
|
388
|
-
options = lodash_1.defaults(options || {}, {});
|
|
437
|
+
options = (0, lodash_1.defaults)(options || {}, {});
|
|
389
438
|
const classRef = this.getClassRefFor(options.target, Constants_1.METATYPE_CLASS_REF);
|
|
390
439
|
classRef.setOptions(options);
|
|
391
440
|
return classRef;
|
|
@@ -412,10 +461,10 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
412
461
|
.getByContextAndTarget(context, target, 'merge', propertyName);
|
|
413
462
|
let metadataOptions = {};
|
|
414
463
|
if (metadataOptionList.length > 1) {
|
|
415
|
-
metadataOptions = lodash_1.
|
|
464
|
+
metadataOptions = (0, lodash_1.assign)(metadataOptions, ...metadataOptionList.map(x => (0, lodash_1.cloneDeep)(x)));
|
|
416
465
|
}
|
|
417
466
|
else if (metadataOptionList.length === 1) {
|
|
418
|
-
metadataOptions = lodash_1.cloneDeep(metadataOptionList.shift());
|
|
467
|
+
metadataOptions = (0, lodash_1.cloneDeep)(metadataOptionList.shift());
|
|
419
468
|
}
|
|
420
469
|
if (propertyName) {
|
|
421
470
|
// remove namespace for properties
|
|
@@ -429,7 +478,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
429
478
|
return this.getPropertyRefs(clsRef);
|
|
430
479
|
}
|
|
431
480
|
create(context, options) {
|
|
432
|
-
const skipNsCheck = lodash_1.get(options, 'skipNsCheck', false);
|
|
481
|
+
const skipNsCheck = (0, lodash_1.get)(options, 'skipNsCheck', false);
|
|
433
482
|
delete options.skipNsCheck;
|
|
434
483
|
const metadata = this.getMetadata(context, options.target, options.propertyName ? options.propertyName : null);
|
|
435
484
|
if (metadata) {
|
|
@@ -439,8 +488,8 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
439
488
|
' the namespace of this registry is ' + this.namespace);
|
|
440
489
|
}
|
|
441
490
|
}
|
|
442
|
-
if (!lodash_1.isEmpty(metadata) && lodash_1.keys(metadata).length > 0) {
|
|
443
|
-
lodash_1.merge(options, lodash_1.assign(metadata, { namespace: this.namespace }));
|
|
491
|
+
if (!(0, lodash_1.isEmpty)(metadata) && (0, lodash_1.keys)(metadata).length > 0) {
|
|
492
|
+
(0, lodash_1.merge)(options, (0, lodash_1.assign)(metadata, { namespace: this.namespace }));
|
|
444
493
|
}
|
|
445
494
|
}
|
|
446
495
|
options.metaType = context;
|
|
@@ -479,10 +528,10 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
479
528
|
}
|
|
480
529
|
getClassRefFor(object, type) {
|
|
481
530
|
let ref = null;
|
|
482
|
-
if (lodash_1.isString(object)) {
|
|
531
|
+
if ((0, lodash_1.isString)(object)) {
|
|
483
532
|
ref = this.find(Constants_1.METATYPE_CLASS_REF, (x) => x.name === object);
|
|
484
533
|
}
|
|
485
|
-
else if (lodash_1.isFunction(object)) {
|
|
534
|
+
else if ((0, lodash_1.isFunction)(object)) {
|
|
486
535
|
ref = this.find(Constants_1.METATYPE_CLASS_REF, (x) => x.getClass(true) === object);
|
|
487
536
|
}
|
|
488
537
|
else {
|
|
@@ -491,9 +540,9 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
491
540
|
if (!ref) {
|
|
492
541
|
ref = ClassRef_1.ClassRef.get(object, this.namespace, type === Constants_1.METATYPE_PROPERTY);
|
|
493
542
|
const metadata = this.getMetadata(Constants_1.METATYPE_EMBEDDABLE, object);
|
|
494
|
-
if (!lodash_1.isEmpty(metadata) && lodash_1.keys(metadata).length > 0) {
|
|
543
|
+
if (!(0, lodash_1.isEmpty)(metadata) && (0, lodash_1.keys)(metadata).length > 0) {
|
|
495
544
|
const refOptions = ref.getOptions();
|
|
496
|
-
lodash_1.merge(refOptions, metadata);
|
|
545
|
+
(0, lodash_1.merge)(refOptions, metadata);
|
|
497
546
|
}
|
|
498
547
|
// this.createPropertiesForRef(ref);
|
|
499
548
|
}
|
|
@@ -501,9 +550,9 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
501
550
|
}
|
|
502
551
|
reset() {
|
|
503
552
|
super.reset();
|
|
504
|
-
MetadataRegistry_1.MetadataRegistry.$().
|
|
505
|
-
MetadataRegistry_1.MetadataRegistry.$().
|
|
506
|
-
MetadataRegistry_1.MetadataRegistry.$().
|
|
553
|
+
MetadataRegistry_1.MetadataRegistry.$().off(Constants_1.C_EVENT_ADD, this.onAdd.bind(this));
|
|
554
|
+
MetadataRegistry_1.MetadataRegistry.$().off(Constants_1.C_EVENT_REMOVE, this.onRemove.bind(this));
|
|
555
|
+
MetadataRegistry_1.MetadataRegistry.$().off(Constants_1.C_EVENT_UPDATE, this.onUpdate.bind(this));
|
|
507
556
|
}
|
|
508
557
|
}
|
|
509
558
|
exports.DefaultNamespacedRegistry = DefaultNamespacedRegistry;
|