@xylabs/promise 4.13.21 → 4.13.22

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 CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  Base functionality used throughout XY Labs TypeScript/JavaScript libraries
17
17
 
18
- ## API Documentation
18
+ ## Reference
19
19
 
20
20
  **@xylabs/promise**
21
21
 
@@ -1,8 +1,66 @@
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
+ 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.21",
3
+ "version": "4.13.22",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "promise",
@@ -41,11 +41,13 @@
41
41
  "dist",
42
42
  "src"
43
43
  ],
44
+ "dependencies": {
45
+ "@xylabs/typeof": "^4.13.22"
46
+ },
44
47
  "devDependencies": {
45
48
  "@xylabs/ts-scripts-yarn3": "^7.0.0",
46
49
  "@xylabs/tsconfig": "^7.0.0",
47
- "@xylabs/typeof": "^4.13.21",
48
- "@xylabs/vitest-extended": "^4.13.21",
50
+ "@xylabs/vitest-extended": "^4.13.22",
49
51
  "typescript": "^5.8.3",
50
52
  "vitest": "^3.2.4"
51
53
  },