From 11fe348c229b6a263f38def25d7c0efeab5048d2 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Fri, 8 Jul 2022 13:09:46 +0200 Subject: [PATCH 1/4] chore(docs/source/api): change converting types to string to be consistent also properly handle types in case "property" (could not handle arrays or other extra symbols before) --- docs/source/api.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/source/api.js b/docs/source/api.js index 2062ac68c1e..27227f8eeac 100644 --- a/docs/source/api.js +++ b/docs/source/api.js @@ -126,6 +126,11 @@ function parse() { ctx.constructorWasUndefined = true; } + // helper function to keep translating array types to string consistent + function convertTypesToString(types) { + return Array.isArray(types) ? types.join('|') : types + } + for (const tag of prop.tags) { switch (tag.type) { case 'receiver': @@ -134,18 +139,16 @@ function parse() { case 'property': ctx.type = 'property'; - // somewhere since 6.0 the "string" property came back, which was gone with 4.5 - let str = tag.string; - - const match = str.match(/^{\w+}/); - if (match != null) { - ctx.type = match[0].substring(1, match[0].length - 1); - str = str.replace(/^{\w+}\s*/, ''); + // using "name" over "string" because "string" also contains the type and maybe other stuff + ctx.name = tag.name; + // only assign "type" if there are types + if (tag.types.length > 0) { + ctx.type = convertTypesToString(tag.types); } - ctx.name = str; + break; case 'type': - ctx.type = Array.isArray(tag.types) ? tag.types.join('|') : tag.types; + ctx.type = convertTypesToString(tag.types); break; case 'static': ctx.type = 'property'; @@ -184,7 +187,7 @@ function parse() { tag.types.push('null'); } if (tag.types) { - tag.types = tag.types.join('|'); + tag.types = convertTypesToString(tag.types); } ctx[tag.type].push(tag); if (tag.name != null && tag.name.startsWith('[') && tag.name.endsWith(']') && tag.name.includes('.')) { From da504c5034017664c809646dafb3b8aeb0cf90f2 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Fri, 8 Jul 2022 13:11:06 +0200 Subject: [PATCH 2/4] style(schema): move jsdoc to proper place for "Schema.indexTypes" --- lib/schema.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/schema.js b/lib/schema.js index 26144de75a5..4d982e61040 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -1870,6 +1870,8 @@ Schema.prototype.get = function(key) { return this.options[key]; }; +const indexTypes = '2d 2dsphere hashed text'.split(' '); + /** * The allowed index types * @@ -1878,8 +1880,6 @@ Schema.prototype.get = function(key) { * @api public */ -const indexTypes = '2d 2dsphere hashed text'.split(' '); - Object.defineProperty(Schema, 'indexTypes', { get: function() { return indexTypes; From ee825d262710ab9c014bf84379056c5e85b3614f Mon Sep 17 00:00:00 2001 From: hasezoey Date: Fri, 8 Jul 2022 13:23:08 +0200 Subject: [PATCH 3/4] style: replace all "@receiver" with proper jsdoc tags --- lib/error/messages.js | 2 +- lib/model.js | 2 +- lib/query.js | 11 +++++++---- lib/schema.js | 3 ++- lib/schematype.js | 8 ++++---- lib/types/DocumentArray/methods/index.js | 2 +- lib/types/subdocument.js | 2 +- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/error/messages.js b/lib/error/messages.js index 717340acab2..b750d5d5ec2 100644 --- a/lib/error/messages.js +++ b/lib/error/messages.js @@ -17,7 +17,7 @@ * Click the "show code" link below to see all defaults. * * @static - * @receiver MongooseError + * @memberOf MongooseError * @api public */ diff --git a/lib/model.js b/lib/model.js index 26443296ea8..c084f016d49 100644 --- a/lib/model.js +++ b/lib/model.js @@ -1822,7 +1822,7 @@ function _ensureIndexes(model, options, callback) { * Schema the model uses. * * @property schema - * @receiver Model + * @static * @api public * @memberOf Model */ diff --git a/lib/query.js b/lib/query.js index 8a3813955f1..1bfed85a27e 100644 --- a/lib/query.js +++ b/lib/query.js @@ -170,7 +170,7 @@ Query.base = mquery.prototype; * @default true * @property use$geoWithin * @memberOf Query - * @receiver Query + * @static * @api public */ @@ -1847,7 +1847,7 @@ Query.prototype.setUpdate = function(val) { * @method _fieldsForExec * @return {Object} * @api private - * @receiver Query + * @memberOf Query */ Query.prototype._fieldsForExec = function() { @@ -1859,8 +1859,9 @@ Query.prototype._fieldsForExec = function() { * Return an update document with corrected `$set` operations. * * @method _updateForExec + * @return {Object} * @api private - * @receiver Query + * @memberOf Query */ Query.prototype._updateForExec = function() { @@ -1907,10 +1908,12 @@ Query.prototype._updateForExec = function() { /** * Makes sure _path is set. * + * This method is inherited by `mquery` + * * @method _ensurePath * @param {String} method * @api private - * @receiver Query + * @memberOf Query */ /** diff --git a/lib/schema.js b/lib/schema.js index 4d982e61040..96a800aa433 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -1875,7 +1875,8 @@ const indexTypes = '2d 2dsphere hashed text'.split(' '); /** * The allowed index types * - * @receiver Schema + * @property {String[]} indexTypes + * @memberOf Schema * @static * @api public */ diff --git a/lib/schematype.js b/lib/schematype.js index d8a0a4ce37e..832aa15c4aa 100644 --- a/lib/schematype.js +++ b/lib/schematype.js @@ -206,7 +206,7 @@ SchemaType.prototype.splitPath = function() { * @param {Function|false} caster Function that casts arbitrary values to this type, or throws an error if casting failed * @return {Function} * @static - * @receiver SchemaType + * @memberOf SchemaType * @function cast * @api public */ @@ -280,7 +280,7 @@ SchemaType.prototype.cast = function cast() { * @param {Any} value The value of the option you'd like to set. * @return {void} * @static - * @receiver SchemaType + * @memberOf SchemaType * @function set * @api public */ @@ -303,7 +303,7 @@ SchemaType.set = function set(option, value) { * @param {Function} getter * @return {this} * @static - * @receiver SchemaType + * @memberOf SchemaType * @function get * @api public */ @@ -1634,7 +1634,7 @@ SchemaType.prototype._castForQuery = function(val) { * @param {Function} fn * @return {Function} * @static - * @receiver SchemaType + * @memberOf SchemaType * @function checkRequired * @api public */ diff --git a/lib/types/DocumentArray/methods/index.js b/lib/types/DocumentArray/methods/index.js index 879671d803c..66c55678a94 100644 --- a/lib/types/DocumentArray/methods/index.js +++ b/lib/types/DocumentArray/methods/index.js @@ -35,7 +35,7 @@ const methods = { * * @method _cast * @api private - * @receiver MongooseDocumentArray + * @memberOf MongooseDocumentArray */ _cast(value, index) { diff --git a/lib/types/subdocument.js b/lib/types/subdocument.js index 57c675bb485..197f086224c 100644 --- a/lib/types/subdocument.js +++ b/lib/types/subdocument.js @@ -188,7 +188,7 @@ Subdocument.prototype.isModified = function(paths, modifiedPaths) { * @param {String} path the field to mark as valid * @api private * @method $markValid - * @receiver Subdocument + * @memberOf Subdocument */ Subdocument.prototype.$markValid = function(path) { From d4e35220450661f120c25f462ff783a97e322be9 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Fri, 8 Jul 2022 13:26:15 +0200 Subject: [PATCH 4/4] chore(docs/source/api): change case "receiver" to a warning and no-op --- docs/source/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/api.js b/docs/source/api.js index 27227f8eeac..3dd49029fc4 100644 --- a/docs/source/api.js +++ b/docs/source/api.js @@ -134,7 +134,7 @@ function parse() { for (const tag of prop.tags) { switch (tag.type) { case 'receiver': - ctx.constructor = tag.string; + console.warn(`Found "@receiver" tag in ${ctx.constructor} ${ctx.name}`); break; case 'property': ctx.type = 'property';