@rocicorp/zero 1.11.0-canary.4 → 1.11.0-canary.6
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/out/replicache/src/kv/expo-sqlite/store.d.ts.map +1 -1
- package/out/replicache/src/kv/expo-sqlite/store.js +27 -4
- package/out/replicache/src/kv/expo-sqlite/store.js.map +1 -1
- package/out/replicache/src/kv/sqlite-store.d.ts +11 -0
- package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -1
- package/out/replicache/src/kv/sqlite-store.js +43 -3
- package/out/replicache/src/kv/sqlite-store.js.map +1 -1
- package/out/shared/src/error.d.ts +11 -0
- package/out/shared/src/error.d.ts.map +1 -1
- package/out/shared/src/error.js +35 -1
- package/out/shared/src/error.js.map +1 -1
- package/out/shared/src/map.d.ts +7 -2
- package/out/shared/src/map.d.ts.map +1 -1
- package/out/shared/src/map.js.map +1 -1
- package/out/zero/package.js +2 -2
- package/out/zero/package.js.map +1 -1
- package/out/zero-cache/src/config/normalize.d.ts.map +1 -1
- package/out/zero-cache/src/config/normalize.js +7 -1
- package/out/zero-cache/src/config/normalize.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +9 -0
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +21 -0
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/server/change-streamer.js +15 -6
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/main.d.ts.map +1 -1
- package/out/zero-cache/src/server/main.js +8 -1
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/mutator.js +2 -0
- package/out/zero-cache/src/server/mutator.js.map +1 -1
- package/out/zero-cache/src/server/reaper.d.ts.map +1 -1
- package/out/zero-cache/src/server/reaper.js +2 -0
- package/out/zero-cache/src/server/reaper.js.map +1 -1
- package/out/zero-cache/src/server/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/server/replicator.js +2 -0
- package/out/zero-cache/src/server/replicator.js.map +1 -1
- package/out/zero-cache/src/server/runner/zero-dispatcher.d.ts.map +1 -1
- package/out/zero-cache/src/server/runner/zero-dispatcher.js +3 -0
- package/out/zero-cache/src/server/runner/zero-dispatcher.js.map +1 -1
- package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
- package/out/zero-cache/src/server/syncer.js +2 -0
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.js +68 -8
- package/out/zero-cache/src/services/change-source/pg/schema/index-predicate.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-log-codec.d.ts +19 -4
- package/out/zero-cache/src/services/change-streamer/change-log-codec.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-log-codec.js +28 -8
- package/out/zero-cache/src/services/change-streamer/change-log-codec.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +3 -0
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +3 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts +6 -0
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +86 -51
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.js +4 -4
- package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.d.ts +6 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.js +27 -9
- package/out/zero-cache/src/services/change-streamer/sqlite-change-log-writer.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.d.ts +2 -2
- package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js +6 -5
- package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
- package/out/zero-cache/src/services/litestream/litestream-checkpointer.js +50 -23
- package/out/zero-cache/src/services/litestream/litestream-checkpointer.js.map +1 -1
- package/out/zero-cache/src/services/profz.d.ts +7 -0
- package/out/zero-cache/src/services/profz.d.ts.map +1 -0
- package/out/zero-cache/src/services/profz.js +99 -0
- package/out/zero-cache/src/services/profz.js.map +1 -0
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.d.ts +5 -4
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.js +20 -22
- package/out/zero-cache/src/services/replicator/change-log-stream-writer.js.map +1 -1
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.d.ts +6 -6
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.js +19 -14
- package/out/zero-cache/src/services/replicator/sqlite-change-log-observability.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts +17 -0
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js +59 -0
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.d.ts +51 -0
- package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.d.ts.map +1 -0
- package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.js +78 -0
- package/out/zero-cache/src/services/view-syncer/hydration-circuit-breaker.js.map +1 -0
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +18 -6
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +154 -6
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/processes.d.ts +24 -0
- package/out/zero-cache/src/types/processes.d.ts.map +1 -1
- package/out/zero-cache/src/types/processes.js +25 -1
- package/out/zero-cache/src/types/processes.js.map +1 -1
- package/out/zero-cache/src/types/profiler.d.ts +12 -0
- package/out/zero-cache/src/types/profiler.d.ts.map +1 -1
- package/out/zero-cache/src/types/profiler.js +46 -1
- package/out/zero-cache/src/types/profiler.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +12 -8
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-protocol/src/down.d.ts +27 -27
- package/out/zero-react/src/use-query.d.ts.map +1 -1
- package/out/zero-react/src/use-query.js +50 -3
- package/out/zero-react/src/use-query.js.map +1 -1
- package/out/zero-solid/src/use-query.js +1 -2
- package/out/zero-solid/src/use-query.js.map +1 -1
- package/out/zql/src/ivm/data.d.ts.map +1 -1
- package/out/zql/src/ivm/data.js +8 -3
- package/out/zql/src/ivm/data.js.map +1 -1
- package/out/zql/src/ivm/view-apply-change.js +6 -1
- package/out/zql/src/ivm/view-apply-change.js.map +1 -1
- package/package.json +2 -2
|
@@ -16,7 +16,23 @@ export declare const MESSAGE_TYPES: {
|
|
|
16
16
|
readonly notify: 'notify';
|
|
17
17
|
readonly ready: 'ready';
|
|
18
18
|
readonly backupWatermarkUpdate: 'backupWatermakUpdate';
|
|
19
|
+
readonly profile: 'profile';
|
|
20
|
+
readonly profileResponse: 'profileResponse';
|
|
19
21
|
};
|
|
22
|
+
export type ProfileRequest = {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly durationMs: number;
|
|
25
|
+
readonly worker?: string | undefined;
|
|
26
|
+
readonly workerIndex?: number | undefined;
|
|
27
|
+
};
|
|
28
|
+
export type ProfileResponse = {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly profile?: unknown | undefined;
|
|
32
|
+
readonly error?: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
export type ProfileMessage = ['profile', ProfileRequest];
|
|
35
|
+
export type ProfileResponseMessage = ['profileResponse', ProfileResponse];
|
|
20
36
|
export type Message<Payload> = [keyof typeof MESSAGE_TYPES, Payload];
|
|
21
37
|
export interface Sender {
|
|
22
38
|
send<M extends Message<unknown>>(message: M, sendHandle?: SendHandle, callback?: (error: Error | null) => void): boolean;
|
|
@@ -86,4 +102,12 @@ export declare function forkChildWorker(moduleUrl: URL, env?: NodeJS.ProcessEnv,
|
|
|
86
102
|
* in a single process.
|
|
87
103
|
*/
|
|
88
104
|
export declare function inProcChannel(): [Worker, Worker];
|
|
105
|
+
/**
|
|
106
|
+
* Creates a {@link Worker} facade that broadcasts `send()` to all provided
|
|
107
|
+
* workers and aggregates their `'message'` events into one stream.
|
|
108
|
+
*
|
|
109
|
+
* This is useful for code that expects a single Worker for IPC (e.g.
|
|
110
|
+
* `handleProfzRequest`) but needs to reach multiple child workers.
|
|
111
|
+
*/
|
|
112
|
+
export declare function broadcastWorker(workers: Worker[]): Worker;
|
|
89
113
|
//# sourceMappingURL=processes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processes.d.ts","sourceRoot":"","sources":["../../../../../zero-cache/src/types/processes.ts"],"names":[],"mappings":"AAAA,OAAO,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AAE,MAAM,GAAG,IAE5B,CAAC;AAIT,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,OAAc,GAAG,IAAI,CAElE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,mBAAmB,EAAE,OAAO,GAC3B,OAAO,CAET;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,GAAG,EACd,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,EACvB,GAAG,IAAI,EAAE,MAAM,EAAE,GAChB,MAAM,CAoBR;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,GAAG,EACd,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,EACvB,GAAG,IAAI,EAAE,MAAM,EAAE,GAChB,MAAM,CAER;AAuBD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CA+BhD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CA8BzD"}
|
|
@@ -112,7 +112,31 @@ function inProcChannel() {
|
|
|
112
112
|
pid
|
|
113
113
|
}))];
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates a {@link Worker} facade that broadcasts `send()` to all provided
|
|
117
|
+
* workers and aggregates their `'message'` events into one stream.
|
|
118
|
+
*
|
|
119
|
+
* This is useful for code that expects a single Worker for IPC (e.g.
|
|
120
|
+
* `handleProfzRequest`) but needs to reach multiple child workers.
|
|
121
|
+
*/
|
|
122
|
+
function broadcastWorker(workers) {
|
|
123
|
+
const emitter = new EventEmitter();
|
|
124
|
+
for (const w of workers) w.on("message", (message, sendHandle) => emitter.emit("message", message, sendHandle));
|
|
125
|
+
const send = (message, sendHandle, callback) => {
|
|
126
|
+
for (const w of workers) w.send(message, sendHandle);
|
|
127
|
+
if (callback) callback(null);
|
|
128
|
+
return true;
|
|
129
|
+
};
|
|
130
|
+
const kill = (signal = "SIGTERM") => {
|
|
131
|
+
for (const w of workers) w.kill(signal);
|
|
132
|
+
};
|
|
133
|
+
return wrap(Object.assign(emitter, {
|
|
134
|
+
send,
|
|
135
|
+
kill,
|
|
136
|
+
pid
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
115
139
|
//#endregion
|
|
116
|
-
export { childWorker, parentWorker, singleProcessMode };
|
|
140
|
+
export { broadcastWorker, childWorker, parentWorker, singleProcessMode };
|
|
117
141
|
|
|
118
142
|
//# sourceMappingURL=processes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processes.js","names":[],"sources":["../../../../../zero-cache/src/types/processes.ts"],"sourcesContent":["import {\n type ChildProcess,\n fork,\n type SendHandle,\n type Serializable,\n} from 'node:child_process';\nimport EventEmitter from 'node:events';\nimport {platform} from 'node:os';\nimport {pid} from 'node:process';\n\n/**\n * Central registry of message type names, which are used to identify\n * the payload in {@link Message} objects sent between processes. The\n * payloads themselves are implementation specific and defined in each\n * component; only the type name is reserved here to avoid collisions.\n *\n * Receiving logic can call {@link getMessage()} with the name of\n * the message of interest to filter messages to those of interest.\n */\nexport const MESSAGE_TYPES = {\n handoff: 'handoff',\n status: 'status',\n subscribe: 'subscribe',\n notify: 'notify',\n ready: 'ready',\n backupWatermarkUpdate: 'backupWatermakUpdate',\n} as const;\n\nexport type Message<Payload> = [keyof typeof MESSAGE_TYPES, Payload];\n\nfunction getMessage<M extends Message<unknown>>(\n type: M[0],\n data: unknown,\n): M[1] | null {\n if (Array.isArray(data) && data.length === 2 && data[0] === type) {\n return data[1] as M[1];\n }\n return null;\n}\n\nfunction onMessageType<M extends Message<unknown>>(\n e: EventEmitter,\n type: M[0],\n handler: (msg: M[1], sendHandle?: SendHandle) => void,\n) {\n return e.on('message', (data, sendHandle) => {\n const msg = getMessage(type, data);\n if (msg) {\n handler(msg, sendHandle);\n }\n });\n}\n\nfunction onceMessageType<M extends Message<unknown>>(\n e: EventEmitter,\n type: M[0],\n handler: (msg: M[1], sendHandle?: SendHandle) => void,\n) {\n const listener = (data: unknown, sendHandle: SendHandle) => {\n const msg = getMessage(type, data);\n if (msg) {\n e.off('message', listener);\n handler(msg, sendHandle);\n }\n };\n return e.on('message', listener);\n}\n\nexport interface Sender {\n send<M extends Message<unknown>>(\n message: M,\n sendHandle?: SendHandle,\n callback?: (error: Error | null) => void,\n ): boolean;\n\n kill(signal?: NodeJS.Signals): void;\n}\n\nexport interface Subprocess extends Sender, EventEmitter {\n pid?: number | undefined;\n}\n\nexport interface Receiver extends EventEmitter {\n /**\n * The receiving side of {@link Sender.send()} that is a wrapper around\n * {@link on}('message', ...) that invokes the `handler` for messages of\n * the specified `type`.\n */\n onMessageType<M extends Message<unknown>>(\n type: M[0],\n handler: (msg: M[1], sendHandle?: SendHandle) => void,\n ): this;\n\n /**\n * The receiving side of {@link Sender.send()} that behaves like\n * {@link once}('message', ...) that invokes the `handler` for the next\n * message of the specified `type` and then unsubscribes.\n */\n onceMessageType<M extends Message<unknown>>(\n type: M[0],\n handler: (msg: M[1], sendHandle?: SendHandle) => void,\n ): this;\n}\n\nexport interface Worker extends Subprocess, Receiver {}\n\n/**\n * Adds the {@link Receiver.onMessageType()} and {@link Receiver.onceMessageType()}\n * methods to convert the given `EventEmitter` to a `Receiver`.\n */\nfunction wrap<P extends EventEmitter>(proc: P): P & Receiver {\n return new Proxy(proc, {\n get(target: P, prop: string | symbol, receiver: unknown) {\n switch (prop) {\n case 'onMessageType':\n return (\n type: keyof typeof MESSAGE_TYPES,\n handler: (msg: unknown, sendHandle?: SendHandle) => void,\n ) => {\n onMessageType(target, type, handler);\n return receiver; // this\n };\n case 'onceMessageType':\n return (\n type: keyof typeof MESSAGE_TYPES,\n handler: (msg: unknown, sendHandle?: SendHandle) => void,\n ) => {\n onceMessageType(target, type, handler);\n return receiver; // this\n };\n }\n return Reflect.get(target, prop, receiver);\n },\n }) as P & Receiver;\n}\n\ntype Proc = Pick<ChildProcess, 'send' | 'kill' | 'pid'> & EventEmitter;\n\n/**\n * The parentWorker for forked processes, or `null` if the process was not forked.\n * (Analogous to the `parentPort: MessagePort | null` of the `\"workers\"` library).\n */\nexport const parentWorker: Worker | null = process.send\n ? wrap(process as Proc)\n : null;\n\nconst SINGLE_PROCESS = 'SINGLE_PROCESS';\nlet singleProcessOverride = false;\nexport function singleProcessMode(): boolean {\n return singleProcessOverride || (process.env[SINGLE_PROCESS] ?? '0') !== '0';\n}\n\nexport function setSingleProcessMode(enabled: boolean = true): void {\n singleProcessOverride = enabled;\n}\n\n/**\n * Determines whether a module loaded as a worker process entry point should\n * start its worker.\n *\n * Most workers are launched via {@link childWorker}, which in single-process\n * mode runs them in-process (no real fork) by invoking their exported\n * `runWorker` directly; those entry points must therefore *not* self-start in\n * single-process mode, or they would run twice.\n *\n * A worker launched via {@link forkChildWorker}, however, is *always* a real\n * forked OS process — even in single-process mode — and it inherits the\n * parent's `SINGLE_PROCESS` env. So {@link singleProcessMode} alone would\n * wrongly suppress its startup, leaving the parent to spin re-forking a child\n * that immediately exits. Such a forked child has a non-null\n * {@link parentWorker} (`process.send` is defined), which is the signal to\n * start regardless. A standalone direct launch (no parent, not single-process)\n * also starts.\n *\n * @param parent The entry point's {@link parentWorker} (non-null iff forked).\n * @param isSingleProcessMode The result of {@link singleProcessMode}.\n */\nexport function shouldStartWorker(\n parent: Worker | null,\n isSingleProcessMode: boolean,\n): boolean {\n return parent !== null || !isSingleProcessMode;\n}\n\n/**\n *\n * @param modulePath Path to the module file, relative to zero-cache/src/, or an absolute file:// URL\n */\nexport function childWorker(\n moduleUrl: URL,\n env?: NodeJS.ProcessEnv,\n ...args: string[]\n): Worker {\n args = workerArgs(args);\n\n if (singleProcessMode()) {\n const [parent, child] = inProcChannel();\n import(moduleUrl.href)\n .then(async ({default: runWorker}) => {\n try {\n await runWorker(parent, env ?? process.env, ...args);\n child.emit('close', 0);\n return;\n } catch (err) {\n child.emit('error', err);\n child.emit('close', -1);\n }\n })\n .catch(err => child.emit('error', err));\n return child;\n }\n return forkChildWorkerWithArgs(moduleUrl, env, args);\n}\n\nexport function forkChildWorker(\n moduleUrl: URL,\n env?: NodeJS.ProcessEnv,\n ...args: string[]\n): Worker {\n return forkChildWorkerWithArgs(moduleUrl, env, workerArgs(args));\n}\n\nfunction workerArgs(args: string[]): string[] {\n return [...args, ...process.argv.slice(2)];\n}\n\nfunction forkChildWorkerWithArgs(\n moduleUrl: URL,\n env: NodeJS.ProcessEnv | undefined,\n args: string[],\n): Worker {\n const child = fork(moduleUrl, args, {\n // For production / non-windows, set `detached` to `true` so that SIGINT is\n // not automatically propagated and graceful shutdown happens as intended.\n // For Win32, detached: true causes all subprocesses to open in separate\n // terminals and breaks inter-process kill signals, so set it to false.\n detached: platform() !== 'win32',\n serialization: 'advanced', // use structured clone for IPC\n env,\n });\n return wrap(child);\n}\n\n/**\n * Creates two connected `Worker` instances such that messages sent to one\n * via the {@link Worker.send()} method are received by the other's\n * `on('message', ...)` handler.\n *\n * This is analogous to the two `MessagePort`s of a `MessageChannel`, and\n * is useful for executing code written for inter-process communication\n * in a single process.\n */\nexport function inProcChannel(): [Worker, Worker] {\n const worker1 = new EventEmitter();\n const worker2 = new EventEmitter();\n\n const sendTo =\n (dest: EventEmitter) =>\n (\n message: Serializable,\n sendHandle?: SendHandle,\n callback?: (error: Error | null) => void,\n ) => {\n dest.emit('message', message, sendHandle);\n if (callback) {\n callback(null);\n }\n return true;\n };\n\n const kill =\n (dest: EventEmitter) =>\n (signal: NodeJS.Signals = 'SIGTERM') =>\n dest.emit(signal, signal);\n\n return [\n wrap(\n Object.assign(worker1, {send: sendTo(worker2), kill: kill(worker2), pid}),\n ),\n wrap(\n Object.assign(worker2, {send: sendTo(worker1), kill: kill(worker1), pid}),\n ),\n ];\n}\n"],"mappings":";;;;;AA8BA,SAAS,WACP,MACA,MACa;CACb,IAAI,MAAM,QAAQ,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AK,GAAG,IAAI;IACnD,MAAM,KAAK,SAAS,CAAC;IACrB;GACF,SAAS,KAAK;IACZ,MAAM,KAAK,SAAS,GAAG;IACvB,MAAM,KAAK,SAAS,EAAE;GACxB;EACF,CAAC,EACA,OAAM,QAAO,MAAM,KAAK,SAAS,GAAG,CAAC;EACxC,OAAO;CACT;CACA,OAAO,wBAAwB,WAAW,KAAK,IAAI;AACrD;AAUA,SAAS,WAAW,MAA0B;CAC5C,OAAO,CAAC,GAAG,MAAM,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC;AAC3C;AAEA,SAAS,wBACP,WACA,KACA,MACQ;CAUR,OAAO,KATO,KAAK,WAAW,MAAM;EAKlC,UAAU,SAAS,MAAM;EACzB,eAAe;EACf;CACF,CACY,CAAK;AACnB;;;;;;;;;;AAWA,SAAgB,gBAAkC;CAChD,MAAM,UAAU,IAAI,aAAa;CACjC,MAAM,UAAU,IAAI,aAAa;CAEjC,MAAM,UACH,UAEC,SACA,YACA,aACG;EACH,KAAK,KAAK,WAAW,SAAS,UAAU;EACxC,IAAI,UACF,SAAS,IAAI;EAEf,OAAO;CACT;CAEF,MAAM,QACH,UACA,SAAyB,cACxB,KAAK,KAAK,QAAQ,MAAM;CAE5B,OAAO,CACL,KACE,OAAO,OAAO,SAAS;EAAC,MAAM,OAAO,OAAO;EAAG,MAAM,KAAK,OAAO;EAAG;CAAG,CAAC,CAC1E,GACA,KACE,OAAO,OAAO,SAAS;EAAC,MAAM,OAAO,OAAO;EAAG,MAAM,KAAK,OAAO;EAAG;CAAG,CAAC,CAC1E,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"processes.js","names":[],"sources":["../../../../../zero-cache/src/types/processes.ts"],"sourcesContent":["import {\n type ChildProcess,\n fork,\n type SendHandle,\n type Serializable,\n} from 'node:child_process';\nimport EventEmitter from 'node:events';\nimport {platform} from 'node:os';\nimport {pid} from 'node:process';\n\n/**\n * Central registry of message type names, which are used to identify\n * the payload in {@link Message} objects sent between processes. The\n * payloads themselves are implementation specific and defined in each\n * component; only the type name is reserved here to avoid collisions.\n *\n * Receiving logic can call {@link getMessage()} with the name of\n * the message of interest to filter messages to those of interest.\n */\nexport const MESSAGE_TYPES = {\n handoff: 'handoff',\n status: 'status',\n subscribe: 'subscribe',\n notify: 'notify',\n ready: 'ready',\n backupWatermarkUpdate: 'backupWatermakUpdate',\n profile: 'profile',\n profileResponse: 'profileResponse',\n} as const;\n\nexport type ProfileRequest = {\n readonly id: string;\n readonly durationMs: number;\n readonly worker?: string | undefined;\n readonly workerIndex?: number | undefined;\n};\n\nexport type ProfileResponse = {\n readonly id: string;\n readonly name: string;\n readonly profile?: unknown | undefined;\n readonly error?: string | undefined;\n};\n\nexport type ProfileMessage = ['profile', ProfileRequest];\nexport type ProfileResponseMessage = ['profileResponse', ProfileResponse];\n\nexport type Message<Payload> = [keyof typeof MESSAGE_TYPES, Payload];\n\nfunction getMessage<M extends Message<unknown>>(\n type: M[0],\n data: unknown,\n): M[1] | null {\n if (Array.isArray(data) && data.length === 2 && data[0] === type) {\n return data[1] as M[1];\n }\n return null;\n}\n\nfunction onMessageType<M extends Message<unknown>>(\n e: EventEmitter,\n type: M[0],\n handler: (msg: M[1], sendHandle?: SendHandle) => void,\n) {\n return e.on('message', (data, sendHandle) => {\n const msg = getMessage(type, data);\n if (msg) {\n handler(msg, sendHandle);\n }\n });\n}\n\nfunction onceMessageType<M extends Message<unknown>>(\n e: EventEmitter,\n type: M[0],\n handler: (msg: M[1], sendHandle?: SendHandle) => void,\n) {\n const listener = (data: unknown, sendHandle: SendHandle) => {\n const msg = getMessage(type, data);\n if (msg) {\n e.off('message', listener);\n handler(msg, sendHandle);\n }\n };\n return e.on('message', listener);\n}\n\nexport interface Sender {\n send<M extends Message<unknown>>(\n message: M,\n sendHandle?: SendHandle,\n callback?: (error: Error | null) => void,\n ): boolean;\n\n kill(signal?: NodeJS.Signals): void;\n}\n\nexport interface Subprocess extends Sender, EventEmitter {\n pid?: number | undefined;\n}\n\nexport interface Receiver extends EventEmitter {\n /**\n * The receiving side of {@link Sender.send()} that is a wrapper around\n * {@link on}('message', ...) that invokes the `handler` for messages of\n * the specified `type`.\n */\n onMessageType<M extends Message<unknown>>(\n type: M[0],\n handler: (msg: M[1], sendHandle?: SendHandle) => void,\n ): this;\n\n /**\n * The receiving side of {@link Sender.send()} that behaves like\n * {@link once}('message', ...) that invokes the `handler` for the next\n * message of the specified `type` and then unsubscribes.\n */\n onceMessageType<M extends Message<unknown>>(\n type: M[0],\n handler: (msg: M[1], sendHandle?: SendHandle) => void,\n ): this;\n}\n\nexport interface Worker extends Subprocess, Receiver {}\n\n/**\n * Adds the {@link Receiver.onMessageType()} and {@link Receiver.onceMessageType()}\n * methods to convert the given `EventEmitter` to a `Receiver`.\n */\nfunction wrap<P extends EventEmitter>(proc: P): P & Receiver {\n return new Proxy(proc, {\n get(target: P, prop: string | symbol, receiver: unknown) {\n switch (prop) {\n case 'onMessageType':\n return (\n type: keyof typeof MESSAGE_TYPES,\n handler: (msg: unknown, sendHandle?: SendHandle) => void,\n ) => {\n onMessageType(target, type, handler);\n return receiver; // this\n };\n case 'onceMessageType':\n return (\n type: keyof typeof MESSAGE_TYPES,\n handler: (msg: unknown, sendHandle?: SendHandle) => void,\n ) => {\n onceMessageType(target, type, handler);\n return receiver; // this\n };\n }\n return Reflect.get(target, prop, receiver);\n },\n }) as P & Receiver;\n}\n\ntype Proc = Pick<ChildProcess, 'send' | 'kill' | 'pid'> & EventEmitter;\n\n/**\n * The parentWorker for forked processes, or `null` if the process was not forked.\n * (Analogous to the `parentPort: MessagePort | null` of the `\"workers\"` library).\n */\nexport const parentWorker: Worker | null = process.send\n ? wrap(process as Proc)\n : null;\n\nconst SINGLE_PROCESS = 'SINGLE_PROCESS';\nlet singleProcessOverride = false;\nexport function singleProcessMode(): boolean {\n return singleProcessOverride || (process.env[SINGLE_PROCESS] ?? '0') !== '0';\n}\n\nexport function setSingleProcessMode(enabled: boolean = true): void {\n singleProcessOverride = enabled;\n}\n\n/**\n * Determines whether a module loaded as a worker process entry point should\n * start its worker.\n *\n * Most workers are launched via {@link childWorker}, which in single-process\n * mode runs them in-process (no real fork) by invoking their exported\n * `runWorker` directly; those entry points must therefore *not* self-start in\n * single-process mode, or they would run twice.\n *\n * A worker launched via {@link forkChildWorker}, however, is *always* a real\n * forked OS process — even in single-process mode — and it inherits the\n * parent's `SINGLE_PROCESS` env. So {@link singleProcessMode} alone would\n * wrongly suppress its startup, leaving the parent to spin re-forking a child\n * that immediately exits. Such a forked child has a non-null\n * {@link parentWorker} (`process.send` is defined), which is the signal to\n * start regardless. A standalone direct launch (no parent, not single-process)\n * also starts.\n *\n * @param parent The entry point's {@link parentWorker} (non-null iff forked).\n * @param isSingleProcessMode The result of {@link singleProcessMode}.\n */\nexport function shouldStartWorker(\n parent: Worker | null,\n isSingleProcessMode: boolean,\n): boolean {\n return parent !== null || !isSingleProcessMode;\n}\n\n/**\n *\n * @param modulePath Path to the module file, relative to zero-cache/src/, or an absolute file:// URL\n */\nexport function childWorker(\n moduleUrl: URL,\n env?: NodeJS.ProcessEnv,\n ...args: string[]\n): Worker {\n args = workerArgs(args);\n\n if (singleProcessMode()) {\n const [parent, child] = inProcChannel();\n import(moduleUrl.href)\n .then(async ({default: runWorker}) => {\n try {\n await runWorker(parent, env ?? process.env, ...args);\n child.emit('close', 0);\n return;\n } catch (err) {\n child.emit('error', err);\n child.emit('close', -1);\n }\n })\n .catch(err => child.emit('error', err));\n return child;\n }\n return forkChildWorkerWithArgs(moduleUrl, env, args);\n}\n\nexport function forkChildWorker(\n moduleUrl: URL,\n env?: NodeJS.ProcessEnv,\n ...args: string[]\n): Worker {\n return forkChildWorkerWithArgs(moduleUrl, env, workerArgs(args));\n}\n\nfunction workerArgs(args: string[]): string[] {\n return [...args, ...process.argv.slice(2)];\n}\n\nfunction forkChildWorkerWithArgs(\n moduleUrl: URL,\n env: NodeJS.ProcessEnv | undefined,\n args: string[],\n): Worker {\n const child = fork(moduleUrl, args, {\n // For production / non-windows, set `detached` to `true` so that SIGINT is\n // not automatically propagated and graceful shutdown happens as intended.\n // For Win32, detached: true causes all subprocesses to open in separate\n // terminals and breaks inter-process kill signals, so set it to false.\n detached: platform() !== 'win32',\n serialization: 'advanced', // use structured clone for IPC\n env,\n });\n return wrap(child);\n}\n\n/**\n * Creates two connected `Worker` instances such that messages sent to one\n * via the {@link Worker.send()} method are received by the other's\n * `on('message', ...)` handler.\n *\n * This is analogous to the two `MessagePort`s of a `MessageChannel`, and\n * is useful for executing code written for inter-process communication\n * in a single process.\n */\nexport function inProcChannel(): [Worker, Worker] {\n const worker1 = new EventEmitter();\n const worker2 = new EventEmitter();\n\n const sendTo =\n (dest: EventEmitter) =>\n (\n message: Serializable,\n sendHandle?: SendHandle,\n callback?: (error: Error | null) => void,\n ) => {\n dest.emit('message', message, sendHandle);\n if (callback) {\n callback(null);\n }\n return true;\n };\n\n const kill =\n (dest: EventEmitter) =>\n (signal: NodeJS.Signals = 'SIGTERM') =>\n dest.emit(signal, signal);\n\n return [\n wrap(\n Object.assign(worker1, {send: sendTo(worker2), kill: kill(worker2), pid}),\n ),\n wrap(\n Object.assign(worker2, {send: sendTo(worker1), kill: kill(worker1), pid}),\n ),\n ];\n}\n\n/**\n * Creates a {@link Worker} facade that broadcasts `send()` to all provided\n * workers and aggregates their `'message'` events into one stream.\n *\n * This is useful for code that expects a single Worker for IPC (e.g.\n * `handleProfzRequest`) but needs to reach multiple child workers.\n */\nexport function broadcastWorker(workers: Worker[]): Worker {\n const emitter = new EventEmitter();\n\n for (const w of workers) {\n w.on('message', (message: Serializable, sendHandle?: SendHandle) =>\n emitter.emit('message', message, sendHandle),\n );\n }\n\n const send = <M extends Message<unknown>>(\n message: M,\n sendHandle?: SendHandle,\n callback?: (error: Error | null) => void,\n ) => {\n for (const w of workers) {\n w.send(message, sendHandle);\n }\n if (callback) {\n callback(null);\n }\n return true;\n };\n\n const kill = (signal: NodeJS.Signals = 'SIGTERM') => {\n for (const w of work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B,eACtC,QAAQ,KAAK,WAAW,SAAS,UAAU,CAC7C;CAGF,MAAM,QACJ,SACA,YACA,aACG;EACH,KAAK,MAAM,KAAK,SACd,EAAE,KAAK,SAAS,UAAU;EAE5B,IAAI,UACF,SAAS,IAAI;EAEf,OAAO;CACT;CAEA,MAAM,QAAQ,SAAyB,cAAc;EACnD,KAAK,MAAM,KAAK,SACd,EAAE,KAAK,MAAM;CAEjB;CAEA,OAAO,KAAK,OAAO,OAAO,SAAS;EAAC;EAAM;EAAM;CAAG,CAAC,CAAC;AACvD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LogContext } from '@rocicorp/logger';
|
|
2
|
+
import type { Worker } from './processes.ts';
|
|
2
3
|
/**
|
|
3
4
|
* Convenience wrapper around a `node:inspector` {@link Session} for
|
|
4
5
|
* optionally taking cpu profiles.
|
|
@@ -8,6 +9,17 @@ export declare class CpuProfiler {
|
|
|
8
9
|
static connect(): Promise<CpuProfiler>;
|
|
9
10
|
private constructor();
|
|
10
11
|
start(): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Captures a CPU profile for the specified duration (in milliseconds)
|
|
14
|
+
* and returns the V8 profile object.
|
|
15
|
+
*/
|
|
16
|
+
static profile(durationMs: number): Promise<unknown>;
|
|
17
|
+
stop(): Promise<unknown>;
|
|
11
18
|
stopAndDispose(lc: LogContext, filename: string): Promise<void>;
|
|
12
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Registers an IPC handler on `parent` to capture a CPU profile when
|
|
22
|
+
* requested, sending back the resulting V8 profile.
|
|
23
|
+
*/
|
|
24
|
+
export declare function installProfileHandler(parent: Worker | null, workerName: string, workerIndex?: number | undefined): void;
|
|
13
25
|
//# sourceMappingURL=profiler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../../../../../zero-cache/src/types/profiler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../../../../../zero-cache/src/types/profiler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAiB,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAE3D;;;GAGG;AACH,qBAAa,WAAW;;IACtB,OAAa,OAAO,yBAKnB;IAID,OAAO,eAEN;IAEK,KAAK,kBAEV;IAED;;;OAGG;IACH,OAAa,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAKzD;IAEK,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAK7B;IAEK,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAMpD;CACF;AAID;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,UAAU,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,GAC/B,IAAI,CA6BN"}
|
|
@@ -21,6 +21,22 @@ var CpuProfiler = class CpuProfiler {
|
|
|
21
21
|
async start() {
|
|
22
22
|
await this.#session.post("Profiler.start");
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Captures a CPU profile for the specified duration (in milliseconds)
|
|
26
|
+
* and returns the V8 profile object.
|
|
27
|
+
*/
|
|
28
|
+
static async profile(durationMs) {
|
|
29
|
+
const profiler = await CpuProfiler.connect();
|
|
30
|
+
await profiler.start();
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
32
|
+
return await profiler.stop();
|
|
33
|
+
}
|
|
34
|
+
async stop() {
|
|
35
|
+
const { profile } = await this.#session.post("Profiler.stop");
|
|
36
|
+
await this.#session.post("Profiler.disable");
|
|
37
|
+
this.#session.disconnect();
|
|
38
|
+
return profile;
|
|
39
|
+
}
|
|
24
40
|
async stopAndDispose(lc, filename) {
|
|
25
41
|
const { profile } = await this.#session.post("Profiler.stop");
|
|
26
42
|
const path = join(tmpdir(), `${filename}.cpuprofile`);
|
|
@@ -29,7 +45,36 @@ var CpuProfiler = class CpuProfiler {
|
|
|
29
45
|
this.#session.disconnect();
|
|
30
46
|
}
|
|
31
47
|
};
|
|
48
|
+
var WORKER_INDEX_SUFFIX = /-\d+$/;
|
|
49
|
+
/**
|
|
50
|
+
* Registers an IPC handler on `parent` to capture a CPU profile when
|
|
51
|
+
* requested, sending back the resulting V8 profile.
|
|
52
|
+
*/
|
|
53
|
+
function installProfileHandler(parent, workerName, workerIndex) {
|
|
54
|
+
if (!parent) return;
|
|
55
|
+
parent.onMessageType("profile", async (req) => {
|
|
56
|
+
if (req.worker !== void 0) {
|
|
57
|
+
const baseName = workerName.replace(WORKER_INDEX_SUFFIX, "");
|
|
58
|
+
if (!(req.worker === workerName || req.worker === baseName)) return;
|
|
59
|
+
if (req.workerIndex !== void 0 && workerIndex !== void 0 && req.workerIndex !== workerIndex) return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const profile = await CpuProfiler.profile(req.durationMs);
|
|
63
|
+
parent.send(["profileResponse", {
|
|
64
|
+
id: req.id,
|
|
65
|
+
name: workerName,
|
|
66
|
+
profile
|
|
67
|
+
}]);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
parent.send(["profileResponse", {
|
|
70
|
+
id: req.id,
|
|
71
|
+
name: workerName,
|
|
72
|
+
error: String(err)
|
|
73
|
+
}]);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
32
77
|
//#endregion
|
|
33
|
-
export { CpuProfiler };
|
|
78
|
+
export { CpuProfiler, installProfileHandler };
|
|
34
79
|
|
|
35
80
|
//# sourceMappingURL=profiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler.js","names":["#session"],"sources":["../../../../../zero-cache/src/types/profiler.ts"],"sourcesContent":["import {writeFile} from 'node:fs/promises';\nimport {Session} from 'node:inspector/promises';\nimport {tmpdir} from 'node:os';\nimport {join} from 'node:path';\nimport type {LogContext} from '@rocicorp/logger';\n\n/**\n * Convenience wrapper around a `node:inspector` {@link Session} for\n * optionally taking cpu profiles.\n */\nexport class CpuProfiler {\n static async connect() {\n const session = new Session();\n session.connect();\n await session.post('Profiler.enable');\n return new CpuProfiler(session);\n }\n\n readonly #session;\n\n private constructor(session: Session) {\n this.#session = session;\n }\n\n async start() {\n await this.#session.post('Profiler.start');\n }\n\n async stopAndDispose(lc: LogContext, filename: string) {\n const {profile} = await this.#session.post('Profiler.stop');\n const path = join(tmpdir(), `${filename}.cpuprofile`);\n await writeFile(path, JSON.stringify(profile));\n lc.info?.(`wrote cpu profile to ${path}`);\n this.#session.disconnect();\n }\n}\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"profiler.js","names":["#session"],"sources":["../../../../../zero-cache/src/types/profiler.ts"],"sourcesContent":["import {writeFile} from 'node:fs/promises';\nimport {Session} from 'node:inspector/promises';\nimport {tmpdir} from 'node:os';\nimport {join} from 'node:path';\nimport type {LogContext} from '@rocicorp/logger';\nimport type {ProfileMessage, Worker} from './processes.ts';\n\n/**\n * Convenience wrapper around a `node:inspector` {@link Session} for\n * optionally taking cpu profiles.\n */\nexport class CpuProfiler {\n static async connect() {\n const session = new Session();\n session.connect();\n await session.post('Profiler.enable');\n return new CpuProfiler(session);\n }\n\n readonly #session;\n\n private constructor(session: Session) {\n this.#session = session;\n }\n\n async start() {\n await this.#session.post('Profiler.start');\n }\n\n /**\n * Captures a CPU profile for the specified duration (in milliseconds)\n * and returns the V8 profile object.\n */\n static async profile(durationMs: number): Promise<unknown> {\n const profiler = await CpuProfiler.connect();\n await profiler.start();\n await new Promise(resolve => setTimeout(resolve, durationMs));\n return await profiler.stop();\n }\n\n async stop(): Promise<unknown> {\n const {profile} = await this.#session.post('Profiler.stop');\n await this.#session.post('Profiler.disable');\n this.#session.disconnect();\n return profile;\n }\n\n async stopAndDispose(lc: LogContext, filename: string) {\n const {profile} = await this.#session.post('Profiler.stop');\n const path = join(tmpdir(), `${filename}.cpuprofile`);\n await writeFile(path, JSON.stringify(profile));\n lc.info?.(`wrote cpu profile to ${path}`);\n this.#session.disconnect();\n }\n}\n\nconst WORKER_INDEX_SUFFIX = /-\\d+$/;\n\n/**\n * Registers an IPC handler on `parent` to capture a CPU profile when\n * requested, sending back the resulting V8 profile.\n */\nexport function installProfileHandler(\n parent: Worker | null,\n workerName: string,\n workerIndex?: number | undefined,\n): void {\n if (!parent) {\n return;\n }\n parent.onMessageType<ProfileMessage>('profile', async req => {\n if (req.worker !== undefined) {\n const baseName = workerName.replace(WORKER_INDEX_SUFFIX, '');\n const matchesName = req.worker === workerName || req.worker === baseName;\n if (!matchesName) {\n return;\n }\n if (\n req.workerIndex !== undefined &&\n workerIndex !== undefined &&\n req.workerIndex !== workerIndex\n ) {\n return;\n }\n }\n try {\n const profile = await CpuProfiler.profile(req.durationMs);\n parent.send(['profileResponse', {id: req.id, name: workerName, profile}]);\n } catch (err) {\n parent.send([\n 'profileResponse',\n {id: req.id, name: workerName, error: String(err)},\n ]);\n }\n });\n}\n"],"mappings":";;;;;;;;;AAWA,IAAa,cAAb,MAAa,YAAY;CACvB,aAAa,UAAU;EACrB,MAAM,UAAU,IAAI,QAAQ;EAC5B,QAAQ,QAAQ;EAChB,MAAM,QAAQ,KAAK,iBAAiB;EACpC,OAAO,IAAI,YAAY,OAAO;CAChC;CAEA;CAEA,YAAoB,SAAkB;EACpC,KAAKA,WAAW;CAClB;CAEA,MAAM,QAAQ;EACZ,MAAM,KAAKA,SAAS,KAAK,gBAAgB;CAC3C;;;;;CAMA,aAAa,QAAQ,YAAsC;EACzD,MAAM,WAAW,MAAM,YAAY,QAAQ;EAC3C,MAAM,SAAS,MAAM;EACrB,MAAM,IAAI,SAAQ,YAAW,WAAW,SAAS,UAAU,CAAC;EAC5D,OAAO,MAAM,S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SAAS,EAC/B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EACnD,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EACpD,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3D,oBAAoB,EAAE,IAAI,CAAC,oBAAoB,EAAE,eAAe,CAAC,EACjE,eAAe,SAAW,EAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAChC,OAAO,CACR;IACE,SAAS;IACT,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG,SAAS;IACzC,iBAAiB,GAAG,SAAS;CAC9B,CACF,CAuEA;AAED,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,UAAU,GAAG,QAAQ,EACnC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,EAC1C,SAAS,EAAE,OAAO,EAClB,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3D,EAAE,EAAE,UAAU,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,gBA+B3D"}
|
|
@@ -11,7 +11,7 @@ import { dropDatabase } from "../../../replicache/src/persist/collect-idb-databa
|
|
|
11
11
|
import { must } from "../../../shared/src/must.js";
|
|
12
12
|
import { clientToServer } from "../../../zero-schema/src/name-mapper.js";
|
|
13
13
|
import { h64 } from "../../../shared/src/hash.js";
|
|
14
|
-
import { getErrorMessage } from "../../../shared/src/error.js";
|
|
14
|
+
import { getErrorCauses, getErrorMessage } from "../../../shared/src/error.js";
|
|
15
15
|
import { ClientNotFound, InvalidMessage } from "../../../zero-protocol/src/error-kind-enum.js";
|
|
16
16
|
import { ProtocolError } from "../../../zero-protocol/src/error.js";
|
|
17
17
|
import "../../../zero-protocol/src/client-schema.js";
|
|
@@ -919,11 +919,11 @@ var Zero = class Zero {
|
|
|
919
919
|
const clientGroupID = await this.clientGroupID;
|
|
920
920
|
this.#addConnectEvent(lc, attempt, "initializing active clients");
|
|
921
921
|
const activeClientsManager = await this.#activeClientsManager;
|
|
922
|
-
if (signal.aborted) throw signal.reason;
|
|
922
|
+
if (signal.aborted) throw attempt.abortReason ?? signal.reason;
|
|
923
923
|
const [ws, initConnectionQueries, deletedClients] = await createSocket(this.#rep, this.#queryManager, this.#deleteClientsManager, socketOrigin, connectCookie, this.clientID, clientGroupID, this.#clientSchema, this.userID, fromReplicacheAuthToken(this.#rep.auth), this.#lastMutationIDReceived, wsid, this.#options.logLevel === "debug", lc, this.#options.mutateURL, this.#options.mutateHeaders, this.#options.queryURL ?? this.#options.getQueriesURL, this.#options.queryHeaders, additionalConnectParams, activeClientsManager, this.#options.maxHeaderLength, (event) => this.#addConnectEvent(lc, attempt, event));
|
|
924
924
|
if (signal.aborted) {
|
|
925
925
|
ws.close();
|
|
926
|
-
throw signal.reason;
|
|
926
|
+
throw attempt.abortReason ?? signal.reason;
|
|
927
927
|
}
|
|
928
928
|
if (this.closed) {
|
|
929
929
|
ws.close();
|
|
@@ -942,7 +942,7 @@ var Zero = class Zero {
|
|
|
942
942
|
attempt.clearTimeout?.();
|
|
943
943
|
attempt.clearTimeout = this.#armConnectTimeout(lc, attempt, "ack");
|
|
944
944
|
await attempt.connected.promise;
|
|
945
|
-
if (signal.aborted) throw signal.reason;
|
|
945
|
+
if (signal.aborted) throw attempt.abortReason ?? signal.reason;
|
|
946
946
|
this.#mutationTracker.onConnected(this.#lastMutationIDReceived);
|
|
947
947
|
this.#rep.push().catch(() => {});
|
|
948
948
|
}
|
|
@@ -980,7 +980,11 @@ var Zero = class Zero {
|
|
|
980
980
|
lc.debug?.("Connect event", event);
|
|
981
981
|
}
|
|
982
982
|
#disconnect(lc, reason, closeCode) {
|
|
983
|
-
this.#currentConnectAttempt
|
|
983
|
+
const attempt = this.#currentConnectAttempt;
|
|
984
|
+
if (attempt) {
|
|
985
|
+
attempt.abortReason = reason;
|
|
986
|
+
attempt.controller.abort(reason);
|
|
987
|
+
}
|
|
984
988
|
if (shouldReportConnectError(reason)) {
|
|
985
989
|
this.#connectErrorCount++;
|
|
986
990
|
this.#metrics.lastConnectError.set(getLastConnectErrorValue(reason));
|
|
@@ -1185,7 +1189,7 @@ var Zero = class Zero {
|
|
|
1185
1189
|
this.#addConnectEvent(lc, attempt, "starting the connection");
|
|
1186
1190
|
attempt.clearTimeout = this.#armConnectTimeout(lc, attempt, "setup");
|
|
1187
1191
|
const canceled = resolver();
|
|
1188
|
-
const abortHandler = () => canceled.reject(attempt.controller.signal.reason);
|
|
1192
|
+
const abortHandler = () => canceled.reject(attempt.abortReason ?? attempt.controller.signal.reason);
|
|
1189
1193
|
attempt.controller.signal.addEventListener("abort", abortHandler, { once: true });
|
|
1190
1194
|
try {
|
|
1191
1195
|
try {
|
|
@@ -1256,7 +1260,7 @@ var Zero = class Zero {
|
|
|
1256
1260
|
})).key === "connectRequest") this.#connectionManager.resumeFromConnectRequest();
|
|
1257
1261
|
break;
|
|
1258
1262
|
case Error$1:
|
|
1259
|
-
lc.info?.(`Run loop paused in error state. Call zero.connection.connect() to resume.`, currentState.reason);
|
|
1263
|
+
lc.info?.(`Run loop paused in error state. Call zero.connection.connect() to resume.`, currentState.reason, ...getErrorCauses(currentState.reason));
|
|
1260
1264
|
if ((await promiseRace({
|
|
1261
1265
|
connectRequest: this.#connectionManager.waitForConnectRequest(),
|
|
1262
1266
|
stateChange: this.#connectionManager.waitForStateChange()
|
|
@@ -1270,7 +1274,7 @@ var Zero = class Zero {
|
|
|
1270
1274
|
if (!this.#connectionManager.is("connected") && !isClientClosedError) {
|
|
1271
1275
|
const level = isAuthError(ex) ? "warn" : "error";
|
|
1272
1276
|
const kind = isServerError(ex) ? ex.kind : "Unknown Error";
|
|
1273
|
-
lc[level]?.("Failed to connect", ex, kind, {
|
|
1277
|
+
lc[level]?.("Failed to connect", ex, ...getErrorCauses(ex), kind, {
|
|
1274
1278
|
lmid: this.#lastMutationIDReceived,
|
|
1275
1279
|
baseCookie: this.#connectCookie
|
|
1276
1280
|
});
|