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

46
node_modules/mongoose/lib/cast/bigint.js generated vendored Normal file
View file

@ -0,0 +1,46 @@
'use strict';
const { Long } = require('bson');
/**
* Given a value, cast it to a BigInt, or throw an `Error` if the value
* cannot be casted. `null` and `undefined` are considered valid.
*
* @param {Any} value
* @return {Number}
* @throws {Error} if `value` is not one of the allowed values
* @api private
*/
const MAX_BIGINT = 9223372036854775807n;
const MIN_BIGINT = -9223372036854775808n;
const ERROR_MESSAGE = `Mongoose only supports BigInts between ${MIN_BIGINT} and ${MAX_BIGINT} because MongoDB does not support arbitrary precision integers`;
module.exports = function castBigInt(val) {
if (val == null) {
return val;
}
if (val === '') {
return null;
}
if (typeof val === 'bigint') {
if (val > MAX_BIGINT || val < MIN_BIGINT) {
throw new Error(ERROR_MESSAGE);
}
return val;
}
if (val instanceof Long) {
return val.toBigInt();
}
if (typeof val === 'string' || typeof val === 'number') {
val = BigInt(val);
if (val > MAX_BIGINT || val < MIN_BIGINT) {
throw new Error(ERROR_MESSAGE);
}
return val;
}
throw new Error(`Cannot convert value to BigInt: "${val}"`);
};

32
node_modules/mongoose/lib/cast/boolean.js generated vendored Normal file
View file

@ -0,0 +1,32 @@
'use strict';
const CastError = require('../error/cast');
/**
* Given a value, cast it to a boolean, or throw a `CastError` if the value
* cannot be casted. `null` and `undefined` are considered valid.
*
* @param {Any} value
* @param {String} [path] optional the path to set on the CastError
* @return {Boolean|null|undefined}
* @throws {CastError} if `value` is not one of the allowed values
* @api private
*/
module.exports = function castBoolean(value, path) {
if (module.exports.convertToTrue.has(value)) {
return true;
}
if (module.exports.convertToFalse.has(value)) {
return false;
}
if (value == null) {
return value;
}
throw new CastError('boolean', value, path);
};
module.exports.convertToTrue = new Set([true, 'true', 1, '1', 'yes']);
module.exports.convertToFalse = new Set([false, 'false', 0, '0', 'no']);

41
node_modules/mongoose/lib/cast/date.js generated vendored Normal file
View file

@ -0,0 +1,41 @@
'use strict';
const assert = require('assert');
module.exports = function castDate(value) {
// Support empty string because of empty form values. Originally introduced
// in https://github.com/Automattic/mongoose/commit/efc72a1898fc3c33a319d915b8c5463a22938dfe
if (value == null || value === '') {
return null;
}
if (value instanceof Date) {
assert.ok(!isNaN(value.valueOf()));
return value;
}
let date;
assert.ok(typeof value !== 'boolean');
if (value instanceof Number || typeof value === 'number') {
date = new Date(value);
} else if (typeof value === 'string' && !isNaN(Number(value)) && (Number(value) >= 275761 || Number(value) < -271820)) {
// string representation of milliseconds take this path
date = new Date(Number(value));
} else if (typeof value.valueOf === 'function') {
// support for moment.js. This is also the path strings will take because
// strings have a `valueOf()`
date = new Date(value.valueOf());
} else {
// fallback
date = new Date(value);
}
if (!isNaN(date.valueOf())) {
return date;
}
assert.ok(false);
};

39
node_modules/mongoose/lib/cast/decimal128.js generated vendored Normal file
View file

@ -0,0 +1,39 @@
'use strict';
const Decimal128Type = require('../types/decimal128');
const assert = require('assert');
module.exports = function castDecimal128(value) {
if (value == null) {
return value;
}
if (typeof value === 'object' && typeof value.$numberDecimal === 'string') {
return Decimal128Type.fromString(value.$numberDecimal);
}
if (value instanceof Decimal128Type) {
return value;
}
if (typeof value === 'string') {
return Decimal128Type.fromString(value);
}
if (typeof Buffer === 'function' && Buffer.isBuffer(value)) {
return new Decimal128Type(value);
}
if (typeof Uint8Array === 'function' && value instanceof Uint8Array) {
return new Decimal128Type(value);
}
if (typeof value === 'number') {
return Decimal128Type.fromString(String(value));
}
if (typeof value.valueOf === 'function' && typeof value.valueOf() === 'string') {
return Decimal128Type.fromString(value.valueOf());
}
assert.ok(false);
};

50
node_modules/mongoose/lib/cast/double.js generated vendored Normal file
View file

@ -0,0 +1,50 @@
'use strict';
const assert = require('assert');
const BSON = require('bson');
const isBsonType = require('../helpers/isBsonType');
/**
* Given a value, cast it to a IEEE 754-2008 floating point, or throw an `Error` if the value
* cannot be casted. `null`, `undefined`, and `NaN` are considered valid inputs.
*
* @param {Any} value
* @return {Number}
* @throws {Error} if `value` does not represent a IEEE 754-2008 floating point. If casting from a string, see [BSON Double.fromString API documentation](https://mongodb.github.io/node-mongodb-native/Next/classes/BSON.Double.html#fromString)
* @api private
*/
module.exports = function castDouble(val) {
if (val == null || val === '') {
return null;
}
let coercedVal;
if (isBsonType(val, 'Long')) {
coercedVal = val.toNumber();
} else if (typeof val === 'string') {
try {
coercedVal = BSON.Double.fromString(val);
return coercedVal;
} catch {
assert.ok(false);
}
} else if (typeof val === 'object') {
const tempVal = val.valueOf() ?? val.toString();
// ex: { a: 'im an object, valueOf: () => 'helloworld' } // throw an error
if (typeof tempVal === 'string') {
try {
coercedVal = BSON.Double.fromString(val);
return coercedVal;
} catch {
assert.ok(false);
}
} else {
coercedVal = Number(tempVal);
}
} else {
coercedVal = Number(val);
}
return new BSON.Double(coercedVal);
};

36
node_modules/mongoose/lib/cast/int32.js generated vendored Normal file
View file

@ -0,0 +1,36 @@
'use strict';
const isBsonType = require('../helpers/isBsonType');
const assert = require('assert');
/**
* Given a value, cast it to a Int32, or throw an `Error` if the value
* cannot be casted. `null` and `undefined` are considered valid.
*
* @param {Any} value
* @return {Number}
* @throws {Error} if `value` does not represent an integer, or is outside the bounds of an 32-bit integer.
* @api private
*/
module.exports = function castInt32(val) {
if (val == null) {
return val;
}
if (val === '') {
return null;
}
const coercedVal = isBsonType(val, 'Long') ? val.toNumber() : Number(val);
const INT32_MAX = 0x7FFFFFFF;
const INT32_MIN = -0x80000000;
if (coercedVal === (coercedVal | 0) &&
coercedVal >= INT32_MIN &&
coercedVal <= INT32_MAX
) {
return coercedVal;
}
assert.ok(false);
};

42
node_modules/mongoose/lib/cast/number.js generated vendored Normal file
View file

@ -0,0 +1,42 @@
'use strict';
const assert = require('assert');
/**
* Given a value, cast it to a number, or throw an `Error` if the value
* cannot be casted. `null` and `undefined` are considered valid.
*
* @param {Any} value
* @return {Number}
* @throws {Error} if `value` is not one of the allowed values
* @api private
*/
module.exports = function castNumber(val) {
if (val == null) {
return val;
}
if (val === '') {
return null;
}
if (typeof val === 'string' || typeof val === 'boolean') {
val = Number(val);
}
assert.ok(!isNaN(val));
if (val instanceof Number) {
return val.valueOf();
}
if (typeof val === 'number') {
return val;
}
if (!Array.isArray(val) && typeof val.valueOf === 'function') {
return Number(val.valueOf());
}
if (val.toString && !Array.isArray(val) && val.toString() == Number(val)) {
return Number(val);
}
assert.ok(false);
};

29
node_modules/mongoose/lib/cast/objectid.js generated vendored Normal file
View file

@ -0,0 +1,29 @@
'use strict';
const isBsonType = require('../helpers/isBsonType');
const ObjectId = require('../types/objectid');
module.exports = function castObjectId(value) {
if (value == null) {
return value;
}
if (isBsonType(value, 'ObjectId')) {
return value;
}
if (value._id) {
if (isBsonType(value._id, 'ObjectId')) {
return value._id;
}
if (value._id.toString instanceof Function) {
return new ObjectId(value._id.toString());
}
}
if (value.toString instanceof Function) {
return new ObjectId(value.toString());
}
return new ObjectId(value);
};

37
node_modules/mongoose/lib/cast/string.js generated vendored Normal file
View file

@ -0,0 +1,37 @@
'use strict';
const CastError = require('../error/cast');
/**
* Given a value, cast it to a string, or throw a `CastError` if the value
* cannot be casted. `null` and `undefined` are considered valid.
*
* @param {Any} value
* @param {String} [path] optional the path to set on the CastError
* @return {string|null|undefined}
* @throws {CastError}
* @api private
*/
module.exports = function castString(value, path) {
// If null or undefined
if (value == null) {
return value;
}
// handle documents being passed
if (value._id && typeof value._id === 'string') {
return value._id;
}
// Re: gh-647 and gh-3030, we're ok with casting using `toString()`
// **unless** its the default Object.toString, because "[object Object]"
// doesn't really qualify as useful data
if (value.toString &&
value.toString !== Object.prototype.toString &&
!Array.isArray(value)) {
return value.toString();
}
throw new CastError('string', value, path);
};

78
node_modules/mongoose/lib/cast/uuid.js generated vendored Normal file
View file

@ -0,0 +1,78 @@
'use strict';
const MongooseBuffer = require('../types/buffer');
const UUID_FORMAT = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i;
const Binary = MongooseBuffer.Binary;
module.exports = function castUUID(value) {
if (value == null) {
return value;
}
function newBuffer(initbuff) {
const buff = new MongooseBuffer(initbuff);
buff._subtype = 4;
return buff;
}
if (typeof value === 'string') {
if (UUID_FORMAT.test(value)) {
return stringToBinary(value);
} else {
throw new Error(`"${value}" is not a valid UUID string`);
}
}
if (Buffer.isBuffer(value)) {
return newBuffer(value);
}
if (value instanceof Binary) {
return newBuffer(value.value(true));
}
// Re: gh-647 and gh-3030, we're ok with casting using `toString()`
// **unless** its the default Object.toString, because "[object Object]"
// doesn't really qualify as useful data
if (value.toString && value.toString !== Object.prototype.toString) {
if (UUID_FORMAT.test(value.toString())) {
return stringToBinary(value.toString());
}
}
throw new Error(`"${value}" cannot be casted to a UUID`);
};
module.exports.UUID_FORMAT = UUID_FORMAT;
/**
* Helper function to convert the input hex-string to a buffer
* @param {String} hex The hex string to convert
* @returns {Buffer} The hex as buffer
* @api private
*/
function hex2buffer(hex) {
// use buffer built-in function to convert from hex-string to buffer
const buff = hex != null && Buffer.from(hex, 'hex');
return buff;
}
/**
* Convert a String to Binary
* @param {String} uuidStr The value to process
* @returns {MongooseBuffer} The binary to store
* @api private
*/
function stringToBinary(uuidStr) {
// Protect against undefined & throwing err
if (typeof uuidStr !== 'string') uuidStr = '';
const hex = uuidStr.replace(/[{}-]/g, ''); // remove extra characters
const bytes = hex2buffer(hex);
const buff = new MongooseBuffer(bytes);
buff._subtype = 4;
return buff;
}