@daiso-tech/core 0.22.2 → 0.23.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/dist/cjs/lock/contracts/lock.errors.js +4 -4
- package/dist/cjs/lock/contracts/lock.errors.js.map +1 -1
- package/dist/cjs/lock/implementations/_shared/lock-adapter.test-suite.js +0 -129
- package/dist/cjs/lock/implementations/_shared/lock-adapter.test-suite.js.map +1 -1
- package/dist/cjs/lock/implementations/_shared/lock-provider.test-suite.js +487 -489
- package/dist/cjs/lock/implementations/_shared/lock-provider.test-suite.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +0 -16
- package/dist/cjs/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +5 -5
- package/dist/cjs/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +0 -13
- package/dist/cjs/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider/database-lock-adapter.js +0 -32
- package/dist/cjs/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock-provider.js +22 -12
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock-state.js +58 -0
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock-state.js.map +1 -0
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock.js +32 -39
- package/dist/cjs/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +1 -1
- package/dist/cjs/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/cjs/utilities/contracts/_module.js +0 -1
- package/dist/cjs/utilities/contracts/_module.js.map +1 -1
- package/dist/esm/lock/contracts/lock.errors.js +2 -2
- package/dist/esm/lock/contracts/lock.errors.js.map +1 -1
- package/dist/esm/lock/implementations/_shared/lock-adapter.test-suite.js +0 -129
- package/dist/esm/lock/implementations/_shared/lock-adapter.test-suite.js.map +1 -1
- package/dist/esm/lock/implementations/_shared/lock-provider.test-suite.js +488 -490
- package/dist/esm/lock/implementations/_shared/lock-provider.test-suite.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +1 -1
- package/dist/esm/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js +1 -1
- package/dist/esm/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +1 -17
- package/dist/esm/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +6 -6
- package/dist/esm/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +1 -14
- package/dist/esm/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js +1 -1
- package/dist/esm/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider/database-lock-adapter.js +1 -33
- package/dist/esm/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider/lock-provider.js +22 -12
- package/dist/esm/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider/lock-state.js +54 -0
- package/dist/esm/lock/implementations/derivables/lock-provider/lock-state.js.map +1 -0
- package/dist/esm/lock/implementations/derivables/lock-provider/lock.js +33 -40
- package/dist/esm/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js +1 -1
- package/dist/esm/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/esm/utilities/contracts/_module.js +0 -1
- package/dist/esm/utilities/contracts/_module.js.map +1 -1
- package/dist/types/lock/contracts/database-lock-adapter.contract.d.ts +1 -2
- package/dist/types/lock/contracts/lock-adapter.contract.d.ts +0 -9
- package/dist/types/lock/contracts/lock.contract.d.ts +1 -1
- package/dist/types/lock/contracts/lock.errors.d.ts +2 -2
- package/dist/types/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +2 -2
- package/dist/types/lock/implementations/adapters/libsql-lock-adapter/libsql-lock-adapter.d.ts +2 -2
- package/dist/types/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +1 -3
- package/dist/types/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +2 -1
- package/dist/types/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +1 -3
- package/dist/types/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts +2 -2
- package/dist/types/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +2 -7
- package/dist/types/lock/implementations/derivables/lock-provider/lock-provider.d.ts +8 -10
- package/dist/types/lock/implementations/derivables/lock-provider/lock-state.d.ts +40 -0
- package/dist/types/lock/implementations/derivables/lock-provider/lock.d.ts +8 -2
- package/dist/types/utilities/contracts/_module.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/utilities/contracts/serde-registrable.contract.js +0 -3
- package/dist/cjs/utilities/contracts/serde-registrable.contract.js.map +0 -1
- package/dist/esm/utilities/contracts/serde-registrable.contract.js +0 -1
- package/dist/esm/utilities/contracts/serde-registrable.contract.js.map +0 -1
- package/dist/types/utilities/contracts/serde-registrable.contract.d.ts +0 -11
package/dist/types/lock/implementations/adapters/sqlite-lock-adapter/sqlite-lock-adapter.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
4
|
import type { IDatabaseLockAdapter, ILockData } from "../../../../lock/contracts/_module";
|
|
5
|
-
import { TimeSpan } from "../../../../utilities/_module";
|
|
5
|
+
import { type IDeinitizable, type IInitizable, TimeSpan } from "../../../../utilities/_module";
|
|
6
6
|
import type { SqliteDatabase } from "kysely";
|
|
7
7
|
/**
|
|
8
8
|
* @group Adapters
|
|
@@ -17,7 +17,7 @@ export type SqliteLockAdapterSettings = {
|
|
|
17
17
|
/**
|
|
18
18
|
* @group Adapters
|
|
19
19
|
*/
|
|
20
|
-
export declare class SqliteLockAdapter implements IDatabaseLockAdapter {
|
|
20
|
+
export declare class SqliteLockAdapter implements IDatabaseLockAdapter, IDeinitizable, IInitizable {
|
|
21
21
|
private databaseLockAdapter;
|
|
22
22
|
/**
|
|
23
23
|
* @example
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
5
|
-
import { TimeSpan } from "../../../../_module";
|
|
4
|
+
import type { TimeSpan } from "../../../../_module";
|
|
6
5
|
import type { IDatabaseLockAdapter, ILockAdapter } from "../../../../lock/contracts/_module";
|
|
7
6
|
/**
|
|
8
7
|
* @internal
|
|
9
8
|
*/
|
|
10
|
-
export declare class DatabaseLockAdapter implements ILockAdapter
|
|
9
|
+
export declare class DatabaseLockAdapter implements ILockAdapter {
|
|
11
10
|
private readonly adapter;
|
|
12
11
|
constructor(adapter: IDatabaseLockAdapter);
|
|
13
|
-
init(): Promise<void>;
|
|
14
|
-
deInit(): Promise<void>;
|
|
15
12
|
acquire(key: string, owner: string, ttl: TimeSpan | null): Promise<boolean>;
|
|
16
13
|
release(key: string, owner: string): Promise<boolean>;
|
|
17
14
|
forceRelease(key: string): Promise<void>;
|
|
18
|
-
isLocked(key: string): Promise<boolean>;
|
|
19
|
-
getRemainingTime(key: string): Promise<TimeSpan | null>;
|
|
20
15
|
refresh(key: string, owner: string, ttl: TimeSpan): Promise<boolean>;
|
|
21
16
|
getGroup(): string;
|
|
22
17
|
withGroup(group: string): ILockAdapter;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Lock
|
|
3
3
|
*/
|
|
4
|
-
import type { ISerdeRegistrable } from "../../../../utilities/_module";
|
|
5
4
|
import { TimeSpan, type OneOrMore } from "../../../../utilities/_module";
|
|
6
5
|
import type { IDatabaseLockAdapter, LockEvents } from "../../../../lock/contracts/_module";
|
|
7
6
|
import { type ILock, type IGroupableLockProvider, type LockProviderCreateSettings, type ILockProvider, type ILockAdapter } from "../../../../lock/contracts/_module";
|
|
@@ -18,6 +17,7 @@ export type LockProviderSettings = {
|
|
|
18
17
|
*/
|
|
19
18
|
createOwnerId?: () => string;
|
|
20
19
|
adapter: ILockAdapter | IDatabaseLockAdapter;
|
|
20
|
+
serde: OneOrMore<IFlexibleSerde>;
|
|
21
21
|
/**
|
|
22
22
|
* In order to listen to events of <i>{@link LockProvider}</i> class you must pass in <i>{@link IGroupableEventBus}</i>.
|
|
23
23
|
*/
|
|
@@ -57,10 +57,11 @@ export type LockProviderSettings = {
|
|
|
57
57
|
* <i>LockProvider</i> class can be derived from any <i>{@link ILockAdapter}</i> or <i>{@link IDatabaseLockAdapter}</i>.
|
|
58
58
|
* @group Derivables
|
|
59
59
|
*/
|
|
60
|
-
export declare class LockProvider implements IGroupableLockProvider,
|
|
60
|
+
export declare class LockProvider implements IGroupableLockProvider, ISerdeTransformer<Lock, ISerializedLock> {
|
|
61
61
|
private static DEFAULT_TTL;
|
|
62
62
|
private static DEFAULT_REFRESH_TIME;
|
|
63
63
|
private static isDatabaseAdapter;
|
|
64
|
+
private readonly serde;
|
|
64
65
|
private readonly createOwnerId;
|
|
65
66
|
private readonly adapter;
|
|
66
67
|
private readonly defaultTtl;
|
|
@@ -71,7 +72,7 @@ export declare class LockProvider implements IGroupableLockProvider, ISerdeRegis
|
|
|
71
72
|
private readonly timeout;
|
|
72
73
|
private readonly eventBus;
|
|
73
74
|
private readonly lockProviderEventBus;
|
|
74
|
-
|
|
75
|
+
private stateRecord;
|
|
75
76
|
/**
|
|
76
77
|
*@example
|
|
77
78
|
* ```ts
|
|
@@ -80,19 +81,20 @@ export declare class LockProvider implements IGroupableLockProvider, ISerdeRegis
|
|
|
80
81
|
* const eventBus = new EventBus({
|
|
81
82
|
* adapter: new MemoryEventBusAdapter({ rootGroup: "@global" })
|
|
82
83
|
* });
|
|
84
|
+
* const serde = new SuperJsonSerde();
|
|
83
85
|
* const lockProvider = new LockProvider({
|
|
86
|
+
* serde,
|
|
84
87
|
* adapter: new MemoryLockAdapter({
|
|
85
88
|
* rootGroup: "@global"
|
|
86
89
|
* }),
|
|
87
90
|
* eventBus,
|
|
88
91
|
* });
|
|
89
|
-
* const serde = new SuperJsonSerde();
|
|
90
|
-
* lockProvider.registerToSerde(serde);
|
|
91
92
|
* registerLockEvents(serde);
|
|
92
93
|
* reigsterLockErrors(serde);
|
|
93
94
|
* ```
|
|
94
95
|
*/
|
|
95
96
|
constructor(settings: LockProviderSettings);
|
|
97
|
+
private registerToSerde;
|
|
96
98
|
addListener<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener: Listener<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
97
99
|
addListenerMany<TEventClass extends EventClass<LockEvents>>(events: TEventClass[], listener: Listener<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
98
100
|
removeListener<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener: Listener<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
@@ -100,15 +102,11 @@ export declare class LockProvider implements IGroupableLockProvider, ISerdeRegis
|
|
|
100
102
|
listenOnce<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener: Listener<EventInstance<TEventClass>>): LazyPromise<void>;
|
|
101
103
|
subscribe<TEventClass extends EventClass<LockEvents>>(event: TEventClass, listener: Listener<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
|
|
102
104
|
subscribeMany<TEventClass extends EventClass<LockEvents>>(events: TEventClass[], listener: Listener<EventInstance<TEventClass>>): LazyPromise<Unsubscribe>;
|
|
105
|
+
get name(): string;
|
|
103
106
|
isApplicable(value: unknown): value is Lock;
|
|
104
107
|
serialize(deserializedValue: Lock): ISerializedLock;
|
|
105
108
|
deserialize(serializedValue: ISerializedLock): Lock;
|
|
106
109
|
create(key: OneOrMore<string>, settings?: LockProviderCreateSettings): ILock;
|
|
107
110
|
getGroup(): string;
|
|
108
111
|
withGroup(group: OneOrMore<string>): ILockProvider;
|
|
109
|
-
/**
|
|
110
|
-
* The <i>registerToSerde</i> method ensures that the <i>ILock</i> instance returned by the <i>create</i> method is serializable.
|
|
111
|
-
* This method must be called once before using the <i>LockProvider</i> class.
|
|
112
|
-
*/
|
|
113
|
-
registerToSerde(serde: OneOrMore<IFlexibleSerde>): void;
|
|
114
112
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TimeSpan } from "../../../../utilities/_module";
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export type ILockStateData = {
|
|
6
|
+
expiration: Date | null;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export type ILockStateRecord = Partial<Record<string, ILockStateData>>;
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare class LockState {
|
|
16
|
+
private stateRecord;
|
|
17
|
+
private readonly key;
|
|
18
|
+
constructor(stateRecord: ILockStateRecord, key: string);
|
|
19
|
+
/**
|
|
20
|
+
* Return the expiration as a date.
|
|
21
|
+
*/
|
|
22
|
+
get(): Date | null;
|
|
23
|
+
/**
|
|
24
|
+
* Sets the expiration time.
|
|
25
|
+
* If a number is provided, it must be in milliseconds.
|
|
26
|
+
*/
|
|
27
|
+
set(ttl: TimeSpan | number | null): void;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if the key is expired.
|
|
30
|
+
*/
|
|
31
|
+
isExpired(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the remaining time.
|
|
34
|
+
*/
|
|
35
|
+
getRemainingTime(): TimeSpan | null;
|
|
36
|
+
/**
|
|
37
|
+
* Removes the expiration from the record.
|
|
38
|
+
*/
|
|
39
|
+
remove(): void;
|
|
40
|
+
}
|
|
@@ -8,6 +8,7 @@ import { LazyPromise } from "../../../../async/_module";
|
|
|
8
8
|
import type { ILockAdapter, LockEvents } from "../../../../lock/contracts/_module";
|
|
9
9
|
import { KeyAlreadyAcquiredLockError, type ILock } from "../../../../lock/contracts/_module";
|
|
10
10
|
import type { EventClass, Listener, EventInstance, Unsubscribe, IGroupableEventBus, IEventDispatcher } from "../../../../event-bus/contracts/_module";
|
|
11
|
+
import { type ILockStateRecord } from "../../../../lock/implementations/derivables/lock-provider/lock-state";
|
|
11
12
|
/**
|
|
12
13
|
* @group Derivables
|
|
13
14
|
*/
|
|
@@ -16,6 +17,7 @@ export type ISerializedLock = {
|
|
|
16
17
|
key: string;
|
|
17
18
|
owner: string;
|
|
18
19
|
ttlInMs: number | null;
|
|
20
|
+
expirationInMs: number | null;
|
|
19
21
|
};
|
|
20
22
|
/**
|
|
21
23
|
* @internal
|
|
@@ -28,12 +30,14 @@ export type LockSettings = {
|
|
|
28
30
|
owner: string;
|
|
29
31
|
defaultRefreshTime: TimeSpan;
|
|
30
32
|
ttl: TimeSpan | null;
|
|
33
|
+
expirationInMs: number | null;
|
|
31
34
|
lazyPromiseSettings: {
|
|
32
35
|
retryAttempts: number | null;
|
|
33
36
|
backoffPolicy: BackoffPolicy | null;
|
|
34
37
|
retryPolicy: RetryPolicy | null;
|
|
35
38
|
timeout: TimeSpan | null;
|
|
36
39
|
};
|
|
40
|
+
stateRecord: ILockStateRecord;
|
|
37
41
|
};
|
|
38
42
|
/**
|
|
39
43
|
* @internal
|
|
@@ -48,10 +52,12 @@ export declare class Lock implements ILock {
|
|
|
48
52
|
private readonly ttl;
|
|
49
53
|
private readonly defaultRefreshTime;
|
|
50
54
|
private readonly lazyPromiseSettings;
|
|
55
|
+
private readonly state;
|
|
56
|
+
private readonly expirationInMs;
|
|
51
57
|
constructor(settings: LockSettings);
|
|
52
58
|
private createLayPromise;
|
|
53
|
-
run<TValue = void>(asyncFn: LazyPromiseable<TValue
|
|
54
|
-
runOrFail<TValue = void>(asyncFn: LazyPromiseable<TValue
|
|
59
|
+
run<TValue = void>(asyncFn: LazyPromiseable<TValue>): LazyPromise<Result<TValue, KeyAlreadyAcquiredLockError>>;
|
|
60
|
+
runOrFail<TValue = void>(asyncFn: LazyPromiseable<TValue>): LazyPromise<TValue>;
|
|
55
61
|
acquire(): LazyPromise<boolean>;
|
|
56
62
|
acquireOrFail(): LazyPromise<void>;
|
|
57
63
|
release(): LazyPromise<boolean>;
|
|
@@ -2,4 +2,3 @@ export * from "../../utilities/contracts/serialized-error.contract";
|
|
|
2
2
|
export * from "../../utilities/contracts/buildable.contract";
|
|
3
3
|
export * from "../../utilities/contracts/deinitizable.contract";
|
|
4
4
|
export * from "../../utilities/contracts/initizable.contract";
|
|
5
|
-
export * from "../../utilities/contracts/serde-registrable.contract";
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serde-registrable.contract.js","sourceRoot":"","sources":["../../../../src/utilities/contracts/serde-registrable.contract.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=serde-registrable.contract.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serde-registrable.contract.js","sourceRoot":"","sources":["../../../../src/utilities/contracts/serde-registrable.contract.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Utilities
|
|
3
|
-
*/
|
|
4
|
-
import type { IFlexibleSerde } from "../../serde/contracts/_module";
|
|
5
|
-
import type { OneOrMore } from "../../utilities/types";
|
|
6
|
-
/**
|
|
7
|
-
* @group Contracts
|
|
8
|
-
*/
|
|
9
|
-
export type ISerdeRegistrable = {
|
|
10
|
-
registerToSerde(serde: OneOrMore<IFlexibleSerde>): void;
|
|
11
|
-
};
|