forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiveQueryController.js
More file actions
63 lines (57 loc) · 1.79 KB
/
LiveQueryController.js
File metadata and controls
63 lines (57 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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;