@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.
- package/LICENSE +1 -1
- package/api/IBaseRef.js +1 -0
- package/api/IBaseRef.js.map +1 -0
- package/api/IBuildOptions.js +1 -0
- package/api/IBuildOptions.js.map +1 -0
- package/api/IClassRef.js +1 -0
- package/api/IClassRef.js.map +1 -0
- package/api/IEntityRef.js +2 -1
- package/api/IEntityRef.js.map +1 -0
- package/api/IJsonSchema.js +1 -0
- package/api/IJsonSchema.js.map +1 -0
- package/api/ILookupRegistry.js +1 -0
- package/api/ILookupRegistry.js.map +1 -0
- package/api/IPropertyExtentions.js +1 -0
- package/api/IPropertyExtentions.js.map +1 -0
- package/api/IPropertyRef.js +1 -0
- package/api/IPropertyRef.js.map +1 -0
- package/api/ISchemaRef.js +1 -0
- package/api/ISchemaRef.js.map +1 -0
- package/api/ISerializeSupport.js +1 -0
- package/api/ISerializeSupport.js.map +1 -0
- package/browser.js +1 -0
- package/browser.js.map +1 -0
- package/decorators/Embeddable.js +1 -0
- package/decorators/Embeddable.js.map +1 -0
- package/decorators/Entity.js +1 -0
- package/decorators/Entity.js.map +1 -0
- package/decorators/Namespace.js +1 -0
- package/decorators/Namespace.js.map +1 -0
- package/decorators/Property.js +1 -0
- package/decorators/Property.js.map +1 -0
- package/decorators/PropertyOf.js +1 -0
- package/decorators/PropertyOf.js.map +1 -0
- package/decorators/Schema.js +1 -0
- package/decorators/Schema.js.map +1 -0
- package/decorators/validate/Hostname.js +1 -0
- package/decorators/validate/Hostname.js.map +1 -0
- package/decorators/validate/Ip4.js +1 -0
- package/decorators/validate/Ip4.js.map +1 -0
- package/decorators/validate/Ip6.js +1 -0
- package/decorators/validate/Ip6.js.map +1 -0
- package/decorators/validate/IsEmail.js +1 -0
- package/decorators/validate/IsEmail.js.map +1 -0
- package/decorators/validate/IsNotEmpty.js +1 -0
- package/decorators/validate/IsNotEmpty.js.map +1 -0
- package/decorators/validate/MaxLength.js +1 -0
- package/decorators/validate/MaxLength.js.map +1 -0
- package/decorators/validate/MinLength.js +1 -0
- package/decorators/validate/MinLength.js.map +1 -0
- package/decorators/validate/Regex.js +1 -0
- package/decorators/validate/Regex.js.map +1 -0
- package/decorators/validate/Required.js +1 -0
- package/decorators/validate/Required.js.map +1 -0
- package/decorators/validate/index.js +1 -0
- package/decorators/validate/index.js.map +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -0
- package/lib/AbstractRef.js +1 -0
- package/lib/AbstractRef.js.map +1 -0
- package/lib/AnnotationsHelper.js +1 -0
- package/lib/AnnotationsHelper.js.map +1 -0
- package/lib/ClassRef.js +1 -0
- package/lib/ClassRef.js.map +1 -0
- package/lib/Constants.js +1 -0
- package/lib/Constants.js.map +1 -0
- package/lib/DataContainer.js +35 -45
- package/lib/DataContainer.js.map +1 -0
- package/lib/LookupRegistry.js +1 -0
- package/lib/LookupRegistry.js.map +1 -0
- package/lib/SchemaRef.js +1 -0
- package/lib/SchemaRef.js.map +1 -0
- package/lib/SchemaUtils.js +1 -0
- package/lib/SchemaUtils.js.map +1 -0
- package/lib/functions.js +1 -0
- package/lib/functions.js.map +1 -0
- package/lib/json-schema/Constants.js +1 -0
- package/lib/json-schema/Constants.js.map +1 -0
- package/lib/json-schema/IJsonSchemaSerializeOptions.js +1 -0
- package/lib/json-schema/IJsonSchemaSerializeOptions.js.map +1 -0
- package/lib/json-schema/IJsonSchemaSerializer.js +1 -0
- package/lib/json-schema/IJsonSchemaSerializer.js.map +1 -0
- package/lib/json-schema/IJsonSchemaUnserializeOptions.js +1 -0
- package/lib/json-schema/IJsonSchemaUnserializeOptions.js.map +1 -0
- package/lib/json-schema/IJsonSchemaUnserializer.js +1 -0
- package/lib/json-schema/IJsonSchemaUnserializer.js.map +1 -0
- package/lib/json-schema/IParseOptions.js +1 -0
- package/lib/json-schema/IParseOptions.js.map +1 -0
- package/lib/json-schema/JsonSchema.js +28 -38
- package/lib/json-schema/JsonSchema.js.map +1 -0
- package/lib/json-schema/JsonSchema7.js +1 -0
- package/lib/json-schema/JsonSchema7.js.map +1 -0
- package/lib/json-schema/JsonSchema7Serializer.js +2 -2
- package/lib/json-schema/JsonSchema7Serializer.js.map +1 -0
- package/lib/json-schema/JsonSchema7Unserializer.js +326 -352
- package/lib/json-schema/JsonSchema7Unserializer.js.map +1 -0
- package/lib/json-schema/functions.d.ts +4 -1
- package/lib/json-schema/functions.js +1 -0
- package/lib/json-schema/functions.js.map +1 -0
- package/lib/options/IAbstractOptions.js +1 -0
- package/lib/options/IAbstractOptions.js.map +1 -0
- package/lib/options/IAttributeOptions.js +1 -0
- package/lib/options/IAttributeOptions.js.map +1 -0
- package/lib/options/IEntityOptions.js +1 -0
- package/lib/options/IEntityOptions.js.map +1 -0
- package/lib/options/INamedOptions.js +1 -0
- package/lib/options/INamedOptions.js.map +1 -0
- package/lib/options/IObjectOptions.js +1 -0
- package/lib/options/IObjectOptions.js.map +1 -0
- package/lib/options/IPropertyOptions.js +1 -0
- package/lib/options/IPropertyOptions.js.map +1 -0
- package/lib/options/ISchemaOptions.js +1 -0
- package/lib/options/ISchemaOptions.js.map +1 -0
- package/lib/registry/AbstractRegistry.js +1 -0
- package/lib/registry/AbstractRegistry.js.map +1 -0
- package/lib/registry/Binding.js +1 -0
- package/lib/registry/Binding.js.map +1 -0
- package/lib/registry/DefaultEntityRef.js +1 -0
- package/lib/registry/DefaultEntityRef.js.map +1 -0
- package/lib/registry/DefaultNamespacedRegistry.js +19 -33
- package/lib/registry/DefaultNamespacedRegistry.js.map +1 -0
- package/lib/registry/DefaultPropertyRef.js +1 -0
- package/lib/registry/DefaultPropertyRef.js.map +1 -0
- package/lib/registry/IRegistryOptions.js +1 -0
- package/lib/registry/IRegistryOptions.js.map +1 -0
- package/lib/registry/MetadataRegistry.js +1 -0
- package/lib/registry/MetadataRegistry.js.map +1 -0
- package/lib/registry/RegistryFactory.js +1 -0
- package/lib/registry/RegistryFactory.js.map +1 -0
- package/lib/serializer/ISerializeOptions.js +1 -0
- package/lib/serializer/ISerializeOptions.js.map +1 -0
- package/lib/serializer/ISerializer.js +1 -0
- package/lib/serializer/ISerializer.js.map +1 -0
- package/lib/serializer/ISerializerFactory.js +1 -0
- package/lib/serializer/ISerializerFactory.js.map +1 -0
- package/lib/serializer/IUnserializeOptions.js +1 -0
- package/lib/serializer/IUnserializeOptions.js.map +1 -0
- package/lib/serializer/IUnserializer.js +1 -0
- package/lib/serializer/IUnserializer.js.map +1 -0
- package/lib/serializer/SerializerRegistry.js +1 -0
- package/lib/serializer/SerializerRegistry.js.map +1 -0
- package/lib/validation/DefaultValidator.js +79 -91
- package/lib/validation/DefaultValidator.js.map +1 -0
- package/lib/validation/IValidateOptions.js +1 -0
- package/lib/validation/IValidateOptions.js.map +1 -0
- package/lib/validation/IValidationError.js +1 -0
- package/lib/validation/IValidationError.js.map +1 -0
- package/lib/validation/IValidationMessage.js +1 -0
- package/lib/validation/IValidationMessage.js.map +1 -0
- package/lib/validation/IValidationOptions.js +1 -0
- package/lib/validation/IValidationOptions.js.map +1 -0
- package/lib/validation/IValidationResult.js +1 -0
- package/lib/validation/IValidationResult.js.map +1 -0
- package/lib/validation/IValidator.js +1 -0
- package/lib/validation/IValidator.js.map +1 -0
- package/lib/validation/IValidatorEntry.js +1 -0
- package/lib/validation/IValidatorEntry.js.map +1 -0
- package/lib/validation/IValidatorHandle.js +1 -0
- package/lib/validation/IValidatorHandle.js.map +1 -0
- package/lib/validation/Validator.js +13 -25
- package/lib/validation/Validator.js.map +1 -0
- 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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (data.type) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
if
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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('
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (
|
|
190
|
-
|
|
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
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
233
|
-
|
|
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(
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
245
|
+
isRoot: false,
|
|
246
|
+
metaType: 'property',
|
|
247
|
+
// isPattern: options.isPattern ? true : false
|
|
256
248
|
};
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
|
|
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
|
-
|
|
299
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
|
|
348
|
-
|
|
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 (
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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(
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (options) {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
classRef = this.getClassRef(fn, namespace);
|
|
417
|
+
else {
|
|
418
|
+
className = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(options.propertyName));
|
|
452
419
|
}
|
|
453
|
-
if
|
|
454
|
-
|
|
455
|
-
|
|
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
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
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
|
-
|
|
476
|
+
ret = classRef;
|
|
507
477
|
}
|
|
508
|
-
|
|
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
|