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
16
node_modules/mongoose/lib/helpers/discriminator/areDiscriminatorValuesEqual.js
generated
vendored
Normal file
16
node_modules/mongoose/lib/helpers/discriminator/areDiscriminatorValuesEqual.js
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
const isBsonType = require('../isBsonType');
|
||||
|
||||
module.exports = function areDiscriminatorValuesEqual(a, b) {
|
||||
if (typeof a === 'string' && typeof b === 'string') {
|
||||
return a === b;
|
||||
}
|
||||
if (typeof a === 'number' && typeof b === 'number') {
|
||||
return a === b;
|
||||
}
|
||||
if (isBsonType(a, 'ObjectId') && isBsonType(b, 'ObjectId')) {
|
||||
return a.toString() === b.toString();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
12
node_modules/mongoose/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js
generated
vendored
Normal file
12
node_modules/mongoose/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function checkEmbeddedDiscriminatorKeyProjection(userProjection, path, schema, selected, addedPaths) {
|
||||
const userProjectedInPath = Object.keys(userProjection).
|
||||
reduce((cur, key) => cur || key.startsWith(path + '.'), false);
|
||||
const _discriminatorKey = path + '.' + schema.options.discriminatorKey;
|
||||
if (!userProjectedInPath &&
|
||||
addedPaths.length === 1 &&
|
||||
addedPaths[0] === _discriminatorKey) {
|
||||
selected.splice(selected.indexOf(_discriminatorKey), 1);
|
||||
}
|
||||
};
|
||||
26
node_modules/mongoose/lib/helpers/discriminator/getConstructor.js
generated
vendored
Normal file
26
node_modules/mongoose/lib/helpers/discriminator/getConstructor.js
generated
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
const getDiscriminatorByValue = require('./getDiscriminatorByValue');
|
||||
|
||||
/**
|
||||
* Find the correct constructor, taking into account discriminators
|
||||
* @api private
|
||||
*/
|
||||
|
||||
module.exports = function getConstructor(Constructor, value) {
|
||||
const discriminatorKey = Constructor.schema.options.discriminatorKey;
|
||||
if (value != null &&
|
||||
Constructor.discriminators &&
|
||||
value[discriminatorKey] != null) {
|
||||
if (Constructor.discriminators[value[discriminatorKey]]) {
|
||||
Constructor = Constructor.discriminators[value[discriminatorKey]];
|
||||
} else {
|
||||
const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[discriminatorKey]);
|
||||
if (constructorByValue) {
|
||||
Constructor = constructorByValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Constructor;
|
||||
};
|
||||
28
node_modules/mongoose/lib/helpers/discriminator/getDiscriminatorByValue.js
generated
vendored
Normal file
28
node_modules/mongoose/lib/helpers/discriminator/getDiscriminatorByValue.js
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
|
||||
const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
|
||||
|
||||
/**
|
||||
* returns discriminator by discriminatorMapping.value
|
||||
*
|
||||
* @param {Object} discriminators
|
||||
* @param {string} value
|
||||
* @api private
|
||||
*/
|
||||
|
||||
module.exports = function getDiscriminatorByValue(discriminators, value) {
|
||||
if (discriminators == null) {
|
||||
return null;
|
||||
}
|
||||
for (const name of Object.keys(discriminators)) {
|
||||
const it = discriminators[name];
|
||||
if (
|
||||
it.schema &&
|
||||
it.schema.discriminatorMapping &&
|
||||
areDiscriminatorValuesEqual(it.schema.discriminatorMapping.value, value)
|
||||
) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
27
node_modules/mongoose/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js
generated
vendored
Normal file
27
node_modules/mongoose/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
|
||||
|
||||
/**
|
||||
* returns discriminator by discriminatorMapping.value
|
||||
*
|
||||
* @param {Schema} schema
|
||||
* @param {string} value
|
||||
* @api private
|
||||
*/
|
||||
|
||||
module.exports = function getSchemaDiscriminatorByValue(schema, value) {
|
||||
if (schema == null || schema.discriminators == null) {
|
||||
return null;
|
||||
}
|
||||
for (const key of Object.keys(schema.discriminators)) {
|
||||
const discriminatorSchema = schema.discriminators[key];
|
||||
if (discriminatorSchema.discriminatorMapping == null) {
|
||||
continue;
|
||||
}
|
||||
if (areDiscriminatorValuesEqual(discriminatorSchema.discriminatorMapping.value, value)) {
|
||||
return discriminatorSchema;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
75
node_modules/mongoose/lib/helpers/discriminator/mergeDiscriminatorSchema.js
generated
vendored
Normal file
75
node_modules/mongoose/lib/helpers/discriminator/mergeDiscriminatorSchema.js
generated
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
'use strict';
|
||||
const schemaMerge = require('../schema/merge');
|
||||
const specialProperties = require('../../helpers/specialProperties');
|
||||
const isBsonType = require('../../helpers/isBsonType');
|
||||
const ObjectId = require('../../types/objectid');
|
||||
const isObject = require('../../helpers/isObject');
|
||||
/**
|
||||
* Merges `from` into `to` without overwriting existing properties.
|
||||
*
|
||||
* @param {Object} to
|
||||
* @param {Object} from
|
||||
* @param {String} [path]
|
||||
* @api private
|
||||
*/
|
||||
|
||||
module.exports = function mergeDiscriminatorSchema(to, from, path, seen) {
|
||||
const keys = Object.keys(from);
|
||||
let i = 0;
|
||||
const len = keys.length;
|
||||
let key;
|
||||
|
||||
path = path || '';
|
||||
seen = seen || new WeakSet();
|
||||
|
||||
if (seen.has(from)) {
|
||||
return;
|
||||
}
|
||||
seen.add(from);
|
||||
|
||||
while (i < len) {
|
||||
key = keys[i++];
|
||||
if (!path) {
|
||||
if (key === 'discriminators' ||
|
||||
key === 'base' ||
|
||||
key === '_applyDiscriminators' ||
|
||||
key === '_userProvidedOptions' ||
|
||||
key === 'options') {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (path === 'tree' && from != null && from.instanceOfSchema) {
|
||||
continue;
|
||||
}
|
||||
if (specialProperties.has(key)) {
|
||||
continue;
|
||||
}
|
||||
if (to[key] == null) {
|
||||
to[key] = from[key];
|
||||
} else if (isObject(from[key])) {
|
||||
if (!isObject(to[key])) {
|
||||
to[key] = {};
|
||||
}
|
||||
if (from[key] != null) {
|
||||
// Skip merging schemas if we're creating a discriminator schema and
|
||||
// base schema has a given path as a single nested but discriminator schema
|
||||
// has the path as a document array, or vice versa (gh-9534)
|
||||
if ((from[key].$isSingleNested && to[key].$isMongooseDocumentArray) ||
|
||||
(from[key].$isMongooseDocumentArray && to[key].$isSingleNested)) {
|
||||
continue;
|
||||
} else if (from[key].instanceOfSchema) {
|
||||
if (to[key].instanceOfSchema) {
|
||||
schemaMerge(to[key], from[key].clone(), true);
|
||||
} else {
|
||||
to[key] = from[key].clone();
|
||||
}
|
||||
continue;
|
||||
} else if (isBsonType(from[key], 'ObjectId')) {
|
||||
to[key] = new ObjectId(from[key]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
mergeDiscriminatorSchema(to[key], from[key], path ? path + '.' + key : key, seen);
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue