feat: align file trigger syntax with class trigger; use the new syntax Parse.Cloud.beforeSave(Parse.File, (request) => {}), the old syntax Parse.Cloud.beforeSaveFile((request) => {}) has been deprecated (#7966)
This commit is contained in:
@@ -12,16 +12,11 @@ export const Types = {
|
||||
afterDelete: 'afterDelete',
|
||||
beforeFind: 'beforeFind',
|
||||
afterFind: 'afterFind',
|
||||
beforeSaveFile: 'beforeSaveFile',
|
||||
afterSaveFile: 'afterSaveFile',
|
||||
beforeDeleteFile: 'beforeDeleteFile',
|
||||
afterDeleteFile: 'afterDeleteFile',
|
||||
beforeConnect: 'beforeConnect',
|
||||
beforeSubscribe: 'beforeSubscribe',
|
||||
afterEvent: 'afterEvent',
|
||||
};
|
||||
|
||||
const FileClassName = '@File';
|
||||
const ConnectClassName = '@Connect';
|
||||
|
||||
const baseStore = function () {
|
||||
@@ -50,6 +45,9 @@ export function getClassName(parseClass) {
|
||||
if (parseClass && parseClass.className) {
|
||||
return parseClass.className;
|
||||
}
|
||||
if (parseClass && parseClass.name) {
|
||||
return parseClass.name.replace('Parse', '@');
|
||||
}
|
||||
return parseClass;
|
||||
}
|
||||
|
||||
@@ -140,11 +138,6 @@ export function addTrigger(type, className, handler, applicationId, validationHa
|
||||
add(Category.Validators, `${type}.${className}`, validationHandler, applicationId);
|
||||
}
|
||||
|
||||
export function addFileTrigger(type, handler, applicationId, validationHandler) {
|
||||
add(Category.Triggers, `${type}.${FileClassName}`, handler, applicationId);
|
||||
add(Category.Validators, `${type}.${FileClassName}`, validationHandler, applicationId);
|
||||
}
|
||||
|
||||
export function addConnectTrigger(type, handler, applicationId, validationHandler) {
|
||||
add(Category.Triggers, `${type}.${ConnectClassName}`, handler, applicationId);
|
||||
add(Category.Validators, `${type}.${ConnectClassName}`, validationHandler, applicationId);
|
||||
@@ -207,10 +200,6 @@ export async function runTrigger(trigger, name, request, auth) {
|
||||
return await trigger(request);
|
||||
}
|
||||
|
||||
export function getFileTrigger(type, applicationId) {
|
||||
return getTrigger(FileClassName, type, applicationId);
|
||||
}
|
||||
|
||||
export function triggerExists(className: string, type: string, applicationId: string): boolean {
|
||||
return getTrigger(className, type, applicationId) != undefined;
|
||||
}
|
||||
@@ -961,7 +950,8 @@ export function getRequestFileObject(triggerType, auth, fileObject, config) {
|
||||
}
|
||||
|
||||
export async function maybeRunFileTrigger(triggerType, fileObject, config, auth) {
|
||||
const fileTrigger = getFileTrigger(triggerType, config.applicationId);
|
||||
const FileClassName = getClassName(Parse.File);
|
||||
const fileTrigger = getTrigger(FileClassName, triggerType, config.applicationId);
|
||||
if (typeof fileTrigger === 'function') {
|
||||
try {
|
||||
const request = getRequestFileObject(triggerType, auth, fileObject, config);
|
||||
|
||||
Reference in New Issue
Block a user