forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parse.Cloud.js
69 lines (55 loc) · 2.41 KB
/
Parse.Cloud.js
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
64
65
66
67
68
69
import { Parse } from 'parse/node';
import * as triggers from '../triggers';
function validateClassNameForTriggers(className) {
const restrictedClassNames = [ '_Session' ];
if (restrictedClassNames.indexOf(className) != -1) {
throw `Triggers are not supported for ${className} class.`;
}
return className;
}
function getClassName(parseClass) {
if (parseClass && parseClass.className) {
return validateClassNameForTriggers(parseClass.className);
}
return validateClassNameForTriggers(parseClass);
}
var ParseCloud = {};
ParseCloud.define = function(functionName, handler, validationHandler) {
triggers.addFunction(functionName, handler, validationHandler, Parse.applicationId);
};
ParseCloud.job = function(functionName, handler) {
triggers.addJob(functionName, handler, Parse.applicationId);
};
ParseCloud.beforeSave = function(parseClass, handler) {
var className = getClassName(parseClass);
triggers.addTrigger(triggers.Types.beforeSave, className, handler, Parse.applicationId);
};
ParseCloud.beforeDelete = function(parseClass, handler) {
var className = getClassName(parseClass);
triggers.addTrigger(triggers.Types.beforeDelete, className, handler, Parse.applicationId);
};
ParseCloud.afterSave = function(parseClass, handler) {
var className = getClassName(parseClass);
triggers.addTrigger(triggers.Types.afterSave, className, handler, Parse.applicationId);
};
ParseCloud.afterDelete = function(parseClass, handler) {
var className = getClassName(parseClass);
triggers.addTrigger(triggers.Types.afterDelete, className, handler, Parse.applicationId);
};
ParseCloud.beforeFind = function(parseClass, handler) {
var className = getClassName(parseClass);
triggers.addTrigger(triggers.Types.beforeFind, className, handler, Parse.applicationId);
};
ParseCloud.afterFind = function(parseClass, handler) {
const className = getClassName(parseClass);
triggers.addTrigger(triggers.Types.afterFind, className, handler, Parse.applicationId);
};
ParseCloud._removeAllHooks = () => {
triggers._unregisterAll();
}
ParseCloud.useMasterKey = () => {
// eslint-disable-next-line
console.warn("Parse.Cloud.useMasterKey is deprecated (and has no effect anymore) on parse-server, please refer to the cloud code migration notes: https://github.com/ParsePlatform/parse-server/wiki/Compatibility-with-Hosted-Parse#cloud-code")
}
ParseCloud.httpRequest = require("./httpRequest");
module.exports = ParseCloud;