@xylabs/promise 5.0.83 → 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.
- package/README.md +188 -193
- package/dist/neutral/PromiseEx.d.ts +13 -0
- package/dist/neutral/PromiseEx.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +26 -0
- package/dist/neutral/index.mjs +6 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/toPromise.d.ts +5 -0
- package/dist/neutral/toPromise.d.ts.map +1 -1
- package/dist/neutral/types.d.ts +8 -0
- package/dist/neutral/types.d.ts.map +1 -1
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
|
@@ -59,37 +69,34 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
59
69
|
|
|
60
70
|
***
|
|
61
71
|
|
|
72
|
+
An extended Promise that carries an optional attached value and supports cancellation.
|
|
73
|
+
The value can be inspected via the `then` or `value` methods to conditionally cancel.
|
|
74
|
+
|
|
62
75
|
## Extends
|
|
63
76
|
|
|
64
77
|
- `Promise`\<`T`\>
|
|
65
78
|
|
|
66
79
|
## Type Parameters
|
|
67
80
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`T`
|
|
71
|
-
|
|
72
|
-
### V
|
|
73
|
-
|
|
74
|
-
`V` = `void`
|
|
81
|
+
| Type Parameter | Default type |
|
|
82
|
+
| ------ | ------ |
|
|
83
|
+
| `T` | - |
|
|
84
|
+
| `V` | `void` |
|
|
75
85
|
|
|
76
86
|
## Constructors
|
|
77
87
|
|
|
78
88
|
### Constructor
|
|
79
89
|
|
|
80
90
|
```ts
|
|
81
|
-
new PromiseEx<T, V>(func
|
|
91
|
+
new PromiseEx<T, V>(func: PromiseExFunc<T>, value?: V): PromiseEx<T, V>;
|
|
82
92
|
```
|
|
83
93
|
|
|
84
94
|
### Parameters
|
|
85
95
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
[`PromiseExFunc`](#../type-aliases/PromiseExFunc)\<`T`\>
|
|
89
|
-
|
|
90
|
-
#### value?
|
|
91
|
-
|
|
92
|
-
`V`
|
|
96
|
+
| Parameter | Type |
|
|
97
|
+
| ------ | ------ |
|
|
98
|
+
| `func` | [`PromiseExFunc`](#../type-aliases/PromiseExFunc)\<`T`\> |
|
|
99
|
+
| `value?` | `V` |
|
|
93
100
|
|
|
94
101
|
### Returns
|
|
95
102
|
|
|
@@ -103,11 +110,9 @@ Promise<T>.constructor
|
|
|
103
110
|
|
|
104
111
|
## Properties
|
|
105
112
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
optional cancelled: boolean;
|
|
110
|
-
```
|
|
113
|
+
| Property | Type | Description |
|
|
114
|
+
| ------ | ------ | ------ |
|
|
115
|
+
| <a id="cancelled"></a> `cancelled?` | `boolean` | Whether the promise has been cancelled via a value callback. |
|
|
111
116
|
|
|
112
117
|
## Methods
|
|
113
118
|
|
|
@@ -115,40 +120,29 @@ optional cancelled: boolean;
|
|
|
115
120
|
|
|
116
121
|
```ts
|
|
117
122
|
then<TResult1, TResult2>(
|
|
118
|
-
onfulfilled
|
|
119
|
-
onrejected
|
|
120
|
-
|
|
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>;
|
|
121
128
|
```
|
|
122
129
|
|
|
123
130
|
Attaches callbacks for the resolution and/or rejection of the Promise.
|
|
124
131
|
|
|
125
132
|
### Type Parameters
|
|
126
133
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
`TResult1`
|
|
130
|
-
|
|
131
|
-
#### TResult2
|
|
132
|
-
|
|
133
|
-
`TResult2` = `never`
|
|
134
|
+
| Type Parameter | Default type |
|
|
135
|
+
| ------ | ------ |
|
|
136
|
+
| `TResult1` | `T` |
|
|
137
|
+
| `TResult2` | `never` |
|
|
134
138
|
|
|
135
139
|
### Parameters
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
The callback to execute when the Promise is resolved.
|
|
140
|
-
|
|
141
|
-
(`value`) => `
|
|
142
|
-
|
|
143
|
-
#### onrejected?
|
|
144
|
-
|
|
145
|
-
The callback to execute when the Promise is rejected.
|
|
146
|
-
|
|
147
|
-
(`reason`) => `TResult2` \| `PromiseLike`\<`TResult2`\> | `null`
|
|
148
|
-
|
|
149
|
-
#### onvalue?
|
|
150
|
-
|
|
151
|
-
(`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` | - |
|
|
152
146
|
|
|
153
147
|
### Returns
|
|
154
148
|
|
|
@@ -167,19 +161,23 @@ Promise.then
|
|
|
167
161
|
### value()
|
|
168
162
|
|
|
169
163
|
```ts
|
|
170
|
-
value(onvalue
|
|
164
|
+
value(onvalue?: (value?: V) => boolean): PromiseEx<T, V>;
|
|
171
165
|
```
|
|
172
166
|
|
|
173
|
-
|
|
167
|
+
Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.
|
|
174
168
|
|
|
175
|
-
|
|
169
|
+
### Parameters
|
|
176
170
|
|
|
177
|
-
|
|
171
|
+
| Parameter | Type | Description |
|
|
172
|
+
| ------ | ------ | ------ |
|
|
173
|
+
| `onvalue?` | (`value?`: `V`) => `boolean` | A callback that receives the attached value and returns whether to cancel. |
|
|
178
174
|
|
|
179
175
|
### Returns
|
|
180
176
|
|
|
181
177
|
`PromiseEx`\<`T`, `V`\>
|
|
182
178
|
|
|
179
|
+
This instance for chaining.
|
|
180
|
+
|
|
183
181
|
### functions
|
|
184
182
|
|
|
185
183
|
### <a id="fulfilled"></a>fulfilled
|
|
@@ -189,22 +187,22 @@ value(onvalue?): PromiseEx<T, V>;
|
|
|
189
187
|
***
|
|
190
188
|
|
|
191
189
|
```ts
|
|
192
|
-
function fulfilled<T>(val): val is PromiseFulfilledResult<T>;
|
|
190
|
+
function fulfilled<T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T>;
|
|
193
191
|
```
|
|
194
192
|
|
|
195
193
|
For use with Promise.allSettled to filter only successful results
|
|
196
194
|
|
|
197
195
|
## Type Parameters
|
|
198
196
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
`T`
|
|
197
|
+
| Type Parameter |
|
|
198
|
+
| ------ |
|
|
199
|
+
| `T` |
|
|
202
200
|
|
|
203
201
|
## Parameters
|
|
204
202
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
`PromiseSettledResult`\<`T`\>
|
|
203
|
+
| Parameter | Type | Description |
|
|
204
|
+
| ------ | ------ | ------ |
|
|
205
|
+
| `val` | `PromiseSettledResult`\<`T`\> | - |
|
|
208
206
|
|
|
209
207
|
## Returns
|
|
210
208
|
|
|
@@ -217,26 +215,23 @@ For use with Promise.allSettled to filter only successful results
|
|
|
217
215
|
***
|
|
218
216
|
|
|
219
217
|
```ts
|
|
220
|
-
function fulfilledValues<T>(previousValue, currentValue): T[];
|
|
218
|
+
function fulfilledValues<T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[];
|
|
221
219
|
```
|
|
222
220
|
|
|
223
221
|
For use with Promise.allSettled to reduce to only successful result values
|
|
224
222
|
|
|
225
223
|
## Type Parameters
|
|
226
224
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
`T`
|
|
225
|
+
| Type Parameter |
|
|
226
|
+
| ------ |
|
|
227
|
+
| `T` |
|
|
230
228
|
|
|
231
229
|
## Parameters
|
|
232
230
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
`T`[]
|
|
236
|
-
|
|
237
|
-
### currentValue
|
|
238
|
-
|
|
239
|
-
`PromiseSettledResult`\<`T`\>
|
|
231
|
+
| Parameter | Type | Description |
|
|
232
|
+
| ------ | ------ | ------ |
|
|
233
|
+
| `previousValue` | `T`[] | - |
|
|
234
|
+
| `currentValue` | `PromiseSettledResult`\<`T`\> | - |
|
|
240
235
|
|
|
241
236
|
## Returns
|
|
242
237
|
|
|
@@ -269,14 +264,16 @@ const results = settled.reduce<string[]>(fulfilledValues, [])
|
|
|
269
264
|
## Call Signature
|
|
270
265
|
|
|
271
266
|
```ts
|
|
272
|
-
function isPromise(value): value is Promise<unknown>;
|
|
267
|
+
function isPromise(value: unknown): value is Promise<unknown>;
|
|
273
268
|
```
|
|
274
269
|
|
|
275
|
-
|
|
270
|
+
Type guard that checks whether a value is a Promise instance.
|
|
276
271
|
|
|
277
|
-
###
|
|
272
|
+
### Parameters
|
|
278
273
|
|
|
279
|
-
|
|
274
|
+
| Parameter | Type |
|
|
275
|
+
| ------ | ------ |
|
|
276
|
+
| `value` | `unknown` |
|
|
280
277
|
|
|
281
278
|
### Returns
|
|
282
279
|
|
|
@@ -285,20 +282,22 @@ function isPromise(value): value is Promise<unknown>;
|
|
|
285
282
|
## Call Signature
|
|
286
283
|
|
|
287
284
|
```ts
|
|
288
|
-
function isPromise<T>(value): value is Extract<T, Promise<unknown>>;
|
|
285
|
+
function isPromise<T>(value: T): value is Extract<T, Promise<unknown>>;
|
|
289
286
|
```
|
|
290
287
|
|
|
291
|
-
|
|
288
|
+
Type guard that checks whether a value is a Promise instance.
|
|
292
289
|
|
|
293
|
-
###
|
|
290
|
+
### Type Parameters
|
|
294
291
|
|
|
295
|
-
|
|
292
|
+
| Type Parameter |
|
|
293
|
+
| ------ |
|
|
294
|
+
| `T` |
|
|
296
295
|
|
|
297
296
|
### Parameters
|
|
298
297
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
`T`
|
|
298
|
+
| Parameter | Type |
|
|
299
|
+
| ------ | ------ |
|
|
300
|
+
| `value` | `T` |
|
|
302
301
|
|
|
303
302
|
### Returns
|
|
304
303
|
|
|
@@ -311,22 +310,22 @@ function isPromise<T>(value): value is Extract<T, Promise<unknown>>;
|
|
|
311
310
|
***
|
|
312
311
|
|
|
313
312
|
```ts
|
|
314
|
-
function rejected<T>(val): val is PromiseRejectedResult;
|
|
313
|
+
function rejected<T>(val: PromiseSettledResult<T>): val is PromiseRejectedResult;
|
|
315
314
|
```
|
|
316
315
|
|
|
317
316
|
For use with Promise.allSettled to filter only rejected results
|
|
318
317
|
|
|
319
318
|
## Type Parameters
|
|
320
319
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
`T`
|
|
320
|
+
| Type Parameter |
|
|
321
|
+
| ------ |
|
|
322
|
+
| `T` |
|
|
324
323
|
|
|
325
324
|
## Parameters
|
|
326
325
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
`PromiseSettledResult`\<`T`\>
|
|
326
|
+
| Parameter | Type | Description |
|
|
327
|
+
| ------ | ------ | ------ |
|
|
328
|
+
| `val` | `PromiseSettledResult`\<`T`\> | - |
|
|
330
329
|
|
|
331
330
|
## Returns
|
|
332
331
|
|
|
@@ -339,25 +338,29 @@ For use with Promise.allSettled to filter only rejected results
|
|
|
339
338
|
***
|
|
340
339
|
|
|
341
340
|
```ts
|
|
342
|
-
function toPromise<T>(value): Promise<T>;
|
|
341
|
+
function toPromise<T>(value: Promisable<T>): Promise<T>;
|
|
343
342
|
```
|
|
344
343
|
|
|
345
|
-
|
|
344
|
+
Wraps a value in a Promise if it is not already one.
|
|
346
345
|
|
|
347
|
-
|
|
346
|
+
## Type Parameters
|
|
348
347
|
|
|
349
|
-
|
|
348
|
+
| Type Parameter |
|
|
349
|
+
| ------ |
|
|
350
|
+
| `T` |
|
|
350
351
|
|
|
351
352
|
## Parameters
|
|
352
353
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
[`Promisable`](#../type-aliases/Promisable)\<`T`\>
|
|
354
|
+
| Parameter | Type | Description |
|
|
355
|
+
| ------ | ------ | ------ |
|
|
356
|
+
| `value` | [`Promisable`](#../type-aliases/Promisable)\<`T`\> | A value that may or may not be a Promise. |
|
|
356
357
|
|
|
357
358
|
## Returns
|
|
358
359
|
|
|
359
360
|
`Promise`\<`T`\>
|
|
360
361
|
|
|
362
|
+
A Promise resolving to the value.
|
|
363
|
+
|
|
361
364
|
### interfaces
|
|
362
365
|
|
|
363
366
|
### <a id="PromiseType"></a>PromiseType
|
|
@@ -366,17 +369,13 @@ function toPromise<T>(value): Promise<T>;
|
|
|
366
369
|
|
|
367
370
|
***
|
|
368
371
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
### then()
|
|
372
|
-
|
|
373
|
-
```ts
|
|
374
|
-
then: () => unknown;
|
|
375
|
-
```
|
|
372
|
+
An interface representing any thenable (promise-like) object.
|
|
376
373
|
|
|
377
|
-
|
|
374
|
+
## Properties
|
|
378
375
|
|
|
379
|
-
|
|
376
|
+
| Property | Type |
|
|
377
|
+
| ------ | ------ |
|
|
378
|
+
| <a id="then"></a> `then` | () => `unknown` |
|
|
380
379
|
|
|
381
380
|
### type-aliases
|
|
382
381
|
|
|
@@ -390,6 +389,8 @@ then: () => unknown;
|
|
|
390
389
|
type AnyNonPromise = Exclude<TypedValue, PromiseType>;
|
|
391
390
|
```
|
|
392
391
|
|
|
392
|
+
Any non-promise typed value, excluding thenables.
|
|
393
|
+
|
|
393
394
|
### <a id="AsyncMutex"></a>AsyncMutex
|
|
394
395
|
|
|
395
396
|
[**@xylabs/promise**](#../README)
|
|
@@ -402,9 +403,9 @@ type AsyncMutex<T> = Promise<T>;
|
|
|
402
403
|
|
|
403
404
|
## Type Parameters
|
|
404
405
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
`T`
|
|
406
|
+
| Type Parameter |
|
|
407
|
+
| ------ |
|
|
408
|
+
| `T` |
|
|
408
409
|
|
|
409
410
|
## Description
|
|
410
411
|
|
|
@@ -420,15 +421,14 @@ Used to document promises that are being used as Mutexes
|
|
|
420
421
|
type NullablePromisable<T, V> = Promisable<T | null, V>;
|
|
421
422
|
```
|
|
422
423
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
### T
|
|
426
|
-
|
|
427
|
-
`T`
|
|
424
|
+
A Promisable that may resolve to null.
|
|
428
425
|
|
|
429
|
-
|
|
426
|
+
## Type Parameters
|
|
430
427
|
|
|
431
|
-
|
|
428
|
+
| Type Parameter | Default type |
|
|
429
|
+
| ------ | ------ |
|
|
430
|
+
| `T` | - |
|
|
431
|
+
| `V` | `never` |
|
|
432
432
|
|
|
433
433
|
### <a id="NullablePromisableArray"></a>NullablePromisableArray
|
|
434
434
|
|
|
@@ -440,15 +440,14 @@ type NullablePromisable<T, V> = Promisable<T | null, V>;
|
|
|
440
440
|
type NullablePromisableArray<T, V> = PromisableArray<T | null, V>;
|
|
441
441
|
```
|
|
442
442
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
### T
|
|
446
|
-
|
|
447
|
-
`T`
|
|
443
|
+
A Promisable array where elements may be null.
|
|
448
444
|
|
|
449
|
-
|
|
445
|
+
## Type Parameters
|
|
450
446
|
|
|
451
|
-
|
|
447
|
+
| Type Parameter | Default type |
|
|
448
|
+
| ------ | ------ |
|
|
449
|
+
| `T` | - |
|
|
450
|
+
| `V` | `never` |
|
|
452
451
|
|
|
453
452
|
### <a id="OptionalPromisable"></a>OptionalPromisable
|
|
454
453
|
|
|
@@ -460,15 +459,14 @@ type NullablePromisableArray<T, V> = PromisableArray<T | null, V>;
|
|
|
460
459
|
type OptionalPromisable<T, V> = Promisable<T | undefined, V>;
|
|
461
460
|
```
|
|
462
461
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
### T
|
|
462
|
+
A Promisable that may resolve to undefined.
|
|
466
463
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
### V
|
|
464
|
+
## Type Parameters
|
|
470
465
|
|
|
471
|
-
|
|
466
|
+
| Type Parameter | Default type |
|
|
467
|
+
| ------ | ------ |
|
|
468
|
+
| `T` | - |
|
|
469
|
+
| `V` | `never` |
|
|
472
470
|
|
|
473
471
|
### <a id="OptionalPromisableArray"></a>OptionalPromisableArray
|
|
474
472
|
|
|
@@ -480,15 +478,14 @@ type OptionalPromisable<T, V> = Promisable<T | undefined, V>;
|
|
|
480
478
|
type OptionalPromisableArray<T, V> = PromisableArray<T | undefined, V>;
|
|
481
479
|
```
|
|
482
480
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
### T
|
|
486
|
-
|
|
487
|
-
`T`
|
|
481
|
+
A Promisable array where elements may be undefined.
|
|
488
482
|
|
|
489
|
-
|
|
483
|
+
## Type Parameters
|
|
490
484
|
|
|
491
|
-
|
|
485
|
+
| Type Parameter | Default type |
|
|
486
|
+
| ------ | ------ |
|
|
487
|
+
| `T` | - |
|
|
488
|
+
| `V` | `never` |
|
|
492
489
|
|
|
493
490
|
### <a id="Promisable"></a>Promisable
|
|
494
491
|
|
|
@@ -500,15 +497,14 @@ type OptionalPromisableArray<T, V> = PromisableArray<T | undefined, V>;
|
|
|
500
497
|
type Promisable<T, V> = PromiseEx<T, V> | Promise<T> | T;
|
|
501
498
|
```
|
|
502
499
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
### T
|
|
500
|
+
A value that may be a Promise, PromiseEx, or a plain synchronous value.
|
|
506
501
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
### V
|
|
502
|
+
## Type Parameters
|
|
510
503
|
|
|
511
|
-
|
|
504
|
+
| Type Parameter | Default type |
|
|
505
|
+
| ------ | ------ |
|
|
506
|
+
| `T` | - |
|
|
507
|
+
| `V` | `never` |
|
|
512
508
|
|
|
513
509
|
### <a id="PromisableArray"></a>PromisableArray
|
|
514
510
|
|
|
@@ -520,15 +516,14 @@ type Promisable<T, V> = PromiseEx<T, V> | Promise<T> | T;
|
|
|
520
516
|
type PromisableArray<T, V> = Promisable<T[], V>;
|
|
521
517
|
```
|
|
522
518
|
|
|
523
|
-
|
|
519
|
+
A Promisable that resolves to an array.
|
|
524
520
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
`T`
|
|
528
|
-
|
|
529
|
-
### V
|
|
521
|
+
## Type Parameters
|
|
530
522
|
|
|
531
|
-
|
|
523
|
+
| Type Parameter | Default type |
|
|
524
|
+
| ------ | ------ |
|
|
525
|
+
| `T` | - |
|
|
526
|
+
| `V` | `never` |
|
|
532
527
|
|
|
533
528
|
### <a id="PromiseExFunc"></a>PromiseExFunc
|
|
534
529
|
|
|
@@ -537,24 +532,23 @@ type PromisableArray<T, V> = Promisable<T[], V>;
|
|
|
537
532
|
***
|
|
538
533
|
|
|
539
534
|
```ts
|
|
540
|
-
type PromiseExFunc<T> = (resolve
|
|
535
|
+
type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void;
|
|
541
536
|
```
|
|
542
537
|
|
|
543
|
-
|
|
538
|
+
The executor function passed to the PromiseEx constructor.
|
|
544
539
|
|
|
545
|
-
|
|
540
|
+
## Type Parameters
|
|
546
541
|
|
|
547
|
-
|
|
542
|
+
| Type Parameter |
|
|
543
|
+
| ------ |
|
|
544
|
+
| `T` |
|
|
548
545
|
|
|
549
546
|
## Parameters
|
|
550
547
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
[`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\>
|
|
554
|
-
|
|
555
|
-
### reject?
|
|
556
|
-
|
|
557
|
-
[`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\>
|
|
548
|
+
| Parameter | Type |
|
|
549
|
+
| ------ | ------ |
|
|
550
|
+
| `resolve?` | [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\> |
|
|
551
|
+
| `reject?` | [`PromiseExSubFunc`](#PromiseExSubFunc)\<`T`, `void`\> |
|
|
558
552
|
|
|
559
553
|
## Returns
|
|
560
554
|
|
|
@@ -567,24 +561,23 @@ type PromiseExFunc<T> = (resolve?, reject?) => void;
|
|
|
567
561
|
***
|
|
568
562
|
|
|
569
563
|
```ts
|
|
570
|
-
type PromiseExSubFunc<T, TResult> = (value) => TResult;
|
|
564
|
+
type PromiseExSubFunc<T, TResult> = (value: T) => TResult;
|
|
571
565
|
```
|
|
572
566
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
### T
|
|
576
|
-
|
|
577
|
-
`T`
|
|
567
|
+
A resolve/reject callback used within PromiseEx.
|
|
578
568
|
|
|
579
|
-
|
|
569
|
+
## Type Parameters
|
|
580
570
|
|
|
581
|
-
|
|
571
|
+
| Type Parameter | Default type |
|
|
572
|
+
| ------ | ------ |
|
|
573
|
+
| `T` | - |
|
|
574
|
+
| `TResult` | `T` |
|
|
582
575
|
|
|
583
576
|
## Parameters
|
|
584
577
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
`T`
|
|
578
|
+
| Parameter | Type |
|
|
579
|
+
| ------ | ------ |
|
|
580
|
+
| `value` | `T` |
|
|
588
581
|
|
|
589
582
|
## Returns
|
|
590
583
|
|
|
@@ -597,20 +590,22 @@ type PromiseExSubFunc<T, TResult> = (value) => TResult;
|
|
|
597
590
|
***
|
|
598
591
|
|
|
599
592
|
```ts
|
|
600
|
-
type PromiseExValueFunc<V> = (value
|
|
593
|
+
type PromiseExValueFunc<V> = (value?: V) => boolean;
|
|
601
594
|
```
|
|
602
595
|
|
|
603
|
-
|
|
596
|
+
A callback that inspects the attached value and returns whether to cancel the promise.
|
|
604
597
|
|
|
605
|
-
|
|
598
|
+
## Type Parameters
|
|
606
599
|
|
|
607
|
-
|
|
600
|
+
| Type Parameter |
|
|
601
|
+
| ------ |
|
|
602
|
+
| `V` |
|
|
608
603
|
|
|
609
604
|
## Parameters
|
|
610
605
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
`V`
|
|
606
|
+
| Parameter | Type |
|
|
607
|
+
| ------ | ------ |
|
|
608
|
+
| `value?` | `V` |
|
|
614
609
|
|
|
615
610
|
## Returns
|
|
616
611
|
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
/** A resolve/reject callback used within PromiseEx. */
|
|
1
2
|
export type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult;
|
|
3
|
+
/** The executor function passed to the PromiseEx constructor. */
|
|
2
4
|
export type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void;
|
|
5
|
+
/** A callback that inspects the attached value and returns whether to cancel the promise. */
|
|
3
6
|
export type PromiseExValueFunc<V> = (value?: V) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* An extended Promise that carries an optional attached value and supports cancellation.
|
|
9
|
+
* The value can be inspected via the `then` or `value` methods to conditionally cancel.
|
|
10
|
+
*/
|
|
4
11
|
export declare class PromiseEx<T, V = void> extends Promise<T> {
|
|
12
|
+
/** Whether the promise has been cancelled via a value callback. */
|
|
5
13
|
cancelled?: boolean;
|
|
6
14
|
private _value?;
|
|
7
15
|
constructor(func: PromiseExFunc<T>, value?: V);
|
|
8
16
|
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined, onvalue?: (value?: V) => boolean): Promise<TResult1 | TResult2>;
|
|
17
|
+
/**
|
|
18
|
+
* Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.
|
|
19
|
+
* @param onvalue - A callback that receives the attached value and returns whether to cancel.
|
|
20
|
+
* @returns This instance for chaining.
|
|
21
|
+
*/
|
|
9
22
|
value(onvalue?: (value?: V) => boolean): this;
|
|
10
23
|
}
|
|
11
24
|
//# sourceMappingURL=PromiseEx.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromiseEx.d.ts","sourceRoot":"","sources":["../../src/PromiseEx.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"PromiseEx.d.ts","sourceRoot":"","sources":["../../src/PromiseEx.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAA;AAEpE,iEAAiE;AACjE,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,IAAI,CAAA;AAEhH,6FAA6F;AAC7F,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;AAE1D;;;GAGG;AACH,qBAAa,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAE,SAAQ,OAAO,CAAC,CAAC,CAAC;IACpD,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,MAAM,CAAC,CAAG;gBAEN,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;IAMpC,IAAI,CAAC,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,KAAK,EAC1C,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EACjF,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EACvF,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,OAAO,GAC/B,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAO/B;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,OAAO;CAMvC"}
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -28,14 +28,27 @@ declare const fulfilled: <T>(val: PromiseSettledResult<T>) => val is PromiseFulf
|
|
|
28
28
|
*/
|
|
29
29
|
declare const fulfilledValues: <T>(previousValue: T[], currentValue: PromiseSettledResult<T>) => T[];
|
|
30
30
|
|
|
31
|
+
/** A resolve/reject callback used within PromiseEx. */
|
|
31
32
|
type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult;
|
|
33
|
+
/** The executor function passed to the PromiseEx constructor. */
|
|
32
34
|
type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void;
|
|
35
|
+
/** A callback that inspects the attached value and returns whether to cancel the promise. */
|
|
33
36
|
type PromiseExValueFunc<V> = (value?: V) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* An extended Promise that carries an optional attached value and supports cancellation.
|
|
39
|
+
* The value can be inspected via the `then` or `value` methods to conditionally cancel.
|
|
40
|
+
*/
|
|
34
41
|
declare class PromiseEx<T, V = void> extends Promise<T> {
|
|
42
|
+
/** Whether the promise has been cancelled via a value callback. */
|
|
35
43
|
cancelled?: boolean;
|
|
36
44
|
private _value?;
|
|
37
45
|
constructor(func: PromiseExFunc<T>, value?: V);
|
|
38
46
|
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined, onvalue?: (value?: V) => boolean): Promise<TResult1 | TResult2>;
|
|
47
|
+
/**
|
|
48
|
+
* Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.
|
|
49
|
+
* @param onvalue - A callback that receives the attached value and returns whether to cancel.
|
|
50
|
+
* @returns This instance for chaining.
|
|
51
|
+
*/
|
|
39
52
|
value(onvalue?: (value?: V) => boolean): this;
|
|
40
53
|
}
|
|
41
54
|
|
|
@@ -46,19 +59,32 @@ declare class PromiseEx<T, V = void> extends Promise<T> {
|
|
|
46
59
|
*/
|
|
47
60
|
declare const rejected: <T>(val: PromiseSettledResult<T>) => val is PromiseRejectedResult;
|
|
48
61
|
|
|
62
|
+
/** A value that may be a Promise, PromiseEx, or a plain synchronous value. */
|
|
49
63
|
type Promisable<T, V = never> = PromiseEx<T, V> | Promise<T> | T;
|
|
64
|
+
/** A Promisable that resolves to an array. */
|
|
50
65
|
type PromisableArray<T, V = never> = Promisable<T[], V>;
|
|
66
|
+
/** A Promisable that may resolve to undefined. */
|
|
51
67
|
type OptionalPromisable<T, V = never> = Promisable<T | undefined, V>;
|
|
68
|
+
/** A Promisable array where elements may be undefined. */
|
|
52
69
|
type OptionalPromisableArray<T, V = never> = PromisableArray<T | undefined, V>;
|
|
70
|
+
/** A Promisable that may resolve to null. */
|
|
53
71
|
type NullablePromisable<T, V = never> = Promisable<T | null, V>;
|
|
72
|
+
/** A Promisable array where elements may be null. */
|
|
54
73
|
type NullablePromisableArray<T, V = never> = PromisableArray<T | null, V>;
|
|
55
74
|
/** @description Used to document promises that are being used as Mutexes */
|
|
56
75
|
type AsyncMutex<T> = Promise<T>;
|
|
76
|
+
/** An interface representing any thenable (promise-like) object. */
|
|
57
77
|
interface PromiseType {
|
|
58
78
|
then: () => unknown;
|
|
59
79
|
}
|
|
80
|
+
/** Any non-promise typed value, excluding thenables. */
|
|
60
81
|
type AnyNonPromise = Exclude<TypedValue, PromiseType>;
|
|
61
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Wraps a value in a Promise if it is not already one.
|
|
85
|
+
* @param value - A value that may or may not be a Promise.
|
|
86
|
+
* @returns A Promise resolving to the value.
|
|
87
|
+
*/
|
|
62
88
|
declare function toPromise<T>(value: Promisable<T>): Promise<T>;
|
|
63
89
|
|
|
64
90
|
export { PromiseEx, fulfilled, fulfilledValues, rejected, toPromise };
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ var fulfilledValues = (previousValue, currentValue) => {
|
|
|
11
11
|
|
|
12
12
|
// src/PromiseEx.ts
|
|
13
13
|
var PromiseEx = class extends Promise {
|
|
14
|
+
/** Whether the promise has been cancelled via a value callback. */
|
|
14
15
|
cancelled;
|
|
15
16
|
_value;
|
|
16
17
|
constructor(func, value) {
|
|
@@ -24,6 +25,11 @@ var PromiseEx = class extends Promise {
|
|
|
24
25
|
}
|
|
25
26
|
return super.then(onfulfilled, onrejected);
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.
|
|
30
|
+
* @param onvalue - A callback that receives the attached value and returns whether to cancel.
|
|
31
|
+
* @returns This instance for chaining.
|
|
32
|
+
*/
|
|
27
33
|
value(onvalue) {
|
|
28
34
|
if (onvalue?.(this._value)) {
|
|
29
35
|
this.cancelled = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fulfilled.ts","../../src/fulfilledValues.ts","../../src/PromiseEx.ts","../../src/rejected.ts","../../src/toPromise.ts","../../src/index.ts"],"sourcesContent":["/**\n * For use with Promise.allSettled to filter only successful results\n * @param val\n * @returns\n */\nexport const fulfilled = <T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T> => {\n return val.status === 'fulfilled'\n}\n","/**\n * For use with Promise.allSettled to reduce to only successful result values\n * @example <caption>Casting the initialValue provided to reduce</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce(fulfilledValues, [] as string[])\n * // results === [ 'resolved' ]\n * @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce<string[]>(fulfilledValues, [])\n * // results === [ 'resolved' ]\n * @param previousValue\n * @param currentValue\n * @returns\n */\nexport const fulfilledValues = <T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[] => {\n if (currentValue.status === 'fulfilled') previousValue.push(currentValue.value)\n return previousValue\n}\n","
|
|
1
|
+
{"version":3,"sources":["../../src/fulfilled.ts","../../src/fulfilledValues.ts","../../src/PromiseEx.ts","../../src/rejected.ts","../../src/toPromise.ts","../../src/index.ts"],"sourcesContent":["/**\n * For use with Promise.allSettled to filter only successful results\n * @param val\n * @returns\n */\nexport const fulfilled = <T>(val: PromiseSettledResult<T>): val is PromiseFulfilledResult<T> => {\n return val.status === 'fulfilled'\n}\n","/**\n * For use with Promise.allSettled to reduce to only successful result values\n * @example <caption>Casting the initialValue provided to reduce</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce(fulfilledValues, [] as string[])\n * // results === [ 'resolved' ]\n * @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>\n * const resolved = Promise.resolve('resolved')\n * const rejected = Promise.reject('rejected')\n * const settled = await Promise.allSettled([resolved, rejected])\n * const results = settled.reduce<string[]>(fulfilledValues, [])\n * // results === [ 'resolved' ]\n * @param previousValue\n * @param currentValue\n * @returns\n */\nexport const fulfilledValues = <T>(previousValue: T[], currentValue: PromiseSettledResult<T>): T[] => {\n if (currentValue.status === 'fulfilled') previousValue.push(currentValue.value)\n return previousValue\n}\n","/** A resolve/reject callback used within PromiseEx. */\nexport type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult\n\n/** The executor function passed to the PromiseEx constructor. */\nexport type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void\n\n/** A callback that inspects the attached value and returns whether to cancel the promise. */\nexport type PromiseExValueFunc<V> = (value?: V) => boolean\n\n/**\n * An extended Promise that carries an optional attached value and supports cancellation.\n * The value can be inspected via the `then` or `value` methods to conditionally cancel.\n */\nexport class PromiseEx<T, V = void> extends Promise<T> {\n /** Whether the promise has been cancelled via a value callback. */\n cancelled?: boolean\n private _value?: V\n\n constructor(func: PromiseExFunc<T>, value?: V) {\n super(func)\n this._value = value\n }\n\n // eslint-disable-next-line unicorn/no-thenable\n override then<TResult1 = T, TResult2 = never>(\n onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n onvalue?: (value?: V) => boolean,\n ): Promise<TResult1 | TResult2> {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return super.then(onfulfilled, onrejected)\n }\n\n /**\n * Inspects the attached value via the callback; if it returns true, marks the promise as cancelled.\n * @param onvalue - A callback that receives the attached value and returns whether to cancel.\n * @returns This instance for chaining.\n */\n value(onvalue?: (value?: V) => boolean) {\n if (onvalue?.(this._value)) {\n this.cancelled = true\n }\n return this\n }\n}\n","/**\n * For use with Promise.allSettled to filter only rejected results\n * @param val\n * @returns\n */\nexport const rejected = <T>(val: PromiseSettledResult<T>): val is PromiseRejectedResult => {\n return val.status === 'rejected'\n}\n","import type { Promisable } from './types.ts'\n\n/**\n * Wraps a value in a Promise if it is not already one.\n * @param value - A value that may or may not be a Promise.\n * @returns A Promise resolving to the value.\n */\nexport function toPromise<T>(value: Promisable<T>): Promise<T> {\n return value instanceof Promise ? value : Promise.resolve(value)\n}\n","export { fulfilled } from './fulfilled.ts'\nexport { fulfilledValues } from './fulfilledValues.ts'\nexport * from './PromiseEx.ts'\nexport { rejected } from './rejected.ts'\nexport * from './toPromise.ts'\nexport * from './types.ts'\nexport { isPromise } from '@xylabs/typeof'\n"],"mappings":";AAKO,IAAM,YAAY,CAAI,QAAmE;AAC9F,SAAO,IAAI,WAAW;AACxB;;;ACWO,IAAM,kBAAkB,CAAI,eAAoB,iBAA+C;AACpG,MAAI,aAAa,WAAW,YAAa,eAAc,KAAK,aAAa,KAAK;AAC9E,SAAO;AACT;;;ACRO,IAAM,YAAN,cAAqC,QAAW;AAAA;AAAA,EAErD;AAAA,EACQ;AAAA,EAER,YAAY,MAAwB,OAAW;AAC7C,UAAM,IAAI;AACV,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGS,KACP,aACA,YACA,SAC8B;AAC9B,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO,MAAM,KAAK,aAAa,UAAU;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAkC;AACtC,QAAI,UAAU,KAAK,MAAM,GAAG;AAC1B,WAAK,YAAY;AAAA,IACnB;AACA,WAAO;AAAA,EACT;AACF;;;ACzCO,IAAM,WAAW,CAAI,QAA+D;AACzF,SAAO,IAAI,WAAW;AACxB;;;ACAO,SAAS,UAAa,OAAkC;AAC7D,SAAO,iBAAiB,UAAU,QAAQ,QAAQ,QAAQ,KAAK;AACjE;;;ACHA,SAAS,iBAAiB;","names":[]}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { Promisable } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a value in a Promise if it is not already one.
|
|
4
|
+
* @param value - A value that may or may not be a Promise.
|
|
5
|
+
* @returns A Promise resolving to the value.
|
|
6
|
+
*/
|
|
2
7
|
export declare function toPromise<T>(value: Promisable<T>): Promise<T>;
|
|
3
8
|
//# sourceMappingURL=toPromise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toPromise.d.ts","sourceRoot":"","sources":["../../src/toPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE7D"}
|
|
1
|
+
{"version":3,"file":"toPromise.d.ts","sourceRoot":"","sources":["../../src/toPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE7D"}
|
package/dist/neutral/types.d.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import type { TypedValue } from '@xylabs/typeof';
|
|
2
2
|
import type { PromiseEx } from './PromiseEx.ts';
|
|
3
|
+
/** A value that may be a Promise, PromiseEx, or a plain synchronous value. */
|
|
3
4
|
export type Promisable<T, V = never> = PromiseEx<T, V> | Promise<T> | T;
|
|
5
|
+
/** A Promisable that resolves to an array. */
|
|
4
6
|
export type PromisableArray<T, V = never> = Promisable<T[], V>;
|
|
7
|
+
/** A Promisable that may resolve to undefined. */
|
|
5
8
|
export type OptionalPromisable<T, V = never> = Promisable<T | undefined, V>;
|
|
9
|
+
/** A Promisable array where elements may be undefined. */
|
|
6
10
|
export type OptionalPromisableArray<T, V = never> = PromisableArray<T | undefined, V>;
|
|
11
|
+
/** A Promisable that may resolve to null. */
|
|
7
12
|
export type NullablePromisable<T, V = never> = Promisable<T | null, V>;
|
|
13
|
+
/** A Promisable array where elements may be null. */
|
|
8
14
|
export type NullablePromisableArray<T, V = never> = PromisableArray<T | null, V>;
|
|
9
15
|
/** @description Used to document promises that are being used as Mutexes */
|
|
10
16
|
export type AsyncMutex<T> = Promise<T>;
|
|
17
|
+
/** An interface representing any thenable (promise-like) object. */
|
|
11
18
|
export interface PromiseType {
|
|
12
19
|
then: () => unknown;
|
|
13
20
|
}
|
|
21
|
+
/** Any non-promise typed value, excluding thenables. */
|
|
14
22
|
export type AnyNonPromise = Exclude<TypedValue, PromiseType>;
|
|
15
23
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,8EAA8E;AAC9E,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEvE,8CAA8C;AAC9C,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAE9D,kDAAkD;AAClD,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAA;AAE3E,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,eAAe,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAA;AAErF,6CAA6C;AAC7C,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;AAEtE,qDAAqD;AACrD,MAAM,MAAM,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,eAAe,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;AAEhF,4EAA4E;AAC5E,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAA;AAEtC,oEAAoE;AACpE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,OAAO,CAAA;CACpB;AAED,wDAAwD;AACxD,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/promise",
|
|
3
|
-
"version": "5.0.
|
|
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.
|
|
45
|
+
"@xylabs/typeof": "~5.0.86"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
49
|
-
"@xylabs/tsconfig": "~7.4.
|
|
50
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
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
|
},
|