Documentation ¶
Index ¶
- Variables
- type Kind
- type StructField
- type StructRepresentation
- type StructRepresentation_Map
- type StructRepresentation_StringJoin
- type StructRepresentation_StringPairs
- type StructRepresentation_Tuple
- type Type
- type TypeBool
- type TypeBytes
- type TypeEnum
- type TypeFloat
- type TypeInt
- type TypeLink
- type TypeList
- type TypeMap
- type TypeName
- type TypeString
- type TypeStruct
- type TypeSystem
- type TypeUnion
- type UnionStyle
Constants ¶
This section is empty.
Variables ¶
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.
func (Kind) ActsLike ¶
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).
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
}
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) TypeSystem ¶
func (t TypeBool) TypeSystem() *TypeSystem
type TypeBytes ¶
type TypeBytes struct {
// contains filtered or unexported fields
}
func (TypeBytes) TypeSystem ¶
func (t TypeBytes) TypeSystem() *TypeSystem
type TypeEnum ¶
type TypeEnum struct {
// contains filtered or unexported fields
}
func (TypeEnum) Members ¶
Members returns a slice the strings which are valid inhabitants of this enum.
func (TypeEnum) TypeSystem ¶
func (t TypeEnum) TypeSystem() *TypeSystem
type TypeFloat ¶
type TypeFloat struct {
// contains filtered or unexported fields
}
func (TypeFloat) TypeSystem ¶
func (t TypeFloat) TypeSystem() *TypeSystem
type TypeInt ¶
type TypeInt struct {
// contains filtered or unexported fields
}
func (TypeInt) TypeSystem ¶
func (t TypeInt) TypeSystem() *TypeSystem
type TypeLink ¶
type TypeLink struct {
// contains filtered or unexported fields
}
func (TypeLink) TypeSystem ¶
func (t TypeLink) TypeSystem() *TypeSystem
type TypeList ¶
type TypeList struct {
// contains filtered or unexported fields
}
func (TypeList) IsAnonymous ¶
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) TypeSystem ¶
func (t TypeList) TypeSystem() *TypeSystem
func (TypeList) ValueIsNullable ¶
ValueIsNullable returns a bool describing if the list values are permitted to be null.
type TypeMap ¶
type TypeMap struct {
// contains filtered or unexported fields
}
func (TypeMap) IsAnonymous ¶
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 ¶
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) TypeSystem ¶
func (t TypeMap) TypeSystem() *TypeSystem
func (TypeMap) ValueIsNullable ¶
ValueIsNullable returns a bool describing if the map values are permitted to be null.
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) 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) 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) 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) TypeSystem ¶
func (t TypeUnion) TypeSystem() *TypeSystem
func (TypeUnion) UnionMembers ¶
UnionMembers returns a set of all the types that can inhabit this Union.
type UnionStyle ¶
type UnionStyle struct {
// contains filtered or unexported fields
}