From bb5d029e68d99c6eeb9ec2cc317053fec51590f6 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Mon, 2 Jun 2025 07:16:52 +0100 Subject: [PATCH 1/5] feat(api): add strict Setting types --- api/src/setting/schemas/types.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/api/src/setting/schemas/types.ts b/api/src/setting/schemas/types.ts index 5d1b6bc2..1e99713d 100644 --- a/api/src/setting/schemas/types.ts +++ b/api/src/setting/schemas/types.ts @@ -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). */ +import { BaseSchema } from '@/utils/generics/base-schema'; + import { Setting } from './setting.schema'; export enum SettingType { @@ -128,3 +130,17 @@ export type AnySetting = | MultipleAttachmentSetting; export type SettingDict = { [group: string]: Setting[] }; + +export type StrictSetting< + U, + E extends object = object, + 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; From 4b42c03fb9d04c58a917e4aa9267cc73fbb4fb6b Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Mon, 2 Jun 2025 07:17:25 +0100 Subject: [PATCH 2/5] feat(api): add strict Setting types to channels --- api/src/channel/types.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api/src/channel/types.ts b/api/src/channel/types.ts index 0c654f19..7269a38c 100644 --- a/api/src/channel/types.ts +++ b/api/src/channel/types.ts @@ -6,14 +6,14 @@ * 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 { AnySetting, StrictSetting } from '@/setting/schemas/types'; import { HyphenToUnderscore } from '@/utils/types/extension'; export type ChannelName = `${string}-channel`; -export type ChannelSetting = Omit< - SettingCreateDto, - 'group' | 'weight' -> & { - group: HyphenToUnderscore; -}; +export type ChannelSetting = StrictSetting< + AnySetting, + { + group: HyphenToUnderscore; + } +>; From 801a60b331f9ac6d59b2f89686c8f50588592219 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Mon, 2 Jun 2025 07:17:35 +0100 Subject: [PATCH 3/5] feat(api): add strict Setting types to helpers --- api/src/helper/types.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api/src/helper/types.ts b/api/src/helper/types.ts index fd373f85..a6c841e0 100644 --- a/api/src/helper/types.ts +++ b/api/src/helper/types.ts @@ -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). */ -import { SettingCreateDto } from '@/setting/dto/setting.dto'; +import { AnySetting, StrictSetting } from '@/setting/schemas/types'; import { HyphenToUnderscore } from '@/utils/types/extension'; import BaseHelper from './lib/base-helper'; @@ -116,9 +116,9 @@ export type HelperRegistry = Map< Map >; -export type HelperSetting = Omit< - SettingCreateDto, - 'group' | 'weight' -> & { - group: HyphenToUnderscore; -}; +export type HelperSetting = StrictSetting< + AnySetting, + { + group: HyphenToUnderscore; + } +>; From c15c30895ff655749bf0ee679defdffd7a2ce224 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Mon, 2 Jun 2025 07:17:48 +0100 Subject: [PATCH 4/5] feat(api): add strict Setting types to plugins --- api/src/plugins/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/plugins/types.ts b/api/src/plugins/types.ts index d296de6d..09a3beac 100644 --- a/api/src/plugins/types.ts +++ b/api/src/plugins/types.ts @@ -10,7 +10,7 @@ import { ChannelEvent } from '@/channel/lib/EventWrapper'; import { BlockCreateDto } from '@/chat/dto/block.dto'; import { Block } from '@/chat/schemas/block.schema'; import { Conversation } from '@/chat/schemas/conversation.schema'; -import { SettingCreateDto } from '@/setting/dto/setting.dto'; +import { AnySetting, StrictSetting } from '@/setting/schemas/types'; export type PluginName = `${string}-plugin`; @@ -23,7 +23,7 @@ export interface CustomBlocks {} type BlockAttrs = Partial & { name: string }; -export type PluginSetting = Omit; +export type PluginSetting = StrictSetting; export type PluginBlockTemplate = Omit< BlockAttrs, From 8c32d9af53826b701129c01e94b53c9d0a69896f Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Mon, 2 Jun 2025 09:16:13 +0100 Subject: [PATCH 5/5] fix(api): apply feedback --- api/src/channel/types.ts | 13 +++++-------- api/src/helper/types.ts | 10 ++++------ api/src/plugins/types.ts | 4 ++-- api/src/setting/schemas/types.ts | 4 ++-- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/api/src/channel/types.ts b/api/src/channel/types.ts index 7269a38c..18d8348d 100644 --- a/api/src/channel/types.ts +++ b/api/src/channel/types.ts @@ -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: * 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). */ -import { AnySetting, StrictSetting } from '@/setting/schemas/types'; +import { ExtensionSetting } from '@/setting/schemas/types'; import { HyphenToUnderscore } from '@/utils/types/extension'; export type ChannelName = `${string}-channel`; -export type ChannelSetting = StrictSetting< - AnySetting, - { - group: HyphenToUnderscore; - } ->; +export type ChannelSetting = ExtensionSetting<{ + group: HyphenToUnderscore; +}>; diff --git a/api/src/helper/types.ts b/api/src/helper/types.ts index a6c841e0..658c95c3 100644 --- a/api/src/helper/types.ts +++ b/api/src/helper/types.ts @@ -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). */ -import { AnySetting, StrictSetting } from '@/setting/schemas/types'; +import { ExtensionSetting } from '@/setting/schemas/types'; import { HyphenToUnderscore } from '@/utils/types/extension'; import BaseHelper from './lib/base-helper'; @@ -116,9 +116,7 @@ export type HelperRegistry = Map< Map >; -export type HelperSetting = StrictSetting< - AnySetting, - { +export type HelperSetting = + ExtensionSetting<{ group: HyphenToUnderscore; - } ->; + }>; diff --git a/api/src/plugins/types.ts b/api/src/plugins/types.ts index 09a3beac..0f4be5ed 100644 --- a/api/src/plugins/types.ts +++ b/api/src/plugins/types.ts @@ -10,7 +10,7 @@ import { ChannelEvent } from '@/channel/lib/EventWrapper'; import { BlockCreateDto } from '@/chat/dto/block.dto'; import { Block } from '@/chat/schemas/block.schema'; import { Conversation } from '@/chat/schemas/conversation.schema'; -import { AnySetting, StrictSetting } from '@/setting/schemas/types'; +import { ExtensionSetting } from '@/setting/schemas/types'; export type PluginName = `${string}-plugin`; @@ -23,7 +23,7 @@ export interface CustomBlocks {} type BlockAttrs = Partial & { name: string }; -export type PluginSetting = StrictSetting; +export type PluginSetting = ExtensionSetting; export type PluginBlockTemplate = Omit< BlockAttrs, diff --git a/api/src/setting/schemas/types.ts b/api/src/setting/schemas/types.ts index 1e99713d..a0aee11c 100644 --- a/api/src/setting/schemas/types.ts +++ b/api/src/setting/schemas/types.ts @@ -131,9 +131,9 @@ export type AnySetting = export type SettingDict = { [group: string]: Setting[] }; -export type StrictSetting< - U, +export type ExtensionSetting< E extends object = object, + U extends AnySetting = AnySetting, K extends keyof BaseSchema = keyof BaseSchema, > = U extends any ? {