@atlaspack/graph 3.5.10 → 3.5.11-typescript-17c3d1dec.0
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/LICENSE +201 -0
- package/lib/AdjacencyList.d.ts +607 -0
- package/lib/AdjacencyList.js +26 -3
- package/lib/BitSet.d.ts +19 -0
- package/lib/BitSet.js +0 -1
- package/lib/ContentGraph.d.ts +23 -0
- package/lib/ContentGraph.js +1 -5
- package/lib/Graph.d.ts +91 -0
- package/lib/Graph.js +8 -3
- package/lib/index.d.ts +7 -0
- package/lib/shared-buffer.d.ts +2 -0
- package/lib/shared-buffer.js +5 -1
- package/lib/types.d.ts +9 -0
- package/lib/types.js +1 -0
- package/package.json +11 -8
- package/src/{AdjacencyList.js → AdjacencyList.ts} +127 -101
- package/src/{BitSet.js → BitSet.ts} +0 -3
- package/src/{ContentGraph.js → ContentGraph.ts} +21 -20
- package/src/{Graph.js → Graph.ts} +88 -65
- package/src/{index.js → index.ts} +0 -2
- package/src/{shared-buffer.js → shared-buffer.ts} +6 -3
- package/src/{types.js → types.ts} +5 -7
- package/test/{AdjacencyList.test.js → AdjacencyList.test.ts} +21 -29
- package/test/{BitSet.test.js → BitSet.test.ts} +3 -5
- package/test/{ContentGraph.test.js → ContentGraph.test.ts} +2 -4
- package/test/{Graph.test.js → Graph.test.ts} +22 -24
- package/tsconfig.json +4 -0
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import {fromNodeId} from './types';
|
|
4
|
-
import AdjacencyList, {
|
|
2
|
+
import AdjacencyList, {SerializedAdjacencyList} from './AdjacencyList';
|
|
5
3
|
import type {Edge, NodeId} from './types';
|
|
6
4
|
import type {
|
|
7
5
|
TraversalActions,
|
|
@@ -14,32 +12,32 @@ import nullthrows from 'nullthrows';
|
|
|
14
12
|
|
|
15
13
|
export type NullEdgeType = 1;
|
|
16
14
|
export const NULL_EDGE_TYPE: NullEdgeType = 1;
|
|
17
|
-
export type GraphOpts<TNode, TEdgeType
|
|
18
|
-
nodes?: Array<TNode | null
|
|
19
|
-
adjacencyList?: SerializedAdjacencyList<TEdgeType
|
|
20
|
-
rootNodeId?:
|
|
21
|
-
initialCapacity?: number
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export type SerializedGraph<TNode, TEdgeType
|
|
25
|
-
nodes: Array<TNode | null
|
|
26
|
-
adjacencyList: SerializedAdjacencyList<TEdgeType
|
|
27
|
-
rootNodeId:
|
|
28
|
-
|
|
15
|
+
export type GraphOpts<TNode, TEdgeType extends number = NullEdgeType> = {
|
|
16
|
+
nodes?: Array<TNode | null>;
|
|
17
|
+
adjacencyList?: SerializedAdjacencyList<TEdgeType>;
|
|
18
|
+
rootNodeId?: NodeId | null | undefined;
|
|
19
|
+
initialCapacity?: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type SerializedGraph<TNode, TEdgeType extends number = NullEdgeType> = {
|
|
23
|
+
nodes: Array<TNode | null>;
|
|
24
|
+
adjacencyList: SerializedAdjacencyList<TEdgeType>;
|
|
25
|
+
rootNodeId: NodeId | null | undefined;
|
|
26
|
+
};
|
|
29
27
|
|
|
30
28
|
export type AllEdgeTypes = -1;
|
|
31
29
|
export const ALL_EDGE_TYPES: AllEdgeTypes = -1;
|
|
32
30
|
|
|
33
|
-
type DFSCommandVisit<TContext> = {
|
|
34
|
-
nodeId: NodeId
|
|
35
|
-
context: TContext | null
|
|
36
|
-
|
|
31
|
+
type DFSCommandVisit<TContext> = {
|
|
32
|
+
nodeId: NodeId;
|
|
33
|
+
context: TContext | null;
|
|
34
|
+
};
|
|
37
35
|
|
|
38
|
-
type DFSCommandExit<TContext> = {
|
|
39
|
-
nodeId: NodeId
|
|
40
|
-
exit: GraphTraversalCallback<NodeId, TContext
|
|
41
|
-
context: TContext | null
|
|
42
|
-
|
|
36
|
+
type DFSCommandExit<TContext> = {
|
|
37
|
+
nodeId: NodeId;
|
|
38
|
+
exit: GraphTraversalCallback<NodeId, TContext>;
|
|
39
|
+
context: TContext | null;
|
|
40
|
+
};
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
43
|
* Internal type used for queue iterative DFS implementation.
|
|
@@ -51,8 +49,8 @@ type DFSCommand<TContext> =
|
|
|
51
49
|
/**
|
|
52
50
|
* Options for DFS traversal.
|
|
53
51
|
*/
|
|
54
|
-
export type DFSParams<TContext> = {
|
|
55
|
-
visit: GraphVisitor<NodeId, TContext
|
|
52
|
+
export type DFSParams<TContext> = {
|
|
53
|
+
visit: GraphVisitor<NodeId, TContext>;
|
|
56
54
|
/**
|
|
57
55
|
* Custom function to get next entries to visit.
|
|
58
56
|
*
|
|
@@ -71,17 +69,17 @@ export type DFSParams<TContext> = {|
|
|
|
71
69
|
*
|
|
72
70
|
* Only due to the latter we aren't replacing this.
|
|
73
71
|
*/
|
|
74
|
-
getChildren: (nodeId: NodeId) => Array<NodeId
|
|
75
|
-
startNodeId?:
|
|
76
|
-
|
|
72
|
+
getChildren: (nodeId: NodeId) => Array<NodeId>;
|
|
73
|
+
startNodeId?: NodeId | null | undefined;
|
|
74
|
+
};
|
|
77
75
|
|
|
78
|
-
export default class Graph<TNode, TEdgeType
|
|
76
|
+
export default class Graph<TNode, TEdgeType extends number = NullEdgeType> {
|
|
79
77
|
nodes: Array<TNode | null>;
|
|
80
78
|
adjacencyList: AdjacencyList<TEdgeType>;
|
|
81
|
-
rootNodeId:
|
|
82
|
-
_visited:
|
|
79
|
+
rootNodeId: NodeId | null | undefined;
|
|
80
|
+
_visited: BitSet | null | undefined;
|
|
83
81
|
|
|
84
|
-
constructor(opts
|
|
82
|
+
constructor(opts?: GraphOpts<TNode, TEdgeType> | null) {
|
|
85
83
|
this.nodes = opts?.nodes || [];
|
|
86
84
|
this.setRootNodeId(opts?.rootNodeId);
|
|
87
85
|
|
|
@@ -94,11 +92,11 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
94
92
|
);
|
|
95
93
|
}
|
|
96
94
|
|
|
97
|
-
setRootNodeId(id
|
|
95
|
+
setRootNodeId(id?: NodeId | null) {
|
|
98
96
|
this.rootNodeId = id;
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
static deserialize(
|
|
99
|
+
static deserialize<TNode, TEdgeType extends number = NullEdgeType>(
|
|
102
100
|
opts: GraphOpts<TNode, TEdgeType>,
|
|
103
101
|
): Graph<TNode, TEdgeType> {
|
|
104
102
|
return new this({
|
|
@@ -132,7 +130,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
132
130
|
return this.nodes[id] != null;
|
|
133
131
|
}
|
|
134
132
|
|
|
135
|
-
getNode(id: NodeId):
|
|
133
|
+
getNode(id: NodeId): TNode | null | undefined {
|
|
136
134
|
return this.nodes[id];
|
|
137
135
|
}
|
|
138
136
|
|
|
@@ -159,7 +157,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
159
157
|
hasEdge(
|
|
160
158
|
from: NodeId,
|
|
161
159
|
to: NodeId,
|
|
162
|
-
type
|
|
160
|
+
type:
|
|
163
161
|
| TEdgeType
|
|
164
162
|
| NullEdgeType
|
|
165
163
|
| Array<TEdgeType | NullEdgeType> = NULL_EDGE_TYPE,
|
|
@@ -169,7 +167,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
169
167
|
|
|
170
168
|
forEachNodeIdConnectedTo(
|
|
171
169
|
to: NodeId,
|
|
172
|
-
fn: (nodeId: NodeId) => boolean |
|
|
170
|
+
fn: (nodeId: NodeId) => boolean | undefined,
|
|
173
171
|
type: AllEdgeTypes | TEdgeType | NullEdgeType = NULL_EDGE_TYPE,
|
|
174
172
|
) {
|
|
175
173
|
this._assertHasNodeId(to);
|
|
@@ -327,9 +325,9 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
327
325
|
// Update a node's downstream nodes making sure to prune any orphaned branches
|
|
328
326
|
replaceNodeIdsConnectedTo(
|
|
329
327
|
fromNodeId: NodeId,
|
|
330
|
-
toNodeIds:
|
|
331
|
-
replaceFilter?: null | ((NodeId) => boolean),
|
|
332
|
-
type
|
|
328
|
+
toNodeIds: ReadonlyArray<NodeId>,
|
|
329
|
+
replaceFilter?: null | ((arg1: NodeId) => boolean),
|
|
330
|
+
type: TEdgeType | NullEdgeType = NULL_EDGE_TYPE,
|
|
333
331
|
removeOrphans: boolean = true,
|
|
334
332
|
): void {
|
|
335
333
|
this._assertHasNodeId(fromNodeId);
|
|
@@ -355,13 +353,13 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
355
353
|
|
|
356
354
|
traverse<TContext>(
|
|
357
355
|
visit: GraphVisitor<NodeId, TContext>,
|
|
358
|
-
startNodeId
|
|
356
|
+
startNodeId?: NodeId | null,
|
|
359
357
|
type:
|
|
360
358
|
| TEdgeType
|
|
361
359
|
| NullEdgeType
|
|
362
360
|
| Array<TEdgeType | NullEdgeType>
|
|
363
361
|
| AllEdgeTypes = NULL_EDGE_TYPE,
|
|
364
|
-
):
|
|
362
|
+
): TContext | null | undefined {
|
|
365
363
|
let enter = typeof visit === 'function' ? visit : visit.enter;
|
|
366
364
|
if (
|
|
367
365
|
type === ALL_EDGE_TYPES &&
|
|
@@ -379,23 +377,23 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
379
377
|
}
|
|
380
378
|
|
|
381
379
|
filteredTraverse<TValue, TContext>(
|
|
382
|
-
filter: (NodeId, TraversalActions) =>
|
|
380
|
+
filter: (arg1: NodeId, arg2: TraversalActions) => TValue | null | undefined,
|
|
383
381
|
visit: GraphVisitor<TValue, TContext>,
|
|
384
|
-
startNodeId
|
|
382
|
+
startNodeId?: NodeId | null,
|
|
385
383
|
type?: TEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes,
|
|
386
|
-
):
|
|
384
|
+
): TContext | null | undefined {
|
|
387
385
|
return this.traverse(mapVisitor(filter, visit), startNodeId, type);
|
|
388
386
|
}
|
|
389
387
|
|
|
390
388
|
traverseAncestors<TContext>(
|
|
391
|
-
startNodeId:
|
|
389
|
+
startNodeId: NodeId | null | undefined,
|
|
392
390
|
visit: GraphVisitor<NodeId, TContext>,
|
|
393
391
|
type:
|
|
394
392
|
| TEdgeType
|
|
395
393
|
| NullEdgeType
|
|
396
394
|
| Array<TEdgeType | NullEdgeType>
|
|
397
395
|
| AllEdgeTypes = NULL_EDGE_TYPE,
|
|
398
|
-
):
|
|
396
|
+
): TContext | null | undefined {
|
|
399
397
|
return this.dfs({
|
|
400
398
|
visit,
|
|
401
399
|
startNodeId,
|
|
@@ -405,8 +403,8 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
405
403
|
|
|
406
404
|
dfsFast<TContext>(
|
|
407
405
|
visit: GraphTraversalCallback<NodeId, TContext>,
|
|
408
|
-
startNodeId
|
|
409
|
-
):
|
|
406
|
+
startNodeId?: NodeId | null,
|
|
407
|
+
): TContext | null | undefined {
|
|
410
408
|
let traversalStartNode = nullthrows(
|
|
411
409
|
startNodeId ?? this.rootNodeId,
|
|
412
410
|
'A start node is required to traverse',
|
|
@@ -437,6 +435,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
437
435
|
|
|
438
436
|
let queue = [{nodeId: traversalStartNode, context: null}];
|
|
439
437
|
while (queue.length !== 0) {
|
|
438
|
+
// @ts-expect-error TS2339
|
|
440
439
|
let {nodeId, context} = queue.pop();
|
|
441
440
|
if (!this.hasNode(nodeId) || visited.has(nodeId)) continue;
|
|
442
441
|
visited.add(nodeId);
|
|
@@ -444,7 +443,6 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
444
443
|
skipped = false;
|
|
445
444
|
let newContext = visit(nodeId, context, actions);
|
|
446
445
|
if (typeof newContext !== 'undefined') {
|
|
447
|
-
// $FlowFixMe[reassign-const]
|
|
448
446
|
context = newContext;
|
|
449
447
|
}
|
|
450
448
|
|
|
@@ -472,7 +470,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
472
470
|
// A post-order implementation of dfsFast
|
|
473
471
|
postOrderDfsFast(
|
|
474
472
|
visit: GraphTraversalCallback<NodeId, TraversalActions>,
|
|
475
|
-
startNodeId
|
|
473
|
+
startNodeId?: NodeId | null,
|
|
476
474
|
): void {
|
|
477
475
|
let traversalStartNode = nullthrows(
|
|
478
476
|
startNodeId ?? this.rootNodeId,
|
|
@@ -542,7 +540,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
542
540
|
visit,
|
|
543
541
|
startNodeId,
|
|
544
542
|
getChildren,
|
|
545
|
-
}: DFSParams<TContext>):
|
|
543
|
+
}: DFSParams<TContext>): TContext | null | undefined {
|
|
546
544
|
let traversalStartNode = nullthrows(
|
|
547
545
|
startNodeId ?? this.rootNodeId,
|
|
548
546
|
'A start node is required to traverse',
|
|
@@ -578,11 +576,13 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
578
576
|
while (queue.length !== 0) {
|
|
579
577
|
const command = queue.pop();
|
|
580
578
|
|
|
579
|
+
// @ts-expect-error TS18048
|
|
581
580
|
if (command.exit != null) {
|
|
581
|
+
// @ts-expect-error TS2339
|
|
582
582
|
let {nodeId, context, exit} = command;
|
|
583
|
+
// @ts-expect-error TS18048
|
|
583
584
|
let newContext = exit(nodeId, command.context, actions);
|
|
584
585
|
if (typeof newContext !== 'undefined') {
|
|
585
|
-
// $FlowFixMe[reassign-const]
|
|
586
586
|
context = newContext;
|
|
587
587
|
}
|
|
588
588
|
|
|
@@ -595,6 +595,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
595
595
|
return context;
|
|
596
596
|
}
|
|
597
597
|
} else {
|
|
598
|
+
// @ts-expect-error TS2339
|
|
598
599
|
let {nodeId, context} = command;
|
|
599
600
|
if (!this.hasNode(nodeId) || visited.has(nodeId)) continue;
|
|
600
601
|
visited.add(nodeId);
|
|
@@ -603,7 +604,6 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
603
604
|
if (enter) {
|
|
604
605
|
let newContext = enter(nodeId, context, actions);
|
|
605
606
|
if (typeof newContext !== 'undefined') {
|
|
606
|
-
// $FlowFixMe[reassign-const]
|
|
607
607
|
context = newContext;
|
|
608
608
|
}
|
|
609
609
|
}
|
|
@@ -641,7 +641,9 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
641
641
|
this._visited = visited;
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
-
bfs(
|
|
644
|
+
bfs(
|
|
645
|
+
visit: (nodeId: NodeId) => boolean | null | undefined,
|
|
646
|
+
): NodeId | null | undefined {
|
|
645
647
|
let rootNodeId = nullthrows(
|
|
646
648
|
this.rootNodeId,
|
|
647
649
|
'A root node is required to traverse',
|
|
@@ -657,6 +659,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
657
659
|
return node;
|
|
658
660
|
}
|
|
659
661
|
|
|
662
|
+
// @ts-expect-error TS2345
|
|
660
663
|
for (let child of this.getNodeIdsConnectedFrom(node)) {
|
|
661
664
|
if (!visited.has(child)) {
|
|
662
665
|
visited.add(child);
|
|
@@ -682,7 +685,10 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
682
685
|
return sorted.reverse();
|
|
683
686
|
}
|
|
684
687
|
|
|
685
|
-
findAncestor(
|
|
688
|
+
findAncestor(
|
|
689
|
+
nodeId: NodeId,
|
|
690
|
+
fn: (nodeId: NodeId) => boolean,
|
|
691
|
+
): NodeId | null | undefined {
|
|
686
692
|
let res = null;
|
|
687
693
|
this.traverseAncestors(nodeId, (nodeId, ctx, traversal) => {
|
|
688
694
|
if (fn(nodeId)) {
|
|
@@ -697,7 +703,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
697
703
|
nodeId: NodeId,
|
|
698
704
|
fn: (nodeId: NodeId) => boolean,
|
|
699
705
|
): Array<NodeId> {
|
|
700
|
-
let res = [];
|
|
706
|
+
let res: Array<NodeId> = [];
|
|
701
707
|
this.traverseAncestors(nodeId, (nodeId, ctx, traversal) => {
|
|
702
708
|
if (fn(nodeId)) {
|
|
703
709
|
res.push(nodeId);
|
|
@@ -707,7 +713,10 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
707
713
|
return res;
|
|
708
714
|
}
|
|
709
715
|
|
|
710
|
-
findDescendant(
|
|
716
|
+
findDescendant(
|
|
717
|
+
nodeId: NodeId,
|
|
718
|
+
fn: (nodeId: NodeId) => boolean,
|
|
719
|
+
): NodeId | null | undefined {
|
|
711
720
|
let res = null;
|
|
712
721
|
this.traverse((nodeId, ctx, traversal) => {
|
|
713
722
|
if (fn(nodeId)) {
|
|
@@ -722,7 +731,7 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
722
731
|
nodeId: NodeId,
|
|
723
732
|
fn: (nodeId: NodeId) => boolean,
|
|
724
733
|
): Array<NodeId> {
|
|
725
|
-
let res = [];
|
|
734
|
+
let res: Array<NodeId> = [];
|
|
726
735
|
this.traverse((nodeId, ctx, traversal) => {
|
|
727
736
|
if (fn(nodeId)) {
|
|
728
737
|
res.push(nodeId);
|
|
@@ -740,11 +749,21 @@ export default class Graph<TNode, TEdgeType: number = NullEdgeType> {
|
|
|
740
749
|
}
|
|
741
750
|
|
|
742
751
|
export function mapVisitor<NodeId, TValue, TContext>(
|
|
743
|
-
filter: (NodeId, TraversalActions) =>
|
|
752
|
+
filter: (arg1: NodeId, arg2: TraversalActions) => TValue | null | undefined,
|
|
744
753
|
visit: GraphVisitor<TValue, TContext>,
|
|
745
754
|
): GraphVisitor<NodeId, TContext> {
|
|
746
|
-
function makeEnter(
|
|
747
|
-
|
|
755
|
+
function makeEnter(
|
|
756
|
+
visit: (
|
|
757
|
+
node: TValue,
|
|
758
|
+
context: TContext | null | undefined,
|
|
759
|
+
actions: TraversalActions,
|
|
760
|
+
) => TContext | null | undefined,
|
|
761
|
+
) {
|
|
762
|
+
return function mappedEnter(
|
|
763
|
+
nodeId: NodeId,
|
|
764
|
+
context: TContext | null | undefined,
|
|
765
|
+
actions: TraversalActions,
|
|
766
|
+
) {
|
|
748
767
|
let value = filter(nodeId, actions);
|
|
749
768
|
if (value != null) {
|
|
750
769
|
return visit(value, context, actions);
|
|
@@ -756,13 +775,17 @@ export function mapVisitor<NodeId, TValue, TContext>(
|
|
|
756
775
|
return makeEnter(visit);
|
|
757
776
|
}
|
|
758
777
|
|
|
759
|
-
let mapped = {};
|
|
778
|
+
let mapped: Record<string, any> = {};
|
|
760
779
|
if (visit.enter != null) {
|
|
761
780
|
mapped.enter = makeEnter(visit.enter);
|
|
762
781
|
}
|
|
763
782
|
|
|
764
783
|
if (visit.exit != null) {
|
|
765
|
-
mapped.exit = function mappedExit(
|
|
784
|
+
mapped.exit = function mappedExit(
|
|
785
|
+
nodeId: NodeId,
|
|
786
|
+
context: TContext | null | undefined,
|
|
787
|
+
actions: TraversalActions,
|
|
788
|
+
) {
|
|
766
789
|
let exit = visit.exit;
|
|
767
790
|
if (!exit) {
|
|
768
791
|
return;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
//
|
|
1
|
+
// flow-to-ts helpers
|
|
2
|
+
export type Class<T> = new (...args: any[]) => T;
|
|
3
|
+
// /flow-to-ts helpers
|
|
4
|
+
|
|
2
5
|
// Copy from @atlaspack/utils to fix: https://github.com/stackblitz/core/issues/1855
|
|
3
6
|
export let SharedBuffer: Class<ArrayBuffer> | Class<SharedArrayBuffer>;
|
|
4
7
|
|
|
5
|
-
//
|
|
8
|
+
// @ts-expect-error TS2339
|
|
6
9
|
if (process.browser) {
|
|
7
10
|
SharedBuffer = ArrayBuffer;
|
|
8
11
|
// Safari has removed the constructor
|
|
@@ -12,7 +15,7 @@ if (process.browser) {
|
|
|
12
15
|
// Firefox might throw when sending the Buffer over a MessagePort
|
|
13
16
|
channel.port1.postMessage(new SharedArrayBuffer(0));
|
|
14
17
|
SharedBuffer = SharedArrayBuffer;
|
|
15
|
-
} catch (_) {
|
|
18
|
+
} catch (_: any) {
|
|
16
19
|
// NOOP
|
|
17
20
|
}
|
|
18
21
|
channel.port1.close();
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
// forcing NodeId to be opaque as it should only be created once
|
|
4
2
|
export type NodeId = number;
|
|
5
3
|
export function toNodeId(x: number): NodeId {
|
|
@@ -11,8 +9,8 @@ export function fromNodeId(x: NodeId): number {
|
|
|
11
9
|
|
|
12
10
|
export type ContentKey = string;
|
|
13
11
|
|
|
14
|
-
export type Edge<TEdgeType
|
|
15
|
-
from: NodeId
|
|
16
|
-
to: NodeId
|
|
17
|
-
type: TEdgeType
|
|
18
|
-
|
|
12
|
+
export type Edge<TEdgeType extends number> = {
|
|
13
|
+
from: NodeId;
|
|
14
|
+
to: NodeId;
|
|
15
|
+
type: TEdgeType;
|
|
16
|
+
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import sinon from 'sinon';
|
|
5
3
|
import path from 'path';
|
|
@@ -214,9 +212,7 @@ describe('AdjacencyList', () => {
|
|
|
214
212
|
|
|
215
213
|
it('addEdge should not replace a deleted edge if the edge was already added', () => {
|
|
216
214
|
// Mock hash fn to generate collisions
|
|
217
|
-
// $FlowFixMe[prop-missing]
|
|
218
215
|
let originalHash = AdjacencyList.prototype.hash;
|
|
219
|
-
// $FlowFixMe[prop-missing]
|
|
220
216
|
AdjacencyList.prototype.hash = () => 1;
|
|
221
217
|
|
|
222
218
|
let graph = new AdjacencyList();
|
|
@@ -229,15 +225,12 @@ describe('AdjacencyList', () => {
|
|
|
229
225
|
assert(graph.addEdge(n0, n1, 1) === false);
|
|
230
226
|
assert(graph.stats.edges === 1);
|
|
231
227
|
|
|
232
|
-
// $FlowFixMe[prop-missing]
|
|
233
228
|
AdjacencyList.prototype.hash = originalHash;
|
|
234
229
|
});
|
|
235
230
|
|
|
236
231
|
it('addEdge should replace a deleted edge', () => {
|
|
237
232
|
// Mock hash fn to generate collisions
|
|
238
|
-
// $FlowFixMe[prop-missing]
|
|
239
233
|
let originalHash = AdjacencyList.prototype.hash;
|
|
240
|
-
// $FlowFixMe[prop-missing]
|
|
241
234
|
AdjacencyList.prototype.hash = () => 1;
|
|
242
235
|
|
|
243
236
|
try {
|
|
@@ -254,7 +247,6 @@ describe('AdjacencyList', () => {
|
|
|
254
247
|
assert(graph.stats.edges === 1);
|
|
255
248
|
assert(graph.stats.deleted === 0);
|
|
256
249
|
} finally {
|
|
257
|
-
// $FlowFixMe[prop-missing]
|
|
258
250
|
AdjacencyList.prototype.hash = originalHash;
|
|
259
251
|
}
|
|
260
252
|
});
|
|
@@ -299,8 +291,8 @@ describe('AdjacencyList', () => {
|
|
|
299
291
|
graph.addEdge(a, b);
|
|
300
292
|
graph.addEdge(c, b);
|
|
301
293
|
|
|
302
|
-
const nodeIds = [];
|
|
303
|
-
graph.forEachNodeIdConnectedTo(b, (id) => {
|
|
294
|
+
const nodeIds: Array<any> = [];
|
|
295
|
+
graph.forEachNodeIdConnectedTo(b, (id: any) => {
|
|
304
296
|
nodeIds.push(id);
|
|
305
297
|
});
|
|
306
298
|
|
|
@@ -318,8 +310,8 @@ describe('AdjacencyList', () => {
|
|
|
318
310
|
graph.addEdge(b, d);
|
|
319
311
|
graph.addEdge(c, d);
|
|
320
312
|
|
|
321
|
-
const nodeIds = [];
|
|
322
|
-
graph.forEachNodeIdConnectedTo(d, (nodeId) => {
|
|
313
|
+
const nodeIds: Array<any> = [];
|
|
314
|
+
graph.forEachNodeIdConnectedTo(d, (nodeId: any) => {
|
|
323
315
|
nodeIds.push(nodeId);
|
|
324
316
|
return true;
|
|
325
317
|
});
|
|
@@ -337,8 +329,8 @@ describe('AdjacencyList', () => {
|
|
|
337
329
|
graph.addEdge(c, b);
|
|
338
330
|
graph.addEdge(b, b);
|
|
339
331
|
|
|
340
|
-
const nodeIds = [];
|
|
341
|
-
graph.forEachNodeIdConnectedTo(b, (id) => {
|
|
332
|
+
const nodeIds: Array<any> = [];
|
|
333
|
+
graph.forEachNodeIdConnectedTo(b, (id: any) => {
|
|
342
334
|
nodeIds.push(id);
|
|
343
335
|
});
|
|
344
336
|
|
|
@@ -354,8 +346,8 @@ describe('AdjacencyList', () => {
|
|
|
354
346
|
graph.addEdge(a, b);
|
|
355
347
|
graph.addEdge(c, b, 2);
|
|
356
348
|
|
|
357
|
-
const nodeIds = [];
|
|
358
|
-
graph.forEachNodeIdConnectedTo(b, (id) => {
|
|
349
|
+
const nodeIds: Array<any> = [];
|
|
350
|
+
graph.forEachNodeIdConnectedTo(b, (id: any) => {
|
|
359
351
|
nodeIds.push(id);
|
|
360
352
|
});
|
|
361
353
|
|
|
@@ -371,10 +363,10 @@ describe('AdjacencyList', () => {
|
|
|
371
363
|
graph.addEdge(a, b);
|
|
372
364
|
graph.addEdge(c, b, 2);
|
|
373
365
|
|
|
374
|
-
const nodeIds = [];
|
|
366
|
+
const nodeIds: Array<any> = [];
|
|
375
367
|
graph.forEachNodeIdConnectedTo(
|
|
376
368
|
b,
|
|
377
|
-
(id) => {
|
|
369
|
+
(id: any) => {
|
|
378
370
|
nodeIds.push(id);
|
|
379
371
|
},
|
|
380
372
|
ALL_EDGE_TYPES,
|
|
@@ -413,8 +405,8 @@ describe('AdjacencyList', () => {
|
|
|
413
405
|
graph.addEdge(b, d, 3);
|
|
414
406
|
graph.addEdge(c, e, 4);
|
|
415
407
|
|
|
416
|
-
const nodeIds = [];
|
|
417
|
-
graph.forEachNodeIdConnectedFromReverse(a, (nodeId) => {
|
|
408
|
+
const nodeIds: Array<any> = [];
|
|
409
|
+
graph.forEachNodeIdConnectedFromReverse(a, (nodeId: any) => {
|
|
418
410
|
nodeIds.push(nodeId);
|
|
419
411
|
return false;
|
|
420
412
|
});
|
|
@@ -432,8 +424,8 @@ describe('AdjacencyList', () => {
|
|
|
432
424
|
graph.addEdge(a, c);
|
|
433
425
|
graph.addEdge(a, a);
|
|
434
426
|
|
|
435
|
-
const nodeIds = [];
|
|
436
|
-
graph.forEachNodeIdConnectedFromReverse(a, (nodeId) => {
|
|
427
|
+
const nodeIds: Array<any> = [];
|
|
428
|
+
graph.forEachNodeIdConnectedFromReverse(a, (nodeId: any) => {
|
|
437
429
|
nodeIds.push(nodeId);
|
|
438
430
|
return false;
|
|
439
431
|
});
|
|
@@ -452,8 +444,8 @@ describe('AdjacencyList', () => {
|
|
|
452
444
|
graph.addEdge(a, c);
|
|
453
445
|
graph.addEdge(a, d);
|
|
454
446
|
|
|
455
|
-
const nodeIds = [];
|
|
456
|
-
graph.forEachNodeIdConnectedFromReverse(a, (nodeId) => {
|
|
447
|
+
const nodeIds: Array<any> = [];
|
|
448
|
+
graph.forEachNodeIdConnectedFromReverse(a, (nodeId: any) => {
|
|
457
449
|
nodeIds.push(nodeId);
|
|
458
450
|
return true;
|
|
459
451
|
});
|
|
@@ -472,10 +464,10 @@ describe('AdjacencyList', () => {
|
|
|
472
464
|
graph.addEdge(a, c, 2);
|
|
473
465
|
graph.addEdge(a, d);
|
|
474
466
|
|
|
475
|
-
const nodeIds = [];
|
|
467
|
+
const nodeIds: Array<any> = [];
|
|
476
468
|
graph.forEachNodeIdConnectedFromReverse(
|
|
477
469
|
a,
|
|
478
|
-
(nodeId) => {
|
|
470
|
+
(nodeId: any) => {
|
|
479
471
|
nodeIds.push(nodeId);
|
|
480
472
|
return false;
|
|
481
473
|
},
|
|
@@ -503,7 +495,7 @@ describe('AdjacencyList', () => {
|
|
|
503
495
|
let originalSerialized = graph.serialize();
|
|
504
496
|
let originalNodes = [...originalSerialized.nodes];
|
|
505
497
|
let originalEdges = [...originalSerialized.edges];
|
|
506
|
-
let work = new Promise((resolve) => worker.on('message', resolve));
|
|
498
|
+
let work = new Promise((resolve: any) => worker.on('message', resolve));
|
|
507
499
|
worker.postMessage(originalSerialized);
|
|
508
500
|
let received = AdjacencyList.deserialize(await work);
|
|
509
501
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -512,7 +504,7 @@ describe('AdjacencyList', () => {
|
|
|
512
504
|
assert.deepEqual(received.serialize().nodes, graph.serialize().nodes);
|
|
513
505
|
assert.deepEqual(received.serialize().edges, graph.serialize().edges);
|
|
514
506
|
|
|
515
|
-
originalNodes.forEach((v, i) => {
|
|
507
|
+
originalNodes.forEach((v: any, i: any) => {
|
|
516
508
|
if (i < NodeTypeMap.HEADER_SIZE) {
|
|
517
509
|
assert.equal(v, received.serialize().nodes[i]);
|
|
518
510
|
assert.equal(v, graph.serialize().nodes[i]);
|
|
@@ -522,7 +514,7 @@ describe('AdjacencyList', () => {
|
|
|
522
514
|
}
|
|
523
515
|
});
|
|
524
516
|
|
|
525
|
-
originalEdges.forEach((v, i) => {
|
|
517
|
+
originalEdges.forEach((v: any, i: any) => {
|
|
526
518
|
if (i < EdgeTypeMap.HEADER_SIZE) {
|
|
527
519
|
assert.equal(v, received.serialize().edges[i]);
|
|
528
520
|
assert.equal(v, graph.serialize().edges[i]);
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import {BitSet} from '../src/BitSet';
|
|
5
3
|
|
|
6
4
|
function assertValues(set: BitSet, values: Array<number>) {
|
|
7
|
-
let setValues = [];
|
|
8
|
-
set.forEach((bit) => {
|
|
5
|
+
let setValues: Array<any> = [];
|
|
6
|
+
set.forEach((bit: any) => {
|
|
9
7
|
setValues.push(bit);
|
|
10
8
|
});
|
|
11
9
|
|
|
12
10
|
for (let value of values) {
|
|
13
11
|
assert(set.has(value), 'Set.has returned false');
|
|
14
12
|
assert(
|
|
15
|
-
setValues.some((v) => v === value),
|
|
13
|
+
setValues.some((v: any) => v === value),
|
|
16
14
|
'Set values is missing value',
|
|
17
15
|
);
|
|
18
16
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import ContentGraph from '../src/ContentGraph';
|
|
5
3
|
|
|
@@ -7,7 +5,7 @@ describe('ContentGraph', () => {
|
|
|
7
5
|
it('should addNodeByContentKey if no node exists with the content key', () => {
|
|
8
6
|
let graph = new ContentGraph();
|
|
9
7
|
|
|
10
|
-
const node = {};
|
|
8
|
+
const node: Record<string, any> = {};
|
|
11
9
|
|
|
12
10
|
const nodeId1 = graph.addNodeByContentKey('contentKey', node);
|
|
13
11
|
|
|
@@ -29,7 +27,7 @@ describe('ContentGraph', () => {
|
|
|
29
27
|
it('should remove the content key from graph when node is removed', () => {
|
|
30
28
|
let graph = new ContentGraph();
|
|
31
29
|
|
|
32
|
-
const node1 = {};
|
|
30
|
+
const node1: Record<string, any> = {};
|
|
33
31
|
const nodeId1 = graph.addNodeByContentKey('contentKey', node1);
|
|
34
32
|
|
|
35
33
|
assert.equal(graph.getNode(nodeId1), node1);
|