@xylabs/promise 5.0.84 → 5.0.86

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 (2) hide show
  1. package/README.md +151 -199
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -15,6 +15,8 @@
15
15
 
16
16
  Base functionality used throughout XY Labs TypeScript/JavaScript libraries
17
17
 
18
+
19
+
18
20
  ## Reference
19
21
 
20
22
  **@xylabs/promise**
@@ -23,33 +25,41 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
23
25
 
24
26
  ## Classes
25
27
 
26
- - [PromiseEx](#classes/PromiseEx)
28
+ | Class | Description |
29
+ | ------ | ------ |
30
+ | [PromiseEx](#classes/PromiseEx) | An extended Promise that carries an optional attached value and supports cancellation. The value can be inspected via the `then` or `value` methods to conditionally cancel. |
27
31
 
28
32
  ## Interfaces
29
33
 
30
- - [PromiseType](#interfaces/PromiseType)
34
+ | Interface | Description |
35
+ | ------ | ------ |
36
+ | [PromiseType](#interfaces/PromiseType) | An interface representing any thenable (promise-like) object. |
31
37
 
32
38
  ## Type Aliases
33
39
 
34
- - [PromiseExSubFunc](#type-aliases/PromiseExSubFunc)
35
- - [PromiseExFunc](#type-aliases/PromiseExFunc)
36
- - [PromiseExValueFunc](#type-aliases/PromiseExValueFunc)
37
- - [Promisable](#type-aliases/Promisable)
38
- - [PromisableArray](#type-aliases/PromisableArray)
39
- - [OptionalPromisable](#type-aliases/OptionalPromisable)
40
- - [OptionalPromisableArray](#type-aliases/OptionalPromisableArray)
41
- - [NullablePromisable](#type-aliases/NullablePromisable)
42
- - [NullablePromisableArray](#type-aliases/NullablePromisableArray)
43
- - [AsyncMutex](#type-aliases/AsyncMutex)
44
- - [AnyNonPromise](#type-aliases/AnyNonPromise)
40
+ | Type Alias | Description |
41
+ | ------ | ------ |
42
+ | [PromiseExSubFunc](#type-aliases/PromiseExSubFunc) | A resolve/reject callback used within PromiseEx. |
43
+ | [PromiseExFunc](#type-aliases/PromiseExFunc) | The executor function passed to the PromiseEx constructor. |
44
+ | [PromiseExValueFunc](#type-aliases/PromiseExValueFunc) | A callback that inspects the attached value and returns whether to cancel the promise. |
45
+ | [Promisable](#type-aliases/Promisable) | A value that may be a Promise, PromiseEx, or a plain synchronous value. |
46
+ | [PromisableArray](#type-aliases/PromisableArray) | A Promisable that resolves to an array. |
47
+ | [OptionalPromisable](#type-aliases/OptionalPromisable) | A Promisable that may resolve to undefined. |
48
+ | [OptionalPromisableArray](#type-aliases/OptionalPromisableArray) | A Promisable array where elements may be undefined. |
49
+ | [NullablePromisable](#type-aliases/NullablePromisable) | A Promisable that may resolve to null. |
50
+ | [NullablePromisableArray](#type-aliases/NullablePromisableArray) | A Promisable array where elements may be null. |
51
+ | [AsyncMutex](#type-aliases/AsyncMutex) | - |
52
+ | [AnyNonPromise](#type-aliases/AnyNonPromise) | Any non-promise typed value, excluding thenables. |
45
53
 
46
54
  ## Functions
47
55
 
48
- - [fulfilled](#functions/fulfilled)
49
- - [fulfilledValues](#functions/fulfilledValues)
50
- - [rejected](#functions/rejected)
51
- - [toPromise](#functions/toPromise)
52
- - [isPromise](#functions/isPromise)
56
+ | Function | Description |
57
+ | ------ | ------ |
58
+ | [fulfilled](#functions/fulfilled) | For use with Promise.allSettled to filter only successful results |
59
+ | [fulfilledValues](#functions/fulfilledValues) | For use with Promise.allSettled to reduce to only successful result values |
60
+ | [rejected](#functions/rejected) | For use with Promise.allSettled to filter only rejected results |
61
+ | [toPromise](#functions/toPromise) | Wraps a value in a Promise if it is not already one. |
62
+ | [isPromise](#functions/isPromise) | Type guard that checks whether a value is a Promise instance. |
53
63
 
54
64
  ### classes
55
65
 
@@ -68,31 +78,25 @@ The value can be inspected via the `then` or `value` methods to conditionally ca
68
78
 
69
79
  ## Type Parameters
70
80
 
71
- ### T
72
-
73
- `T`
74
-
75
- ### V
76
-
77
- `V` = `void`
81
+ | Type Parameter | Default type |
82
+ | ------ | ------ |
83
+ | `T` | - |
84
+ | `V` | `void` |
78
85
 
79
86
  ## Constructors
80
87
 
81
88
  ### Constructor
82
89
 
83
90
  ```ts
84
- new PromiseEx<T, V>(func, value?): PromiseEx<T, V>;
91
+ new PromiseEx<T, V>(func: PromiseExFunc<T>, value?: V): PromiseEx<T, V>;
85
92
  ```
86
93
 
87
94
  ### Parameters
88
95
 
89
- #### func
90
-
91
- [`PromiseExFunc`](#../type-aliases/PromiseExFunc)\<`T`\>
92
-
93
- #### value?
94
-
95
- `V`
96
+ | Parameter | Type |
97
+ | ------ | ------ |
98
+ | `func` | [`PromiseExFunc`](#../type-aliases/PromiseExFunc)\<`T`\> |
99
+ | `value?` | `V` |
96
100
 
97
101
  ### Returns
98
102
 
@@ -106,13 +110,9 @@ Promise<T>.constructor
106
110
 
107
111
  ## Properties
108
112
 
109
- ### cancelled?
110
-
111
- ```ts
112
- optional cancelled: boolean;
113
- ```
114
-
115
- Whether the promise has been cancelled via a value callback.
113
+ | Property | Type | Description |
114
+ | ------ | ------ | ------ |
115
+ | <a id="cancelled"></a> `cancelled?` | `boolean` | Whether the promise has been cancelled via a value callback. |
116
116
 
117
117
  ## Methods
118
118
 
@@ -120,40 +120,29 @@ Whether the promise has been cancelled via a value callback.
120
120
 
121
121
  ```ts
122
122
  then<TResult1, TResult2>(
123
- onfulfilled?,
124
- onrejected?,
125
- onvalue?): Promise<TResult1 | TResult2>;
123
+ onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1> | null,
124
+ onrejected?:
125
+ | (reason: unknown) => TResult2 | PromiseLike<TResult2>
126
+ | null,
127
+ onvalue?: (value?: V) => boolean): Promise<TResult1 | TResult2>;
126
128
  ```
127
129
 
128
130
  Attaches callbacks for the resolution and/or rejection of the Promise.
129
131
 
130
132
  ### Type Parameters
131
133
 
132
- #### TResult1
133
-
134
- `TResult1` = `T`
135
-
136
- #### TResult2
137
-
138
- `TResult2` = `never`
134
+ | Type Parameter | Default type |
135
+ | ------ | ------ |
136
+ | `TResult1` | `T` |
137
+ | `TResult2` | `never` |
139
138
 
140
139
  ### Parameters
141
140
 
142
- #### onfulfilled?
143
-
144
- The callback to execute when the Promise is resolved.
145
-
146
- (`value`) => `TResult1` \| `PromiseLike`\<`TResult1`\> | `null`
147
-
148
- #### onrejected?
149
-
150
- The callback to execute when the Promise is rejected.
151
-
152
- (`reason`) => `TResult2` \| `PromiseLike`\<`TResult2`\> | `null`
153
-
154
- #### onvalue?
155
-
156
- (`value?`) => `boolean`
141
+ | Parameter | Type | Description |
142
+ | ------ | ------ | ------ |
143
+ | `onfulfilled?` | (`value`: `T`) => `TResult1` \| `PromiseLike`\<`TResult1`\> \| `null` | The callback to execute when the Promise is resolved. |
144
+ | `onrejected?` | \| (`reason`: `unknown`) => `TResult2` \| `PromiseLike`\<`TResult2`\> \| `null` | The callback to execute when the Promise is rejected. |
145
+ | `onvalue?` | (`value?`: `V`) => `boolean` | - |
157
146
 
158
147
  ### Returns
159
148
 
@@ -172,18 +161,16 @@ Promise.then
172
161
  ### value()
173
162
 
174
163
  ```ts
175
- value(onvalue?): PromiseEx<T, V>;
164
+ value(onvalue?: (value?: V) => boolean): PromiseEx<T, V>;
176
165
  ```
177
166
 
178
167
  Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.
179
168
 
180
169
  ### Parameters
181
170
 
182
- #### onvalue?
183
-
184
- (`value?`) => `boolean`
185
-
186
- A callback that receives the attached value and returns whether to cancel.
171
+ | Parameter | Type | Description |
172
+ | ------ | ------ | ------ |
173
+ | `onvalue?` | (`value?`: `V`) => `boolean` | A callback that receives the attached value and returns whether to cancel. |
187
174
 
188
175
  ### Returns
189
176
 
@@ -200,22 +187,22 @@ This instance for chaining.
200
187
  ***
201
188
 
202
189
  ```ts
203
- function fulfilled<T>(val): val is PromiseFulfilledResult<T>;
190
+ function fulfilled<T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T>;
204
191
  ```
205
192
 
206
193
  For use with Promise.allSettled to filter only successful results
207
194
 
208
195
  ## Type Parameters
209
196
 
210
- ### T
211
-
212
- `T`
197
+ | Type Parameter |
198
+ | ------ |
199
+ | `T` |
213
200
 
214
201
  ## Parameters
215
202
 
216
- ### val
217
-
218
- `PromiseSettledResult`\<`T`\>
203
+ | Parameter | Type | Description |
204
+ | ------ | ------ | ------ |
205
+ | `val` | `PromiseSettledResult`\<`T`\> | - |
219
206
 
220
207
  ## Returns
221
208
 
@@ -228,26 +215,23 @@ For use with Promise.allSettled to filter only successful results
228
215
  ***
229
216
 
230
217
  ```ts
231
- function fulfilledValues<T>(previousValue, currentValue): T[];
218
+ function fulfilledValues<T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[];
232
219
  ```
233
220
 
234
221
  For use with Promise.allSettled to reduce to only successful result values
235
222
 
236
223
  ## Type Parameters
237
224
 
238
- ### T
239
-
240
- `T`
225
+ | Type Parameter |
226
+ | ------ |
227
+ | `T` |
241
228
 
242
229
  ## Parameters
243
230
 
244
- ### previousValue
245
-
246
- `T`[]
247
-
248
- ### currentValue
249
-
250
- `PromiseSettledResult`\<`T`\>
231
+ | Parameter | Type | Description |
232
+ | ------ | ------ | ------ |
233
+ | `previousValue` | `T`[] | - |
234
+ | `currentValue` | `PromiseSettledResult`\<`T`\> | - |
251
235
 
252
236
  ## Returns
253
237
 
@@ -280,16 +264,16 @@ const results = settled.reduce<string[]>(fulfilledValues, [])
280
264
  ## Call Signature
281
265
 
282
266
  ```ts
283
- function isPromise(value): value is Promise<unknown>;
267
+ function isPromise(value: unknown): value is Promise<unknown>;
284
268
  ```
285
269
 
286
270
  Type guard that checks whether a value is a Promise instance.
287
271
 
288
272
  ### Parameters
289
273
 
290
- ### value
291
-
292
- `unknown`
274
+ | Parameter | Type |
275
+ | ------ | ------ |
276
+ | `value` | `unknown` |
293
277
 
294
278
  ### Returns
295
279
 
@@ -298,22 +282,22 @@ Type guard that checks whether a value is a Promise instance.
298
282
  ## Call Signature
299
283
 
300
284
  ```ts
301
- function isPromise<T>(value): value is Extract<T, Promise<unknown>>;
285
+ function isPromise<T>(value: T): value is Extract<T, Promise<unknown>>;
302
286
  ```
303
287
 
304
288
  Type guard that checks whether a value is a Promise instance.
305
289
 
306
290
  ### Type Parameters
307
291
 
308
- ### T
309
-
310
- `T`
292
+ | Type Parameter |
293
+ | ------ |
294
+ | `T` |
311
295
 
312
296
  ### Parameters
313
297
 
314
- ### value
315
-
316
- `T`
298
+ | Parameter | Type |
299
+ | ------ | ------ |
300
+ | `value` | `T` |
317
301
 
318
302
  ### Returns
319
303
 
@@ -326,22 +310,22 @@ Type guard that checks whether a value is a Promise instance.
326
310
  ***
327
311
 
328
312
  ```ts
329
- function rejected<T>(val): val is PromiseRejectedResult;
313
+ function rejected<T>(val: PromiseSettledResult<T>): val is PromiseRejectedResult;
330
314
  ```
331
315
 
332
316
  For use with Promise.allSettled to filter only rejected results
333
317
 
334
318
  ## Type Parameters
335
319
 
336
- ### T
337
-
338
- `T`
320
+ | Type Parameter |
321
+ | ------ |
322
+ | `T` |
339
323
 
340
324
  ## Parameters
341
325
 
342
- ### val
343
-
344
- `PromiseSettledResult`\<`T`\>
326
+ | Parameter | Type | Description |
327
+ | ------ | ------ | ------ |
328
+ | `val` | `PromiseSettledResult`\<`T`\> | - |
345
329
 
346
330
  ## Returns
347
331
 
@@ -354,24 +338,22 @@ For use with Promise.allSettled to filter only rejected results
354
338
  ***
355
339
 
356
340
  ```ts
357
- function toPromise<T>(value): Promise<T>;
341
+ function toPromise<T>(value: Promisable<T>): Promise<T>;
358
342
  ```
359
343
 
360
344
  Wraps a value in a Promise if it is not already one.
361
345
 
362
346
  ## Type Parameters
363
347
 
364
- ### T
365
-
366
- `T`
348
+ | Type Parameter |
349
+ | ------ |
350
+ | `T` |
367
351
 
368
352
  ## Parameters
369
353
 
370
- ### value
371
-
372
- [`Promisable`](#../type-aliases/Promisable)\<`T`\>
373
-
374
- A value that may or may not be a Promise.
354
+ | Parameter | Type | Description |
355
+ | ------ | ------ | ------ |
356
+ | `value` | [`Promisable`](#../type-aliases/Promisable)\<`T`\> | A value that may or may not be a Promise. |
375
357
 
376
358
  ## Returns
377
359
 
@@ -391,15 +373,9 @@ An interface representing any thenable (promise-like) object.
391
373
 
392
374
  ## Properties
393
375
 
394
- ### then()
395
-
396
- ```ts
397
- then: () => unknown;
398
- ```
399
-
400
- ### Returns
401
-
402
- `unknown`
376
+ | Property | Type |
377
+ | ------ | ------ |
378
+ | <a id="then"></a> `then` | () => `unknown` |
403
379
 
404
380
  ### type-aliases
405
381
 
@@ -427,9 +403,9 @@ type AsyncMutex<T> = Promise<T>;
427
403
 
428
404
  ## Type Parameters
429
405
 
430
- ### T
431
-
432
- `T`
406
+ | Type Parameter |
407
+ | ------ |
408
+ | `T` |
433
409
 
434
410
  ## Description
435
411
 
@@ -449,13 +425,10 @@ A Promisable that may resolve to null.
449
425
 
450
426
  ## Type Parameters
451
427
 
452
- ### T
453
-
454
- `T`
455
-
456
- ### V
457
-
458
- `V` = `never`
428
+ | Type Parameter | Default type |
429
+ | ------ | ------ |
430
+ | `T` | - |
431
+ | `V` | `never` |
459
432
 
460
433
  ### <a id="NullablePromisableArray"></a>NullablePromisableArray
461
434
 
@@ -471,13 +444,10 @@ A Promisable array where elements may be null.
471
444
 
472
445
  ## Type Parameters
473
446
 
474
- ### T
475
-
476
- `T`
477
-
478
- ### V
479
-
480
- `V` = `never`
447
+ | Type Parameter | Default type |
448
+ | ------ | ------ |
449
+ | `T` | - |
450
+ | `V` | `never` |
481
451
 
482
452
  ### <a id="OptionalPromisable"></a>OptionalPromisable
483
453
 
@@ -493,13 +463,10 @@ A Promisable that may resolve to undefined.
493
463
 
494
464
  ## Type Parameters
495
465
 
496
- ### T
497
-
498
- `T`
499
-
500
- ### V
501
-
502
- `V` = `never`
466
+ | Type Parameter | Default type |
467
+ | ------ | ------ |
468
+ | `T` | - |
469
+ | `V` | `never` |
503
470
 
504
471
  ### <a id="OptionalPromisableArray"></a>OptionalPromisableArray
505
472
 
@@ -515,13 +482,10 @@ A Promisable array where elements may be undefined.
515
482
 
516
483
  ## Type Parameters
517
484
 
518
- ### T
519
-
520
- `T`
521
-
522
- ### V
523
-
524
- `V` = `never`
485
+ | Type Parameter | Default type |
486
+ | ------ | ------ |
487
+ | `T` | - |
488
+ | `V` | `never` |
525
489
 
526
490
  ### <a id="Promisable"></a>Promisable
527
491
 
@@ -537,13 +501,10 @@ A value that may be a Promise, PromiseEx, or a plain synchronous value.
537
501
 
538
502
  ## Type Parameters
539
503
 
540
- ### T
541
-
542
- `T`
543
-
544
- ### V
545
-
546
- `V` = `never`
504
+ | Type Parameter | Default type |
505
+ | ------ | ------ |
506
+ | `T` | - |
507
+ | `V` | `never` |
547
508
 
548
509
  ### <a id="PromisableArray"></a>PromisableArray
549
510
 
@@ -559,13 +520,10 @@ A Promisable that resolves to an array.
559
520
 
560
521
  ## Type Parameters
561
522
 
562
- ### T
563
-
564
- `T`
565
-
566
- ### V
567
-
568
- `V` = `never`
523
+ | Type Parameter | Default type |
524
+ | ------ | ------ |
525
+ | `T` | - |
526
+ | `V` | `never` |
569
527
 
570
528
  ### <a id="PromiseExFunc"></a>PromiseExFunc
571
529
 
@@ -574,26 +532,23 @@ A Promisable that resolves to an array.
574
532
  ***
575
533
 
576
534
  ```ts
577
- type PromiseExFunc<T> = (resolve?, reject?) => void;
535
+ type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void;
578
536
  ```
579
537
 
580
538
  The executor function passed to the PromiseEx constructor.
581
539
 
582
540
  ## Type Parameters
583
541
 
584
- ### T
585
-
586
- `T`
542
+ | Type Parameter |
543
+ | ------ |
544
+ | `T` |
587
545
 
588
546
  ## Parameters
589
547
 
590
- ### resolve?
591
-
592
- [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\>
593
-
594
- ### reject?
595
-
596
- [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\>
548
+ | Parameter | Type |
549
+ | ------ | ------ |
550
+ | `resolve?` | [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\> |
551
+ | `reject?` | [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\> |
597
552
 
598
553
  ## Returns
599
554
 
@@ -606,26 +561,23 @@ The executor function passed to the PromiseEx constructor.
606
561
  ***
607
562
 
608
563
  ```ts
609
- type PromiseExSubFunc<T, TResult> = (value) => TResult;
564
+ type PromiseExSubFunc<T, TResult> = (value: T) => TResult;
610
565
  ```
611
566
 
612
567
  A resolve/reject callback used within PromiseEx.
613
568
 
614
569
  ## Type Parameters
615
570
 
616
- ### T
617
-
618
- `T`
619
-
620
- ### TResult
621
-
622
- `TResult` = `T`
571
+ | Type Parameter | Default type |
572
+ | ------ | ------ |
573
+ | `T` | - |
574
+ | `TResult` | `T` |
623
575
 
624
576
  ## Parameters
625
577
 
626
- ### value
627
-
628
- `T`
578
+ | Parameter | Type |
579
+ | ------ | ------ |
580
+ | `value` | `T` |
629
581
 
630
582
  ## Returns
631
583
 
@@ -638,22 +590,22 @@ A resolve/reject callback used within PromiseEx.
638
590
  ***
639
591
 
640
592
  ```ts
641
- type PromiseExValueFunc<V> = (value?) => boolean;
593
+ type PromiseExValueFunc<V> = (value?: V) => boolean;
642
594
  ```
643
595
 
644
596
  A callback that inspects the attached value and returns whether to cancel the promise.
645
597
 
646
598
  ## Type Parameters
647
599
 
648
- ### V
649
-
650
- `V`
600
+ | Type Parameter |
601
+ | ------ |
602
+ | `V` |
651
603
 
652
604
  ## Parameters
653
605
 
654
- ### value?
655
-
656
- `V`
606
+ | Parameter | Type |
607
+ | ------ | ------ |
608
+ | `value?` | `V` |
657
609
 
658
610
  ## Returns
659
611
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/promise",
3
- "version": "5.0.84",
3
+ "version": "5.0.86",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "promise",
@@ -42,12 +42,12 @@
42
42
  "!**/*.test.*"
43
43
  ],
44
44
  "dependencies": {
45
- "@xylabs/typeof": "~5.0.84"
45
+ "@xylabs/typeof": "~5.0.86"
46
46
  },
47
47
  "devDependencies": {
48
- "@xylabs/ts-scripts-yarn3": "~7.4.13",
49
- "@xylabs/tsconfig": "~7.4.13",
50
- "@xylabs/vitest-extended": "~5.0.84",
48
+ "@xylabs/ts-scripts-yarn3": "~7.4.16",
49
+ "@xylabs/tsconfig": "~7.4.16",
50
+ "@xylabs/vitest-extended": "~5.0.86",
51
51
  "typescript": "~5.9.3",
52
52
  "vitest": "~4.0.18"
53
53
  },