schema

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModuleName = "schema"
)
View Source
const (
	// SchemaFunctionName is the name of the function in Starlark that we expect
	// to be able to call to get the schema for an applet.
	SchemaFunctionName = "get_schema"
)

Variables

This section is empty.

Functions

func EncodeOptions

func EncodeOptions(
	starlarkOptions starlark.Value) (string, error)

Encodes a list of schema options into validated json.

func LoadModule

func LoadModule() (starlark.StringDict, error)

Types

type Dropdown struct {
	SchemaField
	// contains filtered or unexported fields
}
func (s *Dropdown) AsSchemaField() SchemaField
func (s *Dropdown) Attr(name string) (starlark.Value, error)
func (s *Dropdown) AttrNames() []string
func (s *Dropdown) Freeze()
func (s *Dropdown) Hash() (uint32, error)
func (s *Dropdown) String() string
func (s *Dropdown) Truth() starlark.Bool
func (s *Dropdown) Type() string

type Field

type Field interface {
	AsSchemaField() SchemaField
}

type HandlerReturnType

type HandlerReturnType int8

HandlerReturnType defines an enum for the type of information we expect to get back from the schema function.

const (
	ReturnSchema HandlerReturnType = iota
	ReturnOptions
	ReturnString
	ReturnField
)

type Location

type Location struct {
	SchemaField
}

func (*Location) AsSchemaField

func (s *Location) AsSchemaField() SchemaField

func (*Location) Attr

func (s *Location) Attr(name string) (starlark.Value, error)

func (*Location) AttrNames

func (s *Location) AttrNames() []string

func (*Location) Freeze

func (s *Location) Freeze()

func (*Location) Hash

func (s *Location) Hash() (uint32, error)

func (*Location) String

func (s *Location) String() string

func (*Location) Truth

func (s *Location) Truth() starlark.Bool

func (*Location) Type

func (s *Location) Type() string

type Option

type Option struct {
	SchemaOption
}

func (*Option) AsSchemaOption

func (s *Option) AsSchemaOption() SchemaOption

func (*Option) Attr

func (s *Option) Attr(name string) (starlark.Value, error)

func (*Option) AttrNames

func (s *Option) AttrNames() []string

func (*Option) Freeze

func (s *Option) Freeze()

func (*Option) Hash

func (s *Option) Hash() (uint32, error)

func (*Option) String

func (s *Option) String() string

func (*Option) Truth

func (s *Option) Truth() starlark.Bool

func (*Option) Type

func (s *Option) Type() string

type Schema

type Schema struct {
	Version  string                   `json:"version" validate:"required"`
	Fields   []SchemaField            `json:"schema" validate:"required,dive"`
	Handlers map[string]SchemaHandler `json:"-"`
	// contains filtered or unexported fields
}

Schema holds a configuration object for an applet. It holds a list of fileds that are exported from an applet.

func FromStarlark added in v0.11.1

func FromStarlark(
	starlarkSchema starlark.Value,
	globals starlark.StringDict) (*Schema, error)

FromStarlark creates a new Schema from a Starlark schema object.

func (*Schema) Field added in v0.11.1

func (s *Schema) Field(id string) *SchemaField

Field returns a pointer to the schema field with the given ID, or nil if it doesn't exist.

type SchemaField

type SchemaField struct {
	Type        string            `` /* 133-byte string literal not displayed */
	ID          string            `json:"id" validate:"required"`
	Name        string            `json:"name,omitempty" validate:"required_for=datetime dropdown location locationbased onoff radio text typeahead png"`
	Description string            `json:"description,omitempty"`
	Icon        string            `json:"icon,omitempty" validate:"forbidden_for=generated"`
	Visibility  *SchemaVisibility `json:"visibility,omitempty" validate:"omitempty,dive"`

	Default string         `json:"default,omitempty" validate:"required_for=dropdown onoff radio"`
	Options []SchemaOption `json:"options,omitempty" validate:"required_for=dropdown radio,dive"`

	Source  string `json:"source,omitempty" validate:"required_for=generated"`
	Handler string `json:"handler,omitempty" validate:"required_for=generated locationbased typeahead oauth2"`

	ClientID              string   `json:"client_id,omitempty" validate:"required_for=oauth2"`
	AuthorizationEndpoint string   `json:"authorization_endpoint,omitempty" validate:"required_for=oauth2"`
	Scopes                []string `json:"scopes,omitempty" validate:"required_for=oauth2"`
}

SchemaField represents an item in the config used to confgure an applet.

type SchemaHandler

type SchemaHandler struct {
	Function   *starlark.Function
	ReturnType HandlerReturnType
}

SchemaHandler defines a function and and return type for getting the schema for an applet. This can both be the predefined schema function we expect all applets to have for config, but can also be used as a callback for

type SchemaOption

type SchemaOption struct {
	Text  string `json:"text" validate:"required"`
	Value string `json:"value" validate:"required"`
}

SchemaOption represents an option in a field. For example, an item in a drop down menu.

type SchemaVisibility

type SchemaVisibility struct {
	Type      string `json:"type" validate:"required,oneof=invisible disabled"`
	Condition string `json:"condition" validate:"required,oneof=equal not_equal"`
	Variable  string `json:"variable" validate:"required"`
	Value     string `json:"value"`
}

SchemaVisibility enables conditional fields inside of the mobile app. For example, if a field should be invisible until a login is provided.

type StarlarkSchema

type StarlarkSchema struct {
	Schema
	// contains filtered or unexported fields
}

func (StarlarkSchema) Attr

func (s StarlarkSchema) Attr(name string) (starlark.Value, error)

func (StarlarkSchema) AttrNames

func (s StarlarkSchema) AttrNames() []string

func (StarlarkSchema) Freeze

func (s StarlarkSchema) Freeze()

func (StarlarkSchema) Hash

func (s StarlarkSchema) Hash() (uint32, error)

func (StarlarkSchema) String

func (s StarlarkSchema) String() string

func (StarlarkSchema) Truth

func (s StarlarkSchema) Truth() starlark.Bool

func (StarlarkSchema) Type

func (s StarlarkSchema) Type() string

type Text added in v0.10.1

type Text struct {
	SchemaField
}

func (*Text) AsSchemaField added in v0.10.1

func (s *Text) AsSchemaField() SchemaField

func (*Text) Attr added in v0.10.1

func (s *Text) Attr(name string) (starlark.Value, error)

func (*Text) AttrNames added in v0.10.1

func (s *Text) AttrNames() []string

func (*Text) Freeze added in v0.10.1

func (s *Text) Freeze()

func (*Text) Hash added in v0.10.1

func (s *Text) Hash() (uint32, error)

func (*Text) String added in v0.10.1

func (s *Text) String() string

func (*Text) Truth added in v0.10.1

func (s *Text) Truth() starlark.Bool

func (*Text) Type added in v0.10.1

func (s *Text) Type() string

type Toggle

type Toggle struct {
	SchemaField
}

func (*Toggle) AsSchemaField

func (s *Toggle) AsSchemaField() SchemaField

func (*Toggle) Attr

func (s *Toggle) Attr(name string) (starlark.Value, error)

func (*Toggle) AttrNames

func (s *Toggle) AttrNames() []string

func (*Toggle) Freeze

func (s *Toggle) Freeze()

func (*Toggle) Hash

func (s *Toggle) Hash() (uint32, error)

func (*Toggle) String

func (s *Toggle) String() string

func (*Toggle) Truth

func (s *Toggle) Truth() starlark.Bool

func (*Toggle) Type

func (s *Toggle) Type() string

Jump to

Keyboard shortcuts

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