@server/next 0.48.2 → 0.49.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.
Files changed (3) hide show
  1. package/index.d.ts +260 -257
  2. package/index.js +2038 -1833
  3. package/package.json +7 -5
package/index.d.ts CHANGED
@@ -2,125 +2,6 @@ import * as http from 'http';
2
2
  import { Readable } from 'node:stream';
3
3
  export { default as bucket } from 'bucket';
4
4
 
5
- type LimitOptions = {
6
- maxSize?: number | string;
7
- minSize?: number | string;
8
- fileType?: string[];
9
- };
10
-
11
- type CookieOptions = string | string[] | Cookie | Cookie[] | null;
12
- type SendBody = SerializableValue | JSX.Element | Uint8Array | ReadableStream | Readable | Response | Reply$1 | BucketFile | Promise<SendBody>;
13
- interface ResponseData {
14
- headers: Headers;
15
- status?: number;
16
- }
17
- declare class Reply$1 {
18
- res: ResponseData;
19
- constructor();
20
- status(status: number): this;
21
- type(type?: string): this;
22
- download(name?: string): this;
23
- headers(key: string | Record<string, string | string[]>, value?: string | string[]): this;
24
- cache(value: CacheOption): this;
25
- cookies(key: string | Record<string, CookieOptions>, value?: CookieOptions): this;
26
- json(body: unknown): Promise<Response>;
27
- redirect(path: string): Promise<Response>;
28
- file(path: string | BucketFile): Promise<Response>;
29
- send(input?: SendBody): Promise<Response>;
30
- }
31
- type Params<K extends keyof Reply$1> = Reply$1[K] extends (...args: infer A) => any ? A : never;
32
- declare const status: (...args: Params<"status">) => Reply$1;
33
- declare const headers: (...args: Params<"headers">) => Reply$1;
34
- declare const type: (...args: Params<"type">) => Reply$1;
35
- declare const cache: (...args: Params<"cache">) => Reply$1;
36
- declare const download: (...args: Params<"download">) => Reply$1;
37
- declare const cookies: (...args: Params<"cookies">) => Reply$1;
38
- declare const send: (...args: Params<"send">) => Promise<Response>;
39
- declare const json: (...args: Params<"json">) => Promise<Response>;
40
- declare const file: (...args: Params<"file">) => Promise<Response>;
41
- declare const redirect: (...args: Params<"redirect">) => Promise<Response>;
42
-
43
- type Reply = ReturnType<typeof status>;
44
- type Method = "get" | "post" | "put" | "patch" | "delete" | "head" | "options" | "socket";
45
- type ContextTypes = {
46
- user?: any;
47
- params?: any;
48
- query?: any;
49
- body?: any;
50
- };
51
- type Field<C, K extends keyof ContextTypes, Fallback> = K extends keyof C ? SchemaOutput<C[K], C[K]> : Fallback;
52
- declare namespace JSX$1 {
53
- interface Element {
54
- (): string;
55
- }
56
- interface IntrinsicElements {
57
- [elem: string]: any;
58
- }
59
- }
60
- type BodyMode = "parse" | "raw" | "stream";
61
- type StandardIssue = {
62
- readonly message: string;
63
- readonly path?: readonly (PropertyKey | {
64
- readonly key: PropertyKey;
65
- })[];
66
- };
67
- interface StandardSchemaV1<Input = unknown, Output = Input> {
68
- readonly "~standard": {
69
- readonly version: 1;
70
- readonly vendor: string;
71
- readonly validate: (value: unknown) => {
72
- value: Output;
73
- issues?: undefined;
74
- } | {
75
- issues: readonly StandardIssue[];
76
- } | Promise<{
77
- value: Output;
78
- issues?: undefined;
79
- } | {
80
- issues: readonly StandardIssue[];
81
- }>;
82
- readonly types?: {
83
- readonly input: Input;
84
- readonly output: Output;
85
- };
86
- };
87
- }
88
- type SchemaOutput<S, Fallback> = [S] extends [
89
- StandardSchemaV1<any, infer Output>
90
- ] ? Output : Fallback;
91
- type CacheOption = string | number | false;
92
- type RouteSchema = {
93
- tags?: string | string[];
94
- title?: string;
95
- description?: string;
96
- };
97
- type RouteOptions = {
98
- schema?: RouteSchema | false;
99
- parser?: BodyMode;
100
- body?: StandardSchemaV1<any, any>;
101
- query?: StandardSchemaV1<any, any>;
102
- params?: StandardSchemaV1<any, any>;
103
- response?: StandardSchemaV1<any, any>;
104
- cache?: CacheOption;
105
- uploads?: string | Bucket | UploadOptions | false;
106
- };
107
- type Route = {
108
- path: string;
109
- options: Omit<RouteOptions, "uploads"> & {
110
- uploads?: Settings["uploads"];
111
- };
112
- fns: Middleware[];
113
- };
114
- type Cookie = {
115
- value?: string | null;
116
- path?: string;
117
- expires?: number | string | Date;
118
- maxAge?: number;
119
- httpOnly?: boolean;
120
- secure?: boolean;
121
- sameSite?: "Strict" | "Lax" | "None";
122
- };
123
- type RouterMethod = "*" | Method;
124
5
  type FileInfo = {
125
6
  size: number;
126
7
  type: string | null;
@@ -144,15 +25,24 @@ type Bucket = {
144
25
  file(name: string): BucketFile;
145
26
  folder?(prefix: string): Bucket;
146
27
  };
28
+
29
+ type LimitOptions = {
30
+ maxFileSize?: number | string;
31
+ maxTotalSize?: number | string;
32
+ maxFiles?: number;
33
+ minSize?: number | string;
34
+ fileType?: string[];
35
+ };
36
+ type UploadOptions = LimitOptions & {
37
+ bucket: string | Bucket;
38
+ };
147
39
  type UploadedFile = {
148
40
  name: string;
149
41
  path: string;
150
42
  type: string;
151
43
  size: number;
152
44
  };
153
- type UploadOptions = LimitOptions & {
154
- bucket: string | Bucket;
155
- };
45
+
156
46
  type CorsSettings = {
157
47
  origin: string | boolean;
158
48
  methods: string;
@@ -165,10 +55,95 @@ type CorsOptions = boolean | string | string[] | {
165
55
  headers?: string | string[];
166
56
  credentials?: boolean;
167
57
  };
168
- type BasicValue = string | number | boolean | null;
169
- type SerializableValue = BasicValue | {
170
- [key: string]: SerializableValue;
171
- } | Array<SerializableValue>;
58
+
59
+ type LogLevel = "info";
60
+ type Logger = {
61
+ level?: LogLevel;
62
+ message: (scope: string, message: string) => void;
63
+ start: (url: string) => void;
64
+ request: (ctx: Context, res: Response) => void;
65
+ };
66
+
67
+ type SecurityOptions = {
68
+ trustProxy?: boolean;
69
+ frameguard?: boolean | string;
70
+ noSniff?: boolean;
71
+ referrerPolicy?: boolean | string;
72
+ hsts?: boolean | string;
73
+ xssProtection?: boolean;
74
+ traversalProtection?: boolean;
75
+ maxBodySize?: number | string | false;
76
+ csp?: boolean | string;
77
+ coop?: boolean | string;
78
+ corp?: boolean | string;
79
+ permissionsPolicy?: string;
80
+ };
81
+ type SecuritySettings = {
82
+ trustProxy: boolean;
83
+ traversalProtection: boolean;
84
+ maxBodySize: number;
85
+ headers: Record<string, string>;
86
+ hsts: string | null;
87
+ };
88
+
89
+ type Time = {
90
+ (name: string): void;
91
+ times: [string, number][];
92
+ headers: () => string;
93
+ };
94
+
95
+ type Fn<C extends ContextTypes> = (ctx: Context<C>) => ReturnType<Middleware>;
96
+ type RouteCtx<C extends ContextTypes, RO extends RouteOptions, Params> = Omit<C, "params" | "query" | "body"> & {
97
+ params: [RO["params"]] extends [StandardSchemaV1<any, any>] ? RO["params"] : Params;
98
+ } & Pick<RO, keyof RO & ("query" | "body")>;
99
+ type Mids<C extends ContextTypes, Path extends string, RO extends RouteOptions = {}> = Fn<RouteCtx<C, RO, PathToParams<Path>>>[];
100
+ type Exact<RO> = RouteOptions & {
101
+ [K in Exclude<keyof RO, keyof RouteOptions>]: never;
102
+ };
103
+ declare class Router<C extends ContextTypes = {}> {
104
+ protected settings?: Settings;
105
+ middleware: Middleware[];
106
+ handlers: Record<Method, Route[]>;
107
+ self(): this;
108
+ handle(method: Method, pathOrFn?: any, ...rest: any[]): this;
109
+ socket<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
110
+ socket(...middleware: Fn<C>[]): this;
111
+ socket<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
112
+ socket<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
113
+ get<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
114
+ get(...middleware: Fn<C>[]): this;
115
+ get<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
116
+ get<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
117
+ head<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
118
+ head(...middleware: Fn<C>[]): this;
119
+ head<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
120
+ head<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
121
+ post<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
122
+ post(...middleware: Fn<C>[]): this;
123
+ post<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
124
+ post<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
125
+ put<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
126
+ put(...middleware: Fn<C>[]): this;
127
+ put<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
128
+ put<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
129
+ patch<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
130
+ patch(...middleware: Fn<C>[]): this;
131
+ patch<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
132
+ patch<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
133
+ delete<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
134
+ delete(...middleware: Fn<C>[]): this;
135
+ delete<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
136
+ delete<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
137
+ options<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
138
+ options(...middleware: Fn<C>[]): this;
139
+ options<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
140
+ options<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...mid: Mids<C, Path, RO>): this;
141
+ use(...middleware: Fn<C>[]): this;
142
+ use(router: Router<any>): this;
143
+ }
144
+ declare function router<C extends ContextTypes = {}>(): Router<C>;
145
+
146
+ type Awaitable<T> = T | Promise<T>;
172
147
  type Strategy = "session" | "cookie" | "token" | "jwt";
173
148
  type AuthProfile = {
174
149
  provider: string;
@@ -189,18 +164,18 @@ type AuthMeta = {
189
164
  type AuthClaims = {
190
165
  sub: string;
191
166
  } & Record<string, any>;
192
- type Awaitable<T> = T | Promise<T>;
193
167
  type ProviderOptions = {
194
168
  id?: string;
195
169
  secret?: string;
196
170
  scope?: string | string[];
197
171
  issuer?: string;
198
172
  } & Record<string, any>;
199
- type RedirectOption = string | ((user: any, ctx: Context) => Awaitable<string>) | {
173
+ type RedirectTargets = {
200
174
  login?: string | ((user: any, ctx: Context) => Awaitable<string>);
201
175
  logout?: string;
202
176
  error?: string;
203
177
  };
178
+ type RedirectOption = string | ((user: any, ctx: Context) => Awaitable<string>) | RedirectTargets;
204
179
  type AuthConfig<U = AuthProfile> = {
205
180
  providers: string | readonly string[] | Record<string, string | ProviderOptions>;
206
181
  strategy?: Strategy;
@@ -225,54 +200,168 @@ type AuthInstance = {
225
200
  };
226
201
  type AuthFunction<U = any> = (ctx: Context<any>) => Awaitable<U>;
227
202
  type AuthOption = string | AuthFunction | AuthConfig<any> | AuthVerify<any> | AuthInstance;
228
- type UserOf<A> = A extends (...args: any[]) => infer R ? NonNullable<Awaited<R>> : A extends {
229
- getUser: (...args: any[]) => infer R;
230
- } ? NonNullable<Awaited<R>> : A extends {
231
- issuer: any;
232
- } ? AuthClaims : A extends {
233
- providers: any;
234
- } ? AuthProfile : A extends string ? AuthProfile : never;
203
+ type AuthContext = Pick<Context, "options" | "headers" | "cookies" | "platform" | "app">;
235
204
  type AuthEntry = {
236
205
  name: string;
237
- user: (ctx: Context) => Promise<any>;
238
- routes?: (app: Server) => void;
206
+ user: (ctx: AuthContext) => Promise<any>;
207
+ routes?: () => Router;
239
208
  };
240
209
  type AuthSettings = AuthEntry;
241
- type LogLevel = "info";
242
- type Logger = {
243
- level?: LogLevel;
244
- message: (scope: string, message: string) => void;
245
- start: (url: string) => void;
246
- request: (ctx: Context, res: Response) => void;
210
+
211
+ type StandardIssue = {
212
+ readonly message: string;
213
+ readonly path?: readonly (PropertyKey | {
214
+ readonly key: PropertyKey;
215
+ })[];
247
216
  };
248
- type SecurityOptions = {
249
- trustProxy?: boolean;
250
- frameguard?: boolean | string;
251
- noSniff?: boolean;
252
- referrerPolicy?: boolean | string;
253
- hsts?: boolean | string;
254
- xssProtection?: boolean;
255
- traversalProtection?: boolean;
256
- maxBody?: number | string | false;
257
- csp?: boolean | string;
258
- coop?: boolean | string;
259
- corp?: boolean | string;
260
- permissionsPolicy?: string;
217
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
218
+ readonly "~standard": {
219
+ readonly version: 1;
220
+ readonly vendor: string;
221
+ readonly validate: (value: unknown) => {
222
+ value: Output;
223
+ issues?: undefined;
224
+ } | {
225
+ issues: readonly StandardIssue[];
226
+ } | Promise<{
227
+ value: Output;
228
+ issues?: undefined;
229
+ } | {
230
+ issues: readonly StandardIssue[];
231
+ }>;
232
+ readonly types?: {
233
+ readonly input: Input;
234
+ readonly output: Output;
235
+ };
236
+ };
237
+ }
238
+ type SchemaOutput<S, Fallback> = [S] extends [
239
+ StandardSchemaV1<any, infer Output>
240
+ ] ? Output : Fallback;
241
+
242
+ type Variables = Record<string, string | string[]>;
243
+ type RequestError = Error & {
244
+ code?: string;
245
+ status?: number;
246
+ hint?: string;
247
+ issues?: readonly StandardIssue[];
261
248
  };
262
- type SecuritySettings = {
263
- trustProxy: boolean;
264
- traversalProtection: boolean;
265
- maxBody: number;
266
- headers: Record<string, string>;
267
- hsts: string | null;
249
+ type ExtendError = string | {
250
+ message: string;
251
+ status: number;
252
+ hint?: string;
253
+ };
254
+ interface ServerErrorConstructor {
255
+ extend(errors: Record<string, ExtendError>): Record<string, ExtendError>;
256
+ [key: string]: ((vars?: Variables) => ServerError) | any;
257
+ }
258
+ declare class ServerError extends Error {
259
+ code: string;
260
+ status: number;
261
+ hint?: string;
262
+ constructor(code: string, status: number, message: string | ((vars: Variables) => string), vars?: Variables);
263
+ static extend(errors: Record<string, ExtendError>): Record<string, ExtendError>;
264
+ }
265
+ declare const TypedServerError: typeof ServerError & ServerErrorConstructor;
266
+
267
+ type CookieOptions = string | string[] | Cookie | Cookie[] | null;
268
+ type SendBody = SerializableValue | JSX.Element | Uint8Array | ReadableStream | Readable | Response | Reply$1 | BucketFile | Promise<SendBody>;
269
+ interface ResponseData {
270
+ headers: Headers;
271
+ status?: number;
272
+ }
273
+ declare class Reply$1 {
274
+ res: ResponseData;
275
+ constructor();
276
+ status(status: number): this;
277
+ type(type?: string): this;
278
+ download(name?: string): this;
279
+ headers(key: string | Record<string, string | string[]>, value?: string | string[]): this;
280
+ cache(value: CacheOption): this;
281
+ cookies(key: string | Record<string, CookieOptions>, value?: CookieOptions): this;
282
+ json(body: unknown): Promise<Response>;
283
+ redirect(path: string): Promise<Response>;
284
+ file(path: string | BucketFile): Promise<Response>;
285
+ send(input?: SendBody): Promise<Response>;
286
+ }
287
+ type Params<K extends keyof Reply$1> = Reply$1[K] extends (...args: infer A) => any ? A : never;
288
+ declare const status: (...args: Params<"status">) => Reply$1;
289
+ declare const headers: (...args: Params<"headers">) => Reply$1;
290
+ declare const type: (...args: Params<"type">) => Reply$1;
291
+ declare const cache: (...args: Params<"cache">) => Reply$1;
292
+ declare const download: (...args: Params<"download">) => Reply$1;
293
+ declare const cookies: (...args: Params<"cookies">) => Reply$1;
294
+ declare const send: (...args: Params<"send">) => Promise<Response>;
295
+ declare const json: (...args: Params<"json">) => Promise<Response>;
296
+ declare const file: (...args: Params<"file">) => Promise<Response>;
297
+ declare const redirect: (...args: Params<"redirect">) => Promise<Response>;
298
+
299
+ type Cookie = {
300
+ value?: string | null;
301
+ path?: string;
302
+ expires?: number | string | Date;
303
+ maxAge?: number;
304
+ httpOnly?: boolean;
305
+ secure?: boolean;
306
+ sameSite?: "Strict" | "Lax" | "None";
268
307
  };
269
- type OnError = (error: Error, ctx: Context) => Response | Promise<Response>;
308
+
309
+ type ExtractPathParams<Path extends string> = Path extends `${string}:${infer Param}(${infer Type})?/${infer Rest}` ? `${Param}:${Type}?` | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}(${infer Type})?` ? `${Param}:${Type}?` : Path extends `${string}:${infer Param}(${infer Type})/${infer Rest}` ? `${Param}:${Type}` | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}(${infer Type})` ? `${Param}:${Type}` : Path extends `${string}:${infer Param}?/${infer Rest}` ? `${Param}?` | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}?` ? `${Param}?` : Path extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}` ? Param : never;
310
+ type ParamTypeMap = {
311
+ string: string;
312
+ number: number;
313
+ date: Date;
314
+ };
315
+ type InferParamType<T extends string> = T extends keyof ParamTypeMap ? ParamTypeMap[T] : string;
316
+ type ParamsToObject<Params extends string> = {
317
+ [K in Params as K extends `${infer Key}:${infer _Type}?` ? Key : K extends `${infer Key}:${infer _Type}` ? Key : K extends `${infer Key}?` ? Key : K]: K extends `${infer _Key}:${infer Type}?` ? InferParamType<Type> | undefined : K extends `${infer _Key}:${infer Type}` ? InferParamType<Type> : K extends `${infer _Key}?` ? string | undefined : string;
318
+ };
319
+ type PathToParams<Path extends string> = ParamsToObject<ExtractPathParams<Path>>;
320
+
321
+ type Reply = ReturnType<typeof status>;
322
+ type Method = "get" | "post" | "put" | "patch" | "delete" | "head" | "options" | "socket";
323
+ type ContextTypes = {
324
+ user?: any;
325
+ params?: any;
326
+ query?: any;
327
+ body?: any;
328
+ };
329
+ type Field<C, K extends keyof ContextTypes, Fallback> = K extends keyof C ? SchemaOutput<C[K], C[K]> : Fallback;
330
+ type BodyMode = "parse" | "raw" | "stream";
331
+ type CacheOption = string | number | false;
332
+ type RouteSchema = {
333
+ tags?: string | string[];
334
+ title?: string;
335
+ description?: string;
336
+ };
337
+ type RouteOptions = {
338
+ schema?: RouteSchema | false;
339
+ parser?: BodyMode;
340
+ body?: StandardSchemaV1<any, any>;
341
+ query?: StandardSchemaV1<any, any>;
342
+ params?: StandardSchemaV1<any, any>;
343
+ response?: StandardSchemaV1<any, any>;
344
+ cache?: CacheOption;
345
+ uploads?: string | Bucket | UploadOptions | false;
346
+ };
347
+ type Route = {
348
+ path: string;
349
+ options: Omit<RouteOptions, "uploads"> & {
350
+ uploads?: Settings["uploads"];
351
+ };
352
+ fns: Middleware[];
353
+ };
354
+ type BasicValue = string | number | boolean | null;
355
+ type SerializableValue = BasicValue | {
356
+ [key: string]: SerializableValue;
357
+ } | Array<SerializableValue>;
358
+ type OnError = (error: RequestError, ctx: Context) => Response | Promise<Response>;
270
359
  type OnResponse = (response: Response, ctx: Context) => Response | void | Promise<Response | void>;
271
360
  type Options<A = AuthOption> = {
272
361
  port?: number;
273
362
  secrets?: string | string[];
274
363
  public?: string | Bucket;
275
- uploads?: string | Bucket | UploadOptions;
364
+ uploads?: string | Bucket | UploadOptions | false;
276
365
  cors?: CorsOptions;
277
366
  auth?: A;
278
367
  openapi?: boolean | string | {
@@ -294,7 +383,7 @@ type Settings = {
294
383
  public?: Bucket;
295
384
  uploads?: ({
296
385
  bucket: Bucket;
297
- } & LimitOptions) | null;
386
+ } & LimitOptions) | null | false;
298
387
  cors?: CorsSettings;
299
388
  auth?: AuthSettings;
300
389
  openapi?: {
@@ -310,31 +399,18 @@ type Settings = {
310
399
  parser: BodyMode;
311
400
  cache?: CacheOption;
312
401
  };
313
- type Time = {
314
- (name: string): void;
315
- times: [string, number][];
316
- headers: () => string;
317
- };
318
402
  type Platform = {
319
403
  provider: string | null;
320
404
  runtime: string | null;
321
405
  production: boolean;
322
406
  };
323
- type ExtractPathParams<Path extends string> = Path extends `${string}:${infer Param}(${infer Type})?/${infer Rest}` ? `${Param}:${Type}?` | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}(${infer Type})?` ? `${Param}:${Type}?` : Path extends `${string}:${infer Param}(${infer Type})/${infer Rest}` ? `${Param}:${Type}` | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}(${infer Type})` ? `${Param}:${Type}` : Path extends `${string}:${infer Param}?/${infer Rest}` ? `${Param}?` | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}?` ? `${Param}?` : Path extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractPathParams<`/${Rest}`> : Path extends `${string}:${infer Param}` ? Param : never;
324
- type ParamTypeMap = {
325
- string: string;
326
- number: number;
327
- date: Date;
328
- };
329
- type InferParamType<T extends string> = T extends keyof ParamTypeMap ? ParamTypeMap[T] : string;
330
- type ParamsToObject<Params extends string> = {
331
- [K in Params as K extends `${infer Key}:${infer _Type}?` ? Key : K extends `${infer Key}:${infer _Type}` ? Key : K extends `${infer Key}?` ? Key : K]: K extends `${infer _Key}:${infer Type}?` ? InferParamType<Type> | undefined : K extends `${infer _Key}:${infer Type}` ? InferParamType<Type> : K extends `${infer _Key}?` ? string | undefined : string;
332
- };
333
- type PathToParams<Path extends string> = ParamsToObject<ExtractPathParams<Path>>;
334
407
  type BunEnv = Record<string, string> & {
335
408
  upgrade?: (req: Request, options?: {
336
409
  data?: any;
337
410
  }) => boolean;
411
+ requestIP?: (req: Request) => {
412
+ address: string;
413
+ } | null;
338
414
  };
339
415
  interface ContextExtension {
340
416
  }
@@ -365,87 +441,14 @@ type Context<C extends ContextTypes = {}> = {
365
441
  type InlineReply = Response | Reply | BucketFile | {
366
442
  body: string;
367
443
  headers?: Headers;
368
- } | SerializableValue | JSX$1.Element | Buffer | ReadableStream;
369
- type Body = InlineReply;
444
+ } | SerializableValue | JSX.Element | Buffer | ReadableStream;
370
445
  type Middleware<C extends ContextTypes = {}> = (ctx: Context<C>) => InlineReply | Promise<InlineReply> | void | Promise<void>;
371
446
 
372
- type Variables = Record<string, string | string[]>;
373
- type ExtendError = string | {
374
- message: string;
375
- status: number;
376
- };
377
- interface ServerErrorConstructor {
378
- extend(errors: Record<string, ExtendError>): Record<string, ExtendError>;
379
- [key: string]: ((vars?: Variables) => ServerError) | any;
380
- }
381
- declare class ServerError extends Error {
382
- code: string;
383
- status: number;
384
- constructor(code: string, status: number, message: string | ((vars: Variables) => string), vars?: Variables);
385
- static extend(errors: Record<string, ExtendError>): Record<string, ExtendError>;
386
- }
387
- declare const TypedServerError: typeof ServerError & ServerErrorConstructor;
388
-
389
447
  declare global {
390
448
  var env: Record<string, string | undefined>;
391
449
  }
392
450
 
393
- type Fn<C extends ContextTypes> = (ctx: Context<C>) => ReturnType<Middleware>;
394
- type RouteCtx<C extends ContextTypes, RO extends RouteOptions, Params> = Omit<C, "params" | "query" | "body"> & {
395
- params: [RO["params"]] extends [StandardSchemaV1<any, any>] ? RO["params"] : Params;
396
- } & Pick<RO, keyof RO & ("query" | "body")>;
397
- type Mids<C extends ContextTypes, Path extends string, RO extends RouteOptions = {}> = Fn<RouteCtx<C, RO, PathToParams<Path>>>[];
398
- type Exact<RO> = RouteOptions & {
399
- [K in Exclude<keyof RO, keyof RouteOptions>]: never;
400
- };
401
- declare class Router<C extends ContextTypes = {}> {
402
- middleware: Middleware[];
403
- handlers: Record<Method, Route[]>;
404
- self(): this;
405
- handle(method: Method, pathOrFn?: any, ...rest: any[]): this;
406
- socket<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
407
- socket(...middleware: Fn<C>[]): this;
408
- socket<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
409
- socket<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
410
- get<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
411
- get(...middleware: Fn<C>[]): this;
412
- get<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
413
- get<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
414
- head<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
415
- head(...middleware: Fn<C>[]): this;
416
- head<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
417
- head<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
418
- post<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
419
- post(...middleware: Fn<C>[]): this;
420
- post<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
421
- post<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
422
- put<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
423
- put(...middleware: Fn<C>[]): this;
424
- put<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
425
- put<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
426
- patch<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
427
- patch(...middleware: Fn<C>[]): this;
428
- patch<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
429
- patch<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
430
- delete<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
431
- delete(...middleware: Fn<C>[]): this;
432
- delete<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
433
- delete<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...middleware: Mids<C, Path, RO>): this;
434
- options<Path extends string>(path: Path, ...middleware: Mids<C, Path>): this;
435
- options(...middleware: Fn<C>[]): this;
436
- options<RO extends Exact<RO>>(options: RO, ...middleware: Fn<RouteCtx<C, RO, Record<string, string>>>[]): this;
437
- options<Path extends string, RO extends Exact<RO>>(path: Path, options: RO, ...mid: Mids<C, Path, RO>): this;
438
- use(...middleware: Fn<C>[]): this;
439
- use(router: Router<any>): this;
440
- }
441
- declare function router<C extends ContextTypes = {}>(): Router<C>;
442
-
443
- declare class StatusError extends Error {
444
- status: number;
445
- constructor(msg: string, status?: number);
446
- }
447
-
448
- declare class ValidationError extends StatusError {
451
+ declare class ValidationError extends TypedServerError {
449
452
  source: "body" | "query" | "params" | "response";
450
453
  issues: readonly StandardIssue[];
451
454
  constructor(source: "body" | "query" | "params" | "response", issues: readonly StandardIssue[]);
@@ -598,4 +601,4 @@ declare function server<U>(options: Omit<Options, "auth"> & {
598
601
  }>;
599
602
  declare function server<C extends ContextTypes = {}>(options?: Options): Server<C>;
600
603
 
601
- export { type AuthClaims, type AuthConfig, type AuthEntry, type AuthFunction, type AuthInstance, type AuthMeta, type AuthOption, type AuthProfile, type AuthSettings, type AuthVerify, type BasicValue, type Body, type BodyMode, type Bucket, type BucketFile, type BunEnv, type CacheOption, type Context, type ContextExtension, type ContextTypes, type Cookie, type CorsSettings, type ExtractPathParams, type FileInfo, type InferParamType, type InlineReply, type LogLevel, type Logger, type Method, type Middleware, type Options, type ParamTypeMap, type ParamsToObject, type PathToParams, type Platform, type ProviderOptions, type RedirectOption, type Route, type RouteOptions, type RouteSchema, type RouterMethod, type SchemaOutput, type SecurityOptions, type SecuritySettings, type SerializableValue, Server, TypedServerError as ServerError, type Settings, type StandardIssue, type StandardSchemaV1, type Strategy, type Time, type UploadOptions, type UploadedFile, type UserOf, ValidationError, cache, cookies, server as default, download, file, headers, json, redirect, router, send, status, type };
604
+ export { type AuthClaims, type AuthConfig, type AuthEntry, type AuthFunction, type AuthInstance, type AuthMeta, type AuthOption, type AuthProfile, type AuthSettings, type AuthVerify, type BasicValue, type BodyMode, type Bucket, type BucketFile, type BunEnv, type CacheOption, type Context, type ContextExtension, type ContextTypes, type Cookie, type CorsSettings, type ExtractPathParams, type FileInfo, type InferParamType, type InlineReply, type LogLevel, type Logger, type Method, type Middleware, type Options, type ParamTypeMap, type ParamsToObject, type PathToParams, type Platform, type ProviderOptions, type RedirectOption, type RedirectTargets, type RequestError, type Route, type RouteOptions, type RouteSchema, type SchemaOutput, type SecurityOptions, type SecuritySettings, type SerializableValue, Server, TypedServerError as ServerError, type Settings, type StandardIssue, type StandardSchemaV1, type Strategy, type Time, type UploadOptions, type UploadedFile, ValidationError, cache, cookies, server as default, download, file, headers, json, redirect, router, send, status, type };