@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.
183 lines • 6.72 kB
JavaScript
/**
* @module SharedLock
*/
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/shared-lock/contracts"`
* @group Errors
*/
export class LimitReachedReaderSemaphoreError extends Error {
static create(key, cause) {
return new LimitReachedReaderSemaphoreError(`Key "${key.get()}" has reached the limit`, cause);
}
/**
* Note: Do not instantiate `LimitReachedReaderSemaphoreError` 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 = LimitReachedReaderSemaphoreError.name;
}
}
/**
* The error is thrown when trying to refresh a semaphore slot that is already expired.
*
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export class FailedRefreshReaderSemaphoreError extends Error {
static create(key, slotId, cause) {
return new FailedRefreshReaderSemaphoreError(`Failed to refresh slot "${slotId}" of key "${key.get()}"`, cause);
}
/**
* Note: Do not instantiate `FailedRefreshReaderSemaphoreError` 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 = FailedRefreshReaderSemaphoreError.name;
}
}
/**
* The error is thrown when trying to release a semaphore slot that is already expired.
*
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export class FailedReleaseReaderSemaphoreError extends Error {
static create(key, slotId, cause) {
return new FailedReleaseReaderSemaphoreError(`Failed to release slot "${slotId}" of key "${key.get()}"`, cause);
}
/**
* Note: Do not instantiate `FailedReleaseReaderSemaphoreError` 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 = FailedReleaseReaderSemaphoreError.name;
}
}
/**
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export const READER_SEMAPHORE_ERRORS = {
ReachedLimitReader: LimitReachedReaderSemaphoreError,
FailedRefreshReader: FailedRefreshReaderSemaphoreError,
FailedReleaseReader: FailedReleaseReaderSemaphoreError,
};
/**
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export function isReaderSemaphoreError(value) {
for (const errorClass of Object.values(READER_SEMAPHORE_ERRORS)) {
if (value instanceof errorClass) {
return true;
}
}
return false;
}
/**
* The error is thrown when trying to acquire a shared-lock that is owned by a different owner.
*
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export class FailedAcquireWriterLockError extends Error {
static create(key, cause) {
return new FailedAcquireWriterLockError(`Key "${key.get()}" already acquired`, cause);
}
/**
* Note: Do not instantiate `FailedAcquireWriterLockError` 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 = FailedAcquireWriterLockError.name;
}
}
/**
* The error is thrown when trying to release a shared-lock that is owned by a different owner.
*
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export class FailedReleaseWriterLockError extends Error {
static create(key, lockId, cause) {
return new FailedReleaseWriterLockError(`Unonwed release on key "${key.get()}" by owner "${lockId}"`, cause);
}
/**
* Note: Do not instantiate `FailedReleaseWriterLockError` 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 = FailedReleaseWriterLockError.name;
}
}
/**
* The error is thrown when trying to refresh a shared-lock that is owned by a different owner.
*
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export class FailedRefreshWriterLockError extends Error {
static create(_key, lockId, cause) {
return new FailedRefreshWriterLockError(`Unonwed refresh on key "${_key.get()}" by owner "${lockId}"`, cause);
}
/**
* Note: Do not instantiate `FailedRefreshWriterLockError` 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 = FailedRefreshWriterLockError.name;
}
}
/**
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export const WRITER_LOCK_ERRORS = {
FailedAcquireWriter: FailedAcquireWriterLockError,
FailedReleaseWriter: FailedReleaseWriterLockError,
FailedRefreshWriter: FailedRefreshWriterLockError,
};
/**
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export function isWriterLockError(value) {
for (const errorClass of Object.values(WRITER_LOCK_ERRORS)) {
if (value instanceof errorClass) {
return true;
}
}
return false;
}
/**
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export const SHARED_LOCK_ERRORS = {
...READER_SEMAPHORE_ERRORS,
...WRITER_LOCK_ERRORS,
};
/**
* IMPORT_PATH: `"@daiso-tech/core/shared-lock/contracts"`
* @group Errors
*/
export function isSharedLockError(value) {
return isReaderSemaphoreError(value) || isWriterLockError(value);
}
//# sourceMappingURL=shared-lock.errors.js.map