Event schema definitions with type validation
Complete event schema with preserved literal types
// v9: No 'as const' needed!
export const EventSchemas = createEventSchemas({
emitEvents: {
'todo.created': createFireAndForgetEvent(TodoItemSchema, 'Emitted when todo is created'),
},
emitReturnableEvents: {
'todo.create': createReturnableEvent(CreateInputSchema, TodoItemSchema, 'Create a todo'),
},
});
// Compile error if wrong event type used:
// emitEvents: {
// 'todo.create': createReturnableEvent(...) // ❌ Type error!
// }
Helper function to create a complete event schema with all 6 event types and preserve type safety.
v9 Breaking Change: This function now uses const type parameters to eliminate the need for 'as const'. It also validates that event types match their categories at compile time using type branding.
Features: