From 55b68ea032b99bce632250e3d364ec0942d7d600 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Tue, 5 Oct 2021 20:25:12 +0530 Subject: [PATCH 1/7] feat(LiveQuery): Support $eq --- src/LiveQuery/QueryTools.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/LiveQuery/QueryTools.js b/src/LiveQuery/QueryTools.js index 905919ef61..db9b4a0608 100644 --- a/src/LiveQuery/QueryTools.js +++ b/src/LiveQuery/QueryTools.js @@ -217,6 +217,32 @@ function matchesKeyConstraints(object, key, constraints) { compareTo = Parse._decode(key, compareTo); } switch (condition) { + case '$eq': { + if (typeof compareTo !== 'object') { + // Equality (or Array contains) cases + if (Array.isArray(object[key])) { + if (object[key].indexOf(constraints[condition]) === -1) { + return false; + } + break; + } + if (object[key] !== compareTo) { + return false; + } + break; + } else { + if (compareTo && constraints[condition].__type === 'Pointer') { + return equalObjectsGeneric(object[key], constraints[condition], function (obj, ptr) { + return ( + typeof obj !== 'undefined' && + ptr.className === obj.className && + ptr.objectId === obj.objectId + ); + }); + } + return equalObjectsGeneric(object[key], compareTo, equalObjects); + } + } case '$lt': if (object[key] >= compareTo) { return false; From 2b52e3437742275d8ec655595d892df76af982dd Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 6 Oct 2021 08:17:16 +0530 Subject: [PATCH 2/7] updated changelog.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 635777d7f1..fc20d3b728 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ ___ - Add official support for MongoDB 5.0 (Manuel Trezza) [#7469](https://github.com/parse-community/parse-server/pull/7469) ### Other Changes +- feat: add support for $eq queries in LiveQuery (Prerna Mehra) [#7607](https://github.com/parse-community/parse-server/pull/7607) - Support native mongodb syntax in aggregation pipelines (Raschid JF Rafeally) [#7339](https://github.com/parse-community/parse-server/pull/7339) - Fix error when a not yet inserted job is updated (Antonio Davi Macedo Coelho de Castro) [#7196](https://github.com/parse-community/parse-server/pull/7196) - request.context for afterFind triggers (dblythy) [#7078](https://github.com/parse-community/parse-server/pull/7078) From 0287282267a1bdee4f96a3b84b18ecb8ef4ddb49 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Tue, 19 Oct 2021 13:20:19 +0200 Subject: [PATCH 3/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5990e477ee..407205d4bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,7 +103,7 @@ ___ ## Breaking Changes - (none) ## Features -- feat: add support for $eq queries in LiveQuery (Prerna Mehra) [#7607](https://github.com/parse-community/parse-server/pull/7607) +- add support for $eq queries in LiveQuery (Prerna Mehra) [#7607](https://github.com/parse-community/parse-server/pull/7607) ## Bug Fixes - (none) From f8b4f7b4374f3b58905d1385d39870deed58d929 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Tue, 16 Nov 2021 19:10:10 +0530 Subject: [PATCH 4/7] added test case for new format query --- spec/QueryTools.spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/QueryTools.spec.js b/spec/QueryTools.spec.js index 7e09078dad..1f96839bfd 100644 --- a/spec/QueryTools.spec.js +++ b/spec/QueryTools.spec.js @@ -255,6 +255,21 @@ describe('matchesQuery', function () { expect(matchesQuery(img, q)).toBe(false); }); + it('matches on queries with new format #parse-SDK-JS/pull/1373', function () { + const obj1 = { + id: new Id('Person', 'O1'), + score: 12, + name: 'Bill', + }; + + const q = { + score: { + $eq: 12, + }, + }; + expect(matchesQuery(obj1, q)).toBe(true); + }); + it('matches on inequalities', function () { const player = { id: new Id('Person', 'O1'), From d35ce8504c7d1befd7aaaf2abc5958e153ed3984 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Tue, 14 Dec 2021 10:37:42 +0530 Subject: [PATCH 5/7] added more testcase for new query format --- spec/QueryTools.spec.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/spec/QueryTools.spec.js b/spec/QueryTools.spec.js index 1f96839bfd..a3d08dd809 100644 --- a/spec/QueryTools.spec.js +++ b/spec/QueryTools.spec.js @@ -270,6 +270,41 @@ describe('matchesQuery', function () { expect(matchesQuery(obj1, q)).toBe(true); }); + it('matches on queries with new format #parse-SDK-JS/pull/1373 for Pointer', function () { + const obj1 = { + objectId: 'Person01', + name: 'Bill', + age: 34, + }; + + const obj2 = { + objectId: 'Car01', + name: 'Volkswagen', + owner: pointer('Person', obj1.objectId), + }; + + const q = { + owner: { + $eq: pointer('Person', obj1.objectId), + }, + }; + expect(matchesQuery(obj2, q)).toBe(true); + }); + + it('matches on queries with new format #parse-SDK-JS/pull/1373 for Object', function () { + const obj1 = { + id: new Id('Person', '01'), + addr: { planet: 'Earth' }, + }; + + const q = { + addr: { + $eq: { planet: 'Earth' }, + }, + }; + expect(matchesQuery(obj1, q)).toBe(true); + }); + it('matches on inequalities', function () { const player = { id: new Id('Person', 'O1'), From e864fd248c5aeb79890b3d41ef3350f3e3ea5aa1 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Thu, 6 Jan 2022 11:27:33 +0530 Subject: [PATCH 6/7] added testcase for array type --- spec/QueryTools.spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/QueryTools.spec.js b/spec/QueryTools.spec.js index a3d08dd809..1a29a3de9d 100644 --- a/spec/QueryTools.spec.js +++ b/spec/QueryTools.spec.js @@ -305,6 +305,21 @@ describe('matchesQuery', function () { expect(matchesQuery(obj1, q)).toBe(true); }); + it('matches on queries with new format #parse-SDK-JS/pull/1373 for Array', function () { + const obj = { + objectId: 'Person01', + name: 'Bill', + nums: [1, 2, 3, 4], + }; + + const q = { + nums: { + $eq: 5, + }, + }; + expect(matchesQuery(obj, q)).toBe(false); + }); + it('matches on inequalities', function () { const player = { id: new Id('Person', 'O1'), From 8d5021ff66fd53039ecbd28486a3b60dfc732e3b Mon Sep 17 00:00:00 2001 From: sadakchap Date: Thu, 6 Jan 2022 11:28:01 +0530 Subject: [PATCH 7/7] using objectId instead of id in testcases --- spec/QueryTools.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/QueryTools.spec.js b/spec/QueryTools.spec.js index 1a29a3de9d..28bbc7a9e4 100644 --- a/spec/QueryTools.spec.js +++ b/spec/QueryTools.spec.js @@ -257,7 +257,7 @@ describe('matchesQuery', function () { it('matches on queries with new format #parse-SDK-JS/pull/1373', function () { const obj1 = { - id: new Id('Person', 'O1'), + objectId: 'Person01', score: 12, name: 'Bill', }; @@ -293,7 +293,7 @@ describe('matchesQuery', function () { it('matches on queries with new format #parse-SDK-JS/pull/1373 for Object', function () { const obj1 = { - id: new Id('Person', '01'), + objectId: 'Person01', addr: { planet: 'Earth' }, };