quicktype-core 23.1.2 → 23.1.4
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/dist/ConvenienceRenderer.js +2 -2
- package/dist/DeclarationIR.d.ts +2 -2
- package/dist/GatherNames.d.ts +1 -1
- package/dist/GatherNames.js +2 -2
- package/dist/GraphRewriting.d.ts +4 -2
- package/dist/GraphRewriting.js +25 -26
- package/dist/MakeTransformations.d.ts +1 -1
- package/dist/MakeTransformations.js +2 -2
- package/dist/Renderer.d.ts +1 -1
- package/dist/RendererOptions/types.d.ts +3 -2
- package/dist/Run.d.ts +1 -1
- package/dist/Run.js +8 -6
- package/dist/TargetLanguage.d.ts +3 -3
- package/dist/Transformers.d.ts +2 -1
- package/dist/Transformers.js +8 -8
- package/dist/Type/ProvenanceTypeAttributeKind.d.ts +2 -0
- package/dist/Type/ProvenanceTypeAttributeKind.js +28 -0
- package/dist/Type/TransformedStringType.d.ts +62 -0
- package/dist/Type/TransformedStringType.js +53 -0
- package/dist/{Type.d.ts → Type/Type.d.ts} +6 -63
- package/dist/{Type.js → Type/Type.js} +15 -63
- package/dist/{TypeBuilder.d.ts → Type/TypeBuilder.d.ts} +12 -10
- package/dist/{TypeBuilder.js → Type/TypeBuilder.js} +30 -60
- package/dist/Type/TypeBuilderUtils.d.ts +4 -0
- package/dist/Type/TypeBuilderUtils.js +19 -0
- package/dist/{TypeGraph.d.ts → Type/TypeGraph.d.ts} +6 -15
- package/dist/{TypeGraph.js → Type/TypeGraph.js} +33 -149
- package/dist/Type/TypeGraphUtils.d.ts +5 -0
- package/dist/Type/TypeGraphUtils.js +86 -0
- package/dist/Type/TypeRef.d.ts +12 -0
- package/dist/Type/TypeRef.js +50 -0
- package/dist/{TypeUtils.d.ts → Type/TypeUtils.d.ts} +2 -2
- package/dist/{TypeUtils.js → Type/TypeUtils.js} +5 -5
- package/dist/Type/index.d.ts +5 -0
- package/dist/Type/index.js +22 -0
- package/dist/UnifyClasses.d.ts +3 -3
- package/dist/UnifyClasses.js +5 -5
- package/dist/UnionBuilder.d.ts +2 -2
- package/dist/UnionBuilder.js +1 -1
- package/dist/attributes/AccessorNames.d.ts +1 -1
- package/dist/attributes/Description.js +2 -6
- package/dist/attributes/EnumValues.d.ts +1 -1
- package/dist/attributes/StringTypes.d.ts +2 -2
- package/dist/attributes/StringTypes.js +2 -3
- package/dist/index.d.ts +5 -4
- package/dist/index.js +4 -4
- package/dist/input/Inference.d.ts +2 -2
- package/dist/input/Inference.js +3 -3
- package/dist/input/Inputs.d.ts +1 -1
- package/dist/input/JSONSchemaInput.d.ts +2 -18
- package/dist/input/JSONSchemaInput.js +26 -36
- package/dist/input/PathElement.d.ts +17 -0
- package/dist/input/PathElement.js +10 -0
- package/dist/language/CJSON/CJSONRenderer.js +1 -1
- package/dist/language/CPlusPlus/CPlusPlusRenderer.js +1 -1
- package/dist/language/CSharp/CSharpRenderer.js +1 -1
- package/dist/language/CSharp/NewtonSoftCSharpRenderer.js +1 -1
- package/dist/language/CSharp/SystemTextJsonCSharpRenderer.js +1 -1
- package/dist/language/CSharp/language.d.ts +1 -1
- package/dist/language/CSharp/utils.js +1 -1
- package/dist/language/Crystal/CrystalRenderer.js +1 -1
- package/dist/language/Dart/DartRenderer.js +1 -1
- package/dist/language/Dart/language.d.ts +1 -1
- package/dist/language/Elixir/ElixirRenderer.js +1 -1
- package/dist/language/Elm/ElmRenderer.js +1 -1
- package/dist/language/Elm/utils.js +1 -1
- package/dist/language/Golang/GolangRenderer.js +1 -1
- package/dist/language/Golang/language.d.ts +1 -1
- package/dist/language/Haskell/HaskellRenderer.js +1 -1
- package/dist/language/JSONSchema/JSONSchemaRenderer.js +1 -1
- package/dist/language/JSONSchema/language.d.ts +1 -1
- package/dist/language/JSONSchema/language.js +2 -2
- package/dist/language/Java/JavaJacksonRenderer.js +1 -1
- package/dist/language/Java/JavaRenderer.js +1 -1
- package/dist/language/Java/language.d.ts +1 -1
- package/dist/language/JavaScript/JavaScriptRenderer.js +1 -1
- package/dist/language/JavaScript/language.d.ts +1 -1
- package/dist/language/JavaScriptPropTypes/JavaScriptPropTypesRenderer.js +1 -1
- package/dist/language/Kotlin/KotlinJacksonRenderer.js +1 -1
- package/dist/language/Kotlin/KotlinKlaxonRenderer.js +1 -1
- package/dist/language/Kotlin/KotlinRenderer.js +1 -1
- package/dist/language/Objective-C/ObjectiveCRenderer.js +1 -1
- package/dist/language/Php/PhpRenderer.js +1 -1
- package/dist/language/Php/language.d.ts +1 -1
- package/dist/language/Pike/PikeRenderer.js +1 -1
- package/dist/language/Python/JSONPythonRenderer.js +1 -1
- package/dist/language/Python/PythonRenderer.js +1 -1
- package/dist/language/Python/language.d.ts +1 -1
- package/dist/language/Ruby/RubyRenderer.js +1 -1
- package/dist/language/Rust/RustRenderer.js +1 -1
- package/dist/language/Scala3/CirceRenderer.js +1 -1
- package/dist/language/Scala3/Scala3Renderer.js +1 -1
- package/dist/language/Smithy4s/Smithy4sRenderer.js +1 -1
- package/dist/language/Swift/SwiftRenderer.js +1 -1
- package/dist/language/Swift/language.d.ts +1 -1
- package/dist/language/TypeScriptEffectSchema/TypeScriptEffectSchemaRenderer.js +1 -1
- package/dist/language/TypeScriptFlow/TypeScriptFlowBaseRenderer.js +1 -1
- package/dist/language/TypeScriptFlow/TypeScriptRenderer.js +1 -1
- package/dist/language/TypeScriptFlow/language.d.ts +1 -1
- package/dist/language/TypeScriptZod/TypeScriptZodRenderer.js +1 -1
- package/dist/language/TypeScriptZod/language.d.ts +1 -1
- package/dist/rewrites/CombineClasses.d.ts +1 -1
- package/dist/rewrites/CombineClasses.js +2 -2
- package/dist/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/rewrites/ExpandStrings.js +1 -1
- package/dist/rewrites/FlattenStrings.d.ts +2 -2
- package/dist/rewrites/FlattenStrings.js +1 -1
- package/dist/rewrites/FlattenUnions.d.ts +2 -2
- package/dist/rewrites/FlattenUnions.js +4 -4
- package/dist/rewrites/InferMaps.d.ts +2 -2
- package/dist/rewrites/InferMaps.js +1 -1
- package/dist/rewrites/ReplaceObjectType.d.ts +2 -2
- package/dist/rewrites/ResolveIntersections.d.ts +2 -2
- package/dist/rewrites/ResolveIntersections.js +1 -1
- package/package.json +1 -1
|
@@ -18,8 +18,8 @@ const Strings_1 = require("./support/Strings");
|
|
|
18
18
|
const Support_1 = require("./support/Support");
|
|
19
19
|
const Transformers_1 = require("./Transformers");
|
|
20
20
|
const Type_1 = require("./Type");
|
|
21
|
-
const TypeGraph_1 = require("./TypeGraph");
|
|
22
|
-
const TypeUtils_1 = require("./TypeUtils");
|
|
21
|
+
const TypeGraph_1 = require("./Type/TypeGraph");
|
|
22
|
+
const TypeUtils_1 = require("./Type/TypeUtils");
|
|
23
23
|
const wordWrap = (0, wordwrap_1.default)(90);
|
|
24
24
|
exports.topLevelNameOrder = 1;
|
|
25
25
|
const givenNameOrder = 10;
|
package/dist/DeclarationIR.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Type } from "./Type";
|
|
2
|
-
import { type TypeGraph } from "./TypeGraph";
|
|
1
|
+
import { type Type } from "./Type/Type";
|
|
2
|
+
import { type TypeGraph } from "./Type/TypeGraph";
|
|
3
3
|
export type DeclarationKind = "forward" | "define";
|
|
4
4
|
export interface Declaration {
|
|
5
5
|
readonly kind: DeclarationKind;
|
package/dist/GatherNames.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type TypeGraph } from "./TypeGraph";
|
|
1
|
+
import { type TypeGraph } from "./Type/TypeGraph";
|
|
2
2
|
export declare function gatherNames(graph: TypeGraph, destructive: boolean, debugPrint: boolean): void;
|
package/dist/GatherNames.js
CHANGED
|
@@ -29,8 +29,8 @@ const pluralize = __importStar(require("pluralize"));
|
|
|
29
29
|
const TypeNames_1 = require("./attributes/TypeNames");
|
|
30
30
|
const Support_1 = require("./support/Support");
|
|
31
31
|
const Transformers_1 = require("./Transformers");
|
|
32
|
-
const Type_1 = require("./Type");
|
|
33
|
-
const TypeUtils_1 = require("./TypeUtils");
|
|
32
|
+
const Type_1 = require("./Type/Type");
|
|
33
|
+
const TypeUtils_1 = require("./Type/TypeUtils");
|
|
34
34
|
class UniqueQueue {
|
|
35
35
|
constructor() {
|
|
36
36
|
this._present = new Set();
|
package/dist/GraphRewriting.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type TypeAttributes } from "./attributes/TypeAttributes";
|
|
2
2
|
import { type ClassProperty, type MaybeTypeIdentity, type PrimitiveTypeKind, type Type } from "./Type";
|
|
3
|
-
import {
|
|
4
|
-
import { type
|
|
3
|
+
import { TypeBuilder } from "./Type/TypeBuilder";
|
|
4
|
+
import { type StringTypeMapping } from "./Type/TypeBuilderUtils";
|
|
5
|
+
import { type TypeGraph } from "./Type/TypeGraph";
|
|
6
|
+
import { type TypeRef } from "./Type/TypeRef";
|
|
5
7
|
export interface TypeLookerUp {
|
|
6
8
|
lookupTypeRefs: (typeRefs: TypeRef[], forwardingRef?: TypeRef) => TypeRef | undefined;
|
|
7
9
|
reconstituteTypeRef: (typeRef: TypeRef, attributes?: TypeAttributes, forwardingRef?: TypeRef) => TypeRef;
|
package/dist/GraphRewriting.js
CHANGED
|
@@ -4,10 +4,9 @@ exports.GraphRewriteBuilder = exports.GraphRemapBuilder = exports.BaseGraphRewri
|
|
|
4
4
|
const collection_utils_1 = require("collection-utils");
|
|
5
5
|
const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
6
6
|
const Support_1 = require("./support/Support");
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const TypeUtils_1 = require("./TypeUtils");
|
|
7
|
+
const TypeBuilder_1 = require("./Type/TypeBuilder");
|
|
8
|
+
const TypeRef_1 = require("./Type/TypeRef");
|
|
9
|
+
const TypeUtils_1 = require("./Type/TypeUtils");
|
|
11
10
|
class TypeReconstituter {
|
|
12
11
|
constructor(_typeBuilder, _makeClassUnique, _typeAttributes, _forwardingRef, _register) {
|
|
13
12
|
this._typeBuilder = _typeBuilder;
|
|
@@ -45,7 +44,7 @@ class TypeReconstituter {
|
|
|
45
44
|
}
|
|
46
45
|
lookup(trefs) {
|
|
47
46
|
(0, Support_1.assert)(!this._wasUsed, "Cannot lookup constituents after building type");
|
|
48
|
-
if ((0,
|
|
47
|
+
if ((0, TypeRef_1.isTypeRef)(trefs)) {
|
|
49
48
|
return this._typeBuilder.lookupTypeRefs([trefs], undefined, false);
|
|
50
49
|
}
|
|
51
50
|
else {
|
|
@@ -70,7 +69,7 @@ class TypeReconstituter {
|
|
|
70
69
|
}
|
|
71
70
|
reconstitute(trefs) {
|
|
72
71
|
(0, Support_1.assert)(this._wasUsed, "Cannot reconstitute constituents before building type");
|
|
73
|
-
if ((0,
|
|
72
|
+
if ((0, TypeRef_1.isTypeRef)(trefs)) {
|
|
74
73
|
return this._typeBuilder.reconstituteTypeRef(trefs);
|
|
75
74
|
}
|
|
76
75
|
else {
|
|
@@ -142,7 +141,7 @@ class TypeReconstituter {
|
|
|
142
141
|
exports.TypeReconstituter = TypeReconstituter;
|
|
143
142
|
class BaseGraphRewriteBuilder extends TypeBuilder_1.TypeBuilder {
|
|
144
143
|
constructor(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, debugPrint) {
|
|
145
|
-
super(
|
|
144
|
+
super(stringTypeMapping, alphabetizeProperties, false, false, graphHasProvenanceAttributes);
|
|
146
145
|
this.originalGraph = originalGraph;
|
|
147
146
|
this.debugPrint = debugPrint;
|
|
148
147
|
this.reconstitutedTypes = new Map();
|
|
@@ -177,10 +176,10 @@ class BaseGraphRewriteBuilder extends TypeBuilder_1.TypeBuilder {
|
|
|
177
176
|
assertTypeRefsToReconstitute(typeRefs, forwardingRef) {
|
|
178
177
|
(0, Support_1.assert)(typeRefs.length > 0, "Must have at least one type to reconstitute");
|
|
179
178
|
for (const originalRef of typeRefs) {
|
|
180
|
-
(0,
|
|
179
|
+
(0, TypeRef_1.assertTypeRefGraph)(originalRef, this.originalGraph);
|
|
181
180
|
}
|
|
182
181
|
if (forwardingRef !== undefined) {
|
|
183
|
-
(0,
|
|
182
|
+
(0, TypeRef_1.assertTypeRefGraph)(forwardingRef, this.typeGraph);
|
|
184
183
|
}
|
|
185
184
|
}
|
|
186
185
|
changeDebugPrintIndent(delta) {
|
|
@@ -221,7 +220,7 @@ class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
|
221
220
|
return undefined;
|
|
222
221
|
}
|
|
223
222
|
getMapTarget(tref) {
|
|
224
|
-
const maybeType = this._map.get((0,
|
|
223
|
+
const maybeType = this._map.get((0, TypeRef_1.derefTypeRef)(tref, this.originalGraph));
|
|
225
224
|
if (maybeType === undefined)
|
|
226
225
|
return tref;
|
|
227
226
|
(0, Support_1.assert)(this._map.get(maybeType) === undefined, "We have a type that's remapped to a remapped type");
|
|
@@ -233,11 +232,11 @@ class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
|
233
232
|
lookupTypeRefs(typeRefs, forwardingRef) {
|
|
234
233
|
(0, Support_1.assert)(forwardingRef === undefined, "We can't have a forwarding ref when we remap");
|
|
235
234
|
this.assertTypeRefsToReconstitute(typeRefs, forwardingRef);
|
|
236
|
-
const first = this.reconstitutedTypes.get((0,
|
|
235
|
+
const first = this.reconstitutedTypes.get((0, TypeRef_1.typeRefIndex)(this.getMapTarget(typeRefs[0])));
|
|
237
236
|
if (first === undefined)
|
|
238
237
|
return undefined;
|
|
239
238
|
for (let i = 1; i < typeRefs.length; i++) {
|
|
240
|
-
const other = this.reconstitutedTypes.get((0,
|
|
239
|
+
const other = this.reconstitutedTypes.get((0, TypeRef_1.typeRefIndex)(this.getMapTarget(typeRefs[i])));
|
|
241
240
|
if (first !== other)
|
|
242
241
|
return undefined;
|
|
243
242
|
}
|
|
@@ -245,16 +244,16 @@ class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
|
245
244
|
}
|
|
246
245
|
forceReconstituteTypeRef(originalRef, attributes, maybeForwardingRef) {
|
|
247
246
|
originalRef = this.getMapTarget(originalRef);
|
|
248
|
-
const index = (0,
|
|
247
|
+
const index = (0, TypeRef_1.typeRefIndex)(originalRef);
|
|
249
248
|
(0, Support_1.assert)(this.reconstitutedTypes.get(index) === undefined, "Type has already been reconstituted");
|
|
250
249
|
(0, Support_1.assert)(maybeForwardingRef === undefined, "We can't have a forwarding ref when we remap");
|
|
251
250
|
return this.withForwardingRef(undefined, forwardingRef => {
|
|
252
251
|
this.reconstitutedTypes.set(index, forwardingRef);
|
|
253
252
|
if (this.debugPrint) {
|
|
254
|
-
console.log(`${this.debugPrintIndentation}reconstituting ${index} as ${(0,
|
|
253
|
+
console.log(`${this.debugPrintIndentation}reconstituting ${index} as ${(0, TypeRef_1.typeRefIndex)(forwardingRef)}`);
|
|
255
254
|
this.changeDebugPrintIndent(1);
|
|
256
255
|
}
|
|
257
|
-
const [originalType, originalAttributes] = (0,
|
|
256
|
+
const [originalType, originalAttributes] = (0, TypeRef_1.typeAndAttributesForTypeRef)(originalRef, this.originalGraph);
|
|
258
257
|
const attributeSources = this._attributeSources.get(originalType);
|
|
259
258
|
if (attributes === undefined) {
|
|
260
259
|
attributes = TypeAttributes_1.emptyTypeAttributes;
|
|
@@ -270,7 +269,7 @@ class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
|
270
269
|
(0, Support_1.assert)(tref === forwardingRef, "Reconstituted type as a different ref");
|
|
271
270
|
if (this.debugPrint) {
|
|
272
271
|
this.changeDebugPrintIndent(-1);
|
|
273
|
-
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${(0,
|
|
272
|
+
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${(0, TypeRef_1.typeRefIndex)(tref)}`);
|
|
274
273
|
}
|
|
275
274
|
});
|
|
276
275
|
originalType.reconstitute(reconstituter, this.canonicalOrder);
|
|
@@ -304,12 +303,12 @@ class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
|
304
303
|
if (this.debugPrint) {
|
|
305
304
|
console.log(`${this.debugPrintIndentation}replacing set ${Array.from(typesToReplace)
|
|
306
305
|
.map(t => t.index.toString())
|
|
307
|
-
.join(",")} as ${(0,
|
|
306
|
+
.join(",")} as ${(0, TypeRef_1.typeRefIndex)(forwardingRef)}`);
|
|
308
307
|
this.changeDebugPrintIndent(1);
|
|
309
308
|
}
|
|
310
309
|
for (const t of typesToReplace) {
|
|
311
310
|
const originalRef = t.typeRef;
|
|
312
|
-
const index = (0,
|
|
311
|
+
const index = (0, TypeRef_1.typeRefIndex)(originalRef);
|
|
313
312
|
this.reconstitutedTypes.set(index, forwardingRef);
|
|
314
313
|
this._setsToReplaceByMember.delete(index);
|
|
315
314
|
}
|
|
@@ -319,14 +318,14 @@ class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
|
319
318
|
this.changeDebugPrintIndent(-1);
|
|
320
319
|
console.log(`${this.debugPrintIndentation}replaced set ${Array.from(typesToReplace)
|
|
321
320
|
.map(t => t.index.toString())
|
|
322
|
-
.join(",")} as ${(0,
|
|
321
|
+
.join(",")} as ${(0, TypeRef_1.typeRefIndex)(forwardingRef)}`);
|
|
323
322
|
}
|
|
324
323
|
return result;
|
|
325
324
|
});
|
|
326
325
|
}
|
|
327
326
|
forceReconstituteTypeRef(originalRef, attributes, maybeForwardingRef) {
|
|
328
|
-
const [originalType, originalAttributes] = (0,
|
|
329
|
-
const index = (0,
|
|
327
|
+
const [originalType, originalAttributes] = (0, TypeRef_1.typeAndAttributesForTypeRef)(originalRef, this.originalGraph);
|
|
328
|
+
const index = (0, TypeRef_1.typeRefIndex)(originalRef);
|
|
330
329
|
if (this.debugPrint) {
|
|
331
330
|
console.log(`${this.debugPrintIndentation}reconstituting ${index}`);
|
|
332
331
|
this.changeDebugPrintIndent(1);
|
|
@@ -340,7 +339,7 @@ class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
|
340
339
|
const reconstituter = new TypeReconstituter(this, this.canonicalOrder, attributes, maybeForwardingRef, tref => {
|
|
341
340
|
if (this.debugPrint) {
|
|
342
341
|
this.changeDebugPrintIndent(-1);
|
|
343
|
-
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${(0,
|
|
342
|
+
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${(0, TypeRef_1.typeRefIndex)(tref)}`);
|
|
344
343
|
}
|
|
345
344
|
if (maybeForwardingRef !== undefined) {
|
|
346
345
|
(0, Support_1.assert)(tref === maybeForwardingRef, "We didn't pass the forwarding ref");
|
|
@@ -375,11 +374,11 @@ class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
|
375
374
|
this.assertTypeRefsToReconstitute(typeRefs, forwardingRef);
|
|
376
375
|
// Check whether we have already reconstituted them. That means ensuring
|
|
377
376
|
// that they all have the same target type.
|
|
378
|
-
let maybeRef = this.reconstitutedTypes.get((0,
|
|
377
|
+
let maybeRef = this.reconstitutedTypes.get((0, TypeRef_1.typeRefIndex)(typeRefs[0]));
|
|
379
378
|
if (maybeRef !== undefined && maybeRef !== forwardingRef) {
|
|
380
379
|
let allEqual = true;
|
|
381
380
|
for (let i = 1; i < typeRefs.length; i++) {
|
|
382
|
-
if (this.reconstitutedTypes.get((0,
|
|
381
|
+
if (this.reconstitutedTypes.get((0, TypeRef_1.typeRefIndex)(typeRefs[i])) !== maybeRef) {
|
|
383
382
|
allEqual = false;
|
|
384
383
|
break;
|
|
385
384
|
}
|
|
@@ -394,12 +393,12 @@ class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
|
394
393
|
return this.forwardIfNecessary(forwardingRef, maybeRef);
|
|
395
394
|
}
|
|
396
395
|
// Is this set requested to be replaced? If not, we're out of options.
|
|
397
|
-
const maybeSet = this._setsToReplaceByMember.get((0,
|
|
396
|
+
const maybeSet = this._setsToReplaceByMember.get((0, TypeRef_1.typeRefIndex)(typeRefs[0]));
|
|
398
397
|
if (maybeSet === undefined) {
|
|
399
398
|
return undefined;
|
|
400
399
|
}
|
|
401
400
|
for (let i = 1; i < typeRefs.length; i++) {
|
|
402
|
-
if (this._setsToReplaceByMember.get((0,
|
|
401
|
+
if (this._setsToReplaceByMember.get((0, TypeRef_1.typeRefIndex)(typeRefs[i])) !== maybeSet) {
|
|
403
402
|
return undefined;
|
|
404
403
|
}
|
|
405
404
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type RunContext } from "./Run";
|
|
2
2
|
import { type TargetLanguage } from "./TargetLanguage";
|
|
3
|
-
import { type TypeGraph } from "./TypeGraph";
|
|
3
|
+
import { type TypeGraph } from "./Type/TypeGraph";
|
|
4
4
|
export declare function makeTransformations(ctx: RunContext, graph: TypeGraph, targetLanguage: TargetLanguage): TypeGraph;
|
|
@@ -8,11 +8,11 @@ const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
|
8
8
|
const Support_1 = require("./support/Support");
|
|
9
9
|
const Transformers_1 = require("./Transformers");
|
|
10
10
|
const Type_1 = require("./Type");
|
|
11
|
-
const
|
|
11
|
+
const TypeRef_1 = require("./Type/TypeRef");
|
|
12
12
|
function transformationAttributes(graph, reconstitutedTargetType, transformer, debugPrintTransformations) {
|
|
13
13
|
const transformation = new Transformers_1.Transformation(graph, reconstitutedTargetType, transformer);
|
|
14
14
|
if (debugPrintTransformations) {
|
|
15
|
-
console.log(`transformation for ${(0,
|
|
15
|
+
console.log(`transformation for ${(0, TypeRef_1.typeRefIndex)(reconstitutedTargetType)}:`);
|
|
16
16
|
transformation.debugPrint();
|
|
17
17
|
console.log("reverse:");
|
|
18
18
|
transformation.reverse.debugPrint();
|
package/dist/Renderer.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type Name, type Namespace } from "./Naming";
|
|
|
3
3
|
import { type Source, type Sourcelike } from "./Source";
|
|
4
4
|
import { type Comment } from "./support/Comments";
|
|
5
5
|
import { type TargetLanguage } from "./TargetLanguage";
|
|
6
|
-
import { type TypeGraph } from "./TypeGraph";
|
|
6
|
+
import { type TypeGraph } from "./Type/TypeGraph";
|
|
7
7
|
export interface RenderResult {
|
|
8
8
|
names: ReadonlyMap<Name, string>;
|
|
9
9
|
sources: ReadonlyMap<string, Source>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { EnumOption, Option } from "./index";
|
|
2
2
|
/**
|
|
3
3
|
* Primary options show up in the web UI in the "Language" settings tab,
|
|
4
|
-
*
|
|
4
|
+
* Secondary options in "Other".
|
|
5
|
+
* CLI is only for cli
|
|
5
6
|
*/
|
|
6
|
-
export type OptionKind = "primary" | "secondary";
|
|
7
|
+
export type OptionKind = "primary" | "secondary" | "cli";
|
|
7
8
|
export interface OptionDefinition<Name extends string = string, T = unknown> {
|
|
8
9
|
alias?: string;
|
|
9
10
|
defaultOption?: boolean;
|
package/dist/Run.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type SerializedRenderResult } from "./Source";
|
|
|
5
5
|
import { type Comment } from "./support/Comments";
|
|
6
6
|
import { type MultiFileRenderResult, type TargetLanguage } from "./TargetLanguage";
|
|
7
7
|
import { type TransformedStringTypeKind } from "./Type";
|
|
8
|
-
import { type StringTypeMapping } from "./
|
|
8
|
+
import { type StringTypeMapping } from "./Type/TypeBuilderUtils";
|
|
9
9
|
export declare function getTargetLanguage(nameOrInstance: LanguageName | TargetLanguage): TargetLanguage;
|
|
10
10
|
export interface InferenceFlag {
|
|
11
11
|
description: string;
|
package/dist/Run.js
CHANGED
|
@@ -48,8 +48,9 @@ const InferMaps_1 = require("./rewrites/InferMaps");
|
|
|
48
48
|
const ReplaceObjectType_1 = require("./rewrites/ReplaceObjectType");
|
|
49
49
|
const ResolveIntersections_1 = require("./rewrites/ResolveIntersections");
|
|
50
50
|
const Support_1 = require("./support/Support");
|
|
51
|
-
const TypeBuilder_1 = require("./TypeBuilder");
|
|
52
|
-
const TypeGraph_1 = require("./TypeGraph");
|
|
51
|
+
const TypeBuilder_1 = require("./Type/TypeBuilder");
|
|
52
|
+
const TypeGraph_1 = require("./Type/TypeGraph");
|
|
53
|
+
const TypeGraphUtils_1 = require("./Type/TypeGraphUtils");
|
|
53
54
|
function getTargetLanguage(nameOrInstance) {
|
|
54
55
|
if (typeof nameOrInstance === "object") {
|
|
55
56
|
return nameOrInstance;
|
|
@@ -208,7 +209,8 @@ class Run {
|
|
|
208
209
|
const targetLanguage = getTargetLanguage(this._options.lang);
|
|
209
210
|
const stringTypeMapping = this.stringTypeMapping;
|
|
210
211
|
const conflateNumbers = !targetLanguage.supportsUnionsWithBothNumberTypes;
|
|
211
|
-
const typeBuilder = new TypeBuilder_1.TypeBuilder(
|
|
212
|
+
const typeBuilder = new TypeBuilder_1.TypeBuilder(stringTypeMapping, this._options.alphabetizeProperties, this._options.allPropertiesOptional, this._options.checkProvenance, false);
|
|
213
|
+
typeBuilder.typeGraph = new TypeGraph_1.TypeGraph(typeBuilder, 0, this._options.checkProvenance);
|
|
212
214
|
return { targetLanguage, stringTypeMapping, conflateNumbers, typeBuilder };
|
|
213
215
|
}
|
|
214
216
|
makeGraph(allInputs) {
|
|
@@ -234,7 +236,7 @@ class Run {
|
|
|
234
236
|
}
|
|
235
237
|
const debugPrintReconstitution = this.debugPrintReconstitution;
|
|
236
238
|
if (typeBuilder.didAddForwardingIntersection || !this._options.ignoreJsonRefs) {
|
|
237
|
-
this.time("remove indirection intersections", () => (graph = (0,
|
|
239
|
+
this.time("remove indirection intersections", () => (graph = (0, TypeGraphUtils_1.removeIndirectionIntersections)(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
238
240
|
}
|
|
239
241
|
let unionsDone = false;
|
|
240
242
|
if (allInputs.needSchemaProcessing || !this._options.ignoreJsonRefs) {
|
|
@@ -281,9 +283,9 @@ class Run {
|
|
|
281
283
|
if (allInputs.needSchemaProcessing) {
|
|
282
284
|
this.time("flatten strings", () => (graph = (0, FlattenStrings_1.flattenStrings)(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
283
285
|
}
|
|
284
|
-
this.time("none to any", () => (graph = (0,
|
|
286
|
+
this.time("none to any", () => (graph = (0, TypeGraphUtils_1.noneToAny)(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
285
287
|
if (!targetLanguage.supportsOptionalClassProperties) {
|
|
286
|
-
this.time("optional to nullable", () => (graph = (0,
|
|
288
|
+
this.time("optional to nullable", () => (graph = (0, TypeGraphUtils_1.optionalToNullable)(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
287
289
|
}
|
|
288
290
|
this.time("fixed point", () => (graph = graph.rewriteFixedPoint(false, debugPrintReconstitution)));
|
|
289
291
|
this.time("make transformations", () => (graph = (0, MakeTransformations_1.makeTransformations)(this, graph, targetLanguage)));
|
package/dist/TargetLanguage.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { type RenderContext, type Renderer } from "./Renderer";
|
|
|
3
3
|
import { type Option, type OptionDefinition } from "./RendererOptions";
|
|
4
4
|
import { type SerializedRenderResult } from "./Source";
|
|
5
5
|
import { type Comment } from "./support/Comments";
|
|
6
|
-
import { type Type } from "./Type";
|
|
7
|
-
import { type StringTypeMapping } from "./
|
|
8
|
-
import { type TypeGraph } from "./TypeGraph";
|
|
6
|
+
import { type Type } from "./Type/Type";
|
|
7
|
+
import { type StringTypeMapping } from "./Type/TypeBuilderUtils";
|
|
8
|
+
import { type TypeGraph } from "./Type/TypeGraph";
|
|
9
9
|
import { type FixMeOptionsType } from "./types";
|
|
10
10
|
export type MultiFileRenderResult = ReadonlyMap<string, SerializedRenderResult>;
|
|
11
11
|
export interface LanguageConfig {
|
package/dist/Transformers.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { TypeAttributeKind } from "./attributes/TypeAttributes";
|
|
2
2
|
import { type BaseGraphRewriteBuilder } from "./GraphRewriting";
|
|
3
3
|
import { EnumType, PrimitiveType, type Type, UnionType } from "./Type";
|
|
4
|
-
import { type TypeGraph
|
|
4
|
+
import { type TypeGraph } from "./Type/TypeGraph";
|
|
5
|
+
import { type TypeRef } from "./Type/TypeRef";
|
|
5
6
|
export declare abstract class Transformer {
|
|
6
7
|
readonly kind: string;
|
|
7
8
|
protected readonly graph: TypeGraph;
|
package/dist/Transformers.js
CHANGED
|
@@ -5,7 +5,7 @@ const collection_utils_1 = require("collection-utils");
|
|
|
5
5
|
const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
6
6
|
const Support_1 = require("./support/Support");
|
|
7
7
|
const Type_1 = require("./Type");
|
|
8
|
-
const
|
|
8
|
+
const TypeRef_1 = require("./Type/TypeRef");
|
|
9
9
|
function debugStringForType(t) {
|
|
10
10
|
const target = followTargetType(t);
|
|
11
11
|
if (t === target) {
|
|
@@ -23,7 +23,7 @@ class Transformer {
|
|
|
23
23
|
this.sourceTypeRef = sourceTypeRef;
|
|
24
24
|
}
|
|
25
25
|
get sourceType() {
|
|
26
|
-
return (0,
|
|
26
|
+
return (0, TypeRef_1.derefTypeRef)(this.sourceTypeRef, this.graph);
|
|
27
27
|
}
|
|
28
28
|
/** This must return a newly constructed set. */
|
|
29
29
|
getChildren() {
|
|
@@ -177,7 +177,7 @@ class ArrayDecodingTransformer extends ProducerTransformer {
|
|
|
177
177
|
return false;
|
|
178
178
|
}
|
|
179
179
|
get itemTargetType() {
|
|
180
|
-
return (0,
|
|
180
|
+
return (0, TypeRef_1.derefTypeRef)(this._itemTargetTypeRef, this.graph);
|
|
181
181
|
}
|
|
182
182
|
reverse(targetTypeRef, continuationTransformer) {
|
|
183
183
|
if (continuationTransformer !== undefined) {
|
|
@@ -233,7 +233,7 @@ class ArrayEncodingTransformer extends Transformer {
|
|
|
233
233
|
return false;
|
|
234
234
|
}
|
|
235
235
|
get itemTargetType() {
|
|
236
|
-
return (0,
|
|
236
|
+
return (0, TypeRef_1.derefTypeRef)(this._itemTargetTypeRef, this.graph);
|
|
237
237
|
}
|
|
238
238
|
reverse(_targetTypeRef, _continuationTransformer) {
|
|
239
239
|
return (0, Support_1.panic)("Can't reverse array encoding transformer");
|
|
@@ -487,7 +487,7 @@ class UnionMemberMatchTransformer extends MatchTransformer {
|
|
|
487
487
|
this.memberTypeRef = memberTypeRef;
|
|
488
488
|
}
|
|
489
489
|
get sourceType() {
|
|
490
|
-
const t = (0,
|
|
490
|
+
const t = (0, TypeRef_1.derefTypeRef)(this.sourceTypeRef, this.graph);
|
|
491
491
|
if (!(t instanceof Type_1.UnionType)) {
|
|
492
492
|
return (0, Support_1.panic)("The source of a union member match transformer must be a union type");
|
|
493
493
|
}
|
|
@@ -497,7 +497,7 @@ class UnionMemberMatchTransformer extends MatchTransformer {
|
|
|
497
497
|
return true;
|
|
498
498
|
}
|
|
499
499
|
get memberType() {
|
|
500
|
-
return (0,
|
|
500
|
+
return (0, TypeRef_1.derefTypeRef)(this.memberTypeRef, this.graph);
|
|
501
501
|
}
|
|
502
502
|
getChildren() {
|
|
503
503
|
return super.getChildren().add(this.memberType);
|
|
@@ -533,7 +533,7 @@ class StringMatchTransformer extends MatchTransformer {
|
|
|
533
533
|
this.stringCase = stringCase;
|
|
534
534
|
}
|
|
535
535
|
get sourceType() {
|
|
536
|
-
const t = (0,
|
|
536
|
+
const t = (0, TypeRef_1.derefTypeRef)(this.sourceTypeRef, this.graph);
|
|
537
537
|
if (!(t instanceof Type_1.EnumType) && !(t instanceof Type_1.PrimitiveType && t.kind === "string")) {
|
|
538
538
|
return (0, Support_1.panic)("The source of a string match transformer must be an enum or string type");
|
|
539
539
|
}
|
|
@@ -744,7 +744,7 @@ class Transformation {
|
|
|
744
744
|
return this.transformer.sourceType;
|
|
745
745
|
}
|
|
746
746
|
get targetType() {
|
|
747
|
-
return (0,
|
|
747
|
+
return (0, TypeRef_1.derefTypeRef)(this._targetTypeRef, this._graph);
|
|
748
748
|
}
|
|
749
749
|
get reverse() {
|
|
750
750
|
return new Transformation(this._graph, this.transformer.sourceTypeRef, this.transformer.reverse(this._targetTypeRef, undefined));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.provenanceTypeAttributeKind = void 0;
|
|
4
|
+
const collection_utils_1 = require("collection-utils");
|
|
5
|
+
const TypeAttributes_1 = require("../attributes/TypeAttributes");
|
|
6
|
+
// FIXME: Don't infer provenance. All original types should be present in
|
|
7
|
+
// non-inferred form in the final graph.
|
|
8
|
+
class ProvenanceTypeAttributeKind extends TypeAttributes_1.TypeAttributeKind {
|
|
9
|
+
constructor() {
|
|
10
|
+
super("provenance");
|
|
11
|
+
}
|
|
12
|
+
appliesToTypeKind(_kind) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
combine(arr) {
|
|
16
|
+
return (0, collection_utils_1.setUnionManyInto)(new Set(), arr);
|
|
17
|
+
}
|
|
18
|
+
makeInferred(p) {
|
|
19
|
+
return p;
|
|
20
|
+
}
|
|
21
|
+
stringify(p) {
|
|
22
|
+
return Array.from(p)
|
|
23
|
+
.sort()
|
|
24
|
+
.map(i => i.toString())
|
|
25
|
+
.join(",");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.provenanceTypeAttributeKind = new ProvenanceTypeAttributeKind();
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type TypeAttributes } from "../attributes/TypeAttributes";
|
|
2
|
+
import { uriInferenceAttributesProducer } from "../attributes/URIAttributes";
|
|
3
|
+
import { type Type } from "./Type";
|
|
4
|
+
/**
|
|
5
|
+
* `jsonSchema` is the `format` to be used to represent this string type in
|
|
6
|
+
* JSON Schema. It's ok to "invent" a new one if the JSON Schema standard doesn't
|
|
7
|
+
* have that particular type yet.
|
|
8
|
+
*
|
|
9
|
+
* For transformed type kinds that map to an existing primitive type, `primitive`
|
|
10
|
+
* must specify that type kind.
|
|
11
|
+
*/
|
|
12
|
+
export interface TransformedStringTypeTargets {
|
|
13
|
+
attributesProducer?: (s: string) => TypeAttributes;
|
|
14
|
+
jsonSchema: string;
|
|
15
|
+
primitive: PrimitiveNonStringTypeKind | undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* All the transformed string type kinds and the JSON Schema formats and
|
|
19
|
+
* primitive type kinds they map to. Not all transformed string types map to
|
|
20
|
+
* primitive types. Date-time types, for example, stand on their own, but
|
|
21
|
+
* stringified integers map to integers.
|
|
22
|
+
*/
|
|
23
|
+
declare const transformedStringTypeTargetTypeKinds: {
|
|
24
|
+
date: {
|
|
25
|
+
jsonSchema: string;
|
|
26
|
+
primitive: undefined;
|
|
27
|
+
};
|
|
28
|
+
time: {
|
|
29
|
+
jsonSchema: string;
|
|
30
|
+
primitive: undefined;
|
|
31
|
+
};
|
|
32
|
+
"date-time": {
|
|
33
|
+
jsonSchema: string;
|
|
34
|
+
primitive: undefined;
|
|
35
|
+
};
|
|
36
|
+
uuid: {
|
|
37
|
+
jsonSchema: string;
|
|
38
|
+
primitive: undefined;
|
|
39
|
+
};
|
|
40
|
+
uri: {
|
|
41
|
+
jsonSchema: string;
|
|
42
|
+
primitive: undefined;
|
|
43
|
+
attributesProducer: typeof uriInferenceAttributesProducer;
|
|
44
|
+
};
|
|
45
|
+
"integer-string": TransformedStringTypeTargets;
|
|
46
|
+
"bool-string": TransformedStringTypeTargets;
|
|
47
|
+
};
|
|
48
|
+
export declare const transformedStringTypeTargetTypeKindsMap: Map<string, TransformedStringTypeTargets>;
|
|
49
|
+
export type TransformedStringTypeKind = keyof typeof transformedStringTypeTargetTypeKinds;
|
|
50
|
+
export type PrimitiveStringTypeKind = "string" | TransformedStringTypeKind;
|
|
51
|
+
export type PrimitiveNonStringTypeKind = "none" | "any" | "null" | "bool" | "integer" | "double";
|
|
52
|
+
export type PrimitiveTypeKind = PrimitiveNonStringTypeKind | PrimitiveStringTypeKind;
|
|
53
|
+
export type NamedTypeKind = "class" | "enum" | "union";
|
|
54
|
+
export type TypeKind = PrimitiveTypeKind | NamedTypeKind | "array" | "object" | "map" | "intersection";
|
|
55
|
+
export type ObjectTypeKind = "object" | "map" | "class";
|
|
56
|
+
export declare const transformedStringTypeKinds: ReadonlySet<"date" | "time" | "date-time" | "uuid" | "uri" | "integer-string" | "bool-string">;
|
|
57
|
+
export declare function isPrimitiveStringTypeKind(kind: string): kind is PrimitiveStringTypeKind;
|
|
58
|
+
export declare function targetTypeKindForTransformedStringTypeKind(kind: PrimitiveStringTypeKind): PrimitiveNonStringTypeKind | undefined;
|
|
59
|
+
export declare function isNumberTypeKind(kind: TypeKind): kind is "integer" | "double";
|
|
60
|
+
export declare function isPrimitiveTypeKind(kind: TypeKind): kind is PrimitiveTypeKind;
|
|
61
|
+
export declare function triviallyStructurallyCompatible(x: Type, y: Type): boolean;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.triviallyStructurallyCompatible = exports.isPrimitiveTypeKind = exports.isNumberTypeKind = exports.targetTypeKindForTransformedStringTypeKind = exports.isPrimitiveStringTypeKind = exports.transformedStringTypeKinds = exports.transformedStringTypeTargetTypeKindsMap = void 0;
|
|
4
|
+
const collection_utils_1 = require("collection-utils");
|
|
5
|
+
const URIAttributes_1 = require("../attributes/URIAttributes");
|
|
6
|
+
/**
|
|
7
|
+
* All the transformed string type kinds and the JSON Schema formats and
|
|
8
|
+
* primitive type kinds they map to. Not all transformed string types map to
|
|
9
|
+
* primitive types. Date-time types, for example, stand on their own, but
|
|
10
|
+
* stringified integers map to integers.
|
|
11
|
+
*/
|
|
12
|
+
const transformedStringTypeTargetTypeKinds = {
|
|
13
|
+
"date": { jsonSchema: "date", primitive: undefined },
|
|
14
|
+
"time": { jsonSchema: "time", primitive: undefined },
|
|
15
|
+
"date-time": { jsonSchema: "date-time", primitive: undefined },
|
|
16
|
+
"uuid": { jsonSchema: "uuid", primitive: undefined },
|
|
17
|
+
"uri": { jsonSchema: "uri", primitive: undefined, attributesProducer: URIAttributes_1.uriInferenceAttributesProducer },
|
|
18
|
+
"integer-string": { jsonSchema: "integer", primitive: "integer" },
|
|
19
|
+
"bool-string": { jsonSchema: "boolean", primitive: "bool" }
|
|
20
|
+
};
|
|
21
|
+
exports.transformedStringTypeTargetTypeKindsMap = (0, collection_utils_1.mapFromObject)(transformedStringTypeTargetTypeKinds);
|
|
22
|
+
exports.transformedStringTypeKinds = new Set(Object.getOwnPropertyNames(transformedStringTypeTargetTypeKinds));
|
|
23
|
+
function isPrimitiveStringTypeKind(kind) {
|
|
24
|
+
return kind === "string" || (0, collection_utils_1.hasOwnProperty)(transformedStringTypeTargetTypeKinds, kind);
|
|
25
|
+
}
|
|
26
|
+
exports.isPrimitiveStringTypeKind = isPrimitiveStringTypeKind;
|
|
27
|
+
function targetTypeKindForTransformedStringTypeKind(kind) {
|
|
28
|
+
const target = exports.transformedStringTypeTargetTypeKindsMap.get(kind);
|
|
29
|
+
if (target === undefined)
|
|
30
|
+
return undefined;
|
|
31
|
+
return target.primitive;
|
|
32
|
+
}
|
|
33
|
+
exports.targetTypeKindForTransformedStringTypeKind = targetTypeKindForTransformedStringTypeKind;
|
|
34
|
+
function isNumberTypeKind(kind) {
|
|
35
|
+
return kind === "integer" || kind === "double";
|
|
36
|
+
}
|
|
37
|
+
exports.isNumberTypeKind = isNumberTypeKind;
|
|
38
|
+
function isPrimitiveTypeKind(kind) {
|
|
39
|
+
if (isPrimitiveStringTypeKind(kind))
|
|
40
|
+
return true;
|
|
41
|
+
if (isNumberTypeKind(kind))
|
|
42
|
+
return true;
|
|
43
|
+
return kind === "none" || kind === "any" || kind === "null" || kind === "bool";
|
|
44
|
+
}
|
|
45
|
+
exports.isPrimitiveTypeKind = isPrimitiveTypeKind;
|
|
46
|
+
function triviallyStructurallyCompatible(x, y) {
|
|
47
|
+
if (x.index === y.index)
|
|
48
|
+
return true;
|
|
49
|
+
if (x.kind === "none" || y.kind === "none")
|
|
50
|
+
return true;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
exports.triviallyStructurallyCompatible = triviallyStructurallyCompatible;
|