quicktype 17.0.3 → 17.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/CompressedJSONFromStream.js +38 -26
- package/dist/cli/GraphQLIntrospection.js +41 -33
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +3 -4
- package/dist/cli/index.js +364 -363
- package/dist/quicktype-core/Annotation.js +0 -2
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +81 -104
- package/dist/quicktype-core/DateTime.js +0 -1
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +10 -13
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -1
- package/dist/quicktype-core/GatherNames.js +25 -47
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +19 -23
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +54 -65
- package/dist/quicktype-core/MakeTransformations.js +22 -23
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +8 -9
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +3 -8
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +61 -76
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +17 -34
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +3 -6
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +67 -72
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +18 -19
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +2 -6
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +66 -94
- package/dist/quicktype-core/Type.d.ts +43 -41
- package/dist/quicktype-core/Type.js +71 -96
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +47 -53
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +40 -49
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +22 -23
- package/dist/quicktype-core/UnifyClasses.js +12 -16
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +30 -33
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +17 -18
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +4 -8
- package/dist/quicktype-core/attributes/Description.js +5 -6
- package/dist/quicktype-core/attributes/EnumValues.js +3 -4
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +21 -24
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +10 -12
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +21 -49
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +6 -10
- package/dist/quicktype-core/index.js +125 -128
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +54 -49
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +13 -5
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +17 -25
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +54 -38
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +523 -503
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +35 -24
- package/dist/quicktype-core/input/PostmanCollection.js +1 -2
- package/dist/quicktype-core/input/io/NodeIO.js +44 -55
- package/dist/quicktype-core/input/io/get-stream/index.js +2 -6
- package/dist/quicktype-core/language/All.js +2 -3
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +151 -185
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +72 -82
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +17 -18
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +34 -36
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +45 -47
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +20 -23
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +23 -25
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +16 -17
- package/dist/quicktype-core/language/Java.d.ts +2 -2
- package/dist/quicktype-core/language/Java.js +97 -97
- package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
- package/dist/quicktype-core/language/JavaScript.js +17 -19
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +13 -15
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +11 -12
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +37 -39
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +41 -45
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +41 -66
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +17 -18
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +64 -63
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +19 -21
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +804 -807
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +26 -28
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +24 -49
- package/dist/quicktype-core/language/ruby/keywords.js +0 -1
- package/dist/quicktype-core/rewrites/CombineClasses.js +8 -9
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +17 -18
- package/dist/quicktype-core/rewrites/FlattenStrings.js +6 -7
- package/dist/quicktype-core/rewrites/FlattenUnions.js +8 -9
- package/dist/quicktype-core/rewrites/InferMaps.js +10 -11
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +7 -8
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +67 -68
- package/dist/quicktype-core/support/Acronyms.js +1 -3
- package/dist/quicktype-core/support/Chance.js +0 -10
- package/dist/quicktype-core/support/Converters.js +0 -1
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +16 -17
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +6 -30
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -1
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +212 -229
- package/dist/quicktype-typescript-input/index.js +4 -28
- package/package.json +19 -25
|
@@ -1,30 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
|
|
27
|
-
const pluralize = __importStar(require("pluralize"));
|
|
3
|
+
const pluralize = require("pluralize");
|
|
28
4
|
const collection_utils_1 = require("collection-utils");
|
|
29
5
|
const Type_1 = require("./Type");
|
|
30
6
|
const TypeUtils_1 = require("./TypeUtils");
|
|
@@ -32,9 +8,11 @@ const TypeNames_1 = require("./attributes/TypeNames");
|
|
|
32
8
|
const Support_1 = require("./support/Support");
|
|
33
9
|
const Transformers_1 = require("./Transformers");
|
|
34
10
|
class UniqueQueue {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
11
|
+
constructor() {
|
|
12
|
+
this._present = new Set();
|
|
13
|
+
this._queue = [];
|
|
14
|
+
this._front = 0;
|
|
15
|
+
}
|
|
38
16
|
get size() {
|
|
39
17
|
return this._queue.length - this._front;
|
|
40
18
|
}
|
|
@@ -48,10 +26,10 @@ class UniqueQueue {
|
|
|
48
26
|
this._present.add(v);
|
|
49
27
|
}
|
|
50
28
|
unshift() {
|
|
51
|
-
|
|
29
|
+
Support_1.assert(!this.isEmpty, "Trying to unshift from an empty queue");
|
|
52
30
|
const v = this._queue[this._front];
|
|
53
31
|
if (v === undefined) {
|
|
54
|
-
return
|
|
32
|
+
return Support_1.panic("Value should have been present in queue");
|
|
55
33
|
}
|
|
56
34
|
this._queue[this._front] = undefined;
|
|
57
35
|
this._front += 1;
|
|
@@ -131,13 +109,13 @@ function gatherNames(graph, destructive, debugPrint) {
|
|
|
131
109
|
newNames = null;
|
|
132
110
|
}
|
|
133
111
|
else {
|
|
134
|
-
newNames =
|
|
112
|
+
newNames = collection_utils_1.setUnion(oldNames, names);
|
|
135
113
|
}
|
|
136
114
|
if (newNames !== null && newNames.size >= TypeNames_1.tooManyNamesThreshold) {
|
|
137
115
|
newNames = null;
|
|
138
116
|
}
|
|
139
117
|
namesForType.set(t, newNames);
|
|
140
|
-
const transformation =
|
|
118
|
+
const transformation = Transformers_1.transformationForType(t);
|
|
141
119
|
if (transformation !== undefined) {
|
|
142
120
|
addNames(transformation.targetType, names);
|
|
143
121
|
}
|
|
@@ -156,7 +134,7 @@ function gatherNames(graph, destructive, debugPrint) {
|
|
|
156
134
|
}
|
|
157
135
|
while (!queue.isEmpty) {
|
|
158
136
|
const t = queue.unshift();
|
|
159
|
-
const names =
|
|
137
|
+
const names = Support_1.defined(namesForType.get(t));
|
|
160
138
|
if (t instanceof Type_1.ObjectType) {
|
|
161
139
|
const properties = t.getSortedProperties();
|
|
162
140
|
for (const [propertyName, property] of properties) {
|
|
@@ -164,14 +142,14 @@ function gatherNames(graph, destructive, debugPrint) {
|
|
|
164
142
|
}
|
|
165
143
|
const values = t.getAdditionalProperties();
|
|
166
144
|
if (values !== undefined) {
|
|
167
|
-
addNames(values, names === null ? null :
|
|
145
|
+
addNames(values, names === null ? null : collection_utils_1.setMap(names, pluralize.singular));
|
|
168
146
|
}
|
|
169
147
|
}
|
|
170
148
|
else {
|
|
171
|
-
|
|
172
|
-
addNames(arrayType.items, names === null ? null :
|
|
173
|
-
}, _classType =>
|
|
174
|
-
const members =
|
|
149
|
+
TypeUtils_1.matchCompoundType(t, arrayType => {
|
|
150
|
+
addNames(arrayType.items, names === null ? null : collection_utils_1.setMap(names, pluralize.singular));
|
|
151
|
+
}, _classType => Support_1.panic("We handled this above"), _mapType => Support_1.panic("We handled this above"), _objectType => Support_1.panic("We handled this above"), unionType => {
|
|
152
|
+
const members = collection_utils_1.setSortBy(unionType.members, member => member.kind);
|
|
175
153
|
for (const memberType of members) {
|
|
176
154
|
addNames(memberType, names);
|
|
177
155
|
}
|
|
@@ -198,14 +176,14 @@ function gatherNames(graph, destructive, debugPrint) {
|
|
|
198
176
|
if (existing === undefined) {
|
|
199
177
|
existing = new Set();
|
|
200
178
|
}
|
|
201
|
-
existing =
|
|
179
|
+
existing = collection_utils_1.setUnion(existing, alternatives);
|
|
202
180
|
if (existing.size < TypeNames_1.tooManyNamesThreshold) {
|
|
203
181
|
return existing;
|
|
204
182
|
}
|
|
205
183
|
return null;
|
|
206
184
|
}
|
|
207
185
|
function processType(ancestor, t, alternativeSuffix) {
|
|
208
|
-
const names =
|
|
186
|
+
const names = Support_1.defined(namesForType.get(t));
|
|
209
187
|
let processedEntry = pairsProcessed.get(ancestor);
|
|
210
188
|
if (processedEntry === undefined)
|
|
211
189
|
processedEntry = new Set();
|
|
@@ -213,7 +191,7 @@ function gatherNames(graph, destructive, debugPrint) {
|
|
|
213
191
|
return;
|
|
214
192
|
processedEntry.add(t);
|
|
215
193
|
pairsProcessed.set(ancestor, processedEntry);
|
|
216
|
-
const transformation =
|
|
194
|
+
const transformation = Transformers_1.transformationForType(t);
|
|
217
195
|
if (transformation !== undefined) {
|
|
218
196
|
processType(ancestor, transformation.targetType, alternativeSuffix);
|
|
219
197
|
}
|
|
@@ -266,12 +244,12 @@ function gatherNames(graph, destructive, debugPrint) {
|
|
|
266
244
|
}
|
|
267
245
|
}
|
|
268
246
|
else {
|
|
269
|
-
|
|
247
|
+
TypeUtils_1.matchCompoundType(t, arrayType => {
|
|
270
248
|
processType(ancestor, arrayType.items, "element");
|
|
271
|
-
}, _classType =>
|
|
272
|
-
const members =
|
|
249
|
+
}, _classType => Support_1.panic("We handled this above"), _mapType => Support_1.panic("We handled this above"), _objectType => Support_1.panic("We handled this above"), unionType => {
|
|
250
|
+
const members = collection_utils_1.setSortBy(unionType.members, member => member.kind);
|
|
273
251
|
const unionHasGivenName = unionType.hasNames && !unionType.getNames().areInferred;
|
|
274
|
-
const unionIsAncestor = unionHasGivenName ||
|
|
252
|
+
const unionIsAncestor = unionHasGivenName || TypeUtils_1.nullableFromUnion(unionType) === null;
|
|
275
253
|
const ancestorForMembers = unionIsAncestor ? unionType : ancestor;
|
|
276
254
|
for (const memberType of members) {
|
|
277
255
|
processType(ancestorForMembers, memberType, undefined);
|
|
@@ -296,7 +274,7 @@ function gatherNames(graph, destructive, debugPrint) {
|
|
|
296
274
|
if (alternatives === undefined) {
|
|
297
275
|
alternatives = new Set();
|
|
298
276
|
}
|
|
299
|
-
alternatives =
|
|
277
|
+
alternatives = collection_utils_1.setUnion(alternatives, collection_utils_1.setMap(names, name => `${name}_${t.kind}`));
|
|
300
278
|
directAlternativesForType.set(t, alternatives);
|
|
301
279
|
}
|
|
302
280
|
for (const t of graph.allTypesUnordered()) {
|
|
@@ -322,7 +300,7 @@ function gatherNames(graph, destructive, debugPrint) {
|
|
|
322
300
|
alternatives = new Set();
|
|
323
301
|
}
|
|
324
302
|
if (ancestorAlternatives !== null && ancestorAlternatives !== undefined) {
|
|
325
|
-
alternatives =
|
|
303
|
+
alternatives = collection_utils_1.setUnion(alternatives, ancestorAlternatives);
|
|
326
304
|
}
|
|
327
305
|
}
|
|
328
306
|
typeNames = TypeNames_1.TypeNames.makeWithDistance(names, alternatives, destructive ? 1 : 10);
|
|
@@ -3,8 +3,8 @@ export declare class Graph<T> {
|
|
|
3
3
|
private readonly _indexByNode;
|
|
4
4
|
private readonly _successors;
|
|
5
5
|
constructor(nodes: Iterable<T>, invertDirection: boolean, edges: number[][] | ((node: T) => ReadonlySet<T>));
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
readonly size: number;
|
|
7
|
+
readonly nodes: ReadonlyArray<T>;
|
|
8
8
|
findRoots(): ReadonlySet<T>;
|
|
9
9
|
dfsTraversal(root: T, preOrder: boolean, process: (node: T) => void): void;
|
|
10
10
|
stronglyConnectedComponents(): Graph<ReadonlySet<T>>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Graph = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const Support_1 = require("./support/Support");
|
|
6
5
|
function countComponentGraphNodes(components) {
|
|
@@ -9,14 +8,14 @@ function countComponentGraphNodes(components) {
|
|
|
9
8
|
let largest = -1;
|
|
10
9
|
let count = 0;
|
|
11
10
|
for (const c of components) {
|
|
12
|
-
|
|
11
|
+
Support_1.assert(c.length > 0, "Empty component not allowed");
|
|
13
12
|
for (const v of c) {
|
|
14
|
-
|
|
13
|
+
Support_1.assert(v >= 0, "Negative vertex index is invalid");
|
|
15
14
|
largest = Math.max(largest, v);
|
|
16
15
|
count += 1;
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
|
-
|
|
18
|
+
Support_1.assert(largest + 1 === count, "Vertex indexes and count don't match up");
|
|
20
19
|
return count;
|
|
21
20
|
}
|
|
22
21
|
// https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
|
|
@@ -24,9 +23,9 @@ function stronglyConnectedComponents(successors) {
|
|
|
24
23
|
let index = 0;
|
|
25
24
|
const stack = [];
|
|
26
25
|
const numNodes = successors.length;
|
|
27
|
-
const indexes =
|
|
28
|
-
const lowLinks =
|
|
29
|
-
const onStack =
|
|
26
|
+
const indexes = Support_1.repeated(numNodes, -1);
|
|
27
|
+
const lowLinks = Support_1.repeated(numNodes, -1);
|
|
28
|
+
const onStack = Support_1.repeated(numNodes, false);
|
|
30
29
|
const sccs = [];
|
|
31
30
|
function strongconnect(v) {
|
|
32
31
|
// Set the depth index for v to the smallest unused index
|
|
@@ -55,7 +54,7 @@ function stronglyConnectedComponents(successors) {
|
|
|
55
54
|
const scc = [];
|
|
56
55
|
let w;
|
|
57
56
|
do {
|
|
58
|
-
w =
|
|
57
|
+
w = Support_1.defined(stack.pop());
|
|
59
58
|
onStack[w] = false;
|
|
60
59
|
scc.push(w);
|
|
61
60
|
} while (w !== v);
|
|
@@ -67,17 +66,17 @@ function stronglyConnectedComponents(successors) {
|
|
|
67
66
|
strongconnect(v);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
|
-
|
|
69
|
+
Support_1.assert(countComponentGraphNodes(sccs) === numNodes, "We didn't put all the nodes into SCCs");
|
|
71
70
|
return sccs;
|
|
72
71
|
}
|
|
73
72
|
function buildComponentOfNodeMap(successors, components) {
|
|
74
73
|
const numComponents = components.length;
|
|
75
74
|
const numNodes = successors.length;
|
|
76
|
-
|
|
77
|
-
const componentOfNode =
|
|
75
|
+
Support_1.assert(numNodes === countComponentGraphNodes(components), "Components don't match up with graph");
|
|
76
|
+
const componentOfNode = Support_1.repeated(numNodes, -1);
|
|
78
77
|
for (let c = 0; c < numComponents; c++) {
|
|
79
78
|
for (const n of components[c]) {
|
|
80
|
-
|
|
79
|
+
Support_1.assert(componentOfNode[n] < 0, "We have a node that's in two components");
|
|
81
80
|
componentOfNode[n] = c;
|
|
82
81
|
}
|
|
83
82
|
}
|
|
@@ -86,7 +85,7 @@ function buildComponentOfNodeMap(successors, components) {
|
|
|
86
85
|
function buildMetaSuccessors(successors, components) {
|
|
87
86
|
const numComponents = components.length;
|
|
88
87
|
const componentOfNode = buildComponentOfNodeMap(successors, components);
|
|
89
|
-
const componentAdded =
|
|
88
|
+
const componentAdded = Support_1.repeated(numComponents, false);
|
|
90
89
|
const metaSuccessors = [];
|
|
91
90
|
for (let c = 0; c < numComponents; c++) {
|
|
92
91
|
const succ = [];
|
|
@@ -101,7 +100,7 @@ function buildMetaSuccessors(successors, components) {
|
|
|
101
100
|
}
|
|
102
101
|
// reset bookkeeping
|
|
103
102
|
for (const ms of succ) {
|
|
104
|
-
|
|
103
|
+
Support_1.assert(componentAdded[ms]);
|
|
105
104
|
componentAdded[ms] = false;
|
|
106
105
|
}
|
|
107
106
|
metaSuccessors.push(succ);
|
|
@@ -110,7 +109,7 @@ function buildMetaSuccessors(successors, components) {
|
|
|
110
109
|
}
|
|
111
110
|
function invertEdges(successors) {
|
|
112
111
|
const numNodes = successors.length;
|
|
113
|
-
const predecessors =
|
|
112
|
+
const predecessors = Support_1.repeatedCall(numNodes, () => []);
|
|
114
113
|
for (let s = 0; s < numNodes; s++) {
|
|
115
114
|
for (const v of successors[s]) {
|
|
116
115
|
predecessors[v].push(s);
|
|
@@ -120,7 +119,7 @@ function invertEdges(successors) {
|
|
|
120
119
|
}
|
|
121
120
|
function calculateInDegrees(successors) {
|
|
122
121
|
const numNodes = successors.length;
|
|
123
|
-
const inDegrees =
|
|
122
|
+
const inDegrees = Support_1.repeated(numNodes, 0);
|
|
124
123
|
for (const s of successors) {
|
|
125
124
|
for (const v of s) {
|
|
126
125
|
inDegrees[v] += 1;
|
|
@@ -140,9 +139,6 @@ function findRoots(successors) {
|
|
|
140
139
|
return roots;
|
|
141
140
|
}
|
|
142
141
|
class Graph {
|
|
143
|
-
_nodes;
|
|
144
|
-
_indexByNode;
|
|
145
|
-
_successors;
|
|
146
142
|
constructor(nodes, invertDirection, edges) {
|
|
147
143
|
this._nodes = Array.from(nodes);
|
|
148
144
|
this._indexByNode = new Map(this._nodes.map((n, i) => [n, i]));
|
|
@@ -151,7 +147,7 @@ class Graph {
|
|
|
151
147
|
edgesArray = edges;
|
|
152
148
|
}
|
|
153
149
|
else {
|
|
154
|
-
edgesArray = this._nodes.map(n => Array.from(edges(n)).map(s =>
|
|
150
|
+
edgesArray = this._nodes.map(n => Array.from(edges(n)).map(s => Support_1.defined(this._indexByNode.get(s))));
|
|
155
151
|
}
|
|
156
152
|
if (invertDirection) {
|
|
157
153
|
edgesArray = invertEdges(edgesArray);
|
|
@@ -170,7 +166,7 @@ class Graph {
|
|
|
170
166
|
}
|
|
171
167
|
// The subgraph starting at `root` must be acyclic.
|
|
172
168
|
dfsTraversal(root, preOrder, process) {
|
|
173
|
-
const visited =
|
|
169
|
+
const visited = Support_1.repeated(this.size, false);
|
|
174
170
|
const visit = (v) => {
|
|
175
171
|
if (visited[v])
|
|
176
172
|
return;
|
|
@@ -185,12 +181,12 @@ class Graph {
|
|
|
185
181
|
process(this._nodes[v]);
|
|
186
182
|
}
|
|
187
183
|
};
|
|
188
|
-
visit(
|
|
184
|
+
visit(Support_1.defined(this._indexByNode.get(root)));
|
|
189
185
|
}
|
|
190
186
|
stronglyConnectedComponents() {
|
|
191
187
|
const components = stronglyConnectedComponents(this._successors);
|
|
192
188
|
const componentSuccessors = buildMetaSuccessors(this._successors, components);
|
|
193
|
-
return new Graph(components.map(ns =>
|
|
189
|
+
return new Graph(components.map(ns => collection_utils_1.setMap(ns, n => this._nodes[n])), false, componentSuccessors);
|
|
194
190
|
}
|
|
195
191
|
makeDot(includeNode, nodeLabel) {
|
|
196
192
|
const lines = [];
|
|
@@ -60,10 +60,10 @@ export declare abstract class BaseGraphRewriteBuilder extends TypeBuilder implem
|
|
|
60
60
|
reconstituteTypeAttributes(attributes: TypeAttributes): TypeAttributes;
|
|
61
61
|
protected assertTypeRefsToReconstitute(typeRefs: TypeRef[], forwardingRef?: TypeRef): void;
|
|
62
62
|
protected changeDebugPrintIndent(delta: number): void;
|
|
63
|
-
protected
|
|
63
|
+
protected readonly debugPrintIndentation: string;
|
|
64
64
|
finish(): TypeGraph;
|
|
65
65
|
setLostTypeAttributes(): void;
|
|
66
|
-
|
|
66
|
+
readonly lostTypeAttributes: boolean;
|
|
67
67
|
}
|
|
68
68
|
export declare class GraphRemapBuilder extends BaseGraphRewriteBuilder {
|
|
69
69
|
private readonly _map;
|