@allgemein/schema-api 1.5.33 → 1.6.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.
Files changed (161) hide show
  1. package/LICENSE +1 -1
  2. package/api/IBaseRef.js +1 -0
  3. package/api/IBaseRef.js.map +1 -0
  4. package/api/IBuildOptions.js +1 -0
  5. package/api/IBuildOptions.js.map +1 -0
  6. package/api/IClassRef.js +1 -0
  7. package/api/IClassRef.js.map +1 -0
  8. package/api/IEntityRef.js +2 -1
  9. package/api/IEntityRef.js.map +1 -0
  10. package/api/IJsonSchema.js +1 -0
  11. package/api/IJsonSchema.js.map +1 -0
  12. package/api/ILookupRegistry.js +1 -0
  13. package/api/ILookupRegistry.js.map +1 -0
  14. package/api/IPropertyExtentions.js +1 -0
  15. package/api/IPropertyExtentions.js.map +1 -0
  16. package/api/IPropertyRef.js +1 -0
  17. package/api/IPropertyRef.js.map +1 -0
  18. package/api/ISchemaRef.js +1 -0
  19. package/api/ISchemaRef.js.map +1 -0
  20. package/api/ISerializeSupport.js +1 -0
  21. package/api/ISerializeSupport.js.map +1 -0
  22. package/browser.js +1 -0
  23. package/browser.js.map +1 -0
  24. package/decorators/Embeddable.js +1 -0
  25. package/decorators/Embeddable.js.map +1 -0
  26. package/decorators/Entity.js +1 -0
  27. package/decorators/Entity.js.map +1 -0
  28. package/decorators/Namespace.js +1 -0
  29. package/decorators/Namespace.js.map +1 -0
  30. package/decorators/Property.js +1 -0
  31. package/decorators/Property.js.map +1 -0
  32. package/decorators/PropertyOf.js +1 -0
  33. package/decorators/PropertyOf.js.map +1 -0
  34. package/decorators/Schema.js +1 -0
  35. package/decorators/Schema.js.map +1 -0
  36. package/decorators/validate/Hostname.js +1 -0
  37. package/decorators/validate/Hostname.js.map +1 -0
  38. package/decorators/validate/Ip4.js +1 -0
  39. package/decorators/validate/Ip4.js.map +1 -0
  40. package/decorators/validate/Ip6.js +1 -0
  41. package/decorators/validate/Ip6.js.map +1 -0
  42. package/decorators/validate/IsEmail.js +1 -0
  43. package/decorators/validate/IsEmail.js.map +1 -0
  44. package/decorators/validate/IsNotEmpty.js +1 -0
  45. package/decorators/validate/IsNotEmpty.js.map +1 -0
  46. package/decorators/validate/MaxLength.js +1 -0
  47. package/decorators/validate/MaxLength.js.map +1 -0
  48. package/decorators/validate/MinLength.js +1 -0
  49. package/decorators/validate/MinLength.js.map +1 -0
  50. package/decorators/validate/Regex.js +1 -0
  51. package/decorators/validate/Regex.js.map +1 -0
  52. package/decorators/validate/Required.js +1 -0
  53. package/decorators/validate/Required.js.map +1 -0
  54. package/decorators/validate/index.js +1 -0
  55. package/decorators/validate/index.js.map +1 -0
  56. package/index.js +1 -0
  57. package/index.js.map +1 -0
  58. package/lib/AbstractRef.js +1 -0
  59. package/lib/AbstractRef.js.map +1 -0
  60. package/lib/AnnotationsHelper.js +1 -0
  61. package/lib/AnnotationsHelper.js.map +1 -0
  62. package/lib/ClassRef.js +1 -0
  63. package/lib/ClassRef.js.map +1 -0
  64. package/lib/Constants.js +1 -0
  65. package/lib/Constants.js.map +1 -0
  66. package/lib/DataContainer.js +35 -45
  67. package/lib/DataContainer.js.map +1 -0
  68. package/lib/LookupRegistry.js +1 -0
  69. package/lib/LookupRegistry.js.map +1 -0
  70. package/lib/SchemaRef.js +1 -0
  71. package/lib/SchemaRef.js.map +1 -0
  72. package/lib/SchemaUtils.js +1 -0
  73. package/lib/SchemaUtils.js.map +1 -0
  74. package/lib/functions.js +1 -0
  75. package/lib/functions.js.map +1 -0
  76. package/lib/json-schema/Constants.js +1 -0
  77. package/lib/json-schema/Constants.js.map +1 -0
  78. package/lib/json-schema/IJsonSchemaSerializeOptions.js +1 -0
  79. package/lib/json-schema/IJsonSchemaSerializeOptions.js.map +1 -0
  80. package/lib/json-schema/IJsonSchemaSerializer.js +1 -0
  81. package/lib/json-schema/IJsonSchemaSerializer.js.map +1 -0
  82. package/lib/json-schema/IJsonSchemaUnserializeOptions.js +1 -0
  83. package/lib/json-schema/IJsonSchemaUnserializeOptions.js.map +1 -0
  84. package/lib/json-schema/IJsonSchemaUnserializer.js +1 -0
  85. package/lib/json-schema/IJsonSchemaUnserializer.js.map +1 -0
  86. package/lib/json-schema/IParseOptions.js +1 -0
  87. package/lib/json-schema/IParseOptions.js.map +1 -0
  88. package/lib/json-schema/JsonSchema.js +28 -38
  89. package/lib/json-schema/JsonSchema.js.map +1 -0
  90. package/lib/json-schema/JsonSchema7.js +1 -0
  91. package/lib/json-schema/JsonSchema7.js.map +1 -0
  92. package/lib/json-schema/JsonSchema7Serializer.js +2 -2
  93. package/lib/json-schema/JsonSchema7Serializer.js.map +1 -0
  94. package/lib/json-schema/JsonSchema7Unserializer.js +326 -352
  95. package/lib/json-schema/JsonSchema7Unserializer.js.map +1 -0
  96. package/lib/json-schema/functions.d.ts +4 -1
  97. package/lib/json-schema/functions.js +1 -0
  98. package/lib/json-schema/functions.js.map +1 -0
  99. package/lib/options/IAbstractOptions.js +1 -0
  100. package/lib/options/IAbstractOptions.js.map +1 -0
  101. package/lib/options/IAttributeOptions.js +1 -0
  102. package/lib/options/IAttributeOptions.js.map +1 -0
  103. package/lib/options/IEntityOptions.js +1 -0
  104. package/lib/options/IEntityOptions.js.map +1 -0
  105. package/lib/options/INamedOptions.js +1 -0
  106. package/lib/options/INamedOptions.js.map +1 -0
  107. package/lib/options/IObjectOptions.js +1 -0
  108. package/lib/options/IObjectOptions.js.map +1 -0
  109. package/lib/options/IPropertyOptions.js +1 -0
  110. package/lib/options/IPropertyOptions.js.map +1 -0
  111. package/lib/options/ISchemaOptions.js +1 -0
  112. package/lib/options/ISchemaOptions.js.map +1 -0
  113. package/lib/registry/AbstractRegistry.js +1 -0
  114. package/lib/registry/AbstractRegistry.js.map +1 -0
  115. package/lib/registry/Binding.js +1 -0
  116. package/lib/registry/Binding.js.map +1 -0
  117. package/lib/registry/DefaultEntityRef.js +1 -0
  118. package/lib/registry/DefaultEntityRef.js.map +1 -0
  119. package/lib/registry/DefaultNamespacedRegistry.js +19 -33
  120. package/lib/registry/DefaultNamespacedRegistry.js.map +1 -0
  121. package/lib/registry/DefaultPropertyRef.js +1 -0
  122. package/lib/registry/DefaultPropertyRef.js.map +1 -0
  123. package/lib/registry/IRegistryOptions.js +1 -0
  124. package/lib/registry/IRegistryOptions.js.map +1 -0
  125. package/lib/registry/MetadataRegistry.js +1 -0
  126. package/lib/registry/MetadataRegistry.js.map +1 -0
  127. package/lib/registry/RegistryFactory.js +1 -0
  128. package/lib/registry/RegistryFactory.js.map +1 -0
  129. package/lib/serializer/ISerializeOptions.js +1 -0
  130. package/lib/serializer/ISerializeOptions.js.map +1 -0
  131. package/lib/serializer/ISerializer.js +1 -0
  132. package/lib/serializer/ISerializer.js.map +1 -0
  133. package/lib/serializer/ISerializerFactory.js +1 -0
  134. package/lib/serializer/ISerializerFactory.js.map +1 -0
  135. package/lib/serializer/IUnserializeOptions.js +1 -0
  136. package/lib/serializer/IUnserializeOptions.js.map +1 -0
  137. package/lib/serializer/IUnserializer.js +1 -0
  138. package/lib/serializer/IUnserializer.js.map +1 -0
  139. package/lib/serializer/SerializerRegistry.js +1 -0
  140. package/lib/serializer/SerializerRegistry.js.map +1 -0
  141. package/lib/validation/DefaultValidator.js +79 -91
  142. package/lib/validation/DefaultValidator.js.map +1 -0
  143. package/lib/validation/IValidateOptions.js +1 -0
  144. package/lib/validation/IValidateOptions.js.map +1 -0
  145. package/lib/validation/IValidationError.js +1 -0
  146. package/lib/validation/IValidationError.js.map +1 -0
  147. package/lib/validation/IValidationMessage.js +1 -0
  148. package/lib/validation/IValidationMessage.js.map +1 -0
  149. package/lib/validation/IValidationOptions.js +1 -0
  150. package/lib/validation/IValidationOptions.js.map +1 -0
  151. package/lib/validation/IValidationResult.js +1 -0
  152. package/lib/validation/IValidationResult.js.map +1 -0
  153. package/lib/validation/IValidator.js +1 -0
  154. package/lib/validation/IValidator.js.map +1 -0
  155. package/lib/validation/IValidatorEntry.js +1 -0
  156. package/lib/validation/IValidatorEntry.js.map +1 -0
  157. package/lib/validation/IValidatorHandle.js +1 -0
  158. package/lib/validation/IValidatorHandle.js.map +1 -0
  159. package/lib/validation/Validator.js +13 -25
  160. package/lib/validation/Validator.js.map +1 -0
  161. package/package.json +7 -41
@@ -1,13 +1,4 @@
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
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.JsonSchema7Unserializer = void 0;
13
4
  const lodash_1 = require("lodash");
@@ -34,27 +25,25 @@ class JsonSchema7Unserializer {
34
25
  uri() {
35
26
  return `http://json-schema.org/${Constants_1.DRAFT_07}/schema`;
36
27
  }
37
- unserialize(data) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- this.data = data;
40
- const isRoot = (0, lodash_1.get)(this.options, 'rootAsEntity', true);
41
- const opts = { isRoot: isRoot };
42
- IParseOptions_1.PARSE_OPTIONS_KEYS.forEach(x => {
43
- if ((0, lodash_1.has)(this.options, x)) {
44
- opts[x] = this.options[x];
45
- }
46
- });
47
- const ret = this.options.return ? this.options.return : 'default';
48
- return this.parse(data, opts).then(refs => {
49
- switch (ret) {
50
- case 'class-refs':
51
- return this.classRefs;
52
- case 'entity-refs':
53
- return this.classRefs.filter(x => x.hasEntityRef()).map(x => x.getEntityRef());
54
- default:
55
- return refs;
56
- }
57
- });
28
+ async unserialize(data) {
29
+ this.data = data;
30
+ const isRoot = (0, lodash_1.get)(this.options, 'rootAsEntity', true);
31
+ const opts = { isRoot: isRoot };
32
+ IParseOptions_1.PARSE_OPTIONS_KEYS.forEach(x => {
33
+ if ((0, lodash_1.has)(this.options, x)) {
34
+ opts[x] = this.options[x];
35
+ }
36
+ });
37
+ const ret = this.options.return ? this.options.return : 'default';
38
+ return this.parse(data, opts).then(refs => {
39
+ switch (ret) {
40
+ case 'class-refs':
41
+ return this.classRefs;
42
+ case 'entity-refs':
43
+ return this.classRefs.filter(x => x.hasEntityRef()).map(x => x.getEntityRef());
44
+ default:
45
+ return refs;
46
+ }
58
47
  });
59
48
  }
60
49
  /**
@@ -104,68 +93,64 @@ class JsonSchema7Unserializer {
104
93
  }
105
94
  return ClassRef_1.ClassRef.get(className, namespace);
106
95
  }
107
- parse(data_1) {
108
- return __awaiter(this, arguments, void 0, function* (data, options = null) {
109
- let ret = null;
110
- if (data.type) {
111
- if (data.type === Constants_2.T_OBJECT) {
112
- ret = yield this.parseTypeObject(data, options);
113
- if (ret) {
114
- if (options.$ref) {
115
- // finish reference if waiting
116
- this.reference[options.$ref] = ret;
117
- delete options.$ref;
118
- }
119
- if (this.hasProperties(data)) {
120
- yield this.parseProperties(ret, data.properties, options);
121
- }
122
- if (this.hasPatternProperties(data)) {
123
- options.isPattern = true;
124
- yield this.parseProperties(ret, data.patternProperties, options);
125
- }
96
+ async parse(data, options = null) {
97
+ let ret = null;
98
+ if (data.type) {
99
+ if (data.type === Constants_2.T_OBJECT) {
100
+ ret = await this.parseTypeObject(data, options);
101
+ if (ret) {
102
+ if (options.$ref) {
103
+ // finish reference if waiting
104
+ this.reference[options.$ref] = ret;
105
+ delete options.$ref;
106
+ }
107
+ if (this.hasProperties(data)) {
108
+ await this.parseProperties(ret, data.properties, options);
109
+ }
110
+ if (this.hasPatternProperties(data)) {
111
+ options.isPattern = true;
112
+ await this.parseProperties(ret, data.patternProperties, options);
126
113
  }
127
- }
128
- else {
129
- throw new Error('type is not supported at this place');
130
- }
131
- }
132
- else if (data.$ref) {
133
- return this.parseRef(data, options);
134
- }
135
- else if (data.anyOf && options.isRoot) {
136
- // loading multi schema
137
- ret = [];
138
- for (const anyEntry of data.anyOf) {
139
- ret.push(yield this.parse(anyEntry, options));
140
114
  }
141
115
  }
142
- else if (data.definitions && (0, lodash_1.keys)(data.definitions).length === 0) {
143
- // doing nothing no entries found
144
- }
145
116
  else {
146
- throw new Error('no valid schema element for further parse, key with name type or $ref must be present.');
147
- }
148
- return ret;
149
- });
150
- }
151
- parseRef(data, options) {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- // refers
154
- let ret = null;
155
- if ((0, lodash_1.has)(this.reference, data.$ref)) {
156
- ret = this.reference[data.$ref];
117
+ throw new Error('type is not supported at this place');
157
118
  }
158
- else {
159
- const res = yield this.followRef(data.$ref, this.data);
160
- const opts = (0, lodash_1.clone)(options);
161
- opts.$ref = data.$ref;
162
- if (!opts.className) {
163
- opts.className = this.getClassNameFromRef(data.$ref);
164
- }
165
- ret = yield this.parse(res, opts);
119
+ }
120
+ else if (data.$ref) {
121
+ return this.parseRef(data, options);
122
+ }
123
+ else if (data.anyOf && options.isRoot) {
124
+ // loading multi schema
125
+ ret = [];
126
+ for (const anyEntry of data.anyOf) {
127
+ ret.push(await this.parse(anyEntry, options));
166
128
  }
167
- return ret;
168
- });
129
+ }
130
+ else if (data.definitions && (0, lodash_1.keys)(data.definitions).length === 0) {
131
+ // doing nothing no entries found
132
+ }
133
+ else {
134
+ throw new Error('no valid schema element for further parse, key with name type or $ref must be present.');
135
+ }
136
+ return ret;
137
+ }
138
+ async parseRef(data, options) {
139
+ // refers
140
+ let ret = null;
141
+ if ((0, lodash_1.has)(this.reference, data.$ref)) {
142
+ ret = this.reference[data.$ref];
143
+ }
144
+ else {
145
+ const res = await this.followRef(data.$ref, this.data);
146
+ const opts = (0, lodash_1.clone)(options);
147
+ opts.$ref = data.$ref;
148
+ if (!opts.className) {
149
+ opts.className = this.getClassNameFromRef(data.$ref);
150
+ }
151
+ ret = await this.parse(res, opts);
152
+ }
153
+ return ret;
169
154
  }
170
155
  getDefinitionsKey(data) {
171
156
  for (const k of (0, lodash_1.keys)(data)) {
@@ -178,127 +163,121 @@ class JsonSchema7Unserializer {
178
163
  }
179
164
  return 'definition';
180
165
  }
181
- followRef($ref, data) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- let [addr, anchor] = $ref.split('#');
184
- if (!anchor) {
185
- anchor = '';
186
- }
187
- if ((0, lodash_1.isEmpty)(addr)) {
188
- // local
189
- if ((0, lodash_1.isEmpty)(anchor)) {
190
- if (data.$ref) {
191
- return this.followRef(data.$ref, data);
192
- }
193
- else {
194
- return data;
195
- }
166
+ async followRef($ref, data) {
167
+ let [addr, anchor] = $ref.split('#');
168
+ if (!anchor) {
169
+ anchor = '';
170
+ }
171
+ if ((0, lodash_1.isEmpty)(addr)) {
172
+ // local
173
+ if ((0, lodash_1.isEmpty)(anchor)) {
174
+ if (data.$ref) {
175
+ return this.followRef(data.$ref, data);
196
176
  }
197
- else if (/^\//.test(anchor)) {
198
- // starts with path
199
- const dottedPath = anchor.substr(1).replace(/\//, '.');
200
- const entry = (0, lodash_1.get)(data, dottedPath, null);
201
- if (entry) {
202
- return entry;
203
- }
177
+ else {
178
+ return data;
179
+ }
180
+ }
181
+ else if (/^\//.test(anchor)) {
182
+ // starts with path
183
+ const dottedPath = anchor.substr(1).replace(/\//, '.');
184
+ const entry = (0, lodash_1.get)(data, dottedPath, null);
185
+ if (entry) {
186
+ return entry;
187
+ }
188
+ }
189
+ else {
190
+ // refs to local id
191
+ const refHashed = '#' + anchor;
192
+ if (data.$id === refHashed) {
193
+ return data;
204
194
  }
205
195
  else {
206
- // refs to local id
207
- const refHashed = '#' + anchor;
208
- if (data.$id === refHashed) {
209
- return data;
210
- }
211
- else {
212
- const defKey = this.getDefinitionsKey(data);
213
- if (data[defKey]) {
214
- for (const k of (0, lodash_1.keys)(data[defKey])) {
215
- // @ts-ignore
216
- const x = data[defKey][k];
217
- if (x && x.$id && x.$id === refHashed) {
218
- return x;
219
- }
196
+ const defKey = this.getDefinitionsKey(data);
197
+ if (data[defKey]) {
198
+ for (const k of (0, lodash_1.keys)(data[defKey])) {
199
+ // @ts-ignore
200
+ const x = data[defKey][k];
201
+ if (x && x.$id && x.$id === refHashed) {
202
+ return x;
220
203
  }
221
204
  }
222
205
  }
223
206
  }
224
207
  }
225
- else {
226
- // remote fetch url
227
- if (!this.fetched[addr]) {
228
- this.fetched[addr] = yield JsonSchema_1.JsonSchema.request(addr, { cwd: this.options.cwd });
229
- }
230
- return this.followRef('#' + anchor, this.fetched[addr]);
208
+ }
209
+ else {
210
+ // remote fetch url
211
+ if (!this.fetched[addr]) {
212
+ this.fetched[addr] = await JsonSchema_1.JsonSchema.request(addr, { cwd: this.options.cwd });
231
213
  }
232
- // TODO create exception
233
- throw new Error($ref + ' not found');
234
- });
214
+ return this.followRef('#' + anchor, this.fetched[addr]);
215
+ }
216
+ // TODO create exception
217
+ throw new Error($ref + ' not found');
235
218
  }
236
- parseProperties(classRef_1, properties_1) {
237
- return __awaiter(this, arguments, void 0, function* (classRef, properties, options = null) {
238
- const _classRef = (0, IEntityRef_1.isEntityRef)(classRef) ? classRef.getClassRef() : classRef;
239
- const propertyNames = (0, lodash_1.keys)(properties);
240
- for (const propertyName of propertyNames) {
241
- yield this.parseProperty(_classRef, propertyName, properties[propertyName], options);
242
- }
243
- });
219
+ async parseProperties(classRef, properties, options = null) {
220
+ const _classRef = (0, IEntityRef_1.isEntityRef)(classRef) ? classRef.getClassRef() : classRef;
221
+ const propertyNames = (0, lodash_1.keys)(properties);
222
+ for (const propertyName of propertyNames) {
223
+ await this.parseProperty(_classRef, propertyName, properties[propertyName], options);
224
+ }
244
225
  }
245
- parseProperty(classRef_1, propertyName_1, data_1) {
246
- return __awaiter(this, arguments, void 0, function* (classRef, propertyName, data, options = null) {
247
- const _classRef = (0, IEntityRef_1.isEntityRef)(classRef) ? classRef.getClassRef() : classRef;
248
- const propRefExits = _classRef.getRegistry()
249
- .find(Constants_2.METATYPE_PROPERTY, (x) => x.getClassRef() === _classRef && x.name === propertyName);
250
- const propOptions = {
251
- metaType: Constants_2.METATYPE_PROPERTY,
226
+ async parseProperty(classRef, propertyName, data, options = null) {
227
+ const _classRef = (0, IEntityRef_1.isEntityRef)(classRef) ? classRef.getClassRef() : classRef;
228
+ const propRefExits = _classRef.getRegistry()
229
+ .find(Constants_2.METATYPE_PROPERTY, (x) => x.getClassRef() === _classRef && x.name === propertyName);
230
+ const propOptions = {
231
+ metaType: Constants_2.METATYPE_PROPERTY,
232
+ propertyName: propertyName,
233
+ target: _classRef.getClass(true),
234
+ // default type is object
235
+ type: Constants_2.T_OBJECT,
236
+ };
237
+ if (options.isPattern) {
238
+ propOptions[Constants_2.K_PATTERN_PROPERTY] = true;
239
+ }
240
+ if ((0, lodash_1.isObjectLike)(data)) {
241
+ const parseOptions = {
242
+ isProperty: true,
243
+ sourceRef: _classRef,
252
244
  propertyName: propertyName,
253
- target: _classRef.getClass(true),
254
- // default type is object
255
- type: Constants_2.T_OBJECT,
245
+ isRoot: false,
246
+ metaType: 'property',
247
+ // isPattern: options.isPattern ? true : false
256
248
  };
257
- if (options.isPattern) {
258
- propOptions[Constants_2.K_PATTERN_PROPERTY] = true;
259
- }
260
- if ((0, lodash_1.isObjectLike)(data)) {
261
- const parseOptions = {
262
- isProperty: true,
263
- sourceRef: _classRef,
264
- propertyName: propertyName,
265
- isRoot: false,
266
- metaType: 'property',
267
- // isPattern: options.isPattern ? true : false
268
- };
269
- const dataPointer = data;
270
- let collectOptions = {};
271
- collectOptions = this.collectAndProcess(dataPointer, collectOptions, ['type', '$ref', '$schema', '$id'], parseOptions);
272
- (0, lodash_1.assign)(propOptions, collectOptions);
273
- if (dataPointer.$ref) {
274
- const ref = yield this.parse(dataPointer, parseOptions);
275
- propOptions.type = ref;
276
- if (options.isPattern) {
277
- propOptions[Constants_2.K_PATTERN_PROPERTY] = true;
278
- }
279
- }
280
- else if (dataPointer.type) {
281
- yield this.onTypes(dataPointer, propOptions, parseOptions);
249
+ const dataPointer = data;
250
+ let collectOptions = {};
251
+ collectOptions = this.collectAndProcess(dataPointer, collectOptions, ['type', '$ref', '$schema', '$id'], parseOptions);
252
+ (0, lodash_1.assign)(propOptions, collectOptions);
253
+ if (dataPointer.$ref) {
254
+ const ref = await this.parse(dataPointer, parseOptions);
255
+ propOptions.type = ref;
256
+ if (options.isPattern) {
257
+ propOptions[Constants_2.K_PATTERN_PROPERTY] = true;
282
258
  }
283
259
  }
284
- else {
285
- // boolean
286
- throw new base_1.NotSupportedError('passed boolean value as definition not supported');
287
- }
288
- if (!propRefExits || (0, lodash_1.get)(this.options, 'forcePropertyRefCreation', false)) {
289
- // remove properties key if exists
290
- delete propOptions.properties;
291
- try {
292
- _classRef.getRegistry().create(Constants_2.METATYPE_PROPERTY, propOptions);
293
- }
294
- catch (e) {
295
- this.issues.push({ msg: e.message, level: 'error' });
296
- }
260
+ else if (dataPointer.type) {
261
+ await this.onTypes(dataPointer, propOptions, parseOptions);
297
262
  }
298
- else if (propRefExits) {
299
- propRefExits.setOptions(propOptions);
263
+ }
264
+ else {
265
+ // boolean
266
+ throw new base_1.NotSupportedError('passed boolean value as definition not supported');
267
+ }
268
+ if (!propRefExits || (0, lodash_1.get)(this.options, 'forcePropertyRefCreation', false)) {
269
+ // remove properties key if exists
270
+ delete propOptions.properties;
271
+ try {
272
+ _classRef.getRegistry().create(Constants_2.METATYPE_PROPERTY, propOptions);
300
273
  }
301
- });
274
+ catch (e) {
275
+ this.issues.push({ msg: e.message, level: 'error' });
276
+ }
277
+ }
278
+ else if (propRefExits) {
279
+ propRefExits.setOptions(propOptions);
280
+ }
302
281
  }
303
282
  hasProperties(datapointer) {
304
283
  return (0, lodash_1.has)(datapointer, 'properties');
@@ -306,72 +285,70 @@ class JsonSchema7Unserializer {
306
285
  hasPatternProperties(datapointer) {
307
286
  return (0, lodash_1.has)(datapointer, 'patternProperties');
308
287
  }
309
- onTypes(dataPointer, propOptions, options) {
310
- return __awaiter(this, void 0, void 0, function* () {
311
- let type = dataPointer.type;
312
- if ((0, lodash_1.isString)(type)) {
313
- type = type.toLowerCase();
314
- }
315
- switch (type) {
316
- case Constants_2.T_STRING:
317
- const res = this.onTypeString(dataPointer);
318
- (0, lodash_1.assign)(propOptions, res);
319
- break;
320
- case 'boolean':
321
- propOptions.type = 'boolean';
322
- break;
323
- case 'integer':
324
- propOptions.type = 'number';
325
- break;
326
- case 'number':
327
- propOptions.type = 'number';
328
- break;
329
- case Constants_2.T_OBJECT:
330
- propOptions.type = Constants_2.T_OBJECT;
331
- if (this.hasProperties(dataPointer) || this.hasPatternProperties(dataPointer)) {
332
- propOptions.type = yield this.parse(dataPointer, options);
333
- }
334
- break;
335
- case Constants_2.T_ARRAY:
336
- // check items
337
- if (dataPointer.minItems || dataPointer.maxItems) {
338
- propOptions.cardinality = {
339
- min: (0, lodash_1.get)(dataPointer, 'minItems', 0),
340
- max: (0, lodash_1.get)(dataPointer, 'maxItems', 0),
341
- };
342
- }
343
- else {
344
- propOptions.cardinality = 0;
288
+ async onTypes(dataPointer, propOptions, options) {
289
+ let type = dataPointer.type;
290
+ if ((0, lodash_1.isString)(type)) {
291
+ type = type.toLowerCase();
292
+ }
293
+ switch (type) {
294
+ case Constants_2.T_STRING:
295
+ const res = this.onTypeString(dataPointer);
296
+ (0, lodash_1.assign)(propOptions, res);
297
+ break;
298
+ case 'boolean':
299
+ propOptions.type = 'boolean';
300
+ break;
301
+ case 'integer':
302
+ propOptions.type = 'number';
303
+ break;
304
+ case 'number':
305
+ propOptions.type = 'number';
306
+ break;
307
+ case Constants_2.T_OBJECT:
308
+ propOptions.type = Constants_2.T_OBJECT;
309
+ if (this.hasProperties(dataPointer) || this.hasPatternProperties(dataPointer)) {
310
+ propOptions.type = await this.parse(dataPointer, options);
311
+ }
312
+ break;
313
+ case Constants_2.T_ARRAY:
314
+ // check items
315
+ if (dataPointer.minItems || dataPointer.maxItems) {
316
+ propOptions.cardinality = {
317
+ min: (0, lodash_1.get)(dataPointer, 'minItems', 0),
318
+ max: (0, lodash_1.get)(dataPointer, 'maxItems', 0),
319
+ };
320
+ }
321
+ else {
322
+ propOptions.cardinality = 0;
323
+ }
324
+ if (dataPointer.items) {
325
+ if ((0, lodash_1.isArray)(dataPointer.items)) {
326
+ throw new base_1.NotSupportedError('tuple values for array is not supported');
345
327
  }
346
- if (dataPointer.items) {
347
- if ((0, lodash_1.isArray)(dataPointer.items)) {
348
- throw new base_1.NotSupportedError('tuple values for array is not supported');
328
+ else if ((0, lodash_1.isObjectLike)(dataPointer.items)) {
329
+ options.asArray = true;
330
+ const items = dataPointer.items;
331
+ if (items.$ref) {
332
+ propOptions.type = await this.parse(items, options);
349
333
  }
350
- else if ((0, lodash_1.isObjectLike)(dataPointer.items)) {
351
- options.asArray = true;
352
- const items = dataPointer.items;
353
- if (items.$ref) {
354
- propOptions.type = yield this.parse(items, options);
355
- }
356
- else if (items.type === Constants_2.T_OBJECT) {
357
- propOptions.type = items.type;
358
- if (this.hasProperties(items) || this.hasPatternProperties(items)) {
359
- propOptions.type = yield this.parse(items, options);
360
- }
361
- }
362
- else {
363
- propOptions.type = items.type;
364
- }
365
- if (options.isPattern) {
366
- propOptions[Constants_2.K_PATTERN_PROPERTY] = true;
334
+ else if (items.type === Constants_2.T_OBJECT) {
335
+ propOptions.type = items.type;
336
+ if (this.hasProperties(items) || this.hasPatternProperties(items)) {
337
+ propOptions.type = await this.parse(items, options);
367
338
  }
368
339
  }
340
+ else {
341
+ propOptions.type = items.type;
342
+ }
343
+ if (options.isPattern) {
344
+ propOptions[Constants_2.K_PATTERN_PROPERTY] = true;
345
+ }
369
346
  }
370
- break;
371
- case 'null':
372
- throw new base_1.NotSupportedError('null value is not supported for property');
373
- }
374
- });
347
+ }
348
+ break;
349
+ case 'null':
350
+ throw new base_1.NotSupportedError('null value is not supported for property');
351
+ }
375
352
  }
376
353
  onTypeString(dataPointer) {
377
354
  const propOptions = {};
@@ -392,121 +369,117 @@ class JsonSchema7Unserializer {
392
369
  }
393
370
  return propOptions;
394
371
  }
395
- parseInherits(classRef, data, key) {
396
- return __awaiter(this, void 0, void 0, function* () {
397
- if ((0, lodash_1.has)(data, key)) {
398
- const values = data[key];
399
- if ((0, lodash_1.isArray)(values)) {
400
- for (const inheritEntry of values) {
401
- const extend = yield this.parse(inheritEntry, { isRoot: false });
402
- classRef.addExtend(extend);
403
- }
404
- }
405
- else {
406
- throw new base_1.NotSupportedError('only array is allowed for ' + key);
372
+ async parseInherits(classRef, data, key) {
373
+ if ((0, lodash_1.has)(data, key)) {
374
+ const values = data[key];
375
+ if ((0, lodash_1.isArray)(values)) {
376
+ for (const inheritEntry of values) {
377
+ const extend = await this.parse(inheritEntry, { isRoot: false });
378
+ classRef.addExtend(extend);
407
379
  }
408
380
  }
409
- });
381
+ else {
382
+ throw new base_1.NotSupportedError('only array is allowed for ' + key);
383
+ }
384
+ }
410
385
  }
411
- parseTypeObject(data_1) {
412
- return __awaiter(this, arguments, void 0, function* (data, options = null) {
413
- let ret = null;
414
- const id = (0, lodash_1.get)(data, '$id', (0, lodash_1.get)(data, 'id', null));
415
- let metaType = options.isRoot || !(0, lodash_1.isEmpty)(id) ? Constants_2.METATYPE_ENTITY : Constants_2.METATYPE_CLASS_REF;
416
- const title = (0, lodash_1.get)(data, 'title', null);
417
- // get namespace or override
418
- const namespace = !(0, lodash_1.get)(this.options, 'skipNamespace', false) ?
419
- (0, lodash_1.get)(data, '$' + Constants_2.METATYPE_NAMESPACE, this.getNamespace()) : this.getNamespace();
420
- // check if class ref exists else create one or recreate if parse options are set
421
- let classRef = null;
422
- let className = null;
423
- if (options) {
424
- if (options.className) {
425
- className = options.className;
426
- }
427
- if (options.ref) {
428
- classRef = options.ref;
429
- className = options.ref.name;
430
- }
386
+ async parseTypeObject(data, options = null) {
387
+ let ret = null;
388
+ const id = (0, lodash_1.get)(data, '$id', (0, lodash_1.get)(data, 'id', null));
389
+ let metaType = options.isRoot || !(0, lodash_1.isEmpty)(id) ? Constants_2.METATYPE_ENTITY : Constants_2.METATYPE_CLASS_REF;
390
+ const title = (0, lodash_1.get)(data, 'title', null);
391
+ // get namespace or override
392
+ const namespace = !(0, lodash_1.get)(this.options, 'skipNamespace', false) ?
393
+ (0, lodash_1.get)(data, '$' + Constants_2.METATYPE_NAMESPACE, this.getNamespace()) : this.getNamespace();
394
+ // check if class ref exists else create one or recreate if parse options are set
395
+ let classRef = null;
396
+ let className = null;
397
+ if (options) {
398
+ if (options.className) {
399
+ className = options.className;
400
+ }
401
+ if (options.ref) {
402
+ classRef = options.ref;
403
+ className = options.ref.name;
431
404
  }
432
- // title data override passed className
433
- if (title) {
434
- if (!className || !(0, lodash_1.get)(this.options, 'ignoreDeclared', false)) {
435
- className = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(title));
436
- }
405
+ }
406
+ // title data override passed className
407
+ if (title) {
408
+ if (!className || !(0, lodash_1.get)(this.options, 'ignoreDeclared', false)) {
409
+ className = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(title));
437
410
  }
438
- let entityName = metaType === Constants_2.METATYPE_ENTITY && id ? id.replace(/^#/, '') : className;
439
- if (!className && (options === null || options === void 0 ? void 0 : options.isProperty) && options.propertyName) {
440
- if ((0, lodash_1.get)(this.options, 'prependClass', false)) {
441
- className = [options.sourceRef.name, options.propertyName].map(x => (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(x))).join('');
442
- }
443
- else {
444
- className = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(options.propertyName));
445
- }
446
- // pass property name as entity name if the object is declared as a property
447
- entityName = className;
411
+ }
412
+ let entityName = metaType === Constants_2.METATYPE_ENTITY && id ? id.replace(/^#/, '') : className;
413
+ if (!className && options?.isProperty && options.propertyName) {
414
+ if ((0, lodash_1.get)(this.options, 'prependClass', false)) {
415
+ className = [options.sourceRef.name, options.propertyName].map(x => (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(x))).join('');
448
416
  }
449
- if (className && !classRef) {
450
- const fn = (0, lodash_1.get)(this.options, 'forceClassRefCreation', false) ? SchemaUtils_1.SchemaUtils.clazz(className) : className;
451
- classRef = this.getClassRef(fn, namespace);
417
+ else {
418
+ className = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(options.propertyName));
452
419
  }
453
- if (!classRef) {
454
- metaType = Constants_2.METATYPE_CLASS_REF;
455
- classRef = this.getClassRef(SchemaUtils_1.SchemaUtils.clazzAnonymous(), namespace);
420
+ // pass property name as entity name if the object is declared as a property
421
+ entityName = className;
422
+ }
423
+ if (className && !classRef) {
424
+ const fn = (0, lodash_1.get)(this.options, 'forceClassRefCreation', false) ? SchemaUtils_1.SchemaUtils.clazz(className) : className;
425
+ classRef = this.getClassRef(fn, namespace);
426
+ }
427
+ if (!classRef) {
428
+ metaType = Constants_2.METATYPE_CLASS_REF;
429
+ classRef = this.getClassRef(SchemaUtils_1.SchemaUtils.clazzAnonymous(), namespace);
430
+ }
431
+ // TODO check extentions!
432
+ for (const inheritsKey of ['allOf', 'anyOf']) {
433
+ if ((0, lodash_1.has)(data, inheritsKey)) {
434
+ await this.parseInherits(classRef, data, inheritsKey);
456
435
  }
457
- // TODO check extentions!
458
- for (const inheritsKey of ['allOf', 'anyOf']) {
459
- if ((0, lodash_1.has)(data, inheritsKey)) {
460
- yield this.parseInherits(classRef, data, inheritsKey);
461
- }
436
+ }
437
+ if (classRef) {
438
+ // a named class ref exists
439
+ if (!this.classRefs.find(x => x === classRef)) {
440
+ this.classRefs.push(classRef);
441
+ }
442
+ const clazz = classRef.getClass(true);
443
+ const refOptions = {
444
+ name: entityName,
445
+ namespace: this.getNamespace(),
446
+ target: clazz
447
+ };
448
+ const collectorOptions = (0, lodash_1.clone)(options);
449
+ collectorOptions.metaType = metaType;
450
+ collectorOptions.ref = classRef;
451
+ this.collectAndProcess(data, refOptions, skipKeys, collectorOptions);
452
+ metaType = collectorOptions.metaType;
453
+ let entityOptions = MetadataRegistry_1.MetadataRegistry.$().find(metaType, (x) => x.target === clazz);
454
+ if (entityOptions) {
455
+ // merge existing
456
+ (0, lodash_1.assign)(entityOptions, refOptions);
462
457
  }
463
- if (classRef) {
464
- // a named class ref exists
465
- if (!this.classRefs.find(x => x === classRef)) {
466
- this.classRefs.push(classRef);
467
- }
468
- const clazz = classRef.getClass(true);
469
- const refOptions = {
470
- name: entityName,
471
- namespace: this.getNamespace(),
472
- target: clazz
473
- };
474
- const collectorOptions = (0, lodash_1.clone)(options);
475
- collectorOptions.metaType = metaType;
476
- collectorOptions.ref = classRef;
477
- this.collectAndProcess(data, refOptions, skipKeys, collectorOptions);
478
- metaType = collectorOptions.metaType;
479
- let entityOptions = MetadataRegistry_1.MetadataRegistry.$().find(metaType, (x) => x.target === clazz);
480
- if (entityOptions) {
481
- // merge existing
482
- (0, lodash_1.assign)(entityOptions, refOptions);
483
- }
484
- else {
485
- entityOptions = refOptions;
486
- refOptions.metaType = Constants_2.METATYPE_CLASS_REF;
487
- const existingOptions = classRef.getOptions();
488
- classRef.setOptions((0, lodash_1.defaults)(refOptions, existingOptions));
489
- }
490
- if (metaType === Constants_2.METATYPE_ENTITY) {
491
- ret = this.getRegistry(namespace).find(metaType, (x) => x.getClassRef() === classRef);
492
- if (!ret || (0, lodash_1.get)(this.options, 'forceEntityRefCreation', false)) {
493
- try {
494
- ret = this.getRegistry(namespace).create(metaType, entityOptions);
495
- }
496
- catch (e) {
497
- this.issues.push({ msg: e.message, level: 'error' });
498
- }
458
+ else {
459
+ entityOptions = refOptions;
460
+ refOptions.metaType = Constants_2.METATYPE_CLASS_REF;
461
+ const existingOptions = classRef.getOptions();
462
+ classRef.setOptions((0, lodash_1.defaults)(refOptions, existingOptions));
463
+ }
464
+ if (metaType === Constants_2.METATYPE_ENTITY) {
465
+ ret = this.getRegistry(namespace).find(metaType, (x) => x.getClassRef() === classRef);
466
+ if (!ret || (0, lodash_1.get)(this.options, 'forceEntityRefCreation', false)) {
467
+ try {
468
+ ret = this.getRegistry(namespace).create(metaType, entityOptions);
469
+ }
470
+ catch (e) {
471
+ this.issues.push({ msg: e.message, level: 'error' });
499
472
  }
500
- }
501
- else {
502
- ret = classRef;
503
473
  }
504
474
  }
505
475
  else {
506
- throw new base_1.NotYetImplementedError();
476
+ ret = classRef;
507
477
  }
508
- return ret;
509
- });
478
+ }
479
+ else {
480
+ throw new base_1.NotYetImplementedError();
481
+ }
482
+ return ret;
510
483
  }
511
484
  collectAndProcess(data, collectingObject, skipKeys, collectorOptions) {
512
485
  const type = (0, lodash_1.get)(collectorOptions, 'metaType', Constants_2.METATYPE_ENTITY);
@@ -533,3 +506,4 @@ class JsonSchema7Unserializer {
533
506
  }
534
507
  }
535
508
  exports.JsonSchema7Unserializer = JsonSchema7Unserializer;
509
+ //# sourceMappingURL=JsonSchema7Unserializer.js.map