leangraph 1.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +456 -0
  3. package/dist/auth.d.ts +66 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +148 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/backup.d.ts +51 -0
  8. package/dist/backup.d.ts.map +1 -0
  9. package/dist/backup.js +201 -0
  10. package/dist/backup.js.map +1 -0
  11. package/dist/cli-helpers.d.ts +17 -0
  12. package/dist/cli-helpers.d.ts.map +1 -0
  13. package/dist/cli-helpers.js +121 -0
  14. package/dist/cli-helpers.js.map +1 -0
  15. package/dist/cli.d.ts +3 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +660 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/db.d.ts +118 -0
  20. package/dist/db.d.ts.map +1 -0
  21. package/dist/db.js +720 -0
  22. package/dist/db.js.map +1 -0
  23. package/dist/executor.d.ts +663 -0
  24. package/dist/executor.d.ts.map +1 -0
  25. package/dist/executor.js +8578 -0
  26. package/dist/executor.js.map +1 -0
  27. package/dist/index.d.ts +62 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +86 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/local.d.ts +7 -0
  32. package/dist/local.d.ts.map +1 -0
  33. package/dist/local.js +119 -0
  34. package/dist/local.js.map +1 -0
  35. package/dist/parser.d.ts +365 -0
  36. package/dist/parser.d.ts.map +1 -0
  37. package/dist/parser.js +2711 -0
  38. package/dist/parser.js.map +1 -0
  39. package/dist/property-value.d.ts +3 -0
  40. package/dist/property-value.d.ts.map +1 -0
  41. package/dist/property-value.js +30 -0
  42. package/dist/property-value.js.map +1 -0
  43. package/dist/remote.d.ts +6 -0
  44. package/dist/remote.d.ts.map +1 -0
  45. package/dist/remote.js +93 -0
  46. package/dist/remote.js.map +1 -0
  47. package/dist/routes.d.ts +31 -0
  48. package/dist/routes.d.ts.map +1 -0
  49. package/dist/routes.js +202 -0
  50. package/dist/routes.js.map +1 -0
  51. package/dist/server.d.ts +16 -0
  52. package/dist/server.d.ts.map +1 -0
  53. package/dist/server.js +25 -0
  54. package/dist/server.js.map +1 -0
  55. package/dist/translator.d.ts +330 -0
  56. package/dist/translator.d.ts.map +1 -0
  57. package/dist/translator.js +13712 -0
  58. package/dist/translator.js.map +1 -0
  59. package/dist/types.d.ts +136 -0
  60. package/dist/types.d.ts.map +1 -0
  61. package/dist/types.js +21 -0
  62. package/dist/types.js.map +1 -0
  63. package/package.json +77 -0
@@ -0,0 +1,663 @@
1
+ import { GraphDatabase } from "./db.js";
2
+ /**
3
+ * Phase execution context - carries variable values between phases
4
+ *
5
+ * Cypher is inherently sequential. Each clause operates on variables from
6
+ * previous clauses. This context tracks:
7
+ * - nodeIds: Map variable names to node IDs (for nodes we've created/matched)
8
+ * - edgeIds: Map variable names to edge IDs (for edges we've created/matched)
9
+ * - values: Map variable names to arbitrary values (scalars, lists, aggregates)
10
+ * - rows: The current "row set" - multiple rows from MATCH or UNWIND
11
+ */
12
+ export interface PhaseContext {
13
+ nodeIds: Map<string, string>;
14
+ edgeIds: Map<string, string>;
15
+ values: Map<string, unknown>;
16
+ rows: Array<Map<string, unknown>>;
17
+ }
18
+ export interface ExecutionResult {
19
+ success: true;
20
+ data: Record<string, unknown>[];
21
+ meta: {
22
+ count: number;
23
+ time_ms: number;
24
+ };
25
+ }
26
+ export interface ExecutionError {
27
+ success: false;
28
+ error: {
29
+ message: string;
30
+ position?: number;
31
+ line?: number;
32
+ column?: number;
33
+ };
34
+ }
35
+ export type QueryResponse = ExecutionResult | ExecutionError;
36
+ export declare class Executor {
37
+ private db;
38
+ constructor(db: GraphDatabase);
39
+ /**
40
+ * Execute a Cypher query and return formatted results
41
+ */
42
+ execute(cypher: string, params?: Record<string, unknown>): QueryResponse;
43
+ /**
44
+ * Check if a query needs phase-based execution and execute it if so.
45
+ *
46
+ * Phase boundaries are detected when:
47
+ * 1. A WITH clause contains an aggregate function (collect, count, sum, etc.)
48
+ * 2. An UNWIND clause references a variable that doesn't exist yet (from previous phase)
49
+ * 3. A clause references a variable computed from aggregation
50
+ *
51
+ * Returns null if the query can be handled by standard SQL translation.
52
+ */
53
+ private tryPhasedExecution;
54
+ /**
55
+ * Validate MERGE variables - cannot MERGE a variable that's already bound by MATCH
56
+ *
57
+ * The rule is: you cannot MERGE a node pattern that is just a variable already
58
+ * bound by MATCH. MATCH guarantees the node exists, so MERGE would be meaningless.
59
+ *
60
+ * However, you CAN use already-bound variables in:
61
+ * - Relationship MERGE endpoints: MATCH (a), (b) MERGE (a)-[:REL]->(b) is valid
62
+ * - Subsequent MERGE clauses: MERGE (c) MERGE (c) is valid (second one just matches)
63
+ *
64
+ * Additionally: you cannot impose new predicates (labels/properties) on a variable
65
+ * that is already bound. E.g., CREATE (a:Foo) MERGE (a)-[:R]->(a:Bar) is invalid
66
+ * because it tries to impose label :Bar on variable 'a' which is already bound.
67
+ */
68
+ private validateMergeVariables;
69
+ /**
70
+ * Validate that SET assignment values do not reference undefined variables.
71
+ *
72
+ * Example (invalid):
73
+ * MATCH (a) SET a.name = missing RETURN a
74
+ */
75
+ private validateSetClauseValueVariables;
76
+ /**
77
+ * Validate that ORDER BY expressions do not reference undefined or out-of-scope variables.
78
+ *
79
+ * Examples (invalid):
80
+ * MATCH (a), (b) WITH a ORDER BY b RETURN a
81
+ * MATCH (a) RETURN a.name AS name ORDER BY missing
82
+ */
83
+ private validateOrderByVariables;
84
+ private validateOrderByVariablesInQuery;
85
+ private validateSetClauseValueVariablesInQuery;
86
+ private validateExpressionVariablesInScope;
87
+ private validateWhereConditionVariablesInScope;
88
+ /**
89
+ * Collect all node and relationship variables from a pattern
90
+ */
91
+ private collectPatternVariables;
92
+ /**
93
+ * Check if a MERGE pattern tries to use an already-bound variable
94
+ */
95
+ private checkMergePatternForBoundVariables;
96
+ /**
97
+ * Check if a MERGE pattern tries to impose new labels/properties on an already-bound variable.
98
+ * E.g., CREATE (a:Foo) MERGE (a)-[:R]->(a:Bar) is invalid because :Bar conflicts with :Foo
99
+ */
100
+ private checkMergePatternForLabelConflicts;
101
+ /**
102
+ * Validate that MERGE properties in the AST don't contain explicit null values.
103
+ * MERGE cannot use null property values because null = null is undefined in Cypher.
104
+ * This validates the original AST properties, not the resolved values,
105
+ * to distinguish between explicit null (invalid) and variable references that may resolve to null.
106
+ */
107
+ private validateMergeAstPropertiesNotNull;
108
+ /**
109
+ * Detect phase boundaries in a query.
110
+ *
111
+ * A phase boundary occurs when:
112
+ * - A WITH clause contains aggregate functions (collect, count, sum, avg, min, max)
113
+ * - An UNWIND clause references a variable from a previous WITH aggregate
114
+ */
115
+ private detectPhases;
116
+ /**
117
+ * Get all variable names referenced in an expression
118
+ */
119
+ private getExpressionVariables;
120
+ /**
121
+ * Get all variable names referenced in a WHERE condition
122
+ */
123
+ private getWhereVariables;
124
+ /**
125
+ * Get all variables referenced by a clause (not defined, just referenced)
126
+ */
127
+ private getClauseReferencedVariables;
128
+ /**
129
+ * Track variables defined by a clause
130
+ */
131
+ private trackClauseVariables;
132
+ /**
133
+ * Check if an expression contains aggregate functions
134
+ */
135
+ private expressionHasAggregate;
136
+ /**
137
+ * Check if a WhereCondition contains non-deterministic functions
138
+ */
139
+ private whereConditionHasNonDeterministic;
140
+ /**
141
+ * Check if an expression contains non-deterministic functions (like rand())
142
+ * These expressions cannot be safely inlined by the translator and require
143
+ * phased execution to materialize intermediate results.
144
+ */
145
+ private expressionHasNonDeterministic;
146
+ /**
147
+ * Execute a single phase with the given context
148
+ */
149
+ private executePhase;
150
+ /**
151
+ * Execute a single clause and update context
152
+ */
153
+ private executeClause;
154
+ /**
155
+ * Execute CREATE clause
156
+ */
157
+ private executeCreateClause;
158
+ /**
159
+ * Execute MERGE clause
160
+ *
161
+ * MERGE semantics:
162
+ * - For each input row, find nodes/edges matching the MERGE pattern
163
+ * - If match found, bind to existing nodes (creating Cartesian product with all matches)
164
+ * - If no match, create new nodes/edges
165
+ *
166
+ * For MERGE (b) with no label/properties after MATCH (a):
167
+ * - If ANY nodes exist, match ALL of them → Cartesian product with input rows
168
+ * - If NO nodes exist, create one node per input row
169
+ */
170
+ private executeMergeClause;
171
+ /**
172
+ * Build a path object from relationship patterns.
173
+ * Returns an array alternating [nodeProps, edgeProps, nodeProps, ...]
174
+ * or null if the path cannot be constructed.
175
+ */
176
+ private buildPathFromPatterns;
177
+ /**
178
+ * Execute MERGE for a node pattern within a row context
179
+ * Returns multiple rows if multiple nodes match (Cartesian product)
180
+ */
181
+ private executeMergeNodeInContext;
182
+ /**
183
+ * Execute MERGE for a relationship pattern within a row context
184
+ * Returns multiple rows if multiple matches found
185
+ */
186
+ private executeMergeRelationshipInContext;
187
+ /**
188
+ * Execute CREATE for a single node pattern within a row context
189
+ */
190
+ private executeCreateNodeInContext;
191
+ /**
192
+ * Extract a node ID from a value that could be:
193
+ * - A raw UUID string
194
+ * - A JSON string like '{"name":"Alice","_nf_id":"uuid"}'
195
+ * - An object with _nf_id property
196
+ */
197
+ private extractNodeId;
198
+ /**
199
+ * Execute CREATE for a relationship pattern within a row context
200
+ */
201
+ private executeCreateRelationshipInContext;
202
+ /**
203
+ * Execute WITH clause
204
+ */
205
+ private executeWithClause;
206
+ /**
207
+ * Sort rows by ORDER BY expressions
208
+ */
209
+ private sortRowsByOrderBy;
210
+ /**
211
+ * Compare two values for sorting (Cypher ordering semantics)
212
+ */
213
+ private compareValues;
214
+ /**
215
+ * Evaluate a literal expression (for SKIP/LIMIT)
216
+ */
217
+ private evaluateLiteralExpression;
218
+ /**
219
+ * Execute UNWIND clause
220
+ */
221
+ private executeUnwindClause;
222
+ /**
223
+ * Execute MATCH clause
224
+ */
225
+ private executeMatchClause;
226
+ /**
227
+ * Execute a MATCH clause for a single input row, using bound variable values as constraints
228
+ */
229
+ private executeMatchForRow;
230
+ /**
231
+ * Execute a MATCH clause for a single input row using SQL translation.
232
+ * This handles complex patterns (multi-hop, anonymous nodes) by:
233
+ * 1. Translating the MATCH to SQL
234
+ * 2. Adding WHERE constraints for bound variables (matching by node ID)
235
+ * 3. Executing and returning results
236
+ */
237
+ private executeMatchWithSqlForRow;
238
+ /**
239
+ * Transform a MATCH clause to substitute context variable references with parameter references.
240
+ * This converts WHERE conditions like `n.id = foo` (where foo is from context)
241
+ * to `n.id = $_ctx_foo` so the translator can handle it.
242
+ */
243
+ private transformClauseForContext;
244
+ /**
245
+ * Transform a WHERE condition to substitute context variable references with parameter references
246
+ */
247
+ private transformWhereForContext;
248
+ /**
249
+ * Transform an expression to substitute context variable references with parameter references
250
+ */
251
+ private transformExpressionForContext;
252
+ /**
253
+ * Check if a WHERE condition references context variables
254
+ */
255
+ private whereReferencesContextVars;
256
+ /**
257
+ * Check if an expression references a context variable (not a pattern variable)
258
+ */
259
+ private expressionReferencesContextVar;
260
+ /**
261
+ * Find a pattern with a variable-length edge where the edge variable is bound to a list
262
+ * Returns the pattern info if found, null otherwise
263
+ */
264
+ private findBoundRelationshipListPattern;
265
+ /**
266
+ * Execute MATCH with a pre-bound relationship list
267
+ * e.g., MATCH (first)-[rs*]->(second) where rs = [r1, r2, ...]
268
+ * This finds the path by following the exact sequence of relationships in rs
269
+ */
270
+ private executeMatchWithBoundRelList;
271
+ /**
272
+ * Build RETURN items for all variables in a MATCH pattern
273
+ */
274
+ private buildReturnItemsForMatch;
275
+ /**
276
+ * Execute RETURN clause
277
+ */
278
+ private executeReturnClause;
279
+ /**
280
+ * Execute SET clause
281
+ */
282
+ private executeSetClause;
283
+ /**
284
+ * Execute DELETE clause
285
+ */
286
+ private executeDeleteClause;
287
+ /**
288
+ * Evaluate an expression in the context of a single row
289
+ */
290
+ private evaluateExpressionInRow;
291
+ /**
292
+ * Evaluate a function expression in a row context
293
+ */
294
+ private evaluateFunctionInRow;
295
+ /**
296
+ * Evaluate a binary expression in a row context
297
+ */
298
+ private evaluateBinaryInRow;
299
+ /**
300
+ * Evaluate an aggregate expression across all rows
301
+ */
302
+ private evaluateAggregateExpression;
303
+ /**
304
+ * Evaluate a WHERE condition in a row context
305
+ */
306
+ private evaluateWhereInRow;
307
+ /**
308
+ * Resolve properties with row context
309
+ */
310
+ private resolvePropertiesInContext;
311
+ /**
312
+ * Resolve a property value with row context
313
+ */
314
+ private resolvePropertyValueInContext;
315
+ /**
316
+ * Convert context to result format
317
+ */
318
+ private contextToResults;
319
+ /**
320
+ * Handle UNWIND with CREATE pattern
321
+ * UNWIND expands an array and executes CREATE for each element
322
+ */
323
+ private tryUnwindCreateExecution;
324
+ /**
325
+ * Evaluate a WITH clause WHERE condition against created nodes
326
+ */
327
+ private evaluateWithWhereCondition;
328
+ /**
329
+ * Evaluate a WITH clause WHERE condition using captured property values
330
+ * This is used for patterns like: WITH n.num AS num ... DELETE n ... WITH num WHERE num % 2 = 0
331
+ */
332
+ private evaluateWithWhereConditionWithPropertyAliases;
333
+ /**
334
+ * Evaluate an expression using captured property values (for property alias references)
335
+ */
336
+ private evaluateExpressionWithPropertyAliases;
337
+ /**
338
+ * Evaluate an expression for filtering in UNWIND+CREATE+WITH context
339
+ */
340
+ private evaluateExpressionForFilter;
341
+ /**
342
+ * Handle UNWIND + MERGE pattern (optionally with WITH clauses between)
343
+ * This requires special handling to resolve UNWIND variables in MERGE patterns
344
+ */
345
+ private tryUnwindMergeExecution;
346
+ /**
347
+ * Apply a WITH clause to transform rows
348
+ */
349
+ private applyWithClauseToRows;
350
+ /**
351
+ * Evaluate a WHERE condition on a row context
352
+ */
353
+ private evaluateWhereConditionOnRow;
354
+ /**
355
+ * Evaluate an expression in the context of a row
356
+ */
357
+ private evaluateExpressionOnRow;
358
+ /**
359
+ * Check if a value is a parameter reference
360
+ */
361
+ private isParamRef;
362
+ /**
363
+ * Check if a value is a variable reference
364
+ */
365
+ private isVarRef;
366
+ /**
367
+ * Resolve MERGE pattern properties from a row context
368
+ */
369
+ private resolvePropertiesFromRow;
370
+ /**
371
+ * Convert expression to string for alias/key purposes
372
+ */
373
+ private expressionToString;
374
+ /**
375
+ * Compare two values with operator
376
+ */
377
+ private evaluateComparison;
378
+ /**
379
+ * Handle MATCH+WITH(COLLECT)+UNWIND+RETURN pattern
380
+ * This requires a subquery for the aggregate function because SQLite doesn't
381
+ * allow aggregate functions directly inside json_each()
382
+ */
383
+ private tryCollectUnwindExecution;
384
+ /**
385
+ * Handle MATCH+WITH(COLLECT)+DELETE[expr] pattern
386
+ * This handles queries like:
387
+ * MATCH (:User)-[:FRIEND]->(n)
388
+ * WITH collect(n) AS friends
389
+ * DETACH DELETE friends[$friendIndex]
390
+ */
391
+ private tryCollectDeleteExecution;
392
+ /**
393
+ * Evaluate a DELETE expression (like friends[$index]) with collected context
394
+ */
395
+ private evaluateDeleteExpression;
396
+ /**
397
+ * Evaluate UNWIND expressions to get the arrays to iterate over
398
+ */
399
+ private evaluateUnwindExpressions;
400
+ /**
401
+ * Evaluate a SKIP or LIMIT expression to a number
402
+ */
403
+ private evaluateSkipLimitExpression;
404
+ /**
405
+ * Evaluate an expression that should return a list
406
+ */
407
+ private evaluateListExpression;
408
+ /**
409
+ * Evaluate a simple expression (literals, parameters, basic arithmetic)
410
+ */
411
+ private evaluateSimpleExpression;
412
+ /**
413
+ * Generate cartesian product of arrays
414
+ */
415
+ private generateCartesianProduct;
416
+ /**
417
+ * Resolve properties, including unwind variable references and binary expressions
418
+ */
419
+ private resolvePropertiesWithUnwind;
420
+ /**
421
+ * Resolve a single property value, handling binary expressions recursively
422
+ */
423
+ private resolvePropertyValueWithUnwind;
424
+ /**
425
+ * Evaluate a function call within a property value context
426
+ */
427
+ private evaluateFunctionInProperty;
428
+ /**
429
+ * Execute CREATE relationship pattern with unwind context
430
+ */
431
+ private executeCreateRelationshipPatternWithUnwind;
432
+ /**
433
+ * Handle CREATE...RETURN pattern by creating nodes/edges and then querying them back
434
+ */
435
+ private tryCreateReturnExecution;
436
+ /**
437
+ * Handle MATCH...WITH...MATCH patterns where the second MATCH has a variable-length
438
+ * pattern with a bound relationship list from the WITH clause.
439
+ *
440
+ * Example: MATCH ()-[r1]->()-[r2]->() WITH [r1, r2] AS rs MATCH (a)-[rs*]->(b) RETURN a, b
441
+ *
442
+ * The second MATCH should follow the exact sequence of relationships in rs.
443
+ * Returns null if this pattern is not detected.
444
+ */
445
+ private tryBoundRelationshipListExecution;
446
+ /**
447
+ * Handle MERGE clauses that need special execution (relationship patterns or ON CREATE/MATCH SET)
448
+ * Returns null if this is not a MERGE pattern that needs special handling
449
+ */
450
+ private tryMergeExecution;
451
+ /**
452
+ * Execute multiple MERGE clauses in sequence, handling path expressions
453
+ */
454
+ private executeMultipleMergeClauses;
455
+ /**
456
+ * Execute a MERGE for a node pattern, tracking the result
457
+ */
458
+ private executeMergeNodeWithTracking;
459
+ /**
460
+ * Execute a MERGE for a relationship pattern, tracking the result
461
+ */
462
+ private executeMergeRelationshipWithTracking;
463
+ /**
464
+ * Build a path from patterns using tracked nodes and edges
465
+ */
466
+ private buildPathFromPatternsWithTracking;
467
+ /**
468
+ * Process RETURN clause with paths support
469
+ */
470
+ private processReturnClauseWithPaths;
471
+ /**
472
+ * Execute a MERGE clause with ON CREATE SET and/or ON MATCH SET
473
+ *
474
+ * This needs to handle the case where MATCH returns multiple rows.
475
+ * For each MATCH row, we execute the MERGE (with its ON CREATE SET / ON MATCH SET)
476
+ * and collect results for RETURN.
477
+ */
478
+ private executeMergeWithSetClauses;
479
+ /**
480
+ * Execute a simple node MERGE for a single input row
481
+ * Used when there's a MATCH before MERGE - this handles one row at a time
482
+ */
483
+ private executeMergeNodeForRow;
484
+ /**
485
+ * Execute a relationship MERGE for a single input row
486
+ */
487
+ private executeMergeRelationshipForRow;
488
+ /**
489
+ * Execute a relationship MERGE for a single input row, tracking edges for aggregation
490
+ * This version doesn't process RETURN - it just executes the MERGE and captures the edge info
491
+ */
492
+ private executeMergeRelationshipForRowWithTracking;
493
+ /**
494
+ * Process RETURN clause with aggregate functions over multiple rows of matched nodes/edges
495
+ */
496
+ private processAggregateReturn;
497
+ /**
498
+ * Resolve properties with access to matched nodes for property references
499
+ */
500
+ private resolvePropertiesWithMatchedNodes;
501
+ /**
502
+ * Resolve a single property value with matched nodes context
503
+ */
504
+ private resolvePropertyValueWithMatchedNodes;
505
+ /**
506
+ * Evaluate an expression with matched nodes context
507
+ */
508
+ private evaluateExpressionWithMatchedNodes;
509
+ /**
510
+ * Execute a simple node MERGE
511
+ */
512
+ private executeMergeNode;
513
+ /**
514
+ * Execute a relationship MERGE: MERGE (a)-[:TYPE]->(b)
515
+ * Handles multiple scenarios:
516
+ * 1. MATCH (a), (b) MERGE (a)-[:REL]->(b) - both nodes already matched
517
+ * 2. MATCH (a) MERGE (a)-[:REL]->(b:Label {props}) - source matched, target to find/create
518
+ * 3. MERGE (a:Label)-[:REL]->(b:Label) - entire pattern to find/create
519
+ */
520
+ private executeMergeRelationship;
521
+ /**
522
+ * Find an existing node matching the pattern, or create a new one
523
+ */
524
+ private findOrCreateNode;
525
+ /**
526
+ * Process a RETURN clause using matched nodes and edges
527
+ */
528
+ private processReturnClauseWithEdges;
529
+ /**
530
+ * Process a RETURN clause using matched nodes
531
+ */
532
+ private processReturnClause;
533
+ /**
534
+ * Evaluate an expression for RETURN clause
535
+ */
536
+ private evaluateReturnExpression;
537
+ /**
538
+ * Execute a CREATE relationship pattern, tracking created IDs
539
+ */
540
+ private executeCreateRelationshipPattern;
541
+ /**
542
+ * Get a name for an expression (for default aliases)
543
+ */
544
+ private getExpressionName;
545
+ /**
546
+ * Detect and handle patterns that need multi-phase execution:
547
+ * - MATCH...CREATE that references matched variables
548
+ * - MATCH...SET that updates matched nodes/edges via relationships
549
+ * - MATCH...DELETE that deletes matched nodes/edges via relationships
550
+ * Returns null if this is not a multi-phase pattern, otherwise returns the result data.
551
+ */
552
+ private tryMultiPhaseExecution;
553
+ /**
554
+ * Collect variable names from a pattern
555
+ */
556
+ private collectVariablesFromPattern;
557
+ /**
558
+ * Find variables in CREATE that reference MATCH variables (with alias support)
559
+ */
560
+ private findReferencedVariablesWithAliases;
561
+ /**
562
+ * Validate that all variable references in CREATE clause properties are defined.
563
+ * Throws an error if an undefined variable is referenced.
564
+ */
565
+ private validateCreatePropertyVariables;
566
+ /**
567
+ * Check a properties object for undefined variable references.
568
+ * Throws an error if found.
569
+ */
570
+ private validatePropertiesForUndefinedVariables;
571
+ /**
572
+ * Recursively check a value for undefined variable references.
573
+ */
574
+ private validateValueForUndefinedVariables;
575
+ /**
576
+ * Execute a complex pattern with MATCH...CREATE/SET/DELETE in multiple phases
577
+ */
578
+ private executeMultiPhaseGeneral;
579
+ /**
580
+ * Collect variable names referenced in a RETURN clause
581
+ */
582
+ private collectReturnVariables;
583
+ /**
584
+ * Collect variable names from an expression
585
+ */
586
+ private collectExpressionVariables;
587
+ /**
588
+ * Build RETURN results from resolved node/edge IDs
589
+ */
590
+ private buildReturnResults;
591
+ /**
592
+ * Execute SET clause with pre-resolved node IDs
593
+ */
594
+ private executeSetWithResolvedIds;
595
+ /**
596
+ * Evaluate an object expression to get its key-value pairs
597
+ */
598
+ private evaluateObjectExpression;
599
+ /**
600
+ * Execute DELETE clause with pre-resolved node/edge IDs
601
+ * Returns the set of variables that were deleted
602
+ */
603
+ private executeDeleteWithResolvedIds;
604
+ /**
605
+ * Evaluate an expression to get its value
606
+ * Note: For property and binary expressions that reference nodes, use evaluateExpressionWithContext
607
+ */
608
+ private evaluateExpression;
609
+ /**
610
+ * Evaluate an expression with access to node/edge context for property lookups
611
+ */
612
+ private evaluateExpressionWithContext;
613
+ /**
614
+ * Execute a CREATE clause with pre-resolved node IDs for referenced variables
615
+ * The resolvedIds map is mutated to include newly created node IDs
616
+ */
617
+ private executeCreateWithResolvedIds;
618
+ /**
619
+ * Create a relationship where some endpoints reference pre-existing nodes.
620
+ * The resolvedIds map is mutated to include newly created node IDs.
621
+ */
622
+ private createRelationshipWithResolvedIds;
623
+ /**
624
+ * Resolve parameter references and binary expressions in properties
625
+ */
626
+ private resolveProperties;
627
+ /**
628
+ * Type guard for relationship patterns
629
+ */
630
+ private isRelationshipPattern;
631
+ /**
632
+ * Format raw database results into a more usable structure
633
+ */
634
+ private formatResults;
635
+ /**
636
+ * Recursively parse JSON strings in a value
637
+ * Also normalizes labels (single-element arrays become strings)
638
+ */
639
+ private deepParseJson;
640
+ /**
641
+ * Normalize label to JSON string for storage
642
+ * Handles both single labels and multiple labels
643
+ */
644
+ private normalizeLabelToJson;
645
+ /**
646
+ * Normalize label for output (from database JSON to user-friendly format)
647
+ * Single label: return string, multiple labels: return array
648
+ */
649
+ private normalizeLabelForOutput;
650
+ /**
651
+ * Generate SQL condition for label matching
652
+ * Supports both single and multiple labels
653
+ */
654
+ private generateLabelCondition;
655
+ /**
656
+ * Extract id() function conditions from a WHERE clause
657
+ * For conditions like: WHERE id(n) = $id
658
+ * Populates the idConditions map with variable -> id value mappings
659
+ */
660
+ private extractIdConditions;
661
+ }
662
+ export declare function executeQuery(db: GraphDatabase, cypher: string, params?: Record<string, unknown>): QueryResponse;
663
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAyDxC;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAE3B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE7B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAG7B,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnC;AA0BD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CA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