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,62 @@
1
+ import type { GraphDBOptions, GraphDBClient } from "./types.js";
2
+ export type { GraphDBOptions, GraphDBClient, QueryResponse, HealthResponse, NodeResult, } from "./types.js";
3
+ export { GraphDBError } from "./types.js";
4
+ export { parse } from "./parser.js";
5
+ export type { Query, Clause, CreateClause, MatchClause, MergeClause, SetClause, DeleteClause, ReturnClause, NodePattern, RelationshipPattern, EdgePattern, WhereCondition, Expression, PropertyValue, ParameterRef, ParseResult, ParseError, } from "./parser.js";
6
+ export { translate, Translator } from "./translator.js";
7
+ export type { SqlStatement, TranslationResult } from "./translator.js";
8
+ export { GraphDatabase, DatabaseManager } from "./db.js";
9
+ export type { Node, Edge, NodeRow, EdgeRow, QueryResult } from "./db.js";
10
+ export { Executor, executeQuery } from "./executor.js";
11
+ export type { ExecutionResult, ExecutionError, QueryResponse as ServerQueryResponse, } from "./executor.js";
12
+ export { createApp, createServer } from "./routes.js";
13
+ export type { QueryRequest, ServerOptions } from "./routes.js";
14
+ export { BackupManager } from "./backup.js";
15
+ export type { BackupResult, BackupStatus, BackupAllOptions } from "./backup.js";
16
+ export { ApiKeyStore, authMiddleware, generateApiKey } from "./auth.js";
17
+ export type { ApiKeyConfig, ValidationResult, KeyInfo } from "./auth.js";
18
+ export declare const VERSION: string;
19
+ /**
20
+ * Create a GraphDB client.
21
+ *
22
+ * All options support environment variable defaults:
23
+ * - `url`: GRAPHDB_URL (default: 'https://leangraph.io')
24
+ * - `project`: GRAPHDB_PROJECT (required)
25
+ * - `env`: NODE_ENV (default: 'production')
26
+ * - `apiKey`: GRAPHDB_API_KEY
27
+ * - `dataPath`: GRAPHDB_DATA_PATH (default: './data')
28
+ *
29
+ * **Development Mode** (NODE_ENV=development):
30
+ * - Uses a local SQLite database
31
+ * - `url` and `apiKey` are ignored
32
+ * - Data is stored at `dataPath/{env}/{project}.db`
33
+ *
34
+ * **Production Mode** (NODE_ENV=production or unset):
35
+ * - Connects to a remote server via HTTP
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { GraphDB } from 'leangraph';
40
+ *
41
+ * // Using environment variables (set GRAPHDB_PROJECT, GRAPHDB_API_KEY)
42
+ * const db = await GraphDB();
43
+ *
44
+ * // Or with explicit options
45
+ * const db = await GraphDB({
46
+ * project: 'myapp',
47
+ * apiKey: process.env.GRAPHDB_API_KEY,
48
+ * });
49
+ *
50
+ * // Create nodes
51
+ * await db.execute('CREATE (n:User {name: "Alice"})');
52
+ *
53
+ * // Query
54
+ * const users = await db.query('MATCH (n:User) RETURN n');
55
+ *
56
+ * // Always close when done
57
+ * db.close();
58
+ * ```
59
+ */
60
+ export declare function GraphDB(options?: GraphDBOptions): Promise<GraphDBClient>;
61
+ export default GraphDB;
62
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAShE,YAAY,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACb,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAO1C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,YAAY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AGD,eAAe,OAAO,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,86 @@
1
+ // LeanGraph - Unified Package
2
+ // A lightweight graph database with Cypher query support, powered by SQLite.
3
+ import { createRequire } from "module";
4
+ import { createRemoteClient } from "./remote.js";
5
+ const require = createRequire(import.meta.url);
6
+ const pkg = require("../package.json");
7
+ export { GraphDBError } from "./types.js";
8
+ // ============================================================================
9
+ // Re-export Server Components (for advanced usage)
10
+ // ============================================================================
11
+ // Parser
12
+ export { parse } from "./parser.js";
13
+ // Translator
14
+ export { translate, Translator } from "./translator.js";
15
+ // Database
16
+ export { GraphDatabase, DatabaseManager } from "./db.js";
17
+ // Executor
18
+ export { Executor, executeQuery } from "./executor.js";
19
+ // Routes / Server
20
+ export { createApp, createServer } from "./routes.js";
21
+ // Backup
22
+ export { BackupManager } from "./backup.js";
23
+ // Auth
24
+ export { ApiKeyStore, authMiddleware, generateApiKey } from "./auth.js";
25
+ // ============================================================================
26
+ // Version
27
+ // ============================================================================
28
+ export const VERSION = pkg.version;
29
+ // ============================================================================
30
+ // Main Factory Function
31
+ // ============================================================================
32
+ /**
33
+ * Create a GraphDB client.
34
+ *
35
+ * All options support environment variable defaults:
36
+ * - `url`: GRAPHDB_URL (default: 'https://leangraph.io')
37
+ * - `project`: GRAPHDB_PROJECT (required)
38
+ * - `env`: NODE_ENV (default: 'production')
39
+ * - `apiKey`: GRAPHDB_API_KEY
40
+ * - `dataPath`: GRAPHDB_DATA_PATH (default: './data')
41
+ *
42
+ * **Development Mode** (NODE_ENV=development):
43
+ * - Uses a local SQLite database
44
+ * - `url` and `apiKey` are ignored
45
+ * - Data is stored at `dataPath/{env}/{project}.db`
46
+ *
47
+ * **Production Mode** (NODE_ENV=production or unset):
48
+ * - Connects to a remote server via HTTP
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { GraphDB } from 'leangraph';
53
+ *
54
+ * // Using environment variables (set GRAPHDB_PROJECT, GRAPHDB_API_KEY)
55
+ * const db = await GraphDB();
56
+ *
57
+ * // Or with explicit options
58
+ * const db = await GraphDB({
59
+ * project: 'myapp',
60
+ * apiKey: process.env.GRAPHDB_API_KEY,
61
+ * });
62
+ *
63
+ * // Create nodes
64
+ * await db.execute('CREATE (n:User {name: "Alice"})');
65
+ *
66
+ * // Query
67
+ * const users = await db.query('MATCH (n:User) RETURN n');
68
+ *
69
+ * // Always close when done
70
+ * db.close();
71
+ * ```
72
+ */
73
+ export async function GraphDB(options = {}) {
74
+ const isProduction = process.env.NODE_ENV === "production";
75
+ if (isProduction) {
76
+ return createRemoteClient(options);
77
+ }
78
+ else {
79
+ // Lazy-load local client to avoid requiring better-sqlite3 when not needed
80
+ const { createLocalClient } = await import("./local.js");
81
+ return createLocalClient(options);
82
+ }
83
+ }
84
+ // Default export
85
+ export default GraphDB;
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,6EAA6E;AAE7E,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAcvC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,+EAA+E;AAC/E,mDAAmD;AACnD,+EAA+E;AAE/E,SAAS;AACT,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAqBpC,aAAa;AACb,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGxD,WAAW;AACX,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGzD,WAAW;AACX,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAOvD,kBAAkB;AAClB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGtD,SAAS;AACT,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO;AACP,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGxE,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E,MAAM,CAAC,MAAM,OAAO,GAAW,GAAG,CAAC,OAAO,CAAC;AAE3C,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,UAA0B,EAAE;IACxD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;IAE3D,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,2EAA2E;QAC3E,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC;QACzD,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED,iBAAiB;AACjB,eAAe,OAAO,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { GraphDBClient, GraphDBOptions } from "./types.js";
2
+ /**
3
+ * Create a local embedded GraphDB client.
4
+ * This client uses SQLite directly without any HTTP layer.
5
+ */
6
+ export declare function createLocalClient(options?: GraphDBOptions): GraphDBClient;
7
+ //# sourceMappingURL=local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../src/local.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EAIf,MAAM,YAAY,CAAC;AAGpB;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CAqJ7E"}
package/dist/local.js ADDED
@@ -0,0 +1,119 @@
1
+ // LeanGraph - Local Embedded Client
2
+ // Uses SQLite directly without HTTP
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import { GraphDatabase } from "./db.js";
6
+ import { Executor } from "./executor.js";
7
+ import { GraphDBError } from "./types.js";
8
+ /**
9
+ * Create a local embedded GraphDB client.
10
+ * This client uses SQLite directly without any HTTP layer.
11
+ */
12
+ export function createLocalClient(options = {}) {
13
+ const dataPath = options.dataPath ?? process.env.GRAPHDB_DATA_PATH ?? "./data";
14
+ const project = options.project ?? process.env.GRAPHDB_PROJECT;
15
+ const env = options.env ?? process.env.NODE_ENV ?? "production";
16
+ if (!project) {
17
+ throw new Error("Project is required. Set via options.project or GRAPHDB_PROJECT env var.");
18
+ }
19
+ // Determine database path
20
+ let dbPath;
21
+ if (dataPath === ":memory:") {
22
+ dbPath = ":memory:";
23
+ }
24
+ else {
25
+ // Ensure directory exists
26
+ const dir = path.join(dataPath, env);
27
+ if (!fs.existsSync(dir)) {
28
+ fs.mkdirSync(dir, { recursive: true });
29
+ }
30
+ dbPath = path.join(dir, `${project}.db`);
31
+ }
32
+ // Create and initialize database
33
+ const db = new GraphDatabase(dbPath);
34
+ db.initialize();
35
+ const executor = new Executor(db);
36
+ return {
37
+ async query(cypher, params = {}) {
38
+ const result = executor.execute(cypher, params);
39
+ if (!result.success) {
40
+ throw new GraphDBError(result.error.message, {
41
+ position: result.error.position,
42
+ line: result.error.line,
43
+ column: result.error.column,
44
+ });
45
+ }
46
+ return result.data;
47
+ },
48
+ async queryRaw(cypher, params = {}) {
49
+ const result = executor.execute(cypher, params);
50
+ if (!result.success) {
51
+ throw new GraphDBError(result.error.message, {
52
+ position: result.error.position,
53
+ line: result.error.line,
54
+ column: result.error.column,
55
+ });
56
+ }
57
+ return {
58
+ success: true,
59
+ data: result.data,
60
+ meta: result.meta,
61
+ };
62
+ },
63
+ async execute(cypher, params = {}) {
64
+ const result = executor.execute(cypher, params);
65
+ if (!result.success) {
66
+ throw new GraphDBError(result.error.message, {
67
+ position: result.error.position,
68
+ line: result.error.line,
69
+ column: result.error.column,
70
+ });
71
+ }
72
+ },
73
+ async createNode(label, properties = {}) {
74
+ const propKeys = Object.keys(properties);
75
+ const propAssignments = propKeys.map((k) => `${k}: $${k}`).join(", ");
76
+ const cypher = `CREATE (n:${label} {${propAssignments}}) RETURN id(n) as id`;
77
+ const result = await this.query(cypher, properties);
78
+ return result[0]?.id;
79
+ },
80
+ async createEdge(sourceId, type, targetId, properties = {}) {
81
+ const propKeys = Object.keys(properties);
82
+ const propAssignments = propKeys.length > 0
83
+ ? ` {${propKeys.map((k) => `${k}: $${k}`).join(", ")}}`
84
+ : "";
85
+ const cypher = `
86
+ MATCH (source), (target)
87
+ WHERE id(source) = $sourceId AND id(target) = $targetId
88
+ MERGE (source)-[:${type}${propAssignments}]->(target)
89
+ `;
90
+ await this.execute(cypher, { sourceId, targetId, ...properties });
91
+ },
92
+ async getNode(label, filter) {
93
+ const filterKeys = Object.keys(filter);
94
+ const filterProps = filterKeys.map((k) => `${k}: $${k}`).join(", ");
95
+ const cypher = `MATCH (n:${label} {${filterProps}}) RETURN n LIMIT 1`;
96
+ const result = await this.query(cypher, filter);
97
+ return result.length > 0 ? result[0].n : null;
98
+ },
99
+ async deleteNode(id) {
100
+ await this.execute("MATCH (n) WHERE id(n) = $id DETACH DELETE n", { id });
101
+ },
102
+ async updateNode(id, properties) {
103
+ const propKeys = Object.keys(properties);
104
+ const setClause = propKeys.map((k) => `n.${k} = $${k}`).join(", ");
105
+ const cypher = `MATCH (n) WHERE id(n) = $id SET ${setClause}`;
106
+ await this.execute(cypher, { id, ...properties });
107
+ },
108
+ async health() {
109
+ return {
110
+ status: "ok",
111
+ timestamp: new Date().toISOString(),
112
+ };
113
+ },
114
+ close() {
115
+ db.close();
116
+ },
117
+ };
118
+ }
119
+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AAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEnE,MAAM,MAAM,GAAG,mCAAmC,SAAS,EAAE,CAAC;YAC9D,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC;QACpD,CAAC;QAED,KAAK,CAAC,MAAM;YACV,OAAO;gBACL,MAAM,EAAE,IAAI;gBACZ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC,CAAC;QACJ,CAAC;QAED,KAAK;YACH,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,365 @@
1
+ export interface NodePattern {
2
+ variable?: string;
3
+ label?: string | string[];
4
+ properties?: Record<string, PropertyValue>;
5
+ }
6
+ export interface EdgePattern {
7
+ variable?: string;
8
+ type?: string;
9
+ types?: string[];
10
+ properties?: Record<string, PropertyValue>;
11
+ direction: "left" | "right" | "none";
12
+ minHops?: number;
13
+ maxHops?: number;
14
+ }
15
+ export interface RelationshipPattern {
16
+ source: NodePattern;
17
+ edge: EdgePattern;
18
+ target: NodePattern;
19
+ }
20
+ export interface PathExpression {
21
+ type: "path";
22
+ variable: string;
23
+ patterns: (NodePattern | RelationshipPattern)[];
24
+ }
25
+ export interface ParameterRef {
26
+ type: "parameter";
27
+ name: string;
28
+ }
29
+ export interface VariableRef {
30
+ type: "variable";
31
+ name: string;
32
+ }
33
+ export interface PropertyRef {
34
+ type: "property";
35
+ variable: string;
36
+ property: string;
37
+ }
38
+ export interface BinaryPropertyValue {
39
+ type: "binary";
40
+ operator: "+" | "-" | "*" | "/" | "%" | "^";
41
+ left: PropertyValue;
42
+ right: PropertyValue;
43
+ }
44
+ export interface FunctionPropertyValue {
45
+ type: "function";
46
+ name: string;
47
+ args: PropertyValue[];
48
+ }
49
+ export interface MapPropertyValue {
50
+ type: "map";
51
+ properties: Record<string, PropertyValue>;
52
+ }
53
+ export type PropertyValue = string | number | boolean | null | ParameterRef | VariableRef | PropertyRef | BinaryPropertyValue | MapPropertyValue | FunctionPropertyValue | PropertyValue[];
54
+ export interface WhereCondition {
55
+ type: "comparison" | "and" | "or" | "not" | "contains" | "startsWith" | "endsWith" | "isNull" | "isNotNull" | "exists" | "in" | "listPredicate" | "patternMatch" | "expression";
56
+ left?: Expression;
57
+ right?: Expression;
58
+ operator?: "=" | "<>" | "<" | ">" | "<=" | ">=";
59
+ conditions?: WhereCondition[];
60
+ condition?: WhereCondition;
61
+ pattern?: NodePattern | RelationshipPattern;
62
+ patterns?: (NodePattern | RelationshipPattern)[];
63
+ list?: Expression;
64
+ predicateType?: "ALL" | "ANY" | "NONE" | "SINGLE";
65
+ variable?: string;
66
+ listExpr?: Expression;
67
+ filterCondition?: WhereCondition;
68
+ }
69
+ export interface CaseWhen {
70
+ condition: WhereCondition;
71
+ result: Expression;
72
+ }
73
+ export interface CaseExpression {
74
+ type: "case";
75
+ expression?: Expression;
76
+ whens: CaseWhen[];
77
+ elseExpr?: Expression;
78
+ }
79
+ export interface ObjectProperty {
80
+ key: string;
81
+ value: Expression;
82
+ }
83
+ export interface Expression {
84
+ type: "property" | "literal" | "parameter" | "variable" | "function" | "case" | "binary" | "object" | "comparison" | "listComprehension" | "listPredicate" | "patternComprehension" | "unary" | "labelPredicate" | "propertyAccess" | "indexAccess" | "in" | "stringOp";
85
+ variable?: string;
86
+ property?: string;
87
+ value?: PropertyValue;
88
+ raw?: string;
89
+ numberLiteralKind?: "integer" | "float";
90
+ name?: string;
91
+ functionName?: string;
92
+ args?: Expression[];
93
+ distinct?: boolean;
94
+ star?: boolean;
95
+ expression?: Expression;
96
+ whens?: CaseWhen[];
97
+ elseExpr?: Expression;
98
+ operator?: "+" | "-" | "*" | "/" | "%" | "^" | "AND" | "OR" | "XOR" | "NOT";
99
+ left?: Expression;
100
+ right?: Expression;
101
+ operand?: Expression;
102
+ comparisonOperator?: "=" | "<>" | "<" | ">" | "<=" | ">=" | "IS NULL" | "IS NOT NULL";
103
+ properties?: ObjectProperty[];
104
+ listExpr?: Expression;
105
+ filterCondition?: WhereCondition;
106
+ mapExpr?: Expression;
107
+ predicateType?: "ALL" | "ANY" | "NONE" | "SINGLE";
108
+ patterns?: (NodePattern | RelationshipPattern)[];
109
+ pathVariable?: string;
110
+ label?: string;
111
+ labels?: string[];
112
+ object?: Expression;
113
+ array?: Expression;
114
+ index?: Expression;
115
+ list?: Expression;
116
+ stringOperator?: "CONTAINS" | "STARTS WITH" | "ENDS WITH";
117
+ }
118
+ export interface ReturnItem {
119
+ expression: Expression;
120
+ alias?: string;
121
+ }
122
+ export interface SetAssignment {
123
+ variable: string;
124
+ property?: string;
125
+ value?: Expression;
126
+ labels?: string[];
127
+ replaceProps?: boolean;
128
+ mergeProps?: boolean;
129
+ }
130
+ export interface CreateClause {
131
+ type: "CREATE";
132
+ patterns: (NodePattern | RelationshipPattern)[];
133
+ }
134
+ export interface MatchClause {
135
+ type: "MATCH" | "OPTIONAL_MATCH";
136
+ patterns: (NodePattern | RelationshipPattern)[];
137
+ pathExpressions?: PathExpression[];
138
+ where?: WhereCondition;
139
+ }
140
+ export interface MergeClause {
141
+ type: "MERGE";
142
+ patterns: (NodePattern | RelationshipPattern)[];
143
+ pathExpressions?: PathExpression[];
144
+ onCreateSet?: SetAssignment[];
145
+ onMatchSet?: SetAssignment[];
146
+ }
147
+ export interface SetClause {
148
+ type: "SET";
149
+ assignments: SetAssignment[];
150
+ }
151
+ export interface DeleteClause {
152
+ type: "DELETE";
153
+ variables: string[];
154
+ expressions?: Expression[];
155
+ detach?: boolean;
156
+ }
157
+ export interface RemoveItem {
158
+ variable: string;
159
+ property?: string;
160
+ labels?: string[];
161
+ }
162
+ export interface RemoveClause {
163
+ type: "REMOVE";
164
+ items: RemoveItem[];
165
+ }
166
+ export interface ReturnClause {
167
+ type: "RETURN";
168
+ distinct?: boolean;
169
+ items: ReturnItem[];
170
+ orderBy?: {
171
+ expression: Expression;
172
+ direction: "ASC" | "DESC";
173
+ }[];
174
+ skip?: Expression;
175
+ limit?: Expression;
176
+ }
177
+ export interface WithClause {
178
+ type: "WITH";
179
+ distinct?: boolean;
180
+ items: ReturnItem[];
181
+ orderBy?: {
182
+ expression: Expression;
183
+ direction: "ASC" | "DESC";
184
+ }[];
185
+ skip?: Expression;
186
+ limit?: Expression;
187
+ where?: WhereCondition;
188
+ }
189
+ export interface UnwindClause {
190
+ type: "UNWIND";
191
+ expression: Expression;
192
+ alias: string;
193
+ }
194
+ export interface UnionClause {
195
+ type: "UNION";
196
+ all: boolean;
197
+ left: Query;
198
+ right: Query;
199
+ }
200
+ export interface CallClause {
201
+ type: "CALL";
202
+ procedure: string;
203
+ args: Expression[];
204
+ yields?: string[];
205
+ where?: WhereCondition;
206
+ }
207
+ export type Clause = CreateClause | MatchClause | MergeClause | SetClause | DeleteClause | RemoveClause | ReturnClause | WithClause | UnwindClause | UnionClause | CallClause;
208
+ export interface Query {
209
+ clauses: Clause[];
210
+ }
211
+ export interface ParseError {
212
+ message: string;
213
+ position: number;
214
+ line: number;
215
+ column: number;
216
+ }
217
+ export type ParseResult = {
218
+ success: true;
219
+ query: Query;
220
+ } | {
221
+ success: false;
222
+ error: ParseError;
223
+ };
224
+ export declare class Parser {
225
+ private tokens;
226
+ private pos;
227
+ private anonVarCounter;
228
+ /**
229
+ * Parse a number string, validating that integers are within int64 range.
230
+ * Throws SyntaxError for overflow.
231
+ */
232
+ private parseNumber;
233
+ parse(input: string): ParseResult;
234
+ private parseQuery;
235
+ private error;
236
+ private parseClause;
237
+ private parseCreate;
238
+ private parseMatch;
239
+ /**
240
+ * Parse either a regular pattern chain or a named path expression.
241
+ * Syntax: p = (a)-[r]->(b) or just (a)-[r]->(b)
242
+ */
243
+ private parsePatternOrPath;
244
+ private parseOptionalMatch;
245
+ /**
246
+ * Validate that no variable is used as both a node and a relationship in the same MATCH clause,
247
+ * and that no relationship variable is used more than once in the same pattern.
248
+ * These are invalid Cypher syntax.
249
+ */
250
+ private validateNoNodeRelationshipVariableConflict;
251
+ private parseMerge;
252
+ private parseSet;
253
+ private parseSetAssignments;
254
+ private parseRemove;
255
+ private parseDelete;
256
+ private parseDeleteTarget;
257
+ private parseReturn;
258
+ private parseWith;
259
+ private parseUnwind;
260
+ private parseUnwindExpression;
261
+ private parseCall;
262
+ /**
263
+ * Parse a pattern, which can be a single node or a chain of relationships.
264
+ * For chained patterns like (a)-[:R1]->(b)-[:R2]->(c), this returns multiple
265
+ * RelationshipPattern objects via parsePatternChain.
266
+ */
267
+ private parsePattern;
268
+ /**
269
+ * Parse a pattern chain, returning an array of patterns.
270
+ * Handles multi-hop patterns like (a)-[:R1]->(b)-[:R2]->(c).
271
+ */
272
+ private parsePatternChain;
273
+ private parseNodePattern;
274
+ private parseEdgePattern;
275
+ private parseVariableLengthSpec;
276
+ private parseProperties;
277
+ private parsePropertyValue;
278
+ private parsePrimaryPropertyValue;
279
+ private parseMapPropertyValue;
280
+ private parseArray;
281
+ private parseWhereCondition;
282
+ private parseOrCondition;
283
+ private parseAndCondition;
284
+ private parseNotCondition;
285
+ /**
286
+ * Detect if we're looking at a pattern (e.g., (a)-[:R]->(b)).
287
+ * A pattern starts with ( and after the matching ), we expect - or <- (not a keyword like AND, OR, etc).
288
+ */
289
+ private isPatternStart;
290
+ private parsePrimaryCondition;
291
+ private parseListPredicateCondition;
292
+ private parseExistsCondition;
293
+ private parseComparisonCondition;
294
+ private parseInListExpression;
295
+ private parseExpression;
296
+ private parseReturnExpression;
297
+ private parseOrExpression;
298
+ private parseXorExpression;
299
+ private parseAndExpression;
300
+ private parseNotExpression;
301
+ private parseComparisonExpression;
302
+ private parseIsNullExpression;
303
+ private parseAdditiveExpression;
304
+ private parseMultiplicativeExpression;
305
+ private parseExponentialExpression;
306
+ private parsePostfixExpression;
307
+ /**
308
+ * Parse an expression that can be used as a slice bound (start or end).
309
+ * This is similar to parseExpression but stops at ".." to allow slice syntax.
310
+ * It uses a modified postfix parser that detects ".." and stops before consuming it.
311
+ */
312
+ private parseSliceBoundExpression;
313
+ private parseSliceBoundAdditiveExpression;
314
+ private parseSliceBoundMultiplicativeExpression;
315
+ private parseSliceBoundExponentialExpression;
316
+ /**
317
+ * Parse postfix expression for slice bounds. This version detects ".."
318
+ * and stops before consuming it, allowing the slice syntax to be parsed correctly.
319
+ */
320
+ private parseSliceBoundPostfixExpression;
321
+ private parsePrimaryExpression;
322
+ private parseCaseExpression;
323
+ private parseObjectLiteral;
324
+ private parseListLiteralExpression;
325
+ /**
326
+ * Parse a list comprehension after [variable IN has been consumed.
327
+ * Full syntax: [variable IN listExpr WHERE filterCondition | mapExpr]
328
+ * - WHERE and | are both optional
329
+ */
330
+ private parseListComprehension;
331
+ /**
332
+ * Parse a pattern comprehension after [ has been consumed and we see (.
333
+ * Syntax: [(pattern) WHERE filterCondition | mapExpr]
334
+ * Or with named path: [p = (pattern) WHERE filterCondition | p]
335
+ * WHERE and | mapExpr are optional.
336
+ */
337
+ private parsePatternComprehension;
338
+ /**
339
+ * Parse a list predicate after PRED(variable IN has been consumed.
340
+ * Syntax: ALL/ANY/NONE/SINGLE(variable IN listExpr WHERE filterCondition)
341
+ * WHERE is required for list predicates.
342
+ */
343
+ private parseListPredicate;
344
+ /**
345
+ * Parse a condition in a list comprehension, where the variable can be used.
346
+ * Similar to parseWhereCondition but resolves variable references.
347
+ */
348
+ private parseListComprehensionCondition;
349
+ /**
350
+ * Parse an expression in a list comprehension map projection.
351
+ * Similar to parseExpression but the variable is in scope.
352
+ */
353
+ private parseListComprehensionExpression;
354
+ private peek;
355
+ private advance;
356
+ private isAtEnd;
357
+ private check;
358
+ private checkKeyword;
359
+ private expect;
360
+ private expectIdentifier;
361
+ private expectIdentifierOrKeyword;
362
+ private expectLabelOrType;
363
+ }
364
+ export declare function parse(input: string): ParseResult;
365
+ //# sourceMappingURL=parser.d.ts.map