Documentation
¶
Index ¶
- Constants
- Variables
- func ConstraintErrorAddPathSegment(err error, pathSegment string) error
- func IntPointer[T ~int](value T) *int64
- func PointerTo[T any](value T) *T
- type AbstractListSchema
- func (l AbstractListSchema[ItemType]) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
- func (l AbstractListSchema[ItemType]) Items() ItemType
- func (l AbstractListSchema[ItemType]) Max() *int64
- func (l AbstractListSchema[ItemType]) Min() *int64
- func (l AbstractListSchema[ItemType]) ReflectedType() reflect.Type
- func (l AbstractListSchema[ItemType]) Serialize(data any) (any, error)
- func (l AbstractListSchema[ItemType]) TypeID() TypeID
- func (l AbstractListSchema[ItemType]) Unserialize(data any) (any, error)
- func (l AbstractListSchema[ItemType]) Validate(data any) error
- func (l AbstractListSchema[ItemType]) ValidateCompatibility(typeOrData any) error
- func (l AbstractListSchema[ItemType]) ValidateReferences() error
- type AnySchema
- func (a *AnySchema) ReflectedType() reflect.Type
- func (a *AnySchema) Serialize(data any) (any, error)
- func (a *AnySchema) TypeID() TypeID
- func (a *AnySchema) Unserialize(data any) (any, error)
- func (a *AnySchema) Validate(data any) error
- func (a *AnySchema) ValidateCompatibility(typeOrData any) error
- type AnyTypedObject
- type BadArgumentError
- type Bool
- type BoolSchema
- func (b BoolSchema) ReflectedType() reflect.Type
- func (b BoolSchema) Serialize(d any) (any, error)
- func (b BoolSchema) SerializeType(data bool) (any, error)
- func (b BoolSchema) TypeID() TypeID
- func (b BoolSchema) Unserialize(data any) (any, error)
- func (b BoolSchema) UnserializeType(data any) (bool, error)
- func (b BoolSchema) Validate(data any) error
- func (b BoolSchema) ValidateCompatibility(typeOrData any) error
- func (b BoolSchema) ValidateType(data bool) error
- type CallableFunction
- type CallableFunctionSchema
- func (f CallableFunctionSchema) Call(arguments []any) (any, error)
- func (f CallableFunctionSchema) Display() Display
- func (f CallableFunctionSchema) ID() string
- func (f CallableFunctionSchema) Output(inputType []Type) (Type, bool, error)
- func (f CallableFunctionSchema) ParameterTypeNames() []string
- func (f CallableFunctionSchema) Parameters() []Type
- func (f CallableFunctionSchema) String() string
- func (f CallableFunctionSchema) ToFunctionSchema() (*FunctionSchema, error)
- type CallableSchema
- func (s CallableSchema) CallSignal(ctx context.Context, runID string, stepID string, signalID string, ...) (err error)
- func (s CallableSchema) CallStep(ctx context.Context, runID string, stepID string, serializedInputData any) (outputID string, serializedOutputData any, err error)
- func (s CallableSchema) SelfSerialize() (any, error)
- type CallableSignal
- type CallableSignalSchema
- func (s CallableSignalSchema[StepData, InputType]) Call(ctx context.Context, stepData any, input any) error
- func (s CallableSignalSchema[StepData, InputType]) DataSchema() Scope
- func (s CallableSignalSchema[StepData, InputType]) Display() Display
- func (s CallableSignalSchema[StepData, InputType]) ID() string
- func (s CallableSignalSchema[StepData, InputType]) ToSignalSchema() *SignalSchema
- type CallableStep
- type CallableStepSchema
- func (s *CallableStepSchema[StepData, InputType]) Call(ctx context.Context, runID string, input any) (string, any, error)
- func (s *CallableStepSchema[StepData, InputType]) CallSignal(ctx context.Context, runID string, signalID string, input any) error
- func (s *CallableStepSchema[StepData, InputType]) Display() Display
- func (s *CallableStepSchema[StepData, InputType]) ID() string
- func (s *CallableStepSchema[StepData, InputType]) Input() Scope
- func (s *CallableStepSchema[StepData, InputType]) Outputs() map[string]*StepOutputSchema
- func (s *CallableStepSchema[StepData, InputType]) SignalEmitters() map[string]*SignalSchema
- func (s *CallableStepSchema[StepData, InputType]) SignalHandlers() map[string]*SignalSchema
- func (s *CallableStepSchema[StepData, InputType]) ToStepSchema() *StepSchema
- type ConstraintError
- type Display
- type DisplayValue
- type Enum
- type EnumSchema
- func (e EnumSchema[S, T]) ReflectedType() reflect.Type
- func (e EnumSchema[S, T]) Serialize(d any) (any, error)
- func (e EnumSchema[S, T]) SerializeType(data T) (any, error)
- func (e EnumSchema[S, T]) ValidValues() map[T]*DisplayValue
- func (e EnumSchema[S, T]) Validate(d any) error
- func (e EnumSchema[S, T]) ValidateCompatibility(typeOrData any) error
- func (e EnumSchema[S, T]) ValidateType(data T) error
- type Float
- type FloatSchema
- func (f FloatSchema) Max() *float64
- func (f FloatSchema) Min() *float64
- func (f FloatSchema) ReflectedType() reflect.Type
- func (f FloatSchema) Serialize(d any) (any, error)
- func (f FloatSchema) SerializeType(data float64) (any, error)
- func (f FloatSchema) TypeID() TypeID
- func (f FloatSchema) Units() *UnitsDefinition
- func (f FloatSchema) Unserialize(data any) (any, error)
- func (f FloatSchema) UnserializeType(data any) (float64, error)
- func (f FloatSchema) Validate(d any) error
- func (f FloatSchema) ValidateCompatibility(typeOrData any) error
- func (f FloatSchema) ValidateType(data float64) error
- type Function
- type FunctionCallError
- type FunctionSchema
- type IllegalStateError
- type Input
- type Int
- type IntEnum
- type IntEnumSchema
- type IntSchema
- func (i IntSchema) Max() *int64
- func (i IntSchema) Min() *int64
- func (i IntSchema) ReflectedType() reflect.Type
- func (i IntSchema) Serialize(d any) (any, error)
- func (i IntSchema) SerializeType(data int64) (any, error)
- func (i IntSchema) TypeID() TypeID
- func (i IntSchema) Units() *UnitsDefinition
- func (i IntSchema) Unserialize(data any) (any, error)
- func (i IntSchema) UnserializeType(data any) (int64, error)
- func (i IntSchema) Validate(d any) error
- func (i IntSchema) ValidateCompatibility(typeOrData any) error
- func (i IntSchema) ValidateType(data int64) error
- type InvalidInputError
- type InvalidOutputError
- type List
- type ListSchema
- type Map
- type MapKeyType
- type MapSchema
- func (m MapSchema[K, V]) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
- func (m MapSchema[K, V]) Keys() K
- func (m MapSchema[K, V]) Max() *int64
- func (m MapSchema[K, V]) Min() *int64
- func (m MapSchema[K, V]) ReflectedType() reflect.Type
- func (m MapSchema[K, V]) Serialize(data any) (any, error)
- func (m MapSchema[K, V]) TypeID() TypeID
- func (m MapSchema[K, V]) Unserialize(data any) (any, error)
- func (m MapSchema[K, V]) Validate(data any) error
- func (m MapSchema[K, V]) ValidateCompatibility(typeOrData any) error
- func (m MapSchema[K, V]) ValidateReferences() error
- func (m MapSchema[K, V]) Values() V
- type NoSuchStepError
- type NumberType
- type Object
- type ObjectSchema
- func (o *ObjectSchema) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
- func (o *ObjectSchema) GetDefaults() map[string]any
- func (o *ObjectSchema) ID() string
- func (o *ObjectSchema) IDUnenforced() bool
- func (o *ObjectSchema) Properties() map[string]*PropertySchema
- func (o *ObjectSchema) ReflectedType() reflect.Type
- func (o *ObjectSchema) Serialize(data any) (any, error)
- func (o *ObjectSchema) TypeID() TypeID
- func (o *ObjectSchema) Unserialize(data any) (result any, err error)
- func (o *ObjectSchema) Validate(data any) error
- func (o *ObjectSchema) ValidateCompatibility(typeOrData any) error
- func (o *ObjectSchema) ValidateReferences() error
- type OneOf
- type OneOfInt
- type OneOfSchema
- func (o OneOfSchema[KeyType]) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
- func (o OneOfSchema[KeyType]) DiscriminatorFieldName() string
- func (o OneOfSchema[KeyType]) ReflectedType() reflect.Type
- func (o OneOfSchema[KeyType]) Serialize(data any) (result any, err error)
- func (o OneOfSchema[KeyType]) SerializeType(data any) (any, error)
- func (o OneOfSchema[KeyType]) TypeID() TypeID
- func (o OneOfSchema[KeyType]) Types() map[KeyType]Object
- func (o OneOfSchema[KeyType]) Unserialize(data any) (any, error)
- func (o OneOfSchema[KeyType]) UnserializeType(data any) (result any, err error)
- func (o OneOfSchema[KeyType]) Validate(data any) error
- func (o OneOfSchema[KeyType]) ValidateCompatibility(typeOrData any) error
- func (o OneOfSchema[KeyType]) ValidateReferences() error
- func (o OneOfSchema[KeyType]) ValidateType(data any) error
- type OneOfString
- type Pattern
- type PatternSchema
- func (p PatternSchema) ReflectedType() reflect.Type
- func (p PatternSchema) Serialize(data any) (any, error)
- func (p PatternSchema) SerializeType(data *regexp.Regexp) (any, error)
- func (p PatternSchema) TypeID() TypeID
- func (p PatternSchema) Unserialize(data any) (any, error)
- func (p PatternSchema) UnserializeType(data any) (*regexp.Regexp, error)
- func (p PatternSchema) Validate(d any) error
- func (p PatternSchema) ValidateCompatibility(typeOrData any) error
- func (p PatternSchema) ValidateType(data *regexp.Regexp) error
- type Property
- type PropertySchema
- func (p *PropertySchema) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
- func (p *PropertySchema) Conflicts() []string
- func (p *PropertySchema) Default() *string
- func (p *PropertySchema) Disable(reason string) *PropertySchema
- func (p *PropertySchema) Display() Display
- func (p *PropertySchema) Examples() []string
- func (p *PropertySchema) ReflectedType() reflect.Type
- func (p *PropertySchema) Required() bool
- func (p *PropertySchema) RequiredIf() []string
- func (p *PropertySchema) RequiredIfNot() []string
- func (p *PropertySchema) Serialize(data any) (any, error)
- func (p *PropertySchema) TreatEmptyAsDefaultValue() *PropertySchema
- func (p *PropertySchema) Type() Type
- func (p *PropertySchema) TypeID() TypeID
- func (p *PropertySchema) Unserialize(data any) (any, error)
- func (p *PropertySchema) Validate(data any) error
- func (p *PropertySchema) ValidateCompatibility(typeOrData any) error
- func (p *PropertySchema) ValidateReferences() error
- type Ref
- type RefSchema
- func (r *RefSchema) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
- func (r *RefSchema) Display() Display
- func (r *RefSchema) GetDefaults() map[string]any
- func (r *RefSchema) GetObject() Object
- func (r *RefSchema) ID() string
- func (r *RefSchema) IDUnenforced() bool
- func (r *RefSchema) Namespace() string
- func (r *RefSchema) ObjectReady() bool
- func (r *RefSchema) Properties() map[string]*PropertySchema
- func (r *RefSchema) ReflectedType() reflect.Type
- func (r *RefSchema) Serialize(data any) (any, error)
- func (r *RefSchema) TypeID() TypeID
- func (r *RefSchema) Unserialize(data any) (any, error)
- func (r *RefSchema) Validate(data any) error
- func (r *RefSchema) ValidateCompatibility(typeOrData any) error
- func (r *RefSchema) ValidateReferences() error
- type ScalarType
- type Schema
- type SchemaSchema
- type Scope
- type ScopeSchema
- func DescribeSchema() *ScopeSchema
- func DescribeScope() *ScopeSchema
- func DescribeStepOutput() *ScopeSchema
- func NewScopeSchema(rootObject *ObjectSchema, objects ...*ObjectSchema) *ScopeSchema
- func NewScopeSchemaFromScope(scope Scope) *ScopeSchema
- func UnserializeScope(data any) (*ScopeSchema, error)
- func (s *ScopeSchema) ApplyNamespace(externalObjects map[string]*ObjectSchema, namespace string)
- func (s *ScopeSchema) ApplySelf()
- func (s *ScopeSchema) GetDefaults() map[string]any
- func (s *ScopeSchema) ID() string
- func (s *ScopeSchema) IDUnenforced() bool
- func (s *ScopeSchema) Objects() map[string]*ObjectSchema
- func (s *ScopeSchema) Properties() map[string]*PropertySchema
- func (s *ScopeSchema) ReflectedType() reflect.Type
- func (s *ScopeSchema) Root() string
- func (s *ScopeSchema) RootObject() *ObjectSchema
- func (s *ScopeSchema) SelfSerialize() (any, error)
- func (s *ScopeSchema) Serialize(data any) (any, error)
- func (s *ScopeSchema) TypeID() TypeID
- func (s *ScopeSchema) Unserialize(data any) (any, error)
- func (s *ScopeSchema) Validate(data any) error
- func (s *ScopeSchema) ValidateCompatibility(typeOrData any) error
- func (s *ScopeSchema) ValidateReferences() error
- type Serializable
- type Signal
- type SignalSchema
- type Step
- type StepOutput
- type StepOutputSchema
- func (s StepOutputSchema) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
- func (s StepOutputSchema) Display() *DisplayValue
- func (s StepOutputSchema) Error() bool
- func (s StepOutputSchema) ReflectedType() reflect.Type
- func (s StepOutputSchema) Schema() Scope
- func (s StepOutputSchema) Serialize(data any) (any, error)
- func (s StepOutputSchema) Unserialize(data any) (any, error)
- func (s StepOutputSchema) Validate(data any) error
- func (s StepOutputSchema) ValidateCompatibility(data any) error
- func (s StepOutputSchema) ValidateReferences() error
- type StepSchema
- type String
- type StringEnum
- type StringEnumSchema
- type StringSchema
- func (s StringSchema) Max() *int64
- func (s StringSchema) Min() *int64
- func (s StringSchema) Pattern() *regexp.Regexp
- func (s StringSchema) ReflectedType() reflect.Type
- func (s StringSchema) Serialize(d any) (any, error)
- func (s StringSchema) SerializeType(data string) (any, error)
- func (s StringSchema) TypeID() TypeID
- func (s StringSchema) Unserialize(data any) (any, error)
- func (s StringSchema) UnserializeType(data any) (string, error)
- func (s StringSchema) Validate(d any) error
- func (s StringSchema) ValidateCompatibility(typeOrData any) error
- func (s StringSchema) ValidateType(data string) error
- type Type
- type TypeID
- type TypedList
- type TypedListSchema
- func (t TypedListSchema[UnserializedType, ItemType]) SerializeType(data []UnserializedType) (any, error)
- func (t TypedListSchema[UnserializedType, ItemType]) UnserializeType(data any) (result []UnserializedType, err error)
- func (t TypedListSchema[UnserializedType, ItemType]) ValidateType(data []UnserializedType) error
- type TypedMap
- type TypedMapSchema
- func (m TypedMapSchema[KeyType, ValueType]) SerializeType(data map[KeyType]ValueType) (any, error)
- func (m TypedMapSchema[KeyType, ValueType]) UnserializeType(data any) (result map[KeyType]ValueType, err error)
- func (m TypedMapSchema[KeyType, ValueType]) ValidateType(data map[KeyType]ValueType) error
- type TypedObject
- type TypedObjectSchema
- type TypedScopeSchema
- type TypedStringEnumSchema
- type TypedType
- type Unit
- type UnitDefinition
- func (u *UnitDefinition) FormatLongFloat(amount float64, displayZero bool) string
- func (u *UnitDefinition) FormatLongInt(amount int64, displayZero bool) string
- func (u *UnitDefinition) FormatShortFloat(amount float64, displayZero bool) string
- func (u *UnitDefinition) FormatShortInt(amount int64, displayZero bool) string
- func (u *UnitDefinition) NameLongPlural() string
- func (u *UnitDefinition) NameLongSingular() string
- func (u *UnitDefinition) NameShortPlural() string
- func (u *UnitDefinition) NameShortSingular() string
- type UnitParseError
- type Units
- type UnitsDefinition
- func (u *UnitsDefinition) BaseUnit() *UnitDefinition
- func (u *UnitsDefinition) FormatLongFloat(data float64) string
- func (u *UnitsDefinition) FormatLongInt(data int64) string
- func (u *UnitsDefinition) FormatShortFloat(data float64) string
- func (u *UnitsDefinition) FormatShortInt(data int64) string
- func (u *UnitsDefinition) Multipliers() map[int64]*UnitDefinition
- func (u *UnitsDefinition) ParseFloat(data string) (float64, error)
- func (u *UnitsDefinition) ParseInt(data string) (int64, error)
- type UntypedList
- type UntypedMap
Examples ¶
Constants ¶
const SelfNamespace string = ""
Variables ¶
var UnitBytes = NewUnits( NewUnit( "B", "B", "byte", "bytes", ), map[int64]*UnitDefinition{ 1024: NewUnit( "kB", "kB", "kilobyte", "kilobytes", ), 1048576: NewUnit( "MB", "MB", "megabyte", "megabytes", ), 1073741824: NewUnit( "GB", "GB", "gigabyte", "gigabytes", ), 1099511627776: NewUnit( "TB", "TB", "terabyte", "terabytes", ), 1125899906842624: NewUnit( "PB", "PB", "petabyte", "petabytes", ), }, )
UnitBytes is scaling, byte-based UnitDefinition.
var UnitCharacters = NewUnits( NewUnit( "char", "chars", "character", "characters", ), nil, )
UnitCharacters is a single UnitDefinition for characters.
var UnitDurationNanoseconds = NewUnits( NewUnit( "ns", "ns", "nanosecond", "nanoseconds", ), map[int64]*UnitDefinition{ int64(time.Microsecond): NewUnit( "μs", "μs", "microsecond", "microseconds", ), int64(time.Millisecond): NewUnit( "ms", "ms", "milliseconds", "milliseconds", ), int64(time.Second): NewUnit( "s", "s", "second", "seconds", ), int64(time.Minute): NewUnit( "m", "m", "minute", "minutes", ), int64(time.Hour): NewUnit( "H", "H", "hour", "hours", ), int64(24 * time.Hour): NewUnit( "d", "d", "day", "days", ), }, )
UnitDurationNanoseconds is a nanosecond-based UnitDefinition for time durations.
var UnitDurationSeconds = NewUnits( NewUnit( "s", "s", "second", "seconds", ), map[int64]*UnitDefinition{ 60: NewUnit( "m", "m", "minute", "minutes", ), 3600: NewUnit( "H", "H", "hour", "hours", ), 86400: NewUnit( "d", "d", "day", "days", ), }, )
UnitDurationSeconds is a second-based UnitDefinition for time durations.
var UnitPercentage = NewUnits( NewUnit( "%", "%", "percent", "percent", ), nil, )
UnitPercentage is a single UnitDefinition for percentages.
Functions ¶
func ConstraintErrorAddPathSegment ¶
ConstraintErrorAddPathSegment adds a path segment if a ConstraintError is found.
func IntPointer ¶
IntPointer creates a pointer to an int after converting it to int64.
Types ¶
type AbstractListSchema ¶
type AbstractListSchema[ItemType Type] struct { ItemsValue ItemType `json:"items"` MinValue *int64 `json:"min"` MaxValue *int64 `json:"max"` }
AbstractListSchema is a root type for both the untyped and the typed lists.
func (AbstractListSchema[ItemType]) ApplyNamespace ¶ added in v0.12.0
func (l AbstractListSchema[ItemType]) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
func (AbstractListSchema[ItemType]) Items ¶
func (l AbstractListSchema[ItemType]) Items() ItemType
func (AbstractListSchema[ItemType]) Max ¶
func (l AbstractListSchema[ItemType]) Max() *int64
func (AbstractListSchema[ItemType]) Min ¶
func (l AbstractListSchema[ItemType]) Min() *int64
func (AbstractListSchema[ItemType]) ReflectedType ¶
func (l AbstractListSchema[ItemType]) ReflectedType() reflect.Type
func (AbstractListSchema[ItemType]) Serialize ¶
func (l AbstractListSchema[ItemType]) Serialize(data any) (any, error)
func (AbstractListSchema[ItemType]) TypeID ¶
func (l AbstractListSchema[ItemType]) TypeID() TypeID
func (AbstractListSchema[ItemType]) Unserialize ¶
func (l AbstractListSchema[ItemType]) Unserialize(data any) (any, error)
func (AbstractListSchema[ItemType]) Validate ¶
func (l AbstractListSchema[ItemType]) Validate(data any) error
func (AbstractListSchema[ItemType]) ValidateCompatibility ¶ added in v0.4.1
func (l AbstractListSchema[ItemType]) ValidateCompatibility(typeOrData any) error
func (AbstractListSchema[ItemType]) ValidateReferences ¶ added in v0.11.0
func (l AbstractListSchema[ItemType]) ValidateReferences() error
type AnySchema ¶
type AnySchema struct {
ScalarType
}
AnySchema is a wildcard allowing maps, lists, integers, strings, bools. and floats.
func NewAnySchema ¶
func NewAnySchema() *AnySchema
NewAnySchema creates an AnySchema which is a wildcard allowing maps, lists, integers, strings, bools. and floats.
func (*AnySchema) ReflectedType ¶
func (*AnySchema) ValidateCompatibility ¶ added in v0.4.1
type AnyTypedObject ¶
type AnyTypedObject[T any] struct { ObjectSchema `json:",inline"` }
AnyTypedObject is an object that pretends to be typed, but accepts any type.
func (*AnyTypedObject[T]) Any ¶
func (a *AnyTypedObject[T]) Any() TypedObject[any]
func (*AnyTypedObject[T]) IDEnforced ¶ added in v0.13.0
func (a *AnyTypedObject[T]) IDEnforced() bool
func (*AnyTypedObject[T]) SerializeType ¶
func (a *AnyTypedObject[T]) SerializeType(data any) (any, error)
func (*AnyTypedObject[T]) UnserializeType ¶
func (a *AnyTypedObject[T]) UnserializeType(data any) (any, error)
func (*AnyTypedObject[T]) ValidateType ¶
func (a *AnyTypedObject[T]) ValidateType(data any) error
type BadArgumentError ¶
BadArgumentError indicates that an invalid configuration was passed to a schema component. The message will explain what exactly the problem is, but may not be able to locate the exact error as the schema may be manually built.
func (BadArgumentError) Error ¶
func (b BadArgumentError) Error() string
Error returns the error message.
func (BadArgumentError) Unwrap ¶
func (b BadArgumentError) Unwrap() error
Unwrap returns the underlying error if any.
type BoolSchema ¶
type BoolSchema struct {
ScalarType
}
BoolSchema holds the schema information for boolean types.
Example ¶
package main import ( "fmt" "go.flow.arcalot.io/pluginsdk/schema" ) func main() { boolType := schema.NewBoolSchema() // Unserialize a bool: unserializedValue, err := boolType.Unserialize(true) if err != nil { panic(err) } fmt.Println(unserializedValue) // Validate: if err := boolType.Validate(unserializedValue); err != nil { panic(err) } // Serialize: serializedValue, err := boolType.Serialize(unserializedValue) if err != nil { panic(err) } fmt.Println(serializedValue) // Print protocol type ID fmt.Println(boolType.TypeID()) }
Output: true true bool
Example (Unserialize) ¶
package main import ( "fmt" "go.flow.arcalot.io/pluginsdk/schema" ) func main() { boolType := schema.NewBoolSchema() // Unserialize a bool: unserializedValue, err := boolType.Unserialize(true) if err != nil { panic(err) } fmt.Println(unserializedValue) // Unserialize an int: unserializedValue, err = boolType.Unserialize(1) if err != nil { panic(err) } fmt.Println(unserializedValue) // Unserialize a string like this: unserializedValue, err = boolType.Unserialize("true") if err != nil { panic(err) } fmt.Println(unserializedValue) // Or like this: unserializedValue, err = boolType.Unserialize("yes") if err != nil { panic(err) } fmt.Println(unserializedValue) // Or like this: unserializedValue, err = boolType.Unserialize("y") if err != nil { panic(err) } fmt.Println(unserializedValue) // Or like this: unserializedValue, err = boolType.Unserialize("enable") if err != nil { panic(err) } fmt.Println(unserializedValue) // Or like this: unserializedValue, err = boolType.Unserialize("enable") if err != nil { panic(err) } fmt.Println(unserializedValue) }
Output: true true true true true true true
func NewBoolSchema ¶
func NewBoolSchema() *BoolSchema
NewBoolSchema creates a new boolean representation.
func (BoolSchema) ReflectedType ¶
func (b BoolSchema) ReflectedType() reflect.Type
func (BoolSchema) SerializeType ¶
func (b BoolSchema) SerializeType(data bool) (any, error)
func (BoolSchema) TypeID ¶
func (b BoolSchema) TypeID() TypeID
func (BoolSchema) Unserialize ¶
func (b BoolSchema) Unserialize(data any) (any, error)
func (BoolSchema) UnserializeType ¶
func (b BoolSchema) UnserializeType(data any) (bool, error)
func (BoolSchema) Validate ¶
func (b BoolSchema) Validate(data any) error
func (BoolSchema) ValidateCompatibility ¶ added in v0.4.1
func (b BoolSchema) ValidateCompatibility(typeOrData any) error
func (BoolSchema) ValidateType ¶
func (b BoolSchema) ValidateType(data bool) error
type CallableFunction ¶ added in v0.7.0
type CallableFunction interface { Function ToFunctionSchema() (*FunctionSchema, error) Call(arguments []any) (any, error) }
func NewCallableFunction ¶ added in v0.7.0
func NewCallableFunction( id string, inputs []Type, output Type, outputsError bool, display Display, handler any, ) (CallableFunction, error)
NewCallableFunction creates a CallableFunction schema type for the strictly typed function.
- The handler types must match the input and output types specified. - The return type of the handler is determined by the value specified for output. If output is nil, it's a void function that may have no return, or a single error return if outputsError is true. - If output is not nil, the return type must match, plus it must have an error return if outputsError is true.
func NewDynamicCallableFunction ¶ added in v0.7.0
func NewDynamicCallableFunction( id string, inputs []Type, display Display, handler any, typeHandler func(inputType []Type) (Type, error), ) (CallableFunction, error)
NewDynamicCallableFunction returns a CallableFunction for the dynamically typed function.
- The input types must be specified and match, but you may use any types for instances when there are multiple allowed inputs. - The return type of the handler should be any plus an error return. - The handler function handles execution of the function. - The typeHandler function returns the output type given the input type. If the inputs are invalid, the handler should return an error.
type CallableFunctionSchema ¶ added in v0.7.0
type CallableFunctionSchema struct { IDValue string `json:"id"` InputsValue []Type `json:"inputs"` // The output type when the output type does not change. Nil for void. StaticOutputValue Type `json:"output"` OutputsError bool `json:"outputs_error"` DisplayValue Display `json:"display"` // A callable function whose parameters (if any) match the type schema specified in InputsValue, // and whose return value type matches StaticOutputValue, the return type from DynamicTypeHandler, // or is void if both StaticOutputValue and DynamicTypeHandler are nil. An error return must be present // if OutputsError is true. // The handler may also return an error type. Handler reflect.Value // Returns the output type based on the input type. For advanced use cases. Cannot be void. DynamicTypeHandler func(inputType []Type) (Type, error) }
func (CallableFunctionSchema) Call ¶ added in v0.7.0
func (f CallableFunctionSchema) Call(arguments []any) (any, error)
func (CallableFunctionSchema) Display ¶ added in v0.7.0
func (f CallableFunctionSchema) Display() Display
func (CallableFunctionSchema) ID ¶ added in v0.7.0
func (f CallableFunctionSchema) ID() string
func (CallableFunctionSchema) Output ¶ added in v0.7.0
func (f CallableFunctionSchema) Output(inputType []Type) (Type, bool, error)
func (CallableFunctionSchema) ParameterTypeNames ¶ added in v0.7.0
func (f CallableFunctionSchema) ParameterTypeNames() []string
func (CallableFunctionSchema) Parameters ¶ added in v0.7.0
func (f CallableFunctionSchema) Parameters() []Type
func (CallableFunctionSchema) String ¶ added in v0.7.0
func (f CallableFunctionSchema) String() string
func (CallableFunctionSchema) ToFunctionSchema ¶ added in v0.7.0
func (f CallableFunctionSchema) ToFunctionSchema() (*FunctionSchema, error)
type CallableSchema ¶
type CallableSchema struct {
StepsValue map[string]CallableStep `json:"steps"`
}
func NewCallableSchema ¶
func NewCallableSchema( steps ...CallableStep, ) *CallableSchema
func (CallableSchema) CallSignal ¶ added in v0.4.1
func (CallableSchema) SelfSerialize ¶
func (s CallableSchema) SelfSerialize() (any, error)
type CallableSignal ¶ added in v0.4.1
type CallableSignal interface { Signal ToSignalSchema() *SignalSchema Call(ctx context.Context, stepData any, inputData any) (err error) }
CallableSignal is a signal that can be directly called.
func NewCallableSignal ¶ added in v0.4.1
func NewCallableSignal[StepData any, InputType any]( id string, input *ScopeSchema, display Display, handler func(context.Context, StepData, InputType), ) CallableSignal
NewCallableSignal creates a callable signal definition.
func NewCallableSignalFromSchema ¶ added in v0.4.1
func NewCallableSignalFromSchema[StepData any, InputType any]( s *SignalSchema, handler func(context.Context, StepData, InputType), ) CallableSignal
NewCallableSignalFromSchema creates a callable signal definition from a schema and handler.
type CallableSignalSchema ¶ added in v0.4.1
type CallableSignalSchema[StepData any, InputType any] struct { IDValue string `json:"id"` InputValue *ScopeSchema `json:"data_input_schema"` DisplayValue Display `json:"display"` // contains filtered or unexported fields }
CallableSignalSchema is a signal that can be directly called and is typed to a specific input type. This is an input-only representation of the signal.
func (CallableSignalSchema[StepData, InputType]) DataSchema ¶ added in v0.4.1
func (s CallableSignalSchema[StepData, InputType]) DataSchema() Scope
func (CallableSignalSchema[StepData, InputType]) Display ¶ added in v0.4.1
func (s CallableSignalSchema[StepData, InputType]) Display() Display
func (CallableSignalSchema[StepData, InputType]) ID ¶ added in v0.4.1
func (s CallableSignalSchema[StepData, InputType]) ID() string
func (CallableSignalSchema[StepData, InputType]) ToSignalSchema ¶ added in v0.4.1
func (s CallableSignalSchema[StepData, InputType]) ToSignalSchema() *SignalSchema
type CallableStep ¶
type CallableStep interface { Step ToStepSchema() *StepSchema Call(ctx context.Context, runID string, data any) (outputID string, outputData any, err error) CallSignal(ctx context.Context, runID string, signalID string, data any) (err error) }
CallableStep is a step that can be directly called.
func NewCallableStep ¶
func NewCallableStep[StepInputType any]( id string, input *ScopeSchema, outputs map[string]*StepOutputSchema, display Display, handler func(context.Context, StepInputType) (string, any), ) CallableStep
NewCallableStep creates a callable step definition.
func NewCallableStepWithSignals ¶ added in v0.4.1
func NewCallableStepWithSignals[StepData any, StepInputType any]( id string, input *ScopeSchema, outputs map[string]*StepOutputSchema, signalHandlers map[string]CallableSignal, signalEmitters map[string]*SignalSchema, display Display, initializer func() StepData, handler func(context.Context, StepData, StepInputType) (string, any), ) CallableStep
NewCallableStepWithSignals creates a callable step definition, and allows the inclusion of signal handlers and emitters.
type CallableStepSchema ¶
type CallableStepSchema[StepData any, InputType any] struct { IDValue string `json:"id"` InputValue *ScopeSchema `json:"input"` SignalHandlersValue map[string]CallableSignal `json:"signal_handlers"` SignalEmittersValue map[string]*SignalSchema `json:"signal_emitters"` OutputsValue map[string]*StepOutputSchema `json:"outputs"` DisplayValue Display `json:"display"` // contains filtered or unexported fields }
CallableStepSchema is a step that can be directly called and is typed to a specific input type.
func (*CallableStepSchema[StepData, InputType]) CallSignal ¶ added in v0.4.1
func (*CallableStepSchema[StepData, InputType]) Display ¶
func (s *CallableStepSchema[StepData, InputType]) Display() Display
func (*CallableStepSchema[StepData, InputType]) ID ¶
func (s *CallableStepSchema[StepData, InputType]) ID() string
func (*CallableStepSchema[StepData, InputType]) Input ¶
func (s *CallableStepSchema[StepData, InputType]) Input() Scope
func (*CallableStepSchema[StepData, InputType]) Outputs ¶
func (s *CallableStepSchema[StepData, InputType]) Outputs() map[string]*StepOutputSchema
func (*CallableStepSchema[StepData, InputType]) SignalEmitters ¶ added in v0.4.1
func (s *CallableStepSchema[StepData, InputType]) SignalEmitters() map[string]*SignalSchema
func (*CallableStepSchema[StepData, InputType]) SignalHandlers ¶ added in v0.4.1
func (s *CallableStepSchema[StepData, InputType]) SignalHandlers() map[string]*SignalSchema
func (*CallableStepSchema[StepData, InputType]) ToStepSchema ¶
func (s *CallableStepSchema[StepData, InputType]) ToStepSchema() *StepSchema
type ConstraintError ¶
ConstraintError indicates that the passed data violated one or more constraints defined in the schema. The message holds the exact path of the problematic field, as well as a message explaining the error. If this error is not easily understood, please open an issue on the Arcaflow plugin SDK.
func (*ConstraintError) AddPathSegment ¶
func (c *ConstraintError) AddPathSegment(pathSegment string) error
AddPathSegment adds a path segment to the constraint error.
func (*ConstraintError) Error ¶
func (c *ConstraintError) Error() string
Error returns the error message.
func (*ConstraintError) Unwrap ¶
func (c *ConstraintError) Unwrap() error
Unwrap returns the underlying error if any.
type DisplayValue ¶
type DisplayValue struct { NameValue *string `json:"name"` DescriptionValue *string `json:"description"` IconValue *string `json:"icon"` }
DisplayValue holds the data related to displaying fields.
func NewDisplayValue ¶
func NewDisplayValue(name *string, description *string, icon *string) *DisplayValue
NewDisplayValue creates a new display from the given parameters.
func (DisplayValue) Description ¶
func (d DisplayValue) Description() *string
func (DisplayValue) Icon ¶
func (d DisplayValue) Icon() *string
func (DisplayValue) Name ¶
func (d DisplayValue) Name() *string
type Enum ¶
type Enum[T enumValue] interface { TypedType[T] ValidValues() map[T]*DisplayValue }
Enum is an abstract schema for enumerated types.
type EnumSchema ¶
type EnumSchema[S serializedEnumValue, T enumValue] struct { ScalarType ValidValuesMap map[T]*DisplayValue `json:"values"` }
func (EnumSchema[S, T]) ReflectedType ¶
func (e EnumSchema[S, T]) ReflectedType() reflect.Type
func (EnumSchema[S, T]) SerializeType ¶
func (e EnumSchema[S, T]) SerializeType(data T) (any, error)
func (EnumSchema[S, T]) ValidValues ¶
func (e EnumSchema[S, T]) ValidValues() map[T]*DisplayValue
func (EnumSchema[S, T]) Validate ¶
func (e EnumSchema[S, T]) Validate(d any) error
func (EnumSchema[S, T]) ValidateCompatibility ¶ added in v0.4.1
func (e EnumSchema[S, T]) ValidateCompatibility(typeOrData any) error
func (EnumSchema[S, T]) ValidateType ¶
func (e EnumSchema[S, T]) ValidateType(data T) error
type Float ¶
type Float interface { TypedType[float64] Min() *float64 Max() *float64 Units() *UnitsDefinition }
Float holds the schema information for 64-bit floating point numbers. This dataclass only has the ability to hold the configuration but cannot serialize, unserialize or validate. For that functionality please use FloatType.
type FloatSchema ¶
type FloatSchema struct { ScalarType MinValue *float64 `json:"min"` MaxValue *float64 `json:"max"` UnitsValue *UnitsDefinition `json:"units"` }
func NewFloatSchema ¶
func NewFloatSchema(min *float64, max *float64, units *UnitsDefinition) *FloatSchema
NewFloatSchema creates a new float schema from the specified values.
func (FloatSchema) Max ¶
func (f FloatSchema) Max() *float64
func (FloatSchema) Min ¶
func (f FloatSchema) Min() *float64
func (FloatSchema) ReflectedType ¶
func (f FloatSchema) ReflectedType() reflect.Type
func (FloatSchema) SerializeType ¶
func (f FloatSchema) SerializeType(data float64) (any, error)
func (FloatSchema) TypeID ¶
func (f FloatSchema) TypeID() TypeID
func (FloatSchema) Units ¶
func (f FloatSchema) Units() *UnitsDefinition
func (FloatSchema) Unserialize ¶
func (f FloatSchema) Unserialize(data any) (any, error)
func (FloatSchema) UnserializeType ¶
func (f FloatSchema) UnserializeType(data any) (float64, error)
func (FloatSchema) Validate ¶
func (f FloatSchema) Validate(d any) error
func (FloatSchema) ValidateCompatibility ¶ added in v0.4.1
func (f FloatSchema) ValidateCompatibility(typeOrData any) error
func (FloatSchema) ValidateType ¶
func (f FloatSchema) ValidateType(data float64) error
type FunctionCallError ¶ added in v0.7.0
type FunctionCallError struct { // isFunctionReportedError is true when the error originated from the function itself from its return value or a panic // It is false when the function did something unexpected, or the call is invalid. IsFunctionReportedError bool SourceError error }
func NewFunctionCallError ¶ added in v0.7.0
func NewFunctionCallError(err error, isFunctionReportedError bool) *FunctionCallError
func (*FunctionCallError) Error ¶ added in v0.7.0
func (e *FunctionCallError) Error() string
type FunctionSchema ¶ added in v0.7.0
type FunctionSchema struct { IDValue string `json:"id"` InputsValue []Type `json:"inputs"` OutputValue Type `json:"output"` DisplayValue Display `json:"display"` }
func (FunctionSchema) Display ¶ added in v0.7.0
func (f FunctionSchema) Display() Display
func (FunctionSchema) ID ¶ added in v0.7.0
func (f FunctionSchema) ID() string
func (FunctionSchema) Output ¶ added in v0.7.0
func (f FunctionSchema) Output(_ []Type) (Type, error)
func (FunctionSchema) ParameterTypeNames ¶ added in v0.7.0
func (f FunctionSchema) ParameterTypeNames() []string
func (FunctionSchema) Parameters ¶ added in v0.7.0
func (f FunctionSchema) Parameters() []Type
func (FunctionSchema) String ¶ added in v0.7.0
func (f FunctionSchema) String() string
type IllegalStateError ¶ added in v0.4.1
type IllegalStateError struct {
Cause error
}
IllegalStateError is for when something is called when it shouldn't have.
func (IllegalStateError) Error ¶ added in v0.4.1
func (i IllegalStateError) Error() string
Error returns the error message.
func (IllegalStateError) Unwrap ¶ added in v0.4.1
func (i IllegalStateError) Unwrap() error
Unwrap returns the underlying error that explains the output problem.
type Int ¶
type Int interface { TypedType[int64] ScalarType Min() *int64 Max() *int64 Units() *UnitsDefinition }
Int holds the schema information for 64-bit integers. This dataclass only has the ability to hold the configuration but cannot serialize, unserialize or validate. For that functionality please use IntType.
type IntEnum ¶
type IntEnum interface { Enum[int64] Units() *UnitsDefinition }
IntEnum is an enum type with integer values.
type IntEnumSchema ¶
type IntEnumSchema struct { EnumSchema[int64, int64] `json:",inline"` IntUnits *UnitsDefinition `json:"units"` }
IntEnumSchema is an enum type with integer values.
Example (Unserialize) ¶
package main import ( "fmt" "go.flow.arcalot.io/pluginsdk/schema" ) func main() { payloadSize := schema.NewIntEnumSchema(map[int64]*schema.DisplayValue{ 1024: {NameValue: schema.PointerTo("Small")}, 1048576: {NameValue: schema.PointerTo("Large")}, }, schema.UnitBytes) // Try to unserialize an invalid value: _, err := payloadSize.Unserialize(2048) fmt.Println(err) // Unserialize a valid value: val, err := payloadSize.Unserialize(1024) if err != nil { panic(err) } fmt.Println(val) // Unserialize a formatted value: val, err = payloadSize.Unserialize("1MB") if err != nil { panic(err) } fmt.Println(val) }
Output: Validation failed: '2048' is not a valid value, must be one of: '1024', '1048576' 1024 1048576
func NewIntEnumSchema ¶
func NewIntEnumSchema(validValues map[int64]*DisplayValue, units *UnitsDefinition) *IntEnumSchema
NewIntEnumSchema creates a new enum of integer values.
Example ¶
package main import ( "fmt" "go.flow.arcalot.io/pluginsdk/schema" ) func main() { // Create a new enum type by defining its valid values: var payloadSize schema.IntEnum = schema.NewIntEnumSchema(map[int64]*schema.DisplayValue{ 1024: {NameValue: schema.PointerTo("Small")}, 1048576: {NameValue: schema.PointerTo("Large")}, }, schema.UnitBytes) // You can now print the valid values: fmt.Println(*payloadSize.ValidValues()[1024].NameValue) }
Output: Small
func (IntEnumSchema) TypeID ¶
func (i IntEnumSchema) TypeID() TypeID
func (IntEnumSchema) Units ¶
func (i IntEnumSchema) Units() *UnitsDefinition
func (IntEnumSchema) Unserialize ¶
func (i IntEnumSchema) Unserialize(data any) (any, error)
func (IntEnumSchema) UnserializeType ¶
func (e IntEnumSchema) UnserializeType(data any) (int64, error)
type IntSchema ¶
type IntSchema struct { ScalarType MinValue *int64 `json:"min"` MaxValue *int64 `json:"max"` UnitsValue *UnitsDefinition `json:"units"` }
func NewIntSchema ¶
func NewIntSchema(min *int64, max *int64, units *UnitsDefinition) *IntSchema
NewIntSchema creates a new integer schema with the specified values.
func (IntSchema) ReflectedType ¶
func (IntSchema) Units ¶
func (i IntSchema) Units() *UnitsDefinition
func (IntSchema) ValidateCompatibility ¶ added in v0.4.1
func (IntSchema) ValidateType ¶
type InvalidInputError ¶
type InvalidInputError struct {
Cause error
}
InvalidInputError signals that the input provided for a step was invalid. The underlying error can be unwrapped.
func (InvalidInputError) Error ¶
func (i InvalidInputError) Error() string
Error returns the error message.
func (InvalidInputError) Unwrap ¶
func (i InvalidInputError) Unwrap() error
Unwrap returns the underlying error that explains the input problem.
type InvalidOutputError ¶
type InvalidOutputError struct {
Cause error
}
InvalidOutputError signals that the step returned an output that does not match the output ID.
func (InvalidOutputError) Error ¶
func (i InvalidOutputError) Error() string
Error returns the error message.
func (InvalidOutputError) Unwrap ¶
func (i InvalidOutputError) Unwrap() error
Unwrap returns the underlying error that explains the output problem.
type ListSchema ¶
type ListSchema struct { AbstractListSchema[Type] `json:",inline"` }
ListSchema is the untyped representation of a list.
func NewListSchema ¶
func NewListSchema(items Type, min *int64, max *int64) *ListSchema
NewListSchema creates a new list schema from the specified values.
type Map ¶
type Map[KeyType Type, ValueType Type] interface { Type Keys() KeyType Values() ValueType Min() *int64 Max() *int64 }
Map holds the schema definition for key-value associations. This dataclass only has the ability to hold the configuration but cannot serialize, unserialize or validate. For that functionality please use MapType.
type MapKeyType ¶
MapKeyType are types that can be used as map keys.
type MapSchema ¶
type MapSchema[K Type, V Type] struct { KeysValue K `json:"keys"` ValuesValue V `json:"values"` MinValue *int64 `json:"min"` MaxValue *int64 `json:"max"` }
MapSchema is the implementation of tye map types.
func NewMapSchema ¶
NewMapSchema creates a new map schema.
func (MapSchema[K, V]) ApplyNamespace ¶ added in v0.12.0
func (m MapSchema[K, V]) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
func (MapSchema[K, V]) ReflectedType ¶
func (MapSchema[K, V]) ValidateCompatibility ¶ added in v0.4.1
func (MapSchema[K, V]) ValidateReferences ¶ added in v0.11.0
type NoSuchStepError ¶
type NoSuchStepError struct {
Step string
}
NoSuchStepError indicates that the given step is not supported by the plugin.
func (NoSuchStepError) Error ¶
func (n NoSuchStepError) Error() string
Error returns the error message.
type NumberType ¶
NumberType is a type collection of number types.
type Object ¶
type Object interface { Type ID() string // IDUnenforced indicates whether the ID must match when validating schema compatibility. // If true, the IDs do not need to match between compared objects, but fields must still match. // Only one object schema needs to not enforce the ID to skip the ID check. IDUnenforced() bool Properties() map[string]*PropertySchema // GetDefaults returns the defaults in a serialized form. GetDefaults() map[string]any }
Object holds the definition for objects comprised of defined fields.
func ConvertToObjectSchema ¶ added in v0.11.0
ConvertToObjectSchema attempts to extract an ObjectSchema from the input.
If an ObjectSchema is found, it returns it. If a RefSchema is found, it extracts the cached object schema the ref is referencing. If a ScopeSchema is found, it extracts the root object schema. Returns the ObjectSchema and true if successful, otherwise nil and false.
type ObjectSchema ¶
type ObjectSchema struct { IDValue string `json:"id"` PropertiesValue map[string]*PropertySchema `json:"properties"` IDUnenforcedValue bool `json:"id_unenforced"` // contains filtered or unexported fields }
ObjectSchema is the implementation of the object schema type.
func NewObjectSchema ¶
func NewObjectSchema(id string, properties map[string]*PropertySchema) *ObjectSchema
NewObjectSchema creates a new object definition. If you need it tied to a struct, use NewStructMappedObjectSchema instead.
func NewStructMappedObjectSchema ¶
func NewStructMappedObjectSchema[T any](id string, properties map[string]*PropertySchema) *ObjectSchema
NewStructMappedObjectSchema creates an object schema that is tied to a specific struct. The values will be mapped to that struct when unserialized.
func NewUnenforcedIDObjectSchema ¶ added in v0.13.0
func NewUnenforcedIDObjectSchema(id string, properties map[string]*PropertySchema) *ObjectSchema
NewUnenforcedIDObjectSchema creates a new object definition with the ID not enforced. The unenforced ID checking is useful for generated schemas, where the ID may be insignificant, or could burden workflow development.
func (*ObjectSchema) ApplyNamespace ¶ added in v0.12.0
func (o *ObjectSchema) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
func (*ObjectSchema) GetDefaults ¶
func (o *ObjectSchema) GetDefaults() map[string]any
func (*ObjectSchema) ID ¶
func (o *ObjectSchema) ID() string
func (*ObjectSchema) IDUnenforced ¶ added in v0.13.0
func (o *ObjectSchema) IDUnenforced() bool
func (*ObjectSchema) Properties ¶
func (o *ObjectSchema) Properties() map[string]*PropertySchema
func (*ObjectSchema) ReflectedType ¶
func (o *ObjectSchema) ReflectedType() reflect.Type
func (*ObjectSchema) TypeID ¶
func (o *ObjectSchema) TypeID() TypeID
func (*ObjectSchema) Unserialize ¶
func (o *ObjectSchema) Unserialize(data any) (result any, err error)
func (*ObjectSchema) Validate ¶
func (o *ObjectSchema) Validate(data any) error
func (*ObjectSchema) ValidateCompatibility ¶ added in v0.4.1
func (o *ObjectSchema) ValidateCompatibility(typeOrData any) error
func (*ObjectSchema) ValidateReferences ¶ added in v0.11.0
func (o *ObjectSchema) ValidateReferences() error
type OneOf ¶
type OneOf[KeyType int64 | string] interface { Type Types() map[KeyType]Object DiscriminatorFieldName() string }
OneOf is the root interface for one-of types. It should not be used directly but is provided for convenience.
type OneOfInt ¶
OneOfInt holds the definition of variable types with an integer discriminator. This type acts as a split for a case where multiple possible object types can be present in a field. This type requires that there be a common field (the discriminator) which tells a parsing party which type it is. The field type in this case is a string.
type OneOfSchema ¶
type OneOfSchema[KeyType int64 | string] struct { TypesValue map[KeyType]Object `json:"types"` DiscriminatorFieldNameValue string `json:"discriminator_field_name"` // whether or not the discriminator is inlined in the underlying objects' schema DiscriminatorInlined bool `json:"discriminator_inlined"` // contains filtered or unexported fields }
func NewOneOfIntSchema ¶
func NewOneOfIntSchema[ItemsInterface any]( types map[int64]Object, discriminatorFieldName string, discriminatorInlined bool, ) *OneOfSchema[int64]
NewOneOfIntSchema creates a new OneOf-type with integer discriminators.
func NewOneOfStringSchema ¶
func NewOneOfStringSchema[ItemsInterface any]( types map[string]Object, discriminatorFieldName string, discriminatorInlined bool, ) *OneOfSchema[string]
NewOneOfStringSchema creates a new OneOf-type with integer discriminators.
func (OneOfSchema[KeyType]) ApplyNamespace ¶ added in v0.12.0
func (o OneOfSchema[KeyType]) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
func (OneOfSchema[KeyType]) DiscriminatorFieldName ¶
func (o OneOfSchema[KeyType]) DiscriminatorFieldName() string
func (OneOfSchema[KeyType]) ReflectedType ¶
func (o OneOfSchema[KeyType]) ReflectedType() reflect.Type
func (OneOfSchema[KeyType]) Serialize ¶
func (o OneOfSchema[KeyType]) Serialize(data any) (result any, err error)
func (OneOfSchema[KeyType]) SerializeType ¶
func (o OneOfSchema[KeyType]) SerializeType(data any) (any, error)
func (OneOfSchema[KeyType]) TypeID ¶
func (o OneOfSchema[KeyType]) TypeID() TypeID
func (OneOfSchema[KeyType]) Types ¶
func (o OneOfSchema[KeyType]) Types() map[KeyType]Object
func (OneOfSchema[KeyType]) Unserialize ¶
func (o OneOfSchema[KeyType]) Unserialize(data any) (any, error)
func (OneOfSchema[KeyType]) UnserializeType ¶
func (o OneOfSchema[KeyType]) UnserializeType(data any) (result any, err error)
func (OneOfSchema[KeyType]) Validate ¶
func (o OneOfSchema[KeyType]) Validate(data any) error
func (OneOfSchema[KeyType]) ValidateCompatibility ¶ added in v0.4.1
func (o OneOfSchema[KeyType]) ValidateCompatibility(typeOrData any) error
func (OneOfSchema[KeyType]) ValidateReferences ¶ added in v0.11.0
func (o OneOfSchema[KeyType]) ValidateReferences() error
func (OneOfSchema[KeyType]) ValidateType ¶
func (o OneOfSchema[KeyType]) ValidateType(data any) error
type OneOfString ¶
OneOfString holds the definition of variable types with an integer discriminator. This type acts as a split for a case where multiple possible object types can be present in a field. This type requires that there be a common field (the discriminator) which tells a parsing party which type it is. The field type in this case is a string.
type Pattern ¶
Pattern holds the schema information for regular expression patterns. This dataclass only has the ability to hold the configuration but cannot serialize, unserialize or validate. For that functionality please use PatternType.
type PatternSchema ¶
type PatternSchema struct {
ScalarType
}
Example ¶
package main import ( "fmt" "go.flow.arcalot.io/pluginsdk/schema" ) func main() { patternType := schema.NewPatternSchema() // Unserialize a string pattern, err := patternType.UnserializeType("^[a-z]+$") if err != nil { panic(err) } if pattern.MatchString("asdf") { fmt.Println("The pattern matches!") } }
Output: The pattern matches!
func NewPatternSchema ¶
func NewPatternSchema() *PatternSchema
NewPatternSchema creates a new pattern schema.
func (PatternSchema) ReflectedType ¶
func (p PatternSchema) ReflectedType() reflect.Type
func (PatternSchema) SerializeType ¶
func (p PatternSchema) SerializeType(data *regexp.Regexp) (any, error)
func (PatternSchema) TypeID ¶
func (p PatternSchema) TypeID() TypeID
func (PatternSchema) Unserialize ¶
func (p PatternSchema) Unserialize(data any) (any, error)
func (PatternSchema) UnserializeType ¶
func (p PatternSchema) UnserializeType(data any) (*regexp.Regexp, error)
func (PatternSchema) Validate ¶
func (p PatternSchema) Validate(d any) error
func (PatternSchema) ValidateCompatibility ¶ added in v0.4.1
func (p PatternSchema) ValidateCompatibility(typeOrData any) error
func (PatternSchema) ValidateType ¶
func (p PatternSchema) ValidateType(data *regexp.Regexp) error
type Property ¶
type Property interface { Type // Type returns the underlying type this property holds. Type() Type Display() Display Default() *string Required() bool RequiredIf() []string RequiredIfNot() []string Conflicts() []string Examples() []string }
Property holds the schema definition for a single object property. It is usable in conjunction with Object.
type PropertySchema ¶
type PropertySchema struct { TypeValue Type `json:"type"` DisplayValue Display `json:"display"` RequiredValue bool `json:"required"` RequiredIfValue []string `json:"required_if"` RequiredIfNotValue []string `json:"required_if_not"` ConflictsValue []string `json:"conflicts"` DefaultValue *string `json:"default"` ExamplesValue []string `json:"examples"` // Disabled sets whether the field can be used. Set the DisabledReason if set to true. Disabled bool `json:"disabled"` // DisabledReason explains why the property is disabled. Default nil DisabledReason *string `json:"disabled_reason"` // contains filtered or unexported fields }
func NewPropertySchema ¶
func NewPropertySchema( t Type, displayValue Display, required bool, requiredIf []string, requiredIfNot []string, conflicts []string, defaultValue *string, examples []string, ) *PropertySchema
NewPropertySchema creates a new object property schema.
func (*PropertySchema) ApplyNamespace ¶ added in v0.12.0
func (p *PropertySchema) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
func (*PropertySchema) Conflicts ¶
func (p *PropertySchema) Conflicts() []string
func (*PropertySchema) Default ¶
func (p *PropertySchema) Default() *string
func (*PropertySchema) Disable ¶ added in v0.4.1
func (p *PropertySchema) Disable(reason string) *PropertySchema
Disable is a builder-pattern way of disabling the property.
func (*PropertySchema) Display ¶
func (p *PropertySchema) Display() Display
func (*PropertySchema) Examples ¶
func (p *PropertySchema) Examples() []string
func (*PropertySchema) ReflectedType ¶
func (p *PropertySchema) ReflectedType() reflect.Type
func (*PropertySchema) Required ¶
func (p *PropertySchema) Required() bool
func (*PropertySchema) RequiredIf ¶
func (p *PropertySchema) RequiredIf() []string
func (*PropertySchema) RequiredIfNot ¶
func (p *PropertySchema) RequiredIfNot() []string
func (*PropertySchema) TreatEmptyAsDefaultValue ¶
func (p *PropertySchema) TreatEmptyAsDefaultValue() *PropertySchema
TreatEmptyAsDefaultValue triggers the property to treat an empty value (e.g. "", or 0) as the default value for serialization and validation only. It has no effect on objects that are not mapped to a struct.
This is useful in case of third party structs where the property may not have a pointer despite being optional. However, to avoid ambiguity and better performance, this option should be used only when needed.
func (*PropertySchema) Type ¶
func (p *PropertySchema) Type() Type
func (*PropertySchema) TypeID ¶
func (p *PropertySchema) TypeID() TypeID
func (*PropertySchema) Unserialize ¶
func (p *PropertySchema) Unserialize(data any) (any, error)
func (*PropertySchema) Validate ¶
func (p *PropertySchema) Validate(data any) error
func (*PropertySchema) ValidateCompatibility ¶ added in v0.4.1
func (p *PropertySchema) ValidateCompatibility(typeOrData any) error
func (*PropertySchema) ValidateReferences ¶ added in v0.11.0
func (p *PropertySchema) ValidateReferences() error
type Ref ¶
type Ref interface { Object ID() string Namespace() string Display() Display GetObject() Object ObjectReady() bool }
Ref holds the definition of a reference to a scope-wide object. The ref must always be inside a scope, either directly or indirectly. If several scopes are embedded within each other, the Ref references the object in the scope specified. SelfNamespace refers to the current scope.
type RefSchema ¶
type RefSchema struct { IDValue string `json:"id"` DisplayValue Display `json:"display"` ObjectNamespace string `json:"namespace"` // contains filtered or unexported fields }
func NewNamespacedRefSchema ¶ added in v0.11.0
NewNamespacedRefSchema creates a new reference to an object in a wrapping Scope by ID and namespace.
func NewRefSchema ¶
NewRefSchema creates a new reference to an object in a wrapping Scope by ID.
func (*RefSchema) ApplyNamespace ¶ added in v0.12.0
func (r *RefSchema) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
ApplyNamespace links the reference to the object if the given namespace matches the ref's namespace. Other namespaces are skipped.
func (*RefSchema) GetDefaults ¶
func (*RefSchema) IDUnenforced ¶ added in v0.13.0
func (*RefSchema) ObjectReady ¶ added in v0.11.0
func (*RefSchema) Properties ¶
func (r *RefSchema) Properties() map[string]*PropertySchema
func (*RefSchema) ReflectedType ¶
func (*RefSchema) ValidateCompatibility ¶ added in v0.4.1
func (*RefSchema) ValidateReferences ¶ added in v0.11.0
type ScalarType ¶ added in v0.12.0
type ScalarType struct { }
ScalarType is a struct that provides default implementations for ApplyNamespace and ValidateReferences for types that cannot contain references.
func (*ScalarType) ApplyNamespace ¶ added in v0.12.0
func (s *ScalarType) ApplyNamespace(_ map[string]*ObjectSchema, _ string)
func (*ScalarType) ValidateReferences ¶ added in v0.12.0
func (s *ScalarType) ValidateReferences() error
type SchemaSchema ¶
type SchemaSchema struct {
StepsValue map[string]*StepSchema `json:"steps"`
}
func UnserializeSchema ¶
func UnserializeSchema(data any) (*SchemaSchema, error)
UnserializeSchema unserializes an entire schema definition from raw data.
func (SchemaSchema) SelfSerialize ¶
func (s SchemaSchema) SelfSerialize() (any, error)
func (SchemaSchema) Steps ¶
func (s SchemaSchema) Steps() map[string]Step
type Scope ¶
type Scope interface { Object Objects() map[string]*ObjectSchema Root() string RootObject() *ObjectSchema ApplySelf() SelfSerialize() (any, error) }
Scope is a container for holding objects that can be referenced. It also optionally holds a reference to the root object of the current scope. References within the scope must always reference IDs in a scope. Scopes can be embedded into other objects, and scopes can have subscopes. Each Ref will reference objects in its current scope.
type ScopeSchema ¶
type ScopeSchema struct { ObjectsValue map[string]*ObjectSchema `json:"objects"` RootValue string `json:"root"` }
func DescribeSchema ¶
func DescribeSchema() *ScopeSchema
DescribeSchema returns a scope that describes a plugin schema.
func DescribeScope ¶
func DescribeScope() *ScopeSchema
DescribeScope returns a scope that describes the ScopeSchema itself.
func DescribeStepOutput ¶ added in v0.1.3
func DescribeStepOutput() *ScopeSchema
DescribeStepOutput returns a scope that describes a step output.
func NewScopeSchema ¶
func NewScopeSchema(rootObject *ObjectSchema, objects ...*ObjectSchema) *ScopeSchema
NewScopeSchema returns a new scope.
func NewScopeSchemaFromScope ¶ added in v0.4.1
func NewScopeSchemaFromScope(scope Scope) *ScopeSchema
NewScopeSchemaFromScope returns a new scope.
func UnserializeScope ¶
func UnserializeScope(data any) (*ScopeSchema, error)
UnserializeScope unserializes a scope definition from raw data.
func (*ScopeSchema) ApplyNamespace ¶ added in v0.12.0
func (s *ScopeSchema) ApplyNamespace(externalObjects map[string]*ObjectSchema, namespace string)
func (*ScopeSchema) ApplySelf ¶ added in v0.12.0
func (s *ScopeSchema) ApplySelf()
func (*ScopeSchema) GetDefaults ¶
func (s *ScopeSchema) GetDefaults() map[string]any
func (*ScopeSchema) ID ¶
func (s *ScopeSchema) ID() string
func (*ScopeSchema) IDUnenforced ¶ added in v0.13.0
func (s *ScopeSchema) IDUnenforced() bool
func (*ScopeSchema) Objects ¶
func (s *ScopeSchema) Objects() map[string]*ObjectSchema
func (*ScopeSchema) Properties ¶
func (s *ScopeSchema) Properties() map[string]*PropertySchema
func (*ScopeSchema) ReflectedType ¶
func (s *ScopeSchema) ReflectedType() reflect.Type
func (*ScopeSchema) Root ¶
func (s *ScopeSchema) Root() string
func (*ScopeSchema) RootObject ¶ added in v0.11.0
func (s *ScopeSchema) RootObject() *ObjectSchema
func (*ScopeSchema) SelfSerialize ¶
func (s *ScopeSchema) SelfSerialize() (any, error)
func (*ScopeSchema) TypeID ¶
func (s *ScopeSchema) TypeID() TypeID
func (*ScopeSchema) Unserialize ¶
func (s *ScopeSchema) Unserialize(data any) (any, error)
func (*ScopeSchema) Validate ¶
func (s *ScopeSchema) Validate(data any) error
func (*ScopeSchema) ValidateCompatibility ¶ added in v0.4.1
func (s *ScopeSchema) ValidateCompatibility(typeOrData any) error
func (*ScopeSchema) ValidateReferences ¶ added in v0.11.0
func (s *ScopeSchema) ValidateReferences() error
type Serializable ¶
type Serializable interface { // ReflectedType returns the underlying unserialized type. ReflectedType() reflect.Type // Unserialize unserializes the provided data. Unserialize(data any) (any, error) // Validate validates the specified unserialized data in accordance with the schema. Validate(data any) error // ValidateCompatibility validates the specified serialized data or schema is compatible with the schema. ValidateCompatibility(typeOrData any) error // Serialize serializes the provided data. Serialize(data any) (any, error) // ApplyNamespace makes namespace object available to resolve references. ApplyNamespace(objects map[string]*ObjectSchema, namespace string) // ValidateReferences validates that all references had their referenced objects found. // Useful to ensure the error is caught early rather than later when it's used. ValidateReferences() error }
Serializable describes the minimum feature set a part of the schema hierarchy must implement.
type Signal ¶ added in v0.4.1
Signal holds the definition for a single signal. This is universal for emitted or received.
type SignalSchema ¶ added in v0.4.1
type SignalSchema struct { IDValue string `json:"id"` DataSchemaValue Scope `json:"data_schema"` DisplayValue Display `json:"display"` }
SignalSchema describes a single signal in a schema to execute one task. It has a fixed data input or output, which is either input or output depending on whether it's receiving or emitting the signal.
func NewSignalSchema ¶ added in v0.4.1
func NewSignalSchema( id string, dataSchema Scope, display Display, ) *SignalSchema
NewSignalSchema defines a new signal.
func (SignalSchema) DataSchema ¶ added in v0.4.1
func (s SignalSchema) DataSchema() Scope
func (SignalSchema) Display ¶ added in v0.4.1
func (s SignalSchema) Display() Display
func (SignalSchema) ID ¶ added in v0.4.1
func (s SignalSchema) ID() string
type Step ¶
type Step interface { ID() string Input() Scope Outputs() map[string]*StepOutputSchema SignalHandlers() map[string]*SignalSchema SignalEmitters() map[string]*SignalSchema Display() Display }
Step holds the definition for a single step, it's input and output definitions.
type StepOutput ¶
type StepOutput interface { Serializable Schema() Scope Display() *DisplayValue Error() bool }
StepOutput holds the possible outputs of a step and the metadata information related to these outputs.
This schema only has the ability to hold the configuration but cannot serialize, unserialize or validate. For that functionality please use StepOutputType.
type StepOutputSchema ¶
type StepOutputSchema struct { SchemaValue Scope `json:"schema"` DisplayValue *DisplayValue `json:"display"` ErrorValue bool `json:"error"` }
func NewStepOutputSchema ¶
func NewStepOutputSchema( schema Scope, display *DisplayValue, error bool, ) *StepOutputSchema
NewStepOutputSchema defines a new output for a step.
func (StepOutputSchema) ApplyNamespace ¶ added in v0.12.0
func (s StepOutputSchema) ApplyNamespace(objects map[string]*ObjectSchema, namespace string)
func (StepOutputSchema) Display ¶
func (s StepOutputSchema) Display() *DisplayValue
func (StepOutputSchema) Error ¶
func (s StepOutputSchema) Error() bool
func (StepOutputSchema) ReflectedType ¶
func (s StepOutputSchema) ReflectedType() reflect.Type
func (StepOutputSchema) Schema ¶
func (s StepOutputSchema) Schema() Scope
func (StepOutputSchema) Unserialize ¶
func (s StepOutputSchema) Unserialize(data any) (any, error)
func (StepOutputSchema) Validate ¶
func (s StepOutputSchema) Validate(data any) error
func (StepOutputSchema) ValidateCompatibility ¶ added in v0.4.1
func (s StepOutputSchema) ValidateCompatibility(data any) error
func (StepOutputSchema) ValidateReferences ¶ added in v0.11.0
func (s StepOutputSchema) ValidateReferences() error
type StepSchema ¶
type StepSchema struct { IDValue string `json:"id"` InputValue Scope `json:"input"` OutputsValue map[string]*StepOutputSchema `json:"outputs"` SignalHandlersValue map[string]*SignalSchema `json:"signal_handlers"` SignalEmittersValue map[string]*SignalSchema `json:"signal_emitters"` DisplayValue Display `json:"display"` }
StepSchema describes a single step in a schema to execute one task. It has a fixed input and one or more outputs, denominated by a string output ID.
func NewStepSchema ¶
func NewStepSchema( id string, input Scope, outputs map[string]*StepOutputSchema, signalHandlers map[string]*SignalSchema, signalEmitters map[string]*SignalSchema, display Display, ) *StepSchema
NewStepSchema defines a new step.
func (StepSchema) Display ¶
func (s StepSchema) Display() Display
func (StepSchema) ID ¶
func (s StepSchema) ID() string
func (StepSchema) Input ¶
func (s StepSchema) Input() Scope
func (StepSchema) Outputs ¶
func (s StepSchema) Outputs() map[string]*StepOutputSchema
func (StepSchema) SignalEmitters ¶ added in v0.4.1
func (s StepSchema) SignalEmitters() map[string]*SignalSchema
func (StepSchema) SignalHandlers ¶ added in v0.4.1
func (s StepSchema) SignalHandlers() map[string]*SignalSchema
type String ¶
String holds schema information for strings. This dataclass only has the ability to hold the configuration but cannot serialize, unserialize or validate. For that functionality please use StringType.
type StringEnum ¶
StringEnum is an enum type with string values.
type StringEnumSchema ¶
type StringEnumSchema struct { TypedStringEnumSchema[string] `json:",inline"` }
StringEnumSchema is an enum type with string values.
func NewStringEnumSchema ¶
func NewStringEnumSchema(validValues map[string]*DisplayValue) *StringEnumSchema
NewStringEnumSchema creates a new enum of string values.
Example ¶
package main import ( "fmt" "go.flow.arcalot.io/pluginsdk/schema" ) func main() { // Create a new enum type by defining its valid values: portionSize := schema.NewStringEnumSchema(map[string]*schema.DisplayValue{ "small": {NameValue: schema.PointerTo("Small")}, "large": {NameValue: schema.PointerTo("Large")}, }) // You can now print the valid values: fmt.Println(*portionSize.ValidValues()["large"].NameValue) }
Output: Large
type StringSchema ¶
type StringSchema struct { ScalarType MinValue *int64 `json:"min"` MaxValue *int64 `json:"max"` PatternValue *regexp.Regexp `json:"pattern"` }
Example ¶
package main import ( "fmt" "regexp" "go.flow.arcalot.io/pluginsdk/schema" ) func main() { var stringType schema.String = schema.NewStringSchema( schema.IntPointer(5), schema.IntPointer(16), regexp.MustCompile("^[a-z]+$"), ) // This will fail because it's too short: _, err := stringType.Unserialize("abcd") fmt.Println(err) // This will fail because it's too long: _, err = stringType.Unserialize("abcdefghijklmnopqrstuvwxyz") fmt.Println(err) // This will succeed: unserialized, err := stringType.Unserialize("abcde") if err != nil { panic(err) } fmt.Println(unserialized) // You can validate existing strings: err = stringType.Validate("asdf") fmt.Println(err) // You can also serialize-validate strings: serialized, err := stringType.Serialize("asdfg") if err != nil { panic(err) } fmt.Println(serialized) }
Output: Validation failed: String must be at least 5 characters, 4 given Validation failed: String must be at most 16 characters, 26 given abcde Validation failed: String must be at least 5 characters, 4 given asdfg
func NewStringSchema ¶
func NewStringSchema(minLen *int64, maxLen *int64, pattern *regexp.Regexp) *StringSchema
NewStringSchema creates a new string schema. If the corresponding Golang type is not a string, but a type defined from a string (example `type NameOfType string`), use `NewTypedStringEnumSchema` instead.
func (StringSchema) Max ¶
func (s StringSchema) Max() *int64
Max returns the max length of the string.
func (StringSchema) Min ¶
func (s StringSchema) Min() *int64
Min returns the min length of the string.
func (StringSchema) Pattern ¶
func (s StringSchema) Pattern() *regexp.Regexp
func (StringSchema) ReflectedType ¶
func (s StringSchema) ReflectedType() reflect.Type
func (StringSchema) SerializeType ¶
func (s StringSchema) SerializeType(data string) (any, error)
func (StringSchema) TypeID ¶
func (s StringSchema) TypeID() TypeID
func (StringSchema) Unserialize ¶
func (s StringSchema) Unserialize(data any) (any, error)
func (StringSchema) UnserializeType ¶
func (s StringSchema) UnserializeType(data any) (string, error)
func (StringSchema) Validate ¶
func (s StringSchema) Validate(d any) error
func (StringSchema) ValidateCompatibility ¶ added in v0.4.1
func (s StringSchema) ValidateCompatibility(typeOrData any) error
func (StringSchema) ValidateType ¶
func (s StringSchema) ValidateType(data string) error
type Type ¶
type Type interface { Serializable // TypeID returns the type of the current schema entry. TypeID() TypeID }
Type adds the type ID to Serializable as part of the Schema tree.
type TypeID ¶
type TypeID string
TypeID is the identifier for types supported in the type system.
const ( // TypeIDStringEnum is a type that satisfies the StringEnum. TypeIDStringEnum TypeID = "enum_string" // TypeIDIntEnum is a type that satisfies the StringIntSchema. TypeIDIntEnum TypeID = "enum_integer" // TypeIDString is a type that satisfies the String. TypeIDString TypeID = "string" // TypeIDPattern is a type that satisfies the Pattern. TypeIDPattern TypeID = "pattern" // TypeIDInt is a type that satisfies the Int. TypeIDInt TypeID = "integer" // TypeIDFloat is a type that satisfies the Float. TypeIDFloat TypeID = "float" // TypeIDBool is a type that satisfies the BoolSchema. TypeIDBool TypeID = "bool" // TypeIDList is a type that satisfies the List. TypeIDList TypeID = "list" // TypeIDMap is a type that satisfies the Map. TypeIDMap TypeID = "map" // TypeIDScope is a type that satisfies the Scope. TypeIDScope TypeID = "scope" // TypeIDObject is a type that satisfies the Object. TypeIDObject TypeID = "object" // TypeIDOneOfString is a type that satisfies the OneOfStringSchema. TypeIDOneOfString TypeID = "one_of_string" // TypeIDOneOfInt is a type that satisfies the OneOfInt. TypeIDOneOfInt TypeID = "one_of_int" // TypeIDRef is a type that references an object in a Scope. TypeIDRef TypeID = "ref" // TypeIDAny refers to an any type. This type essentially amounts to unchecked types, as long as they are: // // - maps // - lists // - int64 // - float64 // - string // - bool // // No other types are accepted. TypeIDAny TypeID = "any" )
type TypedList ¶
type TypedList[UnserializedType any, ItemType TypedType[UnserializedType]] interface { List[ItemType] TypedType[[]UnserializedType] }
TypedList extends List by providing typed unserialization.
type TypedListSchema ¶
type TypedListSchema[UnserializedType any, ItemType TypedType[UnserializedType]] struct { AbstractListSchema[ItemType] `json:",inline"` }
TypedListSchema is the typed variant of the list.
func NewTypedListSchema ¶
func NewTypedListSchema[UnserializedType any]( items TypedType[UnserializedType], min *int64, max *int64, ) *TypedListSchema[UnserializedType, TypedType[UnserializedType]]
NewTypedListSchema creates a new list schema from the specified values with typed unserialization.
func (TypedListSchema[UnserializedType, ItemType]) SerializeType ¶
func (t TypedListSchema[UnserializedType, ItemType]) SerializeType(data []UnserializedType) (any, error)
func (TypedListSchema[UnserializedType, ItemType]) UnserializeType ¶
func (t TypedListSchema[UnserializedType, ItemType]) UnserializeType(data any) (result []UnserializedType, err error)
func (TypedListSchema[UnserializedType, ItemType]) ValidateType ¶
func (t TypedListSchema[UnserializedType, ItemType]) ValidateType(data []UnserializedType) error
type TypedMap ¶
type TypedMap[KeyType comparable, ValueType any] interface { TypedType[map[KeyType]ValueType] Map[TypedType[KeyType], TypedType[ValueType]] }
TypedMap is a map schema that can be unserialized in its underlying components.
type TypedMapSchema ¶
type TypedMapSchema[KeyType comparable, ValueType any] struct { MapSchema[TypedType[KeyType], TypedType[ValueType]] }
func NewTypedMapSchema ¶
func NewTypedMapSchema[KeyType comparable, ValueType any]( keys TypedType[KeyType], values TypedType[ValueType], min *int64, max *int64, ) *TypedMapSchema[KeyType, ValueType]
NewTypedMapSchema creates a new map schema with a defined underlying type.
func (TypedMapSchema[KeyType, ValueType]) SerializeType ¶
func (m TypedMapSchema[KeyType, ValueType]) SerializeType(data map[KeyType]ValueType) (any, error)
func (TypedMapSchema[KeyType, ValueType]) UnserializeType ¶
func (m TypedMapSchema[KeyType, ValueType]) UnserializeType(data any) (result map[KeyType]ValueType, err error)
func (TypedMapSchema[KeyType, ValueType]) ValidateType ¶
func (m TypedMapSchema[KeyType, ValueType]) ValidateType(data map[KeyType]ValueType) error
type TypedObject ¶
type TypedObject[T any] interface { Object TypedType[T] Any() TypedObject[any] }
TypedObject is a serializable version of Object.
type TypedObjectSchema ¶
type TypedObjectSchema[T any] struct { ObjectSchema `json:",inline"` }
func NewTypedObject ¶
func NewTypedObject[T any](id string, properties map[string]*PropertySchema) *TypedObjectSchema[T]
func (TypedObjectSchema[T]) Any ¶
func (t TypedObjectSchema[T]) Any() TypedObject[any]
func (TypedObjectSchema[T]) SerializeType ¶
func (t TypedObjectSchema[T]) SerializeType(data T) (any, error)
func (TypedObjectSchema[T]) UnserializeType ¶
func (t TypedObjectSchema[T]) UnserializeType(data any) (T, error)
func (TypedObjectSchema[T]) ValidateType ¶
func (t TypedObjectSchema[T]) ValidateType(data T) error
type TypedScopeSchema ¶
type TypedScopeSchema[T any] struct { ScopeSchema `json:",inline"` }
TypedScopeSchema is a typed variant of the ScopeSchema, allowing for direct type use. This should not be used in full schema definitions as the type parameter will prevent it from being added to lists thanks to the simplistic generics system in Go.
func NewTypedScopeSchema ¶
func NewTypedScopeSchema[T any](rootObject *ObjectSchema, objects ...*ObjectSchema) *TypedScopeSchema[T]
NewTypedScopeSchema returns a new scope that is typed.
func (TypedScopeSchema[T]) SerializeType ¶
func (t TypedScopeSchema[T]) SerializeType(data T) (any, error)
func (TypedScopeSchema[T]) UnserializeType ¶
func (t TypedScopeSchema[T]) UnserializeType(data any) (result T, err error)
func (TypedScopeSchema[T]) ValidateType ¶
func (t TypedScopeSchema[T]) ValidateType(data T) error
type TypedStringEnumSchema ¶ added in v0.14.0
type TypedStringEnumSchema[T ~string] struct { EnumSchema[string, T] `json:",inline"` }
TypedStringEnumSchema is an enum type with string values, but with a generic element for golang enums that have an underlying string type.
func NewTypedStringEnumSchema ¶ added in v0.14.0
func NewTypedStringEnumSchema[T ~string](validValues map[T]*DisplayValue) *TypedStringEnumSchema[T]
NewTypedStringEnumSchema allows the use of a type with string as an underlying type. Useful for external APIs that are being mapped to a schema that use string enums.
func (TypedStringEnumSchema[T]) TypeID ¶ added in v0.14.0
func (s TypedStringEnumSchema[T]) TypeID() TypeID
func (TypedStringEnumSchema[T]) Unserialize ¶ added in v0.14.0
func (s TypedStringEnumSchema[T]) Unserialize(data any) (any, error)
func (TypedStringEnumSchema[T]) UnserializeType ¶ added in v0.14.0
func (s TypedStringEnumSchema[T]) UnserializeType(data any) (string, error)
type TypedType ¶
type TypedType[T any] interface { Type UnserializeType(data any) (T, error) ValidateType(data T) error SerializeType(data T) (any, error) }
TypedType provides additional functionality for unserializing types in a type-safe manner.
type Unit ¶
type Unit interface { NameShortSingular() string NameShortPlural() string NameLongSingular() string NameLongPlural() string FormatShortInt(amount int64, displayZero bool) string FormatShortFloat(amount float64, displayZero bool) string FormatLongInt(amount int64, displayZero bool) string FormatLongFloat(amount float64, displayZero bool) string }
Unit is a description of a single scale of measurement, such as a "second". If there are multiple scales, such as "minute", "second", etc. then multiple of these UnitDefinition classes can be composed into UnitsDefinition.
type UnitDefinition ¶
type UnitDefinition struct { NameShortSingularValue string `json:"name_short_singular"` NameShortPluralValue string `json:"name_short_plural"` NameLongSingularValue string `json:"name_long_singular"` NameLongPluralValue string `json:"name_long_plural"` }
func NewUnit ¶
func NewUnit(nameSortSingular string, nameShortPlural string, nameLongSingular string, nameLongPlural string) *UnitDefinition
NewUnit defines a new UnitDefinition with the given parameters.
func (*UnitDefinition) FormatLongFloat ¶
func (u *UnitDefinition) FormatLongFloat(amount float64, displayZero bool) string
func (*UnitDefinition) FormatLongInt ¶
func (u *UnitDefinition) FormatLongInt(amount int64, displayZero bool) string
func (*UnitDefinition) FormatShortFloat ¶
func (u *UnitDefinition) FormatShortFloat(amount float64, displayZero bool) string
func (*UnitDefinition) FormatShortInt ¶
func (u *UnitDefinition) FormatShortInt(amount int64, displayZero bool) string
func (*UnitDefinition) NameLongPlural ¶
func (u *UnitDefinition) NameLongPlural() string
func (*UnitDefinition) NameLongSingular ¶
func (u *UnitDefinition) NameLongSingular() string
func (*UnitDefinition) NameShortPlural ¶
func (u *UnitDefinition) NameShortPlural() string
func (*UnitDefinition) NameShortSingular ¶
func (u *UnitDefinition) NameShortSingular() string
type UnitParseError ¶
UnitParseError indicates that it failed to parse a UnitDefinition string.
func (UnitParseError) Error ¶
func (u UnitParseError) Error() string
Error returns the error message.
func (UnitParseError) Unwrap ¶
func (u UnitParseError) Unwrap() error
Unwrap returns the underlying error if any.
type Units ¶
type Units interface { BaseUnit() *UnitDefinition Multipliers() map[int64]*UnitDefinition ParseInt(data string) (int64, error) ParseFloat(data string) (float64, error) FormatShortInt(data int64) string FormatShortFloat(data float64) string FormatLongInt(data int64) string FormatLongFloat(data float64) string }
Units holds several scales of magnitude of the same UnitDefinition, for example 5m30s.
type UnitsDefinition ¶
type UnitsDefinition struct { BaseUnitValue *UnitDefinition `json:"base_unit"` MultipliersValue map[int64]*UnitDefinition `json:"multipliers"` // contains filtered or unexported fields }
func NewUnits ¶
func NewUnits(baseUnit *UnitDefinition, multipliers map[int64]*UnitDefinition) *UnitsDefinition
NewUnits defines a new set of UnitsDefinition with the given parameters.
func (*UnitsDefinition) BaseUnit ¶
func (u *UnitsDefinition) BaseUnit() *UnitDefinition
func (*UnitsDefinition) FormatLongFloat ¶
func (u *UnitsDefinition) FormatLongFloat(data float64) string
FormatLongFloat formats the passed float according to the UnitDefinition multipliers.
func (*UnitsDefinition) FormatLongInt ¶
func (u *UnitsDefinition) FormatLongInt(data int64) string
FormatLongInt formats the passed int according to the UnitDefinition multipliers.
func (*UnitsDefinition) FormatShortFloat ¶
func (u *UnitsDefinition) FormatShortFloat(data float64) string
FormatShortFloat formats the passed float according to the UnitDefinition multipliers.
func (*UnitsDefinition) FormatShortInt ¶
func (u *UnitsDefinition) FormatShortInt(data int64) string
FormatShortInt formats the passed int according to the UnitDefinition multipliers.
func (*UnitsDefinition) Multipliers ¶
func (u *UnitsDefinition) Multipliers() map[int64]*UnitDefinition
func (*UnitsDefinition) ParseFloat ¶
func (u *UnitsDefinition) ParseFloat(data string) (float64, error)
ParseFloat parses a string into a floating point number.
type UntypedList ¶ added in v0.1.2
UntypedList specifies a list that has no specific type.
type UntypedMap ¶
UntypedMap is a map schema without specific underlying types.
Source Files
¶
- any.go
- bool.go
- display.go
- enum.go
- enum_int.go
- enum_string.go
- errors.go
- float.go
- function.go
- input.go
- int.go
- list.go
- map.go
- object.go
- oneof.go
- oneof_int.go
- oneof_string.go
- optional.go
- pattern.go
- property.go
- ref.go
- schema.go
- schema_schema.go
- scope.go
- signal.go
- step.go
- step_output.go
- string.go
- types.go
- units.go