@bufbuild/cel
Version:
A CEL evaluator for ECMAScript
40 lines (39 loc) • 1.34 kB
TypeScript
import type { CelValue } from "./type.js";
/**
* Result type that represents either a successful value or a CEL error.
**/
export type CelResult<T = CelValue> = T | CelError;
declare const privateSymbol: unique symbol;
/**
* Common error type returned by CEL.
*/
export interface CelError extends Error {
[privateSymbol]: unknown;
/**
* ID of the expression. Only set if this is from
* evaluating an expression.
*/
readonly exprId: bigint | undefined;
/**
* The underlying cause of this error, if any.
*/
readonly cause: unknown;
}
/**
* Coerces a value to CelError using the following rules:
* - If the given value is a CelError just return that.
* - If it is an Error type, create a new CelError from that.
* - If it is a string, creates a new CelError with that as the message.
* - In all other cases create a new CelError with the given value as the cause.
*/
export declare function celError(value: unknown, exprId?: bigint | number): CelError;
/**
* Merges CelErrors into one. Uses the message and exprId from the first error and
* add the rest as the cause.
*/
export declare function celErrorMerge(first: CelError, ...rest: CelError[]): CelError;
/**
* Returns true if the given value is a CelError.
*/
export declare function isCelError(v: unknown): v is CelError;
export {};