recker 1.0.10 → 1.0.11-alpha.cc0ae8b

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.
@@ -1,57 +0,0 @@
1
- export function rateLimit(options) {
2
- const concurrency = options.concurrency || Infinity;
3
- const limit = options.requestsPerInterval || Infinity;
4
- const interval = options.interval || 1000;
5
- let activeCount = 0;
6
- const queue = [];
7
- let tokens = limit;
8
- let lastRefill = Date.now();
9
- const refillTokens = () => {
10
- const now = Date.now();
11
- const timePassed = now - lastRefill;
12
- if (timePassed >= interval) {
13
- const intervalsPassed = Math.floor(timePassed / interval);
14
- tokens = Math.min(limit, tokens + (intervalsPassed * limit));
15
- lastRefill = now;
16
- }
17
- };
18
- const processQueue = () => {
19
- if (queue.length === 0)
20
- return;
21
- refillTokens();
22
- while (queue.length > 0 && activeCount < concurrency && tokens > 0) {
23
- const next = queue.shift();
24
- if (next) {
25
- activeCount++;
26
- tokens--;
27
- next();
28
- }
29
- }
30
- if (queue.length > 0 && tokens <= 0 && limit !== Infinity) {
31
- const timeToWait = interval - (Date.now() - lastRefill);
32
- setTimeout(processQueue, Math.max(0, timeToWait));
33
- }
34
- };
35
- const rateLimitMiddleware = (req, next) => {
36
- return new Promise((resolve, reject) => {
37
- const run = async () => {
38
- try {
39
- const res = await next(req);
40
- resolve(res);
41
- }
42
- catch (err) {
43
- reject(err);
44
- }
45
- finally {
46
- activeCount--;
47
- processQueue();
48
- }
49
- };
50
- queue.push(run);
51
- processQueue();
52
- });
53
- };
54
- return (client) => {
55
- client.use(rateLimitMiddleware);
56
- };
57
- }
@@ -1,33 +0,0 @@
1
- import { ReckerRequest, ReckerResponse, Timings } from '../types/index.js';
2
- export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
3
- export interface LoggerOptions {
4
- level?: LogLevel;
5
- prefix?: string;
6
- timestamp?: boolean;
7
- colors?: boolean;
8
- }
9
- export declare class Logger {
10
- private level;
11
- private prefix;
12
- private useTimestamp;
13
- private useColors;
14
- constructor(options?: LoggerOptions);
15
- private detectLogLevel;
16
- private supportsColors;
17
- private colorize;
18
- private formatTimestamp;
19
- private shouldLog;
20
- private log;
21
- debug(message: string): void;
22
- info(message: string): void;
23
- warn(message: string): void;
24
- error(message: string): void;
25
- logRequest(req: ReckerRequest): void;
26
- logResponse(req: ReckerRequest, res: ReckerResponse, startTime: number): void;
27
- logTimings(timings: Timings): void;
28
- logError(req: ReckerRequest, error: Error): void;
29
- private formatBytes;
30
- }
31
- export declare function getLogger(): Logger;
32
- export declare function setLogger(logger: Logger): void;
33
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AA2BD,qBAAa,MAAM;IACjB,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,SAAS,CAAU;gBAEf,OAAO,GAAE,aAAkB;IAOvC,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,GAAG;IAQX,KAAK,CAAC,OAAO,EAAE,MAAM;IAIrB,IAAI,CAAC,OAAO,EAAE,MAAM;IAIpB,IAAI,CAAC,OAAO,EAAE,MAAM;IAIpB,KAAK,CAAC,OAAO,EAAE,MAAM;IAOrB,UAAU,CAAC,GAAG,EAAE,aAAa;IAmB7B,WAAW,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM;IA4BtE,UAAU,CAAC,OAAO,EAAE,OAAO;IAoB3B,QAAQ,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK;IAoBzC,OAAO,CAAC,WAAW;CAOpB;AAKD,wBAAgB,SAAS,IAAI,MAAM,CAKlC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,QAEvC"}
@@ -1,160 +0,0 @@
1
- const colors = {
2
- reset: '\x1b[0m',
3
- bright: '\x1b[1m',
4
- dim: '\x1b[2m',
5
- red: '\x1b[31m',
6
- green: '\x1b[32m',
7
- yellow: '\x1b[33m',
8
- blue: '\x1b[34m',
9
- magenta: '\x1b[35m',
10
- cyan: '\x1b[36m',
11
- white: '\x1b[37m',
12
- gray: '\x1b[90m',
13
- };
14
- const levels = {
15
- debug: 0,
16
- info: 1,
17
- warn: 2,
18
- error: 3,
19
- none: 999,
20
- };
21
- export class Logger {
22
- level;
23
- prefix;
24
- useTimestamp;
25
- useColors;
26
- constructor(options = {}) {
27
- this.level = options.level || this.detectLogLevel();
28
- this.prefix = options.prefix || 'recker';
29
- this.useTimestamp = options.timestamp !== false;
30
- this.useColors = options.colors !== false && this.supportsColors();
31
- }
32
- detectLogLevel() {
33
- const env = process.env.DEBUG || '';
34
- if (env === '*' || env.includes('recker') || env.includes('*')) {
35
- return 'debug';
36
- }
37
- return 'none';
38
- }
39
- supportsColors() {
40
- return (process.stdout.isTTY &&
41
- !process.env.NO_COLOR &&
42
- process.env.TERM !== 'dumb');
43
- }
44
- colorize(text, color) {
45
- if (!this.useColors)
46
- return text;
47
- return `${colors[color]}${text}${colors.reset}`;
48
- }
49
- formatTimestamp() {
50
- if (!this.useTimestamp)
51
- return '';
52
- const now = new Date();
53
- const time = now.toTimeString().split(' ')[0];
54
- return this.colorize(`[${time}]`, 'gray') + ' ';
55
- }
56
- shouldLog(level) {
57
- return levels[level] >= levels[this.level];
58
- }
59
- log(level, message) {
60
- if (!this.shouldLog(level))
61
- return;
62
- const timestamp = this.formatTimestamp();
63
- const prefix = this.colorize(`[${this.prefix}]`, 'cyan');
64
- console.log(`${timestamp}${prefix} ${message}`);
65
- }
66
- debug(message) {
67
- this.log('debug', message);
68
- }
69
- info(message) {
70
- this.log('info', message);
71
- }
72
- warn(message) {
73
- this.log('warn', this.colorize(message, 'yellow'));
74
- }
75
- error(message) {
76
- this.log('error', this.colorize(message, 'red'));
77
- }
78
- logRequest(req) {
79
- if (!this.shouldLog('debug'))
80
- return;
81
- const method = this.colorize(req.method, 'blue');
82
- const url = this.colorize(req.url, 'bright');
83
- this.debug(`${this.colorize('→', 'green')} ${method} ${url}`);
84
- if (req.headers && Array.from(req.headers.keys()).length > 0) {
85
- const headerStr = Array.from(req.headers.entries())
86
- .map(([k, v]) => ` ${this.colorize(k, 'gray')}: ${v}`)
87
- .join('\n');
88
- console.log(headerStr);
89
- }
90
- }
91
- logResponse(req, res, startTime) {
92
- if (!this.shouldLog('debug'))
93
- return;
94
- const duration = Date.now() - startTime;
95
- const statusColor = res.ok ? 'green' : 'red';
96
- const status = this.colorize(String(res.status), statusColor);
97
- const method = this.colorize(req.method, 'gray');
98
- this.debug(`${this.colorize('←', 'green')} ${status} ${method} ${req.url} ${this.colorize(`(${duration}ms)`, 'gray')}`);
99
- if (res.timings) {
100
- this.logTimings(res.timings);
101
- }
102
- const contentLength = res.headers.get('content-length');
103
- if (contentLength) {
104
- const size = this.formatBytes(parseInt(contentLength, 10));
105
- console.log(` ${this.colorize('Size:', 'gray')} ${size}`);
106
- }
107
- }
108
- logTimings(timings) {
109
- if (!this.shouldLog('debug'))
110
- return;
111
- const parts = [];
112
- if (timings.dns)
113
- parts.push(`DNS: ${timings.dns.toFixed(0)}ms`);
114
- if (timings.tcp)
115
- parts.push(`TCP: ${timings.tcp.toFixed(0)}ms`);
116
- if (timings.tls)
117
- parts.push(`TLS: ${timings.tls.toFixed(0)}ms`);
118
- if (timings.firstByte)
119
- parts.push(`TTFB: ${timings.firstByte.toFixed(0)}ms`);
120
- if (timings.total)
121
- parts.push(`Total: ${timings.total.toFixed(0)}ms`);
122
- if (parts.length > 0) {
123
- const timelinesStr = parts.join(', ');
124
- console.log(` ${this.colorize('├─', 'gray')} ${timelinesStr}`);
125
- }
126
- }
127
- logError(req, error) {
128
- if (!this.shouldLog('error'))
129
- return;
130
- const method = this.colorize(req.method, 'gray');
131
- this.error(`${this.colorize('✖', 'red')} ${method} ${req.url}`);
132
- console.log(` ${this.colorize('Error:', 'red')} ${error.message}`);
133
- if (error.stack && this.shouldLog('debug')) {
134
- const stack = error.stack
135
- .split('\n')
136
- .slice(1, 4)
137
- .map((line) => ` ${this.colorize('│', 'gray')} ${line.trim()}`)
138
- .join('\n');
139
- console.log(stack);
140
- }
141
- }
142
- formatBytes(bytes) {
143
- if (bytes === 0)
144
- return '0 B';
145
- const k = 1024;
146
- const sizes = ['B', 'KB', 'MB', 'GB'];
147
- const i = Math.floor(Math.log(bytes) / Math.log(k));
148
- return `${(bytes / Math.pow(k, i)).toFixed(1)} ${sizes[i]}`;
149
- }
150
- }
151
- let globalLogger = null;
152
- export function getLogger() {
153
- if (!globalLogger) {
154
- globalLogger = new Logger();
155
- }
156
- return globalLogger;
157
- }
158
- export function setLogger(logger) {
159
- globalLogger = logger;
160
- }
@@ -1,84 +0,0 @@
1
- export declare enum StatusCode {
2
- CONTINUE = 100,
3
- SWITCHING_PROTOCOLS = 101,
4
- PROCESSING = 102,
5
- EARLY_HINTS = 103,
6
- OK = 200,
7
- CREATED = 201,
8
- ACCEPTED = 202,
9
- NON_AUTHORITATIVE_INFORMATION = 203,
10
- NO_CONTENT = 204,
11
- RESET_CONTENT = 205,
12
- PARTIAL_CONTENT = 206,
13
- MULTI_STATUS = 207,
14
- ALREADY_REPORTED = 208,
15
- IM_USED = 226,
16
- MULTIPLE_CHOICES = 300,
17
- MOVED_PERMANENTLY = 301,
18
- FOUND = 302,
19
- SEE_OTHER = 303,
20
- NOT_MODIFIED = 304,
21
- USE_PROXY = 305,
22
- TEMPORARY_REDIRECT = 307,
23
- PERMANENT_REDIRECT = 308,
24
- BAD_REQUEST = 400,
25
- UNAUTHORIZED = 401,
26
- PAYMENT_REQUIRED = 402,
27
- FORBIDDEN = 403,
28
- NOT_FOUND = 404,
29
- METHOD_NOT_ALLOWED = 405,
30
- NOT_ACCEPTABLE = 406,
31
- PROXY_AUTHENTICATION_REQUIRED = 407,
32
- REQUEST_TIMEOUT = 408,
33
- CONFLICT = 409,
34
- GONE = 410,
35
- LENGTH_REQUIRED = 411,
36
- PRECONDITION_FAILED = 412,
37
- PAYLOAD_TOO_LARGE = 413,
38
- URI_TOO_LONG = 414,
39
- UNSUPPORTED_MEDIA_TYPE = 415,
40
- RANGE_NOT_SATISFIABLE = 416,
41
- EXPECTATION_FAILED = 417,
42
- IM_A_TEAPOT = 418,
43
- MISDIRECTED_REQUEST = 421,
44
- UNPROCESSABLE_ENTITY = 422,
45
- LOCKED = 423,
46
- FAILED_DEPENDENCY = 424,
47
- TOO_EARLY = 425,
48
- UPGRADE_REQUIRED = 426,
49
- PRECONDITION_REQUIRED = 428,
50
- TOO_MANY_REQUESTS = 429,
51
- REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
52
- UNAVAILABLE_FOR_LEGAL_REASONS = 451,
53
- INTERNAL_SERVER_ERROR = 500,
54
- NOT_IMPLEMENTED = 501,
55
- BAD_GATEWAY = 502,
56
- SERVICE_UNAVAILABLE = 503,
57
- GATEWAY_TIMEOUT = 504,
58
- HTTP_VERSION_NOT_SUPPORTED = 505,
59
- VARIANT_ALSO_NEGOTIATES = 506,
60
- INSUFFICIENT_STORAGE = 507,
61
- LOOP_DETECTED = 508,
62
- NOT_EXTENDED = 510,
63
- NETWORK_AUTHENTICATION_REQUIRED = 511
64
- }
65
- export declare const STATUS_TEXT: Record<number, string>;
66
- export declare const status: {
67
- isInformational(code: number): boolean;
68
- isSuccess(code: number): boolean;
69
- isRedirect(code: number): boolean;
70
- isClientError(code: number): boolean;
71
- isServerError(code: number): boolean;
72
- isError(code: number): boolean;
73
- isOk(code: number): boolean;
74
- getText(code: number): string | undefined;
75
- getCategory(code: number): string;
76
- };
77
- export declare const statusGroups: {
78
- success: readonly [StatusCode.OK, StatusCode.CREATED, StatusCode.ACCEPTED, StatusCode.NO_CONTENT];
79
- redirect: readonly [StatusCode.MOVED_PERMANENTLY, StatusCode.FOUND, StatusCode.SEE_OTHER, StatusCode.TEMPORARY_REDIRECT, StatusCode.PERMANENT_REDIRECT];
80
- clientError: readonly [StatusCode.BAD_REQUEST, StatusCode.UNAUTHORIZED, StatusCode.FORBIDDEN, StatusCode.NOT_FOUND, StatusCode.METHOD_NOT_ALLOWED, StatusCode.CONFLICT, StatusCode.TOO_MANY_REQUESTS];
81
- serverError: readonly [StatusCode.INTERNAL_SERVER_ERROR, StatusCode.BAD_GATEWAY, StatusCode.SERVICE_UNAVAILABLE, StatusCode.GATEWAY_TIMEOUT];
82
- retryable: readonly [StatusCode.TOO_MANY_REQUESTS, StatusCode.BAD_GATEWAY, StatusCode.SERVICE_UNAVAILABLE, StatusCode.GATEWAY_TIMEOUT];
83
- };
84
- //# sourceMappingURL=status-codes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status-codes.d.ts","sourceRoot":"","sources":["../../src/utils/status-codes.ts"],"names":[],"mappings":"AAUA,oBAAY,UAAU;IAEpB,QAAQ,MAAM;IACd,mBAAmB,MAAM;IACzB,UAAU,MAAM;IAChB,WAAW,MAAM;IAGjB,EAAE,MAAM;IACR,OAAO,MAAM;IACb,QAAQ,MAAM;IACd,6BAA6B,MAAM;IACnC,UAAU,MAAM;IAChB,aAAa,MAAM;IACnB,eAAe,MAAM;IACrB,YAAY,MAAM;IAClB,gBAAgB,MAAM;IACtB,OAAO,MAAM;IAGb,gBAAgB,MAAM;IACtB,iBAAiB,MAAM;IACvB,KAAK,MAAM;IACX,SAAS,MAAM;IACf,YAAY,MAAM;IAClB,SAAS,MAAM;IACf,kBAAkB,MAAM;IACxB,kBAAkB,MAAM;IAGxB,WAAW,MAAM;IACjB,YAAY,MAAM;IAClB,gBAAgB,MAAM;IACtB,SAAS,MAAM;IACf,SAAS,MAAM;IACf,kBAAkB,MAAM;IACxB,cAAc,MAAM;IACpB,6BAA6B,MAAM;IACnC,eAAe,MAAM;IACrB,QAAQ,MAAM;IACd,IAAI,MAAM;IACV,eAAe,MAAM;IACrB,mBAAmB,MAAM;IACzB,iBAAiB,MAAM;IACvB,YAAY,MAAM;IAClB,sBAAsB,MAAM;IAC5B,qBAAqB,MAAM;IAC3B,kBAAkB,MAAM;IACxB,WAAW,MAAM;IACjB,mBAAmB,MAAM;IACzB,oBAAoB,MAAM;IAC1B,MAAM,MAAM;IACZ,iBAAiB,MAAM;IACvB,SAAS,MAAM;IACf,gBAAgB,MAAM;IACtB,qBAAqB,MAAM;IAC3B,iBAAiB,MAAM;IACvB,+BAA+B,MAAM;IACrC,6BAA6B,MAAM;IAGnC,qBAAqB,MAAM;IAC3B,eAAe,MAAM;IACrB,WAAW,MAAM;IACjB,mBAAmB,MAAM;IACzB,eAAe,MAAM;IACrB,0BAA0B,MAAM;IAChC,uBAAuB,MAAM;IAC7B,oBAAoB,MAAM;IAC1B,aAAa,MAAM;IACnB,YAAY,MAAM;IAClB,+BAA+B,MAAM;CACtC;AAKD,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAwE9C,CAAC;AAKF,eAAO,MAAM,MAAM;0BAIK,MAAM,GAAG,OAAO;oBAOtB,MAAM,GAAG,OAAO;qBAOf,MAAM,GAAG,OAAO;wBAOb,MAAM,GAAG,OAAO;wBAOhB,MAAM,GAAG,OAAO;kBAOtB,MAAM,GAAG,OAAO;eAQnB,MAAM,GAAG,OAAO;kBAOb,MAAM,GAAG,MAAM,GAAG,SAAS;sBAOvB,MAAM,GAAG,MAAM;CAQlC,CAAC;AAKF,eAAO,MAAM,YAAY;;;;;;CAsDxB,CAAC"}
@@ -1,204 +0,0 @@
1
- export var StatusCode;
2
- (function (StatusCode) {
3
- StatusCode[StatusCode["CONTINUE"] = 100] = "CONTINUE";
4
- StatusCode[StatusCode["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
5
- StatusCode[StatusCode["PROCESSING"] = 102] = "PROCESSING";
6
- StatusCode[StatusCode["EARLY_HINTS"] = 103] = "EARLY_HINTS";
7
- StatusCode[StatusCode["OK"] = 200] = "OK";
8
- StatusCode[StatusCode["CREATED"] = 201] = "CREATED";
9
- StatusCode[StatusCode["ACCEPTED"] = 202] = "ACCEPTED";
10
- StatusCode[StatusCode["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
11
- StatusCode[StatusCode["NO_CONTENT"] = 204] = "NO_CONTENT";
12
- StatusCode[StatusCode["RESET_CONTENT"] = 205] = "RESET_CONTENT";
13
- StatusCode[StatusCode["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
14
- StatusCode[StatusCode["MULTI_STATUS"] = 207] = "MULTI_STATUS";
15
- StatusCode[StatusCode["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
16
- StatusCode[StatusCode["IM_USED"] = 226] = "IM_USED";
17
- StatusCode[StatusCode["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
18
- StatusCode[StatusCode["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
19
- StatusCode[StatusCode["FOUND"] = 302] = "FOUND";
20
- StatusCode[StatusCode["SEE_OTHER"] = 303] = "SEE_OTHER";
21
- StatusCode[StatusCode["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
22
- StatusCode[StatusCode["USE_PROXY"] = 305] = "USE_PROXY";
23
- StatusCode[StatusCode["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
24
- StatusCode[StatusCode["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
25
- StatusCode[StatusCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
26
- StatusCode[StatusCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
27
- StatusCode[StatusCode["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
28
- StatusCode[StatusCode["FORBIDDEN"] = 403] = "FORBIDDEN";
29
- StatusCode[StatusCode["NOT_FOUND"] = 404] = "NOT_FOUND";
30
- StatusCode[StatusCode["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
31
- StatusCode[StatusCode["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
32
- StatusCode[StatusCode["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
33
- StatusCode[StatusCode["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
34
- StatusCode[StatusCode["CONFLICT"] = 409] = "CONFLICT";
35
- StatusCode[StatusCode["GONE"] = 410] = "GONE";
36
- StatusCode[StatusCode["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
37
- StatusCode[StatusCode["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
38
- StatusCode[StatusCode["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
39
- StatusCode[StatusCode["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
40
- StatusCode[StatusCode["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
41
- StatusCode[StatusCode["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
42
- StatusCode[StatusCode["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
43
- StatusCode[StatusCode["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
44
- StatusCode[StatusCode["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
45
- StatusCode[StatusCode["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
46
- StatusCode[StatusCode["LOCKED"] = 423] = "LOCKED";
47
- StatusCode[StatusCode["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
48
- StatusCode[StatusCode["TOO_EARLY"] = 425] = "TOO_EARLY";
49
- StatusCode[StatusCode["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
50
- StatusCode[StatusCode["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
51
- StatusCode[StatusCode["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
52
- StatusCode[StatusCode["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
53
- StatusCode[StatusCode["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
54
- StatusCode[StatusCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
55
- StatusCode[StatusCode["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
56
- StatusCode[StatusCode["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
57
- StatusCode[StatusCode["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
58
- StatusCode[StatusCode["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
59
- StatusCode[StatusCode["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
60
- StatusCode[StatusCode["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
61
- StatusCode[StatusCode["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
62
- StatusCode[StatusCode["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
63
- StatusCode[StatusCode["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
64
- StatusCode[StatusCode["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
65
- })(StatusCode || (StatusCode = {}));
66
- export const STATUS_TEXT = {
67
- [StatusCode.CONTINUE]: 'Continue',
68
- [StatusCode.SWITCHING_PROTOCOLS]: 'Switching Protocols',
69
- [StatusCode.PROCESSING]: 'Processing',
70
- [StatusCode.EARLY_HINTS]: 'Early Hints',
71
- [StatusCode.OK]: 'OK',
72
- [StatusCode.CREATED]: 'Created',
73
- [StatusCode.ACCEPTED]: 'Accepted',
74
- [StatusCode.NON_AUTHORITATIVE_INFORMATION]: 'Non-Authoritative Information',
75
- [StatusCode.NO_CONTENT]: 'No Content',
76
- [StatusCode.RESET_CONTENT]: 'Reset Content',
77
- [StatusCode.PARTIAL_CONTENT]: 'Partial Content',
78
- [StatusCode.MULTI_STATUS]: 'Multi-Status',
79
- [StatusCode.ALREADY_REPORTED]: 'Already Reported',
80
- [StatusCode.IM_USED]: 'IM Used',
81
- [StatusCode.MULTIPLE_CHOICES]: 'Multiple Choices',
82
- [StatusCode.MOVED_PERMANENTLY]: 'Moved Permanently',
83
- [StatusCode.FOUND]: 'Found',
84
- [StatusCode.SEE_OTHER]: 'See Other',
85
- [StatusCode.NOT_MODIFIED]: 'Not Modified',
86
- [StatusCode.USE_PROXY]: 'Use Proxy',
87
- [StatusCode.TEMPORARY_REDIRECT]: 'Temporary Redirect',
88
- [StatusCode.PERMANENT_REDIRECT]: 'Permanent Redirect',
89
- [StatusCode.BAD_REQUEST]: 'Bad Request',
90
- [StatusCode.UNAUTHORIZED]: 'Unauthorized',
91
- [StatusCode.PAYMENT_REQUIRED]: 'Payment Required',
92
- [StatusCode.FORBIDDEN]: 'Forbidden',
93
- [StatusCode.NOT_FOUND]: 'Not Found',
94
- [StatusCode.METHOD_NOT_ALLOWED]: 'Method Not Allowed',
95
- [StatusCode.NOT_ACCEPTABLE]: 'Not Acceptable',
96
- [StatusCode.PROXY_AUTHENTICATION_REQUIRED]: 'Proxy Authentication Required',
97
- [StatusCode.REQUEST_TIMEOUT]: 'Request Timeout',
98
- [StatusCode.CONFLICT]: 'Conflict',
99
- [StatusCode.GONE]: 'Gone',
100
- [StatusCode.LENGTH_REQUIRED]: 'Length Required',
101
- [StatusCode.PRECONDITION_FAILED]: 'Precondition Failed',
102
- [StatusCode.PAYLOAD_TOO_LARGE]: 'Payload Too Large',
103
- [StatusCode.URI_TOO_LONG]: 'URI Too Long',
104
- [StatusCode.UNSUPPORTED_MEDIA_TYPE]: 'Unsupported Media Type',
105
- [StatusCode.RANGE_NOT_SATISFIABLE]: 'Range Not Satisfiable',
106
- [StatusCode.EXPECTATION_FAILED]: 'Expectation Failed',
107
- [StatusCode.IM_A_TEAPOT]: "I'm a teapot",
108
- [StatusCode.MISDIRECTED_REQUEST]: 'Misdirected Request',
109
- [StatusCode.UNPROCESSABLE_ENTITY]: 'Unprocessable Entity',
110
- [StatusCode.LOCKED]: 'Locked',
111
- [StatusCode.FAILED_DEPENDENCY]: 'Failed Dependency',
112
- [StatusCode.TOO_EARLY]: 'Too Early',
113
- [StatusCode.UPGRADE_REQUIRED]: 'Upgrade Required',
114
- [StatusCode.PRECONDITION_REQUIRED]: 'Precondition Required',
115
- [StatusCode.TOO_MANY_REQUESTS]: 'Too Many Requests',
116
- [StatusCode.REQUEST_HEADER_FIELDS_TOO_LARGE]: 'Request Header Fields Too Large',
117
- [StatusCode.UNAVAILABLE_FOR_LEGAL_REASONS]: 'Unavailable For Legal Reasons',
118
- [StatusCode.INTERNAL_SERVER_ERROR]: 'Internal Server Error',
119
- [StatusCode.NOT_IMPLEMENTED]: 'Not Implemented',
120
- [StatusCode.BAD_GATEWAY]: 'Bad Gateway',
121
- [StatusCode.SERVICE_UNAVAILABLE]: 'Service Unavailable',
122
- [StatusCode.GATEWAY_TIMEOUT]: 'Gateway Timeout',
123
- [StatusCode.HTTP_VERSION_NOT_SUPPORTED]: 'HTTP Version Not Supported',
124
- [StatusCode.VARIANT_ALSO_NEGOTIATES]: 'Variant Also Negotiates',
125
- [StatusCode.INSUFFICIENT_STORAGE]: 'Insufficient Storage',
126
- [StatusCode.LOOP_DETECTED]: 'Loop Detected',
127
- [StatusCode.NOT_EXTENDED]: 'Not Extended',
128
- [StatusCode.NETWORK_AUTHENTICATION_REQUIRED]: 'Network Authentication Required',
129
- };
130
- export const status = {
131
- isInformational(code) {
132
- return code >= 100 && code < 200;
133
- },
134
- isSuccess(code) {
135
- return code >= 200 && code < 300;
136
- },
137
- isRedirect(code) {
138
- return code >= 300 && code < 400;
139
- },
140
- isClientError(code) {
141
- return code >= 400 && code < 500;
142
- },
143
- isServerError(code) {
144
- return code >= 500 && code < 600;
145
- },
146
- isError(code) {
147
- return code >= 400 && code < 600;
148
- },
149
- isOk(code) {
150
- return this.isSuccess(code);
151
- },
152
- getText(code) {
153
- return STATUS_TEXT[code];
154
- },
155
- getCategory(code) {
156
- if (this.isInformational(code))
157
- return 'Informational';
158
- if (this.isSuccess(code))
159
- return 'Success';
160
- if (this.isRedirect(code))
161
- return 'Redirection';
162
- if (this.isClientError(code))
163
- return 'Client Error';
164
- if (this.isServerError(code))
165
- return 'Server Error';
166
- return 'Unknown';
167
- },
168
- };
169
- export const statusGroups = {
170
- success: [
171
- StatusCode.OK,
172
- StatusCode.CREATED,
173
- StatusCode.ACCEPTED,
174
- StatusCode.NO_CONTENT,
175
- ],
176
- redirect: [
177
- StatusCode.MOVED_PERMANENTLY,
178
- StatusCode.FOUND,
179
- StatusCode.SEE_OTHER,
180
- StatusCode.TEMPORARY_REDIRECT,
181
- StatusCode.PERMANENT_REDIRECT,
182
- ],
183
- clientError: [
184
- StatusCode.BAD_REQUEST,
185
- StatusCode.UNAUTHORIZED,
186
- StatusCode.FORBIDDEN,
187
- StatusCode.NOT_FOUND,
188
- StatusCode.METHOD_NOT_ALLOWED,
189
- StatusCode.CONFLICT,
190
- StatusCode.TOO_MANY_REQUESTS,
191
- ],
192
- serverError: [
193
- StatusCode.INTERNAL_SERVER_ERROR,
194
- StatusCode.BAD_GATEWAY,
195
- StatusCode.SERVICE_UNAVAILABLE,
196
- StatusCode.GATEWAY_TIMEOUT,
197
- ],
198
- retryable: [
199
- StatusCode.TOO_MANY_REQUESTS,
200
- StatusCode.BAD_GATEWAY,
201
- StatusCode.SERVICE_UNAVAILABLE,
202
- StatusCode.GATEWAY_TIMEOUT,
203
- ],
204
- };
@@ -1,38 +0,0 @@
1
- export interface TaskPoolOptions {
2
- /**
3
- * Max concurrent tasks allowed to execute at once.
4
- * @default Infinity (no concurrency cap)
5
- */
6
- concurrency?: number;
7
- /**
8
- * Requests allowed per interval window.
9
- * When provided with `interval`, starts will be spaced to respect the cap.
10
- */
11
- requestsPerInterval?: number;
12
- /**
13
- * Interval window length in milliseconds.
14
- */
15
- interval?: number;
16
- }
17
- /**
18
- * Lightweight TaskPool for rate limiting and concurrency control.
19
- *
20
- * - Limits concurrent executions.
21
- * - Enforces a max start rate (`requestsPerInterval` / `interval`) via a sliding window.
22
- * - Respects AbortSignal both while queued and while running.
23
- */
24
- export declare class TaskPool {
25
- private readonly concurrency;
26
- private readonly requestsPerInterval?;
27
- private readonly interval?;
28
- private queue;
29
- private active;
30
- private windowStart;
31
- private startedInWindow;
32
- private waitingTimer?;
33
- constructor(options?: TaskPoolOptions);
34
- run<T>(fn: () => Promise<T>, signal?: AbortSignal): Promise<T>;
35
- private _removeFromQueue;
36
- private _canStart;
37
- private _schedule;
38
- }