@pgxsinkit/client 0.1.53 → 0.2.1
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/export-store.d.ts +1 -1
- package/dist/export-store.d.ts.map +1 -1
- package/dist/index.d.ts +286 -51
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4795 -1519
- package/dist/index.js.map +34 -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 +4 -4
- package/dist/mutation.d.ts +18 -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.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 +300 -16
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +164 -23
- 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 +266 -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/protocol.d.ts +47 -31
- 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 -12
- package/skills/operating/SKILL.md +142 -46
- package/src/adoption.ts +275 -0
- package/src/boot-report.ts +70 -17
- package/src/convergence.ts +2 -1
- package/src/export-store.ts +1 -1
- package/src/index.ts +1157 -115
- package/src/live-rows-sql.ts +1 -1
- package/src/local-store.ts +18 -40
- package/src/local-tables.ts +2 -2
- package/src/mutation.ts +115 -53
- 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 +63 -63
- package/src/sync/index.ts +2 -2
- 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 +1753 -102
- package/src/worker/define-sync-worker.ts +1034 -71
- 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 +4 -1
- package/src/worker/protocol.ts +46 -16
- package/src/worker/sw-placement.ts +64 -0
package/src/boot-report.ts
CHANGED
|
@@ -32,6 +32,31 @@ export interface BootReport {
|
|
|
32
32
|
* which a boolean cannot express.
|
|
33
33
|
*/
|
|
34
34
|
storeKind: "fresh" | "warm" | "restored";
|
|
35
|
+
/**
|
|
36
|
+
* The store backend this boot actually opened (ADR-0049 decision 12): `"opfs-repacked"` (the placement probe
|
|
37
|
+
* granted sync-access handles in the engine home), `"idbfs"` (browser/worker, handles denied — today's default),
|
|
38
|
+
* `"filesystem"` (Bun/Node), or `"memory"` (the sanctioned test/ephemeral lane). Derived from the minted dataDir
|
|
39
|
+
* scheme at the single client-owned mint seam; absent (omitted) on a BYO instance whose backend is underivable.
|
|
40
|
+
* Additive field; `reportVersion` stays `1`. Distinct from {@link BootReport.storeKind}, which is untouched.
|
|
41
|
+
*/
|
|
42
|
+
storageBackend?: "opfs-repacked" | "idbfs" | "filesystem" | "memory";
|
|
43
|
+
/**
|
|
44
|
+
* Where the engine ran for this boot (ADR-0049 decision 12): `"in-process"` for the main-thread/Bun
|
|
45
|
+
* `createSyncClient`; inside `defineSyncWorker`, the placement-probe result — `"shared-worker"` (the engine boots
|
|
46
|
+
* in the SharedWorker itself, WebKit today) or `"elected-worker"` (a tab-spawned dedicated worker holds the
|
|
47
|
+
* handles, Chromium/Firefox). Absent (omitted) when the boot cannot derive it (e.g. a dedicated elected-engine
|
|
48
|
+
* worker that never ran the SharedWorker placement decision). Additive field; `reportVersion` stays `1`.
|
|
49
|
+
*/
|
|
50
|
+
engineHome?: "shared-worker" | "elected-worker" | "in-process";
|
|
51
|
+
/**
|
|
52
|
+
* The verbatim reason an opfs-CAPABLE boot (the probe granted sync-access handles) nonetheless opened `idbfs`
|
|
53
|
+
* (ADR-0049 decision 12). Set ONLY when such a fallback actually occurred — never on a plain idb boot (the probe
|
|
54
|
+
* denied from the start), and never on a granted opfs boot that stayed on opfs. Today's set-sites are the
|
|
55
|
+
* granted-then-idb transitions the client owns: a declaration-gated adoption that deferred/failed (idb stays
|
|
56
|
+
* authoritative) and the recordless idb-store downgrade (invariant 14 — never a fresh opfs mint over an
|
|
57
|
+
* existing idb store's data). Additive field; `reportVersion` stays `1`.
|
|
58
|
+
*/
|
|
59
|
+
storageFallbackReason?: string;
|
|
35
60
|
/** Whether the ADR-0032 S4 fetch/schema overlap was active for this boot. */
|
|
36
61
|
overlapPrefetch: boolean;
|
|
37
62
|
/** The registry fingerprint the store is provisioned under — the same value store-version reconcile stamps. */
|
|
@@ -71,42 +96,39 @@ export interface BootReport {
|
|
|
71
96
|
storeVersionReconcileMs: number;
|
|
72
97
|
/**
|
|
73
98
|
* `startConfiguredSync`: stream/group construction wall. On an overlap boot (ADR-0032 S4,
|
|
74
|
-
* {@link BootReport.overlapPrefetch}) the early-started segment runs concurrently with schema
|
|
75
|
-
*
|
|
99
|
+
* {@link BootReport.overlapPrefetch}) the early-started segment runs concurrently with schema, journal
|
|
100
|
+
* recovery, and registry reconciliation, so this includes that shared wall. Structurally 0 when the boot
|
|
101
|
+
* is ready inside the
|
|
76
102
|
* sync-start call itself (zero eager groups / instant catch-up) — finalize runs before the phase closes.
|
|
77
103
|
*/
|
|
78
104
|
syncStartMs: number;
|
|
79
105
|
/** Sync-start done → last eager boot group ready. */
|
|
80
106
|
catchupMs: number;
|
|
81
107
|
/**
|
|
82
|
-
* Cumulative time in configured prepare hooks (`prepareLocalDbBeforeSchema` + `
|
|
108
|
+
* Cumulative time in configured prepare hooks (`prepareLocalDbBeforeSchema` + `prepareLocalDbAfterSchema`), present
|
|
83
109
|
* only when at least one hook is configured. Not part of the required v1 shape (ADR-0034).
|
|
84
110
|
*/
|
|
85
111
|
prepareMs?: number;
|
|
86
112
|
};
|
|
87
113
|
/**
|
|
88
|
-
* Warm-
|
|
89
|
-
*
|
|
90
|
-
* slice sets the `schema*` flags and the recovery-marker slice the `journal*` flags as those optimizations
|
|
91
|
-
* land. Grouped like {@link BootReport.phases} so the flags structured-clone across the worker bridge as one
|
|
92
|
-
* unit.
|
|
114
|
+
* Warm-store observability for the durable-schema and journal-recovery fast paths. Grouped like
|
|
115
|
+
* {@link BootReport.phases} so the flags structured-clone across the worker bridge as one unit.
|
|
93
116
|
*/
|
|
94
117
|
warmBoot: {
|
|
95
|
-
/** Whether durable-schema replay was skipped this boot
|
|
118
|
+
/** Whether durable-schema replay was skipped this boot because the stored fingerprint matched. */
|
|
96
119
|
schemaSkipped: boolean;
|
|
97
|
-
/** Whether the stored durable-schema fingerprint matched the generated schema.
|
|
120
|
+
/** Whether the stored durable-schema fingerprint matched the generated schema. */
|
|
98
121
|
schemaFingerprintMatch: boolean;
|
|
99
|
-
/** Whether the boot-time `recoverSending` journal pass was skipped this boot.
|
|
122
|
+
/** Whether the boot-time `recoverSending` journal pass was skipped this boot. */
|
|
100
123
|
journalRecoverySkipped: boolean;
|
|
101
124
|
/**
|
|
102
|
-
* Whether
|
|
103
|
-
*
|
|
104
|
-
* from the durable marker instead (a clean shutdown clears the marker → `false`, skipping recovery).
|
|
125
|
+
* Whether the durable recovery marker required journal recovery this boot. A clean settle clears the marker,
|
|
126
|
+
* allowing the next boot to skip the recovery pass.
|
|
105
127
|
*/
|
|
106
128
|
journalRecoveryRequired: boolean;
|
|
107
129
|
/** How many writable table journals the boot-time `recoverSending` pass visited (the registry's writable-entry count). */
|
|
108
130
|
journalTablesVisited: number;
|
|
109
|
-
/** Rows lifted `sending → pending` by recovery
|
|
131
|
+
/** Rows lifted `sending → pending` by recovery; `null` when the selected recovery path cannot count them. */
|
|
110
132
|
journalRowsRecovered: number | null;
|
|
111
133
|
};
|
|
112
134
|
/**
|
|
@@ -235,6 +257,18 @@ export interface BootReportBuilder extends BootStampCollector {
|
|
|
235
257
|
) => Promise<T>;
|
|
236
258
|
setPgliteCreateMs: (ms: number | null) => void;
|
|
237
259
|
setProvision: (provision: BootReport["provision"]) => void;
|
|
260
|
+
/**
|
|
261
|
+
* Stamp `storageBackend` (ADR-0049 decision 12) at the client-owned mint seam, derived from the resolved dataDir
|
|
262
|
+
* scheme. Idempotent — the first stamp wins (the mint runs once per boot). Never called on a BYO instance whose
|
|
263
|
+
* backend is underivable, leaving the field absent.
|
|
264
|
+
*/
|
|
265
|
+
setStorageBackend: (backend: NonNullable<BootReport["storageBackend"]>) => void;
|
|
266
|
+
/**
|
|
267
|
+
* Stamp `storageFallbackReason` (ADR-0049 decision 12) — the verbatim reason an opfs-capable boot opened `idbfs`.
|
|
268
|
+
* Called ONLY when such a fallback occurred; a boot that never falls back leaves the field absent. Idempotent —
|
|
269
|
+
* the first stamp wins.
|
|
270
|
+
*/
|
|
271
|
+
setStorageFallbackReason: (reason: string) => void;
|
|
238
272
|
/**
|
|
239
273
|
* Record the durable-schema fast-path outcome (the durable-schema-fingerprint slice): whether replay was
|
|
240
274
|
* skipped and whether the stored fingerprint matched. Both default to the current truth (`false`), so this
|
|
@@ -280,6 +314,11 @@ export interface BootReportInit {
|
|
|
280
314
|
mode: BootReport["mode"];
|
|
281
315
|
freshStore: boolean;
|
|
282
316
|
storeKind: BootReport["storeKind"];
|
|
317
|
+
/**
|
|
318
|
+
* The engine home for this boot (ADR-0049 decision 12), known at boot start. Omitted (`undefined`) when it
|
|
319
|
+
* cannot be derived up front — the finalized report then carries no `engineHome`.
|
|
320
|
+
*/
|
|
321
|
+
engineHome?: BootReport["engineHome"];
|
|
283
322
|
overlapPrefetch: boolean;
|
|
284
323
|
registryFingerprint: string;
|
|
285
324
|
}
|
|
@@ -291,8 +330,7 @@ export function createBootReportBuilder(init: BootReportInit): BootReportBuilder
|
|
|
291
330
|
let prepareMs: number | null = null;
|
|
292
331
|
let pgliteCreateMs: number | null = null;
|
|
293
332
|
let provision: BootReport["provision"] = null;
|
|
294
|
-
//
|
|
295
|
-
// unconditional today, and recovery is always treated as required pre-marker. Later slices flip these via
|
|
333
|
+
// Conservative defaults used until the boot path reports its actual schema and recovery outcomes through
|
|
296
334
|
// the setters below.
|
|
297
335
|
let warmBoot: BootReport["warmBoot"] = {
|
|
298
336
|
schemaSkipped: false,
|
|
@@ -305,6 +343,10 @@ export function createBootReportBuilder(init: BootReportInit): BootReportBuilder
|
|
|
305
343
|
let syncStartDoneOffset: number | null = null;
|
|
306
344
|
let localReadReadyMs: number | null = null;
|
|
307
345
|
let writeReadyMs: number | null = null;
|
|
346
|
+
// ADR-0049 decision 12 diagnostics — both stamped during the boot (after this builder is created), so they are
|
|
347
|
+
// mutable locals, not `init` fields. Absent (undefined) until stamped; the finalize output omits them then.
|
|
348
|
+
let storageBackend: NonNullable<BootReport["storageBackend"]> | undefined;
|
|
349
|
+
let storageFallbackReason: string | undefined;
|
|
308
350
|
const groups: GroupAccumulator[] = [];
|
|
309
351
|
let built: BootReport | null = null;
|
|
310
352
|
|
|
@@ -331,6 +373,12 @@ export function createBootReportBuilder(init: BootReportInit): BootReportBuilder
|
|
|
331
373
|
setProvision: (value) => {
|
|
332
374
|
provision = value;
|
|
333
375
|
},
|
|
376
|
+
setStorageBackend: (backend) => {
|
|
377
|
+
if (storageBackend == null) storageBackend = backend;
|
|
378
|
+
},
|
|
379
|
+
setStorageFallbackReason: (reason) => {
|
|
380
|
+
if (storageFallbackReason == null) storageFallbackReason = reason;
|
|
381
|
+
},
|
|
334
382
|
setSchemaFastPath: (info) => {
|
|
335
383
|
warmBoot = { ...warmBoot, schemaSkipped: info.skipped, schemaFingerprintMatch: info.fingerprintMatch };
|
|
336
384
|
},
|
|
@@ -369,6 +417,11 @@ export function createBootReportBuilder(init: BootReportInit): BootReportBuilder
|
|
|
369
417
|
mode: init.mode,
|
|
370
418
|
freshStore: init.freshStore,
|
|
371
419
|
storeKind: init.storeKind,
|
|
420
|
+
// ADR-0049 decision 12 diagnostics: additive and OMITTED when not derivable/stamped (so an unstamped boot
|
|
421
|
+
// — or a BYO instance with an underivable backend — carries none of them), keeping `reportVersion` at 1.
|
|
422
|
+
...(init.engineHome != null ? { engineHome: init.engineHome } : {}),
|
|
423
|
+
...(storageBackend != null ? { storageBackend } : {}),
|
|
424
|
+
...(storageFallbackReason != null ? { storageFallbackReason } : {}),
|
|
372
425
|
overlapPrefetch: init.overlapPrefetch,
|
|
373
426
|
registryFingerprint: init.registryFingerprint,
|
|
374
427
|
startedAt,
|
package/src/convergence.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* This driver is the *scheduling-policy seam*: the app decides WHEN to converge (online?
|
|
6
6
|
* foregrounded? on power?) and how it learns those conditions, while the library owns the
|
|
7
7
|
* convergence pass and the congestion policy (jittered backoff + attempt cap, already in the
|
|
8
|
-
* mutation runtime).
|
|
8
|
+
* mutation runtime). The driver is opt-in: pass nothing to `createSyncClient` and no scheduling policy
|
|
9
|
+
* runs — convergence stays fully manual until the app installs one.
|
|
9
10
|
*
|
|
10
11
|
* A pass is `flush` → `reconcile`. It deliberately does NOT call `retryFailed`: `flush`
|
|
11
12
|
* already re-attempts `failed` mutations whose `next_retry_at_us` backoff has elapsed, so a
|
package/src/export-store.ts
CHANGED
|
@@ -175,7 +175,7 @@ export type ExportReport = StoreBackupReport | DiagnosticDumpReport | DataExport
|
|
|
175
175
|
|
|
176
176
|
/** The artefact + its report — the resolved value of {@link SyncClient.exportStore}. */
|
|
177
177
|
export interface StoreExportResult {
|
|
178
|
-
/** The store-backup tarball as a named `File
|
|
178
|
+
/** The store-backup tarball as a named `File`, restorable by PGlite via `loadDataDir`. */
|
|
179
179
|
file: File;
|
|
180
180
|
/** The structured record of the export (ADR-0035). */
|
|
181
181
|
report: StoreBackupReport;
|