@allgemein/schema-api 1.5.0
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/LICENSE +23 -0
- package/README.md +34 -0
- package/api/IBaseRef.d.ts +44 -0
- package/api/IBaseRef.js +4 -0
- package/api/IBaseRef.js.map +1 -0
- package/api/IBuildOptions.d.ts +31 -0
- package/api/IBuildOptions.js +4 -0
- package/api/IBuildOptions.js.map +1 -0
- package/api/IClassRef.d.ts +24 -0
- package/api/IClassRef.js +13 -0
- package/api/IClassRef.js.map +1 -0
- package/api/IEntityRef.d.ts +16 -0
- package/api/IEntityRef.js +11 -0
- package/api/IEntityRef.js.map +1 -0
- package/api/IJsonSchema.d.ts +11 -0
- package/api/IJsonSchema.js +26 -0
- package/api/IJsonSchema.js.map +1 -0
- package/api/ILookupRegistry.d.ts +60 -0
- package/api/ILookupRegistry.js +17 -0
- package/api/ILookupRegistry.js.map +1 -0
- package/api/IPropertyExtentions.d.ts +8 -0
- package/api/IPropertyExtentions.js +5 -0
- package/api/IPropertyExtentions.js.map +1 -0
- package/api/IPropertyRef.d.ts +28 -0
- package/api/IPropertyRef.js +13 -0
- package/api/IPropertyRef.js.map +1 -0
- package/api/ISchemaRef.d.ts +8 -0
- package/api/ISchemaRef.js +4 -0
- package/api/ISchemaRef.js.map +1 -0
- package/api/ISerializeSupport.d.ts +11 -0
- package/api/ISerializeSupport.js +26 -0
- package/api/ISerializeSupport.js.map +1 -0
- package/browser.d.ts +62 -0
- package/browser.js +117 -0
- package/browser.js.map +1 -0
- package/decorators/Embeddable.d.ts +2 -0
- package/decorators/Embeddable.js +14 -0
- package/decorators/Embeddable.js.map +1 -0
- package/decorators/Entity.d.ts +2 -0
- package/decorators/Entity.js +14 -0
- package/decorators/Entity.js.map +1 -0
- package/decorators/Namespace.d.ts +1 -0
- package/decorators/Namespace.js +20 -0
- package/decorators/Namespace.js.map +1 -0
- package/decorators/Property.d.ts +3 -0
- package/decorators/Property.js +59 -0
- package/decorators/Property.js.map +1 -0
- package/decorators/PropertyOf.d.ts +2 -0
- package/decorators/PropertyOf.js +28 -0
- package/decorators/PropertyOf.js.map +1 -0
- package/decorators/Schema.d.ts +2 -0
- package/decorators/Schema.js +14 -0
- package/decorators/Schema.js.map +1 -0
- package/decorators/validate/Hostname.d.ts +6 -0
- package/decorators/validate/Hostname.js +38 -0
- package/decorators/validate/Hostname.js.map +1 -0
- package/decorators/validate/Ip4.d.ts +6 -0
- package/decorators/validate/Ip4.js +37 -0
- package/decorators/validate/Ip4.js.map +1 -0
- package/decorators/validate/Ip6.d.ts +5 -0
- package/decorators/validate/Ip6.js +37 -0
- package/decorators/validate/Ip6.js.map +1 -0
- package/decorators/validate/IsEmail.d.ts +5 -0
- package/decorators/validate/IsEmail.js +37 -0
- package/decorators/validate/IsEmail.js.map +1 -0
- package/decorators/validate/IsNotEmpty.d.ts +5 -0
- package/decorators/validate/IsNotEmpty.js +36 -0
- package/decorators/validate/IsNotEmpty.js.map +1 -0
- package/decorators/validate/MaxLength.d.ts +6 -0
- package/decorators/validate/MaxLength.js +34 -0
- package/decorators/validate/MaxLength.js.map +1 -0
- package/decorators/validate/MinLength.d.ts +6 -0
- package/decorators/validate/MinLength.js +34 -0
- package/decorators/validate/MinLength.js.map +1 -0
- package/decorators/validate/Regex.d.ts +7 -0
- package/decorators/validate/Regex.js +46 -0
- package/decorators/validate/Regex.js.map +1 -0
- package/decorators/validate/Required.d.ts +5 -0
- package/decorators/validate/Required.js +34 -0
- package/decorators/validate/Required.js.map +1 -0
- package/decorators/validate/index.d.ts +9 -0
- package/decorators/validate/index.js +21 -0
- package/decorators/validate/index.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +15 -0
- package/index.js.map +1 -0
- package/lib/AbstractRef.d.ts +26 -0
- package/lib/AbstractRef.js +126 -0
- package/lib/AbstractRef.js.map +1 -0
- package/lib/AnnotationsHelper.d.ts +7 -0
- package/lib/AnnotationsHelper.js +97 -0
- package/lib/AnnotationsHelper.js.map +1 -0
- package/lib/ClassRef.d.ts +120 -0
- package/lib/ClassRef.js +319 -0
- package/lib/ClassRef.js.map +1 -0
- package/lib/Constants.d.ts +45 -0
- package/lib/Constants.js +65 -0
- package/lib/Constants.js.map +1 -0
- package/lib/DataContainer.d.ts +31 -0
- package/lib/DataContainer.js +148 -0
- package/lib/DataContainer.js.map +1 -0
- package/lib/LookupRegistry.d.ts +36 -0
- package/lib/LookupRegistry.js +106 -0
- package/lib/LookupRegistry.js.map +1 -0
- package/lib/SchemaRef.d.ts +14 -0
- package/lib/SchemaRef.js +51 -0
- package/lib/SchemaRef.js.map +1 -0
- package/lib/SchemaUtils.d.ts +39 -0
- package/lib/SchemaUtils.js +129 -0
- package/lib/SchemaUtils.js.map +1 -0
- package/lib/json-schema/Constants.d.ts +2 -0
- package/lib/json-schema/Constants.js +7 -0
- package/lib/json-schema/Constants.js.map +1 -0
- package/lib/json-schema/IJsonSchemaSerializeOptions.d.ts +40 -0
- package/lib/json-schema/IJsonSchemaSerializeOptions.js +4 -0
- package/lib/json-schema/IJsonSchemaSerializeOptions.js.map +1 -0
- package/lib/json-schema/IJsonSchemaSerializer.d.ts +7 -0
- package/lib/json-schema/IJsonSchemaSerializer.js +4 -0
- package/lib/json-schema/IJsonSchemaSerializer.js.map +1 -0
- package/lib/json-schema/IJsonSchemaUnserializeOptions.d.ts +41 -0
- package/lib/json-schema/IJsonSchemaUnserializeOptions.js +4 -0
- package/lib/json-schema/IJsonSchemaUnserializeOptions.js.map +1 -0
- package/lib/json-schema/IJsonSchemaUnserializer.d.ts +5 -0
- package/lib/json-schema/IJsonSchemaUnserializer.js +4 -0
- package/lib/json-schema/IJsonSchemaUnserializer.js.map +1 -0
- package/lib/json-schema/IParseOptions.d.ts +16 -0
- package/lib/json-schema/IParseOptions.js +6 -0
- package/lib/json-schema/IParseOptions.js.map +1 -0
- package/lib/json-schema/JsonSchema.d.ts +22 -0
- package/lib/json-schema/JsonSchema.js +109 -0
- package/lib/json-schema/JsonSchema.js.map +1 -0
- package/lib/json-schema/JsonSchema7.d.ts +16 -0
- package/lib/json-schema/JsonSchema7.js +22 -0
- package/lib/json-schema/JsonSchema7.js.map +1 -0
- package/lib/json-schema/JsonSchema7Serializer.d.ts +42 -0
- package/lib/json-schema/JsonSchema7Serializer.js +438 -0
- package/lib/json-schema/JsonSchema7Serializer.js.map +1 -0
- package/lib/json-schema/JsonSchema7Unserializer.d.ts +60 -0
- package/lib/json-schema/JsonSchema7Unserializer.js +499 -0
- package/lib/json-schema/JsonSchema7Unserializer.js.map +1 -0
- package/lib/options/IAbstractOptions.d.ts +19 -0
- package/lib/options/IAbstractOptions.js +4 -0
- package/lib/options/IAbstractOptions.js.map +1 -0
- package/lib/options/IAttributeOptions.d.ts +7 -0
- package/lib/options/IAttributeOptions.js +4 -0
- package/lib/options/IAttributeOptions.js.map +1 -0
- package/lib/options/IEntityOptions.d.ts +4 -0
- package/lib/options/IEntityOptions.js +4 -0
- package/lib/options/IEntityOptions.js.map +1 -0
- package/lib/options/IObjectOptions.d.ts +4 -0
- package/lib/options/IObjectOptions.js +4 -0
- package/lib/options/IObjectOptions.js.map +1 -0
- package/lib/options/IPropertyOptions.d.ts +24 -0
- package/lib/options/IPropertyOptions.js +4 -0
- package/lib/options/IPropertyOptions.js.map +1 -0
- package/lib/options/ISchemaOptions.d.ts +4 -0
- package/lib/options/ISchemaOptions.js +4 -0
- package/lib/options/ISchemaOptions.js.map +1 -0
- package/lib/registry/AbstractRegistry.d.ts +91 -0
- package/lib/registry/AbstractRegistry.js +135 -0
- package/lib/registry/AbstractRegistry.js.map +1 -0
- package/lib/registry/Binding.d.ts +9 -0
- package/lib/registry/Binding.js +17 -0
- package/lib/registry/Binding.js.map +1 -0
- package/lib/registry/DefaultEntityRef.d.ts +30 -0
- package/lib/registry/DefaultEntityRef.js +60 -0
- package/lib/registry/DefaultEntityRef.js.map +1 -0
- package/lib/registry/DefaultNamespacedRegistry.d.ts +153 -0
- package/lib/registry/DefaultNamespacedRegistry.js +511 -0
- package/lib/registry/DefaultNamespacedRegistry.js.map +1 -0
- package/lib/registry/DefaultPropertyRef.d.ts +44 -0
- package/lib/registry/DefaultPropertyRef.js +175 -0
- package/lib/registry/DefaultPropertyRef.js.map +1 -0
- package/lib/registry/MetadataRegistry.d.ts +52 -0
- package/lib/registry/MetadataRegistry.js +186 -0
- package/lib/registry/MetadataRegistry.js.map +1 -0
- package/lib/registry/RegistryFactory.d.ts +43 -0
- package/lib/registry/RegistryFactory.js +109 -0
- package/lib/registry/RegistryFactory.js.map +1 -0
- package/lib/serializer/ISerializeOptions.d.ts +10 -0
- package/lib/serializer/ISerializeOptions.js +4 -0
- package/lib/serializer/ISerializeOptions.js.map +1 -0
- package/lib/serializer/ISerializer.d.ts +5 -0
- package/lib/serializer/ISerializer.js +4 -0
- package/lib/serializer/ISerializer.js.map +1 -0
- package/lib/serializer/ISerializerFactory.d.ts +13 -0
- package/lib/serializer/ISerializerFactory.js +4 -0
- package/lib/serializer/ISerializerFactory.js.map +1 -0
- package/lib/serializer/IUnserializeOptions.d.ts +14 -0
- package/lib/serializer/IUnserializeOptions.js +4 -0
- package/lib/serializer/IUnserializeOptions.js.map +1 -0
- package/lib/serializer/IUnserializer.d.ts +5 -0
- package/lib/serializer/IUnserializer.js +4 -0
- package/lib/serializer/IUnserializer.js.map +1 -0
- package/lib/serializer/SerializerRegistry.d.ts +8 -0
- package/lib/serializer/SerializerRegistry.js +20 -0
- package/lib/serializer/SerializerRegistry.js.map +1 -0
- package/lib/validation/DefaultValidator.d.ts +14 -0
- package/lib/validation/DefaultValidator.js +221 -0
- package/lib/validation/DefaultValidator.js.map +1 -0
- package/lib/validation/IValidateOptions.d.ts +4 -0
- package/lib/validation/IValidateOptions.js +4 -0
- package/lib/validation/IValidateOptions.js.map +1 -0
- package/lib/validation/IValidationError.d.ts +10 -0
- package/lib/validation/IValidationError.js +4 -0
- package/lib/validation/IValidationError.js.map +1 -0
- package/lib/validation/IValidationMessage.d.ts +4 -0
- package/lib/validation/IValidationMessage.js +4 -0
- package/lib/validation/IValidationMessage.js.map +1 -0
- package/lib/validation/IValidationOptions.d.ts +1 -0
- package/lib/validation/IValidationOptions.js +30 -0
- package/lib/validation/IValidationOptions.js.map +1 -0
- package/lib/validation/IValidationResult.d.ts +7 -0
- package/lib/validation/IValidationResult.js +4 -0
- package/lib/validation/IValidationResult.js.map +1 -0
- package/lib/validation/IValidator.d.ts +9 -0
- package/lib/validation/IValidator.js +4 -0
- package/lib/validation/IValidator.js.map +1 -0
- package/lib/validation/IValidatorEntry.d.ts +7 -0
- package/lib/validation/IValidatorEntry.js +4 -0
- package/lib/validation/IValidatorEntry.js.map +1 -0
- package/lib/validation/IValidatorHandle.d.ts +2 -0
- package/lib/validation/IValidatorHandle.js +4 -0
- package/lib/validation/IValidatorHandle.js.map +1 -0
- package/lib/validation/Validator.d.ts +17 -0
- package/lib/validation/Validator.js +54 -0
- package/lib/validation/Validator.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultPropertyRef = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const AbstractRef_1 = require("../AbstractRef");
|
|
6
|
+
const IClassRef_1 = require("../../api/IClassRef");
|
|
7
|
+
const Constants_1 = require("../Constants");
|
|
8
|
+
const ClassRef_1 = require("../ClassRef");
|
|
9
|
+
const base_1 = require("@allgemein/base");
|
|
10
|
+
const AnnotationsHelper_1 = require("../AnnotationsHelper");
|
|
11
|
+
const RegistryFactory_1 = require("./RegistryFactory");
|
|
12
|
+
const IEntityRef_1 = require("../../api/IEntityRef");
|
|
13
|
+
class DefaultPropertyRef extends AbstractRef_1.AbstractRef {
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
super(Constants_1.METATYPE_PROPERTY, options.propertyName, options.target, options.namespace ? options.namespace : Constants_1.DEFAULT_NAMESPACE);
|
|
16
|
+
this.cardinality = 1;
|
|
17
|
+
this.reference = undefined;
|
|
18
|
+
AnnotationsHelper_1.AnnotationsHelper.merge(this.object, options, this.name);
|
|
19
|
+
this.setOptions(options);
|
|
20
|
+
this.cardinality = lodash_1.has(options, 'cardinality') ? options.cardinality : 1;
|
|
21
|
+
}
|
|
22
|
+
getRegistry() {
|
|
23
|
+
return RegistryFactory_1.RegistryFactory.get(this.namespace);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* TODO
|
|
27
|
+
*/
|
|
28
|
+
convert(data, options) {
|
|
29
|
+
const sourceType = this.getType();
|
|
30
|
+
if (!sourceType || !lodash_1.isString(sourceType)) {
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
const jsType = sourceType.toLowerCase();
|
|
34
|
+
const [baseType, variant] = jsType.split(':');
|
|
35
|
+
switch (baseType) {
|
|
36
|
+
case 'datetime':
|
|
37
|
+
case 'timestamp':
|
|
38
|
+
case 'date':
|
|
39
|
+
return new Date(data);
|
|
40
|
+
case 'time':
|
|
41
|
+
case 'text':
|
|
42
|
+
case Constants_1.T_STRING:
|
|
43
|
+
if (lodash_1.isString(data)) {
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
else if (lodash_1.isArray(data) && data.length === 1) {
|
|
47
|
+
return data[0];
|
|
48
|
+
}
|
|
49
|
+
else if (data) {
|
|
50
|
+
return JSON.stringify(data);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'boolean':
|
|
57
|
+
if (lodash_1.isBoolean(data)) {
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
else if (lodash_1.isNumber(data)) {
|
|
61
|
+
return data > 0;
|
|
62
|
+
}
|
|
63
|
+
else if (lodash_1.isString(data)) {
|
|
64
|
+
if (data.toLowerCase() === 'true' || data.toLowerCase() === '1') {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case 'double':
|
|
71
|
+
case 'number':
|
|
72
|
+
if (lodash_1.isString(data)) {
|
|
73
|
+
if (/^\d+\.|\,\d+$/.test(data)) {
|
|
74
|
+
return parseFloat(data.replace(',', '.'));
|
|
75
|
+
}
|
|
76
|
+
else if (/^\d+$/.test(data)) {
|
|
77
|
+
return parseInt(data, 0);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (lodash_1.isNumber(data)) {
|
|
83
|
+
return data;
|
|
84
|
+
}
|
|
85
|
+
else if (lodash_1.isBoolean(data)) {
|
|
86
|
+
return data ? 1 : 0;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Pass to exception
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
case 'byte':
|
|
93
|
+
case 'json':
|
|
94
|
+
case Constants_1.T_OBJECT:
|
|
95
|
+
case Constants_1.T_ARRAY:
|
|
96
|
+
return data;
|
|
97
|
+
}
|
|
98
|
+
throw new base_1.NotYetImplementedError('value "' + data + '" of type ' + (typeof data) + ' column type=' + jsType);
|
|
99
|
+
}
|
|
100
|
+
get(instance) {
|
|
101
|
+
return lodash_1.get(instance, this.name, null);
|
|
102
|
+
}
|
|
103
|
+
getTargetRef() {
|
|
104
|
+
this.checkReference();
|
|
105
|
+
return this.targetRef;
|
|
106
|
+
}
|
|
107
|
+
getType() {
|
|
108
|
+
return this.getOptions('type');
|
|
109
|
+
}
|
|
110
|
+
isAppended() {
|
|
111
|
+
return this.getOptions('appended', false);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* TODO
|
|
115
|
+
*/
|
|
116
|
+
id() {
|
|
117
|
+
return [this.getClassRef().id(), this.name].join(Constants_1.XS_ID_SEPARATOR);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* check if property parameter is an array
|
|
121
|
+
*/
|
|
122
|
+
isCollection() {
|
|
123
|
+
if (lodash_1.isObjectLike(this.cardinality) &&
|
|
124
|
+
this.cardinality.min >= 0 &&
|
|
125
|
+
this.cardinality.max >= 0) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return this.cardinality !== 1;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Return if is identifier
|
|
132
|
+
*/
|
|
133
|
+
isIdentifier() {
|
|
134
|
+
return this.getOptions('identifier', false);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Return if is a pattern property
|
|
138
|
+
*/
|
|
139
|
+
isPattern() {
|
|
140
|
+
return this.getOptions(Constants_1.K_PATTERN_PROPERTY, false);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Returns info if property parameter results are in classspace
|
|
144
|
+
*/
|
|
145
|
+
isReference() {
|
|
146
|
+
this.checkReference();
|
|
147
|
+
return this.reference;
|
|
148
|
+
}
|
|
149
|
+
checkReference() {
|
|
150
|
+
if (lodash_1.isUndefined(this.reference)) {
|
|
151
|
+
this.reference = false;
|
|
152
|
+
const type = this.getType();
|
|
153
|
+
if (!lodash_1.isString(type) && (IClassRef_1.isClassRef(type) || IEntityRef_1.isEntityRef(type))) {
|
|
154
|
+
this.targetRef = IEntityRef_1.isEntityRef(type) ? type.getClassRef() : type;
|
|
155
|
+
this.reference = true;
|
|
156
|
+
}
|
|
157
|
+
else if (lodash_1.isFunction(type) ||
|
|
158
|
+
(lodash_1.isString(type) && !Constants_1.JS_DATA_TYPES.find(t => (new RegExp('^' + t + ':?')).test(type.toLowerCase())))) {
|
|
159
|
+
// try get existing class
|
|
160
|
+
const exists = ClassRef_1.ClassRef.get(type, this.getClassRef().getNamespace());
|
|
161
|
+
if (exists) {
|
|
162
|
+
this.targetRef = exists;
|
|
163
|
+
this.reference = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return this.reference;
|
|
168
|
+
}
|
|
169
|
+
getClassRefFor(object, type) {
|
|
170
|
+
return this.getRegistry().getClassRefFor(object, this.metaType);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.DefaultPropertyRef = DefaultPropertyRef;
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=DefaultPropertyRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/registry/DefaultPropertyRef.ts"],"names":[],"mappings":";;;AAAA,mCAA+G;AAG/G,gDAA2C;AAE3C,mDAA0D;AAC1D,4CAOsB;AAEtB,0CAAqC;AACrC,0CAAuD;AACvD,4DAAuD;AAEvD,uDAAkD;AAClD,qDAA6D;AAG7D,MAAa,kBAAmB,SAAQ,yBAAW;IAQjD,YAAY,UAA4B,EAAE;QACxC,KAAK,CAAC,6BAAiB,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,6BAAiB,CAAC,CAAC;QAP5H,gBAAW,GAAqB,CAAC,CAAC;QAElC,cAAS,GAAY,SAAS,CAAC;QAM7B,qCAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,YAAG,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,CAAC;IAGD,WAAW;QACT,OAAO,iCAAe,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,IAAS,EAAE,OAAuB;QACxC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAClC,IAAI,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CAAC,iBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAU,IAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE;gBAC/G,yBAAyB;gBACzB,MAAM,MAAM,GAAG,mBAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC;gBACrE,IAAI,MAAM,EAAE;oBACV,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;oBACxB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;iBACvB;aACF;SACF;QACD,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,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;CAGF;AAnLD,gDAmLC","file":"DefaultPropertyRef.js","sourcesContent":["import {get, has, isArray, isBoolean, isFunction, isNumber, isObjectLike, isString, isUndefined} from 'lodash';\n\nimport {IPropertyRef} from '../../api/IPropertyRef';\nimport {AbstractRef} from '../AbstractRef';\nimport {IBuildOptions} from '../../api/IBuildOptions';\nimport {IClassRef, isClassRef} from '../../api/IClassRef';\nimport {\n DEFAULT_NAMESPACE,\n IMinMax,\n JS_DATA_TYPES, K_PATTERN_PROPERTY,\n METADATA_TYPE,\n METATYPE_PROPERTY, T_ARRAY, T_OBJECT, T_STRING,\n XS_ID_SEPARATOR\n} from '../Constants';\nimport {IPropertyOptions} from '../options/IPropertyOptions';\nimport {ClassRef} from '../ClassRef';\nimport {NotYetImplementedError} from '@allgemein/base';\nimport {AnnotationsHelper} from '../AnnotationsHelper';\nimport {ILookupRegistry} from '../../api/ILookupRegistry';\nimport {RegistryFactory} from './RegistryFactory';\nimport {IEntityRef, isEntityRef} from '../../api/IEntityRef';\n\n\nexport class DefaultPropertyRef extends AbstractRef implements IPropertyRef {\n\n cardinality: IMinMax | number = 1;\n\n reference: boolean = undefined;\n\n targetRef: IClassRef;\n\n constructor(options: IPropertyOptions = {}) {\n super(METATYPE_PROPERTY, options.propertyName, options.target, options.namespace ? options.namespace : DEFAULT_NAMESPACE);\n AnnotationsHelper.merge(this.object, options, this.name);\n this.setOptions(options);\n this.cardinality = has(options, 'cardinality') ? options.cardinality : 1;\n }\n\n\n getRegistry(): ILookupRegistry {\n return RegistryFactory.get(this.namespace);\n }\n\n /**\n * TODO\n */\n convert(data: any, options?: IBuildOptions): any {\n const sourceType = this.getType();\n if (!sourceType || !isString(sourceType)) {\n return data;\n }\n\n const jsType = sourceType.toLowerCase();\n const [baseType, variant] = jsType.split(':');\n\n switch (baseType) {\n case 'datetime':\n case 'timestamp':\n case 'date':\n return new Date(data);\n\n case 'time':\n case 'text':\n case T_STRING:\n if (isString(data)) {\n return data;\n } else if (isArray(data) && data.length === 1) {\n return data[0];\n } else if (data) {\n return JSON.stringify(data);\n } else {\n return null;\n }\n break;\n\n case 'boolean':\n if (isBoolean(data)) {\n return data;\n } else if (isNumber(data)) {\n return data > 0;\n } else if (isString(data)) {\n if (data.toLowerCase() === 'true' || data.toLowerCase() === '1') {\n return true;\n }\n return false;\n }\n break;\n\n case 'double':\n case 'number':\n if (isString(data)) {\n if (/^\\d+\\.|\\,\\d+$/.test(data)) {\n return parseFloat(data.replace(',', '.'));\n } else if (/^\\d+$/.test(data)) {\n return parseInt(data, 0);\n } else {\n }\n } else if (isNumber(data)) {\n return data;\n } else if (isBoolean(data)) {\n return data ? 1 : 0;\n } else {\n // Pass to exception\n }\n break;\n\n case 'byte':\n case 'json':\n case T_OBJECT:\n case T_ARRAY:\n return data;\n }\n\n throw new NotYetImplementedError('value \"' + data + '\" of type ' + (typeof data) + ' column type=' + jsType);\n }\n\n\n get(instance: any): any {\n return get(instance, this.name, null);\n }\n\n\n getTargetRef(): IClassRef {\n this.checkReference();\n return this.targetRef;\n }\n\n getType(): string {\n return this.getOptions('type');\n }\n\n isAppended(): boolean {\n return this.getOptions('appended', false);\n }\n\n\n /**\n * TODO\n */\n id(): string {\n return [this.getClassRef().id(), this.name].join(XS_ID_SEPARATOR);\n }\n\n /**\n * check if property parameter is an array\n */\n isCollection(): boolean {\n if (isObjectLike(this.cardinality) &&\n (<IMinMax>this.cardinality).min >= 0 &&\n (<IMinMax>this.cardinality).max >= 0) {\n return true;\n }\n return this.cardinality !== 1;\n }\n\n /**\n * Return if is identifier\n */\n isIdentifier(): boolean {\n return this.getOptions('identifier', false);\n }\n\n /**\n * Return if is a pattern property\n */\n isPattern(): boolean {\n return this.getOptions(K_PATTERN_PROPERTY, false);\n }\n\n /**\n * Returns info if property parameter results are in classspace\n */\n isReference(): boolean {\n this.checkReference();\n return this.reference;\n }\n\n private checkReference() {\n if (isUndefined(this.reference)) {\n this.reference = false;\n const type = this.getType();\n if (!isString(type) && (isClassRef(type) || isEntityRef(type))) {\n this.targetRef = isEntityRef(type) ? (type as IEntityRef).getClassRef() : type;\n this.reference = true;\n } else if (isFunction(type) ||\n (isString(type) && !JS_DATA_TYPES.find(t => (new RegExp('^' + t + ':?')).test((<string>type).toLowerCase())))) {\n // try get existing class\n const exists = ClassRef.get(type, this.getClassRef().getNamespace());\n if (exists) {\n this.targetRef = exists;\n this.reference = true;\n }\n }\n }\n return this.reference;\n }\n\n getClassRefFor(object: string | Function | IClassRef, type: METADATA_TYPE): IClassRef {\n return this.getRegistry().getClassRefFor(object, this.metaType);\n }\n\n\n}\n"],"sourceRoot":"../.."}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Handler for metadata
|
|
4
|
+
*/
|
|
5
|
+
import { CLASS_TYPE, METADATA_TYPE } from './../Constants';
|
|
6
|
+
import { IEntityOptions } from './../options/IEntityOptions';
|
|
7
|
+
import { IPropertyOptions } from './../options/IPropertyOptions';
|
|
8
|
+
import { ISchemaOptions } from './../options/ISchemaOptions';
|
|
9
|
+
import { IObjectOptions } from './../options/IObjectOptions';
|
|
10
|
+
import { EventEmitter } from 'events';
|
|
11
|
+
import { IAbstractOptions } from '../options/IAbstractOptions';
|
|
12
|
+
import { IAttributeOptions } from '../options/IAttributeOptions';
|
|
13
|
+
/**
|
|
14
|
+
* Registry for metadata of classes and there properties
|
|
15
|
+
*/
|
|
16
|
+
export declare class MetadataRegistry extends EventEmitter {
|
|
17
|
+
private static INC;
|
|
18
|
+
private static $self;
|
|
19
|
+
private readonly metadata;
|
|
20
|
+
private readonly cached;
|
|
21
|
+
private schemas;
|
|
22
|
+
private targets;
|
|
23
|
+
constructor();
|
|
24
|
+
static $(): MetadataRegistry;
|
|
25
|
+
static reset(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Add typed element to the local registry
|
|
28
|
+
*
|
|
29
|
+
* @param context
|
|
30
|
+
* @param options
|
|
31
|
+
*/
|
|
32
|
+
add(context: METADATA_TYPE | string, options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions | IAttributeOptions, trigger?: boolean): IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions | IAttributeOptions;
|
|
33
|
+
addCached(context: METADATA_TYPE | string, options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions | IAttributeOptions): IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions | IAttributeOptions;
|
|
34
|
+
notify(eventName: string, context: string, options: any): void;
|
|
35
|
+
remove(context: METADATA_TYPE | string, c: (x: any) => boolean, trigger?: boolean): void;
|
|
36
|
+
getByContext<T extends IAbstractOptions>(context: METADATA_TYPE): T[];
|
|
37
|
+
getTargets(): any[];
|
|
38
|
+
getByContextAndTarget<T extends IAbstractOptions>(context: METADATA_TYPE | string, target: CLASS_TYPE | string, attributes?: 'merge' | 'assign' | 'defaults', propertyName?: string): T[];
|
|
39
|
+
mergeAttributes(context: METADATA_TYPE | string, target: CLASS_TYPE | string, data: IPropertyOptions | IEntityOptions | IObjectOptions | ISchemaOptions, mode?: 'merge' | 'assign' | 'defaults'): void;
|
|
40
|
+
getAttributesForTarget<T extends IAttributeOptions>(context: METADATA_TYPE | string, target: CLASS_TYPE | string): T[];
|
|
41
|
+
getAttributesForTargetProperty<T extends IAttributeOptions>(context: METADATA_TYPE, target: CLASS_TYPE, propertyName: string): T[];
|
|
42
|
+
getAttributesForTargetProperties<T extends IAttributeOptions>(context: METADATA_TYPE, target: CLASS_TYPE | string): T[];
|
|
43
|
+
getByTarget(target: CLASS_TYPE): IAbstractOptions[];
|
|
44
|
+
private createSearchFunction;
|
|
45
|
+
find(context: METADATA_TYPE | string, find: CLASS_TYPE): IAbstractOptions;
|
|
46
|
+
findCached(context: METADATA_TYPE | string, find: CLASS_TYPE): IAbstractOptions;
|
|
47
|
+
filter(context: METADATA_TYPE | string, find: CLASS_TYPE): IAbstractOptions[];
|
|
48
|
+
getMetadata(): IAbstractOptions[];
|
|
49
|
+
getCached(): IAbstractOptions[];
|
|
50
|
+
getSchemas(): any[];
|
|
51
|
+
getMetadatasForSchema(schema: string): IAbstractOptions[];
|
|
52
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MetadataRegistry = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
/**
|
|
6
|
+
* Handler for metadata
|
|
7
|
+
*/
|
|
8
|
+
const Constants_1 = require("./../Constants");
|
|
9
|
+
const base_1 = require("@allgemein/base");
|
|
10
|
+
const events_1 = require("events");
|
|
11
|
+
/**
|
|
12
|
+
* Registry for metadata of classes and there properties
|
|
13
|
+
*/
|
|
14
|
+
class MetadataRegistry extends events_1.EventEmitter {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.metadata = [];
|
|
18
|
+
this.cached = [];
|
|
19
|
+
this.schemas = [];
|
|
20
|
+
this.targets = [];
|
|
21
|
+
this.setMaxListeners(1000);
|
|
22
|
+
this.targets = [];
|
|
23
|
+
this.schemas = [];
|
|
24
|
+
this.metadata = base_1.MetadataStorage.key(Constants_1.METADATA_REGISTRY);
|
|
25
|
+
}
|
|
26
|
+
static $() {
|
|
27
|
+
if (!this.$self) {
|
|
28
|
+
this.$self = new MetadataRegistry();
|
|
29
|
+
}
|
|
30
|
+
return this.$self;
|
|
31
|
+
}
|
|
32
|
+
static reset() {
|
|
33
|
+
this.$self = null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Add typed element to the local registry
|
|
37
|
+
*
|
|
38
|
+
* @param context
|
|
39
|
+
* @param options
|
|
40
|
+
*/
|
|
41
|
+
add(context, options, trigger = true) {
|
|
42
|
+
options.metaType = context;
|
|
43
|
+
// find?
|
|
44
|
+
const id = MetadataRegistry.INC++;
|
|
45
|
+
this.metadata.push(options);
|
|
46
|
+
if (this.targets.indexOf(options.target) === -1) {
|
|
47
|
+
this.targets.push(options.target);
|
|
48
|
+
}
|
|
49
|
+
if (context === Constants_1.METATYPE_SCHEMA) {
|
|
50
|
+
if (this.schemas.indexOf(options.name) === -1) {
|
|
51
|
+
this.schemas.push(options.name);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (trigger) {
|
|
55
|
+
Object.defineProperty(options, Constants_1.K_TRIGGERED, { value: true });
|
|
56
|
+
this.notify(Constants_1.C_EVENT_ADD, context, options);
|
|
57
|
+
}
|
|
58
|
+
return options;
|
|
59
|
+
}
|
|
60
|
+
addCached(context, options) {
|
|
61
|
+
options.metaType = context;
|
|
62
|
+
this.cached.push(options);
|
|
63
|
+
return options;
|
|
64
|
+
}
|
|
65
|
+
notify(eventName, context, options) {
|
|
66
|
+
this.emit(eventName, context, options);
|
|
67
|
+
}
|
|
68
|
+
remove(context, c, trigger = true) {
|
|
69
|
+
const removed = lodash_1.remove(this.metadata, x => x.metaType === context && c(x));
|
|
70
|
+
if (!lodash_1.isEmpty(removed) && trigger) {
|
|
71
|
+
this.notify(Constants_1.C_EVENT_REMOVE, context, removed);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// private update(context: METADATA_TYPE) {
|
|
75
|
+
// this.emit(C_EVENT_UPDATE, {});
|
|
76
|
+
// }
|
|
77
|
+
getByContext(context) {
|
|
78
|
+
return this.metadata.filter(x => x.metaType === context);
|
|
79
|
+
}
|
|
80
|
+
getTargets() {
|
|
81
|
+
return this.targets;
|
|
82
|
+
}
|
|
83
|
+
getByContextAndTarget(context, target, attributes = null, propertyName) {
|
|
84
|
+
const data = this.metadata.filter(x => x.metaType === context &&
|
|
85
|
+
x.target === target &&
|
|
86
|
+
(propertyName ? x.propertyName === propertyName : true));
|
|
87
|
+
if (attributes && !lodash_1.isEmpty(data)) {
|
|
88
|
+
this.mergeAttributes(context, target, data, attributes);
|
|
89
|
+
}
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
mergeAttributes(context, target, data, mode = null) {
|
|
93
|
+
let attributes = [];
|
|
94
|
+
if (context === Constants_1.METATYPE_PROPERTY) {
|
|
95
|
+
// merge with properties
|
|
96
|
+
attributes = this.getAttributesForTargetProperties(context, target);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
attributes = this.getAttributesForTarget(context, target);
|
|
100
|
+
}
|
|
101
|
+
for (const attribute of attributes) {
|
|
102
|
+
let toExtend = null;
|
|
103
|
+
if (attribute.propertyName) {
|
|
104
|
+
toExtend = data.find((x) => x.metaType === Constants_1.METATYPE_PROPERTY && x.propertyName === attribute.propertyName);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
toExtend = data.find((x) => x.metaType === context);
|
|
108
|
+
}
|
|
109
|
+
if (toExtend) {
|
|
110
|
+
switch (mode) {
|
|
111
|
+
case 'assign':
|
|
112
|
+
lodash_1.assign(toExtend, attribute.attributes);
|
|
113
|
+
break;
|
|
114
|
+
case 'merge':
|
|
115
|
+
lodash_1.merge(toExtend, attribute.attributes);
|
|
116
|
+
break;
|
|
117
|
+
case 'defaults':
|
|
118
|
+
lodash_1.defaults(toExtend, attribute.attributes);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getAttributesForTarget(context, target) {
|
|
125
|
+
return this.metadata.filter((x) => x.targetTypes &&
|
|
126
|
+
!x.propertyName &&
|
|
127
|
+
x.attributes &&
|
|
128
|
+
x.targetTypes.includes(context) &&
|
|
129
|
+
x.target === target);
|
|
130
|
+
}
|
|
131
|
+
getAttributesForTargetProperty(context, target, propertyName) {
|
|
132
|
+
return this.metadata.filter((x) => x.targetTypes &&
|
|
133
|
+
x.propertyName === propertyName &&
|
|
134
|
+
x.attributes &&
|
|
135
|
+
x.targetTypes.includes(context) &&
|
|
136
|
+
x.target === target);
|
|
137
|
+
}
|
|
138
|
+
getAttributesForTargetProperties(context, target) {
|
|
139
|
+
return this.metadata.filter((x) => x.targetTypes &&
|
|
140
|
+
x.propertyName &&
|
|
141
|
+
x.attributes &&
|
|
142
|
+
x.targetTypes.includes(context) &&
|
|
143
|
+
x.target === target);
|
|
144
|
+
}
|
|
145
|
+
getByTarget(target) {
|
|
146
|
+
return this.metadata.filter(x => x.target === target);
|
|
147
|
+
}
|
|
148
|
+
createSearchFunction(find) {
|
|
149
|
+
let lookup = find;
|
|
150
|
+
if (!lodash_1.isFunction(find)) {
|
|
151
|
+
const _keys = lodash_1.keys(find);
|
|
152
|
+
lookup = (x) => {
|
|
153
|
+
return _keys.map(k => find[k] === x[k]).reduce((previousValue, currentValue) => previousValue && currentValue);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return lookup;
|
|
157
|
+
}
|
|
158
|
+
find(context, find) {
|
|
159
|
+
const lookup = this.createSearchFunction(find);
|
|
160
|
+
return this.metadata.find((x => x.metaType === context && lookup(x)));
|
|
161
|
+
}
|
|
162
|
+
findCached(context, find) {
|
|
163
|
+
const lookup = this.createSearchFunction(find);
|
|
164
|
+
return this.cached.find((x => x.metaType === context && lookup(x)));
|
|
165
|
+
}
|
|
166
|
+
filter(context, find) {
|
|
167
|
+
const lookup = this.createSearchFunction(find);
|
|
168
|
+
return this.metadata.filter((x => x.context === context && lookup(x)));
|
|
169
|
+
}
|
|
170
|
+
getMetadata() {
|
|
171
|
+
return this.metadata;
|
|
172
|
+
}
|
|
173
|
+
getCached() {
|
|
174
|
+
return this.cached;
|
|
175
|
+
}
|
|
176
|
+
getSchemas() {
|
|
177
|
+
return lodash_1.uniq(this.metadata.filter((x => x.context === Constants_1.METATYPE_SCHEMA)).map(x => x.name));
|
|
178
|
+
}
|
|
179
|
+
getMetadatasForSchema(schema) {
|
|
180
|
+
return this.metadata.filter((x => x.context === Constants_1.METATYPE_SCHEMA && x.name === schema));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.MetadataRegistry = MetadataRegistry;
|
|
184
|
+
MetadataRegistry.INC = 0;
|
|
185
|
+
|
|
186
|
+
//# sourceMappingURL=MetadataRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/registry/MetadataRegistry.ts"],"names":[],"mappings":";;;AAAA,mCAAwF;AAExF;;GAEG;AACH,8CAQwB;AAKxB,0CAAgD;AAChD,mCAAoC;AAIpC;;GAEG;AACH,MAAa,gBAAiB,SAAQ,qBAAY;IAehD;QACE,KAAK,EAAE,CAAC;QAVO,aAAQ,GAAuB,EAAE,CAAC;QAElC,WAAM,GAAuB,EAAE,CAAC;QAEzC,YAAO,GAAa,EAAE,CAAC;QAEvB,YAAO,GAAU,EAAE,CAAC;QAK1B,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,QAAQ,GA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,CAAC,CAAC;IACzE,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAGD,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,UAAU;QACR,OAAO,aAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,2BAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED,qBAAqB,CAAC,MAAc;QAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,2BAAe,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC;IACzF,CAAC;;AA9OH,4CAiPC;AA/OgB,oBAAG,GAAG,CAAC,CAAC","file":"MetadataRegistry.js","sourcesContent":["import {assign, defaults, isEmpty, isFunction, keys, merge, remove, uniq} from 'lodash';\n\n/**\n * Handler for metadata\n */\nimport {\n C_EVENT_ADD,\n C_EVENT_REMOVE,\n CLASS_TYPE, K_TRIGGERED,\n METADATA_REGISTRY,\n METADATA_TYPE,\n METATYPE_PROPERTY,\n METATYPE_SCHEMA\n} from './../Constants';\nimport {IEntityOptions} from './../options/IEntityOptions';\nimport {IPropertyOptions} from './../options/IPropertyOptions';\nimport {ISchemaOptions} from './../options/ISchemaOptions';\nimport {IObjectOptions} from './../options/IObjectOptions';\nimport {MetadataStorage} from '@allgemein/base';\nimport {EventEmitter} from 'events';\nimport {IAbstractOptions} from '../options/IAbstractOptions';\nimport {IAttributeOptions} from '../options/IAttributeOptions';\n\n/**\n * Registry for metadata of classes and there properties\n */\nexport class MetadataRegistry extends EventEmitter {\n\n private static INC = 0;\n\n private static $self: MetadataRegistry;\n\n private readonly metadata: IAbstractOptions[] = [];\n\n private readonly cached: IAbstractOptions[] = [];\n\n private schemas: string[] = [];\n\n private targets: any[] = [];\n\n\n constructor() {\n super();\n this.setMaxListeners(1000);\n this.targets = [];\n this.schemas = [];\n this.metadata = MetadataStorage.key(METADATA_REGISTRY);\n }\n\n\n static $() {\n if (!this.$self) {\n this.$self = new MetadataRegistry();\n }\n return this.$self;\n }\n\n\n static reset() {\n this.$self = null;\n }\n\n\n /**\n * Add typed element to the local registry\n *\n * @param context\n * @param options\n */\n add(context: METADATA_TYPE | string,\n options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions | IAttributeOptions,\n trigger: boolean = true) {\n options.metaType = context;\n\n // find?\n const id = MetadataRegistry.INC++;\n this.metadata.push(options);\n if (this.targets.indexOf(options.target) === -1) {\n this.targets.push(options.target);\n }\n if (context === METATYPE_SCHEMA) {\n if (this.schemas.indexOf(options.name) === -1) {\n this.schemas.push(options.name);\n }\n }\n\n if (trigger) {\n Object.defineProperty(options, K_TRIGGERED, {value: true});\n this.notify(C_EVENT_ADD, context, options);\n }\n\n return options;\n }\n\n addCached(context: METADATA_TYPE | string,\n options: IEntityOptions | IPropertyOptions | ISchemaOptions | IObjectOptions | IAttributeOptions) {\n options.metaType = context;\n this.cached.push(options);\n return options;\n }\n\n notify(eventName: string, context: string, options: any) {\n this.emit(eventName, context, options);\n }\n\n\n remove(context: METADATA_TYPE | string, c: (x: any) => boolean, trigger: boolean = true) {\n const removed = remove(this.metadata, x => x.metaType === context && c(x));\n if (!isEmpty(removed) && trigger) {\n this.notify(C_EVENT_REMOVE, context, removed);\n }\n }\n\n // private update(context: METADATA_TYPE) {\n // this.emit(C_EVENT_UPDATE, {});\n // }\n\n getByContext<T extends IAbstractOptions>(context: METADATA_TYPE): T[] {\n return <T[]>this.metadata.filter(x =>\n x.metaType === context\n );\n }\n\n\n getTargets() {\n return this.targets;\n }\n\n\n getByContextAndTarget<T extends IAbstractOptions>(context: METADATA_TYPE | string,\n target: CLASS_TYPE | string,\n attributes: 'merge' | 'assign' | 'defaults' = null,\n propertyName?: string): T[] {\n const data = <T[]>this.metadata.filter(x =>\n x.metaType === context &&\n x.target === target &&\n (propertyName ? x.propertyName === propertyName : true)\n );\n if (attributes && !isEmpty(data)) {\n this.mergeAttributes(context, target, data, attributes);\n }\n return data;\n }\n\n\n mergeAttributes(context: METADATA_TYPE | string,\n target: CLASS_TYPE | string,\n data: IPropertyOptions | IEntityOptions | IObjectOptions | ISchemaOptions,\n mode: 'merge' | 'assign' | 'defaults' = null) {\n let attributes: IAttributeOptions[] = [];\n if (context === METATYPE_PROPERTY) {\n // merge with properties\n attributes = this.getAttributesForTargetProperties(context, target);\n } else {\n attributes = this.getAttributesForTarget(context, target);\n }\n\n for (const attribute of attributes) {\n let toExtend = null;\n if (attribute.propertyName) {\n toExtend = data.find((x: IPropertyOptions) => x.metaType === METATYPE_PROPERTY && x.propertyName === attribute.propertyName);\n } else {\n toExtend = data.find((x: IAbstractOptions) => x.metaType === context);\n }\n if (toExtend) {\n switch (mode) {\n case 'assign':\n assign(toExtend, attribute.attributes);\n break;\n case 'merge':\n merge(toExtend, attribute.attributes);\n break;\n case 'defaults':\n defaults(toExtend, attribute.attributes);\n break;\n }\n\n }\n }\n }\n\n getAttributesForTarget<T extends IAttributeOptions>(context: METADATA_TYPE | string,\n target: CLASS_TYPE | string): T[] {\n return <T[]>this.metadata.filter((x: IAttributeOptions) =>\n x.targetTypes &&\n !x.propertyName &&\n x.attributes &&\n x.targetTypes.includes(context) &&\n x.target === target\n );\n }\n\n getAttributesForTargetProperty<T extends IAttributeOptions>(context: METADATA_TYPE,\n target: CLASS_TYPE,\n propertyName: string): T[] {\n return <T[]>this.metadata.filter((x: IAttributeOptions) =>\n x.targetTypes &&\n x.propertyName === propertyName &&\n x.attributes &&\n x.targetTypes.includes(context) &&\n x.target === target\n );\n }\n\n getAttributesForTargetProperties<T extends IAttributeOptions>(context: METADATA_TYPE, target: CLASS_TYPE | string): T[] {\n return <T[]>this.metadata.filter((x: IAttributeOptions) =>\n x.targetTypes &&\n x.propertyName &&\n x.attributes &&\n x.targetTypes.includes(context) &&\n x.target === target\n );\n }\n\n getByTarget(target: CLASS_TYPE) {\n return this.metadata.filter(x =>\n x.target === target\n );\n }\n\n private createSearchFunction(find: any) {\n let lookup = find;\n if (!isFunction(find)) {\n const _keys = keys(find);\n lookup = (x: any) => {\n return _keys.map(k => find[k] === x[k]).reduce((previousValue, currentValue) => previousValue && currentValue);\n };\n }\n return lookup;\n }\n\n\n find(context: METADATA_TYPE | string, find: CLASS_TYPE) {\n const lookup = this.createSearchFunction(find);\n return this.metadata.find((x => x.metaType === context && lookup(x)));\n }\n\n\n findCached(context: METADATA_TYPE | string, find: CLASS_TYPE) {\n const lookup = this.createSearchFunction(find);\n return this.cached.find((x => x.metaType === context && lookup(x)));\n }\n\n\n filter(context: METADATA_TYPE | string, find: CLASS_TYPE) {\n const lookup = this.createSearchFunction(find);\n return this.metadata.filter((x => x.context === context && lookup(x)));\n }\n\n getMetadata() {\n return this.metadata;\n }\n\n\n getCached() {\n return this.cached;\n }\n\n getSchemas() {\n return uniq(this.metadata.filter((x => x.context === METATYPE_SCHEMA)).map(x => x.name));\n }\n\n getMetadatasForSchema(schema: string) {\n return this.metadata.filter((x => x.context === METATYPE_SCHEMA && x.name === schema));\n }\n\n\n}\n"],"sourceRoot":"../.."}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ILookupRegistry } from '../../api/ILookupRegistry';
|
|
2
|
+
import { ClassType } from '../Constants';
|
|
3
|
+
export declare class RegistryFactory {
|
|
4
|
+
static $types: {
|
|
5
|
+
pattern: string | RegExp;
|
|
6
|
+
registryClass: ClassType<ILookupRegistry>;
|
|
7
|
+
}[];
|
|
8
|
+
static $handles: {
|
|
9
|
+
[key: string]: ILookupRegistry;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Return the registry handling schema/objects of given context or if not exists the generic default namescaped registry
|
|
13
|
+
*
|
|
14
|
+
* @param namespace
|
|
15
|
+
*/
|
|
16
|
+
static get<T extends ILookupRegistry>(namespace?: string): T;
|
|
17
|
+
/**
|
|
18
|
+
* Remove registry from handles list
|
|
19
|
+
*
|
|
20
|
+
* @param namespace
|
|
21
|
+
*/
|
|
22
|
+
static remove(namespace: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Register a special registry for a given namespace or pattern, remove previous if existed
|
|
25
|
+
*
|
|
26
|
+
* @param namespace
|
|
27
|
+
* @param registry
|
|
28
|
+
*/
|
|
29
|
+
static register(namespace: string | RegExp, registryClass: ClassType<ILookupRegistry>): void;
|
|
30
|
+
/**
|
|
31
|
+
* Return active and registered namespaces
|
|
32
|
+
*/
|
|
33
|
+
static getNamespaces(): string[];
|
|
34
|
+
static getTargets(): any[];
|
|
35
|
+
/**
|
|
36
|
+
* Return all declared namespaces
|
|
37
|
+
*/
|
|
38
|
+
static getDeclaredNamespaces(): {
|
|
39
|
+
target: Function;
|
|
40
|
+
namespace: string;
|
|
41
|
+
}[];
|
|
42
|
+
static reset(): void;
|
|
43
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegistryFactory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Schema definitions can be different depending by handled structure.
|
|
6
|
+
* We want use one api for use and accessing objects. The registry handle for a namespace can be
|
|
7
|
+
* registered here.
|
|
8
|
+
*/
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const Constants_1 = require("../Constants");
|
|
11
|
+
const DefaultNamespacedRegistry_1 = require("./DefaultNamespacedRegistry");
|
|
12
|
+
const MetadataRegistry_1 = require("./MetadataRegistry");
|
|
13
|
+
const base_1 = require("@allgemein/base");
|
|
14
|
+
class RegistryFactory {
|
|
15
|
+
/**
|
|
16
|
+
* Return the registry handling schema/objects of given context or if not exists the generic default namescaped registry
|
|
17
|
+
*
|
|
18
|
+
* @param namespace
|
|
19
|
+
*/
|
|
20
|
+
static get(namespace = Constants_1.DEFAULT_NAMESPACE) {
|
|
21
|
+
if (!this.$handles[namespace]) {
|
|
22
|
+
for (const type of this.$types) {
|
|
23
|
+
if (lodash_1.isString(type.pattern)) {
|
|
24
|
+
if (namespace === type.pattern) {
|
|
25
|
+
this.$handles[namespace] = Reflect.construct(type.registryClass, [namespace]);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (lodash_1.isRegExp(type.pattern) && type.pattern.test(namespace)) {
|
|
31
|
+
this.$handles[namespace] = Reflect.construct(type.registryClass, [namespace]);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!this.$handles[namespace]) {
|
|
37
|
+
// create default as fallback if nothing passes
|
|
38
|
+
this.$handles[namespace] = new DefaultNamespacedRegistry_1.DefaultNamespacedRegistry(namespace);
|
|
39
|
+
}
|
|
40
|
+
if (this.$handles[namespace].prepare) {
|
|
41
|
+
this.$handles[namespace].prepare();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return this.$handles[namespace];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Remove registry from handles list
|
|
48
|
+
*
|
|
49
|
+
* @param namespace
|
|
50
|
+
*/
|
|
51
|
+
static remove(namespace) {
|
|
52
|
+
if (lodash_1.has(this.$handles, namespace)) {
|
|
53
|
+
this.get(namespace).reset();
|
|
54
|
+
}
|
|
55
|
+
delete this.$handles[namespace];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Register a special registry for a given namespace or pattern, remove previous if existed
|
|
59
|
+
*
|
|
60
|
+
* @param namespace
|
|
61
|
+
* @param registry
|
|
62
|
+
*/
|
|
63
|
+
static register(namespace, registryClass) {
|
|
64
|
+
const existsAlready = this.$types.find(x => lodash_1.isString(x.pattern) && lodash_1.isString(namespace) ? x.pattern === namespace :
|
|
65
|
+
lodash_1.isRegExp(x.pattern) && lodash_1.isRegExp(namespace) ? x.pattern.source === namespace.source :
|
|
66
|
+
x.pattern === namespace);
|
|
67
|
+
if (!existsAlready) {
|
|
68
|
+
this.$types.unshift({
|
|
69
|
+
pattern: namespace,
|
|
70
|
+
registryClass: registryClass
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Return active and registered namespaces
|
|
76
|
+
*/
|
|
77
|
+
static getNamespaces() {
|
|
78
|
+
return lodash_1.keys(this.$handles);
|
|
79
|
+
}
|
|
80
|
+
static getTargets() {
|
|
81
|
+
return MetadataRegistry_1.MetadataRegistry.$().getTargets();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Return all declared namespaces
|
|
85
|
+
*/
|
|
86
|
+
static getDeclaredNamespaces() {
|
|
87
|
+
return [].concat(...MetadataRegistry_1.MetadataRegistry.$().getTargets().map(x => {
|
|
88
|
+
const entries = MetadataRegistry_1.MetadataRegistry.$().getByContextAndTarget(Constants_1.METATYPE_ENTITY, x, 'merge');
|
|
89
|
+
return entries.map(x => {
|
|
90
|
+
return { target: x.target, namespace: x.namespace ? x.namespace : base_1.C_DEFAULT };
|
|
91
|
+
});
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
static reset() {
|
|
95
|
+
for (const ns of this.getNamespaces()) {
|
|
96
|
+
this.remove(ns);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.RegistryFactory = RegistryFactory;
|
|
101
|
+
RegistryFactory.$types = [
|
|
102
|
+
{
|
|
103
|
+
pattern: /.*/,
|
|
104
|
+
registryClass: DefaultNamespacedRegistry_1.DefaultNamespacedRegistry
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
RegistryFactory.$handles = {};
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=RegistryFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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B,CAAC,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YAC5D,MAAM,OAAO,GAAG,mCAAgB,CAAC,CAAC,EAAE,CAAC,qBAAqB,CAAC,2BAAe,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;YACxF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;gBACrB,OAAO,EAAC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAS,EAAC,CAAC;YAC9E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC,CAAC;IACN,CAAC;IAGD,MAAM,CAAC,KAAK;QACV,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACjB;IACH,CAAC;;AA1GH,0CA4GC;AA1GQ,sBAAM,GAA8E;IACzF;QACE,OAAO,EAAE,IAAI;QACb,aAAa,EAAE,qDAAyB;KACzC;CACF,CAAC;AAGK,wBAAQ,GAAuC,EAAE,CAAC","file":"RegistryFactory.js","sourcesContent":["/**\n * Schema definitions can be different depending by handled structure.\n * We want use one api for use and accessing objects. The registry handle for a namespace can be\n * registered here.\n */\nimport {has, isRegExp, isString, keys} from 'lodash';\nimport {ILookupRegistry} from '../../api/ILookupRegistry';\nimport {ClassType, DEFAULT_NAMESPACE, METATYPE_ENTITY} from '../Constants';\nimport {DefaultNamespacedRegistry} from './DefaultNamespacedRegistry';\nimport {MetadataRegistry} from './MetadataRegistry';\nimport {C_DEFAULT} from '@allgemein/base';\n\nexport class RegistryFactory {\n\n static $types: { pattern: string | RegExp, registryClass: ClassType<ILookupRegistry> }[] = [\n {\n pattern: /.*/,\n registryClass: DefaultNamespacedRegistry\n }\n ];\n\n\n static $handles: { [key: string]: ILookupRegistry } = {};\n\n\n /**\n * Return the registry handling schema/objects of given context or if not exists the generic default namescaped registry\n *\n * @param namespace\n */\n static get<T extends ILookupRegistry>(namespace: string = DEFAULT_NAMESPACE): T {\n if (!this.$handles[namespace]) {\n for (const type of this.$types) {\n if (isString(type.pattern)) {\n if (namespace === type.pattern) {\n this.$handles[namespace] = Reflect.construct(type.registryClass, [namespace]);\n break;\n }\n } else {\n if (isRegExp(type.pattern) && type.pattern.test(namespace)) {\n this.$handles[namespace] = Reflect.construct(type.registryClass, [namespace]);\n break;\n }\n }\n }\n\n if (!this.$handles[namespace]) {\n // create default as fallback if nothing passes\n this.$handles[namespace] = new DefaultNamespacedRegistry(namespace);\n }\n\n if (this.$handles[namespace].prepare) {\n this.$handles[namespace].prepare();\n }\n }\n return this.$handles[namespace] as T;\n }\n\n /**\n * Remove registry from handles list\n *\n * @param namespace\n */\n static remove(namespace: string) {\n if (has(this.$handles, namespace)) {\n this.get(namespace).reset();\n }\n delete this.$handles[namespace];\n }\n\n\n /**\n * Register a special registry for a given namespace or pattern, remove previous if existed\n *\n * @param namespace\n * @param registry\n */\n static register(namespace: string | RegExp, registryClass: ClassType<ILookupRegistry>) {\n const existsAlready = this.$types.find(x =>\n isString(x.pattern) && isString(namespace) ? x.pattern === namespace :\n isRegExp(x.pattern) && isRegExp(namespace) ? x.pattern.source === namespace.source :\n x.pattern === namespace);\n if (!existsAlready) {\n this.$types.unshift({\n pattern: namespace,\n registryClass: registryClass\n });\n }\n }\n\n /**\n * Return active and registered namespaces\n */\n static getNamespaces() {\n return keys(this.$handles);\n }\n\n static getTargets() {\n return MetadataRegistry.$().getTargets();\n }\n\n /**\n * Return all declared namespaces\n */\n static getDeclaredNamespaces(): { target: Function, namespace: string }[] {\n return [].concat(...MetadataRegistry.$().getTargets().map(x => {\n const entries = MetadataRegistry.$().getByContextAndTarget(METATYPE_ENTITY, x, 'merge');\n return entries.map(x => {\n return {target: x.target, namespace: x.namespace ? x.namespace : C_DEFAULT};\n });\n }));\n }\n\n\n static reset() {\n for (const ns of this.getNamespaces()) {\n this.remove(ns);\n }\n }\n\n}\n"],"sourceRoot":"../.."}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/serializer/ISerializeOptions.ts"],"names":[],"mappings":"","file":"ISerializeOptions.js","sourcesContent":["export interface ISerializeOptions {\n\n /**\n * Name of serializer\n */\n serializer?: string;\n\n\n /**\n * Namespace of the registry\n */\n namespace?: string;\n}\n"],"sourceRoot":"../.."}
|