@ls-stack/utils 3.39.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/consoleFmt.cjs +1 -0
- package/dist/consoleFmt.d.cts +6 -0
- package/dist/consoleFmt.d.ts +6 -0
- package/dist/consoleFmt.js +1 -0
- 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 +6 -2
- 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 -91
- 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.cjs
CHANGED
|
@@ -67,22 +67,23 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
67
67
|
/**
|
|
68
68
|
* Event emitter for tracking task lifecycle
|
|
69
69
|
*
|
|
70
|
-
* @example
|
|
71
|
-
*
|
|
72
|
-
*
|
|
70
|
+
* @example
|
|
71
|
+
* Listening to Events
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const queue = createAsyncQueue<string>();
|
|
73
74
|
*
|
|
74
|
-
*
|
|
75
|
+
* queue.events.on('start', (event) => {
|
|
75
76
|
* console.log('Task started:', event.payload.meta);
|
|
76
|
-
*
|
|
77
|
+
* });
|
|
77
78
|
*
|
|
78
|
-
*
|
|
79
|
+
* queue.events.on('complete', (event) => {
|
|
79
80
|
* console.log('Task completed:', event.payload.value);
|
|
80
|
-
*
|
|
81
|
+
* });
|
|
81
82
|
*
|
|
82
|
-
*
|
|
83
|
+
* queue.events.on('error', (event) => {
|
|
83
84
|
* console.error('Task failed:', event.payload.error);
|
|
84
|
-
*
|
|
85
|
-
*
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
86
87
|
*/
|
|
87
88
|
events = (0, import_evtmitter.evtmitter)();
|
|
88
89
|
#signal;
|
|
@@ -196,32 +197,33 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
196
197
|
/**
|
|
197
198
|
* Add a task that returns a Result to the queue
|
|
198
199
|
*
|
|
199
|
-
* Use this method when your task function already returns a Result type.
|
|
200
|
-
*
|
|
200
|
+
* Use this method when your task function already returns a Result type. For
|
|
201
|
+
* functions that throw errors or return plain values, use `resultifyAdd`
|
|
202
|
+
* instead.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const queue = createAsyncQueue<string>();
|
|
207
|
+
*
|
|
208
|
+
* const result = await queue.add(async () => {
|
|
209
|
+
* try {
|
|
210
|
+
* const data = await fetchData();
|
|
211
|
+
* return Result.ok(data);
|
|
212
|
+
* } catch (error) {
|
|
213
|
+
* return Result.err(error);
|
|
214
|
+
* }
|
|
215
|
+
* });
|
|
216
|
+
*
|
|
217
|
+
* if (result.ok) {
|
|
218
|
+
* console.log('Success:', result.value);
|
|
219
|
+
* } else {
|
|
220
|
+
* console.log('Error:', result.error);
|
|
221
|
+
* }
|
|
222
|
+
* ```;
|
|
201
223
|
*
|
|
202
224
|
* @param fn - Task function that returns a Result
|
|
203
225
|
* @param options - Optional configuration for this task
|
|
204
226
|
* @returns Promise that resolves with the task result
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* const queue = createAsyncQueue<string>();
|
|
209
|
-
*
|
|
210
|
-
* const result = await queue.add(async () => {
|
|
211
|
-
* try {
|
|
212
|
-
* const data = await fetchData();
|
|
213
|
-
* return Result.ok(data);
|
|
214
|
-
* } catch (error) {
|
|
215
|
-
* return Result.err(error);
|
|
216
|
-
* }
|
|
217
|
-
* });
|
|
218
|
-
*
|
|
219
|
-
* if (result.ok) {
|
|
220
|
-
* console.log('Success:', result.value);
|
|
221
|
-
* } else {
|
|
222
|
-
* console.log('Error:', result.error);
|
|
223
|
-
* }
|
|
224
|
-
* ```
|
|
225
227
|
*/
|
|
226
228
|
async add(fn, options) {
|
|
227
229
|
if (this.#signal?.aborted) {
|
|
@@ -265,37 +267,39 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
265
267
|
* This is the most commonly used method. It automatically wraps your function
|
|
266
268
|
* to handle errors and convert them to Result types.
|
|
267
269
|
*
|
|
268
|
-
* @
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
* @example Basic Usage
|
|
273
|
-
* ```typescript
|
|
274
|
-
* const queue = createAsyncQueue<string>();
|
|
270
|
+
* @example
|
|
271
|
+
* Basic Usage
|
|
272
|
+
* ```typescript
|
|
273
|
+
* const queue = createAsyncQueue<string>();
|
|
275
274
|
*
|
|
276
|
-
*
|
|
275
|
+
* queue.resultifyAdd(async () => {
|
|
277
276
|
* const response = await fetch('/api/data');
|
|
278
277
|
* return response.json();
|
|
279
|
-
*
|
|
278
|
+
* }).then(result => {
|
|
280
279
|
* if (result.ok) {
|
|
281
|
-
*
|
|
280
|
+
* console.log('Data:', result.value);
|
|
282
281
|
* } else {
|
|
283
|
-
*
|
|
282
|
+
* console.error('Failed:', result.error);
|
|
284
283
|
* }
|
|
285
|
-
*
|
|
286
|
-
*
|
|
284
|
+
* });
|
|
285
|
+
* ```
|
|
287
286
|
*
|
|
288
|
-
* @example
|
|
289
|
-
*
|
|
290
|
-
*
|
|
287
|
+
* @example
|
|
288
|
+
* With Callbacks
|
|
289
|
+
* ```typescript
|
|
290
|
+
* queue.resultifyAdd(
|
|
291
291
|
* async () => processData(),
|
|
292
292
|
* {
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
293
|
+
* onComplete: (data) => console.log('Processed:', data),
|
|
294
|
+
* onError: (error) => console.error('Failed:', error),
|
|
295
|
+
* timeout: 5000
|
|
296
296
|
* }
|
|
297
|
-
*
|
|
298
|
-
*
|
|
297
|
+
* );
|
|
298
|
+
* ```
|
|
299
|
+
*
|
|
300
|
+
* @param fn - Task function that returns a value or throws
|
|
301
|
+
* @param options - Optional configuration for this task
|
|
302
|
+
* @returns Promise that resolves with the task result wrapped in Result
|
|
299
303
|
*/
|
|
300
304
|
resultifyAdd(fn, options) {
|
|
301
305
|
return this.add(
|
|
@@ -440,29 +444,32 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
440
444
|
this.#resolveIdleWaiters();
|
|
441
445
|
}
|
|
442
446
|
/**
|
|
443
|
-
* Wait for the queue to become idle (no pending tasks, no queued tasks, and
|
|
447
|
+
* Wait for the queue to become idle (no pending tasks, no queued tasks, and
|
|
448
|
+
* no rate-limit timers)
|
|
444
449
|
*
|
|
445
450
|
* This method resolves when:
|
|
451
|
+
*
|
|
446
452
|
* - All tasks have completed (success or failure)
|
|
447
453
|
* - The queue is stopped due to error (stopOnError), even with remaining tasks
|
|
448
|
-
* - There are no queued tasks, no running tasks, and no pending rate-limit
|
|
449
|
-
*
|
|
450
|
-
* @returns Promise that resolves when the queue is idle
|
|
454
|
+
* - There are no queued tasks, no running tasks, and no pending rate-limit
|
|
455
|
+
* timers
|
|
451
456
|
*
|
|
452
457
|
* @example
|
|
453
|
-
*
|
|
454
|
-
*
|
|
458
|
+
* ```typescript
|
|
459
|
+
* const queue = createAsyncQueue<string>();
|
|
455
460
|
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
461
|
+
* // Add multiple tasks
|
|
462
|
+
* for (let i = 0; i < 10; i++) {
|
|
458
463
|
* queue.resultifyAdd(async () => `task ${i}`);
|
|
459
|
-
*
|
|
464
|
+
* }
|
|
465
|
+
*
|
|
466
|
+
* // Wait for all tasks to complete
|
|
467
|
+
* await queue.onIdle();
|
|
460
468
|
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
469
|
+
* console.log(`Completed: ${queue.completed}, Failed: ${queue.failed}`);
|
|
470
|
+
* ```
|
|
463
471
|
*
|
|
464
|
-
*
|
|
465
|
-
* ```
|
|
472
|
+
* @returns Promise that resolves when the queue is idle
|
|
466
473
|
*/
|
|
467
474
|
async onIdle() {
|
|
468
475
|
if (this.#stopped || this.#pending === 0 && this.#size === 0 && this.#rateLimitTimeouts.size === 0) {
|
|
@@ -493,24 +500,24 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
493
500
|
/**
|
|
494
501
|
* Clear all queued tasks (does not affect currently running tasks)
|
|
495
502
|
*
|
|
496
|
-
* This removes all tasks waiting in the queue but allows currently
|
|
497
|
-
*
|
|
503
|
+
* This removes all tasks waiting in the queue but allows currently executing
|
|
504
|
+
* tasks to complete normally.
|
|
498
505
|
*
|
|
499
506
|
* @example
|
|
500
|
-
*
|
|
501
|
-
*
|
|
507
|
+
* ```typescript
|
|
508
|
+
* const queue = createAsyncQueue({ concurrency: 1 });
|
|
502
509
|
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
510
|
+
* // Add multiple tasks
|
|
511
|
+
* queue.resultifyAdd(async () => longRunningTask()); // Will start immediately
|
|
512
|
+
* queue.resultifyAdd(async () => task2()); // Queued
|
|
513
|
+
* queue.resultifyAdd(async () => task3()); // Queued
|
|
507
514
|
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
515
|
+
* // Clear remaining queued tasks
|
|
516
|
+
* queue.clear();
|
|
510
517
|
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
518
|
+
* // Only the first task will complete
|
|
519
|
+
* await queue.onIdle();
|
|
520
|
+
* ```;
|
|
514
521
|
*/
|
|
515
522
|
clear() {
|
|
516
523
|
this.#queue = [];
|
|
@@ -544,17 +551,17 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
544
551
|
* Manually start processing tasks (only needed if autoStart: false)
|
|
545
552
|
*
|
|
546
553
|
* @example
|
|
547
|
-
*
|
|
548
|
-
*
|
|
554
|
+
* ```typescript
|
|
555
|
+
* const queue = createAsyncQueue({ autoStart: false });
|
|
549
556
|
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
557
|
+
* // Add tasks without starting processing
|
|
558
|
+
* queue.resultifyAdd(async () => 'task1');
|
|
559
|
+
* queue.resultifyAdd(async () => 'task2');
|
|
553
560
|
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
561
|
+
* // Start processing when ready
|
|
562
|
+
* queue.start();
|
|
563
|
+
* await queue.onIdle();
|
|
564
|
+
* ```;
|
|
558
565
|
*/
|
|
559
566
|
start() {
|
|
560
567
|
if (this.#stopped) {
|
|
@@ -567,26 +574,24 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
567
574
|
* Pause processing new tasks (currently running tasks continue)
|
|
568
575
|
*
|
|
569
576
|
* @example
|
|
570
|
-
*
|
|
571
|
-
*
|
|
577
|
+
* ```typescript
|
|
578
|
+
* const queue = createAsyncQueue();
|
|
572
579
|
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
580
|
+
* // Start some tasks
|
|
581
|
+
* queue.resultifyAdd(async () => longRunningTask1());
|
|
582
|
+
* queue.resultifyAdd(async () => longRunningTask2());
|
|
576
583
|
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
584
|
+
* // Pause before more tasks are picked up
|
|
585
|
+
* queue.pause();
|
|
579
586
|
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
587
|
+
* // Later, resume processing
|
|
588
|
+
* queue.resume();
|
|
589
|
+
* ```;
|
|
583
590
|
*/
|
|
584
591
|
pause() {
|
|
585
592
|
this.#paused = true;
|
|
586
593
|
}
|
|
587
|
-
/**
|
|
588
|
-
* Resume processing tasks after pause
|
|
589
|
-
*/
|
|
594
|
+
/** Resume processing tasks after pause */
|
|
590
595
|
resume() {
|
|
591
596
|
this.#paused = false;
|
|
592
597
|
if (this.#started && !this.#stopped) {
|
|
@@ -596,27 +601,27 @@ var AsyncQueue = class _AsyncQueue {
|
|
|
596
601
|
/**
|
|
597
602
|
* Reset the queue after being stopped, allowing new tasks to be processed
|
|
598
603
|
*
|
|
599
|
-
* This clears the stopped state and error reason, and resumes processing
|
|
600
|
-
*
|
|
604
|
+
* This clears the stopped state and error reason, and resumes processing any
|
|
605
|
+
* remaining queued tasks if autoStart was enabled.
|
|
601
606
|
*
|
|
602
607
|
* @example
|
|
603
|
-
*
|
|
604
|
-
*
|
|
608
|
+
* ```typescript
|
|
609
|
+
* const queue = createAsyncQueue({ stopOnError: true });
|
|
605
610
|
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
611
|
+
* // Add tasks that will cause the queue to stop
|
|
612
|
+
* queue.resultifyAdd(async () => { throw new Error('fail'); });
|
|
613
|
+
* queue.resultifyAdd(async () => 'remaining task');
|
|
609
614
|
*
|
|
610
|
-
*
|
|
615
|
+
* await queue.onIdle();
|
|
611
616
|
*
|
|
612
|
-
*
|
|
617
|
+
* if (queue.isStopped) {
|
|
613
618
|
* console.log(`Queue stopped, ${queue.size} tasks remaining`);
|
|
614
619
|
*
|
|
615
620
|
* // Reset and process remaining tasks
|
|
616
621
|
* queue.reset();
|
|
617
622
|
* await queue.onIdle();
|
|
618
|
-
*
|
|
619
|
-
*
|
|
623
|
+
* }
|
|
624
|
+
* ```
|
|
620
625
|
*/
|
|
621
626
|
reset() {
|
|
622
627
|
this.#stopped = false;
|