mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-06 00:14:54 +00:00
* Split the inbound WebSocket validator per message type zod-aot compiled WSOutboundMessageSchema into one 11 MB function. Every inbound frame, heartbeats included, ran through it, so V8 hosts (daemon clients, plugin hosts, the CLI, Electron) eventually Maglev-compiled the whole function: about 800 MB of compiler memory and multi-second stalls, again after each deoptimization. Generate a tag-only envelope validator plus one validator per session message, and dispatch on the message type. Issue paths, defaults and passthrough behave as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Use forward slashes in generated validator imports path.relative() returns backslash paths on Windows, which break the import specifiers written into the generated files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Declare the session export helper as a function Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
954 B
TypeScript
26 lines
954 B
TypeScript
import { z } from "zod";
|
|
import {
|
|
SessionOutboundMessageSchema,
|
|
WSHelloRejectedMessageSchema,
|
|
WSPongMessageSchema,
|
|
} from "../messages.js";
|
|
|
|
export const sessionOutboundMessageOptions = SessionOutboundMessageSchema.options;
|
|
|
|
const [firstSessionTag, ...otherSessionTags] = sessionOutboundMessageOptions.map((option) =>
|
|
z.object({ type: option.shape.type }),
|
|
);
|
|
|
|
// WSOutboundMessageSchema with every session message reduced to its tag. It reports the same
|
|
// envelope and discriminator issues, while each session message gets its own generated validator:
|
|
// one function for the whole protocol is large enough that V8's Maglev tier spends hundreds of MB
|
|
// and seconds compiling it.
|
|
export const WSOutboundEnvelopeSchema = z.discriminatedUnion("type", [
|
|
WSPongMessageSchema,
|
|
z.object({
|
|
type: z.literal("session"),
|
|
message: z.discriminatedUnion("type", [firstSessionTag, ...otherSessionTags]),
|
|
}),
|
|
WSHelloRejectedMessageSchema,
|
|
]);
|