Skip to content

Commit c32a58f

Browse files
committed
fix(file): add #_toPointer
fixes #542
1 parent 6818217 commit c32a58f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/file.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,18 @@ module.exports = function(AV) {
248248
return this._toFullJSON(seenObjects, false);
249249
},
250250

251+
/**
252+
* Gets a Pointer referencing this file.
253+
* @private
254+
*/
255+
_toPointer() {
256+
return {
257+
__type: 'Pointer',
258+
className: this.className,
259+
objectId: this.id,
260+
};
261+
},
262+
251263
/**
252264
* Returns the ACL for this file.
253265
* @returns {AV.ACL} An instance of AV.ACL.

src/object.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ const {
77
transformFetchOptions,
88
setValue,
99
findValue,
10+
isPlainObject,
1011
} = require('./utils');
1112

1213
const recursiveToPointer = value => {
1314
if (_.isArray(value)) return value.map(recursiveToPointer);
14-
if (_.isObject(value)) {
15-
if (value._toPointer) return value._toPointer();
16-
return _.mapObject(value, recursiveToPointer);
17-
}
15+
if (isPlainObject(value)) return _.mapObject(value, recursiveToPointer);
16+
if (_.isObject(value) && value._toPointer) return value._toPointer();
1817
return value;
1918
};
2019

src/utils/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ const findValue = (target, key) => {
221221
return [value, currentTarget, lastSeg, firstSeg];
222222
};
223223

224+
const isPlainObject = obj =>
225+
_.isObject(obj) && Object.getPrototypeOf(obj) === Object.prototype;
226+
224227
module.exports = {
225228
ajax,
226229
isNullOrUndefined,
@@ -232,4 +235,5 @@ module.exports = {
232235
parseDate,
233236
setValue,
234237
findValue,
238+
isPlainObject,
235239
};

0 commit comments

Comments
 (0)