/** * The runtime client (SPEC.md §48). * * It speaks the REST CRUD of SPEC.md §43 and the error model of §83, and it knows * nothing about the server's internals — this package depends on `@assemora/schema` * and on nothing else, so it is safe in a browser bundle. */ export type ClientOptions = { readonly url: string; /** * The language to read and write in (SPEC.md §131). * * A language is a path segment, so this is a base rather than a header: `url` plus * `ru` is `https://…/api/ru`, which is the same API answering in Russian. Left out, * the deployment's default language answers — and in an application that serves one * language there is nothing else it could be. * * The OpenAPI document says the same thing as a server variable, so a client generated * from it and this one reach the same addresses. */ readonly locale?: string; readonly token?: string; /** Injected in tests, and wherever `fetch` is not global. */ readonly fetch?: typeof globalThis.fetch; readonly headers?: Readonly>; }; export type ListQuery = { readonly search?: string; readonly sort?: string; readonly page?: number; readonly perPage?: number; readonly filters?: Readonly>; }; export type Page = { readonly data: readonly T[]; readonly total: number; readonly page: number; readonly perPage: number; readonly lastPage: number; }; export type Created = { readonly id: string; readonly entry: T; }; export type ResourceClient = { list(query?: ListQuery): Promise>; get(id: string): Promise; create(data: Partial): Promise>; update(id: string, data: Partial): Promise>; delete(id: string): Promise<{ readonly id: string; }>; }; /** The error model of SPEC.md §83, as a client sees it. */ export declare class SdkError extends Error { readonly code: string; readonly status: number; readonly details: unknown; readonly fields: Readonly> | undefined; readonly requestId: string | undefined; constructor(status: number, payload: { code?: string; message?: string; details?: unknown; fields?: Readonly>; requestId?: string; }); } /** * The untyped runtime client. * * It deliberately carries no index signature: under `noUncheckedIndexedAccess` one * would make `api.articles` possibly `undefined`, and the `api.articles.list()` of * SPEC.md §48 would not compile. That shorthand is real at runtime and typed by the * generated client, which declares each resource by name. */ export type Client = { readonly resource: (name: string) => ResourceClient; request(method: string, path: string, options?: { body?: unknown; query?: Readonly>; }): Promise; /** * The same client, reading and writing in another language. * * A second client rather than a mode on this one: a language decides what every answer * *is*, and a client that could change it under a caller holding a reference would be * one whose earlier reads and later reads disagree with nothing saying so. */ inLocale(locale: string): Client; }; export declare const createClient: (options: ClientOptions) => Client; //# sourceMappingURL=client.d.ts.map