MCPcopy Create free account
hub / github.com/parse-community/parse-server / replacePointers

Function replacePointers

src/RestQuery.js:1324–1356  ·  view source on GitHub ↗
(object, path, replace)

Source from the content-addressed store, hash-verified

1322// Returns something analogous to object, but with the appropriate
1323// pointers inflated.
1324function replacePointers(object, path, replace) {
1325 if (Array.isArray(object)) {
1326 return object
1327 .map(obj => replacePointers(obj, path, replace))
1328 .filter(obj => typeof obj !== 'undefined');
1329 }
1330
1331 if (typeof object !== 'object' || !object) {
1332 return object;
1333 }
1334
1335 if (path.length === 0) {
1336 if (object && object.__type === 'Pointer') {
1337 return replace[object.objectId];
1338 }
1339 return object;
1340 }
1341
1342 var subobject = object[path[0]];
1343 if (!subobject) {
1344 return object;
1345 }
1346 var newsub = replacePointers(subobject, path.slice(1), replace);
1347 var answer = {};
1348 for (var key in object) {
1349 if (key == path[0]) {
1350 answer[key] = newsub;
1351 } else {
1352 answer[key] = object[key];
1353 }
1354 }
1355 return answer;
1356}
1357
1358// Finds a subobject that has the given key, if there is one.
1359// Returns undefined otherwise.

Callers 1

includePathFunction · 0.85

Calls 1

filterMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…