support Zod in machine-runner
rkuhn opened this issue · comments
Roland Kuhn commented
With zod
being quite user-friendly, it would make sense to allow the state machine to pull in parser and thus improve type-safety. The main issue is that the parser instance needs to be available at runtime, so it needs to be injected by @proto
. Possibly like so:
// in machine-runner:
export type AllEvents<T extends z.ZodTypeAny> = z.infer<T>[keyof z.infer<T>]
// in user code:
const Event1 = z.object({ ... })
const Event2 = z.object({ ... })
const Events = z.object({ Event1, Event2 })
type Events = AllEvents<typeof Events>
@proto('my-proto', Events)
class Initial extends State<Events> { ... }
Then the runtime can access the parser instance for an event type using parser.shape[e.type]
.
Roland Kuhn commented
The approach will now be via an extension of the MachineEvent designer DSL.
Roland Kuhn commented
@Kelerchian This is done, right?
Alan Darmasaputra commented
Yes.
Resolved in #59
Closing and thank you for catching it.