quicktype 17.0.6 → 18.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 +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 +36 -34
- 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 +20 -18
- 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 +24 -20
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeBuilder = exports.getNoStringTypeMapping = exports.stringTypeMappingGet = exports.provenanceTypeAttributeKind = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const Type_1 = require("./Type");
|
|
5
6
|
const TypeGraph_1 = require("./TypeGraph");
|
|
@@ -16,7 +17,7 @@ class ProvenanceTypeAttributeKind extends TypeAttributes_1.TypeAttributeKind {
|
|
|
16
17
|
return true;
|
|
17
18
|
}
|
|
18
19
|
combine(arr) {
|
|
19
|
-
return collection_utils_1.setUnionManyInto(new Set(), arr);
|
|
20
|
+
return (0, collection_utils_1.setUnionManyInto)(new Set(), arr);
|
|
20
21
|
}
|
|
21
22
|
makeInferred(p) {
|
|
22
23
|
return p;
|
|
@@ -45,30 +46,34 @@ function getNoStringTypeMapping() {
|
|
|
45
46
|
}
|
|
46
47
|
exports.getNoStringTypeMapping = getNoStringTypeMapping;
|
|
47
48
|
class TypeBuilder {
|
|
49
|
+
_stringTypeMapping;
|
|
50
|
+
canonicalOrder;
|
|
51
|
+
_allPropertiesOptional;
|
|
52
|
+
_addProvenanceAttributes;
|
|
53
|
+
typeGraph;
|
|
54
|
+
topLevels = new Map();
|
|
55
|
+
types = [];
|
|
56
|
+
typeAttributes = [];
|
|
57
|
+
_addedForwardingIntersection = false;
|
|
48
58
|
constructor(typeGraphSerial, _stringTypeMapping, canonicalOrder, _allPropertiesOptional, _addProvenanceAttributes, inheritsProvenanceAttributes) {
|
|
49
59
|
this._stringTypeMapping = _stringTypeMapping;
|
|
50
60
|
this.canonicalOrder = canonicalOrder;
|
|
51
61
|
this._allPropertiesOptional = _allPropertiesOptional;
|
|
52
62
|
this._addProvenanceAttributes = _addProvenanceAttributes;
|
|
53
|
-
|
|
54
|
-
this.types = [];
|
|
55
|
-
this.typeAttributes = [];
|
|
56
|
-
this._addedForwardingIntersection = false;
|
|
57
|
-
this._typeForIdentity = new collection_utils_1.EqualityMap();
|
|
58
|
-
Support_1.assert(!_addProvenanceAttributes || !inheritsProvenanceAttributes, "We can't both inherit as well as add provenance");
|
|
63
|
+
(0, Support_1.assert)(!_addProvenanceAttributes || !inheritsProvenanceAttributes, "We can't both inherit as well as add provenance");
|
|
59
64
|
this.typeGraph = new TypeGraph_1.TypeGraph(this, typeGraphSerial, _addProvenanceAttributes || inheritsProvenanceAttributes);
|
|
60
65
|
}
|
|
61
66
|
addTopLevel(name, tref) {
|
|
62
67
|
// assert(t.typeGraph === this.typeGraph, "Adding top-level to wrong type graph");
|
|
63
|
-
Support_1.assert(!this.topLevels.has(name), "Trying to add top-level with existing name");
|
|
64
|
-
Support_1.assert(this.types[TypeGraph_1.typeRefIndex(tref)] !== undefined, "Trying to add a top-level type that doesn't exist (yet?)");
|
|
68
|
+
(0, Support_1.assert)(!this.topLevels.has(name), "Trying to add top-level with existing name");
|
|
69
|
+
(0, Support_1.assert)(this.types[(0, TypeGraph_1.typeRefIndex)(tref)] !== undefined, "Trying to add a top-level type that doesn't exist (yet?)");
|
|
65
70
|
this.topLevels.set(name, tref);
|
|
66
71
|
}
|
|
67
72
|
reserveTypeRef() {
|
|
68
73
|
const index = this.types.length;
|
|
69
74
|
// console.log(`reserving ${index}`);
|
|
70
75
|
this.types.push(undefined);
|
|
71
|
-
const tref = TypeGraph_1.makeTypeRef(this.typeGraph, index);
|
|
76
|
+
const tref = (0, TypeGraph_1.makeTypeRef)(this.typeGraph, index);
|
|
72
77
|
const attributes = this._addProvenanceAttributes
|
|
73
78
|
? exports.provenanceTypeAttributeKind.makeAttributes(new Set([index]))
|
|
74
79
|
: TypeAttributes_1.emptyTypeAttributes;
|
|
@@ -78,7 +83,7 @@ class TypeBuilder {
|
|
|
78
83
|
assertTypeRefGraph(tref) {
|
|
79
84
|
if (tref === undefined)
|
|
80
85
|
return;
|
|
81
|
-
TypeGraph_1.assertTypeRefGraph(tref, this.typeGraph);
|
|
86
|
+
(0, TypeGraph_1.assertTypeRefGraph)(tref, this.typeGraph);
|
|
82
87
|
}
|
|
83
88
|
assertTypeRefSetGraph(trefs) {
|
|
84
89
|
if (trefs === undefined)
|
|
@@ -86,7 +91,7 @@ class TypeBuilder {
|
|
|
86
91
|
trefs.forEach(tref => this.assertTypeRefGraph(tref));
|
|
87
92
|
}
|
|
88
93
|
filterTypeAttributes(t, attributes) {
|
|
89
|
-
const filtered = collection_utils_1.mapFilter(attributes, (_, k) => k.appliesToTypeKind(t.kind));
|
|
94
|
+
const filtered = (0, collection_utils_1.mapFilter)(attributes, (_, k) => k.appliesToTypeKind(t.kind));
|
|
90
95
|
if (attributes.size !== filtered.size) {
|
|
91
96
|
this.setLostTypeAttributes();
|
|
92
97
|
}
|
|
@@ -94,22 +99,22 @@ class TypeBuilder {
|
|
|
94
99
|
}
|
|
95
100
|
commitType(tref, t) {
|
|
96
101
|
this.assertTypeRefGraph(tref);
|
|
97
|
-
const index = TypeGraph_1.typeRefIndex(tref);
|
|
102
|
+
const index = (0, TypeGraph_1.typeRefIndex)(tref);
|
|
98
103
|
// const name = names !== undefined ? ` ${names.combinedName}` : "";
|
|
99
104
|
// console.log(`committing ${t.kind}${name} to ${index}`);
|
|
100
|
-
Support_1.assert(this.types[index] === undefined, "A type index was committed twice");
|
|
105
|
+
(0, Support_1.assert)(this.types[index] === undefined, "A type index was committed twice");
|
|
101
106
|
this.types[index] = t;
|
|
102
107
|
this.typeAttributes[index] = this.filterTypeAttributes(t, this.typeAttributes[index]);
|
|
103
108
|
}
|
|
104
109
|
addType(forwardingRef, creator, attributes) {
|
|
105
110
|
if (forwardingRef !== undefined) {
|
|
106
111
|
this.assertTypeRefGraph(forwardingRef);
|
|
107
|
-
Support_1.assert(this.types[TypeGraph_1.typeRefIndex(forwardingRef)] === undefined);
|
|
112
|
+
(0, Support_1.assert)(this.types[(0, TypeGraph_1.typeRefIndex)(forwardingRef)] === undefined);
|
|
108
113
|
}
|
|
109
114
|
const tref = forwardingRef !== undefined ? forwardingRef : this.reserveTypeRef();
|
|
110
115
|
if (attributes !== undefined) {
|
|
111
|
-
const index = TypeGraph_1.typeRefIndex(tref);
|
|
112
|
-
this.typeAttributes[index] = TypeAttributes_1.combineTypeAttributes("union", this.typeAttributes[index], attributes);
|
|
116
|
+
const index = (0, TypeGraph_1.typeRefIndex)(tref);
|
|
117
|
+
this.typeAttributes[index] = (0, TypeAttributes_1.combineTypeAttributes)("union", this.typeAttributes[index], attributes);
|
|
113
118
|
}
|
|
114
119
|
const t = creator(tref);
|
|
115
120
|
this.commitType(tref, t);
|
|
@@ -118,7 +123,7 @@ class TypeBuilder {
|
|
|
118
123
|
typeAtIndex(index) {
|
|
119
124
|
const maybeType = this.types[index];
|
|
120
125
|
if (maybeType === undefined) {
|
|
121
|
-
return Support_1.panic("Trying to deref an undefined type in a type builder");
|
|
126
|
+
return (0, Support_1.panic)("Trying to deref an undefined type in a type builder");
|
|
122
127
|
}
|
|
123
128
|
return maybeType;
|
|
124
129
|
}
|
|
@@ -129,22 +134,22 @@ class TypeBuilder {
|
|
|
129
134
|
}
|
|
130
135
|
addAttributes(tref, attributes) {
|
|
131
136
|
this.assertTypeRefGraph(tref);
|
|
132
|
-
const index = TypeGraph_1.typeRefIndex(tref);
|
|
137
|
+
const index = (0, TypeGraph_1.typeRefIndex)(tref);
|
|
133
138
|
const existingAttributes = this.typeAttributes[index];
|
|
134
|
-
Support_1.assert(collection_utils_1.iterableEvery(attributes, ([k, v]) => {
|
|
139
|
+
(0, Support_1.assert)((0, collection_utils_1.iterableEvery)(attributes, ([k, v]) => {
|
|
135
140
|
if (!k.inIdentity)
|
|
136
141
|
return true;
|
|
137
142
|
const existing = existingAttributes.get(k);
|
|
138
143
|
if (existing === undefined)
|
|
139
144
|
return false;
|
|
140
|
-
return collection_utils_1.areEqual(existing, v);
|
|
145
|
+
return (0, collection_utils_1.areEqual)(existing, v);
|
|
141
146
|
}), "Can't add different identity type attributes to an existing type");
|
|
142
147
|
const maybeType = this.types[index];
|
|
143
148
|
if (maybeType !== undefined) {
|
|
144
149
|
attributes = this.filterTypeAttributes(maybeType, attributes);
|
|
145
150
|
}
|
|
146
|
-
const nonIdentityAttributes = collection_utils_1.mapFilter(attributes, (_, k) => !k.inIdentity);
|
|
147
|
-
this.typeAttributes[index] = TypeAttributes_1.combineTypeAttributes("union", existingAttributes, nonIdentityAttributes);
|
|
151
|
+
const nonIdentityAttributes = (0, collection_utils_1.mapFilter)(attributes, (_, k) => !k.inIdentity);
|
|
152
|
+
this.typeAttributes[index] = (0, TypeAttributes_1.combineTypeAttributes)("union", existingAttributes, nonIdentityAttributes);
|
|
148
153
|
}
|
|
149
154
|
finish() {
|
|
150
155
|
this.typeGraph.freeze(this.topLevels, this.types.map(Support_1.defined), this.typeAttributes);
|
|
@@ -165,6 +170,7 @@ class TypeBuilder {
|
|
|
165
170
|
get didAddForwardingIntersection() {
|
|
166
171
|
return this._addedForwardingIntersection;
|
|
167
172
|
}
|
|
173
|
+
_typeForIdentity = new collection_utils_1.EqualityMap();
|
|
168
174
|
registerTypeForIdentity(identity, tref) {
|
|
169
175
|
if (identity === undefined)
|
|
170
176
|
return;
|
|
@@ -189,7 +195,7 @@ class TypeBuilder {
|
|
|
189
195
|
// we found the type based on its identity, i.e. all the identity
|
|
190
196
|
// attributes must be in there already, and we have a check that
|
|
191
197
|
// asserts that no identity attributes are added later.
|
|
192
|
-
this.addAttributes(result, collection_utils_1.mapFilter(attributes, (_, k) => !k.inIdentity));
|
|
198
|
+
this.addAttributes(result, (0, collection_utils_1.mapFilter)(attributes, (_, k) => !k.inIdentity));
|
|
193
199
|
}
|
|
194
200
|
return result;
|
|
195
201
|
}
|
|
@@ -201,35 +207,35 @@ class TypeBuilder {
|
|
|
201
207
|
this.registerTypeForIdentity(t.identity, t.typeRef);
|
|
202
208
|
}
|
|
203
209
|
getPrimitiveType(kind, maybeAttributes, forwardingRef) {
|
|
204
|
-
const attributes = collection_utils_1.withDefault(maybeAttributes, TypeAttributes_1.emptyTypeAttributes);
|
|
210
|
+
const attributes = (0, collection_utils_1.withDefault)(maybeAttributes, TypeAttributes_1.emptyTypeAttributes);
|
|
205
211
|
// FIXME: Why do date/time types need a StringTypes attribute?
|
|
206
212
|
// FIXME: Remove this from here and put it into flattenStrings
|
|
207
213
|
let stringTypes = kind === "string" ? undefined : StringTypes_1.StringTypes.unrestricted;
|
|
208
|
-
if (Type_1.isPrimitiveStringTypeKind(kind) && kind !== "string") {
|
|
214
|
+
if ((0, Type_1.isPrimitiveStringTypeKind)(kind) && kind !== "string") {
|
|
209
215
|
kind = stringTypeMappingGet(this._stringTypeMapping, kind);
|
|
210
216
|
}
|
|
211
217
|
if (kind === "string") {
|
|
212
218
|
return this.getStringType(attributes, stringTypes, forwardingRef);
|
|
213
219
|
}
|
|
214
|
-
return this.getOrAddType(() => Type_1.primitiveTypeIdentity(kind, attributes), tr => new Type_1.PrimitiveType(tr, this.typeGraph, kind), attributes, forwardingRef);
|
|
220
|
+
return this.getOrAddType(() => (0, Type_1.primitiveTypeIdentity)(kind, attributes), tr => new Type_1.PrimitiveType(tr, this.typeGraph, kind), attributes, forwardingRef);
|
|
215
221
|
}
|
|
216
222
|
getStringType(attributes, stringTypes, forwardingRef) {
|
|
217
|
-
const existingStringTypes = collection_utils_1.mapFind(attributes, (_, k) => k === StringTypes_1.stringTypesTypeAttributeKind);
|
|
218
|
-
Support_1.assert((stringTypes === undefined) !== (existingStringTypes === undefined), "Must instantiate string type with one enum case attribute");
|
|
223
|
+
const existingStringTypes = (0, collection_utils_1.mapFind)(attributes, (_, k) => k === StringTypes_1.stringTypesTypeAttributeKind);
|
|
224
|
+
(0, Support_1.assert)((stringTypes === undefined) !== (existingStringTypes === undefined), "Must instantiate string type with one enum case attribute");
|
|
219
225
|
if (existingStringTypes === undefined) {
|
|
220
|
-
attributes = TypeAttributes_1.combineTypeAttributes("union", attributes, StringTypes_1.stringTypesTypeAttributeKind.makeAttributes(Support_1.defined(stringTypes)));
|
|
226
|
+
attributes = (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, StringTypes_1.stringTypesTypeAttributeKind.makeAttributes((0, Support_1.defined)(stringTypes)));
|
|
221
227
|
}
|
|
222
|
-
return this.getOrAddType(() => Type_1.primitiveTypeIdentity("string", attributes), tr => new Type_1.PrimitiveType(tr, this.typeGraph, "string"), attributes, forwardingRef);
|
|
228
|
+
return this.getOrAddType(() => (0, Type_1.primitiveTypeIdentity)("string", attributes), tr => new Type_1.PrimitiveType(tr, this.typeGraph, "string"), attributes, forwardingRef);
|
|
223
229
|
}
|
|
224
230
|
getEnumType(attributes, cases, forwardingRef) {
|
|
225
|
-
return this.getOrAddType(() => Type_1.enumTypeIdentity(attributes, cases), tr => new Type_1.EnumType(tr, this.typeGraph, cases), attributes, forwardingRef);
|
|
231
|
+
return this.getOrAddType(() => (0, Type_1.enumTypeIdentity)(attributes, cases), tr => new Type_1.EnumType(tr, this.typeGraph, cases), attributes, forwardingRef);
|
|
226
232
|
}
|
|
227
233
|
makeClassProperty(tref, isOptional) {
|
|
228
234
|
return new Type_1.ClassProperty(tref, this.typeGraph, isOptional);
|
|
229
235
|
}
|
|
230
236
|
getUniqueObjectType(attributes, properties, additionalProperties, forwardingRef) {
|
|
231
237
|
this.assertTypeRefGraph(additionalProperties);
|
|
232
|
-
properties = collection_utils_1.definedMap(properties, p => this.modifyPropertiesIfNecessary(p));
|
|
238
|
+
properties = (0, collection_utils_1.definedMap)(properties, p => this.modifyPropertiesIfNecessary(p));
|
|
233
239
|
return this.addType(forwardingRef, tref => new Type_1.ObjectType(tref, this.typeGraph, "object", true, properties, additionalProperties), attributes);
|
|
234
240
|
}
|
|
235
241
|
getUniqueMapType(forwardingRef) {
|
|
@@ -237,13 +243,13 @@ class TypeBuilder {
|
|
|
237
243
|
}
|
|
238
244
|
getMapType(attributes, values, forwardingRef) {
|
|
239
245
|
this.assertTypeRefGraph(values);
|
|
240
|
-
return this.getOrAddType(() => Type_1.mapTypeIdentify(attributes, values), tr => new Type_1.MapType(tr, this.typeGraph, values), attributes, forwardingRef);
|
|
246
|
+
return this.getOrAddType(() => (0, Type_1.mapTypeIdentify)(attributes, values), tr => new Type_1.MapType(tr, this.typeGraph, values), attributes, forwardingRef);
|
|
241
247
|
}
|
|
242
248
|
setObjectProperties(ref, properties, additionalProperties) {
|
|
243
249
|
this.assertTypeRefGraph(additionalProperties);
|
|
244
|
-
const type = TypeGraph_1.derefTypeRef(ref, this.typeGraph);
|
|
250
|
+
const type = (0, TypeGraph_1.derefTypeRef)(ref, this.typeGraph);
|
|
245
251
|
if (!(type instanceof Type_1.ObjectType)) {
|
|
246
|
-
return Support_1.panic("Tried to set properties of non-object type");
|
|
252
|
+
return (0, Support_1.panic)("Tried to set properties of non-object type");
|
|
247
253
|
}
|
|
248
254
|
type.setProperties(this.modifyPropertiesIfNecessary(properties), additionalProperties);
|
|
249
255
|
this.registerType(type);
|
|
@@ -253,13 +259,13 @@ class TypeBuilder {
|
|
|
253
259
|
}
|
|
254
260
|
getArrayType(attributes, items, forwardingRef) {
|
|
255
261
|
this.assertTypeRefGraph(items);
|
|
256
|
-
return this.getOrAddType(() => Type_1.arrayTypeIdentity(attributes, items), tr => new Type_1.ArrayType(tr, this.typeGraph, items), attributes, forwardingRef);
|
|
262
|
+
return this.getOrAddType(() => (0, Type_1.arrayTypeIdentity)(attributes, items), tr => new Type_1.ArrayType(tr, this.typeGraph, items), attributes, forwardingRef);
|
|
257
263
|
}
|
|
258
264
|
setArrayItems(ref, items) {
|
|
259
265
|
this.assertTypeRefGraph(items);
|
|
260
|
-
const type = TypeGraph_1.derefTypeRef(ref, this.typeGraph);
|
|
266
|
+
const type = (0, TypeGraph_1.derefTypeRef)(ref, this.typeGraph);
|
|
261
267
|
if (!(type instanceof Type_1.ArrayType)) {
|
|
262
|
-
return Support_1.panic("Tried to set items of non-array type");
|
|
268
|
+
return (0, Support_1.panic)("Tried to set items of non-array type");
|
|
263
269
|
}
|
|
264
270
|
type.setItems(items);
|
|
265
271
|
this.registerType(type);
|
|
@@ -267,26 +273,26 @@ class TypeBuilder {
|
|
|
267
273
|
modifyPropertiesIfNecessary(properties) {
|
|
268
274
|
properties.forEach(p => this.assertTypeRefGraph(p.typeRef));
|
|
269
275
|
if (this.canonicalOrder) {
|
|
270
|
-
properties = collection_utils_1.mapSortByKey(properties);
|
|
276
|
+
properties = (0, collection_utils_1.mapSortByKey)(properties);
|
|
271
277
|
}
|
|
272
278
|
if (this._allPropertiesOptional) {
|
|
273
|
-
properties = collection_utils_1.mapMap(properties, cp => this.makeClassProperty(cp.typeRef, true));
|
|
279
|
+
properties = (0, collection_utils_1.mapMap)(properties, cp => this.makeClassProperty(cp.typeRef, true));
|
|
274
280
|
}
|
|
275
281
|
return properties;
|
|
276
282
|
}
|
|
277
283
|
getClassType(attributes, properties, forwardingRef) {
|
|
278
284
|
properties = this.modifyPropertiesIfNecessary(properties);
|
|
279
|
-
return this.getOrAddType(() => Type_1.classTypeIdentity(attributes, properties), tr => new Type_1.ClassType(tr, this.typeGraph, false, properties), attributes, forwardingRef);
|
|
285
|
+
return this.getOrAddType(() => (0, Type_1.classTypeIdentity)(attributes, properties), tr => new Type_1.ClassType(tr, this.typeGraph, false, properties), attributes, forwardingRef);
|
|
280
286
|
}
|
|
281
287
|
// FIXME: Maybe just distinguish between this and `getClassType`
|
|
282
288
|
// via a flag? That would make `ClassType.map` simpler.
|
|
283
289
|
getUniqueClassType(attributes, isFixed, properties, forwardingRef) {
|
|
284
|
-
properties = collection_utils_1.definedMap(properties, p => this.modifyPropertiesIfNecessary(p));
|
|
290
|
+
properties = (0, collection_utils_1.definedMap)(properties, p => this.modifyPropertiesIfNecessary(p));
|
|
285
291
|
return this.addType(forwardingRef, tref => new Type_1.ClassType(tref, this.typeGraph, isFixed, properties), attributes);
|
|
286
292
|
}
|
|
287
293
|
getUnionType(attributes, members, forwardingRef) {
|
|
288
294
|
this.assertTypeRefSetGraph(members);
|
|
289
|
-
return this.getOrAddType(() => Type_1.unionTypeIdentity(attributes, members), tr => new Type_1.UnionType(tr, this.typeGraph, members), attributes, forwardingRef);
|
|
295
|
+
return this.getOrAddType(() => (0, Type_1.unionTypeIdentity)(attributes, members), tr => new Type_1.UnionType(tr, this.typeGraph, members), attributes, forwardingRef);
|
|
290
296
|
}
|
|
291
297
|
// FIXME: why do we sometimes call this with defined members???
|
|
292
298
|
getUniqueUnionType(attributes, members, forwardingRef) {
|
|
@@ -295,7 +301,7 @@ class TypeBuilder {
|
|
|
295
301
|
}
|
|
296
302
|
getIntersectionType(attributes, members, forwardingRef) {
|
|
297
303
|
this.assertTypeRefSetGraph(members);
|
|
298
|
-
return this.getOrAddType(() => Type_1.intersectionTypeIdentity(attributes, members), tr => new Type_1.IntersectionType(tr, this.typeGraph, members), attributes, forwardingRef);
|
|
304
|
+
return this.getOrAddType(() => (0, Type_1.intersectionTypeIdentity)(attributes, members), tr => new Type_1.IntersectionType(tr, this.typeGraph, members), attributes, forwardingRef);
|
|
299
305
|
}
|
|
300
306
|
// FIXME: why do we sometimes call this with defined members???
|
|
301
307
|
getUniqueIntersectionType(attributes, members, forwardingRef) {
|
|
@@ -304,9 +310,9 @@ class TypeBuilder {
|
|
|
304
310
|
}
|
|
305
311
|
setSetOperationMembers(ref, members) {
|
|
306
312
|
this.assertTypeRefSetGraph(members);
|
|
307
|
-
const type = TypeGraph_1.derefTypeRef(ref, this.typeGraph);
|
|
313
|
+
const type = (0, TypeGraph_1.derefTypeRef)(ref, this.typeGraph);
|
|
308
314
|
if (!(type instanceof Type_1.UnionType || type instanceof Type_1.IntersectionType)) {
|
|
309
|
-
return Support_1.panic("Tried to set members of non-set-operation type");
|
|
315
|
+
return (0, Support_1.panic)("Tried to set members of non-set-operation type");
|
|
310
316
|
}
|
|
311
317
|
type.setMembers(members);
|
|
312
318
|
this.registerType(type);
|
|
@@ -4,7 +4,7 @@ import { TypeBuilder, StringTypeMapping } from "./TypeBuilder";
|
|
|
4
4
|
import { GraphRewriteBuilder, BaseGraphRewriteBuilder } from "./GraphRewriting";
|
|
5
5
|
import { Graph } from "./Graph";
|
|
6
6
|
import { TypeAttributeKind, TypeAttributes } from "./attributes/TypeAttributes";
|
|
7
|
-
export
|
|
7
|
+
export type TypeRef = number;
|
|
8
8
|
export declare function isTypeRef(x: any): x is TypeRef;
|
|
9
9
|
export declare function makeTypeRef(graph: TypeGraph, index: number): TypeRef;
|
|
10
10
|
export declare function typeRefIndex(tref: TypeRef): number;
|
|
@@ -48,10 +48,10 @@ export declare class TypeGraph {
|
|
|
48
48
|
private _parents;
|
|
49
49
|
private _printOnRewrite;
|
|
50
50
|
constructor(typeBuilder: TypeBuilder, serial: number, _haveProvenanceAttributes: boolean);
|
|
51
|
-
private
|
|
52
|
-
|
|
51
|
+
private get isFrozen();
|
|
52
|
+
get attributeStore(): TypeAttributeStore;
|
|
53
53
|
freeze(topLevels: ReadonlyMap<string, TypeRef>, types: Type[], typeAttributes: (TypeAttributes | undefined)[]): void;
|
|
54
|
-
|
|
54
|
+
get topLevels(): ReadonlyMap<string, Type>;
|
|
55
55
|
typeAtIndex(index: number): Type;
|
|
56
56
|
atIndex(index: number): [Type, TypeAttributes];
|
|
57
57
|
private filterTypes;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeIndirectionIntersections = exports.optionalToNullable = exports.noneToAny = exports.TypeGraph = exports.TypeAttributeStoreView = exports.TypeAttributeStore = exports.typeAndAttributesForTypeRef = exports.attributesForTypeRef = exports.derefTypeRef = exports.assertTypeRefGraph = exports.typeRefIndex = exports.makeTypeRef = exports.isTypeRef = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const Type_1 = require("./Type");
|
|
5
6
|
const TypeUtils_1 = require("./TypeUtils");
|
|
@@ -19,7 +20,7 @@ function isTypeRef(x) {
|
|
|
19
20
|
}
|
|
20
21
|
exports.isTypeRef = isTypeRef;
|
|
21
22
|
function makeTypeRef(graph, index) {
|
|
22
|
-
Support_1.assert(index <= indexMask, "Too many types in graph");
|
|
23
|
+
(0, Support_1.assert)(index <= indexMask, "Too many types in graph");
|
|
23
24
|
return ((graph.serial & serialMask) << indexBits) | index;
|
|
24
25
|
}
|
|
25
26
|
exports.makeTypeRef = makeTypeRef;
|
|
@@ -28,7 +29,7 @@ function typeRefIndex(tref) {
|
|
|
28
29
|
}
|
|
29
30
|
exports.typeRefIndex = typeRefIndex;
|
|
30
31
|
function assertTypeRefGraph(tref, graph) {
|
|
31
|
-
Support_1.assert(((tref >> indexBits) & serialMask) === (graph.serial & serialMask), "Mixing the wrong type reference and graph");
|
|
32
|
+
(0, Support_1.assert)(((tref >> indexBits) & serialMask) === (graph.serial & serialMask), "Mixing the wrong type reference and graph");
|
|
32
33
|
}
|
|
33
34
|
exports.assertTypeRefGraph = assertTypeRefGraph;
|
|
34
35
|
function getGraph(graphOrBuilder) {
|
|
@@ -55,10 +56,12 @@ function typeAndAttributesForTypeRef(tref, graphOrBuilder) {
|
|
|
55
56
|
}
|
|
56
57
|
exports.typeAndAttributesForTypeRef = typeAndAttributesForTypeRef;
|
|
57
58
|
class TypeAttributeStore {
|
|
59
|
+
_typeGraph;
|
|
60
|
+
_values;
|
|
61
|
+
_topLevelValues = new Map();
|
|
58
62
|
constructor(_typeGraph, _values) {
|
|
59
63
|
this._typeGraph = _typeGraph;
|
|
60
64
|
this._values = _values;
|
|
61
|
-
this._topLevelValues = new Map();
|
|
62
65
|
}
|
|
63
66
|
getTypeIndex(t) {
|
|
64
67
|
const tref = t.typeRef;
|
|
@@ -106,6 +109,8 @@ class TypeAttributeStore {
|
|
|
106
109
|
}
|
|
107
110
|
exports.TypeAttributeStore = TypeAttributeStore;
|
|
108
111
|
class TypeAttributeStoreView {
|
|
112
|
+
_attributeStore;
|
|
113
|
+
_definition;
|
|
109
114
|
constructor(_attributeStore, _definition) {
|
|
110
115
|
this._attributeStore = _attributeStore;
|
|
111
116
|
this._definition = _definition;
|
|
@@ -120,36 +125,40 @@ class TypeAttributeStoreView {
|
|
|
120
125
|
return this._attributeStore.tryGet(this._definition, t);
|
|
121
126
|
}
|
|
122
127
|
get(t) {
|
|
123
|
-
return Support_1.defined(this.tryGet(t));
|
|
128
|
+
return (0, Support_1.defined)(this.tryGet(t));
|
|
124
129
|
}
|
|
125
130
|
tryGetForTopLevel(name) {
|
|
126
131
|
return this._attributeStore.tryGetForTopLevel(this._definition, name);
|
|
127
132
|
}
|
|
128
133
|
getForTopLevel(name) {
|
|
129
|
-
return Support_1.defined(this.tryGetForTopLevel(name));
|
|
134
|
+
return (0, Support_1.defined)(this.tryGetForTopLevel(name));
|
|
130
135
|
}
|
|
131
136
|
}
|
|
132
137
|
exports.TypeAttributeStoreView = TypeAttributeStoreView;
|
|
133
138
|
class TypeGraph {
|
|
139
|
+
serial;
|
|
140
|
+
_haveProvenanceAttributes;
|
|
141
|
+
_typeBuilder;
|
|
142
|
+
_attributeStore = undefined;
|
|
143
|
+
// FIXME: OrderedMap? We lose the order in PureScript right now, though,
|
|
144
|
+
// and maybe even earlier in the TypeScript driver.
|
|
145
|
+
_topLevels = new Map();
|
|
146
|
+
_types;
|
|
147
|
+
_parents = undefined;
|
|
148
|
+
_printOnRewrite = false;
|
|
134
149
|
constructor(typeBuilder, serial, _haveProvenanceAttributes) {
|
|
135
150
|
this.serial = serial;
|
|
136
151
|
this._haveProvenanceAttributes = _haveProvenanceAttributes;
|
|
137
|
-
this._attributeStore = undefined;
|
|
138
|
-
// FIXME: OrderedMap? We lose the order in PureScript right now, though,
|
|
139
|
-
// and maybe even earlier in the TypeScript driver.
|
|
140
|
-
this._topLevels = new Map();
|
|
141
|
-
this._parents = undefined;
|
|
142
|
-
this._printOnRewrite = false;
|
|
143
152
|
this._typeBuilder = typeBuilder;
|
|
144
153
|
}
|
|
145
154
|
get isFrozen() {
|
|
146
155
|
return this._typeBuilder === undefined;
|
|
147
156
|
}
|
|
148
157
|
get attributeStore() {
|
|
149
|
-
return Support_1.defined(this._attributeStore);
|
|
158
|
+
return (0, Support_1.defined)(this._attributeStore);
|
|
150
159
|
}
|
|
151
160
|
freeze(topLevels, types, typeAttributes) {
|
|
152
|
-
Support_1.assert(!this.isFrozen, "Tried to freeze TypeGraph a second time");
|
|
161
|
+
(0, Support_1.assert)(!this.isFrozen, "Tried to freeze TypeGraph a second time");
|
|
153
162
|
for (const t of types) {
|
|
154
163
|
assertTypeRefGraph(t.typeRef, this);
|
|
155
164
|
}
|
|
@@ -160,24 +169,24 @@ class TypeGraph {
|
|
|
160
169
|
// either a _typeBuilder or a _types.
|
|
161
170
|
this._types = types;
|
|
162
171
|
this._typeBuilder = undefined;
|
|
163
|
-
this._topLevels = collection_utils_1.mapMap(topLevels, tref => derefTypeRef(tref, this));
|
|
172
|
+
this._topLevels = (0, collection_utils_1.mapMap)(topLevels, tref => derefTypeRef(tref, this));
|
|
164
173
|
}
|
|
165
174
|
get topLevels() {
|
|
166
|
-
Support_1.assert(this.isFrozen, "Cannot get top-levels from a non-frozen graph");
|
|
175
|
+
(0, Support_1.assert)(this.isFrozen, "Cannot get top-levels from a non-frozen graph");
|
|
167
176
|
return this._topLevels;
|
|
168
177
|
}
|
|
169
178
|
typeAtIndex(index) {
|
|
170
179
|
if (this._typeBuilder !== undefined) {
|
|
171
180
|
return this._typeBuilder.typeAtIndex(index);
|
|
172
181
|
}
|
|
173
|
-
return Support_1.defined(this._types)[index];
|
|
182
|
+
return (0, Support_1.defined)(this._types)[index];
|
|
174
183
|
}
|
|
175
184
|
atIndex(index) {
|
|
176
185
|
if (this._typeBuilder !== undefined) {
|
|
177
186
|
return this._typeBuilder.atIndex(index);
|
|
178
187
|
}
|
|
179
188
|
const t = this.typeAtIndex(index);
|
|
180
|
-
return [t, Support_1.defined(this._attributeStore).attributesForType(t)];
|
|
189
|
+
return [t, (0, Support_1.defined)(this._attributeStore).attributesForType(t)];
|
|
181
190
|
}
|
|
182
191
|
filterTypes(predicate) {
|
|
183
192
|
const seen = new Set();
|
|
@@ -204,10 +213,10 @@ class TypeGraph {
|
|
|
204
213
|
}
|
|
205
214
|
allNamedTypesSeparated() {
|
|
206
215
|
const types = this.allNamedTypes();
|
|
207
|
-
return TypeUtils_1.separateNamedTypes(types);
|
|
216
|
+
return (0, TypeUtils_1.separateNamedTypes)(types);
|
|
208
217
|
}
|
|
209
218
|
allProvenance() {
|
|
210
|
-
Support_1.assert(this._haveProvenanceAttributes);
|
|
219
|
+
(0, Support_1.assert)(this._haveProvenanceAttributes);
|
|
211
220
|
const view = new TypeAttributeStoreView(this.attributeStore, TypeBuilder_1.provenanceTypeAttributeKind);
|
|
212
221
|
const sets = Array.from(this.allTypesUnordered()).map(t => {
|
|
213
222
|
const maybeSet = view.tryGet(t);
|
|
@@ -216,7 +225,7 @@ class TypeGraph {
|
|
|
216
225
|
return new Set();
|
|
217
226
|
});
|
|
218
227
|
const result = new Set();
|
|
219
|
-
collection_utils_1.setUnionManyInto(result, sets);
|
|
228
|
+
(0, collection_utils_1.setUnionManyInto)(result, sets);
|
|
220
229
|
return result;
|
|
221
230
|
}
|
|
222
231
|
setPrintOnRewrite() {
|
|
@@ -228,9 +237,9 @@ class TypeGraph {
|
|
|
228
237
|
const oldProvenance = this.allProvenance();
|
|
229
238
|
const newProvenance = newGraph.allProvenance();
|
|
230
239
|
if (oldProvenance.size !== newProvenance.size) {
|
|
231
|
-
const difference = collection_utils_1.setSubtract(oldProvenance, newProvenance);
|
|
240
|
+
const difference = (0, collection_utils_1.setSubtract)(oldProvenance, newProvenance);
|
|
232
241
|
const indexes = Array.from(difference);
|
|
233
|
-
return Messages_1.messageError("IRTypeAttributesNotPropagated", { count: difference.size, indexes });
|
|
242
|
+
return (0, Messages_1.messageError)("IRTypeAttributesNotPropagated", { count: difference.size, indexes });
|
|
234
243
|
}
|
|
235
244
|
}
|
|
236
245
|
printRewrite(title) {
|
|
@@ -270,17 +279,17 @@ class TypeGraph {
|
|
|
270
279
|
newGraph.setPrintOnRewrite();
|
|
271
280
|
newGraph.printGraph();
|
|
272
281
|
}
|
|
273
|
-
Support_1.assert(!builder.didAddForwardingIntersection);
|
|
282
|
+
(0, Support_1.assert)(!builder.didAddForwardingIntersection);
|
|
274
283
|
return newGraph;
|
|
275
284
|
}
|
|
276
285
|
garbageCollect(alphabetizeProperties, debugPrintReconstitution) {
|
|
277
|
-
const newGraph = this.remap("GC", TypeBuilder_1.getNoStringTypeMapping(), alphabetizeProperties, new Map(), debugPrintReconstitution, true);
|
|
286
|
+
const newGraph = this.remap("GC", (0, TypeBuilder_1.getNoStringTypeMapping)(), alphabetizeProperties, new Map(), debugPrintReconstitution, true);
|
|
278
287
|
return newGraph;
|
|
279
288
|
}
|
|
280
289
|
rewriteFixedPoint(alphabetizeProperties, debugPrintReconstitution) {
|
|
281
290
|
let graph = this;
|
|
282
291
|
for (;;) {
|
|
283
|
-
const newGraph = this.rewrite("fixed-point", TypeBuilder_1.getNoStringTypeMapping(), alphabetizeProperties, [], debugPrintReconstitution, Support_1.mustNotHappen, true);
|
|
292
|
+
const newGraph = this.rewrite("fixed-point", (0, TypeBuilder_1.getNoStringTypeMapping)(), alphabetizeProperties, [], debugPrintReconstitution, Support_1.mustNotHappen, true);
|
|
284
293
|
if (graph.allTypesUnordered().size === newGraph.allTypesUnordered().size) {
|
|
285
294
|
return graph;
|
|
286
295
|
}
|
|
@@ -288,16 +297,16 @@ class TypeGraph {
|
|
|
288
297
|
}
|
|
289
298
|
}
|
|
290
299
|
allTypesUnordered() {
|
|
291
|
-
Support_1.assert(this.isFrozen, "Tried to get all graph types before it was frozen");
|
|
292
|
-
return new Set(Support_1.defined(this._types));
|
|
300
|
+
(0, Support_1.assert)(this.isFrozen, "Tried to get all graph types before it was frozen");
|
|
301
|
+
return new Set((0, Support_1.defined)(this._types));
|
|
293
302
|
}
|
|
294
303
|
makeGraph(invertDirection, childrenOfType) {
|
|
295
|
-
return new Graph_1.Graph(Support_1.defined(this._types), invertDirection, childrenOfType);
|
|
304
|
+
return new Graph_1.Graph((0, Support_1.defined)(this._types), invertDirection, childrenOfType);
|
|
296
305
|
}
|
|
297
306
|
getParentsOfType(t) {
|
|
298
307
|
assertTypeRefGraph(t.typeRef, this);
|
|
299
308
|
if (this._parents === undefined) {
|
|
300
|
-
const parents = Support_1.defined(this._types).map(_ => new Set());
|
|
309
|
+
const parents = (0, Support_1.defined)(this._types).map(_ => new Set());
|
|
301
310
|
for (const p of this.allTypesUnordered()) {
|
|
302
311
|
for (const c of p.getChildren()) {
|
|
303
312
|
const index = c.index;
|
|
@@ -309,7 +318,7 @@ class TypeGraph {
|
|
|
309
318
|
return this._parents[t.index];
|
|
310
319
|
}
|
|
311
320
|
printGraph() {
|
|
312
|
-
const types = Support_1.defined(this._types);
|
|
321
|
+
const types = (0, Support_1.defined)(this._types);
|
|
313
322
|
for (let i = 0; i < types.length; i++) {
|
|
314
323
|
const t = types[i];
|
|
315
324
|
const parts = [];
|
|
@@ -332,13 +341,13 @@ class TypeGraph {
|
|
|
332
341
|
}
|
|
333
342
|
exports.TypeGraph = TypeGraph;
|
|
334
343
|
function noneToAny(graph, stringTypeMapping, debugPrintReconstitution) {
|
|
335
|
-
const noneTypes = collection_utils_1.setFilter(graph.allTypesUnordered(), t => t.kind === "none");
|
|
344
|
+
const noneTypes = (0, collection_utils_1.setFilter)(graph.allTypesUnordered(), t => t.kind === "none");
|
|
336
345
|
if (noneTypes.size === 0) {
|
|
337
346
|
return graph;
|
|
338
347
|
}
|
|
339
|
-
Support_1.assert(noneTypes.size === 1, "Cannot have more than one none type");
|
|
348
|
+
(0, Support_1.assert)(noneTypes.size === 1, "Cannot have more than one none type");
|
|
340
349
|
return graph.rewrite("none to any", stringTypeMapping, false, [Array.from(noneTypes)], debugPrintReconstitution, (types, builder, forwardingRef) => {
|
|
341
|
-
const attributes = TypeUtils_1.combineTypeAttributesOfTypes("union", types);
|
|
350
|
+
const attributes = (0, TypeUtils_1.combineTypeAttributesOfTypes)("union", types);
|
|
342
351
|
const tref = builder.getPrimitiveType("any", attributes, forwardingRef);
|
|
343
352
|
return tref;
|
|
344
353
|
});
|
|
@@ -346,7 +355,7 @@ function noneToAny(graph, stringTypeMapping, debugPrintReconstitution) {
|
|
|
346
355
|
exports.noneToAny = noneToAny;
|
|
347
356
|
function optionalToNullable(graph, stringTypeMapping, debugPrintReconstitution) {
|
|
348
357
|
function rewriteClass(c, builder, forwardingRef) {
|
|
349
|
-
const properties = collection_utils_1.mapMap(c.getProperties(), (p, name) => {
|
|
358
|
+
const properties = (0, collection_utils_1.mapMap)(c.getProperties(), (p, name) => {
|
|
350
359
|
const t = p.type;
|
|
351
360
|
let ref;
|
|
352
361
|
if (!p.isOptional || t.isNullable) {
|
|
@@ -356,7 +365,7 @@ function optionalToNullable(graph, stringTypeMapping, debugPrintReconstitution)
|
|
|
356
365
|
const nullType = builder.getPrimitiveType("null");
|
|
357
366
|
let members;
|
|
358
367
|
if (t instanceof Type_1.UnionType) {
|
|
359
|
-
members = collection_utils_1.setMap(t.members, m => builder.reconstituteType(m)).add(nullType);
|
|
368
|
+
members = (0, collection_utils_1.setMap)(t.members, m => builder.reconstituteType(m)).add(nullType);
|
|
360
369
|
}
|
|
361
370
|
else {
|
|
362
371
|
members = new Set([builder.reconstituteType(t), nullType]);
|
|
@@ -373,14 +382,14 @@ function optionalToNullable(graph, stringTypeMapping, debugPrintReconstitution)
|
|
|
373
382
|
return builder.getClassType(c.getAttributes(), properties, forwardingRef);
|
|
374
383
|
}
|
|
375
384
|
}
|
|
376
|
-
const classesWithOptional = collection_utils_1.setFilter(graph.allTypesUnordered(), t => t instanceof Type_1.ClassType && collection_utils_1.mapSome(t.getProperties(), p => p.isOptional));
|
|
385
|
+
const classesWithOptional = (0, collection_utils_1.setFilter)(graph.allTypesUnordered(), t => t instanceof Type_1.ClassType && (0, collection_utils_1.mapSome)(t.getProperties(), p => p.isOptional));
|
|
377
386
|
const replacementGroups = Array.from(classesWithOptional).map(c => [c]);
|
|
378
387
|
if (classesWithOptional.size === 0) {
|
|
379
388
|
return graph;
|
|
380
389
|
}
|
|
381
390
|
return graph.rewrite("optional to nullable", stringTypeMapping, false, replacementGroups, debugPrintReconstitution, (setOfClass, builder, forwardingRef) => {
|
|
382
|
-
Support_1.assert(setOfClass.size === 1);
|
|
383
|
-
const c = Support_1.defined(collection_utils_1.iterableFirst(setOfClass));
|
|
391
|
+
(0, Support_1.assert)(setOfClass.size === 1);
|
|
392
|
+
const c = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(setOfClass));
|
|
384
393
|
return rewriteClass(c, builder, forwardingRef);
|
|
385
394
|
});
|
|
386
395
|
}
|
|
@@ -393,14 +402,14 @@ function removeIndirectionIntersections(graph, stringTypeMapping, debugPrintRema
|
|
|
393
402
|
const seen = new Set([t]);
|
|
394
403
|
let current = t;
|
|
395
404
|
while (current.members.size === 1) {
|
|
396
|
-
const member = Support_1.defined(collection_utils_1.iterableFirst(current.members));
|
|
405
|
+
const member = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(current.members));
|
|
397
406
|
if (!(member instanceof Type_1.IntersectionType)) {
|
|
398
407
|
map.push([t, member]);
|
|
399
408
|
break;
|
|
400
409
|
}
|
|
401
410
|
if (seen.has(member)) {
|
|
402
411
|
// FIXME: Technically, this is an any type.
|
|
403
|
-
return Support_1.panic("There's a cycle of intersection types");
|
|
412
|
+
return (0, Support_1.panic)("There's a cycle of intersection types");
|
|
404
413
|
}
|
|
405
414
|
seen.add(member);
|
|
406
415
|
current = member;
|
|
@@ -14,7 +14,7 @@ export declare function nullableFromUnion(t: UnionType): Type | null;
|
|
|
14
14
|
export declare function nonNullTypeCases(t: Type): ReadonlySet<Type>;
|
|
15
15
|
export declare function getNullAsOptional(cp: ClassProperty): [boolean, ReadonlySet<Type>];
|
|
16
16
|
export declare function isNamedType(t: Type): boolean;
|
|
17
|
-
export
|
|
17
|
+
export type SeparatedNamedTypes = {
|
|
18
18
|
objects: ReadonlySet<ObjectType>;
|
|
19
19
|
enums: ReadonlySet<EnumType>;
|
|
20
20
|
unions: ReadonlySet<UnionType>;
|
|
@@ -23,7 +23,7 @@ export declare function separateNamedTypes(types: Iterable<Type>): SeparatedName
|
|
|
23
23
|
export declare function directlyReachableTypes<T>(t: Type, setForType: (t: Type) => ReadonlySet<T> | null): ReadonlySet<T>;
|
|
24
24
|
export declare function directlyReachableSingleNamedType(type: Type): Type | undefined;
|
|
25
25
|
export declare function stringTypesForType(t: PrimitiveType): StringTypes;
|
|
26
|
-
export
|
|
26
|
+
export type StringTypeMatchers<U> = {
|
|
27
27
|
dateType?: (dateType: PrimitiveType) => U;
|
|
28
28
|
timeType?: (timeType: PrimitiveType) => U;
|
|
29
29
|
dateTimeType?: (dateTimeType: PrimitiveType) => U;
|