diff --git a/framework/framework/api.ts b/framework/framework/api.ts index d4391b8fa..dc63a2bf9 100644 --- a/framework/framework/api.ts +++ b/framework/framework/api.ts @@ -11,7 +11,7 @@ const REDIRECT = Symbol.for('hydro.api.response.redirect'); type MaybePromise = T | Promise; export type ApiType = 'Query' | 'Mutation' | 'Subscription'; -export interface ApiCall { +export interface ApiCall { readonly type: Type; readonly input: Schema; readonly func: (Type extends 'Subscription' @@ -20,10 +20,10 @@ export interface ApiCall { readonly hooks: ApiCall<'Query', Arg, void>[]; } -export const _get = (type: Type) => ( +export const _get = (type: Type) => ( schema: Schema, func: ApiCall['func'], - hooks: ApiCall<'Query', Arg, void, never>[] = [], + hooks: ApiCall<'Query', Arg, void, void>[] = [], ): ApiCall => ({ input: schema, func, hooks, type } as const); export const Query = _get('Query'); @@ -115,14 +115,16 @@ export class ApiService extends Service { super(ctx, 'api'); } - provide(calls: Partial) { + provide(calls: Partial, atNameSpace = '') { this.ctx.effect(() => { for (const key in calls) { - APIS[key] = calls[key]; + const target = `${atNameSpace ? `${atNameSpace}.` : ''}${key}`; + if (APIS[target]) console.warn(`API ${target} already exists, will be overridden`); + APIS[target] = calls[key]; } return () => { for (const key in calls) { - delete APIS[key]; + delete APIS[`${atNameSpace ? `${atNameSpace}.` : ''}${key}`]; } }; }); diff --git a/packages/hydrooj/src/model/setting.ts b/packages/hydrooj/src/model/setting.ts index 382854ae3..730533653 100644 --- a/packages/hydrooj/src/model/setting.ts +++ b/packages/hydrooj/src/model/setting.ts @@ -95,7 +95,7 @@ function schemaToSettings(schema: Schema) { if (s.meta?.role === 'password') flag |= FLAG_SECRET; const options = {}; for (const item of actualList || []) { - if (item.type !== 'const') throw new Error('List item must be a constant'); + if (item.type !== 'const') throw new Error(`List item must be a constant, got ${item.type}`); options[item.value] = item.meta?.description || item.value; } return {