@xylabs/promise 4.12.44 → 4.13.1
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 +76 -0
- package/package.json +8 -8
- package/dist/types/PromiseEx.d.ts +0 -11
- package/dist/types/PromiseEx.d.ts.map +0 -1
- package/dist/types/fulfilled.d.ts +0 -7
- package/dist/types/fulfilled.d.ts.map +0 -1
- package/dist/types/fulfilledValues.d.ts +0 -20
- package/dist/types/fulfilledValues.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -8
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/isPromise.d.ts +0 -7
- package/dist/types/isPromise.d.ts.map +0 -1
- package/dist/types/rejected.d.ts +0 -7
- package/dist/types/rejected.d.ts.map +0 -1
- package/dist/types/toPromise.d.ts +0 -3
- package/dist/types/toPromise.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -10
- package/dist/types/types.d.ts.map +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { TypedValue } from '@xylabs/typeof';
|
|
2
|
+
|
|
3
|
+
export declare type AnyNonPromise = Exclude<TypedValue, PromiseType>;
|
|
4
|
+
|
|
5
|
+
/** @description Used to document promises that are being used as Mutexes */
|
|
6
|
+
export declare type AsyncMutex<T> = Promise<T>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* For use with Promise.allSettled to filter only successful results
|
|
10
|
+
* @param val
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare const fulfilled: <T>(val: PromiseSettledResult<T>) => val is PromiseFulfilledResult<T>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* For use with Promise.allSettled to reduce to only successful result values
|
|
17
|
+
* @example <caption>Casting the initialValue provided to reduce</caption>
|
|
18
|
+
* const resolved = Promise.resolve('resolved')
|
|
19
|
+
* const rejected = Promise.reject('rejected')
|
|
20
|
+
* const settled = await Promise.allSettled([resolved, rejected])
|
|
21
|
+
* const results = settled.reduce(fulfilledValues, [] as string[])
|
|
22
|
+
* // results === [ 'resolved' ]
|
|
23
|
+
* @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>
|
|
24
|
+
* const resolved = Promise.resolve('resolved')
|
|
25
|
+
* const rejected = Promise.reject('rejected')
|
|
26
|
+
* const settled = await Promise.allSettled([resolved, rejected])
|
|
27
|
+
* const results = settled.reduce<string[]>(fulfilledValues, [])
|
|
28
|
+
* // results === [ 'resolved' ]
|
|
29
|
+
* @param previousValue
|
|
30
|
+
* @param currentValue
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export declare const fulfilledValues: <T>(previousValue: T[], currentValue: PromiseSettledResult<T>) => T[];
|
|
34
|
+
|
|
35
|
+
export declare const isPromise: (value: unknown) => value is Promise<unknown>;
|
|
36
|
+
|
|
37
|
+
export declare type NullablePromisable<T, V = never> = Promisable<T | null, V>;
|
|
38
|
+
|
|
39
|
+
export declare type NullablePromisableArray<T, V = never> = PromisableArray<T | null, V>;
|
|
40
|
+
|
|
41
|
+
export declare type OptionalPromisable<T, V = never> = Promisable<T | undefined, V>;
|
|
42
|
+
|
|
43
|
+
export declare type OptionalPromisableArray<T, V = never> = PromisableArray<T | undefined, V>;
|
|
44
|
+
|
|
45
|
+
export declare type Promisable<T, V = never> = PromiseEx<T, V> | Promise<T> | T;
|
|
46
|
+
|
|
47
|
+
export declare type PromisableArray<T, V = never> = Promisable<T[], V>;
|
|
48
|
+
|
|
49
|
+
export declare class PromiseEx<T, V = void> extends Promise<T> {
|
|
50
|
+
cancelled?: boolean;
|
|
51
|
+
private _value?;
|
|
52
|
+
constructor(func: PromiseExFunc<T>, value?: V);
|
|
53
|
+
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>;
|
|
54
|
+
value(onvalue?: (value?: V) => boolean): this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export declare type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void;
|
|
58
|
+
|
|
59
|
+
export declare type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult;
|
|
60
|
+
|
|
61
|
+
export declare type PromiseExValueFunc<V> = (value?: V) => boolean;
|
|
62
|
+
|
|
63
|
+
export declare interface PromiseType {
|
|
64
|
+
then: () => unknown;
|
|
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 { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/promise",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.1",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"promise",
|
|
@@ -28,21 +28,21 @@
|
|
|
28
28
|
"type": "module",
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
|
-
"types": "./dist/
|
|
31
|
+
"types": "./dist/neutral/index.d.ts",
|
|
32
32
|
"default": "./dist/neutral/index.mjs"
|
|
33
33
|
},
|
|
34
34
|
"./package.json": "./package.json"
|
|
35
35
|
},
|
|
36
36
|
"module": "./dist/neutral/index.mjs",
|
|
37
|
-
"types": "./dist/
|
|
37
|
+
"types": "./dist/neutral/index.d.ts",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@xylabs/typeof": "^4.
|
|
39
|
+
"@xylabs/typeof": "^4.13.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@xylabs/ts-scripts-yarn3": "^
|
|
43
|
-
"@xylabs/tsconfig": "^
|
|
44
|
-
"@xylabs/typeof": "^4.
|
|
45
|
-
"@xylabs/vitest-extended": "^4.
|
|
42
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.0-rc.7",
|
|
43
|
+
"@xylabs/tsconfig": "^7.0.0-rc.7",
|
|
44
|
+
"@xylabs/typeof": "^4.13.1",
|
|
45
|
+
"@xylabs/vitest-extended": "^4.13.1",
|
|
46
46
|
"typescript": "^5.8.3",
|
|
47
47
|
"vitest": "^3.2.4"
|
|
48
48
|
},
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type PromiseExSubFunc<T, TResult = T> = (value: T) => TResult;
|
|
2
|
-
export type PromiseExFunc<T> = (resolve?: PromiseExSubFunc<T, void>, reject?: PromiseExSubFunc<T, void>) => void;
|
|
3
|
-
export type PromiseExValueFunc<V> = (value?: V) => boolean;
|
|
4
|
-
export declare class PromiseEx<T, V = void> extends Promise<T> {
|
|
5
|
-
cancelled?: boolean;
|
|
6
|
-
private _value?;
|
|
7
|
-
constructor(func: PromiseExFunc<T>, value?: V);
|
|
8
|
-
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>;
|
|
9
|
-
value(onvalue?: (value?: V) => boolean): this;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=PromiseEx.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,CA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CAAC,EAAE,KAAK,oBAAoB,CAAC,CAAC,CAAC,KAAG,GAAG,IAAI,sBAAsB,CAAC,CAAC,CAE1F,CAAA"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For use with Promise.allSettled to reduce to only successful result values
|
|
3
|
-
* @example <caption>Casting the initialValue provided to reduce</caption>
|
|
4
|
-
* const resolved = Promise.resolve('resolved')
|
|
5
|
-
* const rejected = Promise.reject('rejected')
|
|
6
|
-
* const settled = await Promise.allSettled([resolved, rejected])
|
|
7
|
-
* const results = settled.reduce(fulfilledValues, [] as string[])
|
|
8
|
-
* // results === [ 'resolved' ]
|
|
9
|
-
* @example <caption>Providing type parameter to reduce and initialValue type can be inferred</caption>
|
|
10
|
-
* const resolved = Promise.resolve('resolved')
|
|
11
|
-
* const rejected = Promise.reject('rejected')
|
|
12
|
-
* const settled = await Promise.allSettled([resolved, rejected])
|
|
13
|
-
* const results = settled.reduce<string[]>(fulfilledValues, [])
|
|
14
|
-
* // results === [ 'resolved' ]
|
|
15
|
-
* @param previousValue
|
|
16
|
-
* @param currentValue
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
export declare const fulfilledValues: <T>(previousValue: T[], currentValue: PromiseSettledResult<T>) => T[];
|
|
20
|
-
//# sourceMappingURL=fulfilledValues.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fulfilledValues.d.ts","sourceRoot":"","sources":["../../src/fulfilledValues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAAE,eAAe,CAAC,EAAE,EAAE,cAAc,oBAAoB,CAAC,CAAC,CAAC,KAAG,CAAC,EAG/F,CAAA"}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { fulfilled } from './fulfilled.ts';
|
|
2
|
-
export { fulfilledValues } from './fulfilledValues.ts';
|
|
3
|
-
export * from './isPromise.ts';
|
|
4
|
-
export * from './PromiseEx.ts';
|
|
5
|
-
export { rejected } from './rejected.ts';
|
|
6
|
-
export * from './toPromise.ts';
|
|
7
|
-
export * from './types.ts';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { TypedValue } from '@xylabs/typeof';
|
|
2
|
-
export interface PromiseType {
|
|
3
|
-
then: () => unknown;
|
|
4
|
-
}
|
|
5
|
-
export type AnyNonPromise = Exclude<TypedValue, PromiseType>;
|
|
6
|
-
export declare const isPromise: (value: unknown) => value is Promise<unknown>;
|
|
7
|
-
//# sourceMappingURL=isPromise.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isPromise.d.ts","sourceRoot":"","sources":["../../src/isPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OAAO,CAAC,OAAO,CAKlE,CAAA"}
|
package/dist/types/rejected.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rejected.d.ts","sourceRoot":"","sources":["../../src/rejected.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,KAAK,oBAAoB,CAAC,CAAC,CAAC,KAAG,GAAG,IAAI,qBAEjE,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/types/types.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { PromiseEx } from './PromiseEx.ts';
|
|
2
|
-
export type Promisable<T, V = never> = PromiseEx<T, V> | Promise<T> | T;
|
|
3
|
-
export type PromisableArray<T, V = never> = Promisable<T[], V>;
|
|
4
|
-
export type OptionalPromisable<T, V = never> = Promisable<T | undefined, V>;
|
|
5
|
-
export type OptionalPromisableArray<T, V = never> = PromisableArray<T | undefined, V>;
|
|
6
|
-
export type NullablePromisable<T, V = never> = Promisable<T | null, V>;
|
|
7
|
-
export type NullablePromisableArray<T, V = never> = PromisableArray<T | null, V>;
|
|
8
|
-
/** @description Used to document promises that are being used as Mutexes */
|
|
9
|
-
export type AsyncMutex<T> = Promise<T>;
|
|
10
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,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;AACvE,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAC9D,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAA;AAC3E,MAAM,MAAM,uBAAuB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,eAAe,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC,CAAA;AACrF,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;AACtE,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"}
|