@satisfactory-dev/docs.json.ts 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +190 -0
- package/README.md +81 -0
- package/assert/CustomAssert.d.ts +2 -0
- package/assert/CustomAssert.js +5 -0
- package/lib/AjvUtilities.d.ts +7 -0
- package/lib/AjvUtilities.js +59 -0
- package/lib/ArrayUtilities.d.ts +24 -0
- package/lib/ArrayUtilities.js +21 -0
- package/lib/CustomParsingTypes/CustomPairingTypes.d.ts +37 -0
- package/lib/CustomParsingTypes/CustomPairingTypes.js +42 -0
- package/lib/CustomParsingTypes/TypedString.d.ts +411 -0
- package/lib/CustomParsingTypes/TypedString.js +204 -0
- package/lib/CustomParsingTypes/TypedStringConst.d.ts +28 -0
- package/lib/CustomParsingTypes/TypedStringConst.js +35 -0
- package/lib/CustomParsingTypes/TypedStringEnum.d.ts +30 -0
- package/lib/CustomParsingTypes/TypedStringEnum.js +36 -0
- package/lib/CustomParsingTypes/TypedStringPattern.d.ts +64 -0
- package/lib/CustomParsingTypes/TypedStringPattern.js +82 -0
- package/lib/CustomParsingTypes/UnrealEngineString.d.ts +215 -0
- package/lib/CustomParsingTypes/UnrealEngineString.js +308 -0
- package/lib/CustomParsingTypes/ValueToRegexFormatter.d.ts +29 -0
- package/lib/CustomParsingTypes/ValueToRegexFormatter.js +205 -0
- package/lib/DataDiscovery/CustomTypes/BooleanOrBooleanExtended.d.ts +12 -0
- package/lib/DataDiscovery/CustomTypes/BooleanOrBooleanExtended.js +32 -0
- package/lib/DataDiscovery/CustomTypes/StringStartsWith.d.ts +9 -0
- package/lib/DataDiscovery/CustomTypes/StringStartsWith.js +19 -0
- package/lib/DataDiscovery/CustomTypes/TypedString.d.ts +23 -0
- package/lib/DataDiscovery/CustomTypes/TypedString.js +251 -0
- package/lib/DataDiscovery/CustomTypes/UnrealEngineString.d.ts +9 -0
- package/lib/DataDiscovery/CustomTypes/UnrealEngineString.js +45 -0
- package/lib/DataDiscovery/Generator.d.ts +19 -0
- package/lib/DataDiscovery/Generator.js +41 -0
- package/lib/DataDiscovery/JsonSchema/Array.d.ts +17 -0
- package/lib/DataDiscovery/JsonSchema/Array.js +41 -0
- package/lib/DataDiscovery/JsonSchema/Object.d.ts +61 -0
- package/lib/DataDiscovery/JsonSchema/Object.js +184 -0
- package/lib/DataDiscovery/JsonSchema/OneOf.d.ts +13 -0
- package/lib/DataDiscovery/JsonSchema/OneOf.js +47 -0
- package/lib/DataDiscovery/JsonSchema/Ref.d.ts +17 -0
- package/lib/DataDiscovery/JsonSchema/Ref.js +66 -0
- package/lib/DataDiscovery/JsonSchema/StringType.d.ts +39 -0
- package/lib/DataDiscovery/JsonSchema/StringType.js +121 -0
- package/lib/DataDiscovery/Literal.d.ts +8 -0
- package/lib/DataDiscovery/Literal.js +69 -0
- package/lib/DataDiscovery.d.ts +28 -0
- package/lib/DataDiscovery.js +116 -0
- package/lib/DocsToAutoImport/ArrayTypeNodes.d.ts +5 -0
- package/lib/DocsToAutoImport/ArrayTypeNodes.js +7 -0
- package/lib/DocsToAutoImport/ClassDeclarations.d.ts +5 -0
- package/lib/DocsToAutoImport/ClassDeclarations.js +14 -0
- package/lib/DocsToAutoImport/FunctionDeclaration.d.ts +5 -0
- package/lib/DocsToAutoImport/FunctionDeclaration.js +16 -0
- package/lib/DocsToAutoImport/LiteralTypeNodes.d.ts +5 -0
- package/lib/DocsToAutoImport/LiteralTypeNodes.js +23 -0
- package/lib/DocsToAutoImport/MethodDeclarations.d.ts +5 -0
- package/lib/DocsToAutoImport/MethodDeclarations.js +15 -0
- package/lib/DocsToAutoImport/NodeExtraction.d.ts +6 -0
- package/lib/DocsToAutoImport/NodeExtraction.js +21 -0
- package/lib/DocsToAutoImport/PropertyDeclarations.d.ts +5 -0
- package/lib/DocsToAutoImport/PropertyDeclarations.js +10 -0
- package/lib/DocsToAutoImport/TupleTypeNodes.d.ts +5 -0
- package/lib/DocsToAutoImport/TupleTypeNodes.js +7 -0
- package/lib/DocsToAutoImport/TypeLiteralNodes.d.ts +5 -0
- package/lib/DocsToAutoImport/TypeLiteralNodes.js +33 -0
- package/lib/DocsToAutoImport/TypeReferenceNodes.d.ts +5 -0
- package/lib/DocsToAutoImport/TypeReferenceNodes.js +7 -0
- package/lib/DocsToAutoImport/from_Node_array.d.ts +3 -0
- package/lib/DocsToAutoImport/from_Node_array.js +245 -0
- package/lib/DocsTsAutoImports.d.ts +21 -0
- package/lib/DocsTsAutoImports.js +110 -0
- package/lib/DocsTsGenerator/FilesGenerator.d.ts +25 -0
- package/lib/DocsTsGenerator/FilesGenerator.js +52 -0
- package/lib/DocsTsGenerator.d.ts +47 -0
- package/lib/DocsTsGenerator.js +188 -0
- package/lib/DocsValidation.d.ts +7 -0
- package/lib/DocsValidation.js +179 -0
- package/lib/Exceptions.d.ts +7 -0
- package/lib/Exceptions.js +13 -0
- package/lib/FilesGenerator.d.ts +19 -0
- package/lib/FilesGenerator.js +38 -0
- package/lib/MarkdownUtilities.d.ts +16 -0
- package/lib/MarkdownUtilities.js +68 -0
- package/lib/StringStartsWith.d.ts +10 -0
- package/lib/StringStartsWith.js +20 -0
- package/lib/TsFactoryWrapper.d.ts +80 -0
- package/lib/TsFactoryWrapper.js +236 -0
- package/lib/TypeDefinitionDiscovery/CustomParsingTypes/UnrealEngineString.d.ts +13 -0
- package/lib/TypeDefinitionDiscovery/CustomParsingTypes/UnrealEngineString.js +26 -0
- package/lib/TypeDefinitionDiscovery/CustomParsingTypes/string_starts_with.d.ts +25 -0
- package/lib/TypeDefinitionDiscovery/CustomParsingTypes/string_starts_with.js +20 -0
- package/lib/TypeDefinitionDiscovery/CustomParsingTypes/typed_string.d.ts +14 -0
- package/lib/TypeDefinitionDiscovery/CustomParsingTypes/typed_string.js +96 -0
- package/lib/TypeDefinitionDiscovery/Generator.d.ts +8 -0
- package/lib/TypeDefinitionDiscovery/Generator.js +8 -0
- package/lib/TypeDefinitionDiscovery/GeneratorDoesDiscovery.d.ts +8 -0
- package/lib/TypeDefinitionDiscovery/GeneratorDoesDiscovery.js +9 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/ArrayType.d.ts +19 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/ArrayType.js +61 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/Object/ExtendsObject.d.ts +23 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/Object/ExtendsObject.js +40 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/ObjectType.d.ts +91 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/ObjectType.js +76 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String/Const.d.ts +29 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String/Const.js +20 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String/Enum/BooleanEnum.d.ts +16 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String/Enum/BooleanEnum.js +47 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String/Enum.d.ts +40 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String/Enum.js +22 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String/Pattern.d.ts +13 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String/Pattern.js +21 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String.d.ts +52 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/String.js +72 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/oneOf_or_anyOf.d.ts +63 -0
- package/lib/TypeDefinitionDiscovery/JsonSchema/oneOf_or_anyOf.js +47 -0
- package/lib/TypeDefinitionDiscovery.d.ts +49 -0
- package/lib/TypeDefinitionDiscovery.js +376 -0
- package/lib/TypeDefinitionWriter.d.ts +22 -0
- package/lib/TypeDefinitionWriter.js +233 -0
- package/lib/TypesDiscovery/CandidatesDiscovery.d.ts +10 -0
- package/lib/TypesDiscovery/CandidatesDiscovery.js +14 -0
- package/lib/TypesDiscovery/CustomParsingTypes/UnrealEngineString.d.ts +5 -0
- package/lib/TypesDiscovery/CustomParsingTypes/UnrealEngineString.js +18 -0
- package/lib/TypesDiscovery/CustomParsingTypes/typed_string.d.ts +6 -0
- package/lib/TypesDiscovery/CustomParsingTypes/typed_string.js +34 -0
- package/lib/TypesDiscovery/JsonSchema/$ref.d.ts +7 -0
- package/lib/TypesDiscovery/JsonSchema/$ref.js +33 -0
- package/lib/TypesDiscovery/JsonSchema/const.d.ts +6 -0
- package/lib/TypesDiscovery/JsonSchema/const.js +22 -0
- package/lib/TypesDiscovery/JsonSchema/enum.d.ts +6 -0
- package/lib/TypesDiscovery/JsonSchema/enum.js +22 -0
- package/lib/TypesDiscovery/JsonSchema/properties.d.ts +4 -0
- package/lib/TypesDiscovery/JsonSchema/properties.js +14 -0
- package/lib/TypesDiscovery/non_array_object_property.d.ts +4 -0
- package/lib/TypesDiscovery/non_array_object_property.js +11 -0
- package/lib/TypesDiscovery/non_empty_array_property.d.ts +4 -0
- package/lib/TypesDiscovery/non_empty_array_property.js +11 -0
- package/lib/TypesDiscovery.d.ts +24 -0
- package/lib/TypesDiscovery.js +77 -0
- package/lib/TypesGeneration/validators.d.ts +9 -0
- package/lib/TypesGeneration/validators.js +26 -0
- package/lib/TypesGeneration.d.ts +17 -0
- package/lib/TypesGeneration.js +53 -0
- package/lib/__dirname.d.ts +1 -0
- package/lib/__dirname.js +6 -0
- package/lib/helpers.d.ts +5 -0
- package/lib/helpers.js +29 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +9 -0
- package/package.json +39 -0
- package/schema/update8.schema.json +8848 -0
- package/setup_PerformanceObserver.d.ts +3 -0
- package/setup_PerformanceObserver.js +55 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { Converter, ConverterMatchesSchema, ExpressionResult, } from '../Generator';
|
|
2
|
+
import { generate_object_parent_schema, generate_typed_string_$defs, } from '../../CustomParsingTypes/TypedString';
|
|
3
|
+
import { is_string, local_ref, } from '../../StringStartsWith';
|
|
4
|
+
import { NoMatchError, } from '../../Exceptions';
|
|
5
|
+
import { string_to_array, string_to_object, } from '../../DocsValidation';
|
|
6
|
+
import { compile, } from '../../AjvUtilities';
|
|
7
|
+
import { typed_string, } from '../../TypeDefinitionDiscovery/CustomParsingTypes/typed_string';
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
export class TypedStringConverter extends ConverterMatchesSchema {
|
|
10
|
+
$defs;
|
|
11
|
+
discovery;
|
|
12
|
+
regex_schema_cache = {};
|
|
13
|
+
constructor(discovery, $defs) {
|
|
14
|
+
const local_refs = Object.keys($defs).map(local_ref);
|
|
15
|
+
super(discovery.docs.ajv, {
|
|
16
|
+
...generate_object_parent_schema(),
|
|
17
|
+
$defs: {
|
|
18
|
+
...$defs,
|
|
19
|
+
...generate_typed_string_$defs(local_refs),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
this.discovery = discovery;
|
|
23
|
+
this.$defs = $defs;
|
|
24
|
+
}
|
|
25
|
+
can_convert_schema_and_raw_data(schema, raw_data) {
|
|
26
|
+
return Promise.resolve(this.can_convert_schema(schema)
|
|
27
|
+
&& is_string(raw_data)
|
|
28
|
+
&& (('required' in schema.typed_string
|
|
29
|
+
&& false !== string_to_object(raw_data, true))
|
|
30
|
+
|| ('patternProperties' in schema.typed_string
|
|
31
|
+
&& false !== string_to_object(raw_data, true))
|
|
32
|
+
|| (!('required' in schema.typed_string)
|
|
33
|
+
&& ((typed_string.is_array_type(schema.typed_string)
|
|
34
|
+
&& this.check_shallow_array_schema(schema.typed_string, string_to_array(raw_data, true)))
|
|
35
|
+
|| (typed_string.is_prefixItems_type(schema.typed_string)
|
|
36
|
+
&& this.check_shallow_array_prefixItems_schema(schema.typed_string, string_to_array(raw_data, true)))))));
|
|
37
|
+
}
|
|
38
|
+
async convert(schema, raw_data) {
|
|
39
|
+
if (!await this.can_convert_schema_and_raw_data(schema, raw_data)) {
|
|
40
|
+
throw new NoMatchError({
|
|
41
|
+
schema,
|
|
42
|
+
raw_data,
|
|
43
|
+
}, 'Cannot convert!');
|
|
44
|
+
}
|
|
45
|
+
else if (typed_string.is_object_type(schema.typed_string)
|
|
46
|
+
|| typed_string.is_object_pattern_type(schema.typed_string)) {
|
|
47
|
+
const shallow = string_to_object(raw_data, true);
|
|
48
|
+
assert.notEqual(shallow, false, new NoMatchError({
|
|
49
|
+
raw_data,
|
|
50
|
+
}, 'raw data not a typed_string!'));
|
|
51
|
+
return this.convert_object(schema.typed_string, shallow);
|
|
52
|
+
}
|
|
53
|
+
const shallow = string_to_array(raw_data, true);
|
|
54
|
+
assert.notEqual(shallow, false, new NoMatchError({
|
|
55
|
+
raw_data,
|
|
56
|
+
}, 'raw data not a typed string!'));
|
|
57
|
+
if (typed_string.is_array_type(schema.typed_string)) {
|
|
58
|
+
return this.convert_array(schema.typed_string, shallow);
|
|
59
|
+
}
|
|
60
|
+
else if (typed_string.is_prefixItems_type(schema.typed_string)) {
|
|
61
|
+
return this.convert_prefixItems(schema.typed_string, shallow);
|
|
62
|
+
}
|
|
63
|
+
throw new NoMatchError({
|
|
64
|
+
raw_data,
|
|
65
|
+
shallow,
|
|
66
|
+
schema,
|
|
67
|
+
}, 'Failed to convert native type!');
|
|
68
|
+
}
|
|
69
|
+
check_shallow_array_prefixItems_schema(schema, shallow) {
|
|
70
|
+
if (!(shallow instanceof Array)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
for (const entry of shallow) {
|
|
74
|
+
if (!is_string(entry)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const inner_shallow = string_to_array(entry, true);
|
|
78
|
+
if (false === inner_shallow
|
|
79
|
+
|| !this.check_shallow_array_schema(schema, inner_shallow)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
check_shallow_array_schema(schema, shallow) {
|
|
86
|
+
if (false === shallow) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const check = compile(this.discovery.docs.ajv, {
|
|
90
|
+
...schema,
|
|
91
|
+
$defs: this.$defs,
|
|
92
|
+
type: 'array',
|
|
93
|
+
});
|
|
94
|
+
return !!check(shallow);
|
|
95
|
+
}
|
|
96
|
+
check_shallow_array_schema_assert(schema, shallow) {
|
|
97
|
+
const check = compile(this.discovery.docs.ajv, {
|
|
98
|
+
...schema,
|
|
99
|
+
$defs: this.$defs,
|
|
100
|
+
type: 'array',
|
|
101
|
+
});
|
|
102
|
+
if (!check(shallow)) {
|
|
103
|
+
throw new NoMatchError({
|
|
104
|
+
shallow,
|
|
105
|
+
schema,
|
|
106
|
+
errors: check.errors,
|
|
107
|
+
}, 'Shallow parse of typed_string does not match array schema!');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async convert_array(schema, shallow) {
|
|
111
|
+
performance.mark(`${this.constructor.name}.convert_array() start`);
|
|
112
|
+
this.check_shallow_array_schema_assert(schema, shallow);
|
|
113
|
+
const converter = await Converter.find_matching_schema(await this.discovery.candidates, schema.items);
|
|
114
|
+
const items = [];
|
|
115
|
+
for (const e of shallow) {
|
|
116
|
+
items.push(await converter.convert(schema.items, e));
|
|
117
|
+
}
|
|
118
|
+
const result = new ExpressionResult(await this.discovery.literal.array_literal(items));
|
|
119
|
+
performance.measure(`${this.constructor.name}.convert_array()`, `${this.constructor.name}.convert_array() start`);
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
async convert_object(schema, shallow) {
|
|
123
|
+
performance.mark(`${this.constructor.name}.convert_object() start`);
|
|
124
|
+
this.convert_object_check_shallow_parse(schema, shallow);
|
|
125
|
+
const converted_entries = [];
|
|
126
|
+
for (const entry of Object.entries(shallow)) {
|
|
127
|
+
const [property, value] = entry;
|
|
128
|
+
const property_schema = this.convert_object_property_schema(schema, property);
|
|
129
|
+
const converter = await Converter.find_matching_schema(await this.discovery.candidates, property_schema);
|
|
130
|
+
converted_entries.push([
|
|
131
|
+
property,
|
|
132
|
+
await converter.convert(property_schema, value),
|
|
133
|
+
]);
|
|
134
|
+
}
|
|
135
|
+
const converted = Object.fromEntries(converted_entries);
|
|
136
|
+
performance.measure(`${this.constructor.name}.convert_object() bootstrap`, `${this.constructor.name}.convert_object() start`);
|
|
137
|
+
try {
|
|
138
|
+
performance.mark(`${this.constructor.name}.convert_object() start`);
|
|
139
|
+
const result = new ExpressionResult(await this.discovery.literal.object_literal(converted));
|
|
140
|
+
performance.measure(`${this.constructor.name}.convert_object()`, `${this.constructor.name}.convert_object() start`);
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
throw new NoMatchError({
|
|
145
|
+
converted,
|
|
146
|
+
error,
|
|
147
|
+
}, 'Failed to grab object literal!');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
convert_object_check_shallow_parse(schema, shallow) {
|
|
151
|
+
performance.mark(`${this.constructor.name}.convert_object_check_shallow_parse() start`);
|
|
152
|
+
const check = compile(this.discovery.docs.ajv, {
|
|
153
|
+
...schema,
|
|
154
|
+
$defs: this.$defs,
|
|
155
|
+
type: 'object',
|
|
156
|
+
});
|
|
157
|
+
const result = check(shallow);
|
|
158
|
+
performance.measure(`${this.constructor.name}.convert_object_check_shallow_parse()`, `${this.constructor.name}.convert_object_check_shallow_parse() start`);
|
|
159
|
+
if (!result) {
|
|
160
|
+
throw new NoMatchError({
|
|
161
|
+
shallow,
|
|
162
|
+
schema,
|
|
163
|
+
errors: check.errors,
|
|
164
|
+
}, 'Shallow parse of typed_string does not match object schema!');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
convert_object_property_schema(schema, property) {
|
|
168
|
+
performance.mark(`${this.constructor.name}.convert_object_property_schema() start`);
|
|
169
|
+
if ('properties' in schema) {
|
|
170
|
+
if (!(property in schema.properties)) {
|
|
171
|
+
performance.measure(`${this.constructor.name}.convert_object_property_schema() object failure`, `${this.constructor.name}.convert_object_property_schema() start`);
|
|
172
|
+
throw new NoMatchError({
|
|
173
|
+
property,
|
|
174
|
+
schema,
|
|
175
|
+
}, 'Property not in schema!');
|
|
176
|
+
}
|
|
177
|
+
performance.measure(`${this.constructor.name}.convert_object_property_schema() object schema`, `${this.constructor.name}.convert_object_property_schema() start`);
|
|
178
|
+
return schema.properties[property];
|
|
179
|
+
}
|
|
180
|
+
const json_string = JSON.stringify(schema.patternProperties);
|
|
181
|
+
if (!(json_string in this.regex_schema_cache)) {
|
|
182
|
+
this.regex_schema_cache[json_string] = Object.entries(schema.patternProperties).map((e) => {
|
|
183
|
+
return [
|
|
184
|
+
new RegExp(e[0]),
|
|
185
|
+
e[1],
|
|
186
|
+
];
|
|
187
|
+
});
|
|
188
|
+
performance.measure(`${this.constructor.name}.convert_object_property_schema() pattern caching`, `${this.constructor.name}.convert_object_property_schema() start`);
|
|
189
|
+
}
|
|
190
|
+
const property_regex_schema = this.regex_schema_cache[json_string].find(maybe => maybe[0].test(property));
|
|
191
|
+
if (!property_regex_schema) {
|
|
192
|
+
performance.measure(`${this.constructor.name}.convert_object_property_schema() pattern failure`, `${this.constructor.name}.convert_object_property_schema() start`);
|
|
193
|
+
throw new NoMatchError({
|
|
194
|
+
property,
|
|
195
|
+
schema,
|
|
196
|
+
}, 'Property not in schema!');
|
|
197
|
+
}
|
|
198
|
+
performance.measure(`${this.constructor.name}.convert_object_property_schema() pattern schema`, `${this.constructor.name}.convert_object_property_schema() start`);
|
|
199
|
+
return property_regex_schema[1];
|
|
200
|
+
}
|
|
201
|
+
async convert_prefixItems(schema, shallow) {
|
|
202
|
+
performance.mark(`${this.constructor.name}.convert_prefixItems() start`);
|
|
203
|
+
const slightly_less_than_shallow = [];
|
|
204
|
+
for (const entry of shallow) {
|
|
205
|
+
if (!is_string(entry)) {
|
|
206
|
+
throw new NoMatchError({
|
|
207
|
+
schema,
|
|
208
|
+
shallow,
|
|
209
|
+
entry,
|
|
210
|
+
}, 'Expecting string entries on shallow array!');
|
|
211
|
+
}
|
|
212
|
+
const inner_shallow = string_to_array(entry, true);
|
|
213
|
+
if (false === inner_shallow) {
|
|
214
|
+
throw new NoMatchError({
|
|
215
|
+
entry,
|
|
216
|
+
}, 'Failed to parse inner entry!');
|
|
217
|
+
}
|
|
218
|
+
this.check_shallow_array_schema_assert(schema, inner_shallow);
|
|
219
|
+
slightly_less_than_shallow.push(inner_shallow);
|
|
220
|
+
}
|
|
221
|
+
const converted = [];
|
|
222
|
+
for (const e of slightly_less_than_shallow) {
|
|
223
|
+
if (e.length !== schema.prefixItems.length) {
|
|
224
|
+
throw new NoMatchError({
|
|
225
|
+
e,
|
|
226
|
+
schema,
|
|
227
|
+
}, `Expected an array of length ${schema.prefixItems.length}, received ${e.length}`);
|
|
228
|
+
}
|
|
229
|
+
const items = [];
|
|
230
|
+
let index = 0;
|
|
231
|
+
for (const entry of e) {
|
|
232
|
+
const type = schema.prefixItems[index];
|
|
233
|
+
const converter = await Converter.find_matching_schema(await this.discovery.candidates, type);
|
|
234
|
+
if (!await converter.can_convert_schema_and_raw_data(type, entry)) {
|
|
235
|
+
throw new NoMatchError({
|
|
236
|
+
entry,
|
|
237
|
+
type,
|
|
238
|
+
converter: converter.constructor.name,
|
|
239
|
+
}, 'Cannot convert entry!');
|
|
240
|
+
}
|
|
241
|
+
items.push(await converter.convert(type, entry));
|
|
242
|
+
++index;
|
|
243
|
+
}
|
|
244
|
+
converted.push(new ExpressionResult(await this.discovery.literal.array_literal(items)));
|
|
245
|
+
}
|
|
246
|
+
const result = new ExpressionResult(await this.discovery.literal.array_literal(converted));
|
|
247
|
+
performance.measure(`${this.constructor.name}.convert_prefixItems()`, `${this.constructor.name}.convert_prefixItems() start`);
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=TypedString.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Converter, ExpressionResult } from '../Generator';
|
|
2
|
+
import { UnrealEngineString_parent_type } from '../../CustomParsingTypes/UnrealEngineString';
|
|
3
|
+
import { CallExpression } from 'typescript';
|
|
4
|
+
import { SchemaObject } from 'ajv';
|
|
5
|
+
export declare class UnrealEngineStringConverter extends Converter<UnrealEngineString_parent_type, string, CallExpression> {
|
|
6
|
+
can_convert_schema(schema: SchemaObject): schema is UnrealEngineString_parent_type;
|
|
7
|
+
can_convert_schema_and_raw_data(schema: SchemaObject, raw_data: unknown): Promise<boolean>;
|
|
8
|
+
convert(schema: UnrealEngineString_parent_type, raw_data: string): Promise<ExpressionResult<CallExpression>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Converter, ExpressionResult, } from '../Generator';
|
|
2
|
+
import { is_string, } from '../../StringStartsWith';
|
|
3
|
+
import { is_UnrealEngineString_parent, string_or_string_array_to_node, UnrealEngineString_regex, } from '../../CustomParsingTypes/UnrealEngineString';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
import { create_literal, create_property_access, create_type, type_reference_node, } from '../../TsFactoryWrapper';
|
|
6
|
+
import { object_has_property, value_is_non_array_object, } from '../../CustomParsingTypes/CustomPairingTypes';
|
|
7
|
+
import { NoMatchError, } from '../../Exceptions';
|
|
8
|
+
export class UnrealEngineStringConverter extends Converter {
|
|
9
|
+
can_convert_schema(schema) {
|
|
10
|
+
return is_UnrealEngineString_parent(schema);
|
|
11
|
+
}
|
|
12
|
+
can_convert_schema_and_raw_data(schema, raw_data) {
|
|
13
|
+
return Promise.resolve(this.can_convert_schema(schema)
|
|
14
|
+
&& is_string(raw_data)
|
|
15
|
+
&& UnrealEngineString_regex.test(raw_data));
|
|
16
|
+
}
|
|
17
|
+
async convert(schema, raw_data) {
|
|
18
|
+
if (!await this.can_convert_schema_and_raw_data(schema, raw_data)) {
|
|
19
|
+
throw new NoMatchError({
|
|
20
|
+
schema,
|
|
21
|
+
raw_data,
|
|
22
|
+
}, 'Not an UnrealEngineString!');
|
|
23
|
+
}
|
|
24
|
+
const type_args = [
|
|
25
|
+
create_literal('/Script/Engine.BlueprintGeneratedClass'),
|
|
26
|
+
create_type('string'),
|
|
27
|
+
];
|
|
28
|
+
const { UnrealEngineString } = schema;
|
|
29
|
+
if (true !== UnrealEngineString) {
|
|
30
|
+
if (object_has_property(UnrealEngineString, 'left')) {
|
|
31
|
+
type_args[0] = string_or_string_array_to_node(UnrealEngineString.left);
|
|
32
|
+
}
|
|
33
|
+
if (object_has_property(UnrealEngineString, 'right')) {
|
|
34
|
+
if (value_is_non_array_object(UnrealEngineString.right)) {
|
|
35
|
+
type_args[1] = type_reference_node('StringStartsWith', string_or_string_array_to_node(UnrealEngineString.right.starts_with));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
type_args[1] = string_or_string_array_to_node(UnrealEngineString.right);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return new ExpressionResult(ts.factory.createCallExpression(create_property_access(ts.factory.createIdentifier('UnrealEngineString'), 'fromString'), type_args, [ts.factory.createStringLiteral(raw_data)]));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=UnrealEngineString.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Expression } from 'typescript';
|
|
2
|
+
import Ajv, { SchemaObject, ValidateFunction } from 'ajv/dist/2020';
|
|
3
|
+
export declare abstract class Converter<Schema extends SchemaObject, RawData = unknown, Output extends Expression = Expression> {
|
|
4
|
+
abstract can_convert_schema(schema: SchemaObject): schema is Schema;
|
|
5
|
+
abstract can_convert_schema_and_raw_data(schema: SchemaObject, raw_data: unknown): Promise<boolean>;
|
|
6
|
+
abstract convert(schema: Schema, raw_data: RawData): Promise<ExpressionResult<Output>>;
|
|
7
|
+
static find_matching_schema(candidates: [Converter<SchemaObject>, ...Converter<SchemaObject>[]], schema: SchemaObject): Promise<Converter<SchemaObject>>;
|
|
8
|
+
static has_matching_schema(candidates: [Converter<SchemaObject>, ...Converter<SchemaObject>[]], schema: SchemaObject): Converter<SchemaObject> | undefined;
|
|
9
|
+
static has_matching_schema_and_raw_data(candidates: [Converter<SchemaObject>, ...Converter<SchemaObject>[]], schema: SchemaObject, raw_data: unknown): Promise<Converter<SchemaObject> | undefined>;
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class ConverterMatchesSchema<Schema extends SchemaObject, RawData = unknown, Output extends Expression = Expression> extends Converter<Schema, RawData, Output> {
|
|
12
|
+
protected check_schema: ValidateFunction<Schema>;
|
|
13
|
+
protected constructor(ajv: Ajv, schema: SchemaObject);
|
|
14
|
+
can_convert_schema(schema: SchemaObject): schema is Schema;
|
|
15
|
+
}
|
|
16
|
+
export declare class ExpressionResult<T extends Expression = Expression> {
|
|
17
|
+
readonly expression: T;
|
|
18
|
+
constructor(expression: T);
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { NoMatchError, } from '../Exceptions';
|
|
2
|
+
import { compile, } from '../AjvUtilities';
|
|
3
|
+
export class Converter {
|
|
4
|
+
static find_matching_schema(candidates, schema) {
|
|
5
|
+
const converter = this.has_matching_schema(candidates, schema);
|
|
6
|
+
if (converter) {
|
|
7
|
+
return Promise.resolve(converter);
|
|
8
|
+
}
|
|
9
|
+
return Promise.reject(new NoMatchError({
|
|
10
|
+
schema,
|
|
11
|
+
}, 'Could not identify suitable candidate!'));
|
|
12
|
+
}
|
|
13
|
+
static has_matching_schema(candidates, schema) {
|
|
14
|
+
return candidates.find(e => e.can_convert_schema(schema));
|
|
15
|
+
}
|
|
16
|
+
static async has_matching_schema_and_raw_data(candidates, schema, raw_data) {
|
|
17
|
+
for (const candidate of candidates) {
|
|
18
|
+
if (await candidate.can_convert_schema_and_raw_data(schema, raw_data)) {
|
|
19
|
+
return candidate;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class ConverterMatchesSchema extends Converter {
|
|
26
|
+
check_schema;
|
|
27
|
+
constructor(ajv, schema) {
|
|
28
|
+
super();
|
|
29
|
+
this.check_schema = compile(ajv, schema);
|
|
30
|
+
}
|
|
31
|
+
can_convert_schema(schema) {
|
|
32
|
+
return !!this.check_schema(schema);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class ExpressionResult {
|
|
36
|
+
expression;
|
|
37
|
+
constructor(expression) {
|
|
38
|
+
this.expression = expression;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=Generator.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConverterMatchesSchema, ExpressionResult } from '../Generator';
|
|
2
|
+
import { DataDiscovery } from '../../DataDiscovery';
|
|
3
|
+
import { SchemaObject } from 'ajv/dist/2020';
|
|
4
|
+
import { ArrayLiteralExpression } from 'typescript';
|
|
5
|
+
type array_type = {
|
|
6
|
+
type: 'array';
|
|
7
|
+
items: SchemaObject;
|
|
8
|
+
minItems: number;
|
|
9
|
+
maxItems?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare class ArrayConverter extends ConverterMatchesSchema<array_type, unknown[], ArrayLiteralExpression> {
|
|
12
|
+
private readonly discovery;
|
|
13
|
+
constructor(discovery: DataDiscovery);
|
|
14
|
+
can_convert_schema_and_raw_data(schema: SchemaObject, raw_data: unknown): Promise<boolean>;
|
|
15
|
+
convert(schema: array_type, raw_data: unknown[]): Promise<ExpressionResult<ArrayLiteralExpression>>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Converter, ConverterMatchesSchema, ExpressionResult, } from '../Generator';
|
|
2
|
+
import { NoMatchError, } from '../../Exceptions';
|
|
3
|
+
export class ArrayConverter extends ConverterMatchesSchema {
|
|
4
|
+
discovery;
|
|
5
|
+
constructor(discovery) {
|
|
6
|
+
super(discovery.docs.ajv, {
|
|
7
|
+
type: 'object',
|
|
8
|
+
required: ['type', 'minItems', 'items'],
|
|
9
|
+
additionalProperties: false,
|
|
10
|
+
properties: {
|
|
11
|
+
type: { type: 'string', const: 'array' },
|
|
12
|
+
items: { type: 'object' },
|
|
13
|
+
minItems: { type: 'number', minimum: 0 },
|
|
14
|
+
maxItems: { type: 'number', minimum: 1 },
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
this.discovery = discovery;
|
|
18
|
+
}
|
|
19
|
+
async can_convert_schema_and_raw_data(schema, raw_data) {
|
|
20
|
+
return Promise.resolve(this.can_convert_schema(schema)
|
|
21
|
+
&& raw_data instanceof Array
|
|
22
|
+
&& !!((await this.discovery.candidates).find(e => e.can_convert_schema(schema.items)))
|
|
23
|
+
&& !!Converter.has_matching_schema(await this.discovery.candidates, schema.items));
|
|
24
|
+
}
|
|
25
|
+
async convert(schema, raw_data) {
|
|
26
|
+
if (!this.can_convert_schema(schema)
|
|
27
|
+
|| !await this.can_convert_schema_and_raw_data(schema, raw_data)) {
|
|
28
|
+
throw new NoMatchError({
|
|
29
|
+
schema,
|
|
30
|
+
raw_data,
|
|
31
|
+
}, 'Cannot convert!');
|
|
32
|
+
}
|
|
33
|
+
const converter = await Converter.find_matching_schema(await this.discovery.candidates, schema.items);
|
|
34
|
+
const converted = [];
|
|
35
|
+
for (const entry of raw_data) {
|
|
36
|
+
converted.push(await converter.convert(schema.items, entry));
|
|
37
|
+
}
|
|
38
|
+
return new ExpressionResult(await this.discovery.literal.array_literal(converted));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=Array.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Converter, ConverterMatchesSchema, ExpressionResult } from '../Generator';
|
|
2
|
+
import { DataDiscovery } from '../../DataDiscovery';
|
|
3
|
+
import { SchemaObject } from 'ajv/dist/2020';
|
|
4
|
+
import { local_ref } from '../../StringStartsWith';
|
|
5
|
+
import { Expression, ObjectLiteralExpression } from 'typescript';
|
|
6
|
+
import { typed_string_inner_object_pattern_type } from '../../CustomParsingTypes/TypedString';
|
|
7
|
+
export type schema_type = {
|
|
8
|
+
type: 'object';
|
|
9
|
+
$ref: local_ref<string>;
|
|
10
|
+
unevaluatedProperties?: false;
|
|
11
|
+
required?: [string, ...string[]];
|
|
12
|
+
properties?: {
|
|
13
|
+
[key: string]: SchemaObject;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
declare abstract class ObjectConverterMatchesSchema<Schema extends SchemaObject, RawData = unknown, Output extends Expression = Expression> extends ConverterMatchesSchema<Schema, RawData, Output> {
|
|
17
|
+
protected readonly already_resolved: {
|
|
18
|
+
[key: string]: {
|
|
19
|
+
[key: string]: SchemaObject;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
protected readonly discovery: DataDiscovery;
|
|
23
|
+
constructor(discovery: DataDiscovery, schema: SchemaObject);
|
|
24
|
+
can_convert_schema_and_raw_data(schema: SchemaObject, raw_data: unknown): Promise<boolean>;
|
|
25
|
+
check_converters(schema: schema_type, raw_data: {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
[key: string]: Converter<SchemaObject, unknown, Expression>;
|
|
29
|
+
}>;
|
|
30
|
+
check_converters_for_missing_keys(raw_data: {
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}, converters: {
|
|
33
|
+
[key: string]: Converter<SchemaObject>;
|
|
34
|
+
}): string[];
|
|
35
|
+
protected resolve_converters(schema: SchemaObject): Promise<{
|
|
36
|
+
[key: string]: Converter<SchemaObject>;
|
|
37
|
+
}>;
|
|
38
|
+
protected resolve_converters_for_$ref($ref: local_ref<string>): Promise<{
|
|
39
|
+
[key: string]: Converter<SchemaObject>;
|
|
40
|
+
}>;
|
|
41
|
+
protected resolve_schema(schema: SchemaObject, depth?: number): Promise<{
|
|
42
|
+
[key: string]: SchemaObject;
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
export declare class ObjectConverter extends ObjectConverterMatchesSchema<schema_type, {
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}, ObjectLiteralExpression> {
|
|
48
|
+
constructor(discovery: DataDiscovery);
|
|
49
|
+
convert(schema: schema_type, raw_data: {
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}): Promise<ExpressionResult<ObjectLiteralExpression>>;
|
|
52
|
+
}
|
|
53
|
+
export declare class PatternedObjectConverter extends ObjectConverterMatchesSchema<typed_string_inner_object_pattern_type, {
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
}, ObjectLiteralExpression> {
|
|
56
|
+
constructor(discovery: DataDiscovery);
|
|
57
|
+
convert(schema: typed_string_inner_object_pattern_type, raw_data: {
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}): Promise<ExpressionResult<ObjectLiteralExpression>>;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Converter, ConverterMatchesSchema, ExpressionResult, } from '../Generator';
|
|
2
|
+
import { object_has_property, value_is_non_array_object, } from '../../CustomParsingTypes/CustomPairingTypes';
|
|
3
|
+
import { is_string, } from '../../StringStartsWith';
|
|
4
|
+
import { NoMatchError, } from '../../Exceptions';
|
|
5
|
+
import { pattern_properties_regex, } from '../../CustomParsingTypes/TypedString';
|
|
6
|
+
class ObjectConverterMatchesSchema extends ConverterMatchesSchema {
|
|
7
|
+
already_resolved = {};
|
|
8
|
+
discovery;
|
|
9
|
+
constructor(discovery, schema) {
|
|
10
|
+
super(discovery.docs.ajv, schema);
|
|
11
|
+
this.discovery = discovery;
|
|
12
|
+
}
|
|
13
|
+
async can_convert_schema_and_raw_data(schema, raw_data) {
|
|
14
|
+
return (this.can_convert_schema(schema)
|
|
15
|
+
&& value_is_non_array_object(raw_data)
|
|
16
|
+
&& 0 === this.check_converters_for_missing_keys(raw_data, await this.resolve_converters(schema)).length
|
|
17
|
+
&& await new Promise((yup => {
|
|
18
|
+
this.convert(schema, raw_data).then(() => yup(true)).catch(() => yup(false));
|
|
19
|
+
})));
|
|
20
|
+
}
|
|
21
|
+
async check_converters(schema, raw_data) {
|
|
22
|
+
const converters = await this.resolve_converters(schema);
|
|
23
|
+
performance.mark(`${this.constructor.name}.check_converters() start`);
|
|
24
|
+
const missing_keys = this.check_converters_for_missing_keys(raw_data, converters);
|
|
25
|
+
if (missing_keys.length) {
|
|
26
|
+
performance.measure(`${this.constructor.name}.check_converters() missing converters`, `${this.constructor.name}.check_converters() start`);
|
|
27
|
+
throw new NoMatchError({
|
|
28
|
+
missing_keys,
|
|
29
|
+
schema,
|
|
30
|
+
raw_data,
|
|
31
|
+
}, 'Missing converters');
|
|
32
|
+
}
|
|
33
|
+
return converters;
|
|
34
|
+
}
|
|
35
|
+
check_converters_for_missing_keys(raw_data, converters) {
|
|
36
|
+
return Object.keys(raw_data).filter((maybe) => !(maybe in converters));
|
|
37
|
+
}
|
|
38
|
+
async resolve_converters(schema) {
|
|
39
|
+
performance.mark(`${this.constructor.name}.resolve_converters() start`);
|
|
40
|
+
const converters = {};
|
|
41
|
+
if (object_has_property(schema, 'properties', (maybe) => {
|
|
42
|
+
return (value_is_non_array_object(maybe)
|
|
43
|
+
&& Object.values(maybe).every(e => value_is_non_array_object(e)));
|
|
44
|
+
})) {
|
|
45
|
+
const { properties } = schema;
|
|
46
|
+
for (const entry of Object.entries(properties)) {
|
|
47
|
+
converters[entry[0]] = await Converter.find_matching_schema(await this.discovery.candidates, entry[1]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if ('$ref' in schema
|
|
51
|
+
&& is_string(schema.$ref)
|
|
52
|
+
&& schema.$ref.startsWith('#/$defs/')) {
|
|
53
|
+
const $ref_converters = Object.entries(await this.resolve_converters_for_$ref(schema.$ref));
|
|
54
|
+
for (const entry of $ref_converters) {
|
|
55
|
+
const [property, converter] = entry;
|
|
56
|
+
if (!(property in converters)) {
|
|
57
|
+
converters[property] = converter;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
performance.measure(`${this.constructor.name}.resolve_converters() resolve_converters`, `${this.constructor.name}.resolve_converters() start`);
|
|
62
|
+
return converters;
|
|
63
|
+
}
|
|
64
|
+
async resolve_converters_for_$ref($ref) {
|
|
65
|
+
const definition = await this.discovery.docs.definition($ref.substring(8));
|
|
66
|
+
return this.resolve_converters(definition);
|
|
67
|
+
}
|
|
68
|
+
async resolve_schema(schema, depth = 0) {
|
|
69
|
+
performance.mark(`${this.constructor.name}.resolve_schema() start`);
|
|
70
|
+
const json_string = JSON.stringify(schema);
|
|
71
|
+
if (json_string in this.already_resolved) {
|
|
72
|
+
performance.measure(`${this.constructor.name}.resolve_schema() previously resolved`, `${this.constructor.name}.resolve_schema() start`);
|
|
73
|
+
return this.already_resolved[json_string];
|
|
74
|
+
}
|
|
75
|
+
const resolved_schema = {};
|
|
76
|
+
if (object_has_property(schema, 'properties', (e) => {
|
|
77
|
+
return (value_is_non_array_object(e)
|
|
78
|
+
&& Object.values(e).every(value_is_non_array_object));
|
|
79
|
+
})) {
|
|
80
|
+
const { properties } = schema;
|
|
81
|
+
for (const entry of Object.entries(properties)) {
|
|
82
|
+
const [property, sub_schema] = entry;
|
|
83
|
+
resolved_schema[property] = sub_schema;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if ('$ref' in schema
|
|
87
|
+
&& is_string(schema.$ref)
|
|
88
|
+
&& schema.$ref.startsWith('#/$defs/')) {
|
|
89
|
+
for (const entry of Object.entries(await this.resolve_schema(await this.discovery.docs.definition(schema.$ref.substring(8)), depth + 1))) {
|
|
90
|
+
const [property, sub_schema] = entry;
|
|
91
|
+
if (!(property in resolved_schema)) {
|
|
92
|
+
resolved_schema[property] = sub_schema;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
performance.measure(`${this.constructor.name}.resolve_schema()`, `${this.constructor.name}.resolve_schema() start`);
|
|
97
|
+
this.already_resolved[json_string] = resolved_schema;
|
|
98
|
+
return resolved_schema;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export class ObjectConverter extends ObjectConverterMatchesSchema {
|
|
102
|
+
constructor(discovery) {
|
|
103
|
+
super(discovery, {
|
|
104
|
+
type: 'object',
|
|
105
|
+
required: ['type'],
|
|
106
|
+
additionalProperties: false,
|
|
107
|
+
properties: {
|
|
108
|
+
type: { type: 'string', const: 'object' },
|
|
109
|
+
$ref: { type: 'string', pattern: '^#/\\$defs/' },
|
|
110
|
+
required: {
|
|
111
|
+
type: 'array',
|
|
112
|
+
minItems: 1,
|
|
113
|
+
items: { type: 'string' },
|
|
114
|
+
},
|
|
115
|
+
additionalProperties: { type: 'boolean', const: false },
|
|
116
|
+
unevaluatedProperties: { type: 'boolean', const: false },
|
|
117
|
+
properties: { type: 'object', minProperties: 1 },
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async convert(schema, raw_data) {
|
|
122
|
+
performance.mark(`${this.constructor.name}.convert() start`);
|
|
123
|
+
const sub_schema = await this.resolve_schema(schema);
|
|
124
|
+
performance.measure(`${this.constructor.name}.convert() sub_schema`, `${this.constructor.name}.convert() start`);
|
|
125
|
+
const converters = await this.check_converters(schema, raw_data);
|
|
126
|
+
const result = {};
|
|
127
|
+
for (const entry of Object.entries(raw_data)) {
|
|
128
|
+
const [property, value] = entry;
|
|
129
|
+
performance.mark(`${this.constructor.name}.convert() property start`);
|
|
130
|
+
if (!await converters[property].can_convert_schema_and_raw_data(sub_schema[property], value)) {
|
|
131
|
+
throw new NoMatchError({
|
|
132
|
+
property,
|
|
133
|
+
value,
|
|
134
|
+
sub_schema: sub_schema[property],
|
|
135
|
+
instance: converters[property].constructor.name,
|
|
136
|
+
}, 'Cannot convert value!');
|
|
137
|
+
}
|
|
138
|
+
performance.measure(`${this.constructor.name}.convert() property checked`, `${this.constructor.name}.convert() property start`);
|
|
139
|
+
performance.mark(`${this.constructor.name}.convert() property start`);
|
|
140
|
+
result[property] = await converters[property].convert(sub_schema[property], value);
|
|
141
|
+
performance.measure(`${this.constructor.name}.convert() property converted`, `${this.constructor.name}.convert() property start`);
|
|
142
|
+
}
|
|
143
|
+
performance.measure(`${this.constructor.name}.convert() converted`, `${this.constructor.name}.convert() start`);
|
|
144
|
+
performance.mark(`${this.constructor.name}.convert() start`);
|
|
145
|
+
const expression = new ExpressionResult(await this.discovery.literal.object_literal(result));
|
|
146
|
+
performance.measure(`${this.constructor.name}.convert() expression`, `${this.constructor.name}.convert() start`);
|
|
147
|
+
return expression;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export class PatternedObjectConverter extends ObjectConverterMatchesSchema {
|
|
151
|
+
constructor(discovery) {
|
|
152
|
+
super(discovery, {
|
|
153
|
+
type: 'object',
|
|
154
|
+
required: ['type', 'minProperties', 'patternProperties'],
|
|
155
|
+
additionalProperties: false,
|
|
156
|
+
properties: {
|
|
157
|
+
type: { type: 'string', const: 'object' },
|
|
158
|
+
$ref: { type: 'string', pattern: '^#/\\$defs/' },
|
|
159
|
+
additionalProperties: { type: 'boolean', const: false },
|
|
160
|
+
unevaluatedProperties: { type: 'boolean', const: false },
|
|
161
|
+
minProperties: { type: 'number', minimum: 1 },
|
|
162
|
+
maxProperties: { type: 'number', minimum: 1 },
|
|
163
|
+
patternProperties: {
|
|
164
|
+
type: 'object',
|
|
165
|
+
minProperties: 1,
|
|
166
|
+
maxProperties: 1,
|
|
167
|
+
patternProperties: {
|
|
168
|
+
[pattern_properties_regex]: {
|
|
169
|
+
type: 'object',
|
|
170
|
+
minProperties: 1,
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
convert(schema, raw_data) {
|
|
178
|
+
throw new NoMatchError({
|
|
179
|
+
schema,
|
|
180
|
+
raw_data,
|
|
181
|
+
}, 'Method not implemented.');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=Object.js.map
|