BSB Node.js Type Definitions
    Preparing search index...

    Function createEventSchemas

    • 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:

      • No 'as const' required - type inference is automatic via const type parameter
      • Compile-time validation that fire-and-forget events are in fire-and-forget categories
      • Compile-time validation that returnable events are in returnable categories
      • Compile-time validation that broadcast events are in broadcast categories
      • Runtime duplicate name detection across categories (warns for developer clarity)

      Type Parameters

      Parameters

      • schemas: T

        Event schema definitions with type validation

      Returns T

      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!
      // }