Integrate BACKBEAT SDK and resolve KACHING license validation

Major integrations and fixes:
- Added BACKBEAT SDK integration for P2P operation timing
- Implemented beat-aware status tracking for distributed operations
- Added Docker secrets support for secure license management
- Resolved KACHING license validation via HTTPS/TLS
- Updated docker-compose configuration for clean stack deployment
- Disabled rollback policies to prevent deployment failures
- Added license credential storage (CHORUS-DEV-MULTI-001)

Technical improvements:
- BACKBEAT P2P operation tracking with phase management
- Enhanced configuration system with file-based secrets
- Improved error handling for license validation
- Clean separation of KACHING and CHORUS deployment stacks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
anthonyrawlins
2025-09-06 07:56:26 +10:00
parent 543ab216f9
commit 9bdcbe0447
4730 changed files with 1480093 additions and 1916 deletions

View File

@@ -0,0 +1,427 @@
package schemadmt
import (
"fmt"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/schema"
)
// 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.
func Compile(ts *schema.TypeSystem, node *Schema) error {
// Prelude; probably belongs elsewhere.
{
ts.Accumulate(schema.SpawnBool("Bool"))
ts.Accumulate(schema.SpawnInt("Int"))
ts.Accumulate(schema.SpawnFloat("Float"))
ts.Accumulate(schema.SpawnString("String"))
ts.Accumulate(schema.SpawnBytes("Bytes"))
ts.Accumulate(schema.SpawnAny("Any"))
ts.Accumulate(schema.SpawnMap("Map", "String", "Any", false))
ts.Accumulate(schema.SpawnList("List", "Any", false))
// Should be &Any, really.
ts.Accumulate(schema.SpawnLink("Link"))
// TODO: schema package lacks support?
// ts.Accumulate(schema.SpawnUnit("Null", NullRepr))
}
for _, name := range node.Types.Keys {
defn := node.Types.Values[name]
// TODO: once ./schema supports anonymous/inline types, remove the ts argument.
typ, err := spawnType(ts, name, defn)
if err != nil {
return err
}
ts.Accumulate(typ)
}
// TODO: if this fails and the user forgot to check Compile's returned error,
// we can leave the TypeSystem in an unfortunate broken state:
// they can obtain types out of the TypeSystem and they are non-nil,
// but trying to use them in any way may result in panics.
// Consider making that less prone to misuse, such as making it illegal to
// call TypeByName until ValidateGraph is happy.
if errs := ts.ValidateGraph(); errs != nil {
// Return the first error.
for _, err := range errs {
return err
}
}
return nil
}
// Note that the parser and compiler support defaults. We're lacking support in bindnode.
func todoFromImplicitlyFalseBool(b *bool) bool {
if b == nil {
return false
}
return *b
}
func anonTypeName(nameOrDefn TypeNameOrInlineDefn) string {
if nameOrDefn.TypeName != nil {
return *nameOrDefn.TypeName
}
defn := *nameOrDefn.InlineDefn
switch {
case defn.TypeDefnMap != nil:
defn := defn.TypeDefnMap
return fmt.Sprintf("Map__%s__%s", defn.KeyType, anonTypeName(defn.ValueType))
case defn.TypeDefnList != nil:
defn := defn.TypeDefnList
return fmt.Sprintf("List__%s", anonTypeName(defn.ValueType))
case defn.TypeDefnLink != nil:
return anonLinkName(*defn.TypeDefnLink)
default:
panic(fmt.Errorf("%#v", defn))
}
}
func anonLinkName(defn TypeDefnLink) string {
if defn.ExpectedType != nil {
return fmt.Sprintf("Link__%s", *defn.ExpectedType)
}
return "Link__Link"
}
func parseKind(s string) datamodel.Kind {
switch s {
case "map":
return datamodel.Kind_Map
case "list":
return datamodel.Kind_List
case "null":
return datamodel.Kind_Null
case "bool":
return datamodel.Kind_Bool
case "int":
return datamodel.Kind_Int
case "float":
return datamodel.Kind_Float
case "string":
return datamodel.Kind_String
case "bytes":
return datamodel.Kind_Bytes
case "link":
return datamodel.Kind_Link
default:
return datamodel.Kind_Invalid
}
}
func spawnType(ts *schema.TypeSystem, name schema.TypeName, defn TypeDefn) (schema.Type, error) {
switch {
// Scalar types without parameters.
case defn.TypeDefnBool != nil:
return schema.SpawnBool(name), nil
case defn.TypeDefnString != nil:
return schema.SpawnString(name), nil
case defn.TypeDefnBytes != nil:
return schema.SpawnBytes(name), nil
case defn.TypeDefnInt != nil:
return schema.SpawnInt(name), nil
case defn.TypeDefnFloat != nil:
return schema.SpawnFloat(name), nil
case defn.TypeDefnList != nil:
typ := defn.TypeDefnList
tname := ""
if typ.ValueType.TypeName != nil {
tname = *typ.ValueType.TypeName
} else if tname = anonTypeName(typ.ValueType); ts.TypeByName(tname) == nil {
anonDefn := TypeDefn{
TypeDefnMap: typ.ValueType.InlineDefn.TypeDefnMap,
TypeDefnList: typ.ValueType.InlineDefn.TypeDefnList,
TypeDefnLink: typ.ValueType.InlineDefn.TypeDefnLink,
}
anonType, err := spawnType(ts, tname, anonDefn)
if err != nil {
return nil, err
}
ts.Accumulate(anonType)
}
switch {
case typ.Representation == nil ||
typ.Representation.ListRepresentation_List != nil:
// default behavior
default:
return nil, fmt.Errorf("TODO: support other list repr in schema package")
}
return schema.SpawnList(name,
tname,
todoFromImplicitlyFalseBool(typ.ValueNullable),
), nil
case defn.TypeDefnMap != nil:
typ := defn.TypeDefnMap
tname := ""
if typ.ValueType.TypeName != nil {
tname = *typ.ValueType.TypeName
} else if tname = anonTypeName(typ.ValueType); ts.TypeByName(tname) == nil {
anonDefn := TypeDefn{
TypeDefnMap: typ.ValueType.InlineDefn.TypeDefnMap,
TypeDefnList: typ.ValueType.InlineDefn.TypeDefnList,
TypeDefnLink: typ.ValueType.InlineDefn.TypeDefnLink,
}
anonType, err := spawnType(ts, tname, anonDefn)
if err != nil {
return nil, err
}
ts.Accumulate(anonType)
}
switch {
case typ.Representation == nil ||
typ.Representation.MapRepresentation_Map != nil:
// default behavior
case typ.Representation.MapRepresentation_Stringpairs != nil:
return nil, fmt.Errorf("TODO: support stringpairs map repr in schema package")
default:
return nil, fmt.Errorf("TODO: support other map repr in schema package")
}
return schema.SpawnMap(name,
typ.KeyType,
tname,
todoFromImplicitlyFalseBool(typ.ValueNullable),
), nil
case defn.TypeDefnStruct != nil:
typ := defn.TypeDefnStruct
var fields []schema.StructField
for _, fname := range typ.Fields.Keys {
field := typ.Fields.Values[fname]
tname := ""
if field.Type.TypeName != nil {
tname = *field.Type.TypeName
} else if tname = anonTypeName(field.Type); ts.TypeByName(tname) == nil {
// Note that TypeDefn and InlineDefn aren't the same enum.
anonDefn := TypeDefn{
TypeDefnMap: field.Type.InlineDefn.TypeDefnMap,
TypeDefnList: field.Type.InlineDefn.TypeDefnList,
TypeDefnLink: field.Type.InlineDefn.TypeDefnLink,
}
anonType, err := spawnType(ts, tname, anonDefn)
if err != nil {
return nil, err
}
ts.Accumulate(anonType)
}
fields = append(fields, schema.SpawnStructField(fname,
tname,
todoFromImplicitlyFalseBool(field.Optional),
todoFromImplicitlyFalseBool(field.Nullable),
))
}
var repr schema.StructRepresentation
switch {
case typ.Representation.StructRepresentation_Map != nil:
rp := typ.Representation.StructRepresentation_Map
if rp.Fields == nil {
repr = schema.SpawnStructRepresentationMap2(nil, nil)
break
}
renames := make(map[string]string, len(rp.Fields.Keys))
implicits := make(map[string]schema.ImplicitValue, len(rp.Fields.Keys))
for _, name := range rp.Fields.Keys {
details := rp.Fields.Values[name]
if details.Rename != nil {
renames[name] = *details.Rename
}
if imp := details.Implicit; imp != nil {
var sumVal schema.ImplicitValue
switch {
case imp.Bool != nil:
sumVal = schema.ImplicitValue_Bool(*imp.Bool)
case imp.String != nil:
sumVal = schema.ImplicitValue_String(*imp.String)
case imp.Int != nil:
sumVal = schema.ImplicitValue_Int(*imp.Int)
default:
panic("TODO: implicit value kind")
}
implicits[name] = sumVal
}
}
repr = schema.SpawnStructRepresentationMap2(renames, implicits)
case typ.Representation.StructRepresentation_Tuple != nil:
rp := typ.Representation.StructRepresentation_Tuple
if rp.FieldOrder == nil {
repr = schema.SpawnStructRepresentationTuple()
break
}
return nil, fmt.Errorf("TODO: support for tuples with field orders in the schema package")
case typ.Representation.StructRepresentation_Stringjoin != nil:
join := typ.Representation.StructRepresentation_Stringjoin.Join
if join == "" {
return nil, fmt.Errorf("stringjoin has empty join value")
}
repr = schema.SpawnStructRepresentationStringjoin(join)
default:
return nil, fmt.Errorf("TODO: support other struct repr in schema package")
}
return schema.SpawnStruct(name,
fields,
repr,
), nil
case defn.TypeDefnUnion != nil:
typ := defn.TypeDefnUnion
var members []schema.TypeName
for _, member := range typ.Members {
if member.TypeName != nil {
members = append(members, *member.TypeName)
} else {
tname := anonLinkName(*member.UnionMemberInlineDefn.TypeDefnLink)
members = append(members, tname)
if ts.TypeByName(tname) == nil {
anonDefn := TypeDefn{
TypeDefnLink: member.UnionMemberInlineDefn.TypeDefnLink,
}
anonType, err := spawnType(ts, tname, anonDefn)
if err != nil {
return nil, err
}
ts.Accumulate(anonType)
}
}
}
remainingMembers := make(map[string]bool)
for _, memberName := range members {
remainingMembers[memberName] = true
}
validMember := func(memberName string) error {
switch remaining, known := remainingMembers[memberName]; {
case remaining:
remainingMembers[memberName] = false
return nil
case !known:
return fmt.Errorf("%q is not a valid member of union %q", memberName, name)
default:
return fmt.Errorf("%q is duplicate in the union repr of %q", memberName, name)
}
}
var repr schema.UnionRepresentation
switch {
case typ.Representation.UnionRepresentation_Kinded != nil:
rp := typ.Representation.UnionRepresentation_Kinded
table := make(map[datamodel.Kind]schema.TypeName, len(rp.Keys))
for _, kindStr := range rp.Keys {
kind := parseKind(kindStr)
member := rp.Values[kindStr]
switch {
case member.TypeName != nil:
memberName := *member.TypeName
validMember(memberName)
table[kind] = memberName
case member.UnionMemberInlineDefn != nil:
tname := anonLinkName(*member.UnionMemberInlineDefn.TypeDefnLink)
validMember(tname)
table[kind] = tname
}
}
repr = schema.SpawnUnionRepresentationKinded(table)
case typ.Representation.UnionRepresentation_Keyed != nil:
rp := typ.Representation.UnionRepresentation_Keyed
table := make(map[string]schema.TypeName, len(rp.Keys))
for _, key := range rp.Keys {
member := rp.Values[key]
switch {
case member.TypeName != nil:
memberName := *member.TypeName
validMember(memberName)
table[key] = memberName
case member.UnionMemberInlineDefn != nil:
tname := anonLinkName(*member.UnionMemberInlineDefn.TypeDefnLink)
validMember(tname)
table[key] = tname
}
}
repr = schema.SpawnUnionRepresentationKeyed(table)
case typ.Representation.UnionRepresentation_StringPrefix != nil:
prefixes := typ.Representation.UnionRepresentation_StringPrefix.Prefixes
for _, key := range prefixes.Keys {
validMember(prefixes.Values[key])
}
repr = schema.SpawnUnionRepresentationStringprefix("", prefixes.Values)
default:
return nil, fmt.Errorf("TODO: support other union repr in schema package")
}
for memberName, remaining := range remainingMembers {
if remaining {
return nil, fmt.Errorf("%q is not present in the union repr of %q", memberName, name)
}
}
return schema.SpawnUnion(name,
members,
repr,
), nil
case defn.TypeDefnEnum != nil:
typ := defn.TypeDefnEnum
var repr schema.EnumRepresentation
// TODO: we should probably also reject duplicates.
validMember := func(name string) bool {
for _, memberName := range typ.Members {
if memberName == name {
return true
}
}
return false
}
switch {
case typ.Representation.EnumRepresentation_String != nil:
rp := typ.Representation.EnumRepresentation_String
for memberName := range rp.Values {
if !validMember(memberName) {
return nil, fmt.Errorf("%q is not a valid member of enum %q", memberName, name)
}
}
repr = schema.EnumRepresentation_String(rp.Values)
case typ.Representation.EnumRepresentation_Int != nil:
rp := typ.Representation.EnumRepresentation_Int
for memberName := range rp.Values {
if !validMember(memberName) {
return nil, fmt.Errorf("%q is not a valid member of enum %q", memberName, name)
}
}
repr = schema.EnumRepresentation_Int(rp.Values)
default:
return nil, fmt.Errorf("TODO: support other enum repr in schema package")
}
return schema.SpawnEnum(name,
typ.Members,
repr,
), nil
case defn.TypeDefnLink != nil:
typ := defn.TypeDefnLink
if typ.ExpectedType == nil {
return schema.SpawnLink(name), nil
}
return schema.SpawnLinkReference(name, *typ.ExpectedType), nil
case defn.TypeDefnAny != nil:
return schema.SpawnAny(name), nil
default:
panic(fmt.Errorf("%#v", defn))
}
}

30
vendor/github.com/ipld/go-ipld-prime/schema/dmt/doc.go generated vendored Normal file
View File

@@ -0,0 +1,30 @@
/*
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.
*/
package schemadmt

View File

@@ -0,0 +1,27 @@
package schemadmt
import (
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/node/bindnode"
)
// 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.
func ConcatenateSchemas(a, b *Schema) *Schema {
// The joy of having an intermediate form that's just regular data model:
// we can implement this by simply using data model "copy" operations,
// and the result is correct.
nb := Prototypes.Schema.NewBuilder()
if err := datamodel.Copy(bindnode.Wrap(a, Prototypes.Schema.Type()), nb); err != nil {
panic(err)
}
if err := datamodel.Copy(bindnode.Wrap(b, Prototypes.Schema.Type()), nb); err != nil {
panic(err)
}
return bindnode.Unwrap(nb.Build()).(*Schema)
}

View File

@@ -0,0 +1,452 @@
package schemadmt
import (
"fmt"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/node/bindnode"
"github.com/ipld/go-ipld-prime/schema"
)
// 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 Prototypes struct {
Schema schema.TypedPrototype
}
//go:generate go run -tags=schemadmtgen gen.go
// 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 .
var TypeSystem schema.TypeSystem
// In this init function, we manually create a type system that *matches* the IPLD schema-schema.
// This manual work is unfortunate, and also must be kept in-sync manually,
// but is important because breaks a cyclic dependency --
// we use the compiled schema-schema produced by this to parse other schema documents.
// We would also use it to parse... the IPLD schema-schema... if that weren't a cyclic dependency.
func init() {
var ts schema.TypeSystem
ts.Init()
// I've elided all references to Advancedlayouts stuff for the moment.
// (Not because it's particularly hard or problematic; I just want to draw a slightly smaller circle first.)
// Prelude
ts.Accumulate(schema.SpawnString("String"))
ts.Accumulate(schema.SpawnBool("Bool"))
ts.Accumulate(schema.SpawnInt("Int"))
ts.Accumulate(schema.SpawnFloat("Float"))
ts.Accumulate(schema.SpawnBytes("Bytes"))
// Schema-schema!
// In the same order as the spec's ipldsch file.
// Note that ADL stuff is excluded for now, as per above.
ts.Accumulate(schema.SpawnString("TypeName"))
ts.Accumulate(schema.SpawnStruct("Schema",
[]schema.StructField{
schema.SpawnStructField("types", "Map__TypeName__TypeDefn", false, false),
// also: `advanced AdvancedDataLayoutMap`, but as commented above, we'll pursue this later.
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnMap("Map__TypeName__TypeDefn",
"TypeName", "TypeDefn", false,
))
ts.Accumulate(schema.SpawnUnion("TypeDefn",
[]schema.TypeName{
"TypeDefnBool",
"TypeDefnString",
"TypeDefnBytes",
"TypeDefnInt",
"TypeDefnFloat",
"TypeDefnMap",
"TypeDefnList",
"TypeDefnLink",
"TypeDefnUnion",
"TypeDefnStruct",
"TypeDefnEnum",
"TypeDefnUnit",
"TypeDefnAny",
"TypeDefnCopy",
},
// TODO: spec uses inline repr.
schema.SpawnUnionRepresentationKeyed(map[string]schema.TypeName{
"bool": "TypeDefnBool",
"string": "TypeDefnString",
"bytes": "TypeDefnBytes",
"int": "TypeDefnInt",
"float": "TypeDefnFloat",
"map": "TypeDefnMap",
"list": "TypeDefnList",
"link": "TypeDefnLink",
"union": "TypeDefnUnion",
"struct": "TypeDefnStruct",
"enum": "TypeDefnEnum",
"unit": "TypeDefnUnit",
"any": "TypeDefnAny",
"copy": "TypeDefnCopy",
}),
))
ts.Accumulate(schema.SpawnUnion("TypeNameOrInlineDefn",
[]schema.TypeName{
"TypeName",
"InlineDefn",
},
schema.SpawnUnionRepresentationKinded(map[datamodel.Kind]schema.TypeName{
datamodel.Kind_String: "TypeName",
datamodel.Kind_Map: "InlineDefn",
}),
))
ts.Accumulate(schema.SpawnUnion("InlineDefn",
[]schema.TypeName{
"TypeDefnMap",
"TypeDefnList",
"TypeDefnLink",
},
schema.SpawnUnionRepresentationKeyed(map[string]schema.TypeName{
"map": "TypeDefnMap",
"list": "TypeDefnList",
"link": "TypeDefnLink",
}),
))
ts.Accumulate(schema.SpawnStruct("TypeDefnBool",
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("TypeDefnString",
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("TypeDefnBytes",
[]schema.StructField{},
// No BytesRepresentation, since we omit ADL stuff.
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("TypeDefnInt",
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("TypeDefnFloat",
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("TypeDefnMap",
[]schema.StructField{
schema.SpawnStructField("keyType", "TypeName", false, false),
schema.SpawnStructField("valueType", "TypeNameOrInlineDefn", false, false),
schema.SpawnStructField("valueNullable", "Bool", true, false), // TODO: wants to use the "implicit" feature, but not supported yet
schema.SpawnStructField("representation", "MapRepresentation", true, false), // XXXXXX
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnUnion("MapRepresentation",
[]schema.TypeName{
"MapRepresentation_Map",
"MapRepresentation_Stringpairs",
"MapRepresentation_Listpairs",
},
schema.SpawnUnionRepresentationKeyed(map[string]schema.TypeName{
"map": "MapRepresentation_Map",
"stringpairs": "MapRepresentation_Stringpairs",
"listpairs": "MapRepresentation_Listpairs",
}),
))
ts.Accumulate(schema.SpawnStruct("MapRepresentation_Map",
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("MapRepresentation_Stringpairs",
[]schema.StructField{
schema.SpawnStructField("innerDelim", "String", false, false),
schema.SpawnStructField("entryDelim", "String", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("MapRepresentation_Listpairs",
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("TypeDefnList",
[]schema.StructField{
schema.SpawnStructField("valueType", "TypeNameOrInlineDefn", false, false),
schema.SpawnStructField("valueNullable", "Bool", true, false), // TODO: wants to use the "implicit" feature, but not supported yet
schema.SpawnStructField("representation", "ListRepresentation", true, false), // XXXXXX
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnUnion("ListRepresentation",
[]schema.TypeName{
"ListRepresentation_List",
},
schema.SpawnUnionRepresentationKeyed(map[string]schema.TypeName{
"list": "ListRepresentation_List",
}),
))
ts.Accumulate(schema.SpawnStruct("ListRepresentation_List",
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("TypeDefnUnion",
[]schema.StructField{
// n.b. we could conceivably allow TypeNameOrInlineDefn here rather than just TypeName. but... we'd rather not: imagine what that means about the type-level behavior of the union: the name munge for the anonymous type would suddenly become load-bearing. would rather not.
schema.SpawnStructField("members", "List__UnionMember", false, false),
schema.SpawnStructField("representation", "UnionRepresentation", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnList("List__UnionMember",
"UnionMember", false,
))
ts.Accumulate(schema.SpawnUnion("UnionMember",
[]schema.TypeName{
"TypeName",
"UnionMemberInlineDefn",
},
schema.SpawnUnionRepresentationKinded(map[datamodel.Kind]schema.TypeName{
datamodel.Kind_String: "TypeName",
datamodel.Kind_Map: "UnionMemberInlineDefn",
}),
))
ts.Accumulate(schema.SpawnUnion("UnionMemberInlineDefn",
[]schema.TypeName{
"TypeDefnLink",
},
schema.SpawnUnionRepresentationKeyed(map[string]schema.TypeName{
"link": "TypeDefnLink",
}),
))
ts.Accumulate(schema.SpawnList("List__TypeName", // todo: this is a slight hack: should be an anon inside TypeDefnUnion.members.
"TypeName", false,
))
ts.Accumulate(schema.SpawnStruct("TypeDefnLink",
[]schema.StructField{
schema.SpawnStructField("expectedType", "TypeName", true, false), // todo: this uses an implicit with a value of 'any' in the schema-schema, but that's been questioned before. maybe it should simply be an optional.
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnUnion("UnionRepresentation",
[]schema.TypeName{
"UnionRepresentation_Kinded",
"UnionRepresentation_Keyed",
"UnionRepresentation_Envelope",
"UnionRepresentation_Inline",
"UnionRepresentation_StringPrefix",
"UnionRepresentation_BytesPrefix",
},
schema.SpawnUnionRepresentationKeyed(map[string]schema.TypeName{
"kinded": "UnionRepresentation_Kinded",
"keyed": "UnionRepresentation_Keyed",
"envelope": "UnionRepresentation_Envelope",
"inline": "UnionRepresentation_Inline",
"stringprefix": "UnionRepresentation_StringPrefix",
"byteprefix": "UnionRepresentation_BytesPrefix",
}),
))
ts.Accumulate(schema.SpawnMap("UnionRepresentation_Kinded",
"RepresentationKind", "UnionMember", false,
))
ts.Accumulate(schema.SpawnMap("UnionRepresentation_Keyed",
"String", "UnionMember", false,
))
ts.Accumulate(schema.SpawnMap("Map__String__UnionMember",
"TypeName", "TypeDefn", false,
))
ts.Accumulate(schema.SpawnStruct("UnionRepresentation_Envelope",
[]schema.StructField{
schema.SpawnStructField("discriminantKey", "String", false, false),
schema.SpawnStructField("contentKey", "String", false, false),
schema.SpawnStructField("discriminantTable", "Map__String__UnionMember", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("UnionRepresentation_Inline",
[]schema.StructField{
schema.SpawnStructField("discriminantKey", "String", false, false),
schema.SpawnStructField("discriminantTable", "Map__String__TypeName", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("UnionRepresentation_StringPrefix",
[]schema.StructField{
schema.SpawnStructField("prefixes", "Map__String__TypeName", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("UnionRepresentation_BytesPrefix",
[]schema.StructField{
schema.SpawnStructField("prefixes", "Map__HexString__TypeName", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnMap("Map__HexString__TypeName",
"String", "TypeName", false,
))
ts.Accumulate(schema.SpawnString("HexString"))
ts.Accumulate(schema.SpawnMap("Map__String__TypeName",
"String", "TypeName", false,
))
ts.Accumulate(schema.SpawnMap("Map__TypeName__Int",
"String", "Int", false,
))
ts.Accumulate(schema.SpawnString("RepresentationKind")) // todo: RepresentationKind is supposed to be an enum, but we're puting it to a string atm.
ts.Accumulate(schema.SpawnStruct("TypeDefnStruct",
[]schema.StructField{
schema.SpawnStructField("fields", "Map__FieldName__StructField", false, false), // todo: dodging inline defn's again.
schema.SpawnStructField("representation", "StructRepresentation", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnMap("Map__FieldName__StructField",
"FieldName", "StructField", false,
))
ts.Accumulate(schema.SpawnString("FieldName"))
ts.Accumulate(schema.SpawnStruct("StructField",
[]schema.StructField{
schema.SpawnStructField("type", "TypeNameOrInlineDefn", false, false),
schema.SpawnStructField("optional", "Bool", true, false), // todo: wants to use the "implicit" feature, but not supported yet
schema.SpawnStructField("nullable", "Bool", true, false), // todo: wants to use the "implicit" feature, but not supported yet
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnUnion("StructRepresentation",
[]schema.TypeName{
"StructRepresentation_Map",
"StructRepresentation_Tuple",
"StructRepresentation_Stringpairs",
"StructRepresentation_Stringjoin",
"StructRepresentation_Listpairs",
},
schema.SpawnUnionRepresentationKeyed(map[string]schema.TypeName{
"map": "StructRepresentation_Map",
"tuple": "StructRepresentation_Tuple",
"stringpairs": "StructRepresentation_Stringpairs",
"stringjoin": "StructRepresentation_Stringjoin",
"listpairs": "StructRepresentation_Listpairs",
}),
))
ts.Accumulate(schema.SpawnStruct("StructRepresentation_Map",
[]schema.StructField{
schema.SpawnStructField("fields", "Map__FieldName__StructRepresentation_Map_FieldDetails", true, false), // todo: dodging inline defn's again.
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnMap("Map__FieldName__StructRepresentation_Map_FieldDetails",
"FieldName", "StructRepresentation_Map_FieldDetails", false,
))
ts.Accumulate(schema.SpawnStruct("StructRepresentation_Map_FieldDetails",
[]schema.StructField{
schema.SpawnStructField("rename", "String", true, false),
schema.SpawnStructField("implicit", "AnyScalar", true, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("StructRepresentation_Tuple",
[]schema.StructField{
schema.SpawnStructField("fieldOrder", "List__FieldName", true, false), // todo: dodging inline defn's again.
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnList("List__FieldName",
"FieldName", false,
))
ts.Accumulate(schema.SpawnStruct("StructRepresentation_Stringpairs",
[]schema.StructField{
schema.SpawnStructField("innerDelim", "String", false, false),
schema.SpawnStructField("entryDelim", "String", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("StructRepresentation_Stringjoin",
[]schema.StructField{
schema.SpawnStructField("join", "String", false, false), // review: "delim" would seem more consistent with others -- but this is currently what the schema-schema says.
schema.SpawnStructField("fieldOrder", "List__FieldName", true, false), // todo: dodging inline defn's again.
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("StructRepresentation_Listpairs",
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("TypeDefnEnum",
[]schema.StructField{
schema.SpawnStructField("members", "List__EnumMember", false, false),
schema.SpawnStructField("representation", "EnumRepresentation", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("Unit", // todo: we should formalize the introdution of unit as first class type kind.
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnList("List__EnumMember",
"EnumMember", false,
))
ts.Accumulate(schema.SpawnString("EnumMember"))
ts.Accumulate(schema.SpawnUnion("EnumRepresentation",
[]schema.TypeName{
"EnumRepresentation_String",
"EnumRepresentation_Int",
},
schema.SpawnUnionRepresentationKeyed(map[string]schema.TypeName{
"string": "EnumRepresentation_String",
"int": "EnumRepresentation_Int",
}),
))
ts.Accumulate(schema.SpawnMap("EnumRepresentation_String",
"EnumMember", "String", false,
))
ts.Accumulate(schema.SpawnMap("EnumRepresentation_Int",
"EnumMember", "Int", false,
))
ts.Accumulate(schema.SpawnStruct("TypeDefnUnit",
[]schema.StructField{
schema.SpawnStructField("representation", "UnitRepresentation", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnString("UnitRepresentation")) // TODO: enum
ts.Accumulate(schema.SpawnStruct("TypeDefnAny",
[]schema.StructField{},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnStruct("TypeDefnCopy",
[]schema.StructField{
schema.SpawnStructField("fromType", "TypeName", false, false),
},
schema.StructRepresentation_Map{},
))
ts.Accumulate(schema.SpawnUnion("AnyScalar",
[]schema.TypeName{
"Bool",
"String",
"Bytes",
"Int",
"Float",
},
schema.SpawnUnionRepresentationKinded(map[datamodel.Kind]schema.TypeName{
datamodel.Kind_Bool: "Bool",
datamodel.Kind_String: "String",
datamodel.Kind_Bytes: "Bytes",
datamodel.Kind_Int: "Int",
datamodel.Kind_Float: "Float",
}),
))
if errs := ts.ValidateGraph(); errs != nil {
for _, err := range errs {
fmt.Printf("- %s\n", err)
}
panic("not happening")
}
TypeSystem = ts
Prototypes.Schema = bindnode.Prototype(
(*Schema)(nil),
TypeSystem.TypeByName("Schema"),
)
}

View File

@@ -0,0 +1,215 @@
package schemadmt
type Schema struct {
Types Map__TypeName__TypeDefn
}
type Map__TypeName__TypeDefn struct {
Keys []string
Values map[string]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 TypeNameOrInlineDefn struct {
TypeName *string
InlineDefn *InlineDefn
}
type InlineDefn struct {
TypeDefnMap *TypeDefnMap
TypeDefnList *TypeDefnList
TypeDefnLink *TypeDefnLink
}
type TypeDefnBool struct {
}
type TypeDefnString struct {
}
type TypeDefnBytes struct {
}
type TypeDefnInt struct {
}
type TypeDefnFloat struct {
}
type TypeDefnMap struct {
KeyType string
ValueType TypeNameOrInlineDefn
ValueNullable *bool
Representation *MapRepresentation
}
type MapRepresentation struct {
MapRepresentation_Map *MapRepresentation_Map
MapRepresentation_Stringpairs *MapRepresentation_Stringpairs
MapRepresentation_Listpairs *MapRepresentation_Listpairs
}
type MapRepresentation_Map struct {
}
type MapRepresentation_Stringpairs struct {
InnerDelim string
EntryDelim string
}
type MapRepresentation_Listpairs struct {
}
type TypeDefnList struct {
ValueType TypeNameOrInlineDefn
ValueNullable *bool
Representation *ListRepresentation
}
type ListRepresentation struct {
ListRepresentation_List *ListRepresentation_List
}
type ListRepresentation_List struct {
}
type TypeDefnUnion struct {
Members List__UnionMember
Representation UnionRepresentation
}
type List__UnionMember []UnionMember
type UnionMember struct {
TypeName *string
UnionMemberInlineDefn *UnionMemberInlineDefn
}
type UnionMemberInlineDefn struct {
TypeDefnLink *TypeDefnLink
}
type List__TypeName []string
type TypeDefnLink struct {
ExpectedType *string
}
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_Kinded struct {
Keys []string
Values map[string]UnionMember
}
type UnionRepresentation_Keyed struct {
Keys []string
Values map[string]UnionMember
}
type Map__String__UnionMember struct {
Keys []string
Values map[string]TypeDefn
}
type UnionRepresentation_Envelope struct {
DiscriminantKey string
ContentKey string
DiscriminantTable Map__String__UnionMember
}
type UnionRepresentation_Inline struct {
DiscriminantKey string
DiscriminantTable Map__String__TypeName
}
type UnionRepresentation_StringPrefix struct {
Prefixes Map__String__TypeName
}
type UnionRepresentation_BytesPrefix struct {
Prefixes Map__HexString__TypeName
}
type Map__HexString__TypeName struct {
Keys []string
Values map[string]string
}
type Map__String__TypeName struct {
Keys []string
Values map[string]string
}
type Map__TypeName__Int struct {
Keys []string
Values map[string]int
}
type TypeDefnStruct struct {
Fields Map__FieldName__StructField
Representation StructRepresentation
}
type Map__FieldName__StructField struct {
Keys []string
Values map[string]StructField
}
type StructField struct {
Type TypeNameOrInlineDefn
Optional *bool
Nullable *bool
}
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_Map struct {
Fields *Map__FieldName__StructRepresentation_Map_FieldDetails
}
type Map__FieldName__StructRepresentation_Map_FieldDetails struct {
Keys []string
Values map[string]StructRepresentation_Map_FieldDetails
}
type StructRepresentation_Map_FieldDetails struct {
Rename *string
Implicit *AnyScalar
}
type StructRepresentation_Tuple struct {
FieldOrder *List__FieldName
}
type List__FieldName []string
type StructRepresentation_Stringpairs struct {
InnerDelim string
EntryDelim string
}
type StructRepresentation_Stringjoin struct {
Join string
FieldOrder *List__FieldName
}
type StructRepresentation_Listpairs struct {
}
type TypeDefnEnum struct {
Members List__EnumMember
Representation EnumRepresentation
}
type Unit struct {
}
type List__EnumMember []string
type EnumRepresentation struct {
EnumRepresentation_String *EnumRepresentation_String
EnumRepresentation_Int *EnumRepresentation_Int
}
type EnumRepresentation_String struct {
Keys []string
Values map[string]string
}
type EnumRepresentation_Int struct {
Keys []string
Values map[string]int
}
type TypeDefnUnit struct {
Representation string
}
type TypeDefnAny struct {
}
type TypeDefnCopy struct {
FromType string
}
type AnyScalar struct {
Bool *bool
String *string
Bytes *[]uint8
Int *int
Float *float64
}