Skip to content

Commit c82d85a

Browse files
committed
style(schematype): touch-up jsdoc
1 parent b61dfbd commit c82d85a

File tree

1 file changed

+90
-76
lines changed

1 file changed

+90
-76
lines changed

lib/schematype.js

Lines changed: 90 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ SchemaType.prototype.OptionsConstructor = SchemaTypeOptions;
134134
* The path to this SchemaType in a Schema.
135135
*
136136
* #### Example:
137+
*
137138
* const schema = new Schema({ name: String });
138139
* schema.path('name').path; // 'name'
139140
*
@@ -148,6 +149,7 @@ SchemaType.prototype.path;
148149
* The validators that Mongoose should run to validate properties at this SchemaType's path.
149150
*
150151
* #### Example:
152+
*
151153
* const schema = new Schema({ name: { type: String, required: true } });
152154
* schema.path('name').validators.length; // 1, the `required` validator
153155
*
@@ -162,6 +164,7 @@ SchemaType.prototype.validators;
162164
* True if this SchemaType has a required validator. False otherwise.
163165
*
164166
* #### Example:
167+
*
165168
* const schema = new Schema({ name: { type: String, required: true } });
166169
* schema.path('name').isRequired; // true
167170
*
@@ -175,8 +178,11 @@ SchemaType.prototype.validators;
175178

176179
SchemaType.prototype.validators;
177180

178-
/*!
179-
* ignore
181+
/**
182+
* Split the current dottet path into segments
183+
*
184+
* @return {String[]|undefined}
185+
* @api private
180186
*/
181187

182188
SchemaType.prototype.splitPath = function() {
@@ -351,8 +357,8 @@ SchemaType.get = function(getter) {
351357
* const m2 = new M;
352358
* console.log(m2.mixed); // { added: 1 }
353359
*
354-
* @param {Function|any} val the default value
355-
* @return {defaultValue}
360+
* @param {Function|any} val The default value to set
361+
* @return {Any|undefined} Returns the set default value.
356362
* @api public
357363
*/
358364

@@ -414,7 +420,7 @@ SchemaType.prototype.index = function(options) {
414420
*
415421
* #### Example:
416422
*
417-
* const s = new Schema({ name: { type: String, unique: true }});
423+
* const s = new Schema({ name: { type: String, unique: true } });
418424
* s.path('name').index({ unique: true });
419425
*
420426
* _NOTE: violating the constraint returns an `E11000` error from MongoDB when saving, not a Mongoose validation error._
@@ -452,8 +458,9 @@ SchemaType.prototype.unique = function(bool) {
452458
*
453459
* ### Example:
454460
*
455-
* const s = new Schema({name : {type: String, text : true })
456-
* s.path('name').index({text : true});
461+
* const s = new Schema({ name : { type: String, text : true } })
462+
* s.path('name').index({ text : true });
463+
*
457464
* @param {Boolean} bool
458465
* @return {SchemaType} this
459466
* @api public
@@ -606,19 +613,17 @@ SchemaType.prototype.transform = function(fn) {
606613
*
607614
* #### Example:
608615
*
609-
* ```javascript
610-
* function capitalize (val) {
611-
* if (typeof val !== 'string') val = '';
612-
* return val.charAt(0).toUpperCase() + val.substring(1);
613-
* }
616+
* function capitalize (val) {
617+
* if (typeof val !== 'string') val = '';
618+
* return val.charAt(0).toUpperCase() + val.substring(1);
619+
* }
614620
*
615-
* // defining within the schema
616-
* const s = new Schema({ name: { type: String, set: capitalize }});
621+
* // defining within the schema
622+
* const s = new Schema({ name: { type: String, set: capitalize }});
617623
*
618-
* // or with the SchemaType
619-
* const s = new Schema({ name: String })
620-
* s.path('name').set(capitalize);
621-
* ```
624+
* // or with the SchemaType
625+
* const s = new Schema({ name: String })
626+
* s.path('name').set(capitalize);
622627
*
623628
* Setters allow you to transform the data before it gets to the raw mongodb
624629
* document or query.
@@ -630,76 +635,68 @@ SchemaType.prototype.transform = function(fn) {
630635
*
631636
* You can set up email lower case normalization easily via a Mongoose setter.
632637
*
633-
* ```javascript
634-
* function toLower(v) {
635-
* return v.toLowerCase();
636-
* }
638+
* function toLower(v) {
639+
* return v.toLowerCase();
640+
* }
637641
*
638-
* const UserSchema = new Schema({
639-
* email: { type: String, set: toLower }
640-
* });
642+
* const UserSchema = new Schema({
643+
* email: { type: String, set: toLower }
644+
* });
641645
*
642-
* const User = db.model('User', UserSchema);
646+
* const User = db.model('User', UserSchema);
643647
*
644-
* const user = new User({email: 'AVENUE@Q.COM'});
645-
* console.log(user.email); // '[email protected]'
648+
* const user = new User({email: 'AVENUE@Q.COM'});
649+
* console.log(user.email); // '[email protected]'
646650
*
647-
* // or
648-
* const user = new User();
649-
* user.email = '[email protected]';
650-
* console.log(user.email); // '[email protected]'
651-
* User.updateOne({ _id: _id }, { $set: { email: 'AVENUE@Q.COM' } }); // update to '[email protected]'
652-
* ```
651+
* // or
652+
* const user = new User();
653+
* user.email = '[email protected]';
654+
* console.log(user.email); // '[email protected]'
655+
* User.updateOne({ _id: _id }, { $set: { email: 'AVENUE@Q.COM' } }); // update to '[email protected]'
653656
*
654657
* As you can see above, setters allow you to transform the data before it
655658
* stored in MongoDB, or before executing a query.
656659
*
657660
* _NOTE: we could have also just used the built-in `lowercase: true` SchemaType option instead of defining our own function._
658661
*
659-
* ```javascript
660-
* new Schema({ email: { type: String, lowercase: true }})
661-
* ```
662+
* new Schema({ email: { type: String, lowercase: true }})
662663
*
663664
* Setters are also passed a second argument, the schematype on which the setter was defined. This allows for tailored behavior based on options passed in the schema.
664665
*
665-
* ```javascript
666-
* function inspector (val, priorValue, schematype) {
667-
* if (schematype.options.required) {
668-
* return schematype.path + ' is required';
669-
* } else {
670-
* return val;
671-
* }
672-
* }
666+
* function inspector (val, priorValue, schematype) {
667+
* if (schematype.options.required) {
668+
* return schematype.path + ' is required';
669+
* } else {
670+
* return val;
671+
* }
672+
* }
673673
*
674-
* const VirusSchema = new Schema({
675-
* name: { type: String, required: true, set: inspector },
676-
* taxonomy: { type: String, set: inspector }
677-
* })
674+
* const VirusSchema = new Schema({
675+
* name: { type: String, required: true, set: inspector },
676+
* taxonomy: { type: String, set: inspector }
677+
* })
678678
*
679-
* const Virus = db.model('Virus', VirusSchema);
680-
* const v = new Virus({ name: 'Parvoviridae', taxonomy: 'Parvovirinae' });
679+
* const Virus = db.model('Virus', VirusSchema);
680+
* const v = new Virus({ name: 'Parvoviridae', taxonomy: 'Parvovirinae' });
681681
*
682-
* console.log(v.name); // name is required
683-
* console.log(v.taxonomy); // Parvovirinae
684-
* ```
682+
* console.log(v.name); // name is required
683+
* console.log(v.taxonomy); // Parvovirinae
685684
*
686685
* You can also use setters to modify other properties on the document. If
687686
* you're setting a property `name` on a document, the setter will run with
688687
* `this` as the document. Be careful, in mongoose 5 setters will also run
689688
* when querying by `name` with `this` as the query.
690689
*
691-
* ```javascript
692-
* const nameSchema = new Schema({ name: String, keywords: [String] });
693-
* nameSchema.path('name').set(function(v) {
694-
* // Need to check if `this` is a document, because in mongoose 5
695-
* // setters will also run on queries, in which case `this` will be a
696-
* // mongoose query object.
697-
* if (this instanceof Document && v != null) {
698-
* this.keywords = v.split(' ');
699-
* }
700-
* return v;
701-
* });
702-
* ```
690+
* const nameSchema = new Schema({ name: String, keywords: [String] });
691+
* nameSchema.path('name').set(function(v) {
692+
* // Need to check if `this` is a document, because in mongoose 5
693+
* // setters will also run on queries, in which case `this` will be a
694+
* // mongoose query object.
695+
* if (this instanceof Document && v != null) {
696+
* this.keywords = v.split(' ');
697+
* }
698+
* return v;
699+
* });
703700
*
704701
* @param {Function} fn
705702
* @return {SchemaType} this
@@ -1079,6 +1076,7 @@ SchemaType.prototype.required = function(required, message) {
10791076
* looks at to determine the foreign collection it should query.
10801077
*
10811078
* #### Example:
1079+
*
10821080
* const userSchema = new Schema({ name: String });
10831081
* const User = mongoose.model('User', userSchema);
10841082
*
@@ -1108,6 +1106,7 @@ SchemaType.prototype.ref = function(ref) {
11081106
*
11091107
* @param {Object} scope the scope which callback are executed
11101108
* @param {Boolean} init
1109+
* @return {Any} The Stored default value.
11111110
* @api private
11121111
*/
11131112

@@ -1175,6 +1174,7 @@ SchemaType.prototype._castNullish = function _castNullish(v) {
11751174
* @param {Object} value
11761175
* @param {Object} scope
11771176
* @param {Boolean} init
1177+
* @return {Any}
11781178
* @api private
11791179
*/
11801180

@@ -1195,6 +1195,7 @@ SchemaType.prototype.applySetters = function(value, scope, init, priorVal, optio
11951195
*
11961196
* @param {Object} value
11971197
* @param {Object} scope
1198+
* @return {Any}
11981199
* @api private
11991200
*/
12001201

@@ -1239,9 +1240,12 @@ SchemaType.prototype.select = function select(val) {
12391240
/**
12401241
* Performs a validation of `value` using the validators declared for this SchemaType.
12411242
*
1242-
* @param {any} value
1243+
* @param {Any} value
12431244
* @param {Function} callback
12441245
* @param {Object} scope
1246+
* @param {Object} [options]
1247+
* @param {String} [options.path]
1248+
* @return {Any} If no validators, returns the output from calling `fn`, otherwise no return
12451249
* @api public
12461250
*/
12471251

@@ -1352,9 +1356,11 @@ function _validate(ok, validatorProperties) {
13521356
*
13531357
* This method ignores the asynchronous validators.
13541358
*
1355-
* @param {any} value
1359+
* @param {Any} value
13561360
* @param {Object} scope
1357-
* @return {MongooseError|undefined}
1361+
* @param {Object} [options]
1362+
* @param {Object} [options.path]
1363+
* @return {MongooseError|null}
13581364
* @api private
13591365
*/
13601366

@@ -1595,7 +1601,8 @@ SchemaType.prototype.castForQueryWrapper = function(params) {
15951601
* Cast the given value with the given optional query operator.
15961602
*
15971603
* @param {String} [$conditional] query operator, like `$eq` or `$in`
1598-
* @param {any} val
1604+
* @param {Any} val
1605+
* @return {Any}
15991606
* @api private
16001607
*/
16011608

@@ -1612,9 +1619,11 @@ SchemaType.prototype.castForQuery = function($conditional, val) {
16121619
return this._castForQuery(val);
16131620
};
16141621

1615-
/*!
1622+
/**
16161623
* Internal switch for runSetters
16171624
*
1625+
* @param {Any} val
1626+
* @return {Any}
16181627
* @api private
16191628
*/
16201629

@@ -1623,6 +1632,7 @@ SchemaType.prototype._castForQuery = function(val) {
16231632
};
16241633

16251634
/**
1635+
* Set & Get the `checkRequired` function
16261636
* Override the function the required validator uses to check whether a value
16271637
* passes the `required` check. Override this on the individual SchemaType.
16281638
*
@@ -1631,8 +1641,8 @@ SchemaType.prototype._castForQuery = function(val) {
16311641
* // Use this to allow empty strings to pass the `required` validator
16321642
* mongoose.Schema.Types.String.checkRequired(v => typeof v === 'string');
16331643
*
1634-
* @param {Function} fn
1635-
* @return {Function}
1644+
* @param {Function} [fn] If set, will overwrite the current set function
1645+
* @return {Function} The input `fn` or the already set function
16361646
* @static
16371647
* @memberOf SchemaType
16381648
* @function checkRequired
@@ -1650,16 +1660,20 @@ SchemaType.checkRequired = function(fn) {
16501660
/**
16511661
* Default check for if this path satisfies the `required` validator.
16521662
*
1653-
* @param {any} val
1663+
* @param {Any} val
1664+
* @return {Boolean} `true` when the value is not `null`, `false` otherwise
16541665
* @api private
16551666
*/
16561667

16571668
SchemaType.prototype.checkRequired = function(val) {
16581669
return val != null;
16591670
};
16601671

1661-
/*!
1662-
* ignore
1672+
/**
1673+
* Clone the current SchemaType
1674+
*
1675+
* @return {SchemaType} The cloned SchemaType instance
1676+
* @api private
16631677
*/
16641678

16651679
SchemaType.prototype.clone = function() {

0 commit comments

Comments
 (0)