@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.
Files changed (228) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +34 -0
  3. package/api/IBaseRef.d.ts +44 -0
  4. package/api/IBaseRef.js +4 -0
  5. package/api/IBaseRef.js.map +1 -0
  6. package/api/IBuildOptions.d.ts +31 -0
  7. package/api/IBuildOptions.js +4 -0
  8. package/api/IBuildOptions.js.map +1 -0
  9. package/api/IClassRef.d.ts +24 -0
  10. package/api/IClassRef.js +13 -0
  11. package/api/IClassRef.js.map +1 -0
  12. package/api/IEntityRef.d.ts +16 -0
  13. package/api/IEntityRef.js +11 -0
  14. package/api/IEntityRef.js.map +1 -0
  15. package/api/IJsonSchema.d.ts +11 -0
  16. package/api/IJsonSchema.js +26 -0
  17. package/api/IJsonSchema.js.map +1 -0
  18. package/api/ILookupRegistry.d.ts +60 -0
  19. package/api/ILookupRegistry.js +17 -0
  20. package/api/ILookupRegistry.js.map +1 -0
  21. package/api/IPropertyExtentions.d.ts +8 -0
  22. package/api/IPropertyExtentions.js +5 -0
  23. package/api/IPropertyExtentions.js.map +1 -0
  24. package/api/IPropertyRef.d.ts +28 -0
  25. package/api/IPropertyRef.js +13 -0
  26. package/api/IPropertyRef.js.map +1 -0
  27. package/api/ISchemaRef.d.ts +8 -0
  28. package/api/ISchemaRef.js +4 -0
  29. package/api/ISchemaRef.js.map +1 -0
  30. package/api/ISerializeSupport.d.ts +11 -0
  31. package/api/ISerializeSupport.js +26 -0
  32. package/api/ISerializeSupport.js.map +1 -0
  33. package/browser.d.ts +62 -0
  34. package/browser.js +117 -0
  35. package/browser.js.map +1 -0
  36. package/decorators/Embeddable.d.ts +2 -0
  37. package/decorators/Embeddable.js +14 -0
  38. package/decorators/Embeddable.js.map +1 -0
  39. package/decorators/Entity.d.ts +2 -0
  40. package/decorators/Entity.js +14 -0
  41. package/decorators/Entity.js.map +1 -0
  42. package/decorators/Namespace.d.ts +1 -0
  43. package/decorators/Namespace.js +20 -0
  44. package/decorators/Namespace.js.map +1 -0
  45. package/decorators/Property.d.ts +3 -0
  46. package/decorators/Property.js +59 -0
  47. package/decorators/Property.js.map +1 -0
  48. package/decorators/PropertyOf.d.ts +2 -0
  49. package/decorators/PropertyOf.js +28 -0
  50. package/decorators/PropertyOf.js.map +1 -0
  51. package/decorators/Schema.d.ts +2 -0
  52. package/decorators/Schema.js +14 -0
  53. package/decorators/Schema.js.map +1 -0
  54. package/decorators/validate/Hostname.d.ts +6 -0
  55. package/decorators/validate/Hostname.js +38 -0
  56. package/decorators/validate/Hostname.js.map +1 -0
  57. package/decorators/validate/Ip4.d.ts +6 -0
  58. package/decorators/validate/Ip4.js +37 -0
  59. package/decorators/validate/Ip4.js.map +1 -0
  60. package/decorators/validate/Ip6.d.ts +5 -0
  61. package/decorators/validate/Ip6.js +37 -0
  62. package/decorators/validate/Ip6.js.map +1 -0
  63. package/decorators/validate/IsEmail.d.ts +5 -0
  64. package/decorators/validate/IsEmail.js +37 -0
  65. package/decorators/validate/IsEmail.js.map +1 -0
  66. package/decorators/validate/IsNotEmpty.d.ts +5 -0
  67. package/decorators/validate/IsNotEmpty.js +36 -0
  68. package/decorators/validate/IsNotEmpty.js.map +1 -0
  69. package/decorators/validate/MaxLength.d.ts +6 -0
  70. package/decorators/validate/MaxLength.js +34 -0
  71. package/decorators/validate/MaxLength.js.map +1 -0
  72. package/decorators/validate/MinLength.d.ts +6 -0
  73. package/decorators/validate/MinLength.js +34 -0
  74. package/decorators/validate/MinLength.js.map +1 -0
  75. package/decorators/validate/Regex.d.ts +7 -0
  76. package/decorators/validate/Regex.js +46 -0
  77. package/decorators/validate/Regex.js.map +1 -0
  78. package/decorators/validate/Required.d.ts +5 -0
  79. package/decorators/validate/Required.js +34 -0
  80. package/decorators/validate/Required.js.map +1 -0
  81. package/decorators/validate/index.d.ts +9 -0
  82. package/decorators/validate/index.js +21 -0
  83. package/decorators/validate/index.js.map +1 -0
  84. package/index.d.ts +1 -0
  85. package/index.js +15 -0
  86. package/index.js.map +1 -0
  87. package/lib/AbstractRef.d.ts +26 -0
  88. package/lib/AbstractRef.js +126 -0
  89. package/lib/AbstractRef.js.map +1 -0
  90. package/lib/AnnotationsHelper.d.ts +7 -0
  91. package/lib/AnnotationsHelper.js +97 -0
  92. package/lib/AnnotationsHelper.js.map +1 -0
  93. package/lib/ClassRef.d.ts +120 -0
  94. package/lib/ClassRef.js +319 -0
  95. package/lib/ClassRef.js.map +1 -0
  96. package/lib/Constants.d.ts +45 -0
  97. package/lib/Constants.js +65 -0
  98. package/lib/Constants.js.map +1 -0
  99. package/lib/DataContainer.d.ts +31 -0
  100. package/lib/DataContainer.js +148 -0
  101. package/lib/DataContainer.js.map +1 -0
  102. package/lib/LookupRegistry.d.ts +36 -0
  103. package/lib/LookupRegistry.js +106 -0
  104. package/lib/LookupRegistry.js.map +1 -0
  105. package/lib/SchemaRef.d.ts +14 -0
  106. package/lib/SchemaRef.js +51 -0
  107. package/lib/SchemaRef.js.map +1 -0
  108. package/lib/SchemaUtils.d.ts +39 -0
  109. package/lib/SchemaUtils.js +129 -0
  110. package/lib/SchemaUtils.js.map +1 -0
  111. package/lib/json-schema/Constants.d.ts +2 -0
  112. package/lib/json-schema/Constants.js +7 -0
  113. package/lib/json-schema/Constants.js.map +1 -0
  114. package/lib/json-schema/IJsonSchemaSerializeOptions.d.ts +40 -0
  115. package/lib/json-schema/IJsonSchemaSerializeOptions.js +4 -0
  116. package/lib/json-schema/IJsonSchemaSerializeOptions.js.map +1 -0
  117. package/lib/json-schema/IJsonSchemaSerializer.d.ts +7 -0
  118. package/lib/json-schema/IJsonSchemaSerializer.js +4 -0
  119. package/lib/json-schema/IJsonSchemaSerializer.js.map +1 -0
  120. package/lib/json-schema/IJsonSchemaUnserializeOptions.d.ts +41 -0
  121. package/lib/json-schema/IJsonSchemaUnserializeOptions.js +4 -0
  122. package/lib/json-schema/IJsonSchemaUnserializeOptions.js.map +1 -0
  123. package/lib/json-schema/IJsonSchemaUnserializer.d.ts +5 -0
  124. package/lib/json-schema/IJsonSchemaUnserializer.js +4 -0
  125. package/lib/json-schema/IJsonSchemaUnserializer.js.map +1 -0
  126. package/lib/json-schema/IParseOptions.d.ts +16 -0
  127. package/lib/json-schema/IParseOptions.js +6 -0
  128. package/lib/json-schema/IParseOptions.js.map +1 -0
  129. package/lib/json-schema/JsonSchema.d.ts +22 -0
  130. package/lib/json-schema/JsonSchema.js +109 -0
  131. package/lib/json-schema/JsonSchema.js.map +1 -0
  132. package/lib/json-schema/JsonSchema7.d.ts +16 -0
  133. package/lib/json-schema/JsonSchema7.js +22 -0
  134. package/lib/json-schema/JsonSchema7.js.map +1 -0
  135. package/lib/json-schema/JsonSchema7Serializer.d.ts +42 -0
  136. package/lib/json-schema/JsonSchema7Serializer.js +438 -0
  137. package/lib/json-schema/JsonSchema7Serializer.js.map +1 -0
  138. package/lib/json-schema/JsonSchema7Unserializer.d.ts +60 -0
  139. package/lib/json-schema/JsonSchema7Unserializer.js +499 -0
  140. package/lib/json-schema/JsonSchema7Unserializer.js.map +1 -0
  141. package/lib/options/IAbstractOptions.d.ts +19 -0
  142. package/lib/options/IAbstractOptions.js +4 -0
  143. package/lib/options/IAbstractOptions.js.map +1 -0
  144. package/lib/options/IAttributeOptions.d.ts +7 -0
  145. package/lib/options/IAttributeOptions.js +4 -0
  146. package/lib/options/IAttributeOptions.js.map +1 -0
  147. package/lib/options/IEntityOptions.d.ts +4 -0
  148. package/lib/options/IEntityOptions.js +4 -0
  149. package/lib/options/IEntityOptions.js.map +1 -0
  150. package/lib/options/IObjectOptions.d.ts +4 -0
  151. package/lib/options/IObjectOptions.js +4 -0
  152. package/lib/options/IObjectOptions.js.map +1 -0
  153. package/lib/options/IPropertyOptions.d.ts +24 -0
  154. package/lib/options/IPropertyOptions.js +4 -0
  155. package/lib/options/IPropertyOptions.js.map +1 -0
  156. package/lib/options/ISchemaOptions.d.ts +4 -0
  157. package/lib/options/ISchemaOptions.js +4 -0
  158. package/lib/options/ISchemaOptions.js.map +1 -0
  159. package/lib/registry/AbstractRegistry.d.ts +91 -0
  160. package/lib/registry/AbstractRegistry.js +135 -0
  161. package/lib/registry/AbstractRegistry.js.map +1 -0
  162. package/lib/registry/Binding.d.ts +9 -0
  163. package/lib/registry/Binding.js +17 -0
  164. package/lib/registry/Binding.js.map +1 -0
  165. package/lib/registry/DefaultEntityRef.d.ts +30 -0
  166. package/lib/registry/DefaultEntityRef.js +60 -0
  167. package/lib/registry/DefaultEntityRef.js.map +1 -0
  168. package/lib/registry/DefaultNamespacedRegistry.d.ts +153 -0
  169. package/lib/registry/DefaultNamespacedRegistry.js +511 -0
  170. package/lib/registry/DefaultNamespacedRegistry.js.map +1 -0
  171. package/lib/registry/DefaultPropertyRef.d.ts +44 -0
  172. package/lib/registry/DefaultPropertyRef.js +175 -0
  173. package/lib/registry/DefaultPropertyRef.js.map +1 -0
  174. package/lib/registry/MetadataRegistry.d.ts +52 -0
  175. package/lib/registry/MetadataRegistry.js +186 -0
  176. package/lib/registry/MetadataRegistry.js.map +1 -0
  177. package/lib/registry/RegistryFactory.d.ts +43 -0
  178. package/lib/registry/RegistryFactory.js +109 -0
  179. package/lib/registry/RegistryFactory.js.map +1 -0
  180. package/lib/serializer/ISerializeOptions.d.ts +10 -0
  181. package/lib/serializer/ISerializeOptions.js +4 -0
  182. package/lib/serializer/ISerializeOptions.js.map +1 -0
  183. package/lib/serializer/ISerializer.d.ts +5 -0
  184. package/lib/serializer/ISerializer.js +4 -0
  185. package/lib/serializer/ISerializer.js.map +1 -0
  186. package/lib/serializer/ISerializerFactory.d.ts +13 -0
  187. package/lib/serializer/ISerializerFactory.js +4 -0
  188. package/lib/serializer/ISerializerFactory.js.map +1 -0
  189. package/lib/serializer/IUnserializeOptions.d.ts +14 -0
  190. package/lib/serializer/IUnserializeOptions.js +4 -0
  191. package/lib/serializer/IUnserializeOptions.js.map +1 -0
  192. package/lib/serializer/IUnserializer.d.ts +5 -0
  193. package/lib/serializer/IUnserializer.js +4 -0
  194. package/lib/serializer/IUnserializer.js.map +1 -0
  195. package/lib/serializer/SerializerRegistry.d.ts +8 -0
  196. package/lib/serializer/SerializerRegistry.js +20 -0
  197. package/lib/serializer/SerializerRegistry.js.map +1 -0
  198. package/lib/validation/DefaultValidator.d.ts +14 -0
  199. package/lib/validation/DefaultValidator.js +221 -0
  200. package/lib/validation/DefaultValidator.js.map +1 -0
  201. package/lib/validation/IValidateOptions.d.ts +4 -0
  202. package/lib/validation/IValidateOptions.js +4 -0
  203. package/lib/validation/IValidateOptions.js.map +1 -0
  204. package/lib/validation/IValidationError.d.ts +10 -0
  205. package/lib/validation/IValidationError.js +4 -0
  206. package/lib/validation/IValidationError.js.map +1 -0
  207. package/lib/validation/IValidationMessage.d.ts +4 -0
  208. package/lib/validation/IValidationMessage.js +4 -0
  209. package/lib/validation/IValidationMessage.js.map +1 -0
  210. package/lib/validation/IValidationOptions.d.ts +1 -0
  211. package/lib/validation/IValidationOptions.js +30 -0
  212. package/lib/validation/IValidationOptions.js.map +1 -0
  213. package/lib/validation/IValidationResult.d.ts +7 -0
  214. package/lib/validation/IValidationResult.js +4 -0
  215. package/lib/validation/IValidationResult.js.map +1 -0
  216. package/lib/validation/IValidator.d.ts +9 -0
  217. package/lib/validation/IValidator.js +4 -0
  218. package/lib/validation/IValidator.js.map +1 -0
  219. package/lib/validation/IValidatorEntry.d.ts +7 -0
  220. package/lib/validation/IValidatorEntry.js +4 -0
  221. package/lib/validation/IValidatorEntry.js.map +1 -0
  222. package/lib/validation/IValidatorHandle.d.ts +2 -0
  223. package/lib/validation/IValidatorHandle.js +4 -0
  224. package/lib/validation/IValidatorHandle.js.map +1 -0
  225. package/lib/validation/Validator.d.ts +17 -0
  226. package/lib/validation/Validator.js +54 -0
  227. package/lib/validation/Validator.js.map +1 -0
  228. package/package.json +73 -0
@@ -0,0 +1,499 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.JsonSchema7Unserializer = void 0;
13
+ const lodash_1 = require("lodash");
14
+ const Constants_1 = require("./Constants");
15
+ const JsonSchema_1 = require("./JsonSchema");
16
+ const RegistryFactory_1 = require("../registry/RegistryFactory");
17
+ const Constants_2 = require("../Constants");
18
+ const IEntityRef_1 = require("../../api/IEntityRef");
19
+ const ClassRef_1 = require("../ClassRef");
20
+ const base_1 = require("@allgemein/base");
21
+ const MetadataRegistry_1 = require("../registry/MetadataRegistry");
22
+ const IParseOptions_1 = require("./IParseOptions");
23
+ const SchemaUtils_1 = require("../SchemaUtils");
24
+ const skipKeys = ['$id', 'id', 'title', 'type', 'properties', 'allOf', 'anyOf', '$schema', 'patternProperties'];
25
+ class JsonSchema7Unserializer {
26
+ constructor(opts) {
27
+ this.version = Constants_1.DRAFT_07;
28
+ this.classRefs = [];
29
+ this.fetched = {};
30
+ this.reference = {};
31
+ this.options = opts;
32
+ }
33
+ uri() {
34
+ return `http://json-schema.org/${Constants_1.DRAFT_07}/schema`;
35
+ }
36
+ unserialize(data) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ this.data = data;
39
+ const isRoot = lodash_1.get(this.options, 'rootAsEntity', true);
40
+ const opts = { isRoot: isRoot };
41
+ IParseOptions_1.PARSE_OPTIONS_KEYS.forEach(x => {
42
+ if (lodash_1.has(this.options, x)) {
43
+ opts[x] = this.options[x];
44
+ }
45
+ });
46
+ const ret = this.options.return ? this.options.return : 'default';
47
+ return this.parse(data, opts).then(refs => {
48
+ switch (ret) {
49
+ case 'class-refs':
50
+ return this.classRefs;
51
+ case 'entity-refs':
52
+ return this.classRefs.filter(x => x.hasEntityRef()).map(x => x.getEntityRef());
53
+ default:
54
+ return refs;
55
+ }
56
+ });
57
+ });
58
+ }
59
+ /**
60
+ * Return namespace if set in passed options or if used in json-schema object.
61
+ * If no match return default namespace
62
+ */
63
+ getNamespace() {
64
+ return lodash_1.get(this.options, 'namespace', lodash_1.get(this.data, 'namespace', Constants_2.DEFAULT_NAMESPACE));
65
+ }
66
+ /**
67
+ * Get registry containing elements
68
+ */
69
+ getRegistry() {
70
+ return RegistryFactory_1.RegistryFactory.get(this.getNamespace());
71
+ }
72
+ /**
73
+ * If collectors are defined use them before default
74
+ *
75
+ *
76
+ * @param type
77
+ * @param key
78
+ * @param data
79
+ * @param options
80
+ * @private
81
+ */
82
+ collectOptions(key, data, options = {}) {
83
+ const type = lodash_1.get(options, 'metaType', Constants_2.METATYPE_ENTITY);
84
+ let ret = null;
85
+ if (!lodash_1.isUndefined(data[key]) || !lodash_1.isNull(data[key])) {
86
+ ret = {};
87
+ ret[key] = data[key];
88
+ }
89
+ if (lodash_1.has(this.options, 'collector')) {
90
+ const methods = this.options.collector.filter(x => x.type === type && x.key === key);
91
+ ret = lodash_1.assign(ret, ...methods.map(e => e.fn(key, data, options)));
92
+ }
93
+ return ret;
94
+ }
95
+ getClassRef(className, namespace) {
96
+ if (!namespace) {
97
+ namespace = this.getNamespace();
98
+ }
99
+ return ClassRef_1.ClassRef.get(className, namespace);
100
+ }
101
+ parse(data, options = null) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ let ret = null;
104
+ if (data.type) {
105
+ if (data.type === Constants_2.T_OBJECT) {
106
+ ret = yield this.parseTypeObject(data, options);
107
+ if (options.$ref) {
108
+ // finish reference if waiting
109
+ this.reference[options.$ref] = ret;
110
+ delete options.$ref;
111
+ }
112
+ if (this.hasProperties(data)) {
113
+ yield this.parseProperties(ret, data.properties, options);
114
+ }
115
+ if (this.hasPatternProperties(data)) {
116
+ options.isPattern = true;
117
+ yield this.parseProperties(ret, data.patternProperties, options);
118
+ }
119
+ }
120
+ else {
121
+ throw new Error('type is not supported at this place');
122
+ }
123
+ }
124
+ else if (data.$ref) {
125
+ return this.parseRef(data, options);
126
+ }
127
+ else if (data.anyOf && options.isRoot) {
128
+ // loading multi schema
129
+ ret = [];
130
+ for (const anyEntry of data.anyOf) {
131
+ ret.push(yield this.parse(anyEntry, options));
132
+ }
133
+ }
134
+ else {
135
+ throw new Error('no valid schema element for further parse, key with name type or $ref must be present.');
136
+ }
137
+ return ret;
138
+ });
139
+ }
140
+ parseRef(data, options) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ // refers
143
+ let ret = null;
144
+ if (lodash_1.has(this.reference, data.$ref)) {
145
+ ret = this.reference[data.$ref];
146
+ }
147
+ else {
148
+ const res = yield this.followRef(data.$ref, this.data);
149
+ const opts = lodash_1.clone(options);
150
+ opts.$ref = data.$ref;
151
+ if (!opts.className) {
152
+ opts.className = this.getClassNameFromRef(data.$ref);
153
+ }
154
+ ret = yield this.parse(res, opts);
155
+ }
156
+ return ret;
157
+ });
158
+ }
159
+ getDefinitionsKey(data) {
160
+ for (const k of lodash_1.keys(data)) {
161
+ if (k !== 'properties' && lodash_1.isObjectLike(data[k])) {
162
+ const exists = lodash_1.keys(data[k]).find(x => lodash_1.has(data[k][x], 'type'));
163
+ if (exists) {
164
+ return k;
165
+ }
166
+ }
167
+ }
168
+ return 'definition';
169
+ }
170
+ followRef($ref, data) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ let [addr, anchor] = $ref.split('#');
173
+ if (!anchor) {
174
+ anchor = '';
175
+ }
176
+ if (lodash_1.isEmpty(addr)) {
177
+ // local
178
+ if (lodash_1.isEmpty(anchor)) {
179
+ if (data.$ref) {
180
+ return this.followRef(data.$ref, data);
181
+ }
182
+ else {
183
+ return data;
184
+ }
185
+ }
186
+ else if (/^\//.test(anchor)) {
187
+ // starts with path
188
+ const dottedPath = anchor.substr(1).replace(/\//, '.');
189
+ const entry = lodash_1.get(data, dottedPath, null);
190
+ if (entry) {
191
+ return entry;
192
+ }
193
+ }
194
+ else {
195
+ // refs to local id
196
+ const refHashed = '#' + anchor;
197
+ if (data.$id === refHashed) {
198
+ return data;
199
+ }
200
+ else {
201
+ const defKey = this.getDefinitionsKey(data);
202
+ if (data[defKey]) {
203
+ for (const k of lodash_1.keys(data[defKey])) {
204
+ const x = data[defKey][k];
205
+ if (x && x.$id && x.$id === refHashed) {
206
+ return x;
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ else {
214
+ // remote fetch url
215
+ if (!this.fetched[addr]) {
216
+ this.fetched[addr] = yield JsonSchema_1.JsonSchema.request(addr, { cwd: this.options.cwd });
217
+ }
218
+ return this.followRef('#' + anchor, this.fetched[addr]);
219
+ }
220
+ // TODO create exception
221
+ throw new Error($ref + ' not found');
222
+ });
223
+ }
224
+ parseProperties(classRef, properties, options = null) {
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ const _classRef = IEntityRef_1.isEntityRef(classRef) ? classRef.getClassRef() : classRef;
227
+ const propertyNames = lodash_1.keys(properties);
228
+ for (const propertyName of propertyNames) {
229
+ yield this.parseProperty(_classRef, propertyName, properties[propertyName], options);
230
+ }
231
+ });
232
+ }
233
+ parseProperty(classRef, propertyName, data, options = null) {
234
+ return __awaiter(this, void 0, void 0, function* () {
235
+ const _classRef = IEntityRef_1.isEntityRef(classRef) ? classRef.getClassRef() : classRef;
236
+ const propRefExits = _classRef.getRegistry().find(Constants_2.METATYPE_PROPERTY, (x) => x.getClassRef() === _classRef && x.name === propertyName);
237
+ const propOptions = {
238
+ metaType: Constants_2.METATYPE_PROPERTY,
239
+ propertyName: propertyName,
240
+ target: _classRef.getClass(true),
241
+ // default type is object
242
+ type: Constants_2.T_OBJECT,
243
+ };
244
+ if (options.isPattern) {
245
+ propOptions[Constants_2.K_PATTERN_PROPERTY] = true;
246
+ }
247
+ if (lodash_1.isObjectLike(data)) {
248
+ const parseOptions = {
249
+ isProperty: true,
250
+ sourceRef: _classRef,
251
+ propertyName: propertyName,
252
+ isRoot: false,
253
+ metaType: 'property',
254
+ // isPattern: options.isPattern ? true : false
255
+ };
256
+ const dataPointer = data;
257
+ const collectOptions = {};
258
+ this.collectAndProcess(dataPointer, collectOptions, ['type', '$ref', '$schema', '$id'], parseOptions);
259
+ lodash_1.assign(propOptions, collectOptions);
260
+ if (dataPointer.$ref) {
261
+ const ref = yield this.parse(dataPointer, parseOptions);
262
+ propOptions.type = ref;
263
+ if (options.isPattern) {
264
+ propOptions[Constants_2.K_PATTERN_PROPERTY] = true;
265
+ }
266
+ }
267
+ else if (dataPointer.type) {
268
+ yield this.onTypes(dataPointer, propOptions, parseOptions);
269
+ }
270
+ }
271
+ else {
272
+ // boolean
273
+ throw new base_1.NotSupportedError('passed boolean value as definition not supported');
274
+ }
275
+ if (!propRefExits || lodash_1.get(this.options, 'forcePropertyRefCreation', false)) {
276
+ // remove properties key if exists
277
+ delete propOptions.properties;
278
+ _classRef.getRegistry().create(Constants_2.METATYPE_PROPERTY, propOptions);
279
+ }
280
+ });
281
+ }
282
+ hasProperties(datapointer) {
283
+ return lodash_1.has(datapointer, 'properties');
284
+ }
285
+ hasPatternProperties(datapointer) {
286
+ return lodash_1.has(datapointer, 'patternProperties');
287
+ }
288
+ onTypes(dataPointer, propOptions, options) {
289
+ return __awaiter(this, void 0, void 0, function* () {
290
+ let type = dataPointer.type;
291
+ if (lodash_1.isString(type)) {
292
+ type = type.toLowerCase();
293
+ }
294
+ switch (type) {
295
+ case Constants_2.T_STRING:
296
+ const res = this.onTypeString(dataPointer);
297
+ lodash_1.assign(propOptions, res);
298
+ break;
299
+ case 'boolean':
300
+ propOptions.type = 'boolean';
301
+ break;
302
+ case 'integer':
303
+ propOptions.type = 'number';
304
+ break;
305
+ case 'number':
306
+ propOptions.type = 'number';
307
+ break;
308
+ case Constants_2.T_OBJECT:
309
+ propOptions.type = Constants_2.T_OBJECT;
310
+ if (this.hasProperties(dataPointer) || this.hasPatternProperties(dataPointer)) {
311
+ propOptions.type = yield this.parse(dataPointer, options);
312
+ }
313
+ break;
314
+ case Constants_2.T_ARRAY:
315
+ // check items
316
+ if (dataPointer.minItems || dataPointer.maxItems) {
317
+ propOptions.cardinality = {
318
+ min: lodash_1.get(dataPointer, 'minItems', 0),
319
+ max: lodash_1.get(dataPointer, 'maxItems', 0),
320
+ };
321
+ }
322
+ else {
323
+ propOptions.cardinality = 0;
324
+ }
325
+ if (dataPointer.items) {
326
+ if (lodash_1.isArray(dataPointer.items)) {
327
+ throw new base_1.NotSupportedError('tuple values for array is not supported');
328
+ }
329
+ else if (lodash_1.isObjectLike(dataPointer.items)) {
330
+ options.asArray = true;
331
+ const items = dataPointer.items;
332
+ if (items.$ref) {
333
+ propOptions.type = yield this.parse(items, options);
334
+ }
335
+ else if (items.type === Constants_2.T_OBJECT) {
336
+ propOptions.type = items.type;
337
+ if (this.hasProperties(items) || this.hasPatternProperties(items)) {
338
+ propOptions.type = yield this.parse(items, options);
339
+ }
340
+ }
341
+ else {
342
+ propOptions.type = items.type;
343
+ }
344
+ if (options.isPattern) {
345
+ propOptions[Constants_2.K_PATTERN_PROPERTY] = true;
346
+ }
347
+ }
348
+ }
349
+ break;
350
+ case 'null':
351
+ throw new base_1.NotSupportedError('null value is not supported for property');
352
+ }
353
+ });
354
+ }
355
+ onTypeString(dataPointer) {
356
+ const propOptions = {};
357
+ propOptions.type = Constants_2.T_STRING;
358
+ // or date check format
359
+ if (dataPointer.format) {
360
+ propOptions.format = dataPointer.format;
361
+ switch (dataPointer.format) {
362
+ case 'date-time':
363
+ // set date type
364
+ propOptions.type = 'date';
365
+ break;
366
+ case 'date':
367
+ // set date type
368
+ propOptions.type = 'date';
369
+ break;
370
+ }
371
+ }
372
+ return propOptions;
373
+ }
374
+ parseInherits(classRef, data, key) {
375
+ return __awaiter(this, void 0, void 0, function* () {
376
+ if (lodash_1.has(data, key)) {
377
+ const values = data[key];
378
+ if (lodash_1.isArray(values)) {
379
+ for (const inheritEntry of values) {
380
+ const extend = yield this.parse(inheritEntry, { isRoot: false });
381
+ classRef.addExtend(extend);
382
+ }
383
+ }
384
+ else {
385
+ throw new base_1.NotSupportedError('only array is allowed for ' + key);
386
+ }
387
+ }
388
+ });
389
+ }
390
+ parseTypeObject(data, options = null) {
391
+ return __awaiter(this, void 0, void 0, function* () {
392
+ let ret = null;
393
+ const id = lodash_1.get(data, '$id', lodash_1.get(data, 'id', null));
394
+ let metaType = options.isRoot || !lodash_1.isEmpty(id) ? Constants_2.METATYPE_ENTITY : Constants_2.METATYPE_CLASS_REF;
395
+ const title = lodash_1.get(data, 'title', null);
396
+ // get namespace or override
397
+ const namespace = lodash_1.get(data, 'namespace', this.getNamespace());
398
+ // check if class ref exists else create one or recreate if parse options are set
399
+ let classRef = null;
400
+ let className = null;
401
+ if (options) {
402
+ if (options.className) {
403
+ className = options.className;
404
+ }
405
+ if (options.ref) {
406
+ classRef = options.ref;
407
+ className = options.ref.name;
408
+ }
409
+ }
410
+ // title data override passed className
411
+ if (title) {
412
+ if (!className || !lodash_1.get(this.options, 'ignoreDeclared', false)) {
413
+ className = lodash_1.upperFirst(lodash_1.camelCase(title));
414
+ }
415
+ }
416
+ if (!className && (options === null || options === void 0 ? void 0 : options.isProperty) && options.propertyName) {
417
+ if (lodash_1.get(this.options, 'prependClass', false)) {
418
+ className = [options.sourceRef.name, options.propertyName].map(x => lodash_1.upperFirst(lodash_1.camelCase(x))).join('');
419
+ }
420
+ else {
421
+ className = lodash_1.upperFirst(lodash_1.camelCase(options.propertyName));
422
+ }
423
+ }
424
+ if (className && !classRef) {
425
+ const fn = lodash_1.get(this.options, 'forceClassRefCreation', false) ? SchemaUtils_1.SchemaUtils.clazz(className) : className;
426
+ classRef = this.getClassRef(fn, namespace);
427
+ }
428
+ if (!classRef) {
429
+ metaType = Constants_2.METATYPE_CLASS_REF;
430
+ classRef = this.getClassRef(SchemaUtils_1.SchemaUtils.clazzAnonymous(), namespace);
431
+ }
432
+ // TODO check extentions!
433
+ for (const inheritsKey of ['allOf', 'anyOf']) {
434
+ if (lodash_1.has(data, inheritsKey)) {
435
+ yield this.parseInherits(classRef, data, inheritsKey);
436
+ }
437
+ }
438
+ if (classRef) {
439
+ // a named class ref exists
440
+ if (!this.classRefs.find(x => x === classRef)) {
441
+ this.classRefs.push(classRef);
442
+ }
443
+ const clazz = classRef.getClass(true);
444
+ const refOptions = {
445
+ name: classRef.name,
446
+ namespace: this.getNamespace(),
447
+ target: clazz
448
+ };
449
+ const collectorOptions = lodash_1.clone(options);
450
+ collectorOptions.metaType = metaType;
451
+ collectorOptions.ref = classRef;
452
+ this.collectAndProcess(data, refOptions, skipKeys, collectorOptions);
453
+ metaType = collectorOptions.metaType;
454
+ let entityOptions = MetadataRegistry_1.MetadataRegistry.$().find(metaType, (x) => x.target === clazz);
455
+ if (entityOptions) {
456
+ // merge existing
457
+ lodash_1.assign(entityOptions, refOptions);
458
+ }
459
+ else {
460
+ entityOptions = refOptions;
461
+ refOptions.metaType = Constants_2.METATYPE_CLASS_REF;
462
+ const existingOptions = classRef.getOptions();
463
+ classRef.setOptions(lodash_1.defaults(refOptions, existingOptions));
464
+ }
465
+ if (metaType === Constants_2.METATYPE_ENTITY) {
466
+ ret = this.getRegistry().find(metaType, (x) => x.getClassRef() === classRef);
467
+ if (!ret || lodash_1.get(this.options, 'forceEntityRefCreation', false)) {
468
+ ret = this.getRegistry().create(metaType, entityOptions);
469
+ }
470
+ }
471
+ else {
472
+ ret = classRef;
473
+ }
474
+ }
475
+ else {
476
+ throw new base_1.NotYetImplementedError();
477
+ }
478
+ return ret;
479
+ });
480
+ }
481
+ collectAndProcess(data, collectingObject, skipKeys, collectorOptions) {
482
+ const _keys = lodash_1.keys(data);
483
+ for (const key of _keys) {
484
+ const entry = this.collectOptions(key, data, collectorOptions);
485
+ if (skipKeys.includes(key)) {
486
+ continue;
487
+ }
488
+ if (entry && lodash_1.isObjectLike(entry)) {
489
+ lodash_1.assign(collectingObject, entry);
490
+ }
491
+ }
492
+ }
493
+ getClassNameFromRef(data) {
494
+ return data.split(/#|\//).pop();
495
+ }
496
+ }
497
+ exports.JsonSchema7Unserializer = JsonSchema7Unserializer;
498
+
499
+ //# sourceMappingURL=JsonSchema7Unserializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/json-schema/JsonSchema7Unserializer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAegB;AAIhB,2CAAqC;AAErC,6CAAwC;AACxC,iEAA4D;AAC5D,4CAUsB;AACtB,qDAA6D;AAE7D,0CAAqC;AACrC,0CAA0E;AAC1E,mEAA8D;AAC9D,mDAAkE;AAGlE,gDAA2C;AAG3C,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,mBAAmB,CAAC,CAAC;AAEhH,MAAa,uBAAuB;IAclC,YAAY,IAAmC;QAZ/C,YAAO,GAAW,oBAAQ,CAAC;QAM3B,cAAS,GAAgB,EAAE,CAAC;QAE5B,YAAO,GAAkC,EAAE,CAAC;QAE5C,cAAS,GAAyB,EAAE,CAAC;QAGnC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,GAAG;QACD,OAAO,0BAA0B,oBAAQ,SAAS,CAAC;IACrD,CAAC;IAGK,WAAW,CAAC,IAAS;;YACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,MAAM,MAAM,GAAG,YAAG,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;YACvD,MAAM,IAAI,GAAQ,EAAC,MAAM,EAAE,MAAM,EAAC,CAAC;YACnC,kCAAkB,CAAC,OAAO,CAAC,CAAC,CAA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I,CAAC,GAAG,IAAI,YAAG,CAAC,IAAI,CAAC,OAAO,EAAE,wBAAwB,EAAE,KAAK,CAAC,EAAE;wBAC9D,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;qBAC1D;iBACF;qBAAM;oBACL,GAAG,GAAG,QAAQ,CAAC;iBAChB;aAEF;iBAAM;gBACL,MAAM,IAAI,6BAAsB,EAAE,CAAC;aACpC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;KAAA;IAGD,iBAAiB,CAAC,IAAkB,EAClB,gBAAqB,EACrB,QAAkB,EAClB,gBAA+B;QAE/C,MAAM,KAAK,GAAG,aAAI,CAAC,IAAI,CAAC,CAAC;QACzB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;YACvB,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;YAC/D,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAC1B,SAAS;aACV;YACD,IAAI,KAAK,IAAI,qBAAY,CAAC,KAAK,CAAC,EAAE;gBAChC,eAAM,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;aACjC;SACF;IACH,CAAC;IAED,mBAAmB,CAAC,IAAY;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;IAClC,CAAC;CAEF;AA/fD,0DA+fC","file":"JsonSchema7Unserializer.js","sourcesContent":["import {\n assign,\n camelCase,\n clone,\n defaults,\n get,\n has,\n isArray,\n isEmpty,\n isNull,\n isObjectLike,\n isString,\n isUndefined,\n keys,\n upperFirst\n} from 'lodash';\nimport {IJsonSchema7, IJsonSchema7Definition} from './JsonSchema7';\nimport {IClassRef} from '../../api/IClassRef';\nimport {IJsonSchemaUnserializeOptions} from './IJsonSchemaUnserializeOptions';\nimport {DRAFT_07} from './Constants';\nimport {IJsonSchemaUnserializer} from './IJsonSchemaUnserializer';\nimport {JsonSchema} from './JsonSchema';\nimport {RegistryFactory} from '../registry/RegistryFactory';\nimport {\n DEFAULT_NAMESPACE,\n K_PATTERN_PROPERTY,\n METADATA_TYPE,\n METATYPE_CLASS_REF,\n METATYPE_ENTITY,\n METATYPE_PROPERTY,\n T_ARRAY,\n T_OBJECT,\n T_STRING\n} from '../Constants';\nimport {IEntityRef, isEntityRef} from '../../api/IEntityRef';\nimport {IEntityOptions} from '../options/IEntityOptions';\nimport {ClassRef} from '../ClassRef';\nimport {NotSupportedError, NotYetImplementedError} from '@allgemein/base';\nimport {MetadataRegistry} from '../registry/MetadataRegistry';\nimport {IParseOptions, PARSE_OPTIONS_KEYS} from './IParseOptions';\nimport {IPropertyOptions} from '../options/IPropertyOptions';\nimport {IAbstractOptions} from '../options/IAbstractOptions';\nimport {SchemaUtils} from '../SchemaUtils';\nimport {IPropertyRef} from '../../api/IPropertyRef';\n\nconst skipKeys = ['$id', 'id', 'title', 'type', 'properties', 'allOf', 'anyOf', '$schema', 'patternProperties'];\n\nexport class JsonSchema7Unserializer implements IJsonSchemaUnserializer {\n\n version: string = DRAFT_07;\n\n options: IJsonSchemaUnserializeOptions;\n\n data: IJsonSchema7;\n\n classRefs: IClassRef[] = [];\n\n fetched: { [k: string]: IJsonSchema7 } = {};\n\n reference: { [k: string]: any } = {};\n\n constructor(opts: IJsonSchemaUnserializeOptions) {\n this.options = opts;\n }\n\n uri(): string {\n return `http://json-schema.org/${DRAFT_07}/schema`;\n }\n\n\n async unserialize(data: any): Promise<IClassRef | IEntityRef | (IClassRef | IEntityRef)[]> {\n this.data = data;\n const isRoot = get(this.options, 'rootAsEntity', true);\n const opts: any = {isRoot: isRoot};\n PARSE_OPTIONS_KEYS.forEach(x => {\n if (has(this.options, x)) {\n opts[x] = this.options[x];\n }\n });\n\n const ret = this.options.return ? this.options.return : 'default';\n return this.parse(data, opts).then(refs => {\n switch (ret) {\n case 'class-refs':\n return this.classRefs;\n case 'entity-refs':\n return this.classRefs.filter(x => x.hasEntityRef()).map(x => x.getEntityRef());\n default:\n return refs;\n }\n });\n }\n\n /**\n * Return namespace if set in passed options or if used in json-schema object.\n * If no match return default namespace\n */\n getNamespace() {\n return get(this.options, 'namespace', get(this.data, 'namespace', DEFAULT_NAMESPACE));\n }\n\n /**\n * Get registry containing elements\n */\n getRegistry() {\n return RegistryFactory.get(this.getNamespace());\n }\n\n\n /**\n * If collectors are defined use them before default\n *\n *\n * @param type\n * @param key\n * @param data\n * @param options\n * @private\n */\n private collectOptions(key: string, data: IJsonSchema7, options: IParseOptions = {}) {\n const type = get(options, 'metaType', METATYPE_ENTITY);\n let ret: any = null;\n if (!isUndefined(data[key]) || !isNull(data[key])) {\n ret = {};\n ret[key] = data[key];\n }\n\n if (has(this.options, 'collector')) {\n const methods = this.options.collector.filter(x => x.type === type && x.key === key);\n ret = assign(ret, ...methods.map(e => e.fn(key, data, options)));\n }\n return ret;\n }\n\n\n getClassRef(className: string | Function, namespace?: string) {\n if (!namespace) {\n namespace = this.getNamespace();\n }\n return ClassRef.get(className, namespace);\n }\n\n\n async parse(data: IJsonSchema7, options: IParseOptions = null): Promise<IClassRef | IEntityRef | (IClassRef | IEntityRef)[]> {\n let ret: IClassRef | IEntityRef | (IClassRef | IEntityRef)[] = null;\n if (data.type) {\n\n if (data.type === T_OBJECT) {\n ret = await this.parseTypeObject(data, options);\n if (options.$ref) {\n // finish reference if waiting\n this.reference[options.$ref] = ret;\n delete options.$ref;\n }\n\n if (this.hasProperties(data)) {\n await this.parseProperties(ret, data.properties, options);\n }\n if (this.hasPatternProperties(data)) {\n options.isPattern = true;\n await this.parseProperties(ret, data.patternProperties, options);\n }\n } else {\n throw new Error('type is not supported at this place');\n }\n\n } else if (data.$ref) {\n return this.parseRef(data, options);\n } else if (data.anyOf && options.isRoot) {\n // loading multi schema\n ret = [];\n for (const anyEntry of data.anyOf) {\n ret.push(await this.parse(anyEntry as any, options) as (IClassRef | IEntityRef));\n }\n } else {\n throw new Error('no valid schema element for further parse, key with name type or $ref must be present.');\n }\n return ret;\n }\n\n async parseRef(data: any, options: IParseOptions) {\n // refers\n let ret = null;\n if (has(this.reference, data.$ref)) {\n ret = this.reference[data.$ref];\n } else {\n const res = await this.followRef(data.$ref, this.data);\n const opts = clone(options);\n opts.$ref = data.$ref;\n if (!opts.className) {\n opts.className = this.getClassNameFromRef(data.$ref);\n }\n ret = await this.parse(res, opts);\n }\n return ret;\n }\n\n\n getDefinitionsKey(data: object) {\n for (const k of keys(data)) {\n if (k !== 'properties' && isObjectLike(data[k])) {\n const exists = keys(data[k]).find(x => has(data[k][x], 'type'));\n if (exists) {\n return k;\n }\n }\n }\n return 'definition';\n }\n\n\n async followRef($ref: string, data: IJsonSchema7): Promise<any> {\n let [addr, anchor] = $ref.split('#');\n\n if (!anchor) {\n anchor = '';\n }\n\n if (isEmpty(addr)) {\n // local\n if (isEmpty(anchor)) {\n if (data.$ref) {\n return this.followRef(data.$ref, data);\n } else {\n return data;\n }\n\n } else if (/^\\//.test(anchor)) {\n // starts with path\n const dottedPath = anchor.substr(1).replace(/\\//, '.');\n const entry = get(data, dottedPath, null);\n if (entry) {\n return entry;\n }\n } else {\n // refs to local id\n const refHashed = '#' + anchor;\n if (data.$id === refHashed) {\n return data;\n } else {\n const defKey = this.getDefinitionsKey(data);\n if (data[defKey]) {\n for (const k of keys(data[defKey])) {\n const x = data[defKey][k] as IJsonSchema7;\n if (x && x.$id && x.$id === refHashed) {\n return x;\n }\n }\n }\n }\n }\n } else {\n // remote fetch url\n if (!this.fetched[addr]) {\n this.fetched[addr] = await JsonSchema.request(addr, {cwd: this.options.cwd});\n }\n return this.followRef('#' + anchor, this.fetched[addr]);\n\n }\n // TODO create exception\n throw new Error($ref + ' not found');\n }\n\n\n async parseProperties(classRef: IClassRef | IEntityRef, properties: { [propertyName: string]: IJsonSchema7Definition }, options: IParseOptions = null) {\n const _classRef = isEntityRef(classRef) ? classRef.getClassRef() : classRef;\n const propertyNames = keys(properties);\n for (const propertyName of propertyNames) {\n await this.parseProperty(_classRef, propertyName, properties[propertyName], options);\n }\n }\n\n\n async parseProperty(classRef: IClassRef | IEntityRef, propertyName: string, data: IJsonSchema7Definition, options: IParseOptions = null) {\n const _classRef = isEntityRef(classRef) ? classRef.getClassRef() : classRef;\n\n const propRefExits = _classRef.getRegistry().find(METATYPE_PROPERTY, (x: IPropertyRef) => x.getClassRef() === _classRef && x.name === propertyName);\n\n const propOptions: IPropertyOptions = {\n metaType: METATYPE_PROPERTY,\n propertyName: propertyName,\n target: _classRef.getClass(true),\n // default type is object\n type: T_OBJECT,\n };\n if (options.isPattern) {\n propOptions[K_PATTERN_PROPERTY] = true;\n }\n\n if (isObjectLike(data)) {\n const parseOptions: IParseOptions = {\n isProperty: true,\n sourceRef: _classRef,\n propertyName: propertyName,\n isRoot: false,\n metaType: 'property',\n // isPattern: options.isPattern ? true : false\n };\n const dataPointer = data as IJsonSchema7;\n const collectOptions = {};\n\n this.collectAndProcess(dataPointer, collectOptions, ['type', '$ref', '$schema', '$id'], parseOptions);\n assign(propOptions, collectOptions);\n if (dataPointer.$ref) {\n const ref = await this.parse(dataPointer, parseOptions);\n propOptions.type = ref;\n if (options.isPattern) {\n propOptions[K_PATTERN_PROPERTY] = true;\n }\n } else if (dataPointer.type) {\n await this.onTypes(dataPointer, propOptions, parseOptions);\n }\n } else {\n // boolean\n throw new NotSupportedError('passed boolean value as definition not supported');\n }\n\n if (!propRefExits || get(this.options, 'forcePropertyRefCreation', false)) {\n // remove properties key if exists\n delete propOptions.properties;\n _classRef.getRegistry().create(METATYPE_PROPERTY, propOptions);\n }\n\n }\n\n\n hasProperties(datapointer: any) {\n return has(datapointer, 'properties');\n }\n\n hasPatternProperties(datapointer: any) {\n return has(datapointer, 'patternProperties');\n }\n\n async onTypes(dataPointer: IJsonSchema7, propOptions: IPropertyOptions, options: IParseOptions) {\n let type = dataPointer.type as string;\n if (isString(type)) {\n type = type.toLowerCase();\n }\n switch (type) {\n case T_STRING:\n const res = this.onTypeString(dataPointer);\n assign(propOptions, res);\n break;\n case 'boolean':\n propOptions.type = 'boolean';\n break;\n case 'integer':\n propOptions.type = 'number';\n break;\n case 'number':\n propOptions.type = 'number';\n break;\n case T_OBJECT:\n propOptions.type = T_OBJECT;\n if (this.hasProperties(dataPointer) || this.hasPatternProperties(dataPointer)) {\n propOptions.type = await this.parse(dataPointer, options);\n }\n break;\n case T_ARRAY:\n // check items\n if (dataPointer.minItems || dataPointer.maxItems) {\n propOptions.cardinality = {\n min: get(dataPointer, 'minItems', 0),\n max: get(dataPointer, 'maxItems', 0),\n };\n } else {\n propOptions.cardinality = 0;\n }\n\n if (dataPointer.items) {\n\n if (isArray(dataPointer.items)) {\n throw new NotSupportedError('tuple values for array is not supported');\n } else if (isObjectLike(dataPointer.items)) {\n options.asArray = true;\n const items = dataPointer.items as IJsonSchema7;\n if (items.$ref) {\n propOptions.type = await this.parse(items as IJsonSchema7, options);\n } else if (items.type === T_OBJECT) {\n propOptions.type = items.type;\n if (this.hasProperties(items) || this.hasPatternProperties(items)) {\n propOptions.type = await this.parse(items as IJsonSchema7, options);\n }\n } else {\n propOptions.type = items.type;\n }\n if (options.isPattern) {\n propOptions[K_PATTERN_PROPERTY] = true;\n }\n }\n }\n break;\n case 'null':\n throw new NotSupportedError('null value is not supported for property');\n }\n }\n\n\n onTypeString(dataPointer: any) {\n const propOptions: any = {};\n propOptions.type = T_STRING;\n // or date check format\n if (dataPointer.format) {\n propOptions.format = dataPointer.format;\n switch (dataPointer.format) {\n case 'date-time':\n // set date type\n propOptions.type = 'date';\n break;\n case 'date':\n // set date type\n propOptions.type = 'date';\n break;\n }\n }\n return propOptions;\n }\n\n\n async parseInherits(classRef: IClassRef, data: IJsonSchema7, key: 'allOf' | 'anyOf') {\n if (has(data, key)) {\n const values = data[key];\n if (isArray(values)) {\n for (const inheritEntry of values) {\n const extend = await this.parse(inheritEntry as IJsonSchema7, {isRoot: false}) as IClassRef;\n classRef.addExtend(extend);\n }\n } else {\n throw new NotSupportedError('only array is allowed for ' + key);\n }\n }\n }\n\n\n async parseTypeObject(data: IJsonSchema7, options: IParseOptions = null) {\n let ret: IClassRef | IEntityRef = null;\n\n const id = get(data, '$id', get(data, 'id', null));\n let metaType: METADATA_TYPE = options.isRoot || !isEmpty(id) ? METATYPE_ENTITY : METATYPE_CLASS_REF;\n\n const title = get(data, 'title', null);\n // get namespace or override\n const namespace = get(data, 'namespace', this.getNamespace());\n // check if class ref exists else create one or recreate if parse options are set\n let classRef: IClassRef = null;\n let className = null;\n if (options) {\n if (options.className) {\n className = options.className;\n }\n if (options.ref) {\n classRef = options.ref;\n className = options.ref.name;\n }\n }\n\n // title data override passed className\n if (title) {\n if (!className || !get(this.options, 'ignoreDeclared', false)) {\n className = upperFirst(camelCase(title));\n }\n }\n\n if (!className && options?.isProperty && options.propertyName) {\n if (get(this.options, 'prependClass', false)) {\n className = [options.sourceRef.name, options.propertyName].map(x => upperFirst(camelCase(x))).join('');\n } else {\n className = upperFirst(camelCase(options.propertyName));\n }\n\n }\n\n if (className && !classRef) {\n const fn = get(this.options, 'forceClassRefCreation', false) ? SchemaUtils.clazz(className) : className;\n classRef = this.getClassRef(fn, namespace);\n }\n\n if (!classRef) {\n metaType = METATYPE_CLASS_REF;\n classRef = this.getClassRef(SchemaUtils.clazzAnonymous(), namespace);\n }\n\n // TODO check extentions!\n for (const inheritsKey of ['allOf', 'anyOf']) {\n if (has(data, inheritsKey)) {\n await this.parseInherits(classRef, data, inheritsKey as any);\n }\n }\n\n if (classRef) {\n // a named class ref exists\n if (!this.classRefs.find(x => x === classRef)) {\n this.classRefs.push(classRef);\n }\n const clazz = classRef.getClass(true);\n const refOptions: IEntityOptions = {\n name: classRef.name,\n namespace: this.getNamespace(),\n target: clazz\n };\n\n const collectorOptions = clone(options);\n collectorOptions.metaType = metaType;\n collectorOptions.ref = classRef;\n this.collectAndProcess(data, refOptions, skipKeys, collectorOptions);\n\n metaType = collectorOptions.metaType;\n\n let entityOptions = MetadataRegistry.$().find(metaType, (x: IAbstractOptions) => x.target === clazz);\n if (entityOptions) {\n // merge existing\n assign(entityOptions, refOptions);\n } else {\n entityOptions = refOptions;\n refOptions.metaType = METATYPE_CLASS_REF;\n const existingOptions = classRef.getOptions();\n\n classRef.setOptions(defaults(refOptions, existingOptions));\n }\n\n if (metaType === METATYPE_ENTITY) {\n ret = this.getRegistry().find(metaType, (x: IEntityRef) => x.getClassRef() === classRef);\n if (!ret || get(this.options, 'forceEntityRefCreation', false)) {\n ret = this.getRegistry().create(metaType, entityOptions);\n }\n } else {\n ret = classRef;\n }\n\n } else {\n throw new NotYetImplementedError();\n }\n return ret;\n }\n\n\n collectAndProcess(data: IJsonSchema7,\n collectingObject: any,\n skipKeys: string[],\n collectorOptions: IParseOptions\n ) {\n const _keys = keys(data);\n for (const key of _keys) {\n const entry = this.collectOptions(key, data, collectorOptions);\n if (skipKeys.includes(key)) {\n continue;\n }\n if (entry && isObjectLike(entry)) {\n assign(collectingObject, entry);\n }\n }\n }\n\n getClassNameFromRef(data: string) {\n return data.split(/#|\\//).pop();\n }\n\n}\n"],"sourceRoot":"../.."}
@@ -0,0 +1,19 @@
1
+ import { ClassType } from '../Constants';
2
+ export interface IAbstractOptions {
3
+ /**
4
+ * target option
5
+ */
6
+ target?: Function | ClassType<any> | string;
7
+ /**
8
+ * metadata type of this options
9
+ */
10
+ metaType?: string;
11
+ /**
12
+ * namespace for this object
13
+ */
14
+ namespace?: string;
15
+ /**
16
+ * default key definitions
17
+ */
18
+ [k: string]: any;
19
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=IAbstractOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/options/IAbstractOptions.ts"],"names":[],"mappings":"","file":"IAbstractOptions.js","sourcesContent":["import {ClassType} from '../Constants';\nimport {IClassRef} from '../../api/IClassRef';\n\nexport interface IAbstractOptions {\n\n /**\n * target option\n */\n target?: Function | ClassType<any> | string;\n\n /**\n * metadata type of this options\n */\n metaType?: string;\n\n\n /**\n * namespace for this object\n */\n namespace?: string;\n\n /**\n * default key definitions\n */\n [k: string]: any;\n}\n"],"sourceRoot":"../.."}
@@ -0,0 +1,7 @@
1
+ import { METADATA_TYPE } from '../Constants';
2
+ import { IAbstractOptions } from './IAbstractOptions';
3
+ export interface IAttributeOptions extends IAbstractOptions {
4
+ targetTypes: (METADATA_TYPE | string)[];
5
+ propertyName?: string;
6
+ attributes: any;
7
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=IAttributeOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/options/IAttributeOptions.ts"],"names":[],"mappings":"","file":"IAttributeOptions.js","sourcesContent":["import {METADATA_TYPE} from '../Constants';\nimport {IAbstractOptions} from './IAbstractOptions';\n\nexport interface IAttributeOptions extends IAbstractOptions{\n targetTypes: (METADATA_TYPE | string)[];\n propertyName?: string;\n attributes: any;\n}\n"],"sourceRoot":"../.."}
@@ -0,0 +1,4 @@
1
+ import { IAbstractOptions } from './IAbstractOptions';
2
+ export interface IEntityOptions extends IAbstractOptions {
3
+ name?: string;
4
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=IEntityOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/options/IEntityOptions.ts"],"names":[],"mappings":"","file":"IEntityOptions.js","sourcesContent":["import {IAbstractOptions} from './IAbstractOptions';\n\nexport interface IEntityOptions extends IAbstractOptions {\n\n name?: string;\n\n}\n"],"sourceRoot":"../.."}
@@ -0,0 +1,4 @@
1
+ import { IAbstractOptions } from './IAbstractOptions';
2
+ export interface IObjectOptions extends IAbstractOptions {
3
+ name?: string;
4
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=IObjectOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/options/IObjectOptions.ts"],"names":[],"mappings":"","file":"IObjectOptions.js","sourcesContent":["import {IAbstractOptions} from './IAbstractOptions';\n\nexport interface IObjectOptions extends IAbstractOptions {\n\n name?: string;\n\n}\n"],"sourceRoot":"../.."}