@pgxsinkit/client 0.1.32 → 0.1.40
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 +11 -0
- package/dist/boot-report.d.ts +134 -0
- package/dist/boot-report.d.ts.map +1 -0
- package/dist/convergence.d.ts +76 -0
- package/dist/convergence.d.ts.map +1 -0
- package/dist/debug.d.ts +34 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/export-data.d.ts +100 -0
- package/dist/export-data.d.ts.map +1 -0
- package/dist/export-dump.d.ts +92 -0
- package/dist/export-dump.d.ts.map +1 -0
- package/dist/export-store.d.ts +214 -0
- package/dist/export-store.d.ts.map +1 -0
- package/dist/index.d.ts +615 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8083 -2286
- package/dist/index.js.map +81 -44
- package/dist/lazy-guard.d.ts +59 -0
- package/dist/lazy-guard.d.ts.map +1 -0
- package/dist/lifecycle-slot.d.ts +31 -0
- package/dist/lifecycle-slot.d.ts.map +1 -0
- package/dist/live-rows-sql.d.ts +21 -0
- package/dist/live-rows-sql.d.ts.map +1 -0
- package/dist/local-store.d.ts +56 -0
- package/dist/local-store.d.ts.map +1 -0
- package/dist/local-tables.d.ts +707 -0
- package/dist/local-tables.d.ts.map +1 -0
- package/dist/mutation-state.d.ts +69 -0
- package/dist/mutation-state.d.ts.map +1 -0
- package/dist/mutation.d.ts +129 -4
- package/dist/mutation.d.ts.map +1 -1
- package/dist/schema.d.ts +82 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/shape-sync.d.ts +190 -0
- package/dist/shape-sync.d.ts.map +1 -0
- package/dist/store-path.d.ts +132 -0
- package/dist/store-path.d.ts.map +1 -0
- package/dist/sync/apply.d.ts +51 -0
- package/dist/sync/apply.d.ts.map +1 -0
- package/dist/sync/copy.d.ts +43 -0
- package/dist/sync/copy.d.ts.map +1 -0
- package/dist/sync/drizzle-executor.d.ts +5 -0
- package/dist/sync/drizzle-executor.d.ts.map +1 -0
- package/dist/sync/index.d.ts +32 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/metadata-tables.d.ts +131 -0
- package/dist/sync/metadata-tables.d.ts.map +1 -0
- package/dist/sync/nudge.d.ts +49 -0
- package/dist/sync/nudge.d.ts.map +1 -0
- package/dist/sync/shape-inbox.d.ts +215 -0
- package/dist/sync/shape-inbox.d.ts.map +1 -0
- package/dist/sync/subscription-state.d.ts +39 -0
- package/dist/sync/subscription-state.d.ts.map +1 -0
- package/dist/sync/tags.d.ts +130 -0
- package/dist/sync/tags.d.ts.map +1 -0
- package/dist/sync/types.d.ts +126 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync-auth.d.ts +53 -0
- package/dist/sync-auth.d.ts.map +1 -0
- package/dist/testing.d.ts +27 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +17 -0
- package/dist/testing.js.map +11 -0
- package/dist/worker/attach-sync-client.d.ts +96 -0
- package/dist/worker/attach-sync-client.d.ts.map +1 -0
- package/dist/worker/define-sync-worker.d.ts +76 -0
- package/dist/worker/define-sync-worker.d.ts.map +1 -0
- package/dist/worker/live-diff.d.ts +44 -0
- package/dist/worker/live-diff.d.ts.map +1 -0
- package/dist/worker/protocol.d.ts +341 -0
- package/dist/worker/protocol.d.ts.map +1 -0
- package/dist/worker/token-cache.d.ts +26 -0
- package/dist/worker/token-cache.d.ts.map +1 -0
- package/oxlint-plugin.js +143 -0
- package/package.json +20 -7
- package/skills/core/SKILL.md +210 -0
- package/skills/operating/SKILL.md +303 -0
- package/src/boot-report.ts +287 -0
- package/src/convergence.ts +197 -0
- package/src/debug.ts +151 -0
- package/src/export-data.ts +300 -0
- package/src/export-dump.ts +239 -0
- package/src/export-store.ts +309 -0
- package/src/index.ts +1652 -51
- package/src/lazy-guard.ts +135 -0
- package/src/lifecycle-slot.ts +66 -0
- package/src/live-rows-sql.ts +45 -0
- package/src/local-store.ts +193 -0
- package/src/local-tables.ts +546 -0
- package/src/mutation-state.ts +99 -0
- package/src/mutation.ts +1910 -562
- package/src/schema.ts +472 -28
- package/src/shape-sync.ts +498 -0
- package/src/store-path.ts +249 -0
- package/src/sync/apply.ts +530 -0
- package/src/sync/copy.ts +206 -0
- package/src/sync/drizzle-executor.ts +48 -0
- package/src/sync/index.ts +1087 -0
- package/src/sync/metadata-tables.ts +67 -0
- package/src/sync/nudge.ts +110 -0
- package/src/sync/shape-inbox.ts +566 -0
- package/src/sync/subscription-state.ts +135 -0
- package/src/sync/tags.ts +365 -0
- package/src/sync/types.ts +141 -0
- package/src/sync-auth.ts +117 -0
- package/src/testing.ts +53 -0
- package/src/worker/attach-sync-client.ts +653 -0
- package/src/worker/define-sync-worker.ts +762 -0
- package/src/worker/live-diff.ts +140 -0
- package/src/worker/protocol.ts +425 -0
- package/src/worker/token-cache.ts +84 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a `storePath` is not a plain name (ADR-0036 decision 1): it carries a URL scheme (`://`) or
|
|
3
|
+
* is empty/whitespace-only. A distinct type — not a bare `Error` — so a caller can `instanceof`-branch the
|
|
4
|
+
* old dataDir-URL contract from a genuine store failure. The message names the plain-path contract and
|
|
5
|
+
* shows the corrected form, without echoing a resolvable URL a consumer might imitate.
|
|
6
|
+
*/
|
|
7
|
+
export declare class InvalidStorePathError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Thrown when a caller-owned PGlite handed to {@link CreateSyncClientOptions.pgliteInstance} /
|
|
12
|
+
* {@link CreateSyncClientOptions.precreatedPglite} is PROVABLY non-persistent (ADR-0036 decision 4): its
|
|
13
|
+
* `dataDir` is `undefined` (PGlite's in-memory default — the `new PGlite()` a copy-paste reaches) or begins
|
|
14
|
+
* `memory://`. Names both the why (durability semantics assume a persisted store) and the two exits, so a
|
|
15
|
+
* consumer is never left guessing which store to hand us instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare class NonPersistentStoreError extends Error {
|
|
18
|
+
constructor(observed: "in-memory-default" | "memory-scheme");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Thrown when a restore (`restoreFrom`, ADR-0035 decision 6) targets a store path whose backend store ALREADY
|
|
22
|
+
* exists. Restore is a CREATION-path feature — it boots a brand-new store on `loadDataDir` — and never
|
|
23
|
+
* overlays a live store: silently merging a backup into an existing datadir would corrupt it. A distinct type
|
|
24
|
+
* (not a bare `Error`) so a caller can `instanceof`-branch "target already there" from a genuine boot failure.
|
|
25
|
+
* The remedy is a deliberate manual {@link SyncClient.destroy} of the existing store first (never automatic —
|
|
26
|
+
* dropping a user's local store must be their explicit act).
|
|
27
|
+
*/
|
|
28
|
+
export declare class RestoreTargetExistsError extends Error {
|
|
29
|
+
constructor(storePath: string);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The module-internal marker a testing helper stamps onto the options object so option handling can select
|
|
33
|
+
* the memory backend / unlock the BYO refusal (ADR-0036 decision 3). `Symbol.for` (not a bare `Symbol()`)
|
|
34
|
+
* on purpose: each public entry point is bundled STANDALONE (`scripts/build-public-packages.ts`,
|
|
35
|
+
* `splitting: false`), so a plain module symbol would be DUPLICATED between the main bundle and the
|
|
36
|
+
* `./testing` bundle — two distinct symbols, and the marker set by `./testing` would be invisible to the
|
|
37
|
+
* main entry's reader. The global registry key guarantees ONE symbol across bundles. It is deliberately
|
|
38
|
+
* absent from the main entry's exports and from every public type, so a production consumer cannot name it.
|
|
39
|
+
*/
|
|
40
|
+
export declare const TEST_STORE_BACKEND: unique symbol;
|
|
41
|
+
/**
|
|
42
|
+
* What a testing helper's marker asks of option handling: `"memory"` mints a scheme-selected memory store
|
|
43
|
+
* (and, being ours-under-the-covers, also unlocks the BYO refusal); `"acknowledged"` only unlocks the BYO
|
|
44
|
+
* refusal for a caller who owns the (test) instance themselves. Both are visible, deliberate acts — an
|
|
45
|
+
* import whose name says what it is.
|
|
46
|
+
*/
|
|
47
|
+
export type TestStoreMarker = "memory" | "acknowledged";
|
|
48
|
+
/** An options object that MAY carry the internal testing marker (read via {@link readTestStoreMarker}). */
|
|
49
|
+
export type WithTestStoreMarker = {
|
|
50
|
+
[TEST_STORE_BACKEND]?: TestStoreMarker;
|
|
51
|
+
};
|
|
52
|
+
/** Read the internal testing marker off an options object, or `undefined` when none was stamped. */
|
|
53
|
+
export declare function readTestStoreMarker(options: unknown): TestStoreMarker | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* What {@link createClientPGlite} (and any store-opening seam) accepts as its store argument: a plain
|
|
56
|
+
* `storePath` string, or the option object a testing helper mints (`memoryStoreForTests(...)`) — carrying a
|
|
57
|
+
* `storePath` plus the invisible internal marker. Accepting the object form is what lets the testing
|
|
58
|
+
* helper's output flow STRAIGHT into `createClientPGlite(memoryStoreForTests("x"))` without a consumer ever
|
|
59
|
+
* naming a backend.
|
|
60
|
+
*/
|
|
61
|
+
export type StorePathInput = string | ({
|
|
62
|
+
storePath: string;
|
|
63
|
+
} & WithTestStoreMarker);
|
|
64
|
+
/** Normalise a {@link StorePathInput} to a plain path plus any internal memory-backend override it carried. */
|
|
65
|
+
export declare function normaliseStorePathInput(input: StorePathInput): {
|
|
66
|
+
storePath: string;
|
|
67
|
+
backendOverride?: "memory";
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The environment seam the backend derivation reads — factored out so a browser derivation is fakeable in
|
|
71
|
+
* a Bun unit test (there is no `indexedDB` there). `hasIndexedDb` is the browser/worker signal: PGlite's
|
|
72
|
+
* IndexedDB backend needs `indexedDB`, which a browser tab AND a Web/Shared/dedicated worker expose but
|
|
73
|
+
* Bun/Node do not — so it distinguishes "run in the browser" (idb) from "run on the server" (filesystem)
|
|
74
|
+
* without a DOM-lib dependency.
|
|
75
|
+
*/
|
|
76
|
+
export interface StoreEnv {
|
|
77
|
+
hasIndexedDb: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolve a plain {@link storePath} to the PGlite dataDir URL the store opens at — the ONE derivation point
|
|
81
|
+
* (ADR-0036 decision 2). Browser/worker (`indexedDB` present) → `idb://<storePath>`; Bun/Node → `file://<storePath>`
|
|
82
|
+
* (relative paths resolve against the working directory, exactly as PGlite's filesystem backend does — pass
|
|
83
|
+
* an absolute path if that matters). The `backendOverride` is internal-only: `"memory"` selects a
|
|
84
|
+
* scheme-selected `memory://<storePath>` store for the sanctioned test/ephemeral lanes.
|
|
85
|
+
*
|
|
86
|
+
* Rejects a scheme-bearing or empty/whitespace-only path with {@link InvalidStorePathError} — the storePath
|
|
87
|
+
* contract fails loudly at the boundary, never silently re-interpreted (no-legacy rule). The returned URL is
|
|
88
|
+
* internal plumbing; do not surface it to consumers as something to imitate.
|
|
89
|
+
*
|
|
90
|
+
* CRITICAL (ADR-0036 decision 5, probed on PGlite 0.5.4): memory selection is ALWAYS the scheme-selected
|
|
91
|
+
* `memory://` form, NEVER PGlite's explicit `fs: new MemoryFS()` option — `dumpDataDir` from an explicit-`fs`
|
|
92
|
+
* instance silently omits relation files created after initdb, so a restored clone raises "relation does not
|
|
93
|
+
* exist". Callers that need a memory store must route through this function, never construct `MemoryFS`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function resolveStoreDataDir(storePath: string, backendOverride?: "memory", env?: StoreEnv): string;
|
|
96
|
+
/**
|
|
97
|
+
* The IndexedDB database name a browser store occupies (ADR-0036) — a browser-only OPERATIONAL helper for
|
|
98
|
+
* orphan GC / corrupt-store deletion (`indexedDB.deleteDatabase(...)`), NOT part of the create path. PGlite
|
|
99
|
+
* maps `idb://<storePath>` to the IndexedDB database `/pglite/<storePath>` (its `WASM_PREFIX` `/pglite`
|
|
100
|
+
* joined with the path after the scheme; verified against `@electric-sql/pglite` 0.5.4 dist). Exposed so a
|
|
101
|
+
* consumer that GCs its own stores routes that PGlite-internal naming knowledge through the library rather
|
|
102
|
+
* than re-deriving the `/pglite/` prefix itself. Rejects a scheme-bearing/empty path exactly as
|
|
103
|
+
* {@link resolveStoreDataDir} does, so the two stay in lockstep.
|
|
104
|
+
*/
|
|
105
|
+
export declare function storeIndexedDbDatabaseName(storePath: string): string;
|
|
106
|
+
/**
|
|
107
|
+
* Classify a PGlite instance's `dataDir` for the BYO refusal (ADR-0036 decision 4). Returns the offending
|
|
108
|
+
* shape when the instance is PROVABLY non-persistent (`undefined` = PGlite's in-memory default; a
|
|
109
|
+
* `memory://` prefix = an explicit memory store), or `null` when it passes — anything else present,
|
|
110
|
+
* including exotic custom-VFS configs we cannot classify, is the caller's own call (the guard catches the
|
|
111
|
+
* two accidental non-persistent shapes, it is not a storage-backend whitelist).
|
|
112
|
+
*/
|
|
113
|
+
export declare function classifyNonPersistentDataDir(dataDir: string | undefined): "in-memory-default" | "memory-scheme" | null;
|
|
114
|
+
/**
|
|
115
|
+
* Does the backend store a plain {@link storePath} resolves to ALREADY exist? The fresh-target gate for a
|
|
116
|
+
* restore (ADR-0035 decision 6) — restore refuses a target that is already there. Per backend:
|
|
117
|
+
*
|
|
118
|
+
* - **memory** (`backendOverride === "memory"`) — a scheme-selected memory store is fresh by construction:
|
|
119
|
+
* it lives only for the instance about to be created, so there is nothing to collide with. Always `false`
|
|
120
|
+
* (the sanctioned test/ephemeral lane never blocks a restore).
|
|
121
|
+
* - **`file://`** (Bun/Node) — filesystem existence of the datadir directory. `node:fs` is imported
|
|
122
|
+
* DYNAMICALLY inside this branch, never at module top level, so a browser bundle (which only ever hits the
|
|
123
|
+
* `idb://` branch below) never pulls `node:fs` in. Relative paths resolve against the working directory,
|
|
124
|
+
* exactly as PGlite's filesystem backend and {@link resolveStoreDataDir} do.
|
|
125
|
+
* - **`idb://`** (browser/worker) — `indexedDB.databases()` enumerated for the store's database name
|
|
126
|
+
* ({@link storeIndexedDbDatabaseName}). BEST-EFFORT: `databases()` is unavailable on some engines (older
|
|
127
|
+
* Firefox, certain worker contexts); when absent we CANNOT prove existence, so we report `false` and let
|
|
128
|
+
* the restore proceed rather than fabricate a result — a real overlay collision would still surface as a
|
|
129
|
+
* PGlite-level boot failure. We never fake a positive.
|
|
130
|
+
*/
|
|
131
|
+
export declare function storeTargetExists(storePath: string, backendOverride?: "memory", env?: StoreEnv): Promise<boolean>;
|
|
132
|
+
//# sourceMappingURL=store-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-path.d.ts","sourceRoot":"","sources":["../src/store-path.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED;;;;;;GAMG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,QAAQ,EAAE,mBAAmB,GAAG,eAAe,EAa1D;CACF;AAED;;;;;;;GAOG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,SAAS,EAAE,MAAM,EAQ5B;CACF;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,OAAO,MAA0D,CAAC;AAEnG;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,cAAc,CAAC;AAExD,2GAA2G;AAC3G,MAAM,MAAM,mBAAmB,GAAG;IAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,eAAe,CAAA;CAAE,CAAC;AAE7E,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAIjF;AAED;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,mBAAmB,CAAC,CAAC;AAEpF,+GAA+G;AAC/G,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,cAAc,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,QAAQ,CAAA;CAAE,CAMhH;AAED;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB,YAAY,EAAE,OAAO,CAAC;CACvB;AAOD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,QAAQ,EAC1B,GAAG,GAAE,QAA2B,GAC/B,MAAM,CAeR;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAYpE;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,mBAAmB,GAAG,eAAe,GAAG,IAAI,CAI9C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,eAAe,CAAC,EAAE,QAAQ,EAC1B,GAAG,GAAE,QAA2B,GAC/B,OAAO,CAAC,OAAO,CAAC,CAiBlB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ChangeMessage, Row } from "@electric-sql/client";
|
|
2
|
+
import type { PGliteInterface, Transaction } from "@electric-sql/pglite";
|
|
3
|
+
import type { ApplyTarget } from "../local-tables";
|
|
4
|
+
import type { InsertChangeMessage } from "./types";
|
|
5
|
+
export interface ApplyMessageToTableOptions {
|
|
6
|
+
pg: PGliteInterface | Transaction;
|
|
7
|
+
target: ApplyTarget;
|
|
8
|
+
message: ChangeMessage<Row<unknown>>;
|
|
9
|
+
debug: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function applyMessageToTable({ pg, target, message, debug }: ApplyMessageToTableOptions): Promise<import("@electric-sql/pglite").Results<never> | undefined>;
|
|
12
|
+
export interface BulkApplyMessagesToTableOptions {
|
|
13
|
+
pg: PGliteInterface | Transaction;
|
|
14
|
+
target: ApplyTarget;
|
|
15
|
+
messages: InsertChangeMessage[];
|
|
16
|
+
debug: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function applyInsertsToTable({ pg, target, messages, debug }: BulkApplyMessagesToTableOptions): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Bulk **upsert** for tagged-subquery move-in rows (ADR-0024). A move-in is an existing row ENTERING the
|
|
21
|
+
* shape — unlike a CDC `insert` (a brand-new row) it may already be present locally via an independent
|
|
22
|
+
* grant, or be re-delivered on a resume from before the move-in's offset. So it is applied idempotently:
|
|
23
|
+
* `INSERT … ON CONFLICT (pk) DO UPDATE` refreshes to the move-in's authoritative value (or `DO NOTHING`
|
|
24
|
+
* for a pk-only table). The plain-`INSERT` invariant of the CDC path — a genuine PK collision must
|
|
25
|
+
* surface ({@link applyInsertsToTable}) — is intentionally NOT used here, because for a move-in a present
|
|
26
|
+
* row is expected, not a bug. Batched by parameter count (move-in volume is incremental, not a backfill).
|
|
27
|
+
*/
|
|
28
|
+
export declare function applyUpsertsToTable({ pg, target, messages, debug }: BulkKeyedApplyOptions): Promise<void>;
|
|
29
|
+
export declare function applyMessagesToTableWithJson({ pg, target, messages, debug }: BulkApplyMessagesToTableOptions): Promise<void>;
|
|
30
|
+
export declare function applyMessagesToTableWithCopy({ pg, target, messages, debug }: BulkApplyMessagesToTableOptions): Promise<void>;
|
|
31
|
+
export interface BulkKeyedApplyOptions {
|
|
32
|
+
pg: PGliteInterface | Transaction;
|
|
33
|
+
target: ApplyTarget;
|
|
34
|
+
/** Folded messages: for deletes the value carries the PK; for updates the PK plus merged columns. */
|
|
35
|
+
messages: ChangeMessage<Row<unknown>>[];
|
|
36
|
+
debug: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Bulk DELETE by primary key via `DELETE … USING json_to_recordset(…)` (ADR-0014 Phase 3). Safe
|
|
40
|
+
* because the read-path fold already left **one row per PK** — no same-PK duplicate in the source.
|
|
41
|
+
*/
|
|
42
|
+
export declare function applyBulkDeletesToTable({ pg, target, messages, debug }: BulkKeyedApplyOptions): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Bulk UPDATE via `UPDATE … FROM json_to_recordset(…)` (ADR-0014 Phase 3), **grouped by the set of
|
|
45
|
+
* non-PK columns** each row carries. Electric's default replica sends only the changed columns, so
|
|
46
|
+
* two rows in one batch can set different columns; one `UPDATE … FROM` per distinct column-set keeps
|
|
47
|
+
* each statement uniform. Safe from the same-PK join hazard because the fold already left one row per
|
|
48
|
+
* PK, so no PK appears twice within a group.
|
|
49
|
+
*/
|
|
50
|
+
export declare function applyBulkUpdatesToTable({ pg, target, messages, debug }: BulkKeyedApplyOptions): Promise<void>;
|
|
51
|
+
//# sourceMappingURL=apply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA4BnD,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,eAAe,GAAG,WAAW,CAAC;IAClC,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IACrC,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,0BAA0B,sEA+BnG;AAED,MAAM,WAAW,+BAA+B;IAC9C,EAAE,EAAE,eAAe,GAAG,WAAW,CAAC;IAClC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC;CAChB;AAyDD,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,+BAA+B,iBA2GzG;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,qBAAqB,iBAsC/F;AAqBD,wBAAsB,4BAA4B,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,+BAA+B,iBA6BlH;AAsBD,wBAAsB,4BAA4B,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,+BAA+B,iBAuClH;AAoBD,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,eAAe,GAAG,WAAW,CAAC;IAClC,MAAM,EAAE,WAAW,CAAC;IACpB,qGAAqG;IACrG,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;IACxC,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,qBAAqB,iBA+BnG;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,qBAAqB,iBAgDnG"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization of JavaScript values into a PostgreSQL `COPY ... WITH (FORMAT
|
|
3
|
+
* text)` stream.
|
|
4
|
+
*
|
|
5
|
+
* The Electric client parses the wire values it receives into native JS values
|
|
6
|
+
* before they reach this module: `int2`/`int4`/`float4`/`float8` become
|
|
7
|
+
* `number`, `int8` becomes `bigint`, `bool` becomes `boolean`, `json`/`jsonb`
|
|
8
|
+
* become parsed objects/arrays, array columns become (possibly nested) JS
|
|
9
|
+
* arrays, and every other type is left as its raw Postgres text representation
|
|
10
|
+
* (a `string`). To feed those values back into `COPY` we have to reverse that:
|
|
11
|
+
* turn each value into the exact text Postgres' input functions expect, then
|
|
12
|
+
* apply the COPY framing.
|
|
13
|
+
*
|
|
14
|
+
* Rather than invent an escaping scheme (the previous CSV-based approach broke
|
|
15
|
+
* on arrays, JSON, embedded delimiters, etc.) this is a faithful port of the
|
|
16
|
+
* two relevant PostgreSQL backend routines:
|
|
17
|
+
*
|
|
18
|
+
* - `CopyAttributeOutText` (src/backend/commands/copyto.c) — field escaping
|
|
19
|
+
* - `array_out` (src/backend/utils/adt/arrayfuncs.c) — array literals
|
|
20
|
+
*
|
|
21
|
+
* The TEXT format is used (not CSV) because it is what Postgres itself emits
|
|
22
|
+
* internally, has a single well-defined escaping algorithm, and round-trips
|
|
23
|
+
* every built-in type.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Serialize a single value into one COPY TEXT field. `null`/`undefined` become
|
|
27
|
+
* the NULL marker (`\N`); everything else is converted to text and escaped.
|
|
28
|
+
*
|
|
29
|
+
* `udtName` is the column's Postgres `udt_name`. When supplied it disambiguates
|
|
30
|
+
* `json`/`jsonb` columns; when omitted the value's runtime type is used (which
|
|
31
|
+
* cannot tell a `jsonb` array from a SQL array).
|
|
32
|
+
*/
|
|
33
|
+
export declare function serializeCopyValue(value: unknown, udtName?: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Serialize a list of row objects into the body of a `COPY ... FROM` request in
|
|
36
|
+
* TEXT format. Columns are emitted in the given order, fields are tab
|
|
37
|
+
* separated, and rows are newline separated.
|
|
38
|
+
*
|
|
39
|
+
* `columnTypes` optionally maps a column name to its Postgres `udt_name`; pass
|
|
40
|
+
* it so `json`/`jsonb` columns serialize correctly.
|
|
41
|
+
*/
|
|
42
|
+
export declare function generateCopyData(rows: ReadonlyArray<Record<string, unknown>>, columns: ReadonlyArray<string>, columnTypes?: Readonly<Record<string, string | undefined>>): string;
|
|
43
|
+
//# sourceMappingURL=copy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy.d.ts","sourceRoot":"","sources":["../../src/sync/copy.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAkJH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAO3E;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC5C,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,EAC9B,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GACzD,MAAM,CAIR"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PGliteInterface, Transaction } from "@electric-sql/pglite";
|
|
2
|
+
import { type PgliteDatabase } from "drizzle-orm/pglite";
|
|
3
|
+
/** A (memoized) Drizzle handle over an open PGlite connection or transaction — engine-internal. */
|
|
4
|
+
export declare function drizzleOverPg(pg: PGliteInterface | Transaction): PgliteDatabase<never>;
|
|
5
|
+
//# sourceMappingURL=drizzle-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-executor.d.ts","sourceRoot":"","sources":["../../src/sync/drizzle-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAsClE,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,EAAE,EAAE,eAAe,GAAG,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,CAOtF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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, 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sync/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA0C5D,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;6LA0BzC,yBAAyB,KAAG,OAAO,CAAC,wBAAwB,CAAC;oCAq0BvB,uBAAuB,KAAG,OAAO,CAAC,sBAAsB,CAAC;kCAqC3D,MAAM;;;GA0B9C;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"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { pgSchema } from "drizzle-orm/pg-core";
|
|
2
|
+
import type { ShapeSubscriptionState } from "./subscription-state";
|
|
3
|
+
/**
|
|
4
|
+
* The two metadata-store relations the sync engine provisions at boot (ADR-0028 decision 4). The
|
|
5
|
+
* metadata schema name is dynamic (per-client config) but fixed at engine construction, so the tables
|
|
6
|
+
* are built per schema string and memoized.
|
|
7
|
+
*
|
|
8
|
+
* ADR-0029 D3: these pgTables are the SINGLE SOURCE for the relations. `migrateSubscriptionMetadataTables`
|
|
9
|
+
* (subscription-state.ts) renders their `CREATE TABLE`/`CREATE INDEX` DDL FROM these definitions via the
|
|
10
|
+
* in-house `renderCreateTableSql` (schema.ts), and the DML paths query them directly — so the DDL and the
|
|
11
|
+
* pgTable can no longer diverge, and the former drift guard in `tests/unit/sync-drizzle-executor.test.ts`
|
|
12
|
+
* is now a plain provisioning round-trip.
|
|
13
|
+
*
|
|
14
|
+
* Property keys are deliberately snake_case to mirror the row shapes the callers already consume
|
|
15
|
+
* (`shape_metadata`, `last_lsn`, `pk_json`, …), so a `select()` returns rows in the existing shape with
|
|
16
|
+
* no alias mapping.
|
|
17
|
+
*/
|
|
18
|
+
export interface MetadataTables {
|
|
19
|
+
/** `<schema>.subscriptions_metadata` — one row per subscription key. */
|
|
20
|
+
readonly subscriptionsMetadata: ReturnType<typeof buildSubscriptionsMetadata>;
|
|
21
|
+
/** `<schema>.shape_row_tags` — the tagged-subquery reason-set store (ADR-0023). */
|
|
22
|
+
readonly shapeRowTags: ReturnType<typeof buildShapeRowTags>;
|
|
23
|
+
}
|
|
24
|
+
declare function buildSubscriptionsMetadata(schema: ReturnType<typeof pgSchema>): import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
25
|
+
name: "subscriptions_metadata";
|
|
26
|
+
schema: string;
|
|
27
|
+
columns: {
|
|
28
|
+
key: import("drizzle-orm/pg-core").PgBuildColumn<"subscriptions_metadata", import("drizzle-orm/pg-core").SetIsPrimaryKey<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
|
|
29
|
+
name: string;
|
|
30
|
+
tableName: "subscriptions_metadata";
|
|
31
|
+
dataType: "string";
|
|
32
|
+
data: string;
|
|
33
|
+
driverParam: string;
|
|
34
|
+
notNull: true;
|
|
35
|
+
hasDefault: false;
|
|
36
|
+
isPrimaryKey: false;
|
|
37
|
+
isAutoincrement: false;
|
|
38
|
+
hasRuntimeDefault: false;
|
|
39
|
+
enumValues: undefined;
|
|
40
|
+
identity: undefined;
|
|
41
|
+
generated: undefined;
|
|
42
|
+
}>;
|
|
43
|
+
shape_metadata: import("drizzle-orm/pg-core").PgBuildColumn<"subscriptions_metadata", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").Set$Type<import("drizzle-orm/pg-core").PgJsonbBuilder, Record<string, ShapeSubscriptionState>>>, {
|
|
44
|
+
name: string;
|
|
45
|
+
tableName: "subscriptions_metadata";
|
|
46
|
+
dataType: "object json";
|
|
47
|
+
data: Record<string, ShapeSubscriptionState>;
|
|
48
|
+
driverParam: unknown;
|
|
49
|
+
notNull: true;
|
|
50
|
+
hasDefault: false;
|
|
51
|
+
isPrimaryKey: false;
|
|
52
|
+
isAutoincrement: false;
|
|
53
|
+
hasRuntimeDefault: false;
|
|
54
|
+
enumValues: undefined;
|
|
55
|
+
identity: undefined;
|
|
56
|
+
generated: undefined;
|
|
57
|
+
}>;
|
|
58
|
+
last_lsn: import("drizzle-orm/pg-core").PgBuildColumn<"subscriptions_metadata", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
|
|
59
|
+
name: string;
|
|
60
|
+
tableName: "subscriptions_metadata";
|
|
61
|
+
dataType: "string";
|
|
62
|
+
data: string;
|
|
63
|
+
driverParam: string;
|
|
64
|
+
notNull: true;
|
|
65
|
+
hasDefault: false;
|
|
66
|
+
isPrimaryKey: false;
|
|
67
|
+
isAutoincrement: false;
|
|
68
|
+
hasRuntimeDefault: false;
|
|
69
|
+
enumValues: undefined;
|
|
70
|
+
identity: undefined;
|
|
71
|
+
generated: undefined;
|
|
72
|
+
}>;
|
|
73
|
+
};
|
|
74
|
+
dialect: 'pg';
|
|
75
|
+
}>;
|
|
76
|
+
declare function buildShapeRowTags(schema: ReturnType<typeof pgSchema>): import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
77
|
+
name: "shape_row_tags";
|
|
78
|
+
schema: string;
|
|
79
|
+
columns: {
|
|
80
|
+
shape_table: import("drizzle-orm/pg-core").PgBuildColumn<"shape_row_tags", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
|
|
81
|
+
name: string;
|
|
82
|
+
tableName: "shape_row_tags";
|
|
83
|
+
dataType: "string";
|
|
84
|
+
data: string;
|
|
85
|
+
driverParam: string;
|
|
86
|
+
notNull: true;
|
|
87
|
+
hasDefault: false;
|
|
88
|
+
isPrimaryKey: false;
|
|
89
|
+
isAutoincrement: false;
|
|
90
|
+
hasRuntimeDefault: false;
|
|
91
|
+
enumValues: undefined;
|
|
92
|
+
identity: undefined;
|
|
93
|
+
generated: undefined;
|
|
94
|
+
}>;
|
|
95
|
+
pk_json: import("drizzle-orm/pg-core").PgBuildColumn<"shape_row_tags", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
|
|
96
|
+
name: string;
|
|
97
|
+
tableName: "shape_row_tags";
|
|
98
|
+
dataType: "string";
|
|
99
|
+
data: string;
|
|
100
|
+
driverParam: string;
|
|
101
|
+
notNull: true;
|
|
102
|
+
hasDefault: false;
|
|
103
|
+
isPrimaryKey: false;
|
|
104
|
+
isAutoincrement: false;
|
|
105
|
+
hasRuntimeDefault: false;
|
|
106
|
+
enumValues: undefined;
|
|
107
|
+
identity: undefined;
|
|
108
|
+
generated: undefined;
|
|
109
|
+
}>;
|
|
110
|
+
tag: import("drizzle-orm/pg-core").PgBuildColumn<"shape_row_tags", import("drizzle-orm/pg-core").SetNotNull<import("drizzle-orm/pg-core").PgTextBuilder<[string, ...string[]]>>, {
|
|
111
|
+
name: string;
|
|
112
|
+
tableName: "shape_row_tags";
|
|
113
|
+
dataType: "string";
|
|
114
|
+
data: string;
|
|
115
|
+
driverParam: string;
|
|
116
|
+
notNull: true;
|
|
117
|
+
hasDefault: false;
|
|
118
|
+
isPrimaryKey: false;
|
|
119
|
+
isAutoincrement: false;
|
|
120
|
+
hasRuntimeDefault: false;
|
|
121
|
+
enumValues: undefined;
|
|
122
|
+
identity: undefined;
|
|
123
|
+
generated: undefined;
|
|
124
|
+
}>;
|
|
125
|
+
};
|
|
126
|
+
dialect: 'pg';
|
|
127
|
+
}>;
|
|
128
|
+
/** The (memoized) metadata-store `pgTable`s for a given metadata schema name. */
|
|
129
|
+
export declare function getMetadataTables(metadataSchema: string): MetadataTables;
|
|
130
|
+
export {};
|
|
131
|
+
//# sourceMappingURL=metadata-tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-tables.d.ts","sourceRoot":"","sources":["../../src/sync/metadata-tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAoB,MAAM,qBAAqB,CAAC;AAE/E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,qBAAqB,EAAE,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC;IAC9E,mFAAmF;IACnF,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;CAC7D;AAED,iBAAS,0BAA0B,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAQtE;AAED,iBAAS,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAa7D;AAID,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,cAAc,CAWxE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|