diff --git a/CHANGELOG.md b/CHANGELOG.md index 251f179237..3a12739f78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - 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: 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 [Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index be2da8c866..fa259785ee 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -56,6 +56,29 @@ describe('ParseLiveQuery', function () { 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 => { await reconfigureServer({ liveQuery: { diff --git a/src/Controllers/LiveQueryController.js b/src/Controllers/LiveQueryController.js index 3b239a8c30..ea71ade033 100644 --- a/src/Controllers/LiveQueryController.js +++ b/src/Controllers/LiveQueryController.js @@ -9,7 +9,9 @@ export class LiveQueryController { if (!config || !config.classNames) { this.classNames = new Set(); } 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 { throw 'liveQuery.classes should be an array of string'; } @@ -43,7 +45,12 @@ export class LiveQueryController { } 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 {