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