@reverbia/sdk 1.0.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/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/cjs/client/client/client.gen.d.ts +2 -0
- package/dist/cjs/client/client/client.gen.js +203 -0
- package/dist/cjs/client/client/index.d.ts +8 -0
- package/dist/cjs/client/client/index.js +16 -0
- package/dist/cjs/client/client/types.gen.d.ts +99 -0
- package/dist/cjs/client/client/types.gen.js +3 -0
- package/dist/cjs/client/client/utils.gen.d.ts +40 -0
- package/dist/cjs/client/client/utils.gen.js +314 -0
- package/dist/cjs/client/client.gen.d.ts +12 -0
- package/dist/cjs/client/client.gen.js +6 -0
- package/dist/cjs/client/core/auth.gen.d.ts +18 -0
- package/dist/cjs/client/core/auth.gen.js +18 -0
- package/dist/cjs/client/core/bodySerializer.gen.d.ts +25 -0
- package/dist/cjs/client/core/bodySerializer.gen.js +60 -0
- package/dist/cjs/client/core/params.gen.d.ts +43 -0
- package/dist/cjs/client/core/params.gen.js +104 -0
- package/dist/cjs/client/core/pathSerializer.gen.d.ts +33 -0
- package/dist/cjs/client/core/pathSerializer.gen.js +123 -0
- package/dist/cjs/client/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/cjs/client/core/queryKeySerializer.gen.js +105 -0
- package/dist/cjs/client/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/cjs/client/core/serverSentEvents.gen.js +139 -0
- package/dist/cjs/client/core/types.gen.d.ts +78 -0
- package/dist/cjs/client/core/types.gen.js +3 -0
- package/dist/cjs/client/core/utils.gen.d.ts +19 -0
- package/dist/cjs/client/core/utils.gen.js +93 -0
- package/dist/cjs/client/index.d.ts +2 -0
- package/dist/cjs/client/index.js +18 -0
- package/dist/cjs/client/sdk.gen.d.ts +27 -0
- package/dist/cjs/client/sdk.gen.js +33 -0
- package/dist/cjs/client/types.gen.d.ts +120 -0
- package/dist/cjs/client/types.gen.js +3 -0
- package/dist/esm/client/client/client.gen.d.ts +2 -0
- package/dist/esm/client/client/client.gen.js +199 -0
- package/dist/esm/client/client/index.d.ts +8 -0
- package/dist/esm/client/client/index.js +6 -0
- package/dist/esm/client/client/types.gen.d.ts +99 -0
- package/dist/esm/client/client/types.gen.js +2 -0
- package/dist/esm/client/client/utils.gen.d.ts +40 -0
- package/dist/esm/client/client/utils.gen.js +302 -0
- package/dist/esm/client/client.gen.d.ts +12 -0
- package/dist/esm/client/client.gen.js +3 -0
- package/dist/esm/client/core/auth.gen.d.ts +18 -0
- package/dist/esm/client/core/auth.gen.js +14 -0
- package/dist/esm/client/core/bodySerializer.gen.d.ts +25 -0
- package/dist/esm/client/core/bodySerializer.gen.js +57 -0
- package/dist/esm/client/core/params.gen.d.ts +43 -0
- package/dist/esm/client/core/params.gen.js +100 -0
- package/dist/esm/client/core/pathSerializer.gen.d.ts +33 -0
- package/dist/esm/client/core/pathSerializer.gen.js +114 -0
- package/dist/esm/client/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/esm/client/core/queryKeySerializer.gen.js +99 -0
- package/dist/esm/client/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/esm/client/core/serverSentEvents.gen.js +135 -0
- package/dist/esm/client/core/types.gen.d.ts +78 -0
- package/dist/esm/client/core/types.gen.js +2 -0
- package/dist/esm/client/core/utils.gen.d.ts +19 -0
- package/dist/esm/client/core/utils.gen.js +87 -0
- package/dist/esm/client/index.d.ts +2 -0
- package/dist/esm/client/index.js +2 -0
- package/dist/esm/client/sdk.gen.d.ts +27 -0
- package/dist/esm/client/sdk.gen.js +28 -0
- package/dist/esm/client/types.gen.d.ts +120 -0
- package/dist/esm/client/types.gen.js +2 -0
- package/dist/types/client/client/client.gen.d.ts +2 -0
- package/dist/types/client/client/index.d.ts +8 -0
- package/dist/types/client/client/types.gen.d.ts +99 -0
- package/dist/types/client/client/utils.gen.d.ts +40 -0
- package/dist/types/client/client.gen.d.ts +12 -0
- package/dist/types/client/core/auth.gen.d.ts +18 -0
- package/dist/types/client/core/bodySerializer.gen.d.ts +25 -0
- package/dist/types/client/core/params.gen.d.ts +43 -0
- package/dist/types/client/core/pathSerializer.gen.d.ts +33 -0
- package/dist/types/client/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/types/client/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/types/client/core/types.gen.d.ts +78 -0
- package/dist/types/client/core/utils.gen.d.ts +19 -0
- package/dist/types/client/index.d.ts +2 -0
- package/dist/types/client/sdk.gen.d.ts +27 -0
- package/dist/types/client/types.gen.d.ts +120 -0
- package/package.json +48 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Client, Options as Options2, TDataShape } from './client';
|
|
2
|
+
import type { GetHealthData, GetHealthErrors, GetHealthResponses, PostApiV1ChatCompletionsData, PostApiV1ChatCompletionsErrors, PostApiV1ChatCompletionsResponses } from './types.gen';
|
|
3
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options2<TData, ThrowOnError> & {
|
|
4
|
+
/**
|
|
5
|
+
* You can provide a client instance returned by `createClient()` instead of
|
|
6
|
+
* individual options. This might be also useful if you want to implement a
|
|
7
|
+
* custom client.
|
|
8
|
+
*/
|
|
9
|
+
client?: Client;
|
|
10
|
+
/**
|
|
11
|
+
* You can pass arbitrary values through the `meta` object. This can be
|
|
12
|
+
* used to access values that aren't defined as part of the SDK function.
|
|
13
|
+
*/
|
|
14
|
+
meta?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Create chat completion
|
|
18
|
+
*
|
|
19
|
+
* Generates a chat completion using the configured gateway.
|
|
20
|
+
*/
|
|
21
|
+
export declare const postApiV1ChatCompletions: <ThrowOnError extends boolean = false>(options: Options<PostApiV1ChatCompletionsData, ThrowOnError>) => import("./client").RequestResult<PostApiV1ChatCompletionsResponses, PostApiV1ChatCompletionsErrors, ThrowOnError>;
|
|
22
|
+
/**
|
|
23
|
+
* Health check
|
|
24
|
+
*
|
|
25
|
+
* Returns the current health status of the service.
|
|
26
|
+
*/
|
|
27
|
+
export declare const getHealth: <ThrowOnError extends boolean = false>(options?: Options<GetHealthData, ThrowOnError>) => import("./client").RequestResult<GetHealthResponses, GetHealthErrors, ThrowOnError>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getHealth = exports.postApiV1ChatCompletions = void 0;
|
|
5
|
+
const client_gen_1 = require("./client.gen");
|
|
6
|
+
/**
|
|
7
|
+
* Create chat completion
|
|
8
|
+
*
|
|
9
|
+
* Generates a chat completion using the configured gateway.
|
|
10
|
+
*/
|
|
11
|
+
const postApiV1ChatCompletions = (options) => {
|
|
12
|
+
return (options.client ?? client_gen_1.client).post({
|
|
13
|
+
url: '/api/v1/chat/completions',
|
|
14
|
+
...options,
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
...options.headers
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.postApiV1ChatCompletions = postApiV1ChatCompletions;
|
|
22
|
+
/**
|
|
23
|
+
* Health check
|
|
24
|
+
*
|
|
25
|
+
* Returns the current health status of the service.
|
|
26
|
+
*/
|
|
27
|
+
const getHealth = (options) => {
|
|
28
|
+
return (options?.client ?? client_gen_1.client).get({
|
|
29
|
+
url: '/health',
|
|
30
|
+
...options
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.getHealth = getHealth;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export type ClientOptions = {
|
|
2
|
+
baseUrl: `${string}://${string}` | (string & {});
|
|
3
|
+
};
|
|
4
|
+
export type HandlersHealthResponse = {
|
|
5
|
+
/**
|
|
6
|
+
* Status indicates the service health status
|
|
7
|
+
*/
|
|
8
|
+
status?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Timestamp is the Unix timestamp of the response
|
|
11
|
+
*/
|
|
12
|
+
timestamp?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Version is the current API version
|
|
15
|
+
*/
|
|
16
|
+
version?: string;
|
|
17
|
+
};
|
|
18
|
+
export type LlmapiChatCompletionRequest = {
|
|
19
|
+
/**
|
|
20
|
+
* Messages is the conversation history
|
|
21
|
+
*/
|
|
22
|
+
messages?: Array<LlmapiMessage>;
|
|
23
|
+
/**
|
|
24
|
+
* Model is the model identifier
|
|
25
|
+
*/
|
|
26
|
+
model?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Stream indicates if response should be streamed
|
|
29
|
+
*/
|
|
30
|
+
stream?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type LlmapiChatCompletionResponse = {
|
|
33
|
+
/**
|
|
34
|
+
* Choices contains the completion choices
|
|
35
|
+
*/
|
|
36
|
+
choices?: Array<LlmapiChoice>;
|
|
37
|
+
/**
|
|
38
|
+
* ID is the completion ID
|
|
39
|
+
*/
|
|
40
|
+
id?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Model is the model used
|
|
43
|
+
*/
|
|
44
|
+
model?: string;
|
|
45
|
+
};
|
|
46
|
+
export type LlmapiChoice = {
|
|
47
|
+
/**
|
|
48
|
+
* FinishReason indicates why the completion stopped
|
|
49
|
+
*/
|
|
50
|
+
finish_reason?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Index is the choice index
|
|
53
|
+
*/
|
|
54
|
+
index?: number;
|
|
55
|
+
message?: LlmapiMessage;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Message is the generated message
|
|
59
|
+
*/
|
|
60
|
+
export type LlmapiMessage = {
|
|
61
|
+
/**
|
|
62
|
+
* Content is the message content
|
|
63
|
+
*/
|
|
64
|
+
content?: string;
|
|
65
|
+
role?: LlmapiRole;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Role is the message role (system, user, assistant)
|
|
69
|
+
*/
|
|
70
|
+
export type LlmapiRole = string;
|
|
71
|
+
export type ResponseErrorResponse = {
|
|
72
|
+
error?: string;
|
|
73
|
+
};
|
|
74
|
+
export type PostApiV1ChatCompletionsData = {
|
|
75
|
+
/**
|
|
76
|
+
* Chat completion request
|
|
77
|
+
*/
|
|
78
|
+
body: LlmapiChatCompletionRequest;
|
|
79
|
+
path?: never;
|
|
80
|
+
query?: never;
|
|
81
|
+
url: '/api/v1/chat/completions';
|
|
82
|
+
};
|
|
83
|
+
export type PostApiV1ChatCompletionsErrors = {
|
|
84
|
+
/**
|
|
85
|
+
* Bad Request
|
|
86
|
+
*/
|
|
87
|
+
400: ResponseErrorResponse;
|
|
88
|
+
/**
|
|
89
|
+
* Internal Server Error
|
|
90
|
+
*/
|
|
91
|
+
500: ResponseErrorResponse;
|
|
92
|
+
};
|
|
93
|
+
export type PostApiV1ChatCompletionsError = PostApiV1ChatCompletionsErrors[keyof PostApiV1ChatCompletionsErrors];
|
|
94
|
+
export type PostApiV1ChatCompletionsResponses = {
|
|
95
|
+
/**
|
|
96
|
+
* OK
|
|
97
|
+
*/
|
|
98
|
+
200: LlmapiChatCompletionResponse;
|
|
99
|
+
};
|
|
100
|
+
export type PostApiV1ChatCompletionsResponse = PostApiV1ChatCompletionsResponses[keyof PostApiV1ChatCompletionsResponses];
|
|
101
|
+
export type GetHealthData = {
|
|
102
|
+
body?: never;
|
|
103
|
+
path?: never;
|
|
104
|
+
query?: never;
|
|
105
|
+
url: '/health';
|
|
106
|
+
};
|
|
107
|
+
export type GetHealthErrors = {
|
|
108
|
+
/**
|
|
109
|
+
* Internal Server Error
|
|
110
|
+
*/
|
|
111
|
+
500: ResponseErrorResponse;
|
|
112
|
+
};
|
|
113
|
+
export type GetHealthError = GetHealthErrors[keyof GetHealthErrors];
|
|
114
|
+
export type GetHealthResponses = {
|
|
115
|
+
/**
|
|
116
|
+
* OK
|
|
117
|
+
*/
|
|
118
|
+
200: HandlersHealthResponse;
|
|
119
|
+
};
|
|
120
|
+
export type GetHealthResponse = GetHealthResponses[keyof GetHealthResponses];
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { createSseClient } from '../core/serverSentEvents.gen';
|
|
3
|
+
import { getValidRequestBody } from '../core/utils.gen';
|
|
4
|
+
import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from './utils.gen';
|
|
5
|
+
export const createClient = (config = {}) => {
|
|
6
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
7
|
+
const getConfig = () => ({ ..._config });
|
|
8
|
+
const setConfig = (config) => {
|
|
9
|
+
_config = mergeConfigs(_config, config);
|
|
10
|
+
return getConfig();
|
|
11
|
+
};
|
|
12
|
+
const interceptors = createInterceptors();
|
|
13
|
+
const beforeRequest = async (options) => {
|
|
14
|
+
const opts = {
|
|
15
|
+
..._config,
|
|
16
|
+
...options,
|
|
17
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
18
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
19
|
+
serializedBody: undefined,
|
|
20
|
+
};
|
|
21
|
+
if (opts.security) {
|
|
22
|
+
await setAuthParams({
|
|
23
|
+
...opts,
|
|
24
|
+
security: opts.security,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (opts.requestValidator) {
|
|
28
|
+
await opts.requestValidator(opts);
|
|
29
|
+
}
|
|
30
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
31
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
32
|
+
}
|
|
33
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
34
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
35
|
+
opts.headers.delete('Content-Type');
|
|
36
|
+
}
|
|
37
|
+
const url = buildUrl(opts);
|
|
38
|
+
return { opts, url };
|
|
39
|
+
};
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
const request = async (options) => {
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
const { opts, url } = await beforeRequest(options);
|
|
44
|
+
for (const fn of interceptors.request.fns) {
|
|
45
|
+
if (fn) {
|
|
46
|
+
await fn(opts);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
50
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
51
|
+
const _fetch = opts.fetch;
|
|
52
|
+
const requestInit = {
|
|
53
|
+
...opts,
|
|
54
|
+
body: getValidRequestBody(opts),
|
|
55
|
+
};
|
|
56
|
+
let response = await _fetch(url, requestInit);
|
|
57
|
+
for (const fn of interceptors.response.fns) {
|
|
58
|
+
if (fn) {
|
|
59
|
+
response = await fn(response, opts);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const result = {
|
|
63
|
+
response,
|
|
64
|
+
};
|
|
65
|
+
if (response.ok) {
|
|
66
|
+
const parseAs = (opts.parseAs === 'auto'
|
|
67
|
+
? getParseAs(response.headers.get('Content-Type'))
|
|
68
|
+
: opts.parseAs) ?? 'json';
|
|
69
|
+
if (response.status === 204 ||
|
|
70
|
+
response.headers.get('Content-Length') === '0') {
|
|
71
|
+
let emptyData;
|
|
72
|
+
switch (parseAs) {
|
|
73
|
+
case 'arrayBuffer':
|
|
74
|
+
case 'blob':
|
|
75
|
+
case 'text':
|
|
76
|
+
emptyData = await response[parseAs]();
|
|
77
|
+
break;
|
|
78
|
+
case 'formData':
|
|
79
|
+
emptyData = new FormData();
|
|
80
|
+
break;
|
|
81
|
+
case 'stream':
|
|
82
|
+
emptyData = response.body;
|
|
83
|
+
break;
|
|
84
|
+
case 'json':
|
|
85
|
+
default:
|
|
86
|
+
emptyData = {};
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
data: emptyData,
|
|
91
|
+
...result,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
let data;
|
|
95
|
+
switch (parseAs) {
|
|
96
|
+
case 'arrayBuffer':
|
|
97
|
+
case 'blob':
|
|
98
|
+
case 'formData':
|
|
99
|
+
case 'json':
|
|
100
|
+
case 'text':
|
|
101
|
+
data = await response[parseAs]();
|
|
102
|
+
break;
|
|
103
|
+
case 'stream':
|
|
104
|
+
return {
|
|
105
|
+
data: response.body,
|
|
106
|
+
...result,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (parseAs === 'json') {
|
|
110
|
+
if (opts.responseValidator) {
|
|
111
|
+
await opts.responseValidator(data);
|
|
112
|
+
}
|
|
113
|
+
if (opts.responseTransformer) {
|
|
114
|
+
data = await opts.responseTransformer(data);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
data,
|
|
119
|
+
...result,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const textError = await response.text();
|
|
123
|
+
let jsonError;
|
|
124
|
+
try {
|
|
125
|
+
jsonError = JSON.parse(textError);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// noop
|
|
129
|
+
}
|
|
130
|
+
const error = jsonError ?? textError;
|
|
131
|
+
let finalError = error;
|
|
132
|
+
for (const fn of interceptors.error.fns) {
|
|
133
|
+
if (fn) {
|
|
134
|
+
finalError = (await fn(error, response, opts));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
finalError = finalError || {};
|
|
138
|
+
if (opts.throwOnError) {
|
|
139
|
+
throw finalError;
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
error: finalError,
|
|
143
|
+
...result,
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
147
|
+
const makeSseFn = (method) => async (options) => {
|
|
148
|
+
const { opts, url } = await beforeRequest(options);
|
|
149
|
+
return createSseClient({
|
|
150
|
+
...opts,
|
|
151
|
+
body: opts.body,
|
|
152
|
+
headers: opts.headers,
|
|
153
|
+
method,
|
|
154
|
+
onRequest: async (url, init) => {
|
|
155
|
+
let request = new Request(url, init);
|
|
156
|
+
const requestInit = {
|
|
157
|
+
...init,
|
|
158
|
+
method: init.method,
|
|
159
|
+
url,
|
|
160
|
+
};
|
|
161
|
+
for (const fn of interceptors.request.fns) {
|
|
162
|
+
if (fn) {
|
|
163
|
+
await fn(requestInit);
|
|
164
|
+
request = new Request(requestInit.url, requestInit);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return request;
|
|
168
|
+
},
|
|
169
|
+
url,
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
buildUrl,
|
|
174
|
+
connect: makeMethodFn('CONNECT'),
|
|
175
|
+
delete: makeMethodFn('DELETE'),
|
|
176
|
+
get: makeMethodFn('GET'),
|
|
177
|
+
getConfig,
|
|
178
|
+
head: makeMethodFn('HEAD'),
|
|
179
|
+
interceptors,
|
|
180
|
+
options: makeMethodFn('OPTIONS'),
|
|
181
|
+
patch: makeMethodFn('PATCH'),
|
|
182
|
+
post: makeMethodFn('POST'),
|
|
183
|
+
put: makeMethodFn('PUT'),
|
|
184
|
+
request,
|
|
185
|
+
setConfig,
|
|
186
|
+
sse: {
|
|
187
|
+
connect: makeSseFn('CONNECT'),
|
|
188
|
+
delete: makeSseFn('DELETE'),
|
|
189
|
+
get: makeSseFn('GET'),
|
|
190
|
+
head: makeSseFn('HEAD'),
|
|
191
|
+
options: makeSseFn('OPTIONS'),
|
|
192
|
+
patch: makeSseFn('PATCH'),
|
|
193
|
+
post: makeSseFn('POST'),
|
|
194
|
+
put: makeSseFn('PUT'),
|
|
195
|
+
trace: makeSseFn('TRACE'),
|
|
196
|
+
},
|
|
197
|
+
trace: makeMethodFn('TRACE'),
|
|
198
|
+
};
|
|
199
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { Auth } from '../core/auth.gen';
|
|
2
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
3
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
4
|
+
export { buildClientParams } from '../core/params.gen';
|
|
5
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
6
|
+
export { createClient } from './client.gen';
|
|
7
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, TDataShape, } from './types.gen';
|
|
8
|
+
export { createConfig } from './utils.gen';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen';
|
|
3
|
+
export { buildClientParams } from '../core/params.gen';
|
|
4
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
5
|
+
export { createClient } from './client.gen';
|
|
6
|
+
export { createConfig } from './utils.gen';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Auth } from '../core/auth.gen';
|
|
2
|
+
import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen';
|
|
3
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
|
|
4
|
+
import type { Middleware } from './utils.gen';
|
|
5
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Base URL for all requests made by this client.
|
|
8
|
+
*/
|
|
9
|
+
baseUrl?: T['baseUrl'];
|
|
10
|
+
/**
|
|
11
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
12
|
+
* fetch instance.
|
|
13
|
+
*
|
|
14
|
+
* @default globalThis.fetch
|
|
15
|
+
*/
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
/**
|
|
18
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
19
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
20
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
21
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
22
|
+
*
|
|
23
|
+
* @default 'auto'
|
|
24
|
+
*/
|
|
25
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
26
|
+
/**
|
|
27
|
+
* Throw an error instead of returning it in the response?
|
|
28
|
+
*
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
throwOnError?: T['throwOnError'];
|
|
32
|
+
}
|
|
33
|
+
export interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
34
|
+
throwOnError: ThrowOnError;
|
|
35
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
36
|
+
/**
|
|
37
|
+
* Any body that you want to add to your request.
|
|
38
|
+
*
|
|
39
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
40
|
+
*/
|
|
41
|
+
body?: unknown;
|
|
42
|
+
path?: Record<string, unknown>;
|
|
43
|
+
query?: Record<string, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Security mechanism(s) to use for the request.
|
|
46
|
+
*/
|
|
47
|
+
security?: ReadonlyArray<Auth>;
|
|
48
|
+
url: Url;
|
|
49
|
+
}
|
|
50
|
+
export interface ResolvedRequestOptions<ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, ThrowOnError, Url> {
|
|
51
|
+
serializedBody?: string;
|
|
52
|
+
}
|
|
53
|
+
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<{
|
|
54
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
55
|
+
response: Response;
|
|
56
|
+
}> : Promise<({
|
|
57
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
58
|
+
error: undefined;
|
|
59
|
+
} | {
|
|
60
|
+
data: undefined;
|
|
61
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
62
|
+
}) & {
|
|
63
|
+
response: Response;
|
|
64
|
+
}>;
|
|
65
|
+
export interface ClientOptions {
|
|
66
|
+
baseUrl?: string;
|
|
67
|
+
throwOnError?: boolean;
|
|
68
|
+
}
|
|
69
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
|
|
70
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
71
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
|
|
72
|
+
type BuildUrlFn = <TData extends {
|
|
73
|
+
body?: unknown;
|
|
74
|
+
path?: Record<string, unknown>;
|
|
75
|
+
query?: Record<string, unknown>;
|
|
76
|
+
url: string;
|
|
77
|
+
}>(options: TData & Options<TData>) => string;
|
|
78
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
79
|
+
interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The `createClientConfig()` function will be called on client initialization
|
|
83
|
+
* and the returned object will become the client's initial configuration.
|
|
84
|
+
*
|
|
85
|
+
* You may want to initialize your client this way instead of calling
|
|
86
|
+
* `setConfig()`. This is useful for example if you're using Next.js
|
|
87
|
+
* to ensure your client always has the correct values.
|
|
88
|
+
*/
|
|
89
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
90
|
+
export interface TDataShape {
|
|
91
|
+
body?: unknown;
|
|
92
|
+
headers?: unknown;
|
|
93
|
+
path?: unknown;
|
|
94
|
+
query?: unknown;
|
|
95
|
+
url: string;
|
|
96
|
+
}
|
|
97
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
98
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = OmitKeys<RequestOptions<TResponse, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { QuerySerializer, QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
2
|
+
import type { Client, ClientOptions, Config, RequestOptions } from './types.gen';
|
|
3
|
+
export declare const createQuerySerializer: <T = unknown>({ parameters, ...args }?: QuerySerializerOptions) => (queryParams: T) => string;
|
|
4
|
+
/**
|
|
5
|
+
* Infers parseAs value from provided Content-Type header.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto">;
|
|
8
|
+
export declare const setAuthParams: ({ security, ...options }: Pick<Required<RequestOptions>, "security"> & Pick<RequestOptions, "auth" | "query"> & {
|
|
9
|
+
headers: Headers;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
export declare const buildUrl: Client['buildUrl'];
|
|
12
|
+
export declare const getUrl: ({ baseUrl, path, query, querySerializer, url: _url, }: {
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
path?: Record<string, unknown>;
|
|
15
|
+
query?: Record<string, unknown>;
|
|
16
|
+
querySerializer: QuerySerializer;
|
|
17
|
+
url: string;
|
|
18
|
+
}) => string;
|
|
19
|
+
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
20
|
+
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
21
|
+
type ErrInterceptor<Err, Res, Options> = (error: Err, response: Res, options: Options) => Err | Promise<Err>;
|
|
22
|
+
type ReqInterceptor<Options> = (options: Options) => void | Promise<void>;
|
|
23
|
+
type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>;
|
|
24
|
+
declare class Interceptors<Interceptor> {
|
|
25
|
+
fns: Array<Interceptor | null>;
|
|
26
|
+
clear(): void;
|
|
27
|
+
eject(id: number | Interceptor): void;
|
|
28
|
+
exists(id: number | Interceptor): boolean;
|
|
29
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
30
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
31
|
+
use(fn: Interceptor): number;
|
|
32
|
+
}
|
|
33
|
+
export interface Middleware<Res, Err, Options> {
|
|
34
|
+
error: Interceptors<ErrInterceptor<Err, Res, Options>>;
|
|
35
|
+
request: Interceptors<ReqInterceptor<Options>>;
|
|
36
|
+
response: Interceptors<ResInterceptor<Res, Options>>;
|
|
37
|
+
}
|
|
38
|
+
export declare const createInterceptors: <Res, Err, Options>() => Middleware<Res, Err, Options>;
|
|
39
|
+
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
40
|
+
export {};
|