quicktype-core 23.1.3 → 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.
Files changed (114) hide show
  1. package/dist/ConvenienceRenderer.js +2 -2
  2. package/dist/DeclarationIR.d.ts +2 -2
  3. package/dist/GatherNames.d.ts +1 -1
  4. package/dist/GatherNames.js +2 -2
  5. package/dist/GraphRewriting.d.ts +4 -2
  6. package/dist/GraphRewriting.js +25 -26
  7. package/dist/MakeTransformations.d.ts +1 -1
  8. package/dist/MakeTransformations.js +2 -2
  9. package/dist/Renderer.d.ts +1 -1
  10. package/dist/Run.d.ts +1 -1
  11. package/dist/Run.js +8 -6
  12. package/dist/TargetLanguage.d.ts +3 -3
  13. package/dist/Transformers.d.ts +2 -1
  14. package/dist/Transformers.js +8 -8
  15. package/dist/Type/ProvenanceTypeAttributeKind.d.ts +2 -0
  16. package/dist/Type/ProvenanceTypeAttributeKind.js +28 -0
  17. package/dist/Type/TransformedStringType.d.ts +62 -0
  18. package/dist/Type/TransformedStringType.js +53 -0
  19. package/dist/{Type.d.ts → Type/Type.d.ts} +6 -63
  20. package/dist/{Type.js → Type/Type.js} +15 -63
  21. package/dist/{TypeBuilder.d.ts → Type/TypeBuilder.d.ts} +12 -10
  22. package/dist/{TypeBuilder.js → Type/TypeBuilder.js} +30 -60
  23. package/dist/Type/TypeBuilderUtils.d.ts +4 -0
  24. package/dist/Type/TypeBuilderUtils.js +19 -0
  25. package/dist/{TypeGraph.d.ts → Type/TypeGraph.d.ts} +6 -15
  26. package/dist/{TypeGraph.js → Type/TypeGraph.js} +33 -149
  27. package/dist/Type/TypeGraphUtils.d.ts +5 -0
  28. package/dist/Type/TypeGraphUtils.js +86 -0
  29. package/dist/Type/TypeRef.d.ts +12 -0
  30. package/dist/Type/TypeRef.js +50 -0
  31. package/dist/{TypeUtils.d.ts → Type/TypeUtils.d.ts} +2 -2
  32. package/dist/{TypeUtils.js → Type/TypeUtils.js} +5 -5
  33. package/dist/Type/index.d.ts +5 -0
  34. package/dist/Type/index.js +22 -0
  35. package/dist/UnifyClasses.d.ts +3 -3
  36. package/dist/UnifyClasses.js +5 -5
  37. package/dist/UnionBuilder.d.ts +2 -2
  38. package/dist/UnionBuilder.js +1 -1
  39. package/dist/attributes/AccessorNames.d.ts +1 -1
  40. package/dist/attributes/Description.js +2 -6
  41. package/dist/attributes/EnumValues.d.ts +1 -1
  42. package/dist/attributes/StringTypes.d.ts +2 -2
  43. package/dist/attributes/StringTypes.js +2 -3
  44. package/dist/index.d.ts +5 -4
  45. package/dist/index.js +4 -4
  46. package/dist/input/Inference.d.ts +2 -2
  47. package/dist/input/Inference.js +3 -3
  48. package/dist/input/Inputs.d.ts +1 -1
  49. package/dist/input/JSONSchemaInput.d.ts +2 -18
  50. package/dist/input/JSONSchemaInput.js +26 -36
  51. package/dist/input/PathElement.d.ts +17 -0
  52. package/dist/input/PathElement.js +10 -0
  53. package/dist/language/CJSON/CJSONRenderer.js +1 -1
  54. package/dist/language/CPlusPlus/CPlusPlusRenderer.js +1 -1
  55. package/dist/language/CSharp/CSharpRenderer.js +1 -1
  56. package/dist/language/CSharp/NewtonSoftCSharpRenderer.js +1 -1
  57. package/dist/language/CSharp/SystemTextJsonCSharpRenderer.js +1 -1
  58. package/dist/language/CSharp/language.d.ts +1 -1
  59. package/dist/language/CSharp/utils.js +1 -1
  60. package/dist/language/Crystal/CrystalRenderer.js +1 -1
  61. package/dist/language/Dart/DartRenderer.js +1 -1
  62. package/dist/language/Dart/language.d.ts +1 -1
  63. package/dist/language/Elixir/ElixirRenderer.js +1 -1
  64. package/dist/language/Elm/ElmRenderer.js +1 -1
  65. package/dist/language/Elm/utils.js +1 -1
  66. package/dist/language/Golang/GolangRenderer.js +1 -1
  67. package/dist/language/Golang/language.d.ts +1 -1
  68. package/dist/language/Haskell/HaskellRenderer.js +1 -1
  69. package/dist/language/JSONSchema/JSONSchemaRenderer.js +1 -1
  70. package/dist/language/JSONSchema/language.d.ts +1 -1
  71. package/dist/language/JSONSchema/language.js +2 -2
  72. package/dist/language/Java/JavaJacksonRenderer.js +1 -1
  73. package/dist/language/Java/JavaRenderer.js +1 -1
  74. package/dist/language/Java/language.d.ts +1 -1
  75. package/dist/language/JavaScript/JavaScriptRenderer.js +1 -1
  76. package/dist/language/JavaScript/language.d.ts +1 -1
  77. package/dist/language/JavaScriptPropTypes/JavaScriptPropTypesRenderer.js +1 -1
  78. package/dist/language/Kotlin/KotlinJacksonRenderer.js +1 -1
  79. package/dist/language/Kotlin/KotlinKlaxonRenderer.js +1 -1
  80. package/dist/language/Kotlin/KotlinRenderer.js +1 -1
  81. package/dist/language/Objective-C/ObjectiveCRenderer.js +1 -1
  82. package/dist/language/Php/PhpRenderer.js +1 -1
  83. package/dist/language/Php/language.d.ts +1 -1
  84. package/dist/language/Pike/PikeRenderer.js +1 -1
  85. package/dist/language/Python/JSONPythonRenderer.js +1 -1
  86. package/dist/language/Python/PythonRenderer.js +1 -1
  87. package/dist/language/Python/language.d.ts +1 -1
  88. package/dist/language/Ruby/RubyRenderer.js +1 -1
  89. package/dist/language/Rust/RustRenderer.js +1 -1
  90. package/dist/language/Scala3/CirceRenderer.js +1 -1
  91. package/dist/language/Scala3/Scala3Renderer.js +1 -1
  92. package/dist/language/Smithy4s/Smithy4sRenderer.js +1 -1
  93. package/dist/language/Swift/SwiftRenderer.js +1 -1
  94. package/dist/language/Swift/language.d.ts +1 -1
  95. package/dist/language/TypeScriptEffectSchema/TypeScriptEffectSchemaRenderer.js +1 -1
  96. package/dist/language/TypeScriptFlow/TypeScriptFlowBaseRenderer.js +1 -1
  97. package/dist/language/TypeScriptFlow/TypeScriptRenderer.js +1 -1
  98. package/dist/language/TypeScriptFlow/language.d.ts +1 -1
  99. package/dist/language/TypeScriptZod/TypeScriptZodRenderer.js +1 -1
  100. package/dist/language/TypeScriptZod/language.d.ts +1 -1
  101. package/dist/rewrites/CombineClasses.d.ts +1 -1
  102. package/dist/rewrites/CombineClasses.js +2 -2
  103. package/dist/rewrites/ExpandStrings.d.ts +1 -1
  104. package/dist/rewrites/ExpandStrings.js +1 -1
  105. package/dist/rewrites/FlattenStrings.d.ts +2 -2
  106. package/dist/rewrites/FlattenStrings.js +1 -1
  107. package/dist/rewrites/FlattenUnions.d.ts +2 -2
  108. package/dist/rewrites/FlattenUnions.js +4 -4
  109. package/dist/rewrites/InferMaps.d.ts +2 -2
  110. package/dist/rewrites/InferMaps.js +1 -1
  111. package/dist/rewrites/ReplaceObjectType.d.ts +2 -2
  112. package/dist/rewrites/ResolveIntersections.d.ts +2 -2
  113. package/dist/rewrites/ResolveIntersections.js +1 -1
  114. 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;
@@ -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;
@@ -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;
@@ -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();
@@ -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 { type StringTypeMapping, TypeBuilder } from "./TypeBuilder";
4
- import { type TypeGraph, type TypeRef } from "./TypeGraph";
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;
@@ -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
- // eslint-disable-next-line import/no-cycle
8
- const TypeBuilder_1 = require("./TypeBuilder");
9
- const TypeGraph_1 = require("./TypeGraph");
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, TypeGraph_1.isTypeRef)(trefs)) {
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, TypeGraph_1.isTypeRef)(trefs)) {
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(originalGraph.serial + 1, stringTypeMapping, alphabetizeProperties, false, false, graphHasProvenanceAttributes);
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, TypeGraph_1.assertTypeRefGraph)(originalRef, this.originalGraph);
179
+ (0, TypeRef_1.assertTypeRefGraph)(originalRef, this.originalGraph);
181
180
  }
182
181
  if (forwardingRef !== undefined) {
183
- (0, TypeGraph_1.assertTypeRefGraph)(forwardingRef, this.typeGraph);
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, TypeGraph_1.derefTypeRef)(tref, this.originalGraph));
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, TypeGraph_1.typeRefIndex)(this.getMapTarget(typeRefs[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, TypeGraph_1.typeRefIndex)(this.getMapTarget(typeRefs[i])));
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, TypeGraph_1.typeRefIndex)(originalRef);
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, TypeGraph_1.typeRefIndex)(forwardingRef)}`);
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, TypeGraph_1.typeAndAttributesForTypeRef)(originalRef, this.originalGraph);
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, TypeGraph_1.typeRefIndex)(tref)}`);
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, TypeGraph_1.typeRefIndex)(forwardingRef)}`);
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, TypeGraph_1.typeRefIndex)(originalRef);
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, TypeGraph_1.typeRefIndex)(forwardingRef)}`);
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, TypeGraph_1.typeAndAttributesForTypeRef)(originalRef, this.originalGraph);
329
- const index = (0, TypeGraph_1.typeRefIndex)(originalRef);
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, TypeGraph_1.typeRefIndex)(tref)}`);
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, TypeGraph_1.typeRefIndex)(typeRefs[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, TypeGraph_1.typeRefIndex)(typeRefs[i])) !== maybeRef) {
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, TypeGraph_1.typeRefIndex)(typeRefs[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, TypeGraph_1.typeRefIndex)(typeRefs[i])) !== maybeSet) {
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 TypeGraph_1 = require("./TypeGraph");
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, TypeGraph_1.typeRefIndex)(reconstitutedTargetType)}:`);
15
+ console.log(`transformation for ${(0, TypeRef_1.typeRefIndex)(reconstitutedTargetType)}:`);
16
16
  transformation.debugPrint();
17
17
  console.log("reverse:");
18
18
  transformation.reverse.debugPrint();
@@ -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>;
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 "./TypeBuilder";
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(0, stringTypeMapping, this._options.alphabetizeProperties, this._options.allPropertiesOptional, this._options.checkProvenance, false);
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, TypeGraph_1.removeIndirectionIntersections)(graph, stringTypeMapping, debugPrintReconstitution)));
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, TypeGraph_1.noneToAny)(graph, stringTypeMapping, debugPrintReconstitution)));
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, TypeGraph_1.optionalToNullable)(graph, stringTypeMapping, debugPrintReconstitution)));
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)));
@@ -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 "./TypeBuilder";
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 {
@@ -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, type TypeRef } from "./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;
@@ -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 TypeGraph_1 = require("./TypeGraph");
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, TypeGraph_1.derefTypeRef)(this.sourceTypeRef, this.graph);
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, TypeGraph_1.derefTypeRef)(this._itemTargetTypeRef, this.graph);
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, TypeGraph_1.derefTypeRef)(this._itemTargetTypeRef, this.graph);
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, TypeGraph_1.derefTypeRef)(this.sourceTypeRef, this.graph);
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, TypeGraph_1.derefTypeRef)(this.memberTypeRef, this.graph);
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, TypeGraph_1.derefTypeRef)(this.sourceTypeRef, this.graph);
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, TypeGraph_1.derefTypeRef)(this._targetTypeRef, this._graph);
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,2 @@
1
+ import { TypeAttributeKind } from "../attributes/TypeAttributes";
2
+ export declare const provenanceTypeAttributeKind: TypeAttributeKind<Set<number>>;
@@ -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;
@@ -1,65 +1,9 @@
1
- import { type TypeAttributes } from "./attributes/TypeAttributes";
2
- import { type TypeNames } from "./attributes/TypeNames";
3
- import { uriInferenceAttributesProducer } from "./attributes/URIAttributes";
4
- import { type BaseGraphRewriteBuilder, type TypeReconstituter } from "./GraphRewriting";
5
- import { type TypeGraph, type TypeRef } from "./TypeGraph";
6
- /**
7
- * `jsonSchema` is the `format` to be used to represent this string type in
8
- * JSON Schema. It's ok to "invent" a new one if the JSON Schema standard doesn't
9
- * have that particular type yet.
10
- *
11
- * For transformed type kinds that map to an existing primitive type, `primitive`
12
- * must specify that type kind.
13
- */
14
- export interface TransformedStringTypeTargets {
15
- attributesProducer?: (s: string) => TypeAttributes;
16
- jsonSchema: string;
17
- primitive: PrimitiveNonStringTypeKind | undefined;
18
- }
19
- /**
20
- * All the transformed string type kinds and the JSON Schema formats and
21
- * primitive type kinds they map to. Not all transformed string types map to
22
- * primitive types. Date-time types, for example, stand on their own, but
23
- * stringified integers map to integers.
24
- */
25
- declare const transformedStringTypeTargetTypeKinds: {
26
- date: {
27
- jsonSchema: string;
28
- primitive: undefined;
29
- };
30
- time: {
31
- jsonSchema: string;
32
- primitive: undefined;
33
- };
34
- "date-time": {
35
- jsonSchema: string;
36
- primitive: undefined;
37
- };
38
- uuid: {
39
- jsonSchema: string;
40
- primitive: undefined;
41
- };
42
- uri: {
43
- jsonSchema: string;
44
- primitive: undefined;
45
- attributesProducer: typeof uriInferenceAttributesProducer;
46
- };
47
- "integer-string": TransformedStringTypeTargets;
48
- "bool-string": TransformedStringTypeTargets;
49
- };
50
- export declare const transformedStringTypeTargetTypeKindsMap: Map<string, TransformedStringTypeTargets>;
51
- export type TransformedStringTypeKind = keyof typeof transformedStringTypeTargetTypeKinds;
52
- export type PrimitiveStringTypeKind = "string" | TransformedStringTypeKind;
53
- export type PrimitiveNonStringTypeKind = "none" | "any" | "null" | "bool" | "integer" | "double";
54
- export type PrimitiveTypeKind = PrimitiveNonStringTypeKind | PrimitiveStringTypeKind;
55
- export type NamedTypeKind = "class" | "enum" | "union";
56
- export type TypeKind = PrimitiveTypeKind | NamedTypeKind | "array" | "object" | "map" | "intersection";
57
- export type ObjectTypeKind = "object" | "map" | "class";
58
- export declare const transformedStringTypeKinds: ReadonlySet<"date" | "time" | "date-time" | "uuid" | "uri" | "integer-string" | "bool-string">;
59
- export declare function isPrimitiveStringTypeKind(kind: string): kind is PrimitiveStringTypeKind;
60
- export declare function targetTypeKindForTransformedStringTypeKind(kind: PrimitiveStringTypeKind): PrimitiveNonStringTypeKind | undefined;
61
- export declare function isNumberTypeKind(kind: TypeKind): kind is "integer" | "double";
62
- export declare function isPrimitiveTypeKind(kind: TypeKind): kind is PrimitiveTypeKind;
1
+ import { type TypeAttributes } from "../attributes/TypeAttributes";
2
+ import { type TypeNames } from "../attributes/TypeNames";
3
+ import { type BaseGraphRewriteBuilder, type TypeReconstituter } from "../GraphRewriting";
4
+ import { type ObjectTypeKind, type PrimitiveTypeKind, type TypeKind } from "./TransformedStringType";
5
+ import { type TypeGraph } from "./TypeGraph";
6
+ import { type TypeRef } from "./TypeRef";
63
7
  export declare class TypeIdentity {
64
8
  private readonly _kind;
65
9
  private readonly _components;
@@ -203,4 +147,3 @@ export declare class UnionType extends SetOperationType {
203
147
  get isCanonical(): boolean;
204
148
  reconstitute<T extends BaseGraphRewriteBuilder>(builder: TypeReconstituter<T>, canonicalOrder: boolean): void;
205
149
  }
206
- export {};