quicktype 23.0.158 → 23.0.159

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.
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "quicktype",
3
+ "version": "23.0.0",
4
+ "license": "Apache-2.0",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "repository": "https://github.com/quicktype/quicktype",
8
+ "engines": {
9
+ "node": ">=18.12.0"
10
+ },
11
+ "scripts": {
12
+ "pub": "script/publish.sh",
13
+ "build": "npm run build --workspaces --if-present && tsc",
14
+ "test": "script/test",
15
+ "start": "script/watch",
16
+ "clean": "rm -rf dist node_modules *~ packages/*/{dist,node_modules,out}",
17
+ "debug": "node --inspect-brk --max-old-space-size=4096 ./dist/index.js",
18
+ "lint": "eslint src/** packages/*/src/**",
19
+ "lint:fix": "eslint --fix src/** packages/*/src/**"
20
+ },
21
+ "workspaces": [
22
+ "./packages/quicktype-core",
23
+ "./packages/quicktype-graphql-input",
24
+ "./packages/quicktype-typescript-input",
25
+ "./packages/quicktype-vscode"
26
+ ],
27
+ "dependencies": {
28
+ "@glideapps/ts-necessities": "^2.2.3",
29
+ "chalk": "^4.1.2",
30
+ "collection-utils": "^1.0.1",
31
+ "command-line-args": "^5.2.1",
32
+ "command-line-usage": "^7.0.1",
33
+ "cross-fetch": "^4.0.0",
34
+ "graphql": "^0.11.7",
35
+ "lodash": "^4.17.21",
36
+ "moment": "^2.30.1",
37
+ "quicktype-core": "20.0.12",
38
+ "quicktype-graphql-input": "20.0.2",
39
+ "quicktype-typescript-input": "20.0.2",
40
+ "readable-stream": "^4.5.2",
41
+ "stream-json": "1.8.0",
42
+ "string-to-stream": "^3.0.1",
43
+ "typescript": "4.9.5"
44
+ },
45
+ "devDependencies": {
46
+ "@tsconfig/node18": "^1.0.1",
47
+ "@types/command-line-args": "^5.2.0",
48
+ "@types/command-line-usage": "^5.0.4",
49
+ "@types/graphql": "^0.11.7",
50
+ "@types/lodash": "^4.17.0",
51
+ "@types/semver": "^7.5.0",
52
+ "@types/shelljs": "^0.8.15",
53
+ "@types/stream-json": "^1.7.3",
54
+ "@types/urijs": "^1.19.25",
55
+ "@types/wordwrap": "^1.0.3",
56
+ "@typescript-eslint/eslint-plugin": "^6.3.0",
57
+ "@typescript-eslint/parser": "^6.3.0",
58
+ "ajv": "^5.5.2",
59
+ "deep-equal": "^2.2.3",
60
+ "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
+ "exit": "^0.1.2",
70
+ "prettier": "^3.2.5",
71
+ "promise-timeout": "^1.3.0",
72
+ "semver": "^7.5.4",
73
+ "shelljs": "^0.8.5",
74
+ "ts-node": "^10.9.2",
75
+ "watch": "^1.0.2"
76
+ },
77
+ "files": [
78
+ "dist"
79
+ ],
80
+ "bin": "dist/index.js"
81
+ }
@@ -1,5 +1,5 @@
1
- import { Readable } from "readable-stream";
2
- import { CompressedJSON, Value } from "quicktype-core";
1
+ import { type Readable } from "readable-stream";
2
+ import { CompressedJSON, type Value } from "quicktype-core";
3
3
  export declare class CompressedJSONFromStream extends CompressedJSON<Readable> {
4
4
  parse(readStream: Readable): Promise<Value>;
5
5
  protected handleStartNumber: () => void;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CompressedJSONFromStream = void 0;
4
- const quicktype_core_1 = require("quicktype-core");
5
4
  const stream_json_1 = require("stream-json");
5
+ const quicktype_core_1 = require("quicktype-core");
6
6
  const methodMap = {
7
7
  startObject: "pushObjectContext",
8
8
  endObject: "finishObject",
@@ -22,6 +22,7 @@ class CompressedJSONFromStream extends quicktype_core_1.CompressedJSON {
22
22
  const combo = new stream_json_1.Parser({ packKeys: true, packStrings: true });
23
23
  combo.on("data", (item) => {
24
24
  if (typeof methodMap[item.name] === "string") {
25
+ // @ts-expect-error FIXME: strongly type this
25
26
  this[methodMap[item.name]](item.value);
26
27
  }
27
28
  });
@@ -36,7 +37,7 @@ class CompressedJSONFromStream extends quicktype_core_1.CompressedJSON {
36
37
  readStream.setEncoding("utf8");
37
38
  readStream.pipe(combo);
38
39
  readStream.resume();
39
- return promise;
40
+ return await promise;
40
41
  }
41
42
  handleStartNumber = () => {
42
43
  this.pushContext();
@@ -44,7 +45,7 @@ class CompressedJSONFromStream extends quicktype_core_1.CompressedJSON {
44
45
  };
45
46
  handleNumberChunk = (s) => {
46
47
  const ctx = this.context;
47
- if (!ctx.currentNumberIsDouble && /[\.e]/i.test(s)) {
48
+ if (!ctx.currentNumberIsDouble && /[.e]/i.test(s)) {
48
49
  ctx.currentNumberIsDouble = true;
49
50
  }
50
51
  };
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.introspectServer = void 0;
7
- const quicktype_core_1 = require("quicktype-core");
8
- const graphql_1 = require("graphql");
9
7
  const ts_necessities_1 = require("@glideapps/ts-necessities");
10
8
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
9
+ const graphql_1 = require("graphql");
10
+ 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",
@@ -20,7 +20,7 @@ async function introspectServer(url, method, headerStrings) {
20
20
  headers[name] = defaultHeaders[name];
21
21
  }
22
22
  for (const str of headerStrings) {
23
- const matches = str.match(headerRegExp);
23
+ const matches = headerRegExp.exec(str);
24
24
  if (matches === null) {
25
25
  return (0, quicktype_core_1.panic)(`Not a valid HTTP header: "${str}"`);
26
26
  }
@@ -1,6 +1,6 @@
1
- import { Readable } from "readable-stream";
2
- import { JSONSourceData, JSONSchemaSourceData } from "quicktype-core";
3
- import { GraphQLSourceData } from "quicktype-graphql-input";
1
+ import { type Readable } from "readable-stream";
2
+ import { type JSONSchemaSourceData, type 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
  }
@@ -0,0 +1,3 @@
1
+ export declare function urlsFromURLGrammar(json: unknown): {
2
+ [name: string]: string[];
3
+ };
@@ -20,7 +20,7 @@ function expand(json) {
20
20
  }
21
21
  return result;
22
22
  }
23
- if (Object.prototype.hasOwnProperty.call(json, "oneOf")) {
23
+ if (typeof json === "object" && json && "oneOf" in json) {
24
24
  const options = (0, quicktype_core_1.checkArray)(json.oneOf);
25
25
  const result = [];
26
26
  for (const j of options) {
@@ -1,29 +1,29 @@
1
1
  #!/usr/bin/env node
2
- import { Readable } from "readable-stream";
3
- import { Options, RendererOptions, SerializedRenderResult, TargetLanguage, JSONInput } from "quicktype-core";
2
+ import { type Readable } from "readable-stream";
3
+ import { JSONInput, type Options, type RendererOptions, type SerializedRenderResult, type TargetLanguage } from "quicktype-core";
4
4
  export interface CLIOptions {
5
- lang: string;
6
- topLevel: string;
7
- src: string[];
8
- srcUrls?: string;
9
- srcLang: string;
5
+ [option: string]: any;
10
6
  additionalSchema: string[];
11
- graphqlSchema?: string;
7
+ allPropertiesOptional: boolean;
8
+ alphabetizeProperties: boolean;
9
+ buildMarkovChain?: string;
10
+ debug?: string;
12
11
  graphqlIntrospect?: string;
12
+ graphqlSchema?: string;
13
+ help: boolean;
13
14
  httpHeader?: string[];
14
15
  httpMethod?: string;
15
- out?: string;
16
- buildMarkovChain?: string;
17
- alphabetizeProperties: boolean;
18
- allPropertiesOptional: boolean;
16
+ lang: string;
19
17
  noRender: boolean;
20
- rendererOptions: RendererOptions;
21
- help: boolean;
18
+ out?: string;
22
19
  quiet: boolean;
23
- version: boolean;
24
- debug?: string;
20
+ rendererOptions: RendererOptions;
21
+ src: string[];
22
+ srcLang: string;
23
+ srcUrls?: string;
25
24
  telemetry?: string;
26
- [option: string]: any;
25
+ topLevel: string;
26
+ version: boolean;
27
27
  }
28
28
  export declare function parseCLIOptions(argv: string[], targetLanguage?: TargetLanguage): CLIOptions;
29
29
  export declare function jsonInputForTargetLanguage(targetLanguage: string | TargetLanguage, languages?: TargetLanguage[], handleJSONRefs?: boolean): JSONInput<Readable>;
@@ -30,24 +30,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.main = exports.writeOutput = exports.makeQuicktypeOptions = exports.jsonInputForTargetLanguage = exports.parseCLIOptions = void 0;
31
31
  const fs = __importStar(require("fs"));
32
32
  const path = __importStar(require("path"));
33
- const _ = __importStar(require("lodash"));
34
- const collection_utils_1 = require("collection-utils");
35
33
  const ts_necessities_1 = require("@glideapps/ts-necessities");
34
+ const chalk_1 = __importDefault(require("chalk"));
35
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
36
+ const collection_utils_1 = require("collection-utils");
37
+ const command_line_args_1 = __importDefault(require("command-line-args"));
38
+ const command_line_usage_1 = __importDefault(require("command-line-usage"));
39
+ const _ = __importStar(require("lodash"));
40
+ const string_to_stream_1 = __importDefault(require("string-to-stream"));
41
+ const wordwrap_1 = __importDefault(require("wordwrap"));
36
42
  const quicktype_core_1 = require("quicktype-core");
37
- const quicktype_typescript_input_1 = require("quicktype-typescript-input");
38
43
  const quicktype_graphql_input_1 = require("quicktype-graphql-input");
39
- const URLGrammar_1 = require("./URLGrammar");
40
- const GraphQLIntrospection_1 = require("./GraphQLIntrospection");
44
+ const quicktype_typescript_input_1 = require("quicktype-typescript-input");
45
+ const package_json_1 = __importDefault(require("../package.json"));
41
46
  const CompressedJSONFromStream_1 = require("./CompressedJSONFromStream");
42
- const stringToStream = require("string-to-stream");
43
- const command_line_args_1 = __importDefault(require("command-line-args"));
44
- const command_line_usage_1 = __importDefault(require("command-line-usage"));
45
- const chalk_1 = __importDefault(require("chalk"));
46
- const wordWrap = require("wordwrap")(90);
47
- const packageJSON = require("../package.json");
47
+ const GraphQLIntrospection_1 = require("./GraphQLIntrospection");
48
+ const URLGrammar_1 = require("./URLGrammar");
49
+ const wordWrap = (0, wordwrap_1.default)(90);
48
50
  const defaultDefaultTargetLanguageName = "go";
49
51
  async function sourceFromFileOrUrlArray(name, filesOrUrls, httpHeaders) {
50
- const samples = await Promise.all(filesOrUrls.map(file => (0, quicktype_core_1.readableFromFileOrURL)(file, httpHeaders)));
52
+ const samples = await Promise.all(filesOrUrls.map(async (file) => await (0, quicktype_core_1.readableFromFileOrURL)(file, httpHeaders)));
51
53
  return { kind: "json", name, samples };
52
54
  }
53
55
  function typeNameFromFilename(filename) {
@@ -140,6 +142,7 @@ async function samplesFromDirectory(dataDir, httpHeaders) {
140
142
  if (jsonSamples.length > 0 && schemaSources.length + graphQLSources.length > 0) {
141
143
  return (0, quicktype_core_1.messageError)("DriverCannotMixJSONWithOtherSamples", { dir: dir });
142
144
  }
145
+ // FIXME: rewrite this to be clearer
143
146
  const oneUnlessEmpty = (xs) => Math.sign(xs.length);
144
147
  if (oneUnlessEmpty(schemaSources) + oneUnlessEmpty(graphQLSources) > 1) {
145
148
  return (0, quicktype_core_1.messageError)("DriverCannotMixNonJSONInputs", { dir: dir });
@@ -201,7 +204,7 @@ function inferCLIOptions(opts, targetLanguage) {
201
204
  language = targetLanguage;
202
205
  }
203
206
  else {
204
- const languageName = opts.lang !== undefined ? opts.lang : inferLang(opts, defaultDefaultTargetLanguageName);
207
+ const languageName = opts.lang ?? inferLang(opts, defaultDefaultTargetLanguageName);
205
208
  const maybeLanguage = (0, quicktype_core_1.languageNamed)(languageName);
206
209
  if (maybeLanguage === undefined) {
207
210
  return (0, quicktype_core_1.messageError)("DriverUnknownOutputLanguage", { lang: languageName });
@@ -209,21 +212,21 @@ function inferCLIOptions(opts, targetLanguage) {
209
212
  language = maybeLanguage;
210
213
  }
211
214
  const options = {
212
- src: opts.src || [],
215
+ src: opts.src ?? [],
213
216
  srcUrls: opts.srcUrls,
214
217
  srcLang: srcLang,
215
218
  lang: language.displayName,
216
- topLevel: opts.topLevel || inferTopLevel(opts),
219
+ topLevel: opts.topLevel ?? inferTopLevel(opts),
217
220
  noRender: !!opts.noRender,
218
221
  alphabetizeProperties: !!opts.alphabetizeProperties,
219
222
  allPropertiesOptional: !!opts.allPropertiesOptional,
220
- rendererOptions: opts.rendererOptions || {},
221
- help: opts.help || false,
222
- quiet: opts.quiet || false,
223
- version: opts.version || false,
223
+ rendererOptions: opts.rendererOptions ?? {},
224
+ help: opts.help ?? false,
225
+ quiet: opts.quiet ?? false,
226
+ version: opts.version ?? false,
224
227
  out: opts.out,
225
228
  buildMarkovChain: opts.buildMarkovChain,
226
- additionalSchema: opts.additionalSchema || [],
229
+ additionalSchema: opts.additionalSchema ?? [],
227
230
  graphqlSchema: opts.graphqlSchema,
228
231
  graphqlIntrospect: opts.graphqlIntrospect,
229
232
  httpMethod: opts.httpMethod,
@@ -259,7 +262,7 @@ function makeOptionDefinitions(targetLanguages) {
259
262
  name: "out",
260
263
  alias: "o",
261
264
  type: String,
262
- typeLabel: `FILE`,
265
+ typeLabel: "FILE",
263
266
  description: "The output file. Determines --lang and --top-level."
264
267
  },
265
268
  {
@@ -485,6 +488,8 @@ exports.parseCLIOptions = parseCLIOptions;
485
488
  // according to each option definition's `renderer` field. If `partial` is false this
486
489
  // will throw if it encounters an unknown option.
487
490
  function parseOptions(definitions, argv, partial) {
491
+ // FIXME: update this when options strongly typed
492
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
488
493
  let opts;
489
494
  try {
490
495
  opts = (0, command_line_args_1.default)(definitions, { argv, partial });
@@ -500,6 +505,7 @@ function parseOptions(definitions, argv, partial) {
500
505
  });
501
506
  }
502
507
  }
508
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
503
509
  const options = { rendererOptions: {} };
504
510
  for (const o of definitions) {
505
511
  if (!(0, collection_utils_1.hasOwnProperty)(opts, o.name))
@@ -601,15 +607,19 @@ async function makeInputData(sources, targetLanguage, additionalSchemaAddresses,
601
607
  return inputData;
602
608
  }
603
609
  function stringSourceDataToStreamSourceData(src) {
604
- return { name: src.name, description: src.description, samples: src.samples.map(stringToStream) };
610
+ return {
611
+ name: src.name,
612
+ description: src.description,
613
+ samples: src.samples.map(sample => (0, string_to_stream_1.default)(sample))
614
+ };
605
615
  }
606
616
  async function makeQuicktypeOptions(options, targetLanguages) {
607
617
  if (options.help) {
608
- usage(targetLanguages === undefined ? quicktype_core_1.defaultTargetLanguages : targetLanguages);
618
+ usage(targetLanguages ?? quicktype_core_1.defaultTargetLanguages);
609
619
  return undefined;
610
620
  }
611
621
  if (options.version) {
612
- console.log(`quicktype version ${packageJSON.version}`);
622
+ console.log(`quicktype version ${package_json_1.default.version}`);
613
623
  console.log("Visit quicktype.io for more info.");
614
624
  return undefined;
615
625
  }
@@ -688,7 +698,7 @@ async function makeQuicktypeOptions(options, targetLanguages) {
688
698
  return (0, quicktype_core_1.messageError)("DriverUnknownSourceLanguage", { lang: options.srcLang });
689
699
  }
690
700
  const components = (0, collection_utils_1.definedMap)(options.debug, d => d.split(","));
691
- const debugAll = components !== undefined && components.indexOf("all") >= 0;
701
+ const debugAll = components !== undefined && components.includes("all");
692
702
  let debugPrintGraph = debugAll;
693
703
  let checkProvenance = debugAll;
694
704
  let debugPrintReconstitution = debugAll;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype",
3
- "version": "23.0.158",
3
+ "version": "23.0.159",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,9 +34,9 @@
34
34
  "graphql": "^0.11.7",
35
35
  "lodash": "^4.17.21",
36
36
  "moment": "^2.30.1",
37
- "quicktype-core": "23.0.158",
38
- "quicktype-graphql-input": "23.0.158",
39
- "quicktype-typescript-input": "23.0.158",
37
+ "quicktype-core": "23.0.159",
38
+ "quicktype-graphql-input": "23.0.159",
39
+ "quicktype-typescript-input": "23.0.159",
40
40
  "readable-stream": "^4.5.2",
41
41
  "stream-json": "1.8.0",
42
42
  "string-to-stream": "^3.0.1",
@@ -52,6 +52,7 @@
52
52
  "@types/shelljs": "^0.8.15",
53
53
  "@types/stream-json": "^1.7.3",
54
54
  "@types/urijs": "^1.19.25",
55
+ "@types/wordwrap": "^1.0.3",
55
56
  "@typescript-eslint/eslint-plugin": "^6.3.0",
56
57
  "@typescript-eslint/parser": "^6.3.0",
57
58
  "ajv": "^5.5.2",
@@ -1,3 +0,0 @@
1
- export declare function urlsFromURLGrammar(json: any): {
2
- [name: string]: string[];
3
- };
File without changes