@graphrs/core 0.0.0-canary.de24fef
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 +21 -0
- package/dist/index.d.ts +151 -0
- package/dist/index.js +278 -0
- package/dist/index.js.map +1 -0
- package/dist/worker.d.ts +7 -0
- package/dist/worker.js +10 -0
- package/dist/worker.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Totoro-jam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
type VertexId = number;
|
|
2
|
+
type EdgeId = number;
|
|
3
|
+
interface GraphOptions {
|
|
4
|
+
directed?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface NodeData {
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface EdgeData {
|
|
10
|
+
weight?: number;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface SerializedGraph {
|
|
14
|
+
directed: boolean;
|
|
15
|
+
nodes: Array<{
|
|
16
|
+
id: VertexId;
|
|
17
|
+
data?: Record<string, unknown>;
|
|
18
|
+
}>;
|
|
19
|
+
edges: Array<{
|
|
20
|
+
source: VertexId;
|
|
21
|
+
target: VertexId;
|
|
22
|
+
data?: Record<string, unknown>;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
interface CommunityResult {
|
|
26
|
+
membership: number[];
|
|
27
|
+
modularity: number;
|
|
28
|
+
clusters: number;
|
|
29
|
+
}
|
|
30
|
+
interface CentralityResult {
|
|
31
|
+
scores: number[];
|
|
32
|
+
}
|
|
33
|
+
interface LayoutResult {
|
|
34
|
+
positions: [number, number][];
|
|
35
|
+
}
|
|
36
|
+
interface Layout3DResult {
|
|
37
|
+
positions: [number, number, number][];
|
|
38
|
+
}
|
|
39
|
+
interface PathResult {
|
|
40
|
+
path: number[];
|
|
41
|
+
distance: number;
|
|
42
|
+
}
|
|
43
|
+
interface FlowResult {
|
|
44
|
+
value: number;
|
|
45
|
+
flow: number[];
|
|
46
|
+
}
|
|
47
|
+
interface G6GraphData {
|
|
48
|
+
nodes: Array<{
|
|
49
|
+
id: string;
|
|
50
|
+
x?: number;
|
|
51
|
+
y?: number;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}>;
|
|
54
|
+
edges: Array<{
|
|
55
|
+
source: string;
|
|
56
|
+
target: string;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
}>;
|
|
59
|
+
}
|
|
60
|
+
interface ReactFlowData {
|
|
61
|
+
nodes: Array<{
|
|
62
|
+
id: string;
|
|
63
|
+
position: {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
};
|
|
67
|
+
data: Record<string, unknown>;
|
|
68
|
+
}>;
|
|
69
|
+
edges: Array<{
|
|
70
|
+
id: string;
|
|
71
|
+
source: string;
|
|
72
|
+
target: string;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
interface CytoscapeData {
|
|
76
|
+
elements: {
|
|
77
|
+
nodes: Array<{
|
|
78
|
+
data: {
|
|
79
|
+
id: string;
|
|
80
|
+
[key: string]: unknown;
|
|
81
|
+
};
|
|
82
|
+
}>;
|
|
83
|
+
edges: Array<{
|
|
84
|
+
data: {
|
|
85
|
+
source: string;
|
|
86
|
+
target: string;
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
};
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
interface WasmExports {
|
|
93
|
+
[key: string]: unknown;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class Graph<N extends NodeData = NodeData, E extends EdgeData = EdgeData> {
|
|
97
|
+
readonly directed: boolean;
|
|
98
|
+
private _nodes;
|
|
99
|
+
private _edges;
|
|
100
|
+
private _adjacency;
|
|
101
|
+
constructor(options?: GraphOptions);
|
|
102
|
+
static fromEdges<N extends NodeData = NodeData, E extends EdgeData = EdgeData>(edges: [number, number][], options?: GraphOptions): Graph<N, E>;
|
|
103
|
+
static fromAdjacencyMatrix<N extends NodeData = NodeData, E extends EdgeData = EdgeData>(matrix: number[][], options?: GraphOptions): Graph<N, E>;
|
|
104
|
+
static fromJSON<N extends NodeData = NodeData, E extends EdgeData = EdgeData>(data: SerializedGraph): Graph<N, E>;
|
|
105
|
+
addNode(id: VertexId, data?: N): this;
|
|
106
|
+
addEdge(source: VertexId, target: VertexId, data?: E): this;
|
|
107
|
+
removeNode(id: VertexId): this;
|
|
108
|
+
removeEdge(source: VertexId, target: VertexId): this;
|
|
109
|
+
nodeCount(): number;
|
|
110
|
+
edgeCount(): number;
|
|
111
|
+
hasNode(id: VertexId): boolean;
|
|
112
|
+
hasEdge(source: VertexId, target: VertexId): boolean;
|
|
113
|
+
neighbors(id: VertexId): VertexId[];
|
|
114
|
+
degree(id: VertexId): number;
|
|
115
|
+
nodes(): VertexId[];
|
|
116
|
+
edges(): Array<{
|
|
117
|
+
source: VertexId;
|
|
118
|
+
target: VertexId;
|
|
119
|
+
data: E;
|
|
120
|
+
}>;
|
|
121
|
+
nodeData(id: VertexId): N;
|
|
122
|
+
subgraph(nodeIds: VertexId[]): Graph<N, E>;
|
|
123
|
+
toJSON(): SerializedGraph;
|
|
124
|
+
toG6Format(layout?: LayoutResult): G6GraphData;
|
|
125
|
+
toReactFlowFormat(layout?: LayoutResult): ReactFlowData;
|
|
126
|
+
toCytoscapeFormat(layout?: LayoutResult): CytoscapeData;
|
|
127
|
+
_getEdgePairs(): [number, number][];
|
|
128
|
+
_getWeights(): number[] | null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare function getWasm(): Promise<WasmExports>;
|
|
132
|
+
declare function isWasmInitialized(): boolean;
|
|
133
|
+
|
|
134
|
+
declare class GraphError extends Error {
|
|
135
|
+
readonly code: string;
|
|
136
|
+
constructor(code: string, message: string);
|
|
137
|
+
}
|
|
138
|
+
declare class WasmNotInitializedError extends GraphError {
|
|
139
|
+
constructor();
|
|
140
|
+
}
|
|
141
|
+
declare class NodeNotFoundError extends GraphError {
|
|
142
|
+
constructor(id: number);
|
|
143
|
+
}
|
|
144
|
+
declare class EdgeNotFoundError extends GraphError {
|
|
145
|
+
constructor(source: number, target: number);
|
|
146
|
+
}
|
|
147
|
+
declare class WasmError extends GraphError {
|
|
148
|
+
constructor(message: string);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { type CentralityResult, type CommunityResult, type CytoscapeData, type EdgeData, type EdgeId, EdgeNotFoundError, type FlowResult, type G6GraphData, Graph, GraphError, type GraphOptions, type Layout3DResult, type LayoutResult, type NodeData, NodeNotFoundError, type PathResult, type ReactFlowData, type SerializedGraph, type VertexId, WasmError, type WasmExports, WasmNotInitializedError, getWasm, isWasmInitialized };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var GraphError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "GraphError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var WasmNotInitializedError = class extends GraphError {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(
|
|
13
|
+
"WASM_NOT_INITIALIZED",
|
|
14
|
+
"WASM module has not been initialized. Call an async algorithm function first."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var NodeNotFoundError = class extends GraphError {
|
|
19
|
+
constructor(id) {
|
|
20
|
+
super("NODE_NOT_FOUND", `Node ${id} not found in graph`);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var EdgeNotFoundError = class extends GraphError {
|
|
24
|
+
constructor(source, target) {
|
|
25
|
+
super("EDGE_NOT_FOUND", `Edge (${source}, ${target}) not found in graph`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var WasmError = class extends GraphError {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super("WASM_ERROR", message);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/graph.ts
|
|
35
|
+
var Graph = class _Graph {
|
|
36
|
+
directed;
|
|
37
|
+
_nodes = /* @__PURE__ */ new Map();
|
|
38
|
+
_edges = [];
|
|
39
|
+
_adjacency = /* @__PURE__ */ new Map();
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.directed = options?.directed ?? false;
|
|
42
|
+
}
|
|
43
|
+
static fromEdges(edges, options) {
|
|
44
|
+
const g = new _Graph(options);
|
|
45
|
+
for (const [source, target] of edges) {
|
|
46
|
+
if (!g.hasNode(source)) g.addNode(source);
|
|
47
|
+
if (!g.hasNode(target)) g.addNode(target);
|
|
48
|
+
g.addEdge(source, target);
|
|
49
|
+
}
|
|
50
|
+
return g;
|
|
51
|
+
}
|
|
52
|
+
static fromAdjacencyMatrix(matrix, options) {
|
|
53
|
+
const g = new _Graph(options);
|
|
54
|
+
const n = matrix.length;
|
|
55
|
+
for (let i = 0; i < n; i++) {
|
|
56
|
+
g.addNode(i);
|
|
57
|
+
}
|
|
58
|
+
for (let i = 0; i < n; i++) {
|
|
59
|
+
for (let j = 0; j < n; j++) {
|
|
60
|
+
if (matrix[i][j] > 0) {
|
|
61
|
+
if (!g.directed && j <= i) continue;
|
|
62
|
+
g.addEdge(i, j, { weight: matrix[i][j] });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return g;
|
|
67
|
+
}
|
|
68
|
+
static fromJSON(data) {
|
|
69
|
+
const g = new _Graph({ directed: data.directed });
|
|
70
|
+
for (const node of data.nodes) {
|
|
71
|
+
g.addNode(node.id, node.data);
|
|
72
|
+
}
|
|
73
|
+
for (const edge of data.edges) {
|
|
74
|
+
g.addEdge(edge.source, edge.target, edge.data);
|
|
75
|
+
}
|
|
76
|
+
return g;
|
|
77
|
+
}
|
|
78
|
+
addNode(id, data) {
|
|
79
|
+
if (!this._nodes.has(id)) {
|
|
80
|
+
this._nodes.set(id, { id, data: data ?? {} });
|
|
81
|
+
this._adjacency.set(id, /* @__PURE__ */ new Set());
|
|
82
|
+
}
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
addEdge(source, target, data) {
|
|
86
|
+
if (!this._nodes.has(source)) this.addNode(source);
|
|
87
|
+
if (!this._nodes.has(target)) this.addNode(target);
|
|
88
|
+
this._edges.push({ source, target, data: data ?? {} });
|
|
89
|
+
this._adjacency.get(source).add(target);
|
|
90
|
+
if (!this.directed) {
|
|
91
|
+
this._adjacency.get(target).add(source);
|
|
92
|
+
}
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
removeNode(id) {
|
|
96
|
+
if (!this._nodes.has(id)) throw new NodeNotFoundError(id);
|
|
97
|
+
this._nodes.delete(id);
|
|
98
|
+
this._adjacency.delete(id);
|
|
99
|
+
this._edges = this._edges.filter((e) => e.source !== id && e.target !== id);
|
|
100
|
+
for (const neighbors of this._adjacency.values()) {
|
|
101
|
+
neighbors.delete(id);
|
|
102
|
+
}
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
removeEdge(source, target) {
|
|
106
|
+
const idx = this._edges.findIndex((e) => e.source === source && e.target === target);
|
|
107
|
+
if (idx === -1) throw new EdgeNotFoundError(source, target);
|
|
108
|
+
this._edges.splice(idx, 1);
|
|
109
|
+
const hasOther = this._edges.some((e) => e.source === source && e.target === target);
|
|
110
|
+
if (!hasOther) {
|
|
111
|
+
this._adjacency.get(source)?.delete(target);
|
|
112
|
+
if (!this.directed) {
|
|
113
|
+
this._adjacency.get(target)?.delete(source);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
nodeCount() {
|
|
119
|
+
return this._nodes.size;
|
|
120
|
+
}
|
|
121
|
+
edgeCount() {
|
|
122
|
+
return this._edges.length;
|
|
123
|
+
}
|
|
124
|
+
hasNode(id) {
|
|
125
|
+
return this._nodes.has(id);
|
|
126
|
+
}
|
|
127
|
+
hasEdge(source, target) {
|
|
128
|
+
return this._edges.some((e) => e.source === source && e.target === target);
|
|
129
|
+
}
|
|
130
|
+
neighbors(id) {
|
|
131
|
+
const adj = this._adjacency.get(id);
|
|
132
|
+
if (!adj) throw new NodeNotFoundError(id);
|
|
133
|
+
return [...adj];
|
|
134
|
+
}
|
|
135
|
+
degree(id) {
|
|
136
|
+
const adj = this._adjacency.get(id);
|
|
137
|
+
if (!adj) throw new NodeNotFoundError(id);
|
|
138
|
+
return adj.size;
|
|
139
|
+
}
|
|
140
|
+
nodes() {
|
|
141
|
+
return [...this._nodes.keys()];
|
|
142
|
+
}
|
|
143
|
+
edges() {
|
|
144
|
+
return this._edges.map((e) => ({ source: e.source, target: e.target, data: e.data }));
|
|
145
|
+
}
|
|
146
|
+
nodeData(id) {
|
|
147
|
+
const node = this._nodes.get(id);
|
|
148
|
+
if (!node) throw new NodeNotFoundError(id);
|
|
149
|
+
return node.data;
|
|
150
|
+
}
|
|
151
|
+
subgraph(nodeIds) {
|
|
152
|
+
const nodeSet = new Set(nodeIds);
|
|
153
|
+
const g = new _Graph({ directed: this.directed });
|
|
154
|
+
for (const id of nodeIds) {
|
|
155
|
+
if (this._nodes.has(id)) {
|
|
156
|
+
g.addNode(id, this._nodes.get(id).data);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
for (const edge of this._edges) {
|
|
160
|
+
if (nodeSet.has(edge.source) && nodeSet.has(edge.target)) {
|
|
161
|
+
g.addEdge(edge.source, edge.target, edge.data);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return g;
|
|
165
|
+
}
|
|
166
|
+
toJSON() {
|
|
167
|
+
return {
|
|
168
|
+
directed: this.directed,
|
|
169
|
+
nodes: [...this._nodes.values()].map((n) => ({
|
|
170
|
+
id: n.id,
|
|
171
|
+
data: n.data
|
|
172
|
+
})),
|
|
173
|
+
edges: this._edges.map((e) => ({
|
|
174
|
+
source: e.source,
|
|
175
|
+
target: e.target,
|
|
176
|
+
data: e.data
|
|
177
|
+
}))
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
toG6Format(layout) {
|
|
181
|
+
const nodes = [...this._nodes.values()].map((n, i) => ({
|
|
182
|
+
id: String(n.id),
|
|
183
|
+
...layout ? { x: layout.positions[i][0], y: layout.positions[i][1] } : {},
|
|
184
|
+
...n.data
|
|
185
|
+
}));
|
|
186
|
+
const edgesOut = this._edges.map((e) => ({
|
|
187
|
+
source: String(e.source),
|
|
188
|
+
target: String(e.target),
|
|
189
|
+
...e.data
|
|
190
|
+
}));
|
|
191
|
+
return { nodes, edges: edgesOut };
|
|
192
|
+
}
|
|
193
|
+
toReactFlowFormat(layout) {
|
|
194
|
+
const nodes = [...this._nodes.values()].map((n, i) => ({
|
|
195
|
+
id: String(n.id),
|
|
196
|
+
position: layout ? { x: layout.positions[i][0], y: layout.positions[i][1] } : { x: 0, y: 0 },
|
|
197
|
+
data: n.data
|
|
198
|
+
}));
|
|
199
|
+
const edgesOut = this._edges.map((e, i) => ({
|
|
200
|
+
id: `e-${i}`,
|
|
201
|
+
source: String(e.source),
|
|
202
|
+
target: String(e.target)
|
|
203
|
+
}));
|
|
204
|
+
return { nodes, edges: edgesOut };
|
|
205
|
+
}
|
|
206
|
+
toCytoscapeFormat(layout) {
|
|
207
|
+
const nodes = [...this._nodes.values()].map((n, i) => ({
|
|
208
|
+
data: {
|
|
209
|
+
id: String(n.id),
|
|
210
|
+
...layout ? { x: layout.positions[i][0], y: layout.positions[i][1] } : {},
|
|
211
|
+
...n.data
|
|
212
|
+
}
|
|
213
|
+
}));
|
|
214
|
+
const edgesOut = this._edges.map((e) => ({
|
|
215
|
+
data: {
|
|
216
|
+
source: String(e.source),
|
|
217
|
+
target: String(e.target),
|
|
218
|
+
...e.data
|
|
219
|
+
}
|
|
220
|
+
}));
|
|
221
|
+
return { elements: { nodes, edges: edgesOut } };
|
|
222
|
+
}
|
|
223
|
+
_getEdgePairs() {
|
|
224
|
+
return this._edges.map((e) => [e.source, e.target]);
|
|
225
|
+
}
|
|
226
|
+
_getWeights() {
|
|
227
|
+
const hasWeights = this._edges.some((e) => e.data.weight !== void 0);
|
|
228
|
+
if (!hasWeights) return null;
|
|
229
|
+
return this._edges.map((e) => e.data.weight ?? 1);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/wasm-loader.ts
|
|
234
|
+
var wasmInstance = null;
|
|
235
|
+
var initPromise = null;
|
|
236
|
+
function detectEnvironment() {
|
|
237
|
+
if (typeof globalThis.process !== "undefined" && globalThis.process.versions?.node) {
|
|
238
|
+
return "node";
|
|
239
|
+
}
|
|
240
|
+
return "browser";
|
|
241
|
+
}
|
|
242
|
+
async function initWasm() {
|
|
243
|
+
const env = detectEnvironment();
|
|
244
|
+
if (env === "node") {
|
|
245
|
+
const { readFile } = await import('fs/promises');
|
|
246
|
+
const { fileURLToPath } = await import('url');
|
|
247
|
+
const { dirname, join } = await import('path');
|
|
248
|
+
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
249
|
+
const wasmPath = join(currentDir, "..", "wasm", "igraph_wasm_bg.wasm");
|
|
250
|
+
const jsGluePath = join(currentDir, "..", "wasm", "igraph_wasm.js");
|
|
251
|
+
const initFn = (await import(jsGluePath)).default;
|
|
252
|
+
const wasmBytes = await readFile(wasmPath);
|
|
253
|
+
wasmInstance = await initFn(wasmBytes);
|
|
254
|
+
} else {
|
|
255
|
+
const wasmUrl = new URL("../wasm/igraph_wasm_bg.wasm", import.meta.url);
|
|
256
|
+
const jsGlueUrl = new URL("../wasm/igraph_wasm.js", import.meta.url);
|
|
257
|
+
const initFn = (await import(
|
|
258
|
+
/* @vite-ignore */
|
|
259
|
+
jsGlueUrl.href
|
|
260
|
+
)).default;
|
|
261
|
+
wasmInstance = await initFn(wasmUrl);
|
|
262
|
+
}
|
|
263
|
+
return wasmInstance;
|
|
264
|
+
}
|
|
265
|
+
async function getWasm() {
|
|
266
|
+
if (wasmInstance) return wasmInstance;
|
|
267
|
+
if (!initPromise) {
|
|
268
|
+
initPromise = initWasm();
|
|
269
|
+
}
|
|
270
|
+
return initPromise;
|
|
271
|
+
}
|
|
272
|
+
function isWasmInitialized() {
|
|
273
|
+
return wasmInstance !== null;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export { EdgeNotFoundError, Graph, GraphError, NodeNotFoundError, WasmError, WasmNotInitializedError, getWasm, isWasmInitialized };
|
|
277
|
+
//# sourceMappingURL=index.js.map
|
|
278
|
+
//# sourceMappingURL=index.js.map
|
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,CAAI,wBAAA,EAA0B,YAAY,GAAG,CAAA;AAEnE,IAAA,MAAM,UAAU,MAAM;AAAA;AAAA,MAA0B,SAAA,CAAU;AAAA,KAAA,EAAO,OAAA;AACjE,IAAA,YAAA,GAAe,MAAM,OAAO,OAAO,CAAA;AAAA,EACrC;AAEA,EAAA,OAAO,YAAA;AACT;AAEA,eAAsB,OAAA,GAAgC;AACpD,EAAA,IAAI,cAAc,OAAO,YAAA;AACzB,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,WAAA,GAAc,QAAA,EAAS;AAAA,EACzB;AACA,EAAA,OAAO,WAAA;AACT;AAMO,SAAS,iBAAA,GAA6B;AAC3C,EAAA,OAAO,YAAA,KAAiB,IAAA;AAC1B","file":"index.js","sourcesContent":["export class GraphError extends Error {\n readonly code: string;\n\n constructor(code: string, message: string) {\n super(message);\n this.name = 'GraphError';\n this.code = code;\n }\n}\n\nexport class WasmNotInitializedError extends GraphError {\n constructor() {\n super(\n 'WASM_NOT_INITIALIZED',\n 'WASM module has not been initialized. Call an async algorithm function first.',\n );\n }\n}\n\nexport class NodeNotFoundError extends GraphError {\n constructor(id: number) {\n super('NODE_NOT_FOUND', `Node ${id} not found in graph`);\n }\n}\n\nexport class EdgeNotFoundError extends GraphError {\n constructor(source: number, target: number) {\n super('EDGE_NOT_FOUND', `Edge (${source}, ${target}) not found in graph`);\n }\n}\n\nexport class WasmError extends GraphError {\n constructor(message: string) {\n super('WASM_ERROR', message);\n }\n}\n","import type {\n VertexId,\n NodeData,\n EdgeData,\n GraphOptions,\n SerializedGraph,\n LayoutResult,\n G6GraphData,\n ReactFlowData,\n CytoscapeData,\n} from './types.js';\nimport { NodeNotFoundError, EdgeNotFoundError } from './errors.js';\n\ninterface InternalNode<N> {\n id: VertexId;\n data: N;\n}\n\ninterface InternalEdge<E> {\n source: VertexId;\n target: VertexId;\n data: E;\n}\n\nexport class Graph<N extends NodeData = NodeData, E extends EdgeData = EdgeData> {\n readonly directed: boolean;\n\n private _nodes: Map<VertexId, InternalNode<N>> = new Map();\n private _edges: InternalEdge<E>[] = [];\n private _adjacency: Map<VertexId, Set<VertexId>> = new Map();\n\n constructor(options?: GraphOptions) {\n this.directed = options?.directed ?? false;\n }\n\n static fromEdges<N extends NodeData = NodeData, E extends EdgeData = EdgeData>(\n edges: [number, number][],\n options?: GraphOptions,\n ): Graph<N, E> {\n const g = new Graph<N, E>(options);\n for (const [source, target] of edges) {\n if (!g.hasNode(source)) g.addNode(source);\n if (!g.hasNode(target)) g.addNode(target);\n g.addEdge(source, target);\n }\n return g;\n }\n\n static fromAdjacencyMatrix<N extends NodeData = NodeData, E extends EdgeData = EdgeData>(\n matrix: number[][],\n options?: GraphOptions,\n ): Graph<N, E> {\n const g = new Graph<N, E>(options);\n const n = matrix.length;\n for (let i = 0; i < n; i++) {\n g.addNode(i);\n }\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n if (matrix[i]![j]! > 0) {\n if (!g.directed && j <= i) continue;\n g.addEdge(i, j, { weight: matrix[i]![j] } as unknown as E);\n }\n }\n }\n return g;\n }\n\n static fromJSON<N extends NodeData = NodeData, E extends EdgeData = EdgeData>(\n data: SerializedGraph,\n ): Graph<N, E> {\n const g = new Graph<N, E>({ directed: data.directed });\n for (const node of data.nodes) {\n g.addNode(node.id, node.data as N);\n }\n for (const edge of data.edges) {\n g.addEdge(edge.source, edge.target, edge.data as E);\n }\n return g;\n }\n\n addNode(id: VertexId, data?: N): this {\n if (!this._nodes.has(id)) {\n this._nodes.set(id, { id, data: (data ?? {}) as N });\n this._adjacency.set(id, new Set());\n }\n return this;\n }\n\n addEdge(source: VertexId, target: VertexId, data?: E): this {\n if (!this._nodes.has(source)) this.addNode(source);\n if (!this._nodes.has(target)) this.addNode(target);\n\n this._edges.push({ source, target, data: (data ?? {}) as E });\n this._adjacency.get(source)!.add(target);\n if (!this.directed) {\n this._adjacency.get(target)!.add(source);\n }\n return this;\n }\n\n removeNode(id: VertexId): this {\n if (!this._nodes.has(id)) throw new NodeNotFoundError(id);\n\n this._nodes.delete(id);\n this._adjacency.delete(id);\n this._edges = this._edges.filter((e) => e.source !== id && e.target !== id);\n\n for (const neighbors of this._adjacency.values()) {\n neighbors.delete(id);\n }\n return this;\n }\n\n removeEdge(source: VertexId, target: VertexId): this {\n const idx = this._edges.findIndex((e) => e.source === source && e.target === target);\n if (idx === -1) throw new EdgeNotFoundError(source, target);\n\n this._edges.splice(idx, 1);\n const hasOther = this._edges.some((e) => e.source === source && e.target === target);\n if (!hasOther) {\n this._adjacency.get(source)?.delete(target);\n if (!this.directed) {\n this._adjacency.get(target)?.delete(source);\n }\n }\n return this;\n }\n\n nodeCount(): number {\n return this._nodes.size;\n }\n\n edgeCount(): number {\n return this._edges.length;\n }\n\n hasNode(id: VertexId): boolean {\n return this._nodes.has(id);\n }\n\n hasEdge(source: VertexId, target: VertexId): boolean {\n return this._edges.some((e) => e.source === source && e.target === target);\n }\n\n neighbors(id: VertexId): VertexId[] {\n const adj = this._adjacency.get(id);\n if (!adj) throw new NodeNotFoundError(id);\n return [...adj];\n }\n\n degree(id: VertexId): number {\n const adj = this._adjacency.get(id);\n if (!adj) throw new NodeNotFoundError(id);\n return adj.size;\n }\n\n nodes(): VertexId[] {\n return [...this._nodes.keys()];\n }\n\n edges(): Array<{ source: VertexId; target: VertexId; data: E }> {\n return this._edges.map((e) => ({ source: e.source, target: e.target, data: e.data }));\n }\n\n nodeData(id: VertexId): N {\n const node = this._nodes.get(id);\n if (!node) throw new NodeNotFoundError(id);\n return node.data;\n }\n\n subgraph(nodeIds: VertexId[]): Graph<N, E> {\n const nodeSet = new Set(nodeIds);\n const g = new Graph<N, E>({ directed: this.directed });\n for (const id of nodeIds) {\n if (this._nodes.has(id)) {\n g.addNode(id, this._nodes.get(id)!.data);\n }\n }\n for (const edge of this._edges) {\n if (nodeSet.has(edge.source) && nodeSet.has(edge.target)) {\n g.addEdge(edge.source, edge.target, edge.data);\n }\n }\n return g;\n }\n\n toJSON(): SerializedGraph {\n return {\n directed: this.directed,\n nodes: [...this._nodes.values()].map((n) => ({\n id: n.id,\n data: n.data as Record<string, unknown>,\n })),\n edges: this._edges.map((e) => ({\n source: e.source,\n target: e.target,\n data: e.data as Record<string, unknown>,\n })),\n };\n }\n\n toG6Format(layout?: LayoutResult): G6GraphData {\n const nodes = [...this._nodes.values()].map((n, i) => ({\n id: String(n.id),\n ...(layout ? { x: layout.positions[i]![0], y: layout.positions[i]![1] } : {}),\n ...(n.data as Record<string, unknown>),\n }));\n const edgesOut = this._edges.map((e) => ({\n source: String(e.source),\n target: String(e.target),\n ...(e.data as Record<string, unknown>),\n }));\n return { nodes, edges: edgesOut };\n }\n\n toReactFlowFormat(layout?: LayoutResult): ReactFlowData {\n const nodes = [...this._nodes.values()].map((n, i) => ({\n id: String(n.id),\n position: layout\n ? { x: layout.positions[i]![0]!, y: layout.positions[i]![1]! }\n : { x: 0, y: 0 },\n data: n.data as Record<string, unknown>,\n }));\n const edgesOut = this._edges.map((e, i) => ({\n id: `e-${i}`,\n source: String(e.source),\n target: String(e.target),\n }));\n return { nodes, edges: edgesOut };\n }\n\n toCytoscapeFormat(layout?: LayoutResult): CytoscapeData {\n const nodes = [...this._nodes.values()].map((n, i) => ({\n data: {\n id: String(n.id),\n ...(layout ? { x: layout.positions[i]![0], y: layout.positions[i]![1] } : {}),\n ...(n.data as Record<string, unknown>),\n },\n }));\n const edgesOut = this._edges.map((e) => ({\n data: {\n source: String(e.source),\n target: String(e.target),\n ...(e.data as Record<string, unknown>),\n },\n }));\n return { elements: { nodes, edges: edgesOut } };\n }\n\n _getEdgePairs(): [number, number][] {\n return this._edges.map((e) => [e.source, e.target]);\n }\n\n _getWeights(): number[] | null {\n const hasWeights = this._edges.some((e) => e.data.weight !== undefined);\n if (!hasWeights) return null;\n return this._edges.map((e) => (e.data.weight as number) ?? 1.0);\n }\n}\n","import type { WasmExports } from './types.js';\n\nlet wasmInstance: WasmExports | null = null;\nlet initPromise: Promise<WasmExports> | null = null;\n\nfunction detectEnvironment(): 'browser' | 'node' {\n if (typeof globalThis.process !== 'undefined' && globalThis.process.versions?.node) {\n return 'node';\n }\n return 'browser';\n}\n\nasync function initWasm(): Promise<WasmExports> {\n const env = detectEnvironment();\n\n if (env === 'node') {\n const { readFile } = await import('node:fs/promises');\n const { fileURLToPath } = await import('node:url');\n const { dirname, join } = await import('node:path');\n\n const currentDir = dirname(fileURLToPath(import.meta.url));\n const wasmPath = join(currentDir, '..', 'wasm', 'igraph_wasm_bg.wasm');\n const jsGluePath = join(currentDir, '..', 'wasm', 'igraph_wasm.js');\n\n const initFn = (await import(jsGluePath)).default;\n const wasmBytes = await readFile(wasmPath);\n wasmInstance = await initFn(wasmBytes);\n } else {\n const wasmUrl = new URL('../wasm/igraph_wasm_bg.wasm', import.meta.url);\n const jsGlueUrl = new URL('../wasm/igraph_wasm.js', import.meta.url);\n\n const initFn = (await import(/* @vite-ignore */ jsGlueUrl.href)).default;\n wasmInstance = await initFn(wasmUrl);\n }\n\n return wasmInstance!;\n}\n\nexport async function getWasm(): Promise<WasmExports> {\n if (wasmInstance) return wasmInstance;\n if (!initPromise) {\n initPromise = initWasm();\n }\n return initPromise;\n}\n\nexport function getWasmSync(): WasmExports | null {\n return wasmInstance;\n}\n\nexport function isWasmInitialized(): boolean {\n return wasmInstance !== null;\n}\n"]}
|
package/dist/worker.d.ts
ADDED
package/dist/worker.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/worker.ts
|
|
2
|
+
function createGraphWorker() {
|
|
3
|
+
throw new Error(
|
|
4
|
+
"Web Worker support is not yet implemented. Use the main thread API for now. Worker support coming in v0.2.0."
|
|
5
|
+
);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { createGraphWorker };
|
|
9
|
+
//# sourceMappingURL=worker.js.map
|
|
10
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/worker.ts"],"names":[],"mappings":";AAKO,SAAS,iBAAA,GAAiC;AAC/C,EAAA,MAAM,IAAI,KAAA;AAAA,IACR;AAAA,GAEF;AACF","file":"worker.js","sourcesContent":["export interface GraphWorker {\n run<T>(fn: (graphrs: unknown) => T | Promise<T>): Promise<T>;\n terminate(): void;\n}\n\nexport function createGraphWorker(): GraphWorker {\n throw new Error(\n 'Web Worker support is not yet implemented. ' +\n 'Use the main thread API for now. Worker support coming in v0.2.0.',\n );\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphrs/core",
|
|
3
|
+
"version": "0.0.0-canary.de24fef",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "Core graph data structure and WASM runtime for @graphrs — high-performance graph algorithms via WebAssembly",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"graph",
|
|
9
|
+
"wasm",
|
|
10
|
+
"webassembly",
|
|
11
|
+
"graph-algorithms",
|
|
12
|
+
"network-analysis"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/Totoro-jam/graphrs",
|
|
17
|
+
"directory": "packages/core"
|
|
18
|
+
},
|
|
19
|
+
"author": "Totoro-jam <moqiuchen66@gmail.com>",
|
|
20
|
+
"homepage": "https://github.com/Totoro-jam/graphrs#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/Totoro-jam/graphrs/issues"
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./worker": {
|
|
31
|
+
"types": "./dist/worker.d.ts",
|
|
32
|
+
"import": "./dist/worker.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"wasm/*.wasm",
|
|
40
|
+
"wasm/*.js",
|
|
41
|
+
"wasm/*.d.ts"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=20.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup",
|
|
48
|
+
"test": "vitest run --passWithNoTests",
|
|
49
|
+
"test:ci": "vitest run --reporter=default --passWithNoTests",
|
|
50
|
+
"lint": "tsc --noEmit",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"clean": "rm -rf dist"
|
|
53
|
+
}
|
|
54
|
+
}
|