@allgemein/schema-api 1.4.5 → 1.5.3
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 +4 -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 +5 -1
- package/lib/Constants.js +14 -2
- 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 +16 -1
- package/lib/registry/DefaultNamespacedRegistry.js +165 -91
- 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,24 @@ 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>;
|
|
42
|
+
/**
|
|
43
|
+
* Check if object has the correct namespace for this registry handle
|
|
44
|
+
*
|
|
45
|
+
* @param options
|
|
46
|
+
*/
|
|
47
|
+
validNamespace(options: IAbstractOptions): boolean;
|
|
34
48
|
/**
|
|
35
49
|
* react on dynamically added context
|
|
36
50
|
*
|
|
@@ -38,6 +52,7 @@ export declare class DefaultNamespacedRegistry extends AbstractRegistry {
|
|
|
38
52
|
* @param entries
|
|
39
53
|
*/
|
|
40
54
|
onAdd(context: METADATA_TYPE, options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions): void;
|
|
55
|
+
getOrCreateSchemaRefByName(options: ISchemaOptions): ISchemaRef;
|
|
41
56
|
addSchemaToEntityRef(schemaRef: string | ISchemaRef, entityRef: IEntityRef, options?: {
|
|
42
57
|
override?: boolean;
|
|
43
58
|
onlyDefault?: boolean;
|
|
@@ -55,7 +70,7 @@ export declare class DefaultNamespacedRegistry extends AbstractRegistry {
|
|
|
55
70
|
* @param context
|
|
56
71
|
* @param entries
|
|
57
72
|
*/
|
|
58
|
-
onUpdate(): void;
|
|
73
|
+
onUpdate(context: METADATA_TYPE, options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions): void;
|
|
59
74
|
/**
|
|
60
75
|
* Return all registered schema references
|
|
61
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,28 +70,72 @@ 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
|
*
|
|
61
|
-
* @param
|
|
62
|
-
* @param entries
|
|
103
|
+
* @param options
|
|
63
104
|
*/
|
|
64
|
-
|
|
65
|
-
// check namespace, if not given use this as default
|
|
105
|
+
validNamespace(options) {
|
|
66
106
|
if (options.namespace) {
|
|
67
107
|
if (options.namespace !== this.namespace) {
|
|
68
108
|
// skip not my namespace
|
|
69
|
-
return;
|
|
109
|
+
return false;
|
|
70
110
|
}
|
|
71
111
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
112
|
+
else {
|
|
113
|
+
// if namespace not present skipping
|
|
114
|
+
if (options.metaType !== Constants_1.METATYPE_PROPERTY) {
|
|
115
|
+
// only properties should be pass and check if entity already exists
|
|
116
|
+
const namespace = MetadataRegistry_1.MetadataRegistry.$().find(Constants_1.METATYPE_NAMESPACE, (x) => x.target === options.target);
|
|
117
|
+
if (namespace && namespace.attributes.namespace === this.namespace) {
|
|
118
|
+
options.namespace = namespace.attributes.namespace;
|
|
119
|
+
}
|
|
120
|
+
else if (this.namespace !== Constants_1.DEFAULT_NAMESPACE) {
|
|
121
|
+
// passing to default namespace if nothing
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* react on dynamically added context
|
|
130
|
+
*
|
|
131
|
+
* @param context
|
|
132
|
+
* @param entries
|
|
133
|
+
*/
|
|
134
|
+
onAdd(context, options) {
|
|
135
|
+
if (!this.validNamespace(options)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
75
138
|
if (context === Constants_1.METATYPE_PROPERTY) {
|
|
76
|
-
// if (!!this.processing.find(x => x.target === options.target && x.propertyName === options.propertyName)) {
|
|
77
|
-
// return;
|
|
78
|
-
// }
|
|
79
|
-
// this.processing.push(options);
|
|
80
139
|
const sourceEntry = this.find(Constants_1.METATYPE_CLASS_REF, (ref) => ref.getClass() === options.target);
|
|
81
140
|
if (sourceEntry) {
|
|
82
141
|
const find = this.find(context, (c) => c.getClassRef().getClass() === options.target &&
|
|
@@ -86,14 +145,13 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
86
145
|
this.create(context, options);
|
|
87
146
|
}
|
|
88
147
|
}
|
|
89
|
-
// remove(this.processing, x => x === options);
|
|
90
148
|
}
|
|
91
149
|
else if (context === Constants_1.METATYPE_ENTITY) {
|
|
92
150
|
const find = this.find(context, (c) => c.getClassRef().getClass() === options.target);
|
|
93
151
|
if (!find) {
|
|
94
152
|
const entityRef = this.create(context, options);
|
|
95
153
|
const properties = this.find(Constants_1.METATYPE_PROPERTY, (c) => c.getClassRef().getClass() === options.target);
|
|
96
|
-
if (lodash_1.isEmpty(properties)) {
|
|
154
|
+
if ((0, lodash_1.isEmpty)(properties)) {
|
|
97
155
|
// create properties only when non exists
|
|
98
156
|
this.createPropertiesForRef(entityRef.getClassRef());
|
|
99
157
|
}
|
|
@@ -106,48 +164,59 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
106
164
|
}
|
|
107
165
|
else {
|
|
108
166
|
const refOptions = find.getOptions();
|
|
109
|
-
lodash_1.defaults(refOptions, options);
|
|
167
|
+
(0, lodash_1.defaults)(refOptions, options);
|
|
110
168
|
}
|
|
111
169
|
}
|
|
112
170
|
else if (context === Constants_1.METATYPE_SCHEMA) {
|
|
113
|
-
let find = this
|
|
114
|
-
.find(context, (c) => c.name === options.name);
|
|
115
|
-
if (!find) {
|
|
116
|
-
find = this.create(context, options);
|
|
117
|
-
}
|
|
171
|
+
let find = this.getOrCreateSchemaRefByName(options);
|
|
118
172
|
if (options.target) {
|
|
119
|
-
let entityRef = this
|
|
120
|
-
.find(Constants_1.METATYPE_ENTITY, (c) => c.getClass() === options.target);
|
|
173
|
+
let entityRef = this.find(Constants_1.METATYPE_ENTITY, (c) => c.getClass() === options.target);
|
|
121
174
|
if (find && entityRef) {
|
|
122
175
|
this.addSchemaToEntityRef(find, entityRef);
|
|
123
176
|
}
|
|
124
177
|
}
|
|
125
178
|
}
|
|
126
179
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (entry) {
|
|
132
|
-
if (lodash_1.isArray(entry)) {
|
|
133
|
-
entry.push(name);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
entry = [entry, name];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
entry = [name];
|
|
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);
|
|
141
184
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
+
}
|
|
145
206
|
}
|
|
146
207
|
else {
|
|
147
208
|
entry = [name];
|
|
148
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));
|
|
149
219
|
}
|
|
150
|
-
entityRef.setOption('schema', lodash_1.uniq(entry));
|
|
151
220
|
}
|
|
152
221
|
/**
|
|
153
222
|
* react on dynamically removed context
|
|
@@ -158,9 +227,9 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
158
227
|
onRemove(context, entries) {
|
|
159
228
|
if (context === Constants_1.METATYPE_ENTITY || context === Constants_1.METATYPE_CLASS_REF) {
|
|
160
229
|
const targets = entries.map(x => x.target);
|
|
161
|
-
this.getLookupRegistry().remove(
|
|
162
|
-
this.getLookupRegistry().remove(
|
|
163
|
-
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));
|
|
164
233
|
}
|
|
165
234
|
else if (context === Constants_1.METATYPE_PROPERTY) {
|
|
166
235
|
const targets = entries.map(x => [x.target, x.propertyName]);
|
|
@@ -177,7 +246,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
177
246
|
* @param context
|
|
178
247
|
* @param entries
|
|
179
248
|
*/
|
|
180
|
-
onUpdate() {
|
|
249
|
+
onUpdate(context, options) {
|
|
181
250
|
}
|
|
182
251
|
/**
|
|
183
252
|
* Return all registered schema references
|
|
@@ -190,8 +259,8 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
190
259
|
}
|
|
191
260
|
getSchemaRefsFor(ref) {
|
|
192
261
|
let lookup = [];
|
|
193
|
-
if (IEntityRef_1.isEntityRef(ref) || IClassRef_1.isClassRef(ref)) {
|
|
194
|
-
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, []);
|
|
195
264
|
for (const schema of schemas) {
|
|
196
265
|
let schemaRef = this.find(Constants_1.METATYPE_SCHEMA, (x) => x.name === schema);
|
|
197
266
|
if (!schemaRef) {
|
|
@@ -201,7 +270,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
201
270
|
}
|
|
202
271
|
lookup = this.getSchemaRefs((x) => schemas.includes(x.name));
|
|
203
272
|
}
|
|
204
|
-
else if (lodash_1.isString(ref)) {
|
|
273
|
+
else if ((0, lodash_1.isString)(ref)) {
|
|
205
274
|
let schemaRef = this.find(Constants_1.METATYPE_SCHEMA, (x) => x.name === ref);
|
|
206
275
|
if (!schemaRef) {
|
|
207
276
|
schemaRef = this.create(Constants_1.METATYPE_SCHEMA, { name: ref });
|
|
@@ -211,7 +280,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
211
280
|
else {
|
|
212
281
|
throw new base_1.NotSupportedError('passed value is not supported');
|
|
213
282
|
}
|
|
214
|
-
return lookup ? lodash_1.uniq(lookup) : null;
|
|
283
|
+
return lookup ? (0, lodash_1.uniq)(lookup) : null;
|
|
215
284
|
}
|
|
216
285
|
/**
|
|
217
286
|
* TODO
|
|
@@ -228,11 +297,11 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
228
297
|
*/
|
|
229
298
|
getEntityRefFor(fn, skipNsCheck = true) {
|
|
230
299
|
let lookup = fn;
|
|
231
|
-
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)) {
|
|
232
301
|
lookup = base_1.ClassUtils.getFunction(fn);
|
|
233
302
|
}
|
|
234
303
|
let lookupFn = (x) => x.getClassRef().getClass() === lookup;
|
|
235
|
-
if (lodash_1.isString(fn)) {
|
|
304
|
+
if ((0, lodash_1.isString)(fn)) {
|
|
236
305
|
lookupFn = (x) => x.getClassRef().name === lookup || x.name === lookup;
|
|
237
306
|
}
|
|
238
307
|
const entityRefExists = this.find(Constants_1.METATYPE_ENTITY, lookupFn);
|
|
@@ -251,7 +320,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
251
320
|
* @param filter
|
|
252
321
|
*/
|
|
253
322
|
getPropertyRef(ref, name) {
|
|
254
|
-
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));
|
|
255
324
|
}
|
|
256
325
|
/**
|
|
257
326
|
* Returns all properties for given class or entity ref
|
|
@@ -259,7 +328,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
259
328
|
* @param ref
|
|
260
329
|
*/
|
|
261
330
|
getPropertyRefs(ref) {
|
|
262
|
-
const clsRef = IEntityRef_1.isEntityRef(ref) ? ref.getClassRef() : ref;
|
|
331
|
+
const clsRef = (0, IEntityRef_1.isEntityRef)(ref) ? ref.getClassRef() : ref;
|
|
263
332
|
// Return existing
|
|
264
333
|
const clsRefExists = this.find(Constants_1.METATYPE_CLASS_REF, (x) => x === clsRef);
|
|
265
334
|
let properties = [];
|
|
@@ -276,30 +345,35 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
276
345
|
*/
|
|
277
346
|
createPropertiesForRef(clsRef) {
|
|
278
347
|
const cls = clsRef.getClass(true);
|
|
279
|
-
const jsonSchema = JsonSchema_1.JsonSchema.serialize(cls, { appendTarget: true });
|
|
280
348
|
const propOptions = [];
|
|
281
349
|
const metaPropOptions = MetadataRegistry_1.MetadataRegistry.$().getByContextAndTarget(Constants_1.METATYPE_PROPERTY, cls);
|
|
282
|
-
if (
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
+
}
|
|
300
374
|
}
|
|
375
|
+
propOptions.push(opts);
|
|
301
376
|
}
|
|
302
|
-
propOptions.push(opts);
|
|
303
377
|
}
|
|
304
378
|
}
|
|
305
379
|
const propertyOptions = propOptions.concat(metaPropOptions)
|
|
@@ -309,7 +383,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
309
383
|
// .filter(x => !this.processing.find((z: IPropertyOptions) => z.propertyName === x.propertyName && z.target === x.target))
|
|
310
384
|
.map(p => {
|
|
311
385
|
// change namespace of properties namespace
|
|
312
|
-
const copy = lodash_1.clone(p);
|
|
386
|
+
const copy = (0, lodash_1.clone)(p);
|
|
313
387
|
copy.namespace = clsRef.getNamespace();
|
|
314
388
|
copy.skipNsCheck = true;
|
|
315
389
|
return copy;
|
|
@@ -322,7 +396,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
322
396
|
* @param options
|
|
323
397
|
*/
|
|
324
398
|
createPropertyForOptions(options) {
|
|
325
|
-
if (lodash_1.keys(options).length === 0) {
|
|
399
|
+
if ((0, lodash_1.keys)(options).length === 0) {
|
|
326
400
|
throw new Error('can\'t create property for empty options');
|
|
327
401
|
}
|
|
328
402
|
options.namespace = this.namespace;
|
|
@@ -360,7 +434,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
360
434
|
// if (!options.name) {
|
|
361
435
|
// options.name = ClassRef.getClassName(options.target);
|
|
362
436
|
// }
|
|
363
|
-
options = lodash_1.defaults(options || {}, {});
|
|
437
|
+
options = (0, lodash_1.defaults)(options || {}, {});
|
|
364
438
|
const classRef = this.getClassRefFor(options.target, Constants_1.METATYPE_CLASS_REF);
|
|
365
439
|
classRef.setOptions(options);
|
|
366
440
|
return classRef;
|
|
@@ -387,10 +461,10 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
387
461
|
.getByContextAndTarget(context, target, 'merge', propertyName);
|
|
388
462
|
let metadataOptions = {};
|
|
389
463
|
if (metadataOptionList.length > 1) {
|
|
390
|
-
metadataOptions = lodash_1.
|
|
464
|
+
metadataOptions = (0, lodash_1.assign)(metadataOptions, ...metadataOptionList.map(x => (0, lodash_1.cloneDeep)(x)));
|
|
391
465
|
}
|
|
392
466
|
else if (metadataOptionList.length === 1) {
|
|
393
|
-
metadataOptions = lodash_1.cloneDeep(metadataOptionList.shift());
|
|
467
|
+
metadataOptions = (0, lodash_1.cloneDeep)(metadataOptionList.shift());
|
|
394
468
|
}
|
|
395
469
|
if (propertyName) {
|
|
396
470
|
// remove namespace for properties
|
|
@@ -404,7 +478,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
404
478
|
return this.getPropertyRefs(clsRef);
|
|
405
479
|
}
|
|
406
480
|
create(context, options) {
|
|
407
|
-
const skipNsCheck = lodash_1.get(options, 'skipNsCheck', false);
|
|
481
|
+
const skipNsCheck = (0, lodash_1.get)(options, 'skipNsCheck', false);
|
|
408
482
|
delete options.skipNsCheck;
|
|
409
483
|
const metadata = this.getMetadata(context, options.target, options.propertyName ? options.propertyName : null);
|
|
410
484
|
if (metadata) {
|
|
@@ -414,8 +488,8 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
414
488
|
' the namespace of this registry is ' + this.namespace);
|
|
415
489
|
}
|
|
416
490
|
}
|
|
417
|
-
if (!lodash_1.isEmpty(metadata) && lodash_1.keys(metadata).length > 0) {
|
|
418
|
-
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 }));
|
|
419
493
|
}
|
|
420
494
|
}
|
|
421
495
|
options.metaType = context;
|
|
@@ -454,10 +528,10 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
454
528
|
}
|
|
455
529
|
getClassRefFor(object, type) {
|
|
456
530
|
let ref = null;
|
|
457
|
-
if (lodash_1.isString(object)) {
|
|
531
|
+
if ((0, lodash_1.isString)(object)) {
|
|
458
532
|
ref = this.find(Constants_1.METATYPE_CLASS_REF, (x) => x.name === object);
|
|
459
533
|
}
|
|
460
|
-
else if (lodash_1.isFunction(object)) {
|
|
534
|
+
else if ((0, lodash_1.isFunction)(object)) {
|
|
461
535
|
ref = this.find(Constants_1.METATYPE_CLASS_REF, (x) => x.getClass(true) === object);
|
|
462
536
|
}
|
|
463
537
|
else {
|
|
@@ -466,9 +540,9 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
466
540
|
if (!ref) {
|
|
467
541
|
ref = ClassRef_1.ClassRef.get(object, this.namespace, type === Constants_1.METATYPE_PROPERTY);
|
|
468
542
|
const metadata = this.getMetadata(Constants_1.METATYPE_EMBEDDABLE, object);
|
|
469
|
-
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) {
|
|
470
544
|
const refOptions = ref.getOptions();
|
|
471
|
-
lodash_1.merge(refOptions, metadata);
|
|
545
|
+
(0, lodash_1.merge)(refOptions, metadata);
|
|
472
546
|
}
|
|
473
547
|
// this.createPropertiesForRef(ref);
|
|
474
548
|
}
|
|
@@ -476,9 +550,9 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
476
550
|
}
|
|
477
551
|
reset() {
|
|
478
552
|
super.reset();
|
|
479
|
-
MetadataRegistry_1.MetadataRegistry.$().
|
|
480
|
-
MetadataRegistry_1.MetadataRegistry.$().
|
|
481
|
-
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));
|
|
482
556
|
}
|
|
483
557
|
}
|
|
484
558
|
exports.DefaultNamespacedRegistry = DefaultNamespacedRegistry;
|