quicktype 17.0.4 → 17.0.5

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 +38 -26
  2. package/dist/cli/GraphQLIntrospection.js +41 -33
  3. package/dist/cli/TypeSource.d.ts +1 -1
  4. package/dist/cli/URLGrammar.js +3 -4
  5. package/dist/cli/index.js +364 -363
  6. package/dist/quicktype-core/Annotation.js +0 -2
  7. package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
  8. package/dist/quicktype-core/ConvenienceRenderer.js +81 -104
  9. package/dist/quicktype-core/DateTime.js +0 -1
  10. package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
  11. package/dist/quicktype-core/DeclarationIR.js +10 -13
  12. package/dist/quicktype-core/EncodedMarkovChain.js +0 -1
  13. package/dist/quicktype-core/GatherNames.js +25 -47
  14. package/dist/quicktype-core/Graph.d.ts +2 -2
  15. package/dist/quicktype-core/Graph.js +19 -23
  16. package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
  17. package/dist/quicktype-core/GraphRewriting.js +54 -65
  18. package/dist/quicktype-core/MakeTransformations.js +22 -23
  19. package/dist/quicktype-core/MarkovChain.d.ts +3 -3
  20. package/dist/quicktype-core/MarkovChain.js +8 -9
  21. package/dist/quicktype-core/Messages.d.ts +3 -3
  22. package/dist/quicktype-core/Messages.js +3 -8
  23. package/dist/quicktype-core/Naming.d.ts +11 -11
  24. package/dist/quicktype-core/Naming.js +61 -76
  25. package/dist/quicktype-core/Renderer.d.ts +6 -6
  26. package/dist/quicktype-core/Renderer.js +17 -34
  27. package/dist/quicktype-core/RendererOptions.d.ts +5 -5
  28. package/dist/quicktype-core/RendererOptions.js +3 -6
  29. package/dist/quicktype-core/Run.d.ts +9 -9
  30. package/dist/quicktype-core/Run.js +67 -72
  31. package/dist/quicktype-core/Source.d.ts +3 -3
  32. package/dist/quicktype-core/Source.js +18 -19
  33. package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
  34. package/dist/quicktype-core/TargetLanguage.js +2 -6
  35. package/dist/quicktype-core/Transformers.d.ts +25 -25
  36. package/dist/quicktype-core/Transformers.js +66 -94
  37. package/dist/quicktype-core/Type.d.ts +43 -41
  38. package/dist/quicktype-core/Type.js +71 -96
  39. package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
  40. package/dist/quicktype-core/TypeBuilder.js +47 -53
  41. package/dist/quicktype-core/TypeGraph.d.ts +4 -4
  42. package/dist/quicktype-core/TypeGraph.js +40 -49
  43. package/dist/quicktype-core/TypeUtils.d.ts +2 -2
  44. package/dist/quicktype-core/TypeUtils.js +22 -23
  45. package/dist/quicktype-core/UnifyClasses.js +12 -16
  46. package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
  47. package/dist/quicktype-core/UnionBuilder.js +30 -33
  48. package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
  49. package/dist/quicktype-core/attributes/AccessorNames.js +17 -18
  50. package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
  51. package/dist/quicktype-core/attributes/Constraints.js +4 -8
  52. package/dist/quicktype-core/attributes/Description.js +5 -6
  53. package/dist/quicktype-core/attributes/EnumValues.js +3 -4
  54. package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
  55. package/dist/quicktype-core/attributes/StringTypes.js +21 -24
  56. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
  57. package/dist/quicktype-core/attributes/TypeAttributes.js +10 -12
  58. package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
  59. package/dist/quicktype-core/attributes/TypeNames.js +21 -49
  60. package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
  61. package/dist/quicktype-core/attributes/URIAttributes.js +6 -10
  62. package/dist/quicktype-core/index.js +125 -128
  63. package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
  64. package/dist/quicktype-core/input/CompressedJSON.js +54 -49
  65. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +13 -5
  66. package/dist/quicktype-core/input/Inference.d.ts +2 -2
  67. package/dist/quicktype-core/input/Inference.js +17 -25
  68. package/dist/quicktype-core/input/Inputs.d.ts +2 -2
  69. package/dist/quicktype-core/input/Inputs.js +54 -38
  70. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
  71. package/dist/quicktype-core/input/JSONSchemaInput.js +523 -503
  72. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
  73. package/dist/quicktype-core/input/JSONSchemaStore.js +35 -24
  74. package/dist/quicktype-core/input/PostmanCollection.js +1 -2
  75. package/dist/quicktype-core/input/io/NodeIO.js +44 -55
  76. package/dist/quicktype-core/input/io/get-stream/index.js +2 -6
  77. package/dist/quicktype-core/language/All.js +2 -3
  78. package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
  79. package/dist/quicktype-core/language/CPlusPlus.js +151 -185
  80. package/dist/quicktype-core/language/CSharp.d.ts +7 -7
  81. package/dist/quicktype-core/language/CSharp.js +72 -82
  82. package/dist/quicktype-core/language/Crystal.d.ts +2 -2
  83. package/dist/quicktype-core/language/Crystal.js +17 -18
  84. package/dist/quicktype-core/language/Dart.d.ts +4 -4
  85. package/dist/quicktype-core/language/Dart.js +34 -36
  86. package/dist/quicktype-core/language/Elm.d.ts +6 -6
  87. package/dist/quicktype-core/language/Elm.js +45 -47
  88. package/dist/quicktype-core/language/Golang.d.ts +4 -4
  89. package/dist/quicktype-core/language/Golang.js +20 -23
  90. package/dist/quicktype-core/language/Haskell.d.ts +5 -5
  91. package/dist/quicktype-core/language/Haskell.js +23 -25
  92. package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
  93. package/dist/quicktype-core/language/JSONSchema.js +16 -17
  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 +17 -19
  98. package/dist/quicktype-core/language/JavaScriptPropTypes.js +13 -15
  99. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +11 -12
  100. package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
  101. package/dist/quicktype-core/language/Kotlin.js +37 -39
  102. package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
  103. package/dist/quicktype-core/language/Objective-C.js +41 -45
  104. package/dist/quicktype-core/language/Php.d.ts +2 -2
  105. package/dist/quicktype-core/language/Php.js +41 -66
  106. package/dist/quicktype-core/language/Pike.d.ts +1 -1
  107. package/dist/quicktype-core/language/Pike.js +17 -18
  108. package/dist/quicktype-core/language/Python.d.ts +8 -8
  109. package/dist/quicktype-core/language/Python.js +64 -63
  110. package/dist/quicktype-core/language/Rust.d.ts +2 -2
  111. package/dist/quicktype-core/language/Rust.js +19 -21
  112. package/dist/quicktype-core/language/Swift.d.ts +7 -7
  113. package/dist/quicktype-core/language/Swift.js +804 -807
  114. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
  115. package/dist/quicktype-core/language/TypeScriptFlow.js +26 -28
  116. package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
  117. package/dist/quicktype-core/language/ruby/index.js +24 -49
  118. package/dist/quicktype-core/language/ruby/keywords.js +0 -1
  119. package/dist/quicktype-core/rewrites/CombineClasses.js +8 -9
  120. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
  121. package/dist/quicktype-core/rewrites/ExpandStrings.js +17 -18
  122. package/dist/quicktype-core/rewrites/FlattenStrings.js +6 -7
  123. package/dist/quicktype-core/rewrites/FlattenUnions.js +8 -9
  124. package/dist/quicktype-core/rewrites/InferMaps.js +10 -11
  125. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +7 -8
  126. package/dist/quicktype-core/rewrites/ResolveIntersections.js +67 -68
  127. package/dist/quicktype-core/support/Acronyms.js +1 -3
  128. package/dist/quicktype-core/support/Chance.js +0 -10
  129. package/dist/quicktype-core/support/Converters.js +0 -1
  130. package/dist/quicktype-core/support/Strings.d.ts +4 -4
  131. package/dist/quicktype-core/support/Strings.js +16 -17
  132. package/dist/quicktype-core/support/Support.d.ts +1 -1
  133. package/dist/quicktype-core/support/Support.js +6 -30
  134. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
  135. package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -1
  136. package/dist/quicktype-graphql-input/index.d.ts +1 -1
  137. package/dist/quicktype-graphql-input/index.js +212 -229
  138. package/dist/quicktype-typescript-input/index.js +4 -28
  139. package/package.json +19 -25
@@ -1,43 +1,27 @@
1
1
  "use strict";
2
2
  /* tslint:disable:strict-boolean-expressions */
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;
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
+ });
25
10
  };
26
11
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.GraphQLInput = void 0;
28
- const graphql = __importStar(require("graphql/language"));
12
+ const graphql = require("graphql/language");
29
13
  const collection_utils_1 = require("collection-utils");
30
14
  const quicktype_core_1 = require("../quicktype-core");
31
15
  const GraphQLSchema_1 = require("./GraphQLSchema");
32
16
  function getField(t, name) {
33
17
  if (!t.fields)
34
- return (0, quicktype_core_1.panic)(`Required field ${name} in type ${t.name} which doesn't have fields.`);
18
+ return quicktype_core_1.panic(`Required field ${name} in type ${t.name} which doesn't have fields.`);
35
19
  for (const f of t.fields) {
36
20
  if (f.name === name) {
37
21
  return f;
38
22
  }
39
23
  }
40
- return (0, quicktype_core_1.panic)(`Required field ${name} not defined on type ${t.name}.`);
24
+ return quicktype_core_1.panic(`Required field ${name} not defined on type ${t.name}.`);
41
25
  }
42
26
  function makeNames(name, fieldName, containingTypeName) {
43
27
  const alternatives = [];
@@ -51,14 +35,14 @@ function makeNames(name, fieldName, containingTypeName) {
51
35
  }
52
36
  function makeNullable(builder, tref, name, fieldName, containingTypeName) {
53
37
  const typeNames = makeNames(name, fieldName, containingTypeName);
54
- const t = (0, quicktype_core_1.derefTypeRef)(tref, builder.typeGraph);
38
+ const t = quicktype_core_1.derefTypeRef(tref, builder.typeGraph);
55
39
  if (!(t instanceof quicktype_core_1.UnionType)) {
56
40
  return builder.getUnionType(typeNames, new Set([tref, builder.getPrimitiveType("null")]));
57
41
  }
58
- const [maybeNull, nonNulls] = (0, quicktype_core_1.removeNullFromUnion)(t);
42
+ const [maybeNull, nonNulls] = quicktype_core_1.removeNullFromUnion(t);
59
43
  if (maybeNull)
60
44
  return tref;
61
- return builder.getUnionType(typeNames, (0, collection_utils_1.setMap)(nonNulls, nn => nn.typeRef).add(builder.getPrimitiveType("null")));
45
+ return builder.getUnionType(typeNames, collection_utils_1.setMap(nonNulls, nn => nn.typeRef).add(builder.getPrimitiveType("null")));
62
46
  }
63
47
  // This is really not the way to do this, but it's easy and works. By default
64
48
  // all types in GraphQL are nullable, and non-nullability must be specially marked,
@@ -67,18 +51,18 @@ function makeNullable(builder, tref, name, fieldName, containingTypeName) {
67
51
  // (and the null) might be left unreachable in the graph. Provenance checking
68
52
  // won't work in this case, which is why it's disabled in testing for GraphQL.
69
53
  function removeNull(builder, tref) {
70
- const t = (0, quicktype_core_1.derefTypeRef)(tref, builder.typeGraph);
54
+ const t = quicktype_core_1.derefTypeRef(tref, builder.typeGraph);
71
55
  if (!(t instanceof quicktype_core_1.UnionType)) {
72
56
  return tref;
73
57
  }
74
- const nonNulls = (0, quicktype_core_1.removeNullFromUnion)(t)[1];
75
- const first = (0, collection_utils_1.iterableFirst)(nonNulls);
58
+ const nonNulls = quicktype_core_1.removeNullFromUnion(t)[1];
59
+ const first = collection_utils_1.iterableFirst(nonNulls);
76
60
  if (first) {
77
61
  if (nonNulls.size === 1)
78
62
  return first.typeRef;
79
- return builder.getUnionType(t.getAttributes(), (0, collection_utils_1.setMap)(nonNulls, nn => nn.typeRef));
63
+ return builder.getUnionType(t.getAttributes(), collection_utils_1.setMap(nonNulls, nn => nn.typeRef));
80
64
  }
81
- return (0, quicktype_core_1.panic)("Trying to remove null results in empty union.");
65
+ return quicktype_core_1.panic("Trying to remove null results in empty union.");
82
66
  }
83
67
  function makeScalar(builder, ft) {
84
68
  switch (ft.name) {
@@ -109,10 +93,118 @@ function expandSelectionSet(selectionSet, inType, optional) {
109
93
  .map(s => ({ selection: s, inType, optional: optional || hasOptionalDirectives(s.directives) }));
110
94
  }
111
95
  class GQLQuery {
112
- _schema;
113
- _fragments;
114
- queries;
115
96
  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
+ };
116
208
  this._schema = schema;
117
209
  this._fragments = {};
118
210
  const queryDocument = graphql.parse(queryString);
@@ -127,159 +219,100 @@ class GQLQuery {
127
219
  this._fragments[def.name.value] = def;
128
220
  }
129
221
  }
130
- (0, quicktype_core_1.messageAssert)(queries.length >= 1, "GraphQLNoQueriesDefined", {});
222
+ quicktype_core_1.messageAssert(queries.length >= 1, "GraphQLNoQueriesDefined", {});
131
223
  this.queries = queries;
132
224
  }
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
- };
244
225
  makeType(builder, query, queryName) {
245
226
  if (query.operation === "query") {
246
227
  return this.makeIRTypeFromSelectionSet(builder, query.selectionSet, this._schema.queryType, null, queryName, "data");
247
228
  }
248
229
  if (query.operation === "mutation") {
249
230
  if (this._schema.mutationType === undefined) {
250
- return (0, quicktype_core_1.panic)("This GraphQL endpoint has no mutations.");
231
+ return quicktype_core_1.panic("This GraphQL endpoint has no mutations.");
251
232
  }
252
233
  return this.makeIRTypeFromSelectionSet(builder, query.selectionSet, this._schema.mutationType, null, queryName, "data");
253
234
  }
254
- return (0, quicktype_core_1.panic)(`Unknown query operation type: "${query.operation}"`);
235
+ return quicktype_core_1.panic(`Unknown query operation type: "${query.operation}"`);
255
236
  }
256
237
  }
257
238
  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;
263
239
  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
+ };
264
297
  const schema = json.data;
265
298
  if (schema.__schema.queryType.name === null) {
266
- return (0, quicktype_core_1.panic)("Query type doesn't have a name.");
299
+ return quicktype_core_1.panic("Query type doesn't have a name.");
267
300
  }
268
301
  for (const t of schema.__schema.types) {
269
302
  if (!t.name)
270
- return (0, quicktype_core_1.panic)("No top-level type name given");
303
+ return quicktype_core_1.panic("No top-level type name given");
271
304
  this.types[t.name] = { kind: t.kind, name: t.name, description: t.description };
272
305
  }
273
306
  for (const t of schema.__schema.types) {
274
307
  if (!t.name)
275
- return (0, quicktype_core_1.panic)("This cannot happen");
308
+ return quicktype_core_1.panic("This cannot happen");
276
309
  const type = this.types[t.name];
277
310
  this.addTypeFields(type, t);
278
311
  // console.log(`type ${type.name} is ${type.kind}`);
279
312
  }
280
313
  const queryType = this.types[schema.__schema.queryType.name];
281
314
  if (queryType === undefined) {
282
- return (0, quicktype_core_1.panic)("Query type not found.");
315
+ return quicktype_core_1.panic("Query type not found.");
283
316
  }
284
317
  // console.log(`query type ${queryType.name} is ${queryType.kind}`);
285
318
  this.queryType = queryType;
@@ -287,70 +320,14 @@ class GQLSchemaFromJSON {
287
320
  return;
288
321
  }
289
322
  if (schema.__schema.mutationType.name === null) {
290
- return (0, quicktype_core_1.panic)("Mutation type doesn't have a name.");
323
+ return quicktype_core_1.panic("Mutation type doesn't have a name.");
291
324
  }
292
325
  const mutationType = this.types[schema.__schema.mutationType.name];
293
326
  if (mutationType === undefined) {
294
- return (0, quicktype_core_1.panic)("Mutation type not found.");
327
+ return quicktype_core_1.panic("Mutation type not found.");
295
328
  }
296
329
  this.mutationType = mutationType;
297
330
  }
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
- };
354
331
  }
355
332
  function makeGraphQLQueryTypes(topLevelName, builder, json, queryString) {
356
333
  const schema = new GQLSchemaFromJSON(json);
@@ -359,15 +336,15 @@ function makeGraphQLQueryTypes(topLevelName, builder, json, queryString) {
359
336
  for (const odn of query.queries) {
360
337
  const queryName = odn.name ? odn.name.value : topLevelName;
361
338
  if (types.has(queryName)) {
362
- return (0, quicktype_core_1.panic)(`Duplicate query name ${queryName}`);
339
+ return quicktype_core_1.panic(`Duplicate query name ${queryName}`);
363
340
  }
364
341
  const dataType = query.makeType(builder, odn, queryName);
365
342
  const dataOrNullType = builder.getUnionType(quicktype_core_1.emptyTypeAttributes, new Set([dataType, builder.getPrimitiveType("null")]));
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)({
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({
367
344
  message: builder.makeClassProperty(builder.getStringType(quicktype_core_1.emptyTypeAttributes, quicktype_core_1.StringTypes.unrestricted), false)
368
345
  }));
369
346
  const errorArray = builder.getArrayType(quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set(["errors"]), new Set(["graphQLErrors"]), false)), errorType);
370
- const t = builder.getClassType((0, quicktype_core_1.makeNamesTypeAttributes)(queryName, false), (0, collection_utils_1.mapFromObject)({
347
+ const t = builder.getClassType(quicktype_core_1.makeNamesTypeAttributes(queryName, false), collection_utils_1.mapFromObject({
371
348
  data: builder.makeClassProperty(dataOrNullType, false),
372
349
  errors: builder.makeClassProperty(errorArray, true)
373
350
  }));
@@ -376,12 +353,16 @@ function makeGraphQLQueryTypes(topLevelName, builder, json, queryString) {
376
353
  return types;
377
354
  }
378
355
  class GraphQLInput {
379
- kind = "graphql";
380
- needIR = true;
381
- needSchemaProcessing = false;
382
- _topLevels = new Map();
383
- async addSource(source) {
384
- this.addSourceSync(source);
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
+ });
385
366
  }
386
367
  addSourceSync(source) {
387
368
  this._topLevels.set(source.name, {
@@ -392,8 +373,10 @@ class GraphQLInput {
392
373
  singleStringSchemaSource() {
393
374
  return undefined;
394
375
  }
395
- async addTypes(ctx, typeBuilder) {
396
- return this.addTypesSync(ctx, typeBuilder);
376
+ addTypes(ctx, typeBuilder) {
377
+ return __awaiter(this, void 0, void 0, function* () {
378
+ return this.addTypesSync(ctx, typeBuilder);
379
+ });
397
380
  }
398
381
  addTypesSync(_ctx, typeBuilder) {
399
382
  for (const [name, { schema, query }] of this._topLevels) {
@@ -1,30 +1,6 @@
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
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.schemaForTypeScriptSources = void 0;
27
- const ts = __importStar(require("typescript"));
3
+ const ts = require("typescript");
28
4
  const typescript_json_schema_1 = require("@mark.probst/typescript-json-schema");
29
5
  const quicktype_core_1 = require("../quicktype-core");
30
6
  const settings = {
@@ -50,11 +26,11 @@ function schemaForTypeScriptSources(sourceFileNames) {
50
26
  const diagnostics = ts.getPreEmitDiagnostics(program);
51
27
  const error = diagnostics.find(d => d.category === ts.DiagnosticCategory.Error);
52
28
  if (error !== undefined) {
53
- return (0, quicktype_core_1.messageError)("TypeScriptCompilerError", {
29
+ return quicktype_core_1.messageError("TypeScriptCompilerError", {
54
30
  message: ts.flattenDiagnosticMessageText(error.messageText, "\n")
55
31
  });
56
32
  }
57
- const schema = (0, typescript_json_schema_1.generateSchema)(program, "*", settings);
33
+ const schema = typescript_json_schema_1.generateSchema(program, "*", settings);
58
34
  const uris = [];
59
35
  let topLevelName = undefined;
60
36
  if (schema !== null && typeof schema === "object" && typeof schema.definitions === "object") {
@@ -71,7 +47,7 @@ function schemaForTypeScriptSources(sourceFileNames) {
71
47
  if (matches === null) {
72
48
  continue;
73
49
  }
74
- const index = (0, quicktype_core_1.defined)(matches.index);
50
+ const index = quicktype_core_1.defined(matches.index);
75
51
  definition.description = description.slice(0, index) + description.slice(index + matches[0].length);
76
52
  uris.push(`#/definitions/${name}`);
77
53
  if (topLevelName === undefined) {