@mrxsys/mrx-core 2.11.0-1-and-267-20250925 → 2.11.1-1-and-275-20251023
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-fp8xg6kq.js → chunk-441xs5k1.js} +1 -1
- package/dist/{chunk-bdcsh435.js → chunk-4v86f7gp.js} +5 -5
- package/dist/{chunk-00s6t4tw.js → chunk-7t524zqh.js} +4 -4
- package/dist/{chunk-d1vp74n0.js → chunk-afd82epa.js} +2 -2
- package/dist/{chunk-v9kvw5x7.js → chunk-afyz8rg5.js} +2 -2
- package/dist/{chunk-6sfnrhfs.js → chunk-pjv1ekwr.js} +33 -1
- package/dist/chunk-rz5p4j3p.js +13 -0
- package/dist/{chunk-h9t48r9q.js → chunk-sqts8vyk.js} +16 -2
- package/dist/errors/enums/http-status-codes.d.ts +15 -1
- package/dist/errors/enums/index.d.ts +1 -1
- package/dist/errors/enums/index.js +3 -3
- package/dist/errors/http-error.d.ts +3 -3
- package/dist/errors/index.js +2 -2
- package/dist/errors/utils/index.js +2 -2
- package/dist/modules/database/enums/database-error-keys.d.ts +2 -2
- package/dist/modules/database/enums/index.js +1 -1
- package/dist/modules/database/index.js +5 -5
- package/dist/modules/elysia/cache/cache.d.ts +8 -14
- package/dist/modules/elysia/cache/index.js +66 -46
- package/dist/modules/elysia/cache/types/cache-item.d.ts +0 -1
- package/dist/modules/elysia/cache/types/cache-options.d.ts +2 -11
- package/dist/modules/elysia/crud/index.js +16 -16
- package/dist/modules/elysia/crud/operations/count.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/delete.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/deleteOne.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/find.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/findOne.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/index.js +7 -7
- package/dist/modules/elysia/crud/operations/insert.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/update.d.ts +1 -1
- package/dist/modules/elysia/crud/operations/updateOne.d.ts +1 -1
- package/dist/modules/elysia/db-resolver/db-resolver.d.ts +1 -1
- package/dist/modules/elysia/db-resolver/index.js +6 -6
- package/dist/modules/elysia/error/index.js +2 -2
- package/dist/modules/elysia/microservice/microservice.d.ts +12 -12
- package/dist/modules/elysia/rate-limit/index.js +53 -28
- package/dist/modules/elysia/rate-limit/rate-limit.d.ts +361 -32
- package/dist/modules/elysia/rate-limit/types/rate-limit-options.d.ts +0 -9
- package/dist/modules/jwt/index.js +2 -2
- package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +25 -0
- package/dist/modules/kv-store/bun-redis/index.d.ts +1 -0
- package/dist/modules/kv-store/bun-redis/index.js +76 -0
- package/dist/modules/kv-store/ioredis/index.js +4 -10
- package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +0 -82
- package/dist/modules/kv-store/memory/index.js +98 -4
- package/dist/modules/kv-store/memory/memory-store.d.ts +0 -84
- package/dist/modules/kv-store/types/kv-store.d.ts +2 -2
- package/dist/modules/logger/enums/index.js +1 -1
- package/dist/modules/logger/enums/logger-error-keys.d.ts +6 -3
- package/dist/modules/logger/events/logger-events.d.ts +12 -3
- package/dist/modules/logger/index.js +173 -81
- package/dist/modules/logger/logger.d.ts +115 -133
- package/dist/modules/logger/sinks/console-logger.d.ts +2 -16
- package/dist/modules/logger/sinks/devnull-logger.d.ts +8 -0
- package/dist/modules/logger/sinks/file-logger/enums/file-logger-error-keys.d.ts +3 -0
- package/dist/modules/logger/sinks/file-logger/file-logger.d.ts +25 -0
- package/dist/modules/logger/sinks/index.d.ts +4 -2
- package/dist/modules/logger/sinks/index.js +54 -31
- package/dist/modules/logger/types/index.d.ts +6 -6
- package/dist/modules/logger/types/log-levels.d.ts +1 -4
- package/dist/modules/logger/types/logger-options.d.ts +41 -0
- package/dist/modules/logger/types/logger-sink.d.ts +12 -3
- package/dist/modules/logger/types/sink-bodies-intersection.d.ts +2 -0
- package/dist/modules/logger/types/sink-body.d.ts +1 -1
- package/dist/modules/logger/types/sink-map.d.ts +1 -1
- package/dist/modules/repository/index.js +4 -4
- package/dist/modules/repository/types/query-options.d.ts +2 -2
- package/package.json +30 -25
- package/dist/chunk-b23dvm2d.js +0 -29
- package/dist/chunk-b96fm9ph.js +0 -10
- package/dist/chunk-e30paw8a.js +0 -101
- package/dist/modules/elysia/cache/utils/index.d.ts +0 -1
- package/dist/modules/elysia/cache/utils/index.js +0 -7
- package/dist/modules/logger/sinks/file-logger.d.ts +0 -25
- package/dist/modules/logger/types/bodies-intersection.d.ts +0 -2
- package/dist/modules/logger/types/log-stream-chunk.d.ts +0 -15
|
@@ -1,42 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { KvStore } from '../../../modules/kv-store/types';
|
|
2
|
+
import { Elysia, type HTTPHeaders, type StatusMap } from 'elysia';
|
|
2
3
|
import type { RateLimitOptions } from './types/rate-limit-options';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
* protecting APIs from excessive use and potential abuse. It tracks request rates by client IP
|
|
6
|
-
* and enforces configurable limits based on a sliding time window.
|
|
5
|
+
* Rate limiting plugin for Elysia applications that protects APIs from excessive use and potential abuse.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* The plugin tracks request rates by client IP address and enforces configurable limits based on a fixed time window.
|
|
8
|
+
* It supports multiple storage backends through the `@mrxsys/mrx-core/modules/kv-store` ecosystem for both single-instance and distributed deployments.
|
|
9
|
+
*
|
|
10
|
+
* ### How It Works
|
|
11
|
+
* - Rate limiting is applied per IP address and per route
|
|
12
|
+
* - Each route can have its own limit and time window configuration
|
|
13
|
+
* - Route-level rate limits override global rate limits
|
|
14
|
+
* - Headers are added to all responses indicating the current rate limit status
|
|
15
|
+
*
|
|
16
|
+
* ### Rate Limit Headers
|
|
17
|
+
* The plugin adds the following headers to all responses (including 429 errors):
|
|
10
18
|
* - `X-RateLimit-Limit`: The maximum number of requests allowed in the window
|
|
11
19
|
* - `X-RateLimit-Remaining`: The number of requests remaining in the current window
|
|
12
|
-
* - `X-RateLimit-Reset`: The time in seconds until the rate limit resets
|
|
20
|
+
* - `X-RateLimit-Reset`: The time in seconds until the rate limit resets (Unix timestamp)
|
|
21
|
+
*
|
|
22
|
+
* When a rate limit is exceeded, the response includes a 429 (Too Many Requests) status code
|
|
23
|
+
* and the error key `elysia.rate-limit.error.exceeded`, along with the rate limit headers
|
|
24
|
+
* to help clients implement exponential backoff retry strategies.
|
|
13
25
|
*
|
|
14
|
-
* @param
|
|
26
|
+
* @param store - The KV store instance for tracking rate limits. Defaults to an in-memory store.
|
|
27
|
+
* Supports any `KvStore` implementation from `@mrxsys/mrx-core/modules/kv-store` (e.g., `MemoryStore`, `IoRedisStore`)
|
|
15
28
|
*
|
|
16
|
-
* @returns An {@link Elysia} plugin that adds rate limiting functionality
|
|
29
|
+
* @returns An {@link Elysia} plugin that adds rate limiting functionality via the `rateLimit` macro
|
|
17
30
|
*
|
|
18
31
|
* @example
|
|
19
|
-
* Basic usage with default in-memory store
|
|
32
|
+
* Basic usage with default in-memory store (development)
|
|
20
33
|
* ```ts
|
|
21
|
-
* import { rateLimit } from '@
|
|
34
|
+
* import { rateLimit } from '@mrxsys/mrx-core/modules/elysia/elysia-ratelimit';
|
|
22
35
|
* import { Elysia } from 'elysia';
|
|
23
36
|
*
|
|
24
37
|
* const app = new Elysia()
|
|
25
|
-
* .use(rateLimit(
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
38
|
+
* .use(rateLimit())
|
|
39
|
+
* .get('/api/data', () => ({ message: 'Hello World' }), {
|
|
40
|
+
* rateLimit: {
|
|
41
|
+
* limit: 100, // 100 requests
|
|
42
|
+
* window: 60 // per minute
|
|
43
|
+
* }
|
|
44
|
+
* })
|
|
45
|
+
* .listen(3000);
|
|
33
46
|
* ```
|
|
34
47
|
*
|
|
35
48
|
* @example
|
|
36
|
-
* Using Redis store for distributed rate limiting
|
|
49
|
+
* Using Redis store for distributed rate limiting (production)
|
|
37
50
|
* ```ts
|
|
38
|
-
* import { IoRedisStore } from '@
|
|
39
|
-
* import { rateLimit } from '@
|
|
51
|
+
* import { IoRedisStore } from '@mrxsys/mrx-core/modules/kv-store/ioredis'; // or use bun-redis
|
|
52
|
+
* import { rateLimit } from '@mrxsys/mrx-core/modules/elysia/elysia-ratelimit';
|
|
40
53
|
* import { Elysia } from 'elysia';
|
|
41
54
|
*
|
|
42
55
|
* const redisStore = new IoRedisStore({
|
|
@@ -46,17 +59,40 @@ import type { RateLimitOptions } from './types/rate-limit-options';
|
|
|
46
59
|
* await redisStore.connect();
|
|
47
60
|
*
|
|
48
61
|
* const app = new Elysia()
|
|
49
|
-
* .use(rateLimit(
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
62
|
+
* .use(rateLimit(redisStore))
|
|
63
|
+
* .get('/api/endpoint', () => ({ data: 'content' }), {
|
|
64
|
+
* rateLimit: {
|
|
65
|
+
* limit: 1000, // 1000 requests
|
|
66
|
+
* window: 3600 // per hour
|
|
67
|
+
* }
|
|
68
|
+
* })
|
|
69
|
+
* .listen(3000);
|
|
70
|
+
* ```
|
|
55
71
|
*
|
|
56
|
-
*
|
|
72
|
+
* @example
|
|
73
|
+
* Global rate limit with route-level overrides
|
|
74
|
+
* ```ts
|
|
75
|
+
* const app = new Elysia()
|
|
76
|
+
* .use(rateLimit())
|
|
77
|
+
* .guard({
|
|
78
|
+
* rateLimit: {
|
|
79
|
+
* limit: 100,
|
|
80
|
+
* window: 60
|
|
81
|
+
* }
|
|
82
|
+
* })
|
|
83
|
+
* .get('/api/slow', () => 'content', {
|
|
84
|
+
* rateLimit: {
|
|
85
|
+
* limit: 10, // Override global: stricter limit
|
|
86
|
+
* window: 60
|
|
87
|
+
* }
|
|
88
|
+
* })
|
|
89
|
+
* .get('/api/fast', () => 'content') // Uses global limit
|
|
90
|
+
* .listen(3000);
|
|
57
91
|
* ```
|
|
92
|
+
*
|
|
93
|
+
* @throws ({@link HttpError}) – `elysia.rate-limit.error.exceeded` when the rate limit is exceeded (HTTP 429)
|
|
58
94
|
*/
|
|
59
|
-
export declare const rateLimit: (
|
|
95
|
+
export declare const rateLimit: (store?: KvStore) => Elysia<"", {
|
|
60
96
|
decorator: {};
|
|
61
97
|
store: {};
|
|
62
98
|
derive: {};
|
|
@@ -67,8 +103,301 @@ export declare const rateLimit: ({ store, limit, window }: RateLimitOptions) =>
|
|
|
67
103
|
}, {
|
|
68
104
|
schema: {};
|
|
69
105
|
standaloneSchema: {};
|
|
70
|
-
macro: {
|
|
71
|
-
|
|
106
|
+
macro: Partial<{
|
|
107
|
+
readonly rateLimit: RateLimitOptions;
|
|
108
|
+
}>;
|
|
109
|
+
macroFn: {
|
|
110
|
+
readonly rateLimit: ({ limit, window }: RateLimitOptions) => {
|
|
111
|
+
readonly transform: ({ request }: {
|
|
112
|
+
body: unknown;
|
|
113
|
+
query: Record<string, string>;
|
|
114
|
+
params: {};
|
|
115
|
+
headers: Record<string, string | undefined>;
|
|
116
|
+
cookie: Record<string, import("elysia").Cookie<unknown>>;
|
|
117
|
+
server: import("elysia/universal/server").Server | null;
|
|
118
|
+
redirect: import("elysia").redirect;
|
|
119
|
+
set: {
|
|
120
|
+
headers: HTTPHeaders;
|
|
121
|
+
status?: number | keyof StatusMap;
|
|
122
|
+
redirect?: string;
|
|
123
|
+
cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
|
|
124
|
+
};
|
|
125
|
+
path: string;
|
|
126
|
+
route: string;
|
|
127
|
+
request: Request;
|
|
128
|
+
store: {};
|
|
129
|
+
status: <const Code extends number | keyof StatusMap, const T = Code extends 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | 300 | 301 | 302 | 303 | 304 | 307 | 308 | 420 ? {
|
|
130
|
+
readonly 100: "Continue";
|
|
131
|
+
readonly 101: "Switching Protocols";
|
|
132
|
+
readonly 102: "Processing";
|
|
133
|
+
readonly 103: "Early Hints";
|
|
134
|
+
readonly 200: "OK";
|
|
135
|
+
readonly 201: "Created";
|
|
136
|
+
readonly 202: "Accepted";
|
|
137
|
+
readonly 203: "Non-Authoritative Information";
|
|
138
|
+
readonly 204: "No Content";
|
|
139
|
+
readonly 205: "Reset Content";
|
|
140
|
+
readonly 206: "Partial Content";
|
|
141
|
+
readonly 207: "Multi-Status";
|
|
142
|
+
readonly 208: "Already Reported";
|
|
143
|
+
readonly 300: "Multiple Choices";
|
|
144
|
+
readonly 301: "Moved Permanently";
|
|
145
|
+
readonly 302: "Found";
|
|
146
|
+
readonly 303: "See Other";
|
|
147
|
+
readonly 304: "Not Modified";
|
|
148
|
+
readonly 307: "Temporary Redirect";
|
|
149
|
+
readonly 308: "Permanent Redirect";
|
|
150
|
+
readonly 400: "Bad Request";
|
|
151
|
+
readonly 401: "Unauthorized";
|
|
152
|
+
readonly 402: "Payment Required";
|
|
153
|
+
readonly 403: "Forbidden";
|
|
154
|
+
readonly 404: "Not Found";
|
|
155
|
+
readonly 405: "Method Not Allowed";
|
|
156
|
+
readonly 406: "Not Acceptable";
|
|
157
|
+
readonly 407: "Proxy Authentication Required";
|
|
158
|
+
readonly 408: "Request Timeout";
|
|
159
|
+
readonly 409: "Conflict";
|
|
160
|
+
readonly 410: "Gone";
|
|
161
|
+
readonly 411: "Length Required";
|
|
162
|
+
readonly 412: "Precondition Failed";
|
|
163
|
+
readonly 413: "Payload Too Large";
|
|
164
|
+
readonly 414: "URI Too Long";
|
|
165
|
+
readonly 415: "Unsupported Media Type";
|
|
166
|
+
readonly 416: "Range Not Satisfiable";
|
|
167
|
+
readonly 417: "Expectation Failed";
|
|
168
|
+
readonly 418: "I'm a teapot";
|
|
169
|
+
readonly 420: "Enhance Your Calm";
|
|
170
|
+
readonly 421: "Misdirected Request";
|
|
171
|
+
readonly 422: "Unprocessable Content";
|
|
172
|
+
readonly 423: "Locked";
|
|
173
|
+
readonly 424: "Failed Dependency";
|
|
174
|
+
readonly 425: "Too Early";
|
|
175
|
+
readonly 426: "Upgrade Required";
|
|
176
|
+
readonly 428: "Precondition Required";
|
|
177
|
+
readonly 429: "Too Many Requests";
|
|
178
|
+
readonly 431: "Request Header Fields Too Large";
|
|
179
|
+
readonly 451: "Unavailable For Legal Reasons";
|
|
180
|
+
readonly 500: "Internal Server Error";
|
|
181
|
+
readonly 501: "Not Implemented";
|
|
182
|
+
readonly 502: "Bad Gateway";
|
|
183
|
+
readonly 503: "Service Unavailable";
|
|
184
|
+
readonly 504: "Gateway Timeout";
|
|
185
|
+
readonly 505: "HTTP Version Not Supported";
|
|
186
|
+
readonly 506: "Variant Also Negotiates";
|
|
187
|
+
readonly 507: "Insufficient Storage";
|
|
188
|
+
readonly 508: "Loop Detected";
|
|
189
|
+
readonly 510: "Not Extended";
|
|
190
|
+
readonly 511: "Network Authentication Required";
|
|
191
|
+
}[Code] : Code>(code: Code, response?: T) => import("elysia").ElysiaCustomStatusResponse<Code, T, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
|
|
192
|
+
readonly Continue: 100;
|
|
193
|
+
readonly "Switching Protocols": 101;
|
|
194
|
+
readonly Processing: 102;
|
|
195
|
+
readonly "Early Hints": 103;
|
|
196
|
+
readonly OK: 200;
|
|
197
|
+
readonly Created: 201;
|
|
198
|
+
readonly Accepted: 202;
|
|
199
|
+
readonly "Non-Authoritative Information": 203;
|
|
200
|
+
readonly "No Content": 204;
|
|
201
|
+
readonly "Reset Content": 205;
|
|
202
|
+
readonly "Partial Content": 206;
|
|
203
|
+
readonly "Multi-Status": 207;
|
|
204
|
+
readonly "Already Reported": 208;
|
|
205
|
+
readonly "Multiple Choices": 300;
|
|
206
|
+
readonly "Moved Permanently": 301;
|
|
207
|
+
readonly Found: 302;
|
|
208
|
+
readonly "See Other": 303;
|
|
209
|
+
readonly "Not Modified": 304;
|
|
210
|
+
readonly "Temporary Redirect": 307;
|
|
211
|
+
readonly "Permanent Redirect": 308;
|
|
212
|
+
readonly "Bad Request": 400;
|
|
213
|
+
readonly Unauthorized: 401;
|
|
214
|
+
readonly "Payment Required": 402;
|
|
215
|
+
readonly Forbidden: 403;
|
|
216
|
+
readonly "Not Found": 404;
|
|
217
|
+
readonly "Method Not Allowed": 405;
|
|
218
|
+
readonly "Not Acceptable": 406;
|
|
219
|
+
readonly "Proxy Authentication Required": 407;
|
|
220
|
+
readonly "Request Timeout": 408;
|
|
221
|
+
readonly Conflict: 409;
|
|
222
|
+
readonly Gone: 410;
|
|
223
|
+
readonly "Length Required": 411;
|
|
224
|
+
readonly "Precondition Failed": 412;
|
|
225
|
+
readonly "Payload Too Large": 413;
|
|
226
|
+
readonly "URI Too Long": 414;
|
|
227
|
+
readonly "Unsupported Media Type": 415;
|
|
228
|
+
readonly "Range Not Satisfiable": 416;
|
|
229
|
+
readonly "Expectation Failed": 417;
|
|
230
|
+
readonly "I'm a teapot": 418;
|
|
231
|
+
readonly "Enhance Your Calm": 420;
|
|
232
|
+
readonly "Misdirected Request": 421;
|
|
233
|
+
readonly "Unprocessable Content": 422;
|
|
234
|
+
readonly Locked: 423;
|
|
235
|
+
readonly "Failed Dependency": 424;
|
|
236
|
+
readonly "Too Early": 425;
|
|
237
|
+
readonly "Upgrade Required": 426;
|
|
238
|
+
readonly "Precondition Required": 428;
|
|
239
|
+
readonly "Too Many Requests": 429;
|
|
240
|
+
readonly "Request Header Fields Too Large": 431;
|
|
241
|
+
readonly "Unavailable For Legal Reasons": 451;
|
|
242
|
+
readonly "Internal Server Error": 500;
|
|
243
|
+
readonly "Not Implemented": 501;
|
|
244
|
+
readonly "Bad Gateway": 502;
|
|
245
|
+
readonly "Service Unavailable": 503;
|
|
246
|
+
readonly "Gateway Timeout": 504;
|
|
247
|
+
readonly "HTTP Version Not Supported": 505;
|
|
248
|
+
readonly "Variant Also Negotiates": 506;
|
|
249
|
+
readonly "Insufficient Storage": 507;
|
|
250
|
+
readonly "Loop Detected": 508;
|
|
251
|
+
readonly "Not Extended": 510;
|
|
252
|
+
readonly "Network Authentication Required": 511;
|
|
253
|
+
}[Code] : Code>;
|
|
254
|
+
}) => void;
|
|
255
|
+
readonly beforeHandle: ({ set, request, server }: {
|
|
256
|
+
body: unknown;
|
|
257
|
+
query: Record<string, string>;
|
|
258
|
+
params: {};
|
|
259
|
+
headers: Record<string, string | undefined>;
|
|
260
|
+
cookie: Record<string, import("elysia").Cookie<unknown>>;
|
|
261
|
+
server: import("elysia/universal/server").Server | null;
|
|
262
|
+
redirect: import("elysia").redirect;
|
|
263
|
+
set: {
|
|
264
|
+
headers: HTTPHeaders;
|
|
265
|
+
status?: number | keyof StatusMap;
|
|
266
|
+
redirect?: string;
|
|
267
|
+
cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
|
|
268
|
+
};
|
|
269
|
+
path: string;
|
|
270
|
+
route: string;
|
|
271
|
+
request: Request;
|
|
272
|
+
store: {};
|
|
273
|
+
status: <const Code extends number | keyof StatusMap, const T = Code extends 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | 300 | 301 | 302 | 303 | 304 | 307 | 308 | 420 ? {
|
|
274
|
+
readonly 100: "Continue";
|
|
275
|
+
readonly 101: "Switching Protocols";
|
|
276
|
+
readonly 102: "Processing";
|
|
277
|
+
readonly 103: "Early Hints";
|
|
278
|
+
readonly 200: "OK";
|
|
279
|
+
readonly 201: "Created";
|
|
280
|
+
readonly 202: "Accepted";
|
|
281
|
+
readonly 203: "Non-Authoritative Information";
|
|
282
|
+
readonly 204: "No Content";
|
|
283
|
+
readonly 205: "Reset Content";
|
|
284
|
+
readonly 206: "Partial Content";
|
|
285
|
+
readonly 207: "Multi-Status";
|
|
286
|
+
readonly 208: "Already Reported";
|
|
287
|
+
readonly 300: "Multiple Choices";
|
|
288
|
+
readonly 301: "Moved Permanently";
|
|
289
|
+
readonly 302: "Found";
|
|
290
|
+
readonly 303: "See Other";
|
|
291
|
+
readonly 304: "Not Modified";
|
|
292
|
+
readonly 307: "Temporary Redirect";
|
|
293
|
+
readonly 308: "Permanent Redirect";
|
|
294
|
+
readonly 400: "Bad Request";
|
|
295
|
+
readonly 401: "Unauthorized";
|
|
296
|
+
readonly 402: "Payment Required";
|
|
297
|
+
readonly 403: "Forbidden";
|
|
298
|
+
readonly 404: "Not Found";
|
|
299
|
+
readonly 405: "Method Not Allowed";
|
|
300
|
+
readonly 406: "Not Acceptable";
|
|
301
|
+
readonly 407: "Proxy Authentication Required";
|
|
302
|
+
readonly 408: "Request Timeout";
|
|
303
|
+
readonly 409: "Conflict";
|
|
304
|
+
readonly 410: "Gone";
|
|
305
|
+
readonly 411: "Length Required";
|
|
306
|
+
readonly 412: "Precondition Failed";
|
|
307
|
+
readonly 413: "Payload Too Large";
|
|
308
|
+
readonly 414: "URI Too Long";
|
|
309
|
+
readonly 415: "Unsupported Media Type";
|
|
310
|
+
readonly 416: "Range Not Satisfiable";
|
|
311
|
+
readonly 417: "Expectation Failed";
|
|
312
|
+
readonly 418: "I'm a teapot";
|
|
313
|
+
readonly 420: "Enhance Your Calm";
|
|
314
|
+
readonly 421: "Misdirected Request";
|
|
315
|
+
readonly 422: "Unprocessable Content";
|
|
316
|
+
readonly 423: "Locked";
|
|
317
|
+
readonly 424: "Failed Dependency";
|
|
318
|
+
readonly 425: "Too Early";
|
|
319
|
+
readonly 426: "Upgrade Required";
|
|
320
|
+
readonly 428: "Precondition Required";
|
|
321
|
+
readonly 429: "Too Many Requests";
|
|
322
|
+
readonly 431: "Request Header Fields Too Large";
|
|
323
|
+
readonly 451: "Unavailable For Legal Reasons";
|
|
324
|
+
readonly 500: "Internal Server Error";
|
|
325
|
+
readonly 501: "Not Implemented";
|
|
326
|
+
readonly 502: "Bad Gateway";
|
|
327
|
+
readonly 503: "Service Unavailable";
|
|
328
|
+
readonly 504: "Gateway Timeout";
|
|
329
|
+
readonly 505: "HTTP Version Not Supported";
|
|
330
|
+
readonly 506: "Variant Also Negotiates";
|
|
331
|
+
readonly 507: "Insufficient Storage";
|
|
332
|
+
readonly 508: "Loop Detected";
|
|
333
|
+
readonly 510: "Not Extended";
|
|
334
|
+
readonly 511: "Network Authentication Required";
|
|
335
|
+
}[Code] : Code>(code: Code, response?: T) => import("elysia").ElysiaCustomStatusResponse<Code, T, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
|
|
336
|
+
readonly Continue: 100;
|
|
337
|
+
readonly "Switching Protocols": 101;
|
|
338
|
+
readonly Processing: 102;
|
|
339
|
+
readonly "Early Hints": 103;
|
|
340
|
+
readonly OK: 200;
|
|
341
|
+
readonly Created: 201;
|
|
342
|
+
readonly Accepted: 202;
|
|
343
|
+
readonly "Non-Authoritative Information": 203;
|
|
344
|
+
readonly "No Content": 204;
|
|
345
|
+
readonly "Reset Content": 205;
|
|
346
|
+
readonly "Partial Content": 206;
|
|
347
|
+
readonly "Multi-Status": 207;
|
|
348
|
+
readonly "Already Reported": 208;
|
|
349
|
+
readonly "Multiple Choices": 300;
|
|
350
|
+
readonly "Moved Permanently": 301;
|
|
351
|
+
readonly Found: 302;
|
|
352
|
+
readonly "See Other": 303;
|
|
353
|
+
readonly "Not Modified": 304;
|
|
354
|
+
readonly "Temporary Redirect": 307;
|
|
355
|
+
readonly "Permanent Redirect": 308;
|
|
356
|
+
readonly "Bad Request": 400;
|
|
357
|
+
readonly Unauthorized: 401;
|
|
358
|
+
readonly "Payment Required": 402;
|
|
359
|
+
readonly Forbidden: 403;
|
|
360
|
+
readonly "Not Found": 404;
|
|
361
|
+
readonly "Method Not Allowed": 405;
|
|
362
|
+
readonly "Not Acceptable": 406;
|
|
363
|
+
readonly "Proxy Authentication Required": 407;
|
|
364
|
+
readonly "Request Timeout": 408;
|
|
365
|
+
readonly Conflict: 409;
|
|
366
|
+
readonly Gone: 410;
|
|
367
|
+
readonly "Length Required": 411;
|
|
368
|
+
readonly "Precondition Failed": 412;
|
|
369
|
+
readonly "Payload Too Large": 413;
|
|
370
|
+
readonly "URI Too Long": 414;
|
|
371
|
+
readonly "Unsupported Media Type": 415;
|
|
372
|
+
readonly "Range Not Satisfiable": 416;
|
|
373
|
+
readonly "Expectation Failed": 417;
|
|
374
|
+
readonly "I'm a teapot": 418;
|
|
375
|
+
readonly "Enhance Your Calm": 420;
|
|
376
|
+
readonly "Misdirected Request": 421;
|
|
377
|
+
readonly "Unprocessable Content": 422;
|
|
378
|
+
readonly Locked: 423;
|
|
379
|
+
readonly "Failed Dependency": 424;
|
|
380
|
+
readonly "Too Early": 425;
|
|
381
|
+
readonly "Upgrade Required": 426;
|
|
382
|
+
readonly "Precondition Required": 428;
|
|
383
|
+
readonly "Too Many Requests": 429;
|
|
384
|
+
readonly "Request Header Fields Too Large": 431;
|
|
385
|
+
readonly "Unavailable For Legal Reasons": 451;
|
|
386
|
+
readonly "Internal Server Error": 500;
|
|
387
|
+
readonly "Not Implemented": 501;
|
|
388
|
+
readonly "Bad Gateway": 502;
|
|
389
|
+
readonly "Service Unavailable": 503;
|
|
390
|
+
readonly "Gateway Timeout": 504;
|
|
391
|
+
readonly "HTTP Version Not Supported": 505;
|
|
392
|
+
readonly "Variant Also Negotiates": 506;
|
|
393
|
+
readonly "Insufficient Storage": 507;
|
|
394
|
+
readonly "Loop Detected": 508;
|
|
395
|
+
readonly "Not Extended": 510;
|
|
396
|
+
readonly "Network Authentication Required": 511;
|
|
397
|
+
}[Code] : Code>;
|
|
398
|
+
}) => Promise<void>;
|
|
399
|
+
};
|
|
400
|
+
};
|
|
72
401
|
parser: {};
|
|
73
402
|
response: {};
|
|
74
403
|
}, {}, {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import type { KvStore } from '../../../../modules/kv-store/types/kv-store';
|
|
2
1
|
export interface RateLimitOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Storage backend for rate limit data.
|
|
5
|
-
*
|
|
6
|
-
* - If not specified, defaults to in-memory storage
|
|
7
|
-
* - Use ':memory:' to explicitly specify in-memory storage
|
|
8
|
-
* - Provide a KvStore instance for persistent distributed storage
|
|
9
|
-
*/
|
|
10
|
-
readonly store?: ':memory:' | KvStore;
|
|
11
2
|
/**
|
|
12
3
|
* Maximum number of requests allowed in the time window.
|
|
13
4
|
*
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
import"../../chunk-12qzn7jw.js";
|
|
9
9
|
import {
|
|
10
10
|
HttpError
|
|
11
|
-
} from "../../chunk-
|
|
12
|
-
import"../../chunk-
|
|
11
|
+
} from "../../chunk-7t524zqh.js";
|
|
12
|
+
import"../../chunk-sqts8vyk.js";
|
|
13
13
|
import"../../chunk-9cgzhc50.js";
|
|
14
14
|
|
|
15
15
|
// source/modules/jwt/jwt.ts
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type RedisOptions } from 'bun';
|
|
2
|
+
import type { KvStore } from '../../../modules/kv-store/types/kv-store';
|
|
3
|
+
/**
|
|
4
|
+
* Redis-based key-value store implementation using Bun's Redis client.
|
|
5
|
+
*
|
|
6
|
+
* Provides a Redis-backed implementation of the KvStore interface with
|
|
7
|
+
* automatic JSON serialization/deserialization and proper error handling.
|
|
8
|
+
*/
|
|
9
|
+
export declare class BunRedisStore implements KvStore {
|
|
10
|
+
/**
|
|
11
|
+
* Redis client instance.
|
|
12
|
+
*/
|
|
13
|
+
private readonly _client;
|
|
14
|
+
constructor(url?: string, options?: RedisOptions);
|
|
15
|
+
connect(): Promise<void>;
|
|
16
|
+
close?(): void;
|
|
17
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
18
|
+
set<T = unknown>(key: string, value: T, ttlSec?: number): Promise<void>;
|
|
19
|
+
increment(key: string, amount?: number): Promise<number>;
|
|
20
|
+
decrement(key: string, amount?: number): Promise<number>;
|
|
21
|
+
del(key: string): Promise<boolean>;
|
|
22
|
+
expire(key: string, ttlSec: number): Promise<boolean>;
|
|
23
|
+
ttl(key: string): Promise<number>;
|
|
24
|
+
clean(): Promise<number>;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BunRedisStore } from './bun-redis-store';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
KV_STORE_ERROR_KEYS
|
|
4
|
+
} from "../../../chunk-xhhj1gvj.js";
|
|
5
|
+
import {
|
|
6
|
+
BaseError
|
|
7
|
+
} from "../../../chunk-9cgzhc50.js";
|
|
8
|
+
|
|
9
|
+
// source/modules/kv-store/bun-redis/bun-redis-store.ts
|
|
10
|
+
var {RedisClient } = globalThis.Bun;
|
|
11
|
+
class BunRedisStore {
|
|
12
|
+
_client;
|
|
13
|
+
constructor(url, options) {
|
|
14
|
+
this._client = new RedisClient(url, options);
|
|
15
|
+
}
|
|
16
|
+
async connect() {
|
|
17
|
+
await this._client.connect();
|
|
18
|
+
}
|
|
19
|
+
close() {
|
|
20
|
+
this._client.close();
|
|
21
|
+
}
|
|
22
|
+
async get(key) {
|
|
23
|
+
const value = await this._client.get(key);
|
|
24
|
+
if (value === null)
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(value);
|
|
28
|
+
} catch {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async set(key, value, ttlSec) {
|
|
33
|
+
const serialized = typeof value === "string" ? value : JSON.stringify(value);
|
|
34
|
+
if (ttlSec)
|
|
35
|
+
await this._client.set(key, serialized, "EX", ttlSec);
|
|
36
|
+
else
|
|
37
|
+
await this._client.set(key, serialized);
|
|
38
|
+
}
|
|
39
|
+
async increment(key, amount) {
|
|
40
|
+
let current = Number(await this._client.get(key));
|
|
41
|
+
if (current !== null && isNaN(current))
|
|
42
|
+
throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
43
|
+
current += amount ?? 1;
|
|
44
|
+
await this._client.set(key, current.toString());
|
|
45
|
+
return current;
|
|
46
|
+
}
|
|
47
|
+
async decrement(key, amount) {
|
|
48
|
+
let current = Number(await this._client.get(key));
|
|
49
|
+
if (current !== null && isNaN(current))
|
|
50
|
+
throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
51
|
+
current -= amount ?? 1;
|
|
52
|
+
await this._client.set(key, current.toString());
|
|
53
|
+
return current;
|
|
54
|
+
}
|
|
55
|
+
async del(key) {
|
|
56
|
+
const res = await this._client.del(key);
|
|
57
|
+
return res === 1;
|
|
58
|
+
}
|
|
59
|
+
async expire(key, ttlSec) {
|
|
60
|
+
const res = await this._client.expire(key, ttlSec);
|
|
61
|
+
return res === 1;
|
|
62
|
+
}
|
|
63
|
+
async ttl(key) {
|
|
64
|
+
const res = await this._client.ttl(key);
|
|
65
|
+
return res;
|
|
66
|
+
}
|
|
67
|
+
async clean() {
|
|
68
|
+
const keys = await this._client.keys("*");
|
|
69
|
+
if (keys.length === 0)
|
|
70
|
+
return 0;
|
|
71
|
+
return this._client.del(...keys);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
BunRedisStore
|
|
76
|
+
};
|
|
@@ -49,22 +49,16 @@ class IoRedisStore {
|
|
|
49
49
|
}
|
|
50
50
|
async increment(key, amount = 1) {
|
|
51
51
|
const current = await this._client.get(key);
|
|
52
|
-
if (current !== null)
|
|
53
|
-
|
|
54
|
-
if (Number.isNaN(parsed))
|
|
55
|
-
throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
56
|
-
}
|
|
52
|
+
if (current !== null && isNaN(Number(current)))
|
|
53
|
+
throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
57
54
|
if (amount === 1)
|
|
58
55
|
return this._client.incr(key);
|
|
59
56
|
return this._client.incrby(key, amount);
|
|
60
57
|
}
|
|
61
58
|
async decrement(key, amount = 1) {
|
|
62
59
|
const current = await this._client.get(key);
|
|
63
|
-
if (current !== null)
|
|
64
|
-
|
|
65
|
-
if (Number.isNaN(parsed))
|
|
66
|
-
throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
67
|
-
}
|
|
60
|
+
if (current !== null && isNaN(Number(current)))
|
|
61
|
+
throw new BaseError(KV_STORE_ERROR_KEYS.NOT_INTEGER);
|
|
68
62
|
if (amount === 1)
|
|
69
63
|
return this._client.decr(key);
|
|
70
64
|
return this._client.decrby(key, amount);
|