Merge pull request #1080 from Hexastack/1042-bug---settingtypemultiple_attachment-setting-fields-type

feat(api): add strict Setting types
This commit is contained in:
Med Marrouchi 2025-06-02 10:47:05 +01:00 committed by GitHub
commit 02efab8308
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 16 deletions

View File

@ -1,19 +1,16 @@
/* /*
* Copyright © 2024 Hexastack. All rights reserved. * Copyright © 2025 Hexastack. All rights reserved.
* *
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { SettingCreateDto } from '@/setting/dto/setting.dto'; import { ExtensionSetting } from '@/setting/schemas/types';
import { HyphenToUnderscore } from '@/utils/types/extension'; import { HyphenToUnderscore } from '@/utils/types/extension';
export type ChannelName = `${string}-channel`; export type ChannelName = `${string}-channel`;
export type ChannelSetting<N extends string = string> = Omit< export type ChannelSetting<N extends string = string> = ExtensionSetting<{
SettingCreateDto,
'group' | 'weight'
> & {
group: HyphenToUnderscore<N>; group: HyphenToUnderscore<N>;
}; }>;

View File

@ -6,7 +6,7 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { SettingCreateDto } from '@/setting/dto/setting.dto'; import { ExtensionSetting } from '@/setting/schemas/types';
import { HyphenToUnderscore } from '@/utils/types/extension'; import { HyphenToUnderscore } from '@/utils/types/extension';
import BaseHelper from './lib/base-helper'; import BaseHelper from './lib/base-helper';
@ -116,9 +116,7 @@ export type HelperRegistry<H extends BaseHelper = BaseHelper> = Map<
Map<string, H> Map<string, H>
>; >;
export type HelperSetting<N extends HelperName = HelperName> = Omit< export type HelperSetting<N extends HelperName = HelperName> =
SettingCreateDto, ExtensionSetting<{
'group' | 'weight' group: HyphenToUnderscore<N>;
> & { }>;
group: HyphenToUnderscore<N>;
};

View File

@ -10,7 +10,7 @@ import { ChannelEvent } from '@/channel/lib/EventWrapper';
import { BlockCreateDto } from '@/chat/dto/block.dto'; import { BlockCreateDto } from '@/chat/dto/block.dto';
import { Block } from '@/chat/schemas/block.schema'; import { Block } from '@/chat/schemas/block.schema';
import { Conversation } from '@/chat/schemas/conversation.schema'; import { Conversation } from '@/chat/schemas/conversation.schema';
import { SettingCreateDto } from '@/setting/dto/setting.dto'; import { ExtensionSetting } from '@/setting/schemas/types';
export type PluginName = `${string}-plugin`; export type PluginName = `${string}-plugin`;
@ -23,7 +23,7 @@ export interface CustomBlocks {}
type BlockAttrs = Partial<BlockCreateDto> & { name: string }; type BlockAttrs = Partial<BlockCreateDto> & { name: string };
export type PluginSetting = Omit<SettingCreateDto, 'weight'>; export type PluginSetting = ExtensionSetting;
export type PluginBlockTemplate = Omit< export type PluginBlockTemplate = Omit<
BlockAttrs, BlockAttrs,

View File

@ -6,6 +6,8 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/ */
import { BaseSchema } from '@/utils/generics/base-schema';
import { Setting } from './setting.schema'; import { Setting } from './setting.schema';
export enum SettingType { export enum SettingType {
@ -128,3 +130,17 @@ export type AnySetting =
| MultipleAttachmentSetting; | MultipleAttachmentSetting;
export type SettingDict = { [group: string]: Setting[] }; export type SettingDict = { [group: string]: Setting[] };
export type ExtensionSetting<
E extends object = object,
U extends AnySetting = AnySetting,
K extends keyof BaseSchema = keyof BaseSchema,
> = U extends any
? {
[P in keyof U as P extends K
? never
: U[P] extends never
? never
: P]: U[P];
} & E
: never;