@pgxsinkit/client 0.1.36 → 0.1.41
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/boot-report.d.ts +134 -0
- package/dist/boot-report.d.ts.map +1 -0
- package/dist/export-data.d.ts +100 -0
- package/dist/export-data.d.ts.map +1 -0
- package/dist/export-dump.d.ts +92 -0
- package/dist/export-dump.d.ts.map +1 -0
- package/dist/export-store.d.ts +214 -0
- package/dist/export-store.d.ts.map +1 -0
- package/dist/index.d.ts +206 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1373 -8308
- package/dist/index.js.map +25 -131
- package/dist/lazy-guard.d.ts +4 -3
- package/dist/lazy-guard.d.ts.map +1 -1
- package/dist/lifecycle-slot.d.ts +31 -0
- package/dist/lifecycle-slot.d.ts.map +1 -0
- package/dist/live-rows-sql.d.ts +21 -0
- package/dist/live-rows-sql.d.ts.map +1 -0
- package/dist/mutation-state.d.ts +9 -2
- package/dist/mutation-state.d.ts.map +1 -1
- package/dist/mutation.d.ts +12 -0
- package/dist/mutation.d.ts.map +1 -1
- package/dist/schema.d.ts +33 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/shape-sync.d.ts +10 -0
- package/dist/shape-sync.d.ts.map +1 -1
- package/dist/store-path.d.ts +132 -0
- package/dist/store-path.d.ts.map +1 -0
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/types.d.ts +8 -0
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/testing.d.ts +27 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +17 -0
- package/dist/testing.js.map +11 -0
- package/dist/worker/attach-sync-client.d.ts +23 -2
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +5 -4
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/protocol.d.ts +89 -8
- package/dist/worker/protocol.d.ts.map +1 -1
- package/package.json +9 -4
- package/skills/core/SKILL.md +14 -1
- package/skills/operating/SKILL.md +75 -15
- package/src/boot-report.ts +287 -0
- package/src/export-data.ts +300 -0
- package/src/export-dump.ts +239 -0
- package/src/export-store.ts +309 -0
- package/src/index.ts +623 -82
- package/src/lazy-guard.ts +23 -9
- package/src/lifecycle-slot.ts +66 -0
- package/src/live-rows-sql.ts +45 -0
- package/src/mutation-state.ts +11 -2
- package/src/mutation.ts +42 -0
- package/src/schema.ts +120 -1
- package/src/shape-sync.ts +21 -0
- package/src/store-path.ts +249 -0
- package/src/sync/index.ts +11 -0
- package/src/sync/types.ts +9 -0
- package/src/testing.ts +53 -0
- package/src/worker/attach-sync-client.ts +101 -6
- package/src/worker/define-sync-worker.ts +196 -30
- package/src/worker/protocol.ts +110 -10
package/dist/lazy-guard.d.ts
CHANGED
|
@@ -21,9 +21,10 @@ export interface LazyGuardIndex {
|
|
|
21
21
|
readonly lazyKeys: ReadonlySet<string>;
|
|
22
22
|
/**
|
|
23
23
|
* Per lazy key, the exact quoted reference token(s) the compiled SQL emits when reading it: the synced
|
|
24
|
-
* table (and, for readwrite, its read-model view) as `"name"` or `"schema"."name"
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* table (and, for readwrite, its read-model view) as `"name"` or `"schema"."name"` — or, for a read
|
|
25
|
+
* PROJECTION (ADR-0025), its DISTINCT local identity (`localTable`, the `as` name) rather than the
|
|
26
|
+
* owner's physical table. Schema-qualified when the Drizzle object carries a schema — which makes the
|
|
27
|
+
* token collision-proof against bare aliases/CTEs.
|
|
27
28
|
*/
|
|
28
29
|
readonly lazyTokens: ReadonlyMap<string, readonly string[]>;
|
|
29
30
|
}
|
package/dist/lazy-guard.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-guard.d.ts","sourceRoot":"","sources":["../src/lazy-guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;;;;;;;;;;;GAeG;AAEH,sGAAsG;AACtG,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC
|
|
1
|
+
{"version":3,"file":"lazy-guard.d.ts","sourceRoot":"","sources":["../src/lazy-guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;;;;;;;;;;;GAeG;AAEH,sGAAsG;AACtG,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;CAC7D;AAED,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,cAAc,CAgC/E;AAOD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,CAM3F;AAaD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC,GAAG,IAAI,CAIP;AAED,uHAAuH;AACvH,qBAAa,6BAA8B,SAAQ,KAAK;IACtD,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAEtC,YAAY,SAAS,EAAE,SAAS,MAAM,EAAE,EAUvC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a lifecycle operation is attempted while another already holds the slot (ADR-0035). Carries
|
|
3
|
+
* the running operation's `label` so a caller (or a retry policy) can report exactly what it collided with.
|
|
4
|
+
* A distinct error type — not a bare `Error` — so callers can `instanceof`-branch a busy collision from a
|
|
5
|
+
* genuine operation failure.
|
|
6
|
+
*/
|
|
7
|
+
export declare class LifecycleBusyError extends Error {
|
|
8
|
+
/** The label of the lifecycle operation currently holding the slot. */
|
|
9
|
+
readonly runningLabel: string;
|
|
10
|
+
/** The label of the operation that was refused. */
|
|
11
|
+
readonly attemptedLabel: string;
|
|
12
|
+
constructor(attemptedLabel: string, runningLabel: string);
|
|
13
|
+
}
|
|
14
|
+
/** A single-occupancy lifecycle slot. One owner per store (`createSyncClient`); one operation at a time. */
|
|
15
|
+
export interface LifecycleSlot {
|
|
16
|
+
/**
|
|
17
|
+
* Run `fn` under the slot's exclusion. Rejects with a {@link LifecycleBusyError} — without invoking `fn`
|
|
18
|
+
* — if the slot is already occupied; otherwise holds the slot for `fn`'s lifetime and releases it in a
|
|
19
|
+
* `finally`, so a throwing operation never leaves the slot stuck. The occupancy check + claim run
|
|
20
|
+
* synchronously on entry (before the first `await`), so two calls issued in the same tick resolve
|
|
21
|
+
* deterministically: the first claims, the second is refused.
|
|
22
|
+
*/
|
|
23
|
+
run: <T>(label: string, fn: () => Promise<T>) => Promise<T>;
|
|
24
|
+
/** Whether an operation currently holds the slot. */
|
|
25
|
+
isBusy: () => boolean;
|
|
26
|
+
/** The label of the operation currently holding the slot, or `null` when free. */
|
|
27
|
+
runningLabel: () => string | null;
|
|
28
|
+
}
|
|
29
|
+
/** Create an empty lifecycle slot (ADR-0035 decision 4). */
|
|
30
|
+
export declare function createLifecycleSlot(): LifecycleSlot;
|
|
31
|
+
//# sourceMappingURL=lifecycle-slot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-slot.d.ts","sourceRoot":"","sources":["../src/lifecycle-slot.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,uEAAuE;IACvE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,mDAAmD;IACnD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,YAAY,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAOvD;CACF;AAED,4GAA4G;AAC5G,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5D,qDAAqD;IACrD,MAAM,EAAE,MAAM,OAAO,CAAC;IACtB,kFAAkF;IAClF,YAAY,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,4DAA4D;AAC5D,wBAAgB,mBAAmB,IAAI,aAAa,CAkBnD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make a live-read SQL statement SAFE TO MATERIALISE by giving every output column a UNIQUE explicit name.
|
|
3
|
+
*
|
|
4
|
+
* `fields` is the ordered list of unique output aliases — one per output column, in the compiled SQL's
|
|
5
|
+
* column order (Drizzle emits columns depth-first over the select's field keys, which are unique by
|
|
6
|
+
* construction). The statement is wrapped in a derived table with a POSITIONAL column-alias-list:
|
|
7
|
+
*
|
|
8
|
+
* SELECT * FROM (<sql>) "__pgx_live" ("<a0>", "<a1>", …)
|
|
9
|
+
*
|
|
10
|
+
* A plain `SELECT * FROM (<sql>)` does NOT dedupe — the inner duplicate names survive — so the
|
|
11
|
+
* column-alias-list is what renames every output column POSITIONALLY to a distinct name. The wrapped
|
|
12
|
+
* query materialises cleanly, and its rows come back keyed by the aliases (so same-named source columns
|
|
13
|
+
* keep DISTINCT values). `SELECT *` from the aliased derived table is safe precisely because the alias
|
|
14
|
+
* list has already made the names unique.
|
|
15
|
+
*
|
|
16
|
+
* Returns the SQL UNCHANGED when `fields` is absent or empty — the backward-compatible path for existing
|
|
17
|
+
* callers (raw SQL strings, or non-colliding queries that pass no `fields`): they keep name-keyed rows
|
|
18
|
+
* exactly as before. Only a caller that supplies `fields` opts into alias-keyed rows.
|
|
19
|
+
*/
|
|
20
|
+
export declare function wrapLiveQueryForMaterialization(sql: string, fields: readonly string[] | undefined): string;
|
|
21
|
+
//# sourceMappingURL=live-rows-sql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live-rows-sql.d.ts","sourceRoot":"","sources":["../src/live-rows-sql.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,CAM1G"}
|
package/dist/mutation-state.d.ts
CHANGED
|
@@ -30,11 +30,18 @@ export type MutationStatus = "pending" | "sending" | "acked" | "failed" | "quara
|
|
|
30
30
|
* - `sending -> conflicted` a stale write the reject-if-stale policy declined (ADR-0015).
|
|
31
31
|
* - `sending -> rejected` a business rejection from the authoritative endpoint (ADR-0022).
|
|
32
32
|
* - `sending -> pending` recoverSending re-queues an in-flight row on startup.
|
|
33
|
+
* - `pending -> quarantined` a RESTORE boot quarantines every non-terminal row recovered from a
|
|
34
|
+
* backup (ADR-0035 decision 6). A `pending` row is normally only ever claimed (`-> sending`), but a
|
|
35
|
+
* store restored from a backup must NOT auto-flush anything it recovered — the write path has no
|
|
36
|
+
* `mutationId` dedupe ledger, so replaying a recovered `pending`/`sending`/`failed` mutation is unsafe
|
|
37
|
+
* (silent last-write-wins reverts, create PK collisions). Restore is therefore the ONE producer of this
|
|
38
|
+
* edge; ordinary boots never move a `pending` row straight to `quarantined`.
|
|
33
39
|
* - `failed -> pending` retryFailed re-queues a failed row.
|
|
34
|
-
* - `failed -> quarantined` the hard max-attempts cap is reached; stop retrying
|
|
40
|
+
* - `failed -> quarantined` the hard max-attempts cap is reached; stop retrying (also the restore
|
|
41
|
+
* quarantine of a recovered `failed` row, ADR-0035 decision 6 — the edge already existed).
|
|
35
42
|
*/
|
|
36
43
|
export declare const MUTATION_TRANSITIONS: {
|
|
37
|
-
readonly pending: readonly ["sending"];
|
|
44
|
+
readonly pending: readonly ["sending", "quarantined"];
|
|
38
45
|
readonly sending: readonly ["acked", "failed", "quarantined", "conflicted", "rejected", "pending"];
|
|
39
46
|
readonly failed: readonly ["pending", "quarantined"];
|
|
40
47
|
readonly quarantined: readonly [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-state.d.ts","sourceRoot":"","sources":["../src/mutation-state.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,aAAa,GAAG,YAAY,GAAG,UAAU,CAAC;AAEpH
|
|
1
|
+
{"version":3,"file":"mutation-state.d.ts","sourceRoot":"","sources":["../src/mutation-state.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,aAAa,GAAG,YAAY,GAAG,UAAU,CAAC;AAEpH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;CAUqC,CAAC;AAEvE,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,cAAc,GAAG,OAAO,CAE3F;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,cAAc,GAAG,IAAI,CAI5F;AAED;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAShD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,CAUrG"}
|
package/dist/mutation.d.ts
CHANGED
|
@@ -146,6 +146,18 @@ export interface MutationRuntime<TRegistry extends SyncTableRegistry> {
|
|
|
146
146
|
reconcile: (table?: SyncTableName<TRegistry>) => Promise<void>;
|
|
147
147
|
retryFailed: (table?: SyncTableName<TRegistry>) => Promise<void>;
|
|
148
148
|
recoverSending: (table?: SyncTableName<TRegistry>) => Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Quarantine EVERY non-terminal journal row recovered from a backup (`pending`/`sending`/`failed` →
|
|
151
|
+
* `quarantined`) — the restore-boot rule (ADR-0035 decision 6). Nothing recovered from a store backup
|
|
152
|
+
* may ever auto-flush: the write path keeps `mutationId` in `operations_log` but never consults it, so
|
|
153
|
+
* there is no dedupe ledger, and a replayed mutation would silently re-apply stale values over newer
|
|
154
|
+
* writes on a last-write-wins table (and a replayed create collides on its PK). Terminal states
|
|
155
|
+
* (`acked`/`conflicted`/`rejected`) are left untouched. Run ONCE, on the restore boot only, AFTER
|
|
156
|
+
* `recoverSending` (which first lifts any `sending` back to `pending`); the app then inspects
|
|
157
|
+
* `diagnostics()` and resolves each row via `discardQuarantined` (quarantine is terminal — "release"
|
|
158
|
+
* means discard and re-author as a new mutation) before going online. A no-op on a clean journal.
|
|
159
|
+
*/
|
|
160
|
+
quarantineRecovered: (table?: SyncTableName<TRegistry>) => Promise<void>;
|
|
149
161
|
readMutationStats: (table?: SyncTableName<TRegistry>) => Promise<MutationDiagnostics>;
|
|
150
162
|
readMutationDetails: (table?: SyncTableName<TRegistry>) => Promise<MutationDetail[]>;
|
|
151
163
|
createOptimisticRecord: <TKey extends SyncTableName<TRegistry>>(table: TKey, input: SyncTableCreateInput<TRegistry, TKey>) => SyncTableRecord<TRegistry, TKey>;
|
package/dist/mutation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../src/mutation.ts"],"names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AgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAelF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAYzG;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,UAGzD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,MAAoB,UAG3F;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,MAAoB,UAE3G;AAED,wBAAgB,qBAAqB,CAAC,SAAS,SAAS,iBAAiB,EACvE,OAAO,EAAE,4BAA4B,CAAC,SAAS,CAAC,GAC/C,eAAe,CAAC,SAAS,CAAC,CAy3B5B"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -23,6 +23,39 @@ export declare function generateLocalSchemaSql<TRegistry extends SyncTableRegist
|
|
|
23
23
|
* identifiers assembled at construction), but it is GENERATED from the model, never hand-maintained.
|
|
24
24
|
*/
|
|
25
25
|
export declare function renderCreateTableSql(table: AnyPgTable): string[];
|
|
26
|
+
/**
|
|
27
|
+
* The `-t` allowlist for a Data export (ADR-0035 decision 1): the schema-qualified PHYSICAL synced table
|
|
28
|
+
* name for every registry entry that owns one, resolved through the SAME `getClientProjection` the local
|
|
29
|
+
* DDL generator uses — NOT re-derived by string convention. This is deliberately the physical `syncedTable`,
|
|
30
|
+
* never the read-model view (whose name can carry the entry name while the table differs): `-t` must target
|
|
31
|
+
* the tables that hold the rows. Read-projection and ephemeral entries are excluded (see
|
|
32
|
+
* {@link ownsPersistentSyncedTable}).
|
|
33
|
+
*/
|
|
34
|
+
export declare function collectDataExportSyncedTableNames<TRegistry extends SyncTableRegistry>(registry: TRegistry): string[];
|
|
35
|
+
/**
|
|
36
|
+
* The clone-cleanup SQL a Data export runs on its THROWAWAY clone before `pg_dump -t` (ADR-0035). The
|
|
37
|
+
* reconcile trigger sits ON the synced table (`AFTER INSERT/UPDATE/DELETE ON <syncedTable>`), so
|
|
38
|
+
* `pg_dump -t <syncedTable>` pulls the trigger into the dump — but its function is pgxsinkit machinery the
|
|
39
|
+
* data export deliberately EXCLUDES, so the artefact would carry a trigger referencing a missing function
|
|
40
|
+
* and fail to load into a vanilla Postgres. Because the clone is a memory-backed throwaway we fully own, we
|
|
41
|
+
* drop each reconcile trigger (and its now-unreferenced function) on it first, so `-t` yields clean,
|
|
42
|
+
* portable tables. Overlay/journal/views/metadata are NOT captured by `-t <syncedTable>` at all (a probe
|
|
43
|
+
* confirmed only the table, its PK, its data, and this trigger appear), so nothing else needs dropping.
|
|
44
|
+
* Returns `""` when the registry declares no writable owning table.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildDataExportCloneCleanupSql<TRegistry extends SyncTableRegistry>(registry: TRegistry): string;
|
|
47
|
+
/**
|
|
48
|
+
* The enum DDL header for a Data export artefact (ADR-0035 decision 1). `pg_dump -t <table>` emits the
|
|
49
|
+
* tables but NOT the enum types their columns reference, so the portable artefact is this generated header
|
|
50
|
+
* concatenated ahead of the `pg_dump` output. It reuses the SAME `CREATE TYPE` generation the local-schema
|
|
51
|
+
* generator emits ({@link buildCreateEnumTypeSql}) — every enum wrapped in an idempotent `IF NOT EXISTS`
|
|
52
|
+
* guard — restricted to the enums actually referenced by the exported (owning, persistent) tables, so a
|
|
53
|
+
* dropped/ephemeral-only enum never bloats the artefact. When the registry uses a non-`public` schema, a
|
|
54
|
+
* `CREATE SCHEMA IF NOT EXISTS` precedes the types (they live in that schema, and the header runs before
|
|
55
|
+
* `pg_dump`'s own schema creation), so the header is self-contained against a bare Postgres. Returns `""`
|
|
56
|
+
* when no exported table references an enum.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildDataExportEnumHeaderSql<TRegistry extends SyncTableRegistry>(registry: TRegistry): string;
|
|
26
59
|
/**
|
|
27
60
|
* Drop the reconstructible **read cache** — the synced tables and their read-model views
|
|
28
61
|
* and reconcile triggers/functions — while preserving the authority tables (overlay,
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAErF,OAAO,EAUL,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAyB9B;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAI/D,wBAAgB,sBAAsB,CAAC,SAAS,SAAS,iBAAiB,EAAE,QAAQ,EAAE,SAAS,UAuO9F;AA0CD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,CAchE;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAErF,OAAO,EAUL,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAyB9B;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAI/D,wBAAgB,sBAAsB,CAAC,SAAS,SAAS,iBAAiB,EAAE,QAAQ,EAAE,SAAS,UAuO9F;AA0CD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,CAchE;AAmLD;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAAC,SAAS,SAAS,iBAAiB,EAAE,QAAQ,EAAE,SAAS,GAAG,MAAM,EAAE,CAapH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,SAAS,SAAS,iBAAiB,EAAE,QAAQ,EAAE,SAAS,GAAG,MAAM,CAgB/G;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,SAAS,iBAAiB,EAAE,QAAQ,EAAE,SAAS,GAAG,MAAM,CAyB7G;AAgHD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,SAAS,iBAAiB,EAAE,QAAQ,EAAE,SAAS,GAAG,MAAM,CAkBtG;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,SAAS,iBAAiB,EAAE,QAAQ,EAAE,SAAS,GAAG,MAAM,CA8BvG;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,SAAS,iBAAiB,EACrE,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,MAAM,GACf,MAAM,CAkCR"}
|
package/dist/shape-sync.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ExternalHeadersRecord } from "@electric-sql/client";
|
|
2
2
|
import type { PGliteInterface } from "@electric-sql/pglite";
|
|
3
3
|
import { type Retention, type SubscriptionTiming, type SyncConfigInput, type SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
4
|
+
import type { BootStampCollector, GroupBootStamp } from "./boot-report";
|
|
4
5
|
import type { SyncNamespaceObj } from "./sync";
|
|
5
6
|
export interface ShapeSyncSpec {
|
|
6
7
|
electricUrl: string;
|
|
@@ -91,6 +92,13 @@ export interface StartConfiguredSyncOptions {
|
|
|
91
92
|
* without the all-eager-groups `onInitialSync` gate. The matching promise is {@link StartConfiguredSyncResult.groupReady}.
|
|
92
93
|
*/
|
|
93
94
|
onGroupReady?: (groupKey: string) => void;
|
|
95
|
+
/**
|
|
96
|
+
* Boot observability (ADR-0034): opens a per-group accumulator (rows/requests/fetch/apply wall) for each
|
|
97
|
+
* EAGER + PROMOTED boot group, stamped by the engine as the group's stream chain delivers and applies. A
|
|
98
|
+
* lazy on-demand start gets none — so a lazily-activated-later group never enters (or mutates) the report.
|
|
99
|
+
* Absent → no boot instrumentation.
|
|
100
|
+
*/
|
|
101
|
+
bootCollector?: BootStampCollector;
|
|
94
102
|
}
|
|
95
103
|
type SyncEnginePGlite = PGliteInterface & {
|
|
96
104
|
electric: SyncNamespaceObj;
|
|
@@ -158,6 +166,8 @@ interface StartGroupSyncOptions {
|
|
|
158
166
|
headers?: ExternalHeadersRecord;
|
|
159
167
|
/** Fresh-store prefetch overlap gate (ADR-0032 S4) — forwarded to the engine's `syncShapesToTables`. */
|
|
160
168
|
dbReady?: Promise<void>;
|
|
169
|
+
/** Boot observability (ADR-0034): the group's accumulator, stamped by the engine on delivery/apply. */
|
|
170
|
+
bootStamp?: GroupBootStamp;
|
|
161
171
|
onGroupInitialSync?: () => void;
|
|
162
172
|
onSyncError?: (error: Error) => void;
|
|
163
173
|
onAuthError?: () => void;
|
package/dist/shape-sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shape-sync.d.ts","sourceRoot":"","sources":["../src/shape-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EACL,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EAEvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG/C,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,U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AAI,CAAC,uBAAuB,EAAE,kBAAkB,GAAG,UAAU,CAAC,GAAG,MAAM,CAEjH"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a `storePath` is not a plain name (ADR-0036 decision 1): it carries a URL scheme (`://`) or
|
|
3
|
+
* is empty/whitespace-only. A distinct type — not a bare `Error` — so a caller can `instanceof`-branch the
|
|
4
|
+
* old dataDir-URL contract from a genuine store failure. The message names the plain-path contract and
|
|
5
|
+
* shows the corrected form, without echoing a resolvable URL a consumer might imitate.
|
|
6
|
+
*/
|
|
7
|
+
export declare class InvalidStorePathError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Thrown when a caller-owned PGlite handed to {@link CreateSyncClientOptions.pgliteInstance} /
|
|
12
|
+
* {@link CreateSyncClientOptions.precreatedPglite} is PROVABLY non-persistent (ADR-0036 decision 4): its
|
|
13
|
+
* `dataDir` is `undefined` (PGlite's in-memory default — the `new PGlite()` a copy-paste reaches) or begins
|
|
14
|
+
* `memory://`. Names both the why (durability semantics assume a persisted store) and the two exits, so a
|
|
15
|
+
* consumer is never left guessing which store to hand us instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare class NonPersistentStoreError extends Error {
|
|
18
|
+
constructor(observed: "in-memory-default" | "memory-scheme");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Thrown when a restore (`restoreFrom`, ADR-0035 decision 6) targets a store path whose backend store ALREADY
|
|
22
|
+
* exists. Restore is a CREATION-path feature — it boots a brand-new store on `loadDataDir` — and never
|
|
23
|
+
* overlays a live store: silently merging a backup into an existing datadir would corrupt it. A distinct type
|
|
24
|
+
* (not a bare `Error`) so a caller can `instanceof`-branch "target already there" from a genuine boot failure.
|
|
25
|
+
* The remedy is a deliberate manual {@link SyncClient.destroy} of the existing store first (never automatic —
|
|
26
|
+
* dropping a user's local store must be their explicit act).
|
|
27
|
+
*/
|
|
28
|
+
export declare class RestoreTargetExistsError extends Error {
|
|
29
|
+
constructor(storePath: string);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The module-internal marker a testing helper stamps onto the options object so option handling can select
|
|
33
|
+
* the memory backend / unlock the BYO refusal (ADR-0036 decision 3). `Symbol.for` (not a bare `Symbol()`)
|
|
34
|
+
* on purpose: each public entry point is bundled STANDALONE (`scripts/build-public-packages.ts`,
|
|
35
|
+
* `splitting: false`), so a plain module symbol would be DUPLICATED between the main bundle and the
|
|
36
|
+
* `./testing` bundle — two distinct symbols, and the marker set by `./testing` would be invisible to the
|
|
37
|
+
* main entry's reader. The global registry key guarantees ONE symbol across bundles. It is deliberately
|
|
38
|
+
* absent from the main entry's exports and from every public type, so a production consumer cannot name it.
|
|
39
|
+
*/
|
|
40
|
+
export declare const TEST_STORE_BACKEND: unique symbol;
|
|
41
|
+
/**
|
|
42
|
+
* What a testing helper's marker asks of option handling: `"memory"` mints a scheme-selected memory store
|
|
43
|
+
* (and, being ours-under-the-covers, also unlocks the BYO refusal); `"acknowledged"` only unlocks the BYO
|
|
44
|
+
* refusal for a caller who owns the (test) instance themselves. Both are visible, deliberate acts — an
|
|
45
|
+
* import whose name says what it is.
|
|
46
|
+
*/
|
|
47
|
+
export type TestStoreMarker = "memory" | "acknowledged";
|
|
48
|
+
/** An options object that MAY carry the internal testing marker (read via {@link readTestStoreMarker}). */
|
|
49
|
+
export type WithTestStoreMarker = {
|
|
50
|
+
[TEST_STORE_BACKEND]?: TestStoreMarker;
|
|
51
|
+
};
|
|
52
|
+
/** Read the internal testing marker off an options object, or `undefined` when none was stamped. */
|
|
53
|
+
export declare function readTestStoreMarker(options: unknown): TestStoreMarker | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* What {@link createClientPGlite} (and any store-opening seam) accepts as its store argument: a plain
|
|
56
|
+
* `storePath` string, or the option object a testing helper mints (`memoryStoreForTests(...)`) — carrying a
|
|
57
|
+
* `storePath` plus the invisible internal marker. Accepting the object form is what lets the testing
|
|
58
|
+
* helper's output flow STRAIGHT into `createClientPGlite(memoryStoreForTests("x"))` without a consumer ever
|
|
59
|
+
* naming a backend.
|
|
60
|
+
*/
|
|
61
|
+
export type StorePathInput = string | ({
|
|
62
|
+
storePath: string;
|
|
63
|
+
} & WithTestStoreMarker);
|
|
64
|
+
/** Normalise a {@link StorePathInput} to a plain path plus any internal memory-backend override it carried. */
|
|
65
|
+
export declare function normaliseStorePathInput(input: StorePathInput): {
|
|
66
|
+
storePath: string;
|
|
67
|
+
backendOverride?: "memory";
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The environment seam the backend derivation reads — factored out so a browser derivation is fakeable in
|
|
71
|
+
* a Bun unit test (there is no `indexedDB` there). `hasIndexedDb` is the browser/worker signal: PGlite's
|
|
72
|
+
* IndexedDB backend needs `indexedDB`, which a browser tab AND a Web/Shared/dedicated worker expose but
|
|
73
|
+
* Bun/Node do not — so it distinguishes "run in the browser" (idb) from "run on the server" (filesystem)
|
|
74
|
+
* without a DOM-lib dependency.
|
|
75
|
+
*/
|
|
76
|
+
export interface StoreEnv {
|
|
77
|
+
hasIndexedDb: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolve a plain {@link storePath} to the PGlite dataDir URL the store opens at — the ONE derivation point
|
|
81
|
+
* (ADR-0036 decision 2). Browser/worker (`indexedDB` present) → `idb://<storePath>`; Bun/Node → `file://<storePath>`
|
|
82
|
+
* (relative paths resolve against the working directory, exactly as PGlite's filesystem backend does — pass
|
|
83
|
+
* an absolute path if that matters). The `backendOverride` is internal-only: `"memory"` selects a
|
|
84
|
+
* scheme-selected `memory://<storePath>` store for the sanctioned test/ephemeral lanes.
|
|
85
|
+
*
|
|
86
|
+
* Rejects a scheme-bearing or empty/whitespace-only path with {@link InvalidStorePathError} — the storePath
|
|
87
|
+
* contract fails loudly at the boundary, never silently re-interpreted (no-legacy rule). The returned URL is
|
|
88
|
+
* internal plumbing; do not surface it to consumers as something to imitate.
|
|
89
|
+
*
|
|
90
|
+
* CRITICAL (ADR-0036 decision 5, probed on PGlite 0.5.4): memory selection is ALWAYS the scheme-selected
|
|
91
|
+
* `memory://` form, NEVER PGlite's explicit `fs: new MemoryFS()` option — `dumpDataDir` from an explicit-`fs`
|
|
92
|
+
* instance silently omits relation files created after initdb, so a restored clone raises "relation does not
|
|
93
|
+
* exist". Callers that need a memory store must route through this function, never construct `MemoryFS`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function resolveStoreDataDir(storePath: string, backendOverride?: "memory", env?: StoreEnv): string;
|
|
96
|
+
/**
|
|
97
|
+
* The IndexedDB database name a browser store occupies (ADR-0036) — a browser-only OPERATIONAL helper for
|
|
98
|
+
* orphan GC / corrupt-store deletion (`indexedDB.deleteDatabase(...)`), NOT part of the create path. PGlite
|
|
99
|
+
* maps `idb://<storePath>` to the IndexedDB database `/pglite/<storePath>` (its `WASM_PREFIX` `/pglite`
|
|
100
|
+
* joined with the path after the scheme; verified against `@electric-sql/pglite` 0.5.4 dist). Exposed so a
|
|
101
|
+
* consumer that GCs its own stores routes that PGlite-internal naming knowledge through the library rather
|
|
102
|
+
* than re-deriving the `/pglite/` prefix itself. Rejects a scheme-bearing/empty path exactly as
|
|
103
|
+
* {@link resolveStoreDataDir} does, so the two stay in lockstep.
|
|
104
|
+
*/
|
|
105
|
+
export declare function storeIndexedDbDatabaseName(storePath: string): string;
|
|
106
|
+
/**
|
|
107
|
+
* Classify a PGlite instance's `dataDir` for the BYO refusal (ADR-0036 decision 4). Returns the offending
|
|
108
|
+
* shape when the instance is PROVABLY non-persistent (`undefined` = PGlite's in-memory default; a
|
|
109
|
+
* `memory://` prefix = an explicit memory store), or `null` when it passes — anything else present,
|
|
110
|
+
* including exotic custom-VFS configs we cannot classify, is the caller's own call (the guard catches the
|
|
111
|
+
* two accidental non-persistent shapes, it is not a storage-backend whitelist).
|
|
112
|
+
*/
|
|
113
|
+
export declare function classifyNonPersistentDataDir(dataDir: string | undefined): "in-memory-default" | "memory-scheme" | null;
|
|
114
|
+
/**
|
|
115
|
+
* Does the backend store a plain {@link storePath} resolves to ALREADY exist? The fresh-target gate for a
|
|
116
|
+
* restore (ADR-0035 decision 6) — restore refuses a target that is already there. Per backend:
|
|
117
|
+
*
|
|
118
|
+
* - **memory** (`backendOverride === "memory"`) — a scheme-selected memory store is fresh by construction:
|
|
119
|
+
* it lives only for the instance about to be created, so there is nothing to collide with. Always `false`
|
|
120
|
+
* (the sanctioned test/ephemeral lane never blocks a restore).
|
|
121
|
+
* - **`file://`** (Bun/Node) — filesystem existence of the datadir directory. `node:fs` is imported
|
|
122
|
+
* DYNAMICALLY inside this branch, never at module top level, so a browser bundle (which only ever hits the
|
|
123
|
+
* `idb://` branch below) never pulls `node:fs` in. Relative paths resolve against the working directory,
|
|
124
|
+
* exactly as PGlite's filesystem backend and {@link resolveStoreDataDir} do.
|
|
125
|
+
* - **`idb://`** (browser/worker) — `indexedDB.databases()` enumerated for the store's database name
|
|
126
|
+
* ({@link storeIndexedDbDatabaseName}). BEST-EFFORT: `databases()` is unavailable on some engines (older
|
|
127
|
+
* Firefox, certain worker contexts); when absent we CANNOT prove existence, so we report `false` and let
|
|
128
|
+
* the restore proceed rather than fabricate a result — a real overlay collision would still surface as a
|
|
129
|
+
* PGlite-level boot failure. We never fake a positive.
|
|
130
|
+
*/
|
|
131
|
+
export declare function storeTargetExists(storePath: string, backendOverride?: "memory", env?: StoreEnv): Promise<boolean>;
|
|
132
|
+
//# sourceMappingURL=store-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-path.d.ts","sourceRoot":"","sources":["../src/store-path.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED;;;;;;GAMG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,QAAQ,EAAE,mBAAmB,GAAG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AAS,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,QAAQ,EAC1B,GAAG,GAAE,QAA2B,GAC/B,OAAO,CAAC,OAAO,CAAC,CAiBlB"}
|
package/dist/sync/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export * from "./types";
|
|
|
13
13
|
export declare function createSyncEngine(pg: PGliteInterface, options?: ElectricSyncOptions): Promise<{
|
|
14
14
|
namespace: {
|
|
15
15
|
initMetadataTables: () => Promise<void>;
|
|
16
|
-
syncShapesToTables: ({ key, registry, shapes, initialInsertMethod, onInitialSync, onError, onSyncError, onSyncActivity, dbReady, maxCommitRetries, commitRetryDelayMs, }: SyncShapesToTablesOptions) => Promise<SyncShapesToTablesResult>;
|
|
16
|
+
syncShapesToTables: ({ key, registry, shapes, initialInsertMethod, onInitialSync, onError, onSyncError, onSyncActivity, dbReady, bootStamp, maxCommitRetries, commitRetryDelayMs, }: SyncShapesToTablesOptions) => Promise<SyncShapesToTablesResult>;
|
|
17
17
|
syncShapeToTable: (options: SyncShapeToTableOptions) => Promise<SyncShapeToTableResult>;
|
|
18
18
|
deleteSubscription: (key: string) => Promise<void>;
|
|
19
19
|
};
|
package/dist/sync/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA0C5D,OAAO,EAEL,KAAK,mBAAmB,EAIxB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC5B,MAAM,SAAS,CAAC;AAEjB,cAAc,SAAS,CAAC;AAgDxB;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,mBAAmB;;kCA+BxD,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA0C5D,OAAO,EAEL,KAAK,mBAAmB,EAIxB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC5B,MAAM,SAAS,CAAC;AAEjB,cAAc,SAAS,CAAC;AAgDxB;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,mBAAmB;;kCA+BxD,OAAO,CAAC,IAAI,CAAC;6LA0BzC,yBAAyB,KAAG,OAAO,CAAC,wBAAwB,CAAC;oCAq0BvB,uBAAuB,KAAG,OAAO,CAAC,sBAAsB,CAAC;kCAqC3D,MAAM;;;GA0B9C;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC;AACtE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;AAEvD,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C,IAAI,EAAE,gBAAgB,CAAC;CACxB,CAAC"}
|
package/dist/sync/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ChangeMessage, FetchError, Row, ShapeStreamInterface, ShapeStreamOptions } from "@electric-sql/client";
|
|
2
2
|
import type { PgliteDatabase } from "drizzle-orm/pglite";
|
|
3
3
|
import type { SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
4
|
+
import type { GroupBootStamp } from "../boot-report";
|
|
4
5
|
export type { Row, ShapeStreamOptions } from "@electric-sql/client";
|
|
5
6
|
export type { MultiShapeMessages } from "@electric-sql/experimental";
|
|
6
7
|
export type Lsn = bigint;
|
|
@@ -75,6 +76,13 @@ export interface SyncShapesToTablesOptions {
|
|
|
75
76
|
* immediate retry instead of sleeping the real backoff.
|
|
76
77
|
*/
|
|
77
78
|
commitRetryDelayMs?: ((attempt: number) => number) | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Boot observability (ADR-0034): a per-group accumulator, stamped as this group's stream chain delivers
|
|
81
|
+
* batches (`onBatchDelivered`), applies commits into PGlite (`onApply`), and reaches initial sync
|
|
82
|
+
* (`markReady`). Present only for eager + promoted BOOT groups; absent for on-demand lazy starts and any
|
|
83
|
+
* boot without report instrumentation.
|
|
84
|
+
*/
|
|
85
|
+
bootStamp?: GroupBootStamp | undefined;
|
|
78
86
|
}
|
|
79
87
|
export interface SyncShapesToTablesResult {
|
|
80
88
|
unsubscribe: () => void;
|
package/dist/sync/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sync/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sync/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAKrD,YAAY,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACpE,YAAY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AS,CAAC;IAC/D,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;CACrE;AAED,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,MAAM,EAAE,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG;IAC9D,OAAO,EAAE;QAAE,SAAS,EAAE,QAAQ,CAAA;KAAE,CAAC;CAClC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The public shape of {@link memoryStoreForTests}'s output: just a `storePath`. The internal backend marker
|
|
3
|
+
* rides alongside at runtime but is deliberately absent from this type, so no production type mentions memory.
|
|
4
|
+
*/
|
|
5
|
+
export interface MemoryStoreForTests {
|
|
6
|
+
storePath: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Mint client store options that resolve to a scheme-selected in-memory store — the unit-test / ephemeral
|
|
10
|
+
* lane (ADR-0036 decision 3). Spread the result into `createSyncClient` (or `defineSyncWorker` where its
|
|
11
|
+
* options accept `storePath`): the client reads the internal marker and selects the memory backend.
|
|
12
|
+
*
|
|
13
|
+
* DURABILITY CAVEAT: a memory store is session-scoped, so pgxsinkit's persistent-retention guarantee and the
|
|
14
|
+
* optimistic Mutation journal's durability window are BOTH void on it — everything is lost when the instance
|
|
15
|
+
* closes. Use it only for tests and throwaway/ephemeral flows, never for anything a user expects to persist.
|
|
16
|
+
*/
|
|
17
|
+
export declare function memoryStoreForTests(storePath: string): MemoryStoreForTests;
|
|
18
|
+
/**
|
|
19
|
+
* Mint an options fragment that ACKNOWLEDGES a caller-owned test store, bypassing the BYO refusal
|
|
20
|
+
* (ADR-0036 decision 4) WITHOUT selecting a backend — for when the test supplies its own non-persistent
|
|
21
|
+
* PGlite via `pgliteInstance` / `precreatedPglite`. Spread it alongside that option.
|
|
22
|
+
*
|
|
23
|
+
* Same DURABILITY CAVEAT as {@link memoryStoreForTests}: only for tests / throwaway flows; a non-persistent
|
|
24
|
+
* store voids the retention + journal durability guarantees.
|
|
25
|
+
*/
|
|
26
|
+
export declare function testStoreAcknowledgment(): Record<never, never>;
|
|
27
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,mBAAmB,CAI1E;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAG9D"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/client/src/store-path.ts
|
|
3
|
+
var TEST_STORE_BACKEND = Symbol.for("pgxsinkit.internal.testStoreBackend");
|
|
4
|
+
|
|
5
|
+
// packages/client/src/testing.ts
|
|
6
|
+
function memoryStoreForTests(storePath) {
|
|
7
|
+
return { storePath, [TEST_STORE_BACKEND]: "memory" };
|
|
8
|
+
}
|
|
9
|
+
function testStoreAcknowledgment() {
|
|
10
|
+
return { [TEST_STORE_BACKEND]: "acknowledged" };
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
testStoreAcknowledgment,
|
|
14
|
+
memoryStoreForTests
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//# debugId=7077823A374194F864756E2164756E21
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/store-path.ts", "../src/testing.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// Store path contract (ADR-0036). The public seams (`createSyncClient`, `createClientPGlite`, the worker\n// attach/provision messages, the board store registry) take a `storePath` — a PLAIN path/name, never a\n// PGlite storage URL. The storage backend is DERIVED from the environment here, never chosen by the\n// consumer: IndexedDB in a browser (or a worker), the filesystem on Bun/Node. A memory-backed store is\n// not a product configuration — pgxsinkit's durability semantics (persistent retention, the optimistic\n// Mutation journal) assume a persisted store — so it exists ONLY behind the explicit testing\n// acknowledgment (`@pgxsinkit/client/testing`), carried into option handling as the module-internal\n// {@link TEST_STORE_BACKEND} symbol.\n//\n// This module is the ONLY place in the toolkit that assembles `idb://` / `file://` / `memory://` URLs (the\n// export machinery's throwaway clone, a later slice, is the one other internal `memory://` site). A\n// resolved URL is internal plumbing: it never leaks into config, results, reports, or errors as something\n// a consumer could copy back into a storePath — hence the scheme-rejection guard below fails the old\n// contract loudly at the boundary rather than silently re-interpreting it.\n\n/**\n * Thrown when a `storePath` is not a plain name (ADR-0036 decision 1): it carries a URL scheme (`://`) or\n * is empty/whitespace-only. A distinct type — not a bare `Error` — so a caller can `instanceof`-branch the\n * old dataDir-URL contract from a genuine store failure. The message names the plain-path contract and\n * shows the corrected form, without echoing a resolvable URL a consumer might imitate.\n */\nexport class InvalidStorePathError extends Error {\n constructor(message: string) {\n super(`[pgxsinkit] ${message}`);\n this.name = \"InvalidStorePathError\";\n }\n}\n\n/**\n * Thrown when a caller-owned PGlite handed to {@link CreateSyncClientOptions.pgliteInstance} /\n * {@link CreateSyncClientOptions.precreatedPglite} is PROVABLY non-persistent (ADR-0036 decision 4): its\n * `dataDir` is `undefined` (PGlite's in-memory default — the `new PGlite()` a copy-paste reaches) or begins\n * `memory://`. Names both the why (durability semantics assume a persisted store) and the two exits, so a\n * consumer is never left guessing which store to hand us instead.\n */\nexport class NonPersistentStoreError extends Error {\n constructor(observed: \"in-memory-default\" | \"memory-scheme\") {\n const reason =\n observed === \"in-memory-default\"\n ? \"its dataDir is undefined — PGlite's default is an in-memory store (`new PGlite()`)\"\n : \"its dataDir is a memory-backed store\";\n super(\n `[pgxsinkit] refusing a non-persistent PGlite instance: ${reason}. pgxsinkit's durability semantics ` +\n \"(persistent retention, the optimistic Mutation journal) assume a persisted store — a memory store \" +\n \"would silently forget acked-but-unflushed writes. Either hand a persisted instance (open it under a \" +\n \"plain store path so the backend is derived), or, for a test/ephemeral store, acknowledge it with \" +\n '`memoryStoreForTests` / `testStoreAcknowledgment` from \"@pgxsinkit/client/testing\" (ADR-0036).',\n );\n this.name = \"NonPersistentStoreError\";\n }\n}\n\n/**\n * Thrown when a restore (`restoreFrom`, ADR-0035 decision 6) targets a store path whose backend store ALREADY\n * exists. Restore is a CREATION-path feature — it boots a brand-new store on `loadDataDir` — and never\n * overlays a live store: silently merging a backup into an existing datadir would corrupt it. A distinct type\n * (not a bare `Error`) so a caller can `instanceof`-branch \"target already there\" from a genuine boot failure.\n * The remedy is a deliberate manual {@link SyncClient.destroy} of the existing store first (never automatic —\n * dropping a user's local store must be their explicit act).\n */\nexport class RestoreTargetExistsError extends Error {\n constructor(storePath: string) {\n super(\n `[pgxsinkit] refusing to restore into ${JSON.stringify(storePath)}: a store already exists at that path. ` +\n \"Restore only ever boots a brand-new store (it never overlays an existing one — that would corrupt the \" +\n \"datadir). Destroy the existing store first (a deliberate `destroy()`), then restore into the now-fresh \" +\n \"path (ADR-0035 decision 6).\",\n );\n this.name = \"RestoreTargetExistsError\";\n }\n}\n\n/**\n * The module-internal marker a testing helper stamps onto the options object so option handling can select\n * the memory backend / unlock the BYO refusal (ADR-0036 decision 3). `Symbol.for` (not a bare `Symbol()`)\n * on purpose: each public entry point is bundled STANDALONE (`scripts/build-public-packages.ts`,\n * `splitting: false`), so a plain module symbol would be DUPLICATED between the main bundle and the\n * `./testing` bundle — two distinct symbols, and the marker set by `./testing` would be invisible to the\n * main entry's reader. The global registry key guarantees ONE symbol across bundles. It is deliberately\n * absent from the main entry's exports and from every public type, so a production consumer cannot name it.\n */\nexport const TEST_STORE_BACKEND: unique symbol = Symbol.for(\"pgxsinkit.internal.testStoreBackend\");\n\n/**\n * What a testing helper's marker asks of option handling: `\"memory\"` mints a scheme-selected memory store\n * (and, being ours-under-the-covers, also unlocks the BYO refusal); `\"acknowledged\"` only unlocks the BYO\n * refusal for a caller who owns the (test) instance themselves. Both are visible, deliberate acts — an\n * import whose name says what it is.\n */\nexport type TestStoreMarker = \"memory\" | \"acknowledged\";\n\n/** An options object that MAY carry the internal testing marker (read via {@link readTestStoreMarker}). */\nexport type WithTestStoreMarker = { [TEST_STORE_BACKEND]?: TestStoreMarker };\n\n/** Read the internal testing marker off an options object, or `undefined` when none was stamped. */\nexport function readTestStoreMarker(options: unknown): TestStoreMarker | undefined {\n if (options == null || typeof options !== \"object\") return undefined;\n const marker = (options as WithTestStoreMarker)[TEST_STORE_BACKEND];\n return marker === \"memory\" || marker === \"acknowledged\" ? marker : undefined;\n}\n\n/**\n * What {@link createClientPGlite} (and any store-opening seam) accepts as its store argument: a plain\n * `storePath` string, or the option object a testing helper mints (`memoryStoreForTests(...)`) — carrying a\n * `storePath` plus the invisible internal marker. Accepting the object form is what lets the testing\n * helper's output flow STRAIGHT into `createClientPGlite(memoryStoreForTests(\"x\"))` without a consumer ever\n * naming a backend.\n */\nexport type StorePathInput = string | ({ storePath: string } & WithTestStoreMarker);\n\n/** Normalise a {@link StorePathInput} to a plain path plus any internal memory-backend override it carried. */\nexport function normaliseStorePathInput(input: StorePathInput): { storePath: string; backendOverride?: \"memory\" } {\n if (typeof input === \"string\") return { storePath: input };\n return {\n storePath: input.storePath,\n ...(readTestStoreMarker(input) === \"memory\" ? { backendOverride: \"memory\" as const } : {}),\n };\n}\n\n/**\n * The environment seam the backend derivation reads — factored out so a browser derivation is fakeable in\n * a Bun unit test (there is no `indexedDB` there). `hasIndexedDb` is the browser/worker signal: PGlite's\n * IndexedDB backend needs `indexedDB`, which a browser tab AND a Web/Shared/dedicated worker expose but\n * Bun/Node do not — so it distinguishes \"run in the browser\" (idb) from \"run on the server\" (filesystem)\n * without a DOM-lib dependency.\n */\nexport interface StoreEnv {\n hasIndexedDb: boolean;\n}\n\n/** Detect the ambient store environment off `globalThis` (the library carries no DOM lib dependency). */\nfunction detectStoreEnv(): StoreEnv {\n return { hasIndexedDb: typeof (globalThis as { indexedDB?: unknown }).indexedDB !== \"undefined\" };\n}\n\n/**\n * Resolve a plain {@link storePath} to the PGlite dataDir URL the store opens at — the ONE derivation point\n * (ADR-0036 decision 2). Browser/worker (`indexedDB` present) → `idb://<storePath>`; Bun/Node → `file://<storePath>`\n * (relative paths resolve against the working directory, exactly as PGlite's filesystem backend does — pass\n * an absolute path if that matters). The `backendOverride` is internal-only: `\"memory\"` selects a\n * scheme-selected `memory://<storePath>` store for the sanctioned test/ephemeral lanes.\n *\n * Rejects a scheme-bearing or empty/whitespace-only path with {@link InvalidStorePathError} — the storePath\n * contract fails loudly at the boundary, never silently re-interpreted (no-legacy rule). The returned URL is\n * internal plumbing; do not surface it to consumers as something to imitate.\n *\n * CRITICAL (ADR-0036 decision 5, probed on PGlite 0.5.4): memory selection is ALWAYS the scheme-selected\n * `memory://` form, NEVER PGlite's explicit `fs: new MemoryFS()` option — `dumpDataDir` from an explicit-`fs`\n * instance silently omits relation files created after initdb, so a restored clone raises \"relation does not\n * exist\". Callers that need a memory store must route through this function, never construct `MemoryFS`.\n */\nexport function resolveStoreDataDir(\n storePath: string,\n backendOverride?: \"memory\",\n env: StoreEnv = detectStoreEnv(),\n): string {\n if (typeof storePath !== \"string\" || storePath.trim().length === 0) {\n throw new InvalidStorePathError(\n 'invalid storePath: expected a non-empty plain store name (e.g. \"my-app-store\"); received an empty or whitespace-only value (ADR-0036).',\n );\n }\n if (storePath.includes(\"://\")) {\n throw new InvalidStorePathError(\n `invalid storePath ${JSON.stringify(storePath)}: a store path is a plain name, not a storage URL. ` +\n 'Pass just the name (e.g. \"my-app-store\") — the storage backend (IndexedDB in a browser, the ' +\n \"filesystem on Bun/Node) is derived for you; drop the scheme prefix (ADR-0036).\",\n );\n }\n if (backendOverride === \"memory\") return `memory://${storePath}`;\n return env.hasIndexedDb ? `idb://${storePath}` : `file://${storePath}`;\n}\n\n/**\n * The IndexedDB database name a browser store occupies (ADR-0036) — a browser-only OPERATIONAL helper for\n * orphan GC / corrupt-store deletion (`indexedDB.deleteDatabase(...)`), NOT part of the create path. PGlite\n * maps `idb://<storePath>` to the IndexedDB database `/pglite/<storePath>` (its `WASM_PREFIX` `/pglite`\n * joined with the path after the scheme; verified against `@electric-sql/pglite` 0.5.4 dist). Exposed so a\n * consumer that GCs its own stores routes that PGlite-internal naming knowledge through the library rather\n * than re-deriving the `/pglite/` prefix itself. Rejects a scheme-bearing/empty path exactly as\n * {@link resolveStoreDataDir} does, so the two stay in lockstep.\n */\nexport function storeIndexedDbDatabaseName(storePath: string): string {\n if (typeof storePath !== \"string\" || storePath.trim().length === 0) {\n throw new InvalidStorePathError(\n \"invalid storePath: storeIndexedDbDatabaseName expects a non-empty plain store name (ADR-0036).\",\n );\n }\n if (storePath.includes(\"://\")) {\n throw new InvalidStorePathError(\n `invalid storePath ${JSON.stringify(storePath)}: storeIndexedDbDatabaseName expects a plain name, not a storage URL (ADR-0036).`,\n );\n }\n return `/pglite/${storePath}`;\n}\n\n/**\n * Classify a PGlite instance's `dataDir` for the BYO refusal (ADR-0036 decision 4). Returns the offending\n * shape when the instance is PROVABLY non-persistent (`undefined` = PGlite's in-memory default; a\n * `memory://` prefix = an explicit memory store), or `null` when it passes — anything else present,\n * including exotic custom-VFS configs we cannot classify, is the caller's own call (the guard catches the\n * two accidental non-persistent shapes, it is not a storage-backend whitelist).\n */\nexport function classifyNonPersistentDataDir(\n dataDir: string | undefined,\n): \"in-memory-default\" | \"memory-scheme\" | null {\n if (dataDir == null) return \"in-memory-default\";\n if (dataDir.startsWith(\"memory://\")) return \"memory-scheme\";\n return null;\n}\n\n/**\n * Does the backend store a plain {@link storePath} resolves to ALREADY exist? The fresh-target gate for a\n * restore (ADR-0035 decision 6) — restore refuses a target that is already there. Per backend:\n *\n * - **memory** (`backendOverride === \"memory\"`) — a scheme-selected memory store is fresh by construction:\n * it lives only for the instance about to be created, so there is nothing to collide with. Always `false`\n * (the sanctioned test/ephemeral lane never blocks a restore).\n * - **`file://`** (Bun/Node) — filesystem existence of the datadir directory. `node:fs` is imported\n * DYNAMICALLY inside this branch, never at module top level, so a browser bundle (which only ever hits the\n * `idb://` branch below) never pulls `node:fs` in. Relative paths resolve against the working directory,\n * exactly as PGlite's filesystem backend and {@link resolveStoreDataDir} do.\n * - **`idb://`** (browser/worker) — `indexedDB.databases()` enumerated for the store's database name\n * ({@link storeIndexedDbDatabaseName}). BEST-EFFORT: `databases()` is unavailable on some engines (older\n * Firefox, certain worker contexts); when absent we CANNOT prove existence, so we report `false` and let\n * the restore proceed rather than fabricate a result — a real overlay collision would still surface as a\n * PGlite-level boot failure. We never fake a positive.\n */\nexport async function storeTargetExists(\n storePath: string,\n backendOverride?: \"memory\",\n env: StoreEnv = detectStoreEnv(),\n): Promise<boolean> {\n const dataDir = resolveStoreDataDir(storePath, backendOverride, env);\n if (dataDir.startsWith(\"memory://\")) return false;\n if (dataDir.startsWith(\"file://\")) {\n // The datadir path is everything after the `file://` scheme; `node:fs` handles absolute and\n // cwd-relative paths identically to PGlite's own filesystem backend.\n const path = dataDir.slice(\"file://\".length);\n const { existsSync } = await import(\"node:fs\");\n return existsSync(path);\n }\n // `idb://` — enumerate the IndexedDB databases for this store's database name. `databases()` is optional in\n // the spec, so guard it: when absent, best-effort `false` (documented above), never a fabricated positive.\n const idb = (globalThis as { indexedDB?: { databases?: () => Promise<Array<{ name?: string }>> } }).indexedDB;\n if (idb?.databases == null) return false;\n const target = storeIndexedDbDatabaseName(storePath);\n const databases = await idb.databases();\n return databases.some((db) => db.name === target);\n}\n",
|
|
6
|
+
"// `@pgxsinkit/client/testing` — the ONLY sanctioned door to a memory-backed store (ADR-0036 decision 3).\n//\n// pgxsinkit's durability semantics assume a persisted store, so the production API surface cannot express a\n// memory store: `createSyncClient`/`createClientPGlite` take a plain `storePath` whose backend is derived\n// (IndexedDB / filesystem), and the BYO seam refuses a provably non-persistent instance. Genuine memory\n// stores are needed in exactly two of OUR places — the unit-test lane (speed + isolation) and the export\n// machinery's throwaway clone — and this subpath serves the first: an import whose NAME says what it is, so\n// reaching a memory store is always a visible, deliberate act. App bundles never import it, so the whole\n// module (and any mention of memory) tree-shakes away.\n//\n// The helpers mint plain options objects that ALSO carry the module-internal {@link TEST_STORE_BACKEND}\n// marker at runtime — invisible in the public return type. Consumers SPREAD them into the client options:\n//\n// createSyncClient({ ...memoryStoreForTests(\"my-test\"), registry, electricUrl, writeUrl })\n// createSyncClient({ ...testStoreAcknowledgment(), pgliteInstance, registry, electricUrl, writeUrl })\n\nimport { TEST_STORE_BACKEND } from \"./store-path\";\n\n/**\n * The public shape of {@link memoryStoreForTests}'s output: just a `storePath`. The internal backend marker\n * rides alongside at runtime but is deliberately absent from this type, so no production type mentions memory.\n */\nexport interface MemoryStoreForTests {\n storePath: string;\n}\n\n/**\n * Mint client store options that resolve to a scheme-selected in-memory store — the unit-test / ephemeral\n * lane (ADR-0036 decision 3). Spread the result into `createSyncClient` (or `defineSyncWorker` where its\n * options accept `storePath`): the client reads the internal marker and selects the memory backend.\n *\n * DURABILITY CAVEAT: a memory store is session-scoped, so pgxsinkit's persistent-retention guarantee and the\n * optimistic Mutation journal's durability window are BOTH void on it — everything is lost when the instance\n * closes. Use it only for tests and throwaway/ephemeral flows, never for anything a user expects to persist.\n */\nexport function memoryStoreForTests(storePath: string): MemoryStoreForTests {\n // The marker is a symbol-keyed property, so it survives an object spread but is invisible to the public\n // type and to `Object.keys`. Cast because the return TYPE deliberately hides it (ADR-0036 decision 3).\n return { storePath, [TEST_STORE_BACKEND]: \"memory\" } as MemoryStoreForTests;\n}\n\n/**\n * Mint an options fragment that ACKNOWLEDGES a caller-owned test store, bypassing the BYO refusal\n * (ADR-0036 decision 4) WITHOUT selecting a backend — for when the test supplies its own non-persistent\n * PGlite via `pgliteInstance` / `precreatedPglite`. Spread it alongside that option.\n *\n * Same DURABILITY CAVEAT as {@link memoryStoreForTests}: only for tests / throwaway flows; a non-persistent\n * store voids the retention + journal durability guarantees.\n */\nexport function testStoreAcknowledgment(): Record<never, never> {\n // An empty public shape carrying only the internal marker — nothing for a consumer to configure.\n return { [TEST_STORE_BACKEND]: \"acknowledged\" } as Record<never, never>;\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";;AAiFO,IAAM,qBAAoC,OAAO,IAAI,qCAAqC;;;AC9C1F,SAAS,mBAAmB,CAAC,WAAwC;AAAA,EAG1E,OAAO,EAAE,YAAY,qBAAqB,SAAS;AAAA;AAW9C,SAAS,uBAAuB,GAAyB;AAAA,EAE9D,OAAO,GAAG,qBAAqB,eAAe;AAAA;",
|
|
9
|
+
"debugId": "7077823A374194F864756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|