quicktype 23.0.175 → 23.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -186,6 +186,11 @@ main();
186
186
 
187
187
  The argument to `quicktype` is a complex object with many optional properties. [Explore its definition](https://github.com/quicktype/quicktype/blob/master/packages/quicktype-core/src/Run.ts#L637) to understand what options are allowed.
188
188
 
189
+ ### Adding Custom logic or Rendering:
190
+
191
+ Quicktype supports creating your own custom languages and rendering output, you can extend existing classes or create your own to be using by the `quicktype function`.<br/>
192
+ Check out [this guide](./doc/CustomRenderer.md) for more info.
193
+
189
194
  ## Contributing
190
195
 
191
196
  `quicktype` is [Open Source](LICENSE) and we love contributors! In fact, we have a [list of issues](https://github.com/quicktype/quicktype/issues?utf8=✓&q=is%3Aissue+is%3Aopen+label%3Ahelp-wanted) that are low-priority for us, but for which we'd happily accept contributions. Support for new target languages is also strongly desired. If you'd like to contribute, need help with anything at all, or would just like to talk things over, come [join us on Slack](http://slack.quicktype.io/).
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { type Readable } from "readable-stream";
3
- import { JSONInput, type Options, type RendererOptions, type SerializedRenderResult, type TargetLanguage } from "quicktype-core";
4
- export interface CLIOptions {
3
+ import { JSONInput, type LanguageName, type Options, type RendererOptions, type SerializedRenderResult, type TargetLanguage } from "quicktype-core";
4
+ export interface CLIOptions<Lang extends LanguageName = LanguageName> {
5
5
  [option: string]: any;
6
6
  additionalSchema: string[];
7
7
  allPropertiesOptional: boolean;
@@ -13,11 +13,11 @@ export interface CLIOptions {
13
13
  help: boolean;
14
14
  httpHeader?: string[];
15
15
  httpMethod?: string;
16
- lang: string;
16
+ lang: Lang;
17
17
  noRender: boolean;
18
18
  out?: string;
19
19
  quiet: boolean;
20
- rendererOptions: RendererOptions;
20
+ rendererOptions: RendererOptions<Lang>;
21
21
  src: string[];
22
22
  srcLang: string;
23
23
  srcUrls?: string;
package/dist/index.js CHANGED
@@ -206,17 +206,18 @@ function inferCLIOptions(opts, targetLanguage) {
206
206
  }
207
207
  else {
208
208
  const languageName = opts.lang ?? inferLang(opts, defaultDefaultTargetLanguageName);
209
- const maybeLanguage = (0, quicktype_core_1.languageNamed)(languageName);
210
- if (maybeLanguage === undefined) {
209
+ if ((0, quicktype_core_1.isLanguageName)(languageName)) {
210
+ language = (0, quicktype_core_1.languageNamed)(languageName);
211
+ }
212
+ else {
211
213
  return (0, quicktype_core_1.messageError)("DriverUnknownOutputLanguage", { lang: languageName });
212
214
  }
213
- language = maybeLanguage;
214
215
  }
215
216
  const options = {
216
217
  src: opts.src ?? [],
217
218
  srcUrls: opts.srcUrls,
218
219
  srcLang: srcLang,
219
- lang: language.displayName,
220
+ lang: language.name,
220
221
  topLevel: opts.topLevel ?? inferTopLevel(opts),
221
222
  noRender: !!opts.noRender,
222
223
  alphabetizeProperties: !!opts.alphabetizeProperties,
@@ -476,7 +477,8 @@ function parseCLIOptions(argv, targetLanguage) {
476
477
  // twice. This is the first parse to get the renderer:
477
478
  const incompleteOptions = inferCLIOptions(parseOptions(optionDefinitions, argv, true), targetLanguage);
478
479
  if (targetLanguage === undefined) {
479
- targetLanguage = (0, quicktype_core_1.getTargetLanguage)(incompleteOptions.lang);
480
+ const languageName = (0, quicktype_core_1.isLanguageName)(incompleteOptions.lang) ? incompleteOptions.lang : "typescript";
481
+ targetLanguage = (0, quicktype_core_1.getTargetLanguage)(languageName);
480
482
  }
481
483
  const rendererOptionDefinitions = targetLanguage.cliOptionDefinitions.actual;
482
484
  // Use the global options as well as the renderer options from now on:
@@ -506,16 +508,17 @@ function parseOptions(definitions, argv, partial) {
506
508
  });
507
509
  }
508
510
  }
509
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
510
511
  const options = { rendererOptions: {} };
511
- for (const o of definitions) {
512
- if (!(0, collection_utils_1.hasOwnProperty)(opts, o.name))
512
+ for (const optionDefinition of definitions) {
513
+ if (!(0, collection_utils_1.hasOwnProperty)(opts, optionDefinition.name)) {
513
514
  continue;
514
- const v = opts[o.name];
515
- if (o.renderer !== undefined)
516
- options.rendererOptions[o.name] = v;
515
+ }
516
+ const v = opts[optionDefinition.name];
517
+ if (optionDefinition.name in options.rendererOptions) {
518
+ options.rendererOptions[optionDefinition.name] = v;
519
+ }
517
520
  else {
518
- const k = _.lowerFirst(o.name.split("-").map(_.upperFirst).join(""));
521
+ const k = _.lowerFirst(optionDefinition.name.split("-").map(_.upperFirst).join(""));
519
522
  options[k] = v;
520
523
  }
521
524
  }
@@ -582,7 +585,8 @@ function makeTypeScriptSource(fileNames) {
582
585
  }
583
586
  function jsonInputForTargetLanguage(targetLanguage, languages, handleJSONRefs = false) {
584
587
  if (typeof targetLanguage === "string") {
585
- targetLanguage = (0, quicktype_core_1.defined)((0, quicktype_core_1.languageNamed)(targetLanguage, languages));
588
+ const languageName = (0, quicktype_core_1.isLanguageName)(targetLanguage) ? targetLanguage : "typescript";
589
+ targetLanguage = (0, quicktype_core_1.defined)((0, quicktype_core_1.languageNamed)(languageName, languages));
586
590
  }
587
591
  const compressedJSON = new CompressedJSONFromStream_1.CompressedJSONFromStream(targetLanguage.dateTimeRecognizer, handleJSONRefs);
588
592
  return new quicktype_core_1.JSONInput(compressedJSON);
@@ -736,10 +740,10 @@ async function makeQuicktypeOptions(options, targetLanguages) {
736
740
  }
737
741
  }
738
742
  }
739
- const lang = (0, quicktype_core_1.languageNamed)(options.lang, targetLanguages);
740
- if (lang === undefined) {
743
+ if (!(0, quicktype_core_1.isLanguageName)(options.lang)) {
741
744
  return (0, quicktype_core_1.messageError)("DriverUnknownOutputLanguage", { lang: options.lang });
742
745
  }
746
+ const lang = (0, quicktype_core_1.languageNamed)(options.lang, targetLanguages);
743
747
  const quicktypeOptions = {
744
748
  lang,
745
749
  alphabetizeProperties: options.alphabetizeProperties,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype",
3
- "version": "23.0.175",
3
+ "version": "23.1.0",
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.175",
38
- "quicktype-graphql-input": "23.0.175",
39
- "quicktype-typescript-input": "23.0.175",
37
+ "quicktype-core": "23.1.0",
38
+ "quicktype-graphql-input": "23.1.0",
39
+ "quicktype-typescript-input": "23.1.0",
40
40
  "readable-stream": "^4.5.2",
41
41
  "stream-json": "1.8.0",
42
42
  "string-to-stream": "^3.0.1",