Type Generation

The @tablecraft/codegen package generates TypeScript types from your TableCraft API metadata, providing full type safety for your frontend code.

Installation

# Install as dev dependency
pnpm add -D @tablecraft/codegen

# Or use directly with npx
npx @tablecraft/codegen --url http://localhost:3000/api/engine --out ./src/generated

Usage

Basic Usage

npx @tablecraft/codegen --url http://localhost:3000/api/engine --out ./src/generated

This will:

  1. Fetch metadata from all tables via /_tables endpoint

  2. Generate TypeScript interfaces for each table

  3. Create typed adapter factory functions

Options

Option
Alias
Description
Required

--url

-u

Base URL of your TableCraft API

Yes

--out

-o

Output directory for generated files

Yes

--tables

-t

Specific tables to generate (default: all)

No

--header

-H

Custom headers (e.g., -H "Authorization: Bearer token")

No

Examples

Generated Files

Generated Types

Each table generates a Row interface with all column types:

Using Generated Types

With DataTable

Type-Safe Hidden Columns

The hiddenColumns helper function provides compile-time type checking:

With Custom Adapter

Benefits

Benefit

Autocomplete

Description

Column names and filter operators appear in your IDE.

Benefit

Type Checking

Description

Catch errors like typos or invalid types at compile time.

Benefit

Refactoring

Description

Rename columns safely across the entire codebase.

Benefit

Documentation

Description

Generated types serve as always-up-to-date documentation.

CI/CD Integration

Add to your package.json to ensure types are always fresh before building:

Last updated

Was this helpful?