···88 "math"
99 "sort"
10101111+ util "github.com/bluesky-social/indigo/lex/util"
1112 cid "github.com/ipfs/go-cid"
1213 cbg "github.com/whyrusleeping/cbor-gen"
1314 xerrors "golang.org/x/xerrors"
···3098309930993100 return nil
31003101}
31023102+func (t *RepoArtifact) MarshalCBOR(w io.Writer) error {
31033103+ if t == nil {
31043104+ _, err := w.Write(cbg.CborNull)
31053105+ return err
31063106+ }
31073107+31083108+ cw := cbg.NewCborWriter(w)
31093109+ fieldCount := 6
31103110+31113111+ if t.Tag == nil {
31123112+ fieldCount--
31133113+ }
31143114+31153115+ if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil {
31163116+ return err
31173117+ }
31183118+31193119+ // t.Tag (util.LexBytes) (slice)
31203120+ if t.Tag != nil {
31213121+31223122+ if len("tag") > 1000000 {
31233123+ return xerrors.Errorf("Value in field \"tag\" was too long")
31243124+ }
31253125+31263126+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("tag"))); err != nil {
31273127+ return err
31283128+ }
31293129+ if _, err := cw.WriteString(string("tag")); err != nil {
31303130+ return err
31313131+ }
31323132+31333133+ if len(t.Tag) > 2097152 {
31343134+ return xerrors.Errorf("Byte array in field t.Tag was too long")
31353135+ }
31363136+31373137+ if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Tag))); err != nil {
31383138+ return err
31393139+ }
31403140+31413141+ if _, err := cw.Write(t.Tag); err != nil {
31423142+ return err
31433143+ }
31443144+31453145+ }
31463146+31473147+ // t.Name (string) (string)
31483148+ if len("name") > 1000000 {
31493149+ return xerrors.Errorf("Value in field \"name\" was too long")
31503150+ }
31513151+31523152+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("name"))); err != nil {
31533153+ return err
31543154+ }
31553155+ if _, err := cw.WriteString(string("name")); err != nil {
31563156+ return err
31573157+ }
31583158+31593159+ if len(t.Name) > 1000000 {
31603160+ return xerrors.Errorf("Value in field t.Name was too long")
31613161+ }
31623162+31633163+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Name))); err != nil {
31643164+ return err
31653165+ }
31663166+ if _, err := cw.WriteString(string(t.Name)); err != nil {
31673167+ return err
31683168+ }
31693169+31703170+ // t.Repo (string) (string)
31713171+ if len("repo") > 1000000 {
31723172+ return xerrors.Errorf("Value in field \"repo\" was too long")
31733173+ }
31743174+31753175+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repo"))); err != nil {
31763176+ return err
31773177+ }
31783178+ if _, err := cw.WriteString(string("repo")); err != nil {
31793179+ return err
31803180+ }
31813181+31823182+ if len(t.Repo) > 1000000 {
31833183+ return xerrors.Errorf("Value in field t.Repo was too long")
31843184+ }
31853185+31863186+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repo))); err != nil {
31873187+ return err
31883188+ }
31893189+ if _, err := cw.WriteString(string(t.Repo)); err != nil {
31903190+ return err
31913191+ }
31923192+31933193+ // t.LexiconTypeID (string) (string)
31943194+ if len("$type") > 1000000 {
31953195+ return xerrors.Errorf("Value in field \"$type\" was too long")
31963196+ }
31973197+31983198+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil {
31993199+ return err
32003200+ }
32013201+ if _, err := cw.WriteString(string("$type")); err != nil {
32023202+ return err
32033203+ }
32043204+32053205+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sh.tangled.repo.artifact"))); err != nil {
32063206+ return err
32073207+ }
32083208+ if _, err := cw.WriteString(string("sh.tangled.repo.artifact")); err != nil {
32093209+ return err
32103210+ }
32113211+32123212+ // t.Artifact (util.LexBlob) (struct)
32133213+ if len("artifact") > 1000000 {
32143214+ return xerrors.Errorf("Value in field \"artifact\" was too long")
32153215+ }
32163216+32173217+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("artifact"))); err != nil {
32183218+ return err
32193219+ }
32203220+ if _, err := cw.WriteString(string("artifact")); err != nil {
32213221+ return err
32223222+ }
32233223+32243224+ if err := t.Artifact.MarshalCBOR(cw); err != nil {
32253225+ return err
32263226+ }
32273227+32283228+ // t.CreatedAt (string) (string)
32293229+ if len("createdAt") > 1000000 {
32303230+ return xerrors.Errorf("Value in field \"createdAt\" was too long")
32313231+ }
32323232+32333233+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil {
32343234+ return err
32353235+ }
32363236+ if _, err := cw.WriteString(string("createdAt")); err != nil {
32373237+ return err
32383238+ }
32393239+32403240+ if len(t.CreatedAt) > 1000000 {
32413241+ return xerrors.Errorf("Value in field t.CreatedAt was too long")
32423242+ }
32433243+32443244+ if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil {
32453245+ return err
32463246+ }
32473247+ if _, err := cw.WriteString(string(t.CreatedAt)); err != nil {
32483248+ return err
32493249+ }
32503250+ return nil
32513251+}
32523252+32533253+func (t *RepoArtifact) UnmarshalCBOR(r io.Reader) (err error) {
32543254+ *t = RepoArtifact{}
32553255+32563256+ cr := cbg.NewCborReader(r)
32573257+32583258+ maj, extra, err := cr.ReadHeader()
32593259+ if err != nil {
32603260+ return err
32613261+ }
32623262+ defer func() {
32633263+ if err == io.EOF {
32643264+ err = io.ErrUnexpectedEOF
32653265+ }
32663266+ }()
32673267+32683268+ if maj != cbg.MajMap {
32693269+ return fmt.Errorf("cbor input should be of type map")
32703270+ }
32713271+32723272+ if extra > cbg.MaxLength {
32733273+ return fmt.Errorf("RepoArtifact: map struct too large (%d)", extra)
32743274+ }
32753275+32763276+ n := extra
32773277+32783278+ nameBuf := make([]byte, 9)
32793279+ for i := uint64(0); i < n; i++ {
32803280+ nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000)
32813281+ if err != nil {
32823282+ return err
32833283+ }
32843284+32853285+ if !ok {
32863286+ // Field doesn't exist on this type, so ignore it
32873287+ if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil {
32883288+ return err
32893289+ }
32903290+ continue
32913291+ }
32923292+32933293+ switch string(nameBuf[:nameLen]) {
32943294+ // t.Tag (util.LexBytes) (slice)
32953295+ case "tag":
32963296+32973297+ maj, extra, err = cr.ReadHeader()
32983298+ if err != nil {
32993299+ return err
33003300+ }
33013301+33023302+ if extra > 2097152 {
33033303+ return fmt.Errorf("t.Tag: byte array too large (%d)", extra)
33043304+ }
33053305+ if maj != cbg.MajByteString {
33063306+ return fmt.Errorf("expected byte array")
33073307+ }
33083308+33093309+ if extra > 0 {
33103310+ t.Tag = make([]uint8, extra)
33113311+ }
33123312+33133313+ if _, err := io.ReadFull(cr, t.Tag); err != nil {
33143314+ return err
33153315+ }
33163316+33173317+ // t.Name (string) (string)
33183318+ case "name":
33193319+33203320+ {
33213321+ sval, err := cbg.ReadStringWithMax(cr, 1000000)
33223322+ if err != nil {
33233323+ return err
33243324+ }
33253325+33263326+ t.Name = string(sval)
33273327+ }
33283328+ // t.Repo (string) (string)
33293329+ case "repo":
33303330+33313331+ {
33323332+ sval, err := cbg.ReadStringWithMax(cr, 1000000)
33333333+ if err != nil {
33343334+ return err
33353335+ }
33363336+33373337+ t.Repo = string(sval)
33383338+ }
33393339+ // t.LexiconTypeID (string) (string)
33403340+ case "$type":
33413341+33423342+ {
33433343+ sval, err := cbg.ReadStringWithMax(cr, 1000000)
33443344+ if err != nil {
33453345+ return err
33463346+ }
33473347+33483348+ t.LexiconTypeID = string(sval)
33493349+ }
33503350+ // t.Artifact (util.LexBlob) (struct)
33513351+ case "artifact":
33523352+33533353+ {
33543354+33553355+ b, err := cr.ReadByte()
33563356+ if err != nil {
33573357+ return err
33583358+ }
33593359+ if b != cbg.CborNull[0] {
33603360+ if err := cr.UnreadByte(); err != nil {
33613361+ return err
33623362+ }
33633363+ t.Artifact = new(util.LexBlob)
33643364+ if err := t.Artifact.UnmarshalCBOR(cr); err != nil {
33653365+ return xerrors.Errorf("unmarshaling t.Artifact pointer: %w", err)
33663366+ }
33673367+ }
33683368+33693369+ }
33703370+ // t.CreatedAt (string) (string)
33713371+ case "createdAt":
33723372+33733373+ {
33743374+ sval, err := cbg.ReadStringWithMax(cr, 1000000)
33753375+ if err != nil {
33763376+ return err
33773377+ }
33783378+33793379+ t.CreatedAt = string(sval)
33803380+ }
33813381+33823382+ default:
33833383+ // Field doesn't exist on this type, so ignore it
33843384+ if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil {
33853385+ return err
33863386+ }
33873387+ }
33883388+ }
33893389+33903390+ return nil
33913391+}
+31
api/tangled/repoartifact.go
···11+// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.
22+33+package tangled
44+55+// schema: sh.tangled.repo.artifact
66+77+import (
88+ "github.com/bluesky-social/indigo/lex/util"
99+)
1010+1111+const (
1212+ RepoArtifactNSID = "sh.tangled.repo.artifact"
1313+)
1414+1515+func init() {
1616+ util.RegisterType("sh.tangled.repo.artifact", &RepoArtifact{})
1717+} //
1818+// RECORDTYPE: RepoArtifact
1919+type RepoArtifact struct {
2020+ LexiconTypeID string `json:"$type,const=sh.tangled.repo.artifact" cborgen:"$type,const=sh.tangled.repo.artifact"`
2121+ // artifact: the artifact
2222+ Artifact *util.LexBlob `json:"artifact" cborgen:"artifact"`
2323+ // createdAt: time of creation of this artifact
2424+ CreatedAt string `json:"createdAt" cborgen:"createdAt"`
2525+ // name: name of the artifact
2626+ Name string `json:"name" cborgen:"name"`
2727+ // repo: repo that this artifact is being uploaded to
2828+ Repo string `json:"repo" cborgen:"repo"`
2929+ // tag: hash of the tag object that this artifact is attached to (only annotated tags are supported)
3030+ Tag util.LexBytes `json:"tag,omitempty" cborgen:"tag,omitempty"`
3131+}
···208208 unique(did, email)
209209 );
210210211211+ create table if not exists artifacts (
212212+ -- id
213213+ id integer primary key autoincrement,
214214+ did text not null,
215215+ rkey text not null,
216216+217217+ -- meta
218218+ repo_at text not null,
219219+ tag binary(20) not null,
220220+ created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
221221+222222+ -- data
223223+ blob_cid text not null,
224224+ name text not null,
225225+ size integer not null default 0,
226226+ mimetype string not null default "*/*",
227227+228228+ -- constraints
229229+ unique(did, rkey), -- record must be unique
230230+ unique(repo_at, tag, name), -- for a given tag object, each file must be unique
231231+ foreign key (repo_at) references repos(at_uri) on delete cascade
232232+ );
233233+211234 create table if not exists migrations (
212235 id integer primary key autoincrement,
213236 name text unique