Litestone guide / Misc
TypeScript
litestone types writes a .d.ts from the schema: a row type, create, update, where and order-by types per model, and a typed client. Nothing is needed at runtime; the file is for the editor.
enum Role { admin member }
model User {
id Int
email String
role Role (member)
}
import { generateTypeScript } from '@frontierjs/litestone'
const dts = generateTypeScript(db.$schema)
if (!dts.includes('export interface User {') || !dts.includes('export interface UserCreate {')) throw new Error('expected User and UserCreate')
if (!dts.includes("export type Role = 'admin' | 'member'")) throw new Error('expected the enum as a union')
From a shell it is litestone types, which writes schema.d.ts beside the schema.
What else it can do
litestone types ./db/types.d.tspicks the output path, and--stdoutprints--only=User,Postlimits the output to these models--audience=systemincludes the fields a client never sees, and registers the typed client socreateClient()needs no type argument--augment=junctionadds the module augmentation Junction's service types read- A field with an
@id, a@defaultor a?is optional in the create type ///doc comments become JSDocWhereBaseputs$rawin every where type, andsqlis typed- A plain JavaScript app never runs any of it
In depth: TypeScript § Generate types, § What gets generated, § The typed client, § Doc comments