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.
This commit is contained in:
@@ -11,6 +11,7 @@ ___
|
|||||||
- 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)
|
- 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)
|
||||||
- FIX: Winston Logger interpolating stdout to console [#7114](https://github.com/parse-community/parse-server/pull/7114). Thanks to [dplewis](https://github.com/dplewis)
|
- FIX: Winston Logger interpolating stdout to console [#7114](https://github.com/parse-community/parse-server/pull/7114). Thanks to [dplewis](https://github.com/dplewis)
|
||||||
- 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)
|
- 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)
|
||||||
|
- 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)
|
||||||
|
|
||||||
### 4.5.0
|
### 4.5.0
|
||||||
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)
|
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)
|
||||||
|
|||||||
@@ -56,6 +56,29 @@ describe('ParseLiveQuery', function () {
|
|||||||
await object.save();
|
await object.save();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can use patterns in className', async done => {
|
||||||
|
await reconfigureServer({
|
||||||
|
liveQuery: {
|
||||||
|
classNames: ['Test.*'],
|
||||||
|
},
|
||||||
|
startLiveQueryServer: true,
|
||||||
|
verbose: false,
|
||||||
|
silent: true,
|
||||||
|
});
|
||||||
|
const object = new TestObject();
|
||||||
|
await object.save();
|
||||||
|
|
||||||
|
const query = new Parse.Query(TestObject);
|
||||||
|
query.equalTo('objectId', object.id);
|
||||||
|
const subscription = await query.subscribe();
|
||||||
|
subscription.on('update', object => {
|
||||||
|
expect(object.get('foo')).toBe('bar');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
object.set({ foo: 'bar' });
|
||||||
|
await object.save();
|
||||||
|
});
|
||||||
|
|
||||||
it('expect afterEvent create', async done => {
|
it('expect afterEvent create', async done => {
|
||||||
await reconfigureServer({
|
await reconfigureServer({
|
||||||
liveQuery: {
|
liveQuery: {
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ export class LiveQueryController {
|
|||||||
if (!config || !config.classNames) {
|
if (!config || !config.classNames) {
|
||||||
this.classNames = new Set();
|
this.classNames = new Set();
|
||||||
} else if (config.classNames instanceof Array) {
|
} else if (config.classNames instanceof Array) {
|
||||||
this.classNames = new Set(config.classNames);
|
const classNames = config.classNames
|
||||||
|
.map(name => new RegExp("^" + name + "$"));
|
||||||
|
this.classNames = new Set(classNames);
|
||||||
} else {
|
} else {
|
||||||
throw 'liveQuery.classes should be an array of string';
|
throw 'liveQuery.classes should be an array of string';
|
||||||
}
|
}
|
||||||
@@ -43,7 +45,12 @@ export class LiveQueryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasLiveQuery(className: string): boolean {
|
hasLiveQuery(className: string): boolean {
|
||||||
return this.classNames.has(className);
|
for (const name of this.classNames) {
|
||||||
|
if (name.test(className)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_makePublisherRequest(currentObject: any, originalObject: any, classLevelPermissions: ?any): any {
|
_makePublisherRequest(currentObject: any, originalObject: any, classLevelPermissions: ?any): any {
|
||||||
|
|||||||
Reference in New Issue
Block a user