quicktype 17.0.6 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/CompressedJSONFromStream.js +26 -38
- package/dist/cli/GraphQLIntrospection.js +33 -41
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +4 -3
- package/dist/cli/index.js +363 -364
- package/dist/quicktype-core/Annotation.js +2 -0
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +104 -81
- package/dist/quicktype-core/DateTime.js +1 -0
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +13 -10
- package/dist/quicktype-core/EncodedMarkovChain.js +1 -0
- package/dist/quicktype-core/GatherNames.js +47 -25
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +23 -19
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +65 -54
- package/dist/quicktype-core/MakeTransformations.js +23 -22
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +9 -8
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +8 -3
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +76 -61
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +34 -17
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +6 -3
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +72 -67
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +19 -18
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +6 -2
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +94 -66
- package/dist/quicktype-core/Type.d.ts +41 -43
- package/dist/quicktype-core/Type.js +96 -71
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +53 -47
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +49 -40
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +23 -22
- package/dist/quicktype-core/UnifyClasses.js +16 -12
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +33 -30
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +18 -17
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +8 -4
- package/dist/quicktype-core/attributes/Description.js +6 -5
- package/dist/quicktype-core/attributes/EnumValues.js +4 -3
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +24 -21
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +12 -10
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +49 -21
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +10 -6
- package/dist/quicktype-core/index.js +128 -125
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +49 -54
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +5 -13
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +25 -17
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +38 -54
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +503 -523
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +24 -35
- package/dist/quicktype-core/input/PostmanCollection.js +2 -1
- package/dist/quicktype-core/input/io/NodeIO.js +55 -44
- package/dist/quicktype-core/input/io/get-stream/index.js +6 -2
- package/dist/quicktype-core/language/All.js +3 -2
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +185 -151
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +82 -72
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +18 -17
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +36 -34
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +47 -45
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +23 -20
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +25 -23
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +17 -16
- package/dist/quicktype-core/language/Java.d.ts +2 -2
- package/dist/quicktype-core/language/Java.js +97 -97
- package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
- package/dist/quicktype-core/language/JavaScript.js +19 -17
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +15 -13
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +12 -11
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +39 -37
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +45 -41
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +66 -41
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +18 -17
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +63 -64
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +21 -19
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +568 -565
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +28 -26
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +49 -24
- package/dist/quicktype-core/language/ruby/keywords.js +1 -0
- package/dist/quicktype-core/rewrites/CombineClasses.js +9 -8
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +18 -17
- package/dist/quicktype-core/rewrites/FlattenStrings.js +7 -6
- package/dist/quicktype-core/rewrites/FlattenUnions.js +9 -8
- package/dist/quicktype-core/rewrites/InferMaps.js +11 -10
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +8 -7
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +68 -67
- package/dist/quicktype-core/support/Acronyms.js +3 -1
- package/dist/quicktype-core/support/Chance.js +10 -0
- package/dist/quicktype-core/support/Converters.js +1 -0
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +17 -16
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +30 -6
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +1 -0
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +229 -212
- package/dist/quicktype-typescript-input/index.js +28 -4
- package/package.json +24 -20
|
@@ -4,7 +4,7 @@ import { StringTypeMapping } from "./TypeBuilder";
|
|
|
4
4
|
import { InputData } from "./input/Inputs";
|
|
5
5
|
import { TransformedStringTypeKind } from "./Type";
|
|
6
6
|
export declare function getTargetLanguage(nameOrInstance: string | TargetLanguage): TargetLanguage;
|
|
7
|
-
export
|
|
7
|
+
export type RendererOptions = {
|
|
8
8
|
[name: string]: string;
|
|
9
9
|
};
|
|
10
10
|
export interface InferenceFlag {
|
|
@@ -34,7 +34,7 @@ export declare const inferenceFlagsObject: {
|
|
|
34
34
|
description: string;
|
|
35
35
|
negationDescription: string;
|
|
36
36
|
explanation: string;
|
|
37
|
-
stringType: "
|
|
37
|
+
stringType: "date" | "time" | "date-time" | "uuid" | "uri" | "integer-string" | "bool-string";
|
|
38
38
|
order: number;
|
|
39
39
|
};
|
|
40
40
|
/** Whether to assume that JSON strings that look like dates are dates */
|
|
@@ -42,7 +42,7 @@ export declare const inferenceFlagsObject: {
|
|
|
42
42
|
description: string;
|
|
43
43
|
negationDescription: string;
|
|
44
44
|
explanation: string;
|
|
45
|
-
stringType: "
|
|
45
|
+
stringType: "date" | "time" | "date-time" | "uuid" | "uri" | "integer-string" | "bool-string";
|
|
46
46
|
order: number;
|
|
47
47
|
};
|
|
48
48
|
/** Whether to convert stringified integers to integers */
|
|
@@ -50,7 +50,7 @@ export declare const inferenceFlagsObject: {
|
|
|
50
50
|
description: string;
|
|
51
51
|
negationDescription: string;
|
|
52
52
|
explanation: string;
|
|
53
|
-
stringType: "
|
|
53
|
+
stringType: "date" | "time" | "date-time" | "uuid" | "uri" | "integer-string" | "bool-string";
|
|
54
54
|
order: number;
|
|
55
55
|
};
|
|
56
56
|
/** Whether to convert stringified booleans to boolean values */
|
|
@@ -58,7 +58,7 @@ export declare const inferenceFlagsObject: {
|
|
|
58
58
|
description: string;
|
|
59
59
|
negationDescription: string;
|
|
60
60
|
explanation: string;
|
|
61
|
-
stringType: "
|
|
61
|
+
stringType: "date" | "time" | "date-time" | "uuid" | "uri" | "integer-string" | "bool-string";
|
|
62
62
|
order: number;
|
|
63
63
|
};
|
|
64
64
|
/** Combine similar classes. This doesn't apply to classes from a schema, only from inference. */
|
|
@@ -76,19 +76,19 @@ export declare const inferenceFlagsObject: {
|
|
|
76
76
|
order: number;
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
|
-
export
|
|
79
|
+
export type InferenceFlagName = keyof typeof inferenceFlagsObject;
|
|
80
80
|
export declare const inferenceFlagNames: ("inferMaps" | "inferEnums" | "inferUuids" | "inferDateTimes" | "inferIntegerStrings" | "inferBooleanStrings" | "combineClasses" | "ignoreJsonRefs")[];
|
|
81
81
|
export declare const inferenceFlags: {
|
|
82
82
|
[F in InferenceFlagName]: InferenceFlag;
|
|
83
83
|
};
|
|
84
|
-
export
|
|
84
|
+
export type InferenceFlags = {
|
|
85
85
|
[F in InferenceFlagName]: boolean;
|
|
86
86
|
};
|
|
87
87
|
/**
|
|
88
88
|
* The options type for the main quicktype entry points,
|
|
89
89
|
* `quicktypeMultiFile` and `quicktype`.
|
|
90
90
|
*/
|
|
91
|
-
export
|
|
91
|
+
export type NonInferenceOptions = {
|
|
92
92
|
/**
|
|
93
93
|
* The target language for which to produce code. This can be either an instance of `TargetLanguage`,
|
|
94
94
|
* or a string specifying one of the names for quicktype's built-in target languages. For example,
|
|
@@ -139,7 +139,7 @@ export declare type NonInferenceOptions = {
|
|
|
139
139
|
/** Print schema resolving steps */
|
|
140
140
|
debugPrintSchemaResolving: boolean;
|
|
141
141
|
};
|
|
142
|
-
export
|
|
142
|
+
export type Options = NonInferenceOptions & InferenceFlags;
|
|
143
143
|
export interface RunContext {
|
|
144
144
|
stringTypeMapping: StringTypeMapping;
|
|
145
145
|
debugPrintReconstitution: boolean;
|
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
24
|
};
|
|
10
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;
|
|
11
27
|
const collection_utils_1 = require("collection-utils");
|
|
12
|
-
const targetLanguages = require("./language/All");
|
|
28
|
+
const targetLanguages = __importStar(require("./language/All"));
|
|
13
29
|
const Support_1 = require("./support/Support");
|
|
14
30
|
const CombineClasses_1 = require("./rewrites/CombineClasses");
|
|
15
31
|
const InferMaps_1 = require("./rewrites/InferMaps");
|
|
@@ -33,7 +49,7 @@ function getTargetLanguage(nameOrInstance) {
|
|
|
33
49
|
if (language !== undefined) {
|
|
34
50
|
return language;
|
|
35
51
|
}
|
|
36
|
-
return Messages_1.messageError("DriverUnknownOutputLanguage", { lang: nameOrInstance });
|
|
52
|
+
return (0, Messages_1.messageError)("DriverUnknownOutputLanguage", { lang: nameOrInstance });
|
|
37
53
|
}
|
|
38
54
|
exports.getTargetLanguage = getTargetLanguage;
|
|
39
55
|
exports.inferenceFlagsObject = {
|
|
@@ -128,6 +144,7 @@ function makeDefaultInferenceFlags() {
|
|
|
128
144
|
}
|
|
129
145
|
exports.defaultInferenceFlags = makeDefaultInferenceFlags();
|
|
130
146
|
class Run {
|
|
147
|
+
_options;
|
|
131
148
|
constructor(options) {
|
|
132
149
|
// We must not overwrite defaults with undefined values, which
|
|
133
150
|
// we sometimes get.
|
|
@@ -159,16 +176,14 @@ class Run {
|
|
|
159
176
|
get debugPrintSchemaResolving() {
|
|
160
177
|
return this._options.debugPrintSchemaResolving;
|
|
161
178
|
}
|
|
162
|
-
timeSync(name, f) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return result;
|
|
171
|
-
});
|
|
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;
|
|
172
187
|
}
|
|
173
188
|
time(name, f) {
|
|
174
189
|
const start = Date.now();
|
|
@@ -186,14 +201,10 @@ class Run {
|
|
|
186
201
|
const typeBuilder = new TypeBuilder_1.TypeBuilder(0, stringTypeMapping, this._options.alphabetizeProperties, this._options.allPropertiesOptional, this._options.checkProvenance, false);
|
|
187
202
|
return { targetLanguage, stringTypeMapping, conflateNumbers, typeBuilder };
|
|
188
203
|
}
|
|
189
|
-
makeGraph(allInputs) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return yield allInputs.addTypes(this, graphInputs.typeBuilder, this._options.inferMaps, this._options.inferEnums, this._options.fixedTopLevels);
|
|
194
|
-
}));
|
|
195
|
-
return this.processGraph(allInputs, graphInputs);
|
|
196
|
-
});
|
|
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);
|
|
197
208
|
}
|
|
198
209
|
makeGraphSync(allInputs) {
|
|
199
210
|
const graphInputs = this.makeGraphInputs();
|
|
@@ -209,7 +220,7 @@ class Run {
|
|
|
209
220
|
}
|
|
210
221
|
const debugPrintReconstitution = this.debugPrintReconstitution;
|
|
211
222
|
if (typeBuilder.didAddForwardingIntersection || !this._options.ignoreJsonRefs) {
|
|
212
|
-
this.time("remove indirection intersections", () => (graph = TypeGraph_1.removeIndirectionIntersections(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
223
|
+
this.time("remove indirection intersections", () => (graph = (0, TypeGraph_1.removeIndirectionIntersections)(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
213
224
|
}
|
|
214
225
|
let unionsDone = false;
|
|
215
226
|
if (allInputs.needSchemaProcessing || !this._options.ignoreJsonRefs) {
|
|
@@ -217,32 +228,32 @@ class Run {
|
|
|
217
228
|
do {
|
|
218
229
|
const graphBeforeRewrites = graph;
|
|
219
230
|
if (!intersectionsDone) {
|
|
220
|
-
this.time("resolve intersections", () => ([graph, intersectionsDone] = ResolveIntersections_1.resolveIntersections(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
231
|
+
this.time("resolve intersections", () => ([graph, intersectionsDone] = (0, ResolveIntersections_1.resolveIntersections)(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
221
232
|
}
|
|
222
233
|
if (!unionsDone) {
|
|
223
|
-
this.time("flatten unions", () => ([graph, unionsDone] = FlattenUnions_1.flattenUnions(graph, stringTypeMapping, conflateNumbers, true, debugPrintReconstitution)));
|
|
234
|
+
this.time("flatten unions", () => ([graph, unionsDone] = (0, FlattenUnions_1.flattenUnions)(graph, stringTypeMapping, conflateNumbers, true, debugPrintReconstitution)));
|
|
224
235
|
}
|
|
225
236
|
if (graph === graphBeforeRewrites) {
|
|
226
|
-
Support_1.assert(intersectionsDone && unionsDone, "Graph didn't change but we're not done");
|
|
237
|
+
(0, Support_1.assert)(intersectionsDone && unionsDone, "Graph didn't change but we're not done");
|
|
227
238
|
}
|
|
228
239
|
} while (!intersectionsDone || !unionsDone);
|
|
229
240
|
}
|
|
230
|
-
this.time("replace object type", () => (graph = ReplaceObjectType_1.replaceObjectType(graph, stringTypeMapping, conflateNumbers, targetLanguage.supportsFullObjectType, debugPrintReconstitution)));
|
|
241
|
+
this.time("replace object type", () => (graph = (0, ReplaceObjectType_1.replaceObjectType)(graph, stringTypeMapping, conflateNumbers, targetLanguage.supportsFullObjectType, debugPrintReconstitution)));
|
|
231
242
|
do {
|
|
232
|
-
this.time("flatten unions", () => ([graph, unionsDone] = FlattenUnions_1.flattenUnions(graph, stringTypeMapping, conflateNumbers, false, debugPrintReconstitution)));
|
|
243
|
+
this.time("flatten unions", () => ([graph, unionsDone] = (0, FlattenUnions_1.flattenUnions)(graph, stringTypeMapping, conflateNumbers, false, debugPrintReconstitution)));
|
|
233
244
|
} while (!unionsDone);
|
|
234
245
|
if (this._options.combineClasses) {
|
|
235
|
-
const combinedGraph = this.time("combine classes", () => CombineClasses_1.combineClasses(this, graph, this._options.alphabetizeProperties, true, false, debugPrintReconstitution));
|
|
246
|
+
const combinedGraph = this.time("combine classes", () => (0, CombineClasses_1.combineClasses)(this, graph, this._options.alphabetizeProperties, true, false, debugPrintReconstitution));
|
|
236
247
|
if (combinedGraph === graph) {
|
|
237
248
|
graph = combinedGraph;
|
|
238
249
|
}
|
|
239
250
|
else {
|
|
240
|
-
this.time("combine classes cleanup", () => (graph = CombineClasses_1.combineClasses(this, combinedGraph, this._options.alphabetizeProperties, false, true, debugPrintReconstitution)));
|
|
251
|
+
this.time("combine classes cleanup", () => (graph = (0, CombineClasses_1.combineClasses)(this, combinedGraph, this._options.alphabetizeProperties, false, true, debugPrintReconstitution)));
|
|
241
252
|
}
|
|
242
253
|
}
|
|
243
254
|
if (this._options.inferMaps) {
|
|
244
255
|
for (;;) {
|
|
245
|
-
const newGraph = this.time("infer maps", () => InferMaps_1.inferMaps(graph, stringTypeMapping, true, debugPrintReconstitution));
|
|
256
|
+
const newGraph = this.time("infer maps", () => (0, InferMaps_1.inferMaps)(graph, stringTypeMapping, true, debugPrintReconstitution));
|
|
246
257
|
if (newGraph === graph) {
|
|
247
258
|
break;
|
|
248
259
|
}
|
|
@@ -250,20 +261,20 @@ class Run {
|
|
|
250
261
|
}
|
|
251
262
|
}
|
|
252
263
|
const enumInference = allInputs.needSchemaProcessing ? "all" : this._options.inferEnums ? "infer" : "none";
|
|
253
|
-
this.time("expand strings", () => (graph = ExpandStrings_1.expandStrings(this, graph, enumInference)));
|
|
254
|
-
this.time("flatten unions", () => ([graph, unionsDone] = FlattenUnions_1.flattenUnions(graph, stringTypeMapping, conflateNumbers, false, debugPrintReconstitution)));
|
|
255
|
-
Support_1.assert(unionsDone, "We should only have to flatten unions once after expanding strings");
|
|
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");
|
|
256
267
|
if (allInputs.needSchemaProcessing) {
|
|
257
|
-
this.time("flatten strings", () => (graph = FlattenStrings_1.flattenStrings(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
268
|
+
this.time("flatten strings", () => (graph = (0, FlattenStrings_1.flattenStrings)(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
258
269
|
}
|
|
259
|
-
this.time("none to any", () => (graph = TypeGraph_1.noneToAny(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
270
|
+
this.time("none to any", () => (graph = (0, TypeGraph_1.noneToAny)(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
260
271
|
if (!targetLanguage.supportsOptionalClassProperties) {
|
|
261
|
-
this.time("optional to nullable", () => (graph = TypeGraph_1.optionalToNullable(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
272
|
+
this.time("optional to nullable", () => (graph = (0, TypeGraph_1.optionalToNullable)(graph, stringTypeMapping, debugPrintReconstitution)));
|
|
262
273
|
}
|
|
263
274
|
this.time("fixed point", () => (graph = graph.rewriteFixedPoint(false, debugPrintReconstitution)));
|
|
264
|
-
this.time("make transformations", () => (graph = MakeTransformations_1.makeTransformations(this, graph, targetLanguage)));
|
|
265
|
-
this.time("flatten unions", () => ([graph, unionsDone] = FlattenUnions_1.flattenUnions(graph, stringTypeMapping, conflateNumbers, false, debugPrintReconstitution)));
|
|
266
|
-
Support_1.assert(unionsDone, "We should only have to flatten unions once after making transformations");
|
|
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");
|
|
267
278
|
// Sometimes we combine classes in ways that will the order come out
|
|
268
279
|
// differently compared to what it would be from the equivalent schema,
|
|
269
280
|
// so we always just garbage collect to get a defined order and be done
|
|
@@ -275,7 +286,7 @@ class Run {
|
|
|
275
286
|
if (this._options.debugPrintGraph) {
|
|
276
287
|
console.log("\n# gather names");
|
|
277
288
|
}
|
|
278
|
-
this.time("gather names", () => GatherNames_1.gatherNames(graph, !allInputs.needSchemaProcessing, this._options.debugPrintGatherNames));
|
|
289
|
+
this.time("gather names", () => (0, GatherNames_1.gatherNames)(graph, !allInputs.needSchemaProcessing, this._options.debugPrintGatherNames));
|
|
279
290
|
if (this._options.debugPrintGraph) {
|
|
280
291
|
graph.printGraph();
|
|
281
292
|
}
|
|
@@ -286,7 +297,7 @@ class Run {
|
|
|
286
297
|
}
|
|
287
298
|
preRun() {
|
|
288
299
|
// FIXME: This makes quicktype not quite reentrant
|
|
289
|
-
TypeNames_1.initTypeNames();
|
|
300
|
+
(0, TypeNames_1.initTypeNames)();
|
|
290
301
|
const targetLanguage = getTargetLanguage(this._options.lang);
|
|
291
302
|
const inputData = this._options.inputData;
|
|
292
303
|
const needIR = inputData.needIR || targetLanguage.names.indexOf("schema") < 0;
|
|
@@ -299,16 +310,14 @@ class Run {
|
|
|
299
310
|
}
|
|
300
311
|
return [inputData, targetLanguage];
|
|
301
312
|
}
|
|
302
|
-
run() {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return this.renderGraph(targetLanguage, graph);
|
|
311
|
-
});
|
|
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);
|
|
312
321
|
}
|
|
313
322
|
runSync() {
|
|
314
323
|
const preRunResult = this.preRun();
|
|
@@ -332,10 +341,8 @@ class Run {
|
|
|
332
341
|
* @param options Partial options. For options that are not defined, the
|
|
333
342
|
* defaults will be used.
|
|
334
343
|
*/
|
|
335
|
-
function quicktypeMultiFile(options) {
|
|
336
|
-
return
|
|
337
|
-
return yield new Run(options).run();
|
|
338
|
-
});
|
|
344
|
+
async function quicktypeMultiFile(options) {
|
|
345
|
+
return await new Run(options).run();
|
|
339
346
|
}
|
|
340
347
|
exports.quicktypeMultiFile = quicktypeMultiFile;
|
|
341
348
|
function quicktypeMultiFileSync(options) {
|
|
@@ -355,7 +362,7 @@ function offsetSpan(span, lineOffset) {
|
|
|
355
362
|
*/
|
|
356
363
|
function combineRenderResults(result) {
|
|
357
364
|
if (result.size <= 1) {
|
|
358
|
-
const first = collection_utils_1.mapFirst(result);
|
|
365
|
+
const first = (0, collection_utils_1.mapFirst)(result);
|
|
359
366
|
if (first === undefined) {
|
|
360
367
|
return { lines: [], annotations: [] };
|
|
361
368
|
}
|
|
@@ -379,10 +386,8 @@ exports.combineRenderResults = combineRenderResults;
|
|
|
379
386
|
* @param options Partial options. For options that are not defined, the
|
|
380
387
|
* defaults will be used.
|
|
381
388
|
*/
|
|
382
|
-
function quicktype(options) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
return combineRenderResults(result);
|
|
386
|
-
});
|
|
389
|
+
async function quicktype(options) {
|
|
390
|
+
const result = await quicktypeMultiFile(options);
|
|
391
|
+
return combineRenderResults(result);
|
|
387
392
|
}
|
|
388
393
|
exports.quicktype = quicktype;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnnotationData } from "./Annotation";
|
|
2
2
|
import { Name } from "./Naming";
|
|
3
|
-
export
|
|
3
|
+
export type Source = TextSource | NewlineSource | SequenceSource | TableSource | AnnotatedSource | NameSource | ModifiedSource;
|
|
4
4
|
export interface TextSource {
|
|
5
5
|
kind: "text";
|
|
6
6
|
text: string;
|
|
@@ -32,7 +32,7 @@ export interface ModifiedSource {
|
|
|
32
32
|
source: Source;
|
|
33
33
|
}
|
|
34
34
|
export declare function newline(): NewlineSource;
|
|
35
|
-
export
|
|
35
|
+
export type Sourcelike = Source | string | Name | SourcelikeArray;
|
|
36
36
|
export interface SourcelikeArray extends Array<Sourcelike> {
|
|
37
37
|
}
|
|
38
38
|
export declare function sourcelikeToSource(sl: Sourcelike): Source;
|
|
@@ -56,7 +56,7 @@ export interface SerializedRenderResult {
|
|
|
56
56
|
annotations: ReadonlyArray<Annotation>;
|
|
57
57
|
}
|
|
58
58
|
export declare function serializeRenderResult(rootSource: Source, names: ReadonlyMap<Name, string>, indentation: string): SerializedRenderResult;
|
|
59
|
-
export
|
|
59
|
+
export type MultiWord = {
|
|
60
60
|
source: Sourcelike;
|
|
61
61
|
needsParens: boolean;
|
|
62
62
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const Naming_1 = require("./Naming");
|
|
5
6
|
const Support_1 = require("./support/Support");
|
|
@@ -24,7 +25,7 @@ function sourcelikeToSource(sl) {
|
|
|
24
25
|
}
|
|
25
26
|
return {
|
|
26
27
|
kind: "sequence",
|
|
27
|
-
sequence: collection_utils_1.arrayIntercalate(newline(), lines.map((l) => ({ kind: "text", text: l })))
|
|
28
|
+
sequence: (0, collection_utils_1.arrayIntercalate)(newline(), lines.map((l) => ({ kind: "text", text: l })))
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
if (sl instanceof Naming_1.Name) {
|
|
@@ -61,21 +62,21 @@ function sourceLineLength(source, names) {
|
|
|
61
62
|
case "text":
|
|
62
63
|
return source.text.length;
|
|
63
64
|
case "newline":
|
|
64
|
-
return Support_1.panic("Newline must not occur within a line.");
|
|
65
|
+
return (0, Support_1.panic)("Newline must not occur within a line.");
|
|
65
66
|
case "sequence":
|
|
66
67
|
return source.sequence
|
|
67
68
|
.map((s) => sourceLineLength(s, names))
|
|
68
69
|
.reduce((a, b) => a + b, 0);
|
|
69
70
|
case "table":
|
|
70
|
-
return Support_1.panic("Table must not occur within a line.");
|
|
71
|
+
return (0, Support_1.panic)("Table must not occur within a line.");
|
|
71
72
|
case "annotated":
|
|
72
73
|
return sourceLineLength(source.source, names);
|
|
73
74
|
case "name":
|
|
74
|
-
return Support_1.defined(names.get(source.named)).length;
|
|
75
|
+
return (0, Support_1.defined)(names.get(source.named)).length;
|
|
75
76
|
case "modified":
|
|
76
77
|
return serializeRenderResult(source, names, "").lines.join("\n").length;
|
|
77
78
|
default:
|
|
78
|
-
return Support_1.assertNever(source);
|
|
79
|
+
return (0, Support_1.assertNever)(source);
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
function serializeRenderResult(rootSource, names, indentation) {
|
|
@@ -87,7 +88,7 @@ function serializeRenderResult(rootSource, names, indentation) {
|
|
|
87
88
|
function indentIfNeeded() {
|
|
88
89
|
if (indentNeeded === 0)
|
|
89
90
|
return;
|
|
90
|
-
currentLine.push(Strings_1.repeatString(indentation, indentNeeded));
|
|
91
|
+
currentLine.push((0, Strings_1.repeatString)(indentation, indentNeeded));
|
|
91
92
|
indentNeeded = 0;
|
|
92
93
|
}
|
|
93
94
|
function flattenCurrentLine() {
|
|
@@ -124,24 +125,24 @@ function serializeRenderResult(rootSource, names, indentation) {
|
|
|
124
125
|
if (numRows === 0)
|
|
125
126
|
break;
|
|
126
127
|
const widths = t.map(l => l.map(s => sourceLineLength(s, names)));
|
|
127
|
-
const numColumns = Support_1.defined(collection_utils_1.iterableMax(t.map(l => l.length)));
|
|
128
|
+
const numColumns = (0, Support_1.defined)((0, collection_utils_1.iterableMax)(t.map(l => l.length)));
|
|
128
129
|
if (numColumns === 0)
|
|
129
130
|
break;
|
|
130
131
|
const columnWidths = [];
|
|
131
132
|
for (let i = 0; i < numColumns; i++) {
|
|
132
|
-
columnWidths.push(Support_1.defined(collection_utils_1.iterableMax(widths.map(l => collection_utils_1.withDefault(l[i], 0)))));
|
|
133
|
+
columnWidths.push((0, Support_1.defined)((0, collection_utils_1.iterableMax)(widths.map(l => (0, collection_utils_1.withDefault)(l[i], 0)))));
|
|
133
134
|
}
|
|
134
135
|
for (let y = 0; y < numRows; y++) {
|
|
135
136
|
indentIfNeeded();
|
|
136
|
-
const row = Support_1.defined(t[y]);
|
|
137
|
-
const rowWidths = Support_1.defined(widths[y]);
|
|
137
|
+
const row = (0, Support_1.defined)(t[y]);
|
|
138
|
+
const rowWidths = (0, Support_1.defined)(widths[y]);
|
|
138
139
|
for (let x = 0; x < numColumns; x++) {
|
|
139
140
|
const colWidth = columnWidths[x];
|
|
140
|
-
const src = collection_utils_1.withDefault(row[x], { kind: "text", text: "" });
|
|
141
|
-
const srcWidth = collection_utils_1.withDefault(rowWidths[x], 0);
|
|
141
|
+
const src = (0, collection_utils_1.withDefault)(row[x], { kind: "text", text: "" });
|
|
142
|
+
const srcWidth = (0, collection_utils_1.withDefault)(rowWidths[x], 0);
|
|
142
143
|
serializeToStringArray(src);
|
|
143
144
|
if (x < numColumns - 1 && srcWidth < colWidth) {
|
|
144
|
-
currentLine.push(Strings_1.repeatString(" ", colWidth - srcWidth));
|
|
145
|
+
currentLine.push((0, Strings_1.repeatString)(" ", colWidth - srcWidth));
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
if (y < numRows - 1) {
|
|
@@ -157,18 +158,18 @@ function serializeRenderResult(rootSource, names, indentation) {
|
|
|
157
158
|
annotations.push({ annotation: source.annotation, span: { start, end } });
|
|
158
159
|
break;
|
|
159
160
|
case "name":
|
|
160
|
-
Support_1.assert(names.has(source.named), "No name for Named");
|
|
161
|
+
(0, Support_1.assert)(names.has(source.named), "No name for Named");
|
|
161
162
|
indentIfNeeded();
|
|
162
|
-
currentLine.push(Support_1.defined(names.get(source.named)));
|
|
163
|
+
currentLine.push((0, Support_1.defined)(names.get(source.named)));
|
|
163
164
|
break;
|
|
164
165
|
case "modified":
|
|
165
166
|
indentIfNeeded();
|
|
166
167
|
const serialized = serializeRenderResult(source.source, names, indentation).lines;
|
|
167
|
-
Support_1.assert(serialized.length === 1, "Cannot modify more than one line.");
|
|
168
|
+
(0, Support_1.assert)(serialized.length === 1, "Cannot modify more than one line.");
|
|
168
169
|
currentLine.push(source.modifier(serialized[0]));
|
|
169
170
|
break;
|
|
170
171
|
default:
|
|
171
|
-
return Support_1.assertNever(source);
|
|
172
|
+
return (0, Support_1.assertNever)(source);
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
serializeToStringArray(rootSource);
|
|
@@ -181,7 +182,7 @@ function singleWord(...source) {
|
|
|
181
182
|
}
|
|
182
183
|
exports.singleWord = singleWord;
|
|
183
184
|
function multiWord(separator, ...words) {
|
|
184
|
-
Support_1.assert(words.length > 0, "Zero words is not multiple");
|
|
185
|
+
(0, Support_1.assert)(words.length > 0, "Zero words is not multiple");
|
|
185
186
|
if (words.length === 1) {
|
|
186
187
|
return singleWord(words[0]);
|
|
187
188
|
}
|
|
@@ -5,30 +5,30 @@ import { SerializedRenderResult } from "./Source";
|
|
|
5
5
|
import { StringTypeMapping } from "./TypeBuilder";
|
|
6
6
|
import { Type } from "./Type";
|
|
7
7
|
import { DateTimeRecognizer } from "./DateTime";
|
|
8
|
-
export
|
|
8
|
+
export type MultiFileRenderResult = ReadonlyMap<string, SerializedRenderResult>;
|
|
9
9
|
export declare abstract class TargetLanguage {
|
|
10
10
|
readonly displayName: string;
|
|
11
11
|
readonly names: string[];
|
|
12
12
|
readonly extension: string;
|
|
13
13
|
constructor(displayName: string, names: string[], extension: string);
|
|
14
14
|
protected abstract getOptions(): Option<any>[];
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
get optionDefinitions(): OptionDefinition[];
|
|
16
|
+
get cliOptionDefinitions(): {
|
|
17
17
|
display: OptionDefinition[];
|
|
18
18
|
actual: OptionDefinition[];
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
get name(): string;
|
|
21
21
|
protected abstract makeRenderer(renderContext: RenderContext, optionValues: {
|
|
22
22
|
[name: string]: any;
|
|
23
23
|
}): Renderer;
|
|
24
24
|
renderGraphAndSerialize(typeGraph: TypeGraph, givenOutputFilename: string, alphabetizeProperties: boolean, leadingComments: string[] | undefined, rendererOptions: {
|
|
25
25
|
[name: string]: any;
|
|
26
26
|
}, indentation?: string): MultiFileRenderResult;
|
|
27
|
-
protected
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
protected get defaultIndentation(): string;
|
|
28
|
+
get stringTypeMapping(): StringTypeMapping;
|
|
29
|
+
get supportsOptionalClassProperties(): boolean;
|
|
30
|
+
get supportsUnionsWithBothNumberTypes(): boolean;
|
|
31
|
+
get supportsFullObjectType(): boolean;
|
|
32
32
|
needsTransformerForType(_t: Type): boolean;
|
|
33
|
-
|
|
33
|
+
get dateTimeRecognizer(): DateTimeRecognizer;
|
|
34
34
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TargetLanguage = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const Source_1 = require("./Source");
|
|
5
6
|
const Support_1 = require("./support/Support");
|
|
6
7
|
const DateTime_1 = require("./DateTime");
|
|
7
8
|
class TargetLanguage {
|
|
9
|
+
displayName;
|
|
10
|
+
names;
|
|
11
|
+
extension;
|
|
8
12
|
constructor(displayName, names, extension) {
|
|
9
13
|
this.displayName = displayName;
|
|
10
14
|
this.names = names;
|
|
@@ -23,7 +27,7 @@ class TargetLanguage {
|
|
|
23
27
|
return { actual, display };
|
|
24
28
|
}
|
|
25
29
|
get name() {
|
|
26
|
-
return Support_1.defined(this.names[0]);
|
|
30
|
+
return (0, Support_1.defined)(this.names[0]);
|
|
27
31
|
}
|
|
28
32
|
renderGraphAndSerialize(typeGraph, givenOutputFilename, alphabetizeProperties, leadingComments, rendererOptions, indentation) {
|
|
29
33
|
if (indentation === undefined) {
|
|
@@ -35,7 +39,7 @@ class TargetLanguage {
|
|
|
35
39
|
renderer.setAlphabetizeProperties(alphabetizeProperties);
|
|
36
40
|
}
|
|
37
41
|
const renderResult = renderer.render(givenOutputFilename);
|
|
38
|
-
return collection_utils_1.mapMap(renderResult.sources, s => Source_1.serializeRenderResult(s, renderResult.names, Support_1.defined(indentation)));
|
|
42
|
+
return (0, collection_utils_1.mapMap)(renderResult.sources, s => (0, Source_1.serializeRenderResult)(s, renderResult.names, (0, Support_1.defined)(indentation)));
|
|
39
43
|
}
|
|
40
44
|
get defaultIndentation() {
|
|
41
45
|
return " ";
|