UNPKG

@bufbuild/cel

Version:

A CEL evaluator for ECMAScript

46 lines (45 loc) 1.62 kB
// Copyright 2024-2025 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. var _a; import { createRegistryWithWKT } from "./registry.js"; import { FuncRegistry, OrderedDispatcher, } from "./func.js"; import { STD_FUNCS } from "./std/std.js"; import { Namespace } from "./namespace.js"; const privateSymbol = Symbol.for("@bufbuild/cel/env"); /** * Creates a new CelEnv. */ export function celEnv(options) { return new _CelEnv(options?.namespace ? new Namespace(options?.namespace) : undefined, options?.registry ? createRegistryWithWKT(options.registry) : createRegistryWithWKT(), new OrderedDispatcher([new FuncRegistry(options?.funcs), STD_FUNCS])); } class _CelEnv { constructor(_namespace, _registry, _dispatcher) { this._namespace = _namespace; this._registry = _registry; this._dispatcher = _dispatcher; this[_a] = {}; } get namespace() { return this._namespace; } get registry() { return this._registry; } get dispatcher() { return this._dispatcher; } } _a = privateSymbol;