Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dox to latest version and fix some documentation issues #12024

Merged
merged 46 commits into from Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
46073dd
chore: add yarn.lock to ignore
hasezoey Jun 30, 2022
f0fa4b5
chore: upgrade "dox" to "0.4.4"
hasezoey Jun 30, 2022
a889e3a
chore: upgrade "dox" to "0.4.5"
hasezoey Jun 30, 2022
5de8b9a
chore(docs/source/api.js): add log of file when "parseComments" errors
hasezoey Jun 30, 2022
aa297ba
style: fix empty "returns" jsdoc for "syncIndexes"
hasezoey Jun 30, 2022
b4c26a4
style: fix empty "returns" jsdoc for "buildBulkWriteOperations"
hasezoey Jun 30, 2022
c42bdba
chore: upgrade "dox" to "0.5.3"
hasezoey Jun 30, 2022
dce32d5
style: properly define Document Arrays in jsdoc
hasezoey Jun 30, 2022
7155089
style: remove function definition from "VirtualType.get" and "Virtual…
hasezoey Jun 30, 2022
c22e7cf
style: add jsdoc tags "memberOf" and "instance" to "Mongoose.prototyp…
hasezoey Jun 30, 2022
97b47c3
style: add jsdoc tag "memberOf" to "Model.prototype.increment"
hasezoey Jun 30, 2022
a6c9834
style: add jsdoc tag "memberOf" to "QueryCursor.prototype.map"
hasezoey Jun 30, 2022
0354bb5
style: change jsdoc tag "memberOf" to point to the correct member for…
hasezoey Jun 30, 2022
48beee1
style: add jsdoc tag "memberOf" to "AggregationCursor.prototype.map"
hasezoey Jun 30, 2022
7646125
style: properly set jsdoc tag "function" for "SchemaType.prototype.ca…
hasezoey Jun 30, 2022
82a8c03
style: remove and add some jsdoc tags for "SchemaType.prototype.castF…
hasezoey Jun 30, 2022
cb8e66a
style: move jsdoc comment to proper function ("DocumentArrayPath.set")
hasezoey Jun 30, 2022
953853f
style: replace all "@param {*}" with "@param {Any}" to match other cases
hasezoey Jun 30, 2022
e57594c
style: remove "- " before description to be more consistent
hasezoey Jun 30, 2022
1719bf6
style: remove extra parameters from "@static"
hasezoey Jun 30, 2022
590f0ff
style: move jsdoc comment to proper function ("SubdocumentPath.set")
hasezoey Jun 30, 2022
dbc078b
chore: upgrade "dox" to "0.8.1"
hasezoey Jun 30, 2022
728d967
chore: upgrade "dox" to "0.9.1"
hasezoey Jun 30, 2022
96e1ffd
chore(docs/source/api): change to use "isFunction" instead of directl…
hasezoey Jun 30, 2022
cfe7248
chore(docs/source/api): use "ctx.constructor" over "data.name" for "f…
hasezoey Jun 30, 2022
39a02a1
chore(docs/source/api): remove console.log of the "ctx"
hasezoey Jun 30, 2022
bb0bf63
Merge branch 'master' into updateDox
Uzlopak Jul 2, 2022
407fe61
style: update "syncIndexes" jsdoc to only have "Promise" as return ty…
hasezoey Jul 2, 2022
831d170
Merge branch 'master' into updateDox
hasezoey Jul 3, 2022
1384f27
chore(docs/source/api): basic handle jsdoc "@instance" tag
hasezoey Jul 3, 2022
a006214
chore(docs/source/api): rename "ctx.static" to "ctx.isStatic"
hasezoey Jul 3, 2022
17c7e63
chore(docs/source/api): move setting of "ctx.string" to after the tag…
hasezoey Jul 3, 2022
73f3400
style: update jsdoc "memberOf" for "MongooseMap.prototype.$isMongoose…
hasezoey Jul 3, 2022
6c0e316
style: set proper jsdoc "memberOf" path for "MongooseBuffer.mixin.*" …
hasezoey Jul 3, 2022
da57bf2
chore(docs/source/api): remove redundant setting of "isFunction" in "…
hasezoey Jul 3, 2022
9f73623
chore(docs/source/api): add more comments explaining what some things do
hasezoey Jul 3, 2022
fcb2bfc
chore(docs/source/api): add "void" to types in return, so it does not…
hasezoey Jul 3, 2022
cf6ad88
chore(docs/source/api): add some jsdoc-typescript types to help remem…
hasezoey Jul 3, 2022
ec947f6
chore(docs/source/api): add handling for "@deprecated" and property
hasezoey Jul 3, 2022
5d80579
style: properly escape "@type" type parameters
hasezoey Jul 4, 2022
906cb4f
style: fix missing next line in jsdoc for "Aggregate.prototype.lookup"
hasezoey Jul 4, 2022
e6776b3
chore(docs/source/api): re-add "null" to types when nullable
hasezoey Jul 4, 2022
a1eade6
style: update "Query.prototype.box" jsdoc to use proper "@param" tags
hasezoey Jul 4, 2022
4c7e85c
chore(docs/source/api): change "return" to overwrite "description" in…
hasezoey Jul 4, 2022
6a10d4f
style: add ":" to all jsdoc headers where missing
hasezoey Jul 4, 2022
1cc2293
Merge branch 'master' into updateDox
vkarpov15 Jul 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -48,4 +48,7 @@ docs/*.html
docs/tutorials/*.html
docs/typescript/*.html
docs/api/*.html
index.html
index.html

# yarn package-lock
yarn.lock
106 changes: 86 additions & 20 deletions docs/source/api.js
Expand Up @@ -50,13 +50,35 @@ const out = module.exports.docs;

const combinedFiles = [];
for (const file of files) {
const comments = dox.parseComments(fs.readFileSync(`./${file}`, 'utf8'), { raw: true });
comments.file = file;
combinedFiles.push(comments);
try {
const comments = dox.parseComments(fs.readFileSync(`./${file}`, 'utf8'), { raw: true });
comments.file = file;
combinedFiles.push(comments);
} catch (err) {
// show log of which file has thrown a error for easier debugging
console.error("Error while trying to parseComments for ", file);
throw err;
}
}

parse();

/**
* @typedef {Object} PropContext
* @property {boolean} [isStatic] Defines wheter the current property is a static property (not mutually exlusive with "isInstance")
* @property {boolean} [isInstance] Defines wheter the current property is a instance property (not mutually exlusive with "isStatic")
* @property {boolean} [isFunction] Defines wheter the current property is meant to be a function
* @property {string} [constructor] Defines the Constructor (or rather path) the current property is on
* @property {boolean} [constructorWasUndefined] Defined wheter the "constructor" property was defined by "dox", but was set to "undefined"
* @property {string} [type] Defines the type the property is meant to be
* @property {string} [name] Defines the current Properties name
* @property {Object} [return] The full object for a "@return" jsdoc tag
* @property {string} [string] Defines the full string the property will be listed as
* @property {string} [anchorId] Defines the Anchor ID to be used for linking
* @property {string} [description] Defines the Description the property will be listed with
* @property {string} [deprecated] Defines wheter the current Property is signaled as deprecated
*/

function parse() {
for (const props of combinedFiles) {
let name = props.file.
Expand Down Expand Up @@ -88,43 +110,67 @@ function parse() {
if (prop.ignore || prop.isPrivate) {
continue;
}


/** @type {PropContext} */
const ctx = prop.ctx || {};

// somehow in "dox", it is named "receiver" sometimes, not "constructor"
// this is used as a fall-back if the handling below does not overwrite it
if ("receiver" in ctx) {
ctx.constructor = ctx.receiver;
delete ctx.receiver;
}

// in some cases "dox" has "ctx.constructor" defined but set to "undefined", which will later be used for setting "ctx.string"
if ("constructor" in ctx && ctx.constructor === undefined) {
ctx.constructorWasUndefined = true;
}

for (const tag of prop.tags) {
switch (tag.type) {
case 'receiver':
ctx.constructor = tag.string;
break;
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*/, '');
}
ctx.name = str;
ctx.string = `${ctx.constructor}.prototype.${ctx.name}`;
break;
case 'type':
ctx.type = Array.isArray(tag.types) ? tag.types.join('|') : tag.types;
break;
case 'static':
ctx.type = 'property';
ctx.static = true;
ctx.name = tag.string;
ctx.string = `${data.name}.${ctx.name}`;
ctx.isStatic = true;
// dont take "string" as "name" from here, because jsdoc definitions of "static" do not have parameters, also its defined elsewhere anyway
// ctx.name = tag.string;
break;
case 'function':
ctx.type = 'function';
ctx.static = true;
ctx.isStatic = true;
ctx.name = tag.string;
ctx.string = `${data.name}.${ctx.name}()`;
// extra parameter to make function definitions independant of where "@function" is defined
// like "@static" could have overwritten "ctx.string" again if defined after "@function"
ctx.isFunction = true;
break;
case 'return':
tag.return = tag.description ?
md.parse(tag.description).replace(/^<p>/, '').replace(/<\/p>$/, '') :
'';

// dox does not add "void" / "undefined" to types, so in the documentation it would result in a empty "«»"
if (tag.string.includes('void') || tag.string.includes('undefined')) {
tag.types.push("void");
}

ctx.return = tag;
break;
case 'inherits':
Expand All @@ -147,26 +193,49 @@ function parse() {
case 'method':
ctx.type = 'method';
ctx.name = tag.string;
ctx.string = `${ctx.constructor}.prototype.${ctx.name}()`;
ctx.isFunction = true;
break;
case 'memberOf':
ctx.constructor = tag.parent;
ctx.string = `${ctx.constructor}.prototype.${ctx.name}`;
if (ctx.type === 'method') {
ctx.string += '()';
}
break;
case 'constructor':
ctx.string = tag.string + '()';
ctx.string = tag.string;
ctx.name = tag.string;
ctx.isFunction = true;
break;
case 'instance':
ctx.isInstance = true;
break;
case 'deprecated':
ctx.deprecated = true;
break;
Comment on lines +213 to +215
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have now included basic handling for @deprecated tag, but i am not sure where or in what style it should appear in the documentation

}
}

if (ctx.isInstance && ctx.isStatic) {
console.warn(`Property "${ctx.name}" in "${ctx.constructor}" has both instance and static JSDOC markings (most likely both @instance and @static)! (File: "${props.file}")`);
}

// the following if-else-if statement is in this order, because there are more "instance" methods thans static
// the following condition will be true if "isInstance = true" or if "isInstance = false && isStatic = false" AND "ctx.string" are empty or not defined
// if "isStatic" and "isInstance" are falsy and "ctx.string" is not falsy, then rely on the "ctx.string" set by "dox"
if (ctx.isInstance || (!ctx.isStatic && !ctx.isInstance && (!ctx.string || ctx.constructorWasUndefined))) {
ctx.string = `${ctx.constructor}.prototype.${ctx.name}`;
} else if (ctx.isStatic) {
ctx.string = `${ctx.constructor}.${ctx.name}`;
}

// add "()" to the end of the string if function
if ((ctx.isFunction || ctx.type === "method") && !ctx.string.endsWith("()")) {
ctx.string = ctx.string + "()";
}

// fixing up "something.prototypemissingdot" to "something.prototype.missingdot"
if (/\.prototype[^.]/.test(ctx.string)) {
ctx.string = `${ctx.constructor}.prototype.${ctx.name}`;
}
hasezoey marked this conversation as resolved.
Show resolved Hide resolved

// Backwards compat
// Backwards compat anchors
if (typeof ctx.constructor === 'string') {
ctx.anchorId = `${ctx.constructor.toLowerCase()}_${ctx.constructor}-${ctx.name}`;
} else if (typeof ctx.receiver === 'string') {
Expand All @@ -178,9 +247,6 @@ function parse() {
ctx.description = prop.description.full.
replace(/<br \/>/ig, ' ').
replace(/&gt;/ig, '>');
if (ctx.description.includes('function capitalize')) {
console.log('\n\n-------\n\n', ctx);
}
ctx.description = md.parse(ctx.description);

data.props.push(ctx);
Expand Down
2 changes: 1 addition & 1 deletion lib/connection.js
Expand Up @@ -1452,7 +1452,7 @@ Connection.prototype.setClient = function setClient(client) {
*
* @param {Object} options
* @param {Boolean} options.continueOnError `false` by default. If set to `true`, mongoose will not throw an error if one model syncing failed, and will return an object where the keys are the names of the models, and the values are the results/errors for each model.
* @returns
* @return {Promise} Returns a Promise, when the Promise resolves the value is a list of the dropped indexes.
*/
Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
const result = {};
Expand Down
1 change: 1 addition & 0 deletions lib/cursor/AggregationCursor.js
Expand Up @@ -132,6 +132,7 @@ if (Symbol.asyncIterator != null) {
*
* @param {Function} fn
* @return {AggregationCursor}
* @memberOf AggregationCursor
* @api public
* @method map
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/cursor/QueryCursor.js
Expand Up @@ -137,6 +137,7 @@ QueryCursor.prototype._read = function() {
*
* @param {Function} fn
* @return {QueryCursor}
* @memberOf QueryCursor
* @api public
* @method map
*/
Expand Down Expand Up @@ -320,7 +321,7 @@ QueryCursor.prototype._transformForAsyncIterator = function() {
* support async iterators.
*
* @method Symbol.asyncIterator
* @memberOf Query
* @memberOf QueryCursor
* @instance
* @api public
*/
Expand Down
24 changes: 12 additions & 12 deletions lib/error/index.js
Expand Up @@ -56,7 +56,7 @@ module.exports = exports = MongooseError;
* @see Error.messages #error_messages_MongooseError-messages
* @api public
* @memberOf Error
* @static messages
* @static
*/

MongooseError.messages = require('./messages');
Expand All @@ -73,7 +73,7 @@ MongooseError.Messages = MongooseError.messages;
*
* @api public
* @memberOf Error
* @static DocumentNotFoundError
* @static
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
*/

MongooseError.DocumentNotFoundError = require('./notFound');
Expand All @@ -84,7 +84,7 @@ MongooseError.DocumentNotFoundError = require('./notFound');
*
* @api public
* @memberOf Error
* @static CastError
* @static
*/

MongooseError.CastError = require('./cast');
Expand All @@ -96,7 +96,7 @@ MongooseError.CastError = require('./cast');
*
* @api public
* @memberOf Error
* @static ValidationError
* @static
*/

MongooseError.ValidationError = require('./validation');
Expand Down Expand Up @@ -131,7 +131,7 @@ MongooseError.ValidationError = require('./validation');
*
* @api public
* @memberOf Error
* @static ValidatorError
* @static
*/

MongooseError.ValidatorError = require('./validator');
Expand All @@ -143,7 +143,7 @@ MongooseError.ValidatorError = require('./validator');
*
* @api public
* @memberOf Error
* @static VersionError
* @static
*/

MongooseError.VersionError = require('./version');
Expand All @@ -155,7 +155,7 @@ MongooseError.VersionError = require('./version');
*
* @api public
* @memberOf Error
* @static ParallelSaveError
* @static
*/

MongooseError.ParallelSaveError = require('./parallelSave');
Expand All @@ -166,7 +166,7 @@ MongooseError.ParallelSaveError = require('./parallelSave');
*
* @api public
* @memberOf Error
* @static OverwriteModelError
* @static
*/

MongooseError.OverwriteModelError = require('./overwriteModel');
Expand All @@ -176,7 +176,7 @@ MongooseError.OverwriteModelError = require('./overwriteModel');
*
* @api public
* @memberOf Error
* @static MissingSchemaError
* @static
*/

MongooseError.MissingSchemaError = require('./missingSchema');
Expand All @@ -187,7 +187,7 @@ MongooseError.MissingSchemaError = require('./missingSchema');
*
* @api public
* @memberOf Error
* @static MongooseServerSelectionError
* @static
*/

MongooseError.MongooseServerSelectionError = require('./serverSelection');
Expand All @@ -198,7 +198,7 @@ MongooseError.MongooseServerSelectionError = require('./serverSelection');
*
* @api public
* @memberOf Error
* @static DivergentArrayError
* @static
*/

MongooseError.DivergentArrayError = require('./divergentArray');
Expand All @@ -210,7 +210,7 @@ MongooseError.DivergentArrayError = require('./divergentArray');
*
* @api public
* @memberOf Error
* @static StrictModeError
* @static
*/

MongooseError.StrictModeError = require('./strict');
2 changes: 1 addition & 1 deletion lib/error/messages.js
Expand Up @@ -16,7 +16,7 @@
*
* Click the "show code" link below to see all defaults.
*
* @static messages
* @static
* @receiver MongooseError
* @api public
*/
Expand Down
8 changes: 4 additions & 4 deletions lib/helpers/query/castUpdate.js
Expand Up @@ -155,12 +155,12 @@ function castPipelineOperator(op, val) {
* according to its schema.
*
* @param {Schema} schema
* @param {Object} obj - part of a query
* @param {String} op - the atomic operator ($pull, $set, etc)
* @param {Object} obj part of a query
* @param {String} op the atomic operator ($pull, $set, etc)
* @param {Object} options
* @param {Boolean|String} [options.strict]
* @param {Query} context
* @param {String} pref - path prefix (internal only)
* @param {String} pref path prefix (internal only)
* @return {Bool} true if this path has keys to update
* @api private
*/
Expand Down Expand Up @@ -451,7 +451,7 @@ const overwriteOps = {
*
* @param {SchemaType} schema
* @param {Object} val
* @param {String} op - the atomic operator ($pull, $set, etc)
* @param {String} op the atomic operator ($pull, $set, etc)
* @param {String} $conditional
* @param {Query} context
* @api private
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Expand Up @@ -761,6 +761,8 @@ Mongoose.prototype.Aggregate = Aggregate;
/**
* The Mongoose Collection constructor
*
* @memberOf Mongoose
* @instance
* @method Collection
* @api public
*/
Expand Down Expand Up @@ -1044,7 +1046,7 @@ Mongoose.prototype.isObjectIdOrHexString = function(v) {
*
* @param {Object} options
* @param {Boolean} options.continueOnError `false` by default. If set to `true`, mongoose will not throw an error if one model syncing failed, and will return an object where the keys are the names of the models, and the values are the results/errors for each model.
* @returns
* @return {Promise} Returns a Promise, when the Promise resolves the value is a list of the dropped indexes.
*/
Mongoose.prototype.syncIndexes = function(options) {
const _mongoose = this instanceof Mongoose ? this : mongoose;
Expand Down