@xylabs/promise 4.13.4 → 4.13.5
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/neutral/index.d.ts +66 -76
- package/package.json +6 -6
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,76 +1,66 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* const
|
|
20
|
-
* const
|
|
21
|
-
* const
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* For use with Promise.allSettled to filter only rejected results
|
|
69
|
-
* @param val
|
|
70
|
-
* @returns
|
|
71
|
-
*/
|
|
72
|
-
export declare const rejected: <T>(val: PromiseSettledResult<T>) => val is PromiseRejectedResult;
|
|
73
|
-
|
|
74
|
-
export declare function toPromise<T>(value: Promisable<T>): Promise<T>;
|
|
75
|
-
|
|
76
|
-
export { }
|
|
1
|
+
import { TypedValue } from '@xylabs/typeof';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* For use with Promise.allSettled to filter only successful results
|
|
5
|
+
* @param val
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
declare const fulfilled: <T>(val: PromiseSettledResult<T>) => val is PromiseFulfilledResult<T>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* For use with Promise.allSettled to reduce to only successful result values
|
|
12
|
+
* @example <caption>Casting the initialValue provided to reduce</caption>
|
|
13
|
+
* const resolved = Promise.resolve('resolved')
|
|
14
|
+
* const rejected = Promise.reject('rejected')
|
|
15
|
+
* const settled = await Promise.allSettled([resolved, rejected])
|
|
16
|
+
* const results = settled.reduce(fulfilledValues, [] as string[])
|
|
17
|
+
* // results === [ 'resolved' ]
|
|
18
|
+
* @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>
|
|
19
|
+
* const resolved = Promise.resolve('resolved')
|
|
20
|
+
* const rejected = Promise.reject('rejected')
|
|
21
|
+
* const settled = await Promise.allSettled([resolved, rejected])
|
|
22
|
+
* const results = settled.reduce<string[]>(fulfilledValues, [])
|
|
23
|
+
* // results === [ 'resolved' ]
|
|
24
|
+
* @param previousValue
|
|
25
|
+
* @param currentValue
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
declare const fulfilledValues: <T>(previousValue: T[], currentValue: PromiseSettledResult<T>) => T[];
|
|
29
|
+
|
|
30
|
+
interface PromiseType {
|
|
31
|
+
then: () => unknown;
|
|
32
|
+
}
|
|
33
|
+
type AnyNonPromise = Exclude<TypedValue, PromiseType>;
|
|
34
|
+
declare const isPromise: (value: unknown) => value is Promise<unknown>;
|
|
35
|
+
|
|
36
|
+
type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult;
|
|
37
|
+
type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void;
|
|
38
|
+
type PromiseExValueFunc<V> = (value?: V) => boolean;
|
|
39
|
+
declare class PromiseEx<T, V = void> extends Promise<T> {
|
|
40
|
+
cancelled?: boolean;
|
|
41
|
+
private _value?;
|
|
42
|
+
constructor(func: PromiseExFunc<T>, value?: V);
|
|
43
|
+
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>;
|
|
44
|
+
value(onvalue?: (value?: V) => boolean): this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* For use with Promise.allSettled to filter only rejected results
|
|
49
|
+
* @param val
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
declare const rejected: <T>(val: PromiseSettledResult<T>) => val is PromiseRejectedResult;
|
|
53
|
+
|
|
54
|
+
type Promisable<T, V = never> = PromiseEx<T, V> | Promise<T> | T;
|
|
55
|
+
type PromisableArray<T, V = never> = Promisable<T[], V>;
|
|
56
|
+
type OptionalPromisable<T, V = never> = Promisable<T | undefined, V>;
|
|
57
|
+
type OptionalPromisableArray<T, V = never> = PromisableArray<T | undefined, V>;
|
|
58
|
+
type NullablePromisable<T, V = never> = Promisable<T | null, V>;
|
|
59
|
+
type NullablePromisableArray<T, V = never> = PromisableArray<T | null, V>;
|
|
60
|
+
/** @description Used to document promises that are being used as Mutexes */
|
|
61
|
+
type AsyncMutex<T> = Promise<T>;
|
|
62
|
+
|
|
63
|
+
declare function toPromise<T>(value: Promisable<T>): Promise<T>;
|
|
64
|
+
|
|
65
|
+
export { PromiseEx, fulfilled, fulfilledValues, isPromise, rejected, toPromise };
|
|
66
|
+
export type { AnyNonPromise, AsyncMutex, NullablePromisable, NullablePromisableArray, OptionalPromisable, OptionalPromisableArray, Promisable, PromisableArray, PromiseExFunc, PromiseExSubFunc, PromiseExValueFunc, PromiseType };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/promise",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.5",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"promise",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"module": "./dist/neutral/index.mjs",
|
|
37
37
|
"types": "./dist/neutral/index.d.ts",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@xylabs/typeof": "^4.13.
|
|
39
|
+
"@xylabs/typeof": "^4.13.5"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.0-rc.
|
|
43
|
-
"@xylabs/tsconfig": "^7.0.0-rc.
|
|
44
|
-
"@xylabs/typeof": "^4.13.
|
|
45
|
-
"@xylabs/vitest-extended": "^4.13.
|
|
42
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.0-rc.8",
|
|
43
|
+
"@xylabs/tsconfig": "^7.0.0-rc.8",
|
|
44
|
+
"@xylabs/typeof": "^4.13.5",
|
|
45
|
+
"@xylabs/vitest-extended": "^4.13.5",
|
|
46
46
|
"typescript": "^5.8.3",
|
|
47
47
|
"vitest": "^3.2.4"
|
|
48
48
|
},
|