grafio-mongo 1.2.0 → 2.0.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/README.md +71 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -17,10 +17,7 @@ This package provides the MongoDB storage provider for grafio, extracted from th
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
npm install grafio-mongo
|
|
21
|
-
|
|
22
|
-
# peer dependencies
|
|
23
|
-
npm install grafio
|
|
20
|
+
npm install grafio-mongo
|
|
24
21
|
```
|
|
25
22
|
|
|
26
23
|
## Quick Start
|
|
@@ -155,6 +152,76 @@ try {
|
|
|
155
152
|
- `isFailed()` — returns true if a storage operation failed within the transaction
|
|
156
153
|
- `isActive()` — returns true if transaction is active and not failed
|
|
157
154
|
|
|
155
|
+
## Cypher Query Language
|
|
156
|
+
|
|
157
|
+
MongoDB-backed graphs support read-only openCypher-compatible queries via the `CypherEngine`:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { Graph } from 'grafio';
|
|
161
|
+
import { CypherEngine } from 'grafio/cypher';
|
|
162
|
+
|
|
163
|
+
const graph = factory.forGraph('my-graph');
|
|
164
|
+
|
|
165
|
+
// Build your graph
|
|
166
|
+
const alice = await graph.addNode('Person', { name: 'Alice', age: 30 });
|
|
167
|
+
const bob = await graph.addNode('Person', { name: 'Bob', age: 25 });
|
|
168
|
+
await graph.addEdge(alice.id, bob.id, 'KNOWS', { since: 2020 });
|
|
169
|
+
|
|
170
|
+
const engine = new CypherEngine(graph);
|
|
171
|
+
|
|
172
|
+
// Scan nodes by type
|
|
173
|
+
const result = await engine.query('MATCH (p:Person) RETURN p.name, p.age');
|
|
174
|
+
|
|
175
|
+
// Filter with WHERE
|
|
176
|
+
const adults = await engine.query(
|
|
177
|
+
'MATCH (p:Person) WHERE p.age > 25 RETURN p.name'
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// Follow relationships
|
|
181
|
+
const friends = await engine.query(
|
|
182
|
+
'MATCH (a:Person)-[:KNOWS]->(b:Person) RETURN a.name, b.name'
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// Multi-hop traversal
|
|
186
|
+
const network = await engine.query(
|
|
187
|
+
'MATCH (a:Person)-[:KNOWS*1..2]->(b:Person) RETURN DISTINCT a.name, b.name'
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
// Parameterized queries
|
|
191
|
+
const byName = await engine.query(
|
|
192
|
+
'MATCH (p:Person {name: $name}) RETURN p',
|
|
193
|
+
{ name: 'Alice' }
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
// Pagination
|
|
197
|
+
const page = await engine.query(
|
|
198
|
+
'MATCH (p:Person) RETURN p ORDER BY p.age DESC SKIP 0 LIMIT 10'
|
|
199
|
+
);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Supported Clauses
|
|
203
|
+
|
|
204
|
+
| Clause | Support | Notes |
|
|
205
|
+
|--------|---------|-------|
|
|
206
|
+
| `MATCH` | ✅ Read-only patterns | Typed/untyped nodes, directed edges, multi-label `(n:A\|B)`, inline property maps |
|
|
207
|
+
| `WHERE` | ✅ Full expressions | `AND`/`OR`/`NOT`, comparisons, `IN`, `NOT IN`, `IS NULL`, `IS NOT NULL` |
|
|
208
|
+
| `RETURN` | ✅ With `DISTINCT` | Property access, aliases with `AS` |
|
|
209
|
+
| `ORDER BY` | ✅ ASC/DESC | Default ASC when omitted |
|
|
210
|
+
| `SKIP` | ✅ Literal + `$param` | Evaluated at runtime |
|
|
211
|
+
| `LIMIT` | ✅ Literal + `$param` | Evaluated at runtime |
|
|
212
|
+
| `CREATE` / `DELETE` / `SET` / `REMOVE` / `MERGE` | ❌ Rejected | Validation gate prevents execution |
|
|
213
|
+
|
|
214
|
+
### Variable-length Edge Syntax
|
|
215
|
+
|
|
216
|
+
| Syntax | Meaning |
|
|
217
|
+
|--------|---------|
|
|
218
|
+
| `[*]` | Unbounded (up to 100 hops) |
|
|
219
|
+
| `[*1..3]` | 1 to 3 hops (BFS by default) |
|
|
220
|
+
| `[*2]` | Exactly 2 hops |
|
|
221
|
+
| `[*..5]` | Up to 5 hops |
|
|
222
|
+
|
|
223
|
+
> **Strategy selection**: BFS is used by default for multi-hop expansion. When `LIMIT` is present, DFS is selected automatically for better early-result performance.
|
|
224
|
+
|
|
158
225
|
## Graph Operations
|
|
159
226
|
|
|
160
227
|
All graph operations from grafio are available when using MongoDB storage. See the [grafio documentation](https://github.com/satyajugran/grafio) for the complete API reference.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grafio-mongo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "MongoDB storage backend for grafio",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
"perf:gc": "cross-env TS_NODE_PROJECT=tsconfig.perf.json node --expose-gc -r ts-node/register tests/perf/entryPoint.ts"
|
|
15
15
|
|
|
16
16
|
},
|
|
17
|
-
"peerDependencies": {
|
|
18
|
-
|
|
17
|
+
"peerDependencies": {},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"grafio": ">=6.0.0",
|
|
19
20
|
"mongodb": ">=5.0.0"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@types/jest": "^29.5.0",
|
|
23
24
|
"@types/node": "^25.6.0",
|
|
24
|
-
"grafio": "^6.2.0",
|
|
25
25
|
"cross-env": "^10.1.0",
|
|
26
26
|
"jest": "^29.5.0",
|
|
27
27
|
"rimraf": "^5.0.0",
|