Skip to content

Commit 5d41830

Browse files
authored
Implement getField CEL function (#102)
1 parent 76b6709 commit 5d41830

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • packages/protovalidate/src

packages/protovalidate/src/cel.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
type CelEnv,
2525
CelError,
2626
CelList,
27+
CelObject,
2728
type CelResult,
2829
type CelVal,
2930
createEnv,
@@ -234,6 +235,18 @@ function createCustomFuncs(): FuncRegistry {
234235
},
235236
),
236237
);
238+
reg.add(
239+
Func.binary(
240+
"getField",
241+
["dyn_string_get_field_dyn"],
242+
(id: number, lhs: CelVal, rhs: CelVal): CelResult | undefined => {
243+
if (typeof rhs == "string" && lhs instanceof CelObject) {
244+
return lhs.accessByName(id, rhs);
245+
}
246+
return undefined;
247+
},
248+
),
249+
);
237250
return reg;
238251
}
239252

0 commit comments

Comments
 (0)