lexicons,api: remove ids from issue/comment lexicons #522

merged
opened by anirudh.fi targeting master from push-wnotmtoqlnvl

This hinders atprotation and is very appview-specific anyway.

Signed-off-by: Anirudh Oppiliappan anirudh@tangled.sh

Changed files
+8 -151
api
appview
issues
lexicons
+2 -122
api/tangled/cbor_gen.go
···
cw := cbg.NewCborWriter(w)
-
fieldCount := 7
+
fieldCount := 6
if t.Body == nil {
fieldCount--
···
return err
-
// t.IssueId (int64) (int64)
-
if len("issueId") > 1000000 {
-
return xerrors.Errorf("Value in field \"issueId\" was too long")
-
}
-
-
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("issueId"))); err != nil {
-
return err
-
}
-
if _, err := cw.WriteString(string("issueId")); err != nil {
-
return err
-
}
-
-
if t.IssueId >= 0 {
-
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.IssueId)); err != nil {
-
return err
-
}
-
} else {
-
if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.IssueId-1)); err != nil {
-
return err
-
}
-
}
-
// t.CreatedAt (string) (string)
if len("createdAt") > 1000000 {
return xerrors.Errorf("Value in field \"createdAt\" was too long")
···
t.Title = string(sval)
-
// t.IssueId (int64) (int64)
-
case "issueId":
-
{
-
maj, extra, err := cr.ReadHeader()
-
if err != nil {
-
return err
-
}
-
var extraI int64
-
switch maj {
-
case cbg.MajUnsignedInt:
-
extraI = int64(extra)
-
if extraI < 0 {
-
return fmt.Errorf("int64 positive overflow")
-
}
-
case cbg.MajNegativeInt:
-
extraI = int64(extra)
-
if extraI < 0 {
-
return fmt.Errorf("int64 negative overflow")
-
}
-
extraI = -1 - extraI
-
default:
-
return fmt.Errorf("wrong type for int64 field: %d", maj)
-
}
-
-
t.IssueId = int64(extraI)
-
}
// t.CreatedAt (string) (string)
case "createdAt":
···
cw := cbg.NewCborWriter(w)
-
fieldCount := 7
-
-
if t.CommentId == nil {
-
fieldCount--
-
}
+
fieldCount := 6
if t.Owner == nil {
fieldCount--
···
-
// t.CommentId (int64) (int64)
-
if t.CommentId != nil {
-
-
if len("commentId") > 1000000 {
-
return xerrors.Errorf("Value in field \"commentId\" was too long")
-
}
-
-
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("commentId"))); err != nil {
-
return err
-
}
-
if _, err := cw.WriteString(string("commentId")); err != nil {
-
return err
-
}
-
-
if t.CommentId == nil {
-
if _, err := cw.Write(cbg.CborNull); err != nil {
-
return err
-
}
-
} else {
-
if *t.CommentId >= 0 {
-
if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(*t.CommentId)); err != nil {
-
return err
-
}
-
} else {
-
if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-*t.CommentId-1)); err != nil {
-
return err
-
}
-
}
-
}
-
-
}
-
// t.CreatedAt (string) (string)
if len("createdAt") > 1000000 {
return xerrors.Errorf("Value in field \"createdAt\" was too long")
···
t.Owner = (*string)(&sval)
-
// t.CommentId (int64) (int64)
-
case "commentId":
-
{
-
-
b, err := cr.ReadByte()
-
if err != nil {
-
return err
-
}
-
if b != cbg.CborNull[0] {
-
if err := cr.UnreadByte(); err != nil {
-
return err
-
}
-
maj, extra, err := cr.ReadHeader()
-
if err != nil {
-
return err
-
}
-
var extraI int64
-
switch maj {
-
case cbg.MajUnsignedInt:
-
extraI = int64(extra)
-
if extraI < 0 {
-
return fmt.Errorf("int64 positive overflow")
-
}
-
case cbg.MajNegativeInt:
-
extraI = int64(extra)
-
if extraI < 0 {
-
return fmt.Errorf("int64 negative overflow")
-
}
-
extraI = -1 - extraI
-
default:
-
return fmt.Errorf("wrong type for int64 field: %d", maj)
-
}
-
-
t.CommentId = (*int64)(&extraI)
-
}
-
}
// t.CreatedAt (string) (string)
case "createdAt":
-1
api/tangled/issuecomment.go
···
type RepoIssueComment struct {
LexiconTypeID string `json:"$type,const=sh.tangled.repo.issue.comment" cborgen:"$type,const=sh.tangled.repo.issue.comment"`
Body string `json:"body" cborgen:"body"`
-
CommentId *int64 `json:"commentId,omitempty" cborgen:"commentId,omitempty"`
CreatedAt string `json:"createdAt" cborgen:"createdAt"`
Issue string `json:"issue" cborgen:"issue"`
Owner *string `json:"owner,omitempty" cborgen:"owner,omitempty"`
-1
api/tangled/repoissue.go
···
LexiconTypeID string `json:"$type,const=sh.tangled.repo.issue" cborgen:"$type,const=sh.tangled.repo.issue"`
Body *string `json:"body,omitempty" cborgen:"body,omitempty"`
CreatedAt string `json:"createdAt" cborgen:"createdAt"`
-
IssueId int64 `json:"issueId" cborgen:"issueId"`
Owner string `json:"owner" cborgen:"owner"`
Repo string `json:"repo" cborgen:"repo"`
Title string `json:"title" cborgen:"title"`
+4 -9
appview/issues/issues.go
···
}
createdAt := time.Now().Format(time.RFC3339)
-
commentIdInt64 := int64(commentId)
ownerDid := user.Did
issueAt, err := db.GetIssueAt(rp.db, f.RepoAt(), issueIdInt)
if err != nil {
···
Val: &tangled.RepoIssueComment{
Repo: &atUri,
Issue: issueAt,
-
CommentId: &commentIdInt64,
Owner: &ownerDid,
Body: body,
CreatedAt: createdAt,
···
repoAt := record["repo"].(string)
issueAt := record["issue"].(string)
createdAt := record["createdAt"].(string)
-
commentIdInt64 := int64(commentIdInt)
_, err = client.RepoPutRecord(r.Context(), &comatproto.RepoPutRecord_Input{
Collection: tangled.RepoIssueCommentNSID,
···
Val: &tangled.RepoIssueComment{
Repo: &repoAt,
Issue: issueAt,
-
CommentId: &commentIdInt64,
Owner: &comment.OwnerDid,
Body: newBody,
CreatedAt: createdAt,
···
Rkey: issue.Rkey,
Record: &lexutil.LexiconTypeDecoder{
Val: &tangled.RepoIssue{
-
Repo: atUri,
-
Title: title,
-
Body: &body,
-
Owner: user.Did,
-
IssueId: int64(issue.IssueId),
+
Repo: atUri,
+
Title: title,
+
Body: &body,
+
Owner: user.Did,
},
},
})
+1 -8
lexicons/issue/comment.json
···
"key": "tid",
"record": {
"type": "object",
-
"required": [
-
"issue",
-
"body",
-
"createdAt"
-
],
+
"required": ["issue", "body", "createdAt"],
"properties": {
"issue": {
"type": "string",
···
"type": "string",
"format": "at-uri"
},
-
"commentId": {
-
"type": "integer"
-
},
"owner": {
"type": "string",
"format": "did"
+1 -10
lexicons/issue/issue.json
···
"key": "tid",
"record": {
"type": "object",
-
"required": [
-
"repo",
-
"issueId",
-
"owner",
-
"title",
-
"createdAt"
-
],
+
"required": ["repo", "owner", "title", "createdAt"],
"properties": {
"repo": {
"type": "string",
"format": "at-uri"
},
-
"issueId": {
-
"type": "integer"
-
},
"owner": {
"type": "string",
"format": "did"