quicktype 18.0.6 → 19.0.5

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} +2 -1
  11. package/dist/{cli/index.js → index.js} +4 -4
  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,393 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.quicktype = exports.combineRenderResults = exports.quicktypeMultiFileSync = exports.quicktypeMultiFile = exports.defaultInferenceFlags = exports.inferenceFlags = exports.inferenceFlagNames = exports.inferenceFlagsObject = exports.getTargetLanguage = void 0;
27
- const collection_utils_1 = require("collection-utils");
28
- const targetLanguages = __importStar(require("./language/All"));
29
- const Support_1 = require("./support/Support");
30
- const CombineClasses_1 = require("./rewrites/CombineClasses");
31
- const InferMaps_1 = require("./rewrites/InferMaps");
32
- const TypeBuilder_1 = require("./TypeBuilder");
33
- const TypeGraph_1 = require("./TypeGraph");
34
- const TypeNames_1 = require("./attributes/TypeNames");
35
- const GatherNames_1 = require("./GatherNames");
36
- const ExpandStrings_1 = require("./rewrites/ExpandStrings");
37
- const FlattenUnions_1 = require("./rewrites/FlattenUnions");
38
- const ResolveIntersections_1 = require("./rewrites/ResolveIntersections");
39
- const ReplaceObjectType_1 = require("./rewrites/ReplaceObjectType");
40
- const Messages_1 = require("./Messages");
41
- const Inputs_1 = require("./input/Inputs");
42
- const FlattenStrings_1 = require("./rewrites/FlattenStrings");
43
- const MakeTransformations_1 = require("./MakeTransformations");
44
- function getTargetLanguage(nameOrInstance) {
45
- if (typeof nameOrInstance === "object") {
46
- return nameOrInstance;
47
- }
48
- const language = targetLanguages.languageNamed(nameOrInstance);
49
- if (language !== undefined) {
50
- return language;
51
- }
52
- return (0, Messages_1.messageError)("DriverUnknownOutputLanguage", { lang: nameOrInstance });
53
- }
54
- exports.getTargetLanguage = getTargetLanguage;
55
- exports.inferenceFlagsObject = {
56
- /** Whether to infer map types from JSON data */
57
- inferMaps: {
58
- description: "Detect maps",
59
- negationDescription: "Don't infer maps, always use classes",
60
- explanation: "Infer maps when object keys look like map keys.",
61
- order: 1
62
- },
63
- /** Whether to infer enum types from JSON data */
64
- inferEnums: {
65
- description: "Detect enums",
66
- negationDescription: "Don't infer enums, always use strings",
67
- explanation: "If string values occur within a relatively small domain,\ninfer them as enum values.",
68
- order: 2
69
- },
70
- /** Whether to convert UUID strings to UUID objects */
71
- inferUuids: {
72
- description: "Detect UUIDs",
73
- negationDescription: "Don't convert UUIDs to UUID objects",
74
- explanation: "Detect UUIDs like '123e4567-e89b-12d3-a456-426655440000' (partial support).",
75
- stringType: "uuid",
76
- order: 3
77
- },
78
- /** Whether to assume that JSON strings that look like dates are dates */
79
- inferDateTimes: {
80
- description: "Detect dates & times",
81
- negationDescription: "Don't infer dates or times",
82
- explanation: "Infer dates from strings (partial support).",
83
- stringType: "date-time",
84
- order: 4
85
- },
86
- /** Whether to convert stringified integers to integers */
87
- inferIntegerStrings: {
88
- description: "Detect integers in strings",
89
- negationDescription: "Don't convert stringified integers to integers",
90
- explanation: 'Automatically convert stringified integers to integers.\nFor example, "1" is converted to 1.',
91
- stringType: "integer-string",
92
- order: 5
93
- },
94
- /** Whether to convert stringified booleans to boolean values */
95
- inferBooleanStrings: {
96
- description: "Detect booleans in strings",
97
- negationDescription: "Don't convert stringified booleans to booleans",
98
- explanation: 'Automatically convert stringified booleans to booleans.\nFor example, "true" is converted to true.',
99
- stringType: "bool-string",
100
- order: 6
101
- },
102
- /** Combine similar classes. This doesn't apply to classes from a schema, only from inference. */
103
- combineClasses: {
104
- description: "Merge similar classes",
105
- negationDescription: "Don't combine similar classes",
106
- explanation: "Combine classes with significantly overlapping properties,\ntreating contingent properties as nullable.",
107
- order: 7
108
- },
109
- /** Whether to treat $ref as references within JSON */
110
- ignoreJsonRefs: {
111
- description: "Don't treat $ref as a reference in JSON",
112
- negationDescription: "Treat $ref as a reference in JSON",
113
- explanation: "Like in JSON Schema, allow objects like\n'{ $ref: \"#/foo/bar\" }' to refer\nto another part of the input.",
114
- order: 8
115
- }
116
- };
117
- exports.inferenceFlagNames = Object.getOwnPropertyNames(exports.inferenceFlagsObject);
118
- exports.inferenceFlags = exports.inferenceFlagsObject;
119
- const defaultOptions = {
120
- lang: "ts",
121
- inputData: new Inputs_1.InputData(),
122
- alphabetizeProperties: false,
123
- allPropertiesOptional: false,
124
- fixedTopLevels: false,
125
- noRender: false,
126
- leadingComments: undefined,
127
- rendererOptions: {},
128
- indentation: undefined,
129
- outputFilename: "stdout",
130
- debugPrintGraph: false,
131
- checkProvenance: false,
132
- debugPrintReconstitution: false,
133
- debugPrintGatherNames: false,
134
- debugPrintTransformations: false,
135
- debugPrintTimes: false,
136
- debugPrintSchemaResolving: false
137
- };
138
- function makeDefaultInferenceFlags() {
139
- const flags = {};
140
- for (const flag of exports.inferenceFlagNames) {
141
- flags[flag] = true;
142
- }
143
- return flags;
144
- }
145
- exports.defaultInferenceFlags = makeDefaultInferenceFlags();
146
- class Run {
147
- _options;
148
- constructor(options) {
149
- // We must not overwrite defaults with undefined values, which
150
- // we sometimes get.
151
- this._options = Object.assign({}, defaultOptions, exports.defaultInferenceFlags);
152
- for (const k of Object.getOwnPropertyNames(options)) {
153
- const v = options[k];
154
- if (v !== undefined) {
155
- this._options[k] = v;
156
- }
157
- }
158
- }
159
- get stringTypeMapping() {
160
- const targetLanguage = getTargetLanguage(this._options.lang);
161
- const mapping = new Map(targetLanguage.stringTypeMapping);
162
- for (const flag of exports.inferenceFlagNames) {
163
- const stringType = exports.inferenceFlags[flag].stringType;
164
- if (!this._options[flag] && stringType !== undefined) {
165
- mapping.set(stringType, "string");
166
- }
167
- }
168
- return mapping;
169
- }
170
- get debugPrintReconstitution() {
171
- return this._options.debugPrintReconstitution === true;
172
- }
173
- get debugPrintTransformations() {
174
- return this._options.debugPrintTransformations;
175
- }
176
- get debugPrintSchemaResolving() {
177
- return this._options.debugPrintSchemaResolving;
178
- }
179
- async timeSync(name, f) {
180
- const start = Date.now();
181
- const result = await f();
182
- const end = Date.now();
183
- if (this._options.debugPrintTimes) {
184
- console.log(`${name} took ${end - start}ms`);
185
- }
186
- return result;
187
- }
188
- time(name, f) {
189
- const start = Date.now();
190
- const result = f();
191
- const end = Date.now();
192
- if (this._options.debugPrintTimes) {
193
- console.log(`${name} took ${end - start}ms`);
194
- }
195
- return result;
196
- }
197
- makeGraphInputs() {
198
- const targetLanguage = getTargetLanguage(this._options.lang);
199
- const stringTypeMapping = this.stringTypeMapping;
200
- const conflateNumbers = !targetLanguage.supportsUnionsWithBothNumberTypes;
201
- const typeBuilder = new TypeBuilder_1.TypeBuilder(0, stringTypeMapping, this._options.alphabetizeProperties, this._options.allPropertiesOptional, this._options.checkProvenance, false);
202
- return { targetLanguage, stringTypeMapping, conflateNumbers, typeBuilder };
203
- }
204
- async makeGraph(allInputs) {
205
- const graphInputs = this.makeGraphInputs();
206
- await this.timeSync("read input", async () => await allInputs.addTypes(this, graphInputs.typeBuilder, this._options.inferMaps, this._options.inferEnums, this._options.fixedTopLevels));
207
- return this.processGraph(allInputs, graphInputs);
208
- }
209
- makeGraphSync(allInputs) {
210
- const graphInputs = this.makeGraphInputs();
211
- this.time("read input", () => allInputs.addTypesSync(this, graphInputs.typeBuilder, this._options.inferMaps, this._options.inferEnums, this._options.fixedTopLevels));
212
- return this.processGraph(allInputs, graphInputs);
213
- }
214
- processGraph(allInputs, graphInputs) {
215
- const { targetLanguage, stringTypeMapping, conflateNumbers, typeBuilder } = graphInputs;
216
- let graph = typeBuilder.finish();
217
- if (this._options.debugPrintGraph) {
218
- graph.setPrintOnRewrite();
219
- graph.printGraph();
220
- }
221
- const debugPrintReconstitution = this.debugPrintReconstitution;
222
- if (typeBuilder.didAddForwardingIntersection || !this._options.ignoreJsonRefs) {
223
- this.time("remove indirection intersections", () => (graph = (0, TypeGraph_1.removeIndirectionIntersections)(graph, stringTypeMapping, debugPrintReconstitution)));
224
- }
225
- let unionsDone = false;
226
- if (allInputs.needSchemaProcessing || !this._options.ignoreJsonRefs) {
227
- let intersectionsDone = false;
228
- do {
229
- const graphBeforeRewrites = graph;
230
- if (!intersectionsDone) {
231
- this.time("resolve intersections", () => ([graph, intersectionsDone] = (0, ResolveIntersections_1.resolveIntersections)(graph, stringTypeMapping, debugPrintReconstitution)));
232
- }
233
- if (!unionsDone) {
234
- this.time("flatten unions", () => ([graph, unionsDone] = (0, FlattenUnions_1.flattenUnions)(graph, stringTypeMapping, conflateNumbers, true, debugPrintReconstitution)));
235
- }
236
- if (graph === graphBeforeRewrites) {
237
- (0, Support_1.assert)(intersectionsDone && unionsDone, "Graph didn't change but we're not done");
238
- }
239
- } while (!intersectionsDone || !unionsDone);
240
- }
241
- this.time("replace object type", () => (graph = (0, ReplaceObjectType_1.replaceObjectType)(graph, stringTypeMapping, conflateNumbers, targetLanguage.supportsFullObjectType, debugPrintReconstitution)));
242
- do {
243
- this.time("flatten unions", () => ([graph, unionsDone] = (0, FlattenUnions_1.flattenUnions)(graph, stringTypeMapping, conflateNumbers, false, debugPrintReconstitution)));
244
- } while (!unionsDone);
245
- if (this._options.combineClasses) {
246
- const combinedGraph = this.time("combine classes", () => (0, CombineClasses_1.combineClasses)(this, graph, this._options.alphabetizeProperties, true, false, debugPrintReconstitution));
247
- if (combinedGraph === graph) {
248
- graph = combinedGraph;
249
- }
250
- else {
251
- this.time("combine classes cleanup", () => (graph = (0, CombineClasses_1.combineClasses)(this, combinedGraph, this._options.alphabetizeProperties, false, true, debugPrintReconstitution)));
252
- }
253
- }
254
- if (this._options.inferMaps) {
255
- for (;;) {
256
- const newGraph = this.time("infer maps", () => (0, InferMaps_1.inferMaps)(graph, stringTypeMapping, true, debugPrintReconstitution));
257
- if (newGraph === graph) {
258
- break;
259
- }
260
- graph = newGraph;
261
- }
262
- }
263
- const enumInference = allInputs.needSchemaProcessing ? "all" : this._options.inferEnums ? "infer" : "none";
264
- this.time("expand strings", () => (graph = (0, ExpandStrings_1.expandStrings)(this, graph, enumInference)));
265
- this.time("flatten unions", () => ([graph, unionsDone] = (0, FlattenUnions_1.flattenUnions)(graph, stringTypeMapping, conflateNumbers, false, debugPrintReconstitution)));
266
- (0, Support_1.assert)(unionsDone, "We should only have to flatten unions once after expanding strings");
267
- if (allInputs.needSchemaProcessing) {
268
- this.time("flatten strings", () => (graph = (0, FlattenStrings_1.flattenStrings)(graph, stringTypeMapping, debugPrintReconstitution)));
269
- }
270
- this.time("none to any", () => (graph = (0, TypeGraph_1.noneToAny)(graph, stringTypeMapping, debugPrintReconstitution)));
271
- if (!targetLanguage.supportsOptionalClassProperties) {
272
- this.time("optional to nullable", () => (graph = (0, TypeGraph_1.optionalToNullable)(graph, stringTypeMapping, debugPrintReconstitution)));
273
- }
274
- this.time("fixed point", () => (graph = graph.rewriteFixedPoint(false, debugPrintReconstitution)));
275
- this.time("make transformations", () => (graph = (0, MakeTransformations_1.makeTransformations)(this, graph, targetLanguage)));
276
- this.time("flatten unions", () => ([graph, unionsDone] = (0, FlattenUnions_1.flattenUnions)(graph, stringTypeMapping, conflateNumbers, false, debugPrintReconstitution)));
277
- (0, Support_1.assert)(unionsDone, "We should only have to flatten unions once after making transformations");
278
- // Sometimes we combine classes in ways that will the order come out
279
- // differently compared to what it would be from the equivalent schema,
280
- // so we always just garbage collect to get a defined order and be done
281
- // with it.
282
- // FIXME: We don't actually have to do this if any of the above graph
283
- // rewrites did anything. We could just check whether the current graph
284
- // is different from the one we started out with.
285
- this.time("GC", () => (graph = graph.garbageCollect(this._options.alphabetizeProperties, debugPrintReconstitution)));
286
- if (this._options.debugPrintGraph) {
287
- console.log("\n# gather names");
288
- }
289
- this.time("gather names", () => (0, GatherNames_1.gatherNames)(graph, !allInputs.needSchemaProcessing, this._options.debugPrintGatherNames));
290
- if (this._options.debugPrintGraph) {
291
- graph.printGraph();
292
- }
293
- return graph;
294
- }
295
- makeSimpleTextResult(lines) {
296
- return new Map([[this._options.outputFilename, { lines, annotations: [] }]]);
297
- }
298
- preRun() {
299
- // FIXME: This makes quicktype not quite reentrant
300
- (0, TypeNames_1.initTypeNames)();
301
- const targetLanguage = getTargetLanguage(this._options.lang);
302
- const inputData = this._options.inputData;
303
- const needIR = inputData.needIR || targetLanguage.names.indexOf("schema") < 0;
304
- const schemaString = needIR ? undefined : inputData.singleStringSchemaSource();
305
- if (schemaString !== undefined) {
306
- const lines = JSON.stringify(JSON.parse(schemaString), undefined, 4).split("\n");
307
- lines.push("");
308
- const srr = { lines, annotations: [] };
309
- return new Map([[this._options.outputFilename, srr]]);
310
- }
311
- return [inputData, targetLanguage];
312
- }
313
- async run() {
314
- const preRunResult = this.preRun();
315
- if (!Array.isArray(preRunResult)) {
316
- return preRunResult;
317
- }
318
- const [inputData, targetLanguage] = preRunResult;
319
- const graph = await this.makeGraph(inputData);
320
- return this.renderGraph(targetLanguage, graph);
321
- }
322
- runSync() {
323
- const preRunResult = this.preRun();
324
- if (!Array.isArray(preRunResult)) {
325
- return preRunResult;
326
- }
327
- const [inputData, targetLanguage] = preRunResult;
328
- const graph = this.makeGraphSync(inputData);
329
- return this.renderGraph(targetLanguage, graph);
330
- }
331
- renderGraph(targetLanguage, graph) {
332
- if (this._options.noRender) {
333
- return this.makeSimpleTextResult(["Done.", ""]);
334
- }
335
- return targetLanguage.renderGraphAndSerialize(graph, this._options.outputFilename, this._options.alphabetizeProperties, this._options.leadingComments, this._options.rendererOptions, this._options.indentation);
336
- }
337
- }
338
- /**
339
- * Run quicktype and produce one or more output files.
340
- *
341
- * @param options Partial options. For options that are not defined, the
342
- * defaults will be used.
343
- */
344
- async function quicktypeMultiFile(options) {
345
- return await new Run(options).run();
346
- }
347
- exports.quicktypeMultiFile = quicktypeMultiFile;
348
- function quicktypeMultiFileSync(options) {
349
- return new Run(options).runSync();
350
- }
351
- exports.quicktypeMultiFileSync = quicktypeMultiFileSync;
352
- function offsetLocation(loc, lineOffset) {
353
- return { line: loc.line + lineOffset, column: loc.column };
354
- }
355
- function offsetSpan(span, lineOffset) {
356
- return { start: offsetLocation(span.start, lineOffset), end: offsetLocation(span.end, lineOffset) };
357
- }
358
- /**
359
- * Combines a multi-file render result into a single output. All the files
360
- * are concatenated and prefixed with a `//`-style comment giving the
361
- * filename.
362
- */
363
- function combineRenderResults(result) {
364
- if (result.size <= 1) {
365
- const first = (0, collection_utils_1.mapFirst)(result);
366
- if (first === undefined) {
367
- return { lines: [], annotations: [] };
368
- }
369
- return first;
370
- }
371
- let lines = [];
372
- let annotations = [];
373
- for (const [filename, srr] of result) {
374
- const offset = lines.length + 2;
375
- lines = lines.concat([`// ${filename}`, ""], srr.lines);
376
- annotations = annotations.concat(srr.annotations.map(ann => ({ annotation: ann.annotation, span: offsetSpan(ann.span, offset) })));
377
- }
378
- return { lines, annotations };
379
- }
380
- exports.combineRenderResults = combineRenderResults;
381
- /**
382
- * Run quicktype like `quicktypeMultiFile`, but if there are multiple
383
- * output files they will all be squashed into one output, with comments at the
384
- * start of each file.
385
- *
386
- * @param options Partial options. For options that are not defined, the
387
- * defaults will be used.
388
- */
389
- async function quicktype(options) {
390
- const result = await quicktypeMultiFile(options);
391
- return combineRenderResults(result);
392
- }
393
- exports.quicktype = quicktype;
@@ -1,65 +0,0 @@
1
- import { AnnotationData } from "./Annotation";
2
- import { Name } from "./Naming";
3
- export type Source = TextSource | NewlineSource | SequenceSource | TableSource | AnnotatedSource | NameSource | ModifiedSource;
4
- export interface TextSource {
5
- kind: "text";
6
- text: string;
7
- }
8
- export interface NewlineSource {
9
- kind: "newline";
10
- indentationChange: number;
11
- }
12
- export interface SequenceSource {
13
- kind: "sequence";
14
- sequence: ReadonlyArray<Source>;
15
- }
16
- export interface TableSource {
17
- kind: "table";
18
- table: ReadonlyArray<ReadonlyArray<Source>>;
19
- }
20
- export interface AnnotatedSource {
21
- kind: "annotated";
22
- annotation: AnnotationData;
23
- source: Source;
24
- }
25
- export interface NameSource {
26
- kind: "name";
27
- named: Name;
28
- }
29
- export interface ModifiedSource {
30
- kind: "modified";
31
- modifier: (serialized: string) => string;
32
- source: Source;
33
- }
34
- export declare function newline(): NewlineSource;
35
- export type Sourcelike = Source | string | Name | SourcelikeArray;
36
- export interface SourcelikeArray extends Array<Sourcelike> {
37
- }
38
- export declare function sourcelikeToSource(sl: Sourcelike): Source;
39
- export declare function annotated(annotation: AnnotationData, sl: Sourcelike): Source;
40
- export declare function maybeAnnotated(doAnnotate: boolean, annotation: AnnotationData, sl: Sourcelike): Sourcelike;
41
- export declare function modifySource(modifier: (serialized: string) => string, sl: Sourcelike): Sourcelike;
42
- export interface Location {
43
- line: number;
44
- column: number;
45
- }
46
- export interface Span {
47
- start: Location;
48
- end: Location;
49
- }
50
- export interface Annotation {
51
- annotation: AnnotationData;
52
- span: Span;
53
- }
54
- export interface SerializedRenderResult {
55
- lines: string[];
56
- annotations: ReadonlyArray<Annotation>;
57
- }
58
- export declare function serializeRenderResult(rootSource: Source, names: ReadonlyMap<Name, string>, indentation: string): SerializedRenderResult;
59
- export type MultiWord = {
60
- source: Sourcelike;
61
- needsParens: boolean;
62
- };
63
- export declare function singleWord(...source: Sourcelike[]): MultiWord;
64
- export declare function multiWord(separator: Sourcelike, ...words: Sourcelike[]): MultiWord;
65
- export declare function parenIfNeeded({ source, needsParens }: MultiWord): Sourcelike;
@@ -1,204 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parenIfNeeded = exports.multiWord = exports.singleWord = exports.serializeRenderResult = exports.modifySource = exports.maybeAnnotated = exports.annotated = exports.sourcelikeToSource = exports.newline = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const Naming_1 = require("./Naming");
6
- const Support_1 = require("./support/Support");
7
- const Strings_1 = require("./support/Strings");
8
- function newline() {
9
- // We're returning a new object instead of using a singleton
10
- // here because `Renderer` will modify `indentationChange`.
11
- return { kind: "newline", indentationChange: 0 };
12
- }
13
- exports.newline = newline;
14
- function sourcelikeToSource(sl) {
15
- if (sl instanceof Array) {
16
- return {
17
- kind: "sequence",
18
- sequence: sl.map(sourcelikeToSource)
19
- };
20
- }
21
- if (typeof sl === "string") {
22
- const lines = sl.split("\n");
23
- if (lines.length === 1) {
24
- return { kind: "text", text: sl };
25
- }
26
- return {
27
- kind: "sequence",
28
- sequence: (0, collection_utils_1.arrayIntercalate)(newline(), lines.map((l) => ({ kind: "text", text: l })))
29
- };
30
- }
31
- if (sl instanceof Naming_1.Name) {
32
- return { kind: "name", named: sl };
33
- }
34
- return sl;
35
- }
36
- exports.sourcelikeToSource = sourcelikeToSource;
37
- function annotated(annotation, sl) {
38
- return {
39
- kind: "annotated",
40
- annotation,
41
- source: sourcelikeToSource(sl)
42
- };
43
- }
44
- exports.annotated = annotated;
45
- function maybeAnnotated(doAnnotate, annotation, sl) {
46
- if (!doAnnotate) {
47
- return sl;
48
- }
49
- return annotated(annotation, sl);
50
- }
51
- exports.maybeAnnotated = maybeAnnotated;
52
- function modifySource(modifier, sl) {
53
- return {
54
- kind: "modified",
55
- modifier,
56
- source: sourcelikeToSource(sl)
57
- };
58
- }
59
- exports.modifySource = modifySource;
60
- function sourceLineLength(source, names) {
61
- switch (source.kind) {
62
- case "text":
63
- return source.text.length;
64
- case "newline":
65
- return (0, Support_1.panic)("Newline must not occur within a line.");
66
- case "sequence":
67
- return source.sequence
68
- .map((s) => sourceLineLength(s, names))
69
- .reduce((a, b) => a + b, 0);
70
- case "table":
71
- return (0, Support_1.panic)("Table must not occur within a line.");
72
- case "annotated":
73
- return sourceLineLength(source.source, names);
74
- case "name":
75
- return (0, Support_1.defined)(names.get(source.named)).length;
76
- case "modified":
77
- return serializeRenderResult(source, names, "").lines.join("\n").length;
78
- default:
79
- return (0, Support_1.assertNever)(source);
80
- }
81
- }
82
- function serializeRenderResult(rootSource, names, indentation) {
83
- let indent = 0;
84
- let indentNeeded = 0;
85
- const lines = [];
86
- let currentLine = [];
87
- const annotations = [];
88
- function indentIfNeeded() {
89
- if (indentNeeded === 0)
90
- return;
91
- currentLine.push((0, Strings_1.repeatString)(indentation, indentNeeded));
92
- indentNeeded = 0;
93
- }
94
- function flattenCurrentLine() {
95
- const str = currentLine.join("");
96
- currentLine = [str];
97
- return str;
98
- }
99
- function currentLocation() {
100
- return { line: lines.length, column: flattenCurrentLine().length };
101
- }
102
- function finishLine() {
103
- lines.push(flattenCurrentLine());
104
- currentLine = [];
105
- }
106
- function serializeToStringArray(source) {
107
- switch (source.kind) {
108
- case "text":
109
- indentIfNeeded();
110
- currentLine.push(source.text);
111
- break;
112
- case "newline":
113
- finishLine();
114
- indent += source.indentationChange;
115
- indentNeeded = indent;
116
- break;
117
- case "sequence":
118
- for (const s of source.sequence) {
119
- serializeToStringArray(s);
120
- }
121
- break;
122
- case "table":
123
- const t = source.table;
124
- const numRows = t.length;
125
- if (numRows === 0)
126
- break;
127
- const widths = t.map(l => l.map(s => sourceLineLength(s, names)));
128
- const numColumns = (0, Support_1.defined)((0, collection_utils_1.iterableMax)(t.map(l => l.length)));
129
- if (numColumns === 0)
130
- break;
131
- const columnWidths = [];
132
- for (let i = 0; i < numColumns; i++) {
133
- columnWidths.push((0, Support_1.defined)((0, collection_utils_1.iterableMax)(widths.map(l => (0, collection_utils_1.withDefault)(l[i], 0)))));
134
- }
135
- for (let y = 0; y < numRows; y++) {
136
- indentIfNeeded();
137
- const row = (0, Support_1.defined)(t[y]);
138
- const rowWidths = (0, Support_1.defined)(widths[y]);
139
- for (let x = 0; x < numColumns; x++) {
140
- const colWidth = columnWidths[x];
141
- const src = (0, collection_utils_1.withDefault)(row[x], { kind: "text", text: "" });
142
- const srcWidth = (0, collection_utils_1.withDefault)(rowWidths[x], 0);
143
- serializeToStringArray(src);
144
- if (x < numColumns - 1 && srcWidth < colWidth) {
145
- currentLine.push((0, Strings_1.repeatString)(" ", colWidth - srcWidth));
146
- }
147
- }
148
- if (y < numRows - 1) {
149
- finishLine();
150
- indentNeeded = indent;
151
- }
152
- }
153
- break;
154
- case "annotated":
155
- const start = currentLocation();
156
- serializeToStringArray(source.source);
157
- const end = currentLocation();
158
- annotations.push({ annotation: source.annotation, span: { start, end } });
159
- break;
160
- case "name":
161
- (0, Support_1.assert)(names.has(source.named), "No name for Named");
162
- indentIfNeeded();
163
- currentLine.push((0, Support_1.defined)(names.get(source.named)));
164
- break;
165
- case "modified":
166
- indentIfNeeded();
167
- const serialized = serializeRenderResult(source.source, names, indentation).lines;
168
- (0, Support_1.assert)(serialized.length === 1, "Cannot modify more than one line.");
169
- currentLine.push(source.modifier(serialized[0]));
170
- break;
171
- default:
172
- return (0, Support_1.assertNever)(source);
173
- }
174
- }
175
- serializeToStringArray(rootSource);
176
- finishLine();
177
- return { lines, annotations: annotations };
178
- }
179
- exports.serializeRenderResult = serializeRenderResult;
180
- function singleWord(...source) {
181
- return { source, needsParens: false };
182
- }
183
- exports.singleWord = singleWord;
184
- function multiWord(separator, ...words) {
185
- (0, Support_1.assert)(words.length > 0, "Zero words is not multiple");
186
- if (words.length === 1) {
187
- return singleWord(words[0]);
188
- }
189
- const items = [];
190
- for (let i = 0; i < words.length; i++) {
191
- if (i > 0)
192
- items.push(separator);
193
- items.push(words[i]);
194
- }
195
- return { source: items, needsParens: true };
196
- }
197
- exports.multiWord = multiWord;
198
- function parenIfNeeded({ source, needsParens }) {
199
- if (needsParens) {
200
- return ["(", source, ")"];
201
- }
202
- return source;
203
- }
204
- exports.parenIfNeeded = parenIfNeeded;