this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fixup text slice types

why d7816ea5 d15a53ec

+225 -98
+19 -8
api/bsky.go
··· 13 13 } 14 14 15 15 type PostEntity struct { 16 - Index []int64 `json:"index"` 17 - Type string `json:"type"` 18 - Value string `json:"value"` 16 + Index *TextSlice `json:"index" cborgen:"index"` 17 + Type string `json:"type" cborgen:"type"` 18 + Value string `json:"value" cborgen:"value"` 19 + } 20 + 21 + type TextSlice struct { 22 + Start int64 `json:"start" cborgen:"start"` 23 + End int64 `json:"end" cborgen:"end"` 19 24 } 20 25 21 26 type ReplyRef struct { 22 - Root PostRef `json:"root"` 23 - Parent PostRef `json:"parent"` 27 + Root PostRef `json:"root" cborgen:"root"` 28 + Parent PostRef `json:"parent" cborgen:"parent"` 24 29 } 25 30 26 31 type PostRecord struct { ··· 66 71 Record interface{} `json:"record"` 67 72 } 68 73 74 + type Declaration struct { 75 + Cid string `json:"cid"` 76 + ActorType string `json:"actorType"` 77 + } 78 + 69 79 type User struct { 70 - Did string `json:"did"` 71 - Handle string `json:"handle"` 72 - DisplayName string `json:"displayName"` 80 + Did string `json:"did"` 81 + Handle string `json:"handle"` 82 + DisplayName string `json:"displayName"` 83 + Declaration *Declaration `json:"declaration"` 73 84 } 74 85 75 86 func (b *BskyApp) FeedGetTimeline(ctx context.Context, algo string, limit int, before *string) (*GetTimelineResp, error) {
+196 -81
api/cbor_gen.go
··· 284 284 return err 285 285 } 286 286 287 - // t.Index ([]int64) (slice) 288 - if len("Index") > cbg.MaxLength { 289 - return xerrors.Errorf("Value in field \"Index\" was too long") 287 + // t.Index (api.TextSlice) (struct) 288 + if len("index") > cbg.MaxLength { 289 + return xerrors.Errorf("Value in field \"index\" was too long") 290 290 } 291 291 292 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Index"))); err != nil { 292 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("index"))); err != nil { 293 293 return err 294 294 } 295 - if _, err := io.WriteString(w, string("Index")); err != nil { 295 + if _, err := io.WriteString(w, string("index")); err != nil { 296 296 return err 297 297 } 298 298 299 - if len(t.Index) > cbg.MaxLength { 300 - return xerrors.Errorf("Slice value in field t.Index was too long") 301 - } 302 - 303 - if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Index))); err != nil { 299 + if err := t.Index.MarshalCBOR(cw); err != nil { 304 300 return err 305 301 } 306 - for _, v := range t.Index { 307 - if v >= 0 { 308 - if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(v)); err != nil { 309 - return err 310 - } 311 - } else { 312 - if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-v-1)); err != nil { 313 - return err 314 - } 315 - } 316 - } 317 302 318 303 // t.Type (string) (string) 319 - if len("Type") > cbg.MaxLength { 320 - return xerrors.Errorf("Value in field \"Type\" was too long") 304 + if len("type") > cbg.MaxLength { 305 + return xerrors.Errorf("Value in field \"type\" was too long") 321 306 } 322 307 323 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Type"))); err != nil { 308 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("type"))); err != nil { 324 309 return err 325 310 } 326 - if _, err := io.WriteString(w, string("Type")); err != nil { 311 + if _, err := io.WriteString(w, string("type")); err != nil { 327 312 return err 328 313 } 329 314 ··· 339 324 } 340 325 341 326 // t.Value (string) (string) 342 - if len("Value") > cbg.MaxLength { 343 - return xerrors.Errorf("Value in field \"Value\" was too long") 327 + if len("value") > cbg.MaxLength { 328 + return xerrors.Errorf("Value in field \"value\" was too long") 344 329 } 345 330 346 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Value"))); err != nil { 331 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("value"))); err != nil { 347 332 return err 348 333 } 349 - if _, err := io.WriteString(w, string("Value")); err != nil { 334 + if _, err := io.WriteString(w, string("value")); err != nil { 350 335 return err 351 336 } 352 337 ··· 401 386 } 402 387 403 388 switch name { 404 - // t.Index ([]int64) (slice) 405 - case "Index": 389 + // t.Index (api.TextSlice) (struct) 390 + case "index": 406 391 407 - maj, extra, err = cr.ReadHeader() 408 - if err != nil { 409 - return err 410 - } 392 + { 411 393 412 - if extra > cbg.MaxLength { 413 - return fmt.Errorf("t.Index: array too large (%d)", extra) 414 - } 415 - 416 - if maj != cbg.MajArray { 417 - return fmt.Errorf("expected cbor array") 418 - } 419 - 420 - if extra > 0 { 421 - t.Index = make([]int64, extra) 422 - } 423 - 424 - for i := 0; i < int(extra); i++ { 425 - { 426 - maj, extra, err := cr.ReadHeader() 427 - var extraI int64 428 - if err != nil { 394 + b, err := cr.ReadByte() 395 + if err != nil { 396 + return err 397 + } 398 + if b != cbg.CborNull[0] { 399 + if err := cr.UnreadByte(); err != nil { 429 400 return err 430 401 } 431 - switch maj { 432 - case cbg.MajUnsignedInt: 433 - extraI = int64(extra) 434 - if extraI < 0 { 435 - return fmt.Errorf("int64 positive overflow") 436 - } 437 - case cbg.MajNegativeInt: 438 - extraI = int64(extra) 439 - if extraI < 0 { 440 - return fmt.Errorf("int64 negative oveflow") 441 - } 442 - extraI = -1 - extraI 443 - default: 444 - return fmt.Errorf("wrong type for int64 field: %d", maj) 402 + t.Index = new(TextSlice) 403 + if err := t.Index.UnmarshalCBOR(cr); err != nil { 404 + return xerrors.Errorf("unmarshaling t.Index pointer: %w", err) 445 405 } 406 + } 446 407 447 - t.Index[i] = int64(extraI) 448 - } 449 408 } 450 - 451 409 // t.Type (string) (string) 452 - case "Type": 410 + case "type": 453 411 454 412 { 455 413 sval, err := cbg.ReadString(cr) ··· 460 418 t.Type = string(sval) 461 419 } 462 420 // t.Value (string) (string) 463 - case "Value": 421 + case "value": 464 422 465 423 { 466 424 sval, err := cbg.ReadString(cr) ··· 621 579 } 622 580 623 581 // t.Root (api.PostRef) (struct) 624 - if len("Root") > cbg.MaxLength { 625 - return xerrors.Errorf("Value in field \"Root\" was too long") 582 + if len("root") > cbg.MaxLength { 583 + return xerrors.Errorf("Value in field \"root\" was too long") 626 584 } 627 585 628 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Root"))); err != nil { 586 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("root"))); err != nil { 629 587 return err 630 588 } 631 - if _, err := io.WriteString(w, string("Root")); err != nil { 589 + if _, err := io.WriteString(w, string("root")); err != nil { 632 590 return err 633 591 } 634 592 ··· 637 595 } 638 596 639 597 // t.Parent (api.PostRef) (struct) 640 - if len("Parent") > cbg.MaxLength { 641 - return xerrors.Errorf("Value in field \"Parent\" was too long") 598 + if len("parent") > cbg.MaxLength { 599 + return xerrors.Errorf("Value in field \"parent\" was too long") 642 600 } 643 601 644 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Parent"))); err != nil { 602 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("parent"))); err != nil { 645 603 return err 646 604 } 647 - if _, err := io.WriteString(w, string("Parent")); err != nil { 605 + if _, err := io.WriteString(w, string("parent")); err != nil { 648 606 return err 649 607 } 650 608 ··· 693 651 694 652 switch name { 695 653 // t.Root (api.PostRef) (struct) 696 - case "Root": 654 + case "root": 697 655 698 656 { 699 657 ··· 703 661 704 662 } 705 663 // t.Parent (api.PostRef) (struct) 706 - case "Parent": 664 + case "parent": 707 665 708 666 { 709 667 ··· 721 679 722 680 return nil 723 681 } 682 + func (t *TextSlice) MarshalCBOR(w io.Writer) error { 683 + if t == nil { 684 + _, err := w.Write(cbg.CborNull) 685 + return err 686 + } 687 + 688 + cw := cbg.NewCborWriter(w) 689 + 690 + if _, err := cw.Write([]byte{162}); err != nil { 691 + return err 692 + } 693 + 694 + // t.Start (int64) (int64) 695 + if len("start") > cbg.MaxLength { 696 + return xerrors.Errorf("Value in field \"start\" was too long") 697 + } 698 + 699 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("start"))); err != nil { 700 + return err 701 + } 702 + if _, err := io.WriteString(w, string("start")); err != nil { 703 + return err 704 + } 705 + 706 + if t.Start >= 0 { 707 + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Start)); err != nil { 708 + return err 709 + } 710 + } else { 711 + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Start-1)); err != nil { 712 + return err 713 + } 714 + } 715 + 716 + // t.End (int64) (int64) 717 + if len("end") > cbg.MaxLength { 718 + return xerrors.Errorf("Value in field \"end\" was too long") 719 + } 720 + 721 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("end"))); err != nil { 722 + return err 723 + } 724 + if _, err := io.WriteString(w, string("end")); err != nil { 725 + return err 726 + } 727 + 728 + if t.End >= 0 { 729 + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.End)); err != nil { 730 + return err 731 + } 732 + } else { 733 + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.End-1)); err != nil { 734 + return err 735 + } 736 + } 737 + return nil 738 + } 739 + 740 + func (t *TextSlice) UnmarshalCBOR(r io.Reader) (err error) { 741 + *t = TextSlice{} 742 + 743 + cr := cbg.NewCborReader(r) 744 + 745 + maj, extra, err := cr.ReadHeader() 746 + if err != nil { 747 + return err 748 + } 749 + defer func() { 750 + if err == io.EOF { 751 + err = io.ErrUnexpectedEOF 752 + } 753 + }() 754 + 755 + if maj != cbg.MajMap { 756 + return fmt.Errorf("cbor input should be of type map") 757 + } 758 + 759 + if extra > cbg.MaxLength { 760 + return fmt.Errorf("TextSlice: map struct too large (%d)", extra) 761 + } 762 + 763 + var name string 764 + n := extra 765 + 766 + for i := uint64(0); i < n; i++ { 767 + 768 + { 769 + sval, err := cbg.ReadString(cr) 770 + if err != nil { 771 + return err 772 + } 773 + 774 + name = string(sval) 775 + } 776 + 777 + switch name { 778 + // t.Start (int64) (int64) 779 + case "start": 780 + { 781 + maj, extra, err := cr.ReadHeader() 782 + var extraI int64 783 + if err != nil { 784 + return err 785 + } 786 + switch maj { 787 + case cbg.MajUnsignedInt: 788 + extraI = int64(extra) 789 + if extraI < 0 { 790 + return fmt.Errorf("int64 positive overflow") 791 + } 792 + case cbg.MajNegativeInt: 793 + extraI = int64(extra) 794 + if extraI < 0 { 795 + return fmt.Errorf("int64 negative oveflow") 796 + } 797 + extraI = -1 - extraI 798 + default: 799 + return fmt.Errorf("wrong type for int64 field: %d", maj) 800 + } 801 + 802 + t.Start = int64(extraI) 803 + } 804 + // t.End (int64) (int64) 805 + case "end": 806 + { 807 + maj, extra, err := cr.ReadHeader() 808 + var extraI int64 809 + if err != nil { 810 + return err 811 + } 812 + switch maj { 813 + case cbg.MajUnsignedInt: 814 + extraI = int64(extra) 815 + if extraI < 0 { 816 + return fmt.Errorf("int64 positive overflow") 817 + } 818 + case cbg.MajNegativeInt: 819 + extraI = int64(extra) 820 + if extraI < 0 { 821 + return fmt.Errorf("int64 negative oveflow") 822 + } 823 + extraI = -1 - extraI 824 + default: 825 + return fmt.Errorf("wrong type for int64 field: %d", maj) 826 + } 827 + 828 + t.End = int64(extraI) 829 + } 830 + 831 + default: 832 + // Field doesn't exist on this type, so ignore it 833 + cbg.ScanForLinks(r, func(cid.Cid) {}) 834 + } 835 + } 836 + 837 + return nil 838 + }
+1 -1
cmd/gosky/main.go
··· 137 137 Action: func(cctx *cli.Context) error { 138 138 s := cliutil.GetPLCClient(cctx) 139 139 140 - doc, err := s.GetDocument(cctx.Args().First()) 140 + doc, err := s.GetDocument(context.TODO(), cctx.Args().First()) 141 141 if err != nil { 142 142 return err 143 143 }
+1 -1
gen/main.go
··· 16 16 panic(err) 17 17 } 18 18 19 - if err := cbg.WriteMapEncodersToFile("api/cbor_gen.go", "api", api.PostRecord{}, api.PostEntity{}, api.PostRef{}, api.ReplyRef{}); err != nil { 19 + if err := cbg.WriteMapEncodersToFile("api/cbor_gen.go", "api", api.PostRecord{}, api.PostEntity{}, api.PostRef{}, api.ReplyRef{}, api.TextSlice{}); err != nil { 20 20 panic(err) 21 21 } 22 22 }
+4 -3
lex/gen.go
··· 65 65 66 66 func (s *Schema) Name() string { 67 67 p := strings.Split(s.ID, ".") 68 - return p[len(p)-1] 68 + return p[len(p)-2] + p[len(p)-1] 69 69 } 70 70 71 71 type outputType struct { ··· 144 144 fmt.Fprintf(buf, "\t\"github.com/whyrusleeping/gosky/xrpc\"\n") 145 145 fmt.Fprintf(buf, "\t\"github.com/whyrusleeping/gosky/lex/util\"\n") 146 146 fmt.Fprintf(buf, ")\n\n") 147 + fmt.Fprintf(buf, "// schema: %s\n\n", s.ID) 147 148 148 149 tps := s.AllTypes(prefix) 149 150 ··· 486 487 returndef := "error" 487 488 if s.Output != nil { 488 489 assign = "out, handleErr" 489 - fmt.Fprintf(w, "var out %s.%s\n", impname, tname+"_Output") 490 + fmt.Fprintf(w, "var out *%s.%s\n", impname, tname+"_Output") 490 491 returndef = fmt.Sprintf("(*%s.%s_Output, error)", impname, tname) 491 492 } 492 493 fmt.Fprintf(w, "var handleErr error\n") ··· 494 495 fmt.Fprintf(w, "%s = s.handle%s(%s)\n", assign, fname, strings.Join(params, ",")) 495 496 fmt.Fprintf(w, "if handleErr != nil {\nreturn handleErr\n}\n") 496 497 497 - fmt.Fprintf(w, "return nil // TODO: implement me\n}\n\n") 498 + fmt.Fprintf(w, "return c.JSON(200, out)\n}\n\n") 498 499 499 500 return nil 500 501 }
+4 -4
mst/cbor_gen.go
··· 251 251 return xerrors.Errorf("failed to write cid field t.V: %w", err) 252 252 } 253 253 254 - // t.T (cid.Cid) (struct) 254 + // t.Tree (cid.Cid) (struct) 255 255 if len("t") > cbg.MaxLength { 256 256 return xerrors.Errorf("Value in field \"t\" was too long") 257 257 } ··· 269 269 } 270 270 } else { 271 271 if err := cbg.WriteCid(cw, *t.Tree); err != nil { 272 - return xerrors.Errorf("failed to write cid field t.T: %w", err) 272 + return xerrors.Errorf("failed to write cid field t.Tree: %w", err) 273 273 } 274 274 } 275 275 ··· 364 364 t.V = c 365 365 366 366 } 367 - // t.T (cid.Cid) (struct) 367 + // t.Tree (cid.Cid) (struct) 368 368 case "t": 369 369 370 370 { ··· 380 380 381 381 c, err := cbg.ReadCid(cr) 382 382 if err != nil { 383 - return xerrors.Errorf("failed to read cid field t.T: %w", err) 383 + return xerrors.Errorf("failed to read cid field t.Tree: %w", err) 384 384 } 385 385 386 386 t.Tree = &c