schema

package
v0.51.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 15 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)

EncodeOptions encodes a list of schema options into validated json.

func LoadModule

func LoadModule() (starlark.StringDict, error)

Types

type Color

type Color struct {
	SchemaField
	// contains filtered or unexported fields
}

func (*Color) AsSchemaField

func (s *Color) AsSchemaField() SchemaField

func (*Color) Attr

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

func (*Color) AttrNames

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

func (*Color) Freeze

func (s *Color) Freeze()

func (*Color) Hash

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

func (*Color) String

func (s *Color) String() string

func (*Color) Truth

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

func (*Color) Type

func (s *Color) Type() string

type DateTime

type DateTime struct {
	SchemaField
}

func (*DateTime) AsSchemaField

func (s *DateTime) AsSchemaField() SchemaField

func (*DateTime) Attr

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

func (*DateTime) AttrNames

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

func (*DateTime) Freeze

func (s *DateTime) Freeze()

func (*DateTime) Hash

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

func (*DateTime) String

func (s *DateTime) String() string

func (*DateTime) Truth

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

func (*DateTime) Type

func (s *DateTime) Type() string
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 Generated

type Generated struct {
	SchemaField
}

func (*Generated) AsSchemaField

func (s *Generated) AsSchemaField() SchemaField

func (*Generated) Attr

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

func (*Generated) AttrNames

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

func (*Generated) Freeze

func (s *Generated) Freeze()

func (*Generated) Hash

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

func (*Generated) String

func (s *Generated) String() string

func (*Generated) Truth

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

func (*Generated) Type

func (s *Generated) Type() string

type Handler

type Handler struct {
	SchemaHandler
}

func (*Handler) AsSchemaHandler

func (s *Handler) AsSchemaHandler() SchemaHandler

func (*Handler) Attr

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

func (*Handler) AttrNames

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

func (*Handler) Freeze

func (s *Handler) Freeze()

func (*Handler) Hash

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

func (*Handler) String

func (s *Handler) String() string

func (*Handler) Truth

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

func (*Handler) Type

func (s *Handler) Type() string

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 LocationBased

type LocationBased struct {
	SchemaField
}

func (*LocationBased) AsSchemaField

func (s *LocationBased) AsSchemaField() SchemaField

func (*LocationBased) Attr

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

func (*LocationBased) AttrNames

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

func (*LocationBased) Freeze

func (s *LocationBased) Freeze()

func (*LocationBased) Hash

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

func (*LocationBased) String

func (s *LocationBased) String() string

func (*LocationBased) Truth

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

func (*LocationBased) Type

func (s *LocationBased) Type() string

type Notification

type Notification struct {
	SchemaField

	Builder *starlark.Function `json:"-"`
	// contains filtered or unexported fields
}

func (*Notification) AsSchemaField

func (s *Notification) AsSchemaField() SchemaField

func (*Notification) Attr

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

func (*Notification) AttrNames

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

func (*Notification) Freeze

func (s *Notification) Freeze()

func (*Notification) Hash

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

func (*Notification) String

func (s *Notification) String() string

func (*Notification) Truth

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

func (*Notification) Type

func (s *Notification) Type() string

type OAuth2

type OAuth2 struct {
	SchemaField
	// contains filtered or unexported fields
}

func (*OAuth2) AsSchemaField

func (s *OAuth2) AsSchemaField() SchemaField

func (*OAuth2) Attr

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

func (*OAuth2) AttrNames

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

func (*OAuth2) Freeze

func (s *OAuth2) Freeze()

func (*OAuth2) Hash

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

func (*OAuth2) String

func (s *OAuth2) String() string

func (*OAuth2) Truth

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

func (*OAuth2) Type

func (s *OAuth2) 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 PhotoSelect

type PhotoSelect struct {
	SchemaField
}

func (*PhotoSelect) AsSchemaField

func (s *PhotoSelect) AsSchemaField() SchemaField

func (*PhotoSelect) Attr

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

func (*PhotoSelect) AttrNames

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

func (*PhotoSelect) Freeze

func (s *PhotoSelect) Freeze()

func (*PhotoSelect) Hash

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

func (*PhotoSelect) String

func (s *PhotoSelect) String() string

func (*PhotoSelect) Truth

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

func (*PhotoSelect) Type

func (s *PhotoSelect) Type() string

type Schema

type Schema struct {
	Version       string         `json:"version"                 validate:"required"`
	Fields        []SchemaField  `json:"schema"                  validate:"dive"`
	Notifications []Notification `json:"notifications,omitempty" validate:"dive"`

	Handlers map[string]SchemaHandler `json:"-"`
}

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

func FromStarlark

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

FromStarlark creates a new Schema from a Starlark schema object.

func (Schema) MarshalJSON

func (s Schema) MarshalJSON() ([]byte, error)

type SchemaField

type SchemaField struct {
	Type        string            `` /* 169-byte string literal not displayed */
	ID          string            `json:"id"                    validate:"required,excludesall=$"`
	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"`

	Default string         `json:"default,omitempty" validate:"required_for=dropdown onoff radio"`
	Options []SchemaOption `json:"options,omitempty" validate:"required_for=dropdown radio,dive"`
	Palette []string       `json:"palette,omitempty"`
	Sounds  []SchemaSound  `json:"sounds,omitempty"  validate:"required_for=notification,dive"`

	Source          string             `json:"source,omitempty"  validate:"required_for=generated"`
	Handler         string             `json:"handler,omitempty" validate:"required_for=generated locationbased typeahead oauth2"`
	StarlarkHandler *starlark.Function `json:"-"`

	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"`

	Secret bool `json:"secret,omitempty" validate:"allowed_for=text"`
}

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 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 {
	Display string `json:"display"`
	Text    string `json:"text"    validate:"required"` // The same as display, for legacy reasons.
	Value   string `json:"value"   validate:"required"`
}

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

type SchemaSound

type SchemaSound struct {
	ID    string `json:"id"    validate:"required"`
	Title string `json:"title" validate:"required"`
	Path  string `json:"path"  validate:"required"`
}

SchemaSound represents a sound that can be played by the applet.

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 Sound

type Sound struct {
	SchemaSound
	// contains filtered or unexported fields
}

func (*Sound) AsSchemaSound

func (s *Sound) AsSchemaSound() SchemaSound

func (*Sound) Attr

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

func (*Sound) AttrNames

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

func (*Sound) Freeze

func (s *Sound) Freeze()

func (*Sound) Hash

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

func (*Sound) String

func (s *Sound) String() string

func (*Sound) Truth

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

func (*Sound) Type

func (s *Sound) Type() string

type StarlarkSchema

type StarlarkSchema struct {
	Schema

	Handlers map[string]SchemaHandler
	// 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

type Text struct {
	SchemaField
}

func (*Text) AsSchemaField

func (s *Text) AsSchemaField() SchemaField

func (*Text) Attr

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

func (*Text) AttrNames

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

func (*Text) Freeze

func (s *Text) Freeze()

func (*Text) Hash

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

func (*Text) String

func (s *Text) String() string

func (*Text) Truth

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

func (*Text) Type

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

type Typeahead

type Typeahead struct {
	SchemaField
}

func (*Typeahead) AsSchemaField

func (s *Typeahead) AsSchemaField() SchemaField

func (*Typeahead) Attr

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

func (*Typeahead) AttrNames

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

func (*Typeahead) Freeze

func (s *Typeahead) Freeze()

func (*Typeahead) Hash

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

func (*Typeahead) String

func (s *Typeahead) String() string

func (*Typeahead) Truth

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

func (*Typeahead) Type

func (s *Typeahead) Type() string

Jump to

Keyboard shortcuts

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