mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
workspace: update eslint config
This commit is contained in:
1 parent
4e4f6688bc
commit
3a3983d38d
29 files changed
+169
-166
No files matched your search
@@ -10,7 +10,6 @@ import { argv } from 'yargs';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
const logger = new Logger('setup');
|
||||
|
||||
const listenPort = argv.port || 8888;
|
||||
|
||||
async function get(ctx: Context) {
|
||||
@@ -81,7 +80,6 @@ async function get(ctx: Context) {
|
||||
async function post(ctx: Context) {
|
||||
const {
|
||||
host, port, name, username, password,
|
||||
// @ts-ignore
|
||||
} = ctx.request.body;
|
||||
let mongourl = 'mongodb://';
|
||||
if (username) mongourl += `${username}:${password}@`;
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { Readable, Writable } from 'stream';
|
||||
import type { ObjectID } from 'mongodb';
|
||||
import type fs from 'fs';
|
||||
import type { Dictionary, NumericDictionary } from 'lodash';
|
||||
import type * as Koa from 'koa';
|
||||
import type { Pdoc } from './model/problem';
|
||||
|
||||
type document = typeof import('./model/document');
|
||||
@@ -159,7 +160,7 @@ export interface SampleContentNode {
|
||||
payload: [string, string],
|
||||
}
|
||||
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' {
|
||||
interface Pdoc {
|
||||
@@ -589,3 +590,10 @@ declare global {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'koa' {
|
||||
interface Request extends Koa.BaseRequest {
|
||||
body?: any;
|
||||
files?: import('formidable').Files;
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ async function _download(url: string, path: string, retry: number) {
|
||||
return path;
|
||||
}
|
||||
|
||||
function download(url: string): SuperAgentRequest
|
||||
function download(url: string): SuperAgentRequest;
|
||||
function download(url: string, path?: string, retry = 3) {
|
||||
if (path) return _download(url, path, retry);
|
||||
return superagent.get(url).retry(retry);
|
||||
|
||||
@@ -18,11 +18,11 @@ export async function get() {
|
||||
const cpu = `${Cpu.manufacturer} ${Cpu.brand}`;
|
||||
const memory = `${size(Memory.active)}/${size(Memory.total)}`;
|
||||
const osinfo = `${OsInfo.distro} ${OsInfo.release} ${OsInfo.codename} ${OsInfo.kernel} ${OsInfo.arch}`;
|
||||
const load = `${CurrentLoad.avgload}`;
|
||||
const load = `${CurrentLoad.avgLoad}`;
|
||||
const flags = CpuFlags;
|
||||
let battery;
|
||||
if (!Battery.hasbattery) battery = 'No battery';
|
||||
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`;
|
||||
if (!Battery.hasBattery) battery = 'No battery';
|
||||
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`;
|
||||
const mid = OsInfo.serial;
|
||||
cache.cpu = cpu;
|
||||
cache.osinfo = osinfo;
|
||||
@@ -44,10 +44,10 @@ export async function update(): Promise<[string, any, any]> {
|
||||
mid, cpu, osinfo, flags,
|
||||
} = cache;
|
||||
const memory = `${size(Memory.active)}/${size(Memory.total)}`;
|
||||
const load = `${CurrentLoad.avgload}`;
|
||||
const load = `${CurrentLoad.avgLoad}`;
|
||||
let battery;
|
||||
if (!Battery.hasbattery) battery = 'No battery';
|
||||
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`;
|
||||
if (!Battery.hasBattery) battery = 'No battery';
|
||||
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`;
|
||||
return [
|
||||
mid,
|
||||
{
|
||||
|
||||
@@ -3,22 +3,22 @@ import { argv } from 'yargs';
|
||||
import { Time } from './utils';
|
||||
|
||||
const instances: Record<string, Logger> = {};
|
||||
type LogFunction = (format: any, ...param: any[]) => void
|
||||
type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug'
|
||||
type LogFunction = (format: any, ...param: any[]) => void;
|
||||
type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug';
|
||||
export interface Logger extends Record<LogType, LogFunction> { }
|
||||
export class Logger {
|
||||
static readonly SUCCESS = 1
|
||||
static readonly ERROR = 1
|
||||
static readonly INFO = 2
|
||||
static readonly WARN = 2
|
||||
static readonly DEBUG = 3
|
||||
static baseLevel = argv.debug ? 3 : 2
|
||||
static showDiff = false
|
||||
static levels: Record<string, number> = {}
|
||||
static lastTime = 0
|
||||
static readonly SUCCESS = 1;
|
||||
static readonly ERROR = 1;
|
||||
static readonly INFO = 2;
|
||||
static readonly WARN = 2;
|
||||
static readonly DEBUG = 3;
|
||||
static baseLevel = argv.debug ? 3 : 2;
|
||||
static showDiff = false;
|
||||
static levels: Record<string, number> = {};
|
||||
static lastTime = 0;
|
||||
static formatters: Record<string, (this: Logger, value: any) => string> = {
|
||||
o: (value) => inspect(value).replace(/\s*\n\s*/g, ' '),
|
||||
}
|
||||
};
|
||||
|
||||
constructor(public name: string, private showDiff = false) {
|
||||
if (name in instances) return instances[name];
|
||||
@@ -48,7 +48,7 @@ export class Logger {
|
||||
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) => {
|
||||
if (args[0] instanceof Error) args[0] = args[0].stack || args[0].message;
|
||||
@@ -71,7 +71,7 @@ export class Logger {
|
||||
Logger.lastTime = now;
|
||||
}
|
||||
return format(...args);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
global.Hydro.Logger = Logger;
|
||||
|
||||
@@ -49,13 +49,13 @@ export async function add<T extends keyof DocType, K extends DocType[T]['docId']
|
||||
docType: T, docId: K,
|
||||
parentType?: DocType[T]['parentType'], parentId?: DocType[T]['parentId'],
|
||||
args?: Partial<DocType[T]>,
|
||||
): Promise<K>
|
||||
): Promise<K>;
|
||||
export async function add<T extends keyof DocType>(
|
||||
domainId: string, content: Content, owner: number,
|
||||
docType: T, docId: null,
|
||||
parentType?: DocType[T]['parentType'], parentId?: DocType[T]['parentId'],
|
||||
args?: Partial<DocType[T]>,
|
||||
): Promise<ObjectID>
|
||||
): Promise<ObjectID>;
|
||||
export async function add(
|
||||
domainId: string, content: Content, owner: number,
|
||||
docType: number, docId: DocID = null,
|
||||
@@ -164,14 +164,14 @@ export function count<K extends keyof DocType>(
|
||||
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'],
|
||||
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]>(
|
||||
domainId: string, docType: K, docId: DocType[K]['docId'],
|
||||
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(
|
||||
domainId: string, docType: number, docId: DocID, key: string,
|
||||
arg0: any, arg1?: any, arg2?: any,
|
||||
|
||||
@@ -95,8 +95,8 @@ export function setUserRole(domainId: string, uid: number, role: string) {
|
||||
return collUser.updateOne({ uid, domainId }, { $set: { role } }, { upsert: true });
|
||||
}
|
||||
|
||||
export async function getRoles(domainId: string): Promise<any[]>
|
||||
export async function getRoles(domain: DomainDoc): Promise<any[]>
|
||||
export async function getRoles(domainId: string): Promise<any[]>;
|
||||
export async function getRoles(domain: DomainDoc): Promise<any[]>;
|
||||
export async function getRoles(arg: string | DomainDoc) {
|
||||
let ddoc: DomainDoc;
|
||||
if (typeof arg === 'string') ddoc = await get(arg);
|
||||
|
||||
@@ -17,7 +17,7 @@ export interface Pdoc {
|
||||
export namespace Pdoc {
|
||||
export type Field = keyof Pdoc;
|
||||
export const fields: Field[] = [];
|
||||
type Getter = (docId?: number, pid?: string) => Partial<Pdoc>
|
||||
type Getter = (docId?: number, pid?: string) => Partial<Pdoc>;
|
||||
const getters: Getter[] = [];
|
||||
export function extend(getter: Getter) {
|
||||
getters.push(getter);
|
||||
|
||||
@@ -7,37 +7,37 @@ import * as bus from '../service/bus';
|
||||
const coll = db.collection('system');
|
||||
const cache: Record<string, any> = {};
|
||||
|
||||
export function get<K extends keyof SystemKeys>(key: K): SystemKeys[K]
|
||||
export function get(key: string): any
|
||||
export function get<K extends keyof SystemKeys>(key: K): SystemKeys[K];
|
||||
export function get(key: string): any;
|
||||
export function get(key: string): any {
|
||||
return cache[key];
|
||||
}
|
||||
|
||||
export function getMany<
|
||||
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<
|
||||
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<
|
||||
A extends keyof SystemKeys, B extends keyof SystemKeys, C 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<
|
||||
A extends keyof SystemKeys, B extends keyof SystemKeys, C 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<
|
||||
A extends keyof SystemKeys, B extends keyof SystemKeys, C 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]]
|
||||
export function getMany(keys: (keyof SystemKeys)[]): any[]
|
||||
>(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: string[]): any[] {
|
||||
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>(_id: string, value: K, boardcast?: boolean): Promise<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(_id: string, value: any, boardcast = true) {
|
||||
if (boardcast) bus.boardcast('system/setting', { [_id]: value });
|
||||
const res = await coll.findOneAndUpdate(
|
||||
|
||||
@@ -28,4 +28,4 @@ export = function load() {
|
||||
result = {};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable no-use-before-define */
|
||||
/* eslint-disable @typescript-eslint/no-use-before-define */
|
||||
import { ObjectID } from 'mongodb';
|
||||
import * as document from '../model/document';
|
||||
import * as discussion from '../model/discussion';
|
||||
@@ -62,7 +62,7 @@ async function _user(
|
||||
}
|
||||
|
||||
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,
|
||||
}, report) {
|
||||
if (address) await _address(address, new Set(), new Set(), new Set(), dryrun, report);
|
||||
|
||||
@@ -12,10 +12,10 @@ import paginate from '../lib/paginate';
|
||||
|
||||
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(domainId: string, pid: number, 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(...arg: any[]) {
|
||||
const pdoc: Pdoc = (typeof arg[0] === 'string')
|
||||
? 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(
|
||||
domainId: string, tid: ObjectID, udict: ND, report: Function
|
||||
): Promise<void>
|
||||
): Promise<void>;
|
||||
async function runContest(...arg: any[]) {
|
||||
const start = new Date().getTime();
|
||||
const tdoc: Tdoc = (typeof arg[0] === 'string')
|
||||
|
||||
@@ -16,8 +16,8 @@ function isBailed(value: any) {
|
||||
return value !== null && value !== false && value !== undefined;
|
||||
}
|
||||
|
||||
export type Disposable = () => void
|
||||
export type VoidReturn = Promise<any> | any
|
||||
export type Disposable = () => void;
|
||||
export type VoidReturn = Promise<any> | any;
|
||||
|
||||
export interface EventMap {
|
||||
'app/started': () => void
|
||||
@@ -53,7 +53,7 @@ export interface EventMap {
|
||||
|
||||
'document/add': (doc: any) => VoidReturn
|
||||
'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/list': (query: FilterQuery<Pdoc>, handler: any) => VoidReturn
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable prefer-destructuring */
|
||||
import assert from 'assert';
|
||||
import { PassThrough } from 'stream';
|
||||
import { resolve } from 'path';
|
||||
@@ -199,7 +198,7 @@ type DescriptorBuilder =
|
||||
& ((name: string, type: Type, validate: null, 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, ...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 post: DescriptorBuilder = (name, ...args) => _descriptor(_buildParam(name, 'post', ...args));
|
||||
@@ -663,7 +662,7 @@ export class ConnectionHandler extends HandlerCommon {
|
||||
params: Record<string, any>;
|
||||
headers: Record<string, string>;
|
||||
ip: string;
|
||||
}
|
||||
};
|
||||
|
||||
constructor(conn: sockjs.Connection) {
|
||||
super();
|
||||
|
||||
@@ -4,10 +4,10 @@ export type NumberKeys<O> = {
|
||||
|
||||
export type ArrayKeys<O, P = any> = {
|
||||
[K in keyof O]: P[] extends O[K] ? K : never
|
||||
}[keyof O]
|
||||
}[keyof O];
|
||||
|
||||
export type Value<O, V = ''> = {
|
||||
[K in keyof O]: V
|
||||
}
|
||||
};
|
||||
|
||||
export type Projection<O> = (string & keyof O)[]
|
||||
export type Projection<O> = (string & keyof O)[];
|
||||
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable no-shadow */
|
||||
/* eslint-disable @typescript-eslint/no-shadow */
|
||||
// @ts-nocheck
|
||||
import cluster from 'cluster';
|
||||
import {
|
||||
|
||||
Reference in new issue
Block a user