quicktype 23.1.4 → 23.2.1

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.
@@ -1,4 +1,4 @@
1
- import { type Readable } from "readable-stream";
1
+ import type { Readable } from "readable-stream";
2
2
  import { CompressedJSON, type Value } from "quicktype-core";
3
3
  export declare class CompressedJSONFromStream extends CompressedJSON<Readable> {
4
4
  parse(readStream: Readable): Promise<Value>;
@@ -15,7 +15,7 @@ const methodMap = {
15
15
  stringValue: "commitString",
16
16
  nullValue: "commitNull",
17
17
  trueValue: "handleTrueValue",
18
- falseValue: "handleFalseValue"
18
+ falseValue: "handleFalseValue",
19
19
  };
20
20
  class CompressedJSONFromStream extends quicktype_core_1.CompressedJSON {
21
21
  async parse(readStream) {
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.introspectServer = void 0;
6
+ exports.introspectServer = introspectServer;
7
7
  const ts_necessities_1 = require("@glideapps/ts-necessities");
8
8
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
9
9
  const graphql_1 = require("graphql");
@@ -11,7 +11,7 @@ const quicktype_core_1 = require("quicktype-core");
11
11
  // https://github.com/apollographql/apollo-codegen/blob/master/src/downloadSchema.ts
12
12
  const defaultHeaders = {
13
13
  Accept: "application/json",
14
- "Content-Type": "application/json"
14
+ "Content-Type": "application/json",
15
15
  };
16
16
  const headerRegExp = /^([^:]+):\s*(.*)$/;
17
17
  async function introspectServer(url, method, headerStrings) {
@@ -31,7 +31,7 @@ async function introspectServer(url, method, headerStrings) {
31
31
  const response = await (0, cross_fetch_1.default)(url, {
32
32
  method,
33
33
  headers: headers,
34
- body: JSON.stringify({ query: graphql_1.introspectionQuery })
34
+ body: JSON.stringify({ query: graphql_1.introspectionQuery }),
35
35
  });
36
36
  result = await response.json();
37
37
  }
@@ -47,4 +47,3 @@ async function introspectServer(url, method, headerStrings) {
47
47
  }
48
48
  return JSON.stringify(schemaData, null, 2);
49
49
  }
50
- exports.introspectServer = introspectServer;
@@ -1,6 +1,6 @@
1
- import { type Readable } from "readable-stream";
2
- import { type JSONSchemaSourceData, type JSONSourceData } from "quicktype-core";
3
- import { type GraphQLSourceData } from "quicktype-graphql-input";
1
+ import type { Readable } from "readable-stream";
2
+ import type { JSONSchemaSourceData, JSONSourceData } from "quicktype-core";
3
+ import type { GraphQLSourceData } from "quicktype-graphql-input";
4
4
  export interface JSONTypeSource extends JSONSourceData<Readable> {
5
5
  kind: "json";
6
6
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.urlsFromURLGrammar = void 0;
3
+ exports.urlsFromURLGrammar = urlsFromURLGrammar;
4
4
  const quicktype_core_1 = require("quicktype-core");
5
5
  function expand(json) {
6
6
  if (typeof json === "string") {
@@ -40,4 +40,3 @@ function urlsFromURLGrammar(json) {
40
40
  }
41
41
  return results;
42
42
  }
43
- exports.urlsFromURLGrammar = urlsFromURLGrammar;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { type Readable } from "readable-stream";
2
+ import type { Readable } from "readable-stream";
3
3
  import { JSONInput, type LanguageName, type Options, type RendererOptions, type SerializedRenderResult, type TargetLanguage } from "quicktype-core";
4
4
  export interface CLIOptions<Lang extends LanguageName = LanguageName> {
5
5
  [option: string]: any;
package/dist/index.js CHANGED
@@ -16,23 +16,36 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
16
16
  }) : function(o, v) {
17
17
  o["default"] = v;
18
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;
25
- };
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
26
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
27
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
38
  };
29
39
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.main = exports.writeOutput = exports.makeQuicktypeOptions = exports.jsonInputForTargetLanguage = exports.parseCLIOptions = void 0;
31
- const fs = __importStar(require("fs"));
32
- const path = __importStar(require("path"));
40
+ exports.parseCLIOptions = parseCLIOptions;
41
+ exports.jsonInputForTargetLanguage = jsonInputForTargetLanguage;
42
+ exports.makeQuicktypeOptions = makeQuicktypeOptions;
43
+ exports.writeOutput = writeOutput;
44
+ exports.main = main;
45
+ const fs = __importStar(require("node:fs"));
46
+ const path = __importStar(require("node:path"));
33
47
  const ts_necessities_1 = require("@glideapps/ts-necessities");
34
48
  const chalk_1 = __importDefault(require("chalk"));
35
- // eslint-disable-next-line @typescript-eslint/no-redeclare
36
49
  const collection_utils_1 = require("collection-utils");
37
50
  const command_line_args_1 = __importDefault(require("command-line-args"));
38
51
  const command_line_usage_1 = __importDefault(require("command-line-usage"));
@@ -61,8 +74,8 @@ async function samplesFromDirectory(dataDir, httpHeaders) {
61
74
  async function readFilesOrURLsInDirectory(d) {
62
75
  const files = fs
63
76
  .readdirSync(d)
64
- .map(x => path.join(d, x))
65
- .filter(x => fs.lstatSync(x).isFile());
77
+ .map((x) => path.join(d, x))
78
+ .filter((x) => fs.lstatSync(x).isFile());
66
79
  // Each file is a (Name, JSON | URL)
67
80
  const sourcesInDir = [];
68
81
  const graphQLSources = [];
@@ -80,19 +93,21 @@ async function samplesFromDirectory(dataDir, httpHeaders) {
80
93
  sourcesInDir.push({
81
94
  kind: "json",
82
95
  name,
83
- samples: [await (0, quicktype_core_1.readableFromFileOrURL)(fileOrUrl, httpHeaders)]
96
+ samples: [
97
+ await (0, quicktype_core_1.readableFromFileOrURL)(fileOrUrl, httpHeaders),
98
+ ],
84
99
  });
85
100
  }
86
101
  else if (file.endsWith(".schema")) {
87
102
  sourcesInDir.push({
88
103
  kind: "schema",
89
104
  name,
90
- uris: [fileOrUrl]
105
+ uris: [fileOrUrl],
91
106
  });
92
107
  }
93
108
  else if (file.endsWith(".gqlschema")) {
94
109
  (0, quicktype_core_1.messageAssert)(graphQLSchema === undefined, "DriverMoreThanOneGraphQLSchemaInDir", {
95
- dir: dataDir
110
+ dir: dataDir,
96
111
  });
97
112
  graphQLSchema = await (0, quicktype_core_1.readableFromFileOrURL)(fileOrUrl, httpHeaders);
98
113
  graphQLSchemaFileName = fileOrUrl;
@@ -102,13 +117,15 @@ async function samplesFromDirectory(dataDir, httpHeaders) {
102
117
  kind: "graphql",
103
118
  name,
104
119
  schema: undefined,
105
- query: await (0, quicktype_core_1.getStream)(await (0, quicktype_core_1.readableFromFileOrURL)(fileOrUrl, httpHeaders))
120
+ query: await (0, quicktype_core_1.getStream)(await (0, quicktype_core_1.readableFromFileOrURL)(fileOrUrl, httpHeaders)),
106
121
  });
107
122
  }
108
123
  }
109
124
  if (graphQLSources.length > 0) {
110
125
  if (graphQLSchema === undefined) {
111
- return (0, quicktype_core_1.messageError)("DriverNoGraphQLSchemaInDir", { dir: dataDir });
126
+ return (0, quicktype_core_1.messageError)("DriverNoGraphQLSchemaInDir", {
127
+ dir: dataDir,
128
+ });
112
129
  }
113
130
  const schema = (0, quicktype_core_1.parseJSON)(await (0, quicktype_core_1.getStream)(graphQLSchema), "GraphQL schema", graphQLSchemaFileName);
114
131
  for (const source of graphQLSources) {
@@ -118,8 +135,8 @@ async function samplesFromDirectory(dataDir, httpHeaders) {
118
135
  }
119
136
  return sourcesInDir;
120
137
  }
121
- const contents = fs.readdirSync(dataDir).map(x => path.join(dataDir, x));
122
- const directories = contents.filter(x => fs.lstatSync(x).isDirectory());
138
+ const contents = fs.readdirSync(dataDir).map((x) => path.join(dataDir, x));
139
+ const directories = contents.filter((x) => fs.lstatSync(x).isDirectory());
123
140
  let sources = await readFilesOrURLsInDirectory(dataDir);
124
141
  for (const dir of directories) {
125
142
  let jsonSamples = [];
@@ -140,19 +157,23 @@ async function samplesFromDirectory(dataDir, httpHeaders) {
140
157
  return (0, quicktype_core_1.assertNever)(source);
141
158
  }
142
159
  }
143
- if (jsonSamples.length > 0 && schemaSources.length + graphQLSources.length > 0) {
144
- return (0, quicktype_core_1.messageError)("DriverCannotMixJSONWithOtherSamples", { dir: dir });
160
+ if (jsonSamples.length > 0 &&
161
+ schemaSources.length + graphQLSources.length > 0) {
162
+ return (0, quicktype_core_1.messageError)("DriverCannotMixJSONWithOtherSamples", {
163
+ dir: dir,
164
+ });
145
165
  }
146
166
  // FIXME: rewrite this to be clearer
147
167
  const oneUnlessEmpty = (xs) => Math.sign(xs.length);
148
- if (oneUnlessEmpty(schemaSources) + oneUnlessEmpty(graphQLSources) > 1) {
168
+ if (oneUnlessEmpty(schemaSources) + oneUnlessEmpty(graphQLSources) >
169
+ 1) {
149
170
  return (0, quicktype_core_1.messageError)("DriverCannotMixNonJSONInputs", { dir: dir });
150
171
  }
151
172
  if (jsonSamples.length > 0) {
152
173
  sources.push({
153
174
  kind: "json",
154
175
  name: path.basename(dir),
155
- samples: jsonSamples
176
+ samples: jsonSamples,
156
177
  });
157
178
  }
158
179
  sources = sources.concat(schemaSources);
@@ -163,7 +184,7 @@ async function samplesFromDirectory(dataDir, httpHeaders) {
163
184
  function inferLang(options, defaultLanguage) {
164
185
  // Output file extension determines the language if language is undefined
165
186
  if (options.out !== undefined) {
166
- let extension = path.extname(options.out);
187
+ const extension = path.extname(options.out);
167
188
  if (extension === "") {
168
189
  return (0, quicktype_core_1.messageError)("DriverNoLanguageOrExtension", {});
169
190
  }
@@ -174,26 +195,29 @@ function inferLang(options, defaultLanguage) {
174
195
  function inferTopLevel(options) {
175
196
  // Output file name determines the top-level if undefined
176
197
  if (options.out !== undefined) {
177
- let extension = path.extname(options.out);
178
- let without = path.basename(options.out).replace(extension, "");
198
+ const extension = path.extname(options.out);
199
+ const without = path.basename(options.out).replace(extension, "");
179
200
  return without;
180
201
  }
181
202
  // Source determines the top-level if undefined
182
203
  if (options.src !== undefined && options.src.length === 1) {
183
- let src = options.src[0];
184
- let extension = path.extname(src);
185
- let without = path.basename(src).replace(extension, "");
204
+ const src = options.src[0];
205
+ const extension = path.extname(src);
206
+ const without = path.basename(src).replace(extension, "");
186
207
  return without;
187
208
  }
188
209
  return "TopLevel";
189
210
  }
190
211
  function inferCLIOptions(opts, targetLanguage) {
191
212
  let srcLang = opts.srcLang;
192
- if (opts.graphqlSchema !== undefined || opts.graphqlIntrospect !== undefined) {
213
+ if (opts.graphqlSchema !== undefined ||
214
+ opts.graphqlIntrospect !== undefined) {
193
215
  (0, quicktype_core_1.messageAssert)(srcLang === undefined || srcLang === "graphql", "DriverSourceLangMustBeGraphQL", {});
194
216
  srcLang = "graphql";
195
217
  }
196
- else if (opts.src !== undefined && opts.src.length > 0 && opts.src.every(file => _.endsWith(file, ".ts"))) {
218
+ else if (opts.src !== undefined &&
219
+ opts.src.length > 0 &&
220
+ opts.src.every((file) => _.endsWith(file, ".ts"))) {
197
221
  srcLang = "typescript";
198
222
  }
199
223
  else {
@@ -210,7 +234,9 @@ function inferCLIOptions(opts, targetLanguage) {
210
234
  language = (0, quicktype_core_1.languageNamed)(languageName);
211
235
  }
212
236
  else {
213
- return (0, quicktype_core_1.messageError)("DriverUnknownOutputLanguage", { lang: languageName });
237
+ return (0, quicktype_core_1.messageError)("DriverUnknownOutputLanguage", {
238
+ lang: languageName,
239
+ });
214
240
  }
215
241
  }
216
242
  const options = {
@@ -234,7 +260,7 @@ function inferCLIOptions(opts, targetLanguage) {
234
260
  httpMethod: opts.httpMethod,
235
261
  httpHeader: opts.httpHeader,
236
262
  debug: opts.debug,
237
- telemetry: opts.telemetry
263
+ telemetry: opts.telemetry,
238
264
  };
239
265
  for (const flagName of quicktype_core_1.inferenceFlagNames) {
240
266
  const cliName = negatedInferenceFlagName(flagName);
@@ -244,7 +270,9 @@ function inferCLIOptions(opts, targetLanguage) {
244
270
  }
245
271
  function makeLangTypeLabel(targetLanguages) {
246
272
  (0, quicktype_core_1.assert)(targetLanguages.length > 0, "Must have at least one target language");
247
- return targetLanguages.map(r => _.minBy(r.names, s => s.length)).join("|");
273
+ return targetLanguages
274
+ .map((r) => _.minBy(r.names, (s) => s.length))
275
+ .join("|");
248
276
  }
249
277
  function negatedInferenceFlagName(name) {
250
278
  const prefix = "infer";
@@ -255,7 +283,7 @@ function negatedInferenceFlagName(name) {
255
283
  }
256
284
  function dashedFromCamelCase(name) {
257
285
  return (0, quicktype_core_1.splitIntoWords)(name)
258
- .map(w => w.word.toLowerCase())
286
+ .map((w) => w.word.toLowerCase())
259
287
  .join("-");
260
288
  }
261
289
  function makeOptionDefinitions(targetLanguages) {
@@ -266,7 +294,7 @@ function makeOptionDefinitions(targetLanguages) {
266
294
  type: String,
267
295
  typeLabel: "FILE",
268
296
  description: "The output file. Determines --lang and --top-level.",
269
- kind: "cli"
297
+ kind: "cli",
270
298
  },
271
299
  {
272
300
  name: "top-level",
@@ -274,8 +302,8 @@ function makeOptionDefinitions(targetLanguages) {
274
302
  type: String,
275
303
  typeLabel: "NAME",
276
304
  description: "The name for the top level type.",
277
- kind: "cli"
278
- }
305
+ kind: "cli",
306
+ },
279
307
  ];
280
308
  const lang = targetLanguages.length < 2
281
309
  ? []
@@ -286,8 +314,8 @@ function makeOptionDefinitions(targetLanguages) {
286
314
  type: String,
287
315
  typeLabel: "LANG",
288
316
  description: "The target language.",
289
- kind: "cli"
290
- }
317
+ kind: "cli",
318
+ },
291
319
  ];
292
320
  const afterLang = [
293
321
  {
@@ -297,7 +325,7 @@ function makeOptionDefinitions(targetLanguages) {
297
325
  defaultValue: undefined,
298
326
  typeLabel: "SRC_LANG",
299
327
  description: "The source language (default is json).",
300
- kind: "cli"
328
+ kind: "cli",
301
329
  },
302
330
  {
303
331
  name: "src",
@@ -306,22 +334,22 @@ function makeOptionDefinitions(targetLanguages) {
306
334
  defaultOption: true,
307
335
  typeLabel: "FILE|URL|DIRECTORY",
308
336
  description: "The file, url, or data directory to type.",
309
- kind: "cli"
337
+ kind: "cli",
310
338
  },
311
339
  {
312
340
  name: "src-urls",
313
341
  type: String,
314
342
  typeLabel: "FILE",
315
343
  description: "Tracery grammar describing URLs to crawl.",
316
- kind: "cli"
317
- }
344
+ kind: "cli",
345
+ },
318
346
  ];
319
347
  const inference = Array.from((0, collection_utils_1.mapMap)((0, collection_utils_1.mapFromObject)(quicktype_core_1.inferenceFlags), (flag, name) => {
320
348
  return {
321
349
  name: dashedFromCamelCase(negatedInferenceFlagName(name)),
322
350
  type: Boolean,
323
351
  description: flag.negationDescription + ".",
324
- kind: "cli"
352
+ kind: "cli",
325
353
  };
326
354
  }).values());
327
355
  const afterInference = [
@@ -330,21 +358,21 @@ function makeOptionDefinitions(targetLanguages) {
330
358
  type: String,
331
359
  typeLabel: "FILE",
332
360
  description: "GraphQL introspection file.",
333
- kind: "cli"
361
+ kind: "cli",
334
362
  },
335
363
  {
336
364
  name: "graphql-introspect",
337
365
  type: String,
338
366
  typeLabel: "URL",
339
367
  description: "Introspect GraphQL schema from a server.",
340
- kind: "cli"
368
+ kind: "cli",
341
369
  },
342
370
  {
343
371
  name: "http-method",
344
372
  type: String,
345
373
  typeLabel: "METHOD",
346
374
  description: "HTTP method to use for the GraphQL introspection query.",
347
- kind: "cli"
375
+ kind: "cli",
348
376
  },
349
377
  {
350
378
  name: "http-header",
@@ -352,7 +380,7 @@ function makeOptionDefinitions(targetLanguages) {
352
380
  multiple: true,
353
381
  typeLabel: "HEADER",
354
382
  description: "Header(s) to attach to all HTTP requests, including the GraphQL introspection query.",
355
- kind: "cli"
383
+ kind: "cli",
356
384
  },
357
385
  {
358
386
  name: "additional-schema",
@@ -361,67 +389,67 @@ function makeOptionDefinitions(targetLanguages) {
361
389
  multiple: true,
362
390
  typeLabel: "FILE",
363
391
  description: "Register the $id's of additional JSON Schema files.",
364
- kind: "cli"
392
+ kind: "cli",
365
393
  },
366
394
  {
367
395
  name: "no-render",
368
396
  type: Boolean,
369
397
  description: "Don't render output.",
370
- kind: "cli"
398
+ kind: "cli",
371
399
  },
372
400
  {
373
401
  name: "alphabetize-properties",
374
402
  type: Boolean,
375
403
  description: "Alphabetize order of class properties.",
376
- kind: "cli"
404
+ kind: "cli",
377
405
  },
378
406
  {
379
407
  name: "all-properties-optional",
380
408
  type: Boolean,
381
409
  description: "Make all class properties optional.",
382
- kind: "cli"
410
+ kind: "cli",
383
411
  },
384
412
  {
385
413
  name: "build-markov-chain",
386
414
  type: String,
387
415
  typeLabel: "FILE",
388
416
  description: "Markov chain corpus filename.",
389
- kind: "cli"
417
+ kind: "cli",
390
418
  },
391
419
  {
392
420
  name: "quiet",
393
421
  type: Boolean,
394
422
  description: "Don't show issues in the generated code.",
395
- kind: "cli"
423
+ kind: "cli",
396
424
  },
397
425
  {
398
426
  name: "debug",
399
427
  type: String,
400
428
  typeLabel: "OPTIONS or all",
401
429
  description: "Comma separated debug options: print-graph, print-reconstitution, print-gather-names, print-transformations, print-schema-resolving, print-times, provenance",
402
- kind: "cli"
430
+ kind: "cli",
403
431
  },
404
432
  {
405
433
  name: "telemetry",
406
434
  type: String,
407
435
  typeLabel: "enable|disable",
408
436
  description: "Enable anonymous telemetry to help improve quicktype",
409
- kind: "cli"
437
+ kind: "cli",
410
438
  },
411
439
  {
412
440
  name: "help",
413
441
  alias: "h",
414
442
  type: Boolean,
415
443
  description: "Get some help.",
416
- kind: "cli"
444
+ kind: "cli",
417
445
  },
418
446
  {
419
447
  name: "version",
420
448
  alias: "v",
421
449
  type: Boolean,
422
450
  description: "Display the version of quicktype",
423
- kind: "cli"
424
- }
451
+ kind: "cli",
452
+ },
425
453
  ];
426
454
  return beforeLang.concat(lang, afterLang, inference, afterInference);
427
455
  }
@@ -429,16 +457,18 @@ const tableOptionsForOptions = {
429
457
  columns: [
430
458
  {
431
459
  name: "option",
432
- width: 60
460
+ width: 60,
433
461
  },
434
462
  {
435
463
  name: "description",
436
- width: 60
437
- }
438
- ]
464
+ width: 60,
465
+ },
466
+ ],
439
467
  };
440
468
  function makeSectionsBeforeRenderers(targetLanguages) {
441
- const langDisplayNames = targetLanguages.map(r => r.displayName).join(", ");
469
+ const langDisplayNames = targetLanguages
470
+ .map((r) => r.displayName)
471
+ .join(", ");
442
472
  return [
443
473
  {
444
474
  header: "Synopsis",
@@ -447,19 +477,19 @@ function makeSectionsBeforeRenderers(targetLanguages) {
447
477
  "",
448
478
  ` LANG ... ${makeLangTypeLabel(targetLanguages)}`,
449
479
  "",
450
- "SRC_LANG ... json|schema|graphql|postman|typescript"
451
- ]
480
+ "SRC_LANG ... json|schema|graphql|postman|typescript",
481
+ ],
452
482
  },
453
483
  {
454
484
  header: "Description",
455
- content: `Given JSON sample data, quicktype outputs code for working with that data in ${langDisplayNames}.`
485
+ content: `Given JSON sample data, quicktype outputs code for working with that data in ${langDisplayNames}.`,
456
486
  },
457
487
  {
458
488
  header: "Options",
459
489
  optionList: makeOptionDefinitions(targetLanguages),
460
490
  hide: ["no-render", "build-markov-chain"],
461
- tableOptions: tableOptionsForOptions
462
- }
491
+ tableOptions: tableOptionsForOptions,
492
+ },
463
493
  ];
464
494
  }
465
495
  const sectionsAfterRenderers = [
@@ -479,18 +509,20 @@ const sectionsAfterRenderers = [
479
509
  "",
480
510
  chalk_1.default.dim("Generate JSON Schema, then TypeScript"),
481
511
  "$ quicktype -o schema.json https://blockchain.info/latestblock",
482
- "$ quicktype -o bitcoin.ts --src-lang schema schema.json"
483
- ]
512
+ "$ quicktype -o bitcoin.ts --src-lang schema schema.json",
513
+ ],
484
514
  },
485
515
  {
486
- content: `Learn more at ${chalk_1.default.bold("quicktype.io")}`
487
- }
516
+ content: `Learn more at ${chalk_1.default.bold("quicktype.io")}`,
517
+ },
488
518
  ];
489
519
  function parseCLIOptions(argv, targetLanguage) {
490
520
  if (argv.length === 0) {
491
521
  return inferCLIOptions({ help: true }, targetLanguage);
492
522
  }
493
- const targetLanguages = targetLanguage === undefined ? quicktype_core_1.defaultTargetLanguages : [targetLanguage];
523
+ const targetLanguages = targetLanguage === undefined
524
+ ? quicktype_core_1.defaultTargetLanguages
525
+ : [targetLanguage];
494
526
  const optionDefinitions = makeOptionDefinitions(targetLanguages);
495
527
  // We can only fully parse the options once we know which renderer is selected,
496
528
  // because there are renderer-specific options. But we only know which renderer
@@ -498,7 +530,9 @@ function parseCLIOptions(argv, targetLanguage) {
498
530
  // twice. This is the first parse to get the renderer:
499
531
  const incompleteOptions = inferCLIOptions(parseOptions(optionDefinitions, argv, true), targetLanguage);
500
532
  if (targetLanguage === undefined) {
501
- const languageName = (0, quicktype_core_1.isLanguageName)(incompleteOptions.lang) ? incompleteOptions.lang : "typescript";
533
+ const languageName = (0, quicktype_core_1.isLanguageName)(incompleteOptions.lang)
534
+ ? incompleteOptions.lang
535
+ : "typescript";
502
536
  targetLanguage = (0, quicktype_core_1.getTargetLanguage)(languageName);
503
537
  }
504
538
  const rendererOptionDefinitions = targetLanguage.cliOptionDefinitions.actual;
@@ -507,7 +541,6 @@ function parseCLIOptions(argv, targetLanguage) {
507
541
  // This is the parse that counts:
508
542
  return inferCLIOptions(parseOptions(allOptionDefinitions, argv, false), targetLanguage);
509
543
  }
510
- exports.parseCLIOptions = parseCLIOptions;
511
544
  // Parse the options in argv and split them into global options and renderer options,
512
545
  // according to each option definition's `renderer` field. If `partial` is false this
513
546
  // will throw if it encounters an unknown option.
@@ -518,12 +551,14 @@ function parseOptions(definitions, argv, partial) {
518
551
  }
519
552
  catch (e) {
520
553
  (0, quicktype_core_1.assert)(!partial, "Partial option parsing should not have failed");
521
- return (0, quicktype_core_1.messageError)("DriverCLIOptionParsingFailed", { message: (0, ts_necessities_1.exceptionToString)(e) });
554
+ return (0, quicktype_core_1.messageError)("DriverCLIOptionParsingFailed", {
555
+ message: (0, ts_necessities_1.exceptionToString)(e),
556
+ });
522
557
  }
523
558
  for (const k of Object.keys(opts)) {
524
559
  if (opts[k] === null) {
525
560
  return (0, quicktype_core_1.messageError)("DriverCLIOptionParsingFailed", {
526
- message: `Missing value for command line option "${k}"`
561
+ message: `Missing value for command line option "${k}"`,
527
562
  });
528
563
  }
529
564
  }
@@ -534,8 +569,7 @@ function parseOptions(definitions, argv, partial) {
534
569
  }
535
570
  const optionValue = opts[optionDefinition.name];
536
571
  if (optionDefinition.kind !== "cli") {
537
- options.rendererOptions[optionDefinition.name] =
538
- optionValue;
572
+ options.rendererOptions[optionDefinition.name] = optionValue;
539
573
  }
540
574
  else {
541
575
  const k = _.lowerFirst(optionDefinition.name.split("-").map(_.upperFirst).join(""));
@@ -553,7 +587,7 @@ function usage(targetLanguages) {
553
587
  rendererSections.push({
554
588
  header: `Options for ${language.displayName}`,
555
589
  optionList: definitions,
556
- tableOptions: tableOptionsForOptions
590
+ tableOptions: tableOptionsForOptions,
557
591
  });
558
592
  }
559
593
  const sections = _.concat(makeSectionsBeforeRenderers(targetLanguages), rendererSections, sectionsAfterRenderers);
@@ -565,21 +599,21 @@ async function getSourceURIs(options) {
565
599
  const json = (0, quicktype_core_1.parseJSON)(await (0, quicktype_core_1.readFromFileOrURL)(options.srcUrls, options.httpHeader), "URL grammar", options.srcUrls);
566
600
  const jsonMap = (0, URLGrammar_1.urlsFromURLGrammar)(json);
567
601
  const topLevels = Object.getOwnPropertyNames(jsonMap);
568
- return topLevels.map(name => [name, jsonMap[name]]);
602
+ return topLevels.map((name) => [name, jsonMap[name]]);
569
603
  }
570
- else if (options.src.length === 0) {
604
+ if (options.src.length === 0) {
571
605
  return [[options.topLevel, ["-"]]];
572
606
  }
573
- else {
574
- return [];
575
- }
607
+ return [];
576
608
  }
577
609
  async function typeSourcesForURIs(name, uris, options) {
578
610
  switch (options.srcLang) {
579
611
  case "json":
580
- return [await sourceFromFileOrUrlArray(name, uris, options.httpHeader)];
612
+ return [
613
+ await sourceFromFileOrUrlArray(name, uris, options.httpHeader),
614
+ ];
581
615
  case "schema":
582
- return uris.map(uri => ({ kind: "schema", name, uris: [uri] }));
616
+ return uris.map((uri) => ({ kind: "schema", name, uris: [uri] }));
583
617
  default:
584
618
  return (0, quicktype_core_1.panic)(`typeSourceForURIs must not be called for source language ${options.srcLang}`);
585
619
  }
@@ -589,12 +623,12 @@ async function getSources(options) {
589
623
  const sourceArrays = await Promise.all(sourceURIs.map(async ([name, uris]) => await typeSourcesForURIs(name, uris, options)));
590
624
  let sources = [].concat(...sourceArrays);
591
625
  const exists = options.src.filter(fs.existsSync);
592
- const directories = exists.filter(x => fs.lstatSync(x).isDirectory());
626
+ const directories = exists.filter((x) => fs.lstatSync(x).isDirectory());
593
627
  for (const dataDir of directories) {
594
628
  sources = sources.concat(await samplesFromDirectory(dataDir, options.httpHeader));
595
629
  }
596
630
  // Every src that's not a directory is assumed to be a file or URL
597
- const filesOrUrls = options.src.filter(x => !_.includes(directories, x));
631
+ const filesOrUrls = options.src.filter((x) => !_.includes(directories, x));
598
632
  if (!_.isEmpty(filesOrUrls)) {
599
633
  sources.push(...(await typeSourcesForURIs(options.topLevel, filesOrUrls, options)));
600
634
  }
@@ -605,13 +639,14 @@ function makeTypeScriptSource(fileNames) {
605
639
  }
606
640
  function jsonInputForTargetLanguage(targetLanguage, languages, handleJSONRefs = false) {
607
641
  if (typeof targetLanguage === "string") {
608
- const languageName = (0, quicktype_core_1.isLanguageName)(targetLanguage) ? targetLanguage : "typescript";
642
+ const languageName = (0, quicktype_core_1.isLanguageName)(targetLanguage)
643
+ ? targetLanguage
644
+ : "typescript";
609
645
  targetLanguage = (0, quicktype_core_1.defined)((0, quicktype_core_1.languageNamed)(languageName, languages));
610
646
  }
611
647
  const compressedJSON = new CompressedJSONFromStream_1.CompressedJSONFromStream(targetLanguage.dateTimeRecognizer, handleJSONRefs);
612
648
  return new quicktype_core_1.JSONInput(compressedJSON);
613
649
  }
614
- exports.jsonInputForTargetLanguage = jsonInputForTargetLanguage;
615
650
  async function makeInputData(sources, targetLanguage, additionalSchemaAddresses, handleJSONRefs, httpHeaders) {
616
651
  const inputData = new quicktype_core_1.InputData();
617
652
  for (const source of sources) {
@@ -635,7 +670,7 @@ function stringSourceDataToStreamSourceData(src) {
635
670
  return {
636
671
  name: src.name,
637
672
  description: src.description,
638
- samples: src.samples.map(sample => (0, string_to_stream_1.default)(sample))
673
+ samples: src.samples.map((sample) => (0, string_to_stream_1.default)(sample)),
639
674
  };
640
675
  }
641
676
  async function makeQuicktypeOptions(options, targetLanguages) {
@@ -692,7 +727,9 @@ async function makeQuicktypeOptions(options, targetLanguages) {
692
727
  }
693
728
  const schema = (0, quicktype_core_1.parseJSON)(schemaString, "GraphQL schema", schemaFileName);
694
729
  const query = await (0, quicktype_core_1.getStream)(await (0, quicktype_core_1.readableFromFileOrURL)(queryFile, options.httpHeader));
695
- const name = numSources === 1 ? options.topLevel : typeNameFromFilename(queryFile);
730
+ const name = numSources === 1
731
+ ? options.topLevel
732
+ : typeNameFromFilename(queryFile);
696
733
  gqlSources.push({ kind: "graphql", name, schema, query });
697
734
  }
698
735
  sources = gqlSources;
@@ -720,10 +757,12 @@ async function makeQuicktypeOptions(options, targetLanguages) {
720
757
  }
721
758
  break;
722
759
  default:
723
- return (0, quicktype_core_1.messageError)("DriverUnknownSourceLanguage", { lang: options.srcLang });
760
+ return (0, quicktype_core_1.messageError)("DriverUnknownSourceLanguage", {
761
+ lang: options.srcLang,
762
+ });
724
763
  }
725
- const components = (0, collection_utils_1.definedMap)(options.debug, d => d.split(","));
726
- const debugAll = components !== undefined && components.includes("all");
764
+ const components = (0, collection_utils_1.definedMap)(options.debug, (d) => d.split(","));
765
+ const debugAll = components?.includes("all");
727
766
  let debugPrintGraph = debugAll;
728
767
  let checkProvenance = debugAll;
729
768
  let debugPrintReconstitution = debugAll;
@@ -756,12 +795,16 @@ async function makeQuicktypeOptions(options, targetLanguages) {
756
795
  checkProvenance = true;
757
796
  }
758
797
  else if (component !== "all") {
759
- return (0, quicktype_core_1.messageError)("DriverUnknownDebugOption", { option: component });
798
+ return (0, quicktype_core_1.messageError)("DriverUnknownDebugOption", {
799
+ option: component,
800
+ });
760
801
  }
761
802
  }
762
803
  }
763
804
  if (!(0, quicktype_core_1.isLanguageName)(options.lang)) {
764
- return (0, quicktype_core_1.messageError)("DriverUnknownOutputLanguage", { lang: options.lang });
805
+ return (0, quicktype_core_1.messageError)("DriverUnknownOutputLanguage", {
806
+ lang: options.lang,
807
+ });
765
808
  }
766
809
  const lang = (0, quicktype_core_1.languageNamed)(options.lang, targetLanguages);
767
810
  const quicktypeOptions = {
@@ -779,7 +822,7 @@ async function makeQuicktypeOptions(options, targetLanguages) {
779
822
  debugPrintGatherNames,
780
823
  debugPrintTransformations,
781
824
  debugPrintSchemaResolving,
782
- debugPrintTimes
825
+ debugPrintTimes,
783
826
  };
784
827
  for (const flagName of quicktype_core_1.inferenceFlagNames) {
785
828
  const cliName = negatedInferenceFlagName(flagName);
@@ -794,7 +837,6 @@ async function makeQuicktypeOptions(options, targetLanguages) {
794
837
  quicktypeOptions.inputData = await makeInputData(sources, lang, options.additionalSchema, quicktypeOptions.ignoreJsonRefs !== true, options.httpHeader);
795
838
  return quicktypeOptions;
796
839
  }
797
- exports.makeQuicktypeOptions = makeQuicktypeOptions;
798
840
  function writeOutput(cliOptions, resultsByFilename) {
799
841
  let onFirst = true;
800
842
  for (const [filename, { lines, annotations }] of resultsByFilename) {
@@ -826,7 +868,6 @@ function writeOutput(cliOptions, resultsByFilename) {
826
868
  onFirst = false;
827
869
  }
828
870
  }
829
- exports.writeOutput = writeOutput;
830
871
  async function main(args) {
831
872
  let cliOptions;
832
873
  if (Array.isArray(args)) {
@@ -851,14 +892,14 @@ async function main(args) {
851
892
  }
852
893
  }
853
894
  const quicktypeOptions = await makeQuicktypeOptions(cliOptions);
854
- if (quicktypeOptions === undefined)
895
+ if (quicktypeOptions === undefined) {
855
896
  return;
897
+ }
856
898
  const resultsByFilename = await (0, quicktype_core_1.quicktypeMultiFile)(quicktypeOptions);
857
899
  writeOutput(cliOptions, resultsByFilename);
858
900
  }
859
- exports.main = main;
860
901
  if (require.main === module) {
861
- main(process.argv.slice(2)).catch(e => {
902
+ main(process.argv.slice(2)).catch((e) => {
862
903
  if (e instanceof Error) {
863
904
  console.error(`Error: ${e.message}.`);
864
905
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype",
3
- "version": "23.1.4",
3
+ "version": "23.2.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,15 +34,16 @@
34
34
  "graphql": "^0.11.7",
35
35
  "lodash": "^4.17.21",
36
36
  "moment": "^2.30.1",
37
- "quicktype-core": "23.1.4",
38
- "quicktype-graphql-input": "23.1.4",
39
- "quicktype-typescript-input": "23.1.4",
37
+ "quicktype-core": "23.2.1",
38
+ "quicktype-graphql-input": "23.2.1",
39
+ "quicktype-typescript-input": "23.2.1",
40
40
  "readable-stream": "^4.5.2",
41
41
  "stream-json": "1.8.0",
42
42
  "string-to-stream": "^3.0.1",
43
- "typescript": "4.9.5"
43
+ "typescript": "~5.8.3"
44
44
  },
45
45
  "devDependencies": {
46
+ "@biomejs/biome": "^1.9.4",
46
47
  "@tsconfig/node18": "^1.0.1",
47
48
  "@types/command-line-args": "^5.2.0",
48
49
  "@types/command-line-usage": "^5.0.4",
@@ -58,22 +59,20 @@
58
59
  "ajv": "^5.5.2",
59
60
  "deep-equal": "^2.2.3",
60
61
  "esbuild": "^0.20.2",
61
- "eslint": "^8.57.0",
62
- "eslint-config-canonical": "^41.1.7",
63
- "eslint-config-prettier": "^6.10.0",
64
- "eslint-import-resolver-typescript": "^3.6.1",
65
- "eslint-plugin-canonical": "^3.4.0",
66
- "eslint-plugin-import": "^2.26.0",
67
- "eslint-plugin-json": "^3.1.0",
68
- "eslint-plugin-prettier": "^4.2.1",
69
62
  "exit": "^0.1.2",
70
- "prettier": "^3.2.5",
71
63
  "promise-timeout": "^1.3.0",
72
64
  "semver": "^7.5.4",
73
65
  "shelljs": "^0.8.5",
74
66
  "ts-node": "^10.9.2",
75
67
  "watch": "^1.0.2"
76
68
  },
69
+ "overrides": {
70
+ "cross-fetch": {
71
+ "node-fetch": {
72
+ "whatwg-url": "^13.0.0"
73
+ }
74
+ }
75
+ },
77
76
  "files": [
78
77
  "dist"
79
78
  ],