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.

134 lines 3.75 kB
/** * @module Lock */ import { CORE, resolveOneOrMore, } from "../../utilities/_module-exports.js"; /** * * IMPORT_PATH: `"@daiso-tech/core/lock/contracts"` * @group Errors */ export class LockError extends Error { static deserialize(serializedError) { return new LockError(serializedError.message, serializedError.cause); } constructor(message, cause) { super(message, { cause }); } serialize() { return { cause: this.cause, message: this.message, name: this.name, }; } } /** * * IMPORT_PATH: `"@daiso-tech/core/lock/contracts"` * @group Errors */ export class UnexpectedLockError extends LockError { static deserialize(serializedError) { return new UnexpectedLockError(serializedError.message, serializedError.cause); } constructor(message, cause) { super(message, { cause }); } serialize() { return { cause: this.cause, message: this.message, name: this.name, }; } } /** * The error is thrown when trying to acquire a lock that is owned by a different owner. * * IMPORT_PATH: `"@daiso-tech/core/lock/contracts"` * @group Errors */ export class KeyAlreadyAcquiredLockError extends LockError { static deserialize(serializedError) { return new KeyAlreadyAcquiredLockError(serializedError.message, serializedError.cause); } constructor(message, cause) { super(message, { cause }); } serialize() { return { cause: this.cause, message: this.message, name: this.name, }; } } /** * The error is thrown when trying to release a lock that is owned by a different owner. * * IMPORT_PATH: `"@daiso-tech/core/lock/contracts"` * @group Errors */ export class UnownedReleaseLockError extends LockError { static deserialize(serializedError) { return new UnownedReleaseLockError(serializedError.message, serializedError.cause); } constructor(message, cause) { super(message, { cause }); } serialize() { return { cause: this.cause, message: this.message, name: this.name, }; } } /** * The error is thrown when trying to referesh a lock that is owned by a different owner. * * IMPORT_PATH: `"@daiso-tech/core/lock/contracts"` * @group Errors */ export class UnownedRefreshLockError extends LockError { static deserialize(serializedError) { return new UnownedRefreshLockError(serializedError.message, serializedError.cause); } constructor(message, cause) { super(message, { cause }); } serialize() { return { cause: this.cause, message: this.message, name: this.name, }; } } /** * * IMPORT_PATH: `"@daiso-tech/core/lock/contracts"` * @group Errors */ export const LOCK_ERRORS = { Base: LockError, Unexpected: UnexpectedLockError, KeyAlreadyAcquired: KeyAlreadyAcquiredLockError, UnownedRelease: UnownedReleaseLockError, }; /** * The `registerLockErrorsToSerde` function registers all {@link ILock | `ILock`} related errors with `IFlexibleSerde`, ensuring they will properly be serialized and deserialized. * * IMPORT_PATH: `"@daiso-tech/core/lock/contracts"` * @group Errors */ export function registerLockErrorsToSerde(serde) { for (const serde_ of resolveOneOrMore(serde)) { serde_ .registerClass(LockError, CORE) .registerClass(UnexpectedLockError, CORE) .registerClass(KeyAlreadyAcquiredLockError, CORE) .registerClass(UnownedReleaseLockError, CORE); } } //# sourceMappingURL=lock.errors.js.map