@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
63 lines • 2.34 kB
JavaScript
/**
* @module Lock
*/
import { Lock, } from "../../../../lock/implementations/derivables/lock-provider/lock.js";
import { LockState, } from "../../../../lock/implementations/derivables/lock-provider/lock-state.js";
import { getConstructorName, TimeSpan, } from "../../../../utilities/_module-exports.js";
/**
* @internal
*/
export class LockSerdeTransformer {
adapter;
lockStore;
keyPrefixer;
createLazyPromise;
defaultBlockingInterval;
defaultBlockingTime;
defaultRefreshTime;
eventBus;
serdeTransformerName;
constructor(settings) {
const { adapter, lockStore, keyPrefixer, createLazyPromise, defaultBlockingInterval, defaultBlockingTime, defaultRefreshTime, eventBus, serdeTransformerName, } = settings;
this.serdeTransformerName = serdeTransformerName;
this.adapter = adapter;
this.lockStore = lockStore;
this.keyPrefixer = keyPrefixer;
this.createLazyPromise = createLazyPromise;
this.defaultBlockingInterval = defaultBlockingInterval;
this.defaultBlockingTime = defaultBlockingTime;
this.defaultRefreshTime = defaultRefreshTime;
this.eventBus = eventBus;
}
get name() {
return [
"lock",
this.serdeTransformerName,
getConstructorName(this.adapter),
];
}
isApplicable(value) {
return value instanceof Lock && getConstructorName(value) === Lock.name;
}
deserialize(serializedValue) {
const { key, owner, ttlInMs, expirationInMs } = serializedValue;
const keyObj = this.keyPrefixer.create(key);
return new Lock({
createLazyPromise: this.createLazyPromise,
adapter: this.adapter,
lockState: new LockState(this.lockStore, keyObj.prefixed),
eventDispatcher: this.eventBus,
key: keyObj,
owner,
ttl: ttlInMs ? TimeSpan.fromMilliseconds(ttlInMs) : null,
expirationInMs,
defaultBlockingInterval: this.defaultBlockingInterval,
defaultBlockingTime: this.defaultBlockingTime,
defaultRefreshTime: this.defaultRefreshTime,
});
}
serialize(deserializedValue) {
return Lock.serialize(deserializedValue);
}
}
//# sourceMappingURL=lock-serde-transformer.js.map