Generating types
jsorm gen analyzes your models and generates types + runtime files.
pnpm jsorm genGenerated files
Section titled “Generated files”| 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.
Runtime file (server)
Section titled “Runtime file (server)”The generated jsorm.server.ts contains:
// Generated by jsorm gen — do not edit manuallyimport { 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 };Dry run
Section titled “Dry run”To see what would be generated without writing files:
pnpm jsorm gen --dry-runWatch mode
Section titled “Watch mode”Automatically regenerates when model changes are detected:
pnpm jsorm watchUses chokidar for file watching with debounce.
