From 16c1cbf79a300e6bd60046419bf1b3aa2e09ee88 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 1 Sep 2023 18:09:26 +0100 Subject: [PATCH] fix: array destructuring returning not iterable --- .changeset/modern-lizards-impress.md | 5 +++++ src/proxy.ts | 4 ++++ tests/proxy.spec.ts | 6 ++++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/modern-lizards-impress.md diff --git a/.changeset/modern-lizards-impress.md b/.changeset/modern-lizards-impress.md new file mode 100644 index 0000000..155ae86 --- /dev/null +++ b/.changeset/modern-lizards-impress.md @@ -0,0 +1,5 @@ +--- +'cf-bindings-proxy': patch +--- + +Return array responses instead of creating a new proxy for the response. diff --git a/src/proxy.ts b/src/proxy.ts index 2e86ab2..b1cb8a7 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -241,6 +241,10 @@ export const createBindingProxy = (bindingId: string, notChainable = false): return data; } + if (Array.isArray(data)) { + return data; + } + return createResponseProxy(bindingId, target, data); }; }, diff --git a/tests/proxy.spec.ts b/tests/proxy.spec.ts index b2cb124..17725fe 100644 --- a/tests/proxy.spec.ts +++ b/tests/proxy.spec.ts @@ -118,8 +118,10 @@ suite('bindings', () => { const statements = insertQuery.map((query) => d1.prepare(query).bind('hello-world')); - const result = await d1.batch(statements); - expect(result.map((r) => r.success)).toEqual([true, true]); + const [insert1, insert2] = await d1.batch(statements); + + expect(insert1?.success).toEqual(true); + expect(insert2?.success).toEqual(true); }); test('prepare -> bind -> all (select)', async () => {