diff --git a/pkg/workflows/sdk/builder.go b/pkg/workflows/sdk/builder.go index 138e55cf3..efefb681b 100644 --- a/pkg/workflows/sdk/builder.go +++ b/pkg/workflows/sdk/builder.go @@ -10,6 +10,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/capabilities" ) +// WorkflowSpecFactory is used to build WorkflowSpecs. type WorkflowSpecFactory struct { spec *WorkflowSpec names map[string]bool @@ -125,6 +126,8 @@ func (c *capDefinitionImpl[O]) self() CapDefinition[O] { func (c *capDefinitionImpl[O]) private() {} +// NewWorkflowSpecFactory initializes a WorkflowSpecFactory. This is usually the first function that is called +// when writing a new workflow. func NewWorkflowSpecFactory() *WorkflowSpecFactory { return &WorkflowSpecFactory{ spec: &WorkflowSpec{ diff --git a/pkg/workflows/sdk/compute_generated.go b/pkg/workflows/sdk/compute_generated.go index 5098ddc03..f086b22e9 100644 --- a/pkg/workflows/sdk/compute_generated.go +++ b/pkg/workflows/sdk/compute_generated.go @@ -10,6 +10,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/values" ) +// Compute1Inputs contains the inputs for a Compute call with 1 arguments. type Compute1Inputs[T0 any] struct { Arg0 CapDefinition[T0] } @@ -26,6 +27,11 @@ func (input Compute1Inputs[I0]) ToSteps() StepInputs { } } +// Compute1 is used to instantiate a Compute step with 1 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute1[I0 any, O any](w *WorkflowSpecFactory, ref string, input Compute1Inputs[I0], compute func(Runtime, I0) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0) (O, error) { return compute(r, i0) @@ -33,6 +39,12 @@ func Compute1[I0 any, O any](w *WorkflowSpecFactory, ref string, input Compute1I return Compute1WithConfig[I0, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute1 is an alternative to instantiate a Compute step with 1 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute1WithConfig[I0 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute1Inputs[I0], compute func(Runtime, C, I0) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { @@ -147,6 +159,7 @@ func Compute1WithMetadata[I0 any, O any](w *WorkflowSpecFactory, ref string, inp return &computeOutputCap[O]{(&Step[ComputeOutput[O]]{Definition: def}).AddTo(w)} } +// Compute2Inputs contains the inputs for a Compute call with 2 arguments. type Compute2Inputs[T0 any, T1 any] struct { Arg0 CapDefinition[T0] Arg1 CapDefinition[T1] @@ -166,6 +179,11 @@ func (input Compute2Inputs[I0, I1]) ToSteps() StepInputs { } } +// Compute2 is used to instantiate a Compute step with 2 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute2[I0 any, I1 any, O any](w *WorkflowSpecFactory, ref string, input Compute2Inputs[I0, I1], compute func(Runtime, I0, I1) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0, i1 I1) (O, error) { return compute(r, i0, i1) @@ -173,6 +191,12 @@ func Compute2[I0 any, I1 any, O any](w *WorkflowSpecFactory, ref string, input C return Compute2WithConfig[I0, I1, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute2 is an alternative to instantiate a Compute step with 2 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute2WithConfig[I0 any, I1 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute2Inputs[I0, I1], compute func(Runtime, C, I0, I1) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { @@ -287,6 +311,7 @@ func Compute2WithMetadata[I0 any, I1 any, O any](w *WorkflowSpecFactory, ref str return &computeOutputCap[O]{(&Step[ComputeOutput[O]]{Definition: def}).AddTo(w)} } +// Compute3Inputs contains the inputs for a Compute call with 3 arguments. type Compute3Inputs[T0 any, T1 any, T2 any] struct { Arg0 CapDefinition[T0] Arg1 CapDefinition[T1] @@ -309,6 +334,11 @@ func (input Compute3Inputs[I0, I1, I2]) ToSteps() StepInputs { } } +// Compute3 is used to instantiate a Compute step with 3 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute3[I0 any, I1 any, I2 any, O any](w *WorkflowSpecFactory, ref string, input Compute3Inputs[I0, I1, I2], compute func(Runtime, I0, I1, I2) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0, i1 I1, i2 I2) (O, error) { return compute(r, i0, i1, i2) @@ -316,6 +346,12 @@ func Compute3[I0 any, I1 any, I2 any, O any](w *WorkflowSpecFactory, ref string, return Compute3WithConfig[I0, I1, I2, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute3 is an alternative to instantiate a Compute step with 3 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute3WithConfig[I0 any, I1 any, I2 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute3Inputs[I0, I1, I2], compute func(Runtime, C, I0, I1, I2) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { @@ -430,6 +466,7 @@ func Compute3WithMetadata[I0 any, I1 any, I2 any, O any](w *WorkflowSpecFactory, return &computeOutputCap[O]{(&Step[ComputeOutput[O]]{Definition: def}).AddTo(w)} } +// Compute4Inputs contains the inputs for a Compute call with 4 arguments. type Compute4Inputs[T0 any, T1 any, T2 any, T3 any] struct { Arg0 CapDefinition[T0] Arg1 CapDefinition[T1] @@ -455,6 +492,11 @@ func (input Compute4Inputs[I0, I1, I2, I3]) ToSteps() StepInputs { } } +// Compute4 is used to instantiate a Compute step with 4 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute4[I0 any, I1 any, I2 any, I3 any, O any](w *WorkflowSpecFactory, ref string, input Compute4Inputs[I0, I1, I2, I3], compute func(Runtime, I0, I1, I2, I3) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0, i1 I1, i2 I2, i3 I3) (O, error) { return compute(r, i0, i1, i2, i3) @@ -462,6 +504,12 @@ func Compute4[I0 any, I1 any, I2 any, I3 any, O any](w *WorkflowSpecFactory, ref return Compute4WithConfig[I0, I1, I2, I3, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute4 is an alternative to instantiate a Compute step with 4 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute4WithConfig[I0 any, I1 any, I2 any, I3 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute4Inputs[I0, I1, I2, I3], compute func(Runtime, C, I0, I1, I2, I3) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { @@ -576,6 +624,7 @@ func Compute4WithMetadata[I0 any, I1 any, I2 any, I3 any, O any](w *WorkflowSpec return &computeOutputCap[O]{(&Step[ComputeOutput[O]]{Definition: def}).AddTo(w)} } +// Compute5Inputs contains the inputs for a Compute call with 5 arguments. type Compute5Inputs[T0 any, T1 any, T2 any, T3 any, T4 any] struct { Arg0 CapDefinition[T0] Arg1 CapDefinition[T1] @@ -604,6 +653,11 @@ func (input Compute5Inputs[I0, I1, I2, I3, I4]) ToSteps() StepInputs { } } +// Compute5 is used to instantiate a Compute step with 5 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute5[I0 any, I1 any, I2 any, I3 any, I4 any, O any](w *WorkflowSpecFactory, ref string, input Compute5Inputs[I0, I1, I2, I3, I4], compute func(Runtime, I0, I1, I2, I3, I4) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0, i1 I1, i2 I2, i3 I3, i4 I4) (O, error) { return compute(r, i0, i1, i2, i3, i4) @@ -611,6 +665,12 @@ func Compute5[I0 any, I1 any, I2 any, I3 any, I4 any, O any](w *WorkflowSpecFact return Compute5WithConfig[I0, I1, I2, I3, I4, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute5 is an alternative to instantiate a Compute step with 5 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute5WithConfig[I0 any, I1 any, I2 any, I3 any, I4 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute5Inputs[I0, I1, I2, I3, I4], compute func(Runtime, C, I0, I1, I2, I3, I4) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { @@ -725,6 +785,7 @@ func Compute5WithMetadata[I0 any, I1 any, I2 any, I3 any, I4 any, O any](w *Work return &computeOutputCap[O]{(&Step[ComputeOutput[O]]{Definition: def}).AddTo(w)} } +// Compute6Inputs contains the inputs for a Compute call with 6 arguments. type Compute6Inputs[T0 any, T1 any, T2 any, T3 any, T4 any, T5 any] struct { Arg0 CapDefinition[T0] Arg1 CapDefinition[T1] @@ -756,6 +817,11 @@ func (input Compute6Inputs[I0, I1, I2, I3, I4, I5]) ToSteps() StepInputs { } } +// Compute6 is used to instantiate a Compute step with 6 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute6[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, O any](w *WorkflowSpecFactory, ref string, input Compute6Inputs[I0, I1, I2, I3, I4, I5], compute func(Runtime, I0, I1, I2, I3, I4, I5) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0, i1 I1, i2 I2, i3 I3, i4 I4, i5 I5) (O, error) { return compute(r, i0, i1, i2, i3, i4, i5) @@ -763,6 +829,12 @@ func Compute6[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, O any](w *Workflow return Compute6WithConfig[I0, I1, I2, I3, I4, I5, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute6 is an alternative to instantiate a Compute step with 6 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute6WithConfig[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute6Inputs[I0, I1, I2, I3, I4, I5], compute func(Runtime, C, I0, I1, I2, I3, I4, I5) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { @@ -877,6 +949,7 @@ func Compute6WithMetadata[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, O any] return &computeOutputCap[O]{(&Step[ComputeOutput[O]]{Definition: def}).AddTo(w)} } +// Compute7Inputs contains the inputs for a Compute call with 7 arguments. type Compute7Inputs[T0 any, T1 any, T2 any, T3 any, T4 any, T5 any, T6 any] struct { Arg0 CapDefinition[T0] Arg1 CapDefinition[T1] @@ -911,6 +984,11 @@ func (input Compute7Inputs[I0, I1, I2, I3, I4, I5, I6]) ToSteps() StepInputs { } } +// Compute7 is used to instantiate a Compute step with 7 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute7[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, O any](w *WorkflowSpecFactory, ref string, input Compute7Inputs[I0, I1, I2, I3, I4, I5, I6], compute func(Runtime, I0, I1, I2, I3, I4, I5, I6) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0, i1 I1, i2 I2, i3 I3, i4 I4, i5 I5, i6 I6) (O, error) { return compute(r, i0, i1, i2, i3, i4, i5, i6) @@ -918,6 +996,12 @@ func Compute7[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, O any](w * return Compute7WithConfig[I0, I1, I2, I3, I4, I5, I6, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute7 is an alternative to instantiate a Compute step with 7 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute7WithConfig[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute7Inputs[I0, I1, I2, I3, I4, I5, I6], compute func(Runtime, C, I0, I1, I2, I3, I4, I5, I6) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { @@ -1032,6 +1116,7 @@ func Compute7WithMetadata[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any return &computeOutputCap[O]{(&Step[ComputeOutput[O]]{Definition: def}).AddTo(w)} } +// Compute8Inputs contains the inputs for a Compute call with 8 arguments. type Compute8Inputs[T0 any, T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any] struct { Arg0 CapDefinition[T0] Arg1 CapDefinition[T1] @@ -1069,6 +1154,11 @@ func (input Compute8Inputs[I0, I1, I2, I3, I4, I5, I6, I7]) ToSteps() StepInputs } } +// Compute8 is used to instantiate a Compute step with 8 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute8[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, I7 any, O any](w *WorkflowSpecFactory, ref string, input Compute8Inputs[I0, I1, I2, I3, I4, I5, I6, I7], compute func(Runtime, I0, I1, I2, I3, I4, I5, I6, I7) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0, i1 I1, i2 I2, i3 I3, i4 I4, i5 I5, i6 I6, i7 I7) (O, error) { return compute(r, i0, i1, i2, i3, i4, i5, i6, i7) @@ -1076,6 +1166,12 @@ func Compute8[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, I7 any, O return Compute8WithConfig[I0, I1, I2, I3, I4, I5, I6, I7, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute8 is an alternative to instantiate a Compute step with 8 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute8WithConfig[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, I7 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute8Inputs[I0, I1, I2, I3, I4, I5, I6, I7], compute func(Runtime, C, I0, I1, I2, I3, I4, I5, I6, I7) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { @@ -1190,6 +1286,7 @@ func Compute8WithMetadata[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any return &computeOutputCap[O]{(&Step[ComputeOutput[O]]{Definition: def}).AddTo(w)} } +// Compute9Inputs contains the inputs for a Compute call with 9 arguments. type Compute9Inputs[T0 any, T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any] struct { Arg0 CapDefinition[T0] Arg1 CapDefinition[T1] @@ -1230,6 +1327,11 @@ func (input Compute9Inputs[I0, I1, I2, I3, I4, I5, I6, I7, I8]) ToSteps() StepIn } } +// Compute9 is used to instantiate a Compute step with 9 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute9[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, I7 any, I8 any, O any](w *WorkflowSpecFactory, ref string, input Compute9Inputs[I0, I1, I2, I3, I4, I5, I6, I7, I8], compute func(Runtime, I0, I1, I2, I3, I4, I5, I6, I7, I8) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0, i1 I1, i2 I2, i3 I3, i4 I4, i5 I5, i6 I6, i7 I7, i8 I8) (O, error) { return compute(r, i0, i1, i2, i3, i4, i5, i6, i7, i8) @@ -1237,6 +1339,12 @@ func Compute9[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, I7 any, I8 return Compute9WithConfig[I0, I1, I2, I3, I4, I5, I6, I7, I8, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute9 is an alternative to instantiate a Compute step with 9 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute9WithConfig[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, I7 any, I8 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute9Inputs[I0, I1, I2, I3, I4, I5, I6, I7, I8], compute func(Runtime, C, I0, I1, I2, I3, I4, I5, I6, I7, I8) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { @@ -1351,6 +1459,7 @@ func Compute9WithMetadata[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any return &computeOutputCap[O]{(&Step[ComputeOutput[O]]{Definition: def}).AddTo(w)} } +// Compute10Inputs contains the inputs for a Compute call with 10 arguments. type Compute10Inputs[T0 any, T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any] struct { Arg0 CapDefinition[T0] Arg1 CapDefinition[T1] @@ -1394,6 +1503,11 @@ func (input Compute10Inputs[I0, I1, I2, I3, I4, I5, I6, I7, I8, I9]) ToSteps() S } } +// Compute10 is used to instantiate a Compute step with 10 arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute10[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, I7 any, I8 any, I9 any, O any](w *WorkflowSpecFactory, ref string, input Compute10Inputs[I0, I1, I2, I3, I4, I5, I6, I7, I8, I9], compute func(Runtime, I0, I1, I2, I3, I4, I5, I6, I7, I8, I9) (O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, i0 I0, i1 I1, i2 I2, i3 I3, i4 I4, i5 I5, i6 I6, i7 I7, i8 I8, i9 I9) (O, error) { return compute(r, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9) @@ -1401,6 +1515,12 @@ func Compute10[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, I7 any, I return Compute10WithConfig[I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute10 is an alternative to instantiate a Compute step with 10 arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute10WithConfig[I0 any, I1 any, I2 any, I3 any, I4 any, I5 any, I6 any, I7 any, I8 any, I9 any, O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute10Inputs[I0, I1, I2, I3, I4, I5, I6, I7, I8, I9], compute func(Runtime, C, I0, I1, I2, I3, I4, I5, I6, I7, I8, I9) (O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { diff --git a/pkg/workflows/sdk/gen/compute.go.tmpl b/pkg/workflows/sdk/gen/compute.go.tmpl index 00c0ffc29..cce2e37ef 100644 --- a/pkg/workflows/sdk/gen/compute.go.tmpl +++ b/pkg/workflows/sdk/gen/compute.go.tmpl @@ -7,6 +7,7 @@ import ( ) {{- range . }} +// Compute{{.}}Inputs contains the inputs for a Compute call with {{.}} arguments. type Compute{{.}}Inputs[{{range RangeNum . }}T{{.}} any,{{ end }}] struct { {{- range RangeNum .}} Arg{{.}} CapDefinition[T{{.}}] @@ -30,6 +31,11 @@ func (input Compute{{.}}Inputs[{{range RangeNum . }}I{{.}},{{ end }}]) ToSteps() } } +// Compute{{.}} is used to instantiate a Compute step with {{.}} arguments. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), and I1->I (the inputs that were passed in) func Compute{{.}}[{{range RangeNum .}}I{{.}} any, {{ end }}O any](w *WorkflowSpecFactory, ref string, input Compute{{.}}Inputs[{{range RangeNum . }}I{{.}},{{ end }}], compute func(Runtime, {{range RangeNum . }}I{{.}},{{ end }})(O, error)) ComputeOutputCap[O] { adaptedComputeFunc := func(r Runtime, _ struct{}, {{range RangeNum .}}i{{.}} I{{.}},{{end}}) (O, error) { return compute(r, {{range RangeNum .}}i{{.}},{{end}}) @@ -37,6 +43,12 @@ func Compute{{.}}[{{range RangeNum .}}I{{.}} any, {{ end }}O any](w *WorkflowSp return Compute{{.}}WithConfig[{{range RangeNum .}}I{{.}}, {{ end }}O](w, ref, EmptyComputeConfig(), input, adaptedComputeFunc) } +// Compute{{.}} is an alternative to instantiate a Compute step with {{.}} arguments, including config as well. +// - `w` is the spec factory instantiated via sdk.NewWorkflowSpecFactory() +// - `ref` is the name name of the step. This must be unique at the workflow level. +// - `config` contains the config of the step, wrapped in a `ComputeConfig` struct. +// - `input` contains the inputs to the step +// - `compute` is the function that performs the user-defined computation. The inputs to this function are `Runtime` (used to access external APIs like the logger and fetch), `C` (the unwrapped config that was passed in), and I1->I (the inputs that were passed in) func Compute{{.}}WithConfig[{{range RangeNum .}}I{{.}} any, {{ end }}O any, C any](w *WorkflowSpecFactory, ref string, config *ComputeConfig[C], input Compute{{.}}Inputs[{{range RangeNum . }}I{{.}},{{ end }}], compute func(Runtime, C, {{range RangeNum . }}I{{.}},{{ end }})(O, error)) ComputeOutputCap[O] { cm, err := config.ToMap() if err != nil { diff --git a/pkg/workflows/sdk/runtime.go b/pkg/workflows/sdk/runtime.go index d6403717e..9c431161e 100644 --- a/pkg/workflows/sdk/runtime.go +++ b/pkg/workflows/sdk/runtime.go @@ -5,6 +5,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" ) +// BreakErr can be used inside the compute capability function to stop the execution of the workflow. var BreakErr = capabilities.ErrStopExecution type MessageEmitter interface { @@ -16,7 +17,10 @@ type MessageEmitter interface { With(kvs ...string) MessageEmitter } -// Guest interface +// Runtime exposes external system calls to workflow authors. +// - `Logger` can be used to log messages +// - `Emitter` can be used to send messages to beholder +// - `Fetch` can be used to make external HTTP calls type Runtime interface { Logger() logger.Logger Fetch(req FetchRequest) (FetchResponse, error)