contract

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2021 License: BSD-3-Clause Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandRef added in v0.1.4

func ExpandRef(def interface{}) (bool, error)

ExpandRef expand schema ref, returns true if some refs are replaced

func ExtractFlowSchema added in v0.1.4

func ExtractFlowSchema(schemadef interface{}) schema.Schema

ExtractFlowSchema create serializable schema for a flow for a given schema def to work around FE import issue, the schema def is changed as follows:

for object, export only properties of the object
for array, create app schema, and export a ref

func GetAppSchemas added in v0.1.4

func GetAppSchemas() (map[string]*schema.Def, error)

GetAppSchemas construct and return Flogo app schema defs

func ParametersToSchema added in v0.1.4

func ParametersToSchema(params []*Parameter) map[string]interface{}

ParametersToSchema convert transaction parameters to schema def

func ReadAppConfig

func ReadAppConfig(configFile string) (*app.Config, map[string]*definition.DefinitionRep, error)

ReadAppConfig reads a Flogo app json file and returns app.Config

func SetAppResources added in v0.1.2

func SetAppResources(config *app.Config, resources map[string]*definition.DefinitionRep)

SetAppResources serialize flow resources and add them to app config

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase converts camel case string to snake case

func WriteAppConfig

func WriteAppConfig(config *app.Config, outFile string) error

WriteAppConfig serializes an app config and its resources

Types

type Action

type Action struct {
	Activity    string                 `json:"activity"`
	Description string                 `json:"description,omitempty"`
	Name        string                 `json:"name,omitempty"`
	Ledger      map[string]interface{} `json:"ledger,omitempty"`
	Config      map[string]interface{} `json:"config,omitempty"`
	Input       *Input                 `json:"input,omitempty"`
}

Action defines an activity for processing a transaction

type Components

type Components struct {
	Schemas map[string]*Schema `json:"schemas"`
}

Components contains reusable schema definitions

type Condition

type Condition struct {
	Name         string `json:"name,omitempty"`
	Description  string `json:"description"`
	Prerequisite string `json:"prerequisite,omitempty"`
	Expr         string `json:"expr,omitempty"`
}

Condition defines condition for executing list of actions for a transaction

type Contract

type Contract struct {
	Name         string         `json:"name"`
	CID          string         `json:"cid"`
	Transactions []*Transaction `json:"transactions"`
	Info         *Info          `json:"info,omitempty"`
}

Contract defines a smart contract

func (*Contract) ToTrigger

func (c *Contract) ToTrigger(fe bool) (*trigger.Config, error)

ToTrigger converts contract transactions to trigger handlers

type FlowSchema added in v0.1.4

type FlowSchema struct {
	SchemaType  string `json:"type"`
	SchemaValue string `json:"value"`
}

FlowSchema implements schema.Schema, used for flow metadata

func (*FlowSchema) MarshalJSON added in v0.1.4

func (f *FlowSchema) MarshalJSON() ([]byte, error)

MarshalJSON customize JSON marshalling

func (*FlowSchema) Type added in v0.1.4

func (f *FlowSchema) Type() string

Type implement schema.Schema interface

func (*FlowSchema) Validate added in v0.1.4

func (f *FlowSchema) Validate(data interface{}) error

Validate implement schema.Schema interface

func (*FlowSchema) Value added in v0.1.4

func (f *FlowSchema) Value() string

Value implement schema.Schema interface

type Info

type Info struct {
	Title       string `json:"title"`
	Version     string `json:"version"`
	Description string `json:"description,omitempty"`
}

Info defines general metadata of a contract spec

type Input

type Input struct {
	Schema  map[string]interface{} `json:"schema,omitempty"`
	Sample  map[string]interface{} `json:"sample,omitempty"`
	Mapping map[string]interface{} `json:"mapping"`
}

Input defines schema and mapping of an activity input

type Parameter

type Parameter struct {
	Name        string                 `json:"name"`
	Schema      map[string]interface{} `json:"schema"`
	Description string                 `json:"description,omitempty"`
	Required    bool                   `json:"required,omitempty"`
}

Parameter defines a parameter of transaction

type Rule

type Rule struct {
	Description string     `json:"description,omitempty"`
	Condition   *Condition `json:"condition,omitempty"`
	Actions     []*Action  `json:"actions"`
}

Rule defines condition and actions for processing a transaction

type Schema

type Schema struct {
	ID         string                 `json:"$id"`
	Properties map[string]interface{} `json:"properties"`
	Required   []string               `json:"required,omitempty"`
}

Schema defines reusable JSON schema

type Spec

type Spec struct {
	Info       *Info                `json:"info"`
	Imports    []string             `json:"imports"`
	Contracts  map[string]*Contract `json:"contracts"`
	Components *Components          `json:"components"`
}

Spec specifies one or more smart contracts

func ReadContract

func ReadContract(contractFile string) (*Spec, error)

ReadContract reads a contract file and returns the contract spec

func (*Spec) ConvertAppSchemas

func (s *Spec) ConvertAppSchemas() error

ConvertAppSchemas converts schemas in contract spec to Flogo schema def

func (*Spec) ToAppConfig

func (s *Spec) ToAppConfig(fe bool) (*app.Config, error)

ToAppConfig converts the first contract in a contract spec to a Flogo App Config

type Transaction

type Transaction struct {
	Name       string                 `json:"name"`
	Tag        []string               `json:"tag,omitempty"`
	Parameters []*Parameter           `json:"parameters"`
	Transient  map[string]interface{} `json:"transient"`
	Returns    map[string]interface{} `json:"returns"`
	Rules      []*Rule                `json:"rules"`
}

Transaction defines a transaction in a contract

func (*Transaction) ContainsParameter

func (tx *Transaction) ContainsParameter(name string) bool

ContainsParameter returns true if a parameter matches the specified name

func (*Transaction) ParameterDef

func (tx *Transaction) ParameterDef() (string, error)

ParameterDef returns comma-delimited string of transaction parameters

func (*Transaction) ToHandler

func (tx *Transaction) ToHandler(fe bool) (*trigger.HandlerConfig, error)

ToHandler converts a contract transaction to trigger handler config

func (*Transaction) ToHandlerSchema

func (tx *Transaction) ToHandlerSchema() (*trigger.SchemaConfig, error)

ToHandlerSchema extracts schema config from a contract transaction

func (*Transaction) ToResource

func (tx *Transaction) ToResource(schm *trigger.SchemaConfig, cid string) (string, *definition.DefinitionRep, error)

ToResource converts a contract transaction to flow resource definition

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL