@daiso-tech/core 0.34.0 → 0.35.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 +2 -4
- package/dist/async/_module-exports.d.ts +0 -1
- package/dist/async/_module-exports.js +0 -1
- package/dist/async/_module-exports.js.map +1 -1
- package/dist/async/async.errors.d.ts +19 -12
- package/dist/async/async.errors.js +27 -16
- package/dist/async/async.errors.js.map +1 -1
- package/dist/async/middlewares/_module.d.ts +3 -0
- package/dist/async/middlewares/_module.js +3 -0
- package/dist/async/middlewares/_module.js.map +1 -1
- package/dist/async/middlewares/_shared.d.ts +10 -0
- package/dist/async/middlewares/_shared.js +5 -0
- package/dist/async/middlewares/_shared.js.map +1 -0
- package/dist/async/middlewares/bulkhead/_module.d.ts +1 -0
- package/dist/async/middlewares/bulkhead/_module.js +2 -0
- package/dist/async/middlewares/bulkhead/_module.js.map +1 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +80 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js +46 -0
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.js.map +1 -0
- package/dist/async/middlewares/dynamic/dynamic.middleware.d.ts +2 -2
- package/dist/async/middlewares/dynamic/dynamic.middleware.js +5 -5
- package/dist/async/middlewares/dynamic/dynamic.middleware.js.map +1 -1
- package/dist/async/middlewares/fallback/fallback.middleware.d.ts +10 -8
- package/dist/async/middlewares/fallback/fallback.middleware.js +1 -1
- package/dist/async/middlewares/fallback/fallback.middleware.js.map +1 -1
- package/dist/async/middlewares/hedging/_module.d.ts +2 -0
- package/dist/async/middlewares/hedging/_module.js +3 -0
- package/dist/async/middlewares/hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/_shared.d.ts +93 -0
- package/dist/async/middlewares/hedging/_shared.js +5 -0
- package/dist/async/middlewares/hedging/_shared.js.map +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.d.ts +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js +2 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.d.ts +51 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js +138 -0
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js.map +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.d.ts +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js +2 -0
- package/dist/async/middlewares/hedging/sequential-hedging/_module.js.map +1 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.d.ts +51 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js +104 -0
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js.map +1 -0
- package/dist/async/middlewares/observe/observe.middleware.d.ts +14 -16
- package/dist/async/middlewares/observe/observe.middleware.js +1 -1
- package/dist/async/middlewares/observe/observe.middleware.js.map +1 -1
- package/dist/async/middlewares/retry/retry.middleware.d.ts +41 -36
- package/dist/async/middlewares/retry/retry.middleware.js +31 -28
- package/dist/async/middlewares/retry/retry.middleware.js.map +1 -1
- package/dist/async/middlewares/timeout/timeout.middleware.d.ts +34 -39
- package/dist/async/middlewares/timeout/timeout.middleware.js +30 -47
- package/dist/async/middlewares/timeout/timeout.middleware.js.map +1 -1
- package/dist/async/utilities/_module.d.ts +2 -0
- package/dist/async/utilities/_module.js +2 -0
- package/dist/async/utilities/_module.js.map +1 -1
- package/dist/async/utilities/abort-and-fail/abort-and-fail.d.ts +3 -0
- package/dist/async/utilities/abort-and-fail/abort-and-fail.js +6 -7
- package/dist/async/utilities/abort-and-fail/abort-and-fail.js.map +1 -1
- package/dist/async/utilities/lazy-promise/lazy-promise.js +0 -1
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/async/utilities/promise-queue/_module.d.ts +1 -0
- package/dist/async/utilities/promise-queue/_module.js +2 -0
- package/dist/async/utilities/promise-queue/_module.js.map +1 -0
- package/dist/async/utilities/promise-queue/promise-queue.d.ts +32 -0
- package/dist/async/utilities/promise-queue/promise-queue.js +107 -0
- package/dist/async/utilities/promise-queue/promise-queue.js.map +1 -0
- package/dist/async/utilities/timeout-and-fail/_module.d.ts +1 -0
- package/dist/async/utilities/timeout-and-fail/_module.js +2 -0
- package/dist/async/utilities/timeout-and-fail/_module.js.map +1 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.d.ts +7 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js +19 -0
- package/dist/async/utilities/timeout-and-fail/timeout-and-fail.js.map +1 -0
- package/dist/cache/contracts/cache.contract.d.ts +2 -2
- package/dist/cache/contracts/cache.events.d.ts +43 -47
- package/dist/cache/contracts/cache.events.js +5 -103
- package/dist/cache/contracts/cache.events.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +15 -15
- package/dist/cache/implementations/derivables/cache/cache.js +94 -79
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +138 -147
- package/dist/cache/implementations/test-utilities/cache.test-suite.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-adapter.contract.d.ts +6 -1
- package/dist/event-bus/contracts/event-bus-factory.contract.d.ts +2 -3
- package/dist/event-bus/contracts/event-bus-factory.contract.js.map +1 -1
- package/dist/event-bus/contracts/event-bus.contract.d.ts +12 -23
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +10 -10
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +30 -30
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +13 -7
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +11 -5
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.d.ts +0 -2
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +13 -20
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.d.ts +0 -2
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +187 -207
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/lock/contracts/lock-provider.contract.d.ts +2 -2
- package/dist/lock/contracts/lock.events.d.ts +35 -44
- package/dist/lock/contracts/lock.events.js +8 -90
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +9 -9
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +12 -12
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider/lock.js +69 -50
- 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 +1 -1
- 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 +212 -212
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/contracts/flexible-serde.contract.d.ts +0 -11
- package/dist/serde/implementations/derivables/serde.d.ts +1 -32
- package/dist/serde/implementations/derivables/serde.js +0 -45
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/utilities/classes/hooks/async-hooks.d.ts +107 -20
- package/dist/utilities/classes/hooks/async-hooks.js +47 -18
- package/dist/utilities/classes/hooks/async-hooks.js.map +1 -1
- package/dist/utilities/classes/hooks/hooks.d.ts +39 -21
- package/dist/utilities/classes/hooks/hooks.js +19 -18
- package/dist/utilities/classes/hooks/hooks.js.map +1 -1
- package/dist/utilities/classes/key-prefixer/key-prefixer.js +2 -2
- package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +1 -1
- package/dist/utilities/contracts/_module.d.ts +0 -1
- package/dist/utilities/contracts/_module.js +0 -1
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/functions/invokable.d.ts +9 -5
- package/dist/utilities/functions/invokable.js +10 -0
- package/dist/utilities/functions/invokable.js.map +1 -1
- package/package.json +22 -2
- package/dist/async/async.events.d.ts +0 -105
- package/dist/async/async.events.js +0 -82
- package/dist/async/async.events.js.map +0 -1
- package/dist/event-bus/contracts/_shared.d.ts +0 -12
- package/dist/event-bus/contracts/_shared.js +0 -15
- package/dist/event-bus/contracts/_shared.js.map +0 -1
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -34
- package/dist/test.js.map +0 -1
- package/dist/utilities/contracts/sync-event-bus-listenable.d.ts +0 -13
- package/dist/utilities/contracts/sync-event-bus-listenable.js +0 -5
- package/dist/utilities/contracts/sync-event-bus-listenable.js.map +0 -1
|
@@ -3,6 +3,67 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { type IInvokableObject, type Invokable, type InvokableFn, type OneOrMore, type Promisable } from "../../../utilities/_module-exports.js";
|
|
5
5
|
import type { HookContext } from "../../../utilities/classes/hooks/types.js";
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
9
|
+
* @group Hooks
|
|
10
|
+
*/
|
|
11
|
+
export type GetSignal<TParameters extends unknown[] = unknown[]> = Invokable<[
|
|
12
|
+
arguments_: TParameters
|
|
13
|
+
], AbortSignal | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
17
|
+
* @group Hooks
|
|
18
|
+
*/
|
|
19
|
+
export type ForwardSignal<TParameters> = Invokable<[
|
|
20
|
+
arguments_: TParameters,
|
|
21
|
+
signal: AbortSignal
|
|
22
|
+
], void>;
|
|
23
|
+
/**
|
|
24
|
+
* With {@link AbortSignalBinder | `AbortSignalBinder`}, you can bind an {@link AbortSignal | `AbortSignal`} to the middleware, enabling two-way abortion control.
|
|
25
|
+
* This means the middleware can abort the function, or the function can abort the middleware if the input function supports an {@link AbortSignal | `AbortSignal`}.
|
|
26
|
+
*
|
|
27
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
28
|
+
* @group Hooks
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { AsyncHooks } from "@daiso-tech/core/utilities";
|
|
33
|
+
*
|
|
34
|
+
* const abortController = new AbortController();
|
|
35
|
+
*
|
|
36
|
+
* // You can abort the function based on by your on criteria
|
|
37
|
+
* abortController.abort("Aborted") // Remove this code if you want the function to aborted after 2 seconds by the middleware.
|
|
38
|
+
*
|
|
39
|
+
* const data = await new AsyncHooks(async (url: string, signal?: AbortSignal): Promise<unknown> => {
|
|
40
|
+
* const response = await fetch(url, { signal });
|
|
41
|
+
* return await response.json();
|
|
42
|
+
* }, [
|
|
43
|
+
* (args, next, { abort, signal }) => {
|
|
44
|
+
* // We abort the function when it execdes 2 seconds.
|
|
45
|
+
* const id = setTimeout(() => abort("Timed out"), 2000);
|
|
46
|
+
* // We remove the timeout if function is aborted before it execdes 2 seconds.
|
|
47
|
+
* signal.addEventListener("abort", () => clearTimeout(id), { once: true });
|
|
48
|
+
* return next(...args);
|
|
49
|
+
* }
|
|
50
|
+
* ], {
|
|
51
|
+
* signalBinder: {
|
|
52
|
+
* getSignal: (args) => args[1],
|
|
53
|
+
* forwardSignal: (args, signal) => {
|
|
54
|
+
* args[1] = signal;
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* })
|
|
58
|
+
* .invoke("url", abortController.signal);
|
|
59
|
+
*
|
|
60
|
+
* console.log("DATA:", data)
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export type AbortSignalBinder<TParameters extends unknown[] = unknown[]> = {
|
|
64
|
+
getSignal: GetSignal<TParameters>;
|
|
65
|
+
forwardSignal: ForwardSignal<TParameters>;
|
|
66
|
+
};
|
|
6
67
|
/**
|
|
7
68
|
*
|
|
8
69
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
@@ -14,27 +75,59 @@ export type AsyncNextFunc<TParameters extends unknown[] = unknown[], TReturn = u
|
|
|
14
75
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
15
76
|
* @group Hooks
|
|
16
77
|
*/
|
|
17
|
-
export type
|
|
78
|
+
export type AsyncContext<TContext extends HookContext = HookContext> = {
|
|
79
|
+
name: string;
|
|
80
|
+
context: TContext;
|
|
81
|
+
abort: (error: unknown) => void;
|
|
82
|
+
signal: AbortSignal;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
87
|
+
* @group Hooks
|
|
88
|
+
*/
|
|
89
|
+
export type AsyncMiddlewareFn<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = InvokableFn<[
|
|
18
90
|
arguments_: TParameters,
|
|
19
91
|
next: AsyncNextFunc<TParameters, TReturn>,
|
|
20
|
-
|
|
92
|
+
settings: AsyncContext<TContext>
|
|
21
93
|
], Promisable<TReturn>>;
|
|
22
94
|
/**
|
|
23
95
|
*
|
|
24
96
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
25
97
|
* @group Hooks
|
|
26
98
|
*/
|
|
27
|
-
export type IAsyncMiddlewareObject<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext =
|
|
99
|
+
export type IAsyncMiddlewareObject<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = IInvokableObject<[
|
|
28
100
|
arguments_: TParameters,
|
|
29
101
|
next: AsyncNextFunc<TParameters, TReturn>,
|
|
30
|
-
|
|
102
|
+
settings: AsyncContext<TContext>
|
|
31
103
|
], Promisable<TReturn>>;
|
|
32
104
|
/**
|
|
33
105
|
*
|
|
34
106
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
35
107
|
* @group Hooks
|
|
36
108
|
*/
|
|
37
|
-
export type AsyncMiddleware<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext =
|
|
109
|
+
export type AsyncMiddleware<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = IAsyncMiddlewareObject<TParameters, TReturn, TContext> | AsyncMiddlewareFn<TParameters, TReturn, TContext>;
|
|
110
|
+
/**
|
|
111
|
+
*
|
|
112
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
113
|
+
* @group Hooks
|
|
114
|
+
*/
|
|
115
|
+
export type AsyncHooksSettings<TParameters extends unknown[] = unknown[], TContext extends HookContext = HookContext> = {
|
|
116
|
+
/**
|
|
117
|
+
* The name of the function which can be used for logging inside the middleware.
|
|
118
|
+
* By default, it takes the function or method name. If an anonymous function is provided, the name defaults to "func".
|
|
119
|
+
*/
|
|
120
|
+
name?: string;
|
|
121
|
+
/**
|
|
122
|
+
* If the input function accepts an {@link AbortSignal | `AbortSignal`}, you can bind it to the middleware by providing an {@link AbortSignalBinder | `AbortSignalBinder`}.
|
|
123
|
+
* This enables two-way abortion control: you can either abort the function from within the middleware, or abort the middleware from the function itself.
|
|
124
|
+
*/
|
|
125
|
+
signalBinder?: AbortSignalBinder<TParameters>;
|
|
126
|
+
/**
|
|
127
|
+
* You can provide addtional context that can be used in the middleware.
|
|
128
|
+
*/
|
|
129
|
+
context?: TContext;
|
|
130
|
+
};
|
|
38
131
|
/**
|
|
39
132
|
* The `AsyncHooks` class provides a convenient way to change and inspect arguments and return value of both async and sync functions.
|
|
40
133
|
* For example `AsyncHooks` class can be used to log function arguments and return values. Note this class will always return promise and is immutable.
|
|
@@ -45,10 +138,9 @@ export type AsyncMiddleware<TParameters extends unknown[] = unknown[], TReturn =
|
|
|
45
138
|
export declare class AsyncHooks<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> implements IInvokableObject<TParameters, Promise<TReturn>> {
|
|
46
139
|
private readonly invokable;
|
|
47
140
|
private readonly middlewares;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
private readonly context;
|
|
141
|
+
private readonly settings;
|
|
142
|
+
private static defaultAbortSignalBinder;
|
|
143
|
+
private static resolveSignalBinder;
|
|
52
144
|
private static init;
|
|
53
145
|
private readonly func;
|
|
54
146
|
/**
|
|
@@ -56,8 +148,8 @@ export declare class AsyncHooks<TParameters extends unknown[] = unknown[], TRetu
|
|
|
56
148
|
* ```ts
|
|
57
149
|
* import { AsyncHooks, type AsyncMiddlewareFn } from "@daiso-tech/core/utilities";
|
|
58
150
|
*
|
|
59
|
-
* function log<TParameters extends unknown[], TReturn>(): AsyncMiddlewareFn<TParameters, TReturn
|
|
60
|
-
* return async (args, next, { funcName }) => {
|
|
151
|
+
* function log<TParameters extends unknown[], TReturn>(): AsyncMiddlewareFn<TParameters, TReturn> {
|
|
152
|
+
* return async (args, next, { name: funcName }) => {
|
|
61
153
|
* console.log("FUNCTION_NAME:", funcName);
|
|
62
154
|
* console.log("ARGUMENTS:", args);
|
|
63
155
|
* const value = await next(...args);
|
|
@@ -84,10 +176,9 @@ export declare class AsyncHooks<TParameters extends unknown[] = unknown[], TRetu
|
|
|
84
176
|
* const enhancedAdd = new AsyncHooks(add, [
|
|
85
177
|
* log(),
|
|
86
178
|
* time()
|
|
87
|
-
* ],
|
|
88
|
-
*
|
|
89
|
-
* {
|
|
90
|
-
* funcName: add.name
|
|
179
|
+
* ], {
|
|
180
|
+
* // You can provide addtional data to be used the middleware.
|
|
181
|
+
* context: {},
|
|
91
182
|
* });
|
|
92
183
|
*
|
|
93
184
|
* // Will log the function name, arguments and return value.
|
|
@@ -98,11 +189,7 @@ export declare class AsyncHooks<TParameters extends unknown[] = unknown[], TRetu
|
|
|
98
189
|
* console.log(result);
|
|
99
190
|
* ```
|
|
100
191
|
*/
|
|
101
|
-
constructor(invokable: Invokable<TParameters, Promisable<TReturn>>, middlewares: NoInfer<OneOrMore<AsyncMiddleware<TParameters, TReturn, TContext>>>,
|
|
102
|
-
/**
|
|
103
|
-
* You can pass in additional information that can be used by the middleware.
|
|
104
|
-
*/
|
|
105
|
-
context?: TContext);
|
|
192
|
+
constructor(invokable: Invokable<TParameters, Promisable<TReturn>>, middlewares: NoInfer<OneOrMore<AsyncMiddleware<TParameters, TReturn, TContext>>>, settings?: AsyncHooksSettings<TParameters, TContext>);
|
|
106
193
|
/**
|
|
107
194
|
* The `pipe` method returns a new `AsyncHooks` instance with the additional `middlewares` applied.
|
|
108
195
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Utilities
|
|
3
3
|
*/
|
|
4
|
-
import { resolveInvokable, resolveOneOrMore, } from "../../../utilities/_module-exports.js";
|
|
4
|
+
import { callInvokable, getInvokableName, resolveInvokable, resolveOneOrMore, } from "../../../utilities/_module-exports.js";
|
|
5
5
|
/**
|
|
6
6
|
* The `AsyncHooks` class provides a convenient way to change and inspect arguments and return value of both async and sync functions.
|
|
7
7
|
* For example `AsyncHooks` class can be used to log function arguments and return values. Note this class will always return promise and is immutable.
|
|
@@ -12,15 +12,49 @@ import { resolveInvokable, resolveOneOrMore, } from "../../../utilities/_module-
|
|
|
12
12
|
export class AsyncHooks {
|
|
13
13
|
invokable;
|
|
14
14
|
middlewares;
|
|
15
|
-
|
|
16
|
-
static
|
|
15
|
+
settings;
|
|
16
|
+
static defaultAbortSignalBinder() {
|
|
17
|
+
return {
|
|
18
|
+
forwardSignal: (args) => args,
|
|
19
|
+
getSignal: () => new AbortController().signal,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
static resolveSignalBinder(signalBinder, args) {
|
|
23
|
+
const outerSignal = callInvokable(signalBinder.getSignal, args) ??
|
|
24
|
+
new AbortController().signal;
|
|
25
|
+
const abortController = new AbortController();
|
|
26
|
+
const abort = (reason) => {
|
|
27
|
+
abortController.abort(reason);
|
|
28
|
+
};
|
|
29
|
+
const mergedSignal = AbortSignal.any([
|
|
30
|
+
outerSignal,
|
|
31
|
+
abortController.signal,
|
|
32
|
+
]);
|
|
33
|
+
callInvokable(signalBinder.forwardSignal, args, mergedSignal);
|
|
34
|
+
return {
|
|
35
|
+
abort,
|
|
36
|
+
changedArgs: args,
|
|
37
|
+
signal: mergedSignal,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
static init(invokable, middlewares, { name = getInvokableName(invokable), signalBinder = AsyncHooks.defaultAbortSignalBinder(), context = {}, }) {
|
|
17
41
|
let func = resolveInvokable(invokable);
|
|
18
42
|
for (const hook of resolveOneOrMore(middlewares)
|
|
19
43
|
.map(resolveInvokable)
|
|
20
44
|
.reverse()) {
|
|
21
45
|
const prevFunc = func;
|
|
22
46
|
const next = async (...arguments_) => await prevFunc(...arguments_);
|
|
23
|
-
func = async (...arguments_) =>
|
|
47
|
+
func = async (...arguments_) => {
|
|
48
|
+
const resolvedSignalBinder = AsyncHooks.resolveSignalBinder(signalBinder, arguments_);
|
|
49
|
+
return await hook(resolvedSignalBinder.changedArgs, next, {
|
|
50
|
+
name,
|
|
51
|
+
abort: (error) => {
|
|
52
|
+
resolvedSignalBinder.abort(error);
|
|
53
|
+
},
|
|
54
|
+
signal: resolvedSignalBinder.signal,
|
|
55
|
+
context,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
24
58
|
}
|
|
25
59
|
return func;
|
|
26
60
|
}
|
|
@@ -30,8 +64,8 @@ export class AsyncHooks {
|
|
|
30
64
|
* ```ts
|
|
31
65
|
* import { AsyncHooks, type AsyncMiddlewareFn } from "@daiso-tech/core/utilities";
|
|
32
66
|
*
|
|
33
|
-
* function log<TParameters extends unknown[], TReturn>(): AsyncMiddlewareFn<TParameters, TReturn
|
|
34
|
-
* return async (args, next, { funcName }) => {
|
|
67
|
+
* function log<TParameters extends unknown[], TReturn>(): AsyncMiddlewareFn<TParameters, TReturn> {
|
|
68
|
+
* return async (args, next, { name: funcName }) => {
|
|
35
69
|
* console.log("FUNCTION_NAME:", funcName);
|
|
36
70
|
* console.log("ARGUMENTS:", args);
|
|
37
71
|
* const value = await next(...args);
|
|
@@ -58,10 +92,9 @@ export class AsyncHooks {
|
|
|
58
92
|
* const enhancedAdd = new AsyncHooks(add, [
|
|
59
93
|
* log(),
|
|
60
94
|
* time()
|
|
61
|
-
* ],
|
|
62
|
-
*
|
|
63
|
-
* {
|
|
64
|
-
* funcName: add.name
|
|
95
|
+
* ], {
|
|
96
|
+
* // You can provide addtional data to be used the middleware.
|
|
97
|
+
* context: {},
|
|
65
98
|
* });
|
|
66
99
|
*
|
|
67
100
|
* // Will log the function name, arguments and return value.
|
|
@@ -72,15 +105,11 @@ export class AsyncHooks {
|
|
|
72
105
|
* console.log(result);
|
|
73
106
|
* ```
|
|
74
107
|
*/
|
|
75
|
-
constructor(invokable, middlewares,
|
|
76
|
-
/**
|
|
77
|
-
* You can pass in additional information that can be used by the middleware.
|
|
78
|
-
*/
|
|
79
|
-
context = {}) {
|
|
108
|
+
constructor(invokable, middlewares, settings = {}) {
|
|
80
109
|
this.invokable = invokable;
|
|
81
110
|
this.middlewares = middlewares;
|
|
82
|
-
this.
|
|
83
|
-
this.func = AsyncHooks.init(invokable, middlewares,
|
|
111
|
+
this.settings = settings;
|
|
112
|
+
this.func = AsyncHooks.init(invokable, middlewares, this.settings);
|
|
84
113
|
}
|
|
85
114
|
/**
|
|
86
115
|
* The `pipe` method returns a new `AsyncHooks` instance with the additional `middlewares` applied.
|
|
@@ -89,7 +118,7 @@ export class AsyncHooks {
|
|
|
89
118
|
return new AsyncHooks(this.invokable, [
|
|
90
119
|
...resolveOneOrMore(this.middlewares),
|
|
91
120
|
...resolveOneOrMore(middlewares),
|
|
92
|
-
], this.
|
|
121
|
+
], this.settings);
|
|
93
122
|
}
|
|
94
123
|
/**
|
|
95
124
|
* The `pipeWhen` method conditionally applies additional `middlewares`, returning a new `AsyncHooks` instance only if the specified condition is met.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-hooks.js","sourceRoot":"","sources":["../../../../src/utilities/classes/hooks/async-hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,gBAAgB,EAChB,gBAAgB,GAMnB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"async-hooks.js","sourceRoot":"","sources":["../../../../src/utilities/classes/hooks/async-hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GAMnB,MAAM,gCAAgC,CAAC;AAsKxC;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IA6HE;IACA;IAGA;IA3Hb,MAAM,CAAC,wBAAwB;QAGnC,OAAO;YACH,aAAa,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI;YAC7B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC,MAAM;SAChD,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAC9B,YAA4C,EAC5C,IAAiB;QAEjB,MAAM,WAAW,GACb,aAAa,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC;YAC3C,IAAI,eAAe,EAAE,CAAC,MAAM,CAAC;QACjC,MAAM,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ilities
|
|
3
3
|
*/
|
|
4
4
|
import { type IInvokableObject, type Invokable, type InvokableFn, type OneOrMore } from "../../../utilities/_module-exports.js";
|
|
5
|
+
import type { HookContext } from "../../../utilities/classes/hooks/types.js";
|
|
5
6
|
/**
|
|
6
7
|
*
|
|
7
8
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
@@ -13,41 +14,63 @@ export type NextFunc<TParameters extends unknown[] = unknown[], TReturn = unknow
|
|
|
13
14
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
14
15
|
* @group Hooks
|
|
15
16
|
*/
|
|
16
|
-
export type
|
|
17
|
+
export type Context<TContext extends HookContext = HookContext> = {
|
|
18
|
+
name: string;
|
|
19
|
+
context: TContext;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
24
|
+
* @group Hooks
|
|
25
|
+
*/
|
|
26
|
+
export type MiddlewareFn<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = InvokableFn<[
|
|
17
27
|
arguments_: TParameters,
|
|
18
28
|
next: NextFunc<TParameters, TReturn>,
|
|
19
|
-
|
|
29
|
+
settings: Context<TContext>
|
|
20
30
|
], TReturn>;
|
|
21
31
|
/**
|
|
22
32
|
*
|
|
23
33
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
24
34
|
* @group Hooks
|
|
25
35
|
*/
|
|
26
|
-
export type IMiddlewareObject<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext =
|
|
36
|
+
export type IMiddlewareObject<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = IInvokableObject<[
|
|
27
37
|
arguments_: TParameters,
|
|
28
38
|
next: NextFunc<TParameters, TReturn>,
|
|
29
|
-
|
|
39
|
+
settings: Context<TContext>
|
|
30
40
|
], TReturn>;
|
|
31
41
|
/**
|
|
32
42
|
*
|
|
33
43
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
34
44
|
* @group Hooks
|
|
35
45
|
*/
|
|
36
|
-
export type Middleware<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext =
|
|
46
|
+
export type Middleware<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> = IMiddlewareObject<TParameters, TReturn, TContext> | MiddlewareFn<TParameters, TReturn, TContext>;
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
50
|
+
* @group Hooks
|
|
51
|
+
*/
|
|
52
|
+
export type HooksSettings<TContext extends HookContext = HookContext> = {
|
|
53
|
+
/**
|
|
54
|
+
* The name of the function which can be used for logging inside the middleware.
|
|
55
|
+
* By default, it takes the function or method name. If an anonymous function is provided, the name defaults to "func".
|
|
56
|
+
*/
|
|
57
|
+
name?: string;
|
|
58
|
+
/**
|
|
59
|
+
* You can provide addtional context that can be used in the middleware.
|
|
60
|
+
*/
|
|
61
|
+
context?: TContext;
|
|
62
|
+
};
|
|
37
63
|
/**
|
|
38
64
|
* The `Hooks` class provides a convenient way to change and inspect arguments and return value of both only sync functions.
|
|
39
|
-
* For example `Hooks` class can be used to log function arguments and return values. Note this class will always return
|
|
65
|
+
* For example `Hooks` class can be used to log function arguments and return values. Note this class will always return promise and is immutable.
|
|
40
66
|
*
|
|
41
67
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
42
68
|
* @group Hooks
|
|
43
69
|
*/
|
|
44
|
-
export declare class Hooks<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends
|
|
70
|
+
export declare class Hooks<TParameters extends unknown[] = unknown[], TReturn = unknown, TContext extends HookContext = HookContext> implements IInvokableObject<TParameters, TReturn> {
|
|
45
71
|
private readonly invokable;
|
|
46
72
|
private readonly middlewares;
|
|
47
|
-
|
|
48
|
-
* You can pass in additional information that can be used by the middleware.
|
|
49
|
-
*/
|
|
50
|
-
private readonly context;
|
|
73
|
+
private readonly settings;
|
|
51
74
|
private static init;
|
|
52
75
|
private readonly func;
|
|
53
76
|
/**
|
|
@@ -56,7 +79,7 @@ export declare class Hooks<TParameters extends unknown[] = unknown[], TReturn =
|
|
|
56
79
|
* import { Hooks, type MiddlewareFn } from "@daiso-tech/core/utilities";
|
|
57
80
|
*
|
|
58
81
|
* function log<TParameters extends unknown[], TReturn>(): MiddlewareFn<TParameters, TReturn, { funcName: string; }> {
|
|
59
|
-
* return (args, next, { funcName }) => {
|
|
82
|
+
* return (args, next, { name: funcName }) => {
|
|
60
83
|
* console.log("FUNCTION_NAME:", funcName);
|
|
61
84
|
* console.log("ARGUMENTS:", args);
|
|
62
85
|
* const value = next(...args);
|
|
@@ -83,10 +106,9 @@ export declare class Hooks<TParameters extends unknown[] = unknown[], TReturn =
|
|
|
83
106
|
* const enhancedAdd = new Hooks(add, [
|
|
84
107
|
* log(),
|
|
85
108
|
* time()
|
|
86
|
-
* ],
|
|
87
|
-
*
|
|
88
|
-
* {
|
|
89
|
-
* funcName: add.name
|
|
109
|
+
* ], {
|
|
110
|
+
* // You can provide addtional data to be used the middleware.
|
|
111
|
+
* context: {},
|
|
90
112
|
* });
|
|
91
113
|
*
|
|
92
114
|
* // Will log the function name, arguments and return value.
|
|
@@ -97,11 +119,7 @@ export declare class Hooks<TParameters extends unknown[] = unknown[], TReturn =
|
|
|
97
119
|
* console.log(result);
|
|
98
120
|
* ```
|
|
99
121
|
*/
|
|
100
|
-
constructor(invokable: Invokable<TParameters, TReturn>, middlewares: NoInfer<OneOrMore<Middleware<TParameters, TReturn, TContext>>>,
|
|
101
|
-
/**
|
|
102
|
-
* You can pass in additional information that can be used by the middleware.
|
|
103
|
-
*/
|
|
104
|
-
context?: TContext);
|
|
122
|
+
constructor(invokable: Invokable<TParameters, TReturn>, middlewares: NoInfer<OneOrMore<Middleware<TParameters, TReturn, TContext>>>, settings?: HooksSettings<TContext>);
|
|
105
123
|
/**
|
|
106
124
|
* The `pipe` method returns a new `Hooks` instance with the additional `middlewares` applied.
|
|
107
125
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Utilities
|
|
3
3
|
*/
|
|
4
|
-
import { resolveInvokable, resolveOneOrMore, } from "../../../utilities/_module-exports.js";
|
|
4
|
+
import { getInvokableName, resolveInvokable, resolveOneOrMore, } from "../../../utilities/_module-exports.js";
|
|
5
5
|
/**
|
|
6
6
|
* The `Hooks` class provides a convenient way to change and inspect arguments and return value of both only sync functions.
|
|
7
|
-
* For example `Hooks` class can be used to log function arguments and return values. Note this class will always return
|
|
7
|
+
* For example `Hooks` class can be used to log function arguments and return values. Note this class will always return promise and is immutable.
|
|
8
8
|
*
|
|
9
9
|
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
|
|
10
10
|
* @group Hooks
|
|
@@ -12,14 +12,20 @@ import { resolveInvokable, resolveOneOrMore, } from "../../../utilities/_module-
|
|
|
12
12
|
export class Hooks {
|
|
13
13
|
invokable;
|
|
14
14
|
middlewares;
|
|
15
|
-
|
|
16
|
-
static init(invokable, middlewares, context) {
|
|
15
|
+
settings;
|
|
16
|
+
static init(invokable, middlewares, { name = getInvokableName(invokable), context = {}, }) {
|
|
17
17
|
let func = resolveInvokable(invokable);
|
|
18
18
|
for (const hook of resolveOneOrMore(middlewares)
|
|
19
19
|
.map(resolveInvokable)
|
|
20
20
|
.reverse()) {
|
|
21
21
|
const prevFunc = func;
|
|
22
|
-
|
|
22
|
+
const next = (...arguments_) => prevFunc(...arguments_);
|
|
23
|
+
func = (...arguments_) => {
|
|
24
|
+
return hook(arguments_, next, {
|
|
25
|
+
name,
|
|
26
|
+
context,
|
|
27
|
+
});
|
|
28
|
+
};
|
|
23
29
|
}
|
|
24
30
|
return func;
|
|
25
31
|
}
|
|
@@ -30,7 +36,7 @@ export class Hooks {
|
|
|
30
36
|
* import { Hooks, type MiddlewareFn } from "@daiso-tech/core/utilities";
|
|
31
37
|
*
|
|
32
38
|
* function log<TParameters extends unknown[], TReturn>(): MiddlewareFn<TParameters, TReturn, { funcName: string; }> {
|
|
33
|
-
* return (args, next, { funcName }) => {
|
|
39
|
+
* return (args, next, { name: funcName }) => {
|
|
34
40
|
* console.log("FUNCTION_NAME:", funcName);
|
|
35
41
|
* console.log("ARGUMENTS:", args);
|
|
36
42
|
* const value = next(...args);
|
|
@@ -57,10 +63,9 @@ export class Hooks {
|
|
|
57
63
|
* const enhancedAdd = new Hooks(add, [
|
|
58
64
|
* log(),
|
|
59
65
|
* time()
|
|
60
|
-
* ],
|
|
61
|
-
*
|
|
62
|
-
* {
|
|
63
|
-
* funcName: add.name
|
|
66
|
+
* ], {
|
|
67
|
+
* // You can provide addtional data to be used the middleware.
|
|
68
|
+
* context: {},
|
|
64
69
|
* });
|
|
65
70
|
*
|
|
66
71
|
* // Will log the function name, arguments and return value.
|
|
@@ -71,15 +76,11 @@ export class Hooks {
|
|
|
71
76
|
* console.log(result);
|
|
72
77
|
* ```
|
|
73
78
|
*/
|
|
74
|
-
constructor(invokable, middlewares,
|
|
75
|
-
/**
|
|
76
|
-
* You can pass in additional information that can be used by the middleware.
|
|
77
|
-
*/
|
|
78
|
-
context = {}) {
|
|
79
|
+
constructor(invokable, middlewares, settings = {}) {
|
|
79
80
|
this.invokable = invokable;
|
|
80
81
|
this.middlewares = middlewares;
|
|
81
|
-
this.
|
|
82
|
-
this.func = Hooks.init(invokable, middlewares,
|
|
82
|
+
this.settings = settings;
|
|
83
|
+
this.func = Hooks.init(invokable, middlewares, this.settings);
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
86
|
* The `pipe` method returns a new `Hooks` instance with the additional `middlewares` applied.
|
|
@@ -88,7 +89,7 @@ export class Hooks {
|
|
|
88
89
|
return new Hooks(this.invokable, [
|
|
89
90
|
...resolveOneOrMore(this.middlewares),
|
|
90
91
|
...resolveOneOrMore(middlewares),
|
|
91
|
-
], this.
|
|
92
|
+
], this.settings);
|
|
92
93
|
}
|
|
93
94
|
/**
|
|
94
95
|
* The `pipeWhen` method conditionally applies additional `middlewares`, returning a new `Hooks` instance only if the specified condition is met.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../../src/utilities/classes/hooks/hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,gBAAgB,EAChB,gBAAgB,GAKnB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../../src/utilities/classes/hooks/hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GAKnB,MAAM,gCAAgC,CAAC;AA0FxC;;;;;;GAMG;AACH,MAAM,OAAO,KAAK;IAoFO;IACA;IAGA;IAlFb,MAAM,CAAC,IAAI,CAKf,SAA0C,EAC1C,WAAkE,EAClE,EACI,IAAI,GAAG,gBAAgB,CAAC,SAAS,CAAC,EAClC,OAAO,GAAG,EAAc,GACF;QAE1B,IAAI,IAAI,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACvC,KAAK,MAAM,IAAI,IAAI,gBAAgB,CAAC,WAAW,CAAC;aAC3C,GAAG,CAAC,gBAAgB,CAAC;aACrB,OAAO,EAAE,EAAE,CAAC;YACb,MAAM,QAAQ,GAAG,IAAI,CAAC;YACtB,MAAM,IAAI,GAAG,CAAC,GAAG,UAAuB,EAAE,EAAE,CACxC,QAAQ,CAAC,GAAG,UAAU,CAAC,CAAC;YAC5B,IAAI,GAAG,CAAC,GAAG,UAAuB,EAAE,EAAE;gBAClC,OAAO,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE;oBAC1B,IAAI;oBACJ,OAAO;iBACV,CAAC,CAAC;YACP,CAAC,CAAC;QACN,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAEgB,IAAI,CAAoC;IAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACH,YACqB,SAA0C,EAC1C,WAEhB,EACgB,WAAoC,EAAE;QAJtC,cAAS,GAAT,SAAS,CAAiC;QAC1C,gBAAW,GAAX,WAAW,CAE3B;QACgB,aAAQ,GAAR,QAAQ,CAA8B;QAEvD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,IAAI,CACA,WAAkE;QAElE,OAAO,IAAI,KAAK,CACZ,IAAI,CAAC,SAAS,EACd;YACI,GAAG,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC;YACrC,GAAG,gBAAgB,CAAC,WAAW,CAAC;SACnC,EACD,IAAI,CAAC,QAAQ,CAChB,CAAC;IACN,CAAC;IAED;;OAEG;IACH,QAAQ,CACJ,SAAkB,EAClB,WAAkE;QAElE,IAAI,SAAS,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,MAAM;QACF,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,GAAG,UAAuB;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;IACpC,CAAC;CACJ"}
|
|
@@ -65,10 +65,10 @@ export class KeyPrefixer {
|
|
|
65
65
|
validate(key) {
|
|
66
66
|
const resolvedKey = resolveOneOrMoreStr(key);
|
|
67
67
|
if (resolvedKey.includes(this.rootIdentifier)) {
|
|
68
|
-
throw new Error("
|
|
68
|
+
throw new Error(`Resolved key "${resolvedKey}" cannot not include "${this.rootIdentifier}"`);
|
|
69
69
|
}
|
|
70
70
|
if (resolvedKey.includes(this.keyIdentifier)) {
|
|
71
|
-
throw new Error("
|
|
71
|
+
throw new Error(`Resolved key "${resolvedKey}" cannot not include "${this.keyIdentifier}"`);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
getKeyPrefixArray() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-prefixer.js","sourceRoot":"","sources":["../../../../src/utilities/classes/key-prefixer/key-prefixer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAatE;;;;GAIG;AACH,MAAM,OAAO,GAAG;IACK,SAAS,CAAqB;IAC9B,GAAG,CAAoB;IACvB,mBAAmB,CAAS;IAC5B,YAAY,CAAS;IAEtC;;;OAGG;IACH,YAAY,QAAqB;QAC7B,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,mBAAmB,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC;QACvE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,mBAAmB,CACtB;YACI,GAAG,IAAI,CAAC,SAAS;YACjB,mBAAmB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC;SACnD,EACD,IAAI,CAAC,mBAAmB,CAC3B,CAAC;IACN,CAAC;CACJ;AAeD;;;;GAIG;AACH,MAAM,OAAO,WAAW;IAOC;IANJ,mBAAmB,CAAS;IAC5B,YAAY,CAAS;IACrB,cAAc,CAAS;IACvB,aAAa,C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AC;IACjD,CAAC;IAEO,QAAQ,CAAC,GAAsB;QACnC,MAAM,WAAW,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAC7C,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CACX,iBAAiB,WAAW,yBAAyB,IAAI,CAAC,cAAc,GAAG,CAC9E,CAAC;QACN,CAAC;QACD,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,CACX,iBAAiB,WAAW,yBAAyB,IAAI,CAAC,aAAa,GAAG,CAC7E,CAAC;QACN,CAAC;IACL,CAAC;IAEO,iBAAiB;QACrB,OAAO;YACH,mBAAmB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC;YACxD,IAAI,CAAC,cAAc;SACtB,CAAC;IACN,CAAC;IAED,IAAI,SAAS;QACT,OAAO,mBAAmB,CACtB,IAAI,CAAC,iBAAiB,EAAE,EACxB,IAAI,CAAC,mBAAmB,CAC3B,CAAC;IACN,CAAC;IAED,MAAM,CAAC,GAAsB;QACzB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,IAAI,GAAG,CAAC;YACX,GAAG;YACH,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;YAC7C,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE;SACtC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -3,4 +3,3 @@ export * from "../../utilities/contracts/initizable.contract.js";
|
|
|
3
3
|
export * from "../../utilities/contracts/prunable.contract.js";
|
|
4
4
|
export * from "../../utilities/contracts/serialized-error.contract.js";
|
|
5
5
|
export * from "../../utilities/contracts/sqlite-database.contract.js";
|
|
6
|
-
export * from "../../utilities/contracts/sync-event-bus-listenable.js";
|
|
@@ -3,5 +3,4 @@ export * from "../../utilities/contracts/initizable.contract.js";
|
|
|
3
3
|
export * from "../../utilities/contracts/prunable.contract.js";
|
|
4
4
|
export * from "../../utilities/contracts/serialized-error.contract.js";
|
|
5
5
|
export * from "../../utilities/contracts/sqlite-database.contract.js";
|
|
6
|
-
export * from "../../utilities/contracts/sync-event-bus-listenable.js";
|
|
7
6
|
//# sourceMappingURL=_module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/utilities/contracts/_module.ts"],"names":[],"mappings":"AAAA,cAAc,gDAAgD,CAAC;AAC/D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,4CAA4C,CAAC;AAC3D,cAAc,oDAAoD,CAAC;AACnE,cAAc,mDAAmD,CAAC
|
|
1
|
+
{"version":3,"file":"_module.js","sourceRoot":"","sources":["../../../src/utilities/contracts/_module.ts"],"names":[],"mappings":"AAAA,cAAc,gDAAgD,CAAC;AAC/D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,4CAA4C,CAAC;AAC3D,cAAc,oDAAoD,CAAC;AACnE,cAAc,mDAAmD,CAAC"}
|
|
@@ -5,20 +5,24 @@ import type { Invokable, InvokableFn, IInvokableObject } from "../../utilities/t
|
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
|
-
export declare function isInvokableObject<TValue,
|
|
8
|
+
export declare function isInvokableObject<TValue, TParameters extends unknown[], TReturn>(invokable: TValue | Invokable<TParameters, TReturn>): invokable is IInvokableObject<TParameters, TReturn>;
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export declare function isInvokableFn<TValue,
|
|
12
|
+
export declare function isInvokableFn<TValue, TParameters extends unknown[], TReturn>(invokable: TValue | Invokable<TParameters, TReturn>): invokable is InvokableFn<TParameters, TReturn>;
|
|
13
13
|
/**
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
|
-
export declare function isInvokable<TValue,
|
|
16
|
+
export declare function isInvokable<TValue, TParameters extends unknown[], TReturn>(invokable: TValue | Invokable<TParameters, TReturn>): invokable is Invokable<TParameters, TReturn>;
|
|
17
17
|
/**
|
|
18
18
|
* @internal
|
|
19
19
|
*/
|
|
20
|
-
export declare function resolveInvokable<
|
|
20
|
+
export declare function resolveInvokable<TParameters extends unknown[], TReturn>(invokable: Invokable<TParameters, TReturn>): InvokableFn<TParameters, TReturn>;
|
|
21
21
|
/**
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
|
-
export declare function callInvokable<
|
|
24
|
+
export declare function callInvokable<TParameters extends unknown[], TReturn>(invokable: Invokable<TParameters, TReturn>, ...args: TParameters): TReturn;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function getInvokableName<TParameters extends unknown[], TReturn>(invokable: Invokable<TParameters, TReturn>): string;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @module Utilities
|
|
3
3
|
*/
|
|
4
4
|
import { isNullable } from "../../utilities/functions/is-nullable.js";
|
|
5
|
+
import { getConstructorName } from "../../utilities/functions/get-constructor-name.js";
|
|
5
6
|
/**
|
|
6
7
|
* @internal
|
|
7
8
|
*/
|
|
@@ -39,4 +40,13 @@ export function callInvokable(invokable, ...args) {
|
|
|
39
40
|
}
|
|
40
41
|
return invokable(...args);
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export function getInvokableName(invokable) {
|
|
47
|
+
if (isInvokableFn(invokable)) {
|
|
48
|
+
return invokable.name;
|
|
49
|
+
}
|
|
50
|
+
return getConstructorName(invokable);
|
|
51
|
+
}
|
|
42
52
|
//# sourceMappingURL=invokable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invokable.js","sourceRoot":"","sources":["../../../src/utilities/functions/invokable.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAA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