vapor-chamber API reference - v1.16.0
    Preparing search index...

    Function defineSchema

    • defineSchema — identity helper that PRESERVES field-type literals, so the schema keeps its inference power. Without it, { id: 'number' } widens to Record<string, string> and every inferred type collapses to any.

      The complete one-source-of-truth wiring:

      Type Parameters

      Parameters

      • schema: S

      Returns S

      // commands.ts — define once
      export const schema = defineSchema({
      cartAdd: {
      description: 'Add a product to the cart',
      target: { id: 'number', name: 'string' },
      payload: { qty: 'number' },
      result: { count: 'number', total: 'number' },
      },
      cartCheckout: {
      description: 'Charge the cart and place the order',
      authorize: 'checkout', // → Gate::forUser($user)->authorize('checkout', ...)
      target: { cartId: 'number' },
      },
      });

      // → typed schema bus (validation + LLM tools included)
      const bus = createSchemaCommandBus(schema);

      // → typed SHARED bus for every useCommand()/getCommandBus() call site
      declare module 'vapor-chamber' {
      interface GlobalCommands extends CommandsOf<typeof schema> {}
      }
      setCommandBus(bus);

      // → Laravel stubs + registry: node scripts/generate-laravel.mjs commands.mjs
      // → agent tools: bus.toTools() / vapor-chamber/mcp