@ultimat3/db 31.32.0 → 31.34.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/db",
3
- "version": "31.32.0",
3
+ "version": "31.34.0",
4
4
  "description": "Postgres access, transactions, migrations and drift detection",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -45,7 +45,7 @@
45
45
  "test": "bun test"
46
46
  },
47
47
  "dependencies": {
48
- "@ultimat3/core": "31.32.0"
48
+ "@ultimat3/core": "31.34.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@electric-sql/pglite": ">=0.5.0"
@@ -1,8 +1,9 @@
1
1
  // Single responsibility: every value of one statement, encoded into what `Bun.SQL` sends correctly.
2
+ //
2
3
  // Two kinds need it, both measured against Postgres 17: a JS array (`array-parameter.ts`, #384),
3
4
  // and a `Date` once the pool runs unnamed statements (`prepare: false`, `bun-sql.ts`) — with no
4
- // described type to go by the driver sent `Date.prototype.toString()`, a local-zone string
5
- // Postgres refuses (`22007`), so every entity write carrying a timestamp failed.
5
+ // described type to go by the driver sent `Date.prototype.toString()`, a local-zone string Postgres
6
+ // refuses (`22007`), so every entity write carrying a timestamp failed.
6
7
 
7
8
  import { instantText, pgArrayLiteral } from './array-parameter';
8
9
 
package/src/catalog.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  // Single responsibility: the SHAPE of a whole schema as the catalog holds it — every object kind
2
2
  // the schema dump renders, in Postgres' own spelling. Distinct from `SchemaDescription`
3
3
  // (`introspect.ts`) on purpose: that one is the entity vocabulary a snapshot is diffed in, and a
4
- // catalog spelling can never compare equal to a generated one. This one is only ever compared to
5
- // itself, which is why it may carry `pg_get_*def` text verbatim.
4
+ // catalog spelling can never compare equal to a generated one.
5
+ //
6
+ // This one is only ever compared to itself, which is why it may carry `pg_get_*def` text verbatim.
6
7
 
7
8
  export interface CatalogExtension {
8
9
  readonly name: string;
package/src/check-ddl.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  // Single responsibility: every CHECK constraint a table declares — a COLUMN's own and an
2
- // INVARIANT's — and which of them a migration adds, rebuilds or drops. Split out of `generate.ts`
3
- // and `invariant-ddl.ts` because a column check was the one part of a column that reached
4
- // `create table` and nothing else: `columnClause` wrote `check (…)` inline and ANONYMOUS,
5
- // `snapshotOf` recorded nothing for it and `diffTable` had no arm for it, so the SECOND `x db gen`
6
- // turned `enumerated(POST_STATUSES)` into bare `text` accepting any string, and the value set the
7
- // entity still declares left the database with no statement anywhere saying so.
2
+ // INVARIANT's — and which of them a migration adds, rebuilds or drops.
3
+ //
4
+ // Split out of `generate.ts` and `invariant-ddl.ts` because a column check was the one part of a
5
+ // column that reached `create table` and nothing else: `columnClause` wrote `check (…)` inline and
6
+ // ANONYMOUS, `snapshotOf` recorded nothing for it and `diffTable` had no arm for it, so the SECOND
7
+ // `x db gen` turned `enumerated(POST_STATUSES)` into bare `text` accepting any string, and the
8
+ // value set the entity still declares left the database with no statement anywhere saying so.
8
9
  //
9
10
  // One list, for the reason `declaredIndexes` is one list: `createTable`, `diffTable` and
10
11
  // `snapshotOf` must agree about what exists, and two producers of `add constraint` that never met
package/src/client.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  // Single responsibility: the pooled Postgres client and the ambient `db()` handle — the lazy
2
2
  // connect, the reserved-connection pin, and the process-wide client every repository reaches
3
- // through. Sizing lives in `pool-profile.ts`, the connection string in `connection-url.ts`, the
4
- // `Bun.SQL` slice in `bun-sql.ts` and the observed statement funnel in `statement-funnel.ts`, so
5
- // importing this module never opens a socket.
3
+ // through.
4
+ //
5
+ // Sizing lives in `pool-profile.ts`, the connection string in `connection-url.ts`, the `Bun.SQL`
6
+ // slice in `bun-sql.ts` and the observed statement funnel in `statement-funnel.ts`, so importing
7
+ // this module never opens a socket.
6
8
 
7
9
  import { logger, type Role, resolveRole, type Scheduler } from '@ultimat3/core';
8
10
  import {
@@ -1,8 +1,10 @@
1
1
  // Single responsibility: the attributes of an EXISTING column that move in place — its default, its
2
- // collation and its nullability. Split from `generate.ts` because `diffTable` emitted SQL for a type change only:
3
- // a changed or removed `.default()`, or a nullability change, emitted nothing while the snapshot
4
- // beside it recorded the move, so `x verify` answered `X_DB_SCHEMA_UNMIGRATED` and its own fix,
5
- // `x db gen`, produced an empty diff. A gate red forever, with the repair being the thing that failed.
2
+ // collation and its nullability.
3
+ //
4
+ // Split from `generate.ts` because `diffTable` emitted SQL for a type change only: a changed or
5
+ // removed `.default()`, or a nullability change, emitted nothing while the snapshot beside it
6
+ // recorded the move, so `x verify` answered `X_DB_SCHEMA_UNMIGRATED` and its own fix, `x db gen`,
7
+ // produced an empty diff. A gate red forever, with the repair being the thing that failed.
6
8
 
7
9
  import { defaultExpression, hasUnrenderedDefault } from './column-default';
8
10
  import { columnDefaultUnsafe } from './ddl-errors';
@@ -1,9 +1,11 @@
1
- // Single responsibility: what a column's DEFAULT is, as SQL. Split out of `generate.ts` because
2
- // the question has two halves that must be answered together — what a declared default renders as,
3
- // and what it MEANS when a column claims one this generator cannot write down. That second half
4
- // had no answer at all until 2026-08-25: `hasDefault` reached the generator with no expression
5
- // beside it, so nine scalar defaults in the reference app's own schema were dropped in silence and
6
- // only `now()` and `gen_random_uuid()` survived, because those two are inferable from the kind.
1
+ // Single responsibility: what a column's DEFAULT is, as SQL. Split out of `generate.ts` because the
2
+ // question has two halves that must be answered together — what a declared default renders as, and
3
+ // what it MEANS when a column claims one this generator cannot write down.
4
+ //
5
+ // That second half had no answer at all until 2026-08-25: `hasDefault` reached the generator with
6
+ // no expression beside it, so nine scalar defaults in the reference app's own schema were dropped
7
+ // in silence and only `now()` and `gen_random_uuid()` survived, because those two are inferable
8
+ // from the kind.
7
9
 
8
10
  import { assert } from '@ultimat3/core';
9
11
  import { literal } from './sql';
@@ -1,10 +1,12 @@
1
1
  // Single responsibility: the `X_DB_DRIFT` constructor — the error form of the finding
2
2
  // `drift-findings.ts`'s `unexpectedColumn` reports, thrown where a caller has no report to hand
3
- // back. Split out of `errors.ts` for the import it needs and nothing else: the fix line puts a
4
- // column name into a shell command, so it screens through `shellInertIdentifier` (`sql.ts`) —
5
- // and `sql.ts` imports `errors.ts`, so this cannot live there without a cycle around the module
6
- // whose evaluation registers every code. The code is still declared, titled and registered in
7
- // `errors.ts`, exactly as `migration-errors.ts` and `invariant-errors.ts` are.
3
+ // back.
4
+ //
5
+ // Split out of `errors.ts` for the import it needs and nothing else: the fix line puts a column
6
+ // name into a shell command, so it screens through `shellInertIdentifier` (`sql.ts`) — and `sql.ts`
7
+ // imports `errors.ts`, so this cannot live there without a cycle around the module whose evaluation
8
+ // registers every code. The code is still declared, titled and registered in `errors.ts`, exactly
9
+ // as `migration-errors.ts` and `invariant-errors.ts` are.
8
10
 
9
11
  import { renderFixShellArg } from '@ultimat3/core';
10
12
  import { DbError } from './errors';
package/src/index-ddl.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  // Single responsibility: the DDL an entity's INDEX declaration becomes — the `create index` a
2
2
  // declaration writes out, what makes two definitions the same index, and what a moved definition
3
- // rebuilds. Split out of `generate.ts` at the 500-line ceiling, along the seam `check-ddl.ts` and
3
+ // rebuilds.
4
+ //
5
+ // Split out of `generate.ts` at the 500-line ceiling, along the seam `check-ddl.ts` and
4
6
  // `generated-column.ts` already drew: `generate.ts` assembles a plan, this file writes the index
5
7
  // statements it puts in it, and `invariant-ddl.ts` decides which indexes a table declares.
6
8
 
package/src/index-plan.ts CHANGED
@@ -1,8 +1,10 @@
1
- // Single responsibility: which indexes an existing table gains, has rebuilt, or LOSES. Split out
2
- // of `generate.ts` along the seam `check-ddl.ts` and `index-ddl.ts` already drew — `generate.ts`
1
+ // Single responsibility: which indexes an existing table gains, has rebuilt, or LOSES. Split out of
2
+ // `generate.ts` along the seam `check-ddl.ts` and `index-ddl.ts` already drew — `generate.ts`
3
3
  // assembles a plan, `index-ddl.ts` writes the statements, and this file decides which of them go
4
- // in. `checkPlan` is its shape, deliberately: "what does the record hold that the declaration does
5
- // not" is one question, and a fourth spelling of it is the split axiom 1 refuses.
4
+ // in.
5
+ //
6
+ // `checkPlan` is its shape, deliberately: "what does the record hold that the declaration does not"
7
+ // is one question, and a fourth spelling of it is the split axiom 1 refuses.
6
8
  //
7
9
  // The removal arm is why this file exists. `diffTable` walked `declaredIndexes(entity)` and matched
8
10
  // by name, with no reverse pass, so an index the entities stopped declaring stayed on the database
@@ -1,9 +1,10 @@
1
1
  // Single responsibility: the two refusals an entity INVARIANT earns before its DDL exists — a name
2
2
  // that cannot be an identifier, and a predicate holding a second command. Split out of `errors.ts`
3
3
  // only because that file reached the 500-line ceiling; both carry `X_SQL_UNSAFE`, which
4
- // `DB_OWNED_ERROR_CODES` there still declares and registers. No new code, and none is needed: an
5
- // invariant name reaching a statement text is the same hazard a branch name or an isolation level
6
- // is, and axiom 1 says one situation gets one code.
4
+ // `DB_OWNED_ERROR_CODES` there still declares and registers.
5
+ //
6
+ // No new code, and none is needed: an invariant name reaching a statement text is the same hazard a
7
+ // branch name or an isolation level is, and axiom 1 says one situation gets one code.
7
8
 
8
9
  import { describeValue } from '@ultimat3/core';
9
10
  import { DbError } from './errors';
@@ -1,9 +1,10 @@
1
1
  // Single responsibility: the refusals a MIGRATION earns — the lock it could not take, a ledger that
2
2
  // disagrees with this build, a plan that cannot be reversed, a plan that destroys rows without
3
- // saying so, a snapshot never written, a view in a retype's way, a concurrent build. Split out of
4
- // `errors.ts` only because that file reached the 500-line ceiling, exactly as `invariant-errors.ts`
5
- // was: every code below is still declared, titled and registered there, and `DbError` is still the
6
- // one class. One direction only — nothing here is imported back.
3
+ // saying so, a snapshot never written, a view in a retype's way, a concurrent build.
4
+ //
5
+ // Split out of `errors.ts` only because that file reached the 500-line ceiling, exactly as
6
+ // `invariant-errors.ts` was: every code below is still declared, titled and registered there, and
7
+ // `DbError` is still the one class. One direction only — nothing here is imported back.
7
8
 
8
9
  import { renderFixShellArg } from '@ultimat3/core';
9
10
  import { DESTRUCTIVE_CAUSE, DESTRUCTIVE_MARKER, type DestructiveStatement } from './destructive';
package/src/pg-instant.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  // Single responsibility: Postgres' TEXT form of `timestamptz` and `timestamp`, read as an instant.
2
+ //
2
3
  // PGlite's own parser — and Bun.SQL's on the text protocol — read year `0099` as 1999, and under a
3
4
  // session zone that is not UTC answered Invalid Date for an offset carrying seconds (local mean
4
5
  // time before a zone's standard time: `-04:56:02`), which `@ultimat3/entity` then refused as
@@ -3,6 +3,7 @@
3
3
  // validated before it ever reaches a path, and why the caller must have closed the source first:
4
4
  // this copies files, it does not take a snapshot of a running instance.
5
5
 
6
+ // why: cp/rm recursive and an empty-directory mkdir — Bun copies and writes single files only.
6
7
  import { cp, mkdir, rm, stat } from 'node:fs/promises';
7
8
  import { basename, dirname, join } from 'node:path';
8
9
  import { NotImplementedError, systemClock } from '@ultimat3/core';
@@ -1,8 +1,10 @@
1
1
  // Single responsibility: taking turns on PGlite's one connection. Embedded Postgres is a single
2
2
  // session, not a pool, so two units of work that each `BEGIN` would be sharing one transaction —
3
3
  // the second `COMMIT` commits the first's uncommitted rows and the first `ROLLBACK` finds nothing
4
- // to undo. This queue makes them consecutive instead, which is what a pinned pool connection
5
- // gives `withTransaction` and `readOnlyQuery` on a real server.
4
+ // to undo.
5
+ //
6
+ // This queue makes them consecutive instead, which is what a pinned pool connection gives
7
+ // `withTransaction` and `readOnlyQuery` on a real server.
6
8
 
7
9
  /**
8
10
  * Gives the connection back. `release()` is idempotent for free: it is a settled promise's
@@ -1,7 +1,9 @@
1
- // Single responsibility: the `alter table … replica identity full` a live query needs, emitted once.
2
- // `@ultimat3/realtime` refuses a subscription to a table without it — logical replication carries no
3
- // old row on an UPDATE, so no patch can be computed — and which tables need it is a tier-3 fact no
4
- // entity carries, so it arrives as `GenerateOptions.replicaIdentityFull` and is recorded on the
1
+ // Single responsibility: the `alter table … replica identity full` a live query needs, emitted
2
+ // once.
3
+ //
4
+ // `@ultimat3/realtime` refuses a subscription to a table without it — logical replication carries
5
+ // no old row on an UPDATE, so no patch can be computed — and which tables need it is a tier-3 fact
6
+ // no entity carries, so it arrives as `GenerateOptions.replicaIdentityFull` and is recorded on the
5
7
  // snapshot: the record is what stops the statement being re-emitted on every `x db gen`.
6
8
 
7
9
  import type { Plan } from './foreign-key-plan';
@@ -2,6 +2,7 @@
2
2
  // writes, and the identity repeated statements are counted under. Two detectors above this package
3
3
  // group statements by that identity (`x dev`'s ledger, the `statements` test fixture) and a third
4
4
  // names spans from the same verb, so the rule lives once, next to the `DbStatementEvent` it reads.
5
+ //
5
6
  // Nothing here counts anything: a threshold is a verdict's, and a verdict is `@ultimat3/entity`'s.
6
7
 
7
8
  import type { DbStatementEvent } from '@ultimat3/core';
@@ -1,8 +1,10 @@
1
1
  // Single responsibility: what one statement is to the rest of the process — a `db.<verb>` client
2
2
  // span carrying OTel's stable database attributes, opened for EVERY statement (production has DB
3
3
  // spans, not only `x dev`), and one `db.statement` event on the instrumentation bus once it has
4
- // settled. Both drivers' funnels (`statement-funnel.ts`, `pglite.ts`) call `traceStatement` and
5
- // nothing else, so the two cannot answer differently for the same statement.
4
+ // settled.
5
+ //
6
+ // Both drivers' funnels (`statement-funnel.ts`, `pglite.ts`) call `traceStatement` and nothing
7
+ // else, so the two cannot answer differently for the same statement.
6
8
 
7
9
  import { instrument, SEMCONV, SEMCONV_VALUES, subscribed, withSpan } from '@ultimat3/core';
8
10
  import { statementAttribution } from './attribution';
package/src/type-pins.ts CHANGED
@@ -1,12 +1,12 @@
1
- // Compile-time pins for this package's disposable resources. Source, not a `.test.ts`, on
2
- // purpose: `tsconfig.json` excludes `src/**/*.test.ts`, so `tsc -b` never reads a test file and a
3
- // type-level assertion written there can never fail. This module emits nothing and exports
4
- // nothing anybody imports — a regression is a build error, the only enforcement that counts
5
- // (axiom 3). `DbConnection` and `Turn` both went through a session where `release()`/`close()`
6
- // left a resource cached or unreturned; the fix each time was RAII (`Disposable` + `using`), and
7
- // this pin is what stops a future edit from quietly dropping `Disposable` off either interface —
8
- // the one place a regression here would otherwise surface is a leaked connection under load, not
9
- // a red test.
1
+ // Compile-time pins for this package's disposable resources. Source, not a `.test.ts`, on purpose:
2
+ // `tsconfig.json` excludes `src/**/*.test.ts`, so `tsc -b` never reads a test file and a type-level
3
+ // assertion written there can never fail. This module emits nothing and exports nothing anybody
4
+ // imports — a regression is a build error, the only enforcement that counts (axiom 3).
5
+ //
6
+ // `DbConnection` and `Turn` both went through a session where `release()`/`close()` left a resource
7
+ // cached or unreturned; the fix each time was RAII (`Disposable` + `using`), and this pin is what
8
+ // stops a future edit from quietly dropping `Disposable` off either interface — the one place a
9
+ // regression here would otherwise surface is a leaked connection under load, not a red test.
10
10
 
11
11
  import type { DbConnection } from './client';
12
12
  import type { Turn } from './pglite-turns';
@@ -1,8 +1,10 @@
1
1
  // Single responsibility: which statements in a migration's `up` half `x db gen` could never have
2
- // written — the SQL a squash discards in silence. `REPLICA IDENTITY FULL`, `CREATE EXTENSION`, a
3
- // `GRANT`, a data backfill: none of them is a declaration, none reaches a `.snapshot.json`, and no
4
- // declaration-based drift check can see them, because a regenerated sidecar equals the declaration
5
- // by construction. The rail is the same shape `destructive.ts` is — statements in, statements out.
2
+ // written — the SQL a squash discards in silence.
3
+ //
4
+ // `REPLICA IDENTITY FULL`, `CREATE EXTENSION`, a `GRANT`, a data backfill: none of them is a
5
+ // declaration, none reaches a `.snapshot.json`, and no declaration-based drift check can see them,
6
+ // because a regenerated sidecar equals the declaration by construction. The rail is the same shape
7
+ // `destructive.ts` is — statements in, statements out.
6
8
 
7
9
  import { PARTITION_FUNCTION } from './generate-partition';
8
10
  import { ROW_SECURITY_POLICY } from './row-security';
package/src/unrendered.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  // Single responsibility: what a generated migration declares it could NOT write, and how that
2
- // reaches the file. A generator that silently emits less than the declaration is the defect this
3
- // module exists against — ten invariants and nine defaults went missing between an entity and its
4
- // own regenerated migration, and the `drift` gate step compares a source hash to a sidecar and
5
- // never reads the SQL, so the loss was GREEN. A comment in the emitted `up` cannot be green.
2
+ // reaches the file.
3
+ //
4
+ // A generator that silently emits less than the declaration is the defect this module exists
5
+ // against — ten invariants and nine defaults went missing between an entity and its own regenerated
6
+ // migration, and the `drift` gate step compares a source hash to a sidecar and never reads the SQL,
7
+ // so the loss was GREEN. A comment in the emitted `up` cannot be green.
6
8
 
7
9
  import { assert } from '@ultimat3/core';
8
10
  import { columnNamesConstraint } from './check-ddl';