@pgxsinkit/client 0.2.7 → 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/README.md +2 -1
- package/dist/boot-report.d.ts +5 -2
- package/dist/boot-report.d.ts.map +1 -1
- package/dist/circuits/envelope-to-change.d.ts +35 -0
- package/dist/circuits/envelope-to-change.d.ts.map +1 -0
- package/dist/circuits/group-sync.d.ts +123 -0
- package/dist/circuits/group-sync.d.ts.map +1 -0
- package/dist/circuits/shape-group.d.ts +77 -0
- package/dist/circuits/shape-group.d.ts.map +1 -0
- package/dist/circuits/stream-inbox.d.ts +126 -0
- package/dist/circuits/stream-inbox.d.ts.map +1 -0
- package/dist/circuits/stream-source.d.ts +90 -0
- package/dist/circuits/stream-source.d.ts.map +1 -0
- package/dist/circuits/subscription-client.d.ts +143 -0
- package/dist/circuits/subscription-client.d.ts.map +1 -0
- package/dist/circuits/sync-engine.d.ts +131 -0
- package/dist/circuits/sync-engine.d.ts.map +1 -0
- package/dist/debug.d.ts +0 -10
- package/dist/debug.d.ts.map +1 -1
- package/dist/export-dump.d.ts.map +1 -1
- package/dist/index.d.ts +47 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6258 -6443
- package/dist/index.js.map +26 -26
- package/dist/local-tables.d.ts +1 -1
- package/dist/local-tables.d.ts.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/sync/apply.d.ts +13 -21
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/copy.d.ts +8 -8
- package/dist/sync/fold.d.ts +40 -0
- package/dist/sync/fold.d.ts.map +1 -0
- package/dist/sync/metadata-tables.d.ts +25 -1
- package/dist/sync/metadata-tables.d.ts.map +1 -1
- package/dist/sync/subscription-state.d.ts +21 -2
- package/dist/sync/subscription-state.d.ts.map +1 -1
- package/dist/sync/types.d.ts +9 -129
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/testing.js +3 -3
- package/dist/testing.js.map +2 -2
- package/dist/worker/attach-sync-client.d.ts +3 -1
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +17 -1
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/engine-control.d.ts +53 -0
- package/dist/worker/engine-control.d.ts.map +1 -1
- package/package.json +4 -5
- package/skills/core/SKILL.md +72 -55
- package/skills/operating/SKILL.md +120 -120
- package/src/boot-report.ts +4 -3
- package/src/circuits/envelope-to-change.ts +102 -0
- package/src/circuits/group-sync.ts +1047 -0
- package/src/circuits/shape-group.ts +158 -0
- package/src/circuits/stream-inbox.ts +225 -0
- package/src/circuits/stream-source.ts +165 -0
- package/src/circuits/subscription-client.ts +353 -0
- package/src/circuits/sync-engine.ts +641 -0
- package/src/debug.ts +1 -85
- package/src/export-dump.ts +3 -2
- package/src/index.ts +290 -273
- package/src/lazy-guard.ts +1 -1
- package/src/local-tables.ts +9 -2
- package/src/schema.ts +2 -11
- package/src/sync/apply.ts +72 -110
- package/src/sync/copy.ts +15 -15
- package/src/sync/fold.ts +94 -0
- package/src/sync/metadata-tables.ts +42 -1
- package/src/sync/subscription-state.ts +21 -3
- package/src/sync/types.ts +13 -141
- package/src/testing.ts +2 -2
- package/src/worker/attach-sync-client.ts +8 -1
- package/src/worker/define-sync-worker.ts +122 -13
- package/src/worker/engine-control.ts +89 -0
- package/dist/read-stream-stall.d.ts +0 -54
- package/dist/read-stream-stall.d.ts.map +0 -1
- package/dist/shape-sync.d.ts +0 -207
- package/dist/shape-sync.d.ts.map +0 -1
- package/dist/sync/index.d.ts +0 -32
- package/dist/sync/index.d.ts.map +0 -1
- package/dist/sync/nudge.d.ts +0 -49
- package/dist/sync/nudge.d.ts.map +0 -1
- package/dist/sync/shape-inbox.d.ts +0 -215
- package/dist/sync/shape-inbox.d.ts.map +0 -1
- package/dist/sync/tags.d.ts +0 -142
- package/dist/sync/tags.d.ts.map +0 -1
- package/dist/sync-auth.d.ts +0 -53
- package/dist/sync-auth.d.ts.map +0 -1
- package/src/read-stream-stall.ts +0 -102
- package/src/shape-sync.ts +0 -533
- package/src/sync/index.ts +0 -1124
- package/src/sync/nudge.ts +0 -110
- package/src/sync/shape-inbox.ts +0 -566
- package/src/sync/tags.ts +0 -390
- package/src/sync-auth.ts +0 -117
package/dist/local-tables.d.ts
CHANGED
|
@@ -831,7 +831,7 @@ export declare function getReadModelView<TRegistry extends SyncTableRegistry, TK
|
|
|
831
831
|
* appliers need is derived once from the registry entry — the real projected synced table object, its
|
|
832
832
|
* columns indexed by DB column name, the primary-key column names, and the model-derived column types —
|
|
833
833
|
* so the appliers author over Drizzle objects (no name/schema strings, no `information_schema` probe).
|
|
834
|
-
* Resolved once per shape at subscribe time; reused for every message.
|
|
834
|
+
* Resolved once per shape at subscribe time; reused for every message. Streamed change rows are keyed
|
|
835
835
|
* by DB **column name**, while Drizzle DML keys by **property key**, so both indexes are carried.
|
|
836
836
|
*/
|
|
837
837
|
export interface ApplyTarget {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-tables.d.ts","sourceRoot":"","sources":["../src/local-tables.ts"],"names":[],"mappings":"AAEA,OAAO,EAaL,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAgH9B,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;EAAwE,CAAC;AAEhG;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,iBAAiB,CAAC;AAExD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,gBAAgB,CAElF;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,iBAAiB,GAAG,WAAW,CASvE;AAED,+FAA+F;AAC/F,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,cAAc,CAY7E"}
|
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,EAWL,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;
|
|
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,EAWL,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAuB9B,kGAAkG;AAClG,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,YAAY,qBAAqB,CAAC;AAE/C,iHAAiH;AACjH,eAAO,MAAM,eAAe,yBAAwB,CAAC;AACrD,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAC/D;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,6BAA6B,CAAC;AACvE,4EAA4E;AAC5E,eAAO,MAAM,+BAA+B,UAAU,CAAC;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,4BAA4B,CAAC;AAE5D;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6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AUG;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,CAmCvG;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,SAAS,iBAAiB,EACrE,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,MAAM,GACf,MAAM,CA2BR"}
|
package/dist/sync/apply.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import type { ChangeMessage, Row } from "@electric-sql/client";
|
|
2
1
|
import type { PGliteInterface, Transaction } from "@electric-sql/pglite";
|
|
2
|
+
import { type SyncChange } from "@pgxsinkit/contracts";
|
|
3
3
|
import type { ApplyTarget } from "../local-tables";
|
|
4
|
-
import type {
|
|
4
|
+
import type { UpsertChangeMessage } from "./types";
|
|
5
5
|
export interface ApplyMessageToTableOptions {
|
|
6
6
|
pg: PGliteInterface | Transaction;
|
|
7
7
|
target: ApplyTarget;
|
|
8
|
-
message:
|
|
8
|
+
message: SyncChange;
|
|
9
9
|
debug: boolean;
|
|
10
10
|
}
|
|
11
|
-
export declare function applyMessageToTable({ pg, target, message, debug }: ApplyMessageToTableOptions): Promise<import("@electric-sql/pglite").Results<never
|
|
11
|
+
export declare function applyMessageToTable({ pg, target, message, debug }: ApplyMessageToTableOptions): Promise<import("@electric-sql/pglite").Results<never>>;
|
|
12
12
|
export interface BulkApplyMessagesToTableOptions {
|
|
13
13
|
pg: PGliteInterface | Transaction;
|
|
14
14
|
target: ApplyTarget;
|
|
15
|
-
messages:
|
|
15
|
+
messages: UpsertChangeMessage[];
|
|
16
16
|
debug: boolean;
|
|
17
17
|
}
|
|
18
18
|
export declare function applyInsertsToTable({ pg, target, messages, debug }: BulkApplyMessagesToTableOptions): Promise<void>;
|
|
19
19
|
/**
|
|
20
|
-
* Bulk **upsert** for
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* for a pk-only table). The plain
|
|
25
|
-
*
|
|
26
|
-
*
|
|
20
|
+
* Bulk **upsert** — the applier for the wire's `upsert` verb (ADR-0058 decision 1). The engine states a
|
|
21
|
+
* row's new value rather than claiming anything about what preceded it, so an upsert routinely names a
|
|
22
|
+
* row already present locally: a subquery flip, a scope grant, a backfill replay, or a re-delivery on a
|
|
23
|
+
* resume from before its offset. So it is applied idempotently: `INSERT … ON CONFLICT (pk) DO UPDATE`
|
|
24
|
+
* refreshes to the authoritative value (or `DO NOTHING` for a pk-only table). The plain `INSERT` of the
|
|
25
|
+
* backfill path ({@link applyInsertsToTable}) is intentionally NOT used here, because a present row is
|
|
26
|
+
* expected, not a bug. Batched by parameter count (steady-state volume is incremental, not a backfill).
|
|
27
27
|
*/
|
|
28
28
|
export declare function applyUpsertsToTable({ pg, target, messages, debug }: BulkKeyedApplyOptions): Promise<void>;
|
|
29
29
|
export declare function applyMessagesToTableWithJson(options: BulkApplyMessagesToTableOptions): Promise<void>;
|
|
@@ -43,7 +43,7 @@ export interface BulkKeyedApplyOptions {
|
|
|
43
43
|
pg: PGliteInterface | Transaction;
|
|
44
44
|
target: ApplyTarget;
|
|
45
45
|
/** Folded messages: for deletes the value carries the PK; for updates the PK plus merged columns. */
|
|
46
|
-
messages:
|
|
46
|
+
messages: SyncChange[];
|
|
47
47
|
debug: boolean;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
@@ -51,12 +51,4 @@ export interface BulkKeyedApplyOptions {
|
|
|
51
51
|
* because the read-path fold already left **one row per PK** — no same-PK duplicate in the source.
|
|
52
52
|
*/
|
|
53
53
|
export declare function applyBulkDeletesToTable({ pg, target, messages, debug }: BulkKeyedApplyOptions): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Bulk UPDATE via `UPDATE … FROM json_to_recordset(…)` (ADR-0014 Phase 3), **grouped by the set of
|
|
56
|
-
* non-PK columns** each row carries. Electric's default replica sends only the changed columns, so
|
|
57
|
-
* two rows in one batch can set different columns; one `UPDATE … FROM` per distinct column-set keeps
|
|
58
|
-
* each statement uniform. Safe from the same-PK join hazard because the fold already left one row per
|
|
59
|
-
* PK, so no PK appears twice within a group.
|
|
60
|
-
*/
|
|
61
|
-
export declare function applyBulkUpdatesToTable({ pg, target, messages, debug }: BulkKeyedApplyOptions): Promise<void>;
|
|
62
54
|
//# sourceMappingURL=apply.d.ts.map
|
package/dist/sync/apply.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIzE,OAAO,EAAmB,KAAK,UAAU,EAAqC,MAAM,sBAAsB,CAAC;AAE3G,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA4EnD,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,eAAe,GAAG,WAAW,CAAC;IAClC,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,0BAA0B,0DA0BnG;AAED,MAAM,WAAW,+BAA+B;IAC9C,EAAE,EAAE,eAAe,GAAG,WAAW,CAAC;IAClC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC;CAChB;AAsHD,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,+BAA+B,iBA8CzG;AAyDD;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,qBAAqB,iBA+B/F;AAgGD,wBAAsB,4BAA4B,CAAC,OAAO,EAAE,+BAA+B,iBAE1F;AAED;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,+BAA+B,iBAKzF;AAsBD,wBAAsB,4BAA4B,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,+BAA+B,iBAwClH;AAqBD,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,eAAe,GAAG,WAAW,CAAC;IAClC,MAAM,EAAE,WAAW,CAAC;IACpB,qGAAqG;IACrG,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,qBAAqB,iBA+BnG"}
|
package/dist/sync/copy.d.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Serialization of JavaScript values into a PostgreSQL `COPY ... WITH (FORMAT
|
|
3
3
|
* text)` stream.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* arrays, and every other type
|
|
10
|
-
* (a `string`). To feed those values back into
|
|
11
|
-
* turn each value into the exact text Postgres'
|
|
12
|
-
* apply the COPY framing.
|
|
5
|
+
* Values reach this module already decoded — the read path hands the applier
|
|
6
|
+
* JSON cell values, never Postgres wire text — so the runtime types it accepts
|
|
7
|
+
* are the decoded ones: `int2`/`int4`/`float4`/`float8` as `number`, `bool` as
|
|
8
|
+
* `boolean`, `json`/`jsonb` as parsed objects/arrays, array columns as
|
|
9
|
+
* (possibly nested) JS arrays, `int8` as `bigint`, and every other type as its
|
|
10
|
+
* raw Postgres text representation (a `string`). To feed those values back into
|
|
11
|
+
* `COPY` we have to reverse that: turn each value into the exact text Postgres'
|
|
12
|
+
* input functions expect, then apply the COPY framing.
|
|
13
13
|
*
|
|
14
14
|
* Rather than invent an escaping scheme (the previous CSV-based approach broke
|
|
15
15
|
* on arrays, JSON, embedded delimiters, etc.) this is a faithful port of the
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SyncChange } from "@pgxsinkit/contracts";
|
|
2
|
+
import type { UpsertChangeMessage } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* A drained shape batch folded to **one net operation per primary key** (ADR-0014 decision 1).
|
|
5
|
+
* Each PK appears in at most one of `deletes`/`upserts` — except a *re-created* PK
|
|
6
|
+
* (`[delete, … , upsert]`), which appears in both so the pre-existing row is cleared before the new
|
|
7
|
+
* one lands. The Sync applier therefore runs two bulk statements **in the order `deletes → upserts`**:
|
|
8
|
+
* that ordering is what makes a re-create drop local-only column state instead of inheriting it, and
|
|
9
|
+
* every other PK is touched by exactly one statement.
|
|
10
|
+
*/
|
|
11
|
+
export interface FoldedShapeBatch {
|
|
12
|
+
/** PKs to delete — net-`delete` keys, plus the clearing delete of each re-created key. */
|
|
13
|
+
deletes: SyncChange[];
|
|
14
|
+
/** Full rows to upsert — net-`upsert` keys, plus each re-created key's new row. */
|
|
15
|
+
upserts: UpsertChangeMessage[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Fold a drained shape batch (ordered by LSN, one shape) to one net operation per primary key
|
|
19
|
+
* (ADR-0014 decision 1), so the read path can bulk-apply without the `INSERT … SELECT
|
|
20
|
+
* json_to_recordset(…)` same-PK join hazard (which uses **one arbitrary** matching row when the
|
|
21
|
+
* source holds duplicate PKs). Each PK's ops are replayed in stream order down to:
|
|
22
|
+
*
|
|
23
|
+
* - **trailing `delete`** ⇒ a single DELETE;
|
|
24
|
+
* - **upserts, no preceding delete** ⇒ a single UPSERT of the net row;
|
|
25
|
+
* - **re-created** (`[delete, … , upsert, …]`, no trailing delete) ⇒ DELETE **and** UPSERT.
|
|
26
|
+
*
|
|
27
|
+
* The clearing DELETE on a re-create is not redundant against an upsert. `ON CONFLICT DO UPDATE`
|
|
28
|
+
* refreshes only the columns the shape projects; a row that genuinely left and re-entered must not
|
|
29
|
+
* keep local-only column values from its previous life, so it is removed first.
|
|
30
|
+
*
|
|
31
|
+
* There is no `updates` bucket and no malformed-batch case, because there is no third verb: the
|
|
32
|
+
* engine emits `upsert | delete` and nothing else ({@link SyncOperation}). The old
|
|
33
|
+
* "update after delete ⇒ throw" guard checked for a stream state the vocabulary can no longer
|
|
34
|
+
* express.
|
|
35
|
+
*
|
|
36
|
+
* Pure and dependency-free by design (ADR-0014 / ISS-06): property-tested against the oracle
|
|
37
|
+
* *fold-then-bulk ≡ ordered per-row apply* over random same-PK sequences and random initial state.
|
|
38
|
+
*/
|
|
39
|
+
export declare function foldChangeBatch(messages: SyncChange[]): FoldedShapeBatch;
|
|
40
|
+
//# sourceMappingURL=fold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fold.d.ts","sourceRoot":"","sources":["../../src/sync/fold.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,sBAAsB,CAAC;AAEhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0FAA0F;IAC1F,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,mFAAmF;IACnF,OAAO,EAAE,mBAAmB,EAAE,CAAC;CAChC;AAkBD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAgBxE"}
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { pgSchema } from "drizzle-orm/pg-core";
|
|
2
2
|
import type { ShapeSubscriptionState } from "./subscription-state";
|
|
3
|
+
/**
|
|
4
|
+
* The pgxsinkit-owned metadata schema (ADR-0009 decision 6) — where the subscription cursor and the
|
|
5
|
+
* sync-origin GUC live. Ours, not the sync substrate's, which is why it is not named after one.
|
|
6
|
+
*
|
|
7
|
+
* The sync engine defaults its `metadataSchema` to this and `createSyncClient` never overrides it, so
|
|
8
|
+
* paths outside the engine can address the same relations by this constant.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_METADATA_SCHEMA = "pgxsinkit";
|
|
11
|
+
/**
|
|
12
|
+
* Validate the metadata schema name at engine construction. The name is interpolated RAW into two
|
|
13
|
+
* positions a double-quoted identifier cannot cover:
|
|
14
|
+
* - GUC space — `SET LOCAL <schema>.syncing` (sync/index.ts) and `SET <schema>.syncing = false`
|
|
15
|
+
* (the metadata migration). GUC grammar takes a `namespace.name` of bare identifiers; it does not
|
|
16
|
+
* accept a quoted identifier the way a table/column position does, so the name cannot be safely
|
|
17
|
+
* quoted there.
|
|
18
|
+
* - the `CREATE SCHEMA <schema>` DDL identifier position.
|
|
19
|
+
* Rather than trust arbitrary caller input in those raw positions, restrict the name to a bare
|
|
20
|
+
* lowercase identifier and reject uppercase/exotic names outright. The default "pgxsinkit" passes.
|
|
21
|
+
*/
|
|
22
|
+
export declare function assertValidMetadataSchema(metadataSchema: string): void;
|
|
3
23
|
/**
|
|
4
24
|
* The two metadata-store relations the sync engine provisions at boot (ADR-0028 decision 4). The
|
|
5
25
|
* metadata schema name is dynamic (per-client config) but fixed at engine construction, so the tables
|
|
@@ -18,7 +38,11 @@ import type { ShapeSubscriptionState } from "./subscription-state";
|
|
|
18
38
|
export interface MetadataTables {
|
|
19
39
|
/** `<schema>.subscriptions_metadata` — one row per subscription key. */
|
|
20
40
|
readonly subscriptionsMetadata: ReturnType<typeof buildSubscriptionsMetadata>;
|
|
21
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* `<schema>.shape_row_tags` — the tagged-subquery reason-set store (ADR-0023), whose mechanism
|
|
43
|
+
* ADR-0057 retired. Still provisioned by `migrateSubscriptionMetadataTables`; nothing reads or
|
|
44
|
+
* writes it on the native path.
|
|
45
|
+
*/
|
|
22
46
|
readonly shapeRowTags: ReturnType<typeof buildShapeRowTags>;
|
|
23
47
|
}
|
|
24
48
|
declare function buildSubscriptionsMetadata(schema: ReturnType<typeof pgSchema>): import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-tables.d.ts","sourceRoot":"","sources":["../../src/sync/metadata-tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAoB,MAAM,qBAAqB,CAAC;AAE/E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,qBAAqB,EAAE,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC;IAC9E
|
|
1
|
+
{"version":3,"file":"metadata-tables.d.ts","sourceRoot":"","sources":["../../src/sync/metadata-tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAoB,MAAM,qBAAqB,CAAC;AAE/E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,cAAc,CAAC;AAQnD;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAStE;AAED;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,qBAAqB,EAAE,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC;IAC9E;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;CAC7D;AAYD,iBAAS,0BAA0B,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAQtE;AAED,iBAAS,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAa7D;AAID,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,cAAc,CAWxE;AAID;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,IAAI,cAAc,CASzD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,GAAG,cAAc,CAEjG"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Offset } from "@electric-sql/client";
|
|
2
1
|
import type { PGliteInterface, Transaction } from "@electric-sql/pglite";
|
|
2
|
+
import { type PredicateValue } from "@pgxsinkit/contracts";
|
|
3
3
|
import { type Lsn, type SubscriptionKey } from "./types";
|
|
4
4
|
export interface SubscriptionState {
|
|
5
5
|
key: SubscriptionKey;
|
|
@@ -8,7 +8,26 @@ export interface SubscriptionState {
|
|
|
8
8
|
}
|
|
9
9
|
export interface ShapeSubscriptionState {
|
|
10
10
|
handle: string;
|
|
11
|
-
|
|
11
|
+
/** Opaque, per-stream, lexicographically ordered. Never compared across streams. */
|
|
12
|
+
offset: string;
|
|
13
|
+
/**
|
|
14
|
+
* The registry shape this entry is a reader of.
|
|
15
|
+
*
|
|
16
|
+
* Persisted so a later subscribe can say what a stored entry WAS, not merely that it exists. The
|
|
17
|
+
* map key is a logical shape name the client mints (shape key plus scope), which is enough to match
|
|
18
|
+
* an entry against a fresh grant but carries no way back to the registry — and the reconcile at
|
|
19
|
+
* subscribe (ADR-0055 decision 6) needs exactly that: a scope the control plane no longer grants has
|
|
20
|
+
* to be resolved to its spec before its rows can be cleared.
|
|
21
|
+
*/
|
|
22
|
+
shapeKey: string;
|
|
23
|
+
/**
|
|
24
|
+
* Shared tier only: the scope values this reader's grant named, in the shape's declared column
|
|
25
|
+
* order. Absent for the private tier, whose subject arrives in the claims instead.
|
|
26
|
+
*
|
|
27
|
+
* `readonly` because a persisted tuple is a record of what was granted, never something to edit —
|
|
28
|
+
* which also lets a grant's own `readonly PredicateValue[]` be stored without a defensive copy.
|
|
29
|
+
*/
|
|
30
|
+
scope?: readonly PredicateValue[];
|
|
12
31
|
}
|
|
13
32
|
export interface GetSubscriptionStateOptions {
|
|
14
33
|
readonly pg: PGliteInterface | Transaction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-state.d.ts","sourceRoot":"","sources":["../../src/sync/subscription-state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"subscription-state.d.ts","sourceRoot":"","sources":["../../src/sync/subscription-state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGzE,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAK5E,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAEzD,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,eAAe,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACvD,QAAQ,EAAE,GAAG,CAAC;CACf;AAED,MAAM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EAAE,eAAe,EAAE,EAAE,8BAA8B,iBAUpH;AAED,MAAM,WAAW,wCAAwC;IACvD,EAAE,EAAE,eAAe,GAAG,WAAW,CAAC;IAClC,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAsB,iCAAiC,CAAC,EACtD,EAAE,EACF,cAAc,GACf,EAAE,wCAAwC,iBAsB1C"}
|
package/dist/sync/types.d.ts
CHANGED
|
@@ -1,138 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { PgliteDatabase } from "drizzle-orm/pglite";
|
|
3
|
-
import type { SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
4
|
-
import type { GroupBootStamp } from "../boot-report";
|
|
5
|
-
export type { Row, ShapeStreamOptions } from "@electric-sql/client";
|
|
6
|
-
export type { MultiShapeMessages } from "@electric-sql/experimental";
|
|
1
|
+
import type { SyncChange } from "@pgxsinkit/contracts";
|
|
7
2
|
export type Lsn = bigint;
|
|
8
3
|
export type SubscriptionKey = string;
|
|
9
4
|
export type InitialInsertMethod = "insert" | "copy" | "json";
|
|
10
|
-
/** Default hard cap on commit-transaction attempts before the engine goes degraded (ADR-0009). */
|
|
11
|
-
export declare const DEFAULT_MAX_COMMIT_RETRIES = 5;
|
|
12
5
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
6
|
+
* A change the fold has established is the net UPSERT of a complete row.
|
|
7
|
+
*
|
|
8
|
+
* The narrowing is what the bulk paths rely on: `value` carries every projected column, so the rows
|
|
9
|
+
* can go out as one multi-row statement (or a COPY) with no per-row branch on which columns are
|
|
10
|
+
* present. Guaranteed by the engine, not merely hoped for — `row_to_json_cols` emits every column of
|
|
11
|
+
* the shape's `out_cols` on every upsert.
|
|
17
12
|
*/
|
|
18
|
-
export
|
|
19
|
-
shape: ShapeStreamOptions<Row<unknown>>;
|
|
20
|
-
/** The registry table key this shape applies into — the engine's sole per-table spec (ADR-0029 D1). */
|
|
21
|
-
tableKey: string;
|
|
22
|
-
/**
|
|
23
|
-
* Must-refetch override: replaces the default `TRUNCATE` cache wipe (ADR-0029 D4). Receives a Drizzle
|
|
24
|
-
* handle bound to the commit transaction (`drizzleOverPg(tx)`), so a scoped clear authors tier-①
|
|
25
|
-
* (`db.delete(table).where(…)`).
|
|
26
|
-
*/
|
|
27
|
-
onMustRefetch?: ((db: PgliteDatabase) => Promise<void>) | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Per-shape initial-backfill apply strategy override (ADR-0009 decisions 2 + 3). In a consistency
|
|
30
|
-
* group each shape resolves its own apply path, so one shape's backfill never forces the rest onto
|
|
31
|
-
* plain `INSERT`. When set it wins over the registry-classified strategy; otherwise the strategy is
|
|
32
|
-
* derived from the entry and mapped, else the group-level default applies.
|
|
33
|
-
*/
|
|
34
|
-
initialInsertMethod?: InitialInsertMethod | undefined;
|
|
35
|
-
}
|
|
36
|
-
export interface SyncShapesToTablesOptions {
|
|
37
|
-
key: string | null;
|
|
38
|
-
/** The engine's per-table spec source (ADR-0029 D1): every shape's `tableKey` resolves against it. */
|
|
39
|
-
registry: SyncTableRegistry;
|
|
40
|
-
shapes: Record<string, ShapeToTableOptions>;
|
|
41
|
-
/**
|
|
42
|
-
* ADR-0042: this group's sync bookkeeping (subscription cursor + tagged-subquery reason sets) is
|
|
43
|
-
* SESSION-scoped — stored in the engine's `pg_temp` metadata relations that die with the engine, not the
|
|
44
|
-
* durable ones. Set for an `ephemeral`-retention group, whose whole cluster is already TEMP: the cursor
|
|
45
|
-
* and tags then die with the rows they index, so a returning engine re-streams the shape from scratch
|
|
46
|
-
* instead of resuming a stale durable cursor over a recreated-empty TEMP cluster. Default `false` — a
|
|
47
|
-
* persistent group's storage is identical whether the bit is `false` or unset; it only scopes an
|
|
48
|
-
* ephemeral group's bookkeeping. One storage-scope bit; the engine never learns the retention model.
|
|
49
|
-
*/
|
|
50
|
-
sessionScoped?: boolean | undefined;
|
|
51
|
-
initialInsertMethod?: InitialInsertMethod | undefined;
|
|
52
|
-
onInitialSync?: (() => void) | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* Fresh-store prefetch overlap (ADR-0032 S4 / backlog-0003). When present, the group is on a
|
|
55
|
-
* PROVABLY-FRESH store (a claimed schemaless spare — the caller's `freshStore` hint), so the engine
|
|
56
|
-
* starts the shape streams and BUFFERS their catch-up into the memory inbox immediately — WITHOUT the
|
|
57
|
-
* two DB touches the sequential path takes first (`initMetadataTables`, `getSubscriptionState`) — and
|
|
58
|
-
* gates every commit (the first write to PGlite) until this promise resolves. The owner resolves it
|
|
59
|
-
* once the local store is ready (schema exec + journal recovery + store-version reconcile complete), so
|
|
60
|
-
* the network catch-up overlaps those local phases instead of running strictly after them. Absent → the
|
|
61
|
-
* exact sequential path (warm stores, and every non-overlap caller). Because a fresh store has no prior
|
|
62
|
-
* subscription state, the overlap treats the group as a new subscription (`subState === null`), which the
|
|
63
|
-
* `freshStore` gate guarantees.
|
|
64
|
-
*/
|
|
65
|
-
dbReady?: Promise<void> | undefined;
|
|
66
|
-
/** Stream-level (network / fetch) error from Electric, forwarded to `MultiShapeStream.subscribe`. */
|
|
67
|
-
onError?: ((error: FetchError | Error) => void) | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* Commit-level error surfacing (ADR-0009 decision 5). Fired when a sync commit transaction
|
|
70
|
-
* still fails after `maxCommitRetries` jittered-backoff attempts. The engine then holds its
|
|
71
|
-
* buffer and committed frontier (never advancing `isUpToDate` on an unapplied commit) so the
|
|
72
|
-
* read cache cannot silently diverge; recovery is a later commit or a restart/refetch.
|
|
73
|
-
*/
|
|
74
|
-
onSyncError?: ((error: Error) => void) | undefined;
|
|
75
|
-
/**
|
|
76
|
-
* Fired whenever the stream delivers a batch — i.e. a fetch just succeeded (ADR-0013 Phase 3).
|
|
77
|
-
* The runtime uses this as the read path's "alive again" signal to clear an `auth-needed` status
|
|
78
|
-
* once sync resumes after re-authentication.
|
|
79
|
-
*/
|
|
80
|
-
onSyncActivity?: (() => void) | undefined;
|
|
81
|
-
/** Hard cap on commit-transaction attempts before going degraded. Defaults to {@link DEFAULT_MAX_COMMIT_RETRIES}. */
|
|
82
|
-
maxCommitRetries?: number | undefined;
|
|
83
|
-
/**
|
|
84
|
-
* Backoff before re-attempting a failed commit, as a function of the attempt number. Defaults to
|
|
85
|
-
* the runtime's jittered backoff (`computeRetryDelayMs`). A test seam — pass `() => 0` for an
|
|
86
|
-
* immediate retry instead of sleeping the real backoff.
|
|
87
|
-
*/
|
|
88
|
-
commitRetryDelayMs?: ((attempt: number) => number) | undefined;
|
|
89
|
-
/**
|
|
90
|
-
* Boot observability (ADR-0034): a per-group accumulator, stamped as this group's stream chain delivers
|
|
91
|
-
* batches (`onBatchDelivered`), applies commits into PGlite (`onApply`), and reaches initial sync
|
|
92
|
-
* (`markReady`). Present only for eager + promoted BOOT groups; absent for on-demand lazy starts and any
|
|
93
|
-
* boot without report instrumentation.
|
|
94
|
-
*/
|
|
95
|
-
bootStamp?: GroupBootStamp | undefined;
|
|
96
|
-
}
|
|
97
|
-
export interface SyncShapesToTablesResult {
|
|
98
|
-
unsubscribe: () => void;
|
|
99
|
-
readonly isUpToDate: boolean;
|
|
100
|
-
streams: Record<string, ShapeStreamInterface<Row<unknown>>>;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Single-shape options (ADR-0029 D6): thin sugar over the group form, taking the same entry-based
|
|
104
|
-
* fields plus a `shapeKey`. Every table-scoped fact is derived from `(registry, tableKey)`.
|
|
105
|
-
*/
|
|
106
|
-
export interface SyncShapeToTableOptions {
|
|
107
|
-
shape: ShapeStreamOptions<Row<unknown>>;
|
|
108
|
-
registry: SyncTableRegistry;
|
|
109
|
-
tableKey: string;
|
|
110
|
-
shapeKey: string | null;
|
|
111
|
-
/** ADR-0042: SESSION-scope this shape's cursor + tags (ephemeral retention); see {@link SyncShapesToTablesOptions.sessionScoped}. */
|
|
112
|
-
sessionScoped?: boolean | undefined;
|
|
113
|
-
initialInsertMethod?: InitialInsertMethod | undefined;
|
|
114
|
-
onInitialSync?: (() => void) | undefined;
|
|
115
|
-
onError?: ((error: FetchError | Error) => void) | undefined;
|
|
116
|
-
/** Commit-level error surfacing (ADR-0009 decision 5); see {@link SyncShapesToTablesOptions.onSyncError}. */
|
|
117
|
-
onSyncError?: ((error: Error) => void) | undefined;
|
|
118
|
-
/** Hard cap on commit-transaction attempts before going degraded. Defaults to {@link DEFAULT_MAX_COMMIT_RETRIES}. */
|
|
119
|
-
maxCommitRetries?: number | undefined;
|
|
120
|
-
/** Backoff before re-attempting a failed commit; see {@link SyncShapesToTablesOptions.commitRetryDelayMs}. */
|
|
121
|
-
commitRetryDelayMs?: ((attempt: number) => number) | undefined;
|
|
122
|
-
onMustRefetch?: ((db: PgliteDatabase) => Promise<void>) | undefined;
|
|
123
|
-
}
|
|
124
|
-
export interface SyncShapeToTableResult {
|
|
125
|
-
unsubscribe: () => void;
|
|
126
|
-
readonly isUpToDate: boolean;
|
|
127
|
-
stream: ShapeStreamInterface<Row<unknown>>;
|
|
128
|
-
}
|
|
129
|
-
export interface ElectricSyncOptions {
|
|
130
|
-
debug?: boolean;
|
|
131
|
-
metadataSchema?: string;
|
|
132
|
-
}
|
|
133
|
-
export type InsertChangeMessage = ChangeMessage<Row<unknown>> & {
|
|
13
|
+
export type UpsertChangeMessage = SyncChange & {
|
|
134
14
|
headers: {
|
|
135
|
-
operation: "
|
|
15
|
+
operation: "upsert";
|
|
136
16
|
};
|
|
137
17
|
};
|
|
138
18
|
//# sourceMappingURL=types.d.ts.map
|
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":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sync/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AACrC,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG;IAC7C,OAAO,EAAE;QAAE,SAAS,EAAE,QAAQ,CAAA;KAAE,CAAC;CAClC,CAAC"}
|
package/dist/testing.js
CHANGED
|
@@ -10,8 +10,8 @@ function testStoreAcknowledgment() {
|
|
|
10
10
|
return { [TEST_STORE_BACKEND]: "acknowledged" };
|
|
11
11
|
}
|
|
12
12
|
export {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
memoryStoreForTests,
|
|
14
|
+
testStoreAcknowledgment
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
//# debugId=
|
|
17
|
+
//# debugId=70F1E266BD33AAED64756E2164756E21
|
package/dist/testing.js.map
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/store-path.ts", "../src/testing.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
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 engine home's capabilities here, never chosen by\n// the consumer: opfs-repacked when that home holds sync access, IndexedDB as the browser fallback, and the\n// 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://` / `opfs://`\n// URLs (the export machinery's throwaway clone 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 a\n// consumer could copy back into a storePath — hence the scheme-rejection guard below fails the old contract\n// loudly at the boundary rather than silently re-interpreting it.\n//\n// Under ADR-0049 (capability-driven engine placement) it also owns the browser-side STORE IDENTITY encoding\n// and the disjoint OPFS namespaces the placement probe, the commitment marker, and the store meta record all\n// key on. `storeIdentityComponent` is the one injective encoding for every browser-side identity surface\n// (OPFS namespace entries, leader lock, meta record key, communication-centre SharedWorker name; D11), and the\n// `pgxsinkit/stores|commitments|probe` namespace builders are the one place those names live (D6).\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 * ADR-0049 (D1): the PLACEMENT PROBE's injected result — whether a REAL `createSyncAccessHandle` open\n * succeeded in the executing scope (the bench phase-0 mechanism, performed by the async boot path — never\n * method-presence sniffing). Optional so every existing `StoreEnv` construction stays valid; `undefined`\n * means \"no OPFS sync access\" (false). {@link detectStoreEnv} ALWAYS reports `false` for it: there is no\n * synchronous ambient detection for handle grants, and method-presence sniffing is forbidden — only the\n * boot path's real probe open can flip it true.\n */\n hasOpfsSyncAccess?: boolean;\n}\n\n/** Detect the ambient store environment off `globalThis` (the library carries no DOM lib dependency). */\nfunction detectStoreEnv(): StoreEnv {\n // `hasOpfsSyncAccess` is deliberately absent (false): the placement probe (an async handle open) is the\n // only honest source, and this synchronous ambient detector must never guess it (ADR-0049 D1).\n return { hasIndexedDb: typeof (globalThis as { indexedDB?: unknown }).indexedDB !== \"undefined\" };\n}\n\n/**\n * The shared plain-`storePath` boundary guard (ADR-0036 decision 1). A storePath is a PLAIN name, never a\n * storage URL: empty/whitespace-only or scheme-bearing (`://`) values fail loudly with\n * {@link InvalidStorePathError}. Factored so {@link resolveStoreDataDir} and {@link storeIdentityComponent}\n * share ONE message set (no drift between the two identity-surface entry points).\n */\nfunction assertPlainStorePath(storePath: string): void {\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 (capability-selected opfs-repacked ' +\n \"with IndexedDB fallback in a browser, or the filesystem on Bun/Node) is derived for you; drop the \" +\n \"scheme prefix (ADR-0036/ADR-0049).\",\n );\n }\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, amended by ADR-0049). A browser worker with a proven OPFS sync-access grant resolves\n * to `opfs://<storePath>`; another browser context (`indexedDB` present) resolves to `idb://<storePath>`;\n * Bun/Node resolves to `file://<storePath>` (relative paths use the working directory). The `backendOverride`\n * is internal-only: `\"memory\"` selects a scheme-selected `memory://<storePath>` test/ephemeral store.\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. 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 *\n * ADR-0049 (D1) adds the `opfs://<storePath>` form: when the placement probe granted a sync-access handle in\n * the executing scope (`env.hasOpfsSyncAccess`), the browser store lives on `opfs-repacked`. Precedence:\n * memory override (test/ephemeral) → `opfs://` (probe granted) → `idb://` (browser, handle denied) →\n * `file://` (Bun/Node). `opfs://` is TOOLKIT-INTERNAL plumbing — PGlite does NOT accept it as a `dataDir`;\n * {@link createClientPGlite} (plan step 10) interprets it via the opfs-repacked factory + the OPFS namespace\n * builders below. Like every URL resolved here, it never leaks to consumers.\n */\nexport function resolveStoreDataDir(\n storePath: string,\n backendOverride?: \"memory\",\n env: StoreEnv = detectStoreEnv(),\n): string {\n assertPlainStorePath(storePath);\n if (backendOverride === \"memory\") return `memory://${storePath}`;\n if (env.hasOpfsSyncAccess) return `opfs://${storePath}`;\n return env.hasIndexedDb ? `idb://${storePath}` : `file://${storePath}`;\n}\n\n/**\n * The per-component ENCODED length cap for {@link storeIdentityComponent}. A filesystem-safe bound for a\n * single OPFS name component; the fixed container/namespace names (`pgxsinkit`, `stores`, `commitments`,\n * `probe`) are SEPARATE path components and add nothing to this budget. Encoding is what is capped, not the\n * raw input — a short multi-byte name can expand past the bound.\n */\nconst STORE_IDENTITY_ENCODED_CAP = 128;\n\n/**\n * The ONE injective encoding for every browser-side identity surface (ADR-0049 D11, invariant 10): OPFS\n * namespace entries ({@link opfsStoreDirectoryPath} / {@link opfsCommitmentSentinelPath}), the leader lock\n * name, the store meta record key, and the communication-centre SharedWorker name all derive from this single\n * canonical component. Percent-encoding (`encodeURIComponent`) — injective, never lossy sanitising, so two\n * distinct store paths can never collapse to one identity (e.g. `\"foo/bar\"` → `foo%2Fbar` vs the literal\n * `\"foo%2Fbar\"` → `foo%252Fbar`).\n *\n * Domain (invariant 10):\n * - Same boundary guards as {@link resolveStoreDataDir}: empty/whitespace-only or scheme-bearing (`://`)\n * paths throw {@link InvalidStorePathError} (shared {@link assertPlainStorePath}).\n * - A lone UTF-16 surrogate makes `encodeURIComponent` raise a `URIError`; that is wrapped into\n * {@link InvalidStorePathError} so callers branch one error type at the boundary.\n * - `.` and `..` pass through `encodeURIComponent` UNCHANGED, but the File System Standard reserves them as\n * invalid file names, so both are rejected.\n * - The ENCODED length is capped at {@link STORE_IDENTITY_ENCODED_CAP} (a per-component filesystem-safe\n * bound); overflow is rejected.\n */\nexport function storeIdentityComponent(storePath: string): string {\n assertPlainStorePath(storePath);\n let identity: string;\n try {\n identity = encodeURIComponent(storePath);\n } catch (error) {\n // The only `encodeURIComponent` failure is a lone UTF-16 surrogate (`URIError`); rewrap it so the domain\n // presents ONE error type at the boundary (never a bare `URIError`).\n if (error instanceof URIError) {\n throw new InvalidStorePathError(\n `invalid storePath ${JSON.stringify(storePath)}: it contains a lone UTF-16 surrogate, which has no ` +\n \"valid encoding as a store identity (ADR-0049).\",\n );\n }\n throw error;\n }\n if (identity === \".\" || identity === \"..\") {\n throw new InvalidStorePathError(\n `invalid storePath ${JSON.stringify(storePath)}: \".\" and \"..\" are reserved file names (File System ` +\n \"Standard) and cannot be a store identity (ADR-0049).\",\n );\n }\n if (identity.length > STORE_IDENTITY_ENCODED_CAP) {\n throw new InvalidStorePathError(\n `invalid storePath ${JSON.stringify(storePath)}: its encoded store identity is ${identity.length} ` +\n `characters, over the ${STORE_IDENTITY_ENCODED_CAP}-character per-component cap (ADR-0049). Note the ` +\n \"cap is on the ENCODED form — a short multi-byte name can expand past it.\",\n );\n }\n return identity;\n}\n\n/**\n * The toolkit-owned OPFS container at the root (ADR-0049 D6). Its child namespaces (`stores`, `commitments`,\n * `probe`) are DISJOINT so two valid identities can never contend for one OPFS entry (e.g. store `\"foo\"`'s\n * commitment sentinel vs a store literally named `\"foo.committed\"`). This module is the ONLY place that knows\n * these names — the same rule that keeps {@link storeIndexedDbDatabaseName} the sole owner of the `/pglite/`\n * prefix.\n */\nexport const OPFS_TOOLKIT_CONTAINER = \"pgxsinkit\";\n\n/**\n * OPFS path (segment array) of a store's four-file VFS directory: `pgxsinkit/stores/<identity>` (ADR-0049 D6).\n * Returned as SEGMENTS, not a joined string, because consumers traverse OPFS via a `getDirectoryHandle` chain.\n */\nexport function opfsStoreDirectoryPath(storePath: string): readonly [string, string, string] {\n return [OPFS_TOOLKIT_CONTAINER, \"stores\", storeIdentityComponent(storePath)];\n}\n\n/**\n * OPFS path (segment array) of a store's commitment marker sentinel: `pgxsinkit/commitments/<identity>`\n * (ADR-0049 D6). Disjoint from {@link opfsStoreDirectoryPath} — the store directory holds exactly the four\n * VFS-owned files, and a suffix-sibling sentinel would collide across valid identities. Segments, not a joined\n * string, for the same `getDirectoryHandle`-chain reason.\n */\nexport function opfsCommitmentSentinelPath(storePath: string): readonly [string, string, string] {\n return [OPFS_TOOLKIT_CONTAINER, \"commitments\", storeIdentityComponent(storePath)];\n}\n\n/**\n * OPFS path (segment array) of the placement-probe scratch namespace: `pgxsinkit/probe` (ADR-0049 D6). No\n * identity — the probe is per-SharedWorker-scope, not per-store. Segments, not a joined string.\n */\nexport function opfsProbeDirectoryPath(): readonly [string, string] {\n return [OPFS_TOOLKIT_CONTAINER, \"probe\"];\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 * The minimal structural shape of an OPFS `FileSystemDirectoryHandle` this module traverses — just the\n * never-creating `getDirectoryHandle` hop. Declared locally so the module carries no DOM lib dependency\n * (matching how the rest of it reads capabilities structurally off `globalThis`).\n */\ninterface OpfsDirectoryHandle {\n getDirectoryHandle(name: string, options: { create: false }): Promise<OpfsDirectoryHandle>;\n}\n\n/**\n * Does either backend a browser boot could own for a plain {@link storePath} ALREADY exist? The fresh-target\n * gate for a 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 * - **`opfs://`** (browser, placement probe granted) — existence of the store DIRECTORY at\n * `pgxsinkit/stores/<identity>` ({@link opfsStoreDirectoryPath}), walked via\n * `navigator.storage.getDirectory()` and a `getDirectoryHandle` chain with `{ create: false }`. This is\n * ONLY the fresh-target gate; it is emphatically NOT commitment authority — a store directory without a\n * commitment marker is an uncommitted CANDIDATE, and deciding that is the store meta record's phase machine\n * (plan step 2), never this function. `navigator.storage`/`getDirectory` absent → best-effort `false`\n * (mirrors the idb `databases()` stance — never fabricate a positive). A `NotFoundError` anywhere in the\n * chain → `false`; any OTHER error propagates (a genuine failure the restore caller must see).\n * A missing OPFS directory does not finish a granted browser check: IDB is also probed, because a predecessor\n * or fixed-placement store may still own the same public path.\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 if (dataDir.startsWith(\"opfs://\")) {\n // Structural typing off `globalThis` — no DOM lib dependency (like the rest of the module).\n const storage = (\n globalThis as {\n navigator?: {\n storage?: { getDirectory?: () => Promise<OpfsDirectoryHandle> };\n };\n }\n ).navigator?.storage;\n // API absent → best-effort false (never a fabricated positive), same stance as idb `databases()`.\n if (storage?.getDirectory != null) {\n const segments = opfsStoreDirectoryPath(storePath);\n try {\n let handle = await storage.getDirectory();\n for (const segment of segments) {\n // Never-creating existence walk: `{ create: false }` at every hop — this is a gate, not a mkdir.\n handle = await handle.getDirectoryHandle(segment, { create: false });\n }\n return true;\n } catch (error) {\n // A missing entry anywhere in the chain proves OPFS absence; anything else is a real failure to surface.\n if ((error as { name?: string }).name !== \"NotFoundError\") throw error;\n }\n }\n // A granted browser must also reject an IDB predecessor at this path; fall through to the shared IDB probe.\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,
|
|
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, controlPlaneUrl, streamBaseUrl, batchWriteUrl })\n// createSyncClient({ ...testStoreAcknowledgment(), pgliteInstance, registry, controlPlaneUrl, streamBaseUrl, batchWriteUrl })\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
7
|
],
|
|
8
8
|
"mappings": ";;AAwFO,IAAM,qBAAoC,OAAO,IAAI,qCAAqC;;;ACrD1F,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": "
|
|
9
|
+
"debugId": "70F1E266BD33AAED64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -87,7 +87,9 @@ export declare class ElectedEngineUnconstructibleError extends Error {
|
|
|
87
87
|
*
|
|
88
88
|
* - **SW-direct.** The attempt lives in the SharedWorker and is left running (an in-flight store open cannot be
|
|
89
89
|
* safely abandoned — a second open against the same store is an ownership conflict). A later
|
|
90
|
-
* {@link attachSyncClient} ADOPTS it if it completed and
|
|
90
|
+
* {@link attachSyncClient} ADOPTS it if it completed, and waits on a genuinely stuck one only within the
|
|
91
|
+
* engine's spare-store adoption budget (`provisionAdoptionBudgetMs`, default 20000 from the attempt's start),
|
|
92
|
+
* past which that attach is refused with {@link ProvisionStalledError} instead of hanging; a retried
|
|
91
93
|
* provision re-acks against the SAME attempt, so a second open never starts. A stuck storage open blocks that
|
|
92
94
|
* store whether or not it was ever provisioned, and expiring this promise neither causes nor cures that.
|
|
93
95
|
* - **Elected.** This deadline is ALSO the provision claim's expiry, so the claim releases here too. When it is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-sync-client.d.ts","sourceRoot":"","sources":["../../src/worker/attach-sync-client.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAEV,iBAAiB,EACjB,sBAAsB,EAEtB,iBAAiB,EAElB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjD,OAAO,EAQL,KAAK,cAAc,EAEnB,KAAK,UAAU,EAGhB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAyB,KAAK,aAAa,EAAwB,MAAM,eAAe,CAAC;AAGhG,OAAO,EAQL,KAAK,oBAAoB,EAE1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAOL,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"attach-sync-client.d.ts","sourceRoot":"","sources":["../../src/worker/attach-sync-client.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAEV,iBAAiB,EACjB,sBAAsB,EAEtB,iBAAiB,EAElB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjD,OAAO,EAQL,KAAK,cAAc,EAEnB,KAAK,UAAU,EAGhB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,sBAAsB,EAA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