workspace: update eslint config

This commit is contained in:
undefined committed 2021-02-01 12:33:48 +08:00
1 parent 4e4f6688bc
commit 3a3983d38d
29 files changed
+169 -166

No files matched your search

+2 -1
View File
@@ -2,4 +2,5 @@ dist
*.d.ts *.d.ts
*.js *.js
test test
tests tests
node_modules
-59
View File
@@ -1,59 +0,0 @@
module.exports = {
root: true,
env: {
node: true,
},
extends: [
'airbnb-base',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
BigInt: true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/no-dupe-class-members': 'error',
'@typescript-eslint/no-unused-vars': 'error',
camelcase: 'off',
'global-require': 'off',
'guard-for-in': 'off',
'implicit-arrow-linebreak': 'off',
'import/extensions': 'off',
'import/no-cycle': 'off',
'import/no-extraneous-dependencies': 'off',
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'import/prefer-default-export': 'off',
indent: ['warn', 4],
'lines-between-class-members': ['error', 'always', { 'exceptAfterSingleLine': true }],
'max-classes-per-file': 'off',
'max-len': ['warn', 150],
'no-bitwise': 'off',
'no-console': 'off',
'no-continue': 'off',
'no-dupe-class-members': 'off',
'no-extend-native': 'off',
'no-inner-declarations': 'off',
'no-multi-assign': 'off',
'no-nested-ternary': 'off',
'no-param-reassign': 'off',
'no-plusplus': 'off',
'no-restricted-syntax': 'off',
'no-return-await': 'off',
'no-underscore-dangle': 'off',
'no-unused-vars': 'off',
'prefer-destructuring': 'off',
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts'],
},
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
},
};
+55
View File
@@ -0,0 +1,55 @@
root: true
extends:
- airbnb-typescript/base
globals:
Atomics: readonly
SharedArrayBuffer: readonly
BigInt: readonly
parser: '@typescript-eslint/parser'
plugins:
- '@typescript-eslint'
rules:
'@typescript-eslint/dot-notation': off
'@typescript-eslint/no-implied-eval': off
'@typescript-eslint/no-throw-literal': off
'@typescript-eslint/indent':
- warn
- 4
'@typescript-eslint/lines-between-class-members':
- error
- always
- exceptAfterSingleLine: true
'@typescript-eslint/naming-convention': off
'@typescript-eslint/no-redeclare': off
global-require: off
guard-for-in: off
implicit-arrow-linebreak: off
import/no-cycle: off
import/no-extraneous-dependencies: off
import/no-named-as-default: off
import/prefer-default-export: off
max-classes-per-file: off
max-len:
- warn
- 150
no-bitwise: off
no-console: off
no-continue: off
no-extend-native: off
no-multi-assign: off
no-nested-ternary: off
no-param-reassign: off
no-plusplus: off
no-restricted-syntax: off
no-return-await: off
no-underscore-dangle: off
prefer-destructuring: off
settings:
import/parsers:
'@typescript-eslint/parser':
- .ts
import/resolver:
typescript:
alwaysTryTypes: true
+5 -5
View File
@@ -23,11 +23,11 @@
"@types/jest": "^26.0.20", "@types/jest": "^26.0.20",
"@types/node": "^14.14.22", "@types/node": "^14.14.22",
"@types/semver": "^7.3.4", "@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^3.9.1", "@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^3.9.1", "@typescript-eslint/parser": "^4.14.1",
"cross-spawn": "^7.0.3", "cross-spawn": "^7.0.3",
"eslint": "^7.18.0", "eslint": "^7.19.0",
"eslint-config-airbnb-base": "^14.2.1", "eslint-config-airbnb-typescript": "^12.0.0",
"eslint-import-resolver-typescript": "^2.3.0", "eslint-import-resolver-typescript": "^2.3.0",
"eslint-plugin-import": "^2.22.1", "eslint-plugin-import": "^2.22.1",
"globby": "^11.0.2", "globby": "^11.0.2",
@@ -35,7 +35,7 @@
"latest-version": "^5.1.0", "latest-version": "^5.1.0",
"ora": "^5.3.0", "ora": "^5.3.0",
"semver": "^7.3.4", "semver": "^7.3.4",
"ts-jest": "^26.4.4", "ts-jest": "^26.5.0",
"typescript": "4.1.3" "typescript": "4.1.3"
}, },
"dependencies": { "dependencies": {
+2 -2
View File
@@ -7,13 +7,13 @@
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"dependencies": { "dependencies": {
"adm-zip": "^0.5.1", "adm-zip": "^0.5.2",
"decode-html": "^2.0.0", "decode-html": "^2.0.0",
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
"xml2js": "^0.4.23" "xml2js": "^0.4.23"
}, },
"devDependencies": { "devDependencies": {
"@types/xml2js": "^0.4.7", "@types/xml2js": "^0.4.8",
"bson": "^4.2.2" "bson": "^4.2.2"
}, },
"peerDependencies": { "peerDependencies": {
+3 -3
View File
@@ -1,12 +1,12 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.3.2", "version": "2.3.3",
"main": "package.json", "main": "package.json",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
"dependencies": { "dependencies": {
"adm-zip": "^0.5.1", "adm-zip": "^0.5.2",
"axios": "^0.21.1", "axios": "^0.21.1",
"bson": "^4.2.2", "bson": "^4.2.2",
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
@@ -14,7 +14,7 @@
"lodash": "^4.17.20", "lodash": "^4.17.20",
"p-queue": "^6.6.1", "p-queue": "^6.6.1",
"shell-quote": "^1.7.2", "shell-quote": "^1.7.2",
"systeminformation": "^4.34.9", "systeminformation": "^5.0.8",
"yargs": "^16.2.0" "yargs": "^16.2.0"
}, },
"peerDependencies": { "peerDependencies": {
+1 -1
View File
@@ -36,4 +36,4 @@ export = async function compile(
}; };
} }
throw new SystemError('Unknown language type.'); throw new SystemError('Unknown language type.');
} };
+1 -1
View File
@@ -6,4 +6,4 @@ import * as hack from './hack';
export = { export = {
default: def, interactive, run, submit_answer, hack, default: def, interactive, run, submit_answer, hack,
} };
+18 -18
View File
@@ -31,39 +31,39 @@ const colors = [
]; ];
const instances: Record<string, Logger> = {}; const instances: Record<string, Logger> = {};
type LogFunction = (format: any, ...param: any[]) => void type LogFunction = (format: any, ...param: any[]) => void;
type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug' type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug';
export interface Logger extends Record<LogType, LogFunction> { } export interface Logger extends Record<LogType, LogFunction> { }
export class Logger { export class Logger {
static readonly SUCCESS = 1 static readonly SUCCESS = 1;
static readonly ERROR = 1 static readonly ERROR = 1;
static readonly INFO = 2 static readonly INFO = 2;
static readonly WARN = 2 static readonly WARN = 2;
static readonly DEBUG = 3 static readonly DEBUG = 3;
static baseLevel = argv.debug ? 3 : 2 static baseLevel = argv.debug ? 3 : 2;
static showDiff = false static showDiff = false;
static levels: Record<string, number> = {} static levels: Record<string, number> = {};
static lastTime = 0 static lastTime = 0;
static options: InspectOptions = { static options: InspectOptions = {
colors: process.stderr.isTTY, colors: process.stderr.isTTY,
} };
static formatters: Record<string, (this: Logger, value: any) => string> = { static formatters: Record<string, (this: Logger, value: any) => string> = {
c: Logger.prototype.color, c: Logger.prototype.color,
C: (value) => Logger.color(15, value, ';1'), C: (value) => Logger.color(15, value, ';1'),
o: (value) => inspect(value, Logger.options).replace(/\s*\n\s*/g, ' '), o: (value) => inspect(value, Logger.options).replace(/\s*\n\s*/g, ' '),
} };
static color(code: number, value: any, decoration = '') { static color(code: number, value: any, decoration = '') {
if (!Logger.options.colors) return `${value}`; if (!Logger.options.colors) return `${value}`;
return `\u001B[3${code < 8 ? code : `8;5;${code}`}${decoration}m${value}\u001B[0m`; return `\u001B[3${code < 8 ? code : `8;5;${code}`}${decoration}m${value}\u001B[0m`;
} }
private code: number private code: number;
private displayName: string private displayName: string;
public stream: NodeJS.WritableStream = process.stderr public stream: NodeJS.WritableStream = process.stderr;
constructor(public name: string, private showDiff = false) { constructor(public name: string, private showDiff = false) {
if (name in instances) return instances[name]; if (name in instances) return instances[name];
@@ -97,7 +97,7 @@ export class Logger {
return Logger.levels[this.name] ?? Logger.baseLevel; return Logger.levels[this.name] ?? Logger.baseLevel;
} }
extend = (namespace: string, showDiff = this.showDiff) => new Logger(`${this.name}:${namespace}`, showDiff) extend = (namespace: string, showDiff = this.showDiff) => new Logger(`${this.name}:${namespace}`, showDiff);
format: (format: any, ...param: any[]) => string = (...args) => { format: (format: any, ...param: any[]) => string = (...args) => {
if (args[0] instanceof Error) args[0] = args[0].stack || args[0].message; if (args[0] instanceof Error) args[0] = args[0].stack || args[0].message;
@@ -122,7 +122,7 @@ export class Logger {
Logger.lastTime = now; Logger.lastTime = now;
} }
return format(...args); return format(...args);
} };
} }
export default new Logger('judge'); export default new Logger('judge');
+6 -6
View File
@@ -78,11 +78,11 @@ export async function get() {
const cpu = `${Cpu.manufacturer} ${Cpu.brand}`; const cpu = `${Cpu.manufacturer} ${Cpu.brand}`;
const memory = `${size(Memory.active)}/${size(Memory.total)}`; const memory = `${size(Memory.active)}/${size(Memory.total)}`;
const osinfo = `${OsInfo.distro} ${OsInfo.release} ${OsInfo.codename} ${OsInfo.kernel} ${OsInfo.arch}`; const osinfo = `${OsInfo.distro} ${OsInfo.release} ${OsInfo.codename} ${OsInfo.kernel} ${OsInfo.arch}`;
const load = `${CurrentLoad.avgload}`; const load = `${CurrentLoad.avgLoad}`;
const flags = CpuFlags; const flags = CpuFlags;
let battery; let battery;
if (!Battery.hasbattery) battery = 'No battery'; if (!Battery.hasBattery) battery = 'No battery';
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`; else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`;
const mid = OsInfo.serial; const mid = OsInfo.serial;
cache.cpu = cpu; cache.cpu = cpu;
cache.osinfo = osinfo; cache.osinfo = osinfo;
@@ -114,10 +114,10 @@ export async function update() {
mid, cpu, osinfo, flags, stack, mid, cpu, osinfo, flags, stack,
} = cache; } = cache;
const memory = `${size(Memory.active)}/${size(Memory.total)}`; const memory = `${size(Memory.active)}/${size(Memory.total)}`;
const load = `${CurrentLoad.avgload}`; const load = `${CurrentLoad.avgLoad}`;
let battery; let battery;
if (!Battery.hasbattery) battery = 'No battery'; if (!Battery.hasBattery) battery = 'No battery';
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`; else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`;
const reqCount = global.reqCount; const reqCount = global.reqCount;
global.reqCount = 0; global.reqCount = 0;
return [ return [
+9 -8
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.17.6", "version": "2.17.7",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
@@ -11,8 +11,8 @@
"node": ">=10.10" "node": ">=10.10"
}, },
"dependencies": { "dependencies": {
"adm-zip": "^0.5.1", "adm-zip": "^0.5.2",
"ansi_up": "^4.0.4", "ansi_up": "^5.0.0",
"cookies": "^0.8.0", "cookies": "^0.8.0",
"detect-browser": "^5.1.1", "detect-browser": "^5.1.1",
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
@@ -32,27 +32,28 @@
"serialize-javascript": "^5.0.1", "serialize-javascript": "^5.0.1",
"sockjs": "^0.3.20", "sockjs": "^0.3.20",
"superagent": "^6.1.0", "superagent": "^6.1.0",
"systeminformation": "^4.34.9", "systeminformation": "^5.0.8",
"terminal-kit": "^1.45.8", "terminal-kit": "^1.45.9",
"yargs": "^16.2.0" "yargs": "^16.2.0"
}, },
"devDependencies": { "devDependencies": {
"@types/adm-zip": "^0.4.33", "@types/adm-zip": "^0.4.33",
"@types/fs-extra": "^9.0.6", "@types/fs-extra": "^9.0.6",
"@types/js-yaml": "^4.0.0", "@types/js-yaml": "^4.0.0",
"@types/koa": "^2.11.4", "@types/koa": "^2.11.7",
"@types/koa-router": "^7.4.1", "@types/koa-router": "^7.4.1",
"@types/koa-static-cache": "^5.1.0", "@types/koa-static-cache": "^5.1.0",
"@types/lodash": "^4.14.168", "@types/lodash": "^4.14.168",
"@types/lru-cache": "^5.1.0", "@types/lru-cache": "^5.1.0",
"@types/minio": "^7.0.7", "@types/minio": "^7.0.7",
"@types/mongodb": "^3.5.33", "@types/mongodb": "^3.6.3",
"@types/nodemailer": "^6.4.0", "@types/nodemailer": "^6.4.0",
"@types/serialize-javascript": "^5.0.0", "@types/serialize-javascript": "^5.0.0",
"@types/sockjs": "^0.3.32", "@types/sockjs": "^0.3.32",
"@types/superagent": "^4.1.8", "@types/superagent": "^4.1.8",
"@types/terminal-kit": "^1.28.2", "@types/terminal-kit": "^1.28.2",
"@types/yargs": "^15.0.12" "@types/yargs": "^16.0.0",
"formidable": "^1.2.2"
}, },
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
-2
View File
@@ -10,7 +10,6 @@ import { argv } from 'yargs';
import { Logger } from '../logger'; import { Logger } from '../logger';
const logger = new Logger('setup'); const logger = new Logger('setup');
const listenPort = argv.port || 8888; const listenPort = argv.port || 8888;
async function get(ctx: Context) { async function get(ctx: Context) {
@@ -81,7 +80,6 @@ async function get(ctx: Context) {
async function post(ctx: Context) { async function post(ctx: Context) {
const { const {
host, port, name, username, password, host, port, name, username, password,
// @ts-ignore
} = ctx.request.body; } = ctx.request.body;
let mongourl = 'mongodb://'; let mongourl = 'mongodb://';
if (username) mongourl += `${username}:${password}@`; if (username) mongourl += `${username}:${password}@`;
+9 -1
View File
@@ -2,6 +2,7 @@ import type { Readable, Writable } from 'stream';
import type { ObjectID } from 'mongodb'; import type { ObjectID } from 'mongodb';
import type fs from 'fs'; import type fs from 'fs';
import type { Dictionary, NumericDictionary } from 'lodash'; import type { Dictionary, NumericDictionary } from 'lodash';
import type * as Koa from 'koa';
import type { Pdoc } from './model/problem'; import type { Pdoc } from './model/problem';
type document = typeof import('./model/document'); type document = typeof import('./model/document');
@@ -159,7 +160,7 @@ export interface SampleContentNode {
payload: [string, string], payload: [string, string],
} }
export type ContentNode = PlainContentNode | TextContentNode | SampleContentNode; export type ContentNode = PlainContentNode | TextContentNode | SampleContentNode;
export type Content = string | ContentNode[] | Record<string, ContentNode[]> export type Content = string | ContentNode[] | Record<string, ContentNode[]>;
declare module './model/problem' { declare module './model/problem' {
interface Pdoc { interface Pdoc {
@@ -589,3 +590,10 @@ declare global {
} }
} }
} }
declare module 'koa' {
interface Request extends Koa.BaseRequest {
body?: any;
files?: import('formidable').Files;
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ async function _download(url: string, path: string, retry: number) {
return path; return path;
} }
function download(url: string): SuperAgentRequest function download(url: string): SuperAgentRequest;
function download(url: string, path?: string, retry = 3) { function download(url: string, path?: string, retry = 3) {
if (path) return _download(url, path, retry); if (path) return _download(url, path, retry);
return superagent.get(url).retry(retry); return superagent.get(url).retry(retry);
+6 -6
View File
@@ -18,11 +18,11 @@ export async function get() {
const cpu = `${Cpu.manufacturer} ${Cpu.brand}`; const cpu = `${Cpu.manufacturer} ${Cpu.brand}`;
const memory = `${size(Memory.active)}/${size(Memory.total)}`; const memory = `${size(Memory.active)}/${size(Memory.total)}`;
const osinfo = `${OsInfo.distro} ${OsInfo.release} ${OsInfo.codename} ${OsInfo.kernel} ${OsInfo.arch}`; const osinfo = `${OsInfo.distro} ${OsInfo.release} ${OsInfo.codename} ${OsInfo.kernel} ${OsInfo.arch}`;
const load = `${CurrentLoad.avgload}`; const load = `${CurrentLoad.avgLoad}`;
const flags = CpuFlags; const flags = CpuFlags;
let battery; let battery;
if (!Battery.hasbattery) battery = 'No battery'; if (!Battery.hasBattery) battery = 'No battery';
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`; else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`;
const mid = OsInfo.serial; const mid = OsInfo.serial;
cache.cpu = cpu; cache.cpu = cpu;
cache.osinfo = osinfo; cache.osinfo = osinfo;
@@ -44,10 +44,10 @@ export async function update(): Promise<[string, any, any]> {
mid, cpu, osinfo, flags, mid, cpu, osinfo, flags,
} = cache; } = cache;
const memory = `${size(Memory.active)}/${size(Memory.total)}`; const memory = `${size(Memory.active)}/${size(Memory.total)}`;
const load = `${CurrentLoad.avgload}`; const load = `${CurrentLoad.avgLoad}`;
let battery; let battery;
if (!Battery.hasbattery) battery = 'No battery'; if (!Battery.hasBattery) battery = 'No battery';
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`; else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`;
return [ return [
mid, mid,
{ {
+14 -14
View File
@@ -3,22 +3,22 @@ import { argv } from 'yargs';
import { Time } from './utils'; import { Time } from './utils';
const instances: Record<string, Logger> = {}; const instances: Record<string, Logger> = {};
type LogFunction = (format: any, ...param: any[]) => void type LogFunction = (format: any, ...param: any[]) => void;
type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug' type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug';
export interface Logger extends Record<LogType, LogFunction> { } export interface Logger extends Record<LogType, LogFunction> { }
export class Logger { export class Logger {
static readonly SUCCESS = 1 static readonly SUCCESS = 1;
static readonly ERROR = 1 static readonly ERROR = 1;
static readonly INFO = 2 static readonly INFO = 2;
static readonly WARN = 2 static readonly WARN = 2;
static readonly DEBUG = 3 static readonly DEBUG = 3;
static baseLevel = argv.debug ? 3 : 2 static baseLevel = argv.debug ? 3 : 2;
static showDiff = false static showDiff = false;
static levels: Record<string, number> = {} static levels: Record<string, number> = {};
static lastTime = 0 static lastTime = 0;
static formatters: Record<string, (this: Logger, value: any) => string> = { static formatters: Record<string, (this: Logger, value: any) => string> = {
o: (value) => inspect(value).replace(/\s*\n\s*/g, ' '), o: (value) => inspect(value).replace(/\s*\n\s*/g, ' '),
} };
constructor(public name: string, private showDiff = false) { constructor(public name: string, private showDiff = false) {
if (name in instances) return instances[name]; if (name in instances) return instances[name];
@@ -48,7 +48,7 @@ export class Logger {
return Logger.levels[this.name] ?? Logger.baseLevel; return Logger.levels[this.name] ?? Logger.baseLevel;
} }
extend = (namespace: string, showDiff = this.showDiff) => new Logger(`${this.name}:${namespace}`, showDiff) extend = (namespace: string, showDiff = this.showDiff) => new Logger(`${this.name}:${namespace}`, showDiff);
format: (format: any, ...param: any[]) => string = (...args) => { format: (format: any, ...param: any[]) => string = (...args) => {
if (args[0] instanceof Error) args[0] = args[0].stack || args[0].message; if (args[0] instanceof Error) args[0] = args[0].stack || args[0].message;
@@ -71,7 +71,7 @@ export class Logger {
Logger.lastTime = now; Logger.lastTime = now;
} }
return format(...args); return format(...args);
} };
} }
global.Hydro.Logger = Logger; global.Hydro.Logger = Logger;
+5 -5
View File
@@ -49,13 +49,13 @@ export async function add<T extends keyof DocType, K extends DocType[T]['docId']
docType: T, docId: K, docType: T, docId: K,
parentType?: DocType[T]['parentType'], parentId?: DocType[T]['parentId'], parentType?: DocType[T]['parentType'], parentId?: DocType[T]['parentId'],
args?: Partial<DocType[T]>, args?: Partial<DocType[T]>,
): Promise<K> ): Promise<K>;
export async function add<T extends keyof DocType>( export async function add<T extends keyof DocType>(
domainId: string, content: Content, owner: number, domainId: string, content: Content, owner: number,
docType: T, docId: null, docType: T, docId: null,
parentType?: DocType[T]['parentType'], parentId?: DocType[T]['parentId'], parentType?: DocType[T]['parentType'], parentId?: DocType[T]['parentId'],
args?: Partial<DocType[T]>, args?: Partial<DocType[T]>,
): Promise<ObjectID> ): Promise<ObjectID>;
export async function add( export async function add(
domainId: string, content: Content, owner: number, domainId: string, content: Content, owner: number,
docType: number, docId: DocID = null, docType: number, docId: DocID = null,
@@ -164,14 +164,14 @@ export function count<K extends keyof DocType>(
return coll.find({ ...query, docType, domainId }).count(); return coll.find({ ...query, docType, domainId }).count();
} }
export async function push<K extends keyof DocType, T extends keyof DocType[K]>( export async function push<K extends keyof DocType>(
domainId: string, docType: K, docId: DocType[K]['docId'], domainId: string, docType: K, docId: DocType[K]['docId'],
key: ArrayKeys<DocType[K]>, value: DocType[K][0], key: ArrayKeys<DocType[K]>, value: DocType[K][0],
): Promise<[DocType[K], ObjectID]> ): Promise<[DocType[K], ObjectID]>;
export async function push<K extends keyof DocType, T extends keyof DocType[K]>( export async function push<K extends keyof DocType, T extends keyof DocType[K]>(
domainId: string, docType: K, docId: DocType[K]['docId'], domainId: string, docType: K, docId: DocType[K]['docId'],
key: keyof DocType[K], content: string, owner: number, args?: DocType[K][T][0], key: keyof DocType[K], content: string, owner: number, args?: DocType[K][T][0],
): Promise<[DocType[K], ObjectID]> ): Promise<[DocType[K], ObjectID]>;
export async function push( export async function push(
domainId: string, docType: number, docId: DocID, key: string, domainId: string, docType: number, docId: DocID, key: string,
arg0: any, arg1?: any, arg2?: any, arg0: any, arg1?: any, arg2?: any,
+2 -2
View File
@@ -95,8 +95,8 @@ export function setUserRole(domainId: string, uid: number, role: string) {
return collUser.updateOne({ uid, domainId }, { $set: { role } }, { upsert: true }); return collUser.updateOne({ uid, domainId }, { $set: { role } }, { upsert: true });
} }
export async function getRoles(domainId: string): Promise<any[]> export async function getRoles(domainId: string): Promise<any[]>;
export async function getRoles(domain: DomainDoc): Promise<any[]> export async function getRoles(domain: DomainDoc): Promise<any[]>;
export async function getRoles(arg: string | DomainDoc) { export async function getRoles(arg: string | DomainDoc) {
let ddoc: DomainDoc; let ddoc: DomainDoc;
if (typeof arg === 'string') ddoc = await get(arg); if (typeof arg === 'string') ddoc = await get(arg);
+1 -1
View File
@@ -17,7 +17,7 @@ export interface Pdoc {
export namespace Pdoc { export namespace Pdoc {
export type Field = keyof Pdoc; export type Field = keyof Pdoc;
export const fields: Field[] = []; export const fields: Field[] = [];
type Getter = (docId?: number, pid?: string) => Partial<Pdoc> type Getter = (docId?: number, pid?: string) => Partial<Pdoc>;
const getters: Getter[] = []; const getters: Getter[] = [];
export function extend(getter: Getter) { export function extend(getter: Getter) {
getters.push(getter); getters.push(getter);
+10 -10
View File
@@ -7,37 +7,37 @@ import * as bus from '../service/bus';
const coll = db.collection('system'); const coll = db.collection('system');
const cache: Record<string, any> = {}; const cache: Record<string, any> = {};
export function get<K extends keyof SystemKeys>(key: K): SystemKeys[K] export function get<K extends keyof SystemKeys>(key: K): SystemKeys[K];
export function get(key: string): any export function get(key: string): any;
export function get(key: string): any { export function get(key: string): any {
return cache[key]; return cache[key];
} }
export function getMany< export function getMany<
A extends keyof SystemKeys, B extends keyof SystemKeys, A extends keyof SystemKeys, B extends keyof SystemKeys,
>(keys: [A, B]): [SystemKeys[A], SystemKeys[B]] >(keys: [A, B]): [SystemKeys[A], SystemKeys[B]];
export function getMany< export function getMany<
A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys, A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys,
>(keys: [A, B, C]): [SystemKeys[A], SystemKeys[B], SystemKeys[C]] >(keys: [A, B, C]): [SystemKeys[A], SystemKeys[B], SystemKeys[C]];
export function getMany< export function getMany<
A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys, A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys,
D extends keyof SystemKeys, D extends keyof SystemKeys,
>(keys: [A, B, C, D]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D]] >(keys: [A, B, C, D]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D]];
export function getMany< export function getMany<
A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys, A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys,
D extends keyof SystemKeys, E extends keyof SystemKeys, D extends keyof SystemKeys, E extends keyof SystemKeys,
>(keys: [A, B, C, D, E]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E]] >(keys: [A, B, C, D, E]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E]];
export function getMany< export function getMany<
A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys, A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys,
D extends keyof SystemKeys, E extends keyof SystemKeys, F extends keyof SystemKeys, D extends keyof SystemKeys, E extends keyof SystemKeys, F extends keyof SystemKeys,
>(keys: [A, B, C, D, E, F]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E], SystemKeys[F]] >(keys: [A, B, C, D, E, F]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E], SystemKeys[F]];
export function getMany(keys: (keyof SystemKeys)[]): any[] export function getMany(keys: (keyof SystemKeys)[]): any[];
export function getMany(keys: string[]): any[] { export function getMany(keys: string[]): any[] {
return keys.map((key) => cache[key]); return keys.map((key) => cache[key]);
} }
export async function set<K extends keyof SystemKeys>(_id: K, value: SystemKeys[K], boardcast?: boolean): Promise<SystemKeys[K]> export async function set<K extends keyof SystemKeys>(_id: K, value: SystemKeys[K], boardcast?: boolean): Promise<SystemKeys[K]>;
export async function set<K>(_id: string, value: K, boardcast?: boolean): Promise<K> export async function set<K>(_id: string, value: K, boardcast?: boolean): Promise<K>;
export async function set(_id: string, value: any, boardcast = true) { export async function set(_id: string, value: any, boardcast = true) {
if (boardcast) bus.boardcast('system/setting', { [_id]: value }); if (boardcast) bus.boardcast('system/setting', { [_id]: value });
const res = await coll.findOneAndUpdate( const res = await coll.findOneAndUpdate(
+1 -1
View File
@@ -28,4 +28,4 @@ export = function load() {
result = {}; result = {};
} }
return result; return result;
} };
+2 -2
View File
@@ -1,4 +1,4 @@
/* eslint-disable no-use-before-define */ /* eslint-disable @typescript-eslint/no-use-before-define */
import { ObjectID } from 'mongodb'; import { ObjectID } from 'mongodb';
import * as document from '../model/document'; import * as document from '../model/document';
import * as discussion from '../model/discussion'; import * as discussion from '../model/discussion';
@@ -62,7 +62,7 @@ async function _user(
} }
export async function run({ export async function run({
// eslint-disable-next-line no-shadow // eslint-disable-next-line @typescript-eslint/no-shadow
address = null, discuss = null, user = null, dryrun = true, address = null, discuss = null, user = null, dryrun = true,
}, report) { }, report) {
if (address) await _address(address, new Set(), new Set(), new Set(), dryrun, report); if (address) await _address(address, new Set(), new Set(), new Set(), dryrun, report);
+5 -5
View File
@@ -12,10 +12,10 @@ import paginate from '../lib/paginate';
export const description = 'Calculate rp of a domain, or all domains'; export const description = 'Calculate rp of a domain, or all domains';
type ND = NumericDictionary<number> type ND = NumericDictionary<number>;
async function runProblem(pdoc: Pdoc, udict: ND): Promise<void> async function runProblem(pdoc: Pdoc, udict: ND): Promise<void>;
async function runProblem(domainId: string, pid: number, udict: ND): Promise<void> async function runProblem(domainId: string, pid: number, udict: ND): Promise<void>;
async function runProblem(...arg: any[]) { async function runProblem(...arg: any[]) {
const pdoc: Pdoc = (typeof arg[0] === 'string') const pdoc: Pdoc = (typeof arg[0] === 'string')
? await problem.get(arg[0], arg[1], -1) ? await problem.get(arg[0], arg[1], -1)
@@ -50,10 +50,10 @@ async function runProblem(...arg: any[]) {
} }
} }
async function runContest(tdoc: Tdoc, udict: ND, report: Function): Promise<void> async function runContest(tdoc: Tdoc, udict: ND, report: Function): Promise<void>;
async function runContest( async function runContest(
domainId: string, tid: ObjectID, udict: ND, report: Function domainId: string, tid: ObjectID, udict: ND, report: Function
): Promise<void> ): Promise<void>;
async function runContest(...arg: any[]) { async function runContest(...arg: any[]) {
const start = new Date().getTime(); const start = new Date().getTime();
const tdoc: Tdoc = (typeof arg[0] === 'string') const tdoc: Tdoc = (typeof arg[0] === 'string')
+3 -3
View File
@@ -16,8 +16,8 @@ function isBailed(value: any) {
return value !== null && value !== false && value !== undefined; return value !== null && value !== false && value !== undefined;
} }
export type Disposable = () => void export type Disposable = () => void;
export type VoidReturn = Promise<any> | any export type VoidReturn = Promise<any> | any;
export interface EventMap { export interface EventMap {
'app/started': () => void 'app/started': () => void
@@ -53,7 +53,7 @@ export interface EventMap {
'document/add': (doc: any) => VoidReturn 'document/add': (doc: any) => VoidReturn
'document/set': <T extends keyof DocType> 'document/set': <T extends keyof DocType>
(domainId: string, docType: T, docId: DocType[T], $set: any, $unset: OnlyFieldsOfType<DocType[T], any, true | '' | 1>) => VoidReturn (domainId: string, docType: T, docId: DocType[T], $set: any, $unset: OnlyFieldsOfType<DocType[T], any, true | '' | 1>) => VoidReturn
'problem/edit': (doc: Pdoc) => VoidReturn 'problem/edit': (doc: Pdoc) => VoidReturn
'problem/list': (query: FilterQuery<Pdoc>, handler: any) => VoidReturn 'problem/list': (query: FilterQuery<Pdoc>, handler: any) => VoidReturn
+2 -3
View File
@@ -1,4 +1,3 @@
/* eslint-disable prefer-destructuring */
import assert from 'assert'; import assert from 'assert';
import { PassThrough } from 'stream'; import { PassThrough } from 'stream';
import { resolve } from 'path'; import { resolve } from 'path';
@@ -199,7 +198,7 @@ type DescriptorBuilder =
& ((name: string, type: Type, validate: null, convert: Converter) => MethodDecorator) & ((name: string, type: Type, validate: null, convert: Converter) => MethodDecorator)
& ((name: string, type: Type, validate?: Validator, convert?: Converter) => MethodDecorator) & ((name: string, type: Type, validate?: Validator, convert?: Converter) => MethodDecorator)
& ((name: string, type?: Type, isOptional?: boolean, validate?: Validator, convert?: Converter) => MethodDecorator) & ((name: string, type?: Type, isOptional?: boolean, validate?: Validator, convert?: Converter) => MethodDecorator)
& ((name: string, ...args: Array<Type | boolean | Validator | Converter>) => MethodDecorator) & ((name: string, ...args: Array<Type | boolean | Validator | Converter>) => MethodDecorator);
export const get: DescriptorBuilder = (name, ...args) => _descriptor(_buildParam(name, 'get', ...args)); export const get: DescriptorBuilder = (name, ...args) => _descriptor(_buildParam(name, 'get', ...args));
export const post: DescriptorBuilder = (name, ...args) => _descriptor(_buildParam(name, 'post', ...args)); export const post: DescriptorBuilder = (name, ...args) => _descriptor(_buildParam(name, 'post', ...args));
@@ -663,7 +662,7 @@ export class ConnectionHandler extends HandlerCommon {
params: Record<string, any>; params: Record<string, any>;
headers: Record<string, string>; headers: Record<string, string>;
ip: string; ip: string;
} };
constructor(conn: sockjs.Connection) { constructor(conn: sockjs.Connection) {
super(); super();
+3 -3
View File
@@ -4,10 +4,10 @@ export type NumberKeys<O> = {
export type ArrayKeys<O, P = any> = { export type ArrayKeys<O, P = any> = {
[K in keyof O]: P[] extends O[K] ? K : never [K in keyof O]: P[] extends O[K] ? K : never
}[keyof O] }[keyof O];
export type Value<O, V = ''> = { export type Value<O, V = ''> = {
[K in keyof O]: V [K in keyof O]: V
} };
export type Projection<O> = (string & keyof O)[] export type Projection<O> = (string & keyof O)[];
+1 -1
View File
@@ -1,4 +1,4 @@
/* eslint-disable no-shadow */ /* eslint-disable @typescript-eslint/no-shadow */
// @ts-nocheck // @ts-nocheck
import cluster from 'cluster'; import cluster from 'cluster';
import { import {
+1 -1
View File
@@ -7,7 +7,7 @@
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"dependencies": { "dependencies": {
"adm-zip": "^0.5.1", "adm-zip": "^0.5.2",
"decode-html": "^2.0.0", "decode-html": "^2.0.0",
"fs-extra": "^9.1.0" "fs-extra": "^9.1.0"
}, },
+1 -1
View File
@@ -11,7 +11,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/js-yaml": "^4.0.0", "@types/js-yaml": "^4.0.0",
"@types/mongodb": "^3.5.33" "@types/mongodb": "^3.6.3"
}, },
"peerDependencies": { "peerDependencies": {
"hydrooj": "2.14.x" "hydrooj": "2.14.x"