@confluentinc/schemaregistry
Version:
Node.js client for Confluent Schema Registry
53 lines (52 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CelFieldExecutorTransform = exports.CelFieldExecutor = void 0;
const rule_registry_1 = require("../../serde/rule-registry");
const serde_1 = require("../../serde/serde");
const cel_executor_1 = require("./cel-executor");
class CelFieldExecutor extends serde_1.FieldRuleExecutor {
constructor() {
super(...arguments);
this.executor = new cel_executor_1.CelExecutor();
}
static register() {
const executor = new CelFieldExecutor();
rule_registry_1.RuleRegistry.registerRuleExecutor(executor);
return executor;
}
configure(clientConfig, config) {
this.config = config;
}
type() {
return "CEL_FIELD";
}
newTransform(ctx) {
return new CelFieldExecutorTransform(this.executor);
}
async close() {
}
}
exports.CelFieldExecutor = CelFieldExecutor;
class CelFieldExecutorTransform {
constructor(executor) {
this.executor = executor;
}
async transform(ctx, fieldCtx, fieldValue) {
if (fieldValue == null) {
return null;
}
if (!fieldCtx.isPrimitive()) {
return fieldValue;
}
const args = {
value: fieldValue,
fullName: fieldCtx.fullName,
name: fieldCtx.name,
typeName: fieldCtx.typeName(),
tags: Array.from(fieldCtx.tags),
message: fieldCtx.containingMessage
};
return await this.executor.execute(ctx, fieldValue, args);
}
}
exports.CelFieldExecutorTransform = CelFieldExecutorTransform;