@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.
87 lines • 3.15 kB
JavaScript
/**
* @module Semaphore
*/
import {} from "../../namespace/contracts/_module.js";
import {} from "../../utilities/_module.js";
/**
* The error is thrown when trying to acquire a semaphore slot, but all slots are already taken.
*
* IMPORT_PATH: `"@daiso-tech/core/semaphore/contracts"`
* @group Errors
*/
export class LimitReachedSemaphoreError extends Error {
static create(key, cause) {
return new LimitReachedSemaphoreError(`Key "${key.get()}" has reached the limit`, cause);
}
/**
* Note: Do not instantiate `LimitReachedSemaphoreError` directly via the constructor. Use the static `create()` factory method instead.
* The constructor remains public only to maintain compatibility with errorPolicy types and prevent type errors.
* @internal
*/
constructor(message, cause) {
super(message, { cause });
this.name = LimitReachedSemaphoreError.name;
}
}
/**
* The error is thrown when trying to refresh a semaphore slot that is already expired.
*
* IMPORT_PATH: `"@daiso-tech/core/semaphore/contracts"`
* @group Errors
*/
export class FailedRefreshSemaphoreError extends Error {
static create(key, slotId, cause) {
return new FailedRefreshSemaphoreError(`Failed to refresh slot "${slotId}" of key "${key.get()}"`, cause);
}
/**
* Note: Do not instantiate `FailedRefreshSemaphoreError` directly via the constructor. Use the static `create()` factory method instead.
* The constructor remains public only to maintain compatibility with errorPolicy types and prevent type errors.
* @internal
*/
constructor(message, cause) {
super(message, { cause });
this.name = FailedRefreshSemaphoreError.name;
}
}
/**
* The error is thrown when trying to release a semaphore slot that is already expired.
*
* IMPORT_PATH: `"@daiso-tech/core/semaphore/contracts"`
* @group Errors
*/
export class FailedReleaseSemaphoreError extends Error {
static create(key, slotId, cause) {
return new FailedReleaseSemaphoreError(`Failed to release slot "${slotId}" of key "${key.get()}"`, cause);
}
/**
* Note: Do not instantiate `FailedReleaseSemaphoreError` directly via the constructor. Use the static `create()` factory method instead.
* The constructor remains public only to maintain compatibility with errorPolicy types and prevent type errors.
* @internal
*/
constructor(message, cause) {
super(message, { cause });
this.name = FailedReleaseSemaphoreError.name;
}
}
/**
* IMPORT_PATH: `"@daiso-tech/core/semaphore/contracts"`
* @group Errors
*/
export const SEMAPHORE_ERRORS = {
ReachedLimit: LimitReachedSemaphoreError,
FailedRefresh: FailedRefreshSemaphoreError,
FailedRelease: FailedReleaseSemaphoreError,
};
/**
* IMPORT_PATH: `"@daiso-tech/core/semaphore/contracts"`
* @group Errors
*/
export function isSemaphoreError(value) {
for (const errorClass of Object.values(SEMAPHORE_ERRORS)) {
if (value instanceof errorClass) {
return true;
}
}
return false;
}
//# sourceMappingURL=semaphore.errors.js.map