quicktype 18.0.5 → 19.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,421 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GraphRewriteBuilder = exports.GraphRemapBuilder = exports.BaseGraphRewriteBuilder = exports.TypeReconstituter = void 0;
|
|
4
|
-
const collection_utils_1 = require("collection-utils");
|
|
5
|
-
const TypeUtils_1 = require("./TypeUtils");
|
|
6
|
-
const TypeGraph_1 = require("./TypeGraph");
|
|
7
|
-
const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
8
|
-
const Support_1 = require("./support/Support");
|
|
9
|
-
const TypeBuilder_1 = require("./TypeBuilder");
|
|
10
|
-
class TypeReconstituter {
|
|
11
|
-
_typeBuilder;
|
|
12
|
-
_makeClassUnique;
|
|
13
|
-
_typeAttributes;
|
|
14
|
-
_forwardingRef;
|
|
15
|
-
_register;
|
|
16
|
-
_wasUsed = false;
|
|
17
|
-
_typeRef = undefined;
|
|
18
|
-
constructor(_typeBuilder, _makeClassUnique, _typeAttributes, _forwardingRef, _register) {
|
|
19
|
-
this._typeBuilder = _typeBuilder;
|
|
20
|
-
this._makeClassUnique = _makeClassUnique;
|
|
21
|
-
this._typeAttributes = _typeAttributes;
|
|
22
|
-
this._forwardingRef = _forwardingRef;
|
|
23
|
-
this._register = _register;
|
|
24
|
-
}
|
|
25
|
-
builderForNewType() {
|
|
26
|
-
(0, Support_1.assert)(!this._wasUsed, "TypeReconstituter used more than once");
|
|
27
|
-
this._wasUsed = true;
|
|
28
|
-
return this._typeBuilder;
|
|
29
|
-
}
|
|
30
|
-
builderForSetting() {
|
|
31
|
-
(0, Support_1.assert)(this._wasUsed && this._typeRef !== undefined, "Can't set type members before constructing a type");
|
|
32
|
-
return this._typeBuilder;
|
|
33
|
-
}
|
|
34
|
-
getResult() {
|
|
35
|
-
if (this._typeRef === undefined) {
|
|
36
|
-
return (0, Support_1.panic)("Type was not reconstituted");
|
|
37
|
-
}
|
|
38
|
-
return this._typeRef;
|
|
39
|
-
}
|
|
40
|
-
// FIXME: Do registration automatically.
|
|
41
|
-
register(tref) {
|
|
42
|
-
(0, Support_1.assert)(this._typeRef === undefined, "Cannot register a type twice");
|
|
43
|
-
this._typeRef = tref;
|
|
44
|
-
this._register(tref);
|
|
45
|
-
}
|
|
46
|
-
registerAndAddAttributes(tref) {
|
|
47
|
-
this._typeBuilder.addAttributes(tref, this._typeAttributes);
|
|
48
|
-
this.register(tref);
|
|
49
|
-
}
|
|
50
|
-
lookup(trefs) {
|
|
51
|
-
(0, Support_1.assert)(!this._wasUsed, "Cannot lookup constituents after building type");
|
|
52
|
-
if ((0, TypeGraph_1.isTypeRef)(trefs)) {
|
|
53
|
-
return this._typeBuilder.lookupTypeRefs([trefs], undefined, false);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const maybeRefs = Array.from(trefs).map(tref => this._typeBuilder.lookupTypeRefs([tref], undefined, false));
|
|
57
|
-
if (maybeRefs.some(tref => tref === undefined))
|
|
58
|
-
return undefined;
|
|
59
|
-
return maybeRefs;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
lookupMap(trefs) {
|
|
63
|
-
const resultValues = this.lookup(trefs.values());
|
|
64
|
-
if (resultValues === undefined)
|
|
65
|
-
return undefined;
|
|
66
|
-
(0, Support_1.assert)(resultValues.length === trefs.size, "Didn't get back the correct number of types");
|
|
67
|
-
const result = new Map();
|
|
68
|
-
let i = 0;
|
|
69
|
-
for (const k of trefs.keys()) {
|
|
70
|
-
result.set(k, resultValues[i]);
|
|
71
|
-
i += 1;
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
reconstitute(trefs) {
|
|
76
|
-
(0, Support_1.assert)(this._wasUsed, "Cannot reconstitute constituents before building type");
|
|
77
|
-
if ((0, TypeGraph_1.isTypeRef)(trefs)) {
|
|
78
|
-
return this._typeBuilder.reconstituteTypeRef(trefs);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
return Array.from(trefs).map(tref => this._typeBuilder.reconstituteTypeRef(tref));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
reconstituteMap(trefs) {
|
|
85
|
-
return (0, collection_utils_1.mapMap)(trefs, tref => this._typeBuilder.reconstituteTypeRef(tref));
|
|
86
|
-
}
|
|
87
|
-
getPrimitiveType(kind) {
|
|
88
|
-
this.register(this.builderForNewType().getPrimitiveType(kind, this._typeAttributes, this._forwardingRef));
|
|
89
|
-
}
|
|
90
|
-
getEnumType(cases) {
|
|
91
|
-
this.register(this.builderForNewType().getEnumType(this._typeAttributes, cases, this._forwardingRef));
|
|
92
|
-
}
|
|
93
|
-
getUniqueMapType() {
|
|
94
|
-
this.registerAndAddAttributes(this.builderForNewType().getUniqueMapType(this._forwardingRef));
|
|
95
|
-
}
|
|
96
|
-
getMapType(values) {
|
|
97
|
-
this.register(this.builderForNewType().getMapType(this._typeAttributes, values, this._forwardingRef));
|
|
98
|
-
}
|
|
99
|
-
getUniqueArrayType() {
|
|
100
|
-
this.registerAndAddAttributes(this.builderForNewType().getUniqueArrayType(this._forwardingRef));
|
|
101
|
-
}
|
|
102
|
-
getArrayType(items) {
|
|
103
|
-
this.register(this.builderForNewType().getArrayType(this._typeAttributes, items, this._forwardingRef));
|
|
104
|
-
}
|
|
105
|
-
setArrayItems(items) {
|
|
106
|
-
this.builderForSetting().setArrayItems(this.getResult(), items);
|
|
107
|
-
}
|
|
108
|
-
makeClassProperty(tref, isOptional) {
|
|
109
|
-
return this._typeBuilder.makeClassProperty(tref, isOptional);
|
|
110
|
-
}
|
|
111
|
-
getObjectType(properties, additionalProperties) {
|
|
112
|
-
this.register(this.builderForNewType().getUniqueObjectType(this._typeAttributes, properties, additionalProperties, this._forwardingRef));
|
|
113
|
-
}
|
|
114
|
-
getUniqueObjectType(properties, additionalProperties) {
|
|
115
|
-
this.register(this.builderForNewType().getUniqueObjectType(this._typeAttributes, properties, additionalProperties, this._forwardingRef));
|
|
116
|
-
}
|
|
117
|
-
getClassType(properties) {
|
|
118
|
-
if (this._makeClassUnique) {
|
|
119
|
-
this.getUniqueClassType(false, properties);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
this.register(this.builderForNewType().getClassType(this._typeAttributes, properties, this._forwardingRef));
|
|
123
|
-
}
|
|
124
|
-
getUniqueClassType(isFixed, properties) {
|
|
125
|
-
this.register(this.builderForNewType().getUniqueClassType(this._typeAttributes, isFixed, properties, this._forwardingRef));
|
|
126
|
-
}
|
|
127
|
-
setObjectProperties(properties, additionalProperties) {
|
|
128
|
-
this.builderForSetting().setObjectProperties(this.getResult(), properties, additionalProperties);
|
|
129
|
-
}
|
|
130
|
-
getUnionType(members) {
|
|
131
|
-
this.register(this.builderForNewType().getUnionType(this._typeAttributes, members, this._forwardingRef));
|
|
132
|
-
}
|
|
133
|
-
getUniqueUnionType() {
|
|
134
|
-
this.register(this.builderForNewType().getUniqueUnionType(this._typeAttributes, undefined, this._forwardingRef));
|
|
135
|
-
}
|
|
136
|
-
getIntersectionType(members) {
|
|
137
|
-
this.register(this.builderForNewType().getIntersectionType(this._typeAttributes, members, this._forwardingRef));
|
|
138
|
-
}
|
|
139
|
-
getUniqueIntersectionType(members) {
|
|
140
|
-
this.register(this.builderForNewType().getUniqueIntersectionType(this._typeAttributes, members, this._forwardingRef));
|
|
141
|
-
}
|
|
142
|
-
setSetOperationMembers(members) {
|
|
143
|
-
this.builderForSetting().setSetOperationMembers(this.getResult(), members);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
exports.TypeReconstituter = TypeReconstituter;
|
|
147
|
-
class BaseGraphRewriteBuilder extends TypeBuilder_1.TypeBuilder {
|
|
148
|
-
originalGraph;
|
|
149
|
-
debugPrint;
|
|
150
|
-
reconstitutedTypes = new Map();
|
|
151
|
-
_lostTypeAttributes = false;
|
|
152
|
-
_printIndent = 0;
|
|
153
|
-
constructor(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, debugPrint) {
|
|
154
|
-
super(originalGraph.serial + 1, stringTypeMapping, alphabetizeProperties, false, false, graphHasProvenanceAttributes);
|
|
155
|
-
this.originalGraph = originalGraph;
|
|
156
|
-
this.debugPrint = debugPrint;
|
|
157
|
-
}
|
|
158
|
-
withForwardingRef(maybeForwardingRef, typeCreator) {
|
|
159
|
-
if (maybeForwardingRef !== undefined) {
|
|
160
|
-
return typeCreator(maybeForwardingRef);
|
|
161
|
-
}
|
|
162
|
-
const forwardingRef = this.reserveTypeRef();
|
|
163
|
-
const actualRef = typeCreator(forwardingRef);
|
|
164
|
-
(0, Support_1.assert)(actualRef === forwardingRef, "Type creator didn't return its forwarding ref");
|
|
165
|
-
return actualRef;
|
|
166
|
-
}
|
|
167
|
-
reconstituteType(t, attributes, forwardingRef) {
|
|
168
|
-
return this.reconstituteTypeRef(t.typeRef, attributes, forwardingRef);
|
|
169
|
-
}
|
|
170
|
-
reconstituteTypeRef(originalRef, attributes, maybeForwardingRef) {
|
|
171
|
-
const maybeRef = this.lookupTypeRefs([originalRef], maybeForwardingRef);
|
|
172
|
-
if (maybeRef !== undefined) {
|
|
173
|
-
if (attributes !== undefined) {
|
|
174
|
-
this.addAttributes(maybeRef, attributes);
|
|
175
|
-
}
|
|
176
|
-
return maybeRef;
|
|
177
|
-
}
|
|
178
|
-
return this.forceReconstituteTypeRef(originalRef, attributes, maybeForwardingRef);
|
|
179
|
-
}
|
|
180
|
-
reconstituteTypeAttributes(attributes) {
|
|
181
|
-
return (0, collection_utils_1.mapMap)(attributes, (v, a) => a.reconstitute(this, v));
|
|
182
|
-
}
|
|
183
|
-
assertTypeRefsToReconstitute(typeRefs, forwardingRef) {
|
|
184
|
-
(0, Support_1.assert)(typeRefs.length > 0, "Must have at least one type to reconstitute");
|
|
185
|
-
for (const originalRef of typeRefs) {
|
|
186
|
-
(0, TypeGraph_1.assertTypeRefGraph)(originalRef, this.originalGraph);
|
|
187
|
-
}
|
|
188
|
-
if (forwardingRef !== undefined) {
|
|
189
|
-
(0, TypeGraph_1.assertTypeRefGraph)(forwardingRef, this.typeGraph);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
changeDebugPrintIndent(delta) {
|
|
193
|
-
this._printIndent += delta;
|
|
194
|
-
}
|
|
195
|
-
get debugPrintIndentation() {
|
|
196
|
-
return (0, Support_1.indentationString)(this._printIndent);
|
|
197
|
-
}
|
|
198
|
-
finish() {
|
|
199
|
-
for (const [name, t] of this.originalGraph.topLevels) {
|
|
200
|
-
this.addTopLevel(name, this.reconstituteType(t));
|
|
201
|
-
}
|
|
202
|
-
return super.finish();
|
|
203
|
-
}
|
|
204
|
-
setLostTypeAttributes() {
|
|
205
|
-
this._lostTypeAttributes = true;
|
|
206
|
-
}
|
|
207
|
-
get lostTypeAttributes() {
|
|
208
|
-
return this._lostTypeAttributes;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.BaseGraphRewriteBuilder = BaseGraphRewriteBuilder;
|
|
212
|
-
class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
213
|
-
_map;
|
|
214
|
-
_attributeSources = new Map();
|
|
215
|
-
constructor(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, _map, debugPrintRemapping) {
|
|
216
|
-
super(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, debugPrintRemapping);
|
|
217
|
-
this._map = _map;
|
|
218
|
-
for (const [source, target] of _map) {
|
|
219
|
-
let maybeSources = this._attributeSources.get(target);
|
|
220
|
-
if (maybeSources === undefined) {
|
|
221
|
-
maybeSources = [target];
|
|
222
|
-
this._attributeSources.set(target, maybeSources);
|
|
223
|
-
}
|
|
224
|
-
maybeSources.push(source);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
makeIdentity(_maker) {
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
getMapTarget(tref) {
|
|
231
|
-
const maybeType = this._map.get((0, TypeGraph_1.derefTypeRef)(tref, this.originalGraph));
|
|
232
|
-
if (maybeType === undefined)
|
|
233
|
-
return tref;
|
|
234
|
-
(0, Support_1.assert)(this._map.get(maybeType) === undefined, "We have a type that's remapped to a remapped type");
|
|
235
|
-
return maybeType.typeRef;
|
|
236
|
-
}
|
|
237
|
-
addForwardingIntersection(_forwardingRef, _tref) {
|
|
238
|
-
return (0, Support_1.panic)("We can't add forwarding intersections when we're removing forwarding intersections");
|
|
239
|
-
}
|
|
240
|
-
lookupTypeRefs(typeRefs, forwardingRef) {
|
|
241
|
-
(0, Support_1.assert)(forwardingRef === undefined, "We can't have a forwarding ref when we remap");
|
|
242
|
-
this.assertTypeRefsToReconstitute(typeRefs, forwardingRef);
|
|
243
|
-
const first = this.reconstitutedTypes.get((0, TypeGraph_1.typeRefIndex)(this.getMapTarget(typeRefs[0])));
|
|
244
|
-
if (first === undefined)
|
|
245
|
-
return undefined;
|
|
246
|
-
for (let i = 1; i < typeRefs.length; i++) {
|
|
247
|
-
const other = this.reconstitutedTypes.get((0, TypeGraph_1.typeRefIndex)(this.getMapTarget(typeRefs[i])));
|
|
248
|
-
if (first !== other)
|
|
249
|
-
return undefined;
|
|
250
|
-
}
|
|
251
|
-
return first;
|
|
252
|
-
}
|
|
253
|
-
forceReconstituteTypeRef(originalRef, attributes, maybeForwardingRef) {
|
|
254
|
-
originalRef = this.getMapTarget(originalRef);
|
|
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");
|
|
258
|
-
return this.withForwardingRef(undefined, forwardingRef => {
|
|
259
|
-
this.reconstitutedTypes.set(index, forwardingRef);
|
|
260
|
-
if (this.debugPrint) {
|
|
261
|
-
console.log(`${this.debugPrintIndentation}reconstituting ${index} as ${(0, TypeGraph_1.typeRefIndex)(forwardingRef)}`);
|
|
262
|
-
this.changeDebugPrintIndent(1);
|
|
263
|
-
}
|
|
264
|
-
const [originalType, originalAttributes] = (0, TypeGraph_1.typeAndAttributesForTypeRef)(originalRef, this.originalGraph);
|
|
265
|
-
const attributeSources = this._attributeSources.get(originalType);
|
|
266
|
-
if (attributes === undefined) {
|
|
267
|
-
attributes = TypeAttributes_1.emptyTypeAttributes;
|
|
268
|
-
}
|
|
269
|
-
if (attributeSources === undefined) {
|
|
270
|
-
attributes = (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, this.reconstituteTypeAttributes(originalAttributes));
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
attributes = (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, this.reconstituteTypeAttributes((0, TypeUtils_1.combineTypeAttributesOfTypes)("union", attributeSources)));
|
|
274
|
-
}
|
|
275
|
-
const newAttributes = attributes;
|
|
276
|
-
const reconstituter = new TypeReconstituter(this, this.canonicalOrder, newAttributes, forwardingRef, tref => {
|
|
277
|
-
(0, Support_1.assert)(tref === forwardingRef, "Reconstituted type as a different ref");
|
|
278
|
-
if (this.debugPrint) {
|
|
279
|
-
this.changeDebugPrintIndent(-1);
|
|
280
|
-
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${(0, TypeGraph_1.typeRefIndex)(tref)}`);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
originalType.reconstitute(reconstituter, this.canonicalOrder);
|
|
284
|
-
return reconstituter.getResult();
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
exports.GraphRemapBuilder = GraphRemapBuilder;
|
|
289
|
-
class GraphRewriteBuilder extends BaseGraphRewriteBuilder {
|
|
290
|
-
_replacer;
|
|
291
|
-
_setsToReplaceByMember;
|
|
292
|
-
_reconstitutedUnions = new collection_utils_1.EqualityMap();
|
|
293
|
-
constructor(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, setsToReplace, debugPrintReconstitution, _replacer) {
|
|
294
|
-
super(originalGraph, stringTypeMapping, alphabetizeProperties, graphHasProvenanceAttributes, debugPrintReconstitution);
|
|
295
|
-
this._replacer = _replacer;
|
|
296
|
-
this._setsToReplaceByMember = new Map();
|
|
297
|
-
for (const types of setsToReplace) {
|
|
298
|
-
const set = new Set(types);
|
|
299
|
-
for (const t of set) {
|
|
300
|
-
const index = t.index;
|
|
301
|
-
(0, Support_1.assert)(!this._setsToReplaceByMember.has(index), "A type is member of more than one set to be replaced");
|
|
302
|
-
this._setsToReplaceByMember.set(index, set);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
registerUnion(typeRefs, reconstituted) {
|
|
307
|
-
const set = new Set(typeRefs);
|
|
308
|
-
(0, Support_1.assert)(!this._reconstitutedUnions.has(set), "Cannot register reconstituted set twice");
|
|
309
|
-
this._reconstitutedUnions.set(set, reconstituted);
|
|
310
|
-
}
|
|
311
|
-
replaceSet(typesToReplace, maybeForwardingRef) {
|
|
312
|
-
return this.withForwardingRef(maybeForwardingRef, forwardingRef => {
|
|
313
|
-
if (this.debugPrint) {
|
|
314
|
-
console.log(`${this.debugPrintIndentation}replacing set ${Array.from(typesToReplace)
|
|
315
|
-
.map(t => t.index.toString())
|
|
316
|
-
.join(",")} as ${(0, TypeGraph_1.typeRefIndex)(forwardingRef)}`);
|
|
317
|
-
this.changeDebugPrintIndent(1);
|
|
318
|
-
}
|
|
319
|
-
for (const t of typesToReplace) {
|
|
320
|
-
const originalRef = t.typeRef;
|
|
321
|
-
const index = (0, TypeGraph_1.typeRefIndex)(originalRef);
|
|
322
|
-
this.reconstitutedTypes.set(index, forwardingRef);
|
|
323
|
-
this._setsToReplaceByMember.delete(index);
|
|
324
|
-
}
|
|
325
|
-
const result = this._replacer(typesToReplace, this, forwardingRef);
|
|
326
|
-
(0, Support_1.assert)(result === forwardingRef, "The forwarding ref got lost when replacing");
|
|
327
|
-
if (this.debugPrint) {
|
|
328
|
-
this.changeDebugPrintIndent(-1);
|
|
329
|
-
console.log(`${this.debugPrintIndentation}replaced set ${Array.from(typesToReplace)
|
|
330
|
-
.map(t => t.index.toString())
|
|
331
|
-
.join(",")} as ${(0, TypeGraph_1.typeRefIndex)(forwardingRef)}`);
|
|
332
|
-
}
|
|
333
|
-
return result;
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
forceReconstituteTypeRef(originalRef, attributes, maybeForwardingRef) {
|
|
337
|
-
const [originalType, originalAttributes] = (0, TypeGraph_1.typeAndAttributesForTypeRef)(originalRef, this.originalGraph);
|
|
338
|
-
const index = (0, TypeGraph_1.typeRefIndex)(originalRef);
|
|
339
|
-
if (this.debugPrint) {
|
|
340
|
-
console.log(`${this.debugPrintIndentation}reconstituting ${index}`);
|
|
341
|
-
this.changeDebugPrintIndent(1);
|
|
342
|
-
}
|
|
343
|
-
if (attributes === undefined) {
|
|
344
|
-
attributes = this.reconstituteTypeAttributes(originalAttributes);
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
attributes = (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, this.reconstituteTypeAttributes(originalAttributes));
|
|
348
|
-
}
|
|
349
|
-
const reconstituter = new TypeReconstituter(this, this.canonicalOrder, attributes, maybeForwardingRef, tref => {
|
|
350
|
-
if (this.debugPrint) {
|
|
351
|
-
this.changeDebugPrintIndent(-1);
|
|
352
|
-
console.log(`${this.debugPrintIndentation}reconstituted ${index} as ${(0, TypeGraph_1.typeRefIndex)(tref)}`);
|
|
353
|
-
}
|
|
354
|
-
if (maybeForwardingRef !== undefined) {
|
|
355
|
-
(0, Support_1.assert)(tref === maybeForwardingRef, "We didn't pass the forwarding ref");
|
|
356
|
-
}
|
|
357
|
-
const alreadyReconstitutedType = this.reconstitutedTypes.get(index);
|
|
358
|
-
if (alreadyReconstitutedType === undefined) {
|
|
359
|
-
this.reconstitutedTypes.set(index, tref);
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
(0, Support_1.assert)(tref === alreadyReconstitutedType, "We reconstituted a type twice differently");
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
originalType.reconstitute(reconstituter, this.canonicalOrder);
|
|
366
|
-
return reconstituter.getResult();
|
|
367
|
-
}
|
|
368
|
-
/*
|
|
369
|
-
reconstituteTypeUnmodified(originalType: Type): TypeRef {
|
|
370
|
-
const reconstituter = new TypeReconstituter(
|
|
371
|
-
this,
|
|
372
|
-
this.alphabetizeProperties,
|
|
373
|
-
emptyTypeAttributes,
|
|
374
|
-
undefined,
|
|
375
|
-
() => {}
|
|
376
|
-
);
|
|
377
|
-
originalType.reconstitute(reconstituter);
|
|
378
|
-
return reconstituter.getResult();
|
|
379
|
-
}
|
|
380
|
-
*/
|
|
381
|
-
// If the union of these type refs have been, or are supposed to be, reconstituted to
|
|
382
|
-
// one target type, return it. Otherwise return undefined.
|
|
383
|
-
lookupTypeRefs(typeRefs, forwardingRef, replaceSet = true) {
|
|
384
|
-
this.assertTypeRefsToReconstitute(typeRefs, forwardingRef);
|
|
385
|
-
// Check whether we have already reconstituted them. That means ensuring
|
|
386
|
-
// that they all have the same target type.
|
|
387
|
-
let maybeRef = this.reconstitutedTypes.get((0, TypeGraph_1.typeRefIndex)(typeRefs[0]));
|
|
388
|
-
if (maybeRef !== undefined && maybeRef !== forwardingRef) {
|
|
389
|
-
let allEqual = true;
|
|
390
|
-
for (let i = 1; i < typeRefs.length; i++) {
|
|
391
|
-
if (this.reconstitutedTypes.get((0, TypeGraph_1.typeRefIndex)(typeRefs[i])) !== maybeRef) {
|
|
392
|
-
allEqual = false;
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
if (allEqual) {
|
|
397
|
-
return this.forwardIfNecessary(forwardingRef, maybeRef);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
// Has this been reconstituted as a set?
|
|
401
|
-
maybeRef = this._reconstitutedUnions.get(new Set(typeRefs));
|
|
402
|
-
if (maybeRef !== undefined && maybeRef !== forwardingRef) {
|
|
403
|
-
return this.forwardIfNecessary(forwardingRef, maybeRef);
|
|
404
|
-
}
|
|
405
|
-
// Is this set requested to be replaced? If not, we're out of options.
|
|
406
|
-
const maybeSet = this._setsToReplaceByMember.get((0, TypeGraph_1.typeRefIndex)(typeRefs[0]));
|
|
407
|
-
if (maybeSet === undefined) {
|
|
408
|
-
return undefined;
|
|
409
|
-
}
|
|
410
|
-
for (let i = 1; i < typeRefs.length; i++) {
|
|
411
|
-
if (this._setsToReplaceByMember.get((0, TypeGraph_1.typeRefIndex)(typeRefs[i])) !== maybeSet) {
|
|
412
|
-
return undefined;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
// Yes, this set is requested to be replaced, so do it.
|
|
416
|
-
if (!replaceSet)
|
|
417
|
-
return undefined;
|
|
418
|
-
return this.replaceSet(maybeSet, forwardingRef);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
exports.GraphRewriteBuilder = GraphRewriteBuilder;
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeTransformations = void 0;
|
|
4
|
-
const collection_utils_1 = require("collection-utils");
|
|
5
|
-
const TypeGraph_1 = require("./TypeGraph");
|
|
6
|
-
const Type_1 = require("./Type");
|
|
7
|
-
const Support_1 = require("./support/Support");
|
|
8
|
-
const Transformers_1 = require("./Transformers");
|
|
9
|
-
const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
10
|
-
const StringTypes_1 = require("./attributes/StringTypes");
|
|
11
|
-
const Constraints_1 = require("./attributes/Constraints");
|
|
12
|
-
function transformationAttributes(graph, reconstitutedTargetType, transformer, debugPrintTransformations) {
|
|
13
|
-
const transformation = new Transformers_1.Transformation(graph, reconstitutedTargetType, transformer);
|
|
14
|
-
if (debugPrintTransformations) {
|
|
15
|
-
console.log(`transformation for ${(0, TypeGraph_1.typeRefIndex)(reconstitutedTargetType)}:`);
|
|
16
|
-
transformation.debugPrint();
|
|
17
|
-
console.log(`reverse:`);
|
|
18
|
-
transformation.reverse.debugPrint();
|
|
19
|
-
}
|
|
20
|
-
return Transformers_1.transformationTypeAttributeKind.makeAttributes(transformation);
|
|
21
|
-
}
|
|
22
|
-
function makeEnumTransformer(graph, enumType, stringType, continuation) {
|
|
23
|
-
const sortedCases = Array.from(enumType.cases).sort();
|
|
24
|
-
const caseTransformers = sortedCases.map(c => new Transformers_1.StringMatchTransformer(graph, stringType, new Transformers_1.StringProducerTransformer(graph, stringType, continuation, c), c));
|
|
25
|
-
return new Transformers_1.ChoiceTransformer(graph, stringType, caseTransformers);
|
|
26
|
-
}
|
|
27
|
-
function replaceUnion(union, builder, forwardingRef, transformedTypes, debugPrintTransformations) {
|
|
28
|
-
const graph = builder.typeGraph;
|
|
29
|
-
(0, Support_1.assert)(union.members.size > 0, "We can't have empty unions");
|
|
30
|
-
// Type attributes that we lost during reconstitution.
|
|
31
|
-
let additionalAttributes = TypeAttributes_1.emptyTypeAttributes;
|
|
32
|
-
function reconstituteMember(t) {
|
|
33
|
-
// Special handling for some transformed string type kinds: The type in
|
|
34
|
-
// the union must be the target type, so if one already exists, use that
|
|
35
|
-
// one, otherwise make a new one.
|
|
36
|
-
if ((0, Type_1.isPrimitiveStringTypeKind)(t.kind)) {
|
|
37
|
-
const targetTypeKind = (0, Type_1.targetTypeKindForTransformedStringTypeKind)(t.kind);
|
|
38
|
-
if (targetTypeKind !== undefined) {
|
|
39
|
-
const targetTypeMember = union.findMember(targetTypeKind);
|
|
40
|
-
additionalAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", additionalAttributes, t.getAttributes());
|
|
41
|
-
if (targetTypeMember !== undefined) {
|
|
42
|
-
return builder.reconstituteType(targetTypeMember);
|
|
43
|
-
}
|
|
44
|
-
return builder.getPrimitiveType(targetTypeKind);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return builder.reconstituteType(t);
|
|
48
|
-
}
|
|
49
|
-
const reconstitutedMembersByKind = (0, collection_utils_1.mapMapEntries)(union.members.entries(), m => [m.kind, reconstituteMember(m)]);
|
|
50
|
-
const reconstitutedMemberSet = new Set(reconstitutedMembersByKind.values());
|
|
51
|
-
const haveUnion = reconstitutedMemberSet.size > 1;
|
|
52
|
-
if (!haveUnion) {
|
|
53
|
-
builder.setLostTypeAttributes();
|
|
54
|
-
}
|
|
55
|
-
const reconstitutedTargetType = haveUnion
|
|
56
|
-
? builder.getUnionType(union.getAttributes(), reconstitutedMemberSet)
|
|
57
|
-
: (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(reconstitutedMemberSet));
|
|
58
|
-
function memberForKind(kind) {
|
|
59
|
-
return (0, Support_1.defined)(reconstitutedMembersByKind.get(kind));
|
|
60
|
-
}
|
|
61
|
-
function consumer(memberTypeRef) {
|
|
62
|
-
if (!haveUnion)
|
|
63
|
-
return undefined;
|
|
64
|
-
return new Transformers_1.UnionInstantiationTransformer(graph, memberTypeRef);
|
|
65
|
-
}
|
|
66
|
-
function transformerForKind(kind) {
|
|
67
|
-
const member = union.findMember(kind);
|
|
68
|
-
if (member === undefined)
|
|
69
|
-
return undefined;
|
|
70
|
-
const memberTypeRef = memberForKind(kind);
|
|
71
|
-
return new Transformers_1.DecodingTransformer(graph, memberTypeRef, consumer(memberTypeRef));
|
|
72
|
-
}
|
|
73
|
-
let maybeStringType = undefined;
|
|
74
|
-
function getStringType() {
|
|
75
|
-
if (maybeStringType === undefined) {
|
|
76
|
-
maybeStringType = builder.getStringType(TypeAttributes_1.emptyTypeAttributes, StringTypes_1.StringTypes.unrestricted);
|
|
77
|
-
}
|
|
78
|
-
return maybeStringType;
|
|
79
|
-
}
|
|
80
|
-
function transformerForStringType(t) {
|
|
81
|
-
const memberRef = memberForKind(t.kind);
|
|
82
|
-
if (t.kind === "string") {
|
|
83
|
-
const minMax = (0, Constraints_1.minMaxLengthForType)(t);
|
|
84
|
-
if (minMax === undefined) {
|
|
85
|
-
return consumer(memberRef);
|
|
86
|
-
}
|
|
87
|
-
const [min, max] = minMax;
|
|
88
|
-
return new Transformers_1.MinMaxLengthCheckTransformer(graph, getStringType(), consumer(memberRef), min, max);
|
|
89
|
-
}
|
|
90
|
-
else if (t instanceof Type_1.EnumType && transformedTypes.has(t)) {
|
|
91
|
-
return makeEnumTransformer(graph, t, getStringType(), consumer(memberRef));
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return new Transformers_1.ParseStringTransformer(graph, getStringType(), consumer(memberRef));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const stringTypes = (0, collection_utils_1.arraySortByInto)(Array.from(union.stringTypeMembers), t => t.kind);
|
|
98
|
-
let transformerForString;
|
|
99
|
-
if (stringTypes.length === 0) {
|
|
100
|
-
transformerForString = undefined;
|
|
101
|
-
}
|
|
102
|
-
else if (stringTypes.length === 1) {
|
|
103
|
-
const t = stringTypes[0];
|
|
104
|
-
transformerForString = new Transformers_1.DecodingTransformer(graph, getStringType(), transformerForStringType(t));
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
transformerForString = new Transformers_1.DecodingTransformer(graph, getStringType(), new Transformers_1.ChoiceTransformer(graph, getStringType(), stringTypes.map(t => (0, Support_1.defined)(transformerForStringType(t)))));
|
|
108
|
-
}
|
|
109
|
-
const transformerForClass = transformerForKind("class");
|
|
110
|
-
const transformerForMap = transformerForKind("map");
|
|
111
|
-
(0, Support_1.assert)(transformerForClass === undefined || transformerForMap === undefined, "Can't have both class and map in a transformed union");
|
|
112
|
-
const transformerForObject = transformerForClass !== undefined ? transformerForClass : transformerForMap;
|
|
113
|
-
const transformer = new Transformers_1.DecodingChoiceTransformer(graph, builder.getPrimitiveType("any"), transformerForKind("null"), transformerForKind("integer"), transformerForKind("double"), transformerForKind("bool"), transformerForString, transformerForKind("array"), transformerForObject);
|
|
114
|
-
const attributes = transformationAttributes(graph, reconstitutedTargetType, transformer, debugPrintTransformations);
|
|
115
|
-
return builder.getPrimitiveType("any", (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, additionalAttributes), forwardingRef);
|
|
116
|
-
}
|
|
117
|
-
function replaceArray(arrayType, builder, forwardingRef, debugPrintTransformations) {
|
|
118
|
-
const anyType = builder.getPrimitiveType("any");
|
|
119
|
-
const anyArrayType = builder.getArrayType(TypeAttributes_1.emptyTypeAttributes, anyType);
|
|
120
|
-
const reconstitutedItems = builder.reconstituteType(arrayType.items);
|
|
121
|
-
const transformer = new Transformers_1.ArrayDecodingTransformer(builder.typeGraph, anyArrayType, undefined, reconstitutedItems, new Transformers_1.DecodingTransformer(builder.typeGraph, anyType, undefined));
|
|
122
|
-
const reconstitutedArray = builder.getArrayType(builder.reconstituteTypeAttributes(arrayType.getAttributes()), reconstitutedItems);
|
|
123
|
-
const attributes = transformationAttributes(builder.typeGraph, reconstitutedArray, transformer, debugPrintTransformations);
|
|
124
|
-
return builder.getArrayType(attributes, anyType, forwardingRef);
|
|
125
|
-
}
|
|
126
|
-
function replaceEnum(enumType, builder, forwardingRef, debugPrintTransformations) {
|
|
127
|
-
const stringType = builder.getStringType(TypeAttributes_1.emptyTypeAttributes, StringTypes_1.StringTypes.unrestricted);
|
|
128
|
-
const transformer = new Transformers_1.DecodingTransformer(builder.typeGraph, stringType, makeEnumTransformer(builder.typeGraph, enumType, stringType));
|
|
129
|
-
const reconstitutedEnum = builder.getEnumType(enumType.getAttributes(), enumType.cases);
|
|
130
|
-
const attributes = transformationAttributes(builder.typeGraph, reconstitutedEnum, transformer, debugPrintTransformations);
|
|
131
|
-
return builder.getStringType(attributes, StringTypes_1.StringTypes.unrestricted, forwardingRef);
|
|
132
|
-
}
|
|
133
|
-
function replaceNumber(t, builder, forwardingRef, debugPrintTransformations) {
|
|
134
|
-
const stringType = builder.getStringType(TypeAttributes_1.emptyTypeAttributes, StringTypes_1.StringTypes.unrestricted);
|
|
135
|
-
const [min, max] = (0, Support_1.defined)((0, Constraints_1.minMaxValueForType)(t));
|
|
136
|
-
const transformer = new Transformers_1.DecodingTransformer(builder.typeGraph, stringType, new Transformers_1.MinMaxValueTransformer(builder.typeGraph, stringType, undefined, min, max));
|
|
137
|
-
const reconstitutedAttributes = builder.reconstituteTypeAttributes(t.getAttributes());
|
|
138
|
-
const attributes = transformationAttributes(builder.typeGraph, builder.getPrimitiveType("double", reconstitutedAttributes, undefined), transformer, debugPrintTransformations);
|
|
139
|
-
return builder.getPrimitiveType("double", attributes, forwardingRef);
|
|
140
|
-
}
|
|
141
|
-
function replaceString(t, builder, forwardingRef, debugPrintTransformations) {
|
|
142
|
-
const [min, max] = (0, Support_1.defined)((0, Constraints_1.minMaxLengthForType)(t));
|
|
143
|
-
const reconstitutedAttributes = builder.reconstituteTypeAttributes(t.getAttributes());
|
|
144
|
-
const stringType = builder.getStringType(TypeAttributes_1.emptyTypeAttributes, StringTypes_1.StringTypes.unrestricted);
|
|
145
|
-
const transformer = new Transformers_1.DecodingTransformer(builder.typeGraph, stringType, new Transformers_1.MinMaxLengthCheckTransformer(builder.typeGraph, stringType, undefined, min, max));
|
|
146
|
-
const attributes = transformationAttributes(builder.typeGraph, builder.getStringType(reconstitutedAttributes, undefined), transformer, debugPrintTransformations);
|
|
147
|
-
return builder.getStringType(attributes, StringTypes_1.StringTypes.unrestricted, forwardingRef);
|
|
148
|
-
}
|
|
149
|
-
function replaceTransformedStringType(t, kind, builder, forwardingRef, debugPrintTransformations) {
|
|
150
|
-
const reconstitutedAttributes = builder.reconstituteTypeAttributes(t.getAttributes());
|
|
151
|
-
const targetTypeKind = (0, collection_utils_1.withDefault)((0, Type_1.targetTypeKindForTransformedStringTypeKind)(kind), kind);
|
|
152
|
-
const stringType = builder.getStringType(TypeAttributes_1.emptyTypeAttributes, StringTypes_1.StringTypes.unrestricted);
|
|
153
|
-
const transformer = new Transformers_1.DecodingTransformer(builder.typeGraph, stringType, new Transformers_1.ParseStringTransformer(builder.typeGraph, stringType, undefined));
|
|
154
|
-
const attributes = transformationAttributes(builder.typeGraph, builder.getPrimitiveType(targetTypeKind, reconstitutedAttributes), transformer, debugPrintTransformations);
|
|
155
|
-
return builder.getStringType(attributes, StringTypes_1.StringTypes.unrestricted, forwardingRef);
|
|
156
|
-
}
|
|
157
|
-
function makeTransformations(ctx, graph, targetLanguage) {
|
|
158
|
-
const transformedTypes = (0, collection_utils_1.setFilter)(graph.allTypesUnordered(), t => {
|
|
159
|
-
if (targetLanguage.needsTransformerForType(t))
|
|
160
|
-
return true;
|
|
161
|
-
if (!(t instanceof Type_1.UnionType))
|
|
162
|
-
return false;
|
|
163
|
-
const stringMembers = t.stringTypeMembers;
|
|
164
|
-
if (stringMembers.size <= 1)
|
|
165
|
-
return false;
|
|
166
|
-
return (0, collection_utils_1.iterableSome)(stringMembers, m => targetLanguage.needsTransformerForType(m));
|
|
167
|
-
});
|
|
168
|
-
function replace(setOfOneUnion, builder, forwardingRef) {
|
|
169
|
-
const t = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(setOfOneUnion));
|
|
170
|
-
if (t instanceof Type_1.UnionType) {
|
|
171
|
-
return replaceUnion(t, builder, forwardingRef, transformedTypes, ctx.debugPrintTransformations);
|
|
172
|
-
}
|
|
173
|
-
if (t instanceof Type_1.ArrayType) {
|
|
174
|
-
return replaceArray(t, builder, forwardingRef, ctx.debugPrintTransformations);
|
|
175
|
-
}
|
|
176
|
-
if (t instanceof Type_1.EnumType) {
|
|
177
|
-
return replaceEnum(t, builder, forwardingRef, ctx.debugPrintTransformations);
|
|
178
|
-
}
|
|
179
|
-
if (t.kind === "string") {
|
|
180
|
-
return replaceString(t, builder, forwardingRef, ctx.debugPrintTransformations);
|
|
181
|
-
}
|
|
182
|
-
if ((0, Type_1.isNumberTypeKind)(t.kind)) {
|
|
183
|
-
return replaceNumber(t, builder, forwardingRef, ctx.debugPrintTransformations);
|
|
184
|
-
}
|
|
185
|
-
if ((0, Type_1.isPrimitiveStringTypeKind)(t.kind)) {
|
|
186
|
-
return replaceTransformedStringType(t, t.kind, builder, forwardingRef, ctx.debugPrintTransformations);
|
|
187
|
-
}
|
|
188
|
-
return (0, Support_1.panic)(`Cannot make transformation for type ${t.kind}`);
|
|
189
|
-
}
|
|
190
|
-
const groups = Array.from(transformedTypes).map(t => [t]);
|
|
191
|
-
return graph.rewrite("make-transformations", ctx.stringTypeMapping, false, groups, ctx.debugPrintReconstitution, replace);
|
|
192
|
-
}
|
|
193
|
-
exports.makeTransformations = makeTransformations;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type SubTrie = number | null | Trie;
|
|
2
|
-
export type Trie = {
|
|
3
|
-
count: number;
|
|
4
|
-
arr: SubTrie[];
|
|
5
|
-
};
|
|
6
|
-
export type MarkovChain = {
|
|
7
|
-
trie: Trie;
|
|
8
|
-
depth: number;
|
|
9
|
-
};
|
|
10
|
-
export declare function train(lines: string[], depth: number): MarkovChain;
|
|
11
|
-
export declare function load(): MarkovChain;
|
|
12
|
-
export declare function evaluateFull(mc: MarkovChain, word: string): [number, number[]];
|
|
13
|
-
export declare function evaluate(mc: MarkovChain, word: string): number;
|
|
14
|
-
export declare function generate(mc: MarkovChain, state: string, unseenWeight: number): string;
|
|
15
|
-
export declare function test(): void;
|