rossa 0.0.3 → 0.0.6
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/LICENSE +1 -1
- package/README.md +226 -1
- package/dist/index.d.ts +1511 -157
- package/dist/index.js +74 -3
- package/package.json +19 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,158 +1,786 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as bun from 'bun';
|
|
3
|
-
import { Server, ServerWebSocket, Serve, WebSocketHandler } from 'bun';
|
|
4
|
-
|
|
5
|
-
type obj<T> = Record<string, T>;
|
|
6
|
-
|
|
7
|
-
declare class $$ {
|
|
8
|
-
static set p(a: any);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare class session {
|
|
12
|
-
session: obj<string>;
|
|
13
|
-
jwt: obj<string>;
|
|
14
|
-
timedJWT: ServerSide;
|
|
15
|
-
}
|
|
16
|
-
declare class ResponseSession implements session {
|
|
17
|
-
__session?: ServerSide;
|
|
18
|
-
__jwt?: ServerSide;
|
|
19
|
-
get session(): ServerSide;
|
|
20
|
-
set session(sesh: ServerSide);
|
|
21
|
-
get jwt(): ServerSide;
|
|
22
|
-
set jwt(jwt: ServerSide);
|
|
23
|
-
get timedJWT(): ServerSide;
|
|
24
|
-
setServerSession(rsp: ResponseSession): void;
|
|
25
|
-
}
|
|
26
|
-
declare const auths: {
|
|
27
|
-
session<T>(...arg: any[]): any;
|
|
28
|
-
jwt<T>(...arg: any[]): any;
|
|
29
|
-
jwt_refresh<T>(...arg: any[]): any;
|
|
30
|
-
};
|
|
1
|
+
import { Server, SocketAddress, BunFile, ServerWebSocket, WebSocketHandler, SQL } from 'bun';
|
|
31
2
|
|
|
32
|
-
declare class
|
|
33
|
-
|
|
34
|
-
server?: Server | undefined;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
3
|
+
declare class req {
|
|
4
|
+
readonly request: Request;
|
|
5
|
+
readonly server?: Server<unknown> | undefined;
|
|
6
|
+
private readonly fileDetector;
|
|
7
|
+
params: Record<string, string>;
|
|
8
|
+
private _url?;
|
|
9
|
+
private _query?;
|
|
10
|
+
private _cookies?;
|
|
11
|
+
private _formData?;
|
|
12
|
+
private _json?;
|
|
13
|
+
private _txt?;
|
|
14
|
+
constructor(request: Request, server?: Server<unknown> | undefined, fileDetector?: (path: string) => boolean);
|
|
15
|
+
/**
|
|
16
|
+
* Caches the raw text.
|
|
17
|
+
* By resolving text first, we prevent Bun's "body stream already locked" error
|
|
18
|
+
* if you attempt to read .text() and .json() in the same request lifecycle.
|
|
19
|
+
*/
|
|
20
|
+
text(): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Parses JSON from the cached text to prevent stream locks.
|
|
23
|
+
*/
|
|
24
|
+
json<T extends Record<string, any>>(): Promise<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Parses FormData. Cannot be mixed with .text() or .json() for multipart binary uploads.
|
|
27
|
+
*/
|
|
40
28
|
form(): Promise<FormData>;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
jwtv: string;
|
|
44
|
-
refreshjwt: string;
|
|
45
|
-
}>;
|
|
46
|
-
upgradeConnection(data?: obj<any>): boolean;
|
|
47
|
-
get auth(): string | undefined;
|
|
48
|
-
get accept(): string | null;
|
|
49
|
-
get contentType(): string | null;
|
|
29
|
+
get url(): URL;
|
|
30
|
+
get query(): Record<string, string>;
|
|
50
31
|
get cookies(): Map<string, string>;
|
|
32
|
+
get auth(): string | undefined;
|
|
33
|
+
get method(): string;
|
|
51
34
|
get headers(): Headers;
|
|
52
|
-
|
|
53
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Helper to grab a specific header safely.
|
|
37
|
+
*/
|
|
38
|
+
header(key: string): string | null;
|
|
39
|
+
get ip(): SocketAddress | null;
|
|
54
40
|
get path(): string;
|
|
55
|
-
get
|
|
56
|
-
get searchParams(): URLSearchParams;
|
|
57
|
-
get range(): string | undefined;
|
|
58
|
-
get isEventStream(): boolean | undefined;
|
|
41
|
+
get isForm(): boolean;
|
|
59
42
|
get isWSS(): boolean;
|
|
43
|
+
get isEventStream(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Infers if the route is a static file by checking for an extension in the last URL segment.
|
|
46
|
+
*/
|
|
60
47
|
get isFile(): boolean;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
declare class eStream {
|
|
68
|
-
ctrl?: ReadableStreamDefaultController<any> | undefined;
|
|
69
|
-
intervalID: Timer[];
|
|
70
|
-
constructor(ctrl?: ReadableStreamDefaultController<any> | undefined);
|
|
71
|
-
push(fn: () => {
|
|
72
|
-
id: string | number;
|
|
73
|
-
data: string | Record<string, string>;
|
|
74
|
-
event?: string;
|
|
75
|
-
retry?: number;
|
|
76
|
-
end?: boolean;
|
|
77
|
-
}, interval?: number | 1000): void;
|
|
78
|
-
close(): void;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
declare class response extends ResponseSession implements response {
|
|
82
|
-
request: request;
|
|
83
|
-
args: Record<string, string>;
|
|
84
|
-
[key: string]: any;
|
|
85
|
-
status?: number;
|
|
86
|
-
stream?: eStream;
|
|
87
|
-
path: string;
|
|
88
|
-
private headers;
|
|
89
|
-
constructor(request: request, args?: Record<string, string>);
|
|
90
|
-
get?(): Promise<any> | any;
|
|
91
|
-
post?(): Promise<any> | any;
|
|
92
|
-
put?(): Promise<any> | any;
|
|
93
|
-
patch?(): Promise<any> | any;
|
|
94
|
-
eventStream?(): Promise<any> | any;
|
|
95
|
-
set header(head: obj<string>);
|
|
96
|
-
get header(): obj<string>;
|
|
97
|
-
set type(content: string);
|
|
98
|
-
setCookie({ key, val, path, days, httpOnly, }: {
|
|
99
|
-
key: string;
|
|
100
|
-
val: string;
|
|
101
|
-
path?: string;
|
|
102
|
-
days?: number;
|
|
103
|
-
httpOnly?: boolean;
|
|
104
|
-
}): void;
|
|
105
|
-
deleteCookie(key: string): void;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
declare class websocket extends ResponseSession {
|
|
109
|
-
request: request;
|
|
110
|
-
[Key: string]: any;
|
|
111
|
-
ws: ServerWebSocket<{
|
|
112
|
-
wclass: websocket;
|
|
48
|
+
getAuthCredentials(): Promise<{
|
|
49
|
+
sid: string;
|
|
50
|
+
jwt: string;
|
|
51
|
+
refresh: string;
|
|
113
52
|
}>;
|
|
114
|
-
|
|
53
|
+
upgrade<T = any>(data?: T): boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type HeaderObject$1 = Record<string, string>;
|
|
57
|
+
|
|
58
|
+
declare class HeadBase {
|
|
59
|
+
protected data: HeaderObject$1;
|
|
60
|
+
constructor(initialData?: HeaderObject$1);
|
|
61
|
+
protected _add(key: string, value: string): this;
|
|
62
|
+
add(key: string, value: string): this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** * Layer 1: Security
|
|
66
|
+
*/
|
|
67
|
+
declare class SecurityHead extends HeadBase {
|
|
68
|
+
/** * Prevents clickjacking by forbidding the page from being framed.
|
|
69
|
+
* Options: 'DENY', 'SAMEORIGIN'
|
|
70
|
+
*/
|
|
71
|
+
frameOptions(option?: "DENY" | "SAMEORIGIN"): this;
|
|
72
|
+
/** * Forces browser to stick to the declared Content-Type.
|
|
73
|
+
*/
|
|
74
|
+
noSniff(): this;
|
|
75
|
+
/** * Forces HTTPS for a set duration (default 1 year).
|
|
76
|
+
*/
|
|
77
|
+
hsts(maxAge?: number): this;
|
|
78
|
+
/** * Basic CSP: Only allow scripts/styles from your own origin.
|
|
79
|
+
*/
|
|
80
|
+
csp(policy?: string): this;
|
|
81
|
+
/** Referrer policy for privacy */
|
|
82
|
+
referrer(policy?: "no-referrer" | "origin" | "strict-origin-when-cross-origin"): this;
|
|
83
|
+
/** * NEW: Cross-Origin Opener Policy (Isolates your tab from others)
|
|
84
|
+
*/
|
|
85
|
+
coop(policy?: "same-origin" | "same-origin-allow-popups" | "unsafe-none"): this;
|
|
86
|
+
/** * NEW: Cross-Origin Embedder Policy
|
|
87
|
+
*/
|
|
88
|
+
coep(policy?: "require-corp" | "unsafe-none"): this;
|
|
89
|
+
/** * Modern replacement for Feature-Policy.
|
|
90
|
+
* e.g., "camera=(), microphone=()"
|
|
91
|
+
*/
|
|
92
|
+
permissions(policy: string): this;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** * Layer 2: Traffic (Extends SecurityHead)
|
|
96
|
+
*/
|
|
97
|
+
declare class Traffic extends SecurityHead {
|
|
98
|
+
cors(origin?: string): this;
|
|
99
|
+
cache(seconds?: number): this;
|
|
100
|
+
noCache(): this;
|
|
101
|
+
etag(val: string): this;
|
|
102
|
+
/** * Set custom timing metrics for browser dev tools.
|
|
103
|
+
*/
|
|
104
|
+
serverTiming(name: string, durMs: number, desc?: string): this;
|
|
105
|
+
/** Sets standard rate limit headers */
|
|
106
|
+
rateLimit(limit: number, remaining: number, resetSeconds: number): this;
|
|
107
|
+
/** Sets the Retry-After header (useful for 429 or 503) */
|
|
108
|
+
retryAfter(seconds: number | string): this;
|
|
109
|
+
/**
|
|
110
|
+
* Sets the date/time after which the response is considered stale.
|
|
111
|
+
*/
|
|
112
|
+
expires(date: Date): this;
|
|
113
|
+
/**
|
|
114
|
+
* Indicates the date and time at which the resource was last modified.
|
|
115
|
+
*/
|
|
116
|
+
lastModified(date: Date): this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** * Layer 3: Auth (Extends Traffic)
|
|
120
|
+
*/
|
|
121
|
+
declare class AuthHead extends Traffic {
|
|
122
|
+
/** * Sets the WWW-Authenticate header for 401 responses.
|
|
123
|
+
* e.g., head.authenticate("Bearer", "realm=\"access\"")
|
|
124
|
+
*/
|
|
125
|
+
authenticate(scheme: "Bearer" | "Basic" | "Digest", details?: string): this;
|
|
126
|
+
/** * Sets the Proxy-Authenticate header.
|
|
127
|
+
*/
|
|
128
|
+
proxyAuthenticate(value: string): this;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
type CommonMimeType = "text/plain" | "text/html" | "text/css" | "text/javascript" | "application/json" | "application/xml" | "application/x-www-form-urlencoded" | "multipart/form-data" | "audio/mpeg" | "video/mp4" | (string & {});
|
|
132
|
+
/** * Layer 3: Auth (Extends AuthHead)
|
|
133
|
+
*/
|
|
134
|
+
declare class Contents extends AuthHead {
|
|
135
|
+
/**
|
|
136
|
+
* Bulk setter for content headers.
|
|
137
|
+
* Accepts an object where keys match semantic method names.
|
|
138
|
+
*/
|
|
139
|
+
content(options: {
|
|
140
|
+
length?: number;
|
|
141
|
+
type?: CommonMimeType;
|
|
142
|
+
encoding?: "gzip" | "deflate" | "br" | "identity" | "zstd";
|
|
143
|
+
disposition?: {
|
|
144
|
+
type: "inline" | "attachment";
|
|
145
|
+
filename?: string;
|
|
146
|
+
};
|
|
147
|
+
language?: string;
|
|
148
|
+
range?: string;
|
|
149
|
+
location?: string;
|
|
150
|
+
md5?: string;
|
|
151
|
+
}): this;
|
|
152
|
+
/** The size of the response body in bytes */
|
|
153
|
+
contentLength(bytes: number): this;
|
|
154
|
+
/** The MD5 hash of the body to verify data integrity */
|
|
155
|
+
contentMD5(hash: string): this;
|
|
156
|
+
/** content type */
|
|
157
|
+
contentType(mime: CommonMimeType): this;
|
|
158
|
+
/** * Defines the compression algorithm used.
|
|
159
|
+
* Common: 'gzip', 'deflate', 'br' (Brotli)
|
|
160
|
+
*/
|
|
161
|
+
contentEncoding(encoding: "gzip" | "deflate" | "br" | "identity" | "zstd"): this;
|
|
162
|
+
/** * Where the content actually lives if this is a partial view
|
|
163
|
+
* or a reference to another location.
|
|
164
|
+
*/
|
|
165
|
+
contentLocation(url: string): this;
|
|
166
|
+
/** Used to indicate the range of bytes in a partial response (Status 206) */
|
|
167
|
+
contentRange(range: string): this;
|
|
168
|
+
/** Specifies the security level or sensitivity of the content */
|
|
169
|
+
contentSecurity(value: string): this;
|
|
170
|
+
/** * Controls if content is displayed inline or as an attachment (download).
|
|
171
|
+
* @param type 'inline' or 'attachment'
|
|
172
|
+
* @param filename Optional name for the downloaded file
|
|
173
|
+
*/
|
|
174
|
+
disposition(type?: "inline" | "attachment", filename?: string): this;
|
|
175
|
+
/** Tells the client which request headers were used to decide the response */
|
|
176
|
+
vary(...headers: string[]): this;
|
|
177
|
+
/** Suggests a language for the content */
|
|
178
|
+
language(lang: string): this;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** * Layer 5: Auth (Extends Traffic)
|
|
182
|
+
*/
|
|
183
|
+
declare class Utils extends Contents {
|
|
184
|
+
location(url: string): this;
|
|
185
|
+
/**
|
|
186
|
+
* Specifically sets the Access-Control-Allow-Origin header.
|
|
187
|
+
*/
|
|
188
|
+
origin(value?: string): this;
|
|
189
|
+
/**
|
|
190
|
+
* The date and time at which the message was originated.
|
|
191
|
+
*/
|
|
192
|
+
date(date?: Date): this;
|
|
193
|
+
/**
|
|
194
|
+
* Contains information about the software used by the origin server.
|
|
195
|
+
*/
|
|
196
|
+
server(name: string): this;
|
|
197
|
+
/**
|
|
198
|
+
* Controls whether the network connection stays open after the transaction finishes.
|
|
199
|
+
* Common: 'keep-alive', 'close'
|
|
200
|
+
*/
|
|
201
|
+
connection(value: "keep-alive" | "close"): this;
|
|
202
|
+
/**
|
|
203
|
+
* Sets parameters for a persistent connection (timeout and max requests).
|
|
204
|
+
* e.g., head.keepAlive("timeout=5, max=1000")
|
|
205
|
+
*/
|
|
206
|
+
keepAlive(value: string | number): this;
|
|
207
|
+
cookie(name: string, value: string, options?: CookieOptions): this;
|
|
208
|
+
}
|
|
209
|
+
interface CookieOptions {
|
|
210
|
+
/**
|
|
211
|
+
* Max-Age in seconds, or a Date from which seconds will be derived.
|
|
212
|
+
*/
|
|
213
|
+
maxAge?: number | Date;
|
|
214
|
+
/**
|
|
215
|
+
* Expires as Date, timestamp, or preformatted date string.
|
|
216
|
+
*/
|
|
217
|
+
expires?: Date | number | string;
|
|
218
|
+
path?: string | null;
|
|
219
|
+
domain?: string;
|
|
220
|
+
secure?: boolean;
|
|
221
|
+
httpOnly?: boolean;
|
|
222
|
+
sameSite?: "Lax" | "Strict" | "None" | null;
|
|
223
|
+
/**
|
|
224
|
+
* Internal only – not serialized; used if you actually measure size.
|
|
225
|
+
*/
|
|
226
|
+
maxSize?: number;
|
|
227
|
+
syncExpires?: boolean;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** * Final Master Class (The one you actually use)
|
|
231
|
+
*/
|
|
232
|
+
declare class Heder extends Utils {
|
|
233
|
+
/**
|
|
234
|
+
* Creates a deep copy of the current builder for reuse.
|
|
235
|
+
*/
|
|
236
|
+
get copy(): Heder;
|
|
237
|
+
use(plugin: HederPlugin): this;
|
|
238
|
+
merge(_heder: Heder | HeaderObject$1): this;
|
|
239
|
+
static init(initial?: HeaderObject$1): Heder;
|
|
240
|
+
static get $(): Heder;
|
|
241
|
+
get done(): HeaderObject$1;
|
|
242
|
+
}
|
|
243
|
+
type HederPlugin = (h: Heder) => void;
|
|
244
|
+
|
|
245
|
+
declare class ServerSide<TData extends Record<string, any> = Record<string, any>> {
|
|
246
|
+
sid: string;
|
|
247
|
+
data: TData;
|
|
248
|
+
isNew: boolean;
|
|
249
|
+
isModified: boolean;
|
|
250
|
+
isReadOnly: boolean;
|
|
251
|
+
isFound: boolean;
|
|
252
|
+
length: number;
|
|
253
|
+
constructor(sid?: string, initialData?: Partial<TData>, readOnly?: boolean, isNew?: boolean, isFound?: boolean);
|
|
254
|
+
/**
|
|
255
|
+
* Generates the dynamic Proxy trapped instance.
|
|
256
|
+
* We use `this & TData` so TypeScript knows this object contains both
|
|
257
|
+
* the class methods AND the dynamic user data.
|
|
258
|
+
*/
|
|
259
|
+
get session(): any;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
declare class ctx<Args extends Record<string, string> = Record<string, string>, SessionType = ServerSide, BodyType = unknown> {
|
|
263
|
+
readonly res: res;
|
|
264
|
+
params: Args;
|
|
265
|
+
/**
|
|
266
|
+
* Custom header maker
|
|
267
|
+
*/
|
|
268
|
+
headr: Heder;
|
|
269
|
+
url: URL;
|
|
270
|
+
data: Record<string, any>;
|
|
271
|
+
jwtData: Record<string, any>;
|
|
272
|
+
session?: SessionType;
|
|
273
|
+
body?: BodyType;
|
|
274
|
+
query: Record<string, string | string[] | undefined>;
|
|
275
|
+
form: Record<string, any>;
|
|
276
|
+
readonly req: req;
|
|
277
|
+
method: string;
|
|
278
|
+
methods: string[];
|
|
279
|
+
clientDirectory: string;
|
|
280
|
+
constructor(res: res);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
type ErrorConfig = {
|
|
284
|
+
code?: number | undefined;
|
|
285
|
+
message?: string | undefined;
|
|
286
|
+
redirect?: string | undefined;
|
|
287
|
+
headers?: Record<string, string> | undefined;
|
|
288
|
+
error?: (ctx: ctx) => Response;
|
|
289
|
+
maxSize?: number | undefined;
|
|
290
|
+
};
|
|
291
|
+
declare function sendError(config: ErrorConfig, details?: any): Response;
|
|
292
|
+
|
|
293
|
+
type ContentEncodingType = "gzip" | "deflate" | "br" | "zstd" | "none";
|
|
294
|
+
|
|
295
|
+
interface StreamPayload {
|
|
296
|
+
/** Provides a recovery ID for automatic reconnection tracking. */
|
|
297
|
+
id?: string | number;
|
|
298
|
+
/** Contains the actual payload (must be the last field in the packet). */
|
|
299
|
+
data: string | Record<string, any>;
|
|
300
|
+
/** Names the event so the client can use addEventListener('name', ...). */
|
|
301
|
+
event?: string;
|
|
302
|
+
/** Tells the client how many milliseconds to wait before reconnecting (default is 3000ms). */
|
|
303
|
+
retry?: number;
|
|
304
|
+
/** Forcefully end and close the stream. */
|
|
305
|
+
end?: boolean;
|
|
306
|
+
/** State function to return the value as an argument in the next interval. */
|
|
307
|
+
fn?: () => any;
|
|
308
|
+
}
|
|
309
|
+
type StreamPushFn = (prevFnResult?: any) => StreamPayload;
|
|
310
|
+
|
|
311
|
+
declare class StaticFileServer {
|
|
312
|
+
private readonly absoluteClientPath;
|
|
313
|
+
private readonly additionalExtensions;
|
|
314
|
+
private readonly SMALL_FILE_THRESHOLD;
|
|
315
|
+
private readonly CACHE_TTL;
|
|
316
|
+
constructor(resolvedAssetRootPath: string, additionalExtensions?: string[]);
|
|
317
|
+
isFile(path: string): boolean;
|
|
318
|
+
serve(req: req, res: res): Promise<Response>;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
type HeaderObject = Record<string, string>;
|
|
322
|
+
interface RespoOptions {
|
|
323
|
+
/** Compression encoding to apply to generated response bodies. */
|
|
324
|
+
encoding?: ContentEncodingType;
|
|
325
|
+
}
|
|
326
|
+
interface FileMeta {
|
|
327
|
+
/** Byte length of a raw `Uint8Array` file. */
|
|
328
|
+
size: number;
|
|
329
|
+
/** MIME type of a raw `Uint8Array` file. */
|
|
330
|
+
type: string;
|
|
331
|
+
}
|
|
332
|
+
/** Builds HTTP responses while retaining status, headers, and encoding settings. */
|
|
333
|
+
declare class res {
|
|
334
|
+
readonly req: req;
|
|
335
|
+
private readonly staticServer;
|
|
336
|
+
private readonly server?;
|
|
337
|
+
private _code;
|
|
338
|
+
private _headers;
|
|
339
|
+
private _encoding?;
|
|
340
|
+
/**
|
|
341
|
+
* Creates a response builder for the current request.
|
|
342
|
+
*
|
|
343
|
+
* @param options - Optional response encoding settings.
|
|
344
|
+
* @param req - The request context used by file serving and streaming helpers.
|
|
345
|
+
* @param staticServer - Static file server used by {@link fileServer}.
|
|
346
|
+
* @param server - Optional Bun server. Streaming helpers need it to disable
|
|
347
|
+
* Bun's request timeout for the long-lived connection.
|
|
348
|
+
*/
|
|
349
|
+
constructor(options: RespoOptions | undefined, req: req, staticServer: StaticFileServer, server?: Bun.Server<undefined> | undefined);
|
|
350
|
+
/**
|
|
351
|
+
* Sets the HTTP response status code.
|
|
352
|
+
* * ### 1xx: Informational
|
|
353
|
+
* - **101 (Switching Protocols):** Switching to WebSockets.
|
|
354
|
+
* * ### 2xx: Success
|
|
355
|
+
* - **200 (OK):** Request succeeded.
|
|
356
|
+
* - **201 (Created):** Resource created (e.g., new database record).
|
|
357
|
+
* - **202 (Accepted):** Request accepted but still processing (Async).
|
|
358
|
+
* - **204 (No Content):** Success, but returning no body (e.g., OPTIONS/DELETE).
|
|
359
|
+
* - **206 (Partial Content):** Range request success (Streaming).
|
|
360
|
+
* * ### 3xx: Redirection
|
|
361
|
+
* - **301 (Moved Permanently):** Permanent URL change.
|
|
362
|
+
* - **302 (Found):** Temporary URL change.
|
|
363
|
+
* - **304 (Not Modified):** Use the browser's cached version.
|
|
364
|
+
* - **307/308:** Temporary/Permanent redirect (preserves POST data).
|
|
365
|
+
* * ### 4xx: Client Errors
|
|
366
|
+
* - **400 (Bad Request):** Invalid syntax or malformed data.
|
|
367
|
+
* - **401 (Unauthorized):** Authentication is missing or invalid.
|
|
368
|
+
* - **403 (Forbidden):** Authenticated but lacks permissions.
|
|
369
|
+
* - **404 (Not Found):** Resource doesn't exist.
|
|
370
|
+
* - **405 (Method Not Allowed):** e.g., POSTing to a GET-only route.
|
|
371
|
+
* - **406 (Not Acceptable):** Requested format (Accept header) not supported.
|
|
372
|
+
* - **408 (Request Timeout):** Client took too long to send data.
|
|
373
|
+
* - **409 (Conflict):** State conflict (e.g., duplicate username).
|
|
374
|
+
* - **410 (Gone):** Resource is permanently deleted.
|
|
375
|
+
* - **413 (Payload Too Large):** Request body exceeds limits.
|
|
376
|
+
* - **415 (Unsupported Media Type):** e.g., sending XML when API expects JSON.
|
|
377
|
+
* - **416 (Range Not Satisfiable):** Invalid byte range requested.
|
|
378
|
+
* - **422 (Unprocessable Entity):** Validation error (correct syntax, wrong data).
|
|
379
|
+
* - **429 (Too Many Requests):** Rate limit exceeded.
|
|
380
|
+
* * ### 5xx: Server Errors
|
|
381
|
+
* - **500 (Internal Server Error):** General server crash.
|
|
382
|
+
* - **501 (Not Implemented):** Server doesn't support the requested method.
|
|
383
|
+
* - **502 (Bad Gateway):** Upstream server (proxy) sent an invalid response.
|
|
384
|
+
* - **503 (Service Unavailable):** Server is overloaded or down for maintenance.
|
|
385
|
+
* - **504 (Gateway Timeout):** Upstream server took too long to respond.
|
|
386
|
+
* * @param code - The numeric HTTP status code.
|
|
387
|
+
*/
|
|
388
|
+
status(code: number): this;
|
|
389
|
+
/**
|
|
390
|
+
* Sets the Content-Encoding header and internal state.
|
|
391
|
+
*/
|
|
392
|
+
/**
|
|
393
|
+
* Sets or clears the response content encoding.
|
|
394
|
+
*
|
|
395
|
+
* @param type - Encoding to use, or `"none"` to remove the encoding header.
|
|
396
|
+
* @returns This response builder for chaining.
|
|
397
|
+
*/
|
|
398
|
+
encode(type: ContentEncodingType): this;
|
|
399
|
+
/**
|
|
400
|
+
* Consumes the Head builder object.
|
|
401
|
+
*/
|
|
402
|
+
/**
|
|
403
|
+
* Adds or replaces response headers. `Vary` values are merged without
|
|
404
|
+
* duplicates so callers can add negotiation dimensions incrementally.
|
|
405
|
+
*
|
|
406
|
+
* @param input - A header builder or a map of header names to values.
|
|
407
|
+
* @returns This response builder for chaining.
|
|
408
|
+
*/
|
|
409
|
+
header(input: Heder | HeaderObject): this;
|
|
410
|
+
private _assemble;
|
|
411
|
+
/**
|
|
412
|
+
* Creates a response with no body using the supplied status or current status.
|
|
413
|
+
*
|
|
414
|
+
* @param status - Optional status code for this response.
|
|
415
|
+
*/
|
|
416
|
+
null(status?: number): Response;
|
|
417
|
+
/** Serializes a value as JSON and returns an `application/json` response. */
|
|
418
|
+
json(data: Record<string, any>): Response;
|
|
419
|
+
/** Returns an HTML response with a UTF-8 content type. */
|
|
420
|
+
html(body: string): Response;
|
|
421
|
+
/** Returns a plain text response with a UTF-8 content type. */
|
|
422
|
+
text(body?: string): Response;
|
|
423
|
+
/**
|
|
424
|
+
* Standardized Error Response.
|
|
425
|
+
* Automatically sets the status code and returns a JSON error structure.
|
|
426
|
+
* * ### Common Error Codes:
|
|
427
|
+
* - **400 (Bad Request):** The server cannot process the request due to client error (e.g., malformed syntax).
|
|
428
|
+
* - **401 (Unauthorized):** Authentication is required and has failed or has not yet been provided.
|
|
429
|
+
* - **403 (Forbidden):** The server understood the request but refuses to authorize it.
|
|
430
|
+
* - **404 (Not Found):** The requested resource could not be found.
|
|
431
|
+
* - **405 (Method Not Allowed):** The request method is known by the server but has been disabled.
|
|
432
|
+
* - **409 (Conflict):** Request conflicts with current state (e.g., duplicate entry).
|
|
433
|
+
* - **413 (Payload Too Large):** The request entity is larger than limits defined by server.
|
|
434
|
+
* - **415 (Unsupported Media Type):** The media format of the requested data is not supported.
|
|
435
|
+
* - **422 (Unprocessable Entity):** Valid syntax but contains semantic errors (e.g., validation failed).
|
|
436
|
+
* - **429 (Too Many Requests):** The user has sent too many requests in a given amount of time.
|
|
437
|
+
* - **500 (Internal Server Error):** A generic error message, given when an unexpected condition was encountered.
|
|
438
|
+
* - **503 (Service Unavailable):** The server is currently unable to handle the request (overloaded or down).
|
|
439
|
+
* @param code - The numeric HTTP error status code.
|
|
440
|
+
* @param message - A human-readable explanation of the error.
|
|
441
|
+
* @param details - Optional object or array containing specific error details (e.g., field-level validation).
|
|
442
|
+
*/
|
|
443
|
+
error(code: number, message: string | Record<string, any>): Response;
|
|
444
|
+
/**
|
|
445
|
+
* Standardized Success Response.
|
|
446
|
+
* Automatically sets the status code and returns a JSON success structure.
|
|
447
|
+
* * ### Common Success Codes:
|
|
448
|
+
* - **200 (OK):** The request was successful and the payload is returned in the response body.
|
|
449
|
+
* - **201 (Created):** The request succeeded and a new resource was created (e.g., successful insert or register).
|
|
450
|
+
* - **202 (Accepted):** The request was received but has not yet been acted upon (e.g., background job started).
|
|
451
|
+
* - **204 (No Content):** The request succeeded but there is no payload to return (e.g., successful delete).
|
|
452
|
+
* * @param code - The numeric HTTP success status code (defaults to 200).
|
|
453
|
+
* @param data - Optional primary payload or resource data returned to the client.
|
|
454
|
+
* @param message - Optional human-readable confirmation message.
|
|
455
|
+
*/
|
|
456
|
+
success(code?: number, data?: any, message?: string): Response;
|
|
457
|
+
/**
|
|
458
|
+
* Creates an empty redirect response with a `Location` header.
|
|
459
|
+
*
|
|
460
|
+
* @param url - Destination URL placed in the `Location` header.
|
|
461
|
+
* @param status - Redirect status code; defaults to `302`.
|
|
462
|
+
*/
|
|
463
|
+
redirect(url: string, status?: number): Response;
|
|
464
|
+
/**
|
|
465
|
+
* use fileserver to serve the file securely.
|
|
466
|
+
*/
|
|
467
|
+
/** Serves the current request through the configured secure static file server. */
|
|
468
|
+
fileServer(): Promise<Response>;
|
|
469
|
+
/**
|
|
470
|
+
* Universal file handler supporting BunFile and raw Uint8Array.
|
|
471
|
+
*/
|
|
472
|
+
/**
|
|
473
|
+
* Sends a Bun file or byte array, with optional metadata and extra headers.
|
|
474
|
+
* Bun files support byte range requests; byte arrays do not. A missing Bun
|
|
475
|
+
* file returns `404`, and an invalid range returns `416`.
|
|
476
|
+
*
|
|
477
|
+
* @param file - File handle or bytes to send.
|
|
478
|
+
* @param meta - MIME type and size metadata for a byte array.
|
|
479
|
+
* @param extraHeaders - Additional headers to apply before sending.
|
|
480
|
+
*/
|
|
481
|
+
file(file: BunFile | Uint8Array, meta?: FileMeta, extraHeaders?: Heder | HeaderObject): Promise<Response>;
|
|
482
|
+
/**
|
|
483
|
+
* Returns Server-Sent Events (SSE) response helpers.
|
|
484
|
+
*
|
|
485
|
+
* SSE keeps an HTTP response open so the server can push events to a client.
|
|
486
|
+
* Use the returned helper that best fits the producer:
|
|
487
|
+
*
|
|
488
|
+
* - `asyncStream` consumes an async generator and emits each yielded value as
|
|
489
|
+
* a `data:` message. Objects are JSON-encoded; other values are stringified.
|
|
490
|
+
* - `eStream` calls a push function on an interval and supports SSE `id`,
|
|
491
|
+
* `event`, `retry`, and end-of-stream fields in its returned payload.
|
|
492
|
+
* - `readableStream` gives a producer the stream controller for fully manual
|
|
493
|
+
* framing and lifecycle control.
|
|
494
|
+
*
|
|
495
|
+
* Each helper returns a `text/event-stream` response and disables Bun's
|
|
496
|
+
* request timeout for the current request. If this response builder was
|
|
497
|
+
* created without a Bun server, its helpers return a `500` response.
|
|
498
|
+
* Consumers can listen in browsers with `EventSource`; SSE is one-way, from
|
|
499
|
+
* server to client. Use WebSockets when clients also need to send live data.
|
|
500
|
+
*/
|
|
501
|
+
get event(): {
|
|
502
|
+
/**
|
|
503
|
+
* Creates an SSE stream from an async generator.
|
|
504
|
+
*
|
|
505
|
+
* Every yielded value becomes one `data: ...` message followed by a blank
|
|
506
|
+
* line. Objects are JSON-encoded; primitives are converted to strings.
|
|
507
|
+
* Returning from the generator closes the stream. If the client
|
|
508
|
+
* disconnects, the generator's `return()` method is called when present.
|
|
509
|
+
*
|
|
510
|
+
* @param generator - Factory that returns the async iterable of messages.
|
|
511
|
+
* @returns An SSE response, or a `500` response when no Bun server is set.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```ts
|
|
515
|
+
* return res.event.asyncStream(async function* () {
|
|
516
|
+
* yield { status: "connected" };
|
|
517
|
+
* while (true) {
|
|
518
|
+
* yield { time: new Date().toISOString() };
|
|
519
|
+
* await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
520
|
+
* }
|
|
521
|
+
* });
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
asyncStream: (generator: () => AsyncGenerator<any, void, unknown>) => Response;
|
|
525
|
+
/**
|
|
526
|
+
* Creates an interval-driven SSE stream.
|
|
527
|
+
*
|
|
528
|
+
* The callback returns a payload containing `data` and optional SSE
|
|
529
|
+
* metadata (`id`, `event`, `retry`), an `end` flag, or an `fn` callback
|
|
530
|
+
* whose result is passed to the next invocation. The interval is clamped
|
|
531
|
+
* to at least one second. Setting `end: true` closes the stream before
|
|
532
|
+
* emitting that callback's payload. On client disconnect, the interval
|
|
533
|
+
* is cleared and `onCancel` is invoked.
|
|
534
|
+
*
|
|
535
|
+
* @param push - Produces the next event payload, optionally using the
|
|
536
|
+
* previous `fn` result.
|
|
537
|
+
* @param options - Interval in milliseconds and disconnect callback.
|
|
538
|
+
* @returns An SSE response, or a `500` response when no Bun server is set.
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```ts
|
|
542
|
+
* return res.event.eStream(
|
|
543
|
+
* () => ({ event: "heartbeat", data: { time: Date.now() } }),
|
|
544
|
+
* { interval: 5000 },
|
|
545
|
+
* );
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
eStream: (push: StreamPushFn, { interval, onCancel, }?: {
|
|
549
|
+
interval?: number;
|
|
550
|
+
onCancel?: () => void;
|
|
551
|
+
}) => Response;
|
|
552
|
+
/**
|
|
553
|
+
* Creates an SSE response with direct control over its stream controller.
|
|
554
|
+
*
|
|
555
|
+
* The producer is responsible for writing valid SSE frames (for example,
|
|
556
|
+
* `data: hello\\n\\n`) and closing or erroring the controller when done.
|
|
557
|
+
* `onCancel` runs if the client cancels or disconnects.
|
|
558
|
+
*
|
|
559
|
+
* @param producer - Writes to the response stream using its controller.
|
|
560
|
+
* @param onCancel - Optional cleanup callback for client cancellation.
|
|
561
|
+
* @returns An SSE response, or a `500` response when no Bun server is set.
|
|
562
|
+
*/
|
|
563
|
+
readableStream: (producer: (controller: ReadableStreamDefaultController<any>) => void | Promise<void>, onCancel?: () => void) => Response;
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
declare const METHODS: readonly ["GET", "POST", "PUT", "HEAD", "DELETE", "PATCH", "EVENT", "OPTIONS"];
|
|
568
|
+
type methodsKeys = (typeof METHODS)[number];
|
|
569
|
+
type handlerGuard = {
|
|
570
|
+
guards: any[];
|
|
571
|
+
handler: Function;
|
|
572
|
+
};
|
|
573
|
+
type methodGuards = Partial<Record<methodsKeys, handlerGuard>>;
|
|
574
|
+
declare class Methods {
|
|
575
|
+
[key: string]: any;
|
|
576
|
+
/**
|
|
577
|
+
* The GET method requests a representation of the specified resource.
|
|
578
|
+
* Requests using GET should only retrieve data.
|
|
579
|
+
*/
|
|
580
|
+
get?({ req, res }: ctx): Promise<Response> | Response;
|
|
581
|
+
/**
|
|
582
|
+
* The POST method is used to submit an entity to the specified resource,
|
|
583
|
+
* often causing a change in state or side effects on the server.
|
|
584
|
+
*/
|
|
585
|
+
post?({ req, res }: ctx): Promise<Response> | Response;
|
|
586
|
+
/**
|
|
587
|
+
* The PUT method replaces all current representations of the target
|
|
588
|
+
* resource with the request payload.
|
|
589
|
+
*/
|
|
590
|
+
put?({ req, res }: ctx): Promise<Response> | Response;
|
|
591
|
+
/**
|
|
592
|
+
* The HEAD method asks for a response identical to that of a GET request,
|
|
593
|
+
* but without the response body.
|
|
594
|
+
*/
|
|
595
|
+
head?({ req, res }: ctx): Promise<Response> | Response;
|
|
596
|
+
/**
|
|
597
|
+
* The DELETE method deletes the specified resource.
|
|
598
|
+
*/
|
|
599
|
+
delete?({ req, res }: ctx): Promise<Response> | Response;
|
|
600
|
+
/**
|
|
601
|
+
* The OPTIONS method is used to describe the communication options
|
|
602
|
+
* for the target resource (essential for CORS preflight).
|
|
603
|
+
*/
|
|
604
|
+
options({ res, methods }: ctx): Response;
|
|
605
|
+
/**
|
|
606
|
+
* The PATCH method is used to apply partial modifications to a resource.
|
|
607
|
+
*/
|
|
608
|
+
patch?({ req, res }: ctx): Promise<Response> | Response;
|
|
609
|
+
/**
|
|
610
|
+
* Specialized handler for Server-Sent Events (SSE).
|
|
611
|
+
* Used for real-time, uni-directional streaming from server to client.
|
|
612
|
+
*/
|
|
613
|
+
event?({ req, res }: ctx): Promise<Response> | Response;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
type TopicPublishStatus = "sent" | "backpressured" | "dropped" | "oversize";
|
|
617
|
+
interface TopicPublishResult {
|
|
618
|
+
topic: string;
|
|
619
|
+
status: TopicPublishStatus;
|
|
620
|
+
}
|
|
621
|
+
declare class subManager {
|
|
622
|
+
private ws;
|
|
115
623
|
id: string;
|
|
116
|
-
|
|
624
|
+
constructor(ws: ServerWebSocket<any>, nickname?: string);
|
|
625
|
+
subscribe(topic: string): void;
|
|
626
|
+
unsubscribe(topic: string): void;
|
|
627
|
+
cleanup(): void;
|
|
628
|
+
unregister(): void;
|
|
629
|
+
setAdmin(topic: string): void;
|
|
630
|
+
isAdmin(topic: string): boolean;
|
|
631
|
+
isSubscribed(topic: string): boolean;
|
|
632
|
+
setTopicConfig(topic: string, config?: WssConfig): void;
|
|
633
|
+
/** Publishes to unique topics and returns Bun's outcome for each topic. */
|
|
634
|
+
broadcast(topics: string[], data: any): TopicPublishResult[];
|
|
635
|
+
}
|
|
636
|
+
declare class WssManager {
|
|
637
|
+
private connections;
|
|
638
|
+
private topicConfigs;
|
|
639
|
+
private topicRegistry;
|
|
640
|
+
private memberTopics;
|
|
641
|
+
private roomAdmins;
|
|
642
|
+
private defaultTopicConfig;
|
|
643
|
+
/** 1. Lifecycle: Register/Unregister Connections */
|
|
644
|
+
register(ws: ServerWebSocket<any>, nickname?: string): string;
|
|
645
|
+
getMemberDetails(topic: string): {
|
|
646
|
+
id: string;
|
|
647
|
+
userId: any;
|
|
648
|
+
nickname: any;
|
|
649
|
+
}[];
|
|
650
|
+
/** Get all topics a specific user is currently in */
|
|
651
|
+
getUserTopics(id: string): string[];
|
|
652
|
+
get(topic: string): {
|
|
653
|
+
id: string;
|
|
654
|
+
userId: any;
|
|
655
|
+
nickname: any;
|
|
656
|
+
}[];
|
|
657
|
+
unregister(id: string): void;
|
|
658
|
+
/** 2. Subscription Management */
|
|
659
|
+
subscribe(id: string, topic: string): void;
|
|
660
|
+
isSubscribed(id: string, topic: string): boolean;
|
|
661
|
+
unsubscribe(id: string, topic: string): void;
|
|
662
|
+
/** 3. Admin & Role Management */
|
|
663
|
+
setAdmin(id: string, topic: string): void;
|
|
664
|
+
isAdmin(id: string, topic: string): boolean;
|
|
665
|
+
/** 4. Security & Config Helpers */
|
|
666
|
+
isPayloadTooLarge(topic: string, byteLength: number): boolean;
|
|
667
|
+
/** Helper to get the correct config for any topic */
|
|
668
|
+
private getConfigForTopic;
|
|
669
|
+
setTopicConfig(topic: string, config?: WssConfig): void;
|
|
670
|
+
/** Broadcast to an array of topics */
|
|
671
|
+
/**
|
|
672
|
+
* Publishes an encoded payload to each unique topic within that topic's
|
|
673
|
+
* configured byte limit. Bun's `-1` result is reported as backpressured,
|
|
674
|
+
* `0` as dropped, and a positive result as sent.
|
|
675
|
+
*/
|
|
676
|
+
broadcastToTopics(ws: ServerWebSocket<any>, topics: string[], data: unknown): TopicPublishResult[];
|
|
677
|
+
/** Ensures all topics for a client are cleaned up on disconnect */
|
|
678
|
+
cleanup(id: string): void;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
declare const WSSMAN: WssManager;
|
|
682
|
+
interface WssConfig {
|
|
683
|
+
maxClients?: number;
|
|
684
|
+
maxPayloadSize?: number;
|
|
685
|
+
}
|
|
686
|
+
/** Fixed-window incoming message limit applied independently to each socket. */
|
|
687
|
+
interface WssMessageRateLimit {
|
|
688
|
+
/** Maximum messages accepted from each connection during one window. */
|
|
117
689
|
max: number;
|
|
118
|
-
|
|
119
|
-
|
|
690
|
+
/** Fixed-window duration in milliseconds. */
|
|
691
|
+
windowMs: number;
|
|
692
|
+
}
|
|
693
|
+
type wssMessage<T extends Record<string, any> = Record<string, any>> = {
|
|
694
|
+
text: string;
|
|
695
|
+
json: T;
|
|
696
|
+
topic?: string | undefined;
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
declare class Websocket<T extends Record<string, any> = Record<string, any>> {
|
|
700
|
+
ws: ServerWebSocket<{}>;
|
|
701
|
+
manager: subManager;
|
|
702
|
+
/** Data populated by WebSocket route guards before the connection upgrades. */
|
|
703
|
+
contextData: Record<string, any>;
|
|
704
|
+
data: T;
|
|
705
|
+
constructor();
|
|
120
706
|
open(): Promise<void> | void;
|
|
121
|
-
message(
|
|
707
|
+
message({ text, json, topic }: wssMessage): Promise<void> | void;
|
|
708
|
+
/** Called when Bun has drained buffered outbound data for this connection. */
|
|
709
|
+
drain(): Promise<void> | void;
|
|
122
710
|
close(code: number, reason: string): Promise<void> | void;
|
|
123
|
-
set send(message: string | Bun.BufferSource
|
|
124
|
-
get role(): "maker" | "joiner" | "god" | undefined;
|
|
711
|
+
set send(message: string | Bun.BufferSource);
|
|
125
712
|
}
|
|
126
713
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
714
|
+
/**
|
|
715
|
+
* Router entry
|
|
716
|
+
* @param basePath - /url/:hello
|
|
717
|
+
* @returns
|
|
718
|
+
*/
|
|
719
|
+
declare function route(basePath?: string): <TTarget extends abstract new (...args: any[]) => Methods>(target: TTarget, context: ClassDecoratorContext<any>) => void | TTarget;
|
|
720
|
+
/**
|
|
721
|
+
* Router entry
|
|
722
|
+
* @param basePath - /url/:hello
|
|
723
|
+
* @returns
|
|
724
|
+
*/
|
|
725
|
+
declare function wss(basePath?: string): <TTarget extends abstract new (...args: any[]) => Websocket<Record<string, any>>>(target: TTarget, context: ClassDecoratorContext<any>) => void | TTarget;
|
|
726
|
+
|
|
727
|
+
type GuardFactoryHandler<TOptions = void, ExtraCfg = Record<string, any>> = (ctx: ctx, next: () => Promise<Response> | Response, options: TOptions, Config: ErrorConfig & ExtraCfg) => Promise<Response>;
|
|
728
|
+
type GuardConfig = ErrorConfig & {
|
|
729
|
+
id?: string | undefined;
|
|
730
|
+
};
|
|
731
|
+
type BaseConfig = Omit<ErrorConfig, "code">;
|
|
732
|
+
type GuardReturnType = {
|
|
733
|
+
(ctx: ctx, next: () => Promise<Response> | Response): Promise<Response>;
|
|
734
|
+
_middlewareId: string;
|
|
735
|
+
id: string;
|
|
736
|
+
};
|
|
737
|
+
declare function createGuard<TOptions = void, ExtraCfg = Record<string, unknown>>(handler: GuardFactoryHandler<TOptions, ExtraCfg>, defaultConfig?: GuardConfig): (options?: TOptions, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
738
|
+
|
|
739
|
+
type Class = new (...args: any[]) => any;
|
|
740
|
+
interface WssBaseController {
|
|
741
|
+
open?(ws: any): void;
|
|
742
|
+
message(ws: any, message: string | Uint8Array): void;
|
|
743
|
+
close?(ws: any, code: number, reason: string): void;
|
|
130
744
|
}
|
|
131
|
-
interface
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
745
|
+
interface WssRouteConfig {
|
|
746
|
+
path: string;
|
|
747
|
+
regex: RegExp;
|
|
748
|
+
paramNames: string[];
|
|
749
|
+
instance: typeof Websocket<{}>;
|
|
750
|
+
guards: GuardReturnType[];
|
|
751
|
+
}
|
|
752
|
+
interface HttpRouteConfig {
|
|
753
|
+
path: string;
|
|
754
|
+
regex: RegExp;
|
|
755
|
+
controller: Class;
|
|
756
|
+
methods: methodGuards;
|
|
757
|
+
methodKeys: string[];
|
|
758
|
+
paramNames: string[];
|
|
759
|
+
}
|
|
760
|
+
interface HttpRouteMatch extends Partial<handlerGuard> {
|
|
761
|
+
controller?: Class;
|
|
762
|
+
methodKeys?: string[];
|
|
763
|
+
params: Record<string, string>;
|
|
764
|
+
}
|
|
765
|
+
declare class RouterManager {
|
|
766
|
+
protected globalBasePath: string;
|
|
767
|
+
httpRoutes: HttpRouteConfig[];
|
|
768
|
+
wssRoutes: WssRouteConfig[];
|
|
769
|
+
protected globalGuards: any[];
|
|
770
|
+
private registeredSignatures;
|
|
771
|
+
constructor(globalBasePath?: string);
|
|
772
|
+
use(...guards: GuardReturnType[]): void;
|
|
773
|
+
private compiler;
|
|
774
|
+
private checkSignature;
|
|
775
|
+
registerWSS(...ControllerClass: (typeof Websocket<{}>)[]): void;
|
|
776
|
+
register(...ControllerClass: (typeof Methods)[]): void;
|
|
777
|
+
protected matchWSS(url: string): Partial<WssRouteConfig & {
|
|
778
|
+
params: HttpRouteMatch["params"];
|
|
779
|
+
}>;
|
|
780
|
+
protected match(method: methodsKeys, url: string): HttpRouteMatch;
|
|
781
|
+
printRoutes(): void;
|
|
782
|
+
/** Returns registered HTTP paths, including the base path, with parameter colons removed. */
|
|
783
|
+
getPaths(): string[];
|
|
156
784
|
}
|
|
157
785
|
|
|
158
786
|
interface dev {
|
|
@@ -161,26 +789,752 @@ interface dev {
|
|
|
161
789
|
method?: string;
|
|
162
790
|
port?: number;
|
|
163
791
|
}
|
|
792
|
+
interface serverOptions {
|
|
793
|
+
server: Partial<Bun.Serve.Options<any, never>> & dev & {
|
|
794
|
+
fn?: (port: number) => void;
|
|
795
|
+
};
|
|
796
|
+
wss?: RossaWebSocketOptions | undefined;
|
|
797
|
+
}
|
|
798
|
+
type RossaWebSocketOptions = Partial<WebSocketHandler<any>> & {
|
|
799
|
+
/** Optional fixed-window incoming message limit applied separately per socket. */
|
|
800
|
+
messageRateLimit?: WssMessageRateLimit;
|
|
801
|
+
};
|
|
802
|
+
interface RossaOptions {
|
|
803
|
+
basePath?: string;
|
|
804
|
+
clientPath?: string;
|
|
805
|
+
dirPath?: string;
|
|
806
|
+
/** Additional static-file extensions to recognize, with or without a leading dot. */
|
|
807
|
+
fileExtensions?: string[];
|
|
808
|
+
logError?: boolean | undefined;
|
|
809
|
+
Encoding?: ContentEncodingType;
|
|
810
|
+
}
|
|
811
|
+
declare class Rossa extends RouterManager {
|
|
812
|
+
protected options: Omit<Required<RossaOptions>, "fileExtensions">;
|
|
813
|
+
fileServer: StaticFileServer;
|
|
814
|
+
private clientRoot;
|
|
815
|
+
constructor(options?: RossaOptions);
|
|
816
|
+
private get getClientRoot();
|
|
817
|
+
private pipeline;
|
|
818
|
+
private processRouter;
|
|
819
|
+
private processWSS;
|
|
820
|
+
test(req: Request, encoding?: ContentEncodingType): Promise<Response>;
|
|
821
|
+
serve(server?: serverOptions["server"], wss?: serverOptions["wss"]): Bun.Server<undefined>;
|
|
822
|
+
protected errorHandler(res: res, error: any): Response;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
type ColumnType = "text" | "integer" | "bigint" | "boolean" | "json" | "timestamp" | "serial" | "numeric";
|
|
826
|
+
/** Logical column definition interpreted by the selected database dialect. */
|
|
827
|
+
declare class Column {
|
|
828
|
+
readonly type: ColumnType;
|
|
829
|
+
readonly precision?: number | undefined;
|
|
830
|
+
readonly scale?: number | undefined;
|
|
831
|
+
primaryKey: boolean;
|
|
832
|
+
required: boolean;
|
|
833
|
+
isUnique: boolean;
|
|
834
|
+
hasDefault: boolean;
|
|
835
|
+
defaultIsCurrentTimestamp: boolean;
|
|
836
|
+
defaultValue: string | number | boolean | null;
|
|
837
|
+
constructor(type: ColumnType, precision?: number | undefined, scale?: number | undefined);
|
|
838
|
+
get primary(): this;
|
|
839
|
+
get notNull(): this;
|
|
840
|
+
get unique(): this;
|
|
841
|
+
get defaultNow(): this;
|
|
842
|
+
default(value: string | number | boolean): this;
|
|
843
|
+
}
|
|
844
|
+
declare const t: {
|
|
845
|
+
text: () => Column;
|
|
846
|
+
int: () => Column;
|
|
847
|
+
bigint: () => Column;
|
|
848
|
+
boolean: () => Column;
|
|
849
|
+
json: () => Column;
|
|
850
|
+
timestamp: () => Column;
|
|
851
|
+
serial: () => Column;
|
|
852
|
+
numeric: (precision?: number, scale?: number) => Column;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
declare class DatabaseError extends Error {
|
|
856
|
+
constructor(message: string);
|
|
857
|
+
}
|
|
858
|
+
declare class UniqueConstraintError extends DatabaseError {
|
|
859
|
+
constructor(message: string);
|
|
860
|
+
}
|
|
861
|
+
declare class ForeignKeyError extends DatabaseError {
|
|
862
|
+
constructor(message?: string);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
type DbDialectName = "sqlite" | "postgres" | "mysql" | "mariadb";
|
|
866
|
+
interface TableStats {
|
|
867
|
+
rowCount: number;
|
|
868
|
+
diskSize: string;
|
|
869
|
+
indexCount: number;
|
|
870
|
+
}
|
|
871
|
+
/** Operations whose SQL differs between database engines. */
|
|
872
|
+
interface DbDialectAdapter {
|
|
873
|
+
readonly name: DbDialectName;
|
|
874
|
+
quoteIdentifier(name: string): string;
|
|
875
|
+
quoteTable(name: string): string;
|
|
876
|
+
normalizeColumnName(name: string): string;
|
|
877
|
+
buildColumn(name: string, column: Column): string;
|
|
878
|
+
buildColumnType(column: Column): string;
|
|
879
|
+
normalizeOperator(operator: string): string;
|
|
880
|
+
version(db: SQL): Promise<string>;
|
|
881
|
+
createTable(db: SQL, schema: Schema<any>): Promise<void>;
|
|
882
|
+
getColumns(db: SQL, schema: Schema<any>): Promise<string[]>;
|
|
883
|
+
addColumn(db: SQL, schema: Schema<any>, name: string, type: string): Promise<void>;
|
|
884
|
+
dropColumn(db: SQL, schema: Schema<any>, name: string): Promise<void>;
|
|
885
|
+
upsert<T extends Record<string, any>>(db: SQL, schema: Schema<T>, data: T, conflictColumn: keyof T): Promise<T | undefined>;
|
|
886
|
+
listTables(db: SQL): Promise<string[]>;
|
|
887
|
+
dropTable(db: SQL, schema: Schema<any>): Promise<void>;
|
|
888
|
+
truncateTable(db: SQL, schema: Schema<any>): Promise<void>;
|
|
889
|
+
getTableStats(db: SQL, schema: Schema<any>): Promise<TableStats>;
|
|
890
|
+
getTableIndices(db: SQL, schema: Schema<any>): Promise<any[]>;
|
|
891
|
+
getTableSchema(db: SQL, schema: Schema<any>): Promise<any[]>;
|
|
892
|
+
getTableData(db: SQL, schema: Schema<any>, limit: number, offset: number): Promise<any[]>;
|
|
893
|
+
optimize(db: SQL, schema: Schema<any>): Promise<void>;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
declare class Schema<T extends Record<string, any>> {
|
|
897
|
+
readonly table: string;
|
|
898
|
+
private readonly definitions;
|
|
899
|
+
readonly dialect: DbDialectAdapter;
|
|
900
|
+
constructor(table: string, definitions: Record<keyof T, Column>, dialect: DbDialectAdapter);
|
|
901
|
+
entries(): Array<[string, Column]>;
|
|
902
|
+
withDialect(dialect: DbDialectAdapter): Schema<T>;
|
|
903
|
+
createSQL(adapter?: DbDialectAdapter): string;
|
|
904
|
+
columnDefinitions(adapter?: DbDialectAdapter): Record<string, string>;
|
|
905
|
+
get columns(): {
|
|
906
|
+
[K in keyof T]: string;
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/** Shared inspection API; SQL-specific operations live in the dialect adapter. */
|
|
911
|
+
declare class DbInspector<T extends Record<string, any>> {
|
|
912
|
+
private readonly db;
|
|
913
|
+
readonly schema: Schema<T>;
|
|
914
|
+
constructor(db: SQL, schema: Schema<T>);
|
|
915
|
+
listTables(): Promise<string[]>;
|
|
916
|
+
dropTable(): Promise<void>;
|
|
917
|
+
truncateTable(): Promise<void>;
|
|
918
|
+
getTableStats(): Promise<TableStats>;
|
|
919
|
+
getTableIndices(): Promise<any[]>;
|
|
920
|
+
getTableSchema(): Promise<any[]>;
|
|
921
|
+
getTableData(limit?: number, offset?: number): Promise<any[]>;
|
|
922
|
+
optimize(): Promise<void>;
|
|
923
|
+
static sqlite<T extends Record<string, any>>(db: SQL, schema: Schema<T>): DbInspector<T>;
|
|
924
|
+
static postgres<T extends Record<string, any>>(db: SQL, schema: Schema<T>): DbInspector<T>;
|
|
925
|
+
}
|
|
164
926
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
927
|
+
type Where<T> = {
|
|
928
|
+
[K in keyof T]?: T[K] | {
|
|
929
|
+
operator: string;
|
|
930
|
+
value: unknown;
|
|
931
|
+
};
|
|
932
|
+
};
|
|
933
|
+
/** Shared CRUD repository. Dialect-specific statements are delegated to its adapter. */
|
|
934
|
+
declare class DbRepository<T extends Record<string, any>> {
|
|
935
|
+
private readonly db;
|
|
936
|
+
readonly schema: Schema<T>;
|
|
937
|
+
constructor(db: SQL, schema: Schema<T>);
|
|
938
|
+
private get dialect();
|
|
939
|
+
get inspect(): DbInspector<T>;
|
|
940
|
+
withContext(context: SQL): DbRepository<T>;
|
|
941
|
+
create(): Promise<void>;
|
|
942
|
+
testConnection(): Promise<string>;
|
|
943
|
+
syncColumns(allowDrop?: boolean): Promise<void>;
|
|
944
|
+
private identifier;
|
|
945
|
+
private get table();
|
|
946
|
+
private joinSql;
|
|
947
|
+
private buildWhere;
|
|
948
|
+
insert(data: T): Promise<T | undefined>;
|
|
949
|
+
upsert(data: T, conflictColumn: keyof T): Promise<T | undefined>;
|
|
950
|
+
find(where: Where<T>): Promise<T | null>;
|
|
951
|
+
findAll(where?: Where<T>): Promise<T[]>;
|
|
952
|
+
count(where?: Where<T>): Promise<number>;
|
|
953
|
+
exists(where: Where<T>): Promise<boolean>;
|
|
954
|
+
paginate(page: number, limit: number, where?: Where<T>): Promise<T[]>;
|
|
955
|
+
update(where: Where<T>, data: Partial<T>): Promise<T[]>;
|
|
956
|
+
delete(where: Where<T>): Promise<T[]>;
|
|
957
|
+
transaction<R>(callback: (repository: DbRepository<T>, tx: SQL) => Promise<R>): Promise<R>;
|
|
958
|
+
private handleDbError;
|
|
170
959
|
}
|
|
171
|
-
|
|
172
|
-
declare
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
960
|
+
|
|
961
|
+
declare function getDialect(name: DbDialectName): DbDialectAdapter;
|
|
962
|
+
|
|
963
|
+
declare const postgresDialect: DbDialectAdapter;
|
|
964
|
+
|
|
965
|
+
declare const sqliteDialect: DbDialectAdapter;
|
|
966
|
+
|
|
967
|
+
declare const mysqlDialect: DbDialectAdapter;
|
|
968
|
+
declare const mariadbDialect: DbDialectAdapter;
|
|
969
|
+
|
|
970
|
+
declare function use(...middlewares: GuardReturnType[]): <TTarget, TCtx extends ClassDecoratorContext<any> | ClassMethodDecoratorContext<any, any>>(target: TTarget, context: TCtx) => void | TTarget;
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* Creates a guard that validates a bearer token from the `Authorization` header.
|
|
974
|
+
*
|
|
975
|
+
* @param validator - Checks the request context and extracted bearer token.
|
|
976
|
+
* @returns A guard factory that accepts a validator and optional error configuration.
|
|
977
|
+
*/
|
|
978
|
+
declare const authBearer: (options?: ((ctx: ctx, token?: string) => Promise<boolean> | boolean) | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
979
|
+
/**
|
|
980
|
+
* Creates a guard that validates an API key from the `x-api-key` header.
|
|
981
|
+
*
|
|
982
|
+
* @param validator - Checks the request context and extracted API key.
|
|
983
|
+
* @returns A guard factory that accepts a validator and optional error configuration.
|
|
984
|
+
*/
|
|
985
|
+
declare const apiKey: (options?: ((ctx: ctx, key?: string) => Promise<boolean> | boolean) | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
986
|
+
/**
|
|
987
|
+
* Creates a guard that validates one or more request headers.
|
|
988
|
+
*
|
|
989
|
+
* Each entry in the validator map uses a header name as its key and a callback
|
|
990
|
+
* that validates that header's value.
|
|
991
|
+
*
|
|
992
|
+
* @param validator - Map of header names to validation callbacks.
|
|
993
|
+
* @returns A guard factory that accepts validators and optional error configuration.
|
|
994
|
+
*/
|
|
995
|
+
declare const auth: (options?: Record<string, (ctx: ctx, keyValue?: string) => Promise<boolean> | boolean> | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
996
|
+
/**
|
|
997
|
+
* Checks whether the authenticated request may access a route.
|
|
998
|
+
*
|
|
999
|
+
* Use this after an authentication guard has established the identity in
|
|
1000
|
+
* `ctx`, then check roles, ownership, scopes, or other application policy in
|
|
1001
|
+
* the callback. A failed check returns HTTP 403 by default.
|
|
1002
|
+
*
|
|
1003
|
+
* @param canAccess - Synchronous or asynchronous authorization check.
|
|
1004
|
+
* @returns A guard factory that accepts the check and optional error config.
|
|
1005
|
+
*/
|
|
1006
|
+
declare const authorize: (options?: ((ctx: ctx) => Promise<boolean> | boolean) | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1007
|
+
|
|
1008
|
+
interface CacheOptions {
|
|
1009
|
+
ttlMs: number;
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Caches public, successful GET responses by their full URL for the configured
|
|
1013
|
+
* lifetime. Requests carrying cookies or authorization headers bypass the cache.
|
|
1014
|
+
*/
|
|
1015
|
+
declare const smartCache: (options?: CacheOptions | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* Rule parameter: a single MIME type string, an array, or a custom validator function.
|
|
1019
|
+
* @example 'application/json'
|
|
1020
|
+
* @example ['application/json', 'multipart/form-data']
|
|
1021
|
+
* @example (ct, ctx) => ct?.startsWith('application/') ?? false
|
|
1022
|
+
*/
|
|
1023
|
+
type ContentTypeRules = string | string[] | ((contentType: string | null, ctx: ctx) => boolean);
|
|
1024
|
+
/**
|
|
1025
|
+
* `contentType` — validates that the request `Content-Type` matches allowed types.
|
|
1026
|
+
*
|
|
1027
|
+
* @example
|
|
1028
|
+
* @Use(contentType('application/json'))
|
|
1029
|
+
* @Post('/upload')
|
|
1030
|
+
* upload(ctx: RossaContext) { ... }
|
|
1031
|
+
*/
|
|
1032
|
+
declare const contentType: (options?: ContentTypeRules | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Requires the named cookie to be present on the request.
|
|
1036
|
+
*
|
|
1037
|
+
* @param name - Cookie name to look up in the request's Cookie header.
|
|
1038
|
+
* @returns A guard factory that continues when the cookie exists.
|
|
1039
|
+
*/
|
|
1040
|
+
declare const cookies: (options?: string | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1041
|
+
|
|
1042
|
+
interface CorsOptions {
|
|
1043
|
+
/**
|
|
1044
|
+
* Allowed origin(s). Can be "*", exact origin URLs, or an array of them,
|
|
1045
|
+
* or a custom validator function.
|
|
1046
|
+
* @default "*"
|
|
1047
|
+
*/
|
|
1048
|
+
origin?: string | string[] | ((incomingOrigin: string | null, ctx: ctx) => string | boolean);
|
|
1049
|
+
/**
|
|
1050
|
+
* Headers allowed in requests (Access-Control-Allow-Headers).
|
|
1051
|
+
* @default "*"
|
|
1052
|
+
*/
|
|
1053
|
+
allowHeaders?: string | string[];
|
|
1054
|
+
/** Methods advertised for browser preflight requests. */
|
|
1055
|
+
methods?: string | string[];
|
|
1056
|
+
/**
|
|
1057
|
+
* Headers exposed to the browser client (Access-Control-Expose-Headers).
|
|
1058
|
+
*/
|
|
1059
|
+
exposeHeaders?: string | string[];
|
|
1060
|
+
/**
|
|
1061
|
+
* Whether to allow credentials like cookies or Authorization headers.
|
|
1062
|
+
* @default false
|
|
1063
|
+
*/
|
|
1064
|
+
credentials?: boolean;
|
|
1065
|
+
/**
|
|
1066
|
+
* Preflight cache duration in seconds (Access-Control-Max-Age).
|
|
1067
|
+
* @default 86400 (24 hours)
|
|
1068
|
+
*/
|
|
1069
|
+
maxAge?: number | string;
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Sets CORS response headers and rejects requests whose origin is not allowed.
|
|
1073
|
+
*
|
|
1074
|
+
* @param options - Allowed origins, headers, credentials, and preflight caching.
|
|
1075
|
+
* @returns A guard factory that accepts CORS options and optional error config.
|
|
1076
|
+
*/
|
|
1077
|
+
declare const cors: (options?: CorsOptions | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1078
|
+
|
|
1079
|
+
interface CsrfOptions {
|
|
1080
|
+
headerName?: string;
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Checks a CSRF header against the `csrf_token` cookie on state-changing requests.
|
|
1084
|
+
*
|
|
1085
|
+
* @param options - Optional name of the request header containing the token.
|
|
1086
|
+
* @returns A guard factory that accepts CSRF options and optional error config.
|
|
1087
|
+
*/
|
|
1088
|
+
declare const csrf: (options?: CsrfOptions | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1089
|
+
|
|
1090
|
+
interface ErrorGuardOptions {
|
|
1091
|
+
/** Log caught errors. Defaults to false. */
|
|
1092
|
+
logErrors?: boolean;
|
|
1093
|
+
/** Safe message returned for unexpected errors. */
|
|
1094
|
+
message?: string;
|
|
1095
|
+
/** Custom response handler. */
|
|
1096
|
+
onError?: (error: unknown, ctx: ctx) => Response | Promise<Response>;
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Catches errors thrown by downstream guards or handlers and returns a safe
|
|
1100
|
+
* 500 response unless a custom handler is provided. Place it before the guards
|
|
1101
|
+
* and handlers whose errors it should catch.
|
|
1102
|
+
*
|
|
1103
|
+
* @param options - Logging, public message, and custom error response behavior.
|
|
1104
|
+
* @returns A guard factory that wraps downstream execution with error handling.
|
|
1105
|
+
*/
|
|
1106
|
+
declare const errorHandler: (options?: ErrorGuardOptions | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1107
|
+
|
|
1108
|
+
type HeaderValidationRules = Record<string, (ctx: ctx, headName: string, value: string) => boolean>;
|
|
1109
|
+
/**
|
|
1110
|
+
* Requires named headers or validates header values with caller-provided rules.
|
|
1111
|
+
*
|
|
1112
|
+
* @param rules - Header names to require, or a map of names to validators.
|
|
1113
|
+
* @returns A guard factory that accepts header rules and optional error config.
|
|
1114
|
+
*/
|
|
1115
|
+
declare const header: (options?: string | string[] | HeaderValidationRules | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1116
|
+
|
|
1117
|
+
type IpOptions = {
|
|
1118
|
+
whitelist?: string[];
|
|
1119
|
+
blacklist?: string[];
|
|
1120
|
+
};
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* Allows or blocks requests based on configured client IP allow and deny lists.
|
|
1124
|
+
*
|
|
1125
|
+
* @param options - IP allowlist and blocklist rules.
|
|
1126
|
+
* @returns A guard factory that accepts IP rules and optional error config.
|
|
1127
|
+
*/
|
|
1128
|
+
declare const ipFilter: (options?: IpOptions | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1129
|
+
|
|
1130
|
+
declare class SchemaBuilder<T extends Record<string, any>> {
|
|
1131
|
+
private schema;
|
|
1132
|
+
private rules;
|
|
1133
|
+
private defaults;
|
|
1134
|
+
string(key: keyof T, defaultValue?: T[keyof T]): this;
|
|
1135
|
+
number(key: keyof T, defaultValue?: T[keyof T]): this;
|
|
1136
|
+
boolean(key: keyof T, defaultValue?: T[keyof T]): this;
|
|
1137
|
+
min(key: keyof T, val: number): this;
|
|
1138
|
+
max(key: keyof T, val: number): this;
|
|
1139
|
+
email(key: keyof T): this;
|
|
1140
|
+
private addRule;
|
|
1141
|
+
private noBool;
|
|
1142
|
+
private noKey;
|
|
1143
|
+
validate(data: any): {
|
|
1144
|
+
errors: string[];
|
|
1145
|
+
processedData: any;
|
|
1146
|
+
};
|
|
1147
|
+
private validateObject;
|
|
176
1148
|
}
|
|
1149
|
+
declare function z<T extends Record<string, any>>(): SchemaBuilder<T>;
|
|
177
1150
|
|
|
178
|
-
declare
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
1151
|
+
declare const DEFAULT_MAX_SIZE: number;
|
|
1152
|
+
/**
|
|
1153
|
+
* Parses and validates JSON request bodies for POST, PUT, and PATCH requests.
|
|
1154
|
+
* The validated value is stored on the request as `_json`.
|
|
1155
|
+
*
|
|
1156
|
+
* @param schema - Schema used to validate the parsed JSON object.
|
|
1157
|
+
* @returns A guard factory that accepts a schema and optional error config.
|
|
1158
|
+
*/
|
|
1159
|
+
declare const json: (options?: SchemaBuilder<any> | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1160
|
+
interface RequireKeysOptions {
|
|
1161
|
+
keys: string[];
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Requires the JSON request body to contain each listed key and stores the
|
|
1165
|
+
* parsed body in `ctx.body`.
|
|
1166
|
+
*
|
|
1167
|
+
* @param keys - Required top-level body keys.
|
|
1168
|
+
* @returns A guard factory that accepts required keys and optional error config.
|
|
1169
|
+
*/
|
|
1170
|
+
declare const keys: (options?: string[] | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1171
|
+
|
|
1172
|
+
type JwtPayload<T> = T & {
|
|
1173
|
+
iat: number;
|
|
1174
|
+
exp: number;
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
/**
|
|
1178
|
+
* Persistence contract for refresh tokens.
|
|
1179
|
+
*
|
|
1180
|
+
* Implement this interface with any database, key-value store, or external
|
|
1181
|
+
* persistence service. `consume` must atomically remove a token and return
|
|
1182
|
+
* `true` only for the caller that removed it, preventing concurrent reuse.
|
|
1183
|
+
*/
|
|
1184
|
+
interface JwtRefreshTokenStore {
|
|
1185
|
+
/** Initialize the backing store or its schema when needed. */
|
|
1186
|
+
initialize?(): Promise<void>;
|
|
1187
|
+
/** Persist a refresh token until its Unix expiration time in milliseconds. */
|
|
1188
|
+
save(token: string, expiresAt: number): Promise<void>;
|
|
1189
|
+
/** Atomically remove a stored refresh token and report whether it existed. */
|
|
1190
|
+
consume(token: string): Promise<boolean>;
|
|
1191
|
+
}
|
|
1192
|
+
interface JWTConfig {
|
|
1193
|
+
/** Refresh token lifetime in days. Defaults to 7. */
|
|
1194
|
+
refreshValidity?: number;
|
|
1195
|
+
/** Access token lifetime in minutes. Defaults to 15. */
|
|
1196
|
+
tokenValidity?: number;
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Signs access tokens and manages one-time refresh tokens through an injected
|
|
1200
|
+
* persistence adapter.
|
|
1201
|
+
*
|
|
1202
|
+
* @typeParam T - Shape of the claims carried by the access and refresh tokens.
|
|
1203
|
+
*/
|
|
1204
|
+
declare class JWTAuthService<T extends Record<string, any> = {}> {
|
|
1205
|
+
private readonly refreshTokens;
|
|
1206
|
+
readonly config: Required<JWTConfig>;
|
|
1207
|
+
private readonly engine;
|
|
1208
|
+
constructor(refreshTokens: JwtRefreshTokenStore, secret: string, config?: JWTConfig);
|
|
1209
|
+
/** Initialize the configured persistence adapter, if it needs initialization. */
|
|
1210
|
+
init(): Promise<void>;
|
|
1211
|
+
/** Sign an access token using the configured access-token lifetime. */
|
|
1212
|
+
sign(payload: T): string;
|
|
1213
|
+
/** Verify an access token and return its claims, or `null` if invalid. */
|
|
1214
|
+
verify(token: string): JwtPayload<T> | null;
|
|
1215
|
+
/**
|
|
1216
|
+
* Atomically consume a valid, stored refresh token.
|
|
1217
|
+
*
|
|
1218
|
+
* @returns The token claims when consumption succeeds; otherwise `null`.
|
|
1219
|
+
*/
|
|
1220
|
+
consume(token: string): Promise<JwtPayload<T> | null>;
|
|
1221
|
+
/** Issue a refresh token, persist it, and return it with a new access token. */
|
|
1222
|
+
issue(payload: T): Promise<{
|
|
1223
|
+
accessToken: string;
|
|
1224
|
+
refreshToken: string;
|
|
1225
|
+
}>;
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
/**
|
|
1229
|
+
* Verifies a Bearer access token and stores its decoded claims in `ctx.jwtData`.
|
|
1230
|
+
*
|
|
1231
|
+
* @param service - JWT service used to verify the access token.
|
|
1232
|
+
* @returns A guard factory that accepts a JWT service and optional error config.
|
|
1233
|
+
*/
|
|
1234
|
+
declare const jwtAuth: (options?: JWTAuthService<any> | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1235
|
+
/**
|
|
1236
|
+
* Consumes an `x-refresh-token`, issues a replacement token pair, and stores
|
|
1237
|
+
* the authenticated claims in `ctx.jwtData` and the new tokens in
|
|
1238
|
+
* `ctx.data.jwtTokens`.
|
|
1239
|
+
*
|
|
1240
|
+
* @param service - JWT service used to consume and issue tokens.
|
|
1241
|
+
* @returns A guard factory that accepts a JWT service and optional error config.
|
|
1242
|
+
*/
|
|
1243
|
+
declare const jwtRefresh: (options?: JWTAuthService<any> | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Logs the request method, path, timestamp, and optional label before continuing.
|
|
1247
|
+
*
|
|
1248
|
+
* @param label - Optional text included in the log entry.
|
|
1249
|
+
* @returns A guard factory that accepts a label and optional error config.
|
|
1250
|
+
*/
|
|
1251
|
+
declare const logger: (options?: void | string | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1252
|
+
type logFN = {
|
|
1253
|
+
ctx: ctx;
|
|
1254
|
+
res: Response;
|
|
1255
|
+
timestamp: string;
|
|
1256
|
+
method: string;
|
|
1257
|
+
url: string;
|
|
1258
|
+
};
|
|
1259
|
+
/**
|
|
1260
|
+
* Runs a formatter with request metadata and the downstream response, then logs
|
|
1261
|
+
* its returned value when truthy.
|
|
1262
|
+
*
|
|
1263
|
+
* @param formatter - Function that formats the request and response details.
|
|
1264
|
+
* @returns A guard factory that accepts a formatter and optional error config.
|
|
1265
|
+
*/
|
|
1266
|
+
declare const loggerFN: (options?: ((ff: logFN) => any) | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* Parses a multipart request and stores its fields and uploaded files in
|
|
1270
|
+
* `ctx.form`.
|
|
1271
|
+
*
|
|
1272
|
+
* @returns A guard factory that parses multipart form data before continuing.
|
|
1273
|
+
*/
|
|
1274
|
+
declare const multipart: (options?: void | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1275
|
+
|
|
1276
|
+
interface QueryValidationOptions<T extends Record<string, any>> {
|
|
1277
|
+
schema: SchemaBuilder<T>;
|
|
1278
|
+
}
|
|
1279
|
+
interface FormValidationOptions<T extends Record<string, any>> {
|
|
1280
|
+
schema: SchemaBuilder<T>;
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Validates and coerces URL query parameters against a schema, then stores the
|
|
1284
|
+
* result in `ctx.query`.
|
|
1285
|
+
*
|
|
1286
|
+
* @param schema - Schema used to validate and coerce query values.
|
|
1287
|
+
* @returns A guard factory that accepts the schema and optional error config.
|
|
1288
|
+
*/
|
|
1289
|
+
declare const validateQuery: (options?: SchemaBuilder<{}> | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1290
|
+
/**
|
|
1291
|
+
* Validates multipart or URL-encoded form fields against a schema and stores
|
|
1292
|
+
* the processed result in `ctx.form`.
|
|
1293
|
+
*
|
|
1294
|
+
* @param schema - Schema used to validate and coerce form values.
|
|
1295
|
+
* @returns A guard factory that accepts the schema and optional error config.
|
|
1296
|
+
*/
|
|
1297
|
+
declare const validateForm: (options?: SchemaBuilder<{}> | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1298
|
+
|
|
1299
|
+
interface RateLimitOptions {
|
|
1300
|
+
/** Maximum number of connections/requests allowed within the window. @default 100 */
|
|
1301
|
+
max?: number;
|
|
1302
|
+
/** Window duration in milliseconds. @default 60000 (1 minute) */
|
|
1303
|
+
windowMs?: number;
|
|
1304
|
+
/** Whether to attach X-RateLimit-* headers to responses. @default true */
|
|
1305
|
+
expose?: boolean;
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Limits requests by client IP, HTTP method, and URL path.
|
|
1309
|
+
*
|
|
1310
|
+
* @param options - Request limit, time window, and response-header settings.
|
|
1311
|
+
* @returns A guard factory that accepts rate-limit settings and optional error config.
|
|
1312
|
+
*/
|
|
1313
|
+
declare const rateLimit: (options?: RateLimitOptions | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1314
|
+
|
|
1315
|
+
interface SanitizeOptions {
|
|
1316
|
+
/** Custom string sanitizer. Defaults to escaping HTML-sensitive characters. */
|
|
1317
|
+
sanitizeString?: (value: string) => string;
|
|
1318
|
+
/** Whether to sanitize `ctx.query`. @default true */
|
|
1319
|
+
query?: boolean;
|
|
1320
|
+
/** Whether to sanitize `ctx.form`. @default true */
|
|
1321
|
+
form?: boolean;
|
|
1322
|
+
/** Whether to sanitize parsed JSON in `ctx.body` and `ctx.req._json`. @default true */
|
|
1323
|
+
body?: boolean;
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Escapes or custom-sanitizes string values in parsed request data before
|
|
1327
|
+
* handlers consume them. Continue to encode output for its final HTML context.
|
|
1328
|
+
*
|
|
1329
|
+
* @param options - Selects request data and the string sanitizer to apply.
|
|
1330
|
+
* @returns A guard factory that sanitizes selected context data.
|
|
1331
|
+
*/
|
|
1332
|
+
declare const sanitize: (options?: SanitizeOptions | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1333
|
+
|
|
1334
|
+
interface SecurityHeadersOptions {
|
|
1335
|
+
contentSecurityPolicy?: string | false;
|
|
1336
|
+
crossOriginEmbedderPolicy?: string | false;
|
|
1337
|
+
crossOriginOpenerPolicy?: string | false;
|
|
1338
|
+
crossOriginResourcePolicy?: string | false;
|
|
1339
|
+
hsts?: string | false;
|
|
1340
|
+
permissionsPolicy?: string | false;
|
|
1341
|
+
referrerPolicy?: string | false;
|
|
1342
|
+
xContentTypeOptions?: string | false;
|
|
1343
|
+
xFrameOptions?: string | false;
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Adds common security headers to downstream responses. CSP and HSTS are opt-in
|
|
1347
|
+
* because their correct values depend on the application and deployment.
|
|
1348
|
+
*
|
|
1349
|
+
* @param options - Header values to apply or disable.
|
|
1350
|
+
* @returns A guard factory that applies security headers to each response.
|
|
1351
|
+
*/
|
|
1352
|
+
declare const security: (options?: SecurityHeadersOptions | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1353
|
+
|
|
1354
|
+
declare class Signator {
|
|
1355
|
+
salt: string;
|
|
1356
|
+
private readonly key;
|
|
1357
|
+
constructor(salt: string);
|
|
1358
|
+
/**
|
|
1359
|
+
* Generates an HMAC SHA-256 signature, encoded cleanly for URLs.
|
|
1360
|
+
*/
|
|
1361
|
+
getSignature(val: string): string;
|
|
1362
|
+
/**
|
|
1363
|
+
* Attaches the signature to the value using the standard "." separator.
|
|
1364
|
+
* Format: payload.signature
|
|
1365
|
+
*/
|
|
1366
|
+
sign(val: string): string;
|
|
1367
|
+
/**
|
|
1368
|
+
* Verifies a signed string.
|
|
1369
|
+
* Returns the original value if valid, or null if tampered/invalid.
|
|
1370
|
+
*/
|
|
1371
|
+
unsign(signedVal: string): string | null;
|
|
1372
|
+
/**
|
|
1373
|
+
* Cryptographically secure comparison to prevent Timing Attacks.
|
|
1374
|
+
*/
|
|
1375
|
+
private verifySignature;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
declare class SidGenerator {
|
|
1379
|
+
protected signer: Signator;
|
|
1380
|
+
constructor(salt: string);
|
|
1381
|
+
/**
|
|
1382
|
+
* Generates a URL-safe, cryptographically secure, signed session ID.
|
|
1383
|
+
*/
|
|
1384
|
+
generate(len?: number): string;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
interface AuthConfig {
|
|
1388
|
+
COOKIE_NAME?: string;
|
|
1389
|
+
COOKIE_LIFETIME?: number;
|
|
1390
|
+
COOKIE_DOMAIN?: string | undefined;
|
|
1391
|
+
COOKIE_PATH?: string;
|
|
1392
|
+
COOKIE_HTTPONLY?: boolean;
|
|
1393
|
+
COOKIE_SECURE?: boolean;
|
|
1394
|
+
COOKIE_SAMESITE?: "Strict" | "Lax" | "None";
|
|
1395
|
+
MAX_COOKIE_SIZE?: number;
|
|
1396
|
+
SESSION_LIFETIME?: number;
|
|
1397
|
+
}
|
|
1398
|
+
type newSession = {
|
|
1399
|
+
sid?: string | undefined;
|
|
1400
|
+
readonly?: boolean | undefined;
|
|
1401
|
+
isFound?: boolean;
|
|
1402
|
+
};
|
|
1403
|
+
declare abstract class SessionAuthInterface extends SidGenerator {
|
|
1404
|
+
config: Required<AuthConfig>;
|
|
1405
|
+
constructor(config: AuthConfig, salt?: string);
|
|
1406
|
+
init(): Promise<void>;
|
|
1407
|
+
/**
|
|
1408
|
+
* Verifies the cryptographic signature and opens the session.
|
|
1409
|
+
*/
|
|
1410
|
+
openSession(sid?: string, readonly?: boolean): Promise<ServerSide>;
|
|
1411
|
+
/** To be implemented by child class: Retrieve from DB */
|
|
1412
|
+
fetchSession(sid: string, readonly?: boolean): Promise<any>;
|
|
1413
|
+
abstract fetchData(sid: string, readonly?: boolean): Promise<any | undefined>;
|
|
1414
|
+
/** To be implemented by child class: Save to DB */
|
|
1415
|
+
abstract saveSession(session: ServerSide, headers: Headers): Promise<void>;
|
|
1416
|
+
/** To be implemented by child class: Save to DB */
|
|
1417
|
+
abstract deleteSession(session: ServerSide, headers: Headers): Promise<void>;
|
|
1418
|
+
/** Instantiates a fresh, writable session */
|
|
1419
|
+
new({ sid, isFound, readonly, }: newSession): ServerSide;
|
|
1420
|
+
/** Instantiates a read-only session */
|
|
1421
|
+
get readonly(): ServerSide;
|
|
1422
|
+
/**
|
|
1423
|
+
* Calculates the exact Date object when this session expires.
|
|
1424
|
+
*/
|
|
1425
|
+
get getSessionExpirationDate(): Date;
|
|
1426
|
+
get getCookieExpirationDate(): Date;
|
|
1427
|
+
/**
|
|
1428
|
+
* Verifies if the session is still active and has not expired.
|
|
1429
|
+
* @returns true if valid, false if expired.
|
|
1430
|
+
*/
|
|
1431
|
+
isNotExpired(_date: Date): boolean;
|
|
1432
|
+
/**
|
|
1433
|
+
* Builds the raw standard HTTP Set-Cookie string.
|
|
1434
|
+
*/
|
|
1435
|
+
buildCookieString(session: ServerSide, expirationOverride?: Date | number, sameSiteOverride?: AuthConfig["COOKIE_SAMESITE"]): string;
|
|
1436
|
+
setCookie(session: ServerSide, headers: Headers): void;
|
|
1437
|
+
removeCookie(session: ServerSide, headers: Headers): void;
|
|
1438
|
+
/**
|
|
1439
|
+
* Extracts the Cookie directly from the Web API Request instance.
|
|
1440
|
+
*/
|
|
1441
|
+
loadHeader(req: Request, readonly?: boolean): Promise<[string | undefined, ServerSide]>;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
interface SessionConfig {
|
|
1445
|
+
auth: SessionAuthInterface;
|
|
1446
|
+
readonly?: boolean;
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Loads the request session into `ctx.session` and persists session changes
|
|
1450
|
+
* after downstream guards and handlers complete.
|
|
1451
|
+
*
|
|
1452
|
+
* @param auth - Session service used to load, save, and delete sessions.
|
|
1453
|
+
* @returns A guard factory that accepts a session service and optional error config.
|
|
1454
|
+
*/
|
|
1455
|
+
declare const session: (options?: SessionAuthInterface | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1456
|
+
|
|
1457
|
+
/**
|
|
1458
|
+
* Serves requests for file-like paths through the configured static file server.
|
|
1459
|
+
* Only GET and HEAD requests are intercepted.
|
|
1460
|
+
*
|
|
1461
|
+
* @returns A guard factory that serves static assets before route handling.
|
|
1462
|
+
*/
|
|
1463
|
+
declare const staticFiles: (options?: void | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1464
|
+
|
|
1465
|
+
/**
|
|
1466
|
+
* Stops waiting for downstream work after the configured number of milliseconds.
|
|
1467
|
+
*
|
|
1468
|
+
* @param ms - Maximum time to wait for downstream guards and handlers.
|
|
1469
|
+
* @returns A guard factory that accepts a timeout and optional error config.
|
|
1470
|
+
*/
|
|
1471
|
+
declare const timeout: (options?: number | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1472
|
+
|
|
1473
|
+
/** Function signature for a guard that receives request context and continues the pipeline. */
|
|
1474
|
+
type GlobalGuard = (ctx: ctx, next: () => Promise<Response>) => Promise<Response>;
|
|
1475
|
+
|
|
1476
|
+
interface UrlValidationOptions {
|
|
1477
|
+
maxUrlLength?: number;
|
|
1478
|
+
maxQueryLength?: number;
|
|
1479
|
+
allowedKeys?: string[];
|
|
1480
|
+
disallowedKeys?: string[];
|
|
1481
|
+
noDuplicates?: boolean;
|
|
1482
|
+
sanitizePaths?: boolean;
|
|
1483
|
+
patterns?: Record<string, RegExp>;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Validates URL and query limits, query keys, duplicate keys, and path safety.
|
|
1487
|
+
*
|
|
1488
|
+
* @param options - URL size, query, and path validation rules.
|
|
1489
|
+
* @returns A guard factory that accepts validation rules and optional error config.
|
|
1490
|
+
*/
|
|
1491
|
+
declare const validateUrl: (options?: void | number | UrlValidationOptions | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1492
|
+
|
|
1493
|
+
/**
|
|
1494
|
+
* Parses an URL-encoded form request and stores its fields in `ctx.form`.
|
|
1495
|
+
*
|
|
1496
|
+
* @returns A guard factory that parses URL-encoded form data before continuing.
|
|
1497
|
+
*/
|
|
1498
|
+
declare const urlencoded: (options?: void | undefined, overrideConfig?: BaseConfig) => GuardReturnType;
|
|
1499
|
+
|
|
1500
|
+
type ScopeDecorator<V> = (value: undefined, context: ClassFieldDecoratorContext<any, V>) => (this: any) => V;
|
|
1501
|
+
type ScopeProxy<T> = {
|
|
1502
|
+
readonly [K in keyof T]: ScopeDecorator<T[K]>;
|
|
1503
|
+
};
|
|
1504
|
+
type FieldScopeSet<Config extends Record<string, Record<string, any>>> = {
|
|
1505
|
+
use<Name extends keyof Config & string>(name: Name): ScopeProxy<Config[Name]>;
|
|
1506
|
+
};
|
|
1507
|
+
declare class _FieldScope {
|
|
1508
|
+
private static registry;
|
|
1509
|
+
static register<Config extends Record<string, Record<string, any>>>(data: Config): FieldScopeSet<Config>;
|
|
1510
|
+
static use<T extends Record<string, any>>(scopeName: string): ScopeProxy<T>;
|
|
1511
|
+
}
|
|
1512
|
+
/**
|
|
1513
|
+
* Describes the static interface of the Field class
|
|
1514
|
+
*/
|
|
1515
|
+
interface FieldScopeStatic {
|
|
1516
|
+
register<Config extends Record<string, Record<string, any>>>(data: Config): FieldScopeSet<Config>;
|
|
1517
|
+
use<T extends Record<string, any>>(name: string): ScopeProxy<T>;
|
|
1518
|
+
}
|
|
1519
|
+
type Field = _FieldScope;
|
|
1520
|
+
declare const Field: FieldScopeStatic;
|
|
1521
|
+
|
|
1522
|
+
type ScopeSet<Config extends Record<string, Record<string, any>>> = {
|
|
1523
|
+
use<Name extends keyof Config & string>(name: Name): Config[Name];
|
|
1524
|
+
};
|
|
1525
|
+
/** Named, shared values for use in functions, classes, or application setup. */
|
|
1526
|
+
declare class _Scope {
|
|
1527
|
+
private static registry;
|
|
1528
|
+
static register<Config extends Record<string, Record<string, any>>>(data: Config): ScopeSet<Config>;
|
|
1529
|
+
static use<T extends Record<string, any>>(name: string): T;
|
|
1530
|
+
}
|
|
1531
|
+
/** Describes the static interface of the Scope class. */
|
|
1532
|
+
interface ScopeStatic {
|
|
1533
|
+
register<Config extends Record<string, Record<string, any>>>(data: Config): ScopeSet<Config>;
|
|
1534
|
+
use<T extends Record<string, any>>(name: string): T;
|
|
184
1535
|
}
|
|
1536
|
+
type Scope = _Scope;
|
|
1537
|
+
declare const Scope: ScopeStatic;
|
|
185
1538
|
|
|
186
|
-
export {
|
|
1539
|
+
export { Column, DEFAULT_MAX_SIZE, DatabaseError, DbInspector, DbRepository, Field, ForeignKeyError, JWTAuthService, Methods, req as Req, res as Res, Rossa, RouterManager, Schema, SchemaBuilder, Scope, ServerSide, SessionAuthInterface, UniqueConstraintError, WSSMAN, Websocket, WssManager, apiKey, auth, authBearer, authorize, contentType, cookies, cors, createGuard, csrf, ctx, errorHandler, getDialect, header, ipFilter, json, jwtAuth, jwtRefresh, keys, logger, loggerFN, mariadbDialect, multipart, mysqlDialect, postgresDialect, rateLimit, route, sanitize, security, sendError, session, smartCache, sqliteDialect, staticFiles, subManager, t, timeout, urlencoded, use, validateForm, validateQuery, validateUrl, wss, z };
|
|
1540
|
+
export type { AuthConfig, BaseConfig, CacheOptions, ColumnType, ContentEncodingType, ContentTypeRules, CorsOptions, CsrfOptions, DbDialectAdapter, DbDialectName, ErrorConfig, ErrorGuardOptions, FormValidationOptions, GlobalGuard, GuardConfig, GuardFactoryHandler, GuardReturnType, HeaderValidationRules, HttpRouteConfig, HttpRouteMatch, JWTConfig, JwtPayload, JwtRefreshTokenStore, QueryValidationOptions, RateLimitOptions, RequireKeysOptions, RossaOptions, RossaWebSocketOptions, SanitizeOptions, SecurityHeadersOptions, SessionConfig, TableStats, TopicPublishResult, TopicPublishStatus, UrlValidationOptions, Where, WssBaseController, WssConfig, WssMessageRateLimit, WssRouteConfig, dev, methodsKeys, serverOptions, wssMessage };
|