fix: allow LiveQuery on Parse.Session (#7554)

This commit is contained in:
dblythy
2021-10-09 02:24:33 +11:00
committed by GitHub
parent 484c2e81ca
commit caee281bc5
7 changed files with 120 additions and 22 deletions

View File

@@ -1591,11 +1591,22 @@ RestWrite.prototype.sanitizedData = function () {
// Returns an updated copy of the object
RestWrite.prototype.buildUpdatedObject = function (extraData) {
const className = Parse.Object.fromJSON(extraData);
const readOnlyAttributes = className.constructor.readOnlyAttributes
? className.constructor.readOnlyAttributes()
: [];
if (!this.originalData) {
for (const attribute of readOnlyAttributes) {
extraData[attribute] = this.data[attribute];
}
}
const updatedObject = triggers.inflate(extraData, this.originalData);
Object.keys(this.data).reduce(function (data, key) {
if (key.indexOf('.') > 0) {
if (typeof data[key].__op === 'string') {
updatedObject.set(key, data[key]);
if (!readOnlyAttributes.includes(key)) {
updatedObject.set(key, data[key]);
}
} else {
// subdocument key with dot notation { 'x.y': v } => { 'x': { 'y' : v } })
const splittedKey = key.split('.');
@@ -1612,7 +1623,11 @@ RestWrite.prototype.buildUpdatedObject = function (extraData) {
return data;
}, deepcopy(this.data));
updatedObject.set(this.sanitizedData());
const sanitized = this.sanitizedData();
for (const attribute of readOnlyAttributes) {
delete sanitized[attribute];
}
updatedObject.set(sanitized);
return updatedObject;
};