Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tailor-platform/sdk/llms.txt

Use this file to discover all available pages before exploring further.

Generators analyze your TailorDB types, Resolvers, and Executors to automatically generate TypeScript code.
Generators have been replaced by the Plugin system. See the migration guide for upgrading. This page documents the legacy generator syntax for backward compatibility.

Overview

When you run tailor-sdk generate, the SDK:
  1. Loads all TailorDB types, Resolvers, and Executors from your configuration
  2. Passes each definition to the configured generators
  3. Aggregates the results and writes output files
This enables generators to create derived code based on your application’s schema. For example, the @tailor-platform/kysely-type generator produces type-safe database access code from your TailorDB definitions.

Configuration

Define generators in tailor.config.ts using defineGenerators():
tailor.config.ts
import { defineConfig, defineGenerators } from "@tailor-platform/sdk";

export const generators = defineGenerators(
  ["@tailor-platform/kysely-type", { distPath: "./generated/tailordb.ts" }],
  ["@tailor-platform/enum-constants", { distPath: "./generated/enums.ts" }],
  ["@tailor-platform/file-utils", { distPath: "./generated/files.ts" }],
  ["@tailor-platform/seed", { distPath: "./seed", machineUserName: "admin" }],
);

export default defineConfig({
  name: "my-app",
  // ...
});
The generators export must be a named export (not default).

CLI Commands

Generate Files

tailor-sdk generate
Generates all configured output files.

Watch Mode

tailor-sdk generate --watch
Watches for file changes and regenerates automatically.

Builtin Generators

The SDK includes four builtin generators for common code generation tasks.

@tailor-platform/kysely-type

Generates Kysely type definitions and the getDB() function for type-safe database access.
["@tailor-platform/kysely-type", { distPath: "./generated/tailordb.ts" }]
OptionTypeDescription
distPathstringOutput file path (required)
Prerequisites: Install the required dev dependency for type definitions:
pnpm add -D @tailor-platform/function-types
Output: Generates a TypeScript file containing:
  • Type definitions for all TailorDB types
  • getDB(namespace) function to create Kysely instances
  • Utility types for Timestamp and Serial fields
Usage:
resolvers/userQuery.ts
import { getDB } from "./generated/tailordb";

// In resolvers
body: async (context) => {
  const db = getDB("tailordb");
  const users = await db
    .selectFrom("User")
    .selectAll()
    .where("email", "=", context.input.email)
    .execute();
  return { users };
};
executors/auditLog.ts
import { getDB } from "./generated/tailordb";

// In executors
body: async ({ newRecord }) => {
  const db = getDB("tailordb");
  await db.insertInto("AuditLog").values({ userId: newRecord.id, action: "created" }).execute();
};
workflows/orderProcessing.ts
import { getDB } from "./generated/tailordb";

// In workflow jobs
body: async (input, { env }) => {
  const db = getDB("tailordb");
  return await db
    .selectFrom("Order")
    .selectAll()
    .where("id", "=", input.orderId)
    .executeTakeFirst();
};

@tailor-platform/enum-constants

Extracts enum constants from TailorDB type definitions.
["@tailor-platform/enum-constants", { distPath: "./generated/enums.ts" }]
OptionTypeDescription
distPathstringOutput file path (required)
Output: Generates TypeScript constants for all enum fields:
generated/enums.ts
// Generated output
export const OrderStatus = {
  PENDING: "PENDING",
  PROCESSING: "PROCESSING",
  COMPLETED: "COMPLETED",
  CANCELLED: "CANCELLED",
} as const;

export type OrderStatus = (typeof OrderStatus)[keyof typeof OrderStatus];
Usage:
resolvers/orderQuery.ts
import { OrderStatus } from "./generated/enums";
import { getDB } from "./generated/tailordb";

// Type-safe enum usage
const status: OrderStatus = OrderStatus.PENDING;

// In queries
const orders = await db
  .selectFrom("Order")
  .selectAll()
  .where("status", "=", OrderStatus.COMPLETED)
  .execute();

@tailor-platform/file-utils

Generates utility functions for handling file-type fields in TailorDB.
["@tailor-platform/file-utils", { distPath: "./generated/files.ts" }]
OptionTypeDescription
distPathstringOutput file path (required)
Output: Generates TypeScript interfaces and utilities for types with file fields:
generated/files.ts
// Generated output
export interface UserFileFields {
  avatar: string;
  documents: string;
}

export function getUserFileFields(): (keyof UserFileFields)[] {
  return ["avatar", "documents"];
}

@tailor-platform/seed

Generates seed data configuration files for database initialization.
// Basic configuration
["@tailor-platform/seed", { distPath: "./seed" }]

// With default machine user
["@tailor-platform/seed", { distPath: "./seed", machineUserName: "admin" }]
OptionTypeDescription
distPathstringOutput directory path (required)
machineUserNamestringDefault machine user name (can be overridden at runtime)
Output: Generates a seed directory structure:
seed/
├── data/
│   ├── User.jsonl        # Seed data files (JSONL format)
│   ├── User.schema.ts    # lines-db schema definitions
│   └── Product.jsonl
└── exec.mjs              # Executable script
Usage: Run the generated executable script:
# With machine user from config
node seed/exec.mjs

# Specify machine user at runtime (required if not configured, or to override)
node seed/exec.mjs --machine-user admin

# Short form
node seed/exec.mjs -m admin

# With other options
node seed/exec.mjs -m admin --truncate --yes
The --machine-user option is required at runtime if machineUserName is not configured in the generator options.
The generated files are compatible with gql-ingest for bulk data import.

Example Configuration

Here’s a complete example from the SDK example project:
tailor.config.ts
import {
  defineAuth,
  defineConfig,
  defineIdp,
  defineGenerators,
  defineStaticWebSite,
} from "@tailor-platform/sdk";
import { user } from "./tailordb/user";

const website = defineStaticWebSite("my-frontend", {
  description: "my frontend application",
});

const idp = defineIdp("my-idp", {
  authorization: "loggedIn",
  clients: ["default-idp-client"],
});

export const auth = defineAuth("my-auth", {
  userProfile: {
    type: user,
    usernameField: "email",
    attributes: {
      role: true,
    },
  },
  machineUsers: {
    "manager-machine-user": {
      attributes: {
        role: "MANAGER",
      },
    },
  },
  idProvider: idp.provider("sample", "default-idp-client"),
});

export const generators = defineGenerators(
  ["@tailor-platform/kysely-type", { distPath: "./generated/tailordb.ts" }],
  ["@tailor-platform/enum-constants", { distPath: "./generated/enums.ts" }],
  ["@tailor-platform/file-utils", { distPath: "./generated/files.ts" }],
  ["@tailor-platform/seed", { distPath: "./seed", machineUserName: "manager-machine-user" }],
);

export default defineConfig({
  name: "my-app",
  inlineSourcemap: false,
  env: {
    foo: 1,
    bar: "hello",
    baz: true,
  },
  cors: [
    website.url, // This will be replaced with the actual Static Website URL
  ],
  db: {
    tailordb: {
      files: ["./tailordb/*.ts"],
      migration: {
        directory: "./migrations",
      },
    },
  },
  resolver: {
    "my-resolver": { files: ["./resolvers/*.ts"] },
  },
  idp: [idp],
  auth,
  executor: { files: ["./executors/*.ts"] },
  workflow: {
    files: ["./workflows/**/*.ts"],
  },
  staticWebsites: [website],
});

Workflow

  1. Define your TailorDB types:
    tailordb/user.ts
    import { db } from "@tailor-platform/sdk";
    
    export const user = db.type("User", {
      name: db.string(),
      email: db.string(),
      role: db.enum(["MANAGER", "STAFF"]),
      age: db.int().optional(),
      ...db.fields.timestamps(),
    });
    
  2. Configure generators in tailor.config.ts
  3. Run generation:
    tailor-sdk generate
    
  4. Use generated code in resolvers, executors, and workflows:
    resolvers/userOperations.ts
    import { getDB } from "./generated/tailordb";
    import { createResolver, t } from "@tailor-platform/sdk";
    
    export default createResolver({
      name: "getUsersByRole",
      operation: "query",
      input: { role: t.string() },
      body: async ({ input }) => {
        const db = getDB("tailordb");
        return await db
          .selectFrom("User")
          .selectAll()
          .where("role", "=", input.role)
          .execute();
      },
      output: t.array(t.object({
        id: t.string(),
        name: t.string(),
        email: t.string(),
        role: t.string(),
      })),
    });
    

Next Steps

  • Learn about the Plugin system (recommended replacement for generators)
  • Explore TailorDB for database schema definition
  • Understand Migrations for schema evolution

Build docs developers (and LLMs) love