quicktype 18.0.5 → 19.0.4

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 (174) hide show
  1. package/README.md +1 -1
  2. package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
  3. package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
  4. package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
  5. package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
  6. package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
  7. package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
  8. package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
  9. package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
  10. package/dist/{cli/index.d.ts → index.d.ts} +1 -1
  11. package/dist/{cli/index.js → index.js} +4 -5
  12. package/package.json +61 -77
  13. package/dist/quicktype-core/Annotation.d.ts +0 -8
  14. package/dist/quicktype-core/Annotation.js +0 -16
  15. package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
  16. package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
  17. package/dist/quicktype-core/DateTime.d.ts +0 -10
  18. package/dist/quicktype-core/DateTime.js +0 -57
  19. package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
  20. package/dist/quicktype-core/DeclarationIR.js +0 -167
  21. package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
  22. package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
  23. package/dist/quicktype-core/GatherNames.d.ts +0 -2
  24. package/dist/quicktype-core/GatherNames.js +0 -333
  25. package/dist/quicktype-core/Graph.d.ts +0 -12
  26. package/dist/quicktype-core/Graph.js +0 -220
  27. package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
  28. package/dist/quicktype-core/GraphRewriting.js +0 -421
  29. package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
  30. package/dist/quicktype-core/MakeTransformations.js +0 -193
  31. package/dist/quicktype-core/MarkovChain.d.ts +0 -15
  32. package/dist/quicktype-core/MarkovChain.js +0 -154
  33. package/dist/quicktype-core/Messages.d.ts +0 -294
  34. package/dist/quicktype-core/Messages.js +0 -105
  35. package/dist/quicktype-core/Naming.d.ts +0 -64
  36. package/dist/quicktype-core/Naming.js +0 -356
  37. package/dist/quicktype-core/Renderer.d.ts +0 -50
  38. package/dist/quicktype-core/Renderer.js +0 -274
  39. package/dist/quicktype-core/RendererOptions.d.ts +0 -71
  40. package/dist/quicktype-core/RendererOptions.js +0 -141
  41. package/dist/quicktype-core/Run.d.ts +0 -174
  42. package/dist/quicktype-core/Run.js +0 -393
  43. package/dist/quicktype-core/Source.d.ts +0 -65
  44. package/dist/quicktype-core/Source.js +0 -204
  45. package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
  46. package/dist/quicktype-core/TargetLanguage.js +0 -66
  47. package/dist/quicktype-core/Transformers.d.ts +0 -209
  48. package/dist/quicktype-core/Transformers.js +0 -836
  49. package/dist/quicktype-core/Type.d.ts +0 -206
  50. package/dist/quicktype-core/Type.js +0 -716
  51. package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
  52. package/dist/quicktype-core/TypeBuilder.js +0 -324
  53. package/dist/quicktype-core/TypeGraph.d.ts +0 -75
  54. package/dist/quicktype-core/TypeGraph.js +0 -420
  55. package/dist/quicktype-core/TypeUtils.d.ts +0 -33
  56. package/dist/quicktype-core/TypeUtils.js +0 -230
  57. package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
  58. package/dist/quicktype-core/UnifyClasses.js +0 -159
  59. package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
  60. package/dist/quicktype-core/UnionBuilder.js +0 -282
  61. package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
  62. package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
  63. package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
  64. package/dist/quicktype-core/attributes/Constraints.js +0 -172
  65. package/dist/quicktype-core/attributes/Description.d.ts +0 -9
  66. package/dist/quicktype-core/attributes/Description.js +0 -97
  67. package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
  68. package/dist/quicktype-core/attributes/EnumValues.js +0 -31
  69. package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
  70. package/dist/quicktype-core/attributes/StringTypes.js +0 -189
  71. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
  72. package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
  73. package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
  74. package/dist/quicktype-core/attributes/TypeNames.js +0 -274
  75. package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
  76. package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
  77. package/dist/quicktype-core/index.d.ts +0 -48
  78. package/dist/quicktype-core/index.js +0 -180
  79. package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
  80. package/dist/quicktype-core/input/CompressedJSON.js +0 -276
  81. package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
  82. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
  83. package/dist/quicktype-core/input/Inference.d.ts +0 -22
  84. package/dist/quicktype-core/input/Inference.js +0 -240
  85. package/dist/quicktype-core/input/Inputs.d.ts +0 -48
  86. package/dist/quicktype-core/input/Inputs.js +0 -145
  87. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
  88. package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
  89. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
  90. package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
  91. package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
  92. package/dist/quicktype-core/input/PostmanCollection.js +0 -60
  93. package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
  94. package/dist/quicktype-core/input/io/NodeIO.js +0 -87
  95. package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
  96. package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
  97. package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
  98. package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
  99. package/dist/quicktype-core/language/All.d.ts +0 -3
  100. package/dist/quicktype-core/language/All.js +0 -57
  101. package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
  102. package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
  103. package/dist/quicktype-core/language/CSharp.d.ts +0 -201
  104. package/dist/quicktype-core/language/CSharp.js +0 -1850
  105. package/dist/quicktype-core/language/Crystal.d.ts +0 -37
  106. package/dist/quicktype-core/language/Crystal.js +0 -337
  107. package/dist/quicktype-core/language/Dart.d.ts +0 -66
  108. package/dist/quicktype-core/language/Dart.js +0 -576
  109. package/dist/quicktype-core/language/Elm.d.ts +0 -58
  110. package/dist/quicktype-core/language/Elm.js +0 -522
  111. package/dist/quicktype-core/language/Golang.d.ts +0 -51
  112. package/dist/quicktype-core/language/Golang.js +0 -460
  113. package/dist/quicktype-core/language/Haskell.d.ts +0 -56
  114. package/dist/quicktype-core/language/Haskell.js +0 -411
  115. package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
  116. package/dist/quicktype-core/language/JSONSchema.js +0 -169
  117. package/dist/quicktype-core/language/Java.d.ts +0 -125
  118. package/dist/quicktype-core/language/Java.js +0 -1081
  119. package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
  120. package/dist/quicktype-core/language/JavaScript.js +0 -435
  121. package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
  122. package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
  123. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
  124. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
  125. package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
  126. package/dist/quicktype-core/language/Kotlin.js +0 -832
  127. package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
  128. package/dist/quicktype-core/language/Objective-C.js +0 -777
  129. package/dist/quicktype-core/language/Php.d.ts +0 -80
  130. package/dist/quicktype-core/language/Php.js +0 -702
  131. package/dist/quicktype-core/language/Pike.d.ts +0 -37
  132. package/dist/quicktype-core/language/Pike.js +0 -276
  133. package/dist/quicktype-core/language/Python.d.ts +0 -107
  134. package/dist/quicktype-core/language/Python.js +0 -969
  135. package/dist/quicktype-core/language/Rust.d.ts +0 -56
  136. package/dist/quicktype-core/language/Rust.js +0 -309
  137. package/dist/quicktype-core/language/Swift.d.ts +0 -96
  138. package/dist/quicktype-core/language/Swift.js +0 -1211
  139. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
  140. package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
  141. package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
  142. package/dist/quicktype-core/language/ruby/index.js +0 -557
  143. package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
  144. package/dist/quicktype-core/language/ruby/keywords.js +0 -358
  145. package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
  146. package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
  147. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
  148. package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
  149. package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
  150. package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
  151. package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
  152. package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
  153. package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
  154. package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
  155. package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
  156. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
  157. package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
  158. package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
  159. package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
  160. package/dist/quicktype-core/support/Acronyms.js +0 -1128
  161. package/dist/quicktype-core/support/Chance.d.ts +0 -38
  162. package/dist/quicktype-core/support/Chance.js +0 -2146
  163. package/dist/quicktype-core/support/Converters.d.ts +0 -6
  164. package/dist/quicktype-core/support/Converters.js +0 -16
  165. package/dist/quicktype-core/support/Strings.d.ts +0 -44
  166. package/dist/quicktype-core/support/Strings.js +0 -525
  167. package/dist/quicktype-core/support/Support.d.ts +0 -29
  168. package/dist/quicktype-core/support/Support.js +0 -162
  169. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
  170. package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
  171. package/dist/quicktype-graphql-input/index.d.ts +0 -17
  172. package/dist/quicktype-graphql-input/index.js +0 -407
  173. package/dist/quicktype-typescript-input/index.d.ts +0 -2
  174. package/dist/quicktype-typescript-input/index.js +0 -98
@@ -1,716 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnionType = exports.IntersectionType = exports.SetOperationType = exports.intersectionTypeIdentity = exports.unionTypeIdentity = exports.setOperationTypeIdentity = exports.setOperationCasesEqual = exports.EnumType = exports.enumTypeIdentity = exports.MapType = exports.ClassType = exports.ObjectType = exports.mapTypeIdentify = exports.classTypeIdentity = exports.ClassProperty = exports.GenericClassProperty = exports.ArrayType = exports.arrayTypeIdentity = exports.PrimitiveType = exports.primitiveTypeIdentity = exports.Type = exports.TypeIdentity = exports.isPrimitiveTypeKind = exports.isNumberTypeKind = exports.targetTypeKindForTransformedStringTypeKind = exports.isPrimitiveStringTypeKind = exports.transformedStringTypeKinds = exports.transformedStringTypeTargetTypeKindsMap = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const Support_1 = require("./support/Support");
6
- const TypeNames_1 = require("./attributes/TypeNames");
7
- const Messages_1 = require("./Messages");
8
- const TypeGraph_1 = require("./TypeGraph");
9
- const URIAttributes_1 = require("./attributes/URIAttributes");
10
- /**
11
- * All the transformed string type kinds and the JSON Schema formats and
12
- * primitive type kinds they map to. Not all transformed string types map to
13
- * primitive types. Date-time types, for example, stand on their own, but
14
- * stringified integers map to integers.
15
- */
16
- const transformedStringTypeTargetTypeKinds = {
17
- date: { jsonSchema: "date", primitive: undefined },
18
- time: { jsonSchema: "time", primitive: undefined },
19
- "date-time": { jsonSchema: "date-time", primitive: undefined },
20
- uuid: { jsonSchema: "uuid", primitive: undefined },
21
- uri: { jsonSchema: "uri", primitive: undefined, attributesProducer: URIAttributes_1.uriInferenceAttributesProducer },
22
- "integer-string": { jsonSchema: "integer", primitive: "integer" },
23
- "bool-string": { jsonSchema: "boolean", primitive: "bool" }
24
- };
25
- exports.transformedStringTypeTargetTypeKindsMap = (0, collection_utils_1.mapFromObject)(transformedStringTypeTargetTypeKinds);
26
- exports.transformedStringTypeKinds = new Set(Object.getOwnPropertyNames(transformedStringTypeTargetTypeKinds));
27
- function isPrimitiveStringTypeKind(kind) {
28
- return kind === "string" || (0, collection_utils_1.hasOwnProperty)(transformedStringTypeTargetTypeKinds, kind);
29
- }
30
- exports.isPrimitiveStringTypeKind = isPrimitiveStringTypeKind;
31
- function targetTypeKindForTransformedStringTypeKind(kind) {
32
- const target = exports.transformedStringTypeTargetTypeKindsMap.get(kind);
33
- if (target === undefined)
34
- return undefined;
35
- return target.primitive;
36
- }
37
- exports.targetTypeKindForTransformedStringTypeKind = targetTypeKindForTransformedStringTypeKind;
38
- function isNumberTypeKind(kind) {
39
- return kind === "integer" || kind === "double";
40
- }
41
- exports.isNumberTypeKind = isNumberTypeKind;
42
- function isPrimitiveTypeKind(kind) {
43
- if (isPrimitiveStringTypeKind(kind))
44
- return true;
45
- if (isNumberTypeKind(kind))
46
- return true;
47
- return kind === "none" || kind === "any" || kind === "null" || kind === "bool";
48
- }
49
- exports.isPrimitiveTypeKind = isPrimitiveTypeKind;
50
- function triviallyStructurallyCompatible(x, y) {
51
- if (x.index === y.index)
52
- return true;
53
- if (x.kind === "none" || y.kind === "none")
54
- return true;
55
- return false;
56
- }
57
- class TypeIdentity {
58
- _kind;
59
- _components;
60
- _hashCode;
61
- constructor(_kind, _components) {
62
- this._kind = _kind;
63
- this._components = _components;
64
- let h = collection_utils_1.hashCodeInit;
65
- h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this._kind));
66
- for (const c of _components) {
67
- h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(c));
68
- }
69
- this._hashCode = h;
70
- }
71
- equals(other) {
72
- if (!(other instanceof TypeIdentity))
73
- return false;
74
- if (this._kind !== other._kind)
75
- return false;
76
- const n = this._components.length;
77
- (0, Support_1.assert)(n === other._components.length, "Components of a type kind's identity must have the same length");
78
- for (let i = 0; i < n; i++) {
79
- if (!(0, collection_utils_1.areEqual)(this._components[i], other._components[i]))
80
- return false;
81
- }
82
- return true;
83
- }
84
- hashCode() {
85
- return this._hashCode;
86
- }
87
- }
88
- exports.TypeIdentity = TypeIdentity;
89
- class Type {
90
- typeRef;
91
- graph;
92
- constructor(typeRef, graph) {
93
- this.typeRef = typeRef;
94
- this.graph = graph;
95
- }
96
- get index() {
97
- return (0, TypeGraph_1.typeRefIndex)(this.typeRef);
98
- }
99
- getChildren() {
100
- let result = this.getNonAttributeChildren();
101
- for (const [k, v] of this.getAttributes()) {
102
- if (k.children === undefined)
103
- continue;
104
- (0, collection_utils_1.setUnionInto)(result, k.children(v));
105
- }
106
- return result;
107
- }
108
- getAttributes() {
109
- return (0, TypeGraph_1.attributesForTypeRef)(this.typeRef, this.graph);
110
- }
111
- get hasNames() {
112
- return TypeNames_1.namesTypeAttributeKind.tryGetInAttributes(this.getAttributes()) !== undefined;
113
- }
114
- getNames() {
115
- return (0, Support_1.defined)(TypeNames_1.namesTypeAttributeKind.tryGetInAttributes(this.getAttributes()));
116
- }
117
- getCombinedName() {
118
- return this.getNames().combinedName;
119
- }
120
- get debugPrintKind() {
121
- return this.kind;
122
- }
123
- equals(other) {
124
- if (!(other instanceof Type))
125
- return false;
126
- return this.typeRef === other.typeRef;
127
- }
128
- hashCode() {
129
- return (0, collection_utils_1.hashCodeOf)(this.typeRef);
130
- }
131
- structurallyCompatible(other, conflateNumbers = false) {
132
- function kindsCompatible(kind1, kind2) {
133
- if (kind1 === kind2)
134
- return true;
135
- if (!conflateNumbers)
136
- return false;
137
- if (kind1 === "integer")
138
- return kind2 === "double";
139
- if (kind1 === "double")
140
- return kind2 === "integer";
141
- return false;
142
- }
143
- if (triviallyStructurallyCompatible(this, other))
144
- return true;
145
- if (!kindsCompatible(this.kind, other.kind))
146
- return false;
147
- const workList = [[this, other]];
148
- // This contains a set of pairs which are the type pairs
149
- // we have already determined to be equal. We can't just
150
- // do comparison recursively because types can have cycles.
151
- const done = [];
152
- let failed;
153
- const queue = (x, y) => {
154
- if (triviallyStructurallyCompatible(x, y))
155
- return true;
156
- if (!kindsCompatible(x.kind, y.kind)) {
157
- failed = true;
158
- return false;
159
- }
160
- workList.push([x, y]);
161
- return true;
162
- };
163
- while (workList.length > 0) {
164
- let [a, b] = (0, Support_1.defined)(workList.pop());
165
- if (a.index > b.index) {
166
- [a, b] = [b, a];
167
- }
168
- if (!a.isPrimitive()) {
169
- let ai = a.index;
170
- let bi = b.index;
171
- let found = false;
172
- for (const [dai, dbi] of done) {
173
- if (dai === ai && dbi === bi) {
174
- found = true;
175
- break;
176
- }
177
- }
178
- if (found)
179
- continue;
180
- done.push([ai, bi]);
181
- }
182
- failed = false;
183
- if (!a.structuralEqualityStep(b, conflateNumbers, queue))
184
- return false;
185
- if (failed)
186
- return false;
187
- }
188
- return true;
189
- }
190
- getParentTypes() {
191
- return this.graph.getParentsOfType(this);
192
- }
193
- getAncestorsNotInSet(set) {
194
- const workList = [this];
195
- const processed = new Set();
196
- const ancestors = new Set();
197
- for (;;) {
198
- const t = workList.pop();
199
- if (t === undefined)
200
- break;
201
- const parents = t.getParentTypes();
202
- console.log(`${parents.size} parents`);
203
- for (const p of parents) {
204
- if (processed.has(p))
205
- continue;
206
- processed.add(p);
207
- if (set.has(p.typeRef)) {
208
- console.log(`adding ${p.kind}`);
209
- workList.push(p);
210
- }
211
- else {
212
- console.log(`found ${p.kind}`);
213
- ancestors.add(p);
214
- }
215
- }
216
- }
217
- return ancestors;
218
- }
219
- }
220
- exports.Type = Type;
221
- function hasUniqueIdentityAttributes(attributes) {
222
- return (0, collection_utils_1.mapSome)(attributes, (v, ta) => ta.requiresUniqueIdentity(v));
223
- }
224
- function identityAttributes(attributes) {
225
- return (0, collection_utils_1.mapFilter)(attributes, (_, kind) => kind.inIdentity);
226
- }
227
- function primitiveTypeIdentity(kind, attributes) {
228
- if (hasUniqueIdentityAttributes(attributes))
229
- return undefined;
230
- return new TypeIdentity(kind, [identityAttributes(attributes)]);
231
- }
232
- exports.primitiveTypeIdentity = primitiveTypeIdentity;
233
- class PrimitiveType extends Type {
234
- kind;
235
- constructor(typeRef, graph, kind) {
236
- super(typeRef, graph);
237
- this.kind = kind;
238
- }
239
- get isNullable() {
240
- return this.kind === "null" || this.kind === "any" || this.kind === "none";
241
- }
242
- isPrimitive() {
243
- return true;
244
- }
245
- getNonAttributeChildren() {
246
- return new Set();
247
- }
248
- get identity() {
249
- return primitiveTypeIdentity(this.kind, this.getAttributes());
250
- }
251
- reconstitute(builder) {
252
- builder.getPrimitiveType(this.kind);
253
- }
254
- structuralEqualityStep(_other, _conflateNumbers, _queue) {
255
- return true;
256
- }
257
- }
258
- exports.PrimitiveType = PrimitiveType;
259
- function arrayTypeIdentity(attributes, itemsRef) {
260
- if (hasUniqueIdentityAttributes(attributes))
261
- return undefined;
262
- return new TypeIdentity("array", [identityAttributes(attributes), itemsRef]);
263
- }
264
- exports.arrayTypeIdentity = arrayTypeIdentity;
265
- class ArrayType extends Type {
266
- _itemsRef;
267
- kind = "array";
268
- constructor(typeRef, graph, _itemsRef) {
269
- super(typeRef, graph);
270
- this._itemsRef = _itemsRef;
271
- }
272
- setItems(itemsRef) {
273
- if (this._itemsRef !== undefined) {
274
- return (0, Support_1.panic)("Can only set array items once");
275
- }
276
- this._itemsRef = itemsRef;
277
- }
278
- getItemsRef() {
279
- if (this._itemsRef === undefined) {
280
- return (0, Support_1.panic)("Array items accessed before they were set");
281
- }
282
- return this._itemsRef;
283
- }
284
- get items() {
285
- return (0, TypeGraph_1.derefTypeRef)(this.getItemsRef(), this.graph);
286
- }
287
- getNonAttributeChildren() {
288
- return new Set([this.items]);
289
- }
290
- get isNullable() {
291
- return false;
292
- }
293
- isPrimitive() {
294
- return false;
295
- }
296
- get identity() {
297
- return arrayTypeIdentity(this.getAttributes(), this.getItemsRef());
298
- }
299
- reconstitute(builder) {
300
- const itemsRef = this.getItemsRef();
301
- const maybeItems = builder.lookup(itemsRef);
302
- if (maybeItems === undefined) {
303
- builder.getUniqueArrayType();
304
- builder.setArrayItems(builder.reconstitute(this.getItemsRef()));
305
- }
306
- else {
307
- builder.getArrayType(maybeItems);
308
- }
309
- }
310
- structuralEqualityStep(other, _conflateNumbers, queue) {
311
- return queue(this.items, other.items);
312
- }
313
- }
314
- exports.ArrayType = ArrayType;
315
- class GenericClassProperty {
316
- typeData;
317
- isOptional;
318
- constructor(typeData, isOptional) {
319
- this.typeData = typeData;
320
- this.isOptional = isOptional;
321
- }
322
- equals(other) {
323
- if (!(other instanceof GenericClassProperty)) {
324
- return false;
325
- }
326
- return (0, collection_utils_1.areEqual)(this.typeData, other.typeData) && this.isOptional === other.isOptional;
327
- }
328
- hashCode() {
329
- return (0, collection_utils_1.hashCodeOf)(this.typeData) + (this.isOptional ? 17 : 23);
330
- }
331
- }
332
- exports.GenericClassProperty = GenericClassProperty;
333
- class ClassProperty extends GenericClassProperty {
334
- graph;
335
- constructor(typeRef, graph, isOptional) {
336
- super(typeRef, isOptional);
337
- this.graph = graph;
338
- }
339
- get typeRef() {
340
- return this.typeData;
341
- }
342
- get type() {
343
- return (0, TypeGraph_1.derefTypeRef)(this.typeRef, this.graph);
344
- }
345
- }
346
- exports.ClassProperty = ClassProperty;
347
- function objectTypeIdentify(kind, attributes, properties, additionalPropertiesRef) {
348
- if (hasUniqueIdentityAttributes(attributes))
349
- return undefined;
350
- return new TypeIdentity(kind, [identityAttributes(attributes), properties, additionalPropertiesRef]);
351
- }
352
- function classTypeIdentity(attributes, properties) {
353
- return objectTypeIdentify("class", attributes, properties, undefined);
354
- }
355
- exports.classTypeIdentity = classTypeIdentity;
356
- function mapTypeIdentify(attributes, additionalPropertiesRef) {
357
- return objectTypeIdentify("map", attributes, new Map(), additionalPropertiesRef);
358
- }
359
- exports.mapTypeIdentify = mapTypeIdentify;
360
- class ObjectType extends Type {
361
- kind;
362
- isFixed;
363
- _properties;
364
- _additionalPropertiesRef;
365
- constructor(typeRef, graph, kind, isFixed, _properties, _additionalPropertiesRef) {
366
- super(typeRef, graph);
367
- this.kind = kind;
368
- this.isFixed = isFixed;
369
- this._properties = _properties;
370
- this._additionalPropertiesRef = _additionalPropertiesRef;
371
- if (kind === "map") {
372
- if (_properties !== undefined) {
373
- (0, Support_1.assert)(_properties.size === 0);
374
- }
375
- (0, Support_1.assert)(!isFixed);
376
- }
377
- else if (kind === "class") {
378
- (0, Support_1.assert)(_additionalPropertiesRef === undefined);
379
- }
380
- else {
381
- (0, Support_1.assert)(isFixed);
382
- }
383
- }
384
- setProperties(properties, additionalPropertiesRef) {
385
- (0, Support_1.assert)(this._properties === undefined, "Tried to set object properties twice");
386
- if (this instanceof MapType) {
387
- (0, Support_1.assert)(properties.size === 0, "Cannot set properties on map type");
388
- }
389
- if (this instanceof ClassType) {
390
- (0, Support_1.assert)(additionalPropertiesRef === undefined, "Cannot set additional properties of class type");
391
- }
392
- this._properties = properties;
393
- this._additionalPropertiesRef = additionalPropertiesRef;
394
- }
395
- getProperties() {
396
- return (0, Support_1.defined)(this._properties);
397
- }
398
- getSortedProperties() {
399
- return (0, collection_utils_1.mapSortByKey)(this.getProperties());
400
- }
401
- getAdditionalPropertiesRef() {
402
- (0, Support_1.assert)(this._properties !== undefined, "Properties are not set yet");
403
- return this._additionalPropertiesRef;
404
- }
405
- getAdditionalProperties() {
406
- const tref = this.getAdditionalPropertiesRef();
407
- if (tref === undefined)
408
- return undefined;
409
- return (0, TypeGraph_1.derefTypeRef)(tref, this.graph);
410
- }
411
- getNonAttributeChildren() {
412
- const types = (0, collection_utils_1.mapSortToArray)(this.getProperties(), (_, k) => k).map(([_, p]) => p.type);
413
- const additionalProperties = this.getAdditionalProperties();
414
- if (additionalProperties !== undefined) {
415
- types.push(additionalProperties);
416
- }
417
- return new Set(types);
418
- }
419
- get isNullable() {
420
- return false;
421
- }
422
- isPrimitive() {
423
- return false;
424
- }
425
- get identity() {
426
- if (this.isFixed)
427
- return undefined;
428
- return objectTypeIdentify(this.kind, this.getAttributes(), this.getProperties(), this.getAdditionalPropertiesRef());
429
- }
430
- reconstitute(builder, canonicalOrder) {
431
- const sortedProperties = this.getSortedProperties();
432
- const propertiesInNewOrder = canonicalOrder ? sortedProperties : this.getProperties();
433
- const maybePropertyTypes = builder.lookupMap((0, collection_utils_1.mapMap)(sortedProperties, cp => cp.typeRef));
434
- const maybeAdditionalProperties = (0, collection_utils_1.definedMap)(this._additionalPropertiesRef, r => builder.lookup(r));
435
- if (maybePropertyTypes !== undefined &&
436
- (maybeAdditionalProperties !== undefined || this._additionalPropertiesRef === undefined)) {
437
- const properties = (0, collection_utils_1.mapMap)(propertiesInNewOrder, (cp, n) => builder.makeClassProperty((0, Support_1.defined)(maybePropertyTypes.get(n)), cp.isOptional));
438
- switch (this.kind) {
439
- case "object":
440
- (0, Support_1.assert)(this.isFixed);
441
- builder.getObjectType(properties, maybeAdditionalProperties);
442
- break;
443
- case "map":
444
- builder.getMapType((0, Support_1.defined)(maybeAdditionalProperties));
445
- break;
446
- case "class":
447
- if (this.isFixed) {
448
- builder.getUniqueClassType(true, properties);
449
- }
450
- else {
451
- builder.getClassType(properties);
452
- }
453
- break;
454
- default:
455
- return (0, Support_1.panic)(`Invalid object type kind ${this.kind}`);
456
- }
457
- }
458
- else {
459
- switch (this.kind) {
460
- case "object":
461
- (0, Support_1.assert)(this.isFixed);
462
- builder.getUniqueObjectType(undefined, undefined);
463
- break;
464
- case "map":
465
- builder.getUniqueMapType();
466
- break;
467
- case "class":
468
- builder.getUniqueClassType(this.isFixed, undefined);
469
- break;
470
- default:
471
- return (0, Support_1.panic)(`Invalid object type kind ${this.kind}`);
472
- }
473
- const reconstitutedTypes = (0, collection_utils_1.mapMap)(sortedProperties, cp => builder.reconstitute(cp.typeRef));
474
- const properties = (0, collection_utils_1.mapMap)(propertiesInNewOrder, (cp, n) => builder.makeClassProperty((0, Support_1.defined)(reconstitutedTypes.get(n)), cp.isOptional));
475
- const additionalProperties = (0, collection_utils_1.definedMap)(this._additionalPropertiesRef, r => builder.reconstitute(r));
476
- builder.setObjectProperties(properties, additionalProperties);
477
- }
478
- }
479
- structuralEqualityStep(other, _conflateNumbers, queue) {
480
- const pa = this.getProperties();
481
- const pb = other.getProperties();
482
- if (pa.size !== pb.size)
483
- return false;
484
- let failed = false;
485
- for (const [name, cpa] of pa) {
486
- const cpb = pb.get(name);
487
- if (cpb === undefined || cpa.isOptional !== cpb.isOptional || !queue(cpa.type, cpb.type)) {
488
- failed = true;
489
- return false;
490
- }
491
- }
492
- if (failed)
493
- return false;
494
- const thisAdditionalProperties = this.getAdditionalProperties();
495
- const otherAdditionalProperties = other.getAdditionalProperties();
496
- if ((thisAdditionalProperties === undefined) !== (otherAdditionalProperties === undefined))
497
- return false;
498
- if (thisAdditionalProperties === undefined || otherAdditionalProperties === undefined)
499
- return true;
500
- return queue(thisAdditionalProperties, otherAdditionalProperties);
501
- }
502
- }
503
- exports.ObjectType = ObjectType;
504
- class ClassType extends ObjectType {
505
- constructor(typeRef, graph, isFixed, properties) {
506
- super(typeRef, graph, "class", isFixed, properties, undefined);
507
- }
508
- }
509
- exports.ClassType = ClassType;
510
- class MapType extends ObjectType {
511
- constructor(typeRef, graph, valuesRef) {
512
- super(typeRef, graph, "map", false, (0, collection_utils_1.definedMap)(valuesRef, () => new Map()), valuesRef);
513
- }
514
- // FIXME: Remove and use `getAdditionalProperties()` instead.
515
- get values() {
516
- return (0, Support_1.defined)(this.getAdditionalProperties());
517
- }
518
- }
519
- exports.MapType = MapType;
520
- function enumTypeIdentity(attributes, cases) {
521
- if (hasUniqueIdentityAttributes(attributes))
522
- return undefined;
523
- return new TypeIdentity("enum", [identityAttributes(attributes), cases]);
524
- }
525
- exports.enumTypeIdentity = enumTypeIdentity;
526
- class EnumType extends Type {
527
- cases;
528
- kind = "enum";
529
- constructor(typeRef, graph, cases) {
530
- super(typeRef, graph);
531
- this.cases = cases;
532
- }
533
- get isNullable() {
534
- return false;
535
- }
536
- isPrimitive() {
537
- return false;
538
- }
539
- get identity() {
540
- return enumTypeIdentity(this.getAttributes(), this.cases);
541
- }
542
- getNonAttributeChildren() {
543
- return new Set();
544
- }
545
- reconstitute(builder) {
546
- builder.getEnumType(this.cases);
547
- }
548
- structuralEqualityStep(other, _conflateNumbers, _queue) {
549
- return (0, collection_utils_1.areEqual)(this.cases, other.cases);
550
- }
551
- }
552
- exports.EnumType = EnumType;
553
- function setOperationCasesEqual(typesA, typesB, conflateNumbers, membersEqual) {
554
- const ma = (0, collection_utils_1.toReadonlySet)(typesA);
555
- const mb = (0, collection_utils_1.toReadonlySet)(typesB);
556
- if (ma.size !== mb.size)
557
- return false;
558
- return (0, collection_utils_1.iterableEvery)(ma, ta => {
559
- const tb = (0, collection_utils_1.iterableFind)(mb, t => t.kind === ta.kind);
560
- if (tb !== undefined) {
561
- if (membersEqual(ta, tb))
562
- return true;
563
- }
564
- if (conflateNumbers) {
565
- if (ta.kind === "integer" && (0, collection_utils_1.iterableSome)(mb, t => t.kind === "double"))
566
- return true;
567
- if (ta.kind === "double" && (0, collection_utils_1.iterableSome)(mb, t => t.kind === "integer"))
568
- return true;
569
- }
570
- return false;
571
- });
572
- }
573
- exports.setOperationCasesEqual = setOperationCasesEqual;
574
- function setOperationTypeIdentity(kind, attributes, memberRefs) {
575
- if (hasUniqueIdentityAttributes(attributes))
576
- return undefined;
577
- return new TypeIdentity(kind, [identityAttributes(attributes), memberRefs]);
578
- }
579
- exports.setOperationTypeIdentity = setOperationTypeIdentity;
580
- function unionTypeIdentity(attributes, memberRefs) {
581
- return setOperationTypeIdentity("union", attributes, memberRefs);
582
- }
583
- exports.unionTypeIdentity = unionTypeIdentity;
584
- function intersectionTypeIdentity(attributes, memberRefs) {
585
- return setOperationTypeIdentity("intersection", attributes, memberRefs);
586
- }
587
- exports.intersectionTypeIdentity = intersectionTypeIdentity;
588
- class SetOperationType extends Type {
589
- kind;
590
- _memberRefs;
591
- constructor(typeRef, graph, kind, _memberRefs) {
592
- super(typeRef, graph);
593
- this.kind = kind;
594
- this._memberRefs = _memberRefs;
595
- }
596
- setMembers(memberRefs) {
597
- if (this._memberRefs !== undefined) {
598
- return (0, Support_1.panic)("Can only set map members once");
599
- }
600
- this._memberRefs = memberRefs;
601
- }
602
- getMemberRefs() {
603
- if (this._memberRefs === undefined) {
604
- return (0, Support_1.panic)("Map members accessed before they were set");
605
- }
606
- return this._memberRefs;
607
- }
608
- get members() {
609
- return (0, collection_utils_1.setMap)(this.getMemberRefs(), tref => (0, TypeGraph_1.derefTypeRef)(tref, this.graph));
610
- }
611
- get sortedMembers() {
612
- return this.getNonAttributeChildren();
613
- }
614
- getNonAttributeChildren() {
615
- // FIXME: We're assuming no two members of the same kind.
616
- return (0, collection_utils_1.setSortBy)(this.members, t => t.kind);
617
- }
618
- isPrimitive() {
619
- return false;
620
- }
621
- get identity() {
622
- return setOperationTypeIdentity(this.kind, this.getAttributes(), this.getMemberRefs());
623
- }
624
- reconstituteSetOperation(builder, canonicalOrder, getType) {
625
- const sortedMemberRefs = (0, collection_utils_1.mapMap)(this.sortedMembers.entries(), t => t.typeRef);
626
- const membersInOrder = canonicalOrder ? this.sortedMembers : this.members;
627
- const maybeMembers = builder.lookupMap(sortedMemberRefs);
628
- if (maybeMembers === undefined) {
629
- getType(undefined);
630
- const reconstituted = builder.reconstituteMap(sortedMemberRefs);
631
- builder.setSetOperationMembers((0, collection_utils_1.setMap)(membersInOrder, t => (0, Support_1.defined)(reconstituted.get(t))));
632
- }
633
- else {
634
- getType((0, collection_utils_1.setMap)(membersInOrder, t => (0, Support_1.defined)(maybeMembers.get(t))));
635
- }
636
- }
637
- structuralEqualityStep(other, conflateNumbers, queue) {
638
- return setOperationCasesEqual(this.members, other.members, conflateNumbers, queue);
639
- }
640
- }
641
- exports.SetOperationType = SetOperationType;
642
- class IntersectionType extends SetOperationType {
643
- constructor(typeRef, graph, memberRefs) {
644
- super(typeRef, graph, "intersection", memberRefs);
645
- }
646
- get isNullable() {
647
- return (0, Support_1.panic)("isNullable not implemented for IntersectionType");
648
- }
649
- reconstitute(builder, canonicalOrder) {
650
- this.reconstituteSetOperation(builder, canonicalOrder, members => {
651
- if (members === undefined) {
652
- builder.getUniqueIntersectionType();
653
- }
654
- else {
655
- builder.getIntersectionType(members);
656
- }
657
- });
658
- }
659
- }
660
- exports.IntersectionType = IntersectionType;
661
- class UnionType extends SetOperationType {
662
- constructor(typeRef, graph, memberRefs) {
663
- super(typeRef, graph, "union", memberRefs);
664
- if (memberRefs !== undefined) {
665
- (0, Messages_1.messageAssert)(memberRefs.size > 0, "IRNoEmptyUnions", {});
666
- }
667
- }
668
- setMembers(memberRefs) {
669
- (0, Messages_1.messageAssert)(memberRefs.size > 0, "IRNoEmptyUnions", {});
670
- super.setMembers(memberRefs);
671
- }
672
- get stringTypeMembers() {
673
- return (0, collection_utils_1.setFilter)(this.members, t => isPrimitiveStringTypeKind(t.kind) || t.kind === "enum");
674
- }
675
- findMember(kind) {
676
- return (0, collection_utils_1.iterableFind)(this.members, t => t.kind === kind);
677
- }
678
- get isNullable() {
679
- return this.findMember("null") !== undefined;
680
- }
681
- get isCanonical() {
682
- const members = this.members;
683
- if (members.size <= 1)
684
- return false;
685
- const kinds = (0, collection_utils_1.setMap)(members, t => t.kind);
686
- if (kinds.size < members.size)
687
- return false;
688
- if (kinds.has("union") || kinds.has("intersection"))
689
- return false;
690
- if (kinds.has("none") || kinds.has("any"))
691
- return false;
692
- if (kinds.has("string") && kinds.has("enum"))
693
- return false;
694
- let numObjectTypes = 0;
695
- if (kinds.has("class"))
696
- numObjectTypes += 1;
697
- if (kinds.has("map"))
698
- numObjectTypes += 1;
699
- if (kinds.has("object"))
700
- numObjectTypes += 1;
701
- if (numObjectTypes > 1)
702
- return false;
703
- return true;
704
- }
705
- reconstitute(builder, canonicalOrder) {
706
- this.reconstituteSetOperation(builder, canonicalOrder, members => {
707
- if (members === undefined) {
708
- builder.getUniqueUnionType();
709
- }
710
- else {
711
- builder.getUnionType(members);
712
- }
713
- });
714
- }
715
- }
716
- exports.UnionType = UnionType;