@pgxsinkit/client 0.2.6 → 0.3.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.
- package/README.md +2 -1
- package/dist/boot-report.d.ts +5 -2
- package/dist/boot-report.d.ts.map +1 -1
- package/dist/circuits/envelope-to-change.d.ts +35 -0
- package/dist/circuits/envelope-to-change.d.ts.map +1 -0
- package/dist/circuits/group-sync.d.ts +123 -0
- package/dist/circuits/group-sync.d.ts.map +1 -0
- package/dist/circuits/shape-group.d.ts +77 -0
- package/dist/circuits/shape-group.d.ts.map +1 -0
- package/dist/circuits/stream-inbox.d.ts +126 -0
- package/dist/circuits/stream-inbox.d.ts.map +1 -0
- package/dist/circuits/stream-source.d.ts +90 -0
- package/dist/circuits/stream-source.d.ts.map +1 -0
- package/dist/circuits/subscription-client.d.ts +143 -0
- package/dist/circuits/subscription-client.d.ts.map +1 -0
- package/dist/circuits/sync-engine.d.ts +131 -0
- package/dist/circuits/sync-engine.d.ts.map +1 -0
- package/dist/debug.d.ts +0 -10
- package/dist/debug.d.ts.map +1 -1
- package/dist/export-dump.d.ts.map +1 -1
- package/dist/index.d.ts +47 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6258 -6443
- package/dist/index.js.map +26 -26
- package/dist/local-tables.d.ts +1 -1
- package/dist/local-tables.d.ts.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/sync/apply.d.ts +13 -21
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/copy.d.ts +8 -8
- package/dist/sync/fold.d.ts +40 -0
- package/dist/sync/fold.d.ts.map +1 -0
- package/dist/sync/metadata-tables.d.ts +25 -1
- package/dist/sync/metadata-tables.d.ts.map +1 -1
- package/dist/sync/subscription-state.d.ts +21 -2
- package/dist/sync/subscription-state.d.ts.map +1 -1
- package/dist/sync/types.d.ts +9 -129
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/testing.js +3 -3
- package/dist/testing.js.map +2 -2
- package/dist/worker/attach-sync-client.d.ts +3 -1
- package/dist/worker/attach-sync-client.d.ts.map +1 -1
- package/dist/worker/define-sync-worker.d.ts +17 -1
- package/dist/worker/define-sync-worker.d.ts.map +1 -1
- package/dist/worker/engine-control.d.ts +53 -0
- package/dist/worker/engine-control.d.ts.map +1 -1
- package/package.json +6 -7
- package/skills/core/SKILL.md +72 -55
- package/skills/operating/SKILL.md +120 -120
- package/src/boot-report.ts +4 -3
- package/src/circuits/envelope-to-change.ts +102 -0
- package/src/circuits/group-sync.ts +1047 -0
- package/src/circuits/shape-group.ts +158 -0
- package/src/circuits/stream-inbox.ts +225 -0
- package/src/circuits/stream-source.ts +165 -0
- package/src/circuits/subscription-client.ts +353 -0
- package/src/circuits/sync-engine.ts +641 -0
- package/src/debug.ts +1 -85
- package/src/export-dump.ts +3 -2
- package/src/index.ts +290 -273
- package/src/lazy-guard.ts +1 -1
- package/src/local-tables.ts +9 -2
- package/src/schema.ts +2 -11
- package/src/sync/apply.ts +72 -110
- package/src/sync/copy.ts +15 -15
- package/src/sync/fold.ts +94 -0
- package/src/sync/metadata-tables.ts +42 -1
- package/src/sync/subscription-state.ts +21 -3
- package/src/sync/types.ts +13 -141
- package/src/testing.ts +2 -2
- package/src/worker/attach-sync-client.ts +8 -1
- package/src/worker/define-sync-worker.ts +122 -13
- package/src/worker/engine-control.ts +89 -0
- package/dist/read-stream-stall.d.ts +0 -54
- package/dist/read-stream-stall.d.ts.map +0 -1
- package/dist/shape-sync.d.ts +0 -207
- package/dist/shape-sync.d.ts.map +0 -1
- package/dist/sync/index.d.ts +0 -32
- package/dist/sync/index.d.ts.map +0 -1
- package/dist/sync/nudge.d.ts +0 -49
- package/dist/sync/nudge.d.ts.map +0 -1
- package/dist/sync/shape-inbox.d.ts +0 -215
- package/dist/sync/shape-inbox.d.ts.map +0 -1
- package/dist/sync/tags.d.ts +0 -142
- package/dist/sync/tags.d.ts.map +0 -1
- package/dist/sync-auth.d.ts +0 -53
- package/dist/sync-auth.d.ts.map +0 -1
- package/src/read-stream-stall.ts +0 -102
- package/src/shape-sync.ts +0 -533
- package/src/sync/index.ts +0 -1124
- package/src/sync/nudge.ts +0 -110
- package/src/sync/shape-inbox.ts +0 -566
- package/src/sync/tags.ts +0 -390
- package/src/sync-auth.ts +0 -117
package/dist/shape-sync.d.ts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import type { ExternalHeadersRecord } from "@electric-sql/client";
|
|
2
|
-
import type { PGliteInterface } from "@electric-sql/pglite";
|
|
3
|
-
import { type Retention, type SubscriptionTiming, type SyncConfigInput, type SyncTableRegistry } from "@pgxsinkit/contracts";
|
|
4
|
-
import type { BootStampCollector, GroupBootStamp } from "./boot-report";
|
|
5
|
-
import type { SyncNamespaceObj } from "./sync";
|
|
6
|
-
export interface ShapeSyncSpec {
|
|
7
|
-
electricUrl: string;
|
|
8
|
-
tableName: string;
|
|
9
|
-
schema?: string;
|
|
10
|
-
shapeKey: string;
|
|
11
|
-
primaryKey: string[];
|
|
12
|
-
electricTable?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Consistency group (ADR-0009 decision 2). Specs sharing a group sync on one `MultiShapeStream`
|
|
15
|
-
* and commit atomically. Absent → the table is its own singleton group keyed by its `shapeKey`.
|
|
16
|
-
*/
|
|
17
|
-
consistencyGroup?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Subscription timing (ADR-0021). Absent → `eager`. A `lazy` spec's group is held out of the eager
|
|
20
|
-
* boot set and started on demand via {@link StartConfiguredSyncResult.ensureGroupStarted}. A group's
|
|
21
|
-
* members all agree (registry-validated), so the group's timing is any member's.
|
|
22
|
-
*/
|
|
23
|
-
subscription?: SubscriptionTiming;
|
|
24
|
-
/**
|
|
25
|
-
* Retention (ADR-0021). Absent → `persistent`. Only a `persistent` `lazy` group is promoted to the
|
|
26
|
-
* eager set on activation (its activation is permanent across boots); an `ephemeral` group's activation
|
|
27
|
-
* is session-scoped by construction, so it is never promoted/persisted.
|
|
28
|
-
*/
|
|
29
|
-
retention?: Retention;
|
|
30
|
-
}
|
|
31
|
-
export interface ConfiguredShapeSyncSpec extends ShapeSyncSpec {
|
|
32
|
-
key: string;
|
|
33
|
-
}
|
|
34
|
-
export interface StartConfiguredSyncOptions {
|
|
35
|
-
syncConfig: SyncConfigInput;
|
|
36
|
-
/**
|
|
37
|
-
* The sync registry (ADR-0029 D1): the engine's sole per-table spec source. Each shape's `tableKey`
|
|
38
|
-
* (its `syncConfig` table key) resolves against it for the local table, PKs, apply strategy, and
|
|
39
|
-
* column types — no table-scoped fact is threaded from `syncConfig` into the engine.
|
|
40
|
-
*/
|
|
41
|
-
registry: SyncTableRegistry;
|
|
42
|
-
/**
|
|
43
|
-
* Shape request headers shared by every member shape. Values may be async functions resolved per
|
|
44
|
-
* request (ADR-0013) — the read-path `Authorization` token is one such function.
|
|
45
|
-
*/
|
|
46
|
-
shapeHeaders?: ExternalHeadersRecord;
|
|
47
|
-
onInitialSync?: () => void;
|
|
48
|
-
onTableInitialSync?: (tableKey: string) => void;
|
|
49
|
-
/**
|
|
50
|
-
* Fresh-store prefetch overlap (ADR-0032 S4). When present, every EAGER group starts its shape streams
|
|
51
|
-
* and buffers their catch-up into the memory inbox immediately, gating all commits until this promise
|
|
52
|
-
* resolves — so the network catch-up overlaps the local boot phases (schema/journal/reconcile) instead
|
|
53
|
-
* of running after them. Set ONLY by `createSyncClient` on a provably-fresh store (its `freshStore`
|
|
54
|
-
* hint); absent → the sequential path. Passed straight through to the engine's `syncShapesToTables`.
|
|
55
|
-
*/
|
|
56
|
-
dbReady?: Promise<void>;
|
|
57
|
-
/** Commit-level error surfacing (ADR-0009 decision 5): a sync commit exhausted its retries. */
|
|
58
|
-
onSyncError?: (error: Error) => void;
|
|
59
|
-
/**
|
|
60
|
-
* Notified when a shape hits an auth error (401/403) and the read path is retrying for a fresh
|
|
61
|
-
* token (ADR-0013 Phase 3). The runtime surfaces a distinct `auth-needed` status from this.
|
|
62
|
-
*/
|
|
63
|
-
onAuthError?: () => void;
|
|
64
|
-
/**
|
|
65
|
-
* Notified when a shape hits a NON-auth stream error (#4): a transient 5xx/429/network (retried) or
|
|
66
|
-
* a structural 4xx (stops the stream). The runtime surfaces a `degraded` status from this so it
|
|
67
|
-
* never silently believes the read path is live while it has actually stalled.
|
|
68
|
-
*/
|
|
69
|
-
onReadStreamError?: (error: Error) => void;
|
|
70
|
-
/**
|
|
71
|
-
* Notified when a shape's fetch ATTEMPT failed and Electric is retrying it inside its own backoff
|
|
72
|
-
* wrapper (board ADR-0010): a rejected request (the offline case — no HTTP status at all), a 5xx, or a
|
|
73
|
-
* 429. The complement of {@link onReadStreamError}, which only ever fires for an error that ESCAPED that
|
|
74
|
-
* wrapper (any other 4xx) — which a network outage never does, since Electric retries it forever. Fires
|
|
75
|
-
* per attempt for as long as the outage lasts, so the runtime owns the transition; a deliberate abort
|
|
76
|
-
* (teardown, hidden tab, nudge refresh) is not a failure and is filtered out. See `read-stream-stall.ts`.
|
|
77
|
-
*/
|
|
78
|
-
onReadStreamStalled?: () => void;
|
|
79
|
-
/**
|
|
80
|
-
* Notified when a shape successfully delivers a batch — i.e. a fetch just succeeded (ADR-0013
|
|
81
|
-
* Phase 3). The runtime uses this to clear an `auth-needed`/`degraded` status once sync resumes.
|
|
82
|
-
*/
|
|
83
|
-
onSyncActivity?: () => void;
|
|
84
|
-
/**
|
|
85
|
-
* Consistency-group keys of `lazy` groups that were activated on a previous boot and persisted their
|
|
86
|
-
* activation flag (ADR-0021 §2 — `lazy + persistent` promotion). These join the eager boot set as if
|
|
87
|
-
* they were declared `eager`, so a once-activated durable lazy group resumes without re-evaluation.
|
|
88
|
-
* Computed by the caller from the local meta table (the sync engine does no DB read of its own).
|
|
89
|
-
*/
|
|
90
|
-
promotedGroups?: ReadonlySet<string>;
|
|
91
|
-
/**
|
|
92
|
-
* Invoked when a `persistent` `lazy` group is activated on demand (not promoted at boot), so the
|
|
93
|
-
* caller can persist its activation flag for the next boot (ADR-0021 §2). Never fired for an
|
|
94
|
-
* `ephemeral` group (its activation is session-scoped and leaves no durable trace).
|
|
95
|
-
*/
|
|
96
|
-
onLazyActivated?: (groupKey: string) => void;
|
|
97
|
-
/**
|
|
98
|
-
* Invoked exactly once per consistency group the moment it becomes up-to-date (ADR-0032 decision 6 —
|
|
99
|
-
* per-group readiness). Fires for eager, promoted, and on-demand `lazy` groups alike, so a client can
|
|
100
|
-
* surface progressive per-group paint (and the worker bridge can fan a `groupReady` event to tabs)
|
|
101
|
-
* without the all-eager-groups `onInitialSync` gate. The matching promise is {@link StartConfiguredSyncResult.groupReady}.
|
|
102
|
-
*/
|
|
103
|
-
onGroupReady?: (groupKey: string) => void;
|
|
104
|
-
/**
|
|
105
|
-
* Boot observability (ADR-0034): opens a per-group accumulator (rows/requests/fetch/apply wall) for each
|
|
106
|
-
* EAGER + PROMOTED boot group, stamped by the engine as the group's stream chain delivers and applies. A
|
|
107
|
-
* lazy on-demand start gets none — so a lazily-activated-later group never enters (or mutates) the report.
|
|
108
|
-
* Absent → no boot instrumentation.
|
|
109
|
-
*/
|
|
110
|
-
bootCollector?: BootStampCollector;
|
|
111
|
-
}
|
|
112
|
-
type SyncEnginePGlite = PGliteInterface & {
|
|
113
|
-
electric: SyncNamespaceObj;
|
|
114
|
-
};
|
|
115
|
-
export interface ShapeSyncResult {
|
|
116
|
-
unsubscribe: () => void;
|
|
117
|
-
readonly isUpToDate: boolean;
|
|
118
|
-
}
|
|
119
|
-
export interface StartConfiguredSyncResult {
|
|
120
|
-
unsubscribe: () => void;
|
|
121
|
-
tables: Record<string, ShapeSyncResult>;
|
|
122
|
-
/**
|
|
123
|
-
* Start a `lazy` consistency group (ADR-0021) held out of the eager boot set. Idempotent and
|
|
124
|
-
* single-flight: concurrent calls share one start; a started, unknown, or eager group resolves
|
|
125
|
-
* immediately. Resolves once the group's initial sync completes — the seam the live-query layer
|
|
126
|
-
* calls on first reference to a lazy table. After it resolves, the group's member `tables` entries
|
|
127
|
-
* report `isUpToDate` live.
|
|
128
|
-
*/
|
|
129
|
-
ensureGroupStarted: (groupKey: string) => Promise<void>;
|
|
130
|
-
/**
|
|
131
|
-
* Stop a group's stream and return it to dormant (ADR-0021 §2): tear down its live subscription and
|
|
132
|
-
* clear the runtime so {@link isTableStarted} reports false again and a later {@link ensureGroupStarted}
|
|
133
|
-
* re-subscribes from scratch — the inverse of an on-demand activation. Used by the client's `desync`
|
|
134
|
-
* to halt a lazy group before truncating its read cache. A no-op for an unknown or never-started group.
|
|
135
|
-
* The temp cluster of an `ephemeral` group is NOT dropped here (that is the deferred idle-eviction); the
|
|
136
|
-
* cluster simply stops being fed.
|
|
137
|
-
*/
|
|
138
|
-
stopGroup: (groupKey: string) => void;
|
|
139
|
-
/** The consistency-group key a table belongs to — maps a queried table to its {@link ensureGroupStarted}. */
|
|
140
|
-
groupKeyForTable: (tableKey: string) => string | undefined;
|
|
141
|
-
/**
|
|
142
|
-
* Whether a table's consistency group has started and completed its initial sync, so its reads are
|
|
143
|
-
* hydrated (ADR-0021). False for a `lazy` group still held out of the boot set. Drives the read-path
|
|
144
|
-
* tripwire — a lazy relation read while this is false would return empty/stale rows.
|
|
145
|
-
*/
|
|
146
|
-
isTableStarted: (tableKey: string) => boolean;
|
|
147
|
-
/**
|
|
148
|
-
* A promise that resolves the moment the given consistency group is up-to-date (ADR-0032 decision 6).
|
|
149
|
-
* Resolves immediately for an already-ready group; stays pending for a `lazy` group until it is
|
|
150
|
-
* activated (via {@link ensureGroupStarted}) and catches up. An unknown group resolves immediately
|
|
151
|
-
* (nothing to await). Per-group readiness the client re-exposes as `client.groupReady(table)`.
|
|
152
|
-
*/
|
|
153
|
-
groupReady: (groupKey: string) => Promise<void>;
|
|
154
|
-
/** Whether the given consistency group has completed its initial sync (synchronous peek at {@link groupReady}). */
|
|
155
|
-
isGroupReady: (groupKey: string) => boolean;
|
|
156
|
-
/** Every consistency-group key this config declares — the domain of {@link groupReady}/{@link isGroupReady}. */
|
|
157
|
-
groupKeys: () => string[];
|
|
158
|
-
}
|
|
159
|
-
export declare function buildShapeUrl(electricUrl: string, table: string): string;
|
|
160
|
-
export declare function buildShapeConfig(input: ShapeSyncSpec): {
|
|
161
|
-
shape: {
|
|
162
|
-
url: string;
|
|
163
|
-
};
|
|
164
|
-
table: string;
|
|
165
|
-
schema?: string;
|
|
166
|
-
primaryKey: string[];
|
|
167
|
-
shapeKey: string;
|
|
168
|
-
};
|
|
169
|
-
export declare function buildConfiguredShapeSpecs(input: SyncConfigInput): ConfiguredShapeSyncSpec[];
|
|
170
|
-
export declare function startConfiguredSync(pg: SyncEnginePGlite, input: StartConfiguredSyncOptions): Promise<StartConfiguredSyncResult>;
|
|
171
|
-
interface StartGroupSyncOptions {
|
|
172
|
-
groupKey: string;
|
|
173
|
-
specs: ConfiguredShapeSyncSpec[];
|
|
174
|
-
registry: SyncTableRegistry;
|
|
175
|
-
/**
|
|
176
|
-
* ADR-0042: the group's retention is `ephemeral`, so its sync bookkeeping (cursor + tags) is session-
|
|
177
|
-
* scoped — the engine stores it in `pg_temp` relations that die with the engine. Forwarded straight to
|
|
178
|
-
* the engine's `syncShapesToTables`; absent/`false` for a persistent group (byte-identical storage).
|
|
179
|
-
*/
|
|
180
|
-
sessionScoped?: boolean;
|
|
181
|
-
headers?: ExternalHeadersRecord;
|
|
182
|
-
/** Fresh-store prefetch overlap gate (ADR-0032 S4) — forwarded to the engine's `syncShapesToTables`. */
|
|
183
|
-
dbReady?: Promise<void>;
|
|
184
|
-
/** Boot observability (ADR-0034): the group's accumulator, stamped by the engine on delivery/apply. */
|
|
185
|
-
bootStamp?: GroupBootStamp;
|
|
186
|
-
onGroupInitialSync?: () => void;
|
|
187
|
-
onSyncError?: (error: Error) => void;
|
|
188
|
-
onAuthError?: () => void;
|
|
189
|
-
onReadStreamError?: (error: Error) => void;
|
|
190
|
-
/** A failed fetch ATTEMPT inside Electric's backoff loop; see {@link StartConfiguredSyncOptions.onReadStreamStalled}. */
|
|
191
|
-
onReadStreamStalled?: () => void;
|
|
192
|
-
onSyncActivity?: () => void;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Sync one consistency group on a single `MultiShapeStream` (ADR-0009 decision 2). All member
|
|
196
|
-
* shapes share the group's subscription key and commit atomically at a shared LSN frontier; each
|
|
197
|
-
* shape keeps its own apply strategy and column types (resolved per-shape inside the engine).
|
|
198
|
-
*/
|
|
199
|
-
export declare function startGroupSync(pg: SyncEnginePGlite, input: StartGroupSyncOptions): Promise<import("./sync").SyncShapesToTablesResult>;
|
|
200
|
-
/**
|
|
201
|
-
* The subscription key for a spec's consistency group (ADR-0009 decision 2): the explicit
|
|
202
|
-
* `consistencyGroup` when set, else the table's own `shapeKey` (a singleton group). One persisted
|
|
203
|
-
* subscription-state row exists per group key, so subscription reset enumerates these.
|
|
204
|
-
*/
|
|
205
|
-
export declare function groupSubscriptionKey(spec: Pick<ConfiguredShapeSyncSpec, "consistencyGroup" | "shapeKey">): string;
|
|
206
|
-
export {};
|
|
207
|
-
//# sourceMappingURL=shape-sync.d.ts.map
|
package/dist/shape-sync.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shape-sync.d.ts","sourceRoot":"","sources":["../src/shape-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EACL,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EAEvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG/C,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MA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I3F;AAgBD,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,gBAAgB,EACpB,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,yBAAyB,CAAC,CAgMpC;AAED,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAChC,wGAAwG;IACxG,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,uGAAuG;IACvG,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC3C,yHAAyH;IACzH,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,qBAAqB,sDAmDtF;AAgCD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,kBAAkB,GAAG,UAAU,CAAC,GAAG,MAAM,CAEjH"}
|
package/dist/sync/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { PGliteInterface } from "@electric-sql/pglite";
|
|
2
|
-
import { type ElectricSyncOptions, type SyncShapesToTablesOptions, type SyncShapesToTablesResult, type SyncShapeToTableOptions, type SyncShapeToTableResult } from "./types";
|
|
3
|
-
export * from "./types";
|
|
4
|
-
/**
|
|
5
|
-
* Construct the pgxsinkit sync engine over an ALREADY-created PGlite instance (ADR-0032 S1). The engine
|
|
6
|
-
* is a plain module — not a create-time PGlite extension — so it demands only the minimal surface it
|
|
7
|
-
* actually uses: a {@link PGliteInterface} (it runs its metadata DDL + apply commits through `pg.transaction`
|
|
8
|
-
* / `pg.query` / `pg.exec`; it does NOT touch the `live` extension). It returns the `namespace` object (the
|
|
9
|
-
* local-bookkeeping + shape-sync entry points the client attaches as `pg.electric`) plus an explicit
|
|
10
|
-
* `close()` — the teardown the former extension's `close` hook ran when PGlite closed, now invoked
|
|
11
|
-
* explicitly by the owner at the same moment (see `createSyncClient`'s `stop`/`destroy`).
|
|
12
|
-
*/
|
|
13
|
-
export declare function createSyncEngine(pg: PGliteInterface, options?: ElectricSyncOptions): Promise<{
|
|
14
|
-
namespace: {
|
|
15
|
-
initMetadataTables: () => Promise<void>;
|
|
16
|
-
syncShapesToTables: ({ key, registry, shapes, sessionScoped, initialInsertMethod, onInitialSync, onError, onSyncError, onSyncActivity, dbReady, bootStamp, maxCommitRetries, commitRetryDelayMs, }: SyncShapesToTablesOptions) => Promise<SyncShapesToTablesResult>;
|
|
17
|
-
syncShapeToTable: (options: SyncShapeToTableOptions) => Promise<SyncShapeToTableResult>;
|
|
18
|
-
deleteSubscription: (key: string) => Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
close: () => Promise<void>;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* The pgxsinkit sync engine handle: the {@link SyncNamespaceObj} the client attaches as `pg.electric`,
|
|
24
|
-
* plus the explicit `close()` teardown. Derived from {@link createSyncEngine}'s real return so the type
|
|
25
|
-
* follows the object.
|
|
26
|
-
*/
|
|
27
|
-
export type SyncEngine = Awaited<ReturnType<typeof createSyncEngine>>;
|
|
28
|
-
export type SyncNamespaceObj = SyncEngine["namespace"];
|
|
29
|
-
export type PGliteWithSync = PGliteInterface & {
|
|
30
|
-
sync: SyncNamespaceObj;
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/sync/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA2C5D,OAAO,EAEL,KAAK,mBAAmB,EAIxB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC5B,MAAM,SAAS,CAAC;AAEjB,cAAc,SAAS,CAAC;AAgDxB;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,mBAAmB;;kCA+BxD,OAAO,CAAC,IAAI,CAAC;4MA2BzC,yBAAyB,KAAG,OAAO,CAAC,wBAAwB,CAAC;oCAi2BvB,uBAAuB,KAAG,OAAO,CAAC,sBAAsB,CAAC;kCAsC3D,MAAM;;;GAgC9C;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC;AACtE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;AAEvD,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C,IAAI,EAAE,gBAAgB,CAAC;CACxB,CAAC"}
|
package/dist/sync/nudge.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* How long a hold must PERSIST before the first nudge round fires. A cross-shape transaction's halves
|
|
3
|
-
* arrive milliseconds apart even on a healthy stack, so every grouped commit passes through a
|
|
4
|
-
* transient "held" instant — nudging on it immediately ABORTS the sibling's long-poll that was about
|
|
5
|
-
* to deliver the other half, turning a millisecond hold into an abort/refetch disruption loop
|
|
6
|
-
* (regression caught by the sync-e2e integration lane on local Electric). A hold that outlives this
|
|
7
|
-
* grace is the real thing: a quiet sibling parked in a multi-second poll. On Electric Cloud this adds
|
|
8
|
-
* ~1s to a path that saves ~40s; on local stacks it means the nudge simply never fires.
|
|
9
|
-
*/
|
|
10
|
-
export declare const NUDGE_HOLD_GRACE_MS = 1000;
|
|
11
|
-
/**
|
|
12
|
-
* Max nudge rounds before a dead / genuinely-still-polling sibling degrades back to the old behavior
|
|
13
|
-
* (wait out its live long-poll) instead of being nudged forever — so a stuck sibling never becomes a
|
|
14
|
-
* refresh storm.
|
|
15
|
-
*/
|
|
16
|
-
export declare const NUDGE_MAX_ROUNDS = 3;
|
|
17
|
-
/**
|
|
18
|
-
* Polling step while waiting for a nudge round's forced catch-ups to advance the group frontier. The
|
|
19
|
-
* `forceDisconnectAndRefresh()` promise settles BEFORE the refreshed catch-up response lands (field
|
|
20
|
-
* measurement: round 2 fired ~750ms into round 1's still-in-flight requests when the wait keyed off that
|
|
21
|
-
* promise alone), so the watchdog instead polls the frontier at this step, up to
|
|
22
|
-
* {@link NUDGE_ROUND_WAIT_MS} per round, breaking out the moment the target is reached.
|
|
23
|
-
*/
|
|
24
|
-
export declare const NUDGE_ROUND_GRACE_MS = 100;
|
|
25
|
-
/**
|
|
26
|
-
* Max wait per nudge round for the forced catch-ups to return and advance the frontier. A nudged
|
|
27
|
-
* catch-up measures ~0.9–1.4s through a warm deployed edge proxy but >3.5s against a cold one — and
|
|
28
|
-
* a next round's refresh ABORTS a still-in-flight round (the abort-and-reconnect is the mechanism),
|
|
29
|
-
* so an early re-nudge throws away an almost-done response. The wait therefore covers the cold-edge
|
|
30
|
-
* tail; worst case to exhaustion stays NUDGE_MAX_ROUNDS × this ≈ 12s, still far under a ~41s hold.
|
|
31
|
-
*/
|
|
32
|
-
export declare const NUDGE_ROUND_WAIT_MS = 4000;
|
|
33
|
-
/**
|
|
34
|
-
* Wrap a `fetchClient` so a pending one-shot nudge token defeats the CDN on the nudged sibling's catch-up.
|
|
35
|
-
*
|
|
36
|
-
* A nudge's `forceDisconnectAndRefresh` issues a NON-live catch-up (Electric sets `canLongPoll: false`),
|
|
37
|
-
* which is CDN-cacheable — a HIT would return the SAME stale watermark that made the sibling lag, defeating
|
|
38
|
-
* the nudge. So the watchdog drops a per-shape token into `nudgeBusters` just before it nudges; this wrapper
|
|
39
|
-
* consumes that token on the sibling's next NON-live request, appending `cache-buster=<token>` to force a
|
|
40
|
-
* CDN miss. It is one-shot (the token is deleted on use) and skips LIVE (`live=true`) long-polls — the token
|
|
41
|
-
* is meant for the catch-up that follows the aborted poll, not the poll itself, which is left to be retained
|
|
42
|
-
* for that catch-up. An already-present `cache-buster` param is overwritten. When no token is pending this is
|
|
43
|
-
* a straight passthrough, so the off-path pays only this closure.
|
|
44
|
-
*
|
|
45
|
-
* Exported for unit testing; composed in the engine as the OUTER wrapper around `instrumentShapeFetch`, so
|
|
46
|
-
* the buster stamps the URL BEFORE instrumentation logs it (the debug rail then shows `BUSTED`).
|
|
47
|
-
*/
|
|
48
|
-
export declare function withNudgeBuster(fetchClient: typeof fetch, nudgeBusters: Map<string, string>, shapeName: string): typeof fetch;
|
|
49
|
-
//# sourceMappingURL=nudge.d.ts.map
|
package/dist/sync/nudge.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nudge.d.ts","sourceRoot":"","sources":["../../src/sync/nudge.ts"],"names":[],"mappings":"AAeA;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AAYzC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,OAAO,KAAK,EACzB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,SAAS,EAAE,MAAM,GAChB,OAAO,KAAK,CA6Bd"}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import type { ChangeMessage, MovePattern, Row } from "@electric-sql/client";
|
|
2
|
-
import type { InsertChangeMessage, Lsn } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* The Shape inbox (ADR-0014 / ISS-06): the pure, in-memory staging buffer between a shape's
|
|
5
|
-
* Electric subscription and the Sync applier. It buffers each shape's change messages keyed by
|
|
6
|
-
* LSN, tracks each shape's complete-LSN frontier, and drains everything up to a target LSN for the
|
|
7
|
-
* applier to write. No database I/O lives here — that is exactly what makes it (and the ADR-0014
|
|
8
|
-
* per-PK fold that will live here) property-testable against an ordered per-row apply oracle.
|
|
9
|
-
*
|
|
10
|
-
* One inbox owns all shapes in a consistency group; the group commits atomically at the lowest
|
|
11
|
-
* complete frontier across its shapes ({@link lowestCompleteLsn}). `must-refetch` truncation stays
|
|
12
|
-
* with the applier (the inbox only drops the affected shape's buffer via {@link resetShape}).
|
|
13
|
-
*
|
|
14
|
-
* COMMIT WATERMARK vs DEDUP FRONTIER (ADR-0031) — the load-bearing separation. Two per-shape LSNs live
|
|
15
|
-
* here and they are deliberately NOT the same number:
|
|
16
|
-
*
|
|
17
|
-
* - {@link completeLsns} — the SOLE dedup threshold. {@link ingestChange} drops any change at or below
|
|
18
|
-
* it as already-seen. Nothing else may narrow what the inbox accepts; a change below a shape's floor
|
|
19
|
-
* (below) but above its raw frontier is still buffered, never dropped.
|
|
20
|
-
* - {@link commitFloors} — a per-shape COMMIT watermark laid down once per catch-up completion (see
|
|
21
|
-
* {@link ingestUpToDate}'s alignment). It only ever RAISES a shape's effective commit frontier in
|
|
22
|
-
* {@link lowestCompleteLsn}; it never gates ingestion.
|
|
23
|
-
*
|
|
24
|
-
* Why the two must be separate: Electric's catch-up (non-live) shape responses are CDN-cacheable
|
|
25
|
-
* (`s-maxage`, `stale-while-revalidate`), and the `up-to-date` control message — with its
|
|
26
|
-
* `global_last_seen_lsn` watermark — rides INSIDE that cached body. So a quiet shape's cached catch-up
|
|
27
|
-
* can assert a STALE watermark (captured before a busy sibling shape's newer writes), which drags the
|
|
28
|
-
* group min-frontier below changes already delivered on the busy shape, holding them buffered until the
|
|
29
|
-
* quiet shape's first LIVE long-poll returns a fresh watermark (~tens of seconds on Electric Cloud). The
|
|
30
|
-
* alignment lifts the commit floors to the freshest ASSERTED global head so those changes commit at
|
|
31
|
-
* catch-up completion — while the dedup frontier stays put, so a late sub-floor change from a shape whose
|
|
32
|
-
* cached catch-up omitted it is still ingested and committed rather than dropped.
|
|
33
|
-
*/
|
|
34
|
-
export declare class ShapeInbox {
|
|
35
|
-
private readonly changes;
|
|
36
|
-
private readonly completeLsns;
|
|
37
|
-
private readonly moveOuts;
|
|
38
|
-
private readonly moveIns;
|
|
39
|
-
private readonly epochs;
|
|
40
|
-
private readonly snapshotAccepted;
|
|
41
|
-
private readonly upToDateSeen;
|
|
42
|
-
private readonly lastUpToDateLsn;
|
|
43
|
-
private readonly commitFloors;
|
|
44
|
-
private aligned;
|
|
45
|
-
private lastAlignedFloor;
|
|
46
|
-
constructor(shapeNames: Iterable<string>);
|
|
47
|
-
/**
|
|
48
|
-
* Whether the shape is still accepting snapshot (LSN-0) rows past the dedup frontier — true from
|
|
49
|
-
* registration / the last {@link resetShape} until the first real-lsn change re-armed the dedup. The
|
|
50
|
-
* commit path reads this to apply such rows idempotently (the racing recovery loops can double-deliver
|
|
51
|
-
* them), consistent with the move-in upsert path, rather than as a plain collision-surfacing insert.
|
|
52
|
-
*/
|
|
53
|
-
acceptsSnapshotRowsFor(shapeName: string): boolean;
|
|
54
|
-
/** The complete-LSN frontier for one shape (the already-seen dedup threshold). */
|
|
55
|
-
completeLsnFor(shapeName: string): Lsn;
|
|
56
|
-
/**
|
|
57
|
-
* The shape's current reset epoch. The commit path snapshots this for every peeked shape and passes it
|
|
58
|
-
* back to the acks, which no-op for any shape whose epoch changed (a mid-commit {@link resetShape}) so
|
|
59
|
-
* the reset's own truncate+rebuild path owns that shape's post-reset state.
|
|
60
|
-
*/
|
|
61
|
-
epochFor(shapeName: string): number;
|
|
62
|
-
/**
|
|
63
|
-
* Buffer a change message. A message at or below the shape's current complete frontier is
|
|
64
|
-
* already-seen and dropped. `isLastOfLsn` advances the frontier to this LSN.
|
|
65
|
-
*/
|
|
66
|
-
ingestChange(shapeName: string, message: ChangeMessage<Row<unknown>>, lsn: Lsn, isLastOfLsn: boolean): void;
|
|
67
|
-
/** The commit floor (ADR-0031) for one shape — the aligned watermark; -1 when no floor has been laid. */
|
|
68
|
-
commitFloorFor(shapeName: string): Lsn;
|
|
69
|
-
/**
|
|
70
|
-
* A shape's EFFECTIVE complete frontier (ADR-0031): `max(completeLsnFor(shape), commitFloorFor(shape))` —
|
|
71
|
-
* the raw dedup frontier raised by any aligned commit floor. This is the exact per-shape quantity
|
|
72
|
-
* {@link lowestCompleteLsn} minimizes over (both go through here, so the two definitions cannot drift),
|
|
73
|
-
* and the input the live-tail sibling nudge reads to decide which siblings still lag a target LSN.
|
|
74
|
-
*/
|
|
75
|
-
effectiveLsnFor(shapeName: string): Lsn;
|
|
76
|
-
/**
|
|
77
|
-
* Whether this shape has reported `up-to-date` at least once since registration / its last
|
|
78
|
-
* {@link resetShape} — the {@link upToDateSeen} flag. The live-tail sibling nudge (ADR-0031) reads this:
|
|
79
|
-
* a shape still catching up advances on its own, so only a shape already in its live tail is ever nudged.
|
|
80
|
-
*/
|
|
81
|
-
hasReportedUpToDate(shapeName: string): boolean;
|
|
82
|
-
/** The freshest asserted global head the last catch-up alignment aligned to (ADR-0031); -1 if never aligned. */
|
|
83
|
-
alignedFloor(): Lsn;
|
|
84
|
-
/**
|
|
85
|
-
* Advance the frontier on an `up-to-date` control message (carries no buffered change) AND run the
|
|
86
|
-
* one-time catch-up commit-floor alignment (ADR-0031) once the whole group has reported up-to-date.
|
|
87
|
-
*
|
|
88
|
-
* Returns `true` iff THIS call performed the alignment (the caller emits a single diagnostic line on
|
|
89
|
-
* that transition); `false` on every other call.
|
|
90
|
-
*/
|
|
91
|
-
ingestUpToDate(shapeName: string, globalLastSeenLsn: Lsn): boolean;
|
|
92
|
-
/** Buffer a `move-out` event's patterns for a shape (ADR-0023); applied at the next commit. */
|
|
93
|
-
ingestMoveOut(shapeName: string, patterns: MovePattern[]): void;
|
|
94
|
-
/** Remove and return a shape's buffered `move-out` pattern sets (one per event), in arrival order. */
|
|
95
|
-
drainMoveOuts(shapeName: string): MovePattern[][];
|
|
96
|
-
/**
|
|
97
|
-
* Peek — WITHOUT removing — a shape's buffered `move-out` pattern sets (a copy, arrival order). Pairs
|
|
98
|
-
* with {@link ackMoveOuts}: the commit path peeks, applies inside its transaction, and acks (removes)
|
|
99
|
-
* only after the transaction succeeds — so a failed/degraded commit (ADR-0009 decision 5) leaves the
|
|
100
|
-
* revocations buffered rather than silently losing them.
|
|
101
|
-
*/
|
|
102
|
-
peekMoveOuts(shapeName: string): MovePattern[][];
|
|
103
|
-
/**
|
|
104
|
-
* Remove the first `count` buffered `move-out` pattern sets for a shape (call only after the commit
|
|
105
|
-
* that consumed a matching {@link peekMoveOuts} of that many entries succeeded). Removing exactly the
|
|
106
|
-
* peeked count — not clear-all — keeps any move-out that arrived DURING the commit (coalescing path)
|
|
107
|
-
* buffered for the next run. `epochAtPeek` is the shape's {@link epochFor} captured at peek time: if a
|
|
108
|
-
* {@link resetShape} bumped it since, the peeked entries no longer exist (the array was replaced), so
|
|
109
|
-
* this no-ops rather than splicing the post-reset replacement.
|
|
110
|
-
*/
|
|
111
|
-
ackMoveOuts(shapeName: string, count: number, epochAtPeek: number): void;
|
|
112
|
-
/** Whether any shape has a buffered `move-out` awaiting a commit. */
|
|
113
|
-
hasPendingMoveOuts(): boolean;
|
|
114
|
-
/** Buffer a `move-in` snapshot row for a shape (ADR-0024); applied idempotently at the next commit. */
|
|
115
|
-
ingestMoveIn(shapeName: string, message: ChangeMessage<Row<unknown>>): void;
|
|
116
|
-
/** Remove and return a shape's buffered `move-in` snapshot rows, in arrival order. */
|
|
117
|
-
drainMoveIns(shapeName: string): ChangeMessage<Row<unknown>>[];
|
|
118
|
-
/** Peek — WITHOUT removing — a shape's buffered `move-in` snapshot rows (a copy, arrival order). See {@link peekMoveOuts}. */
|
|
119
|
-
peekMoveIns(shapeName: string): ChangeMessage<Row<unknown>>[];
|
|
120
|
-
/**
|
|
121
|
-
* Remove the first `count` buffered `move-in` snapshot rows for a shape (post-commit ack; see
|
|
122
|
-
* {@link ackMoveOuts}). No-ops if `epochAtPeek` no longer matches the shape's current epoch (a
|
|
123
|
-
* mid-commit {@link resetShape}), so the post-reset replacement rows survive.
|
|
124
|
-
*/
|
|
125
|
-
ackMoveIns(shapeName: string, count: number, epochAtPeek: number): void;
|
|
126
|
-
/** Whether any shape has a buffered `move-in` awaiting a commit. */
|
|
127
|
-
hasPendingMoveIns(): boolean;
|
|
128
|
-
/** Reset a shape on `must-refetch`: drop its buffer and rewind its frontier (the applier truncates). */
|
|
129
|
-
resetShape(shapeName: string): void;
|
|
130
|
-
/**
|
|
131
|
-
* The lowest EFFECTIVE complete frontier across all shapes — the atomic group commit target. A shape's
|
|
132
|
-
* effective frontier is `max(completeLsnFor(shape), commitFloorFor(shape))` (ADR-0031): the raw dedup
|
|
133
|
-
* frontier, raised by any aligned commit floor. Aligning the floors up to the freshest asserted global
|
|
134
|
-
* head lets a group whose quiet shapes reported a STALE cached catch-up watermark still commit a busy
|
|
135
|
-
* shape's delivered changes at catch-up completion, instead of holding them until the quiet shapes'
|
|
136
|
-
* first live long-poll. The floor never narrows what {@link ingestChange} accepts (that remains the raw
|
|
137
|
-
* {@link completeLsns}), so a late sub-floor change is still ingested and then committed.
|
|
138
|
-
*/
|
|
139
|
-
lowestCompleteLsn(): Lsn;
|
|
140
|
-
/**
|
|
141
|
-
* Whether any shape has a buffered change entry at an LSN at or below `targetLsn` (ADR-0031). The commit
|
|
142
|
-
* loop uses this to fire a commit for a LATE-arriving change that lands at or below an already-committed
|
|
143
|
-
* target — possible exactly because the aligned commit floor lets {@link ingestChange} accept a change
|
|
144
|
-
* below the floor while the group frontier already sits at (or above) it, so no new frontier advance
|
|
145
|
-
* would otherwise trigger a commit for it.
|
|
146
|
-
*/
|
|
147
|
-
hasBufferedChangesAtOrBelow(targetLsn: Lsn): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* Peek — WITHOUT removing — every buffered change at or below `targetLsn`, per shape, in buffered-LSN
|
|
150
|
-
* order. The returned map has an entry for every shape (an empty array where nothing peeked). Pairs
|
|
151
|
-
* with {@link ackUpTo}: the commit path peeks, writes the batch inside its transaction, and acks
|
|
152
|
-
* (removes) only after the transaction succeeds — so a failed/degraded commit (ADR-0009 decision 5)
|
|
153
|
-
* holds the batch in the buffer rather than dropping it, and a newer LSN can never land over it.
|
|
154
|
-
*/
|
|
155
|
-
peekUpTo(targetLsn: Lsn): Map<string, ChangeMessage<Row<unknown>>[]>;
|
|
156
|
-
/**
|
|
157
|
-
* Remove every buffered change at or below `targetLsn` (call only after the commit that consumed a
|
|
158
|
-
* matching {@link peekUpTo} succeeded). `epochsAtPeek` maps each shape to its {@link epochFor} captured
|
|
159
|
-
* at peek time; a shape whose epoch has since changed is **skipped entirely**.
|
|
160
|
-
*
|
|
161
|
-
* The epoch guard is load-bearing under a frontier REWIND. In the steady state, the frontier only
|
|
162
|
-
* advances, so nothing new at or below `targetLsn` can be buffered between peek and ack. But a mid-commit
|
|
163
|
-
* {@link resetShape} (must-refetch) rewinds a shape's frontier to -1 and lets its re-snapshot buffer at
|
|
164
|
-
* LSN 0 — content that was NOT in this commit's peek. Deleting it here (LSN 0 ≤ `targetLsn`) would drop
|
|
165
|
-
* the rebuild; the epoch bump makes this no-op for that shape so the reset's own rebuild path owns it.
|
|
166
|
-
*/
|
|
167
|
-
ackUpTo(targetLsn: Lsn, epochsAtPeek: Map<string, number>): void;
|
|
168
|
-
/** Snapshot every shape's current {@link epochFor} — captured at peek time and passed to the acks. */
|
|
169
|
-
snapshotEpochs(): Map<string, number>;
|
|
170
|
-
/**
|
|
171
|
-
* Remove and return every buffered change at or below `targetLsn`, per shape, in buffered-LSN order
|
|
172
|
-
* ({@link peekUpTo} then {@link ackUpTo}). The returned map has an entry for every shape (an empty
|
|
173
|
-
* array where nothing drained).
|
|
174
|
-
*/
|
|
175
|
-
drainUpTo(targetLsn: Lsn): Map<string, ChangeMessage<Row<unknown>>[]>;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* A drained shape batch folded to **one net operation per primary key** (ADR-0014 decision 1).
|
|
179
|
-
* Each PK appears in at most one of `inserts`/`updates`, and at most once in `deletes` — except a
|
|
180
|
-
* *re-created* PK (`[delete, insert]`), which appears in both `deletes` and `inserts` so the bulk
|
|
181
|
-
* apply clears the pre-existing row before inserting the new one. The Sync applier therefore runs
|
|
182
|
-
* three bulk statements **in the order `deletes → inserts → updates`** (Phase 3): that ordering is
|
|
183
|
-
* what makes a re-create safe, and every other PK is touched by exactly one statement, so the rest
|
|
184
|
-
* of the order is irrelevant within the atomic commit.
|
|
185
|
-
*/
|
|
186
|
-
export interface FoldedShapeBatch {
|
|
187
|
-
/** PKs to delete — net-`delete` keys, plus the clearing delete of each re-created key. */
|
|
188
|
-
deletes: ChangeMessage<Row<unknown>>[];
|
|
189
|
-
/** Full rows to insert — net-`insert` keys, plus each re-created key's new row (merged values). */
|
|
190
|
-
inserts: InsertChangeMessage[];
|
|
191
|
-
/** Merged partial updates — net-`update` keys (carry the PK plus the union of updated columns). */
|
|
192
|
-
updates: ChangeMessage<Row<unknown>>[];
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Fold a drained shape batch (ordered by LSN, one shape) to one net operation per primary key
|
|
196
|
-
* (ADR-0014 decision 1), so the read path can bulk-apply without the `UPDATE … FROM` / `INSERT …
|
|
197
|
-
* SELECT json_to_recordset(…)` same-PK join hazard (those use **one arbitrary** matching row when
|
|
198
|
-
* the source holds duplicate PKs). Each PK's ops are replayed in LSN order down to:
|
|
199
|
-
*
|
|
200
|
-
* - **trailing `delete`** ⇒ a single DELETE;
|
|
201
|
-
* - **`insert` with no preceding delete**, then any updates ⇒ a single INSERT with merged values
|
|
202
|
-
* (a *plain* insert — a genuine PK collision still surfaces, never a silent upsert);
|
|
203
|
-
* - **only `update`s** ⇒ a single UPDATE with merged values;
|
|
204
|
-
* - **re-created** (`[delete, … , insert, …]`, no trailing delete) ⇒ DELETE **and** INSERT, so the
|
|
205
|
-
* pre-existing row is cleared first (faithful to the per-row `DELETE`-then-`INSERT`; a plain INSERT
|
|
206
|
-
* would collide with the row the dropped delete was meant to remove);
|
|
207
|
-
* - **`update` after a delete** (`[delete, update]` and kin) is malformed for a faithful stream
|
|
208
|
-
* (an update asserts the row exists) ⇒ throw, surfacing stream corruption rather than silently
|
|
209
|
-
* dropping it.
|
|
210
|
-
*
|
|
211
|
-
* Pure and dependency-free by design (ADR-0014 / ISS-06): property-tested against the oracle
|
|
212
|
-
* *fold-then-bulk ≡ ordered per-row apply* over random same-PK sequences and random initial state.
|
|
213
|
-
*/
|
|
214
|
-
export declare function foldChangeBatch(messages: ChangeMessage<Row<unknown>>[]): FoldedShapeBatch;
|
|
215
|
-
//# sourceMappingURL=shape-inbox.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shape-inbox.d.ts","sourceRoot":"","sources":["../../src/sync/shape-inbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAE5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,UAAU;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8D;IAEtF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA0B;IAIvD,OAAO,CAAC,QAAQ,CAAC,QA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