/
loop_handler.gen.go
286 lines (244 loc) · 5.34 KB
/
loop_handler.gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
package automation
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
// automation/automation/loop_handler.yaml
import (
"context"
atypes "github.com/cortezaproject/corteza/server/automation/types"
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/pkg/wfexec"
"io"
)
var _ wfexec.ExecResponse
type (
loopHandlerRegistry interface {
AddFunctions(ff ...*atypes.Function)
Type(ref string) expr.Type
}
)
func (h loopHandler) register() {
h.reg.AddFunctions(
h.Sequence(),
h.Do(),
h.Each(),
h.Lines(),
)
}
type (
loopSequenceArgs struct {
hasFirst bool
First int64
hasLast bool
Last int64
hasStep bool
Step int64
}
loopSequenceResults struct {
Counter int64
IsFirst bool
IsLast bool
}
)
// Sequence function Iterates over sequence of numbers
//
// expects implementation of sequence function:
// func (h loopHandler) sequence(ctx context.Context, args *loopSequenceArgs) (results *loopSequenceResults, err error) {
// return
// }
func (h loopHandler) Sequence() *atypes.Function {
return &atypes.Function{
Ref: "loopSequence",
Kind: "iterator",
Labels: map[string]string(nil),
Meta: &atypes.FunctionMeta{
Short: "Iterates over sequence of numbers",
},
Parameters: []*atypes.Param{
{
Name: "first",
Types: []string{"Integer"},
},
{
Name: "last",
Types: []string{"Integer"},
},
{
Name: "step",
Types: []string{"Integer"},
},
},
Results: []*atypes.Param{
{
Name: "counter",
Types: []string{"Integer"},
},
{
Name: "isFirst",
Types: []string{"Boolean"},
},
{
Name: "isLast",
Types: []string{"Boolean"},
},
},
Iterator: func(ctx context.Context, in *expr.Vars) (out wfexec.IteratorHandler, err error) {
var (
args = &loopSequenceArgs{
hasFirst: in.Has("first"),
hasLast: in.Has("last"),
hasStep: in.Has("step"),
}
)
if err = in.Decode(args); err != nil {
return
}
return h.sequence(ctx, args)
},
}
}
type (
loopDoArgs struct {
hasWhile bool
While string
}
)
// Do function Condition
//
// expects implementation of do function:
// func (h loopHandler) do(ctx context.Context, args *loopDoArgs) (err error) {
// return
// }
func (h loopHandler) Do() *atypes.Function {
return &atypes.Function{
Ref: "loopDo",
Kind: "iterator",
Labels: map[string]string(nil),
Meta: &atypes.FunctionMeta{
Short: "Condition",
Description: "Iterates while condition is true",
},
Parameters: []*atypes.Param{
{
Name: "while",
Types: []string{"String"}, Required: true,
Meta: &atypes.ParamMeta{
Label: "Expression tested before each iteration",
Description: "Expression to be evaluated each iteration; loop will continue until expression is true",
},
},
},
Iterator: func(ctx context.Context, in *expr.Vars) (out wfexec.IteratorHandler, err error) {
var (
args = &loopDoArgs{
hasWhile: in.Has("while"),
}
)
if err = in.Decode(args); err != nil {
return
}
return h.do(ctx, args)
},
}
}
type (
loopEachArgs struct {
hasItems bool
Items []expr.TypedValue
}
loopEachResults struct {
Item interface{}
}
)
// Each function Items
//
// expects implementation of each function:
// func (h loopHandler) each(ctx context.Context, args *loopEachArgs) (results *loopEachResults, err error) {
// return
// }
func (h loopHandler) Each() *atypes.Function {
return &atypes.Function{
Ref: "loopEach",
Kind: "iterator",
Labels: map[string]string(nil),
Meta: &atypes.FunctionMeta{
Short: "Items",
Description: "Iterates over set of items",
},
Parameters: []*atypes.Param{
{
Name: "items",
Types: []string{"Array"}, Required: true,
},
},
Results: []*atypes.Param{
{
Name: "item",
Types: []string{"Any"},
},
},
Iterator: func(ctx context.Context, in *expr.Vars) (out wfexec.IteratorHandler, err error) {
var (
args = &loopEachArgs{
hasItems: in.Has("items"),
}
)
if err = in.Decode(args); err != nil {
return
}
return h.each(ctx, args)
},
}
}
type (
loopLinesArgs struct {
hasStream bool
Stream io.Reader
}
loopLinesResults struct {
Line string
}
)
// Lines function Stream lines
//
// expects implementation of lines function:
// func (h loopHandler) lines(ctx context.Context, args *loopLinesArgs) (results *loopLinesResults, err error) {
// return
// }
func (h loopHandler) Lines() *atypes.Function {
return &atypes.Function{
Ref: "loopLines",
Kind: "iterator",
Labels: map[string]string(nil),
Meta: &atypes.FunctionMeta{
Short: "Stream lines",
Description: "Iterates over lines from stream",
},
Parameters: []*atypes.Param{
{
Name: "stream",
Types: []string{"Reader"}, Required: true,
},
},
Results: []*atypes.Param{
{
Name: "line",
Types: []string{"String"},
},
},
Iterator: func(ctx context.Context, in *expr.Vars) (out wfexec.IteratorHandler, err error) {
var (
args = &loopLinesArgs{
hasStream: in.Has("stream"),
}
)
if err = in.Decode(args); err != nil {
return
}
return h.lines(ctx, args)
},
}
}