UNPKG

@bufbuild/protovalidate

Version:

Protocol Buffer Validation for ECMAScript

81 lines (80 loc) 3.1 kB
import { type DescExtension, type DescField, type DescMessage, type Registry, ScalarType } from "@bufbuild/protobuf"; import type { Path, ReflectMessageGet } from "@bufbuild/protobuf/reflect"; import { type CelEnv } from "@bufbuild/cel"; import { type Rule, type FieldRules } from "./gen/buf/validate/validate_pb.js"; import { CompilationError } from "./error.js"; import type { Eval } from "./eval.js"; import type { Cursor } from "./cursor.js"; type CelCompiledRules = { standard: { field: DescField; rule: Rule; compiled: CelCompiledRule; }[]; extensions: Map<number, { ext: DescExtension; rule: Rule; compiled: CelCompiledRule; }[]>; }; export type CelCompiledRule = { kind: "compilation_error"; error: CompilationError; } | { kind: "interpretable"; interpretable: ReturnType<CelEnv["plan"]>; rule: Rule; }; export type RegexMatcher = (pattern: string, against: string) => boolean; export declare class CelManager { private readonly registry; private readonly env; private readonly now; private readonly rulesCache; constructor(registry: Registry, regexMatcher: RegexMatcher | undefined); /** * Update the CEL variable "now" to the current time. */ updateCelNow(): void; setEnv(key: "this" | "rules" | "rule", value: unknown): void; eval(compiled: CelCompiledRule): { message: string; ruleId: string; } | undefined; compileRule(rule: Rule): CelCompiledRule; compileRules(descMessage: DescMessage): CelCompiledRules; private compileRulesUncached; } export declare class EvalCustomCel implements Eval<ReflectMessageGet> { private readonly celMan; private readonly forMapKey; private readonly thisScalarType; private readonly children; constructor(celMan: CelManager, forMapKey: boolean, thisScalarType: ScalarType | undefined); add(compiled: CelCompiledRule, rulePath: Path): void; eval(val: ReflectMessageGet, cursor: Cursor): void; prune(): boolean; } export declare class EvalExtendedRulesCel implements Eval<ReflectMessageGet> { private readonly celMan; private readonly rules; private readonly forMapKey; private readonly children; private readonly thisScalarType; constructor(celMan: CelManager, rules: Exclude<FieldRules["type"]["value"], undefined>, forMapKey: boolean); add(compiled: CelCompiledRule, rulePath: Path, ruleValue: unknown, ruleScalarType: ScalarType | undefined): void; eval(val: ReflectMessageGet, cursor: Cursor): void; prune(): boolean; } export declare class EvalStandardRulesCel implements Eval<ReflectMessageGet> { private readonly celMan; private readonly rules; private readonly forMapKey; private readonly children; private readonly thisScalarType; constructor(celMan: CelManager, rules: Exclude<FieldRules["type"]["value"], undefined>, forMapKey: boolean); add(compiled: CelCompiledRule, rulePath: Path): void; eval(val: ReflectMessageGet, cursor: Cursor): void; prune(): boolean; } export {};