@ericsanchezok/synergy-sdk 0.0.2 → 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/dist/client.d.ts +3 -3
- package/dist/client.js +6 -4
- package/dist/gen/client/client.gen.js +92 -32
- package/dist/gen/client/index.d.ts +2 -1
- package/dist/gen/client/index.js +1 -0
- package/dist/gen/client/types.gen.d.ts +6 -16
- package/dist/gen/client/utils.gen.d.ts +7 -12
- package/dist/gen/client/utils.gen.js +32 -32
- package/dist/gen/client.gen.d.ts +3 -3
- package/dist/gen/client.gen.js +1 -3
- package/dist/gen/core/bodySerializer.gen.d.ts +12 -4
- package/dist/gen/core/params.gen.d.ts +10 -0
- package/dist/gen/core/params.gen.js +18 -5
- package/dist/gen/core/serverSentEvents.gen.d.ts +13 -1
- package/dist/gen/core/serverSentEvents.gen.js +16 -2
- package/dist/gen/core/types.gen.d.ts +12 -12
- package/dist/gen/core/utils.gen.d.ts +6 -1
- package/dist/gen/core/utils.gen.js +18 -0
- package/dist/gen/sdk.gen.d.ts +1713 -198
- package/dist/gen/sdk.gen.js +3312 -383
- package/dist/gen/types.gen.d.ts +5376 -1146
- package/package.json +2 -14
- package/dist/v2/client.d.ts +0 -11
- package/dist/v2/client.js +0 -29
- package/dist/v2/gen/client/client.gen.d.ts +0 -2
- package/dist/v2/gen/client/client.gen.js +0 -225
- package/dist/v2/gen/client/index.d.ts +0 -8
- package/dist/v2/gen/client/index.js +0 -6
- package/dist/v2/gen/client/types.gen.d.ts +0 -117
- package/dist/v2/gen/client/types.gen.js +0 -2
- package/dist/v2/gen/client/utils.gen.d.ts +0 -33
- package/dist/v2/gen/client/utils.gen.js +0 -226
- package/dist/v2/gen/client.gen.d.ts +0 -12
- package/dist/v2/gen/client.gen.js +0 -3
- package/dist/v2/gen/core/auth.gen.d.ts +0 -18
- package/dist/v2/gen/core/auth.gen.js +0 -14
- package/dist/v2/gen/core/bodySerializer.gen.d.ts +0 -25
- package/dist/v2/gen/core/bodySerializer.gen.js +0 -57
- package/dist/v2/gen/core/params.gen.d.ts +0 -43
- package/dist/v2/gen/core/params.gen.js +0 -102
- package/dist/v2/gen/core/pathSerializer.gen.d.ts +0 -33
- package/dist/v2/gen/core/pathSerializer.gen.js +0 -106
- package/dist/v2/gen/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/v2/gen/core/serverSentEvents.gen.js +0 -131
- package/dist/v2/gen/core/types.gen.d.ts +0 -78
- package/dist/v2/gen/core/types.gen.js +0 -2
- package/dist/v2/gen/core/utils.gen.d.ts +0 -19
- package/dist/v2/gen/core/utils.gen.js +0 -87
- package/dist/v2/gen/sdk.gen.d.ts +0 -1114
- package/dist/v2/gen/sdk.gen.js +0 -2145
- package/dist/v2/gen/types.gen.d.ts +0 -4553
- package/dist/v2/gen/types.gen.js +0 -2
- package/dist/v2/index.d.ts +0 -12
- package/dist/v2/index.js +0 -18
- package/dist/v2/server.d.ts +0 -27
- package/dist/v2/server.js +0 -98
- /package/dist/{v2/gen → gen}/core/queryKeySerializer.gen.d.ts +0 -0
- /package/dist/{v2/gen → gen}/core/queryKeySerializer.gen.js +0 -0
package/dist/client.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export * from "./gen/types.gen.js";
|
|
2
2
|
import { type Config } from "./gen/client/types.gen.js";
|
|
3
|
-
import {
|
|
3
|
+
import { SynergyClient } from "./gen/sdk.gen.js";
|
|
4
4
|
export { type Config as SynergyClientConfig };
|
|
5
5
|
export { type Config as OpencodeClientConfig };
|
|
6
|
-
export {
|
|
6
|
+
export { SynergyClient, SynergyClient as OpencodeClient };
|
|
7
7
|
export declare function createSynergyClient(config?: Config & {
|
|
8
8
|
directory?: string;
|
|
9
|
-
}):
|
|
9
|
+
}): SynergyClient;
|
|
10
10
|
/** @deprecated Use createSynergyClient instead */
|
|
11
11
|
export declare const createOpencodeClient: typeof createSynergyClient;
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./gen/types.gen.js";
|
|
2
2
|
import { createClient } from "./gen/client/client.gen.js";
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
3
|
+
import { SynergyClient } from "./gen/sdk.gen.js";
|
|
4
|
+
export { SynergyClient, SynergyClient as OpencodeClient };
|
|
5
5
|
export function createSynergyClient(config) {
|
|
6
6
|
if (!config?.fetch) {
|
|
7
7
|
const customFetch = (req) => {
|
|
@@ -15,13 +15,15 @@ export function createSynergyClient(config) {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
if (config?.directory) {
|
|
18
|
+
const isNonASCII = /[^\x00-\x7F]/.test(config.directory);
|
|
19
|
+
const encodedDirectory = isNonASCII ? encodeURIComponent(config.directory) : config.directory;
|
|
18
20
|
config.headers = {
|
|
19
21
|
...config.headers,
|
|
20
|
-
"x-synergy-directory":
|
|
22
|
+
"x-synergy-directory": encodedDirectory,
|
|
21
23
|
};
|
|
22
24
|
}
|
|
23
25
|
const client = createClient(config);
|
|
24
|
-
return new
|
|
26
|
+
return new SynergyClient({ client });
|
|
25
27
|
}
|
|
26
28
|
/** @deprecated Use createSynergyClient instead */
|
|
27
29
|
export const createOpencodeClient = createSynergyClient;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
2
|
import { createSseClient } from "../core/serverSentEvents.gen.js";
|
|
3
|
+
import { getValidRequestBody } from "../core/utils.gen.js";
|
|
3
4
|
import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from "./utils.gen.js";
|
|
4
5
|
export const createClient = (config = {}) => {
|
|
5
6
|
let _config = mergeConfigs(createConfig(), config);
|
|
@@ -26,11 +27,11 @@ export const createClient = (config = {}) => {
|
|
|
26
27
|
if (opts.requestValidator) {
|
|
27
28
|
await opts.requestValidator(opts);
|
|
28
29
|
}
|
|
29
|
-
if (opts.body && opts.bodySerializer) {
|
|
30
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
30
31
|
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
31
32
|
}
|
|
32
33
|
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
33
|
-
if (opts.
|
|
34
|
+
if (opts.body === undefined || opts.serializedBody === "") {
|
|
34
35
|
opts.headers.delete("Content-Type");
|
|
35
36
|
}
|
|
36
37
|
const url = buildUrl(opts);
|
|
@@ -42,10 +43,10 @@ export const createClient = (config = {}) => {
|
|
|
42
43
|
const requestInit = {
|
|
43
44
|
redirect: "follow",
|
|
44
45
|
...opts,
|
|
45
|
-
body: opts
|
|
46
|
+
body: getValidRequestBody(opts),
|
|
46
47
|
};
|
|
47
48
|
let request = new Request(url, requestInit);
|
|
48
|
-
for (const fn of interceptors.request.
|
|
49
|
+
for (const fn of interceptors.request.fns) {
|
|
49
50
|
if (fn) {
|
|
50
51
|
request = await fn(request, opts);
|
|
51
52
|
}
|
|
@@ -53,8 +54,32 @@ export const createClient = (config = {}) => {
|
|
|
53
54
|
// fetch must be assigned here, otherwise it would throw the error:
|
|
54
55
|
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
55
56
|
const _fetch = opts.fetch;
|
|
56
|
-
let response
|
|
57
|
-
|
|
57
|
+
let response;
|
|
58
|
+
try {
|
|
59
|
+
response = await _fetch(request);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
63
|
+
let finalError = error;
|
|
64
|
+
for (const fn of interceptors.error.fns) {
|
|
65
|
+
if (fn) {
|
|
66
|
+
finalError = (await fn(error, undefined, request, opts));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
finalError = finalError || {};
|
|
70
|
+
if (opts.throwOnError) {
|
|
71
|
+
throw finalError;
|
|
72
|
+
}
|
|
73
|
+
// Return error response
|
|
74
|
+
return opts.responseStyle === "data"
|
|
75
|
+
? undefined
|
|
76
|
+
: {
|
|
77
|
+
error: finalError,
|
|
78
|
+
request,
|
|
79
|
+
response: undefined,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
for (const fn of interceptors.response.fns) {
|
|
58
83
|
if (fn) {
|
|
59
84
|
response = await fn(response, request, opts);
|
|
60
85
|
}
|
|
@@ -64,15 +89,33 @@ export const createClient = (config = {}) => {
|
|
|
64
89
|
response,
|
|
65
90
|
};
|
|
66
91
|
if (response.ok) {
|
|
92
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
67
93
|
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
94
|
+
let emptyData;
|
|
95
|
+
switch (parseAs) {
|
|
96
|
+
case "arrayBuffer":
|
|
97
|
+
case "blob":
|
|
98
|
+
case "text":
|
|
99
|
+
emptyData = await response[parseAs]();
|
|
100
|
+
break;
|
|
101
|
+
case "formData":
|
|
102
|
+
emptyData = new FormData();
|
|
103
|
+
break;
|
|
104
|
+
case "stream":
|
|
105
|
+
emptyData = response.body;
|
|
106
|
+
break;
|
|
107
|
+
case "json":
|
|
108
|
+
default:
|
|
109
|
+
emptyData = {};
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
68
112
|
return opts.responseStyle === "data"
|
|
69
|
-
?
|
|
113
|
+
? emptyData
|
|
70
114
|
: {
|
|
71
|
-
data:
|
|
115
|
+
data: emptyData,
|
|
72
116
|
...result,
|
|
73
117
|
};
|
|
74
118
|
}
|
|
75
|
-
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
76
119
|
let data;
|
|
77
120
|
switch (parseAs) {
|
|
78
121
|
case "arrayBuffer":
|
|
@@ -115,7 +158,7 @@ export const createClient = (config = {}) => {
|
|
|
115
158
|
}
|
|
116
159
|
const error = jsonError ?? textError;
|
|
117
160
|
let finalError = error;
|
|
118
|
-
for (const fn of interceptors.error.
|
|
161
|
+
for (const fn of interceptors.error.fns) {
|
|
119
162
|
if (fn) {
|
|
120
163
|
finalError = (await fn(error, response, request, opts));
|
|
121
164
|
}
|
|
@@ -132,34 +175,51 @@ export const createClient = (config = {}) => {
|
|
|
132
175
|
...result,
|
|
133
176
|
};
|
|
134
177
|
};
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
url,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
178
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
179
|
+
const makeSseFn = (method) => async (options) => {
|
|
180
|
+
const { opts, url } = await beforeRequest(options);
|
|
181
|
+
return createSseClient({
|
|
182
|
+
...opts,
|
|
183
|
+
body: opts.body,
|
|
184
|
+
headers: opts.headers,
|
|
185
|
+
method,
|
|
186
|
+
onRequest: async (url, init) => {
|
|
187
|
+
let request = new Request(url, init);
|
|
188
|
+
for (const fn of interceptors.request.fns) {
|
|
189
|
+
if (fn) {
|
|
190
|
+
request = await fn(request, opts);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return request;
|
|
194
|
+
},
|
|
195
|
+
url,
|
|
196
|
+
});
|
|
148
197
|
};
|
|
149
198
|
return {
|
|
150
199
|
buildUrl,
|
|
151
|
-
connect:
|
|
152
|
-
delete:
|
|
153
|
-
get:
|
|
200
|
+
connect: makeMethodFn("CONNECT"),
|
|
201
|
+
delete: makeMethodFn("DELETE"),
|
|
202
|
+
get: makeMethodFn("GET"),
|
|
154
203
|
getConfig,
|
|
155
|
-
head:
|
|
204
|
+
head: makeMethodFn("HEAD"),
|
|
156
205
|
interceptors,
|
|
157
|
-
options:
|
|
158
|
-
patch:
|
|
159
|
-
post:
|
|
160
|
-
put:
|
|
206
|
+
options: makeMethodFn("OPTIONS"),
|
|
207
|
+
patch: makeMethodFn("PATCH"),
|
|
208
|
+
post: makeMethodFn("POST"),
|
|
209
|
+
put: makeMethodFn("PUT"),
|
|
161
210
|
request,
|
|
162
211
|
setConfig,
|
|
163
|
-
|
|
212
|
+
sse: {
|
|
213
|
+
connect: makeSseFn("CONNECT"),
|
|
214
|
+
delete: makeSseFn("DELETE"),
|
|
215
|
+
get: makeSseFn("GET"),
|
|
216
|
+
head: makeSseFn("HEAD"),
|
|
217
|
+
options: makeSseFn("OPTIONS"),
|
|
218
|
+
patch: makeSseFn("PATCH"),
|
|
219
|
+
post: makeSseFn("POST"),
|
|
220
|
+
put: makeSseFn("PUT"),
|
|
221
|
+
trace: makeSseFn("TRACE"),
|
|
222
|
+
},
|
|
223
|
+
trace: makeMethodFn("TRACE"),
|
|
164
224
|
};
|
|
165
225
|
};
|
|
@@ -2,6 +2,7 @@ export type { Auth } from "../core/auth.gen.js";
|
|
|
2
2
|
export type { QuerySerializerOptions } from "../core/bodySerializer.gen.js";
|
|
3
3
|
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from "../core/bodySerializer.gen.js";
|
|
4
4
|
export { buildClientParams } from "../core/params.gen.js";
|
|
5
|
+
export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen.js";
|
|
5
6
|
export { createClient } from "./client.gen.js";
|
|
6
|
-
export type { Client, ClientOptions, Config, CreateClientConfig, Options,
|
|
7
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from "./types.gen.js";
|
|
7
8
|
export { createConfig, mergeHeaders } from "./utils.gen.js";
|
package/dist/gen/client/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
2
|
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from "../core/bodySerializer.gen.js";
|
|
3
3
|
export { buildClientParams } from "../core/params.gen.js";
|
|
4
|
+
export { serializeQueryKeyValue } from "../core/queryKeySerializer.gen.js";
|
|
4
5
|
export { createClient } from "./client.gen.js";
|
|
5
6
|
export { createConfig, mergeHeaders } from "./utils.gen.js";
|
|
@@ -14,7 +14,7 @@ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<Re
|
|
|
14
14
|
*
|
|
15
15
|
* @default globalThis.fetch
|
|
16
16
|
*/
|
|
17
|
-
fetch?:
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
18
|
/**
|
|
19
19
|
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
20
20
|
* options won't have any effect.
|
|
@@ -84,19 +84,16 @@ export interface ClientOptions {
|
|
|
84
84
|
responseStyle?: ResponseStyle;
|
|
85
85
|
throwOnError?: boolean;
|
|
86
86
|
}
|
|
87
|
-
type
|
|
88
|
-
type
|
|
89
|
-
type MethodFn = MethodFnBase & {
|
|
90
|
-
sse: MethodFnServerSentEvents;
|
|
91
|
-
};
|
|
87
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
88
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
92
89
|
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
93
90
|
type BuildUrlFn = <TData extends {
|
|
94
91
|
body?: unknown;
|
|
95
92
|
path?: Record<string, unknown>;
|
|
96
93
|
query?: Record<string, unknown>;
|
|
97
94
|
url: string;
|
|
98
|
-
}>(options:
|
|
99
|
-
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
|
|
95
|
+
}>(options: TData & Options<TData>) => string;
|
|
96
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
100
97
|
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
101
98
|
};
|
|
102
99
|
/**
|
|
@@ -116,12 +113,5 @@ export interface TDataShape {
|
|
|
116
113
|
url: string;
|
|
117
114
|
}
|
|
118
115
|
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
119
|
-
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = "fields"> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, "body" | "path" | "query" | "url"> & Omit<TData, "url"
|
|
120
|
-
export type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = "fields"> = TData extends {
|
|
121
|
-
body?: any;
|
|
122
|
-
} ? TData extends {
|
|
123
|
-
headers?: any;
|
|
124
|
-
} ? OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "body" | "headers" | "url"> & TData : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "body" | "url"> & TData & Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "headers"> : TData extends {
|
|
125
|
-
headers?: any;
|
|
126
|
-
} ? OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "headers" | "url"> & TData & Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "body"> : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "url"> & TData;
|
|
116
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = "fields"> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, "body" | "path" | "query" | "url"> & ([TData] extends [never] ? unknown : Omit<TData, "url">);
|
|
127
117
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { QuerySerializerOptions } from "../core/bodySerializer.gen.js";
|
|
2
2
|
import type { Client, ClientOptions, Config, RequestOptions } from "./types.gen.js";
|
|
3
|
-
export declare const createQuerySerializer: <T = unknown>({
|
|
3
|
+
export declare const createQuerySerializer: <T = unknown>({ parameters, ...args }?: QuerySerializerOptions) => (queryParams: T) => string;
|
|
4
4
|
/**
|
|
5
5
|
* Infers parseAs value from provided Content-Type header.
|
|
6
6
|
*/
|
|
@@ -15,24 +15,19 @@ type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, reques
|
|
|
15
15
|
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
16
16
|
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
17
17
|
declare class Interceptors<Interceptor> {
|
|
18
|
-
|
|
19
|
-
constructor();
|
|
18
|
+
fns: Array<Interceptor | null>;
|
|
20
19
|
clear(): void;
|
|
21
|
-
getInterceptorIndex(id: number | Interceptor): number;
|
|
22
|
-
exists(id: number | Interceptor): boolean;
|
|
23
20
|
eject(id: number | Interceptor): void;
|
|
24
|
-
|
|
21
|
+
exists(id: number | Interceptor): boolean;
|
|
22
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
23
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
25
24
|
use(fn: Interceptor): number;
|
|
26
25
|
}
|
|
27
26
|
export interface Middleware<Req, Res, Err, Options> {
|
|
28
|
-
error: Pick<Interceptors<ErrInterceptor<Err, Res, Req, Options>>, "eject" | "use">;
|
|
29
|
-
request: Pick<Interceptors<ReqInterceptor<Req, Options>>, "eject" | "use">;
|
|
30
|
-
response: Pick<Interceptors<ResInterceptor<Res, Req, Options>>, "eject" | "use">;
|
|
31
|
-
}
|
|
32
|
-
export declare const createInterceptors: <Req, Res, Err, Options>() => {
|
|
33
27
|
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
34
28
|
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
35
29
|
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
36
|
-
}
|
|
30
|
+
}
|
|
31
|
+
export declare const createInterceptors: <Req, Res, Err, Options>() => Middleware<Req, Res, Err, Options>;
|
|
37
32
|
export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
|
|
38
33
|
export {};
|
|
@@ -3,7 +3,7 @@ import { getAuthToken } from "../core/auth.gen.js";
|
|
|
3
3
|
import { jsonBodySerializer } from "../core/bodySerializer.gen.js";
|
|
4
4
|
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer.gen.js";
|
|
5
5
|
import { getUrl } from "../core/utils.gen.js";
|
|
6
|
-
export const createQuerySerializer = ({
|
|
6
|
+
export const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
7
7
|
const querySerializer = (queryParams) => {
|
|
8
8
|
const search = [];
|
|
9
9
|
if (queryParams && typeof queryParams === "object") {
|
|
@@ -12,33 +12,34 @@ export const createQuerySerializer = ({ allowReserved, array, object } = {}) =>
|
|
|
12
12
|
if (value === undefined || value === null) {
|
|
13
13
|
continue;
|
|
14
14
|
}
|
|
15
|
+
const options = parameters[name] || args;
|
|
15
16
|
if (Array.isArray(value)) {
|
|
16
17
|
const serializedArray = serializeArrayParam({
|
|
17
|
-
allowReserved,
|
|
18
|
+
allowReserved: options.allowReserved,
|
|
18
19
|
explode: true,
|
|
19
20
|
name,
|
|
20
21
|
style: "form",
|
|
21
22
|
value,
|
|
22
|
-
...array,
|
|
23
|
+
...options.array,
|
|
23
24
|
});
|
|
24
25
|
if (serializedArray)
|
|
25
26
|
search.push(serializedArray);
|
|
26
27
|
}
|
|
27
28
|
else if (typeof value === "object") {
|
|
28
29
|
const serializedObject = serializeObjectParam({
|
|
29
|
-
allowReserved,
|
|
30
|
+
allowReserved: options.allowReserved,
|
|
30
31
|
explode: true,
|
|
31
32
|
name,
|
|
32
33
|
style: "deepObject",
|
|
33
34
|
value: value,
|
|
34
|
-
...object,
|
|
35
|
+
...options.object,
|
|
35
36
|
});
|
|
36
37
|
if (serializedObject)
|
|
37
38
|
search.push(serializedObject);
|
|
38
39
|
}
|
|
39
40
|
else {
|
|
40
41
|
const serializedPrimitive = serializePrimitiveParam({
|
|
41
|
-
allowReserved,
|
|
42
|
+
allowReserved: options.allowReserved,
|
|
42
43
|
name,
|
|
43
44
|
value: value,
|
|
44
45
|
});
|
|
@@ -131,13 +132,20 @@ export const mergeConfigs = (a, b) => {
|
|
|
131
132
|
config.headers = mergeHeaders(a.headers, b.headers);
|
|
132
133
|
return config;
|
|
133
134
|
};
|
|
135
|
+
const headersEntries = (headers) => {
|
|
136
|
+
const entries = [];
|
|
137
|
+
headers.forEach((value, key) => {
|
|
138
|
+
entries.push([key, value]);
|
|
139
|
+
});
|
|
140
|
+
return entries;
|
|
141
|
+
};
|
|
134
142
|
export const mergeHeaders = (...headers) => {
|
|
135
143
|
const mergedHeaders = new Headers();
|
|
136
144
|
for (const header of headers) {
|
|
137
|
-
if (!header
|
|
145
|
+
if (!header) {
|
|
138
146
|
continue;
|
|
139
147
|
}
|
|
140
|
-
const iterator = header instanceof Headers ? header
|
|
148
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
141
149
|
for (const [key, value] of iterator) {
|
|
142
150
|
if (value === null) {
|
|
143
151
|
mergedHeaders.delete(key);
|
|
@@ -157,47 +165,39 @@ export const mergeHeaders = (...headers) => {
|
|
|
157
165
|
return mergedHeaders;
|
|
158
166
|
};
|
|
159
167
|
class Interceptors {
|
|
160
|
-
|
|
161
|
-
constructor() {
|
|
162
|
-
this._fns = [];
|
|
163
|
-
}
|
|
168
|
+
fns = [];
|
|
164
169
|
clear() {
|
|
165
|
-
this.
|
|
170
|
+
this.fns = [];
|
|
166
171
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
else {
|
|
172
|
-
return this._fns.indexOf(id);
|
|
172
|
+
eject(id) {
|
|
173
|
+
const index = this.getInterceptorIndex(id);
|
|
174
|
+
if (this.fns[index]) {
|
|
175
|
+
this.fns[index] = null;
|
|
173
176
|
}
|
|
174
177
|
}
|
|
175
178
|
exists(id) {
|
|
176
179
|
const index = this.getInterceptorIndex(id);
|
|
177
|
-
return
|
|
180
|
+
return Boolean(this.fns[index]);
|
|
178
181
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this._fns[index] = null;
|
|
182
|
+
getInterceptorIndex(id) {
|
|
183
|
+
if (typeof id === "number") {
|
|
184
|
+
return this.fns[id] ? id : -1;
|
|
183
185
|
}
|
|
186
|
+
return this.fns.indexOf(id);
|
|
184
187
|
}
|
|
185
188
|
update(id, fn) {
|
|
186
189
|
const index = this.getInterceptorIndex(id);
|
|
187
|
-
if (this.
|
|
188
|
-
this.
|
|
190
|
+
if (this.fns[index]) {
|
|
191
|
+
this.fns[index] = fn;
|
|
189
192
|
return id;
|
|
190
193
|
}
|
|
191
|
-
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
+
return false;
|
|
194
195
|
}
|
|
195
196
|
use(fn) {
|
|
196
|
-
this.
|
|
197
|
-
return this.
|
|
197
|
+
this.fns.push(fn);
|
|
198
|
+
return this.fns.length - 1;
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
|
-
// do not add `Middleware` as return type so we can use _fns internally
|
|
201
201
|
export const createInterceptors = () => ({
|
|
202
202
|
error: new Interceptors(),
|
|
203
203
|
request: new Interceptors(),
|
package/dist/gen/client.gen.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
1
|
+
import { type ClientOptions, type Config } from "./client/index.js";
|
|
2
|
+
import type { ClientOptions as ClientOptions2 } from "./types.gen.js";
|
|
3
3
|
/**
|
|
4
4
|
* The `createClientConfig()` function will be called on client initialization
|
|
5
5
|
* and the returned object will become the client's initial configuration.
|
|
@@ -8,5 +8,5 @@ import { type Config, type ClientOptions as DefaultClientOptions } from "./clien
|
|
|
8
8
|
* `setConfig()`. This is useful for example if you're using Next.js
|
|
9
9
|
* to ensure your client always has the correct values.
|
|
10
10
|
*/
|
|
11
|
-
export type CreateClientConfig<T extends
|
|
11
|
+
export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
|
|
12
12
|
export declare const client: import("./client/types.gen.js").Client;
|
package/dist/gen/client.gen.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
2
|
import { createClient, createConfig } from "./client/index.js";
|
|
3
|
-
export const client = createClient(createConfig({
|
|
4
|
-
baseUrl: "http://localhost:4096",
|
|
5
|
-
}));
|
|
3
|
+
export const client = createClient(createConfig({ baseUrl: "http://localhost:4096" }));
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer.gen.js";
|
|
2
2
|
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
3
3
|
export type BodySerializer = (body: any) => any;
|
|
4
|
-
|
|
4
|
+
type QuerySerializerOptionsObject = {
|
|
5
5
|
allowReserved?: boolean;
|
|
6
|
-
array?: SerializerOptions<ArrayStyle
|
|
7
|
-
object?: SerializerOptions<ObjectStyle
|
|
8
|
-
}
|
|
6
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
7
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
8
|
+
};
|
|
9
|
+
export type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
10
|
+
/**
|
|
11
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
12
|
+
* override the global array/object settings for specific parameter names.
|
|
13
|
+
*/
|
|
14
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
15
|
+
};
|
|
9
16
|
export declare const formDataBodySerializer: {
|
|
10
17
|
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => FormData;
|
|
11
18
|
};
|
|
@@ -15,3 +22,4 @@ export declare const jsonBodySerializer: {
|
|
|
15
22
|
export declare const urlSearchParamsBodySerializer: {
|
|
16
23
|
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
|
|
17
24
|
};
|
|
25
|
+
export {};
|
|
@@ -17,6 +17,16 @@ export type Field = {
|
|
|
17
17
|
*/
|
|
18
18
|
key?: string;
|
|
19
19
|
map?: string;
|
|
20
|
+
} | {
|
|
21
|
+
/**
|
|
22
|
+
* Field name. This is the name we want the user to see and use.
|
|
23
|
+
*/
|
|
24
|
+
key: string;
|
|
25
|
+
/**
|
|
26
|
+
* Field mapped name. This is the name we want to use in the request.
|
|
27
|
+
* If `in` is omitted, `map` aliases `key` to the transport layer.
|
|
28
|
+
*/
|
|
29
|
+
map: Slot;
|
|
20
30
|
};
|
|
21
31
|
export interface Fields {
|
|
22
32
|
allowExtra?: Partial<Record<Slot, boolean>>;
|
|
@@ -19,6 +19,11 @@ const buildKeyMap = (fields, map) => {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
else if ("key" in config) {
|
|
23
|
+
map.set(config.key, {
|
|
24
|
+
map: config.map,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
22
27
|
else if (config.args) {
|
|
23
28
|
buildKeyMap(config.args, map);
|
|
24
29
|
}
|
|
@@ -52,7 +57,10 @@ export const buildClientParams = (args, fields) => {
|
|
|
52
57
|
if (config.key) {
|
|
53
58
|
const field = map.get(config.key);
|
|
54
59
|
const name = field.map || config.key;
|
|
55
|
-
|
|
60
|
+
if (field.in) {
|
|
61
|
+
;
|
|
62
|
+
params[field.in][name] = arg;
|
|
63
|
+
}
|
|
56
64
|
}
|
|
57
65
|
else {
|
|
58
66
|
params.body = arg;
|
|
@@ -62,8 +70,13 @@ export const buildClientParams = (args, fields) => {
|
|
|
62
70
|
for (const [key, value] of Object.entries(arg ?? {})) {
|
|
63
71
|
const field = map.get(key);
|
|
64
72
|
if (field) {
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
if (field.in) {
|
|
74
|
+
const name = field.map || key;
|
|
75
|
+
params[field.in][name] = value;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
params[field.map] = value;
|
|
79
|
+
}
|
|
67
80
|
}
|
|
68
81
|
else {
|
|
69
82
|
const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
|
|
@@ -71,8 +84,8 @@ export const buildClientParams = (args, fields) => {
|
|
|
71
84
|
const [prefix, slot] = extra;
|
|
72
85
|
params[slot][key.slice(prefix.length)] = value;
|
|
73
86
|
}
|
|
74
|
-
else {
|
|
75
|
-
for (const [slot, allowed] of Object.entries(config.allowExtra
|
|
87
|
+
else if ("allowExtra" in config && config.allowExtra) {
|
|
88
|
+
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
|
76
89
|
if (allowed) {
|
|
77
90
|
;
|
|
78
91
|
params[slot][key] = value;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { Config } from "./types.gen.js";
|
|
2
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>;
|
|
3
14
|
/**
|
|
4
15
|
* Callback invoked when a network or parsing error occurs during streaming.
|
|
5
16
|
*
|
|
@@ -17,6 +28,7 @@ export type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, "method
|
|
|
17
28
|
* @returns Nothing (void).
|
|
18
29
|
*/
|
|
19
30
|
onSseEvent?: (event: StreamEvent<TData>) => void;
|
|
31
|
+
serializedBody?: RequestInit["body"];
|
|
20
32
|
/**
|
|
21
33
|
* Default retry delay in milliseconds.
|
|
22
34
|
*
|
|
@@ -56,4 +68,4 @@ export interface StreamEvent<TData = unknown> {
|
|
|
56
68
|
export type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
57
69
|
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
58
70
|
};
|
|
59
|
-
export declare const createSseClient: <TData = unknown>({ onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }: ServerSentEventsOptions) => ServerSentEventsResult<TData>;
|
|
71
|
+
export declare const createSseClient: <TData = unknown>({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }: ServerSentEventsOptions) => ServerSentEventsResult<TData>;
|