schema

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UnionStyle_Kinded   = UnionStyle{"kinded"}
	UnionStyle_Keyed    = UnionStyle{"keyed"}
	UnionStyle_Envelope = UnionStyle{"envelope"}
	UnionStyle_Inline   = UnionStyle{"inline"}
)

Functions

This section is empty.

Types

type Kind

type Kind uint8

Kind is an enum of kind in the IPLD Schema system.

Note that schema.Kind is distinct from ipld.ReprKind! Schema kinds include concepts such as "struct" and "enum", which are concepts only introduced by the Schema layer, and not present in the Data Model layer.

const (
	Kind_Invalid Kind = 0
	Kind_Map     Kind = '{'
	Kind_List    Kind = '['
	Kind_Unit    Kind = '1'
	Kind_Bool    Kind = 'b'
	Kind_Int     Kind = 'i'
	Kind_Float   Kind = 'f'
	Kind_String  Kind = 's'
	Kind_Bytes   Kind = 'x'
	Kind_Link    Kind = '/'
	Kind_Struct  Kind = '$'
	Kind_Union   Kind = '^'
	Kind_Enum    Kind = '%'
)

func (Kind) ActsLike

func (k Kind) ActsLike() ipld.ReprKind

ActsLike returns a constant from the ipld.ReprKind enum describing what this schema.Kind acts like at the Data Model layer.

Things with similar names are generally conserved (e.g. "map" acts like "map"); concepts added by the schema layer have to be mapped onto something (e.g. "struct" acts like "map").

Note that this mapping describes how a typed Node will *act*, programmatically; it does not necessarily describe how it will be *serialized* (for example, a struct will always act like a map, even if it has a tuple representation strategy and thus becomes a list when serialized).

func (Kind) String

func (k Kind) String() string

type StructField

type StructField struct {
	// contains filtered or unexported fields
}

func SpawnStructField

func SpawnStructField(name string, typ Type, optional bool, nullable bool) StructField

func (StructField) IsNullable

func (f StructField) IsNullable() bool

IsNullable returns true if the field value is allowed to be null.

If is Nullable is false, note that it's still possible that the field value will be absent if the field is Optional! Being nullable is unrelated to whether the field's presence is optional as a whole.

Note that a field may be both nullable and optional simultaneously, or either, or neither.

func (StructField) IsOptional

func (f StructField) IsOptional() bool

IsOptional returns true if the field is allowed to be absent from the object. If IsOptional is false, the field may be absent from the serial representation of the object entirely.

Note being optional is different than saying the value is permitted to be null! A field may be both nullable and optional simultaneously, or either, or neither.

func (StructField) Name

func (f StructField) Name() string

Name returns the string name of this field. The name is the string that will be used as a map key if the structure this field is a member of is serialized as a map representation.

func (StructField) Type

func (f StructField) Type() Type

Type returns the Type of this field's value. Note the field may also be unset if it is either Optional or Nullable.

type StructRepresentation

type StructRepresentation interface {
	// contains filtered or unexported methods
}

type StructRepresentation_Map

type StructRepresentation_Map struct {
	// contains filtered or unexported fields
}

func (StructRepresentation_Map) GetFieldKey

func (r StructRepresentation_Map) GetFieldKey(field StructField) string

type StructRepresentation_StringJoin

type StructRepresentation_StringJoin struct {
	// contains filtered or unexported fields
}

type StructRepresentation_StringPairs

type StructRepresentation_StringPairs struct {
	// contains filtered or unexported fields
}

type StructRepresentation_Tuple

type StructRepresentation_Tuple struct{}

type Type

type Type interface {

	// Returns a pointer to the TypeSystem this Type is a member of.
	TypeSystem() *TypeSystem

	// Returns the string name of the Type.  This name is unique within the
	// universe this type is a member of, *unless* this type is Anonymous,
	// in which case a string describing the type will still be returned, but
	// that string will not be required to be unique.
	Name() TypeName

	// Returns the Kind of this Type.
	//
	// The returned value is a 1:1 association with which of the concrete
	// "schema.Type*" structs this interface can be cast to.
	//
	// Note that a schema.Kind is a different enum than ipld.ReprKind;
	// and furthermore, there's no strict relationship between them.
	// typed.Node values can be described by *two* distinct ReprKinds:
	// one which describes how the Node itself will act,
	// and another which describes how the Node presents for serialization.
	// For some combinations of Type and representation strategy, one or both
	// of the ReprKinds can be determined statically; but not always:
	// it can sometimes be necessary to inspect the value quite concretely
	// (e.g., `typed.Node{}.Representation().ReprKind()`) in order to find
	// out exactly how a node will be serialized!  This is because some types
	// can vary in representation kind based on their value (specifically,
	// kinded-representation unions have this property).
	Kind() Kind
	// contains filtered or unexported methods
}

typesystem.Type is an union interface; each of the `Type*` concrete types in this package are one of its members.

Specifically,

TypeBool
TypeString
TypeBytes
TypeInt
TypeFloat
TypeMap
TypeList
TypeLink
TypeUnion
TypeStruct
TypeEnum

are all of the kinds of Type.

This is a closed union; you can switch upon the above members without including a default case. The membership is closed by the unexported '_Type' method; you may use the BurntSushi/go-sumtype tool to check your switches for completeness.

Many interesting properties of each Type are only defined for that specific type, so it's typical to use a type switch to handle each type of Type. (Your humble author is truly sorry for the word-mash that results from attempting to describe the types that describe the typesystem.Type.)

For example, to inspect the kind of fields in a struct: you might cast a `Type` interface into `TypeStruct`, and then the `Fields()` on that `TypeStruct` can be inspected. (`Fields()` isn't defined for any other kind of Type.)

type TypeBool

type TypeBool struct {
	// contains filtered or unexported fields
}

func (TypeBool) Kind

func (TypeBool) Kind() Kind

func (TypeBool) Name

func (t TypeBool) Name() TypeName

func (TypeBool) TypeSystem

func (t TypeBool) TypeSystem() *TypeSystem

type TypeBytes

type TypeBytes struct {
	// contains filtered or unexported fields
}

func SpawnBytes

func SpawnBytes(name TypeName) TypeBytes

func (TypeBytes) Kind

func (TypeBytes) Kind() Kind

func (TypeBytes) Name

func (t TypeBytes) Name() TypeName

func (TypeBytes) TypeSystem

func (t TypeBytes) TypeSystem() *TypeSystem

type TypeEnum

type TypeEnum struct {
	// contains filtered or unexported fields
}

func (TypeEnum) Kind

func (TypeEnum) Kind() Kind

func (TypeEnum) Members

func (t TypeEnum) Members() []string

Members returns a slice the strings which are valid inhabitants of this enum.

func (TypeEnum) Name

func (t TypeEnum) Name() TypeName

func (TypeEnum) TypeSystem

func (t TypeEnum) TypeSystem() *TypeSystem

type TypeFloat

type TypeFloat struct {
	// contains filtered or unexported fields
}

func (TypeFloat) Kind

func (TypeFloat) Kind() Kind

func (TypeFloat) Name

func (t TypeFloat) Name() TypeName

func (TypeFloat) TypeSystem

func (t TypeFloat) TypeSystem() *TypeSystem

type TypeInt

type TypeInt struct {
	// contains filtered or unexported fields
}

func SpawnInt

func SpawnInt(name TypeName) TypeInt

func (TypeInt) Kind

func (TypeInt) Kind() Kind

func (TypeInt) Name

func (t TypeInt) Name() TypeName

func (TypeInt) TypeSystem

func (t TypeInt) TypeSystem() *TypeSystem
type TypeLink struct {
	// contains filtered or unexported fields
}
func SpawnLink(name TypeName) TypeLink

func (TypeLink) Kind

func (TypeLink) Kind() Kind

func (TypeLink) Name

func (t TypeLink) Name() TypeName

func (TypeLink) TypeSystem

func (t TypeLink) TypeSystem() *TypeSystem

type TypeList

type TypeList struct {
	// contains filtered or unexported fields
}

func SpawnList

func SpawnList(name TypeName, typ Type, nullable bool) TypeList

func (TypeList) IsAnonymous

func (t TypeList) IsAnonymous() bool

IsAnonymous is returns true if the type was unnamed. Unnamed types will claim to have a Name property like `[Foo]`, and this is not guaranteed to be a unique string for all types in the universe.

func (TypeList) Kind

func (TypeList) Kind() Kind

func (TypeList) Name

func (t TypeList) Name() TypeName

func (TypeList) TypeSystem

func (t TypeList) TypeSystem() *TypeSystem

func (TypeList) ValueIsNullable

func (t TypeList) ValueIsNullable() bool

ValueIsNullable returns a bool describing if the list values are permitted to be null.

func (TypeList) ValueType

func (t TypeList) ValueType() Type

ValueType returns to the Type of the list values.

type TypeMap

type TypeMap struct {
	// contains filtered or unexported fields
}

func (TypeMap) IsAnonymous

func (t TypeMap) IsAnonymous() bool

IsAnonymous is returns true if the type was unnamed. Unnamed types will claim to have a Name property like `{Foo:Bar}`, and this is not guaranteed to be a unique string for all types in the universe.

func (TypeMap) KeyType

func (t TypeMap) KeyType() Type

KeyType returns the Type of the map keys.

Note that map keys will must always be some type which is representable as a string in the IPLD Data Model (e.g. either TypeString or TypeEnum).

func (TypeMap) Kind

func (TypeMap) Kind() Kind

func (TypeMap) Name

func (t TypeMap) Name() TypeName

func (TypeMap) TypeSystem

func (t TypeMap) TypeSystem() *TypeSystem

func (TypeMap) ValueIsNullable

func (t TypeMap) ValueIsNullable() bool

ValueIsNullable returns a bool describing if the map values are permitted to be null.

func (TypeMap) ValueType

func (t TypeMap) ValueType() Type

ValueType returns to the Type of the map values.

type TypeName

type TypeName string // = ast.TypeName

type TypeString

type TypeString struct {
	// contains filtered or unexported fields
}

func SpawnString

func SpawnString(name TypeName) TypeString

func (TypeString) Kind

func (TypeString) Kind() Kind

func (TypeString) Name

func (t TypeString) Name() TypeName

func (TypeString) TypeSystem

func (t TypeString) TypeSystem() *TypeSystem

type TypeStruct

type TypeStruct struct {
	// contains filtered or unexported fields
}

func SpawnStruct

func SpawnStruct(name TypeName, fields []StructField, repr StructRepresentation) TypeStruct

func (TypeStruct) Field

func (t TypeStruct) Field(name string) *StructField

Field looks up a StructField by name, or returns nil if no such field.

func (TypeStruct) Fields

func (t TypeStruct) Fields() []StructField

Fields returns a slice of descriptions of the object's fields.

func (TypeStruct) Kind

func (TypeStruct) Kind() Kind

func (TypeStruct) Name

func (t TypeStruct) Name() TypeName

func (TypeStruct) RepresentationStrategy

func (t TypeStruct) RepresentationStrategy() StructRepresentation

func (TypeStruct) TypeSystem

func (t TypeStruct) TypeSystem() *TypeSystem

type TypeSystem

type TypeSystem struct {
	// contains filtered or unexported fields
}

type TypeUnion

type TypeUnion struct {
	// contains filtered or unexported fields
}

func (TypeUnion) Kind

func (TypeUnion) Kind() Kind

func (TypeUnion) Name

func (t TypeUnion) Name() TypeName

func (TypeUnion) TypeSystem

func (t TypeUnion) TypeSystem() *TypeSystem

func (TypeUnion) UnionMembers

func (t TypeUnion) UnionMembers() map[Type]struct{}

UnionMembers returns a set of all the types that can inhabit this Union.

type UnionStyle

type UnionStyle struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis
gen
go
The `schema/tests` package contains behavioral tests for type-constrained Node implementations -- meant to work with either codegenerated Nodes OR with the runtime typed.Node wrappers, checking for the same behavior on each.
The `schema/tests` package contains behavioral tests for type-constrained Node implementations -- meant to work with either codegenerated Nodes OR with the runtime typed.Node wrappers, checking for the same behavior on each.

Jump to

Keyboard shortcuts

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