@voltro/api-client 0.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13518 -0
- package/LICENSE +61 -0
- package/README.md +26 -0
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +11 -0
- package/dist/index.d.ts +566 -0
- package/dist/index.js +787 -0
- package/package.json +38 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
export declare interface ApiClientBindings {
|
|
2
|
+
readonly manifest: ClientManifest;
|
|
3
|
+
/** The app's declared error classes by tag — the generated `errors`. */
|
|
4
|
+
readonly errors: ErrorClasses;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export declare interface ApiClientConfig extends RestClientConfig {
|
|
8
|
+
/** The socket the live queries ride — derived from `baseUrl` by default,
|
|
9
|
+
* opened on the first `subscribe`. */
|
|
10
|
+
readonly subscriptions?: LiveQueriesConfig | undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The base of every error the client raises: a `_tag`, the HTTP `status`
|
|
14
|
+
* when there was an answer, the `x-request-id` when the server sent one. */
|
|
15
|
+
export declare abstract class ApiClientError extends Error {
|
|
16
|
+
abstract readonly _tag: string;
|
|
17
|
+
readonly status: number | undefined;
|
|
18
|
+
readonly requestId: string | undefined;
|
|
19
|
+
constructor(message: string, meta?: ErrorMeta, options?: {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
});
|
|
22
|
+
get name(): string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare type ApiClientOwnError = TransportError | ApiHttpError | RateLimitedError | ProfileMismatchError | InputEncodeError;
|
|
26
|
+
|
|
27
|
+
/** A non-2xx answer whose body is not one of the descriptor's typed errors:
|
|
28
|
+
* the transport's refusals (400, 401, 403, 404, 410, 500) and anything
|
|
29
|
+
* unknown. `errorTag` is the URN's tag under problem details. */
|
|
30
|
+
export declare class ApiHttpError extends ApiClientError {
|
|
31
|
+
readonly _tag: "ApiHttpError";
|
|
32
|
+
readonly tag: string;
|
|
33
|
+
readonly status: number;
|
|
34
|
+
readonly errorTag: string | undefined;
|
|
35
|
+
readonly detail: string | undefined;
|
|
36
|
+
readonly body: unknown;
|
|
37
|
+
constructor(fields: {
|
|
38
|
+
readonly tag: string;
|
|
39
|
+
readonly status: number;
|
|
40
|
+
readonly errorTag?: string | undefined;
|
|
41
|
+
readonly detail?: string | undefined;
|
|
42
|
+
readonly body: unknown;
|
|
43
|
+
readonly requestId?: string | undefined;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Apply a patch to `prev`: `add`/`replace` set the id's row, `mergeCells`
|
|
49
|
+
* folds columns into it, and the result is materialised strictly in the
|
|
50
|
+
* patch's `order` — a `remove`d id is absent from it. An id in `order` that
|
|
51
|
+
* resolves to no row (a desync) is skipped rather than thrown.
|
|
52
|
+
*/
|
|
53
|
+
export declare const applyRowPatch: (prev: ReadonlyArray<PatchRow>, patch: RowPatch, options?: ApplyRowPatchOptions) => ReadonlyArray<PatchRow>;
|
|
54
|
+
|
|
55
|
+
export declare interface ApplyRowPatchOptions {
|
|
56
|
+
/** Fold a `mergeCells` update into the held cell; without one the update
|
|
57
|
+
* replaces the cell. */
|
|
58
|
+
readonly mergeCell?: ((column: string, prevValue: unknown, update: unknown) => unknown) | undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export declare const buildNamespaces: (client: PromiseClient) => Namespaces;
|
|
62
|
+
|
|
63
|
+
export declare interface CallOptions {
|
|
64
|
+
readonly signal?: AbortSignal | undefined;
|
|
65
|
+
/** Overrides the generated key for an idempotent mutation. */
|
|
66
|
+
readonly idempotencyKey?: string | undefined;
|
|
67
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** One decoded answer: the value, the cursor of the next page when there is
|
|
71
|
+
* one, and what the transport learned. */
|
|
72
|
+
export declare interface CallResult<A = unknown> {
|
|
73
|
+
readonly value: A;
|
|
74
|
+
readonly nextCursor: string | undefined;
|
|
75
|
+
readonly status: number;
|
|
76
|
+
readonly requestId: string | undefined;
|
|
77
|
+
readonly etag: string | undefined;
|
|
78
|
+
readonly fromCache: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export declare interface ClientManifest {
|
|
82
|
+
/** The generated package's name and version — the `User-Agent` line. */
|
|
83
|
+
readonly name?: string;
|
|
84
|
+
readonly version?: string;
|
|
85
|
+
/** The API version the client was generated for (`--version v2`). */
|
|
86
|
+
readonly apiVersion?: string;
|
|
87
|
+
readonly profile: ClientProfile;
|
|
88
|
+
readonly servers: ReadonlyArray<ClientServer>;
|
|
89
|
+
readonly projections: ReadonlyArray<ClientProjection>;
|
|
90
|
+
/** The wire shapes: which fields are dates, which keys are renamed, what
|
|
91
|
+
* each declared error carries. */
|
|
92
|
+
readonly wire: WireBindings;
|
|
93
|
+
/** The digest of the bindings the client was generated from; the spec
|
|
94
|
+
* publishes the current one as `x-voltro-surface-digest`. */
|
|
95
|
+
readonly digest: string;
|
|
96
|
+
/** `voltro-ts <cli version>`. */
|
|
97
|
+
readonly generatedBy: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export declare type ClientMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
101
|
+
|
|
102
|
+
export declare type ClientProcedureKind = 'query' | 'mutation' | 'action' | 'stream';
|
|
103
|
+
|
|
104
|
+
/** The profile facts a client needs to speak the surface: what the server's
|
|
105
|
+
* `RestFormat` decided, minus its encoder hooks. */
|
|
106
|
+
export declare interface ClientProfile {
|
|
107
|
+
readonly name: string;
|
|
108
|
+
readonly dates: 'iso' | 'epoch-ms';
|
|
109
|
+
readonly errors: 'problem-details' | 'tagged';
|
|
110
|
+
readonly envelope: 'none' | 'data' | 'jsonapi';
|
|
111
|
+
readonly pagination: 'link-header' | 'body-cursor';
|
|
112
|
+
readonly cursorField: string;
|
|
113
|
+
readonly cursorParam: string;
|
|
114
|
+
readonly naming: 'camelCase' | 'snake_case';
|
|
115
|
+
readonly etag: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** One `publicApi` projection as the client calls it. */
|
|
119
|
+
export declare interface ClientProjection {
|
|
120
|
+
readonly tag: string;
|
|
121
|
+
readonly kind: ClientProcedureKind;
|
|
122
|
+
readonly method: ClientMethod;
|
|
123
|
+
/** The route pattern with `:name` parameters (`/v1/teams/:teamId`). */
|
|
124
|
+
readonly path: string;
|
|
125
|
+
/** The input fields the path binds, in path order. */
|
|
126
|
+
readonly pathParams: ReadonlyArray<string>;
|
|
127
|
+
readonly version: string;
|
|
128
|
+
readonly security: 'required' | 'optional' | 'none';
|
|
129
|
+
readonly scopes?: ReadonlyArray<string>;
|
|
130
|
+
/** Sends `Idempotency-Key` automatically (a UUID v7 per call). */
|
|
131
|
+
readonly idempotent?: boolean;
|
|
132
|
+
readonly sunset?: string;
|
|
133
|
+
readonly deprecated?: string;
|
|
134
|
+
/** The typed errors the projection answers with, by tag, and the status
|
|
135
|
+
* each is answered with. */
|
|
136
|
+
readonly errorStatus?: Readonly<Record<string, number>>;
|
|
137
|
+
/** Whether the output carries the profile's cursor field — the route can
|
|
138
|
+
* answer with a next page. */
|
|
139
|
+
readonly paginates: boolean;
|
|
140
|
+
readonly summary?: string;
|
|
141
|
+
readonly operationId?: string;
|
|
142
|
+
readonly tags?: ReadonlyArray<string>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export declare interface ClientServer {
|
|
146
|
+
readonly url: string;
|
|
147
|
+
readonly description?: string;
|
|
148
|
+
readonly environment?: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The whole client in one call: the namespaces plus `close` and the raw
|
|
152
|
+
* `call`/`pages` by tag. What a generated package's `createClient(config)`
|
|
153
|
+
* returns. */
|
|
154
|
+
export declare const createClient: (bindings: ApiClientBindings, config?: ApiClientConfig) => Namespaces & PromiseClient;
|
|
155
|
+
|
|
156
|
+
export declare const createMockClient: (manifest: ClientManifest, errors?: ErrorClasses) => MockClient & Namespaces;
|
|
157
|
+
|
|
158
|
+
export declare const createPromiseClient: (bindings: ApiClientBindings, config?: ApiClientConfig) => PromiseClient;
|
|
159
|
+
|
|
160
|
+
/** The `cursor` parameter of the `rel="next"` link. */
|
|
161
|
+
export declare const cursorFromLink: (link: string | null, param: string) => string | undefined;
|
|
162
|
+
|
|
163
|
+
/** An error the app declares on a descriptor, decoded from the answer: its
|
|
164
|
+
* `_tag`, its fields as properties, the status it was answered with. */
|
|
165
|
+
export declare class DeclaredError<Tag extends string = string> extends ApiClientError {
|
|
166
|
+
readonly _tag: Tag;
|
|
167
|
+
readonly detail: string | undefined;
|
|
168
|
+
constructor(tag: Tag, fields: Readonly<Record<string, unknown>>, meta?: ErrorMeta);
|
|
169
|
+
/** The fields and the tag — what the server sent, without the meta. */
|
|
170
|
+
toJSON(): Record<string, unknown>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The constructor a generated package extends per declared error. */
|
|
174
|
+
export declare type DeclaredErrorClass<Tag extends string> = new <Fields extends Record<string, unknown> = {}>(fields: Fields, meta?: ErrorMeta) => DeclaredError<Tag> & Readonly<Fields>;
|
|
175
|
+
|
|
176
|
+
/** Any declared error class, as the runtime holds it — the fields are the
|
|
177
|
+
* answer's, so the parameter is `never` here and the class's own where it
|
|
178
|
+
* is declared. */
|
|
179
|
+
export declare interface DeclaredErrorConstructor {
|
|
180
|
+
new (fields: never, meta?: ErrorMeta): DeclaredError;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The failure of a declared error tag, as the app's class when the package
|
|
184
|
+
* declares one — else an `ApiHttpError` carrying the tag. */
|
|
185
|
+
export declare const declaredErrorOf: (manifest: ClientManifest, errors: ErrorClasses, projectionTag: string, tag: string | undefined, fields: Record<string, unknown>, meta: {
|
|
186
|
+
readonly status: number;
|
|
187
|
+
readonly requestId: string | undefined;
|
|
188
|
+
readonly detail: string | undefined;
|
|
189
|
+
readonly body: unknown;
|
|
190
|
+
}) => unknown;
|
|
191
|
+
|
|
192
|
+
/** A wire value → the caller's form: dates revived, keys folded back to the schema's names. */
|
|
193
|
+
export declare const decodeWire: (type: WireType | undefined, value: unknown, options: WireCodecOptions) => unknown;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* export class NotFoundError extends defineError('NotFoundError')<{ readonly id: string }> {}
|
|
197
|
+
*
|
|
198
|
+
* The class the runtime instantiates when an answer carries that tag; the
|
|
199
|
+
* fields become properties, `status` and `requestId` ride along.
|
|
200
|
+
*/
|
|
201
|
+
export declare const defineError: <const Tag extends string>(tag: Tag) => DeclaredErrorClass<Tag>;
|
|
202
|
+
|
|
203
|
+
/** A caller's value → the wire form: dates per the profile, keys per the naming. */
|
|
204
|
+
export declare const encodeWire: (type: WireType | undefined, value: unknown, options: WireCodecOptions) => unknown;
|
|
205
|
+
|
|
206
|
+
/** The declared error classes by tag — what a generated package's `errors`
|
|
207
|
+
* export is, and what the runtime instantiates from. */
|
|
208
|
+
export declare type ErrorClasses = Readonly<Record<string, DeclaredErrorConstructor>>;
|
|
209
|
+
|
|
210
|
+
export declare interface ErrorMeta {
|
|
211
|
+
readonly status?: number | undefined;
|
|
212
|
+
readonly requestId?: string | undefined;
|
|
213
|
+
readonly detail?: string | undefined;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Whether `type` (resolved) declares any required field — the generated
|
|
217
|
+
* call signature makes the input optional when it does not. */
|
|
218
|
+
export declare const hasRequiredField: (type: WireType | undefined, models: Readonly<Record<string, WireType>>) => boolean;
|
|
219
|
+
|
|
220
|
+
/** The input did not encode through the projection's wire shape. */
|
|
221
|
+
export declare class InputEncodeError extends ApiClientError {
|
|
222
|
+
readonly _tag: "InputEncodeError";
|
|
223
|
+
readonly tag: string;
|
|
224
|
+
constructor(fields: {
|
|
225
|
+
readonly tag: string;
|
|
226
|
+
readonly message: string;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export declare interface LiveQueries {
|
|
231
|
+
/** The current value of `tag(input)` and every change to it. Ends when the
|
|
232
|
+
* consumer returns, or the server ends the stream; throws the app's own
|
|
233
|
+
* error class on an in-band or exit error. */
|
|
234
|
+
readonly subscribe: (tag: string, input?: unknown) => AsyncIterable<unknown>;
|
|
235
|
+
readonly close: () => Promise<void>;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export declare interface LiveQueriesConfig {
|
|
239
|
+
/** `wss://host/ws`. Default: derived from the REST base URL (`https://` →
|
|
240
|
+
* `wss://`, path `/ws`). */
|
|
241
|
+
readonly wsUrl?: string | undefined;
|
|
242
|
+
readonly token?: TokenSource | undefined;
|
|
243
|
+
readonly tenant?: string | undefined;
|
|
244
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
245
|
+
/** The WebSocket to construct — the global by default; Node 20 hands in `ws`. */
|
|
246
|
+
readonly webSocketConstructor?: ((url: string) => WebSocketLike) | undefined;
|
|
247
|
+
/** A `Ping` every so often; a missing `Pong` by the next one reconnects. Default 10 s. */
|
|
248
|
+
readonly pingIntervalMs?: number | undefined;
|
|
249
|
+
/** The reconnect backoff: `initialMs` × 1.5 per attempt, capped at `maxMs`. Default 500 ms → 5 s. */
|
|
250
|
+
readonly reconnect?: {
|
|
251
|
+
readonly initialMs?: number | undefined;
|
|
252
|
+
readonly maxMs?: number | undefined;
|
|
253
|
+
} | undefined;
|
|
254
|
+
/** Observe the socket: opened, closed, reconnecting (with the delay). */
|
|
255
|
+
readonly onStatus?: ((status: LiveStatus) => void) | undefined;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export declare type LiveStatus = {
|
|
259
|
+
readonly kind: 'connecting';
|
|
260
|
+
readonly attempt: number;
|
|
261
|
+
} | {
|
|
262
|
+
readonly kind: 'open';
|
|
263
|
+
} | {
|
|
264
|
+
readonly kind: 'closed';
|
|
265
|
+
readonly reconnectInMs: number | undefined;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Build the transport. Pure construction; the first request is the first
|
|
270
|
+
* network activity.
|
|
271
|
+
*/
|
|
272
|
+
export declare const makeRestCore: (manifest: ClientManifest, errors: ErrorClasses, config?: RestClientConfig) => RestCore;
|
|
273
|
+
|
|
274
|
+
export declare interface MockClient extends PromiseClient {
|
|
275
|
+
/** The next call of `tag` answers `value` (every call, until changed). */
|
|
276
|
+
readonly setData: (tag: string, value: unknown) => void;
|
|
277
|
+
/** The next call of `tag` fails with `error` — an instance of the app's own
|
|
278
|
+
* error class, a `RateLimitedError`, anything. `times` limits it (default:
|
|
279
|
+
* every call); after that the data answer applies again. */
|
|
280
|
+
readonly setError: (tag: string, error: unknown, times?: number) => void;
|
|
281
|
+
/** `pages()` of `tag` yields these, in order. An `Error` in the list is
|
|
282
|
+
* thrown at that page. */
|
|
283
|
+
readonly setPages: (tag: string, pages: ReadonlyArray<unknown>) => void;
|
|
284
|
+
/** Push a value to every live subscription of `tag`. */
|
|
285
|
+
readonly push: (tag: string, value: unknown) => void;
|
|
286
|
+
readonly subscribe: (tag: string, input?: unknown) => AsyncIterable<unknown>;
|
|
287
|
+
/** Every call so far: tag, input. */
|
|
288
|
+
readonly calls: ReadonlyArray<{
|
|
289
|
+
readonly tag: string;
|
|
290
|
+
readonly input: unknown;
|
|
291
|
+
}>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** One callable per projection: `api.teams.list(input)`, with `.pages(input)`
|
|
295
|
+
* beside it, grouped by the tag prefix. The generated package types this
|
|
296
|
+
* from the wire shapes; the runtime builds the values. */
|
|
297
|
+
export declare interface NamespacedCall {
|
|
298
|
+
(input?: unknown, options?: CallOptions): Promise<unknown>;
|
|
299
|
+
readonly pages: (input?: unknown, options?: CallOptions) => AsyncIterable<unknown>;
|
|
300
|
+
readonly subscribe: (input?: unknown) => AsyncIterable<unknown>;
|
|
301
|
+
readonly tag: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export declare type Namespaces = Readonly<Record<string, Readonly<Record<string, NamespacedCall>> | NamespacedCall>>;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Open the socket lazily — on the first subscription — and share it across
|
|
308
|
+
* every subscription of this client; close it when the last one ends.
|
|
309
|
+
*/
|
|
310
|
+
export declare const openLiveQueries: (manifest: ClientManifest, errors: ErrorClasses, baseUrl: string, config?: LiveQueriesConfig) => LiveQueries;
|
|
311
|
+
|
|
312
|
+
/** Every page, as an async iterable — `for await (const page of …)`. */
|
|
313
|
+
export declare const pagesOf: (callRaw: (input: unknown, options?: CallOptions) => Promise<CallResult>, cursorParam: string, input: unknown, options?: CallOptions) => AsyncIterable<unknown>;
|
|
314
|
+
|
|
315
|
+
export declare type PatchRow = Readonly<Record<string, unknown>> & {
|
|
316
|
+
readonly id: RowId;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/** Inverse of the producer's `idToPath`: `/<id>` with `~1` → `/`, `~0` → `~`. */
|
|
320
|
+
export declare const pathToId: (path: string) => string;
|
|
321
|
+
|
|
322
|
+
/** The API answers with a profile the client was not generated for
|
|
323
|
+
* (`x-voltro-rest-profile`). Raised on the first call that sees it. */
|
|
324
|
+
export declare class ProfileMismatchError extends ApiClientError {
|
|
325
|
+
readonly _tag: "ProfileMismatchError";
|
|
326
|
+
readonly expected: string;
|
|
327
|
+
readonly actual: string;
|
|
328
|
+
constructor(fields: {
|
|
329
|
+
readonly expected: string;
|
|
330
|
+
readonly actual: string;
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export declare const projectionOf: (manifest: ClientManifest, tag: string) => ClientProjection;
|
|
335
|
+
|
|
336
|
+
/** What every client — the real one, the mock — exposes by tag. */
|
|
337
|
+
export declare interface PromiseClient {
|
|
338
|
+
readonly manifest: ClientManifest;
|
|
339
|
+
readonly errors: ErrorClasses;
|
|
340
|
+
readonly call: (tag: string, input?: unknown, options?: CallOptions) => Promise<unknown>;
|
|
341
|
+
readonly callRaw: (tag: string, input?: unknown, options?: CallOptions) => Promise<CallResult>;
|
|
342
|
+
/** Every page of a paginated query, following the profile's cursor
|
|
343
|
+
* (`Link: …; rel="next"` or the body's cursor field) until there is none. */
|
|
344
|
+
readonly pages: (tag: string, input?: unknown, options?: CallOptions) => AsyncIterable<unknown>;
|
|
345
|
+
/** The current value of a query and every change to it, over the rpc
|
|
346
|
+
* socket (a mock answers its `push`es here). Ends when the consumer
|
|
347
|
+
* returns; throws the app's own error class on an error. */
|
|
348
|
+
readonly subscribe: (tag: string, input?: unknown) => AsyncIterable<unknown>;
|
|
349
|
+
readonly close: () => Promise<void>;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** 429 with the wait the server asked for — a wait, not a failure, when the
|
|
353
|
+
* client is configured to honour it (`retry.on429`). */
|
|
354
|
+
export declare class RateLimitedError extends ApiClientError {
|
|
355
|
+
readonly _tag: "RateLimitedError";
|
|
356
|
+
readonly tag: string;
|
|
357
|
+
readonly retryAfterMs: number;
|
|
358
|
+
readonly limit: number | undefined;
|
|
359
|
+
readonly remaining: number | undefined;
|
|
360
|
+
readonly resetAtMs: number | undefined;
|
|
361
|
+
constructor(fields: {
|
|
362
|
+
readonly tag: string;
|
|
363
|
+
readonly retryAfterMs: number;
|
|
364
|
+
readonly limit?: number | undefined;
|
|
365
|
+
readonly remaining?: number | undefined;
|
|
366
|
+
readonly resetAtMs?: number | undefined;
|
|
367
|
+
readonly requestId?: string | undefined;
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export declare interface RestClientConfig {
|
|
372
|
+
/** Default: the manifest's first server. */
|
|
373
|
+
readonly baseUrl?: string | undefined;
|
|
374
|
+
/** A personal access token or a team key — sent as `Authorization: Bearer`.
|
|
375
|
+
* A function is asked per request, so a rotated token needs no restart. */
|
|
376
|
+
readonly token?: TokenSource | undefined;
|
|
377
|
+
/** `x-tenant`. */
|
|
378
|
+
readonly tenant?: string | undefined;
|
|
379
|
+
/** Headers on every request. */
|
|
380
|
+
readonly headers?: Readonly<Record<string, string>> | undefined;
|
|
381
|
+
/** The `fetch` to use — the global by default; a test hands in its own. */
|
|
382
|
+
readonly fetch?: typeof fetch | undefined;
|
|
383
|
+
/** `User-Agent`; default `<name>/<version> (voltro-ts <cli>)` from the manifest. */
|
|
384
|
+
readonly userAgent?: string | undefined;
|
|
385
|
+
/** Honour `Retry-After` on a 429 by waiting and retrying — up to `maxWaitMs`
|
|
386
|
+
* per call in total. Off by default: a 429 is then a `RateLimitedError`. */
|
|
387
|
+
readonly retry?: {
|
|
388
|
+
readonly on429?: {
|
|
389
|
+
readonly maxWaitMs: number;
|
|
390
|
+
} | undefined;
|
|
391
|
+
} | undefined;
|
|
392
|
+
/** Keep the last answer per GET URL with its ETag and send `If-None-Match`;
|
|
393
|
+
* a 304 answers from the cache. Default: the profile's `etag`. */
|
|
394
|
+
readonly etagCache?: boolean | undefined;
|
|
395
|
+
/** `traceparent` for every request — a caller's own trace, continued. */
|
|
396
|
+
readonly traceparent?: (() => string | undefined) | undefined;
|
|
397
|
+
/** Called once per tag the first time a response carries `Sunset` or
|
|
398
|
+
* `Deprecation`. Default: one `console.warn` line. */
|
|
399
|
+
readonly onSunset?: ((info: SunsetInfo) => void) | undefined;
|
|
400
|
+
readonly clock?: (() => number) | undefined;
|
|
401
|
+
/** How to wait (the 429 retry) — `setTimeout` by default; a test hands in its own. */
|
|
402
|
+
readonly sleep?: ((ms: number) => Promise<void>) | undefined;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export declare interface RestCore {
|
|
406
|
+
readonly manifest: ClientManifest;
|
|
407
|
+
readonly call: (tag: string, input: unknown, options?: CallOptions) => Promise<CallResult>;
|
|
408
|
+
readonly baseUrl: string;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export declare type RowId = string | number;
|
|
412
|
+
|
|
413
|
+
export declare interface RowPatch {
|
|
414
|
+
readonly ops: ReadonlyArray<RowPatchOp>;
|
|
415
|
+
readonly order: ReadonlyArray<RowId>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export declare type RowPatchOp = {
|
|
419
|
+
readonly op: 'add';
|
|
420
|
+
readonly path: string;
|
|
421
|
+
readonly value: PatchRow;
|
|
422
|
+
} | {
|
|
423
|
+
readonly op: 'replace';
|
|
424
|
+
readonly path: string;
|
|
425
|
+
readonly value: PatchRow;
|
|
426
|
+
} | {
|
|
427
|
+
readonly op: 'remove';
|
|
428
|
+
readonly path: string;
|
|
429
|
+
} | {
|
|
430
|
+
readonly op: 'mergeCells';
|
|
431
|
+
readonly path: string;
|
|
432
|
+
readonly value: Readonly<Record<string, unknown>>;
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
/** The codec options of the rpc socket: the schema's own date forms, no renaming. */
|
|
436
|
+
export declare const rpcCodec: (models: Readonly<Record<string, WireType>>) => WireCodecOptions;
|
|
437
|
+
|
|
438
|
+
/** `teams.getById` → `{ namespace: 'teams', method: 'getById' }`; a tag
|
|
439
|
+
* without a dot lives at the root. The tag prefix is the namespace, like the
|
|
440
|
+
* OpenAPI tag group. */
|
|
441
|
+
export declare const splitTag: (tag: string) => {
|
|
442
|
+
readonly namespace: string | undefined;
|
|
443
|
+
readonly method: string;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
export declare interface SunsetInfo {
|
|
447
|
+
readonly tag: string;
|
|
448
|
+
readonly sunset?: string | undefined;
|
|
449
|
+
readonly deprecated?: string | undefined;
|
|
450
|
+
readonly path: string;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export declare type TokenSource = string | (() => string | undefined | Promise<string | undefined>);
|
|
454
|
+
|
|
455
|
+
/** `createdAt` → `created_at` — the server's own rule. */
|
|
456
|
+
export declare const toSnakeCase: (key: string) => string;
|
|
457
|
+
|
|
458
|
+
/** The request never got an answer: DNS, TCP, TLS, an abort, a body that was
|
|
459
|
+
* not JSON. */
|
|
460
|
+
export declare class TransportError extends ApiClientError {
|
|
461
|
+
readonly _tag: "TransportError";
|
|
462
|
+
readonly tag: string;
|
|
463
|
+
readonly reason: 'network' | 'aborted' | 'decode' | 'encode';
|
|
464
|
+
constructor(fields: {
|
|
465
|
+
readonly tag: string;
|
|
466
|
+
readonly reason: TransportError['reason'];
|
|
467
|
+
readonly message: string;
|
|
468
|
+
readonly cause?: unknown;
|
|
469
|
+
readonly requestId?: string | undefined;
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** A UUID v7: time-ordered, so an idempotency key sorts by when it was minted. */
|
|
474
|
+
export declare const uuidV7: (now?: number) => string;
|
|
475
|
+
|
|
476
|
+
/** What the client needs of a WebSocket — the browser's, Node ≥ 22's global, `ws`. */
|
|
477
|
+
export declare interface WebSocketLike {
|
|
478
|
+
send(data: string): void;
|
|
479
|
+
close(code?: number, reason?: string): void;
|
|
480
|
+
onopen: ((ev: unknown) => void) | null;
|
|
481
|
+
onmessage: ((ev: {
|
|
482
|
+
readonly data: unknown;
|
|
483
|
+
}) => void) | null;
|
|
484
|
+
onclose: ((ev: unknown) => void) | null;
|
|
485
|
+
onerror: ((ev: unknown) => void) | null;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export declare interface WireBindings {
|
|
489
|
+
readonly models: Readonly<Record<string, WireType>>;
|
|
490
|
+
readonly procedures: Readonly<Record<string, WireProcedure>>;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export declare interface WireCodecOptions {
|
|
494
|
+
/** The REST profile's date form — or `'rpc'`: the form the app's own
|
|
495
|
+
* schema uses on the socket, per field (`WireType.date.rpc`). */
|
|
496
|
+
readonly dates: ClientProfile['dates'] | 'rpc';
|
|
497
|
+
readonly naming: ClientProfile['naming'];
|
|
498
|
+
readonly models: Readonly<Record<string, WireType>>;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export declare interface WireField {
|
|
502
|
+
/** The field's name as the schema declares it (camelCase). */
|
|
503
|
+
readonly name: string;
|
|
504
|
+
readonly type: WireType;
|
|
505
|
+
readonly optional: boolean;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
export declare interface WireProcedure {
|
|
509
|
+
readonly input?: WireType | undefined;
|
|
510
|
+
readonly output?: WireType | undefined;
|
|
511
|
+
/** The typed errors the procedure declares, by tag — each an object type
|
|
512
|
+
* of the error's fields (without `_tag`). */
|
|
513
|
+
readonly errors?: Readonly<Record<string, WireType>> | undefined;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export declare type WireType = {
|
|
517
|
+
readonly kind: 'string';
|
|
518
|
+
} | {
|
|
519
|
+
readonly kind: 'number';
|
|
520
|
+
} | {
|
|
521
|
+
readonly kind: 'integer';
|
|
522
|
+
} | {
|
|
523
|
+
readonly kind: 'boolean';
|
|
524
|
+
} | {
|
|
525
|
+
readonly kind: 'undefined';
|
|
526
|
+
} | {
|
|
527
|
+
readonly kind: 'unknown';
|
|
528
|
+
} | {
|
|
529
|
+
readonly kind: 'never';
|
|
530
|
+
} | {
|
|
531
|
+
readonly kind: 'literal';
|
|
532
|
+
readonly value: string | number | boolean | null;
|
|
533
|
+
}
|
|
534
|
+
/** A `Date` in the caller's hands. `rpc` is how the app's own schema puts it
|
|
535
|
+
* on the rpc wire (`DateFromNumber` → number, `DateFromString` → string);
|
|
536
|
+
* the REST profile's `dates` decides the REST form. */
|
|
537
|
+
| {
|
|
538
|
+
readonly kind: 'date';
|
|
539
|
+
readonly rpc: 'number' | 'string';
|
|
540
|
+
} | {
|
|
541
|
+
readonly kind: 'array';
|
|
542
|
+
readonly element: WireType;
|
|
543
|
+
} | {
|
|
544
|
+
readonly kind: 'tuple';
|
|
545
|
+
readonly elements: ReadonlyArray<WireType>;
|
|
546
|
+
readonly rest?: WireType | undefined;
|
|
547
|
+
} | {
|
|
548
|
+
readonly kind: 'record';
|
|
549
|
+
readonly value: WireType;
|
|
550
|
+
} | {
|
|
551
|
+
readonly kind: 'object';
|
|
552
|
+
readonly fields: ReadonlyArray<WireField>;
|
|
553
|
+
} | {
|
|
554
|
+
readonly kind: 'union';
|
|
555
|
+
readonly members: ReadonlyArray<WireType>;
|
|
556
|
+
}
|
|
557
|
+
/** A named model in `WireBindings.models` — every object the generator
|
|
558
|
+
* named, and the knot of a recursive schema. */
|
|
559
|
+
| {
|
|
560
|
+
readonly kind: 'ref';
|
|
561
|
+
readonly name: string;
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
export declare const wsUrlFromBase: (baseUrl: string) => string;
|
|
565
|
+
|
|
566
|
+
export { }
|