@daiso-tech/core 0.38.0 → 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/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/bulkhead/bulkhead.middleware.d.ts +2 -2
- package/dist/async/middlewares/hedging/sequential-hedging.middleware.js +2 -2
- package/dist/async/middlewares/hedging/sequential-hedging.middleware.js.map +1 -1
- package/dist/async/middlewares/retry/retry.middleware.js +2 -2
- package/dist/async/middlewares/retry/retry.middleware.js.map +1 -1
- package/dist/async/middlewares/retry/retry.types.d.ts +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/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/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 +23 -23
- package/dist/lock/contracts/lock.errors.d.ts +5 -32
- package/dist/lock/contracts/lock.errors.js +1 -77
- 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 +46 -22
- 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 +28 -28
- 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/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 +3 -3
- 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.d.ts +1 -0
- package/dist/utilities/functions/_module.js +1 -0
- package/dist/utilities/functions/_module.js.map +1 -1
- package/dist/utilities/functions/is-class.d.ts +4 -0
- package/dist/utilities/functions/is-class.js +4 -0
- package/dist/utilities/functions/is-class.js.map +1 -1
- 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/package.json +1 -1
- package/dist/event-bus/contracts/event-bus.errors.d.ts +0 -40
- package/dist/event-bus/contracts/event-bus.errors.js +0 -62
- package/dist/event-bus/contracts/event-bus.errors.js.map +0 -1
|
@@ -11,20 +11,21 @@ export type ILockData = {
|
|
|
11
11
|
expiration: Date | null;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* The `
|
|
15
|
-
* This contract
|
|
14
|
+
* The `IDatabaseLockAdapter` contract defines a way for managing locks independent of data storage.
|
|
15
|
+
* This contract simplifies the implementation of lock adapters with CRUD-based databases, such as SQL databases and ORMs like TypeOrm and MikroOrm.
|
|
16
16
|
*
|
|
17
17
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
18
18
|
* @group Contracts
|
|
19
19
|
*/
|
|
20
20
|
export type IDatabaseLockAdapter = {
|
|
21
21
|
/**
|
|
22
|
-
* The `insert` method will create a lock if
|
|
22
|
+
* The `insert` method will create a lock if it does not exist and if the lock already exists an error must be thrown.
|
|
23
23
|
*/
|
|
24
24
|
insert(key: string, owner: string, expiration: Date | null): PromiseLike<void>;
|
|
25
25
|
/**
|
|
26
26
|
* The `update` method will update a lock if it has expired, matches the given `key` and matches the given `owner`.
|
|
27
|
-
*
|
|
27
|
+
*
|
|
28
|
+
* @returns Returns number of updated rows or documents.
|
|
28
29
|
*/
|
|
29
30
|
update(key: string, owner: string, expiration: Date | null): PromiseLike<number>;
|
|
30
31
|
/**
|
|
@@ -33,7 +34,8 @@ export type IDatabaseLockAdapter = {
|
|
|
33
34
|
remove(key: string, owner: string | null): PromiseLike<void>;
|
|
34
35
|
/**
|
|
35
36
|
* The `refresh` method will upadte expiration of lock if it matches the given `key` and matches the given `owner`.
|
|
36
|
-
*
|
|
37
|
+
*
|
|
38
|
+
* @returns Returns number of updated rows or documents.
|
|
37
39
|
*/
|
|
38
40
|
refresh(key: string, owner: string, expiration: Date): PromiseLike<number>;
|
|
39
41
|
/**
|
|
@@ -12,12 +12,14 @@ import type { TimeSpan } from "../../utilities/_module-exports.js";
|
|
|
12
12
|
export type ILockAdapter = {
|
|
13
13
|
/**
|
|
14
14
|
* The `acquire` method acquires a lock only if the lock is not already acquired.
|
|
15
|
-
*
|
|
15
|
+
*
|
|
16
|
+
* @returns Returns true if not already acquired othewise false is returned.
|
|
16
17
|
*/
|
|
17
18
|
acquire(key: string, owner: string, ttl: TimeSpan | null): PromiseLike<boolean>;
|
|
18
19
|
/**
|
|
19
20
|
* The `release` method releases a lock if the owner matches.
|
|
20
|
-
*
|
|
21
|
+
*
|
|
22
|
+
* @returns Returns true if released otherwise false is returned.
|
|
21
23
|
*/
|
|
22
24
|
release(key: string, owner: string): PromiseLike<boolean>;
|
|
23
25
|
/**
|
|
@@ -25,7 +27,7 @@ export type ILockAdapter = {
|
|
|
25
27
|
*/
|
|
26
28
|
forceRelease(key: string): PromiseLike<void>;
|
|
27
29
|
/**
|
|
28
|
-
* The `refresh` method will upadte ttl of lock if it matches the given `key` and matches the given `owner`.
|
|
30
|
+
* The `refresh` method will upadte `ttl` of lock if it matches the given `key` and matches the given `owner`.
|
|
29
31
|
* Returns true if the update occured otherwise false is returned.
|
|
30
32
|
*/
|
|
31
33
|
refresh(key: string, owner: string, ttl: TimeSpan): PromiseLike<boolean>;
|
|
@@ -9,7 +9,7 @@ import type { KeyAlreadyAcquiredLockError } from "../../lock/contracts/lock.erro
|
|
|
9
9
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
10
10
|
* @group Contracts
|
|
11
11
|
*/
|
|
12
|
-
export type
|
|
12
|
+
export type LockAquireBlockingSettings = {
|
|
13
13
|
time?: TimeSpan;
|
|
14
14
|
interval?: TimeSpan;
|
|
15
15
|
};
|
|
@@ -31,44 +31,44 @@ export type ILock = {
|
|
|
31
31
|
/**
|
|
32
32
|
* The `runBlocking` method wraps an {@link Invokable | `Invokable`} or {@link LazyPromise| `LazyPromise`} with the `acquireBlocking` and `release` method.
|
|
33
33
|
*/
|
|
34
|
-
runBlocking<TValue = void>(asyncFn: AsyncLazy<TValue>, settings?:
|
|
34
|
+
runBlocking<TValue = void>(asyncFn: AsyncLazy<TValue>, settings?: LockAquireBlockingSettings): LazyPromise<Result<TValue, KeyAlreadyAcquiredLockError>>;
|
|
35
35
|
/**
|
|
36
36
|
* The `runBlockingOrFail` method wraps an {@link Invokable | `Invokable`} or {@link LazyPromise| `LazyPromise`} with the `acquireBlockingOrFail` and `release` method.
|
|
37
37
|
* @throws {KeyAlreadyAcquiredLockError} {@link KeyAlreadyAcquiredLockError}
|
|
38
38
|
*/
|
|
39
|
-
runBlockingOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>, settings?:
|
|
39
|
+
runBlockingOrFail<TValue = void>(asyncFn: AsyncLazy<TValue>, settings?: LockAquireBlockingSettings): LazyPromise<TValue>;
|
|
40
40
|
/**
|
|
41
|
-
* The `acquire` method acquires a lock only if the lock is
|
|
41
|
+
* The `acquire` method acquires a lock only if the lock is available.
|
|
42
42
|
*
|
|
43
|
-
* @returns true if the lock is
|
|
43
|
+
* @returns Returns true if the lock is acquired otherwise false is returned.
|
|
44
44
|
*/
|
|
45
45
|
acquire(): LazyPromise<boolean>;
|
|
46
46
|
/**
|
|
47
|
-
* The `
|
|
48
|
-
*
|
|
47
|
+
* The `acquireOrFail` method acquires a lock only if the lock is available.
|
|
48
|
+
* Throws an error if already acquired.
|
|
49
49
|
*
|
|
50
|
-
* @
|
|
50
|
+
* @throws {KeyAlreadyAcquiredLockError} {@link KeyAlreadyAcquiredLockError}
|
|
51
51
|
*/
|
|
52
|
-
|
|
52
|
+
acquireOrFail(): LazyPromise<void>;
|
|
53
53
|
/**
|
|
54
|
-
* The `
|
|
55
|
-
* If the lock is acquired, it retries every `settings.interval` until `settings.time` is reached.
|
|
56
|
-
* Throws an error if not lock cannot be acquired after the given `settings.time`.
|
|
54
|
+
* The `acquireBlocking` method acquires a lock only if the lock is available.
|
|
55
|
+
* If the lock is not acquired, it retries every `settings.interval` until `settings.time` is reached.
|
|
57
56
|
*
|
|
58
|
-
* @
|
|
57
|
+
* @returns Returns true if the lock is acquired otherwise false is returned.
|
|
59
58
|
*/
|
|
60
|
-
|
|
59
|
+
acquireBlocking(settings?: LockAquireBlockingSettings): LazyPromise<boolean>;
|
|
61
60
|
/**
|
|
62
|
-
* The `
|
|
63
|
-
*
|
|
61
|
+
* The `acquireBlockingOrFail` method acquires a lock only if the lock is available.
|
|
62
|
+
* If the lock is not acquired, it retries every `settings.interval` until `settings.time` is reached.
|
|
63
|
+
* Throws an error if the lock cannot be acquired after the given `settings.time`.
|
|
64
64
|
*
|
|
65
65
|
* @throws {KeyAlreadyAcquiredLockError} {@link KeyAlreadyAcquiredLockError}
|
|
66
66
|
*/
|
|
67
|
-
|
|
67
|
+
acquireBlockingOrFail(settings?: LockAquireBlockingSettings): LazyPromise<void>;
|
|
68
68
|
/**
|
|
69
69
|
* The `release` method releases a lock if owned by the same owner.
|
|
70
70
|
*
|
|
71
|
-
* @returns true if the lock is released otherwise false is returned.
|
|
71
|
+
* @returns Returns true if the lock is released otherwise false is returned.
|
|
72
72
|
*/
|
|
73
73
|
release(): LazyPromise<boolean>;
|
|
74
74
|
/**
|
|
@@ -83,7 +83,7 @@ export type ILock = {
|
|
|
83
83
|
*/
|
|
84
84
|
forceRelease(): LazyPromise<void>;
|
|
85
85
|
/**
|
|
86
|
-
* The `isExpired` method returns true if the expired otherwise false is returned.
|
|
86
|
+
* The `isExpired` method returns true if the lock is expired otherwise false is returned.
|
|
87
87
|
*/
|
|
88
88
|
isExpired(): LazyPromise<boolean>;
|
|
89
89
|
/**
|
|
@@ -91,13 +91,13 @@ export type ILock = {
|
|
|
91
91
|
*/
|
|
92
92
|
isLocked(): LazyPromise<boolean>;
|
|
93
93
|
/**
|
|
94
|
-
* The `refresh` method updates the
|
|
94
|
+
* The `refresh` method updates the `ttl` of the lock if owned by the same owner.
|
|
95
95
|
*
|
|
96
|
-
* @returns true if the lock is refreshed
|
|
96
|
+
* @returns Returns true if the lock is refreshed otherwise false is returned.
|
|
97
97
|
*/
|
|
98
98
|
refresh(ttl?: TimeSpan): LazyPromise<boolean>;
|
|
99
99
|
/**
|
|
100
|
-
* The `refreshOrFail` method updates the
|
|
100
|
+
* The `refreshOrFail` method updates the `ttl` of the lock if owned by the same owner.
|
|
101
101
|
* Throws an error if a different owner attempts to refresh the lock.
|
|
102
102
|
* @throws {UnownedRefreshLockError} {@link UnownedRefreshLockError}
|
|
103
103
|
*/
|
|
@@ -105,7 +105,7 @@ export type ILock = {
|
|
|
105
105
|
/**
|
|
106
106
|
* The `getRemainingTime` return the reaming time as {@link TimeSpan | `TimeSpan`}.
|
|
107
107
|
*
|
|
108
|
-
* @returns null if the key doesnt exist, key has no expiration and key has expired.
|
|
108
|
+
* @returns Returns null if the key doesnt exist, key has no expiration and key has expired.
|
|
109
109
|
*/
|
|
110
110
|
getRemainingTime(): LazyPromise<TimeSpan | null>;
|
|
111
111
|
/**
|
|
@@ -1,27 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import { type ISerializedError, type OneOrMore } from "../../utilities/_module-exports.js";
|
|
5
|
-
import type { ISerderRegister, ISerializable } from "../../serde/contracts/_module-exports.js";
|
|
6
4
|
/**
|
|
7
5
|
*
|
|
8
6
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
9
7
|
* @group Errors
|
|
10
8
|
*/
|
|
11
|
-
export declare class LockError extends Error
|
|
12
|
-
static deserialize(serializedError: ISerializedError): LockError;
|
|
9
|
+
export declare class LockError extends Error {
|
|
13
10
|
constructor(message: string, cause?: unknown);
|
|
14
|
-
serialize(): ISerializedError;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
19
|
-
* @group Errors
|
|
20
|
-
*/
|
|
21
|
-
export declare class UnexpectedLockError extends LockError implements ISerializable<ISerializedError> {
|
|
22
|
-
static deserialize(serializedError: ISerializedError): UnexpectedLockError;
|
|
23
|
-
constructor(message: string, cause?: unknown);
|
|
24
|
-
serialize(): ISerializedError;
|
|
25
11
|
}
|
|
26
12
|
/**
|
|
27
13
|
* The error is thrown when trying to acquire a lock that is owned by a different owner.
|
|
@@ -29,10 +15,8 @@ export declare class UnexpectedLockError extends LockError implements ISerializa
|
|
|
29
15
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
30
16
|
* @group Errors
|
|
31
17
|
*/
|
|
32
|
-
export declare class KeyAlreadyAcquiredLockError extends LockError
|
|
33
|
-
static deserialize(serializedError: ISerializedError): KeyAlreadyAcquiredLockError;
|
|
18
|
+
export declare class KeyAlreadyAcquiredLockError extends LockError {
|
|
34
19
|
constructor(message: string, cause?: unknown);
|
|
35
|
-
serialize(): ISerializedError;
|
|
36
20
|
}
|
|
37
21
|
/**
|
|
38
22
|
* The error is thrown when trying to release a lock that is owned by a different owner.
|
|
@@ -40,10 +24,8 @@ export declare class KeyAlreadyAcquiredLockError extends LockError implements IS
|
|
|
40
24
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
41
25
|
* @group Errors
|
|
42
26
|
*/
|
|
43
|
-
export declare class UnownedReleaseLockError extends LockError
|
|
44
|
-
static deserialize(serializedError: ISerializedError): UnownedReleaseLockError;
|
|
27
|
+
export declare class UnownedReleaseLockError extends LockError {
|
|
45
28
|
constructor(message: string, cause?: unknown);
|
|
46
|
-
serialize(): ISerializedError;
|
|
47
29
|
}
|
|
48
30
|
/**
|
|
49
31
|
* The error is thrown when trying to referesh a lock that is owned by a different owner.
|
|
@@ -51,10 +33,8 @@ export declare class UnownedReleaseLockError extends LockError implements ISeria
|
|
|
51
33
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
52
34
|
* @group Errors
|
|
53
35
|
*/
|
|
54
|
-
export declare class UnownedRefreshLockError extends LockError
|
|
55
|
-
static deserialize(serializedError: ISerializedError): UnownedRefreshLockError;
|
|
36
|
+
export declare class UnownedRefreshLockError extends LockError {
|
|
56
37
|
constructor(message: string, cause?: unknown);
|
|
57
|
-
serialize(): ISerializedError;
|
|
58
38
|
}
|
|
59
39
|
/**
|
|
60
40
|
*
|
|
@@ -63,14 +43,7 @@ export declare class UnownedRefreshLockError extends LockError implements ISeria
|
|
|
63
43
|
*/
|
|
64
44
|
export declare const LOCK_ERRORS: {
|
|
65
45
|
readonly Base: typeof LockError;
|
|
66
|
-
readonly Unexpected: typeof UnexpectedLockError;
|
|
67
46
|
readonly KeyAlreadyAcquired: typeof KeyAlreadyAcquiredLockError;
|
|
68
47
|
readonly UnownedRelease: typeof UnownedReleaseLockError;
|
|
48
|
+
readonly UnownedRefresh: typeof UnownedRefreshLockError;
|
|
69
49
|
};
|
|
70
|
-
/**
|
|
71
|
-
* The `registerLockErrorsToSerde` function registers all {@link ILock | `ILock`} related errors with `IFlexibleSerde`, ensuring they will properly be serialized and deserialized.
|
|
72
|
-
*
|
|
73
|
-
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
74
|
-
* @group Errors
|
|
75
|
-
*/
|
|
76
|
-
export declare function registerLockErrorsToSerde(serde: OneOrMore<ISerderRegister>): void;
|
|
@@ -1,46 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import { CORE, resolveOneOrMore, } from "../../utilities/_module-exports.js";
|
|
5
4
|
/**
|
|
6
5
|
*
|
|
7
6
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
8
7
|
* @group Errors
|
|
9
8
|
*/
|
|
10
9
|
export class LockError extends Error {
|
|
11
|
-
static deserialize(serializedError) {
|
|
12
|
-
return new LockError(serializedError.message, serializedError.cause);
|
|
13
|
-
}
|
|
14
10
|
constructor(message, cause) {
|
|
15
11
|
super(message, { cause });
|
|
16
12
|
}
|
|
17
|
-
serialize() {
|
|
18
|
-
return {
|
|
19
|
-
cause: this.cause,
|
|
20
|
-
message: this.message,
|
|
21
|
-
name: this.name,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
28
|
-
* @group Errors
|
|
29
|
-
*/
|
|
30
|
-
export class UnexpectedLockError extends LockError {
|
|
31
|
-
static deserialize(serializedError) {
|
|
32
|
-
return new UnexpectedLockError(serializedError.message, serializedError.cause);
|
|
33
|
-
}
|
|
34
|
-
constructor(message, cause) {
|
|
35
|
-
super(message, { cause });
|
|
36
|
-
}
|
|
37
|
-
serialize() {
|
|
38
|
-
return {
|
|
39
|
-
cause: this.cause,
|
|
40
|
-
message: this.message,
|
|
41
|
-
name: this.name,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
13
|
}
|
|
45
14
|
/**
|
|
46
15
|
* The error is thrown when trying to acquire a lock that is owned by a different owner.
|
|
@@ -49,19 +18,9 @@ export class UnexpectedLockError extends LockError {
|
|
|
49
18
|
* @group Errors
|
|
50
19
|
*/
|
|
51
20
|
export class KeyAlreadyAcquiredLockError extends LockError {
|
|
52
|
-
static deserialize(serializedError) {
|
|
53
|
-
return new KeyAlreadyAcquiredLockError(serializedError.message, serializedError.cause);
|
|
54
|
-
}
|
|
55
21
|
constructor(message, cause) {
|
|
56
22
|
super(message, { cause });
|
|
57
23
|
}
|
|
58
|
-
serialize() {
|
|
59
|
-
return {
|
|
60
|
-
cause: this.cause,
|
|
61
|
-
message: this.message,
|
|
62
|
-
name: this.name,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
24
|
}
|
|
66
25
|
/**
|
|
67
26
|
* The error is thrown when trying to release a lock that is owned by a different owner.
|
|
@@ -70,19 +29,9 @@ export class KeyAlreadyAcquiredLockError extends LockError {
|
|
|
70
29
|
* @group Errors
|
|
71
30
|
*/
|
|
72
31
|
export class UnownedReleaseLockError extends LockError {
|
|
73
|
-
static deserialize(serializedError) {
|
|
74
|
-
return new UnownedReleaseLockError(serializedError.message, serializedError.cause);
|
|
75
|
-
}
|
|
76
32
|
constructor(message, cause) {
|
|
77
33
|
super(message, { cause });
|
|
78
34
|
}
|
|
79
|
-
serialize() {
|
|
80
|
-
return {
|
|
81
|
-
cause: this.cause,
|
|
82
|
-
message: this.message,
|
|
83
|
-
name: this.name,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
35
|
}
|
|
87
36
|
/**
|
|
88
37
|
* The error is thrown when trying to referesh a lock that is owned by a different owner.
|
|
@@ -91,19 +40,9 @@ export class UnownedReleaseLockError extends LockError {
|
|
|
91
40
|
* @group Errors
|
|
92
41
|
*/
|
|
93
42
|
export class UnownedRefreshLockError extends LockError {
|
|
94
|
-
static deserialize(serializedError) {
|
|
95
|
-
return new UnownedRefreshLockError(serializedError.message, serializedError.cause);
|
|
96
|
-
}
|
|
97
43
|
constructor(message, cause) {
|
|
98
44
|
super(message, { cause });
|
|
99
45
|
}
|
|
100
|
-
serialize() {
|
|
101
|
-
return {
|
|
102
|
-
cause: this.cause,
|
|
103
|
-
message: this.message,
|
|
104
|
-
name: this.name,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
46
|
}
|
|
108
47
|
/**
|
|
109
48
|
*
|
|
@@ -112,23 +51,8 @@ export class UnownedRefreshLockError extends LockError {
|
|
|
112
51
|
*/
|
|
113
52
|
export const LOCK_ERRORS = {
|
|
114
53
|
Base: LockError,
|
|
115
|
-
Unexpected: UnexpectedLockError,
|
|
116
54
|
KeyAlreadyAcquired: KeyAlreadyAcquiredLockError,
|
|
117
55
|
UnownedRelease: UnownedReleaseLockError,
|
|
56
|
+
UnownedRefresh: UnownedRefreshLockError,
|
|
118
57
|
};
|
|
119
|
-
/**
|
|
120
|
-
* The `registerLockErrorsToSerde` function registers all {@link ILock | `ILock`} related errors with `IFlexibleSerde`, ensuring they will properly be serialized and deserialized.
|
|
121
|
-
*
|
|
122
|
-
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
123
|
-
* @group Errors
|
|
124
|
-
*/
|
|
125
|
-
export function registerLockErrorsToSerde(serde) {
|
|
126
|
-
for (const serde_ of resolveOneOrMore(serde)) {
|
|
127
|
-
serde_
|
|
128
|
-
.registerClass(LockError, CORE)
|
|
129
|
-
.registerClass(UnexpectedLockError, CORE)
|
|
130
|
-
.registerClass(KeyAlreadyAcquiredLockError, CORE)
|
|
131
|
-
.registerClass(UnownedReleaseLockError, CORE);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
58
|
//# sourceMappingURL=lock.errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock.errors.js","sourceRoot":"","sources":["../../../src/lock/contracts/lock.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"lock.errors.js","sourceRoot":"","sources":["../../../src/lock/contracts/lock.errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAChC,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9B,CAAC;CACJ;AAED;;;;;GAKG;AACH,MAAM,OAAO,2BAA4B,SAAQ,SAAS;IACtD,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9B,CAAC;CACJ;AAED;;;;;GAKG;AACH,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IAClD,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9B,CAAC;CACJ;AAED;;;;;GAKG;AACH,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IAClD,YAAY,OAAe,EAAE,KAAe;QACxC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9B,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,IAAI,EAAE,SAAS;IACf,kBAAkB,EAAE,2BAA2B;IAC/C,cAAc,EAAE,uBAAuB;IACvC,cAAc,EAAE,uBAAuB;CACjC,CAAC"}
|
|
@@ -58,7 +58,7 @@ export type UnownedRefreshTryLockEvent = {
|
|
|
58
58
|
* IMPORT_PATH: `"@daiso-tech/core/lock/contracts"`
|
|
59
59
|
* @group Events
|
|
60
60
|
*/
|
|
61
|
-
export type
|
|
61
|
+
export type UnavailableLockEvent = {
|
|
62
62
|
key: string;
|
|
63
63
|
owner: string;
|
|
64
64
|
};
|
|
@@ -94,7 +94,7 @@ export declare const LOCK_EVENTS: {
|
|
|
94
94
|
readonly RELEASED: "RELEASED";
|
|
95
95
|
readonly UNOWNED_RELEASE_TRY: "UNOWNED_RELEASE_TRY";
|
|
96
96
|
readonly UNOWNED_REFRESH_TRY: "UNOWNED_REFRESH_TRY";
|
|
97
|
-
readonly
|
|
97
|
+
readonly UNAVAILABLE: "UNAVAILABLE";
|
|
98
98
|
readonly FORCE_RELEASED: "FORCE_RELEASED";
|
|
99
99
|
readonly REFRESHED: "REFRESHED";
|
|
100
100
|
readonly UNEXPECTED_ERROR: "UNEXPECTED_ERROR";
|
|
@@ -109,7 +109,7 @@ export type LockEventMap = {
|
|
|
109
109
|
[LOCK_EVENTS.RELEASED]: ReleasedLockEvent;
|
|
110
110
|
[LOCK_EVENTS.UNOWNED_RELEASE_TRY]: UnownedReleaseTryLockEvent;
|
|
111
111
|
[LOCK_EVENTS.UNOWNED_REFRESH_TRY]: UnownedRefreshTryLockEvent;
|
|
112
|
-
[LOCK_EVENTS.
|
|
112
|
+
[LOCK_EVENTS.UNAVAILABLE]: UnavailableLockEvent;
|
|
113
113
|
[LOCK_EVENTS.FORCE_RELEASED]: ForceReleasedLockEvent;
|
|
114
114
|
[LOCK_EVENTS.REFRESHED]: RefreshedLockEvent;
|
|
115
115
|
[LOCK_EVENTS.UNEXPECTED_ERROR]: UnexpectedErrorLockEvent;
|
|
@@ -11,7 +11,7 @@ export const LOCK_EVENTS = {
|
|
|
11
11
|
RELEASED: "RELEASED",
|
|
12
12
|
UNOWNED_RELEASE_TRY: "UNOWNED_RELEASE_TRY",
|
|
13
13
|
UNOWNED_REFRESH_TRY: "UNOWNED_REFRESH_TRY",
|
|
14
|
-
|
|
14
|
+
UNAVAILABLE: "UNAVAILABLE",
|
|
15
15
|
FORCE_RELEASED: "FORCE_RELEASED",
|
|
16
16
|
REFRESHED: "REFRESHED",
|
|
17
17
|
UNEXPECTED_ERROR: "UNEXPECTED_ERROR",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock.events.js","sourceRoot":"","sources":["../../../src/lock/contracts/lock.events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgGH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,mBAAmB,EAAE,qBAAqB;IAC1C,mBAAmB,EAAE,qBAAqB;IAC1C,
|
|
1
|
+
{"version":3,"file":"lock.events.js","sourceRoot":"","sources":["../../../src/lock/contracts/lock.events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAgGH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,mBAAmB,EAAE,qBAAqB;IAC1C,mBAAmB,EAAE,qBAAqB;IAC1C,WAAW,EAAE,aAAa;IAC1B,cAAc,EAAE,gBAAgB;IAChC,SAAS,EAAE,WAAW;IACtB,gBAAgB,EAAE,kBAAkB;CAC9B,CAAC"}
|
|
@@ -9,7 +9,7 @@ import { type IDeinitizable, type IInitizable, type IPrunable, TimeSpan } from "
|
|
|
9
9
|
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
10
10
|
* @group Adapters
|
|
11
11
|
*/
|
|
12
|
-
type KyselyLockAdapterTable = {
|
|
12
|
+
export type KyselyLockAdapterTable = {
|
|
13
13
|
key: string;
|
|
14
14
|
owner: string;
|
|
15
15
|
expiresAt: number | string | null;
|
|
@@ -19,7 +19,7 @@ type KyselyLockAdapterTable = {
|
|
|
19
19
|
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
20
20
|
* @group Adapters
|
|
21
21
|
*/
|
|
22
|
-
type KyselyLockAdapterTables = {
|
|
22
|
+
export type KyselyLockAdapterTables = {
|
|
23
23
|
lock: KyselyLockAdapterTable;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
@@ -27,12 +27,25 @@ type KyselyLockAdapterTables = {
|
|
|
27
27
|
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
28
28
|
* @group Adapters
|
|
29
29
|
*/
|
|
30
|
-
type KyselyLockAdapterSettings = {
|
|
30
|
+
export type KyselyLockAdapterSettings = {
|
|
31
31
|
kysely: Kysely<KyselyLockAdapterTables>;
|
|
32
|
+
/**
|
|
33
|
+
* @default
|
|
34
|
+
* ```ts
|
|
35
|
+
* TimeSpan.fromMinutes(1)
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
32
38
|
expiredKeysRemovalInterval?: TimeSpan;
|
|
39
|
+
/**
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
33
42
|
shouldRemoveExpiredKeys?: boolean;
|
|
34
43
|
};
|
|
35
44
|
/**
|
|
45
|
+
* To utilize the `KyselyLockAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance.
|
|
46
|
+
*
|
|
47
|
+
* Note in order to use `KyselyLockAdapter` correctly, ensure you use a single, consistent database across all server instances.
|
|
48
|
+
* The adapter have been tested with `sqlite`, `postgres` and `mysql` databases.
|
|
36
49
|
*
|
|
37
50
|
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
38
51
|
* @group Adapters
|
|
@@ -69,4 +82,3 @@ export declare class KyselyLockAdapter implements IDatabaseLockAdapter, IDeiniti
|
|
|
69
82
|
refresh(key: string, owner: string, expiration: Date): Promise<number>;
|
|
70
83
|
find(key: string): Promise<ILockData | null>;
|
|
71
84
|
}
|
|
72
|
-
export {};
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { TimeSpan, } from "../../../../utilities/_module-exports.js";
|
|
5
5
|
/**
|
|
6
|
+
* To utilize the `KyselyLockAdapter`, you must install the [`"kysely"`](https://www.npmjs.com/package/kysely) package and configure a `Kysely` class instance.
|
|
7
|
+
*
|
|
8
|
+
* Note in order to use `KyselyLockAdapter` correctly, ensure you use a single, consistent database across all server instances.
|
|
9
|
+
* The adapter have been tested with `sqlite`, `postgres` and `mysql` databases.
|
|
6
10
|
*
|
|
7
11
|
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
8
12
|
* @group Adapters
|
|
@@ -39,7 +43,7 @@ export class KyselyLockAdapter {
|
|
|
39
43
|
if (this.shouldRemoveExpiredKeys && this.timeoutId !== null) {
|
|
40
44
|
clearTimeout(this.timeoutId);
|
|
41
45
|
}
|
|
42
|
-
// Should
|
|
46
|
+
// Should throw if the index does not exists thats why the try catch is used.
|
|
43
47
|
try {
|
|
44
48
|
await this.kysely.schema
|
|
45
49
|
.dropIndex("lock_expiresAt")
|
|
@@ -49,7 +53,7 @@ export class KyselyLockAdapter {
|
|
|
49
53
|
catch {
|
|
50
54
|
/* EMPTY */
|
|
51
55
|
}
|
|
52
|
-
// Should
|
|
56
|
+
// Should throw if the table does not exists thats why the try catch is used.
|
|
53
57
|
try {
|
|
54
58
|
await this.kysely.schema.dropTable("lock").execute();
|
|
55
59
|
}
|
|
@@ -58,20 +62,19 @@ export class KyselyLockAdapter {
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
async init() {
|
|
61
|
-
// Should
|
|
65
|
+
// Should throw if the table already exists thats why the try catch is used.
|
|
62
66
|
try {
|
|
63
67
|
await this.kysely.schema
|
|
64
68
|
.createTable("lock")
|
|
65
|
-
.ifNotExists()
|
|
66
69
|
.addColumn("key", "varchar(255)", (col) => col.primaryKey())
|
|
67
|
-
.addColumn("owner", "varchar(255)")
|
|
70
|
+
.addColumn("owner", "varchar(255)", (col) => col.notNull())
|
|
68
71
|
.addColumn("expiresAt", "bigint")
|
|
69
72
|
.execute();
|
|
70
73
|
}
|
|
71
74
|
catch {
|
|
72
75
|
/* EMPTY */
|
|
73
76
|
}
|
|
74
|
-
// Should
|
|
77
|
+
// Should throw if the index already exists thats why the try catch is used.
|
|
75
78
|
try {
|
|
76
79
|
await this.kysely.schema
|
|
77
80
|
.createIndex("lock_expiresAt")
|
|
@@ -83,7 +86,7 @@ export class KyselyLockAdapter {
|
|
|
83
86
|
/* EMPTY */
|
|
84
87
|
}
|
|
85
88
|
if (this.shouldRemoveExpiredKeys) {
|
|
86
|
-
this.timeoutId =
|
|
89
|
+
this.timeoutId = setInterval(() => {
|
|
87
90
|
void this.removeAllExpired();
|
|
88
91
|
}, this.expiredKeysRemovalInterval.toMilliseconds());
|
|
89
92
|
}
|
|
@@ -143,7 +146,7 @@ export class KyselyLockAdapter {
|
|
|
143
146
|
return null;
|
|
144
147
|
}
|
|
145
148
|
return {
|
|
146
|
-
expiration: row.expiresAt ? new Date(Number(row.expiresAt)) : null,
|
|
149
|
+
expiration: row.expiresAt !== null ? new Date(Number(row.expiresAt)) : null,
|
|
147
150
|
owner: row.owner,
|
|
148
151
|
};
|
|
149
152
|
}
|
|
@@ -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,EAIH,QAAQ,GACX,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"kysely-lock-adapter.js","sourceRoot":"","sources":["../../../../../src/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import { type IDeinitizable, type IInitizable
|
|
4
|
+
import { type IDeinitizable, type IInitizable } 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
|
+
import { ObjectId } from "mongodb";
|
|
7
8
|
/**
|
|
8
9
|
*
|
|
9
10
|
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
@@ -12,20 +13,31 @@ import type { CollectionOptions, Db } from "mongodb";
|
|
|
12
13
|
export type MongodbLockAdapterSettings = {
|
|
13
14
|
database: Db;
|
|
14
15
|
/**
|
|
15
|
-
* @default
|
|
16
|
+
* @default "lock"
|
|
16
17
|
*/
|
|
17
18
|
collectionName?: string;
|
|
18
19
|
collectionSettings?: CollectionOptions;
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
+
*
|
|
23
|
+
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
24
|
+
* @group Adapters
|
|
25
|
+
*/
|
|
26
|
+
export type MongodbLockDocument = {
|
|
27
|
+
_id: ObjectId;
|
|
28
|
+
key: string;
|
|
29
|
+
owner: string;
|
|
30
|
+
expiresAt: Date | null;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* To utilize the `MongodbLockAdapter`, you must install the [`"mongodb"`](https://www.npmjs.com/package/mongodb) package.
|
|
22
34
|
*
|
|
23
35
|
* Note in order to use `MongodbLockAdapter` correctly, ensure you use a single, consistent database across all server instances.
|
|
24
36
|
*
|
|
25
37
|
* IMPORT_PATH: `"@daiso-tech/core/lock/adapters"`
|
|
26
38
|
* @group Adapters
|
|
27
39
|
*/
|
|
28
|
-
export declare class MongodbLockAdapter implements IDatabaseLockAdapter, IDeinitizable, IInitizable
|
|
40
|
+
export declare class MongodbLockAdapter implements IDatabaseLockAdapter, IDeinitizable, IInitizable {
|
|
29
41
|
private readonly database;
|
|
30
42
|
private readonly collection;
|
|
31
43
|
private readonly collectionName;
|
|
@@ -44,8 +56,7 @@ export declare class MongodbLockAdapter implements IDatabaseLockAdapter, IDeinit
|
|
|
44
56
|
* await lockAdapter.init()
|
|
45
57
|
* ```
|
|
46
58
|
*/
|
|
47
|
-
constructor(
|
|
48
|
-
removeAllExpired(): Promise<void>;
|
|
59
|
+
constructor(settings: MongodbLockAdapterSettings);
|
|
49
60
|
/**
|
|
50
61
|
* Creates all related indexes.
|
|
51
62
|
* Note the `init` method needs to be called before using the adapter.
|