Skip to content

Commit a1317de

Browse files
committed
add carauctionbids example
Signed-off-by: Antonio Mendoza Pérez <[email protected]>
1 parent 44e5d20 commit a1317de

18 files changed

+603
-177
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
"ts-node": "^9.1.1"
3737
},
3838
"files": [
39-
"dist/src/*",
40-
"dist/base-workflow.*",
41-
"dist/index.*"
39+
"dist/src/*"
4240
]
4341
}

spec/applicantrequest.spec.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.
File renamed without changes.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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 {WorkflowBuilder} from "../../src/model/workflow.builder";
18+
import * as fs from "fs";
19+
import {FunctionBuilder} from "../../src/model/function.builder";
20+
import {DatabasedSwitchBuilder} from "../../src/model/databased-switch.builder";
21+
import {TransitiondataconditionBuilder} from "../../src/model/transitiondatacondition.builder";
22+
import {OperationStateBuilder} from "../../src/model/operation-state.builder";
23+
import {SubFlowStateBuilder} from "../../src/model/sub-flow-state.builder";
24+
import {ActionBuilder} from "../../src/model/action.builder";
25+
import {ArgumentsBuilder} from "../../src/model/arguments.builder";
26+
import {DefaultTransitionTypeBuilder} from "../../src/model/default-transition-type.builder";
27+
28+
29+
describe("applicationrequest workflow example", () => {
30+
31+
32+
it('should generate Workflow object', function () {
33+
34+
const workflow = new WorkflowBuilder()
35+
.withId("applicantrequest")
36+
.withVersion("1.0")
37+
.withName("Applicant Request Decision Workflow")
38+
.withDescription("Determine if applicant request is valid")
39+
.withStart("CheckApplication")
40+
.withFunctions([new FunctionBuilder()
41+
.withName("sendRejectionEmailFunction")
42+
.withOperation("http://myapis.org/applicationapi.json#emailRejection")
43+
.build()])
44+
.withStates([
45+
new DatabasedSwitchBuilder()
46+
.withName("CheckApplication")
47+
.withDataConditions(
48+
[new TransitiondataconditionBuilder()
49+
.withCondition("${ .applicants | .age >= 18 }")
50+
.withTransition("StartApplication")
51+
.build(),
52+
new TransitiondataconditionBuilder()
53+
.withCondition("${ .applicants | .age < 18 }")
54+
.withTransition("RejectApplication")
55+
.build()])
56+
.withDefault(new DefaultTransitionTypeBuilder()
57+
.withTransition(
58+
"RejectApplication",
59+
).build())
60+
.build(),
61+
new SubFlowStateBuilder().withName("StartApplication")
62+
.withWorkflowId("startApplicationWorkflowId")
63+
.withEnd(true)
64+
.build(),
65+
new OperationStateBuilder()
66+
.withName("RejectApplication")
67+
.withActionMode("sequential")
68+
.withEnd(true)
69+
.withActions([
70+
new ActionBuilder().withFunctionRef(
71+
new ArgumentsBuilder()
72+
.withRefName("sendRejectionEmailFunction")
73+
.withArguments({applicant: '${ .applicant }'})
74+
.build(),
75+
)
76+
.build(),
77+
])
78+
.build(),
79+
])
80+
.build();
81+
82+
83+
const expected = JSON.parse(fs.readFileSync("./spec/examples/applicantrequest.json")
84+
.toLocaleString()) as any;
85+
expect(workflow).toEqual(expected);
86+
87+
});
88+
89+
90+
});

spec/examples/carauctionbids.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"id": "handleCarAuctionBid",
3+
"version": "1.0",
4+
"name": "Car Auction Bidding Workflow",
5+
"description": "Store a single bid whole the car auction is active",
6+
"start": {
7+
"stateName": "StoreCarAuctionBid",
8+
"schedule": "2020-03-20T09:00:00Z/2020-03-20T15:00:00Z"
9+
},
10+
"functions": [
11+
{
12+
"name": "StoreBidFunction",
13+
"operation": "http://myapis.org/carauctionapi.json#storeBid",
14+
"type": "rest"
15+
}
16+
],
17+
"events": [
18+
{
19+
"name": "CarBidEvent",
20+
"type": "carBidMadeType",
21+
"source": "carBidEventSource"
22+
}
23+
],
24+
"states": [
25+
{
26+
"name": "StoreCarAuctionBid",
27+
"type": "event",
28+
"exclusive": true,
29+
"onEvents": [
30+
{
31+
"eventRefs": [
32+
"CarBidEvent"
33+
],
34+
"actions": [
35+
{
36+
"functionRef": {
37+
"refName": "StoreBidFunction",
38+
"arguments": {
39+
"bid": "${ .bid }"
40+
}
41+
}
42+
}
43+
]
44+
}
45+
],
46+
"end": true
47+
}
48+
]
49+
}

spec/examples/carauctionbids.spec.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 {ActionBuilder, FunctionBuilder, ArgumentsBuilder, WorkflowBuilder} from '../../src';
18+
import * as fs from 'fs';
19+
import {StartBuilder} from '../../src/model/start.builder';
20+
import {EventsBuilder} from '../../src/model/events.builder';
21+
import {EventBuilder} from '../../src/model/event.builder';
22+
import {EventStateBuilder} from '../../src/model/event-state.builder';
23+
import {OnEventBuilder} from '../../src/model/on-event.builder';
24+
25+
describe("carauctionbids workflow example", () => {
26+
27+
28+
it('should generate Workflow object', function () {
29+
30+
const workflow = new WorkflowBuilder()
31+
.withId("handleCarAuctionBid")
32+
.withVersion("1.0")
33+
.withName("Car Auction Bidding Workflow")
34+
.withDescription("Store a single bid whole the car auction is active")
35+
.withStart(new StartBuilder()
36+
.withName("StoreCarAuctionBid")
37+
.withSchedule("2020-03-20T09:00:00Z/2020-03-20T15:00:00Z").build())
38+
.withFunctions([new FunctionBuilder()
39+
.withName("StoreBidFunction")
40+
.withOperation("http://myapis.org/carauctionapi.json#storeBid")
41+
.build()])
42+
.withEvents(new EventsBuilder().withEvents(
43+
[new EventBuilder()
44+
.withName("CarBidEvent")
45+
.withType("carBidMadeType")
46+
.withSource("carBidEventSource")
47+
.build()],
48+
).build())
49+
.withStates([
50+
new EventStateBuilder()
51+
.withName("StoreCarAuctionBid")
52+
.withExclusive(true)
53+
.withOnEvents([
54+
new OnEventBuilder()
55+
.withEventsRef(["CarBidEvent"])
56+
.withActions([
57+
new ActionBuilder().withFunctionRef(
58+
new ArgumentsBuilder()
59+
.withRefName("StoreBidFunction")
60+
.withArguments({
61+
"bid": "${ .bid }",
62+
})
63+
.build()).build(),
64+
]).build(),
65+
])
66+
.withEnd(true)
67+
.build(),
68+
])
69+
.build();
70+
71+
72+
const expected = JSON.parse(fs.readFileSync("./spec/examples/carauctionbids.json")
73+
.toLocaleString()) as any;
74+
expect(workflow).toEqual(expected);
75+
76+
});
77+
78+
79+
});

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616
*/
1717
export {BaseWorkflow} from "./base-workflow";
1818
export {ActionBuilder} from "./model/action.builder";
19+
export {ArgumentsBuilder} from "./model/arguments.builder";
1920
export {DatabasedSwitchBuilder} from "./model/databased-switch.builder";
2021
export {DefaultTransitionTypeBuilder} from "./model/default-transition-type.builder";
21-
export {FunctionRefImplBuilder} from "./model/function-ref-impl.builder";
22+
export {EventBuilder} from "./model/event.builder";
23+
export {EventRefBuilder} from "./model/event-ref.builder";
24+
export {EventStateBuilder} from "./model/event-state.builder";
25+
export {EventsBuilder} from "./model/events.builder";
2226
export {FunctionBuilder} from "./model/function.builder";
2327
export {InjectStateBuilder} from "./model/inject-state.builder";
28+
export {OnEventBuilder} from "./model/on-event.builder";
29+
export {RepeatBuilder} from "./model/repeat.builder";
30+
export {StartBuilder} from "./model/start.builder";
2431
export {OperationStateBuilder} from "./model/operation-state.builder";
2532
export {SubFlowStateBuilder} from "./model/sub-flow-state.builder";
2633
export {TransitiondataconditionBuilder} from "./model/transitiondatacondition.builder";

src/model/action.builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
import {ActionDataFilterType, ActionType, EventRefType, FunctionRefType} from "./types";
17+
import {ActionDataFilterType, Action, EventRefType, FunctionRefType} from "./types";
1818

1919
export class ActionBuilder {
2020

21-
private model: ActionType = {};
21+
private model: Action = {};
2222

2323

2424
withFunctionRef(value: FunctionRefType): ActionBuilder {
@@ -48,7 +48,7 @@ export class ActionBuilder {
4848

4949
}
5050

51-
build(): ActionType {
51+
build(): Action {
5252

5353
if (!this.model.eventRef && !this.model.functionRef) {
5454
throw new Error("Either eventRef or functionRef have to be defined");

src/model/function-ref-impl.builder.ts renamed to src/model/arguments.builder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
import {FunctionRefImplArgumentsType, FunctionRefImplType} from "./types";
17+
import {Arguments, FunctionRefImplType} from "./types";
1818

19-
export class FunctionRefImplBuilder {
19+
export class ArgumentsBuilder {
2020
// @ts-ignore
2121
private model: FunctionRefImplType = {};
2222

2323

24-
withRefName(value: string): FunctionRefImplBuilder {
24+
withRefName(value: string): ArgumentsBuilder {
2525
this.model.refName = value;
2626
return this;
2727

2828
}
2929

30-
withArguments(value: FunctionRefImplArgumentsType): FunctionRefImplBuilder {
30+
withArguments(value: Arguments): ArgumentsBuilder {
3131
this.model.arguments = value;
3232
return this;
3333
}

0 commit comments

Comments
 (0)