mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-24 01:29:19 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
127
node_modules/mongoose/lib/helpers/common.js
generated
vendored
Normal file
127
node_modules/mongoose/lib/helpers/common.js
generated
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
'use strict';
|
||||
|
||||
/*!
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const Binary = require('bson').Binary;
|
||||
const isBsonType = require('./isBsonType');
|
||||
const isMongooseObject = require('./isMongooseObject');
|
||||
const MongooseError = require('../error');
|
||||
const util = require('util');
|
||||
|
||||
exports.flatten = flatten;
|
||||
exports.modifiedPaths = modifiedPaths;
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
function flatten(update, path, options, schema) {
|
||||
let keys;
|
||||
if (update && isMongooseObject(update) && !Buffer.isBuffer(update)) {
|
||||
keys = Object.keys(update.toObject({ transform: false, virtuals: false }) || {});
|
||||
} else {
|
||||
keys = Object.keys(update || {});
|
||||
}
|
||||
|
||||
const numKeys = keys.length;
|
||||
const result = {};
|
||||
path = path ? path + '.' : '';
|
||||
|
||||
for (let i = 0; i < numKeys; ++i) {
|
||||
const key = keys[i];
|
||||
const val = update[key];
|
||||
result[path + key] = val;
|
||||
|
||||
// Avoid going into mixed paths if schema is specified
|
||||
const keySchema = schema && schema.path && schema.path(path + key);
|
||||
const isNested = schema && schema.nested && schema.nested[path + key];
|
||||
if (keySchema && keySchema.instance === 'Mixed') continue;
|
||||
|
||||
if (shouldFlatten(val)) {
|
||||
if (options && options.skipArrays && Array.isArray(val)) {
|
||||
continue;
|
||||
}
|
||||
const flat = flatten(val, path + key, options, schema);
|
||||
for (const k in flat) {
|
||||
result[k] = flat[k];
|
||||
}
|
||||
if (Array.isArray(val)) {
|
||||
result[path + key] = val;
|
||||
}
|
||||
}
|
||||
|
||||
if (isNested) {
|
||||
const paths = Object.keys(schema.paths);
|
||||
for (const p of paths) {
|
||||
if (p.startsWith(path + key + '.') && !result.hasOwnProperty(p)) {
|
||||
result[p] = void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
function modifiedPaths(update, path, result, recursion = null) {
|
||||
if (update == null || typeof update !== 'object') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (recursion == null) {
|
||||
recursion = {
|
||||
raw: { update, path },
|
||||
trace: new WeakSet()
|
||||
};
|
||||
}
|
||||
|
||||
if (recursion.trace.has(update)) {
|
||||
throw new MongooseError(`a circular reference in the update value, updateValue:
|
||||
${util.inspect(recursion.raw.update, { showHidden: false, depth: 1 })}
|
||||
updatePath: '${recursion.raw.path}'`);
|
||||
}
|
||||
recursion.trace.add(update);
|
||||
|
||||
const keys = Object.keys(update || {});
|
||||
const numKeys = keys.length;
|
||||
result = result || {};
|
||||
path = path ? path + '.' : '';
|
||||
|
||||
for (let i = 0; i < numKeys; ++i) {
|
||||
const key = keys[i];
|
||||
let val = update[key];
|
||||
|
||||
const _path = path + key;
|
||||
result[_path] = true;
|
||||
if (!Buffer.isBuffer(val) && isMongooseObject(val)) {
|
||||
val = val.toObject({ transform: false, virtuals: false });
|
||||
}
|
||||
if (shouldFlatten(val)) {
|
||||
modifiedPaths(val, path + key, result, recursion);
|
||||
}
|
||||
}
|
||||
recursion.trace.delete(update);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
function shouldFlatten(val) {
|
||||
return val &&
|
||||
typeof val === 'object' &&
|
||||
!(val instanceof Date) &&
|
||||
!isBsonType(val, 'ObjectId') &&
|
||||
(!Array.isArray(val) || val.length !== 0) &&
|
||||
!(val instanceof Buffer) &&
|
||||
!isBsonType(val, 'Decimal128') &&
|
||||
!(val instanceof Binary);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue