Skip to content

Commit

Permalink
fix: array destructuring returning not iterable (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-elicx authored Sep 1, 2023
1 parent d87efba commit 7b0d1ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-lizards-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'cf-bindings-proxy': patch
---

Return array responses instead of creating a new proxy for the response.
4 changes: 4 additions & 0 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ export const createBindingProxy = <T>(bindingId: string, notChainable = false):
return data;
}

if (Array.isArray(data)) {
return data;
}

return createResponseProxy(bindingId, target, data);
};
},
Expand Down
6 changes: 4 additions & 2 deletions tests/proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 7b0d1ae

Please sign in to comment.