turbine-orm 0.49.0 → 0.50.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 +122 -39
- package/dist/cjs/adapters/cockroachdb.d.ts +39 -0
- package/dist/cjs/adapters/index.d.ts +110 -0
- package/dist/cjs/adapters/yugabytedb.d.ts +51 -0
- package/dist/cjs/cli/config.d.ts +181 -0
- package/dist/cjs/cli/config.js +32 -6
- package/dist/cjs/cli/destructive.d.ts +38 -0
- package/dist/cjs/cli/index.d.ts +359 -0
- package/dist/cjs/cli/index.js +228 -56
- package/dist/cjs/cli/loader.d.ts +61 -0
- package/dist/cjs/cli/mcp.d.ts +42 -0
- package/dist/cjs/cli/migrate.d.ts +356 -0
- package/dist/cjs/cli/migrate.js +131 -40
- package/dist/cjs/cli/observe-ui.d.ts +1 -0
- package/dist/cjs/cli/observe-ui.js +14 -5
- package/dist/cjs/cli/observe.d.ts +25 -0
- package/dist/cjs/cli/observe.js +49 -12
- package/dist/cjs/cli/pii-tags.d.ts +53 -0
- package/dist/cjs/cli/prisma-report.d.ts +33 -0
- package/dist/cjs/cli/prisma-report.js +73 -0
- package/dist/cjs/cli/prisma-resolve.d.ts +106 -0
- package/dist/cjs/cli/prisma-resolve.js +1 -0
- package/dist/cjs/cli/prisma-schema.d.ts +176 -0
- package/dist/cjs/cli/prisma-schema.js +82 -4
- package/dist/cjs/cli/rate-limit.d.ts +32 -0
- package/dist/cjs/cli/rate-limit.js +45 -0
- package/dist/cjs/cli/studio-demo.d.ts +43 -0
- package/dist/cjs/cli/studio-ui.generated.d.ts +1 -0
- package/dist/cjs/cli/studio.d.ts +207 -0
- package/dist/cjs/cli/studio.js +136 -71
- package/dist/cjs/cli/ui.d.ts +73 -0
- package/dist/cjs/cli/ui.js +51 -9
- package/dist/cjs/client.d.ts +837 -0
- package/dist/cjs/client.js +3 -0
- package/dist/cjs/dialect.d.ts +516 -0
- package/dist/cjs/dialect.js +37 -12
- package/dist/cjs/errors.d.ts +370 -0
- package/dist/cjs/generate.d.ts +137 -0
- package/dist/cjs/generate.js +39 -6
- package/dist/cjs/index-advisor.d.ts +153 -0
- package/dist/cjs/index-stats.d.ts +384 -0
- package/dist/cjs/index.d.ts +55 -0
- package/dist/cjs/index.js +7 -2
- package/dist/cjs/introspect.d.ts +269 -0
- package/dist/cjs/mssql.d.ts +232 -0
- package/dist/cjs/mssql.js +6 -0
- package/dist/cjs/mysql.d.ts +173 -0
- package/dist/cjs/mysql.js +16 -0
- package/dist/cjs/nested-write.d.ts +96 -0
- package/dist/cjs/nested-write.js +414 -24
- package/dist/cjs/observe.d.ts +115 -0
- package/dist/cjs/optional-peer-import.d.cts +72 -0
- package/dist/cjs/pipeline-submittable.d.ts +93 -0
- package/dist/cjs/pipeline.d.ts +71 -0
- package/dist/cjs/powdb-introspect.d.ts +84 -0
- package/dist/cjs/powdb.d.ts +931 -0
- package/dist/cjs/powdb.js +106 -21
- package/dist/cjs/powql.d.ts +592 -0
- package/dist/cjs/powql.js +42 -6
- package/dist/cjs/prisma-compat.d.ts +283 -0
- package/dist/cjs/prisma-compat.js +167 -9
- package/dist/cjs/query/aggregates.d.ts +92 -0
- package/dist/cjs/query/aggregates.js +7 -3
- package/dist/cjs/query/batched-loader.d.ts +193 -0
- package/dist/cjs/query/builder.d.ts +849 -0
- package/dist/cjs/query/builder.js +571 -65
- package/dist/cjs/query/compound-unique.d.ts +51 -0
- package/dist/cjs/query/deferred.d.ts +223 -0
- package/dist/cjs/query/filters.d.ts +201 -0
- package/dist/cjs/query/index.d.ts +14 -0
- package/dist/cjs/query/index.js +6 -1
- package/dist/cjs/query/relations.d.ts +609 -0
- package/dist/cjs/query/relations.js +693 -46
- package/dist/cjs/query/types.d.ts +1300 -0
- package/dist/cjs/query/utils.d.ts +209 -0
- package/dist/cjs/query/utils.js +208 -1
- package/dist/cjs/query/warn-registry.d.ts +68 -0
- package/dist/cjs/query/warn-registry.js +9 -0
- package/dist/cjs/query/where-compile.d.ts +139 -0
- package/dist/cjs/query/where.d.ts +548 -0
- package/dist/cjs/query/where.js +58 -22
- package/dist/cjs/query/writes.d.ts +172 -0
- package/dist/cjs/query/writes.js +105 -12
- package/dist/cjs/realtime.d.ts +70 -0
- package/dist/cjs/schema-builder.d.ts +354 -0
- package/dist/cjs/schema-metadata.d.ts +83 -0
- package/dist/cjs/schema-sql.d.ts +217 -0
- package/dist/cjs/schema-sql.js +23 -5
- package/dist/cjs/schema.d.ts +356 -0
- package/dist/cjs/schema.js +125 -0
- package/dist/cjs/seed.d.ts +15 -0
- package/dist/cjs/serverless.d.ts +142 -0
- package/dist/cjs/sqlite.d.ts +143 -0
- package/dist/cjs/sqlite.js +4 -0
- package/dist/cjs/typed-sql.d.ts +102 -0
- package/dist/cli/config.d.ts +18 -4
- package/dist/cli/config.js +31 -6
- package/dist/cli/index.d.ts +123 -0
- package/dist/cli/index.js +223 -58
- package/dist/cli/migrate.d.ts +59 -10
- package/dist/cli/migrate.js +128 -41
- package/dist/cli/observe-ui.d.ts +1 -1
- package/dist/cli/observe-ui.js +14 -5
- package/dist/cli/observe.d.ts +7 -1
- package/dist/cli/observe.js +48 -12
- package/dist/cli/prisma-report.d.ts +14 -0
- package/dist/cli/prisma-report.js +72 -0
- package/dist/cli/prisma-resolve.d.ts +6 -0
- package/dist/cli/prisma-resolve.js +1 -0
- package/dist/cli/prisma-schema.d.ts +62 -2
- package/dist/cli/prisma-schema.js +81 -4
- package/dist/cli/rate-limit.d.ts +32 -0
- package/dist/cli/rate-limit.js +40 -0
- package/dist/cli/studio.d.ts +5 -5
- package/dist/cli/studio.js +135 -70
- package/dist/cli/ui.d.ts +1 -1
- package/dist/cli/ui.js +51 -9
- package/dist/client.d.ts +40 -0
- package/dist/client.js +3 -0
- package/dist/dialect.d.ts +17 -1
- package/dist/dialect.js +37 -12
- package/dist/generate.js +40 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mssql.js +6 -0
- package/dist/mysql.js +16 -0
- package/dist/nested-write.d.ts +2 -0
- package/dist/nested-write.js +415 -25
- package/dist/powdb.d.ts +4 -2
- package/dist/powdb.js +106 -21
- package/dist/powql.d.ts +5 -0
- package/dist/powql.js +42 -6
- package/dist/prisma-compat.d.ts +2 -0
- package/dist/prisma-compat.js +166 -8
- package/dist/query/aggregates.js +7 -3
- package/dist/query/builder.d.ts +292 -21
- package/dist/query/builder.js +570 -64
- package/dist/query/deferred.d.ts +39 -0
- package/dist/query/index.d.ts +1 -1
- package/dist/query/index.js +1 -1
- package/dist/query/relations.d.ts +173 -5
- package/dist/query/relations.js +688 -47
- package/dist/query/types.d.ts +123 -39
- package/dist/query/utils.d.ts +116 -0
- package/dist/query/utils.js +198 -0
- package/dist/query/warn-registry.d.ts +9 -0
- package/dist/query/warn-registry.js +9 -0
- package/dist/query/where.d.ts +38 -1
- package/dist/query/where.js +58 -23
- package/dist/query/writes.d.ts +42 -1
- package/dist/query/writes.js +104 -13
- package/dist/schema-sql.d.ts +14 -0
- package/dist/schema-sql.js +23 -5
- package/dist/schema.d.ts +38 -0
- package/dist/schema.js +123 -0
- package/dist/sqlite.js +4 -0
- package/package.json +77 -28
package/dist/query/deferred.d.ts
CHANGED
|
@@ -155,6 +155,45 @@ export interface QueryInterfaceOptions {
|
|
|
155
155
|
* byte-identical to before. SQL engines only (PowDB keeps its own defaults).
|
|
156
156
|
*/
|
|
157
157
|
stableRelationOrder?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* When `true`, a `findMany` that paginates (`limit` / `take` / `offset`) but
|
|
160
|
+
* declares no `orderBy` is ordered by the table's primary key ascending
|
|
161
|
+
* (every column of a composite PK, in declaration order), making its pages
|
|
162
|
+
* deterministic. An explicit `orderBy` always wins, PK-less tables are left
|
|
163
|
+
* alone, and `distinct` / `cursor` shapes are skipped.
|
|
164
|
+
*
|
|
165
|
+
* Default `false` in core: an unordered `LIMIT` is non-deterministic, but
|
|
166
|
+
* adding an `ORDER BY` to SQL that existing applications already emit changes
|
|
167
|
+
* both the rows a page returns and the plan the engine picks, so the fix is
|
|
168
|
+
* opt-in until a major. `turbine-orm/prisma-compat` defaults it ON, since
|
|
169
|
+
* matching Prisma's semantics is that layer's contract. When off, the emitted
|
|
170
|
+
* SQL is byte-identical to before.
|
|
171
|
+
*/
|
|
172
|
+
implicitPkOrdering?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Parent-row ceiling for the `relationLoadStrategy: 'auto'` to-one rule: a
|
|
175
|
+
* to-one relation stays in the single-statement join when the query's `limit`
|
|
176
|
+
* bounds the parent set at or under this many rows, and loads batched when the
|
|
177
|
+
* query is unbounded or bounded above it (a correlated to-one subquery is
|
|
178
|
+
* re-evaluated per parent row regardless of indexing). Defaults to
|
|
179
|
+
* `AUTO_TO_ONE_JOIN_MAX_ROWS` (1000); `0` sends every unbounded-or-limited
|
|
180
|
+
* to-one relation batched. Ignored under an explicit `'join'` / `'batched'`.
|
|
181
|
+
*/
|
|
182
|
+
autoToOneJoinMaxRows?: number;
|
|
183
|
+
/**
|
|
184
|
+
* Round-trip time to the database, in milliseconds, used to DERIVE the
|
|
185
|
+
* `relationLoadStrategy: 'auto'` to-one threshold instead of guessing a row
|
|
186
|
+
* count. Prefer this over `autoToOneJoinMaxRows`: the break-even between the
|
|
187
|
+
* single-statement join and the batched follow-up is
|
|
188
|
+
* `roundTripMs / AUTO_JOIN_PENALTY_MS_PER_ROW`, and measurement shows the
|
|
189
|
+
* per-row penalty is a constant of the plan while the break-even moves ~17x
|
|
190
|
+
* between a loopback link and a 2.7ms one. Set it to what `ping` says (a
|
|
191
|
+
* Unix socket is ~0.05, same-region managed Postgres ~0.5-2, cross-region
|
|
192
|
+
* ~30-60). Defaults to `AUTO_ASSUMED_ROUND_TRIP_MS` (0.7ms, same-region),
|
|
193
|
+
* which reproduces the historical 1000-row threshold exactly. Overridden by
|
|
194
|
+
* an explicit `autoToOneJoinMaxRows`; only consulted under `'auto'`.
|
|
195
|
+
*/
|
|
196
|
+
autoRoundTripMs?: number;
|
|
158
197
|
/**
|
|
159
198
|
* How nested-relation subqueries encode each row's JSON: `'object'` (default,
|
|
160
199
|
* `json_build_object`) or `'positional'` (`json_build_array`, key-less — see
|
package/dist/query/index.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ export { postgresDialect } from '../dialect.js';
|
|
|
11
11
|
export type { SqlCacheEntry } from './utils.js';
|
|
12
12
|
export { buildCorrelation, escapeLike, escSingleQuote, fnv1a64Hex, LRUCache, OPERATOR_KEYS, quoteIdent, sqlToPreparedName, } from './utils.js';
|
|
13
13
|
export type { DeferredQuery, MiddlewareFn, QueryEvent, QueryEventListener, QueryInterfaceOptions, ReselectExecutor, } from './builder.js';
|
|
14
|
-
export { QueryInterface } from './builder.js';
|
|
14
|
+
export { AUTO_ASSUMED_ROUND_TRIP_MS, AUTO_JOIN_PENALTY_MS_PER_ROW, AUTO_TO_ONE_JOIN_MAX_ROWS, AUTO_TO_ONE_JOIN_ROWS_MAX, AUTO_TO_ONE_JOIN_ROWS_MIN, QueryInterface, } from './builder.js';
|
package/dist/query/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { postgresDialect } from '../dialect.js';
|
|
9
9
|
export { buildCorrelation, escapeLike, escSingleQuote, fnv1a64Hex, LRUCache, OPERATOR_KEYS, quoteIdent, sqlToPreparedName, } from './utils.js';
|
|
10
|
-
export { QueryInterface } from './builder.js';
|
|
10
|
+
export { AUTO_ASSUMED_ROUND_TRIP_MS, AUTO_JOIN_PENALTY_MS_PER_ROW, AUTO_TO_ONE_JOIN_MAX_ROWS, AUTO_TO_ONE_JOIN_ROWS_MAX, AUTO_TO_ONE_JOIN_ROWS_MIN, QueryInterface, } from './builder.js';
|
|
@@ -49,7 +49,7 @@ export declare function withFingerprint(qi: BuilderCtx, withClause: WithClause |
|
|
|
49
49
|
* Collect params from a `with` clause tree. Mirrors buildSelectWithRelations +
|
|
50
50
|
* buildRelationSubquery param-push order.
|
|
51
51
|
*/
|
|
52
|
-
export declare function collectWithParams(qi: BuilderCtx, withClause: WithClause, params: unknown[], table?: string): void;
|
|
52
|
+
export declare function collectWithParams(qi: BuilderCtx, withClause: WithClause, params: unknown[], table?: string, flattenPlan?: FlattenPlan | null): void;
|
|
53
53
|
/**
|
|
54
54
|
* Collect params from a single relation subquery. Mirrors buildRelationSubquery.
|
|
55
55
|
*/
|
|
@@ -229,8 +229,19 @@ export declare function collectManyToManyTargetGlobalFilter(qi: BuilderCtx, relD
|
|
|
229
229
|
*/
|
|
230
230
|
export declare function collectRelationCountParams(qi: BuilderCtx, relDef: RelationDef, params: unknown[]): void;
|
|
231
231
|
export declare function getCamelDateFields(qi: BuilderCtx, table: string, meta: TableMetadata): Set<string>;
|
|
232
|
-
/**
|
|
233
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Parse a row that may contain JSON nested relation columns.
|
|
234
|
+
*
|
|
235
|
+
* `fromJson` says where THIS row's own scalar columns came from. A root row
|
|
236
|
+
* (join, batched, flatten) is read straight off the driver, so `false`; a row
|
|
237
|
+
* decoded out of a `json_agg`/`json_build_object` column is `true` and gets
|
|
238
|
+
* its divergent scalars decoded back to the driver's representation first (see
|
|
239
|
+
* the JSON-wire section above). Recursion into a relation column is always
|
|
240
|
+
* `true`, which is exactly right on every strategy: `batched` and `flatten`
|
|
241
|
+
* hand this function driver rows, but any relation still nested INSIDE one of
|
|
242
|
+
* those rows arrived as a correlated JSON subquery.
|
|
243
|
+
*/
|
|
244
|
+
export declare function parseNestedRow(qi: BuilderCtx, row: Record<string, unknown>, table: string, fromJson?: boolean): Record<string, unknown>;
|
|
234
245
|
/**
|
|
235
246
|
* Resolve the emitted column list for a relation, honoring `select` / `omit`.
|
|
236
247
|
* Shared by {@link buildRelationSubquery} (json order) and
|
|
@@ -262,7 +273,7 @@ export declare function buildRelationShape(qi: BuilderCtx, relDef: RelationDef,
|
|
|
262
273
|
* positional arrays into the object form first (shapes built once, not per
|
|
263
274
|
* row), then delegates to parseNestedRow for date/snake-camel coercion.
|
|
264
275
|
*/
|
|
265
|
-
export declare function makeNestedParser(qi: BuilderCtx, withClause: WithClause, includePii?: boolean): (row: Record<string, unknown>) => Record<string, unknown>;
|
|
276
|
+
export declare function makeNestedParser(qi: BuilderCtx, withClause: WithClause, includePii?: boolean, flattenPlan?: FlattenPlan | null): (row: Record<string, unknown>) => Record<string, unknown>;
|
|
266
277
|
/**
|
|
267
278
|
* Return a shallow copy of a top-level row with each relation column decoded
|
|
268
279
|
* from its positional array(s) into the object representation. Only relation
|
|
@@ -279,6 +290,160 @@ export declare function decodePositionalRelations(qi: BuilderCtx, row: Record<st
|
|
|
279
290
|
export declare function decodePositionalValue(qi: BuilderCtx, raw: unknown, shape: RelationShape): unknown;
|
|
280
291
|
/** Map one positional array back to a keyed object using the shape's key order. */
|
|
281
292
|
export declare function decodePositionalObject(qi: BuilderCtx, arr: unknown, shape: RelationShape): unknown;
|
|
293
|
+
/** One relation `'flatten'` declined, with the reason, for the dev warning. */
|
|
294
|
+
export interface FlattenReject {
|
|
295
|
+
/** Dotted path from the root table's `with`, e.g. `order.customer`. */
|
|
296
|
+
relation: string;
|
|
297
|
+
reason: string;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* One entry in a flattened relation's nested `with`, in
|
|
301
|
+
* `sortedEntries(spec.with)` order. `'flat'` is another LEFT JOIN; `'json'` is
|
|
302
|
+
* a correlated subquery projected as a single JSON column, exactly as the
|
|
303
|
+
* default strategy would have emitted it (with the join alias as its parent
|
|
304
|
+
* reference). Ordering is preserved so the assembled object's key order matches
|
|
305
|
+
* the join strategy's byte for byte.
|
|
306
|
+
*/
|
|
307
|
+
export interface FlattenSlot {
|
|
308
|
+
relName: string;
|
|
309
|
+
kind: 'flat' | 'json';
|
|
310
|
+
}
|
|
311
|
+
/** A single to-one relation compiled as a LEFT JOIN plus a prefixed projection. */
|
|
312
|
+
export interface FlattenNode {
|
|
313
|
+
relName: string;
|
|
314
|
+
relDef: RelationDef;
|
|
315
|
+
spec: true | WithOptions;
|
|
316
|
+
targetTable: string;
|
|
317
|
+
targetMeta: TableMetadata;
|
|
318
|
+
/** Output-name prefix, and the derived-table alias for a top-level node (`f0`). */
|
|
319
|
+
alias: string;
|
|
320
|
+
/** Alias of the real target table inside the derived table (`f0s`). */
|
|
321
|
+
srcAlias: string;
|
|
322
|
+
/** Target-side correlation columns (provably unique — see {@link provableUniqueTargetKey}). */
|
|
323
|
+
keyColumns: string[];
|
|
324
|
+
/**
|
|
325
|
+
* Match discriminator. A top-level node projects the constant `1` (its
|
|
326
|
+
* derived-table row exists only when the target matched, and the outer LEFT
|
|
327
|
+
* JOIN null-extends it otherwise); a nested node projects the predicate
|
|
328
|
+
* `(src.key IS NOT NULL)`. Either way the discriminator carries no cell
|
|
329
|
+
* VALUE, so a PII-tagged key column never leaves the database merely because
|
|
330
|
+
* a discriminator was needed: no PII column enters the wire, the projection
|
|
331
|
+
* or the assembled object unless the caller selected it or passed
|
|
332
|
+
* `includePii`. Without it, "the join matched nothing" would be
|
|
333
|
+
* indistinguishable from "the row exists and every projected column is NULL".
|
|
334
|
+
*/
|
|
335
|
+
discAlias: string;
|
|
336
|
+
/** `[snake_case column, output alias]` for every projected column. */
|
|
337
|
+
cols: [column: string, sqlAlias: string][];
|
|
338
|
+
/** Nested `with` entries in emission order. */
|
|
339
|
+
slots: FlattenSlot[];
|
|
340
|
+
/** Nested flattened relations, keyed by relation name (the `'flat'` slots). */
|
|
341
|
+
children: Record<string, FlattenNode>;
|
|
342
|
+
/** Output alias of each `'json'` slot's correlated subquery column. */
|
|
343
|
+
jsonAliases: Record<string, string>;
|
|
344
|
+
/**
|
|
345
|
+
* Top-level nodes only: the correlation columns re-exposed by the derived
|
|
346
|
+
* table (`f0__$c0`, ...) so the OUTER join condition can reference them
|
|
347
|
+
* without the real column names entering the outer scope. Never surfaced to
|
|
348
|
+
* the caller.
|
|
349
|
+
*/
|
|
350
|
+
corrAliases: string[];
|
|
351
|
+
/** Nesting depth, matching {@link buildRelationSubquery}'s depth accounting. */
|
|
352
|
+
depth: number;
|
|
353
|
+
/** Breadcrumb trail for {@link CircularRelationError} parity. */
|
|
354
|
+
path: string[];
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* The compiled `'flatten'` plan for one `with` clause: which top-level
|
|
358
|
+
* relations become LEFT JOINs, and a signature that keys the SQL template
|
|
359
|
+
* cache. Relations absent from `nodes` compile exactly as they do today.
|
|
360
|
+
*/
|
|
361
|
+
export interface FlattenPlan {
|
|
362
|
+
nodes: Record<string, FlattenNode>;
|
|
363
|
+
/** Every SELECT-list alias the plan introduces (flat rows carry them all). */
|
|
364
|
+
aliases: string[];
|
|
365
|
+
/** Structural signature for the `fl=` SQL-cache-key segment. */
|
|
366
|
+
signature: string;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* The target-side correlation columns of a to-one relation, but ONLY when the
|
|
370
|
+
* schema PROVES they are unique on the target table. This is the row-
|
|
371
|
+
* multiplication guard: a LEFT JOIN over a non-unique key silently duplicates
|
|
372
|
+
* parent rows, which would change results rather than just the plan.
|
|
373
|
+
*
|
|
374
|
+
* Proof sources, all exact set matches (a unique index on `(a, b)` does NOT
|
|
375
|
+
* make `a` unique):
|
|
376
|
+
* - the target's primary key,
|
|
377
|
+
* - a declared unique constraint (`uniqueColumns`),
|
|
378
|
+
* - a full, non-expression UNIQUE index. Partial unique indexes are refused
|
|
379
|
+
* (they only constrain the rows matching their predicate) and PowDB
|
|
380
|
+
* doc-field expression indexes are refused (they index a JSON path, not the
|
|
381
|
+
* raw column).
|
|
382
|
+
*
|
|
383
|
+
* Returns `null` for to-many / manyToMany relations and for anything it cannot
|
|
384
|
+
* prove, which routes the relation back to the correlated subquery.
|
|
385
|
+
*
|
|
386
|
+
* NULLs need no special handling: a unique constraint permits repeated NULLs,
|
|
387
|
+
* but `target.key = parent.fk` never matches a NULL key, so a null-keyed target
|
|
388
|
+
* row can never join.
|
|
389
|
+
*/
|
|
390
|
+
export declare function provableUniqueTargetKey(relDef: RelationDef, targetMeta: TableMetadata): string[] | null;
|
|
391
|
+
/**
|
|
392
|
+
* Compile the `'flatten'` plan for a top-level `with` clause, or return `null`
|
|
393
|
+
* when nothing in it is eligible (in which case the caller emits exactly the SQL
|
|
394
|
+
* it emits today, down to the cache key).
|
|
395
|
+
*
|
|
396
|
+
* The plan is a pure function of the schema, the `with` clause shape and
|
|
397
|
+
* `includePii` — never of any bound value — so the build path, the cache-hit
|
|
398
|
+
* param-collect path and the row assembler can each recompute it and agree.
|
|
399
|
+
*/
|
|
400
|
+
export declare function planFlattenWith(qi: BuilderCtx, table: string, withClause: WithClause, includePii?: boolean): FlattenPlan | null;
|
|
401
|
+
/**
|
|
402
|
+
* Emit one TOP-LEVEL flattened relation: a derived table holding its whole
|
|
403
|
+
* to-one subtree, joined to the parent on the re-exposed correlation columns,
|
|
404
|
+
* plus the pass-through projection of every name that subtree contributes.
|
|
405
|
+
*
|
|
406
|
+
* ```sql
|
|
407
|
+
* LEFT JOIN (
|
|
408
|
+
* SELECT 1 AS "f0__$k", f0s."id" AS "f0__$c0",
|
|
409
|
+
* f0s."id" AS "f0__id", f0s."name" AS "f0__name",
|
|
410
|
+
* (f1s."id" IS NOT NULL) AS "f1__$k", f1s."code" AS "f1__code"
|
|
411
|
+
* FROM "orgs" f0s
|
|
412
|
+
* LEFT JOIN "regions" f1s ON f1s."id" = f0s."region_id"
|
|
413
|
+
* WHERE f0s."deleted" = $1
|
|
414
|
+
* ) f0 ON f0."f0__$c0" = "users"."org_id"
|
|
415
|
+
* ```
|
|
416
|
+
*
|
|
417
|
+
* See the derived-table note above for why the join cannot expose the target's
|
|
418
|
+
* real column names.
|
|
419
|
+
*/
|
|
420
|
+
export declare function emitFlattenNode(qi: BuilderCtx, node: FlattenNode, parentRef: string, params: unknown[], joinSink: string[], selectSink: string[], aliasCounter: {
|
|
421
|
+
n: number;
|
|
422
|
+
}, includePii?: boolean): void;
|
|
423
|
+
/** Param-collect mirror of {@link emitFlattenNode}. */
|
|
424
|
+
export declare function collectFlattenNodeParams(qi: BuilderCtx, node: FlattenNode, params: unknown[]): void;
|
|
425
|
+
/**
|
|
426
|
+
* Rebuild one flattened relation's object from a flat row.
|
|
427
|
+
*
|
|
428
|
+
* Returns `null` when the discriminator is NULL (the LEFT JOIN matched
|
|
429
|
+
* nothing), which is the ONLY signal that distinguishes "no related row" from
|
|
430
|
+
* "a related row whose every projected column is NULL".
|
|
431
|
+
*
|
|
432
|
+
* The sub-row is keyed by the target's raw snake_case column names and handed
|
|
433
|
+
* to {@link parseNestedRow}, so the flattened object goes through the very same
|
|
434
|
+
* camelCase mapping, Date coercion and nested-JSON parsing the join strategy's
|
|
435
|
+
* `json_build_object` output does. Nested flattened relations are assigned
|
|
436
|
+
* after the parse, over placeholder keys inserted in slot order, so the
|
|
437
|
+
* assembled object's key order matches the join strategy's exactly.
|
|
438
|
+
*/
|
|
439
|
+
export declare function assembleFlattenNode(qi: BuilderCtx, row: Record<string, unknown>, node: FlattenNode): Record<string, unknown> | null;
|
|
440
|
+
/**
|
|
441
|
+
* Row parser for a `'flatten'` plan: strip the prefixed join columns out of the
|
|
442
|
+
* flat row (inserting a placeholder at the position each relation's block
|
|
443
|
+
* started, so key order is preserved), parse the remainder exactly as the join
|
|
444
|
+
* strategy does, then assemble each flattened relation.
|
|
445
|
+
*/
|
|
446
|
+
export declare function makeFlattenParser(qi: BuilderCtx, plan: FlattenPlan): (row: Record<string, unknown>) => Record<string, unknown>;
|
|
282
447
|
/**
|
|
283
448
|
* Build a SELECT clause that includes both base columns and nested relation subqueries.
|
|
284
449
|
*
|
|
@@ -320,7 +485,10 @@ export declare function decodePositionalObject(qi: BuilderCtx, arr: unknown, sha
|
|
|
320
485
|
* @returns A complete SELECT clause string (without the `SELECT` keyword) containing
|
|
321
486
|
* base columns and relation subqueries.
|
|
322
487
|
*/
|
|
323
|
-
export declare function buildSelectWithRelations(qi: BuilderCtx, table: string, withClause: WithClause, params: unknown[], columnsList?: string[] | null, depth?: number, path?: string[], includePii?: boolean
|
|
488
|
+
export declare function buildSelectWithRelations(qi: BuilderCtx, table: string, withClause: WithClause, params: unknown[], columnsList?: string[] | null, depth?: number, path?: string[], includePii?: boolean, flatten?: {
|
|
489
|
+
plan: FlattenPlan;
|
|
490
|
+
joinSink: string[];
|
|
491
|
+
}): string;
|
|
324
492
|
/**
|
|
325
493
|
* Generate a correlated subquery that returns JSON for a single relation.
|
|
326
494
|
*
|