Documentation ¶
Overview ¶
Package schema/dmt contains types and functions for dealing with the data model form of IPLD Schemas.
(DMT is short for "data model tree" -- see https://ipld.io/glossary/#dmt .)
As with anything that's IPLD data model, this data can be serialized or deserialized into a wide variety of codecs.
To contrast this package with some of its neighbors and with some various formats for the data this package describes: Schemas also have a DSL (a domain-specific language -- something that's meant to look nice, and be easy for humans to read and write), which are parsed by the `schema/dsl` package, and produce a DMT form (defined by and handled by this package). Schemas also have a compiled form, which is the in-memory structure that this library uses when working with them; this compiled form differs from the DMT because it can use pointers (and that includes cyclic pointers, which is something the DMT form cannot contain). We use the DMT form (this package) to produce the compiled form (which is the `schema` package).
Creating a Compiled schema either flows from DSL(text)->`schema/dsl`->`schema/dmt`->`schema`, or just (some codec, e.g. JSON or CBOR or etc)->`schema/dmt`->`schema`.
The `dmt.Schema` type describes the data found at the root of an IPLD Schema document. The `Compile` function turns such data into a `schema.TypeSystem` that is ready to be used. The `dmt.Prototype.Schema` value is a NodePrototype that can be used to handle IPLD Schemas in DMT form as regular IPLD Nodes.
Typically this package is imported aliased as "schemadmt", since "dmt" is a fairly generic term in the IPLD ecosystem (see https://ipld.io/glossary/#dmt ).
Many types in this package lack documentation directly on the type; generally, these are structs that match the IPLD schema-schema, and so you can find descriptions of them in documentation for the schema-schema.
Index ¶
- Variables
- func Compile(ts *schema.TypeSystem, node *Schema) error
- type AnyScalar
- type EnumRepresentation
- type EnumRepresentation_Int
- type EnumRepresentation_String
- type InlineDefn
- type ListRepresentation
- type ListRepresentation_List
- type List__EnumMember
- type List__FieldName
- type List__TypeName
- type List__UnionMember
- type MapRepresentation
- type MapRepresentation_Listpairs
- type MapRepresentation_Map
- type MapRepresentation_Stringpairs
- type Map__FieldName__StructField
- type Map__FieldName__StructRepresentation_Map_FieldDetails
- type Map__HexString__TypeName
- type Map__String__TypeName
- type Map__String__UnionMember
- type Map__TypeName__Int
- type Map__TypeName__TypeDefn
- type Schema
- type StructField
- type StructRepresentation
- type StructRepresentation_Listpairs
- type StructRepresentation_Map
- type StructRepresentation_Map_FieldDetails
- type StructRepresentation_Stringjoin
- type StructRepresentation_Stringpairs
- type StructRepresentation_Tuple
- type TypeDefn
- type TypeDefnAny
- type TypeDefnBool
- type TypeDefnBytes
- type TypeDefnCopy
- type TypeDefnEnum
- type TypeDefnFloat
- type TypeDefnInt
- type TypeDefnLink
- type TypeDefnList
- type TypeDefnMap
- type TypeDefnString
- type TypeDefnStruct
- type TypeDefnUnion
- type TypeDefnUnit
- type TypeNameOrInlineDefn
- type UnionMember
- type UnionMemberInlineDefn
- type UnionRepresentation
- type UnionRepresentation_BytesPrefix
- type UnionRepresentation_Envelope
- type UnionRepresentation_Inline
- type UnionRepresentation_Keyed
- type UnionRepresentation_Kinded
- type UnionRepresentation_StringPrefix
- type Unit
Constants ¶
This section is empty.
Variables ¶
var Prototypes struct { Schema schema.TypedPrototype }
Prototypes contains some schema.TypedPrototype values which match the IPLD schema-schema -- that is, the schema that describes IPLD schemas. These prototypes create an in-memory representation that is backed by structs in this package and bindnode.
var TypeSystem schema.TypeSystem
TypeSystem is a compiled equivalent of the IPLD schema-schema -- that is, the schema that describes IPLD schemas.
The IPLD schema-schema can be found at https://ipld.io/specs/schemas/schema-schema.ipldsch .
Functions ¶
func Compile ¶ added in v0.12.2
func Compile(ts *schema.TypeSystem, node *Schema) error
Compile transforms a description of a schema in raw data model ("dmt") form into a compiled schema.TypeSystem, which is the ready-to-use form.
The first parameter is mutated by this process, and the second parameter is the data source.
The compilation process includes first inserting the "prelude" types into the schema.TypeSystem -- that is, the "type Bool bool" and "type String string", etc, which are generally presumed to be present in any type system.
The compilation process attempts to check the validity of the schema at a logical level as it goes. For example, references to type names not present elsewhere in the same schema are now an error (even though that has been easily representable in the dmt.Schema form up until this point).
Note that this API is EXPERIMENTAL and will likely change. It supports many features of IPLD Schemas, but it may yet not support all of them. It supports several validations for logical coherency of schemas, but may not yet successfully reject all invalid schemas.
Types ¶
type EnumRepresentation ¶
type EnumRepresentation struct { EnumRepresentation_String *EnumRepresentation_String EnumRepresentation_Int *EnumRepresentation_Int }
type EnumRepresentation_Int ¶
type InlineDefn ¶ added in v0.12.2
type InlineDefn struct { TypeDefnMap *TypeDefnMap TypeDefnList *TypeDefnList TypeDefnLink *TypeDefnLink }
type ListRepresentation ¶
type ListRepresentation struct {
ListRepresentation_List *ListRepresentation_List
}
type ListRepresentation_List ¶
type ListRepresentation_List struct { }
type List__EnumMember ¶ added in v0.12.3
type List__EnumMember []string
type List__FieldName ¶
type List__FieldName []string
type List__TypeName ¶
type List__TypeName []string
type List__UnionMember ¶ added in v0.12.3
type List__UnionMember []UnionMember
type MapRepresentation ¶
type MapRepresentation struct { MapRepresentation_Map *MapRepresentation_Map MapRepresentation_Stringpairs *MapRepresentation_Stringpairs MapRepresentation_Listpairs *MapRepresentation_Listpairs }
type MapRepresentation_Listpairs ¶
type MapRepresentation_Listpairs struct { }
type MapRepresentation_Map ¶
type MapRepresentation_Map struct { }
type Map__FieldName__StructField ¶
type Map__FieldName__StructField struct { Keys []string Values map[string]StructField }
type Map__FieldName__StructRepresentation_Map_FieldDetails ¶
type Map__FieldName__StructRepresentation_Map_FieldDetails struct { Keys []string Values map[string]StructRepresentation_Map_FieldDetails }
type Map__HexString__TypeName ¶ added in v0.12.3
type Map__String__TypeName ¶
type Map__String__UnionMember ¶ added in v0.12.3
type Map__TypeName__Int ¶
type Map__TypeName__TypeDefn ¶ added in v0.12.3
type Schema ¶
type Schema struct {
Types Map__TypeName__TypeDefn
}
func ConcatenateSchemas ¶ added in v0.20.0
ConcatenateSchemas returns a new schema DMT object containing the type declarations from both.
As is usual for DMT form data, there is no check about the validity of the result yet; you'll need to apply `Compile` on the produced value to produce a usable compiled typesystem or to become certain that all references in the DMT are satisfied, etc.
type StructField ¶
type StructField struct { Type TypeNameOrInlineDefn Optional *bool Nullable *bool }
type StructRepresentation ¶
type StructRepresentation struct { StructRepresentation_Map *StructRepresentation_Map StructRepresentation_Tuple *StructRepresentation_Tuple StructRepresentation_Stringpairs *StructRepresentation_Stringpairs StructRepresentation_Stringjoin *StructRepresentation_Stringjoin StructRepresentation_Listpairs *StructRepresentation_Listpairs }
type StructRepresentation_Listpairs ¶
type StructRepresentation_Listpairs struct { }
type StructRepresentation_Map ¶
type StructRepresentation_Map struct {
Fields *Map__FieldName__StructRepresentation_Map_FieldDetails
}
type StructRepresentation_Stringjoin ¶
type StructRepresentation_Stringjoin struct { Join string FieldOrder *List__FieldName }
type StructRepresentation_Tuple ¶
type StructRepresentation_Tuple struct {
FieldOrder *List__FieldName
}
type TypeDefn ¶
type TypeDefn struct { TypeDefnBool *TypeDefnBool TypeDefnString *TypeDefnString TypeDefnBytes *TypeDefnBytes TypeDefnInt *TypeDefnInt TypeDefnFloat *TypeDefnFloat TypeDefnMap *TypeDefnMap TypeDefnList *TypeDefnList TypeDefnLink *TypeDefnLink TypeDefnUnion *TypeDefnUnion TypeDefnStruct *TypeDefnStruct TypeDefnEnum *TypeDefnEnum TypeDefnUnit *TypeDefnUnit TypeDefnAny *TypeDefnAny TypeDefnCopy *TypeDefnCopy }
type TypeDefnAny ¶ added in v0.12.3
type TypeDefnAny struct { }
type TypeDefnBool ¶ added in v0.12.3
type TypeDefnBool struct { }
type TypeDefnBytes ¶ added in v0.12.3
type TypeDefnBytes struct { }
type TypeDefnCopy ¶ added in v0.12.3
type TypeDefnCopy struct {
FromType string
}
type TypeDefnEnum ¶ added in v0.12.3
type TypeDefnEnum struct { Members List__EnumMember Representation EnumRepresentation }
type TypeDefnFloat ¶ added in v0.12.3
type TypeDefnFloat struct { }
type TypeDefnInt ¶ added in v0.12.3
type TypeDefnInt struct { }
type TypeDefnLink ¶ added in v0.12.3
type TypeDefnLink struct {
ExpectedType *string
}
type TypeDefnList ¶ added in v0.12.3
type TypeDefnList struct { ValueType TypeNameOrInlineDefn ValueNullable *bool Representation *ListRepresentation }
type TypeDefnMap ¶ added in v0.12.3
type TypeDefnMap struct { KeyType string ValueType TypeNameOrInlineDefn ValueNullable *bool Representation *MapRepresentation }
type TypeDefnString ¶ added in v0.12.3
type TypeDefnString struct { }
type TypeDefnStruct ¶ added in v0.12.3
type TypeDefnStruct struct { Fields Map__FieldName__StructField Representation StructRepresentation }
type TypeDefnUnion ¶ added in v0.12.3
type TypeDefnUnion struct { Members List__UnionMember Representation UnionRepresentation }
type TypeDefnUnit ¶ added in v0.12.3
type TypeDefnUnit struct {
Representation string
}
type TypeNameOrInlineDefn ¶
type TypeNameOrInlineDefn struct { TypeName *string InlineDefn *InlineDefn }
type UnionMember ¶ added in v0.12.3
type UnionMember struct { TypeName *string UnionMemberInlineDefn *UnionMemberInlineDefn }
type UnionMemberInlineDefn ¶ added in v0.12.3
type UnionMemberInlineDefn struct {
TypeDefnLink *TypeDefnLink
}
type UnionRepresentation ¶
type UnionRepresentation struct { UnionRepresentation_Kinded *UnionRepresentation_Kinded UnionRepresentation_Keyed *UnionRepresentation_Keyed UnionRepresentation_Envelope *UnionRepresentation_Envelope UnionRepresentation_Inline *UnionRepresentation_Inline UnionRepresentation_StringPrefix *UnionRepresentation_StringPrefix UnionRepresentation_BytesPrefix *UnionRepresentation_BytesPrefix }
type UnionRepresentation_BytesPrefix ¶ added in v0.12.3
type UnionRepresentation_BytesPrefix struct {
Prefixes Map__HexString__TypeName
}
type UnionRepresentation_Envelope ¶
type UnionRepresentation_Envelope struct { DiscriminantKey string ContentKey string DiscriminantTable Map__String__UnionMember }
type UnionRepresentation_Inline ¶
type UnionRepresentation_Inline struct { DiscriminantKey string DiscriminantTable Map__String__TypeName }
type UnionRepresentation_Keyed ¶
type UnionRepresentation_Keyed struct { Keys []string Values map[string]UnionMember }
type UnionRepresentation_Kinded ¶
type UnionRepresentation_Kinded struct { Keys []string Values map[string]UnionMember }
type UnionRepresentation_StringPrefix ¶
type UnionRepresentation_StringPrefix struct {
Prefixes Map__String__TypeName
}