@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.
26 lines • 917 B
JavaScript
/**
* @module Semaphore
*/
import { v4 } from "uuid";
import {} from "../../../middleware/contracts/_module.js";
import {} from "../../../semaphore/contracts/_module.js";
import {} from "../../../time-span/contracts/time-span.contract.js";
import { callInvokable } from "../../../utilities/_module.js";
/**
* IMPORT_PATH: `"@daiso-tech/core/semaphore/middlewares"`
* @group Middleware
*/
export function semaphoreMiddlewareFactory(semaphoreFactory) {
return (settings) => {
const { key = (...args) => JSON.stringify(args), slotId = () => v4(), ...rest } = settings;
return ({ next, args }) => {
return semaphoreFactory
.create(callInvokable(key, ...args), {
...rest,
slotId: callInvokable(slotId, ...args),
})
.runOrFail(next);
};
};
}
//# sourceMappingURL=semaphore-middleware-factory.js.map