From aeb9d4cf500022fca82f0af490390fd184caad3a Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 4 Mar 2025 09:55:05 +0800 Subject: [PATCH] bus: remove legacy `import *` usage support --- packages/hydrooj/src/handler/judge.ts | 2 +- packages/hydrooj/src/model/contest.ts | 2 +- packages/hydrooj/src/model/discussion.ts | 2 +- packages/hydrooj/src/model/document.ts | 2 +- packages/hydrooj/src/model/domain.ts | 2 +- packages/hydrooj/src/model/message.ts | 2 +- packages/hydrooj/src/model/oplog.ts | 2 +- packages/hydrooj/src/model/problem.ts | 2 +- packages/hydrooj/src/model/solution.ts | 2 +- packages/hydrooj/src/model/system.ts | 2 +- packages/hydrooj/src/model/task.ts | 2 +- packages/hydrooj/src/model/token.ts | 2 +- packages/hydrooj/src/model/user.ts | 2 +- packages/hydrooj/src/service/bus.ts | 8 -------- packages/hydrooj/src/service/db.ts | 2 +- packages/hydrooj/src/service/monitor.ts | 2 +- packages/hydrooj/src/ui.ts | 2 +- 17 files changed, 16 insertions(+), 24 deletions(-) diff --git a/packages/hydrooj/src/handler/judge.ts b/packages/hydrooj/src/handler/judge.ts index 15ca4c26b..967f374c1 100644 --- a/packages/hydrooj/src/handler/judge.ts +++ b/packages/hydrooj/src/handler/judge.ts @@ -23,7 +23,7 @@ import storage from '../model/storage'; import * as system from '../model/system'; import task, { Consumer } from '../model/task'; import user from '../model/user'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import { updateJudge } from '../service/monitor'; import { ConnectionHandler, Handler, post, subscribe, Types, diff --git a/packages/hydrooj/src/model/contest.ts b/packages/hydrooj/src/model/contest.ts index 8679df0d5..78110af95 100644 --- a/packages/hydrooj/src/model/contest.ts +++ b/packages/hydrooj/src/model/contest.ts @@ -9,7 +9,7 @@ import { BaseUserDict, ContestRule, ContestRules, ProblemDict, RecordDoc, ScoreboardConfig, ScoreboardNode, ScoreboardRow, SubtaskResult, Tdoc, } from '../interface'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import type { Handler } from '../service/server'; import { Optional } from '../typeutils'; diff --git a/packages/hydrooj/src/model/discussion.ts b/packages/hydrooj/src/model/discussion.ts index 03f93855e..f62e10b06 100644 --- a/packages/hydrooj/src/model/discussion.ts +++ b/packages/hydrooj/src/model/discussion.ts @@ -5,7 +5,7 @@ import { DiscussionNodeNotFoundError, DocumentNotFoundError } from '../error'; import { DiscussionHistoryDoc, DiscussionReplyDoc, DiscussionTailReplyDoc, Document, } from '../interface'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import { NumberKeys } from '../typeutils'; import { buildProjection } from '../utils'; diff --git a/packages/hydrooj/src/model/document.ts b/packages/hydrooj/src/model/document.ts index f2f72ef5c..f252481c6 100644 --- a/packages/hydrooj/src/model/document.ts +++ b/packages/hydrooj/src/model/document.ts @@ -9,7 +9,7 @@ import { DiscussionReplyDoc, ProblemDoc, ProblemStatusDoc, Tdoc, TrainingDoc, } from '../interface'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import { ArrayKeys, MaybeArray, NumberKeys, Projection } from '../typeutils'; import { buildProjection } from '../utils'; diff --git a/packages/hydrooj/src/model/domain.ts b/packages/hydrooj/src/model/domain.ts index 5ec4f1b68..a11f1afa4 100644 --- a/packages/hydrooj/src/model/domain.ts +++ b/packages/hydrooj/src/model/domain.ts @@ -2,7 +2,7 @@ import { Dictionary, escapeRegExp } from 'lodash'; import { LRUCache } from 'lru-cache'; import { Filter } from 'mongodb'; import { DomainDoc } from '../interface'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import { MaybeArray, NumberKeys } from '../typeutils'; import { ArgMethod } from '../utils'; diff --git a/packages/hydrooj/src/model/message.ts b/packages/hydrooj/src/model/message.ts index 50b5a85b7..83e638316 100644 --- a/packages/hydrooj/src/model/message.ts +++ b/packages/hydrooj/src/model/message.ts @@ -1,6 +1,6 @@ import { Filter, ObjectId } from 'mongodb'; import { MessageDoc } from '../interface'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import { ArgMethod } from '../utils'; import { PRIV } from './builtin'; diff --git a/packages/hydrooj/src/model/oplog.ts b/packages/hydrooj/src/model/oplog.ts index 86d8187f9..7dd10aaa5 100644 --- a/packages/hydrooj/src/model/oplog.ts +++ b/packages/hydrooj/src/model/oplog.ts @@ -1,7 +1,7 @@ import { cloneDeep } from 'lodash'; import { ObjectId } from 'mongodb'; import { OplogDoc } from '../interface'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import type { Handler } from '../service/server'; diff --git a/packages/hydrooj/src/model/problem.ts b/packages/hydrooj/src/model/problem.ts index 1e0c8a72d..ff58db2c7 100644 --- a/packages/hydrooj/src/model/problem.ts +++ b/packages/hydrooj/src/model/problem.ts @@ -16,7 +16,7 @@ import type { Document, ProblemDict, ProblemStatusDoc, User, } from '../interface'; import { parseConfig } from '../lib/testdataConfig'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import { ArrayKeys, MaybeArray, NumberKeys, Projection, diff --git a/packages/hydrooj/src/model/solution.ts b/packages/hydrooj/src/model/solution.ts index 53f1b04e8..fee847c7a 100644 --- a/packages/hydrooj/src/model/solution.ts +++ b/packages/hydrooj/src/model/solution.ts @@ -1,6 +1,6 @@ import { ObjectId } from 'mongodb'; import { SolutionNotFoundError } from '../error'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import * as document from './document'; class SolutionModel { diff --git a/packages/hydrooj/src/model/system.ts b/packages/hydrooj/src/model/system.ts index 110266151..8eaaa6be9 100644 --- a/packages/hydrooj/src/model/system.ts +++ b/packages/hydrooj/src/model/system.ts @@ -1,5 +1,5 @@ import { SystemKeys } from '../interface'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import { NumberKeys } from '../typeutils'; import { SYSTEM_SETTINGS } from './setting'; diff --git a/packages/hydrooj/src/model/task.ts b/packages/hydrooj/src/model/task.ts index 57831b991..1ab22c4c5 100644 --- a/packages/hydrooj/src/model/task.ts +++ b/packages/hydrooj/src/model/task.ts @@ -6,7 +6,7 @@ import { sleep } from '@hydrooj/utils/lib/utils'; import { Context } from '../context'; import { EventDoc, Task } from '../interface'; import { Logger } from '../logger'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; const logger = new Logger('model/task'); diff --git a/packages/hydrooj/src/model/token.ts b/packages/hydrooj/src/model/token.ts index 21dade6aa..9dd9b8841 100644 --- a/packages/hydrooj/src/model/token.ts +++ b/packages/hydrooj/src/model/token.ts @@ -1,6 +1,6 @@ import { Filter } from 'mongodb'; import { TokenDoc } from '../interface'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import { ArgMethod } from '../utils'; diff --git a/packages/hydrooj/src/model/user.ts b/packages/hydrooj/src/model/user.ts index cfb4226b5..785ec31a6 100644 --- a/packages/hydrooj/src/model/user.ts +++ b/packages/hydrooj/src/model/user.ts @@ -9,7 +9,7 @@ import { } from '../interface'; import avatar from '../lib/avatar'; import pwhash from '../lib/hash.hydro'; -import * as bus from '../service/bus'; +import bus from '../service/bus'; import db from '../service/db'; import { Value } from '../typeutils'; import { ArgMethod, buildProjection } from '../utils'; diff --git a/packages/hydrooj/src/service/bus.ts b/packages/hydrooj/src/service/bus.ts index 22c0576dc..a3ef6081a 100644 --- a/packages/hydrooj/src/service/bus.ts +++ b/packages/hydrooj/src/service/bus.ts @@ -114,14 +114,6 @@ export function apply(ctx: Context) { } export default app; -export const on = (a, b, c?) => app.on(a, b, c); -export const once = (a, b, c?) => app.once(a, b, c); -export const parallel = app.parallel.bind(app); -export const emit = app.parallel.bind(app); -export const bail = app.bail.bind(app); -// For backward compatibility -export const serial: any = app.parallel.bind(app); -export const broadcast = app.broadcast.bind(app); global.Hydro.service.bus = app as any; global.bus = app; diff --git a/packages/hydrooj/src/service/db.ts b/packages/hydrooj/src/service/db.ts index 7adfe951b..701b7375e 100644 --- a/packages/hydrooj/src/service/db.ts +++ b/packages/hydrooj/src/service/db.ts @@ -7,7 +7,7 @@ import { Time } from '@hydrooj/utils'; import { ValidationError } from '../error'; import { Logger } from '../logger'; import { load } from '../options'; -import * as bus from './bus'; +import bus from './bus'; const logger = new Logger('mongo'); export interface Collections { } diff --git a/packages/hydrooj/src/service/monitor.ts b/packages/hydrooj/src/service/monitor.ts index 9e1c016ce..770dca4a4 100644 --- a/packages/hydrooj/src/service/monitor.ts +++ b/packages/hydrooj/src/service/monitor.ts @@ -4,7 +4,7 @@ import type { StatusUpdate } from '@hydrooj/utils/lib/sysinfo'; import * as sysinfo from '@hydrooj/utils/lib/sysinfo'; import { Context } from '../context'; import { Logger } from '../logger'; -import * as bus from './bus'; +import bus from './bus'; import db from './db'; const coll = db.collection('status'); diff --git a/packages/hydrooj/src/ui.ts b/packages/hydrooj/src/ui.ts index 452101960..ffd0e3a53 100644 --- a/packages/hydrooj/src/ui.ts +++ b/packages/hydrooj/src/ui.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-shadow */ import { Logger } from './logger'; -import * as bus from './service/bus'; +import bus from './service/bus'; let terminating = false; async function terminate() {