quicktype 17.0.0 → 17.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/cli/CompressedJSONFromStream.js +38 -26
  2. package/dist/cli/GraphQLIntrospection.js +41 -33
  3. package/dist/cli/TypeSource.d.ts +1 -1
  4. package/dist/cli/URLGrammar.js +3 -4
  5. package/dist/cli/index.js +364 -363
  6. package/dist/quicktype-core/Annotation.js +0 -2
  7. package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
  8. package/dist/quicktype-core/ConvenienceRenderer.js +81 -104
  9. package/dist/quicktype-core/DateTime.js +0 -1
  10. package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
  11. package/dist/quicktype-core/DeclarationIR.js +10 -13
  12. package/dist/quicktype-core/EncodedMarkovChain.js +0 -1
  13. package/dist/quicktype-core/GatherNames.js +25 -47
  14. package/dist/quicktype-core/Graph.d.ts +2 -2
  15. package/dist/quicktype-core/Graph.js +19 -23
  16. package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
  17. package/dist/quicktype-core/GraphRewriting.js +54 -65
  18. package/dist/quicktype-core/MakeTransformations.js +22 -23
  19. package/dist/quicktype-core/MarkovChain.d.ts +3 -3
  20. package/dist/quicktype-core/MarkovChain.js +8 -9
  21. package/dist/quicktype-core/Messages.d.ts +3 -3
  22. package/dist/quicktype-core/Messages.js +3 -8
  23. package/dist/quicktype-core/Naming.d.ts +11 -11
  24. package/dist/quicktype-core/Naming.js +61 -76
  25. package/dist/quicktype-core/Renderer.d.ts +6 -6
  26. package/dist/quicktype-core/Renderer.js +17 -34
  27. package/dist/quicktype-core/RendererOptions.d.ts +5 -5
  28. package/dist/quicktype-core/RendererOptions.js +3 -6
  29. package/dist/quicktype-core/Run.d.ts +9 -9
  30. package/dist/quicktype-core/Run.js +67 -72
  31. package/dist/quicktype-core/Source.d.ts +3 -3
  32. package/dist/quicktype-core/Source.js +18 -19
  33. package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
  34. package/dist/quicktype-core/TargetLanguage.js +2 -6
  35. package/dist/quicktype-core/Transformers.d.ts +25 -25
  36. package/dist/quicktype-core/Transformers.js +66 -94
  37. package/dist/quicktype-core/Type.d.ts +43 -41
  38. package/dist/quicktype-core/Type.js +71 -96
  39. package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
  40. package/dist/quicktype-core/TypeBuilder.js +47 -53
  41. package/dist/quicktype-core/TypeGraph.d.ts +4 -4
  42. package/dist/quicktype-core/TypeGraph.js +40 -49
  43. package/dist/quicktype-core/TypeUtils.d.ts +2 -2
  44. package/dist/quicktype-core/TypeUtils.js +22 -23
  45. package/dist/quicktype-core/UnifyClasses.js +12 -16
  46. package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
  47. package/dist/quicktype-core/UnionBuilder.js +30 -33
  48. package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
  49. package/dist/quicktype-core/attributes/AccessorNames.js +17 -18
  50. package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
  51. package/dist/quicktype-core/attributes/Constraints.js +4 -8
  52. package/dist/quicktype-core/attributes/Description.js +5 -6
  53. package/dist/quicktype-core/attributes/EnumValues.js +3 -4
  54. package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
  55. package/dist/quicktype-core/attributes/StringTypes.js +21 -24
  56. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
  57. package/dist/quicktype-core/attributes/TypeAttributes.js +10 -12
  58. package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
  59. package/dist/quicktype-core/attributes/TypeNames.js +21 -49
  60. package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
  61. package/dist/quicktype-core/attributes/URIAttributes.js +6 -10
  62. package/dist/quicktype-core/index.js +125 -128
  63. package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
  64. package/dist/quicktype-core/input/CompressedJSON.js +54 -49
  65. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +13 -5
  66. package/dist/quicktype-core/input/Inference.d.ts +2 -2
  67. package/dist/quicktype-core/input/Inference.js +17 -25
  68. package/dist/quicktype-core/input/Inputs.d.ts +2 -2
  69. package/dist/quicktype-core/input/Inputs.js +54 -38
  70. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
  71. package/dist/quicktype-core/input/JSONSchemaInput.js +523 -503
  72. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
  73. package/dist/quicktype-core/input/JSONSchemaStore.js +35 -24
  74. package/dist/quicktype-core/input/PostmanCollection.js +1 -2
  75. package/dist/quicktype-core/input/io/NodeIO.js +44 -55
  76. package/dist/quicktype-core/input/io/get-stream/index.js +2 -6
  77. package/dist/quicktype-core/language/All.js +2 -3
  78. package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
  79. package/dist/quicktype-core/language/CPlusPlus.js +151 -185
  80. package/dist/quicktype-core/language/CSharp.d.ts +7 -7
  81. package/dist/quicktype-core/language/CSharp.js +72 -82
  82. package/dist/quicktype-core/language/Crystal.d.ts +2 -2
  83. package/dist/quicktype-core/language/Crystal.js +17 -18
  84. package/dist/quicktype-core/language/Dart.d.ts +4 -4
  85. package/dist/quicktype-core/language/Dart.js +34 -36
  86. package/dist/quicktype-core/language/Elm.d.ts +6 -6
  87. package/dist/quicktype-core/language/Elm.js +45 -47
  88. package/dist/quicktype-core/language/Golang.d.ts +4 -4
  89. package/dist/quicktype-core/language/Golang.js +20 -23
  90. package/dist/quicktype-core/language/Haskell.d.ts +5 -5
  91. package/dist/quicktype-core/language/Haskell.js +23 -25
  92. package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
  93. package/dist/quicktype-core/language/JSONSchema.js +16 -17
  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 +17 -19
  98. package/dist/quicktype-core/language/JavaScriptPropTypes.js +13 -15
  99. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +11 -12
  100. package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
  101. package/dist/quicktype-core/language/Kotlin.js +37 -39
  102. package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
  103. package/dist/quicktype-core/language/Objective-C.js +41 -45
  104. package/dist/quicktype-core/language/Php.d.ts +2 -2
  105. package/dist/quicktype-core/language/Php.js +41 -66
  106. package/dist/quicktype-core/language/Pike.d.ts +1 -1
  107. package/dist/quicktype-core/language/Pike.js +17 -18
  108. package/dist/quicktype-core/language/Python.d.ts +8 -8
  109. package/dist/quicktype-core/language/Python.js +64 -63
  110. package/dist/quicktype-core/language/Rust.d.ts +2 -2
  111. package/dist/quicktype-core/language/Rust.js +19 -21
  112. package/dist/quicktype-core/language/Swift.d.ts +7 -7
  113. package/dist/quicktype-core/language/Swift.js +804 -807
  114. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
  115. package/dist/quicktype-core/language/TypeScriptFlow.js +26 -28
  116. package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
  117. package/dist/quicktype-core/language/ruby/index.js +24 -49
  118. package/dist/quicktype-core/language/ruby/keywords.js +0 -1
  119. package/dist/quicktype-core/rewrites/CombineClasses.js +8 -9
  120. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
  121. package/dist/quicktype-core/rewrites/ExpandStrings.js +17 -18
  122. package/dist/quicktype-core/rewrites/FlattenStrings.js +6 -7
  123. package/dist/quicktype-core/rewrites/FlattenUnions.js +8 -9
  124. package/dist/quicktype-core/rewrites/InferMaps.js +10 -11
  125. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +7 -8
  126. package/dist/quicktype-core/rewrites/ResolveIntersections.js +67 -68
  127. package/dist/quicktype-core/support/Acronyms.js +1 -3
  128. package/dist/quicktype-core/support/Chance.js +0 -10
  129. package/dist/quicktype-core/support/Converters.js +0 -1
  130. package/dist/quicktype-core/support/Strings.d.ts +4 -4
  131. package/dist/quicktype-core/support/Strings.js +16 -17
  132. package/dist/quicktype-core/support/Support.d.ts +1 -1
  133. package/dist/quicktype-core/support/Support.js +6 -30
  134. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
  135. package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -1
  136. package/dist/quicktype-graphql-input/index.d.ts +1 -1
  137. package/dist/quicktype-graphql-input/index.js +212 -229
  138. package/dist/quicktype-typescript-input/index.js +4 -28
  139. package/package.json +19 -25
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
+ });
4
9
  };
5
10
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.JSONSchemaInput = exports.schemaTypeDict = exports.Ref = exports.PathElementKind = void 0;
7
- const urijs_1 = __importDefault(require("urijs"));
11
+ const URI = require("urijs");
8
12
  const collection_utils_1 = require("collection-utils");
9
13
  const Type_1 = require("../Type");
10
14
  const Support_1 = require("../support/Support");
@@ -51,13 +55,13 @@ function withRef(refOrLoc, props) {
51
55
  }
52
56
  function checkJSONSchemaObject(x, refOrLoc) {
53
57
  if (Array.isArray(x)) {
54
- return (0, Messages_1.messageError)("SchemaArrayIsInvalidSchema", withRef(refOrLoc));
58
+ return Messages_1.messageError("SchemaArrayIsInvalidSchema", withRef(refOrLoc));
55
59
  }
56
60
  if (x === null) {
57
- return (0, Messages_1.messageError)("SchemaNullIsInvalidSchema", withRef(refOrLoc));
61
+ return Messages_1.messageError("SchemaNullIsInvalidSchema", withRef(refOrLoc));
58
62
  }
59
63
  if (typeof x !== "object") {
60
- return (0, Messages_1.messageError)("SchemaInvalidJSONSchemaType", withRef(refOrLoc, { type: typeof x }));
64
+ return Messages_1.messageError("SchemaInvalidJSONSchemaType", withRef(refOrLoc, { type: typeof x }));
61
65
  }
62
66
  return x;
63
67
  }
@@ -74,14 +78,23 @@ function normalizeURI(uri) {
74
78
  // JSONSchemaStore should take a URI, not a string, and if it reads from
75
79
  // a file it can decode by itself.
76
80
  if (typeof uri === "string") {
77
- uri = new urijs_1.default(uri);
81
+ uri = new URI(uri);
78
82
  }
79
- return new urijs_1.default(urijs_1.default.decode(uri.clone().normalize().toString()));
83
+ return new URI(URI.decode(uri.clone().normalize().toString()));
80
84
  }
81
85
  class Ref {
82
- path;
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
+ }
83
96
  static root(address) {
84
- const uri = (0, collection_utils_1.definedMap)(address, a => new urijs_1.default(a));
97
+ const uri = collection_utils_1.definedMap(address, a => new URI(a));
85
98
  return new Ref(uri, []);
86
99
  }
87
100
  static parsePath(path) {
@@ -111,24 +124,13 @@ class Ref {
111
124
  return new Ref(uri, elements);
112
125
  }
113
126
  static parse(ref) {
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
- }
127
+ return Ref.parseURI(new URI(ref), true);
126
128
  }
127
129
  get hasAddress() {
128
130
  return this.addressURI !== undefined;
129
131
  }
130
132
  get address() {
131
- return (0, Support_1.defined)(this.addressURI).toString();
133
+ return Support_1.defined(this.addressURI).toString();
132
134
  }
133
135
  get isRoot() {
134
136
  return this.path.length === 1 && this.path[0].kind === PathElementKind.Root;
@@ -181,18 +183,18 @@ class Ref {
181
183
  break;
182
184
  case PathElementKind.Type:
183
185
  case PathElementKind.Object:
184
- return (0, Support_1.panic)("We shouldn't try to get the name of Type or Object refs");
186
+ return Support_1.panic("We shouldn't try to get the name of Type or Object refs");
185
187
  default:
186
- return (0, Support_1.assertNever)(e);
188
+ return Support_1.assertNever(e);
187
189
  }
188
190
  }
189
191
  }
190
192
  get definitionName() {
191
- const pe = (0, collection_utils_1.arrayGetFromEnd)(this.path, 2);
193
+ const pe = collection_utils_1.arrayGetFromEnd(this.path, 2);
192
194
  if (pe === undefined)
193
195
  return undefined;
194
196
  if (keyOrIndex(pe) === "definitions")
195
- return keyOrIndex((0, Support_1.defined)((0, collection_utils_1.arrayLast)(this.path)));
197
+ return keyOrIndex(Support_1.defined(collection_utils_1.arrayLast(this.path)));
196
198
  return undefined;
197
199
  }
198
200
  toString() {
@@ -207,7 +209,7 @@ class Ref {
207
209
  case PathElementKind.KeyOrIndex:
208
210
  return e.key;
209
211
  default:
210
- return (0, Support_1.assertNever)(e);
212
+ return Support_1.assertNever(e);
211
213
  }
212
214
  }
213
215
  const address = this.addressURI === undefined ? "" : this.addressURI.toString();
@@ -227,26 +229,26 @@ class Ref {
227
229
  const key = first.key;
228
230
  if (Array.isArray(local)) {
229
231
  if (!/^\d+$/.test(key)) {
230
- return (0, Messages_1.messageError)("SchemaCannotIndexArrayWithNonNumber", withRef(refMaker, { actual: key }));
232
+ return Messages_1.messageError("SchemaCannotIndexArrayWithNonNumber", withRef(refMaker, { actual: key }));
231
233
  }
232
234
  const index = parseInt(first.key, 10);
233
235
  if (index >= local.length) {
234
- return (0, Messages_1.messageError)("SchemaIndexNotInArray", withRef(refMaker, { index }));
236
+ return Messages_1.messageError("SchemaIndexNotInArray", withRef(refMaker, { index }));
235
237
  }
236
238
  return this.lookup(local[index], rest, root);
237
239
  }
238
240
  else {
239
- if (!(0, collection_utils_1.hasOwnProperty)(local, key)) {
240
- return (0, Messages_1.messageError)("SchemaKeyNotInObject", withRef(refMaker, { key }));
241
+ if (!collection_utils_1.hasOwnProperty(local, key)) {
242
+ return Messages_1.messageError("SchemaKeyNotInObject", withRef(refMaker, { key }));
241
243
  }
242
244
  return this.lookup(checkJSONSchemaObject(local, refMaker)[first.key], rest, root);
243
245
  }
244
246
  case PathElementKind.Type:
245
- return (0, Support_1.panic)('Cannot look up path that indexes "type"');
247
+ return Support_1.panic('Cannot look up path that indexes "type"');
246
248
  case PathElementKind.Object:
247
- return (0, Support_1.panic)('Cannot look up path that indexes "object"');
249
+ return Support_1.panic('Cannot look up path that indexes "object"');
248
250
  default:
249
- return (0, Support_1.assertNever)(first);
251
+ return Support_1.assertNever(first);
250
252
  }
251
253
  }
252
254
  lookupRef(root) {
@@ -273,15 +275,15 @@ class Ref {
273
275
  return true;
274
276
  }
275
277
  hashCode() {
276
- let acc = (0, collection_utils_1.hashCodeOf)((0, collection_utils_1.definedMap)(this.addressURI, u => u.toString()));
278
+ let acc = collection_utils_1.hashCodeOf(collection_utils_1.definedMap(this.addressURI, u => u.toString()));
277
279
  for (const pe of this.path) {
278
- acc = (0, collection_utils_1.addHashCode)(acc, pe.kind);
280
+ acc = collection_utils_1.addHashCode(acc, pe.kind);
279
281
  switch (pe.kind) {
280
282
  case PathElementKind.Type:
281
- acc = (0, collection_utils_1.addHashCode)(acc, pe.index);
283
+ acc = collection_utils_1.addHashCode(acc, pe.index);
282
284
  break;
283
285
  case PathElementKind.KeyOrIndex:
284
- acc = (0, collection_utils_1.addHashCode)(acc, (0, collection_utils_1.hashString)(pe.key));
286
+ acc = collection_utils_1.addHashCode(acc, collection_utils_1.hashString(pe.key));
285
287
  break;
286
288
  default:
287
289
  break;
@@ -292,9 +294,6 @@ class Ref {
292
294
  }
293
295
  exports.Ref = Ref;
294
296
  class Location {
295
- haveID;
296
- canonicalRef;
297
- virtualRef;
298
297
  constructor(canonicalRef, virtualRef, haveID = false) {
299
298
  this.haveID = haveID;
300
299
  this.canonicalRef = canonicalRef;
@@ -306,7 +305,7 @@ class Location {
306
305
  const parsed = Ref.parse(id);
307
306
  const virtual = this.haveID ? parsed.resolveAgainst(this.virtualRef) : parsed;
308
307
  if (!this.haveID) {
309
- (0, Messages_1.messageAssert)(virtual.hasAddress, "SchemaIDMustHaveAddress", withRef(this, { id }));
308
+ Messages_1.messageAssert(virtual.hasAddress, "SchemaIDMustHaveAddress", withRef(this, { id }));
310
309
  }
311
310
  return new Location(this.canonicalRef, virtual, true);
312
311
  }
@@ -324,11 +323,10 @@ class Location {
324
323
  }
325
324
  }
326
325
  class Canonizer {
327
- _ctx;
328
- _map = new collection_utils_1.EqualityMap();
329
- _schemaAddressesAdded = new Set();
330
326
  constructor(_ctx) {
331
327
  this._ctx = _ctx;
328
+ this._map = new collection_utils_1.EqualityMap();
329
+ this._schemaAddressesAdded = new Set();
332
330
  }
333
331
  addIDs(schema, loc) {
334
332
  if (schema === null)
@@ -384,30 +382,30 @@ function checkTypeList(typeOrTypes, loc) {
384
382
  const arr = [];
385
383
  for (const t of typeOrTypes) {
386
384
  if (typeof t !== "string") {
387
- return (0, Messages_1.messageError)("SchemaTypeElementMustBeString", withRef(loc, { element: t }));
385
+ return Messages_1.messageError("SchemaTypeElementMustBeString", withRef(loc, { element: t }));
388
386
  }
389
387
  arr.push(t);
390
388
  }
391
389
  set = new Set(arr);
392
390
  }
393
391
  else {
394
- return (0, Messages_1.messageError)("SchemaTypeMustBeStringOrStringArray", withRef(loc, { actual: typeOrTypes }));
392
+ return Messages_1.messageError("SchemaTypeMustBeStringOrStringArray", withRef(loc, { actual: typeOrTypes }));
395
393
  }
396
- (0, Messages_1.messageAssert)(set.size > 0, "SchemaNoTypeSpecified", withRef(loc));
394
+ Messages_1.messageAssert(set.size > 0, "SchemaNoTypeSpecified", withRef(loc));
397
395
  const validTypes = ["null", "boolean", "object", "array", "number", "string", "integer"];
398
- const maybeInvalid = (0, collection_utils_1.iterableFind)(set, s => validTypes.indexOf(s) < 0);
396
+ const maybeInvalid = collection_utils_1.iterableFind(set, s => validTypes.indexOf(s) < 0);
399
397
  if (maybeInvalid !== undefined) {
400
- return (0, Messages_1.messageError)("SchemaInvalidType", withRef(loc, { type: maybeInvalid }));
398
+ return Messages_1.messageError("SchemaInvalidType", withRef(loc, { type: maybeInvalid }));
401
399
  }
402
400
  return set;
403
401
  }
404
402
  function checkRequiredArray(arr, loc) {
405
403
  if (!Array.isArray(arr)) {
406
- return (0, Messages_1.messageError)("SchemaRequiredMustBeStringOrStringArray", withRef(loc, { actual: arr }));
404
+ return Messages_1.messageError("SchemaRequiredMustBeStringOrStringArray", withRef(loc, { actual: arr }));
407
405
  }
408
406
  for (const e of arr) {
409
407
  if (typeof e !== "string") {
410
- return (0, Messages_1.messageError)("SchemaRequiredElementMustBeString", withRef(loc, { element: e }));
408
+ return Messages_1.messageError("SchemaRequiredElementMustBeString", withRef(loc, { element: e }));
411
409
  }
412
410
  }
413
411
  return arr;
@@ -423,410 +421,429 @@ exports.schemaTypeDict = {
423
421
  };
424
422
  const schemaTypes = Object.getOwnPropertyNames(exports.schemaTypeDict);
425
423
  function typeKindForJSONSchemaFormat(format) {
426
- const target = (0, collection_utils_1.iterableFind)(Type_1.transformedStringTypeTargetTypeKindsMap, ([_, { jsonSchema }]) => jsonSchema === format);
424
+ const target = collection_utils_1.iterableFind(Type_1.transformedStringTypeTargetTypeKindsMap, ([_, { jsonSchema }]) => jsonSchema === format);
427
425
  if (target === undefined)
428
426
  return undefined;
429
427
  return target[0];
430
428
  }
431
429
  function schemaFetchError(base, address) {
432
430
  if (base === undefined) {
433
- return (0, Messages_1.messageError)("SchemaFetchErrorTopLevel", { address });
431
+ return Messages_1.messageError("SchemaFetchErrorTopLevel", { address });
434
432
  }
435
433
  else {
436
- return (0, Messages_1.messageError)("SchemaFetchError", { address, base: base.canonicalRef });
434
+ return Messages_1.messageError("SchemaFetchError", { address, base: base.canonicalRef });
437
435
  }
438
436
  }
439
437
  class Resolver {
440
- _ctx;
441
- _store;
442
- _canonizer;
443
438
  constructor(_ctx, _store, _canonizer) {
444
439
  this._ctx = _ctx;
445
440
  this._store = _store;
446
441
  this._canonizer = _canonizer;
447
442
  }
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);
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];
473
471
  }
474
- return [lookupLoc.canonicalRef.lookupRef(schema), lookupLoc];
475
472
  }
476
- }
473
+ });
477
474
  }
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) {
475
+ resolveVirtualRef(base, virtualRef) {
476
+ return __awaiter(this, void 0, void 0, function* () {
487
477
  if (this._ctx.debugPrintSchemaResolving) {
488
- console.log(`resolved to ${result[1].toString()}`);
478
+ console.log(`resolving ${virtualRef.toString()} relative to ${base.toString()}`);
489
479
  }
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()}`);
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]];
498
489
  }
499
- return [schema, result[1]];
500
- }
501
- return schemaFetchError(base, virtualRef.address);
502
- }
503
- async resolveTopLevelRef(ref) {
504
- return await this.resolveVirtualRef(new Location(new Ref(ref.addressURI, [])), new Ref(undefined, ref.path));
505
- }
506
- }
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);
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]];
498
+ }
499
+ return schemaFetchError(base, virtualRef.address);
500
+ });
515
501
  }
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);
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));
524
505
  });
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));
541
- }
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
506
  }
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;
507
+ }
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");
553
515
  }
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;
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");
566
531
  }
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);
532
+ else if (additionalProperties === false) {
533
+ additionalPropertiesType = undefined;
585
534
  }
586
- if (cases === undefined) {
587
- producedAttributesForNoCases = attributes;
535
+ else {
536
+ const additionalLoc = loc.push("additionalProperties");
537
+ additionalPropertiesType = yield toType(checkJSONSchema(additionalProperties, additionalLoc.canonicalRef), additionalLoc, TypeNames_2.singularizeTypeNames(attributes));
588
538
  }
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);
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);
547
+ }
548
+ return typeBuilder.getUniqueObjectType(attributes, props, additionalPropertiesType);
601
549
  });
602
- return result;
603
550
  }
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;
615
- }
616
- let title = schema.title;
617
- if (typeof title !== "string") {
618
- title = loc.canonicalRef.definitionName;
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;
619
575
  }
620
- if (typeof title === "string") {
621
- return TypeNames_1.TypeNames.make(new Set([title]), new Set(), schema.$ref !== undefined);
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
+ }
622
598
  }
623
- else {
624
- return typeNames.makeInferred();
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;
625
608
  }
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);
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
+ });
683
632
  }
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);
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);
723
639
  }
724
- if (forUnion !== undefined) {
725
- unionAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", unionAttributes, forUnion);
640
+ else {
641
+ return typeBuilder.getPrimitiveType(kind, attributes);
726
642
  }
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]);
643
+ }
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
+ });
724
+ }
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
+ });
731
746
  }
747
+ const unionType = typeBuilder.getUniqueUnionType(unionAttributes, undefined);
748
+ typeBuilder.setSetOperationMembers(unionType, new Set(typeRefs));
749
+ return unionType;
750
+ });
751
+ }
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));
732
777
  }
733
- });
734
- }
735
- const unionType = typeBuilder.getUniqueUnionType(unionAttributes, undefined);
736
- typeBuilder.setSetOperationMembers(unionType, new Set(typeRefs));
737
- return unionType;
738
- }
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);
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());
788
+ }
789
+ if (includeObject) {
790
+ unionTypes.push(yield makeObjectType());
791
+ }
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 }));
797
+ }
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;
791
818
  });
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
819
  }
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");
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;
839
+ });
817
840
  }
818
- else {
819
- loc = loc.updateWithID(schema["$id"]);
820
- result = await convertToType(schema, loc, typeAttributes);
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);
821
845
  }
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
- }
846
+ });
830
847
  }
831
848
  function removeExtension(fn) {
832
849
  const lower = fn.toLowerCase();
@@ -857,69 +874,68 @@ function nameFromURI(uri) {
857
874
  if (filename !== "") {
858
875
  return removeExtension(filename);
859
876
  }
860
- return (0, Messages_1.messageError)("DriverCannotInferNameForSchema", { uri: uri.toString() });
877
+ return Messages_1.messageError("DriverCannotInferNameForSchema", { uri: uri.toString() });
861
878
  }
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;
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));
883
896
  }
884
897
  else {
885
- const maybeName = nameFromURI(uri);
886
- name = maybeName !== undefined ? maybeName : defaultName;
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];
887
907
  }
888
- return [name, ref];
889
- }
908
+ });
890
909
  }
891
910
  class InputJSONSchemaStore extends JSONSchemaStore_1.JSONSchemaStore {
892
- _inputs;
893
- _delegate;
894
911
  constructor(_inputs, _delegate) {
895
912
  super();
896
913
  this._inputs = _inputs;
897
914
  this._delegate = _delegate;
898
915
  }
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);
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
+ });
908
927
  }
909
928
  }
910
929
  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;
920
930
  constructor(_schemaStore, additionalAttributeProducers = [], _additionalSchemaAddresses = []) {
921
931
  this._schemaStore = _schemaStore;
922
932
  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;
923
939
  this._attributeProducers = [
924
940
  Description_1.descriptionAttributeProducer,
925
941
  AccessorNames_1.accessorNamesAttributeProducer,
@@ -936,54 +952,58 @@ class JSONSchemaInput {
936
952
  addTopLevel(name, ref) {
937
953
  this._topLevels.set(name, ref);
938
954
  }
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");
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
+ }
946
964
  }
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 });
965
+ else {
966
+ maybeSchemaStore = this._schemaStore = new InputJSONSchemaStore(this._schemaInputs, maybeSchemaStore);
957
967
  }
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;
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 });
968
974
  }
969
- else {
970
- name = refs[0];
971
- }
972
- this.addTopLevel(name, refs[1]);
975
+ canonizer.addSchema(schema, address);
973
976
  }
974
- else {
975
- for (const [refName, ref] of refs) {
976
- this.addTopLevel(refName, ref);
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]);
990
+ }
991
+ else {
992
+ for (const [refName, ref] of refs) {
993
+ this.addTopLevel(refName, ref);
994
+ }
977
995
  }
978
996
  }
979
- }
980
- await addTypesInSchema(resolver, typeBuilder, this._topLevels, this._attributeProducers);
997
+ yield addTypesInSchema(resolver, typeBuilder, this._topLevels, this._attributeProducers);
998
+ });
981
999
  }
982
1000
  addTypesSync() {
983
- return (0, Support_1.panic)("addTypesSync not supported in JSONSchemaInput");
1001
+ return Support_1.panic("addTypesSync not supported in JSONSchemaInput");
984
1002
  }
985
- async addSource(schemaSource) {
986
- return this.addSourceSync(schemaSource);
1003
+ addSource(schemaSource) {
1004
+ return __awaiter(this, void 0, void 0, function* () {
1005
+ return this.addSourceSync(schemaSource);
1006
+ });
987
1007
  }
988
1008
  addSourceSync(schemaSource) {
989
1009
  const { name, uris, schema, isConverted } = schemaSource;
@@ -992,7 +1012,7 @@ class JSONSchemaInput {
992
1012
  }
993
1013
  let normalizedURIs;
994
1014
  if (uris === undefined) {
995
- normalizedURIs = [new urijs_1.default(name)];
1015
+ normalizedURIs = [new URI(name)];
996
1016
  }
997
1017
  else {
998
1018
  normalizedURIs = uris.map(uri => {
@@ -1004,7 +1024,7 @@ class JSONSchemaInput {
1004
1024
  });
1005
1025
  }
1006
1026
  if (schema === undefined) {
1007
- (0, Support_1.assert)(uris !== undefined, "URIs must be given if schema source is not specified");
1027
+ Support_1.assert(uris !== undefined, "URIs must be given if schema source is not specified");
1008
1028
  }
1009
1029
  else {
1010
1030
  for (let i = 0; i < normalizedURIs.length; i++) {
@@ -1033,7 +1053,7 @@ class JSONSchemaInput {
1033
1053
  }
1034
1054
  const set = new Set(this._schemaSources.map(([_, { schema }]) => schema));
1035
1055
  if (set.size === 1) {
1036
- return (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(set));
1056
+ return Support_1.defined(collection_utils_1.iterableFirst(set));
1037
1057
  }
1038
1058
  return undefined;
1039
1059
  }