@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
package/README.md
CHANGED
|
@@ -17,7 +17,11 @@
|
|
|
17
17
|
@daiso-tech/core leverages modern JavaScript primitives, including ES modules
|
|
18
18
|
|
|
19
19
|
- **Easily testable:**
|
|
20
|
-
@daiso-tech/core includes built-in vitest helpers for custom adapters and in-memory adapters for all components, enabling testing without Docker.
|
|
20
|
+
@daiso-tech/core includes built-in [vitest](https://vitest.dev/) helpers for custom adapters and in-memory adapters for all components, enabling testing without Docker.
|
|
21
|
+
|
|
22
|
+
- **Supports standard schema:**
|
|
23
|
+
Integrated seamlessly with [standard schema](https://standardschema.dev/) allowing you to use libraries like zod to ensure both compile time and runtimte typesafety.
|
|
24
|
+
|
|
21
25
|
|
|
22
26
|
## A growing collection of officially maintained components
|
|
23
27
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "../async/backof-policies/_module.js";
|
|
2
2
|
export * from "../async/middlewares/_module.js";
|
|
3
|
-
export * from "../async/utilities/_module.js";
|
|
3
|
+
export * from "../async/utilities/lazy-promise/_module.js";
|
|
4
4
|
export * from "../async/async.errors.js";
|
|
5
5
|
//# sourceMappingURL=_module-exports.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module-exports.js","sourceRoot":"","sources":["../../src/async/_module-exports.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,
|
|
1
|
+
{"version":3,"file":"_module-exports.js","sourceRoot":"","sources":["../../src/async/_module-exports.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yBAAyB,CAAC"}
|
|
@@ -17,25 +17,6 @@ export declare class AsyncError extends Error {
|
|
|
17
17
|
export declare class TimeoutAsyncError extends AsyncError {
|
|
18
18
|
constructor(message: string, cause?: unknown);
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
23
|
-
* @group Errors
|
|
24
|
-
*/
|
|
25
|
-
export type RetryAsyncErrorData = {
|
|
26
|
-
errors: unknown[];
|
|
27
|
-
maxAttempts: number;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
32
|
-
* @group Errors
|
|
33
|
-
*/
|
|
34
|
-
export declare class RetryAsyncError extends AsyncError {
|
|
35
|
-
readonly maxAttempts: number;
|
|
36
|
-
readonly errors: unknown[];
|
|
37
|
-
constructor(message: string, { errors, maxAttempts }: RetryAsyncErrorData);
|
|
38
|
-
}
|
|
39
20
|
/**
|
|
40
21
|
*
|
|
41
22
|
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
@@ -61,7 +42,6 @@ export declare class CapacityFullAsyncError extends AsyncError {
|
|
|
61
42
|
export declare const ASYNC_ERRORS: {
|
|
62
43
|
readonly Base: typeof AsyncError;
|
|
63
44
|
readonly Timeout: typeof TimeoutAsyncError;
|
|
64
|
-
readonly Retry: typeof RetryAsyncError;
|
|
65
45
|
readonly Hedging: typeof HedgingAsyncError;
|
|
66
46
|
readonly CapacityFull: typeof CapacityFullAsyncError;
|
|
67
47
|
};
|
|
@@ -23,21 +23,6 @@ export class TimeoutAsyncError extends AsyncError {
|
|
|
23
23
|
this.name = TimeoutAsyncError.name;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
29
|
-
* @group Errors
|
|
30
|
-
*/
|
|
31
|
-
export class RetryAsyncError extends AsyncError {
|
|
32
|
-
maxAttempts;
|
|
33
|
-
errors = [];
|
|
34
|
-
constructor(message, { errors, maxAttempts }) {
|
|
35
|
-
super(message, errors);
|
|
36
|
-
this.errors = errors;
|
|
37
|
-
this.maxAttempts = maxAttempts;
|
|
38
|
-
this.name = RetryAsyncError.name;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
26
|
/**
|
|
42
27
|
*
|
|
43
28
|
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
@@ -70,7 +55,6 @@ export class CapacityFullAsyncError extends AsyncError {
|
|
|
70
55
|
export const ASYNC_ERRORS = {
|
|
71
56
|
Base: AsyncError,
|
|
72
57
|
Timeout: TimeoutAsyncError,
|
|
73
|
-
Retry: RetryAsyncError,
|
|
74
58
|
Hedging: HedgingAsyncError,
|
|
75
59
|
CapacityFull: CapacityFullAsyncError,
|
|
76
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async.errors.js","sourceRoot":"","sources":["../../src/async/async.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAChC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAC7C,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC;IACvC,CAAC;CACJ;
|
|
1
|
+
{"version":3,"file":"async.errors.js","sourceRoot":"","sources":["../../src/async/async.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAChC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAC7C,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC;IACvC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAGzB;IAFpB,YACI,OAAe,EACC,MAAiB;QAEjC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAFP,WAAM,GAAN,MAAM,CAAW;QAGjC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC;IACvC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,UAAU;IAClD,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC,IAAI,CAAC;IAC5C,CAAC;CACJ;AACD;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,iBAAiB;IAC1B,OAAO,EAAE,iBAAiB;IAC1B,YAAY,EAAE,sBAAsB;CAC9B,CAAC"}
|
|
@@ -5,4 +5,3 @@ export * from "../../async/middlewares/hedging/_module.js";
|
|
|
5
5
|
export * from "../../async/middlewares/observe/_module.js";
|
|
6
6
|
export * from "../../async/middlewares/retry/_module.js";
|
|
7
7
|
export * from "../../async/middlewares/timeout/_module.js";
|
|
8
|
-
export * from "../../async/middlewares/_shared.js";
|
|
@@ -5,5 +5,4 @@ export * from "../../async/middlewares/hedging/_module.js";
|
|
|
5
5
|
export * from "../../async/middlewares/observe/_module.js";
|
|
6
6
|
export * from "../../async/middlewares/retry/_module.js";
|
|
7
7
|
export * from "../../async/middlewares/timeout/_module.js";
|
|
8
|
-
export * from "../../async/middlewares/_shared.js";
|
|
9
8
|
//# sourceMappingURL=_module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/async/middlewares/_module.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,wCAAwC,CAAC
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/async/middlewares/_module.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,wCAAwC,CAAC"}
|
|
@@ -34,14 +34,14 @@ export type BulkheadSettings<TParameters extends unknown[] = unknown[], TContext
|
|
|
34
34
|
/**
|
|
35
35
|
* The maximum number of promises allowed to run concurrently. If this limit is exceeded, additional promises will be queued until a slot becomes available.
|
|
36
36
|
*
|
|
37
|
-
* @default
|
|
37
|
+
* @default 25
|
|
38
38
|
*/
|
|
39
39
|
maxConcurrency?: number;
|
|
40
40
|
/**
|
|
41
41
|
* The maximum capacity of the promise queue. If null, the queue can grow indefinitely.
|
|
42
42
|
* If a number is provided and the queue exceeds this limit, an error will be thrown, and no further promises will be enqueued.
|
|
43
43
|
*
|
|
44
|
-
* @default
|
|
44
|
+
* @default null
|
|
45
45
|
*/
|
|
46
46
|
maxCapacity?: number | null;
|
|
47
47
|
/**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
4
|
import { callInvokable, TimeSpan, } from "../../../utilities/_module-exports.js";
|
|
5
|
-
import { PromiseQueue } from "../../../async/utilities/_module.js";
|
|
5
|
+
import { PromiseQueue } from "../../../async/utilities/promise-queue/_module.js";
|
|
6
6
|
/**
|
|
7
7
|
* The `bulkhead` middlewares ensures that a given amount of {@link Promiselike | `PromiseLike`} objects run at the same time concurrently and the rest will be queued up.
|
|
8
8
|
* You can provide {@link BulkheadSettings | `settings.maxCapacity`}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulkhead.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/bulkhead/bulkhead.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,aAAa,EACb,QAAQ,GAIX,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"bulkhead.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/bulkhead/bulkhead.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,aAAa,EACb,QAAQ,GAIX,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAwE1E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,QAAQ,CAKpB,WAAoD,EAAE;IAEtD,MAAM,EACF,cAAc,GAAG,EAAE,EACnB,WAAW,GAAG,IAAI,EAClB,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,EACvC,YAAY,GAAG,GAAG,EAAE,GAAE,CAAC,GAC1B,GAAG,QAAQ,CAAC;IACb,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC;QAClC,WAAW;QACX,cAAc;QACd,QAAQ;KACX,CAAC,CAAC;IACH,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;QAC7C,OAAO,MAAM,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE;YAC/B,aAAa,CAAC,YAAY,EAAE;gBACxB,IAAI;gBACJ,OAAO;aACV,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC,EAAE,MAAM,CAAC,CAAC;IACf,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/middlewares/fallback/_module.ts"],"names":[],"mappings":"AAAA,cAAc,qDAAqD,CAAC"}
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/middlewares/fallback/_module.ts"],"names":[],"mappings":"AAAA,cAAc,qDAAqD,CAAC;AACpE,cAAc,gDAAgD,CAAC"}
|
|
@@ -1,54 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
10
|
-
* @group Middlewares
|
|
11
|
-
*/
|
|
12
|
-
export type OnFallbackData<TParameters extends unknown[] = unknown[], TFallbackValue = unknown, TContext extends HookContext = HookContext> = {
|
|
13
|
-
error: unknown;
|
|
14
|
-
fallbackValue: TFallbackValue;
|
|
15
|
-
args: TParameters;
|
|
16
|
-
context: TContext;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
21
|
-
* @group Middlewares
|
|
22
|
-
*/
|
|
23
|
-
export type OnFallback<TParameters extends unknown[] = unknown[], TFallbackValue = unknown, TContext extends HookContext = HookContext> = Invokable<[data: OnFallbackData<TParameters, TFallbackValue, TContext>]>;
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
27
|
-
* @group Middlewares
|
|
28
|
-
*/
|
|
29
|
-
export type FallbackCallbacks<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = {
|
|
30
|
-
/**
|
|
31
|
-
* Callback {@link Invokable | `Invokable`} that will be called before fallback value is returned.
|
|
32
|
-
*/
|
|
33
|
-
onFallback?: OnFallback<TParameters, TReturn, TContext>;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
38
|
-
* @group Middlewares
|
|
39
|
-
*/
|
|
40
|
-
export type FallbackSettings<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = FallbackCallbacks<TParameters, TReturn, TContext> & {
|
|
41
|
-
fallbackValue: AsyncLazyable<TReturn>;
|
|
42
|
-
/**
|
|
43
|
-
* You can choose what errors you want to add fallback value. By default fallback value will be added to all errors.
|
|
44
|
-
*
|
|
45
|
-
* @default
|
|
46
|
-
* ```ts
|
|
47
|
-
* (_error: unknown) => true
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
errorPolicy?: ErrorPolicy;
|
|
51
|
-
};
|
|
4
|
+
import { type HookContext } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import type { AsyncMiddlewareFn } from "../../../utilities/_module-exports.js";
|
|
6
|
+
import type { FallbackSettings } from "../../../async/middlewares/fallback/fallback.types.js";
|
|
52
7
|
/**
|
|
53
8
|
* The `fallback` middleware adds fallback value when an error occurs.
|
|
54
9
|
*
|
|
@@ -74,5 +29,26 @@ export type FallbackSettings<TParameters extends unknown[] = unknown[], TReturn
|
|
|
74
29
|
* // Will return null when the fetch method throws an error.
|
|
75
30
|
* console.log(await fetchData.invoke("URL_ENDPOINT"));
|
|
76
31
|
* ```
|
|
32
|
+
*
|
|
33
|
+
* The middleware works also when the function returns a {@link Result | `Result`} type.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { fallback } from "@daiso-tech/core/async";
|
|
37
|
+
* import { AsyncHooks, Result, resultFailure, resultSuccess } from "@daiso-tech/core/utilities";
|
|
38
|
+
*
|
|
39
|
+
* const fetchData = new AsyncHooks(async (url: string): Promise<Result> => {
|
|
40
|
+
* const response = await fetch(url);
|
|
41
|
+
* const json = await response.json();
|
|
42
|
+
* if (!response.ok) {
|
|
43
|
+
* return resultFailure(json);
|
|
44
|
+
* }
|
|
45
|
+
* return resultSuccess(json);
|
|
46
|
+
* }, [
|
|
47
|
+
* fallback({ fallbackValue: null })
|
|
48
|
+
* ]);
|
|
49
|
+
*
|
|
50
|
+
* // Will return null when the fetch method throws an error.
|
|
51
|
+
* console.log(await fetchData.invoke("URL_ENDPOINT"));
|
|
52
|
+
* ```
|
|
77
53
|
*/
|
|
78
|
-
export declare function fallback<TParameters extends unknown[], TReturn, TContext extends HookContext>(settings: NoInfer<FallbackSettings<TParameters, TReturn, TContext>>): AsyncMiddlewareFn<TParameters, TReturn, TContext>;
|
|
54
|
+
export declare function fallback<TParameters extends unknown[], TReturn, TContext extends HookContext>(settings: NoInfer<FallbackSettings<TParameters, TReturn, TContext, TReturn>>): AsyncMiddlewareFn<TParameters, TReturn, TContext>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
|
-
import { callInvokable,
|
|
5
|
-
import {
|
|
4
|
+
import { resolveAsyncLazyable, callInvokable, resultSuccess, callErrorPolicyOnValue, isResultFailure, } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import { callErrorPolicyOnThrow } from "../../../utilities/_module-exports.js";
|
|
6
6
|
/**
|
|
7
7
|
* The `fallback` middleware adds fallback value when an error occurs.
|
|
8
8
|
*
|
|
@@ -28,25 +28,63 @@ import { callErrorPolicy, } from "../../../async/middlewares/_shared.js";
|
|
|
28
28
|
* // Will return null when the fetch method throws an error.
|
|
29
29
|
* console.log(await fetchData.invoke("URL_ENDPOINT"));
|
|
30
30
|
* ```
|
|
31
|
+
*
|
|
32
|
+
* The middleware works also when the function returns a {@link Result | `Result`} type.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { fallback } from "@daiso-tech/core/async";
|
|
36
|
+
* import { AsyncHooks, Result, resultFailure, resultSuccess } from "@daiso-tech/core/utilities";
|
|
37
|
+
*
|
|
38
|
+
* const fetchData = new AsyncHooks(async (url: string): Promise<Result> => {
|
|
39
|
+
* const response = await fetch(url);
|
|
40
|
+
* const json = await response.json();
|
|
41
|
+
* if (!response.ok) {
|
|
42
|
+
* return resultFailure(json);
|
|
43
|
+
* }
|
|
44
|
+
* return resultSuccess(json);
|
|
45
|
+
* }, [
|
|
46
|
+
* fallback({ fallbackValue: null })
|
|
47
|
+
* ]);
|
|
48
|
+
*
|
|
49
|
+
* // Will return null when the fetch method throws an error.
|
|
50
|
+
* console.log(await fetchData.invoke("URL_ENDPOINT"));
|
|
51
|
+
* ```
|
|
31
52
|
*/
|
|
32
53
|
export function fallback(settings) {
|
|
33
|
-
const { fallbackValue, errorPolicy
|
|
54
|
+
const { fallbackValue, errorPolicy, onFallback = () => { } } = settings;
|
|
34
55
|
return async (args, next, { context }) => {
|
|
35
56
|
try {
|
|
36
|
-
|
|
57
|
+
const value = await next(...args);
|
|
58
|
+
// Handle fallback value if an Result type is returned
|
|
59
|
+
if (!(await callErrorPolicyOnValue(errorPolicy, value))) {
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
// This is only needed for type inference
|
|
63
|
+
if (!isResultFailure(value)) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
const resolvedFallbackValue = await resolveAsyncLazyable(fallbackValue);
|
|
67
|
+
callInvokable(onFallback, {
|
|
68
|
+
error: value.error,
|
|
69
|
+
fallbackValue: resolvedFallbackValue,
|
|
70
|
+
args,
|
|
71
|
+
context,
|
|
72
|
+
});
|
|
73
|
+
return resultSuccess(resolvedFallbackValue);
|
|
74
|
+
// Handle fallback value if an error is thrown
|
|
37
75
|
}
|
|
38
76
|
catch (error) {
|
|
39
|
-
if (await
|
|
40
|
-
|
|
41
|
-
callInvokable(onFallback, {
|
|
42
|
-
error,
|
|
43
|
-
fallbackValue: resolvedFallbackValue,
|
|
44
|
-
args,
|
|
45
|
-
context,
|
|
46
|
-
});
|
|
47
|
-
return resolvedFallbackValue;
|
|
77
|
+
if (!(await callErrorPolicyOnThrow(errorPolicy, error))) {
|
|
78
|
+
throw error;
|
|
48
79
|
}
|
|
49
|
-
|
|
80
|
+
const resolvedFallbackValue = await resolveAsyncLazyable(fallbackValue);
|
|
81
|
+
callInvokable(onFallback, {
|
|
82
|
+
error,
|
|
83
|
+
fallbackValue: resolvedFallbackValue,
|
|
84
|
+
args,
|
|
85
|
+
context,
|
|
86
|
+
});
|
|
87
|
+
return resolvedFallbackValue;
|
|
50
88
|
}
|
|
51
89
|
};
|
|
52
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fallback.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/fallback/fallback.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"fallback.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/fallback/fallback.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAIH,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,eAAe,GAClB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,UAAU,QAAQ,CAKpB,QAEC;IAED,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,GAAG,GAAG,EAAE,GAAE,CAAC,EAAE,GAAG,QAAQ,CAAC;IACvE,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,EAAoB,EAAE;QACvD,IAAI,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;YAElC,sDAAsD;YACtD,IAAI,CAAC,CAAC,MAAM,sBAAsB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;gBACtD,OAAO,KAAK,CAAC;YACjB,CAAC;YACD,yCAAyC;YACzC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC1B,OAAO,KAAK,CAAC;YACjB,CAAC;YAED,MAAM,qBAAqB,GACvB,MAAM,oBAAoB,CAAC,aAAa,CAAC,CAAC;YAC9C,aAAa,CAAC,UAAU,EAAE;gBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,aAAa,EAAE,qBAAgC;gBAC/C,IAAI;gBACJ,OAAO;aACV,CAAC,CAAC;YACH,OAAO,aAAa,CAAC,qBAAqB,CAAY,CAAC;YAEvD,8CAA8C;QAClD,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,IAAI,CAAC,CAAC,MAAM,sBAAsB,CAAM,WAAW,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3D,MAAM,KAAK,CAAC;YAChB,CAAC;YACD,MAAM,qBAAqB,GACvB,MAAM,oBAAoB,CAAC,aAAa,CAAC,CAAC;YAC9C,aAAa,CAAC,UAAU,EAAE;gBACtB,KAAK;gBACL,aAAa,EAAE,qBAAgC;gBAC/C,IAAI;gBACJ,OAAO;aACV,CAAC,CAAC;YACH,OAAO,qBAAgC,CAAC;QAC5C,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Async
|
|
3
|
+
*/
|
|
4
|
+
import type { HookContext, AsyncLazyable, InferResultSuccess, InferResultError } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import { type Invokable } from "../../../utilities/_module-exports.js";
|
|
6
|
+
import { type ErrorPolicySettings } from "../../../utilities/_module-exports.js";
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
10
|
+
* @group Middlewares
|
|
11
|
+
*/
|
|
12
|
+
export type OnFallbackData<TParameters extends unknown[] = unknown[], TFallbackValue = unknown, TContext extends HookContext = HookContext> = {
|
|
13
|
+
error: unknown;
|
|
14
|
+
fallbackValue: TFallbackValue;
|
|
15
|
+
args: TParameters;
|
|
16
|
+
context: TContext;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
21
|
+
* @group Middlewares
|
|
22
|
+
*/
|
|
23
|
+
export type OnFallback<TParameters extends unknown[] = unknown[], TFallbackValue = unknown, TContext extends HookContext = HookContext> = Invokable<[data: OnFallbackData<TParameters, TFallbackValue, TContext>]>;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
27
|
+
* @group Middlewares
|
|
28
|
+
*/
|
|
29
|
+
export type FallbackCallbacks<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = {
|
|
30
|
+
/**
|
|
31
|
+
* Callback {@link Invokable | `Invokable`} that will be called before fallback value is returned.
|
|
32
|
+
*/
|
|
33
|
+
onFallback?: OnFallback<TParameters, TReturn, TContext>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
38
|
+
* @group Middlewares
|
|
39
|
+
*/
|
|
40
|
+
export type FallbackSettings<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext, TError = unknown> = FallbackCallbacks<TParameters, TReturn, TContext> & ErrorPolicySettings<InferResultError<TError>> & {
|
|
41
|
+
fallbackValue: AsyncLazyable<InferResultSuccess<TReturn>>;
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallback.types.js","sourceRoot":"","sources":["../../../../src/async/middlewares/fallback/fallback.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EAAkB,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAA4B,MAAM,gCAAgC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "../../../async/middlewares/hedging/
|
|
2
|
-
export * from "../../../async/middlewares/hedging/sequential-hedging
|
|
1
|
+
export * from "../../../async/middlewares/hedging/hedging.types.js";
|
|
2
|
+
export * from "../../../async/middlewares/hedging/sequential-hedging.middleware.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "../../../async/middlewares/hedging/
|
|
2
|
-
export * from "../../../async/middlewares/hedging/sequential-hedging
|
|
1
|
+
export * from "../../../async/middlewares/hedging/hedging.types.js";
|
|
2
|
+
export * from "../../../async/middlewares/hedging/sequential-hedging.middleware.js";
|
|
3
3
|
//# sourceMappingURL=_module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/middlewares/hedging/_module.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/middlewares/hedging/_module.ts"],"names":[],"mappings":"AAAA,cAAc,8CAA8C,CAAC;AAC7D,cAAc,8DAA8D,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
5
|
-
import
|
|
4
|
+
import { type AsyncMiddleware, type HookContext, type OneOrMore } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import type { ErrorPolicySettings, InferResultError } from "../../../utilities/_module-exports.js";
|
|
6
|
+
import { type Invokable, type Promisable } from "../../../utilities/_module-exports.js";
|
|
6
7
|
/**
|
|
7
8
|
*
|
|
8
9
|
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
@@ -74,20 +75,47 @@ export type NamedFallback<TParameters extends unknown[] = unknown[], TReturn = u
|
|
|
74
75
|
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
75
76
|
* @group Middlewares
|
|
76
77
|
*/
|
|
77
|
-
export type HedgingSettings<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = HedgingCallbacks<TParameters, TContext> & {
|
|
78
|
+
export type HedgingSettings<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = HedgingCallbacks<TParameters, TContext> & ErrorPolicySettings<InferResultError<TReturn>> & {
|
|
78
79
|
/**
|
|
79
|
-
* The
|
|
80
|
+
* The fallback functions that run in case the primary function fails.
|
|
80
81
|
*
|
|
81
82
|
* @default
|
|
82
83
|
* ```ts
|
|
83
|
-
* import {
|
|
84
|
+
* import { retry } from "@daiso-tech/core/async";
|
|
85
|
+
* import { timeout } from "@daiso-tech/core/async";
|
|
84
86
|
*
|
|
85
|
-
*
|
|
87
|
+
* [timeout(), retry()]
|
|
86
88
|
* ```
|
|
87
89
|
*/
|
|
88
|
-
|
|
90
|
+
fallbacks: OneOrMore<Fallback<TParameters, TReturn> | NamedFallback<TParameters, TReturn>>;
|
|
89
91
|
/**
|
|
90
|
-
*
|
|
92
|
+
* Middlewares to apply on all fallback functions and on primary function.
|
|
93
|
+
*
|
|
94
|
+
* You can wrap primary and fallback functions with for example `retry` and `timeout` middlewares.
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { retry, timeout, sequentialHedging } from "@daiso-tech/core/async";
|
|
98
|
+
*
|
|
99
|
+
* new AsyncHooks(fn, [
|
|
100
|
+
* sequentialHedging({
|
|
101
|
+
* fallbacks: [
|
|
102
|
+
* fn1,
|
|
103
|
+
* fn2,
|
|
104
|
+
* fn3,
|
|
105
|
+
* ],
|
|
106
|
+
* middlewares: [
|
|
107
|
+
* timeout({
|
|
108
|
+
* waitTime: TimeSpan.fromSeconds(2),
|
|
109
|
+
* }),
|
|
110
|
+
* retry({
|
|
111
|
+
* maxAttempts: 4
|
|
112
|
+
* }),
|
|
113
|
+
* ]
|
|
114
|
+
* })
|
|
115
|
+
* ], {
|
|
116
|
+
* signalBinder,
|
|
117
|
+
* })
|
|
118
|
+
* ```
|
|
91
119
|
*/
|
|
92
|
-
|
|
120
|
+
middlewares?: Array<AsyncMiddleware<TParameters, TReturn>>;
|
|
93
121
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hedging.types.js","sourceRoot":"","sources":["../../../../src/async/middlewares/hedging/hedging.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAIN,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAGN,MAAM,gCAAgC,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
|
-
import { type AsyncMiddlewareFn, type HookContext } from "
|
|
5
|
-
import type
|
|
4
|
+
import { type AsyncMiddlewareFn, type HookContext } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import { type HedgingSettings } from "../../../async/middlewares/hedging/hedging.types.js";
|
|
6
6
|
/**
|
|
7
7
|
* The `sequentialHedging` middleware executes the primary function and all fallback functions sequentially.
|
|
8
8
|
* It returns the result of the first successful function and automatically cancels all remaining functions.
|
|
9
|
-
* If all function fail than error is thrown.
|
|
9
|
+
* If all function fail than last error is thrown.
|
|
10
10
|
*
|
|
11
11
|
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
12
12
|
* @group Middlewares
|