quicktype 17.0.1 → 17.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/cli/CompressedJSONFromStream.js +26 -38
  2. package/dist/cli/GraphQLIntrospection.js +33 -41
  3. package/dist/cli/TypeSource.d.ts +1 -1
  4. package/dist/cli/URLGrammar.js +4 -3
  5. package/dist/cli/index.js +363 -364
  6. package/dist/quicktype-core/Annotation.js +2 -0
  7. package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
  8. package/dist/quicktype-core/ConvenienceRenderer.js +104 -81
  9. package/dist/quicktype-core/DateTime.js +1 -0
  10. package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
  11. package/dist/quicktype-core/DeclarationIR.js +13 -10
  12. package/dist/quicktype-core/EncodedMarkovChain.js +1 -0
  13. package/dist/quicktype-core/GatherNames.js +47 -25
  14. package/dist/quicktype-core/Graph.d.ts +2 -2
  15. package/dist/quicktype-core/Graph.js +23 -19
  16. package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
  17. package/dist/quicktype-core/GraphRewriting.js +65 -54
  18. package/dist/quicktype-core/MakeTransformations.js +23 -22
  19. package/dist/quicktype-core/MarkovChain.d.ts +3 -3
  20. package/dist/quicktype-core/MarkovChain.js +9 -8
  21. package/dist/quicktype-core/Messages.d.ts +3 -3
  22. package/dist/quicktype-core/Messages.js +8 -3
  23. package/dist/quicktype-core/Naming.d.ts +11 -11
  24. package/dist/quicktype-core/Naming.js +76 -61
  25. package/dist/quicktype-core/Renderer.d.ts +6 -6
  26. package/dist/quicktype-core/Renderer.js +34 -17
  27. package/dist/quicktype-core/RendererOptions.d.ts +5 -5
  28. package/dist/quicktype-core/RendererOptions.js +6 -3
  29. package/dist/quicktype-core/Run.d.ts +9 -9
  30. package/dist/quicktype-core/Run.js +72 -67
  31. package/dist/quicktype-core/Source.d.ts +3 -3
  32. package/dist/quicktype-core/Source.js +19 -18
  33. package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
  34. package/dist/quicktype-core/TargetLanguage.js +6 -2
  35. package/dist/quicktype-core/Transformers.d.ts +25 -25
  36. package/dist/quicktype-core/Transformers.js +94 -66
  37. package/dist/quicktype-core/Type.d.ts +41 -43
  38. package/dist/quicktype-core/Type.js +96 -71
  39. package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
  40. package/dist/quicktype-core/TypeBuilder.js +53 -47
  41. package/dist/quicktype-core/TypeGraph.d.ts +4 -4
  42. package/dist/quicktype-core/TypeGraph.js +49 -40
  43. package/dist/quicktype-core/TypeUtils.d.ts +2 -2
  44. package/dist/quicktype-core/TypeUtils.js +23 -22
  45. package/dist/quicktype-core/UnifyClasses.js +16 -12
  46. package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
  47. package/dist/quicktype-core/UnionBuilder.js +33 -30
  48. package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
  49. package/dist/quicktype-core/attributes/AccessorNames.js +18 -17
  50. package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
  51. package/dist/quicktype-core/attributes/Constraints.js +8 -4
  52. package/dist/quicktype-core/attributes/Description.js +6 -5
  53. package/dist/quicktype-core/attributes/EnumValues.js +4 -3
  54. package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
  55. package/dist/quicktype-core/attributes/StringTypes.js +24 -21
  56. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
  57. package/dist/quicktype-core/attributes/TypeAttributes.js +12 -10
  58. package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
  59. package/dist/quicktype-core/attributes/TypeNames.js +49 -21
  60. package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
  61. package/dist/quicktype-core/attributes/URIAttributes.js +10 -6
  62. package/dist/quicktype-core/index.js +128 -125
  63. package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
  64. package/dist/quicktype-core/input/CompressedJSON.js +49 -54
  65. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +5 -13
  66. package/dist/quicktype-core/input/Inference.d.ts +2 -2
  67. package/dist/quicktype-core/input/Inference.js +25 -17
  68. package/dist/quicktype-core/input/Inputs.d.ts +2 -2
  69. package/dist/quicktype-core/input/Inputs.js +38 -54
  70. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
  71. package/dist/quicktype-core/input/JSONSchemaInput.js +503 -523
  72. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
  73. package/dist/quicktype-core/input/JSONSchemaStore.js +24 -35
  74. package/dist/quicktype-core/input/PostmanCollection.js +2 -1
  75. package/dist/quicktype-core/input/io/NodeIO.js +55 -44
  76. package/dist/quicktype-core/input/io/get-stream/index.js +6 -2
  77. package/dist/quicktype-core/language/All.js +3 -2
  78. package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
  79. package/dist/quicktype-core/language/CPlusPlus.js +185 -151
  80. package/dist/quicktype-core/language/CSharp.d.ts +7 -7
  81. package/dist/quicktype-core/language/CSharp.js +82 -72
  82. package/dist/quicktype-core/language/Crystal.d.ts +2 -2
  83. package/dist/quicktype-core/language/Crystal.js +18 -17
  84. package/dist/quicktype-core/language/Dart.d.ts +4 -4
  85. package/dist/quicktype-core/language/Dart.js +36 -34
  86. package/dist/quicktype-core/language/Elm.d.ts +6 -6
  87. package/dist/quicktype-core/language/Elm.js +47 -45
  88. package/dist/quicktype-core/language/Golang.d.ts +4 -4
  89. package/dist/quicktype-core/language/Golang.js +23 -20
  90. package/dist/quicktype-core/language/Haskell.d.ts +5 -5
  91. package/dist/quicktype-core/language/Haskell.js +25 -23
  92. package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
  93. package/dist/quicktype-core/language/JSONSchema.js +17 -16
  94. package/dist/quicktype-core/language/Java.d.ts +2 -2
  95. package/dist/quicktype-core/language/Java.js +97 -97
  96. package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
  97. package/dist/quicktype-core/language/JavaScript.js +19 -17
  98. package/dist/quicktype-core/language/JavaScriptPropTypes.js +15 -13
  99. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +12 -11
  100. package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
  101. package/dist/quicktype-core/language/Kotlin.js +39 -37
  102. package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
  103. package/dist/quicktype-core/language/Objective-C.js +45 -41
  104. package/dist/quicktype-core/language/Php.d.ts +2 -2
  105. package/dist/quicktype-core/language/Php.js +66 -41
  106. package/dist/quicktype-core/language/Pike.d.ts +1 -1
  107. package/dist/quicktype-core/language/Pike.js +18 -17
  108. package/dist/quicktype-core/language/Python.d.ts +8 -8
  109. package/dist/quicktype-core/language/Python.js +63 -64
  110. package/dist/quicktype-core/language/Rust.d.ts +2 -2
  111. package/dist/quicktype-core/language/Rust.js +21 -19
  112. package/dist/quicktype-core/language/Swift.d.ts +7 -7
  113. package/dist/quicktype-core/language/Swift.js +568 -565
  114. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
  115. package/dist/quicktype-core/language/TypeScriptFlow.js +28 -26
  116. package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
  117. package/dist/quicktype-core/language/ruby/index.js +49 -24
  118. package/dist/quicktype-core/language/ruby/keywords.js +1 -0
  119. package/dist/quicktype-core/rewrites/CombineClasses.js +9 -8
  120. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
  121. package/dist/quicktype-core/rewrites/ExpandStrings.js +18 -17
  122. package/dist/quicktype-core/rewrites/FlattenStrings.js +7 -6
  123. package/dist/quicktype-core/rewrites/FlattenUnions.js +9 -8
  124. package/dist/quicktype-core/rewrites/InferMaps.js +11 -10
  125. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +8 -7
  126. package/dist/quicktype-core/rewrites/ResolveIntersections.js +68 -67
  127. package/dist/quicktype-core/support/Acronyms.js +3 -1
  128. package/dist/quicktype-core/support/Chance.js +10 -0
  129. package/dist/quicktype-core/support/Converters.js +1 -0
  130. package/dist/quicktype-core/support/Strings.d.ts +4 -4
  131. package/dist/quicktype-core/support/Strings.js +17 -16
  132. package/dist/quicktype-core/support/Support.d.ts +1 -1
  133. package/dist/quicktype-core/support/Support.js +30 -6
  134. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
  135. package/dist/quicktype-graphql-input/GraphQLSchema.js +1 -0
  136. package/dist/quicktype-graphql-input/index.d.ts +1 -1
  137. package/dist/quicktype-graphql-input/index.js +229 -212
  138. package/dist/quicktype-typescript-input/index.js +30 -5
  139. package/package.json +25 -19
package/dist/cli/index.js CHANGED
@@ -1,18 +1,35 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
10
25
  };
11
26
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const fs = require("fs");
13
- const path = require("path");
14
- const _ = require("lodash");
27
+ exports.main = exports.writeOutput = exports.makeQuicktypeOptions = exports.jsonInputForTargetLanguage = exports.parseCLIOptions = void 0;
28
+ const fs = __importStar(require("fs"));
29
+ const path = __importStar(require("path"));
30
+ const _ = __importStar(require("lodash"));
15
31
  const collection_utils_1 = require("collection-utils");
32
+ const ts_necessities_1 = require("@glideapps/ts-necessities");
16
33
  const quicktype_core_1 = require("../quicktype-core");
17
34
  const quicktype_typescript_input_1 = require("../quicktype-typescript-input");
18
35
  const quicktype_graphql_input_1 = require("../quicktype-graphql-input");
@@ -26,128 +43,122 @@ const chalk = require("chalk");
26
43
  const wordWrap = require("wordwrap")(90);
27
44
  const packageJSON = require("../../package.json");
28
45
  const defaultDefaultTargetLanguageName = "go";
29
- function sourceFromFileOrUrlArray(name, filesOrUrls, httpHeaders) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const samples = yield Promise.all(filesOrUrls.map(file => quicktype_core_1.readableFromFileOrURL(file, httpHeaders)));
32
- return { kind: "json", name, samples };
33
- });
46
+ async function sourceFromFileOrUrlArray(name, filesOrUrls, httpHeaders) {
47
+ const samples = await Promise.all(filesOrUrls.map(file => (0, quicktype_core_1.readableFromFileOrURL)(file, httpHeaders)));
48
+ return { kind: "json", name, samples };
34
49
  }
35
50
  function typeNameFromFilename(filename) {
36
51
  const name = path.basename(filename);
37
52
  return name.substring(0, name.lastIndexOf("."));
38
53
  }
39
- function samplesFromDirectory(dataDir, httpHeaders) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- function readFilesOrURLsInDirectory(d) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const files = fs
44
- .readdirSync(d)
45
- .map(x => path.join(d, x))
46
- .filter(x => fs.lstatSync(x).isFile());
47
- // Each file is a (Name, JSON | URL)
48
- const sourcesInDir = [];
49
- const graphQLSources = [];
50
- let graphQLSchema = undefined;
51
- let graphQLSchemaFileName = undefined;
52
- for (let file of files) {
53
- const name = typeNameFromFilename(file);
54
- let fileOrUrl = file;
55
- file = file.toLowerCase();
56
- // If file is a URL string, download it
57
- if (file.endsWith(".url")) {
58
- fileOrUrl = fs.readFileSync(file, "utf8").trim();
59
- }
60
- if (file.endsWith(".url") || file.endsWith(".json")) {
61
- sourcesInDir.push({
62
- kind: "json",
63
- name,
64
- samples: [yield quicktype_core_1.readableFromFileOrURL(fileOrUrl, httpHeaders)]
65
- });
66
- }
67
- else if (file.endsWith(".schema")) {
68
- sourcesInDir.push({
69
- kind: "schema",
70
- name,
71
- uris: [fileOrUrl]
72
- });
73
- }
74
- else if (file.endsWith(".gqlschema")) {
75
- quicktype_core_1.messageAssert(graphQLSchema === undefined, "DriverMoreThanOneGraphQLSchemaInDir", {
76
- dir: dataDir
77
- });
78
- graphQLSchema = yield quicktype_core_1.readableFromFileOrURL(fileOrUrl, httpHeaders);
79
- graphQLSchemaFileName = fileOrUrl;
80
- }
81
- else if (file.endsWith(".graphql")) {
82
- graphQLSources.push({
83
- kind: "graphql",
84
- name,
85
- schema: undefined,
86
- query: yield quicktype_core_1.getStream(yield quicktype_core_1.readableFromFileOrURL(fileOrUrl, httpHeaders))
87
- });
88
- }
89
- }
90
- if (graphQLSources.length > 0) {
91
- if (graphQLSchema === undefined) {
92
- return quicktype_core_1.messageError("DriverNoGraphQLSchemaInDir", { dir: dataDir });
93
- }
94
- const schema = quicktype_core_1.parseJSON(yield quicktype_core_1.getStream(graphQLSchema), "GraphQL schema", graphQLSchemaFileName);
95
- for (const source of graphQLSources) {
96
- source.schema = schema;
97
- sourcesInDir.push(source);
98
- }
99
- }
100
- return sourcesInDir;
101
- });
102
- }
103
- const contents = fs.readdirSync(dataDir).map(x => path.join(dataDir, x));
104
- const directories = contents.filter(x => fs.lstatSync(x).isDirectory());
105
- let sources = yield readFilesOrURLsInDirectory(dataDir);
106
- for (const dir of directories) {
107
- let jsonSamples = [];
108
- const schemaSources = [];
109
- const graphQLSources = [];
110
- for (const source of yield readFilesOrURLsInDirectory(dir)) {
111
- switch (source.kind) {
112
- case "json":
113
- jsonSamples = jsonSamples.concat(source.samples);
114
- break;
115
- case "schema":
116
- schemaSources.push(source);
117
- break;
118
- case "graphql":
119
- graphQLSources.push(source);
120
- break;
121
- default:
122
- return quicktype_core_1.assertNever(source);
123
- }
54
+ async function samplesFromDirectory(dataDir, httpHeaders) {
55
+ async function readFilesOrURLsInDirectory(d) {
56
+ const files = fs
57
+ .readdirSync(d)
58
+ .map(x => path.join(d, x))
59
+ .filter(x => fs.lstatSync(x).isFile());
60
+ // Each file is a (Name, JSON | URL)
61
+ const sourcesInDir = [];
62
+ const graphQLSources = [];
63
+ let graphQLSchema = undefined;
64
+ let graphQLSchemaFileName = undefined;
65
+ for (let file of files) {
66
+ const name = typeNameFromFilename(file);
67
+ let fileOrUrl = file;
68
+ file = file.toLowerCase();
69
+ // If file is a URL string, download it
70
+ if (file.endsWith(".url")) {
71
+ fileOrUrl = fs.readFileSync(file, "utf8").trim();
124
72
  }
125
- if (jsonSamples.length > 0 && schemaSources.length + graphQLSources.length > 0) {
126
- return quicktype_core_1.messageError("DriverCannotMixJSONWithOtherSamples", { dir: dir });
73
+ if (file.endsWith(".url") || file.endsWith(".json")) {
74
+ sourcesInDir.push({
75
+ kind: "json",
76
+ name,
77
+ samples: [await (0, quicktype_core_1.readableFromFileOrURL)(fileOrUrl, httpHeaders)]
78
+ });
127
79
  }
128
- const oneUnlessEmpty = (xs) => Math.sign(xs.length);
129
- if (oneUnlessEmpty(schemaSources) + oneUnlessEmpty(graphQLSources) > 1) {
130
- return quicktype_core_1.messageError("DriverCannotMixNonJSONInputs", { dir: dir });
80
+ else if (file.endsWith(".schema")) {
81
+ sourcesInDir.push({
82
+ kind: "schema",
83
+ name,
84
+ uris: [fileOrUrl]
85
+ });
131
86
  }
132
- if (jsonSamples.length > 0) {
133
- sources.push({
134
- kind: "json",
135
- name: path.basename(dir),
136
- samples: jsonSamples
87
+ else if (file.endsWith(".gqlschema")) {
88
+ (0, quicktype_core_1.messageAssert)(graphQLSchema === undefined, "DriverMoreThanOneGraphQLSchemaInDir", {
89
+ dir: dataDir
90
+ });
91
+ graphQLSchema = await (0, quicktype_core_1.readableFromFileOrURL)(fileOrUrl, httpHeaders);
92
+ graphQLSchemaFileName = fileOrUrl;
93
+ }
94
+ else if (file.endsWith(".graphql")) {
95
+ graphQLSources.push({
96
+ kind: "graphql",
97
+ name,
98
+ schema: undefined,
99
+ query: await (0, quicktype_core_1.getStream)(await (0, quicktype_core_1.readableFromFileOrURL)(fileOrUrl, httpHeaders))
137
100
  });
138
101
  }
139
- sources = sources.concat(schemaSources);
140
- sources = sources.concat(graphQLSources);
141
102
  }
142
- return sources;
143
- });
103
+ if (graphQLSources.length > 0) {
104
+ if (graphQLSchema === undefined) {
105
+ return (0, quicktype_core_1.messageError)("DriverNoGraphQLSchemaInDir", { dir: dataDir });
106
+ }
107
+ const schema = (0, quicktype_core_1.parseJSON)(await (0, quicktype_core_1.getStream)(graphQLSchema), "GraphQL schema", graphQLSchemaFileName);
108
+ for (const source of graphQLSources) {
109
+ source.schema = schema;
110
+ sourcesInDir.push(source);
111
+ }
112
+ }
113
+ return sourcesInDir;
114
+ }
115
+ const contents = fs.readdirSync(dataDir).map(x => path.join(dataDir, x));
116
+ const directories = contents.filter(x => fs.lstatSync(x).isDirectory());
117
+ let sources = await readFilesOrURLsInDirectory(dataDir);
118
+ for (const dir of directories) {
119
+ let jsonSamples = [];
120
+ const schemaSources = [];
121
+ const graphQLSources = [];
122
+ for (const source of await readFilesOrURLsInDirectory(dir)) {
123
+ switch (source.kind) {
124
+ case "json":
125
+ jsonSamples = jsonSamples.concat(source.samples);
126
+ break;
127
+ case "schema":
128
+ schemaSources.push(source);
129
+ break;
130
+ case "graphql":
131
+ graphQLSources.push(source);
132
+ break;
133
+ default:
134
+ return (0, quicktype_core_1.assertNever)(source);
135
+ }
136
+ }
137
+ if (jsonSamples.length > 0 && schemaSources.length + graphQLSources.length > 0) {
138
+ return (0, quicktype_core_1.messageError)("DriverCannotMixJSONWithOtherSamples", { dir: dir });
139
+ }
140
+ const oneUnlessEmpty = (xs) => Math.sign(xs.length);
141
+ if (oneUnlessEmpty(schemaSources) + oneUnlessEmpty(graphQLSources) > 1) {
142
+ return (0, quicktype_core_1.messageError)("DriverCannotMixNonJSONInputs", { dir: dir });
143
+ }
144
+ if (jsonSamples.length > 0) {
145
+ sources.push({
146
+ kind: "json",
147
+ name: path.basename(dir),
148
+ samples: jsonSamples
149
+ });
150
+ }
151
+ sources = sources.concat(schemaSources);
152
+ sources = sources.concat(graphQLSources);
153
+ }
154
+ return sources;
144
155
  }
145
156
  function inferLang(options, defaultLanguage) {
146
157
  // Output file extension determines the language if language is undefined
147
158
  if (options.out !== undefined) {
148
159
  let extension = path.extname(options.out);
149
160
  if (extension === "") {
150
- return quicktype_core_1.messageError("DriverNoLanguageOrExtension", {});
161
+ return (0, quicktype_core_1.messageError)("DriverNoLanguageOrExtension", {});
151
162
  }
152
163
  return extension.slice(1);
153
164
  }
@@ -172,15 +183,15 @@ function inferTopLevel(options) {
172
183
  function inferCLIOptions(opts, targetLanguage) {
173
184
  let srcLang = opts.srcLang;
174
185
  if (opts.graphqlSchema !== undefined || opts.graphqlIntrospect !== undefined) {
175
- quicktype_core_1.messageAssert(srcLang === undefined || srcLang === "graphql", "DriverSourceLangMustBeGraphQL", {});
186
+ (0, quicktype_core_1.messageAssert)(srcLang === undefined || srcLang === "graphql", "DriverSourceLangMustBeGraphQL", {});
176
187
  srcLang = "graphql";
177
188
  }
178
189
  else if (opts.src !== undefined && opts.src.length > 0 && opts.src.every(file => _.endsWith(file, ".ts"))) {
179
190
  srcLang = "typescript";
180
191
  }
181
192
  else {
182
- quicktype_core_1.messageAssert(srcLang !== "graphql", "DriverGraphQLSchemaNeeded", {});
183
- srcLang = collection_utils_1.withDefault(srcLang, "json");
193
+ (0, quicktype_core_1.messageAssert)(srcLang !== "graphql", "DriverGraphQLSchemaNeeded", {});
194
+ srcLang = (0, collection_utils_1.withDefault)(srcLang, "json");
184
195
  }
185
196
  let language;
186
197
  if (targetLanguage !== undefined) {
@@ -188,9 +199,9 @@ function inferCLIOptions(opts, targetLanguage) {
188
199
  }
189
200
  else {
190
201
  const languageName = opts.lang !== undefined ? opts.lang : inferLang(opts, defaultDefaultTargetLanguageName);
191
- const maybeLanguage = quicktype_core_1.languageNamed(languageName);
202
+ const maybeLanguage = (0, quicktype_core_1.languageNamed)(languageName);
192
203
  if (maybeLanguage === undefined) {
193
- return quicktype_core_1.messageError("DriverUnknownOutputLanguage", { lang: languageName });
204
+ return (0, quicktype_core_1.messageError)("DriverUnknownOutputLanguage", { lang: languageName });
194
205
  }
195
206
  language = maybeLanguage;
196
207
  }
@@ -226,7 +237,7 @@ function inferCLIOptions(opts, targetLanguage) {
226
237
  return options;
227
238
  }
228
239
  function makeLangTypeLabel(targetLanguages) {
229
- quicktype_core_1.assert(targetLanguages.length > 0, "Must have at least one target language");
240
+ (0, quicktype_core_1.assert)(targetLanguages.length > 0, "Must have at least one target language");
230
241
  return targetLanguages.map(r => _.minBy(r.names, s => s.length)).join("|");
231
242
  }
232
243
  function negatedInferenceFlagName(name) {
@@ -234,10 +245,10 @@ function negatedInferenceFlagName(name) {
234
245
  if (name.startsWith(prefix)) {
235
246
  name = name.slice(prefix.length);
236
247
  }
237
- return "no" + quicktype_core_1.capitalize(name);
248
+ return "no" + (0, quicktype_core_1.capitalize)(name);
238
249
  }
239
250
  function dashedFromCamelCase(name) {
240
- return quicktype_core_1.splitIntoWords(name)
251
+ return (0, quicktype_core_1.splitIntoWords)(name)
241
252
  .map(w => w.word.toLowerCase())
242
253
  .join("-");
243
254
  }
@@ -293,7 +304,7 @@ function makeOptionDefinitions(targetLanguages) {
293
304
  description: "Tracery grammar describing URLs to crawl."
294
305
  }
295
306
  ];
296
- const inference = Array.from(collection_utils_1.mapMap(collection_utils_1.mapFromObject(quicktype_core_1.inferenceFlags), (flag, name) => {
307
+ const inference = Array.from((0, collection_utils_1.mapMap)((0, collection_utils_1.mapFromObject)(quicktype_core_1.inferenceFlags), (flag, name) => {
297
308
  return {
298
309
  name: dashedFromCamelCase(negatedInferenceFlagName(name)),
299
310
  type: Boolean,
@@ -457,7 +468,7 @@ function parseCLIOptions(argv, targetLanguage) {
457
468
  // twice. This is the first parse to get the renderer:
458
469
  const incompleteOptions = inferCLIOptions(parseOptions(optionDefinitions, argv, true), targetLanguage);
459
470
  if (targetLanguage === undefined) {
460
- targetLanguage = quicktype_core_1.getTargetLanguage(incompleteOptions.lang);
471
+ targetLanguage = (0, quicktype_core_1.getTargetLanguage)(incompleteOptions.lang);
461
472
  }
462
473
  const rendererOptionDefinitions = targetLanguage.cliOptionDefinitions.actual;
463
474
  // Use the global options as well as the renderer options from now on:
@@ -475,19 +486,19 @@ function parseOptions(definitions, argv, partial) {
475
486
  opts = commandLineArgs(definitions, { argv, partial });
476
487
  }
477
488
  catch (e) {
478
- quicktype_core_1.assert(!partial, "Partial option parsing should not have failed");
479
- return quicktype_core_1.messageError("DriverCLIOptionParsingFailed", { message: e.message });
489
+ (0, quicktype_core_1.assert)(!partial, "Partial option parsing should not have failed");
490
+ return (0, quicktype_core_1.messageError)("DriverCLIOptionParsingFailed", { message: (0, ts_necessities_1.exceptionToString)(e) });
480
491
  }
481
492
  for (const k of Object.keys(opts)) {
482
493
  if (opts[k] === null) {
483
- return quicktype_core_1.messageError("DriverCLIOptionParsingFailed", {
494
+ return (0, quicktype_core_1.messageError)("DriverCLIOptionParsingFailed", {
484
495
  message: `Missing value for command line option "${k}"`
485
496
  });
486
497
  }
487
498
  }
488
499
  const options = { rendererOptions: {} };
489
500
  for (const o of definitions) {
490
- if (!collection_utils_1.hasOwnProperty(opts, o.name))
501
+ if (!(0, collection_utils_1.hasOwnProperty)(opts, o.name))
491
502
  continue;
492
503
  const v = opts[o.name];
493
504
  if (o.renderer !== undefined)
@@ -515,244 +526,234 @@ function usage(targetLanguages) {
515
526
  console.log(getUsage(sections));
516
527
  }
517
528
  // Returns an array of [name, sourceURIs] pairs.
518
- function getSourceURIs(options) {
519
- return __awaiter(this, void 0, void 0, function* () {
520
- if (options.srcUrls !== undefined) {
521
- const json = quicktype_core_1.parseJSON(yield quicktype_core_1.readFromFileOrURL(options.srcUrls, options.httpHeader), "URL grammar", options.srcUrls);
522
- const jsonMap = URLGrammar_1.urlsFromURLGrammar(json);
523
- const topLevels = Object.getOwnPropertyNames(jsonMap);
524
- return topLevels.map(name => [name, jsonMap[name]]);
525
- }
526
- else if (options.src.length === 0) {
527
- return [[options.topLevel, ["-"]]];
528
- }
529
- else {
530
- return [];
531
- }
532
- });
529
+ async function getSourceURIs(options) {
530
+ if (options.srcUrls !== undefined) {
531
+ const json = (0, quicktype_core_1.parseJSON)(await (0, quicktype_core_1.readFromFileOrURL)(options.srcUrls, options.httpHeader), "URL grammar", options.srcUrls);
532
+ const jsonMap = (0, URLGrammar_1.urlsFromURLGrammar)(json);
533
+ const topLevels = Object.getOwnPropertyNames(jsonMap);
534
+ return topLevels.map(name => [name, jsonMap[name]]);
535
+ }
536
+ else if (options.src.length === 0) {
537
+ return [[options.topLevel, ["-"]]];
538
+ }
539
+ else {
540
+ return [];
541
+ }
533
542
  }
534
- function typeSourcesForURIs(name, uris, options) {
535
- return __awaiter(this, void 0, void 0, function* () {
536
- switch (options.srcLang) {
537
- case "json":
538
- return [yield sourceFromFileOrUrlArray(name, uris, options.httpHeader)];
539
- case "schema":
540
- return uris.map(uri => ({ kind: "schema", name, uris: [uri] }));
541
- default:
542
- return quicktype_core_1.panic(`typeSourceForURIs must not be called for source language ${options.srcLang}`);
543
- }
544
- });
543
+ async function typeSourcesForURIs(name, uris, options) {
544
+ switch (options.srcLang) {
545
+ case "json":
546
+ return [await sourceFromFileOrUrlArray(name, uris, options.httpHeader)];
547
+ case "schema":
548
+ return uris.map(uri => ({ kind: "schema", name, uris: [uri] }));
549
+ default:
550
+ return (0, quicktype_core_1.panic)(`typeSourceForURIs must not be called for source language ${options.srcLang}`);
551
+ }
545
552
  }
546
- function getSources(options) {
547
- return __awaiter(this, void 0, void 0, function* () {
548
- const sourceURIs = yield getSourceURIs(options);
549
- const sourceArrays = yield Promise.all(sourceURIs.map(([name, uris]) => __awaiter(this, void 0, void 0, function* () { return yield typeSourcesForURIs(name, uris, options); })));
550
- let sources = [].concat(...sourceArrays);
551
- const exists = options.src.filter(fs.existsSync);
552
- const directories = exists.filter(x => fs.lstatSync(x).isDirectory());
553
- for (const dataDir of directories) {
554
- sources = sources.concat(yield samplesFromDirectory(dataDir, options.httpHeader));
555
- }
556
- // Every src that's not a directory is assumed to be a file or URL
557
- const filesOrUrls = options.src.filter(x => !_.includes(directories, x));
558
- if (!_.isEmpty(filesOrUrls)) {
559
- sources.push(...(yield typeSourcesForURIs(options.topLevel, filesOrUrls, options)));
560
- }
561
- return sources;
562
- });
553
+ async function getSources(options) {
554
+ const sourceURIs = await getSourceURIs(options);
555
+ const sourceArrays = await Promise.all(sourceURIs.map(async ([name, uris]) => await typeSourcesForURIs(name, uris, options)));
556
+ let sources = [].concat(...sourceArrays);
557
+ const exists = options.src.filter(fs.existsSync);
558
+ const directories = exists.filter(x => fs.lstatSync(x).isDirectory());
559
+ for (const dataDir of directories) {
560
+ sources = sources.concat(await samplesFromDirectory(dataDir, options.httpHeader));
561
+ }
562
+ // Every src that's not a directory is assumed to be a file or URL
563
+ const filesOrUrls = options.src.filter(x => !_.includes(directories, x));
564
+ if (!_.isEmpty(filesOrUrls)) {
565
+ sources.push(...(await typeSourcesForURIs(options.topLevel, filesOrUrls, options)));
566
+ }
567
+ return sources;
563
568
  }
564
569
  function makeTypeScriptSource(fileNames) {
565
- return Object.assign({ kind: "schema" }, quicktype_typescript_input_1.schemaForTypeScriptSources(fileNames));
570
+ return Object.assign({ kind: "schema" }, (0, quicktype_typescript_input_1.schemaForTypeScriptSources)(fileNames));
566
571
  }
567
572
  function jsonInputForTargetLanguage(targetLanguage, languages, handleJSONRefs = false) {
568
573
  if (typeof targetLanguage === "string") {
569
- targetLanguage = quicktype_core_1.defined(quicktype_core_1.languageNamed(targetLanguage, languages));
574
+ targetLanguage = (0, quicktype_core_1.defined)((0, quicktype_core_1.languageNamed)(targetLanguage, languages));
570
575
  }
571
576
  const compressedJSON = new CompressedJSONFromStream_1.CompressedJSONFromStream(targetLanguage.dateTimeRecognizer, handleJSONRefs);
572
577
  return new quicktype_core_1.JSONInput(compressedJSON);
573
578
  }
574
579
  exports.jsonInputForTargetLanguage = jsonInputForTargetLanguage;
575
- function makeInputData(sources, targetLanguage, additionalSchemaAddresses, handleJSONRefs, httpHeaders) {
576
- return __awaiter(this, void 0, void 0, function* () {
577
- const inputData = new quicktype_core_1.InputData();
578
- for (const source of sources) {
579
- switch (source.kind) {
580
- case "graphql":
581
- yield inputData.addSource("graphql", source, () => new quicktype_graphql_input_1.GraphQLInput());
582
- break;
583
- case "json":
584
- yield inputData.addSource("json", source, () => jsonInputForTargetLanguage(targetLanguage, undefined, handleJSONRefs));
585
- break;
586
- case "schema":
587
- yield inputData.addSource("schema", source, () => new quicktype_core_1.JSONSchemaInput(new quicktype_core_1.FetchingJSONSchemaStore(httpHeaders), [], additionalSchemaAddresses));
588
- break;
589
- default:
590
- return quicktype_core_1.assertNever(source);
591
- }
592
- }
593
- return inputData;
594
- });
595
- }
596
- function stringSourceDataToStreamSourceData(src) {
597
- return { name: src.name, description: src.description, samples: src.samples.map(stringToStream) };
598
- }
599
- function makeQuicktypeOptions(options, targetLanguages) {
600
- return __awaiter(this, void 0, void 0, function* () {
601
- if (options.help) {
602
- usage(targetLanguages === undefined ? quicktype_core_1.defaultTargetLanguages : targetLanguages);
603
- return undefined;
604
- }
605
- if (options.version) {
606
- console.log(`quicktype version ${packageJSON.version}`);
607
- console.log("Visit quicktype.io for more info.");
608
- return undefined;
609
- }
610
- if (options.buildMarkovChain !== undefined) {
611
- const contents = fs.readFileSync(options.buildMarkovChain).toString();
612
- const lines = contents.split("\n");
613
- const mc = quicktype_core_1.trainMarkovChain(lines, 3);
614
- console.log(JSON.stringify(mc));
615
- return undefined;
616
- }
617
- let sources = [];
618
- let leadingComments = undefined;
619
- let fixedTopLevels = false;
620
- switch (options.srcLang) {
580
+ async function makeInputData(sources, targetLanguage, additionalSchemaAddresses, handleJSONRefs, httpHeaders) {
581
+ const inputData = new quicktype_core_1.InputData();
582
+ for (const source of sources) {
583
+ switch (source.kind) {
621
584
  case "graphql":
622
- let schemaString = undefined;
623
- let wroteSchemaToFile = false;
624
- if (options.graphqlIntrospect !== undefined) {
625
- schemaString = yield GraphQLIntrospection_1.introspectServer(options.graphqlIntrospect, collection_utils_1.withDefault(options.httpMethod, "POST"), collection_utils_1.withDefault(options.httpHeader, []));
626
- if (options.graphqlSchema !== undefined) {
627
- fs.writeFileSync(options.graphqlSchema, schemaString);
628
- wroteSchemaToFile = true;
629
- }
630
- }
631
- const numSources = options.src.length;
632
- if (numSources !== 1) {
633
- if (wroteSchemaToFile) {
634
- // We're done.
635
- return undefined;
636
- }
637
- if (numSources === 0) {
638
- if (schemaString !== undefined) {
639
- console.log(schemaString);
640
- return undefined;
641
- }
642
- return quicktype_core_1.messageError("DriverNoGraphQLQueryGiven", {});
643
- }
644
- }
645
- const gqlSources = [];
646
- for (const queryFile of options.src) {
647
- let schemaFileName = undefined;
648
- if (schemaString === undefined) {
649
- schemaFileName = quicktype_core_1.defined(options.graphqlSchema);
650
- schemaString = fs.readFileSync(schemaFileName, "utf8");
651
- }
652
- const schema = quicktype_core_1.parseJSON(schemaString, "GraphQL schema", schemaFileName);
653
- const query = yield quicktype_core_1.getStream(yield quicktype_core_1.readableFromFileOrURL(queryFile, options.httpHeader));
654
- const name = numSources === 1 ? options.topLevel : typeNameFromFilename(queryFile);
655
- gqlSources.push({ kind: "graphql", name, schema, query });
656
- }
657
- sources = gqlSources;
585
+ await inputData.addSource("graphql", source, () => new quicktype_graphql_input_1.GraphQLInput());
658
586
  break;
659
587
  case "json":
660
- case "schema":
661
- sources = yield getSources(options);
662
- break;
663
- case "typescript":
664
- sources = [makeTypeScriptSource(options.src)];
588
+ await inputData.addSource("json", source, () => jsonInputForTargetLanguage(targetLanguage, undefined, handleJSONRefs));
665
589
  break;
666
- case "postman":
667
- for (const collectionFile of options.src) {
668
- const collectionJSON = fs.readFileSync(collectionFile, "utf8");
669
- const { sources: postmanSources, description } = quicktype_core_1.sourcesFromPostmanCollection(collectionJSON, collectionFile);
670
- for (const src of postmanSources) {
671
- sources.push(Object.assign({ kind: "json" }, stringSourceDataToStreamSourceData(src)));
672
- }
673
- if (postmanSources.length > 1) {
674
- fixedTopLevels = true;
675
- }
676
- if (description !== undefined) {
677
- leadingComments = wordWrap(description).split("\n");
678
- }
679
- }
590
+ case "schema":
591
+ await inputData.addSource("schema", source, () => new quicktype_core_1.JSONSchemaInput(new quicktype_core_1.FetchingJSONSchemaStore(httpHeaders), [], additionalSchemaAddresses));
680
592
  break;
681
593
  default:
682
- return quicktype_core_1.messageError("DriverUnknownSourceLanguage", { lang: options.srcLang });
594
+ return (0, quicktype_core_1.assertNever)(source);
683
595
  }
684
- const components = collection_utils_1.definedMap(options.debug, d => d.split(","));
685
- const debugAll = components !== undefined && components.indexOf("all") >= 0;
686
- let debugPrintGraph = debugAll;
687
- let checkProvenance = debugAll;
688
- let debugPrintReconstitution = debugAll;
689
- let debugPrintGatherNames = debugAll;
690
- let debugPrintTransformations = debugAll;
691
- let debugPrintSchemaResolving = debugAll;
692
- let debugPrintTimes = debugAll;
693
- if (components !== undefined) {
694
- for (let component of components) {
695
- component = component.trim();
696
- if (component === "print-graph") {
697
- debugPrintGraph = true;
698
- }
699
- else if (component === "print-reconstitution") {
700
- debugPrintReconstitution = true;
596
+ }
597
+ return inputData;
598
+ }
599
+ function stringSourceDataToStreamSourceData(src) {
600
+ return { name: src.name, description: src.description, samples: src.samples.map(stringToStream) };
601
+ }
602
+ async function makeQuicktypeOptions(options, targetLanguages) {
603
+ if (options.help) {
604
+ usage(targetLanguages === undefined ? quicktype_core_1.defaultTargetLanguages : targetLanguages);
605
+ return undefined;
606
+ }
607
+ if (options.version) {
608
+ console.log(`quicktype version ${packageJSON.version}`);
609
+ console.log("Visit quicktype.io for more info.");
610
+ return undefined;
611
+ }
612
+ if (options.buildMarkovChain !== undefined) {
613
+ const contents = fs.readFileSync(options.buildMarkovChain).toString();
614
+ const lines = contents.split("\n");
615
+ const mc = (0, quicktype_core_1.trainMarkovChain)(lines, 3);
616
+ console.log(JSON.stringify(mc));
617
+ return undefined;
618
+ }
619
+ let sources = [];
620
+ let leadingComments = undefined;
621
+ let fixedTopLevels = false;
622
+ switch (options.srcLang) {
623
+ case "graphql":
624
+ let schemaString = undefined;
625
+ let wroteSchemaToFile = false;
626
+ if (options.graphqlIntrospect !== undefined) {
627
+ schemaString = await (0, GraphQLIntrospection_1.introspectServer)(options.graphqlIntrospect, (0, collection_utils_1.withDefault)(options.httpMethod, "POST"), (0, collection_utils_1.withDefault)(options.httpHeader, []));
628
+ if (options.graphqlSchema !== undefined) {
629
+ fs.writeFileSync(options.graphqlSchema, schemaString);
630
+ wroteSchemaToFile = true;
701
631
  }
702
- else if (component === "print-gather-names") {
703
- debugPrintGatherNames = true;
632
+ }
633
+ const numSources = options.src.length;
634
+ if (numSources !== 1) {
635
+ if (wroteSchemaToFile) {
636
+ // We're done.
637
+ return undefined;
704
638
  }
705
- else if (component === "print-transformations") {
706
- debugPrintTransformations = true;
639
+ if (numSources === 0) {
640
+ if (schemaString !== undefined) {
641
+ console.log(schemaString);
642
+ return undefined;
643
+ }
644
+ return (0, quicktype_core_1.messageError)("DriverNoGraphQLQueryGiven", {});
707
645
  }
708
- else if (component === "print-times") {
709
- debugPrintTimes = true;
646
+ }
647
+ const gqlSources = [];
648
+ for (const queryFile of options.src) {
649
+ let schemaFileName = undefined;
650
+ if (schemaString === undefined) {
651
+ schemaFileName = (0, quicktype_core_1.defined)(options.graphqlSchema);
652
+ schemaString = fs.readFileSync(schemaFileName, "utf8");
710
653
  }
711
- else if (component === "print-schema-resolving") {
712
- debugPrintSchemaResolving = true;
654
+ const schema = (0, quicktype_core_1.parseJSON)(schemaString, "GraphQL schema", schemaFileName);
655
+ const query = await (0, quicktype_core_1.getStream)(await (0, quicktype_core_1.readableFromFileOrURL)(queryFile, options.httpHeader));
656
+ const name = numSources === 1 ? options.topLevel : typeNameFromFilename(queryFile);
657
+ gqlSources.push({ kind: "graphql", name, schema, query });
658
+ }
659
+ sources = gqlSources;
660
+ break;
661
+ case "json":
662
+ case "schema":
663
+ sources = await getSources(options);
664
+ break;
665
+ case "typescript":
666
+ sources = [makeTypeScriptSource(options.src)];
667
+ break;
668
+ case "postman":
669
+ for (const collectionFile of options.src) {
670
+ const collectionJSON = fs.readFileSync(collectionFile, "utf8");
671
+ const { sources: postmanSources, description } = (0, quicktype_core_1.sourcesFromPostmanCollection)(collectionJSON, collectionFile);
672
+ for (const src of postmanSources) {
673
+ sources.push(Object.assign({ kind: "json" }, stringSourceDataToStreamSourceData(src)));
713
674
  }
714
- else if (component === "provenance") {
715
- checkProvenance = true;
675
+ if (postmanSources.length > 1) {
676
+ fixedTopLevels = true;
716
677
  }
717
- else if (component !== "all") {
718
- return quicktype_core_1.messageError("DriverUnknownDebugOption", { option: component });
678
+ if (description !== undefined) {
679
+ leadingComments = wordWrap(description).split("\n");
719
680
  }
720
681
  }
721
- }
722
- const lang = quicktype_core_1.languageNamed(options.lang, targetLanguages);
723
- if (lang === undefined) {
724
- return quicktype_core_1.messageError("DriverUnknownOutputLanguage", { lang: options.lang });
725
- }
726
- const quicktypeOptions = {
727
- lang,
728
- alphabetizeProperties: options.alphabetizeProperties,
729
- allPropertiesOptional: options.allPropertiesOptional,
730
- fixedTopLevels,
731
- noRender: options.noRender,
732
- rendererOptions: options.rendererOptions,
733
- leadingComments,
734
- outputFilename: collection_utils_1.definedMap(options.out, path.basename),
735
- debugPrintGraph,
736
- checkProvenance,
737
- debugPrintReconstitution,
738
- debugPrintGatherNames,
739
- debugPrintTransformations,
740
- debugPrintSchemaResolving,
741
- debugPrintTimes
742
- };
743
- for (const flagName of quicktype_core_1.inferenceFlagNames) {
744
- const cliName = negatedInferenceFlagName(flagName);
745
- const v = options[cliName];
746
- if (typeof v === "boolean") {
747
- quicktypeOptions[flagName] = !v;
682
+ break;
683
+ default:
684
+ return (0, quicktype_core_1.messageError)("DriverUnknownSourceLanguage", { lang: options.srcLang });
685
+ }
686
+ const components = (0, collection_utils_1.definedMap)(options.debug, d => d.split(","));
687
+ const debugAll = components !== undefined && components.indexOf("all") >= 0;
688
+ let debugPrintGraph = debugAll;
689
+ let checkProvenance = debugAll;
690
+ let debugPrintReconstitution = debugAll;
691
+ let debugPrintGatherNames = debugAll;
692
+ let debugPrintTransformations = debugAll;
693
+ let debugPrintSchemaResolving = debugAll;
694
+ let debugPrintTimes = debugAll;
695
+ if (components !== undefined) {
696
+ for (let component of components) {
697
+ component = component.trim();
698
+ if (component === "print-graph") {
699
+ debugPrintGraph = true;
700
+ }
701
+ else if (component === "print-reconstitution") {
702
+ debugPrintReconstitution = true;
703
+ }
704
+ else if (component === "print-gather-names") {
705
+ debugPrintGatherNames = true;
706
+ }
707
+ else if (component === "print-transformations") {
708
+ debugPrintTransformations = true;
709
+ }
710
+ else if (component === "print-times") {
711
+ debugPrintTimes = true;
712
+ }
713
+ else if (component === "print-schema-resolving") {
714
+ debugPrintSchemaResolving = true;
715
+ }
716
+ else if (component === "provenance") {
717
+ checkProvenance = true;
748
718
  }
749
- else {
750
- quicktypeOptions[flagName] = true;
719
+ else if (component !== "all") {
720
+ return (0, quicktype_core_1.messageError)("DriverUnknownDebugOption", { option: component });
751
721
  }
752
722
  }
753
- quicktypeOptions.inputData = yield makeInputData(sources, lang, options.additionalSchema, quicktypeOptions.ignoreJsonRefs !== true, options.httpHeader);
754
- return quicktypeOptions;
755
- });
723
+ }
724
+ const lang = (0, quicktype_core_1.languageNamed)(options.lang, targetLanguages);
725
+ if (lang === undefined) {
726
+ return (0, quicktype_core_1.messageError)("DriverUnknownOutputLanguage", { lang: options.lang });
727
+ }
728
+ const quicktypeOptions = {
729
+ lang,
730
+ alphabetizeProperties: options.alphabetizeProperties,
731
+ allPropertiesOptional: options.allPropertiesOptional,
732
+ fixedTopLevels,
733
+ noRender: options.noRender,
734
+ rendererOptions: options.rendererOptions,
735
+ leadingComments,
736
+ outputFilename: (0, collection_utils_1.definedMap)(options.out, path.basename),
737
+ debugPrintGraph,
738
+ checkProvenance,
739
+ debugPrintReconstitution,
740
+ debugPrintGatherNames,
741
+ debugPrintTransformations,
742
+ debugPrintSchemaResolving,
743
+ debugPrintTimes
744
+ };
745
+ for (const flagName of quicktype_core_1.inferenceFlagNames) {
746
+ const cliName = negatedInferenceFlagName(flagName);
747
+ const v = options[cliName];
748
+ if (typeof v === "boolean") {
749
+ quicktypeOptions[flagName] = !v;
750
+ }
751
+ else {
752
+ quicktypeOptions[flagName] = true;
753
+ }
754
+ }
755
+ quicktypeOptions.inputData = await makeInputData(sources, lang, options.additionalSchema, quicktypeOptions.ignoreJsonRefs !== true, options.httpHeader);
756
+ return quicktypeOptions;
756
757
  }
757
758
  exports.makeQuicktypeOptions = makeQuicktypeOptions;
758
759
  function writeOutput(cliOptions, resultsByFilename) {
@@ -787,36 +788,34 @@ function writeOutput(cliOptions, resultsByFilename) {
787
788
  }
788
789
  }
789
790
  exports.writeOutput = writeOutput;
790
- function main(args) {
791
- return __awaiter(this, void 0, void 0, function* () {
792
- let cliOptions;
793
- if (Array.isArray(args)) {
794
- cliOptions = parseCLIOptions(args);
795
- }
796
- else {
797
- cliOptions = inferCLIOptions(args, undefined);
798
- }
799
- if (cliOptions.telemetry !== undefined) {
800
- switch (cliOptions.telemetry) {
801
- case "enable":
802
- break;
803
- case "disable":
804
- break;
805
- default:
806
- console.error(chalk.red("telemetry must be 'enable' or 'disable'"));
807
- return;
808
- }
809
- if (Array.isArray(args) && args.length === 2) {
810
- // This was merely a CLI run to set telemetry and we should not proceed
791
+ async function main(args) {
792
+ let cliOptions;
793
+ if (Array.isArray(args)) {
794
+ cliOptions = parseCLIOptions(args);
795
+ }
796
+ else {
797
+ cliOptions = inferCLIOptions(args, undefined);
798
+ }
799
+ if (cliOptions.telemetry !== undefined) {
800
+ switch (cliOptions.telemetry) {
801
+ case "enable":
802
+ break;
803
+ case "disable":
804
+ break;
805
+ default:
806
+ console.error(chalk.red("telemetry must be 'enable' or 'disable'"));
811
807
  return;
812
- }
813
808
  }
814
- const quicktypeOptions = yield makeQuicktypeOptions(cliOptions);
815
- if (quicktypeOptions === undefined)
809
+ if (Array.isArray(args) && args.length === 2) {
810
+ // This was merely a CLI run to set telemetry and we should not proceed
816
811
  return;
817
- const resultsByFilename = yield quicktype_core_1.quicktypeMultiFile(quicktypeOptions);
818
- writeOutput(cliOptions, resultsByFilename);
819
- });
812
+ }
813
+ }
814
+ const quicktypeOptions = await makeQuicktypeOptions(cliOptions);
815
+ if (quicktypeOptions === undefined)
816
+ return;
817
+ const resultsByFilename = await (0, quicktype_core_1.quicktypeMultiFile)(quicktypeOptions);
818
+ writeOutput(cliOptions, resultsByFilename);
820
819
  }
821
820
  exports.main = main;
822
821
  if (require.main === module) {