@daiso-tech/core 0.27.0 → 0.28.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 +10 -10
- package/dist/async/utilities/lazy-promise/lazy-promise.d.ts +57 -19
- package/dist/async/utilities/lazy-promise/lazy-promise.js +93 -52
- package/dist/async/utilities/lazy-promise/lazy-promise.js.map +1 -1
- package/dist/async/utilities/retry/retry-or-fail.d.ts +2 -0
- package/dist/async/utilities/retry/retry-or-fail.js.map +1 -1
- package/dist/cache/contracts/cache.contract.d.ts +98 -14
- package/dist/cache/implementations/adapters/_module-exports.d.ts +1 -0
- package/dist/cache/implementations/adapters/_module-exports.js +1 -0
- package/dist/cache/implementations/adapters/_module-exports.js.map +1 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.d.ts +1 -0
- package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.js +2 -0
- package/dist/cache/implementations/adapters/no-op-cache-adapter/_module.js.map +1 -0
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +23 -0
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +41 -0
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +1 -0
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.d.ts +2 -3
- package/dist/cache/implementations/adapters/sqlite-cache-adapter/sqlite-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +250 -45
- package/dist/cache/implementations/derivables/cache/cache.js +256 -28
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +20 -17
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js +33 -19
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.d.ts +4 -20
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +7 -4
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +1 -1
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +21 -36
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +24 -17
- 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 +57 -14
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js +61 -13
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/lock/contracts/lock-provider.contract.d.ts +19 -5
- package/dist/lock/contracts/lock.contract.d.ts +37 -8
- package/dist/lock/implementations/adapters/_module-exports.d.ts +1 -0
- package/dist/lock/implementations/adapters/_module-exports.js +1 -0
- package/dist/lock/implementations/adapters/_module-exports.js.map +1 -1
- package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.d.ts +1 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js +2 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/_module.js.map +1 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +17 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +24 -0
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js.map +1 -0
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +2 -3
- package/dist/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +130 -62
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +134 -44
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +238 -0
- package/dist/lock/implementations/derivables/lock-provider/lock.js +258 -0
- 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 +75 -9
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +85 -7
- 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 +162 -8
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.d.ts +1 -0
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js +1 -0
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js.map +1 -1
- package/dist/utilities/_module-exports.d.ts +1 -1
- package/dist/utilities/_module-exports.js +1 -1
- package/dist/utilities/_module-exports.js.map +1 -1
- package/dist/utilities/classes/key-prefixer/key-prefixer.js +1 -1
- package/dist/utilities/classes/key-prefixer/key-prefixer.js.map +1 -1
- package/dist/utilities/{_constants.d.ts → constants.d.ts} +0 -3
- package/dist/utilities/constants.js +5 -0
- package/dist/utilities/constants.js.map +1 -0
- package/dist/utilities/contracts/_module.d.ts +2 -1
- package/dist/utilities/contracts/_module.js +2 -1
- package/dist/utilities/contracts/_module.js.map +1 -1
- package/dist/utilities/contracts/sqlite-database.contract.d.ts +26 -0
- package/dist/utilities/contracts/sqlite-database.contract.js +5 -0
- package/dist/utilities/contracts/sqlite-database.contract.js.map +1 -0
- package/dist/utilities/functions.d.ts +4 -0
- package/dist/utilities/functions.js +10 -4
- package/dist/utilities/functions.js.map +1 -1
- package/dist/utilities/types.d.ts +4 -4
- package/package.json +1 -1
- package/dist/utilities/_constants.js +0 -8
- package/dist/utilities/_constants.js.map +0 -1
package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts
CHANGED
|
@@ -3,17 +3,15 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { BackoffPolicy, RetryPolicy } from "../../../../async/_module-exports.js";
|
|
5
5
|
import type { IGroupableEventBus } from "../../../../event-bus/contracts/_module-exports.js";
|
|
6
|
-
import type {
|
|
7
|
-
import type { ILockProviderFactory } from "../../../../lock/contracts/lock-provider-factory.contract.js";
|
|
8
|
-
import type { IGroupableLockProvider } from "../../../../lock/contracts/lock-provider.contract.js";
|
|
6
|
+
import type { ILockProviderFactory, IGroupableLockProvider } from "../../../../lock/contracts/_module-exports.js";
|
|
9
7
|
import type { IKeyPrefixer, TimeSpan } from "../../../../utilities/_module-exports.js";
|
|
10
|
-
import { type LockProviderSettingsBase } from "../../../../lock/implementations/derivables/lock-provider/_module.js";
|
|
8
|
+
import { type LockAdapterFactoryable, type LockProviderSettingsBase } from "../../../../lock/implementations/derivables/lock-provider/_module.js";
|
|
11
9
|
/**
|
|
12
10
|
*
|
|
13
11
|
* IMPORT_PATH: ```"@daiso-tech/core/lock"```
|
|
14
12
|
* @group Derivables
|
|
15
13
|
*/
|
|
16
|
-
export type LockAdapters<TAdapters extends string> = Partial<Record<TAdapters,
|
|
14
|
+
export type LockAdapters<TAdapters extends string> = Partial<Record<TAdapters, LockAdapterFactoryable>>;
|
|
17
15
|
/**
|
|
18
16
|
*
|
|
19
17
|
* IMPORT_PATH: ```"@daiso-tech/core/lock"```
|
|
@@ -30,6 +28,48 @@ export type LockProviderFactorySettings<TAdapters extends string> = LockProvider
|
|
|
30
28
|
*/
|
|
31
29
|
export declare class LockProviderFactory<TAdapters extends string> implements ILockProviderFactory<TAdapters> {
|
|
32
30
|
private readonly settings;
|
|
31
|
+
/**
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { LockProviderFactory } from "@daiso-tech/core/lock";
|
|
35
|
+
* import type { ILockAdapter } from "@daiso-tech/core/lock/contracts";
|
|
36
|
+
* import { MemoryLockAdapter, RedisLockAdapter, SqliteLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
37
|
+
* import { Serde } from "@daiso-tech/core/serde";
|
|
38
|
+
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
39
|
+
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
|
|
40
|
+
* import { KeyPrefixer, TimeSpan, type ISqliteDatabase, type FactoryFn } from "@daiso-tech/core/utilities";
|
|
41
|
+
* import Redis from "ioredis"
|
|
42
|
+
* import Sqlite from "better-sqlite3";
|
|
43
|
+
*
|
|
44
|
+
* function lockAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>): FactoryFn<string, ILockAdapter> {
|
|
45
|
+
* return async (prefix) => {
|
|
46
|
+
* const lockAdapter = new SqliteLockAdapter({
|
|
47
|
+
* database,
|
|
48
|
+
* serde,
|
|
49
|
+
* tableName: `lock_${prefix}`
|
|
50
|
+
* });
|
|
51
|
+
* await lockAdapter.init();
|
|
52
|
+
* return lockAdapter;
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* const database = new Sqlite("local.db");
|
|
57
|
+
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
58
|
+
* const lockProviderFactory = new LockProviderFactory({
|
|
59
|
+
* serde,
|
|
60
|
+
* keyPrefixer: new KeyPrefixer("lock"),
|
|
61
|
+
* adapters: {
|
|
62
|
+
* sqlite: lockAdapterFactory(database, serde),
|
|
63
|
+
* memory: new MemoryLockAdapter(),
|
|
64
|
+
* redis: new RedisLockAdapter({
|
|
65
|
+
* client: new Redis("YOUR_REDIS_CONNECTION"),
|
|
66
|
+
* serde,
|
|
67
|
+
* }),
|
|
68
|
+
* },
|
|
69
|
+
* defaultAdapter: "memory",
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
33
73
|
constructor(settings: LockProviderFactorySettings<TAdapters>);
|
|
34
74
|
setKeyPrefixer(keyPrefixer: IKeyPrefixer): LockProviderFactory<TAdapters>;
|
|
35
75
|
setCreateOwnerId(createId: () => string): LockProviderFactory<TAdapters>;
|
|
@@ -41,19 +81,45 @@ export declare class LockProviderFactory<TAdapters extends string> implements IL
|
|
|
41
81
|
setRetryAttempts(attempts: number): LockProviderFactory<TAdapters>;
|
|
42
82
|
setBackoffPolicy(policy: BackoffPolicy): LockProviderFactory<TAdapters>;
|
|
43
83
|
setRetryPolicy(policy: RetryPolicy): LockProviderFactory<TAdapters>;
|
|
44
|
-
|
|
84
|
+
setRetryTimeout(timeout: TimeSpan): LockProviderFactory<TAdapters>;
|
|
85
|
+
setTotalTimeout(timeout: TimeSpan): LockProviderFactory<TAdapters>;
|
|
45
86
|
/**
|
|
46
87
|
* @example
|
|
47
88
|
* ```ts
|
|
48
89
|
* import { LockProviderFactory } from "@daiso-tech/core/lock";
|
|
49
|
-
* import {
|
|
90
|
+
* import type { ILockAdapter } from "@daiso-tech/core/lock/contracts";
|
|
91
|
+
* import { MemoryLockAdapter, RedisLockAdapter, SqliteLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
92
|
+
* import { Serde } from "@daiso-tech/core/serde";
|
|
93
|
+
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
94
|
+
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
|
|
95
|
+
* import { KeyPrefixer, TimeSpan, type ISqliteDatabase, type FactoryFn } from "@daiso-tech/core/utilities";
|
|
50
96
|
* import Redis from "ioredis"
|
|
97
|
+
* import Sqlite from "better-sqlite3";
|
|
98
|
+
*
|
|
99
|
+
* function lockAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>): FactoryFn<string, ILockAdapter> {
|
|
100
|
+
* return async (prefix) => {
|
|
101
|
+
* const lockAdapter = new SqliteLockAdapter({
|
|
102
|
+
* database,
|
|
103
|
+
* serde,
|
|
104
|
+
* tableName: `lock_${prefix}`
|
|
105
|
+
* });
|
|
106
|
+
* await lockAdapter.init();
|
|
107
|
+
* return lockAdapter;
|
|
108
|
+
* }
|
|
109
|
+
* }
|
|
51
110
|
*
|
|
111
|
+
* const database = new Sqlite("local.db");
|
|
112
|
+
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
52
113
|
* const lockProviderFactory = new LockProviderFactory({
|
|
114
|
+
* serde,
|
|
53
115
|
* keyPrefixer: new KeyPrefixer("lock"),
|
|
54
116
|
* adapters: {
|
|
117
|
+
* sqlite: lockAdapterFactory(database, serde),
|
|
55
118
|
* memory: new MemoryLockAdapter(),
|
|
56
|
-
* redis: new RedisLockAdapter(
|
|
119
|
+
* redis: new RedisLockAdapter({
|
|
120
|
+
* client: new Redis("YOUR_REDIS_CONNECTION"),
|
|
121
|
+
* serde,
|
|
122
|
+
* }),
|
|
57
123
|
* },
|
|
58
124
|
* defaultAdapter: "memory",
|
|
59
125
|
* });
|
|
@@ -88,7 +154,7 @@ export declare class LockProviderFactory<TAdapters extends string> implements IL
|
|
|
88
154
|
*
|
|
89
155
|
* // You can extend the settings
|
|
90
156
|
* const extendedLockProviderFactory = longLivedLockProviderFactory
|
|
91
|
-
* .
|
|
157
|
+
* .setRetryTimeout(TimeSpan.fromSeconds(1));
|
|
92
158
|
*
|
|
93
159
|
* await extendedLockProviderFactory
|
|
94
160
|
* .use()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import { DefaultAdapterNotDefinedError, UnregisteredAdapterError, } from "../../../../utilities/_module-exports.js";
|
|
4
|
+
import { DefaultAdapterNotDefinedError, KeyPrefixer, resolveOneOrMore, UnregisteredAdapterError, } from "../../../../utilities/_module-exports.js";
|
|
5
5
|
import { LockProvider, } from "../../../../lock/implementations/derivables/lock-provider/_module.js";
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
@@ -10,6 +10,48 @@ import { LockProvider, } from "../../../../lock/implementations/derivables/lock-
|
|
|
10
10
|
*/
|
|
11
11
|
export class LockProviderFactory {
|
|
12
12
|
settings;
|
|
13
|
+
/**
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { LockProviderFactory } from "@daiso-tech/core/lock";
|
|
17
|
+
* import type { ILockAdapter } from "@daiso-tech/core/lock/contracts";
|
|
18
|
+
* import { MemoryLockAdapter, RedisLockAdapter, SqliteLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
19
|
+
* import { Serde } from "@daiso-tech/core/serde";
|
|
20
|
+
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
21
|
+
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
|
|
22
|
+
* import { KeyPrefixer, TimeSpan, type ISqliteDatabase, type FactoryFn } from "@daiso-tech/core/utilities";
|
|
23
|
+
* import Redis from "ioredis"
|
|
24
|
+
* import Sqlite from "better-sqlite3";
|
|
25
|
+
*
|
|
26
|
+
* function lockAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>): FactoryFn<string, ILockAdapter> {
|
|
27
|
+
* return async (prefix) => {
|
|
28
|
+
* const lockAdapter = new SqliteLockAdapter({
|
|
29
|
+
* database,
|
|
30
|
+
* serde,
|
|
31
|
+
* tableName: `lock_${prefix}`
|
|
32
|
+
* });
|
|
33
|
+
* await lockAdapter.init();
|
|
34
|
+
* return lockAdapter;
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* const database = new Sqlite("local.db");
|
|
39
|
+
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
40
|
+
* const lockProviderFactory = new LockProviderFactory({
|
|
41
|
+
* serde,
|
|
42
|
+
* keyPrefixer: new KeyPrefixer("lock"),
|
|
43
|
+
* adapters: {
|
|
44
|
+
* sqlite: lockAdapterFactory(database, serde),
|
|
45
|
+
* memory: new MemoryLockAdapter(),
|
|
46
|
+
* redis: new RedisLockAdapter({
|
|
47
|
+
* client: new Redis("YOUR_REDIS_CONNECTION"),
|
|
48
|
+
* serde,
|
|
49
|
+
* }),
|
|
50
|
+
* },
|
|
51
|
+
* defaultAdapter: "memory",
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
13
55
|
constructor(settings) {
|
|
14
56
|
this.settings = settings;
|
|
15
57
|
}
|
|
@@ -73,24 +115,55 @@ export class LockProviderFactory {
|
|
|
73
115
|
retryPolicy: policy,
|
|
74
116
|
});
|
|
75
117
|
}
|
|
76
|
-
|
|
118
|
+
setRetryTimeout(timeout) {
|
|
77
119
|
return new LockProviderFactory({
|
|
78
120
|
...this.settings,
|
|
79
|
-
timeout,
|
|
121
|
+
retryTimeout: timeout,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
setTotalTimeout(timeout) {
|
|
125
|
+
return new LockProviderFactory({
|
|
126
|
+
...this.settings,
|
|
127
|
+
totalTimeout: timeout,
|
|
80
128
|
});
|
|
81
129
|
}
|
|
82
130
|
/**
|
|
83
131
|
* @example
|
|
84
132
|
* ```ts
|
|
85
133
|
* import { LockProviderFactory } from "@daiso-tech/core/lock";
|
|
86
|
-
* import {
|
|
134
|
+
* import type { ILockAdapter } from "@daiso-tech/core/lock/contracts";
|
|
135
|
+
* import { MemoryLockAdapter, RedisLockAdapter, SqliteLockAdapter } from "@daiso-tech/core/lock/adapters";
|
|
136
|
+
* import { Serde } from "@daiso-tech/core/serde";
|
|
137
|
+
* import type { ISerde } from "@daiso-tech/core/serde/contracts";
|
|
138
|
+
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters";
|
|
139
|
+
* import { KeyPrefixer, TimeSpan, type ISqliteDatabase, type FactoryFn } from "@daiso-tech/core/utilities";
|
|
87
140
|
* import Redis from "ioredis"
|
|
141
|
+
* import Sqlite from "better-sqlite3";
|
|
142
|
+
*
|
|
143
|
+
* function lockAdapterFactory(database: ISqliteDatabase, serde: ISerde<string>): FactoryFn<string, ILockAdapter> {
|
|
144
|
+
* return async (prefix) => {
|
|
145
|
+
* const lockAdapter = new SqliteLockAdapter({
|
|
146
|
+
* database,
|
|
147
|
+
* serde,
|
|
148
|
+
* tableName: `lock_${prefix}`
|
|
149
|
+
* });
|
|
150
|
+
* await lockAdapter.init();
|
|
151
|
+
* return lockAdapter;
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
88
154
|
*
|
|
155
|
+
* const database = new Sqlite("local.db");
|
|
156
|
+
* const serde = new Serde(new SuperJsonSerdeAdapter());
|
|
89
157
|
* const lockProviderFactory = new LockProviderFactory({
|
|
158
|
+
* serde,
|
|
90
159
|
* keyPrefixer: new KeyPrefixer("lock"),
|
|
91
160
|
* adapters: {
|
|
161
|
+
* sqlite: lockAdapterFactory(database, serde),
|
|
92
162
|
* memory: new MemoryLockAdapter(),
|
|
93
|
-
* redis: new RedisLockAdapter(
|
|
163
|
+
* redis: new RedisLockAdapter({
|
|
164
|
+
* client: new Redis("YOUR_REDIS_CONNECTION"),
|
|
165
|
+
* serde,
|
|
166
|
+
* }),
|
|
94
167
|
* },
|
|
95
168
|
* defaultAdapter: "memory",
|
|
96
169
|
* });
|
|
@@ -125,7 +198,7 @@ export class LockProviderFactory {
|
|
|
125
198
|
*
|
|
126
199
|
* // You can extend the settings
|
|
127
200
|
* const extendedLockProviderFactory = longLivedLockProviderFactory
|
|
128
|
-
* .
|
|
201
|
+
* .setRetryTimeout(TimeSpan.fromSeconds(1));
|
|
129
202
|
*
|
|
130
203
|
* await extendedLockProviderFactory
|
|
131
204
|
* .use()
|
|
@@ -141,9 +214,14 @@ export class LockProviderFactory {
|
|
|
141
214
|
if (adapter === undefined) {
|
|
142
215
|
throw new UnregisteredAdapterError(adapterName);
|
|
143
216
|
}
|
|
217
|
+
const { keyPrefixer } = this.settings;
|
|
144
218
|
return new LockProvider({
|
|
145
|
-
adapter,
|
|
146
219
|
...this.settings,
|
|
220
|
+
adapter,
|
|
221
|
+
keyPrefixer: new KeyPrefixer([
|
|
222
|
+
...resolveOneOrMore(keyPrefixer.originalRootPrefix),
|
|
223
|
+
adapterName,
|
|
224
|
+
]),
|
|
147
225
|
});
|
|
148
226
|
}
|
|
149
227
|
}
|
package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock-provider-factory.js","sourceRoot":"","sources":["../../../../../src/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"lock-provider-factory.js","sourceRoot":"","sources":["../../../../../src/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.ts"],"names":[],"mappings":"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"}
|
|
@@ -215,6 +215,78 @@ export function lockProviderTestSuite(settings) {
|
|
|
215
215
|
expect(index).toBeGreaterThan(1);
|
|
216
216
|
});
|
|
217
217
|
});
|
|
218
|
+
describe("method: runBlockingOrFail", () => {
|
|
219
|
+
test("Should return string when lock is available", async () => {
|
|
220
|
+
const key = "a";
|
|
221
|
+
const ttl = null;
|
|
222
|
+
const lock = lockProviderA.create(key, {
|
|
223
|
+
ttl,
|
|
224
|
+
});
|
|
225
|
+
const result = await lock.runBlockingOrFail(async () => {
|
|
226
|
+
await LazyPromise.delay(DELAY_TIME);
|
|
227
|
+
return "a";
|
|
228
|
+
}, {
|
|
229
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
230
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
231
|
+
});
|
|
232
|
+
expect(result).toBe("a");
|
|
233
|
+
});
|
|
234
|
+
test("Should throw KeyAlreadyAcquiredLockError when lock is already acquired", async () => {
|
|
235
|
+
const key = "a";
|
|
236
|
+
const ttl = null;
|
|
237
|
+
const lock = lockProviderA.create(key, {
|
|
238
|
+
ttl,
|
|
239
|
+
});
|
|
240
|
+
await lock.acquire();
|
|
241
|
+
const promise = lock.runBlockingOrFail(async () => {
|
|
242
|
+
await LazyPromise.delay(DELAY_TIME);
|
|
243
|
+
return "a";
|
|
244
|
+
}, {
|
|
245
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
246
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
247
|
+
});
|
|
248
|
+
await expect(promise).rejects.toBeInstanceOf(KeyAlreadyAcquiredLockError);
|
|
249
|
+
});
|
|
250
|
+
test("Should work with LazyPromise", async () => {
|
|
251
|
+
const key = "a";
|
|
252
|
+
const ttl = null;
|
|
253
|
+
const lock = lockProviderA.create(key, {
|
|
254
|
+
ttl,
|
|
255
|
+
});
|
|
256
|
+
const result = await lock.runBlockingOrFail(new LazyPromise(async () => {
|
|
257
|
+
await LazyPromise.delay(DELAY_TIME);
|
|
258
|
+
return "a";
|
|
259
|
+
}), {
|
|
260
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
261
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
262
|
+
});
|
|
263
|
+
expect(result).toBe("a");
|
|
264
|
+
});
|
|
265
|
+
test("Should retry acquire the lock", async () => {
|
|
266
|
+
const key = "a";
|
|
267
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
268
|
+
const lock = lockProviderA.create(key, {
|
|
269
|
+
ttl,
|
|
270
|
+
});
|
|
271
|
+
await lock.acquire();
|
|
272
|
+
let index = 0;
|
|
273
|
+
await lock.addListener(KeyAlreadyAcquiredLockEvent, (_event) => {
|
|
274
|
+
index++;
|
|
275
|
+
});
|
|
276
|
+
try {
|
|
277
|
+
await lock.runBlockingOrFail(async () => {
|
|
278
|
+
await LazyPromise.delay(DELAY_TIME);
|
|
279
|
+
}, {
|
|
280
|
+
time: TimeSpan.fromMilliseconds(55),
|
|
281
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
/* Empty */
|
|
286
|
+
}
|
|
287
|
+
expect(index).toBeGreaterThan(1);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
218
290
|
describe("method: acquire", () => {
|
|
219
291
|
test("Should return true when lock is available", async () => {
|
|
220
292
|
const key = "a";
|
|
@@ -301,12 +373,12 @@ export function lockProviderTestSuite(settings) {
|
|
|
301
373
|
ttl,
|
|
302
374
|
});
|
|
303
375
|
await lock.acquireBlocking({
|
|
304
|
-
time: TimeSpan.fromMilliseconds(
|
|
305
|
-
interval: TimeSpan.fromMilliseconds(
|
|
376
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
377
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
306
378
|
});
|
|
307
379
|
const result = await lock.acquireBlocking({
|
|
308
|
-
time: TimeSpan.fromMilliseconds(
|
|
309
|
-
interval: TimeSpan.fromMilliseconds(
|
|
380
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
381
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
310
382
|
});
|
|
311
383
|
expect(result).toBe(false);
|
|
312
384
|
});
|
|
@@ -319,8 +391,8 @@ export function lockProviderTestSuite(settings) {
|
|
|
319
391
|
owner,
|
|
320
392
|
});
|
|
321
393
|
await lock.acquireBlocking({
|
|
322
|
-
time: TimeSpan.fromMilliseconds(
|
|
323
|
-
interval: TimeSpan.fromMilliseconds(
|
|
394
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
395
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
324
396
|
});
|
|
325
397
|
const result = await lock.isExpired();
|
|
326
398
|
expect(result).toBe(false);
|
|
@@ -334,8 +406,8 @@ export function lockProviderTestSuite(settings) {
|
|
|
334
406
|
owner,
|
|
335
407
|
});
|
|
336
408
|
await lock.acquireBlocking({
|
|
337
|
-
time: TimeSpan.fromMilliseconds(
|
|
338
|
-
interval: TimeSpan.fromMilliseconds(
|
|
409
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
410
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
339
411
|
});
|
|
340
412
|
const result = await lock.isLocked();
|
|
341
413
|
expect(result).toBe(true);
|
|
@@ -358,6 +430,88 @@ export function lockProviderTestSuite(settings) {
|
|
|
358
430
|
expect(index).toBeGreaterThan(1);
|
|
359
431
|
});
|
|
360
432
|
});
|
|
433
|
+
describe("method: acquireBlockingOrFail", () => {
|
|
434
|
+
test("Should not throw KeyAlreadyAcquiredLockError when lock is available", async () => {
|
|
435
|
+
const key = "a";
|
|
436
|
+
const ttl = null;
|
|
437
|
+
const lock = lockProviderA.create(key, {
|
|
438
|
+
ttl,
|
|
439
|
+
});
|
|
440
|
+
const promise = lock.acquireBlockingOrFail({
|
|
441
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
442
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
443
|
+
});
|
|
444
|
+
await expect(promise).resolves.toBeUndefined();
|
|
445
|
+
});
|
|
446
|
+
test("Should throw KeyAlreadyAcquiredLockError when lock is already acquired", async () => {
|
|
447
|
+
const key = "a";
|
|
448
|
+
const ttl = null;
|
|
449
|
+
const lock = lockProviderA.create(key, {
|
|
450
|
+
ttl,
|
|
451
|
+
});
|
|
452
|
+
await lock.acquireBlockingOrFail({
|
|
453
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
454
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
455
|
+
});
|
|
456
|
+
const promise = lock.acquireBlockingOrFail({
|
|
457
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
458
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
459
|
+
});
|
|
460
|
+
await expect(promise).rejects.toBeInstanceOf(KeyAlreadyAcquiredLockError);
|
|
461
|
+
});
|
|
462
|
+
test("Should not be expired when released by same owner", async () => {
|
|
463
|
+
const key = "a";
|
|
464
|
+
const ttl = null;
|
|
465
|
+
const owner = "b";
|
|
466
|
+
const lock = lockProviderA.create(key, {
|
|
467
|
+
ttl,
|
|
468
|
+
owner,
|
|
469
|
+
});
|
|
470
|
+
await lock.acquireBlockingOrFail({
|
|
471
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
472
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
473
|
+
});
|
|
474
|
+
const result = await lock.isExpired();
|
|
475
|
+
expect(result).toBe(false);
|
|
476
|
+
});
|
|
477
|
+
test("Should be loked when released by same owner", async () => {
|
|
478
|
+
const key = "a";
|
|
479
|
+
const ttl = null;
|
|
480
|
+
const owner = "b";
|
|
481
|
+
const lock = lockProviderA.create(key, {
|
|
482
|
+
ttl,
|
|
483
|
+
owner,
|
|
484
|
+
});
|
|
485
|
+
await lock.acquireBlockingOrFail({
|
|
486
|
+
time: TimeSpan.fromMilliseconds(5),
|
|
487
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
488
|
+
});
|
|
489
|
+
const result = await lock.isLocked();
|
|
490
|
+
expect(result).toBe(true);
|
|
491
|
+
});
|
|
492
|
+
test("Should retry acquire the lock", async () => {
|
|
493
|
+
const key = "a";
|
|
494
|
+
const ttl = TimeSpan.fromMilliseconds(50);
|
|
495
|
+
const lock = lockProviderA.create(key, {
|
|
496
|
+
ttl,
|
|
497
|
+
});
|
|
498
|
+
await lock.acquire();
|
|
499
|
+
let index = 0;
|
|
500
|
+
await lock.addListener(KeyAlreadyAcquiredLockEvent, (_event) => {
|
|
501
|
+
index++;
|
|
502
|
+
});
|
|
503
|
+
try {
|
|
504
|
+
await lock.acquireBlockingOrFail({
|
|
505
|
+
time: TimeSpan.fromMilliseconds(55),
|
|
506
|
+
interval: TimeSpan.fromMilliseconds(5),
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
catch {
|
|
510
|
+
/* Empty */
|
|
511
|
+
}
|
|
512
|
+
expect(index).toBeGreaterThan(1);
|
|
513
|
+
});
|
|
514
|
+
});
|
|
361
515
|
describe("method: release", () => {
|
|
362
516
|
test("Should return true when released by same owner", async () => {
|
|
363
517
|
const key = "a";
|