github.com/ipld/go-ipld-prime@v0.21.0/schema/dmt/operations.go (about) 1 package schemadmt 2 3 import ( 4 "github.com/ipld/go-ipld-prime/datamodel" 5 "github.com/ipld/go-ipld-prime/node/bindnode" 6 ) 7 8 // ConcatenateSchemas returns a new schema DMT object containing the 9 // type declarations from both. 10 // 11 // As is usual for DMT form data, there is no check about the validity 12 // of the result yet; you'll need to apply `Compile` on the produced value 13 // to produce a usable compiled typesystem or to become certain that 14 // all references in the DMT are satisfied, etc. 15 func ConcatenateSchemas(a, b *Schema) *Schema { 16 // The joy of having an intermediate form that's just regular data model: 17 // we can implement this by simply using data model "copy" operations, 18 // and the result is correct. 19 nb := Prototypes.Schema.NewBuilder() 20 if err := datamodel.Copy(bindnode.Wrap(a, Prototypes.Schema.Type()), nb); err != nil { 21 panic(err) 22 } 23 if err := datamodel.Copy(bindnode.Wrap(b, Prototypes.Schema.Type()), nb); err != nil { 24 panic(err) 25 } 26 return bindnode.Unwrap(nb.Build()).(*Schema) 27 }