@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.
55 lines (54 loc) • 1.8 kB
TypeScript
/**
* @module Utilities
*/
import { type Invokable } from "../../utilities/functions/invokable.js";
import { type Result } from "../../utilities/functions/result.js";
import type { StandardSchemaV1 } from "@standard-schema/spec";
import { type AnyClass } from "../../utilities/types/_module.js";
/**
*
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
* @group Middlewares
*/
export type ErrorPolicyBoolSetting = {
/**
* If true will treat false return values as errors.
* You can use this with `retry` middleware to rerun functions that return false.
*/
treatFalseAsError: boolean;
};
/**
* @internal
*/
export declare function isErrorPolicyBoolSetting(value: unknown): value is ErrorPolicyBoolSetting;
/**
* The `ErrorPolicy` can be a predicate function, {@link StandardSchemaV1 | `StandardSchemaV1`} and a class.
*
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
* @group Middlewares
*/
export type ErrorPolicy<TError = unknown> = Invokable<[error: TError], boolean> | StandardSchemaV1<TError> | AnyClass | ErrorPolicyBoolSetting;
/**
*
* IMPORT_PATH: `"@daiso-tech/core/utilities"`
* @group Middlewares
*/
export type ErrorPolicySettings<TError = unknown> = {
/**
* You can choose what errors you want to retry. By default all erros will be retried.
*
* @default
* ```ts
* (_error: unknown) => true
* ```
*/
errorPolicy?: ErrorPolicy<TError>;
};
/**
* @internal
*/
export declare function callErrorPolicyOnValue<TValue = unknown, TError = unknown>(errorPolicy: ErrorPolicy<TError> | undefined, value: TValue | Result<TValue, TError>): Promise<boolean>;
/**
* @internal
*/
export declare function callErrorPolicyOnThrow<TError = unknown>(errorPolicy: ErrorPolicy<TError> | undefined, error: TError): Promise<boolean>;