@pgxsinkit/client 0.1.49 → 0.1.51

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.
Files changed (51) hide show
  1. package/dist/boot-report.d.ts +76 -0
  2. package/dist/boot-report.d.ts.map +1 -1
  3. package/dist/index.d.ts +56 -3
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +1106 -312
  6. package/dist/index.js.map +19 -18
  7. package/dist/local-store.d.ts +58 -0
  8. package/dist/local-store.d.ts.map +1 -1
  9. package/dist/local-tables.d.ts +340 -0
  10. package/dist/local-tables.d.ts.map +1 -1
  11. package/dist/mutation.d.ts +36 -0
  12. package/dist/mutation.d.ts.map +1 -1
  13. package/dist/mutations-api.d.ts +82 -0
  14. package/dist/mutations-api.d.ts.map +1 -0
  15. package/dist/schema.d.ts +80 -1
  16. package/dist/schema.d.ts.map +1 -1
  17. package/dist/shape-sync.d.ts +6 -0
  18. package/dist/shape-sync.d.ts.map +1 -1
  19. package/dist/sync/index.d.ts +1 -1
  20. package/dist/sync/index.d.ts.map +1 -1
  21. package/dist/sync/metadata-tables.d.ts +16 -0
  22. package/dist/sync/metadata-tables.d.ts.map +1 -1
  23. package/dist/sync/subscription-state.d.ts +10 -2
  24. package/dist/sync/subscription-state.d.ts.map +1 -1
  25. package/dist/sync/tags.d.ts +16 -4
  26. package/dist/sync/tags.d.ts.map +1 -1
  27. package/dist/sync/types.d.ts +12 -0
  28. package/dist/sync/types.d.ts.map +1 -1
  29. package/dist/worker/attach-sync-client.d.ts.map +1 -1
  30. package/dist/worker/define-sync-worker.d.ts.map +1 -1
  31. package/dist/worker/protocol.d.ts +44 -1
  32. package/dist/worker/protocol.d.ts.map +1 -1
  33. package/package.json +2 -2
  34. package/skills/core/SKILL.md +1 -1
  35. package/skills/operating/SKILL.md +1 -1
  36. package/src/boot-report.ts +108 -0
  37. package/src/index.ts +555 -136
  38. package/src/local-store.ts +150 -3
  39. package/src/local-tables.ts +49 -1
  40. package/src/mutation.ts +256 -15
  41. package/src/mutations-api.ts +310 -0
  42. package/src/schema.ts +428 -197
  43. package/src/shape-sync.ts +11 -0
  44. package/src/sync/index.ts +14 -1
  45. package/src/sync/metadata-tables.ts +41 -0
  46. package/src/sync/subscription-state.ts +29 -4
  47. package/src/sync/tags.ts +34 -9
  48. package/src/sync/types.ts +12 -0
  49. package/src/worker/attach-sync-client.ts +114 -5
  50. package/src/worker/define-sync-worker.ts +65 -4
  51. package/src/worker/protocol.ts +38 -1
@@ -24,6 +24,14 @@ export interface BootReport {
24
24
  mode: "in-process" | "worker";
25
25
  /** Whether the caller proved the store a schemaless spare (the ADR-0032 S4 fresh-store hint). */
26
26
  freshStore: boolean;
27
+ /**
28
+ * How this store presented at boot: `"restored"` when the boot seeded a brand-new store from a backup
29
+ * (ADR-0035 `restoreFrom`); `"fresh"` when the caller proved it a schemaless spare (the SAME signal as
30
+ * {@link BootReport.freshStore}); `"warm"` otherwise (an existing persisted store — the common case).
31
+ * Distinct from `freshStore`, which stays a bare boolean: `storeKind` additionally names the restore case,
32
+ * which a boolean cannot express.
33
+ */
34
+ storeKind: "fresh" | "warm" | "restored";
27
35
  /** Whether the ADR-0032 S4 fetch/schema overlap was active for this boot. */
28
36
  overlapPrefetch: boolean;
29
37
  /** The registry fingerprint the store is provisioned under — the same value store-version reconcile stamps. */
@@ -32,6 +40,18 @@ export interface BootReport {
32
40
  startedAt: number;
33
41
  /** Boot start → `onInitialSync` (all eager groups caught up). */
34
42
  totalMs: number;
43
+ /**
44
+ * Boot start → `localReadReady` resolved (ADR-0041): PGlite open, durable schema compatible, store-version
45
+ * reconcile complete, and the drizzle read facade built — cached reads are safe with ZERO network. `null`
46
+ * when the boot rejected before the stage. Additive field; `reportVersion` stays `1`.
47
+ */
48
+ localReadReadyMs: number | null;
49
+ /**
50
+ * Boot start → `writeReady` resolved (ADR-0041): the mutation runtime is constructed and boot recovery
51
+ * (plus restore quarantine on a restore boot) has completed — enqueue is safe. `null` when the boot
52
+ * rejected before the stage. Additive field; `reportVersion` stays `1`.
53
+ */
54
+ writeReadyMs: number | null;
35
55
  /**
36
56
  * Present only when the store was pre-provisioned (a spare's initdb ran off-thread before this boot
37
57
  * adopted it); `null` otherwise. When present, `phases.pgliteCreateMs` is `null` — the create cost is
@@ -64,6 +84,31 @@ export interface BootReport {
64
84
  */
65
85
  prepareMs?: number;
66
86
  };
87
+ /**
88
+ * Warm-persisted-store-startup observability (the schema-replay + journal-recovery fast-path lane). Every
89
+ * field carries the honest CURRENT truth so the report never lies mid-lane: the durable-schema-fingerprint
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.
93
+ */
94
+ warmBoot: {
95
+ /** Whether durable-schema replay was skipped this boot (a fingerprint match). `false` today — replay is unconditional. */
96
+ schemaSkipped: boolean;
97
+ /** Whether the stored durable-schema fingerprint matched the generated schema. `false` today — not yet computed. */
98
+ schemaFingerprintMatch: boolean;
99
+ /** Whether the boot-time `recoverSending` journal pass was skipped this boot. `false` today — the pass is unconditional. */
100
+ journalRecoverySkipped: boolean;
101
+ /**
102
+ * Whether journal recovery was required this boot. `true` today under pre-marker legacy semantics: with no
103
+ * durable recovery marker, recovery is ALWAYS treated as required. The recovery-marker slice will set this
104
+ * from the durable marker instead (a clean shutdown clears the marker → `false`, skipping recovery).
105
+ */
106
+ journalRecoveryRequired: boolean;
107
+ /** How many writable table journals the boot-time `recoverSending` pass visited (the registry's writable-entry count). */
108
+ journalTablesVisited: number;
109
+ /** Rows lifted `sending → pending` by recovery. `null` = not yet instrumented; populated by the recovery-marker slice. */
110
+ journalRowsRecovered: number | null;
111
+ };
67
112
  /**
68
113
  * Per consistency GROUP, for the eager + promoted boot groups only (a lazily-activated-later group never
69
114
  * appears — nor mutates a finalized report). Groups run concurrently, so `fetchMs`/`applyMs` are per-group
@@ -190,6 +235,33 @@ export interface BootReportBuilder extends BootStampCollector {
190
235
  ) => Promise<T>;
191
236
  setPgliteCreateMs: (ms: number | null) => void;
192
237
  setProvision: (provision: BootReport["provision"]) => void;
238
+ /**
239
+ * Record the durable-schema fast-path outcome (the durable-schema-fingerprint slice): whether replay was
240
+ * skipped and whether the stored fingerprint matched. Both default to the current truth (`false`), so this
241
+ * need not be called until that slice lands.
242
+ */
243
+ setSchemaFastPath: (info: { skipped: boolean; fingerprintMatch: boolean }) => void;
244
+ /**
245
+ * Record the boot-time journal-recovery outcome (the recovery-marker slice): whether the pass was skipped,
246
+ * whether it was required, how many writable journals it visited, and how many rows it lifted (`null` until
247
+ * instrumented). `tablesVisited` is wired from boot today; the rest default to current-truth values.
248
+ */
249
+ setJournalRecovery: (info: {
250
+ skipped: boolean;
251
+ required: boolean;
252
+ tablesVisited: number;
253
+ rowsRecovered: number | null;
254
+ }) => void;
255
+ /**
256
+ * Stamp `localReadReadyMs` at the moment the staged local-read core resolves `localReadReady` (ADR-0041).
257
+ * Idempotent — the first stamp wins.
258
+ */
259
+ setLocalReadReadyMs: (ms: number) => void;
260
+ /**
261
+ * Stamp `writeReadyMs` at the moment the write/recovery tail resolves `writeReady` (ADR-0041). Idempotent —
262
+ * the first stamp wins.
263
+ */
264
+ setWriteReadyMs: (ms: number) => void;
193
265
  /**
194
266
  * Record `phases.syncStartMs` directly — for the ADR-0032 S4 overlap path, where sync construction is
195
267
  * kicked off before schema exec (not wrapped in {@link BootReportBuilder.phase}) and has no rail line.
@@ -207,6 +279,7 @@ export interface BootReportBuilder extends BootStampCollector {
207
279
  export interface BootReportInit {
208
280
  mode: BootReport["mode"];
209
281
  freshStore: boolean;
282
+ storeKind: BootReport["storeKind"];
210
283
  overlapPrefetch: boolean;
211
284
  registryFingerprint: string;
212
285
  }
@@ -218,7 +291,20 @@ export function createBootReportBuilder(init: BootReportInit): BootReportBuilder
218
291
  let prepareMs: number | null = null;
219
292
  let pgliteCreateMs: number | null = null;
220
293
  let provision: BootReport["provision"] = null;
294
+ // Current-truth defaults (this slice's honest baseline): durable schema replay + journal recovery are both
295
+ // unconditional today, and recovery is always treated as required pre-marker. Later slices flip these via
296
+ // the setters below.
297
+ let warmBoot: BootReport["warmBoot"] = {
298
+ schemaSkipped: false,
299
+ schemaFingerprintMatch: false,
300
+ journalRecoverySkipped: false,
301
+ journalRecoveryRequired: true,
302
+ journalTablesVisited: 0,
303
+ journalRowsRecovered: null,
304
+ };
221
305
  let syncStartDoneOffset: number | null = null;
306
+ let localReadReadyMs: number | null = null;
307
+ let writeReadyMs: number | null = null;
222
308
  const groups: GroupAccumulator[] = [];
223
309
  let built: BootReport | null = null;
224
310
 
@@ -245,6 +331,24 @@ export function createBootReportBuilder(init: BootReportInit): BootReportBuilder
245
331
  setProvision: (value) => {
246
332
  provision = value;
247
333
  },
334
+ setSchemaFastPath: (info) => {
335
+ warmBoot = { ...warmBoot, schemaSkipped: info.skipped, schemaFingerprintMatch: info.fingerprintMatch };
336
+ },
337
+ setJournalRecovery: (info) => {
338
+ warmBoot = {
339
+ ...warmBoot,
340
+ journalRecoverySkipped: info.skipped,
341
+ journalRecoveryRequired: info.required,
342
+ journalTablesVisited: info.tablesVisited,
343
+ journalRowsRecovered: info.rowsRecovered,
344
+ };
345
+ },
346
+ setLocalReadReadyMs: (ms) => {
347
+ if (localReadReadyMs == null) localReadReadyMs = ms;
348
+ },
349
+ setWriteReadyMs: (ms) => {
350
+ if (writeReadyMs == null) writeReadyMs = ms;
351
+ },
248
352
  setSyncStartMs: (ms) => {
249
353
  durations.set("syncStart", ms);
250
354
  },
@@ -264,11 +368,15 @@ export function createBootReportBuilder(init: BootReportInit): BootReportBuilder
264
368
  reportVersion: 1,
265
369
  mode: init.mode,
266
370
  freshStore: init.freshStore,
371
+ storeKind: init.storeKind,
267
372
  overlapPrefetch: init.overlapPrefetch,
268
373
  registryFingerprint: init.registryFingerprint,
269
374
  startedAt,
270
375
  totalMs,
376
+ localReadReadyMs,
377
+ writeReadyMs,
271
378
  provision,
379
+ warmBoot,
272
380
  phases: {
273
381
  pgliteCreateMs,
274
382
  schemaExecMs: duration("schemaExec"),