@forklaunch/core 0.6.6 → 0.7.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.
@@ -11,6 +11,14 @@ interface LogFn {
11
11
  (obj: unknown | LoggerMeta, msg?: string | LoggerMeta, ...args: unknown[]): void;
12
12
  (msg: string | LoggerMeta, ...args: unknown[]): void;
13
13
  }
14
+ interface TelemetryOptions {
15
+ enabled: boolean | {
16
+ metrics?: boolean;
17
+ tracing?: boolean;
18
+ logging?: boolean;
19
+ };
20
+ level: LevelWithSilentOrString;
21
+ }
14
22
 
15
23
  declare class OpenTelemetryCollector<AppliedMetricsDefinition extends MetricsDefinition> {
16
24
  private readonly serviceName;
@@ -41,4 +49,4 @@ declare const httpServerDurationHistogram: Histogram<{
41
49
  "http.response.status_code": number;
42
50
  }>;
43
51
 
44
- export { type LoggerMeta as L, type MetricsDefinition as M, OpenTelemetryCollector as O, type LogFn as a, httpServerDurationHistogram as b, type MetricType as c, httpRequestsTotalCounter as h };
52
+ export { type LoggerMeta as L, type MetricsDefinition as M, OpenTelemetryCollector as O, type TelemetryOptions as T, type LogFn as a, httpServerDurationHistogram as b, type MetricType as c, httpRequestsTotalCounter as h };
@@ -11,6 +11,14 @@ interface LogFn {
11
11
  (obj: unknown | LoggerMeta, msg?: string | LoggerMeta, ...args: unknown[]): void;
12
12
  (msg: string | LoggerMeta, ...args: unknown[]): void;
13
13
  }
14
+ interface TelemetryOptions {
15
+ enabled: boolean | {
16
+ metrics?: boolean;
17
+ tracing?: boolean;
18
+ logging?: boolean;
19
+ };
20
+ level: LevelWithSilentOrString;
21
+ }
14
22
 
15
23
  declare class OpenTelemetryCollector<AppliedMetricsDefinition extends MetricsDefinition> {
16
24
  private readonly serviceName;
@@ -41,4 +49,4 @@ declare const httpServerDurationHistogram: Histogram<{
41
49
  "http.response.status_code": number;
42
50
  }>;
43
51
 
44
- export { type LoggerMeta as L, type MetricsDefinition as M, OpenTelemetryCollector as O, type LogFn as a, httpServerDurationHistogram as b, type MetricType as c, httpRequestsTotalCounter as h };
52
+ export { type LoggerMeta as L, type MetricsDefinition as M, OpenTelemetryCollector as O, type TelemetryOptions as T, type LogFn as a, httpServerDurationHistogram as b, type MetricType as c, httpRequestsTotalCounter as h };
@@ -1,8 +1,19 @@
1
1
  import { RedisClientOptions } from 'redis';
2
- import { O as OpenTelemetryCollector, M as MetricsDefinition } from '../../openTelemetryCollector-CWrfzmmW.mjs';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition, T as TelemetryOptions } from '../../openTelemetryCollector-CmZ3T_2T.mjs';
3
3
  import '@opentelemetry/api';
4
4
  import 'pino';
5
5
 
6
+ /**
7
+ * Creates a function that generates cache keys with a given prefix.
8
+ *
9
+ * @param {string} cacheKeyPrefix - The prefix to use for all cache keys
10
+ * @returns {Function} A function that takes an ID and returns a formatted cache key
11
+ * @example
12
+ * const createUserCacheKey = createCacheKey('user');
13
+ * const key = createUserCacheKey('123'); // Returns 'user:123'
14
+ */
15
+ declare const createCacheKey: (cacheKeyPrefix: string) => (id: string) => string;
16
+
6
17
  /**
7
18
  * Type representing a TTL (Time-To-Live) cache record.
8
19
  *
@@ -28,6 +39,28 @@ interface TtlCache {
28
39
  * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
29
40
  */
30
41
  putRecord<T>(cacheRecord: TtlCacheRecord<T>): Promise<void>;
42
+ /**
43
+ * Puts a batch of records into the cache.
44
+ *
45
+ * @param {TtlCacheRecord<T>[]} cacheRecords - The cache records to put into the cache.
46
+ * @returns {Promise<void>} - A promise that resolves when the records are put into the cache.
47
+ */
48
+ putBatchRecords<T>(cacheRecords: TtlCacheRecord<T>[]): Promise<void>;
49
+ /**
50
+ * Enqueues a record into the cache.
51
+ *
52
+ * @param {string} cacheRecordKey - The key of the cache record to enqueue.
53
+ * @returns {Promise<void>} - A promise that resolves when the record is enqueued into the cache.
54
+ */
55
+ enqueueRecord<T>(queueName: string, cacheRecord: T): Promise<void>;
56
+ /**
57
+ *
58
+ * Enqueues a batch of records into the cache.
59
+ *
60
+ * @param {string[]} cacheRecordKeys - The keys of the cache records to enqueue.
61
+ * @returns {Promise<void>} - A promise that resolves when the records are enqueued into the cache.
62
+ */
63
+ enqueueBatchRecords<T>(queueName: string, cacheRecords: T[]): Promise<void>;
31
64
  /**
32
65
  * Deletes a record from the cache.
33
66
  *
@@ -35,6 +68,27 @@ interface TtlCache {
35
68
  * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.
36
69
  */
37
70
  deleteRecord(cacheRecordKey: string): Promise<void>;
71
+ /**
72
+ * Deletes a batch of records from the cache.
73
+ *
74
+ * @param {string[]} cacheRecordKeys - The keys of the cache records to delete.
75
+ * @returns {Promise<void>} - A promise that resolves when the records are deleted from the cache.
76
+ */
77
+ deleteBatchRecords(cacheRecordKeys: string[]): Promise<void>;
78
+ /**
79
+ * Dequeues a record from the cache.
80
+ *
81
+ * @param {string} cacheRecordKey - The key of the cache record to dequeue.
82
+ * @returns {Promise<void>} - A promise that resolves when the record is dequeued from the cache.
83
+ */
84
+ dequeueRecord<T>(queueName: string): Promise<T>;
85
+ /**
86
+ * Dequeues a batch of records from the cache.
87
+ *
88
+ * @param {string[]} cacheRecordKeys - The keys of the cache records to dequeue.
89
+ * @returns {Promise<void>} - A promise that resolves when the records are dequeued from the cache.
90
+ */
91
+ dequeueBatchRecords<T>(queueName: string, pageSize: number): Promise<T[]>;
38
92
  /**
39
93
  * Reads a record from the cache.
40
94
  *
@@ -42,6 +96,13 @@ interface TtlCache {
42
96
  * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
43
97
  */
44
98
  readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>>;
99
+ /**
100
+ * Reads a batch of records from the cache.
101
+ *
102
+ * @param {string[] | string} cacheRecordKeysOrPrefix - The keys of the cache records to read or a prefix to match.
103
+ * @returns {Promise<TtlCacheRecord<T>[]>} - A promise that resolves with the cache records.
104
+ */
105
+ readBatchRecords<T>(cacheRecordKeysOrPrefix: string[] | string): Promise<TtlCacheRecord<T>[]>;
45
106
  /**
46
107
  * Peeks at a record in the cache to check if it exists.
47
108
  *
@@ -49,6 +110,27 @@ interface TtlCache {
49
110
  * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.
50
111
  */
51
112
  peekRecord(cacheRecordKey: string): Promise<boolean>;
113
+ /**
114
+ * Peeks at a batch of records in the cache to check if they exist.
115
+ *
116
+ * @param {string[] | string} cacheRecordKeysOrPrefix - The keys of the cache records to peek at or a prefix to match.
117
+ * @returns {Promise<boolean[]>} - A promise that resolves with an array of booleans indicating if the records exist.
118
+ */
119
+ peekBatchRecords(cacheRecordKeysOrPrefix: string[] | string): Promise<boolean[]>;
120
+ /**
121
+ * Peeks at a record in the cache to check if it exists.
122
+ *
123
+ * @param {string} queueName - The name of the queue to peek at.
124
+ * @returns {Promise<T>} - A promise that resolves with the record.
125
+ */
126
+ peekQueueRecord<T>(queueName: string): Promise<T>;
127
+ /**
128
+ * Peeks at a batch of records in the cache to check if they exist.
129
+ *
130
+ * @param {string} queueName - The name of the queue to peek at.
131
+ * @returns {Promise<T[]>} - A promise that resolves with the records.
132
+ */
133
+ peekQueueRecords<T>(queueName: string, pageSize: number): Promise<T[]>;
52
134
  /**
53
135
  * Gets the TTL (Time-To-Live) in milliseconds.
54
136
  *
@@ -66,69 +148,173 @@ interface TtlCache {
66
148
 
67
149
  /**
68
150
  * Class representing a Redis-based TTL (Time-To-Live) cache.
69
- * Implements the TtlCache interface.
151
+ * Implements the TtlCache interface to provide caching functionality with automatic expiration.
70
152
  */
71
153
  declare class RedisTtlCache implements TtlCache {
72
154
  private ttlMilliseconds;
73
155
  private openTelemetryCollector;
74
156
  private client;
157
+ private telemetryOptions;
75
158
  /**
76
159
  * Creates an instance of RedisTtlCache.
77
160
  *
78
- * @param {number} ttlMilliseconds - The default TTL in milliseconds.
79
- * @param {RedisClientOptions} [hostingOptions] - The Redis client options.
161
+ * @param {number} ttlMilliseconds - The default Time-To-Live in milliseconds for cache entries
162
+ * @param {OpenTelemetryCollector<MetricsDefinition>} openTelemetryCollector - Collector for OpenTelemetry metrics
163
+ * @param {RedisClientOptions} hostingOptions - Configuration options for the Redis client
164
+ * @param {TelemetryOptions} telemetryOptions - Configuration options for telemetry
165
+ */
166
+ constructor(ttlMilliseconds: number, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, hostingOptions: RedisClientOptions, telemetryOptions: TelemetryOptions);
167
+ /**
168
+ * Parses a raw Redis reply into the expected type.
169
+ * Handles null values, arrays, buffers, and JSON strings.
170
+ *
171
+ * @template T - The expected type of the parsed value
172
+ * @param {RedisCommandRawReply} value - The raw value from Redis to parse
173
+ * @returns {T} The parsed value cast to type T
80
174
  */
81
- constructor(ttlMilliseconds: number, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, hostingOptions?: RedisClientOptions);
175
+ private parseValue;
82
176
  /**
83
177
  * Puts a record into the Redis cache.
84
178
  *
85
- * @param {TtlCacheRecord} param0 - The cache record to put into the cache.
86
- * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
179
+ * @template T - The type of value being cached
180
+ * @param {TtlCacheRecord<T>} param0 - The cache record containing key, value and optional TTL
181
+ * @param {string} param0.key - The key to store the value under
182
+ * @param {T} param0.value - The value to cache
183
+ * @param {number} [param0.ttlMilliseconds] - Optional TTL in milliseconds, defaults to constructor value
184
+ * @returns {Promise<void>} A promise that resolves when the value is cached
87
185
  */
88
186
  putRecord<T>({ key, value, ttlMilliseconds }: TtlCacheRecord<T>): Promise<void>;
187
+ /**
188
+ * Puts multiple records into the Redis cache in a single transaction.
189
+ *
190
+ * @template T - The type of values being cached
191
+ * @param {TtlCacheRecord<T>[]} cacheRecords - Array of cache records to store
192
+ * @returns {Promise<void>} A promise that resolves when all values are cached
193
+ */
194
+ putBatchRecords<T>(cacheRecords: TtlCacheRecord<T>[]): Promise<void>;
195
+ /**
196
+ * Adds a value to the left end of a Redis list.
197
+ *
198
+ * @template T - The type of value being enqueued
199
+ * @param {string} queueName - The name of the Redis list
200
+ * @param {T} value - The value to add to the list
201
+ * @returns {Promise<void>} A promise that resolves when the value is enqueued
202
+ */
203
+ enqueueRecord<T>(queueName: string, value: T): Promise<void>;
204
+ /**
205
+ * Adds multiple values to the left end of a Redis list in a single transaction.
206
+ *
207
+ * @template T - The type of values being enqueued
208
+ * @param {string} queueName - The name of the Redis list
209
+ * @param {T[]} values - Array of values to add to the list
210
+ * @returns {Promise<void>} A promise that resolves when all values are enqueued
211
+ */
212
+ enqueueBatchRecords<T>(queueName: string, values: T[]): Promise<void>;
89
213
  /**
90
214
  * Deletes a record from the Redis cache.
91
215
  *
92
- * @param {string} cacheRecordKey - The key of the cache record to delete.
93
- * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.
216
+ * @param {string} cacheRecordKey - The key of the record to delete
217
+ * @returns {Promise<void>} A promise that resolves when the record is deleted
94
218
  */
95
219
  deleteRecord(cacheRecordKey: string): Promise<void>;
220
+ /**
221
+ * Deletes multiple records from the Redis cache in a single transaction.
222
+ *
223
+ * @param {string[]} cacheRecordKeys - Array of keys to delete
224
+ * @returns {Promise<void>} A promise that resolves when all records are deleted
225
+ */
226
+ deleteBatchRecords(cacheRecordKeys: string[]): Promise<void>;
227
+ /**
228
+ * Removes and returns the rightmost element from a Redis list.
229
+ *
230
+ * @template T - The type of value being dequeued
231
+ * @param {string} queueName - The name of the Redis list
232
+ * @returns {Promise<T>} A promise that resolves with the dequeued value
233
+ * @throws {Error} If the queue is empty
234
+ */
235
+ dequeueRecord<T>(queueName: string): Promise<T>;
236
+ /**
237
+ * Removes and returns multiple elements from the right end of a Redis list.
238
+ *
239
+ * @template T - The type of values being dequeued
240
+ * @param {string} queueName - The name of the Redis list
241
+ * @param {number} pageSize - Maximum number of elements to dequeue
242
+ * @returns {Promise<T[]>} A promise that resolves with an array of dequeued values
243
+ */
244
+ dequeueBatchRecords<T>(queueName: string, pageSize: number): Promise<T[]>;
96
245
  /**
97
246
  * Reads a record from the Redis cache.
98
247
  *
99
- * @param {string} cacheRecordKey - The key of the cache record to read.
100
- * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
101
- * @throws {Error} - Throws an error if the record is not found.
248
+ * @template T - The type of value being read
249
+ * @param {string} cacheRecordKey - The key of the record to read
250
+ * @returns {Promise<TtlCacheRecord<T>>} A promise that resolves with the cache record
251
+ * @throws {Error} If the record is not found
102
252
  */
103
253
  readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>>;
104
254
  /**
105
- * Lists the keys in the Redis cache that match a pattern prefix.
255
+ * Reads multiple records from the Redis cache.
106
256
  *
107
- * @param {string} pattern_prefix - The pattern prefix to match.
108
- * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.
257
+ * @template T - The type of values being read
258
+ * @param {string[] | string} cacheRecordKeysOrPrefix - Array of keys to read, or a prefix pattern
259
+ * @returns {Promise<TtlCacheRecord<T>[]>} A promise that resolves with an array of cache records
260
+ */
261
+ readBatchRecords<T>(cacheRecordKeysOrPrefix: string[] | string): Promise<TtlCacheRecord<T>[]>;
262
+ /**
263
+ * Lists all keys in the Redis cache that match a pattern prefix.
264
+ *
265
+ * @param {string} pattern_prefix - The prefix pattern to match keys against
266
+ * @returns {Promise<string[]>} A promise that resolves with an array of matching keys
109
267
  */
110
268
  listKeys(pattern_prefix: string): Promise<string[]>;
111
269
  /**
112
- * Peeks at a record in the Redis cache to check if it exists.
270
+ * Checks if a record exists in the Redis cache.
113
271
  *
114
- * @param {string} cacheRecordKey - The key of the cache record to peek at.
115
- * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.
272
+ * @param {string} cacheRecordKey - The key to check
273
+ * @returns {Promise<boolean>} A promise that resolves with true if the record exists, false otherwise
116
274
  */
117
275
  peekRecord(cacheRecordKey: string): Promise<boolean>;
118
276
  /**
119
- * Disconnects the Redis client.
277
+ * Checks if multiple records exist in the Redis cache.
120
278
  *
121
- * @returns {Promise<void>} - A promise that resolves when the client is disconnected.
279
+ * @param {string[] | string} cacheRecordKeysOrPrefix - Array of keys to check, or a prefix pattern
280
+ * @returns {Promise<boolean[]>} A promise that resolves with an array of existence booleans
281
+ */
282
+ peekBatchRecords(cacheRecordKeysOrPrefix: string[] | string): Promise<boolean[]>;
283
+ /**
284
+ * Peeks at a record in the Redis cache.
285
+ *
286
+ * @template T - The type of value being peeked at
287
+ * @param {string} queueName - The name of the Redis queue
288
+ * @returns {Promise<T>} A promise that resolves with the peeked value
289
+ */
290
+ peekQueueRecord<T>(queueName: string): Promise<T>;
291
+ /**
292
+ * Peeks at multiple records in the Redis cache.
293
+ *
294
+ * @template T - The type of values being peeked at
295
+ * @param {string} queueName - The name of the Redis queue
296
+ * @param {number} pageSize - The number of records to peek at
297
+ * @returns {Promise<T[]>} A promise that resolves with an array of peeked values
298
+ */
299
+ peekQueueRecords<T>(queueName: string, pageSize: number): Promise<T[]>;
300
+ /**
301
+ * Gracefully disconnects from the Redis server.
302
+ *
303
+ * @returns {Promise<void>} A promise that resolves when the connection is closed
122
304
  */
123
305
  disconnect(): Promise<void>;
124
306
  /**
125
- * Gets the default TTL (Time-To-Live) in milliseconds.
307
+ * Gets the default Time-To-Live value in milliseconds.
126
308
  *
127
- * @returns {number} - The TTL in milliseconds.
309
+ * @returns {number} The default TTL in milliseconds
128
310
  */
129
311
  getTtlMilliseconds(): number;
312
+ /**
313
+ * Gets the underlying Redis client instance.
314
+ *
315
+ * @returns {typeof this.client} The Redis client instance
316
+ */
317
+ getClient(): typeof this.client;
130
318
  }
131
319
 
132
- declare const createCacheKey: (cacheKeyPrefix: string) => (id: string) => string;
133
-
134
320
  export { RedisTtlCache, type TtlCache, type TtlCacheRecord, createCacheKey };