Skip to content

Commit 027b88c

Browse files
ivicacclaude
andcommitted
2897 Add evaluator function DSL, definitions, and GraphQL endpoint
- Add EvaluatorFunctionDefinition record and EvaluatorFunctionDsl builder in evaluator-api - Add EvaluatorFunctionDefinitionFactory interface for pluggable definition providers - Add EvaluatorFunctionDefinitions with definitions for all 40+ built-in functions grouped by category (Collection, String, DateTime, Map, Type, Utility) - Add GraphQL schema and controller for querying function definitions with list (filterable by name) and individual lookup queries - Add spring-context dependency to evaluator-impl for @component support - Add evaluator-api dependency to platform-configuration-graphql Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 011464d commit 027b88c

File tree

12 files changed

+2204
-54
lines changed

12 files changed

+2204
-54
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.evaluator;
18+
19+
/**
20+
* Enumerates the categories of evaluator functions.
21+
*
22+
* @author Ivica Cardic
23+
*/
24+
public enum EvaluatorFunctionCategory {
25+
26+
COLLECTION,
27+
DATE_TIME,
28+
MAP,
29+
STRING,
30+
TYPE,
31+
UTILITY
32+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.evaluator;
18+
19+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
20+
import java.util.List;
21+
22+
/**
23+
* Describes an evaluator function available in the workflow expression language.
24+
*
25+
* @author Ivica Cardic
26+
*/
27+
@SuppressFBWarnings("EI")
28+
public record EvaluatorFunctionDefinition(
29+
String name,
30+
String title,
31+
String description,
32+
EvaluatorFunctionCategory category,
33+
List<EvaluatorFunctionParameter> parameters,
34+
EvaluatorFunctionType returnType,
35+
String example) {
36+
37+
/**
38+
* Describes a parameter of an evaluator function.
39+
*
40+
* @author Ivica Cardic
41+
*/
42+
public record EvaluatorFunctionParameter(
43+
String name, String description, EvaluatorFunctionType type, boolean required) {
44+
}
45+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.evaluator;
18+
19+
import java.util.List;
20+
21+
/**
22+
* Factory interface for providing evaluator function definitions.
23+
*
24+
* @author Ivica Cardic
25+
*/
26+
public interface EvaluatorFunctionDefinitionFactory {
27+
28+
/**
29+
* Returns all evaluator function definitions provided by this factory.
30+
*
31+
* @return a list of {@link EvaluatorFunctionDefinition} instances
32+
*/
33+
List<EvaluatorFunctionDefinition> getDefinitions();
34+
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.evaluator;
18+
19+
import java.util.ArrayList;
20+
import java.util.Collections;
21+
import java.util.List;
22+
23+
/**
24+
* Fluent DSL for building {@link EvaluatorFunctionDefinition} instances.
25+
*
26+
* @author Ivica Cardic
27+
*/
28+
public final class EvaluatorFunctionDsl {
29+
30+
private EvaluatorFunctionDsl() {
31+
}
32+
33+
/**
34+
* Creates a new modifiable function definition with the given name.
35+
*
36+
* @param name the function name as it appears in expressions
37+
* @return a new {@link ModifiableEvaluatorFunctionDefinition}
38+
*/
39+
public static ModifiableEvaluatorFunctionDefinition function(String name) {
40+
return new ModifiableEvaluatorFunctionDefinition(name);
41+
}
42+
43+
/**
44+
* Creates a new modifiable parameter definition with the given name.
45+
*
46+
* @param name the parameter name
47+
* @return a new {@link ModifiableEvaluatorFunctionParameter}
48+
*/
49+
public static ModifiableEvaluatorFunctionParameter parameter(String name) {
50+
return new ModifiableEvaluatorFunctionParameter(name);
51+
}
52+
53+
/**
54+
* Mutable builder for {@link EvaluatorFunctionDefinition}.
55+
*
56+
* @author Ivica Cardic
57+
*/
58+
public static final class ModifiableEvaluatorFunctionDefinition {
59+
60+
private EvaluatorFunctionCategory category;
61+
private String description;
62+
private String example;
63+
private final String name;
64+
private List<ModifiableEvaluatorFunctionParameter> parameters = new ArrayList<>();
65+
private EvaluatorFunctionType returnType;
66+
private String title;
67+
68+
private ModifiableEvaluatorFunctionDefinition(String name) {
69+
this.name = name;
70+
}
71+
72+
public ModifiableEvaluatorFunctionDefinition title(String title) {
73+
this.title = title;
74+
75+
return this;
76+
}
77+
78+
public ModifiableEvaluatorFunctionDefinition description(String description) {
79+
this.description = description;
80+
81+
return this;
82+
}
83+
84+
public ModifiableEvaluatorFunctionDefinition category(EvaluatorFunctionCategory category) {
85+
this.category = category;
86+
87+
return this;
88+
}
89+
90+
public ModifiableEvaluatorFunctionDefinition parameters(ModifiableEvaluatorFunctionParameter... parameters) {
91+
this.parameters = List.of(parameters);
92+
93+
return this;
94+
}
95+
96+
public ModifiableEvaluatorFunctionDefinition returnType(EvaluatorFunctionType returnType) {
97+
this.returnType = returnType;
98+
99+
return this;
100+
}
101+
102+
public ModifiableEvaluatorFunctionDefinition example(String example) {
103+
this.example = example;
104+
105+
return this;
106+
}
107+
108+
/**
109+
* Builds an immutable {@link EvaluatorFunctionDefinition} from this builder's current state.
110+
*
111+
* @return a new {@link EvaluatorFunctionDefinition}
112+
*/
113+
public EvaluatorFunctionDefinition toDefinition() {
114+
List<EvaluatorFunctionDefinition.EvaluatorFunctionParameter> builtParameters = parameters.stream()
115+
.map(ModifiableEvaluatorFunctionParameter::toParameter)
116+
.toList();
117+
118+
return new EvaluatorFunctionDefinition(
119+
name, title, description, category, Collections.unmodifiableList(builtParameters), returnType, example);
120+
}
121+
}
122+
123+
/**
124+
* Mutable builder for {@link EvaluatorFunctionDefinition.EvaluatorFunctionParameter}.
125+
*
126+
* @author Ivica Cardic
127+
*/
128+
public static final class ModifiableEvaluatorFunctionParameter {
129+
130+
private String description;
131+
private final String name;
132+
private boolean required = true;
133+
private EvaluatorFunctionType type;
134+
135+
private ModifiableEvaluatorFunctionParameter(String name) {
136+
this.name = name;
137+
}
138+
139+
public ModifiableEvaluatorFunctionParameter description(String description) {
140+
this.description = description;
141+
142+
return this;
143+
}
144+
145+
public ModifiableEvaluatorFunctionParameter type(EvaluatorFunctionType type) {
146+
this.type = type;
147+
148+
return this;
149+
}
150+
151+
public ModifiableEvaluatorFunctionParameter required(boolean required) {
152+
this.required = required;
153+
154+
return this;
155+
}
156+
157+
EvaluatorFunctionDefinition.EvaluatorFunctionParameter toParameter() {
158+
return new EvaluatorFunctionDefinition.EvaluatorFunctionParameter(name, description, type, required);
159+
}
160+
}
161+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.evaluator;
18+
19+
/**
20+
* Enumerates the data types available for evaluator function parameters and return values.
21+
*
22+
* @author Ivica Cardic
23+
*/
24+
public enum EvaluatorFunctionType {
25+
26+
BOOLEAN,
27+
BYTE,
28+
CHARACTER,
29+
DATETIME,
30+
DOUBLE,
31+
FLOAT,
32+
INTEGER,
33+
LIST,
34+
LONG,
35+
MAP,
36+
NUMBER,
37+
SHORT,
38+
STRING
39+
}

server/libs/core/evaluator/evaluator-impl/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ dependencies {
22
api(project(":server:libs:core:evaluator:evaluator-api"))
33

44
implementation("org.slf4j:slf4j-api")
5+
implementation("org.springframework:spring-context")
56
implementation("org.springframework:spring-expression")
67

78
testImplementation(project(":server:libs:config:jackson-config"))

0 commit comments

Comments
 (0)