Documentation ¶
Index ¶
- type EnumRepresentation
- type EnumRepresentation_Int
- type EnumRepresentation_String
- type StructField
- type StructRepresentation
- type StructRepresentation_Listpairs
- 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 TypeKind
- type TypeLink
- type TypeList
- type TypeMap
- type TypeName
- type TypeReference
- type TypeString
- type TypeStruct
- func (t *TypeStruct) Field(name string) *StructField
- func (t *TypeStruct) Fields() []StructField
- func (t *TypeStruct) Name() TypeName
- func (t TypeStruct) RepresentationBehavior() ld.Kind
- func (t *TypeStruct) RepresentationStrategy() StructRepresentation
- func (TypeStruct) TypeKind() TypeKind
- func (t *TypeStruct) TypeSystem() *TypeSystem
- type TypeSystem
- type TypeUnion
- type UnionRepresentation
- type UnionRepresentation_BytePrefix
- type UnionRepresentation_Envelope
- type UnionRepresentation_Inline
- type UnionRepresentation_Keyed
- type UnionRepresentation_Kinded
- type UnionRepresentation_StringPrefix
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 ld.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 LD 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() ld.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) RepresentationBehavior ¶
func (t TypeBool) RepresentationBehavior() ld.Kind
func (*TypeBool) TypeSystem ¶
func (t *TypeBool) TypeSystem() *TypeSystem
type TypeBytes ¶
type TypeBytes struct {
// contains filtered or unexported fields
}
func (TypeBytes) RepresentationBehavior ¶
func (*TypeBytes) TypeSystem ¶
func (t *TypeBytes) TypeSystem() *TypeSystem
type TypeEnum ¶
type TypeEnum struct {
// contains filtered or unexported fields
}
func (TypeEnum) RepresentationBehavior ¶
func (t TypeEnum) RepresentationBehavior() ld.Kind
func (*TypeEnum) RepresentationStrategy ¶
func (t *TypeEnum) RepresentationStrategy() EnumRepresentation
func (*TypeEnum) TypeSystem ¶
func (t *TypeEnum) TypeSystem() *TypeSystem
type TypeFloat ¶
type TypeFloat struct {
// contains filtered or unexported fields
}
func (TypeFloat) RepresentationBehavior ¶
func (t TypeFloat) RepresentationBehavior() ld.Kind
func (*TypeFloat) TypeSystem ¶
func (t *TypeFloat) TypeSystem() *TypeSystem
type TypeInt ¶
type TypeInt struct {
// contains filtered or unexported fields
}
func (TypeInt) RepresentationBehavior ¶
func (t TypeInt) RepresentationBehavior() ld.Kind
func (*TypeInt) TypeSystem ¶
func (t *TypeInt) TypeSystem() *TypeSystem
type TypeKind ¶
type TypeKind uint8
TypeKind is an enum of kind in the LD Schema system.
Note that schema.TypeKind is distinct from ld.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 ¶
ActsLike returns a constant from the ld.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).
type TypeLink ¶
type TypeLink struct {
// contains filtered or unexported fields
}
func (*TypeLink) HasReferencedType ¶
HasReferencedType returns true if the link has a hint about the type it references.
func (*TypeLink) ReferencedType ¶
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 (*TypeLink) TypeSystem ¶
func (t *TypeLink) TypeSystem() *TypeSystem
type TypeList ¶
type TypeList struct {
// contains filtered or unexported fields
}
func (TypeList) RepresentationBehavior ¶
func (*TypeList) TypeSystem ¶
func (t *TypeList) TypeSystem() *TypeSystem
func (*TypeList) ValueIsNullable ¶
ValueIsNullable returns a bool describing if the map values are permitted to be null.
type TypeMap ¶
type TypeMap struct {
// contains filtered or unexported fields
}
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 LD Data Model (e.g. either TypeString or TypeEnum).
func (TypeMap) RepresentationBehavior ¶
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 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() ld.Kind
func (TypeString) TypeKind ¶
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() ld.Kind
func (*TypeStruct) RepresentationStrategy ¶
func (t *TypeStruct) RepresentationStrategy() StructRepresentation
func (TypeStruct) TypeKind ¶
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) RepresentationBehavior ¶
func (*TypeUnion) RepresentationStrategy ¶
func (t *TypeUnion) RepresentationStrategy() UnionRepresentation
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
}
type UnionRepresentation_StringPrefix ¶
type UnionRepresentation_StringPrefix struct {
// contains filtered or unexported fields
}