Skip to content

@smitejs/client ​

Generates a typed, builder-style HTTP client from a Smite app definition.

bash
yarn add @smitejs/client

13 documented symbols · version 2.0.0-SNAPSHOT.0 · source

Codegen ​

functionclient ​

ts
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.

ts
const pluginApp = await compileApp({
  entry,
  alias: sourceAliases,
});
await plugin.run({ apps: [pluginApp] });
ts
"users"
"globalRegistry"

packages/client/src/generate.ts:57

interfaceClientPluginOptions ​

ts
interface ClientPluginOptions {
    readonly outfile: string;
}

Options for the client CLI plugin.

packages/client/src/generate.ts:23

interfaceCollectedEndpoint ​

ts
interface CollectedEndpoint {
    readonly method: string;
    readonly path: string;
    readonly pathParams: readonly string[];
}

A collected endpoint: its method, path template, and path params.

packages/client/src/emit.ts:5

functioncollectEndpoints ​

ts
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 ​

ts
function collectEndpointsFromApps(apps: readonly AppDescriptor[]): readonly CollectedEndpoint[];

Collects endpoints across every compiled app, in order.

packages/client/src/emit.ts:124

functionemitClient ​

ts
function emitClient(endpoints: readonly CollectedEndpoint[]): string;

Renders the builder-client source for a set of endpoints.

packages/client/src/emit.ts:135

functiongenerate ​

ts
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.

ts
const code = await generate(options);
ts
"users"
"$id"

packages/client/src/generate.ts:32

interfaceGenerateOptions ​

ts
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 ​

ts
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 ​

ts
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().

ts
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" },
});
ts
200
{ id: "42" }

packages/client/src/runtime.ts:13

interfaceClientResponse ​

ts
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 ​

ts
function configure(next: ClientConfig): void;

Sets module-level defaults (baseUrl, fetch) for the runtime.

ts
configure({
  baseUrl: "https://api.example.com",
  fetch: async () =>
    new Response(JSON.stringify({ ok: true }), { status: 200 }),
});
const response = await request("GET", "/health");
ts
200
{ ok: true }

packages/client/src/runtime.ts:42

functionrequest ​

ts
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.

ts
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" },
});
ts
200
{ id: "42" }

packages/client/src/runtime.ts:52

Released under the MIT License.

/ search•[ ] prev/next•j/k scroll•h home•t theme•api/smitejs-client