some progress

This commit is contained in:
Jonas_Jones 2023-03-30 20:40:42 +02:00
parent aea93a5527
commit e3c15bd288
1388 changed files with 306946 additions and 68323 deletions

View file

@ -0,0 +1,28 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
class MissingSchemaError extends MongooseError {
/**
* MissingSchema Error constructor.
*/
constructor() {
super('Schema hasn\'t been registered for document.\n'
+ 'Use mongoose.Document(name, schema)');
}
}
Object.defineProperty(MissingSchemaError.prototype, 'name', {
value: 'MongooseError'
});
/*!
* exports
*/
module.exports = MissingSchemaError;

158
node_modules/mongoose/lib/error/cast.js generated vendored Normal file
View file

@ -0,0 +1,158 @@
'use strict';
/*!
* Module dependencies.
*/
const MongooseError = require('./mongooseError');
const util = require('util');
/**
* Casting Error constructor.
*
* @param {String} type
* @param {String} value
* @inherits MongooseError
* @api private
*/
class CastError extends MongooseError {
constructor(type, value, path, reason, schemaType) {
// If no args, assume we'll `init()` later.
if (arguments.length > 0) {
const stringValue = getStringValue(value);
const valueType = getValueType(value);
const messageFormat = getMessageFormat(schemaType);
const msg = formatMessage(null, type, stringValue, path, messageFormat, valueType, reason);
super(msg);
this.init(type, value, path, reason, schemaType);
} else {
super(formatMessage());
}
}
toJSON() {
return {
stringValue: this.stringValue,
valueType: this.valueType,
kind: this.kind,
value: this.value,
path: this.path,
reason: this.reason,
name: this.name,
message: this.message
};
}
/*!
* ignore
*/
init(type, value, path, reason, schemaType) {
this.stringValue = getStringValue(value);
this.messageFormat = getMessageFormat(schemaType);
this.kind = type;
this.value = value;
this.path = path;
this.reason = reason;
this.valueType = getValueType(value);
}
/**
* ignore
* @param {Readonly<CastError>} other
* @api private
*/
copy(other) {
this.messageFormat = other.messageFormat;
this.stringValue = other.stringValue;
this.kind = other.kind;
this.value = other.value;
this.path = other.path;
this.reason = other.reason;
this.message = other.message;
this.valueType = other.valueType;
}
/*!
* ignore
*/
setModel(model) {
this.model = model;
this.message = formatMessage(model, this.kind, this.stringValue, this.path,
this.messageFormat, this.valueType);
}
}
Object.defineProperty(CastError.prototype, 'name', {
value: 'CastError'
});
function getStringValue(value) {
let stringValue = util.inspect(value);
stringValue = stringValue.replace(/^'|'$/g, '"');
if (!stringValue.startsWith('"')) {
stringValue = '"' + stringValue + '"';
}
return stringValue;
}
function getValueType(value) {
if (value == null) {
return '' + value;
}
const t = typeof value;
if (t !== 'object') {
return t;
}
if (typeof value.constructor !== 'function') {
return t;
}
return value.constructor.name;
}
function getMessageFormat(schemaType) {
const messageFormat = schemaType &&
schemaType.options &&
schemaType.options.cast || null;
if (typeof messageFormat === 'string') {
return messageFormat;
}
}
/*!
* ignore
*/
function formatMessage(model, kind, stringValue, path, messageFormat, valueType, reason) {
if (messageFormat != null) {
let ret = messageFormat.
replace('{KIND}', kind).
replace('{VALUE}', stringValue).
replace('{PATH}', path);
if (model != null) {
ret = ret.replace('{MODEL}', model.modelName);
}
return ret;
} else {
const valueTypeMsg = valueType ? ' (type ' + valueType + ')' : '';
let ret = 'Cast to ' + kind + ' failed for value ' +
stringValue + valueTypeMsg + ' at path "' + path + '"';
if (model != null) {
ret += ' for model "' + model.modelName + '"';
}
if (reason != null &&
typeof reason.constructor === 'function' &&
reason.constructor.name !== 'AssertionError' &&
reason.constructor.name !== 'Error') {
ret += ' because of "' + reason.constructor.name + '"';
}
return ret;
}
}
/*!
* exports
*/
module.exports = CastError;

38
node_modules/mongoose/lib/error/divergentArray.js generated vendored Normal file
View file

@ -0,0 +1,38 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
class DivergentArrayError extends MongooseError {
/**
* DivergentArrayError constructor.
* @param {Array<String>} paths
* @api private
*/
constructor(paths) {
const msg = 'For your own good, using `document.save()` to update an array '
+ 'which was selected using an $elemMatch projection OR '
+ 'populated using skip, limit, query conditions, or exclusion of '
+ 'the _id field when the operation results in a $pop or $set of '
+ 'the entire array is not supported. The following '
+ 'path(s) would have been modified unsafely:\n'
+ ' ' + paths.join('\n ') + '\n'
+ 'Use Model.updateOne() to update these arrays instead.';
// TODO write up a docs page (FAQ) and link to it
super(msg);
}
}
Object.defineProperty(DivergentArrayError.prototype, 'name', {
value: 'DivergentArrayError'
});
/*!
* exports
*/
module.exports = DivergentArrayError;

41
node_modules/mongoose/lib/error/eachAsyncMultiError.js generated vendored Normal file
View file

@ -0,0 +1,41 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
/**
* If `eachAsync()` is called with `continueOnError: true`, there can be
* multiple errors. This error class contains an `errors` property, which
* contains an array of all errors that occurred in `eachAsync()`.
*
* @api private
*/
class EachAsyncMultiError extends MongooseError {
/**
* @param {String} connectionString
*/
constructor(errors) {
let preview = errors.map(e => e.message).join(', ');
if (preview.length > 50) {
preview = preview.slice(0, 50) + '...';
}
super(`eachAsync() finished with ${errors.length} errors: ${preview}`);
this.errors = errors;
}
}
Object.defineProperty(EachAsyncMultiError.prototype, 'name', {
value: 'EachAsyncMultiError'
});
/*!
* exports
*/
module.exports = EachAsyncMultiError;

227
node_modules/mongoose/lib/error/index.js generated vendored Normal file
View file

@ -0,0 +1,227 @@
'use strict';
/**
* MongooseError constructor. MongooseError is the base class for all
* Mongoose-specific errors.
*
* #### Example:
*
* const Model = mongoose.model('Test', new mongoose.Schema({ answer: Number }));
* const doc = new Model({ answer: 'not a number' });
* const err = doc.validateSync();
*
* err instanceof mongoose.Error.ValidationError; // true
*
* @constructor Error
* @param {String} msg Error message
* @inherits Error https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error
*/
const MongooseError = require('./mongooseError');
/**
* The name of the error. The name uniquely identifies this Mongoose error. The
* possible values are:
*
* - `MongooseError`: general Mongoose error
* - `CastError`: Mongoose could not convert a value to the type defined in the schema path. May be in a `ValidationError` class' `errors` property.
* - `DivergentArrayError`: You attempted to `save()` an array that was modified after you loaded it with a `$elemMatch` or similar projection
* - `MissingSchemaError`: You tried to access a model with [`mongoose.model()`](mongoose.html#mongoose_Mongoose-model) that was not defined
* - `DocumentNotFoundError`: The document you tried to [`save()`](document.html#document_Document-save) was not found
* - `ValidatorError`: error from an individual schema path's validator
* - `ValidationError`: error returned from [`validate()`](document.html#document_Document-validate) or [`validateSync()`](document.html#document_Document-validateSync). Contains zero or more `ValidatorError` instances in `.errors` property.
* - `MissingSchemaError`: You called `mongoose.Document()` without a schema
* - `ObjectExpectedError`: Thrown when you set a nested path to a non-object value with [strict mode set](/docs/guide.html#strict).
* - `ObjectParameterError`: Thrown when you pass a non-object value to a function which expects an object as a paramter
* - `OverwriteModelError`: Thrown when you call [`mongoose.model()`](mongoose.html#mongoose_Mongoose-model) to re-define a model that was already defined.
* - `ParallelSaveError`: Thrown when you call [`save()`](model.html#model_Model-save) on a document when the same document instance is already saving.
* - `StrictModeError`: Thrown when you set a path that isn't the schema and [strict mode](/docs/guide.html#strict) is set to `throw`.
* - `VersionError`: Thrown when the [document is out of sync](/docs/guide.html#versionKey)
*
* @api public
* @property {String} name
* @memberOf Error
* @instance
*/
/*!
* Module exports.
*/
module.exports = exports = MongooseError;
/**
* The default built-in validator error messages.
*
* @see Error.messages #error_messages_MongooseError-messages
* @api public
* @memberOf Error
* @static
*/
MongooseError.messages = require('./messages');
// backward compat
MongooseError.Messages = MongooseError.messages;
/**
* An instance of this error class will be returned when `save()` fails
* because the underlying
* document was not found. The constructor takes one parameter, the
* conditions that mongoose passed to `updateOne()` when trying to update
* the document.
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.DocumentNotFoundError = require('./notFound');
/**
* An instance of this error class will be returned when mongoose failed to
* cast a value.
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.CastError = require('./cast');
/**
* An instance of this error class will be returned when [validation](/docs/validation.html) failed.
* The `errors` property contains an object whose keys are the paths that failed and whose values are
* instances of CastError or ValidationError.
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.ValidationError = require('./validation');
/**
* A `ValidationError` has a hash of `errors` that contain individual
* `ValidatorError` instances.
*
* #### Example:
*
* const schema = Schema({ name: { type: String, required: true } });
* const Model = mongoose.model('Test', schema);
* const doc = new Model({});
*
* // Top-level error is a ValidationError, **not** a ValidatorError
* const err = doc.validateSync();
* err instanceof mongoose.Error.ValidationError; // true
*
* // A ValidationError `err` has 0 or more ValidatorErrors keyed by the
* // path in the `err.errors` property.
* err.errors['name'] instanceof mongoose.Error.ValidatorError;
*
* err.errors['name'].kind; // 'required'
* err.errors['name'].path; // 'name'
* err.errors['name'].value; // undefined
*
* Instances of `ValidatorError` have the following properties:
*
* - `kind`: The validator's `type`, like `'required'` or `'regexp'`
* - `path`: The path that failed validation
* - `value`: The value that failed validation
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.ValidatorError = require('./validator');
/**
* An instance of this error class will be returned when you call `save()` after
* the document in the database was changed in a potentially unsafe way. See
* the [`versionKey` option](/docs/guide.html#versionKey) for more information.
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.VersionError = require('./version');
/**
* An instance of this error class will be returned when you call `save()` multiple
* times on the same document in parallel. See the [FAQ](/docs/faq.html) for more
* information.
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.ParallelSaveError = require('./parallelSave');
/**
* Thrown when a model with the given name was already registered on the connection.
* See [the FAQ about `OverwriteModelError`](/docs/faq.html#overwrite-model-error).
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.OverwriteModelError = require('./overwriteModel');
/**
* Thrown when you try to access a model that has not been registered yet
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.MissingSchemaError = require('./missingSchema');
/**
* Thrown when the MongoDB Node driver can't connect to a valid server
* to send an operation to.
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.MongooseServerSelectionError = require('./serverSelection');
/**
* An instance of this error will be returned if you used an array projection
* and then modified the array in an unsafe way.
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.DivergentArrayError = require('./divergentArray');
/**
* Thrown when your try to pass values to model constructor that
* were not specified in schema or change immutable properties when
* `strict` mode is `"throw"`
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.StrictModeError = require('./strict');
/**
* An instance of this error class will be returned when mongoose failed to
* populate with a path that is not existing.
*
* @api public
* @memberOf Error
* @static
*/
MongooseError.StrictPopulateError = require('./strictPopulate');

47
node_modules/mongoose/lib/error/messages.js generated vendored Normal file
View file

@ -0,0 +1,47 @@
/**
* The default built-in validator error messages. These may be customized.
*
* // customize within each schema or globally like so
* const mongoose = require('mongoose');
* mongoose.Error.messages.String.enum = "Your custom message for {PATH}.";
*
* As you might have noticed, error messages support basic templating
*
* - `{PATH}` is replaced with the invalid document path
* - `{VALUE}` is replaced with the invalid value
* - `{TYPE}` is replaced with the validator type such as "regexp", "min", or "user defined"
* - `{MIN}` is replaced with the declared min value for the Number.min validator
* - `{MAX}` is replaced with the declared max value for the Number.max validator
*
* Click the "show code" link below to see all defaults.
*
* @static
* @memberOf MongooseError
* @api public
*/
'use strict';
const msg = module.exports = exports = {};
msg.DocumentNotFoundError = null;
msg.general = {};
msg.general.default = 'Validator failed for path `{PATH}` with value `{VALUE}`';
msg.general.required = 'Path `{PATH}` is required.';
msg.Number = {};
msg.Number.min = 'Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).';
msg.Number.max = 'Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).';
msg.Number.enum = '`{VALUE}` is not a valid enum value for path `{PATH}`.';
msg.Date = {};
msg.Date.min = 'Path `{PATH}` ({VALUE}) is before minimum allowed value ({MIN}).';
msg.Date.max = 'Path `{PATH}` ({VALUE}) is after maximum allowed value ({MAX}).';
msg.String = {};
msg.String.enum = '`{VALUE}` is not a valid enum value for path `{PATH}`.';
msg.String.match = 'Path `{PATH}` is invalid ({VALUE}).';
msg.String.minlength = 'Path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).';
msg.String.maxlength = 'Path `{PATH}` (`{VALUE}`) is longer than the maximum allowed length ({MAXLENGTH}).';

31
node_modules/mongoose/lib/error/missingSchema.js generated vendored Normal file
View file

@ -0,0 +1,31 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
class MissingSchemaError extends MongooseError {
/**
* MissingSchema Error constructor.
* @param {String} name
* @api private
*/
constructor(name) {
const msg = 'Schema hasn\'t been registered for model "' + name + '".\n'
+ 'Use mongoose.model(name, schema)';
super(msg);
}
}
Object.defineProperty(MissingSchemaError.prototype, 'name', {
value: 'MissingSchemaError'
});
/*!
* exports
*/
module.exports = MissingSchemaError;

13
node_modules/mongoose/lib/error/mongooseError.js generated vendored Normal file
View file

@ -0,0 +1,13 @@
'use strict';
/*!
* ignore
*/
class MongooseError extends Error { }
Object.defineProperty(MongooseError.prototype, 'name', {
value: 'MongooseError'
});
module.exports = MongooseError;

45
node_modules/mongoose/lib/error/notFound.js generated vendored Normal file
View file

@ -0,0 +1,45 @@
'use strict';
/*!
* Module dependencies.
*/
const MongooseError = require('./');
const util = require('util');
class DocumentNotFoundError extends MongooseError {
/**
* OverwriteModel Error constructor.
* @api private
*/
constructor(filter, model, numAffected, result) {
let msg;
const messages = MongooseError.messages;
if (messages.DocumentNotFoundError != null) {
msg = typeof messages.DocumentNotFoundError === 'function' ?
messages.DocumentNotFoundError(filter, model) :
messages.DocumentNotFoundError;
} else {
msg = 'No document found for query "' + util.inspect(filter) +
'" on model "' + model + '"';
}
super(msg);
this.result = result;
this.numAffected = numAffected;
this.filter = filter;
// Backwards compat
this.query = filter;
}
}
Object.defineProperty(DocumentNotFoundError.prototype, 'name', {
value: 'DocumentNotFoundError'
});
/*!
* exports
*/
module.exports = DocumentNotFoundError;

30
node_modules/mongoose/lib/error/objectExpected.js generated vendored Normal file
View file

@ -0,0 +1,30 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
class ObjectExpectedError extends MongooseError {
/**
* Strict mode error constructor
*
* @param {string} type
* @param {string} value
* @api private
*/
constructor(path, val) {
const typeDescription = Array.isArray(val) ? 'array' : 'primitive value';
super('Tried to set nested object field `' + path +
`\` to ${typeDescription} \`` + val + '`');
this.path = path;
}
}
Object.defineProperty(ObjectExpectedError.prototype, 'name', {
value: 'ObjectExpectedError'
});
module.exports = ObjectExpectedError;

30
node_modules/mongoose/lib/error/objectParameter.js generated vendored Normal file
View file

@ -0,0 +1,30 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
class ObjectParameterError extends MongooseError {
/**
* Constructor for errors that happen when a parameter that's expected to be
* an object isn't an object
*
* @param {Any} value
* @param {String} paramName
* @param {String} fnName
* @api private
*/
constructor(value, paramName, fnName) {
super('Parameter "' + paramName + '" to ' + fnName +
'() must be an object, got ' + value.toString());
}
}
Object.defineProperty(ObjectParameterError.prototype, 'name', {
value: 'ObjectParameterError'
});
module.exports = ObjectParameterError;

30
node_modules/mongoose/lib/error/overwriteModel.js generated vendored Normal file
View file

@ -0,0 +1,30 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
class OverwriteModelError extends MongooseError {
/**
* OverwriteModel Error constructor.
* @param {String} name
* @api private
*/
constructor(name) {
super('Cannot overwrite `' + name + '` model once compiled.');
}
}
Object.defineProperty(OverwriteModelError.prototype, 'name', {
value: 'OverwriteModelError'
});
/*!
* exports
*/
module.exports = OverwriteModelError;

30
node_modules/mongoose/lib/error/parallelSave.js generated vendored Normal file
View file

@ -0,0 +1,30 @@
'use strict';
/*!
* Module dependencies.
*/
const MongooseError = require('./');
class ParallelSaveError extends MongooseError {
/**
* ParallelSave Error constructor.
*
* @param {Document} doc
* @api private
*/
constructor(doc) {
const msg = 'Can\'t save() the same doc multiple times in parallel. Document: ';
super(msg + doc._id);
}
}
Object.defineProperty(ParallelSaveError.prototype, 'name', {
value: 'ParallelSaveError'
});
/*!
* exports
*/
module.exports = ParallelSaveError;

31
node_modules/mongoose/lib/error/parallelValidate.js generated vendored Normal file
View file

@ -0,0 +1,31 @@
'use strict';
/*!
* Module dependencies.
*/
const MongooseError = require('./mongooseError');
class ParallelValidateError extends MongooseError {
/**
* ParallelValidate Error constructor.
*
* @param {Document} doc
* @api private
*/
constructor(doc) {
const msg = 'Can\'t validate() the same doc multiple times in parallel. Document: ';
super(msg + doc._id);
}
}
Object.defineProperty(ParallelValidateError.prototype, 'name', {
value: 'ParallelValidateError'
});
/*!
* exports
*/
module.exports = ParallelValidateError;

61
node_modules/mongoose/lib/error/serverSelection.js generated vendored Normal file
View file

@ -0,0 +1,61 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./mongooseError');
const allServersUnknown = require('../helpers/topology/allServersUnknown');
const isAtlas = require('../helpers/topology/isAtlas');
const isSSLError = require('../helpers/topology/isSSLError');
/*!
* ignore
*/
const atlasMessage = 'Could not connect to any servers in your MongoDB Atlas cluster. ' +
'One common reason is that you\'re trying to access the database from ' +
'an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas ' +
'cluster\'s IP whitelist: https://www.mongodb.com/docs/atlas/security-whitelist/';
const sslMessage = 'Mongoose is connecting with SSL enabled, but the server is ' +
'not accepting SSL connections. Please ensure that the MongoDB server you are ' +
'connecting to is configured to accept SSL connections. Learn more: ' +
'https://mongoosejs.com/docs/tutorials/ssl.html';
class MongooseServerSelectionError extends MongooseError {
/**
* MongooseServerSelectionError constructor
*
* @api private
*/
assimilateError(err) {
const reason = err.reason;
// Special message for a case that is likely due to IP whitelisting issues.
const isAtlasWhitelistError = isAtlas(reason) &&
allServersUnknown(reason) &&
err.message.indexOf('bad auth') === -1 &&
err.message.indexOf('Authentication failed') === -1;
if (isAtlasWhitelistError) {
this.message = atlasMessage;
} else if (isSSLError(reason)) {
this.message = sslMessage;
} else {
this.message = err.message;
}
for (const key in err) {
if (key !== 'name') {
this[key] = err[key];
}
}
return this;
}
}
Object.defineProperty(MongooseServerSelectionError.prototype, 'name', {
value: 'MongooseServerSelectionError'
});
module.exports = MongooseServerSelectionError;

101
node_modules/mongoose/lib/error/setOptionError.js generated vendored Normal file
View file

@ -0,0 +1,101 @@
/*!
* Module requirements
*/
'use strict';
const MongooseError = require('./mongooseError');
const util = require('util');
const combinePathErrors = require('../helpers/error/combinePathErrors');
class SetOptionError extends MongooseError {
/**
* Mongoose.set Error
*
* @api private
* @inherits MongooseError
*/
constructor() {
super('');
this.errors = {};
}
/**
* Console.log helper
*/
toString() {
return combinePathErrors(this);
}
/**
* inspect helper
* @api private
*/
inspect() {
return Object.assign(new Error(this.message), this);
}
/**
* add message
* @param {String} key
* @param {String|Error} error
* @api private
*/
addError(key, error) {
if (error instanceof SetOptionError) {
const { errors } = error;
for (const optionKey of Object.keys(errors)) {
this.addError(optionKey, errors[optionKey]);
}
return;
}
this.errors[key] = error;
this.message = combinePathErrors(this);
}
}
if (util.inspect.custom) {
// Avoid Node deprecation warning DEP0079
SetOptionError.prototype[util.inspect.custom] = SetOptionError.prototype.inspect;
}
/**
* Helper for JSON.stringify
* Ensure `name` and `message` show up in toJSON output re: gh-9847
* @api private
*/
Object.defineProperty(SetOptionError.prototype, 'toJSON', {
enumerable: false,
writable: false,
configurable: true,
value: function() {
return Object.assign({}, this, { name: this.name, message: this.message });
}
});
Object.defineProperty(SetOptionError.prototype, 'name', {
value: 'SetOptionError'
});
class SetOptionInnerError extends MongooseError {
/**
* Error for the "errors" array in "SetOptionError" with consistent message
* @param {String} key
*/
constructor(key) {
super(`"${key}" is not a valid option to set`);
}
}
SetOptionError.SetOptionInnerError = SetOptionInnerError;
/*!
* Module exports
*/
module.exports = SetOptionError;

33
node_modules/mongoose/lib/error/strict.js generated vendored Normal file
View file

@ -0,0 +1,33 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
class StrictModeError extends MongooseError {
/**
* Strict mode error constructor
*
* @param {String} path
* @param {String} [msg]
* @param {Boolean} [immutable]
* @inherits MongooseError
* @api private
*/
constructor(path, msg, immutable) {
msg = msg || 'Field `' + path + '` is not in schema and strict ' +
'mode is set to throw.';
super(msg);
this.isImmutableError = !!immutable;
this.path = path;
}
}
Object.defineProperty(StrictModeError.prototype, 'name', {
value: 'StrictModeError'
});
module.exports = StrictModeError;

29
node_modules/mongoose/lib/error/strictPopulate.js generated vendored Normal file
View file

@ -0,0 +1,29 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
class StrictPopulateError extends MongooseError {
/**
* Strict mode error constructor
*
* @param {String} path
* @param {String} [msg]
* @inherits MongooseError
* @api private
*/
constructor(path, msg) {
msg = msg || 'Cannot populate path `' + path + '` because it is not in your schema. ' + 'Set the `strictPopulate` option to false to override.';
super(msg);
this.path = path;
}
}
Object.defineProperty(StrictPopulateError.prototype, 'name', {
value: 'StrictPopulateError'
});
module.exports = StrictPopulateError;

30
node_modules/mongoose/lib/error/syncIndexes.js generated vendored Normal file
View file

@ -0,0 +1,30 @@
'use strict';
/*!
* Module dependencies.
*/
const MongooseError = require('./mongooseError');
/**
* SyncIndexes Error constructor.
*
* @param {String} message
* @param {String} errorsMap
* @inherits MongooseError
* @api private
*/
class SyncIndexesError extends MongooseError {
constructor(message, errorsMap) {
super(message);
this.errors = errorsMap;
}
}
Object.defineProperty(SyncIndexesError.prototype, 'name', {
value: 'SyncIndexesError'
});
module.exports = SyncIndexesError;

103
node_modules/mongoose/lib/error/validation.js generated vendored Normal file
View file

@ -0,0 +1,103 @@
/*!
* Module requirements
*/
'use strict';
const MongooseError = require('./mongooseError');
const getConstructorName = require('../helpers/getConstructorName');
const util = require('util');
const combinePathErrors = require('../helpers/error/combinePathErrors');
class ValidationError extends MongooseError {
/**
* Document Validation Error
*
* @api private
* @param {Document} [instance]
* @inherits MongooseError
*/
constructor(instance) {
let _message;
if (getConstructorName(instance) === 'model') {
_message = instance.constructor.modelName + ' validation failed';
} else {
_message = 'Validation failed';
}
super(_message);
this.errors = {};
this._message = _message;
if (instance) {
instance.$errors = this.errors;
}
}
/**
* Console.log helper
*/
toString() {
return this.name + ': ' + combinePathErrors(this);
}
/**
* inspect helper
* @api private
*/
inspect() {
return Object.assign(new Error(this.message), this);
}
/**
* add message
* @param {String} path
* @param {String|Error} error
* @api private
*/
addError(path, error) {
if (error instanceof ValidationError) {
const { errors } = error;
for (const errorPath of Object.keys(errors)) {
this.addError(`${path}.${errorPath}`, errors[errorPath]);
}
return;
}
this.errors[path] = error;
this.message = this._message + ': ' + combinePathErrors(this);
}
}
if (util.inspect.custom) {
// Avoid Node deprecation warning DEP0079
ValidationError.prototype[util.inspect.custom] = ValidationError.prototype.inspect;
}
/**
* Helper for JSON.stringify
* Ensure `name` and `message` show up in toJSON output re: gh-9847
* @api private
*/
Object.defineProperty(ValidationError.prototype, 'toJSON', {
enumerable: false,
writable: false,
configurable: true,
value: function() {
return Object.assign({}, this, { name: this.name, message: this.message });
}
});
Object.defineProperty(ValidationError.prototype, 'name', {
value: 'ValidationError'
});
/*!
* Module exports
*/
module.exports = ValidationError;

99
node_modules/mongoose/lib/error/validator.js generated vendored Normal file
View file

@ -0,0 +1,99 @@
/*!
* Module dependencies.
*/
'use strict';
const MongooseError = require('./');
class ValidatorError extends MongooseError {
/**
* Schema validator error
*
* @param {Object} properties
* @param {Document} doc
* @api private
*/
constructor(properties, doc) {
let msg = properties.message;
if (!msg) {
msg = MongooseError.messages.general.default;
}
const message = formatMessage(msg, properties, doc);
super(message);
properties = Object.assign({}, properties, { message: message });
this.properties = properties;
this.kind = properties.type;
this.path = properties.path;
this.value = properties.value;
this.reason = properties.reason;
}
/**
* toString helper
* TODO remove? This defaults to `${this.name}: ${this.message}`
* @api private
*/
toString() {
return this.message;
}
/**
* Ensure `name` and `message` show up in toJSON output re: gh-9296
* @api private
*/
toJSON() {
return Object.assign({ name: this.name, message: this.message }, this);
}
}
Object.defineProperty(ValidatorError.prototype, 'name', {
value: 'ValidatorError'
});
/**
* The object used to define this validator. Not enumerable to hide
* it from `require('util').inspect()` output re: gh-3925
* @api private
*/
Object.defineProperty(ValidatorError.prototype, 'properties', {
enumerable: false,
writable: true,
value: null
});
// Exposed for testing
ValidatorError.prototype.formatMessage = formatMessage;
/**
* Formats error messages
* @api private
*/
function formatMessage(msg, properties, doc) {
if (typeof msg === 'function') {
return msg(properties, doc);
}
const propertyNames = Object.keys(properties);
for (const propertyName of propertyNames) {
if (propertyName === 'message') {
continue;
}
msg = msg.replace('{' + propertyName.toUpperCase() + '}', properties[propertyName]);
}
return msg;
}
/*!
* exports
*/
module.exports = ValidatorError;

36
node_modules/mongoose/lib/error/version.js generated vendored Normal file
View file

@ -0,0 +1,36 @@
'use strict';
/*!
* Module dependencies.
*/
const MongooseError = require('./');
class VersionError extends MongooseError {
/**
* Version Error constructor.
*
* @param {Document} doc
* @param {Number} currentVersion
* @param {Array<String>} modifiedPaths
* @api private
*/
constructor(doc, currentVersion, modifiedPaths) {
const modifiedPathsStr = modifiedPaths.join(', ');
super('No matching document found for id "' + doc._id +
'" version ' + currentVersion + ' modifiedPaths "' + modifiedPathsStr + '"');
this.version = currentVersion;
this.modifiedPaths = modifiedPaths;
}
}
Object.defineProperty(VersionError.prototype, 'name', {
value: 'VersionError'
});
/*!
* exports
*/
module.exports = VersionError;