First Commit
This commit is contained in:
commit
601e886c14
2123 files changed
+334815
No files matched your search
+30
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('../utils');
|
||||
|
||||
class PopulateOptions {
|
||||
constructor(obj) {
|
||||
this._docs = {};
|
||||
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
obj = utils.clone(obj);
|
||||
Object.assign(this, obj);
|
||||
if (typeof obj.subPopulate === 'object') {
|
||||
this.populate = obj.subPopulate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The connection used to look up models by name. If not specified, Mongoose
|
||||
* will default to using the connection associated with the model in
|
||||
* `PopulateOptions#model`.
|
||||
*
|
||||
* @memberOf PopulateOptions
|
||||
* @property {Connection} connection
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = PopulateOptions;
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
const SchemaTypeOptions = require('./SchemaTypeOptions');
|
||||
|
||||
/**
|
||||
* The options defined on an Array schematype.
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* const schema = new Schema({ tags: [String] });
|
||||
* schema.path('tags').options; // SchemaArrayOptions instance
|
||||
*
|
||||
* @api public
|
||||
* @inherits SchemaTypeOptions
|
||||
* @constructor SchemaArrayOptions
|
||||
*/
|
||||
|
||||
class SchemaArrayOptions extends SchemaTypeOptions {}
|
||||
|
||||
const opts = {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* If this is an array of strings, an array of allowed values for this path.
|
||||
* Throws an error if this array isn't an array of strings.
|
||||
*
|
||||
* @api public
|
||||
* @property enum
|
||||
* @memberOf SchemaArrayOptions
|
||||
* @type Array
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaArrayOptions.prototype, 'enum', opts);
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = SchemaArrayOptions;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const SchemaTypeOptions = require('./SchemaTypeOptions');
|
||||
|
||||
/**
|
||||
* The options defined on a Buffer schematype.
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* const schema = new Schema({ bitmap: Buffer });
|
||||
* schema.path('bitmap').options; // SchemaBufferOptions instance
|
||||
*
|
||||
* @api public
|
||||
* @inherits SchemaTypeOptions
|
||||
* @constructor SchemaBufferOptions
|
||||
*/
|
||||
|
||||
class SchemaBufferOptions extends SchemaTypeOptions {}
|
||||
|
||||
const opts = {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the default subtype for this buffer.
|
||||
*
|
||||
* @api public
|
||||
* @property subtype
|
||||
* @memberOf SchemaBufferOptions
|
||||
* @type Number
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaBufferOptions.prototype, 'subtype', opts);
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = SchemaBufferOptions;
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
const SchemaTypeOptions = require('./SchemaTypeOptions');
|
||||
|
||||
/**
|
||||
* The options defined on a Date schematype.
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* const schema = new Schema({ startedAt: Date });
|
||||
* schema.path('startedAt').options; // SchemaDateOptions instance
|
||||
*
|
||||
* @api public
|
||||
* @inherits SchemaTypeOptions
|
||||
* @constructor SchemaDateOptions
|
||||
*/
|
||||
|
||||
class SchemaDateOptions extends SchemaTypeOptions {}
|
||||
|
||||
const opts = {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* If set, Mongoose adds a validator that checks that this path is after the
|
||||
* given `min`.
|
||||
*
|
||||
* @api public
|
||||
* @property min
|
||||
* @memberOf SchemaDateOptions
|
||||
* @type Date
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaDateOptions.prototype, 'min', opts);
|
||||
|
||||
/**
|
||||
* If set, Mongoose adds a validator that checks that this path is before the
|
||||
* given `max`.
|
||||
*
|
||||
* @api public
|
||||
* @property max
|
||||
* @memberOf SchemaDateOptions
|
||||
* @type Date
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaDateOptions.prototype, 'max', opts);
|
||||
|
||||
/**
|
||||
* If set, Mongoose creates a TTL index on this path.
|
||||
*
|
||||
* @api public
|
||||
* @property expires
|
||||
* @memberOf SchemaDateOptions
|
||||
* @type Date
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaDateOptions.prototype, 'expires', opts);
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = SchemaDateOptions;
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
const SchemaTypeOptions = require('./SchemaTypeOptions');
|
||||
|
||||
/**
|
||||
* The options defined on a Number schematype.
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* const schema = new Schema({ count: Number });
|
||||
* schema.path('count').options; // SchemaNumberOptions instance
|
||||
*
|
||||
* @api public
|
||||
* @inherits SchemaTypeOptions
|
||||
* @constructor SchemaNumberOptions
|
||||
*/
|
||||
|
||||
class SchemaNumberOptions extends SchemaTypeOptions {}
|
||||
|
||||
const opts = {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* If set, Mongoose adds a validator that checks that this path is at least the
|
||||
* given `min`.
|
||||
*
|
||||
* @api public
|
||||
* @property min
|
||||
* @memberOf SchemaNumberOptions
|
||||
* @type Number
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaNumberOptions.prototype, 'min', opts);
|
||||
|
||||
/**
|
||||
* If set, Mongoose adds a validator that checks that this path is less than the
|
||||
* given `max`.
|
||||
*
|
||||
* @api public
|
||||
* @property max
|
||||
* @memberOf SchemaNumberOptions
|
||||
* @type Number
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaNumberOptions.prototype, 'max', opts);
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = SchemaNumberOptions;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const SchemaTypeOptions = require('./SchemaTypeOptions');
|
||||
|
||||
/**
|
||||
* The options defined on an ObjectId schematype.
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* const schema = new Schema({ testId: mongoose.ObjectId });
|
||||
* schema.path('testId').options; // SchemaObjectIdOptions instance
|
||||
*
|
||||
* @api public
|
||||
* @inherits SchemaTypeOptions
|
||||
* @constructor SchemaObjectIdOptions
|
||||
*/
|
||||
|
||||
class SchemaObjectIdOptions extends SchemaTypeOptions {}
|
||||
|
||||
const opts = {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* If truthy, uses Mongoose's default built-in ObjectId path.
|
||||
*
|
||||
* @api public
|
||||
* @property auto
|
||||
* @memberOf SchemaObjectIdOptions
|
||||
* @type Boolean
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaObjectIdOptions.prototype, 'auto', opts);
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = SchemaObjectIdOptions;
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
const SchemaTypeOptions = require('./SchemaTypeOptions');
|
||||
|
||||
/**
|
||||
* The options defined on a string schematype.
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* const schema = new Schema({ name: String });
|
||||
* schema.path('name').options; // SchemaStringOptions instance
|
||||
*
|
||||
* @api public
|
||||
* @inherits SchemaTypeOptions
|
||||
* @constructor SchemaStringOptions
|
||||
*/
|
||||
|
||||
class SchemaStringOptions extends SchemaTypeOptions {}
|
||||
|
||||
const opts = {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* Array of allowed values for this path
|
||||
*
|
||||
* @api public
|
||||
* @property enum
|
||||
* @memberOf SchemaStringOptions
|
||||
* @type Array
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaStringOptions.prototype, 'enum', opts);
|
||||
|
||||
/**
|
||||
* Attach a validator that succeeds if the data string matches the given regular
|
||||
* expression, and fails otherwise.
|
||||
*
|
||||
* @api public
|
||||
* @property match
|
||||
* @memberOf SchemaStringOptions
|
||||
* @type RegExp
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaStringOptions.prototype, 'match', opts);
|
||||
|
||||
/**
|
||||
* If truthy, Mongoose will add a custom setter that lowercases this string
|
||||
* using JavaScript's built-in `String#toLowerCase()`.
|
||||
*
|
||||
* @api public
|
||||
* @property lowercase
|
||||
* @memberOf SchemaStringOptions
|
||||
* @type Boolean
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaStringOptions.prototype, 'lowercase', opts);
|
||||
|
||||
/**
|
||||
* If truthy, Mongoose will add a custom setter that removes leading and trailing
|
||||
* whitespace using JavaScript's built-in `String#trim()`.
|
||||
*
|
||||
* @api public
|
||||
* @property trim
|
||||
* @memberOf SchemaStringOptions
|
||||
* @type Boolean
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaStringOptions.prototype, 'trim', opts);
|
||||
|
||||
/**
|
||||
* If truthy, Mongoose will add a custom setter that uppercases this string
|
||||
* using JavaScript's built-in `String#toUpperCase()`.
|
||||
*
|
||||
* @api public
|
||||
* @property uppercase
|
||||
* @memberOf SchemaStringOptions
|
||||
* @type Boolean
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaStringOptions.prototype, 'uppercase', opts);
|
||||
|
||||
/*!
|
||||
* ignore
|
||||
*/
|
||||
|
||||
module.exports = SchemaStringOptions;
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('../utils');
|
||||
|
||||
/**
|
||||
* The options defined on a schematype.
|
||||
*
|
||||
* ####Example:
|
||||
*
|
||||
* const schema = new Schema({ name: String });
|
||||
* schema.path('name').options instanceof mongoose.SchemaTypeOptions; // true
|
||||
*
|
||||
* @api public
|
||||
* @constructor SchemaTypeOptions
|
||||
*/
|
||||
|
||||
class SchemaTypeOptions {
|
||||
constructor(obj) {
|
||||
if (obj == null) {
|
||||
return this;
|
||||
}
|
||||
Object.assign(this, utils.clone(obj));
|
||||
}
|
||||
}
|
||||
|
||||
const opts = {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: null
|
||||
};
|
||||
|
||||
/**
|
||||
* The type to cast this path to.
|
||||
*
|
||||
* @api public
|
||||
* @property type
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Function|String|Object
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'type', opts);
|
||||
|
||||
/**
|
||||
* Function or object describing how to validate this schematype.
|
||||
*
|
||||
* @api public
|
||||
* @property validate
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Function|Object
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'validate', opts);
|
||||
|
||||
/**
|
||||
* If true, attach a required validator to this path, which ensures this path
|
||||
* path cannot be set to a nullish value. If a function, Mongoose calls the
|
||||
* function and only checks for nullish values if the function returns a truthy value.
|
||||
*
|
||||
* @api public
|
||||
* @property required
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Function|Boolean
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'required', opts);
|
||||
|
||||
/**
|
||||
* The default value for this path. If a function, Mongoose executes the function
|
||||
* and uses the return value as the default.
|
||||
*
|
||||
* @api public
|
||||
* @property default
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Function|Any
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'default', opts);
|
||||
|
||||
/**
|
||||
* The model that `populate()` should use if populating this path.
|
||||
*
|
||||
* @api public
|
||||
* @property ref
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Function|String
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'ref', opts);
|
||||
|
||||
/**
|
||||
* Whether to include or exclude this path by default when loading documents
|
||||
* using `find()`, `findOne()`, etc.
|
||||
*
|
||||
* @api public
|
||||
* @property select
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Boolean|Number
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'select', opts);
|
||||
|
||||
/**
|
||||
* If truthy, Mongoose will build an index on this path when the model is
|
||||
* compiled.
|
||||
*
|
||||
* @api public
|
||||
* @property index
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Boolean|Number|Object
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'index', opts);
|
||||
|
||||
/**
|
||||
* If truthy, Mongoose will build a unique index on this path when the
|
||||
* model is compiled. [The `unique` option is **not** a validator](/docs/validation.html#the-unique-option-is-not-a-validator).
|
||||
*
|
||||
* @api public
|
||||
* @property unique
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Boolean|Number
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'unique', opts);
|
||||
|
||||
/**
|
||||
* If truthy, Mongoose will disallow changes to this path once the document
|
||||
* is saved to the database for the first time. Read more about [immutability in Mongoose here](http://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html).
|
||||
*
|
||||
* @api public
|
||||
* @property immutable
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Function|Boolean
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'immutable', opts);
|
||||
|
||||
/**
|
||||
* If truthy, Mongoose will build a sparse index on this path.
|
||||
*
|
||||
* @api public
|
||||
* @property sparse
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Boolean|Number
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'sparse', opts);
|
||||
|
||||
/**
|
||||
* If truthy, Mongoose will build a text index on this path.
|
||||
*
|
||||
* @api public
|
||||
* @property text
|
||||
* @memberOf SchemaTypeOptions
|
||||
* @type Boolean|Number|Object
|
||||
* @instance
|
||||
*/
|
||||
|
||||
Object.defineProperty(SchemaTypeOptions.prototype, 'text', opts);
|
||||
|
||||
module.exports = SchemaTypeOptions;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('../utils');
|
||||
|
||||
class RemoveOptions {
|
||||
constructor(obj) {
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
Object.assign(this, utils.clone(obj));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RemoveOptions;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('../utils');
|
||||
|
||||
class SaveOptions {
|
||||
constructor(obj) {
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
Object.assign(this, utils.clone(obj));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SaveOptions;
|
||||
Reference in new issue
Block a user