2025-04-22 16:46:33 +08:00
|
|
|
import type { NodeDefault } from '../../types'
|
|
|
|
import type { DataSourceNodeType } from './types'
|
2025-04-25 11:32:17 +08:00
|
|
|
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
|
|
|
import { BlockEnum } from '@/app/components/workflow/types'
|
2025-05-23 18:19:01 +08:00
|
|
|
import { OUTPUT_VARIABLES_MAP } from './constants'
|
2025-05-27 18:44:04 +08:00
|
|
|
import { inputVarTypeToVarType } from './utils'
|
2025-04-22 16:46:33 +08:00
|
|
|
|
2025-04-29 16:11:54 +08:00
|
|
|
const metaData = genNodeMetaData({
|
|
|
|
sort: -1,
|
|
|
|
type: BlockEnum.DataSource,
|
|
|
|
})
|
2025-04-22 16:46:33 +08:00
|
|
|
const nodeDefault: NodeDefault<DataSourceNodeType> = {
|
2025-04-29 16:11:54 +08:00
|
|
|
metaData,
|
2025-05-23 18:19:01 +08:00
|
|
|
defaultValue: {
|
2025-05-27 17:42:02 +08:00
|
|
|
variables: [],
|
2025-05-23 18:19:01 +08:00
|
|
|
datasource_parameters: {},
|
|
|
|
datasource_configurations: {},
|
|
|
|
},
|
2025-04-22 16:46:33 +08:00
|
|
|
checkValid() {
|
|
|
|
return {
|
|
|
|
isValid: true,
|
|
|
|
errorMessage: '',
|
|
|
|
}
|
|
|
|
},
|
2025-05-23 18:19:01 +08:00
|
|
|
getOutputVars(payload) {
|
2025-05-27 18:44:04 +08:00
|
|
|
const {
|
|
|
|
provider_type,
|
|
|
|
variables,
|
|
|
|
} = payload
|
2025-05-26 17:47:03 +08:00
|
|
|
const isLocalFile = provider_type === 'local_file'
|
2025-05-27 18:44:04 +08:00
|
|
|
const hasUserInputFields = !!variables?.length
|
2025-05-23 18:19:01 +08:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
variable: OUTPUT_VARIABLES_MAP.datasource_type.name,
|
|
|
|
type: OUTPUT_VARIABLES_MAP.datasource_type.type,
|
|
|
|
},
|
|
|
|
...(
|
|
|
|
isLocalFile
|
|
|
|
? [
|
|
|
|
{
|
|
|
|
variable: OUTPUT_VARIABLES_MAP.file.name,
|
|
|
|
type: OUTPUT_VARIABLES_MAP.file.type,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: []
|
|
|
|
),
|
2025-05-27 18:44:04 +08:00
|
|
|
...(
|
|
|
|
hasUserInputFields
|
|
|
|
? variables.map((field) => {
|
|
|
|
return {
|
|
|
|
variable: field.variable,
|
|
|
|
type: inputVarTypeToVarType(field.type),
|
|
|
|
isUserInputField: true,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
: []
|
|
|
|
),
|
2025-05-23 18:19:01 +08:00
|
|
|
]
|
|
|
|
},
|
2025-04-22 16:46:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default nodeDefault
|