@pgxsinkit/client 0.2.7 → 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 +4 -5
- 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/src/debug.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
//
|
|
5
5
|
// Enable it from the browser console (`globalThis.__pgxsinkitDebug = true`) — or set it before the
|
|
6
6
|
// client boots; the board's dev build turns it on automatically. Each line is stamped with a monotonic
|
|
7
|
-
// millisecond clock so the gaps between phases (enqueue → flush → server ack →
|
|
7
|
+
// millisecond clock so the gaps between phases (enqueue → flush → server ack → stream echo →
|
|
8
8
|
// overlay clear → live-query render) can be read straight off the console.
|
|
9
9
|
|
|
10
10
|
interface DebugGlobal {
|
|
@@ -50,90 +50,6 @@ export function syncDebug(event: string, data?: Record<string, unknown>): void {
|
|
|
50
50
|
syncDebugSink?.(event, stamp, data);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
/** The request URL of a `fetch` first argument, in any of its accepted forms; undefined if unreadable. */
|
|
54
|
-
function fetchInputUrl(input: Parameters<typeof fetch>[0]): string | undefined {
|
|
55
|
-
if (typeof input === "string") return input;
|
|
56
|
-
if (input instanceof URL) return input.toString();
|
|
57
|
-
if (typeof input === "object" && input !== null && "url" in input) {
|
|
58
|
-
return (input as { url: string }).url;
|
|
59
|
-
}
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Wrap a `fetch` so every ShapeStream request (the Electric read-path long-poll/catch-up) emits a start
|
|
65
|
-
* line (shape/table, offset, live — derived from the request URL params) and a completion line (status,
|
|
66
|
-
* ms, and whether the response is up-to-date). Passthrough when instrumentation is off: the early return
|
|
67
|
-
* runs before any URL parsing, so the off-path pays nothing per request beyond this closure itself.
|
|
68
|
-
*
|
|
69
|
-
* Inject it as a ShapeStream `fetchClient`; pass the stream's existing `fetchClient` (if any) as the base
|
|
70
|
-
* so the instrumentation composes rather than replaces.
|
|
71
|
-
*/
|
|
72
|
-
export function instrumentShapeFetch(baseFetch: typeof fetch = fetch): typeof fetch {
|
|
73
|
-
const wrapped = (input: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]): Promise<Response> => {
|
|
74
|
-
if (!isEnabled()) return baseFetch(input, init);
|
|
75
|
-
const url = fetchInputUrl(input);
|
|
76
|
-
const params = url ? new URL(url).searchParams : undefined;
|
|
77
|
-
// Derive the shape identity ONCE and name it on BOTH the start and done lines, so a start/done pair
|
|
78
|
-
// is readable without cross-referencing timing (multiple shapes' requests interleave on the rail).
|
|
79
|
-
const shape = params?.get("table") ?? undefined;
|
|
80
|
-
const live = params?.get("live") === "true";
|
|
81
|
-
const offset = params?.get("offset") ?? undefined;
|
|
82
|
-
// The handle chain is the backlog-0001 forensic: WHICH handle each request carried, which one the
|
|
83
|
-
// response minted, and whether the stale-cache ladder's params were on the wire — so a
|
|
84
|
-
// dead-handle-served-N-times storm reads straight off the rail (same responseHandle across busted
|
|
85
|
-
// attempts) instead of needing a network-tab capture at the moment of recurrence.
|
|
86
|
-
const requestHandle = params?.get("handle") ?? undefined;
|
|
87
|
-
const cacheBuster = params?.has("cache-buster") ?? false;
|
|
88
|
-
const expiredHandle = params?.get("expired_handle") ?? undefined;
|
|
89
|
-
// The whole request identity rides in ONE compact string field: Chrome's console preview truncates
|
|
90
|
-
// object previews at ~5 properties, and a captured log (the only artifact of a live recurrence) keeps
|
|
91
|
-
// just the preview — separate fields silently vanish exactly when they matter (backlog 0001).
|
|
92
|
-
const cursor = params?.get("cursor") ?? undefined;
|
|
93
|
-
const req = [
|
|
94
|
-
`${shape ?? "?"}@${offset ?? "?"}`,
|
|
95
|
-
live ? "live" : "catchup",
|
|
96
|
-
requestHandle ? `h=${requestHandle}` : "no-handle",
|
|
97
|
-
// The live-cycle cursor is Electric's CDN-collapse defense — its absence or non-advancement on
|
|
98
|
-
// live polls is itself a finding (backlog 0001).
|
|
99
|
-
cursor ? `c=${cursor}` : live ? "NO-CURSOR" : "",
|
|
100
|
-
cacheBuster ? "BUSTED" : "",
|
|
101
|
-
expiredHandle ? `expired=${expiredHandle}` : "",
|
|
102
|
-
]
|
|
103
|
-
.filter(Boolean)
|
|
104
|
-
.join(" ");
|
|
105
|
-
syncDebug("shape request start", { req });
|
|
106
|
-
const startedAt = now();
|
|
107
|
-
return baseFetch(input, init).then((response) => {
|
|
108
|
-
// Same single-string discipline for the response half: status/ms stay first-class (they are what
|
|
109
|
-
// rail readers scan), the forensic chain (up-to-date, minted handle, end offset) folds into `resp`.
|
|
110
|
-
const responseHandle = response.headers.get("electric-handle");
|
|
111
|
-
const responseOffset = response.headers.get("electric-offset");
|
|
112
|
-
const responseCursor = response.headers.get("electric-cursor");
|
|
113
|
-
const age = response.headers.get("age");
|
|
114
|
-
const resp = [
|
|
115
|
-
response.headers.has("electric-up-to-date") ? "up-to-date" : "",
|
|
116
|
-
responseHandle && responseHandle !== requestHandle ? `minted h=${responseHandle}` : "",
|
|
117
|
-
responseOffset ? `end=${responseOffset}` : "",
|
|
118
|
-
responseCursor ? `c=${responseCursor}` : "",
|
|
119
|
-
age ? `age=${age}` : "",
|
|
120
|
-
]
|
|
121
|
-
.filter(Boolean)
|
|
122
|
-
.join(" ");
|
|
123
|
-
syncDebug("shape request done", {
|
|
124
|
-
req,
|
|
125
|
-
status: response.status,
|
|
126
|
-
ms: Math.round(now() - startedAt),
|
|
127
|
-
...(resp ? { resp } : {}),
|
|
128
|
-
});
|
|
129
|
-
return response;
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
// `typeof fetch` (Bun's global) carries a `preconnect` member the wrapper neither has nor needs — the
|
|
133
|
-
// ShapeStream only ever invokes fetchClient as a plain fetch — so the shape-compatible cast is safe.
|
|
134
|
-
return wrapped as typeof fetch;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
53
|
/**
|
|
138
54
|
* Run `fn`, logging `<event> done` with its wall-clock duration (and any extra `data`). When
|
|
139
55
|
* instrumentation is off this is a thin pass-through with no logging and no timing overhead beyond the
|
package/src/export-dump.ts
CHANGED
|
@@ -143,8 +143,9 @@ export async function runThrowawayCloneDump(
|
|
|
143
143
|
|
|
144
144
|
// Step 2 — boot the throwaway. Memory-backed via the resolution module's SCHEME selection (ADR-0036
|
|
145
145
|
// decision 5: NEVER PGlite's explicit `fs: new MemoryFS()` — on 0.5.4 a `dumpDataDir` from an explicit-fs
|
|
146
|
-
// instance silently omits post-initdb relation files). No extensions
|
|
147
|
-
// the clone exists only to be read out by `pg_dump`, and `DEALLOCATE ALL` has nothing
|
|
146
|
+
// instance silently omits post-initdb relation files). No extensions at all — not even `live` — and no
|
|
147
|
+
// sync runtime: the clone exists only to be read out by `pg_dump`, and `DEALLOCATE ALL` has nothing
|
|
148
|
+
// here to corrupt.
|
|
148
149
|
const cloneDataDir = resolveStoreDataDir(nextCloneStorePath(), "memory");
|
|
149
150
|
const cloneBootStartedAtMs = nowMs() - startPerf;
|
|
150
151
|
const cloneBootStartPerf = nowMs();
|