@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
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @pgxsinkit/client
|
|
2
|
+
|
|
3
|
+
The [pgxsinkit](https://pgxsinkit.github.io) client: `createSyncClient` stages writes
|
|
4
|
+
into a local PGlite overlay and a durable mutation journal, flushes them to the write
|
|
5
|
+
API, and subscribes to Electric shapes that land in local PGlite.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @pgxsinkit/client @pgxsinkit/contracts
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
See the [documentation](https://pgxsinkit.github.io) for the read and write paths.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A structured, versioned record of one client boot (ADR-0034). `reportVersion` is a contract number:
|
|
3
|
+
* additive fields keep it, a breaking reshape bumps it. All durations are milliseconds; all `*AtMs` are
|
|
4
|
+
* offsets from boot start (the `startedAt` epoch anchor is the only wall-clock value).
|
|
5
|
+
*/
|
|
6
|
+
export interface BootReport {
|
|
7
|
+
reportVersion: 1;
|
|
8
|
+
/** How the engine booted: the in-process client (bun/Node/fallback) or inside `defineSyncWorker`. */
|
|
9
|
+
mode: "in-process" | "worker";
|
|
10
|
+
/** Whether the caller proved the store a schemaless spare (the ADR-0032 S4 fresh-store hint). */
|
|
11
|
+
freshStore: boolean;
|
|
12
|
+
/** Whether the ADR-0032 S4 fetch/schema overlap was active for this boot. */
|
|
13
|
+
overlapPrefetch: boolean;
|
|
14
|
+
/** The registry fingerprint the store is provisioned under — the same value store-version reconcile stamps. */
|
|
15
|
+
registryFingerprint: string;
|
|
16
|
+
/** Epoch anchor (`Date.now()`) at boot start; every other duration/offset is monotonic relative to it. */
|
|
17
|
+
startedAt: number;
|
|
18
|
+
/** Boot start → `onInitialSync` (all eager groups caught up). */
|
|
19
|
+
totalMs: number;
|
|
20
|
+
/**
|
|
21
|
+
* Present only when the store was pre-provisioned (a spare's initdb ran off-thread before this boot
|
|
22
|
+
* adopted it); `null` otherwise. When present, `phases.pgliteCreateMs` is `null` — the create cost is
|
|
23
|
+
* reported here instead.
|
|
24
|
+
*/
|
|
25
|
+
provision: {
|
|
26
|
+
/** The spare's PGlite create (initdb) cost, paid at provision time. */
|
|
27
|
+
initdbMs: number;
|
|
28
|
+
/** How long the provisioned store sat ready before this boot adopted it. */
|
|
29
|
+
provisionedMsBeforeBoot: number;
|
|
30
|
+
} | null;
|
|
31
|
+
phases: {
|
|
32
|
+
/** PGlite create cost, or `null` when the store was adopted from a spare (see {@link BootReport.provision}). */
|
|
33
|
+
pgliteCreateMs: number | null;
|
|
34
|
+
schemaExecMs: number;
|
|
35
|
+
journalRecoveryMs: number;
|
|
36
|
+
storeVersionReconcileMs: number;
|
|
37
|
+
/**
|
|
38
|
+
* `startConfiguredSync`: stream/group construction wall. On an overlap boot (ADR-0032 S4,
|
|
39
|
+
* {@link BootReport.overlapPrefetch}) the early-started segment runs concurrently with schema/journal/
|
|
40
|
+
* reconcile, so this includes that shared wall. Structurally 0 when the boot is ready inside the
|
|
41
|
+
* sync-start call itself (zero eager groups / instant catch-up) — finalize runs before the phase closes.
|
|
42
|
+
*/
|
|
43
|
+
syncStartMs: number;
|
|
44
|
+
/** Sync-start done → last eager boot group ready. */
|
|
45
|
+
catchupMs: number;
|
|
46
|
+
/**
|
|
47
|
+
* Cumulative time in configured prepare hooks (`prepareLocalDbBeforeSchema` + `prepareLocalDb`), present
|
|
48
|
+
* only when at least one hook is configured. Not part of the required v1 shape (ADR-0034).
|
|
49
|
+
*/
|
|
50
|
+
prepareMs?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Per consistency GROUP, for the eager + promoted boot groups only (a lazily-activated-later group never
|
|
54
|
+
* appears — nor mutates a finalized report). Groups run concurrently, so `fetchMs`/`applyMs` are per-group
|
|
55
|
+
* wall SEGMENTS, not a partition of `totalMs`.
|
|
56
|
+
*/
|
|
57
|
+
groups: Array<{
|
|
58
|
+
groupKey: string;
|
|
59
|
+
/** Number of member tables (shapes) in the group. */
|
|
60
|
+
tables: number;
|
|
61
|
+
/** Offset from boot start when the group's streams started. */
|
|
62
|
+
startedAtMs: number;
|
|
63
|
+
/** Offset from boot start when the group reached its initial sync. */
|
|
64
|
+
readyAtMs: number;
|
|
65
|
+
/** Number of batch deliveries the group's stream chain received during boot catch-up. */
|
|
66
|
+
requests: number;
|
|
67
|
+
/** Number of change rows ingested during boot catch-up. */
|
|
68
|
+
rows: number;
|
|
69
|
+
/**
|
|
70
|
+
* Settle→next-delivery wall within this group's chain. On the single-threaded WASM host this absorbs
|
|
71
|
+
* OTHER groups' apply transactions and main-thread work between deliveries — read it as "time this
|
|
72
|
+
* group spent not applying", an upper bound on its network wait, not pure network cost.
|
|
73
|
+
*/
|
|
74
|
+
fetchMs: number;
|
|
75
|
+
/**
|
|
76
|
+
* Wall around this group's batch commits into PGlite. Includes waiting behind another group's
|
|
77
|
+
* transaction on the shared connection (single writer), so concurrent groups' `applyMs` can overlap.
|
|
78
|
+
*/
|
|
79
|
+
applyMs: number;
|
|
80
|
+
}>;
|
|
81
|
+
}
|
|
82
|
+
/** The phase durations the builder captures by key; `catchupMs` is derived, not a captured phase. */
|
|
83
|
+
type PhaseKey = "schemaExec" | "journalRecovery" | "storeVersionReconcile" | "syncStart";
|
|
84
|
+
/**
|
|
85
|
+
* The per-group accumulator the engine stamps as a boot group's stream chain delivers and applies (ADR-0034).
|
|
86
|
+
* One per consistency group (one `syncShapesToTables` call). Frozen at the group's ready edge so later live
|
|
87
|
+
* traffic never mutates a finalized report.
|
|
88
|
+
*/
|
|
89
|
+
export interface GroupBootStamp {
|
|
90
|
+
/** A batch was delivered to the group's subscribe callback (one response). `changeCount` = its change rows. */
|
|
91
|
+
onBatchDelivered: (changeCount: number) => void;
|
|
92
|
+
/** A commit transaction applied `ms` of work into PGlite for this group. */
|
|
93
|
+
onApply: (ms: number) => void;
|
|
94
|
+
/** The group reached its initial sync — stamp `readyAtMs` and freeze accumulation. */
|
|
95
|
+
markReady: () => void;
|
|
96
|
+
}
|
|
97
|
+
/** The seam `startConfiguredSync` uses to open a boot group's accumulator (implemented by the builder). */
|
|
98
|
+
export interface BootStampCollector {
|
|
99
|
+
beginGroup: (groupKey: string, tables: number) => GroupBootStamp;
|
|
100
|
+
}
|
|
101
|
+
/** Builds a {@link BootReport} across a boot and finalizes it exactly once. Owned by `createSyncClient`. */
|
|
102
|
+
export interface BootReportBuilder extends BootStampCollector {
|
|
103
|
+
/** The monotonic anchor (`performance.now()` at boot start) every offset is relative to. */
|
|
104
|
+
readonly bootStartPerf: number;
|
|
105
|
+
/**
|
|
106
|
+
* Time `fn`, always measuring (unlike `timeAsync`, which only measures when the rail is on) and capturing
|
|
107
|
+
* the duration into the report, while emitting the SAME rail lines `timeAsync` would. `key` is `null` for
|
|
108
|
+
* a prepare hook (folded into the optional `prepareMs`).
|
|
109
|
+
*/
|
|
110
|
+
phase: <T>(key: PhaseKey | "prepare", event: string, fn: () => Promise<T>, data?: Record<string, unknown>) => Promise<T>;
|
|
111
|
+
setPgliteCreateMs: (ms: number | null) => void;
|
|
112
|
+
setProvision: (provision: BootReport["provision"]) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Record `phases.syncStartMs` directly — for the ADR-0032 S4 overlap path, where sync construction is
|
|
115
|
+
* kicked off before schema exec (not wrapped in {@link BootReportBuilder.phase}) and has no rail line.
|
|
116
|
+
*/
|
|
117
|
+
setSyncStartMs: (ms: number) => void;
|
|
118
|
+
/** Capture the offset at which sync construction completed — the base for `catchupMs`. */
|
|
119
|
+
markSyncStartDone: () => void;
|
|
120
|
+
/** Build + store the report once (idempotent). Returns the report, or the already-built one on a re-call. */
|
|
121
|
+
finalize: () => BootReport;
|
|
122
|
+
/** The finalized report, or `null` before the first boot completes / after an early stop. */
|
|
123
|
+
report: () => BootReport | null;
|
|
124
|
+
}
|
|
125
|
+
/** Inputs known at boot start — the flags and identity the report carries verbatim. */
|
|
126
|
+
export interface BootReportInit {
|
|
127
|
+
mode: BootReport["mode"];
|
|
128
|
+
freshStore: boolean;
|
|
129
|
+
overlapPrefetch: boolean;
|
|
130
|
+
registryFingerprint: string;
|
|
131
|
+
}
|
|
132
|
+
export declare function createBootReportBuilder(init: BootReportInit): BootReportBuilder;
|
|
133
|
+
export {};
|
|
134
|
+
//# sourceMappingURL=boot-report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boot-report.d.ts","sourceRoot":"","sources":["../src/boot-report.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,CAAC,CAAC;IACjB,qGAAqG;IACrG,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC;IAC9B,iGAAiG;IACjG,UAAU,EAAE,OAAO,CAAC;IACpB,6EAA6E;IAC7E,eAAe,EAAE,OAAO,CAAC;IACzB,+GAA+G;IAC/G,mBAAmB,EAAE,MAAM,CAAC;IAC5B,0GAA0G;IAC1G,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,SAAS,EAAE;QACT,uEAAuE;QAC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ives (`flush` / `reconcile` / `retryFailed`) stay public and manual.
|
|
5
|
+
* This driver is the *scheduling-policy seam*: the app decides WHEN to converge (online?
|
|
6
|
+
* foregrounded? on power?) and how it learns those conditions, while the library owns the
|
|
7
|
+
* convergence pass and the congestion policy (jittered backoff + attempt cap, already in the
|
|
8
|
+
* mutation runtime). Pass nothing to `createSyncClient` → fully manual, today's behaviour.
|
|
9
|
+
*
|
|
10
|
+
* A pass is `flush` → `reconcile`. It deliberately does NOT call `retryFailed`: `flush`
|
|
11
|
+
* already re-attempts `failed` mutations whose `next_retry_at_us` backoff has elapsed, so a
|
|
12
|
+
* pass leaves the jittered backoff intact. Calling `retryFailed` on every pass would reset
|
|
13
|
+
* every failed mutation to "due now" and, under a short trigger interval, burn the whole
|
|
14
|
+
* attempt budget during a transient outage and quarantine writes prematurely. `retryFailed`
|
|
15
|
+
* stays a manual, user-initiated primitive ("retry my failed writes now").
|
|
16
|
+
*/
|
|
17
|
+
/** The mechanism primitives a convergence pass schedules. */
|
|
18
|
+
export interface ConvergenceClient {
|
|
19
|
+
flush: () => Promise<void>;
|
|
20
|
+
reconcile: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The scheduling-policy seam. Browser (`online` / `visibilitychange`) and React Native
|
|
24
|
+
* (`AppState` / `NetInfo`) are two genuine adapters — which is what earns this its place as a
|
|
25
|
+
* seam rather than being inlined.
|
|
26
|
+
*/
|
|
27
|
+
export interface ConvergenceTrigger {
|
|
28
|
+
/** Register a callback fired whenever the app wants a convergence attempt; returns an unsubscribe. */
|
|
29
|
+
subscribe: (onSignal: () => void) => () => void;
|
|
30
|
+
/** Whether a convergence pass should run right now (e.g. online and foregrounded). */
|
|
31
|
+
shouldConverge: () => boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface ConvergenceDriverOptions {
|
|
34
|
+
client: ConvergenceClient;
|
|
35
|
+
trigger: ConvergenceTrigger;
|
|
36
|
+
/** Invoked after each convergence pass with the error it raised, or `null` on success. */
|
|
37
|
+
onPass?: (error: unknown) => void;
|
|
38
|
+
}
|
|
39
|
+
export interface ConvergenceDriver {
|
|
40
|
+
start: () => void;
|
|
41
|
+
/**
|
|
42
|
+
* Stop scheduling and **await any in-flight pass** before resolving, so a caller can then
|
|
43
|
+
* safely close or wipe the underlying database without a pass racing against it. Idempotent.
|
|
44
|
+
*/
|
|
45
|
+
stop: () => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Request a convergence pass now — the event-driven path. The client calls this the moment a
|
|
48
|
+
* mutation is enqueued, so a local write flushes immediately instead of waiting for the trigger's
|
|
49
|
+
* next interval tick. Coalesced exactly like a trigger signal (one pass at a time; a request mid-pass
|
|
50
|
+
* queues a single follow-up) and still gated by `shouldConverge()`, so a write made while offline
|
|
51
|
+
* stages without flushing. With this, the trigger's interval is only a fallback (retries/recovery),
|
|
52
|
+
* which lets it run far less often — the interval, not real convergence, is what costs idle CPU.
|
|
53
|
+
*/
|
|
54
|
+
requestPass: () => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Drive convergence from a {@link ConvergenceTrigger}. Each signal runs at most one pass at a
|
|
58
|
+
* time (`flush` → `reconcile`); a signal arriving mid-pass coalesces into a single follow-up
|
|
59
|
+
* pass, so a burst of triggers never stampedes the server (the per-mutation backoff in the
|
|
60
|
+
* runtime handles the rest).
|
|
61
|
+
*/
|
|
62
|
+
export declare function createConvergenceDriver(options: ConvergenceDriverOptions): ConvergenceDriver;
|
|
63
|
+
/**
|
|
64
|
+
* Browser convergence trigger: fires on `online`, `visibilitychange`, and a fallback interval,
|
|
65
|
+
* and converges only while online and not backgrounded. The adapter most apps use.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createBrowserConvergenceTrigger(options?: {
|
|
68
|
+
intervalMs?: number;
|
|
69
|
+
}): ConvergenceTrigger;
|
|
70
|
+
/**
|
|
71
|
+
* Interval convergence trigger: fires on a fixed cadence and always converges. The minimal
|
|
72
|
+
* non-browser adapter — usable directly in tests/servers and the base a React Native
|
|
73
|
+
* `AppState`/`NetInfo` adapter builds on — which is the second adapter that proves the seam.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createIntervalConvergenceTrigger(intervalMs: number): ConvergenceTrigger;
|
|
76
|
+
//# sourceMappingURL=convergence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convergence.d.ts","sourceRoot":"","sources":["../src/convergence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,6DAA6D;AAC7D,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,sGAAsG;IACtG,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;IAChD,sFAAsF;IACtF,cAAc,EAAE,MAAM,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,EAAE,kBAAkB,CAAC;IAC5B,0FAA0F;IAC1F,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;OAGG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B;;;;;;;OAOG;IACH,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAsE5F;AAaD;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,kBAAkB,CAqBzG;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,MAAM,GAAG,kBAAkB,CAavF"}
|
package/dist/debug.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sink that receives every `syncDebug` line (event, the worker's monotonic stamp, optional data),
|
|
3
|
+
* INDEPENDENT of the local `__pgxsinkitDebug` console gate. This is the seam `defineSyncWorker` installs
|
|
4
|
+
* to forward the debug rail to tabs (ADR-0032 decision 7): a SharedWorker's own console is invisible
|
|
5
|
+
* (`chrome://inspect`), so lines must cross the bridge and each tab re-prints them gated on ITS OWN flag.
|
|
6
|
+
* Unset by default → no forwarding and zero cost on the in-process path.
|
|
7
|
+
*/
|
|
8
|
+
type SyncDebugSink = (event: string, stamp: number, data?: Record<string, unknown>) => void;
|
|
9
|
+
/** Install (or clear, with `undefined`) the debug-rail sink. Idempotent; `defineSyncWorker` owns it. */
|
|
10
|
+
export declare function setSyncDebugSink(sink: SyncDebugSink | undefined): void;
|
|
11
|
+
/**
|
|
12
|
+
* Log one timestamped event. Prints to the console only when `globalThis.__pgxsinkitDebug` is on, but ALSO
|
|
13
|
+
* feeds any installed {@link setSyncDebugSink} sink (so the worker can forward the rail to tabs even when the
|
|
14
|
+
* worker's own console gate is off). No sink AND not enabled → an early return, so the off-path pays nothing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function syncDebug(event: string, data?: Record<string, unknown>): void;
|
|
17
|
+
/**
|
|
18
|
+
* Wrap a `fetch` so every ShapeStream request (the Electric read-path long-poll/catch-up) emits a start
|
|
19
|
+
* line (shape/table, offset, live — derived from the request URL params) and a completion line (status,
|
|
20
|
+
* ms, and whether the response is up-to-date). Passthrough when instrumentation is off: the early return
|
|
21
|
+
* runs before any URL parsing, so the off-path pays nothing per request beyond this closure itself.
|
|
22
|
+
*
|
|
23
|
+
* Inject it as a ShapeStream `fetchClient`; pass the stream's existing `fetchClient` (if any) as the base
|
|
24
|
+
* so the instrumentation composes rather than replaces.
|
|
25
|
+
*/
|
|
26
|
+
export declare function instrumentShapeFetch(baseFetch?: typeof fetch): typeof fetch;
|
|
27
|
+
/**
|
|
28
|
+
* Run `fn`, logging `<event> done` with its wall-clock duration (and any extra `data`). When
|
|
29
|
+
* instrumentation is off this is a thin pass-through with no logging and no timing overhead beyond the
|
|
30
|
+
* call itself. Returns whatever `fn` returns.
|
|
31
|
+
*/
|
|
32
|
+
export declare function timeAsync<T>(event: string, fn: () => Promise<T>, data?: Record<string, unknown>): Promise<T>;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=debug.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAiBA;;;;;;GAMG;AACH,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;AAG5F,wGAAwG;AACxG,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAa7E;AAYD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,GAAE,OAAO,KAAa,GAAG,OAAO,KAAK,CA+DlF;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CASlH"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { MutationDiagnostics } from "@pgxsinkit/contracts";
|
|
2
|
+
import { type DataExportReport } from "./export-store";
|
|
3
|
+
import type { ClientPGlite } from "./index";
|
|
4
|
+
/** The default drain budget: actively flush + await the convergence barrier for up to 15s before failing. */
|
|
5
|
+
export declare const DEFAULT_DRAIN_TIMEOUT_MS = 15000;
|
|
6
|
+
/** The drain guard's tuning: the wait budget for reaching a fully-drained journal. */
|
|
7
|
+
export interface DrainJournalOptions {
|
|
8
|
+
/** Milliseconds to flush + await convergence before throwing {@link DataExportDrainError}. */
|
|
9
|
+
timeoutMs: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* `exportData`'s drain policy: the default `{ timeoutMs }` guard, or `false` — the explicit escape hatch
|
|
13
|
+
* that skips the drain and exports the SYNCED state as-is (unflushed local writes silently absent). A plain
|
|
14
|
+
* JSON shape, so it survives structured clone across the worker bridge unchanged.
|
|
15
|
+
*/
|
|
16
|
+
export type DrainJournalOption = DrainJournalOptions | false;
|
|
17
|
+
/** Options for {@link SyncClient.exportData}. Plain JSON — structured-clone-safe across the worker bridge. */
|
|
18
|
+
export interface DataExportOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Override the generated artefact file name. When omitted, the name is `<storeId>-<timestamp>-data.sql`,
|
|
21
|
+
* where `storeId` is a filesystem-safe derivation of the store path (see `deriveStoreId`).
|
|
22
|
+
*/
|
|
23
|
+
fileName?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The drain guard (ADR-0035 decision 3). Default `{ timeoutMs: 15_000 }`: fail fast on non-drainable
|
|
26
|
+
* states, else flush + await convergence up to the budget. `false` is the escape hatch — export synced
|
|
27
|
+
* state as-is, skipping the drain entirely.
|
|
28
|
+
*/
|
|
29
|
+
drainJournal?: DrainJournalOption;
|
|
30
|
+
}
|
|
31
|
+
/** The SQL artefact + its report — the resolved value of {@link SyncClient.exportData}. */
|
|
32
|
+
export interface DataExportResult {
|
|
33
|
+
/** The portable SQL as a named `File` (`application/sql`), loadable into a vanilla Postgres. */
|
|
34
|
+
file: File;
|
|
35
|
+
/** The structured record of the export (ADR-0035). */
|
|
36
|
+
report: DataExportReport;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Thrown when `exportData`'s strict drain cannot produce a drained journal (ADR-0035 decision 3). Carries
|
|
40
|
+
* the `MutationDiagnostics` snapshot at the moment of failure so the caller sees exactly what blocked the
|
|
41
|
+
* export, and a `reason` distinguishing the two failure modes:
|
|
42
|
+
*
|
|
43
|
+
* - `"non-drainable-state"` — `failed`/`quarantined`/`conflicted` rows are present (either pre-existing, so
|
|
44
|
+
* the failure is immediate with no waiting, or a mid-drain `flush()` failure that moved rows to `failed`);
|
|
45
|
+
* these terminal states never drain on their own, so waiting is pointless.
|
|
46
|
+
* - `"timeout"` — drainable rows (`pending`/`sending`/`acked`) did not reach fully-drained within the
|
|
47
|
+
* budget; most commonly `acked` writes whose synced echo never arrived (an offline device, a stalled
|
|
48
|
+
* read path).
|
|
49
|
+
*
|
|
50
|
+
* A distinct type — not a bare `Error` — so a caller can `instanceof`-branch a drain failure from a genuine
|
|
51
|
+
* export failure, inspect the diagnostics, and choose the escape hatch (`drainJournal: false`) or the
|
|
52
|
+
* lossless store backup instead.
|
|
53
|
+
*/
|
|
54
|
+
export declare class DataExportDrainError extends Error {
|
|
55
|
+
/** Which drain failure occurred (see the class doc). */
|
|
56
|
+
readonly reason: "non-drainable-state" | "timeout";
|
|
57
|
+
/** The mutation diagnostics at the moment the drain gave up — the evidence of what was unflushed. */
|
|
58
|
+
readonly diagnostics: MutationDiagnostics;
|
|
59
|
+
constructor(reason: "non-drainable-state" | "timeout", diagnostics: MutationDiagnostics);
|
|
60
|
+
}
|
|
61
|
+
/** The dependencies {@link performDataExport} needs from the owning client — narrow, so it is unit-testable. */
|
|
62
|
+
export interface DataExportDeps {
|
|
63
|
+
/** The live store to checkpoint and dump (the clone source; the live engine is never suspended). */
|
|
64
|
+
pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">;
|
|
65
|
+
/** The Mutation diagnostics seam (`client.diagnostics().mutation` / `readMutationStats`). */
|
|
66
|
+
readMutationStats: () => Promise<MutationDiagnostics>;
|
|
67
|
+
/** The optimistic flush (`client.flush()`), driven during the drain to send drainable rows. */
|
|
68
|
+
flush: () => Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* The `-t` allowlist: the schema-qualified physical synced table names, resolved from the registry by the
|
|
71
|
+
* SAME projection the DDL generator uses (`collectDataExportSyncedTableNames`) — never re-derived here.
|
|
72
|
+
*/
|
|
73
|
+
syncedTableNames: string[];
|
|
74
|
+
/**
|
|
75
|
+
* The generated enum DDL header (`buildDataExportEnumHeaderSql`) — the `CREATE TYPE` statements for the
|
|
76
|
+
* enums the exported tables reference, which `pg_dump -t` omits. `""` when no exported table uses an enum.
|
|
77
|
+
*/
|
|
78
|
+
enumHeaderSql: string;
|
|
79
|
+
/**
|
|
80
|
+
* The clone-cleanup SQL (`buildDataExportCloneCleanupSql`) run on the throwaway clone before `pg_dump -t`,
|
|
81
|
+
* dropping the reconcile triggers `-t` would otherwise pull into the artefact (referencing pgxsinkit
|
|
82
|
+
* functions the export excludes). `""` when the registry has no writable owning table.
|
|
83
|
+
*/
|
|
84
|
+
cloneCleanupSql: string;
|
|
85
|
+
/**
|
|
86
|
+
* The store's configured plain store PATH (ADR-0036) — reduced to the `storeId` in the default artefact
|
|
87
|
+
* file name. The resolved PGlite dataDir URL is deliberately NOT used: internal plumbing, never an
|
|
88
|
+
* artefact-name seed.
|
|
89
|
+
*/
|
|
90
|
+
storePath?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Run a data export (ADR-0035): drain the journal (unless the escape hatch is set) → throwaway-clone
|
|
94
|
+
* `pg_dump -t` per synced table → concatenate the comment + enum DDL header → assemble the report. The
|
|
95
|
+
* caller (`createSyncClient`) awaits engine-ready and enters the lifecycle slot BEFORE calling this, so the
|
|
96
|
+
* whole drain+dump runs under the store's single lifecycle slot (the drain must sit inside it — see the
|
|
97
|
+
* module header).
|
|
98
|
+
*/
|
|
99
|
+
export declare function performDataExport(deps: DataExportDeps, options?: DataExportOptions): Promise<DataExportResult>;
|
|
100
|
+
//# sourceMappingURL=export-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-data.d.ts","sourceRoot":"","sources":["../src/export-data.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,EAAoB,KAAK,gBAAgB,EAAwB,MAAM,gBAAgB,CAAC;AAC/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,6GAA6G;AAC7G,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAI/C,sFAAsF;AACtF,MAAM,WAAW,mBAAmB;IAClC,8FAA8F;IAC9F,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,GAAG,KAAK,CAAC;AAE7D,8GAA8G;AAC9G,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAC;CACnC;AAED,2FAA2F;AAC3F,MAAM,WAAW,gBAAgB;IAC/B,gGAAgG;IAChG,IAAI,EAAE,IAAI,CAAC;IACX,sDAAsD;IACtD,MAAM,EAAE,gBAAgB,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,GAAG,SAAS,CAAC;IACnD,qGAAqG;IACrG,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAE1C,YAAY,MAAM,EAAE,qBAAqB,GAAG,SAAS,EAAE,WAAW,EAAE,mBAAmB,EAiBtF;CACF;AAED,gHAAgH;AAChH,MAAM,WAAW,cAAc;IAC7B,oGAAoG;IACpG,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC;IACnD,6FAA6F;IAC7F,iBAAiB,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACtD,+FAA+F;IAC/F,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B;;;OAGG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAsFD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,gBAAgB,CAAC,CA6D3B"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import type { MutationDiagnostics } from "@pgxsinkit/contracts";
|
|
3
|
+
import { type DiagnosticDumpReport } from "./export-store";
|
|
4
|
+
import type { ClientPGlite } from "./index";
|
|
5
|
+
/** Options for {@link SyncClient.exportDiagnostics}. */
|
|
6
|
+
export interface DiagnosticExportOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Override the generated artefact file name. When omitted, the name is
|
|
9
|
+
* `<storeId>-<timestamp>-diagnostics.sql`, where `storeId` is a filesystem-safe derivation of the store
|
|
10
|
+
* path (see `deriveStoreId`).
|
|
11
|
+
*/
|
|
12
|
+
fileName?: string;
|
|
13
|
+
}
|
|
14
|
+
/** The SQL artefact + its report — the resolved value of {@link SyncClient.exportDiagnostics}. */
|
|
15
|
+
export interface DiagnosticExportResult {
|
|
16
|
+
/** The `pg_dump` output as a named `File` (`application/sql`), loadable into a vanilla Postgres. */
|
|
17
|
+
file: File;
|
|
18
|
+
/** The structured record of the export (ADR-0035). */
|
|
19
|
+
report: DiagnosticDumpReport;
|
|
20
|
+
}
|
|
21
|
+
/** The dependencies {@link performDiagnosticExport} needs from the owning client — narrow, so it is unit-testable. */
|
|
22
|
+
export interface DiagnosticExportDeps {
|
|
23
|
+
/** The live store to checkpoint and dump (the clone source; the live engine is never suspended). */
|
|
24
|
+
pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">;
|
|
25
|
+
/** The Mutation diagnostics seam (`client.diagnostics().mutation` / `readMutationStats`). */
|
|
26
|
+
readMutationStats: () => Promise<MutationDiagnostics>;
|
|
27
|
+
/**
|
|
28
|
+
* The store's configured plain store PATH (ADR-0036) — reduced to the `storeId` in the default artefact
|
|
29
|
+
* file name. The resolved PGlite dataDir URL is deliberately NOT used: it is internal plumbing and must
|
|
30
|
+
* not leak into an artefact name as something to imitate.
|
|
31
|
+
*/
|
|
32
|
+
storePath?: string;
|
|
33
|
+
}
|
|
34
|
+
/** The four extra phase walls the throwaway-clone pipeline adds on top of the shared checkpoint/dump pair. */
|
|
35
|
+
export interface CloneDumpPhases {
|
|
36
|
+
/** Offset from `startPerf` when the internal `dumpDataDir` (the clone's source) began. */
|
|
37
|
+
dumpStartedAtMs: number;
|
|
38
|
+
/** `dumpDataDir` wall — the uncompressed internal tarball the throwaway clone boots from (`compression: "none"`). */
|
|
39
|
+
dumpMs: number;
|
|
40
|
+
/** Offset from `startPerf` when the `CHECKPOINT` began. */
|
|
41
|
+
checkpointStartedAtMs: number;
|
|
42
|
+
/** `CHECKPOINT` wall — flushing dirty buffers before the internal datadir dump the clone consumes. */
|
|
43
|
+
checkpointMs: number;
|
|
44
|
+
/** Offset from `startPerf` when the throwaway clone's `PGlite.create({ loadDataDir })` began. */
|
|
45
|
+
cloneBootStartedAtMs: number;
|
|
46
|
+
/** Clone boot wall — booting the memory-backed throwaway from the internal dump. */
|
|
47
|
+
cloneBootMs: number;
|
|
48
|
+
/** Offset from `startPerf` when `pg_dump` began running against the clone. */
|
|
49
|
+
pgDumpStartedAtMs: number;
|
|
50
|
+
/** `pg_dump` wall — the WASM `pg_dump` reading the clone out to SQL. */
|
|
51
|
+
pgDumpMs: number;
|
|
52
|
+
}
|
|
53
|
+
/** The raw SQL bytes plus the pipeline phase walls — {@link runThrowawayCloneDump}'s result. */
|
|
54
|
+
export interface CloneDumpResult {
|
|
55
|
+
/** The `pg_dump` output bytes (unwrapped from pglite-tools' `File` polyfill). */
|
|
56
|
+
sqlBytes: Uint8Array<ArrayBuffer>;
|
|
57
|
+
/** The pipeline phase timings, all offset from the caller's `startPerf` anchor. */
|
|
58
|
+
phases: CloneDumpPhases;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The throwaway-clone dump core shared by BOTH `pgDump` exports (ADR-0035 addendum): (1) a LIVE datadir dump
|
|
62
|
+
* of the running store (`compression: "none"` — the clone consumes the bytes immediately, so gzip+gunzip is
|
|
63
|
+
* pure waste); (2) a memory-backed THROWAWAY PGlite booted from it via `loadDataDir` — engine-less, no
|
|
64
|
+
* `live` extension, nothing `pg_dump`'s `DEALLOCATE ALL` can corrupt; (3) `pg_dump` against the throwaway
|
|
65
|
+
* with the caller's `args` (none for a diagnostic dump; the `-t` allowlist + `--no-owner` for a data
|
|
66
|
+
* export); (4) discard the clone in a `finally`. Factored out so `performDiagnosticExport` and
|
|
67
|
+
* `performDataExport` cannot drift on the clone plumbing, the memory-scheme selection, or the timing house
|
|
68
|
+
* style — the ONLY differences between the two dumps are the `pg_dump` args and the artefact assembly.
|
|
69
|
+
*
|
|
70
|
+
* `@electric-sql/pglite-tools` is loaded ONLY via the dynamic `import()` here (ADR-0035 decision 7): its
|
|
71
|
+
* ~700 kB `pg_dump.wasm` (+ ~100 kB JS) stays off boot and off every non-exporting bundle.
|
|
72
|
+
*/
|
|
73
|
+
export interface CloneDumpOptions {
|
|
74
|
+
/** The `pg_dump` args (none for a diagnostic dump; `-t` allowlist + `--no-owner` for a data export). */
|
|
75
|
+
pgDumpArgs?: string[];
|
|
76
|
+
/**
|
|
77
|
+
* A hook run on the throwaway clone AFTER boot, BEFORE `pg_dump` — its one legitimate window to mutate the
|
|
78
|
+
* clone (which is fully owned and discarded straight after). The data export uses it to drop the reconcile
|
|
79
|
+
* triggers `pg_dump -t` would otherwise pull into the artefact (see `buildDataExportCloneCleanupSql`); a
|
|
80
|
+
* diagnostic dump passes none (it wants the store verbatim).
|
|
81
|
+
*/
|
|
82
|
+
prepareClone?: (clone: PGlite) => Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
export declare function runThrowawayCloneDump(pglite: Pick<ClientPGlite, "exec" | "dumpDataDir">, startPerf: number, options?: CloneDumpOptions): Promise<CloneDumpResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Run a diagnostic dump (ADR-0035): live datadir dump → memory-backed throwaway clone → `pg_dump` → discard
|
|
87
|
+
* the clone → assemble the report. The caller (`createSyncClient`) awaits engine-ready and enters the
|
|
88
|
+
* lifecycle slot BEFORE calling this, exactly as it does for the store backup — kept out of here so the
|
|
89
|
+
* helper stays a pure "do the dump" unit.
|
|
90
|
+
*/
|
|
91
|
+
export declare function performDiagnosticExport(deps: DiagnosticExportDeps, options?: DiagnosticExportOptions): Promise<DiagnosticExportResult>;
|
|
92
|
+
//# sourceMappingURL=export-dump.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-dump.d.ts","sourceRoot":"","sources":["../src/export-dump.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAAoB,KAAK,oBAAoB,EAA4C,MAAM,gBAAgB,CAAC;AACvH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,wDAAwD;AACxD,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAA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