quicktype 16.0.42 → 17.0.0
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 +26 -38
- package/dist/cli/GraphQLIntrospection.js +33 -41
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +4 -3
- package/dist/cli/index.js +363 -364
- package/dist/quicktype-core/Annotation.js +2 -0
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +104 -81
- package/dist/quicktype-core/DateTime.js +1 -0
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +13 -10
- package/dist/quicktype-core/EncodedMarkovChain.js +1 -0
- package/dist/quicktype-core/GatherNames.js +47 -25
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +23 -19
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +65 -54
- package/dist/quicktype-core/MakeTransformations.js +23 -22
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +9 -8
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +8 -3
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +76 -61
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +34 -17
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +6 -3
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +72 -67
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +19 -18
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +6 -2
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +94 -66
- package/dist/quicktype-core/Type.d.ts +41 -43
- package/dist/quicktype-core/Type.js +96 -71
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +53 -47
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +49 -40
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +23 -22
- package/dist/quicktype-core/UnifyClasses.js +16 -12
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +33 -30
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +18 -17
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +8 -4
- package/dist/quicktype-core/attributes/Description.js +6 -5
- package/dist/quicktype-core/attributes/EnumValues.js +4 -3
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +24 -21
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +12 -10
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +49 -21
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +10 -6
- package/dist/quicktype-core/index.js +128 -125
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +49 -54
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +5 -13
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +25 -17
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +38 -54
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +503 -523
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +24 -35
- package/dist/quicktype-core/input/PostmanCollection.js +2 -1
- package/dist/quicktype-core/input/io/NodeIO.js +55 -44
- package/dist/quicktype-core/input/io/get-stream/index.js +6 -2
- package/dist/quicktype-core/language/All.js +3 -2
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +185 -151
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +82 -72
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +18 -17
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +40 -38
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +47 -45
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +23 -20
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +25 -23
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +17 -16
- 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 +19 -17
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +15 -13
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +12 -11
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +39 -37
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +45 -41
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +66 -41
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +18 -17
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +63 -64
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +21 -19
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +568 -565
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +28 -26
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +49 -24
- package/dist/quicktype-core/language/ruby/keywords.js +1 -0
- package/dist/quicktype-core/rewrites/CombineClasses.js +9 -8
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +18 -17
- package/dist/quicktype-core/rewrites/FlattenStrings.js +7 -6
- package/dist/quicktype-core/rewrites/FlattenUnions.js +9 -8
- package/dist/quicktype-core/rewrites/InferMaps.js +11 -10
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +8 -7
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +68 -67
- package/dist/quicktype-core/support/Acronyms.js +3 -1
- package/dist/quicktype-core/support/Chance.js +10 -0
- package/dist/quicktype-core/support/Converters.js +1 -0
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +17 -16
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +30 -6
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +1 -0
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +229 -212
- package/dist/quicktype-typescript-input/index.js +28 -4
- package/package.json +25 -19
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphRewriteBuilder = exports.GraphRemapBuilder = exports.BaseGraphRewriteBuilder = exports.TypeReconstituter = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const TypeUtils_1 = require("./TypeUtils");
|
|
5
6
|
const TypeGraph_1 = require("./TypeGraph");
|
|
@@ -7,33 +8,38 @@ const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
|
7
8
|
const Support_1 = require("./support/Support");
|
|
8
9
|
const TypeBuilder_1 = require("./TypeBuilder");
|
|
9
10
|
class TypeReconstituter {
|
|
11
|
+
_typeBuilder;
|
|
12
|
+
_makeClassUnique;
|
|
13
|
+
_typeAttributes;
|
|
14
|
+
_forwardingRef;
|
|
15
|
+
_register;
|
|
16
|
+
_wasUsed = false;
|
|
17
|
+
_typeRef = undefined;
|
|
10
18
|
constructor(_typeBuilder, _makeClassUnique, _typeAttributes, _forwardingRef, _register) {
|
|
11
19
|
this._typeBuilder = _typeBuilder;
|
|
12
20
|
this._makeClassUnique = _makeClassUnique;
|
|
13
21
|
this._typeAttributes = _typeAttributes;
|
|
14
22
|
this._forwardingRef = _forwardingRef;
|
|
15
23
|
this._register = _register;
|
|
16
|
-
this._wasUsed = false;
|
|
17
|
-
this._typeRef = undefined;
|
|
18
24
|
}
|
|
19
25
|
builderForNewType() {
|
|
20
|
-
Support_1.assert(!this._wasUsed, "TypeReconstituter used more than once");
|
|
26
|
+
(0, Support_1.assert)(!this._wasUsed, "TypeReconstituter used more than once");
|
|
21
27
|
this._wasUsed = true;
|
|
22
28
|
return this._typeBuilder;
|
|
23
29
|
}
|
|
24
30
|
builderForSetting() {
|
|
25
|
-
Support_1.assert(this._wasUsed && this._typeRef !== undefined, "Can't set type members before constructing a type");
|
|
31
|
+
(0, Support_1.assert)(this._wasUsed && this._typeRef !== undefined, "Can't set type members before constructing a type");
|
|
26
32
|
return this._typeBuilder;
|
|
27
33
|
}
|
|
28
34
|
getResult() {
|
|
29
35
|
if (this._typeRef === undefined) {
|
|
30
|
-
return Support_1.panic("Type was not reconstituted");
|
|
36
|
+
return (0, Support_1.panic)("Type was not reconstituted");
|
|
31
37
|
}
|
|
32
38
|
return this._typeRef;
|
|
33
39
|
}
|
|
34
40
|
// FIXME: Do registration automatically.
|
|
35
41
|
register(tref) {
|
|
36
|
-
Support_1.assert(this._typeRef === undefined, "Cannot register a type twice");
|
|
42
|
+
(0, Support_1.assert)(this._typeRef === undefined, "Cannot register a type twice");
|
|
37
43
|
this._typeRef = tref;
|
|
38
44
|
this._register(tref);
|
|
39
45
|
}
|
|
@@ -42,8 +48,8 @@ class TypeReconstituter {
|
|
|
42
48
|
this.register(tref);
|
|
43
49
|
}
|
|
44
50
|
lookup(trefs) {
|
|
45
|
-
Support_1.assert(!this._wasUsed, "Cannot lookup constituents after building type");
|
|
46
|
-
if (TypeGraph_1.isTypeRef(trefs)) {
|
|
51
|
+
(0, Support_1.assert)(!this._wasUsed, "Cannot lookup constituents after building type");
|
|
52
|
+
if ((0, TypeGraph_1.isTypeRef)(trefs)) {
|
|
47
53
|
return this._typeBuilder.lookupTypeRefs([trefs], undefined, false);
|
|
48
54
|
}
|
|
49
55
|
else {
|
|
@@ -57,7 +63,7 @@ class TypeReconstituter {
|
|
|
57
63
|
const resultValues = this.lookup(trefs.values());
|
|
58
64
|
if (resultValues === undefined)
|
|
59
65
|
return undefined;
|
|
60
|
-
Support_1.assert(resultValues.length === trefs.size, "Didn't get back the correct number of types");
|
|
66
|
+
(0, Support_1.assert)(resultValues.length === trefs.size, "Didn't get back the correct number of types");
|
|
61
67
|
const result = new Map();
|
|
62
68
|
let i = 0;
|
|
63
69
|
for (const k of trefs.keys()) {
|
|
@@ -67,8 +73,8 @@ class TypeReconstituter {
|
|
|
67
73
|
return result;
|
|
68
74
|
}
|
|
69
75
|
reconstitute(trefs) {
|
|
70
|
-
Support_1.assert(this._wasUsed, "Cannot reconstitute constituents before building type");
|
|
71
|
-
if (TypeGraph_1.isTypeRef(trefs)) {
|
|
76
|
+
(0, Support_1.assert)(this._wasUsed, "Cannot reconstitute constituents before building type");
|
|
77
|
+
if ((0, TypeGraph_1.isTypeRef)(trefs)) {
|
|
72
78
|
return this._typeBuilder.reconstituteTypeRef(trefs);
|
|
73
79
|
}
|
|
74
80
|
else {
|
|
@@ -76,7 +82,7 @@ class TypeReconstituter {
|
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
reconstituteMap(trefs) {
|
|
79
|
-
return collection_utils_1.mapMap(trefs, tref => this._typeBuilder.reconstituteTypeRef(tref));
|
|
85
|
+
return (0, collection_utils_1.mapMap)(trefs, tref => this._typeBuilder.reconstituteTypeRef(tref));
|
|
80
86
|
}
|
|
81
87
|
getPrimitiveType(kind) {
|
|
82
88
|
this.register(this.builderForNewType().getPrimitiveType(kind, this._typeAttributes, this._forwardingRef));
|
|
@@ -139,13 +145,15 @@ class TypeReconstituter {
|
|
|
139
145
|
}
|
|
140
146
|
exports.TypeReconstituter = TypeReconstituter;
|
|
141
147
|
class BaseGraphRewriteBuilder extends TypeBuilder_1.TypeBuilder {
|
|
148
|
+
originalGraph;
|
|
149
|
+
debugPrint;
|
|
150
|
+
reconstitutedTypes = new Map();
|
|
151
|
+
_lostTypeAttributes = false;
|
|
152
|
+
_printIndent = 0;
|
|
142
153
|
constructor(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, debugPrint) {
|
|
143
154
|
super(originalGraph.serial + 1, stringTypeMapping, alphabetizeProperties, false, false, graphHasProvenanceAttributes);
|
|
144
155
|
this.originalGraph = originalGraph;
|
|
145
156
|
this.debugPrint = debugPrint;
|
|
146
|
-
this.reconstitutedTypes = new Map();
|
|
147
|
-
this._lostTypeAttributes = false;
|
|
148
|
-
this._printIndent = 0;
|
|
149
157
|
}
|
|
150
158
|
withForwardingRef(maybeForwardingRef, typeCreator) {
|
|
151
159
|
if (maybeForwardingRef !== undefined) {
|
|
@@ -153,7 +161,7 @@ class BaseGraphRewriteBuilder extends TypeBuilder_1.TypeBuilder {
|
|
|
153
161
|
}
|
|
154
162
|
const forwardingRef = this.reserveTypeRef();
|
|
155
163
|
const actualRef = typeCreator(forwardingRef);
|
|
156
|
-
Support_1.assert(actualRef === forwardingRef, "Type creator didn't return its forwarding ref");
|
|
164
|
+
(0, Support_1.assert)(actualRef === forwardingRef, "Type creator didn't return its forwarding ref");
|
|
157
165
|
return actualRef;
|
|
158
166
|
}
|
|
159
167
|
reconstituteType(t, attributes, forwardingRef) {
|
|
@@ -170,22 +178,22 @@ class BaseGraphRewriteBuilder extends TypeBuilder_1.TypeBuilder {
|
|
|
170
178
|
return this.forceReconstituteTypeRef(originalRef, attributes, maybeForwardingRef);
|
|
171
179
|
}
|
|
172
180
|
reconstituteTypeAttributes(attributes) {
|
|
173
|
-
return collection_utils_1.mapMap(attributes, (v, a) => a.reconstitute(this, v));
|
|
181
|
+
return (0, collection_utils_1.mapMap)(attributes, (v, a) => a.reconstitute(this, v));
|
|
174
182
|
}
|
|
175
183
|
assertTypeRefsToReconstitute(typeRefs, forwardingRef) {
|
|
176
|
-
Support_1.assert(typeRefs.length > 0, "Must have at least one type to reconstitute");
|
|
184
|
+
(0, Support_1.assert)(typeRefs.length > 0, "Must have at least one type to reconstitute");
|
|
177
185
|
for (const originalRef of typeRefs) {
|
|
178
|
-
TypeGraph_1.assertTypeRefGraph(originalRef, this.originalGraph);
|
|
186
|
+
(0, TypeGraph_1.assertTypeRefGraph)(originalRef, this.originalGraph);
|
|
179
187
|
}
|
|
180
188
|
if (forwardingRef !== undefined) {
|
|
181
|
-
TypeGraph_1.assertTypeRefGraph(forwardingRef, this.typeGraph);
|
|
189
|
+
(0, TypeGraph_1.assertTypeRefGraph)(forwardingRef, this.typeGraph);
|
|
182
190
|
}
|
|
183
191
|
}
|
|
184
192
|
changeDebugPrintIndent(delta) {
|
|
185
193
|
this._printIndent += delta;
|
|
186
194
|
}
|
|
187
195
|
get debugPrintIndentation() {
|
|
188
|
-
return Support_1.indentationString(this._printIndent);
|
|
196
|
+
return (0, Support_1.indentationString)(this._printIndent);
|
|
189
197
|
}
|
|
190
198
|
finish() {
|
|
191
199
|
for (const [name, t] of this.originalGraph.topLevels) {
|
|
@@ -202,10 +210,11 @@ class BaseGraphRewriteBuilder extends TypeBuilder_1.TypeBuilder {
|
|
|
202
210
|
}
|
|
203
211
|
exports.BaseGraphRewriteBuilder = BaseGraphRewriteBuilder;
|
|
204
212
|
class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
213
|
+
_map;
|
|
214
|
+
_attributeSources = new Map();
|
|
205
215
|
constructor(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, _map, debugPrintRemapping) {
|
|
206
216
|
super(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, debugPrintRemapping);
|
|
207
217
|
this._map = _map;
|
|
208
|
-
this._attributeSources = new Map();
|
|
209
218
|
for (const [source, target] of _map) {
|
|
210
219
|
let maybeSources = this._attributeSources.get(target);
|
|
211
220
|
if (maybeSources === undefined) {
|
|
@@ -219,23 +228,23 @@ class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
|
219
228
|
return undefined;
|
|
220
229
|
}
|
|
221
230
|
getMapTarget(tref) {
|
|
222
|
-
const maybeType = this._map.get(TypeGraph_1.derefTypeRef(tref, this.originalGraph));
|
|
231
|
+
const maybeType = this._map.get((0, TypeGraph_1.derefTypeRef)(tref, this.originalGraph));
|
|
223
232
|
if (maybeType === undefined)
|
|
224
233
|
return tref;
|
|
225
|
-
Support_1.assert(this._map.get(maybeType) === undefined, "We have a type that's remapped to a remapped type");
|
|
234
|
+
(0, Support_1.assert)(this._map.get(maybeType) === undefined, "We have a type that's remapped to a remapped type");
|
|
226
235
|
return maybeType.typeRef;
|
|
227
236
|
}
|
|
228
237
|
addForwardingIntersection(_forwardingRef, _tref) {
|
|
229
|
-
return Support_1.panic("We can't add forwarding intersections when we're removing forwarding intersections");
|
|
238
|
+
return (0, Support_1.panic)("We can't add forwarding intersections when we're removing forwarding intersections");
|
|
230
239
|
}
|
|
231
240
|
lookupTypeRefs(typeRefs, forwardingRef) {
|
|
232
|
-
Support_1.assert(forwardingRef === undefined, "We can't have a forwarding ref when we remap");
|
|
241
|
+
(0, Support_1.assert)(forwardingRef === undefined, "We can't have a forwarding ref when we remap");
|
|
233
242
|
this.assertTypeRefsToReconstitute(typeRefs, forwardingRef);
|
|
234
|
-
const first = this.reconstitutedTypes.get(TypeGraph_1.typeRefIndex(this.getMapTarget(typeRefs[0])));
|
|
243
|
+
const first = this.reconstitutedTypes.get((0, TypeGraph_1.typeRefIndex)(this.getMapTarget(typeRefs[0])));
|
|
235
244
|
if (first === undefined)
|
|
236
245
|
return undefined;
|
|
237
246
|
for (let i = 1; i < typeRefs.length; i++) {
|
|
238
|
-
const other = this.reconstitutedTypes.get(TypeGraph_1.typeRefIndex(this.getMapTarget(typeRefs[i])));
|
|
247
|
+
const other = this.reconstitutedTypes.get((0, TypeGraph_1.typeRefIndex)(this.getMapTarget(typeRefs[i])));
|
|
239
248
|
if (first !== other)
|
|
240
249
|
return undefined;
|
|
241
250
|
}
|
|
@@ -243,32 +252,32 @@ class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
|
243
252
|
}
|
|
244
253
|
forceReconstituteTypeRef(originalRef, attributes, maybeForwardingRef) {
|
|
245
254
|
originalRef = this.getMapTarget(originalRef);
|
|
246
|
-
const index = TypeGraph_1.typeRefIndex(originalRef);
|
|
247
|
-
Support_1.assert(this.reconstitutedTypes.get(index) === undefined, "Type has already been reconstituted");
|
|
248
|
-
Support_1.assert(maybeForwardingRef === undefined, "We can't have a forwarding ref when we remap");
|
|
255
|
+
const index = (0, TypeGraph_1.typeRefIndex)(originalRef);
|
|
256
|
+
(0, Support_1.assert)(this.reconstitutedTypes.get(index) === undefined, "Type has already been reconstituted");
|
|
257
|
+
(0, Support_1.assert)(maybeForwardingRef === undefined, "We can't have a forwarding ref when we remap");
|
|
249
258
|
return this.withForwardingRef(undefined, forwardingRef => {
|
|
250
259
|
this.reconstitutedTypes.set(index, forwardingRef);
|
|
251
260
|
if (this.debugPrint) {
|
|
252
|
-
console.log(`${this.debugPrintIndentation}reconstituting ${index} as ${TypeGraph_1.typeRefIndex(forwardingRef)}`);
|
|
261
|
+
console.log(`${this.debugPrintIndentation}reconstituting ${index} as ${(0, TypeGraph_1.typeRefIndex)(forwardingRef)}`);
|
|
253
262
|
this.changeDebugPrintIndent(1);
|
|
254
263
|
}
|
|
255
|
-
const [originalType, originalAttributes] = TypeGraph_1.typeAndAttributesForTypeRef(originalRef, this.originalGraph);
|
|
264
|
+
const [originalType, originalAttributes] = (0, TypeGraph_1.typeAndAttributesForTypeRef)(originalRef, this.originalGraph);
|
|
256
265
|
const attributeSources = this._attributeSources.get(originalType);
|
|
257
266
|
if (attributes === undefined) {
|
|
258
267
|
attributes = TypeAttributes_1.emptyTypeAttributes;
|
|
259
268
|
}
|
|
260
269
|
if (attributeSources === undefined) {
|
|
261
|
-
attributes = TypeAttributes_1.combineTypeAttributes("union", attributes, this.reconstituteTypeAttributes(originalAttributes));
|
|
270
|
+
attributes = (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, this.reconstituteTypeAttributes(originalAttributes));
|
|
262
271
|
}
|
|
263
272
|
else {
|
|
264
|
-
attributes = TypeAttributes_1.combineTypeAttributes("union", attributes, this.reconstituteTypeAttributes(TypeUtils_1.combineTypeAttributesOfTypes("union", attributeSources)));
|
|
273
|
+
attributes = (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, this.reconstituteTypeAttributes((0, TypeUtils_1.combineTypeAttributesOfTypes)("union", attributeSources)));
|
|
265
274
|
}
|
|
266
275
|
const newAttributes = attributes;
|
|
267
276
|
const reconstituter = new TypeReconstituter(this, this.canonicalOrder, newAttributes, forwardingRef, tref => {
|
|
268
|
-
Support_1.assert(tref === forwardingRef, "Reconstituted type as a different ref");
|
|
277
|
+
(0, Support_1.assert)(tref === forwardingRef, "Reconstituted type as a different ref");
|
|
269
278
|
if (this.debugPrint) {
|
|
270
279
|
this.changeDebugPrintIndent(-1);
|
|
271
|
-
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${TypeGraph_1.typeRefIndex(tref)}`);
|
|
280
|
+
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${(0, TypeGraph_1.typeRefIndex)(tref)}`);
|
|
272
281
|
}
|
|
273
282
|
});
|
|
274
283
|
originalType.reconstitute(reconstituter, this.canonicalOrder);
|
|
@@ -278,23 +287,25 @@ class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
|
278
287
|
}
|
|
279
288
|
exports.GraphRemapBuilder = GraphRemapBuilder;
|
|
280
289
|
class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
290
|
+
_replacer;
|
|
291
|
+
_setsToReplaceByMember;
|
|
292
|
+
_reconstitutedUnions = new collection_utils_1.EqualityMap();
|
|
281
293
|
constructor(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, setsToReplace, debugPrintReconstitution, _replacer) {
|
|
282
294
|
super(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, debugPrintReconstitution);
|
|
283
295
|
this._replacer = _replacer;
|
|
284
|
-
this._reconstitutedUnions = new collection_utils_1.EqualityMap();
|
|
285
296
|
this._setsToReplaceByMember = new Map();
|
|
286
297
|
for (const types of setsToReplace) {
|
|
287
298
|
const set = new Set(types);
|
|
288
299
|
for (const t of set) {
|
|
289
300
|
const index = t.index;
|
|
290
|
-
Support_1.assert(!this._setsToReplaceByMember.has(index), "A type is member of more than one set to be replaced");
|
|
301
|
+
(0, Support_1.assert)(!this._setsToReplaceByMember.has(index), "A type is member of more than one set to be replaced");
|
|
291
302
|
this._setsToReplaceByMember.set(index, set);
|
|
292
303
|
}
|
|
293
304
|
}
|
|
294
305
|
}
|
|
295
306
|
registerUnion(typeRefs, reconstituted) {
|
|
296
307
|
const set = new Set(typeRefs);
|
|
297
|
-
Support_1.assert(!this._reconstitutedUnions.has(set), "Cannot register reconstituted set twice");
|
|
308
|
+
(0, Support_1.assert)(!this._reconstitutedUnions.has(set), "Cannot register reconstituted set twice");
|
|
298
309
|
this._reconstitutedUnions.set(set, reconstituted);
|
|
299
310
|
}
|
|
300
311
|
replaceSet(typesToReplace, maybeForwardingRef) {
|
|
@@ -302,29 +313,29 @@ class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
|
302
313
|
if (this.debugPrint) {
|
|
303
314
|
console.log(`${this.debugPrintIndentation}replacing set ${Array.from(typesToReplace)
|
|
304
315
|
.map(t => t.index.toString())
|
|
305
|
-
.join(",")} as ${TypeGraph_1.typeRefIndex(forwardingRef)}`);
|
|
316
|
+
.join(",")} as ${(0, TypeGraph_1.typeRefIndex)(forwardingRef)}`);
|
|
306
317
|
this.changeDebugPrintIndent(1);
|
|
307
318
|
}
|
|
308
319
|
for (const t of typesToReplace) {
|
|
309
320
|
const originalRef = t.typeRef;
|
|
310
|
-
const index = TypeGraph_1.typeRefIndex(originalRef);
|
|
321
|
+
const index = (0, TypeGraph_1.typeRefIndex)(originalRef);
|
|
311
322
|
this.reconstitutedTypes.set(index, forwardingRef);
|
|
312
323
|
this._setsToReplaceByMember.delete(index);
|
|
313
324
|
}
|
|
314
325
|
const result = this._replacer(typesToReplace, this, forwardingRef);
|
|
315
|
-
Support_1.assert(result === forwardingRef, "The forwarding ref got lost when replacing");
|
|
326
|
+
(0, Support_1.assert)(result === forwardingRef, "The forwarding ref got lost when replacing");
|
|
316
327
|
if (this.debugPrint) {
|
|
317
328
|
this.changeDebugPrintIndent(-1);
|
|
318
329
|
console.log(`${this.debugPrintIndentation}replaced set ${Array.from(typesToReplace)
|
|
319
330
|
.map(t => t.index.toString())
|
|
320
|
-
.join(",")} as ${TypeGraph_1.typeRefIndex(forwardingRef)}`);
|
|
331
|
+
.join(",")} as ${(0, TypeGraph_1.typeRefIndex)(forwardingRef)}`);
|
|
321
332
|
}
|
|
322
333
|
return result;
|
|
323
334
|
});
|
|
324
335
|
}
|
|
325
336
|
forceReconstituteTypeRef(originalRef, attributes, maybeForwardingRef) {
|
|
326
|
-
const [originalType, originalAttributes] = TypeGraph_1.typeAndAttributesForTypeRef(originalRef, this.originalGraph);
|
|
327
|
-
const index = TypeGraph_1.typeRefIndex(originalRef);
|
|
337
|
+
const [originalType, originalAttributes] = (0, TypeGraph_1.typeAndAttributesForTypeRef)(originalRef, this.originalGraph);
|
|
338
|
+
const index = (0, TypeGraph_1.typeRefIndex)(originalRef);
|
|
328
339
|
if (this.debugPrint) {
|
|
329
340
|
console.log(`${this.debugPrintIndentation}reconstituting ${index}`);
|
|
330
341
|
this.changeDebugPrintIndent(1);
|
|
@@ -333,22 +344,22 @@ class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
|
333
344
|
attributes = this.reconstituteTypeAttributes(originalAttributes);
|
|
334
345
|
}
|
|
335
346
|
else {
|
|
336
|
-
attributes = TypeAttributes_1.combineTypeAttributes("union", attributes, this.reconstituteTypeAttributes(originalAttributes));
|
|
347
|
+
attributes = (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, this.reconstituteTypeAttributes(originalAttributes));
|
|
337
348
|
}
|
|
338
349
|
const reconstituter = new TypeReconstituter(this, this.canonicalOrder, attributes, maybeForwardingRef, tref => {
|
|
339
350
|
if (this.debugPrint) {
|
|
340
351
|
this.changeDebugPrintIndent(-1);
|
|
341
|
-
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${TypeGraph_1.typeRefIndex(tref)}`);
|
|
352
|
+
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${(0, TypeGraph_1.typeRefIndex)(tref)}`);
|
|
342
353
|
}
|
|
343
354
|
if (maybeForwardingRef !== undefined) {
|
|
344
|
-
Support_1.assert(tref === maybeForwardingRef, "We didn't pass the forwarding ref");
|
|
355
|
+
(0, Support_1.assert)(tref === maybeForwardingRef, "We didn't pass the forwarding ref");
|
|
345
356
|
}
|
|
346
357
|
const alreadyReconstitutedType = this.reconstitutedTypes.get(index);
|
|
347
358
|
if (alreadyReconstitutedType === undefined) {
|
|
348
359
|
this.reconstitutedTypes.set(index, tref);
|
|
349
360
|
}
|
|
350
361
|
else {
|
|
351
|
-
Support_1.assert(tref === alreadyReconstitutedType, "We reconstituted a type twice differently");
|
|
362
|
+
(0, Support_1.assert)(tref === alreadyReconstitutedType, "We reconstituted a type twice differently");
|
|
352
363
|
}
|
|
353
364
|
});
|
|
354
365
|
originalType.reconstitute(reconstituter, this.canonicalOrder);
|
|
@@ -373,11 +384,11 @@ class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
|
373
384
|
this.assertTypeRefsToReconstitute(typeRefs, forwardingRef);
|
|
374
385
|
// Check whether we have already reconstituted them. That means ensuring
|
|
375
386
|
// that they all have the same target type.
|
|
376
|
-
let maybeRef = this.reconstitutedTypes.get(TypeGraph_1.typeRefIndex(typeRefs[0]));
|
|
387
|
+
let maybeRef = this.reconstitutedTypes.get((0, TypeGraph_1.typeRefIndex)(typeRefs[0]));
|
|
377
388
|
if (maybeRef !== undefined && maybeRef !== forwardingRef) {
|
|
378
389
|
let allEqual = true;
|
|
379
390
|
for (let i = 1; i < typeRefs.length; i++) {
|
|
380
|
-
if (this.reconstitutedTypes.get(TypeGraph_1.typeRefIndex(typeRefs[i])) !== maybeRef) {
|
|
391
|
+
if (this.reconstitutedTypes.get((0, TypeGraph_1.typeRefIndex)(typeRefs[i])) !== maybeRef) {
|
|
381
392
|
allEqual = false;
|
|
382
393
|
break;
|
|
383
394
|
}
|
|
@@ -392,12 +403,12 @@ class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
|
392
403
|
return this.forwardIfNecessary(forwardingRef, maybeRef);
|
|
393
404
|
}
|
|
394
405
|
// Is this set requested to be replaced? If not, we're out of options.
|
|
395
|
-
const maybeSet = this._setsToReplaceByMember.get(TypeGraph_1.typeRefIndex(typeRefs[0]));
|
|
406
|
+
const maybeSet = this._setsToReplaceByMember.get((0, TypeGraph_1.typeRefIndex)(typeRefs[0]));
|
|
396
407
|
if (maybeSet === undefined) {
|
|
397
408
|
return undefined;
|
|
398
409
|
}
|
|
399
410
|
for (let i = 1; i < typeRefs.length; i++) {
|
|
400
|
-
if (this._setsToReplaceByMember.get(TypeGraph_1.typeRefIndex(typeRefs[i])) !== maybeSet) {
|
|
411
|
+
if (this._setsToReplaceByMember.get((0, TypeGraph_1.typeRefIndex)(typeRefs[i])) !== maybeSet) {
|
|
401
412
|
return undefined;
|
|
402
413
|
}
|
|
403
414
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeTransformations = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const TypeGraph_1 = require("./TypeGraph");
|
|
5
6
|
const Type_1 = require("./Type");
|
|
@@ -11,7 +12,7 @@ const Constraints_1 = require("./attributes/Constraints");
|
|
|
11
12
|
function transformationAttributes(graph, reconstitutedTargetType, transformer, debugPrintTransformations) {
|
|
12
13
|
const transformation = new Transformers_1.Transformation(graph, reconstitutedTargetType, transformer);
|
|
13
14
|
if (debugPrintTransformations) {
|
|
14
|
-
console.log(`transformation for ${TypeGraph_1.typeRefIndex(reconstitutedTargetType)}:`);
|
|
15
|
+
console.log(`transformation for ${(0, TypeGraph_1.typeRefIndex)(reconstitutedTargetType)}:`);
|
|
15
16
|
transformation.debugPrint();
|
|
16
17
|
console.log(`reverse:`);
|
|
17
18
|
transformation.reverse.debugPrint();
|
|
@@ -25,18 +26,18 @@ function makeEnumTransformer(graph, enumType, stringType, continuation) {
|
|
|
25
26
|
}
|
|
26
27
|
function replaceUnion(union, builder, forwardingRef, transformedTypes, debugPrintTransformations) {
|
|
27
28
|
const graph = builder.typeGraph;
|
|
28
|
-
Support_1.assert(union.members.size > 0, "We can't have empty unions");
|
|
29
|
+
(0, Support_1.assert)(union.members.size > 0, "We can't have empty unions");
|
|
29
30
|
// Type attributes that we lost during reconstitution.
|
|
30
31
|
let additionalAttributes = TypeAttributes_1.emptyTypeAttributes;
|
|
31
32
|
function reconstituteMember(t) {
|
|
32
33
|
// Special handling for some transformed string type kinds: The type in
|
|
33
34
|
// the union must be the target type, so if one already exists, use that
|
|
34
35
|
// one, otherwise make a new one.
|
|
35
|
-
if (Type_1.isPrimitiveStringTypeKind(t.kind)) {
|
|
36
|
-
const targetTypeKind = Type_1.targetTypeKindForTransformedStringTypeKind(t.kind);
|
|
36
|
+
if ((0, Type_1.isPrimitiveStringTypeKind)(t.kind)) {
|
|
37
|
+
const targetTypeKind = (0, Type_1.targetTypeKindForTransformedStringTypeKind)(t.kind);
|
|
37
38
|
if (targetTypeKind !== undefined) {
|
|
38
39
|
const targetTypeMember = union.findMember(targetTypeKind);
|
|
39
|
-
additionalAttributes = TypeAttributes_1.combineTypeAttributes("union", additionalAttributes, t.getAttributes());
|
|
40
|
+
additionalAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", additionalAttributes, t.getAttributes());
|
|
40
41
|
if (targetTypeMember !== undefined) {
|
|
41
42
|
return builder.reconstituteType(targetTypeMember);
|
|
42
43
|
}
|
|
@@ -45,7 +46,7 @@ function replaceUnion(union, builder, forwardingRef, transformedTypes, debugPrin
|
|
|
45
46
|
}
|
|
46
47
|
return builder.reconstituteType(t);
|
|
47
48
|
}
|
|
48
|
-
const reconstitutedMembersByKind = collection_utils_1.mapMapEntries(union.members.entries(), m => [m.kind, reconstituteMember(m)]);
|
|
49
|
+
const reconstitutedMembersByKind = (0, collection_utils_1.mapMapEntries)(union.members.entries(), m => [m.kind, reconstituteMember(m)]);
|
|
49
50
|
const reconstitutedMemberSet = new Set(reconstitutedMembersByKind.values());
|
|
50
51
|
const haveUnion = reconstitutedMemberSet.size > 1;
|
|
51
52
|
if (!haveUnion) {
|
|
@@ -53,9 +54,9 @@ function replaceUnion(union, builder, forwardingRef, transformedTypes, debugPrin
|
|
|
53
54
|
}
|
|
54
55
|
const reconstitutedTargetType = haveUnion
|
|
55
56
|
? builder.getUnionType(union.getAttributes(), reconstitutedMemberSet)
|
|
56
|
-
: Support_1.defined(collection_utils_1.iterableFirst(reconstitutedMemberSet));
|
|
57
|
+
: (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(reconstitutedMemberSet));
|
|
57
58
|
function memberForKind(kind) {
|
|
58
|
-
return Support_1.defined(reconstitutedMembersByKind.get(kind));
|
|
59
|
+
return (0, Support_1.defined)(reconstitutedMembersByKind.get(kind));
|
|
59
60
|
}
|
|
60
61
|
function consumer(memberTypeRef) {
|
|
61
62
|
if (!haveUnion)
|
|
@@ -79,7 +80,7 @@ function replaceUnion(union, builder, forwardingRef, transformedTypes, debugPrin
|
|
|
79
80
|
function transformerForStringType(t) {
|
|
80
81
|
const memberRef = memberForKind(t.kind);
|
|
81
82
|
if (t.kind === "string") {
|
|
82
|
-
const minMax = Constraints_1.minMaxLengthForType(t);
|
|
83
|
+
const minMax = (0, Constraints_1.minMaxLengthForType)(t);
|
|
83
84
|
if (minMax === undefined) {
|
|
84
85
|
return consumer(memberRef);
|
|
85
86
|
}
|
|
@@ -93,7 +94,7 @@ function replaceUnion(union, builder, forwardingRef, transformedTypes, debugPrin
|
|
|
93
94
|
return new Transformers_1.ParseStringTransformer(graph, getStringType(), consumer(memberRef));
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
|
-
const stringTypes = collection_utils_1.arraySortByInto(Array.from(union.stringTypeMembers), t => t.kind);
|
|
97
|
+
const stringTypes = (0, collection_utils_1.arraySortByInto)(Array.from(union.stringTypeMembers), t => t.kind);
|
|
97
98
|
let transformerForString;
|
|
98
99
|
if (stringTypes.length === 0) {
|
|
99
100
|
transformerForString = undefined;
|
|
@@ -103,15 +104,15 @@ function replaceUnion(union, builder, forwardingRef, transformedTypes, debugPrin
|
|
|
103
104
|
transformerForString = new Transformers_1.DecodingTransformer(graph, getStringType(), transformerForStringType(t));
|
|
104
105
|
}
|
|
105
106
|
else {
|
|
106
|
-
transformerForString = new Transformers_1.DecodingTransformer(graph, getStringType(), new Transformers_1.ChoiceTransformer(graph, getStringType(), stringTypes.map(t => Support_1.defined(transformerForStringType(t)))));
|
|
107
|
+
transformerForString = new Transformers_1.DecodingTransformer(graph, getStringType(), new Transformers_1.ChoiceTransformer(graph, getStringType(), stringTypes.map(t => (0, Support_1.defined)(transformerForStringType(t)))));
|
|
107
108
|
}
|
|
108
109
|
const transformerForClass = transformerForKind("class");
|
|
109
110
|
const transformerForMap = transformerForKind("map");
|
|
110
|
-
Support_1.assert(transformerForClass === undefined || transformerForMap === undefined, "Can't have both class and map in a transformed union");
|
|
111
|
+
(0, Support_1.assert)(transformerForClass === undefined || transformerForMap === undefined, "Can't have both class and map in a transformed union");
|
|
111
112
|
const transformerForObject = transformerForClass !== undefined ? transformerForClass : transformerForMap;
|
|
112
113
|
const transformer = new Transformers_1.DecodingChoiceTransformer(graph, builder.getPrimitiveType("any"), transformerForKind("null"), transformerForKind("integer"), transformerForKind("double"), transformerForKind("bool"), transformerForString, transformerForKind("array"), transformerForObject);
|
|
113
114
|
const attributes = transformationAttributes(graph, reconstitutedTargetType, transformer, debugPrintTransformations);
|
|
114
|
-
return builder.getPrimitiveType("any", TypeAttributes_1.combineTypeAttributes("union", attributes, additionalAttributes), forwardingRef);
|
|
115
|
+
return builder.getPrimitiveType("any", (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, additionalAttributes), forwardingRef);
|
|
115
116
|
}
|
|
116
117
|
function replaceArray(arrayType, builder, forwardingRef, debugPrintTransformations) {
|
|
117
118
|
const anyType = builder.getPrimitiveType("any");
|
|
@@ -131,14 +132,14 @@ function replaceEnum(enumType, builder, forwardingRef, debugPrintTransformations
|
|
|
131
132
|
}
|
|
132
133
|
function replaceNumber(t, builder, forwardingRef, debugPrintTransformations) {
|
|
133
134
|
const stringType = builder.getStringType(TypeAttributes_1.emptyTypeAttributes, StringTypes_1.StringTypes.unrestricted);
|
|
134
|
-
const [min, max] = Support_1.defined(Constraints_1.minMaxValueForType(t));
|
|
135
|
+
const [min, max] = (0, Support_1.defined)((0, Constraints_1.minMaxValueForType)(t));
|
|
135
136
|
const transformer = new Transformers_1.DecodingTransformer(builder.typeGraph, stringType, new Transformers_1.MinMaxValueTransformer(builder.typeGraph, stringType, undefined, min, max));
|
|
136
137
|
const reconstitutedAttributes = builder.reconstituteTypeAttributes(t.getAttributes());
|
|
137
138
|
const attributes = transformationAttributes(builder.typeGraph, builder.getPrimitiveType("double", reconstitutedAttributes, undefined), transformer, debugPrintTransformations);
|
|
138
139
|
return builder.getPrimitiveType("double", attributes, forwardingRef);
|
|
139
140
|
}
|
|
140
141
|
function replaceString(t, builder, forwardingRef, debugPrintTransformations) {
|
|
141
|
-
const [min, max] = Support_1.defined(Constraints_1.minMaxLengthForType(t));
|
|
142
|
+
const [min, max] = (0, Support_1.defined)((0, Constraints_1.minMaxLengthForType)(t));
|
|
142
143
|
const reconstitutedAttributes = builder.reconstituteTypeAttributes(t.getAttributes());
|
|
143
144
|
const stringType = builder.getStringType(TypeAttributes_1.emptyTypeAttributes, StringTypes_1.StringTypes.unrestricted);
|
|
144
145
|
const transformer = new Transformers_1.DecodingTransformer(builder.typeGraph, stringType, new Transformers_1.MinMaxLengthCheckTransformer(builder.typeGraph, stringType, undefined, min, max));
|
|
@@ -147,14 +148,14 @@ function replaceString(t, builder, forwardingRef, debugPrintTransformations) {
|
|
|
147
148
|
}
|
|
148
149
|
function replaceTransformedStringType(t, kind, builder, forwardingRef, debugPrintTransformations) {
|
|
149
150
|
const reconstitutedAttributes = builder.reconstituteTypeAttributes(t.getAttributes());
|
|
150
|
-
const targetTypeKind = collection_utils_1.withDefault(Type_1.targetTypeKindForTransformedStringTypeKind(kind), kind);
|
|
151
|
+
const targetTypeKind = (0, collection_utils_1.withDefault)((0, Type_1.targetTypeKindForTransformedStringTypeKind)(kind), kind);
|
|
151
152
|
const stringType = builder.getStringType(TypeAttributes_1.emptyTypeAttributes, StringTypes_1.StringTypes.unrestricted);
|
|
152
153
|
const transformer = new Transformers_1.DecodingTransformer(builder.typeGraph, stringType, new Transformers_1.ParseStringTransformer(builder.typeGraph, stringType, undefined));
|
|
153
154
|
const attributes = transformationAttributes(builder.typeGraph, builder.getPrimitiveType(targetTypeKind, reconstitutedAttributes), transformer, debugPrintTransformations);
|
|
154
155
|
return builder.getStringType(attributes, StringTypes_1.StringTypes.unrestricted, forwardingRef);
|
|
155
156
|
}
|
|
156
157
|
function makeTransformations(ctx, graph, targetLanguage) {
|
|
157
|
-
const transformedTypes = collection_utils_1.setFilter(graph.allTypesUnordered(), t => {
|
|
158
|
+
const transformedTypes = (0, collection_utils_1.setFilter)(graph.allTypesUnordered(), t => {
|
|
158
159
|
if (targetLanguage.needsTransformerForType(t))
|
|
159
160
|
return true;
|
|
160
161
|
if (!(t instanceof Type_1.UnionType))
|
|
@@ -162,10 +163,10 @@ function makeTransformations(ctx, graph, targetLanguage) {
|
|
|
162
163
|
const stringMembers = t.stringTypeMembers;
|
|
163
164
|
if (stringMembers.size <= 1)
|
|
164
165
|
return false;
|
|
165
|
-
return collection_utils_1.iterableSome(stringMembers, m => targetLanguage.needsTransformerForType(m));
|
|
166
|
+
return (0, collection_utils_1.iterableSome)(stringMembers, m => targetLanguage.needsTransformerForType(m));
|
|
166
167
|
});
|
|
167
168
|
function replace(setOfOneUnion, builder, forwardingRef) {
|
|
168
|
-
const t = Support_1.defined(collection_utils_1.iterableFirst(setOfOneUnion));
|
|
169
|
+
const t = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(setOfOneUnion));
|
|
169
170
|
if (t instanceof Type_1.UnionType) {
|
|
170
171
|
return replaceUnion(t, builder, forwardingRef, transformedTypes, ctx.debugPrintTransformations);
|
|
171
172
|
}
|
|
@@ -178,13 +179,13 @@ function makeTransformations(ctx, graph, targetLanguage) {
|
|
|
178
179
|
if (t.kind === "string") {
|
|
179
180
|
return replaceString(t, builder, forwardingRef, ctx.debugPrintTransformations);
|
|
180
181
|
}
|
|
181
|
-
if (Type_1.isNumberTypeKind(t.kind)) {
|
|
182
|
+
if ((0, Type_1.isNumberTypeKind)(t.kind)) {
|
|
182
183
|
return replaceNumber(t, builder, forwardingRef, ctx.debugPrintTransformations);
|
|
183
184
|
}
|
|
184
|
-
if (Type_1.isPrimitiveStringTypeKind(t.kind)) {
|
|
185
|
+
if ((0, Type_1.isPrimitiveStringTypeKind)(t.kind)) {
|
|
185
186
|
return replaceTransformedStringType(t, t.kind, builder, forwardingRef, ctx.debugPrintTransformations);
|
|
186
187
|
}
|
|
187
|
-
return Support_1.panic(`Cannot make transformation for type ${t.kind}`);
|
|
188
|
+
return (0, Support_1.panic)(`Cannot make transformation for type ${t.kind}`);
|
|
188
189
|
}
|
|
189
190
|
const groups = Array.from(transformedTypes).map(t => [t]);
|
|
190
191
|
return graph.rewrite("make-transformations", ctx.stringTypeMapping, false, groups, ctx.debugPrintReconstitution, replace);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type SubTrie = number | null | Trie;
|
|
2
|
+
export type Trie = {
|
|
3
3
|
count: number;
|
|
4
4
|
arr: SubTrie[];
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type MarkovChain = {
|
|
7
7
|
trie: Trie;
|
|
8
8
|
depth: number;
|
|
9
9
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.test = exports.generate = exports.evaluate = exports.evaluateFull = exports.load = exports.train = void 0;
|
|
3
4
|
const Support_1 = require("./support/Support");
|
|
4
5
|
const EncodedMarkovChain_1 = require("./EncodedMarkovChain");
|
|
5
6
|
function makeTrie() {
|
|
@@ -35,14 +36,14 @@ function increment(t, seq, i) {
|
|
|
35
36
|
}
|
|
36
37
|
if (i >= seq.length - 1) {
|
|
37
38
|
if (typeof t !== "object") {
|
|
38
|
-
return Support_1.panic("Malformed trie");
|
|
39
|
+
return (0, Support_1.panic)("Malformed trie");
|
|
39
40
|
}
|
|
40
41
|
let n = t.arr[first];
|
|
41
42
|
if (n === null) {
|
|
42
43
|
n = 0;
|
|
43
44
|
}
|
|
44
45
|
else if (typeof n === "object") {
|
|
45
|
-
return Support_1.panic("Malformed trie");
|
|
46
|
+
return (0, Support_1.panic)("Malformed trie");
|
|
46
47
|
}
|
|
47
48
|
t.arr[first] = n + 1;
|
|
48
49
|
t.count += 1;
|
|
@@ -53,7 +54,7 @@ function increment(t, seq, i) {
|
|
|
53
54
|
t.arr[first] = st = makeTrie();
|
|
54
55
|
}
|
|
55
56
|
if (typeof st !== "object") {
|
|
56
|
-
return Support_1.panic("Malformed trie");
|
|
57
|
+
return (0, Support_1.panic)("Malformed trie");
|
|
57
58
|
}
|
|
58
59
|
return increment(st, seq, i + 1);
|
|
59
60
|
}
|
|
@@ -68,7 +69,7 @@ function train(lines, depth) {
|
|
|
68
69
|
}
|
|
69
70
|
exports.train = train;
|
|
70
71
|
function load() {
|
|
71
|
-
return JSON.parse(Support_1.inflateBase64(EncodedMarkovChain_1.encodedMarkovChain));
|
|
72
|
+
return JSON.parse((0, Support_1.inflateBase64)(EncodedMarkovChain_1.encodedMarkovChain));
|
|
72
73
|
}
|
|
73
74
|
exports.load = load;
|
|
74
75
|
function evaluateFull(mc, word) {
|
|
@@ -81,7 +82,7 @@ function evaluateFull(mc, word) {
|
|
|
81
82
|
for (let i = depth; i <= word.length; i++) {
|
|
82
83
|
let cp = lookup(trie, word.slice(i - depth, i), 0);
|
|
83
84
|
if (typeof cp === "object") {
|
|
84
|
-
return Support_1.panic("Did we mess up the depth?");
|
|
85
|
+
return (0, Support_1.panic)("Did we mess up the depth?");
|
|
85
86
|
}
|
|
86
87
|
if (cp === undefined) {
|
|
87
88
|
cp = 0.0001;
|
|
@@ -101,10 +102,10 @@ function randomInt(lower, upper) {
|
|
|
101
102
|
return lower + Math.floor(Math.random() * range);
|
|
102
103
|
}
|
|
103
104
|
function generate(mc, state, unseenWeight) {
|
|
104
|
-
Support_1.assert(state.length === mc.depth - 1, "State and chain length don't match up");
|
|
105
|
+
(0, Support_1.assert)(state.length === mc.depth - 1, "State and chain length don't match up");
|
|
105
106
|
const t = lookup(mc.trie, state, 0);
|
|
106
107
|
if (typeof t === "number") {
|
|
107
|
-
return Support_1.panic("Wrong depth?");
|
|
108
|
+
return (0, Support_1.panic)("Wrong depth?");
|
|
108
109
|
}
|
|
109
110
|
if (t === undefined) {
|
|
110
111
|
return String.fromCharCode(randomInt(32, 127));
|
|
@@ -122,7 +123,7 @@ function generate(mc, state, unseenWeight) {
|
|
|
122
123
|
return String.fromCharCode(i);
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
|
-
return Support_1.panic("We screwed up bookkeeping, or randomInt");
|
|
126
|
+
return (0, Support_1.panic)("We screwed up bookkeeping, or randomInt");
|
|
126
127
|
}
|
|
127
128
|
exports.generate = generate;
|
|
128
129
|
function testWord(mc, word) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StringMap } from "./support/Support";
|
|
2
2
|
import { Ref } from "./input/JSONSchemaInput";
|
|
3
|
-
export
|
|
3
|
+
export type ErrorProperties = {
|
|
4
4
|
kind: "InternalError";
|
|
5
5
|
properties: {
|
|
6
6
|
message: string;
|
|
@@ -276,10 +276,10 @@ export declare type ErrorProperties = {
|
|
|
276
276
|
message: string;
|
|
277
277
|
};
|
|
278
278
|
};
|
|
279
|
-
export
|
|
279
|
+
export type ErrorKinds = ErrorProperties extends {
|
|
280
280
|
kind: infer K;
|
|
281
281
|
} ? K : never;
|
|
282
|
-
export
|
|
282
|
+
export type ErrorPropertiesForName<K> = Extract<ErrorProperties, {
|
|
283
283
|
kind: K;
|
|
284
284
|
}> extends {
|
|
285
285
|
properties: infer P;
|