@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,18 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
|
-
import { callInvokable, } from "../../../utilities/_module-exports.js";
|
|
5
|
-
import { exponentialBackoffPolicy
|
|
6
|
-
import {
|
|
7
|
-
import { LazyPromise } from "../../../async/utilities/_module.js";
|
|
8
|
-
import { callErrorPolicy, } from "../../../async/middlewares/_shared.js";
|
|
4
|
+
import { callInvokable, optionNone, optionSome, OPTION, UnexpectedError, } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import { exponentialBackoffPolicy } from "../../../async/backof-policies/_module.js";
|
|
6
|
+
import { callErrorPolicyOnThrow, callErrorPolicyOnValue, } from "../../../utilities/_module-exports.js";
|
|
7
|
+
import { LazyPromise } from "../../../async/utilities/lazy-promise/_module.js";
|
|
9
8
|
/**
|
|
10
9
|
* The `retry` middleware enables automatic retries for all errors or specific errors, with configurable backoff policies.
|
|
11
10
|
* An error will be thrown when all retry attempts fail.
|
|
12
11
|
*
|
|
13
12
|
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
14
13
|
* @group Middleware
|
|
15
|
-
* @throws {RetryAsyncError} {@link RetryAsyncError}
|
|
16
14
|
*
|
|
17
15
|
* @example
|
|
18
16
|
* ```ts
|
|
@@ -22,7 +20,39 @@ import { callErrorPolicy, } from "../../../async/middlewares/_shared.js";
|
|
|
22
20
|
* const data = await new AsyncHooks(
|
|
23
21
|
* async (url: string, signal?: AbortSignal): Promise<unknown> => {
|
|
24
22
|
* const response = await fetch(url, { signal });
|
|
25
|
-
*
|
|
23
|
+
* const json = await response.json();
|
|
24
|
+
* if (!response.ok) {
|
|
25
|
+
* return json;
|
|
26
|
+
* }
|
|
27
|
+
* return json;
|
|
28
|
+
* },
|
|
29
|
+
* [retry()],
|
|
30
|
+
* {
|
|
31
|
+
* signalBinder: {
|
|
32
|
+
* getSignal: (args) => args[1],
|
|
33
|
+
* forwardSignal: (args, signal) => {
|
|
34
|
+
* args[1] = signal;
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* )
|
|
39
|
+
* .invoke("URL");
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* The middleware works also when the function returns a {@link Result | `Result`} type.
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { retry } from "@daiso-tech/core/async";
|
|
46
|
+
* import { AsyncHooks, TimeSpan, Result, resultFailure, resultSuccess } from "@daiso-tech/core/utilities";
|
|
47
|
+
*
|
|
48
|
+
* const data = await new AsyncHooks(
|
|
49
|
+
* async (url: string, signal?: AbortSignal): Promise<Result> => {
|
|
50
|
+
* const response = await fetch(url, { signal });
|
|
51
|
+
* const json = await response.json();
|
|
52
|
+
* if (!response.ok) {
|
|
53
|
+
* return resultFailure(json);
|
|
54
|
+
* }
|
|
55
|
+
* return resultSuccess(json);
|
|
26
56
|
* },
|
|
27
57
|
* [retry()],
|
|
28
58
|
* {
|
|
@@ -38,27 +68,48 @@ import { callErrorPolicy, } from "../../../async/middlewares/_shared.js";
|
|
|
38
68
|
* ```
|
|
39
69
|
*/
|
|
40
70
|
export function retry(settings = {}) {
|
|
41
|
-
const { maxAttempts = 4, backoffPolicy = exponentialBackoffPolicy(), errorPolicy
|
|
71
|
+
const { maxAttempts = 4, backoffPolicy = exponentialBackoffPolicy(), errorPolicy, onRetryDelay = () => { }, onExecutionAttempt = () => { }, } = settings;
|
|
42
72
|
return async (args, next, { context, signal }) => {
|
|
43
|
-
|
|
73
|
+
let result = optionNone();
|
|
74
|
+
let error_ = optionNone();
|
|
44
75
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
45
76
|
try {
|
|
46
77
|
callInvokable(onExecutionAttempt, { attempt, args, context });
|
|
47
|
-
|
|
78
|
+
const value = await next(...args);
|
|
79
|
+
// Handle retrying if an Result type is returned
|
|
80
|
+
result = optionSome(value);
|
|
81
|
+
if (!(await callErrorPolicyOnValue(errorPolicy, value))) {
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
// We can cast type here because callErrorPolicyOnValue ensures the value is a ResultFailure
|
|
85
|
+
const resultFailure = value;
|
|
86
|
+
if (signal.aborted) {
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
const waitTime = callInvokable(backoffPolicy, attempt, resultFailure.error);
|
|
90
|
+
callInvokable(onRetryDelay, {
|
|
91
|
+
error: resultFailure.error,
|
|
92
|
+
waitTime,
|
|
93
|
+
attempt,
|
|
94
|
+
args,
|
|
95
|
+
context,
|
|
96
|
+
});
|
|
97
|
+
await LazyPromise.delay(waitTime, signal);
|
|
98
|
+
// Handle retrying if an error is thrown
|
|
48
99
|
}
|
|
49
100
|
catch (error) {
|
|
50
101
|
if (signal.aborted) {
|
|
51
102
|
break;
|
|
52
103
|
}
|
|
53
|
-
if (await
|
|
54
|
-
|
|
104
|
+
if (await callErrorPolicyOnThrow(errorPolicy, error)) {
|
|
105
|
+
error_ = optionSome(error);
|
|
55
106
|
}
|
|
56
107
|
else {
|
|
57
108
|
throw error;
|
|
58
109
|
}
|
|
59
110
|
const waitTime = callInvokable(backoffPolicy, attempt, error);
|
|
60
111
|
callInvokable(onRetryDelay, {
|
|
61
|
-
error,
|
|
112
|
+
error: error,
|
|
62
113
|
waitTime,
|
|
63
114
|
attempt,
|
|
64
115
|
args,
|
|
@@ -67,16 +118,13 @@ export function retry(settings = {}) {
|
|
|
67
118
|
await LazyPromise.delay(waitTime, signal);
|
|
68
119
|
}
|
|
69
120
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
121
|
+
if (error_.type === OPTION.SOME) {
|
|
122
|
+
throw error_.value;
|
|
123
|
+
}
|
|
124
|
+
if (result.type === OPTION.SOME) {
|
|
125
|
+
return result.value;
|
|
75
126
|
}
|
|
76
|
-
throw new
|
|
77
|
-
errors,
|
|
78
|
-
maxAttempts,
|
|
79
|
-
});
|
|
127
|
+
throw new UnexpectedError("!!__MESSAGE__!!");
|
|
80
128
|
};
|
|
81
129
|
}
|
|
82
130
|
//# sourceMappingURL=retry.middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/retry/retry.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"retry.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/retry/retry.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAGH,aAAa,EACb,UAAU,EACV,UAAU,EACV,MAAM,EACN,eAAe,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAE9E,OAAO,EACH,sBAAsB,EACtB,sBAAsB,GACzB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,UAAU,KAAK,CAKjB,WAAmE,EAAE;IAErE,MAAM,EACF,WAAW,GAAG,CAAC,EACf,aAAa,GAAG,wBAAwB,EAAE,EAC1C,WAAW,EACX,YAAY,GAAG,GAAG,EAAE,GAAE,CAAC,EACvB,kBAAkB,GAAG,GAAG,EAAE,GAAE,CAAC,GAChC,GAAG,QAAQ,CAAC;IACb,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;QAC7C,IAAI,MAAM,GAAoB,UAAU,EAAE,CAAC;QAC3C,IAAI,MAAM,GAAW,UAAU,EAAE,CAAC;QAClC,KAAK,IAAI,OAAO,GAAG,CAA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AC;gBAE9D,aAAa,CAAC,YAAY,EAAE;oBACxB,KAAK,EAAE,KAAK;oBACZ,QAAQ;oBACR,OAAO;oBACP,IAAI;oBACJ,OAAO;iBACV,CAAC,CAAC;gBACH,MAAM,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC9C,CAAC;QACL,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;YAC9B,MAAM,MAAM,CAAC,KAAK,CAAC;QACvB,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;YAC9B,OAAO,MAAM,CAAC,KAAK,CAAC;QACxB,CAAC;QACD,MAAM,IAAI,eAAe,CAAC,iBAAiB,CAAC,CAAC;IACjD,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Async
|
|
3
|
+
*/
|
|
4
|
+
import type { InferResultError, TimeSpan } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import { type Invokable, type HookContext } from "../../../utilities/_module-exports.js";
|
|
6
|
+
import { type BackoffPolicy } from "../../../async/backof-policies/_module.js";
|
|
7
|
+
import { type ErrorPolicySettings } from "../../../utilities/_module-exports.js";
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
11
|
+
* @group Middlewares
|
|
12
|
+
*/
|
|
13
|
+
export type OnRetryAttemptData<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
14
|
+
attempt: number;
|
|
15
|
+
args: TParameters;
|
|
16
|
+
context: TContext;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
21
|
+
* @group Middlewares
|
|
22
|
+
*/
|
|
23
|
+
export type OnExecutionAttempt<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = Invokable<[data: OnRetryAttemptData<TParameters, TContext>]>;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
27
|
+
* @group Middlewares
|
|
28
|
+
*/
|
|
29
|
+
export type OnRetryDelayData<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
30
|
+
error: unknown;
|
|
31
|
+
attempt: number;
|
|
32
|
+
waitTime: TimeSpan;
|
|
33
|
+
args: TParameters;
|
|
34
|
+
context: TContext;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
39
|
+
* @group Middlewares
|
|
40
|
+
*/
|
|
41
|
+
export type OnRetryDelay<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = Invokable<[data: OnRetryDelayData<TParameters, TContext>]>;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
45
|
+
* @group Middlewares
|
|
46
|
+
*/
|
|
47
|
+
export type RetryCallbacks<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
48
|
+
/**
|
|
49
|
+
* Callback {@link Invokable | `Invokable`} that will be called before execution attempt.
|
|
50
|
+
*/
|
|
51
|
+
onExecutionAttempt?: OnExecutionAttempt<TParameters, TContext>;
|
|
52
|
+
/**
|
|
53
|
+
* Callback {@link Invokable | `Invokable`} that will be called before the retry delay starts.
|
|
54
|
+
*/
|
|
55
|
+
onRetryDelay?: OnRetryDelay<TParameters, TContext>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
60
|
+
* @group Middlewares
|
|
61
|
+
*/
|
|
62
|
+
export type RetrySettings<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext, TReturn = unknown> = RetryCallbacks<TParameters, TContext> & ErrorPolicySettings<InferResultError<TReturn>> & {
|
|
63
|
+
/**
|
|
64
|
+
* You can decide maximal times you can retry.
|
|
65
|
+
* @default 4
|
|
66
|
+
*/
|
|
67
|
+
maxAttempts?: number;
|
|
68
|
+
/**
|
|
69
|
+
* @default
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { exponentialBackoffPolicy } from "@daiso-tech/core/async";
|
|
72
|
+
*
|
|
73
|
+
* exponentialBackoffPolicy();
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
backoffPolicy?: BackoffPolicy;
|
|
77
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.types.js","sourceRoot":"","sources":["../../../../src/async/middlewares/retry/retry.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAGN,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAsB,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAA4B,MAAM,gCAAgC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/middlewares/timeout/_module.ts"],"names":[],"mappings":"AAAA,cAAc,mDAAmD,CAAC"}
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../../src/async/middlewares/timeout/_module.ts"],"names":[],"mappings":"AAAA,cAAc,mDAAmD,CAAC;AAClE,cAAc,6CAA6C,CAAC"}
|
|
@@ -1,54 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
|
-
import { TimeSpan } from "../../../utilities/_module-exports.js";
|
|
5
4
|
import { type AsyncMiddlewareFn, type HookContext } from "../../../utilities/_module-exports.js";
|
|
6
|
-
import {
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
10
|
-
* @group Middlewares
|
|
11
|
-
*/
|
|
12
|
-
export type OnTimeoutData<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
13
|
-
waitTime: TimeSpan;
|
|
14
|
-
args: TParameters;
|
|
15
|
-
context: TContext;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
20
|
-
* @group Middlewares
|
|
21
|
-
*/
|
|
22
|
-
export type OnTimeout<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = Invokable<[data: OnTimeoutData<TParameters, TContext>]>;
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
26
|
-
* @group Middlewares
|
|
27
|
-
*/
|
|
28
|
-
export type TimeoutCallbacks<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
29
|
-
/**
|
|
30
|
-
* Callback {@link Invokable | `Invokable`} that will be called before the timeout occurs.
|
|
31
|
-
*/
|
|
32
|
-
onTimeout?: OnTimeout<TParameters, TContext>;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
37
|
-
* @group Middlewares
|
|
38
|
-
*/
|
|
39
|
-
export type TimeoutSettings<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = TimeoutCallbacks<TParameters, TContext> & {
|
|
40
|
-
/**
|
|
41
|
-
* The maximum time to wait before automatically aborting the executing function.
|
|
42
|
-
*
|
|
43
|
-
* @default
|
|
44
|
-
* ```ts
|
|
45
|
-
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
46
|
-
*
|
|
47
|
-
* TimeSpan.fromSeconds(2)
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
waitTime?: TimeSpan;
|
|
51
|
-
};
|
|
5
|
+
import type { TimeoutSettings } from "../../../async/middlewares/timeout/timeout.type.js";
|
|
52
6
|
/**
|
|
53
7
|
* The `timeout` middleware automatically cancels functions after a specified time period, throwing an error when aborted.
|
|
54
8
|
*
|
|
@@ -5,7 +5,7 @@ import { TimeSpan } from "../../../utilities/_module-exports.js";
|
|
|
5
5
|
import {} from "../../../utilities/_module-exports.js";
|
|
6
6
|
import { callInvokable } from "../../../utilities/_module-exports.js";
|
|
7
7
|
import { TimeoutAsyncError } from "../../../async/async.errors.js";
|
|
8
|
-
import { timeoutAndFail } from "../../../async/utilities/_module.js";
|
|
8
|
+
import { timeoutAndFail } from "../../../async/utilities/timeout-and-fail/_module.js";
|
|
9
9
|
/**
|
|
10
10
|
* The `timeout` middleware automatically cancels functions after a specified time period, throwing an error when aborted.
|
|
11
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/timeout/timeout.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAON,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"timeout.middleware.js","sourceRoot":"","sources":["../../../../src/async/middlewares/timeout/timeout.middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAON,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAG/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,OAAO,CAKnB,WAA4D,EAAE;IAE9D,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,GAAG,EAAE,GAAE,CAAC,EAAE,GAC9D,QAAQ,CAAC;IACb,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE;QACpD,IAAI,CAAC;YACD,OAAO,MAAM,cAAc,CACvB,IAAI,CAAC,GAAG,IAAI,CAAC,EACb,QAAQ,EACR,CAAC,KAAc,EAAE,EAAE;gBACf,KAAK,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,EACD,MAAM,CACT,CAAC;QACN,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,IAAI,KAAK,YAAY,iBAAiB,EAAE,CAAC;gBACrC,aAAa,CAAC,SAAS,EAAE;oBACrB,IAAI;oBACJ,OAAO;oBACP,QAAQ;iBACX,CAAC,CAAC;YACP,CAAC;YACD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Async
|
|
3
|
+
*/
|
|
4
|
+
import type { TimeSpan } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import { type HookContext } from "../../../utilities/_module-exports.js";
|
|
6
|
+
import { type Invokable } from "../../../utilities/_module-exports.js";
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
10
|
+
* @group Middlewares
|
|
11
|
+
*/
|
|
12
|
+
export type OnTimeoutData<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
13
|
+
waitTime: TimeSpan;
|
|
14
|
+
args: TParameters;
|
|
15
|
+
context: TContext;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
20
|
+
* @group Middlewares
|
|
21
|
+
*/
|
|
22
|
+
export type OnTimeout<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = Invokable<[data: OnTimeoutData<TParameters, TContext>]>;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
26
|
+
* @group Middlewares
|
|
27
|
+
*/
|
|
28
|
+
export type TimeoutCallbacks<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
29
|
+
/**
|
|
30
|
+
* Callback {@link Invokable | `Invokable`} that will be called before the timeout occurs.
|
|
31
|
+
*/
|
|
32
|
+
onTimeout?: OnTimeout<TParameters, TContext>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* IMPORT_PATH: `"@daiso-tech/core/async"`
|
|
37
|
+
* @group Middlewares
|
|
38
|
+
*/
|
|
39
|
+
export type TimeoutSettings<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = TimeoutCallbacks<TParameters, TContext> & {
|
|
40
|
+
/**
|
|
41
|
+
* The maximum time to wait before automatically aborting the executing function.
|
|
42
|
+
*
|
|
43
|
+
* @default
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { TimeSpan } from "@daiso-tech/core/utilities";
|
|
46
|
+
*
|
|
47
|
+
* TimeSpan.fromSeconds(2)
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
waitTime?: TimeSpan;
|
|
51
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.type.js","sourceRoot":"","sources":["../../../../src/async/middlewares/timeout/timeout.type.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAoB,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAkB,MAAM,gCAAgC,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module Async
|
|
3
3
|
*/
|
|
4
4
|
import {} from "../../../utilities/_module-exports.js";
|
|
5
|
-
import { LazyPromise } from "../../../async/utilities/_module.js";
|
|
5
|
+
import { LazyPromise } from "../../../async/utilities/lazy-promise/_module.js";
|
|
6
6
|
import { v4 } from "uuid";
|
|
7
7
|
import { CapacityFullAsyncError } from "../../../async/async.errors.js";
|
|
8
8
|
/**
|
|
@@ -54,14 +54,23 @@ export class PromiseQueue {
|
|
|
54
54
|
const listener = this.listeners.get(item.id);
|
|
55
55
|
try {
|
|
56
56
|
if (item.signal.aborted) {
|
|
57
|
-
listener?.(
|
|
57
|
+
listener?.({
|
|
58
|
+
type: "failure",
|
|
59
|
+
error: item.signal.reason,
|
|
60
|
+
});
|
|
58
61
|
return;
|
|
59
62
|
}
|
|
60
63
|
const value = await item.func(item.signal);
|
|
61
|
-
listener?.(
|
|
64
|
+
listener?.({
|
|
65
|
+
type: "success",
|
|
66
|
+
value,
|
|
67
|
+
});
|
|
62
68
|
}
|
|
63
69
|
catch (error) {
|
|
64
|
-
listener?.(
|
|
70
|
+
listener?.({
|
|
71
|
+
type: "failure",
|
|
72
|
+
error,
|
|
73
|
+
});
|
|
65
74
|
throw error;
|
|
66
75
|
}
|
|
67
76
|
}
|
|
@@ -87,13 +96,15 @@ export class PromiseQueue {
|
|
|
87
96
|
}
|
|
88
97
|
asPromise(id) {
|
|
89
98
|
return new Promise((resolve, reject) => {
|
|
90
|
-
this.listenOnce(id, (
|
|
91
|
-
if (
|
|
99
|
+
this.listenOnce(id, (result) => {
|
|
100
|
+
if (result.type === "failure") {
|
|
92
101
|
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
93
|
-
reject(error);
|
|
102
|
+
reject(result.error);
|
|
94
103
|
return;
|
|
95
104
|
}
|
|
96
|
-
|
|
105
|
+
else {
|
|
106
|
+
resolve(result.value);
|
|
107
|
+
}
|
|
97
108
|
});
|
|
98
109
|
});
|
|
99
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise-queue.js","sourceRoot":"","sources":["../../../../src/async/utilities/promise-queue/promise-queue.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAIN,MAA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@@ -92,7 +92,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
92
92
|
*
|
|
93
93
|
* @param ttl - If null is passed, the item will not expire.
|
|
94
94
|
*
|
|
95
|
-
* @returns true when key doesn't exists otherwise false will be returned.
|
|
95
|
+
* @returns Returns true when key doesn't exists otherwise false will be returned.
|
|
96
96
|
*/
|
|
97
97
|
add(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
|
|
98
98
|
/**
|
|
@@ -105,7 +105,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
105
105
|
*
|
|
106
106
|
* @param ttl - If null is passed, the item will not expire.
|
|
107
107
|
*
|
|
108
|
-
* @returns true if the `key` where replaced otherwise false is returned.
|
|
108
|
+
* @returns Returns true if the `key` where replaced otherwise false is returned.
|
|
109
109
|
*/
|
|
110
110
|
put(key: OneOrMore<string>, value: TType, ttl?: TimeSpan | null): LazyPromise<boolean>;
|
|
111
111
|
/**
|
|
@@ -115,7 +115,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
115
115
|
* If it's an `Iterable`, it will be joined into a single string.
|
|
116
116
|
* Think of an `Iterable` as representing a path.
|
|
117
117
|
*
|
|
118
|
-
* @returns true if the `key` where updated otherwise false will be returned.
|
|
118
|
+
* @returns Returns true if the `key` where updated otherwise false will be returned.
|
|
119
119
|
*/
|
|
120
120
|
update(key: OneOrMore<string>, value: TType): LazyPromise<boolean>;
|
|
121
121
|
/**
|
|
@@ -128,7 +128,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
128
128
|
*
|
|
129
129
|
* @param value - If not defined then it will be defaulted to 1.
|
|
130
130
|
*
|
|
131
|
-
* @returns true if the `key` where incremented otherwise false will be returned.
|
|
131
|
+
* @returns Returns true if the `key` where incremented otherwise false will be returned.
|
|
132
132
|
*
|
|
133
133
|
* @throws {TypeCacheError} {@link TypeCacheError}
|
|
134
134
|
*/
|
|
@@ -143,7 +143,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
143
143
|
*
|
|
144
144
|
* @param value - If not defined then it will be defaulted to 1.
|
|
145
145
|
*
|
|
146
|
-
* @returns true if the `key` where decremented otherwise false will be returned.
|
|
146
|
+
* @returns Returns true if the `key` where decremented otherwise false will be returned.
|
|
147
147
|
*
|
|
148
148
|
* @throws {TypeCacheError} {@link TypeCacheError}
|
|
149
149
|
*/
|
|
@@ -155,7 +155,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
155
155
|
* If it's an `Iterable`, it will be joined into a single string.
|
|
156
156
|
* Think of an `Iterable` as representing a path.
|
|
157
157
|
*
|
|
158
|
-
* @returns true if the key is found otherwise false is returned.
|
|
158
|
+
* @returns Returns true if the key is found otherwise false is returned.
|
|
159
159
|
*/
|
|
160
160
|
remove(key: OneOrMore<string>): LazyPromise<boolean>;
|
|
161
161
|
/**
|
|
@@ -165,7 +165,7 @@ export type ICacheBase<TType = unknown> = {
|
|
|
165
165
|
* If the param items are an `Iterable`, it will be joined into a single string.
|
|
166
166
|
* Think of an `Iterable` as representing a path.
|
|
167
167
|
*
|
|
168
|
-
* @returns true if one of the keys where deleted otherwise false is returned.
|
|
168
|
+
* @returns Returns true if one of the keys where deleted otherwise false is returned.
|
|
169
169
|
*/
|
|
170
170
|
removeMany(keys: Iterable<OneOrMore<string>>): LazyPromise<boolean>;
|
|
171
171
|
/**
|
|
@@ -1,25 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Cache
|
|
3
3
|
*/
|
|
4
|
-
import type { ISerderRegister, ISerializable } from "../../serde/contracts/_module-exports.js";
|
|
5
|
-
import { type ISerializedError, type OneOrMore } from "../../utilities/_module-exports.js";
|
|
6
4
|
/**
|
|
7
5
|
*
|
|
8
6
|
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
|
|
9
7
|
* @group Errors
|
|
10
8
|
*/
|
|
11
|
-
export declare class CacheError extends Error
|
|
12
|
-
static deserialize(deserializedValue: ISerializedError): CacheError;
|
|
13
|
-
constructor(message: string, cause?: unknown);
|
|
14
|
-
serialize(): ISerializedError;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
|
|
19
|
-
* @group Errors
|
|
20
|
-
*/
|
|
21
|
-
export declare class UnexpectedCacheError extends CacheError implements ISerializable<ISerializedError> {
|
|
22
|
-
static deserialize(deserializedValue: ISerializedError): CacheError;
|
|
9
|
+
export declare class CacheError extends Error {
|
|
23
10
|
constructor(message: string, cause?: unknown);
|
|
24
11
|
}
|
|
25
12
|
/**
|
|
@@ -28,8 +15,7 @@ export declare class UnexpectedCacheError extends CacheError implements ISeriali
|
|
|
28
15
|
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
|
|
29
16
|
* @group Errors
|
|
30
17
|
*/
|
|
31
|
-
export declare class TypeCacheError extends CacheError
|
|
32
|
-
static deserialize(deserializedValue: ISerializedError): CacheError;
|
|
18
|
+
export declare class TypeCacheError extends CacheError {
|
|
33
19
|
constructor(message: string, cause?: unknown);
|
|
34
20
|
}
|
|
35
21
|
/**
|
|
@@ -38,8 +24,7 @@ export declare class TypeCacheError extends CacheError implements ISerializable<
|
|
|
38
24
|
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
|
|
39
25
|
* @group Errors
|
|
40
26
|
*/
|
|
41
|
-
export declare class KeyNotFoundCacheError extends CacheError
|
|
42
|
-
static deserialize(deserializedValue: ISerializedError): CacheError;
|
|
27
|
+
export declare class KeyNotFoundCacheError extends CacheError {
|
|
43
28
|
constructor(message: string, cause?: unknown);
|
|
44
29
|
}
|
|
45
30
|
/**
|
|
@@ -49,14 +34,6 @@ export declare class KeyNotFoundCacheError extends CacheError implements ISerial
|
|
|
49
34
|
*/
|
|
50
35
|
export declare const CACHE_ERRORS: {
|
|
51
36
|
readonly Base: typeof CacheError;
|
|
52
|
-
readonly Unexpected: typeof UnexpectedCacheError;
|
|
53
37
|
readonly Type: typeof TypeCacheError;
|
|
54
38
|
readonly KeyNotFound: typeof KeyNotFoundCacheError;
|
|
55
39
|
};
|
|
56
|
-
/**
|
|
57
|
-
* The `registerCacheErrorsToSerde` function registers all {@link ICache | `ICache`} related errors with `ISerderRegister`, ensuring they will properly be serialized and deserialized.
|
|
58
|
-
*
|
|
59
|
-
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
|
|
60
|
-
* @group Errors
|
|
61
|
-
*/
|
|
62
|
-
export declare function registerCacheErrorsToSerde(serde: OneOrMore<ISerderRegister>): void;
|