UNPKG

@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.

80 lines 3.09 kB
/** * @module RateLimiter */ import {} from "../../../../event-bus/contracts/_module.js"; import {} from "../../../../execution-context/contracts/_module.js"; import {} from "../../../../namespace/contracts/_module.js"; import {} from "../../../../rate-limiter/contracts/_module.js"; import { RateLimiter, } from "../../../../rate-limiter/implementations/derivables/rate-limiter-factory/rate-limiter.js"; import {} from "../../../../serde/contracts/_module.js"; import { getConstructorName, } from "../../../../utilities/_module.js"; /** * @internal */ export class RateLimiterSerdeTransformer { adapter; namespace; errorPolicy; eventBus; serdeTransformerName; enableAsyncTracking; onlyError; waitUntil; executionContext; constructor(settings) { const { adapter, namespace, eventBus, serdeTransformerName, enableAsyncTracking, errorPolicy, onlyError, waitUntil, executionContext, } = settings; this.executionContext = executionContext; this.waitUntil = waitUntil; this.onlyError = onlyError; this.enableAsyncTracking = enableAsyncTracking; this.serdeTransformerName = serdeTransformerName; this.adapter = adapter; this.namespace = namespace; this.eventBus = eventBus; this.errorPolicy = errorPolicy; this.serdeTransformerName = serdeTransformerName; } get name() { return [ "rateLimiter", this.serdeTransformerName, getConstructorName(this.adapter), this.namespace.toString(), ].filter((str) => str !== ""); } isApplicable(value) { const isRateLimiter = value instanceof RateLimiter && getConstructorName(value) === RateLimiter.name; if (!isRateLimiter) { return false; } const isSerdTransformerNameMathcing = this.serdeTransformerName === value._getSerdeTransformerName(); const isNamespaceMatching = this.namespace.toString() === value._getNamespace().toString(); const isAdapterMatching = getConstructorName(this.adapter) === getConstructorName(value._getAdapter()); return (isSerdTransformerNameMathcing && isNamespaceMatching && isAdapterMatching); } deserialize(serializedValue) { const { key, limit } = serializedValue; const keyObj = this.namespace.create(key); return new RateLimiter({ executionContext: this.executionContext, waitUntil: this.waitUntil, enableAsyncTracking: this.enableAsyncTracking, eventDispatcher: this.eventBus, adapter: this.adapter, key: keyObj, limit, onlyError: this.onlyError, errorPolicy: this.errorPolicy, serdeTransformerName: this.serdeTransformerName, namespace: this.namespace, }); } serialize(deserializedValue) { return RateLimiter._serialize(deserializedValue); } } //# sourceMappingURL=rate-limiter-serde-transformer.js.map