Skip to content

Commit 7638ff8

Browse files
Nes-sidplewis
authored andcommitted
Supporting patterns in classNames for Live Queries (#7131)
* Parse LiveQuery Server. Supporting patterns in classNames. * Parse LiveQuery Server. Supporting patterns in classNames. Small optimisation. * Parse LiveQuery Server. Supporting patterns in classNames. Adding info to changelog. * Parse LiveQuery Server. Supporting patterns in classNames. Test case.
1 parent 16de5f4 commit 7638ff8

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ___
1111
- NEW: Added convenience method Parse.Cloud.sendEmail(...) to send email via email adapter in Cloud Code. [#7089](https://github.com/parse-community/parse-server/pull/7089). Thanks to [dblythy](https://github.com/dblythy)
1212
- FIX: Winston Logger interpolating stdout to console [#7114](https://github.com/parse-community/parse-server/pull/7114). Thanks to [dplewis](https://github.com/dplewis)
1313
- NEW: LiveQuery support for $and, $nor, $containedBy, $geoWithin, $geoIntersects queries [#7113](https://github.com/parse-community/parse-server/pull/7113). Thanks to [dplewis](https://github.com/dplewis)
14+
- NEW: Supporting patterns in LiveQuery server's config parameter `classNames` [#7131](https://github.com/parse-community/parse-server/pull/7131). Thanks to [Nes-si](https://github.com/Nes-si)
1415

1516
### 4.5.0
1617
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)

spec/ParseLiveQuery.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ describe('ParseLiveQuery', function () {
5656
await object.save();
5757
});
5858

59+
it('can use patterns in className', async done => {
60+
await reconfigureServer({
61+
liveQuery: {
62+
classNames: ['Test.*'],
63+
},
64+
startLiveQueryServer: true,
65+
verbose: false,
66+
silent: true,
67+
});
68+
const object = new TestObject();
69+
await object.save();
70+
71+
const query = new Parse.Query(TestObject);
72+
query.equalTo('objectId', object.id);
73+
const subscription = await query.subscribe();
74+
subscription.on('update', object => {
75+
expect(object.get('foo')).toBe('bar');
76+
done();
77+
});
78+
object.set({ foo: 'bar' });
79+
await object.save();
80+
});
81+
5982
it('expect afterEvent create', async done => {
6083
await reconfigureServer({
6184
liveQuery: {

src/Controllers/LiveQueryController.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export class LiveQueryController {
99
if (!config || !config.classNames) {
1010
this.classNames = new Set();
1111
} else if (config.classNames instanceof Array) {
12-
this.classNames = new Set(config.classNames);
12+
const classNames = config.classNames
13+
.map(name => new RegExp("^" + name + "$"));
14+
this.classNames = new Set(classNames);
1315
} else {
1416
throw 'liveQuery.classes should be an array of string';
1517
}
@@ -43,7 +45,12 @@ export class LiveQueryController {
4345
}
4446

4547
hasLiveQuery(className: string): boolean {
46-
return this.classNames.has(className);
48+
for (const name of this.classNames) {
49+
if (name.test(className)) {
50+
return true;
51+
}
52+
}
53+
return false;
4754
}
4855

4956
_makePublisherRequest(currentObject: any, originalObject: any, classLevelPermissions: ?any): any {

0 commit comments

Comments
 (0)