From 62b8cd366c4a80d9f073817372c64898c0b3bd5f Mon Sep 17 00:00:00 2001 From: sadakchap Date: Tue, 8 Jun 2021 19:00:14 +0530 Subject: [PATCH 01/12] added failing test case --- src/__tests__/ParseQuery-test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/__tests__/ParseQuery-test.js b/src/__tests__/ParseQuery-test.js index 89150dc03..77dc04b47 100644 --- a/src/__tests__/ParseQuery-test.js +++ b/src/__tests__/ParseQuery-test.js @@ -807,6 +807,21 @@ describe('ParseQuery', () => { }); }); + it('can combine equalTo clause with any other clause', () => { + const q = new ParseQuery('Item'); + q.equalTo('inStock', null); + q.exists('inStock'); + + expect(q.toJSON()).toEqual({ + where: { + inStock: { + $eq: null, + $exists: true, + }, + }, + }); + }); + it('can specify ordering', () => { const q = new ParseQuery('Item'); q.greaterThan('inStock', 0).ascending('createdAt'); From 0fc3c45fcb85099af69864d84ba113d65e74597e Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 9 Jun 2021 10:23:00 +0530 Subject: [PATCH 02/12] adding other clauses on equalTo --- src/ParseQuery.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ParseQuery.js b/src/ParseQuery.js index fe5c6f0ea..9959d2eb5 100644 --- a/src/ParseQuery.js +++ b/src/ParseQuery.js @@ -344,7 +344,9 @@ class ParseQuery { */ _addCondition(key: string, condition: string, value: mixed): ParseQuery { if (!this._where[key] || typeof this._where[key] === 'string') { + const prev = this._where[key]; this._where[key] = {}; + this._where[key]['$eq'] = prev; } this._where[key][condition] = encode(value, false, true); return this; @@ -1222,7 +1224,11 @@ class ParseQuery { return this.doesNotExist(key); } - this._where[key] = encode(value, false, true); + if (typeof this._where[key] === 'undefined') { + this._where[key] = encode(value, false, true); + } else { + this._addCondition(key, '$eq', value); + } return this; } From 0baadbae16ded641b3d20054ec907042aa44bcb2 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 9 Jun 2021 10:31:42 +0530 Subject: [PATCH 03/12] add testcase for combine equalTo to existing clauses --- src/__tests__/ParseQuery-test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/__tests__/ParseQuery-test.js b/src/__tests__/ParseQuery-test.js index 77dc04b47..32f17bd76 100644 --- a/src/__tests__/ParseQuery-test.js +++ b/src/__tests__/ParseQuery-test.js @@ -807,6 +807,21 @@ describe('ParseQuery', () => { }); }); + it('can combine other clauses with equalTo', () => { + const q = new ParseQuery('Item'); + q.exists('inStock'); + q.equalTo('inStock', null); + + expect(q.toJSON()).toEqual({ + where: { + inStock: { + $eq: null, + $exists: true, + }, + }, + }); + }); + it('can combine equalTo clause with any other clause', () => { const q = new ParseQuery('Item'); q.equalTo('inStock', null); From 2a04e8b679eba46b6a75d8aae69ad21dff68c108 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 9 Jun 2021 18:32:46 +0530 Subject: [PATCH 04/12] added condition of string type in add condition --- src/ParseQuery.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ParseQuery.js b/src/ParseQuery.js index 9959d2eb5..8966ea9da 100644 --- a/src/ParseQuery.js +++ b/src/ParseQuery.js @@ -346,7 +346,9 @@ class ParseQuery { if (!this._where[key] || typeof this._where[key] === 'string') { const prev = this._where[key]; this._where[key] = {}; - this._where[key]['$eq'] = prev; + if (typeof this._where[key] === 'string') { + this._where[key]['$eq'] = prev; + } } this._where[key][condition] = encode(value, false, true); return this; From 64bd7286486f70c5b13dc394f4e6087e56f58748 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 22 Sep 2021 08:14:17 +0530 Subject: [PATCH 05/12] using addCondition in equalTo method --- src/ParseQuery.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/ParseQuery.js b/src/ParseQuery.js index 8966ea9da..c6ffb4959 100644 --- a/src/ParseQuery.js +++ b/src/ParseQuery.js @@ -344,11 +344,7 @@ class ParseQuery { */ _addCondition(key: string, condition: string, value: mixed): ParseQuery { if (!this._where[key] || typeof this._where[key] === 'string') { - const prev = this._where[key]; this._where[key] = {}; - if (typeof this._where[key] === 'string') { - this._where[key]['$eq'] = prev; - } } this._where[key][condition] = encode(value, false, true); return this; @@ -1226,11 +1222,8 @@ class ParseQuery { return this.doesNotExist(key); } - if (typeof this._where[key] === 'undefined') { - this._where[key] = encode(value, false, true); - } else { - this._addCondition(key, '$eq', value); - } + // this._where[key] = encode(value, false, true); + this._addCondition(key, '$eq', value); return this; } From 2c294b4f95111c82c5c5b40ba835b45457354063 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 22 Sep 2021 08:16:12 +0530 Subject: [PATCH 06/12] updated testcase to check with arrays --- src/__tests__/ParseQuery-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/__tests__/ParseQuery-test.js b/src/__tests__/ParseQuery-test.js index 32f17bd76..bfc434243 100644 --- a/src/__tests__/ParseQuery-test.js +++ b/src/__tests__/ParseQuery-test.js @@ -824,13 +824,13 @@ describe('ParseQuery', () => { it('can combine equalTo clause with any other clause', () => { const q = new ParseQuery('Item'); - q.equalTo('inStock', null); - q.exists('inStock'); + q.equalTo('arrayField', ['a', 'b']); + q.exists('arrayField'); expect(q.toJSON()).toEqual({ where: { - inStock: { - $eq: null, + arrayField: { + $eq: ['a', 'b'], $exists: true, }, }, From 03ee50409474521f73d2e61899b629aa66db028f Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 22 Sep 2021 08:17:45 +0530 Subject: [PATCH 07/12] added case for '$eq' at matchesKeyConstraints func --- src/OfflineQuery.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/OfflineQuery.js b/src/OfflineQuery.js index 59b191a40..6124c626f 100644 --- a/src/OfflineQuery.js +++ b/src/OfflineQuery.js @@ -325,6 +325,11 @@ function matchesKeyConstraints(className, object, objects, key, constraints) { } switch (condition) { + case '$eq': + if (object[key] !== compareTo) { + return false; + } + break; case '$lt': if (object[key] >= compareTo) { return false; From 445fa8e80b5819918b1446cb2dfffaffaba45fd6 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 22 Sep 2021 08:19:01 +0530 Subject: [PATCH 08/12] fixed failing testcase in ParseQuery-test.js file --- src/__tests__/ParseQuery-test.js | 132 ++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 36 deletions(-) diff --git a/src/__tests__/ParseQuery-test.js b/src/__tests__/ParseQuery-test.js index bfc434243..449e98b8f 100644 --- a/src/__tests__/ParseQuery-test.js +++ b/src/__tests__/ParseQuery-test.js @@ -119,7 +119,9 @@ describe('ParseQuery', () => { q.equalTo('size', 'medium'); expect(q.toJSON()).toEqual({ where: { - size: 'medium', + size: { + $eq: 'medium', + }, }, }); @@ -127,7 +129,9 @@ describe('ParseQuery', () => { q.equalTo('size', 'small'); expect(q.toJSON()).toEqual({ where: { - size: 'small', + size: { + $eq: 'small', + }, }, }); @@ -136,6 +140,7 @@ describe('ParseQuery', () => { expect(q.toJSON()).toEqual({ where: { size: { + $eq: 'small', $exists: false, }, }, @@ -146,8 +151,13 @@ describe('ParseQuery', () => { q.equalTo({ size, stock }); expect(q.toJSON()).toEqual({ where: { - size: 'medium', - stock: true, + size: { + $eq: 'medium', + $exists: false, + }, + stock: { + $eq: true, + }, }, }); }); @@ -463,7 +473,9 @@ describe('ParseQuery', () => { $inQuery: { className: 'Item', where: { - inStock: 0, + inStock: { + $eq: 0, + }, }, }, }, @@ -483,7 +495,9 @@ describe('ParseQuery', () => { $notInQuery: { className: 'Item', where: { - inStock: 0, + inStock: { + $eq: 0, + }, }, }, }, @@ -505,7 +519,9 @@ describe('ParseQuery', () => { query: { className: 'Item', where: { - inStock: 0, + inStock: { + $eq: 0, + }, }, }, }, @@ -528,7 +544,9 @@ describe('ParseQuery', () => { query: { className: 'Item', where: { - inStock: 0, + inStock: { + $eq: 0, + }, }, }, }, @@ -980,7 +998,9 @@ describe('ParseQuery', () => { q.equalTo('name', 'Product 5'); expect(q.toJSON()).toEqual({ where: { - name: 'Product 5', + name: { + $eq: 'Product 5', + }, }, skip: 4, }); @@ -1176,7 +1196,7 @@ describe('ParseQuery', () => { let mediumOrLarge = ParseQuery.or(q, q2); expect(mediumOrLarge.toJSON()).toEqual({ where: { - $or: [{ size: 'medium' }, { size: 'large' }], + $or: [{ size: { $eq: 'medium' } }, { size: { $eq: 'large' } }], }, }); @@ -1185,7 +1205,7 @@ describe('ParseQuery', () => { mediumOrLarge = ParseQuery.or(q, q2); expect(mediumOrLarge.toJSON()).toEqual({ where: { - $or: [{ size: 'medium' }, { size: 'large' }], + $or: [{ size: { $eq: 'medium' } }, { size: { $eq: 'large' } }], }, }); }); @@ -1202,7 +1222,7 @@ describe('ParseQuery', () => { let mediumOrLarge = ParseQuery.and(q, q2); expect(mediumOrLarge.toJSON()).toEqual({ where: { - $and: [{ size: 'medium' }, { size: 'large' }], + $and: [{ size: { $eq: 'medium' } }, { size: { $eq: 'large' } }], }, }); @@ -1211,7 +1231,7 @@ describe('ParseQuery', () => { mediumOrLarge = ParseQuery.and(q, q2); expect(mediumOrLarge.toJSON()).toEqual({ where: { - $and: [{ size: 'medium' }, { size: 'large' }], + $and: [{ size: { $eq: 'medium' } }, { size: { $eq: 'large' } }], }, }); }); @@ -1228,7 +1248,7 @@ describe('ParseQuery', () => { let mediumOrLarge = ParseQuery.nor(q, q2); expect(mediumOrLarge.toJSON()).toEqual({ where: { - $nor: [{ size: 'medium' }, { size: 'large' }], + $nor: [{ size: { $eq: 'medium' } }, { size: { $eq: 'large' } }], }, }); @@ -1237,7 +1257,7 @@ describe('ParseQuery', () => { mediumOrLarge = ParseQuery.nor(q, q2); expect(mediumOrLarge.toJSON()).toEqual({ where: { - $nor: [{ size: 'medium' }, { size: 'large' }], + $nor: [{ size: { $eq: 'medium' } }, { size: { $eq: 'large' } }], }, }); }); @@ -1250,7 +1270,9 @@ describe('ParseQuery', () => { expect(params).toEqual({ limit: 1, where: { - size: 'small', + size: { + $eq: 'small', + }, }, }); expect(options.requestTask).toBeDefined(); @@ -1283,7 +1305,9 @@ describe('ParseQuery', () => { expect(params).toEqual({ limit: 1, where: { - size: 'small', + size: { + $eq: 'small', + }, }, }); expect(options.useMasterKey).toEqual(true); @@ -1314,7 +1338,9 @@ describe('ParseQuery', () => { expect(params).toEqual({ explain: true, where: { - size: 'small', + size: { + $eq: 'small', + }, }, }); expect(options.requestTask).toBeDefined(); @@ -1348,7 +1374,9 @@ describe('ParseQuery', () => { expect(params).toEqual({ limit: 1, where: { - objectId: 'I27', + objectId: { + $eq: 'I27', + }, }, }); expect(options.requestTask).toBeDefined(); @@ -1416,7 +1444,9 @@ describe('ParseQuery', () => { expect(params).toEqual({ limit: 1, where: { - objectId: 'I28', + objectId: { + $eq: 'I28', + }, }, }); expect(options.requestTask).toBeDefined(); @@ -1450,7 +1480,9 @@ describe('ParseQuery', () => { expect(params).toEqual({ limit: 1, where: { - objectId: 'I27', + objectId: { + $eq: 'I27', + }, }, }); expect(options.useMasterKey).toEqual(true); @@ -1481,7 +1513,9 @@ describe('ParseQuery', () => { limit: 0, count: 1, where: { - size: 'small', + size: { + $eq: 'small', + }, }, }); expect(options.requestTask).toBeDefined(); @@ -1510,7 +1544,9 @@ describe('ParseQuery', () => { limit: 0, count: 1, where: { - size: 'small', + size: { + $eq: 'small', + }, }, }); expect(options.useMasterKey).toEqual(true); @@ -1703,7 +1739,9 @@ describe('ParseQuery', () => { include: '*', hint: '_id_', where: { - arrayField: ['a', 'b'], + arrayField: { + $eq: ['a', 'b'], + }, size: { $in: ['small', 'medium'], }, @@ -1713,12 +1751,14 @@ describe('ParseQuery', () => { query: { className: 'Review', where: { - stars: 5, + stars: { $eq: 5 }, }, }, }, }, - valid: true, + valid: { + $eq: true, + }, }, }); expect(options.requestTask).toBeDefined(); @@ -1839,12 +1879,16 @@ describe('ParseQuery', () => { query: { className: 'Review', where: { - stars: 5, + stars: { + $eq: 5, + }, }, }, }, }, - valid: true, + valid: { + $eq: true, + }, }, }); expect(options.requestTask).toBeDefined(); @@ -1909,12 +1953,16 @@ describe('ParseQuery', () => { query: { className: 'Review', where: { - stars: 5, + stars: { + $eq: 5, + }, }, }, }, }, - valid: true, + valid: { + $eq: true, + }, }, }); expect(options.requestTask).toBeDefined(); @@ -1958,7 +2006,9 @@ describe('ParseQuery', () => { size: { $in: ['small', 'medium'], }, - valid: true, + valid: { + $eq: true, + }, }, }); expect(options.useMasterKey).toEqual(true); @@ -2009,7 +2059,9 @@ describe('ParseQuery', () => { size: { $in: ['small', 'medium'], }, - valid: true, + valid: { + $eq: true, + }, }, hint: '_id_', }); @@ -2558,7 +2610,9 @@ describe('ParseQuery', () => { order: 'a,b,c', skip: 4, where: { - size: 'medium', + size: { + $eq: 'medium', + }, }, }); }); @@ -2571,7 +2625,9 @@ describe('ParseQuery', () => { expect(params).toEqual({ distinct: 'size', where: { - size: 'small', + size: { + $eq: 'small', + }, }, }); expect(options.useMasterKey).toEqual(true); @@ -2599,7 +2655,9 @@ describe('ParseQuery', () => { expect(params).toEqual({ distinct: 'size', where: { - size: 'small', + size: { + $eq: 'small', + }, }, }); expect(options.useMasterKey).toEqual(true); @@ -2630,7 +2688,9 @@ describe('ParseQuery', () => { expect(params).toEqual({ distinct: 'size', where: { - size: 'small', + size: { + $eq: 'small', + }, }, hint: '_id_', }); From b20de35001ed286a1e3224d2aeedc92f9b2a4d61 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 22 Sep 2021 08:25:59 +0530 Subject: [PATCH 09/12] fixing failing testcases in Cloud-test.js --- src/__tests__/Cloud-test.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/__tests__/Cloud-test.js b/src/__tests__/Cloud-test.js index b65bff268..52245edb5 100644 --- a/src/__tests__/Cloud-test.js +++ b/src/__tests__/Cloud-test.js @@ -301,7 +301,9 @@ describe('CloudController', () => { expect(data).toEqual({ limit: 1, where: { - objectId: 'jobId1234', + objectId: { + $eq: 'jobId1234', + }, }, }); expect(options.useMasterKey).toBe(true); @@ -323,7 +325,9 @@ describe('CloudController', () => { expect(data).toEqual({ limit: 1, where: { - objectId: 'pushId1234', + objectId: { + $eq: 'pushId1234', + }, }, }); expect(options.useMasterKey).toBe(true); @@ -345,7 +349,9 @@ describe('CloudController', () => { expect(data).toEqual({ limit: 1, where: { - objectId: 'pushId1234', + objectId: { + $eq: 'pushId1234', + }, }, }); expect(options.useMasterKey).toBe(false); From aaff9591b3a0abe07f1f6fd3b3df3d5f7a073822 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 22 Sep 2021 08:40:07 +0530 Subject: [PATCH 10/12] fixed some testcase in LiveQueryClient-test.js --- src/__tests__/LiveQueryClient-test.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/__tests__/LiveQueryClient-test.js b/src/__tests__/LiveQueryClient-test.js index 812ebb978..836be6163 100644 --- a/src/__tests__/LiveQueryClient-test.js +++ b/src/__tests__/LiveQueryClient-test.js @@ -766,7 +766,9 @@ describe('LiveQueryClient', () => { query: { className: 'Test', where: { - key: 'value', + key: { + $eq: 'value', + }, }, }, }); @@ -805,7 +807,9 @@ describe('LiveQueryClient', () => { query: { className: 'Test', where: { - key: 'value', + key: { + $eq: 'value', + }, }, }, }); @@ -884,7 +888,9 @@ describe('LiveQueryClient', () => { query: { className: 'Test', where: { - key: 'value', + key: { + $eq: 'value', + }, }, }, }); @@ -919,7 +925,9 @@ describe('LiveQueryClient', () => { query: { className: 'Test', where: { - key: 'value', + key: { + $eq: 'value', + }, }, }, }); From eb1ead9521c35d09ee206b75da789573dab1c137 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 22 Sep 2021 08:53:43 +0530 Subject: [PATCH 11/12] safe cond, compareTo = null for matchesKeyConstraints --- src/OfflineQuery.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OfflineQuery.js b/src/OfflineQuery.js index 6124c626f..3d0144767 100644 --- a/src/OfflineQuery.js +++ b/src/OfflineQuery.js @@ -300,11 +300,11 @@ function matchesKeyConstraints(className, object, objects, key, constraints) { for (const condition in constraints) { compareTo = constraints[condition]; - if (compareTo.__type) { + if (compareTo && compareTo.__type) { compareTo = decode(compareTo); } // is it a $relativeTime? convert to date - if (compareTo['$relativeTime']) { + if (compareTo && compareTo['$relativeTime']) { const parserResult = relativeTimeToDate(compareTo['$relativeTime']); if (parserResult.status !== 'success') { throw new ParseError( From 7c9f1110b1f07fdde3990194ddd96bcc674fec10 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 22 Sep 2021 22:50:14 +0530 Subject: [PATCH 12/12] updated $eq condition for Pointer and Array contains --- src/OfflineQuery.js | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/OfflineQuery.js b/src/OfflineQuery.js index 3d0144767..e44561782 100644 --- a/src/OfflineQuery.js +++ b/src/OfflineQuery.js @@ -319,17 +319,47 @@ function matchesKeyConstraints(className, object, objects, key, constraints) { toString.call(compareTo) === '[object Date]' || (typeof compareTo === 'string' && new Date(compareTo) !== 'Invalid Date' && - !isNaN(new Date(compareTo))) + !isNaN(new Date(compareTo)) && + new Date(compareTo).toISOString() === compareTo) ) { object[key] = new Date(object[key].iso ? object[key].iso : object[key]); } switch (condition) { - case '$eq': - if (object[key] !== compareTo) { - return false; + 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') { + if ( + !equalObjectsGeneric(object[key], constraints[condition], function (obj, ptr) { + return ( + typeof obj !== 'undefined' && + ptr.className === obj.className && + ptr.objectId === obj.objectId + ); + }) + ) { + return false; + } + break; + } + if (!equalObjects(decode(object[key]), compareTo)) { + return false; + } } break; + } case '$lt': if (object[key] >= compareTo) { return false;