Skip to content

Generating types

jsorm gen analyzes your models and generates types + runtime files.

Terminal window
pnpm jsorm gen
File Location Content
types.ts .jsorm/ Record interfaces, query types, DB, DBClient
jsorm.server.ts src/models/ Server instance with createJsorm<DB>
jsorm.client.ts src/models/ Client instance (if client databases exist)

The relative-path depth (../../ in this example) is computed from the configured models directory up to the root .jsorm/; with a different models path, the number of ../ changes.

The generated jsorm.server.ts contains:

// Generated by jsorm gen — do not edit manually
import { createJsorm } from "@jsorm/client";
import { type DB } from "../../.jsorm/types.js";
import config from "../../jsorm.config.js";
import { createSqliteNodeProvider } from "@jsorm/provider-sqlite-node";
import { createPostgresNodeProvider } from "@jsorm/provider-pg-node";
import { User } from "./server/main/User.js";
import { UserCache } from "./server/cache/User.js";
const allModels = [User, UserCache] as const;
const jsorm = createJsorm<DB>(config, allModels, {
"cache": (ctx) => createSqliteNodeProvider(ctx.models, ctx.options),
"main": (ctx) => createPostgresNodeProvider(ctx.models, ctx.options),
});
export { jsorm, type DB };

To see what would be generated without writing files:

Terminal window
pnpm jsorm gen --dry-run

Automatically regenerates when model changes are detected:

Terminal window
pnpm jsorm watch

Uses chokidar for file watching with debounce.