@allgemein/schema-api 1.7.1 → 1.8.1
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/README.md +104 -1
- package/api/IBaseRef.d.ts +2 -2
- package/api/IBaseRef.js +1 -2
- package/api/IBuildOptions.d.ts +2 -2
- package/api/IBuildOptions.js +1 -2
- package/api/IClassRef.d.ts +5 -5
- package/api/IClassRef.js +3 -6
- package/api/IClassRef.js.map +1 -1
- package/api/IEntityRef.d.ts +5 -5
- package/api/IEntityRef.js +3 -6
- package/api/IEntityRef.js.map +1 -1
- package/api/IJsonSchema.d.ts +4 -4
- package/api/IJsonSchema.js +3 -8
- package/api/IJsonSchema.js.map +1 -1
- package/api/ILookupRegistry.d.ts +6 -6
- package/api/ILookupRegistry.js +6 -9
- package/api/ILookupRegistry.js.map +1 -1
- package/api/IPropertyExtentions.d.ts +1 -1
- package/api/IPropertyExtentions.js +1 -2
- package/api/IPropertyExtentions.js.map +1 -1
- package/api/IPropertyRef.d.ts +3 -3
- package/api/IPropertyRef.js +3 -6
- package/api/IPropertyRef.js.map +1 -1
- package/api/ISchemaRef.d.ts +2 -2
- package/api/ISchemaRef.js +1 -2
- package/api/ISerializeSupport.d.ts +4 -4
- package/api/ISerializeSupport.js +3 -8
- package/api/ISerializeSupport.js.map +1 -1
- package/browser.d.ts +65 -65
- package/browser.js +43 -112
- package/browser.js.map +1 -1
- package/decorators/Embeddable.d.ts +1 -1
- package/decorators/Embeddable.js +4 -7
- package/decorators/Embeddable.js.map +1 -1
- package/decorators/Entity.d.ts +1 -1
- package/decorators/Entity.js +4 -7
- package/decorators/Entity.js.map +1 -1
- package/decorators/Namespace.js +7 -10
- package/decorators/Namespace.js.map +1 -1
- package/decorators/Property.d.ts +1 -1
- package/decorators/Property.js +20 -23
- package/decorators/Property.js.map +1 -1
- package/decorators/PropertyOf.d.ts +1 -1
- package/decorators/PropertyOf.js +6 -9
- package/decorators/PropertyOf.js.map +1 -1
- package/decorators/Schema.d.ts +1 -1
- package/decorators/Schema.js +4 -7
- package/decorators/Schema.js.map +1 -1
- package/decorators/validate/Hostname.d.ts +2 -3
- package/decorators/validate/Hostname.js +12 -16
- package/decorators/validate/Hostname.js.map +1 -1
- package/decorators/validate/Ip4.d.ts +1 -1
- package/decorators/validate/Ip4.js +11 -15
- package/decorators/validate/Ip4.js.map +1 -1
- package/decorators/validate/Ip6.d.ts +2 -3
- package/decorators/validate/Ip6.js +12 -15
- package/decorators/validate/Ip6.js.map +1 -1
- package/decorators/validate/IsEmail.d.ts +2 -3
- package/decorators/validate/IsEmail.js +10 -14
- package/decorators/validate/IsEmail.js.map +1 -1
- package/decorators/validate/IsNotEmpty.d.ts +1 -1
- package/decorators/validate/IsNotEmpty.js +11 -14
- package/decorators/validate/IsNotEmpty.js.map +1 -1
- package/decorators/validate/MaxLength.d.ts +1 -1
- package/decorators/validate/MaxLength.js +9 -12
- package/decorators/validate/MaxLength.js.map +1 -1
- package/decorators/validate/MinLength.d.ts +1 -1
- package/decorators/validate/MinLength.js +9 -12
- package/decorators/validate/MinLength.js.map +1 -1
- package/decorators/validate/Regex.d.ts +1 -1
- package/decorators/validate/Regex.js +10 -13
- package/decorators/validate/Regex.js.map +1 -1
- package/decorators/validate/Required.d.ts +1 -1
- package/decorators/validate/Required.js +9 -12
- package/decorators/validate/Required.js.map +1 -1
- package/decorators/validate/index.d.ts +8 -8
- package/decorators/validate/index.js +9 -19
- package/decorators/validate/index.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -17
- package/index.js.map +1 -1
- package/lib/AbstractRef.d.ts +4 -4
- package/lib/AbstractRef.js +29 -33
- package/lib/AbstractRef.js.map +1 -1
- package/lib/AnnotationsHelper.d.ts +2 -2
- package/lib/AnnotationsHelper.js +32 -36
- package/lib/AnnotationsHelper.js.map +1 -1
- package/lib/ClassRef.d.ts +7 -7
- package/lib/ClassRef.js +69 -73
- package/lib/ClassRef.js.map +1 -1
- package/lib/Constants.d.ts +1 -3
- package/lib/Constants.js +42 -45
- package/lib/Constants.js.map +1 -1
- package/lib/DataContainer.d.ts +6 -6
- package/lib/DataContainer.js +20 -25
- package/lib/DataContainer.js.map +1 -1
- package/lib/LookupRegistry.js +13 -17
- package/lib/LookupRegistry.js.map +1 -1
- package/lib/SchemaRef.d.ts +7 -7
- package/lib/SchemaRef.js +11 -15
- package/lib/SchemaRef.js.map +1 -1
- package/lib/SchemaUtils.d.ts +3 -3
- package/lib/SchemaUtils.js +23 -27
- package/lib/SchemaUtils.js.map +1 -1
- package/lib/functions.d.ts +2 -2
- package/lib/functions.js +7 -10
- package/lib/functions.js.map +1 -1
- package/lib/json-schema/Constants.js +3 -6
- package/lib/json-schema/Constants.js.map +1 -1
- package/lib/json-schema/IJsonSchemaSerializeOptions.d.ts +4 -4
- package/lib/json-schema/IJsonSchemaSerializeOptions.js +1 -2
- package/lib/json-schema/IJsonSchemaSerializer.d.ts +3 -3
- package/lib/json-schema/IJsonSchemaSerializer.js +1 -2
- package/lib/json-schema/IJsonSchemaUnserializeOptions.d.ts +3 -3
- package/lib/json-schema/IJsonSchemaUnserializeOptions.js +1 -2
- package/lib/json-schema/IJsonSchemaUnserializer.d.ts +1 -1
- package/lib/json-schema/IJsonSchemaUnserializer.js +1 -2
- package/lib/json-schema/IParseOptions.d.ts +2 -2
- package/lib/json-schema/IParseOptions.js +1 -4
- package/lib/json-schema/IParseOptions.js.map +1 -1
- package/lib/json-schema/JsonSchema.d.ts +10 -10
- package/lib/json-schema/JsonSchema.js +26 -30
- package/lib/json-schema/JsonSchema.js.map +1 -1
- package/lib/json-schema/JsonSchema7.d.ts +2 -2
- package/lib/json-schema/JsonSchema7.js +3 -8
- package/lib/json-schema/JsonSchema7.js.map +1 -1
- package/lib/json-schema/JsonSchema7Serializer.d.ts +9 -9
- package/lib/json-schema/JsonSchema7Serializer.js +96 -100
- package/lib/json-schema/JsonSchema7Serializer.js.map +1 -1
- package/lib/json-schema/JsonSchema7Unserializer.d.ts +12 -12
- package/lib/json-schema/JsonSchema7Unserializer.js +99 -103
- package/lib/json-schema/JsonSchema7Unserializer.js.map +1 -1
- package/lib/json-schema/functions.d.ts +2 -2
- package/lib/json-schema/functions.js +8 -12
- package/lib/json-schema/functions.js.map +1 -1
- package/lib/options/IAbstractOptions.d.ts +1 -1
- package/lib/options/IAbstractOptions.js +1 -2
- package/lib/options/IAttributeOptions.d.ts +2 -2
- package/lib/options/IAttributeOptions.js +1 -2
- package/lib/options/IEntityOptions.d.ts +2 -2
- package/lib/options/IEntityOptions.js +1 -2
- package/lib/options/INamedOptions.js +1 -2
- package/lib/options/IObjectOptions.d.ts +2 -2
- package/lib/options/IObjectOptions.js +1 -2
- package/lib/options/IPropertyOptions.d.ts +2 -2
- package/lib/options/IPropertyOptions.js +1 -2
- package/lib/options/ISchemaOptions.d.ts +2 -2
- package/lib/options/ISchemaOptions.js +1 -2
- package/lib/registry/AbstractRegistry.d.ts +8 -8
- package/lib/registry/AbstractRegistry.js +19 -23
- package/lib/registry/AbstractRegistry.js.map +1 -1
- package/lib/registry/Binding.d.ts +1 -1
- package/lib/registry/Binding.js +2 -6
- package/lib/registry/Binding.js.map +1 -1
- package/lib/registry/DefaultEntityRef.d.ts +9 -9
- package/lib/registry/DefaultEntityRef.js +10 -14
- package/lib/registry/DefaultEntityRef.js.map +1 -1
- package/lib/registry/DefaultNamespacedRegistry.d.ts +14 -14
- package/lib/registry/DefaultNamespacedRegistry.js +123 -127
- package/lib/registry/DefaultNamespacedRegistry.js.map +1 -1
- package/lib/registry/DefaultPropertyRef.d.ts +7 -7
- package/lib/registry/DefaultPropertyRef.js +42 -46
- package/lib/registry/DefaultPropertyRef.js.map +1 -1
- package/lib/registry/IRegistryOptions.js +1 -2
- package/lib/registry/MetadataRegistry.d.ts +10 -10
- package/lib/registry/MetadataRegistry.js +30 -36
- package/lib/registry/MetadataRegistry.js.map +1 -1
- package/lib/registry/RegistryFactory.d.ts +3 -3
- package/lib/registry/RegistryFactory.js +19 -25
- package/lib/registry/RegistryFactory.js.map +1 -1
- package/lib/serializer/ISerializeOptions.js +1 -2
- package/lib/serializer/ISerializer.d.ts +2 -2
- package/lib/serializer/ISerializer.js +1 -2
- package/lib/serializer/ISerializerFactory.d.ts +6 -6
- package/lib/serializer/ISerializerFactory.js +1 -2
- package/lib/serializer/IUnserializeOptions.js +1 -2
- package/lib/serializer/IUnserializer.d.ts +2 -2
- package/lib/serializer/IUnserializer.js +1 -2
- package/lib/serializer/SerializerRegistry.d.ts +1 -1
- package/lib/serializer/SerializerRegistry.js +3 -7
- package/lib/serializer/SerializerRegistry.js.map +1 -1
- package/lib/validation/DefaultValidator.d.ts +5 -5
- package/lib/validation/DefaultValidator.js +33 -37
- package/lib/validation/DefaultValidator.js.map +1 -1
- package/lib/validation/IValidateOptions.js +1 -2
- package/lib/validation/IValidationError.js +1 -2
- package/lib/validation/IValidationMessage.js +1 -2
- package/lib/validation/IValidationOptions.d.ts +1 -0
- package/lib/validation/IValidationOptions.js +1 -0
- package/lib/validation/IValidationOptions.js.map +1 -1
- package/lib/validation/IValidationResult.d.ts +1 -1
- package/lib/validation/IValidationResult.js +1 -2
- package/lib/validation/IValidator.d.ts +1 -1
- package/lib/validation/IValidator.js +1 -2
- package/lib/validation/IValidatorEntry.d.ts +1 -1
- package/lib/validation/IValidatorEntry.js +1 -2
- package/lib/validation/IValidatorHandle.js +1 -2
- package/lib/validation/Validator.d.ts +4 -4
- package/lib/validation/Validator.js +7 -11
- package/lib/validation/Validator.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultNamespacedRegistry = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Handler for metadata
|
|
6
3
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
import { assign, clone, cloneDeep, defaults, get, isArray, isEmpty, isFunction, isObjectLike, isString, keys, merge, remove, snakeCase, uniq } from '@allgemein/base';
|
|
5
|
+
import { C_EVENT_ADD, C_EVENT_DRAIN_FINISHED, C_EVENT_REMOVE, C_EVENT_UPDATE, DEFAULT_NAMESPACE, K_TRIGGERED, METATYPE_CLASS_REF, METATYPE_EMBEDDABLE, METATYPE_ENTITY, METATYPE_NAMESPACE, METATYPE_PROPERTY, METATYPE_SCHEMA } from './../Constants.js';
|
|
6
|
+
import { isEntityRef } from '../../api/IEntityRef.js';
|
|
7
|
+
import { isClassRef } from '../../api/IClassRef.js';
|
|
8
|
+
import { MetadataRegistry } from './MetadataRegistry.js';
|
|
9
|
+
import { DefaultPropertyRef } from './DefaultPropertyRef.js';
|
|
10
|
+
import { ClassRef } from '../ClassRef.js';
|
|
11
|
+
import { DefaultEntityRef } from './DefaultEntityRef.js';
|
|
12
|
+
import { hasClassPropertiesInDefinition } from '../json-schema/JsonSchema7.js';
|
|
13
|
+
import { C_DEFAULT, ClassUtils, NotSupportedError } from '@allgemein/base';
|
|
14
|
+
import { JsonSchema } from '../json-schema/JsonSchema.js';
|
|
15
|
+
import { SchemaRef } from '../SchemaRef.js';
|
|
16
|
+
import { AbstractRegistry } from './AbstractRegistry.js';
|
|
20
17
|
/**
|
|
21
18
|
* Registry which handles by default class, schema, embeddalbes and properties, which are not handled by a specialized registry.
|
|
22
19
|
*
|
|
@@ -31,9 +28,9 @@ const AbstractRegistry_1 = require("./AbstractRegistry");
|
|
|
31
28
|
* 4. append through reload method
|
|
32
29
|
*
|
|
33
30
|
*/
|
|
34
|
-
class DefaultNamespacedRegistry extends
|
|
31
|
+
export class DefaultNamespacedRegistry extends AbstractRegistry {
|
|
35
32
|
constructor(namespace, options) {
|
|
36
|
-
super(namespace,
|
|
33
|
+
super(namespace, defaults(options || {}, { detectUnannotatedProperties: true }));
|
|
37
34
|
this.drained = false;
|
|
38
35
|
}
|
|
39
36
|
/**
|
|
@@ -42,9 +39,9 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
42
39
|
prepare() {
|
|
43
40
|
// apply listener
|
|
44
41
|
this.drainAlreadyAdded();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
MetadataRegistry.$().on(C_EVENT_ADD, this.onMetadataAdd.bind(this));
|
|
43
|
+
MetadataRegistry.$().on(C_EVENT_REMOVE, this.onMetadataRemove.bind(this));
|
|
44
|
+
MetadataRegistry.$().on(C_EVENT_UPDATE, this.onMetadataUpdate.bind(this));
|
|
48
45
|
}
|
|
49
46
|
ready(timeout) {
|
|
50
47
|
return super.ready(timeout).then(() => {
|
|
@@ -56,7 +53,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
56
53
|
const t = setTimeout(() => {
|
|
57
54
|
reject();
|
|
58
55
|
}, timeout ? timeout : 10000);
|
|
59
|
-
|
|
56
|
+
MetadataRegistry.$().once(C_EVENT_DRAIN_FINISHED + this.namespace, () => {
|
|
60
57
|
resolve(true);
|
|
61
58
|
});
|
|
62
59
|
});
|
|
@@ -68,14 +65,14 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
68
65
|
*/
|
|
69
66
|
drainAlreadyAdded() {
|
|
70
67
|
this.drained = false;
|
|
71
|
-
const alreadyFired =
|
|
68
|
+
const alreadyFired = MetadataRegistry.$()
|
|
72
69
|
.getMetadata()
|
|
73
70
|
.filter(x => {
|
|
74
|
-
const v = Object.getOwnPropertyDescriptor(x,
|
|
71
|
+
const v = Object.getOwnPropertyDescriptor(x, K_TRIGGERED);
|
|
75
72
|
return v && v.value;
|
|
76
73
|
});
|
|
77
74
|
for (const event of alreadyFired) {
|
|
78
|
-
const cloneEvent =
|
|
75
|
+
const cloneEvent = cloneDeep(event);
|
|
79
76
|
try {
|
|
80
77
|
this.onAdd(cloneEvent.metaType, cloneEvent);
|
|
81
78
|
}
|
|
@@ -83,7 +80,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
82
|
this.drained = true;
|
|
86
|
-
|
|
83
|
+
MetadataRegistry.$().emit([C_EVENT_DRAIN_FINISHED, this.namespace].join('_'), true);
|
|
87
84
|
}
|
|
88
85
|
async onMetadataAdd(context, options) {
|
|
89
86
|
await this.lock.acquire();
|
|
@@ -120,13 +117,13 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
120
117
|
}
|
|
121
118
|
else {
|
|
122
119
|
// if namespace not present skipping
|
|
123
|
-
if (options.metaType !==
|
|
120
|
+
if (options.metaType !== METATYPE_PROPERTY) {
|
|
124
121
|
// only properties should be pass and check if entity already exists
|
|
125
|
-
const namespace =
|
|
122
|
+
const namespace = MetadataRegistry.$().find(METATYPE_NAMESPACE, (x) => x.target === options.target);
|
|
126
123
|
if (namespace && namespace.attributes.namespace === this.namespace) {
|
|
127
124
|
options.namespace = namespace.attributes.namespace;
|
|
128
125
|
}
|
|
129
|
-
else if (this.namespace !==
|
|
126
|
+
else if (this.namespace !== DEFAULT_NAMESPACE) {
|
|
130
127
|
// passing to default namespace if nothing
|
|
131
128
|
return false;
|
|
132
129
|
}
|
|
@@ -144,8 +141,8 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
144
141
|
if (!this.validNamespace(options)) {
|
|
145
142
|
return;
|
|
146
143
|
}
|
|
147
|
-
if (context ===
|
|
148
|
-
const sourceEntry = this.find(
|
|
144
|
+
if (context === METATYPE_PROPERTY) {
|
|
145
|
+
const sourceEntry = this.find(METATYPE_CLASS_REF, (ref) => ref.getClass() === options.target);
|
|
149
146
|
if (sourceEntry) {
|
|
150
147
|
const find = this.find(context, (c) => c.getClassRef().getClass() === options.target &&
|
|
151
148
|
c.name === options.propertyName);
|
|
@@ -155,31 +152,31 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
155
152
|
}
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
|
-
else if (context ===
|
|
155
|
+
else if (context === METATYPE_ENTITY) {
|
|
159
156
|
const find = this.find(context, (c) => c.getClassRef().getClass() === options.target);
|
|
160
157
|
if (!find) {
|
|
161
158
|
const entityRef = this.create(context, options);
|
|
162
|
-
const properties = this.find(
|
|
163
|
-
if (
|
|
159
|
+
const properties = this.find(METATYPE_PROPERTY, (c) => c.getClassRef().getClass() === options.target);
|
|
160
|
+
if (isEmpty(properties)) {
|
|
164
161
|
// create properties only when non exists
|
|
165
162
|
this.createPropertiesForRef(entityRef.getClassRef());
|
|
166
163
|
}
|
|
167
164
|
}
|
|
168
165
|
}
|
|
169
|
-
else if (context ===
|
|
170
|
-
const find = this.find(
|
|
166
|
+
else if (context === METATYPE_EMBEDDABLE) {
|
|
167
|
+
const find = this.find(METATYPE_CLASS_REF, (c) => c.getClass() === options.target);
|
|
171
168
|
if (!find) {
|
|
172
169
|
this.create(context, options);
|
|
173
170
|
}
|
|
174
171
|
else {
|
|
175
172
|
const refOptions = find.getOptions();
|
|
176
|
-
|
|
173
|
+
defaults(refOptions, options);
|
|
177
174
|
}
|
|
178
175
|
}
|
|
179
|
-
else if (context ===
|
|
180
|
-
|
|
176
|
+
else if (context === METATYPE_SCHEMA) {
|
|
177
|
+
const find = this.getOrCreateSchemaRefByName(options);
|
|
181
178
|
if (options.target) {
|
|
182
|
-
|
|
179
|
+
const entityRef = this.find(METATYPE_ENTITY, (c) => c.getClass() === options.target);
|
|
183
180
|
if (find && entityRef) {
|
|
184
181
|
this.addSchemaToEntityRef(find, entityRef);
|
|
185
182
|
}
|
|
@@ -187,26 +184,26 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
187
184
|
}
|
|
188
185
|
}
|
|
189
186
|
getOrCreateSchemaRefByName(options) {
|
|
190
|
-
let find = this.find(
|
|
187
|
+
let find = this.find(METATYPE_SCHEMA, (c) => c.name === options.name);
|
|
191
188
|
if (!find) {
|
|
192
189
|
find = this.createSchemaForOptions(options);
|
|
193
190
|
}
|
|
194
191
|
return find;
|
|
195
192
|
}
|
|
196
193
|
addSchemaToEntityRef(schemaRef, entityRef, options = {}) {
|
|
197
|
-
if (
|
|
194
|
+
if (isString(schemaRef)) {
|
|
198
195
|
schemaRef = this.getOrCreateSchemaRefByName({
|
|
199
|
-
metaType:
|
|
196
|
+
metaType: METATYPE_SCHEMA,
|
|
200
197
|
name: schemaRef,
|
|
201
198
|
namespace: this.namespace,
|
|
202
199
|
target: entityRef.getClass()
|
|
203
200
|
});
|
|
204
201
|
}
|
|
205
202
|
const name = schemaRef.name;
|
|
206
|
-
let entry = entityRef.getOptions(
|
|
203
|
+
let entry = entityRef.getOptions(METATYPE_SCHEMA, []);
|
|
207
204
|
if (!entry.includes(name)) {
|
|
208
205
|
if (entry) {
|
|
209
|
-
if (
|
|
206
|
+
if (isArray(entry)) {
|
|
210
207
|
entry.push(name);
|
|
211
208
|
}
|
|
212
209
|
else {
|
|
@@ -216,15 +213,15 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
216
213
|
else {
|
|
217
214
|
entry = [name];
|
|
218
215
|
}
|
|
219
|
-
if (
|
|
220
|
-
if (
|
|
221
|
-
|
|
216
|
+
if (get(options, 'override', false)) {
|
|
217
|
+
if (get(options, 'onlyDefault', false)) {
|
|
218
|
+
remove(entry, x => x === C_DEFAULT);
|
|
222
219
|
}
|
|
223
220
|
else {
|
|
224
221
|
entry = [name];
|
|
225
222
|
}
|
|
226
223
|
}
|
|
227
|
-
entityRef.setOption(
|
|
224
|
+
entityRef.setOption(METATYPE_SCHEMA, uniq(entry));
|
|
228
225
|
}
|
|
229
226
|
}
|
|
230
227
|
/**
|
|
@@ -234,17 +231,17 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
234
231
|
* @param entries
|
|
235
232
|
*/
|
|
236
233
|
onRemove(context, entries) {
|
|
237
|
-
if (context ===
|
|
234
|
+
if (context === METATYPE_ENTITY || context === METATYPE_CLASS_REF) {
|
|
238
235
|
const targets = entries.map(x => x.target);
|
|
239
|
-
this.getLookupRegistry().remove(
|
|
240
|
-
this.getLookupRegistry().remove(
|
|
241
|
-
this.getLookupRegistry().remove(
|
|
236
|
+
this.getLookupRegistry().remove(METATYPE_CLASS_REF, (x) => targets.includes(x.target));
|
|
237
|
+
this.getLookupRegistry().remove(METATYPE_ENTITY, (x) => targets.includes(x.target));
|
|
238
|
+
this.getLookupRegistry().remove(METATYPE_PROPERTY, (x) => targets.includes(x.target));
|
|
242
239
|
}
|
|
243
|
-
else if (context ===
|
|
240
|
+
else if (context === METATYPE_PROPERTY) {
|
|
244
241
|
const targets = entries.map(x => [x.target, x.propertyName]);
|
|
245
242
|
this.getLookupRegistry().remove(context, (x) => targets.includes([x.target, x.name]));
|
|
246
243
|
}
|
|
247
|
-
else if (context ===
|
|
244
|
+
else if (context === METATYPE_SCHEMA) {
|
|
248
245
|
// TODO remove schema ref
|
|
249
246
|
// TODO remove schema options entries
|
|
250
247
|
}
|
|
@@ -264,32 +261,32 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
264
261
|
* @return ISchemaRef[]
|
|
265
262
|
*/
|
|
266
263
|
getSchemaRefs(filter) {
|
|
267
|
-
return this.filter(
|
|
264
|
+
return this.filter(METATYPE_SCHEMA, filter);
|
|
268
265
|
}
|
|
269
266
|
getSchemaRefsFor(ref) {
|
|
270
267
|
let lookup = [];
|
|
271
|
-
if (
|
|
272
|
-
const schemas = ref.getOptions(
|
|
268
|
+
if (isEntityRef(ref) || isClassRef(ref)) {
|
|
269
|
+
const schemas = ref.getOptions(METATYPE_SCHEMA, []);
|
|
273
270
|
for (const schema of schemas) {
|
|
274
|
-
let schemaRef = this.find(
|
|
271
|
+
let schemaRef = this.find(METATYPE_SCHEMA, (x) => x.name === schema);
|
|
275
272
|
if (!schemaRef) {
|
|
276
|
-
schemaRef = this.create(
|
|
273
|
+
schemaRef = this.create(METATYPE_SCHEMA, { name: schema, target: ref.getClass() });
|
|
277
274
|
}
|
|
278
275
|
lookup.push(schemaRef);
|
|
279
276
|
}
|
|
280
277
|
lookup = this.getSchemaRefs((x) => schemas.includes(x.name));
|
|
281
278
|
}
|
|
282
|
-
else if (
|
|
283
|
-
let schemaRef = this.find(
|
|
279
|
+
else if (isString(ref)) {
|
|
280
|
+
let schemaRef = this.find(METATYPE_SCHEMA, (x) => x.name === ref);
|
|
284
281
|
if (!schemaRef) {
|
|
285
|
-
schemaRef = this.create(
|
|
282
|
+
schemaRef = this.create(METATYPE_SCHEMA, { name: ref });
|
|
286
283
|
}
|
|
287
284
|
return schemaRef;
|
|
288
285
|
}
|
|
289
286
|
else {
|
|
290
|
-
throw new
|
|
287
|
+
throw new NotSupportedError('passed value is not supported');
|
|
291
288
|
}
|
|
292
|
-
return lookup ?
|
|
289
|
+
return lookup ? uniq(lookup) : null;
|
|
293
290
|
}
|
|
294
291
|
/**
|
|
295
292
|
* TODO
|
|
@@ -297,7 +294,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
297
294
|
* @param filter
|
|
298
295
|
*/
|
|
299
296
|
getEntities(filter) {
|
|
300
|
-
return this.getLookupRegistry().filter(
|
|
297
|
+
return this.getLookupRegistry().filter(METATYPE_ENTITY, filter);
|
|
301
298
|
}
|
|
302
299
|
/**
|
|
303
300
|
* Can get get entity ref for function.
|
|
@@ -306,18 +303,18 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
306
303
|
*/
|
|
307
304
|
getEntityRefFor(fn, skipNsCheck = true) {
|
|
308
305
|
let lookup = fn;
|
|
309
|
-
if (!
|
|
310
|
-
lookup =
|
|
306
|
+
if (!isFunction(fn) && !isString(fn) && isObjectLike(fn)) {
|
|
307
|
+
lookup = ClassUtils.getFunction(fn);
|
|
311
308
|
}
|
|
312
309
|
let lookupFn = (x) => x.getClassRef().getClass() === lookup;
|
|
313
|
-
if (
|
|
310
|
+
if (isString(fn)) {
|
|
314
311
|
lookupFn = (x) => x.getClassRef().name === lookup || x.name === lookup;
|
|
315
312
|
}
|
|
316
|
-
const entityRefExists = this.find(
|
|
313
|
+
const entityRefExists = this.find(METATYPE_ENTITY, lookupFn);
|
|
317
314
|
if (entityRefExists) {
|
|
318
315
|
return entityRefExists;
|
|
319
316
|
}
|
|
320
|
-
return this.create(
|
|
317
|
+
return this.create(METATYPE_ENTITY, {
|
|
321
318
|
target: lookup,
|
|
322
319
|
namespace: this.namespace,
|
|
323
320
|
skipNsCheck: skipNsCheck
|
|
@@ -329,7 +326,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
329
326
|
* @param filter
|
|
330
327
|
*/
|
|
331
328
|
getPropertyRef(ref, name) {
|
|
332
|
-
return this.getPropertyRefs(ref).find(x =>
|
|
329
|
+
return this.getPropertyRefs(ref).find(x => snakeCase(x.name) === snakeCase(name));
|
|
333
330
|
}
|
|
334
331
|
/**
|
|
335
332
|
* Returns all properties for given class or entity ref
|
|
@@ -337,12 +334,12 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
337
334
|
* @param ref
|
|
338
335
|
*/
|
|
339
336
|
getPropertyRefs(ref) {
|
|
340
|
-
const clsRef =
|
|
337
|
+
const clsRef = isEntityRef(ref) ? ref.getClassRef() : ref;
|
|
341
338
|
// Return existing
|
|
342
|
-
const clsRefExists = this.find(
|
|
339
|
+
const clsRefExists = this.find(METATYPE_CLASS_REF, (x) => x === clsRef);
|
|
343
340
|
let properties = [];
|
|
344
341
|
if (clsRefExists) {
|
|
345
|
-
properties = this.filter(
|
|
342
|
+
properties = this.filter(METATYPE_PROPERTY, (x) => x.getClassRef() === clsRefExists);
|
|
346
343
|
}
|
|
347
344
|
else {
|
|
348
345
|
properties = this.createPropertiesForRef(clsRef);
|
|
@@ -355,15 +352,15 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
355
352
|
createPropertiesForRef(clsRef) {
|
|
356
353
|
const cls = clsRef.getClass(true);
|
|
357
354
|
const propOptions = [];
|
|
358
|
-
const metaPropOptions =
|
|
355
|
+
const metaPropOptions = MetadataRegistry.$().getByContextAndTarget(METATYPE_PROPERTY, cls);
|
|
359
356
|
if (this.getOptions().detectUnannotatedProperties) {
|
|
360
|
-
const jsonSchema =
|
|
361
|
-
if (
|
|
357
|
+
const jsonSchema = JsonSchema.serialize(cls, { appendTarget: true });
|
|
358
|
+
if (hasClassPropertiesInDefinition(clsRef.name, jsonSchema)) {
|
|
362
359
|
const properties = jsonSchema.definitions[clsRef.name].properties;
|
|
363
|
-
for (const k of
|
|
360
|
+
for (const k of keys(properties)) {
|
|
364
361
|
const property = properties[k];
|
|
365
362
|
const opts = {
|
|
366
|
-
metaType:
|
|
363
|
+
metaType: METATYPE_PROPERTY,
|
|
367
364
|
namespace: clsRef.getNamespace(),
|
|
368
365
|
type: property.$target ? property.$target : property.type,
|
|
369
366
|
propertyName: k,
|
|
@@ -372,13 +369,13 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
372
369
|
if (property.default) {
|
|
373
370
|
opts.default = property.default;
|
|
374
371
|
}
|
|
375
|
-
const propMetadata =
|
|
376
|
-
if (!
|
|
372
|
+
const propMetadata = remove(metaPropOptions, x => x.propertyName === k);
|
|
373
|
+
if (!isEmpty(propMetadata)) {
|
|
377
374
|
for (const p of propMetadata) {
|
|
378
375
|
// clean namespace
|
|
379
|
-
const copy =
|
|
376
|
+
const copy = clone(p);
|
|
380
377
|
delete copy.namespace;
|
|
381
|
-
|
|
378
|
+
assign(opts, copy);
|
|
382
379
|
}
|
|
383
380
|
}
|
|
384
381
|
propOptions.push(opts);
|
|
@@ -392,12 +389,12 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
392
389
|
// .filter(x => !this.processing.find((z: IPropertyOptions) => z.propertyName === x.propertyName && z.target === x.target))
|
|
393
390
|
.map(p => {
|
|
394
391
|
// change namespace of properties namespace
|
|
395
|
-
const copy =
|
|
392
|
+
const copy = clone(p);
|
|
396
393
|
copy.namespace = clsRef.getNamespace();
|
|
397
394
|
copy.skipNsCheck = true;
|
|
398
395
|
return copy;
|
|
399
396
|
});
|
|
400
|
-
return propertyOptions.map(opts => clsRef.getRegistry().create(
|
|
397
|
+
return propertyOptions.map(opts => clsRef.getRegistry().create(METATYPE_PROPERTY, opts));
|
|
401
398
|
}
|
|
402
399
|
/**
|
|
403
400
|
* Create default property reference
|
|
@@ -405,11 +402,11 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
405
402
|
* @param options
|
|
406
403
|
*/
|
|
407
404
|
createPropertyForOptions(options) {
|
|
408
|
-
if (
|
|
405
|
+
if (keys(options).length === 0) {
|
|
409
406
|
throw new Error('can\'t create property for empty options');
|
|
410
407
|
}
|
|
411
408
|
options.namespace = this.namespace;
|
|
412
|
-
const prop = new
|
|
409
|
+
const prop = new DefaultPropertyRef(options);
|
|
413
410
|
return this.add(prop.metaType, prop);
|
|
414
411
|
}
|
|
415
412
|
/**
|
|
@@ -420,12 +417,12 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
420
417
|
createEntityForOptions(options) {
|
|
421
418
|
options.namespace = this.namespace;
|
|
422
419
|
if (!options.name) {
|
|
423
|
-
options.name =
|
|
420
|
+
options.name = ClassRef.getClassName(options.target);
|
|
424
421
|
}
|
|
425
|
-
const entityRef = new
|
|
422
|
+
const entityRef = new DefaultEntityRef(options);
|
|
426
423
|
const retRef = this.add(entityRef.metaType, entityRef);
|
|
427
|
-
const metaSchemaOptionsForEntity =
|
|
428
|
-
.getByContextAndTarget(
|
|
424
|
+
const metaSchemaOptionsForEntity = MetadataRegistry.$()
|
|
425
|
+
.getByContextAndTarget(METATYPE_SCHEMA, entityRef.getClass());
|
|
429
426
|
if (metaSchemaOptionsForEntity.length > 0) {
|
|
430
427
|
for (const schemaOptions of metaSchemaOptionsForEntity) {
|
|
431
428
|
this.addSchemaToEntityRef(schemaOptions.name, entityRef);
|
|
@@ -443,8 +440,8 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
443
440
|
// if (!options.name) {
|
|
444
441
|
// options.name = ClassRef.getClassName(options.target);
|
|
445
442
|
// }
|
|
446
|
-
options =
|
|
447
|
-
const classRef = this.getClassRefFor(options.target,
|
|
443
|
+
options = defaults(options || {}, {});
|
|
444
|
+
const classRef = this.getClassRefFor(options.target, METATYPE_CLASS_REF);
|
|
448
445
|
classRef.setOptions(options);
|
|
449
446
|
return classRef;
|
|
450
447
|
}
|
|
@@ -455,7 +452,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
455
452
|
*/
|
|
456
453
|
createSchemaForOptions(options) {
|
|
457
454
|
options.namespace = this.namespace;
|
|
458
|
-
const schemaRef = new
|
|
455
|
+
const schemaRef = new SchemaRef(options);
|
|
459
456
|
return this.add(schemaRef.metaType, schemaRef);
|
|
460
457
|
}
|
|
461
458
|
/**
|
|
@@ -466,14 +463,14 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
466
463
|
* @return IAbstractOptions
|
|
467
464
|
*/
|
|
468
465
|
getMetadata(context, target, propertyName) {
|
|
469
|
-
|
|
466
|
+
const metadataOptionList = MetadataRegistry.$()
|
|
470
467
|
.getByContextAndTarget(context, target, 'merge', propertyName);
|
|
471
468
|
let metadataOptions = {};
|
|
472
469
|
if (metadataOptionList.length > 1) {
|
|
473
|
-
metadataOptions =
|
|
470
|
+
metadataOptions = assign(metadataOptions, ...metadataOptionList.map(x => cloneDeep(x)));
|
|
474
471
|
}
|
|
475
472
|
else if (metadataOptionList.length === 1) {
|
|
476
|
-
metadataOptions =
|
|
473
|
+
metadataOptions = cloneDeep(metadataOptionList.shift());
|
|
477
474
|
}
|
|
478
475
|
if (propertyName) {
|
|
479
476
|
// remove namespace for properties
|
|
@@ -482,44 +479,44 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
482
479
|
return metadataOptions;
|
|
483
480
|
}
|
|
484
481
|
getPropertyRefsFor(fn) {
|
|
485
|
-
const clsName =
|
|
486
|
-
const clsRef =
|
|
482
|
+
const clsName = ClassRef.getClassName(fn);
|
|
483
|
+
const clsRef = ClassRef.get(clsName, this.namespace);
|
|
487
484
|
return this.getPropertyRefs(clsRef);
|
|
488
485
|
}
|
|
489
486
|
create(context, options) {
|
|
490
|
-
const skipNsCheck =
|
|
491
|
-
const failedNsCheck =
|
|
487
|
+
const skipNsCheck = get(options, 'skipNsCheck', false);
|
|
488
|
+
const failedNsCheck = get(options, 'failedNsCheckMode', 'throw');
|
|
492
489
|
delete options.skipNsCheck;
|
|
493
490
|
const metadata = this.getMetadata(context, options.target, options.propertyName ? options.propertyName : null);
|
|
494
491
|
if (metadata) {
|
|
495
492
|
if (metadata.namespace && metadata.namespace !== this.namespace) {
|
|
496
493
|
if (!skipNsCheck) {
|
|
497
|
-
if (context !==
|
|
494
|
+
if (context !== METATYPE_PROPERTY) {
|
|
498
495
|
if (failedNsCheck === 'ignore') {
|
|
499
496
|
return null;
|
|
500
497
|
}
|
|
501
498
|
else {
|
|
502
|
-
throw new
|
|
499
|
+
throw new NotSupportedError('namespace for ' + context + ' is ' + metadata.namespace +
|
|
503
500
|
' the namespace of this registry is ' + this.namespace);
|
|
504
501
|
}
|
|
505
502
|
}
|
|
506
503
|
}
|
|
507
504
|
}
|
|
508
|
-
if (!
|
|
509
|
-
|
|
505
|
+
if (!isEmpty(metadata) && keys(metadata).length > 0) {
|
|
506
|
+
merge(options, assign(metadata, { namespace: this.namespace }));
|
|
510
507
|
}
|
|
511
508
|
}
|
|
512
509
|
options.metaType = context;
|
|
513
510
|
switch (context) {
|
|
514
|
-
case
|
|
511
|
+
case METATYPE_CLASS_REF:
|
|
515
512
|
break;
|
|
516
|
-
case
|
|
513
|
+
case METATYPE_EMBEDDABLE:
|
|
517
514
|
return this.createEmbeddableForOptions(options);
|
|
518
|
-
case
|
|
515
|
+
case METATYPE_ENTITY:
|
|
519
516
|
return this.createEntityForOptions(options);
|
|
520
|
-
case
|
|
517
|
+
case METATYPE_PROPERTY:
|
|
521
518
|
return this.createPropertyForOptions(options);
|
|
522
|
-
case
|
|
519
|
+
case METATYPE_SCHEMA:
|
|
523
520
|
return this.createSchemaForOptions(options);
|
|
524
521
|
}
|
|
525
522
|
return null;
|
|
@@ -528,7 +525,7 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
528
525
|
* TODO
|
|
529
526
|
*/
|
|
530
527
|
add(context, entry) {
|
|
531
|
-
if (context ===
|
|
528
|
+
if (context === METATYPE_CLASS_REF) {
|
|
532
529
|
return this.addClassRef(entry);
|
|
533
530
|
}
|
|
534
531
|
return this.getLookupRegistry().add(context, entry);
|
|
@@ -539,30 +536,30 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
539
536
|
* @param options
|
|
540
537
|
*/
|
|
541
538
|
addClassRef(ref) {
|
|
542
|
-
const addedClassRef = this.getLookupRegistry().add(
|
|
539
|
+
const addedClassRef = this.getLookupRegistry().add(METATYPE_CLASS_REF, ref);
|
|
543
540
|
this.createPropertiesForRef(addedClassRef);
|
|
544
541
|
return addedClassRef;
|
|
545
542
|
}
|
|
546
543
|
getClassRefFor(object, type) {
|
|
547
544
|
let ref = null;
|
|
548
|
-
if (
|
|
549
|
-
ref = this.find(
|
|
545
|
+
if (isString(object)) {
|
|
546
|
+
ref = this.find(METATYPE_CLASS_REF, (x) => x.name === object);
|
|
550
547
|
}
|
|
551
|
-
else if (
|
|
552
|
-
ref = this.find(
|
|
548
|
+
else if (isFunction(object)) {
|
|
549
|
+
ref = this.find(METATYPE_CLASS_REF, (x) => x.getClass(true) === object);
|
|
553
550
|
}
|
|
554
551
|
else {
|
|
555
|
-
ref = this.find(
|
|
552
|
+
ref = this.find(METATYPE_CLASS_REF, (x) => x === object);
|
|
556
553
|
}
|
|
557
554
|
if (!ref) {
|
|
558
|
-
ref =
|
|
559
|
-
resolve: type ===
|
|
555
|
+
ref = ClassRef.get(object, this.namespace, {
|
|
556
|
+
resolve: type === METATYPE_PROPERTY,
|
|
560
557
|
checkNamespace: true
|
|
561
558
|
});
|
|
562
|
-
const metadata = this.getMetadata(
|
|
563
|
-
if (!
|
|
559
|
+
const metadata = this.getMetadata(METATYPE_EMBEDDABLE, object);
|
|
560
|
+
if (!isEmpty(metadata) && keys(metadata).length > 0) {
|
|
564
561
|
const refOptions = ref.getOptions();
|
|
565
|
-
|
|
562
|
+
merge(refOptions, metadata);
|
|
566
563
|
}
|
|
567
564
|
// this.createPropertiesForRef(ref);
|
|
568
565
|
}
|
|
@@ -570,10 +567,9 @@ class DefaultNamespacedRegistry extends AbstractRegistry_1.AbstractRegistry {
|
|
|
570
567
|
}
|
|
571
568
|
reset() {
|
|
572
569
|
super.reset();
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
570
|
+
MetadataRegistry.$().off(C_EVENT_ADD, this.onAdd.bind(this));
|
|
571
|
+
MetadataRegistry.$().off(C_EVENT_REMOVE, this.onRemove.bind(this));
|
|
572
|
+
MetadataRegistry.$().off(C_EVENT_UPDATE, this.onUpdate.bind(this));
|
|
576
573
|
}
|
|
577
574
|
}
|
|
578
|
-
exports.DefaultNamespacedRegistry = DefaultNamespacedRegistry;
|
|
579
575
|
//# sourceMappingURL=DefaultNamespacedRegistry.js.map
|