From 8527c950acd57d7b7e8873f3894e11d6f5bef2d3 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 27 Aug 2023 17:36:25 +0100 Subject: [PATCH] fix: `JSON.stringify(...)` throwing an error (#31) --- .changeset/green-bobcats-notice.md | 5 +++++ src/proxy.ts | 2 ++ tests/proxy.spec.ts | 2 ++ 3 files changed, 9 insertions(+) create mode 100644 .changeset/green-bobcats-notice.md diff --git a/.changeset/green-bobcats-notice.md b/.changeset/green-bobcats-notice.md new file mode 100644 index 0000000..393ffec --- /dev/null +++ b/.changeset/green-bobcats-notice.md @@ -0,0 +1,5 @@ +--- +'cf-bindings-proxy': patch +--- + +Fix using `JSON.stringify(...)` throwing an error. diff --git a/src/proxy.ts b/src/proxy.ts index 2255da0..0470899 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -88,6 +88,8 @@ const createResponseProxy = ( return data[Number(prop)]; } + if (['toJSON'].includes(prop as string)) return data; + // eslint-disable-next-line @typescript-eslint/no-use-before-define const newProxy = createBindingProxy(bindingId, true); diff --git a/tests/proxy.spec.ts b/tests/proxy.spec.ts index d2cf5f8..ff05277 100644 --- a/tests/proxy.spec.ts +++ b/tests/proxy.spec.ts @@ -320,6 +320,8 @@ suite('bindings', () => { { key: 'json-key' }, { key: 'second-key' }, ]); + + expect(JSON.stringify(list.truncated)).toEqual('false'); }); test('head', async () => {