From c447d44bf78efcb32a0a7427aff0dc1d44d3a6fc Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 7 May 2024 10:00:38 -0300 Subject: aggregate: receive single {aggregate, result} object --- src/util/aggregate.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/util/aggregate.js b/src/util/aggregate.js index 2e4d9de7..5429e640 100644 --- a/src/util/aggregate.js +++ b/src/util/aggregate.js @@ -93,10 +93,27 @@ export function openAggregate({ aggregate.receive = (results) => { if (!Array.isArray(results)) { - throw new Error(`Expected an array`); + if (typeof results === 'object' && results.aggregate) { + const {aggregate, result} = results; + + try { + aggregate.close(); + } catch (error) { + errors.push(error); + } + + return result; + } + + throw new Error(`Expected an array or {aggregate, result} object`); } return results.map(({aggregate, result}) => { + if (!aggregate) { + console.log('nope:', results); + throw new Error(`Expected an array of {aggregate, result} objects`); + } + try { aggregate.close(); } catch (error) { -- cgit 1.3.0-6-gf8a5