Skip to content

Commit eb35fe5

Browse files
authored
Merge 296940d into 992b3c7
2 parents 992b3c7 + 296940d commit eb35fe5

File tree

5 files changed

+110
-14
lines changed

5 files changed

+110
-14
lines changed

Diff for: DEPRECATIONS.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h
1212
| 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 | - |
1313
| 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 | - |
1414
| 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 | - |
15+
| 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 | - |
1516

1617
[i_deprecation]: ## "The version and date of the deprecation."
1718
[i_removal]: ## "The version and date of the planned removal."

Diff for: spec/ParseLiveQueryServer.spec.js

+62-6
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ describe('ParseLiveQueryServer', function () {
294294
where: {
295295
key: 'value',
296296
},
297-
fields: ['test'],
297+
keys: ['test'],
298298
};
299299
const requestId = 2;
300300
const request = {
@@ -331,7 +331,7 @@ describe('ParseLiveQueryServer', function () {
331331
where: {
332332
key: 'value',
333333
},
334-
fields: ['test'],
334+
keys: ['test'],
335335
};
336336
const requestId = 2;
337337
const request = {
@@ -378,7 +378,7 @@ describe('ParseLiveQueryServer', function () {
378378
where: {
379379
key: 'value',
380380
},
381-
fields: ['test'],
381+
keys: ['test'],
382382
};
383383
await addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query);
384384
// Add subscription for mock client 2
@@ -390,7 +390,7 @@ describe('ParseLiveQueryServer', function () {
390390
where: {
391391
key: 'value',
392392
},
393-
fields: ['testAgain'],
393+
keys: ['testAgain'],
394394
};
395395
const requestIdAgain = 1;
396396
await addMockSubscription(
@@ -1060,7 +1060,7 @@ describe('ParseLiveQueryServer', function () {
10601060
where: {
10611061
key: 'value',
10621062
},
1063-
fields: ['test'],
1063+
keys: ['test'],
10641064
};
10651065
await addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query);
10661066
// Mock _matchesSubscription to return matching
@@ -1087,6 +1087,62 @@ describe('ParseLiveQueryServer', function () {
10871087
done();
10881088
});
10891089

1090+
it('can deprecate fields', async () => {
1091+
const Deprecator = require('../lib/Deprecator/Deprecator');
1092+
const spy = spyOn(Deprecator, 'logRuntimeDeprecation').and.callFake(() => {});
1093+
jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client');
1094+
const Client = require('../lib/LiveQuery/Client').Client;
1095+
const parseLiveQueryServer = new ParseLiveQueryServer({});
1096+
// Make mock request message
1097+
const message = generateMockMessage();
1098+
1099+
const clientId = 1;
1100+
const parseWebSocket = {
1101+
clientId,
1102+
send: jasmine.createSpy('send'),
1103+
};
1104+
const client = new Client(clientId, parseWebSocket);
1105+
spyOn(client, 'pushCreate').and.callThrough();
1106+
parseLiveQueryServer.clients.set(clientId, client);
1107+
1108+
// Add mock subscription
1109+
const requestId = 2;
1110+
const query = {
1111+
className: testClassName,
1112+
where: {
1113+
key: 'value',
1114+
},
1115+
fields: ['test'],
1116+
};
1117+
await addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query);
1118+
// Mock _matchesSubscription to return matching
1119+
parseLiveQueryServer._matchesSubscription = function (parseObject) {
1120+
if (!parseObject) {
1121+
return false;
1122+
}
1123+
return true;
1124+
};
1125+
parseLiveQueryServer._matchesACL = function () {
1126+
return Promise.resolve(true);
1127+
};
1128+
1129+
parseLiveQueryServer._onAfterSave(message);
1130+
1131+
// Make sure we send create command to client
1132+
await timeout();
1133+
1134+
expect(client.pushCreate).toHaveBeenCalled();
1135+
const args = parseWebSocket.send.calls.mostRecent().args;
1136+
const toSend = JSON.parse(args[0]);
1137+
expect(toSend.object).toBeDefined();
1138+
expect(toSend.original).toBeUndefined();
1139+
expect(spy).toHaveBeenCalledWith({
1140+
usage: 'Subscribing using fields parameter',
1141+
solution:
1142+
`Subscribe using "keys" instead.`,
1143+
});
1144+
});
1145+
10901146
it('can handle create command with watch', async () => {
10911147
jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client');
10921148
const Client = require('../lib/LiveQuery/Client').Client;
@@ -1865,7 +1921,7 @@ describe('ParseLiveQueryServer', function () {
18651921
where: {
18661922
key: 'value',
18671923
},
1868-
fields: ['test'],
1924+
keys: ['test'],
18691925
};
18701926
}
18711927
const request = {

Diff for: src/LiveQuery/Client.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ class Client {
9898
response['requestId'] = subscriptionId;
9999
}
100100
if (typeof parseObjectJSON !== 'undefined') {
101-
let fields;
101+
let keys;
102102
if (this.subscriptionInfos.has(subscriptionId)) {
103-
fields = this.subscriptionInfos.get(subscriptionId).fields;
103+
keys = this.subscriptionInfos.get(subscriptionId).keys;
104104
}
105-
response['object'] = this._toJSONWithFields(parseObjectJSON, fields);
105+
response['object'] = this._toJSONWithFields(parseObjectJSON, keys);
106106
if (parseOriginalObjectJSON) {
107-
response['original'] = this._toJSONWithFields(parseOriginalObjectJSON, fields);
107+
response['original'] = this._toJSONWithFields(parseOriginalObjectJSON, keys);
108108
}
109109
}
110110
Client.pushResponse(this.parseWebSocket, JSON.stringify(response));

Diff for: src/LiveQuery/ParseLiveQueryServer.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import LRU from 'lru-cache';
2323
import UserRouter from '../Routers/UsersRouter';
2424
import DatabaseController from '../Controllers/DatabaseController';
2525
import { isDeepStrictEqual } from 'util';
26+
import Deprecator from '../Deprecator/Deprecator';
2627

2728
class ParseLiveQueryServer {
2829
clients: Map;
@@ -850,9 +851,6 @@ class ParseLiveQueryServer {
850851
await runTrigger(trigger, `beforeSubscribe.${className}`, request, auth);
851852

852853
const query = request.query.toJSON();
853-
if (query.keys) {
854-
query.fields = query.keys.split(',');
855-
}
856854
request.query = query;
857855
}
858856

@@ -901,8 +899,17 @@ class ParseLiveQueryServer {
901899
subscription: subscription,
902900
};
903901
// Add selected fields, sessionToken and installationId for this subscription if necessary
902+
if (request.query.keys) {
903+
subscriptionInfo.keys = Array.isArray(request.query.keys)
904+
? request.query.keys
905+
: request.query.keys.split(',');
906+
}
904907
if (request.query.fields) {
905-
subscriptionInfo.fields = request.query.fields;
908+
subscriptionInfo.keys = request.query.fields;
909+
Deprecator.logRuntimeDeprecation({
910+
usage: `Subscribing using fields parameter`,
911+
solution: `Subscribe using "keys" instead.`,
912+
});
906913
}
907914
if (request.query.watch) {
908915
subscriptionInfo.watch = request.query.watch;

Diff for: src/LiveQuery/RequestSchema.js

+32
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ const subscribe = {
7070
minItems: 1,
7171
uniqueItems: true,
7272
},
73+
keys: {
74+
type: 'array',
75+
items: {
76+
type: 'string',
77+
},
78+
minItems: 1,
79+
uniqueItems: true,
80+
},
81+
watch: {
82+
type: 'array',
83+
items: {
84+
type: 'string',
85+
},
86+
minItems: 1,
87+
uniqueItems: true,
88+
},
7389
},
7490
required: ['where', 'className'],
7591
additionalProperties: false,
@@ -108,6 +124,22 @@ const update = {
108124
minItems: 1,
109125
uniqueItems: true,
110126
},
127+
keys: {
128+
type: 'array',
129+
items: {
130+
type: 'string',
131+
},
132+
minItems: 1,
133+
uniqueItems: true,
134+
},
135+
watch: {
136+
type: 'array',
137+
items: {
138+
type: 'string',
139+
},
140+
minItems: 1,
141+
uniqueItems: true,
142+
},
111143
},
112144
required: ['where', 'className'],
113145
additionalProperties: false,

0 commit comments

Comments
 (0)