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.

52 lines 1.7 kB
/** * @module Utilities */ import {} from "@standard-schema/spec"; import {} from "mongodb"; import { callInvokable, isInvokable, } from "../../utilities/functions/invokable.js"; import { isStandardSchema } from "../../utilities/functions/is-standard-schema.js"; import { resolveOneOrMore } from "../../utilities/functions/resolve-one-or-more.js"; import {} from "../../utilities/types/_module.js"; /** * @internal */ export function isErrorPolicyBoolSetting(value) { return (typeof value === "object" && value !== null && "treatFalseAsError" in value && typeof value.treatFalseAsError === "boolean"); } /** * @internal */ export function callErrorPolicyOnValue(errorPolicy = () => true, value) { // Will retry if the value is false and the setting treatFalseAsError is true const shouldRetry = isErrorPolicyBoolSetting(errorPolicy) && typeof value === "boolean" && !value && errorPolicy.treatFalseAsError; return shouldRetry; } /** * @internal */ export async function callErrorPolicyOnThrow(errorPolicy = () => true, error) { if (isInvokable(errorPolicy)) { return callInvokable(errorPolicy, error); } if (isStandardSchema(errorPolicy)) { const result = await errorPolicy["~standard"].validate(error); return result.issues === undefined; } // Used only for ensuring correct type without type casting. if (isErrorPolicyBoolSetting(errorPolicy)) { return false; } for (const ErrorClass of resolveOneOrMore(errorPolicy)) { if (error instanceof ErrorClass) { return true; } } return false; } //# sourceMappingURL=error-policy.js.map