@bufbuild/cel
Version:
A CEL evaluator for ECMAScript
51 lines (50 loc) • 2.45 kB
TypeScript
import type { Activation } from "./activation.js";
import { EvalAttr, type Interpretable } from "./planner.js";
import type { Namespace } from "./namespace.js";
import { type CelResult, type CelError } from "./error.js";
import { type CelValue } from "./type.js";
import type { Registry } from "@bufbuild/protobuf";
export interface AttributeFactory {
createAbsolute(id: number, names: string[]): NamespacedAttribute;
createConditional(id: number, cond: Interpretable, t: Attribute, f: Attribute): Attribute;
createMaybe(id: number, name: string): Attribute;
createRelative(id: number, operand: Interpretable): Attribute;
newAccess(id: number, val: CelValue | EvalAttr, opt: boolean): Access;
}
export interface Access<T extends CelValue = CelValue> {
readonly id: number;
access(vars: Activation, obj: T): CelResult<T> | undefined;
isPresent(_vars: Activation, obj: T): CelResult<boolean>;
accessIfPresent(vars: Activation, obj: T, presenceOnly: boolean): CelResult<T> | undefined;
isOptional(): boolean;
}
export interface Attribute<T extends CelValue = CelValue> extends Access<T> {
resolve(vars: Activation): CelResult<T> | undefined;
addAccess(access: Access): void;
}
export interface NamespacedAttribute extends Attribute {
candidateNames(): string[];
accesses(): Access[];
}
export declare class ErrorAttr implements Attribute {
readonly id: number;
readonly error: CelError;
private readonly opt;
constructor(id: number, error: CelError, opt: boolean);
addAccess(_access: Access): void;
resolve(_vars: Activation): CelResult | undefined;
isOptional(): boolean;
access(_vars: Activation, _obj: CelValue): CelResult | undefined;
isPresent(_vars: Activation, _obj: CelValue): CelResult<boolean>;
accessIfPresent(_vars: Activation, _obj: CelValue, _presenceOnly: boolean): CelResult | undefined;
}
export declare class ConcreteAttributeFactory implements AttributeFactory {
registry: Registry;
container: Namespace;
constructor(registry: Registry, container: Namespace);
createAbsolute(id: number, names: string[]): NamespacedAttribute;
createConditional(id: number, cond: Interpretable, t: Attribute, f: Attribute): Attribute;
createMaybe(id: number, name: string): Attribute;
createRelative(id: number, operand: Interpretable): Attribute;
newAccess(id: number, val: CelValue | EvalAttr, opt: boolean): Access;
}