From 6f604bd0f999a5df4ed6a57aef524f0dcf9eb356 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Thu, 29 May 2025 11:32:55 -0400 Subject: remove secondary codegen --- js/src/bus/index.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'js/src/bus') diff --git a/js/src/bus/index.ts b/js/src/bus/index.ts index 15d2b1107..cf5101b67 100644 --- a/js/src/bus/index.ts +++ b/js/src/bus/index.ts @@ -1,4 +1,4 @@ -import { z, type ZodType } from "zod/v4"; +import { z, type ZodType } from "zod"; import { App } from "../app"; import { Log } from "../util/log"; @@ -30,16 +30,23 @@ export namespace Bus { return result; } - export function specs() { - const children = {} as any; - for (const [type, def] of registry.entries()) { - children["event." + def.type] = def.properties; - } - const result = z.toJSONSchema(z.object(children)) as any; - result.definitions = result.properties; - delete result.properties; - delete result.required; - return result; + export function payloads() { + return z.discriminatedUnion( + "type", + registry + .entries() + .map(([type, def]) => + z + .object({ + type: z.literal(type), + properties: def.properties, + }) + .openapi({ + ref: "Event" + "." + def.type, + }), + ) + .toArray() as any, + ); } export function publish( -- cgit v1.2.3