mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-07 22:45:23 +02:00
fixed jsdocs warning, leaving editor confirmation
This commit is contained in:
parent
1f166c1a3d
commit
86e7293c7a
26 changed files with 94 additions and 78 deletions
|
@ -13,10 +13,11 @@
|
|||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"no-unused-expressions": 0,
|
||||
"no-unused-expressions": 1,
|
||||
"chai-friendly/no-unused-expressions": 2,
|
||||
"@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",
|
||||
"globals": {
|
||||
|
|
2
public/dist/code-styling.bundle.js
vendored
2
public/dist/code-styling.bundle.js
vendored
File diff suppressed because one or more lines are too long
14
public/dist/editor.bundle.js
vendored
14
public/dist/editor.bundle.js
vendored
File diff suppressed because one or more lines are too long
4
public/dist/main.bundle.js
vendored
4
public/dist/main.bundle.js
vendored
File diff suppressed because one or more lines are too long
2
public/dist/main.css
vendored
2
public/dist/main.css
vendored
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,4 @@
|
|||
import express, { NextFunction, Request, Response } from 'express';
|
||||
import express, { Request, Response } from 'express';
|
||||
import path from 'path';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import morgan from 'morgan';
|
||||
|
@ -25,7 +25,7 @@ app.use(express.static(path.join(__dirname, '../public')));
|
|||
app.use('/', routes);
|
||||
|
||||
// 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
|
||||
res.locals.message = err.message;
|
||||
res.locals.error = req.app.get('env') == 'development' ? err : {};
|
||||
|
|
|
@ -84,7 +84,7 @@ class Pages {
|
|||
/**
|
||||
* Create new page model and save it in the database
|
||||
*
|
||||
* @param {PageData} data
|
||||
* @param {PageData} data - info about page
|
||||
* @returns {Promise<Page>}
|
||||
*/
|
||||
public static async insert(data: PageData): Promise<Page> {
|
||||
|
@ -114,7 +114,7 @@ class Pages {
|
|||
* Update page with given id in the database
|
||||
*
|
||||
* @param {string} id - page id
|
||||
* @param {PageData} data
|
||||
* @param {PageData} data - info about page
|
||||
* @returns {Promise<Page>}
|
||||
*/
|
||||
public static async update(id: string, data: PageData): Promise<Page> {
|
||||
|
@ -171,7 +171,7 @@ class Pages {
|
|||
/**
|
||||
* Check PageData object for required fields
|
||||
*
|
||||
* @param {PageData} data
|
||||
* @param {PageData} data - info about page
|
||||
* @throws {Error} - validation error
|
||||
*/
|
||||
private static validate(data: PageData): void {
|
||||
|
|
|
@ -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} parentPageId - parent page's id that contains both two pages
|
||||
* @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>}
|
||||
*/
|
||||
public static async remove(parentId: string): Promise<void> {
|
||||
|
|
|
@ -95,7 +95,7 @@ class Transport {
|
|||
/**
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -5,8 +5,8 @@ class HttpException extends Error {
|
|||
public status: number;
|
||||
public message: string;
|
||||
/**
|
||||
* @param status
|
||||
* @param message
|
||||
* @param status - status of the exception
|
||||
* @param message - message about the exception
|
||||
*/
|
||||
constructor(status: number, message: string) {
|
||||
super(message);
|
||||
|
|
|
@ -52,11 +52,16 @@ export default class Writing {
|
|||
this.editor = editor;
|
||||
});
|
||||
|
||||
window.onbeforeunload = (e) => {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate form elements
|
||||
*/
|
||||
this.nodes.saveButton = moduleEl.querySelector('[name="js-submit-save"]');
|
||||
this.nodes.saveButton.addEventListener('click', () => {
|
||||
window.onbeforeunload = null;
|
||||
this.saveButtonClicked();
|
||||
});
|
||||
|
||||
|
@ -69,7 +74,7 @@ export default class Writing {
|
|||
if (!isUserAgree) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.onbeforeunload = null;
|
||||
this.removeButtonClicked();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class Alias {
|
|||
/**
|
||||
* @class
|
||||
*
|
||||
* @param {AliasData} data
|
||||
* @param {AliasData} data - info about alias
|
||||
* @param {string} aliasName - alias of entity
|
||||
*/
|
||||
constructor(data: AliasData = {}, aliasName = '') {
|
||||
|
@ -125,7 +125,7 @@ class Alias {
|
|||
/**
|
||||
* Set AliasData object fields to internal model fields
|
||||
*
|
||||
* @param {AliasData} aliasData
|
||||
* @param {AliasData} aliasData - info about alias
|
||||
*/
|
||||
public set data(aliasData: AliasData) {
|
||||
const { id, type, hash, deprecated } = aliasData;
|
||||
|
|
|
@ -12,7 +12,6 @@ const filesDb = database['files'];
|
|||
* @property {string} mimetype - file MIME type
|
||||
* @property {number} size - size of the file in
|
||||
*/
|
||||
|
||||
export interface FileData {
|
||||
_id?: string;
|
||||
name?: string;
|
||||
|
@ -45,7 +44,7 @@ class File {
|
|||
/**
|
||||
* @class
|
||||
*
|
||||
* @param {FileData} data
|
||||
* @param {FileData} data - info about file
|
||||
*/
|
||||
constructor(data: FileData = {}) {
|
||||
if (data === null) {
|
||||
|
@ -85,7 +84,7 @@ class File {
|
|||
/**
|
||||
* Find all files which match passed query object
|
||||
*
|
||||
* @param {object} query
|
||||
* @param {object} query - input query
|
||||
* @returns {Promise<File[]>}
|
||||
*/
|
||||
public static async getAll(query: object = {}): Promise<File[]> {
|
||||
|
@ -101,7 +100,7 @@ class File {
|
|||
/**
|
||||
* Set FileData object fields to internal model fields
|
||||
*
|
||||
* @param {FileData} fileData
|
||||
* @param {FileData} fileData - info about file
|
||||
*/
|
||||
public set data(fileData: FileData) {
|
||||
const { name, filename, path, mimetype, size } = fileData;
|
||||
|
@ -171,7 +170,7 @@ class File {
|
|||
/**
|
||||
* Removes unnecessary public folder prefix
|
||||
*
|
||||
* @param {string} path
|
||||
* @param {string} path - input path to be processed
|
||||
* @returns {string}
|
||||
*/
|
||||
private processPath(path: string): string {
|
||||
|
|
|
@ -40,7 +40,7 @@ class Page {
|
|||
/**
|
||||
* @class
|
||||
*
|
||||
* @param {PageData} data
|
||||
* @param {PageData} data - page's data
|
||||
*/
|
||||
constructor(data: PageData = {}) {
|
||||
if (data === null) {
|
||||
|
@ -89,7 +89,7 @@ class Page {
|
|||
/**
|
||||
* Find all pages which match passed query object
|
||||
*
|
||||
* @param {object} query
|
||||
* @param {object} query - input query
|
||||
* @returns {Promise<Page[]>}
|
||||
*/
|
||||
public static async getAll(query: object = {}): Promise<Page[]> {
|
||||
|
@ -105,7 +105,7 @@ class Page {
|
|||
/**
|
||||
* Set PageData object fields to internal model fields
|
||||
*
|
||||
* @param {PageData} pageData
|
||||
* @param {PageData} pageData - page's data
|
||||
*/
|
||||
public set data(pageData: PageData) {
|
||||
const { body, parent, uri } = pageData;
|
||||
|
@ -134,7 +134,7 @@ class Page {
|
|||
/**
|
||||
* Link given page as parent
|
||||
*
|
||||
* @param {Page} parentPage
|
||||
* @param {Page} parentPage - the page to be set as parent
|
||||
*/
|
||||
public set parent(parentPage: Page) {
|
||||
this._parent = parentPage._id;
|
||||
|
@ -216,7 +216,7 @@ class Page {
|
|||
* Find and return available uri
|
||||
*
|
||||
* @returns {Promise<string>}
|
||||
* @param uri
|
||||
* @param uri - input uri to be composed
|
||||
*/
|
||||
private async composeUri(uri: string): Promise<string> {
|
||||
let pageWithSameUriCount = 0;
|
||||
|
|
|
@ -8,7 +8,6 @@ const db = database['pagesOrder'];
|
|||
* @property {string} page - page id
|
||||
* @property {Array<string>} order - list of ordered pages
|
||||
*/
|
||||
|
||||
export interface PageOrderData {
|
||||
_id?: string;
|
||||
page?: string;
|
||||
|
@ -30,7 +29,7 @@ class PageOrder {
|
|||
/**
|
||||
* @class
|
||||
*
|
||||
* @param {PageOrderData} data
|
||||
* @param {PageOrderData} data - info about pageOrder
|
||||
*/
|
||||
constructor(data: PageOrderData = {}) {
|
||||
if (data === null) {
|
||||
|
@ -67,7 +66,7 @@ class PageOrder {
|
|||
/**
|
||||
* Find all pages which match passed query object
|
||||
*
|
||||
* @param {object} query
|
||||
* @param {object} query - input query
|
||||
* @returns {Promise<PageOrder[]>}
|
||||
*/
|
||||
public static async getAll(query: object = {}): Promise<PageOrder[]> {
|
||||
|
@ -83,7 +82,7 @@ class PageOrder {
|
|||
/**
|
||||
* constructor data setter
|
||||
*
|
||||
* @param {PageOrderData} pageOrderData
|
||||
* @param {PageOrderData} pageOrderData - info about pageOrder
|
||||
*/
|
||||
public set data(pageOrderData: PageOrderData) {
|
||||
this.page = pageOrderData.page || '0';
|
||||
|
@ -163,7 +162,7 @@ class PageOrder {
|
|||
/**
|
||||
* Returns page before passed page with id
|
||||
*
|
||||
* @param {string} pageId
|
||||
* @param {string} pageId - identity of page
|
||||
*/
|
||||
public getPageBefore(pageId: string): string | null {
|
||||
if (this.order === undefined) {
|
||||
|
@ -185,7 +184,7 @@ class PageOrder {
|
|||
/**
|
||||
* Returns page before passed page with id
|
||||
*
|
||||
* @param pageId
|
||||
* @param pageId - identity of page
|
||||
*/
|
||||
public getPageAfter(pageId: string): string | null {
|
||||
if (this.order === undefined) {
|
||||
|
|
|
@ -18,7 +18,7 @@ class User {
|
|||
/**
|
||||
* @class
|
||||
*
|
||||
* @param {UserData} userData
|
||||
* @param {UserData} userData - user data for construct new object
|
||||
*/
|
||||
constructor(userData: UserData) {
|
||||
this.passHash = userData.passHash;
|
||||
|
|
|
@ -107,7 +107,7 @@ router.post('/page/:id', multer.none(), async (req: Request, res: Response) => {
|
|||
|
||||
const unOrdered: string[] = [];
|
||||
|
||||
unordered.forEach((item, index) => {
|
||||
unordered.forEach(item => {
|
||||
if (typeof item === 'string') {
|
||||
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
|
||||
*
|
||||
* @param {string} startFrom
|
||||
* @param {string} startFrom - start point to delete
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const deleteRecursively = async (startFrom: string): Promise<void> => {
|
||||
|
|
|
@ -3,9 +3,9 @@ import { NextFunction, Request, Response } from 'express';
|
|||
/**
|
||||
* Middleware for checking locals.isAuthorized property, which allows to edit/create pages
|
||||
*
|
||||
* @param req
|
||||
* @param res
|
||||
* @param next
|
||||
* @param req - request object
|
||||
* @param res - response object
|
||||
* @param next - next function
|
||||
*/
|
||||
export default function allowEdit(req: Request, res: Response, next: NextFunction): void {
|
||||
if (res.locals.isAuthorized) {
|
||||
|
|
|
@ -11,8 +11,8 @@ import PageOrder from '../../models/pageOrder';
|
|||
* @param {string} parentPageId - parent page id
|
||||
* @param {Page[]} pages - list of all available pages
|
||||
* @param {PagesOrder[]} pagesOrder - list of pages order
|
||||
* @param {number} level
|
||||
* @param {number} currentLevel
|
||||
* @param {number} level - max level recursion
|
||||
* @param {number} currentLevel - current level of element
|
||||
*
|
||||
* @returns {Page[]}
|
||||
*/
|
||||
|
|
|
@ -9,9 +9,9 @@ dotenv.config();
|
|||
/**
|
||||
* Middleware for checking jwt token
|
||||
*
|
||||
* @param req
|
||||
* @param res
|
||||
* @param next
|
||||
* @param req - request object
|
||||
* @param res - response object
|
||||
* @param next - next function
|
||||
*/
|
||||
export default async function verifyToken(req: Request, res: Response, next: NextFunction): Promise<void> {
|
||||
const token = req.cookies.authToken;
|
||||
|
|
|
@ -3,10 +3,9 @@ import { NextFunction, Request, Response } from 'express';
|
|||
/**
|
||||
* Helper for making async middlewares for express router
|
||||
*
|
||||
* @param fn
|
||||
* @param {Function} fn - input function
|
||||
* @returns {function(*=, *=, *=)}
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export default function asyncMiddleware(fn: Function): (...params: any) => void {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
Promise.resolve(fn(req, res, next))
|
||||
|
|
|
@ -5,17 +5,24 @@ import aliases from './aliases';
|
|||
import pagesOrder from './pagesOrder';
|
||||
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 {
|
||||
multi?: boolean;
|
||||
upsert?: boolean;
|
||||
returnUpdatedDocs?: boolean;
|
||||
multi?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @class Database
|
||||
* @classdesc Simple decorator class to work with nedb datastore
|
||||
*
|
||||
* @property db - nedb Datastore object
|
||||
* @property {Datastore} db - nedb Datastore object
|
||||
*/
|
||||
export class Database {
|
||||
private db: Datastore;
|
||||
|
@ -107,11 +114,7 @@ export class Database {
|
|||
*
|
||||
* @param {Object} query - query object
|
||||
* @param {Object} update - fields to update
|
||||
* @param {Object} options
|
||||
* @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
|
||||
* @param {Options} options - optional params
|
||||
* @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> {
|
||||
|
@ -142,11 +145,10 @@ export class Database {
|
|||
* @see https://github.com/louischatriot/nedb#removing-documents
|
||||
*
|
||||
* @param {Object} query - query object
|
||||
* @param {Object} options
|
||||
* @param {boolean} options.multi - (false) if true, remove several docs
|
||||
* @param {Options} options - optional params
|
||||
* @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) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @param target
|
||||
* @param {...any} sources
|
||||
* @param target - target to merge into
|
||||
* @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);
|
||||
|
||||
if (!sources.length) {
|
||||
|
|
|
@ -4,17 +4,27 @@ import config from 'config';
|
|||
|
||||
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
|
||||
* @property {string} title - website title
|
||||
* @property {object[]} menu - options for website menu
|
||||
* @property {string} menu[].title - menu option title
|
||||
* @property {string} menu[].uri - menu option href
|
||||
* @property {Menu[]} menu - options for website menu
|
||||
*/
|
||||
interface RCData {
|
||||
title: string;
|
||||
menu: Menu[];
|
||||
[key: string]: string | Menu[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @class RCParser
|
||||
|
@ -27,11 +37,11 @@ export default class RCParser {
|
|||
* @static
|
||||
* @returns {{title: string, menu: Array}}
|
||||
*/
|
||||
public static get DEFAULTS():RConfig {
|
||||
public static get DEFAULTS():RCData {
|
||||
return {
|
||||
title: 'CodeX Docs',
|
||||
menu: [],
|
||||
} as RConfig;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +50,7 @@ export default class RCParser {
|
|||
* @static
|
||||
* @returns {{title: string, menu: []}}
|
||||
*/
|
||||
public static getConfiguration(): RConfig {
|
||||
public static getConfiguration(): RCData {
|
||||
if (!fs.existsSync(rcPath)) {
|
||||
return RCParser.DEFAULTS;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
return string.replace(/[А-яёЁ]/g, (char) => translationTable[char] || char);
|
||||
|
|
|
@ -34,7 +34,7 @@ export default (function () {
|
|||
* Parse link as URL object
|
||||
*
|
||||
* @param {string} linkUrl - link to be processed
|
||||
* @returns {UrlWithStringQuery} — url data
|
||||
* @returns {string} url — url data
|
||||
*/
|
||||
twig.extendFunction('parseLink', function (linkUrl: string): string {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue