schema

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnumRepresentation

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

type EnumRepresentation_Int

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

type EnumRepresentation_String

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

type StructField

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

func (*StructField) IsMaybe

func (f *StructField) IsMaybe() bool

IsMaybe returns true if the field value is allowed to be either null or absent.

This is a simple "or" of the two properties, but this method is a shorthand that turns out useful often.

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) Parent

func (f *StructField) Parent() *TypeStruct

Parent returns the type information that this field describes a part of.

While in many cases, you may know the parent already from context, there may still be situations where want to pass around a field and not need to continue passing down the parent type with it; this method helps your code be less redundant in such a situation. (You'll find this useful for looking up any rename directives, for example, when holding onto a field, since that requires looking up information from the representation strategy, which is a property of the type as a whole.)

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_Listpairs

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

type StructRepresentation_Map

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

func (StructRepresentation_Map) GetFieldKey

func (r StructRepresentation_Map) GetFieldKey(field StructField) string

GetFieldKey returns the string that should be the key when serializing this field. For some fields, it's the same as the field name; for others, a rename directive may provide a different value.

type StructRepresentation_Stringjoin

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

func (StructRepresentation_Stringjoin) GetJoinDelim

func (r StructRepresentation_Stringjoin) GetJoinDelim() string

type StructRepresentation_Stringpairs

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

type StructRepresentation_Tuple

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

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 TypeKind 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.TypeKind is a different enum than ipld.Kind;
	// and furthermore, there's no strict relationship between them.
	// schema.TypedNode values can be described by *two* distinct Kinds:
	// 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 Kinds can be determined statically; but not always:
	// it can sometimes be necessary to inspect the value quite concretely
	// (e.g., `schema.TypedNode{}.Representation().Kind()`) 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).
	TypeKind() TypeKind

	// RepresentationBehavior returns a description of how the representation
	// of this type will behave in terms of the IPLD Data Model.
	// This property varies based on the representation strategy of a type.
	//
	// In one case, the representation behavior cannot be known statically,
	// and varies based on the data: kinded unions have this trait.
	//
	// This property is used by kinded unions, which require that their members
	// all have distinct representation behavior.
	// (It follows that a kinded union cannot have another kinded union as a member.)
	//
	// You may also be interested in a related property that might have been called "TypeBehavior".
	// However, this method doesn't exist, because it's a deterministic property of `TypeKind()`!
	// You can use `TypeKind.ActsLike()` to get type-level behavioral information.
	RepresentationBehavior() ipld.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) Name

func (t *TypeBool) Name() TypeName

func (TypeBool) RepresentationBehavior

func (t TypeBool) RepresentationBehavior() ipld.Kind

func (TypeBool) TypeKind added in v0.7.0

func (TypeBool) TypeKind() TypeKind

func (*TypeBool) TypeSystem

func (t *TypeBool) TypeSystem() *TypeSystem

type TypeBytes

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

func (*TypeBytes) Name

func (t *TypeBytes) Name() TypeName

func (TypeBytes) RepresentationBehavior

func (t TypeBytes) RepresentationBehavior() ipld.Kind

func (TypeBytes) TypeKind added in v0.7.0

func (TypeBytes) TypeKind() TypeKind

func (*TypeBytes) TypeSystem

func (t *TypeBytes) TypeSystem() *TypeSystem

type TypeEnum

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

func (*TypeEnum) Name

func (t *TypeEnum) Name() TypeName

func (TypeEnum) RepresentationBehavior

func (t TypeEnum) RepresentationBehavior() ipld.Kind

func (*TypeEnum) RepresentationStrategy

func (t *TypeEnum) RepresentationStrategy() EnumRepresentation

func (TypeEnum) TypeKind added in v0.7.0

func (TypeEnum) TypeKind() TypeKind

func (*TypeEnum) TypeSystem

func (t *TypeEnum) TypeSystem() *TypeSystem

type TypeFloat

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

func (*TypeFloat) Name

func (t *TypeFloat) Name() TypeName

func (TypeFloat) RepresentationBehavior

func (t TypeFloat) RepresentationBehavior() ipld.Kind

func (TypeFloat) TypeKind added in v0.7.0

func (TypeFloat) TypeKind() TypeKind

func (*TypeFloat) TypeSystem

func (t *TypeFloat) TypeSystem() *TypeSystem

type TypeInt

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

func (*TypeInt) Name

func (t *TypeInt) Name() TypeName

func (TypeInt) RepresentationBehavior

func (t TypeInt) RepresentationBehavior() ipld.Kind

func (TypeInt) TypeKind added in v0.7.0

func (TypeInt) TypeKind() TypeKind

func (*TypeInt) TypeSystem

func (t *TypeInt) TypeSystem() *TypeSystem

type TypeKind added in v0.7.0

type TypeKind uint8

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

Note that schema.TypeKind is distinct from ipld.Kind! 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 (
	TypeKind_Invalid TypeKind = 0
	TypeKind_Map     TypeKind = '{'
	TypeKind_List    TypeKind = '['
	TypeKind_Unit    TypeKind = '1'
	TypeKind_Bool    TypeKind = 'b'
	TypeKind_Int     TypeKind = 'i'
	TypeKind_Float   TypeKind = 'f'
	TypeKind_String  TypeKind = 's'
	TypeKind_Bytes   TypeKind = 'x'
	TypeKind_Link    TypeKind = '/'
	TypeKind_Struct  TypeKind = '$'
	TypeKind_Union   TypeKind = '^'
	TypeKind_Enum    TypeKind = '%'
)

func (TypeKind) ActsLike added in v0.7.0

func (k TypeKind) ActsLike() ipld.Kind

ActsLike returns a constant from the ipld.Kind enum describing what this schema.TypeKind 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 (TypeKind) String added in v0.7.0

func (k TypeKind) String() string
type TypeLink struct {
	// contains filtered or unexported fields
}

func (*TypeLink) HasReferencedType

func (t *TypeLink) HasReferencedType() bool

HasReferencedType returns true if the link has a hint about the type it references.

func (*TypeLink) Name

func (t *TypeLink) Name() TypeName

func (*TypeLink) ReferencedType

func (t *TypeLink) ReferencedType() Type

ReferencedType returns the type which is expected for the node on the other side of the link. Nil is returned if there is no information about the expected type (which may be interpreted as "any").

func (TypeLink) RepresentationBehavior

func (t TypeLink) RepresentationBehavior() ipld.Kind

func (TypeLink) TypeKind added in v0.7.0

func (TypeLink) TypeKind() TypeKind

func (*TypeLink) TypeSystem

func (t *TypeLink) TypeSystem() *TypeSystem

type TypeList

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

func (*TypeList) Name

func (t *TypeList) Name() TypeName

func (TypeList) RepresentationBehavior

func (t TypeList) RepresentationBehavior() ipld.Kind

func (TypeList) TypeKind added in v0.7.0

func (TypeList) TypeKind() TypeKind

func (*TypeList) TypeSystem

func (t *TypeList) TypeSystem() *TypeSystem

func (*TypeList) ValueIsNullable

func (t *TypeList) ValueIsNullable() bool

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

func (*TypeList) ValueType

func (t *TypeList) ValueType() Type

ValueType returns the Type of the map values.

type TypeMap

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

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) Name

func (t *TypeMap) Name() TypeName

func (TypeMap) RepresentationBehavior

func (t TypeMap) RepresentationBehavior() ipld.Kind

func (TypeMap) TypeKind added in v0.7.0

func (TypeMap) TypeKind() TypeKind

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 the Type of the map values.

type TypeName

type TypeName = schemadmt.TypeName

type TypeReference

type TypeReference = schemadmt.TypeReference

type TypeString

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

func (*TypeString) Name

func (t *TypeString) Name() TypeName

func (TypeString) RepresentationBehavior

func (t TypeString) RepresentationBehavior() ipld.Kind

func (TypeString) TypeKind added in v0.7.0

func (TypeString) TypeKind() TypeKind

func (*TypeString) TypeSystem

func (t *TypeString) TypeSystem() *TypeSystem

type TypeStruct

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

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) Name

func (t *TypeStruct) Name() TypeName

func (TypeStruct) RepresentationBehavior

func (t TypeStruct) RepresentationBehavior() ipld.Kind

func (*TypeStruct) RepresentationStrategy

func (t *TypeStruct) RepresentationStrategy() StructRepresentation

func (TypeStruct) TypeKind added in v0.7.0

func (TypeStruct) TypeKind() TypeKind

func (*TypeStruct) TypeSystem

func (t *TypeStruct) TypeSystem() *TypeSystem

type TypeSystem

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

func BuildTypeSystem

func BuildTypeSystem(schdmt schemadmt.Schema) (*TypeSystem, []error)

type TypeUnion

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

func (*TypeUnion) Name

func (t *TypeUnion) Name() TypeName

func (TypeUnion) RepresentationBehavior

func (t TypeUnion) RepresentationBehavior() ipld.Kind

func (*TypeUnion) RepresentationStrategy

func (t *TypeUnion) RepresentationStrategy() UnionRepresentation

func (TypeUnion) TypeKind added in v0.7.0

func (TypeUnion) TypeKind() TypeKind

func (*TypeUnion) TypeSystem

func (t *TypeUnion) TypeSystem() *TypeSystem

type UnionRepresentation

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

type UnionRepresentation_BytePrefix

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

type UnionRepresentation_Envelope

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

type UnionRepresentation_Inline

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

type UnionRepresentation_Keyed

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

func (UnionRepresentation_Keyed) GetDiscriminantForType

func (r UnionRepresentation_Keyed) GetDiscriminantForType(t Type) string

GetDiscriminantForType looks up the descriminant key for the given type. It panics if the given type is not a member of this union.

type UnionRepresentation_Kinded

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

func (UnionRepresentation_Kinded) GetMember

func (r UnionRepresentation_Kinded) GetMember(k ipld.Kind) Type

GetMember returns type info for the member matching the kind argument, or may return nil if that kind is not mapped to a member of this union.

type UnionRepresentation_StringPrefix

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

Jump to

Keyboard shortcuts

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