@opencode-ai/sdk 0.3.112 → 0.3.120
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/gen/client/client.d.ts +1 -1
- package/dist/gen/client/client.js +26 -29
- package/dist/gen/client/index.d.ts +7 -7
- package/dist/gen/client/index.js +4 -4
- package/dist/gen/client/types.d.ts +18 -18
- package/dist/gen/client/utils.d.ts +7 -7
- package/dist/gen/client/utils.js +46 -47
- package/dist/gen/client.gen.d.ts +2 -2
- package/dist/gen/client.gen.js +2 -2
- package/dist/gen/core/auth.d.ts +3 -3
- package/dist/gen/core/auth.js +3 -3
- package/dist/gen/core/bodySerializer.d.ts +1 -1
- package/dist/gen/core/bodySerializer.js +3 -3
- package/dist/gen/core/params.d.ts +3 -3
- package/dist/gen/core/params.js +8 -7
- package/dist/gen/core/pathSerializer.d.ts +4 -4
- package/dist/gen/core/pathSerializer.js +38 -46
- package/dist/gen/core/types.d.ts +4 -4
- package/dist/gen/sdk.gen.d.ts +2 -2
- package/dist/gen/sdk.gen.js +85 -85
- package/dist/gen/types.gen.d.ts +99 -98
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +8 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Client, Config } from
|
|
1
|
+
import type { Client, Config } from "./types";
|
|
2
2
|
export declare const createClient: (config?: Config) => Client;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from
|
|
1
|
+
import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from "./utils";
|
|
2
2
|
export const createClient = (config = {}) => {
|
|
3
3
|
let _config = mergeConfigs(createConfig(), config);
|
|
4
4
|
const getConfig = () => ({ ..._config });
|
|
@@ -27,12 +27,12 @@ export const createClient = (config = {}) => {
|
|
|
27
27
|
opts.body = opts.bodySerializer(opts.body);
|
|
28
28
|
}
|
|
29
29
|
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
30
|
-
if (opts.body === undefined || opts.body ===
|
|
31
|
-
opts.headers.delete(
|
|
30
|
+
if (opts.body === undefined || opts.body === "") {
|
|
31
|
+
opts.headers.delete("Content-Type");
|
|
32
32
|
}
|
|
33
33
|
const url = buildUrl(opts);
|
|
34
34
|
const requestInit = {
|
|
35
|
-
redirect:
|
|
35
|
+
redirect: "follow",
|
|
36
36
|
...opts,
|
|
37
37
|
};
|
|
38
38
|
let request = new Request(url, requestInit);
|
|
@@ -55,36 +55,33 @@ export const createClient = (config = {}) => {
|
|
|
55
55
|
response,
|
|
56
56
|
};
|
|
57
57
|
if (response.ok) {
|
|
58
|
-
if (response.status === 204 ||
|
|
59
|
-
|
|
60
|
-
return opts.responseStyle === 'data'
|
|
58
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
59
|
+
return opts.responseStyle === "data"
|
|
61
60
|
? {}
|
|
62
61
|
: {
|
|
63
62
|
data: {},
|
|
64
63
|
...result,
|
|
65
64
|
};
|
|
66
65
|
}
|
|
67
|
-
const parseAs = (opts.parseAs ===
|
|
68
|
-
? getParseAs(response.headers.get('Content-Type'))
|
|
69
|
-
: opts.parseAs) ?? 'json';
|
|
66
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
70
67
|
let data;
|
|
71
68
|
switch (parseAs) {
|
|
72
|
-
case
|
|
73
|
-
case
|
|
74
|
-
case
|
|
75
|
-
case
|
|
76
|
-
case
|
|
69
|
+
case "arrayBuffer":
|
|
70
|
+
case "blob":
|
|
71
|
+
case "formData":
|
|
72
|
+
case "json":
|
|
73
|
+
case "text":
|
|
77
74
|
data = await response[parseAs]();
|
|
78
75
|
break;
|
|
79
|
-
case
|
|
80
|
-
return opts.responseStyle ===
|
|
76
|
+
case "stream":
|
|
77
|
+
return opts.responseStyle === "data"
|
|
81
78
|
? response.body
|
|
82
79
|
: {
|
|
83
80
|
data: response.body,
|
|
84
81
|
...result,
|
|
85
82
|
};
|
|
86
83
|
}
|
|
87
|
-
if (parseAs ===
|
|
84
|
+
if (parseAs === "json") {
|
|
88
85
|
if (opts.responseValidator) {
|
|
89
86
|
await opts.responseValidator(data);
|
|
90
87
|
}
|
|
@@ -92,7 +89,7 @@ export const createClient = (config = {}) => {
|
|
|
92
89
|
data = await opts.responseTransformer(data);
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
|
-
return opts.responseStyle ===
|
|
92
|
+
return opts.responseStyle === "data"
|
|
96
93
|
? data
|
|
97
94
|
: {
|
|
98
95
|
data,
|
|
@@ -119,7 +116,7 @@ export const createClient = (config = {}) => {
|
|
|
119
116
|
throw finalError;
|
|
120
117
|
}
|
|
121
118
|
// TODO: we probably want to return error and improve types
|
|
122
|
-
return opts.responseStyle ===
|
|
119
|
+
return opts.responseStyle === "data"
|
|
123
120
|
? undefined
|
|
124
121
|
: {
|
|
125
122
|
error: finalError,
|
|
@@ -128,18 +125,18 @@ export const createClient = (config = {}) => {
|
|
|
128
125
|
};
|
|
129
126
|
return {
|
|
130
127
|
buildUrl,
|
|
131
|
-
connect: (options) => request({ ...options, method:
|
|
132
|
-
delete: (options) => request({ ...options, method:
|
|
133
|
-
get: (options) => request({ ...options, method:
|
|
128
|
+
connect: (options) => request({ ...options, method: "CONNECT" }),
|
|
129
|
+
delete: (options) => request({ ...options, method: "DELETE" }),
|
|
130
|
+
get: (options) => request({ ...options, method: "GET" }),
|
|
134
131
|
getConfig,
|
|
135
|
-
head: (options) => request({ ...options, method:
|
|
132
|
+
head: (options) => request({ ...options, method: "HEAD" }),
|
|
136
133
|
interceptors,
|
|
137
|
-
options: (options) => request({ ...options, method:
|
|
138
|
-
patch: (options) => request({ ...options, method:
|
|
139
|
-
post: (options) => request({ ...options, method:
|
|
140
|
-
put: (options) => request({ ...options, method:
|
|
134
|
+
options: (options) => request({ ...options, method: "OPTIONS" }),
|
|
135
|
+
patch: (options) => request({ ...options, method: "PATCH" }),
|
|
136
|
+
post: (options) => request({ ...options, method: "POST" }),
|
|
137
|
+
put: (options) => request({ ...options, method: "PUT" }),
|
|
141
138
|
request,
|
|
142
139
|
setConfig,
|
|
143
|
-
trace: (options) => request({ ...options, method:
|
|
140
|
+
trace: (options) => request({ ...options, method: "TRACE" }),
|
|
144
141
|
};
|
|
145
142
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type { Auth } from
|
|
2
|
-
export type { QuerySerializerOptions } from
|
|
3
|
-
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer
|
|
4
|
-
export { buildClientParams } from
|
|
5
|
-
export { createClient } from
|
|
6
|
-
export type { Client, ClientOptions, Config, CreateClientConfig, Options, OptionsLegacyParser, RequestOptions, RequestResult, ResponseStyle, TDataShape, } from
|
|
7
|
-
export { createConfig, mergeHeaders } from
|
|
1
|
+
export type { Auth } from "../core/auth";
|
|
2
|
+
export type { QuerySerializerOptions } from "../core/bodySerializer";
|
|
3
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer } from "../core/bodySerializer";
|
|
4
|
+
export { buildClientParams } from "../core/params";
|
|
5
|
+
export { createClient } from "./client";
|
|
6
|
+
export type { Client, ClientOptions, Config, CreateClientConfig, Options, OptionsLegacyParser, RequestOptions, RequestResult, ResponseStyle, TDataShape, } from "./types";
|
|
7
|
+
export { createConfig, mergeHeaders } from "./utils";
|
package/dist/gen/client/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer
|
|
2
|
-
export { buildClientParams } from
|
|
3
|
-
export { createClient } from
|
|
4
|
-
export { createConfig, mergeHeaders } from
|
|
1
|
+
export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer } from "../core/bodySerializer";
|
|
2
|
+
export { buildClientParams } from "../core/params";
|
|
3
|
+
export { createClient } from "./client";
|
|
4
|
+
export { createConfig, mergeHeaders } from "./utils";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Auth } from
|
|
2
|
-
import type { Client as CoreClient, Config as CoreConfig } from
|
|
3
|
-
import type { Middleware } from
|
|
4
|
-
export type ResponseStyle =
|
|
5
|
-
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit,
|
|
1
|
+
import type { Auth } from "../core/auth";
|
|
2
|
+
import type { Client as CoreClient, Config as CoreConfig } from "../core/types";
|
|
3
|
+
import type { Middleware } from "./utils";
|
|
4
|
+
export type ResponseStyle = "data" | "fields";
|
|
5
|
+
export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, "body" | "headers" | "method">, CoreConfig {
|
|
6
6
|
/**
|
|
7
7
|
* Base URL for all requests made by this client.
|
|
8
8
|
*/
|
|
9
|
-
baseUrl?: T[
|
|
9
|
+
baseUrl?: T["baseUrl"];
|
|
10
10
|
/**
|
|
11
11
|
* Fetch API implementation. You can use this option to provide a custom
|
|
12
12
|
* fetch instance.
|
|
@@ -29,7 +29,7 @@ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<Re
|
|
|
29
29
|
*
|
|
30
30
|
* @default 'auto'
|
|
31
31
|
*/
|
|
32
|
-
parseAs?:
|
|
32
|
+
parseAs?: "arrayBuffer" | "auto" | "blob" | "formData" | "json" | "stream" | "text";
|
|
33
33
|
/**
|
|
34
34
|
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
35
35
|
*
|
|
@@ -41,9 +41,9 @@ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<Re
|
|
|
41
41
|
*
|
|
42
42
|
* @default false
|
|
43
43
|
*/
|
|
44
|
-
throwOnError?: T[
|
|
44
|
+
throwOnError?: T["throwOnError"];
|
|
45
45
|
}
|
|
46
|
-
export interface RequestOptions<TResponseStyle extends ResponseStyle =
|
|
46
|
+
export interface RequestOptions<TResponseStyle extends ResponseStyle = "fields", ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
47
47
|
responseStyle: TResponseStyle;
|
|
48
48
|
throwOnError: ThrowOnError;
|
|
49
49
|
}> {
|
|
@@ -61,11 +61,11 @@ export interface RequestOptions<TResponseStyle extends ResponseStyle = 'fields',
|
|
|
61
61
|
security?: ReadonlyArray<Auth>;
|
|
62
62
|
url: Url;
|
|
63
63
|
}
|
|
64
|
-
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle =
|
|
64
|
+
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = "fields"> = ThrowOnError extends true ? Promise<TResponseStyle extends "data" ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
65
65
|
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
66
66
|
request: Request;
|
|
67
67
|
response: Response;
|
|
68
|
-
}> : Promise<TResponseStyle extends
|
|
68
|
+
}> : Promise<TResponseStyle extends "data" ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
69
69
|
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
70
70
|
error: undefined;
|
|
71
71
|
} | {
|
|
@@ -80,14 +80,14 @@ export interface ClientOptions {
|
|
|
80
80
|
responseStyle?: ResponseStyle;
|
|
81
81
|
throwOnError?: boolean;
|
|
82
82
|
}
|
|
83
|
-
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle =
|
|
84
|
-
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle =
|
|
83
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
84
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, "method"> & Pick<Required<RequestOptions<TResponseStyle, ThrowOnError>>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
85
85
|
type BuildUrlFn = <TData extends {
|
|
86
86
|
body?: unknown;
|
|
87
87
|
path?: Record<string, unknown>;
|
|
88
88
|
query?: Record<string, unknown>;
|
|
89
89
|
url: string;
|
|
90
|
-
}>(options: Pick<TData,
|
|
90
|
+
}>(options: Pick<TData, "url"> & Options<TData>) => string;
|
|
91
91
|
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
|
|
92
92
|
interceptors: Middleware<Request, Response, unknown, RequestOptions>;
|
|
93
93
|
};
|
|
@@ -108,12 +108,12 @@ export interface TDataShape {
|
|
|
108
108
|
url: string;
|
|
109
109
|
}
|
|
110
110
|
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
111
|
-
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle =
|
|
112
|
-
export type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle =
|
|
111
|
+
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = "fields"> = OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, "body" | "path" | "query" | "url"> & Omit<TData, "url">;
|
|
112
|
+
export type OptionsLegacyParser<TData = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = "fields"> = TData extends {
|
|
113
113
|
body?: any;
|
|
114
114
|
} ? TData extends {
|
|
115
115
|
headers?: any;
|
|
116
|
-
} ? OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>,
|
|
116
|
+
} ? OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, "body" | "headers" | "url"> & TData : OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, "body" | "url"> & TData & Pick<RequestOptions<TResponseStyle, ThrowOnError>, "headers"> : TData extends {
|
|
117
117
|
headers?: any;
|
|
118
|
-
} ? OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>,
|
|
118
|
+
} ? OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, "headers" | "url"> & TData & Pick<RequestOptions<TResponseStyle, ThrowOnError>, "body"> : OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, "url"> & TData;
|
|
119
119
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { QuerySerializer, QuerySerializerOptions } from
|
|
2
|
-
import type { Client, ClientOptions, Config, RequestOptions } from
|
|
3
|
-
export declare const createQuerySerializer: <T = unknown>({ allowReserved, array, object
|
|
1
|
+
import type { QuerySerializer, QuerySerializerOptions } from "../core/bodySerializer";
|
|
2
|
+
import type { Client, ClientOptions, Config, RequestOptions } from "./types";
|
|
3
|
+
export declare const createQuerySerializer: <T = unknown>({ allowReserved, array, object }?: QuerySerializerOptions) => (queryParams: T) => string;
|
|
4
4
|
/**
|
|
5
5
|
* Infers parseAs value from provided Content-Type header.
|
|
6
6
|
*/
|
|
@@ -8,7 +8,7 @@ export declare const getParseAs: (contentType: string | null) => Exclude<Config[
|
|
|
8
8
|
export declare const setAuthParams: ({ security, ...options }: Pick<Required<RequestOptions>, "security"> & Pick<RequestOptions, "auth" | "query"> & {
|
|
9
9
|
headers: Headers;
|
|
10
10
|
}) => Promise<void>;
|
|
11
|
-
export declare const buildUrl: Client[
|
|
11
|
+
export declare const buildUrl: Client["buildUrl"];
|
|
12
12
|
export declare const getUrl: ({ baseUrl, path, query, querySerializer, url: _url, }: {
|
|
13
13
|
baseUrl?: string;
|
|
14
14
|
path?: Record<string, unknown>;
|
|
@@ -32,9 +32,9 @@ declare class Interceptors<Interceptor> {
|
|
|
32
32
|
use(fn: Interceptor): number;
|
|
33
33
|
}
|
|
34
34
|
export interface Middleware<Req, Res, Err, Options> {
|
|
35
|
-
error: Pick<Interceptors<ErrInterceptor<Err, Res, Req, Options>>,
|
|
36
|
-
request: Pick<Interceptors<ReqInterceptor<Req, Options>>,
|
|
37
|
-
response: Pick<Interceptors<ResInterceptor<Res, Req, Options>>,
|
|
35
|
+
error: Pick<Interceptors<ErrInterceptor<Err, Res, Req, Options>>, "eject" | "use">;
|
|
36
|
+
request: Pick<Interceptors<ReqInterceptor<Req, Options>>, "eject" | "use">;
|
|
37
|
+
response: Pick<Interceptors<ResInterceptor<Res, Req, Options>>, "eject" | "use">;
|
|
38
38
|
}
|
|
39
39
|
export declare const createInterceptors: <Req, Res, Err, Options>() => {
|
|
40
40
|
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
package/dist/gen/client/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getAuthToken } from
|
|
2
|
-
import { jsonBodySerializer } from
|
|
3
|
-
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam
|
|
1
|
+
import { getAuthToken } from "../core/auth";
|
|
2
|
+
import { jsonBodySerializer } from "../core/bodySerializer";
|
|
3
|
+
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer";
|
|
4
4
|
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
5
5
|
const defaultPathSerializer = ({ path, url: _url }) => {
|
|
6
6
|
let url = _url;
|
|
@@ -9,18 +9,18 @@ const defaultPathSerializer = ({ path, url: _url }) => {
|
|
|
9
9
|
for (const match of matches) {
|
|
10
10
|
let explode = false;
|
|
11
11
|
let name = match.substring(1, match.length - 1);
|
|
12
|
-
let style =
|
|
13
|
-
if (name.endsWith(
|
|
12
|
+
let style = "simple";
|
|
13
|
+
if (name.endsWith("*")) {
|
|
14
14
|
explode = true;
|
|
15
15
|
name = name.substring(0, name.length - 1);
|
|
16
16
|
}
|
|
17
|
-
if (name.startsWith(
|
|
17
|
+
if (name.startsWith(".")) {
|
|
18
18
|
name = name.substring(1);
|
|
19
|
-
style =
|
|
19
|
+
style = "label";
|
|
20
20
|
}
|
|
21
|
-
else if (name.startsWith(
|
|
21
|
+
else if (name.startsWith(";")) {
|
|
22
22
|
name = name.substring(1);
|
|
23
|
-
style =
|
|
23
|
+
style = "matrix";
|
|
24
24
|
}
|
|
25
25
|
const value = path[name];
|
|
26
26
|
if (value === undefined || value === null) {
|
|
@@ -30,7 +30,7 @@ const defaultPathSerializer = ({ path, url: _url }) => {
|
|
|
30
30
|
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
|
-
if (typeof value ===
|
|
33
|
+
if (typeof value === "object") {
|
|
34
34
|
url = url.replace(match, serializeObjectParam({
|
|
35
35
|
explode,
|
|
36
36
|
name,
|
|
@@ -40,23 +40,23 @@ const defaultPathSerializer = ({ path, url: _url }) => {
|
|
|
40
40
|
}));
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
|
-
if (style ===
|
|
43
|
+
if (style === "matrix") {
|
|
44
44
|
url = url.replace(match, `;${serializePrimitiveParam({
|
|
45
45
|
name,
|
|
46
46
|
value: value,
|
|
47
47
|
})}`);
|
|
48
48
|
continue;
|
|
49
49
|
}
|
|
50
|
-
const replaceValue = encodeURIComponent(style ===
|
|
50
|
+
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
51
51
|
url = url.replace(match, replaceValue);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
return url;
|
|
55
55
|
};
|
|
56
|
-
export const createQuerySerializer = ({ allowReserved, array, object
|
|
56
|
+
export const createQuerySerializer = ({ allowReserved, array, object } = {}) => {
|
|
57
57
|
const querySerializer = (queryParams) => {
|
|
58
58
|
const search = [];
|
|
59
|
-
if (queryParams && typeof queryParams ===
|
|
59
|
+
if (queryParams && typeof queryParams === "object") {
|
|
60
60
|
for (const name in queryParams) {
|
|
61
61
|
const value = queryParams[name];
|
|
62
62
|
if (value === undefined || value === null) {
|
|
@@ -67,19 +67,19 @@ export const createQuerySerializer = ({ allowReserved, array, object, } = {}) =>
|
|
|
67
67
|
allowReserved,
|
|
68
68
|
explode: true,
|
|
69
69
|
name,
|
|
70
|
-
style:
|
|
70
|
+
style: "form",
|
|
71
71
|
value,
|
|
72
72
|
...array,
|
|
73
73
|
});
|
|
74
74
|
if (serializedArray)
|
|
75
75
|
search.push(serializedArray);
|
|
76
76
|
}
|
|
77
|
-
else if (typeof value ===
|
|
77
|
+
else if (typeof value === "object") {
|
|
78
78
|
const serializedObject = serializeObjectParam({
|
|
79
79
|
allowReserved,
|
|
80
80
|
explode: true,
|
|
81
81
|
name,
|
|
82
|
-
style:
|
|
82
|
+
style: "deepObject",
|
|
83
83
|
value: value,
|
|
84
84
|
...object,
|
|
85
85
|
});
|
|
@@ -97,7 +97,7 @@ export const createQuerySerializer = ({ allowReserved, array, object, } = {}) =>
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
return search.join(
|
|
100
|
+
return search.join("&");
|
|
101
101
|
};
|
|
102
102
|
return querySerializer;
|
|
103
103
|
};
|
|
@@ -108,24 +108,23 @@ export const getParseAs = (contentType) => {
|
|
|
108
108
|
if (!contentType) {
|
|
109
109
|
// If no Content-Type header is provided, the best we can do is return the raw response body,
|
|
110
110
|
// which is effectively the same as the 'stream' option.
|
|
111
|
-
return
|
|
111
|
+
return "stream";
|
|
112
112
|
}
|
|
113
|
-
const cleanContent = contentType.split(
|
|
113
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
114
114
|
if (!cleanContent) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
|
-
if (cleanContent.startsWith(
|
|
118
|
-
|
|
119
|
-
return 'json';
|
|
117
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
118
|
+
return "json";
|
|
120
119
|
}
|
|
121
|
-
if (cleanContent ===
|
|
122
|
-
return
|
|
120
|
+
if (cleanContent === "multipart/form-data") {
|
|
121
|
+
return "formData";
|
|
123
122
|
}
|
|
124
|
-
if ([
|
|
125
|
-
return
|
|
123
|
+
if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
|
|
124
|
+
return "blob";
|
|
126
125
|
}
|
|
127
|
-
if (cleanContent.startsWith(
|
|
128
|
-
return
|
|
126
|
+
if (cleanContent.startsWith("text/")) {
|
|
127
|
+
return "text";
|
|
129
128
|
}
|
|
130
129
|
return;
|
|
131
130
|
};
|
|
@@ -135,18 +134,18 @@ export const setAuthParams = async ({ security, ...options }) => {
|
|
|
135
134
|
if (!token) {
|
|
136
135
|
continue;
|
|
137
136
|
}
|
|
138
|
-
const name = auth.name ??
|
|
137
|
+
const name = auth.name ?? "Authorization";
|
|
139
138
|
switch (auth.in) {
|
|
140
|
-
case
|
|
139
|
+
case "query":
|
|
141
140
|
if (!options.query) {
|
|
142
141
|
options.query = {};
|
|
143
142
|
}
|
|
144
143
|
options.query[name] = token;
|
|
145
144
|
break;
|
|
146
|
-
case
|
|
147
|
-
options.headers.append(
|
|
145
|
+
case "cookie":
|
|
146
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
148
147
|
break;
|
|
149
|
-
case
|
|
148
|
+
case "header":
|
|
150
149
|
default:
|
|
151
150
|
options.headers.set(name, token);
|
|
152
151
|
break;
|
|
@@ -159,7 +158,7 @@ export const buildUrl = (options) => {
|
|
|
159
158
|
baseUrl: options.baseUrl,
|
|
160
159
|
path: options.path,
|
|
161
160
|
query: options.query,
|
|
162
|
-
querySerializer: typeof options.querySerializer ===
|
|
161
|
+
querySerializer: typeof options.querySerializer === "function"
|
|
163
162
|
? options.querySerializer
|
|
164
163
|
: createQuerySerializer(options.querySerializer),
|
|
165
164
|
url: options.url,
|
|
@@ -167,13 +166,13 @@ export const buildUrl = (options) => {
|
|
|
167
166
|
return url;
|
|
168
167
|
};
|
|
169
168
|
export const getUrl = ({ baseUrl, path, query, querySerializer, url: _url, }) => {
|
|
170
|
-
const pathUrl = _url.startsWith(
|
|
171
|
-
let url = (baseUrl ??
|
|
169
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
170
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
172
171
|
if (path) {
|
|
173
172
|
url = defaultPathSerializer({ path, url });
|
|
174
173
|
}
|
|
175
|
-
let search = query ? querySerializer(query) :
|
|
176
|
-
if (search.startsWith(
|
|
174
|
+
let search = query ? querySerializer(query) : "";
|
|
175
|
+
if (search.startsWith("?")) {
|
|
177
176
|
search = search.substring(1);
|
|
178
177
|
}
|
|
179
178
|
if (search) {
|
|
@@ -183,7 +182,7 @@ export const getUrl = ({ baseUrl, path, query, querySerializer, url: _url, }) =>
|
|
|
183
182
|
};
|
|
184
183
|
export const mergeConfigs = (a, b) => {
|
|
185
184
|
const config = { ...a, ...b };
|
|
186
|
-
if (config.baseUrl?.endsWith(
|
|
185
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
187
186
|
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
188
187
|
}
|
|
189
188
|
config.headers = mergeHeaders(a.headers, b.headers);
|
|
@@ -192,7 +191,7 @@ export const mergeConfigs = (a, b) => {
|
|
|
192
191
|
export const mergeHeaders = (...headers) => {
|
|
193
192
|
const mergedHeaders = new Headers();
|
|
194
193
|
for (const header of headers) {
|
|
195
|
-
if (!header || typeof header !==
|
|
194
|
+
if (!header || typeof header !== "object") {
|
|
196
195
|
continue;
|
|
197
196
|
}
|
|
198
197
|
const iterator = header instanceof Headers ? header.entries() : Object.entries(header);
|
|
@@ -208,7 +207,7 @@ export const mergeHeaders = (...headers) => {
|
|
|
208
207
|
else if (value !== undefined) {
|
|
209
208
|
// assume object headers are meant to be JSON stringified, i.e. their
|
|
210
209
|
// content value in OpenAPI specification is 'application/json'
|
|
211
|
-
mergedHeaders.set(key, typeof value ===
|
|
210
|
+
mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
213
|
}
|
|
@@ -223,7 +222,7 @@ class Interceptors {
|
|
|
223
222
|
this._fns = [];
|
|
224
223
|
}
|
|
225
224
|
getInterceptorIndex(id) {
|
|
226
|
-
if (typeof id ===
|
|
225
|
+
if (typeof id === "number") {
|
|
227
226
|
return this._fns[id] ? id : -1;
|
|
228
227
|
}
|
|
229
228
|
else {
|
|
@@ -265,20 +264,20 @@ const defaultQuerySerializer = createQuerySerializer({
|
|
|
265
264
|
allowReserved: false,
|
|
266
265
|
array: {
|
|
267
266
|
explode: true,
|
|
268
|
-
style:
|
|
267
|
+
style: "form",
|
|
269
268
|
},
|
|
270
269
|
object: {
|
|
271
270
|
explode: true,
|
|
272
|
-
style:
|
|
271
|
+
style: "deepObject",
|
|
273
272
|
},
|
|
274
273
|
});
|
|
275
274
|
const defaultHeaders = {
|
|
276
|
-
|
|
275
|
+
"Content-Type": "application/json",
|
|
277
276
|
};
|
|
278
277
|
export const createConfig = (override = {}) => ({
|
|
279
278
|
...jsonBodySerializer,
|
|
280
279
|
headers: defaultHeaders,
|
|
281
|
-
parseAs:
|
|
280
|
+
parseAs: "auto",
|
|
282
281
|
querySerializer: defaultQuerySerializer,
|
|
283
282
|
...override,
|
|
284
283
|
});
|
package/dist/gen/client.gen.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ClientOptions } from
|
|
2
|
-
import { type Config, type ClientOptions as DefaultClientOptions } from
|
|
1
|
+
import type { ClientOptions } from "./types.gen";
|
|
2
|
+
import { type Config, type ClientOptions as DefaultClientOptions } from "./client";
|
|
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.
|
package/dist/gen/client.gen.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
import { createClient, createConfig } from
|
|
2
|
+
import { createClient, createConfig } from "./client";
|
|
3
3
|
export const client = createClient(createConfig({
|
|
4
|
-
baseUrl:
|
|
4
|
+
baseUrl: "http://localhost:4096",
|
|
5
5
|
}));
|
package/dist/gen/core/auth.d.ts
CHANGED
|
@@ -5,14 +5,14 @@ export interface Auth {
|
|
|
5
5
|
*
|
|
6
6
|
* @default 'header'
|
|
7
7
|
*/
|
|
8
|
-
in?:
|
|
8
|
+
in?: "header" | "query" | "cookie";
|
|
9
9
|
/**
|
|
10
10
|
* Header or query parameter name.
|
|
11
11
|
*
|
|
12
12
|
* @default 'Authorization'
|
|
13
13
|
*/
|
|
14
14
|
name?: string;
|
|
15
|
-
scheme?:
|
|
16
|
-
type:
|
|
15
|
+
scheme?: "basic" | "bearer";
|
|
16
|
+
type: "apiKey" | "http";
|
|
17
17
|
}
|
|
18
18
|
export declare const getAuthToken: (auth: Auth, callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken) => Promise<string | undefined>;
|
package/dist/gen/core/auth.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export const getAuthToken = async (auth, callback) => {
|
|
2
|
-
const token = typeof callback ===
|
|
2
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
3
3
|
if (!token) {
|
|
4
4
|
return;
|
|
5
5
|
}
|
|
6
|
-
if (auth.scheme ===
|
|
6
|
+
if (auth.scheme === "bearer") {
|
|
7
7
|
return `Bearer ${token}`;
|
|
8
8
|
}
|
|
9
|
-
if (auth.scheme ===
|
|
9
|
+
if (auth.scheme === "basic") {
|
|
10
10
|
return `Basic ${btoa(token)}`;
|
|
11
11
|
}
|
|
12
12
|
return token;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ArrayStyle, ObjectStyle, SerializerOptions } from
|
|
1
|
+
import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer";
|
|
2
2
|
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
3
3
|
export type BodySerializer = (body: any) => any;
|
|
4
4
|
export interface QuerySerializerOptions {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const serializeFormDataPair = (data, key, value) => {
|
|
2
|
-
if (typeof value ===
|
|
2
|
+
if (typeof value === "string" || value instanceof Blob) {
|
|
3
3
|
data.append(key, value);
|
|
4
4
|
}
|
|
5
5
|
else {
|
|
@@ -7,7 +7,7 @@ const serializeFormDataPair = (data, key, value) => {
|
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
9
|
const serializeUrlSearchParamsPair = (data, key, value) => {
|
|
10
|
-
if (typeof value ===
|
|
10
|
+
if (typeof value === "string") {
|
|
11
11
|
data.append(key, value);
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
@@ -32,7 +32,7 @@ export const formDataBodySerializer = {
|
|
|
32
32
|
},
|
|
33
33
|
};
|
|
34
34
|
export const jsonBodySerializer = {
|
|
35
|
-
bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value ===
|
|
35
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value) => (typeof value === "bigint" ? value.toString() : value)),
|
|
36
36
|
};
|
|
37
37
|
export const urlSearchParamsBodySerializer = {
|
|
38
38
|
bodySerializer: (body) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
type Slot =
|
|
1
|
+
type Slot = "body" | "headers" | "path" | "query";
|
|
2
2
|
export type Field = {
|
|
3
|
-
in: Exclude<Slot,
|
|
3
|
+
in: Exclude<Slot, "body">;
|
|
4
4
|
/**
|
|
5
5
|
* Field name. This is the name we want the user to see and use.
|
|
6
6
|
*/
|
|
@@ -11,7 +11,7 @@ export type Field = {
|
|
|
11
11
|
*/
|
|
12
12
|
map?: string;
|
|
13
13
|
} | {
|
|
14
|
-
in: Extract<Slot,
|
|
14
|
+
in: Extract<Slot, "body">;
|
|
15
15
|
/**
|
|
16
16
|
* Key isn't required for bodies.
|
|
17
17
|
*/
|