@daiso-tech/core 0.37.3 → 0.39.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/README.md +5 -1
- package/dist/async/_module-exports.d.ts +1 -1
- package/dist/async/_module-exports.js +1 -1
- package/dist/async/_module-exports.js.map +1 -1
- package/dist/async/async.errors.d.ts +0 -20
- package/dist/async/async.errors.js +0 -16
- package/dist/async/async.errors.js.map +1 -1
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.d.ts +1 -1
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.d.ts +1 -1
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +2 -2
- package/dist/async/middlewares/_module.d.ts +0 -1
- package/dist/async/middlewares/_module.js +0 -1
- package/dist/async/middlewares/_module.js.map +1 -1
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +2 -2
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js +1 -1
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js.map +1 -1
- package/dist/async/middlewares/fallback/_module.d.ts +1 -0
- package/dist/async/middlewares/fallback/_module.js +1 -0
- package/dist/async/middlewares/fallback/_module.js.map +1 -1
- package/dist/async/middlewares/fallback/fallback.middleware.d.ts +25 -49
- package/dist/async/middlewares/fallback/fallback.middleware.js +52 -14
- package/dist/async/middlewares/fallback/fallback.middleware.js.map +1 -1
- package/dist/async/middlewares/fallback/fallback.types.d.ts +42 -0
- package/dist/async/middlewares/fallback/fallback.types.js +6 -0
- package/dist/async/middlewares/fallback/fallback.types.js.map +1 -0
- package/dist/async/middlewares/hedging/_module.d.ts +2 -2
- package/dist/async/middlewares/hedging/_module.js +2 -2
- package/dist/async/middlewares/hedging/_module.js.map +1 -1
- package/dist/async/middlewares/hedging/{_shared.d.ts → hedging.types.d.ts} +37 -9
- package/dist/async/middlewares/hedging/hedging.types.js +6 -0
- package/dist/async/middlewares/hedging/hedging.types.js.map +1 -0
- package/dist/async/middlewares/hedging/{sequential-hedging/sequential-hedging.middleware.d.ts → sequential-hedging.middleware.d.ts} +3 -3
- package/dist/async/middlewares/hedging/sequential-hedging.middleware.js +133 -0
- package/dist/async/middlewares/hedging/sequential-hedging.middleware.js.map +1 -0
- package/dist/async/middlewares/observe/_module.d.ts +1 -0
- package/dist/async/middlewares/observe/_module.js +1 -0
- package/dist/async/middlewares/observe/_module.js.map +1 -1
- package/dist/async/middlewares/observe/observe.middleware.d.ts +37 -87
- package/dist/async/middlewares/observe/observe.middleware.js +53 -2
- package/dist/async/middlewares/observe/observe.middleware.js.map +1 -1
- package/dist/async/middlewares/observe/observe.types.d.ts +91 -0
- package/dist/async/middlewares/observe/observe.types.js +6 -0
- package/dist/async/middlewares/observe/observe.types.js.map +1 -0
- package/dist/async/middlewares/retry/_module.d.ts +1 -0
- package/dist/async/middlewares/retry/_module.js +1 -0
- package/dist/async/middlewares/retry/_module.js.map +1 -1
- package/dist/async/middlewares/retry/retry.middleware.d.ts +36 -86
- package/dist/async/middlewares/retry/retry.middleware.js +70 -22
- package/dist/async/middlewares/retry/retry.middleware.js.map +1 -1
- package/dist/async/middlewares/retry/retry.types.d.ts +77 -0
- package/dist/async/middlewares/retry/retry.types.js +7 -0
- package/dist/async/middlewares/retry/retry.types.js.map +1 -0
- package/dist/async/middlewares/timeout/_module.d.ts +1 -0
- package/dist/async/middlewares/timeout/_module.js +1 -0
- package/dist/async/middlewares/timeout/_module.js.map +1 -1
- package/dist/async/middlewares/timeout/timeout.middleware.d.ts +1 -47
- package/dist/async/middlewares/timeout/timeout.middleware.js +1 -1
- package/dist/async/middlewares/timeout/timeout.middleware.js.map +1 -1
- package/dist/async/middlewares/timeout/timeout.type.d.ts +51 -0
- package/dist/async/middlewares/timeout/timeout.type.js +6 -0
- package/dist/async/middlewares/timeout/timeout.type.js.map +1 -0
- package/dist/async/utilities/promise-queue/promise-queue.js +19 -8
- package/dist/async/utilities/promise-queue/promise-queue.js.map +1 -1
- package/dist/cache/contracts/cache.contract.d.ts +7 -7
- package/dist/cache/contracts/cache.errors.d.ts +3 -26
- package/dist/cache/contracts/cache.errors.js +0 -47
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +6 -5
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +17 -13
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +15 -3
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +25 -9
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js +2 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +2 -2
- package/dist/cache/implementations/derivables/cache/cache.js +1 -1
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/collection/contracts/async-collection.contract.d.ts +0 -1
- package/dist/collection/contracts/async-collection.contract.js +3 -1
- package/dist/collection/contracts/async-collection.contract.js.map +1 -1
- package/dist/collection/contracts/collection.contract.d.ts +0 -1
- package/dist/collection/contracts/collection.contract.js +3 -1
- package/dist/collection/contracts/collection.contract.js.map +1 -1
- package/dist/collection/contracts/collection.errors.d.ts +1 -26
- package/dist/collection/contracts/collection.errors.js +0 -55
- package/dist/collection/contracts/collection.errors.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.js +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-zip-iterable.js +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-zip-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +9 -6
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/split-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/split-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/zip-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/zip-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +9 -6
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.js +12 -9
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/_module-exports.d.ts +0 -1
- package/dist/event-bus/contracts/_module-exports.js +0 -1
- package/dist/event-bus/contracts/_module-exports.js.map +1 -1
- package/dist/event-bus/contracts/event-bus.contract.d.ts +0 -6
- package/dist/event-bus/contracts/event-bus.contract.js +1 -7
- package/dist/event-bus/contracts/event-bus.contract.js.map +1 -1
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +2 -2
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +3 -2
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +6 -11
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/lock/contracts/database-lock-adapter.contract.d.ts +7 -5
- package/dist/lock/contracts/lock-adapter.contract.d.ts +5 -3
- package/dist/lock/contracts/lock.contract.d.ts +25 -41
- package/dist/lock/contracts/lock.errors.d.ts +5 -56
- package/dist/lock/contracts/lock.errors.js +1 -123
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/contracts/lock.events.d.ts +3 -3
- package/dist/lock/contracts/lock.events.js +1 -1
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +16 -4
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +11 -8
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +17 -6
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +9 -16
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +1 -1
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +3 -3
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +1 -1
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js +3 -2
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +3 -3
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +2 -3
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +4 -3
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-state.d.ts +8 -11
- package/dist/lock/implementations/derivables/lock-provider/lock-state.js +9 -26
- package/dist/lock/implementations/derivables/lock-provider/lock-state.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +11 -14
- package/dist/lock/implementations/derivables/lock-provider/lock.js +50 -26
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +43 -47
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +22 -22
- package/dist/utilities/_module-exports.d.ts +1 -1
- package/dist/utilities/_module-exports.js +1 -1
- package/dist/utilities/_module-exports.js.map +1 -1
- package/dist/utilities/classes/hooks/async-hooks.d.ts +6 -4
- package/dist/utilities/classes/hooks/async-hooks.js +3 -1
- package/dist/utilities/classes/hooks/async-hooks.js.map +1 -1
- package/dist/utilities/classes/hooks/hooks.d.ts +1 -1
- package/dist/utilities/classes/hooks/hooks.js +1 -1
- package/dist/utilities/classes/hooks/hooks.js.map +1 -1
- package/dist/utilities/classes/kysely-table-name-transformer-plugin/kysely-table-name-transformer-plugin.js +2 -1
- package/dist/utilities/classes/kysely-table-name-transformer-plugin/kysely-table-name-transformer-plugin.js.map +1 -1
- package/dist/utilities/classes/namespace/namespace.d.ts +5 -5
- package/dist/utilities/classes/namespace/namespace.js +2 -2
- package/dist/utilities/classes/namespace/namespace.js.map +1 -1
- package/dist/utilities/classes/time-span/time-span.d.ts +10 -2
- package/dist/utilities/classes/time-span/time-span.js +10 -2
- package/dist/utilities/classes/time-span/time-span.js.map +1 -1
- package/dist/utilities/errors.d.ts +8 -0
- package/dist/utilities/errors.js +11 -0
- package/dist/utilities/errors.js.map +1 -1
- package/dist/utilities/functions/{_module-exports.d.ts → _module.d.ts} +6 -1
- package/dist/utilities/functions/{_module-exports.js → _module.js} +7 -2
- package/dist/utilities/functions/_module.js.map +1 -0
- package/dist/utilities/functions/error-policy.d.ts +54 -0
- package/dist/utilities/functions/error-policy.js +63 -0
- package/dist/utilities/functions/error-policy.js.map +1 -0
- package/dist/utilities/functions/invokable.d.ts +57 -1
- package/dist/utilities/functions/invokable.js +3 -1
- package/dist/utilities/functions/invokable.js.map +1 -1
- package/dist/utilities/functions/is-class.d.ts +9 -0
- package/dist/utilities/functions/is-class.js +15 -0
- package/dist/utilities/functions/is-class.js.map +1 -0
- package/dist/utilities/functions/is-positive-nbr.d.ts +8 -0
- package/dist/utilities/functions/is-positive-nbr.js +19 -0
- package/dist/utilities/functions/is-positive-nbr.js.map +1 -0
- package/dist/utilities/functions/is-standard-schema.d.ts +2 -0
- package/dist/utilities/functions/is-standard-schema.js +5 -0
- package/dist/utilities/functions/is-standard-schema.js.map +1 -0
- package/dist/utilities/functions/lazy.d.ts +27 -1
- package/dist/utilities/functions/lazy.js.map +1 -1
- package/dist/utilities/functions/option.d.ts +32 -0
- package/dist/utilities/functions/option.js +25 -0
- package/dist/utilities/functions/option.js.map +1 -0
- package/dist/utilities/functions/resolve-one-or-more.d.ts +5 -1
- package/dist/utilities/functions/resolve-one-or-more.js.map +1 -1
- package/dist/utilities/functions/result.d.ts +81 -1
- package/dist/utilities/functions/result.js +46 -2
- package/dist/utilities/functions/result.js.map +1 -1
- package/dist/utilities/types/_module.d.ts +1 -7
- package/dist/utilities/types/_module.js +1 -7
- package/dist/utilities/types/_module.js.map +1 -1
- package/dist/utilities/types/any-class.type.d.ts +3 -0
- package/dist/utilities/types/any-class.type.js +2 -0
- package/dist/utilities/types/any-class.type.js.map +1 -0
- package/package.json +1 -1
- package/dist/async/middlewares/_shared.d.ts +0 -15
- package/dist/async/middlewares/_shared.js +0 -15
- package/dist/async/middlewares/_shared.js.map +0 -1
- package/dist/async/middlewares/hedging/_shared.js +0 -5
- package/dist/async/middlewares/hedging/_shared.js.map +0 -1
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.d.ts +0 -1
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js +0 -2
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js.map +0 -1
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.d.ts +0 -51
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js +0 -138
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js.map +0 -1
- package/dist/async/middlewares/hedging/sequential-hedging/_module.d.ts +0 -1
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js +0 -2
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js.map +0 -1
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js +0 -104
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js.map +0 -1
- package/dist/event-bus/contracts/event-bus.errors.d.ts +0 -72
- package/dist/event-bus/contracts/event-bus.errors.js +0 -110
- package/dist/event-bus/contracts/event-bus.errors.js.map +0 -1
- package/dist/utilities/functions/_module-exports.js.map +0 -1
- package/dist/utilities/types/at-least-one.type.d.ts +0 -8
- package/dist/utilities/types/at-least-one.type.js +0 -5
- package/dist/utilities/types/at-least-one.type.js.map +0 -1
- package/dist/utilities/types/factory.type.d.ts +0 -44
- package/dist/utilities/types/factory.type.js +0 -5
- package/dist/utilities/types/factory.type.js.map +0 -1
- package/dist/utilities/types/invokable.type.d.ts +0 -20
- package/dist/utilities/types/invokable.type.js +0 -5
- package/dist/utilities/types/invokable.type.js.map +0 -1
- package/dist/utilities/types/items.type.d.ts +0 -8
- package/dist/utilities/types/items.type.js +0 -5
- package/dist/utilities/types/items.type.js.map +0 -1
- package/dist/utilities/types/lazy.type.d.ts +0 -31
- package/dist/utilities/types/lazy.type.js +0 -5
- package/dist/utilities/types/lazy.type.js.map +0 -1
- package/dist/utilities/types/one-or-more.type.d.ts +0 -8
- package/dist/utilities/types/one-or-more.type.js +0 -5
- package/dist/utilities/types/one-or-more.type.js.map +0 -1
- package/dist/utilities/types/result.type.d.ts +0 -18
- package/dist/utilities/types/result.type.js +0 -5
- package/dist/utilities/types/result.type.js.map +0 -1
|
@@ -1,4 +1,84 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module Utilities
|
|
3
|
+
*/
|
|
4
|
+
export declare const RESULT: {
|
|
5
|
+
readonly FAILURE: "failure";
|
|
6
|
+
readonly SUCCESS: "success";
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
11
|
+
*/
|
|
12
|
+
export type ResultFailure<TError = unknown> = {
|
|
13
|
+
type: (typeof RESULT)["FAILURE"];
|
|
14
|
+
error: TError;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
19
|
+
*/
|
|
20
|
+
export type ResultSuccess<TValue = unknown> = {
|
|
21
|
+
type: (typeof RESULT)["SUCCESS"];
|
|
22
|
+
value: TValue;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The `Result` type represents either success or failure.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { Result, resultFailure, resultSuccess, RESULT } from "@daiso-tech/core/utilities";
|
|
30
|
+
*
|
|
31
|
+
* function random(): Result<string, Error> {
|
|
32
|
+
* const nbr = Math.round(Math.random() * 100);
|
|
33
|
+
* if (nbr > 50) {
|
|
34
|
+
* // The resultFailure function return a failed result
|
|
35
|
+
* return resultFailure(new Error("Unexpected error occured"));
|
|
36
|
+
* }
|
|
37
|
+
* // The resultSuccess function return a success result
|
|
38
|
+
* return resultSuccess("Function succeded");
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* const result = random();
|
|
42
|
+
*
|
|
43
|
+
* // Checking for failure
|
|
44
|
+
* if (result.type === RESULT.FAILURE) {
|
|
45
|
+
* console.log("Error occured:", result.error);
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* // Checking for success
|
|
49
|
+
* if (result.type === RESULT.SUCCESS) {
|
|
50
|
+
* console.log("Result was successful:", result.value);
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
55
|
+
*/
|
|
56
|
+
export type Result<TValue = unknown, TError = unknown> = ResultFailure<TError> | ResultSuccess<TValue>;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
60
|
+
*/
|
|
61
|
+
export type InferResultError<TValue> = TValue extends Result ? Extract<TValue, ResultFailure>["error"] : unknown;
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
65
|
+
*/
|
|
66
|
+
export type InferResultSuccess<TValue> = TValue extends Result ? Extract<TValue, ResultSuccess>["value"] : TValue;
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
70
|
+
*/
|
|
71
|
+
export declare function isResultFailure<TError = unknown>(value: unknown): value is ResultFailure<TError>;
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
75
|
+
*/
|
|
76
|
+
export declare function isResultSuccess<TSuccess = unknown>(value: unknown): value is ResultSuccess<TSuccess>;
|
|
77
|
+
/**
|
|
78
|
+
*
|
|
79
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
80
|
+
*/
|
|
81
|
+
export declare function isResult<TValue = unknown, TError = unknown>(value: unknown): value is Result<TValue, TError>;
|
|
2
82
|
/**
|
|
3
83
|
*
|
|
4
84
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
@@ -1,15 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Utilities
|
|
3
|
+
*/
|
|
4
|
+
export const RESULT = {
|
|
5
|
+
FAILURE: "failure",
|
|
6
|
+
SUCCESS: "success",
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
11
|
+
*/
|
|
12
|
+
export function isResultFailure(value) {
|
|
13
|
+
return (typeof value === "object" &&
|
|
14
|
+
value !== null &&
|
|
15
|
+
"type" in value &&
|
|
16
|
+
typeof value.type === "string" &&
|
|
17
|
+
value.type === RESULT.FAILURE &&
|
|
18
|
+
"error" in value);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
23
|
+
*/
|
|
24
|
+
export function isResultSuccess(value) {
|
|
25
|
+
return (typeof value === "object" &&
|
|
26
|
+
value !== null &&
|
|
27
|
+
"type" in value &&
|
|
28
|
+
typeof value.type === "string" &&
|
|
29
|
+
value.type === RESULT.SUCCESS &&
|
|
30
|
+
"value" in value);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
35
|
+
*/
|
|
36
|
+
export function isResult(value) {
|
|
37
|
+
return isResultFailure(value) || isResultSuccess(value);
|
|
38
|
+
}
|
|
1
39
|
/**
|
|
2
40
|
*
|
|
3
41
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
4
42
|
*/
|
|
5
43
|
export function resultFailure(error) {
|
|
6
|
-
return
|
|
44
|
+
return {
|
|
45
|
+
type: RESULT.FAILURE,
|
|
46
|
+
error,
|
|
47
|
+
};
|
|
7
48
|
}
|
|
8
49
|
/**
|
|
9
50
|
*
|
|
10
51
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
11
52
|
*/
|
|
12
53
|
export function resultSuccess(value) {
|
|
13
|
-
return
|
|
54
|
+
return {
|
|
55
|
+
type: RESULT.SUCCESS,
|
|
56
|
+
value,
|
|
57
|
+
};
|
|
14
58
|
}
|
|
15
59
|
//# sourceMappingURL=result.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/utilities/functions/result.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/utilities/functions/result.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,MAAM,GAAG;IAClB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;CACZ,CAAC;AAwEX;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC3B,KAAc;IAEd,OAAO,CACH,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9B,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO;QAC7B,OAAO,IAAI,KAAK,CACnB,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC3B,KAAc;IAEd,OAAO,CACH,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9B,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO;QAC7B,OAAO,IAAI,KAAK,CACnB,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CACpB,KAAc;IAEd,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CACzB,KAAa;IAEb,OAAO;QACH,IAAI,EAAE,MAAM,CAAC,OAAO;QACpB,KAAK;KACR,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAS,KAAa;IAC/C,OAAO;QACH,IAAI,EAAE,MAAM,CAAC,OAAO;QACpB,KAAK;KACR,CAAC;AACN,CAAC"}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
+
export * from "../../utilities/types/any-class.type.js";
|
|
1
2
|
export * from "../../utilities/types/async-iterable-value.type.js";
|
|
2
|
-
export * from "../../utilities/types/at-least-one.type.js";
|
|
3
|
-
export * from "../../utilities/types/factory.type.js";
|
|
4
3
|
export * from "../../utilities/types/none-func.type.js";
|
|
5
|
-
export * from "../../utilities/types/invokable.type.js";
|
|
6
|
-
export * from "../../utilities/types/items.type.js";
|
|
7
|
-
export * from "../../utilities/types/lazy.type.js";
|
|
8
|
-
export * from "../../utilities/types/one-or-more.type.js";
|
|
9
4
|
export * from "../../utilities/types/promiseable.type.js";
|
|
10
|
-
export * from "../../utilities/types/result.type.js";
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
+
export * from "../../utilities/types/any-class.type.js";
|
|
1
2
|
export * from "../../utilities/types/async-iterable-value.type.js";
|
|
2
|
-
export * from "../../utilities/types/at-least-one.type.js";
|
|
3
|
-
export * from "../../utilities/types/factory.type.js";
|
|
4
3
|
export * from "../../utilities/types/none-func.type.js";
|
|
5
|
-
export * from "../../utilities/types/invokable.type.js";
|
|
6
|
-
export * from "../../utilities/types/items.type.js";
|
|
7
|
-
export * from "../../utilities/types/lazy.type.js";
|
|
8
|
-
export * from "../../utilities/types/one-or-more.type.js";
|
|
9
4
|
export * from "../../utilities/types/promiseable.type.js";
|
|
10
|
-
export * from "../../utilities/types/result.type.js";
|
|
11
5
|
//# sourceMappingURL=_module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/utilities/types/_module.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/utilities/types/_module.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"any-class.type.js","sourceRoot":"","sources":["../../../src/utilities/types/any-class.type.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Async
|
|
3
|
-
*/
|
|
4
|
-
import { type Invokable } from "../../utilities/_module-exports.js";
|
|
5
|
-
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
9
|
-
* @group Middlewares
|
|
10
|
-
*/
|
|
11
|
-
export type ErrorPolicy<TInput = unknown, TOutput = unknown> = Invokable<[error: unknown], boolean> | StandardSchemaV1<TInput, TOutput>;
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export declare function callErrorPolicy<TInput = unknown, TOutput = unknown>(errorPolicy: ErrorPolicy<TInput, TOutput>, value: unknown): Promise<boolean>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Async
|
|
3
|
-
*/
|
|
4
|
-
import { callInvokable, isInvokable, } from "../../utilities/_module-exports.js";
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export async function callErrorPolicy(errorPolicy, value) {
|
|
9
|
-
if (isInvokable(errorPolicy)) {
|
|
10
|
-
return callInvokable(errorPolicy, value);
|
|
11
|
-
}
|
|
12
|
-
const result = await errorPolicy["~standard"].validate(value);
|
|
13
|
-
return result.issues === undefined;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=_shared.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../../src/async/middlewares/_shared.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACH,aAAa,EACb,WAAW,GAEd,MAAM,gCAAgC,CAAC;AAYxC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACjC,WAAyC,EACzC,KAAc;IAEd,IAAI,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;QAC3B,OAAO,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9D,OAAO,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC;AACvC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../../../src/async/middlewares/hedging/_shared.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAKN,MAAM,gCAAgC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../async/middlewares/hedging/concurrent-hedging/_module.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../../src/async/middlewares/hedging/concurrent-hedging/_module.ts"],"names":[],"mappings":"AAAA,cAAc,2DAA2D,CAAC"}
|
package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Async
|
|
3
|
-
*/
|
|
4
|
-
import { type AsyncMiddlewareFn, type HookContext } from "../../../../utilities/_module-exports.js";
|
|
5
|
-
import type { HedgingSettings } from "../../../../async/middlewares/hedging/_shared.js";
|
|
6
|
-
/**
|
|
7
|
-
* The `concurrentHedging` middleware executes the primary function and all fallback functions concurrently.
|
|
8
|
-
* It returns the result of the first successful function and automatically aborts all remaining functions.
|
|
9
|
-
* If all function fail than error is thrown.
|
|
10
|
-
*
|
|
11
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
12
|
-
* @group Middlewares
|
|
13
|
-
* @throws {HedgingAsyncError} {@link HedgingAsyncError}
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* import { concurrentHedging } from "@daiso-tech/core/async";
|
|
18
|
-
* import { AsyncHooks } from "@daiso-tech/core/utilities";
|
|
19
|
-
*
|
|
20
|
-
* async function fn1(signal?: AbortSignal): Promise<unknown> {
|
|
21
|
-
* const response = await fetch("ENDPOINT-1", { signal });
|
|
22
|
-
* return await response.json();
|
|
23
|
-
* }
|
|
24
|
-
* async function fn2(signal?: AbortSignal): Promise<unknown> {
|
|
25
|
-
* const response = await fetch("ENDPOINT-2", { signal });
|
|
26
|
-
* return await response.json();
|
|
27
|
-
* }
|
|
28
|
-
* async function fn3(signal?: AbortSignal): Promise<unknown> {
|
|
29
|
-
* const response = await fetch("ENDPOINT-3", { signal });
|
|
30
|
-
* return await response.json();
|
|
31
|
-
* }
|
|
32
|
-
* const fetchData = new AsyncHooks(fn1, [
|
|
33
|
-
* concurrentHedging({
|
|
34
|
-
* fallbacks: [
|
|
35
|
-
* fn2,
|
|
36
|
-
* fn3
|
|
37
|
-
* ]
|
|
38
|
-
* })
|
|
39
|
-
* ], {
|
|
40
|
-
* signalBinder: {
|
|
41
|
-
* getSignal: (args) => args[0],
|
|
42
|
-
* forwardSignal: (args, signal) => {
|
|
43
|
-
* args[0] = signal;
|
|
44
|
-
* }
|
|
45
|
-
* }
|
|
46
|
-
* });
|
|
47
|
-
*
|
|
48
|
-
* console.log(await fetchData.invoke());
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare function concurrentHedging<TParameters extends unknown[], TReturn, TContext extends HookContext>(settings: NoInfer<HedgingSettings<TParameters, TReturn, TContext>>): AsyncMiddlewareFn<TParameters, TReturn, TContext>;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Async
|
|
3
|
-
*/
|
|
4
|
-
import { callInvokable, isInvokable, resolveOneOrMore, TimeSpan, } from "../../../../utilities/_module-exports.js";
|
|
5
|
-
import { HedgingAsyncError } from "../../../../async/async.errors.js";
|
|
6
|
-
import { timeoutAndFail, abortAndFail } from "../../../../async/utilities/_module.js";
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
class ResolvedError extends Error {
|
|
11
|
-
constructor(message, cause) {
|
|
12
|
-
super(message, { cause });
|
|
13
|
-
this.name = ResolvedError.name;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* The `concurrentHedging` middleware executes the primary function and all fallback functions concurrently.
|
|
18
|
-
* It returns the result of the first successful function and automatically aborts all remaining functions.
|
|
19
|
-
* If all function fail than error is thrown.
|
|
20
|
-
*
|
|
21
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
22
|
-
* @group Middlewares
|
|
23
|
-
* @throws {HedgingAsyncError} {@link HedgingAsyncError}
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* import { concurrentHedging } from "@daiso-tech/core/async";
|
|
28
|
-
* import { AsyncHooks } from "@daiso-tech/core/utilities";
|
|
29
|
-
*
|
|
30
|
-
* async function fn1(signal?: AbortSignal): Promise<unknown> {
|
|
31
|
-
* const response = await fetch("ENDPOINT-1", { signal });
|
|
32
|
-
* return await response.json();
|
|
33
|
-
* }
|
|
34
|
-
* async function fn2(signal?: AbortSignal): Promise<unknown> {
|
|
35
|
-
* const response = await fetch("ENDPOINT-2", { signal });
|
|
36
|
-
* return await response.json();
|
|
37
|
-
* }
|
|
38
|
-
* async function fn3(signal?: AbortSignal): Promise<unknown> {
|
|
39
|
-
* const response = await fetch("ENDPOINT-3", { signal });
|
|
40
|
-
* return await response.json();
|
|
41
|
-
* }
|
|
42
|
-
* const fetchData = new AsyncHooks(fn1, [
|
|
43
|
-
* concurrentHedging({
|
|
44
|
-
* fallbacks: [
|
|
45
|
-
* fn2,
|
|
46
|
-
* fn3
|
|
47
|
-
* ]
|
|
48
|
-
* })
|
|
49
|
-
* ], {
|
|
50
|
-
* signalBinder: {
|
|
51
|
-
* getSignal: (args) => args[0],
|
|
52
|
-
* forwardSignal: (args, signal) => {
|
|
53
|
-
* args[0] = signal;
|
|
54
|
-
* }
|
|
55
|
-
* }
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* console.log(await fetchData.invoke());
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export function concurrentHedging(settings) {
|
|
62
|
-
const { waitTime = TimeSpan.fromSeconds(2), fallbacks, onHedgingAttempt = () => { }, onHedgingError = () => { }, } = settings;
|
|
63
|
-
const resolvedFallbacks = resolveOneOrMore(fallbacks).map((fallback, index) => {
|
|
64
|
-
if (isInvokable(fallback)) {
|
|
65
|
-
return {
|
|
66
|
-
name: `fallback-${String(index + 1)}`,
|
|
67
|
-
invokable: fallback,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return fallback;
|
|
71
|
-
});
|
|
72
|
-
return async (args, next, { context, abort, signal }) => {
|
|
73
|
-
function step1({ name, invokable }) {
|
|
74
|
-
return {
|
|
75
|
-
name,
|
|
76
|
-
promise: timeoutAndFail(abortAndFail((async () => callInvokable(invokable, ...args))(), signal), waitTime, (error) => {
|
|
77
|
-
abort(error);
|
|
78
|
-
}, signal),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
async function step2({ name, promise }) {
|
|
82
|
-
try {
|
|
83
|
-
const value = await promise;
|
|
84
|
-
// We abort all other promises when on promise succeds.
|
|
85
|
-
abort(new ResolvedError("Already resolved"));
|
|
86
|
-
return {
|
|
87
|
-
type: "success",
|
|
88
|
-
value,
|
|
89
|
-
name,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
return {
|
|
94
|
-
type: "failure",
|
|
95
|
-
error,
|
|
96
|
-
name,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const funcs = [
|
|
101
|
-
{
|
|
102
|
-
name: "__initial",
|
|
103
|
-
invokable: next,
|
|
104
|
-
},
|
|
105
|
-
...resolvedFallbacks,
|
|
106
|
-
];
|
|
107
|
-
const promises = funcs.map(step1).map(step2);
|
|
108
|
-
const errors = [];
|
|
109
|
-
const promiseResults = await Promise.all(promises);
|
|
110
|
-
for (const promiseResult of promiseResults) {
|
|
111
|
-
callInvokable(onHedgingAttempt, {
|
|
112
|
-
args,
|
|
113
|
-
context,
|
|
114
|
-
name: promiseResult.name,
|
|
115
|
-
});
|
|
116
|
-
// We return the first fulfilled value
|
|
117
|
-
if (promiseResult.type === "success") {
|
|
118
|
-
return promiseResult.value;
|
|
119
|
-
}
|
|
120
|
-
else if (!(promiseResult.error instanceof ResolvedError)) {
|
|
121
|
-
callInvokable(onHedgingError, {
|
|
122
|
-
args,
|
|
123
|
-
context,
|
|
124
|
-
error: promiseResult.error,
|
|
125
|
-
name: promiseResult.name,
|
|
126
|
-
});
|
|
127
|
-
errors.push(promiseResult.error);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
// If all promiseResults are rejected we will throw an error
|
|
131
|
-
const funcNames = funcs
|
|
132
|
-
.slice(1)
|
|
133
|
-
.map(({ name }) => `"${name}"`)
|
|
134
|
-
.join(", ");
|
|
135
|
-
throw new HedgingAsyncError(`The original function and fallback functions failed: ${funcNames}`, errors);
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=concurrent-hedging.middleware.js.map
|
package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"concurrent-hedging.middleware.js","sourceRoot":"","sources":["../../../../../src/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../async/middlewares/hedging/sequential-hedging/_module.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../../src/async/middlewares/hedging/sequential-hedging/_module.ts"],"names":[],"mappings":"AAAA,cAAc,2DAA2D,CAAC"}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Async
|
|
3
|
-
*/
|
|
4
|
-
import { callInvokable, isInvokable, resolveOneOrMore, TimeSpan, } from "../../../../utilities/_module-exports.js";
|
|
5
|
-
import { HedgingAsyncError } from "../../../../async/async.errors.js";
|
|
6
|
-
import { timeoutAndFail } from "../../../../async/utilities/_module.js";
|
|
7
|
-
/**
|
|
8
|
-
* The `sequentialHedging` middleware executes the primary function and all fallback functions sequentially.
|
|
9
|
-
* It returns the result of the first successful function and automatically cancels all remaining functions.
|
|
10
|
-
* If all function fail than error is thrown.
|
|
11
|
-
*
|
|
12
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
13
|
-
* @group Middlewares
|
|
14
|
-
* @throws {HedgingAsyncError} {@link HedgingAsyncError}
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* import { sequentialHedging } from "@daiso-tech/core/async";
|
|
19
|
-
* import { AsyncHooks } from "@daiso-tech/core/utilities";
|
|
20
|
-
*
|
|
21
|
-
* async function fn1(signal?: AbortSignal): Promise<unknown> {
|
|
22
|
-
* const response = await fetch("ENDPOINT-1", { signal });
|
|
23
|
-
* return await response.json();
|
|
24
|
-
* }
|
|
25
|
-
* async function fn2(signal?: AbortSignal): Promise<unknown> {
|
|
26
|
-
* const response = await fetch("ENDPOINT-2", { signal });
|
|
27
|
-
* return await response.json();
|
|
28
|
-
* }
|
|
29
|
-
* async function fn3(signal?: AbortSignal): Promise<unknown> {
|
|
30
|
-
* const response = await fetch("ENDPOINT-3", { signal });
|
|
31
|
-
* return await response.json();
|
|
32
|
-
* }
|
|
33
|
-
* const fetchData = new AsyncHooks(fn1, [
|
|
34
|
-
* sequentialHedging({
|
|
35
|
-
* fallbacks: [
|
|
36
|
-
* fn2,
|
|
37
|
-
* fn3
|
|
38
|
-
* ]
|
|
39
|
-
* })
|
|
40
|
-
* ], {
|
|
41
|
-
* signalBinder: {
|
|
42
|
-
* getSignal: (args) => args[0],
|
|
43
|
-
* forwardSignal: (args, signal) => {
|
|
44
|
-
* args[0] = signal;
|
|
45
|
-
* }
|
|
46
|
-
* }
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
-
* console.log(await fetchData.invoke());
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export function sequentialHedging(settings) {
|
|
53
|
-
const { waitTime = TimeSpan.fromSeconds(2), fallbacks, onHedgingAttempt = () => { }, onHedgingError = () => { }, } = settings;
|
|
54
|
-
const resolvedFallbacks = resolveOneOrMore(fallbacks).map((fallback, index) => {
|
|
55
|
-
if (isInvokable(fallback)) {
|
|
56
|
-
return {
|
|
57
|
-
name: `fallback-${String(index + 1)}`,
|
|
58
|
-
invokable: fallback,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return fallback;
|
|
62
|
-
});
|
|
63
|
-
return async (args, next, { context, signal, abort }) => {
|
|
64
|
-
const errors = [];
|
|
65
|
-
const funcs = [
|
|
66
|
-
{
|
|
67
|
-
name: "__initial",
|
|
68
|
-
invokable: next,
|
|
69
|
-
},
|
|
70
|
-
...resolvedFallbacks,
|
|
71
|
-
];
|
|
72
|
-
for (const { name, invokable: func } of funcs) {
|
|
73
|
-
try {
|
|
74
|
-
callInvokable(onHedgingAttempt, {
|
|
75
|
-
args,
|
|
76
|
-
context,
|
|
77
|
-
name,
|
|
78
|
-
});
|
|
79
|
-
return await timeoutAndFail((async () => callInvokable(func, ...args))(), waitTime, (error) => {
|
|
80
|
-
abort(error);
|
|
81
|
-
}, signal);
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
if (signal.aborted) {
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
callInvokable(onHedgingError, {
|
|
88
|
-
args,
|
|
89
|
-
context,
|
|
90
|
-
error,
|
|
91
|
-
name,
|
|
92
|
-
});
|
|
93
|
-
errors.push(error);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// If all promiseResults are rejected we will throw an error
|
|
97
|
-
const funcNames = funcs
|
|
98
|
-
.slice(1)
|
|
99
|
-
.map(({ name }) => `"${name}"`)
|
|
100
|
-
.join(", ");
|
|
101
|
-
throw new HedgingAsyncError(`The original function and fallback functions failed: ${funcNames}`, errors);
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=sequential-hedging.middleware.js.map
|
package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sequential-hedging.middleware.js","sourceRoot":"","sources":["../../../../../src/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,QAAQ,GAGX,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,UAAU,iBAAiB,CAK7B,QAAkE;IAElE,MAAM,EACF,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EAClC,SAAS,EACT,gBAAgB,GAAG,GAAG,EAAE,GAAE,CAAC,EAC3B,cAAc,GAAG,GAAG,EAAE,GAAE,CAAC,GAC5B,GAAG,QAAQ,CAAC;IAEb,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC,GAAG,CAEvD,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QAClB,IAAI,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,OAAO;gBACH,IAAI,EAAE,YAAY,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE;gBACrC,SAAS,EAAE,QAAQ;aACtB,CAAC;QACN,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;QACpD,MAAM,MAAM,GAAc,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG;YACV;gBACI,IAAI,EAAE,WAAW;gBACjB,SAAS,EAAE,IAAI;aAClB;YACD,GAAG,iBAAiB;SACvB,CAAC;QACF,KAAK,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;YAC5C,IAAI,CAAC;gBACD,aAAa,CAAC,gBAAgB,EAAE;oBAC5B,IAAI;oBACJ,OAAO;oBACP,IAAI;iBACP,CAAC,CAAC;gBACH,OAAO,MAAM,cAAc,CACvB,CAAC,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,EAC5C,QAAQ,EACR,CAAC,KAAc,EAAE,EAAE;oBACf,KAAK,CAAC,KAAK,CAAC,CAAC;gBACjB,CAAC,EACD,MAAM,CACT,CAAC;YACN,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACtB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBACjB,MAAM;gBACV,CAAC;gBACD,aAAa,CAAC,cAAc,EAAE;oBAC1B,IAAI;oBACJ,OAAO;oBACP,KAAK;oBACL,IAAI;iBACP,CAAC,CAAC;gBACH,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;QACL,CAAC;QAED,4DAA4D;QAC5D,MAAM,SAAS,GAAG,KAAK;aAClB,KAAK,CAAC,CAAC,CAAC;aACR,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC;aAC9B,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,MAAM,IAAI,iBAAiB,CACvB,wDAAwD,SAAS,EAAE,EACnE,MAAM,CACT,CAAC;IACN,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module EventBus
|
|
3
|
-
*/
|
|
4
|
-
import type { ISerderRegister, ISerializable } from "../../serde/contracts/_module-exports.js";
|
|
5
|
-
import { type ISerializedError, type OneOrMore } from "../../utilities/_module-exports.js";
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"`
|
|
9
|
-
* @group Errors
|
|
10
|
-
*/
|
|
11
|
-
export declare class EventBusError extends Error implements ISerializable<ISerializedError> {
|
|
12
|
-
static deserialize(deserializedValue: ISerializedError): EventBusError;
|
|
13
|
-
constructor(message: string, cause?: unknown);
|
|
14
|
-
serialize(): ISerializedError;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"`
|
|
19
|
-
* @group Errors
|
|
20
|
-
*/
|
|
21
|
-
export declare class UnexpectedEventBusError extends EventBusError {
|
|
22
|
-
static deserialize(deserializedValue: ISerializedError): EventBusError;
|
|
23
|
-
constructor(message: string, cause?: unknown);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The error is thrown when an unexpected error occurs while removing a listener.
|
|
27
|
-
*
|
|
28
|
-
* IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"`
|
|
29
|
-
* @group Errors
|
|
30
|
-
*/
|
|
31
|
-
export declare class UnableToRemoveListenerEventBusError extends UnexpectedEventBusError {
|
|
32
|
-
static deserialize(deserializedValue: ISerializedError): EventBusError;
|
|
33
|
-
constructor(message: string, cause?: unknown);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* The error is thrown when an unexpected error occurs while adding a listener.
|
|
37
|
-
*
|
|
38
|
-
* IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"`
|
|
39
|
-
* @group Errors
|
|
40
|
-
*/
|
|
41
|
-
export declare class UnableToAddListenerEventBusError extends UnexpectedEventBusError {
|
|
42
|
-
static deserialize(deserializedValue: ISerializedError): EventBusError;
|
|
43
|
-
constructor(message: string, cause?: unknown);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The error is thrown when an unexpected error occurs while dispatching an event.
|
|
47
|
-
*
|
|
48
|
-
* IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"`
|
|
49
|
-
* @group Errors
|
|
50
|
-
*/
|
|
51
|
-
export declare class UnableToDispatchEventBusError extends UnexpectedEventBusError {
|
|
52
|
-
constructor(message: string, cause?: unknown);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"`
|
|
57
|
-
* @group Errors
|
|
58
|
-
*/
|
|
59
|
-
export declare const EVENT_BUS_ERRORS: {
|
|
60
|
-
Base: typeof EventBusError;
|
|
61
|
-
Unexpected: typeof UnexpectedEventBusError;
|
|
62
|
-
UnableToRemoveListener: typeof UnableToRemoveListenerEventBusError;
|
|
63
|
-
UnableToAddListener: typeof UnableToAddListenerEventBusError;
|
|
64
|
-
UnableToDispatch: typeof UnableToDispatchEventBusError;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* The `registerEventBusErrorsToSerde` function registers all {@link IEventBus | `IEventBus`} related errors with `ISerderRegister`, ensuring they will properly be serialized and deserialized.
|
|
68
|
-
*
|
|
69
|
-
* IMPORT_PATH: `"@daiso-tech/core/event-bus/contracts"`
|
|
70
|
-
* @group Errors
|
|
71
|
-
*/
|
|
72
|
-
export declare function registerEventBusErrorsToSerde(serde: OneOrMore<ISerderRegister>): void;
|