* Auth module refactoring in order to be reusable * Ensure cache controller is properly forwarded from helpers * Nits * Adds support for static validation * Adds support for CLP in Live query (no support for roles yet) * Adds e2e test to validate liveQuery hooks is properly called * Adds tests over LiveQueryController to ensure data is correctly transmitted * nits * Fixes for flow types * Removes usage of Parse.Promise * Use the Auth module for authentication and caches * Cleaner implementation of getting auth * Adds authCache that stores auth promises * Proper testing of the caching * nits
76 lines
1.9 KiB
JavaScript
76 lines
1.9 KiB
JavaScript
import { ParseCloudCodePublisher } from '../LiveQuery/ParseCloudCodePublisher';
|
|
import { LiveQueryOptions } from '../Options';
|
|
export class LiveQueryController {
|
|
classNames: any;
|
|
liveQueryPublisher: any;
|
|
|
|
constructor(config: ?LiveQueryOptions) {
|
|
// If config is empty, we just assume no classs needs to be registered as LiveQuery
|
|
if (!config || !config.classNames) {
|
|
this.classNames = new Set();
|
|
} else if (config.classNames instanceof Array) {
|
|
this.classNames = new Set(config.classNames);
|
|
} else {
|
|
throw 'liveQuery.classes should be an array of string';
|
|
}
|
|
this.liveQueryPublisher = new ParseCloudCodePublisher(config);
|
|
}
|
|
|
|
onAfterSave(
|
|
className: string,
|
|
currentObject: any,
|
|
originalObject: any,
|
|
classLevelPermissions: ?any
|
|
) {
|
|
if (!this.hasLiveQuery(className)) {
|
|
return;
|
|
}
|
|
const req = this._makePublisherRequest(
|
|
currentObject,
|
|
originalObject,
|
|
classLevelPermissions
|
|
);
|
|
this.liveQueryPublisher.onCloudCodeAfterSave(req);
|
|
}
|
|
|
|
onAfterDelete(
|
|
className: string,
|
|
currentObject: any,
|
|
originalObject: any,
|
|
classLevelPermissions: any
|
|
) {
|
|
if (!this.hasLiveQuery(className)) {
|
|
return;
|
|
}
|
|
const req = this._makePublisherRequest(
|
|
currentObject,
|
|
originalObject,
|
|
classLevelPermissions
|
|
);
|
|
this.liveQueryPublisher.onCloudCodeAfterDelete(req);
|
|
}
|
|
|
|
hasLiveQuery(className: string): boolean {
|
|
return this.classNames.has(className);
|
|
}
|
|
|
|
_makePublisherRequest(
|
|
currentObject: any,
|
|
originalObject: any,
|
|
classLevelPermissions: ?any
|
|
): any {
|
|
const req = {
|
|
object: currentObject,
|
|
};
|
|
if (currentObject) {
|
|
req.original = originalObject;
|
|
}
|
|
if (classLevelPermissions) {
|
|
req.classLevelPermissions = classLevelPermissions;
|
|
}
|
|
return req;
|
|
}
|
|
}
|
|
|
|
export default LiveQueryController;
|