Skip to content

GolemWrite the type once. Generate the rest.

One toolchain for a TypeScript app's API contract, end to end. Models, validation, JSON conversion, OpenAPI documents and a typed SDK come from the types you already write.

task.model.tsinput
export type TTask = IModel<{  title: string & MinLength<1>;  done: boolean;  priority: number    & TSerde<typeof toPriorityWord, typeof fromPriorityWord>;}>;
01Model base HOCextends model<TTask>()
02Validationtitle: MinLength<1>
03JSON conversionpriority 2 → "normal"

Start from any contract, run one command ​

Start from what you have: TypeScript types, an OpenAPI document or server controllers. Each generator installs on its own. All of them run through the same golem command and read the same golem.yaml.

YOU HAVEGENERATORRUNS THEMYOU GETTypeScript types*.model.tsOpenAPI document3.1 · 3.2Server controllersframework: nestjsgolem-modelmodelsgolem-openapi-tstyped clientgolem-ts-openapiOpenAPI from controllersfileswrites openapi.yamlSDK typesgolem CLIgolem.yamlJOB ORDER1 generators2 controllers3 openapi4 modelstracks files in.golem/.golem/models/codecs · validators · typesSDKoperations · models · validatorsopenapi.yamlOpenAPI 3.2 or 3.1writesAT BUILD TIMEYour sourceparse<Task>(text)Build toolgolem build · Vite · esbuild · NodeRunning app+ @exprtlabs/golembuildsrewritesimports
Generators only return file contents. The golem command writes the files and records which job owns each one. Jobs run in a fixed order, so one golem.yaml can chain controllers into an OpenAPI document, then into a typed client and app models. Your own generator packages run first, in the generators job.

Four packages, one job each ​

@exprtlabs/golem

Runtime, CLI and build tools

Every generated model and client imports it. It holds parse, stringify, the CLI, the build tools and the optional integrations.

dependencies
@exprtlabs/golem-model

You have TypeScript fields

You get validation and JSON conversion for your models. Your class extends model<T>() and keeps its methods.

devDependencies
@exprtlabs/golem-openapi-ts

You have an OpenAPI document

You get typed operations and request and response models. The client checks what it sends and what it receives.

devDependencies; dependencies with MobX
@exprtlabs/golem-ts-openapi

You have server controllers

You get an OpenAPI document from controller routes and types. It reads NestJS 11 controllers without starting the app.

devDependencies; dependencies with NestJS

Which package you need · Quick start

What you get from one declaration ​

TypeScript is the schema

Tags on a field type set its validation and its JSON form. You write no decorators, no schema language and no second copy of the fields. Your code sees the plain type.

name: string & MinLength<2>

Compiled validators

Golem compiles validators directly into TypeScript files under .golem/models/. Nothing reads decorator metadata at runtime. Validation is on by default, and a valid value takes the fast path.

validation: true # default

Strict by default

Golem rejects bad input and never coerces it. A model refuses unknown fields and any. A format that Golem cannot check stops generation.

LibError { causedByInput: true }

Your own JSON forms

A serde tag ties a field to two functions. Your code keeps a number, a Temporal date or minor units. The JSON holds a word, an ISO string or decimal text.

TSerde<typeof to, typeof from>

Your code survives regeneration

Golem writes generated files into .golem/models/, leaving src/ clean. Your class extends model<T>() with zero imports from generated files.

class Task extends model<TTask>()

Types end to end

Server controllers produce the OpenAPI document. The client generator turns that document back into typed operations and models for the web app.

controllers → openapi → client

Safe with your files

A job writes over a file only when it owns that file. Any other file at that path stops the run. golem check writes nothing and fails on stale output.

npx golem check

Any build tool

A build tool rewrites model<T>(), parse<T>() and the other serde calls to generated code. Use golem build, the Vite plugin, the esbuild plugin or the Node loader.

npx golem build

Define models · Validation tags · Serialization · Build tools

Bring the libraries you already use ​

Every integration is optional. Golem works with any mix of them, or with none. Each one is a subpath of the runtime package or a job in golem.yaml.

NestJS

^11
@exprtlabs/golem-ts-openapi/nest

The model interceptor converts and checks @Body() and @Query() models, and answers bad input with HTTP 400 (a default; your own interceptor can answer otherwise). A docs job writes the OpenAPI document, and the nest extension turns on the build rewrite that the interceptor needs.

MobX and React

^6.13
@exprtlabs/golem-openapi-ts/mobx

With the mobx extension, validators keep observable form state, and client operations have an observable loading. asGenObservable makes generated fields observable.

Vite

≥5
@exprtlabs/golem/vite

Add golem() to plugins. The plugin rewrites serde calls in the dev server and in the build.

esbuild

^0.25
@exprtlabs/golem/esbuild

Add golem() to plugins. The plugin rewrites serde calls when esbuild bundles your app.

Node.js loader

≥22.15
node --import @exprtlabs/golem/register

Run TypeScript files directly. The loader rewrites serde calls as Node.js loads each file.

Your own generator

apiVersion 2
"golem": { "block": "…" }

A package exports generate(context) and returns files. Golem writes them. Your package registers its own golem.yaml block.

NestJS · MobX and React · Build tools · Write a generator

Bad data stops at three gates ​

A generated client and your server share one contract. Each side checks the data that crosses to it. On any server, parse<T> and validate<T> do the server check. With NestJS, the model interceptor does it for you.

WEB APPNETWORKYOUR SERVERGenerated clientcreatePayment(input)1checks the requestparse · interceptorvalidates · builds model2Your handlergets a valid modelsends JSONvalidHTTP 400bad inputresponse3checks the response
In the payments example, a NestJS server's controllers write server/api/openapi.yaml. The web app generates its client from that file, with MobX on. Amounts travel as decimal strings, so no float carries money.

Start where you are ​

Install the runtime and the generator for your starting point:

sh
npm install @exprtlabs/golem
npm install --save-dev @exprtlabs/golem-model typescript@~7.1.0-beta
sh
npm install @exprtlabs/golem
npm install --save-dev @exprtlabs/golem-openapi-ts typescript@~7.1.0-beta
sh
npm install @exprtlabs/golem
npm install --save-dev @exprtlabs/golem-ts-openapi typescript@~7.1.0-beta

Then add its job to golem.yaml:

yaml
version: 1
model: {}
yaml
- input: provider/provider.yaml
  output: provider/sdk
  name: Provider
yaml
ts-openapi:
  docs:
    - output: ./api/openapi.yaml
      info:
        title: Payments API
        version: '1'
      globalPrefix: api
  extensions:
    nest: {}

Run npx golem generate for your editor, then npx golem build to compile. The quick start takes one model from declaration to a running app.

JSON Schema rules, written as types ​

Each tag is a TypeScript type. Golem turns it into a check in the validator, a constraint in the OpenAPI document and a check in the client.

NumbersInteger · Minimum<N> · Maximum<N> · ExclusiveMinimum<N> · ExclusiveMaximum<N> · MultipleOf<N>
StringsMinLength<N> · MaxLength<N> · Pattern<'…'> · Format<'…'>
ArraysMinItems<N> · MaxItems<N> · UniqueItems · Contains<T> · MinContains<N> · MaxContains<N>
ObjectsMinProperties<N> · MaxProperties<N> · PropertyNames<T> · PatternProperties<Map> · AdditionalProperties<T> · UnevaluatedProperties<T>
Related fieldsDependentRequired<Map> · DependentSchemas<Map>
Alternatives and custom rulesOneOf<Tuple> · Not<T> · IfThenElse<C, T, E> · TValidation<typeof rule>

Validation tags · Validate models

What Golem does for each job ​

Golem reads the types you already write and generates each piece from them. You keep one declaration for each model.

JobHow Golem does it
Classes from JSONparse<Task>(text)
Validationtags on the field type
Your own JSON formsa serde tag on the field type
OpenAPI from NestJSread from the controller's types
OpenAPI to TypeScript SDKtyped operations with validated models

What it runs on ​

≥ 22.15.0Node.js
7.1+TypeScript
3.1 · 3.2OpenAPI input
3.2.0 · 3.1.2OpenAPI output
all optionalNestJS ^11 · MobX ^6.13 · Vite ≥5 · esbuild ^0.25 · ESLint ^9 or ^10

The configuration format and the public subpaths of @exprtlabs/golem follow semver (Compatibility).