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.
- package/LICENSE +21 -0
- package/README.md +456 -0
- package/dist/auth.d.ts +66 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +148 -0
- package/dist/auth.js.map +1 -0
- package/dist/backup.d.ts +51 -0
- package/dist/backup.d.ts.map +1 -0
- package/dist/backup.js +201 -0
- package/dist/backup.js.map +1 -0
- package/dist/cli-helpers.d.ts +17 -0
- package/dist/cli-helpers.d.ts.map +1 -0
- package/dist/cli-helpers.js +121 -0
- package/dist/cli-helpers.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +660 -0
- package/dist/cli.js.map +1 -0
- package/dist/db.d.ts +118 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +720 -0
- package/dist/db.js.map +1 -0
- package/dist/executor.d.ts +663 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +8578 -0
- package/dist/executor.js.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/local.d.ts +7 -0
- package/dist/local.d.ts.map +1 -0
- package/dist/local.js +119 -0
- package/dist/local.js.map +1 -0
- package/dist/parser.d.ts +365 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +2711 -0
- package/dist/parser.js.map +1 -0
- package/dist/property-value.d.ts +3 -0
- package/dist/property-value.d.ts.map +1 -0
- package/dist/property-value.js +30 -0
- package/dist/property-value.js.map +1 -0
- package/dist/remote.d.ts +6 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/remote.js +93 -0
- package/dist/remote.js.map +1 -0
- package/dist/routes.d.ts +31 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +202 -0
- package/dist/routes.js.map +1 -0
- package/dist/server.d.ts +16 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +25 -0
- package/dist/server.js.map +1 -0
- package/dist/translator.d.ts +330 -0
- package/dist/translator.d.ts.map +1 -0
- package/dist/translator.js +13712 -0
- package/dist/translator.js.map +1 -0
- package/dist/types.d.ts +136 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,YAAY,EACV,KAAK,EACL,MAAM,EACN,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,UAAU,EACV,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,GACX,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACzD,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEzE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACvD,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEpF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACxE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzE,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// LeanGraph Server - Entry Point
|
|
2
|
+
export { parse } from "./parser.js";
|
|
3
|
+
export { translate, Translator } from "./translator.js";
|
|
4
|
+
export { GraphDatabase, DatabaseManager } from "./db.js";
|
|
5
|
+
export { Executor, executeQuery } from "./executor.js";
|
|
6
|
+
export { createApp, createServer } from "./routes.js";
|
|
7
|
+
export { BackupManager } from "./backup.js";
|
|
8
|
+
export { ApiKeyStore, authMiddleware, generateApiKey } from "./auth.js";
|
|
9
|
+
export const VERSION = "0.1.0";
|
|
10
|
+
// If this file is run directly, start the server
|
|
11
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
12
|
+
const { serve } = await import("@hono/node-server");
|
|
13
|
+
const { createServer } = await import("./routes");
|
|
14
|
+
const port = parseInt(process.env.PORT || "3000", 10);
|
|
15
|
+
const dataPath = process.env.DATA_PATH || "./data";
|
|
16
|
+
const { app, dbManager } = createServer({ port, dataPath });
|
|
17
|
+
console.log(`LeanGraph Server v${VERSION}`);
|
|
18
|
+
console.log(`Starting on http://localhost:${port}`);
|
|
19
|
+
console.log(`Data path: ${dataPath}`);
|
|
20
|
+
serve({
|
|
21
|
+
fetch: app.fetch,
|
|
22
|
+
port,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAEjC,OAAO,EAAE,KAAK,EAAE,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KAAK;QAChB,IAAI;KACL,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { Query, WithClause } from "./parser.js";
|
|
2
|
+
export interface SqlStatement {
|
|
3
|
+
sql: string;
|
|
4
|
+
params: unknown[];
|
|
5
|
+
}
|
|
6
|
+
export interface TranslationResult {
|
|
7
|
+
statements: SqlStatement[];
|
|
8
|
+
returnColumns?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface TranslationContext {
|
|
11
|
+
variables: Map<string, {
|
|
12
|
+
type: "node" | "edge" | "path" | "varLengthEdge";
|
|
13
|
+
alias: string;
|
|
14
|
+
pathCteName?: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
}>;
|
|
17
|
+
paramValues: Record<string, unknown>;
|
|
18
|
+
aliasCounter: number;
|
|
19
|
+
withClauses?: WithClause[];
|
|
20
|
+
}
|
|
21
|
+
export declare class Translator {
|
|
22
|
+
private ctx;
|
|
23
|
+
constructor(paramValues?: Record<string, unknown>);
|
|
24
|
+
translate(query: Query): TranslationResult;
|
|
25
|
+
/**
|
|
26
|
+
* Validate and translate a SKIP or LIMIT expression
|
|
27
|
+
* Throws an error if the value is negative
|
|
28
|
+
*/
|
|
29
|
+
private translateSkipLimitExpression;
|
|
30
|
+
private translateClause;
|
|
31
|
+
private translateCreate;
|
|
32
|
+
private translateCreateNode;
|
|
33
|
+
private translateCreateRelationship;
|
|
34
|
+
private translateMatch;
|
|
35
|
+
private registerPathExpression;
|
|
36
|
+
private registerNodePattern;
|
|
37
|
+
private registerRelationshipPattern;
|
|
38
|
+
private translateMerge;
|
|
39
|
+
private translateSet;
|
|
40
|
+
private assertValidPropertyValueExpression;
|
|
41
|
+
/**
|
|
42
|
+
* Evaluate an object expression to get its key-value pairs.
|
|
43
|
+
*/
|
|
44
|
+
private evaluateObjectExpression;
|
|
45
|
+
private translateRemove;
|
|
46
|
+
private translateDelete;
|
|
47
|
+
private translateReturn;
|
|
48
|
+
private translateWith;
|
|
49
|
+
private translateReturnFromCall;
|
|
50
|
+
private translateVariableLengthPath;
|
|
51
|
+
private translateUnion;
|
|
52
|
+
private translateUnwind;
|
|
53
|
+
private translateCall;
|
|
54
|
+
private translateCallWhere;
|
|
55
|
+
private translateExpressionForCall;
|
|
56
|
+
private lookupWithAliasExpression;
|
|
57
|
+
private translateExpression;
|
|
58
|
+
private translateCaseExpression;
|
|
59
|
+
/**
|
|
60
|
+
* Get the Cypher type string for an expression (for type-aware comparison in CASE)
|
|
61
|
+
*/
|
|
62
|
+
private getCypherTypeForExpression;
|
|
63
|
+
private translateBinaryExpression;
|
|
64
|
+
private tryTranslateTemporalDurationArithmetic;
|
|
65
|
+
private isListExpression;
|
|
66
|
+
private isObjectExpression;
|
|
67
|
+
private isStringConcatenation;
|
|
68
|
+
/**
|
|
69
|
+
* Check if an expression could produce NaN (IEEE 754 Not a Number).
|
|
70
|
+
* In SQLite, division by zero returns NULL, but Cypher semantics require NaN.
|
|
71
|
+
* NaN has special comparison semantics: NaN = x is always false, NaN <> x is always true.
|
|
72
|
+
*/
|
|
73
|
+
private couldProduceNaN;
|
|
74
|
+
private wrapForArray;
|
|
75
|
+
private wrapForArithmetic;
|
|
76
|
+
/**
|
|
77
|
+
* Translate an expression for a SET on a just-created node.
|
|
78
|
+
* Property references need to use subqueries since the node ID isn't a table alias.
|
|
79
|
+
*/
|
|
80
|
+
private translateExpressionForCreatedNode;
|
|
81
|
+
private isBooleanProducingExpression;
|
|
82
|
+
private normalizeForBooleanComparison;
|
|
83
|
+
private translateComparisonExpression;
|
|
84
|
+
private wrapForComparison;
|
|
85
|
+
private translateObjectLiteral;
|
|
86
|
+
private translateArrayLiteral;
|
|
87
|
+
/**
|
|
88
|
+
* Translate a list comprehension expression.
|
|
89
|
+
* Syntax: [variable IN listExpr WHERE filterCondition | mapExpr]
|
|
90
|
+
*
|
|
91
|
+
* Translates to SQLite using json_each and json_group_array:
|
|
92
|
+
* (SELECT json_group_array(value_or_mapped) FROM json_each(listExpr) WHERE filter)
|
|
93
|
+
*/
|
|
94
|
+
private translateListComprehension;
|
|
95
|
+
/**
|
|
96
|
+
* Translate a pattern comprehension expression.
|
|
97
|
+
* Syntax: [(pattern) WHERE filterCondition | mapExpr]
|
|
98
|
+
*
|
|
99
|
+
* Pattern comprehensions match a pattern starting from bound variables and
|
|
100
|
+
* return a list of results from the mapExpr (or pattern elements if no mapExpr).
|
|
101
|
+
*
|
|
102
|
+
* Example: [(a)-[:T|OTHER]->() | 1] returns a list of 1s for each matching edge
|
|
103
|
+
*/
|
|
104
|
+
private translatePatternComprehension;
|
|
105
|
+
/**
|
|
106
|
+
* Translate an expression within a pattern comprehension.
|
|
107
|
+
*/
|
|
108
|
+
private translatePatternComprehensionExpr;
|
|
109
|
+
/**
|
|
110
|
+
* Translate a condition within a pattern comprehension.
|
|
111
|
+
*/
|
|
112
|
+
private translatePatternComprehensionCondition;
|
|
113
|
+
/**
|
|
114
|
+
* Translate an expression within a list comprehension, replacing
|
|
115
|
+
* references to the comprehension variable with the json_each value column.
|
|
116
|
+
* Supports scope chains for nested quantifiers.
|
|
117
|
+
*/
|
|
118
|
+
private translateListComprehensionExpr;
|
|
119
|
+
/**
|
|
120
|
+
* Translate a WHERE condition within a list comprehension.
|
|
121
|
+
* Supports scope chains for nested quantifiers.
|
|
122
|
+
*/
|
|
123
|
+
private translateListComprehensionCondition;
|
|
124
|
+
/**
|
|
125
|
+
* Translate a list predicate expression: ALL/ANY/NONE/SINGLE(var IN list WHERE cond)
|
|
126
|
+
*
|
|
127
|
+
* Three-valued logic for handling nulls:
|
|
128
|
+
* - If predicate evaluation produces NULL (unknown) for any element and no definitive answer, return NULL
|
|
129
|
+
* - ALL: false if any element fails; null if unknowns present and all definites pass; true otherwise
|
|
130
|
+
* - ANY: true if any element passes; null if unknowns present and no pass; false otherwise
|
|
131
|
+
* - NONE: false if any element passes; null if unknowns present and no pass; true otherwise
|
|
132
|
+
* - SINGLE: false if >1 element passes; null if unknowns present; true if exactly 1 passes; false otherwise
|
|
133
|
+
*
|
|
134
|
+
* Unknowns are detected by: (total count) - (matches) - (non-matches) > 0
|
|
135
|
+
* This correctly handles cases like `WHERE false` where the predicate is static.
|
|
136
|
+
*
|
|
137
|
+
* Note: Since the CASE expression uses the list/cond multiple times, we must duplicate
|
|
138
|
+
* the params for each occurrence.
|
|
139
|
+
*/
|
|
140
|
+
private translateListPredicate;
|
|
141
|
+
/**
|
|
142
|
+
* Translate a nested list predicate within a list comprehension context.
|
|
143
|
+
* This handles cases like: none(x IN list WHERE none(y IN x WHERE y = 'abc'))
|
|
144
|
+
* Also handles deeply nested cases: none(x IN list WHERE none(y IN list WHERE x <= y))
|
|
145
|
+
*
|
|
146
|
+
* @param expr The nested list predicate expression
|
|
147
|
+
* @param scopes The scope chain from outer contexts (variable to alias mappings)
|
|
148
|
+
*/
|
|
149
|
+
private translateNestedListPredicate;
|
|
150
|
+
/**
|
|
151
|
+
* Wrap an expression for use with json_each in list predicates
|
|
152
|
+
*/
|
|
153
|
+
private wrapForListPredicate;
|
|
154
|
+
/**
|
|
155
|
+
* Get the static type of an expression when it can be determined at compile time.
|
|
156
|
+
* Returns the type name for literals and expressions with known types, or null for dynamic types.
|
|
157
|
+
*/
|
|
158
|
+
private getStaticExpressionType;
|
|
159
|
+
/**
|
|
160
|
+
* Check if expression type is valid for boolean operators (AND, OR, NOT).
|
|
161
|
+
* Throws SyntaxError if the type is definitely invalid.
|
|
162
|
+
*/
|
|
163
|
+
private validateBooleanOperand;
|
|
164
|
+
/**
|
|
165
|
+
* Get the static element type of a list expression (if determinable).
|
|
166
|
+
* Returns the common element type for literal arrays, or null if mixed or unknown.
|
|
167
|
+
*/
|
|
168
|
+
private getListElementType;
|
|
169
|
+
/**
|
|
170
|
+
* Check if a filter condition uses arithmetic operators on a specific variable.
|
|
171
|
+
* Returns true if the variable is used with %, /, *, -, or ^ operators.
|
|
172
|
+
*/
|
|
173
|
+
private conditionUsesArithmeticOnVariable;
|
|
174
|
+
/**
|
|
175
|
+
* Check if an expression uses arithmetic operators on a specific variable.
|
|
176
|
+
* Returns true if the variable is an operand of %, /, *, -, or ^ operators.
|
|
177
|
+
*/
|
|
178
|
+
private expressionUsesArithmeticOnVariable;
|
|
179
|
+
/**
|
|
180
|
+
* Check if an expression directly references a variable.
|
|
181
|
+
*/
|
|
182
|
+
private expressionReferencesVariable;
|
|
183
|
+
/**
|
|
184
|
+
* Validate type compatibility in list predicates (ALL, ANY, NONE, SINGLE).
|
|
185
|
+
* Throws SyntaxError if using arithmetic on non-numeric list elements.
|
|
186
|
+
*/
|
|
187
|
+
private validateListPredicateTypes;
|
|
188
|
+
/**
|
|
189
|
+
* Translate a unary expression: NOT expr
|
|
190
|
+
*/
|
|
191
|
+
private translateUnaryExpression;
|
|
192
|
+
private translateWhere;
|
|
193
|
+
private translateExistsCondition;
|
|
194
|
+
private translatePatternCondition;
|
|
195
|
+
private translateInCondition;
|
|
196
|
+
private buildTimeWithOffsetOrderBy;
|
|
197
|
+
private buildDateTimeWithOffsetOrderBy;
|
|
198
|
+
private translateOrderByExpression;
|
|
199
|
+
/**
|
|
200
|
+
* Translate complex expressions for ORDER BY, substituting RETURN column aliases
|
|
201
|
+
*/
|
|
202
|
+
private translateOrderByComplexExpression;
|
|
203
|
+
private translateWhereExpression;
|
|
204
|
+
/**
|
|
205
|
+
* Translate a function argument expression to SQL.
|
|
206
|
+
* Handles property access, literals, parameters, and variables.
|
|
207
|
+
*/
|
|
208
|
+
private translateFunctionArg;
|
|
209
|
+
/**
|
|
210
|
+
* Check if a property name is a temporal accessor (like year, month, day, etc.)
|
|
211
|
+
* and return the SQL expression to extract it from a temporal value.
|
|
212
|
+
* Returns null if not a temporal accessor.
|
|
213
|
+
*/
|
|
214
|
+
private translateTemporalPropertyAccess;
|
|
215
|
+
private isRelationshipPattern;
|
|
216
|
+
/**
|
|
217
|
+
* Generate SQL condition to match labels stored as JSON array.
|
|
218
|
+
* For a single label "Person", checks if label array contains "Person"
|
|
219
|
+
* For multiple labels ["A", "B"], checks if label array contains all of them
|
|
220
|
+
*/
|
|
221
|
+
private generateLabelMatchCondition;
|
|
222
|
+
/**
|
|
223
|
+
* Normalize label to JSON array string for storage
|
|
224
|
+
*/
|
|
225
|
+
private normalizeLabelToJson;
|
|
226
|
+
/**
|
|
227
|
+
* Quote an identifier for use as SQL alias (handles reserved words like FROM, TO)
|
|
228
|
+
*/
|
|
229
|
+
private quoteAlias;
|
|
230
|
+
private expressionReferencesGraphVariables;
|
|
231
|
+
private findVariablesInExpression;
|
|
232
|
+
/**
|
|
233
|
+
* Extract the bound variables from a pattern comprehension expression.
|
|
234
|
+
* For pattern comprehensions like [p = (n)-->() | p], this returns ["n"]
|
|
235
|
+
* which is the variable from the outer context that the comprehension correlates with.
|
|
236
|
+
*/
|
|
237
|
+
private getPatternComprehensionBoundVars;
|
|
238
|
+
/**
|
|
239
|
+
* Get the SQL expressions to use for GROUP BY when the given expression
|
|
240
|
+
* is used in an aggregation context. For pattern comprehensions, this returns
|
|
241
|
+
* the bound variable's identifier instead of the full correlated subquery.
|
|
242
|
+
*/
|
|
243
|
+
private getGroupByKeys;
|
|
244
|
+
private findVariablesInCondition;
|
|
245
|
+
private isParameterRef;
|
|
246
|
+
/**
|
|
247
|
+
* Check if an expression contains a non-deterministic function (RAND, TIMESTAMP, etc.)
|
|
248
|
+
*/
|
|
249
|
+
private containsNonDeterministicFunction;
|
|
250
|
+
/**
|
|
251
|
+
* Check if an expression is or contains an aggregate function (COUNT, SUM, AVG, MIN, MAX, COLLECT, PERCENTILEDISC, PERCENTILECONT)
|
|
252
|
+
*/
|
|
253
|
+
private isAggregateExpression;
|
|
254
|
+
/**
|
|
255
|
+
* Extract list predicates from an expression that reference WITH aggregate aliases.
|
|
256
|
+
* Returns a set of alias names that need to be materialized.
|
|
257
|
+
*/
|
|
258
|
+
private collectWithAggregateAliasesFromListPredicates;
|
|
259
|
+
/**
|
|
260
|
+
* Check if a WHERE condition references any alias that resolves to an aggregate expression.
|
|
261
|
+
* This is used to determine if the condition should go in HAVING instead of WHERE.
|
|
262
|
+
*/
|
|
263
|
+
private whereConditionReferencesAggregateAlias;
|
|
264
|
+
private serializeProperties;
|
|
265
|
+
private isFunctionPropertyValue;
|
|
266
|
+
private isBinaryPropertyValue;
|
|
267
|
+
private isMapPropertyValue;
|
|
268
|
+
private evaluatePropertyValue;
|
|
269
|
+
private isVariableRef;
|
|
270
|
+
private evaluateExpression;
|
|
271
|
+
private getExpressionName;
|
|
272
|
+
/**
|
|
273
|
+
* Check for duplicate column names in RETURN or WITH items.
|
|
274
|
+
* Throws SyntaxError with ColumnNameConflict if duplicates are found.
|
|
275
|
+
*/
|
|
276
|
+
private checkDuplicateColumnNames;
|
|
277
|
+
/**
|
|
278
|
+
* Validate that ORDER BY expressions with DISTINCT only reference columns in the RETURN clause.
|
|
279
|
+
* In SQL, when using SELECT DISTINCT, ORDER BY can only reference columns that appear in the SELECT list.
|
|
280
|
+
* This is because DISTINCT removes duplicate rows before ORDER BY, so ordering by a column not in
|
|
281
|
+
* the SELECT list would be ambiguous (which value to use from the deduplicated rows?).
|
|
282
|
+
*
|
|
283
|
+
* Special cases:
|
|
284
|
+
* - RETURN DISTINCT b ORDER BY b.name - VALID (b is returned, b.name is a property of b)
|
|
285
|
+
* - RETURN DISTINCT a.name ORDER BY a.age - INVALID (a.age is not in RETURN)
|
|
286
|
+
*/
|
|
287
|
+
private validateDistinctOrderBy;
|
|
288
|
+
/**
|
|
289
|
+
* Validate ORDER BY with aggregation in RETURN.
|
|
290
|
+
* When aggregation is used, ORDER BY can only reference:
|
|
291
|
+
* - Column aliases from RETURN
|
|
292
|
+
* - Expressions that exactly match RETURN expressions
|
|
293
|
+
* - Pure aggregate expressions (no mixing of aggregate and non-aggregate)
|
|
294
|
+
*
|
|
295
|
+
* This prevents queries like:
|
|
296
|
+
* - RETURN count(you.age) ORDER BY me.age + count(you.age) - INVALID (me.age not grouped)
|
|
297
|
+
*/
|
|
298
|
+
private validateAggregationOrderBy;
|
|
299
|
+
/**
|
|
300
|
+
* Check if an expression is a pure aggregate (contains only aggregates, literals, operators, and column aliases).
|
|
301
|
+
* No references to non-aggregated variables.
|
|
302
|
+
*
|
|
303
|
+
* @param expr - The expression to check
|
|
304
|
+
* @param availableColumns - Set of column aliases that are available from RETURN clause
|
|
305
|
+
* @param returnedExpressions - List of expressions in the RETURN clause
|
|
306
|
+
*/
|
|
307
|
+
private isPureAggregateExpression;
|
|
308
|
+
/**
|
|
309
|
+
* Check if an expression matches any expression in the list (structurally).
|
|
310
|
+
*/
|
|
311
|
+
private expressionMatchesAny;
|
|
312
|
+
/**
|
|
313
|
+
* Check if two expressions are structurally equivalent.
|
|
314
|
+
*/
|
|
315
|
+
private expressionsMatch;
|
|
316
|
+
/**
|
|
317
|
+
* Translate temporal truncate functions: date.truncate(), datetime.truncate(), etc.
|
|
318
|
+
* Syntax: type.truncate(unit, temporal [, mapWithOverrides])
|
|
319
|
+
* Units: millennium, century, decade, year, weekYear, quarter, month, week, day, hour, minute, second, millisecond, microsecond
|
|
320
|
+
*/
|
|
321
|
+
private translateTemporalTruncate;
|
|
322
|
+
private translateDateTruncate;
|
|
323
|
+
private translateDatetimeTruncate;
|
|
324
|
+
private translateLocaldatetimeTruncate;
|
|
325
|
+
private translateTimeTruncate;
|
|
326
|
+
private translateLocaltimeTruncate;
|
|
327
|
+
private generateId;
|
|
328
|
+
}
|
|
329
|
+
export declare function translate(query: Query, params?: Record<string, unknown>): TranslationResult;
|
|
330
|
+
//# sourceMappingURL=translator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translator.d.ts","sourceRoot":"","sources":["../src/translator.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EASL,UAAU,EAkBX,MAAM,aAAa,CAAC;AA2ErB,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,iB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