quicktype 17.0.0 → 17.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.
- package/dist/cli/CompressedJSONFromStream.js +38 -26
- package/dist/cli/GraphQLIntrospection.js +41 -33
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +3 -4
- package/dist/cli/index.js +364 -363
- package/dist/quicktype-core/Annotation.js +0 -2
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +81 -104
- package/dist/quicktype-core/DateTime.js +0 -1
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +10 -13
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -1
- package/dist/quicktype-core/GatherNames.js +25 -47
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +19 -23
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +54 -65
- package/dist/quicktype-core/MakeTransformations.js +22 -23
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +8 -9
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +3 -8
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +61 -76
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +17 -34
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +3 -6
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +67 -72
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +18 -19
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +2 -6
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +66 -94
- package/dist/quicktype-core/Type.d.ts +43 -41
- package/dist/quicktype-core/Type.js +71 -96
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +47 -53
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +40 -49
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +22 -23
- package/dist/quicktype-core/UnifyClasses.js +12 -16
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +30 -33
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +17 -18
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +4 -8
- package/dist/quicktype-core/attributes/Description.js +5 -6
- package/dist/quicktype-core/attributes/EnumValues.js +3 -4
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +21 -24
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +10 -12
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +21 -49
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +6 -10
- package/dist/quicktype-core/index.js +125 -128
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +54 -49
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +13 -5
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +17 -25
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +54 -38
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +523 -503
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +35 -24
- package/dist/quicktype-core/input/PostmanCollection.js +1 -2
- package/dist/quicktype-core/input/io/NodeIO.js +44 -55
- package/dist/quicktype-core/input/io/get-stream/index.js +2 -6
- package/dist/quicktype-core/language/All.js +2 -3
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +151 -185
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +72 -82
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +17 -18
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +34 -36
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +45 -47
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +20 -23
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +23 -25
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +16 -17
- package/dist/quicktype-core/language/Java.d.ts +2 -2
- package/dist/quicktype-core/language/Java.js +97 -97
- package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
- package/dist/quicktype-core/language/JavaScript.js +17 -19
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +13 -15
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +11 -12
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +37 -39
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +41 -45
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +41 -66
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +17 -18
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +64 -63
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +19 -21
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +804 -807
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +26 -28
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +24 -49
- package/dist/quicktype-core/language/ruby/keywords.js +0 -1
- package/dist/quicktype-core/rewrites/CombineClasses.js +8 -9
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +17 -18
- package/dist/quicktype-core/rewrites/FlattenStrings.js +6 -7
- package/dist/quicktype-core/rewrites/FlattenUnions.js +8 -9
- package/dist/quicktype-core/rewrites/InferMaps.js +10 -11
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +7 -8
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +67 -68
- package/dist/quicktype-core/support/Acronyms.js +1 -3
- package/dist/quicktype-core/support/Chance.js +0 -10
- package/dist/quicktype-core/support/Converters.js +0 -1
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +16 -17
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +6 -30
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -1
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +212 -229
- package/dist/quicktype-typescript-input/index.js +4 -28
- package/package.json +19 -25
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.followTargetType = exports.transformationForType = exports.transformationTypeAttributeKind = exports.Transformation = exports.MinMaxValueTransformer = exports.MinMaxLengthCheckTransformer = exports.StringifyTransformer = exports.ParseStringTransformer = exports.StringProducerTransformer = exports.UnionInstantiationTransformer = exports.StringMatchTransformer = exports.UnionMemberMatchTransformer = exports.DecodingChoiceTransformer = exports.ChoiceTransformer = exports.ArrayEncodingTransformer = exports.ArrayDecodingTransformer = exports.EncodingTransformer = exports.DecodingTransformer = exports.MatchTransformer = exports.ProducerTransformer = exports.Transformer = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const Type_1 = require("./Type");
|
|
6
5
|
const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
@@ -14,19 +13,16 @@ function debugStringForType(t) {
|
|
|
14
13
|
return `${t.kind} (${target.kind})`;
|
|
15
14
|
}
|
|
16
15
|
function getNumberOfNodes(xfer) {
|
|
17
|
-
return
|
|
16
|
+
return collection_utils_1.definedMapWithDefault(xfer, 0, x => x.getNumberOfNodes());
|
|
18
17
|
}
|
|
19
18
|
class Transformer {
|
|
20
|
-
kind;
|
|
21
|
-
graph;
|
|
22
|
-
sourceTypeRef;
|
|
23
19
|
constructor(kind, graph, sourceTypeRef) {
|
|
24
20
|
this.kind = kind;
|
|
25
21
|
this.graph = graph;
|
|
26
22
|
this.sourceTypeRef = sourceTypeRef;
|
|
27
23
|
}
|
|
28
24
|
get sourceType() {
|
|
29
|
-
return
|
|
25
|
+
return TypeGraph_1.derefTypeRef(this.sourceTypeRef, this.graph);
|
|
30
26
|
}
|
|
31
27
|
/** This must return a newly constructed set. */
|
|
32
28
|
getChildren() {
|
|
@@ -41,7 +37,7 @@ class Transformer {
|
|
|
41
37
|
return this.sourceTypeRef === other.sourceTypeRef;
|
|
42
38
|
}
|
|
43
39
|
hashCode() {
|
|
44
|
-
return
|
|
40
|
+
return collection_utils_1.hashCodeOf(this.sourceTypeRef);
|
|
45
41
|
}
|
|
46
42
|
debugDescription() {
|
|
47
43
|
return `${debugStringForType(this.sourceType)} -> ${this.kind}`;
|
|
@@ -50,13 +46,12 @@ class Transformer {
|
|
|
50
46
|
return;
|
|
51
47
|
}
|
|
52
48
|
debugPrint(indent) {
|
|
53
|
-
console.log(
|
|
49
|
+
console.log(Support_1.indentationString(indent) + this.debugDescription());
|
|
54
50
|
this.debugPrintContinuations(indent + 1);
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
exports.Transformer = Transformer;
|
|
58
54
|
class ProducerTransformer extends Transformer {
|
|
59
|
-
consumer;
|
|
60
55
|
constructor(kind, graph, sourceTypeRef, consumer) {
|
|
61
56
|
super(kind, graph, sourceTypeRef);
|
|
62
57
|
this.consumer = consumer;
|
|
@@ -65,7 +60,7 @@ class ProducerTransformer extends Transformer {
|
|
|
65
60
|
const children = super.getChildren();
|
|
66
61
|
if (this.consumer === undefined)
|
|
67
62
|
return children;
|
|
68
|
-
return
|
|
63
|
+
return collection_utils_1.setUnionInto(children, this.consumer.getChildren());
|
|
69
64
|
}
|
|
70
65
|
getNumberOfNodes() {
|
|
71
66
|
return super.getNumberOfNodes() + getNumberOfNodes(this.consumer);
|
|
@@ -75,11 +70,11 @@ class ProducerTransformer extends Transformer {
|
|
|
75
70
|
return false;
|
|
76
71
|
if (!(other instanceof ProducerTransformer))
|
|
77
72
|
return false;
|
|
78
|
-
return
|
|
73
|
+
return collection_utils_1.areEqual(this.consumer, other.consumer);
|
|
79
74
|
}
|
|
80
75
|
hashCode() {
|
|
81
76
|
const h = super.hashCode();
|
|
82
|
-
return
|
|
77
|
+
return collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.consumer));
|
|
83
78
|
}
|
|
84
79
|
debugPrintContinuations(indent) {
|
|
85
80
|
if (this.consumer === undefined)
|
|
@@ -89,13 +84,12 @@ class ProducerTransformer extends Transformer {
|
|
|
89
84
|
}
|
|
90
85
|
exports.ProducerTransformer = ProducerTransformer;
|
|
91
86
|
class MatchTransformer extends Transformer {
|
|
92
|
-
transformer;
|
|
93
87
|
constructor(kind, graph, sourceTypeRef, transformer) {
|
|
94
88
|
super(kind, graph, sourceTypeRef);
|
|
95
89
|
this.transformer = transformer;
|
|
96
90
|
}
|
|
97
91
|
getChildren() {
|
|
98
|
-
return
|
|
92
|
+
return collection_utils_1.setUnionInto(super.getChildren(), this.transformer.getChildren());
|
|
99
93
|
}
|
|
100
94
|
getNumberOfNodes() {
|
|
101
95
|
return super.getNumberOfNodes() + this.transformer.getNumberOfNodes();
|
|
@@ -109,7 +103,7 @@ class MatchTransformer extends Transformer {
|
|
|
109
103
|
}
|
|
110
104
|
hashCode() {
|
|
111
105
|
const h = super.hashCode();
|
|
112
|
-
return
|
|
106
|
+
return collection_utils_1.addHashCode(h, this.transformer.hashCode());
|
|
113
107
|
}
|
|
114
108
|
debugPrintContinuations(indent) {
|
|
115
109
|
this.transformer.debugPrint(indent);
|
|
@@ -125,7 +119,7 @@ class DecodingTransformer extends ProducerTransformer {
|
|
|
125
119
|
}
|
|
126
120
|
reverse(targetTypeRef, continuationTransformer) {
|
|
127
121
|
if (continuationTransformer !== undefined) {
|
|
128
|
-
return
|
|
122
|
+
return Support_1.panic("Reversing a decoding transformer cannot have a continuation");
|
|
129
123
|
}
|
|
130
124
|
if (this.consumer === undefined) {
|
|
131
125
|
return new EncodingTransformer(this.graph, targetTypeRef);
|
|
@@ -135,7 +129,7 @@ class DecodingTransformer extends ProducerTransformer {
|
|
|
135
129
|
}
|
|
136
130
|
}
|
|
137
131
|
reconstitute(builder) {
|
|
138
|
-
return new DecodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef),
|
|
132
|
+
return new DecodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), collection_utils_1.definedMap(this.consumer, xfer => xfer.reconstitute(builder)));
|
|
139
133
|
}
|
|
140
134
|
equals(other) {
|
|
141
135
|
if (!super.equals(other))
|
|
@@ -152,7 +146,7 @@ class EncodingTransformer extends Transformer {
|
|
|
152
146
|
return false;
|
|
153
147
|
}
|
|
154
148
|
reverse(_targetTypeRef, _continuationTransformer) {
|
|
155
|
-
return
|
|
149
|
+
return Support_1.panic("Can't reverse encoding transformer");
|
|
156
150
|
}
|
|
157
151
|
reconstitute(builder) {
|
|
158
152
|
return new EncodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef));
|
|
@@ -167,8 +161,6 @@ class EncodingTransformer extends Transformer {
|
|
|
167
161
|
}
|
|
168
162
|
exports.EncodingTransformer = EncodingTransformer;
|
|
169
163
|
class ArrayDecodingTransformer extends ProducerTransformer {
|
|
170
|
-
_itemTargetTypeRef;
|
|
171
|
-
itemTransformer;
|
|
172
164
|
constructor(graph, sourceTypeRef, consumer, _itemTargetTypeRef, itemTransformer) {
|
|
173
165
|
super("decode-array", graph, sourceTypeRef, consumer);
|
|
174
166
|
this._itemTargetTypeRef = _itemTargetTypeRef;
|
|
@@ -177,7 +169,7 @@ class ArrayDecodingTransformer extends ProducerTransformer {
|
|
|
177
169
|
getChildren() {
|
|
178
170
|
const children = super.getChildren();
|
|
179
171
|
children.add(this.itemTargetType);
|
|
180
|
-
return
|
|
172
|
+
return collection_utils_1.setUnionInto(children, this.itemTransformer.getChildren());
|
|
181
173
|
}
|
|
182
174
|
getNumberOfNodes() {
|
|
183
175
|
return super.getNumberOfNodes() + this.itemTransformer.getNumberOfNodes();
|
|
@@ -186,11 +178,11 @@ class ArrayDecodingTransformer extends ProducerTransformer {
|
|
|
186
178
|
return false;
|
|
187
179
|
}
|
|
188
180
|
get itemTargetType() {
|
|
189
|
-
return
|
|
181
|
+
return TypeGraph_1.derefTypeRef(this._itemTargetTypeRef, this.graph);
|
|
190
182
|
}
|
|
191
183
|
reverse(targetTypeRef, continuationTransformer) {
|
|
192
184
|
if (continuationTransformer !== undefined) {
|
|
193
|
-
return
|
|
185
|
+
return Support_1.panic("Reversing a decoding transformer cannot have a continuation");
|
|
194
186
|
}
|
|
195
187
|
const itemTransformer = this.itemTransformer.reverse(this._itemTargetTypeRef, undefined);
|
|
196
188
|
if (this.consumer === undefined) {
|
|
@@ -201,12 +193,12 @@ class ArrayDecodingTransformer extends ProducerTransformer {
|
|
|
201
193
|
}
|
|
202
194
|
}
|
|
203
195
|
reconstitute(builder) {
|
|
204
|
-
return new ArrayDecodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef),
|
|
196
|
+
return new ArrayDecodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), collection_utils_1.definedMap(this.consumer, xfer => xfer.reconstitute(builder)), builder.reconstituteTypeRef(this._itemTargetTypeRef), this.itemTransformer.reconstitute(builder));
|
|
205
197
|
}
|
|
206
198
|
hashCode() {
|
|
207
199
|
let h = super.hashCode();
|
|
208
|
-
h =
|
|
209
|
-
h =
|
|
200
|
+
h = collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this._itemTargetTypeRef));
|
|
201
|
+
h = collection_utils_1.addHashCode(h, this.itemTransformer.hashCode());
|
|
210
202
|
return h;
|
|
211
203
|
}
|
|
212
204
|
equals(other) {
|
|
@@ -214,7 +206,7 @@ class ArrayDecodingTransformer extends ProducerTransformer {
|
|
|
214
206
|
return false;
|
|
215
207
|
if (!(other instanceof ArrayDecodingTransformer))
|
|
216
208
|
return false;
|
|
217
|
-
if (!
|
|
209
|
+
if (!collection_utils_1.areEqual(this._itemTargetTypeRef, other._itemTargetTypeRef))
|
|
218
210
|
return false;
|
|
219
211
|
return this.itemTransformer.equals(other.itemTransformer);
|
|
220
212
|
}
|
|
@@ -225,8 +217,6 @@ class ArrayDecodingTransformer extends ProducerTransformer {
|
|
|
225
217
|
}
|
|
226
218
|
exports.ArrayDecodingTransformer = ArrayDecodingTransformer;
|
|
227
219
|
class ArrayEncodingTransformer extends Transformer {
|
|
228
|
-
_itemTargetTypeRef;
|
|
229
|
-
itemTransformer;
|
|
230
220
|
constructor(graph, sourceTypeRef, _itemTargetTypeRef, itemTransformer) {
|
|
231
221
|
super("encode-array", graph, sourceTypeRef);
|
|
232
222
|
this._itemTargetTypeRef = _itemTargetTypeRef;
|
|
@@ -235,7 +225,7 @@ class ArrayEncodingTransformer extends Transformer {
|
|
|
235
225
|
getChildren() {
|
|
236
226
|
const children = super.getChildren();
|
|
237
227
|
children.add(this.itemTargetType);
|
|
238
|
-
return
|
|
228
|
+
return collection_utils_1.setUnionInto(children, this.itemTransformer.getChildren());
|
|
239
229
|
}
|
|
240
230
|
getNumberOfNodes() {
|
|
241
231
|
return super.getNumberOfNodes() + this.itemTransformer.getNumberOfNodes();
|
|
@@ -244,25 +234,25 @@ class ArrayEncodingTransformer extends Transformer {
|
|
|
244
234
|
return false;
|
|
245
235
|
}
|
|
246
236
|
get itemTargetType() {
|
|
247
|
-
return
|
|
237
|
+
return TypeGraph_1.derefTypeRef(this._itemTargetTypeRef, this.graph);
|
|
248
238
|
}
|
|
249
239
|
reverse(_targetTypeRef, _continuationTransformer) {
|
|
250
|
-
return
|
|
240
|
+
return Support_1.panic("Can't reverse array encoding transformer");
|
|
251
241
|
}
|
|
252
242
|
reconstitute(builder) {
|
|
253
243
|
return new ArrayEncodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), builder.reconstituteTypeRef(this._itemTargetTypeRef), this.itemTransformer.reconstitute(builder));
|
|
254
244
|
}
|
|
255
245
|
hashCode() {
|
|
256
246
|
let h = super.hashCode();
|
|
257
|
-
h =
|
|
258
|
-
return
|
|
247
|
+
h = collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this._itemTargetTypeRef));
|
|
248
|
+
return collection_utils_1.addHashCode(h, this.itemTransformer.hashCode());
|
|
259
249
|
}
|
|
260
250
|
equals(other) {
|
|
261
251
|
if (!super.equals(other))
|
|
262
252
|
return false;
|
|
263
253
|
if (!(other instanceof ArrayEncodingTransformer))
|
|
264
254
|
return false;
|
|
265
|
-
if (!
|
|
255
|
+
if (!collection_utils_1.areEqual(this._itemTargetTypeRef, other._itemTargetTypeRef))
|
|
266
256
|
return false;
|
|
267
257
|
return this.itemTransformer.equals(other.itemTransformer);
|
|
268
258
|
}
|
|
@@ -273,16 +263,15 @@ class ArrayEncodingTransformer extends Transformer {
|
|
|
273
263
|
}
|
|
274
264
|
exports.ArrayEncodingTransformer = ArrayEncodingTransformer;
|
|
275
265
|
class ChoiceTransformer extends Transformer {
|
|
276
|
-
transformers;
|
|
277
266
|
constructor(graph, sourceTypeRef, transformers) {
|
|
278
267
|
super("choice", graph, sourceTypeRef);
|
|
279
268
|
this.transformers = transformers;
|
|
280
|
-
|
|
269
|
+
Support_1.assert(transformers.length > 0, "Choice must have at least one transformer");
|
|
281
270
|
}
|
|
282
271
|
getChildren() {
|
|
283
272
|
let children = super.getChildren();
|
|
284
273
|
for (const xfer of this.transformers) {
|
|
285
|
-
|
|
274
|
+
collection_utils_1.setUnionInto(children, xfer.getChildren());
|
|
286
275
|
}
|
|
287
276
|
return children;
|
|
288
277
|
}
|
|
@@ -316,11 +305,11 @@ class ChoiceTransformer extends Transformer {
|
|
|
316
305
|
return false;
|
|
317
306
|
if (!(other instanceof ChoiceTransformer))
|
|
318
307
|
return false;
|
|
319
|
-
return
|
|
308
|
+
return collection_utils_1.areEqual(this.transformers, other.transformers);
|
|
320
309
|
}
|
|
321
310
|
hashCode() {
|
|
322
311
|
const h = super.hashCode();
|
|
323
|
-
return
|
|
312
|
+
return collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.transformers));
|
|
324
313
|
}
|
|
325
314
|
debugPrintContinuations(indent) {
|
|
326
315
|
for (const xfer of this.transformers) {
|
|
@@ -330,13 +319,6 @@ class ChoiceTransformer extends Transformer {
|
|
|
330
319
|
}
|
|
331
320
|
exports.ChoiceTransformer = ChoiceTransformer;
|
|
332
321
|
class DecodingChoiceTransformer extends Transformer {
|
|
333
|
-
nullTransformer;
|
|
334
|
-
integerTransformer;
|
|
335
|
-
doubleTransformer;
|
|
336
|
-
boolTransformer;
|
|
337
|
-
stringTransformer;
|
|
338
|
-
arrayTransformer;
|
|
339
|
-
objectTransformer;
|
|
340
322
|
constructor(graph, sourceTypeRef, nullTransformer, integerTransformer, doubleTransformer, boolTransformer, stringTransformer, arrayTransformer, objectTransformer) {
|
|
341
323
|
super("decoding-choice", graph, sourceTypeRef);
|
|
342
324
|
this.nullTransformer = nullTransformer;
|
|
@@ -366,7 +348,7 @@ class DecodingChoiceTransformer extends Transformer {
|
|
|
366
348
|
getChildren() {
|
|
367
349
|
let children = super.getChildren();
|
|
368
350
|
for (const xfer of this.transformers) {
|
|
369
|
-
|
|
351
|
+
collection_utils_1.setUnionInto(children, xfer.getChildren());
|
|
370
352
|
}
|
|
371
353
|
return children;
|
|
372
354
|
}
|
|
@@ -381,7 +363,7 @@ class DecodingChoiceTransformer extends Transformer {
|
|
|
381
363
|
return false;
|
|
382
364
|
}
|
|
383
365
|
reverse(targetTypeRef, continuationTransformer) {
|
|
384
|
-
|
|
366
|
+
Support_1.assert(continuationTransformer === undefined, "Reversing a decoding transformer can't have a target transformer");
|
|
385
367
|
let transformers = new Map();
|
|
386
368
|
let memberMatchTransformers = new Map();
|
|
387
369
|
function addCase(reversed) {
|
|
@@ -425,7 +407,7 @@ class DecodingChoiceTransformer extends Transformer {
|
|
|
425
407
|
// just pick the "simplest" non-failing one, being the one with the least number
|
|
426
408
|
// of nodes.
|
|
427
409
|
function filter(xfers) {
|
|
428
|
-
|
|
410
|
+
Support_1.assert(xfers.length > 0, "Must have at least one transformer");
|
|
429
411
|
const nonfailing = xfers.filter(xfer => {
|
|
430
412
|
// For member match transformers we're deciding between
|
|
431
413
|
// multiple that match against the same member, so the fact
|
|
@@ -441,7 +423,7 @@ class DecodingChoiceTransformer extends Transformer {
|
|
|
441
423
|
});
|
|
442
424
|
if (nonfailing.length === 0)
|
|
443
425
|
return xfers;
|
|
444
|
-
const smallest =
|
|
426
|
+
const smallest = collection_utils_1.arraySortByInto(nonfailing.map(x => [x.getNumberOfNodes(), x]), ([c, _]) => c)[0][1];
|
|
445
427
|
return [smallest];
|
|
446
428
|
}
|
|
447
429
|
this.transformers.forEach(reverseAndAdd);
|
|
@@ -466,31 +448,31 @@ class DecodingChoiceTransformer extends Transformer {
|
|
|
466
448
|
return false;
|
|
467
449
|
if (!(other instanceof DecodingChoiceTransformer))
|
|
468
450
|
return false;
|
|
469
|
-
if (!
|
|
451
|
+
if (!collection_utils_1.areEqual(this.nullTransformer, other.nullTransformer))
|
|
470
452
|
return false;
|
|
471
|
-
if (!
|
|
453
|
+
if (!collection_utils_1.areEqual(this.integerTransformer, other.integerTransformer))
|
|
472
454
|
return false;
|
|
473
|
-
if (!
|
|
455
|
+
if (!collection_utils_1.areEqual(this.doubleTransformer, other.doubleTransformer))
|
|
474
456
|
return false;
|
|
475
|
-
if (!
|
|
457
|
+
if (!collection_utils_1.areEqual(this.boolTransformer, other.boolTransformer))
|
|
476
458
|
return false;
|
|
477
|
-
if (!
|
|
459
|
+
if (!collection_utils_1.areEqual(this.stringTransformer, other.stringTransformer))
|
|
478
460
|
return false;
|
|
479
|
-
if (!
|
|
461
|
+
if (!collection_utils_1.areEqual(this.arrayTransformer, other.arrayTransformer))
|
|
480
462
|
return false;
|
|
481
|
-
if (!
|
|
463
|
+
if (!collection_utils_1.areEqual(this.objectTransformer, other.objectTransformer))
|
|
482
464
|
return false;
|
|
483
465
|
return true;
|
|
484
466
|
}
|
|
485
467
|
hashCode() {
|
|
486
468
|
let h = super.hashCode();
|
|
487
|
-
h =
|
|
488
|
-
h =
|
|
489
|
-
h =
|
|
490
|
-
h =
|
|
491
|
-
h =
|
|
492
|
-
h =
|
|
493
|
-
h =
|
|
469
|
+
h = collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.nullTransformer));
|
|
470
|
+
h = collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.integerTransformer));
|
|
471
|
+
h = collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.doubleTransformer));
|
|
472
|
+
h = collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.boolTransformer));
|
|
473
|
+
h = collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.stringTransformer));
|
|
474
|
+
h = collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.arrayTransformer));
|
|
475
|
+
h = collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.objectTransformer));
|
|
494
476
|
return h;
|
|
495
477
|
}
|
|
496
478
|
debugPrintContinuations(indent) {
|
|
@@ -501,15 +483,14 @@ class DecodingChoiceTransformer extends Transformer {
|
|
|
501
483
|
}
|
|
502
484
|
exports.DecodingChoiceTransformer = DecodingChoiceTransformer;
|
|
503
485
|
class UnionMemberMatchTransformer extends MatchTransformer {
|
|
504
|
-
memberTypeRef;
|
|
505
486
|
constructor(graph, sourceTypeRef, transformer, memberTypeRef) {
|
|
506
487
|
super("union-member-match", graph, sourceTypeRef, transformer);
|
|
507
488
|
this.memberTypeRef = memberTypeRef;
|
|
508
489
|
}
|
|
509
490
|
get sourceType() {
|
|
510
|
-
const t =
|
|
491
|
+
const t = TypeGraph_1.derefTypeRef(this.sourceTypeRef, this.graph);
|
|
511
492
|
if (!(t instanceof Type_1.UnionType)) {
|
|
512
|
-
return
|
|
493
|
+
return Support_1.panic("The source of a union member match transformer must be a union type");
|
|
513
494
|
}
|
|
514
495
|
return t;
|
|
515
496
|
}
|
|
@@ -517,13 +498,13 @@ class UnionMemberMatchTransformer extends MatchTransformer {
|
|
|
517
498
|
return true;
|
|
518
499
|
}
|
|
519
500
|
get memberType() {
|
|
520
|
-
return
|
|
501
|
+
return TypeGraph_1.derefTypeRef(this.memberTypeRef, this.graph);
|
|
521
502
|
}
|
|
522
503
|
getChildren() {
|
|
523
504
|
return super.getChildren().add(this.memberType);
|
|
524
505
|
}
|
|
525
506
|
reverse(_targetTypeRef, _continuationTransformer) {
|
|
526
|
-
return
|
|
507
|
+
return Support_1.panic("Can't reverse union member match transformer");
|
|
527
508
|
}
|
|
528
509
|
reconstitute(builder) {
|
|
529
510
|
return new UnionMemberMatchTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), this.transformer.reconstitute(builder), builder.reconstituteTypeRef(this.memberTypeRef));
|
|
@@ -537,7 +518,7 @@ class UnionMemberMatchTransformer extends MatchTransformer {
|
|
|
537
518
|
}
|
|
538
519
|
hashCode() {
|
|
539
520
|
const h = super.hashCode();
|
|
540
|
-
return
|
|
521
|
+
return collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.memberTypeRef));
|
|
541
522
|
}
|
|
542
523
|
debugDescription() {
|
|
543
524
|
return `${super.debugDescription()} - member: ${debugStringForType(this.memberType)}`;
|
|
@@ -548,15 +529,14 @@ exports.UnionMemberMatchTransformer = UnionMemberMatchTransformer;
|
|
|
548
529
|
* This matches strings and enum cases.
|
|
549
530
|
*/
|
|
550
531
|
class StringMatchTransformer extends MatchTransformer {
|
|
551
|
-
stringCase;
|
|
552
532
|
constructor(graph, sourceTypeRef, transformer, stringCase) {
|
|
553
533
|
super("string-match", graph, sourceTypeRef, transformer);
|
|
554
534
|
this.stringCase = stringCase;
|
|
555
535
|
}
|
|
556
536
|
get sourceType() {
|
|
557
|
-
const t =
|
|
537
|
+
const t = TypeGraph_1.derefTypeRef(this.sourceTypeRef, this.graph);
|
|
558
538
|
if (!(t instanceof Type_1.EnumType) && !(t instanceof Type_1.PrimitiveType && t.kind === "string")) {
|
|
559
|
-
return
|
|
539
|
+
return Support_1.panic("The source of a string match transformer must be an enum or string type");
|
|
560
540
|
}
|
|
561
541
|
return t;
|
|
562
542
|
}
|
|
@@ -578,7 +558,7 @@ class StringMatchTransformer extends MatchTransformer {
|
|
|
578
558
|
}
|
|
579
559
|
hashCode() {
|
|
580
560
|
const h = super.hashCode();
|
|
581
|
-
return
|
|
561
|
+
return collection_utils_1.addHashCode(h, collection_utils_1.hashString(this.stringCase));
|
|
582
562
|
}
|
|
583
563
|
debugDescription() {
|
|
584
564
|
return `${super.debugDescription()} - case: ${this.stringCase}`;
|
|
@@ -594,7 +574,7 @@ class UnionInstantiationTransformer extends Transformer {
|
|
|
594
574
|
}
|
|
595
575
|
reverse(targetTypeRef, continuationTransformer) {
|
|
596
576
|
if (continuationTransformer === undefined) {
|
|
597
|
-
return
|
|
577
|
+
return Support_1.panic("Union instantiation transformer reverse must have a continuation");
|
|
598
578
|
}
|
|
599
579
|
return new UnionMemberMatchTransformer(this.graph, targetTypeRef, continuationTransformer, this.sourceTypeRef);
|
|
600
580
|
}
|
|
@@ -612,7 +592,6 @@ exports.UnionInstantiationTransformer = UnionInstantiationTransformer;
|
|
|
612
592
|
* Produces a string or an enum case.
|
|
613
593
|
*/
|
|
614
594
|
class StringProducerTransformer extends ProducerTransformer {
|
|
615
|
-
result;
|
|
616
595
|
constructor(graph, sourceTypeRef, consumer, result) {
|
|
617
596
|
super("string-producer", graph, sourceTypeRef, consumer);
|
|
618
597
|
this.result = result;
|
|
@@ -622,7 +601,7 @@ class StringProducerTransformer extends ProducerTransformer {
|
|
|
622
601
|
}
|
|
623
602
|
reverse(targetTypeRef, continuationTransformer) {
|
|
624
603
|
if (continuationTransformer === undefined) {
|
|
625
|
-
return
|
|
604
|
+
return Support_1.panic("Reversing a string producer transformer must have a continuation");
|
|
626
605
|
}
|
|
627
606
|
if (this.consumer === undefined) {
|
|
628
607
|
return new StringMatchTransformer(this.graph, targetTypeRef, continuationTransformer, this.result);
|
|
@@ -632,7 +611,7 @@ class StringProducerTransformer extends ProducerTransformer {
|
|
|
632
611
|
}
|
|
633
612
|
}
|
|
634
613
|
reconstitute(builder) {
|
|
635
|
-
return new StringProducerTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef),
|
|
614
|
+
return new StringProducerTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), collection_utils_1.definedMap(this.consumer, xfer => xfer.reconstitute(builder)), this.result);
|
|
636
615
|
}
|
|
637
616
|
equals(other) {
|
|
638
617
|
if (!super.equals(other))
|
|
@@ -643,7 +622,7 @@ class StringProducerTransformer extends ProducerTransformer {
|
|
|
643
622
|
}
|
|
644
623
|
hashCode() {
|
|
645
624
|
const h = super.hashCode();
|
|
646
|
-
return
|
|
625
|
+
return collection_utils_1.addHashCode(h, collection_utils_1.hashCodeOf(this.consumer));
|
|
647
626
|
}
|
|
648
627
|
debugDescription() {
|
|
649
628
|
return `${super.debugDescription()} - result: ${this.result}`;
|
|
@@ -666,7 +645,7 @@ class ParseStringTransformer extends ProducerTransformer {
|
|
|
666
645
|
}
|
|
667
646
|
}
|
|
668
647
|
reconstitute(builder) {
|
|
669
|
-
return new ParseStringTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef),
|
|
648
|
+
return new ParseStringTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), collection_utils_1.definedMap(this.consumer, xfer => xfer.reconstitute(builder)));
|
|
670
649
|
}
|
|
671
650
|
equals(other) {
|
|
672
651
|
if (!super.equals(other))
|
|
@@ -691,7 +670,7 @@ class StringifyTransformer extends ProducerTransformer {
|
|
|
691
670
|
}
|
|
692
671
|
}
|
|
693
672
|
reconstitute(builder) {
|
|
694
|
-
return new StringifyTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef),
|
|
673
|
+
return new StringifyTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), collection_utils_1.definedMap(this.consumer, xfer => xfer.reconstitute(builder)));
|
|
695
674
|
}
|
|
696
675
|
equals(other) {
|
|
697
676
|
if (!super.equals(other))
|
|
@@ -701,8 +680,6 @@ class StringifyTransformer extends ProducerTransformer {
|
|
|
701
680
|
}
|
|
702
681
|
exports.StringifyTransformer = StringifyTransformer;
|
|
703
682
|
class MinMaxLengthCheckTransformer extends ProducerTransformer {
|
|
704
|
-
minLength;
|
|
705
|
-
maxLength;
|
|
706
683
|
constructor(graph, sourceTypeRef, consumer, minLength, maxLength) {
|
|
707
684
|
super("min-max-length-check", graph, sourceTypeRef, consumer);
|
|
708
685
|
this.minLength = minLength;
|
|
@@ -720,7 +697,7 @@ class MinMaxLengthCheckTransformer extends ProducerTransformer {
|
|
|
720
697
|
}
|
|
721
698
|
}
|
|
722
699
|
reconstitute(builder) {
|
|
723
|
-
return new MinMaxLengthCheckTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef),
|
|
700
|
+
return new MinMaxLengthCheckTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), collection_utils_1.definedMap(this.consumer, xfer => xfer.reconstitute(builder)), this.minLength, this.maxLength);
|
|
724
701
|
}
|
|
725
702
|
equals(other) {
|
|
726
703
|
if (!super.equals(other))
|
|
@@ -732,8 +709,6 @@ class MinMaxLengthCheckTransformer extends ProducerTransformer {
|
|
|
732
709
|
}
|
|
733
710
|
exports.MinMaxLengthCheckTransformer = MinMaxLengthCheckTransformer;
|
|
734
711
|
class MinMaxValueTransformer extends ProducerTransformer {
|
|
735
|
-
minimum;
|
|
736
|
-
maximum;
|
|
737
712
|
constructor(graph, sourceTypeRef, consumer, minimum, maximum) {
|
|
738
713
|
super("min-max-value-check", graph, sourceTypeRef, consumer);
|
|
739
714
|
this.minimum = minimum;
|
|
@@ -751,7 +726,7 @@ class MinMaxValueTransformer extends ProducerTransformer {
|
|
|
751
726
|
}
|
|
752
727
|
}
|
|
753
728
|
reconstitute(builder) {
|
|
754
|
-
return new MinMaxValueTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef),
|
|
729
|
+
return new MinMaxValueTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), collection_utils_1.definedMap(this.consumer, xfer => xfer.reconstitute(builder)), this.minimum, this.maximum);
|
|
755
730
|
}
|
|
756
731
|
equals(other) {
|
|
757
732
|
if (!super.equals(other))
|
|
@@ -761,9 +736,6 @@ class MinMaxValueTransformer extends ProducerTransformer {
|
|
|
761
736
|
}
|
|
762
737
|
exports.MinMaxValueTransformer = MinMaxValueTransformer;
|
|
763
738
|
class Transformation {
|
|
764
|
-
_graph;
|
|
765
|
-
_targetTypeRef;
|
|
766
|
-
transformer;
|
|
767
739
|
constructor(_graph, _targetTypeRef, transformer) {
|
|
768
740
|
this._graph = _graph;
|
|
769
741
|
this._targetTypeRef = _targetTypeRef;
|
|
@@ -773,7 +745,7 @@ class Transformation {
|
|
|
773
745
|
return this.transformer.sourceType;
|
|
774
746
|
}
|
|
775
747
|
get targetType() {
|
|
776
|
-
return
|
|
748
|
+
return TypeGraph_1.derefTypeRef(this._targetTypeRef, this._graph);
|
|
777
749
|
}
|
|
778
750
|
get reverse() {
|
|
779
751
|
return new Transformation(this._graph, this.transformer.sourceTypeRef, this.transformer.reverse(this._targetTypeRef, undefined));
|
|
@@ -790,8 +762,8 @@ class Transformation {
|
|
|
790
762
|
return this._targetTypeRef === other._targetTypeRef && this.transformer.equals(other.transformer);
|
|
791
763
|
}
|
|
792
764
|
hashCode() {
|
|
793
|
-
let h =
|
|
794
|
-
h =
|
|
765
|
+
let h = collection_utils_1.hashCodeOf(this._targetTypeRef);
|
|
766
|
+
h = collection_utils_1.addHashCode(h, this.transformer.hashCode());
|
|
795
767
|
return h;
|
|
796
768
|
}
|
|
797
769
|
debugPrint() {
|