@server/next 0.48.3 → 0.49.1
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/index.d.ts +265 -257
- package/index.js +2204 -1905
- package/package.json +9 -6
- package/readme.md +12 -10
- package/src/jsx/jsx-runtime.js +14 -12
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
|
-
|
|
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
|
-
|
|
169
|
-
type
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
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,169 @@ 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
|
|
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
|
-
|
|
238
|
-
|
|
206
|
+
providers?: string[];
|
|
207
|
+
user: (ctx: AuthContext) => Promise<any>;
|
|
208
|
+
routes?: () => Router;
|
|
239
209
|
};
|
|
240
210
|
type AuthSettings = AuthEntry;
|
|
241
|
-
|
|
242
|
-
type
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
211
|
+
|
|
212
|
+
type StandardIssue = {
|
|
213
|
+
readonly message: string;
|
|
214
|
+
readonly path?: readonly (PropertyKey | {
|
|
215
|
+
readonly key: PropertyKey;
|
|
216
|
+
})[];
|
|
247
217
|
};
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
218
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
219
|
+
readonly "~standard": {
|
|
220
|
+
readonly version: 1;
|
|
221
|
+
readonly vendor: string;
|
|
222
|
+
readonly validate: (value: unknown) => {
|
|
223
|
+
value: Output;
|
|
224
|
+
issues?: undefined;
|
|
225
|
+
} | {
|
|
226
|
+
issues: readonly StandardIssue[];
|
|
227
|
+
} | Promise<{
|
|
228
|
+
value: Output;
|
|
229
|
+
issues?: undefined;
|
|
230
|
+
} | {
|
|
231
|
+
issues: readonly StandardIssue[];
|
|
232
|
+
}>;
|
|
233
|
+
readonly types?: {
|
|
234
|
+
readonly input: Input;
|
|
235
|
+
readonly output: Output;
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
type SchemaOutput<S, Fallback> = [S] extends [
|
|
240
|
+
StandardSchemaV1<any, infer Output>
|
|
241
|
+
] ? Output : Fallback;
|
|
242
|
+
|
|
243
|
+
type Variables = Record<string, string | string[]>;
|
|
244
|
+
type RequestError = Error & {
|
|
245
|
+
code?: string;
|
|
246
|
+
status?: number;
|
|
247
|
+
hint?: string;
|
|
248
|
+
issues?: readonly StandardIssue[];
|
|
261
249
|
};
|
|
262
|
-
type
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
250
|
+
type ExtendError = string | {
|
|
251
|
+
message: string;
|
|
252
|
+
status: number;
|
|
253
|
+
hint?: string;
|
|
254
|
+
};
|
|
255
|
+
interface ServerErrorConstructor {
|
|
256
|
+
extend(errors: Record<string, ExtendError>): Record<string, ExtendError>;
|
|
257
|
+
[key: string]: ((vars?: Variables) => ServerError) | any;
|
|
258
|
+
}
|
|
259
|
+
declare class ServerError extends Error {
|
|
260
|
+
code: string;
|
|
261
|
+
status: number;
|
|
262
|
+
hint?: string;
|
|
263
|
+
constructor(code: string, status: number, message: string | ((vars: Variables) => string), vars?: Variables);
|
|
264
|
+
static extend(errors: Record<string, ExtendError>): Record<string, ExtendError>;
|
|
265
|
+
}
|
|
266
|
+
declare const TypedServerError: typeof ServerError & ServerErrorConstructor;
|
|
267
|
+
|
|
268
|
+
type CookieOptions = string | string[] | Cookie | Cookie[] | null;
|
|
269
|
+
type SendBody = SerializableValue | JSX.Element | Uint8Array | ReadableStream | Readable | Response | Reply$1 | BucketFile | Promise<SendBody>;
|
|
270
|
+
interface ResponseData {
|
|
271
|
+
headers: Headers;
|
|
272
|
+
status?: number;
|
|
273
|
+
}
|
|
274
|
+
declare class Reply$1 {
|
|
275
|
+
res: ResponseData;
|
|
276
|
+
constructor();
|
|
277
|
+
status(status: number): this;
|
|
278
|
+
type(type?: string): this;
|
|
279
|
+
download(name?: string): this;
|
|
280
|
+
headers(key: string | Record<string, string | string[]>, value?: string | string[]): this;
|
|
281
|
+
cache(value: CacheOption): this;
|
|
282
|
+
cookies(key: string | Record<string, CookieOptions>, value?: CookieOptions): this;
|
|
283
|
+
json(body: unknown): Promise<Response>;
|
|
284
|
+
redirect(path: string): Promise<Response>;
|
|
285
|
+
file(path: string | BucketFile): Promise<Response>;
|
|
286
|
+
send(input?: SendBody): Promise<Response>;
|
|
287
|
+
}
|
|
288
|
+
type Params<K extends keyof Reply$1> = Reply$1[K] extends (...args: infer A) => any ? A : never;
|
|
289
|
+
declare const status: (...args: Params<"status">) => Reply$1;
|
|
290
|
+
declare const headers: (...args: Params<"headers">) => Reply$1;
|
|
291
|
+
declare const type: (...args: Params<"type">) => Reply$1;
|
|
292
|
+
declare const cache: (...args: Params<"cache">) => Reply$1;
|
|
293
|
+
declare const download: (...args: Params<"download">) => Reply$1;
|
|
294
|
+
declare const cookies: (...args: Params<"cookies">) => Reply$1;
|
|
295
|
+
declare const send: (...args: Params<"send">) => Promise<Response>;
|
|
296
|
+
declare const json: (...args: Params<"json">) => Promise<Response>;
|
|
297
|
+
declare const file: (...args: Params<"file">) => Promise<Response>;
|
|
298
|
+
declare const redirect: (...args: Params<"redirect">) => Promise<Response>;
|
|
299
|
+
|
|
300
|
+
type Cookie = {
|
|
301
|
+
value?: string | null;
|
|
302
|
+
path?: string;
|
|
303
|
+
expires?: number | string | Date;
|
|
304
|
+
maxAge?: number;
|
|
305
|
+
httpOnly?: boolean;
|
|
306
|
+
secure?: boolean;
|
|
307
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
268
308
|
};
|
|
269
|
-
|
|
309
|
+
|
|
310
|
+
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;
|
|
311
|
+
type ParamTypeMap = {
|
|
312
|
+
string: string;
|
|
313
|
+
number: number;
|
|
314
|
+
date: Date;
|
|
315
|
+
};
|
|
316
|
+
type InferParamType<T extends string> = T extends keyof ParamTypeMap ? ParamTypeMap[T] : string;
|
|
317
|
+
type ParamsToObject<Params extends string> = {
|
|
318
|
+
[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;
|
|
319
|
+
};
|
|
320
|
+
type PathToParams<Path extends string> = ParamsToObject<ExtractPathParams<Path>>;
|
|
321
|
+
|
|
322
|
+
type Reply = ReturnType<typeof status>;
|
|
323
|
+
type Method = "get" | "post" | "put" | "patch" | "delete" | "head" | "options" | "socket";
|
|
324
|
+
type ContextTypes = {
|
|
325
|
+
user?: any;
|
|
326
|
+
params?: any;
|
|
327
|
+
query?: any;
|
|
328
|
+
body?: any;
|
|
329
|
+
};
|
|
330
|
+
type Field<C, K extends keyof ContextTypes, Fallback> = K extends keyof C ? SchemaOutput<C[K], C[K]> : Fallback;
|
|
331
|
+
type BodyMode = "parse" | "raw" | "stream";
|
|
332
|
+
type CacheOption = string | number | false;
|
|
333
|
+
type RouteSchema = {
|
|
334
|
+
tags?: string | string[];
|
|
335
|
+
title?: string;
|
|
336
|
+
description?: string;
|
|
337
|
+
};
|
|
338
|
+
type RouteOptions = {
|
|
339
|
+
schema?: RouteSchema | false;
|
|
340
|
+
parser?: BodyMode;
|
|
341
|
+
body?: StandardSchemaV1<any, any>;
|
|
342
|
+
query?: StandardSchemaV1<any, any>;
|
|
343
|
+
params?: StandardSchemaV1<any, any>;
|
|
344
|
+
response?: StandardSchemaV1<any, any>;
|
|
345
|
+
cache?: CacheOption;
|
|
346
|
+
uploads?: string | Bucket | UploadOptions | false;
|
|
347
|
+
};
|
|
348
|
+
type Route = {
|
|
349
|
+
path: string;
|
|
350
|
+
options: Omit<RouteOptions, "uploads"> & {
|
|
351
|
+
uploads?: Settings["uploads"];
|
|
352
|
+
};
|
|
353
|
+
fns: Middleware[];
|
|
354
|
+
};
|
|
355
|
+
type BasicValue = string | number | boolean | null;
|
|
356
|
+
type SerializableValue = BasicValue | {
|
|
357
|
+
[key: string]: SerializableValue;
|
|
358
|
+
} | Array<SerializableValue>;
|
|
359
|
+
type OnError = (error: RequestError, ctx: Context) => Response | Promise<Response>;
|
|
270
360
|
type OnResponse = (response: Response, ctx: Context) => Response | void | Promise<Response | void>;
|
|
271
361
|
type Options<A = AuthOption> = {
|
|
272
362
|
port?: number;
|
|
273
363
|
secrets?: string | string[];
|
|
274
364
|
public?: string | Bucket;
|
|
275
|
-
uploads?: string | Bucket | UploadOptions;
|
|
365
|
+
uploads?: string | Bucket | UploadOptions | false;
|
|
276
366
|
cors?: CorsOptions;
|
|
277
367
|
auth?: A;
|
|
278
368
|
openapi?: boolean | string | {
|
|
@@ -294,7 +384,7 @@ type Settings = {
|
|
|
294
384
|
public?: Bucket;
|
|
295
385
|
uploads?: ({
|
|
296
386
|
bucket: Bucket;
|
|
297
|
-
} & LimitOptions) | null;
|
|
387
|
+
} & LimitOptions) | null | false;
|
|
298
388
|
cors?: CorsSettings;
|
|
299
389
|
auth?: AuthSettings;
|
|
300
390
|
openapi?: {
|
|
@@ -310,31 +400,18 @@ type Settings = {
|
|
|
310
400
|
parser: BodyMode;
|
|
311
401
|
cache?: CacheOption;
|
|
312
402
|
};
|
|
313
|
-
type Time = {
|
|
314
|
-
(name: string): void;
|
|
315
|
-
times: [string, number][];
|
|
316
|
-
headers: () => string;
|
|
317
|
-
};
|
|
318
403
|
type Platform = {
|
|
319
404
|
provider: string | null;
|
|
320
405
|
runtime: string | null;
|
|
321
406
|
production: boolean;
|
|
322
407
|
};
|
|
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
408
|
type BunEnv = Record<string, string> & {
|
|
335
409
|
upgrade?: (req: Request, options?: {
|
|
336
410
|
data?: any;
|
|
337
411
|
}) => boolean;
|
|
412
|
+
requestIP?: (req: Request) => {
|
|
413
|
+
address: string;
|
|
414
|
+
} | null;
|
|
338
415
|
};
|
|
339
416
|
interface ContextExtension {
|
|
340
417
|
}
|
|
@@ -365,87 +442,14 @@ type Context<C extends ContextTypes = {}> = {
|
|
|
365
442
|
type InlineReply = Response | Reply | BucketFile | {
|
|
366
443
|
body: string;
|
|
367
444
|
headers?: Headers;
|
|
368
|
-
} | SerializableValue | JSX
|
|
369
|
-
type Body = InlineReply;
|
|
445
|
+
} | SerializableValue | JSX.Element | Buffer | ReadableStream;
|
|
370
446
|
type Middleware<C extends ContextTypes = {}> = (ctx: Context<C>) => InlineReply | Promise<InlineReply> | void | Promise<void>;
|
|
371
447
|
|
|
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
448
|
declare global {
|
|
390
449
|
var env: Record<string, string | undefined>;
|
|
391
450
|
}
|
|
392
451
|
|
|
393
|
-
|
|
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 {
|
|
452
|
+
declare class ValidationError extends TypedServerError {
|
|
449
453
|
source: "body" | "query" | "params" | "response";
|
|
450
454
|
issues: readonly StandardIssue[];
|
|
451
455
|
constructor(source: "body" | "query" | "params" | "response", issues: readonly StandardIssue[]);
|
|
@@ -574,6 +578,10 @@ declare class Server<C extends ContextTypes = {}> extends Router<C> {
|
|
|
574
578
|
referrerPolicy?: ReferrerPolicy;
|
|
575
579
|
window?: null;
|
|
576
580
|
}) => Promise<Response>;
|
|
581
|
+
readonly cookies: {
|
|
582
|
+
[k: string]: string;
|
|
583
|
+
};
|
|
584
|
+
clear: () => void;
|
|
577
585
|
};
|
|
578
586
|
}
|
|
579
587
|
declare function server<U = AuthProfile>(options: Omit<Options, "auth"> & {
|
|
@@ -598,4 +606,4 @@ declare function server<U>(options: Omit<Options, "auth"> & {
|
|
|
598
606
|
}>;
|
|
599
607
|
declare function server<C extends ContextTypes = {}>(options?: Options): Server<C>;
|
|
600
608
|
|
|
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
|
|
609
|
+
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 };
|