From 652429377b99085d686d6b907c2f550c304e6b98 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Mon, 19 May 2025 15:43:14 -0400 Subject: sync --- js/src/bus/index.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'js/src/bus') diff --git a/js/src/bus/index.ts b/js/src/bus/index.ts index 4f3b40041..f320aeef3 100644 --- a/js/src/bus/index.ts +++ b/js/src/bus/index.ts @@ -1,4 +1,4 @@ -import type { z, ZodSchema } from "zod"; +import { z, type ZodType } from "zod/v4"; import { App } from "../app"; import { Log } from "../util/log"; @@ -16,14 +16,30 @@ export namespace Bus { export type EventDefinition = ReturnType; - export function event( + const registry = new Map(); + + export function event( type: Type, properties: Properties, ) { - return { + const result = { type, properties, }; + registry.set(type, result); + return result; + } + + export function specs() { + const children = {} as any; + for (const [type, def] of registry.entries()) { + children[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 publish( -- cgit v1.2.3