@dryv/ts-api-clientv0.1.5
A framework-free TypeScript API client over fetch, with typed models and one call per operation.
dryv pack add @dryv/ts-api-clientGenerates a framework-free TypeScript client package: interfaces for every schema, enums, and one typed fetch call per HTTP operation. Any TypeScript frontend can use it; frontend/react-native-app binds it.
| IR | Generated |
|---|---|
| schema | src/models/<schema>.ts: an interface |
| enum | src/enums/<enum>.ts |
| HTTP operation | src/operations/<group>/<operation>.ts: operation(input, options?) → Promise<ApiResult<T>> |
| — | src/transport.ts (configureApi, request, requestBlob), src/index.ts, package.json, tsconfig.json |
Each call takes the operation's single input, like props: a schema input is its model (createUser({ displayName })), named fields an object (getUser({ id })). The call places each field where HTTP binds it (path, query, body or header). Caller-provided request options and headers are preserved, with contract-bound headers added for that operation. Results never throw for HTTP errors: { ok: true, data } or { ok: false, status, message }.
Configure once: configureApi({ baseUrl: "https://api.example.com", headers, credentials: "include" }).
Credential mode is optional per client, and individual operations can override
it through their options argument.
The generated package exposes operation, model, enum, and source subpaths. The source wildcard lets applications add typed API helpers alongside generated contracts, while specific operation/model/enum exports keep their documented paths:
import { listUsers } from "@fixture/api-client/operations/core/list-users";
import type { UserProfile } from "@fixture/api-client/models/user-profile";
import { requestBlob } from "@fixture/api-client/transport";
Provides: operation.client (the calls), schema.types (models), property.enum.types (enums).
The generated package manifest uses package_name for its package name and the
optional package_private boolean to prevent publication of project-internal
clients. It defaults to false for distributable client packages.
Test: bun scripts/test-pack.ts unit/clients/ts-api-client typechecks the package and exercises JSON and binary calls against a mocked fetch.
Response contracts include named composite objects, keyed scalar/reference maps and GeoJSON geometry fields. Map values that need further structure should use named schema, composite or record references; inline structural record expressions require an explicit mapping and are represented as never rather than silently widened. Localized text remains an ordinary reusable project schema; the client imposes no fallback policy. Array outputs preserve their element model type. Imports use generated package addresses, including the transport, so emitted code contains no parent-relative imports.