gcyphrq 0.12.6
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/README.md +179 -0
- package/dist/engine/cypher-engine.d.ts +39 -0
- package/dist/engine/cypher-engine.d.ts.map +1 -0
- package/dist/engine/cypher-parser.d.ts +3 -0
- package/dist/engine/cypher-parser.d.ts.map +1 -0
- package/dist/graph.d.ts +24 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/index.js +5816 -0
- package/dist/indexes.d.ts +38 -0
- package/dist/indexes.d.ts.map +1 -0
- package/dist/lib.d.ts +189 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +1455 -0
- package/dist/types/cypher.d.ts +139 -0
- package/dist/types/cypher.d.ts.map +1 -0
- package/docs/404.md +11 -0
- package/docs/_config.yml +42 -0
- package/docs/_includes/footer.html +6 -0
- package/docs/_includes/head.html +13 -0
- package/docs/_includes/nav.html +23 -0
- package/docs/_layouts/default.html +20 -0
- package/docs/assets/cypher-highlight.js +171 -0
- package/docs/assets/favicon.svg +4 -0
- package/docs/assets/main.css +416 -0
- package/docs/cli.md +115 -0
- package/docs/examples.md +223 -0
- package/docs/getting-started.md +158 -0
- package/docs/index.md +89 -0
- package/docs/library-api.md +618 -0
- package/docs/query-guide.md +302 -0
- package/docs/skill.md +219 -0
- package/examples/README.md +187 -0
- package/examples/cloud-infra.json +199 -0
- package/examples/social-graph.json +11 -0
- package/package.json +71 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { GraphFile } from './lib';
|
|
2
|
+
import type { GraphIndexes } from './types/cypher';
|
|
3
|
+
import type { GraphInstance } from './graph';
|
|
4
|
+
/**
|
|
5
|
+
* Build pre-computed indexes directly from a Graphology graph instance.
|
|
6
|
+
*
|
|
7
|
+
* Iterates nodes and edges on the graph to build label, property, and
|
|
8
|
+
* edge-type adjacency indexes. No original `GraphFile` data is required.
|
|
9
|
+
*
|
|
10
|
+
* This is the preferred path when you already have a Graphology `Graph`
|
|
11
|
+
* (e.g. built externally or programmatically) and want to use it with
|
|
12
|
+
* `GraphEngine` for optimal query performance.
|
|
13
|
+
*
|
|
14
|
+
* Note: property values are coerced to strings via `String(value)`, so
|
|
15
|
+
* `true`/`false` become `"true"`/`"false"` and `0` becomes `"0"`.
|
|
16
|
+
*
|
|
17
|
+
* @param graph - Any Graphology graph instance (must satisfy `GraphInstance`)
|
|
18
|
+
* @returns Indexes for use with `GraphEngine`
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildGraphIndexesFromGraph(graph: GraphInstance): GraphIndexes;
|
|
21
|
+
/**
|
|
22
|
+
* Build pre-computed indexes from validated graph data and a constructed graph.
|
|
23
|
+
*
|
|
24
|
+
* Indexes enable O(1) label/property lookups and typed adjacency traversal,
|
|
25
|
+
* avoiding full-graph scans during query execution.
|
|
26
|
+
*
|
|
27
|
+
* The graph instance is required to get real Graphology edge IDs for the
|
|
28
|
+
* edge-type adjacency index.
|
|
29
|
+
*
|
|
30
|
+
* Note: property values are coerced to strings via `String(value)`, so
|
|
31
|
+
* `true`/`false` become `"true"`/`"false"` and `0` becomes `"0"`.
|
|
32
|
+
*
|
|
33
|
+
* @param data - Validated graph data (nodes + edges)
|
|
34
|
+
* @param graph - Constructed Graphology graph (provides real edge IDs)
|
|
35
|
+
* @returns Indexes for use with `GraphEngine`
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildGraphIndexesFromData(data: GraphFile, graph: GraphInstance): GraphIndexes;
|
|
38
|
+
//# sourceMappingURL=indexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.d.ts","sourceRoot":"","sources":["../src/indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA0F7C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY,CAI7E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,GAAG,YAAY,CAG7F"}
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { AdvancedCypherGraphologyEngine } from './engine/cypher-engine';
|
|
2
|
+
import { Graph, type GraphInstance } from './graph';
|
|
3
|
+
import type { AdvancedCypherAST, ResultRow, GraphIndexes } from './types/cypher';
|
|
4
|
+
export interface GraphFileNode {
|
|
5
|
+
id: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface GraphFileEdge {
|
|
10
|
+
source: string;
|
|
11
|
+
target: string;
|
|
12
|
+
type?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface GraphFile {
|
|
16
|
+
nodes: GraphFileNode[];
|
|
17
|
+
edges: GraphFileEdge[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Thrown when graph data validation fails or a query cannot be executed.
|
|
21
|
+
*/
|
|
22
|
+
export declare class GraphError extends Error {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build a `GraphInstance` from a graph data object.
|
|
27
|
+
*
|
|
28
|
+
* Validates the data and constructs a Graphology-backed graph that the
|
|
29
|
+
* Cypher engine can query.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { createGraph } from 'gcyphrq';
|
|
34
|
+
*
|
|
35
|
+
* const graph = createGraph({
|
|
36
|
+
* nodes: [
|
|
37
|
+
* { id: 'alice', label: 'User', name: 'Alice' },
|
|
38
|
+
* { id: 'bob', label: 'User', name: 'Bob' },
|
|
39
|
+
* ],
|
|
40
|
+
* edges: [
|
|
41
|
+
* { source: 'alice', target: 'bob', type: 'FRIEND' },
|
|
42
|
+
* ],
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @see https://graphology.github.io/
|
|
47
|
+
*/
|
|
48
|
+
export declare function createGraph(data: GraphFile): GraphInstance;
|
|
49
|
+
/**
|
|
50
|
+
* Build pre-computed indexes for fast query execution.
|
|
51
|
+
*
|
|
52
|
+
* **Three overloads:**
|
|
53
|
+
*
|
|
54
|
+
* 1. `buildGraphIndexes(graph)` — from an existing Graphology graph instance.
|
|
55
|
+
* Builds indexes by iterating the graph (no original data needed).
|
|
56
|
+
* 2. `buildGraphIndexes(data)` — from graph data alone.
|
|
57
|
+
* Builds the graph internally and indexes from it.
|
|
58
|
+
* 3. `buildGraphIndexes(data, graph)` — from graph data + graph instance.
|
|
59
|
+
*
|
|
60
|
+
* Pass the returned indexes to `GraphEngine` constructor for O(1) label
|
|
61
|
+
* and property lookups instead of full-graph scans.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* // From an existing Graphology graph
|
|
66
|
+
* import { buildGraphIndexes, GraphEngine } from 'gcyphrq';
|
|
67
|
+
* import Graph from 'graphology';
|
|
68
|
+
*
|
|
69
|
+
* const graph = new Graph();
|
|
70
|
+
* graph.addNode('alice', { label: 'User', name: 'Alice' });
|
|
71
|
+
* const indexes = buildGraphIndexes(graph);
|
|
72
|
+
* const engine = new GraphEngine(graph, indexes);
|
|
73
|
+
*
|
|
74
|
+
* // From graph data alone
|
|
75
|
+
* const indexes = buildGraphIndexes(graphData);
|
|
76
|
+
*
|
|
77
|
+
* // From graph data + graph instance (original API)
|
|
78
|
+
* import { buildGraphIndexes, GraphEngine, createGraph } from 'gcyphrq';
|
|
79
|
+
*
|
|
80
|
+
* const graph = createGraph(graphData);
|
|
81
|
+
* const indexes = buildGraphIndexes(graphData, graph);
|
|
82
|
+
* const engine = new GraphEngine(graph, indexes);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function buildGraphIndexes(graph: GraphInstance): GraphIndexes;
|
|
86
|
+
export declare function buildGraphIndexes(data: GraphFile): GraphIndexes;
|
|
87
|
+
export declare function buildGraphIndexes(data: GraphFile, graph: GraphInstance): GraphIndexes;
|
|
88
|
+
/**
|
|
89
|
+
* Parse a Cypher query string into an AST.
|
|
90
|
+
*
|
|
91
|
+
* The returned AST can be passed to `GraphEngine.execute()` or inspected
|
|
92
|
+
* programmatically.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { parseCypher } from 'gcyphrq';
|
|
97
|
+
*
|
|
98
|
+
* const ast = parseCypher('MATCH (u:User) RETURN u');
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function parseCypher(query: string): AdvancedCypherAST;
|
|
102
|
+
/**
|
|
103
|
+
* Execute a Cypher query against a graph and return results as plain JSON.
|
|
104
|
+
*
|
|
105
|
+
* This is the simplest way to use gcyphrq. Indexes are built automatically.
|
|
106
|
+
*
|
|
107
|
+
* **Two overloads:**
|
|
108
|
+
*
|
|
109
|
+
* 1. `executeQuery(graph, query)` — from an existing Graphology graph instance.
|
|
110
|
+
* 2. `executeQuery(graphData, query)` — from graph data (original API).
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* // From an existing Graphology graph
|
|
115
|
+
* import { executeQuery } from 'gcyphrq';
|
|
116
|
+
* import Graph from 'graphology';
|
|
117
|
+
*
|
|
118
|
+
* const graph = new Graph();
|
|
119
|
+
* graph.addNode('alice', { label: 'User', name: 'Alice' });
|
|
120
|
+
* const results = executeQuery(graph, 'MATCH (u:User) RETURN u.name');
|
|
121
|
+
*
|
|
122
|
+
* // From graph data (original API)
|
|
123
|
+
* const results = executeQuery(graphData, 'MATCH (u:User) RETURN u.name');
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @param graphOrData - Graph data or an existing Graphology graph instance
|
|
127
|
+
* @param query - A Cypher query string
|
|
128
|
+
* @returns Array of result rows
|
|
129
|
+
* @throws {GraphError} If graph data is invalid
|
|
130
|
+
* @throws {Error} If the query is invalid or cannot be executed
|
|
131
|
+
*/
|
|
132
|
+
export declare function executeQuery(graph: GraphInstance, query: string): ResultRow[];
|
|
133
|
+
export declare function executeQuery(graphData: GraphFile, query: string): ResultRow[];
|
|
134
|
+
/**
|
|
135
|
+
* The Cypher query engine. Accepts a `GraphInstance` and executes parsed ASTs.
|
|
136
|
+
*
|
|
137
|
+
* For best performance, pass pre-computed indexes as the second argument.
|
|
138
|
+
* Note: indexes are invalidated after any CREATE/SET/DELETE mutation so that
|
|
139
|
+
* subsequent MATCH/WITH stages see the updated graph state via full-graph scan.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { GraphEngine, createGraph, buildGraphIndexes } from 'gcyphrq';
|
|
144
|
+
*
|
|
145
|
+
* const graph = createGraph(graphData);
|
|
146
|
+
* const indexes = buildGraphIndexes(graphData, graph);
|
|
147
|
+
* const engine = new GraphEngine(graph, indexes);
|
|
148
|
+
* const results = engine.execute(ast);
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export { AdvancedCypherGraphologyEngine as GraphEngine };
|
|
152
|
+
/**
|
|
153
|
+
* The Graphology wrapper class. Use this when you need to build a graph
|
|
154
|
+
* programmatically (node-by-node) instead of from a data object.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* import { Graph, GraphEngine } from 'gcyphrq';
|
|
159
|
+
*
|
|
160
|
+
* const graph = new Graph();
|
|
161
|
+
* graph.addNode('alice', { label: 'User', name: 'Alice' });
|
|
162
|
+
* graph.addNode('bob', { label: 'User', name: 'Bob' });
|
|
163
|
+
* graph.addEdge('alice', 'bob', { type: 'FRIEND' });
|
|
164
|
+
*
|
|
165
|
+
* const engine = new GraphEngine(graph);
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export { Graph };
|
|
169
|
+
/**
|
|
170
|
+
* @module gcyphrq
|
|
171
|
+
*
|
|
172
|
+
* A Cypher graph query engine for in-memory graphs built on Graphology.
|
|
173
|
+
*
|
|
174
|
+
* Can be used as a CLI tool or as a library in Node.js / TypeScript projects.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* import { executeQuery } from 'gcyphrq';
|
|
179
|
+
*
|
|
180
|
+
* const results = executeQuery(graphData, 'MATCH (u:User) RETURN u');
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @see https://github.com/plelevier/gcyphrq
|
|
184
|
+
* @see https://graphology.github.io/
|
|
185
|
+
*/
|
|
186
|
+
export type { GraphInstance } from './graph';
|
|
187
|
+
export type { GraphIndexes } from './types/cypher';
|
|
188
|
+
export type { AdvancedCypherAST, Stage, MatchClause, WithClause, ReturnClause, WriteClause, CreateClause, DeleteClause, SetClause, NodePattern, RelationPattern, Direction, Expression, PropertyAccessExpression, LiteralExpression, AggregationExpression, BinaryExpression, Projection, OrderByItem, ResultRow, QueryContext, CypherNode, CypherEdge, CypherValue, CypherLiteral, } from './types/cypher';
|
|
189
|
+
//# sourceMappingURL=lib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAExE,OAAO,EAAE,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAIjF,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,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