quicktype 16.0.42 → 17.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 +8 -8
  79. package/dist/quicktype-core/language/CPlusPlus.js +185 -151
  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 +40 -38
  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 +25 -19
@@ -1,26 +1,18 @@
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
- });
9
- };
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FetchingJSONSchemaStore = void 0;
11
4
  const JSONSchemaStore_1 = require("./JSONSchemaStore");
12
5
  const __1 = require("..");
13
6
  const NodeIO_1 = require("./io/NodeIO");
14
7
  class FetchingJSONSchemaStore extends JSONSchemaStore_1.JSONSchemaStore {
8
+ _httpHeaders;
15
9
  constructor(_httpHeaders) {
16
10
  super();
17
11
  this._httpHeaders = _httpHeaders;
18
12
  }
19
- fetch(address) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- // console.log(`Fetching ${address}`);
22
- return __1.parseJSON(yield NodeIO_1.readFromFileOrURL(address, this._httpHeaders), "JSON Schema", address);
23
- });
13
+ async fetch(address) {
14
+ // console.log(`Fetching ${address}`);
15
+ return (0, __1.parseJSON)(await (0, NodeIO_1.readFromFileOrURL)(address, this._httpHeaders), "JSON Schema", address);
24
16
  }
25
17
  }
26
18
  exports.FetchingJSONSchemaStore = FetchingJSONSchemaStore;
@@ -3,8 +3,8 @@ import { TypeBuilder } from "../TypeBuilder";
3
3
  import { UnionAccumulator } from "../UnionBuilder";
4
4
  import { TypeAttributes } from "../attributes/TypeAttributes";
5
5
  import { TypeRef } from "../TypeGraph";
6
- export declare type NestedValueArray = any;
7
- export declare type Accumulator = UnionAccumulator<NestedValueArray, NestedValueArray>;
6
+ export type NestedValueArray = any;
7
+ export type Accumulator = UnionAccumulator<NestedValueArray, NestedValueArray>;
8
8
  export declare class TypeInference {
9
9
  private readonly _cjson;
10
10
  private readonly _typeBuilder;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeInference = void 0;
3
4
  const CompressedJSON_1 = require("./CompressedJSON");
4
5
  const Support_1 = require("../support/Support");
5
6
  const UnionBuilder_1 = require("../UnionBuilder");
@@ -30,6 +31,8 @@ function forEachValueInNestedValueArray(va, f) {
30
31
  });
31
32
  }
32
33
  class InferenceUnionBuilder extends UnionBuilder_1.UnionBuilder {
34
+ _typeInference;
35
+ _fixed;
33
36
  constructor(typeBuilder, _typeInference, _fixed) {
34
37
  super(typeBuilder);
35
38
  this._typeInference = _typeInference;
@@ -46,6 +49,11 @@ function canBeEnumCase(_s) {
46
49
  return true;
47
50
  }
48
51
  class TypeInference {
52
+ _cjson;
53
+ _typeBuilder;
54
+ _inferMaps;
55
+ _inferEnums;
56
+ _refIntersections;
49
57
  constructor(_cjson, _typeBuilder, _inferMaps, _inferEnums) {
50
58
  this._cjson = _cjson;
51
59
  this._typeBuilder = _typeBuilder;
@@ -54,7 +62,7 @@ class TypeInference {
54
62
  }
55
63
  addValuesToAccumulator(valueArray, accumulator) {
56
64
  forEachValueInNestedValueArray(valueArray, value => {
57
- const t = CompressedJSON_1.valueTag(value);
65
+ const t = (0, CompressedJSON_1.valueTag)(value);
58
66
  switch (t) {
59
67
  case CompressedJSON_1.Tag.Null:
60
68
  accumulator.addPrimitive("null", TypeAttributes_1.emptyTypeAttributes);
@@ -99,19 +107,19 @@ class TypeInference {
99
107
  }
100
108
  case CompressedJSON_1.Tag.TransformedString: {
101
109
  const s = this._cjson.getStringForValue(value);
102
- const kind = StringTypes_1.inferTransformedStringTypeKindForString(s, this._cjson.dateTimeRecognizer);
110
+ const kind = (0, StringTypes_1.inferTransformedStringTypeKindForString)(s, this._cjson.dateTimeRecognizer);
103
111
  if (kind === undefined) {
104
- return Support_1.panic("TransformedString does not have a kind");
112
+ return (0, Support_1.panic)("TransformedString does not have a kind");
105
113
  }
106
- const producer = Support_1.defined(Type_1.transformedStringTypeTargetTypeKindsMap.get(kind)).attributesProducer;
114
+ const producer = (0, Support_1.defined)(Type_1.transformedStringTypeTargetTypeKindsMap.get(kind)).attributesProducer;
107
115
  if (producer === undefined) {
108
- return Support_1.panic("TransformedString does not have attribute producer");
116
+ return (0, Support_1.panic)("TransformedString does not have attribute producer");
109
117
  }
110
118
  accumulator.addStringType("string", producer(s), new StringTypes_1.StringTypes(new Map(), new Set([kind])));
111
119
  break;
112
120
  }
113
121
  default:
114
- return Support_1.assertNever(t);
122
+ return (0, Support_1.assertNever)(t);
115
123
  }
116
124
  });
117
125
  }
@@ -121,25 +129,25 @@ class TypeInference {
121
129
  }
122
130
  resolveRef(ref, topLevel) {
123
131
  if (!ref.startsWith("#/")) {
124
- return Messages_1.messageError("InferenceJSONReferenceNotRooted", { reference: ref });
132
+ return (0, Messages_1.messageError)("InferenceJSONReferenceNotRooted", { reference: ref });
125
133
  }
126
134
  const parts = ref.split("/").slice(1);
127
135
  const graph = this._typeBuilder.typeGraph;
128
136
  let tref = topLevel;
129
137
  for (const part of parts) {
130
- let t = TypeGraph_1.derefTypeRef(tref, graph);
138
+ let t = (0, TypeGraph_1.derefTypeRef)(tref, graph);
131
139
  if (t instanceof Type_1.UnionType) {
132
- const nullable = TypeUtils_1.nullableFromUnion(t);
140
+ const nullable = (0, TypeUtils_1.nullableFromUnion)(t);
133
141
  if (nullable === null) {
134
142
  // FIXME: handle unions
135
- return Messages_1.messageError("InferenceJSONReferenceToUnion", { reference: ref });
143
+ return (0, Messages_1.messageError)("InferenceJSONReferenceToUnion", { reference: ref });
136
144
  }
137
145
  t = nullable;
138
146
  }
139
147
  if (t instanceof Type_1.ClassType) {
140
148
  const cp = t.getProperties().get(part);
141
149
  if (cp === undefined) {
142
- return Messages_1.messageError("InferenceJSONReferenceWrongProperty", { reference: ref });
150
+ return (0, Messages_1.messageError)("InferenceJSONReferenceWrongProperty", { reference: ref });
143
151
  }
144
152
  tref = cp.typeRef;
145
153
  }
@@ -148,24 +156,24 @@ class TypeInference {
148
156
  }
149
157
  else if (t instanceof Type_1.ArrayType) {
150
158
  if (part.match("^[0-9]+$") === null) {
151
- return Messages_1.messageError("InferenceJSONReferenceInvalidArrayIndex", { reference: ref });
159
+ return (0, Messages_1.messageError)("InferenceJSONReferenceInvalidArrayIndex", { reference: ref });
152
160
  }
153
161
  tref = t.items.typeRef;
154
162
  }
155
163
  else {
156
- return Messages_1.messageError("InferenceJSONReferenceWrongProperty", { reference: ref });
164
+ return (0, Messages_1.messageError)("InferenceJSONReferenceWrongProperty", { reference: ref });
157
165
  }
158
166
  }
159
167
  return tref;
160
168
  }
161
169
  inferTopLevelType(typeAttributes, valueArray, fixed) {
162
- Support_1.assert(this._refIntersections === undefined, "Didn't reset ref intersections - nested invocations?");
170
+ (0, Support_1.assert)(this._refIntersections === undefined, "Didn't reset ref intersections - nested invocations?");
163
171
  if (this._cjson.handleRefs) {
164
172
  this._refIntersections = [];
165
173
  }
166
174
  const topLevel = this.inferType(typeAttributes, valueArray, fixed);
167
175
  if (this._cjson.handleRefs) {
168
- for (const [tref, refs] of Support_1.defined(this._refIntersections)) {
176
+ for (const [tref, refs] of (0, Support_1.defined)(this._refIntersections)) {
169
177
  const resolved = refs.map(r => this.resolveRef(r, topLevel));
170
178
  this._typeBuilder.setSetOperationMembers(tref, new Set(resolved));
171
179
  }
@@ -198,11 +206,11 @@ class TypeInference {
198
206
  });
199
207
  if (this._cjson.handleRefs && propertyNames.length === 1 && propertyNames[0] === "$ref") {
200
208
  const values = propertyValues["$ref"];
201
- if (values.every(v => CompressedJSON_1.valueTag(v) === CompressedJSON_1.Tag.InternedString)) {
209
+ if (values.every(v => (0, CompressedJSON_1.valueTag)(v) === CompressedJSON_1.Tag.InternedString)) {
202
210
  const allRefs = values.map(v => this._cjson.getStringForValue(v));
203
211
  // FIXME: Add is-ref attribute
204
212
  const tref = this._typeBuilder.getUniqueIntersectionType(typeAttributes, undefined);
205
- Support_1.defined(this._refIntersections).push([tref, allRefs]);
213
+ (0, Support_1.defined)(this._refIntersections).push([tref, allRefs]);
206
214
  return tref;
207
215
  }
208
216
  }
@@ -42,7 +42,7 @@ export declare class InputData {
42
42
  addSourceSync<T>(kind: string, source: T, makeInput: () => Input<T>): void;
43
43
  addTypes(ctx: RunContext, typeBuilder: TypeBuilder, inferMaps: boolean, inferEnums: boolean, fixedTopLevels: boolean): Promise<void>;
44
44
  addTypesSync(ctx: RunContext, typeBuilder: TypeBuilder, inferMaps: boolean, inferEnums: boolean, fixedTopLevels: boolean): void;
45
- readonly needIR: boolean;
46
- readonly needSchemaProcessing: boolean;
45
+ get needIR(): boolean;
46
+ get needSchemaProcessing(): boolean;
47
47
  singleStringSchemaSource(): string | undefined;
48
48
  }
@@ -1,13 +1,6 @@
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
- });
9
- };
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InputData = exports.jsonInputForTargetLanguage = exports.JSONInput = void 0;
11
4
  const collection_utils_1 = require("collection-utils");
12
5
  const CompressedJSON_1 = require("./CompressedJSON");
13
6
  const Support_1 = require("../support/Support");
@@ -17,20 +10,21 @@ const Description_1 = require("../attributes/Description");
17
10
  const Inference_1 = require("./Inference");
18
11
  const All_1 = require("../language/All");
19
12
  function messageParseError(name, description, e) {
20
- return Messages_1.messageError("MiscJSONParseError", {
21
- description: collection_utils_1.withDefault(description, "input"),
13
+ return (0, Messages_1.messageError)("MiscJSONParseError", {
14
+ description: (0, collection_utils_1.withDefault)(description, "input"),
22
15
  address: name,
23
- message: Support_1.errorMessage(e)
16
+ message: (0, Support_1.errorMessage)(e)
24
17
  });
25
18
  }
26
19
  class JSONInput {
20
+ _compressedJSON;
21
+ kind = "json";
22
+ needIR = true;
23
+ needSchemaProcessing = false;
24
+ _topLevels = new Map();
27
25
  /* tslint:disable:no-unused-variable */
28
26
  constructor(_compressedJSON) {
29
27
  this._compressedJSON = _compressedJSON;
30
- this.kind = "json";
31
- this.needIR = true;
32
- this.needSchemaProcessing = false;
33
- this._topLevels = new Map();
34
28
  }
35
29
  addSample(topLevelName, sample) {
36
30
  let topLevel = this._topLevels.get(topLevelName);
@@ -43,7 +37,7 @@ class JSONInput {
43
37
  setDescription(topLevelName, description) {
44
38
  let topLevel = this._topLevels.get(topLevelName);
45
39
  if (topLevel === undefined) {
46
- return Support_1.panic("Trying to set description for a top-level that doesn't exist");
40
+ return (0, Support_1.panic)("Trying to set description for a top-level that doesn't exist");
47
41
  }
48
42
  topLevel.description = description;
49
43
  }
@@ -55,17 +49,15 @@ class JSONInput {
55
49
  }
56
50
  }
57
51
  }
58
- addSource(source) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const { name, samples, description } = source;
61
- try {
62
- const values = yield collection_utils_1.arrayMapSync(samples, (s) => __awaiter(this, void 0, void 0, function* () { return yield this._compressedJSON.parse(s); }));
63
- this.addSamples(name, values, description);
64
- }
65
- catch (e) {
66
- return messageParseError(name, description, e);
67
- }
68
- });
52
+ async addSource(source) {
53
+ const { name, samples, description } = source;
54
+ try {
55
+ const values = await (0, collection_utils_1.arrayMapSync)(samples, async (s) => await this._compressedJSON.parse(s));
56
+ this.addSamples(name, values, description);
57
+ }
58
+ catch (e) {
59
+ return messageParseError(name, description, e);
60
+ }
69
61
  }
70
62
  addSourceSync(source) {
71
63
  const { name, samples, description } = source;
@@ -80,15 +72,13 @@ class JSONInput {
80
72
  singleStringSchemaSource() {
81
73
  return undefined;
82
74
  }
83
- addTypes(ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels) {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- return this.addTypesSync(ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels);
86
- });
75
+ async addTypes(ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels) {
76
+ return this.addTypesSync(ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels);
87
77
  }
88
78
  addTypesSync(_ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels) {
89
79
  const inference = new Inference_1.TypeInference(this._compressedJSON, typeBuilder, inferMaps, inferEnums);
90
80
  for (const [name, { samples, description }] of this._topLevels) {
91
- const tref = inference.inferTopLevelType(TypeNames_1.makeNamesTypeAttributes(name, false), samples, fixedTopLevels);
81
+ const tref = inference.inferTopLevelType((0, TypeNames_1.makeNamesTypeAttributes)(name, false), samples, fixedTopLevels);
92
82
  typeBuilder.addTopLevel(name, tref);
93
83
  if (description !== undefined) {
94
84
  const attributes = Description_1.descriptionTypeAttributeKind.makeAttributes(new Set([description]));
@@ -100,44 +90,38 @@ class JSONInput {
100
90
  exports.JSONInput = JSONInput;
101
91
  function jsonInputForTargetLanguage(targetLanguage, languages, handleJSONRefs = false) {
102
92
  if (typeof targetLanguage === "string") {
103
- targetLanguage = Support_1.defined(All_1.languageNamed(targetLanguage, languages));
93
+ targetLanguage = (0, Support_1.defined)((0, All_1.languageNamed)(targetLanguage, languages));
104
94
  }
105
95
  const compressedJSON = new CompressedJSON_1.CompressedJSONFromString(targetLanguage.dateTimeRecognizer, handleJSONRefs);
106
96
  return new JSONInput(compressedJSON);
107
97
  }
108
98
  exports.jsonInputForTargetLanguage = jsonInputForTargetLanguage;
109
99
  class InputData {
110
- constructor() {
111
- // FIXME: Make into a Map, indexed by kind.
112
- this._inputs = new Set();
113
- }
100
+ // FIXME: Make into a Map, indexed by kind.
101
+ _inputs = new Set();
114
102
  addInput(input) {
115
103
  this._inputs = this._inputs.add(input);
116
104
  }
117
105
  getOrAddInput(kind, makeInput) {
118
- let input = collection_utils_1.iterableFind(this._inputs, i => i.kind === kind);
106
+ let input = (0, collection_utils_1.iterableFind)(this._inputs, i => i.kind === kind);
119
107
  if (input === undefined) {
120
108
  input = makeInput();
121
109
  this.addInput(input);
122
110
  }
123
111
  return input;
124
112
  }
125
- addSource(kind, source, makeInput) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- const input = this.getOrAddInput(kind, makeInput);
128
- yield input.addSource(source);
129
- });
113
+ async addSource(kind, source, makeInput) {
114
+ const input = this.getOrAddInput(kind, makeInput);
115
+ await input.addSource(source);
130
116
  }
131
117
  addSourceSync(kind, source, makeInput) {
132
118
  const input = this.getOrAddInput(kind, makeInput);
133
119
  input.addSourceSync(source);
134
120
  }
135
- addTypes(ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels) {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- for (const input of this._inputs) {
138
- yield input.addTypes(ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels);
139
- }
140
- });
121
+ async addTypes(ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels) {
122
+ for (const input of this._inputs) {
123
+ await input.addTypes(ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels);
124
+ }
141
125
  }
142
126
  addTypesSync(ctx, typeBuilder, inferMaps, inferEnums, fixedTopLevels) {
143
127
  for (const input of this._inputs) {
@@ -145,17 +129,17 @@ class InputData {
145
129
  }
146
130
  }
147
131
  get needIR() {
148
- return collection_utils_1.iterableSome(this._inputs, i => i.needIR);
132
+ return (0, collection_utils_1.iterableSome)(this._inputs, i => i.needIR);
149
133
  }
150
134
  get needSchemaProcessing() {
151
- return collection_utils_1.iterableSome(this._inputs, i => i.needSchemaProcessing);
135
+ return (0, collection_utils_1.iterableSome)(this._inputs, i => i.needSchemaProcessing);
152
136
  }
153
137
  singleStringSchemaSource() {
154
- const schemaStrings = collection_utils_1.setFilterMap(this._inputs, i => i.singleStringSchemaSource());
138
+ const schemaStrings = (0, collection_utils_1.setFilterMap)(this._inputs, i => i.singleStringSchemaSource());
155
139
  if (schemaStrings.size > 1) {
156
- return Support_1.panic("We have more than one input with a string schema source");
140
+ return (0, Support_1.panic)("We have more than one input with a string schema source");
157
141
  }
158
- return collection_utils_1.iterableFirst(schemaStrings);
142
+ return (0, collection_utils_1.iterableFirst)(schemaStrings);
159
143
  }
160
144
  }
161
145
  exports.InputData = InputData;
@@ -1,4 +1,4 @@
1
- import * as URI from "urijs";
1
+ import URI from "urijs";
2
2
  import { TypeBuilder } from "../TypeBuilder";
3
3
  import { TypeAttributes } from "../attributes/TypeAttributes";
4
4
  import { JSONSchema, JSONSchemaStore } from "./JSONSchemaStore";
@@ -10,7 +10,7 @@ export declare enum PathElementKind {
10
10
  Type = 2,
11
11
  Object = 3
12
12
  }
13
- export declare type PathElement = {
13
+ export type PathElement = {
14
14
  kind: PathElementKind.Root;
15
15
  } | {
16
16
  kind: PathElementKind.KeyOrIndex;
@@ -29,16 +29,16 @@ export declare class Ref {
29
29
  static parse(ref: string): Ref;
30
30
  addressURI: URI | undefined;
31
31
  constructor(addressURI: URI | undefined, path: ReadonlyArray<PathElement>);
32
- readonly hasAddress: boolean;
33
- readonly address: string;
34
- readonly isRoot: boolean;
32
+ get hasAddress(): boolean;
33
+ get address(): string;
34
+ get isRoot(): boolean;
35
35
  private pushElement;
36
36
  push(...keys: string[]): Ref;
37
37
  pushObject(): Ref;
38
38
  pushType(index: number): Ref;
39
39
  resolveAgainst(base: Ref | undefined): Ref;
40
- readonly name: string;
41
- readonly definitionName: string | undefined;
40
+ get name(): string;
41
+ get definitionName(): string | undefined;
42
42
  toString(): string;
43
43
  private lookup;
44
44
  lookupRef(root: JSONSchema): JSONSchema;
@@ -54,8 +54,8 @@ export declare const schemaTypeDict: {
54
54
  array: boolean;
55
55
  object: boolean;
56
56
  };
57
- export declare type JSONSchemaType = keyof typeof schemaTypeDict;
58
- export declare type JSONSchemaAttributes = {
57
+ export type JSONSchemaType = keyof typeof schemaTypeDict;
58
+ export type JSONSchemaAttributes = {
59
59
  forType?: TypeAttributes;
60
60
  forUnion?: TypeAttributes;
61
61
  forObject?: TypeAttributes;
@@ -63,7 +63,7 @@ export declare type JSONSchemaAttributes = {
63
63
  forString?: TypeAttributes;
64
64
  forCases?: TypeAttributes[];
65
65
  };
66
- export declare type JSONSchemaAttributeProducer = (schema: JSONSchema, canonicalRef: Ref, types: Set<JSONSchemaType>, unionCases: JSONSchema[] | undefined) => JSONSchemaAttributes | undefined;
66
+ export type JSONSchemaAttributeProducer = (schema: JSONSchema, canonicalRef: Ref, types: Set<JSONSchemaType>, unionCases: JSONSchema[] | undefined) => JSONSchemaAttributes | undefined;
67
67
  export interface JSONSchemaSourceData {
68
68
  name: string;
69
69
  uris?: string[];
@@ -81,7 +81,7 @@ export declare class JSONSchemaInput implements Input<JSONSchemaSourceData> {
81
81
  private readonly _topLevels;
82
82
  private _needIR;
83
83
  constructor(_schemaStore: JSONSchemaStore | undefined, additionalAttributeProducers?: JSONSchemaAttributeProducer[], _additionalSchemaAddresses?: ReadonlyArray<string>);
84
- readonly needIR: boolean;
84
+ get needIR(): boolean;
85
85
  addTopLevel(name: string, ref: Ref): void;
86
86
  addTypes(ctx: RunContext, typeBuilder: TypeBuilder): Promise<void>;
87
87
  addTypesSync(): void;