snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s

This commit is contained in:
upstream-mirror
2026-09-18 01:22:23 +05:00
commit 7e385fc126
8391 changed files with 1766236 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
package wfexec
import (
"context"
"github.com/cortezaproject/corteza/server/pkg/expr"
)
type (
// Iterator can be returned from Exec fn as ExecResponse
//
// It helps session's exec fn() to properly navigate through graph
// by calling is/break/iterator/next function
Iterator interface {
// Is the given step this iterator step
Is(Step) bool
// Initialize iterator
Start(context.Context, *expr.Vars) error
// Break fn is called when loop is forcefully broken
Break() Step
Iterator() Step
// Next is called before each iteration and returns
// 1st step of the iteration branch and variables that are added to the scope
Next(context.Context, *expr.Vars) (Step, *expr.Vars, error)
}
ResultEvaluator interface {
EvalResults(ctx context.Context, results *expr.Vars) (out *expr.Vars, err error)
}
IteratorHandler interface {
Start(context.Context, *expr.Vars) error
More(context.Context, *expr.Vars) (bool, error)
Next(context.Context, *expr.Vars) (*expr.Vars, error)
}
// Handles communication between Session's exec() fn and iterator handler
genericIterator struct {
iter, next, exit Step
h IteratorHandler
}
)
const (
DefaultMaxIteratorBufferSize uint = 1000
)
var (
MaxIteratorBufferSize uint = DefaultMaxIteratorBufferSize
)
// GenericIterator creates a wrapper around IteratorHandler and
// returns genericIterator that implements Iterator interface
func GenericIterator(iter, next, exit Step, h IteratorHandler) Iterator {
return &genericIterator{
iter: iter,
next: next,
exit: exit,
h: h,
}
}
func (i *genericIterator) Is(s Step) bool { return i.iter == s }
func (i *genericIterator) Start(ctx context.Context, s *expr.Vars) error { return i.h.Start(ctx, s) }
func (i *genericIterator) Break() Step { return i.exit }
func (i *genericIterator) Iterator() Step { return i.iter }
// Next calls More and Next functions on iterator handler.
//
// If iterator step (iter field) implements ResultEvaluator it calls
// EvalResults on it before returning it. If iterator step does not implement it,
// results are omitted.
func (i *genericIterator) Next(ctx context.Context, scope *expr.Vars) (next Step, out *expr.Vars, err error) {
var (
more bool
results *expr.Vars
)
if more, err = i.h.More(ctx, scope); err != nil || !more {
return
}
if results, err = i.h.Next(ctx, scope); err != nil {
return
}
if re, is := i.iter.(ResultEvaluator); is {
if out, err = re.EvalResults(ctx, results); err != nil {
return
}
}
next = i.next
return
}
func GenericResourceNextCheck(useLimit bool, ptr, buffSize, total, limit uint, hasMore bool) bool {
// if we can go more (inverted)...
// Treat limit = 0 the same as no limit (consistent with other bits of the system)
if (useLimit && limit != 0) && ptr+total >= limit {
return false
}
// if we have some buffer left...
if ptr < buffSize {
return true
}
// if we can get more...
return hasMore
}