This commit is contained in:
PLBXNebulia-Formation 2025-11-21 09:23:11 +01:00
commit d1c8cae2c1
1417 changed files with 326736 additions and 0 deletions

View file

@ -0,0 +1,7 @@
'use strict';
module.exports = function addAutoId(schema) {
const _obj = { _id: { auto: true } };
_obj._id[schema.options.typeKey] = 'ObjectId';
schema.add(_obj);
};

View file

@ -0,0 +1,12 @@
'use strict';
const builtinPlugins = require('../../plugins');
module.exports = function applyBuiltinPlugins(schema) {
for (const plugin of Object.values(builtinPlugins)) {
plugin(schema, { deduplicate: true });
}
schema.plugins = Object.values(builtinPlugins).
map(fn => ({ fn, opts: { deduplicate: true } })).
concat(schema.plugins);
};

View file

@ -0,0 +1,55 @@
'use strict';
module.exports = function applyPlugins(schema, plugins, options, cacheKey) {
if (schema[cacheKey]) {
return;
}
schema[cacheKey] = true;
if (!options || !options.skipTopLevel) {
let pluginTags = null;
for (const plugin of plugins) {
const tags = plugin[1] == null ? null : plugin[1].tags;
if (!Array.isArray(tags)) {
schema.plugin(plugin[0], plugin[1]);
continue;
}
pluginTags = pluginTags || new Set(schema.options.pluginTags || []);
if (!tags.find(tag => pluginTags.has(tag))) {
continue;
}
schema.plugin(plugin[0], plugin[1]);
}
}
options = Object.assign({}, options);
delete options.skipTopLevel;
if (options.applyPluginsToChildSchemas !== false) {
for (const path of Object.keys(schema.paths)) {
const type = schema.paths[path];
if (type.schema != null) {
applyPlugins(type.schema, plugins, options, cacheKey);
// Recompile schema because plugins may have changed it, see gh-7572
type.caster.prototype.$__setSchema(type.schema);
}
}
}
const discriminators = schema.discriminators;
if (discriminators == null) {
return;
}
const applyPluginsToDiscriminators = options.applyPluginsToDiscriminators;
const keys = Object.keys(discriminators);
for (const discriminatorKey of keys) {
const discriminatorSchema = discriminators[discriminatorKey];
applyPlugins(discriminatorSchema, plugins,
{ skipTopLevel: !applyPluginsToDiscriminators }, cacheKey);
}
};

View file

@ -0,0 +1,20 @@
'use strict';
module.exports = function applyReadConcern(schema, options) {
if (options.readConcern !== undefined) {
return;
}
// Don't apply default read concern to operations in transactions,
// because you shouldn't set read concern on individual operations
// within a transaction.
// See: https://www.mongodb.com/docs/manual/reference/read-concern/
if (options && options.session && options.session.transaction) {
return;
}
const level = schema.options?.readConcern?.level;
if (level != null) {
options.readConcern = { level };
}
};

View file

@ -0,0 +1,37 @@
'use strict';
module.exports = function applyWriteConcern(schema, options) {
if (options.writeConcern != null) {
return;
}
// Don't apply default write concern to operations in transactions,
// because setting write concern on an operation in a transaction is an error
// See: https://www.mongodb.com/docs/manual/reference/write-concern/
if (options && options.session && options.session.transaction) {
return;
}
const writeConcern = schema.options.writeConcern ?? {};
if (Object.keys(writeConcern).length != 0) {
options.writeConcern = {};
if (!('w' in options) && writeConcern.w != null) {
options.writeConcern.w = writeConcern.w;
}
if (!('j' in options) && writeConcern.j != null) {
options.writeConcern.j = writeConcern.j;
}
if (!('wtimeout' in options) && writeConcern.wtimeout != null) {
options.writeConcern.wtimeout = writeConcern.wtimeout;
}
}
else {
if (!('w' in options) && writeConcern.w != null) {
options.w = writeConcern.w;
}
if (!('j' in options) && writeConcern.j != null) {
options.j = writeConcern.j;
}
if (!('wtimeout' in options) && writeConcern.wtimeout != null) {
options.wtimeout = writeConcern.wtimeout;
}
}
};

View file

@ -0,0 +1,12 @@
'use strict';
/**
* For consistency's sake, we replace positional operator `$` and array filters
* `$[]` and `$[foo]` with `0` when looking up schema paths.
*/
module.exports = function cleanPositionalOperators(path) {
return path.
replace(/\.\$(\[[^\]]*\])?(?=\.)/g, '.0').
replace(/\.\$(\[[^\]]*\])?$/g, '.0');
};

177
node_modules/mongoose/lib/helpers/schema/getIndexes.js generated vendored Normal file
View file

@ -0,0 +1,177 @@
'use strict';
const get = require('../get');
const helperIsObject = require('../isObject');
const decorateDiscriminatorIndexOptions = require('../indexes/decorateDiscriminatorIndexOptions');
/**
* Gather all indexes defined in the schema, including single nested,
* document arrays, and embedded discriminators.
* @param {Schema} schema
* @api private
*/
module.exports = function getIndexes(schema) {
let indexes = [];
const schemaStack = new WeakMap();
const indexTypes = schema.constructor.indexTypes;
const indexByName = new Map();
collectIndexes(schema);
return indexes;
function collectIndexes(schema, prefix, baseSchema) {
// Ignore infinitely nested schemas, if we've already seen this schema
// along this path there must be a cycle
if (schemaStack.has(schema)) {
return;
}
schemaStack.set(schema, true);
prefix = prefix || '';
const keys = Object.keys(schema.paths);
for (const key of keys) {
const path = schema.paths[key];
if (baseSchema != null && baseSchema.paths[key]) {
// If looking at an embedded discriminator schema, don't look at paths
// that the
continue;
}
if (path._duplicateKeyErrorMessage != null) {
schema._duplicateKeyErrorMessagesByPath = schema._duplicateKeyErrorMessagesByPath || {};
schema._duplicateKeyErrorMessagesByPath[key] = path._duplicateKeyErrorMessage;
}
if (path.$isMongooseDocumentArray || path.$isSingleNested) {
if (get(path, 'options.excludeIndexes') !== true &&
get(path, 'schemaOptions.excludeIndexes') !== true &&
get(path, 'schema.options.excludeIndexes') !== true) {
collectIndexes(path.schema, prefix + key + '.');
}
if (path.schema.discriminators != null) {
const discriminators = path.schema.discriminators;
const discriminatorKeys = Object.keys(discriminators);
for (const discriminatorKey of discriminatorKeys) {
collectIndexes(discriminators[discriminatorKey],
prefix + key + '.', path.schema);
}
}
// Retained to minimize risk of backwards breaking changes due to
// gh-6113
if (path.$isMongooseDocumentArray) {
continue;
}
}
const index = path._index || (path.caster && path.caster._index);
if (index !== false && index !== null && index !== undefined) {
const field = {};
const isObject = helperIsObject(index);
const options = isObject ? { ...index } : {};
const type = typeof index === 'string' ? index :
isObject ? index.type :
false;
if (type && indexTypes.indexOf(type) !== -1) {
field[prefix + key] = type;
} else if (options.text) {
field[prefix + key] = 'text';
delete options.text;
} else {
let isDescendingIndex = false;
if (index === 'descending' || index === 'desc') {
isDescendingIndex = true;
} else if (index === 'ascending' || index === 'asc') {
isDescendingIndex = false;
} else {
isDescendingIndex = Number(index) === -1;
}
field[prefix + key] = isDescendingIndex ? -1 : 1;
}
delete options.type;
if (!('background' in options)) {
options.background = true;
}
if (schema.options.autoIndex != null) {
options._autoIndex = schema.options.autoIndex;
}
const indexName = options && options.name;
if (typeof indexName === 'string') {
if (indexByName.has(indexName)) {
Object.assign(indexByName.get(indexName), field);
} else {
indexes.push([field, options]);
indexByName.set(indexName, field);
}
} else {
indexes.push([field, options]);
indexByName.set(indexName, field);
}
}
}
schemaStack.delete(schema);
if (prefix) {
fixSubIndexPaths(schema, prefix);
} else {
schema._indexes.forEach(function(index) {
const options = index[1];
if (!('background' in options)) {
options.background = true;
}
decorateDiscriminatorIndexOptions(schema, options);
});
indexes = indexes.concat(schema._indexes);
}
}
/**
* Checks for indexes added to subdocs using Schema.index().
* These indexes need their paths prefixed properly.
*
* schema._indexes = [ [indexObj, options], [indexObj, options] ..]
* @param {Schema} schema
* @param {String} prefix
* @api private
*/
function fixSubIndexPaths(schema, prefix) {
const subindexes = schema._indexes;
const len = subindexes.length;
for (let i = 0; i < len; ++i) {
const indexObj = subindexes[i][0];
const indexOptions = subindexes[i][1];
const keys = Object.keys(indexObj);
const klen = keys.length;
const newindex = {};
// use forward iteration, order matters
for (let j = 0; j < klen; ++j) {
const key = keys[j];
newindex[prefix + key] = indexObj[key];
}
const newIndexOptions = Object.assign({}, indexOptions);
if (indexOptions != null && indexOptions.partialFilterExpression != null) {
newIndexOptions.partialFilterExpression = {};
const partialFilterExpression = indexOptions.partialFilterExpression;
for (const key of Object.keys(partialFilterExpression)) {
newIndexOptions.partialFilterExpression[prefix + key] =
partialFilterExpression[key];
}
}
indexes.push([newindex, newIndexOptions]);
}
}
};

View file

@ -0,0 +1,28 @@
'use strict';
const get = require('../get');
module.exports = function getKeysInSchemaOrder(schema, val, path) {
const schemaKeys = path != null ? Object.keys(get(schema.tree, path, {})) : Object.keys(schema.tree);
const valKeys = new Set(Object.keys(val));
let keys;
if (valKeys.size > 1) {
keys = new Set();
for (const key of schemaKeys) {
if (valKeys.has(key)) {
keys.add(key);
}
}
for (const key of valKeys) {
if (!keys.has(key)) {
keys.add(key);
}
}
keys = Array.from(keys);
} else {
keys = Array.from(valKeys);
}
return keys;
};

43
node_modules/mongoose/lib/helpers/schema/getPath.js generated vendored Normal file
View file

@ -0,0 +1,43 @@
'use strict';
const numberRE = /^\d+$/;
/**
* Behaves like `Schema#path()`, except for it also digs into arrays without
* needing to put `.0.`, so `getPath(schema, 'docArr.elProp')` works.
* @api private
*/
module.exports = function getPath(schema, path, discriminatorValueMap) {
let schematype = schema.path(path);
if (schematype != null) {
return schematype;
}
const pieces = path.split('.');
let cur = '';
let isArray = false;
for (const piece of pieces) {
if (isArray && numberRE.test(piece)) {
continue;
}
cur = cur.length === 0 ? piece : cur + '.' + piece;
schematype = schema.path(cur);
if (schematype?.schema) {
schema = schematype.schema;
if (!isArray && schematype.$isMongooseDocumentArray) {
isArray = true;
}
if (discriminatorValueMap && discriminatorValueMap[cur]) {
schema = schema.discriminators[discriminatorValueMap[cur]] ?? schema;
}
cur = '';
} else if (schematype?.instance === 'Mixed') {
// If we found a mixed path, no point in digging further, the end result is always Mixed
break;
}
}
return schematype;
};

View file

@ -0,0 +1,32 @@
'use strict';
/**
* Find the `strict` mode setting for the deepest subdocument along a given path
* to ensure we have the correct default value for `strict`. When setting values
* underneath a subdocument, we should use the subdocument's `strict` setting by
* default, not the top-level document's.
*
* @param {Schema} schema
* @param {String[]} parts
* @returns {boolean | 'throw' | undefined}
*/
module.exports = function getSubdocumentStrictValue(schema, parts) {
if (parts.length === 1) {
return undefined;
}
let cur = parts[0];
let strict = undefined;
for (let i = 0; i < parts.length - 1; ++i) {
const curSchemaType = schema.path(cur);
if (curSchemaType && curSchemaType.schema) {
strict = curSchemaType.schema.options.strict;
schema = curSchemaType.schema;
cur = curSchemaType.$isMongooseDocumentArray && !isNaN(parts[i + 1]) ? '' : parts[i + 1];
} else {
cur += cur.length ? ('.' + parts[i + 1]) : parts[i + 1];
}
}
return strict;
};

View file

@ -0,0 +1,20 @@
'use strict';
const addAutoId = require('./addAutoId');
module.exports = function handleIdOption(schema, options) {
if (options == null || options._id == null) {
return schema;
}
schema = schema.clone();
if (!options._id) {
schema.remove('_id');
schema.options._id = false;
} else if (!schema.paths['_id']) {
addAutoId(schema);
schema.options._id = true;
}
return schema;
};

View file

@ -0,0 +1,24 @@
'use strict';
module.exports = handleTimestampOption;
/*!
* ignore
*/
function handleTimestampOption(arg, prop) {
if (arg == null) {
return null;
}
if (typeof arg === 'boolean') {
return prop;
}
if (typeof arg[prop] === 'boolean') {
return arg[prop] ? prop : null;
}
if (!(prop in arg)) {
return prop;
}
return arg[prop];
}

34
node_modules/mongoose/lib/helpers/schema/idGetter.js generated vendored Normal file
View file

@ -0,0 +1,34 @@
'use strict';
/*!
* ignore
*/
module.exports = function addIdGetter(schema) {
// ensure the documents receive an id getter unless disabled
const autoIdGetter = !schema.paths['id'] &&
schema.paths['_id'] &&
schema.options.id;
if (!autoIdGetter) {
return schema;
}
if (schema.aliases && schema.aliases.id) {
return schema;
}
schema.virtual('id').get(idGetter);
return schema;
};
/**
* Returns this documents _id cast to a string.
* @api private
*/
function idGetter() {
if (this._id != null) {
return this._id.toString();
}
return null;
}

36
node_modules/mongoose/lib/helpers/schema/merge.js generated vendored Normal file
View file

@ -0,0 +1,36 @@
'use strict';
module.exports = function merge(s1, s2, skipConflictingPaths) {
const paths = Object.keys(s2.tree);
const pathsToAdd = {};
for (const key of paths) {
if (skipConflictingPaths && (s1.paths[key] || s1.nested[key] || s1.singleNestedPaths[key])) {
continue;
}
pathsToAdd[key] = s2.tree[key];
}
s1.options._isMerging = true;
s1.add(pathsToAdd, null);
delete s1.options._isMerging;
s1.callQueue = s1.callQueue.concat(s2.callQueue);
s1.method(s2.methods);
s1.static(s2.statics);
for (const [option, value] of Object.entries(s2._userProvidedOptions)) {
if (!(option in s1._userProvidedOptions)) {
s1.set(option, value);
}
}
for (const query in s2.query) {
s1.query[query] = s2.query[query];
}
for (const virtual in s2.virtuals) {
s1.virtuals[virtual] = s2.virtuals[virtual].clone();
}
s1._indexes = s1._indexes.concat(s2._indexes || []);
s1.s.hooks.merge(s2.s.hooks, false);
};