quicktype 23.0.157 → 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,30 +204,29 @@ 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 });
208
211
  }
209
212
  language = maybeLanguage;
210
213
  }
211
- /* tslint:disable:strict-boolean-expressions */
212
214
  const options = {
213
- src: opts.src || [],
215
+ src: opts.src ?? [],
214
216
  srcUrls: opts.srcUrls,
215
217
  srcLang: srcLang,
216
218
  lang: language.displayName,
217
- topLevel: opts.topLevel || inferTopLevel(opts),
219
+ topLevel: opts.topLevel ?? inferTopLevel(opts),
218
220
  noRender: !!opts.noRender,
219
221
  alphabetizeProperties: !!opts.alphabetizeProperties,
220
222
  allPropertiesOptional: !!opts.allPropertiesOptional,
221
- rendererOptions: opts.rendererOptions || {},
222
- help: opts.help || false,
223
- quiet: opts.quiet || false,
224
- version: opts.version || false,
223
+ rendererOptions: opts.rendererOptions ?? {},
224
+ help: opts.help ?? false,
225
+ quiet: opts.quiet ?? false,
226
+ version: opts.version ?? false,
225
227
  out: opts.out,
226
228
  buildMarkovChain: opts.buildMarkovChain,
227
- additionalSchema: opts.additionalSchema || [],
229
+ additionalSchema: opts.additionalSchema ?? [],
228
230
  graphqlSchema: opts.graphqlSchema,
229
231
  graphqlIntrospect: opts.graphqlIntrospect,
230
232
  httpMethod: opts.httpMethod,
@@ -232,7 +234,6 @@ function inferCLIOptions(opts, targetLanguage) {
232
234
  debug: opts.debug,
233
235
  telemetry: opts.telemetry
234
236
  };
235
- /* tslint:enable */
236
237
  for (const flagName of quicktype_core_1.inferenceFlagNames) {
237
238
  const cliName = negatedInferenceFlagName(flagName);
238
239
  options[cliName] = !!opts[cliName];
@@ -261,7 +262,7 @@ function makeOptionDefinitions(targetLanguages) {
261
262
  name: "out",
262
263
  alias: "o",
263
264
  type: String,
264
- typeLabel: `FILE`,
265
+ typeLabel: "FILE",
265
266
  description: "The output file. Determines --lang and --top-level."
266
267
  },
267
268
  {
@@ -487,6 +488,8 @@ exports.parseCLIOptions = parseCLIOptions;
487
488
  // according to each option definition's `renderer` field. If `partial` is false this
488
489
  // will throw if it encounters an unknown option.
489
490
  function parseOptions(definitions, argv, partial) {
491
+ // FIXME: update this when options strongly typed
492
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
490
493
  let opts;
491
494
  try {
492
495
  opts = (0, command_line_args_1.default)(definitions, { argv, partial });
@@ -502,6 +505,7 @@ function parseOptions(definitions, argv, partial) {
502
505
  });
503
506
  }
504
507
  }
508
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
505
509
  const options = { rendererOptions: {} };
506
510
  for (const o of definitions) {
507
511
  if (!(0, collection_utils_1.hasOwnProperty)(opts, o.name))
@@ -603,15 +607,19 @@ async function makeInputData(sources, targetLanguage, additionalSchemaAddresses,
603
607
  return inputData;
604
608
  }
605
609
  function stringSourceDataToStreamSourceData(src) {
606
- 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
+ };
607
615
  }
608
616
  async function makeQuicktypeOptions(options, targetLanguages) {
609
617
  if (options.help) {
610
- usage(targetLanguages === undefined ? quicktype_core_1.defaultTargetLanguages : targetLanguages);
618
+ usage(targetLanguages ?? quicktype_core_1.defaultTargetLanguages);
611
619
  return undefined;
612
620
  }
613
621
  if (options.version) {
614
- console.log(`quicktype version ${packageJSON.version}`);
622
+ console.log(`quicktype version ${package_json_1.default.version}`);
615
623
  console.log("Visit quicktype.io for more info.");
616
624
  return undefined;
617
625
  }
@@ -690,7 +698,7 @@ async function makeQuicktypeOptions(options, targetLanguages) {
690
698
  return (0, quicktype_core_1.messageError)("DriverUnknownSourceLanguage", { lang: options.srcLang });
691
699
  }
692
700
  const components = (0, collection_utils_1.definedMap)(options.debug, d => d.split(","));
693
- const debugAll = components !== undefined && components.indexOf("all") >= 0;
701
+ const debugAll = components !== undefined && components.includes("all");
694
702
  let debugPrintGraph = debugAll;
695
703
  let checkProvenance = debugAll;
696
704
  let debugPrintReconstitution = debugAll;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype",
3
- "version": "23.0.157",
3
+ "version": "23.0.159",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,7 +14,9 @@
14
14
  "test": "script/test",
15
15
  "start": "script/watch",
16
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"
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/**"
18
20
  },
19
21
  "workspaces": [
20
22
  "./packages/quicktype-core",
@@ -32,9 +34,9 @@
32
34
  "graphql": "^0.11.7",
33
35
  "lodash": "^4.17.21",
34
36
  "moment": "^2.30.1",
35
- "quicktype-core": "23.0.157",
36
- "quicktype-graphql-input": "23.0.157",
37
- "quicktype-typescript-input": "23.0.157",
37
+ "quicktype-core": "23.0.159",
38
+ "quicktype-graphql-input": "23.0.159",
39
+ "quicktype-typescript-input": "23.0.159",
38
40
  "readable-stream": "^4.5.2",
39
41
  "stream-json": "1.8.0",
40
42
  "string-to-stream": "^3.0.1",
@@ -50,16 +52,26 @@
50
52
  "@types/shelljs": "^0.8.15",
51
53
  "@types/stream-json": "^1.7.3",
52
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",
53
58
  "ajv": "^5.5.2",
54
59
  "deep-equal": "^2.2.3",
55
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",
56
69
  "exit": "^0.1.2",
57
70
  "prettier": "^3.2.5",
58
71
  "promise-timeout": "^1.3.0",
59
72
  "semver": "^7.5.4",
60
73
  "shelljs": "^0.8.5",
61
74
  "ts-node": "^10.9.2",
62
- "tslint": "^6.1.3",
63
75
  "watch": "^1.0.2"
64
76
  },
65
77
  "files": [
@@ -1,3 +0,0 @@
1
- export declare function urlsFromURLGrammar(json: any): {
2
- [name: string]: string[];
3
- };
File without changes