From 107a638184c2c4f35bb72a05bfdcd73e9e2f96f7 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 2 Feb 2025 10:20:26 +0000 Subject: [PATCH] rename to tangled --- api/bild/bildpublicKey.go | 23 ---- api/bild/cbor_gen.go | 218 -------------------------------- api/tangled/cbor_gen.go | 218 ++++++++++++++++++++++++++++++++ api/tangled/tangledpublicKey.go | 27 ++++ appview/state/state.go | 4 +- cmd/gen.go | 8 +- flake.nix | 1 + knotserver/handler.go | 3 +- lexicon-build-config.json | 8 +- lexicons/publicKey.json | 2 +- 10 files changed, 259 insertions(+), 253 deletions(-) delete mode 100644 api/bild/bildpublicKey.go delete mode 100644 api/bild/cbor_gen.go create mode 100644 api/tangled/cbor_gen.go create mode 100644 api/tangled/tangledpublicKey.go diff --git a/api/bild/bildpublicKey.go b/api/bild/bildpublicKey.go deleted file mode 100644 index 3cd567f6..00000000 --- a/api/bild/bildpublicKey.go +++ /dev/null @@ -1,23 +0,0 @@ -// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. - -package bild - -// schema: sh.bild.publicKey - -import ( - "github.com/bluesky-social/indigo/lex/util" -) - -func init() { - util.RegisterType("sh.bild.publicKey", &PublicKey{}) -} // -// RECORDTYPE: PublicKey -type PublicKey struct { - LexiconTypeID string `json:"$type,const=sh.bild.publicKey" cborgen:"$type,const=sh.bild.publicKey"` - // created: key upload timestamp - Created string `json:"created" cborgen:"created"` - // key: public key contents - Key string `json:"key" cborgen:"key"` - // name: human-readable name for this key - Name string `json:"name" cborgen:"name"` -} diff --git a/api/bild/cbor_gen.go b/api/bild/cbor_gen.go deleted file mode 100644 index 594dea03..00000000 --- a/api/bild/cbor_gen.go +++ /dev/null @@ -1,218 +0,0 @@ -// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. - -package bild - -import ( - "fmt" - "io" - "math" - "sort" - - cid "github.com/ipfs/go-cid" - cbg "github.com/whyrusleeping/cbor-gen" - xerrors "golang.org/x/xerrors" -) - -var _ = xerrors.Errorf -var _ = cid.Undef -var _ = math.E -var _ = sort.Sort - -func (t *PublicKey) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - - cw := cbg.NewCborWriter(w) - - if _, err := cw.Write([]byte{164}); err != nil { - return err - } - - // t.Key (string) (string) - if len("key") > 1000000 { - return xerrors.Errorf("Value in field \"key\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("key"))); err != nil { - return err - } - if _, err := cw.WriteString(string("key")); err != nil { - return err - } - - if len(t.Key) > 1000000 { - return xerrors.Errorf("Value in field t.Key was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Key))); err != nil { - return err - } - if _, err := cw.WriteString(string(t.Key)); err != nil { - return err - } - - // t.Name (string) (string) - if len("name") > 1000000 { - return xerrors.Errorf("Value in field \"name\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("name"))); err != nil { - return err - } - if _, err := cw.WriteString(string("name")); err != nil { - return err - } - - if len(t.Name) > 1000000 { - return xerrors.Errorf("Value in field t.Name was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Name))); err != nil { - return err - } - if _, err := cw.WriteString(string(t.Name)); err != nil { - return err - } - - // t.LexiconTypeID (string) (string) - if len("$type") > 1000000 { - return xerrors.Errorf("Value in field \"$type\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { - return err - } - if _, err := cw.WriteString(string("$type")); err != nil { - return err - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sh.bild.publicKey"))); err != nil { - return err - } - if _, err := cw.WriteString(string("sh.bild.publicKey")); err != nil { - return err - } - - // t.Created (string) (string) - if len("created") > 1000000 { - return xerrors.Errorf("Value in field \"created\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("created"))); err != nil { - return err - } - if _, err := cw.WriteString(string("created")); err != nil { - return err - } - - if len(t.Created) > 1000000 { - return xerrors.Errorf("Value in field t.Created was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Created))); err != nil { - return err - } - if _, err := cw.WriteString(string(t.Created)); err != nil { - return err - } - return nil -} - -func (t *PublicKey) UnmarshalCBOR(r io.Reader) (err error) { - *t = PublicKey{} - - cr := cbg.NewCborReader(r) - - maj, extra, err := cr.ReadHeader() - if err != nil { - return err - } - defer func() { - if err == io.EOF { - err = io.ErrUnexpectedEOF - } - }() - - if maj != cbg.MajMap { - return fmt.Errorf("cbor input should be of type map") - } - - if extra > cbg.MaxLength { - return fmt.Errorf("PublicKey: map struct too large (%d)", extra) - } - - n := extra - - nameBuf := make([]byte, 7) - for i := uint64(0); i < n; i++ { - nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) - if err != nil { - return err - } - - if !ok { - // Field doesn't exist on this type, so ignore it - if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { - return err - } - continue - } - - switch string(nameBuf[:nameLen]) { - // t.Key (string) (string) - case "key": - - { - sval, err := cbg.ReadStringWithMax(cr, 1000000) - if err != nil { - return err - } - - t.Key = string(sval) - } - // t.Name (string) (string) - case "name": - - { - sval, err := cbg.ReadStringWithMax(cr, 1000000) - if err != nil { - return err - } - - t.Name = string(sval) - } - // t.LexiconTypeID (string) (string) - case "$type": - - { - sval, err := cbg.ReadStringWithMax(cr, 1000000) - if err != nil { - return err - } - - t.LexiconTypeID = string(sval) - } - // t.Created (string) (string) - case "created": - - { - sval, err := cbg.ReadStringWithMax(cr, 1000000) - if err != nil { - return err - } - - t.Created = string(sval) - } - - default: - // Field doesn't exist on this type, so ignore it - if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { - return err - } - } - } - - return nil -} diff --git a/api/tangled/cbor_gen.go b/api/tangled/cbor_gen.go new file mode 100644 index 00000000..b71843eb --- /dev/null +++ b/api/tangled/cbor_gen.go @@ -0,0 +1,218 @@ +// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. + +package tangled + +import ( + "fmt" + "io" + "math" + "sort" + + cid "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + xerrors "golang.org/x/xerrors" +) + +var _ = xerrors.Errorf +var _ = cid.Undef +var _ = math.E +var _ = sort.Sort + +func (t *PublicKey) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{164}); err != nil { + return err + } + + // t.Key (string) (string) + if len("key") > 1000000 { + return xerrors.Errorf("Value in field \"key\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("key"))); err != nil { + return err + } + if _, err := cw.WriteString(string("key")); err != nil { + return err + } + + if len(t.Key) > 1000000 { + return xerrors.Errorf("Value in field t.Key was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Key))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Key)); err != nil { + return err + } + + // t.Name (string) (string) + if len("name") > 1000000 { + return xerrors.Errorf("Value in field \"name\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("name"))); err != nil { + return err + } + if _, err := cw.WriteString(string("name")); err != nil { + return err + } + + if len(t.Name) > 1000000 { + return xerrors.Errorf("Value in field t.Name was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Name))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Name)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 1000000 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sh.tangled.publicKey"))); err != nil { + return err + } + if _, err := cw.WriteString(string("sh.tangled.publicKey")); err != nil { + return err + } + + // t.Created (string) (string) + if len("created") > 1000000 { + return xerrors.Errorf("Value in field \"created\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("created"))); err != nil { + return err + } + if _, err := cw.WriteString(string("created")); err != nil { + return err + } + + if len(t.Created) > 1000000 { + return xerrors.Errorf("Value in field t.Created was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Created))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Created)); err != nil { + return err + } + return nil +} + +func (t *PublicKey) UnmarshalCBOR(r io.Reader) (err error) { + *t = PublicKey{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("PublicKey: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 7) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.Key (string) (string) + case "key": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Key = string(sval) + } + // t.Name (string) (string) + case "name": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Name = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Created (string) (string) + case "created": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Created = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} diff --git a/api/tangled/tangledpublicKey.go b/api/tangled/tangledpublicKey.go new file mode 100644 index 00000000..be14d224 --- /dev/null +++ b/api/tangled/tangledpublicKey.go @@ -0,0 +1,27 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +package tangled + +// schema: sh.tangled.publicKey + +import ( + "github.com/bluesky-social/indigo/lex/util" +) + +const ( + PublicKeyNSID = "sh.tangled.publicKey" +) + +func init() { + util.RegisterType("sh.tangled.publicKey", &PublicKey{}) +} // +// RECORDTYPE: PublicKey +type PublicKey struct { + LexiconTypeID string `json:"$type,const=sh.tangled.publicKey" cborgen:"$type,const=sh.tangled.publicKey"` + // created: key upload timestamp + Created string `json:"created" cborgen:"created"` + // key: public key contents + Key string `json:"key" cborgen:"key"` + // name: human-readable name for this key + Name string `json:"name" cborgen:"name"` +} diff --git a/appview/state/state.go b/appview/state/state.go index a2b7cc47..38d8df51 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -14,7 +14,7 @@ import ( "github.com/gliderlabs/ssh" "github.com/go-chi/chi/v5" "github.com/google/uuid" - shbild "github.com/icyphox/bild/api/bild" + tangled "github.com/icyphox/bild/api/tangled" "github.com/icyphox/bild/appview" "github.com/icyphox/bild/appview/auth" "github.com/icyphox/bild/appview/db" @@ -148,7 +148,7 @@ func (s *State) Keys(w http.ResponseWriter, r *http.Request) { Collection: "sh.bild.publicKey", Repo: did, Rkey: uuid.New().String(), - Record: &lexutil.LexiconTypeDecoder{Val: &shbild.PublicKey{ + Record: &lexutil.LexiconTypeDecoder{Val: &tangled.PublicKey{ Created: time.Now().String(), Key: key, Name: name, diff --git a/cmd/gen.go b/cmd/gen.go index dea851c2..53acda32 100644 --- a/cmd/gen.go +++ b/cmd/gen.go @@ -1,7 +1,7 @@ package main import ( - shbild "github.com/icyphox/bild/api/bild" + shtangled "github.com/icyphox/bild/api/tangled" cbg "github.com/whyrusleeping/cbor-gen" ) @@ -12,9 +12,9 @@ func main() { } if err := genCfg.WriteMapEncodersToFile( - "api/bild/cbor_gen.go", - "bild", - shbild.PublicKey{}, + "api/tangled/cbor_gen.go", + "tangled", + shtangled.PublicKey{}, ); err != nil { panic(err) } diff --git a/flake.nix b/flake.nix index 52e5535e..611f730a 100644 --- a/flake.nix +++ b/flake.nix @@ -50,6 +50,7 @@ pkgs.httpie pkgs.indigo-lexgen pkgs.litecli + pkgs.websocat ]; }; }); diff --git a/knotserver/handler.go b/knotserver/handler.go index d3df8b3e..b7b74dee 100644 --- a/knotserver/handler.go +++ b/knotserver/handler.go @@ -8,6 +8,7 @@ import ( "net/http" "github.com/go-chi/chi/v5" + tangled "github.com/icyphox/bild/api/tangled" "github.com/icyphox/bild/knotserver/config" "github.com/icyphox/bild/knotserver/db" "github.com/icyphox/bild/knotserver/jsclient" @@ -71,7 +72,7 @@ func Setup(ctx context.Context, c *config.Config, db *db.DB) (http.Handler, erro } func (h *Handle) StartJetstream(ctx context.Context) error { - colections := []string{"sh.bild.publicKeys"} + colections := []string{tangled.PublicKeyNSID} dids := []string{} h.js = jsclient.NewJetstreamClient(colections, dids) diff --git a/lexicon-build-config.json b/lexicon-build-config.json index 49168679..1274bfd3 100644 --- a/lexicon-build-config.json +++ b/lexicon-build-config.json @@ -1,9 +1,9 @@ [ { - "package": "bild", - "prefix": "sh.bild", - "outdir": "api/bild", - "import": "github.com/icyphox/bild/api/bild", + "package": "tangled", + "prefix": "sh.tangled", + "outdir": "api/tangled", + "import": "github.com/icyphox/bild/api/tangled", "gen-server": true } ] diff --git a/lexicons/publicKey.json b/lexicons/publicKey.json index d6d26638..51250b44 100644 --- a/lexicons/publicKey.json +++ b/lexicons/publicKey.json @@ -1,6 +1,6 @@ { "lexicon": 1, - "id": "sh.bild.publicKey", + "id": "sh.tangled.publicKey", "needsCbor": true, "needsType": true, "defs": { -- knotmirror 0.0.1