@smitejs/client
Generates a typed, builder-style HTTP client from a Smite app definition.
yarn add @smitejs/client13 documented symbols · version 2.0.0-SNAPSHOT.0 · source
Codegen
functionclient
function client(options: ClientPluginOptions): SmitePlugin;CLI plugin factory for @smitejs/cli: a client plugin whose run emits the typed client from the compiled app node.
const pluginApp = await compileApp({
entry,
alias: sourceAliases,
});
await plugin.run({ apps: [pluginApp] });"users"
"globalRegistry"packages/client/src/generate.ts:57
interfaceClientPluginOptions
interface ClientPluginOptions {
readonly outfile: string;
}Options for the client CLI plugin.
packages/client/src/generate.ts:23
interfaceCollectedEndpoint
interface CollectedEndpoint {
readonly method: string;
readonly path: string;
readonly pathParams: readonly string[];
}A collected endpoint: its method, path template, and path params.
functioncollectEndpoints
function collectEndpoints(app: AppDescriptor): readonly CollectedEndpoint[];Traverses an app descriptor's http.route/http.endpoint children and returns the collected endpoints. ANY endpoints are skipped with a warning.
packages/client/src/emit.ts:94
functioncollectEndpointsFromApps
function collectEndpointsFromApps(apps: readonly AppDescriptor[]): readonly CollectedEndpoint[];Collects endpoints across every compiled app, in order.
packages/client/src/emit.ts:124
functionemitClient
function emitClient(endpoints: readonly CollectedEndpoint[]): string;Renders the builder-client source for a set of endpoints.
packages/client/src/emit.ts:135
functiongenerate
function generate(options: GenerateOptions): Promise<string>;Compiles the app entry in collect mode, executes it, traverses the registry, and emits a builder-style typed client to outfile. Returns the generated source. Shares compileApp with the CLI, so the standalone API and the client() plugin behave identically.
const code = await generate(options);"users"
"$id"packages/client/src/generate.ts:32
interfaceGenerateOptions
interface GenerateOptions {
readonly entry: string;
readonly outfile: string;
readonly appName?: string;
readonly alias?: Readonly<Record<string, string>>;
}Options for generate().
packages/client/src/generate.ts:11
Runtime
interfaceClientConfig
interface ClientConfig {
readonly baseUrl?: string;
readonly fetch?: typeof globalThis.fetch;
}Global runtime defaults (baseUrl, fetch) set via configure().
packages/client/src/runtime.ts:3
interfaceClientInput
interface ClientInput {
readonly params?: Readonly<Record<string, unknown>>;
readonly query?: Readonly<Record<string, unknown>>;
readonly headers?: Readonly<Record<string, string>>;
readonly body?: unknown;
readonly $config?: ClientConfig;
}The bucketed input shape accepted by generated calls and request().
configure({
baseUrl: "https://api.example.com",
fetch: async () =>
new Response(JSON.stringify({ id: "42" }), { status: 200 }),
});
const response = await request("GET", "/users/:id", {
params: { id: "42" },
query: { verbose: "1" },
});200
{ id: "42" }packages/client/src/runtime.ts:13
interfaceClientResponse
interface ClientResponse {
readonly status: number;
readonly body: unknown;
readonly headers: Readonly<Record<string, string>>;
}The shape returned by every generated call: mirrors the server response.
packages/client/src/runtime.ts:29
functionconfigure
function configure(next: ClientConfig): void;Sets module-level defaults (baseUrl, fetch) for the runtime.
configure({
baseUrl: "https://api.example.com",
fetch: async () =>
new Response(JSON.stringify({ ok: true }), { status: 200 }),
});
const response = await request("GET", "/health");200
{ ok: true }packages/client/src/runtime.ts:42
functionrequest
function request(method: string, path: string, input?: ClientInput): Promise<ClientResponse>;Performs an HTTP request: interpolates path params, serializes query/body, and returns { status, body, headers }. Never throws on non-2xx.
configure({
baseUrl: "https://api.example.com",
fetch: async () =>
new Response(JSON.stringify({ id: "42" }), { status: 200 }),
});
const response = await request("GET", "/users/:id", {
params: { id: "42" },
query: { verbose: "1" },
});200
{ id: "42" }