@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.
83 lines • 3.27 kB
JavaScript
/**
* @module SharedLock
*/
import {} from "../../../../event-bus/contracts/_module.js";
import {} from "../../../../execution-context/contracts/_module.js";
import {} from "../../../../middleware/contracts/_module.js";
import {} from "../../../../namespace/contracts/_module.js";
import {} from "../../../../serde/contracts/_module.js";
import {} from "../../../../shared-lock/contracts/_module.js";
import { SharedLock, } from "../../../../shared-lock/implementations/derivables/shared-lock-factory/shared-lock.js";
import { TimeSpan } from "../../../../time-span/implementations/_module.js";
import { getConstructorName, } from "../../../../utilities/_module.js";
/**
* @internal
*/
export class SharedLockSerdeTransformer {
adapter;
originalAdapter;
namespace;
defaultRefreshTime;
eventBus;
serdeTransformerName;
waitUntil;
executionContext;
use;
constructor(settings) {
const { adapter, originalAdapter, namespace, defaultRefreshTime, eventBus, serdeTransformerName, waitUntil, executionContext, use, } = settings;
this.use = use;
this.executionContext = executionContext;
this.waitUntil = waitUntil;
this.serdeTransformerName = serdeTransformerName;
this.adapter = adapter;
this.originalAdapter = originalAdapter;
this.namespace = namespace;
this.defaultRefreshTime = defaultRefreshTime;
this.eventBus = eventBus;
}
get name() {
return [
"shared-lock",
this.serdeTransformerName,
getConstructorName(this.originalAdapter),
this.namespace.toString(),
].filter((str) => str !== "");
}
isApplicable(value) {
const isSharedLock = value instanceof SharedLock &&
getConstructorName(value) === SharedLock.name;
if (!isSharedLock) {
return false;
}
const isSerdTransformerNameMathcing = value._getSerdeTransformerName() === this.serdeTransformerName;
const isNamespaceMatching = this.namespace.toString() === value._getNamespace().toString();
const isAdapterMatching = getConstructorName(this.originalAdapter) ===
getConstructorName(value._getAdapter());
return (isSerdTransformerNameMathcing &&
isNamespaceMatching &&
isAdapterMatching);
}
deserialize(serializedValue) {
const { key, lockId, limit, ttlInMs } = serializedValue;
const keyObj = this.namespace.create(key);
return new SharedLock({
use: this.use,
executionContext: this.executionContext,
waitUntil: this.waitUntil,
lockId,
adapter: this.adapter,
originalAdapter: this.originalAdapter,
eventDispatcher: this.eventBus,
key: keyObj,
limit,
serdeTransformerName: this.serdeTransformerName,
ttl: ttlInMs === null ? null : TimeSpan.fromMilliseconds(ttlInMs),
defaultRefreshTime: this.defaultRefreshTime,
namespace: this.namespace,
});
}
serialize(deserializedValue) {
return SharedLock._serialize(deserializedValue);
}
}
//# sourceMappingURL=shared-lock-serde-transformer.js.map