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.

55 lines (54 loc) 1.75 kB
/** * @module Utilities */ import { type StandardSchemaV1 } from "@standard-schema/spec"; import { type OneOrMore } from "mongodb"; import { type Invokable } from "../../utilities/functions/invokable.js"; import { type AnyClass } from "../../utilities/types/_module.js"; /** * * IMPORT_PATH: `"@daiso-tech/core/utilities"` * @group Utilities */ 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 Utilities */ export type ErrorPolicy<TError = unknown> = Invokable<[error: TError], boolean> | StandardSchemaV1<TError> | OneOrMore<AnyClass> | ErrorPolicyBoolSetting; /** * * IMPORT_PATH: `"@daiso-tech/core/utilities"` * @group Utilities */ 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): boolean; /** * @internal */ export declare function callErrorPolicyOnThrow<TError = unknown>(errorPolicy: ErrorPolicy<TError> | undefined, error: TError): Promise<boolean>;