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