@dbsp/adapter-pgsql 1.1.1 → 1.2.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/dist/index.d.ts +42 -16
- package/dist/index.js +909 -193
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExpressionRef, IndexInfo, TruncateOptions, VacuumOptions, AlterColumnOptions, CreateIndexOptions, DropIndexOptions, ModelIR as ModelIR$1 } from '@dbsp/core';
|
|
2
2
|
export { normalizeSQL } from '@dbsp/core';
|
|
3
3
|
import * as _dbsp_types from '@dbsp/types';
|
|
4
|
-
import { DialectCapabilities, ModelIR, DbCasing, ColumnIR, HierarchyIR, Adapter, AdapterLogger, AdapterCapabilities, PlanReport, CompileOptions, CompiledQuery, CompileResultWithIncludes, SubqueryIncludeInfo, ExpressionIntent, InsertIntent, InsertFromIntent, UpdateIntent, BatchUpdateIntent, DeleteIntent, UpsertIntent, UpsertFromIntent, RecursivePlanReport, CteQueryIntent, SetOperationIntent, DumpMeta, Dump, AdapterStreamOptions, CompileOnlyAdapter, QueryIntent } from '@dbsp/types';
|
|
4
|
+
import { ParamIntent, DialectCapabilities, ModelIR, DbCasing, ColumnIR, HierarchyIR, Adapter, AdapterLogger, AdapterCapabilities, PlanReport, CompiledNqlQuery, CompileOptions, CompiledQuery, CompileResultWithIncludes, SubqueryIncludeInfo, ExpressionIntent, InsertIntent, InsertFromIntent, UpdateIntent, BatchUpdateIntent, DeleteIntent, UpsertIntent, UpsertFromIntent, RecursivePlanReport, CteQueryIntent, SetOperationIntent, DumpMeta, Dump, AdapterStreamOptions, CompileOnlyAdapter, QueryIntent } from '@dbsp/types';
|
|
5
5
|
import * as _pgsql_types from '@pgsql/types';
|
|
6
6
|
import { Node, OnConflictClause, ParamRef } from '@pgsql/types';
|
|
7
7
|
import { Pool, PoolClient } from 'pg';
|
|
@@ -117,10 +117,10 @@ interface PlanDecision {
|
|
|
117
117
|
column: string;
|
|
118
118
|
value: unknown;
|
|
119
119
|
}[];
|
|
120
|
-
readonly limit?: number | {
|
|
120
|
+
readonly limit?: number | ParamIntent | {
|
|
121
121
|
paramIndex: number;
|
|
122
122
|
};
|
|
123
|
-
readonly offset?: number | {
|
|
123
|
+
readonly offset?: number | ParamIntent | {
|
|
124
124
|
paramIndex: number;
|
|
125
125
|
};
|
|
126
126
|
readonly partitionBy?: readonly string[];
|
|
@@ -131,6 +131,8 @@ interface PlanDecision {
|
|
|
131
131
|
readonly dataType?: string;
|
|
132
132
|
readonly sourceTable?: string;
|
|
133
133
|
readonly relationName?: string;
|
|
134
|
+
readonly relationPath?: string;
|
|
135
|
+
readonly hydrationPrefix?: string;
|
|
134
136
|
readonly relationType?: 'belongsTo' | 'hasMany' | 'hasOne';
|
|
135
137
|
readonly foreignKey?: string;
|
|
136
138
|
readonly parentKey?: string;
|
|
@@ -141,7 +143,7 @@ interface PlanDecision {
|
|
|
141
143
|
readonly from: string;
|
|
142
144
|
readonly select: string;
|
|
143
145
|
readonly where?: PlanDecision;
|
|
144
|
-
readonly limit?: number;
|
|
146
|
+
readonly limit?: number | ParamIntent;
|
|
145
147
|
readonly orderBy?: readonly {
|
|
146
148
|
field: string;
|
|
147
149
|
direction?: string;
|
|
@@ -273,9 +275,9 @@ declare class PlanCompiler {
|
|
|
273
275
|
/** CTE nodes from include handlers (e.g., CTE strategy) */
|
|
274
276
|
private pendingCtes;
|
|
275
277
|
/**
|
|
276
|
-
* Maps
|
|
277
|
-
* Populated as join decisions are compiled so later hops can find
|
|
278
|
-
*
|
|
278
|
+
* Maps relation-dotted include path → JOIN alias for multi-hop FK resolution.
|
|
279
|
+
* Populated as join decisions are compiled so later hops can find the
|
|
280
|
+
* correct source alias (e.g., 'callee.file' reads parent path 'callee').
|
|
279
281
|
*/
|
|
280
282
|
private joinAliasMap;
|
|
281
283
|
/**
|
|
@@ -286,6 +288,7 @@ declare class PlanCompiler {
|
|
|
286
288
|
constructor(options?: CompilerOptions);
|
|
287
289
|
/** Build immutable context for handler-based WHERE compilation */
|
|
288
290
|
private handlerCtx;
|
|
291
|
+
private findAliasForLegacySourceTable;
|
|
289
292
|
/**
|
|
290
293
|
* Dispatch a PlanDecision through the unified WHERE handler system.
|
|
291
294
|
* Bridges PlanCompiler's state to handler types, calls dispatcher, syncs back.
|
|
@@ -324,6 +327,10 @@ declare class PlanCompiler {
|
|
|
324
327
|
private createHandlerContext;
|
|
325
328
|
/** Build a fresh HandlerCompilerState sharing the current parameter array. */
|
|
326
329
|
private createHandlerState;
|
|
330
|
+
private compileExpressionSubquery;
|
|
331
|
+
private compileGenericNqlFunction;
|
|
332
|
+
private compileNqlFunctionArg;
|
|
333
|
+
private compileNqlCaseExpressionArg;
|
|
327
334
|
/**
|
|
328
335
|
* Compile a SELECT-list target via expression handler.
|
|
329
336
|
* Wraps the node in a ResTarget and pushes it onto targetList.
|
|
@@ -1058,6 +1065,12 @@ interface CompilerContext {
|
|
|
1058
1065
|
ast: Node;
|
|
1059
1066
|
parameters: readonly unknown[];
|
|
1060
1067
|
};
|
|
1068
|
+
/**
|
|
1069
|
+
* Optional recursive compiler for NQL-origin SELECT expression values nested
|
|
1070
|
+
* inside handler arguments, such as coalesce(upper(name), :fallback) or
|
|
1071
|
+
* (price + :a) * :b.
|
|
1072
|
+
*/
|
|
1073
|
+
readonly compileNqlSelectExpression?: (value: unknown, ctx: CompilerContext, state: CompilerState) => Node;
|
|
1061
1074
|
/**
|
|
1062
1075
|
* Optional ModelIR for type-aware parameter casting.
|
|
1063
1076
|
* When provided, WHERE comparisons emit `$N::type` to eliminate
|
|
@@ -1107,15 +1120,17 @@ interface Decision {
|
|
|
1107
1120
|
column: string;
|
|
1108
1121
|
value: unknown;
|
|
1109
1122
|
}[];
|
|
1110
|
-
readonly limit?: number | {
|
|
1123
|
+
readonly limit?: number | ParamIntent | {
|
|
1111
1124
|
paramIndex: number;
|
|
1112
1125
|
};
|
|
1113
|
-
readonly offset?: number | {
|
|
1126
|
+
readonly offset?: number | ParamIntent | {
|
|
1114
1127
|
paramIndex: number;
|
|
1115
1128
|
};
|
|
1116
1129
|
readonly strategy?: 'join' | 'lateral' | 'json_agg' | 'cte';
|
|
1117
1130
|
readonly relation?: string;
|
|
1118
1131
|
readonly relationName?: string;
|
|
1132
|
+
readonly relationPath?: string;
|
|
1133
|
+
readonly hydrationPrefix?: string;
|
|
1119
1134
|
readonly include?: readonly Decision[];
|
|
1120
1135
|
readonly relationType?: 'belongsTo' | 'hasMany' | 'hasOne';
|
|
1121
1136
|
readonly foreignKey?: string;
|
|
@@ -1144,7 +1159,7 @@ interface Decision {
|
|
|
1144
1159
|
readonly expandRelation?: string;
|
|
1145
1160
|
readonly relationColumns?: readonly string[];
|
|
1146
1161
|
readonly columnAliases?: Readonly<Record<string, string>>;
|
|
1147
|
-
readonly jsonPath?: readonly
|
|
1162
|
+
readonly jsonPath?: readonly unknown[];
|
|
1148
1163
|
readonly jsonMode?: 'json' | 'text';
|
|
1149
1164
|
readonly _compiledFilterWhere?: _pgsql_types.Node;
|
|
1150
1165
|
readonly filterWhere?: _pgsql_types.Node;
|
|
@@ -1190,6 +1205,13 @@ type WhereDispatcher = (decision: Decision, ctx: CompilerContext, state: Compile
|
|
|
1190
1205
|
interface ExpressionHandler {
|
|
1191
1206
|
/** Expression type(s) this handler supports */
|
|
1192
1207
|
readonly types: readonly string[];
|
|
1208
|
+
/**
|
|
1209
|
+
* Safe to use when a function name comes from NQL text.
|
|
1210
|
+
*
|
|
1211
|
+
* Raw/escape-hatch handlers must not set this. NQL-origin function names use
|
|
1212
|
+
* this opt-in surface only, then fall back to generic FuncCall emission.
|
|
1213
|
+
*/
|
|
1214
|
+
readonly nqlSafe?: boolean;
|
|
1193
1215
|
/**
|
|
1194
1216
|
* Compile an expression to AST.
|
|
1195
1217
|
* @param decision The expression decision
|
|
@@ -1585,6 +1607,10 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
|
|
|
1585
1607
|
*/
|
|
1586
1608
|
private cloneOptions;
|
|
1587
1609
|
private buildCompileDeps;
|
|
1610
|
+
private requireNqlCompileModel;
|
|
1611
|
+
private compileNqlMutation;
|
|
1612
|
+
private compileNqlBundleLeaf;
|
|
1613
|
+
private compileNqlBundle;
|
|
1588
1614
|
/**
|
|
1589
1615
|
* Returns the pool/client executor, or throws if in compile-only mode.
|
|
1590
1616
|
*/
|
|
@@ -1604,7 +1630,7 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
|
|
|
1604
1630
|
/**
|
|
1605
1631
|
* Compile a plan to executable SQL.
|
|
1606
1632
|
*/
|
|
1607
|
-
compile<T = unknown>(plan: PlanReport, options?: CompileOptions): CompiledQuery<T>;
|
|
1633
|
+
compile<T = unknown>(plan: PlanReport | CompiledNqlQuery, options?: CompileOptions): CompiledQuery<T>;
|
|
1608
1634
|
/**
|
|
1609
1635
|
* Compile a plan with includes, returning subquery include metadata (DX-033).
|
|
1610
1636
|
*/
|
|
@@ -1685,7 +1711,7 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
|
|
|
1685
1711
|
/**
|
|
1686
1712
|
* Compile a set operation (UNION / INTERSECT / EXCEPT) to SQL.
|
|
1687
1713
|
*/
|
|
1688
|
-
compileSetOperation(intent: SetOperationIntent, model: ModelIR,
|
|
1714
|
+
compileSetOperation(intent: SetOperationIntent, model: ModelIR, options?: CompileOptions): CompiledQuery;
|
|
1689
1715
|
/**
|
|
1690
1716
|
* Create a dump for observability.
|
|
1691
1717
|
*/
|
|
@@ -1964,7 +1990,7 @@ declare function compileSetOperation(intent: SetOperationIntent, compileFn: Leaf
|
|
|
1964
1990
|
* @param planFn - The plan() function from @dbsp/core
|
|
1965
1991
|
*/
|
|
1966
1992
|
declare function createLeafCompileFn(adapter: {
|
|
1967
|
-
compile(plan: PlanReport, options: {
|
|
1993
|
+
compile(plan: PlanReport, options: CompileOptions & {
|
|
1968
1994
|
model: ModelIR$1;
|
|
1969
1995
|
}): {
|
|
1970
1996
|
sql: string;
|
|
@@ -1973,7 +1999,7 @@ declare function createLeafCompileFn(adapter: {
|
|
|
1973
1999
|
dialectCapabilities: DialectCapabilities;
|
|
1974
2000
|
}, model: ModelIR$1, planFn: (intent: QueryIntent, model: ModelIR$1, options: {
|
|
1975
2001
|
dialectCapabilities: DialectCapabilities;
|
|
1976
|
-
}) => PlanReport): LeafCompileFn;
|
|
2002
|
+
}) => PlanReport, options?: CompileOptions): LeafCompileFn;
|
|
1977
2003
|
|
|
1978
2004
|
/**
|
|
1979
2005
|
* Cursor-Based Streaming Support
|
|
@@ -2158,10 +2184,10 @@ declare class InvalidIdentifierError extends Error {
|
|
|
2158
2184
|
* 6. Reserved keywords are allowed (will be quoted)
|
|
2159
2185
|
*
|
|
2160
2186
|
* @param value The identifier to validate
|
|
2161
|
-
* @param type Type of identifier (for error messages): 'table', 'column', 'schema', 'alias'
|
|
2187
|
+
* @param type Type of identifier (for error messages): 'table', 'column', 'schema', 'alias', 'function'
|
|
2162
2188
|
* @throws InvalidIdentifierError if validation fails
|
|
2163
2189
|
*/
|
|
2164
|
-
declare function validateIdentifier(value: string, type: 'table' | 'column' | 'schema' | 'alias'): void;
|
|
2190
|
+
declare function validateIdentifier(value: string, type: 'table' | 'column' | 'schema' | 'alias' | 'function'): void;
|
|
2165
2191
|
/**
|
|
2166
2192
|
* Check if an identifier is a SQL reserved keyword.
|
|
2167
2193
|
*/
|