mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: fix #1133
This commit is contained in:
2 files changed
+21
-12
No files matched your search
@@ -48,6 +48,7 @@ export class Loader extends Service {
|
||||
public state: Record<string, Fiber> = Object.create(null);
|
||||
public suspend = false;
|
||||
public cache: Record<string, string> = Object.create(null);
|
||||
private schemaCache = new WeakMap<Schema<any>, Record<string, Schema<any>>>();
|
||||
// public warnings: Record<string, string> = Object.create(null);
|
||||
|
||||
static inject = ['setting', 'timer', 'i18n', 'logger'];
|
||||
@@ -94,12 +95,18 @@ export class Loader extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
buildSchema(schema: Schema<any>, scope?: string) {
|
||||
if (!scope) return schema;
|
||||
const cache = this.schemaCache.get(schema) || {};
|
||||
cache[scope] ||= Schema.object({ [scope]: schema });
|
||||
this.schemaCache.set(schema, cache);
|
||||
return cache[scope];
|
||||
}
|
||||
|
||||
async resolveConfig(plugin: any, configScope: string, dynamic = true) {
|
||||
const schema = plugin['Config'] || plugin['schema'];
|
||||
if (!schema) return Object.freeze({});
|
||||
const schemaRequest = configScope ? Schema.object({
|
||||
[configScope]: schema,
|
||||
}) : schema;
|
||||
const schemaRequest = this.buildSchema(schema, configScope);
|
||||
await this.ctx.setting._tryMigrateConfig(schemaRequest);
|
||||
const res = this.ctx.setting.requestConfig(schemaRequest, dynamic);
|
||||
return configScope ? res[configScope] : res;
|
||||
|
||||
Reference in new issue
Block a user