Skip to content

Conversation

@hudlow
Copy link
Contributor

@hudlow hudlow commented Oct 22, 2025

No description provided.

@hudlow hudlow force-pushed the hudlow/cel-box branch 4 times, most recently from d6b88a9 to 5efbde1 Compare October 22, 2025 23:01
Comment on lines 83 to 103
function toJsonCompatibleValue(
value: CEL.CelValue,
): ReturnType<(typeof JSON)["parse"]> {
if (CEL.isCelMap(value)) {
return Object.fromEntries(
[...value.entries()].map(
([k, v]): [string, ReturnType<(typeof JSON)["parse"]>] => [
k.toString(),
toJsonCompatibleValue(v),
],
),
);
}

if (CEL.isCelList(value)) {
return [...value].map(
(v): ReturnType<(typeof JSON)["parse"]> => toJsonCompatibleValue(v),
);
}

return value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to handle CelUint, bigint, Uint8Array, maybe also CelType and ReflectMessage: https://github.com/bufbuild/cel-es/tree/main/packages/cel#types

This could be a replacer: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter
YAML stringify supports it too.

Or it could be a function in @bufbuild/cel - but then we need to be very certain about it.

Or we could just have a comment here to clarify that this function doesn't handle all possible CEL values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants