@bufbuild/cel
Version:
A CEL evaluator for ECMAScript
49 lines (48 loc) • 1.77 kB
JavaScript
;
// 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;
Object.defineProperty(exports, "__esModule", { value: true });
exports.celEnv = celEnv;
const registry_js_1 = require("./registry.js");
const func_js_1 = require("./func.js");
const std_js_1 = require("./std/std.js");
const namespace_js_1 = require("./namespace.js");
const privateSymbol = Symbol.for("@bufbuild/cel/env");
/**
* Creates a new CelEnv.
*/
function celEnv(options) {
return new _CelEnv(options?.namespace ? new namespace_js_1.Namespace(options?.namespace) : undefined, options?.registry
? (0, registry_js_1.createRegistryWithWKT)(options.registry)
: (0, registry_js_1.createRegistryWithWKT)(), new func_js_1.OrderedDispatcher([new func_js_1.FuncRegistry(options?.funcs), std_js_1.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;