@catbee/utils 2.0.0-next.0 → 2.0.0
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 +102 -52
- package/array/index.cjs +215 -74
- package/array/index.d.ts +345 -2
- package/array/index.mjs +201 -74
- package/async/index.cjs +116 -39
- package/async/index.d.ts +292 -2
- package/async/index.mjs +116 -40
- package/cache/index.cjs +2 -2
- package/cache/index.d.ts +156 -2
- package/cache/index.mjs +3 -3
- package/config/index.cjs +80 -66
- package/config/index.d.ts +65 -3
- package/config/index.mjs +77 -65
- package/context-store/index.cjs +2 -3
- package/context-store/index.d.ts +193 -2
- package/context-store/index.mjs +2 -3
- package/crypto/index.cjs +55 -5
- package/crypto/index.d.ts +225 -2
- package/crypto/index.mjs +52 -7
- package/date/index.cjs +676 -2
- package/date/index.d.ts +676 -2
- package/date/index.mjs +665 -3
- package/decorator/index.cjs +2172 -0
- package/{decorators/decorators.utils.d.ts → decorator/index.d.ts} +58 -54
- package/decorator/index.mjs +2131 -0
- package/{dir → directory}/index.cjs +5 -4
- package/{dir/dir.utils.d.ts → directory/index.d.ts} +24 -21
- package/{dir → directory}/index.mjs +5 -4
- package/env/index.cjs +100 -68
- package/env/index.d.ts +391 -2
- package/env/index.mjs +100 -68
- package/exception/index.cjs +1 -1
- package/exception/index.d.ts +233 -2
- package/exception/index.mjs +1 -1
- package/fs/index.cjs +71 -37
- package/fs/index.d.ts +206 -2
- package/fs/index.mjs +65 -35
- package/http-status-codes/index.cjs +1 -1
- package/http-status-codes/index.d.ts +268 -2
- package/http-status-codes/index.mjs +1 -1
- package/id/index.cjs +1 -1
- package/id/index.d.ts +38 -2
- package/id/index.mjs +1 -1
- package/index.cjs +13 -13
- package/index.d.ts +5 -5
- package/index.mjs +5 -5
- package/logger/index.cjs +13 -15
- package/logger/index.d.ts +190 -2
- package/logger/index.mjs +14 -16
- package/middleware/index.cjs +1 -1
- package/middleware/index.d.ts +104 -2
- package/middleware/index.mjs +1 -1
- package/object/index.cjs +379 -0
- package/{obj/obj.utils.d.ts → object/index.d.ts} +73 -33
- package/object/index.mjs +360 -0
- package/package.json +41 -23
- package/performance/index.cjs +4 -4
- package/performance/index.d.ts +139 -2
- package/performance/index.mjs +4 -4
- package/request/index.cjs +37 -25
- package/request/index.d.ts +242 -3
- package/request/index.mjs +37 -25
- package/response/index.cjs +1 -1
- package/response/index.d.ts +319 -3
- package/response/index.mjs +1 -1
- package/server/index.cjs +249 -146
- package/server/index.d.ts +866 -5
- package/server/index.mjs +248 -144
- package/stream/index.cjs +1 -1
- package/stream/index.d.ts +91 -2
- package/stream/index.mjs +1 -1
- package/string/index.cjs +34 -1
- package/string/index.d.ts +146 -2
- package/string/index.mjs +31 -2
- package/type/index.cjs +19 -2
- package/type/index.d.ts +144 -2
- package/type/index.mjs +17 -3
- package/types/index.cjs +1 -1
- package/types/index.d.ts +775 -5
- package/types/index.mjs +1 -1
- package/url/index.cjs +63 -5
- package/url/index.d.ts +200 -2
- package/url/index.mjs +59 -6
- package/{validate → validation}/index.cjs +91 -44
- package/{validate/validate.utils.d.ts → validation/index.d.ts} +33 -24
- package/{validate → validation}/index.mjs +87 -44
- package/array/array.utils.d.ts +0 -191
- package/async/async.utils.d.ts +0 -296
- package/cache/cache.utils.d.ts +0 -176
- package/config/config.d.ts +0 -57
- package/context-store/context-store.utils.d.ts +0 -212
- package/crypto/crypto.utils.d.ts +0 -183
- package/date/date.utils.d.ts +0 -190
- package/decorators/index.cjs +0 -913
- package/decorators/index.d.ts +0 -25
- package/decorators/index.mjs +0 -872
- package/dir/index.d.ts +0 -25
- package/env/env.utils.d.ts +0 -400
- package/exception/exception.utils.d.ts +0 -253
- package/fs/fs.utils.d.ts +0 -196
- package/http-status-codes/http-status-codes.d.ts +0 -289
- package/id/id.utils.d.ts +0 -59
- package/logger/logger.utils.d.ts +0 -210
- package/middleware/middleware.utils.d.ts +0 -123
- package/obj/index.cjs +0 -317
- package/obj/index.d.ts +0 -25
- package/obj/index.mjs +0 -301
- package/performance/performance.utils.d.ts +0 -159
- package/request/request.utils.d.ts +0 -109
- package/response/response.utils.d.ts +0 -186
- package/server/server.builder.d.ts +0 -531
- package/server/server.d.ts +0 -303
- package/stream/stream.utils.d.ts +0 -111
- package/string/string.utils.d.ts +0 -124
- package/type/type.utils.d.ts +0 -129
- package/types/api-response.d.ts +0 -175
- package/types/common.d.ts +0 -148
- package/types/config.d.ts +0 -88
- package/types/server.d.ts +0 -291
- package/url/url.utils.d.ts +0 -164
- package/validate/index.d.ts +0 -25
package/async/async.utils.d.ts
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Delays execution for a specified number of milliseconds.
|
|
27
|
-
*
|
|
28
|
-
* @param {number} ms - The number of milliseconds to sleep.
|
|
29
|
-
* @returns {Promise<void>} A Promise that resolves after the given time.
|
|
30
|
-
*/
|
|
31
|
-
export declare function sleep(ms: number): Promise<void>;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a debounced version of a function that delays its execution.
|
|
34
|
-
* Provides `.cancel()` and `.flush()` methods.
|
|
35
|
-
*
|
|
36
|
-
* @template T
|
|
37
|
-
* @param {T} fn - The function to debounce.
|
|
38
|
-
* @param {number} delay - Delay in milliseconds.
|
|
39
|
-
* @returns {T & { cancel: () => void; flush: () => void }} A debounced function.
|
|
40
|
-
*/
|
|
41
|
-
export declare function debounce<T extends (...args: any[]) => void>(fn: T, delay: number): {
|
|
42
|
-
(...args: Parameters<T>): void;
|
|
43
|
-
cancel(): void;
|
|
44
|
-
flush(): void;
|
|
45
|
-
} & {
|
|
46
|
-
cancel: () => void;
|
|
47
|
-
flush: () => void;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Creates a throttled version of a function that limits its execution rate.
|
|
51
|
-
* Allows control over leading/trailing invocation.
|
|
52
|
-
*
|
|
53
|
-
* @template T
|
|
54
|
-
* @param {T} fn - The function to throttle.
|
|
55
|
-
* @param {number} limit - Minimum time between calls in milliseconds.
|
|
56
|
-
* @param {{ leading?: boolean, trailing?: boolean }} [opts] - Options for leading/trailing edge throttling.
|
|
57
|
-
* @returns {(...args: Parameters<T>) => void} A throttled function.
|
|
58
|
-
*/
|
|
59
|
-
export declare function throttle<T extends (...args: any[]) => void>(fn: T, limit: number, opts?: {
|
|
60
|
-
leading?: boolean;
|
|
61
|
-
trailing?: boolean;
|
|
62
|
-
}): (...args: Parameters<T>) => void;
|
|
63
|
-
/**
|
|
64
|
-
* Retries an asynchronous function a given number of times with optional delay/backoff.
|
|
65
|
-
*
|
|
66
|
-
* @template T
|
|
67
|
-
* @param {() => Promise<T>} fn - The async function to retry.
|
|
68
|
-
* @param {number} [retries=3] - Number of retry attempts.
|
|
69
|
-
* @param {number} [delay=500] - Delay in milliseconds between retries.
|
|
70
|
-
* @param {boolean} [backoff=false] - Use exponential backoff between attempts.
|
|
71
|
-
* @param {(error: unknown, attempt: number) => void} [onRetry] - Callback for each retry attempt.
|
|
72
|
-
* @returns {Promise<T>} The result of the async function if successful.
|
|
73
|
-
* @throws {*} The last encountered error if all retries fail.
|
|
74
|
-
*/
|
|
75
|
-
export declare function retry<T>(fn: () => Promise<T>, retries?: number, delay?: number, backoff?: boolean, onRetry?: (error: unknown, attempt: number) => void): Promise<T>;
|
|
76
|
-
/**
|
|
77
|
-
* Wraps a promise and rejects it if it doesn't resolve within the specified timeout.
|
|
78
|
-
*
|
|
79
|
-
* @template T
|
|
80
|
-
* @param {Promise<T>} promise - The original promise.
|
|
81
|
-
* @param {number} ms - Timeout in milliseconds.
|
|
82
|
-
* @param {string} [message="Operation timed out"] - Optional timeout message.
|
|
83
|
-
* @returns {Promise<T>} A promise that resolves or rejects within the timeout.
|
|
84
|
-
*/
|
|
85
|
-
export declare function withTimeout<T>(promise: Promise<T>, ms: number, message?: string): Promise<T>;
|
|
86
|
-
/**
|
|
87
|
-
* Executes async tasks in true batches.
|
|
88
|
-
* Each batch runs in parallel, but batches run sequentially.
|
|
89
|
-
* All tasks in a batch start at the same time, next batch waits for full completion.
|
|
90
|
-
* NOTE: For more granular concurrency, use a "queue" or "pooled" approach.
|
|
91
|
-
*
|
|
92
|
-
* @template T
|
|
93
|
-
* @param {Array<() => Promise<T>>} tasks - An array of functions that return Promises.
|
|
94
|
-
* @param {number} limit - Number of tasks to run in parallel per batch.
|
|
95
|
-
* @returns {Promise<T[]>} A promise that resolves to an array of resolved values.
|
|
96
|
-
*/
|
|
97
|
-
export declare function runInBatches<T>(tasks: (() => Promise<T>)[], limit: number): Promise<T[]>;
|
|
98
|
-
/**
|
|
99
|
-
* Wraps a function and ensures it is only called once at a time.
|
|
100
|
-
* Calls made while one is in progress will wait for the same Promise.
|
|
101
|
-
* Optionally, new calls can be dropped while in progress (drop=true).
|
|
102
|
-
*
|
|
103
|
-
* @template TArgs
|
|
104
|
-
* @template TResult
|
|
105
|
-
* @param {(...args: TArgs) => Promise<TResult>} fn - The async function to wrap.
|
|
106
|
-
* @param {boolean} [drop=false] - If true, new calls while one is pending are rejected.
|
|
107
|
-
* @returns {(...args: TArgs) => Promise<TResult>} A wrapped function with singleton behavior.
|
|
108
|
-
*/
|
|
109
|
-
export declare function singletonAsync<TArgs extends unknown[], TResult>(fn: (...args: TArgs) => Promise<TResult>, drop?: boolean): (...args: TArgs) => Promise<TResult>;
|
|
110
|
-
/**
|
|
111
|
-
* Resolves a list of async tasks in parallel, returning both resolved and rejected results.
|
|
112
|
-
*
|
|
113
|
-
* @template T
|
|
114
|
-
* @param {Array<() => Promise<T>>} tasks - Array of promise-returning functions.
|
|
115
|
-
* @returns {Promise<PromiseSettledResult<T>[]>} Results including status and value/reason.
|
|
116
|
-
*/
|
|
117
|
-
export declare function settleAll<T>(tasks: (() => Promise<T>)[]): Promise<PromiseSettledResult<T>[]>;
|
|
118
|
-
export interface TaskQueue {
|
|
119
|
-
<T>(taskFn: () => Promise<T>): Promise<T>;
|
|
120
|
-
pause: () => void;
|
|
121
|
-
resume: () => void;
|
|
122
|
-
readonly length: number;
|
|
123
|
-
readonly isPaused: boolean;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* A simple task queue that executes async tasks with a concurrency limit.
|
|
127
|
-
* Exposes pause, resume, and queue length getters.
|
|
128
|
-
*
|
|
129
|
-
* @param {number} limit - Maximum number of concurrent tasks.
|
|
130
|
-
* @returns {function & { pause: () => void, resume: () => void, length: number, isPaused: boolean }}
|
|
131
|
-
* Enqueue function plus queue controls.
|
|
132
|
-
*/
|
|
133
|
-
export declare function createTaskQueue(limit: number): TaskQueue;
|
|
134
|
-
/**
|
|
135
|
-
* Executes async functions sequentially and collects results.
|
|
136
|
-
* Useful when order matters or tasks depend on each other.
|
|
137
|
-
*
|
|
138
|
-
* @template T
|
|
139
|
-
* @param {Array<() => Promise<T>>} tasks - Array of promise-returning functions.
|
|
140
|
-
* @returns {Promise<T[]>} Array of resolved values.
|
|
141
|
-
*/
|
|
142
|
-
export declare function runInSeries<T>(tasks: (() => Promise<T>)[]): Promise<T[]>;
|
|
143
|
-
/**
|
|
144
|
-
* Memoizes an async function, caching results for repeated calls with identical arguments.
|
|
145
|
-
* Optional TTL (time-to-live) for cached entries.
|
|
146
|
-
*
|
|
147
|
-
* @template T Function return type
|
|
148
|
-
* @template Args Function arguments types
|
|
149
|
-
* @param {(...args: Args) => Promise<T>} fn - The async function to memoize
|
|
150
|
-
* @param {object} [options] - Memoization options
|
|
151
|
-
* @param {number} [options.ttl] - Cache TTL in milliseconds (optional)
|
|
152
|
-
* @param {(args: Args) => string} [options.keyFn] - Custom key generator function
|
|
153
|
-
* @returns {(...args: Args) => Promise<T>} Memoized function
|
|
154
|
-
*/
|
|
155
|
-
export declare function memoizeAsync<T, Args extends any[]>(fn: (...args: Args) => Promise<T>, options?: {
|
|
156
|
-
ttl?: number;
|
|
157
|
-
keyFn?: (args: Args) => string;
|
|
158
|
-
}): (...args: Args) => Promise<T>;
|
|
159
|
-
/**
|
|
160
|
-
* Creates an abortable version of a promise that can be cancelled using an AbortController.
|
|
161
|
-
*
|
|
162
|
-
* @template T
|
|
163
|
-
* @param {Promise<T>} promise - The promise to make abortable
|
|
164
|
-
* @param {AbortSignal} signal - AbortSignal from AbortController
|
|
165
|
-
* @param {any} [abortValue] - Value to use when rejecting on abort
|
|
166
|
-
* @returns {Promise<T>} Promise that rejects if the signal is aborted
|
|
167
|
-
*/
|
|
168
|
-
export declare function abortable<T>(promise: Promise<T>, signal: AbortSignal, abortValue?: any): Promise<T>;
|
|
169
|
-
/**
|
|
170
|
-
* Creates a promise with external resolve/reject functions.
|
|
171
|
-
* Useful for creating promises that can be resolved or rejected from outside.
|
|
172
|
-
*
|
|
173
|
-
* @template T
|
|
174
|
-
* @returns {[Promise<T>, (value: T | PromiseLike<T>) => void, (reason?: any) => void]}
|
|
175
|
-
* Tuple of [promise, resolve, reject]
|
|
176
|
-
*/
|
|
177
|
-
export declare function createDeferred<T>(): [Promise<T>, (value: T | PromiseLike<T>) => void, (reason?: any) => void];
|
|
178
|
-
/**
|
|
179
|
-
* Chains a series of async functions, passing the result of each to the next.
|
|
180
|
-
* Similar to function composition but for async functions.
|
|
181
|
-
*
|
|
182
|
-
* @template T
|
|
183
|
-
* @param {Array<(input: any) => Promise<any>>} fns - Array of async functions to compose
|
|
184
|
-
* @returns {(input: any) => Promise<T>} Composed function
|
|
185
|
-
*/
|
|
186
|
-
export declare function waterfall<T>(fns: Array<(input: any) => Promise<any>>): (initialValue: any) => Promise<T>;
|
|
187
|
-
/**
|
|
188
|
-
* Creates a rate limiter that ensures functions aren't called more than
|
|
189
|
-
* a specified number of times per interval.
|
|
190
|
-
*
|
|
191
|
-
* @template T
|
|
192
|
-
* @param {(...args: any[]) => Promise<T>} fn - Function to rate limit
|
|
193
|
-
* @param {number} maxCalls - Maximum calls allowed per interval
|
|
194
|
-
* @param {number} interval - Time interval in milliseconds
|
|
195
|
-
* @returns {(...args: any[]) => Promise<T>} Rate limited function
|
|
196
|
-
*/
|
|
197
|
-
export declare function rateLimit<T>(fn: (...args: any[]) => Promise<T>, maxCalls: number, interval: number): (...args: any[]) => Promise<T>;
|
|
198
|
-
/**
|
|
199
|
-
* Circuit breaker pattern implementation for protecting against cascading failures.
|
|
200
|
-
* Tracks failures and prevents calling the function when too many failures occur.
|
|
201
|
-
*
|
|
202
|
-
* @param fn - Function to protect with circuit breaker
|
|
203
|
-
* @param options - Circuit breaker options
|
|
204
|
-
* @returns Function wrapped with circuit breaker logic
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* const protectedFetch = circuitBreaker(
|
|
209
|
-
* async (url) => {
|
|
210
|
-
* const response = await fetch(url);
|
|
211
|
-
* if (!response.ok) throw new Error(`HTTP error: ${response.status}`);
|
|
212
|
-
* return response.json();
|
|
213
|
-
* },
|
|
214
|
-
* {
|
|
215
|
-
* failureThreshold: 3,
|
|
216
|
-
* resetTimeout: 30000,
|
|
217
|
-
* onOpen: () => console.log('Circuit breaker opened'),
|
|
218
|
-
* onClose: () => console.log('Circuit breaker closed')
|
|
219
|
-
* }
|
|
220
|
-
* );
|
|
221
|
-
*
|
|
222
|
-
* // Will throw CircuitBreakerOpenError after failureThreshold consecutive failures
|
|
223
|
-
* try {
|
|
224
|
-
* const data = await protectedFetch('https://api.example.com');
|
|
225
|
-
* } catch (error) {
|
|
226
|
-
* if (error instanceof CircuitBreakerOpenError) {
|
|
227
|
-
* console.log('Service is currently unavailable, please try again later');
|
|
228
|
-
* }
|
|
229
|
-
* }
|
|
230
|
-
* ```
|
|
231
|
-
*/
|
|
232
|
-
export declare class CircuitBreakerOpenError extends Error {
|
|
233
|
-
constructor(message?: string);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Circuit breaker states
|
|
237
|
-
*/
|
|
238
|
-
export declare enum CircuitBreakerState {
|
|
239
|
-
CLOSED = "CLOSED",
|
|
240
|
-
OPEN = "OPEN",
|
|
241
|
-
HALF_OPEN = "HALF_OPEN"
|
|
242
|
-
}
|
|
243
|
-
export interface CircuitBreakerOptions {
|
|
244
|
-
/** Number of consecutive failures before opening circuit (default: 5) */
|
|
245
|
-
failureThreshold?: number;
|
|
246
|
-
/** Time in milliseconds to wait before trying again (default: 10000) */
|
|
247
|
-
resetTimeout?: number;
|
|
248
|
-
/** Number of successful calls to close the circuit again (default: 1) */
|
|
249
|
-
successThreshold?: number;
|
|
250
|
-
/** Callback when circuit opens */
|
|
251
|
-
onOpen?: () => void;
|
|
252
|
-
/** Callback when circuit closes */
|
|
253
|
-
onClose?: () => void;
|
|
254
|
-
/** Callback when circuit enters half-open state */
|
|
255
|
-
onHalfOpen?: () => void;
|
|
256
|
-
}
|
|
257
|
-
export declare function circuitBreaker<T, Args extends any[]>(fn: (...args: Args) => Promise<T>, options?: CircuitBreakerOptions): (...args: Args) => Promise<T>;
|
|
258
|
-
/**
|
|
259
|
-
* Run multiple async tasks with concurrency control.
|
|
260
|
-
*
|
|
261
|
-
* @param tasks - Array of async tasks to run
|
|
262
|
-
* @param options - Concurrency options
|
|
263
|
-
* @returns Promise that resolves when all tasks are complete
|
|
264
|
-
*
|
|
265
|
-
* @example
|
|
266
|
-
* ```typescript
|
|
267
|
-
* const urls = ['https://example.com/1', 'https://example.com/2', many more ];
|
|
268
|
-
*
|
|
269
|
-
* // Process up to 5 requests at a time, with progress reporting
|
|
270
|
-
* const results = await runWithConcurrency(
|
|
271
|
-
* urls.map(url => () => fetch(url).then(res => res.json())),
|
|
272
|
-
* {
|
|
273
|
-
* concurrency: 5,
|
|
274
|
-
* onProgress: (completed, total) => {
|
|
275
|
-
* console.log(`Progress: ${completed}/${total}`);
|
|
276
|
-
* }
|
|
277
|
-
* }
|
|
278
|
-
* );
|
|
279
|
-
* ```
|
|
280
|
-
*/
|
|
281
|
-
export declare function runWithConcurrency<T>(tasks: Array<() => Promise<T>>, options?: {
|
|
282
|
-
/** Maximum number of tasks to run at once (default: 3) */
|
|
283
|
-
concurrency?: number;
|
|
284
|
-
/** Called whenever a task completes */
|
|
285
|
-
onProgress?: (completed: number, total: number) => void;
|
|
286
|
-
/** Abort signal to cancel execution */
|
|
287
|
-
signal?: AbortSignal;
|
|
288
|
-
}): Promise<T[]>;
|
|
289
|
-
/**
|
|
290
|
-
* Optionally requires a module, returning null if not found.
|
|
291
|
-
*
|
|
292
|
-
* @template T
|
|
293
|
-
* @param {string} name - The name of the module to require.
|
|
294
|
-
* @returns {T | null} The required module or null if not found.
|
|
295
|
-
*/
|
|
296
|
-
export declare function optionalRequire<T = any>(name: string): T | null;
|
package/cache/cache.utils.d.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Options for configuring a TTLCache instance.
|
|
27
|
-
*/
|
|
28
|
-
export interface TTLCacheOptions {
|
|
29
|
-
/** Default time-to-live in milliseconds for cache entries */
|
|
30
|
-
ttlMs?: number;
|
|
31
|
-
/** Maximum number of entries to keep in cache (uses LRU eviction policy) */
|
|
32
|
-
maxSize?: number;
|
|
33
|
-
/** Auto-cleanup interval in milliseconds (disabled if 0 or negative) */
|
|
34
|
-
autoCleanupMs?: number;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* An in-memory cache with time-to-live (TTL) support for each entry.
|
|
38
|
-
*
|
|
39
|
-
* @typeParam K - Type of the key.
|
|
40
|
-
* @typeParam V - Type of the value.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* const cache = new TTLCache<string, number>({ ttlMs: 1000 });
|
|
44
|
-
* cache.set("x", 123);
|
|
45
|
-
* const value = cache.get("x"); // 123
|
|
46
|
-
*/
|
|
47
|
-
export declare class TTLCache<K, V> {
|
|
48
|
-
private cache;
|
|
49
|
-
private ttlMs;
|
|
50
|
-
private maxSize?;
|
|
51
|
-
private cleanupInterval?;
|
|
52
|
-
/**
|
|
53
|
-
* @param options - Configuration options for the cache
|
|
54
|
-
*/
|
|
55
|
-
constructor(options?: TTLCacheOptions);
|
|
56
|
-
/**
|
|
57
|
-
* Sets a key-value pair in the cache with the default TTL.
|
|
58
|
-
*
|
|
59
|
-
* @param key - The key to set.
|
|
60
|
-
* @param value - The value to associate with the key.
|
|
61
|
-
*/
|
|
62
|
-
set(key: K, value: V): void;
|
|
63
|
-
/**
|
|
64
|
-
* Sets a key-value pair in the cache with a custom TTL.
|
|
65
|
-
*
|
|
66
|
-
* @param key - The key to set.
|
|
67
|
-
* @param value - The value to associate with the key.
|
|
68
|
-
* @param ttlMs - Time-to-live in milliseconds.
|
|
69
|
-
*/
|
|
70
|
-
setWithTTL(key: K, value: V, ttlMs: number): void;
|
|
71
|
-
/**
|
|
72
|
-
* Retrieves the value for a given key if it hasn't expired.
|
|
73
|
-
*
|
|
74
|
-
* @param key - The key to retrieve.
|
|
75
|
-
* @returns The cached value, or undefined if not found or expired.
|
|
76
|
-
*/
|
|
77
|
-
get(key: K): V | undefined;
|
|
78
|
-
/**
|
|
79
|
-
* Retrieves or computes a value if it's not in the cache or has expired.
|
|
80
|
-
*
|
|
81
|
-
* @param key - The key to retrieve
|
|
82
|
-
* @param producer - Function to generate the value if not cached
|
|
83
|
-
* @param ttlMs - Optional custom TTL for the computed value
|
|
84
|
-
* @returns The cached or computed value
|
|
85
|
-
*/
|
|
86
|
-
getOrCompute(key: K, producer: () => Promise<V>, ttlMs?: number): Promise<V>;
|
|
87
|
-
/**
|
|
88
|
-
* Checks if the key exists and hasn't expired.
|
|
89
|
-
*
|
|
90
|
-
* @param key - The key to check.
|
|
91
|
-
* @returns `true` if key exists and is valid, otherwise `false`.
|
|
92
|
-
*/
|
|
93
|
-
has(key: K): boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Deletes a key from the cache.
|
|
96
|
-
*
|
|
97
|
-
* @param key - The key to delete.
|
|
98
|
-
* @returns `true` if the key existed and was removed, `false` otherwise.
|
|
99
|
-
*/
|
|
100
|
-
delete(key: K): boolean;
|
|
101
|
-
/**
|
|
102
|
-
* Clears all entries from the cache.
|
|
103
|
-
*/
|
|
104
|
-
clear(): void;
|
|
105
|
-
/**
|
|
106
|
-
* Returns the number of entries currently in the cache (includes expired entries until next access/cleanup).
|
|
107
|
-
*
|
|
108
|
-
* @returns Number of items in the cache (may include expired keys).
|
|
109
|
-
*/
|
|
110
|
-
size(): number;
|
|
111
|
-
/**
|
|
112
|
-
* Set multiple key-value pairs at once with the default TTL.
|
|
113
|
-
*
|
|
114
|
-
* @param entries - Array of [key, value] tuples to set
|
|
115
|
-
*/
|
|
116
|
-
setMany(entries: [K, V][]): void;
|
|
117
|
-
/**
|
|
118
|
-
* Get multiple values at once.
|
|
119
|
-
*
|
|
120
|
-
* @param keys - Array of keys to retrieve
|
|
121
|
-
* @returns Array of values (undefined for keys that don't exist or expired)
|
|
122
|
-
*/
|
|
123
|
-
getMany(keys: K[]): (V | undefined)[];
|
|
124
|
-
/**
|
|
125
|
-
* Removes all expired entries from the cache.
|
|
126
|
-
*
|
|
127
|
-
* @returns Number of entries removed.
|
|
128
|
-
*/
|
|
129
|
-
cleanup(): number;
|
|
130
|
-
/**
|
|
131
|
-
* Returns an iterator of all current valid [key, value] pairs.
|
|
132
|
-
*
|
|
133
|
-
* @returns IterableIterator<[K, V]>
|
|
134
|
-
*/
|
|
135
|
-
entries(): IterableIterator<[K, V]>;
|
|
136
|
-
/**
|
|
137
|
-
* Returns an iterator of all current valid keys.
|
|
138
|
-
*
|
|
139
|
-
* @returns IterableIterator<K>
|
|
140
|
-
*/
|
|
141
|
-
keys(): IterableIterator<K>;
|
|
142
|
-
/**
|
|
143
|
-
* Returns an iterator of all current valid values.
|
|
144
|
-
*
|
|
145
|
-
* @returns IterableIterator<V>
|
|
146
|
-
*/
|
|
147
|
-
values(): IterableIterator<V>;
|
|
148
|
-
/**
|
|
149
|
-
* Extends the expiration of a key by the specified time or default TTL.
|
|
150
|
-
*
|
|
151
|
-
* @param key - The key to refresh
|
|
152
|
-
* @param ttlMs - Optional new TTL in milliseconds (uses default if not specified)
|
|
153
|
-
* @returns true if the key was found and refreshed, false otherwise
|
|
154
|
-
*/
|
|
155
|
-
refresh(key: K, ttlMs?: number): boolean;
|
|
156
|
-
/**
|
|
157
|
-
* Returns a snapshot of cache stats.
|
|
158
|
-
*
|
|
159
|
-
* @returns Object containing cache statistics
|
|
160
|
-
*/
|
|
161
|
-
stats(): {
|
|
162
|
-
size: number;
|
|
163
|
-
validEntries: number;
|
|
164
|
-
expiredEntries: number;
|
|
165
|
-
maxSize: number | undefined;
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Stop the auto-cleanup interval if it's running.
|
|
169
|
-
*/
|
|
170
|
-
destroy(): void;
|
|
171
|
-
/**
|
|
172
|
-
* Evict the least recently used entry from the cache.
|
|
173
|
-
* @private
|
|
174
|
-
*/
|
|
175
|
-
private evictLRU;
|
|
176
|
-
}
|
package/config/config.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import type { CatbeeConfig, ServerConfig } from '@catbee/utils/types';
|
|
26
|
-
import type { Logger } from '@catbee/utils/logger';
|
|
27
|
-
/**
|
|
28
|
-
* Extends Express Request interface to add request ID tracking.
|
|
29
|
-
* Added by requestId middleware during request processing.
|
|
30
|
-
*/
|
|
31
|
-
declare global {
|
|
32
|
-
namespace Express {
|
|
33
|
-
interface Request {
|
|
34
|
-
/** Unique request identifier (set by middleware) */
|
|
35
|
-
id?: string;
|
|
36
|
-
/** Logger instance for the request (set by middleware) */
|
|
37
|
-
logger?: Logger;
|
|
38
|
-
/** User information (set by authentication middleware) */
|
|
39
|
-
user?: any;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Application runtime configuration loaded from environment variables.
|
|
45
|
-
*/
|
|
46
|
-
export declare let defaultCatbeeConfig: CatbeeConfig;
|
|
47
|
-
export declare const defaultServerConfig: ServerConfig;
|
|
48
|
-
/**
|
|
49
|
-
* Update the @catbee/utils configuration.
|
|
50
|
-
* @param value Partial configuration object.
|
|
51
|
-
*/
|
|
52
|
-
export declare function setConfig(value: Partial<CatbeeConfig>): void;
|
|
53
|
-
/**
|
|
54
|
-
* Get the current @catbee/utils configuration.
|
|
55
|
-
* @returns The current configuration object.
|
|
56
|
-
*/
|
|
57
|
-
export declare function getConfig(): CatbeeConfig;
|