diff --git a/build/prepare.js b/build/prepare.js index 655a41aa1..60cc902af 100644 --- a/build/prepare.js +++ b/build/prepare.js @@ -16,7 +16,7 @@ const withoutTypes = (data) => ({ /** @type {import('typescript/lib/typescript').CompilerOptions} */ const compilerOptionsBase = { target: 'es2022', - lib: ['es2022'], + lib: ['esnext'], module: 'preserve', esModuleInterop: true, moduleResolution: 'bundler', @@ -106,7 +106,7 @@ const UIConfig = { outDir: path.join(baseOutDir, 'ui'), useDefineForClassFields: true, - lib: ['es2022', 'DOM', 'DOM.Iterable'], + lib: ['esnext', 'DOM', 'DOM.Iterable'], /* Bundler mode */ moduleResolution: 'bundler', @@ -143,7 +143,7 @@ const UINextConfig = { noImplicitAny: false, useDefineForClassFields: true, - lib: ['es2022', 'DOM', 'DOM.Iterable'], + lib: ['esnext', 'DOM', 'DOM.Iterable'], /* Bundler mode */ moduleResolution: 'bundler', diff --git a/framework/utils/lib/common.ts b/framework/utils/lib/common.ts index 676db5dbe..bdf6f6d6f 100644 --- a/framework/utils/lib/common.ts +++ b/framework/utils/lib/common.ts @@ -7,11 +7,6 @@ declare global { interface Math { sum: (...args: Array) => number; } - interface SetConstructor { - isSuperset: (set: Set, subset: Set | Array) => boolean; - intersection: (setA: Set | Array, setB: Set | Array) => Set; - union: (setA: Set | Array, setB: Set | Array) => Set; - } } const defaultDict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; @@ -21,10 +16,6 @@ export function randomstring(digit = 32, dict = defaultDict) { for (let i = 1; i <= digit; i++) str += dict[Math.floor(Math.random() * dict.length)]; return str; } -try { - // @ts-ignore - String.random = randomstring; -} catch (e) { } // Cannot add property random, object is not extensible String.prototype.format ||= function formatStr(...args) { let result = this; @@ -68,11 +59,6 @@ export function diffArray(a, b) { return false; } -try { - // @ts-ignore - Array.isDiff = diffArray; -} catch (e) { } // Cannot add property isDiff, object is not extensible - export function formatDate(date: Date, fmt = '%Y-%m-%d %H:%M:%S') { let m = (date.getMonth() + 1).toString(); if (m.length < 2) m = `0${m}`; @@ -105,6 +91,9 @@ Math.sum = function sum(...args) { return s; }; +// TODO: remove these + +// @ts-ignore Set.isSuperset = function isSuperset(set, subset) { for (const elem of subset) { if (!set.has(elem)) return false; @@ -112,12 +101,14 @@ Set.isSuperset = function isSuperset(set, subset) { return true; }; +// @ts-ignore Set.union = function Union(setA: Set | Array, setB: Set | Array) { const union = new Set(setA); for (const elem of setB) union.add(elem); return union; }; +// @ts-ignore Set.intersection = function Intersection(A: Set | Array = [], B: Set | Array = []) { const intersection = new Set(); if (A instanceof Array) A = new Set(A); diff --git a/packages/hydrojudge/src/judge/objective.ts b/packages/hydrojudge/src/judge/objective.ts index 977c904a6..896abca5b 100644 --- a/packages/hydrojudge/src/judge/objective.ts +++ b/packages/hydrojudge/src/judge/objective.ts @@ -66,8 +66,8 @@ export async function judge({ if (stdAns instanceof Array) { const stdSet = new Set(stdAns); const ans = new Set(answers[key] instanceof Array ? answers[key] : [answers[key]]); - if (stdAns.length === ans.size && Set.isSuperset(stdSet, ans)) report(STATUS.STATUS_ACCEPTED, fullScore, 'Correct'); - else if (ans.size && Set.isSuperset(stdSet, ans)) report(STATUS.STATUS_WRONG_ANSWER, Math.floor(fullScore / 2), 'Partially Correct'); + if (stdAns.length === ans.size && stdSet.isSupersetOf(ans)) report(STATUS.STATUS_ACCEPTED, fullScore, 'Correct'); + else if (ans.size && stdSet.isSupersetOf(ans)) report(STATUS.STATUS_WRONG_ANSWER, Math.floor(fullScore / 2), 'Partially Correct'); else report(STATUS.STATUS_WRONG_ANSWER, 0, 'Incorrect'); } else if (stdAns.toString() === usrAns) report(STATUS.STATUS_ACCEPTED, fullScore, 'Correct'); else report(STATUS.STATUS_WRONG_ANSWER, 0, 'Incorrect'); diff --git a/packages/hydrooj/src/handler/contest.ts b/packages/hydrooj/src/handler/contest.ts index de214ce01..72b4c4da2 100644 --- a/packages/hydrooj/src/handler/contest.ts +++ b/packages/hydrooj/src/handler/contest.ts @@ -88,7 +88,7 @@ export class ContestDetailBaseHandler extends Handler { ]); if (this.tdoc.assign?.length && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST)) { const groups = await user.listGroup(domainId, this.user._id); - if (!Set.intersection(this.tdoc.assign, groups.map((i) => i.name)).size) { + if (!new Set(this.tdoc.assign).intersection(new Set(groups.map((i) => i.name))).size) { throw new NotAssignedError('contest', tid); } } diff --git a/packages/hydrooj/src/handler/domain.ts b/packages/hydrooj/src/handler/domain.ts index f29170d50..a33aaa226 100644 --- a/packages/hydrooj/src/handler/domain.ts +++ b/packages/hydrooj/src/handler/domain.ts @@ -261,7 +261,7 @@ class DomainRoleHandler extends ManageHandler { @requireSudo @param('roles', Types.ArrayOf(Types.Role)) async postDelete(domainId: string, roles: string[]) { - if (Set.intersection(roles, ['root', 'default', 'guest']).size > 0) { + if (new Set(roles).intersection(new Set(['root', 'default', 'guest'])).size > 0) { throw new ValidationError('role', null, 'You cannot delete root, default or guest roles'); } await Promise.all([ diff --git a/packages/hydrooj/src/handler/homework.ts b/packages/hydrooj/src/handler/homework.ts index fdd553440..dc1428215 100644 --- a/packages/hydrooj/src/handler/homework.ts +++ b/packages/hydrooj/src/handler/homework.ts @@ -84,7 +84,7 @@ class HomeworkDetailHandler extends Handler { this.tdoc = await contest.get(domainId, tid); if (this.tdoc.rule !== 'homework') throw new ContestNotFoundError(domainId, tid); if (this.tdoc.assign?.length && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_HOMEWORK)) { - if (!Set.intersection(this.tdoc.assign, this.user.group).size) { + if (!new Set(this.tdoc.assign).intersection(new Set(this.user.group)).size) { throw new NotAssignedError('homework', this.tdoc.docId); } } diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index f2fcfdbf9..8adc71bcc 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -418,7 +418,7 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler { contest.getRelated(this.args.domainId, this.pdoc.docId), contest.getRelated(this.args.domainId, this.pdoc.docId, 'homework'), ])).map((tdocs) => tdocs.filter((tdoc) => - this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST) || !tdoc.assign?.length || Set.intersection(tdoc.assign, this.user.group).size, + this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST) || !tdoc.assign?.length || new Set(tdoc.assign).intersection(new Set(this.user.group)).size, )); } } diff --git a/packages/hydrooj/src/handler/training.ts b/packages/hydrooj/src/handler/training.ts index a6c7f06cd..630d52214 100644 --- a/packages/hydrooj/src/handler/training.ts +++ b/packages/hydrooj/src/handler/training.ts @@ -138,7 +138,7 @@ class TrainingDetailHandler extends Handler { for (const node of tdoc.dag) { ndict[node._id] = node; const totalCount = node.pids.length; - const doneCount = Set.intersection(node.pids, donePids).size; + const doneCount = new Set(node.pids).intersection(new Set(donePids)).size; const nsdoc = { progress: totalCount ? Math.floor(100 * (doneCount / totalCount)) : 100, isDone: training.isDone(node, doneNids, donePids), diff --git a/packages/hydrooj/src/model/discussion.ts b/packages/hydrooj/src/model/discussion.ts index 8e2221f06..aec554d80 100644 --- a/packages/hydrooj/src/model/discussion.ts +++ b/packages/hydrooj/src/model/discussion.ts @@ -313,7 +313,7 @@ export async function getListVnodes(domainId: string, ddocs: any, getHidden = fa const vnode = await getVnode(domainId, ddoc.parentType, ddoc.parentId.toString()); res[ddoc.parentType] ||= {}; if (!getHidden && vnode.hidden) return; - if (vnode.assign?.length && Set.intersection(vnode.assign, assign).size) return; + if (vnode.assign?.length && new Set(vnode.assign).intersection(new Set(assign)).size) return; res[ddoc.parentType][ddoc.parentId] = vnode; } await Promise.all(ddocs.map((ddoc) => task(ddoc))); @@ -325,7 +325,7 @@ export function checkVNodeVisibility(type: number, vnode: any, user: User) { if (vnode.hidden && !user.own(vnode) && !user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) return false; } if ([document.TYPE_CONTEST, document.TYPE_TRAINING].includes(type as any)) { - if (!user.own(vnode) && vnode.assign?.length && !Set.intersection(vnode.assign, user.group).size) return false; + if (!user.own(vnode) && vnode.assign?.length && !new Set(vnode.assign).intersection(new Set(user.group)).size) return false; } return true; } diff --git a/packages/hydrooj/src/model/training.ts b/packages/hydrooj/src/model/training.ts index b01e70bd8..4f940f0e0 100644 --- a/packages/hydrooj/src/model/training.ts +++ b/packages/hydrooj/src/model/training.ts @@ -63,30 +63,24 @@ export function getPids(dag: TrainingNode[]) { } export function isDone(node: TrainingNode, doneNids: Set | number[], donePids: Set | number[]) { - return (Set.isSuperset(new Set(doneNids), new Set(node.requireNids)) - && Set.isSuperset(new Set(donePids), new Set(node.pids))); + return new Set(doneNids).isSupersetOf(new Set(node.requireNids)) + && new Set(donePids).isSupersetOf(new Set(node.pids)); } export function isProgress(node: TrainingNode, doneNids: Set | number[], donePids: Set | number[], progPids: Set | number[]) { - return (Set.isSuperset(new Set(doneNids), new Set(node.requireNids)) - && !Set.isSuperset(new Set(donePids), new Set(node.pids)) - && Set.intersection( - Set.union(new Set(donePids), new Set(progPids)), - new Set(node.pids), - ).size); + return new Set(doneNids).isSupersetOf(new Set(node.requireNids)) + && !new Set(donePids).isSupersetOf(new Set(node.pids)) + && new Set(donePids).union(new Set(progPids)).intersection(new Set(node.pids)).size; } export function isOpen(node: TrainingNode, doneNids: Set | number[], donePids: Set | number[], progPids: Set | number[]) { - return (Set.isSuperset(new Set(doneNids), new Set(node.requireNids)) - && !Set.isSuperset(new Set(donePids), new Set(node.pids)) - && !Set.intersection( - Set.union(new Set(donePids), new Set(progPids)), - new Set(node.pids), - ).size); + return new Set(doneNids).isSupersetOf(new Set(node.requireNids)) + && !new Set(donePids).isSupersetOf(new Set(node.pids)) + && !new Set(donePids).union(new Set(progPids)).intersection(new Set(node.pids)).size; } export const isInvalid = (node: TrainingNode, doneNids: Set | number[]) => - !Set.isSuperset(new Set(doneNids), new Set(node.requireNids)); + !new Set(doneNids).isSupersetOf(new Set(node.requireNids)); export async function count(domainId: string, query: Filter) { return await document.count(domainId, document.TYPE_TRAINING, query); diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index 38b42aebf..2cc32996a 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -132,7 +132,7 @@ "html-to-text": "^9.0.5", "js-yaml": "^4.1.1", "jsesc": "^3.1.0", - "katex": "^0.16.44", + "katex": "^0.16.45", "lodash": "^4.18.1", "markdown-it": "^14.1.1", "markdown-it-anchor": "^9.2.0", diff --git a/packages/vjudge/src/index.ts b/packages/vjudge/src/index.ts index 3fe20fb80..893b613ab 100644 --- a/packages/vjudge/src/index.ts +++ b/packages/vjudge/src/index.ts @@ -27,7 +27,7 @@ class AccountService { this.api = new Provider(account, async (data) => { await coll.updateOne({ _id: account._id }, { $set: data }); }); - this.problemLists = Set.union(this.api.entryProblemLists || ['main'], this.account.problemLists || []); + this.problemLists = new Set(this.api.entryProblemLists || ['main']).union(new Set(this.account.problemLists || [])); this.main().catch((e) => { logger.error(`Error occured in ${account.type}/${account.handle}`); this.working = false;