@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.
96 lines • 2.83 kB
JavaScript
/**
* @module Cache
*/
import { CORE, resolveOneOrMore, } from "../../utilities/_module-exports.js";
/**
*
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
* @group Errors
*/
export class CacheError extends Error {
static deserialize(deserializedValue) {
return new CacheError(deserializedValue.message, deserializedValue.cause);
}
constructor(message, cause) {
super(message, { cause });
this.name = CacheError.name;
}
serialize() {
return {
name: this.name,
message: this.message,
cause: this.cause,
};
}
}
/**
*
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
* @group Errors
*/
export class UnexpectedCacheError extends CacheError {
static deserialize(deserializedValue) {
return new UnexpectedCacheError(deserializedValue.message, deserializedValue.cause);
}
constructor(message, cause) {
super(message, { cause });
this.name = UnexpectedCacheError.name;
}
}
/**
* The error is thrown when attempting to increment or decrement a key that is not of number type.
*
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
* @group Errors
*/
export class TypeCacheError extends CacheError {
static deserialize(deserializedValue) {
return new TypeCacheError(deserializedValue.message, deserializedValue.cause);
}
constructor(message, cause) {
super(message, { cause });
this.name = TypeCacheError.name;
}
}
/**
* The error is thrown when a key is not found
*
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
* @group Errors
*/
export class KeyNotFoundCacheError extends CacheError {
static deserialize(deserializedValue) {
return new KeyNotFoundCacheError(deserializedValue.message, deserializedValue.cause);
}
constructor(message, cause) {
super(message, { cause });
this.name = KeyNotFoundCacheError.name;
}
}
/**
*
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
* @group Errors
*/
export const CACHE_ERRORS = {
Base: CacheError,
Unexpected: UnexpectedCacheError,
Type: TypeCacheError,
KeyNotFound: KeyNotFoundCacheError,
};
/**
* The `registerCacheErrorsToSerde` function registers all {@link ICache | `ICache`} related errors with `IFlexibleSerde`, ensuring they will properly be serialized and deserialized.
*
* IMPORT_PATH: `"@daiso-tech/core/cache/contracts"`
* @group Errors
*/
export function registerCacheErrorsToSerde(serde) {
for (const serde_ of resolveOneOrMore(serde)) {
serde_
.registerClass(CacheError, CORE)
.registerClass(UnexpectedCacheError, CORE)
.registerClass(TypeCacheError, CORE)
.registerClass(KeyNotFoundCacheError, CORE);
}
}
//# sourceMappingURL=cache.errors.js.map