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,420 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
4
|
-
const collection_utils_1 = require("collection-utils");
|
|
5
|
-
const Type_1 = require("./Type");
|
|
6
|
-
const TypeUtils_1 = require("./TypeUtils");
|
|
7
|
-
const Support_1 = require("./support/Support");
|
|
8
|
-
const TypeBuilder_1 = require("./TypeBuilder");
|
|
9
|
-
const GraphRewriting_1 = require("./GraphRewriting");
|
|
10
|
-
const TypeNames_1 = require("./attributes/TypeNames");
|
|
11
|
-
const Graph_1 = require("./Graph");
|
|
12
|
-
const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
13
|
-
const Messages_1 = require("./Messages");
|
|
14
|
-
const indexBits = 26;
|
|
15
|
-
const indexMask = (1 << indexBits) - 1;
|
|
16
|
-
const serialBits = 31 - indexBits;
|
|
17
|
-
const serialMask = (1 << serialBits) - 1;
|
|
18
|
-
function isTypeRef(x) {
|
|
19
|
-
return typeof x === "number";
|
|
20
|
-
}
|
|
21
|
-
exports.isTypeRef = isTypeRef;
|
|
22
|
-
function makeTypeRef(graph, index) {
|
|
23
|
-
(0, Support_1.assert)(index <= indexMask, "Too many types in graph");
|
|
24
|
-
return ((graph.serial & serialMask) << indexBits) | index;
|
|
25
|
-
}
|
|
26
|
-
exports.makeTypeRef = makeTypeRef;
|
|
27
|
-
function typeRefIndex(tref) {
|
|
28
|
-
return tref & indexMask;
|
|
29
|
-
}
|
|
30
|
-
exports.typeRefIndex = typeRefIndex;
|
|
31
|
-
function assertTypeRefGraph(tref, graph) {
|
|
32
|
-
(0, Support_1.assert)(((tref >> indexBits) & serialMask) === (graph.serial & serialMask), "Mixing the wrong type reference and graph");
|
|
33
|
-
}
|
|
34
|
-
exports.assertTypeRefGraph = assertTypeRefGraph;
|
|
35
|
-
function getGraph(graphOrBuilder) {
|
|
36
|
-
if (graphOrBuilder instanceof TypeGraph)
|
|
37
|
-
return graphOrBuilder;
|
|
38
|
-
return graphOrBuilder.originalGraph;
|
|
39
|
-
}
|
|
40
|
-
function derefTypeRef(tref, graphOrBuilder) {
|
|
41
|
-
const graph = getGraph(graphOrBuilder);
|
|
42
|
-
assertTypeRefGraph(tref, graph);
|
|
43
|
-
return graph.typeAtIndex(typeRefIndex(tref));
|
|
44
|
-
}
|
|
45
|
-
exports.derefTypeRef = derefTypeRef;
|
|
46
|
-
function attributesForTypeRef(tref, graphOrBuilder) {
|
|
47
|
-
const graph = getGraph(graphOrBuilder);
|
|
48
|
-
assertTypeRefGraph(tref, graph);
|
|
49
|
-
return graph.atIndex(typeRefIndex(tref))[1];
|
|
50
|
-
}
|
|
51
|
-
exports.attributesForTypeRef = attributesForTypeRef;
|
|
52
|
-
function typeAndAttributesForTypeRef(tref, graphOrBuilder) {
|
|
53
|
-
const graph = getGraph(graphOrBuilder);
|
|
54
|
-
assertTypeRefGraph(tref, graph);
|
|
55
|
-
return graph.atIndex(typeRefIndex(tref));
|
|
56
|
-
}
|
|
57
|
-
exports.typeAndAttributesForTypeRef = typeAndAttributesForTypeRef;
|
|
58
|
-
class TypeAttributeStore {
|
|
59
|
-
_typeGraph;
|
|
60
|
-
_values;
|
|
61
|
-
_topLevelValues = new Map();
|
|
62
|
-
constructor(_typeGraph, _values) {
|
|
63
|
-
this._typeGraph = _typeGraph;
|
|
64
|
-
this._values = _values;
|
|
65
|
-
}
|
|
66
|
-
getTypeIndex(t) {
|
|
67
|
-
const tref = t.typeRef;
|
|
68
|
-
assertTypeRefGraph(tref, this._typeGraph);
|
|
69
|
-
return typeRefIndex(tref);
|
|
70
|
-
}
|
|
71
|
-
attributesForType(t) {
|
|
72
|
-
const index = this.getTypeIndex(t);
|
|
73
|
-
const maybeAttributes = this._values[index];
|
|
74
|
-
if (maybeAttributes !== undefined) {
|
|
75
|
-
return maybeAttributes;
|
|
76
|
-
}
|
|
77
|
-
return TypeAttributes_1.emptyTypeAttributes;
|
|
78
|
-
}
|
|
79
|
-
attributesForTopLevel(name) {
|
|
80
|
-
const maybeAttributes = this._topLevelValues.get(name);
|
|
81
|
-
if (maybeAttributes !== undefined) {
|
|
82
|
-
return maybeAttributes;
|
|
83
|
-
}
|
|
84
|
-
return TypeAttributes_1.emptyTypeAttributes;
|
|
85
|
-
}
|
|
86
|
-
setInMap(attributes, kind, value) {
|
|
87
|
-
// FIXME: This is potentially super slow
|
|
88
|
-
return new Map(attributes).set(kind, value);
|
|
89
|
-
}
|
|
90
|
-
set(kind, t, value) {
|
|
91
|
-
const index = this.getTypeIndex(t);
|
|
92
|
-
while (index >= this._values.length) {
|
|
93
|
-
this._values.push(undefined);
|
|
94
|
-
}
|
|
95
|
-
this._values[index] = this.setInMap(this.attributesForType(t), kind, value);
|
|
96
|
-
}
|
|
97
|
-
setForTopLevel(kind, topLevelName, value) {
|
|
98
|
-
this._topLevelValues.set(topLevelName, this.setInMap(this.attributesForTopLevel(topLevelName), kind, value));
|
|
99
|
-
}
|
|
100
|
-
tryGetInMap(attributes, kind) {
|
|
101
|
-
return attributes.get(kind);
|
|
102
|
-
}
|
|
103
|
-
tryGet(kind, t) {
|
|
104
|
-
return this.tryGetInMap(this.attributesForType(t), kind);
|
|
105
|
-
}
|
|
106
|
-
tryGetForTopLevel(kind, topLevelName) {
|
|
107
|
-
return this.tryGetInMap(this.attributesForTopLevel(topLevelName), kind);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
exports.TypeAttributeStore = TypeAttributeStore;
|
|
111
|
-
class TypeAttributeStoreView {
|
|
112
|
-
_attributeStore;
|
|
113
|
-
_definition;
|
|
114
|
-
constructor(_attributeStore, _definition) {
|
|
115
|
-
this._attributeStore = _attributeStore;
|
|
116
|
-
this._definition = _definition;
|
|
117
|
-
}
|
|
118
|
-
set(t, value) {
|
|
119
|
-
this._attributeStore.set(this._definition, t, value);
|
|
120
|
-
}
|
|
121
|
-
setForTopLevel(name, value) {
|
|
122
|
-
this._attributeStore.setForTopLevel(this._definition, name, value);
|
|
123
|
-
}
|
|
124
|
-
tryGet(t) {
|
|
125
|
-
return this._attributeStore.tryGet(this._definition, t);
|
|
126
|
-
}
|
|
127
|
-
get(t) {
|
|
128
|
-
return (0, Support_1.defined)(this.tryGet(t));
|
|
129
|
-
}
|
|
130
|
-
tryGetForTopLevel(name) {
|
|
131
|
-
return this._attributeStore.tryGetForTopLevel(this._definition, name);
|
|
132
|
-
}
|
|
133
|
-
getForTopLevel(name) {
|
|
134
|
-
return (0, Support_1.defined)(this.tryGetForTopLevel(name));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.TypeAttributeStoreView = TypeAttributeStoreView;
|
|
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;
|
|
149
|
-
constructor(typeBuilder, serial, _haveProvenanceAttributes) {
|
|
150
|
-
this.serial = serial;
|
|
151
|
-
this._haveProvenanceAttributes = _haveProvenanceAttributes;
|
|
152
|
-
this._typeBuilder = typeBuilder;
|
|
153
|
-
}
|
|
154
|
-
get isFrozen() {
|
|
155
|
-
return this._typeBuilder === undefined;
|
|
156
|
-
}
|
|
157
|
-
get attributeStore() {
|
|
158
|
-
return (0, Support_1.defined)(this._attributeStore);
|
|
159
|
-
}
|
|
160
|
-
freeze(topLevels, types, typeAttributes) {
|
|
161
|
-
(0, Support_1.assert)(!this.isFrozen, "Tried to freeze TypeGraph a second time");
|
|
162
|
-
for (const t of types) {
|
|
163
|
-
assertTypeRefGraph(t.typeRef, this);
|
|
164
|
-
}
|
|
165
|
-
this._attributeStore = new TypeAttributeStore(this, typeAttributes);
|
|
166
|
-
// The order of these three statements matters. If we set _typeBuilder
|
|
167
|
-
// to undefined before we deref the TypeRefs, then we need to set _types
|
|
168
|
-
// before, also, because the deref will call into typeAtIndex, which requires
|
|
169
|
-
// either a _typeBuilder or a _types.
|
|
170
|
-
this._types = types;
|
|
171
|
-
this._typeBuilder = undefined;
|
|
172
|
-
this._topLevels = (0, collection_utils_1.mapMap)(topLevels, tref => derefTypeRef(tref, this));
|
|
173
|
-
}
|
|
174
|
-
get topLevels() {
|
|
175
|
-
(0, Support_1.assert)(this.isFrozen, "Cannot get top-levels from a non-frozen graph");
|
|
176
|
-
return this._topLevels;
|
|
177
|
-
}
|
|
178
|
-
typeAtIndex(index) {
|
|
179
|
-
if (this._typeBuilder !== undefined) {
|
|
180
|
-
return this._typeBuilder.typeAtIndex(index);
|
|
181
|
-
}
|
|
182
|
-
return (0, Support_1.defined)(this._types)[index];
|
|
183
|
-
}
|
|
184
|
-
atIndex(index) {
|
|
185
|
-
if (this._typeBuilder !== undefined) {
|
|
186
|
-
return this._typeBuilder.atIndex(index);
|
|
187
|
-
}
|
|
188
|
-
const t = this.typeAtIndex(index);
|
|
189
|
-
return [t, (0, Support_1.defined)(this._attributeStore).attributesForType(t)];
|
|
190
|
-
}
|
|
191
|
-
filterTypes(predicate) {
|
|
192
|
-
const seen = new Set();
|
|
193
|
-
let types = [];
|
|
194
|
-
function addFromType(t) {
|
|
195
|
-
if (seen.has(t))
|
|
196
|
-
return;
|
|
197
|
-
seen.add(t);
|
|
198
|
-
const required = predicate === undefined || predicate(t);
|
|
199
|
-
if (required) {
|
|
200
|
-
types.push(t);
|
|
201
|
-
}
|
|
202
|
-
for (const c of t.getChildren()) {
|
|
203
|
-
addFromType(c);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
for (const [, t] of this.topLevels) {
|
|
207
|
-
addFromType(t);
|
|
208
|
-
}
|
|
209
|
-
return new Set(types);
|
|
210
|
-
}
|
|
211
|
-
allNamedTypes() {
|
|
212
|
-
return this.filterTypes(TypeUtils_1.isNamedType);
|
|
213
|
-
}
|
|
214
|
-
allNamedTypesSeparated() {
|
|
215
|
-
const types = this.allNamedTypes();
|
|
216
|
-
return (0, TypeUtils_1.separateNamedTypes)(types);
|
|
217
|
-
}
|
|
218
|
-
allProvenance() {
|
|
219
|
-
(0, Support_1.assert)(this._haveProvenanceAttributes);
|
|
220
|
-
const view = new TypeAttributeStoreView(this.attributeStore, TypeBuilder_1.provenanceTypeAttributeKind);
|
|
221
|
-
const sets = Array.from(this.allTypesUnordered()).map(t => {
|
|
222
|
-
const maybeSet = view.tryGet(t);
|
|
223
|
-
if (maybeSet !== undefined)
|
|
224
|
-
return maybeSet;
|
|
225
|
-
return new Set();
|
|
226
|
-
});
|
|
227
|
-
const result = new Set();
|
|
228
|
-
(0, collection_utils_1.setUnionManyInto)(result, sets);
|
|
229
|
-
return result;
|
|
230
|
-
}
|
|
231
|
-
setPrintOnRewrite() {
|
|
232
|
-
this._printOnRewrite = true;
|
|
233
|
-
}
|
|
234
|
-
checkLostTypeAttributes(builder, newGraph) {
|
|
235
|
-
if (!this._haveProvenanceAttributes || builder.lostTypeAttributes)
|
|
236
|
-
return;
|
|
237
|
-
const oldProvenance = this.allProvenance();
|
|
238
|
-
const newProvenance = newGraph.allProvenance();
|
|
239
|
-
if (oldProvenance.size !== newProvenance.size) {
|
|
240
|
-
const difference = (0, collection_utils_1.setSubtract)(oldProvenance, newProvenance);
|
|
241
|
-
const indexes = Array.from(difference);
|
|
242
|
-
return (0, Messages_1.messageError)("IRTypeAttributesNotPropagated", { count: difference.size, indexes });
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
printRewrite(title) {
|
|
246
|
-
if (!this._printOnRewrite)
|
|
247
|
-
return;
|
|
248
|
-
console.log(`\n# ${title}`);
|
|
249
|
-
}
|
|
250
|
-
// Each array in `replacementGroups` is a bunch of types to be replaced by a
|
|
251
|
-
// single new type. `replacer` is a function that takes a group and a
|
|
252
|
-
// TypeBuilder, and builds a new type with that builder that replaces the group.
|
|
253
|
-
// That particular TypeBuilder will have to take as inputs types in the old
|
|
254
|
-
// graph, but return types in the new graph. Recursive types must be handled
|
|
255
|
-
// carefully.
|
|
256
|
-
rewrite(title, stringTypeMapping, alphabetizeProperties, replacementGroups, debugPrintReconstitution, replacer, force = false) {
|
|
257
|
-
this.printRewrite(title);
|
|
258
|
-
if (!force && replacementGroups.length === 0)
|
|
259
|
-
return this;
|
|
260
|
-
const builder = new GraphRewriting_1.GraphRewriteBuilder(this, stringTypeMapping, alphabetizeProperties, this._haveProvenanceAttributes, replacementGroups, debugPrintReconstitution, replacer);
|
|
261
|
-
const newGraph = builder.finish();
|
|
262
|
-
this.checkLostTypeAttributes(builder, newGraph);
|
|
263
|
-
if (this._printOnRewrite) {
|
|
264
|
-
newGraph.setPrintOnRewrite();
|
|
265
|
-
newGraph.printGraph();
|
|
266
|
-
}
|
|
267
|
-
if (!builder.didAddForwardingIntersection)
|
|
268
|
-
return newGraph;
|
|
269
|
-
return removeIndirectionIntersections(newGraph, stringTypeMapping, debugPrintReconstitution);
|
|
270
|
-
}
|
|
271
|
-
remap(title, stringTypeMapping, alphabetizeProperties, map, debugPrintRemapping, force = false) {
|
|
272
|
-
this.printRewrite(title);
|
|
273
|
-
if (!force && map.size === 0)
|
|
274
|
-
return this;
|
|
275
|
-
const builder = new GraphRewriting_1.GraphRemapBuilder(this, stringTypeMapping, alphabetizeProperties, this._haveProvenanceAttributes, map, debugPrintRemapping);
|
|
276
|
-
const newGraph = builder.finish();
|
|
277
|
-
this.checkLostTypeAttributes(builder, newGraph);
|
|
278
|
-
if (this._printOnRewrite) {
|
|
279
|
-
newGraph.setPrintOnRewrite();
|
|
280
|
-
newGraph.printGraph();
|
|
281
|
-
}
|
|
282
|
-
(0, Support_1.assert)(!builder.didAddForwardingIntersection);
|
|
283
|
-
return newGraph;
|
|
284
|
-
}
|
|
285
|
-
garbageCollect(alphabetizeProperties, debugPrintReconstitution) {
|
|
286
|
-
const newGraph = this.remap("GC", (0, TypeBuilder_1.getNoStringTypeMapping)(), alphabetizeProperties, new Map(), debugPrintReconstitution, true);
|
|
287
|
-
return newGraph;
|
|
288
|
-
}
|
|
289
|
-
rewriteFixedPoint(alphabetizeProperties, debugPrintReconstitution) {
|
|
290
|
-
let graph = this;
|
|
291
|
-
for (;;) {
|
|
292
|
-
const newGraph = this.rewrite("fixed-point", (0, TypeBuilder_1.getNoStringTypeMapping)(), alphabetizeProperties, [], debugPrintReconstitution, Support_1.mustNotHappen, true);
|
|
293
|
-
if (graph.allTypesUnordered().size === newGraph.allTypesUnordered().size) {
|
|
294
|
-
return graph;
|
|
295
|
-
}
|
|
296
|
-
graph = newGraph;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
allTypesUnordered() {
|
|
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));
|
|
302
|
-
}
|
|
303
|
-
makeGraph(invertDirection, childrenOfType) {
|
|
304
|
-
return new Graph_1.Graph((0, Support_1.defined)(this._types), invertDirection, childrenOfType);
|
|
305
|
-
}
|
|
306
|
-
getParentsOfType(t) {
|
|
307
|
-
assertTypeRefGraph(t.typeRef, this);
|
|
308
|
-
if (this._parents === undefined) {
|
|
309
|
-
const parents = (0, Support_1.defined)(this._types).map(_ => new Set());
|
|
310
|
-
for (const p of this.allTypesUnordered()) {
|
|
311
|
-
for (const c of p.getChildren()) {
|
|
312
|
-
const index = c.index;
|
|
313
|
-
parents[index] = parents[index].add(p);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
this._parents = parents;
|
|
317
|
-
}
|
|
318
|
-
return this._parents[t.index];
|
|
319
|
-
}
|
|
320
|
-
printGraph() {
|
|
321
|
-
const types = (0, Support_1.defined)(this._types);
|
|
322
|
-
for (let i = 0; i < types.length; i++) {
|
|
323
|
-
const t = types[i];
|
|
324
|
-
const parts = [];
|
|
325
|
-
parts.push(`${t.debugPrintKind}${t.hasNames ? ` ${t.getCombinedName()}` : ""}`);
|
|
326
|
-
const children = t.getChildren();
|
|
327
|
-
if (children.size > 0) {
|
|
328
|
-
parts.push(`children ${Array.from(children)
|
|
329
|
-
.map(c => c.index)
|
|
330
|
-
.join(",")}`);
|
|
331
|
-
}
|
|
332
|
-
for (const [kind, value] of t.getAttributes()) {
|
|
333
|
-
const maybeString = kind.stringify(value);
|
|
334
|
-
if (maybeString !== undefined) {
|
|
335
|
-
parts.push(maybeString);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
console.log(`${i}: ${parts.join(" | ")}`);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
exports.TypeGraph = TypeGraph;
|
|
343
|
-
function noneToAny(graph, stringTypeMapping, debugPrintReconstitution) {
|
|
344
|
-
const noneTypes = (0, collection_utils_1.setFilter)(graph.allTypesUnordered(), t => t.kind === "none");
|
|
345
|
-
if (noneTypes.size === 0) {
|
|
346
|
-
return graph;
|
|
347
|
-
}
|
|
348
|
-
(0, Support_1.assert)(noneTypes.size === 1, "Cannot have more than one none type");
|
|
349
|
-
return graph.rewrite("none to any", stringTypeMapping, false, [Array.from(noneTypes)], debugPrintReconstitution, (types, builder, forwardingRef) => {
|
|
350
|
-
const attributes = (0, TypeUtils_1.combineTypeAttributesOfTypes)("union", types);
|
|
351
|
-
const tref = builder.getPrimitiveType("any", attributes, forwardingRef);
|
|
352
|
-
return tref;
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
exports.noneToAny = noneToAny;
|
|
356
|
-
function optionalToNullable(graph, stringTypeMapping, debugPrintReconstitution) {
|
|
357
|
-
function rewriteClass(c, builder, forwardingRef) {
|
|
358
|
-
const properties = (0, collection_utils_1.mapMap)(c.getProperties(), (p, name) => {
|
|
359
|
-
const t = p.type;
|
|
360
|
-
let ref;
|
|
361
|
-
if (!p.isOptional || t.isNullable) {
|
|
362
|
-
ref = builder.reconstituteType(t);
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
const nullType = builder.getPrimitiveType("null");
|
|
366
|
-
let members;
|
|
367
|
-
if (t instanceof Type_1.UnionType) {
|
|
368
|
-
members = (0, collection_utils_1.setMap)(t.members, m => builder.reconstituteType(m)).add(nullType);
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
members = new Set([builder.reconstituteType(t), nullType]);
|
|
372
|
-
}
|
|
373
|
-
const attributes = TypeNames_1.namesTypeAttributeKind.setDefaultInAttributes(t.getAttributes(), () => TypeNames_1.TypeNames.make(new Set([name]), new Set(), true));
|
|
374
|
-
ref = builder.getUnionType(attributes, members);
|
|
375
|
-
}
|
|
376
|
-
return builder.makeClassProperty(ref, p.isOptional);
|
|
377
|
-
});
|
|
378
|
-
if (c.isFixed) {
|
|
379
|
-
return builder.getUniqueClassType(c.getAttributes(), true, properties, forwardingRef);
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
return builder.getClassType(c.getAttributes(), properties, forwardingRef);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
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));
|
|
386
|
-
const replacementGroups = Array.from(classesWithOptional).map(c => [c]);
|
|
387
|
-
if (classesWithOptional.size === 0) {
|
|
388
|
-
return graph;
|
|
389
|
-
}
|
|
390
|
-
return graph.rewrite("optional to nullable", stringTypeMapping, false, replacementGroups, debugPrintReconstitution, (setOfClass, builder, forwardingRef) => {
|
|
391
|
-
(0, Support_1.assert)(setOfClass.size === 1);
|
|
392
|
-
const c = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(setOfClass));
|
|
393
|
-
return rewriteClass(c, builder, forwardingRef);
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
exports.optionalToNullable = optionalToNullable;
|
|
397
|
-
function removeIndirectionIntersections(graph, stringTypeMapping, debugPrintRemapping) {
|
|
398
|
-
const map = [];
|
|
399
|
-
for (const t of graph.allTypesUnordered()) {
|
|
400
|
-
if (!(t instanceof Type_1.IntersectionType))
|
|
401
|
-
continue;
|
|
402
|
-
const seen = new Set([t]);
|
|
403
|
-
let current = t;
|
|
404
|
-
while (current.members.size === 1) {
|
|
405
|
-
const member = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(current.members));
|
|
406
|
-
if (!(member instanceof Type_1.IntersectionType)) {
|
|
407
|
-
map.push([t, member]);
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
if (seen.has(member)) {
|
|
411
|
-
// FIXME: Technically, this is an any type.
|
|
412
|
-
return (0, Support_1.panic)("There's a cycle of intersection types");
|
|
413
|
-
}
|
|
414
|
-
seen.add(member);
|
|
415
|
-
current = member;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return graph.remap("remove indirection intersections", stringTypeMapping, false, new Map(map), debugPrintRemapping);
|
|
419
|
-
}
|
|
420
|
-
exports.removeIndirectionIntersections = removeIndirectionIntersections;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { TypeAttributes, CombinationKind } from "./attributes/TypeAttributes";
|
|
2
|
-
import { Type, PrimitiveType, ArrayType, EnumType, ObjectType, MapType, ClassType, ClassProperty, SetOperationType, UnionType } from "./Type";
|
|
3
|
-
import { StringTypes } from "./attributes/StringTypes";
|
|
4
|
-
export declare function assertIsObject(t: Type): ObjectType;
|
|
5
|
-
export declare function assertIsClass(t: Type): ClassType;
|
|
6
|
-
export declare function setOperationMembersRecursively<T extends SetOperationType>(setOperation: T, combinationKind: CombinationKind | undefined): [ReadonlySet<Type>, TypeAttributes];
|
|
7
|
-
export declare function setOperationMembersRecursively<T extends SetOperationType>(setOperations: T[], combinationKind: CombinationKind | undefined): [ReadonlySet<Type>, TypeAttributes];
|
|
8
|
-
export declare function makeGroupsToFlatten<T extends SetOperationType>(setOperations: Iterable<T>, include: ((members: ReadonlySet<Type>) => boolean) | undefined): Type[][];
|
|
9
|
-
export declare function combineTypeAttributesOfTypes(combinationKind: CombinationKind, types: Iterable<Type>): TypeAttributes;
|
|
10
|
-
export declare function isAnyOrNull(t: Type): boolean;
|
|
11
|
-
export declare function removeNullFromUnion(t: UnionType, sortBy?: boolean | ((t: Type) => any)): [PrimitiveType | null, ReadonlySet<Type>];
|
|
12
|
-
export declare function removeNullFromType(t: Type): [PrimitiveType | null, ReadonlySet<Type>];
|
|
13
|
-
export declare function nullableFromUnion(t: UnionType): Type | null;
|
|
14
|
-
export declare function nonNullTypeCases(t: Type): ReadonlySet<Type>;
|
|
15
|
-
export declare function getNullAsOptional(cp: ClassProperty): [boolean, ReadonlySet<Type>];
|
|
16
|
-
export declare function isNamedType(t: Type): boolean;
|
|
17
|
-
export type SeparatedNamedTypes = {
|
|
18
|
-
objects: ReadonlySet<ObjectType>;
|
|
19
|
-
enums: ReadonlySet<EnumType>;
|
|
20
|
-
unions: ReadonlySet<UnionType>;
|
|
21
|
-
};
|
|
22
|
-
export declare function separateNamedTypes(types: Iterable<Type>): SeparatedNamedTypes;
|
|
23
|
-
export declare function directlyReachableTypes<T>(t: Type, setForType: (t: Type) => ReadonlySet<T> | null): ReadonlySet<T>;
|
|
24
|
-
export declare function directlyReachableSingleNamedType(type: Type): Type | undefined;
|
|
25
|
-
export declare function stringTypesForType(t: PrimitiveType): StringTypes;
|
|
26
|
-
export type StringTypeMatchers<U> = {
|
|
27
|
-
dateType?: (dateType: PrimitiveType) => U;
|
|
28
|
-
timeType?: (timeType: PrimitiveType) => U;
|
|
29
|
-
dateTimeType?: (dateTimeType: PrimitiveType) => U;
|
|
30
|
-
};
|
|
31
|
-
export declare function matchTypeExhaustive<U>(t: Type, noneType: (noneType: PrimitiveType) => U, anyType: (anyType: PrimitiveType) => U, nullType: (nullType: PrimitiveType) => U, boolType: (boolType: PrimitiveType) => U, integerType: (integerType: PrimitiveType) => U, doubleType: (doubleType: PrimitiveType) => U, stringType: (stringType: PrimitiveType) => U, arrayType: (arrayType: ArrayType) => U, classType: (classType: ClassType) => U, mapType: (mapType: MapType) => U, objectType: (objectType: ObjectType) => U, enumType: (enumType: EnumType) => U, unionType: (unionType: UnionType) => U, transformedStringType: (transformedStringType: PrimitiveType) => U): U;
|
|
32
|
-
export declare function matchType<U>(type: Type, anyType: (anyType: PrimitiveType) => U, nullType: (nullType: PrimitiveType) => U, boolType: (boolType: PrimitiveType) => U, integerType: (integerType: PrimitiveType) => U, doubleType: (doubleType: PrimitiveType) => U, stringType: (stringType: PrimitiveType) => U, arrayType: (arrayType: ArrayType) => U, classType: (classType: ClassType) => U, mapType: (mapType: MapType) => U, enumType: (enumType: EnumType) => U, unionType: (unionType: UnionType) => U, transformedStringType?: (transformedStringType: PrimitiveType) => U): U;
|
|
33
|
-
export declare function matchCompoundType(t: Type, arrayType: (arrayType: ArrayType) => void, classType: (classType: ClassType) => void, mapType: (mapType: MapType) => void, objectType: (objectType: ObjectType) => void, unionType: (unionType: UnionType) => void): void;
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.matchCompoundType = exports.matchType = exports.matchTypeExhaustive = exports.stringTypesForType = exports.directlyReachableSingleNamedType = exports.directlyReachableTypes = exports.separateNamedTypes = exports.isNamedType = exports.getNullAsOptional = exports.nonNullTypeCases = exports.nullableFromUnion = exports.removeNullFromType = exports.removeNullFromUnion = exports.isAnyOrNull = exports.combineTypeAttributesOfTypes = exports.makeGroupsToFlatten = exports.setOperationMembersRecursively = exports.assertIsClass = exports.assertIsObject = void 0;
|
|
4
|
-
const collection_utils_1 = require("collection-utils");
|
|
5
|
-
const Support_1 = require("./support/Support");
|
|
6
|
-
const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
7
|
-
const Type_1 = require("./Type");
|
|
8
|
-
const StringTypes_1 = require("./attributes/StringTypes");
|
|
9
|
-
function assertIsObject(t) {
|
|
10
|
-
if (t instanceof Type_1.ObjectType) {
|
|
11
|
-
return t;
|
|
12
|
-
}
|
|
13
|
-
return (0, Support_1.panic)("Supposed object type is not an object type");
|
|
14
|
-
}
|
|
15
|
-
exports.assertIsObject = assertIsObject;
|
|
16
|
-
function assertIsClass(t) {
|
|
17
|
-
if (!(t instanceof Type_1.ClassType)) {
|
|
18
|
-
return (0, Support_1.panic)("Supposed class type is not a class type");
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
}
|
|
22
|
-
exports.assertIsClass = assertIsClass;
|
|
23
|
-
function setOperationMembersRecursively(oneOrMany, combinationKind) {
|
|
24
|
-
const setOperations = Array.isArray(oneOrMany) ? oneOrMany : [oneOrMany];
|
|
25
|
-
const kind = setOperations[0].kind;
|
|
26
|
-
const includeAny = kind !== "intersection";
|
|
27
|
-
const processedSetOperations = new Set();
|
|
28
|
-
const members = new Set();
|
|
29
|
-
let attributes = TypeAttributes_1.emptyTypeAttributes;
|
|
30
|
-
function process(t) {
|
|
31
|
-
if (t.kind === kind) {
|
|
32
|
-
const so = t;
|
|
33
|
-
if (processedSetOperations.has(so))
|
|
34
|
-
return;
|
|
35
|
-
processedSetOperations.add(so);
|
|
36
|
-
if (combinationKind !== undefined) {
|
|
37
|
-
attributes = (0, TypeAttributes_1.combineTypeAttributes)(combinationKind, attributes, t.getAttributes());
|
|
38
|
-
}
|
|
39
|
-
for (const m of so.members) {
|
|
40
|
-
process(m);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else if (includeAny || t.kind !== "any") {
|
|
44
|
-
members.add(t);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
if (combinationKind !== undefined) {
|
|
48
|
-
attributes = (0, TypeAttributes_1.combineTypeAttributes)(combinationKind, attributes, t.getAttributes());
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
for (const so of setOperations) {
|
|
53
|
-
process(so);
|
|
54
|
-
}
|
|
55
|
-
return [members, attributes];
|
|
56
|
-
}
|
|
57
|
-
exports.setOperationMembersRecursively = setOperationMembersRecursively;
|
|
58
|
-
function makeGroupsToFlatten(setOperations, include) {
|
|
59
|
-
const typeGroups = new collection_utils_1.EqualityMap();
|
|
60
|
-
for (const u of setOperations) {
|
|
61
|
-
// FIXME: We shouldn't have to make a new set here once we got rid
|
|
62
|
-
// of immutable.
|
|
63
|
-
const members = new Set(setOperationMembersRecursively(u, undefined)[0]);
|
|
64
|
-
if (include !== undefined) {
|
|
65
|
-
if (!include(members))
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
let maybeSet = typeGroups.get(members);
|
|
69
|
-
if (maybeSet === undefined) {
|
|
70
|
-
maybeSet = new Set();
|
|
71
|
-
if (members.size === 1) {
|
|
72
|
-
maybeSet.add((0, Support_1.defined)((0, collection_utils_1.iterableFirst)(members)));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
maybeSet.add(u);
|
|
76
|
-
typeGroups.set(members, maybeSet);
|
|
77
|
-
}
|
|
78
|
-
return Array.from(typeGroups.values()).map(ts => Array.from(ts));
|
|
79
|
-
}
|
|
80
|
-
exports.makeGroupsToFlatten = makeGroupsToFlatten;
|
|
81
|
-
function combineTypeAttributesOfTypes(combinationKind, types) {
|
|
82
|
-
return (0, TypeAttributes_1.combineTypeAttributes)(combinationKind, Array.from(types).map(t => t.getAttributes()));
|
|
83
|
-
}
|
|
84
|
-
exports.combineTypeAttributesOfTypes = combineTypeAttributesOfTypes;
|
|
85
|
-
function isAnyOrNull(t) {
|
|
86
|
-
return t.kind === "any" || t.kind === "null";
|
|
87
|
-
}
|
|
88
|
-
exports.isAnyOrNull = isAnyOrNull;
|
|
89
|
-
// FIXME: We shouldn't have to sort here. This is just because we're not getting
|
|
90
|
-
// back the right order from JSON Schema, due to the changes the intersection types
|
|
91
|
-
// introduced.
|
|
92
|
-
function removeNullFromUnion(t, sortBy = false) {
|
|
93
|
-
function sort(s) {
|
|
94
|
-
if (sortBy === false)
|
|
95
|
-
return s;
|
|
96
|
-
if (sortBy === true)
|
|
97
|
-
return (0, collection_utils_1.setSortBy)(s, m => m.kind);
|
|
98
|
-
return (0, collection_utils_1.setSortBy)(s, sortBy);
|
|
99
|
-
}
|
|
100
|
-
const nullType = t.findMember("null");
|
|
101
|
-
if (nullType === undefined) {
|
|
102
|
-
return [null, sort(t.members)];
|
|
103
|
-
}
|
|
104
|
-
return [nullType, sort((0, collection_utils_1.setFilter)(t.members, m => m.kind !== "null"))];
|
|
105
|
-
}
|
|
106
|
-
exports.removeNullFromUnion = removeNullFromUnion;
|
|
107
|
-
function removeNullFromType(t) {
|
|
108
|
-
if (t.kind === "null") {
|
|
109
|
-
return [t, new Set()];
|
|
110
|
-
}
|
|
111
|
-
if (!(t instanceof Type_1.UnionType)) {
|
|
112
|
-
return [null, new Set([t])];
|
|
113
|
-
}
|
|
114
|
-
return removeNullFromUnion(t);
|
|
115
|
-
}
|
|
116
|
-
exports.removeNullFromType = removeNullFromType;
|
|
117
|
-
function nullableFromUnion(t) {
|
|
118
|
-
const [hasNull, nonNulls] = removeNullFromUnion(t);
|
|
119
|
-
if (hasNull === null)
|
|
120
|
-
return null;
|
|
121
|
-
if (nonNulls.size !== 1)
|
|
122
|
-
return null;
|
|
123
|
-
return (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(nonNulls));
|
|
124
|
-
}
|
|
125
|
-
exports.nullableFromUnion = nullableFromUnion;
|
|
126
|
-
function nonNullTypeCases(t) {
|
|
127
|
-
return removeNullFromType(t)[1];
|
|
128
|
-
}
|
|
129
|
-
exports.nonNullTypeCases = nonNullTypeCases;
|
|
130
|
-
function getNullAsOptional(cp) {
|
|
131
|
-
const [maybeNull, nonNulls] = removeNullFromType(cp.type);
|
|
132
|
-
if (cp.isOptional) {
|
|
133
|
-
return [true, nonNulls];
|
|
134
|
-
}
|
|
135
|
-
return [maybeNull !== null, nonNulls];
|
|
136
|
-
}
|
|
137
|
-
exports.getNullAsOptional = getNullAsOptional;
|
|
138
|
-
// FIXME: Give this an appropriate name, considering that we don't distinguish
|
|
139
|
-
// between named and non-named types anymore.
|
|
140
|
-
function isNamedType(t) {
|
|
141
|
-
return ["class", "union", "enum", "object"].indexOf(t.kind) >= 0;
|
|
142
|
-
}
|
|
143
|
-
exports.isNamedType = isNamedType;
|
|
144
|
-
function separateNamedTypes(types) {
|
|
145
|
-
const objects = (0, collection_utils_1.setFilter)(types, t => t.kind === "object" || t.kind === "class");
|
|
146
|
-
const enums = (0, collection_utils_1.setFilter)(types, t => t instanceof Type_1.EnumType);
|
|
147
|
-
const unions = (0, collection_utils_1.setFilter)(types, t => t instanceof Type_1.UnionType);
|
|
148
|
-
return { objects, enums, unions };
|
|
149
|
-
}
|
|
150
|
-
exports.separateNamedTypes = separateNamedTypes;
|
|
151
|
-
function directlyReachableTypes(t, setForType) {
|
|
152
|
-
const set = setForType(t);
|
|
153
|
-
if (set !== null)
|
|
154
|
-
return set;
|
|
155
|
-
return (0, collection_utils_1.setUnion)(...Array.from(t.getNonAttributeChildren()).map(c => directlyReachableTypes(c, setForType)));
|
|
156
|
-
}
|
|
157
|
-
exports.directlyReachableTypes = directlyReachableTypes;
|
|
158
|
-
function directlyReachableSingleNamedType(type) {
|
|
159
|
-
const definedTypes = directlyReachableTypes(type, t => {
|
|
160
|
-
if ((!(t instanceof Type_1.UnionType) && isNamedType(t)) ||
|
|
161
|
-
(t instanceof Type_1.UnionType && nullableFromUnion(t) === null)) {
|
|
162
|
-
return new Set([t]);
|
|
163
|
-
}
|
|
164
|
-
return null;
|
|
165
|
-
});
|
|
166
|
-
(0, Support_1.assert)(definedTypes.size <= 1, "Cannot have more than one defined type per top-level");
|
|
167
|
-
return (0, collection_utils_1.iterableFirst)(definedTypes);
|
|
168
|
-
}
|
|
169
|
-
exports.directlyReachableSingleNamedType = directlyReachableSingleNamedType;
|
|
170
|
-
function stringTypesForType(t) {
|
|
171
|
-
(0, Support_1.assert)(t.kind === "string", "Only strings can have string types");
|
|
172
|
-
const stringTypes = StringTypes_1.stringTypesTypeAttributeKind.tryGetInAttributes(t.getAttributes());
|
|
173
|
-
if (stringTypes === undefined) {
|
|
174
|
-
return (0, Support_1.panic)("All strings must have a string type attribute");
|
|
175
|
-
}
|
|
176
|
-
return stringTypes;
|
|
177
|
-
}
|
|
178
|
-
exports.stringTypesForType = stringTypesForType;
|
|
179
|
-
function matchTypeExhaustive(t, noneType, anyType, nullType, boolType, integerType, doubleType, stringType, arrayType, classType, mapType, objectType, enumType, unionType, transformedStringType) {
|
|
180
|
-
if (t.isPrimitive()) {
|
|
181
|
-
if ((0, Type_1.isPrimitiveStringTypeKind)(t.kind)) {
|
|
182
|
-
if (t.kind === "string") {
|
|
183
|
-
return stringType(t);
|
|
184
|
-
}
|
|
185
|
-
return transformedStringType(t);
|
|
186
|
-
}
|
|
187
|
-
const kind = t.kind;
|
|
188
|
-
const f = {
|
|
189
|
-
none: noneType,
|
|
190
|
-
any: anyType,
|
|
191
|
-
null: nullType,
|
|
192
|
-
bool: boolType,
|
|
193
|
-
integer: integerType,
|
|
194
|
-
double: doubleType
|
|
195
|
-
}[kind];
|
|
196
|
-
if (f !== undefined)
|
|
197
|
-
return f(t);
|
|
198
|
-
return (0, Support_1.assertNever)(f);
|
|
199
|
-
}
|
|
200
|
-
else if (t instanceof Type_1.ArrayType)
|
|
201
|
-
return arrayType(t);
|
|
202
|
-
else if (t instanceof Type_1.ClassType)
|
|
203
|
-
return classType(t);
|
|
204
|
-
else if (t instanceof Type_1.MapType)
|
|
205
|
-
return mapType(t);
|
|
206
|
-
else if (t instanceof Type_1.ObjectType)
|
|
207
|
-
return objectType(t);
|
|
208
|
-
else if (t instanceof Type_1.EnumType)
|
|
209
|
-
return enumType(t);
|
|
210
|
-
else if (t instanceof Type_1.UnionType)
|
|
211
|
-
return unionType(t);
|
|
212
|
-
return (0, Support_1.panic)(`Unknown type ${t.kind}`);
|
|
213
|
-
}
|
|
214
|
-
exports.matchTypeExhaustive = matchTypeExhaustive;
|
|
215
|
-
function matchType(type, anyType, nullType, boolType, integerType, doubleType, stringType, arrayType, classType, mapType, enumType, unionType, transformedStringType) {
|
|
216
|
-
function typeNotSupported(t) {
|
|
217
|
-
return (0, Support_1.panic)(`Unsupported type ${t.kind} in non-exhaustive match`);
|
|
218
|
-
}
|
|
219
|
-
/* tslint:disable:strict-boolean-expressions */
|
|
220
|
-
return matchTypeExhaustive(type, typeNotSupported, anyType, nullType, boolType, integerType, doubleType, stringType, arrayType, classType, mapType, typeNotSupported, enumType, unionType, transformedStringType || typeNotSupported);
|
|
221
|
-
/* tslint:enable */
|
|
222
|
-
}
|
|
223
|
-
exports.matchType = matchType;
|
|
224
|
-
function matchCompoundType(t, arrayType, classType, mapType, objectType, unionType) {
|
|
225
|
-
function ignore(_) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
return matchTypeExhaustive(t, ignore, ignore, ignore, ignore, ignore, ignore, ignore, arrayType, classType, mapType, objectType, ignore, unionType, ignore);
|
|
229
|
-
}
|
|
230
|
-
exports.matchCompoundType = matchCompoundType;
|