move delarations to @hydrooj/common

This commit is contained in:
undefined committed 2025-02-09 15:17:10 +00:00
1 parent 100ccf718f
commit 4a33816a37
49 files changed
+496 -465

No files matched your search

+5 -4
View File
@@ -1,11 +1,12 @@
/* eslint-disable no-await-in-loop */
import path from 'path';
import {
changeErrorType, fs, normalizeSubtasks, readSubtasksFromFiles, yaml,
convertIniConfig, LangConfig,
normalizeSubtasks, ProblemConfigFile, readSubtasksFromFiles, readYamlCases,
} from '@hydrooj/common';
import {
changeErrorType, fs, yaml,
} from '@hydrooj/utils';
import readYamlCases, { convertIniConfig } from '@hydrooj/utils/lib/cases';
import { LangConfig } from '@hydrooj/utils/lib/lang';
import { ProblemConfigFile } from 'hydrooj';
import { getConfig } from './config';
import { FormatError, SystemError } from './error';
import { NextFunction, ParsedConfig } from './interface';
+1 -1
View File
@@ -1,5 +1,5 @@
/* eslint-disable no-template-curly-in-string */
import { STATUS } from '@hydrooj/utils/lib/status';
import { STATUS } from '@hydrooj/common';
import { FormatError, SystemError } from './error';
import { CopyInFile, runQueued } from './sandbox';
import { parse } from './testlib';
+1 -2
View File
@@ -1,5 +1,4 @@
import { LangConfig } from '@hydrooj/utils/lib/lang';
import { STATUS } from '@hydrooj/utils/lib/status';
import { LangConfig, STATUS } from '@hydrooj/common';
import { CompileError } from './error';
import { Execute } from './interface';
import {
+1 -1
View File
@@ -1,4 +1,4 @@
import { STATUS_TEXTS } from '@hydrooj/utils/lib/status';
import { STATUS_TEXTS } from '@hydrooj/common';
interface CompileErrorInfo {
stdout?: string,
+3 -3
View File
@@ -1,10 +1,10 @@
import Queue from 'p-queue';
import { STATUS } from '@hydrooj/utils/lib/status';
import type { JudgeResultBody } from 'hydrooj';
import {
JudgeResultBody, NormalizedCase, NormalizedSubtask, STATUS,
} from '@hydrooj/common';
import { getConfig } from './config';
import { FormatError } from './error';
import { Context, ContextSubTask } from './judge/interface';
import { NormalizedCase, NormalizedSubtask } from './utils';
interface Task {
compile: () => Promise<void>;
+2 -4
View File
@@ -36,18 +36,16 @@ const session: Session = {
t._callbackAwait ||= Promise.resolve();
return (data: Partial<JudgeResultBody>) => {
logger.debug('Next: %o', data);
data.rid = new ObjectId(t.rid);
if (data.case) data.case.message ||= '';
t._callbackAwait = t._callbackAwait.then(() => JudgeHandler.next({ ...data, domainId: t.request.domainId }));
t._callbackAwait = t._callbackAwait.then(() => JudgeHandler.next({ ...data, rid: t.rid, domainId: t.request.domainId }));
};
},
getEnd(t: Context) {
t._callbackAwait ||= Promise.resolve();
return (data: Partial<JudgeResultBody>) => {
data.key = 'end';
data.rid = new ObjectId(t.rid);
logger.info('End: status=%d score=%d time=%dms memory=%dkb', data.status, data.score, data.time, data.memory);
t._callbackAwait = t._callbackAwait.then(() => JudgeHandler.end({ ...data, domainId: t.request.domainId }));
t._callbackAwait = t._callbackAwait.then(() => JudgeHandler.end({ ...data, rid: t.rid, domainId: t.request.domainId }));
};
},
getLang(lang: string, doThrow = true) {
+1 -3
View File
@@ -4,10 +4,8 @@ import AdmZip from 'adm-zip';
import PQueue from 'p-queue';
import superagent from 'superagent';
import WebSocket from 'ws';
import { JudgeResultBody, parseLang, STATUS } from '@hydrooj/common';
import { fs, noop } from '@hydrooj/utils';
import { parseLang } from '@hydrooj/utils/lib/lang';
import { STATUS } from '@hydrooj/utils/lib/status';
import type { JudgeResultBody } from 'hydrooj';
import { getConfig } from '../config';
import { FormatError, SystemError } from '../error';
import { Session } from '../interface';
+1 -1
View File
@@ -1,4 +1,4 @@
import { LangConfig } from '@hydrooj/utils/lib/lang';
import { LangConfig } from '@hydrooj/common';
import { runQueued } from './sandbox';
export async function compilerVersions(langs: Record<string, LangConfig>) {
+4 -8
View File
@@ -1,7 +1,6 @@
import type { LangConfig } from '@hydrooj/utils/lib/lang';
import { NormalizedSubtask } from '@hydrooj/utils/lib/utils';
import type { JudgeRequest as OrigJudgeRequest, ObjectId } from 'hydrooj';
import { JudgeResultBody, ProblemConfigFile } from 'hydrooj';
import {
JudgeResultBody, type LangConfig, NormalizedSubtask, ProblemConfigFile,
} from '@hydrooj/common';
import { CopyInFile } from './sandbox';
import type { JudgeTask } from './task';
@@ -20,10 +19,7 @@ export interface ParsedConfig extends Omit<ProblemConfigFile, 'time' | 'memory'
subtasks: NormalizedSubtask[];
}
// replace ObjectId to string
export type JudgeRequest = {
[K in keyof OrigJudgeRequest]: OrigJudgeRequest[K] extends ObjectId ? string : OrigJudgeRequest[K];
};
export { JudgeRequest } from '@hydrooj/common';
export interface Session {
getLang: (name: string) => LangConfig;
@@ -1,8 +1,7 @@
import { STATUS } from '@hydrooj/utils/lib/status';
import { NormalizedCase, STATUS } from '@hydrooj/common';
import { runFlow } from '../flow';
import { Parameter, runPiped } from '../sandbox';
import signals from '../signals';
import { NormalizedCase } from '../utils';
import { Context, ContextSubTask } from './interface';
function judgeCase(c: NormalizedCase) {
+1 -2
View File
@@ -1,9 +1,8 @@
import { STATUS } from '@hydrooj/utils/lib/status';
import { NormalizedCase, STATUS } from '@hydrooj/common';
import checkers from '../checkers';
import { runFlow } from '../flow';
import { del, runQueued } from '../sandbox';
import signals from '../signals';
import { NormalizedCase } from '../utils';
import { Context, ContextSubTask } from './interface';
function judgeCase(c: NormalizedCase) {
+1 -1
View File
@@ -2,7 +2,7 @@
import { tmpdir } from 'os';
import path from 'path';
import fs from 'fs-extra';
import { STATUS } from '@hydrooj/utils/lib/status';
import { STATUS } from '@hydrooj/common';
import { SystemError } from '../error';
import { CopyInFile, runQueued } from '../sandbox';
import client from '../sandbox/client';
+3 -4
View File
@@ -1,10 +1,9 @@
/* eslint-disable no-sequences */
import { fs } from '@hydrooj/utils';
import { STATUS } from '@hydrooj/utils/lib/status';
import { STATUS } from '@hydrooj/common';
import { fs, parseMemoryMB, parseTimeMS } from '@hydrooj/utils';
import checkers from '../checkers';
import { del, runQueued } from '../sandbox';
import signals from '../signals';
import { parseMemoryMB, parseTimeMS } from '../utils';
import { Context } from './interface';
export async function judge(ctx: Context) {
@@ -13,7 +12,7 @@ export async function judge(ctx: Context) {
ctx.compile(ctx.lang, ctx.code),
ctx.compileLocalFile('checker', ctx.config.checker, ctx.config.checker_type),
ctx.compileLocalFile('validator', ctx.config.validator),
ctx.session.fetchFile(ctx.files.hack),
ctx.session.fetchFile(null, { [ctx.files.hack]: '' }),
]);
ctx.clean.push(() => fs.unlink(input));
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
+1 -2
View File
@@ -1,9 +1,8 @@
import { STATUS } from '@hydrooj/utils/lib/status';
import { NormalizedCase, STATUS } from '@hydrooj/common';
import { runFlow } from '../flow';
import { runPiped } from '../sandbox';
import signals from '../signals';
import { parse } from '../testlib';
import { NormalizedCase } from '../utils';
import { Context, ContextSubTask } from './interface';
function judgeCase(c: NormalizedCase) {
+1 -1
View File
@@ -1,5 +1,5 @@
import PQueue from 'p-queue';
import type { NormalizedSubtask } from '@hydrooj/utils/lib/common';
import { NormalizedSubtask } from '@hydrooj/common';
import { Execute } from '../interface';
import { JudgeTask } from '../task';
+1 -1
View File
@@ -1,6 +1,6 @@
import assert from 'assert';
import { STATUS } from '@hydrooj/common';
import { fs, yaml } from '@hydrooj/utils';
import { STATUS } from '@hydrooj/utils/lib/status';
import { FormatError } from '../error';
import { Context } from './interface';
+2 -2
View File
@@ -1,8 +1,8 @@
import { STATUS } from '@hydrooj/utils/lib/status';
import { STATUS } from '@hydrooj/common';
import { parseMemoryMB, parseTimeMS } from '@hydrooj/utils';
import { runQueued } from '../sandbox';
import signals from '../signals';
import { JudgeTask } from '../task';
import { parseMemoryMB, parseTimeMS } from '../utils';
export const judge = async (ctx: JudgeTask) => {
ctx.stat.judge = new Date();
@@ -1,9 +1,8 @@
import { NormalizedCase, STATUS } from '@hydrooj/common';
import { fs } from '@hydrooj/utils';
import { STATUS } from '@hydrooj/utils/lib/status';
import checkers from '../checkers';
import { runFlow } from '../flow';
import { del, runQueued } from '../sandbox';
import { NormalizedCase } from '../utils';
import { Context } from './interface';
function judgeCase(c: NormalizedCase) {
+1 -1
View File
@@ -2,7 +2,7 @@ import cac from 'cac';
import PQueue from 'p-queue';
import { gte } from 'semver';
import { ParseEntry } from 'shell-quote';
import { STATUS } from '@hydrooj/utils/lib/status';
import { STATUS } from '@hydrooj/common';
import * as sysinfo from '@hydrooj/utils/lib/sysinfo';
import { getConfig } from './config';
import { FormatError, SystemError } from './error';
+3 -4
View File
@@ -1,9 +1,8 @@
import { basename, join } from 'path';
import {
CompilableSource, FileInfo, JudgeMeta, JudgeResultBody, STATUS, TestCase,
} from '@hydrooj/common';
import { findFileSync, fs } from '@hydrooj/utils';
import { STATUS } from '@hydrooj/utils/lib/status';
import type {
CompilableSource, FileInfo, JudgeMeta, JudgeResultBody, TestCase,
} from 'hydrooj';
import readCases from './cases';
import checkers from './checkers';
import compile from './compile';
+1 -1
View File
@@ -1,4 +1,4 @@
import { STATUS } from '@hydrooj/utils/lib/status';
import { STATUS } from '@hydrooj/common';
const operation = /^\s*(status|score)\((\d+)\)\s*(.*)$/m;