Skip to content

Commit 2ecabf1

Browse files
committed
Add several pieces of docs to schema/dmt.
Package docs are important to have as overviews, and we were previously missing any. Added a few notes to any future hackers, as well. Removed the "export" file that was only used by the generator gadget. I don't believe it worked anyway. It wasn't exercised in CI because of the build tags. And since it was first written, we've relaxed on what we allow to be exported anyway, and the field that file contained a build-tag-fenced accessor for is simply available anyway. So, I updated the codegen gadget to just use that directly. No sweat.
1 parent eda53db commit 2ecabf1

File tree

5 files changed

+56
-14
lines changed

5 files changed

+56
-14
lines changed

schema/dmt/compile.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,25 @@ import (
77
"github.com/ipld/go-ipld-prime/schema"
88
)
99

10-
// Compile transforms a schema in DMT form into a TypeSystem.
10+
// Compile transforms a description of a schema in raw data model ("dmt") form
11+
// into a compiled schema.TypeSystem, which is the ready-to-use form.
12+
//
13+
// The first parameter is mutated by this process,
14+
// and the second parameter is the data source.
15+
//
16+
// The compilation process includes first inserting the "prelude" types into the
17+
// schema.TypeSystem -- that is, the "type Bool bool" and "type String string", etc,
18+
// which are generally presumed to be present in any type system.
19+
//
20+
// The compilation process attempts to check the validity of the schema at a logical level as it goes.
21+
// For example, references to type names not present elsewhere in the same schema are now an error
22+
// (even though that has been easily representable in the dmt.Schema form up until this point).
1123
//
1224
// Note that this API is EXPERIMENTAL and will likely change.
13-
// It is also unfinished and buggy.
25+
// It supports many features of IPLD Schemas,
26+
// but it may yet not support all of them.
27+
// It supports several validations for logical coherency of schemas,
28+
// but may not yet successfully reject all invalid schemas.
1429
func Compile(ts *schema.TypeSystem, node *Schema) error {
1530
// Prelude; probably belongs elsewhere.
1631
{

schema/dmt/doc.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Package schema/dmt contains types and functions for dealing with the data model form of IPLD Schemas.
3+
4+
(DMT is short for "data model tree" -- see https://ipld.io/glossary/#dmt .)
5+
6+
As with anything that's IPLD data model, this data can be serialized or deserialized into a wide variety of codecs.
7+
8+
To contrast this package with some of its neighbors and with some various formats for the data this package describes:
9+
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),
10+
which are parsed by the `schema/dsl` package, and produce a DMT form (defined by and handled by this package).
11+
Schemas also have a compiled form, which is the in-memory structure that this library uses when working with them;
12+
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).
13+
We use the DMT form (this package) to produce the compiled form (which is the `schema` package).
14+
15+
Creating a Compiled schema either flows from DSL(text)->`schema/dsl`->`schema/dmt`->`schema`,
16+
or just (some codec, e.g. JSON or CBOR or etc)->`schema/dmt`->`schema`.
17+
18+
The `dmt.Schema` type describes the data found at the root of an IPLD Schema document.
19+
The `Compile` function turns such data into a `schema.TypeSystem` that is ready to be used.
20+
The `dmt.Prototype.Schema` value is a NodePrototype that can be used to handle IPLD Schemas in DMT form as regular IPLD Nodes.
21+
22+
Typically this package is imported aliased as "schemadmt",
23+
since "dmt" is a fairly generic term in the IPLD ecosystem
24+
(see https://ipld.io/glossary/#dmt ).
25+
*/
26+
package dmt

schema/dmt/export.go

-9
This file was deleted.

schema/dmt/gen.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func main() {
1616
panic(err)
1717
}
1818
fmt.Fprintf(f, "package schemadmt\n\n")
19-
if err := bindnode.ProduceGoTypes(f, schemadmt.InternalTypeSystem()); err != nil {
19+
if err := bindnode.ProduceGoTypes(f, schemadmt.TypeSystem); err != nil {
2020
panic(err)
2121
}
2222
if err := f.Close(); err != nil {

schema/dmt/schema.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@ import (
88
"github.com/ipld/go-ipld-prime/schema"
99
)
1010

11-
// This schema follows https://ipld.io/specs/schemas/schema-schema.ipldsch.
12-
11+
// Prototypes contains some schema.TypedPrototype values which match
12+
// the IPLD schema-schema -- that is, the schema that describes IPLD schemas.
13+
// These prototypes create an in-memory representation that is backed by
14+
// structs in this package and bindnode.
1315
var Prototypes struct {
1416
Schema schema.TypedPrototype
1517
}
1618

1719
//go:generate go run -tags=schemadmtgen gen.go
1820

21+
// TypeSystem is a compiled equivalent of the IPLD schema-schema -- that is, the schema that describes IPLD schemas.
22+
//
23+
// The IPLD schema-schema can be found at https://ipld.io/specs/schemas/schema-schema.ipldsch .
1924
var TypeSystem schema.TypeSystem
2025

26+
// In this init function, we manually create a type system that *matches* the IPLD schema-schema.
27+
// This manual work is unfortunate, and also must be kept in-sync manually,
28+
// but is important because breaks a cyclic dependency --
29+
// we use the compiled schema-schema produced by this to parse other schema documents.
30+
// We would also use it to parse... the IPLD schema-schema... if that weren't a cyclic dependency.
2131
func init() {
2232
var ts schema.TypeSystem
2333
ts.Init()

0 commit comments

Comments
 (0)