@ls-stack/utils 3.40.0 → 3.41.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/dist/arrayUtils.d.cts +70 -57
- package/dist/arrayUtils.d.ts +70 -57
- package/dist/assertions.d.cts +128 -117
- package/dist/assertions.d.ts +128 -117
- package/dist/asyncQueue.cjs +117 -112
- package/dist/asyncQueue.d.cts +217 -215
- package/dist/asyncQueue.d.ts +217 -215
- package/dist/asyncQueue.js +117 -112
- package/dist/awaitDebounce.d.cts +26 -23
- package/dist/awaitDebounce.d.ts +26 -23
- package/dist/cache.cjs +2 -1
- package/dist/cache.d.cts +15 -9
- package/dist/cache.d.ts +15 -9
- package/dist/cache.js +2 -1
- package/dist/{chunk-GHAQOUA6.js → chunk-23KPGKDT.js} +22 -1
- package/dist/{chunk-ADM37GSC.js → chunk-7L4KCZJJ.js} +12 -10
- package/dist/{chunk-KW55OTUG.js → chunk-B3KFV2MH.js} +2 -2
- package/dist/chunk-DTE2QMWE.js +48 -0
- package/dist/concurrentCalls.d.cts +8 -4
- package/dist/concurrentCalls.d.ts +8 -4
- package/dist/concurrentCalls.js +1 -1
- package/dist/debounce.d.cts +12 -20
- package/dist/debounce.d.ts +12 -20
- package/dist/dedent.d.cts +31 -31
- package/dist/dedent.d.ts +31 -31
- package/dist/deepEqual.d.cts +10 -9
- package/dist/deepEqual.d.ts +10 -9
- package/dist/filterObjectOrArrayKeys.d.cts +44 -19
- package/dist/filterObjectOrArrayKeys.d.ts +44 -19
- package/dist/getAutoIncrementId.d.cts +25 -23
- package/dist/getAutoIncrementId.d.ts +25 -23
- package/dist/getCompositeKey.d.cts +2 -1
- package/dist/getCompositeKey.d.ts +2 -1
- package/dist/getValueStableKey.d.cts +4 -3
- package/dist/getValueStableKey.d.ts +4 -3
- package/dist/mutationUtils.d.cts +2 -2
- package/dist/mutationUtils.d.ts +2 -2
- package/dist/objUtils.cjs +51 -2
- package/dist/objUtils.d.cts +8 -3
- package/dist/objUtils.d.ts +8 -3
- package/dist/objUtils.js +11 -3
- package/dist/parallelAsyncCalls.cjs +2 -1
- package/dist/parallelAsyncCalls.d.cts +5 -4
- package/dist/parallelAsyncCalls.d.ts +5 -4
- package/dist/parallelAsyncCalls.js +2 -1
- package/dist/retryOnError.d.cts +23 -20
- package/dist/retryOnError.d.ts +23 -20
- package/dist/runShellCmd.d.cts +40 -40
- package/dist/runShellCmd.d.ts +40 -40
- package/dist/safeJson.d.cts +6 -2
- package/dist/safeJson.d.ts +6 -2
- package/dist/saferTyping.d.cts +21 -14
- package/dist/saferTyping.d.ts +21 -14
- package/dist/shallowEqual.d.cts +1 -1
- package/dist/shallowEqual.d.ts +1 -1
- package/dist/stringUtils.cjs +2 -2
- package/dist/stringUtils.d.cts +6 -7
- package/dist/stringUtils.d.ts +6 -7
- package/dist/stringUtils.js +1 -1
- package/dist/testUtils.cjs +11 -9
- package/dist/testUtils.d.cts +32 -14
- package/dist/testUtils.d.ts +32 -14
- package/dist/testUtils.js +4 -3
- package/dist/throttle.d.cts +57 -48
- package/dist/throttle.d.ts +57 -48
- package/dist/timers.d.cts +68 -63
- package/dist/timers.d.ts +68 -63
- package/dist/tsResult.d.cts +7 -6
- package/dist/tsResult.d.ts +7 -6
- package/dist/typeGuards.d.cts +65 -64
- package/dist/typeGuards.d.ts +65 -64
- package/dist/typeUtils.d.cts +18 -4
- package/dist/typeUtils.d.ts +18 -4
- package/dist/typedStrings.d.cts +68 -57
- package/dist/typedStrings.d.ts +68 -57
- package/dist/typingFnUtils.d.cts +12 -6
- package/dist/typingFnUtils.d.ts +12 -6
- package/dist/typingFnUtils.js +12 -35
- package/dist/typingTestUtils.cjs +7 -1
- package/dist/typingTestUtils.d.cts +52 -11
- package/dist/typingTestUtils.d.ts +52 -11
- package/dist/typingTestUtils.js +7 -1
- package/dist/typingUtils.d.cts +4 -1
- package/dist/typingUtils.d.ts +4 -1
- package/dist/yamlStringify.cjs +11 -9
- package/dist/yamlStringify.js +2 -2
- package/package.json +5 -1
- package/docs/README.md +0 -72
- package/docs/_media/modules.md +0 -58
- package/docs/arrayUtils/-internal-.md +0 -179
- package/docs/arrayUtils/README.md +0 -550
- package/docs/assertions/-internal-.md +0 -63
- package/docs/assertions/README.md +0 -565
- package/docs/asyncQueue/-internal-.md +0 -297
- package/docs/asyncQueue/README.md +0 -1485
- package/docs/awaitDebounce.md +0 -66
- package/docs/cache/-internal-.md +0 -168
- package/docs/cache/README.md +0 -360
- package/docs/castValues.md +0 -47
- package/docs/concurrentCalls/-internal-.md +0 -490
- package/docs/concurrentCalls/README.md +0 -299
- package/docs/consoleFmt.md +0 -115
- package/docs/conversions.md +0 -27
- package/docs/createThrottleController/-internal-.md +0 -73
- package/docs/createThrottleController/README.md +0 -31
- package/docs/debounce.md +0 -188
- package/docs/dedent/-internal-.md +0 -17
- package/docs/dedent/README.md +0 -204
- package/docs/deepEqual.md +0 -94
- package/docs/enhancedMap.md +0 -358
- package/docs/exhaustiveMatch/-internal-.md +0 -39
- package/docs/exhaustiveMatch/README.md +0 -146
- package/docs/filterObjectOrArrayKeys.md +0 -109
- package/docs/getAutoIncrementId.md +0 -93
- package/docs/getCompositeKey.md +0 -39
- package/docs/getValueStableKey.md +0 -57
- package/docs/hash.md +0 -31
- package/docs/interpolate/-internal-.md +0 -61
- package/docs/interpolate/README.md +0 -62
- package/docs/keepPrevIfUnchanged.md +0 -43
- package/docs/levenshtein.md +0 -93
- package/docs/main.md +0 -21
- package/docs/mathUtils.md +0 -137
- package/docs/modules.md +0 -58
- package/docs/mutationUtils.md +0 -44
- package/docs/objUtils.md +0 -237
- package/docs/parallelAsyncCalls/-internal-.md +0 -347
- package/docs/parallelAsyncCalls/README.md +0 -45
- package/docs/promiseUtils/-internal-.md +0 -69
- package/docs/promiseUtils/README.md +0 -31
- package/docs/retryOnError/-internal-.md +0 -111
- package/docs/retryOnError/README.md +0 -168
- package/docs/runShellCmd/-internal-.md +0 -111
- package/docs/runShellCmd/README.md +0 -201
- package/docs/safeJson.md +0 -51
- package/docs/saferTyping.md +0 -228
- package/docs/serializeXML.md +0 -100
- package/docs/shallowEqual.md +0 -33
- package/docs/sleep.md +0 -27
- package/docs/stringUtils/-internal-.md +0 -17
- package/docs/stringUtils/README.md +0 -270
- package/docs/testUtils.md +0 -382
- package/docs/throttle/-internal-.md +0 -47
- package/docs/throttle/README.md +0 -178
- package/docs/time.md +0 -274
- package/docs/timers.md +0 -256
- package/docs/tsResult/-internal-.md +0 -327
- package/docs/tsResult/README.md +0 -702
- package/docs/typeGuards.md +0 -399
- package/docs/typeUtils/-internal-.md +0 -99
- package/docs/typeUtils/README.md +0 -195
- package/docs/typeUtils.typesTest.md +0 -7
- package/docs/typedStrings.md +0 -458
- package/docs/typingFnUtils/-internal-.md +0 -43
- package/docs/typingFnUtils/README.md +0 -317
- package/docs/typingTestUtils.md +0 -172
- package/docs/typingUtils.md +0 -135
- package/docs/yamlStringify.md +0 -83
package/dist/asyncQueue.js
CHANGED
|
@@ -27,22 +27,23 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
27
27
|
/**
|
|
28
28
|
* Event emitter for tracking task lifecycle
|
|
29
29
|
*
|
|
30
|
-
* @example
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* @example
|
|
31
|
+
* Listening to Events
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const queue = createAsyncQueue<string>();
|
|
33
34
|
*
|
|
34
|
-
*
|
|
35
|
+
* queue.events.on('start', (event) => {
|
|
35
36
|
* console.log('Task started:', event.payload.meta);
|
|
36
|
-
*
|
|
37
|
+
* });
|
|
37
38
|
*
|
|
38
|
-
*
|
|
39
|
+
* queue.events.on('complete', (event) => {
|
|
39
40
|
* console.log('Task completed:', event.payload.value);
|
|
40
|
-
*
|
|
41
|
+
* });
|
|
41
42
|
*
|
|
42
|
-
*
|
|
43
|
+
* queue.events.on('error', (event) => {
|
|
43
44
|
* console.error('Task failed:', event.payload.error);
|
|
44
|
-
*
|
|
45
|
-
*
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
46
47
|
*/
|
|
47
48
|
events = evtmitter();
|
|
48
49
|
#signal;
|
|
@@ -156,32 +157,33 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
156
157
|
/**
|
|
157
158
|
* Add a task that returns a Result to the queue
|
|
158
159
|
*
|
|
159
|
-
* Use this method when your task function already returns a Result type.
|
|
160
|
-
*
|
|
160
|
+
* Use this method when your task function already returns a Result type. For
|
|
161
|
+
* functions that throw errors or return plain values, use `resultifyAdd`
|
|
162
|
+
* instead.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const queue = createAsyncQueue<string>();
|
|
167
|
+
*
|
|
168
|
+
* const result = await queue.add(async () => {
|
|
169
|
+
* try {
|
|
170
|
+
* const data = await fetchData();
|
|
171
|
+
* return Result.ok(data);
|
|
172
|
+
* } catch (error) {
|
|
173
|
+
* return Result.err(error);
|
|
174
|
+
* }
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* if (result.ok) {
|
|
178
|
+
* console.log('Success:', result.value);
|
|
179
|
+
* } else {
|
|
180
|
+
* console.log('Error:', result.error);
|
|
181
|
+
* }
|
|
182
|
+
* ```;
|
|
161
183
|
*
|
|
162
184
|
* @param fn - Task function that returns a Result
|
|
163
185
|
* @param options - Optional configuration for this task
|
|
164
186
|
* @returns Promise that resolves with the task result
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```typescript
|
|
168
|
-
* const queue = createAsyncQueue<string>();
|
|
169
|
-
*
|
|
170
|
-
* const result = await queue.add(async () => {
|
|
171
|
-
* try {
|
|
172
|
-
* const data = await fetchData();
|
|
173
|
-
* return Result.ok(data);
|
|
174
|
-
* } catch (error) {
|
|
175
|
-
* return Result.err(error);
|
|
176
|
-
* }
|
|
177
|
-
* });
|
|
178
|
-
*
|
|
179
|
-
* if (result.ok) {
|
|
180
|
-
* console.log('Success:', result.value);
|
|
181
|
-
* } else {
|
|
182
|
-
* console.log('Error:', result.error);
|
|
183
|
-
* }
|
|
184
|
-
* ```
|
|
185
187
|
*/
|
|
186
188
|
async add(fn, options) {
|
|
187
189
|
if (this.#signal?.aborted) {
|
|
@@ -225,37 +227,39 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
225
227
|
* This is the most commonly used method. It automatically wraps your function
|
|
226
228
|
* to handle errors and convert them to Result types.
|
|
227
229
|
*
|
|
228
|
-
* @
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* @example Basic Usage
|
|
233
|
-
* ```typescript
|
|
234
|
-
* const queue = createAsyncQueue<string>();
|
|
230
|
+
* @example
|
|
231
|
+
* Basic Usage
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const queue = createAsyncQueue<string>();
|
|
235
234
|
*
|
|
236
|
-
*
|
|
235
|
+
* queue.resultifyAdd(async () => {
|
|
237
236
|
* const response = await fetch('/api/data');
|
|
238
237
|
* return response.json();
|
|
239
|
-
*
|
|
238
|
+
* }).then(result => {
|
|
240
239
|
* if (result.ok) {
|
|
241
|
-
*
|
|
240
|
+
* console.log('Data:', result.value);
|
|
242
241
|
* } else {
|
|
243
|
-
*
|
|
242
|
+
* console.error('Failed:', result.error);
|
|
244
243
|
* }
|
|
245
|
-
*
|
|
246
|
-
*
|
|
244
|
+
* });
|
|
245
|
+
* ```
|
|
247
246
|
*
|
|
248
|
-
* @example
|
|
249
|
-
*
|
|
250
|
-
*
|
|
247
|
+
* @example
|
|
248
|
+
* With Callbacks
|
|
249
|
+
* ```typescript
|
|
250
|
+
* queue.resultifyAdd(
|
|
251
251
|
* async () => processData(),
|
|
252
252
|
* {
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
253
|
+
* onComplete: (data) => console.log('Processed:', data),
|
|
254
|
+
* onError: (error) => console.error('Failed:', error),
|
|
255
|
+
* timeout: 5000
|
|
256
256
|
* }
|
|
257
|
-
*
|
|
258
|
-
*
|
|
257
|
+
* );
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* @param fn - Task function that returns a value or throws
|
|
261
|
+
* @param options - Optional configuration for this task
|
|
262
|
+
* @returns Promise that resolves with the task result wrapped in Result
|
|
259
263
|
*/
|
|
260
264
|
resultifyAdd(fn, options) {
|
|
261
265
|
return this.add(
|
|
@@ -400,29 +404,32 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
400
404
|
this.#resolveIdleWaiters();
|
|
401
405
|
}
|
|
402
406
|
/**
|
|
403
|
-
* Wait for the queue to become idle (no pending tasks, no queued tasks, and
|
|
407
|
+
* Wait for the queue to become idle (no pending tasks, no queued tasks, and
|
|
408
|
+
* no rate-limit timers)
|
|
404
409
|
*
|
|
405
410
|
* This method resolves when:
|
|
411
|
+
*
|
|
406
412
|
* - All tasks have completed (success or failure)
|
|
407
413
|
* - The queue is stopped due to error (stopOnError), even with remaining tasks
|
|
408
|
-
* - There are no queued tasks, no running tasks, and no pending rate-limit
|
|
409
|
-
*
|
|
410
|
-
* @returns Promise that resolves when the queue is idle
|
|
414
|
+
* - There are no queued tasks, no running tasks, and no pending rate-limit
|
|
415
|
+
* timers
|
|
411
416
|
*
|
|
412
417
|
* @example
|
|
413
|
-
*
|
|
414
|
-
*
|
|
418
|
+
* ```typescript
|
|
419
|
+
* const queue = createAsyncQueue<string>();
|
|
415
420
|
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
421
|
+
* // Add multiple tasks
|
|
422
|
+
* for (let i = 0; i < 10; i++) {
|
|
418
423
|
* queue.resultifyAdd(async () => `task ${i}`);
|
|
419
|
-
*
|
|
424
|
+
* }
|
|
425
|
+
*
|
|
426
|
+
* // Wait for all tasks to complete
|
|
427
|
+
* await queue.onIdle();
|
|
420
428
|
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
429
|
+
* console.log(`Completed: ${queue.completed}, Failed: ${queue.failed}`);
|
|
430
|
+
* ```
|
|
423
431
|
*
|
|
424
|
-
*
|
|
425
|
-
* ```
|
|
432
|
+
* @returns Promise that resolves when the queue is idle
|
|
426
433
|
*/
|
|
427
434
|
async onIdle() {
|
|
428
435
|
if (this.#stopped || this.#pending === 0 && this.#size === 0 && this.#rateLimitTimeouts.size === 0) {
|
|
@@ -453,24 +460,24 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
453
460
|
/**
|
|
454
461
|
* Clear all queued tasks (does not affect currently running tasks)
|
|
455
462
|
*
|
|
456
|
-
* This removes all tasks waiting in the queue but allows currently
|
|
457
|
-
*
|
|
463
|
+
* This removes all tasks waiting in the queue but allows currently executing
|
|
464
|
+
* tasks to complete normally.
|
|
458
465
|
*
|
|
459
466
|
* @example
|
|
460
|
-
*
|
|
461
|
-
*
|
|
467
|
+
* ```typescript
|
|
468
|
+
* const queue = createAsyncQueue({ concurrency: 1 });
|
|
462
469
|
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
470
|
+
* // Add multiple tasks
|
|
471
|
+
* queue.resultifyAdd(async () => longRunningTask()); // Will start immediately
|
|
472
|
+
* queue.resultifyAdd(async () => task2()); // Queued
|
|
473
|
+
* queue.resultifyAdd(async () => task3()); // Queued
|
|
467
474
|
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
475
|
+
* // Clear remaining queued tasks
|
|
476
|
+
* queue.clear();
|
|
470
477
|
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
478
|
+
* // Only the first task will complete
|
|
479
|
+
* await queue.onIdle();
|
|
480
|
+
* ```;
|
|
474
481
|
*/
|
|
475
482
|
clear() {
|
|
476
483
|
this.#queue = [];
|
|
@@ -504,17 +511,17 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
504
511
|
* Manually start processing tasks (only needed if autoStart: false)
|
|
505
512
|
*
|
|
506
513
|
* @example
|
|
507
|
-
*
|
|
508
|
-
*
|
|
514
|
+
* ```typescript
|
|
515
|
+
* const queue = createAsyncQueue({ autoStart: false });
|
|
509
516
|
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
517
|
+
* // Add tasks without starting processing
|
|
518
|
+
* queue.resultifyAdd(async () => 'task1');
|
|
519
|
+
* queue.resultifyAdd(async () => 'task2');
|
|
513
520
|
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
521
|
+
* // Start processing when ready
|
|
522
|
+
* queue.start();
|
|
523
|
+
* await queue.onIdle();
|
|
524
|
+
* ```;
|
|
518
525
|
*/
|
|
519
526
|
start() {
|
|
520
527
|
if (this.#stopped) {
|
|
@@ -527,26 +534,24 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
527
534
|
* Pause processing new tasks (currently running tasks continue)
|
|
528
535
|
*
|
|
529
536
|
* @example
|
|
530
|
-
*
|
|
531
|
-
*
|
|
537
|
+
* ```typescript
|
|
538
|
+
* const queue = createAsyncQueue();
|
|
532
539
|
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
540
|
+
* // Start some tasks
|
|
541
|
+
* queue.resultifyAdd(async () => longRunningTask1());
|
|
542
|
+
* queue.resultifyAdd(async () => longRunningTask2());
|
|
536
543
|
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
544
|
+
* // Pause before more tasks are picked up
|
|
545
|
+
* queue.pause();
|
|
539
546
|
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
547
|
+
* // Later, resume processing
|
|
548
|
+
* queue.resume();
|
|
549
|
+
* ```;
|
|
543
550
|
*/
|
|
544
551
|
pause() {
|
|
545
552
|
this.#paused = true;
|
|
546
553
|
}
|
|
547
|
-
/**
|
|
548
|
-
* Resume processing tasks after pause
|
|
549
|
-
*/
|
|
554
|
+
/** Resume processing tasks after pause */
|
|
550
555
|
resume() {
|
|
551
556
|
this.#paused = false;
|
|
552
557
|
if (this.#started && !this.#stopped) {
|
|
@@ -556,27 +561,27 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
556
561
|
/**
|
|
557
562
|
* Reset the queue after being stopped, allowing new tasks to be processed
|
|
558
563
|
*
|
|
559
|
-
* This clears the stopped state and error reason, and resumes processing
|
|
560
|
-
*
|
|
564
|
+
* This clears the stopped state and error reason, and resumes processing any
|
|
565
|
+
* remaining queued tasks if autoStart was enabled.
|
|
561
566
|
*
|
|
562
567
|
* @example
|
|
563
|
-
*
|
|
564
|
-
*
|
|
568
|
+
* ```typescript
|
|
569
|
+
* const queue = createAsyncQueue({ stopOnError: true });
|
|
565
570
|
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
571
|
+
* // Add tasks that will cause the queue to stop
|
|
572
|
+
* queue.resultifyAdd(async () => { throw new Error('fail'); });
|
|
573
|
+
* queue.resultifyAdd(async () => 'remaining task');
|
|
569
574
|
*
|
|
570
|
-
*
|
|
575
|
+
* await queue.onIdle();
|
|
571
576
|
*
|
|
572
|
-
*
|
|
577
|
+
* if (queue.isStopped) {
|
|
573
578
|
* console.log(`Queue stopped, ${queue.size} tasks remaining`);
|
|
574
579
|
*
|
|
575
580
|
* // Reset and process remaining tasks
|
|
576
581
|
* queue.reset();
|
|
577
582
|
* await queue.onIdle();
|
|
578
|
-
*
|
|
579
|
-
*
|
|
583
|
+
* }
|
|
584
|
+
* ```
|
|
580
585
|
*/
|
|
581
586
|
reset() {
|
|
582
587
|
this.#stopped = false;
|
package/dist/awaitDebounce.d.cts
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import { __LEGIT_ANY__ } from './saferTyping.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Creates an awaitable debounce mechanism that allows you to debounce async
|
|
5
|
-
* When called multiple times with the same `callId`, only the last
|
|
6
|
-
* while all previous calls resolve with
|
|
4
|
+
* Creates an awaitable debounce mechanism that allows you to debounce async
|
|
5
|
+
* operations. When called multiple times with the same `callId`, only the last
|
|
6
|
+
* call will resolve with 'continue', while all previous calls resolve with
|
|
7
|
+
* 'skip'.
|
|
7
8
|
*
|
|
8
|
-
* This is useful for debouncing API calls, search operations, or any async work
|
|
9
|
-
* to ensure only the most recent request is processed.
|
|
10
|
-
*
|
|
11
|
-
* @param options - Configuration object
|
|
12
|
-
* @param options.callId - Unique identifier for the debounce group. Calls with the same ID are debounced together
|
|
13
|
-
* @param options.debounce - Debounce delay in milliseconds
|
|
14
|
-
* @returns Promise that resolves to 'continue' if this call should proceed, or 'skip' if it was superseded
|
|
9
|
+
* This is useful for debouncing API calls, search operations, or any async work
|
|
10
|
+
* where you want to ensure only the most recent request is processed.
|
|
15
11
|
*
|
|
16
12
|
* @example
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* async function searchUsers(query: string) {
|
|
15
|
+
* const result = await awaitDebounce({ callId: 'search', debounce: 300 });
|
|
16
|
+
* if (result === 'skip') return; // This search was superseded
|
|
21
17
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
18
|
+
* // Only the most recent search will reach here
|
|
19
|
+
* const users = await fetchUsers(query);
|
|
20
|
+
* updateUI(users);
|
|
21
|
+
* }
|
|
26
22
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
23
|
+
* // Called rapidly - only the last call will execute
|
|
24
|
+
* searchUsers('a');
|
|
25
|
+
* searchUsers('ab');
|
|
26
|
+
* searchUsers('abc'); // Only this one will continue
|
|
27
|
+
* ```;
|
|
28
|
+
*
|
|
29
|
+
* @param options - Configuration object
|
|
30
|
+
* @param options.callId - Unique identifier for the debounce group. Calls with
|
|
31
|
+
* the same ID are debounced together
|
|
32
|
+
* @param options.debounce - Debounce delay in milliseconds
|
|
33
|
+
* @returns Promise that resolves to 'continue' if this call should proceed, or
|
|
34
|
+
* 'skip' if it was superseded
|
|
32
35
|
*/
|
|
33
36
|
declare function awaitDebounce({ callId: _callId, debounce, }: {
|
|
34
37
|
callId: __LEGIT_ANY__;
|
package/dist/awaitDebounce.d.ts
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import { __LEGIT_ANY__ } from './saferTyping.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Creates an awaitable debounce mechanism that allows you to debounce async
|
|
5
|
-
* When called multiple times with the same `callId`, only the last
|
|
6
|
-
* while all previous calls resolve with
|
|
4
|
+
* Creates an awaitable debounce mechanism that allows you to debounce async
|
|
5
|
+
* operations. When called multiple times with the same `callId`, only the last
|
|
6
|
+
* call will resolve with 'continue', while all previous calls resolve with
|
|
7
|
+
* 'skip'.
|
|
7
8
|
*
|
|
8
|
-
* This is useful for debouncing API calls, search operations, or any async work
|
|
9
|
-
* to ensure only the most recent request is processed.
|
|
10
|
-
*
|
|
11
|
-
* @param options - Configuration object
|
|
12
|
-
* @param options.callId - Unique identifier for the debounce group. Calls with the same ID are debounced together
|
|
13
|
-
* @param options.debounce - Debounce delay in milliseconds
|
|
14
|
-
* @returns Promise that resolves to 'continue' if this call should proceed, or 'skip' if it was superseded
|
|
9
|
+
* This is useful for debouncing API calls, search operations, or any async work
|
|
10
|
+
* where you want to ensure only the most recent request is processed.
|
|
15
11
|
*
|
|
16
12
|
* @example
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* async function searchUsers(query: string) {
|
|
15
|
+
* const result = await awaitDebounce({ callId: 'search', debounce: 300 });
|
|
16
|
+
* if (result === 'skip') return; // This search was superseded
|
|
21
17
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
18
|
+
* // Only the most recent search will reach here
|
|
19
|
+
* const users = await fetchUsers(query);
|
|
20
|
+
* updateUI(users);
|
|
21
|
+
* }
|
|
26
22
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
23
|
+
* // Called rapidly - only the last call will execute
|
|
24
|
+
* searchUsers('a');
|
|
25
|
+
* searchUsers('ab');
|
|
26
|
+
* searchUsers('abc'); // Only this one will continue
|
|
27
|
+
* ```;
|
|
28
|
+
*
|
|
29
|
+
* @param options - Configuration object
|
|
30
|
+
* @param options.callId - Unique identifier for the debounce group. Calls with
|
|
31
|
+
* the same ID are debounced together
|
|
32
|
+
* @param options.debounce - Debounce delay in milliseconds
|
|
33
|
+
* @returns Promise that resolves to 'continue' if this call should proceed, or
|
|
34
|
+
* 'skip' if it was superseded
|
|
32
35
|
*/
|
|
33
36
|
declare function awaitDebounce({ callId: _callId, debounce, }: {
|
|
34
37
|
callId: __LEGIT_ANY__;
|
package/dist/cache.cjs
CHANGED
|
@@ -78,7 +78,8 @@ var WithExpiration = class {
|
|
|
78
78
|
expiration;
|
|
79
79
|
/**
|
|
80
80
|
* @param value - The value to store in the cache.
|
|
81
|
-
* @param expiration - The expiration time of the value in seconds or a
|
|
81
|
+
* @param expiration - The expiration time of the value in seconds or a
|
|
82
|
+
* duration object.
|
|
82
83
|
*/
|
|
83
84
|
constructor(value, expiration) {
|
|
84
85
|
this.value = value;
|
package/dist/cache.d.cts
CHANGED
|
@@ -6,15 +6,15 @@ declare function cachedGetter<T>(getter: () => T): {
|
|
|
6
6
|
type Options = {
|
|
7
7
|
/**
|
|
8
8
|
* The maximum number of items in the cache.
|
|
9
|
+
*
|
|
9
10
|
* @default 1000
|
|
10
11
|
*/
|
|
11
12
|
maxCacheSize?: number;
|
|
12
|
-
/**
|
|
13
|
-
* The maximum age of items in the cache.
|
|
14
|
-
*/
|
|
13
|
+
/** The maximum age of items in the cache. */
|
|
15
14
|
maxItemAge?: DurationObj;
|
|
16
15
|
/**
|
|
17
16
|
* The throttle for checking expired items in milliseconds.
|
|
17
|
+
*
|
|
18
18
|
* @default
|
|
19
19
|
* 10_000
|
|
20
20
|
*/
|
|
@@ -29,25 +29,31 @@ declare class WithExpiration<T> {
|
|
|
29
29
|
expiration: number;
|
|
30
30
|
/**
|
|
31
31
|
* @param value - The value to store in the cache.
|
|
32
|
-
* @param expiration - The expiration time of the value in seconds or a
|
|
32
|
+
* @param expiration - The expiration time of the value in seconds or a
|
|
33
|
+
* duration object.
|
|
33
34
|
*/
|
|
34
35
|
constructor(value: T, expiration: DurationObj);
|
|
35
36
|
}
|
|
36
37
|
type Utils<T> = {
|
|
37
38
|
skipCaching: (value: T) => SkipCaching<T>;
|
|
38
39
|
/**
|
|
39
|
-
* Create a new WithExpiration object with the given value and expiration
|
|
40
|
+
* Create a new WithExpiration object with the given value and expiration
|
|
41
|
+
* time.
|
|
42
|
+
*
|
|
40
43
|
* @param value - The value to store in the cache.
|
|
41
|
-
* @param expiration - The expiration time of the value in seconds or a
|
|
44
|
+
* @param expiration - The expiration time of the value in seconds or a
|
|
45
|
+
* duration object.
|
|
42
46
|
*/
|
|
43
47
|
withExpiration: (value: T, expiration: DurationObj) => WithExpiration<T>;
|
|
44
48
|
};
|
|
45
49
|
type GetOptions<T> = {
|
|
46
50
|
/**
|
|
47
|
-
* A function that determines whether a value should be rejected from being
|
|
48
|
-
* If the function returns true, the value will be returned but not
|
|
51
|
+
* A function that determines whether a value should be rejected from being
|
|
52
|
+
* cached. If the function returns true, the value will be returned but not
|
|
53
|
+
* cached.
|
|
54
|
+
*
|
|
49
55
|
* @param value The value to check
|
|
50
|
-
* @returns
|
|
56
|
+
* @returns True if the value should be rejected, false otherwise
|
|
51
57
|
*/
|
|
52
58
|
skipCachingWhen?: (value: T) => boolean;
|
|
53
59
|
};
|
package/dist/cache.d.ts
CHANGED
|
@@ -6,15 +6,15 @@ declare function cachedGetter<T>(getter: () => T): {
|
|
|
6
6
|
type Options = {
|
|
7
7
|
/**
|
|
8
8
|
* The maximum number of items in the cache.
|
|
9
|
+
*
|
|
9
10
|
* @default 1000
|
|
10
11
|
*/
|
|
11
12
|
maxCacheSize?: number;
|
|
12
|
-
/**
|
|
13
|
-
* The maximum age of items in the cache.
|
|
14
|
-
*/
|
|
13
|
+
/** The maximum age of items in the cache. */
|
|
15
14
|
maxItemAge?: DurationObj;
|
|
16
15
|
/**
|
|
17
16
|
* The throttle for checking expired items in milliseconds.
|
|
17
|
+
*
|
|
18
18
|
* @default
|
|
19
19
|
* 10_000
|
|
20
20
|
*/
|
|
@@ -29,25 +29,31 @@ declare class WithExpiration<T> {
|
|
|
29
29
|
expiration: number;
|
|
30
30
|
/**
|
|
31
31
|
* @param value - The value to store in the cache.
|
|
32
|
-
* @param expiration - The expiration time of the value in seconds or a
|
|
32
|
+
* @param expiration - The expiration time of the value in seconds or a
|
|
33
|
+
* duration object.
|
|
33
34
|
*/
|
|
34
35
|
constructor(value: T, expiration: DurationObj);
|
|
35
36
|
}
|
|
36
37
|
type Utils<T> = {
|
|
37
38
|
skipCaching: (value: T) => SkipCaching<T>;
|
|
38
39
|
/**
|
|
39
|
-
* Create a new WithExpiration object with the given value and expiration
|
|
40
|
+
* Create a new WithExpiration object with the given value and expiration
|
|
41
|
+
* time.
|
|
42
|
+
*
|
|
40
43
|
* @param value - The value to store in the cache.
|
|
41
|
-
* @param expiration - The expiration time of the value in seconds or a
|
|
44
|
+
* @param expiration - The expiration time of the value in seconds or a
|
|
45
|
+
* duration object.
|
|
42
46
|
*/
|
|
43
47
|
withExpiration: (value: T, expiration: DurationObj) => WithExpiration<T>;
|
|
44
48
|
};
|
|
45
49
|
type GetOptions<T> = {
|
|
46
50
|
/**
|
|
47
|
-
* A function that determines whether a value should be rejected from being
|
|
48
|
-
* If the function returns true, the value will be returned but not
|
|
51
|
+
* A function that determines whether a value should be rejected from being
|
|
52
|
+
* cached. If the function returns true, the value will be returned but not
|
|
53
|
+
* cached.
|
|
54
|
+
*
|
|
49
55
|
* @param value The value to check
|
|
50
|
-
* @returns
|
|
56
|
+
* @returns True if the value should be rejected, false otherwise
|
|
51
57
|
*/
|
|
52
58
|
skipCachingWhen?: (value: T) => boolean;
|
|
53
59
|
};
|
package/dist/cache.js
CHANGED
|
@@ -29,7 +29,8 @@ var WithExpiration = class {
|
|
|
29
29
|
expiration;
|
|
30
30
|
/**
|
|
31
31
|
* @param value - The value to store in the cache.
|
|
32
|
-
* @param expiration - The expiration time of the value in seconds or a
|
|
32
|
+
* @param expiration - The expiration time of the value in seconds or a
|
|
33
|
+
* duration object.
|
|
33
34
|
*/
|
|
34
35
|
constructor(value, expiration) {
|
|
35
36
|
this.value = value;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
typedObjectEntries
|
|
3
|
+
} from "./chunk-DTE2QMWE.js";
|
|
4
|
+
import {
|
|
5
|
+
sortBy
|
|
6
|
+
} from "./chunk-27AL66CH.js";
|
|
7
|
+
|
|
1
8
|
// src/objUtils.ts
|
|
2
9
|
function objectTypedEntries(obj) {
|
|
3
10
|
return Object.entries(obj);
|
|
@@ -38,6 +45,18 @@ function rejectObjUndefinedValues(obj) {
|
|
|
38
45
|
}
|
|
39
46
|
return result;
|
|
40
47
|
}
|
|
48
|
+
function filterObjectKeys(obj, predicate) {
|
|
49
|
+
return Object.fromEntries(
|
|
50
|
+
Object.entries(obj).filter(
|
|
51
|
+
([key, value]) => predicate(key, value)
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function sortObjectKeys(obj, sortByFn, options) {
|
|
56
|
+
return Object.fromEntries(
|
|
57
|
+
sortBy(typedObjectEntries(obj), sortByFn, options)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
41
60
|
|
|
42
61
|
export {
|
|
43
62
|
objectTypedEntries,
|
|
@@ -46,5 +65,7 @@ export {
|
|
|
46
65
|
mapObjectToObject,
|
|
47
66
|
omit,
|
|
48
67
|
looseGetObjectProperty,
|
|
49
|
-
rejectObjUndefinedValues
|
|
68
|
+
rejectObjUndefinedValues,
|
|
69
|
+
filterObjectKeys,
|
|
70
|
+
sortObjectKeys
|
|
50
71
|
};
|