quicktype 17.0.5 → 18.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/cli/CompressedJSONFromStream.js +26 -38
  2. package/dist/cli/GraphQLIntrospection.js +33 -41
  3. package/dist/cli/TypeSource.d.ts +1 -1
  4. package/dist/cli/URLGrammar.js +4 -3
  5. package/dist/cli/index.js +363 -364
  6. package/dist/quicktype-core/Annotation.js +2 -0
  7. package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
  8. package/dist/quicktype-core/ConvenienceRenderer.js +104 -81
  9. package/dist/quicktype-core/DateTime.js +1 -0
  10. package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
  11. package/dist/quicktype-core/DeclarationIR.js +13 -10
  12. package/dist/quicktype-core/EncodedMarkovChain.js +1 -0
  13. package/dist/quicktype-core/GatherNames.js +47 -25
  14. package/dist/quicktype-core/Graph.d.ts +2 -2
  15. package/dist/quicktype-core/Graph.js +23 -19
  16. package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
  17. package/dist/quicktype-core/GraphRewriting.js +65 -54
  18. package/dist/quicktype-core/MakeTransformations.js +23 -22
  19. package/dist/quicktype-core/MarkovChain.d.ts +3 -3
  20. package/dist/quicktype-core/MarkovChain.js +9 -8
  21. package/dist/quicktype-core/Messages.d.ts +3 -3
  22. package/dist/quicktype-core/Messages.js +8 -3
  23. package/dist/quicktype-core/Naming.d.ts +11 -11
  24. package/dist/quicktype-core/Naming.js +76 -61
  25. package/dist/quicktype-core/Renderer.d.ts +6 -6
  26. package/dist/quicktype-core/Renderer.js +34 -17
  27. package/dist/quicktype-core/RendererOptions.d.ts +5 -5
  28. package/dist/quicktype-core/RendererOptions.js +6 -3
  29. package/dist/quicktype-core/Run.d.ts +9 -9
  30. package/dist/quicktype-core/Run.js +72 -67
  31. package/dist/quicktype-core/Source.d.ts +3 -3
  32. package/dist/quicktype-core/Source.js +19 -18
  33. package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
  34. package/dist/quicktype-core/TargetLanguage.js +6 -2
  35. package/dist/quicktype-core/Transformers.d.ts +25 -25
  36. package/dist/quicktype-core/Transformers.js +94 -66
  37. package/dist/quicktype-core/Type.d.ts +41 -43
  38. package/dist/quicktype-core/Type.js +96 -71
  39. package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
  40. package/dist/quicktype-core/TypeBuilder.js +53 -47
  41. package/dist/quicktype-core/TypeGraph.d.ts +4 -4
  42. package/dist/quicktype-core/TypeGraph.js +49 -40
  43. package/dist/quicktype-core/TypeUtils.d.ts +2 -2
  44. package/dist/quicktype-core/TypeUtils.js +23 -22
  45. package/dist/quicktype-core/UnifyClasses.js +16 -12
  46. package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
  47. package/dist/quicktype-core/UnionBuilder.js +33 -30
  48. package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
  49. package/dist/quicktype-core/attributes/AccessorNames.js +18 -17
  50. package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
  51. package/dist/quicktype-core/attributes/Constraints.js +8 -4
  52. package/dist/quicktype-core/attributes/Description.js +6 -5
  53. package/dist/quicktype-core/attributes/EnumValues.js +4 -3
  54. package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
  55. package/dist/quicktype-core/attributes/StringTypes.js +24 -21
  56. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
  57. package/dist/quicktype-core/attributes/TypeAttributes.js +12 -10
  58. package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
  59. package/dist/quicktype-core/attributes/TypeNames.js +49 -21
  60. package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
  61. package/dist/quicktype-core/attributes/URIAttributes.js +10 -6
  62. package/dist/quicktype-core/index.js +128 -125
  63. package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
  64. package/dist/quicktype-core/input/CompressedJSON.js +49 -54
  65. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +5 -13
  66. package/dist/quicktype-core/input/Inference.d.ts +2 -2
  67. package/dist/quicktype-core/input/Inference.js +25 -17
  68. package/dist/quicktype-core/input/Inputs.d.ts +2 -2
  69. package/dist/quicktype-core/input/Inputs.js +38 -54
  70. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
  71. package/dist/quicktype-core/input/JSONSchemaInput.js +503 -523
  72. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
  73. package/dist/quicktype-core/input/JSONSchemaStore.js +24 -35
  74. package/dist/quicktype-core/input/PostmanCollection.js +2 -1
  75. package/dist/quicktype-core/input/io/NodeIO.js +55 -44
  76. package/dist/quicktype-core/input/io/get-stream/index.js +6 -2
  77. package/dist/quicktype-core/language/All.js +3 -2
  78. package/dist/quicktype-core/language/CPlusPlus.d.ts +12 -9
  79. package/dist/quicktype-core/language/CPlusPlus.js +283 -217
  80. package/dist/quicktype-core/language/CSharp.d.ts +7 -7
  81. package/dist/quicktype-core/language/CSharp.js +82 -72
  82. package/dist/quicktype-core/language/Crystal.d.ts +2 -2
  83. package/dist/quicktype-core/language/Crystal.js +18 -17
  84. package/dist/quicktype-core/language/Dart.d.ts +4 -4
  85. package/dist/quicktype-core/language/Dart.js +36 -34
  86. package/dist/quicktype-core/language/Elm.d.ts +6 -6
  87. package/dist/quicktype-core/language/Elm.js +47 -45
  88. package/dist/quicktype-core/language/Golang.d.ts +4 -4
  89. package/dist/quicktype-core/language/Golang.js +23 -20
  90. package/dist/quicktype-core/language/Haskell.d.ts +5 -5
  91. package/dist/quicktype-core/language/Haskell.js +25 -23
  92. package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
  93. package/dist/quicktype-core/language/JSONSchema.js +17 -16
  94. package/dist/quicktype-core/language/Java.d.ts +2 -2
  95. package/dist/quicktype-core/language/Java.js +97 -97
  96. package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
  97. package/dist/quicktype-core/language/JavaScript.js +19 -17
  98. package/dist/quicktype-core/language/JavaScriptPropTypes.js +15 -13
  99. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +12 -11
  100. package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
  101. package/dist/quicktype-core/language/Kotlin.js +39 -37
  102. package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
  103. package/dist/quicktype-core/language/Objective-C.js +45 -41
  104. package/dist/quicktype-core/language/Php.d.ts +2 -2
  105. package/dist/quicktype-core/language/Php.js +66 -41
  106. package/dist/quicktype-core/language/Pike.d.ts +1 -1
  107. package/dist/quicktype-core/language/Pike.js +18 -17
  108. package/dist/quicktype-core/language/Python.d.ts +8 -8
  109. package/dist/quicktype-core/language/Python.js +63 -64
  110. package/dist/quicktype-core/language/Rust.d.ts +2 -2
  111. package/dist/quicktype-core/language/Rust.js +21 -19
  112. package/dist/quicktype-core/language/Swift.d.ts +7 -7
  113. package/dist/quicktype-core/language/Swift.js +568 -565
  114. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
  115. package/dist/quicktype-core/language/TypeScriptFlow.js +28 -26
  116. package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
  117. package/dist/quicktype-core/language/ruby/index.js +49 -24
  118. package/dist/quicktype-core/language/ruby/keywords.js +1 -0
  119. package/dist/quicktype-core/rewrites/CombineClasses.js +9 -8
  120. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
  121. package/dist/quicktype-core/rewrites/ExpandStrings.js +18 -17
  122. package/dist/quicktype-core/rewrites/FlattenStrings.js +7 -6
  123. package/dist/quicktype-core/rewrites/FlattenUnions.js +9 -8
  124. package/dist/quicktype-core/rewrites/InferMaps.js +11 -10
  125. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +8 -7
  126. package/dist/quicktype-core/rewrites/ResolveIntersections.js +68 -67
  127. package/dist/quicktype-core/support/Acronyms.js +3 -1
  128. package/dist/quicktype-core/support/Chance.js +10 -0
  129. package/dist/quicktype-core/support/Converters.js +1 -0
  130. package/dist/quicktype-core/support/Strings.d.ts +4 -4
  131. package/dist/quicktype-core/support/Strings.js +17 -16
  132. package/dist/quicktype-core/support/Support.d.ts +1 -1
  133. package/dist/quicktype-core/support/Support.js +30 -6
  134. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
  135. package/dist/quicktype-graphql-input/GraphQLSchema.js +1 -0
  136. package/dist/quicktype-graphql-input/index.d.ts +1 -1
  137. package/dist/quicktype-graphql-input/index.js +229 -212
  138. package/dist/quicktype-typescript-input/index.js +28 -4
  139. package/package.json +24 -20
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
4
  };
10
5
  Object.defineProperty(exports, "__esModule", { value: true });
11
- const URI = require("urijs");
6
+ exports.JSONSchemaInput = exports.schemaTypeDict = exports.Ref = exports.PathElementKind = void 0;
7
+ const urijs_1 = __importDefault(require("urijs"));
12
8
  const collection_utils_1 = require("collection-utils");
13
9
  const Type_1 = require("../Type");
14
10
  const Support_1 = require("../support/Support");
@@ -55,13 +51,13 @@ function withRef(refOrLoc, props) {
55
51
  }
56
52
  function checkJSONSchemaObject(x, refOrLoc) {
57
53
  if (Array.isArray(x)) {
58
- return Messages_1.messageError("SchemaArrayIsInvalidSchema", withRef(refOrLoc));
54
+ return (0, Messages_1.messageError)("SchemaArrayIsInvalidSchema", withRef(refOrLoc));
59
55
  }
60
56
  if (x === null) {
61
- return Messages_1.messageError("SchemaNullIsInvalidSchema", withRef(refOrLoc));
57
+ return (0, Messages_1.messageError)("SchemaNullIsInvalidSchema", withRef(refOrLoc));
62
58
  }
63
59
  if (typeof x !== "object") {
64
- return Messages_1.messageError("SchemaInvalidJSONSchemaType", withRef(refOrLoc, { type: typeof x }));
60
+ return (0, Messages_1.messageError)("SchemaInvalidJSONSchemaType", withRef(refOrLoc, { type: typeof x }));
65
61
  }
66
62
  return x;
67
63
  }
@@ -78,23 +74,14 @@ function normalizeURI(uri) {
78
74
  // JSONSchemaStore should take a URI, not a string, and if it reads from
79
75
  // a file it can decode by itself.
80
76
  if (typeof uri === "string") {
81
- uri = new URI(uri);
77
+ uri = new urijs_1.default(uri);
82
78
  }
83
- return new URI(URI.decode(uri.clone().normalize().toString()));
79
+ return new urijs_1.default(urijs_1.default.decode(uri.clone().normalize().toString()));
84
80
  }
85
81
  class Ref {
86
- constructor(addressURI, path) {
87
- this.path = path;
88
- if (addressURI !== undefined) {
89
- Support_1.assert(addressURI.fragment() === "", `Ref URI with fragment is not allowed: ${addressURI.toString()}`);
90
- this.addressURI = normalizeURI(addressURI);
91
- }
92
- else {
93
- this.addressURI = undefined;
94
- }
95
- }
82
+ path;
96
83
  static root(address) {
97
- const uri = collection_utils_1.definedMap(address, a => new URI(a));
84
+ const uri = (0, collection_utils_1.definedMap)(address, a => new urijs_1.default(a));
98
85
  return new Ref(uri, []);
99
86
  }
100
87
  static parsePath(path) {
@@ -124,13 +111,24 @@ class Ref {
124
111
  return new Ref(uri, elements);
125
112
  }
126
113
  static parse(ref) {
127
- return Ref.parseURI(new URI(ref), true);
114
+ return Ref.parseURI(new urijs_1.default(ref), true);
115
+ }
116
+ addressURI;
117
+ constructor(addressURI, path) {
118
+ this.path = path;
119
+ if (addressURI !== undefined) {
120
+ (0, Support_1.assert)(addressURI.fragment() === "", `Ref URI with fragment is not allowed: ${addressURI.toString()}`);
121
+ this.addressURI = normalizeURI(addressURI);
122
+ }
123
+ else {
124
+ this.addressURI = undefined;
125
+ }
128
126
  }
129
127
  get hasAddress() {
130
128
  return this.addressURI !== undefined;
131
129
  }
132
130
  get address() {
133
- return Support_1.defined(this.addressURI).toString();
131
+ return (0, Support_1.defined)(this.addressURI).toString();
134
132
  }
135
133
  get isRoot() {
136
134
  return this.path.length === 1 && this.path[0].kind === PathElementKind.Root;
@@ -183,18 +181,18 @@ class Ref {
183
181
  break;
184
182
  case PathElementKind.Type:
185
183
  case PathElementKind.Object:
186
- return Support_1.panic("We shouldn't try to get the name of Type or Object refs");
184
+ return (0, Support_1.panic)("We shouldn't try to get the name of Type or Object refs");
187
185
  default:
188
- return Support_1.assertNever(e);
186
+ return (0, Support_1.assertNever)(e);
189
187
  }
190
188
  }
191
189
  }
192
190
  get definitionName() {
193
- const pe = collection_utils_1.arrayGetFromEnd(this.path, 2);
191
+ const pe = (0, collection_utils_1.arrayGetFromEnd)(this.path, 2);
194
192
  if (pe === undefined)
195
193
  return undefined;
196
194
  if (keyOrIndex(pe) === "definitions")
197
- return keyOrIndex(Support_1.defined(collection_utils_1.arrayLast(this.path)));
195
+ return keyOrIndex((0, Support_1.defined)((0, collection_utils_1.arrayLast)(this.path)));
198
196
  return undefined;
199
197
  }
200
198
  toString() {
@@ -209,7 +207,7 @@ class Ref {
209
207
  case PathElementKind.KeyOrIndex:
210
208
  return e.key;
211
209
  default:
212
- return Support_1.assertNever(e);
210
+ return (0, Support_1.assertNever)(e);
213
211
  }
214
212
  }
215
213
  const address = this.addressURI === undefined ? "" : this.addressURI.toString();
@@ -229,26 +227,26 @@ class Ref {
229
227
  const key = first.key;
230
228
  if (Array.isArray(local)) {
231
229
  if (!/^\d+$/.test(key)) {
232
- return Messages_1.messageError("SchemaCannotIndexArrayWithNonNumber", withRef(refMaker, { actual: key }));
230
+ return (0, Messages_1.messageError)("SchemaCannotIndexArrayWithNonNumber", withRef(refMaker, { actual: key }));
233
231
  }
234
232
  const index = parseInt(first.key, 10);
235
233
  if (index >= local.length) {
236
- return Messages_1.messageError("SchemaIndexNotInArray", withRef(refMaker, { index }));
234
+ return (0, Messages_1.messageError)("SchemaIndexNotInArray", withRef(refMaker, { index }));
237
235
  }
238
236
  return this.lookup(local[index], rest, root);
239
237
  }
240
238
  else {
241
- if (!collection_utils_1.hasOwnProperty(local, key)) {
242
- return Messages_1.messageError("SchemaKeyNotInObject", withRef(refMaker, { key }));
239
+ if (!(0, collection_utils_1.hasOwnProperty)(local, key)) {
240
+ return (0, Messages_1.messageError)("SchemaKeyNotInObject", withRef(refMaker, { key }));
243
241
  }
244
242
  return this.lookup(checkJSONSchemaObject(local, refMaker)[first.key], rest, root);
245
243
  }
246
244
  case PathElementKind.Type:
247
- return Support_1.panic('Cannot look up path that indexes "type"');
245
+ return (0, Support_1.panic)('Cannot look up path that indexes "type"');
248
246
  case PathElementKind.Object:
249
- return Support_1.panic('Cannot look up path that indexes "object"');
247
+ return (0, Support_1.panic)('Cannot look up path that indexes "object"');
250
248
  default:
251
- return Support_1.assertNever(first);
249
+ return (0, Support_1.assertNever)(first);
252
250
  }
253
251
  }
254
252
  lookupRef(root) {
@@ -275,15 +273,15 @@ class Ref {
275
273
  return true;
276
274
  }
277
275
  hashCode() {
278
- let acc = collection_utils_1.hashCodeOf(collection_utils_1.definedMap(this.addressURI, u => u.toString()));
276
+ let acc = (0, collection_utils_1.hashCodeOf)((0, collection_utils_1.definedMap)(this.addressURI, u => u.toString()));
279
277
  for (const pe of this.path) {
280
- acc = collection_utils_1.addHashCode(acc, pe.kind);
278
+ acc = (0, collection_utils_1.addHashCode)(acc, pe.kind);
281
279
  switch (pe.kind) {
282
280
  case PathElementKind.Type:
283
- acc = collection_utils_1.addHashCode(acc, pe.index);
281
+ acc = (0, collection_utils_1.addHashCode)(acc, pe.index);
284
282
  break;
285
283
  case PathElementKind.KeyOrIndex:
286
- acc = collection_utils_1.addHashCode(acc, collection_utils_1.hashString(pe.key));
284
+ acc = (0, collection_utils_1.addHashCode)(acc, (0, collection_utils_1.hashString)(pe.key));
287
285
  break;
288
286
  default:
289
287
  break;
@@ -294,6 +292,9 @@ class Ref {
294
292
  }
295
293
  exports.Ref = Ref;
296
294
  class Location {
295
+ haveID;
296
+ canonicalRef;
297
+ virtualRef;
297
298
  constructor(canonicalRef, virtualRef, haveID = false) {
298
299
  this.haveID = haveID;
299
300
  this.canonicalRef = canonicalRef;
@@ -305,7 +306,7 @@ class Location {
305
306
  const parsed = Ref.parse(id);
306
307
  const virtual = this.haveID ? parsed.resolveAgainst(this.virtualRef) : parsed;
307
308
  if (!this.haveID) {
308
- Messages_1.messageAssert(virtual.hasAddress, "SchemaIDMustHaveAddress", withRef(this, { id }));
309
+ (0, Messages_1.messageAssert)(virtual.hasAddress, "SchemaIDMustHaveAddress", withRef(this, { id }));
309
310
  }
310
311
  return new Location(this.canonicalRef, virtual, true);
311
312
  }
@@ -323,10 +324,11 @@ class Location {
323
324
  }
324
325
  }
325
326
  class Canonizer {
327
+ _ctx;
328
+ _map = new collection_utils_1.EqualityMap();
329
+ _schemaAddressesAdded = new Set();
326
330
  constructor(_ctx) {
327
331
  this._ctx = _ctx;
328
- this._map = new collection_utils_1.EqualityMap();
329
- this._schemaAddressesAdded = new Set();
330
332
  }
331
333
  addIDs(schema, loc) {
332
334
  if (schema === null)
@@ -382,30 +384,30 @@ function checkTypeList(typeOrTypes, loc) {
382
384
  const arr = [];
383
385
  for (const t of typeOrTypes) {
384
386
  if (typeof t !== "string") {
385
- return Messages_1.messageError("SchemaTypeElementMustBeString", withRef(loc, { element: t }));
387
+ return (0, Messages_1.messageError)("SchemaTypeElementMustBeString", withRef(loc, { element: t }));
386
388
  }
387
389
  arr.push(t);
388
390
  }
389
391
  set = new Set(arr);
390
392
  }
391
393
  else {
392
- return Messages_1.messageError("SchemaTypeMustBeStringOrStringArray", withRef(loc, { actual: typeOrTypes }));
394
+ return (0, Messages_1.messageError)("SchemaTypeMustBeStringOrStringArray", withRef(loc, { actual: typeOrTypes }));
393
395
  }
394
- Messages_1.messageAssert(set.size > 0, "SchemaNoTypeSpecified", withRef(loc));
396
+ (0, Messages_1.messageAssert)(set.size > 0, "SchemaNoTypeSpecified", withRef(loc));
395
397
  const validTypes = ["null", "boolean", "object", "array", "number", "string", "integer"];
396
- const maybeInvalid = collection_utils_1.iterableFind(set, s => validTypes.indexOf(s) < 0);
398
+ const maybeInvalid = (0, collection_utils_1.iterableFind)(set, s => validTypes.indexOf(s) < 0);
397
399
  if (maybeInvalid !== undefined) {
398
- return Messages_1.messageError("SchemaInvalidType", withRef(loc, { type: maybeInvalid }));
400
+ return (0, Messages_1.messageError)("SchemaInvalidType", withRef(loc, { type: maybeInvalid }));
399
401
  }
400
402
  return set;
401
403
  }
402
404
  function checkRequiredArray(arr, loc) {
403
405
  if (!Array.isArray(arr)) {
404
- return Messages_1.messageError("SchemaRequiredMustBeStringOrStringArray", withRef(loc, { actual: arr }));
406
+ return (0, Messages_1.messageError)("SchemaRequiredMustBeStringOrStringArray", withRef(loc, { actual: arr }));
405
407
  }
406
408
  for (const e of arr) {
407
409
  if (typeof e !== "string") {
408
- return Messages_1.messageError("SchemaRequiredElementMustBeString", withRef(loc, { element: e }));
410
+ return (0, Messages_1.messageError)("SchemaRequiredElementMustBeString", withRef(loc, { element: e }));
409
411
  }
410
412
  }
411
413
  return arr;
@@ -421,429 +423,410 @@ exports.schemaTypeDict = {
421
423
  };
422
424
  const schemaTypes = Object.getOwnPropertyNames(exports.schemaTypeDict);
423
425
  function typeKindForJSONSchemaFormat(format) {
424
- const target = collection_utils_1.iterableFind(Type_1.transformedStringTypeTargetTypeKindsMap, ([_, { jsonSchema }]) => jsonSchema === format);
426
+ const target = (0, collection_utils_1.iterableFind)(Type_1.transformedStringTypeTargetTypeKindsMap, ([_, { jsonSchema }]) => jsonSchema === format);
425
427
  if (target === undefined)
426
428
  return undefined;
427
429
  return target[0];
428
430
  }
429
431
  function schemaFetchError(base, address) {
430
432
  if (base === undefined) {
431
- return Messages_1.messageError("SchemaFetchErrorTopLevel", { address });
433
+ return (0, Messages_1.messageError)("SchemaFetchErrorTopLevel", { address });
432
434
  }
433
435
  else {
434
- return Messages_1.messageError("SchemaFetchError", { address, base: base.canonicalRef });
436
+ return (0, Messages_1.messageError)("SchemaFetchError", { address, base: base.canonicalRef });
435
437
  }
436
438
  }
437
439
  class Resolver {
440
+ _ctx;
441
+ _store;
442
+ _canonizer;
438
443
  constructor(_ctx, _store, _canonizer) {
439
444
  this._ctx = _ctx;
440
445
  this._store = _store;
441
446
  this._canonizer = _canonizer;
442
447
  }
443
- tryResolveVirtualRef(fetchBase, lookupBase, virtualRef) {
444
- return __awaiter(this, void 0, void 0, function* () {
445
- let didAdd = false;
446
- // If we are resolving into a schema file that we haven't seen yet then
447
- // we don't know its $id mapping yet, which means we don't know where we
448
- // will end up. What we do if we encounter a new schema is add all its
449
- // IDs first, and then try to canonize again.
450
- for (;;) {
451
- const loc = this._canonizer.canonize(fetchBase, virtualRef);
452
- const canonical = loc.canonicalRef;
453
- Support_1.assert(canonical.hasAddress, "Canonical ref can't be resolved without an address");
454
- const address = canonical.address;
455
- let schema = canonical.addressURI === undefined
456
- ? undefined
457
- : yield this._store.get(address, this._ctx.debugPrintSchemaResolving);
458
- if (schema === undefined) {
459
- return [undefined, loc];
460
- }
461
- if (this._canonizer.addSchema(schema, address)) {
462
- Support_1.assert(!didAdd, "We can't add a schema twice");
463
- didAdd = true;
464
- }
465
- else {
466
- let lookupLoc = this._canonizer.canonize(lookupBase, virtualRef);
467
- if (fetchBase !== undefined) {
468
- lookupLoc = new Location(new Ref(loc.canonicalRef.addressURI, lookupLoc.canonicalRef.path), lookupLoc.virtualRef, lookupLoc.haveID);
469
- }
470
- return [lookupLoc.canonicalRef.lookupRef(schema), lookupLoc];
448
+ async tryResolveVirtualRef(fetchBase, lookupBase, virtualRef) {
449
+ let didAdd = false;
450
+ // If we are resolving into a schema file that we haven't seen yet then
451
+ // we don't know its $id mapping yet, which means we don't know where we
452
+ // will end up. What we do if we encounter a new schema is add all its
453
+ // IDs first, and then try to canonize again.
454
+ for (;;) {
455
+ const loc = this._canonizer.canonize(fetchBase, virtualRef);
456
+ const canonical = loc.canonicalRef;
457
+ (0, Support_1.assert)(canonical.hasAddress, "Canonical ref can't be resolved without an address");
458
+ const address = canonical.address;
459
+ let schema = canonical.addressURI === undefined
460
+ ? undefined
461
+ : await this._store.get(address, this._ctx.debugPrintSchemaResolving);
462
+ if (schema === undefined) {
463
+ return [undefined, loc];
464
+ }
465
+ if (this._canonizer.addSchema(schema, address)) {
466
+ (0, Support_1.assert)(!didAdd, "We can't add a schema twice");
467
+ didAdd = true;
468
+ }
469
+ else {
470
+ let lookupLoc = this._canonizer.canonize(lookupBase, virtualRef);
471
+ if (fetchBase !== undefined) {
472
+ lookupLoc = new Location(new Ref(loc.canonicalRef.addressURI, lookupLoc.canonicalRef.path), lookupLoc.virtualRef, lookupLoc.haveID);
471
473
  }
474
+ return [lookupLoc.canonicalRef.lookupRef(schema), lookupLoc];
472
475
  }
473
- });
476
+ }
474
477
  }
475
- resolveVirtualRef(base, virtualRef) {
476
- return __awaiter(this, void 0, void 0, function* () {
478
+ async resolveVirtualRef(base, virtualRef) {
479
+ if (this._ctx.debugPrintSchemaResolving) {
480
+ console.log(`resolving ${virtualRef.toString()} relative to ${base.toString()}`);
481
+ }
482
+ // Try with the virtual base first. If that doesn't work, use the
483
+ // canonical ref's address with the virtual base's path.
484
+ let result = await this.tryResolveVirtualRef(base, base, virtualRef);
485
+ let schema = result[0];
486
+ if (schema !== undefined) {
477
487
  if (this._ctx.debugPrintSchemaResolving) {
478
- console.log(`resolving ${virtualRef.toString()} relative to ${base.toString()}`);
488
+ console.log(`resolved to ${result[1].toString()}`);
479
489
  }
480
- // Try with the virtual base first. If that doesn't work, use the
481
- // canonical ref's address with the virtual base's path.
482
- let result = yield this.tryResolveVirtualRef(base, base, virtualRef);
483
- let schema = result[0];
484
- if (schema !== undefined) {
485
- if (this._ctx.debugPrintSchemaResolving) {
486
- console.log(`resolved to ${result[1].toString()}`);
487
- }
488
- return [schema, result[1]];
489
- }
490
- const altBase = new Location(base.canonicalRef, new Ref(base.canonicalRef.addressURI, base.virtualRef.path), base.haveID);
491
- result = yield this.tryResolveVirtualRef(altBase, base, virtualRef);
492
- schema = result[0];
493
- if (schema !== undefined) {
494
- if (this._ctx.debugPrintSchemaResolving) {
495
- console.log(`resolved to ${result[1].toString()}`);
496
- }
497
- return [schema, result[1]];
490
+ return [schema, result[1]];
491
+ }
492
+ const altBase = new Location(base.canonicalRef, new Ref(base.canonicalRef.addressURI, base.virtualRef.path), base.haveID);
493
+ result = await this.tryResolveVirtualRef(altBase, base, virtualRef);
494
+ schema = result[0];
495
+ if (schema !== undefined) {
496
+ if (this._ctx.debugPrintSchemaResolving) {
497
+ console.log(`resolved to ${result[1].toString()}`);
498
498
  }
499
- return schemaFetchError(base, virtualRef.address);
500
- });
499
+ return [schema, result[1]];
500
+ }
501
+ return schemaFetchError(base, virtualRef.address);
501
502
  }
502
- resolveTopLevelRef(ref) {
503
- return __awaiter(this, void 0, void 0, function* () {
504
- return yield this.resolveVirtualRef(new Location(new Ref(ref.addressURI, [])), new Ref(undefined, ref.path));
505
- });
503
+ async resolveTopLevelRef(ref) {
504
+ return await this.resolveVirtualRef(new Location(new Ref(ref.addressURI, [])), new Ref(undefined, ref.path));
506
505
  }
507
506
  }
508
- function addTypesInSchema(resolver, typeBuilder, references, attributeProducers) {
509
- return __awaiter(this, void 0, void 0, function* () {
510
- let typeForCanonicalRef = new collection_utils_1.EqualityMap();
511
- function setTypeForLocation(loc, t) {
512
- const maybeRef = typeForCanonicalRef.get(loc.canonicalRef);
513
- if (maybeRef !== undefined) {
514
- Support_1.assert(maybeRef === t, "Trying to set path again to different type");
507
+ async function addTypesInSchema(resolver, typeBuilder, references, attributeProducers) {
508
+ let typeForCanonicalRef = new collection_utils_1.EqualityMap();
509
+ function setTypeForLocation(loc, t) {
510
+ const maybeRef = typeForCanonicalRef.get(loc.canonicalRef);
511
+ if (maybeRef !== undefined) {
512
+ (0, Support_1.assert)(maybeRef === t, "Trying to set path again to different type");
513
+ }
514
+ typeForCanonicalRef.set(loc.canonicalRef, t);
515
+ }
516
+ async function makeObject(loc, attributes, properties, requiredArray, additionalProperties, sortKey = (k) => k.toLowerCase()) {
517
+ const required = new Set(requiredArray);
518
+ const propertiesMap = (0, collection_utils_1.mapSortBy)((0, collection_utils_1.mapFromObject)(properties), (_, k) => sortKey(k));
519
+ const props = await (0, collection_utils_1.mapMapSync)(propertiesMap, async (propSchema, propName) => {
520
+ const propLoc = loc.push("properties", propName);
521
+ const t = await toType(checkJSONSchema(propSchema, propLoc.canonicalRef), propLoc, (0, TypeNames_2.makeNamesTypeAttributes)(propName, true));
522
+ const isOptional = !required.has(propName);
523
+ return typeBuilder.makeClassProperty(t, isOptional);
524
+ });
525
+ let additionalPropertiesType;
526
+ if (additionalProperties === undefined || additionalProperties === true) {
527
+ additionalPropertiesType = typeBuilder.getPrimitiveType("any");
528
+ }
529
+ else if (additionalProperties === false) {
530
+ additionalPropertiesType = undefined;
531
+ }
532
+ else {
533
+ const additionalLoc = loc.push("additionalProperties");
534
+ additionalPropertiesType = await toType(checkJSONSchema(additionalProperties, additionalLoc.canonicalRef), additionalLoc, (0, TypeNames_2.singularizeTypeNames)(attributes));
535
+ }
536
+ const additionalRequired = (0, collection_utils_1.setSubtract)(required, props.keys());
537
+ if (additionalRequired.size > 0) {
538
+ const t = additionalPropertiesType;
539
+ if (t === undefined) {
540
+ return (0, Messages_1.messageError)("SchemaAdditionalTypesForbidRequired", withRef(loc));
515
541
  }
516
- typeForCanonicalRef.set(loc.canonicalRef, t);
517
- }
518
- function makeObject(loc, attributes, properties, requiredArray, additionalProperties, sortKey = (k) => k.toLowerCase()) {
519
- return __awaiter(this, void 0, void 0, function* () {
520
- const required = new Set(requiredArray);
521
- const propertiesMap = collection_utils_1.mapSortBy(collection_utils_1.mapFromObject(properties), (_, k) => sortKey(k));
522
- const props = yield collection_utils_1.mapMapSync(propertiesMap, (propSchema, propName) => __awaiter(this, void 0, void 0, function* () {
523
- const propLoc = loc.push("properties", propName);
524
- const t = yield toType(checkJSONSchema(propSchema, propLoc.canonicalRef), propLoc, TypeNames_2.makeNamesTypeAttributes(propName, true));
525
- const isOptional = !required.has(propName);
526
- return typeBuilder.makeClassProperty(t, isOptional);
527
- }));
528
- let additionalPropertiesType;
529
- if (additionalProperties === undefined || additionalProperties === true) {
530
- additionalPropertiesType = typeBuilder.getPrimitiveType("any");
531
- }
532
- else if (additionalProperties === false) {
533
- additionalPropertiesType = undefined;
542
+ const additionalProps = (0, collection_utils_1.mapFromIterable)(additionalRequired, _name => typeBuilder.makeClassProperty(t, false));
543
+ (0, collection_utils_1.mapMergeInto)(props, additionalProps);
544
+ }
545
+ return typeBuilder.getUniqueObjectType(attributes, props, additionalPropertiesType);
546
+ }
547
+ async function convertToType(schema, loc, typeAttributes) {
548
+ const enumArray = Array.isArray(schema.enum) ? schema.enum : undefined;
549
+ const typeSet = (0, collection_utils_1.definedMap)(schema.type, t => checkTypeList(t, loc));
550
+ function isTypeIncluded(name) {
551
+ if (typeSet !== undefined && !typeSet.has(name)) {
552
+ return false;
553
+ }
554
+ if (enumArray !== undefined) {
555
+ let predicate;
556
+ switch (name) {
557
+ case "null":
558
+ predicate = (x) => x === null;
559
+ break;
560
+ case "integer":
561
+ predicate = (x) => typeof x === "number" && x === Math.floor(x);
562
+ break;
563
+ default:
564
+ predicate = (x) => typeof x === name;
565
+ break;
534
566
  }
535
- else {
536
- const additionalLoc = loc.push("additionalProperties");
537
- additionalPropertiesType = yield toType(checkJSONSchema(additionalProperties, additionalLoc.canonicalRef), additionalLoc, TypeNames_2.singularizeTypeNames(attributes));
567
+ return enumArray.find(predicate) !== undefined;
568
+ }
569
+ return true;
570
+ }
571
+ const includedTypes = (0, collection_utils_1.setFilter)(schemaTypes, isTypeIncluded);
572
+ let producedAttributesForNoCases = undefined;
573
+ function forEachProducedAttribute(cases, f) {
574
+ let attributes;
575
+ if (cases === undefined && producedAttributesForNoCases !== undefined) {
576
+ attributes = producedAttributesForNoCases;
577
+ }
578
+ else {
579
+ attributes = [];
580
+ for (const producer of attributeProducers) {
581
+ const newAttributes = producer(schema, loc.canonicalRef, includedTypes, cases);
582
+ if (newAttributes === undefined)
583
+ continue;
584
+ attributes.push(newAttributes);
538
585
  }
539
- const additionalRequired = collection_utils_1.setSubtract(required, props.keys());
540
- if (additionalRequired.size > 0) {
541
- const t = additionalPropertiesType;
542
- if (t === undefined) {
543
- return Messages_1.messageError("SchemaAdditionalTypesForbidRequired", withRef(loc));
544
- }
545
- const additionalProps = collection_utils_1.mapFromIterable(additionalRequired, _name => typeBuilder.makeClassProperty(t, false));
546
- collection_utils_1.mapMergeInto(props, additionalProps);
586
+ if (cases === undefined) {
587
+ producedAttributesForNoCases = attributes;
547
588
  }
548
- return typeBuilder.getUniqueObjectType(attributes, props, additionalPropertiesType);
589
+ }
590
+ for (const a of attributes) {
591
+ f(a);
592
+ }
593
+ }
594
+ function combineProducedAttributes(f) {
595
+ let result = TypeAttributes_1.emptyTypeAttributes;
596
+ forEachProducedAttribute(undefined, attr => {
597
+ const maybeAttributes = f(attr);
598
+ if (maybeAttributes === undefined)
599
+ return;
600
+ result = (0, TypeAttributes_1.combineTypeAttributes)("union", result, maybeAttributes);
549
601
  });
602
+ return result;
550
603
  }
551
- function convertToType(schema, loc, typeAttributes) {
552
- return __awaiter(this, void 0, void 0, function* () {
553
- const enumArray = Array.isArray(schema.enum) ? schema.enum : undefined;
554
- const typeSet = collection_utils_1.definedMap(schema.type, t => checkTypeList(t, loc));
555
- function isTypeIncluded(name) {
556
- if (typeSet !== undefined && !typeSet.has(name)) {
557
- return false;
558
- }
559
- if (enumArray !== undefined) {
560
- let predicate;
561
- switch (name) {
562
- case "null":
563
- predicate = (x) => x === null;
564
- break;
565
- case "integer":
566
- predicate = (x) => typeof x === "number" && x === Math.floor(x);
567
- break;
568
- default:
569
- predicate = (x) => typeof x === name;
570
- break;
571
- }
572
- return enumArray.find(predicate) !== undefined;
573
- }
574
- return true;
575
- }
576
- const includedTypes = collection_utils_1.setFilter(schemaTypes, isTypeIncluded);
577
- let producedAttributesForNoCases = undefined;
578
- function forEachProducedAttribute(cases, f) {
579
- let attributes;
580
- if (cases === undefined && producedAttributesForNoCases !== undefined) {
581
- attributes = producedAttributesForNoCases;
582
- }
583
- else {
584
- attributes = [];
585
- for (const producer of attributeProducers) {
586
- const newAttributes = producer(schema, loc.canonicalRef, includedTypes, cases);
587
- if (newAttributes === undefined)
588
- continue;
589
- attributes.push(newAttributes);
590
- }
591
- if (cases === undefined) {
592
- producedAttributesForNoCases = attributes;
593
- }
594
- }
595
- for (const a of attributes) {
596
- f(a);
597
- }
598
- }
599
- function combineProducedAttributes(f) {
600
- let result = TypeAttributes_1.emptyTypeAttributes;
601
- forEachProducedAttribute(undefined, attr => {
602
- const maybeAttributes = f(attr);
603
- if (maybeAttributes === undefined)
604
- return;
605
- result = TypeAttributes_1.combineTypeAttributes("union", result, maybeAttributes);
606
- });
607
- return result;
604
+ function makeAttributes(attributes) {
605
+ if (schema.oneOf === undefined) {
606
+ attributes = (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, combineProducedAttributes(({ forType, forUnion, forCases }) => {
607
+ (0, Support_1.assert)(forUnion === undefined && forCases === undefined, "We can't have attributes for unions and cases if we don't have a union");
608
+ return forType;
609
+ }));
610
+ }
611
+ return (0, TypeNames_2.modifyTypeNames)(attributes, maybeTypeNames => {
612
+ const typeNames = (0, Support_1.defined)(maybeTypeNames);
613
+ if (!typeNames.areInferred) {
614
+ return typeNames;
608
615
  }
609
- function makeAttributes(attributes) {
610
- if (schema.oneOf === undefined) {
611
- attributes = TypeAttributes_1.combineTypeAttributes("union", attributes, combineProducedAttributes(({ forType, forUnion, forCases }) => {
612
- Support_1.assert(forUnion === undefined && forCases === undefined, "We can't have attributes for unions and cases if we don't have a union");
613
- return forType;
614
- }));
615
- }
616
- return TypeNames_2.modifyTypeNames(attributes, maybeTypeNames => {
617
- const typeNames = Support_1.defined(maybeTypeNames);
618
- if (!typeNames.areInferred) {
619
- return typeNames;
620
- }
621
- let title = schema.title;
622
- if (typeof title !== "string") {
623
- title = loc.canonicalRef.definitionName;
624
- }
625
- if (typeof title === "string") {
626
- return TypeNames_1.TypeNames.make(new Set([title]), new Set(), schema.$ref !== undefined);
627
- }
628
- else {
629
- return typeNames.makeInferred();
630
- }
631
- });
616
+ let title = schema.title;
617
+ if (typeof title !== "string") {
618
+ title = loc.canonicalRef.definitionName;
632
619
  }
633
- typeAttributes = makeAttributes(typeAttributes);
634
- const inferredAttributes = TypeAttributes_1.makeTypeAttributesInferred(typeAttributes);
635
- function makeStringType(attributes) {
636
- const kind = typeKindForJSONSchemaFormat(schema.format);
637
- if (kind === undefined) {
638
- return typeBuilder.getStringType(attributes, StringTypes_1.StringTypes.unrestricted);
639
- }
640
- else {
641
- return typeBuilder.getPrimitiveType(kind, attributes);
642
- }
620
+ if (typeof title === "string") {
621
+ return TypeNames_1.TypeNames.make(new Set([title]), new Set(), schema.$ref !== undefined);
643
622
  }
644
- function makeArrayType() {
645
- return __awaiter(this, void 0, void 0, function* () {
646
- const singularAttributes = TypeNames_2.singularizeTypeNames(typeAttributes);
647
- const items = schema.items;
648
- let itemType;
649
- if (Array.isArray(items)) {
650
- const itemsLoc = loc.push("items");
651
- const itemTypes = yield collection_utils_1.arrayMapSync(items, (item, i) => __awaiter(this, void 0, void 0, function* () {
652
- const itemLoc = itemsLoc.push(i.toString());
653
- return yield toType(checkJSONSchema(item, itemLoc.canonicalRef), itemLoc, singularAttributes);
654
- }));
655
- itemType = typeBuilder.getUnionType(TypeAttributes_1.emptyTypeAttributes, new Set(itemTypes));
656
- }
657
- else if (typeof items === "object") {
658
- const itemsLoc = loc.push("items");
659
- itemType = yield toType(checkJSONSchema(items, itemsLoc.canonicalRef), itemsLoc, singularAttributes);
660
- }
661
- else if (items !== undefined) {
662
- return Messages_1.messageError("SchemaArrayItemsMustBeStringOrArray", withRef(loc, { actual: items }));
663
- }
664
- else {
665
- itemType = typeBuilder.getPrimitiveType("any");
666
- }
667
- typeBuilder.addAttributes(itemType, singularAttributes);
668
- return typeBuilder.getArrayType(TypeAttributes_1.emptyTypeAttributes, itemType);
669
- });
670
- }
671
- function makeObjectType() {
672
- return __awaiter(this, void 0, void 0, function* () {
673
- let required;
674
- if (schema.required === undefined || typeof schema.required === "boolean") {
675
- required = [];
676
- }
677
- else {
678
- required = Array.from(checkRequiredArray(schema.required, loc));
679
- }
680
- let properties;
681
- if (schema.properties === undefined) {
682
- properties = {};
683
- }
684
- else {
685
- properties = checkJSONSchemaObject(schema.properties, loc.canonicalRef);
686
- }
687
- // In Schema Draft 3, `required` is `true` on a property that's required.
688
- for (const p of Object.getOwnPropertyNames(properties)) {
689
- if (properties[p].required === true && required.indexOf(p) < 0) {
690
- required.push(p);
691
- }
692
- }
693
- let additionalProperties = schema.additionalProperties;
694
- // This is an incorrect hack to fix an issue with a Go->Schema generator:
695
- // https://github.com/quicktype/quicktype/issues/976
696
- if (additionalProperties === undefined &&
697
- typeof schema.patternProperties === "object" &&
698
- collection_utils_1.hasOwnProperty(schema.patternProperties, ".*")) {
699
- additionalProperties = schema.patternProperties[".*"];
700
- }
701
- const objectAttributes = TypeAttributes_1.combineTypeAttributes("union", inferredAttributes, combineProducedAttributes(({ forObject }) => forObject));
702
- const order = schema.quicktypePropertyOrder ? schema.quicktypePropertyOrder : [];
703
- const orderKey = (propertyName) => {
704
- // use the index of the order array
705
- const index = order.indexOf(propertyName);
706
- // if no index then use the property name
707
- return index !== -1 ? index : propertyName.toLowerCase();
708
- };
709
- return yield makeObject(loc, objectAttributes, properties, required, additionalProperties, orderKey);
710
- });
711
- }
712
- function makeTypesFromCases(cases, kind) {
713
- return __awaiter(this, void 0, void 0, function* () {
714
- const kindLoc = loc.push(kind);
715
- if (!Array.isArray(cases)) {
716
- return Messages_1.messageError("SchemaSetOperationCasesIsNotArray", withRef(kindLoc, { operation: kind, cases }));
717
- }
718
- // FIXME: This cast shouldn't be necessary, but TypeScript forces our hand.
719
- return yield collection_utils_1.arrayMapSync(cases, (t, index) => __awaiter(this, void 0, void 0, function* () {
720
- const caseLoc = kindLoc.push(index.toString());
721
- return yield toType(checkJSONSchema(t, caseLoc.canonicalRef), caseLoc, TypeAttributes_1.makeTypeAttributesInferred(typeAttributes));
722
- }));
723
- });
623
+ else {
624
+ return typeNames.makeInferred();
724
625
  }
725
- const intersectionType = typeBuilder.getUniqueIntersectionType(typeAttributes, undefined);
726
- setTypeForLocation(loc, intersectionType);
727
- function convertOneOrAnyOf(cases, kind) {
728
- return __awaiter(this, void 0, void 0, function* () {
729
- const typeRefs = yield makeTypesFromCases(cases, kind);
730
- let unionAttributes = TypeAttributes_1.makeTypeAttributesInferred(typeAttributes);
731
- if (kind === "oneOf") {
732
- forEachProducedAttribute(cases, ({ forType, forUnion, forCases }) => {
733
- if (forType !== undefined) {
734
- typeBuilder.addAttributes(intersectionType, forType);
735
- }
736
- if (forUnion !== undefined) {
737
- unionAttributes = TypeAttributes_1.combineTypeAttributes("union", unionAttributes, forUnion);
738
- }
739
- if (forCases !== undefined) {
740
- Support_1.assert(forCases.length === typeRefs.length, "Number of case attributes doesn't match number of cases");
741
- for (let i = 0; i < typeRefs.length; i++) {
742
- typeBuilder.addAttributes(typeRefs[i], forCases[i]);
743
- }
744
- }
745
- });
746
- }
747
- const unionType = typeBuilder.getUniqueUnionType(unionAttributes, undefined);
748
- typeBuilder.setSetOperationMembers(unionType, new Set(typeRefs));
749
- return unionType;
750
- });
626
+ });
627
+ }
628
+ typeAttributes = makeAttributes(typeAttributes);
629
+ const inferredAttributes = (0, TypeAttributes_1.makeTypeAttributesInferred)(typeAttributes);
630
+ function makeStringType(attributes) {
631
+ const kind = typeKindForJSONSchemaFormat(schema.format);
632
+ if (kind === undefined) {
633
+ return typeBuilder.getStringType(attributes, StringTypes_1.StringTypes.unrestricted);
634
+ }
635
+ else {
636
+ return typeBuilder.getPrimitiveType(kind, attributes);
637
+ }
638
+ }
639
+ async function makeArrayType() {
640
+ const singularAttributes = (0, TypeNames_2.singularizeTypeNames)(typeAttributes);
641
+ const items = schema.items;
642
+ let itemType;
643
+ if (Array.isArray(items)) {
644
+ const itemsLoc = loc.push("items");
645
+ const itemTypes = await (0, collection_utils_1.arrayMapSync)(items, async (item, i) => {
646
+ const itemLoc = itemsLoc.push(i.toString());
647
+ return await toType(checkJSONSchema(item, itemLoc.canonicalRef), itemLoc, singularAttributes);
648
+ });
649
+ itemType = typeBuilder.getUnionType(TypeAttributes_1.emptyTypeAttributes, new Set(itemTypes));
650
+ }
651
+ else if (typeof items === "object") {
652
+ const itemsLoc = loc.push("items");
653
+ itemType = await toType(checkJSONSchema(items, itemsLoc.canonicalRef), itemsLoc, singularAttributes);
654
+ }
655
+ else if (items !== undefined) {
656
+ return (0, Messages_1.messageError)("SchemaArrayItemsMustBeStringOrArray", withRef(loc, { actual: items }));
657
+ }
658
+ else {
659
+ itemType = typeBuilder.getPrimitiveType("any");
660
+ }
661
+ typeBuilder.addAttributes(itemType, singularAttributes);
662
+ return typeBuilder.getArrayType(TypeAttributes_1.emptyTypeAttributes, itemType);
663
+ }
664
+ async function makeObjectType() {
665
+ let required;
666
+ if (schema.required === undefined || typeof schema.required === "boolean") {
667
+ required = [];
668
+ }
669
+ else {
670
+ required = Array.from(checkRequiredArray(schema.required, loc));
671
+ }
672
+ let properties;
673
+ if (schema.properties === undefined) {
674
+ properties = {};
675
+ }
676
+ else {
677
+ properties = checkJSONSchemaObject(schema.properties, loc.canonicalRef);
678
+ }
679
+ // In Schema Draft 3, `required` is `true` on a property that's required.
680
+ for (const p of Object.getOwnPropertyNames(properties)) {
681
+ if (properties[p].required === true && required.indexOf(p) < 0) {
682
+ required.push(p);
751
683
  }
752
- const includeObject = enumArray === undefined && (typeSet === undefined || typeSet.has("object"));
753
- const includeArray = enumArray === undefined && (typeSet === undefined || typeSet.has("array"));
754
- const needStringEnum = includedTypes.has("string") &&
755
- enumArray !== undefined &&
756
- enumArray.find((x) => typeof x === "string") !== undefined;
757
- const needUnion = typeSet !== undefined ||
758
- schema.properties !== undefined ||
759
- schema.additionalProperties !== undefined ||
760
- schema.items !== undefined ||
761
- schema.required !== undefined ||
762
- enumArray !== undefined;
763
- const types = [];
764
- if (needUnion) {
765
- const unionTypes = [];
766
- const numberAttributes = combineProducedAttributes(({ forNumber }) => forNumber);
767
- for (const [name, kind] of [
768
- ["null", "null"],
769
- ["number", "double"],
770
- ["integer", "integer"],
771
- ["boolean", "bool"]
772
- ]) {
773
- if (!includedTypes.has(name))
774
- continue;
775
- const attributes = Type_1.isNumberTypeKind(kind) ? numberAttributes : undefined;
776
- unionTypes.push(typeBuilder.getPrimitiveType(kind, attributes));
777
- }
778
- const stringAttributes = TypeAttributes_1.combineTypeAttributes("union", inferredAttributes, combineProducedAttributes(({ forString }) => forString));
779
- if (needStringEnum) {
780
- const cases = enumArray.filter(x => typeof x === "string");
781
- unionTypes.push(typeBuilder.getStringType(stringAttributes, StringTypes_1.StringTypes.fromCases(cases)));
782
- }
783
- else if (includedTypes.has("string")) {
784
- unionTypes.push(makeStringType(stringAttributes));
785
- }
786
- if (includeArray) {
787
- unionTypes.push(yield makeArrayType());
684
+ }
685
+ let additionalProperties = schema.additionalProperties;
686
+ // This is an incorrect hack to fix an issue with a Go->Schema generator:
687
+ // https://github.com/quicktype/quicktype/issues/976
688
+ if (additionalProperties === undefined &&
689
+ typeof schema.patternProperties === "object" &&
690
+ (0, collection_utils_1.hasOwnProperty)(schema.patternProperties, ".*")) {
691
+ additionalProperties = schema.patternProperties[".*"];
692
+ }
693
+ const objectAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", inferredAttributes, combineProducedAttributes(({ forObject }) => forObject));
694
+ const order = schema.quicktypePropertyOrder ? schema.quicktypePropertyOrder : [];
695
+ const orderKey = (propertyName) => {
696
+ // use the index of the order array
697
+ const index = order.indexOf(propertyName);
698
+ // if no index then use the property name
699
+ return index !== -1 ? index : propertyName.toLowerCase();
700
+ };
701
+ return await makeObject(loc, objectAttributes, properties, required, additionalProperties, orderKey);
702
+ }
703
+ async function makeTypesFromCases(cases, kind) {
704
+ const kindLoc = loc.push(kind);
705
+ if (!Array.isArray(cases)) {
706
+ return (0, Messages_1.messageError)("SchemaSetOperationCasesIsNotArray", withRef(kindLoc, { operation: kind, cases }));
707
+ }
708
+ // FIXME: This cast shouldn't be necessary, but TypeScript forces our hand.
709
+ return await (0, collection_utils_1.arrayMapSync)(cases, async (t, index) => {
710
+ const caseLoc = kindLoc.push(index.toString());
711
+ return await toType(checkJSONSchema(t, caseLoc.canonicalRef), caseLoc, (0, TypeAttributes_1.makeTypeAttributesInferred)(typeAttributes));
712
+ });
713
+ }
714
+ const intersectionType = typeBuilder.getUniqueIntersectionType(typeAttributes, undefined);
715
+ setTypeForLocation(loc, intersectionType);
716
+ async function convertOneOrAnyOf(cases, kind) {
717
+ const typeRefs = await makeTypesFromCases(cases, kind);
718
+ let unionAttributes = (0, TypeAttributes_1.makeTypeAttributesInferred)(typeAttributes);
719
+ if (kind === "oneOf") {
720
+ forEachProducedAttribute(cases, ({ forType, forUnion, forCases }) => {
721
+ if (forType !== undefined) {
722
+ typeBuilder.addAttributes(intersectionType, forType);
788
723
  }
789
- if (includeObject) {
790
- unionTypes.push(yield makeObjectType());
724
+ if (forUnion !== undefined) {
725
+ unionAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", unionAttributes, forUnion);
791
726
  }
792
- types.push(typeBuilder.getUniqueUnionType(inferredAttributes, new Set(unionTypes)));
793
- }
794
- if (schema.$ref !== undefined) {
795
- if (typeof schema.$ref !== "string") {
796
- return Messages_1.messageError("SchemaRefMustBeString", withRef(loc, { actual: typeof schema.$ref }));
727
+ if (forCases !== undefined) {
728
+ (0, Support_1.assert)(forCases.length === typeRefs.length, "Number of case attributes doesn't match number of cases");
729
+ for (let i = 0; i < typeRefs.length; i++) {
730
+ typeBuilder.addAttributes(typeRefs[i], forCases[i]);
731
+ }
797
732
  }
798
- const virtualRef = Ref.parse(schema.$ref);
799
- const [target, newLoc] = yield resolver.resolveVirtualRef(loc, virtualRef);
800
- const attributes = TypeNames_2.modifyTypeNames(typeAttributes, tn => {
801
- if (!Support_1.defined(tn).areInferred)
802
- return tn;
803
- return TypeNames_1.TypeNames.make(new Set([newLoc.canonicalRef.name]), new Set(), true);
804
- });
805
- types.push(yield toType(target, newLoc, attributes));
806
- }
807
- if (schema.allOf !== undefined) {
808
- types.push(...(yield makeTypesFromCases(schema.allOf, "allOf")));
809
- }
810
- if (schema.oneOf !== undefined) {
811
- types.push(yield convertOneOrAnyOf(schema.oneOf, "oneOf"));
812
- }
813
- if (schema.anyOf !== undefined) {
814
- types.push(yield convertOneOrAnyOf(schema.anyOf, "anyOf"));
815
- }
816
- typeBuilder.setSetOperationMembers(intersectionType, new Set(types));
817
- return intersectionType;
818
- });
733
+ });
734
+ }
735
+ const unionType = typeBuilder.getUniqueUnionType(unionAttributes, undefined);
736
+ typeBuilder.setSetOperationMembers(unionType, new Set(typeRefs));
737
+ return unionType;
819
738
  }
820
- function toType(schema, loc, typeAttributes) {
821
- return __awaiter(this, void 0, void 0, function* () {
822
- const maybeType = typeForCanonicalRef.get(loc.canonicalRef);
823
- if (maybeType !== undefined) {
824
- return maybeType;
825
- }
826
- let result;
827
- if (typeof schema === "boolean") {
828
- // FIXME: Empty union. We'd have to check that it's supported everywhere,
829
- // in particular in union flattening.
830
- Messages_1.messageAssert(schema === true, "SchemaFalseNotSupported", withRef(loc));
831
- result = typeBuilder.getPrimitiveType("any");
832
- }
833
- else {
834
- loc = loc.updateWithID(schema["$id"]);
835
- result = yield convertToType(schema, loc, typeAttributes);
836
- }
837
- setTypeForLocation(loc, result);
838
- return result;
739
+ const includeObject = enumArray === undefined && (typeSet === undefined || typeSet.has("object"));
740
+ const includeArray = enumArray === undefined && (typeSet === undefined || typeSet.has("array"));
741
+ const needStringEnum = includedTypes.has("string") &&
742
+ enumArray !== undefined &&
743
+ enumArray.find((x) => typeof x === "string") !== undefined;
744
+ const needUnion = typeSet !== undefined ||
745
+ schema.properties !== undefined ||
746
+ schema.additionalProperties !== undefined ||
747
+ schema.items !== undefined ||
748
+ schema.required !== undefined ||
749
+ enumArray !== undefined;
750
+ const types = [];
751
+ if (needUnion) {
752
+ const unionTypes = [];
753
+ const numberAttributes = combineProducedAttributes(({ forNumber }) => forNumber);
754
+ for (const [name, kind] of [
755
+ ["null", "null"],
756
+ ["number", "double"],
757
+ ["integer", "integer"],
758
+ ["boolean", "bool"]
759
+ ]) {
760
+ if (!includedTypes.has(name))
761
+ continue;
762
+ const attributes = (0, Type_1.isNumberTypeKind)(kind) ? numberAttributes : undefined;
763
+ unionTypes.push(typeBuilder.getPrimitiveType(kind, attributes));
764
+ }
765
+ const stringAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", inferredAttributes, combineProducedAttributes(({ forString }) => forString));
766
+ if (needStringEnum) {
767
+ const cases = enumArray.filter(x => typeof x === "string");
768
+ unionTypes.push(typeBuilder.getStringType(stringAttributes, StringTypes_1.StringTypes.fromCases(cases)));
769
+ }
770
+ else if (includedTypes.has("string")) {
771
+ unionTypes.push(makeStringType(stringAttributes));
772
+ }
773
+ if (includeArray) {
774
+ unionTypes.push(await makeArrayType());
775
+ }
776
+ if (includeObject) {
777
+ unionTypes.push(await makeObjectType());
778
+ }
779
+ types.push(typeBuilder.getUniqueUnionType(inferredAttributes, new Set(unionTypes)));
780
+ }
781
+ if (schema.$ref !== undefined) {
782
+ if (typeof schema.$ref !== "string") {
783
+ return (0, Messages_1.messageError)("SchemaRefMustBeString", withRef(loc, { actual: typeof schema.$ref }));
784
+ }
785
+ const virtualRef = Ref.parse(schema.$ref);
786
+ const [target, newLoc] = await resolver.resolveVirtualRef(loc, virtualRef);
787
+ const attributes = (0, TypeNames_2.modifyTypeNames)(typeAttributes, tn => {
788
+ if (!(0, Support_1.defined)(tn).areInferred)
789
+ return tn;
790
+ return TypeNames_1.TypeNames.make(new Set([newLoc.canonicalRef.name]), new Set(), true);
839
791
  });
792
+ types.push(await toType(target, newLoc, attributes));
793
+ }
794
+ if (schema.allOf !== undefined) {
795
+ types.push(...(await makeTypesFromCases(schema.allOf, "allOf")));
796
+ }
797
+ if (schema.oneOf !== undefined) {
798
+ types.push(await convertOneOrAnyOf(schema.oneOf, "oneOf"));
799
+ }
800
+ if (schema.anyOf !== undefined) {
801
+ types.push(await convertOneOrAnyOf(schema.anyOf, "anyOf"));
802
+ }
803
+ typeBuilder.setSetOperationMembers(intersectionType, new Set(types));
804
+ return intersectionType;
805
+ }
806
+ async function toType(schema, loc, typeAttributes) {
807
+ const maybeType = typeForCanonicalRef.get(loc.canonicalRef);
808
+ if (maybeType !== undefined) {
809
+ return maybeType;
810
+ }
811
+ let result;
812
+ if (typeof schema === "boolean") {
813
+ // FIXME: Empty union. We'd have to check that it's supported everywhere,
814
+ // in particular in union flattening.
815
+ (0, Messages_1.messageAssert)(schema === true, "SchemaFalseNotSupported", withRef(loc));
816
+ result = typeBuilder.getPrimitiveType("any");
840
817
  }
841
- for (const [topLevelName, topLevelRef] of references) {
842
- const [target, loc] = yield resolver.resolveTopLevelRef(topLevelRef);
843
- const t = yield toType(target, loc, TypeNames_2.makeNamesTypeAttributes(topLevelName, false));
844
- typeBuilder.addTopLevel(topLevelName, t);
818
+ else {
819
+ loc = loc.updateWithID(schema["$id"]);
820
+ result = await convertToType(schema, loc, typeAttributes);
845
821
  }
846
- });
822
+ setTypeForLocation(loc, result);
823
+ return result;
824
+ }
825
+ for (const [topLevelName, topLevelRef] of references) {
826
+ const [target, loc] = await resolver.resolveTopLevelRef(topLevelRef);
827
+ const t = await toType(target, loc, (0, TypeNames_2.makeNamesTypeAttributes)(topLevelName, false));
828
+ typeBuilder.addTopLevel(topLevelName, t);
829
+ }
847
830
  }
848
831
  function removeExtension(fn) {
849
832
  const lower = fn.toLowerCase();
@@ -874,68 +857,69 @@ function nameFromURI(uri) {
874
857
  if (filename !== "") {
875
858
  return removeExtension(filename);
876
859
  }
877
- return Messages_1.messageError("DriverCannotInferNameForSchema", { uri: uri.toString() });
860
+ return (0, Messages_1.messageError)("DriverCannotInferNameForSchema", { uri: uri.toString() });
878
861
  }
879
- function refsInSchemaForURI(resolver, uri, defaultName) {
880
- return __awaiter(this, void 0, void 0, function* () {
881
- const fragment = uri.fragment();
882
- let propertiesAreTypes = fragment.endsWith("/");
883
- if (propertiesAreTypes) {
884
- uri = uri.clone().fragment(fragment.slice(0, -1));
885
- }
886
- const ref = Ref.parseURI(uri);
887
- if (ref.isRoot) {
888
- propertiesAreTypes = false;
889
- }
890
- const schema = (yield resolver.resolveTopLevelRef(ref))[0];
891
- if (propertiesAreTypes) {
892
- if (typeof schema !== "object") {
893
- return Messages_1.messageError("SchemaCannotGetTypesFromBoolean", { ref: ref.toString() });
894
- }
895
- return collection_utils_1.mapMap(collection_utils_1.mapFromObject(schema), (_, name) => ref.push(name));
862
+ async function refsInSchemaForURI(resolver, uri, defaultName) {
863
+ const fragment = uri.fragment();
864
+ let propertiesAreTypes = fragment.endsWith("/");
865
+ if (propertiesAreTypes) {
866
+ uri = uri.clone().fragment(fragment.slice(0, -1));
867
+ }
868
+ const ref = Ref.parseURI(uri);
869
+ if (ref.isRoot) {
870
+ propertiesAreTypes = false;
871
+ }
872
+ const schema = (await resolver.resolveTopLevelRef(ref))[0];
873
+ if (propertiesAreTypes) {
874
+ if (typeof schema !== "object") {
875
+ return (0, Messages_1.messageError)("SchemaCannotGetTypesFromBoolean", { ref: ref.toString() });
876
+ }
877
+ return (0, collection_utils_1.mapMap)((0, collection_utils_1.mapFromObject)(schema), (_, name) => ref.push(name));
878
+ }
879
+ else {
880
+ let name;
881
+ if (typeof schema === "object" && typeof schema.title === "string") {
882
+ name = schema.title;
896
883
  }
897
884
  else {
898
- let name;
899
- if (typeof schema === "object" && typeof schema.title === "string") {
900
- name = schema.title;
901
- }
902
- else {
903
- const maybeName = nameFromURI(uri);
904
- name = maybeName !== undefined ? maybeName : defaultName;
905
- }
906
- return [name, ref];
885
+ const maybeName = nameFromURI(uri);
886
+ name = maybeName !== undefined ? maybeName : defaultName;
907
887
  }
908
- });
888
+ return [name, ref];
889
+ }
909
890
  }
910
891
  class InputJSONSchemaStore extends JSONSchemaStore_1.JSONSchemaStore {
892
+ _inputs;
893
+ _delegate;
911
894
  constructor(_inputs, _delegate) {
912
895
  super();
913
896
  this._inputs = _inputs;
914
897
  this._delegate = _delegate;
915
898
  }
916
- fetch(address) {
917
- return __awaiter(this, void 0, void 0, function* () {
918
- const maybeInput = this._inputs.get(address);
919
- if (maybeInput !== undefined) {
920
- return checkJSONSchema(Support_1.parseJSON(maybeInput, "JSON Schema", address), () => Ref.root(address));
921
- }
922
- if (this._delegate === undefined) {
923
- return Support_1.panic(`Schema URI ${address} requested, but no store given`);
924
- }
925
- return yield this._delegate.fetch(address);
926
- });
899
+ async fetch(address) {
900
+ const maybeInput = this._inputs.get(address);
901
+ if (maybeInput !== undefined) {
902
+ return checkJSONSchema((0, Support_1.parseJSON)(maybeInput, "JSON Schema", address), () => Ref.root(address));
903
+ }
904
+ if (this._delegate === undefined) {
905
+ return (0, Support_1.panic)(`Schema URI ${address} requested, but no store given`);
906
+ }
907
+ return await this._delegate.fetch(address);
927
908
  }
928
909
  }
929
910
  class JSONSchemaInput {
911
+ _schemaStore;
912
+ _additionalSchemaAddresses;
913
+ kind = "schema";
914
+ needSchemaProcessing = true;
915
+ _attributeProducers;
916
+ _schemaInputs = new Map();
917
+ _schemaSources = [];
918
+ _topLevels = new Map();
919
+ _needIR = false;
930
920
  constructor(_schemaStore, additionalAttributeProducers = [], _additionalSchemaAddresses = []) {
931
921
  this._schemaStore = _schemaStore;
932
922
  this._additionalSchemaAddresses = _additionalSchemaAddresses;
933
- this.kind = "schema";
934
- this.needSchemaProcessing = true;
935
- this._schemaInputs = new Map();
936
- this._schemaSources = [];
937
- this._topLevels = new Map();
938
- this._needIR = false;
939
923
  this._attributeProducers = [
940
924
  Description_1.descriptionAttributeProducer,
941
925
  AccessorNames_1.accessorNamesAttributeProducer,
@@ -952,58 +936,54 @@ class JSONSchemaInput {
952
936
  addTopLevel(name, ref) {
953
937
  this._topLevels.set(name, ref);
954
938
  }
955
- addTypes(ctx, typeBuilder) {
956
- return __awaiter(this, void 0, void 0, function* () {
957
- if (this._schemaSources.length === 0)
958
- return;
959
- let maybeSchemaStore = this._schemaStore;
960
- if (this._schemaInputs.size === 0) {
961
- if (maybeSchemaStore === undefined) {
962
- return Support_1.panic("Must have a schema store to process JSON Schema");
963
- }
964
- }
965
- else {
966
- maybeSchemaStore = this._schemaStore = new InputJSONSchemaStore(this._schemaInputs, maybeSchemaStore);
939
+ async addTypes(ctx, typeBuilder) {
940
+ if (this._schemaSources.length === 0)
941
+ return;
942
+ let maybeSchemaStore = this._schemaStore;
943
+ if (this._schemaInputs.size === 0) {
944
+ if (maybeSchemaStore === undefined) {
945
+ return (0, Support_1.panic)("Must have a schema store to process JSON Schema");
967
946
  }
968
- const schemaStore = maybeSchemaStore;
969
- const canonizer = new Canonizer(ctx);
970
- for (const address of this._additionalSchemaAddresses) {
971
- const schema = yield schemaStore.get(address, ctx.debugPrintSchemaResolving);
972
- if (schema === undefined) {
973
- return Messages_1.messageError("SchemaFetchErrorAdditional", { address });
974
- }
975
- canonizer.addSchema(schema, address);
947
+ }
948
+ else {
949
+ maybeSchemaStore = this._schemaStore = new InputJSONSchemaStore(this._schemaInputs, maybeSchemaStore);
950
+ }
951
+ const schemaStore = maybeSchemaStore;
952
+ const canonizer = new Canonizer(ctx);
953
+ for (const address of this._additionalSchemaAddresses) {
954
+ const schema = await schemaStore.get(address, ctx.debugPrintSchemaResolving);
955
+ if (schema === undefined) {
956
+ return (0, Messages_1.messageError)("SchemaFetchErrorAdditional", { address });
976
957
  }
977
- const resolver = new Resolver(ctx, Support_1.defined(this._schemaStore), canonizer);
978
- for (const [normalizedURI, source] of this._schemaSources) {
979
- const givenName = source.name;
980
- const refs = yield refsInSchemaForURI(resolver, normalizedURI, givenName);
981
- if (Array.isArray(refs)) {
982
- let name;
983
- if (this._schemaSources.length === 1) {
984
- name = givenName;
985
- }
986
- else {
987
- name = refs[0];
988
- }
989
- this.addTopLevel(name, refs[1]);
958
+ canonizer.addSchema(schema, address);
959
+ }
960
+ const resolver = new Resolver(ctx, (0, Support_1.defined)(this._schemaStore), canonizer);
961
+ for (const [normalizedURI, source] of this._schemaSources) {
962
+ const givenName = source.name;
963
+ const refs = await refsInSchemaForURI(resolver, normalizedURI, givenName);
964
+ if (Array.isArray(refs)) {
965
+ let name;
966
+ if (this._schemaSources.length === 1) {
967
+ name = givenName;
990
968
  }
991
969
  else {
992
- for (const [refName, ref] of refs) {
993
- this.addTopLevel(refName, ref);
994
- }
970
+ name = refs[0];
995
971
  }
972
+ this.addTopLevel(name, refs[1]);
996
973
  }
997
- yield addTypesInSchema(resolver, typeBuilder, this._topLevels, this._attributeProducers);
998
- });
974
+ else {
975
+ for (const [refName, ref] of refs) {
976
+ this.addTopLevel(refName, ref);
977
+ }
978
+ }
979
+ }
980
+ await addTypesInSchema(resolver, typeBuilder, this._topLevels, this._attributeProducers);
999
981
  }
1000
982
  addTypesSync() {
1001
- return Support_1.panic("addTypesSync not supported in JSONSchemaInput");
983
+ return (0, Support_1.panic)("addTypesSync not supported in JSONSchemaInput");
1002
984
  }
1003
- addSource(schemaSource) {
1004
- return __awaiter(this, void 0, void 0, function* () {
1005
- return this.addSourceSync(schemaSource);
1006
- });
985
+ async addSource(schemaSource) {
986
+ return this.addSourceSync(schemaSource);
1007
987
  }
1008
988
  addSourceSync(schemaSource) {
1009
989
  const { name, uris, schema, isConverted } = schemaSource;
@@ -1012,7 +992,7 @@ class JSONSchemaInput {
1012
992
  }
1013
993
  let normalizedURIs;
1014
994
  if (uris === undefined) {
1015
- normalizedURIs = [new URI(name)];
995
+ normalizedURIs = [new urijs_1.default(name)];
1016
996
  }
1017
997
  else {
1018
998
  normalizedURIs = uris.map(uri => {
@@ -1024,7 +1004,7 @@ class JSONSchemaInput {
1024
1004
  });
1025
1005
  }
1026
1006
  if (schema === undefined) {
1027
- Support_1.assert(uris !== undefined, "URIs must be given if schema source is not specified");
1007
+ (0, Support_1.assert)(uris !== undefined, "URIs must be given if schema source is not specified");
1028
1008
  }
1029
1009
  else {
1030
1010
  for (let i = 0; i < normalizedURIs.length; i++) {
@@ -1053,7 +1033,7 @@ class JSONSchemaInput {
1053
1033
  }
1054
1034
  const set = new Set(this._schemaSources.map(([_, { schema }]) => schema));
1055
1035
  if (set.size === 1) {
1056
- return Support_1.defined(collection_utils_1.iterableFirst(set));
1036
+ return (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(set));
1057
1037
  }
1058
1038
  return undefined;
1059
1039
  }