@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
|
@@ -43,7 +43,7 @@ export declare const deleteOne: <const TDatabase extends Omit<MSSQLDatabaseOptio
|
|
|
43
43
|
route: string;
|
|
44
44
|
request: Request;
|
|
45
45
|
store: {};
|
|
46
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 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 |
|
|
46
|
+
status: <const Code extends number | keyof import("elysia").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 ? {
|
|
47
47
|
readonly 100: "Continue";
|
|
48
48
|
readonly 101: "Switching Protocols";
|
|
49
49
|
readonly 102: "Processing";
|
|
@@ -43,7 +43,7 @@ export declare const find: <const TDatabase extends Omit<MSSQLDatabaseOptions, "
|
|
|
43
43
|
route: string;
|
|
44
44
|
request: Request;
|
|
45
45
|
store: {};
|
|
46
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 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 |
|
|
46
|
+
status: <const Code extends number | keyof import("elysia").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 ? {
|
|
47
47
|
readonly 100: "Continue";
|
|
48
48
|
readonly 101: "Switching Protocols";
|
|
49
49
|
readonly 102: "Processing";
|
|
@@ -43,7 +43,7 @@ export declare const findOne: <const TDatabase extends Omit<MSSQLDatabaseOptions
|
|
|
43
43
|
route: string;
|
|
44
44
|
request: Request;
|
|
45
45
|
store: {};
|
|
46
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 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 |
|
|
46
|
+
status: <const Code extends number | keyof import("elysia").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 ? {
|
|
47
47
|
readonly 100: "Continue";
|
|
48
48
|
readonly 101: "Switching Protocols";
|
|
49
49
|
readonly 102: "Processing";
|
|
@@ -8,19 +8,19 @@ import {
|
|
|
8
8
|
insert,
|
|
9
9
|
update,
|
|
10
10
|
updateOne
|
|
11
|
-
} from "../../../../chunk-
|
|
12
|
-
import"../../../../chunk-
|
|
11
|
+
} from "../../../../chunk-pjv1ekwr.js";
|
|
12
|
+
import"../../../../chunk-441xs5k1.js";
|
|
13
13
|
import"../../../../chunk-fs3wm3p4.js";
|
|
14
14
|
import"../../../../chunk-z0ct35ft.js";
|
|
15
15
|
import"../../../../chunk-8tffnbpn.js";
|
|
16
16
|
import"../../../../chunk-w7h898m3.js";
|
|
17
|
-
import"../../../../chunk-
|
|
18
|
-
import"../../../../chunk-
|
|
17
|
+
import"../../../../chunk-afd82epa.js";
|
|
18
|
+
import"../../../../chunk-afyz8rg5.js";
|
|
19
19
|
import"../../../../chunk-grfyngq0.js";
|
|
20
20
|
import"../../../../chunk-mvrxngm7.js";
|
|
21
|
-
import"../../../../chunk-
|
|
22
|
-
import"../../../../chunk-
|
|
23
|
-
import"../../../../chunk-
|
|
21
|
+
import"../../../../chunk-4v86f7gp.js";
|
|
22
|
+
import"../../../../chunk-7t524zqh.js";
|
|
23
|
+
import"../../../../chunk-sqts8vyk.js";
|
|
24
24
|
import"../../../../chunk-9cgzhc50.js";
|
|
25
25
|
export {
|
|
26
26
|
updateOne,
|
|
@@ -43,7 +43,7 @@ export declare const insert: <const TDatabase extends Omit<MSSQLDatabaseOptions,
|
|
|
43
43
|
route: string;
|
|
44
44
|
request: Request;
|
|
45
45
|
store: {};
|
|
46
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 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 |
|
|
46
|
+
status: <const Code extends number | keyof import("elysia").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 ? {
|
|
47
47
|
readonly 100: "Continue";
|
|
48
48
|
readonly 101: "Switching Protocols";
|
|
49
49
|
readonly 102: "Processing";
|
|
@@ -43,7 +43,7 @@ export declare const update: <const TDatabase extends Omit<MSSQLDatabaseOptions,
|
|
|
43
43
|
route: string;
|
|
44
44
|
request: Request;
|
|
45
45
|
store: {};
|
|
46
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 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 |
|
|
46
|
+
status: <const Code extends number | keyof import("elysia").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 ? {
|
|
47
47
|
readonly 100: "Continue";
|
|
48
48
|
readonly 101: "Switching Protocols";
|
|
49
49
|
readonly 102: "Processing";
|
|
@@ -43,7 +43,7 @@ export declare const updateOne: <const TDatabase extends Omit<MSSQLDatabaseOptio
|
|
|
43
43
|
route: string;
|
|
44
44
|
request: Request;
|
|
45
45
|
store: {};
|
|
46
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 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 |
|
|
46
|
+
status: <const Code extends number | keyof import("elysia").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 ? {
|
|
47
47
|
readonly 100: "Continue";
|
|
48
48
|
readonly 101: "Switching Protocols";
|
|
49
49
|
readonly 102: "Processing";
|
|
@@ -41,7 +41,7 @@ export declare const dbResolver: (prefixDatabaseName?: string) => Elysia<"", {
|
|
|
41
41
|
route: string;
|
|
42
42
|
request: Request;
|
|
43
43
|
store: {};
|
|
44
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 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 |
|
|
44
|
+
status: <const Code extends number | keyof import("elysia").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 ? {
|
|
45
45
|
readonly 100: "Continue";
|
|
46
46
|
readonly 101: "Switching Protocols";
|
|
47
47
|
readonly 102: "Processing";
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
dbResolver
|
|
4
|
-
} from "../../../chunk-
|
|
4
|
+
} from "../../../chunk-441xs5k1.js";
|
|
5
5
|
import"../../../chunk-fs3wm3p4.js";
|
|
6
6
|
import"../../../chunk-z0ct35ft.js";
|
|
7
7
|
import"../../../chunk-8tffnbpn.js";
|
|
8
|
-
import"../../../chunk-
|
|
9
|
-
import"../../../chunk-
|
|
8
|
+
import"../../../chunk-afd82epa.js";
|
|
9
|
+
import"../../../chunk-afyz8rg5.js";
|
|
10
10
|
import"../../../chunk-grfyngq0.js";
|
|
11
11
|
import"../../../chunk-mvrxngm7.js";
|
|
12
|
-
import"../../../chunk-
|
|
13
|
-
import"../../../chunk-
|
|
14
|
-
import"../../../chunk-
|
|
12
|
+
import"../../../chunk-4v86f7gp.js";
|
|
13
|
+
import"../../../chunk-7t524zqh.js";
|
|
14
|
+
import"../../../chunk-sqts8vyk.js";
|
|
15
15
|
import"../../../chunk-9cgzhc50.js";
|
|
16
16
|
export {
|
|
17
17
|
dbResolver
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
import"../../../chunk-jksb9ers.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 {
|
|
14
14
|
BaseError
|
|
15
15
|
} from "../../../chunk-9cgzhc50.js";
|
|
@@ -43,6 +43,9 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
43
43
|
query: unknown;
|
|
44
44
|
headers: unknown;
|
|
45
45
|
response: {
|
|
46
|
+
200: {
|
|
47
|
+
message: string;
|
|
48
|
+
};
|
|
46
49
|
422: {
|
|
47
50
|
type: "validation";
|
|
48
51
|
on: string;
|
|
@@ -52,9 +55,6 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
52
55
|
property?: string;
|
|
53
56
|
expected?: string;
|
|
54
57
|
};
|
|
55
|
-
200: {
|
|
56
|
-
message: string;
|
|
57
|
-
};
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
60
|
};
|
|
@@ -68,15 +68,6 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
68
68
|
query: unknown;
|
|
69
69
|
headers: unknown;
|
|
70
70
|
response: {
|
|
71
|
-
422: {
|
|
72
|
-
type: "validation";
|
|
73
|
-
on: string;
|
|
74
|
-
summary?: string;
|
|
75
|
-
message?: string;
|
|
76
|
-
found?: unknown;
|
|
77
|
-
property?: string;
|
|
78
|
-
expected?: string;
|
|
79
|
-
};
|
|
80
71
|
200: {
|
|
81
72
|
message: string;
|
|
82
73
|
content: {
|
|
@@ -86,6 +77,15 @@ export declare const microservice: Elysia<"/microservice", {
|
|
|
86
77
|
author: string;
|
|
87
78
|
};
|
|
88
79
|
};
|
|
80
|
+
422: {
|
|
81
|
+
type: "validation";
|
|
82
|
+
on: string;
|
|
83
|
+
summary?: string;
|
|
84
|
+
message?: string;
|
|
85
|
+
found?: unknown;
|
|
86
|
+
property?: string;
|
|
87
|
+
expected?: string;
|
|
88
|
+
};
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
91
|
};
|
|
@@ -4,50 +4,75 @@ import {
|
|
|
4
4
|
} from "../../../chunk-dre2fgj0.js";
|
|
5
5
|
import {
|
|
6
6
|
MemoryStore
|
|
7
|
-
} from "
|
|
7
|
+
} from "../../kv-store/memory/index.js";
|
|
8
8
|
import"../../../chunk-xhhj1gvj.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/elysia/rate-limit/rate-limit.ts
|
|
16
16
|
import { Elysia } from "elysia";
|
|
17
|
-
var rateLimit = (
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
window
|
|
25
|
-
|
|
26
|
-
}).onRequest(async ({ set, request, server }) => {
|
|
27
|
-
const ip = request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || server?.requestIP(request)?.address || "127.0.0.1";
|
|
28
|
-
const key = `ratelimit:${ip}`;
|
|
29
|
-
const count = await storeInstance.get(key);
|
|
30
|
-
let newCount;
|
|
31
|
-
if (count === null) {
|
|
32
|
-
await storeInstance.set(key, 1, window);
|
|
33
|
-
newCount = 1;
|
|
17
|
+
var rateLimit = (store = new MemoryStore) => {
|
|
18
|
+
const restrictedRoutes = new Map;
|
|
19
|
+
const rateLimitCheck = async (key, limit, window, set) => {
|
|
20
|
+
if (set.headers["X-RateLimit-Limit"])
|
|
21
|
+
return;
|
|
22
|
+
let count = await store.get(key) ?? 0;
|
|
23
|
+
if (count === 0) {
|
|
24
|
+
await store.set(key, 1, window);
|
|
25
|
+
count = 1;
|
|
34
26
|
} else {
|
|
35
|
-
|
|
27
|
+
count = await store.increment(key);
|
|
36
28
|
}
|
|
37
|
-
|
|
29
|
+
const remaining = Math.max(0, limit - count);
|
|
30
|
+
const resetTime = await store.ttl(key);
|
|
31
|
+
set.headers = {
|
|
32
|
+
"X-RateLimit-Limit": limit.toString(),
|
|
33
|
+
"X-RateLimit-Remaining": remaining.toString(),
|
|
34
|
+
"X-RateLimit-Reset": resetTime.toString()
|
|
35
|
+
};
|
|
36
|
+
if (count > limit) {
|
|
38
37
|
set.status = 429;
|
|
39
38
|
throw new HttpError(RATE_LIMIT_ERROR_KEYS.RATE_LIMIT_EXCEEDED, "TOO_MANY_REQUESTS", {
|
|
40
39
|
limit,
|
|
41
40
|
window,
|
|
42
41
|
remaining: 0,
|
|
43
|
-
reset:
|
|
42
|
+
reset: resetTime
|
|
44
43
|
});
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
};
|
|
46
|
+
return new Elysia({
|
|
47
|
+
name: "rateLimit",
|
|
48
|
+
seed: {
|
|
49
|
+
store
|
|
50
|
+
}
|
|
51
|
+
}).macro({
|
|
52
|
+
rateLimit: ({ limit, window }) => ({
|
|
53
|
+
transform: ({ request }) => {
|
|
54
|
+
const route = `${request.method}:${new URL(request.url).pathname}`;
|
|
55
|
+
if (!restrictedRoutes.has(route)) {
|
|
56
|
+
restrictedRoutes.set(route, { limit, window });
|
|
57
|
+
} else if (restrictedRoutes.has(route)) {
|
|
58
|
+
const existing = restrictedRoutes.get(route);
|
|
59
|
+
if (limit != existing.limit || window != existing.window)
|
|
60
|
+
restrictedRoutes.set(route, {
|
|
61
|
+
limit,
|
|
62
|
+
window
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
beforeHandle: async ({ set, request, server }) => {
|
|
67
|
+
const route = `${request.method}:${new URL(request.url).pathname}`;
|
|
68
|
+
if (restrictedRoutes.has(route)) {
|
|
69
|
+
const { limit: limit2, window: window2 } = restrictedRoutes.get(route);
|
|
70
|
+
const ip = request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || server?.requestIP(request)?.address || "127.0.0.1";
|
|
71
|
+
const key = `ratelimit:${route}:${ip}`;
|
|
72
|
+
await rateLimitCheck(key, limit2, window2, set);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
})
|
|
51
76
|
}).as("global");
|
|
52
77
|
};
|
|
53
78
|
export {
|