fix: jsonata $base64decode/$base64encode in Web Worker (#2275)

This commit is contained in:
min23asdw
2026-06-20 11:40:37 +01:00
committed by GitHub
parent 08e5c13da4
commit 0d2af8ce00
3 changed files with 36 additions and 0 deletions
+12
View File
@@ -51,6 +51,18 @@ class JsonataQuery extends Operation {
try {
const expression = jsonata(query);
// Override built-in base64 functions which fail in Web Worker
// context where `window` is undefined. The jsonata library falls
// back to `global.Buffer` which also does not exist in workers.
// `atob`/`btoa` are available in both browser and worker scopes.
expression.registerFunction("base64decode", (str) => {
if (typeof str === "undefined") return undefined;
return atob(str);
}, "<s-:s>");
expression.registerFunction("base64encode", (str) => {
if (typeof str === "undefined") return undefined;
return btoa(str);
}, "<s-:s>");
result = await expression.evaluate(jsonObj);
} catch (err) {
throw new OperationError(