quicktype 18.0.6 → 19.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +1 -1
  2. package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
  3. package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
  4. package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
  5. package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
  6. package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
  7. package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
  8. package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
  9. package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
  10. package/dist/{cli/index.d.ts → index.d.ts} +1 -1
  11. package/dist/{cli/index.js → index.js} +4 -5
  12. package/package.json +61 -77
  13. package/dist/quicktype-core/Annotation.d.ts +0 -8
  14. package/dist/quicktype-core/Annotation.js +0 -16
  15. package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
  16. package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
  17. package/dist/quicktype-core/DateTime.d.ts +0 -10
  18. package/dist/quicktype-core/DateTime.js +0 -57
  19. package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
  20. package/dist/quicktype-core/DeclarationIR.js +0 -167
  21. package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
  22. package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
  23. package/dist/quicktype-core/GatherNames.d.ts +0 -2
  24. package/dist/quicktype-core/GatherNames.js +0 -333
  25. package/dist/quicktype-core/Graph.d.ts +0 -12
  26. package/dist/quicktype-core/Graph.js +0 -220
  27. package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
  28. package/dist/quicktype-core/GraphRewriting.js +0 -421
  29. package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
  30. package/dist/quicktype-core/MakeTransformations.js +0 -193
  31. package/dist/quicktype-core/MarkovChain.d.ts +0 -15
  32. package/dist/quicktype-core/MarkovChain.js +0 -154
  33. package/dist/quicktype-core/Messages.d.ts +0 -294
  34. package/dist/quicktype-core/Messages.js +0 -105
  35. package/dist/quicktype-core/Naming.d.ts +0 -64
  36. package/dist/quicktype-core/Naming.js +0 -356
  37. package/dist/quicktype-core/Renderer.d.ts +0 -50
  38. package/dist/quicktype-core/Renderer.js +0 -274
  39. package/dist/quicktype-core/RendererOptions.d.ts +0 -71
  40. package/dist/quicktype-core/RendererOptions.js +0 -141
  41. package/dist/quicktype-core/Run.d.ts +0 -174
  42. package/dist/quicktype-core/Run.js +0 -393
  43. package/dist/quicktype-core/Source.d.ts +0 -65
  44. package/dist/quicktype-core/Source.js +0 -204
  45. package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
  46. package/dist/quicktype-core/TargetLanguage.js +0 -66
  47. package/dist/quicktype-core/Transformers.d.ts +0 -209
  48. package/dist/quicktype-core/Transformers.js +0 -836
  49. package/dist/quicktype-core/Type.d.ts +0 -206
  50. package/dist/quicktype-core/Type.js +0 -716
  51. package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
  52. package/dist/quicktype-core/TypeBuilder.js +0 -324
  53. package/dist/quicktype-core/TypeGraph.d.ts +0 -75
  54. package/dist/quicktype-core/TypeGraph.js +0 -420
  55. package/dist/quicktype-core/TypeUtils.d.ts +0 -33
  56. package/dist/quicktype-core/TypeUtils.js +0 -230
  57. package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
  58. package/dist/quicktype-core/UnifyClasses.js +0 -159
  59. package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
  60. package/dist/quicktype-core/UnionBuilder.js +0 -282
  61. package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
  62. package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
  63. package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
  64. package/dist/quicktype-core/attributes/Constraints.js +0 -172
  65. package/dist/quicktype-core/attributes/Description.d.ts +0 -9
  66. package/dist/quicktype-core/attributes/Description.js +0 -97
  67. package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
  68. package/dist/quicktype-core/attributes/EnumValues.js +0 -31
  69. package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
  70. package/dist/quicktype-core/attributes/StringTypes.js +0 -189
  71. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
  72. package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
  73. package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
  74. package/dist/quicktype-core/attributes/TypeNames.js +0 -274
  75. package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
  76. package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
  77. package/dist/quicktype-core/index.d.ts +0 -48
  78. package/dist/quicktype-core/index.js +0 -180
  79. package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
  80. package/dist/quicktype-core/input/CompressedJSON.js +0 -276
  81. package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
  82. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
  83. package/dist/quicktype-core/input/Inference.d.ts +0 -22
  84. package/dist/quicktype-core/input/Inference.js +0 -240
  85. package/dist/quicktype-core/input/Inputs.d.ts +0 -48
  86. package/dist/quicktype-core/input/Inputs.js +0 -145
  87. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
  88. package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
  89. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
  90. package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
  91. package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
  92. package/dist/quicktype-core/input/PostmanCollection.js +0 -60
  93. package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
  94. package/dist/quicktype-core/input/io/NodeIO.js +0 -87
  95. package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
  96. package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
  97. package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
  98. package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
  99. package/dist/quicktype-core/language/All.d.ts +0 -3
  100. package/dist/quicktype-core/language/All.js +0 -57
  101. package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
  102. package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
  103. package/dist/quicktype-core/language/CSharp.d.ts +0 -201
  104. package/dist/quicktype-core/language/CSharp.js +0 -1850
  105. package/dist/quicktype-core/language/Crystal.d.ts +0 -37
  106. package/dist/quicktype-core/language/Crystal.js +0 -337
  107. package/dist/quicktype-core/language/Dart.d.ts +0 -66
  108. package/dist/quicktype-core/language/Dart.js +0 -576
  109. package/dist/quicktype-core/language/Elm.d.ts +0 -58
  110. package/dist/quicktype-core/language/Elm.js +0 -522
  111. package/dist/quicktype-core/language/Golang.d.ts +0 -51
  112. package/dist/quicktype-core/language/Golang.js +0 -460
  113. package/dist/quicktype-core/language/Haskell.d.ts +0 -56
  114. package/dist/quicktype-core/language/Haskell.js +0 -411
  115. package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
  116. package/dist/quicktype-core/language/JSONSchema.js +0 -169
  117. package/dist/quicktype-core/language/Java.d.ts +0 -125
  118. package/dist/quicktype-core/language/Java.js +0 -1081
  119. package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
  120. package/dist/quicktype-core/language/JavaScript.js +0 -435
  121. package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
  122. package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
  123. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
  124. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
  125. package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
  126. package/dist/quicktype-core/language/Kotlin.js +0 -832
  127. package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
  128. package/dist/quicktype-core/language/Objective-C.js +0 -777
  129. package/dist/quicktype-core/language/Php.d.ts +0 -80
  130. package/dist/quicktype-core/language/Php.js +0 -702
  131. package/dist/quicktype-core/language/Pike.d.ts +0 -37
  132. package/dist/quicktype-core/language/Pike.js +0 -276
  133. package/dist/quicktype-core/language/Python.d.ts +0 -107
  134. package/dist/quicktype-core/language/Python.js +0 -969
  135. package/dist/quicktype-core/language/Rust.d.ts +0 -56
  136. package/dist/quicktype-core/language/Rust.js +0 -309
  137. package/dist/quicktype-core/language/Swift.d.ts +0 -96
  138. package/dist/quicktype-core/language/Swift.js +0 -1211
  139. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
  140. package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
  141. package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
  142. package/dist/quicktype-core/language/ruby/index.js +0 -557
  143. package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
  144. package/dist/quicktype-core/language/ruby/keywords.js +0 -358
  145. package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
  146. package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
  147. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
  148. package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
  149. package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
  150. package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
  151. package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
  152. package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
  153. package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
  154. package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
  155. package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
  156. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
  157. package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
  158. package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
  159. package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
  160. package/dist/quicktype-core/support/Acronyms.js +0 -1128
  161. package/dist/quicktype-core/support/Chance.d.ts +0 -38
  162. package/dist/quicktype-core/support/Chance.js +0 -2146
  163. package/dist/quicktype-core/support/Converters.d.ts +0 -6
  164. package/dist/quicktype-core/support/Converters.js +0 -16
  165. package/dist/quicktype-core/support/Strings.d.ts +0 -44
  166. package/dist/quicktype-core/support/Strings.js +0 -525
  167. package/dist/quicktype-core/support/Support.d.ts +0 -29
  168. package/dist/quicktype-core/support/Support.js +0 -162
  169. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
  170. package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
  171. package/dist/quicktype-graphql-input/index.d.ts +0 -17
  172. package/dist/quicktype-graphql-input/index.js +0 -407
  173. package/dist/quicktype-typescript-input/index.d.ts +0 -2
  174. package/dist/quicktype-typescript-input/index.js +0 -98
@@ -1,276 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CompressedJSONFromString = exports.CompressedJSON = exports.valueTag = exports.makeValue = exports.Tag = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const Support_1 = require("../support/Support");
6
- const Type_1 = require("../Type");
7
- const StringTypes_1 = require("../attributes/StringTypes");
8
- var Tag;
9
- (function (Tag) {
10
- Tag[Tag["Null"] = 0] = "Null";
11
- Tag[Tag["False"] = 1] = "False";
12
- Tag[Tag["True"] = 2] = "True";
13
- Tag[Tag["Integer"] = 3] = "Integer";
14
- Tag[Tag["Double"] = 4] = "Double";
15
- Tag[Tag["InternedString"] = 5] = "InternedString";
16
- Tag[Tag["UninternedString"] = 6] = "UninternedString";
17
- Tag[Tag["Object"] = 7] = "Object";
18
- Tag[Tag["Array"] = 8] = "Array";
19
- Tag[Tag["StringFormat"] = 9] = "StringFormat";
20
- Tag[Tag["TransformedString"] = 10] = "TransformedString";
21
- })(Tag = exports.Tag || (exports.Tag = {}));
22
- const TAG_BITS = 4;
23
- const TAG_MASK = (1 << TAG_BITS) - 1;
24
- function makeValue(t, index) {
25
- return t | (index << TAG_BITS);
26
- }
27
- exports.makeValue = makeValue;
28
- function getIndex(v, tag) {
29
- (0, Support_1.assert)(valueTag(v) === tag, "Trying to get index for value with invalid tag");
30
- return v >> TAG_BITS;
31
- }
32
- function valueTag(v) {
33
- return v & TAG_MASK;
34
- }
35
- exports.valueTag = valueTag;
36
- class CompressedJSON {
37
- dateTimeRecognizer;
38
- handleRefs;
39
- _rootValue;
40
- _ctx;
41
- _contextStack = [];
42
- _strings = [];
43
- _stringIndexes = {};
44
- _objects = [];
45
- _arrays = [];
46
- constructor(dateTimeRecognizer, handleRefs) {
47
- this.dateTimeRecognizer = dateTimeRecognizer;
48
- this.handleRefs = handleRefs;
49
- }
50
- parseSync(_input) {
51
- return (0, Support_1.panic)("parseSync not implemented in CompressedJSON");
52
- }
53
- getStringForValue(v) {
54
- const tag = valueTag(v);
55
- (0, Support_1.assert)(tag === Tag.InternedString || tag === Tag.TransformedString);
56
- return this._strings[getIndex(v, tag)];
57
- }
58
- getObjectForValue = (v) => {
59
- return this._objects[getIndex(v, Tag.Object)];
60
- };
61
- getArrayForValue = (v) => {
62
- return this._arrays[getIndex(v, Tag.Array)];
63
- };
64
- getStringFormatTypeKind(v) {
65
- const kind = this._strings[getIndex(v, Tag.StringFormat)];
66
- if (!(0, Type_1.isPrimitiveStringTypeKind)(kind) || kind === "string") {
67
- return (0, Support_1.panic)("Not a transformed string type kind");
68
- }
69
- return kind;
70
- }
71
- get context() {
72
- return (0, Support_1.defined)(this._ctx);
73
- }
74
- internString(s) {
75
- if (Object.prototype.hasOwnProperty.call(this._stringIndexes, s)) {
76
- return this._stringIndexes[s];
77
- }
78
- const index = this._strings.length;
79
- this._strings.push(s);
80
- this._stringIndexes[s] = index;
81
- return index;
82
- }
83
- makeString(s) {
84
- const value = makeValue(Tag.InternedString, this.internString(s));
85
- (0, Support_1.assert)(typeof value === "number", `Interned string value is not a number: ${value}`);
86
- return value;
87
- }
88
- internObject(obj) {
89
- const index = this._objects.length;
90
- this._objects.push(obj);
91
- return makeValue(Tag.Object, index);
92
- }
93
- internArray = (arr) => {
94
- const index = this._arrays.length;
95
- this._arrays.push(arr);
96
- return makeValue(Tag.Array, index);
97
- };
98
- get isExpectingRef() {
99
- return this._ctx !== undefined && this._ctx.currentKey === "$ref";
100
- }
101
- commitValue(value) {
102
- (0, Support_1.assert)(typeof value === "number", `CompressedJSON value is not a number: ${value}`);
103
- if (this._ctx === undefined) {
104
- (0, Support_1.assert)(this._rootValue === undefined, "Committing value but nowhere to commit to - root value still there.");
105
- this._rootValue = value;
106
- }
107
- else if (this._ctx.currentObject !== undefined) {
108
- if (this._ctx.currentKey === undefined) {
109
- return (0, Support_1.panic)("Must have key and can't have string when committing");
110
- }
111
- this._ctx.currentObject.push(this.makeString(this._ctx.currentKey), value);
112
- this._ctx.currentKey = undefined;
113
- }
114
- else if (this._ctx.currentArray !== undefined) {
115
- this._ctx.currentArray.push(value);
116
- }
117
- else {
118
- return (0, Support_1.panic)("Committing value but nowhere to commit to");
119
- }
120
- }
121
- commitNull() {
122
- this.commitValue(makeValue(Tag.Null, 0));
123
- }
124
- commitBoolean(v) {
125
- this.commitValue(makeValue(v ? Tag.True : Tag.False, 0));
126
- }
127
- commitNumber(isDouble) {
128
- const numberTag = isDouble ? Tag.Double : Tag.Integer;
129
- this.commitValue(makeValue(numberTag, 0));
130
- }
131
- commitString(s) {
132
- let value = undefined;
133
- if (this.handleRefs && this.isExpectingRef) {
134
- value = this.makeString(s);
135
- }
136
- else {
137
- const format = (0, StringTypes_1.inferTransformedStringTypeKindForString)(s, this.dateTimeRecognizer);
138
- if (format !== undefined) {
139
- if ((0, Support_1.defined)(Type_1.transformedStringTypeTargetTypeKindsMap.get(format)).attributesProducer !== undefined) {
140
- value = makeValue(Tag.TransformedString, this.internString(s));
141
- }
142
- else {
143
- value = makeValue(Tag.StringFormat, this.internString(format));
144
- }
145
- }
146
- else if (s.length <= 64) {
147
- value = this.makeString(s);
148
- }
149
- else {
150
- value = makeValue(Tag.UninternedString, 0);
151
- }
152
- }
153
- this.commitValue(value);
154
- }
155
- finish() {
156
- const value = this._rootValue;
157
- if (value === undefined) {
158
- return (0, Support_1.panic)("Finished without root document");
159
- }
160
- (0, Support_1.assert)(this._ctx === undefined && this._contextStack.length === 0, "Finished with contexts present");
161
- this._rootValue = undefined;
162
- return value;
163
- }
164
- pushContext() {
165
- if (this._ctx !== undefined) {
166
- this._contextStack.push(this._ctx);
167
- }
168
- this._ctx = {
169
- currentObject: undefined,
170
- currentArray: undefined,
171
- currentKey: undefined,
172
- currentNumberIsDouble: false
173
- };
174
- }
175
- pushObjectContext() {
176
- this.pushContext();
177
- (0, Support_1.defined)(this._ctx).currentObject = [];
178
- }
179
- setPropertyKey(key) {
180
- const ctx = this.context;
181
- ctx.currentKey = key;
182
- }
183
- finishObject() {
184
- const obj = this.context.currentObject;
185
- if (obj === undefined) {
186
- return (0, Support_1.panic)("Object ended but not started");
187
- }
188
- this.popContext();
189
- this.commitValue(this.internObject(obj));
190
- }
191
- pushArrayContext() {
192
- this.pushContext();
193
- (0, Support_1.defined)(this._ctx).currentArray = [];
194
- }
195
- finishArray() {
196
- const arr = this.context.currentArray;
197
- if (arr === undefined) {
198
- return (0, Support_1.panic)("Array ended but not started");
199
- }
200
- this.popContext();
201
- this.commitValue(this.internArray(arr));
202
- }
203
- popContext() {
204
- (0, Support_1.assert)(this._ctx !== undefined, "Popping context when there isn't one");
205
- this._ctx = this._contextStack.pop();
206
- }
207
- equals(other) {
208
- return this === other;
209
- }
210
- hashCode() {
211
- let hashAccumulator = collection_utils_1.hashCodeInit;
212
- for (const s of this._strings) {
213
- hashAccumulator = (0, collection_utils_1.addHashCode)(hashAccumulator, (0, collection_utils_1.hashString)(s));
214
- }
215
- for (const s of Object.getOwnPropertyNames(this._stringIndexes).sort()) {
216
- hashAccumulator = (0, collection_utils_1.addHashCode)(hashAccumulator, (0, collection_utils_1.hashString)(s));
217
- hashAccumulator = (0, collection_utils_1.addHashCode)(hashAccumulator, this._stringIndexes[s]);
218
- }
219
- for (const o of this._objects) {
220
- for (const v of o) {
221
- hashAccumulator = (0, collection_utils_1.addHashCode)(hashAccumulator, v);
222
- }
223
- }
224
- for (const o of this._arrays) {
225
- for (const v of o) {
226
- hashAccumulator = (0, collection_utils_1.addHashCode)(hashAccumulator, v);
227
- }
228
- }
229
- return hashAccumulator;
230
- }
231
- }
232
- exports.CompressedJSON = CompressedJSON;
233
- class CompressedJSONFromString extends CompressedJSON {
234
- async parse(input) {
235
- return this.parseSync(input);
236
- }
237
- parseSync(input) {
238
- const json = JSON.parse(input);
239
- this.process(json);
240
- return this.finish();
241
- }
242
- process(json) {
243
- if (json === null) {
244
- this.commitNull();
245
- }
246
- else if (typeof json === "boolean") {
247
- this.commitBoolean(json);
248
- }
249
- else if (typeof json === "string") {
250
- this.commitString(json);
251
- }
252
- else if (typeof json === "number") {
253
- const isDouble = json !== Math.floor(json) || json < Number.MIN_SAFE_INTEGER || json > Number.MAX_SAFE_INTEGER;
254
- this.commitNumber(isDouble);
255
- }
256
- else if (Array.isArray(json)) {
257
- this.pushArrayContext();
258
- for (const v of json) {
259
- this.process(v);
260
- }
261
- this.finishArray();
262
- }
263
- else if (typeof json === "object") {
264
- this.pushObjectContext();
265
- for (const key of Object.getOwnPropertyNames(json)) {
266
- this.setPropertyKey(key);
267
- this.process(json[key]);
268
- }
269
- this.finishObject();
270
- }
271
- else {
272
- return (0, Support_1.panic)("Invalid JSON object");
273
- }
274
- }
275
- }
276
- exports.CompressedJSONFromString = CompressedJSONFromString;
@@ -1,6 +0,0 @@
1
- import { JSONSchema, JSONSchemaStore } from "./JSONSchemaStore";
2
- export declare class FetchingJSONSchemaStore extends JSONSchemaStore {
3
- private readonly _httpHeaders?;
4
- constructor(_httpHeaders?: string[] | undefined);
5
- fetch(address: string): Promise<JSONSchema | undefined>;
6
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FetchingJSONSchemaStore = void 0;
4
- const JSONSchemaStore_1 = require("./JSONSchemaStore");
5
- const __1 = require("..");
6
- const NodeIO_1 = require("./io/NodeIO");
7
- class FetchingJSONSchemaStore extends JSONSchemaStore_1.JSONSchemaStore {
8
- _httpHeaders;
9
- constructor(_httpHeaders) {
10
- super();
11
- this._httpHeaders = _httpHeaders;
12
- }
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);
16
- }
17
- }
18
- exports.FetchingJSONSchemaStore = FetchingJSONSchemaStore;
@@ -1,22 +0,0 @@
1
- import { CompressedJSON } from "./CompressedJSON";
2
- import { TypeBuilder } from "../TypeBuilder";
3
- import { UnionAccumulator } from "../UnionBuilder";
4
- import { TypeAttributes } from "../attributes/TypeAttributes";
5
- import { TypeRef } from "../TypeGraph";
6
- export type NestedValueArray = any;
7
- export type Accumulator = UnionAccumulator<NestedValueArray, NestedValueArray>;
8
- export declare class TypeInference {
9
- private readonly _cjson;
10
- private readonly _typeBuilder;
11
- private readonly _inferMaps;
12
- private readonly _inferEnums;
13
- private _refIntersections;
14
- constructor(_cjson: CompressedJSON<unknown>, _typeBuilder: TypeBuilder, _inferMaps: boolean, _inferEnums: boolean);
15
- addValuesToAccumulator(valueArray: NestedValueArray, accumulator: Accumulator): void;
16
- inferType(typeAttributes: TypeAttributes, valueArray: NestedValueArray, fixed: boolean, forwardingRef?: TypeRef): TypeRef;
17
- private resolveRef;
18
- inferTopLevelType(typeAttributes: TypeAttributes, valueArray: NestedValueArray, fixed: boolean): TypeRef;
19
- accumulatorForArray(valueArray: NestedValueArray): Accumulator;
20
- makeTypeFromAccumulator(accumulator: Accumulator, typeAttributes: TypeAttributes, fixed: boolean, forwardingRef?: TypeRef): TypeRef;
21
- inferClassType(typeAttributes: TypeAttributes, objects: NestedValueArray, fixed: boolean, forwardingRef?: TypeRef): TypeRef;
22
- }
@@ -1,240 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeInference = void 0;
4
- const CompressedJSON_1 = require("./CompressedJSON");
5
- const Support_1 = require("../support/Support");
6
- const UnionBuilder_1 = require("../UnionBuilder");
7
- const Type_1 = require("../Type");
8
- const TypeAttributes_1 = require("../attributes/TypeAttributes");
9
- const StringTypes_1 = require("../attributes/StringTypes");
10
- const TypeGraph_1 = require("../TypeGraph");
11
- const Messages_1 = require("../Messages");
12
- const TypeUtils_1 = require("../TypeUtils");
13
- function forEachArrayInNestedValueArray(va, f) {
14
- if (va.length === 0) {
15
- return;
16
- }
17
- if (Array.isArray(va[0])) {
18
- for (const x of va) {
19
- forEachArrayInNestedValueArray(x, f);
20
- }
21
- }
22
- else {
23
- f(va);
24
- }
25
- }
26
- function forEachValueInNestedValueArray(va, f) {
27
- forEachArrayInNestedValueArray(va, a => {
28
- for (const x of a) {
29
- f(x);
30
- }
31
- });
32
- }
33
- class InferenceUnionBuilder extends UnionBuilder_1.UnionBuilder {
34
- _typeInference;
35
- _fixed;
36
- constructor(typeBuilder, _typeInference, _fixed) {
37
- super(typeBuilder);
38
- this._typeInference = _typeInference;
39
- this._fixed = _fixed;
40
- }
41
- makeObject(objects, typeAttributes, forwardingRef) {
42
- return this._typeInference.inferClassType(typeAttributes, objects, this._fixed, forwardingRef);
43
- }
44
- makeArray(arrays, typeAttributes, forwardingRef) {
45
- return this.typeBuilder.getArrayType(typeAttributes, this._typeInference.inferType(TypeAttributes_1.emptyTypeAttributes, arrays, this._fixed, forwardingRef));
46
- }
47
- }
48
- function canBeEnumCase(_s) {
49
- return true;
50
- }
51
- class TypeInference {
52
- _cjson;
53
- _typeBuilder;
54
- _inferMaps;
55
- _inferEnums;
56
- _refIntersections;
57
- constructor(_cjson, _typeBuilder, _inferMaps, _inferEnums) {
58
- this._cjson = _cjson;
59
- this._typeBuilder = _typeBuilder;
60
- this._inferMaps = _inferMaps;
61
- this._inferEnums = _inferEnums;
62
- }
63
- addValuesToAccumulator(valueArray, accumulator) {
64
- forEachValueInNestedValueArray(valueArray, value => {
65
- const t = (0, CompressedJSON_1.valueTag)(value);
66
- switch (t) {
67
- case CompressedJSON_1.Tag.Null:
68
- accumulator.addPrimitive("null", TypeAttributes_1.emptyTypeAttributes);
69
- break;
70
- case CompressedJSON_1.Tag.False:
71
- case CompressedJSON_1.Tag.True:
72
- accumulator.addPrimitive("bool", TypeAttributes_1.emptyTypeAttributes);
73
- break;
74
- case CompressedJSON_1.Tag.Integer:
75
- accumulator.addPrimitive("integer", TypeAttributes_1.emptyTypeAttributes);
76
- break;
77
- case CompressedJSON_1.Tag.Double:
78
- accumulator.addPrimitive("double", TypeAttributes_1.emptyTypeAttributes);
79
- break;
80
- case CompressedJSON_1.Tag.InternedString:
81
- if (this._inferEnums) {
82
- const s = this._cjson.getStringForValue(value);
83
- if (canBeEnumCase(s)) {
84
- accumulator.addStringCase(s, 1, TypeAttributes_1.emptyTypeAttributes);
85
- }
86
- else {
87
- accumulator.addStringType("string", TypeAttributes_1.emptyTypeAttributes);
88
- }
89
- }
90
- else {
91
- accumulator.addStringType("string", TypeAttributes_1.emptyTypeAttributes);
92
- }
93
- break;
94
- case CompressedJSON_1.Tag.UninternedString:
95
- accumulator.addStringType("string", TypeAttributes_1.emptyTypeAttributes);
96
- break;
97
- case CompressedJSON_1.Tag.Object:
98
- accumulator.addObject(this._cjson.getObjectForValue(value), TypeAttributes_1.emptyTypeAttributes);
99
- break;
100
- case CompressedJSON_1.Tag.Array:
101
- accumulator.addArray(this._cjson.getArrayForValue(value), TypeAttributes_1.emptyTypeAttributes);
102
- break;
103
- case CompressedJSON_1.Tag.StringFormat: {
104
- const kind = this._cjson.getStringFormatTypeKind(value);
105
- accumulator.addStringType("string", TypeAttributes_1.emptyTypeAttributes, new StringTypes_1.StringTypes(new Map(), new Set([kind])));
106
- break;
107
- }
108
- case CompressedJSON_1.Tag.TransformedString: {
109
- const s = this._cjson.getStringForValue(value);
110
- const kind = (0, StringTypes_1.inferTransformedStringTypeKindForString)(s, this._cjson.dateTimeRecognizer);
111
- if (kind === undefined) {
112
- return (0, Support_1.panic)("TransformedString does not have a kind");
113
- }
114
- const producer = (0, Support_1.defined)(Type_1.transformedStringTypeTargetTypeKindsMap.get(kind)).attributesProducer;
115
- if (producer === undefined) {
116
- return (0, Support_1.panic)("TransformedString does not have attribute producer");
117
- }
118
- accumulator.addStringType("string", producer(s), new StringTypes_1.StringTypes(new Map(), new Set([kind])));
119
- break;
120
- }
121
- default:
122
- return (0, Support_1.assertNever)(t);
123
- }
124
- });
125
- }
126
- inferType(typeAttributes, valueArray, fixed, forwardingRef) {
127
- const accumulator = this.accumulatorForArray(valueArray);
128
- return this.makeTypeFromAccumulator(accumulator, typeAttributes, fixed, forwardingRef);
129
- }
130
- resolveRef(ref, topLevel) {
131
- if (!ref.startsWith("#/")) {
132
- return (0, Messages_1.messageError)("InferenceJSONReferenceNotRooted", { reference: ref });
133
- }
134
- const parts = ref.split("/").slice(1);
135
- const graph = this._typeBuilder.typeGraph;
136
- let tref = topLevel;
137
- for (const part of parts) {
138
- let t = (0, TypeGraph_1.derefTypeRef)(tref, graph);
139
- if (t instanceof Type_1.UnionType) {
140
- const nullable = (0, TypeUtils_1.nullableFromUnion)(t);
141
- if (nullable === null) {
142
- // FIXME: handle unions
143
- return (0, Messages_1.messageError)("InferenceJSONReferenceToUnion", { reference: ref });
144
- }
145
- t = nullable;
146
- }
147
- if (t instanceof Type_1.ClassType) {
148
- const cp = t.getProperties().get(part);
149
- if (cp === undefined) {
150
- return (0, Messages_1.messageError)("InferenceJSONReferenceWrongProperty", { reference: ref });
151
- }
152
- tref = cp.typeRef;
153
- }
154
- else if (t instanceof Type_1.MapType) {
155
- tref = t.values.typeRef;
156
- }
157
- else if (t instanceof Type_1.ArrayType) {
158
- if (part.match("^[0-9]+$") === null) {
159
- return (0, Messages_1.messageError)("InferenceJSONReferenceInvalidArrayIndex", { reference: ref });
160
- }
161
- tref = t.items.typeRef;
162
- }
163
- else {
164
- return (0, Messages_1.messageError)("InferenceJSONReferenceWrongProperty", { reference: ref });
165
- }
166
- }
167
- return tref;
168
- }
169
- inferTopLevelType(typeAttributes, valueArray, fixed) {
170
- (0, Support_1.assert)(this._refIntersections === undefined, "Didn't reset ref intersections - nested invocations?");
171
- if (this._cjson.handleRefs) {
172
- this._refIntersections = [];
173
- }
174
- const topLevel = this.inferType(typeAttributes, valueArray, fixed);
175
- if (this._cjson.handleRefs) {
176
- for (const [tref, refs] of (0, Support_1.defined)(this._refIntersections)) {
177
- const resolved = refs.map(r => this.resolveRef(r, topLevel));
178
- this._typeBuilder.setSetOperationMembers(tref, new Set(resolved));
179
- }
180
- this._refIntersections = undefined;
181
- }
182
- return topLevel;
183
- }
184
- accumulatorForArray(valueArray) {
185
- const accumulator = new UnionBuilder_1.UnionAccumulator(true);
186
- this.addValuesToAccumulator(valueArray, accumulator);
187
- return accumulator;
188
- }
189
- makeTypeFromAccumulator(accumulator, typeAttributes, fixed, forwardingRef) {
190
- const unionBuilder = new InferenceUnionBuilder(this._typeBuilder, this, fixed);
191
- return unionBuilder.buildUnion(accumulator, false, typeAttributes, forwardingRef);
192
- }
193
- inferClassType(typeAttributes, objects, fixed, forwardingRef) {
194
- const propertyNames = [];
195
- const propertyValues = {};
196
- forEachArrayInNestedValueArray(objects, arr => {
197
- for (let i = 0; i < arr.length; i += 2) {
198
- const key = this._cjson.getStringForValue(arr[i]);
199
- const value = arr[i + 1];
200
- if (!Object.prototype.hasOwnProperty.call(propertyValues, key)) {
201
- propertyNames.push(key);
202
- propertyValues[key] = [];
203
- }
204
- propertyValues[key].push(value);
205
- }
206
- });
207
- if (this._cjson.handleRefs && propertyNames.length === 1 && propertyNames[0] === "$ref") {
208
- const values = propertyValues["$ref"];
209
- if (values.every(v => (0, CompressedJSON_1.valueTag)(v) === CompressedJSON_1.Tag.InternedString)) {
210
- const allRefs = values.map(v => this._cjson.getStringForValue(v));
211
- // FIXME: Add is-ref attribute
212
- const tref = this._typeBuilder.getUniqueIntersectionType(typeAttributes, undefined);
213
- (0, Support_1.defined)(this._refIntersections).push([tref, allRefs]);
214
- return tref;
215
- }
216
- }
217
- if (this._inferMaps && propertyNames.length > 500) {
218
- const accumulator = new UnionBuilder_1.UnionAccumulator(true);
219
- for (const key of propertyNames) {
220
- this.addValuesToAccumulator(propertyValues[key], accumulator);
221
- }
222
- const values = this.makeTypeFromAccumulator(accumulator, TypeAttributes_1.emptyTypeAttributes, fixed);
223
- return this._typeBuilder.getMapType(typeAttributes, values, forwardingRef);
224
- }
225
- const properties = new Map();
226
- for (const key of propertyNames) {
227
- const values = propertyValues[key];
228
- const t = this.inferType(TypeAttributes_1.emptyTypeAttributes, values, false);
229
- const isOptional = values.length < objects.length;
230
- properties.set(key, this._typeBuilder.makeClassProperty(t, isOptional));
231
- }
232
- if (fixed) {
233
- return this._typeBuilder.getUniqueClassType(typeAttributes, true, properties, forwardingRef);
234
- }
235
- else {
236
- return this._typeBuilder.getClassType(typeAttributes, properties, forwardingRef);
237
- }
238
- }
239
- }
240
- exports.TypeInference = TypeInference;
@@ -1,48 +0,0 @@
1
- import { CompressedJSON } from "./CompressedJSON";
2
- import { TypeBuilder } from "../TypeBuilder";
3
- import { TargetLanguage } from "../TargetLanguage";
4
- import { RunContext } from "../Run";
5
- export interface Input<T> {
6
- readonly kind: string;
7
- readonly needIR: boolean;
8
- readonly needSchemaProcessing: boolean;
9
- addSource(source: T): Promise<void>;
10
- addSourceSync(source: T): void;
11
- singleStringSchemaSource(): string | undefined;
12
- addTypes(ctx: RunContext, typeBuilder: TypeBuilder, inferMaps: boolean, inferEnums: boolean, fixedTopLevels: boolean): Promise<void>;
13
- addTypesSync(ctx: RunContext, typeBuilder: TypeBuilder, inferMaps: boolean, inferEnums: boolean, fixedTopLevels: boolean): void;
14
- }
15
- export interface JSONSourceData<T> {
16
- name: string;
17
- samples: T[];
18
- description?: string;
19
- }
20
- export declare class JSONInput<T> implements Input<JSONSourceData<T>> {
21
- private readonly _compressedJSON;
22
- readonly kind: string;
23
- readonly needIR: boolean;
24
- readonly needSchemaProcessing: boolean;
25
- private readonly _topLevels;
26
- constructor(_compressedJSON: CompressedJSON<T>);
27
- private addSample;
28
- private setDescription;
29
- private addSamples;
30
- addSource(source: JSONSourceData<T>): Promise<void>;
31
- addSourceSync(source: JSONSourceData<T>): void;
32
- singleStringSchemaSource(): undefined;
33
- addTypes(ctx: RunContext, typeBuilder: TypeBuilder, inferMaps: boolean, inferEnums: boolean, fixedTopLevels: boolean): Promise<void>;
34
- addTypesSync(_ctx: RunContext, typeBuilder: TypeBuilder, inferMaps: boolean, inferEnums: boolean, fixedTopLevels: boolean): void;
35
- }
36
- export declare function jsonInputForTargetLanguage(targetLanguage: string | TargetLanguage, languages?: TargetLanguage[], handleJSONRefs?: boolean): JSONInput<string>;
37
- export declare class InputData {
38
- private _inputs;
39
- addInput<T>(input: Input<T>): void;
40
- private getOrAddInput;
41
- addSource<T>(kind: string, source: T, makeInput: () => Input<T>): Promise<void>;
42
- addSourceSync<T>(kind: string, source: T, makeInput: () => Input<T>): void;
43
- addTypes(ctx: RunContext, typeBuilder: TypeBuilder, inferMaps: boolean, inferEnums: boolean, fixedTopLevels: boolean): Promise<void>;
44
- addTypesSync(ctx: RunContext, typeBuilder: TypeBuilder, inferMaps: boolean, inferEnums: boolean, fixedTopLevels: boolean): void;
45
- get needIR(): boolean;
46
- get needSchemaProcessing(): boolean;
47
- singleStringSchemaSource(): string | undefined;
48
- }