@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,114 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export const separatorArrayExplode = (style) => {
|
|
3
|
+
switch (style) {
|
|
4
|
+
case 'label':
|
|
5
|
+
return '.';
|
|
6
|
+
case 'matrix':
|
|
7
|
+
return ';';
|
|
8
|
+
case 'simple':
|
|
9
|
+
return ',';
|
|
10
|
+
default:
|
|
11
|
+
return '&';
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const separatorArrayNoExplode = (style) => {
|
|
15
|
+
switch (style) {
|
|
16
|
+
case 'form':
|
|
17
|
+
return ',';
|
|
18
|
+
case 'pipeDelimited':
|
|
19
|
+
return '|';
|
|
20
|
+
case 'spaceDelimited':
|
|
21
|
+
return '%20';
|
|
22
|
+
default:
|
|
23
|
+
return ',';
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const separatorObjectExplode = (style) => {
|
|
27
|
+
switch (style) {
|
|
28
|
+
case 'label':
|
|
29
|
+
return '.';
|
|
30
|
+
case 'matrix':
|
|
31
|
+
return ';';
|
|
32
|
+
case 'simple':
|
|
33
|
+
return ',';
|
|
34
|
+
default:
|
|
35
|
+
return '&';
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const serializeArrayParam = ({ allowReserved, explode, name, style, value, }) => {
|
|
39
|
+
if (!explode) {
|
|
40
|
+
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
41
|
+
switch (style) {
|
|
42
|
+
case 'label':
|
|
43
|
+
return `.${joinedValues}`;
|
|
44
|
+
case 'matrix':
|
|
45
|
+
return `;${name}=${joinedValues}`;
|
|
46
|
+
case 'simple':
|
|
47
|
+
return joinedValues;
|
|
48
|
+
default:
|
|
49
|
+
return `${name}=${joinedValues}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const separator = separatorArrayExplode(style);
|
|
53
|
+
const joinedValues = value
|
|
54
|
+
.map((v) => {
|
|
55
|
+
if (style === 'label' || style === 'simple') {
|
|
56
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
57
|
+
}
|
|
58
|
+
return serializePrimitiveParam({
|
|
59
|
+
allowReserved,
|
|
60
|
+
name,
|
|
61
|
+
value: v,
|
|
62
|
+
});
|
|
63
|
+
})
|
|
64
|
+
.join(separator);
|
|
65
|
+
return style === 'label' || style === 'matrix'
|
|
66
|
+
? separator + joinedValues
|
|
67
|
+
: joinedValues;
|
|
68
|
+
};
|
|
69
|
+
export const serializePrimitiveParam = ({ allowReserved, name, value, }) => {
|
|
70
|
+
if (value === undefined || value === null) {
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === 'object') {
|
|
74
|
+
throw new Error('Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.');
|
|
75
|
+
}
|
|
76
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
77
|
+
};
|
|
78
|
+
export const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly, }) => {
|
|
79
|
+
if (value instanceof Date) {
|
|
80
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
81
|
+
}
|
|
82
|
+
if (style !== 'deepObject' && !explode) {
|
|
83
|
+
let values = [];
|
|
84
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
85
|
+
values = [
|
|
86
|
+
...values,
|
|
87
|
+
key,
|
|
88
|
+
allowReserved ? v : encodeURIComponent(v),
|
|
89
|
+
];
|
|
90
|
+
});
|
|
91
|
+
const joinedValues = values.join(',');
|
|
92
|
+
switch (style) {
|
|
93
|
+
case 'form':
|
|
94
|
+
return `${name}=${joinedValues}`;
|
|
95
|
+
case 'label':
|
|
96
|
+
return `.${joinedValues}`;
|
|
97
|
+
case 'matrix':
|
|
98
|
+
return `;${name}=${joinedValues}`;
|
|
99
|
+
default:
|
|
100
|
+
return joinedValues;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const separator = separatorObjectExplode(style);
|
|
104
|
+
const joinedValues = Object.entries(value)
|
|
105
|
+
.map(([key, v]) => serializePrimitiveParam({
|
|
106
|
+
allowReserved,
|
|
107
|
+
name: style === 'deepObject' ? `${name}[${key}]` : key,
|
|
108
|
+
value: v,
|
|
109
|
+
}))
|
|
110
|
+
.join(separator);
|
|
111
|
+
return style === 'label' || style === 'matrix'
|
|
112
|
+
? separator + joinedValues
|
|
113
|
+
: joinedValues;
|
|
114
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-friendly union that mirrors what Pinia Colada can hash.
|
|
3
|
+
*/
|
|
4
|
+
export type JsonValue = null | string | number | boolean | JsonValue[] | {
|
|
5
|
+
[key: string]: JsonValue;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
|
|
9
|
+
*/
|
|
10
|
+
export declare const queryKeyJsonReplacer: (_key: string, value: unknown) => {} | null | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Safely stringifies a value and parses it back into a JsonValue.
|
|
13
|
+
*/
|
|
14
|
+
export declare const stringifyToJsonValue: (input: unknown) => JsonValue | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Normalizes any accepted value into a JSON-friendly shape for query keys.
|
|
17
|
+
*/
|
|
18
|
+
export declare const serializeQueryKeyValue: (value: unknown) => JsonValue | undefined;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
/**
|
|
3
|
+
* Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
|
|
4
|
+
*/
|
|
5
|
+
export const queryKeyJsonReplacer = (_key, value) => {
|
|
6
|
+
if (value === undefined ||
|
|
7
|
+
typeof value === 'function' ||
|
|
8
|
+
typeof value === 'symbol') {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === 'bigint') {
|
|
12
|
+
return value.toString();
|
|
13
|
+
}
|
|
14
|
+
if (value instanceof Date) {
|
|
15
|
+
return value.toISOString();
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Safely stringifies a value and parses it back into a JsonValue.
|
|
21
|
+
*/
|
|
22
|
+
export const stringifyToJsonValue = (input) => {
|
|
23
|
+
try {
|
|
24
|
+
const json = JSON.stringify(input, queryKeyJsonReplacer);
|
|
25
|
+
if (json === undefined) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return JSON.parse(json);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Detects plain objects (including objects with a null prototype).
|
|
36
|
+
*/
|
|
37
|
+
const isPlainObject = (value) => {
|
|
38
|
+
if (value === null || typeof value !== 'object') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const prototype = Object.getPrototypeOf(value);
|
|
42
|
+
return prototype === Object.prototype || prototype === null;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Turns URLSearchParams into a sorted JSON object for deterministic keys.
|
|
46
|
+
*/
|
|
47
|
+
const serializeSearchParams = (params) => {
|
|
48
|
+
const entries = Array.from(params.entries()).sort(([a], [b]) => a.localeCompare(b));
|
|
49
|
+
const result = {};
|
|
50
|
+
for (const [key, value] of entries) {
|
|
51
|
+
const existing = result[key];
|
|
52
|
+
if (existing === undefined) {
|
|
53
|
+
result[key] = value;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(existing)) {
|
|
57
|
+
existing.push(value);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
result[key] = [existing, value];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Normalizes any accepted value into a JSON-friendly shape for query keys.
|
|
67
|
+
*/
|
|
68
|
+
export const serializeQueryKeyValue = (value) => {
|
|
69
|
+
if (value === null) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
if (typeof value === 'string' ||
|
|
73
|
+
typeof value === 'number' ||
|
|
74
|
+
typeof value === 'boolean') {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
if (value === undefined ||
|
|
78
|
+
typeof value === 'function' ||
|
|
79
|
+
typeof value === 'symbol') {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
if (typeof value === 'bigint') {
|
|
83
|
+
return value.toString();
|
|
84
|
+
}
|
|
85
|
+
if (value instanceof Date) {
|
|
86
|
+
return value.toISOString();
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
return stringifyToJsonValue(value);
|
|
90
|
+
}
|
|
91
|
+
if (typeof URLSearchParams !== 'undefined' &&
|
|
92
|
+
value instanceof URLSearchParams) {
|
|
93
|
+
return serializeSearchParams(value);
|
|
94
|
+
}
|
|
95
|
+
if (isPlainObject(value)) {
|
|
96
|
+
return stringifyToJsonValue(value);
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Config } from './types.gen';
|
|
2
|
+
export type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config, 'method' | 'responseTransformer' | 'responseValidator'> & {
|
|
3
|
+
/**
|
|
4
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
5
|
+
* fetch instance.
|
|
6
|
+
*
|
|
7
|
+
* @default globalThis.fetch
|
|
8
|
+
*/
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
/**
|
|
11
|
+
* Implementing clients can call request interceptors inside this hook.
|
|
12
|
+
*/
|
|
13
|
+
onRequest?: (url: string, init: RequestInit) => Promise<Request>;
|
|
14
|
+
/**
|
|
15
|
+
* Callback invoked when a network or parsing error occurs during streaming.
|
|
16
|
+
*
|
|
17
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
18
|
+
*
|
|
19
|
+
* @param error The error that occurred.
|
|
20
|
+
*/
|
|
21
|
+
onSseError?: (error: unknown) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Callback invoked when an event is streamed from the server.
|
|
24
|
+
*
|
|
25
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
26
|
+
*
|
|
27
|
+
* @param event Event streamed from the server.
|
|
28
|
+
* @returns Nothing (void).
|
|
29
|
+
*/
|
|
30
|
+
onSseEvent?: (event: StreamEvent<TData>) => void;
|
|
31
|
+
serializedBody?: RequestInit['body'];
|
|
32
|
+
/**
|
|
33
|
+
* Default retry delay in milliseconds.
|
|
34
|
+
*
|
|
35
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
36
|
+
*
|
|
37
|
+
* @default 3000
|
|
38
|
+
*/
|
|
39
|
+
sseDefaultRetryDelay?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Maximum number of retry attempts before giving up.
|
|
42
|
+
*/
|
|
43
|
+
sseMaxRetryAttempts?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Maximum retry delay in milliseconds.
|
|
46
|
+
*
|
|
47
|
+
* Applies only when exponential backoff is used.
|
|
48
|
+
*
|
|
49
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
50
|
+
*
|
|
51
|
+
* @default 30000
|
|
52
|
+
*/
|
|
53
|
+
sseMaxRetryDelay?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Optional sleep function for retry backoff.
|
|
56
|
+
*
|
|
57
|
+
* Defaults to using `setTimeout`.
|
|
58
|
+
*/
|
|
59
|
+
sseSleepFn?: (ms: number) => Promise<void>;
|
|
60
|
+
url: string;
|
|
61
|
+
};
|
|
62
|
+
export interface StreamEvent<TData = unknown> {
|
|
63
|
+
data: TData;
|
|
64
|
+
event?: string;
|
|
65
|
+
id?: string;
|
|
66
|
+
retry?: number;
|
|
67
|
+
}
|
|
68
|
+
export type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
69
|
+
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
70
|
+
};
|
|
71
|
+
export declare const createSseClient: <TData = unknown>({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }: ServerSentEventsOptions) => ServerSentEventsResult<TData>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export const createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
|
|
3
|
+
let lastEventId;
|
|
4
|
+
const sleep = sseSleepFn ??
|
|
5
|
+
((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
6
|
+
const createStream = async function* () {
|
|
7
|
+
let retryDelay = sseDefaultRetryDelay ?? 3000;
|
|
8
|
+
let attempt = 0;
|
|
9
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
10
|
+
while (true) {
|
|
11
|
+
if (signal.aborted)
|
|
12
|
+
break;
|
|
13
|
+
attempt++;
|
|
14
|
+
const headers = options.headers instanceof Headers
|
|
15
|
+
? options.headers
|
|
16
|
+
: new Headers(options.headers);
|
|
17
|
+
if (lastEventId !== undefined) {
|
|
18
|
+
headers.set('Last-Event-ID', lastEventId);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const requestInit = {
|
|
22
|
+
redirect: 'follow',
|
|
23
|
+
...options,
|
|
24
|
+
body: options.serializedBody,
|
|
25
|
+
headers,
|
|
26
|
+
signal,
|
|
27
|
+
};
|
|
28
|
+
let request = new Request(url, requestInit);
|
|
29
|
+
if (onRequest) {
|
|
30
|
+
request = await onRequest(url, requestInit);
|
|
31
|
+
}
|
|
32
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
33
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
34
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
35
|
+
const response = await _fetch(request);
|
|
36
|
+
if (!response.ok)
|
|
37
|
+
throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
38
|
+
if (!response.body)
|
|
39
|
+
throw new Error('No body in SSE response');
|
|
40
|
+
const reader = response.body
|
|
41
|
+
.pipeThrough(new TextDecoderStream())
|
|
42
|
+
.getReader();
|
|
43
|
+
let buffer = '';
|
|
44
|
+
const abortHandler = () => {
|
|
45
|
+
try {
|
|
46
|
+
reader.cancel();
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// noop
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
signal.addEventListener('abort', abortHandler);
|
|
53
|
+
try {
|
|
54
|
+
while (true) {
|
|
55
|
+
const { done, value } = await reader.read();
|
|
56
|
+
if (done)
|
|
57
|
+
break;
|
|
58
|
+
buffer += value;
|
|
59
|
+
const chunks = buffer.split('\n\n');
|
|
60
|
+
buffer = chunks.pop() ?? '';
|
|
61
|
+
for (const chunk of chunks) {
|
|
62
|
+
const lines = chunk.split('\n');
|
|
63
|
+
const dataLines = [];
|
|
64
|
+
let eventName;
|
|
65
|
+
for (const line of lines) {
|
|
66
|
+
if (line.startsWith('data:')) {
|
|
67
|
+
dataLines.push(line.replace(/^data:\s*/, ''));
|
|
68
|
+
}
|
|
69
|
+
else if (line.startsWith('event:')) {
|
|
70
|
+
eventName = line.replace(/^event:\s*/, '');
|
|
71
|
+
}
|
|
72
|
+
else if (line.startsWith('id:')) {
|
|
73
|
+
lastEventId = line.replace(/^id:\s*/, '');
|
|
74
|
+
}
|
|
75
|
+
else if (line.startsWith('retry:')) {
|
|
76
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10);
|
|
77
|
+
if (!Number.isNaN(parsed)) {
|
|
78
|
+
retryDelay = parsed;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let data;
|
|
83
|
+
let parsedJson = false;
|
|
84
|
+
if (dataLines.length) {
|
|
85
|
+
const rawData = dataLines.join('\n');
|
|
86
|
+
try {
|
|
87
|
+
data = JSON.parse(rawData);
|
|
88
|
+
parsedJson = true;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
data = rawData;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (parsedJson) {
|
|
95
|
+
if (responseValidator) {
|
|
96
|
+
await responseValidator(data);
|
|
97
|
+
}
|
|
98
|
+
if (responseTransformer) {
|
|
99
|
+
data = await responseTransformer(data);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
onSseEvent?.({
|
|
103
|
+
data,
|
|
104
|
+
event: eventName,
|
|
105
|
+
id: lastEventId,
|
|
106
|
+
retry: retryDelay,
|
|
107
|
+
});
|
|
108
|
+
if (dataLines.length) {
|
|
109
|
+
yield data;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
signal.removeEventListener('abort', abortHandler);
|
|
116
|
+
reader.releaseLock();
|
|
117
|
+
}
|
|
118
|
+
break; // exit loop on normal completion
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
// connection failed or aborted; retry after delay
|
|
122
|
+
onSseError?.(error);
|
|
123
|
+
if (sseMaxRetryAttempts !== undefined &&
|
|
124
|
+
attempt >= sseMaxRetryAttempts) {
|
|
125
|
+
break; // stop after firing error
|
|
126
|
+
}
|
|
127
|
+
// exponential backoff: double retry each attempt, cap at 30s
|
|
128
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
|
|
129
|
+
await sleep(backoff);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const stream = createStream();
|
|
134
|
+
return { stream };
|
|
135
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Auth, AuthToken } from './auth.gen';
|
|
2
|
+
import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen';
|
|
3
|
+
export type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
|
|
4
|
+
export type Client<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
|
|
5
|
+
/**
|
|
6
|
+
* Returns the final request URL.
|
|
7
|
+
*/
|
|
8
|
+
buildUrl: BuildUrlFn;
|
|
9
|
+
getConfig: () => Config;
|
|
10
|
+
request: RequestFn;
|
|
11
|
+
setConfig: (config: Config) => Config;
|
|
12
|
+
} & {
|
|
13
|
+
[K in HttpMethod]: MethodFn;
|
|
14
|
+
} & ([SseFn] extends [never] ? {
|
|
15
|
+
sse?: never;
|
|
16
|
+
} : {
|
|
17
|
+
sse: {
|
|
18
|
+
[K in HttpMethod]: SseFn;
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
export interface Config {
|
|
22
|
+
/**
|
|
23
|
+
* Auth token or a function returning auth token. The resolved value will be
|
|
24
|
+
* added to the request payload as defined by its `security` array.
|
|
25
|
+
*/
|
|
26
|
+
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
|
|
27
|
+
/**
|
|
28
|
+
* A function for serializing request body parameter. By default,
|
|
29
|
+
* {@link JSON.stringify()} will be used.
|
|
30
|
+
*/
|
|
31
|
+
bodySerializer?: BodySerializer | null;
|
|
32
|
+
/**
|
|
33
|
+
* An object containing any HTTP headers that you want to pre-populate your
|
|
34
|
+
* `Headers` object with.
|
|
35
|
+
*
|
|
36
|
+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
|
37
|
+
*/
|
|
38
|
+
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* The request method.
|
|
41
|
+
*
|
|
42
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
43
|
+
*/
|
|
44
|
+
method?: Uppercase<HttpMethod>;
|
|
45
|
+
/**
|
|
46
|
+
* A function for serializing request query parameters. By default, arrays
|
|
47
|
+
* will be exploded in form style, objects will be exploded in deepObject
|
|
48
|
+
* style, and reserved characters are percent-encoded.
|
|
49
|
+
*
|
|
50
|
+
* This method will have no effect if the native `paramsSerializer()` Axios
|
|
51
|
+
* API function is used.
|
|
52
|
+
*
|
|
53
|
+
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
|
|
54
|
+
*/
|
|
55
|
+
querySerializer?: QuerySerializer | QuerySerializerOptions;
|
|
56
|
+
/**
|
|
57
|
+
* A function validating request data. This is useful if you want to ensure
|
|
58
|
+
* the request conforms to the desired shape, so it can be safely sent to
|
|
59
|
+
* the server.
|
|
60
|
+
*/
|
|
61
|
+
requestValidator?: (data: unknown) => Promise<unknown>;
|
|
62
|
+
/**
|
|
63
|
+
* A function transforming response data before it's returned. This is useful
|
|
64
|
+
* for post-processing data, e.g. converting ISO strings into Date objects.
|
|
65
|
+
*/
|
|
66
|
+
responseTransformer?: (data: unknown) => Promise<unknown>;
|
|
67
|
+
/**
|
|
68
|
+
* A function validating response data. This is useful if you want to ensure
|
|
69
|
+
* the response conforms to the desired shape, so it can be safely passed to
|
|
70
|
+
* the transformers and returned to the user.
|
|
71
|
+
*/
|
|
72
|
+
responseValidator?: (data: unknown) => Promise<unknown>;
|
|
73
|
+
}
|
|
74
|
+
type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never] ? true : [T] extends [never | undefined] ? [undefined] extends [T] ? false : true : false;
|
|
75
|
+
export type OmitNever<T extends Record<string, unknown>> = {
|
|
76
|
+
[K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true ? never : K]: T[K];
|
|
77
|
+
};
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BodySerializer, QuerySerializer } from './bodySerializer.gen';
|
|
2
|
+
export interface PathSerializer {
|
|
3
|
+
path: Record<string, unknown>;
|
|
4
|
+
url: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const PATH_PARAM_RE: RegExp;
|
|
7
|
+
export declare const defaultPathSerializer: ({ path, url: _url }: PathSerializer) => string;
|
|
8
|
+
export declare const getUrl: ({ baseUrl, path, query, querySerializer, url: _url, }: {
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
path?: Record<string, unknown>;
|
|
11
|
+
query?: Record<string, unknown>;
|
|
12
|
+
querySerializer: QuerySerializer;
|
|
13
|
+
url: string;
|
|
14
|
+
}) => string;
|
|
15
|
+
export declare function getValidRequestBody(options: {
|
|
16
|
+
body?: unknown;
|
|
17
|
+
bodySerializer?: BodySerializer | null;
|
|
18
|
+
serializedBody?: unknown;
|
|
19
|
+
}): unknown;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam, } from './pathSerializer.gen';
|
|
3
|
+
export const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
4
|
+
export const defaultPathSerializer = ({ path, url: _url }) => {
|
|
5
|
+
let url = _url;
|
|
6
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
7
|
+
if (matches) {
|
|
8
|
+
for (const match of matches) {
|
|
9
|
+
let explode = false;
|
|
10
|
+
let name = match.substring(1, match.length - 1);
|
|
11
|
+
let style = 'simple';
|
|
12
|
+
if (name.endsWith('*')) {
|
|
13
|
+
explode = true;
|
|
14
|
+
name = name.substring(0, name.length - 1);
|
|
15
|
+
}
|
|
16
|
+
if (name.startsWith('.')) {
|
|
17
|
+
name = name.substring(1);
|
|
18
|
+
style = 'label';
|
|
19
|
+
}
|
|
20
|
+
else if (name.startsWith(';')) {
|
|
21
|
+
name = name.substring(1);
|
|
22
|
+
style = 'matrix';
|
|
23
|
+
}
|
|
24
|
+
const value = path[name];
|
|
25
|
+
if (value === undefined || value === null) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'object') {
|
|
33
|
+
url = url.replace(match, serializeObjectParam({
|
|
34
|
+
explode,
|
|
35
|
+
name,
|
|
36
|
+
style,
|
|
37
|
+
value: value,
|
|
38
|
+
valueOnly: true,
|
|
39
|
+
}));
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (style === 'matrix') {
|
|
43
|
+
url = url.replace(match, `;${serializePrimitiveParam({
|
|
44
|
+
name,
|
|
45
|
+
value: value,
|
|
46
|
+
})}`);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const replaceValue = encodeURIComponent(style === 'label' ? `.${value}` : value);
|
|
50
|
+
url = url.replace(match, replaceValue);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return url;
|
|
54
|
+
};
|
|
55
|
+
export const getUrl = ({ baseUrl, path, query, querySerializer, url: _url, }) => {
|
|
56
|
+
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
57
|
+
let url = (baseUrl ?? '') + pathUrl;
|
|
58
|
+
if (path) {
|
|
59
|
+
url = defaultPathSerializer({ path, url });
|
|
60
|
+
}
|
|
61
|
+
let search = query ? querySerializer(query) : '';
|
|
62
|
+
if (search.startsWith('?')) {
|
|
63
|
+
search = search.substring(1);
|
|
64
|
+
}
|
|
65
|
+
if (search) {
|
|
66
|
+
url += `?${search}`;
|
|
67
|
+
}
|
|
68
|
+
return url;
|
|
69
|
+
};
|
|
70
|
+
export function getValidRequestBody(options) {
|
|
71
|
+
const hasBody = options.body !== undefined;
|
|
72
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
73
|
+
if (isSerializedBody) {
|
|
74
|
+
if ('serializedBody' in options) {
|
|
75
|
+
const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== '';
|
|
76
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
77
|
+
}
|
|
78
|
+
// not all clients implement a serializedBody property (i.e. client-axios)
|
|
79
|
+
return options.body !== '' ? options.body : null;
|
|
80
|
+
}
|
|
81
|
+
// plain/text body
|
|
82
|
+
if (hasBody) {
|
|
83
|
+
return options.body;
|
|
84
|
+
}
|
|
85
|
+
// no body was provided
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
@@ -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>;
|