@sorrell/utilities 1.1.61 → 1.2.0
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/Distribution/PackageExports.Generated.json +122 -0
- package/Distribution/Types/Array/Array.Internal.Types.d.cts +43 -0
- package/Distribution/Types/Array/Array.Internal.Types.d.cts.map +10 -0
- package/Distribution/Types/Array/Array.Internal.Types.d.mts +43 -0
- package/Distribution/Types/Array/Array.Internal.Types.d.mts.map +10 -0
- package/Distribution/Types/Array/Array.Internal.d.cts +16 -0
- package/Distribution/Types/Array/Array.Internal.d.cts.map +10 -0
- package/Distribution/Types/Array/Array.Internal.d.mts +16 -0
- package/Distribution/Types/Array/Array.Internal.d.mts.map +10 -0
- package/Distribution/Types/Array/Array.Types.d.cts +92 -0
- package/Distribution/Types/Array/Array.Types.d.cts.map +10 -0
- package/Distribution/Types/Array/Array.Types.d.mts +92 -0
- package/Distribution/Types/Array/Array.Types.d.mts.map +10 -0
- package/Distribution/Types/Array/Array.d.cts +33 -0
- package/Distribution/Types/Array/Array.d.cts.map +10 -0
- package/Distribution/Types/Array/Array.d.mts +33 -0
- package/Distribution/Types/Array/Array.d.mts.map +10 -0
- package/Distribution/Types/Array/index.d.cts +9 -0
- package/Distribution/Types/Array/index.d.cts.map +10 -0
- package/Distribution/Types/Array/index.d.mts +9 -0
- package/Distribution/Types/Array/index.d.mts.map +10 -0
- package/Distribution/Types/Async/Async.Types.d.cts +150 -0
- package/Distribution/Types/Async/Async.Types.d.cts.map +10 -0
- package/Distribution/Types/Async/Async.Types.d.mts +150 -0
- package/Distribution/Types/Async/Async.Types.d.mts.map +10 -0
- package/Distribution/Types/Async/Async.d.cts +145 -0
- package/Distribution/Types/Async/Async.d.cts.map +10 -0
- package/Distribution/Types/Async/Async.d.mts +145 -0
- package/Distribution/Types/Async/Async.d.mts.map +10 -0
- package/Distribution/Types/Async/index.d.cts +9 -0
- package/Distribution/Types/Async/index.d.cts.map +10 -0
- package/Distribution/Types/Async/index.d.mts +9 -0
- package/Distribution/Types/Async/index.d.mts.map +10 -0
- package/Distribution/Types/Effect/Effect.Types.d.cts +16 -0
- package/Distribution/Types/Effect/Effect.Types.d.cts.map +10 -0
- package/Distribution/Types/Effect/Effect.Types.d.mts +16 -0
- package/Distribution/Types/Effect/Effect.Types.d.mts.map +10 -0
- package/Distribution/Types/Effect/Effect.d.cts +8 -0
- package/Distribution/Types/Effect/Effect.d.cts.map +10 -0
- package/Distribution/Types/Effect/Effect.d.mts +8 -0
- package/Distribution/Types/Effect/Effect.d.mts.map +10 -0
- package/Distribution/Types/Effect/Index.Effect.d.cts +10 -0
- package/Distribution/Types/Effect/Index.Effect.d.cts.map +10 -0
- package/Distribution/Types/Effect/Index.Effect.d.mts +10 -0
- package/Distribution/Types/Effect/Index.Effect.d.mts.map +10 -0
- package/Distribution/Types/Effect/index.d.cts +8 -0
- package/Distribution/Types/Effect/index.d.cts.map +10 -0
- package/Distribution/Types/Effect/index.d.mts +8 -0
- package/Distribution/Types/Effect/index.d.mts.map +10 -0
- package/Distribution/Types/FileSystem/FileSystem.Types.d.cts +8 -0
- package/Distribution/Types/FileSystem/FileSystem.Types.d.cts.map +10 -0
- package/Distribution/Types/FileSystem/FileSystem.Types.d.mts +8 -0
- package/Distribution/Types/FileSystem/FileSystem.Types.d.mts.map +10 -0
- package/Distribution/Types/FileSystem/FileSystem.d.cts +55 -0
- package/Distribution/Types/FileSystem/FileSystem.d.cts.map +10 -0
- package/Distribution/Types/FileSystem/FileSystem.d.mts +55 -0
- package/Distribution/Types/FileSystem/FileSystem.d.mts.map +10 -0
- package/Distribution/Types/FileSystem/index.d.cts +9 -0
- package/Distribution/Types/FileSystem/index.d.cts.map +10 -0
- package/Distribution/Types/FileSystem/index.d.mts +9 -0
- package/Distribution/Types/FileSystem/index.d.mts.map +10 -0
- package/Distribution/Types/Functional/Functional.Internal.Types.d.cts +9 -0
- package/Distribution/Types/Functional/Functional.Internal.Types.d.cts.map +10 -0
- package/Distribution/Types/Functional/Functional.Internal.Types.d.mts +9 -0
- package/Distribution/Types/Functional/Functional.Internal.Types.d.mts.map +10 -0
- package/Distribution/Types/Functional/Functional.Internal.d.cts +8 -0
- package/Distribution/Types/Functional/Functional.Internal.d.cts.map +10 -0
- package/Distribution/Types/Functional/Functional.Internal.d.mts +8 -0
- package/Distribution/Types/Functional/Functional.Internal.d.mts.map +10 -0
- package/Distribution/Types/Functional/Functional.Types.d.cts +28 -0
- package/Distribution/Types/Functional/Functional.Types.d.cts.map +10 -0
- package/Distribution/Types/Functional/Functional.Types.d.mts +28 -0
- package/Distribution/Types/Functional/Functional.Types.d.mts.map +10 -0
- package/Distribution/Types/Functional/Functional.d.cts +8 -0
- package/Distribution/Types/Functional/Functional.d.cts.map +10 -0
- package/Distribution/Types/Functional/Functional.d.mts +8 -0
- package/Distribution/Types/Functional/Functional.d.mts.map +10 -0
- package/Distribution/Types/Functional/index.d.cts +9 -0
- package/Distribution/Types/Functional/index.d.cts.map +10 -0
- package/Distribution/Types/Functional/index.d.mts +9 -0
- package/Distribution/Types/Functional/index.d.mts.map +10 -0
- package/Distribution/Types/Math/Complex.Internal.d.cts +8 -0
- package/Distribution/Types/Math/Complex.Internal.d.cts.map +10 -0
- package/Distribution/Types/Math/Complex.Internal.d.mts +8 -0
- package/Distribution/Types/Math/Complex.Internal.d.mts.map +10 -0
- package/Distribution/Types/Math/Complex.Types.d.cts +69 -0
- package/Distribution/Types/Math/Complex.Types.d.cts.map +10 -0
- package/Distribution/Types/Math/Complex.Types.d.mts +69 -0
- package/Distribution/Types/Math/Complex.Types.d.mts.map +10 -0
- package/Distribution/Types/Math/Complex.d.cts +63 -0
- package/Distribution/Types/Math/Complex.d.cts.map +10 -0
- package/Distribution/Types/Math/Complex.d.mts +63 -0
- package/Distribution/Types/Math/Complex.d.mts.map +10 -0
- package/Distribution/Types/Math/Index.Complex.d.cts +9 -0
- package/Distribution/Types/Math/Index.Complex.d.cts.map +10 -0
- package/Distribution/Types/Math/Index.Complex.d.mts +9 -0
- package/Distribution/Types/Math/Index.Complex.d.mts.map +10 -0
- package/Distribution/Types/Math/Index.Experimental.d.cts +10 -0
- package/Distribution/Types/Math/Index.Experimental.d.cts.map +10 -0
- package/Distribution/Types/Math/Index.Experimental.d.mts +10 -0
- package/Distribution/Types/Math/Index.Experimental.d.mts.map +10 -0
- package/Distribution/Types/Math/Math.Internal.Types.d.cts +41 -0
- package/Distribution/Types/Math/Math.Internal.Types.d.cts.map +10 -0
- package/Distribution/Types/Math/Math.Internal.Types.d.mts +41 -0
- package/Distribution/Types/Math/Math.Internal.Types.d.mts.map +10 -0
- package/Distribution/Types/Math/Math.Types.d.cts +90 -0
- package/Distribution/Types/Math/Math.Types.d.cts.map +10 -0
- package/Distribution/Types/Math/Math.Types.d.mts +90 -0
- package/Distribution/Types/Math/Math.Types.d.mts.map +10 -0
- package/Distribution/Types/Math/Math.d.cts +8 -0
- package/Distribution/Types/Math/Math.d.cts.map +10 -0
- package/Distribution/Types/Math/Math.d.mts +8 -0
- package/Distribution/Types/Math/Math.d.mts.map +10 -0
- package/Distribution/Types/Math/Vector.d.cts +102 -0
- package/Distribution/Types/Math/Vector.d.cts.map +10 -0
- package/Distribution/Types/Math/Vector.d.mts +102 -0
- package/Distribution/Types/Math/Vector.d.mts.map +10 -0
- package/Distribution/Types/Math/index.d.cts +15 -0
- package/Distribution/Types/Math/index.d.cts.map +10 -0
- package/Distribution/Types/Math/index.d.mts +15 -0
- package/Distribution/Types/Math/index.d.mts.map +10 -0
- package/Distribution/Types/Miscellaneous/Utility.Internal.d.cts +8 -0
- package/Distribution/Types/Miscellaneous/Utility.Internal.d.cts.map +10 -0
- package/Distribution/Types/Miscellaneous/Utility.Internal.d.mts +8 -0
- package/Distribution/Types/Miscellaneous/Utility.Internal.d.mts.map +10 -0
- package/Distribution/Types/Miscellaneous/Utility.Types.d.cts +100 -0
- package/Distribution/Types/Miscellaneous/Utility.Types.d.cts.map +10 -0
- package/Distribution/Types/Miscellaneous/Utility.Types.d.mts +100 -0
- package/Distribution/Types/Miscellaneous/Utility.Types.d.mts.map +10 -0
- package/Distribution/Types/Miscellaneous/index.d.cts +8 -0
- package/Distribution/Types/Miscellaneous/index.d.cts.map +10 -0
- package/Distribution/Types/Miscellaneous/index.d.mts +8 -0
- package/Distribution/Types/Miscellaneous/index.d.mts.map +10 -0
- package/Distribution/Types/Npm/Index.Effect.d.cts +9 -0
- package/Distribution/Types/Npm/Index.Effect.d.cts.map +10 -0
- package/Distribution/Types/Npm/Index.Effect.d.mts +9 -0
- package/Distribution/Types/Npm/Index.Effect.d.mts.map +10 -0
- package/Distribution/Types/Npm/Npm.Effect.Internal.d.cts +17 -0
- package/Distribution/Types/Npm/Npm.Effect.Internal.d.cts.map +10 -0
- package/Distribution/Types/Npm/Npm.Effect.Internal.d.mts +17 -0
- package/Distribution/Types/Npm/Npm.Effect.Internal.d.mts.map +10 -0
- package/Distribution/Types/Npm/Npm.Effect.Types.d.cts +12 -0
- package/Distribution/Types/Npm/Npm.Effect.Types.d.cts.map +10 -0
- package/Distribution/Types/Npm/Npm.Effect.Types.d.mts +12 -0
- package/Distribution/Types/Npm/Npm.Effect.Types.d.mts.map +10 -0
- package/Distribution/Types/Npm/Npm.Effect.d.cts +92 -0
- package/Distribution/Types/Npm/Npm.Effect.d.cts.map +10 -0
- package/Distribution/Types/Npm/Npm.Effect.d.mts +92 -0
- package/Distribution/Types/Npm/Npm.Effect.d.mts.map +10 -0
- package/Distribution/Types/Npm/Npm.Error.d.cts +36 -0
- package/Distribution/Types/Npm/Npm.Error.d.cts.map +10 -0
- package/Distribution/Types/Npm/Npm.Error.d.mts +36 -0
- package/Distribution/Types/Npm/Npm.Error.d.mts.map +10 -0
- package/Distribution/Types/Npm/Npm.d.cts +91 -0
- package/Distribution/Types/Npm/Npm.d.cts.map +10 -0
- package/Distribution/Types/Npm/Npm.d.mts +91 -0
- package/Distribution/Types/Npm/Npm.d.mts.map +10 -0
- package/Distribution/Types/Npm/index.d.cts +15 -0
- package/Distribution/Types/Npm/index.d.cts.map +10 -0
- package/Distribution/Types/Npm/index.d.mts +15 -0
- package/Distribution/Types/Npm/index.d.mts.map +10 -0
- package/Distribution/Types/Path/Path.d.cts +17 -0
- package/Distribution/Types/Path/Path.d.cts.map +10 -0
- package/Distribution/Types/Path/Path.d.mts +17 -0
- package/Distribution/Types/Path/Path.d.mts.map +10 -0
- package/Distribution/Types/Path/index.d.cts +8 -0
- package/Distribution/Types/Path/index.d.cts.map +10 -0
- package/Distribution/Types/Path/index.d.mts +8 -0
- package/Distribution/Types/Path/index.d.mts.map +10 -0
- package/Distribution/Types/String/String.d.cts +28 -0
- package/Distribution/Types/String/String.d.cts.map +10 -0
- package/Distribution/Types/String/String.d.mts +28 -0
- package/Distribution/Types/String/String.d.mts.map +10 -0
- package/Distribution/Types/String/index.d.cts +8 -0
- package/Distribution/Types/String/index.d.cts.map +10 -0
- package/Distribution/Types/String/index.d.mts +8 -0
- package/Distribution/Types/String/index.d.mts.map +10 -0
- package/Distribution/Types/index.d.cts +24 -0
- package/Distribution/Types/index.d.cts.map +10 -0
- package/Distribution/Types/index.d.mts +24 -0
- package/Distribution/Types/index.d.mts.map +10 -0
- package/Distribution/{CJS/array.js → array.cjs} +1 -1
- package/Distribution/{CJS/array.js.map → array.cjs.map} +1 -1
- package/Distribution/{ESM/array.js.map → array.js.map} +1 -1
- package/Distribution/{CJS/async.js → async.cjs} +1 -1
- package/Distribution/{CJS/async.js.map → async.cjs.map} +1 -1
- package/Distribution/{ESM/async.js.map → async.js.map} +1 -1
- package/Distribution/{CJS/complex.js → complex.cjs} +1 -1
- package/Distribution/{CJS/complex.js.map → complex.cjs.map} +1 -1
- package/Distribution/{ESM/complex.js.map → complex.js.map} +1 -1
- package/Distribution/{CJS/effect.js → effect.cjs} +1 -1
- package/Distribution/{CJS/effect.js.map → effect.cjs.map} +1 -1
- package/Distribution/{ESM/effect.js.map → effect.js.map} +1 -1
- package/Distribution/{CJS/fs.js → fs.cjs} +1 -1
- package/Distribution/{CJS/fs.js.map → fs.cjs.map} +1 -1
- package/Distribution/{ESM/fs.js.map → fs.js.map} +1 -1
- package/Distribution/{CJS/functional.js → functional.cjs} +1 -1
- package/Distribution/{CJS/functional.js.map → functional.cjs.map} +1 -1
- package/Distribution/{ESM/functional.js.map → functional.js.map} +1 -1
- package/Distribution/{CJS/index.js → index.cjs} +1 -1
- package/Distribution/{CJS/index.js.map → index.cjs.map} +1 -1
- package/Distribution/{ESM/index.js.map → index.js.map} +1 -1
- package/Distribution/{CJS/math.js → math.cjs} +1 -1
- package/Distribution/{CJS/math.js.map → math.cjs.map} +1 -1
- package/Distribution/{ESM/math.js.map → math.js.map} +1 -1
- package/Distribution/{CJS/misc.js → misc.cjs} +1 -1
- package/Distribution/{CJS/misc.js.map → misc.cjs.map} +1 -1
- package/Distribution/{ESM/misc.js.map → misc.js.map} +1 -1
- package/Distribution/{CJS/npm-effect.js → npm-effect.cjs} +1 -1
- package/Distribution/{CJS/npm-effect.js.map → npm-effect.cjs.map} +1 -1
- package/Distribution/{ESM/npm-effect.js.map → npm-effect.js.map} +1 -1
- package/Distribution/{CJS/npm.js → npm.cjs} +1 -1
- package/Distribution/{CJS/npm.js.map → npm.cjs.map} +1 -1
- package/Distribution/{ESM/npm.js.map → npm.js.map} +1 -1
- package/Distribution/{CJS/path.js → path.cjs} +1 -1
- package/Distribution/{CJS/path.js.map → path.cjs.map} +1 -1
- package/Distribution/{ESM/path.js.map → path.js.map} +1 -1
- package/package.json +100 -50
- /package/Distribution/{ESM/array.js → array.js} +0 -0
- /package/Distribution/{ESM/async.js → async.js} +0 -0
- /package/Distribution/{ESM/complex.js → complex.js} +0 -0
- /package/Distribution/{ESM/effect.js → effect.js} +0 -0
- /package/Distribution/{ESM/fs.js → fs.js} +0 -0
- /package/Distribution/{ESM/functional.js → functional.js} +0 -0
- /package/Distribution/{ESM/index.js → index.js} +0 -0
- /package/Distribution/{ESM/math.js → math.js} +0 -0
- /package/Distribution/{ESM/misc.js → misc.js} +0 -0
- /package/Distribution/{ESM/npm-effect.js → npm-effect.js} +0 -0
- /package/Distribution/{ESM/npm.js → npm.js} +0 -0
- /package/Distribution/{ESM/path.js → path.js} +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Promise.Types.ts
|
|
3
|
+
* @author Gage Sorrell <gage@sorrell.sh>
|
|
4
|
+
* @copyright (c) 2026 Gage Sorrell
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
import type { TExtractFunction, TFunction } from "../Functional/index.cjs";
|
|
8
|
+
import type { TPromise, TPromiseLike } from "./Async.cjs";
|
|
9
|
+
/**
|
|
10
|
+
* @template DataType - The {@link Data} type of this.
|
|
11
|
+
*
|
|
12
|
+
* @property {DataType | undefined} Data - The data returned by the corresponding
|
|
13
|
+
* `async` function or `Promise<DataType>`,
|
|
14
|
+
* iff it resolved successfully. Otherwise, it is `undefined`.
|
|
15
|
+
*
|
|
16
|
+
* @property {undefined | unknown} Error - The error thrown by the corresponding
|
|
17
|
+
* `async` function or `Promise<DataType>`. This is `undefined` iff the
|
|
18
|
+
* corresponding `async` function or `Promise<DataType>` resolved successfully.
|
|
19
|
+
*/
|
|
20
|
+
export type TTryResult<DataType> = {
|
|
21
|
+
Data: DataType;
|
|
22
|
+
Error: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
Data: undefined;
|
|
25
|
+
Error: unknown | undefined;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* An `async` function or `Promise` of the given {@link DataType}.
|
|
29
|
+
* This is the type of the argument of {@link Try}.
|
|
30
|
+
*
|
|
31
|
+
* @template DataType - The type of the data that the `async` function or `Promise<DataType>`.
|
|
32
|
+
*/
|
|
33
|
+
export type TTrySource<DataType> = Promise<DataType> | (() => DataType) | (() => Promise<DataType>);
|
|
34
|
+
/**
|
|
35
|
+
* The type of the function passed to the `then` method of a `Promise`.
|
|
36
|
+
*
|
|
37
|
+
* @template ParameterType - The type of the parameter passed to the function.
|
|
38
|
+
* @template ReturnType - The type of the value returned by the function.
|
|
39
|
+
*/
|
|
40
|
+
export type TThen<ParameterType = unknown, ReturnType = unknown> = (Value: ParameterType) => ReturnType;
|
|
41
|
+
/**
|
|
42
|
+
* The type of the function passed to the `catch` method of a `Promise`.
|
|
43
|
+
*
|
|
44
|
+
* @template Type - The type of the value returned by the `catch` function.
|
|
45
|
+
*/
|
|
46
|
+
export type TPromiseCatchFunction<Type = unknown> = Parameters<TExtractFunction<Promise<Type>["catch"]>>[0];
|
|
47
|
+
/**
|
|
48
|
+
* Maps a function type to union of two functions, each with the original
|
|
49
|
+
* argument vector type. One return type is wrapped with `Promise`, and
|
|
50
|
+
* the other is not. The nuance regarding the return type is elaborated
|
|
51
|
+
* upon in the note below.
|
|
52
|
+
*
|
|
53
|
+
* @note It is expected that in *most* cases, the given {@link FunctionType}
|
|
54
|
+
* is a regular, synchronous function type (*i.e.*, its return type is *not*
|
|
55
|
+
* a `Promise`), but if it *does* return a `Promise`, the default behavior
|
|
56
|
+
* is to assume that this is the intended async form of the resulting union,
|
|
57
|
+
* and the type wrapped in the `Promise` will be inferred. If the given
|
|
58
|
+
* {@link FunctionType} returns a `Promise` but is intended to be the *synchronous*
|
|
59
|
+
* form, then {@link RetainPromiseFlag} should be set to `true`.
|
|
60
|
+
*
|
|
61
|
+
* @template FunctionType - The function type from which this union is constructed.
|
|
62
|
+
* @template RetainPromiseFlag - If `true` and `ReturnType<{@link FunctionType}> extends
|
|
63
|
+
* Promise<unknown>`, then the {@link FunctionType} will be treated as the synchronous
|
|
64
|
+
* form, and the other type in this union will return a `Promise<Promise<infer ResolveType>>`.
|
|
65
|
+
*/
|
|
66
|
+
export type TMaybeAsync<FunctionType extends TFunction, RetainPromiseFlag extends boolean = false> = FunctionType extends TFunction<infer ArgumentVectorType, infer ReturnType> ? ReturnType extends Promise<infer ResolveType> ? RetainPromiseFlag extends true ? TFunction<ArgumentVectorType, ReturnType> : TFunction<ArgumentVectorType, ResolveType> : (TFunction<ArgumentVectorType, ReturnType> | TFunction<ArgumentVectorType, Promise<ReturnType>>) : never;
|
|
67
|
+
/**
|
|
68
|
+
* A function that is an argument of a given {@link PromiseConstructorLike}`, which is called when
|
|
69
|
+
* the {@link PromiseLike} created by the given {@link PromiseConstructorLike} resolves, if it resolves.
|
|
70
|
+
*
|
|
71
|
+
* @param Value - The value to which the given {@link PromiseLike} will resolve by calling this.
|
|
72
|
+
*
|
|
73
|
+
* @template ResolveType - The type to which the given {@link PromiseLike} will resolve by calling this.
|
|
74
|
+
*/
|
|
75
|
+
export type TResolve<ResolveType> = (Value: ResolveType | PromiseLike<ResolveType>) => void;
|
|
76
|
+
/**
|
|
77
|
+
* A function that is called by a given {@link PromiseLike}`, if the given {@link PromiseLike} resolves.
|
|
78
|
+
*
|
|
79
|
+
* @param Value - The value to which the given {@link PromiseLike} resolves when this is called,
|
|
80
|
+
* if it resolves (this is called precisely when the given {@link PromiseLike} resolves).
|
|
81
|
+
*
|
|
82
|
+
* @template ResolveType - The type to which the given {@link PromiseLike} provides once it has
|
|
83
|
+
* resolved, if it resolves.
|
|
84
|
+
*
|
|
85
|
+
* @template Result1Type - The type to which the resulting {@link PromiseLike} will resolve, if it resolves.
|
|
86
|
+
*/
|
|
87
|
+
export type TOnFulfilled<ResolveType, Result1Type = ResolveType> = {
|
|
88
|
+
(Value: ResolveType): Result1Type | PromiseLike<Result1Type>;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* A function that is called by a given {@link Promise}`, if the given {@link Promise} rejects.
|
|
92
|
+
*
|
|
93
|
+
* @param Reason - The reason for why given {@link Promise} rejects when this is called,
|
|
94
|
+
* if it rejects (this is called precisely when the given {@link Promise} rejects).
|
|
95
|
+
*
|
|
96
|
+
* @template RejectType - The type to which the given {@link Promise} provides once it has
|
|
97
|
+
* rejected, if it rejects.
|
|
98
|
+
*
|
|
99
|
+
* @returns {Result2Type | PromiseLike<Result2Type>} A {@link PromiseLike} that resolves when this function
|
|
100
|
+
* has finished handling the rejection of the {@link Promise} which received this function via
|
|
101
|
+
* {@link Promise["catch"]}.
|
|
102
|
+
*/
|
|
103
|
+
export type TOnRejected<RejectType> = {
|
|
104
|
+
(Reason: unknown): RejectType | PromiseLike<RejectType>;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* A function that is an argument of a given {@link PromiseConstructorLike}`, which is called when
|
|
108
|
+
* the {@link PromiseLike} created by the given {@link PromiseConstructorLike} rejects, if it rejects.
|
|
109
|
+
*
|
|
110
|
+
* @param Reason - The reason for why given {@link PromiseLike} will reject by calling this.
|
|
111
|
+
*
|
|
112
|
+
* @template RejectType - The type to which the given {@link PromiseLike} will by calling this.
|
|
113
|
+
*/
|
|
114
|
+
export type TReject<RejectType = unknown> = (Reason: RejectType) => void;
|
|
115
|
+
/**
|
|
116
|
+
* The argument of a {@link TPromise} (or other {@link PromiseLike}), such that a new
|
|
117
|
+
* {@link PromiseLike} is created by the given constructor using this argument.
|
|
118
|
+
*
|
|
119
|
+
* @param Resolve - The function that, if called, will cause the {@link PromiseLike}
|
|
120
|
+
* constructed with this to resolve.
|
|
121
|
+
*
|
|
122
|
+
* @param Reject - The function that, if called, will cause the {@link PromiseLike}
|
|
123
|
+
* constructed with this to resolve.
|
|
124
|
+
*
|
|
125
|
+
* @template ResolveType - The type to which the {@link PromiseLike} constructed with this will be resolved,
|
|
126
|
+
* if it resolves.
|
|
127
|
+
*
|
|
128
|
+
* @template RejectType - The type to which the {@link PromiseLike} constructed with this will be rejected,
|
|
129
|
+
* if it rejects.
|
|
130
|
+
*
|
|
131
|
+
* @returns {void} This does not return anything; control flow is handled entirely by calling either
|
|
132
|
+
* {@link Resolve} or {@link Reject}.
|
|
133
|
+
*/
|
|
134
|
+
export type TPromiseExecutor<ResolveType, RejectType = never> = {
|
|
135
|
+
(Resolve?: TResolve<ResolveType>, Reject?: TReject<RejectType>): void;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* The type of the argument used to construct a {@link TPromise}.
|
|
139
|
+
*
|
|
140
|
+
* @template ResolveType - The type to which the {@link TPromise} constructed with
|
|
141
|
+
* this argument will resolve, if it resolves.
|
|
142
|
+
*/
|
|
143
|
+
export type TPromiseCtorArgument<ResolveType> = TPromiseExecutor<ResolveType> | TPromise<ResolveType> | Promise<ResolveType>;
|
|
144
|
+
/**
|
|
145
|
+
* Either a given {@link ResultType}, or a {@link TPromiseLike} of a given {@link ResultType}.
|
|
146
|
+
*
|
|
147
|
+
* @template ResultType - The type which is either this, or of which this is a {@link PromiseLike}.
|
|
148
|
+
*/
|
|
149
|
+
export type TMaybePromiseLike<ResultType> = ResultType | TPromiseLike<ResultType>;
|
|
150
|
+
//# sourceMappingURL=Async.Types.d.cts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"file": "Async.Types.d.cts",
|
|
4
|
+
"sourceRoot": "",
|
|
5
|
+
"sources": [
|
|
6
|
+
"../../../Source/Async/Async.Types.ts"
|
|
7
|
+
],
|
|
8
|
+
"names": [],
|
|
9
|
+
"mappings": "AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,UAAU,CAAC,QAAQ,IACzB;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;CACpB,GACC;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B,CAAC;AAEN;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,QAAQ,IACzB,OAAO,CAAC,QAAQ,CAAC,GACjB,CAAC,MAAM,QAAQ,CAAC,GAChB,CAAC,MAAM,OAAO,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,EAAE,OAAO,GACV,UAAU,GACV,WAAW,CAAC,UAAU,CAAC,CAAC;CACjC,CAAC;AAEN;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,CAAC,UAAU,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;AAEzE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,CAAC,WAAW,EAAE,UAAU,GAAG,KAAK,IACxD;IACI,CACI,OAAO,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,EAC/B,MAAM,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAC7B,IAAI,CAAC;CACX,CAAC;AAEN;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,CAAC,WAAW,IACtC,gBAAgB,CAAC,WAAW,CAAC,GAC7B,QAAQ,CAAC,WAAW,CAAC,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC;AAE3B;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,UAAU,IAClC,UAAU,GACV,YAAY,CAAC,UAAU,CAAC,CAAC"
|
|
10
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Promise.Types.ts
|
|
3
|
+
* @author Gage Sorrell <gage@sorrell.sh>
|
|
4
|
+
* @copyright (c) 2026 Gage Sorrell
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
import type { TExtractFunction, TFunction } from "../Functional/index.mjs";
|
|
8
|
+
import type { TPromise, TPromiseLike } from "./Async.mjs";
|
|
9
|
+
/**
|
|
10
|
+
* @template DataType - The {@link Data} type of this.
|
|
11
|
+
*
|
|
12
|
+
* @property {DataType | undefined} Data - The data returned by the corresponding
|
|
13
|
+
* `async` function or `Promise<DataType>`,
|
|
14
|
+
* iff it resolved successfully. Otherwise, it is `undefined`.
|
|
15
|
+
*
|
|
16
|
+
* @property {undefined | unknown} Error - The error thrown by the corresponding
|
|
17
|
+
* `async` function or `Promise<DataType>`. This is `undefined` iff the
|
|
18
|
+
* corresponding `async` function or `Promise<DataType>` resolved successfully.
|
|
19
|
+
*/
|
|
20
|
+
export type TTryResult<DataType> = {
|
|
21
|
+
Data: DataType;
|
|
22
|
+
Error: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
Data: undefined;
|
|
25
|
+
Error: unknown | undefined;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* An `async` function or `Promise` of the given {@link DataType}.
|
|
29
|
+
* This is the type of the argument of {@link Try}.
|
|
30
|
+
*
|
|
31
|
+
* @template DataType - The type of the data that the `async` function or `Promise<DataType>`.
|
|
32
|
+
*/
|
|
33
|
+
export type TTrySource<DataType> = Promise<DataType> | (() => DataType) | (() => Promise<DataType>);
|
|
34
|
+
/**
|
|
35
|
+
* The type of the function passed to the `then` method of a `Promise`.
|
|
36
|
+
*
|
|
37
|
+
* @template ParameterType - The type of the parameter passed to the function.
|
|
38
|
+
* @template ReturnType - The type of the value returned by the function.
|
|
39
|
+
*/
|
|
40
|
+
export type TThen<ParameterType = unknown, ReturnType = unknown> = (Value: ParameterType) => ReturnType;
|
|
41
|
+
/**
|
|
42
|
+
* The type of the function passed to the `catch` method of a `Promise`.
|
|
43
|
+
*
|
|
44
|
+
* @template Type - The type of the value returned by the `catch` function.
|
|
45
|
+
*/
|
|
46
|
+
export type TPromiseCatchFunction<Type = unknown> = Parameters<TExtractFunction<Promise<Type>["catch"]>>[0];
|
|
47
|
+
/**
|
|
48
|
+
* Maps a function type to union of two functions, each with the original
|
|
49
|
+
* argument vector type. One return type is wrapped with `Promise`, and
|
|
50
|
+
* the other is not. The nuance regarding the return type is elaborated
|
|
51
|
+
* upon in the note below.
|
|
52
|
+
*
|
|
53
|
+
* @note It is expected that in *most* cases, the given {@link FunctionType}
|
|
54
|
+
* is a regular, synchronous function type (*i.e.*, its return type is *not*
|
|
55
|
+
* a `Promise`), but if it *does* return a `Promise`, the default behavior
|
|
56
|
+
* is to assume that this is the intended async form of the resulting union,
|
|
57
|
+
* and the type wrapped in the `Promise` will be inferred. If the given
|
|
58
|
+
* {@link FunctionType} returns a `Promise` but is intended to be the *synchronous*
|
|
59
|
+
* form, then {@link RetainPromiseFlag} should be set to `true`.
|
|
60
|
+
*
|
|
61
|
+
* @template FunctionType - The function type from which this union is constructed.
|
|
62
|
+
* @template RetainPromiseFlag - If `true` and `ReturnType<{@link FunctionType}> extends
|
|
63
|
+
* Promise<unknown>`, then the {@link FunctionType} will be treated as the synchronous
|
|
64
|
+
* form, and the other type in this union will return a `Promise<Promise<infer ResolveType>>`.
|
|
65
|
+
*/
|
|
66
|
+
export type TMaybeAsync<FunctionType extends TFunction, RetainPromiseFlag extends boolean = false> = FunctionType extends TFunction<infer ArgumentVectorType, infer ReturnType> ? ReturnType extends Promise<infer ResolveType> ? RetainPromiseFlag extends true ? TFunction<ArgumentVectorType, ReturnType> : TFunction<ArgumentVectorType, ResolveType> : (TFunction<ArgumentVectorType, ReturnType> | TFunction<ArgumentVectorType, Promise<ReturnType>>) : never;
|
|
67
|
+
/**
|
|
68
|
+
* A function that is an argument of a given {@link PromiseConstructorLike}`, which is called when
|
|
69
|
+
* the {@link PromiseLike} created by the given {@link PromiseConstructorLike} resolves, if it resolves.
|
|
70
|
+
*
|
|
71
|
+
* @param Value - The value to which the given {@link PromiseLike} will resolve by calling this.
|
|
72
|
+
*
|
|
73
|
+
* @template ResolveType - The type to which the given {@link PromiseLike} will resolve by calling this.
|
|
74
|
+
*/
|
|
75
|
+
export type TResolve<ResolveType> = (Value: ResolveType | PromiseLike<ResolveType>) => void;
|
|
76
|
+
/**
|
|
77
|
+
* A function that is called by a given {@link PromiseLike}`, if the given {@link PromiseLike} resolves.
|
|
78
|
+
*
|
|
79
|
+
* @param Value - The value to which the given {@link PromiseLike} resolves when this is called,
|
|
80
|
+
* if it resolves (this is called precisely when the given {@link PromiseLike} resolves).
|
|
81
|
+
*
|
|
82
|
+
* @template ResolveType - The type to which the given {@link PromiseLike} provides once it has
|
|
83
|
+
* resolved, if it resolves.
|
|
84
|
+
*
|
|
85
|
+
* @template Result1Type - The type to which the resulting {@link PromiseLike} will resolve, if it resolves.
|
|
86
|
+
*/
|
|
87
|
+
export type TOnFulfilled<ResolveType, Result1Type = ResolveType> = {
|
|
88
|
+
(Value: ResolveType): Result1Type | PromiseLike<Result1Type>;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* A function that is called by a given {@link Promise}`, if the given {@link Promise} rejects.
|
|
92
|
+
*
|
|
93
|
+
* @param Reason - The reason for why given {@link Promise} rejects when this is called,
|
|
94
|
+
* if it rejects (this is called precisely when the given {@link Promise} rejects).
|
|
95
|
+
*
|
|
96
|
+
* @template RejectType - The type to which the given {@link Promise} provides once it has
|
|
97
|
+
* rejected, if it rejects.
|
|
98
|
+
*
|
|
99
|
+
* @returns {Result2Type | PromiseLike<Result2Type>} A {@link PromiseLike} that resolves when this function
|
|
100
|
+
* has finished handling the rejection of the {@link Promise} which received this function via
|
|
101
|
+
* {@link Promise["catch"]}.
|
|
102
|
+
*/
|
|
103
|
+
export type TOnRejected<RejectType> = {
|
|
104
|
+
(Reason: unknown): RejectType | PromiseLike<RejectType>;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* A function that is an argument of a given {@link PromiseConstructorLike}`, which is called when
|
|
108
|
+
* the {@link PromiseLike} created by the given {@link PromiseConstructorLike} rejects, if it rejects.
|
|
109
|
+
*
|
|
110
|
+
* @param Reason - The reason for why given {@link PromiseLike} will reject by calling this.
|
|
111
|
+
*
|
|
112
|
+
* @template RejectType - The type to which the given {@link PromiseLike} will by calling this.
|
|
113
|
+
*/
|
|
114
|
+
export type TReject<RejectType = unknown> = (Reason: RejectType) => void;
|
|
115
|
+
/**
|
|
116
|
+
* The argument of a {@link TPromise} (or other {@link PromiseLike}), such that a new
|
|
117
|
+
* {@link PromiseLike} is created by the given constructor using this argument.
|
|
118
|
+
*
|
|
119
|
+
* @param Resolve - The function that, if called, will cause the {@link PromiseLike}
|
|
120
|
+
* constructed with this to resolve.
|
|
121
|
+
*
|
|
122
|
+
* @param Reject - The function that, if called, will cause the {@link PromiseLike}
|
|
123
|
+
* constructed with this to resolve.
|
|
124
|
+
*
|
|
125
|
+
* @template ResolveType - The type to which the {@link PromiseLike} constructed with this will be resolved,
|
|
126
|
+
* if it resolves.
|
|
127
|
+
*
|
|
128
|
+
* @template RejectType - The type to which the {@link PromiseLike} constructed with this will be rejected,
|
|
129
|
+
* if it rejects.
|
|
130
|
+
*
|
|
131
|
+
* @returns {void} This does not return anything; control flow is handled entirely by calling either
|
|
132
|
+
* {@link Resolve} or {@link Reject}.
|
|
133
|
+
*/
|
|
134
|
+
export type TPromiseExecutor<ResolveType, RejectType = never> = {
|
|
135
|
+
(Resolve?: TResolve<ResolveType>, Reject?: TReject<RejectType>): void;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* The type of the argument used to construct a {@link TPromise}.
|
|
139
|
+
*
|
|
140
|
+
* @template ResolveType - The type to which the {@link TPromise} constructed with
|
|
141
|
+
* this argument will resolve, if it resolves.
|
|
142
|
+
*/
|
|
143
|
+
export type TPromiseCtorArgument<ResolveType> = TPromiseExecutor<ResolveType> | TPromise<ResolveType> | Promise<ResolveType>;
|
|
144
|
+
/**
|
|
145
|
+
* Either a given {@link ResultType}, or a {@link TPromiseLike} of a given {@link ResultType}.
|
|
146
|
+
*
|
|
147
|
+
* @template ResultType - The type which is either this, or of which this is a {@link PromiseLike}.
|
|
148
|
+
*/
|
|
149
|
+
export type TMaybePromiseLike<ResultType> = ResultType | TPromiseLike<ResultType>;
|
|
150
|
+
//# sourceMappingURL=Async.Types.d.mts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"file": "Async.Types.d.mts",
|
|
4
|
+
"sourceRoot": "",
|
|
5
|
+
"sources": [
|
|
6
|
+
"../../../Source/Async/Async.Types.ts"
|
|
7
|
+
],
|
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|
10
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Async.ts
|
|
3
|
+
* @author Gage Sorrell <gage@sorrell.sh>
|
|
4
|
+
* @copyright (c) 2026 Gage Sorrell
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
import { type TNullable } from "../Miscellaneous/Utility.Types.cjs";
|
|
8
|
+
import type { TOnFulfilled, TOnRejected, TPromiseCtorArgument, TTryResult, TTrySource } from "./Async.Types.cjs";
|
|
9
|
+
import type { TFunction } from "../Functional/Functional.Types.cjs";
|
|
10
|
+
/**
|
|
11
|
+
* Implements "Errors-as-values" for `async` functions and `Promise<DataType>`s.
|
|
12
|
+
*
|
|
13
|
+
* If the `async` function or `Promise<DataType>` returns/resolves, then the `Error`
|
|
14
|
+
* property of the returned object will be `undefined`, and the result of the
|
|
15
|
+
* `async` function or `Promise<DataType>` will reside in the `Data` property of the
|
|
16
|
+
* returned object.
|
|
17
|
+
*
|
|
18
|
+
* Similarly, if the `async` function or `Promise<DataType>` throws, then the `Data`
|
|
19
|
+
* property of the returned object is `undefined`, and the `Error` property is what
|
|
20
|
+
* was thrown to the `catch` block.
|
|
21
|
+
*
|
|
22
|
+
* @template DataType - The type of the data that the `async` function or `Promise<DataType>`.
|
|
23
|
+
* @param Source - The `async` function or `Promise` to evaluate.
|
|
24
|
+
*
|
|
25
|
+
* @returns {TTryResult<DataType>} A {@link TTryResult} containing either the result
|
|
26
|
+
* ({@link TTryResult.Data}) or error {@link TTryResult.Error}.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // With an `async` function,
|
|
30
|
+
* async function GetName(): Promise<string> { ... }
|
|
31
|
+
* // Or, with a `Promise`,
|
|
32
|
+
* const GetName: Promise<string> = new Promise<string>(...);
|
|
33
|
+
*
|
|
34
|
+
* // For both of the above cases, `Try` behaves the same:
|
|
35
|
+
* const { Data: Name, Error: NameError } = await Try(GetName);
|
|
36
|
+
* // If `GetName` returned,
|
|
37
|
+
* // `typeof Name` <- `"string"`
|
|
38
|
+
* // `typeof NameError` <- `"undefined"`
|
|
39
|
+
* // If `GetName` threw,
|
|
40
|
+
* // `typeof Name` <- `"undefined"`
|
|
41
|
+
* // `NameError !== undefined` <- `true` (Unless `GetName` threw `undefined`).
|
|
42
|
+
*/
|
|
43
|
+
export declare function Try<DataType>(Source: TTrySource<DataType>): Promise<TTryResult<DataType>>;
|
|
44
|
+
/**
|
|
45
|
+
* A cleaner way of using `Array.prototype.map` with an `async` function.
|
|
46
|
+
*
|
|
47
|
+
* @template ArgumentElementType - The type of the given {@link Elements}.
|
|
48
|
+
* @template ReturnElementType - The type of the `Array` returned by this.
|
|
49
|
+
*
|
|
50
|
+
* @param Elements - The `Array` that will be transformed.
|
|
51
|
+
* @param Mapper - The function that maps each {@link ArgumentElementType}
|
|
52
|
+
* to a {@link ReturnElementType}.
|
|
53
|
+
*
|
|
54
|
+
* @returns {Array<ReturnElementType>} An `Array` of {@link ReturnElementType}.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* In an `async` function,
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const ArgumentElements: Array<ArgumentElementType> = [ ... ];
|
|
60
|
+
* const ToReturnElement = async (Element: ArgumentElementType): Promise<ReturnElementType> => ...;
|
|
61
|
+
* const ReturnElements: Array<ReturnElementType> = await Map(ArgumentElements, ToReturnElement);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function Map<ArgumentElementType, ReturnElementType>(Elements: Array<ArgumentElementType>, Mapper: ((Element: ArgumentElementType) => Promise<ReturnElementType>)): Promise<Array<ReturnElementType>>;
|
|
65
|
+
/**
|
|
66
|
+
* An abstract implementation of {@link PromiseLike}. This exists only to maintain the
|
|
67
|
+
* project's naming convention.
|
|
68
|
+
*/
|
|
69
|
+
export declare abstract class TPromiseLike<ResolveType> implements PromiseLike<ResolveType> {
|
|
70
|
+
then<ResultType = ResolveType, RejectType = never>(_OnFulfilled?: TOnFulfilled<ResolveType, ResultType>, _OnRejected?: TOnRejected<RejectType>): TPromiseLike<ResultType | RejectType>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The {@link TypeError} that is thrown by the constructor of {@link TPromise}
|
|
74
|
+
* iff it receives an argument that is not a {@link TPromiseCtorArgument}.
|
|
75
|
+
* It does not provide any additional information (in particular, it does not
|
|
76
|
+
* add any properties, and it does not set any properties inherited from
|
|
77
|
+
* {@link TypeError}).
|
|
78
|
+
*
|
|
79
|
+
* @note While the argument type of {@link TPromise}'s constructor is checked at runtime,
|
|
80
|
+
* the type checker should prevent the error described by this from happening.
|
|
81
|
+
*/
|
|
82
|
+
export declare class FPromiseInstantiationError extends TypeError {
|
|
83
|
+
constructor();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A `then`-able wrapper of {@link Promise}.
|
|
87
|
+
*
|
|
88
|
+
* @template ResolveType - The type to which this resolves, if it does resolve.
|
|
89
|
+
*/
|
|
90
|
+
export declare class TPromise<ResolveType> extends TPromiseLike<ResolveType> implements PromiseLike<ResolveType> {
|
|
91
|
+
constructor(Argument: TPromiseCtorArgument<ResolveType>);
|
|
92
|
+
private readonly Underlying;
|
|
93
|
+
/**
|
|
94
|
+
* This class's extension of {@link Promise!then}.
|
|
95
|
+
*
|
|
96
|
+
* @template ResultType - The type to which the value underlying the {@link TPromise} returned by this
|
|
97
|
+
* will resolve, if the {@link TPromise} resolves.
|
|
98
|
+
*
|
|
99
|
+
* @template RejectType - The type to which the value underlying the {@link TPromise} returned by this
|
|
100
|
+
* will reject, if the {@link TPromise} rejects.
|
|
101
|
+
*
|
|
102
|
+
* @param OnFulfilled - The callback that is called when the underlying {@link Promise} resolves,
|
|
103
|
+
* if it resolves.
|
|
104
|
+
*
|
|
105
|
+
* @param OnRejected - The callback that is called when the underlying {@link Promise} rejects,
|
|
106
|
+
* if it rejects.
|
|
107
|
+
*
|
|
108
|
+
* @returns {TPromise<ResultType | RejectType>} A new {@link TPromise} of the result of the
|
|
109
|
+
* given callbacks.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const Example: TPromise<string> = new TPromise<string>((Resolve, Reject) =>
|
|
114
|
+
* {
|
|
115
|
+
* if (Math.random() < 0.5)
|
|
116
|
+
* {
|
|
117
|
+
* Resolve("Success");
|
|
118
|
+
* }
|
|
119
|
+
* else
|
|
120
|
+
* {
|
|
121
|
+
* Reject("Error");
|
|
122
|
+
* }
|
|
123
|
+
* });
|
|
124
|
+
*
|
|
125
|
+
* Example.then(
|
|
126
|
+
* (Value: string): void =>
|
|
127
|
+
* {
|
|
128
|
+
* // `Value` <- `"Success"`
|
|
129
|
+
* },
|
|
130
|
+
* (Reason: unknown): void =>
|
|
131
|
+
* {
|
|
132
|
+
* // `Reason` <- `"Error"`
|
|
133
|
+
* }
|
|
134
|
+
* );
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
Then<ResultType = ResolveType, RejectType = never>(OnFulfilled: TOnFulfilled<ResolveType, ResultType>, OnRejected?: TOnRejected<RejectType>): TPromise<ResultType | RejectType>;
|
|
138
|
+
then<ResultType = ResolveType, RejectType = never>(OnFulfilled?: TOnFulfilled<ResolveType, ResultType>, OnRejected?: TOnRejected<RejectType>): TPromise<ResultType | RejectType>;
|
|
139
|
+
Catch<ResultType = never>(OnRejected?: TNullable<TOnRejected<ResolveType>>): TPromiseLike<ResolveType | ResultType>;
|
|
140
|
+
Finally(OnFinally?: TNullable<TFunction>): TPromise<ResolveType>;
|
|
141
|
+
static Resolve<ResolveType>(Value: ResolveType | PromiseLike<ResolveType>): TPromise<Awaited<ResolveType>>;
|
|
142
|
+
static Reject<ResolveType = unknown>(Reason?: unknown): TPromise<ResolveType>;
|
|
143
|
+
Raw(): Promise<ResolveType>;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=Async.d.cts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
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@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Async.ts
|
|
3
|
+
* @author Gage Sorrell <gage@sorrell.sh>
|
|
4
|
+
* @copyright (c) 2026 Gage Sorrell
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
import { type TNullable } from "../Miscellaneous/Utility.Types.mjs";
|
|
8
|
+
import type { TOnFulfilled, TOnRejected, TPromiseCtorArgument, TTryResult, TTrySource } from "./Async.Types.mjs";
|
|
9
|
+
import type { TFunction } from "../Functional/Functional.Types.mjs";
|
|
10
|
+
/**
|
|
11
|
+
* Implements "Errors-as-values" for `async` functions and `Promise<DataType>`s.
|
|
12
|
+
*
|
|
13
|
+
* If the `async` function or `Promise<DataType>` returns/resolves, then the `Error`
|
|
14
|
+
* property of the returned object will be `undefined`, and the result of the
|
|
15
|
+
* `async` function or `Promise<DataType>` will reside in the `Data` property of the
|
|
16
|
+
* returned object.
|
|
17
|
+
*
|
|
18
|
+
* Similarly, if the `async` function or `Promise<DataType>` throws, then the `Data`
|
|
19
|
+
* property of the returned object is `undefined`, and the `Error` property is what
|
|
20
|
+
* was thrown to the `catch` block.
|
|
21
|
+
*
|
|
22
|
+
* @template DataType - The type of the data that the `async` function or `Promise<DataType>`.
|
|
23
|
+
* @param Source - The `async` function or `Promise` to evaluate.
|
|
24
|
+
*
|
|
25
|
+
* @returns {TTryResult<DataType>} A {@link TTryResult} containing either the result
|
|
26
|
+
* ({@link TTryResult.Data}) or error {@link TTryResult.Error}.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // With an `async` function,
|
|
30
|
+
* async function GetName(): Promise<string> { ... }
|
|
31
|
+
* // Or, with a `Promise`,
|
|
32
|
+
* const GetName: Promise<string> = new Promise<string>(...);
|
|
33
|
+
*
|
|
34
|
+
* // For both of the above cases, `Try` behaves the same:
|
|
35
|
+
* const { Data: Name, Error: NameError } = await Try(GetName);
|
|
36
|
+
* // If `GetName` returned,
|
|
37
|
+
* // `typeof Name` <- `"string"`
|
|
38
|
+
* // `typeof NameError` <- `"undefined"`
|
|
39
|
+
* // If `GetName` threw,
|
|
40
|
+
* // `typeof Name` <- `"undefined"`
|
|
41
|
+
* // `NameError !== undefined` <- `true` (Unless `GetName` threw `undefined`).
|
|
42
|
+
*/
|
|
43
|
+
export declare function Try<DataType>(Source: TTrySource<DataType>): Promise<TTryResult<DataType>>;
|
|
44
|
+
/**
|
|
45
|
+
* A cleaner way of using `Array.prototype.map` with an `async` function.
|
|
46
|
+
*
|
|
47
|
+
* @template ArgumentElementType - The type of the given {@link Elements}.
|
|
48
|
+
* @template ReturnElementType - The type of the `Array` returned by this.
|
|
49
|
+
*
|
|
50
|
+
* @param Elements - The `Array` that will be transformed.
|
|
51
|
+
* @param Mapper - The function that maps each {@link ArgumentElementType}
|
|
52
|
+
* to a {@link ReturnElementType}.
|
|
53
|
+
*
|
|
54
|
+
* @returns {Array<ReturnElementType>} An `Array` of {@link ReturnElementType}.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* In an `async` function,
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const ArgumentElements: Array<ArgumentElementType> = [ ... ];
|
|
60
|
+
* const ToReturnElement = async (Element: ArgumentElementType): Promise<ReturnElementType> => ...;
|
|
61
|
+
* const ReturnElements: Array<ReturnElementType> = await Map(ArgumentElements, ToReturnElement);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function Map<ArgumentElementType, ReturnElementType>(Elements: Array<ArgumentElementType>, Mapper: ((Element: ArgumentElementType) => Promise<ReturnElementType>)): Promise<Array<ReturnElementType>>;
|
|
65
|
+
/**
|
|
66
|
+
* An abstract implementation of {@link PromiseLike}. This exists only to maintain the
|
|
67
|
+
* project's naming convention.
|
|
68
|
+
*/
|
|
69
|
+
export declare abstract class TPromiseLike<ResolveType> implements PromiseLike<ResolveType> {
|
|
70
|
+
then<ResultType = ResolveType, RejectType = never>(_OnFulfilled?: TOnFulfilled<ResolveType, ResultType>, _OnRejected?: TOnRejected<RejectType>): TPromiseLike<ResultType | RejectType>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The {@link TypeError} that is thrown by the constructor of {@link TPromise}
|
|
74
|
+
* iff it receives an argument that is not a {@link TPromiseCtorArgument}.
|
|
75
|
+
* It does not provide any additional information (in particular, it does not
|
|
76
|
+
* add any properties, and it does not set any properties inherited from
|
|
77
|
+
* {@link TypeError}).
|
|
78
|
+
*
|
|
79
|
+
* @note While the argument type of {@link TPromise}'s constructor is checked at runtime,
|
|
80
|
+
* the type checker should prevent the error described by this from happening.
|
|
81
|
+
*/
|
|
82
|
+
export declare class FPromiseInstantiationError extends TypeError {
|
|
83
|
+
constructor();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A `then`-able wrapper of {@link Promise}.
|
|
87
|
+
*
|
|
88
|
+
* @template ResolveType - The type to which this resolves, if it does resolve.
|
|
89
|
+
*/
|
|
90
|
+
export declare class TPromise<ResolveType> extends TPromiseLike<ResolveType> implements PromiseLike<ResolveType> {
|
|
91
|
+
constructor(Argument: TPromiseCtorArgument<ResolveType>);
|
|
92
|
+
private readonly Underlying;
|
|
93
|
+
/**
|
|
94
|
+
* This class's extension of {@link Promise!then}.
|
|
95
|
+
*
|
|
96
|
+
* @template ResultType - The type to which the value underlying the {@link TPromise} returned by this
|
|
97
|
+
* will resolve, if the {@link TPromise} resolves.
|
|
98
|
+
*
|
|
99
|
+
* @template RejectType - The type to which the value underlying the {@link TPromise} returned by this
|
|
100
|
+
* will reject, if the {@link TPromise} rejects.
|
|
101
|
+
*
|
|
102
|
+
* @param OnFulfilled - The callback that is called when the underlying {@link Promise} resolves,
|
|
103
|
+
* if it resolves.
|
|
104
|
+
*
|
|
105
|
+
* @param OnRejected - The callback that is called when the underlying {@link Promise} rejects,
|
|
106
|
+
* if it rejects.
|
|
107
|
+
*
|
|
108
|
+
* @returns {TPromise<ResultType | RejectType>} A new {@link TPromise} of the result of the
|
|
109
|
+
* given callbacks.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const Example: TPromise<string> = new TPromise<string>((Resolve, Reject) =>
|
|
114
|
+
* {
|
|
115
|
+
* if (Math.random() < 0.5)
|
|
116
|
+
* {
|
|
117
|
+
* Resolve("Success");
|
|
118
|
+
* }
|
|
119
|
+
* else
|
|
120
|
+
* {
|
|
121
|
+
* Reject("Error");
|
|
122
|
+
* }
|
|
123
|
+
* });
|
|
124
|
+
*
|
|
125
|
+
* Example.then(
|
|
126
|
+
* (Value: string): void =>
|
|
127
|
+
* {
|
|
128
|
+
* // `Value` <- `"Success"`
|
|
129
|
+
* },
|
|
130
|
+
* (Reason: unknown): void =>
|
|
131
|
+
* {
|
|
132
|
+
* // `Reason` <- `"Error"`
|
|
133
|
+
* }
|
|
134
|
+
* );
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
Then<ResultType = ResolveType, RejectType = never>(OnFulfilled: TOnFulfilled<ResolveType, ResultType>, OnRejected?: TOnRejected<RejectType>): TPromise<ResultType | RejectType>;
|
|
138
|
+
then<ResultType = ResolveType, RejectType = never>(OnFulfilled?: TOnFulfilled<ResolveType, ResultType>, OnRejected?: TOnRejected<RejectType>): TPromise<ResultType | RejectType>;
|
|
139
|
+
Catch<ResultType = never>(OnRejected?: TNullable<TOnRejected<ResolveType>>): TPromiseLike<ResolveType | ResultType>;
|
|
140
|
+
Finally(OnFinally?: TNullable<TFunction>): TPromise<ResolveType>;
|
|
141
|
+
static Resolve<ResolveType>(Value: ResolveType | PromiseLike<ResolveType>): TPromise<Awaited<ResolveType>>;
|
|
142
|
+
static Reject<ResolveType = unknown>(Reason?: unknown): TPromise<ResolveType>;
|
|
143
|
+
Raw(): Promise<ResolveType>;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=Async.d.mts.map
|