@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.
86 lines • 3.01 kB
JavaScript
/**
* @module Collection
*/
import {} from "../../utilities/_module.js";
/**
* The error is thrown when the item is not found.
*
* IMPORT_PATH: `"@daiso-tech/core/collection/contracts"`
* @group Errors
*/
export class ItemNotFoundCollectionError extends Error {
static create(cause) {
return new ItemNotFoundCollectionError("Item was not found", cause);
}
/**
* Note: Do not instantiate `ItemNotFoundCollectionError` 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 = ItemNotFoundCollectionError.name;
}
}
/**
* The error is thrown when multiple items are found.
*
* IMPORT_PATH: `"@daiso-tech/core/collection/contracts"`
* @group Errors
*/
export class MultipleItemsFoundCollectionError extends Error {
static create(cause) {
return new MultipleItemsFoundCollectionError("Multiple items were found", cause);
}
/**
* Note: Do not instantiate `MultipleItemsFoundCollectionError` 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 = MultipleItemsFoundCollectionError.name;
}
}
/**
* The error is thrown when calling a method that needs the collection not to be empty. For example, the `average` method requires the collection not to be empty.
*
* IMPORT_PATH: `"@daiso-tech/core/collection/contracts"`
* @group Errors
*/
export class EmptyCollectionError extends Error {
static create(cause) {
return new EmptyCollectionError("Collection is empty therby operation cannot be performed", cause);
}
/**
* Note: Do not instantiate `EmptyCollectionError` 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 = EmptyCollectionError.name;
}
}
/**
* IMPORT_PATH: `"@daiso-tech/core/collection/contracts"`
* @group Errors
*/
export const COLLECTION_ERRORS = {
ItemNotFound: ItemNotFoundCollectionError,
MultipleItemsFound: MultipleItemsFoundCollectionError,
Empty: EmptyCollectionError,
};
/**
* IMPORT_PATH: `"@daiso-tech/core/collection/contracts"`
* @group Errors
*/
export function isCollectionError(value) {
for (const errorClass of Object.values(COLLECTION_ERRORS)) {
if (value instanceof errorClass) {
return true;
}
}
return false;
}
//# sourceMappingURL=collection.errors.js.map