@crvouga/mockingbird-service-postgres 0.1.3 → 0.3.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/AGENTS.md CHANGED
@@ -171,4 +171,4 @@ bun run build
171
171
 
172
172
  ## PR and commits
173
173
 
174
- Use [Conventional Commits](https://www.conventionalcommits.org/) for commits and PR titles (enforced on PRs). Prefer squash merges with a conventional title so the npm bump is `feat` → minor / `fix` → patch. Direct pushes to `main` with any other subject still publish a patch. See [README.md](README.md#releasing).
174
+ Use [Conventional Commits](https://www.conventionalcommits.org/) for commits and PR titles (enforced on PRs). Prefer squash merges with a conventional title so the npm bump is `feat` → minor / `fix` → patch. Direct pushes to `main` with any other subject still publish a patch. See [docs/RELEASING.md](../../../docs/RELEASING.md).
package/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  # Changelog — @crvouga/mockingbird-service-postgres
2
2
 
3
- ## 0.1.3 (2026-09-21)
3
+ ## 0.3.0 (2026-09-22)
4
+
5
+ ### Features
6
+
7
+ - add deterministic time travel and branching ([a6c341f](https://github.com/crvouga/mockingbird/commit/a6c341f9476f09227a1be4fe830942e4f60c17d9))
8
+
9
+ ## 0.2.0 (2026-09-21)
10
+
11
+ ### Features
12
+
13
+ - agent issue reporting for parity, features and new services; in-process medplum mock ([fc3a53b](https://github.com/crvouga/mockingbird/commit/fc3a53be83e2840e55aef78970326c27982311a8))
14
+
15
+ ### Fixes and improvements
16
+
17
+ - point the SQL engines' release notes at docs/RELEASING.md ([10f4243](https://github.com/crvouga/mockingbird/commit/10f424394e9058028c66284651dd899fe1d66a24))
18
+
19
+ ## 0.1.3 (2026-09-20)
4
20
 
5
21
  ### Fixes and improvements
6
22
 
package/README.md CHANGED
@@ -157,11 +157,12 @@ back as PostgreSQL text (node-postgres parses timestamps to `Date` and JSON to o
157
157
  | --- | --- |
158
158
  | `exec(sql)` | Runs all semicolon-separated statements; **discards** row results (`void`). Does **not** accept bind parameters. Read `db.changes` afterwards if needed (reflects the **most recent** completed DML statement). Dump-only `DO` blocks and `ALTER TABLE ... SET (` storage parameters are no-ops. |
159
159
  | `registerFunction(spec)` | Install a JavaScript scalar. Not stored in PGMM snapshots; `open()` of a live snapshot copies the implementation by reference. |
160
- | `query(sql, params?)` | **Single statement only** (trailing `;` is fine). Returns all rows. Multi-statement scripts throw `misuse`. |
160
+ | `query(sql, params?, { at? }?)` | **Single statement only** (trailing `;` is fine). Returns all rows. `at` queries an immutable checkpoint without changing live state. Multi-statement scripts throw `misuse`. |
161
161
  | `prepare(sql)` | **Single statement only**. Parses immediately; the AST is reused. Pass binds as rest args to `run` / `all` / `get` / `result` / `textResult` on each call. |
162
162
  | `transaction(fn)` | If idle: `BEGIN`, `fn()`, `COMMIT`, or `ROLLBACK` + rethrow. If already in a transaction: nested savepoint. A nested SQL `BEGIN` inside is a no-op warning like PostgreSQL. `close()` inside `fn` throws `misuse`. |
163
163
  | `copyFrom(sql, data)` | Executes `COPY table [(cols)] FROM STDIN` with `data` as the copy-in payload (text or csv per the COPY options). Returns rows copied. `COPY ... TO STDOUT` output is returned as result rows by `query`. |
164
164
  | `snapshot()` | Freeze a reusable `Snapshot` template (no encode). Illegal inside a transaction (`25P01`). |
165
+ | `checkpoint()` / `branch(at?)` | Name a COW snapshot as a checkpoint; open an isolated branch from it (or current state). |
165
166
  | `Snapshot.open()` | Copy-on-write fork from a template. The parent stays open. |
166
167
  | `Snapshot.encode()` | Lazy PGMM blob for persistence / worker boot (computed once, cached). |
167
168
  | `Snapshot.decode(bytes)` | Decode a blob once per `Uint8Array` (WeakMap); later `open()` calls are copy-on-write. |
@@ -313,11 +314,13 @@ class Database {
313
314
  exec(sql: string): void
314
315
  registerFunction(spec: { name: string; args: string[]; returns: string; strict?: boolean;
315
316
  fn: (...args: JsValue[]) => JsValue }): void
316
- query<T = QueryRow>(sql: string, params?: readonly BindValue[]): T[]
317
+ query<T = QueryRow>(sql: string, params?: readonly BindValue[], options?: { at?: Snapshot }): T[]
317
318
  prepare(sql: string): Statement
318
319
  transaction<T>(fn: () => T): T
319
320
  copyFrom(sql: string, data: string): number // COPY t FROM STDIN payload (\copy analog)
320
321
  snapshot(): Snapshot
322
+ checkpoint(): Snapshot
323
+ branch(at?: Snapshot): Database
321
324
  close(): void // also [Symbol.dispose] when available
322
325
  readonly changes: number // rows affected by the most recent INSERT/UPDATE/DELETE
323
326
  readonly seed: number | bigint
@@ -411,6 +414,6 @@ A React + Vite SQL playground lives in
411
414
  and [`tests/contract/parameters/`](https://github.com/crvouga/mockingbird/tree/main/packages/service/postgres/tests/contract/parameters).
412
415
 
413
416
  Released automatically from the [Mockingbird monorepo](https://github.com/crvouga/mockingbird)
414
- (see the root README, Releasing). License: MIT ([LICENSE](./LICENSE)).
417
+ (see [Releasing](https://github.com/crvouga/mockingbird/blob/main/docs/RELEASING.md)). License: MIT ([LICENSE](./LICENSE)).
415
418
 
416
- Part of [mockingbird](https://github.com/crvouga/mockingbird) — agent integration guide: [README](https://github.com/crvouga/mockingbird#readme) · [llms.txt](https://github.com/crvouga/mockingbird/blob/main/llms.txt).
419
+ Part of [mockingbird](https://github.com/crvouga/mockingbird) — agent integration guide: [README](https://github.com/crvouga/mockingbird#readme) · [llms.txt](https://github.com/crvouga/mockingbird/blob/main/llms.txt) · [report an issue or request a feature](https://github.com/crvouga/mockingbird/blob/main/docs/REPORTING_ISSUES.md).
@@ -2,6 +2,11 @@ import { type DatabaseOptions, type Int8Mode, type RandomMode } from "../runtime
2
2
  import type { BindValue, JsValue, QueryRow } from "./bind.js";
3
3
  import { type Snapshot } from "./snapshot.js";
4
4
  import { Statement } from "./statement.js";
5
+ /** Additive time-travel controls for read APIs. */
6
+ export interface QueryOptions {
7
+ /** Execute against this immutable checkpoint instead of the live database. */
8
+ at?: Snapshot;
9
+ }
5
10
  /**
6
11
  * Pure TypeScript in-memory PostgreSQL database.
7
12
  *
@@ -44,7 +49,7 @@ export declare class Database {
44
49
  */
45
50
  registerFunction(spec: RegisterFunctionOptions): void;
46
51
  /** Execute a single-statement query and return all rows keyed by column name. */
47
- query<T = QueryRow>(sql: string, params?: readonly BindValue[]): T[];
52
+ query<T = QueryRow>(sql: string, params?: readonly BindValue[], options?: QueryOptions): T[];
48
53
  /** Compile a single SQL statement into a reusable {@link Statement}. */
49
54
  prepare(sql: string): Statement;
50
55
  /**
@@ -58,6 +63,10 @@ export declare class Database {
58
63
  * {@link Snapshot.open} for a copy-on-write fork.
59
64
  */
60
65
  snapshot(): Snapshot;
66
+ /** Alias for {@link snapshot}, naming the value as a timeline checkpoint. */
67
+ checkpoint(): Snapshot;
68
+ /** Open a copy-on-write branch from `at`, or from the current state when omitted. */
69
+ branch(at?: Snapshot): Database;
61
70
  /** Close the database. Further SQL throws. Idempotent. */
62
71
  close(): void;
63
72
  /**
package/dist/index.d.ts CHANGED
@@ -23,6 +23,6 @@
23
23
  */
24
24
  import "./serialization/codec.js";
25
25
  export type { BindValue, JsValue, QueryRow } from "./api/bind.js";
26
- export { Database, type DatabaseOptions, type RegisterFunctionOptions, Snapshot } from "./api/database.js";
26
+ export { Database, type DatabaseOptions, type QueryOptions, type RegisterFunctionOptions, Snapshot, } from "./api/database.js";
27
27
  export { type ResultSet, type RunResult, Statement } from "./api/statement.js";
28
28
  export { type ErrorCategory, PostgresError } from "./errors/error.js";
package/dist/index.js CHANGED
@@ -22214,8 +22214,9 @@ var Database = class {
22214
22214
  schema.functions.set(name, existing);
22215
22215
  }
22216
22216
  /** Execute a single-statement query and return all rows keyed by column name. */
22217
- query(sql, params = []) {
22217
+ query(sql, params = [], options = {}) {
22218
22218
  this.assertOpen();
22219
+ if (options.at) return options.at.open().query(sql, params);
22219
22220
  return this.prepareSingle(sql).all(...params);
22220
22221
  }
22221
22222
  /** Compile a single SQL statement into a reusable {@link Statement}. */
@@ -22277,6 +22278,15 @@ var Database = class {
22277
22278
  this.int8Mode
22278
22279
  );
22279
22280
  }
22281
+ /** Alias for {@link snapshot}, naming the value as a timeline checkpoint. */
22282
+ checkpoint() {
22283
+ return this.snapshot();
22284
+ }
22285
+ /** Open a copy-on-write branch from `at`, or from the current state when omitted. */
22286
+ branch(at = this.snapshot()) {
22287
+ this.assertOpen();
22288
+ return at.open();
22289
+ }
22280
22290
  /** Close the database. Further SQL throws. Idempotent. */
22281
22291
  close() {
22282
22292
  if (this.closed) return;