+3
-3
packages/config-vite-base/package.json
+3
-3
packages/config-vite-base/package.json
···
2
2
"name": "@config/vite-base",
3
3
"version": "0.0.1",
4
4
"description": "Base configuration for Vite and Vitest",
5
-
"main": "dist/index.js",
6
-
"module": "dist/index.js",
7
-
"types": "dist/index.d.ts",
5
+
"main": "dist/index.mjs",
6
+
"module": "dist/index.mjs",
7
+
"types": "dist/index.d.mts",
8
8
"license": "MIT",
9
9
"type": "module",
10
10
"scripts": {
+271
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/client-custom/bundle/client/index.d.mts
+271
packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/clients/client-custom/bundle/client/index.d.mts
···
1
+
//#region src/core/auth.d.ts
2
+
type AuthToken = string | undefined;
3
+
interface Auth {
4
+
/**
5
+
* Which part of the request do we use to send the auth?
6
+
*
7
+
* @default 'header'
8
+
*/
9
+
in?: 'header' | 'query' | 'cookie';
10
+
/**
11
+
* Header or query parameter name.
12
+
*
13
+
* @default 'Authorization'
14
+
*/
15
+
name?: string;
16
+
scheme?: 'basic' | 'bearer';
17
+
type: 'apiKey' | 'http';
18
+
}
19
+
//#endregion
20
+
//#region src/core/pathSerializer.d.ts
21
+
interface SerializerOptions<T> {
22
+
/**
23
+
* @default true
24
+
*/
25
+
explode: boolean;
26
+
style: T;
27
+
}
28
+
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
29
+
type ObjectStyle = 'form' | 'deepObject';
30
+
//#endregion
31
+
//#region src/core/bodySerializer.d.ts
32
+
type QuerySerializer = (query: Record<string, unknown>) => string;
33
+
type BodySerializer = (body: any) => any;
34
+
type QuerySerializerOptionsObject = {
35
+
allowReserved?: boolean;
36
+
array?: Partial<SerializerOptions<ArrayStyle>>;
37
+
object?: Partial<SerializerOptions<ObjectStyle>>;
38
+
};
39
+
type QuerySerializerOptions = QuerySerializerOptionsObject & {
40
+
/**
41
+
* Per-parameter serialization overrides. When provided, these settings
42
+
* override the global array/object settings for specific parameter names.
43
+
*/
44
+
parameters?: Record<string, QuerySerializerOptionsObject>;
45
+
};
46
+
declare const formDataBodySerializer: {
47
+
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => FormData;
48
+
};
49
+
declare const jsonBodySerializer: {
50
+
bodySerializer: <T>(body: T) => string;
51
+
};
52
+
declare const urlSearchParamsBodySerializer: {
53
+
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T) => string;
54
+
};
55
+
//#endregion
56
+
//#region src/core/types.d.ts
57
+
interface Client$1<RequestFn$1 = never, Config$2 = unknown, MethodFn$1 = never, BuildUrlFn$1 = never> {
58
+
/**
59
+
* Returns the final request URL.
60
+
*/
61
+
buildUrl: BuildUrlFn$1;
62
+
connect: MethodFn$1;
63
+
delete: MethodFn$1;
64
+
get: MethodFn$1;
65
+
getConfig: () => Config$2;
66
+
head: MethodFn$1;
67
+
options: MethodFn$1;
68
+
patch: MethodFn$1;
69
+
post: MethodFn$1;
70
+
put: MethodFn$1;
71
+
request: RequestFn$1;
72
+
setConfig: (config: Config$2) => Config$2;
73
+
trace: MethodFn$1;
74
+
}
75
+
interface Config$1 {
76
+
/**
77
+
* Auth token or a function returning auth token. The resolved value will be
78
+
* added to the request payload as defined by its `security` array.
79
+
*/
80
+
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
81
+
/**
82
+
* A function for serializing request body parameter. By default,
83
+
* {@link JSON.stringify()} will be used.
84
+
*/
85
+
bodySerializer?: BodySerializer | null;
86
+
/**
87
+
* An object containing any HTTP headers that you want to pre-populate your
88
+
* `Headers` object with.
89
+
*
90
+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
91
+
*/
92
+
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
93
+
/**
94
+
* The request method.
95
+
*
96
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
97
+
*/
98
+
method?: 'CONNECT' | 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT' | 'TRACE';
99
+
/**
100
+
* A function for serializing request query parameters. By default, arrays
101
+
* will be exploded in form style, objects will be exploded in deepObject
102
+
* style, and reserved characters are percent-encoded.
103
+
*
104
+
* This method will have no effect if the native `paramsSerializer()` Axios
105
+
* API function is used.
106
+
*
107
+
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
108
+
*/
109
+
querySerializer?: QuerySerializer | QuerySerializerOptions;
110
+
/**
111
+
* A function validating request data. This is useful if you want to ensure
112
+
* the request conforms to the desired shape, so it can be safely sent to
113
+
* the server.
114
+
*/
115
+
requestValidator?: (data: unknown) => Promise<unknown>;
116
+
/**
117
+
* A function transforming response data before it's returned. This is useful
118
+
* for post-processing data, e.g. converting ISO strings into Date objects.
119
+
*/
120
+
responseTransformer?: (data: unknown) => Promise<unknown>;
121
+
/**
122
+
* A function validating response data. This is useful if you want to ensure
123
+
* the response conforms to the desired shape, so it can be safely passed to
124
+
* the transformers and returned to the user.
125
+
*/
126
+
responseValidator?: (data: unknown) => Promise<unknown>;
127
+
}
128
+
//#endregion
129
+
//#region src/utils.d.ts
130
+
type ErrInterceptor<Err, Res, Req, Options$1> = (error: Err, response: Res, request: Req, options: Options$1) => Err | Promise<Err>;
131
+
type ReqInterceptor<Req, Options$1> = (request: Req, options: Options$1) => Req | Promise<Req>;
132
+
type ResInterceptor<Res, Req, Options$1> = (response: Res, request: Req, options: Options$1) => Res | Promise<Res>;
133
+
declare class Interceptors<Interceptor> {
134
+
fns: Array<Interceptor | null>;
135
+
clear(): void;
136
+
eject(id: number | Interceptor): void;
137
+
exists(id: number | Interceptor): boolean;
138
+
getInterceptorIndex(id: number | Interceptor): number;
139
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
140
+
use(fn: Interceptor): number;
141
+
}
142
+
interface Middleware<Req, Res, Err, Options$1> {
143
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options$1>>;
144
+
request: Interceptors<ReqInterceptor<Req, Options$1>>;
145
+
response: Interceptors<ResInterceptor<Res, Req, Options$1>>;
146
+
}
147
+
declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
148
+
//#endregion
149
+
//#region src/types.d.ts
150
+
interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 {
151
+
/**
152
+
* Base URL for all requests made by this client.
153
+
*/
154
+
baseUrl?: T['baseUrl'];
155
+
/**
156
+
* Fetch API implementation. You can use this option to provide a custom
157
+
* fetch instance.
158
+
*
159
+
* @default globalThis.fetch
160
+
*/
161
+
fetch?: (request: Request) => ReturnType<typeof fetch>;
162
+
/**
163
+
* Return the response data parsed in a specified format. By default, `auto`
164
+
* will infer the appropriate method from the `Content-Type` response header.
165
+
* You can override this behavior with any of the {@link Body} methods.
166
+
* Select `stream` if you don't want to parse response data at all.
167
+
*
168
+
* @default 'auto'
169
+
*/
170
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
171
+
/**
172
+
* Throw an error instead of returning it in the response?
173
+
*
174
+
* @default false
175
+
*/
176
+
throwOnError?: T['throwOnError'];
177
+
}
178
+
interface RequestOptions<ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
179
+
throwOnError: ThrowOnError;
180
+
}> {
181
+
/**
182
+
* Any body that you want to add to your request.
183
+
*
184
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
185
+
*/
186
+
body?: unknown;
187
+
path?: Record<string, unknown>;
188
+
query?: Record<string, unknown>;
189
+
/**
190
+
* Security mechanism(s) to use for the request.
191
+
*/
192
+
security?: ReadonlyArray<Auth>;
193
+
url: Url;
194
+
}
195
+
type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<{
196
+
data: TData;
197
+
request: Request;
198
+
response: Response;
199
+
}> : Promise<({
200
+
data: TData;
201
+
error: undefined;
202
+
} | {
203
+
data: undefined;
204
+
error: TError;
205
+
}) & {
206
+
request: Request;
207
+
response: Response;
208
+
}>;
209
+
interface ClientOptions {
210
+
baseUrl?: string;
211
+
throwOnError?: boolean;
212
+
}
213
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
214
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<ThrowOnError>, 'method'> & Pick<Required<RequestOptions<ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
215
+
type BuildUrlFn = <TData extends {
216
+
body?: unknown;
217
+
path?: Record<string, unknown>;
218
+
query?: Record<string, unknown>;
219
+
url: string;
220
+
}>(options: Pick<TData, 'url'> & Options<TData>) => string;
221
+
type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn> & {
222
+
interceptors: Middleware<Request, Response, unknown, RequestOptions>;
223
+
};
224
+
/**
225
+
* The `createClientConfig()` function will be called on client initialization
226
+
* and the returned object will become the client's initial configuration.
227
+
*
228
+
* You may want to initialize your client this way instead of calling
229
+
* `setConfig()`. This is useful for example if you're using Next.js
230
+
* to ensure your client always has the correct values.
231
+
*/
232
+
type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
233
+
interface TDataShape {
234
+
body?: unknown;
235
+
headers?: unknown;
236
+
path?: unknown;
237
+
query?: unknown;
238
+
url: string;
239
+
}
240
+
type OmitKeys<T, K$1> = Pick<T, Exclude<keyof T, K$1>>;
241
+
type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = OmitKeys<RequestOptions<ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & Omit<TData, 'url'>;
242
+
//#endregion
243
+
//#region src/client.d.ts
244
+
declare const createClient: (config?: Config) => Client;
245
+
//#endregion
246
+
//#region src/core/params.d.ts
247
+
type Slot = 'body' | 'headers' | 'path' | 'query';
248
+
type Field = {
249
+
in: Exclude<Slot, 'body'>;
250
+
key: string;
251
+
map?: string;
252
+
} | {
253
+
in: Extract<Slot, 'body'>;
254
+
key?: string;
255
+
map?: string;
256
+
};
257
+
interface Fields {
258
+
allowExtra?: Partial<Record<Slot, boolean>>;
259
+
args?: ReadonlyArray<Field>;
260
+
}
261
+
type FieldsConfig = ReadonlyArray<Field | Fields>;
262
+
interface Params {
263
+
body: unknown;
264
+
headers: Record<string, unknown>;
265
+
path: Record<string, unknown>;
266
+
query: Record<string, unknown>;
267
+
}
268
+
declare const buildClientParams: (args: ReadonlyArray<unknown>, fields: FieldsConfig) => Params;
269
+
//# sourceMappingURL=index.d.mts.map
270
+
271
+
export { type Auth, type Client, type ClientOptions, type Config, type CreateClientConfig, type Options, type QuerySerializerOptions, type RequestOptions, type RequestResult, type TDataShape, buildClientParams, createClient, createConfig, formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer };
+1
-1
packages/openapi-ts/src/generate/client.ts
+1
-1
packages/openapi-ts/src/generate/client.ts
···
213
213
214
214
const indexJsFile =
215
215
clientModulePathComponents[clientModulePathComponents.length - 1];
216
-
const distFiles = [indexJsFile!, 'index.d.ts', 'index.d.cts'];
216
+
const distFiles = [indexJsFile!, 'index.d.mts', 'index.d.cts'];
217
217
const dirPath = path.resolve(outputPath, 'client');
218
218
ensureDirSync(dirPath);
219
219
for (const file of distFiles) {