Skip to content

Commit eadb677

Browse files
author
André R. de Miranda
committed
proposal sdk-go to v1.0.0-alpha2
Signed-off-by: André R. de Miranda <[email protected]>
1 parent 7219d5c commit eadb677

File tree

172 files changed

+2505
-19523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+2505
-19523
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ lint:
1515
.PHONY: test
1616
coverage="false"
1717

18-
test: deepcopy buildergen
18+
#test: deepcopy buildergen
19+
test:
1920
make lint
2021
@go test ./...
2122

builder/builder.go

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The Serverless Workflow Specification Authors
1+
// Copyright 2024 The Serverless Workflow Specification Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -17,45 +17,37 @@ package builder
1717
import (
1818
"encoding/json"
1919

20+
"github.com/serverlessworkflow/sdk-go/v4/validate"
2021
"sigs.k8s.io/yaml"
21-
22-
"github.com/serverlessworkflow/sdk-go/v2/model"
23-
val "github.com/serverlessworkflow/sdk-go/v2/validator"
2422
)
2523

26-
func New() *model.WorkflowBuilder {
27-
return model.NewWorkflowBuilder()
28-
}
29-
30-
func Yaml(builder *model.WorkflowBuilder) ([]byte, error) {
24+
func Validate(builder *WorkflowBuilder) error {
3125
data, err := Json(builder)
3226
if err != nil {
33-
return nil, err
27+
return err
3428
}
35-
return yaml.JSONToYAML(data)
36-
}
3729

38-
func Json(builder *model.WorkflowBuilder) ([]byte, error) {
39-
workflow, err := Object(builder)
30+
err = validate.FromJSONSource(data)
4031
if err != nil {
41-
return nil, err
32+
return err
4233
}
43-
return json.Marshal(workflow)
34+
35+
return nil
4436
}
4537

46-
func Object(builder *model.WorkflowBuilder) (*model.Workflow, error) {
47-
workflow := builder.Build()
48-
ctx := model.NewValidatorContext(&workflow)
49-
if err := val.GetValidator().StructCtx(ctx, workflow); err != nil {
38+
func Json(builder *WorkflowBuilder) ([]byte, error) {
39+
data, err := json.MarshalIndent(builder.Node(), "", " ")
40+
if err != nil {
5041
return nil, err
5142
}
52-
return &workflow, nil
43+
44+
return data, nil
5345
}
5446

55-
func Validate(object interface{}) error {
56-
ctx := model.NewValidatorContext(object)
57-
if err := val.GetValidator().StructCtx(ctx, object); err != nil {
58-
return val.WorkflowError(err)
47+
func Yaml(builder *WorkflowBuilder) ([]byte, error) {
48+
data, err := Json(builder)
49+
if err != nil {
50+
return nil, err
5951
}
60-
return nil
52+
return yaml.JSONToYAML(data)
6153
}

builder/builder_test.go

Lines changed: 0 additions & 120 deletions
This file was deleted.

builder/call.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2024 The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package builder
16+
17+
import "github.com/serverlessworkflow/sdk-go/v4/graph"
18+
19+
type CallKind string
20+
21+
const (
22+
CallKindHttp CallKind = "http"
23+
CallKindGrpc CallKind = "grpc"
24+
)
25+
26+
type CallBuilder struct {
27+
root *graph.Node
28+
with *MapBuilder
29+
}
30+
31+
func (b *CallBuilder) SetCall(call CallKind) *CallBuilder {
32+
b.root.Edge("call").SetString(string(call))
33+
return b
34+
}
35+
36+
func (b *CallBuilder) GetCall() string {
37+
return b.root.Edge("call").GetString()
38+
}
39+
40+
func (b *CallBuilder) With() *MapBuilder {
41+
if b.with == nil {
42+
b.with = NewMapBuilder(b.root.Edge("with"))
43+
}
44+
return b.with
45+
}
46+
47+
func NewCallBuilder(root *graph.Node) *CallBuilder {
48+
return &CallBuilder{
49+
root: root,
50+
}
51+
}

builder/do.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2024 The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package builder
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/serverlessworkflow/sdk-go/v4/graph"
21+
)
22+
23+
type DoBuilder struct {
24+
root *graph.Node
25+
tasks []any
26+
}
27+
28+
func (b *DoBuilder) AddCall(name string) (*CallBuilder, int) {
29+
index := len(b.tasks)
30+
nodeIndex := b.root.Edge(fmt.Sprintf("%d", index))
31+
nodeName := nodeIndex.Edge(name)
32+
33+
callBuilder := NewCallBuilder(nodeName)
34+
b.tasks = append(b.tasks, callBuilder)
35+
return callBuilder, index
36+
}
37+
38+
func (b *DoBuilder) AddWait(name string) (*WaitBuilder, int) {
39+
index := len(b.tasks)
40+
nodeIndex := b.root.Edge(fmt.Sprintf("%d", index))
41+
nodeName := nodeIndex.Edge(name)
42+
43+
waitBuilder := NewWaitBuilder(nodeName)
44+
b.tasks = append(b.tasks, waitBuilder)
45+
return waitBuilder, index
46+
}
47+
48+
func (b *DoBuilder) RemoveTask(index int) *DoBuilder {
49+
b.tasks = append(b.tasks[:index], b.tasks[index+1:]...)
50+
return b
51+
}
52+
53+
func NewDoBuilder(root *graph.Node) *DoBuilder {
54+
root.List(true)
55+
return &DoBuilder{
56+
root: root,
57+
tasks: []any{},
58+
}
59+
}

builder/document.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2024 The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package builder
16+
17+
import "github.com/serverlessworkflow/sdk-go/v4/graph"
18+
19+
type DocumentBuilder struct {
20+
root *graph.Node
21+
}
22+
23+
func (b *DocumentBuilder) SetDSL(dsl string) *DocumentBuilder {
24+
node := b.root.Edge("dsl")
25+
node.SetString(dsl)
26+
return b
27+
}
28+
29+
func (b *DocumentBuilder) GetDSL() string {
30+
node := b.root.Edge("dsl")
31+
return node.GetString()
32+
}
33+
34+
func (b *DocumentBuilder) SetNamespace(dsl string) *DocumentBuilder {
35+
node := b.root.Edge("namespace")
36+
node.SetString(dsl)
37+
return b
38+
}
39+
40+
func (b *DocumentBuilder) GetNamespace() string {
41+
node := b.root.Edge("namespace")
42+
return node.GetString()
43+
}
44+
45+
func (b *DocumentBuilder) SetName(dsl string) *DocumentBuilder {
46+
node := b.root.Edge("name")
47+
node.SetString(dsl)
48+
return b
49+
}
50+
51+
func (b *DocumentBuilder) GetName() string {
52+
node := b.root.Edge("name")
53+
return node.GetString()
54+
}
55+
56+
func (b *DocumentBuilder) SetVersion(dsl string) *DocumentBuilder {
57+
node := b.root.Edge("version")
58+
node.SetString(dsl)
59+
return b
60+
}
61+
62+
func (b *DocumentBuilder) GetVersion() string {
63+
node := b.root.Edge("version")
64+
return node.GetString()
65+
}
66+
67+
func NewDocumentBuilder(root *graph.Node) *DocumentBuilder {
68+
documentBuilder := &DocumentBuilder{
69+
root: root,
70+
}
71+
documentBuilder.SetDSL("1.0.0-alpha1")
72+
return documentBuilder
73+
}

0 commit comments

Comments
 (0)