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:
dblythy
2022-05-30 04:48:55 +10:00
committed by GitHub
parent ac283d3cc0
commit c6dcad8d16
6 changed files with 123 additions and 91 deletions

View File

@@ -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);