@dbsp/adapter-pgsql 1.1.1 → 1.2.1
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 +50 -16
- package/dist/index.js +996 -215
- 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,19 +275,23 @@ 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
|
/**
|
|
282
284
|
* Tracks all join aliases in use for the current query.
|
|
285
|
+
* Entries are stored in emitted database-alias space, after naming.toDatabase().
|
|
283
286
|
* Ensures no two JOINs share the same alias (DOUBLE-ALIAS prevention).
|
|
284
287
|
*/
|
|
285
288
|
private usedJoinAliases;
|
|
286
289
|
constructor(options?: CompilerOptions);
|
|
287
290
|
/** Build immutable context for handler-based WHERE compilation */
|
|
288
291
|
private handlerCtx;
|
|
292
|
+
private findAliasForLegacySourceTable;
|
|
293
|
+
private emittedJoinAlias;
|
|
294
|
+
private resolvedJoinAliases;
|
|
289
295
|
/**
|
|
290
296
|
* Dispatch a PlanDecision through the unified WHERE handler system.
|
|
291
297
|
* Bridges PlanCompiler's state to handler types, calls dispatcher, syncs back.
|
|
@@ -324,6 +330,10 @@ declare class PlanCompiler {
|
|
|
324
330
|
private createHandlerContext;
|
|
325
331
|
/** Build a fresh HandlerCompilerState sharing the current parameter array. */
|
|
326
332
|
private createHandlerState;
|
|
333
|
+
private compileExpressionSubquery;
|
|
334
|
+
private compileGenericNqlFunction;
|
|
335
|
+
private compileNqlFunctionArg;
|
|
336
|
+
private compileNqlCaseExpressionArg;
|
|
327
337
|
/**
|
|
328
338
|
* Compile a SELECT-list target via expression handler.
|
|
329
339
|
* Wraps the node in a ResTarget and pushes it onto targetList.
|
|
@@ -333,7 +343,9 @@ declare class PlanCompiler {
|
|
|
333
343
|
* Compile an includeStrategy decision and register its results.
|
|
334
344
|
* Pushes targets onto targetList, raw joins / CTEs onto instance collections.
|
|
335
345
|
*/
|
|
346
|
+
private registerIncludeCompilationResult;
|
|
336
347
|
private compileIncludeDecision;
|
|
348
|
+
private compileJoinIncludeAllocationPass;
|
|
337
349
|
/**
|
|
338
350
|
* Fold a WHERE-family decision into an existing where expression.
|
|
339
351
|
* Returns the updated (or new) where node.
|
|
@@ -355,6 +367,7 @@ declare class PlanCompiler {
|
|
|
355
367
|
* column refs like `project_id` resolve against the joined table, not root.
|
|
356
368
|
*/
|
|
357
369
|
private compileIncludeWhereConditions;
|
|
370
|
+
private reserveManualJoinAliases;
|
|
358
371
|
/**
|
|
359
372
|
* Apply a single join decision to the FROM clause in-place.
|
|
360
373
|
* Chains multiple joins by wrapping from[0] as the left-arg each time.
|
|
@@ -1035,6 +1048,8 @@ interface CompilerContext {
|
|
|
1035
1048
|
readonly rootTable: string;
|
|
1036
1049
|
/** Current table alias (for JOINs) */
|
|
1037
1050
|
readonly currentAlias?: string;
|
|
1051
|
+
/** Final relation path/name → SQL join alias map for relation-aware expression contexts */
|
|
1052
|
+
readonly aliases?: ReadonlyMap<string, string>;
|
|
1038
1053
|
/** Maximum recursive depth (default: 100) */
|
|
1039
1054
|
readonly maxRecursiveDepth: number;
|
|
1040
1055
|
/** Optional callback for raw SQL audit trail */
|
|
@@ -1058,6 +1073,12 @@ interface CompilerContext {
|
|
|
1058
1073
|
ast: Node;
|
|
1059
1074
|
parameters: readonly unknown[];
|
|
1060
1075
|
};
|
|
1076
|
+
/**
|
|
1077
|
+
* Optional recursive compiler for NQL-origin SELECT expression values nested
|
|
1078
|
+
* inside handler arguments, such as coalesce(upper(name), :fallback) or
|
|
1079
|
+
* (price + :a) * :b.
|
|
1080
|
+
*/
|
|
1081
|
+
readonly compileNqlSelectExpression?: (value: unknown, ctx: CompilerContext, state: CompilerState) => Node;
|
|
1061
1082
|
/**
|
|
1062
1083
|
* Optional ModelIR for type-aware parameter casting.
|
|
1063
1084
|
* When provided, WHERE comparisons emit `$N::type` to eliminate
|
|
@@ -1107,15 +1128,17 @@ interface Decision {
|
|
|
1107
1128
|
column: string;
|
|
1108
1129
|
value: unknown;
|
|
1109
1130
|
}[];
|
|
1110
|
-
readonly limit?: number | {
|
|
1131
|
+
readonly limit?: number | ParamIntent | {
|
|
1111
1132
|
paramIndex: number;
|
|
1112
1133
|
};
|
|
1113
|
-
readonly offset?: number | {
|
|
1134
|
+
readonly offset?: number | ParamIntent | {
|
|
1114
1135
|
paramIndex: number;
|
|
1115
1136
|
};
|
|
1116
1137
|
readonly strategy?: 'join' | 'lateral' | 'json_agg' | 'cte';
|
|
1117
1138
|
readonly relation?: string;
|
|
1118
1139
|
readonly relationName?: string;
|
|
1140
|
+
readonly relationPath?: string;
|
|
1141
|
+
readonly hydrationPrefix?: string;
|
|
1119
1142
|
readonly include?: readonly Decision[];
|
|
1120
1143
|
readonly relationType?: 'belongsTo' | 'hasMany' | 'hasOne';
|
|
1121
1144
|
readonly foreignKey?: string;
|
|
@@ -1144,7 +1167,7 @@ interface Decision {
|
|
|
1144
1167
|
readonly expandRelation?: string;
|
|
1145
1168
|
readonly relationColumns?: readonly string[];
|
|
1146
1169
|
readonly columnAliases?: Readonly<Record<string, string>>;
|
|
1147
|
-
readonly jsonPath?: readonly
|
|
1170
|
+
readonly jsonPath?: readonly unknown[];
|
|
1148
1171
|
readonly jsonMode?: 'json' | 'text';
|
|
1149
1172
|
readonly _compiledFilterWhere?: _pgsql_types.Node;
|
|
1150
1173
|
readonly filterWhere?: _pgsql_types.Node;
|
|
@@ -1190,6 +1213,13 @@ type WhereDispatcher = (decision: Decision, ctx: CompilerContext, state: Compile
|
|
|
1190
1213
|
interface ExpressionHandler {
|
|
1191
1214
|
/** Expression type(s) this handler supports */
|
|
1192
1215
|
readonly types: readonly string[];
|
|
1216
|
+
/**
|
|
1217
|
+
* Safe to use when a function name comes from NQL text.
|
|
1218
|
+
*
|
|
1219
|
+
* Raw/escape-hatch handlers must not set this. NQL-origin function names use
|
|
1220
|
+
* this opt-in surface only, then fall back to generic FuncCall emission.
|
|
1221
|
+
*/
|
|
1222
|
+
readonly nqlSafe?: boolean;
|
|
1193
1223
|
/**
|
|
1194
1224
|
* Compile an expression to AST.
|
|
1195
1225
|
* @param decision The expression decision
|
|
@@ -1585,6 +1615,10 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
|
|
|
1585
1615
|
*/
|
|
1586
1616
|
private cloneOptions;
|
|
1587
1617
|
private buildCompileDeps;
|
|
1618
|
+
private requireNqlCompileModel;
|
|
1619
|
+
private compileNqlMutation;
|
|
1620
|
+
private compileNqlBundleLeaf;
|
|
1621
|
+
private compileNqlBundle;
|
|
1588
1622
|
/**
|
|
1589
1623
|
* Returns the pool/client executor, or throws if in compile-only mode.
|
|
1590
1624
|
*/
|
|
@@ -1604,7 +1638,7 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
|
|
|
1604
1638
|
/**
|
|
1605
1639
|
* Compile a plan to executable SQL.
|
|
1606
1640
|
*/
|
|
1607
|
-
compile<T = unknown>(plan: PlanReport, options?: CompileOptions): CompiledQuery<T>;
|
|
1641
|
+
compile<T = unknown>(plan: PlanReport | CompiledNqlQuery, options?: CompileOptions): CompiledQuery<T>;
|
|
1608
1642
|
/**
|
|
1609
1643
|
* Compile a plan with includes, returning subquery include metadata (DX-033).
|
|
1610
1644
|
*/
|
|
@@ -1685,7 +1719,7 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
|
|
|
1685
1719
|
/**
|
|
1686
1720
|
* Compile a set operation (UNION / INTERSECT / EXCEPT) to SQL.
|
|
1687
1721
|
*/
|
|
1688
|
-
compileSetOperation(intent: SetOperationIntent, model: ModelIR,
|
|
1722
|
+
compileSetOperation(intent: SetOperationIntent, model: ModelIR, options?: CompileOptions): CompiledQuery;
|
|
1689
1723
|
/**
|
|
1690
1724
|
* Create a dump for observability.
|
|
1691
1725
|
*/
|
|
@@ -1964,7 +1998,7 @@ declare function compileSetOperation(intent: SetOperationIntent, compileFn: Leaf
|
|
|
1964
1998
|
* @param planFn - The plan() function from @dbsp/core
|
|
1965
1999
|
*/
|
|
1966
2000
|
declare function createLeafCompileFn(adapter: {
|
|
1967
|
-
compile(plan: PlanReport, options: {
|
|
2001
|
+
compile(plan: PlanReport, options: CompileOptions & {
|
|
1968
2002
|
model: ModelIR$1;
|
|
1969
2003
|
}): {
|
|
1970
2004
|
sql: string;
|
|
@@ -1973,7 +2007,7 @@ declare function createLeafCompileFn(adapter: {
|
|
|
1973
2007
|
dialectCapabilities: DialectCapabilities;
|
|
1974
2008
|
}, model: ModelIR$1, planFn: (intent: QueryIntent, model: ModelIR$1, options: {
|
|
1975
2009
|
dialectCapabilities: DialectCapabilities;
|
|
1976
|
-
}) => PlanReport): LeafCompileFn;
|
|
2010
|
+
}) => PlanReport, options?: CompileOptions): LeafCompileFn;
|
|
1977
2011
|
|
|
1978
2012
|
/**
|
|
1979
2013
|
* Cursor-Based Streaming Support
|
|
@@ -2158,10 +2192,10 @@ declare class InvalidIdentifierError extends Error {
|
|
|
2158
2192
|
* 6. Reserved keywords are allowed (will be quoted)
|
|
2159
2193
|
*
|
|
2160
2194
|
* @param value The identifier to validate
|
|
2161
|
-
* @param type Type of identifier (for error messages): 'table', 'column', 'schema', 'alias'
|
|
2195
|
+
* @param type Type of identifier (for error messages): 'table', 'column', 'schema', 'alias', 'function'
|
|
2162
2196
|
* @throws InvalidIdentifierError if validation fails
|
|
2163
2197
|
*/
|
|
2164
|
-
declare function validateIdentifier(value: string, type: 'table' | 'column' | 'schema' | 'alias'): void;
|
|
2198
|
+
declare function validateIdentifier(value: string, type: 'table' | 'column' | 'schema' | 'alias' | 'function'): void;
|
|
2165
2199
|
/**
|
|
2166
2200
|
* Check if an identifier is a SQL reserved keyword.
|
|
2167
2201
|
*/
|