From cdd436b5c87c87464953b92ab64e92dcd5db2bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Sun, 25 May 2025 00:52:55 +0100 Subject: [PATCH 1/3] Await array elements --- src/jsonata.js | 2 +- test/async-function.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/jsonata.js b/src/jsonata.js index 58077366..c21eb1e2 100644 --- a/src/jsonata.js +++ b/src/jsonata.js @@ -397,7 +397,7 @@ var jsonata = (function() { // count in from end of array index = input.length + index; } - var item = input[index]; + var item = await input[index]; if(typeof item !== 'undefined') { if(Array.isArray(item)) { results = item; diff --git a/test/async-function.js b/test/async-function.js index 60de7561..3ea93f13 100644 --- a/test/async-function.js +++ b/test/async-function.js @@ -176,3 +176,13 @@ describe('Handle chained functions that end in promises', function() { }); }); + +describe('Async array', function() { + it('should revaluate array items', async function() { + var data = { + list: [Promise.resolve({name: 'hello'})] + }; + var expr = jsonata('list[0].name'); + return expect(expr.evaluate(data)).to.eventually.equal('hello'); + }); +}); \ No newline at end of file From b865a47f99f3967825d882746f2fa53395e040a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Sun, 25 May 2025 00:59:43 +0100 Subject: [PATCH 2/3] Better test name --- test/async-function.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/async-function.js b/test/async-function.js index 3ea93f13..93feaf05 100644 --- a/test/async-function.js +++ b/test/async-function.js @@ -177,8 +177,8 @@ describe('Handle chained functions that end in promises', function() { }); -describe('Async array', function() { - it('should revaluate array items', async function() { +describe('Array with Promise items', function() { + it('should await each item', async function() { var data = { list: [Promise.resolve({name: 'hello'})] }; From 4fce03752be82e4e9cceb18f4ace58d73c860da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Sun, 25 May 2025 01:00:54 +0100 Subject: [PATCH 3/3] Formatting --- test/async-function.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/async-function.js b/test/async-function.js index 93feaf05..a537987f 100644 --- a/test/async-function.js +++ b/test/async-function.js @@ -183,6 +183,6 @@ describe('Array with Promise items', function() { list: [Promise.resolve({name: 'hello'})] }; var expr = jsonata('list[0].name'); - return expect(expr.evaluate(data)).to.eventually.equal('hello'); + return expect(expr.evaluate(data)).to.eventually.equal('hello'); }); }); \ No newline at end of file