fix: set objects in afterFind triggers (#7311)
This commit is contained in:
@@ -10,7 +10,7 @@ import { ParsePubSub } from './ParsePubSub';
|
||||
import SchemaController from '../Controllers/SchemaController';
|
||||
import _ from 'lodash';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { runLiveQueryEventHandlers, getTrigger, runTrigger } from '../triggers';
|
||||
import { runLiveQueryEventHandlers, getTrigger, runTrigger, toJSONwithObjects } from '../triggers';
|
||||
import { getAuthForSessionToken, Auth } from '../Auth';
|
||||
import { getCacheController } from '../Controllers';
|
||||
import LRU from 'lru-cache';
|
||||
@@ -183,8 +183,7 @@ class ParseLiveQueryServer {
|
||||
return;
|
||||
}
|
||||
if (res.object && typeof res.object.toJSON === 'function') {
|
||||
deletedParseObject = res.object.toJSON();
|
||||
deletedParseObject.className = className;
|
||||
deletedParseObject = toJSONwithObjects(res.object, res.object.className || className);
|
||||
}
|
||||
if (
|
||||
(deletedParseObject.className === '_User' ||
|
||||
@@ -337,13 +336,13 @@ class ParseLiveQueryServer {
|
||||
return;
|
||||
}
|
||||
if (res.object && typeof res.object.toJSON === 'function') {
|
||||
currentParseObject = res.object.toJSON();
|
||||
currentParseObject.className = res.object.className || className;
|
||||
currentParseObject = toJSONwithObjects(res.object, res.object.className || className);
|
||||
}
|
||||
|
||||
if (res.original && typeof res.original.toJSON === 'function') {
|
||||
originalParseObject = res.original.toJSON();
|
||||
originalParseObject.className = res.original.className || className;
|
||||
originalParseObject = toJSONwithObjects(
|
||||
res.original,
|
||||
res.original.className || className
|
||||
);
|
||||
}
|
||||
if (
|
||||
(currentParseObject.className === '_User' ||
|
||||
|
||||
@@ -168,6 +168,27 @@ export function _unregisterAll() {
|
||||
Object.keys(_triggerStore).forEach(appId => delete _triggerStore[appId]);
|
||||
}
|
||||
|
||||
export function toJSONwithObjects(object, className) {
|
||||
if (!object || !object.toJSON) {
|
||||
return {};
|
||||
}
|
||||
const toJSON = object.toJSON();
|
||||
const stateController = Parse.CoreManager.getObjectStateController();
|
||||
const [pending] = stateController.getPendingOps(object._getStateIdentifier());
|
||||
for (const key in pending) {
|
||||
const val = object.get(key);
|
||||
if (!val || !val._toFullJSON) {
|
||||
toJSON[key] = val;
|
||||
continue;
|
||||
}
|
||||
toJSON[key] = val._toFullJSON();
|
||||
}
|
||||
if (className) {
|
||||
toJSON.className = className;
|
||||
}
|
||||
return toJSON;
|
||||
}
|
||||
|
||||
export function getTrigger(className, triggerType, applicationId) {
|
||||
if (!applicationId) {
|
||||
throw 'Missing ApplicationID';
|
||||
@@ -323,7 +344,7 @@ export function getResponseObject(request, resolve, reject) {
|
||||
response = request.objects;
|
||||
}
|
||||
response = response.map(object => {
|
||||
return object.toJSON();
|
||||
return toJSONwithObjects(object);
|
||||
});
|
||||
return resolve(response);
|
||||
}
|
||||
@@ -451,12 +472,6 @@ export function maybeRunAfterFindTrigger(
|
||||
const response = trigger(request);
|
||||
if (response && typeof response.then === 'function') {
|
||||
return response.then(results => {
|
||||
if (!results) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.SCRIPT_FAILED,
|
||||
'AfterFind expect results to be returned in the promise'
|
||||
);
|
||||
}
|
||||
return results;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user