@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.
Files changed (152) hide show
  1. package/LICENSE.md +190 -0
  2. package/README.md +81 -0
  3. package/assert/CustomAssert.d.ts +2 -0
  4. package/assert/CustomAssert.js +5 -0
  5. package/lib/AjvUtilities.d.ts +7 -0
  6. package/lib/AjvUtilities.js +59 -0
  7. package/lib/ArrayUtilities.d.ts +24 -0
  8. package/lib/ArrayUtilities.js +21 -0
  9. package/lib/CustomParsingTypes/CustomPairingTypes.d.ts +37 -0
  10. package/lib/CustomParsingTypes/CustomPairingTypes.js +42 -0
  11. package/lib/CustomParsingTypes/TypedString.d.ts +411 -0
  12. package/lib/CustomParsingTypes/TypedString.js +204 -0
  13. package/lib/CustomParsingTypes/TypedStringConst.d.ts +28 -0
  14. package/lib/CustomParsingTypes/TypedStringConst.js +35 -0
  15. package/lib/CustomParsingTypes/TypedStringEnum.d.ts +30 -0
  16. package/lib/CustomParsingTypes/TypedStringEnum.js +36 -0
  17. package/lib/CustomParsingTypes/TypedStringPattern.d.ts +64 -0
  18. package/lib/CustomParsingTypes/TypedStringPattern.js +82 -0
  19. package/lib/CustomParsingTypes/UnrealEngineString.d.ts +215 -0
  20. package/lib/CustomParsingTypes/UnrealEngineString.js +308 -0
  21. package/lib/CustomParsingTypes/ValueToRegexFormatter.d.ts +29 -0
  22. package/lib/CustomParsingTypes/ValueToRegexFormatter.js +205 -0
  23. package/lib/DataDiscovery/CustomTypes/BooleanOrBooleanExtended.d.ts +12 -0
  24. package/lib/DataDiscovery/CustomTypes/BooleanOrBooleanExtended.js +32 -0
  25. package/lib/DataDiscovery/CustomTypes/StringStartsWith.d.ts +9 -0
  26. package/lib/DataDiscovery/CustomTypes/StringStartsWith.js +19 -0
  27. package/lib/DataDiscovery/CustomTypes/TypedString.d.ts +23 -0
  28. package/lib/DataDiscovery/CustomTypes/TypedString.js +251 -0
  29. package/lib/DataDiscovery/CustomTypes/UnrealEngineString.d.ts +9 -0
  30. package/lib/DataDiscovery/CustomTypes/UnrealEngineString.js +45 -0
  31. package/lib/DataDiscovery/Generator.d.ts +19 -0
  32. package/lib/DataDiscovery/Generator.js +41 -0
  33. package/lib/DataDiscovery/JsonSchema/Array.d.ts +17 -0
  34. package/lib/DataDiscovery/JsonSchema/Array.js +41 -0
  35. package/lib/DataDiscovery/JsonSchema/Object.d.ts +61 -0
  36. package/lib/DataDiscovery/JsonSchema/Object.js +184 -0
  37. package/lib/DataDiscovery/JsonSchema/OneOf.d.ts +13 -0
  38. package/lib/DataDiscovery/JsonSchema/OneOf.js +47 -0
  39. package/lib/DataDiscovery/JsonSchema/Ref.d.ts +17 -0
  40. package/lib/DataDiscovery/JsonSchema/Ref.js +66 -0
  41. package/lib/DataDiscovery/JsonSchema/StringType.d.ts +39 -0
  42. package/lib/DataDiscovery/JsonSchema/StringType.js +121 -0
  43. package/lib/DataDiscovery/Literal.d.ts +8 -0
  44. package/lib/DataDiscovery/Literal.js +69 -0
  45. package/lib/DataDiscovery.d.ts +28 -0
  46. package/lib/DataDiscovery.js +116 -0
  47. package/lib/DocsToAutoImport/ArrayTypeNodes.d.ts +5 -0
  48. package/lib/DocsToAutoImport/ArrayTypeNodes.js +7 -0
  49. package/lib/DocsToAutoImport/ClassDeclarations.d.ts +5 -0
  50. package/lib/DocsToAutoImport/ClassDeclarations.js +14 -0
  51. package/lib/DocsToAutoImport/FunctionDeclaration.d.ts +5 -0
  52. package/lib/DocsToAutoImport/FunctionDeclaration.js +16 -0
  53. package/lib/DocsToAutoImport/LiteralTypeNodes.d.ts +5 -0
  54. package/lib/DocsToAutoImport/LiteralTypeNodes.js +23 -0
  55. package/lib/DocsToAutoImport/MethodDeclarations.d.ts +5 -0
  56. package/lib/DocsToAutoImport/MethodDeclarations.js +15 -0
  57. package/lib/DocsToAutoImport/NodeExtraction.d.ts +6 -0
  58. package/lib/DocsToAutoImport/NodeExtraction.js +21 -0
  59. package/lib/DocsToAutoImport/PropertyDeclarations.d.ts +5 -0
  60. package/lib/DocsToAutoImport/PropertyDeclarations.js +10 -0
  61. package/lib/DocsToAutoImport/TupleTypeNodes.d.ts +5 -0
  62. package/lib/DocsToAutoImport/TupleTypeNodes.js +7 -0
  63. package/lib/DocsToAutoImport/TypeLiteralNodes.d.ts +5 -0
  64. package/lib/DocsToAutoImport/TypeLiteralNodes.js +33 -0
  65. package/lib/DocsToAutoImport/TypeReferenceNodes.d.ts +5 -0
  66. package/lib/DocsToAutoImport/TypeReferenceNodes.js +7 -0
  67. package/lib/DocsToAutoImport/from_Node_array.d.ts +3 -0
  68. package/lib/DocsToAutoImport/from_Node_array.js +245 -0
  69. package/lib/DocsTsAutoImports.d.ts +21 -0
  70. package/lib/DocsTsAutoImports.js +110 -0
  71. package/lib/DocsTsGenerator/FilesGenerator.d.ts +25 -0
  72. package/lib/DocsTsGenerator/FilesGenerator.js +52 -0
  73. package/lib/DocsTsGenerator.d.ts +47 -0
  74. package/lib/DocsTsGenerator.js +188 -0
  75. package/lib/DocsValidation.d.ts +7 -0
  76. package/lib/DocsValidation.js +179 -0
  77. package/lib/Exceptions.d.ts +7 -0
  78. package/lib/Exceptions.js +13 -0
  79. package/lib/FilesGenerator.d.ts +19 -0
  80. package/lib/FilesGenerator.js +38 -0
  81. package/lib/MarkdownUtilities.d.ts +16 -0
  82. package/lib/MarkdownUtilities.js +68 -0
  83. package/lib/StringStartsWith.d.ts +10 -0
  84. package/lib/StringStartsWith.js +20 -0
  85. package/lib/TsFactoryWrapper.d.ts +80 -0
  86. package/lib/TsFactoryWrapper.js +236 -0
  87. package/lib/TypeDefinitionDiscovery/CustomParsingTypes/UnrealEngineString.d.ts +13 -0
  88. package/lib/TypeDefinitionDiscovery/CustomParsingTypes/UnrealEngineString.js +26 -0
  89. package/lib/TypeDefinitionDiscovery/CustomParsingTypes/string_starts_with.d.ts +25 -0
  90. package/lib/TypeDefinitionDiscovery/CustomParsingTypes/string_starts_with.js +20 -0
  91. package/lib/TypeDefinitionDiscovery/CustomParsingTypes/typed_string.d.ts +14 -0
  92. package/lib/TypeDefinitionDiscovery/CustomParsingTypes/typed_string.js +96 -0
  93. package/lib/TypeDefinitionDiscovery/Generator.d.ts +8 -0
  94. package/lib/TypeDefinitionDiscovery/Generator.js +8 -0
  95. package/lib/TypeDefinitionDiscovery/GeneratorDoesDiscovery.d.ts +8 -0
  96. package/lib/TypeDefinitionDiscovery/GeneratorDoesDiscovery.js +9 -0
  97. package/lib/TypeDefinitionDiscovery/JsonSchema/ArrayType.d.ts +19 -0
  98. package/lib/TypeDefinitionDiscovery/JsonSchema/ArrayType.js +61 -0
  99. package/lib/TypeDefinitionDiscovery/JsonSchema/Object/ExtendsObject.d.ts +23 -0
  100. package/lib/TypeDefinitionDiscovery/JsonSchema/Object/ExtendsObject.js +40 -0
  101. package/lib/TypeDefinitionDiscovery/JsonSchema/ObjectType.d.ts +91 -0
  102. package/lib/TypeDefinitionDiscovery/JsonSchema/ObjectType.js +76 -0
  103. package/lib/TypeDefinitionDiscovery/JsonSchema/String/Const.d.ts +29 -0
  104. package/lib/TypeDefinitionDiscovery/JsonSchema/String/Const.js +20 -0
  105. package/lib/TypeDefinitionDiscovery/JsonSchema/String/Enum/BooleanEnum.d.ts +16 -0
  106. package/lib/TypeDefinitionDiscovery/JsonSchema/String/Enum/BooleanEnum.js +47 -0
  107. package/lib/TypeDefinitionDiscovery/JsonSchema/String/Enum.d.ts +40 -0
  108. package/lib/TypeDefinitionDiscovery/JsonSchema/String/Enum.js +22 -0
  109. package/lib/TypeDefinitionDiscovery/JsonSchema/String/Pattern.d.ts +13 -0
  110. package/lib/TypeDefinitionDiscovery/JsonSchema/String/Pattern.js +21 -0
  111. package/lib/TypeDefinitionDiscovery/JsonSchema/String.d.ts +52 -0
  112. package/lib/TypeDefinitionDiscovery/JsonSchema/String.js +72 -0
  113. package/lib/TypeDefinitionDiscovery/JsonSchema/oneOf_or_anyOf.d.ts +63 -0
  114. package/lib/TypeDefinitionDiscovery/JsonSchema/oneOf_or_anyOf.js +47 -0
  115. package/lib/TypeDefinitionDiscovery.d.ts +49 -0
  116. package/lib/TypeDefinitionDiscovery.js +376 -0
  117. package/lib/TypeDefinitionWriter.d.ts +22 -0
  118. package/lib/TypeDefinitionWriter.js +233 -0
  119. package/lib/TypesDiscovery/CandidatesDiscovery.d.ts +10 -0
  120. package/lib/TypesDiscovery/CandidatesDiscovery.js +14 -0
  121. package/lib/TypesDiscovery/CustomParsingTypes/UnrealEngineString.d.ts +5 -0
  122. package/lib/TypesDiscovery/CustomParsingTypes/UnrealEngineString.js +18 -0
  123. package/lib/TypesDiscovery/CustomParsingTypes/typed_string.d.ts +6 -0
  124. package/lib/TypesDiscovery/CustomParsingTypes/typed_string.js +34 -0
  125. package/lib/TypesDiscovery/JsonSchema/$ref.d.ts +7 -0
  126. package/lib/TypesDiscovery/JsonSchema/$ref.js +33 -0
  127. package/lib/TypesDiscovery/JsonSchema/const.d.ts +6 -0
  128. package/lib/TypesDiscovery/JsonSchema/const.js +22 -0
  129. package/lib/TypesDiscovery/JsonSchema/enum.d.ts +6 -0
  130. package/lib/TypesDiscovery/JsonSchema/enum.js +22 -0
  131. package/lib/TypesDiscovery/JsonSchema/properties.d.ts +4 -0
  132. package/lib/TypesDiscovery/JsonSchema/properties.js +14 -0
  133. package/lib/TypesDiscovery/non_array_object_property.d.ts +4 -0
  134. package/lib/TypesDiscovery/non_array_object_property.js +11 -0
  135. package/lib/TypesDiscovery/non_empty_array_property.d.ts +4 -0
  136. package/lib/TypesDiscovery/non_empty_array_property.js +11 -0
  137. package/lib/TypesDiscovery.d.ts +24 -0
  138. package/lib/TypesDiscovery.js +77 -0
  139. package/lib/TypesGeneration/validators.d.ts +9 -0
  140. package/lib/TypesGeneration/validators.js +26 -0
  141. package/lib/TypesGeneration.d.ts +17 -0
  142. package/lib/TypesGeneration.js +53 -0
  143. package/lib/__dirname.d.ts +1 -0
  144. package/lib/__dirname.js +6 -0
  145. package/lib/helpers.d.ts +5 -0
  146. package/lib/helpers.js +29 -0
  147. package/lib/index.d.ts +8 -0
  148. package/lib/index.js +9 -0
  149. package/package.json +39 -0
  150. package/schema/update8.schema.json +8848 -0
  151. package/setup_PerformanceObserver.d.ts +3 -0
  152. package/setup_PerformanceObserver.js +55 -0
@@ -0,0 +1,376 @@
1
+ import { TypesDiscovery, } from './TypesDiscovery';
2
+ import { is_non_empty_array, object_has_non_empty_array_property, object_has_property, value_is_non_array_object, } from './CustomParsingTypes/CustomPairingTypes';
3
+ import { is_string, } from './StringStartsWith';
4
+ import ts from 'typescript';
5
+ import { Const, } from './TypeDefinitionDiscovery/JsonSchema/String/Const';
6
+ import { Pattern, } from './TypeDefinitionDiscovery/JsonSchema/String/Pattern';
7
+ import { Enum, } from './TypeDefinitionDiscovery/JsonSchema/String/Enum';
8
+ import { BooleanEnum, } from './TypeDefinitionDiscovery/JsonSchema/String/Enum/BooleanEnum';
9
+ import { string_starts_with, } from './TypeDefinitionDiscovery/CustomParsingTypes/string_starts_with';
10
+ import { UnrealEngineString, } from './TypeDefinitionDiscovery/CustomParsingTypes/UnrealEngineString';
11
+ import { NonEmptyString, NonEmptyStringWithExclusions, StringType, } from './TypeDefinitionDiscovery/JsonSchema/String';
12
+ import { FilesGenerator, guess_filename, } from './FilesGenerator';
13
+ import { adjust_class_name, create_modifiers, } from './TsFactoryWrapper';
14
+ import { reduce, remap, remove_indentation, } from './MarkdownUtilities';
15
+ import { compile, } from './AjvUtilities';
16
+ import { NoMatchError, } from './Exceptions';
17
+ function is_schema_with_$defs(schema, discovered_types) {
18
+ return (object_has_property(schema, '$defs', value_is_non_array_object)
19
+ && Object.keys(schema.$defs).every(maybe => (maybe.startsWith('#/$defs/')
20
+ ? maybe
21
+ : `#/$defs/${maybe}`) in discovered_types)
22
+ && Object.keys(discovered_types).every(maybe => {
23
+ const ref = (maybe.startsWith('#/$defs/')
24
+ ? maybe.substring(8)
25
+ : maybe);
26
+ return value_is_non_array_object(schema.$defs[ref]);
27
+ }));
28
+ }
29
+ export class TypeDefinitionDiscovery extends FilesGenerator {
30
+ $ref_discovery;
31
+ candidates;
32
+ docs;
33
+ types_discovery;
34
+ constructor(types_discovery, type_definition_discover, docs) {
35
+ super();
36
+ this.types_discovery = new TypesDiscovery(types_discovery, docs);
37
+ this.candidates = type_definition_discover;
38
+ this.docs = docs;
39
+ }
40
+ add_candidates(...candidates) {
41
+ this.candidates.push(...candidates);
42
+ }
43
+ async discover_type_$defs() {
44
+ if (!this.$ref_discovery) {
45
+ const discovered_types = await this.types_discovery.discover_types();
46
+ if (discovered_types.missed_types.length > 0) {
47
+ throw new Error(`Missing some type $defs:\n${discovered_types.missed_types.join('\n')}`);
48
+ }
49
+ else if (!is_non_empty_array(discovered_types.discovered_types, is_string)) {
50
+ throw new Error('No types discovered!');
51
+ }
52
+ const discovered_types_as_object = Object.fromEntries(discovered_types.discovered_types.map(e => [e, true]));
53
+ const schema = await this.schema_from_json(discovered_types_as_object);
54
+ this.$ref_discovery = Promise.resolve(this.discover_type_definitions_from(schema, discovered_types_as_object));
55
+ }
56
+ return this.$ref_discovery;
57
+ }
58
+ find(maybe) {
59
+ const type = this.search(maybe);
60
+ if (!type) {
61
+ throw new NoMatchError(maybe, 'Could not find a match!');
62
+ }
63
+ return type;
64
+ }
65
+ async *generate_files() {
66
+ const types = await this.discover_type_$defs();
67
+ for (const entry of Object.entries(types.found_types)) {
68
+ const [definition, generator] = entry;
69
+ const $ref = definition.substring(8);
70
+ const target_file = guess_filename($ref);
71
+ yield {
72
+ file: target_file,
73
+ node: ts.factory.createTypeAliasDeclaration(create_modifiers('export'), adjust_class_name(`${$ref}__type`), undefined, generator(await this.docs.definition($ref))),
74
+ };
75
+ }
76
+ }
77
+ async generate_markdown() {
78
+ const grouped_progress = {
79
+ members: [],
80
+ subgroups: {},
81
+ };
82
+ const manual_groups = {
83
+ class: '',
84
+ 'class--no-description': '',
85
+ 'class--no-description-or-display-name': '',
86
+ 'color-decimal--semi-native': 'color',
87
+ 'decimal-string': '',
88
+ 'decimal-string--signed': '',
89
+ 'integer-string': '',
90
+ 'integer-string--signed': '',
91
+ 'FGAmmoTypeInstantHit--base': 'FGAmmoType',
92
+ 'FGAmmoTypeInstantHit--chaos': 'FGAmmoType',
93
+ 'FGAmmoTypeInstantHit--standard': 'FGAmmoType',
94
+ FGAmmoTypeProjectile: 'FGAmmoType',
95
+ 'FGAmmoTypeProjectile--base': 'FGAmmoType',
96
+ xyz: 'vectors',
97
+ 'xyz--semi-native': 'vectors',
98
+ xy: 'vectors',
99
+ 'xy--integer': 'vectors',
100
+ 'xy--semi-native': 'vectors',
101
+ 'xyz--integer': 'vectors',
102
+ quaternion: 'vectors',
103
+ 'quaternion--semi-native': 'vectors',
104
+ 'pitch-yaw-roll': 'vectors',
105
+ 'FGEquipmentDescriptor--base': 'FGEquipment',
106
+ };
107
+ const discovered_types = await this.types_discovery.discover_types();
108
+ const all_referenced_types = [
109
+ ...discovered_types.discovered_types,
110
+ ...discovered_types.missed_types,
111
+ ].map(e => e.substring(8)).sort((a, b) => a.localeCompare(b));
112
+ const supported_types = discovered_types.discovered_types.map(e => e.substring(8));
113
+ for (const item of all_referenced_types) {
114
+ const parts = item.split('--');
115
+ let checking = grouped_progress;
116
+ if (item in manual_groups) {
117
+ if ('' !== manual_groups[item]) {
118
+ if (!(manual_groups[item] in checking.subgroups)) {
119
+ checking.subgroups[manual_groups[item]] = {
120
+ members: [],
121
+ subgroups: {},
122
+ };
123
+ }
124
+ checking = checking.subgroups[manual_groups[item]];
125
+ }
126
+ }
127
+ else if (parts.length > 1) {
128
+ for (let iteration = 1; iteration < Math.min(2, parts.length); ++iteration) {
129
+ if (!(parts[iteration - 1] in checking.subgroups)) {
130
+ checking.subgroups[parts[iteration - 1]] = {
131
+ members: [],
132
+ subgroups: {},
133
+ };
134
+ }
135
+ checking = checking.subgroups[parts[iteration - 1]];
136
+ }
137
+ }
138
+ if (!checking.members.includes(item)) {
139
+ checking.members.push(item);
140
+ }
141
+ }
142
+ remap(grouped_progress);
143
+ return remove_indentation(`
144
+ # Types Progress
145
+
146
+ ${((supported_types.length /
147
+ all_referenced_types.length) *
148
+ 100).toFixed(2)}% Complete (${supported_types.length} of ${all_referenced_types.length})
149
+
150
+ ${reduce(grouped_progress).map((group) => {
151
+ return remove_indentation(`
152
+ ${'#'.repeat(group.depth)} ${group.title}
153
+
154
+ ${group.members.map((key) => {
155
+ return `- [${supported_types.includes(key) ? 'x' : ' '}] ${key.replace(/__/g, '\\_\\_')}`;
156
+ }).join('\n')}`);
157
+ }).join('\n\n')}
158
+ `);
159
+ }
160
+ discover_type_definitions_from(schema, discovered_types) {
161
+ const result = {
162
+ found_types: {},
163
+ missing_types: [],
164
+ found_classes: [],
165
+ missing_classes: [],
166
+ };
167
+ const $defs = Object.keys(discovered_types);
168
+ for (const definition of $defs) {
169
+ const $ref = definition.substring(8);
170
+ const generator = this.candidates.find(e => e.check(schema.$defs[$ref]));
171
+ if (generator) {
172
+ result.found_types[definition] = generator.generate();
173
+ }
174
+ else {
175
+ result.missing_types.push(definition);
176
+ }
177
+ }
178
+ if (object_has_non_empty_array_property(schema, 'prefixItems', value_is_non_array_object)) {
179
+ const native_class = compile(this.docs.ajv, {
180
+ type: 'object',
181
+ required: ['type', '$ref', 'properties'],
182
+ additionalProperties: false,
183
+ $defs: {
184
+ $ref_base: {
185
+ type: 'object',
186
+ required: [
187
+ 'type',
188
+ '$ref',
189
+ 'unevaluatedProperties',
190
+ ],
191
+ properties: {
192
+ type: {
193
+ type: 'string',
194
+ const: 'object',
195
+ },
196
+ $ref: {
197
+ type: 'string',
198
+ enum: $defs,
199
+ },
200
+ unevaluatedProperties: {
201
+ type: 'boolean',
202
+ const: false,
203
+ },
204
+ },
205
+ },
206
+ $ref: {
207
+ type: 'object',
208
+ $ref: '#/$defs/$ref_base',
209
+ unevaluatedProperties: false,
210
+ },
211
+ },
212
+ properties: {
213
+ type: { type: 'string', const: 'object' },
214
+ $ref: { type: 'string', const: '#/$defs/NativeClass' },
215
+ unevaluatedProperties: { type: 'boolean', const: false },
216
+ properties: {
217
+ type: 'object',
218
+ required: ['Classes'],
219
+ additionalProperties: false,
220
+ properties: { Classes: { oneOf: [
221
+ {
222
+ type: 'object',
223
+ required: [
224
+ 'type',
225
+ 'minItems',
226
+ 'items',
227
+ ],
228
+ additionalProperties: false,
229
+ properties: {
230
+ type: {
231
+ type: 'string',
232
+ const: 'array',
233
+ },
234
+ minItems: {
235
+ type: 'number',
236
+ minimum: 1,
237
+ },
238
+ maxItems: {
239
+ type: 'number',
240
+ minimum: 1,
241
+ },
242
+ items: {
243
+ $ref: '#/$defs/$ref',
244
+ },
245
+ },
246
+ },
247
+ {
248
+ type: 'object',
249
+ required: [
250
+ 'type',
251
+ 'items',
252
+ 'minItems',
253
+ ],
254
+ additionalProperties: false,
255
+ properties: {
256
+ type: {
257
+ type: 'string',
258
+ const: 'array',
259
+ },
260
+ minItems: {
261
+ type: 'number',
262
+ minimum: 1,
263
+ },
264
+ maxItems: {
265
+ type: 'number',
266
+ minimum: 1,
267
+ },
268
+ items: {
269
+ type: 'object',
270
+ required: ['oneOf'],
271
+ additionalProperties: false,
272
+ properties: { oneOf: {
273
+ type: 'array',
274
+ minItems: 1,
275
+ items: {
276
+ $ref: '#/$defs/$ref',
277
+ },
278
+ } },
279
+ },
280
+ },
281
+ },
282
+ {
283
+ type: 'object',
284
+ required: [
285
+ 'type',
286
+ 'items',
287
+ 'minItems',
288
+ ],
289
+ additionalProperties: false,
290
+ properties: {
291
+ type: {
292
+ type: 'string',
293
+ const: 'array',
294
+ },
295
+ minItems: {
296
+ type: 'number',
297
+ minimum: 1,
298
+ },
299
+ items: {
300
+ type: 'object',
301
+ $ref: '#/$defs/$ref_base',
302
+ required: [
303
+ 'type',
304
+ '$ref',
305
+ 'unevaluatedProperties',
306
+ 'properties',
307
+ ],
308
+ unevaluatedProperties: false,
309
+ properties: {
310
+ properties: {
311
+ type: 'object',
312
+ },
313
+ },
314
+ },
315
+ },
316
+ },
317
+ ] } },
318
+ },
319
+ },
320
+ });
321
+ for (const item of schema.prefixItems) {
322
+ if (native_class(item)) {
323
+ result.found_classes.push(item);
324
+ }
325
+ else {
326
+ result.missing_classes.push(item);
327
+ }
328
+ }
329
+ if (result.found_classes.length < 1) {
330
+ throw new Error('No found classes!');
331
+ }
332
+ }
333
+ result.found_types = Object.fromEntries(Object.entries(result.found_types).sort((a, b) => {
334
+ return a[0].localeCompare(b[0]);
335
+ }));
336
+ return result;
337
+ }
338
+ /**
339
+ * @todo move to DocsTsGenerator
340
+ */
341
+ async schema_from_json(discovered_types) {
342
+ const schema = await this.docs.schema();
343
+ if (!is_schema_with_$defs(schema, discovered_types)) {
344
+ throw new Error('Schema $defs not as expected!');
345
+ }
346
+ return schema;
347
+ }
348
+ search(maybe) {
349
+ performance.mark(`${this.constructor.name}.search() start`);
350
+ const generator = this.candidates.find(e => e.check(maybe));
351
+ if (generator) {
352
+ const result = generator.generate()(maybe);
353
+ performance.measure(`${this.constructor.name}.search()`, `${this.constructor.name}.search() start`);
354
+ return result;
355
+ }
356
+ return undefined;
357
+ }
358
+ static custom_parsing_discovery(ajv) {
359
+ return [
360
+ new string_starts_with(ajv),
361
+ new UnrealEngineString(ajv),
362
+ ];
363
+ }
364
+ static standard_jsonschema_discovery(ajv) {
365
+ return [
366
+ new Const(ajv),
367
+ new Pattern(ajv),
368
+ new BooleanEnum(ajv),
369
+ new Enum(ajv),
370
+ new StringType(ajv),
371
+ new NonEmptyString(ajv),
372
+ new NonEmptyStringWithExclusions(ajv),
373
+ ];
374
+ }
375
+ }
376
+ //# sourceMappingURL=TypeDefinitionDiscovery.js.map
@@ -0,0 +1,22 @@
1
+ import { TypeDefinitionDiscovery } from './TypeDefinitionDiscovery';
2
+ import ts, { ClassDeclaration } from 'typescript';
3
+ import { DocsTsGenerator } from './DocsTsGenerator';
4
+ type class_can_have_tree = ClassDeclaration & {
5
+ heritageClauses: [{
6
+ types: [{
7
+ expression: ts.Identifier;
8
+ }];
9
+ }];
10
+ };
11
+ export declare class TypeDefinitionWriter {
12
+ private _discovery;
13
+ private prepared;
14
+ private readonly data_discovery;
15
+ private readonly docs;
16
+ constructor(docs: DocsTsGenerator);
17
+ get discovery(): Promise<TypeDefinitionDiscovery>;
18
+ write(parent_folder: string, cleanup?: boolean): Promise<void>;
19
+ private prepare;
20
+ static can_class_have_tree(class_node: ts.ClassDeclaration): class_node is class_can_have_tree;
21
+ }
22
+ export {};
@@ -0,0 +1,233 @@
1
+ import { TypesDiscovery, } from './TypesDiscovery';
2
+ import { TypeDefinitionDiscovery, } from './TypeDefinitionDiscovery';
3
+ import { mkdir, unlink, writeFile, } from 'node:fs/promises';
4
+ import { ObjectType, } from './TypeDefinitionDiscovery/JsonSchema/ObjectType';
5
+ import { ArrayType, } from './TypeDefinitionDiscovery/JsonSchema/ArrayType';
6
+ import { ExtendsObject, } from './TypeDefinitionDiscovery/JsonSchema/Object/ExtendsObject';
7
+ import { typed_string, } from './TypeDefinitionDiscovery/CustomParsingTypes/typed_string';
8
+ import { oneOf_or_anyOf, } from './TypeDefinitionDiscovery/JsonSchema/oneOf_or_anyOf';
9
+ import { glob, } from 'glob';
10
+ import { object_has_property, value_is_non_array_object, } from './CustomParsingTypes/CustomPairingTypes';
11
+ import ts from 'typescript';
12
+ import { DocsTsAutoImports, } from './DocsTsAutoImports';
13
+ import { dirname, } from 'node:path';
14
+ import { eslint_generated_types, format_code, } from './DocsTsGenerator';
15
+ import { UnrealEngineString as legacy_UnrealEngineString_module, } from './CustomParsingTypes/UnrealEngineString';
16
+ import { string_starts_with, StringPassedRegExp, } from './TypesGeneration/validators';
17
+ import { NoMatchError, } from './Exceptions';
18
+ import { FilesGenerator, FromArray, } from './FilesGenerator';
19
+ import { FilesGenerator as DocsFiles, } from './DocsTsGenerator/FilesGenerator';
20
+ import { require_non_empty_array, } from './ArrayUtilities';
21
+ import { DataDiscovery, } from './DataDiscovery';
22
+ import { __dirname_from_meta, } from './__dirname';
23
+ import { compile, } from './AjvUtilities';
24
+ const __dirname = __dirname_from_meta(import.meta);
25
+ export class TypeDefinitionWriter {
26
+ _discovery = undefined;
27
+ prepared = false;
28
+ data_discovery;
29
+ docs;
30
+ constructor(docs) {
31
+ this.docs = docs;
32
+ this.data_discovery = new DataDiscovery(docs);
33
+ }
34
+ get discovery() {
35
+ if (!this._discovery) {
36
+ const schema = this.docs.schema();
37
+ const type_definition_discover = require_non_empty_array([
38
+ ...TypeDefinitionDiscovery.standard_jsonschema_discovery(this.docs.ajv),
39
+ ...TypeDefinitionDiscovery.custom_parsing_discovery(this.docs.ajv),
40
+ ]);
41
+ this._discovery = Promise.resolve(schema.then((schema) => {
42
+ return new TypeDefinitionDiscovery([
43
+ ...TypesDiscovery.standard_jsonschema_discovery(schema),
44
+ ...TypesDiscovery.custom_parsing_types(schema),
45
+ ], type_definition_discover, this.docs);
46
+ }));
47
+ }
48
+ return this._discovery;
49
+ }
50
+ async write(parent_folder, cleanup = true) {
51
+ performance.mark(`${this.constructor.name}.write() start`);
52
+ await this.prepare();
53
+ performance.measure(`${this.constructor.name}.write() prepare`, `${this.constructor.name}.write() start`);
54
+ performance.mark(`${this.constructor.name}.write() start`);
55
+ const discovery = await this.discovery;
56
+ performance.measure(`${this.constructor.name}.write() discovery`, `${this.constructor.name}.write() start`);
57
+ performance.mark(`${this.constructor.name}.write() start`);
58
+ await writeFile(`${__dirname}/../types-progress.md`, await discovery.generate_markdown());
59
+ await writeFile(`${__dirname}/../data-progress.md`, await this.data_discovery.generate_markdown());
60
+ performance.measure(`${this.constructor.name}.write() generate_markdown`, `${this.constructor.name}.write() start`);
61
+ if (cleanup) {
62
+ performance.mark(`${this.constructor.name}.write() start`);
63
+ for (const remove of await glob(`${parent_folder}/**/*.{ts,js,map}`)) {
64
+ await unlink(remove);
65
+ }
66
+ performance.measure(`${this.constructor.name}.write() cleanup`, `${this.constructor.name}.write() start`);
67
+ }
68
+ performance.mark(`${this.constructor.name}.write() start`);
69
+ const types = await discovery.discover_type_$defs();
70
+ const schema = await this.docs.schema();
71
+ if (types.missing_classes.length > 0
72
+ || types.missing_types.length > 0) {
73
+ throw new NoMatchError({
74
+ found_types: Object.keys(types.found_types),
75
+ missing_types: types.missing_types,
76
+ found_classes: types.found_classes,
77
+ missing_classes: types.missing_classes,
78
+ }, 'Some missing types found!');
79
+ }
80
+ if (!object_has_property(schema, '$defs', value_is_non_array_object)) {
81
+ throw new Error('Schema appears to have no $defs');
82
+ }
83
+ const validations = types.found_classes.map(e => compile(this.docs.ajv, {
84
+ $defs: schema.$defs,
85
+ ...e,
86
+ }));
87
+ if (!object_has_property(schema.$defs, 'NativeClass', value_is_non_array_object)) {
88
+ throw new Error('Could not find NativeClass on provided schema!');
89
+ }
90
+ const files = await FilesGenerator.merge_files([
91
+ discovery,
92
+ new DocsFiles(validations, discovery),
93
+ new FromArray([
94
+ ...legacy_UnrealEngineString_module.CustomGenerators(),
95
+ string_starts_with,
96
+ StringPassedRegExp,
97
+ ]),
98
+ this.data_discovery,
99
+ ]);
100
+ performance.measure(`${this.constructor.name}.write() FilesGenerator`, `${this.constructor.name}.write() start`);
101
+ performance.mark(`${this.constructor.name}.write() start`);
102
+ const auto_imports = new DocsTsAutoImports(files);
103
+ const import_tracker = auto_imports.generate();
104
+ performance.measure(`${this.constructor.name}.write() auto_imports`, `${this.constructor.name}.write() start`);
105
+ await writeFile(`${__dirname}/../imports-come-from.json`, auto_imports.imports_come_from);
106
+ const printer = ts.createPrinter({
107
+ newLine: ts.NewLineKind.LineFeed,
108
+ });
109
+ performance.mark(`${this.constructor.name}.write() start`);
110
+ for (const entry of Object.entries(files)) {
111
+ const result_file = ts.createSourceFile(entry[0], '', ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
112
+ const classes = entry[1].filter(ts.isClassDeclaration);
113
+ const classes_mapped = Object.fromEntries(classes.map((e) => [e.name?.escapedText + '', e]));
114
+ const class_can_have_trees = Object.fromEntries(classes
115
+ .filter(maybe => TypeDefinitionWriter.can_class_have_tree(maybe))
116
+ .map((e) => [e.name?.escapedText + '', e]));
117
+ const class_parents = Object.values(class_can_have_trees).map((class_node) => {
118
+ let checking = class_node;
119
+ const tree = [class_node.name?.escapedText + ''];
120
+ while (checking
121
+ && TypeDefinitionWriter.can_class_have_tree(checking)
122
+ && (checking
123
+ .heritageClauses[0]
124
+ .types[0]
125
+ ?.expression
126
+ .escapedText
127
+ .toString()) in
128
+ class_can_have_trees) {
129
+ const parent_class_name = checking
130
+ .heritageClauses[0]
131
+ .types[0]
132
+ .expression
133
+ .escapedText
134
+ .toString();
135
+ if (parent_class_name in classes_mapped) {
136
+ tree.push(parent_class_name);
137
+ checking = classes_mapped[parent_class_name];
138
+ }
139
+ else {
140
+ checking = undefined;
141
+ }
142
+ }
143
+ return tree;
144
+ });
145
+ const class_parent_classes = class_parents
146
+ .flat()
147
+ .reduce((was, is) => {
148
+ if (!was.includes(is)) {
149
+ was.push(is);
150
+ }
151
+ return was;
152
+ }, []);
153
+ const class_parent_class_max_depth = Object.fromEntries(class_parent_classes
154
+ .map((thing) => {
155
+ const includes = class_parents.filter((e) => e.includes(thing));
156
+ return [thing, includes];
157
+ })
158
+ .filter((entry) => {
159
+ return entry[1].length > 0;
160
+ })
161
+ .map((entry) => {
162
+ return [
163
+ entry[0],
164
+ Math.max(0, ...entry[1].map((e) => e.indexOf(entry[0]))),
165
+ ];
166
+ }));
167
+ const classes_in_order = class_parent_classes.sort((a, b) => {
168
+ return (class_parent_class_max_depth[b] -
169
+ class_parent_class_max_depth[a]);
170
+ });
171
+ const nodes = [
172
+ ...import_tracker.generate_imports(entry[0]),
173
+ ...entry[1].sort((a, b) => {
174
+ if (ts.isTypeAliasDeclaration(a)
175
+ && !ts.isTypeAliasDeclaration(b)) {
176
+ return -1;
177
+ }
178
+ if (ts.isClassDeclaration(a) && ts.isClassDeclaration(b)) {
179
+ return (classes_in_order.indexOf(a.name?.escapedText + '') -
180
+ classes_in_order.indexOf(b.name?.escapedText + ''));
181
+ }
182
+ return 0;
183
+ }),
184
+ ];
185
+ const file_name = `${parent_folder}/${entry[0]}`;
186
+ const dir = dirname(file_name);
187
+ await mkdir(dir, {
188
+ recursive: true,
189
+ });
190
+ const node_strings = [];
191
+ for (const node of nodes) {
192
+ try {
193
+ node_strings.push(printer.printNode(ts.EmitHint.Unspecified, node, result_file));
194
+ }
195
+ catch (err) {
196
+ throw new NoMatchError({
197
+ file_name,
198
+ node,
199
+ err: (err instanceof Error) ? {
200
+ message: err.message,
201
+ stack: err.stack,
202
+ } : err,
203
+ }, 'Error printing node!');
204
+ }
205
+ }
206
+ await writeFile(file_name, await format_code(node_strings
207
+ .join('\n\n')));
208
+ }
209
+ performance.measure(`${this.constructor.name}.write() actually write files`, `${this.constructor.name}.write() start`);
210
+ performance.mark(`${this.constructor.name}.write() start`);
211
+ await writeFile(`${__dirname}/../data-progress.md`, await this.data_discovery.generate_markdown());
212
+ performance.measure(`${this.constructor.name}.write() generate_markdown`, `${this.constructor.name}.write() start`);
213
+ performance.mark(`${this.constructor.name}.write() start`);
214
+ await eslint_generated_types(parent_folder);
215
+ performance.measure(`${this.constructor.name}.write() eslint`, `${this.constructor.name}.write() start`);
216
+ }
217
+ async prepare() {
218
+ if (!this.prepared) {
219
+ this.prepared = true;
220
+ const discovery = await this.discovery;
221
+ const discovered_types = (await discovery.types_discovery.discover_types()).discovered_types;
222
+ discovery.add_candidates(new ObjectType(discovery), new ArrayType(discovered_types, discovery), new ExtendsObject(discovered_types, discovery), new typed_string(discovered_types, discovery), new oneOf_or_anyOf(discovery));
223
+ }
224
+ }
225
+ static can_class_have_tree(class_node) {
226
+ const heritage = [...(class_node.heritageClauses || [])].map((e) => e.types);
227
+ return (1 === heritage.length
228
+ && 1 === heritage[0].length
229
+ && ts.isExpressionWithTypeArguments(heritage[0][0])
230
+ && ts.isIdentifier(heritage[0][0].expression));
231
+ }
232
+ }
233
+ //# sourceMappingURL=TypeDefinitionWriter.js.map
@@ -0,0 +1,10 @@
1
+ import { SchemaObject } from 'ajv/dist/2020';
2
+ export declare abstract class CandidatesDiscovery {
3
+ protected readonly schema: SchemaObject;
4
+ constructor(schema: SchemaObject);
5
+ abstract discovery_candidates(current: unknown, discovered_types: Set<string>): [unknown, ...unknown[]] | undefined;
6
+ }
7
+ export declare abstract class PropertyDependentDiscovery extends CandidatesDiscovery {
8
+ protected readonly property: string;
9
+ constructor(property: string, schema: SchemaObject);
10
+ }
@@ -0,0 +1,14 @@
1
+ export class CandidatesDiscovery {
2
+ schema;
3
+ constructor(schema) {
4
+ this.schema = schema;
5
+ }
6
+ }
7
+ export class PropertyDependentDiscovery extends CandidatesDiscovery {
8
+ property;
9
+ constructor(property, schema) {
10
+ super(schema);
11
+ this.property = property;
12
+ }
13
+ }
14
+ //# sourceMappingURL=CandidatesDiscovery.js.map
@@ -0,0 +1,5 @@
1
+ import { CandidatesDiscovery } from '../CandidatesDiscovery';
2
+ import { SchemaObject } from 'ajv/dist/2020';
3
+ export declare class UnrealEngineString extends CandidatesDiscovery {
4
+ discovery_candidates(current: SchemaObject, discovered_types: Set<string>): [unknown, ...unknown[]] | undefined;
5
+ }