@pgxsinkit/client 0.5.2 → 0.6.0-rc.2

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 (39) hide show
  1. package/dist/circuits/long-poll.d.ts +76 -0
  2. package/dist/circuits/long-poll.d.ts.map +1 -0
  3. package/dist/circuits/shape-group.d.ts +3 -3
  4. package/dist/circuits/stream-source.d.ts +76 -43
  5. package/dist/circuits/stream-source.d.ts.map +1 -1
  6. package/dist/circuits/subscription-client.d.ts +7 -7
  7. package/dist/circuits/sync-engine.d.ts +1 -1
  8. package/dist/event-lane.d.ts +2 -2
  9. package/dist/event-lane.d.ts.map +1 -1
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +228 -54
  13. package/dist/index.js.map +15 -13
  14. package/dist/local-tables.d.ts +511 -482
  15. package/dist/local-tables.d.ts.map +1 -1
  16. package/dist/retry-after.d.ts +9 -0
  17. package/dist/retry-after.d.ts.map +1 -0
  18. package/dist/schema.d.ts.map +1 -1
  19. package/dist/store-build.d.ts.map +1 -1
  20. package/dist/sync/metadata-tables.d.ts +2 -0
  21. package/dist/sync/metadata-tables.d.ts.map +1 -1
  22. package/dist/sync/types.d.ts.map +1 -1
  23. package/dist/worker/live-diff.d.ts.map +1 -1
  24. package/package.json +7 -8
  25. package/skills/core/SKILL.md +1 -1
  26. package/skills/operating/SKILL.md +6 -6
  27. package/src/circuits/long-poll.ts +174 -0
  28. package/src/circuits/shape-group.ts +3 -3
  29. package/src/circuits/stream-source.ts +226 -99
  30. package/src/circuits/subscription-client.ts +15 -15
  31. package/src/circuits/sync-engine.ts +1 -1
  32. package/src/event-lane.ts +3 -19
  33. package/src/index.ts +11 -3
  34. package/src/local-tables.ts +8 -5
  35. package/src/retry-after.ts +24 -0
  36. package/src/schema.ts +9 -4
  37. package/src/store-build.ts +4 -3
  38. package/src/sync/types.ts +2 -1
  39. package/src/worker/live-diff.ts +8 -5
@@ -20,14 +20,15 @@ export function assertStoreBuild(declared: StorageBuild, supplied: BuildIdentity
20
20
 
21
21
  /**
22
22
  * The typed build refusals (ADR-0063): the declared build is not the supplied one, or the data directory or
23
- * backup was made by another build or data format, or its marker is unreadable. Matched by `name`, which is
24
- * stable across bundle copies and the worker bridge. None of them is transient, so an open that failed with
25
- * one is never retried.
23
+ * backup was made by another build, data format or PostgreSQL major, or its marker is unreadable. Matched
24
+ * by `name`, which is stable across bundle copies and the worker bridge. None of them is transient, so an
25
+ * open that failed with one is never retried.
26
26
  */
27
27
  const STORE_BUILD_REFUSALS: ReadonlySet<string> = new Set([
28
28
  "StorageBuildMismatchError",
29
29
  "BuildMismatchError",
30
30
  "DataFormatMismatchError",
31
+ "PostgresVersionMismatchError",
31
32
  "BuildMarkerUnreadableError",
32
33
  ]);
33
34
 
package/src/sync/types.ts CHANGED
@@ -3,7 +3,8 @@
3
3
  //
4
4
  // What remains here is only what the NATIVE path uses. The shape-stream option and message types this
5
5
  // file used to re-export were `@electric-sql/client`'s, and nothing reads them any more: the transport
6
- // is `@durable-streams/client` and the change contract is `@pgxsinkit/contracts`' `SyncChange`.
6
+ // is pgxsinkit's own stream reader (`circuits/stream-source.ts`) and the change contract is
7
+ // `@pgxsinkit/contracts`' `SyncChange`.
7
8
 
8
9
  import type { SyncChange } from "@pgxsinkit/contracts";
9
10
 
@@ -65,15 +65,13 @@ export function computeLiveDiff(
65
65
  const order: string[] = [];
66
66
  const added: { key: string; row: Record<string, unknown> }[] = [];
67
67
  const changed: { key: string; row: Record<string, unknown> }[] = [];
68
- const nextKeys = new Set<string>();
69
68
  const nextMap = new Map<string, Record<string, unknown>>();
70
69
 
71
70
  for (const row of nextRows) {
72
71
  const key = rowKey(row, state.pkColumns);
73
72
  // A duplicate key within one result set (composite PK not actually unique, or a keyless collision):
74
73
  // keep the first, so `order`/diff stay a faithful set. Rare; the read projections are PK-unique.
75
- if (nextKeys.has(key)) continue;
76
- nextKeys.add(key);
74
+ if (nextMap.has(key)) continue;
77
75
  nextMap.set(key, row);
78
76
  order.push(key);
79
77
 
@@ -87,7 +85,7 @@ export function computeLiveDiff(
87
85
 
88
86
  const removed: string[] = [];
89
87
  for (const key of state.previous.keys()) {
90
- if (!nextKeys.has(key)) removed.push(key);
88
+ if (!nextMap.has(key)) removed.push(key);
91
89
  }
92
90
 
93
91
  state.previous = nextMap;
@@ -129,7 +127,12 @@ export class LiveRowsMaterializer<TRow extends Record<string, unknown> = Record<
129
127
  for (const { key, row } of diff.changed) this.byKey.set(key, row as TRow);
130
128
  // Rebuild strictly from the delivered order, reusing whatever object each key now maps to. Added/changed
131
129
  // keys already point at fresh objects (set above); every other key keeps its prior object (=== holds).
132
- this.rows = diff.order.map((key) => this.byKey.get(key)!).filter((row): row is TRow => row !== undefined);
130
+ const rows: TRow[] = [];
131
+ for (const key of diff.order) {
132
+ const row = this.byKey.get(key);
133
+ if (row !== undefined) rows.push(row);
134
+ }
135
+ this.rows = rows;
133
136
  return this.rows;
134
137
  }
135
138