diff --git a/api/tangled/cbor_gen.go b/api/tangled/cbor_gen.go --- a/api/tangled/cbor_gen.go +++ b/api/tangled/cbor_gen.go @@ -3077,6 +3077,454 @@ } return nil } +func (t *LabelOp) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{165}); err != nil { + return err + } + + // t.Add ([]*tangled.LabelOp_Operand) (slice) + if len("add") > 1000000 { + return xerrors.Errorf("Value in field \"add\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("add"))); err != nil { + return err + } + if _, err := cw.WriteString(string("add")); err != nil { + return err + } + + if len(t.Add) > 8192 { + return xerrors.Errorf("Slice value in field t.Add was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Add))); err != nil { + return err + } + for _, v := range t.Add { + if err := v.MarshalCBOR(cw); 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.label.op"))); err != nil { + return err + } + if _, err := cw.WriteString(string("sh.tangled.label.op")); err != nil { + return err + } + + // t.Delete ([]*tangled.LabelOp_Operand) (slice) + if len("delete") > 1000000 { + return xerrors.Errorf("Value in field \"delete\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("delete"))); err != nil { + return err + } + if _, err := cw.WriteString(string("delete")); err != nil { + return err + } + + if len(t.Delete) > 8192 { + return xerrors.Errorf("Slice value in field t.Delete was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Delete))); err != nil { + return err + } + for _, v := range t.Delete { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + + } + + // t.Subject (string) (string) + if len("subject") > 1000000 { + return xerrors.Errorf("Value in field \"subject\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { + return err + } + if _, err := cw.WriteString(string("subject")); err != nil { + return err + } + + if len(t.Subject) > 1000000 { + return xerrors.Errorf("Value in field t.Subject was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Subject))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Subject)); err != nil { + return err + } + + // t.PerformedAt (string) (string) + if len("performedAt") > 1000000 { + return xerrors.Errorf("Value in field \"performedAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("performedAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("performedAt")); err != nil { + return err + } + + if len(t.PerformedAt) > 1000000 { + return xerrors.Errorf("Value in field t.PerformedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.PerformedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.PerformedAt)); err != nil { + return err + } + return nil +} + +func (t *LabelOp) UnmarshalCBOR(r io.Reader) (err error) { + *t = LabelOp{} + + 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("LabelOp: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 11) + 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.Add ([]*tangled.LabelOp_Operand) (slice) + case "add": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.Add: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Add = make([]*LabelOp_Operand, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Add[i] = new(LabelOp_Operand) + if err := t.Add[i].UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Add[i] pointer: %w", err) + } + } + + } + + } + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Delete ([]*tangled.LabelOp_Operand) (slice) + case "delete": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.Delete: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Delete = make([]*LabelOp_Operand, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Delete[i] = new(LabelOp_Operand) + if err := t.Delete[i].UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Delete[i] pointer: %w", err) + } + } + + } + + } + } + // t.Subject (string) (string) + case "subject": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Subject = string(sval) + } + // t.PerformedAt (string) (string) + case "performedAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.PerformedAt = 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 +} +func (t *LabelOp_Operand) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{162}); 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.Value (string) (string) + if len("value") > 1000000 { + return xerrors.Errorf("Value in field \"value\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("value"))); err != nil { + return err + } + if _, err := cw.WriteString(string("value")); err != nil { + return err + } + + if len(t.Value) > 1000000 { + return xerrors.Errorf("Value in field t.Value was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Value))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Value)); err != nil { + return err + } + return nil +} + +func (t *LabelOp_Operand) UnmarshalCBOR(r io.Reader) (err error) { + *t = LabelOp_Operand{} + + 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("LabelOp_Operand: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 5) + 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.Value (string) (string) + case "value": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Value = 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 +} func (t *Pipeline) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) diff --git a/api/tangled/labelop.go b/api/tangled/labelop.go new file mode 100644 --- /dev/null +++ b/api/tangled/labelop.go @@ -0,0 +1,34 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +package tangled + +// schema: sh.tangled.label.op + +import ( + "github.com/bluesky-social/indigo/lex/util" +) + +const ( + LabelOpNSID = "sh.tangled.label.op" +) + +func init() { + util.RegisterType("sh.tangled.label.op", &LabelOp{}) +} // +// RECORDTYPE: LabelOp +type LabelOp struct { + LexiconTypeID string `json:"$type,const=sh.tangled.label.op" cborgen:"$type,const=sh.tangled.label.op"` + Add []*LabelOp_Operand `json:"add" cborgen:"add"` + Delete []*LabelOp_Operand `json:"delete" cborgen:"delete"` + PerformedAt string `json:"performedAt" cborgen:"performedAt"` + // subject: The subject (task, pull or discussion) of this label. Appviews may apply a `scope` check and refuse this op. + Subject string `json:"subject" cborgen:"subject"` +} + +// LabelOp_Operand is a "operand" in the sh.tangled.label.op schema. +type LabelOp_Operand struct { + // key: ATURI to the label definition + Key string `json:"key" cborgen:"key"` + // value: Stringified value of the label. This is first unstringed by appviews and then interpreted as a concrete value. + Value string `json:"value" cborgen:"value"` +} diff --git a/cmd/gen.go b/cmd/gen.go --- a/cmd/gen.go +++ b/cmd/gen.go @@ -28,6 +28,8 @@ tangled.Knot{}, tangled.KnotMember{}, tangled.LabelDefinition{}, tangled.LabelDefinition_ValueType{}, + tangled.LabelOp{}, + tangled.LabelOp_Operand{}, tangled.Pipeline{}, tangled.Pipeline_CloneOpts{}, tangled.Pipeline_ManualTriggerData{}, diff --git a/lexicons/label/op.json b/lexicons/label/op.json new file mode 100644 --- /dev/null +++ b/lexicons/label/op.json @@ -0,0 +1,64 @@ +{ + "lexicon": 1, + "id": "sh.tangled.label.op", + "needsCbor": true, + "needsType": true, + "defs": { + "main": { + "type": "record", + "key": "tid", + "record": { + "type": "object", + "required": [ + "subject", + "add", + "delete", + "performedAt" + ], + "properties": { + "subject": { + "type": "string", + "format": "at-uri", + "description": "The subject (task, pull or discussion) of this label. Appviews may apply a `scope` check and refuse this op." + }, + "performedAt": { + "type": "string", + "format": "datetime" + }, + "add": { + "type": "array", + "items": { + "type": "ref", + "ref": "#operand" + } + }, + "delete": { + "type": "array", + "items": { + "type": "ref", + "ref": "#operand" + } + } + } + } + }, + "operand": { + "type": "object", + "required": [ + "key", + "value" + ], + "properties": { + "key": { + "type": "string", + "format": "at-uri", + "description": "ATURI to the label definition" + }, + "value": { + "type": "string", + "description": "Stringified value of the label. This is first unstringed by appviews and then interpreted as a concrete value." + } + } + } + } +}