better-call 1.3.3 → 2.0.0-beta.2
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.cjs.map +1 -1
- package/dist/client.d.cts +13 -17
- package/dist/client.d.mts +13 -17
- package/dist/client.mjs.map +1 -1
- package/dist/context.cjs +10 -9
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +129 -323
- package/dist/context.d.mts +129 -323
- package/dist/context.mjs +10 -9
- package/dist/context.mjs.map +1 -1
- package/dist/cookies.cjs +1 -1
- package/dist/cookies.d.cts +1 -12
- package/dist/cookies.d.mts +1 -12
- package/dist/cookies.mjs +1 -1
- package/dist/crypto.cjs.map +1 -1
- package/dist/crypto.mjs.map +1 -1
- package/dist/endpoint.cjs +21 -7
- package/dist/endpoint.cjs.map +1 -1
- package/dist/endpoint.d.cts +197 -392
- package/dist/endpoint.d.mts +197 -392
- package/dist/endpoint.mjs +21 -7
- package/dist/endpoint.mjs.map +1 -1
- package/dist/error.cjs +1 -1
- package/dist/error.cjs.map +1 -1
- package/dist/error.mjs +1 -1
- package/dist/error.mjs.map +1 -1
- package/dist/helper.d.cts +2 -3
- package/dist/helper.d.mts +2 -3
- package/dist/index.cjs +3 -10
- package/dist/index.d.cts +9 -8
- package/dist/index.d.mts +9 -8
- package/dist/index.mjs +3 -4
- package/dist/middleware.cjs +59 -13
- package/dist/middleware.cjs.map +1 -1
- package/dist/middleware.d.cts +85 -42
- package/dist/middleware.d.mts +85 -42
- package/dist/middleware.mjs +59 -13
- package/dist/middleware.mjs.map +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.mjs.map +1 -1
- package/dist/openapi.cjs.map +1 -1
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.mjs.map +1 -1
- package/dist/router.cjs.map +1 -1
- package/dist/router.mjs.map +1 -1
- package/dist/to-response.cjs +1 -1
- package/dist/to-response.cjs.map +1 -1
- package/dist/to-response.mjs +1 -1
- package/dist/to-response.mjs.map +1 -1
- package/dist/types.d.cts +142 -0
- package/dist/types.d.mts +142 -0
- package/dist/validator.cjs +1 -1
- package/dist/validator.cjs.map +1 -1
- package/dist/validator.mjs +1 -1
- package/dist/validator.mjs.map +1 -1
- package/package.json +3 -3
package/dist/endpoint.d.cts
CHANGED
|
@@ -1,53 +1,38 @@
|
|
|
1
|
-
import { Prettify } from "./helper.cjs";
|
|
2
1
|
import { StandardSchemaV1 } from "./standard-schema.cjs";
|
|
3
|
-
import { APIError
|
|
4
|
-
import {
|
|
5
|
-
import { InferBody, InferHeaders, InferMethod, InferParam, InferQuery, InferRequest, InferUse, InputContext } from "./context.cjs";
|
|
2
|
+
import { APIError } from "./error.cjs";
|
|
3
|
+
import { BodyOption, HTTPMethod, InferUse, InputContext, ResolveBodyInput, ResolveErrorInput, ResolveQueryInput } from "./types.cjs";
|
|
6
4
|
import { Middleware } from "./middleware.cjs";
|
|
5
|
+
import { EndpointContext } from "./context.cjs";
|
|
7
6
|
import { OpenAPIParameter, OpenAPISchemaType } from "./openapi.cjs";
|
|
8
7
|
|
|
9
8
|
//#region src/endpoint.d.ts
|
|
10
|
-
interface
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*/
|
|
38
|
-
metadata?: {
|
|
39
|
-
/**
|
|
40
|
-
* Open API definition
|
|
41
|
-
*/
|
|
42
|
-
openapi?: {
|
|
43
|
-
summary?: string;
|
|
44
|
-
description?: string;
|
|
45
|
-
tags?: string[];
|
|
46
|
-
operationId?: string;
|
|
47
|
-
parameters?: OpenAPIParameter[];
|
|
48
|
-
requestBody?: {
|
|
49
|
-
content: {
|
|
50
|
-
"application/json": {
|
|
9
|
+
interface EndpointMetadata {
|
|
10
|
+
/**
|
|
11
|
+
* Open API definition
|
|
12
|
+
*/
|
|
13
|
+
openapi?: {
|
|
14
|
+
summary?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
tags?: string[];
|
|
17
|
+
operationId?: string;
|
|
18
|
+
parameters?: OpenAPIParameter[];
|
|
19
|
+
requestBody?: {
|
|
20
|
+
content: {
|
|
21
|
+
"application/json": {
|
|
22
|
+
schema: {
|
|
23
|
+
type?: OpenAPISchemaType;
|
|
24
|
+
properties?: Record<string, any>;
|
|
25
|
+
required?: string[];
|
|
26
|
+
$ref?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
responses?: {
|
|
32
|
+
[status: string]: {
|
|
33
|
+
description: string;
|
|
34
|
+
content?: {
|
|
35
|
+
"application/json"?: {
|
|
51
36
|
schema: {
|
|
52
37
|
type?: OpenAPISchemaType;
|
|
53
38
|
properties?: Record<string, any>;
|
|
@@ -55,376 +40,156 @@ interface EndpointBaseOptions {
|
|
|
55
40
|
$ref?: string;
|
|
56
41
|
};
|
|
57
42
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"application/json"?: {
|
|
65
|
-
schema: {
|
|
66
|
-
type?: OpenAPISchemaType;
|
|
67
|
-
properties?: Record<string, any>;
|
|
68
|
-
required?: string[];
|
|
69
|
-
$ref?: string;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
"text/plain"?: {
|
|
73
|
-
schema?: {
|
|
74
|
-
type?: OpenAPISchemaType;
|
|
75
|
-
properties?: Record<string, any>;
|
|
76
|
-
required?: string[];
|
|
77
|
-
$ref?: string;
|
|
78
|
-
};
|
|
43
|
+
"text/plain"?: {
|
|
44
|
+
schema?: {
|
|
45
|
+
type?: OpenAPISchemaType;
|
|
46
|
+
properties?: Record<string, any>;
|
|
47
|
+
required?: string[];
|
|
48
|
+
$ref?: string;
|
|
79
49
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
50
|
+
};
|
|
51
|
+
"text/html"?: {
|
|
52
|
+
schema?: {
|
|
53
|
+
type?: OpenAPISchemaType;
|
|
54
|
+
properties?: Record<string, any>;
|
|
55
|
+
required?: string[];
|
|
56
|
+
$ref?: string;
|
|
87
57
|
};
|
|
88
58
|
};
|
|
89
59
|
};
|
|
90
60
|
};
|
|
91
61
|
};
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Infer body and query type from ts interface
|
|
65
|
+
*
|
|
66
|
+
* useful for generic and dynamic types
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const endpoint = createEndpoint("/path", {
|
|
71
|
+
* method: "POST",
|
|
72
|
+
* body: z.record(z.string()),
|
|
73
|
+
* $Infer: {
|
|
74
|
+
* body: {} as {
|
|
75
|
+
* type: InferTypeFromOptions<Option> // custom type inference
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* }, async(ctx)=>{
|
|
79
|
+
* const body = ctx.body
|
|
80
|
+
* })
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
$Infer?: {
|
|
92
84
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* useful for generic and dynamic types
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* const endpoint = createEndpoint("/path", {
|
|
100
|
-
* method: "POST",
|
|
101
|
-
* body: z.record(z.string()),
|
|
102
|
-
* $Infer: {
|
|
103
|
-
* body: {} as {
|
|
104
|
-
* type: InferTypeFromOptions<Option> // custom type inference
|
|
105
|
-
* }
|
|
106
|
-
* }
|
|
107
|
-
* }, async(ctx)=>{
|
|
108
|
-
* const body = ctx.body
|
|
109
|
-
* })
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
$Infer?: {
|
|
113
|
-
/**
|
|
114
|
-
* Body
|
|
115
|
-
*/
|
|
116
|
-
body?: any;
|
|
117
|
-
/**
|
|
118
|
-
* Query
|
|
119
|
-
*/
|
|
120
|
-
query?: Record<string, any>;
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* If enabled, endpoint won't be exposed over a router
|
|
124
|
-
* @deprecated Use path-less endpoints instead
|
|
125
|
-
*/
|
|
126
|
-
SERVER_ONLY?: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* If enabled, endpoint won't be exposed as an action to the client
|
|
129
|
-
* @deprecated Use path-less endpoints instead
|
|
130
|
-
*/
|
|
131
|
-
isAction?: boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Defines the places where the endpoint will be available
|
|
134
|
-
*
|
|
135
|
-
* Possible options:
|
|
136
|
-
* - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
|
|
137
|
-
* - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
|
|
138
|
-
* - `http` - the endpoint is only exposed to the router
|
|
139
|
-
* @default "rpc"
|
|
85
|
+
* Body
|
|
140
86
|
*/
|
|
141
|
-
|
|
87
|
+
body?: any;
|
|
142
88
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* if provided, only the media types in the list will be allowed to be passed in the body
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* const endpoint = createEndpoint("/path", {
|
|
150
|
-
* method: "POST",
|
|
151
|
-
* allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
|
|
152
|
-
* }, async(ctx)=>{
|
|
153
|
-
* const body = ctx.body
|
|
154
|
-
* })
|
|
155
|
-
* ```
|
|
89
|
+
* Query
|
|
156
90
|
*/
|
|
157
|
-
|
|
91
|
+
query?: Record<string, any>;
|
|
158
92
|
/**
|
|
159
|
-
*
|
|
93
|
+
* Error
|
|
160
94
|
*/
|
|
161
|
-
|
|
95
|
+
error?: any;
|
|
162
96
|
};
|
|
163
97
|
/**
|
|
164
|
-
*
|
|
165
|
-
|
|
166
|
-
use?: Middleware[];
|
|
167
|
-
/**
|
|
168
|
-
* A callback to run before any API error is throw or returned
|
|
169
|
-
*
|
|
170
|
-
* @param e - The API error
|
|
171
|
-
* @returns - The response to return
|
|
172
|
-
*/
|
|
173
|
-
onAPIError?: (e: APIError) => void | Promise<void>;
|
|
174
|
-
/**
|
|
175
|
-
* A callback to run before a validation error is thrown
|
|
176
|
-
* You can customize the validation error message by throwing your own APIError
|
|
177
|
-
*/
|
|
178
|
-
onValidationError?: ({
|
|
179
|
-
issues,
|
|
180
|
-
message
|
|
181
|
-
}: {
|
|
182
|
-
message: string;
|
|
183
|
-
issues: readonly StandardSchemaV1.Issue[];
|
|
184
|
-
}) => void | Promise<void>;
|
|
185
|
-
}
|
|
186
|
-
type EndpointBodyMethodOptions = {
|
|
187
|
-
/**
|
|
188
|
-
* Request Method
|
|
189
|
-
*/
|
|
190
|
-
method: "POST" | "PUT" | "DELETE" | "PATCH" | ("POST" | "PUT" | "DELETE" | "PATCH")[];
|
|
191
|
-
/**
|
|
192
|
-
* Body Schema
|
|
98
|
+
* If enabled, endpoint won't be exposed over a router
|
|
99
|
+
* @deprecated Use path-less endpoints instead
|
|
193
100
|
*/
|
|
194
|
-
|
|
195
|
-
} | {
|
|
196
|
-
/**
|
|
197
|
-
* Request Method
|
|
198
|
-
*/
|
|
199
|
-
method: "GET" | "HEAD" | ("GET" | "HEAD")[];
|
|
200
|
-
/**
|
|
201
|
-
* Body Schema
|
|
202
|
-
*/
|
|
203
|
-
body?: never;
|
|
204
|
-
} | {
|
|
205
|
-
/**
|
|
206
|
-
* Request Method
|
|
207
|
-
*/
|
|
208
|
-
method: "*";
|
|
209
|
-
/**
|
|
210
|
-
* Body Schema
|
|
211
|
-
*/
|
|
212
|
-
body?: StandardSchemaV1;
|
|
213
|
-
} | {
|
|
101
|
+
SERVER_ONLY?: boolean;
|
|
214
102
|
/**
|
|
215
|
-
*
|
|
103
|
+
* If enabled, endpoint won't be exposed as an action to the client
|
|
104
|
+
* @deprecated Use path-less endpoints instead
|
|
216
105
|
*/
|
|
217
|
-
|
|
106
|
+
isAction?: boolean;
|
|
218
107
|
/**
|
|
219
|
-
*
|
|
220
|
-
*/
|
|
221
|
-
body?: StandardSchemaV1;
|
|
222
|
-
};
|
|
223
|
-
type EndpointOptions = EndpointBaseOptions & EndpointBodyMethodOptions;
|
|
224
|
-
type EndpointContext<Path extends string, Options extends EndpointOptions, Context = {}> = {
|
|
225
|
-
/**
|
|
226
|
-
* Method
|
|
108
|
+
* Defines the places where the endpoint will be available
|
|
227
109
|
*
|
|
228
|
-
*
|
|
110
|
+
* Possible options:
|
|
111
|
+
* - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
|
|
112
|
+
* - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
|
|
113
|
+
* - `http` - the endpoint is only exposed to the router
|
|
114
|
+
* @default "rpc"
|
|
229
115
|
*/
|
|
230
|
-
|
|
116
|
+
scope?: "rpc" | "server" | "http";
|
|
231
117
|
/**
|
|
232
|
-
*
|
|
118
|
+
* List of allowed media types (MIME types) for the endpoint
|
|
233
119
|
*
|
|
234
|
-
*
|
|
235
|
-
*/
|
|
236
|
-
path: Path;
|
|
237
|
-
/**
|
|
238
|
-
* Body
|
|
120
|
+
* if provided, only the media types in the list will be allowed to be passed in the body
|
|
239
121
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const endpoint = createEndpoint("/path", {
|
|
125
|
+
* method: "POST",
|
|
126
|
+
* allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
|
|
127
|
+
* }, async(ctx)=>{
|
|
128
|
+
* const body = ctx.body
|
|
129
|
+
* })
|
|
130
|
+
* ```
|
|
242
131
|
*/
|
|
243
|
-
|
|
132
|
+
allowedMediaTypes?: string[];
|
|
244
133
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* The query object will be the parsed query string from the request
|
|
248
|
-
* and validated against the query schema if it exists
|
|
249
|
-
*/
|
|
250
|
-
query: InferQuery<Options>;
|
|
251
|
-
/**
|
|
252
|
-
* Params
|
|
253
|
-
*
|
|
254
|
-
* If the path is `/user/:id` and the request is `/user/1` then the params will
|
|
255
|
-
* be `{ id: "1" }` and if the path includes a wildcard like `/user/*` then the
|
|
256
|
-
* params will be `{ _: "1" }` where `_` is the wildcard key. If the wildcard
|
|
257
|
-
* is named like `/user/**:name` then the params will be `{ name: string }`
|
|
134
|
+
* Extra metadata
|
|
258
135
|
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
* required
|
|
265
|
-
*/
|
|
266
|
-
request: InferRequest<Options>;
|
|
136
|
+
[key: string]: any;
|
|
137
|
+
}
|
|
138
|
+
interface EndpointRuntimeOptions {
|
|
139
|
+
method: string | string[];
|
|
140
|
+
body?: StandardSchemaV1;
|
|
267
141
|
/**
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* If `requireHeaders` is set to true in the endpoint options this will be
|
|
271
|
-
* required
|
|
142
|
+
* Query Schema
|
|
272
143
|
*/
|
|
273
|
-
|
|
144
|
+
query?: StandardSchemaV1;
|
|
274
145
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* If it's called outside of a request it will just be ignored.
|
|
146
|
+
* Error Schema
|
|
278
147
|
*/
|
|
279
|
-
|
|
148
|
+
error?: StandardSchemaV1;
|
|
280
149
|
/**
|
|
281
|
-
*
|
|
150
|
+
* If true headers will be required to be passed in the context
|
|
282
151
|
*/
|
|
283
|
-
|
|
152
|
+
requireHeaders?: boolean;
|
|
284
153
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* If it's called outside of a request it will just return null
|
|
288
|
-
*
|
|
289
|
-
* @param key - The key of the header
|
|
290
|
-
* @returns
|
|
154
|
+
* If true request object will be required
|
|
291
155
|
*/
|
|
292
|
-
|
|
156
|
+
requireRequest?: boolean;
|
|
293
157
|
/**
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* @param key - The key of the cookie
|
|
297
|
-
* @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
|
|
298
|
-
* @returns - The value of the cookie
|
|
158
|
+
* Clone the request object from the router
|
|
299
159
|
*/
|
|
300
|
-
|
|
160
|
+
cloneRequest?: boolean;
|
|
301
161
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* @param key - The key of the cookie
|
|
305
|
-
* @param secret - The secret of the signed cookie
|
|
306
|
-
* @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
|
|
307
|
-
* @returns - The value of the cookie or null if the cookie is not found or false if the signature is invalid
|
|
162
|
+
* If true the body will be undefined
|
|
308
163
|
*/
|
|
309
|
-
|
|
164
|
+
disableBody?: boolean;
|
|
310
165
|
/**
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
* @param key - The key of the cookie
|
|
314
|
-
* @param value - The value to set
|
|
315
|
-
* @param options - The options of the cookie
|
|
316
|
-
* @returns - The cookie string
|
|
166
|
+
* Endpoint metadata
|
|
317
167
|
*/
|
|
318
|
-
|
|
168
|
+
metadata?: EndpointMetadata;
|
|
319
169
|
/**
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* @param key - The key of the cookie
|
|
323
|
-
* @param value - The value to set
|
|
324
|
-
* @param secret - The secret to sign the cookie with
|
|
325
|
-
* @param options - The options of the cookie
|
|
326
|
-
* @returns - The cookie string
|
|
170
|
+
* List of middlewares to use
|
|
327
171
|
*/
|
|
328
|
-
|
|
172
|
+
use?: Middleware[];
|
|
329
173
|
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* a helper function to create a JSON response with
|
|
333
|
-
* the correct headers
|
|
334
|
-
* and status code. If `asResponse` is set to true in
|
|
335
|
-
* the context then
|
|
336
|
-
* it will return a Response object instead of the
|
|
337
|
-
* JSON object.
|
|
174
|
+
* A callback to run before any API error is thrown or returned
|
|
338
175
|
*
|
|
339
|
-
* @param
|
|
340
|
-
* @param routerResponse - The response object to
|
|
341
|
-
* return if `asResponse` is
|
|
342
|
-
* true in the context this will take precedence
|
|
343
|
-
*/
|
|
344
|
-
json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
|
|
345
|
-
status?: number;
|
|
346
|
-
headers?: Record<string, string>;
|
|
347
|
-
response?: Response;
|
|
348
|
-
body?: Record<string, string>;
|
|
349
|
-
} | Response) => Promise<R>;
|
|
350
|
-
/**
|
|
351
|
-
* Middleware context
|
|
352
|
-
*/
|
|
353
|
-
context: Prettify<Context & InferUse<Options["use"]>>;
|
|
354
|
-
/**
|
|
355
|
-
* Redirect to a new URL
|
|
176
|
+
* @param e - The API error
|
|
356
177
|
*/
|
|
357
|
-
|
|
178
|
+
onAPIError?: (e: APIError) => void | Promise<void>;
|
|
358
179
|
/**
|
|
359
|
-
*
|
|
180
|
+
* A callback to run before a validation error is thrown.
|
|
181
|
+
* You can customize the validation error message by throwing your own APIError.
|
|
360
182
|
*/
|
|
361
|
-
|
|
362
|
-
message
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
type ExtractBody<E extends EndpointBodyMethodOptions> = E extends {
|
|
367
|
-
method: ("POST" | "PUT" | "DELETE" | "PATCH" | "GET" | "HEAD")[];
|
|
368
|
-
body?: StandardSchemaV1<infer B>;
|
|
369
|
-
} ? E extends {
|
|
370
|
-
method: infer M;
|
|
371
|
-
body?: StandardSchemaV1<B>;
|
|
372
|
-
} ? {
|
|
373
|
-
method: M;
|
|
374
|
-
body: StandardSchemaV1<B>;
|
|
375
|
-
} : never : E extends {
|
|
376
|
-
method: "POST" | "PUT" | "DELETE" | "PATCH" | ("POST" | "PUT" | "DELETE" | "PATCH")[];
|
|
377
|
-
body?: StandardSchemaV1<infer B>;
|
|
378
|
-
} ? E extends {
|
|
379
|
-
method: infer M;
|
|
380
|
-
body?: StandardSchemaV1<B>;
|
|
381
|
-
} ? {
|
|
382
|
-
method: M;
|
|
383
|
-
body: StandardSchemaV1<B>;
|
|
384
|
-
} : never : E extends {
|
|
385
|
-
method: "*";
|
|
386
|
-
body?: StandardSchemaV1<infer B>;
|
|
387
|
-
} ? {
|
|
388
|
-
method: "*";
|
|
389
|
-
body?: StandardSchemaV1<B>;
|
|
390
|
-
} : E extends {
|
|
391
|
-
method: "GET" | "HEAD" | ("GET" | "HEAD")[];
|
|
392
|
-
body?: never;
|
|
393
|
-
} ? E extends {
|
|
394
|
-
method: infer M;
|
|
395
|
-
} ? {
|
|
396
|
-
method: M;
|
|
397
|
-
} : never : never;
|
|
398
|
-
type ExtractError<E extends EndpointOptions> = E extends {
|
|
399
|
-
error?: StandardSchemaV1<infer Err>;
|
|
400
|
-
} ? {
|
|
401
|
-
error: StandardSchemaV1<Err>;
|
|
402
|
-
} : {};
|
|
403
|
-
type ExtractQuery<E extends EndpointOptions> = E extends {
|
|
404
|
-
query?: StandardSchemaV1<infer Q>;
|
|
405
|
-
} ? {
|
|
406
|
-
query: StandardSchemaV1<Q>;
|
|
407
|
-
} : {};
|
|
408
|
-
type ExtractOthers<E extends EndpointOptions> = Pick<E, Exclude<keyof E, "method" | "body" | "query" | "error">>;
|
|
409
|
-
/**
|
|
410
|
-
* DO NOT EXPORT THIS TYPE
|
|
411
|
-
*/
|
|
412
|
-
type ExtractStandSchema<E extends EndpointOptions> = ExtractOthers<E> & ExtractBody<E> & ExtractQuery<E> & ExtractError<E>;
|
|
413
|
-
type EndpointHandler<Path extends string, Options extends EndpointOptions, R> = (context: EndpointContext<Path, Options>) => Promise<R>;
|
|
414
|
-
declare function createEndpoint<Path extends string, Options extends EndpointOptions, R>(path: Path, options: Options, handler: EndpointHandler<Path, Options, R>): StrictEndpoint<Path, ExtractStandSchema<Options>, R>;
|
|
415
|
-
declare function createEndpoint<Options extends EndpointOptions, R>(options: Options, handler: EndpointHandler<never, Options, R>): StrictEndpoint<never, ExtractStandSchema<Options>, R>;
|
|
416
|
-
declare namespace createEndpoint {
|
|
417
|
-
var create: <E extends {
|
|
418
|
-
use?: Middleware[];
|
|
419
|
-
}>(opts?: E) => <Path extends string, Opts extends EndpointOptions, R extends Promise<any>>(path: Path, options: Opts, handler: (ctx: EndpointContext<Path, Opts, InferUse<E["use"]>>) => R) => StrictEndpoint<Path, ExtractStandSchema<Opts & {
|
|
420
|
-
use: any[];
|
|
421
|
-
}>, any>;
|
|
183
|
+
onValidationError?: (info: {
|
|
184
|
+
message: string;
|
|
185
|
+
issues: readonly StandardSchemaV1.Issue[];
|
|
186
|
+
}) => void | Promise<void>;
|
|
422
187
|
}
|
|
423
|
-
type
|
|
424
|
-
(context: InputContext<Path,
|
|
188
|
+
type Endpoint<Path extends string = string, Method = any, Body = any, Query = any, Use extends Middleware[] = any, R = any, Meta extends EndpointMetadata | undefined = EndpointMetadata | undefined, Error = any> = {
|
|
189
|
+
(context: InputContext<Path, Method, Body, Query, false, false> & {
|
|
425
190
|
asResponse: true;
|
|
426
191
|
}): Promise<Response>;
|
|
427
|
-
(context: InputContext<Path,
|
|
192
|
+
(context: InputContext<Path, Method, Body, Query, false, false> & {
|
|
428
193
|
returnHeaders: true;
|
|
429
194
|
returnStatus: true;
|
|
430
195
|
}): Promise<{
|
|
@@ -432,44 +197,84 @@ type StrictEndpoint<Path extends string, Options extends EndpointOptions, R = an
|
|
|
432
197
|
status: number;
|
|
433
198
|
response: Awaited<R>;
|
|
434
199
|
}>;
|
|
435
|
-
(context: InputContext<Path,
|
|
436
|
-
returnHeaders: true;
|
|
437
|
-
returnStatus: false;
|
|
438
|
-
}): Promise<{
|
|
439
|
-
headers: Headers;
|
|
440
|
-
response: Awaited<R>;
|
|
441
|
-
}>;
|
|
442
|
-
(context: InputContext<Path, Options> & {
|
|
443
|
-
returnHeaders: false;
|
|
444
|
-
returnStatus: true;
|
|
445
|
-
}): Promise<{
|
|
446
|
-
status: number;
|
|
447
|
-
response: Awaited<R>;
|
|
448
|
-
}>;
|
|
449
|
-
(context: InputContext<Path, Options> & {
|
|
450
|
-
returnHeaders: false;
|
|
451
|
-
returnStatus: false;
|
|
452
|
-
}): Promise<R>;
|
|
453
|
-
(context: InputContext<Path, Options> & {
|
|
200
|
+
(context: InputContext<Path, Method, Body, Query, false, false> & {
|
|
454
201
|
returnHeaders: true;
|
|
455
202
|
}): Promise<{
|
|
456
203
|
headers: Headers;
|
|
457
204
|
response: Awaited<R>;
|
|
458
205
|
}>;
|
|
459
|
-
(context: InputContext<Path,
|
|
206
|
+
(context: InputContext<Path, Method, Body, Query, false, false> & {
|
|
460
207
|
returnStatus: true;
|
|
461
208
|
}): Promise<{
|
|
462
209
|
status: number;
|
|
463
210
|
response: Awaited<R>;
|
|
464
211
|
}>;
|
|
465
|
-
(context?: InputContext<Path,
|
|
466
|
-
options:
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
options: Options;
|
|
212
|
+
(context?: InputContext<Path, Method, Body, Query, false, false>): Promise<Awaited<R>>;
|
|
213
|
+
options: EndpointRuntimeOptions & {
|
|
214
|
+
method: Method;
|
|
215
|
+
metadata?: Meta;
|
|
216
|
+
};
|
|
471
217
|
path: Path;
|
|
472
218
|
};
|
|
219
|
+
declare function createEndpoint<Path extends string, Method extends HTTPMethod | HTTPMethod[] | "*", BodySchema extends object | undefined = undefined, QuerySchema extends object | undefined = undefined, Use extends Middleware[] = [], ReqHeaders extends boolean = false, ReqRequest extends boolean = false, R = unknown, Meta extends EndpointMetadata | undefined = undefined, ErrorSchema extends StandardSchemaV1 | undefined = undefined>(path: Path, options: {
|
|
220
|
+
method: Method;
|
|
221
|
+
} & BodyOption<Method, BodySchema> & {
|
|
222
|
+
query?: QuerySchema;
|
|
223
|
+
use?: [...Use];
|
|
224
|
+
requireHeaders?: ReqHeaders;
|
|
225
|
+
requireRequest?: ReqRequest;
|
|
226
|
+
error?: ErrorSchema;
|
|
227
|
+
cloneRequest?: boolean;
|
|
228
|
+
disableBody?: boolean;
|
|
229
|
+
metadata?: Meta;
|
|
230
|
+
onAPIError?: (e: APIError) => void | Promise<void>;
|
|
231
|
+
onValidationError?: (info: {
|
|
232
|
+
message: string;
|
|
233
|
+
issues: readonly StandardSchemaV1.Issue[];
|
|
234
|
+
}) => void | Promise<void>;
|
|
235
|
+
[key: string]: any;
|
|
236
|
+
}, handler: (ctx: EndpointContext<Path, Method, BodySchema, QuerySchema, Use, ReqHeaders, ReqRequest, InferUse<Use>, Meta>) => Promise<R>): Endpoint<Path, Method, ResolveBodyInput<BodySchema, Meta>, ResolveQueryInput<QuerySchema, Meta>, Use, R, Meta, ResolveErrorInput<ErrorSchema, Meta>>;
|
|
237
|
+
declare function createEndpoint<Method extends HTTPMethod | HTTPMethod[] | "*", BodySchema extends object | undefined = undefined, QuerySchema extends object | undefined = undefined, Use extends Middleware[] = [], ReqHeaders extends boolean = false, ReqRequest extends boolean = false, R = unknown, Meta extends EndpointMetadata | undefined = undefined, ErrorSchema extends StandardSchemaV1 | undefined = undefined>(options: {
|
|
238
|
+
method: Method;
|
|
239
|
+
} & BodyOption<Method, BodySchema> & {
|
|
240
|
+
path?: never;
|
|
241
|
+
query?: QuerySchema;
|
|
242
|
+
use?: [...Use];
|
|
243
|
+
requireHeaders?: ReqHeaders;
|
|
244
|
+
requireRequest?: ReqRequest;
|
|
245
|
+
error?: ErrorSchema;
|
|
246
|
+
cloneRequest?: boolean;
|
|
247
|
+
disableBody?: boolean;
|
|
248
|
+
metadata?: Meta;
|
|
249
|
+
onAPIError?: (e: APIError) => void | Promise<void>;
|
|
250
|
+
onValidationError?: (info: {
|
|
251
|
+
message: string;
|
|
252
|
+
issues: readonly StandardSchemaV1.Issue[];
|
|
253
|
+
}) => void | Promise<void>;
|
|
254
|
+
[key: string]: any;
|
|
255
|
+
}, handler: (ctx: EndpointContext<never, Method, BodySchema, QuerySchema, Use, ReqHeaders, ReqRequest, InferUse<Use>, Meta>) => Promise<R>): Endpoint<never, Method, ResolveBodyInput<BodySchema, Meta>, ResolveQueryInput<QuerySchema, Meta>, Use, R, Meta, ResolveErrorInput<ErrorSchema, Meta>>;
|
|
256
|
+
declare namespace createEndpoint {
|
|
257
|
+
var create: <E extends {
|
|
258
|
+
use?: Middleware[];
|
|
259
|
+
}>(opts?: E) => <Path extends string, Method extends HTTPMethod | HTTPMethod[] | "*", BodySchema extends object | undefined = undefined, QuerySchema extends object | undefined = undefined, Use extends Middleware[] = [], ReqHeaders extends boolean = false, ReqRequest extends boolean = false, R = unknown, Meta extends EndpointMetadata | undefined = undefined, ErrorSchema extends StandardSchemaV1 | undefined = undefined>(path: Path, options: {
|
|
260
|
+
method: Method;
|
|
261
|
+
} & BodyOption<Method, BodySchema> & {
|
|
262
|
+
query?: QuerySchema;
|
|
263
|
+
use?: [...Use];
|
|
264
|
+
requireHeaders?: ReqHeaders;
|
|
265
|
+
requireRequest?: ReqRequest;
|
|
266
|
+
error?: ErrorSchema;
|
|
267
|
+
cloneRequest?: boolean;
|
|
268
|
+
disableBody?: boolean;
|
|
269
|
+
metadata?: Meta;
|
|
270
|
+
onAPIError?: (e: APIError) => void | Promise<void>;
|
|
271
|
+
onValidationError?: (info: {
|
|
272
|
+
message: string;
|
|
273
|
+
issues: readonly StandardSchemaV1.Issue[];
|
|
274
|
+
}) => void | Promise<void>;
|
|
275
|
+
[key: string]: any;
|
|
276
|
+
}, handler: (ctx: EndpointContext<Path, Method, BodySchema, QuerySchema, Use, ReqHeaders, ReqRequest, InferUse<E["use"]>, Meta>) => Promise<R>) => Endpoint<Path, Method, ResolveBodyInput<BodySchema, Meta>, ResolveQueryInput<QuerySchema, Meta>, Use, Awaited<R>, Meta, ResolveErrorInput<ErrorSchema, Meta>>;
|
|
277
|
+
}
|
|
473
278
|
//#endregion
|
|
474
|
-
export { Endpoint,
|
|
279
|
+
export { Endpoint, EndpointMetadata, EndpointRuntimeOptions, createEndpoint };
|
|
475
280
|
//# sourceMappingURL=endpoint.d.cts.map
|