@dbsp/adapter-pgsql 5.0.0 → 7.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/README.md +8 -8
- package/dist/chunk-5BBN6TPD.js +59253 -0
- package/dist/chunk-5BBN6TPD.js.map +1 -0
- package/dist/index.d.ts +317 -2088
- package/dist/index.js +783 -37156
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +599 -5
- package/dist/internal.js +47 -1
- package/dist/outcome-protocol-B3vRIj2q.d.ts +3057 -0
- package/package.json +3 -3
- package/dist/chunk-KZ3NLIZ5.js +0 -13043
- package/dist/chunk-KZ3NLIZ5.js.map +0 -1
- package/dist/outcome-protocol-CACJDzli.d.ts +0 -1088
package/dist/internal.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as _dbsp_types from '@dbsp/types';
|
|
2
|
+
import { TransitionRunMetadata, ProvenPlanShape, TransitionRunJournal, TransitionSessionClient, ModelIR, CompareOutcome, PlanAssessment, ObservationContext, ApplyResult, ApplyPolicy, ColumnListInput, ParamIntent, DialectCapabilities, WhereIntent, ExpressionIntent, NormalizedManagedStep } from '@dbsp/types';
|
|
3
|
+
import { Node } from '@pgsql/types';
|
|
4
|
+
import { an as PgLedgerTarget, T as TransitionJournalQueryable, b$ as PgOrderedLedgerLocks, c0 as PgLedgerShapeAllowance, c1 as PgLedgerPhysicalShapeOutcome, bB as readPgLedgerScopeCurrency, f as PgPhysicalModel, c2 as DeclaredNameResolver, F as FkColumnDerivation, c3 as BindingNameRegistry, c4 as QueryScope, c5 as RelationTargetProjectionRegistry, a as CompilerContext, c as PgLockedRun, d as PgOutcomeCheckpointObserver } from './outcome-protocol-B3vRIj2q.js';
|
|
5
|
+
export { c6 as ComparePgDatabaseSchemaOptions, c7 as ComparePgDeclaredAdoptionSchemaInput, c8 as CompareSchemataOptions, c9 as ConvergePgBaseOptions, ca as ConvergePgCheckOptions, e as ConvergePgOptions, cb as GenerateDDLOptions, cc as MigrationSQLOptions, cd as PgAdoptionComparisonExecutor, a9 as PgApplicationStepTx, ce as PgCommitAcknowledgementAmbiguousError, ad as PgConvergeApplicationStep, ae as PgConvergeAssertStep, h as PgConvergeCheckResult, af as PgConvergeInitializationFailure, ag as PgConvergeOnceStep, ah as PgConvergePlannedStep, aj as PgConvergeRefusalChange, ak as PgConvergeRefusalError, g as PgConvergeResult, cf as appendPgLedgerClaim, cg as appendPgLedgerClaimGroup, ch as appendPgLedgerProgress, ci as appendPgLedgerRelease, cj as appendPgLedgerResolution, ck as appendPgLedgerResolutionGroup, cl as appendPgOutcomeResolution, cm as classifyPgLedgerPhysicalShape, cn as collectReferencedKeyRemovalConflicts, co as comparePgDatabaseSchema, cp as comparePgDeclaredAdoptionSchema, cq as compareSchemata, cr as convergePg, cs as createPgDeclaredAdoptionStep, ct as createPgDeclaredSequenceAdoptionStep, cu as createPgLedgerShapeAllowance, cv as executePgDestructiveOutcome, cw as generateDDL, cx as generateDownSQL, cy as generateMigrationSQL, cz as lockPgJournalRun, cA as modelForDeclaredAdoption, cB as openPgOutcomeClaim, cC as openPgOutcomeClaimGroup, cD as pgDeclaredAdoptionDeclaration, cE as pgDeclaredSequenceAdoptionDeclaration, cF as readPgLedgerReservationsForPair, cG as recoverPgAdmittedReaddressPair, cH as recoverPgOutcomeClaim, cI as resolvePgDestructiveOutcome, cJ as resolvePgOutcomeClaimGroup } from './outcome-protocol-B3vRIj2q.js';
|
|
6
|
+
import { TransitionRunAuthorization, JsonAggOrderByEntry, ScopedApprovalSet } from '@dbsp/types/internal';
|
|
7
|
+
import { InProcessProvenPlan, ValidatedManagedStepManifest } from '@dbsp/core/internal';
|
|
8
|
+
import { Pool, PoolClient } from 'pg';
|
|
3
9
|
import '@dbsp/core';
|
|
4
|
-
import '@dbsp/core/internal';
|
|
5
|
-
import '@dbsp/types';
|
|
6
10
|
|
|
7
11
|
declare const postLockAdmissionEvidenceBrand: unique symbol;
|
|
8
12
|
/**
|
|
@@ -31,4 +35,594 @@ type PostLockAdmissionEvidenceSeams = {
|
|
|
31
35
|
declare function createPostLockAdmissionEvidence(executor: TransitionJournalQueryable, locks: PgOrderedLedgerLocks, seams?: PostLockAdmissionEvidenceSeams, allowance?: PgLedgerShapeAllowance): Promise<PostLockAdmissionEvidence>;
|
|
32
36
|
declare function isPostLockAdmissionEvidence(value: unknown): value is PostLockAdmissionEvidence;
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
/** Reads the live schema from a short-lived adapter-owned PostgreSQL session. */
|
|
39
|
+
type PgLiveSchemaReader = (client: TransitionSessionClient, schema: string | undefined) => Promise<ModelIR>;
|
|
40
|
+
interface PlanPgTransitionRunOptions {
|
|
41
|
+
/** False proves and binds a durable plan but leaves no journal record. */
|
|
42
|
+
readonly persist?: boolean;
|
|
43
|
+
/** Lets a caller prepare an inspection view before durable persistence. */
|
|
44
|
+
readonly beforePersist?: (plan: InProcessProvenPlan, proofContext: ObservationContext) => void | Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
type PgTransitionPlanResult = {
|
|
47
|
+
readonly kind: 'proven';
|
|
48
|
+
readonly compare: CompareOutcome;
|
|
49
|
+
readonly assessment: PlanAssessment;
|
|
50
|
+
readonly plan: InProcessProvenPlan;
|
|
51
|
+
readonly run: TransitionRunMetadata;
|
|
52
|
+
readonly proofContext: ObservationContext;
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: 'no-drift' | 'blocked' | 'inapplicable';
|
|
55
|
+
readonly compare: CompareOutcome;
|
|
56
|
+
readonly assessment: PlanAssessment;
|
|
57
|
+
};
|
|
58
|
+
/** The run id is available even when PostgreSQL cannot confirm persistence. */
|
|
59
|
+
declare class PgTransitionRunPersistenceIndeterminateError extends Error {
|
|
60
|
+
readonly run: TransitionRunMetadata;
|
|
61
|
+
readonly compare: CompareOutcome;
|
|
62
|
+
readonly assessment: PlanAssessment;
|
|
63
|
+
readonly persistenceError: unknown;
|
|
64
|
+
constructor(run: TransitionRunMetadata, compare: CompareOutcome, assessment: PlanAssessment, persistenceError: unknown);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Proves, binds, and optionally persists one PostgreSQL transition run.
|
|
68
|
+
* The reader sees only an adapter-owned introspection lease; all journal,
|
|
69
|
+
* evidence, and contract sessions are opened and released here.
|
|
70
|
+
*/
|
|
71
|
+
declare function planPgTransitionRun(physical: PgPhysicalModel, readLiveSchema: PgLiveSchemaReader, pool: Pool, options?: PlanPgTransitionRunOptions): Promise<PgTransitionPlanResult>;
|
|
72
|
+
type PgTransitionRunApplyResult = {
|
|
73
|
+
readonly kind: 'busy';
|
|
74
|
+
} | {
|
|
75
|
+
readonly kind: 'settled';
|
|
76
|
+
readonly result: ApplyResult;
|
|
77
|
+
};
|
|
78
|
+
interface ApplyPgTransitionRunOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Chooses a durable authorization record from a freshly read journal. Before
|
|
81
|
+
* core may execute, the adapter holds the run-row lock while it commits that
|
|
82
|
+
* exact record to this run's authorization stream, unless the same record was
|
|
83
|
+
* already present. The fresh read, choice, and commit share one transaction.
|
|
84
|
+
*/
|
|
85
|
+
readonly authorize: (input: {
|
|
86
|
+
readonly run: TransitionRunMetadata;
|
|
87
|
+
readonly plan: ProvenPlanShape;
|
|
88
|
+
readonly current: TransitionRunJournal;
|
|
89
|
+
}) => Promise<TransitionRunAuthorization>;
|
|
90
|
+
}
|
|
91
|
+
/** Applies one already-persisted, non-generator PostgreSQL transition run. */
|
|
92
|
+
declare function applyPgTransitionRun(pool: Pool, runId: string, policy: ApplyPolicy, expectedPlanDigest: string, options: ApplyPgTransitionRunOptions): Promise<PgTransitionRunApplyResult>;
|
|
93
|
+
|
|
94
|
+
type PlanExpressionOrderBy = readonly {
|
|
95
|
+
field: string;
|
|
96
|
+
direction?: 'asc' | 'desc';
|
|
97
|
+
}[];
|
|
98
|
+
interface PlanDecision {
|
|
99
|
+
readonly resolvedInclude?: _dbsp_types.ResolvedIncludeNode;
|
|
100
|
+
readonly includePredicate?: _dbsp_types.ResolvedIncludeNode['predicate'];
|
|
101
|
+
readonly type: string;
|
|
102
|
+
readonly table?: string;
|
|
103
|
+
readonly column?: string;
|
|
104
|
+
readonly alias?: string;
|
|
105
|
+
readonly field?: string;
|
|
106
|
+
readonly operator?: string;
|
|
107
|
+
readonly value?: unknown;
|
|
108
|
+
readonly paramIndex?: number;
|
|
109
|
+
readonly direction?: 'ASC' | 'DESC';
|
|
110
|
+
readonly nulls?: 'FIRST' | 'LAST';
|
|
111
|
+
readonly joinType?: 'inner' | 'left';
|
|
112
|
+
readonly sourceColumn?: ColumnListInput;
|
|
113
|
+
readonly targetColumn?: ColumnListInput;
|
|
114
|
+
readonly targetTable?: string;
|
|
115
|
+
readonly function?: string;
|
|
116
|
+
readonly distinct?: boolean;
|
|
117
|
+
readonly args?: readonly unknown[];
|
|
118
|
+
readonly conditions?: readonly PlanDecision[];
|
|
119
|
+
readonly columns?: readonly string[];
|
|
120
|
+
/** An include explicitly selected zero fields, distinct from legacy empty columns. */
|
|
121
|
+
readonly emptyProjection?: boolean;
|
|
122
|
+
/** Original include select form, retained for strategy validation. */
|
|
123
|
+
readonly includeSelectForm?: string;
|
|
124
|
+
readonly values?: readonly unknown[];
|
|
125
|
+
readonly set?: readonly {
|
|
126
|
+
column: string;
|
|
127
|
+
value: unknown;
|
|
128
|
+
}[];
|
|
129
|
+
readonly limit?: number | ParamIntent | {
|
|
130
|
+
paramIndex: number;
|
|
131
|
+
};
|
|
132
|
+
readonly offset?: number | ParamIntent | {
|
|
133
|
+
paramIndex: number;
|
|
134
|
+
};
|
|
135
|
+
readonly partitionBy?: readonly string[];
|
|
136
|
+
readonly orderBy?: PlanExpressionOrderBy | readonly JsonAggOrderByEntry[];
|
|
137
|
+
readonly dataType?: string;
|
|
138
|
+
readonly sourceTable?: string;
|
|
139
|
+
readonly relationName?: string;
|
|
140
|
+
readonly relationPath?: string;
|
|
141
|
+
readonly hydrationPrefix?: string;
|
|
142
|
+
readonly relationType?: 'belongsTo' | 'hasMany' | 'hasOne';
|
|
143
|
+
readonly foreignKey?: ColumnListInput;
|
|
144
|
+
readonly parentKey?: ColumnListInput;
|
|
145
|
+
readonly includeOrderBy?: readonly _dbsp_types.IncludeOrderByIntent[];
|
|
146
|
+
readonly orderByFallback?: boolean;
|
|
147
|
+
readonly children?: readonly PlanDecision[];
|
|
148
|
+
readonly intentPath?: string;
|
|
149
|
+
readonly choice?: string;
|
|
150
|
+
readonly subquery?: {
|
|
151
|
+
readonly from: string;
|
|
152
|
+
readonly select: string;
|
|
153
|
+
readonly where?: PlanDecision;
|
|
154
|
+
readonly limit?: number | ParamIntent;
|
|
155
|
+
readonly orderBy?: readonly {
|
|
156
|
+
field: string;
|
|
157
|
+
direction?: string;
|
|
158
|
+
}[];
|
|
159
|
+
};
|
|
160
|
+
readonly expressionType?: string;
|
|
161
|
+
readonly relation?: string;
|
|
162
|
+
readonly columnAliases?: Readonly<Record<string, string>>;
|
|
163
|
+
readonly defaultRelationColumnLabel?: boolean;
|
|
164
|
+
readonly relationColumnLabelOrigin?: 'nql';
|
|
165
|
+
readonly defaultRelationColumnLabels?: Readonly<Record<string, boolean>>;
|
|
166
|
+
readonly payloadColumnRequests?: readonly {
|
|
167
|
+
col: string;
|
|
168
|
+
alias?: string | undefined;
|
|
169
|
+
defaultLabel?: boolean | undefined;
|
|
170
|
+
nqlLabel?: boolean | undefined;
|
|
171
|
+
}[];
|
|
172
|
+
readonly payloadShape?: _dbsp_types.IncludePayloadShape;
|
|
173
|
+
readonly traversal?: string;
|
|
174
|
+
readonly pkColumn?: string;
|
|
175
|
+
readonly fkColumn?: string;
|
|
176
|
+
readonly recursiveInclude?: _dbsp_types.IncludeRecursiveOptions;
|
|
177
|
+
readonly maxDepth?: number;
|
|
178
|
+
readonly role?: string;
|
|
179
|
+
readonly jsonPath?: readonly string[];
|
|
180
|
+
readonly jsonMode?: 'json' | 'text';
|
|
181
|
+
readonly selectColumn?: string;
|
|
182
|
+
readonly aggregate?: string;
|
|
183
|
+
/**
|
|
184
|
+
* Apply DISTINCT to a scalar subquery's aggregate (e.g. AVG(DISTINCT price)).
|
|
185
|
+
* Deliberately NOT named `distinct` — that field means "this decision's own
|
|
186
|
+
* query-level DISTINCT modifier" and `assertNoDroppedDecisionModifiers`
|
|
187
|
+
* (subquery-emission.ts) rejects it as unsupported on subquery decisions.
|
|
188
|
+
*/
|
|
189
|
+
readonly aggregateDistinct?: boolean;
|
|
190
|
+
readonly subqueryOperator?: string;
|
|
191
|
+
readonly filterCondition?: PlanDecision;
|
|
192
|
+
readonly expressionIntent?: unknown;
|
|
193
|
+
readonly escape?: string;
|
|
194
|
+
readonly include?: readonly PlanDecision[];
|
|
195
|
+
readonly joinRarg?: Node;
|
|
196
|
+
readonly joinOnNode?: Node;
|
|
197
|
+
readonly batchValuesParams?: readonly unknown[];
|
|
198
|
+
/**
|
|
199
|
+
* Provenance: the ORIGINAL QueryIntent before lowering.
|
|
200
|
+
* Carried through every lowering site (convertIn, convertSubquery,
|
|
201
|
+
* normalizeToDecision, dispatchWhere, mapInSubqueryCondition) so that
|
|
202
|
+
* `buildPredicateSubquerySelect` can validate the true caller intent.
|
|
203
|
+
*
|
|
204
|
+
* Required for IN / scalar / inSubquery / notInSubquery decisions.
|
|
205
|
+
* Optional on other decision types.
|
|
206
|
+
*/
|
|
207
|
+
readonly subqueryIntent?: _dbsp_types.QueryIntent;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Any decision of type 'join'.
|
|
212
|
+
* Narrows `type` to the literal 'join' for safe switch exhaustion.
|
|
213
|
+
*/
|
|
214
|
+
interface JoinDecision extends PlanDecision {
|
|
215
|
+
readonly type: 'join';
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* A 'join' decision that carries pre-compiled PostgreSQL AST nodes.
|
|
219
|
+
* Used by both table-mode and BatchValues-mode joins when the ON condition
|
|
220
|
+
* has been compiled ahead of time in adapter-compiler-select.ts.
|
|
221
|
+
*
|
|
222
|
+
* The `joinRarg` is the right-hand RangeVar/RangeFunction; `joinOnNode` is
|
|
223
|
+
* the A_Expr tree for the ON clause.
|
|
224
|
+
*/
|
|
225
|
+
interface PrecompiledJoinDecision extends JoinDecision {
|
|
226
|
+
readonly joinRarg: Node;
|
|
227
|
+
readonly joinOnNode: Node;
|
|
228
|
+
readonly joinOnParams?: readonly unknown[];
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* A pre-compiled 'join' decision backed by a BatchValues unnest() source.
|
|
232
|
+
* `batchValuesParams` holds the arrays then the ON values, numbered locally
|
|
233
|
+
* from $1; compileJoinDecision offsets both fragments by the parameters already
|
|
234
|
+
* in the query and appends these values.
|
|
235
|
+
*/
|
|
236
|
+
interface BatchValuesJoinDecision extends PrecompiledJoinDecision {
|
|
237
|
+
readonly batchValuesParams: readonly unknown[];
|
|
238
|
+
}
|
|
239
|
+
/** Narrows a PlanDecision to JoinDecision (type === 'join'). */
|
|
240
|
+
declare function isJoinDecision(d: PlanDecision): d is JoinDecision;
|
|
241
|
+
/**
|
|
242
|
+
* Narrows a PlanDecision to PrecompiledJoinDecision.
|
|
243
|
+
* True when the join carries pre-compiled `joinRarg` + `joinOnNode` AST nodes
|
|
244
|
+
* (table mode or BatchValues mode).
|
|
245
|
+
*/
|
|
246
|
+
declare function isPrecompiledJoinDecision(d: PlanDecision): d is PrecompiledJoinDecision;
|
|
247
|
+
/**
|
|
248
|
+
* Narrows a PlanDecision to BatchValuesJoinDecision.
|
|
249
|
+
* True when the join is a BatchValues unnest() join and carries its locally
|
|
250
|
+
* numbered parameters in `batchValuesParams`.
|
|
251
|
+
*/
|
|
252
|
+
declare function isBatchValuesJoinDecision(d: PlanDecision): d is BatchValuesJoinDecision;
|
|
253
|
+
/**
|
|
254
|
+
* Simplified PlanReport for the spike
|
|
255
|
+
*/
|
|
256
|
+
interface SimplifiedPlanReport {
|
|
257
|
+
/** Legacy SELECT-expression / NQL body predicate (HAVING, CASE and FILTER still use it); issued root WHERE uses resolvedWhere. */
|
|
258
|
+
readonly rawWhere?: WhereIntent;
|
|
259
|
+
readonly resolvedWhere?: _dbsp_types.ResolvedCondition;
|
|
260
|
+
readonly expressionConditions?: readonly {
|
|
261
|
+
readonly intent: WhereIntent;
|
|
262
|
+
readonly condition: _dbsp_types.ResolvedCondition;
|
|
263
|
+
}[];
|
|
264
|
+
readonly expressionSubqueries?: readonly {
|
|
265
|
+
readonly expression: ExpressionIntent;
|
|
266
|
+
readonly body: Extract<_dbsp_types.ResolvedSubqueryBody, {
|
|
267
|
+
use: 'scalar';
|
|
268
|
+
}>;
|
|
269
|
+
}[];
|
|
270
|
+
readonly rawHaving?: WhereIntent;
|
|
271
|
+
readonly directConditions?: boolean;
|
|
272
|
+
readonly enclosingRanges?: CompilerContext['enclosingRanges'];
|
|
273
|
+
readonly rootAlias?: string;
|
|
274
|
+
readonly rootTable: string;
|
|
275
|
+
readonly decisions: readonly PlanDecision[];
|
|
276
|
+
readonly schema?: string;
|
|
277
|
+
/** If true, wrap result in SELECT EXISTS(SELECT 1 ...) AS "exists" */
|
|
278
|
+
readonly existsWrap?: boolean;
|
|
279
|
+
/** Row-level lock (FOR UPDATE/SHARE/etc.) */
|
|
280
|
+
readonly lock?: _dbsp_types.LockIntent;
|
|
281
|
+
/**
|
|
282
|
+
* When present, the FROM clause is replaced by a pre-compiled RangeFunction node
|
|
283
|
+
* (e.g. unnest() AS alias) instead of the root table rangeVar.
|
|
284
|
+
* `batchValuesFromParams` holds the parameter arrays to splice into state first.
|
|
285
|
+
*/
|
|
286
|
+
readonly batchValuesFromNode?: unknown;
|
|
287
|
+
readonly batchValuesFromParams?: readonly unknown[];
|
|
288
|
+
/** Query-local alias emitted by a BatchValues FROM source. */
|
|
289
|
+
readonly batchValuesFromAlias?: string;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Compiled query result
|
|
293
|
+
*/
|
|
294
|
+
interface CompiledResult {
|
|
295
|
+
readonly sql: string;
|
|
296
|
+
readonly parameters: readonly unknown[];
|
|
297
|
+
readonly ast: Node;
|
|
298
|
+
}
|
|
299
|
+
interface CompilerOptions {
|
|
300
|
+
readonly declaredNames?: DeclaredNameResolver;
|
|
301
|
+
readonly dbCasing?: _dbsp_types.DbCasing;
|
|
302
|
+
readonly schema?: string;
|
|
303
|
+
readonly dialectCapabilities?: DialectCapabilities;
|
|
304
|
+
/** Default primary key column name convention (default: 'id') */
|
|
305
|
+
readonly defaultPkColumnName?: string;
|
|
306
|
+
/** Convention for deriving FK column names: (tableName, pkName) => fkColumnName */
|
|
307
|
+
readonly deriveFkColumnName?: FkColumnDerivation;
|
|
308
|
+
/** ModelIR for type-aware parameter casting in WHERE clauses */
|
|
309
|
+
readonly model?: _dbsp_types.ModelIR;
|
|
310
|
+
/** Query-local CTE/binding names that must not be schema-qualified. */
|
|
311
|
+
readonly bindingNames?: BindingNameRegistry;
|
|
312
|
+
readonly scope?: QueryScope;
|
|
313
|
+
readonly relationTargetProjections?: RelationTargetProjectionRegistry;
|
|
314
|
+
}
|
|
315
|
+
declare class PlanCompiler {
|
|
316
|
+
private readonly declaredNames;
|
|
317
|
+
private readonly dbCasing;
|
|
318
|
+
private readonly schema;
|
|
319
|
+
private readonly defaultPk;
|
|
320
|
+
private readonly deriveFk;
|
|
321
|
+
private readonly model;
|
|
322
|
+
private readonly dialectCapabilities;
|
|
323
|
+
private readonly bindingNames;
|
|
324
|
+
private readonly scope;
|
|
325
|
+
private readonly relationTargetProjections;
|
|
326
|
+
/** Mutable state shared with extracted condition/value compilation functions */
|
|
327
|
+
private state;
|
|
328
|
+
/** Track root table for EXISTS FK correlation */
|
|
329
|
+
private currentRootTable;
|
|
330
|
+
/** Pending JOINs registered by filter/include strategies (flushed in compileSelect) */
|
|
331
|
+
private pendingJoins;
|
|
332
|
+
/** Raw JOIN AST nodes from include handlers (e.g., LATERAL) */
|
|
333
|
+
private rawJoins;
|
|
334
|
+
private keylessJoinProjections;
|
|
335
|
+
/** CTE nodes from include handlers (e.g., CTE strategy) */
|
|
336
|
+
private pendingCtes;
|
|
337
|
+
/** Local aliases for binding relation-column scalar subqueries. */
|
|
338
|
+
private bindingRelationColumnSubqueryIndex;
|
|
339
|
+
/**
|
|
340
|
+
* Maps relation-dotted include path → JOIN alias for multi-hop FK resolution.
|
|
341
|
+
* Populated as join decisions are compiled so later hops can find the
|
|
342
|
+
* correct source alias (e.g., 'callee.file' reads parent path 'callee').
|
|
343
|
+
*/
|
|
344
|
+
private joinAliasMap;
|
|
345
|
+
/**
|
|
346
|
+
* Immutable-before-emission mapping from a public relation qualifier to the
|
|
347
|
+
* SQL alias that is actually emitted for that relation.
|
|
348
|
+
*/
|
|
349
|
+
private visibleSqlQualifiers;
|
|
350
|
+
/** Actual FROM/JOIN namespace, before public relation paths overlay aliases. */
|
|
351
|
+
private emittedRangeQualifiers;
|
|
352
|
+
/** Projection labels are query-local and take precedence in bare ORDER BY. */
|
|
353
|
+
private projectionAliases;
|
|
354
|
+
/**
|
|
355
|
+
* Tracks all join aliases in use for the current query.
|
|
356
|
+
* Entries are stored in query-local alias space, exactly as written.
|
|
357
|
+
* Ensures no two JOINs share the same alias (DOUBLE-ALIAS prevention).
|
|
358
|
+
*/
|
|
359
|
+
private usedJoinAliases;
|
|
360
|
+
/**
|
|
361
|
+
* Query-local authority for every emitted non-root alias. Root bindings are
|
|
362
|
+
* deliberately absent: an unqualified root reference retains its historical
|
|
363
|
+
* SQL semantics, even when the root happens to be a reduced CTE.
|
|
364
|
+
*/
|
|
365
|
+
private aliasColumnAuthorities;
|
|
366
|
+
constructor(options?: CompilerOptions);
|
|
367
|
+
private childCompilerOptions;
|
|
368
|
+
/** Build immutable context for handler-based WHERE compilation */
|
|
369
|
+
private handlerCtx;
|
|
370
|
+
private relationTargetContext;
|
|
371
|
+
/** Register an emitted alias before any column-reference path can use it. */
|
|
372
|
+
private registerAliasAuthority;
|
|
373
|
+
private findAliasForLegacySourceTable;
|
|
374
|
+
private emittedJoinAlias;
|
|
375
|
+
private resolvedJoinAliases;
|
|
376
|
+
private resolveVisibleSqlQualifier;
|
|
377
|
+
/**
|
|
378
|
+
* Dispatch a PlanDecision through the unified WHERE handler system.
|
|
379
|
+
* Bridges PlanCompiler's state to handler types, calls dispatcher, syncs back.
|
|
380
|
+
*/
|
|
381
|
+
private dispatchWhere;
|
|
382
|
+
/**
|
|
383
|
+
* Recursively convert a PlanDecision (potentially with nested in+subquery
|
|
384
|
+
* or a logical group whose children contain in+subquery nodes) into a
|
|
385
|
+
* HandlerDecision suitable for the WHERE dispatcher.
|
|
386
|
+
*
|
|
387
|
+
* When a PlanDecision has operator='in'/'notIn' with a subquery object,
|
|
388
|
+
* mapToHandlerDecision loses the subquery because HandlerDecision has no
|
|
389
|
+
* `subquery` field. This method detects that pattern and converts it to the
|
|
390
|
+
* inSubquery/notInSubquery form that buildScalarSubquery expects.
|
|
391
|
+
*
|
|
392
|
+
* When the node is a logical group (whereAnd / whereOr / whereNot), each
|
|
393
|
+
* child in `conditions` / `condition` is mapped recursively so that nested
|
|
394
|
+
* IN+subquery nodes at any depth are guarded and remapped correctly, rather
|
|
395
|
+
* than falling through to mapToHandlerDecision which would silently drop the
|
|
396
|
+
* subquery and produce a malformed plain-IN binding.
|
|
397
|
+
*
|
|
398
|
+
* Called recursively so 2+ levels of nesting all work.
|
|
399
|
+
*/
|
|
400
|
+
private mapInSubqueryCondition;
|
|
401
|
+
/**
|
|
402
|
+
* Bridge PlanDecision to handler Decision and dispatch to include handler.
|
|
403
|
+
* Returns targets and optional pending joins to apply.
|
|
404
|
+
*/
|
|
405
|
+
private compileIncludeViaHandler;
|
|
406
|
+
/**
|
|
407
|
+
* Compile a simplified plan report to SQL
|
|
408
|
+
*/
|
|
409
|
+
compile(plan: SimplifiedPlanReport): CompiledResult;
|
|
410
|
+
private detectQueryType;
|
|
411
|
+
/** Build a HandlerCompilerContext for the given plan and optional alias override. */
|
|
412
|
+
private createHandlerContext;
|
|
413
|
+
/** Build a fresh HandlerCompilerState sharing the current parameter array. */
|
|
414
|
+
private createHandlerState;
|
|
415
|
+
private schemaForRangeVar;
|
|
416
|
+
private isNqlBindingRoot;
|
|
417
|
+
/** Classify a FROM target before it reaches the typed AST façade. */
|
|
418
|
+
private tableIdentifier;
|
|
419
|
+
private schemaIdentifier;
|
|
420
|
+
private allocateBindingRelationAlias;
|
|
421
|
+
private buildCorrelatedRelationRefs;
|
|
422
|
+
private bindingRelationHasCompleteManyToManyProof;
|
|
423
|
+
private bindingRelationName;
|
|
424
|
+
private bindingRelationNameLooksRecursive;
|
|
425
|
+
private compileBindingRecursiveRelationColumnSubquery;
|
|
426
|
+
private compileBindingRelationColumnSubquery;
|
|
427
|
+
private compileExpressionSubquery;
|
|
428
|
+
private compileGenericNqlFunction;
|
|
429
|
+
private compileNqlFunctionArg;
|
|
430
|
+
private compileNqlCaseExpressionArg;
|
|
431
|
+
/**
|
|
432
|
+
* Compile a SELECT-list target via expression handler.
|
|
433
|
+
* Wraps the node in a ResTarget and pushes it onto targetList.
|
|
434
|
+
*/
|
|
435
|
+
private compileSelectTarget;
|
|
436
|
+
/**
|
|
437
|
+
* Compile an includeStrategy decision and register its results.
|
|
438
|
+
* Pushes targets onto targetList, raw joins / CTEs onto instance collections.
|
|
439
|
+
*/
|
|
440
|
+
private registerIncludeCompilationResult;
|
|
441
|
+
private compileIncludeDecision;
|
|
442
|
+
private compileJoinIncludeAllocationPass;
|
|
443
|
+
/**
|
|
444
|
+
* Allocate visible SQL qualifiers before compiling a target. Only emitted
|
|
445
|
+
* joins register their public qualifier; strategies without an outer source
|
|
446
|
+
* deliberately leave their relation unavailable to qualified references.
|
|
447
|
+
*/
|
|
448
|
+
private allocateVisibleSqlQualifiers;
|
|
449
|
+
/**
|
|
450
|
+
* Fold a WHERE-family decision into an existing where expression.
|
|
451
|
+
* Returns the updated (or new) where node.
|
|
452
|
+
*/
|
|
453
|
+
private compileWhereDecision;
|
|
454
|
+
/**
|
|
455
|
+
* Flush pendingJoins and rawJoins into the FROM clause.
|
|
456
|
+
* Mutates the from array in-place.
|
|
457
|
+
*/
|
|
458
|
+
private flushPendingJoins;
|
|
459
|
+
/**
|
|
460
|
+
* Build the initial FROM clause array and register batch-values parameters.
|
|
461
|
+
* For batch-values queries, the unnest RangeFunction replaces the root rangeVar.
|
|
462
|
+
*/
|
|
463
|
+
private compileFromClause;
|
|
464
|
+
/**
|
|
465
|
+
* Fold WHERE conditions from a join-strategy include decision into the
|
|
466
|
+
* accumulated WHERE expression. The join alias is used as currentAlias so
|
|
467
|
+
* column refs like `project_id` resolve against the joined table, not root.
|
|
468
|
+
*/
|
|
469
|
+
private compileIncludeWhereConditions;
|
|
470
|
+
private reserveManualJoinAliases;
|
|
471
|
+
/**
|
|
472
|
+
* Apply a single join decision to the FROM clause in-place.
|
|
473
|
+
* Chains multiple joins by wrapping from[0] as the left-arg each time.
|
|
474
|
+
*/
|
|
475
|
+
private compileJoinDecision;
|
|
476
|
+
/**
|
|
477
|
+
* Compile a single orderBy decision into a SortBy AST node.
|
|
478
|
+
* Supports both expression-intent and plain column references.
|
|
479
|
+
*/
|
|
480
|
+
/**
|
|
481
|
+
* Compile a single orderBy decision into a SortBy AST node.
|
|
482
|
+
* Supports both expression-intent and plain column references.
|
|
483
|
+
* Returns undefined when neither expressionIntent nor column is present.
|
|
484
|
+
*/
|
|
485
|
+
private compileOrderByDecision;
|
|
486
|
+
/**
|
|
487
|
+
* Compile a column reference that may use dotted 'relation.column' notation.
|
|
488
|
+
*/
|
|
489
|
+
private compileRelationAwareColumnRef;
|
|
490
|
+
/**
|
|
491
|
+
* Compile a single groupBy decision into a ColumnRef AST node.
|
|
492
|
+
* Supports dotted 'relation.column' notation for joined tables.
|
|
493
|
+
*/
|
|
494
|
+
private compileGroupByDecision;
|
|
495
|
+
/**
|
|
496
|
+
* Compile a DISTINCT ON column into a ColumnRef AST node.
|
|
497
|
+
* Mirrors GROUP BY relation-alias resolution while preserving unqualified
|
|
498
|
+
* DISTINCT ON columns as unqualified references.
|
|
499
|
+
*/
|
|
500
|
+
private compileDistinctOnColumn;
|
|
501
|
+
/**
|
|
502
|
+
* Assemble the final SelectStmt from all accumulated clause nodes.
|
|
503
|
+
* Also handles the default SELECT *, CTEs, and row-level locking.
|
|
504
|
+
*/
|
|
505
|
+
private buildSelectStmt;
|
|
506
|
+
/**
|
|
507
|
+
* PostgreSQL does not resolve SELECT labels in HAVING. Reuse the selected
|
|
508
|
+
* aggregate's source expression when HAVING names its output alias.
|
|
509
|
+
*/
|
|
510
|
+
private resolveHavingAggregateAlias;
|
|
511
|
+
private compilePositionCondition;
|
|
512
|
+
private compileLegacyBodyWhere;
|
|
513
|
+
private compileSelect;
|
|
514
|
+
/**
|
|
515
|
+
* Wrap a SELECT statement in SELECT EXISTS(SELECT 1 ...) AS "exists"
|
|
516
|
+
*
|
|
517
|
+
* This transforms the inner SELECT by:
|
|
518
|
+
* 1. Replacing targetList with just `1` (constant)
|
|
519
|
+
* 2. Wrapping in SubLink with EXISTS_SUBLINK
|
|
520
|
+
* 3. Creating outer SELECT with EXISTS result aliased as "exists"
|
|
521
|
+
*/
|
|
522
|
+
private wrapSelectInExists;
|
|
523
|
+
private compileCaseExpression;
|
|
524
|
+
/**
|
|
525
|
+
* Compile a CASE THEN/ELSE value based on its ExpressionIntent kind.
|
|
526
|
+
* Delegates to shared resolveCaseValue with nested CASE support.
|
|
527
|
+
*/
|
|
528
|
+
private compileCaseValue;
|
|
529
|
+
/**
|
|
530
|
+
* Compile a custom ExpressionIntent (customFn, customOp, ref, cast, unary,
|
|
531
|
+
* array, function, subquery, …) to an AST node through the shared expression
|
|
532
|
+
* compiler. Shared by the `selectCustomExpression` target path and CASE
|
|
533
|
+
* THEN/ELSE values so both render the full expression surface identically.
|
|
534
|
+
*/
|
|
535
|
+
private compileCustomExpressionNode;
|
|
536
|
+
private compileInsert;
|
|
537
|
+
private compileUpdate;
|
|
538
|
+
private compileDelete;
|
|
539
|
+
private compileJoin;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Convenience function to compile a plan
|
|
543
|
+
*/
|
|
544
|
+
declare function compilePlan(plan: SimplifiedPlanReport, options?: CompilerOptions): CompiledResult;
|
|
545
|
+
|
|
546
|
+
type GeneratorExecutionExecutor = Pool | Pick<PoolClient, 'query' | 'release'>;
|
|
547
|
+
type GeneratorExecutionResult = {
|
|
548
|
+
readonly outcome: 'completed';
|
|
549
|
+
} | {
|
|
550
|
+
readonly outcome: 'partially-applied';
|
|
551
|
+
readonly detail: string;
|
|
552
|
+
readonly completedStepKeys: readonly string[];
|
|
553
|
+
readonly notStartedStepKeys: readonly string[];
|
|
554
|
+
} | {
|
|
555
|
+
readonly outcome: 'selection-incomplete';
|
|
556
|
+
readonly detail: string;
|
|
557
|
+
} | {
|
|
558
|
+
readonly outcome: 'adoption-refused';
|
|
559
|
+
readonly detail: string;
|
|
560
|
+
} | {
|
|
561
|
+
readonly outcome: 'readdress-unsupported';
|
|
562
|
+
readonly detail: string;
|
|
563
|
+
} | {
|
|
564
|
+
readonly outcome: 'readdress-refused';
|
|
565
|
+
readonly detail: string;
|
|
566
|
+
} | {
|
|
567
|
+
readonly outcome: 'destructive-authority-refused';
|
|
568
|
+
readonly detail: string;
|
|
569
|
+
/** The exact live authority that remained withheld at admission. */
|
|
570
|
+
readonly refusal?: {
|
|
571
|
+
readonly withheldAuthority: string;
|
|
572
|
+
};
|
|
573
|
+
} | {
|
|
574
|
+
readonly outcome: 'prior-step-events-refusal';
|
|
575
|
+
readonly detail: string;
|
|
576
|
+
} | {
|
|
577
|
+
readonly outcome: 'recovery-required';
|
|
578
|
+
readonly claimId: string;
|
|
579
|
+
readonly detail: string;
|
|
580
|
+
} | {
|
|
581
|
+
readonly outcome: 'transport-ambiguous';
|
|
582
|
+
readonly detail: string;
|
|
583
|
+
} | {
|
|
584
|
+
readonly outcome: 'execution-failed';
|
|
585
|
+
readonly detail: string;
|
|
586
|
+
};
|
|
587
|
+
/**
|
|
588
|
+
* Executes the in-memory, just-presented generator material. It never reads
|
|
589
|
+
* a generator run back by id: that persisted row remains review-only.
|
|
590
|
+
*/
|
|
591
|
+
declare function executeGeneratorPlan(input: {
|
|
592
|
+
/**
|
|
593
|
+
* A pg pool or checked-out PoolClient. A connected standalone pg.Client is
|
|
594
|
+
* deliberately unsupported: although session-pinned, it has no release(),
|
|
595
|
+
* and the pool/client distinction must not try to connect it again.
|
|
596
|
+
*/
|
|
597
|
+
readonly pool: GeneratorExecutionExecutor;
|
|
598
|
+
/** Bound by apply after validating the persisted durable manifest. */
|
|
599
|
+
readonly manifest?: ValidatedManagedStepManifest;
|
|
600
|
+
/** @deprecated Compatibility shim for direct fixtures; it is validated before use. */
|
|
601
|
+
readonly plan?: {
|
|
602
|
+
readonly steps: readonly unknown[];
|
|
603
|
+
};
|
|
604
|
+
readonly planDigest: string;
|
|
605
|
+
readonly schema: string;
|
|
606
|
+
/** Preserve scopes and trust roots until admission; never reduce to classes. */
|
|
607
|
+
readonly approval?: ScopedApprovalSet;
|
|
608
|
+
/** Durable witness minted while apply holds this run's journal lock. */
|
|
609
|
+
readonly run: PgLockedRun;
|
|
610
|
+
/** Appends the run-to-attempt mapping before any ledger claim may be opened. */
|
|
611
|
+
readonly recordAttempt: (executionId: string) => Promise<void>;
|
|
612
|
+
/** Test-only admitted-path observation; absent from every CLI invocation. */
|
|
613
|
+
readonly observer?: PgOutcomeCheckpointObserver;
|
|
614
|
+
/** Contiguous fresh-object steps that must commit as one PostgreSQL transaction. */
|
|
615
|
+
readonly atomicCreationGroup?: readonly string[];
|
|
616
|
+
/**
|
|
617
|
+
* Converge supplies its lock-holding canonical comparison here. The
|
|
618
|
+
* callback receives both the preflight executor and the executor inside the
|
|
619
|
+
* admitted outcome transaction, so adoption never escapes that session.
|
|
620
|
+
*/
|
|
621
|
+
readonly verifyDeclaredAdoptionShape?: (executor: TransitionJournalQueryable, step: NormalizedManagedStep) => Promise<boolean>;
|
|
622
|
+
/** @deprecated Compatibility shim for old direct fixtures. */
|
|
623
|
+
readonly accepts?: readonly string[];
|
|
624
|
+
readonly replaces?: readonly string[];
|
|
625
|
+
readonly runId: string;
|
|
626
|
+
}): Promise<GeneratorExecutionResult>;
|
|
627
|
+
|
|
628
|
+
export { type ApplyPgTransitionRunOptions, type BatchValuesJoinDecision, type CompiledResult, type CompilerOptions, type GeneratorExecutionResult, type JoinDecision, PgLedgerPhysicalShapeOutcome, PgLedgerShapeAllowance, type PgLiveSchemaReader, type PgTransitionPlanResult, type PgTransitionRunApplyResult, PgTransitionRunPersistenceIndeterminateError, PlanCompiler, type PlanDecision, type PlanPgTransitionRunOptions, type PostLockAdmissionEvidence, type PrecompiledJoinDecision, type SimplifiedPlanReport, applyPgTransitionRun, compilePlan, createPostLockAdmissionEvidence, executeGeneratorPlan, isBatchValuesJoinDecision, isJoinDecision, isPostLockAdmissionEvidence, isPrecompiledJoinDecision, planPgTransitionRun };
|