quicktype 18.0.6 → 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.
- package/README.md +1 -1
- package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
- package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
- package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
- package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
- package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
- package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
- package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
- package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
- package/dist/{cli/index.d.ts → index.d.ts} +1 -1
- package/dist/{cli/index.js → index.js} +4 -5
- package/package.json +61 -77
- package/dist/quicktype-core/Annotation.d.ts +0 -8
- package/dist/quicktype-core/Annotation.js +0 -16
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
- package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
- package/dist/quicktype-core/DateTime.d.ts +0 -10
- package/dist/quicktype-core/DateTime.js +0 -57
- package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
- package/dist/quicktype-core/DeclarationIR.js +0 -167
- package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
- package/dist/quicktype-core/GatherNames.d.ts +0 -2
- package/dist/quicktype-core/GatherNames.js +0 -333
- package/dist/quicktype-core/Graph.d.ts +0 -12
- package/dist/quicktype-core/Graph.js +0 -220
- package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
- package/dist/quicktype-core/GraphRewriting.js +0 -421
- package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
- package/dist/quicktype-core/MakeTransformations.js +0 -193
- package/dist/quicktype-core/MarkovChain.d.ts +0 -15
- package/dist/quicktype-core/MarkovChain.js +0 -154
- package/dist/quicktype-core/Messages.d.ts +0 -294
- package/dist/quicktype-core/Messages.js +0 -105
- package/dist/quicktype-core/Naming.d.ts +0 -64
- package/dist/quicktype-core/Naming.js +0 -356
- package/dist/quicktype-core/Renderer.d.ts +0 -50
- package/dist/quicktype-core/Renderer.js +0 -274
- package/dist/quicktype-core/RendererOptions.d.ts +0 -71
- package/dist/quicktype-core/RendererOptions.js +0 -141
- package/dist/quicktype-core/Run.d.ts +0 -174
- package/dist/quicktype-core/Run.js +0 -393
- package/dist/quicktype-core/Source.d.ts +0 -65
- package/dist/quicktype-core/Source.js +0 -204
- package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
- package/dist/quicktype-core/TargetLanguage.js +0 -66
- package/dist/quicktype-core/Transformers.d.ts +0 -209
- package/dist/quicktype-core/Transformers.js +0 -836
- package/dist/quicktype-core/Type.d.ts +0 -206
- package/dist/quicktype-core/Type.js +0 -716
- package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
- package/dist/quicktype-core/TypeBuilder.js +0 -324
- package/dist/quicktype-core/TypeGraph.d.ts +0 -75
- package/dist/quicktype-core/TypeGraph.js +0 -420
- package/dist/quicktype-core/TypeUtils.d.ts +0 -33
- package/dist/quicktype-core/TypeUtils.js +0 -230
- package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
- package/dist/quicktype-core/UnifyClasses.js +0 -159
- package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
- package/dist/quicktype-core/UnionBuilder.js +0 -282
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
- package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
- package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
- package/dist/quicktype-core/attributes/Constraints.js +0 -172
- package/dist/quicktype-core/attributes/Description.d.ts +0 -9
- package/dist/quicktype-core/attributes/Description.js +0 -97
- package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
- package/dist/quicktype-core/attributes/EnumValues.js +0 -31
- package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
- package/dist/quicktype-core/attributes/StringTypes.js +0 -189
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
- package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
- package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
- package/dist/quicktype-core/attributes/TypeNames.js +0 -274
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
- package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
- package/dist/quicktype-core/index.d.ts +0 -48
- package/dist/quicktype-core/index.js +0 -180
- package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
- package/dist/quicktype-core/input/CompressedJSON.js +0 -276
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
- package/dist/quicktype-core/input/Inference.d.ts +0 -22
- package/dist/quicktype-core/input/Inference.js +0 -240
- package/dist/quicktype-core/input/Inputs.d.ts +0 -48
- package/dist/quicktype-core/input/Inputs.js +0 -145
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
- package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
- package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
- package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
- package/dist/quicktype-core/input/PostmanCollection.js +0 -60
- package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
- package/dist/quicktype-core/input/io/NodeIO.js +0 -87
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
- package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
- package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
- package/dist/quicktype-core/language/All.d.ts +0 -3
- package/dist/quicktype-core/language/All.js +0 -57
- package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
- package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
- package/dist/quicktype-core/language/CSharp.d.ts +0 -201
- package/dist/quicktype-core/language/CSharp.js +0 -1850
- package/dist/quicktype-core/language/Crystal.d.ts +0 -37
- package/dist/quicktype-core/language/Crystal.js +0 -337
- package/dist/quicktype-core/language/Dart.d.ts +0 -66
- package/dist/quicktype-core/language/Dart.js +0 -576
- package/dist/quicktype-core/language/Elm.d.ts +0 -58
- package/dist/quicktype-core/language/Elm.js +0 -522
- package/dist/quicktype-core/language/Golang.d.ts +0 -51
- package/dist/quicktype-core/language/Golang.js +0 -460
- package/dist/quicktype-core/language/Haskell.d.ts +0 -56
- package/dist/quicktype-core/language/Haskell.js +0 -411
- package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
- package/dist/quicktype-core/language/JSONSchema.js +0 -169
- package/dist/quicktype-core/language/Java.d.ts +0 -125
- package/dist/quicktype-core/language/Java.js +0 -1081
- package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
- package/dist/quicktype-core/language/JavaScript.js +0 -435
- package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
- package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
- package/dist/quicktype-core/language/Kotlin.js +0 -832
- package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
- package/dist/quicktype-core/language/Objective-C.js +0 -777
- package/dist/quicktype-core/language/Php.d.ts +0 -80
- package/dist/quicktype-core/language/Php.js +0 -702
- package/dist/quicktype-core/language/Pike.d.ts +0 -37
- package/dist/quicktype-core/language/Pike.js +0 -276
- package/dist/quicktype-core/language/Python.d.ts +0 -107
- package/dist/quicktype-core/language/Python.js +0 -969
- package/dist/quicktype-core/language/Rust.d.ts +0 -56
- package/dist/quicktype-core/language/Rust.js +0 -309
- package/dist/quicktype-core/language/Swift.d.ts +0 -96
- package/dist/quicktype-core/language/Swift.js +0 -1211
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
- package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
- package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
- package/dist/quicktype-core/language/ruby/index.js +0 -557
- package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
- package/dist/quicktype-core/language/ruby/keywords.js +0 -358
- package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
- package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
- package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
- package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
- package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
- package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
- package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
- package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
- package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
- package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
- package/dist/quicktype-core/support/Acronyms.js +0 -1128
- package/dist/quicktype-core/support/Chance.d.ts +0 -38
- package/dist/quicktype-core/support/Chance.js +0 -2146
- package/dist/quicktype-core/support/Converters.d.ts +0 -6
- package/dist/quicktype-core/support/Converters.js +0 -16
- package/dist/quicktype-core/support/Strings.d.ts +0 -44
- package/dist/quicktype-core/support/Strings.js +0 -525
- package/dist/quicktype-core/support/Support.d.ts +0 -29
- package/dist/quicktype-core/support/Support.js +0 -162
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
- package/dist/quicktype-graphql-input/index.d.ts +0 -17
- package/dist/quicktype-graphql-input/index.js +0 -407
- package/dist/quicktype-typescript-input/index.d.ts +0 -2
- package/dist/quicktype-typescript-input/index.js +0 -98
|
@@ -1,836 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
-
const collection_utils_1 = require("collection-utils");
|
|
5
|
-
const Type_1 = require("./Type");
|
|
6
|
-
const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
7
|
-
const Support_1 = require("./support/Support");
|
|
8
|
-
const TypeGraph_1 = require("./TypeGraph");
|
|
9
|
-
function debugStringForType(t) {
|
|
10
|
-
const target = followTargetType(t);
|
|
11
|
-
if (t === target) {
|
|
12
|
-
return t.kind;
|
|
13
|
-
}
|
|
14
|
-
return `${t.kind} (${target.kind})`;
|
|
15
|
-
}
|
|
16
|
-
function getNumberOfNodes(xfer) {
|
|
17
|
-
return (0, collection_utils_1.definedMapWithDefault)(xfer, 0, x => x.getNumberOfNodes());
|
|
18
|
-
}
|
|
19
|
-
class Transformer {
|
|
20
|
-
kind;
|
|
21
|
-
graph;
|
|
22
|
-
sourceTypeRef;
|
|
23
|
-
constructor(kind, graph, sourceTypeRef) {
|
|
24
|
-
this.kind = kind;
|
|
25
|
-
this.graph = graph;
|
|
26
|
-
this.sourceTypeRef = sourceTypeRef;
|
|
27
|
-
}
|
|
28
|
-
get sourceType() {
|
|
29
|
-
return (0, TypeGraph_1.derefTypeRef)(this.sourceTypeRef, this.graph);
|
|
30
|
-
}
|
|
31
|
-
/** This must return a newly constructed set. */
|
|
32
|
-
getChildren() {
|
|
33
|
-
return new Set([this.sourceType]);
|
|
34
|
-
}
|
|
35
|
-
getNumberOfNodes() {
|
|
36
|
-
return 1;
|
|
37
|
-
}
|
|
38
|
-
equals(other) {
|
|
39
|
-
if (!(other instanceof Transformer))
|
|
40
|
-
return false;
|
|
41
|
-
return this.sourceTypeRef === other.sourceTypeRef;
|
|
42
|
-
}
|
|
43
|
-
hashCode() {
|
|
44
|
-
return (0, collection_utils_1.hashCodeOf)(this.sourceTypeRef);
|
|
45
|
-
}
|
|
46
|
-
debugDescription() {
|
|
47
|
-
return `${debugStringForType(this.sourceType)} -> ${this.kind}`;
|
|
48
|
-
}
|
|
49
|
-
debugPrintContinuations(_indent) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
debugPrint(indent) {
|
|
53
|
-
console.log((0, Support_1.indentationString)(indent) + this.debugDescription());
|
|
54
|
-
this.debugPrintContinuations(indent + 1);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.Transformer = Transformer;
|
|
58
|
-
class ProducerTransformer extends Transformer {
|
|
59
|
-
consumer;
|
|
60
|
-
constructor(kind, graph, sourceTypeRef, consumer) {
|
|
61
|
-
super(kind, graph, sourceTypeRef);
|
|
62
|
-
this.consumer = consumer;
|
|
63
|
-
}
|
|
64
|
-
getChildren() {
|
|
65
|
-
const children = super.getChildren();
|
|
66
|
-
if (this.consumer === undefined)
|
|
67
|
-
return children;
|
|
68
|
-
return (0, collection_utils_1.setUnionInto)(children, this.consumer.getChildren());
|
|
69
|
-
}
|
|
70
|
-
getNumberOfNodes() {
|
|
71
|
-
return super.getNumberOfNodes() + getNumberOfNodes(this.consumer);
|
|
72
|
-
}
|
|
73
|
-
equals(other) {
|
|
74
|
-
if (!super.equals(other))
|
|
75
|
-
return false;
|
|
76
|
-
if (!(other instanceof ProducerTransformer))
|
|
77
|
-
return false;
|
|
78
|
-
return (0, collection_utils_1.areEqual)(this.consumer, other.consumer);
|
|
79
|
-
}
|
|
80
|
-
hashCode() {
|
|
81
|
-
const h = super.hashCode();
|
|
82
|
-
return (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.consumer));
|
|
83
|
-
}
|
|
84
|
-
debugPrintContinuations(indent) {
|
|
85
|
-
if (this.consumer === undefined)
|
|
86
|
-
return;
|
|
87
|
-
this.consumer.debugPrint(indent);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.ProducerTransformer = ProducerTransformer;
|
|
91
|
-
class MatchTransformer extends Transformer {
|
|
92
|
-
transformer;
|
|
93
|
-
constructor(kind, graph, sourceTypeRef, transformer) {
|
|
94
|
-
super(kind, graph, sourceTypeRef);
|
|
95
|
-
this.transformer = transformer;
|
|
96
|
-
}
|
|
97
|
-
getChildren() {
|
|
98
|
-
return (0, collection_utils_1.setUnionInto)(super.getChildren(), this.transformer.getChildren());
|
|
99
|
-
}
|
|
100
|
-
getNumberOfNodes() {
|
|
101
|
-
return super.getNumberOfNodes() + this.transformer.getNumberOfNodes();
|
|
102
|
-
}
|
|
103
|
-
equals(other) {
|
|
104
|
-
if (!super.equals(other))
|
|
105
|
-
return false;
|
|
106
|
-
if (!(other instanceof MatchTransformer))
|
|
107
|
-
return false;
|
|
108
|
-
return this.transformer.equals(other.transformer);
|
|
109
|
-
}
|
|
110
|
-
hashCode() {
|
|
111
|
-
const h = super.hashCode();
|
|
112
|
-
return (0, collection_utils_1.addHashCode)(h, this.transformer.hashCode());
|
|
113
|
-
}
|
|
114
|
-
debugPrintContinuations(indent) {
|
|
115
|
-
this.transformer.debugPrint(indent);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
exports.MatchTransformer = MatchTransformer;
|
|
119
|
-
class DecodingTransformer extends ProducerTransformer {
|
|
120
|
-
constructor(graph, sourceTypeRef, consumer) {
|
|
121
|
-
super("decode", graph, sourceTypeRef, consumer);
|
|
122
|
-
}
|
|
123
|
-
get canFail() {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
127
|
-
if (continuationTransformer !== undefined) {
|
|
128
|
-
return (0, Support_1.panic)("Reversing a decoding transformer cannot have a continuation");
|
|
129
|
-
}
|
|
130
|
-
if (this.consumer === undefined) {
|
|
131
|
-
return new EncodingTransformer(this.graph, targetTypeRef);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
return this.consumer.reverse(targetTypeRef, new EncodingTransformer(this.graph, this.consumer.sourceTypeRef));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
reconstitute(builder) {
|
|
138
|
-
return new DecodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), (0, collection_utils_1.definedMap)(this.consumer, xfer => xfer.reconstitute(builder)));
|
|
139
|
-
}
|
|
140
|
-
equals(other) {
|
|
141
|
-
if (!super.equals(other))
|
|
142
|
-
return false;
|
|
143
|
-
return other instanceof DecodingTransformer;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
exports.DecodingTransformer = DecodingTransformer;
|
|
147
|
-
class EncodingTransformer extends Transformer {
|
|
148
|
-
constructor(graph, sourceTypeRef) {
|
|
149
|
-
super("encode", graph, sourceTypeRef);
|
|
150
|
-
}
|
|
151
|
-
get canFail() {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
reverse(_targetTypeRef, _continuationTransformer) {
|
|
155
|
-
return (0, Support_1.panic)("Can't reverse encoding transformer");
|
|
156
|
-
}
|
|
157
|
-
reconstitute(builder) {
|
|
158
|
-
return new EncodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef));
|
|
159
|
-
}
|
|
160
|
-
equals(other) {
|
|
161
|
-
if (!super.equals(other))
|
|
162
|
-
return false;
|
|
163
|
-
if (!(other instanceof EncodingTransformer))
|
|
164
|
-
return false;
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
exports.EncodingTransformer = EncodingTransformer;
|
|
169
|
-
class ArrayDecodingTransformer extends ProducerTransformer {
|
|
170
|
-
_itemTargetTypeRef;
|
|
171
|
-
itemTransformer;
|
|
172
|
-
constructor(graph, sourceTypeRef, consumer, _itemTargetTypeRef, itemTransformer) {
|
|
173
|
-
super("decode-array", graph, sourceTypeRef, consumer);
|
|
174
|
-
this._itemTargetTypeRef = _itemTargetTypeRef;
|
|
175
|
-
this.itemTransformer = itemTransformer;
|
|
176
|
-
}
|
|
177
|
-
getChildren() {
|
|
178
|
-
const children = super.getChildren();
|
|
179
|
-
children.add(this.itemTargetType);
|
|
180
|
-
return (0, collection_utils_1.setUnionInto)(children, this.itemTransformer.getChildren());
|
|
181
|
-
}
|
|
182
|
-
getNumberOfNodes() {
|
|
183
|
-
return super.getNumberOfNodes() + this.itemTransformer.getNumberOfNodes();
|
|
184
|
-
}
|
|
185
|
-
get canFail() {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
get itemTargetType() {
|
|
189
|
-
return (0, TypeGraph_1.derefTypeRef)(this._itemTargetTypeRef, this.graph);
|
|
190
|
-
}
|
|
191
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
192
|
-
if (continuationTransformer !== undefined) {
|
|
193
|
-
return (0, Support_1.panic)("Reversing a decoding transformer cannot have a continuation");
|
|
194
|
-
}
|
|
195
|
-
const itemTransformer = this.itemTransformer.reverse(this._itemTargetTypeRef, undefined);
|
|
196
|
-
if (this.consumer === undefined) {
|
|
197
|
-
return new ArrayEncodingTransformer(this.graph, targetTypeRef, this.itemTransformer.sourceTypeRef, itemTransformer);
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
return this.consumer.reverse(targetTypeRef, new ArrayEncodingTransformer(this.graph, this.consumer.sourceTypeRef, this.itemTransformer.sourceTypeRef, itemTransformer));
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
reconstitute(builder) {
|
|
204
|
-
return new ArrayDecodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), (0, collection_utils_1.definedMap)(this.consumer, xfer => xfer.reconstitute(builder)), builder.reconstituteTypeRef(this._itemTargetTypeRef), this.itemTransformer.reconstitute(builder));
|
|
205
|
-
}
|
|
206
|
-
hashCode() {
|
|
207
|
-
let h = super.hashCode();
|
|
208
|
-
h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this._itemTargetTypeRef));
|
|
209
|
-
h = (0, collection_utils_1.addHashCode)(h, this.itemTransformer.hashCode());
|
|
210
|
-
return h;
|
|
211
|
-
}
|
|
212
|
-
equals(other) {
|
|
213
|
-
if (!super.equals(other))
|
|
214
|
-
return false;
|
|
215
|
-
if (!(other instanceof ArrayDecodingTransformer))
|
|
216
|
-
return false;
|
|
217
|
-
if (!(0, collection_utils_1.areEqual)(this._itemTargetTypeRef, other._itemTargetTypeRef))
|
|
218
|
-
return false;
|
|
219
|
-
return this.itemTransformer.equals(other.itemTransformer);
|
|
220
|
-
}
|
|
221
|
-
debugPrintContinuations(indent) {
|
|
222
|
-
this.itemTransformer.debugPrint(indent);
|
|
223
|
-
super.debugPrintContinuations(indent);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
exports.ArrayDecodingTransformer = ArrayDecodingTransformer;
|
|
227
|
-
class ArrayEncodingTransformer extends Transformer {
|
|
228
|
-
_itemTargetTypeRef;
|
|
229
|
-
itemTransformer;
|
|
230
|
-
constructor(graph, sourceTypeRef, _itemTargetTypeRef, itemTransformer) {
|
|
231
|
-
super("encode-array", graph, sourceTypeRef);
|
|
232
|
-
this._itemTargetTypeRef = _itemTargetTypeRef;
|
|
233
|
-
this.itemTransformer = itemTransformer;
|
|
234
|
-
}
|
|
235
|
-
getChildren() {
|
|
236
|
-
const children = super.getChildren();
|
|
237
|
-
children.add(this.itemTargetType);
|
|
238
|
-
return (0, collection_utils_1.setUnionInto)(children, this.itemTransformer.getChildren());
|
|
239
|
-
}
|
|
240
|
-
getNumberOfNodes() {
|
|
241
|
-
return super.getNumberOfNodes() + this.itemTransformer.getNumberOfNodes();
|
|
242
|
-
}
|
|
243
|
-
get canFail() {
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
get itemTargetType() {
|
|
247
|
-
return (0, TypeGraph_1.derefTypeRef)(this._itemTargetTypeRef, this.graph);
|
|
248
|
-
}
|
|
249
|
-
reverse(_targetTypeRef, _continuationTransformer) {
|
|
250
|
-
return (0, Support_1.panic)("Can't reverse array encoding transformer");
|
|
251
|
-
}
|
|
252
|
-
reconstitute(builder) {
|
|
253
|
-
return new ArrayEncodingTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), builder.reconstituteTypeRef(this._itemTargetTypeRef), this.itemTransformer.reconstitute(builder));
|
|
254
|
-
}
|
|
255
|
-
hashCode() {
|
|
256
|
-
let h = super.hashCode();
|
|
257
|
-
h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this._itemTargetTypeRef));
|
|
258
|
-
return (0, collection_utils_1.addHashCode)(h, this.itemTransformer.hashCode());
|
|
259
|
-
}
|
|
260
|
-
equals(other) {
|
|
261
|
-
if (!super.equals(other))
|
|
262
|
-
return false;
|
|
263
|
-
if (!(other instanceof ArrayEncodingTransformer))
|
|
264
|
-
return false;
|
|
265
|
-
if (!(0, collection_utils_1.areEqual)(this._itemTargetTypeRef, other._itemTargetTypeRef))
|
|
266
|
-
return false;
|
|
267
|
-
return this.itemTransformer.equals(other.itemTransformer);
|
|
268
|
-
}
|
|
269
|
-
debugPrintContinuations(indent) {
|
|
270
|
-
this.itemTransformer.debugPrint(indent);
|
|
271
|
-
super.debugPrintContinuations(indent);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
exports.ArrayEncodingTransformer = ArrayEncodingTransformer;
|
|
275
|
-
class ChoiceTransformer extends Transformer {
|
|
276
|
-
transformers;
|
|
277
|
-
constructor(graph, sourceTypeRef, transformers) {
|
|
278
|
-
super("choice", graph, sourceTypeRef);
|
|
279
|
-
this.transformers = transformers;
|
|
280
|
-
(0, Support_1.assert)(transformers.length > 0, "Choice must have at least one transformer");
|
|
281
|
-
}
|
|
282
|
-
getChildren() {
|
|
283
|
-
let children = super.getChildren();
|
|
284
|
-
for (const xfer of this.transformers) {
|
|
285
|
-
(0, collection_utils_1.setUnionInto)(children, xfer.getChildren());
|
|
286
|
-
}
|
|
287
|
-
return children;
|
|
288
|
-
}
|
|
289
|
-
getNumberOfNodes() {
|
|
290
|
-
let n = 0;
|
|
291
|
-
for (const xfer of this.transformers) {
|
|
292
|
-
n += xfer.getNumberOfNodes();
|
|
293
|
-
}
|
|
294
|
-
return super.getNumberOfNodes() + n;
|
|
295
|
-
}
|
|
296
|
-
get canFail() {
|
|
297
|
-
return this.transformers.some(xfer => xfer.canFail);
|
|
298
|
-
}
|
|
299
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
300
|
-
const transformers = this.transformers.map(xfer => xfer.reverse(targetTypeRef, continuationTransformer));
|
|
301
|
-
if (transformers.every(xfer => xfer instanceof UnionMemberMatchTransformer)) {
|
|
302
|
-
const memberMatchers = transformers;
|
|
303
|
-
const first = memberMatchers[0];
|
|
304
|
-
if (memberMatchers.every(xfer => first.memberType.equals(xfer.memberType))) {
|
|
305
|
-
const subTransformers = memberMatchers.map(xfer => xfer.transformer);
|
|
306
|
-
return new UnionMemberMatchTransformer(this.graph, targetTypeRef, new ChoiceTransformer(this.graph, subTransformers[0].sourceTypeRef, subTransformers), first.memberTypeRef);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
return new ChoiceTransformer(this.graph, targetTypeRef, transformers);
|
|
310
|
-
}
|
|
311
|
-
reconstitute(builder) {
|
|
312
|
-
return new ChoiceTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), this.transformers.map(xfer => xfer.reconstitute(builder)));
|
|
313
|
-
}
|
|
314
|
-
equals(other) {
|
|
315
|
-
if (!super.equals(other))
|
|
316
|
-
return false;
|
|
317
|
-
if (!(other instanceof ChoiceTransformer))
|
|
318
|
-
return false;
|
|
319
|
-
return (0, collection_utils_1.areEqual)(this.transformers, other.transformers);
|
|
320
|
-
}
|
|
321
|
-
hashCode() {
|
|
322
|
-
const h = super.hashCode();
|
|
323
|
-
return (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.transformers));
|
|
324
|
-
}
|
|
325
|
-
debugPrintContinuations(indent) {
|
|
326
|
-
for (const xfer of this.transformers) {
|
|
327
|
-
xfer.debugPrint(indent);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
exports.ChoiceTransformer = ChoiceTransformer;
|
|
332
|
-
class DecodingChoiceTransformer extends Transformer {
|
|
333
|
-
nullTransformer;
|
|
334
|
-
integerTransformer;
|
|
335
|
-
doubleTransformer;
|
|
336
|
-
boolTransformer;
|
|
337
|
-
stringTransformer;
|
|
338
|
-
arrayTransformer;
|
|
339
|
-
objectTransformer;
|
|
340
|
-
constructor(graph, sourceTypeRef, nullTransformer, integerTransformer, doubleTransformer, boolTransformer, stringTransformer, arrayTransformer, objectTransformer) {
|
|
341
|
-
super("decoding-choice", graph, sourceTypeRef);
|
|
342
|
-
this.nullTransformer = nullTransformer;
|
|
343
|
-
this.integerTransformer = integerTransformer;
|
|
344
|
-
this.doubleTransformer = doubleTransformer;
|
|
345
|
-
this.boolTransformer = boolTransformer;
|
|
346
|
-
this.stringTransformer = stringTransformer;
|
|
347
|
-
this.arrayTransformer = arrayTransformer;
|
|
348
|
-
this.objectTransformer = objectTransformer;
|
|
349
|
-
}
|
|
350
|
-
get transformers() {
|
|
351
|
-
const transformers = [];
|
|
352
|
-
function add(xfer) {
|
|
353
|
-
if (xfer === undefined)
|
|
354
|
-
return;
|
|
355
|
-
transformers.push(xfer);
|
|
356
|
-
}
|
|
357
|
-
add(this.nullTransformer);
|
|
358
|
-
add(this.integerTransformer);
|
|
359
|
-
add(this.doubleTransformer);
|
|
360
|
-
add(this.boolTransformer);
|
|
361
|
-
add(this.stringTransformer);
|
|
362
|
-
add(this.arrayTransformer);
|
|
363
|
-
add(this.objectTransformer);
|
|
364
|
-
return transformers;
|
|
365
|
-
}
|
|
366
|
-
getChildren() {
|
|
367
|
-
let children = super.getChildren();
|
|
368
|
-
for (const xfer of this.transformers) {
|
|
369
|
-
(0, collection_utils_1.setUnionInto)(children, xfer.getChildren());
|
|
370
|
-
}
|
|
371
|
-
return children;
|
|
372
|
-
}
|
|
373
|
-
getNumberOfNodes() {
|
|
374
|
-
let n = super.getNumberOfNodes();
|
|
375
|
-
for (const xfer of this.transformers) {
|
|
376
|
-
n += getNumberOfNodes(xfer);
|
|
377
|
-
}
|
|
378
|
-
return n;
|
|
379
|
-
}
|
|
380
|
-
get canFail() {
|
|
381
|
-
return false;
|
|
382
|
-
}
|
|
383
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
384
|
-
(0, Support_1.assert)(continuationTransformer === undefined, "Reversing a decoding transformer can't have a target transformer");
|
|
385
|
-
let transformers = new Map();
|
|
386
|
-
let memberMatchTransformers = new Map();
|
|
387
|
-
function addCase(reversed) {
|
|
388
|
-
if (reversed instanceof UnionMemberMatchTransformer) {
|
|
389
|
-
const memberType = reversed.memberType;
|
|
390
|
-
let arr = memberMatchTransformers.get(memberType);
|
|
391
|
-
if (arr === undefined) {
|
|
392
|
-
arr = [];
|
|
393
|
-
memberMatchTransformers.set(memberType, arr);
|
|
394
|
-
}
|
|
395
|
-
arr.push(reversed);
|
|
396
|
-
}
|
|
397
|
-
else {
|
|
398
|
-
const kind = reversed.sourceType.kind;
|
|
399
|
-
let arr = transformers.get(kind);
|
|
400
|
-
if (arr === undefined) {
|
|
401
|
-
arr = [];
|
|
402
|
-
transformers.set(kind, arr);
|
|
403
|
-
}
|
|
404
|
-
arr.push(reversed);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
function reverseAndAdd(transformer) {
|
|
408
|
-
const reversed = transformer.reverse(targetTypeRef, undefined);
|
|
409
|
-
let cases = [];
|
|
410
|
-
// Flatten nested ChoiceTransformers
|
|
411
|
-
if (reversed instanceof ChoiceTransformer) {
|
|
412
|
-
cases = reversed.transformers;
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
cases = [reversed];
|
|
416
|
-
}
|
|
417
|
-
for (const xfer of cases) {
|
|
418
|
-
addCase(xfer);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
// FIXME: Actually, keep all the failing transformers and put them first, then
|
|
422
|
-
// finally do the simplest non-failing one. Actually actually, maybe not, since
|
|
423
|
-
// we're reversing to encode? What's a case where this would be useful?
|
|
424
|
-
// If there are non-failing transformers, we ignore the ones that can fail and
|
|
425
|
-
// just pick the "simplest" non-failing one, being the one with the least number
|
|
426
|
-
// of nodes.
|
|
427
|
-
function filter(xfers) {
|
|
428
|
-
(0, Support_1.assert)(xfers.length > 0, "Must have at least one transformer");
|
|
429
|
-
const nonfailing = xfers.filter(xfer => {
|
|
430
|
-
// For member match transformers we're deciding between
|
|
431
|
-
// multiple that match against the same member, so the fact
|
|
432
|
-
// that the match can fail is not important, since if it fails
|
|
433
|
-
// it will fail for all candidates. The question is whether
|
|
434
|
-
// its continuation can fail.
|
|
435
|
-
if (xfer instanceof UnionMemberMatchTransformer) {
|
|
436
|
-
return !xfer.transformer.canFail;
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
return !xfer.canFail;
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
if (nonfailing.length === 0)
|
|
443
|
-
return xfers;
|
|
444
|
-
const smallest = (0, collection_utils_1.arraySortByInto)(nonfailing.map(x => [x.getNumberOfNodes(), x]), ([c, _]) => c)[0][1];
|
|
445
|
-
return [smallest];
|
|
446
|
-
}
|
|
447
|
-
this.transformers.forEach(reverseAndAdd);
|
|
448
|
-
const allTransformers = Array.from(transformers.values()).concat(Array.from(memberMatchTransformers.values()));
|
|
449
|
-
const resultingTransformers = [].concat(...allTransformers.map(filter));
|
|
450
|
-
// No choice needed if there's only one
|
|
451
|
-
if (resultingTransformers.length === 1) {
|
|
452
|
-
return resultingTransformers[0];
|
|
453
|
-
}
|
|
454
|
-
return new ChoiceTransformer(this.graph, targetTypeRef, resultingTransformers);
|
|
455
|
-
}
|
|
456
|
-
reconstitute(builder) {
|
|
457
|
-
function reconstitute(xf) {
|
|
458
|
-
if (xf === undefined)
|
|
459
|
-
return undefined;
|
|
460
|
-
return xf.reconstitute(builder);
|
|
461
|
-
}
|
|
462
|
-
return new DecodingChoiceTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), reconstitute(this.nullTransformer), reconstitute(this.integerTransformer), reconstitute(this.doubleTransformer), reconstitute(this.boolTransformer), reconstitute(this.stringTransformer), reconstitute(this.arrayTransformer), reconstitute(this.objectTransformer));
|
|
463
|
-
}
|
|
464
|
-
equals(other) {
|
|
465
|
-
if (!super.equals(other))
|
|
466
|
-
return false;
|
|
467
|
-
if (!(other instanceof DecodingChoiceTransformer))
|
|
468
|
-
return false;
|
|
469
|
-
if (!(0, collection_utils_1.areEqual)(this.nullTransformer, other.nullTransformer))
|
|
470
|
-
return false;
|
|
471
|
-
if (!(0, collection_utils_1.areEqual)(this.integerTransformer, other.integerTransformer))
|
|
472
|
-
return false;
|
|
473
|
-
if (!(0, collection_utils_1.areEqual)(this.doubleTransformer, other.doubleTransformer))
|
|
474
|
-
return false;
|
|
475
|
-
if (!(0, collection_utils_1.areEqual)(this.boolTransformer, other.boolTransformer))
|
|
476
|
-
return false;
|
|
477
|
-
if (!(0, collection_utils_1.areEqual)(this.stringTransformer, other.stringTransformer))
|
|
478
|
-
return false;
|
|
479
|
-
if (!(0, collection_utils_1.areEqual)(this.arrayTransformer, other.arrayTransformer))
|
|
480
|
-
return false;
|
|
481
|
-
if (!(0, collection_utils_1.areEqual)(this.objectTransformer, other.objectTransformer))
|
|
482
|
-
return false;
|
|
483
|
-
return true;
|
|
484
|
-
}
|
|
485
|
-
hashCode() {
|
|
486
|
-
let h = super.hashCode();
|
|
487
|
-
h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.nullTransformer));
|
|
488
|
-
h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.integerTransformer));
|
|
489
|
-
h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.doubleTransformer));
|
|
490
|
-
h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.boolTransformer));
|
|
491
|
-
h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.stringTransformer));
|
|
492
|
-
h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.arrayTransformer));
|
|
493
|
-
h = (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.objectTransformer));
|
|
494
|
-
return h;
|
|
495
|
-
}
|
|
496
|
-
debugPrintContinuations(indent) {
|
|
497
|
-
for (const xfer of this.transformers) {
|
|
498
|
-
xfer.debugPrint(indent);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
exports.DecodingChoiceTransformer = DecodingChoiceTransformer;
|
|
503
|
-
class UnionMemberMatchTransformer extends MatchTransformer {
|
|
504
|
-
memberTypeRef;
|
|
505
|
-
constructor(graph, sourceTypeRef, transformer, memberTypeRef) {
|
|
506
|
-
super("union-member-match", graph, sourceTypeRef, transformer);
|
|
507
|
-
this.memberTypeRef = memberTypeRef;
|
|
508
|
-
}
|
|
509
|
-
get sourceType() {
|
|
510
|
-
const t = (0, TypeGraph_1.derefTypeRef)(this.sourceTypeRef, this.graph);
|
|
511
|
-
if (!(t instanceof Type_1.UnionType)) {
|
|
512
|
-
return (0, Support_1.panic)("The source of a union member match transformer must be a union type");
|
|
513
|
-
}
|
|
514
|
-
return t;
|
|
515
|
-
}
|
|
516
|
-
get canFail() {
|
|
517
|
-
return true;
|
|
518
|
-
}
|
|
519
|
-
get memberType() {
|
|
520
|
-
return (0, TypeGraph_1.derefTypeRef)(this.memberTypeRef, this.graph);
|
|
521
|
-
}
|
|
522
|
-
getChildren() {
|
|
523
|
-
return super.getChildren().add(this.memberType);
|
|
524
|
-
}
|
|
525
|
-
reverse(_targetTypeRef, _continuationTransformer) {
|
|
526
|
-
return (0, Support_1.panic)("Can't reverse union member match transformer");
|
|
527
|
-
}
|
|
528
|
-
reconstitute(builder) {
|
|
529
|
-
return new UnionMemberMatchTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), this.transformer.reconstitute(builder), builder.reconstituteTypeRef(this.memberTypeRef));
|
|
530
|
-
}
|
|
531
|
-
equals(other) {
|
|
532
|
-
if (!super.equals(other))
|
|
533
|
-
return false;
|
|
534
|
-
if (!(other instanceof UnionMemberMatchTransformer))
|
|
535
|
-
return false;
|
|
536
|
-
return this.memberTypeRef === other.memberTypeRef;
|
|
537
|
-
}
|
|
538
|
-
hashCode() {
|
|
539
|
-
const h = super.hashCode();
|
|
540
|
-
return (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.memberTypeRef));
|
|
541
|
-
}
|
|
542
|
-
debugDescription() {
|
|
543
|
-
return `${super.debugDescription()} - member: ${debugStringForType(this.memberType)}`;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
exports.UnionMemberMatchTransformer = UnionMemberMatchTransformer;
|
|
547
|
-
/**
|
|
548
|
-
* This matches strings and enum cases.
|
|
549
|
-
*/
|
|
550
|
-
class StringMatchTransformer extends MatchTransformer {
|
|
551
|
-
stringCase;
|
|
552
|
-
constructor(graph, sourceTypeRef, transformer, stringCase) {
|
|
553
|
-
super("string-match", graph, sourceTypeRef, transformer);
|
|
554
|
-
this.stringCase = stringCase;
|
|
555
|
-
}
|
|
556
|
-
get sourceType() {
|
|
557
|
-
const t = (0, TypeGraph_1.derefTypeRef)(this.sourceTypeRef, this.graph);
|
|
558
|
-
if (!(t instanceof Type_1.EnumType) && !(t instanceof Type_1.PrimitiveType && t.kind === "string")) {
|
|
559
|
-
return (0, Support_1.panic)("The source of a string match transformer must be an enum or string type");
|
|
560
|
-
}
|
|
561
|
-
return t;
|
|
562
|
-
}
|
|
563
|
-
get canFail() {
|
|
564
|
-
return true;
|
|
565
|
-
}
|
|
566
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
567
|
-
return this.transformer.reverse(targetTypeRef, new StringProducerTransformer(this.graph, this.transformer.sourceTypeRef, continuationTransformer, this.stringCase));
|
|
568
|
-
}
|
|
569
|
-
reconstitute(builder) {
|
|
570
|
-
return new StringMatchTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), this.transformer.reconstitute(builder), this.stringCase);
|
|
571
|
-
}
|
|
572
|
-
equals(other) {
|
|
573
|
-
if (!super.equals(other))
|
|
574
|
-
return false;
|
|
575
|
-
if (!(other instanceof StringMatchTransformer))
|
|
576
|
-
return false;
|
|
577
|
-
return this.stringCase !== other.stringCase;
|
|
578
|
-
}
|
|
579
|
-
hashCode() {
|
|
580
|
-
const h = super.hashCode();
|
|
581
|
-
return (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashString)(this.stringCase));
|
|
582
|
-
}
|
|
583
|
-
debugDescription() {
|
|
584
|
-
return `${super.debugDescription()} - case: ${this.stringCase}`;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
exports.StringMatchTransformer = StringMatchTransformer;
|
|
588
|
-
class UnionInstantiationTransformer extends Transformer {
|
|
589
|
-
constructor(graph, sourceTypeRef) {
|
|
590
|
-
super("union-instantiation", graph, sourceTypeRef);
|
|
591
|
-
}
|
|
592
|
-
get canFail() {
|
|
593
|
-
return false;
|
|
594
|
-
}
|
|
595
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
596
|
-
if (continuationTransformer === undefined) {
|
|
597
|
-
return (0, Support_1.panic)("Union instantiation transformer reverse must have a continuation");
|
|
598
|
-
}
|
|
599
|
-
return new UnionMemberMatchTransformer(this.graph, targetTypeRef, continuationTransformer, this.sourceTypeRef);
|
|
600
|
-
}
|
|
601
|
-
reconstitute(builder) {
|
|
602
|
-
return new UnionInstantiationTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef));
|
|
603
|
-
}
|
|
604
|
-
equals(other) {
|
|
605
|
-
if (!super.equals(other))
|
|
606
|
-
return false;
|
|
607
|
-
return other instanceof UnionInstantiationTransformer;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
exports.UnionInstantiationTransformer = UnionInstantiationTransformer;
|
|
611
|
-
/**
|
|
612
|
-
* Produces a string or an enum case.
|
|
613
|
-
*/
|
|
614
|
-
class StringProducerTransformer extends ProducerTransformer {
|
|
615
|
-
result;
|
|
616
|
-
constructor(graph, sourceTypeRef, consumer, result) {
|
|
617
|
-
super("string-producer", graph, sourceTypeRef, consumer);
|
|
618
|
-
this.result = result;
|
|
619
|
-
}
|
|
620
|
-
get canFail() {
|
|
621
|
-
return false;
|
|
622
|
-
}
|
|
623
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
624
|
-
if (continuationTransformer === undefined) {
|
|
625
|
-
return (0, Support_1.panic)("Reversing a string producer transformer must have a continuation");
|
|
626
|
-
}
|
|
627
|
-
if (this.consumer === undefined) {
|
|
628
|
-
return new StringMatchTransformer(this.graph, targetTypeRef, continuationTransformer, this.result);
|
|
629
|
-
}
|
|
630
|
-
else {
|
|
631
|
-
return this.consumer.reverse(targetTypeRef, new StringMatchTransformer(this.graph, this.consumer.sourceTypeRef, continuationTransformer, this.result));
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
reconstitute(builder) {
|
|
635
|
-
return new StringProducerTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), (0, collection_utils_1.definedMap)(this.consumer, xfer => xfer.reconstitute(builder)), this.result);
|
|
636
|
-
}
|
|
637
|
-
equals(other) {
|
|
638
|
-
if (!super.equals(other))
|
|
639
|
-
return false;
|
|
640
|
-
if (!(other instanceof StringProducerTransformer))
|
|
641
|
-
return false;
|
|
642
|
-
return this.result === other.result;
|
|
643
|
-
}
|
|
644
|
-
hashCode() {
|
|
645
|
-
const h = super.hashCode();
|
|
646
|
-
return (0, collection_utils_1.addHashCode)(h, (0, collection_utils_1.hashCodeOf)(this.consumer));
|
|
647
|
-
}
|
|
648
|
-
debugDescription() {
|
|
649
|
-
return `${super.debugDescription()} - result: ${this.result}`;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
exports.StringProducerTransformer = StringProducerTransformer;
|
|
653
|
-
class ParseStringTransformer extends ProducerTransformer {
|
|
654
|
-
constructor(graph, sourceTypeRef, consumer) {
|
|
655
|
-
super("parse-string", graph, sourceTypeRef, consumer);
|
|
656
|
-
}
|
|
657
|
-
get canFail() {
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
661
|
-
if (this.consumer === undefined) {
|
|
662
|
-
return new StringifyTransformer(this.graph, targetTypeRef, continuationTransformer);
|
|
663
|
-
}
|
|
664
|
-
else {
|
|
665
|
-
return this.consumer.reverse(targetTypeRef, new StringifyTransformer(this.graph, this.consumer.sourceTypeRef, continuationTransformer));
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
reconstitute(builder) {
|
|
669
|
-
return new ParseStringTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), (0, collection_utils_1.definedMap)(this.consumer, xfer => xfer.reconstitute(builder)));
|
|
670
|
-
}
|
|
671
|
-
equals(other) {
|
|
672
|
-
if (!super.equals(other))
|
|
673
|
-
return false;
|
|
674
|
-
return other instanceof ParseStringTransformer;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
exports.ParseStringTransformer = ParseStringTransformer;
|
|
678
|
-
class StringifyTransformer extends ProducerTransformer {
|
|
679
|
-
constructor(graph, sourceTypeRef, consumer) {
|
|
680
|
-
super("stringify", graph, sourceTypeRef, consumer);
|
|
681
|
-
}
|
|
682
|
-
get canFail() {
|
|
683
|
-
return false;
|
|
684
|
-
}
|
|
685
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
686
|
-
if (this.consumer === undefined) {
|
|
687
|
-
return new ParseStringTransformer(this.graph, targetTypeRef, continuationTransformer);
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
return this.consumer.reverse(targetTypeRef, new ParseStringTransformer(this.graph, this.consumer.sourceTypeRef, continuationTransformer));
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
reconstitute(builder) {
|
|
694
|
-
return new StringifyTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), (0, collection_utils_1.definedMap)(this.consumer, xfer => xfer.reconstitute(builder)));
|
|
695
|
-
}
|
|
696
|
-
equals(other) {
|
|
697
|
-
if (!super.equals(other))
|
|
698
|
-
return false;
|
|
699
|
-
return other instanceof StringifyTransformer;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
exports.StringifyTransformer = StringifyTransformer;
|
|
703
|
-
class MinMaxLengthCheckTransformer extends ProducerTransformer {
|
|
704
|
-
minLength;
|
|
705
|
-
maxLength;
|
|
706
|
-
constructor(graph, sourceTypeRef, consumer, minLength, maxLength) {
|
|
707
|
-
super("min-max-length-check", graph, sourceTypeRef, consumer);
|
|
708
|
-
this.minLength = minLength;
|
|
709
|
-
this.maxLength = maxLength;
|
|
710
|
-
}
|
|
711
|
-
get canFail() {
|
|
712
|
-
return true;
|
|
713
|
-
}
|
|
714
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
715
|
-
if (this.consumer === undefined) {
|
|
716
|
-
return new MinMaxLengthCheckTransformer(this.graph, targetTypeRef, continuationTransformer, this.minLength, this.maxLength);
|
|
717
|
-
}
|
|
718
|
-
else {
|
|
719
|
-
return this.consumer.reverse(targetTypeRef, new MinMaxLengthCheckTransformer(this.graph, this.consumer.sourceTypeRef, continuationTransformer, this.minLength, this.maxLength));
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
reconstitute(builder) {
|
|
723
|
-
return new MinMaxLengthCheckTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), (0, collection_utils_1.definedMap)(this.consumer, xfer => xfer.reconstitute(builder)), this.minLength, this.maxLength);
|
|
724
|
-
}
|
|
725
|
-
equals(other) {
|
|
726
|
-
if (!super.equals(other))
|
|
727
|
-
return false;
|
|
728
|
-
return (other instanceof MinMaxLengthCheckTransformer &&
|
|
729
|
-
this.minLength === other.minLength &&
|
|
730
|
-
this.maxLength === other.maxLength);
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
exports.MinMaxLengthCheckTransformer = MinMaxLengthCheckTransformer;
|
|
734
|
-
class MinMaxValueTransformer extends ProducerTransformer {
|
|
735
|
-
minimum;
|
|
736
|
-
maximum;
|
|
737
|
-
constructor(graph, sourceTypeRef, consumer, minimum, maximum) {
|
|
738
|
-
super("min-max-value-check", graph, sourceTypeRef, consumer);
|
|
739
|
-
this.minimum = minimum;
|
|
740
|
-
this.maximum = maximum;
|
|
741
|
-
}
|
|
742
|
-
get canFail() {
|
|
743
|
-
return true;
|
|
744
|
-
}
|
|
745
|
-
reverse(targetTypeRef, continuationTransformer) {
|
|
746
|
-
if (this.consumer === undefined) {
|
|
747
|
-
return new MinMaxValueTransformer(this.graph, targetTypeRef, continuationTransformer, this.minimum, this.maximum);
|
|
748
|
-
}
|
|
749
|
-
else {
|
|
750
|
-
return this.consumer.reverse(targetTypeRef, new MinMaxValueTransformer(this.graph, this.consumer.sourceTypeRef, continuationTransformer, this.minimum, this.maximum));
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
reconstitute(builder) {
|
|
754
|
-
return new MinMaxValueTransformer(builder.typeGraph, builder.reconstituteTypeRef(this.sourceTypeRef), (0, collection_utils_1.definedMap)(this.consumer, xfer => xfer.reconstitute(builder)), this.minimum, this.maximum);
|
|
755
|
-
}
|
|
756
|
-
equals(other) {
|
|
757
|
-
if (!super.equals(other))
|
|
758
|
-
return false;
|
|
759
|
-
return (other instanceof MinMaxValueTransformer && this.minimum === other.minimum && this.maximum === other.maximum);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
exports.MinMaxValueTransformer = MinMaxValueTransformer;
|
|
763
|
-
class Transformation {
|
|
764
|
-
_graph;
|
|
765
|
-
_targetTypeRef;
|
|
766
|
-
transformer;
|
|
767
|
-
constructor(_graph, _targetTypeRef, transformer) {
|
|
768
|
-
this._graph = _graph;
|
|
769
|
-
this._targetTypeRef = _targetTypeRef;
|
|
770
|
-
this.transformer = transformer;
|
|
771
|
-
}
|
|
772
|
-
get sourceType() {
|
|
773
|
-
return this.transformer.sourceType;
|
|
774
|
-
}
|
|
775
|
-
get targetType() {
|
|
776
|
-
return (0, TypeGraph_1.derefTypeRef)(this._targetTypeRef, this._graph);
|
|
777
|
-
}
|
|
778
|
-
get reverse() {
|
|
779
|
-
return new Transformation(this._graph, this.transformer.sourceTypeRef, this.transformer.reverse(this._targetTypeRef, undefined));
|
|
780
|
-
}
|
|
781
|
-
getChildren() {
|
|
782
|
-
return this.transformer.getChildren().add(this.targetType);
|
|
783
|
-
}
|
|
784
|
-
reconstitute(builder) {
|
|
785
|
-
return new Transformation(builder.typeGraph, builder.reconstituteTypeRef(this._targetTypeRef), this.transformer.reconstitute(builder));
|
|
786
|
-
}
|
|
787
|
-
equals(other) {
|
|
788
|
-
if (!(other instanceof Transformation))
|
|
789
|
-
return false;
|
|
790
|
-
return this._targetTypeRef === other._targetTypeRef && this.transformer.equals(other.transformer);
|
|
791
|
-
}
|
|
792
|
-
hashCode() {
|
|
793
|
-
let h = (0, collection_utils_1.hashCodeOf)(this._targetTypeRef);
|
|
794
|
-
h = (0, collection_utils_1.addHashCode)(h, this.transformer.hashCode());
|
|
795
|
-
return h;
|
|
796
|
-
}
|
|
797
|
-
debugPrint() {
|
|
798
|
-
this.transformer.debugPrint(0);
|
|
799
|
-
console.log(`-> ${debugStringForType(this.targetType)}`);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
exports.Transformation = Transformation;
|
|
803
|
-
class TransformationTypeAttributeKind extends TypeAttributes_1.TypeAttributeKind {
|
|
804
|
-
constructor() {
|
|
805
|
-
super("transformation");
|
|
806
|
-
}
|
|
807
|
-
appliesToTypeKind(_kind) {
|
|
808
|
-
return true;
|
|
809
|
-
}
|
|
810
|
-
get inIdentity() {
|
|
811
|
-
return true;
|
|
812
|
-
}
|
|
813
|
-
children(xf) {
|
|
814
|
-
return xf.getChildren();
|
|
815
|
-
}
|
|
816
|
-
reconstitute(builder, xf) {
|
|
817
|
-
return xf.reconstitute(builder);
|
|
818
|
-
}
|
|
819
|
-
stringify(_) {
|
|
820
|
-
return "transformation";
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
exports.transformationTypeAttributeKind = new TransformationTypeAttributeKind();
|
|
824
|
-
function transformationForType(t) {
|
|
825
|
-
return exports.transformationTypeAttributeKind.tryGetInAttributes(t.getAttributes());
|
|
826
|
-
}
|
|
827
|
-
exports.transformationForType = transformationForType;
|
|
828
|
-
function followTargetType(t) {
|
|
829
|
-
for (;;) {
|
|
830
|
-
const xf = transformationForType(t);
|
|
831
|
-
if (xf === undefined)
|
|
832
|
-
return t;
|
|
833
|
-
t = xf.targetType;
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
exports.followTargetType = followTargetType;
|