Skip to content

Commit 6732307

Browse files
authored
Merge pull request #46 from antmendoza/support-the-creation-of-actiondatafilter-object
Support the creation of 'actiondatafilter' object
2 parents 8b059cf + e6b3993 commit 6732307

File tree

3 files changed

+101
-14
lines changed

3 files changed

+101
-14
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2021-Present The Serverless Workflow Specification Authors
3+
* <p>
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+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
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+
18+
import {ActionDataFilterBuilder} from '../src/model/action-data-filter.builder';
19+
20+
describe("ActionDataFilter", () => {
21+
22+
it("should generate an empty object", () => {
23+
expect(new ActionDataFilterBuilder().build()).toEqual({});
24+
});
25+
26+
it("should generate a populated object", () => {
27+
expect(new ActionDataFilterBuilder()
28+
.withFromStateData("fromState")
29+
.withToStateData("toState")
30+
.withResults("result")
31+
.build()).toEqual(
32+
{
33+
fromStateData: "fromState",
34+
toStateData: "toState",
35+
results: "result",
36+
},
37+
);
38+
39+
40+
});
41+
42+
43+
});
44+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2021-Present The Serverless Workflow Specification Authors
3+
* <p>
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+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
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+
import {ActionDataFilterType} from '../index';
18+
19+
export class ActionDataFilterBuilder {
20+
private readonly model: ActionDataFilterType = {};
21+
22+
23+
withFromStateData(value: string): ActionDataFilterBuilder {
24+
this.model.fromStateData = value;
25+
return this;
26+
}
27+
28+
withToStateData(value: string): ActionDataFilterBuilder {
29+
this.model.toStateData = value;
30+
return this;
31+
}
32+
33+
withResults(value: string): ActionDataFilterBuilder {
34+
this.model.results = value;
35+
return this;
36+
}
37+
38+
build(): ActionDataFilterType {
39+
return this.model;
40+
}
41+
42+
}

src/model/types.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ export type EventRefType = {
7373
};
7474
};
7575

76+
export type ActionDataFilterType = {
77+
/**
78+
* Workflow expression that selects state data that the state action can use
79+
*/
80+
fromStateData?: string;
81+
/**
82+
* Workflow expression that filters the actions data results
83+
*/
84+
results?: string;
85+
/**
86+
* Workflow expression that selects a state data element to which the action results should be added/merged into. If not specified, denote, the top-level state data element
87+
*/
88+
toStateData?: string;
89+
};
7690
export type ActionType = {
7791
/**
7892
* Unique action definition name
@@ -90,20 +104,7 @@ export type ActionType = {
90104
/**
91105
* Action data filter
92106
*/
93-
actionDataFilter?: {
94-
/**
95-
* Workflow expression that selects state data that the state action can use
96-
*/
97-
fromStateData?: string;
98-
/**
99-
* Workflow expression that filters the actions data results
100-
*/
101-
results?: string;
102-
/**
103-
* Workflow expression that selects a state data element to which the action results should be added/merged into. If not specified, denote, the top-level state data element
104-
*/
105-
toStateData?: string;
106-
};
107+
actionDataFilter?: ActionDataFilterType;
107108
};
108109
export type ActionsType = ActionType[];
109110

0 commit comments

Comments
 (0)