@daiso-tech/core 0.35.4 → 0.37.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 +22 -54
- package/dist/async/backof-policies/_shared.d.ts +8 -2
- package/dist/async/backof-policies/_shared.js +0 -1
- package/dist/async/backof-policies/_shared.js.map +1 -1
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.d.ts +3 -3
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.js +10 -4
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.js.map +1 -1
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.d.ts +3 -3
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.js +10 -4
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.js.map +1 -1
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.d.ts +3 -3
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.js +10 -4
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.js.map +1 -1
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +3 -3
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.js +10 -4
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.js.map +1 -1
- package/dist/async/middlewares/_shared.d.ts +6 -1
- package/dist/async/middlewares/_shared.js +11 -1
- package/dist/async/middlewares/_shared.js.map +1 -1
- package/dist/async/middlewares/fallback/fallback.middleware.d.ts +3 -3
- package/dist/async/middlewares/fallback/fallback.middleware.js +3 -2
- package/dist/async/middlewares/fallback/fallback.middleware.js.map +1 -1
- package/dist/async/middlewares/hedging/_shared.d.ts +7 -7
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js +7 -7
- package/dist/async/middlewares/hedging/concurrent-hedging/concurrent-hedging.middleware.js.map +1 -1
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js +6 -6
- package/dist/async/middlewares/hedging/sequential-hedging/sequential-hedging.middleware.js.map +1 -1
- package/dist/async/middlewares/observe/observe.middleware.d.ts +4 -4
- package/dist/async/middlewares/retry/retry.middleware.d.ts +5 -4
- package/dist/async/middlewares/retry/retry.middleware.js +10 -10
- package/dist/async/middlewares/retry/retry.middleware.js.map +1 -1
- package/dist/async/middlewares/timeout/timeout.middleware.d.ts +4 -2
- package/dist/async/middlewares/timeout/timeout.middleware.js +3 -1
- package/dist/async/middlewares/timeout/timeout.middleware.js.map +1 -1
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +1 -1
- package/dist/async/utilities/lazy-promise/lazy-promise.js +1 -1
- package/dist/async/utilities/promise-queue/promise-queue.js.map +1 -1
- package/dist/cache/contracts/cache-factory.contract.d.ts +2 -2
- package/dist/cache/contracts/cache.errors.d.ts +3 -3
- package/dist/cache/contracts/cache.errors.js +1 -1
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/implementations/adapters/_module-exports.d.ts +1 -2
- package/dist/cache/implementations/adapters/_module-exports.js +1 -2
- package/dist/cache/implementations/adapters/_module-exports.js.map +1 -1
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +41 -16
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +102 -57
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +4 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +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.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +27 -11
- package/dist/cache/implementations/derivables/cache/cache.js +38 -34
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +15 -47
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +19 -45
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache.test-suite.d.ts +4 -5
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +4 -5
- package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
- package/dist/collection/contracts/async-collection.contract.d.ts +127 -121
- package/dist/collection/contracts/collection.contract.d.ts +126 -120
- package/dist/collection/contracts/collection.errors.d.ts +3 -3
- package/dist/collection/contracts/collection.errors.js +1 -1
- package/dist/collection/contracts/collection.errors.js.map +1 -1
- package/dist/collection/implementations/_shared.d.ts +4 -4
- package/dist/collection/implementations/_shared.js +2 -2
- package/dist/collection/implementations/_shared.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.d.ts +1 -0
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.js +1 -0
- package/dist/collection/implementations/async-iterable-collection/_shared/_module.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.d.ts +7 -0
- package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.js +17 -0
- package/dist/collection/implementations/async-iterable-collection/_shared/async-validate-iterable.js.map +1 -0
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +15 -13
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +19 -16
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/_module.d.ts +1 -0
- package/dist/collection/implementations/iterable-collection/_shared/_module.js +1 -0
- package/dist/collection/implementations/iterable-collection/_shared/_module.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.d.ts +7 -0
- package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.js +21 -0
- package/dist/collection/implementations/iterable-collection/_shared/validate-iterable.js.map +1 -0
- package/dist/collection/implementations/iterable-collection/iterable-collection.d.ts +14 -12
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +16 -13
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.d.ts +14 -12
- package/dist/collection/implementations/list-collection/list-collection.js +26 -13
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/event-bus-factory.contract.d.ts +2 -2
- package/dist/event-bus/contracts/event-bus.contract.d.ts +2 -2
- package/dist/event-bus/contracts/event-bus.errors.d.ts +3 -3
- package/dist/event-bus/contracts/event-bus.errors.js +1 -1
- package/dist/event-bus/contracts/event-bus.errors.js.map +1 -1
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +1 -1
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +46 -9
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +64 -22
- 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 +12 -41
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +15 -35
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/lock/contracts/lock.errors.d.ts +2 -2
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/implementations/adapters/_module-exports.d.ts +1 -2
- package/dist/lock/implementations/adapters/_module-exports.js +1 -2
- package/dist/lock/implementations/adapters/_module-exports.js.map +1 -1
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +40 -15
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +75 -34
- 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 +6 -3
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +1 -1
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +22 -18
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +20 -22
- 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 +3 -3
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +12 -6
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +4 -2
- package/dist/lock/implementations/derivables/lock-provider/lock.js +16 -18
- 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 +6 -50
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +10 -54
- 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.d.ts +1 -9
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +1 -9
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/contracts/flexible-serde.contract.d.ts +9 -2
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js +1 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js.map +1 -1
- package/dist/utilities/classes/_module.d.ts +1 -1
- package/dist/utilities/classes/_module.js +1 -1
- package/dist/utilities/classes/_module.js.map +1 -1
- package/dist/utilities/classes/hooks/hooks.d.ts +2 -2
- package/dist/utilities/classes/hooks/hooks.js +2 -2
- package/dist/utilities/classes/namespace/_module.d.ts +1 -0
- package/dist/utilities/classes/namespace/_module.js +2 -0
- package/dist/utilities/classes/namespace/_module.js.map +1 -0
- package/dist/utilities/classes/{key-prefixer/key-prefixer.d.ts → namespace/namespace.d.ts} +38 -17
- package/dist/utilities/classes/{key-prefixer/key-prefixer.js → namespace/namespace.js} +51 -19
- package/dist/utilities/classes/namespace/namespace.js.map +1 -0
- package/dist/utilities/classes/time-span/time-span.d.ts +1 -2
- package/dist/utilities/classes/time-span/time-span.js +1 -4
- package/dist/utilities/classes/time-span/time-span.js.map +1 -1
- package/dist/utilities/functions/_module-exports.d.ts +2 -1
- package/dist/utilities/functions/_module-exports.js +2 -1
- package/dist/utilities/functions/_module-exports.js.map +1 -1
- package/dist/utilities/functions/lazy.d.ts +4 -0
- package/dist/utilities/functions/lazy.js +9 -3
- package/dist/utilities/functions/lazy.js.map +1 -1
- package/dist/utilities/functions/result.d.ts +11 -0
- package/dist/utilities/functions/result.js +15 -0
- package/dist/utilities/functions/result.js.map +1 -0
- package/dist/utilities/functions/validate.d.ts +8 -0
- package/dist/utilities/functions/validate.js +17 -0
- package/dist/utilities/functions/validate.js.map +1 -0
- package/dist/utilities/types/factory.type.d.ts +13 -18
- package/dist/utilities/types/result.type.d.ts +11 -1
- package/package.json +15 -11
- package/dist/cache/implementations/adapters/libsql-cache-adapter/_module.d.ts +0 -1
- package/dist/cache/implementations/adapters/libsql-cache-adapter/_module.js +0 -2
- package/dist/cache/implementations/adapters/libsql-cache-adapter/_module.js.map +0 -1
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.d.ts +0 -61
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js +0 -95
- package/dist/cache/implementations/adapters/libsql-cache-adapter/libsql-cache-adapter.js.map +0 -1
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/_module.d.ts +0 -1
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/_module.js +0 -2
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/_module.js.map +0 -1
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.d.ts +0 -59
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js +0 -94
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js.map +0 -1
- package/dist/lock/implementations/adapters/libsql-lock-adapter/_module.d.ts +0 -1
- package/dist/lock/implementations/adapters/libsql-lock-adapter/_module.js +0 -2
- package/dist/lock/implementations/adapters/libsql-lock-adapter/_module.js.map +0 -1
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.d.ts +0 -60
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js +0 -84
- package/dist/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js.map +0 -1
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/_module.d.ts +0 -1
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/_module.js +0 -2
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/_module.js.map +0 -1
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +0 -59
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js +0 -83
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js.map +0 -1
- package/dist/utilities/classes/key-prefixer/_module.d.ts +0 -1
- package/dist/utilities/classes/key-prefixer/_module.js +0 -2
- package/dist/utilities/classes/key-prefixer/_module.js.map +0 -1
- package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +0 -1
- package/dist/utilities/functions/factory.d.ts +0 -44
- package/dist/utilities/functions/factory.js +0 -80
- package/dist/utilities/functions/factory.js.map +0 -1
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { LazyPromise } from "../../../../async/_module-exports.js";
|
|
5
5
|
import { type IEventBus, type IEventBusFactory, type BaseEventMap, type IEventBusAdapter } from "../../../../event-bus/contracts/_module-exports.js";
|
|
6
|
-
import { type EventBusSettingsBase } from "../../../../event-bus/implementations/derivables/event-bus/_module.js";
|
|
7
|
-
import type { AsyncLazy, Factory,
|
|
6
|
+
import { type EventBusSettingsBase, type EventMapSchema } from "../../../../event-bus/implementations/derivables/event-bus/_module.js";
|
|
7
|
+
import type { AsyncLazy, Factory, Namespace } from "../../../../utilities/_module-exports.js";
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
10
|
* IMPORT_PATH: `"@daiso-tech/core/event-bus"`
|
|
@@ -16,7 +16,7 @@ export type EventBusAdapters<TAdapters extends string = string> = Partial<Record
|
|
|
16
16
|
* IMPORT_PATH: `"@daiso-tech/core/event-bus"`
|
|
17
17
|
* @group Derivables
|
|
18
18
|
*/
|
|
19
|
-
export type EventBusFactorySettings<TAdapters extends string = string> = EventBusSettingsBase & {
|
|
19
|
+
export type EventBusFactorySettings<TAdapters extends string = string, TEventMap extends BaseEventMap = BaseEventMap> = EventBusSettingsBase<TEventMap> & {
|
|
20
20
|
adapters: EventBusAdapters<TAdapters>;
|
|
21
21
|
defaultAdapter?: NoInfer<TAdapters>;
|
|
22
22
|
};
|
|
@@ -26,7 +26,7 @@ export type EventBusFactorySettings<TAdapters extends string = string> = EventBu
|
|
|
26
26
|
* IMPORT_PATH: `"@daiso-tech/core/event-bus"`
|
|
27
27
|
* @group Derivables
|
|
28
28
|
*/
|
|
29
|
-
export declare class EventBusFactory<TAdapters extends string = string> implements IEventBusFactory<TAdapters> {
|
|
29
|
+
export declare class EventBusFactory<TAdapters extends string = string, TEventMap extends BaseEventMap = BaseEventMap> implements IEventBusFactory<TAdapters, TEventMap> {
|
|
30
30
|
private readonly settings;
|
|
31
31
|
/**
|
|
32
32
|
* @example
|
|
@@ -34,31 +34,18 @@ export declare class EventBusFactory<TAdapters extends string = string> implemen
|
|
|
34
34
|
* import { type IEventBusAdapter, BaseEvent } from "@daiso-tech/core/event-bus/contracts";
|
|
35
35
|
* import { EventBusFactory } from "@daiso-tech/core/event-bus";
|
|
36
36
|
* import { MemoryEventBusAdapter, RedisPubSubEventBusAdapter } from "@daiso-tech/core/event-bus/adapters";
|
|
37
|
-
* import {
|
|
37
|
+
* import { type FactoryFn } from "@daiso-tech/core/utilities";
|
|
38
38
|
* import { Serde } from "@daiso-tech/core/serde";
|
|
39
39
|
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
40
40
|
* import Redis from "ioredis";
|
|
41
41
|
*
|
|
42
42
|
* type Store = Partial<Record<string, IEventBusAdapter>>;
|
|
43
43
|
*
|
|
44
|
-
* function cahceAdapterFactory(store: Store): FactoryFn<string, IEventBusAdapter> {
|
|
45
|
-
* return (prefix) => {
|
|
46
|
-
* let adapter = store[prefix];
|
|
47
|
-
* if (adapter === undefined) {
|
|
48
|
-
* adapter = new MemoryEventBusAdapter();
|
|
49
|
-
* store[prefix] = adapter;
|
|
50
|
-
* }
|
|
51
|
-
* return adapter;
|
|
52
|
-
* }
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
44
|
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
56
45
|
* const store: Store = {};
|
|
57
46
|
* const eventBusFactory = new EventBusFactory({
|
|
58
|
-
* keyPrefixer: new KeyPrefixer("event-bus"),
|
|
59
47
|
* adapters: {
|
|
60
48
|
* memory: new MemoryEventBusAdapter(),
|
|
61
|
-
* memoryFactory: cahceAdapterFactory(store),
|
|
62
49
|
* redis: new RedisPubSubEventBusAdapter({
|
|
63
50
|
* serde,
|
|
64
51
|
* dispatcherClient: new Redis("YOUR_REDIS_CONNECTION_STRING"),
|
|
@@ -69,42 +56,26 @@ export declare class EventBusFactory<TAdapters extends string = string> implemen
|
|
|
69
56
|
* });
|
|
70
57
|
* ```
|
|
71
58
|
*/
|
|
72
|
-
constructor(settings: EventBusFactorySettings<TAdapters>);
|
|
73
|
-
|
|
74
|
-
setLazyPromiseFactory(factory: Factory<AsyncLazy<any>, LazyPromise<any>>): EventBusFactory<TAdapters>;
|
|
59
|
+
constructor(settings: EventBusFactorySettings<TAdapters, TEventMap>);
|
|
60
|
+
setNamespace(namespace: Namespace): EventBusFactory<TAdapters, TEventMap>;
|
|
61
|
+
setLazyPromiseFactory(factory: Factory<AsyncLazy<any>, LazyPromise<any>>): EventBusFactory<TAdapters, TEventMap>;
|
|
62
|
+
setEventMapType<TEventMap extends BaseEventMap>(): EventBusFactory<TAdapters, TEventMap>;
|
|
63
|
+
setEventMapSchema<TEventMap extends BaseEventMap>(eventMapSchema: EventMapSchema<TEventMap>): EventBusFactory<TAdapters, TEventMap>;
|
|
75
64
|
/**
|
|
76
65
|
* @example
|
|
77
66
|
* ```ts
|
|
78
67
|
* import { type IEventBusAdapter, BaseEvent } from "@daiso-tech/core/event-bus/contracts";
|
|
79
68
|
* import { EventBusFactory } from "@daiso-tech/core/event-bus";
|
|
80
69
|
* import { MemoryEventBusAdapter, RedisPubSubEventBusAdapter } from "@daiso-tech/core/event-bus/adapters";
|
|
81
|
-
* import {
|
|
70
|
+
* import { type FactoryFn } from "@daiso-tech/core/utilities";
|
|
82
71
|
* import { Serde } from "@daiso-tech/core/serde";
|
|
83
72
|
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
84
73
|
* import Redis from "ioredis";
|
|
85
74
|
*
|
|
86
|
-
* type Store = Partial<Record<string, IEventBusAdapter>>;
|
|
87
|
-
*
|
|
88
|
-
* function cahceAdapterFactory(store: Store): FactoryFn<string, IEventBusAdapter> {
|
|
89
|
-
* return (prefix) => {
|
|
90
|
-
* let adapter = store[prefix];
|
|
91
|
-
* if (adapter === undefined) {
|
|
92
|
-
* adapter = new MemoryEventBusAdapter();
|
|
93
|
-
* store[prefix] = adapter;
|
|
94
|
-
* }
|
|
95
|
-
* return adapter;
|
|
96
|
-
* }
|
|
97
|
-
* }
|
|
98
|
-
*
|
|
99
|
-
* const dispatcherClient = new Redis("YOUR_REDIS_CONNECTION_STRING");
|
|
100
|
-
* const listenerClient = new Redis("YOUR_REDIS_CONNECTION_STRING");
|
|
101
75
|
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
102
|
-
* const store: Store = {};
|
|
103
76
|
* const eventBusFactory = new EventBusFactory({
|
|
104
|
-
* keyPrefixer: new KeyPrefixer("event-bus"),
|
|
105
77
|
* adapters: {
|
|
106
78
|
* memory: new MemoryEventBusAdapter(),
|
|
107
|
-
* memoryFactory: cahceAdapterFactory(store),
|
|
108
79
|
* redis: new RedisPubSubEventBusAdapter({
|
|
109
80
|
* serde,
|
|
110
81
|
* dispatcherClient: new Redis("YOUR_REDIS_CONNECTION_STRING"),
|
|
@@ -133,5 +104,5 @@ export declare class EventBusFactory<TAdapters extends string = string> implemen
|
|
|
133
104
|
* .dispatch("add", { a: 1, b: 2 });
|
|
134
105
|
* ```
|
|
135
106
|
*/
|
|
136
|
-
use
|
|
107
|
+
use(adapterName?: TAdapters | undefined): IEventBus<TEventMap>;
|
|
137
108
|
}
|
|
@@ -18,31 +18,18 @@ export class EventBusFactory {
|
|
|
18
18
|
* import { type IEventBusAdapter, BaseEvent } from "@daiso-tech/core/event-bus/contracts";
|
|
19
19
|
* import { EventBusFactory } from "@daiso-tech/core/event-bus";
|
|
20
20
|
* import { MemoryEventBusAdapter, RedisPubSubEventBusAdapter } from "@daiso-tech/core/event-bus/adapters";
|
|
21
|
-
* import {
|
|
21
|
+
* import { type FactoryFn } from "@daiso-tech/core/utilities";
|
|
22
22
|
* import { Serde } from "@daiso-tech/core/serde";
|
|
23
23
|
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
24
24
|
* import Redis from "ioredis";
|
|
25
25
|
*
|
|
26
26
|
* type Store = Partial<Record<string, IEventBusAdapter>>;
|
|
27
27
|
*
|
|
28
|
-
* function cahceAdapterFactory(store: Store): FactoryFn<string, IEventBusAdapter> {
|
|
29
|
-
* return (prefix) => {
|
|
30
|
-
* let adapter = store[prefix];
|
|
31
|
-
* if (adapter === undefined) {
|
|
32
|
-
* adapter = new MemoryEventBusAdapter();
|
|
33
|
-
* store[prefix] = adapter;
|
|
34
|
-
* }
|
|
35
|
-
* return adapter;
|
|
36
|
-
* }
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
39
28
|
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
40
29
|
* const store: Store = {};
|
|
41
30
|
* const eventBusFactory = new EventBusFactory({
|
|
42
|
-
* keyPrefixer: new KeyPrefixer("event-bus"),
|
|
43
31
|
* adapters: {
|
|
44
32
|
* memory: new MemoryEventBusAdapter(),
|
|
45
|
-
* memoryFactory: cahceAdapterFactory(store),
|
|
46
33
|
* redis: new RedisPubSubEventBusAdapter({
|
|
47
34
|
* serde,
|
|
48
35
|
* dispatcherClient: new Redis("YOUR_REDIS_CONNECTION_STRING"),
|
|
@@ -56,10 +43,10 @@ export class EventBusFactory {
|
|
|
56
43
|
constructor(settings) {
|
|
57
44
|
this.settings = settings;
|
|
58
45
|
}
|
|
59
|
-
|
|
46
|
+
setNamespace(namespace) {
|
|
60
47
|
return new EventBusFactory({
|
|
61
48
|
...this.settings,
|
|
62
|
-
|
|
49
|
+
namespace,
|
|
63
50
|
});
|
|
64
51
|
}
|
|
65
52
|
setLazyPromiseFactory(factory) {
|
|
@@ -68,39 +55,32 @@ export class EventBusFactory {
|
|
|
68
55
|
lazyPromiseFactory: factory,
|
|
69
56
|
});
|
|
70
57
|
}
|
|
58
|
+
setEventMapType() {
|
|
59
|
+
return new EventBusFactory({
|
|
60
|
+
...this.settings,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
setEventMapSchema(eventMapSchema) {
|
|
64
|
+
return new EventBusFactory({
|
|
65
|
+
...this.settings,
|
|
66
|
+
eventMapSchema,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
71
69
|
/**
|
|
72
70
|
* @example
|
|
73
71
|
* ```ts
|
|
74
72
|
* import { type IEventBusAdapter, BaseEvent } from "@daiso-tech/core/event-bus/contracts";
|
|
75
73
|
* import { EventBusFactory } from "@daiso-tech/core/event-bus";
|
|
76
74
|
* import { MemoryEventBusAdapter, RedisPubSubEventBusAdapter } from "@daiso-tech/core/event-bus/adapters";
|
|
77
|
-
* import {
|
|
75
|
+
* import { type FactoryFn } from "@daiso-tech/core/utilities";
|
|
78
76
|
* import { Serde } from "@daiso-tech/core/serde";
|
|
79
77
|
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"
|
|
80
78
|
* import Redis from "ioredis";
|
|
81
79
|
*
|
|
82
|
-
* type Store = Partial<Record<string, IEventBusAdapter>>;
|
|
83
|
-
*
|
|
84
|
-
* function cahceAdapterFactory(store: Store): FactoryFn<string, IEventBusAdapter> {
|
|
85
|
-
* return (prefix) => {
|
|
86
|
-
* let adapter = store[prefix];
|
|
87
|
-
* if (adapter === undefined) {
|
|
88
|
-
* adapter = new MemoryEventBusAdapter();
|
|
89
|
-
* store[prefix] = adapter;
|
|
90
|
-
* }
|
|
91
|
-
* return adapter;
|
|
92
|
-
* }
|
|
93
|
-
* }
|
|
94
|
-
*
|
|
95
|
-
* const dispatcherClient = new Redis("YOUR_REDIS_CONNECTION_STRING");
|
|
96
|
-
* const listenerClient = new Redis("YOUR_REDIS_CONNECTION_STRING");
|
|
97
80
|
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
98
|
-
* const store: Store = {};
|
|
99
81
|
* const eventBusFactory = new EventBusFactory({
|
|
100
|
-
* keyPrefixer: new KeyPrefixer("event-bus"),
|
|
101
82
|
* adapters: {
|
|
102
83
|
* memory: new MemoryEventBusAdapter(),
|
|
103
|
-
* memoryFactory: cahceAdapterFactory(store),
|
|
104
84
|
* redis: new RedisPubSubEventBusAdapter({
|
|
105
85
|
* serde,
|
|
106
86
|
* dispatcherClient: new Redis("YOUR_REDIS_CONNECTION_STRING"),
|
package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus-factory.js","sourceRoot":"","sources":["../../../../../src/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAKN,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACH,QAAQ,
|
|
1
|
+
{"version":3,"file":"event-bus-factory.js","sourceRoot":"","sources":["../../../../../src/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAKN,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACH,QAAQ,GAGX,MAAM,6DAA6D,CAAC;AAMrE,OAAO,EACH,6BAA6B,EAC7B,wBAAwB,GAC3B,MAAM,gCAAgC,CAAC;AAyBxC;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAkCH;IA7BrB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,YACqB,QAGhB;QAHgB,aAAQ,GAAR,QAAQ,CAGxB;IACF,CAAC;IAEJ,YAAY,CAAC,SAAoB;QAC7B,OAAO,IAAI,eAAe,CAAC;YACvB,GAAG,IAAI,CAAC,QAAQ;YAChB,SAAS;SACZ,CAAC,CAAC;IACP,CAAC;IAED,qBAAqB,CACjB,OAAkD;QAElD,OAAO,IAAI,eAAe,CAAC;YACvB,GAAG,IAAI,CAAC,QAAQ;YAChB,kBAAkB,EAAE,OAAO;SAC9B,CAAC,CAAC;IACP,CAAC;IAED,eAAe;QAIX,OAAO,IAAI,eAAe,CAAC;YACvB,GAAG,IAAI,CAAC,QAAQ;SAC8B,CAAC,CAAC;IACxD,CAAC;IAED,iBAAiB,CACb,cAAyC;QAEzC,OAAO,IAAI,eAAe,CAAC;YACvB,GAAG,IAAI,CAAC,QAAQ;YAChB,cAAc;SACjB,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0CG;IACH,GAAG,CACC,cAAqC,IAAI,CAAC,QAAQ,CAAC,cAAc;QAEjE,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,6BAA6B,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,wBAAwB,CAAC,WAAW,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,IAAI,QAAQ,CAAC;YAChB,OAAO;YACP,GAAG,IAAI,CAAC,QAAQ;SACnB,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
4
|
import { type ISerializedError, type OneOrMore } from "../../utilities/_module-exports.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ISerderRegister, ISerializable } from "../../serde/contracts/_module-exports.js";
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
8
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
@@ -97,4 +97,4 @@ export declare const LOCK_ERRORS: {
|
|
|
97
97
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
98
98
|
* @group Errors
|
|
99
99
|
*/
|
|
100
|
-
export declare function registerLockErrorsToSerde(serde: OneOrMore<
|
|
100
|
+
export declare function registerLockErrorsToSerde(serde: OneOrMore<ISerderRegister>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock.errors.js","sourceRoot":"","sources":["../../../src/lock/contracts/lock.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAA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Ae,CAAC,KAAK,CACxB,CAAC;IACN,CAAC;IAED,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9B,CAAC;IAEQ,SAAS;QACd,OAAO;YACH,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;SAClB,CAAC;IACN,CAAC;CACJ;AAED;;;;;GAKG;AACH,MAAM,OAAO,uBACT,SAAQ,SAAS;IAGjB,MAAM,CAAU,WAAW,CACvB,eAAiC;QAEjC,OAAO,IAAI,uBAAuB,CAC9B,eAAe,CAAC,OAAO,EACvB,eAAe,CAAC,KAAK,CACxB,CAAC;IACN,CAAC;IAED,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9B,CAAC;IAEQ,SAAS;QACd,OAAO;YACH,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;SAClB,CAAC;IACN,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,IAAI,EAAE,SAAS;IACf,UAAU,EAAE,mBAAmB;IAC/B,cAAc,EAAE,uBAAuB;IACvC,eAAe,EAAE,wBAAwB;IACzC,kBAAkB,EAAE,2BAA2B;IAC/C,cAAc,EAAE,uBAAuB;CACjC,CAAC;AAEX;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACrC,
|
|
1
|
+
{"version":3,"file":"lock.errors.js","sourceRoot":"","sources":["../../../src/lock/contracts/lock.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACH,IAAI,EACJ,gBAAgB,GAGnB,MAAM,gCAAgC,CAAC;AAMxC;;;;GAIG;AACH,MAAM,OAAO,SACT,SA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,CAAC;aAChD,aAAa,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;AACL,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from "../../../lock/implementations/adapters/
|
|
1
|
+
export * from "../../../lock/implementations/adapters/kysely-lock-adapter/_module.js";
|
|
2
2
|
export * from "../../../lock/implementations/adapters/memory-lock-adapter/_module.js";
|
|
3
3
|
export * from "../../../lock/implementations/adapters/mongodb-lock-adapter/_module.js";
|
|
4
4
|
export * from "../../../lock/implementations/adapters/no-op-lock-adapter/_module.js";
|
|
5
5
|
export * from "../../../lock/implementations/adapters/redis-lock-adapter/_module.js";
|
|
6
|
-
export * from "../../../lock/implementations/adapters/sqlite-lock-adapter/_module.js";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export * from "../../../lock/implementations/adapters/
|
|
1
|
+
export * from "../../../lock/implementations/adapters/kysely-lock-adapter/_module.js";
|
|
2
2
|
export * from "../../../lock/implementations/adapters/memory-lock-adapter/_module.js";
|
|
3
3
|
export * from "../../../lock/implementations/adapters/mongodb-lock-adapter/_module.js";
|
|
4
4
|
export * from "../../../lock/implementations/adapters/no-op-lock-adapter/_module.js";
|
|
5
5
|
export * from "../../../lock/implementations/adapters/redis-lock-adapter/_module.js";
|
|
6
|
-
export * from "../../../lock/implementations/adapters/sqlite-lock-adapter/_module.js";
|
|
7
6
|
//# sourceMappingURL=_module-exports.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module-exports.js","sourceRoot":"","sources":["../../../../src/lock/implementations/adapters/_module-exports.ts"],"names":[],"mappings":"AAAA,cAAc,gEAAgE,CAAC;AAC/E,cAAc,gEAAgE,CAAC;AAC/E,cAAc,iEAAiE,CAAC;AAChF,cAAc,+DAA+D,CAAC;AAC9E,cAAc,+DAA+D,CAAC
|
|
1
|
+
{"version":3,"file":"_module-exports.js","sourceRoot":"","sources":["../../../../src/lock/implementations/adapters/_module-exports.ts"],"names":[],"mappings":"AAAA,cAAc,gEAAgE,CAAC;AAC/E,cAAc,gEAAgE,CAAC;AAC/E,cAAc,iEAAiE,CAAC;AAChF,cAAc,+DAA+D,CAAC;AAC9E,cAAc,+DAA+D,CAAC"}
|
|
@@ -3,41 +3,66 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { IDatabaseLockAdapter, ILockData } from "../../../../lock/contracts/_module-exports.js";
|
|
5
5
|
import type { Kysely } from "kysely";
|
|
6
|
-
import { type IDeinitizable, type IInitizable, TimeSpan } from "../../../../utilities/_module-exports.js";
|
|
6
|
+
import { type IDeinitizable, type IInitizable, type IPrunable, TimeSpan } from "../../../../utilities/_module-exports.js";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
|
+
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
10
|
+
* @group Adapters
|
|
9
11
|
*/
|
|
10
|
-
type
|
|
12
|
+
type KyselyLockAdapterTable = {
|
|
11
13
|
key: string;
|
|
12
14
|
owner: string;
|
|
13
|
-
expiresAt: number | null;
|
|
15
|
+
expiresAt: number | string | null;
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
18
|
+
*
|
|
19
|
+
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
20
|
+
* @group Adapters
|
|
17
21
|
*/
|
|
18
|
-
type
|
|
19
|
-
lock:
|
|
22
|
+
type KyselyLockAdapterTables = {
|
|
23
|
+
lock: KyselyLockAdapterTable;
|
|
20
24
|
};
|
|
21
25
|
/**
|
|
22
|
-
*
|
|
26
|
+
*
|
|
27
|
+
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
28
|
+
* @group Adapters
|
|
23
29
|
*/
|
|
24
|
-
type
|
|
25
|
-
|
|
30
|
+
type KyselyLockAdapterSettings = {
|
|
31
|
+
kysely: Kysely<KyselyLockAdapterTables>;
|
|
26
32
|
expiredKeysRemovalInterval?: TimeSpan;
|
|
27
33
|
shouldRemoveExpiredKeys?: boolean;
|
|
28
34
|
};
|
|
29
35
|
/**
|
|
30
|
-
*
|
|
36
|
+
*
|
|
37
|
+
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
38
|
+
* @group Adapters
|
|
31
39
|
*/
|
|
32
|
-
export declare class KyselyLockAdapter implements IDatabaseLockAdapter, IDeinitizable, IInitizable {
|
|
33
|
-
private readonly
|
|
40
|
+
export declare class KyselyLockAdapter implements IDatabaseLockAdapter, IDeinitizable, IInitizable, IPrunable {
|
|
41
|
+
private readonly kysely;
|
|
34
42
|
private readonly expiredKeysRemovalInterval;
|
|
35
43
|
private readonly shouldRemoveExpiredKeys;
|
|
36
44
|
private timeoutId;
|
|
37
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { KyselyLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
49
|
+
* import Sqlite from "better-sqlite3";
|
|
50
|
+
*
|
|
51
|
+
* const lockAdapter = new KyselyLockAdapter({
|
|
52
|
+
* kysely: new Kysely({
|
|
53
|
+
* dialect: new SqliteDialect({
|
|
54
|
+
* database: new Sqlite("local.db"),
|
|
55
|
+
* }),
|
|
56
|
+
* }),
|
|
57
|
+
* });
|
|
58
|
+
* // You need initialize the adapter once before using it.
|
|
59
|
+
* await lockAdapter.init();
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
constructor(settings: KyselyLockAdapterSettings);
|
|
38
63
|
deInit(): Promise<void>;
|
|
39
64
|
init(): Promise<void>;
|
|
40
|
-
|
|
65
|
+
removeAllExpired(): Promise<void>;
|
|
41
66
|
insert(key: string, owner: string, expiration: Date | null): Promise<void>;
|
|
42
67
|
update(key: string, owner: string, expiration: Date | null): Promise<number>;
|
|
43
68
|
remove(key: string, owner: string | null): Promise<void>;
|
|
@@ -3,58 +3,99 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { TimeSpan, } from "../../../../utilities/_module-exports.js";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
|
+
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
8
|
+
* @group Adapters
|
|
7
9
|
*/
|
|
8
10
|
export class KyselyLockAdapter {
|
|
9
|
-
|
|
11
|
+
kysely;
|
|
10
12
|
expiredKeysRemovalInterval;
|
|
11
13
|
shouldRemoveExpiredKeys;
|
|
12
|
-
timeoutId;
|
|
14
|
+
timeoutId = null;
|
|
15
|
+
/**
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { KyselyLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
19
|
+
* import Sqlite from "better-sqlite3";
|
|
20
|
+
*
|
|
21
|
+
* const lockAdapter = new KyselyLockAdapter({
|
|
22
|
+
* kysely: new Kysely({
|
|
23
|
+
* dialect: new SqliteDialect({
|
|
24
|
+
* database: new Sqlite("local.db"),
|
|
25
|
+
* }),
|
|
26
|
+
* }),
|
|
27
|
+
* });
|
|
28
|
+
* // You need initialize the adapter once before using it.
|
|
29
|
+
* await lockAdapter.init();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
13
32
|
constructor(settings) {
|
|
14
|
-
const {
|
|
33
|
+
const { kysely, expiredKeysRemovalInterval = TimeSpan.fromMinutes(1), shouldRemoveExpiredKeys = true, } = settings;
|
|
15
34
|
this.expiredKeysRemovalInterval = expiredKeysRemovalInterval;
|
|
16
35
|
this.shouldRemoveExpiredKeys = shouldRemoveExpiredKeys;
|
|
17
|
-
this.
|
|
36
|
+
this.kysely = kysely;
|
|
18
37
|
}
|
|
19
38
|
async deInit() {
|
|
20
|
-
|
|
21
|
-
.dropIndex("lock_expiresAt")
|
|
22
|
-
.ifExists()
|
|
23
|
-
.on("lock")
|
|
24
|
-
.execute();
|
|
25
|
-
await this.database.schema.dropTable("lock").ifExists().execute();
|
|
26
|
-
if (this.shouldRemoveExpiredKeys) {
|
|
39
|
+
if (this.shouldRemoveExpiredKeys && this.timeoutId !== null) {
|
|
27
40
|
clearTimeout(this.timeoutId);
|
|
28
41
|
}
|
|
42
|
+
// Should not throw if the index does not exists thats why the try catch is used.
|
|
43
|
+
try {
|
|
44
|
+
await this.kysely.schema
|
|
45
|
+
.dropIndex("lock_expiresAt")
|
|
46
|
+
.on("lock")
|
|
47
|
+
.execute();
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
/* EMPTY */
|
|
51
|
+
}
|
|
52
|
+
// Should not throw if the table does not exists thats why the try catch is used.
|
|
53
|
+
try {
|
|
54
|
+
await this.kysely.schema.dropTable("lock").execute();
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
/* EMPTY */
|
|
58
|
+
}
|
|
29
59
|
}
|
|
30
60
|
async init() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
// Should not throw if the table already exists thats why the try catch is used.
|
|
62
|
+
try {
|
|
63
|
+
await this.kysely.schema
|
|
64
|
+
.createTable("lock")
|
|
65
|
+
.ifNotExists()
|
|
66
|
+
.addColumn("key", "varchar(255)", (col) => col.primaryKey())
|
|
67
|
+
.addColumn("owner", "varchar(255)")
|
|
68
|
+
.addColumn("expiresAt", "bigint")
|
|
69
|
+
.execute();
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
/* EMPTY */
|
|
73
|
+
}
|
|
74
|
+
// Should not throw if the index already exists thats why the try catch is used.
|
|
75
|
+
try {
|
|
76
|
+
await this.kysely.schema
|
|
77
|
+
.createIndex("lock_expiresAt")
|
|
78
|
+
.on("lock")
|
|
79
|
+
.columns(["expiresAt"])
|
|
80
|
+
.execute();
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
/* EMPTY */
|
|
84
|
+
}
|
|
44
85
|
if (this.shouldRemoveExpiredKeys) {
|
|
45
86
|
this.timeoutId = setTimeout(() => {
|
|
46
|
-
void this.
|
|
87
|
+
void this.removeAllExpired();
|
|
47
88
|
}, this.expiredKeysRemovalInterval.toMilliseconds());
|
|
48
89
|
}
|
|
49
90
|
}
|
|
50
|
-
async
|
|
51
|
-
await this.
|
|
91
|
+
async removeAllExpired() {
|
|
92
|
+
await this.kysely
|
|
52
93
|
.deleteFrom("lock")
|
|
53
94
|
.where("lock.expiresAt", "<=", new Date().getTime())
|
|
54
95
|
.execute();
|
|
55
96
|
}
|
|
56
97
|
async insert(key, owner, expiration) {
|
|
57
|
-
await this.
|
|
98
|
+
await this.kysely
|
|
58
99
|
.insertInto("lock")
|
|
59
100
|
.values({
|
|
60
101
|
key,
|
|
@@ -64,7 +105,7 @@ export class KyselyLockAdapter {
|
|
|
64
105
|
.execute();
|
|
65
106
|
}
|
|
66
107
|
async update(key, owner, expiration) {
|
|
67
|
-
const updateResult = await this.
|
|
108
|
+
const updateResult = await this.kysely
|
|
68
109
|
.updateTable("lock")
|
|
69
110
|
.where("lock.key", "=", key)
|
|
70
111
|
// Has expired
|
|
@@ -77,14 +118,14 @@ export class KyselyLockAdapter {
|
|
|
77
118
|
return Number(updateResult.numUpdatedRows); // > 0;
|
|
78
119
|
}
|
|
79
120
|
async remove(key, owner) {
|
|
80
|
-
await this.
|
|
121
|
+
await this.kysely
|
|
81
122
|
.deleteFrom("lock")
|
|
82
123
|
.where("lock.key", "=", key)
|
|
83
124
|
.$if(owner !== null, (query) => query.where("lock.owner", "=", owner))
|
|
84
125
|
.execute();
|
|
85
126
|
}
|
|
86
127
|
async refresh(key, owner, expiration) {
|
|
87
|
-
const updateResult = await this.
|
|
128
|
+
const updateResult = await this.kysely
|
|
88
129
|
.updateTable("lock")
|
|
89
130
|
.where("lock.key", "=", key)
|
|
90
131
|
.where("lock.owner", "=", owner)
|
|
@@ -93,7 +134,7 @@ export class KyselyLockAdapter {
|
|
|
93
134
|
return Number(updateResult.numUpdatedRows); // > 0;
|
|
94
135
|
}
|
|
95
136
|
async find(key) {
|
|
96
|
-
const row = await this.
|
|
137
|
+
const row = await this.kysely
|
|
97
138
|
.selectFrom("lock")
|
|
98
139
|
.where("lock.key", "=", key)
|
|
99
140
|
.select(["lock.owner", "lock.expiresAt"])
|
|
@@ -102,7 +143,7 @@ export class KyselyLockAdapter {
|
|
|
102
143
|
return null;
|
|
103
144
|
}
|
|
104
145
|
return {
|
|
105
|
-
expiration: row.expiresAt ? new Date(row.expiresAt) : null,
|
|
146
|
+
expiration: row.expiresAt ? new Date(Number(row.expiresAt)) : null,
|
|
106
147
|
owner: row.owner,
|
|
107
148
|
};
|
|
108
149
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-lock-adapter.js","sourceRoot":"","sources":["../../../../../src/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,
|
|
1
|
+
{"version":3,"file":"kysely-lock-adapter.js","sourceRoot":"","sources":["../../../../../src/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EAIH,QAAQ,GACX,MAAM,gCAAgC,CAAC;AAkCxC;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAGT,MAAM,CAAkC;IACxC,0BAA0B,CAAW;IACrC,uBAAuB,CAAU;IAC1C,SAAS,GACb,IAAI,CAAC;IAET;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,QAAmC;QAC3C,MAAM,EACF,MAAM,EACN,0BAA0B,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EACpD,uBAAuB,GAAG,IAAI,GACjC,GAAG,QAAQ,CAAC;QACb,IAAI,CAAC,0BAA0B,GAAG,0BAA0B,CAAC;QAC7D,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,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CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;YAClE,KAAK,EAAE,GAAG,CAAC,KAAK;SACnB,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import { type IDeinitizable, type IInitizable } from "../../../../utilities/_module-exports.js";
|
|
4
|
+
import { type IDeinitizable, type IInitizable, type IPrunable } from "../../../../utilities/_module-exports.js";
|
|
5
5
|
import type { IDatabaseLockAdapter, ILockData } from "../../../../lock/contracts/_module-exports.js";
|
|
6
6
|
import type { CollectionOptions, Db } from "mongodb";
|
|
7
7
|
/**
|
|
@@ -11,6 +11,9 @@ import type { CollectionOptions, Db } from "mongodb";
|
|
|
11
11
|
*/
|
|
12
12
|
export type MongodbLockAdapterSettings = {
|
|
13
13
|
database: Db;
|
|
14
|
+
/**
|
|
15
|
+
* @default {"lock"}
|
|
16
|
+
*/
|
|
14
17
|
collectionName?: string;
|
|
15
18
|
collectionSettings?: CollectionOptions;
|
|
16
19
|
};
|
|
@@ -22,7 +25,7 @@ export type MongodbLockAdapterSettings = {
|
|
|
22
25
|
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
23
26
|
* @group Adapters
|
|
24
27
|
*/
|
|
25
|
-
export declare class MongodbLockAdapter implements IDatabaseLockAdapter, IDeinitizable, IInitizable {
|
|
28
|
+
export declare class MongodbLockAdapter implements IDatabaseLockAdapter, IDeinitizable, IInitizable, IPrunable {
|
|
26
29
|
private readonly database;
|
|
27
30
|
private readonly collection;
|
|
28
31
|
private readonly collectionName;
|
|
@@ -42,7 +45,7 @@ export declare class MongodbLockAdapter implements IDatabaseLockAdapter, IDeinit
|
|
|
42
45
|
* ```
|
|
43
46
|
*/
|
|
44
47
|
constructor({ collectionName, collectionSettings, database, }: MongodbLockAdapterSettings);
|
|
45
|
-
|
|
48
|
+
removeAllExpired(): Promise<void>;
|
|
46
49
|
/**
|
|
47
50
|
* Creates all related indexes.
|
|
48
51
|
* Note the `init` method needs to be called before using the adapter.
|
|
@@ -36,7 +36,7 @@ export class MongodbLockAdapter {
|
|
|
36
36
|
this.database = database;
|
|
37
37
|
this.collection = database.collection(collectionName, collectionSettings);
|
|
38
38
|
}
|
|
39
|
-
async
|
|
39
|
+
async removeAllExpired() {
|
|
40
40
|
await this.collection.deleteMany({
|
|
41
41
|
expiresAt: {
|
|
42
42
|
$lte: new Date(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-lock-adapter.js","sourceRoot":"","sources":["../../../../../src/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"mongodb-lock-adapter.js","sourceRoot":"","sources":["../../../../../src/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAIN,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AA0BnC;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAkB;IAGV,QAAQ,CAAK;IACb,UAAU,CAAkC;IAC5C,cAAc,CAAS;IAExC;;;;;;;;;;;;;;OAcG;IACH,YAAY,EACR,cAAc,GAAG,MAAM,EACvB,kBAAkB,EAClB,QAAQ,GACiB;QACzB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CACjC,cAAc,EACd,kBAAkB,CACrB,CAAC;IACN,CAAC;IAED,KAAK,CAAC,gBAAgB;QAClB,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