@catbee/utils 0.0.8-rc.2 → 0.0.8-rc.4

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.
Files changed (66) hide show
  1. package/build/index.cjs +6591 -0
  2. package/build/index.d.ts +5131 -0
  3. package/build/index.mjs +6321 -0
  4. package/package.json +12 -36
  5. package/build/esm/config.d.ts +0 -121
  6. package/build/esm/config.js +0 -132
  7. package/build/esm/index.d.ts +0 -26
  8. package/build/esm/index.js +0 -49
  9. package/build/esm/servers/server.builder.d.ts +0 -507
  10. package/build/esm/servers/server.builder.js +0 -654
  11. package/build/esm/servers/server.d.ts +0 -255
  12. package/build/esm/servers/server.js +0 -963
  13. package/build/esm/types/api-response.d.ts +0 -151
  14. package/build/esm/types/api-response.js +0 -33
  15. package/build/esm/types/index.d.ts +0 -124
  16. package/build/esm/types/index.js +0 -24
  17. package/build/esm/types/server.d.ts +0 -267
  18. package/build/esm/types/server.js +0 -24
  19. package/build/esm/utils/array.utils.d.ts +0 -167
  20. package/build/esm/utils/array.utils.js +0 -344
  21. package/build/esm/utils/async.utils.d.ts +0 -264
  22. package/build/esm/utils/async.utils.js +0 -619
  23. package/build/esm/utils/cache.utils.d.ts +0 -152
  24. package/build/esm/utils/cache.utils.js +0 -294
  25. package/build/esm/utils/context-store.utils.d.ts +0 -188
  26. package/build/esm/utils/context-store.utils.js +0 -290
  27. package/build/esm/utils/crypto.utils.d.ts +0 -159
  28. package/build/esm/utils/crypto.utils.js +0 -278
  29. package/build/esm/utils/date.utils.d.ts +0 -158
  30. package/build/esm/utils/date.utils.js +0 -383
  31. package/build/esm/utils/decorators.utils.d.ts +0 -511
  32. package/build/esm/utils/decorators.utils.js +0 -1013
  33. package/build/esm/utils/dir.utils.d.ts +0 -195
  34. package/build/esm/utils/dir.utils.js +0 -476
  35. package/build/esm/utils/env.utils.d.ts +0 -376
  36. package/build/esm/utils/env.utils.js +0 -782
  37. package/build/esm/utils/exception.utils.d.ts +0 -229
  38. package/build/esm/utils/exception.utils.js +0 -382
  39. package/build/esm/utils/fs.utils.d.ts +0 -163
  40. package/build/esm/utils/fs.utils.js +0 -348
  41. package/build/esm/utils/http-status-codes.d.ts +0 -265
  42. package/build/esm/utils/http-status-codes.js +0 -294
  43. package/build/esm/utils/id.utils.d.ts +0 -35
  44. package/build/esm/utils/id.utils.js +0 -83
  45. package/build/esm/utils/logger.utils.d.ts +0 -159
  46. package/build/esm/utils/logger.utils.js +0 -304
  47. package/build/esm/utils/middleware.utils.d.ts +0 -99
  48. package/build/esm/utils/middleware.utils.js +0 -235
  49. package/build/esm/utils/obj.utils.d.ts +0 -123
  50. package/build/esm/utils/obj.utils.js +0 -412
  51. package/build/esm/utils/performance.utils.d.ts +0 -135
  52. package/build/esm/utils/performance.utils.js +0 -273
  53. package/build/esm/utils/request.utils.d.ts +0 -85
  54. package/build/esm/utils/request.utils.js +0 -190
  55. package/build/esm/utils/response.utils.d.ts +0 -162
  56. package/build/esm/utils/response.utils.js +0 -261
  57. package/build/esm/utils/stream.utils.d.ts +0 -87
  58. package/build/esm/utils/stream.utils.js +0 -209
  59. package/build/esm/utils/string.utils.d.ts +0 -92
  60. package/build/esm/utils/string.utils.js +0 -164
  61. package/build/esm/utils/type.utils.d.ts +0 -89
  62. package/build/esm/utils/type.utils.js +0 -186
  63. package/build/esm/utils/url.utils.d.ts +0 -140
  64. package/build/esm/utils/url.utils.js +0 -303
  65. package/build/esm/utils/validate.utils.d.ts +0 -176
  66. package/build/esm/utils/validate.utils.js +0 -319
@@ -1,152 +0,0 @@
1
- /**
2
- * Options for configuring a TTLCache instance.
3
- */
4
- export interface TTLCacheOptions {
5
- /** Default time-to-live in milliseconds for cache entries */
6
- ttlMs?: number;
7
- /** Maximum number of entries to keep in cache (uses LRU eviction policy) */
8
- maxSize?: number;
9
- /** Auto-cleanup interval in milliseconds (disabled if 0 or negative) */
10
- autoCleanupMs?: number;
11
- }
12
- /**
13
- * An in-memory cache with time-to-live (TTL) support for each entry.
14
- *
15
- * @typeParam K - Type of the key.
16
- * @typeParam V - Type of the value.
17
- *
18
- * @example
19
- * const cache = new TTLCache<string, number>({ ttlMs: 1000 });
20
- * cache.set("x", 123);
21
- * const value = cache.get("x"); // 123
22
- */
23
- export declare class TTLCache<K, V> {
24
- private cache;
25
- private ttlMs;
26
- private maxSize?;
27
- private cleanupInterval?;
28
- /**
29
- * @param options - Configuration options for the cache
30
- */
31
- constructor(options?: TTLCacheOptions);
32
- /**
33
- * Sets a key-value pair in the cache with the default TTL.
34
- *
35
- * @param key - The key to set.
36
- * @param value - The value to associate with the key.
37
- */
38
- set(key: K, value: V): void;
39
- /**
40
- * Sets a key-value pair in the cache with a custom TTL.
41
- *
42
- * @param key - The key to set.
43
- * @param value - The value to associate with the key.
44
- * @param ttlMs - Time-to-live in milliseconds.
45
- */
46
- setWithTTL(key: K, value: V, ttlMs: number): void;
47
- /**
48
- * Retrieves the value for a given key if it hasn't expired.
49
- *
50
- * @param key - The key to retrieve.
51
- * @returns The cached value, or undefined if not found or expired.
52
- */
53
- get(key: K): V | undefined;
54
- /**
55
- * Retrieves or computes a value if it's not in the cache or has expired.
56
- *
57
- * @param key - The key to retrieve
58
- * @param producer - Function to generate the value if not cached
59
- * @param ttlMs - Optional custom TTL for the computed value
60
- * @returns The cached or computed value
61
- */
62
- getOrCompute(key: K, producer: () => Promise<V>, ttlMs?: number): Promise<V>;
63
- /**
64
- * Checks if the key exists and hasn't expired.
65
- *
66
- * @param key - The key to check.
67
- * @returns `true` if key exists and is valid, otherwise `false`.
68
- */
69
- has(key: K): boolean;
70
- /**
71
- * Deletes a key from the cache.
72
- *
73
- * @param key - The key to delete.
74
- * @returns `true` if the key existed and was removed, `false` otherwise.
75
- */
76
- delete(key: K): boolean;
77
- /**
78
- * Clears all entries from the cache.
79
- */
80
- clear(): void;
81
- /**
82
- * Returns the number of entries currently in the cache (includes expired entries until next access/cleanup).
83
- *
84
- * @returns Number of items in the cache (may include expired keys).
85
- */
86
- size(): number;
87
- /**
88
- * Set multiple key-value pairs at once with the default TTL.
89
- *
90
- * @param entries - Array of [key, value] tuples to set
91
- */
92
- setMany(entries: [K, V][]): void;
93
- /**
94
- * Get multiple values at once.
95
- *
96
- * @param keys - Array of keys to retrieve
97
- * @returns Array of values (undefined for keys that don't exist or expired)
98
- */
99
- getMany(keys: K[]): (V | undefined)[];
100
- /**
101
- * Removes all expired entries from the cache.
102
- *
103
- * @returns Number of entries removed.
104
- */
105
- cleanup(): number;
106
- /**
107
- * Returns an iterator of all current valid [key, value] pairs.
108
- *
109
- * @returns IterableIterator<[K, V]>
110
- */
111
- entries(): IterableIterator<[K, V]>;
112
- /**
113
- * Returns an iterator of all current valid keys.
114
- *
115
- * @returns IterableIterator<K>
116
- */
117
- keys(): IterableIterator<K>;
118
- /**
119
- * Returns an iterator of all current valid values.
120
- *
121
- * @returns IterableIterator<V>
122
- */
123
- values(): IterableIterator<V>;
124
- /**
125
- * Extends the expiration of a key by the specified time or default TTL.
126
- *
127
- * @param key - The key to refresh
128
- * @param ttlMs - Optional new TTL in milliseconds (uses default if not specified)
129
- * @returns true if the key was found and refreshed, false otherwise
130
- */
131
- refresh(key: K, ttlMs?: number): boolean;
132
- /**
133
- * Returns a snapshot of cache stats.
134
- *
135
- * @returns Object containing cache statistics
136
- */
137
- stats(): {
138
- size: number;
139
- validEntries: number;
140
- expiredEntries: number;
141
- maxSize: number | undefined;
142
- };
143
- /**
144
- * Stop the auto-cleanup interval if it's running.
145
- */
146
- destroy(): void;
147
- /**
148
- * Evict the least recently used entry from the cache.
149
- * @private
150
- */
151
- private evictLRU;
152
- }
@@ -1,294 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/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
- import { config } from '../config';
25
- /**
26
- * An in-memory cache with time-to-live (TTL) support for each entry.
27
- *
28
- * @typeParam K - Type of the key.
29
- * @typeParam V - Type of the value.
30
- *
31
- * @example
32
- * const cache = new TTLCache<string, number>({ ttlMs: 1000 });
33
- * cache.set("x", 123);
34
- * const value = cache.get("x"); // 123
35
- */
36
- export class TTLCache {
37
- cache = new Map();
38
- ttlMs;
39
- maxSize;
40
- cleanupInterval;
41
- /**
42
- * @param options - Configuration options for the cache
43
- */
44
- constructor(options = {}) {
45
- this.ttlMs = options.ttlMs ?? config.cache.defaultTtl;
46
- this.maxSize = options.maxSize;
47
- // Setup auto-cleanup if enabled
48
- const autoCleanupMs = options.autoCleanupMs;
49
- if (autoCleanupMs && autoCleanupMs > 0) {
50
- this.cleanupInterval = setInterval(() => {
51
- this.cleanup();
52
- }, autoCleanupMs);
53
- }
54
- }
55
- /**
56
- * Sets a key-value pair in the cache with the default TTL.
57
- *
58
- * @param key - The key to set.
59
- * @param value - The value to associate with the key.
60
- */
61
- set(key, value) {
62
- this.setWithTTL(key, value, this.ttlMs);
63
- }
64
- /**
65
- * Sets a key-value pair in the cache with a custom TTL.
66
- *
67
- * @param key - The key to set.
68
- * @param value - The value to associate with the key.
69
- * @param ttlMs - Time-to-live in milliseconds.
70
- */
71
- setWithTTL(key, value, ttlMs) {
72
- const now = Date.now();
73
- const expiresAt = now + ttlMs;
74
- if (this.cache.has(key)) {
75
- this.cache.delete(key); // remove old entry to maintain LRU order
76
- }
77
- this.cache.set(key, { value, expiresAt, lastAccessed: now });
78
- if (this.maxSize && this.cache.size > this.maxSize) {
79
- this.evictLRU();
80
- }
81
- }
82
- /**
83
- * Retrieves the value for a given key if it hasn't expired.
84
- *
85
- * @param key - The key to retrieve.
86
- * @returns The cached value, or undefined if not found or expired.
87
- */
88
- get(key) {
89
- const entry = this.cache.get(key);
90
- if (!entry)
91
- return undefined;
92
- const now = Date.now();
93
- if (now > entry.expiresAt) {
94
- this.cache.delete(key);
95
- return undefined;
96
- }
97
- // Update lastAccessed and move key to the end (most recently used)
98
- entry.lastAccessed = now;
99
- // Re-insert to end of Map to maintain LRU order
100
- this.cache.delete(key);
101
- this.cache.set(key, entry);
102
- return entry.value;
103
- }
104
- /**
105
- * Retrieves or computes a value if it's not in the cache or has expired.
106
- *
107
- * @param key - The key to retrieve
108
- * @param producer - Function to generate the value if not cached
109
- * @param ttlMs - Optional custom TTL for the computed value
110
- * @returns The cached or computed value
111
- */
112
- async getOrCompute(key, producer, ttlMs) {
113
- const value = this.get(key);
114
- if (value !== undefined)
115
- return value;
116
- const newValue = await producer();
117
- this.setWithTTL(key, newValue, ttlMs ?? this.ttlMs);
118
- return newValue;
119
- }
120
- /**
121
- * Checks if the key exists and hasn't expired.
122
- *
123
- * @param key - The key to check.
124
- * @returns `true` if key exists and is valid, otherwise `false`.
125
- */
126
- has(key) {
127
- return this.get(key) !== undefined;
128
- }
129
- /**
130
- * Deletes a key from the cache.
131
- *
132
- * @param key - The key to delete.
133
- * @returns `true` if the key existed and was removed, `false` otherwise.
134
- */
135
- delete(key) {
136
- return this.cache.delete(key);
137
- }
138
- /**
139
- * Clears all entries from the cache.
140
- */
141
- clear() {
142
- this.cache.clear();
143
- }
144
- /**
145
- * Returns the number of entries currently in the cache (includes expired entries until next access/cleanup).
146
- *
147
- * @returns Number of items in the cache (may include expired keys).
148
- */
149
- size() {
150
- return this.cache.size;
151
- }
152
- /**
153
- * Set multiple key-value pairs at once with the default TTL.
154
- *
155
- * @param entries - Array of [key, value] tuples to set
156
- */
157
- setMany(entries) {
158
- for (const [key, value] of entries) {
159
- this.set(key, value);
160
- }
161
- }
162
- /**
163
- * Get multiple values at once.
164
- *
165
- * @param keys - Array of keys to retrieve
166
- * @returns Array of values (undefined for keys that don't exist or expired)
167
- */
168
- getMany(keys) {
169
- return keys.map(key => this.get(key));
170
- }
171
- /**
172
- * Removes all expired entries from the cache.
173
- *
174
- * @returns Number of entries removed.
175
- */
176
- cleanup() {
177
- let removed = 0;
178
- const now = Date.now();
179
- for (const [key, entry] of this.cache.entries()) {
180
- if (now > entry.expiresAt) {
181
- this.cache.delete(key);
182
- removed++;
183
- }
184
- }
185
- return removed;
186
- }
187
- /**
188
- * Returns an iterator of all current valid [key, value] pairs.
189
- *
190
- * @returns IterableIterator<[K, V]>
191
- */
192
- *entries() {
193
- for (const [key, entry] of this.cache.entries()) {
194
- if (Date.now() <= entry.expiresAt) {
195
- yield [key, entry.value];
196
- }
197
- }
198
- }
199
- /**
200
- * Returns an iterator of all current valid keys.
201
- *
202
- * @returns IterableIterator<K>
203
- */
204
- *keys() {
205
- for (const [key, entry] of this.cache.entries()) {
206
- if (Date.now() <= entry.expiresAt) {
207
- yield key;
208
- }
209
- }
210
- }
211
- /**
212
- * Returns an iterator of all current valid values.
213
- *
214
- * @returns IterableIterator<V>
215
- */
216
- *values() {
217
- for (const entry of this.cache.values()) {
218
- if (Date.now() <= entry.expiresAt) {
219
- yield entry.value;
220
- }
221
- }
222
- }
223
- /**
224
- * Extends the expiration of a key by the specified time or default TTL.
225
- *
226
- * @param key - The key to refresh
227
- * @param ttlMs - Optional new TTL in milliseconds (uses default if not specified)
228
- * @returns true if the key was found and refreshed, false otherwise
229
- */
230
- refresh(key, ttlMs) {
231
- const entry = this.cache.get(key);
232
- if (!entry)
233
- return false;
234
- const now = Date.now();
235
- if (now > entry.expiresAt) {
236
- this.cache.delete(key);
237
- return false;
238
- }
239
- entry.expiresAt = now + (ttlMs ?? this.ttlMs);
240
- entry.lastAccessed = now;
241
- return true;
242
- }
243
- /**
244
- * Returns a snapshot of cache stats.
245
- *
246
- * @returns Object containing cache statistics
247
- */
248
- stats() {
249
- const now = Date.now();
250
- let expired = 0;
251
- let valid = 0;
252
- for (const entry of this.cache.values()) {
253
- if (now > entry.expiresAt) {
254
- expired++;
255
- }
256
- else {
257
- valid++;
258
- }
259
- }
260
- return {
261
- size: this.cache.size,
262
- validEntries: valid,
263
- expiredEntries: expired,
264
- maxSize: this.maxSize
265
- };
266
- }
267
- /**
268
- * Stop the auto-cleanup interval if it's running.
269
- */
270
- destroy() {
271
- if (this.cleanupInterval) {
272
- clearInterval(this.cleanupInterval);
273
- this.cleanupInterval = undefined;
274
- }
275
- }
276
- /**
277
- * Evict the least recently used entry from the cache.
278
- * @private
279
- */
280
- evictLRU() {
281
- const now = Date.now();
282
- // Remove all expired items first
283
- for (const [key, entry] of Array.from(this.cache.entries())) {
284
- if (now > entry.expiresAt) {
285
- this.cache.delete(key);
286
- }
287
- }
288
- // Evict oldest entries until within max size
289
- while (this.maxSize && this.cache.size > this.maxSize) {
290
- const oldestKey = this.cache.keys().next().value;
291
- this.cache.delete(oldestKey);
292
- }
293
- }
294
- }
@@ -1,188 +0,0 @@
1
- import { AsyncLocalStorage } from 'async_hooks';
2
- /**
3
- * Type representing the store object used in AsyncLocalStorage.
4
- * Keys must be unique symbols to ensure isolation and prevent collisions.
5
- */
6
- export interface Store {
7
- [key: symbol]: unknown;
8
- }
9
- /**
10
- * Predefined symbols used as keys in AsyncLocalStorage.
11
- * Add new symbols here to avoid duplication.
12
- */
13
- export declare const StoreKeys: {
14
- LOGGER: symbol;
15
- REQUEST_ID: symbol;
16
- USER: symbol;
17
- SESSION: symbol;
18
- TRANSACTION_ID: symbol;
19
- USER_ID: symbol;
20
- TENANT_ID: symbol;
21
- TRACE_ID: symbol;
22
- CORRELATION_ID: symbol;
23
- };
24
- /**
25
- * Retrieves the current request ID from the async context, if available.
26
- *
27
- * @returns {string | undefined} The request ID string or undefined if not present in the current context.
28
- */
29
- export declare function getRequestId(): string | undefined;
30
- /**
31
- * Type-safe getter for common context values.
32
- *
33
- * @param key The store key symbol
34
- * @returns The typed value from the store
35
- */
36
- export declare function getFromContext<T>(key: symbol): T | undefined;
37
- /**
38
- * ContextStore manages per-request scoped context using AsyncLocalStorage.
39
- * It allows storing and retrieving data across async calls (e.g., request ID, logger).
40
- *
41
- * Example (Express middleware):
42
- * ```
43
- * // Middleware to initialize context and logger
44
- * app.use((req, res, next) => {
45
- * const requestId = req.headers["x-request-id"]?.toString() || crypto.randomUUID();
46
- * ContextStore.run({ [StoreKeys.REQUEST_ID]: requestId }, () => {
47
- * ContextStore.set(StoreKeys.LOGGER, getLogger().child({ requestId }));
48
- * next();
49
- * });
50
- * });
51
- * ```
52
- */
53
- export declare class ContextStore {
54
- /**
55
- * The underlying AsyncLocalStorage instance for context.
56
- * @private
57
- */
58
- private static readonly storage;
59
- /**
60
- * Returns the raw AsyncLocalStorage instance for advanced access.
61
- *
62
- * @returns {AsyncLocalStorage<Store>} The AsyncLocalStorage instance.
63
- */
64
- static getInstance(): AsyncLocalStorage<Store>;
65
- /**
66
- * Retrieves a value from the async context store by symbol key.
67
- *
68
- * @typeParam T - The expected return type of the value.
69
- * @param {symbol} key - Unique symbol used as the store key.
70
- * @returns {T | undefined} The value found (typed) or undefined if not present.
71
- */
72
- static get<T>(key: symbol): T | undefined;
73
- /**
74
- * Sets a value in the current context store by symbol key.
75
- *
76
- * @typeParam T - The value type to set.
77
- * @param {symbol} key - Unique symbol key.
78
- * @param {T} value - Value to set in context.
79
- * @throws {Error} If called outside an active context (not within a .run call or in the wrong async boundaries).
80
- */
81
- static set<T>(key: symbol, value: T): void;
82
- /**
83
- * Retrieves the entire context store object for the current async context.
84
- *
85
- * @returns {Store | undefined} The current store object or undefined if called outside a context.
86
- */
87
- static getAll(): Store | undefined;
88
- /**
89
- * Initializes a new async context and executes a callback within it.
90
- * This must be called at the beginning of a request or logical async flow.
91
- *
92
- * @typeParam T - The callback's return type.
93
- * @param {Store} store - The initial key-value store object.
94
- * @param {() => T} callback - The function to run within the new context.
95
- * @returns {T} The result of the callback function.
96
- */
97
- static run<T>(store: Store, callback: () => T): T;
98
- /**
99
- * Checks if a key exists in the current context store.
100
- *
101
- * @param {symbol} key - The symbol key to check.
102
- * @returns {boolean} True if the key exists, false otherwise.
103
- */
104
- static has(key: symbol): boolean;
105
- /**
106
- * Removes a value from the current context store by symbol key.
107
- *
108
- * @param {symbol} key - The symbol key to delete.
109
- * @returns {boolean} True if the key was deleted, false if the key wasn't found or no active context.
110
- * @throws {Error} If called outside an active context.
111
- */
112
- static delete(key: symbol): boolean;
113
- /**
114
- * Updates multiple values in the current context store at once.
115
- *
116
- * @param {Partial<Record<symbol, unknown>>} values - Object containing symbol keys and values to update.
117
- * @throws {Error} If called outside an active context.
118
- */
119
- static patch(values: Partial<Record<symbol, unknown>>): void;
120
- /**
121
- * Executes a callback with a temporary store value that only exists during execution.
122
- * Original store is restored after callback completes.
123
- *
124
- * @typeParam T - The callback's return type.
125
- * @param {symbol} key - The symbol key to temporarily set.
126
- * @param {unknown} value - The temporary value.
127
- * @param {() => T} callback - The function to execute with the temporary value.
128
- * @returns {T} The result of the callback function.
129
- * @throws {Error} If called outside an active context.
130
- */
131
- static withValue<T>(key: symbol, value: unknown, callback: () => T): T;
132
- /**
133
- * Creates a new context that inherits values from the current context.
134
- *
135
- * @typeParam T - The callback's return type.
136
- * @param {Partial<Record<symbol, unknown>>} newValues - New values to add to or override in the context.
137
- * @param {() => T} callback - The function to execute in the new context.
138
- * @returns {T} The result of the callback function.
139
- */
140
- static extend<T>(newValues: Partial<Record<symbol, unknown>>, callback: () => T): T;
141
- /**
142
- * Creates Express middleware that initializes a context for each request.
143
- *
144
- * @param {(req: any) => Partial<Record<symbol, unknown>>} initialValuesFactory - Function that returns initial context values.
145
- * @returns Express middleware function.
146
- */
147
- static createExpressMiddleware(initialValuesFactory?: (req: any) => Partial<Record<symbol, unknown>>): (req: any, res: any, next: any) => void;
148
- }
149
- /**
150
- * Type-safe wrapper for accessing and modifying context values with specific types.
151
- *
152
- * @typeParam T - The value type.
153
- */
154
- export declare class TypedContextKey<T> {
155
- private symbol;
156
- private defaultValue?;
157
- /**
158
- * Creates a new typed context key.
159
- *
160
- * @param symbol - The unique symbol for this key
161
- * @param defaultValue - Optional default value if key is not found
162
- */
163
- constructor(symbol: symbol, defaultValue?: T | undefined);
164
- /**
165
- * Gets the current value for this key.
166
- *
167
- * @returns The value or defaultValue if not found
168
- */
169
- get(): T | undefined;
170
- /**
171
- * Sets the value for this key.
172
- *
173
- * @param value The value to set
174
- */
175
- set(value: T): void;
176
- /**
177
- * Checks if this key exists in the context.
178
- *
179
- * @returns True if the key exists
180
- */
181
- exists(): boolean;
182
- /**
183
- * Deletes this key from the context.
184
- *
185
- * @returns True if the key was deleted
186
- */
187
- delete(): boolean;
188
- }