@voltro/database 0.83.1 → 0.85.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 CHANGED
@@ -1,15 +1,17 @@
1
- import { ConfigError } from 'effect';
1
+ import { Config } from 'effect';
2
2
  import { Context } from 'effect';
3
+ import { Duration } from 'effect/Duration';
3
4
  import { Effect } from 'effect';
4
5
  import { Exit } from 'effect';
5
6
  import { Layer } from 'effect';
6
7
  import { Schedule } from 'effect';
7
8
  import { Schema } from 'effect';
8
- import { SqlClient } from '@effect/sql';
9
- import { SqlError } from '@effect/sql';
10
- import { Statement } from '@effect/sql';
9
+ import { SqlClient } from 'effect/sql';
10
+ import { SqlError } from 'effect/sql/SqlError';
11
+ import { SqlError as SqlError_2 } from 'effect/sql';
12
+ import { Statement } from 'effect/sql';
11
13
  import { Stream } from 'effect';
12
- import { TransactionConnection } from '@effect/sql/SqlClient';
14
+ import { TransactionConnection } from 'effect/sql/SqlClient';
13
15
  import { VoidIfEmpty } from 'effect/Types';
14
16
  import { YieldableError } from 'effect/Cause';
15
17
 
@@ -271,7 +273,7 @@ export declare const authoredError: (sentence: string, options?: {
271
273
  * error carries none — which is the case for everything a driver threw.
272
274
  *
273
275
  * Walks the same two structures `storeRefusalOf` does: every branch of an
274
- * Effect `Cause` (a `FiberFailure` hides its tree behind a symbol, so `.cause`
276
+ * Effect `Cause` (an `Exit` keeps its reasons in a list, so `.cause`
275
277
  * alone sees nothing), and then each branch's own `.cause` chain, because a
276
278
  * driver layer may have wrapped the refusal before Effect saw it. The FIRST
277
279
  * marked error wins — the outermost is the one that describes the operation
@@ -458,6 +460,11 @@ export declare interface BranchIndexName {
458
460
  * re-derived name is exactly what we do not know. */
459
461
  readonly columns: ReadonlyArray<string>;
460
462
  readonly unique: boolean;
463
+ /** A partial index's predicate as the parent's catalog prints it
464
+ * (`pg_get_expr`). Two indexes on the same columns — one plain, one
465
+ * `WHERE "readAt" IS NULL` — are told apart only by it; without it the
466
+ * restore can give each the other's name. */
467
+ readonly where?: string;
461
468
  /** The name the PARENT's index carries, and the one to restore. */
462
469
  readonly name: string;
463
470
  }
@@ -638,13 +645,13 @@ export declare type CaughtUpVerdict = 'caught-up' | 'behind';
638
645
  /**
639
646
  * Expand an error into the concrete failures behind it.
640
647
  *
641
- * A `FiberFailure` carries an Effect `Cause`, which is a TREE — a failure and a
642
- * defect and an interrupt can all be present at once — so following `.cause`
643
- * from the outside reaches none of them. Exported because anything that wants to
644
- * find something INSIDE a thrown Effect error needs this same expansion, and a
645
- * second copy of it is a second definition that nothing keeps in step. (Learned
646
- * the direct way: a framework refusal marked on an error was invisible to a
647
- * plain `.cause` walk the moment it came back through `runPromise`.)
648
+ * A `Cause` holds a flat list of reasons — a failure and a defect and an
649
+ * interrupt can all be present at once — so following `.cause` from the outside
650
+ * reaches none of them. Exported because anything that wants to find something
651
+ * INSIDE a failed Effect needs this same expansion, and a second copy of it is a
652
+ * second definition that nothing keeps in step. (Learned the direct way: a
653
+ * framework refusal marked on an error was invisible to a plain `.cause` walk
654
+ * the moment it came back through a promise boundary.)
648
655
  */
649
656
  export declare const causeBranches: (err: unknown, depth?: number) => ReadonlyArray<unknown>;
650
657
 
@@ -1018,9 +1025,11 @@ export declare class ColumnBuilder<TsType, Type extends ColumnType, HasDefault e
1018
1025
  private rejectIfRaw;
1019
1026
  nullable(): ColumnBuilder<TsType | null, Type, HasDefault>;
1020
1027
  /**
1021
- * Declare that this scalar id points outside the app's local database graph.
1028
+ * Declare that this scalar id has no single database foreign key target.
1022
1029
  * Use it for provider, gateway, hardware, polymorphic, or cross-installation
1023
1030
  * identifiers that intentionally must not become `reference()` columns.
1031
+ * A polymorphic target may live in this same database. The application
1032
+ * validates the target and cleans up orphans.
1024
1033
  * This is schema metadata only and does not change the SQL column.
1025
1034
  */
1026
1035
  externalId(): this;
@@ -1265,7 +1274,7 @@ export declare class ColumnBuilder<TsType, Type extends ColumnType, HasDefault e
1265
1274
  *
1266
1275
  * Two flavors:
1267
1276
  *
1268
- * - **SQL** (preferred, 95% case): pass an `@effect/sql` `Statement.Fragment`
1277
+ * - **SQL** (preferred, 95% case): pass an `effect/sql` `Statement.Fragment`
1269
1278
  * (a sql`...` template built with `Statement.make`), evaluated
1270
1279
  * server-side. Single round-trip, transactional, scales linearly.
1271
1280
  *
@@ -1478,7 +1487,8 @@ export declare interface ColumnDefinition<TsType, Type extends ColumnType = Colu
1478
1487
  */
1479
1488
  readonly fkAutoIndex?: boolean;
1480
1489
  /**
1481
- * This id-shaped scalar names something outside the local relational graph.
1490
+ * This id-shaped scalar deliberately has no single foreign key target,
1491
+ * including external-system ids and local polymorphic targets.
1482
1492
  * Set by `.externalId()` so schema audits do not guess a local FK from the
1483
1493
  * column name. Metadata only; it emits no constraint or DDL.
1484
1494
  */
@@ -1637,6 +1647,14 @@ export declare interface ColumnDefinition<TsType, Type extends ColumnType = Colu
1637
1647
  * column is just `bytes` with server-merge semantics.
1638
1648
  */
1639
1649
  readonly crdtManaged?: boolean;
1650
+ /**
1651
+ * End-to-end-sealed CRDT marker, set by `crdtSealed()`. The column holds an
1652
+ * append-only LOG of encrypted CRDT updates the server cannot read: the
1653
+ * write path appends an incoming frame (or applies a client's snapshot
1654
+ * frame) and never decodes or merges — clients holding the key do. Same
1655
+ * `bytes` storage and zero DDL churn as `crdtManaged`.
1656
+ */
1657
+ readonly crdtSealed?: boolean;
1640
1658
  /**
1641
1659
  * Optimistic-concurrency marker, set by `.version()`.
1642
1660
  *
@@ -1694,6 +1712,7 @@ export declare interface ColumnDefinition<TsType, Type extends ColumnType = Colu
1694
1712
  * MUST be `<= precision`. See {@link ColumnDefinition.precision}.
1695
1713
  */
1696
1714
  readonly scale?: number;
1715
+ /* Excluded from this release type: sqliteDecimalEncoding */
1697
1716
  /**
1698
1717
  * Vector dimensionality. Populated only when `type === 'vector'`.
1699
1718
  * The migration emitter uses it to size the column DDL —
@@ -1861,7 +1880,7 @@ export declare interface ColumnReference {
1861
1880
  * value through unchanged, so the mapping looked right in any test that only
1862
1881
  * checked a round trip. Take definitions from `table.fields`.
1863
1882
  */
1864
- export declare const columnSchema: <TsType, C extends ColumnType>(def: ColumnDefinition<TsType, C>) => Schema.Schema.Any;
1883
+ export declare const columnSchema: <TsType, C extends ColumnType>(def: ColumnDefinition<TsType, C>) => Schema.Top;
1865
1884
 
1866
1885
  /**
1867
1886
  * A column as seen by the planner: either declared in code (extracted
@@ -1965,6 +1984,10 @@ declare interface ColumnSnapshot {
1965
1984
  */
1966
1985
  readonly precision?: number;
1967
1986
  readonly scale?: number;
1987
+ /** Physical SQLite-family exact-decimal representation. Absent on ordinary
1988
+ * NUMERIC columns. The marker is observable schema state, not a DSL hint:
1989
+ * changing it requires data conversion, never a plain SQL type cast. */
1990
+ readonly sqliteDecimalEncoding?: 'sortable-v1';
1968
1991
  /**
1969
1992
  * Id-generation scheme for `type: 'id'` columns. Mirrors
1970
1993
  * `ColumnDefinition.idScheme.kind` so the applier can tell a numeric
@@ -2122,6 +2145,9 @@ export declare const columnsPerRow: (rows: ReadonlyArray<Record<string, unknown>
2122
2145
 
2123
2146
  export declare type ColumnType = 'id' | 'text' | 'integer' | 'real' | 'decimal' | 'bigint' | 'boolean' | 'timestamp' | 'date' | 'json' | 'bytes' | 'reference' | 'vector' | 'enum' | 'array' | 'interval' | 'raw';
2124
2147
 
2148
+ /** The explicit committed-buffer identity, absent for ordinary/CDC events. */
2149
+ export declare const committedChangeBatchOf: (event: ChangeEvent) => object | undefined;
2150
+
2125
2151
  /** Exact comparison of fixed-point decimal strings, without a floating-point conversion. */
2126
2152
  export declare const compareDecimal: (left: unknown, right: unknown) => number | null;
2127
2153
 
@@ -2157,24 +2183,8 @@ export declare const compileEagerJson: (descriptor: QueryDescriptor, sql: SqlCon
2157
2183
  */
2158
2184
  export declare const compileJsonPatch: (sql: SqlConstructor, dialect: DialectId, path: string, value: unknown, source?: Statement.Fragment) => Statement.Fragment;
2159
2185
 
2160
- /**
2161
- * Lower a `Predicate` AST to a SQL `Fragment` suitable for use inside a
2162
- * WHERE clause. Identifiers are quoted via `sql(col)`; values flow through
2163
- * `sql\`${v}\`` as parameters — no string concatenation, no injection.
2164
- */
2165
- export declare const compilePredicate: (predicate: Predicate, sql: SqlConstructor, namespace?: QueryNamespace,
2166
- /**
2167
- * The table this predicate filters, when the caller knows it. Supplied so a
2168
- * leaf's VALUE can be coerced to the column's shape — `eq('capturedAt',
2169
- * epochMs)` against a `timestamp()` column otherwise compiles to
2170
- * `WHERE capturedAt = 1767916800000` and matches nothing, silently. The write
2171
- * path has always encoded; this closes the asymmetry.
2172
- *
2173
- * Optional because `compilePredicate` is also called for JOIN conditions and
2174
- * by callers that hold only the AST. Absent → no coercion, i.e. exactly the
2175
- * previous behaviour.
2176
- */
2177
- table?: string) => Statement.Fragment;
2186
+ /** Compile a standalone predicate; SELECT supplies its own lexical CTE scope. */
2187
+ export declare const compilePredicate: (predicate: Predicate, sql: SqlConstructor, namespace?: QueryNamespace, table?: string) => Statement.Fragment;
2178
2188
 
2179
2189
  /**
2180
2190
  * Rebind a captured {@link RawSqlFragment} onto a live `sql`
@@ -2193,6 +2203,7 @@ export declare const compileRawFragment: <Row extends object = Record<string, un
2193
2203
  * Shared by SELECT and DML RETURNING; other dialects retain native projection. */
2194
2204
  export declare const compileRowProjection: (table: string, sql: SqlConstructor, projection?: ReadonlyArray<string>) => Statement.Fragment;
2195
2205
 
2206
+ /** Compile a public query descriptor; recursive CTE terms use their SQL scope. */
2196
2207
  export declare const compileSelect: <Row extends object>(descriptor: QueryDescriptor, sql: SqlConstructor, namespace?: QueryNamespace) => Statement.Statement<Row>;
2197
2208
 
2198
2209
  /** Compose the durable identity written to `_voltro_cdcout_claims.changeKey`. */
@@ -2259,7 +2270,7 @@ export declare interface ConnectionConfig {
2259
2270
  * timer). The waiting half is UNBOUNDED by default and deliberately so —
2260
2271
  * see {@link ConnectionConfig.acquireQueueLimit} for the length bound
2261
2272
  * that exists, why it is opt-in, and what it costs.
2262
- * - **mssql** — establishment only. Maps to `@effect/sql-mssql`'s
2273
+ * - **mssql** — establishment only. Maps to `effect/sql-mssql`'s
2263
2274
  * `connectTimeout` (tedious connect + the boot `SELECT 1` probe); its
2264
2275
  * pool is an Effect `Pool` whose `get` has no timeout knob.
2265
2276
  * - **sqlite** — ignored. One in-process connection, no pool to exhaust.
@@ -2287,7 +2298,7 @@ export declare interface ConnectionConfig {
2287
2298
  * The event loop is never reached again: no timer fires, nothing drains the
2288
2299
  * queue that caused the rejection, and nothing is logged.
2289
2300
  *
2290
- * That caller is not hypothetical and not ours to fix: `@effect/cluster`
2301
+ * That caller is not hypothetical and not ours to fix: `effect/cluster`
2291
2302
  * releases shards one statement per shard (300 by default) and wraps each in
2292
2303
  * `Effect.eventually` — retry until success, no schedule, no delay, logged at
2293
2304
  * debug. On a `shardLockDisableAdvisory` (Galera / PXC) runner those releases
@@ -2316,7 +2327,7 @@ export declare interface ConnectionConfig {
2316
2327
  * node-postgres' `statement_timeout` pool option — a runaway query is cancelled
2317
2328
  * with SQLSTATE 57014, not merely disconnected. Every OTHER dialect currently
2318
2329
  * ACCEPTS the field but IGNORES it, and the honest reasons differ:
2319
- * - **mssql** — `@effect/sql-mssql` exposes only `connectTimeout` (connection
2330
+ * - **mssql** — `effect/sql-mssql` exposes only `connectTimeout` (connection
2320
2331
  * establishment), not tedious's per-request `requestTimeout`; mapping this
2321
2332
  * onto `connectTimeout` would bound the wrong phase, so it is left unwired
2322
2333
  * rather than wrong.
@@ -2413,6 +2424,22 @@ export declare const count: (alias?: string) => AggregateColumn<number>;
2413
2424
 
2414
2425
  export declare const countDistinct: (column: string, alias?: string) => AggregateColumn<number>;
2415
2426
 
2427
+ /**
2428
+ * A CONVERGING COUNTER column — likes, stock reservations, votes, a running
2429
+ * total — that any number of clients increment and decrement concurrently,
2430
+ * offline too, without losing a single step. A plain `integer()` column read,
2431
+ * incremented and written back by two clients at once keeps one of the two
2432
+ * increments; this keeps both.
2433
+ *
2434
+ * Each writer (one client session) accumulates its own increments and
2435
+ * decrements under its own key, and the value is the sum over all writers, so
2436
+ * concurrent steps commute. Storage, nullability and the authoritative server
2437
+ * merge are those of `crdtText()` — the column stores the encoded CRDT state
2438
+ * as `bytes`. Read the number with `@voltro/local-first`'s
2439
+ * `crdtCounterValue(state)`; bind it in React with `useCrdtCounter`.
2440
+ */
2441
+ export declare const crdtCounter: () => ColumnBuilder<Uint8Array | null, "bytes">;
2442
+
2416
2443
  /**
2417
2444
  * A whole collaborative DOCUMENT as a column — rich text, nested maps/arrays,
2418
2445
  * whatever the CRDT backend's document model holds. `crdtText()` is the
@@ -2450,6 +2477,22 @@ export declare const crdtManagedColumns: (table: TableLike) => ReadonlyArray<str
2450
2477
  * folds and the capture paths (undo, row history) exclude. */
2451
2478
  export declare const crdtManagedColumnsOf: (table: TableLike) => ReadonlyArray<string>;
2452
2479
 
2480
+ /**
2481
+ * An END-TO-END ENCRYPTED collaborative column: clients encrypt every CRDT
2482
+ * update with a key the server never sees (AES-GCM, `@voltro/local-first`'s
2483
+ * `seal` option on `useCrdtText` / `useCrdtDoc` / `useCrdtCounter`), and the
2484
+ * server stores an append-only log of the sealed frames. It cannot read,
2485
+ * validate or merge the content — clients decrypt and merge locally, which is
2486
+ * why the convergence still holds — and a client's snapshot frame compacts the
2487
+ * log without losing a frame appended concurrently.
2488
+ *
2489
+ * Trade-offs, by construction: `crdt.validate` and server-side restore cannot
2490
+ * see the content, and the downstream lane ships the log, not an increment.
2491
+ * The size limits still apply. Choose it for content the operator must not be
2492
+ * able to read.
2493
+ */
2494
+ export declare const crdtSealed: () => ColumnBuilder<Uint8Array | null, "bytes">;
2495
+
2453
2496
  /**
2454
2497
  * CRDT-managed text column — a field whose value is a CONFLICT-FREE replicated
2455
2498
  * text document rather than a plain string. Two clients editing it at the same
@@ -3122,19 +3165,20 @@ export declare interface DbOpSample {
3122
3165
  }
3123
3166
 
3124
3167
  /**
3125
- * Fixed-point exact-decimal column — money, tax rates, anything where
3126
- * floating-point rounding is unacceptable. Emits `NUMERIC(precision, scale)`
3127
- * on postgres and `DECIMAL(precision, scale)` on mysql / mariadb / mssql;
3128
- * sqlite / turso have no fixed-point type, so it's `NUMERIC` affinity storing
3129
- * the value as text.
3168
+ * Fixed-point exact-decimal column for money, tax rates and other values
3169
+ * that must not pass through floating-point arithmetic. Emits
3170
+ * `NUMERIC(precision, scale)` on postgres and `DECIMAL(precision, scale)`
3171
+ * on mysql / mariadb / mssql. SQLite, native Turso and libSQL use exact,
3172
+ * order-preserving encoded TEXT storage, including declared defaults.
3173
+ * Existing NUMERIC columns require a reviewed offline conversion.
3130
3174
  *
3131
- * The row type is **`string`**, NOT `number`, on purpose: a JS `number` is an
3132
- * IEEE-754 double and silently loses precision past ~15-17 significant digits
3133
- * (`0.1 + 0.2 !== 0.3`), so a `DECIMAL(38,9)` value round-tripped through a JS
3134
- * number would corrupt. The drivers already hand these back as strings
3135
- * (node-postgres, mysql2), and the row decoder coerces the mssql numeric back
3136
- * to a string, so the value is lossless end-to-end. Do arithmetic with a
3137
- * decimal library (or in SQL), not JS `+`.
3175
+ * The row type is **`string`**, NOT `number`: JavaScript numbers lose
3176
+ * precision beyond roughly 15–17 significant digits. SQLite-family stores
3177
+ * encode writes and decode reads at the declared scale. MSSQL's driver
3178
+ * can already have rounded large values before string decoding; use a
3179
+ * text projection for values beyond the driver's numeric precision.
3180
+ * Use a decimal library or supported typed query-builder operations for
3181
+ * arithmetic. Raw SQL must not treat encoded TEXT as a decimal number.
3138
3182
  *
3139
3183
  * ```ts
3140
3184
  * price: decimal(12, 2), // up to 9_999_999_999.99
@@ -3226,8 +3270,11 @@ export declare const decodeRowsForTable: <T extends Record<string, unknown>>(row
3226
3270
  * Unknown tables (not registered) pass through unchanged — this is
3227
3271
  * the case for the framework's internal cluster-runtime tables and
3228
3272
  * for ad-hoc raw-SQL paths that bypass the typed-table mechanism.
3273
+ * Pass the SELECT descriptor when decoding a compileSelect result: explicitly
3274
+ * encoded SQLite queries return logical projections, not physical table rows.
3275
+ * Omit it for DML RETURNING, whose cells retain their storage representation.
3229
3276
  */
3230
- export declare const decodeRowsFromSchema: <T extends Record<string, unknown>>(rows: ReadonlyArray<T>, tableName: string, dialect: DecoderDialectId) => ReadonlyArray<T>;
3277
+ export declare const decodeRowsFromSchema: <T extends Record<string, unknown>>(rows: ReadonlyArray<T>, tableName: string, dialect: DecoderDialectId, query?: QueryDescriptor) => ReadonlyArray<T>;
3231
3278
 
3232
3279
  /**
3233
3280
  * Decrypt every `.encrypted()` column's value on read. A value that
@@ -3496,6 +3543,9 @@ export declare interface DialectTransactionSpec {
3496
3543
  /** The store's `sql.withTransaction` — issues BEGIN/COMMIT/ROLLBACK and
3497
3544
  * provides `TransactionConnection`. */
3498
3545
  readonly withTransaction: <A>(effect: Effect.Effect<A, unknown, never>) => Effect.Effect<A, unknown, never>;
3546
+ /** The store's `sql.transactionService` — the key under which `withTransaction`
3547
+ * provides this client's `[Connection, depth]` (per-client in Effect 4). */
3548
+ readonly transactionService: Context.Service<TransactionConnection, TransactionConnection.Service>;
3499
3549
  /** The store's managed runtime, ALWAYS as `runPromiseExit` — `runPromise` is
3500
3550
  * the bug this file exists to prevent, so the shared bracket never sees one. */
3501
3551
  readonly runPromiseExit: <A>(effect: Effect.Effect<A, unknown, never>) => Promise<Exit.Exit<A, unknown>>;
@@ -3720,6 +3770,13 @@ export declare interface EagerRootPlan {
3720
3770
  readonly children: ReadonlyArray<EagerRelationNode>;
3721
3771
  }
3722
3772
 
3773
+ /**
3774
+ * Emit an explicitly committed buffer synchronously, preserving every row
3775
+ * event and its order. Batch identity is process-local metadata, never wire
3776
+ * payload or attribution. Never use for rows still being written.
3777
+ */
3778
+ export declare const emitCommittedChanges: (events: readonly ChangeEvent[], emit: (event: ChangeEvent) => void) => void;
3779
+
3723
3780
  declare type EmptyMerge = unknown;
3724
3781
 
3725
3782
  /**
@@ -3752,8 +3809,8 @@ declare type EmptyMerge = unknown;
3752
3809
  export declare const encodeFieldValue: (cipher: FieldCipher, value: unknown, binding?: FieldBinding) => string;
3753
3810
 
3754
3811
  /**
3755
- * Serialize selected json()/array()/vector() cells to JSON strings so they can be
3756
- * bound as scalar SQL parameters. Symmetric to `decodeRowsFromSchema`.
3812
+ * Serialize selected JSON-like cells and explicitly marked decimal storage
3813
+ * values so they can be bound as scalar SQL parameters. Symmetric to `decodeRowsFromSchema`.
3757
3814
  * No-op for tables with no json/array columns (cost: one map build +
3758
3815
  * a per-cell type lookup). Unknown tables pass through unchanged.
3759
3816
  */
@@ -3780,6 +3837,9 @@ export declare const encryptedColumnsOf: (table: TableLike) => ReadonlyArray<str
3780
3837
  */
3781
3838
  export declare const encryptFieldsForWrite: (row: Row, table: TableLike | undefined, cipher: FieldCipher | undefined, rowId?: unknown) => Row;
3782
3839
 
3840
+ /** Encrypt a bulk write with one metadata snapshot, retaining per-row AAD. */
3841
+ export declare const encryptFieldsForWriteBatch: (rows: ReadonlyArray<Row>, table: TableLike | undefined, cipher: FieldCipher | undefined) => ReadonlyArray<Row>;
3842
+
3783
3843
  /** Mark it finished — AFTER its `routeEvent` has registered, not after the
3784
3844
  * statement. That is the whole point: the window being closed is exactly the
3785
3845
  * gap between the committing statement and the registration. */
@@ -4097,7 +4157,7 @@ export declare interface FileMigration {
4097
4157
  export declare interface FileMigrationContext {
4098
4158
  /**
4099
4159
  * The escape hatch, and it asks for a reason. `raw('why')` returns the
4100
- * `@effect/sql` client — `sql.unsafe(...)`, `sql\`...\``,
4160
+ * `effect/sql` client — `sql.unsafe(...)`, `sql\`...\``,
4101
4161
  * `sql.onDialectOrElse({...})` — for the one thing neither `store` nor
4102
4162
  * `schema` expresses. The reason is required (an empty one throws), it is
4103
4163
  * what `voltro doctor` lists beside every migration that reaches for raw
@@ -5144,7 +5204,7 @@ export declare const makeNamespaceBranchExecutor: (sql: BranchSqlRunner) => Bran
5144
5204
  * every `Effect.withSpan` inside `transactional()` emits real spans.
5145
5205
  */
5146
5206
  export declare interface MakeStoreOptions {
5147
- readonly sqlLayer: Layer.Layer<SqlClient.SqlClient, ConfigError.ConfigError | SqlError.SqlError, never>;
5207
+ readonly sqlLayer: Layer.Layer<SqlClient.SqlClient, Config.ConfigError | SqlError_2.SqlError, never>;
5148
5208
  readonly tracerLayer?: Layer.Layer<never, never, never>;
5149
5209
  readonly changeStrategy?: ChangeStrategy;
5150
5210
  /** Postgres NOTIFY channel name when changeStrategy is 'cdc'. */
@@ -5304,7 +5364,7 @@ export declare class MigrationExpectationFailed extends Error {
5304
5364
  * `log` and the two probes the store can answer about its own shape
5305
5365
  * (`tableExists`, `columnExists`) work without one; each refusal names what to
5306
5366
  * do instead. Also raised at construction when what was handed in as `sql` is not
5307
- * an `@effect/sql` client, or when a SQL-backed store arrives without the
5367
+ * an `effect/sql` client, or when a SQL-backed store arrives without the
5308
5368
  * client it executes on — both are refused before a body can run rather
5309
5369
  * than surfacing as a TypeError from inside the first helper that touches
5310
5370
  * the client.
@@ -5752,6 +5812,15 @@ export declare interface OneRelation {
5752
5812
  readonly sourceKey?: string;
5753
5813
  }
5754
5814
 
5815
+ /**
5816
+ * Run `effect` ON a transaction captured by `runRetryingTransaction`: the
5817
+ * whole context the transaction's fiber had — `TransactionConnection` plus
5818
+ * the sql client's transaction semaphore a nested `withTransaction`
5819
+ * (savepoint) takes a permit from. A connection this module never saw is
5820
+ * provided on its own, which is all a plain statement needs.
5821
+ */
5822
+ export declare const onTransaction: <A, E, R>(effect: Effect.Effect<A, E, R>, transactionService: Context.Service<TransactionConnection, TransactionConnection.Service>, txn: TransactionConnectionContext) => Effect.Effect<A, E, Exclude<R, TransactionConnection>>;
5823
+
5755
5824
  export declare const or: (...predicates: ReadonlyArray<Predicate>) => OrPredicate;
5756
5825
 
5757
5826
  export declare interface OrderClause {
@@ -5969,7 +6038,7 @@ export declare interface PluginRefSpec {
5969
6038
  readonly onSoftDelete: boolean;
5970
6039
  }
5971
6040
 
5972
- /** The declared spec for a column builder, when it is a `pluginRef`. */
6041
+ /** The declared spec on a builder or its materialized column definition. */
5973
6042
  export declare const pluginRefSpecOf: (column: unknown) => PluginRefSpec | undefined;
5974
6043
 
5975
6044
  /** Postgres SQLSTATEs. */
@@ -5996,6 +6065,12 @@ export declare interface PredicateLeafWithContext extends PredicateLeaf {
5996
6065
  readonly conjunctive: boolean;
5997
6066
  }
5998
6067
 
6068
+ /** Prepare one synchronous evaluation pass. Recreate after mutating the AST or
6069
+ * its value arrays; no process-wide cache retains descriptors or row values. */
6070
+ export declare const preparePredicate: (predicate: Predicate, subqueries?: SubqueryResults | null, columns?: Readonly<Record<string, {
6071
+ readonly type: string;
6072
+ }>>) => ((row: Row | null) => boolean);
6073
+
5999
6074
  export declare interface PrimaryKeyConflictError {
6000
6075
  readonly _tag: 'PrimaryKeyConflictError';
6001
6076
  readonly table: string;
@@ -7434,7 +7509,7 @@ export declare const rowNumber: (alias?: string) => WindowBuilder;
7434
7509
  */
7435
7510
  export declare const rowSchema: <T extends TableLike>(table: T, options?: {
7436
7511
  readonly omit?: ReadonlyArray<string>;
7437
- }) => Schema.Schema.Any;
7512
+ }) => Schema.Top;
7438
7513
 
7439
7514
  /** The context a rule predicate is evaluated with. */
7440
7515
  export declare interface RuleContext {
@@ -7487,7 +7562,7 @@ export declare interface RuleViolationDetail {
7487
7562
  * 1. the connection handshake — `withTransaction` + `TransactionConnection`,
7488
7563
  * with a loud failure rather than a silent non-transactional run when the
7489
7564
  * service is somehow absent;
7490
- * 2. **commit-defect promotion** — `@effect/sql` runs COMMIT as `Effect.orDie`,
7565
+ * 2. **commit-defect promotion** — `effect/sql` runs COMMIT as `Effect.orDie`,
7491
7566
  * so a serialization/deadlock error raised AT COMMIT arrives as a defect and
7492
7567
  * `Effect.retry` never sees it. A retryable defect is promoted back to a
7493
7568
  * typed failure so the schedule can replay it; anything else re-dies, so
@@ -7639,10 +7714,9 @@ export declare interface SchemaTable extends TableLike {
7639
7714
  /**
7640
7715
  * The plugin references DECLARED on this table, surviving `table()`.
7641
7716
  *
7642
- * `pluginRefSpecOf` reads a column BUILDER, and materialisation replaces it
7643
- * with a plain field descriptor — so without this the declaration is
7644
- * unreadable the moment the table exists, and any tool deriving structure
7645
- * from the schema sees an ordinary `text()` column.
7717
+ * Derived from column metadata on every table rebuild, including columns
7718
+ * contributed by mixins. Consumers can inspect these rules without knowing
7719
+ * the private metadata on each materialized scalar definition.
7646
7720
  */
7647
7721
  readonly appliedPluginRefs?: ReadonlyArray<{
7648
7722
  readonly column: string;
@@ -7859,7 +7933,7 @@ export declare const setTenantCreateSeedHook: (hook: TenantCreateSeedHook | null
7859
7933
 
7860
7934
  /**
7861
7935
  * Unwrap a transaction program's `Exit`: return the value, or throw the
7862
- * ORIGINAL error rather than Effect's `FiberFailure` wrapper.
7936
+ * ORIGINAL error rather than a squashed or wrapped one.
7863
7937
  *
7864
7938
  * Use with `runtime.runPromiseExit`, never `runPromise` — the wrapper is
7865
7939
  * created by `runPromise` itself, so there is nothing left to unwrap by the
@@ -7868,7 +7942,7 @@ export declare const setTenantCreateSeedHook: (hook: TenantCreateSeedHook | null
7868
7942
  * `Cause.squash` is what preserves the typing: for a `Fail` it yields the value
7869
7943
  * that was thrown (the app's `TaggedError`, so the rpc encoder can still match
7870
7944
  * it against the descriptor's `error:` schema); for a `Die` the defect; for an
7871
- * interrupt an `InterruptedException`. Retry filtering has already run inside
7945
+ * interrupt an `Error` ("All fibers interrupted without error"). Retry filtering has already run inside
7872
7946
  * the program, so an Exit reaching here is final.
7873
7947
  */
7874
7948
  export declare const settleTransactionExit: <A>(exit: Exit.Exit<A, unknown>) => A;
@@ -7887,6 +7961,14 @@ export declare const settleVersionedUpdate: (input: {
7887
7961
  readonly current: number | null;
7888
7962
  }) => VersionConflict | undefined;
7889
7963
 
7964
+ /** ONE transaction context key for every SQL client a process builds, whatever
7965
+ * the dialect: v4 keys `TransactionConnection` per client, so a statement issued
7966
+ * through a second client (another layer build, a plugin's own runtime) inside a
7967
+ * store transaction would otherwise take a fresh pool connection — outside the
7968
+ * transaction, and a deadlock when the pool is small. node-postgres shared one
7969
+ * tag; every dialect layer passes this key to its client. */
7970
+ export declare const SHARED_TRANSACTION_SERVICE: Context.Service<SqlClient.TransactionConnection, TransactionConnection.Service>;
7971
+
7890
7972
  /** When a `<name>__dropped_<YYYYMMDDHHMMSS>` snapshot was taken (UTC), or
7891
7973
  * `undefined` for a name that is not one. */
7892
7974
  export declare const softDropSnapshotStamp: (name: string) => Date | undefined;
@@ -7968,7 +8050,7 @@ export declare type SqlConstructor = Statement.Constructor;
7968
8050
  * `id` is the canonical name surfaced in logs, boot banners, error
7969
8051
  * messages, and the `DB_DIALECT` env value.
7970
8052
  *
7971
- * `makeSqlLayer` constructs the `@effect/sql` connection Layer from a
8053
+ * `makeSqlLayer` constructs the `effect/sql` connection Layer from a
7972
8054
  * generic `ConnectionConfig`. Each dialect maps the config to its own
7973
8055
  * driver's expected shape.
7974
8056
  *
@@ -7994,12 +8076,14 @@ export declare interface SqlDialect {
7994
8076
  */
7995
8077
  readonly workflowRunnerStorage?: (connection: ConnectionConfig) => 'memory' | 'sql';
7996
8078
  readonly id: DialectId;
7997
- readonly makeSqlLayer: (conn: ConnectionConfig) => Layer.Layer<SqlClient.SqlClient, ConfigError.ConfigError | SqlError.SqlError, never>;
8079
+ readonly makeSqlLayer: (conn: ConnectionConfig) => Layer.Layer<SqlClient.SqlClient, Config.ConfigError | SqlError_2.SqlError, never>;
7998
8080
  readonly makeStore: (options: MakeStoreOptions) => Promise<DataStore>;
7999
8081
  readonly compileContains: (col: Statement.Identifier, value: string, sql: Statement.Constructor) => Statement.Fragment;
8000
8082
  readonly retryFilter: (error: unknown) => RetryDecision;
8001
8083
  }
8002
8084
 
8085
+ export declare const sqlError: (message: string, cause?: unknown) => SqlError;
8086
+
8003
8087
  /** SQLite / turso result codes — symbolic and numeric spellings. */
8004
8088
  export declare const SQLITE_TRANSIENT_CODES: ReadonlySet<string>;
8005
8089
 
@@ -8329,10 +8413,9 @@ export declare interface Table<Name extends string, Fields extends Record<string
8329
8413
  /**
8330
8414
  * The plugin references DECLARED on this table, surviving `table()`.
8331
8415
  *
8332
- * `pluginRefSpecOf` reads a column BUILDER, and materialisation replaces it
8333
- * with a plain field descriptor — so without this the declaration is
8334
- * unreadable the moment the table exists, and any tool deriving structure
8335
- * from the schema sees an ordinary `text()` column.
8416
+ * Derived from column metadata on every table rebuild, including columns
8417
+ * contributed by mixins. Consumers can inspect these rules without knowing
8418
+ * the private metadata on each materialized scalar definition.
8336
8419
  */
8337
8420
  readonly appliedPluginRefs?: ReadonlyArray<{
8338
8421
  readonly column: string;
@@ -8379,7 +8462,7 @@ export declare interface Table<Name extends string, Fields extends Record<string
8379
8462
  * BEFORE every INSERT. Populated by `.validate(schema)`. Set
8380
8463
  * per-table at table-construction time; immutable thereafter.
8381
8464
  */
8382
- readonly insertSchema?: Schema.Schema.Any;
8465
+ readonly insertSchema?: Schema.Top;
8383
8466
  /**
8384
8467
  * Optional `effect/Schema` the framework decodes a patch against
8385
8468
  * BEFORE every UPDATE. Populated by `.validatePatch(schema)`. The
@@ -8388,7 +8471,7 @@ export declare interface Table<Name extends string, Fields extends Record<string
8388
8471
  * are checked. Set per-table at table-construction time; immutable
8389
8472
  * thereafter.
8390
8473
  */
8391
- readonly validatePatchSchema?: Schema.Schema.Any;
8474
+ readonly validatePatchSchema?: Schema.Top;
8392
8475
  with: <const Mixins extends ReadonlyArray<AnyMixin>>(...mixins: Mixins) => Table<Name, Fields & MergeMixinFields<Mixins>, Reactive, IxNames>;
8393
8476
  /**
8394
8477
  * Attach an effect/Schema that validates EVERY insert against the
@@ -8416,7 +8499,7 @@ export declare interface Table<Name extends string, Fields extends Record<string
8416
8499
  * `id` and `createdAt` are already filled in by the time the
8417
8500
  * decoder sees the row.
8418
8501
  */
8419
- validate: <S extends Schema.Schema.Any>(schema: S) => Table<Name, Fields, Reactive, IxNames>;
8502
+ validate: <S extends Schema.Top>(schema: S) => Table<Name, Fields, Reactive, IxNames>;
8420
8503
  /**
8421
8504
  * Attach an effect/Schema that validates UPDATE patches against the
8422
8505
  * table. The framework wraps the schema in `Schema.partial`, so a
@@ -8447,7 +8530,7 @@ export declare interface Table<Name extends string, Fields extends Record<string
8447
8530
  * wrapping is applied for you, so don't pre-wrap fields in
8448
8531
  * `Schema.optional`.
8449
8532
  */
8450
- validatePatch: <S extends Schema.Schema.Any>(schema: S) => Table<Name, Fields, Reactive, IxNames>;
8533
+ validatePatch: <S extends Schema.Struct<Schema.Struct.Fields>>(schema: S) => Table<Name, Fields, Reactive, IxNames>;
8451
8534
  /**
8452
8535
  * Declare a (possibly composite) secondary index on the table.
8453
8536
  *
@@ -9041,7 +9124,7 @@ export declare const timestamp: () => ColumnBuilder<Date, "timestamp", boolean>;
9041
9124
  * There is deliberately no `timestampMsOptional`: an absent field is
9042
9125
  * `Schema.optional(timestampMs)`, which composes without a third export.
9043
9126
  */
9044
- export declare const timestampMs: Schema.Schema<Date, number>;
9127
+ export declare const timestampMs: Schema.Codec<Date, number>;
9045
9128
 
9046
9129
  /**
9047
9130
  * `timestampMs` for a NULLABLE timestamp column — `Date | null` in the
@@ -9053,7 +9136,7 @@ export declare const timestampMs: Schema.Schema<Date, number>;
9053
9136
  * instead of as nothing. Mirrors what `columnSchema` does for a
9054
9137
  * `.nullable()` timestamp.
9055
9138
  */
9056
- export declare const timestampMsOrNull: Schema.Schema<Date | null, number | null>;
9139
+ export declare const timestampMsOrNull: Schema.Codec<Date | null, number | null>;
9057
9140
 
9058
9141
  /**
9059
9142
  * `transactional()`'s work caught a statement failure the engine had already
@@ -9139,14 +9222,14 @@ export declare class TransactionBrokenByBodyError extends Error {
9139
9222
  }
9140
9223
 
9141
9224
  /**
9142
- * The `[Connection, depth]` tuple `@effect/sql` provides inside
9225
+ * The `[Connection, depth]` tuple `effect/sql` provides inside
9143
9226
  * `withTransaction`. Every statement that must run on the transaction's OWN
9144
9227
  * connection (rather than a fresh one from the pool) is given this explicitly.
9145
9228
  */
9146
- export declare type TransactionConnectionContext = Context.Tag.Service<typeof TransactionConnection>;
9229
+ export declare type TransactionConnectionContext = TransactionConnection.Service;
9147
9230
 
9148
9231
  /** Shared bounded contention policy, including stores without a SQL connection. */
9149
- export declare const transactionRetrySchedule: (isRetryable: (error: unknown) => boolean) => Schedule.Schedule<number, unknown, never>;
9232
+ export declare const transactionRetrySchedule: (isRetryable: (error: unknown) => boolean) => Schedule.Schedule< Duration, unknown, never, never>;
9150
9233
 
9151
9234
  /** Turso's MVCC conflicts arrive as messages, not codes. */
9152
9235
  export declare const TURSO_TRANSIENT_MESSAGE: RegExp;
@@ -9539,16 +9622,14 @@ export declare const versionColumnOf: (columns: Readonly<Record<string, {
9539
9622
  export declare class VersionConflict extends VersionConflict_base {
9540
9623
  }
9541
9624
 
9542
- declare const VersionConflict_base: Schema.TaggedErrorClass<VersionConflict, "VersionConflict", {
9543
- readonly _tag: Schema.tag<"VersionConflict">;
9544
- } & {
9545
- table: typeof Schema.String;
9546
- id: typeof Schema.String;
9625
+ declare const VersionConflict_base: Schema.Class<VersionConflict, Schema.TaggedStruct<"VersionConflict", {
9626
+ readonly table: Schema.String;
9627
+ readonly id: Schema.String;
9547
9628
  /** What the caller believed the row was at. */
9548
- expected: typeof Schema.Number;
9629
+ readonly expected: Schema.Number;
9549
9630
  /** What it is actually at. `null` when the row is gone entirely. */
9550
- actual: Schema.NullOr<typeof Schema.Number>;
9551
- }>;
9631
+ readonly actual: Schema.NullOr<Schema.Number>;
9632
+ }>, YieldableError>;
9552
9633
 
9553
9634
  /**
9554
9635
  * A read-only SQL view descriptor. Structurally a `TableLike` (carries
@@ -9816,8 +9897,8 @@ export declare interface WindowSpec {
9816
9897
  * echoes the duplicate value, mssql echoes the truncated one. A cause that
9817
9898
  * forwards the sentence ships row contents to whoever provoked the failure.
9818
9899
  *
9819
- * `StoreOperationFailed.cause` did exactly that: `String(error)` on a
9820
- * `FiberFailure`, which is the message AND the stack, so an absolute server
9900
+ * `StoreOperationFailed.cause` did exactly that: `String(error)` on the
9901
+ * rejection, which is the message AND the stack, so an absolute server
9821
9902
  * path reached any caller that declared the error and every subscriber on a
9822
9903
  * stream carrying it.
9823
9904
  *