1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 15:05:26 +02:00

fixed jsdocs warning, leaving editor confirmation

This commit is contained in:
nvc8996 2021-07-29 17:36:16 +03:00
parent 1f166c1a3d
commit 86e7293c7a
26 changed files with 94 additions and 78 deletions

View file

@ -13,10 +13,11 @@
"mocha": true "mocha": true
}, },
"rules": { "rules": {
"no-unused-expressions": 0, "no-unused-expressions": 1,
"chai-friendly/no-unused-expressions": 2, "chai-friendly/no-unused-expressions": 2,
"@typescript-eslint/ban-types": 1, "@typescript-eslint/ban-types": 1,
"@typescript-eslint/no-magic-numbers": 0 "@typescript-eslint/no-magic-numbers": 0,
"@typescript-eslint/no-explicit-any": 1
}, },
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"globals": { "globals": {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
import express, { NextFunction, Request, Response } from 'express'; import express, { Request, Response } from 'express';
import path from 'path'; import path from 'path';
import cookieParser from 'cookie-parser'; import cookieParser from 'cookie-parser';
import morgan from 'morgan'; import morgan from 'morgan';
@ -25,7 +25,7 @@ app.use(express.static(path.join(__dirname, '../public')));
app.use('/', routes); app.use('/', routes);
// error handler // error handler
app.use(function (err: HttpException, req: Request, res: Response, next: NextFunction) { app.use(function (err: HttpException, req: Request, res: Response) {
// set locals, only providing error in development // set locals, only providing error in development
res.locals.message = err.message; res.locals.message = err.message;
res.locals.error = req.app.get('env') == 'development' ? err : {}; res.locals.error = req.app.get('env') == 'development' ? err : {};

View file

@ -84,7 +84,7 @@ class Pages {
/** /**
* Create new page model and save it in the database * Create new page model and save it in the database
* *
* @param {PageData} data * @param {PageData} data - info about page
* @returns {Promise<Page>} * @returns {Promise<Page>}
*/ */
public static async insert(data: PageData): Promise<Page> { public static async insert(data: PageData): Promise<Page> {
@ -114,7 +114,7 @@ class Pages {
* Update page with given id in the database * Update page with given id in the database
* *
* @param {string} id - page id * @param {string} id - page id
* @param {PageData} data * @param {PageData} data - info about page
* @returns {Promise<Page>} * @returns {Promise<Page>}
*/ */
public static async update(id: string, data: PageData): Promise<Page> { public static async update(id: string, data: PageData): Promise<Page> {
@ -171,7 +171,7 @@ class Pages {
/** /**
* Check PageData object for required fields * Check PageData object for required fields
* *
* @param {PageData} data * @param {PageData} data - info about page
* @throws {Error} - validation error * @throws {Error} - validation error
*/ */
private static validate(data: PageData): void { private static validate(data: PageData): void {

View file

@ -96,7 +96,7 @@ class PagesOrder {
} }
/** /**
* @param {string[]} unordered * @param {string[]} unordered - list of pages
* @param {string} currentPageId - page's id that changes the order * @param {string} currentPageId - page's id that changes the order
* @param {string} parentPageId - parent page's id that contains both two pages * @param {string} parentPageId - parent page's id that contains both two pages
* @param {string} putAbovePageId - page's id above which we put the target page * @param {string} putAbovePageId - page's id above which we put the target page
@ -111,7 +111,7 @@ class PagesOrder {
} }
/** /**
* @param {string} parentId * @param {string} parentId - identity of parent page
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public static async remove(parentId: string): Promise<void> { public static async remove(parentId: string): Promise<void> {

View file

@ -95,7 +95,7 @@ class Transport {
/** /**
* Map fields of File object to response by provided map object * Map fields of File object to response by provided map object
* *
* @param {File} file * @param {Model} file - file object
* @param {object} map - object that represents how should fields of File object should be mapped to response * @param {object} map - object that represents how should fields of File object should be mapped to response
* *
*/ */

View file

@ -5,8 +5,8 @@ class HttpException extends Error {
public status: number; public status: number;
public message: string; public message: string;
/** /**
* @param status * @param status - status of the exception
* @param message * @param message - message about the exception
*/ */
constructor(status: number, message: string) { constructor(status: number, message: string) {
super(message); super(message);

View file

@ -52,11 +52,16 @@ export default class Writing {
this.editor = editor; this.editor = editor;
}); });
window.onbeforeunload = (e) => {
return '';
}
/** /**
* Activate form elements * Activate form elements
*/ */
this.nodes.saveButton = moduleEl.querySelector('[name="js-submit-save"]'); this.nodes.saveButton = moduleEl.querySelector('[name="js-submit-save"]');
this.nodes.saveButton.addEventListener('click', () => { this.nodes.saveButton.addEventListener('click', () => {
window.onbeforeunload = null;
this.saveButtonClicked(); this.saveButtonClicked();
}); });
@ -69,7 +74,7 @@ export default class Writing {
if (!isUserAgree) { if (!isUserAgree) {
return; return;
} }
window.onbeforeunload = null;
this.removeButtonClicked(); this.removeButtonClicked();
}); });
} }

View file

@ -41,7 +41,7 @@ class Alias {
/** /**
* @class * @class
* *
* @param {AliasData} data * @param {AliasData} data - info about alias
* @param {string} aliasName - alias of entity * @param {string} aliasName - alias of entity
*/ */
constructor(data: AliasData = {}, aliasName = '') { constructor(data: AliasData = {}, aliasName = '') {
@ -125,7 +125,7 @@ class Alias {
/** /**
* Set AliasData object fields to internal model fields * Set AliasData object fields to internal model fields
* *
* @param {AliasData} aliasData * @param {AliasData} aliasData - info about alias
*/ */
public set data(aliasData: AliasData) { public set data(aliasData: AliasData) {
const { id, type, hash, deprecated } = aliasData; const { id, type, hash, deprecated } = aliasData;

View file

@ -12,7 +12,6 @@ const filesDb = database['files'];
* @property {string} mimetype - file MIME type * @property {string} mimetype - file MIME type
* @property {number} size - size of the file in * @property {number} size - size of the file in
*/ */
export interface FileData { export interface FileData {
_id?: string; _id?: string;
name?: string; name?: string;
@ -45,7 +44,7 @@ class File {
/** /**
* @class * @class
* *
* @param {FileData} data * @param {FileData} data - info about file
*/ */
constructor(data: FileData = {}) { constructor(data: FileData = {}) {
if (data === null) { if (data === null) {
@ -85,7 +84,7 @@ class File {
/** /**
* Find all files which match passed query object * Find all files which match passed query object
* *
* @param {object} query * @param {object} query - input query
* @returns {Promise<File[]>} * @returns {Promise<File[]>}
*/ */
public static async getAll(query: object = {}): Promise<File[]> { public static async getAll(query: object = {}): Promise<File[]> {
@ -101,7 +100,7 @@ class File {
/** /**
* Set FileData object fields to internal model fields * Set FileData object fields to internal model fields
* *
* @param {FileData} fileData * @param {FileData} fileData - info about file
*/ */
public set data(fileData: FileData) { public set data(fileData: FileData) {
const { name, filename, path, mimetype, size } = fileData; const { name, filename, path, mimetype, size } = fileData;
@ -171,7 +170,7 @@ class File {
/** /**
* Removes unnecessary public folder prefix * Removes unnecessary public folder prefix
* *
* @param {string} path * @param {string} path - input path to be processed
* @returns {string} * @returns {string}
*/ */
private processPath(path: string): string { private processPath(path: string): string {

View file

@ -40,7 +40,7 @@ class Page {
/** /**
* @class * @class
* *
* @param {PageData} data * @param {PageData} data - page's data
*/ */
constructor(data: PageData = {}) { constructor(data: PageData = {}) {
if (data === null) { if (data === null) {
@ -89,7 +89,7 @@ class Page {
/** /**
* Find all pages which match passed query object * Find all pages which match passed query object
* *
* @param {object} query * @param {object} query - input query
* @returns {Promise<Page[]>} * @returns {Promise<Page[]>}
*/ */
public static async getAll(query: object = {}): Promise<Page[]> { public static async getAll(query: object = {}): Promise<Page[]> {
@ -105,7 +105,7 @@ class Page {
/** /**
* Set PageData object fields to internal model fields * Set PageData object fields to internal model fields
* *
* @param {PageData} pageData * @param {PageData} pageData - page's data
*/ */
public set data(pageData: PageData) { public set data(pageData: PageData) {
const { body, parent, uri } = pageData; const { body, parent, uri } = pageData;
@ -134,7 +134,7 @@ class Page {
/** /**
* Link given page as parent * Link given page as parent
* *
* @param {Page} parentPage * @param {Page} parentPage - the page to be set as parent
*/ */
public set parent(parentPage: Page) { public set parent(parentPage: Page) {
this._parent = parentPage._id; this._parent = parentPage._id;
@ -216,7 +216,7 @@ class Page {
* Find and return available uri * Find and return available uri
* *
* @returns {Promise<string>} * @returns {Promise<string>}
* @param uri * @param uri - input uri to be composed
*/ */
private async composeUri(uri: string): Promise<string> { private async composeUri(uri: string): Promise<string> {
let pageWithSameUriCount = 0; let pageWithSameUriCount = 0;

View file

@ -8,7 +8,6 @@ const db = database['pagesOrder'];
* @property {string} page - page id * @property {string} page - page id
* @property {Array<string>} order - list of ordered pages * @property {Array<string>} order - list of ordered pages
*/ */
export interface PageOrderData { export interface PageOrderData {
_id?: string; _id?: string;
page?: string; page?: string;
@ -30,7 +29,7 @@ class PageOrder {
/** /**
* @class * @class
* *
* @param {PageOrderData} data * @param {PageOrderData} data - info about pageOrder
*/ */
constructor(data: PageOrderData = {}) { constructor(data: PageOrderData = {}) {
if (data === null) { if (data === null) {
@ -67,7 +66,7 @@ class PageOrder {
/** /**
* Find all pages which match passed query object * Find all pages which match passed query object
* *
* @param {object} query * @param {object} query - input query
* @returns {Promise<PageOrder[]>} * @returns {Promise<PageOrder[]>}
*/ */
public static async getAll(query: object = {}): Promise<PageOrder[]> { public static async getAll(query: object = {}): Promise<PageOrder[]> {
@ -83,7 +82,7 @@ class PageOrder {
/** /**
* constructor data setter * constructor data setter
* *
* @param {PageOrderData} pageOrderData * @param {PageOrderData} pageOrderData - info about pageOrder
*/ */
public set data(pageOrderData: PageOrderData) { public set data(pageOrderData: PageOrderData) {
this.page = pageOrderData.page || '0'; this.page = pageOrderData.page || '0';
@ -163,7 +162,7 @@ class PageOrder {
/** /**
* Returns page before passed page with id * Returns page before passed page with id
* *
* @param {string} pageId * @param {string} pageId - identity of page
*/ */
public getPageBefore(pageId: string): string | null { public getPageBefore(pageId: string): string | null {
if (this.order === undefined) { if (this.order === undefined) {
@ -185,7 +184,7 @@ class PageOrder {
/** /**
* Returns page before passed page with id * Returns page before passed page with id
* *
* @param pageId * @param pageId - identity of page
*/ */
public getPageAfter(pageId: string): string | null { public getPageAfter(pageId: string): string | null {
if (this.order === undefined) { if (this.order === undefined) {

View file

@ -18,7 +18,7 @@ class User {
/** /**
* @class * @class
* *
* @param {UserData} userData * @param {UserData} userData - user data for construct new object
*/ */
constructor(userData: UserData) { constructor(userData: UserData) {
this.passHash = userData.passHash; this.passHash = userData.passHash;

View file

@ -107,7 +107,7 @@ router.post('/page/:id', multer.none(), async (req: Request, res: Response) => {
const unOrdered: string[] = []; const unOrdered: string[] = [];
unordered.forEach((item, index) => { unordered.forEach(item => {
if (typeof item === 'string') { if (typeof item === 'string') {
unOrdered.push(item); unOrdered.push(item);
} }
@ -166,7 +166,7 @@ router.delete('/page/:id', async (req: Request, res: Response) => {
/** /**
* remove current page and go deeper to remove children with orders * remove current page and go deeper to remove children with orders
* *
* @param {string} startFrom * @param {string} startFrom - start point to delete
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
const deleteRecursively = async (startFrom: string): Promise<void> => { const deleteRecursively = async (startFrom: string): Promise<void> => {

View file

@ -3,9 +3,9 @@ import { NextFunction, Request, Response } from 'express';
/** /**
* Middleware for checking locals.isAuthorized property, which allows to edit/create pages * Middleware for checking locals.isAuthorized property, which allows to edit/create pages
* *
* @param req * @param req - request object
* @param res * @param res - response object
* @param next * @param next - next function
*/ */
export default function allowEdit(req: Request, res: Response, next: NextFunction): void { export default function allowEdit(req: Request, res: Response, next: NextFunction): void {
if (res.locals.isAuthorized) { if (res.locals.isAuthorized) {

View file

@ -11,8 +11,8 @@ import PageOrder from '../../models/pageOrder';
* @param {string} parentPageId - parent page id * @param {string} parentPageId - parent page id
* @param {Page[]} pages - list of all available pages * @param {Page[]} pages - list of all available pages
* @param {PagesOrder[]} pagesOrder - list of pages order * @param {PagesOrder[]} pagesOrder - list of pages order
* @param {number} level * @param {number} level - max level recursion
* @param {number} currentLevel * @param {number} currentLevel - current level of element
* *
* @returns {Page[]} * @returns {Page[]}
*/ */

View file

@ -9,9 +9,9 @@ dotenv.config();
/** /**
* Middleware for checking jwt token * Middleware for checking jwt token
* *
* @param req * @param req - request object
* @param res * @param res - response object
* @param next * @param next - next function
*/ */
export default async function verifyToken(req: Request, res: Response, next: NextFunction): Promise<void> { export default async function verifyToken(req: Request, res: Response, next: NextFunction): Promise<void> {
const token = req.cookies.authToken; const token = req.cookies.authToken;

View file

@ -3,10 +3,9 @@ import { NextFunction, Request, Response } from 'express';
/** /**
* Helper for making async middlewares for express router * Helper for making async middlewares for express router
* *
* @param fn * @param {Function} fn - input function
* @returns {function(*=, *=, *=)} * @returns {function(*=, *=, *=)}
*/ */
// eslint-disable-next-line @typescript-eslint/ban-types
export default function asyncMiddleware(fn: Function): (...params: any) => void { export default function asyncMiddleware(fn: Function): (...params: any) => void {
return (req: Request, res: Response, next: NextFunction) => { return (req: Request, res: Response, next: NextFunction) => {
Promise.resolve(fn(req, res, next)) Promise.resolve(fn(req, res, next))

View file

@ -5,17 +5,24 @@ import aliases from './aliases';
import pagesOrder from './pagesOrder'; import pagesOrder from './pagesOrder';
import Datastore from 'nedb'; import Datastore from 'nedb';
/**
* @typedef Options - optional params
* @param {boolean} multi - (false) allows to take action to several documents
* @param {boolean} upsert - (false) if true, upsert document with update fields.
* Method will return inserted doc or number of affected docs if doc hasn't been inserted
* @param {boolean} returnUpdatedDocs - (false) if true, returns affected docs
*/
interface Options { interface Options {
multi?: boolean;
upsert?: boolean; upsert?: boolean;
returnUpdatedDocs?: boolean; returnUpdatedDocs?: boolean;
multi?: boolean;
} }
/** /**
* @class Database * @class Database
* @classdesc Simple decorator class to work with nedb datastore * @classdesc Simple decorator class to work with nedb datastore
* *
* @property db - nedb Datastore object * @property {Datastore} db - nedb Datastore object
*/ */
export class Database { export class Database {
private db: Datastore; private db: Datastore;
@ -107,11 +114,7 @@ export class Database {
* *
* @param {Object} query - query object * @param {Object} query - query object
* @param {Object} update - fields to update * @param {Object} update - fields to update
* @param {Object} options * @param {Options} options - optional params
* @param {boolean} options.multi - (false) allows update several documents
* @param {boolean} options.upsert - (false) if true, upsert document with update fields.
* Method will return inserted doc or number of affected docs if doc hasn't been inserted
* @param {boolean} options.returnUpdatedDocs - (false) if true, returns affected docs
* @returns {Promise<number|Object|Object[]|Error>} - number of updated rows or affected docs or Error object * @returns {Promise<number|Object|Object[]|Error>} - number of updated rows or affected docs or Error object
*/ */
public async update(query: object, update: object, options: Options = {}): Promise<any> { public async update(query: object, update: object, options: Options = {}): Promise<any> {
@ -142,11 +145,10 @@ export class Database {
* @see https://github.com/louischatriot/nedb#removing-documents * @see https://github.com/louischatriot/nedb#removing-documents
* *
* @param {Object} query - query object * @param {Object} query - query object
* @param {Object} options * @param {Options} options - optional params
* @param {boolean} options.multi - (false) if true, remove several docs
* @returns {Promise<number|Error>} - number of removed rows or Error object * @returns {Promise<number|Error>} - number of removed rows or Error object
*/ */
public async remove(query: object, options = {}): Promise<number|Error> { public async remove(query: object, options: Options = {}): Promise<number|Error> {
return new Promise((resolve, reject) => this.db.remove(query, options, (err, result) => { return new Promise((resolve, reject) => this.db.remove(query, options, (err, result) => {
if (err) { if (err) {
reject(err); reject(err);

View file

@ -7,10 +7,10 @@
*/ */
/** /**
* @param target * @param target - target to merge into
* @param {...any} sources * @param {...any} sources - sources to merge from
*/ */
function deepMerge(target: any, ...sources: any[]): object { function deepMerge(target: any, ...sources: any[]): Record<string, unknown> {
const isObject = (item: any): boolean => item && typeof item === 'object' && !Array.isArray(item); const isObject = (item: any): boolean => item && typeof item === 'object' && !Array.isArray(item);
if (!sources.length) { if (!sources.length) {

View file

@ -4,17 +4,27 @@ import config from 'config';
const rcPath = path.resolve(__dirname, '../../', config.get('rcFile') || './.codexdocsrc'); const rcPath = path.resolve(__dirname, '../../', config.get('rcFile') || './.codexdocsrc');
interface RConfig { /**
[key: string]: any; * @typedef {object} menu
* @property {string} title - menu option title
* @property {string} uri - menu option href
*/
interface Menu {
title: string;
uri: string;
[key: string]: string;
} }
/** /**
* @typedef {object} RCData * @typedef {object} RCData
* @property {string} title - website title * @property {string} title - website title
* @property {object[]} menu - options for website menu * @property {Menu[]} menu - options for website menu
* @property {string} menu[].title - menu option title
* @property {string} menu[].uri - menu option href
*/ */
interface RCData {
title: string;
menu: Menu[];
[key: string]: string | Menu[];
}
/** /**
* @class RCParser * @class RCParser
@ -27,11 +37,11 @@ export default class RCParser {
* @static * @static
* @returns {{title: string, menu: Array}} * @returns {{title: string, menu: Array}}
*/ */
public static get DEFAULTS():RConfig { public static get DEFAULTS():RCData {
return { return {
title: 'CodeX Docs', title: 'CodeX Docs',
menu: [], menu: [],
} as RConfig; };
} }
/** /**
@ -40,7 +50,7 @@ export default class RCParser {
* @static * @static
* @returns {{title: string, menu: []}} * @returns {{title: string, menu: []}}
*/ */
public static getConfiguration(): RConfig { public static getConfiguration(): RCData {
if (!fs.existsSync(rcPath)) { if (!fs.existsSync(rcPath)) {
return RCParser.DEFAULTS; return RCParser.DEFAULTS;
} }

View file

@ -77,7 +77,8 @@ const translationTable: TransTable = {
*/ */
/** /**
* @param string * @param {string} string - input text to be translated
* @returns {string} text - translated text
*/ */
export default function translateString(string: string): string { export default function translateString(string: string): string {
return string.replace(/[А-яёЁ]/g, (char) => translationTable[char] || char); return string.replace(/[А-яёЁ]/g, (char) => translationTable[char] || char);

View file

@ -34,7 +34,7 @@ export default (function () {
* Parse link as URL object * Parse link as URL object
* *
* @param {string} linkUrl - link to be processed * @param {string} linkUrl - link to be processed
* @returns {UrlWithStringQuery} url data * @returns {string} url url data
*/ */
twig.extendFunction('parseLink', function (linkUrl: string): string { twig.extendFunction('parseLink', function (linkUrl: string): string {
try { try {