@atlaspack/graph 3.5.10 → 3.5.11-typescript-5ad950d33.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
package/lib/AdjacencyList.js
CHANGED
|
@@ -23,9 +23,13 @@ var _types = require("./types");
|
|
|
23
23
|
var _Graph = require("./Graph");
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
25
|
/** The address of the node in the nodes map. */
|
|
26
|
+
|
|
26
27
|
/** The address of the edge in the edges map. */
|
|
28
|
+
|
|
27
29
|
// eslint-disable-next-line no-unused-vars
|
|
30
|
+
|
|
28
31
|
// eslint-disable-next-line no-unused-vars
|
|
32
|
+
|
|
29
33
|
const DEFAULT_PARAMS = {
|
|
30
34
|
initialCapacity: 2,
|
|
31
35
|
unloadFactor: 0.3,
|
|
@@ -99,7 +103,10 @@ class AdjacencyList {
|
|
|
99
103
|
constructor(opts) {
|
|
100
104
|
let nodes;
|
|
101
105
|
let edges;
|
|
106
|
+
|
|
107
|
+
// @ts-expect-error TS2339
|
|
102
108
|
if (opts !== null && opts !== void 0 && opts.nodes) {
|
|
109
|
+
// @ts-expect-error TS2339
|
|
103
110
|
({
|
|
104
111
|
nodes,
|
|
105
112
|
edges
|
|
@@ -152,6 +159,7 @@ class AdjacencyList {
|
|
|
152
159
|
get stats() {
|
|
153
160
|
let edgeTypes = new Set();
|
|
154
161
|
let buckets = new Map();
|
|
162
|
+
// @ts-expect-error TS2488
|
|
155
163
|
for (let {
|
|
156
164
|
from,
|
|
157
165
|
to,
|
|
@@ -224,13 +232,17 @@ class AdjacencyList {
|
|
|
224
232
|
|
|
225
233
|
// Copy the existing edges into the new array.
|
|
226
234
|
nodes.nextId = this.#nodes.nextId;
|
|
227
|
-
this.#edges.forEach(edge => void link(this.#edges.from(edge), this.#edges.to(edge), this.#edges.typeOf(edge),
|
|
235
|
+
this.#edges.forEach(edge => void link(this.#edges.from(edge), this.#edges.to(edge), this.#edges.typeOf(edge),
|
|
236
|
+
// @ts-expect-error TS2345
|
|
237
|
+
edges, nodes, this.#params.unloadFactor));
|
|
228
238
|
|
|
229
239
|
// We expect to preserve the same number of edges.
|
|
230
240
|
(0, _assert().default)(this.#edges.count === edges.count, `Edge mismatch! ${this.#edges.count} does not match ${edges.count}.`);
|
|
231
241
|
|
|
232
242
|
// Finally, copy the new data arrays over to this graph.
|
|
243
|
+
// @ts-expect-error TS2322
|
|
233
244
|
this.#nodes = nodes;
|
|
245
|
+
// @ts-expect-error TS2322
|
|
234
246
|
this.#edges = edges;
|
|
235
247
|
}
|
|
236
248
|
|
|
@@ -599,6 +611,7 @@ class SharedTypeMap {
|
|
|
599
611
|
static #TYPE = 1;
|
|
600
612
|
|
|
601
613
|
/** The largest possible capacity. */
|
|
614
|
+
// @ts-expect-error TS1094
|
|
602
615
|
static get MAX_CAPACITY() {
|
|
603
616
|
return Math.floor(
|
|
604
617
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length#what_went_wrong
|
|
@@ -631,6 +644,7 @@ class SharedTypeMap {
|
|
|
631
644
|
|
|
632
645
|
/** The address of the first item in the map. */
|
|
633
646
|
get addressableLimit() {
|
|
647
|
+
// @ts-expect-error TS2339
|
|
634
648
|
return this.constructor.HEADER_SIZE + this.capacity;
|
|
635
649
|
}
|
|
636
650
|
|
|
@@ -653,7 +667,6 @@ class SharedTypeMap {
|
|
|
653
667
|
BYTES_PER_ELEMENT
|
|
654
668
|
} = Uint32Array;
|
|
655
669
|
let CAPACITY = SharedTypeMap.#CAPACITY;
|
|
656
|
-
// $FlowFixMe[incompatible-call]
|
|
657
670
|
this.data = new Uint32Array(new _sharedBuffer.SharedBuffer(this.getLength(capacityOrData) * BYTES_PER_ELEMENT));
|
|
658
671
|
this.data[CAPACITY] = capacityOrData;
|
|
659
672
|
} else {
|
|
@@ -670,6 +683,7 @@ class SharedTypeMap {
|
|
|
670
683
|
* and is expected to be of equal or smaller capacity to this map.
|
|
671
684
|
*/
|
|
672
685
|
set(data) {
|
|
686
|
+
// @ts-expect-error TS2339
|
|
673
687
|
let {
|
|
674
688
|
HEADER_SIZE,
|
|
675
689
|
ITEM_SIZE
|
|
@@ -720,6 +734,7 @@ class SharedTypeMap {
|
|
|
720
734
|
* get the length of the map, in bytes.
|
|
721
735
|
*/
|
|
722
736
|
getLength(capacity = this.capacity) {
|
|
737
|
+
// @ts-expect-error TS2339
|
|
723
738
|
let {
|
|
724
739
|
HEADER_SIZE,
|
|
725
740
|
ITEM_SIZE
|
|
@@ -729,6 +744,7 @@ class SharedTypeMap {
|
|
|
729
744
|
|
|
730
745
|
/** Get the next available address in the map. */
|
|
731
746
|
getNextAddress() {
|
|
747
|
+
// @ts-expect-error TS2339
|
|
732
748
|
let {
|
|
733
749
|
HEADER_SIZE,
|
|
734
750
|
ITEM_SIZE
|
|
@@ -738,6 +754,7 @@ class SharedTypeMap {
|
|
|
738
754
|
|
|
739
755
|
/** Get the address of the first item with the given hash. */
|
|
740
756
|
head(hash) {
|
|
757
|
+
// @ts-expect-error TS2339
|
|
741
758
|
let {
|
|
742
759
|
HEADER_SIZE
|
|
743
760
|
} = this.constructor;
|
|
@@ -763,6 +780,7 @@ class SharedTypeMap {
|
|
|
763
780
|
let COUNT = SharedTypeMap.#COUNT;
|
|
764
781
|
let NEXT = SharedTypeMap.#NEXT;
|
|
765
782
|
let TYPE = SharedTypeMap.#TYPE;
|
|
783
|
+
// @ts-expect-error TS2339
|
|
766
784
|
let {
|
|
767
785
|
HEADER_SIZE
|
|
768
786
|
} = this.constructor;
|
|
@@ -789,6 +807,7 @@ class SharedTypeMap {
|
|
|
789
807
|
let COUNT = SharedTypeMap.#COUNT;
|
|
790
808
|
let NEXT = SharedTypeMap.#NEXT;
|
|
791
809
|
let TYPE = SharedTypeMap.#TYPE;
|
|
810
|
+
// @ts-expect-error TS2339
|
|
792
811
|
let {
|
|
793
812
|
HEADER_SIZE
|
|
794
813
|
} = this.constructor;
|
|
@@ -801,6 +820,7 @@ class SharedTypeMap {
|
|
|
801
820
|
let candidate = head;
|
|
802
821
|
while (candidate !== null && candidate !== item) {
|
|
803
822
|
prev = candidate;
|
|
823
|
+
// @ts-expect-error TS2322
|
|
804
824
|
candidate = this.next(candidate);
|
|
805
825
|
}
|
|
806
826
|
if (prev !== null && next !== null) {
|
|
@@ -818,6 +838,7 @@ class SharedTypeMap {
|
|
|
818
838
|
forEach(cb) {
|
|
819
839
|
let max = this.count;
|
|
820
840
|
let len = this.length;
|
|
841
|
+
// @ts-expect-error TS2339
|
|
821
842
|
let {
|
|
822
843
|
ITEM_SIZE
|
|
823
844
|
} = this.constructor;
|
|
@@ -834,10 +855,10 @@ class SharedTypeMap {
|
|
|
834
855
|
// See https://github.com/facebook/flow/issues/1163#issuecomment-353523840
|
|
835
856
|
/*:: @@iterator(): Iterator<TAddress> { return ({}: any); } */
|
|
836
857
|
|
|
837
|
-
// $FlowFixMe[unsupported-syntax]
|
|
838
858
|
*[Symbol.iterator]() {
|
|
839
859
|
let max = this.count;
|
|
840
860
|
let len = this.length;
|
|
861
|
+
// @ts-expect-error TS2339
|
|
841
862
|
let {
|
|
842
863
|
ITEM_SIZE
|
|
843
864
|
} = this.constructor;
|
|
@@ -849,6 +870,7 @@ class SharedTypeMap {
|
|
|
849
870
|
}
|
|
850
871
|
}
|
|
851
872
|
inspect() {
|
|
873
|
+
// @ts-expect-error TS2339
|
|
852
874
|
const {
|
|
853
875
|
HEADER_SIZE
|
|
854
876
|
} = this.constructor;
|
|
@@ -1168,6 +1190,7 @@ class EdgeTypeMap extends SharedTypeMap {
|
|
|
1168
1190
|
|
|
1169
1191
|
/** Get the next available address in the map. */
|
|
1170
1192
|
getNextAddress() {
|
|
1193
|
+
// @ts-expect-error TS2339
|
|
1171
1194
|
let {
|
|
1172
1195
|
ITEM_SIZE
|
|
1173
1196
|
} = this.constructor;
|
package/lib/BitSet.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class BitSet {
|
|
2
|
+
bits: Uint32Array;
|
|
3
|
+
constructor(maxBits: number);
|
|
4
|
+
clone(): BitSet;
|
|
5
|
+
static union(a: BitSet, b: BitSet): BitSet;
|
|
6
|
+
static intersect(a: BitSet, b: BitSet): BitSet;
|
|
7
|
+
get capacity(): number;
|
|
8
|
+
add(bit: number): void;
|
|
9
|
+
delete(bit: number): void;
|
|
10
|
+
has(bit: number): boolean;
|
|
11
|
+
empty(): boolean;
|
|
12
|
+
clear(): void;
|
|
13
|
+
intersect(other: BitSet): void;
|
|
14
|
+
union(other: BitSet): void;
|
|
15
|
+
remove(other: BitSet): void;
|
|
16
|
+
size(): number;
|
|
17
|
+
equals(other: BitSet): boolean;
|
|
18
|
+
forEach(fn: (bit: number) => void): void;
|
|
19
|
+
}
|
package/lib/BitSet.js
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ContentKey, NodeId } from './types';
|
|
2
|
+
import Graph, { SerializedGraph, GraphOpts } from './Graph';
|
|
3
|
+
export type ContentGraphOpts<TNode, TEdgeType extends number = 1> = GraphOpts<TNode, TEdgeType> & {
|
|
4
|
+
_contentKeyToNodeId: Map<ContentKey, NodeId>;
|
|
5
|
+
_nodeIdToContentKey: Map<NodeId, ContentKey>;
|
|
6
|
+
};
|
|
7
|
+
export type SerializedContentGraph<TNode, TEdgeType extends number = 1> = SerializedGraph<TNode, TEdgeType> & {
|
|
8
|
+
_contentKeyToNodeId: Map<ContentKey, NodeId>;
|
|
9
|
+
};
|
|
10
|
+
export default class ContentGraph<TNode, TEdgeType extends number = 1> extends Graph<TNode, TEdgeType> {
|
|
11
|
+
_contentKeyToNodeId: Map<ContentKey, NodeId>;
|
|
12
|
+
_nodeIdToContentKey: Map<NodeId, ContentKey>;
|
|
13
|
+
constructor(opts?: ContentGraphOpts<TNode, TEdgeType> | null);
|
|
14
|
+
static deserialize<TNode, TEdgeType extends number = 1>(opts: ContentGraphOpts<TNode, TEdgeType>): ContentGraph<TNode, TEdgeType>;
|
|
15
|
+
serialize(): SerializedContentGraph<TNode, TEdgeType>;
|
|
16
|
+
addNodeByContentKey(contentKey: ContentKey, node: TNode): NodeId;
|
|
17
|
+
addNodeByContentKeyIfNeeded(contentKey: ContentKey, node: TNode): NodeId;
|
|
18
|
+
getNodeByContentKey(contentKey: ContentKey): TNode | null | undefined;
|
|
19
|
+
getContentKeyByNodeId(nodeId: NodeId): ContentKey;
|
|
20
|
+
getNodeIdByContentKey(contentKey: ContentKey): NodeId;
|
|
21
|
+
hasContentKey(contentKey: ContentKey): boolean;
|
|
22
|
+
removeNode(nodeId: NodeId, removeOrphans?: boolean): void;
|
|
23
|
+
}
|
package/lib/ContentGraph.js
CHANGED
|
@@ -30,18 +30,14 @@ class ContentGraph extends _Graph.default {
|
|
|
30
30
|
this._nodeIdToContentKey = new Map();
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
// $FlowFixMe[prop-missing]
|
|
35
33
|
static deserialize(opts) {
|
|
36
34
|
return new ContentGraph(opts);
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
// $FlowFixMe[prop-missing]
|
|
40
36
|
serialize() {
|
|
41
|
-
// $FlowFixMe[prop-missing]
|
|
42
37
|
return {
|
|
43
38
|
...super.serialize(),
|
|
44
39
|
_contentKeyToNodeId: this._contentKeyToNodeId,
|
|
40
|
+
// @ts-expect-error TS2353
|
|
45
41
|
_nodeIdToContentKey: this._nodeIdToContentKey
|
|
46
42
|
};
|
|
47
43
|
}
|
package/lib/Graph.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import AdjacencyList, { SerializedAdjacencyList } from './AdjacencyList';
|
|
2
|
+
import type { Edge, NodeId } from './types';
|
|
3
|
+
import type { TraversalActions, GraphVisitor, GraphTraversalCallback } from '@atlaspack/types';
|
|
4
|
+
import { BitSet } from './BitSet';
|
|
5
|
+
export type NullEdgeType = 1;
|
|
6
|
+
export declare const NULL_EDGE_TYPE: NullEdgeType;
|
|
7
|
+
export type GraphOpts<TNode, TEdgeType extends number = NullEdgeType> = {
|
|
8
|
+
nodes?: Array<TNode | null>;
|
|
9
|
+
adjacencyList?: SerializedAdjacencyList<TEdgeType>;
|
|
10
|
+
rootNodeId?: NodeId | null | undefined;
|
|
11
|
+
initialCapacity?: number;
|
|
12
|
+
};
|
|
13
|
+
export type SerializedGraph<TNode, TEdgeType extends number = NullEdgeType> = {
|
|
14
|
+
nodes: Array<TNode | null>;
|
|
15
|
+
adjacencyList: SerializedAdjacencyList<TEdgeType>;
|
|
16
|
+
rootNodeId: NodeId | null | undefined;
|
|
17
|
+
};
|
|
18
|
+
export type AllEdgeTypes = -1;
|
|
19
|
+
export declare const ALL_EDGE_TYPES: AllEdgeTypes;
|
|
20
|
+
/**
|
|
21
|
+
* Options for DFS traversal.
|
|
22
|
+
*/
|
|
23
|
+
export type DFSParams<TContext> = {
|
|
24
|
+
visit: GraphVisitor<NodeId, TContext>;
|
|
25
|
+
/**
|
|
26
|
+
* Custom function to get next entries to visit.
|
|
27
|
+
*
|
|
28
|
+
* This can be a performance bottleneck as arrays are created on every node visit.
|
|
29
|
+
*
|
|
30
|
+
* @deprecated This will be replaced by a static `traversalType` set of orders in the future
|
|
31
|
+
*
|
|
32
|
+
* Currently, this is only used in 3 ways:
|
|
33
|
+
*
|
|
34
|
+
* - Traversing down the tree (normal DFS)
|
|
35
|
+
* - Traversing up the tree (ancestors)
|
|
36
|
+
* - Filtered version of traversal; which does not need to exist at the DFS level as the visitor
|
|
37
|
+
* can handle filtering
|
|
38
|
+
* - Sorted traversal of BundleGraph entries, which does not have a clear use-case, but may
|
|
39
|
+
* not be safe to remove
|
|
40
|
+
*
|
|
41
|
+
* Only due to the latter we aren't replacing this.
|
|
42
|
+
*/
|
|
43
|
+
getChildren: (nodeId: NodeId) => Array<NodeId>;
|
|
44
|
+
startNodeId?: NodeId | null | undefined;
|
|
45
|
+
};
|
|
46
|
+
export default class Graph<TNode, TEdgeType extends number = NullEdgeType> {
|
|
47
|
+
nodes: Array<TNode | null>;
|
|
48
|
+
adjacencyList: AdjacencyList<TEdgeType>;
|
|
49
|
+
rootNodeId: NodeId | null | undefined;
|
|
50
|
+
_visited: BitSet | null | undefined;
|
|
51
|
+
constructor(opts?: GraphOpts<TNode, TEdgeType> | null);
|
|
52
|
+
setRootNodeId(id?: NodeId | null): void;
|
|
53
|
+
static deserialize<TNode, TEdgeType extends number = NullEdgeType>(opts: GraphOpts<TNode, TEdgeType>): Graph<TNode, TEdgeType>;
|
|
54
|
+
serialize(): SerializedGraph<TNode, TEdgeType>;
|
|
55
|
+
getAllEdges(): Iterator<Edge<TEdgeType | NullEdgeType>>;
|
|
56
|
+
addNode(node: TNode): NodeId;
|
|
57
|
+
hasNode(id: NodeId): boolean;
|
|
58
|
+
getNode(id: NodeId): TNode | null | undefined;
|
|
59
|
+
addEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType): boolean;
|
|
60
|
+
hasEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType>): boolean;
|
|
61
|
+
forEachNodeIdConnectedTo(to: NodeId, fn: (nodeId: NodeId) => boolean | undefined, type?: AllEdgeTypes | TEdgeType | NullEdgeType): void;
|
|
62
|
+
forEachNodeIdConnectedFrom(from: NodeId, fn: (nodeId: NodeId) => void, type?: AllEdgeTypes | TEdgeType | NullEdgeType): void;
|
|
63
|
+
getNodeIdsConnectedTo(nodeId: NodeId, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): Array<NodeId>;
|
|
64
|
+
getNodeIdsConnectedFrom(nodeId: NodeId, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): Array<NodeId>;
|
|
65
|
+
removeNode(nodeId: NodeId, removeOrphans?: boolean): void;
|
|
66
|
+
removeEdges(nodeId: NodeId, type?: TEdgeType | NullEdgeType): void;
|
|
67
|
+
removeEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType, removeOrphans?: boolean): void;
|
|
68
|
+
_removeEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType, removeOrphans?: boolean): void;
|
|
69
|
+
isOrphanedNode(nodeId: NodeId): boolean;
|
|
70
|
+
updateNode(nodeId: NodeId, node: TNode): void;
|
|
71
|
+
replaceNodeIdsConnectedTo(fromNodeId: NodeId, toNodeIds: ReadonlyArray<NodeId>, replaceFilter?: null | ((arg1: NodeId) => boolean), type?: TEdgeType | NullEdgeType, removeOrphans?: boolean): void;
|
|
72
|
+
traverse<TContext>(visit: GraphVisitor<NodeId, TContext>, startNodeId?: NodeId | null, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): TContext | null | undefined;
|
|
73
|
+
filteredTraverse<TValue, TContext>(filter: (arg1: NodeId, arg2: TraversalActions) => TValue | null | undefined, visit: GraphVisitor<TValue, TContext>, startNodeId?: NodeId | null, type?: TEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): TContext | null | undefined;
|
|
74
|
+
traverseAncestors<TContext>(startNodeId: NodeId | null | undefined, visit: GraphVisitor<NodeId, TContext>, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): TContext | null | undefined;
|
|
75
|
+
dfsFast<TContext>(visit: GraphTraversalCallback<NodeId, TContext>, startNodeId?: NodeId | null): TContext | null | undefined;
|
|
76
|
+
postOrderDfsFast(visit: GraphTraversalCallback<NodeId, TraversalActions>, startNodeId?: NodeId | null): void;
|
|
77
|
+
/**
|
|
78
|
+
* Iterative implementation of DFS that supports all use-cases.
|
|
79
|
+
*
|
|
80
|
+
* This replaces `dfs` and will replace `dfsFast`.
|
|
81
|
+
*/
|
|
82
|
+
dfs<TContext>({ visit, startNodeId, getChildren, }: DFSParams<TContext>): TContext | null | undefined;
|
|
83
|
+
bfs(visit: (nodeId: NodeId) => boolean | null | undefined): NodeId | null | undefined;
|
|
84
|
+
topoSort(type?: TEdgeType): Array<NodeId>;
|
|
85
|
+
findAncestor(nodeId: NodeId, fn: (nodeId: NodeId) => boolean): NodeId | null | undefined;
|
|
86
|
+
findAncestors(nodeId: NodeId, fn: (nodeId: NodeId) => boolean): Array<NodeId>;
|
|
87
|
+
findDescendant(nodeId: NodeId, fn: (nodeId: NodeId) => boolean): NodeId | null | undefined;
|
|
88
|
+
findDescendants(nodeId: NodeId, fn: (nodeId: NodeId) => boolean): Array<NodeId>;
|
|
89
|
+
_assertHasNodeId(nodeId: NodeId): void;
|
|
90
|
+
}
|
|
91
|
+
export declare function mapVisitor<NodeId, TValue, TContext>(filter: (arg1: NodeId, arg2: TraversalActions) => TValue | null | undefined, visit: GraphVisitor<TValue, TContext>): GraphVisitor<NodeId, TContext>;
|
package/lib/Graph.js
CHANGED
|
@@ -248,6 +248,7 @@ class Graph {
|
|
|
248
248
|
context: null
|
|
249
249
|
}];
|
|
250
250
|
while (queue.length !== 0) {
|
|
251
|
+
// @ts-expect-error TS2339
|
|
251
252
|
let {
|
|
252
253
|
nodeId,
|
|
253
254
|
context
|
|
@@ -257,7 +258,6 @@ class Graph {
|
|
|
257
258
|
skipped = false;
|
|
258
259
|
let newContext = visit(nodeId, context, actions);
|
|
259
260
|
if (typeof newContext !== 'undefined') {
|
|
260
|
-
// $FlowFixMe[reassign-const]
|
|
261
261
|
context = newContext;
|
|
262
262
|
}
|
|
263
263
|
if (skipped) {
|
|
@@ -366,15 +366,18 @@ class Graph {
|
|
|
366
366
|
const enter = typeof visit === 'function' ? visit : visit.enter;
|
|
367
367
|
while (queue.length !== 0) {
|
|
368
368
|
const command = queue.pop();
|
|
369
|
+
|
|
370
|
+
// @ts-expect-error TS18048
|
|
369
371
|
if (command.exit != null) {
|
|
372
|
+
// @ts-expect-error TS2339
|
|
370
373
|
let {
|
|
371
374
|
nodeId,
|
|
372
375
|
context,
|
|
373
376
|
exit
|
|
374
377
|
} = command;
|
|
378
|
+
// @ts-expect-error TS18048
|
|
375
379
|
let newContext = exit(nodeId, command.context, actions);
|
|
376
380
|
if (typeof newContext !== 'undefined') {
|
|
377
|
-
// $FlowFixMe[reassign-const]
|
|
378
381
|
context = newContext;
|
|
379
382
|
}
|
|
380
383
|
if (skipped) {
|
|
@@ -385,6 +388,7 @@ class Graph {
|
|
|
385
388
|
return context;
|
|
386
389
|
}
|
|
387
390
|
} else {
|
|
391
|
+
// @ts-expect-error TS2339
|
|
388
392
|
let {
|
|
389
393
|
nodeId,
|
|
390
394
|
context
|
|
@@ -395,7 +399,6 @@ class Graph {
|
|
|
395
399
|
if (enter) {
|
|
396
400
|
let newContext = enter(nodeId, context, actions);
|
|
397
401
|
if (typeof newContext !== 'undefined') {
|
|
398
|
-
// $FlowFixMe[reassign-const]
|
|
399
402
|
context = newContext;
|
|
400
403
|
}
|
|
401
404
|
}
|
|
@@ -440,6 +443,8 @@ class Graph {
|
|
|
440
443
|
if (stop === true) {
|
|
441
444
|
return node;
|
|
442
445
|
}
|
|
446
|
+
|
|
447
|
+
// @ts-expect-error TS2345
|
|
443
448
|
for (let child of this.getNodeIdsConnectedFrom(node)) {
|
|
444
449
|
if (!visited.has(child)) {
|
|
445
450
|
visited.add(child);
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { NodeId, ContentKey, Edge } from './types';
|
|
2
|
+
export type { GraphOpts } from './Graph';
|
|
3
|
+
export type { ContentGraphOpts, SerializedContentGraph } from './ContentGraph';
|
|
4
|
+
export { toNodeId, fromNodeId } from './types';
|
|
5
|
+
export { default as Graph, ALL_EDGE_TYPES, mapVisitor } from './Graph';
|
|
6
|
+
export { default as ContentGraph } from './ContentGraph';
|
|
7
|
+
export { BitSet } from './BitSet';
|
package/lib/shared-buffer.js
CHANGED
|
@@ -4,10 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.SharedBuffer = void 0;
|
|
7
|
+
// flow-to-ts helpers
|
|
8
|
+
|
|
9
|
+
// /flow-to-ts helpers
|
|
10
|
+
|
|
7
11
|
// Copy from @atlaspack/utils to fix: https://github.com/stackblitz/core/issues/1855
|
|
8
12
|
let SharedBuffer = exports.SharedBuffer = void 0;
|
|
9
13
|
|
|
10
|
-
//
|
|
14
|
+
// @ts-expect-error TS2339
|
|
11
15
|
if (process.browser) {
|
|
12
16
|
exports.SharedBuffer = SharedBuffer = ArrayBuffer;
|
|
13
17
|
// Safari has removed the constructor
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type NodeId = number;
|
|
2
|
+
export declare function toNodeId(x: number): NodeId;
|
|
3
|
+
export declare function fromNodeId(x: NodeId): number;
|
|
4
|
+
export type ContentKey = string;
|
|
5
|
+
export type Edge<TEdgeType extends number> = {
|
|
6
|
+
from: NodeId;
|
|
7
|
+
to: NodeId;
|
|
8
|
+
type: TEdgeType;
|
|
9
|
+
};
|
package/lib/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/graph",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.11-typescript-5ad950d33.0",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,21 +10,24 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
12
|
},
|
|
13
|
-
"main": "lib/index.js",
|
|
14
|
-
"source": "src/index.
|
|
13
|
+
"main": "./lib/index.js",
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"types": "./lib/index.d.ts",
|
|
15
16
|
"engines": {
|
|
16
17
|
"node": ">= 16.0.0"
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|
|
19
|
-
"benchmark": "node ./benchmark/BitSet.js"
|
|
20
|
+
"benchmark": "node ./benchmark/BitSet.js",
|
|
21
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@atlaspack/feature-flags": "2.20.0",
|
|
24
|
+
"@atlaspack/feature-flags": "2.20.1-typescript-5ad950d33.0",
|
|
23
25
|
"nullthrows": "^1.1.1"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"@atlaspack/babel-register": "2.14.
|
|
28
|
+
"@atlaspack/babel-register": "2.14.2-typescript-5ad950d33.0",
|
|
27
29
|
"benny": "^3.7.1"
|
|
28
30
|
},
|
|
29
|
-
"type": "commonjs"
|
|
30
|
-
|
|
31
|
+
"type": "commonjs",
|
|
32
|
+
"gitHead": "5ad950d33a5f2255ebeb10c04a2e84c346e2de85"
|
|
33
|
+
}
|