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 45 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
114 changes: 92 additions & 22 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>$/, '') :
tag.description = tag.description ?
md.parse(tag.description).replace(/^<p>/, '').replace(/<\/p>\n?$/, '') :
'';

// 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 @@ -133,6 +179,10 @@ function parse() {
case 'event':
case 'param':
ctx[tag.type] = (ctx[tag.type] || []);
// the following is required, because in newer "dox" version "null" is not included in "types" anymore, but a seperate property
if (tag.nullable) {
tag.types.push('null');
}
if (tag.types) {
tag.types = tag.types.join('|');
}
Expand All @@ -147,26 +197,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 +251,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
5 changes: 3 additions & 2 deletions lib/aggregate.js
Expand Up @@ -481,7 +481,8 @@ Aggregate.prototype.sortByCount = function(arg) {
*
* @see $lookup https://docs.mongodb.org/manual/reference/operator/aggregation/lookup/#pipe._S_lookup
* @param {Object} options to $lookup as described in the above link
* @return {Aggregate}* @api public
* @return {Aggregate}
* @api public
*/

Aggregate.prototype.lookup = function(options) {
Expand Down Expand Up @@ -1051,7 +1052,7 @@ Aggregate.prototype.catch = function(reject) {
* You do not need to call this function explicitly, the JavaScript runtime
* will call it for you.
*
* #### Example
* #### Example:
*
* const agg = Model.aggregate([{ $match: { age: { $gte: 25 } } }]);
* for await (const doc of agg) {
Expand Down
18 changes: 9 additions & 9 deletions lib/connection.js
Expand Up @@ -93,7 +93,7 @@ Connection.prototype.__proto__ = EventEmitter.prototype;
*
* Each state change emits its associated event name.
*
* #### Example
* #### Example:
*
* conn.on('connected', callback);
* conn.on('disconnected', callback);
Expand Down Expand Up @@ -193,7 +193,7 @@ Connection.prototype.collections;
/**
* The name of the database this connection points to.
*
* #### Example
* #### Example:
*
* mongoose.createConnection('mongodb://localhost:27017/mydb').name; // "mydb"
*
Expand All @@ -210,7 +210,7 @@ Connection.prototype.name;
* a map from model names to models. Contains all models that have been
* added to this connection using [`Connection#model()`](/docs/api/connection.html#connection_Connection-model).
*
* #### Example
* #### Example:
*
* const conn = mongoose.createConnection();
* const Test = conn.model('Test', mongoose.Schema({ name: String }));
Expand All @@ -230,7 +230,7 @@ Connection.prototype.models;
* A number identifier for this connection. Used for debugging when
* you have [multiple connections](/docs/connections.html#multiple_connections).
*
* #### Example
* #### Example:
*
* // The default connection has `id = 0`
* mongoose.connection.id; // 0
Expand Down Expand Up @@ -274,7 +274,7 @@ Object.defineProperty(Connection.prototype, 'plugins', {
* The host name portion of the URI. If multiple hosts, such as a replica set,
* this will contain the first host name in the URI
*
* #### Example
* #### Example:
*
* mongoose.createConnection('mongodb://localhost:27017/mydb').host; // "localhost"
*
Expand All @@ -294,7 +294,7 @@ Object.defineProperty(Connection.prototype, 'host', {
* The port portion of the URI. If multiple hosts, such as a replica set,
* this will contain the port from the first host name in the URI.
*
* #### Example
* #### Example:
*
* mongoose.createConnection('mongodb://localhost:27017/mydb').port; // 27017
*
Expand All @@ -313,7 +313,7 @@ Object.defineProperty(Connection.prototype, 'port', {
/**
* The username specified in the URI
*
* #### Example
* #### Example:
*
* mongoose.createConnection('mongodb://val:psw@localhost:27017/mydb').user; // "val"
*
Expand All @@ -332,7 +332,7 @@ Object.defineProperty(Connection.prototype, 'user', {
/**
* The password specified in the URI
*
* #### Example
* #### Example:
*
* mongoose.createConnection('mongodb://val:psw@localhost:27017/mydb').pass; // "psw"
*
Expand Down 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
5 changes: 3 additions & 2 deletions lib/cursor/AggregationCursor.js
Expand Up @@ -107,7 +107,7 @@ if (Symbol.asyncIterator != null) {
* Registers a transform function which subsequently maps documents retrieved
* via the streams interface or `.next()`
*
* #### Example
* #### Example:
*
* // Map documents returned by `data` events
* Thing.
Expand All @@ -132,6 +132,7 @@ if (Symbol.asyncIterator != null) {
*
* @param {Function} fn
* @return {AggregationCursor}
* @memberOf AggregationCursor
* @api public
* @method map
*/
Expand Down Expand Up @@ -226,7 +227,7 @@ AggregationCursor.prototype.eachAsync = function(fn, opts, callback) {
* You do not need to call this function explicitly, the JavaScript runtime
* will call it for you.
*
* #### Example
* #### Example:
*
* // Async iterator without explicitly calling `cursor()`. Mongoose still
* // creates an AggregationCursor instance internally.
Expand Down
9 changes: 5 additions & 4 deletions lib/cursor/QueryCursor.js
Expand Up @@ -112,7 +112,7 @@ QueryCursor.prototype._read = function() {
* Registers a transform function which subsequently maps documents retrieved
* via the streams interface or `.next()`
*
* #### Example
* #### Example:
*
* // Map documents returned by `data` events
* Thing.
Expand All @@ -137,6 +137,7 @@ QueryCursor.prototype._read = function() {
*
* @param {Function} fn
* @return {QueryCursor}
* @memberOf QueryCursor
* @api public
* @method map
*/
Expand Down Expand Up @@ -211,7 +212,7 @@ QueryCursor.prototype.next = function(callback) {
* will wait for the promise to resolve before iterating on to the next one.
* Returns a promise that resolves when done.
*
* #### Example
* #### Example:
*
* // Iterate over documents asynchronously
* Thing.
Expand Down Expand Up @@ -300,7 +301,7 @@ QueryCursor.prototype._transformForAsyncIterator = function() {
* You do not need to call this function explicitly, the JavaScript runtime
* will call it for you.
*
* #### Example
* #### Example:
*
* // Works without using `cursor()`
* for await (const doc of Model.find([{ $sort: { name: 1 } }])) {
Expand All @@ -320,7 +321,7 @@ QueryCursor.prototype._transformForAsyncIterator = function() {
* support async iterators.
*
* @method Symbol.asyncIterator
* @memberOf Query
* @memberOf QueryCursor
* @instance
* @api public
*/
Expand Down