type Modify = Omit & R; type KeysNotMatching = { [K in keyof T]-?: T[K] extends V ? never : K }[keyof T]; type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; type CommonParamType = "textInput" | "numberInput" | "select" | "keyValueInput"; type DataSourceParamType = CommonParamType | "password" | "checkbox" | "groupTitle"; type ActionParamType = | CommonParamType | "booleanInput" | "switch" | "file" | "jsonInput" | "graphqlInput" | "sqlInput"; type ParamTypeToValueType = T extends | "textInput" | "select" | "password" | "file" ? string : T extends "keyValueInput" ? { key: string; value: any }[] : T extends "numberInput" ? number : T extends "jsonInput" ? any : T extends "checkbox" | "booleanInput" | "switch" ? boolean : never; interface CommonParamConfig { type: T; defaultValue?: ParamTypeToValueType; label?: string; tooltip?: string; placeholder?: string; } // ---- Data Source Param Config ---- interface DataSourceCommonParamConfig extends CommonParamConfig { updatable?: boolean; rules?: readonly ParamRule[]; } interface DataSourceTextInputParamConfig extends DataSourceCommonParamConfig<"textInput"> {} interface DataSourceKeyValueInputParamConfig extends DataSourceCommonParamConfig<"keyValueInput"> { valueType?: "json" | "string"; } interface DataSourcePasswordInputParamConfig extends DataSourceCommonParamConfig<"password"> {} interface DataSourceNumberInputParamConfig extends DataSourceCommonParamConfig<"numberInput"> {} interface DataSourceCheckboxParamConfig extends DataSourceCommonParamConfig<"checkbox"> {} interface DataSourceGroupTitleParamConfig extends DataSourceCommonParamConfig<"groupTitle"> {} interface DataSourceSelectParamConfig extends DataSourceCommonParamConfig<"select"> { options: readonly ParamOption[]; } type B = DataSourceCheckboxParamConfig["defaultValue"]; // ---- Action Param Config ---- interface ActionCommonParamConfig extends CommonParamConfig {} interface ActionTextInputParamConfig extends ActionCommonParamConfig<"textInput"> {} interface ActionNumberInputParamConfig extends ActionCommonParamConfig<"numberInput"> {} interface ActionBooleanInputParamConfig extends ActionCommonParamConfig<"booleanInput"> {} interface ActionKeyValueInputParamConfig extends ActionCommonParamConfig<"keyValueInput"> { valueType?: "json" | "string"; } interface ActionSwitchParamConfig extends ActionCommonParamConfig<"switch"> {} interface ActionFileParamConfig extends ActionCommonParamConfig<"file"> {} interface ActionJSONParamConfig extends ActionCommonParamConfig<"jsonInput"> {} interface ActionSQLParamConfig extends ActionCommonParamConfig<"sqlInput"> {} interface ActionGraphQLParamConfig extends ActionCommonParamConfig<"graphqlInput"> {} interface ActionSelectParamConfig extends ActionCommonParamConfig<"select"> { options: readonly ParamOption[]; } type KeyedConfigToDataType = X extends KeyedParamConfig< infer C, infer K > ? { [key in K]: ConfigToType; } : never; type ActionConfigToDataType = X extends ActionConfig ? ConfigToType & { actionName: K; } : never; export type ActionCategoryValue = string | string[]; export interface ActionCategory { label: string; value: ActionCategoryValue; children?: ActionCategory[]; } export type ActionConfig< C extends Config = readonly ActionParamConfig[], K extends string = string > = { actionName: K; label: string; description?: string; category?: ActionCategoryValue; params: C; }; export interface QueryConfig { type: "query"; label?: string; tooltip?: string; categories?: { label?: string; items?: ActionCategory[]; }; actions: readonly ActionConfig[]; } export type DataSourceConfig = DataSourceConfigBasicInfo & DataSourceConfigFunctions; interface DataSourceConfigBasicInfo { type: "dataSource"; params: readonly DataSourceParamConfig[]; } interface DataSourceExtraConfig { data?: any; extraParams?: DataSourceParamConfig[]; } interface DataSourceConfigFunctions { extra?: (data: DSC) => Promise; } // --- type StringParamConfig = | DataSourceTextInputParamConfig | DataSourceSelectParamConfig | DataSourcePasswordInputParamConfig | ActionTextInputParamConfig | ActionSelectParamConfig | ActionSQLParamConfig | ActionGraphQLParamConfig | ActionFileParamConfig; type NumberParamConfig = DataSourceNumberInputParamConfig | ActionNumberInputParamConfig; type BooleanParamConfig = | DataSourceCheckboxParamConfig | ActionBooleanInputParamConfig | ActionSwitchParamConfig; type JsonParamConfig = ActionJSONParamConfig; type RecordParamConfig = ActionKeyValueInputParamConfig | DataSourceKeyValueInputParamConfig; type SimpleParamConfig = | StringParamConfig | NumberParamConfig | BooleanParamConfig | JsonParamConfig | RecordParamConfig | NonValueParamConfig; type NonValueParamConfig = DataSourceGroupTitleParamConfig; type KeyedParamConfig = C & { key: K; }; type ParamType = T extends { type: infer K } ? K : never; export type DataSourceParamType = ParamType; export type ActionParamType = ParamType; export type DataSourceParamConfig = KeyedParamConfig< | DataSourceCheckboxParamConfig | DataSourceNumberInputParamConfig | DataSourcePasswordInputParamConfig | DataSourceTextInputParamConfig | DataSourceSelectParamConfig | DataSourceGroupTitleParamConfig | DataSourceKeyValueInputParamConfig >; export type ActionParamConfig = KeyedParamConfig< | ActionTextInputParamConfig | ActionNumberInputParamConfig | ActionBooleanInputParamConfig | ActionSelectParamConfig | ActionSwitchParamConfig | ActionFileParamConfig | ActionJSONParamConfig | ActionSQLParamConfig | ActionGraphQLParamConfig | ActionKeyValueInputParamConfig >; export type ArrayParamConfig = readonly KeyedParamConfig< ActionParamConfig | DataSourceParamConfig >[]; export type ActionArrayParamConfig = readonly KeyedParamConfig[]; export type Config = KeyedParamConfig | ArrayParamConfig | QueryConfig | DataSourceConfig; export type DynamicConfig = (data: any) => Promise; export type MixedConfig = Config | DynamicConfig; export type ConfigToType = T extends StringParamConfig ? string : T extends NumberParamConfig ? number : T extends BooleanParamConfig ? boolean : T extends JsonParamConfig ? any : T extends RecordParamConfig ? { key: string; value: any }[] : T extends BooleanParamConfig ? boolean : T extends NonValueParamConfig ? never : T extends ArrayParamConfig ? UnionToIntersection> : T extends QueryConfig ? ActionConfigToDataType : T extends DataSourceConfig ? { extra?: any; dynamicParamsConfig?: any; } & ConfigToType : never; export interface ParamOption { value: string; label: string; description?: string; } export type FieldRuleType = | "string" | "number" | "boolean" | "method" | "regexp" | "integer" | "float" | "object" | "enum" | "date" | "url" | "hex" | "email"; export interface ParamRule { warningOnly?: boolean; enum?: any[]; len?: number; max?: number; message?: string | ReactElement; min?: number; pattern?: RegExp; required?: boolean; type?: FieldRuleType; whitespace?: boolean; } export interface ValidateDataSourceConfigResult { success: boolean; message?: string; } export interface PluginContext { languages: string[]; } export type RunFunc = ( actionData: AC, dataSourceConfig: DSC, context: PluginContext ) => Promise; export type ValidateDataSourceConfigFunc = ( dataSourceConfig: DataSourceConfigType, context: PluginContext ) => Promise; export interface DataSourcePluginBasicInfo { id: string; name: string; description?: string; icon?: string; category: string; } export interface DataSourcePlugin extends DataSourcePluginBasicInfo { dataSourceConfig: DataSourceConfig; queryConfig: QueryConfig | ((dataSourceData: DSC) => Promise); validateDataSourceConfig?: ValidateDataSourceConfigFunc; run: RunFunc; } export type DataSourcePluginFactory = ( context: PluginContext ) => DataSourcePlugin; export interface DataSourcePluginMeta extends DataSourcePluginBasicInfo { dataSourceConfig: Modify< DataSourceConfig, { extra?: DynamicConfigObject; authConfig?: { type: AuthType; authId?: string; } & ( | { username: string; // basic auth password: string; } | OAuthConfig ); sslConfig?: SSLConfig; headers: KeyValue; }, >; queryConfig: DynamicConfigObject | QueryConfig; shouldValidateDataSourceConfig: boolean; } export interface DynamicConfigObject { type: "dynamic"; }