1
- import { FunctionDefinition } from "./DFlowFunction.view" ;
2
- import { DataType , GenericType , isRefObject , Value } from "../data-type/DFlowDataType.view" ;
3
- import { DFlowDataTypeService } from "../data-type/DFlowDataType.service" ;
4
- import { InspectionSeverity , ValidationResult } from "../../../utils/inspection" ;
1
+ import { FunctionDefinition } from "./DFlowFunction.view" ;
2
+ import { DataType , GenericType , isRefObject , Value } from "../data-type/DFlowDataType.view" ;
3
+ import { DFlowDataTypeService } from "../data-type/DFlowDataType.service" ;
4
+ import { InspectionSeverity , ValidationResult } from "../../../utils/inspection" ;
5
5
import {
6
6
replaceGenericKeysInDataTypeObject ,
7
7
replaceGenericKeysInType ,
8
8
resolveGenericKeys
9
9
} from "../../../utils/generics" ;
10
+ import { isNodeFunctionObject , NodeFunctionObject } from "../DFlow.view" ;
11
+ import { useReturnType } from "./DFlowFunction.return.hook" ;
12
+ import { useService } from "../../../utils/contextStore" ;
13
+ import { DFlowFunctionReactiveService } from "./DFlowFunction.service" ;
10
14
11
15
//TODO need to test alo functions not only values and ref objects
12
16
@@ -20,16 +24,16 @@ export const useFunctionValidation = (
20
24
values : Value [ ] ,
21
25
dataTypeService : DFlowDataTypeService
22
26
) : ValidationResult [ ] | null => {
27
+ const functionService = useService ( DFlowFunctionReactiveService )
23
28
const genericTypeMap = resolveGenericKeys ( func , values , dataTypeService )
24
29
const parameters = func . parameters ?? [ ]
25
30
const genericKeys = func . genericKeys ?? [ ]
26
-
27
31
const errors : ValidationResult [ ] = [ ] ;
28
32
29
33
parameters . forEach ( ( parameter , index ) => {
30
34
const value = values [ index ] ;
31
35
const parameterType = parameter . type ;
32
- const valueType = dataTypeService . getTypeFromValue ( value ) ;
36
+ const valueType = isNodeFunctionObject ( value as NodeFunctionObject ) ? useReturnType ( functionService . getFunctionDefinition ( ( value as NodeFunctionObject ) . function . function_id ) ! ! , ( value as NodeFunctionObject ) . parameters ! ! . map ( p => p . value ! ! ) ) ! ! : dataTypeService . getTypeFromValue ( value ) ;
33
37
const parameterDataType = dataTypeService . getDataType ( parameterType ) ;
34
38
const valueDataType = dataTypeService . getDataType ( valueType ) ;
35
39
@@ -44,7 +48,7 @@ export const useFunctionValidation = (
44
48
45
49
if ( isParameterGeneric ) {
46
50
if ( typeof valueType === "object" && valueType && "type" in valueType && parameterDataType ) {
47
- if ( isRefObject ( value ) ) {
51
+ if ( isRefObject ( value ) || isNodeFunctionObject ( value as NodeFunctionObject ) ) {
48
52
const resolvedParameterDT = new DataType (
49
53
replaceGenericKeysInDataTypeObject ( parameterDataType . json , genericTypeMap ) ,
50
54
dataTypeService
@@ -77,7 +81,7 @@ export const useFunctionValidation = (
77
81
return ;
78
82
}
79
83
if ( valueDataType && parameterDataType && parameterDataType . genericKeys && valueDataType . json && parameterDataType . json ) {
80
- if ( isRefObject ( value ) ) {
84
+ if ( isRefObject ( value ) || isNodeFunctionObject ( value as NodeFunctionObject ) ) {
81
85
const resolvedParameterDT = new DataType (
82
86
replaceGenericKeysInDataTypeObject ( parameterDataType . json , genericTypeMap ) ,
83
87
dataTypeService
@@ -100,7 +104,7 @@ export const useFunctionValidation = (
100
104
// Non-generic parameter validation
101
105
if ( parameterDataType ) {
102
106
if ( typeof valueType === "object" && valueType && "type" in valueType && parameterDataType ) {
103
- if ( isRefObject ( value ) ) {
107
+ if ( isRefObject ( value ) || isNodeFunctionObject ( value as NodeFunctionObject ) ) {
104
108
const resolvedValueDT = new DataType (
105
109
replaceGenericKeysInDataTypeObject ( valueDataType ?. json ! , genericTypeMap ) ,
106
110
dataTypeService
@@ -118,7 +122,7 @@ export const useFunctionValidation = (
118
122
return ;
119
123
}
120
124
if ( valueDataType ) {
121
- if ( isRefObject ( value ) ) {
125
+ if ( isRefObject ( value ) || isNodeFunctionObject ( value as NodeFunctionObject ) ) {
122
126
isValid = parameterDataType . validateDataType ( valueDataType ) ;
123
127
if ( ! isValid ) {
124
128
errors . push ( errorResult ( paramLabel , parameterType , value , "Non-generic: Ref Type mismatch" ) ) ;
0 commit comments