@pgxsinkit/client 0.2.7 → 0.5.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.
Files changed (153) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE-APACHE-2.0 +202 -0
  3. package/NOTICE +81 -0
  4. package/README.md +11 -3
  5. package/dist/boot-report.d.ts +11 -8
  6. package/dist/boot-report.d.ts.map +1 -1
  7. package/dist/circuits/envelope-to-change.d.ts +39 -0
  8. package/dist/circuits/envelope-to-change.d.ts.map +1 -0
  9. package/dist/circuits/group-sync.d.ts +123 -0
  10. package/dist/circuits/group-sync.d.ts.map +1 -0
  11. package/dist/circuits/shape-group.d.ts +77 -0
  12. package/dist/circuits/shape-group.d.ts.map +1 -0
  13. package/dist/circuits/stream-inbox.d.ts +126 -0
  14. package/dist/circuits/stream-inbox.d.ts.map +1 -0
  15. package/dist/circuits/stream-source.d.ts +96 -0
  16. package/dist/circuits/stream-source.d.ts.map +1 -0
  17. package/dist/circuits/subscription-client.d.ts +143 -0
  18. package/dist/circuits/subscription-client.d.ts.map +1 -0
  19. package/dist/circuits/sync-engine.d.ts +131 -0
  20. package/dist/circuits/sync-engine.d.ts.map +1 -0
  21. package/dist/debug.d.ts +0 -10
  22. package/dist/debug.d.ts.map +1 -1
  23. package/dist/event-lane.d.ts +32 -1
  24. package/dist/event-lane.d.ts.map +1 -1
  25. package/dist/export-data.d.ts +3 -3
  26. package/dist/export-dump.d.ts +9 -9
  27. package/dist/export-dump.d.ts.map +1 -1
  28. package/dist/export-store.d.ts +13 -13
  29. package/dist/index.d.ts +237 -113
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +7037 -6665
  32. package/dist/index.js.map +46 -43
  33. package/dist/local-store.d.ts +1 -1
  34. package/dist/local-store.d.ts.map +1 -1
  35. package/dist/local-tables.d.ts +59 -1
  36. package/dist/local-tables.d.ts.map +1 -1
  37. package/dist/mutation.d.ts +2 -2
  38. package/dist/mutation.d.ts.map +1 -1
  39. package/dist/mutations-api.d.ts.map +1 -1
  40. package/dist/opfs-effects.d.ts +30 -2
  41. package/dist/opfs-effects.d.ts.map +1 -1
  42. package/dist/schema.d.ts +12 -1
  43. package/dist/schema.d.ts.map +1 -1
  44. package/dist/store-boot.d.ts +30 -2
  45. package/dist/store-boot.d.ts.map +1 -1
  46. package/dist/store-build.d.ts +19 -0
  47. package/dist/store-build.d.ts.map +1 -0
  48. package/dist/store-engine.d.ts +22 -0
  49. package/dist/store-engine.d.ts.map +1 -0
  50. package/dist/store-meta.d.ts +29 -3
  51. package/dist/store-meta.d.ts.map +1 -1
  52. package/dist/store-ownership-lock.d.ts +33 -0
  53. package/dist/store-ownership-lock.d.ts.map +1 -0
  54. package/dist/store-path.d.ts +40 -28
  55. package/dist/store-path.d.ts.map +1 -1
  56. package/dist/sync/apply.d.ts +17 -25
  57. package/dist/sync/apply.d.ts.map +1 -1
  58. package/dist/sync/copy.d.ts +84 -8
  59. package/dist/sync/copy.d.ts.map +1 -1
  60. package/dist/sync/drizzle-executor.d.ts +4 -4
  61. package/dist/sync/drizzle-executor.d.ts.map +1 -1
  62. package/dist/sync/fold.d.ts +40 -0
  63. package/dist/sync/fold.d.ts.map +1 -0
  64. package/dist/sync/metadata-tables.d.ts +25 -1
  65. package/dist/sync/metadata-tables.d.ts.map +1 -1
  66. package/dist/sync/subscription-state.d.ts +26 -7
  67. package/dist/sync/subscription-state.d.ts.map +1 -1
  68. package/dist/sync/types.d.ts +9 -129
  69. package/dist/sync/types.d.ts.map +1 -1
  70. package/dist/testing.d.ts +1 -1
  71. package/dist/testing.js +4 -3
  72. package/dist/testing.js.map +4 -4
  73. package/dist/worker/attach-sync-client.d.ts +27 -14
  74. package/dist/worker/attach-sync-client.d.ts.map +1 -1
  75. package/dist/worker/define-sync-worker.d.ts +52 -19
  76. package/dist/worker/define-sync-worker.d.ts.map +1 -1
  77. package/dist/worker/engine-control.d.ts +53 -0
  78. package/dist/worker/engine-control.d.ts.map +1 -1
  79. package/dist/worker/live-query-manager.d.ts +3 -3
  80. package/dist/worker/live-query-manager.d.ts.map +1 -1
  81. package/dist/worker/live-query-params-guard.d.ts +5 -5
  82. package/dist/worker/protocol.d.ts +26 -7
  83. package/dist/worker/protocol.d.ts.map +1 -1
  84. package/package.json +11 -9
  85. package/skills/core/SKILL.md +145 -63
  86. package/skills/operating/SKILL.md +221 -221
  87. package/skills/operating/references/postgres-builds.md +48 -0
  88. package/src/boot-report.ts +13 -12
  89. package/src/circuits/envelope-to-change.ts +211 -0
  90. package/src/circuits/group-sync.ts +1047 -0
  91. package/src/circuits/shape-group.ts +158 -0
  92. package/src/circuits/stream-inbox.ts +225 -0
  93. package/src/circuits/stream-source.ts +191 -0
  94. package/src/circuits/subscription-client.ts +353 -0
  95. package/src/circuits/sync-engine.ts +643 -0
  96. package/src/debug.ts +1 -85
  97. package/src/event-lane.ts +132 -14
  98. package/src/export-data.ts +4 -4
  99. package/src/export-dump.ts +24 -28
  100. package/src/export-store.ts +17 -17
  101. package/src/index.ts +797 -544
  102. package/src/lazy-guard.ts +1 -1
  103. package/src/live-rows-sql.ts +1 -1
  104. package/src/local-store.ts +2 -2
  105. package/src/local-tables.ts +76 -5
  106. package/src/mutation.ts +9 -8
  107. package/src/mutations-api.ts +2 -2
  108. package/src/opfs-effects.ts +74 -10
  109. package/src/schema.ts +126 -29
  110. package/src/store-boot.ts +71 -7
  111. package/src/store-build.ts +37 -0
  112. package/src/store-engine.ts +94 -0
  113. package/src/store-lifecycle.ts +1 -1
  114. package/src/store-meta.ts +155 -4
  115. package/src/store-ownership-lock.ts +109 -0
  116. package/src/store-path.ts +56 -40
  117. package/src/sync/apply.ts +104 -156
  118. package/src/sync/copy.ts +116 -21
  119. package/src/sync/drizzle-executor.ts +13 -14
  120. package/src/sync/fold.ts +94 -0
  121. package/src/sync/metadata-tables.ts +43 -2
  122. package/src/sync/subscription-state.ts +28 -10
  123. package/src/sync/types.ts +13 -141
  124. package/src/testing.ts +4 -4
  125. package/src/worker/attach-sync-client.ts +150 -57
  126. package/src/worker/define-sync-worker.ts +325 -87
  127. package/src/worker/engine-control.ts +89 -0
  128. package/src/worker/engine-router.ts +1 -1
  129. package/src/worker/live-query-fingerprint.ts +4 -4
  130. package/src/worker/live-query-manager.ts +12 -12
  131. package/src/worker/live-query-params-guard.ts +10 -10
  132. package/src/worker/protocol.ts +38 -7
  133. package/dist/read-stream-stall.d.ts +0 -54
  134. package/dist/read-stream-stall.d.ts.map +0 -1
  135. package/dist/shape-sync.d.ts +0 -207
  136. package/dist/shape-sync.d.ts.map +0 -1
  137. package/dist/sync/index.d.ts +0 -32
  138. package/dist/sync/index.d.ts.map +0 -1
  139. package/dist/sync/nudge.d.ts +0 -49
  140. package/dist/sync/nudge.d.ts.map +0 -1
  141. package/dist/sync/shape-inbox.d.ts +0 -215
  142. package/dist/sync/shape-inbox.d.ts.map +0 -1
  143. package/dist/sync/tags.d.ts +0 -142
  144. package/dist/sync/tags.d.ts.map +0 -1
  145. package/dist/sync-auth.d.ts +0 -53
  146. package/dist/sync-auth.d.ts.map +0 -1
  147. package/src/read-stream-stall.ts +0 -102
  148. package/src/shape-sync.ts +0 -533
  149. package/src/sync/index.ts +0 -1124
  150. package/src/sync/nudge.ts +0 -110
  151. package/src/sync/shape-inbox.ts +0 -566
  152. package/src/sync/tags.ts +0 -390
  153. package/src/sync-auth.ts +0 -117
@@ -1,7 +1,7 @@
1
- // Local store export (ADR-0035). Slice 1 ships the **store backup**: a full-fidelity, PGlite-restorable
1
+ // Local store export (ADR-0035). Slice 1 ships the **store backup**: a full-fidelity, pgwasm-restorable
2
2
  // tarball of the whole local store, taken LIVE (no engine suspension). It is a `CHECKPOINT` — run through
3
3
  // the engine's normal query serialisation so it orders behind in-flight engine work — followed by
4
- // PGlite's `dumpDataDir`. Because the dump is of the datadir itself, the Mutation journal and Overlay
4
+ // pgwasm's `dumpDataDir`. Because the dump is of the datadir itself, the Mutation journal and Overlay
5
5
  // travel INSIDE the artefact: a store backup is the lossless option, the only export an offline device
6
6
  // with unflushed writes can take (CONTEXT.md → Store backup).
7
7
  //
@@ -12,7 +12,7 @@
12
12
 
13
13
  import type { MutationDiagnostics } from "@pgxsinkit/contracts";
14
14
 
15
- import type { ClientPGlite } from "./index";
15
+ import type { PgwasmClient } from "./index";
16
16
 
17
17
  /**
18
18
  * Monotonic clock (ms) — `performance.now()` where available, else `Date.now()` (mirrors BootReport).
@@ -24,7 +24,7 @@ export const nowMs = (): number => (typeof performance !== "undefined" ? perform
24
24
  /** Options for {@link SyncClient.exportStore}. */
25
25
  export interface StoreExportOptions {
26
26
  /**
27
- * How to compress the tarball, forwarded to PGlite's `dumpDataDir`. `"auto"` (the default) gzips when a
27
+ * How to compress the tarball, forwarded to pgwasm's `dumpDataDir`. `"auto"` (the default) gzips when a
28
28
  * `CompressionStream` is available and falls back to an uncompressed tar otherwise; `"gzip"` forces
29
29
  * compression; `"none"` skips it. The report's `compression` records the compression that was actually
30
30
  * applied (which, under `"auto"`, is resolved at runtime).
@@ -61,7 +61,7 @@ export interface ExportReportCommon {
61
61
  }
62
62
 
63
63
  /**
64
- * A live **store backup** (ADR-0035): the whole datadir as a PGlite-restorable tarball, journal and overlay
64
+ * A live **store backup** (ADR-0035): the whole datadir as a pgwasm-restorable tarball, journal and overlay
65
65
  * included. `checkpoint`/`dump` are the only phases — a store backup is a `CHECKPOINT` + `dumpDataDir`, no
66
66
  * clone. Slice-1 shape, kept unchanged (the union is additive).
67
67
  */
@@ -88,7 +88,7 @@ export interface StoreBackupReport extends ExportReportCommon {
88
88
  * A **diagnostic dump** (ADR-0035, via the throwaway clone of the addendum): human-readable SQL of
89
89
  * EVERYTHING the store holds — synced tables, the `_overlay`/`_mutations` journal, the `pgxsinkit` metadata
90
90
  * schema, the read-model views, and the reconcile functions/triggers. It is a live datadir dump (checkpoint
91
- * + `dumpDataDir`) fed into a memory-backed throwaway PGlite via `loadDataDir`, against which `pg_dump` runs
91
+ * + `dumpDataDir`) fed into a memory-backed throwaway pgwasm via `loadDataDir`, against which `pg_dump` runs
92
92
  * — so the live engine is never touched (the addendum's whole point). Its phases add the clone boot and the
93
93
  * `pg_dump` walls to the shared checkpoint/dump pair.
94
94
  */
@@ -105,7 +105,7 @@ export interface DiagnosticDumpReport extends ExportReportCommon {
105
105
  dumpStartedAtMs: number;
106
106
  /** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
107
107
  dumpMs: number;
108
- /** Offset from export start when the throwaway clone's `PGlite.create({ loadDataDir })` began. */
108
+ /** Offset from export start when the throwaway clone's `pgwasm.create({ loadDataDir })` began. */
109
109
  cloneBootStartedAtMs: number;
110
110
  /** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
111
111
  cloneBootMs: number;
@@ -154,7 +154,7 @@ export interface DataExportReport extends ExportReportCommon {
154
154
  dumpStartedAtMs: number;
155
155
  /** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
156
156
  dumpMs: number;
157
- /** Offset from export start when the throwaway clone's `PGlite.create({ loadDataDir })` began. */
157
+ /** Offset from export start when the throwaway clone's `pgwasm.create({ loadDataDir })` began. */
158
158
  cloneBootStartedAtMs: number;
159
159
  /** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
160
160
  cloneBootMs: number;
@@ -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`, restorable by PGlite via `loadDataDir`. */
178
+ /** The store-backup tarball as a named `File`, restorable by pgwasm via `loadDataDir`. */
179
179
  file: File;
180
180
  /** The structured record of the export (ADR-0035). */
181
181
  report: StoreBackupReport;
@@ -183,7 +183,7 @@ export interface StoreExportResult {
183
183
 
184
184
  /**
185
185
  * Reduce a plain store PATH (ADR-0036) to a filesystem-safe token for the backup file name. Takes the
186
- * path's LAST segment (as PGlite's own `dumpDataDir` does when it names the inner db), then keeps only
186
+ * path's LAST segment (as pgwasm's own `dumpDataDir` does when it names the inner db), then keeps only
187
187
  * `[A-Za-z0-9._-]`. No scheme stripping — the store path is a plain name, never a storage URL. Falls back
188
188
  * to a fixed token for an empty path so the name is always well formed.
189
189
  */
@@ -209,16 +209,16 @@ export const compactTimestamp = (): string => new Date().toISOString().replace(/
209
209
  * (the caller's export-start monotonic anchor) so the timings compose into either report.
210
210
  *
211
211
  * The `CHECKPOINT` is a utility statement — Drizzle has no builder for it, so a raw `exec` is the justified
212
- * tier-③ form here. Running it via `pglite.exec` serialises it behind any in-flight engine work on PGlite's
212
+ * tier-③ form here. Running it via `pglite.exec` serialises it behind any in-flight engine work on pgwasm's
213
213
  * single connection, flushing dirty buffers to the datadir the dump then reads — so the tarball reflects
214
214
  * committed state, not a torn mid-write datadir.
215
215
  */
216
216
  export async function performDatadirDump(
217
- pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">,
217
+ pglite: Pick<PgwasmClient, "exec" | "dumpDataDir">,
218
218
  compression: "auto" | "gzip" | "none",
219
219
  startPerf: number,
220
220
  ): Promise<{
221
- dumped: Awaited<ReturnType<ClientPGlite["dumpDataDir"]>>;
221
+ dumped: Awaited<ReturnType<PgwasmClient["dumpDataDir"]>>;
222
222
  checkpointStartedAtMs: number;
223
223
  checkpointMs: number;
224
224
  dumpStartedAtMs: number;
@@ -240,12 +240,12 @@ export async function performDatadirDump(
240
240
  /** The dependencies {@link performStoreExport} needs from the owning client — narrow, so it is unit-testable. */
241
241
  export interface StoreExportDeps {
242
242
  /** The live store to checkpoint and dump. */
243
- pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">;
243
+ pglite: Pick<PgwasmClient, "exec" | "dumpDataDir">;
244
244
  /** The Mutation diagnostics seam (`client.diagnostics().mutation` / `readMutationStats`). */
245
245
  readMutationStats: () => Promise<MutationDiagnostics>;
246
246
  /**
247
247
  * The store's configured plain store PATH (ADR-0036) — reduced to the `storeId` in the default backup
248
- * file name (`deriveStoreId`). The resolved PGlite dataDir URL is deliberately NOT used here: it is
248
+ * file name (`deriveStoreId`). The resolved pgwasm dataDir URL is deliberately NOT used here: it is
249
249
  * internal plumbing and must not leak into an artefact name as something to imitate.
250
250
  */
251
251
  storePath?: string;
@@ -273,7 +273,7 @@ export async function performStoreExport(
273
273
  startPerf,
274
274
  );
275
275
 
276
- // PGlite names its dump `<db>.tar.gz` (type `application/x-gzip`) when it compressed, `<db>.tar`
276
+ // pgwasm names its dump `<db>.tar.gz` (type `application/x-gzip`) when it compressed, `<db>.tar`
277
277
  // (`application/x-tar`) otherwise — so the RESULT, not the requested option, tells us what `"auto"`
278
278
  // resolved to. Detect from whichever of name/type the runtime populated (its `File` is a polyfill in
279
279
  // non-browser hosts, so trust both).
@@ -284,7 +284,7 @@ export async function performStoreExport(
284
284
  const mimeType = gzipped ? "application/x-gzip" : "application/x-tar";
285
285
  const storeId = deriveStoreId(deps.storePath);
286
286
  const fileName = options.fileName ?? `${storeId}-${compactTimestamp()}${extension}`;
287
- // Build the artefact `File` from the raw bytes, NOT by re-wrapping `dumped`: PGlite's dump is a File
287
+ // Build the artefact `File` from the raw bytes, NOT by re-wrapping `dumped`: pgwasm's dump is a File
288
288
  // polyfill in non-browser hosts, and `new File([polyfillFile], name)` keeps the polyfill's own name
289
289
  // rather than the one we pass. Extracting the bytes first guarantees the store-scoped name sticks.
290
290
  const bytes = new Uint8Array(await dumped.arrayBuffer());