Generating a typed client
Compiling your server into a TypeScript client at build time.
package @smitejs/client
@smitejs/client is the codegen engine: it builds your server entry, runs it once at build time to discover the declared routes, and emits a TypeScript client that mirrors them. It is the same engine the future CLI will drive, and it produces fully typed code with no reflection at runtime.
How it works
generate({ entry, outfile }) does this:
- Builds
entrywith esbuild (bundling the app and its dependencies). - Executes the bundle, which runs
http.app()at module scope. - Reads the declared routes and endpoints.
- Emits a builder-style client to
outfileand returns the generated source.
ts
const code = await generate(options);ts
"users"
"$id"tested in packages/client/src/index.test.ts:64
Options
entry— the module that builds the app (must callhttp.app()at module scope).outfile— where the generated client is written.appName— disambiguates when a single build declares more than one app.alias— maps package names (@smitejs/http,@smitejs/core) to source paths so the build resolves local sources.
Build-time, not runtime
Every route is known at compile time. The generated client imports only @smitejs/client/runtime — a small fetch layer, nothing else — so it stays small, tree-shakeable, and free of build-time machinery.