bump version

This commit is contained in:
undefined committed 2025-11-12 05:10:49 +08:00
1 parent 828ba556ae
commit ae43ee16de
26 files changed
+136 -81

No files matched your search

+1
View File
@@ -25,6 +25,7 @@ function provideModule<T extends keyof ModuleInterfaces>(type: T, id: string, mo
}
export type Fiber = cordis.Fiber<Context>;
export const Fiber = cordis.Fiber;
export { Disposable, FiberState, Plugin } from 'cordis';
+1 -1
View File
@@ -124,7 +124,7 @@ export class ProblemMainHandler extends Handler {
const category = parsed.category || [];
const text = (parsed.text || []).join(' ');
if (parsed.difficulty?.every((i) => Number.isSafeInteger(+i))) {
query.difficulty = { $in: parsed.difficulty.map(Number) };
query.difficulty = { $in: parsed.difficulty.flatMap((i) => +i === 0 ? [0, undefined] : [+i]) };
}
if (category.length) query.$and = category.map((tag) => ({ tag }));
if (parsed.namespace?.length) {
+20 -7
View File
@@ -19,6 +19,7 @@ import { sleep, unwrapExports } from './utils';
import { PRIV } from './model/builtin';
import { getAddons } from './options';
import Schema from 'schemastery';
import { isEqual } from 'lodash';
const argv = cac().parse();
const logger = new Logger('loader');
@@ -93,35 +94,47 @@ export class Loader extends Service {
}
}
async resolveConfig(plugin: any, configScope: string) {
async resolveConfig(plugin: any, configScope: string, dynamic = true) {
const schema = plugin['Config'] || plugin['schema'];
if (!schema) return {};
if (!schema) return Object.freeze({});
const schemaRequest = configScope ? Schema.object({
[configScope]: schema,
}) : schema;
await this.ctx.setting._tryMigrateConfig(schemaRequest);
const res = this.ctx.setting.requestConfig(schemaRequest);
const res = this.ctx.setting.requestConfig(schemaRequest, dynamic);
return configScope ? res[configScope] : res;
}
async reloadPlugin(key: string, configScope: string) {
const plugin = this.resolvePlugin(key);
if (!plugin) return;
const config = await this.resolveConfig(plugin, configScope);
// currently cordis validates config and converts proxy to plain object
// must do a full reload once config changed
const config = await this.resolveConfig(plugin, configScope, false);
let fork = this.state[key];
const displayPath = key.includes('node_modules')
? key.split('node_modules').pop()
: path.relative(process.cwd(), key);
logger.info(
`%s plugin %c${configScope ? ' with scope %c' : ''}`,
fork ? 'reload' : 'apply', displayPath, configScope,
fork ? 'update' : 'apply', displayPath, configScope,
);
if (fork) {
fork.update(config);
fork.update(config, true);
} else {
fork = this.ctx.plugin(plugin, config);
if (!fork) return;
this.state[key] = fork;
const inner = Object.getPrototypeOf(fork) !== Fiber.prototype
? Object.getPrototypeOf(fork) : fork;
this.state[key] = inner;
}
if (!Object.isFrozen(config)) {
fork.ctx.on('system/setting', async () => {
if (!fork.uid || !this.state[key]) return;
const resolved = await this.resolveConfig(plugin, configScope, false);
if (isEqual(this.state[key].config, resolved)) return;
this.reloadPlugin(key, configScope);
});
}
return fork;
}
+11 -10
View File
@@ -150,16 +150,16 @@ export class SettingService extends Service {
}
requestConfig<T, S>(s: Schema<T, S>, dynamic = true): S {
if (dynamic) {
this.ctx.effect(() => {
this.settings.push(s);
this.ctx.effect(() => {
logger.debug('Loading config', s);
this.settings.push(s);
this._applySchema();
return () => {
logger.debug('Unloading config', s);
this.settings = this.settings.filter((v) => v !== s);
this._applySchema();
return () => {
this.settings = this.settings.filter((v) => v !== s);
this._applySchema();
};
});
}
};
});
let curValue = s(this.systemConfig);
if (!dynamic) return curValue;
this.ctx.on('system/setting', () => {
@@ -175,7 +175,8 @@ export class SettingService extends Service {
if (path.some((p) => SettingService.blacklist.includes(p.toString()))) throw new Error(`Invalid path: ${path.join('.')}`);
let currentValue = curValue;
for (const p of path) currentValue = currentValue[p];
if (typeof currentValue !== 'object' || !currentValue || Array.isArray(currentValue)) return currentValue;
if ((typeof currentValue !== 'object') || !currentValue || Array.isArray(currentValue)) return currentValue;
if (path.some((p) => typeof p === 'symbol')) return currentValue;
return new Proxy(currentValue, {
get(self, key: string) {
return getAccess(path.concat(key));
+1 -1
View File
@@ -458,7 +458,7 @@ export const coreScripts: MigrationScript[] = [
return await iterateAllDomain(async ({ _id }) => {
const cursor = discussion.getMulti(_id, { parentType: document.TYPE_CONTEST });
for await (const ddoc of cursor) {
const parentId = new ObjectId(ddoc.parentId);
const parentId = new ObjectId(ddoc.parentId as string);
await discussion.edit(_id, ddoc.docId, { parentId });
try {
await contest.get(_id, parentId);