quicktype 17.0.6 → 18.0.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.
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 +36 -34
  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 +20 -18
  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 +24 -20
@@ -1,27 +1,43 @@
1
1
  "use strict";
2
2
  /* tslint:disable:strict-boolean-expressions */
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
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;
10
25
  };
11
26
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const graphql = require("graphql/language");
27
+ exports.GraphQLInput = void 0;
28
+ const graphql = __importStar(require("graphql/language"));
13
29
  const collection_utils_1 = require("collection-utils");
14
30
  const quicktype_core_1 = require("../quicktype-core");
15
31
  const GraphQLSchema_1 = require("./GraphQLSchema");
16
32
  function getField(t, name) {
17
33
  if (!t.fields)
18
- return quicktype_core_1.panic(`Required field ${name} in type ${t.name} which doesn't have fields.`);
34
+ return (0, quicktype_core_1.panic)(`Required field ${name} in type ${t.name} which doesn't have fields.`);
19
35
  for (const f of t.fields) {
20
36
  if (f.name === name) {
21
37
  return f;
22
38
  }
23
39
  }
24
- return quicktype_core_1.panic(`Required field ${name} not defined on type ${t.name}.`);
40
+ return (0, quicktype_core_1.panic)(`Required field ${name} not defined on type ${t.name}.`);
25
41
  }
26
42
  function makeNames(name, fieldName, containingTypeName) {
27
43
  const alternatives = [];
@@ -35,14 +51,14 @@ function makeNames(name, fieldName, containingTypeName) {
35
51
  }
36
52
  function makeNullable(builder, tref, name, fieldName, containingTypeName) {
37
53
  const typeNames = makeNames(name, fieldName, containingTypeName);
38
- const t = quicktype_core_1.derefTypeRef(tref, builder.typeGraph);
54
+ const t = (0, quicktype_core_1.derefTypeRef)(tref, builder.typeGraph);
39
55
  if (!(t instanceof quicktype_core_1.UnionType)) {
40
56
  return builder.getUnionType(typeNames, new Set([tref, builder.getPrimitiveType("null")]));
41
57
  }
42
- const [maybeNull, nonNulls] = quicktype_core_1.removeNullFromUnion(t);
58
+ const [maybeNull, nonNulls] = (0, quicktype_core_1.removeNullFromUnion)(t);
43
59
  if (maybeNull)
44
60
  return tref;
45
- return builder.getUnionType(typeNames, collection_utils_1.setMap(nonNulls, nn => nn.typeRef).add(builder.getPrimitiveType("null")));
61
+ return builder.getUnionType(typeNames, (0, collection_utils_1.setMap)(nonNulls, nn => nn.typeRef).add(builder.getPrimitiveType("null")));
46
62
  }
47
63
  // This is really not the way to do this, but it's easy and works. By default
48
64
  // all types in GraphQL are nullable, and non-nullability must be specially marked,
@@ -51,18 +67,18 @@ function makeNullable(builder, tref, name, fieldName, containingTypeName) {
51
67
  // (and the null) might be left unreachable in the graph. Provenance checking
52
68
  // won't work in this case, which is why it's disabled in testing for GraphQL.
53
69
  function removeNull(builder, tref) {
54
- const t = quicktype_core_1.derefTypeRef(tref, builder.typeGraph);
70
+ const t = (0, quicktype_core_1.derefTypeRef)(tref, builder.typeGraph);
55
71
  if (!(t instanceof quicktype_core_1.UnionType)) {
56
72
  return tref;
57
73
  }
58
- const nonNulls = quicktype_core_1.removeNullFromUnion(t)[1];
59
- const first = collection_utils_1.iterableFirst(nonNulls);
74
+ const nonNulls = (0, quicktype_core_1.removeNullFromUnion)(t)[1];
75
+ const first = (0, collection_utils_1.iterableFirst)(nonNulls);
60
76
  if (first) {
61
77
  if (nonNulls.size === 1)
62
78
  return first.typeRef;
63
- return builder.getUnionType(t.getAttributes(), collection_utils_1.setMap(nonNulls, nn => nn.typeRef));
79
+ return builder.getUnionType(t.getAttributes(), (0, collection_utils_1.setMap)(nonNulls, nn => nn.typeRef));
64
80
  }
65
- return quicktype_core_1.panic("Trying to remove null results in empty union.");
81
+ return (0, quicktype_core_1.panic)("Trying to remove null results in empty union.");
66
82
  }
67
83
  function makeScalar(builder, ft) {
68
84
  switch (ft.name) {
@@ -93,118 +109,10 @@ function expandSelectionSet(selectionSet, inType, optional) {
93
109
  .map(s => ({ selection: s, inType, optional: optional || hasOptionalDirectives(s.directives) }));
94
110
  }
95
111
  class GQLQuery {
112
+ _schema;
113
+ _fragments;
114
+ queries;
96
115
  constructor(schema, queryString) {
97
- this.makeIRTypeFromFieldNode = (builder, fieldNode, fieldType, containingTypeName) => {
98
- let optional = hasOptionalDirectives(fieldNode.directives);
99
- let result;
100
- switch (fieldType.kind) {
101
- case GraphQLSchema_1.TypeKind.SCALAR:
102
- result = makeScalar(builder, fieldType);
103
- optional = true;
104
- break;
105
- case GraphQLSchema_1.TypeKind.OBJECT:
106
- case GraphQLSchema_1.TypeKind.INTERFACE:
107
- case GraphQLSchema_1.TypeKind.UNION:
108
- if (!fieldNode.selectionSet) {
109
- return quicktype_core_1.panic("No selection set on object or interface");
110
- }
111
- return makeNullable(builder, this.makeIRTypeFromSelectionSet(builder, fieldNode.selectionSet, fieldType, fieldNode.name.value, containingTypeName), fieldNode.name.value, null, containingTypeName);
112
- case GraphQLSchema_1.TypeKind.ENUM:
113
- if (!fieldType.enumValues) {
114
- return quicktype_core_1.panic("Enum type doesn't have values");
115
- }
116
- const values = fieldType.enumValues.map(ev => ev.name);
117
- let name;
118
- let fieldName;
119
- if (fieldType.name) {
120
- name = fieldType.name;
121
- fieldName = fieldNode.name.value;
122
- }
123
- else {
124
- name = fieldNode.name.value;
125
- fieldName = null;
126
- }
127
- optional = true;
128
- result = builder.getEnumType(makeNames(name, fieldName, containingTypeName), new Set(values));
129
- break;
130
- case GraphQLSchema_1.TypeKind.INPUT_OBJECT:
131
- // FIXME: Support input objects
132
- return quicktype_core_1.panic("Input objects not supported");
133
- case GraphQLSchema_1.TypeKind.LIST:
134
- if (!fieldType.ofType) {
135
- return quicktype_core_1.panic("No type for list");
136
- }
137
- result = builder.getArrayType(quicktype_core_1.emptyTypeAttributes, this.makeIRTypeFromFieldNode(builder, fieldNode, fieldType.ofType, containingTypeName));
138
- break;
139
- case GraphQLSchema_1.TypeKind.NON_NULL:
140
- if (!fieldType.ofType) {
141
- return quicktype_core_1.panic("No type for non-null");
142
- }
143
- result = removeNull(builder, this.makeIRTypeFromFieldNode(builder, fieldNode, fieldType.ofType, containingTypeName));
144
- break;
145
- default:
146
- return quicktype_core_1.assertNever(fieldType.kind);
147
- }
148
- if (optional) {
149
- result = makeNullable(builder, result, fieldNode.name.value, null, containingTypeName);
150
- }
151
- return result;
152
- };
153
- this.getFragment = (name) => {
154
- const fragment = this._fragments[name];
155
- if (!fragment)
156
- return quicktype_core_1.panic(`Fragment ${name} is not defined.`);
157
- return fragment;
158
- };
159
- this.makeIRTypeFromSelectionSet = (builder, selectionSet, gqlType, containingFieldName, containingTypeName, overrideName) => {
160
- if (gqlType.kind !== GraphQLSchema_1.TypeKind.OBJECT &&
161
- gqlType.kind !== GraphQLSchema_1.TypeKind.INTERFACE &&
162
- gqlType.kind !== GraphQLSchema_1.TypeKind.UNION) {
163
- return quicktype_core_1.panic("Type for selection set is not object, interface, or union.");
164
- }
165
- if (!gqlType.name) {
166
- return quicktype_core_1.panic("Object, interface, or union type doesn't have a name.");
167
- }
168
- const nameOrOverride = overrideName || gqlType.name;
169
- const properties = new Map();
170
- let selections = expandSelectionSet(selectionSet, gqlType, false);
171
- for (;;) {
172
- const nextItem = selections.pop();
173
- if (!nextItem)
174
- break;
175
- const { selection, optional, inType } = nextItem;
176
- switch (selection.kind) {
177
- case "Field":
178
- const fieldName = selection.name.value;
179
- const givenName = selection.alias ? selection.alias.value : fieldName;
180
- const field = getField(inType, fieldName);
181
- let fieldType = this.makeIRTypeFromFieldNode(builder, selection, field.type, nameOrOverride);
182
- properties.set(givenName, builder.makeClassProperty(fieldType, optional));
183
- break;
184
- case "FragmentSpread": {
185
- const fragment = this.getFragment(selection.name.value);
186
- const fragmentType = this._schema.types[fragment.typeCondition.name.value];
187
- const fragmentOptional = optional || fragmentType.name !== inType.name;
188
- const expanded = expandSelectionSet(fragment.selectionSet, fragmentType, fragmentOptional);
189
- selections = selections.concat(expanded);
190
- break;
191
- }
192
- case "InlineFragment": {
193
- // FIXME: support type conditions with discriminated unions
194
- const fragmentType = selection.typeCondition
195
- ? this._schema.types[selection.typeCondition.name.value]
196
- : inType;
197
- const fragmentOptional = optional || fragmentType.name !== inType.name || hasOptionalDirectives(selection.directives);
198
- const expanded = expandSelectionSet(selection.selectionSet, fragmentType, fragmentOptional);
199
- selections = selections.concat(expanded);
200
- break;
201
- }
202
- default:
203
- quicktype_core_1.assertNever(selection);
204
- }
205
- }
206
- return builder.getClassType(makeNames(nameOrOverride, containingFieldName, containingTypeName), properties);
207
- };
208
116
  this._schema = schema;
209
117
  this._fragments = {};
210
118
  const queryDocument = graphql.parse(queryString);
@@ -219,100 +127,159 @@ class GQLQuery {
219
127
  this._fragments[def.name.value] = def;
220
128
  }
221
129
  }
222
- quicktype_core_1.messageAssert(queries.length >= 1, "GraphQLNoQueriesDefined", {});
130
+ (0, quicktype_core_1.messageAssert)(queries.length >= 1, "GraphQLNoQueriesDefined", {});
223
131
  this.queries = queries;
224
132
  }
133
+ makeIRTypeFromFieldNode = (builder, fieldNode, fieldType, containingTypeName) => {
134
+ let optional = hasOptionalDirectives(fieldNode.directives);
135
+ let result;
136
+ switch (fieldType.kind) {
137
+ case GraphQLSchema_1.TypeKind.SCALAR:
138
+ result = makeScalar(builder, fieldType);
139
+ optional = true;
140
+ break;
141
+ case GraphQLSchema_1.TypeKind.OBJECT:
142
+ case GraphQLSchema_1.TypeKind.INTERFACE:
143
+ case GraphQLSchema_1.TypeKind.UNION:
144
+ if (!fieldNode.selectionSet) {
145
+ return (0, quicktype_core_1.panic)("No selection set on object or interface");
146
+ }
147
+ return makeNullable(builder, this.makeIRTypeFromSelectionSet(builder, fieldNode.selectionSet, fieldType, fieldNode.name.value, containingTypeName), fieldNode.name.value, null, containingTypeName);
148
+ case GraphQLSchema_1.TypeKind.ENUM:
149
+ if (!fieldType.enumValues) {
150
+ return (0, quicktype_core_1.panic)("Enum type doesn't have values");
151
+ }
152
+ const values = fieldType.enumValues.map(ev => ev.name);
153
+ let name;
154
+ let fieldName;
155
+ if (fieldType.name) {
156
+ name = fieldType.name;
157
+ fieldName = fieldNode.name.value;
158
+ }
159
+ else {
160
+ name = fieldNode.name.value;
161
+ fieldName = null;
162
+ }
163
+ optional = true;
164
+ result = builder.getEnumType(makeNames(name, fieldName, containingTypeName), new Set(values));
165
+ break;
166
+ case GraphQLSchema_1.TypeKind.INPUT_OBJECT:
167
+ // FIXME: Support input objects
168
+ return (0, quicktype_core_1.panic)("Input objects not supported");
169
+ case GraphQLSchema_1.TypeKind.LIST:
170
+ if (!fieldType.ofType) {
171
+ return (0, quicktype_core_1.panic)("No type for list");
172
+ }
173
+ result = builder.getArrayType(quicktype_core_1.emptyTypeAttributes, this.makeIRTypeFromFieldNode(builder, fieldNode, fieldType.ofType, containingTypeName));
174
+ break;
175
+ case GraphQLSchema_1.TypeKind.NON_NULL:
176
+ if (!fieldType.ofType) {
177
+ return (0, quicktype_core_1.panic)("No type for non-null");
178
+ }
179
+ result = removeNull(builder, this.makeIRTypeFromFieldNode(builder, fieldNode, fieldType.ofType, containingTypeName));
180
+ break;
181
+ default:
182
+ return (0, quicktype_core_1.assertNever)(fieldType.kind);
183
+ }
184
+ if (optional) {
185
+ result = makeNullable(builder, result, fieldNode.name.value, null, containingTypeName);
186
+ }
187
+ return result;
188
+ };
189
+ getFragment = (name) => {
190
+ const fragment = this._fragments[name];
191
+ if (!fragment)
192
+ return (0, quicktype_core_1.panic)(`Fragment ${name} is not defined.`);
193
+ return fragment;
194
+ };
195
+ makeIRTypeFromSelectionSet = (builder, selectionSet, gqlType, containingFieldName, containingTypeName, overrideName) => {
196
+ if (gqlType.kind !== GraphQLSchema_1.TypeKind.OBJECT &&
197
+ gqlType.kind !== GraphQLSchema_1.TypeKind.INTERFACE &&
198
+ gqlType.kind !== GraphQLSchema_1.TypeKind.UNION) {
199
+ return (0, quicktype_core_1.panic)("Type for selection set is not object, interface, or union.");
200
+ }
201
+ if (!gqlType.name) {
202
+ return (0, quicktype_core_1.panic)("Object, interface, or union type doesn't have a name.");
203
+ }
204
+ const nameOrOverride = overrideName || gqlType.name;
205
+ const properties = new Map();
206
+ let selections = expandSelectionSet(selectionSet, gqlType, false);
207
+ for (;;) {
208
+ const nextItem = selections.pop();
209
+ if (!nextItem)
210
+ break;
211
+ const { selection, optional, inType } = nextItem;
212
+ switch (selection.kind) {
213
+ case "Field":
214
+ const fieldName = selection.name.value;
215
+ const givenName = selection.alias ? selection.alias.value : fieldName;
216
+ const field = getField(inType, fieldName);
217
+ let fieldType = this.makeIRTypeFromFieldNode(builder, selection, field.type, nameOrOverride);
218
+ properties.set(givenName, builder.makeClassProperty(fieldType, optional));
219
+ break;
220
+ case "FragmentSpread": {
221
+ const fragment = this.getFragment(selection.name.value);
222
+ const fragmentType = this._schema.types[fragment.typeCondition.name.value];
223
+ const fragmentOptional = optional || fragmentType.name !== inType.name;
224
+ const expanded = expandSelectionSet(fragment.selectionSet, fragmentType, fragmentOptional);
225
+ selections = selections.concat(expanded);
226
+ break;
227
+ }
228
+ case "InlineFragment": {
229
+ // FIXME: support type conditions with discriminated unions
230
+ const fragmentType = selection.typeCondition
231
+ ? this._schema.types[selection.typeCondition.name.value]
232
+ : inType;
233
+ const fragmentOptional = optional || fragmentType.name !== inType.name || hasOptionalDirectives(selection.directives);
234
+ const expanded = expandSelectionSet(selection.selectionSet, fragmentType, fragmentOptional);
235
+ selections = selections.concat(expanded);
236
+ break;
237
+ }
238
+ default:
239
+ (0, quicktype_core_1.assertNever)(selection);
240
+ }
241
+ }
242
+ return builder.getClassType(makeNames(nameOrOverride, containingFieldName, containingTypeName), properties);
243
+ };
225
244
  makeType(builder, query, queryName) {
226
245
  if (query.operation === "query") {
227
246
  return this.makeIRTypeFromSelectionSet(builder, query.selectionSet, this._schema.queryType, null, queryName, "data");
228
247
  }
229
248
  if (query.operation === "mutation") {
230
249
  if (this._schema.mutationType === undefined) {
231
- return quicktype_core_1.panic("This GraphQL endpoint has no mutations.");
250
+ return (0, quicktype_core_1.panic)("This GraphQL endpoint has no mutations.");
232
251
  }
233
252
  return this.makeIRTypeFromSelectionSet(builder, query.selectionSet, this._schema.mutationType, null, queryName, "data");
234
253
  }
235
- return quicktype_core_1.panic(`Unknown query operation type: "${query.operation}"`);
254
+ return (0, quicktype_core_1.panic)(`Unknown query operation type: "${query.operation}"`);
236
255
  }
237
256
  }
238
257
  class GQLSchemaFromJSON {
258
+ types = {};
259
+ // @ts-ignore: The constructor can return early, but only by throwing.
260
+ queryType;
261
+ // @ts-ignore: The constructor can return early, but only by throwing.
262
+ mutationType;
239
263
  constructor(json) {
240
- this.types = {};
241
- this.addTypeFields = (target, source) => {
242
- if (source.fields) {
243
- target.fields = source.fields.map(f => {
244
- return {
245
- name: f.name,
246
- description: f.description,
247
- type: this.makeType(f.type),
248
- args: f.args.map(this.makeInputValue)
249
- };
250
- });
251
- // console.log(`${target.name} has ${target.fields.length} fields`);
252
- }
253
- if (source.interfaces) {
254
- target.interfaces = source.interfaces.map(this.makeType);
255
- // console.log(`${target.name} has ${target.interfaces.length} interfaces`);
256
- }
257
- if (source.possibleTypes) {
258
- target.possibleTypes = source.possibleTypes.map(this.makeType);
259
- // console.log(`${target.name} has ${target.possibleTypes.length} possibleTypes`);
260
- }
261
- if (source.inputFields) {
262
- target.inputFields = source.inputFields.map(this.makeInputValue);
263
- // console.log(`${target.name} has ${target.inputFields.length} inputFields`);
264
- }
265
- if (source.enumValues) {
266
- target.enumValues = source.enumValues.map(ev => {
267
- return { name: ev.name, description: ev.description };
268
- });
269
- // console.log(`${target.name} has ${target.enumValues.length} enumValues`);
270
- }
271
- };
272
- this.makeInputValue = (iv) => {
273
- return {
274
- name: iv.name,
275
- description: iv.description,
276
- type: this.makeType(iv.type),
277
- defaultValue: iv.defaultValue
278
- };
279
- };
280
- this.makeType = (t) => {
281
- if (t.name) {
282
- const namedType = this.types[t.name];
283
- if (!namedType)
284
- return quicktype_core_1.panic(`Type ${t.name} not found`);
285
- return namedType;
286
- }
287
- if (!t.ofType)
288
- return quicktype_core_1.panic(`Type of kind ${t.kind} has neither name nor ofType`);
289
- const type = {
290
- kind: t.kind,
291
- description: t.description,
292
- ofType: this.makeType(t.ofType)
293
- };
294
- this.addTypeFields(type, t);
295
- return type;
296
- };
297
264
  const schema = json.data;
298
265
  if (schema.__schema.queryType.name === null) {
299
- return quicktype_core_1.panic("Query type doesn't have a name.");
266
+ return (0, quicktype_core_1.panic)("Query type doesn't have a name.");
300
267
  }
301
268
  for (const t of schema.__schema.types) {
302
269
  if (!t.name)
303
- return quicktype_core_1.panic("No top-level type name given");
270
+ return (0, quicktype_core_1.panic)("No top-level type name given");
304
271
  this.types[t.name] = { kind: t.kind, name: t.name, description: t.description };
305
272
  }
306
273
  for (const t of schema.__schema.types) {
307
274
  if (!t.name)
308
- return quicktype_core_1.panic("This cannot happen");
275
+ return (0, quicktype_core_1.panic)("This cannot happen");
309
276
  const type = this.types[t.name];
310
277
  this.addTypeFields(type, t);
311
278
  // console.log(`type ${type.name} is ${type.kind}`);
312
279
  }
313
280
  const queryType = this.types[schema.__schema.queryType.name];
314
281
  if (queryType === undefined) {
315
- return quicktype_core_1.panic("Query type not found.");
282
+ return (0, quicktype_core_1.panic)("Query type not found.");
316
283
  }
317
284
  // console.log(`query type ${queryType.name} is ${queryType.kind}`);
318
285
  this.queryType = queryType;
@@ -320,14 +287,70 @@ class GQLSchemaFromJSON {
320
287
  return;
321
288
  }
322
289
  if (schema.__schema.mutationType.name === null) {
323
- return quicktype_core_1.panic("Mutation type doesn't have a name.");
290
+ return (0, quicktype_core_1.panic)("Mutation type doesn't have a name.");
324
291
  }
325
292
  const mutationType = this.types[schema.__schema.mutationType.name];
326
293
  if (mutationType === undefined) {
327
- return quicktype_core_1.panic("Mutation type not found.");
294
+ return (0, quicktype_core_1.panic)("Mutation type not found.");
328
295
  }
329
296
  this.mutationType = mutationType;
330
297
  }
298
+ addTypeFields = (target, source) => {
299
+ if (source.fields) {
300
+ target.fields = source.fields.map(f => {
301
+ return {
302
+ name: f.name,
303
+ description: f.description,
304
+ type: this.makeType(f.type),
305
+ args: f.args.map(this.makeInputValue)
306
+ };
307
+ });
308
+ // console.log(`${target.name} has ${target.fields.length} fields`);
309
+ }
310
+ if (source.interfaces) {
311
+ target.interfaces = source.interfaces.map(this.makeType);
312
+ // console.log(`${target.name} has ${target.interfaces.length} interfaces`);
313
+ }
314
+ if (source.possibleTypes) {
315
+ target.possibleTypes = source.possibleTypes.map(this.makeType);
316
+ // console.log(`${target.name} has ${target.possibleTypes.length} possibleTypes`);
317
+ }
318
+ if (source.inputFields) {
319
+ target.inputFields = source.inputFields.map(this.makeInputValue);
320
+ // console.log(`${target.name} has ${target.inputFields.length} inputFields`);
321
+ }
322
+ if (source.enumValues) {
323
+ target.enumValues = source.enumValues.map(ev => {
324
+ return { name: ev.name, description: ev.description };
325
+ });
326
+ // console.log(`${target.name} has ${target.enumValues.length} enumValues`);
327
+ }
328
+ };
329
+ makeInputValue = (iv) => {
330
+ return {
331
+ name: iv.name,
332
+ description: iv.description,
333
+ type: this.makeType(iv.type),
334
+ defaultValue: iv.defaultValue
335
+ };
336
+ };
337
+ makeType = (t) => {
338
+ if (t.name) {
339
+ const namedType = this.types[t.name];
340
+ if (!namedType)
341
+ return (0, quicktype_core_1.panic)(`Type ${t.name} not found`);
342
+ return namedType;
343
+ }
344
+ if (!t.ofType)
345
+ return (0, quicktype_core_1.panic)(`Type of kind ${t.kind} has neither name nor ofType`);
346
+ const type = {
347
+ kind: t.kind,
348
+ description: t.description,
349
+ ofType: this.makeType(t.ofType)
350
+ };
351
+ this.addTypeFields(type, t);
352
+ return type;
353
+ };
331
354
  }
332
355
  function makeGraphQLQueryTypes(topLevelName, builder, json, queryString) {
333
356
  const schema = new GQLSchemaFromJSON(json);
@@ -336,15 +359,15 @@ function makeGraphQLQueryTypes(topLevelName, builder, json, queryString) {
336
359
  for (const odn of query.queries) {
337
360
  const queryName = odn.name ? odn.name.value : topLevelName;
338
361
  if (types.has(queryName)) {
339
- return quicktype_core_1.panic(`Duplicate query name ${queryName}`);
362
+ return (0, quicktype_core_1.panic)(`Duplicate query name ${queryName}`);
340
363
  }
341
364
  const dataType = query.makeType(builder, odn, queryName);
342
365
  const dataOrNullType = builder.getUnionType(quicktype_core_1.emptyTypeAttributes, new Set([dataType, builder.getPrimitiveType("null")]));
343
- const errorType = builder.getClassType(quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set(["error"]), new Set(["graphQLError"]), false)), collection_utils_1.mapFromObject({
366
+ const errorType = builder.getClassType(quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set(["error"]), new Set(["graphQLError"]), false)), (0, collection_utils_1.mapFromObject)({
344
367
  message: builder.makeClassProperty(builder.getStringType(quicktype_core_1.emptyTypeAttributes, quicktype_core_1.StringTypes.unrestricted), false)
345
368
  }));
346
369
  const errorArray = builder.getArrayType(quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set(["errors"]), new Set(["graphQLErrors"]), false)), errorType);
347
- const t = builder.getClassType(quicktype_core_1.makeNamesTypeAttributes(queryName, false), collection_utils_1.mapFromObject({
370
+ const t = builder.getClassType((0, quicktype_core_1.makeNamesTypeAttributes)(queryName, false), (0, collection_utils_1.mapFromObject)({
348
371
  data: builder.makeClassProperty(dataOrNullType, false),
349
372
  errors: builder.makeClassProperty(errorArray, true)
350
373
  }));
@@ -353,16 +376,12 @@ function makeGraphQLQueryTypes(topLevelName, builder, json, queryString) {
353
376
  return types;
354
377
  }
355
378
  class GraphQLInput {
356
- constructor() {
357
- this.kind = "graphql";
358
- this.needIR = true;
359
- this.needSchemaProcessing = false;
360
- this._topLevels = new Map();
361
- }
362
- addSource(source) {
363
- return __awaiter(this, void 0, void 0, function* () {
364
- this.addSourceSync(source);
365
- });
379
+ kind = "graphql";
380
+ needIR = true;
381
+ needSchemaProcessing = false;
382
+ _topLevels = new Map();
383
+ async addSource(source) {
384
+ this.addSourceSync(source);
366
385
  }
367
386
  addSourceSync(source) {
368
387
  this._topLevels.set(source.name, {
@@ -373,10 +392,8 @@ class GraphQLInput {
373
392
  singleStringSchemaSource() {
374
393
  return undefined;
375
394
  }
376
- addTypes(ctx, typeBuilder) {
377
- return __awaiter(this, void 0, void 0, function* () {
378
- return this.addTypesSync(ctx, typeBuilder);
379
- });
395
+ async addTypes(ctx, typeBuilder) {
396
+ return this.addTypesSync(ctx, typeBuilder);
380
397
  }
381
398
  addTypesSync(_ctx, typeBuilder) {
382
399
  for (const [name, { schema, query }] of this._topLevels) {
@@ -1,6 +1,30 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const ts = require("typescript");
26
+ exports.schemaForTypeScriptSources = void 0;
27
+ const ts = __importStar(require("typescript"));
4
28
  const typescript_json_schema_1 = require("@mark.probst/typescript-json-schema");
5
29
  const quicktype_core_1 = require("../quicktype-core");
6
30
  const settings = {
@@ -26,11 +50,11 @@ function schemaForTypeScriptSources(sourceFileNames) {
26
50
  const diagnostics = ts.getPreEmitDiagnostics(program);
27
51
  const error = diagnostics.find(d => d.category === ts.DiagnosticCategory.Error);
28
52
  if (error !== undefined) {
29
- return quicktype_core_1.messageError("TypeScriptCompilerError", {
53
+ return (0, quicktype_core_1.messageError)("TypeScriptCompilerError", {
30
54
  message: ts.flattenDiagnosticMessageText(error.messageText, "\n")
31
55
  });
32
56
  }
33
- const schema = typescript_json_schema_1.generateSchema(program, "*", settings);
57
+ const schema = (0, typescript_json_schema_1.generateSchema)(program, "*", settings);
34
58
  const uris = [];
35
59
  let topLevelName = undefined;
36
60
  if (schema !== null && typeof schema === "object" && typeof schema.definitions === "object") {
@@ -47,7 +71,7 @@ function schemaForTypeScriptSources(sourceFileNames) {
47
71
  if (matches === null) {
48
72
  continue;
49
73
  }
50
- const index = quicktype_core_1.defined(matches.index);
74
+ const index = (0, quicktype_core_1.defined)(matches.index);
51
75
  definition.description = description.slice(0, index) + description.slice(index + matches[0].length);
52
76
  uris.push(`#/definitions/${name}`);
53
77
  if (topLevelName === undefined) {