deno.land / x / mongoose@6.7.5 / lib / helpers / document / handleSpreadDoc.js

handleSpreadDoc.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const utils = require('../../utils');
const keysToSkip = new Set(['__index', '__parentArray', '_doc']);
/** * Using spread operator on a Mongoose document gives you a * POJO that has a tendency to cause infinite recursion. So * we use this function on `set()` to prevent that. */
module.exports = function handleSpreadDoc(v, includeExtraKeys) { if (utils.isPOJO(v) && v.$__ != null && v._doc != null) { if (includeExtraKeys) { const extraKeys = {}; for (const key of Object.keys(v)) { if (typeof key === 'symbol') { continue; } if (key[0] === '$') { continue; } if (keysToSkip.has(key)) { continue; } extraKeys[key] = v[key]; } return { ...v._doc, ...extraKeys }; } return v._doc; }
return v;};
mongoose

Version Info

Tagged at
a year ago