@pgxsinkit/client 0.1.51 → 0.2.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 +22 -0
- package/dist/adoption.d.ts +118 -0
- package/dist/adoption.d.ts.map +1 -0
- package/dist/boot-report.d.ts +54 -15
- package/dist/boot-report.d.ts.map +1 -1
- package/dist/convergence.d.ts +2 -1
- package/dist/convergence.d.ts.map +1 -1
- package/dist/error-chain.d.ts +9 -0
- package/dist/error-chain.d.ts.map +1 -0
- package/dist/export-dump.d.ts.map +1 -1
- package/dist/export-store.d.ts +1 -1
- package/dist/export-store.d.ts.map +1 -1
- package/dist/index.d.ts +309 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4628 -1489
- package/dist/index.js.map +36 -24
- package/dist/live-rows-sql.d.ts +1 -1
- package/dist/local-store.d.ts +16 -31
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-tables.d.ts +10 -4
- package/dist/local-tables.d.ts.map +1 -1
- package/dist/mutation.d.ts +12 -15
- package/dist/mutation.d.ts.map +1 -1
- package/dist/opfs-effects.d.ts +51 -0
- package/dist/opfs-effects.d.ts.map +1 -0
- package/dist/placement-probe.d.ts +75 -0
- package/dist/placement-probe.d.ts.map +1 -0
- package/dist/schema.d.ts +11 -16
- package/dist/schema.d.ts.map +1 -1
- package/dist/store-boot.d.ts +77 -0
- package/dist/store-boot.d.ts.map +1 -0
- package/dist/store-lifecycle.d.ts +153 -0
- package/dist/store-lifecycle.d.ts.map +1 -0
- package/dist/store-meta.d.ts +190 -0
- package/dist/store-meta.d.ts.map +1 -0
- package/dist/store-path.d.ts +77 -7
- package/dist/store-path.d.ts.map +1 -1
- package/dist/sync/apply.d.ts +12 -1
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/shape-inbox.d.ts +1 -1
- package/dist/sync/types.d.ts +3 -3
- package/dist/testing.js.map +3 -3
- package/dist/worker/attach-sync-client.d.ts +239 -13
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +162 -5
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/election-coordinator.d.ts +95 -0
- package/dist/worker/election-coordinator.d.ts.map +1 -0
- package/dist/worker/engine-control.d.ts +265 -0
- package/dist/worker/engine-control.d.ts.map +1 -0
- package/dist/worker/engine-router.d.ts +75 -0
- package/dist/worker/engine-router.d.ts.map +1 -0
- package/dist/worker/live-query-manager.d.ts.map +1 -1
- package/dist/worker/live-query-params-guard.d.ts +14 -0
- package/dist/worker/live-query-params-guard.d.ts.map +1 -0
- package/dist/worker/protocol.d.ts +32 -11
- package/dist/worker/protocol.d.ts.map +1 -1
- package/dist/worker/sw-placement.d.ts +37 -0
- package/dist/worker/sw-placement.d.ts.map +1 -0
- package/package.json +4 -3
- package/skills/core/SKILL.md +15 -8
- package/skills/operating/SKILL.md +114 -34
- package/src/adoption.ts +275 -0
- package/src/boot-report.ts +70 -17
- package/src/convergence.ts +2 -1
- package/src/error-chain.ts +26 -0
- package/src/export-dump.ts +5 -1
- package/src/export-store.ts +1 -1
- package/src/index.ts +1246 -118
- package/src/live-rows-sql.ts +1 -1
- package/src/local-store.ts +18 -40
- package/src/local-tables.ts +9 -2
- package/src/mutation.ts +67 -49
- package/src/mutations-api.ts +3 -3
- package/src/opfs-effects.ts +160 -0
- package/src/placement-probe.ts +168 -0
- package/src/schema.ts +17 -22
- package/src/store-boot.ts +343 -0
- package/src/store-lifecycle.ts +227 -0
- package/src/store-meta.ts +459 -0
- package/src/store-path.ts +197 -22
- package/src/sync/apply.ts +227 -89
- package/src/sync/index.ts +33 -9
- package/src/sync/shape-inbox.ts +1 -1
- package/src/sync/types.ts +3 -3
- package/src/testing.ts +2 -2
- package/src/worker/attach-sync-client.ts +1675 -117
- package/src/worker/define-sync-worker.ts +810 -50
- package/src/worker/election-coordinator.ts +462 -0
- package/src/worker/engine-control.ts +379 -0
- package/src/worker/engine-router.ts +355 -0
- package/src/worker/live-query-manager.ts +10 -1
- package/src/worker/live-query-params-guard.ts +57 -0
- package/src/worker/protocol.ts +41 -10
- package/src/worker/sw-placement.ts +64 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { StoreMetaPhase } from "./store-meta";
|
|
2
|
+
/**
|
|
3
|
+
* The effects the shared commitment barrier drives, in the one order it always runs them. The barrier is the
|
|
4
|
+
* SINGLE data-before-authority sequence every provenance shares (fresh, restore, adoption): the caller has
|
|
5
|
+
* already passed its provenance gate; the barrier makes the data durable, THEN publishes authority.
|
|
6
|
+
*/
|
|
7
|
+
export interface CommitmentBarrierEffects {
|
|
8
|
+
/**
|
|
9
|
+
* The explicit `strictSync()` on the live engine. MUST resolve ONLY when the sync returned AND VFS health
|
|
10
|
+
* is good (data-before-authority — required even under relaxed runtime durability, ADR-0049 D7/D9).
|
|
11
|
+
* Throwing ABORTS the barrier: nothing downstream runs, so nothing publishes. No idempotency requirement —
|
|
12
|
+
* it is the first step and is never resumed past.
|
|
13
|
+
*/
|
|
14
|
+
strictSyncReturns(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Publish the commitment sentinel (`pgxsinkit/commitments/<identity>`, the "Commitment marker"). Published
|
|
17
|
+
* BEFORE the record's committed phase, so a crash between the two reads as committed off the sentinel
|
|
18
|
+
* (store-meta's `repair-record-then-open-committed`). Idempotency required: CREATE-IF-ABSENT (a resume that
|
|
19
|
+
* finds the sentinel already there is a no-op success).
|
|
20
|
+
*/
|
|
21
|
+
publishSentinel(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Advance the store meta record phase. The barrier only ever calls it with `"opfs-committed"`. Idempotency
|
|
24
|
+
* required: SET-PHASE-AGAIN is a no-op success (writing the same phase twice is harmless).
|
|
25
|
+
*/
|
|
26
|
+
setPhase(phase: StoreMetaPhase): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Run the shared commitment barrier (ADR-0049 decision 7): `strictSync()` returns with VFS health good →
|
|
30
|
+
* publish the sentinel → set the `opfs-committed` phase. The caller invokes this ONLY after its provenance
|
|
31
|
+
* gate has passed (fresh: local init/recovery; restore: backup load + restore recovery; adoption: the
|
|
32
|
+
* Adoption-bootstrap gate). Any throw propagates and later steps NEVER run — so a failed barrier publishes
|
|
33
|
+
* NOTHING and an uncommitted candidate is never granted authority (invariant 3). After it resolves the caller
|
|
34
|
+
* exposes the store (fresh/restore) or deletes the predecessor (adoption).
|
|
35
|
+
*/
|
|
36
|
+
export declare function runCommitmentBarrier(effects: CommitmentBarrierEffects): Promise<void>;
|
|
37
|
+
/** The effects that stand up a fresh/restore candidate before the commitment barrier commits it. */
|
|
38
|
+
export interface FreshCandidateEffects {
|
|
39
|
+
/**
|
|
40
|
+
* Write the store meta record at `{ phase: "opfs-candidate" }`. Written FIRST — the record is the first-use
|
|
41
|
+
* authority (invariant 12), so a crash after this but before the directory leaves a state the boot
|
|
42
|
+
* classifier maps to `delete-candidate-and-rebuild` (an unexposed candidate has no authority). Idempotency
|
|
43
|
+
* required: overwrite-if-present.
|
|
44
|
+
*/
|
|
45
|
+
writeCandidateRecord(): Promise<void>;
|
|
46
|
+
/** Create the store's OPFS directory (`pgxsinkit/stores/<identity>`). Idempotency required: create-if-absent. */
|
|
47
|
+
createStoreDirectory(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Begin a fresh/restore candidate: write the `opfs-candidate` meta record BEFORE creating the store
|
|
51
|
+
* directory. Order is load-bearing (record-first authority, invariant 12) — a crash between the two leaves an
|
|
52
|
+
* `opfs-candidate` record whose directory may be absent, which the boot classifier deletes and rebuilds
|
|
53
|
+
* fresh. The forward path from here is the shared {@link runCommitmentBarrier} (after the caller's provenance
|
|
54
|
+
* gate). Full fresh/restore wiring is plan step 10.
|
|
55
|
+
*/
|
|
56
|
+
export declare function beginFreshCandidate(effects: FreshCandidateEffects): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* The effects the destructive lifecycle drives. ONE backend-agnostic machine: {@link deleteBackendStore} is a
|
|
59
|
+
* single effect the wirer (plan step 10) branches by backend (OPFS store directory OR the idb database) — the
|
|
60
|
+
* machine never knows which. The supervisor-level REFUSALS that guard this machine (owed mutations unless
|
|
61
|
+
* `force`; other tabs still holding claims — close the peers first) live OUTSIDE it, in the coordinator/
|
|
62
|
+
* communication-centre supervisor that survives engine shutdown (ADR-0049 D8, plan step 10). This module owns
|
|
63
|
+
* only the resumable delete SEQUENCE once destruction is authorized and the engine is quiesced/closed.
|
|
64
|
+
*/
|
|
65
|
+
export interface DestructionEffects {
|
|
66
|
+
/** Advance the meta record phase; the machine only ever calls it with `"deleting"`. Idempotency: set-again. */
|
|
67
|
+
setPhase(phase: StoreMetaPhase): Promise<void>;
|
|
68
|
+
/** Delete the commitment sentinel. Idempotency required: ABSENT COUNTS AS DELETED (delete-if-present). */
|
|
69
|
+
deleteSentinel(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Delete the backend store — the OPFS store directory OR the idb database, chosen by the wirer; the machine
|
|
72
|
+
* is backend-agnostic. Idempotency required: absent counts as deleted (delete-if-present).
|
|
73
|
+
*/
|
|
74
|
+
deleteBackendStore(): Promise<void>;
|
|
75
|
+
/** Delete the store meta record — the terminal step. Idempotency required: absent counts as deleted. */
|
|
76
|
+
deleteMetaRecord(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The resume path of the destructive lifecycle, entered from an observed `deleting` phase (a boot that finds
|
|
80
|
+
* `deleting` completes the deletion first — invariant 13): delete sentinel → delete backend store → delete
|
|
81
|
+
* meta record. Every step is idempotent, so a crash at any boundary and a re-run from the top completes
|
|
82
|
+
* cleanly (plan's destruction crash table — each row is `resume-deletion` until the record is gone).
|
|
83
|
+
*/
|
|
84
|
+
export declare function resumeDeletion(effects: DestructionEffects): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Run the full destructive lifecycle from an already-quiesced engine (ADR-0049 D8): record the `deleting`
|
|
87
|
+
* phase (highest-precedence commitment that survives a crash), then {@link resumeDeletion}. The upstream steps
|
|
88
|
+
* (refuse owed mutations unless `force`, stop admissions, quiesce/close the engine) and the supervision that
|
|
89
|
+
* lets the initiating `destroy()` resolve from a context surviving engine shutdown are plan step 10 — this
|
|
90
|
+
* machine begins once destruction is authorized and the engine is down.
|
|
91
|
+
*/
|
|
92
|
+
export declare function runDestruction(effects: DestructionEffects): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* The recovery verdict for a store found mid-adoption (phase `adopting`) at boot. Disambiguated purely by
|
|
95
|
+
* whether the commitment sentinel was published before the crash (plan's adoption crash table).
|
|
96
|
+
*/
|
|
97
|
+
export type AdoptionRecoveryVerdict = {
|
|
98
|
+
action: "complete-adoption";
|
|
99
|
+
} | {
|
|
100
|
+
action: "teardown-and-restart";
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Classify an interrupted adoption purely from the observed sentinel presence (ADR-0049 D7 adoption sequence;
|
|
104
|
+
* plan adoption crash rows). Sentinel present → `complete-adoption` (the commitment barrier had published,
|
|
105
|
+
* so the opfs store is committed); sentinel absent → `teardown-and-restart` (idb remains authoritative — the
|
|
106
|
+
* predecessor is deleted ONLY after commitment, so nothing is lost). This owns RECOVERY only; the full
|
|
107
|
+
* forward adoption transition (pre-expose idb boot, the drain predicate, strict-sync close of the
|
|
108
|
+
* never-exposed engine, phase `adopting`, server bootstrap through the Adoption-bootstrap gate) is plan
|
|
109
|
+
* step 11's wiring.
|
|
110
|
+
*/
|
|
111
|
+
export declare function classifyAdoptionRecovery(obs: {
|
|
112
|
+
sentinelPresent: boolean;
|
|
113
|
+
}): AdoptionRecoveryVerdict;
|
|
114
|
+
/** The effects the adoption completion executor drives (the `complete-adoption` verdict). */
|
|
115
|
+
export interface AdoptionCompletionEffects {
|
|
116
|
+
/** Advance the meta record phase; the executor only ever calls it with `"opfs-committed"`. Idempotency: set-again. */
|
|
117
|
+
setPhase(phase: StoreMetaPhase): Promise<void>;
|
|
118
|
+
/** Delete the idb predecessor now the opfs store is committed. Idempotency required: absent counts as deleted. */
|
|
119
|
+
deleteIdbPredecessor(): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Complete an adoption whose commitment barrier already published the sentinel (the `complete-adoption`
|
|
123
|
+
* verdict): set `opfs-committed`, then delete the idb predecessor. Ordered committed-flag-BEFORE-deletion so
|
|
124
|
+
* a crash between them re-enters as `opfs-committed` with the idb store lingering — the committed-boot path
|
|
125
|
+
* idempotently finishes the deletion (plan adoption crash row 3). The predecessor is deleted ONLY after
|
|
126
|
+
* commitment, never before (invariant 4 — no silent local-only data loss).
|
|
127
|
+
*/
|
|
128
|
+
export declare function completeAdoption(effects: AdoptionCompletionEffects): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* The per-status row counts of the Mutation journal the drain predicate reads. Names + semantics mirror the
|
|
131
|
+
* canonical journal status machine in `packages/contracts/src/mutation.ts` (`mutationStatusSchema`), but this
|
|
132
|
+
* takes COUNTS as plain input rather than coupling to the journal schema — the predicate is pure and
|
|
133
|
+
* unit-testable without a journal.
|
|
134
|
+
*/
|
|
135
|
+
export interface JournalStatusCounts {
|
|
136
|
+
pending: number;
|
|
137
|
+
sending: number;
|
|
138
|
+
acked: number;
|
|
139
|
+
failed: number;
|
|
140
|
+
quarantined: number;
|
|
141
|
+
conflicted: number;
|
|
142
|
+
rejected: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The DRAIN PREDICATE (CONTEXT § "Drain predicate"; ADR-0049 D7): the idb store owes nothing to the server
|
|
146
|
+
* iff no row is `pending`, `sending`, `failed`, `quarantined`, or `conflicted`. `acked` and `rejected` rows
|
|
147
|
+
* are PERMITTED — both are settled (rejection is terminal, ADR-0022). Evaluated PRE-EXPOSE in the adoption
|
|
148
|
+
* transition so no mutation can race it. Echo-landing is deliberately NOT required (the opfs successor is
|
|
149
|
+
* rebuilt from the server, which already holds every acked write) — this is weaker than Data export's
|
|
150
|
+
* "drained", which reads local tables.
|
|
151
|
+
*/
|
|
152
|
+
export declare function journalOwesNothing(counts: JournalStatusCounts): boolean;
|
|
153
|
+
//# sourceMappingURL=store-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-lifecycle.d.ts","sourceRoot":"","sources":["../src/store-lifecycle.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAMnD;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;;OAKG;IACH,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC;;;;;OAKG;IACH,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAI3F;AAQD,oGAAoG;AACpG,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,iHAAiH;IACjH,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvF;AAMD;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,+GAA+G;IAC/G,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,0GAA0G;IAC1G,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC,IAAI,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
2
|
+
* The one total phase of the store meta record (invariant 12). `deleting` has precedence over everything;
|
|
3
|
+
* `adopting` over ordinary idb boot. There is deliberately NO boolean cross-product (`committed` +
|
|
4
|
+
* `deletionIntent`) — that left precedence ambiguous; the phase is total (CONTEXT § "Store meta record").
|
|
5
|
+
*/
|
|
6
|
+
export type StoreMetaPhase = "idb-authoritative" | "opfs-candidate" | "adopting" | "opfs-committed" | "deleting";
|
|
7
|
+
/** One store's meta record: its total {@link StoreMetaPhase} plus a last-write timestamp. */
|
|
8
|
+
export interface StoreMetaRecord {
|
|
9
|
+
phase: StoreMetaPhase;
|
|
10
|
+
updatedAt: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The boot observations the classifier decides on — a PLAIN object so {@link classifyStoreBoot} is total and
|
|
14
|
+
* unit-testable without any IO. Callers assemble it from {@link readStoreMetaRecord}, an OPFS commitment
|
|
15
|
+
* namespace observation, and {@link idbStoreExists}.
|
|
16
|
+
*/
|
|
17
|
+
export interface StoreBootObservations {
|
|
18
|
+
/**
|
|
19
|
+
* The meta record, `undefined` when absent. Callers MUST have already applied the failed-read policy: an
|
|
20
|
+
* UNREADABLE record never reaches the classifier as `undefined` (invariant 12) — it is a fail-closed error
|
|
21
|
+
* ({@link StoreMetaUnreadableError}) the caller handles before classifying. Only a proven absence is
|
|
22
|
+
* `undefined` here.
|
|
23
|
+
*/
|
|
24
|
+
record: StoreMetaRecord | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* The OPFS commitment-namespace observation: `"unobservable"` when the OPFS root threw or the API is absent
|
|
27
|
+
* (present absence is NOT historical proof), otherwise what was actually seen — whether the commitment
|
|
28
|
+
* sentinel and/or the store directory are present.
|
|
29
|
+
*/
|
|
30
|
+
opfs: {
|
|
31
|
+
sentinelPresent: boolean;
|
|
32
|
+
storeDirectoryPresent: boolean;
|
|
33
|
+
} | "unobservable";
|
|
34
|
+
/** The non-creating idb existence check result (invariant 14 — an existing idb store's data is never overwritten; {@link idbStoreExists}). */
|
|
35
|
+
idbStoreExists: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The exhaustive set of boot verdicts. One discriminated union so every branch of {@link classifyStoreBoot}
|
|
39
|
+
* is named and reachable; downstream wiring (plan step 10) switches on `action`.
|
|
40
|
+
*/
|
|
41
|
+
export type StoreBootVerdict = {
|
|
42
|
+
action: "resume-deletion";
|
|
43
|
+
} | {
|
|
44
|
+
action: "adoption-recovery";
|
|
45
|
+
} | {
|
|
46
|
+
action: "open-committed";
|
|
47
|
+
} | {
|
|
48
|
+
action: "repair-record-then-open-committed";
|
|
49
|
+
} | {
|
|
50
|
+
action: "delete-candidate-and-rebuild";
|
|
51
|
+
} | {
|
|
52
|
+
action: "boot-idb-authoritative";
|
|
53
|
+
} | {
|
|
54
|
+
action: "virgin-create";
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The PURE boot classifier — plan boot classification 1–7 EXACTLY (invariant 12). Total over every phase and
|
|
58
|
+
* every observation combination; no IO. Precedence, in order:
|
|
59
|
+
*
|
|
60
|
+
* 1. `deleting` → `resume-deletion` (precedence over EVERYTHING, including a committed-looking OPFS).
|
|
61
|
+
* 2. `adopting` → `adoption-recovery` (precedence over ordinary idb boot).
|
|
62
|
+
* 3. `opfs-committed` → `open-committed` (opfs observations are IRRELEVANT here — the hard-open path handles
|
|
63
|
+
* any failure, including an unreachable root; a committed store never re-derives its verdict from OPFS).
|
|
64
|
+
* 4. `opfs-candidate` → `delete-candidate-and-rebuild` (an unexposed candidate has no authority).
|
|
65
|
+
* 5. `idb-authoritative` → `boot-idb-authoritative`.
|
|
66
|
+
* 6. record `undefined`, OPFS observable: `sentinelPresent` → `repair-record-then-open-committed` (sentinel
|
|
67
|
+
* authority — a sentinel-without-record is a real crash state that reads as committed); else a candidate
|
|
68
|
+
* directory without a sentinel → `delete-candidate-and-rebuild`; neither → fall through to 7.
|
|
69
|
+
* 7. record `undefined` and (OPFS unobservable OR nothing present): the RECORDLESS-IDB CHECK —
|
|
70
|
+
* `idbStoreExists` → `boot-idb-authoritative` (an existing recordless idb store — NEVER virgin; this arm
|
|
71
|
+
* is the entry point of the forward idbfs→opfs transition); else `virgin-create`.
|
|
72
|
+
*
|
|
73
|
+
* NOTE (the caller's nuance, not the classifier's): when OPFS is unobservable and the verdict is
|
|
74
|
+
* `virgin-create`, the caller creates an IDB store (a main thread / no-handle scope cannot hold sync-access
|
|
75
|
+
* handles). The double-loss residual — the meta record independently wiped AND OPFS simultaneously
|
|
76
|
+
* unobservable over a committed store — is accepted-risk register item 1: it is outside the browser
|
|
77
|
+
* termination model, and a later sentinel/record conflict surfaces as a hard error, never silently resolved.
|
|
78
|
+
*/
|
|
79
|
+
export declare function classifyStoreBoot(obs: StoreBootObservations): StoreBootVerdict;
|
|
80
|
+
/** The dedicated IndexedDB database holding every store's meta record — SEPARATE from PGlite's own idb stores. */
|
|
81
|
+
export declare const STORE_META_DATABASE = "pgxsinkit-store-meta";
|
|
82
|
+
/** The bounded read-retry budget before a failed read fails closed (invariant 12). */
|
|
83
|
+
export declare const META_READ_ATTEMPTS = 3;
|
|
84
|
+
/**
|
|
85
|
+
* A failed meta read is an ERROR, never "no record" (invariant 12). After {@link META_READ_ATTEMPTS} bounded
|
|
86
|
+
* retries a read that could not be completed fails closed with this distinct type; a stored value of the
|
|
87
|
+
* wrong shape / an unknown phase raises it too (corruption is not absence). A distinct type — not a bare
|
|
88
|
+
* `Error` — so the boot caller can `instanceof`-branch fail-closed from a proven absence.
|
|
89
|
+
*/
|
|
90
|
+
export declare class StoreMetaUnreadableError extends Error {
|
|
91
|
+
constructor(storePath: string, cause?: unknown);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returned by {@link readStoreMetaRecord} when the `indexedDB` API is ENTIRELY ABSENT — distinct from both a
|
|
95
|
+
* proven absence (`undefined`) and an unreadable record (an error). A no-IDB environment cannot hold a
|
|
96
|
+
* record at all, so absence IS provable there; the caller (plan step 10) maps this into the
|
|
97
|
+
* "OPFS unobservable"-style path. It is emphatically NOT the same as a THROWING IDB, whose outcome is
|
|
98
|
+
* ambiguous → {@link StoreMetaUnreadableError}.
|
|
99
|
+
*/
|
|
100
|
+
export declare const META_STORE_UNAVAILABLE: unique symbol;
|
|
101
|
+
/** The injectable IO seam so Bun unit tests fake IndexedDB (there is no browser IDB there). */
|
|
102
|
+
export interface StoreMetaDeps {
|
|
103
|
+
/** The IndexedDB surface; defaults to `globalThis.indexedDB`. Explicit `undefined` selects the no-IDB path. */
|
|
104
|
+
indexedDB?: IndexedDbLike | undefined;
|
|
105
|
+
/** The between-retries delay; defaults to a real timer. Injected in tests to prove the retry count. */
|
|
106
|
+
delay?: (ms: number) => Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
interface IdbRequestLike {
|
|
109
|
+
result: unknown;
|
|
110
|
+
error: unknown;
|
|
111
|
+
onsuccess: (() => void) | null;
|
|
112
|
+
onerror: (() => void) | null;
|
|
113
|
+
}
|
|
114
|
+
interface IdbObjectStoreLike {
|
|
115
|
+
get(key: string): IdbRequestLike;
|
|
116
|
+
put(value: unknown, key: string): IdbRequestLike;
|
|
117
|
+
delete(key: string): IdbRequestLike;
|
|
118
|
+
}
|
|
119
|
+
interface IdbTransactionLike {
|
|
120
|
+
objectStore(name: string): IdbObjectStoreLike;
|
|
121
|
+
abort(): void;
|
|
122
|
+
commit?(): void;
|
|
123
|
+
error?: unknown;
|
|
124
|
+
oncomplete: (() => void) | null;
|
|
125
|
+
onabort: (() => void) | null;
|
|
126
|
+
onerror: (() => void) | null;
|
|
127
|
+
}
|
|
128
|
+
interface IdbDatabaseLike {
|
|
129
|
+
transaction(store: string, mode: "readonly" | "readwrite", options?: {
|
|
130
|
+
durability?: "default" | "relaxed" | "strict";
|
|
131
|
+
}): IdbTransactionLike;
|
|
132
|
+
objectStoreNames: {
|
|
133
|
+
contains(name: string): boolean;
|
|
134
|
+
};
|
|
135
|
+
createObjectStore(name: string): IdbObjectStoreLike;
|
|
136
|
+
close(): void;
|
|
137
|
+
}
|
|
138
|
+
interface IdbVersionChangeEventLike {
|
|
139
|
+
target: {
|
|
140
|
+
transaction?: IdbTransactionLike | null;
|
|
141
|
+
} | null;
|
|
142
|
+
}
|
|
143
|
+
interface IdbOpenDbRequestLike {
|
|
144
|
+
result: IdbDatabaseLike;
|
|
145
|
+
error: unknown;
|
|
146
|
+
transaction: IdbTransactionLike | null;
|
|
147
|
+
onupgradeneeded: ((event: IdbVersionChangeEventLike) => void) | null;
|
|
148
|
+
onsuccess: (() => void) | null;
|
|
149
|
+
onerror: (() => void) | null;
|
|
150
|
+
}
|
|
151
|
+
interface IndexedDbLike {
|
|
152
|
+
open(name: string, version?: number): IdbOpenDbRequestLike;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Read a store's meta record, applying the FAILED-READ POLICY (invariant 12):
|
|
156
|
+
* - `indexedDB` entirely absent → {@link META_STORE_UNAVAILABLE} (a no-IDB environment cannot hold a record,
|
|
157
|
+
* so absence is provable; the caller maps this into the "OPFS unobservable"-style path).
|
|
158
|
+
* - A successful read that finds nothing → `undefined` (a proven absence).
|
|
159
|
+
* - An open/get that fails is retried up to {@link META_READ_ATTEMPTS} times (an injectable delay between);
|
|
160
|
+
* if every attempt fails, throws {@link StoreMetaUnreadableError} (fail closed, NEVER "no record").
|
|
161
|
+
* - A stored value of the wrong shape / unknown phase → {@link StoreMetaUnreadableError} immediately
|
|
162
|
+
* (deterministic corruption; retrying cannot help, and it must not classify as absent).
|
|
163
|
+
*/
|
|
164
|
+
export declare function readStoreMetaRecord(storePath: string, deps?: StoreMetaDeps): Promise<StoreMetaRecord | undefined | typeof META_STORE_UNAVAILABLE>;
|
|
165
|
+
/**
|
|
166
|
+
* Write (create or overwrite) a store's meta record — done at CREATION for every backend, before exposure,
|
|
167
|
+
* and at each phase transition (invariant 12). A no-IDB environment cannot hold a record, so this is a
|
|
168
|
+
* best-effort no-op there (consistent with {@link readStoreMetaRecord} returning {@link META_STORE_UNAVAILABLE}).
|
|
169
|
+
*/
|
|
170
|
+
export declare function writeStoreMetaRecord(storePath: string, record: StoreMetaRecord, deps?: StoreMetaDeps): Promise<void>;
|
|
171
|
+
/** Delete a store's meta record — the terminal step of the destructive lifecycle (invariant 12/13). */
|
|
172
|
+
export declare function deleteStoreMetaRecord(storePath: string, deps?: StoreMetaDeps): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Does PGlite's idb database for this store ALREADY exist, WITHOUT creating it? The recordless-idb recognition
|
|
175
|
+
* check (invariant 14): no meta record + an existing idb store → `idb-authoritative`, never virgin. This is
|
|
176
|
+
* the entry point of the forward idbfs→opfs transition — an existing idb store's data is never overwritten by
|
|
177
|
+
* a fresh opfs mint; it is opened in place (fixed/denied home) or migrated forward via adoption.
|
|
178
|
+
*
|
|
179
|
+
* Technique (per ADR-0049 D6 — NEVER `indexedDB.databases()`, which is absent on some engines): open the
|
|
180
|
+
* database with NO version. If `onupgradeneeded` fires, the database did NOT exist — flag it and ABORT the
|
|
181
|
+
* versionchange transaction (`event.target.transaction.abort()`) so the freshly-created empty database does
|
|
182
|
+
* not persist, then resolve `false`. On `onsuccess` WITHOUT an upgrade the database already existed — close
|
|
183
|
+
* the handle and resolve `true`. The `onerror` that follows an abort is the EXPECTED completion of the
|
|
184
|
+
* non-exist path (the AbortError), not a failure — it resolves `false`. `indexedDB` absent → `false`
|
|
185
|
+
* (no idb store can exist). The database name comes from `store-path.ts`'s {@link storeIndexedDbDatabaseName}
|
|
186
|
+
* (the sole owner of PGlite's `/pglite/` naming) — never re-derived here.
|
|
187
|
+
*/
|
|
188
|
+
export declare function idbStoreExists(storePath: string, deps?: StoreMetaDeps): Promise<boolean>;
|
|
189
|
+
export {};
|
|
190
|
+
//# sourceMappingURL=store-meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-meta.d.ts","sourceRoot":"","sources":["../src/store-meta.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH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AAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAmCxF"}
|
package/dist/store-path.d.ts
CHANGED
|
@@ -75,24 +75,84 @@ export declare function normaliseStorePathInput(input: StorePathInput): {
|
|
|
75
75
|
*/
|
|
76
76
|
export interface StoreEnv {
|
|
77
77
|
hasIndexedDb: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* ADR-0049 (D1): the PLACEMENT PROBE's injected result — whether a REAL `createSyncAccessHandle` open
|
|
80
|
+
* succeeded in the executing scope (the bench phase-0 mechanism, performed by the async boot path — never
|
|
81
|
+
* method-presence sniffing). Optional so every existing `StoreEnv` construction stays valid; `undefined`
|
|
82
|
+
* means "no OPFS sync access" (false). {@link detectStoreEnv} ALWAYS reports `false` for it: there is no
|
|
83
|
+
* synchronous ambient detection for handle grants, and method-presence sniffing is forbidden — only the
|
|
84
|
+
* boot path's real probe open can flip it true.
|
|
85
|
+
*/
|
|
86
|
+
hasOpfsSyncAccess?: boolean;
|
|
78
87
|
}
|
|
79
88
|
/**
|
|
80
89
|
* Resolve a plain {@link storePath} to the PGlite dataDir URL the store opens at — the ONE derivation point
|
|
81
|
-
* (ADR-0036 decision 2).
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* scheme-selected `memory://<storePath>`
|
|
90
|
+
* (ADR-0036 decision 2, amended by ADR-0049). A browser worker with a proven OPFS sync-access grant resolves
|
|
91
|
+
* to `opfs://<storePath>`; another browser context (`indexedDB` present) resolves to `idb://<storePath>`;
|
|
92
|
+
* Bun/Node resolves to `file://<storePath>` (relative paths use the working directory). The `backendOverride`
|
|
93
|
+
* is internal-only: `"memory"` selects a scheme-selected `memory://<storePath>` test/ephemeral store.
|
|
85
94
|
*
|
|
86
95
|
* 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
|
|
96
|
+
* contract fails loudly at the boundary, never silently re-interpreted. The returned URL is
|
|
88
97
|
* internal plumbing; do not surface it to consumers as something to imitate.
|
|
89
98
|
*
|
|
90
99
|
* CRITICAL (ADR-0036 decision 5, probed on PGlite 0.5.4): memory selection is ALWAYS the scheme-selected
|
|
91
100
|
* `memory://` form, NEVER PGlite's explicit `fs: new MemoryFS()` option — `dumpDataDir` from an explicit-`fs`
|
|
92
101
|
* instance silently omits relation files created after initdb, so a restored clone raises "relation does not
|
|
93
102
|
* exist". Callers that need a memory store must route through this function, never construct `MemoryFS`.
|
|
103
|
+
*
|
|
104
|
+
* ADR-0049 (D1) adds the `opfs://<storePath>` form: when the placement probe granted a sync-access handle in
|
|
105
|
+
* the executing scope (`env.hasOpfsSyncAccess`), the browser store lives on `opfs-repacked`. Precedence:
|
|
106
|
+
* memory override (test/ephemeral) → `opfs://` (probe granted) → `idb://` (browser, handle denied) →
|
|
107
|
+
* `file://` (Bun/Node). `opfs://` is TOOLKIT-INTERNAL plumbing — PGlite does NOT accept it as a `dataDir`;
|
|
108
|
+
* {@link createClientPGlite} (plan step 10) interprets it via the opfs-repacked factory + the OPFS namespace
|
|
109
|
+
* builders below. Like every URL resolved here, it never leaks to consumers.
|
|
94
110
|
*/
|
|
95
111
|
export declare function resolveStoreDataDir(storePath: string, backendOverride?: "memory", env?: StoreEnv): string;
|
|
112
|
+
/**
|
|
113
|
+
* The ONE injective encoding for every browser-side identity surface (ADR-0049 D11, invariant 10): OPFS
|
|
114
|
+
* namespace entries ({@link opfsStoreDirectoryPath} / {@link opfsCommitmentSentinelPath}), the leader lock
|
|
115
|
+
* name, the store meta record key, and the communication-centre SharedWorker name all derive from this single
|
|
116
|
+
* canonical component. Percent-encoding (`encodeURIComponent`) — injective, never lossy sanitising, so two
|
|
117
|
+
* distinct store paths can never collapse to one identity (e.g. `"foo/bar"` → `foo%2Fbar` vs the literal
|
|
118
|
+
* `"foo%2Fbar"` → `foo%252Fbar`).
|
|
119
|
+
*
|
|
120
|
+
* Domain (invariant 10):
|
|
121
|
+
* - Same boundary guards as {@link resolveStoreDataDir}: empty/whitespace-only or scheme-bearing (`://`)
|
|
122
|
+
* paths throw {@link InvalidStorePathError} (shared {@link assertPlainStorePath}).
|
|
123
|
+
* - A lone UTF-16 surrogate makes `encodeURIComponent` raise a `URIError`; that is wrapped into
|
|
124
|
+
* {@link InvalidStorePathError} so callers branch one error type at the boundary.
|
|
125
|
+
* - `.` and `..` pass through `encodeURIComponent` UNCHANGED, but the File System Standard reserves them as
|
|
126
|
+
* invalid file names, so both are rejected.
|
|
127
|
+
* - The ENCODED length is capped at {@link STORE_IDENTITY_ENCODED_CAP} (a per-component filesystem-safe
|
|
128
|
+
* bound); overflow is rejected.
|
|
129
|
+
*/
|
|
130
|
+
export declare function storeIdentityComponent(storePath: string): string;
|
|
131
|
+
/**
|
|
132
|
+
* The toolkit-owned OPFS container at the root (ADR-0049 D6). Its child namespaces (`stores`, `commitments`,
|
|
133
|
+
* `probe`) are DISJOINT so two valid identities can never contend for one OPFS entry (e.g. store `"foo"`'s
|
|
134
|
+
* commitment sentinel vs a store literally named `"foo.committed"`). This module is the ONLY place that knows
|
|
135
|
+
* these names — the same rule that keeps {@link storeIndexedDbDatabaseName} the sole owner of the `/pglite/`
|
|
136
|
+
* prefix.
|
|
137
|
+
*/
|
|
138
|
+
export declare const OPFS_TOOLKIT_CONTAINER = "pgxsinkit";
|
|
139
|
+
/**
|
|
140
|
+
* OPFS path (segment array) of a store's four-file VFS directory: `pgxsinkit/stores/<identity>` (ADR-0049 D6).
|
|
141
|
+
* Returned as SEGMENTS, not a joined string, because consumers traverse OPFS via a `getDirectoryHandle` chain.
|
|
142
|
+
*/
|
|
143
|
+
export declare function opfsStoreDirectoryPath(storePath: string): readonly [string, string, string];
|
|
144
|
+
/**
|
|
145
|
+
* OPFS path (segment array) of a store's commitment marker sentinel: `pgxsinkit/commitments/<identity>`
|
|
146
|
+
* (ADR-0049 D6). Disjoint from {@link opfsStoreDirectoryPath} — the store directory holds exactly the four
|
|
147
|
+
* VFS-owned files, and a suffix-sibling sentinel would collide across valid identities. Segments, not a joined
|
|
148
|
+
* string, for the same `getDirectoryHandle`-chain reason.
|
|
149
|
+
*/
|
|
150
|
+
export declare function opfsCommitmentSentinelPath(storePath: string): readonly [string, string, string];
|
|
151
|
+
/**
|
|
152
|
+
* OPFS path (segment array) of the placement-probe scratch namespace: `pgxsinkit/probe` (ADR-0049 D6). No
|
|
153
|
+
* identity — the probe is per-SharedWorker-scope, not per-store. Segments, not a joined string.
|
|
154
|
+
*/
|
|
155
|
+
export declare function opfsProbeDirectoryPath(): readonly [string, string];
|
|
96
156
|
/**
|
|
97
157
|
* The IndexedDB database name a browser store occupies (ADR-0036) — a browser-only OPERATIONAL helper for
|
|
98
158
|
* orphan GC / corrupt-store deletion (`indexedDB.deleteDatabase(...)`), NOT part of the create path. PGlite
|
|
@@ -112,8 +172,8 @@ export declare function storeIndexedDbDatabaseName(storePath: string): string;
|
|
|
112
172
|
*/
|
|
113
173
|
export declare function classifyNonPersistentDataDir(dataDir: string | undefined): "in-memory-default" | "memory-scheme" | null;
|
|
114
174
|
/**
|
|
115
|
-
* Does
|
|
116
|
-
* restore (ADR-0035 decision 6) — restore refuses a target that is already there. Per backend:
|
|
175
|
+
* Does either backend a browser boot could own for a plain {@link storePath} ALREADY exist? The fresh-target
|
|
176
|
+
* gate for a restore (ADR-0035 decision 6) — restore refuses a target that is already there. Per backend:
|
|
117
177
|
*
|
|
118
178
|
* - **memory** (`backendOverride === "memory"`) — a scheme-selected memory store is fresh by construction:
|
|
119
179
|
* it lives only for the instance about to be created, so there is nothing to collide with. Always `false`
|
|
@@ -122,6 +182,16 @@ export declare function classifyNonPersistentDataDir(dataDir: string | undefined
|
|
|
122
182
|
* DYNAMICALLY inside this branch, never at module top level, so a browser bundle (which only ever hits the
|
|
123
183
|
* `idb://` branch below) never pulls `node:fs` in. Relative paths resolve against the working directory,
|
|
124
184
|
* exactly as PGlite's filesystem backend and {@link resolveStoreDataDir} do.
|
|
185
|
+
* - **`opfs://`** (browser, placement probe granted) — existence of the store DIRECTORY at
|
|
186
|
+
* `pgxsinkit/stores/<identity>` ({@link opfsStoreDirectoryPath}), walked via
|
|
187
|
+
* `navigator.storage.getDirectory()` and a `getDirectoryHandle` chain with `{ create: false }`. This is
|
|
188
|
+
* ONLY the fresh-target gate; it is emphatically NOT commitment authority — a store directory without a
|
|
189
|
+
* commitment marker is an uncommitted CANDIDATE, and deciding that is the store meta record's phase machine
|
|
190
|
+
* (plan step 2), never this function. `navigator.storage`/`getDirectory` absent → best-effort `false`
|
|
191
|
+
* (mirrors the idb `databases()` stance — never fabricate a positive). A `NotFoundError` anywhere in the
|
|
192
|
+
* chain → `false`; any OTHER error propagates (a genuine failure the restore caller must see).
|
|
193
|
+
* A missing OPFS directory does not finish a granted browser check: IDB is also probed, because a predecessor
|
|
194
|
+
* or fixed-placement store may still own the same public path.
|
|
125
195
|
* - **`idb://`** (browser/worker) — `indexedDB.databases()` enumerated for the store's database name
|
|
126
196
|
* ({@link storeIndexedDbDatabaseName}). BEST-EFFORT: `databases()` is unavailable on some engines (older
|
|
127
197
|
* Firefox, certain worker contexts); when absent we CANNOT prove existence, so we report `false` and let
|
package/dist/store-path.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-path.d.ts","sourceRoot":"","sources":["../src/store-path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store-path.d.ts","sourceRoot":"","sources":["../src/store-path.ts"],"names":[],"mappings":"AAsBA;;;;;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,eAAe,EAa1D;CACF;AAED;;;;;;;GAOG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,SAAS,EAAE,MAAM,EAQ5B;C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0B,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAE/F;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAElE;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAYpE;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,mBAAmB,GAAG,eAAe,GAAG,IAAI,CAI9C;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,QAAQ,EAC1B,GAAG,GAAE,QAA2B,GAC/B,OAAO,CAAC,OAAO,CAAC,CA2ClB"}
|
package/dist/sync/apply.d.ts
CHANGED
|
@@ -26,7 +26,18 @@ export declare function applyInsertsToTable({ pg, target, messages, debug }: Bul
|
|
|
26
26
|
* row is expected, not a bug. Batched by parameter count (move-in volume is incremental, not a backfill).
|
|
27
27
|
*/
|
|
28
28
|
export declare function applyUpsertsToTable({ pg, target, messages, debug }: BulkKeyedApplyOptions): Promise<void>;
|
|
29
|
-
export declare function applyMessagesToTableWithJson(
|
|
29
|
+
export declare function applyMessagesToTableWithJson(options: BulkApplyMessagesToTableOptions): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* The `json_to_recordset` **upsert** applier — the ADR-0045 initial-load tier for an `applyMode: "upsert"`
|
|
32
|
+
* table. Identical bulk shape to {@link applyMessagesToTableWithJson} (one statement, one bound param per
|
|
33
|
+
* batch) but with the `ON CONFLICT (pk) DO UPDATE`/`DO NOTHING` clause appended, so a snapshot for a table
|
|
34
|
+
* that already holds locally-derived provisional rows applies idempotently without the 23505 collision the
|
|
35
|
+
* strict path would raise. This is the bulk CEILING for upsert-mode tables: COPY (the faster tier) has no
|
|
36
|
+
* conflict clause, so the initial path downgrades a COPY-eligible upsert table to json rather than
|
|
37
|
+
* param-bound `applyUpsertsToTable` (~31k bound params/statement for a wide table — the very cost this
|
|
38
|
+
* path avoids).
|
|
39
|
+
*/
|
|
40
|
+
export declare function applyUpsertsToTableWithJson(options: BulkApplyMessagesToTableOptions): Promise<void>;
|
|
30
41
|
export declare function applyMessagesToTableWithCopy({ pg, target, messages, debug }: BulkApplyMessagesToTableOptions): Promise<void>;
|
|
31
42
|
export interface BulkKeyedApplyOptions {
|
|
32
43
|
pg: PGliteInterface | Transaction;
|
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,aAAa,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMzE,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,aAAa,CAAC,GAAG,CAAC,OAAO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AE,QAAQ,EAAE,KAAK,EAAE,EAAE,qBAAqB,iBAgDnG"}
|
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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA2C5D,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;4MA2BzC,yBAAyB,KAAG,OAAO,CAAC,wBAAwB,CAAC;oCAi2BvB,uBAAuB,KAAG,OAAO,CAAC,sBAAsB,CAAC;kCAsC3D,MAAM;;;GAgC9C;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"}
|
|
@@ -199,7 +199,7 @@ export interface FoldedShapeBatch {
|
|
|
199
199
|
*
|
|
200
200
|
* - **trailing `delete`** ⇒ a single DELETE;
|
|
201
201
|
* - **`insert` with no preceding delete**, then any updates ⇒ a single INSERT with merged values
|
|
202
|
-
* (a *plain* insert — a genuine PK collision still surfaces, never a silent upsert
|
|
202
|
+
* (a *plain* insert — a genuine PK collision still surfaces, never a silent upsert);
|
|
203
203
|
* - **only `update`s** ⇒ a single UPDATE with merged values;
|
|
204
204
|
* - **re-created** (`[delete, … , insert, …]`, no trailing delete) ⇒ DELETE **and** INSERT, so the
|
|
205
205
|
* pre-existing row is cleared first (faithful to the per-row `DELETE`-then-`INSERT`; a plain INSERT
|
package/dist/sync/types.d.ts
CHANGED
|
@@ -43,9 +43,9 @@ export interface SyncShapesToTablesOptions {
|
|
|
43
43
|
* SESSION-scoped — stored in the engine's `pg_temp` metadata relations that die with the engine, not the
|
|
44
44
|
* durable ones. Set for an `ephemeral`-retention group, whose whole cluster is already TEMP: the cursor
|
|
45
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` —
|
|
47
|
-
* persistent group's storage is
|
|
48
|
-
* the retention model.
|
|
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
49
|
*/
|
|
50
50
|
sessionScoped?: boolean | undefined;
|
|
51
51
|
initialInsertMethod?: InitialInsertMethod | undefined;
|