@pgxsinkit/client 0.1.48 → 0.1.50

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 (40) 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 +84 -3
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +1549 -333
  6. package/dist/index.js.map +15 -12
  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 +62 -0
  16. package/dist/schema.d.ts.map +1 -1
  17. package/dist/worker/attach-sync-client.d.ts.map +1 -1
  18. package/dist/worker/define-sync-worker.d.ts +17 -0
  19. package/dist/worker/define-sync-worker.d.ts.map +1 -1
  20. package/dist/worker/live-query-fingerprint.d.ts +14 -0
  21. package/dist/worker/live-query-fingerprint.d.ts.map +1 -0
  22. package/dist/worker/live-query-manager.d.ts +130 -0
  23. package/dist/worker/live-query-manager.d.ts.map +1 -0
  24. package/dist/worker/protocol.d.ts +53 -2
  25. package/dist/worker/protocol.d.ts.map +1 -1
  26. package/package.json +2 -2
  27. package/skills/core/SKILL.md +1 -1
  28. package/skills/operating/SKILL.md +29 -1
  29. package/src/boot-report.ts +108 -0
  30. package/src/index.ts +648 -152
  31. package/src/local-store.ts +150 -3
  32. package/src/local-tables.ts +49 -1
  33. package/src/mutation.ts +256 -15
  34. package/src/mutations-api.ts +310 -0
  35. package/src/schema.ts +406 -193
  36. package/src/worker/attach-sync-client.ts +193 -15
  37. package/src/worker/define-sync-worker.ts +267 -53
  38. package/src/worker/live-query-fingerprint.ts +128 -0
  39. package/src/worker/live-query-manager.ts +591 -0
  40. package/src/worker/protocol.ts +49 -1
@@ -179,6 +179,15 @@ export interface SetOnlinePayload {
179
179
  online: boolean;
180
180
  }
181
181
 
182
+ /**
183
+ * The two background boot stages the worker announces over the bridge as one-shot milestones (ADR-0041
184
+ * stage 2). `localReadReady` is NOT in this set: under the Option B contract the `attach-ack` fires AT the
185
+ * engine's `localReadReady`, so a tab resolves that stage from the ack itself (early OR late attach) — it
186
+ * needs no separate milestone. `writeReady` and `bootSettled` cross in the background write/sync tail, after
187
+ * the ack, so they DO ride milestone messages (and the late-attach ack fold).
188
+ */
189
+ export type BootMilestone = "writeReady" | "bootSettled";
190
+
182
191
  /** worker → tab: attach acknowledged. `alreadyBooted` is false for the attach that booted the engine. */
183
192
  export interface AttachAckPayload {
184
193
  alreadyBooted: boolean;
@@ -189,9 +198,28 @@ export interface AttachAckPayload {
189
198
  * the ack, rather than wait for a phase-"ready" status that may never come again.
190
199
  */
191
200
  engineReady?: boolean;
201
+ /**
202
+ * Late-attach milestone fold (ADR-0041 stage 2): true when the engine had ALREADY crossed `writeReady` /
203
+ * `bootSettled` by the time this attach was acked, so a tab attaching after the stage fired resolves it
204
+ * straight from the ack rather than waiting for a `milestone` broadcast it missed. The ack fires AT
205
+ * `localReadReady`, so that stage is always implied by a non-error ack and carries no boolean.
206
+ */
207
+ writeReady?: boolean;
208
+ bootSettled?: boolean;
209
+ /**
210
+ * Late-attach failure fold (ADR-0041 stage 2): present when the engine's background write/sync tail had
211
+ * already REJECTED a downstream stage before this attach was acked. The tab rejects the matching stage
212
+ * promise (so a gated write / `bootSettled` awaiter fails loudly rather than hangs) — but the attach
213
+ * itself still RESOLVES (the engine reached `localReadReady`; only the tail failed). A live milestone
214
+ * failure after attach rides the `milestone-error` broadcast instead.
215
+ */
216
+ writeReadyError?: { message: string; detail?: unknown };
217
+ bootSettledError?: { message: string; detail?: unknown };
192
218
  /**
193
219
  * Present when the engine boot REJECTED for this attach: the tab rejects `attachSyncClient` with this
194
- * message instead of hanging forever on the ack (ADR-0032 FIX 1). A later attach retries the boot.
220
+ * message instead of hanging forever on the ack (ADR-0032 FIX 1). A later attach retries the boot. This
221
+ * is a LOCAL-READ-CORE failure (the engine never reached `localReadReady`); a tail failure after
222
+ * `localReadReady` uses the stage-error fields above and does NOT reject the attach.
195
223
  */
196
224
  error?: { message: string; detail?: unknown };
197
225
  }
@@ -232,6 +260,9 @@ export type RpcOp =
232
260
  // Boot observability (ADR-0034): pull the worker engine's most recent completed boot report. Returns the
233
261
  // stored report (or null) regardless of when this tab attached, so a late tab reads a boot predating it.
234
262
  | "bootReport"
263
+ // Live-query diagnostics (ADR-0040 decision 5): pull the worker manager's per-entry snapshot (digests +
264
+ // counts/timings, NEVER SQL/params/rows). Returns [] before any subscription / when the manager is absent.
265
+ | "liveQueryDiagnostics"
235
266
  // Store backup (ADR-0035): the worker runs the live `exportStore` on its owned client; the dump crosses
236
267
  // back as a transferred `ArrayBuffer` ({@link ExportArtefactWire}), rebuilt into a `File` tab-side.
237
268
  | "exportStore"
@@ -299,6 +330,14 @@ export interface SubscribePayload {
299
330
  pkColumns?: string[];
300
331
  /** Lazy relations to activate before the query runs (ADR-0021), forwarded to the worker's `prepareQuery`. */
301
332
  use?: string[];
333
+ /**
334
+ * Per-subscription keep-alive hint (ms) for the worker's live-query manager (ADR-0040 decision 4): how long
335
+ * the shared registration should be retained after this subscription's last consumer leaves, so a matching
336
+ * resubscribe reuses it verbatim. ADDITIVE and backward-compatible both directions — an older tab omits it
337
+ * (the worker falls back to its `liveQueries.defaultKeepAliveMs`), and an older worker ignores it. Absent
338
+ * means "no hint".
339
+ */
340
+ keepAliveMs?: number;
302
341
  }
303
342
 
304
343
  /** worker → tab: the initial ordered snapshot for a subscription. `id` correlates the `subscribe` request. */
@@ -352,6 +391,15 @@ export interface LiveDiffPayload {
352
391
  export type BridgeEvent =
353
392
  | { kind: "status"; status: SyncRuntimeStatus }
354
393
  | { kind: "groupReady"; groupKey: string }
394
+ // Staged boot readiness (ADR-0041 stage 2): a one-shot milestone as the engine crosses a background boot
395
+ // stage (`writeReady` / `bootSettled`), broadcast to currently-attached ports. A tab attaching AFTER a
396
+ // stage fired never sees the broadcast — it folds the current milestone set off its `attach-ack` instead.
397
+ // One engine crosses each stage once; every port observes the same monotonic sequence (ack fold + event).
398
+ | { kind: "milestone"; stage: BootMilestone }
399
+ // The mirror failure edge: the background write/sync tail REJECTED a downstream stage (ADR-0041). Rejects
400
+ // the tab's matching `writeReady` / `bootSettled` promise so an awaiter fails loudly rather than hanging;
401
+ // `localReadReady` (and the resolved attach) are unaffected — the engine reached local-read readiness.
402
+ | { kind: "milestone-error"; stage: BootMilestone; error: { message: string; detail?: unknown } }
355
403
  | { kind: "conflict"; details: unknown }
356
404
  | { kind: "quarantine"; details: unknown }
357
405
  | { kind: "reject"; details: unknown }