nicefox-graphdb 0.1.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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +417 -0
  3. package/package.json +78 -0
  4. package/packages/nicefox-graphdb/LICENSE +21 -0
  5. package/packages/nicefox-graphdb/README.md +417 -0
  6. package/packages/nicefox-graphdb/dist/auth.d.ts +66 -0
  7. package/packages/nicefox-graphdb/dist/auth.d.ts.map +1 -0
  8. package/packages/nicefox-graphdb/dist/auth.js +148 -0
  9. package/packages/nicefox-graphdb/dist/auth.js.map +1 -0
  10. package/packages/nicefox-graphdb/dist/backup.d.ts +51 -0
  11. package/packages/nicefox-graphdb/dist/backup.d.ts.map +1 -0
  12. package/packages/nicefox-graphdb/dist/backup.js +201 -0
  13. package/packages/nicefox-graphdb/dist/backup.js.map +1 -0
  14. package/packages/nicefox-graphdb/dist/cli-helpers.d.ts +17 -0
  15. package/packages/nicefox-graphdb/dist/cli-helpers.d.ts.map +1 -0
  16. package/packages/nicefox-graphdb/dist/cli-helpers.js +121 -0
  17. package/packages/nicefox-graphdb/dist/cli-helpers.js.map +1 -0
  18. package/packages/nicefox-graphdb/dist/cli.d.ts +3 -0
  19. package/packages/nicefox-graphdb/dist/cli.d.ts.map +1 -0
  20. package/packages/nicefox-graphdb/dist/cli.js +660 -0
  21. package/packages/nicefox-graphdb/dist/cli.js.map +1 -0
  22. package/packages/nicefox-graphdb/dist/db.d.ts +118 -0
  23. package/packages/nicefox-graphdb/dist/db.d.ts.map +1 -0
  24. package/packages/nicefox-graphdb/dist/db.js +245 -0
  25. package/packages/nicefox-graphdb/dist/db.js.map +1 -0
  26. package/packages/nicefox-graphdb/dist/executor.d.ts +272 -0
  27. package/packages/nicefox-graphdb/dist/executor.d.ts.map +1 -0
  28. package/packages/nicefox-graphdb/dist/executor.js +3579 -0
  29. package/packages/nicefox-graphdb/dist/executor.js.map +1 -0
  30. package/packages/nicefox-graphdb/dist/index.d.ts +54 -0
  31. package/packages/nicefox-graphdb/dist/index.d.ts.map +1 -0
  32. package/packages/nicefox-graphdb/dist/index.js +74 -0
  33. package/packages/nicefox-graphdb/dist/index.js.map +1 -0
  34. package/packages/nicefox-graphdb/dist/local.d.ts +7 -0
  35. package/packages/nicefox-graphdb/dist/local.d.ts.map +1 -0
  36. package/packages/nicefox-graphdb/dist/local.js +115 -0
  37. package/packages/nicefox-graphdb/dist/local.js.map +1 -0
  38. package/packages/nicefox-graphdb/dist/parser.d.ts +300 -0
  39. package/packages/nicefox-graphdb/dist/parser.d.ts.map +1 -0
  40. package/packages/nicefox-graphdb/dist/parser.js +1891 -0
  41. package/packages/nicefox-graphdb/dist/parser.js.map +1 -0
  42. package/packages/nicefox-graphdb/dist/remote.d.ts +6 -0
  43. package/packages/nicefox-graphdb/dist/remote.d.ts.map +1 -0
  44. package/packages/nicefox-graphdb/dist/remote.js +87 -0
  45. package/packages/nicefox-graphdb/dist/remote.js.map +1 -0
  46. package/packages/nicefox-graphdb/dist/routes.d.ts +31 -0
  47. package/packages/nicefox-graphdb/dist/routes.d.ts.map +1 -0
  48. package/packages/nicefox-graphdb/dist/routes.js +202 -0
  49. package/packages/nicefox-graphdb/dist/routes.js.map +1 -0
  50. package/packages/nicefox-graphdb/dist/translator.d.ts +136 -0
  51. package/packages/nicefox-graphdb/dist/translator.d.ts.map +1 -0
  52. package/packages/nicefox-graphdb/dist/translator.js +4849 -0
  53. package/packages/nicefox-graphdb/dist/translator.js.map +1 -0
  54. package/packages/nicefox-graphdb/dist/types.d.ts +133 -0
  55. package/packages/nicefox-graphdb/dist/types.d.ts.map +1 -0
  56. package/packages/nicefox-graphdb/dist/types.js +21 -0
  57. package/packages/nicefox-graphdb/dist/types.js.map +1 -0
@@ -0,0 +1,272 @@
1
+ import { GraphDatabase } from "./db.js";
2
+ export interface ExecutionResult {
3
+ success: true;
4
+ data: Record<string, unknown>[];
5
+ meta: {
6
+ count: number;
7
+ time_ms: number;
8
+ };
9
+ }
10
+ export interface ExecutionError {
11
+ success: false;
12
+ error: {
13
+ message: string;
14
+ position?: number;
15
+ line?: number;
16
+ column?: number;
17
+ };
18
+ }
19
+ export type QueryResponse = ExecutionResult | ExecutionError;
20
+ export declare class Executor {
21
+ private db;
22
+ constructor(db: GraphDatabase);
23
+ /**
24
+ * Execute a Cypher query and return formatted results
25
+ */
26
+ execute(cypher: string, params?: Record<string, unknown>): QueryResponse;
27
+ /**
28
+ * Handle UNWIND with CREATE pattern
29
+ * UNWIND expands an array and executes CREATE for each element
30
+ */
31
+ private tryUnwindCreateExecution;
32
+ /**
33
+ * Evaluate a WITH clause WHERE condition against created nodes
34
+ */
35
+ private evaluateWithWhereCondition;
36
+ /**
37
+ * Evaluate a WITH clause WHERE condition using captured property values
38
+ * This is used for patterns like: WITH n.num AS num ... DELETE n ... WITH num WHERE num % 2 = 0
39
+ */
40
+ private evaluateWithWhereConditionWithPropertyAliases;
41
+ /**
42
+ * Evaluate an expression using captured property values (for property alias references)
43
+ */
44
+ private evaluateExpressionWithPropertyAliases;
45
+ /**
46
+ * Evaluate an expression for filtering in UNWIND+CREATE+WITH context
47
+ */
48
+ private evaluateExpressionForFilter;
49
+ /**
50
+ * Handle UNWIND + MERGE pattern
51
+ * This requires special handling to resolve UNWIND variables in MERGE patterns
52
+ */
53
+ private tryUnwindMergeExecution;
54
+ /**
55
+ * Handle MATCH+WITH(COLLECT)+UNWIND+RETURN pattern
56
+ * This requires a subquery for the aggregate function because SQLite doesn't
57
+ * allow aggregate functions directly inside json_each()
58
+ */
59
+ private tryCollectUnwindExecution;
60
+ /**
61
+ * Handle MATCH+WITH(COLLECT)+DELETE[expr] pattern
62
+ * This handles queries like:
63
+ * MATCH (:User)-[:FRIEND]->(n)
64
+ * WITH collect(n) AS friends
65
+ * DETACH DELETE friends[$friendIndex]
66
+ */
67
+ private tryCollectDeleteExecution;
68
+ /**
69
+ * Evaluate a DELETE expression (like friends[$index]) with collected context
70
+ */
71
+ private evaluateDeleteExpression;
72
+ /**
73
+ * Evaluate UNWIND expressions to get the arrays to iterate over
74
+ */
75
+ private evaluateUnwindExpressions;
76
+ /**
77
+ * Evaluate an expression that should return a list
78
+ */
79
+ private evaluateListExpression;
80
+ /**
81
+ * Evaluate a simple expression (literals, parameters, basic arithmetic)
82
+ */
83
+ private evaluateSimpleExpression;
84
+ /**
85
+ * Generate cartesian product of arrays
86
+ */
87
+ private generateCartesianProduct;
88
+ /**
89
+ * Resolve properties, including unwind variable references and binary expressions
90
+ */
91
+ private resolvePropertiesWithUnwind;
92
+ /**
93
+ * Resolve a single property value, handling binary expressions recursively
94
+ */
95
+ private resolvePropertyValueWithUnwind;
96
+ /**
97
+ * Evaluate a function call within a property value context
98
+ */
99
+ private evaluateFunctionInProperty;
100
+ /**
101
+ * Execute CREATE relationship pattern with unwind context
102
+ */
103
+ private executeCreateRelationshipPatternWithUnwind;
104
+ /**
105
+ * Handle CREATE...RETURN pattern by creating nodes/edges and then querying them back
106
+ */
107
+ private tryCreateReturnExecution;
108
+ /**
109
+ * Handle MERGE clauses that need special execution (relationship patterns or ON CREATE/MATCH SET)
110
+ * Returns null if this is not a MERGE pattern that needs special handling
111
+ */
112
+ private tryMergeExecution;
113
+ /**
114
+ * Execute a MERGE clause with ON CREATE SET and/or ON MATCH SET
115
+ */
116
+ private executeMergeWithSetClauses;
117
+ /**
118
+ * Execute a simple node MERGE
119
+ */
120
+ private executeMergeNode;
121
+ /**
122
+ * Execute a relationship MERGE: MERGE (a)-[:TYPE]->(b)
123
+ * Handles multiple scenarios:
124
+ * 1. MATCH (a), (b) MERGE (a)-[:REL]->(b) - both nodes already matched
125
+ * 2. MATCH (a) MERGE (a)-[:REL]->(b:Label {props}) - source matched, target to find/create
126
+ * 3. MERGE (a:Label)-[:REL]->(b:Label) - entire pattern to find/create
127
+ */
128
+ private executeMergeRelationship;
129
+ /**
130
+ * Find an existing node matching the pattern, or create a new one
131
+ */
132
+ private findOrCreateNode;
133
+ /**
134
+ * Process a RETURN clause using matched nodes and edges
135
+ */
136
+ private processReturnClauseWithEdges;
137
+ /**
138
+ * Process a RETURN clause using matched nodes
139
+ */
140
+ private processReturnClause;
141
+ /**
142
+ * Evaluate an expression for RETURN clause
143
+ */
144
+ private evaluateReturnExpression;
145
+ /**
146
+ * Execute a CREATE relationship pattern, tracking created IDs
147
+ */
148
+ private executeCreateRelationshipPattern;
149
+ /**
150
+ * Get a name for an expression (for default aliases)
151
+ */
152
+ private getExpressionName;
153
+ /**
154
+ * Detect and handle patterns that need multi-phase execution:
155
+ * - MATCH...CREATE that references matched variables
156
+ * - MATCH...SET that updates matched nodes/edges via relationships
157
+ * - MATCH...DELETE that deletes matched nodes/edges via relationships
158
+ * Returns null if this is not a multi-phase pattern, otherwise returns the result data.
159
+ */
160
+ private tryMultiPhaseExecution;
161
+ /**
162
+ * Collect variable names from a pattern
163
+ */
164
+ private collectVariablesFromPattern;
165
+ /**
166
+ * Find variables in CREATE that reference MATCH variables
167
+ */
168
+ private findReferencedVariables;
169
+ /**
170
+ * Find variables in CREATE that reference MATCH variables (with alias support)
171
+ */
172
+ private findReferencedVariablesWithAliases;
173
+ /**
174
+ * Validate that all variable references in CREATE clause properties are defined.
175
+ * Throws an error if an undefined variable is referenced.
176
+ */
177
+ private validateCreatePropertyVariables;
178
+ /**
179
+ * Check a properties object for undefined variable references.
180
+ * Throws an error if found.
181
+ */
182
+ private validatePropertiesForUndefinedVariables;
183
+ /**
184
+ * Recursively check a value for undefined variable references.
185
+ */
186
+ private validateValueForUndefinedVariables;
187
+ /**
188
+ * Execute a complex pattern with MATCH...CREATE/SET/DELETE in multiple phases
189
+ */
190
+ private executeMultiPhaseGeneral;
191
+ /**
192
+ * Collect variable names referenced in a RETURN clause
193
+ */
194
+ private collectReturnVariables;
195
+ /**
196
+ * Collect variable names from an expression
197
+ */
198
+ private collectExpressionVariables;
199
+ /**
200
+ * Build RETURN results from resolved node/edge IDs
201
+ */
202
+ private buildReturnResults;
203
+ /**
204
+ * Execute a MATCH...CREATE pattern in multiple phases (legacy, for backwards compatibility)
205
+ */
206
+ private executeMultiPhase;
207
+ /**
208
+ * Execute SET clause with pre-resolved node IDs
209
+ */
210
+ private executeSetWithResolvedIds;
211
+ /**
212
+ * Evaluate an object expression to get its key-value pairs
213
+ */
214
+ private evaluateObjectExpression;
215
+ /**
216
+ * Execute DELETE clause with pre-resolved node/edge IDs
217
+ */
218
+ private executeDeleteWithResolvedIds;
219
+ /**
220
+ * Evaluate an expression to get its value
221
+ * Note: For property and binary expressions that reference nodes, use evaluateExpressionWithContext
222
+ */
223
+ private evaluateExpression;
224
+ /**
225
+ * Evaluate an expression with access to node/edge context for property lookups
226
+ */
227
+ private evaluateExpressionWithContext;
228
+ /**
229
+ * Execute a CREATE clause with pre-resolved node IDs for referenced variables
230
+ * The resolvedIds map is mutated to include newly created node IDs
231
+ */
232
+ private executeCreateWithResolvedIds;
233
+ /**
234
+ * Create a relationship where some endpoints reference pre-existing nodes.
235
+ * The resolvedIds map is mutated to include newly created node IDs.
236
+ */
237
+ private createRelationshipWithResolvedIds;
238
+ /**
239
+ * Resolve parameter references and binary expressions in properties
240
+ */
241
+ private resolveProperties;
242
+ /**
243
+ * Type guard for relationship patterns
244
+ */
245
+ private isRelationshipPattern;
246
+ /**
247
+ * Format raw database results into a more usable structure
248
+ */
249
+ private formatResults;
250
+ /**
251
+ * Recursively parse JSON strings in a value
252
+ * Also normalizes labels (single-element arrays become strings)
253
+ */
254
+ private deepParseJson;
255
+ /**
256
+ * Normalize label to JSON string for storage
257
+ * Handles both single labels and multiple labels
258
+ */
259
+ private normalizeLabelToJson;
260
+ /**
261
+ * Normalize label for output (from database JSON to user-friendly format)
262
+ * Single label: return string, multiple labels: return array
263
+ */
264
+ private normalizeLabelForOutput;
265
+ /**
266
+ * Generate SQL condition for label matching
267
+ * Supports both single and multiple labels
268
+ */
269
+ private generateLabelCondition;
270
+ }
271
+ export declare function executeQuery(db: GraphDatabase, cypher: string, params?: Record<string, unknown>): QueryResponse;
272
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAMxC,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAChC,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG,cAAc,CAAC;AAM7D,qBAAa,QAAQ;IACnB,OAAO,CAAC,EAAE,CAAgB;gBAEd,EAAE,EAAE,aAAa;IAI7B;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,aAAa;IA+J5E;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAkZhC;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAiClC;;;OAGG;IACH,OAAO,CAAC,6CAA6C;IAqCrD;;OAEG;IACH,OAAO,CAAC,qCAAqC;IA+D7C;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAsDnC;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IA4G/B;;;;OAIG;IACH,OAAO,CAAC,yBAAyB;IA0HjC;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IA+HjC;;OAEG;IACH,OAAO,C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