@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,11 +1,9 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import sinon from 'sinon';
|
|
5
3
|
import type {TraversalActions} from '@atlaspack/types-internal';
|
|
6
4
|
|
|
7
5
|
import Graph from '../src/Graph';
|
|
8
|
-
import {toNodeId,
|
|
6
|
+
import {toNodeId, NodeId} from '../src/types';
|
|
9
7
|
|
|
10
8
|
describe('Graph', () => {
|
|
11
9
|
it('constructor should initialize an empty graph', () => {
|
|
@@ -16,7 +14,7 @@ describe('Graph', () => {
|
|
|
16
14
|
|
|
17
15
|
it('addNode should add a node to the graph', () => {
|
|
18
16
|
let graph = new Graph();
|
|
19
|
-
let node = {};
|
|
17
|
+
let node: Record<string, any> = {};
|
|
20
18
|
let id = graph.addNode(node);
|
|
21
19
|
assert.equal(graph.getNode(id), node);
|
|
22
20
|
});
|
|
@@ -340,9 +338,9 @@ describe('Graph', () => {
|
|
|
340
338
|
|
|
341
339
|
graph.setRootNodeId(nodeA);
|
|
342
340
|
|
|
343
|
-
let visited = [];
|
|
341
|
+
let visited: Array<any> = [];
|
|
344
342
|
graph.traverse(
|
|
345
|
-
(nodeId) => {
|
|
343
|
+
(nodeId: any) => {
|
|
346
344
|
visited.push(nodeId);
|
|
347
345
|
},
|
|
348
346
|
null, // use root as startNode
|
|
@@ -413,7 +411,7 @@ describe('Graph', () => {
|
|
|
413
411
|
graph.addEdge(1, 3);
|
|
414
412
|
graph.addEdge(2, 3);
|
|
415
413
|
|
|
416
|
-
const order = [];
|
|
414
|
+
const order: Array<any> = [];
|
|
417
415
|
const visit = (node: NodeId) => {
|
|
418
416
|
order.push(node);
|
|
419
417
|
};
|
|
@@ -440,10 +438,10 @@ describe('Graph', () => {
|
|
|
440
438
|
graph.addEdge(1, 2);
|
|
441
439
|
graph.addEdge(0, 3);
|
|
442
440
|
|
|
443
|
-
const order = [];
|
|
441
|
+
const order: Array<any> = [];
|
|
444
442
|
const visit = (
|
|
445
443
|
node: NodeId,
|
|
446
|
-
context:
|
|
444
|
+
context: unknown | null,
|
|
447
445
|
actions: TraversalActions,
|
|
448
446
|
) => {
|
|
449
447
|
if (node === 1) actions.skipChildren();
|
|
@@ -474,10 +472,10 @@ describe('Graph', () => {
|
|
|
474
472
|
graph.addEdge(0, 2);
|
|
475
473
|
graph.addEdge(2, 3);
|
|
476
474
|
|
|
477
|
-
const order = [];
|
|
475
|
+
const order: Array<any> = [];
|
|
478
476
|
const visit = (
|
|
479
477
|
node: NodeId,
|
|
480
|
-
context:
|
|
478
|
+
context: unknown | null,
|
|
481
479
|
actions: TraversalActions,
|
|
482
480
|
) => {
|
|
483
481
|
order.push(node);
|
|
@@ -515,8 +513,8 @@ describe('Graph', () => {
|
|
|
515
513
|
graph.addEdge(0, 2);
|
|
516
514
|
graph.addEdge(2, 3);
|
|
517
515
|
|
|
518
|
-
const contexts = [];
|
|
519
|
-
const visit = (node: NodeId, context:
|
|
516
|
+
const contexts: Array<any> = [];
|
|
517
|
+
const visit = (node: NodeId, context: unknown | null) => {
|
|
520
518
|
contexts.push([node, context]);
|
|
521
519
|
return `node-${node}-created-context`;
|
|
522
520
|
};
|
|
@@ -529,8 +527,8 @@ describe('Graph', () => {
|
|
|
529
527
|
});
|
|
530
528
|
|
|
531
529
|
assert.deepEqual(
|
|
532
|
-
contexts.map((values) =>
|
|
533
|
-
values.map((v) => (v != null ? v : undefined)),
|
|
530
|
+
contexts.map((values: any) =>
|
|
531
|
+
values.map((v: any) => (v != null ? v : undefined)),
|
|
534
532
|
),
|
|
535
533
|
[
|
|
536
534
|
[0, undefined],
|
|
@@ -557,12 +555,12 @@ describe('Graph', () => {
|
|
|
557
555
|
graph.addEdge(1, 3);
|
|
558
556
|
graph.addEdge(0, 2);
|
|
559
557
|
|
|
560
|
-
const contexts = [];
|
|
561
|
-
const visit = (node: NodeId, context:
|
|
558
|
+
const contexts: Array<any> = [];
|
|
559
|
+
const visit = (node: NodeId, context: unknown | null) => {
|
|
562
560
|
contexts.push([node, context]);
|
|
563
561
|
return `node-${node}-created-context`;
|
|
564
562
|
};
|
|
565
|
-
const visitExit = (node: NodeId, context:
|
|
563
|
+
const visitExit = (node: NodeId, context: unknown | null) => {
|
|
566
564
|
contexts.push(['exit', node, context]);
|
|
567
565
|
return `node-exit-${node}-created-context`;
|
|
568
566
|
};
|
|
@@ -578,8 +576,8 @@ describe('Graph', () => {
|
|
|
578
576
|
});
|
|
579
577
|
|
|
580
578
|
assert.deepEqual(
|
|
581
|
-
contexts.map((values) =>
|
|
582
|
-
values.map((v) => (v != null ? v : undefined)),
|
|
579
|
+
contexts.map((values: any) =>
|
|
580
|
+
values.map((v: any) => (v != null ? v : undefined)),
|
|
583
581
|
),
|
|
584
582
|
[
|
|
585
583
|
[0, undefined],
|
|
@@ -612,8 +610,8 @@ describe('Graph', () => {
|
|
|
612
610
|
graph.addEdge(a, c);
|
|
613
611
|
graph.addEdge(c, d);
|
|
614
612
|
|
|
615
|
-
const order = [];
|
|
616
|
-
graph.forEachNodeIdConnectedTo(d, (node) => {
|
|
613
|
+
const order: Array<any> = [];
|
|
614
|
+
graph.forEachNodeIdConnectedTo(d, (node: any) => {
|
|
617
615
|
order.push(node);
|
|
618
616
|
});
|
|
619
617
|
|
|
@@ -636,8 +634,8 @@ describe('Graph', () => {
|
|
|
636
634
|
graph.addEdge(a, c);
|
|
637
635
|
graph.addEdge(c, d);
|
|
638
636
|
|
|
639
|
-
const order = [];
|
|
640
|
-
graph.forEachNodeIdConnectedFrom(a, (node) => {
|
|
637
|
+
const order: Array<any> = [];
|
|
638
|
+
graph.forEachNodeIdConnectedFrom(a, (node: any) => {
|
|
641
639
|
order.push(node);
|
|
642
640
|
});
|
|
643
641
|
|
package/tsconfig.json
ADDED