From ccf34168ed3ac67805a3985410678dc42e85d9bb Mon Sep 17 00:00:00 2001 From: dblythy Date: Tue, 17 Jan 2023 01:04:53 +1100 Subject: [PATCH 1/8] fix: rename LiveQuery `fields` option to `keys` --- spec/ParseLiveQueryServer.spec.js | 12 ++++++------ src/LiveQuery/Client.js | 8 ++++---- src/LiveQuery/ParseLiveQueryServer.js | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/spec/ParseLiveQueryServer.spec.js b/spec/ParseLiveQueryServer.spec.js index 47e90733a1..99f6caff29 100644 --- a/spec/ParseLiveQueryServer.spec.js +++ b/spec/ParseLiveQueryServer.spec.js @@ -294,7 +294,7 @@ describe('ParseLiveQueryServer', function () { where: { key: 'value', }, - fields: ['test'], + keys: ['test'], }; const requestId = 2; const request = { @@ -331,7 +331,7 @@ describe('ParseLiveQueryServer', function () { where: { key: 'value', }, - fields: ['test'], + keys: ['test'], }; const requestId = 2; const request = { @@ -378,7 +378,7 @@ describe('ParseLiveQueryServer', function () { where: { key: 'value', }, - fields: ['test'], + keys: ['test'], }; await addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query); // Add subscription for mock client 2 @@ -390,7 +390,7 @@ describe('ParseLiveQueryServer', function () { where: { key: 'value', }, - fields: ['testAgain'], + keys: ['testAgain'], }; const requestIdAgain = 1; await addMockSubscription( @@ -1060,7 +1060,7 @@ describe('ParseLiveQueryServer', function () { where: { key: 'value', }, - fields: ['test'], + keys: ['test'], }; await addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query); // Mock _matchesSubscription to return matching @@ -1865,7 +1865,7 @@ describe('ParseLiveQueryServer', function () { where: { key: 'value', }, - fields: ['test'], + keys: ['test'], }; } const request = { diff --git a/src/LiveQuery/Client.js b/src/LiveQuery/Client.js index 56d1baedcd..0ce629bd4e 100644 --- a/src/LiveQuery/Client.js +++ b/src/LiveQuery/Client.js @@ -98,13 +98,13 @@ class Client { response['requestId'] = subscriptionId; } if (typeof parseObjectJSON !== 'undefined') { - let fields; + let keys; if (this.subscriptionInfos.has(subscriptionId)) { - fields = this.subscriptionInfos.get(subscriptionId).fields; + keys = this.subscriptionInfos.get(subscriptionId).keys; } - response['object'] = this._toJSONWithFields(parseObjectJSON, fields); + response['object'] = this._toJSONWithFields(parseObjectJSON, keys); if (parseOriginalObjectJSON) { - response['original'] = this._toJSONWithFields(parseOriginalObjectJSON, fields); + response['original'] = this._toJSONWithFields(parseOriginalObjectJSON, keys); } } Client.pushResponse(this.parseWebSocket, JSON.stringify(response)); diff --git a/src/LiveQuery/ParseLiveQueryServer.js b/src/LiveQuery/ParseLiveQueryServer.js index 1ecbda9372..a786d4602c 100644 --- a/src/LiveQuery/ParseLiveQueryServer.js +++ b/src/LiveQuery/ParseLiveQueryServer.js @@ -850,9 +850,6 @@ class ParseLiveQueryServer { await runTrigger(trigger, `beforeSubscribe.${className}`, request, auth); const query = request.query.toJSON(); - if (query.keys) { - query.fields = query.keys.split(','); - } request.query = query; } @@ -901,8 +898,11 @@ class ParseLiveQueryServer { subscription: subscription, }; // Add selected fields, sessionToken and installationId for this subscription if necessary + if (request.query.keys) { + subscriptionInfo.keys = request.query.keys; + } if (request.query.fields) { - subscriptionInfo.fields = request.query.fields; + subscriptionInfo.keys = request.query.fields; } if (request.query.watch) { subscriptionInfo.watch = request.query.watch; From c18e7a470af58ff6243f817afee98b5f4a55ec0d Mon Sep 17 00:00:00 2001 From: dblythy Date: Tue, 17 Jan 2023 01:41:30 +1100 Subject: [PATCH 2/8] wip --- src/LiveQuery/ParseLiveQueryServer.js | 5 +++++ src/LiveQuery/RequestSchema.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/LiveQuery/ParseLiveQueryServer.js b/src/LiveQuery/ParseLiveQueryServer.js index a786d4602c..9745a68fca 100644 --- a/src/LiveQuery/ParseLiveQueryServer.js +++ b/src/LiveQuery/ParseLiveQueryServer.js @@ -23,6 +23,7 @@ import LRU from 'lru-cache'; import UserRouter from '../Routers/UsersRouter'; import DatabaseController from '../Controllers/DatabaseController'; import { isDeepStrictEqual } from 'util'; +import Deprecator from '../Deprecator/Deprecator'; class ParseLiveQueryServer { clients: Map; @@ -903,6 +904,10 @@ class ParseLiveQueryServer { } if (request.query.fields) { subscriptionInfo.keys = request.query.fields; + Deprecator.logRuntimeDeprecation({ + usage: `Subscribing using fields parameter`, + solution: `Subscribe using "keys" instead.`, + }); } if (request.query.watch) { subscriptionInfo.watch = request.query.watch; diff --git a/src/LiveQuery/RequestSchema.js b/src/LiveQuery/RequestSchema.js index 14cb2f046b..44a2c8fe9c 100644 --- a/src/LiveQuery/RequestSchema.js +++ b/src/LiveQuery/RequestSchema.js @@ -70,6 +70,22 @@ const subscribe = { minItems: 1, uniqueItems: true, }, + keys: { + type: 'array', + items: { + type: 'string', + }, + minItems: 1, + uniqueItems: true, + }, + watch: { + type: 'array', + items: { + type: 'string', + }, + minItems: 1, + uniqueItems: true, + }, }, required: ['where', 'className'], additionalProperties: false, From 18a2e736cf39e9194530e04f0368899159b75595 Mon Sep 17 00:00:00 2001 From: dblythy Date: Tue, 17 Jan 2023 01:49:57 +1100 Subject: [PATCH 3/8] add deps --- DEPRECATIONS.md | 1 + spec/ParseLiveQueryServer.spec.js | 56 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/DEPRECATIONS.md b/DEPRECATIONS.md index a647782210..e2750f6a7c 100644 --- a/DEPRECATIONS.md +++ b/DEPRECATIONS.md @@ -12,6 +12,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h | DEPPS6 | Auth providers disabled by default | [#7953](https://github.com/parse-community/parse-server/pull/7953) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - | | DEPPS7 | Remove file trigger syntax `Parse.Cloud.beforeSaveFile((request) => {})` | [#7966](https://github.com/parse-community/parse-server/pull/7966) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - | | DEPPS8 | Login with expired 3rd party authentication token defaults to `false` | [#7079](https://github.com/parse-community/parse-server/pull/7079) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - | +| DEPPS9 | LiveQuery parameter `fields` | [#8389](https://github.com/parse-community/parse-server/issues/8389) | 6.0.0 (2023) | 7.0.0 (2024) | deprecated | - | [i_deprecation]: ## "The version and date of the deprecation." [i_removal]: ## "The version and date of the planned removal." diff --git a/spec/ParseLiveQueryServer.spec.js b/spec/ParseLiveQueryServer.spec.js index 99f6caff29..5b4690ae85 100644 --- a/spec/ParseLiveQueryServer.spec.js +++ b/spec/ParseLiveQueryServer.spec.js @@ -1087,6 +1087,62 @@ describe('ParseLiveQueryServer', function () { done(); }); + it('can deprecate fields', async () => { + const Deprecator = require('../lib/Deprecator/Deprecator'); + const spy = spyOn(Deprecator, 'logRuntimeDeprecation').and.callFake(() => {}); + jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client'); + const Client = require('../lib/LiveQuery/Client').Client; + const parseLiveQueryServer = new ParseLiveQueryServer({}); + // Make mock request message + const message = generateMockMessage(); + + const clientId = 1; + const parseWebSocket = { + clientId, + send: jasmine.createSpy('send'), + }; + const client = new Client(clientId, parseWebSocket); + spyOn(client, 'pushCreate').and.callThrough(); + parseLiveQueryServer.clients.set(clientId, client); + + // Add mock subscription + const requestId = 2; + const query = { + className: testClassName, + where: { + key: 'value', + }, + fields: ['test'], + }; + await addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query); + // Mock _matchesSubscription to return matching + parseLiveQueryServer._matchesSubscription = function (parseObject) { + if (!parseObject) { + return false; + } + return true; + }; + parseLiveQueryServer._matchesACL = function () { + return Promise.resolve(true); + }; + + parseLiveQueryServer._onAfterSave(message); + + // Make sure we send create command to client + await timeout(); + + expect(client.pushCreate).toHaveBeenCalled(); + const args = parseWebSocket.send.calls.mostRecent().args; + const toSend = JSON.parse(args[0]); + expect(toSend.object).toBeDefined(); + expect(toSend.original).toBeUndefined(); + expect(spy).toHaveBeenCalledWith({ + usage: 'Subscribing using fields parameter', + solution: + `Subscribe using "keys" instead.`, + }); + }); + it('can handle create command with watch', async () => { jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client'); const Client = require('../lib/LiveQuery/Client').Client; From ee6ca47b731e96710b9e62b6847390ce5f6c562a Mon Sep 17 00:00:00 2001 From: dblythy Date: Tue, 17 Jan 2023 11:31:41 +1100 Subject: [PATCH 4/8] Update ParseLiveQueryServer.js --- src/LiveQuery/ParseLiveQueryServer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiveQuery/ParseLiveQueryServer.js b/src/LiveQuery/ParseLiveQueryServer.js index 9745a68fca..59a1878ecd 100644 --- a/src/LiveQuery/ParseLiveQueryServer.js +++ b/src/LiveQuery/ParseLiveQueryServer.js @@ -900,7 +900,7 @@ class ParseLiveQueryServer { }; // Add selected fields, sessionToken and installationId for this subscription if necessary if (request.query.keys) { - subscriptionInfo.keys = request.query.keys; + subscriptionInfo.keys = Array.isArray(request.query.keys) ? request.query.keys : [request.query.keys]; } if (request.query.fields) { subscriptionInfo.keys = request.query.fields; From 49a54c2c986a7141e1fdf6acb5e80a758c4d4af8 Mon Sep 17 00:00:00 2001 From: dblythy Date: Thu, 19 Jan 2023 11:18:43 +1100 Subject: [PATCH 5/8] Update RequestSchema.js --- src/LiveQuery/RequestSchema.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/LiveQuery/RequestSchema.js b/src/LiveQuery/RequestSchema.js index 44a2c8fe9c..25cc6ef608 100644 --- a/src/LiveQuery/RequestSchema.js +++ b/src/LiveQuery/RequestSchema.js @@ -124,6 +124,14 @@ const update = { minItems: 1, uniqueItems: true, }, + watch: { + type: 'array', + items: { + type: 'string', + }, + minItems: 1, + uniqueItems: true, + }, }, required: ['where', 'className'], additionalProperties: false, From af9d16bb12ab0036fa8793ef84d7f61af9952bc5 Mon Sep 17 00:00:00 2001 From: dblythy Date: Sat, 21 Jan 2023 11:34:03 +1100 Subject: [PATCH 6/8] Update RequestSchema.js --- src/LiveQuery/RequestSchema.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/LiveQuery/RequestSchema.js b/src/LiveQuery/RequestSchema.js index 25cc6ef608..3a88e9930d 100644 --- a/src/LiveQuery/RequestSchema.js +++ b/src/LiveQuery/RequestSchema.js @@ -124,6 +124,14 @@ const update = { minItems: 1, uniqueItems: true, }, + keys: { + type: 'array', + items: { + type: 'string', + }, + minItems: 1, + uniqueItems: true, + }, watch: { type: 'array', items: { From 8cc4160bd135f3f6fa8627f3342ff89af373834b Mon Sep 17 00:00:00 2001 From: dblythy Date: Wed, 25 Jan 2023 18:24:27 +1100 Subject: [PATCH 7/8] Update ParseLiveQueryServer.js --- src/LiveQuery/ParseLiveQueryServer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/LiveQuery/ParseLiveQueryServer.js b/src/LiveQuery/ParseLiveQueryServer.js index 59a1878ecd..934a556966 100644 --- a/src/LiveQuery/ParseLiveQueryServer.js +++ b/src/LiveQuery/ParseLiveQueryServer.js @@ -900,7 +900,9 @@ class ParseLiveQueryServer { }; // Add selected fields, sessionToken and installationId for this subscription if necessary if (request.query.keys) { - subscriptionInfo.keys = Array.isArray(request.query.keys) ? request.query.keys : [request.query.keys]; + subscriptionInfo.keys = Array.isArray(request.query.keys) + ? request.query.keys + : request.query.keys.split(','); } if (request.query.fields) { subscriptionInfo.keys = request.query.fields; From 296940d58d07cf803c3b59bd95110fd61f213463 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:34:06 +0100 Subject: [PATCH 8/8] Update DEPRECATIONS.md Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- DEPRECATIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPRECATIONS.md b/DEPRECATIONS.md index e2750f6a7c..56359c937e 100644 --- a/DEPRECATIONS.md +++ b/DEPRECATIONS.md @@ -12,7 +12,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h | DEPPS6 | Auth providers disabled by default | [#7953](https://github.com/parse-community/parse-server/pull/7953) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - | | DEPPS7 | Remove file trigger syntax `Parse.Cloud.beforeSaveFile((request) => {})` | [#7966](https://github.com/parse-community/parse-server/pull/7966) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - | | DEPPS8 | Login with expired 3rd party authentication token defaults to `false` | [#7079](https://github.com/parse-community/parse-server/pull/7079) | 5.3.0 (2022) | 7.0.0 (2024) | deprecated | - | -| DEPPS9 | LiveQuery parameter `fields` | [#8389](https://github.com/parse-community/parse-server/issues/8389) | 6.0.0 (2023) | 7.0.0 (2024) | deprecated | - | +| DEPPS9 | Rename LiveQuery `fields` option to `keys` | [#8389](https://github.com/parse-community/parse-server/issues/8389) | 6.0.0 (2023) | 7.0.0 (2024) | deprecated | - | [i_deprecation]: ## "The version and date of the deprecation." [i_removal]: ## "The version and date of the planned removal."