@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.
@@ -1,76 +1,66 @@
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 { }
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.4",
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.4"
39
+ "@xylabs/typeof": "^4.13.5"
40
40
  },
41
41
  "devDependencies": {
42
- "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.7",
43
- "@xylabs/tsconfig": "^7.0.0-rc.7",
44
- "@xylabs/typeof": "^4.13.4",
45
- "@xylabs/vitest-extended": "^4.13.4",
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
  },