superapp
Client

Type Generation

Generate TypeScript types from your database schema for fully type-safe queries.

The superapp CLI generates SuperAppSchema and SuperAppActions types from your live engine, giving you full autocomplete for connection names, table names, column names, action names, action inputs, and return types.

npx superapp generate

Setup

Run the generate command pointing at your running superapp backend.

npx superapp generate --url http://localhost:3001 --output ./generated/schema.ts

This connects to your backend, introspects all configured database connections, and writes a TypeScript file with the full schema.

Options

FlagDescriptionDefault
--urlURL of your superapp backendhttp://localhost:3001
--outputOutput file path./generated/schema.ts

Generated Schema Structure

The generated file exports a SuperAppSchema type (table types) and a SuperAppActions type (action input/output types).

// generated/schema.ts (auto-generated, do not edit)

export type SuperAppSchema = {
  main: {
    orders: {
      id: string
      amount: number
      status: string
      customer_id: string
      created_at: string
      updated_at: string
    }
    customers: {
      id: string
      name: string
      email: string
      organization_id: string
      created_at: string
    }
    organizations: {
      id: string
      name: string
      plan: string
      created_at: string
    }
  }
}

export type SuperAppActions = {
  incrementStock: {
    input: { productId: string; amount: number }
    output: { id: string; stock: number }
  }
  revenueReport: {
    input: { startDate: string; endDate: string }
    output: { month: string; totalRevenue: number; orderCount: number; avgOrderValue: number }[]
  }
}

The SuperAppSchema top-level keys are connection names (e.g., main), and each connection contains table names with their column types. The SuperAppActions type is derived from the Zod schemas defined on each action in the engine config.

Using the Schema

Pass the generated types to createClient for type-safe queries and actions.

import { createClient } from '@superapp/db'
import type { SuperAppSchema, SuperAppActions } from '../generated/schema'

const db = createClient<SuperAppSchema, SuperAppActions>({
  url: 'http://localhost:3001/data',
  userToken,
})

// Full autocomplete for connections, tables, columns
const orders = await db.main.orders.findMany({
  select: ['id', 'amount', 'status'],
  //        ^ autocomplete shows: id, amount, status, customer_id, created_at, updated_at
  where: { status: { $eq: 'active' } },
})
// orders: { id: string; amount: number; status: string }[]

// Full autocomplete for action names, input, and output
const result = await db.action('incrementStock', {
  productId: 'prod_123',  // ← autocomplete
  amount: 5,              // ← autocomplete
})
// result: { id: string; stock: number }

Regenerating

Run the generate command again whenever your database schema changes (new tables, columns, or connections).

npx superapp generate --url http://localhost:3001 --output ./generated/schema.ts

Add it to your package.json scripts for convenience.

{
  "scripts": {
    "generate": "superapp generate --url http://localhost:3001 --output ./generated/schema.ts"
  }
}

Adding to .gitignore

The generated file is derived from your database and can be regenerated at any time. You may choose to either commit it for CI convenience or add it to .gitignore.

# .gitignore
generated/

On this page