quicktype 16.0.42 → 17.0.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.
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 +40 -38
  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 +28 -4
  139. package/package.json +25 -19
@@ -1,13 +1,6 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompressedJSONFromStream = void 0;
11
4
  const CompressedJSON_1 = require("../quicktype-core/input/CompressedJSON");
12
5
  const { Parser } = require("stream-json");
13
6
  const methodMap = {
@@ -25,41 +18,36 @@ const methodMap = {
25
18
  falseValue: "handleFalseValue"
26
19
  };
27
20
  class CompressedJSONFromStream extends CompressedJSON_1.CompressedJSON {
28
- constructor() {
29
- super(...arguments);
30
- this.handleStartNumber = () => {
31
- this.pushContext();
32
- this.context.currentNumberIsDouble = false;
33
- };
34
- this.handleNumberChunk = (s) => {
35
- const ctx = this.context;
36
- if (!ctx.currentNumberIsDouble && /[\.e]/i.test(s)) {
37
- ctx.currentNumberIsDouble = true;
21
+ async parse(readStream) {
22
+ const combo = new Parser({ packKeys: true, packStrings: true });
23
+ combo.on("data", (item) => {
24
+ if (typeof methodMap[item.name] === "string") {
25
+ this[methodMap[item.name]](item.value);
38
26
  }
39
- };
40
- }
41
- parse(readStream) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const combo = new Parser({ packKeys: true, packStrings: true });
44
- combo.on("data", (item) => {
45
- if (typeof methodMap[item.name] === "string") {
46
- this[methodMap[item.name]](item.value);
47
- }
27
+ });
28
+ const promise = new Promise((resolve, reject) => {
29
+ combo.on("end", () => {
30
+ resolve(this.finish());
48
31
  });
49
- const promise = new Promise((resolve, reject) => {
50
- combo.on("end", () => {
51
- resolve(this.finish());
52
- });
53
- combo.on("error", (err) => {
54
- reject(err);
55
- });
32
+ combo.on("error", (err) => {
33
+ reject(err);
56
34
  });
57
- readStream.setEncoding("utf8");
58
- readStream.pipe(combo);
59
- readStream.resume();
60
- return promise;
61
35
  });
36
+ readStream.setEncoding("utf8");
37
+ readStream.pipe(combo);
38
+ readStream.resume();
39
+ return promise;
62
40
  }
41
+ handleStartNumber = () => {
42
+ this.pushContext();
43
+ this.context.currentNumberIsDouble = false;
44
+ };
45
+ handleNumberChunk = (s) => {
46
+ const ctx = this.context;
47
+ if (!ctx.currentNumberIsDouble && /[\.e]/i.test(s)) {
48
+ ctx.currentNumberIsDouble = true;
49
+ }
50
+ };
63
51
  handleEndNumber() {
64
52
  const isDouble = this.context.currentNumberIsDouble;
65
53
  this.popContext();
@@ -1,15 +1,9 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.introspectServer = void 0;
11
4
  const quicktype_core_1 = require("../quicktype-core");
12
5
  const graphql_1 = require("graphql");
6
+ const ts_necessities_1 = require("@glideapps/ts-necessities");
13
7
  const fetch = require("node-fetch");
14
8
  // https://github.com/apollographql/apollo-codegen/blob/master/src/downloadSchema.ts
15
9
  const defaultHeaders = {
@@ -17,39 +11,37 @@ const defaultHeaders = {
17
11
  "Content-Type": "application/json"
18
12
  };
19
13
  const headerRegExp = /^([^:]+):\s*(.*)$/;
20
- function introspectServer(url, method, headerStrings) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const headers = {};
23
- for (const name of Object.getOwnPropertyNames(defaultHeaders)) {
24
- headers[name] = defaultHeaders[name];
25
- }
26
- for (const str of headerStrings) {
27
- const matches = str.match(headerRegExp);
28
- if (matches === null) {
29
- return quicktype_core_1.panic(`Not a valid HTTP header: "${str}"`);
30
- }
31
- headers[matches[1]] = matches[2];
32
- }
33
- let result;
34
- try {
35
- const response = yield fetch(url, {
36
- method,
37
- headers: headers,
38
- body: JSON.stringify({ query: graphql_1.introspectionQuery })
39
- });
40
- result = yield response.json();
41
- }
42
- catch (error) {
43
- return quicktype_core_1.panic(`Error while fetching introspection query result: ${error.message}`);
44
- }
45
- if (result.errors) {
46
- return quicktype_core_1.panic(`Errors in introspection query result: ${JSON.stringify(result.errors)}`);
47
- }
48
- const schemaData = result;
49
- if (!schemaData.data) {
50
- return quicktype_core_1.panic(`No introspection query result data found, server responded with: ${JSON.stringify(result)}`);
14
+ async function introspectServer(url, method, headerStrings) {
15
+ const headers = {};
16
+ for (const name of Object.getOwnPropertyNames(defaultHeaders)) {
17
+ headers[name] = defaultHeaders[name];
18
+ }
19
+ for (const str of headerStrings) {
20
+ const matches = str.match(headerRegExp);
21
+ if (matches === null) {
22
+ return (0, quicktype_core_1.panic)(`Not a valid HTTP header: "${str}"`);
51
23
  }
52
- return JSON.stringify(schemaData, null, 2);
53
- });
24
+ headers[matches[1]] = matches[2];
25
+ }
26
+ let result;
27
+ try {
28
+ const response = await fetch(url, {
29
+ method,
30
+ headers: headers,
31
+ body: JSON.stringify({ query: graphql_1.introspectionQuery })
32
+ });
33
+ result = await response.json();
34
+ }
35
+ catch (error) {
36
+ return (0, quicktype_core_1.panic)(`Error while fetching introspection query result: ${(0, ts_necessities_1.exceptionToString)(error)}`);
37
+ }
38
+ if (result.errors) {
39
+ return (0, quicktype_core_1.panic)(`Errors in introspection query result: ${JSON.stringify(result.errors)}`);
40
+ }
41
+ const schemaData = result;
42
+ if (!schemaData.data) {
43
+ return (0, quicktype_core_1.panic)(`No introspection query result data found, server responded with: ${JSON.stringify(result)}`);
44
+ }
45
+ return JSON.stringify(schemaData, null, 2);
54
46
  }
55
47
  exports.introspectServer = introspectServer;
@@ -10,4 +10,4 @@ export interface SchemaTypeSource extends JSONSchemaSourceData {
10
10
  export interface GraphQLTypeSource extends GraphQLSourceData {
11
11
  kind: "graphql";
12
12
  }
13
- export declare type TypeSource = GraphQLTypeSource | JSONTypeSource | SchemaTypeSource;
13
+ export type TypeSource = GraphQLTypeSource | JSONTypeSource | SchemaTypeSource;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.urlsFromURLGrammar = void 0;
3
4
  const quicktype_core_1 = require("../quicktype-core");
4
5
  function expand(json) {
5
6
  if (typeof json === "string") {
@@ -20,7 +21,7 @@ function expand(json) {
20
21
  return result;
21
22
  }
22
23
  if (Object.prototype.hasOwnProperty.call(json, "oneOf")) {
23
- const options = quicktype_core_1.checkArray(json.oneOf);
24
+ const options = (0, quicktype_core_1.checkArray)(json.oneOf);
24
25
  const result = [];
25
26
  for (const j of options) {
26
27
  for (const x of expand(j)) {
@@ -29,10 +30,10 @@ function expand(json) {
29
30
  }
30
31
  return result;
31
32
  }
32
- return quicktype_core_1.panic(`Value is not a valid URL grammar: ${json}`);
33
+ return (0, quicktype_core_1.panic)(`Value is not a valid URL grammar: ${json}`);
33
34
  }
34
35
  function urlsFromURLGrammar(json) {
35
- const topLevelMap = quicktype_core_1.checkStringMap(json);
36
+ const topLevelMap = (0, quicktype_core_1.checkStringMap)(json);
36
37
  const results = {};
37
38
  for (const name of Object.getOwnPropertyNames(topLevelMap)) {
38
39
  results[name] = expand(topLevelMap[name]);