diff --git a/HACKING.md b/HACKING.md index ba7acd5d6..b831afea5 100644 --- a/HACKING.md +++ b/HACKING.md @@ -63,11 +63,11 @@ Other: go run ./gen To run codegen for new or updated Lexicons, using lexgen, first place (or git -checout) the JSON lexicon files `$SOMEWHERE`. Also, install the `goimports` +checout) the JSON lexicon files at `../atproto/`. Also, install the `goimports` tool. Then, in *this* repository (indigo), run commands like: - go run ./cmd/lexgen/ --package bsky --prefix app.bsky --outdir api/bsky $SOMEWHERE/lexicons/app/bsky/ - go run ./cmd/lexgen/ --package atproto --prefix com.atproto --outdir api/atproto $SOMEWHERE/lexicons/com/atproto/ + go run ./cmd/lexgen/ --package bsky --prefix app.bsky --outdir api/bsky ../atproto/lexicons/app/bsky/ + go run ./cmd/lexgen/ --package atproto --prefix com.atproto --outdir api/atproto ../atproto/lexicons/com/atproto/ You may want to delete all the codegen files before re-generating, to detect deleted files. @@ -76,10 +76,8 @@ It can require some manual munging between the lexgen step and a later `go run . To generate server stubs and handlers, push them in a temporary directory first, then merge changes in to the actual PDS code: - go run ./cmd/lexgen/ --package pds --gen-server --types-import com.atproto:github.com/bluesky-social/indigo/api/atproto --types-import app.bsky:github.com/bluesky-social/indigo/api/bsky --outdir pds $SOMEWHERE/lexicons - mkdir tmppds - go run ./cmd/lexgen/ --package pds --gen-server --types-import com.atproto:github.com/bluesky-social/indigo/api/atproto --types-import app.bsky:github.com/bluesky-social/indigo/api/bsky --outdir tmppds --gen-handlers $SOMEWHERE/lexicons + go run ./cmd/lexgen/ --package pds --gen-server --types-import com.atproto:github.com/bluesky-social/indigo/api/atproto --types-import app.bsky:github.com/bluesky-social/indigo/api/bsky --outdir tmppds --gen-handlers ../atproto/lexicons ## tips and tricks diff --git a/api/atproto/accountcreateInviteCode.go b/api/atproto/accountcreateInviteCode.go deleted file mode 100644 index da4bb90fb..000000000 --- a/api/atproto/accountcreateInviteCode.go +++ /dev/null @@ -1,31 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.account.createInviteCode - -func init() { -} - -type AccountCreateInviteCode_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - UseCount int64 `json:"useCount" cborgen:"useCount"` -} - -type AccountCreateInviteCode_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Code string `json:"code" cborgen:"code"` -} - -func AccountCreateInviteCode(ctx context.Context, c *xrpc.Client, input *AccountCreateInviteCode_Input) (*AccountCreateInviteCode_Output, error) { - var out AccountCreateInviteCode_Output - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.account.createInviteCode", nil, input, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/atproto/accountget.go b/api/atproto/accountget.go deleted file mode 100644 index 32ebf3283..000000000 --- a/api/atproto/accountget.go +++ /dev/null @@ -1,19 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.account.get - -func init() { -} -func AccountGet(ctx context.Context, c *xrpc.Client) error { - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.account.get", nil, nil, nil); err != nil { - return err - } - - return nil -} diff --git a/api/atproto/accountrequestDelete.go b/api/atproto/accountrequestDelete.go deleted file mode 100644 index 9922f1a38..000000000 --- a/api/atproto/accountrequestDelete.go +++ /dev/null @@ -1,19 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.account.requestDelete - -func init() { -} -func AccountRequestDelete(ctx context.Context, c *xrpc.Client) error { - if err := c.Do(ctx, xrpc.Procedure, "", "com.atproto.account.requestDelete", nil, nil, nil); err != nil { - return err - } - - return nil -} diff --git a/api/atproto/accountrequestPasswordReset.go b/api/atproto/accountrequestPasswordReset.go deleted file mode 100644 index d3b741545..000000000 --- a/api/atproto/accountrequestPasswordReset.go +++ /dev/null @@ -1,25 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.account.requestPasswordReset - -func init() { -} - -type AccountRequestPasswordReset_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Email string `json:"email" cborgen:"email"` -} - -func AccountRequestPasswordReset(ctx context.Context, c *xrpc.Client, input *AccountRequestPasswordReset_Input) error { - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.account.requestPasswordReset", nil, input, nil); err != nil { - return err - } - - return nil -} diff --git a/api/atproto/accountresetPassword.go b/api/atproto/accountresetPassword.go deleted file mode 100644 index e2c0f8b5c..000000000 --- a/api/atproto/accountresetPassword.go +++ /dev/null @@ -1,26 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.account.resetPassword - -func init() { -} - -type AccountResetPassword_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Password string `json:"password" cborgen:"password"` - Token string `json:"token" cborgen:"token"` -} - -func AccountResetPassword(ctx context.Context, c *xrpc.Client, input *AccountResetPassword_Input) error { - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.account.resetPassword", nil, input, nil); err != nil { - return err - } - - return nil -} diff --git a/api/atproto/adminblob.go b/api/atproto/adminblob.go deleted file mode 100644 index 6bfad3c40..000000000 --- a/api/atproto/adminblob.go +++ /dev/null @@ -1,76 +0,0 @@ -package atproto - -import ( - "encoding/json" - "fmt" - - "github.com/bluesky-social/indigo/lex/util" -) - -// schema: com.atproto.admin.blob - -func init() { -} - -type AdminBlob_ImageDetails struct { - LexiconTypeID string `json:"$type,omitempty"` - Height int64 `json:"height" cborgen:"height"` - Width int64 `json:"width" cborgen:"width"` -} - -type AdminBlob_Moderation struct { - LexiconTypeID string `json:"$type,omitempty"` - CurrentAction *AdminModerationAction_ViewCurrent `json:"currentAction,omitempty" cborgen:"currentAction"` -} - -type AdminBlob_VideoDetails struct { - LexiconTypeID string `json:"$type,omitempty"` - Height int64 `json:"height" cborgen:"height"` - Length int64 `json:"length" cborgen:"length"` - Width int64 `json:"width" cborgen:"width"` -} - -type AdminBlob_View struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid string `json:"cid" cborgen:"cid"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Details *AdminBlob_View_Details `json:"details,omitempty" cborgen:"details"` - MimeType string `json:"mimeType" cborgen:"mimeType"` - Moderation *AdminBlob_Moderation `json:"moderation,omitempty" cborgen:"moderation"` - Size int64 `json:"size" cborgen:"size"` -} - -type AdminBlob_View_Details struct { - AdminBlob_ImageDetails *AdminBlob_ImageDetails - AdminBlob_VideoDetails *AdminBlob_VideoDetails -} - -func (t *AdminBlob_View_Details) MarshalJSON() ([]byte, error) { - if t.AdminBlob_ImageDetails != nil { - t.AdminBlob_ImageDetails.LexiconTypeID = "com.atproto.admin.blob#imageDetails" - return json.Marshal(t.AdminBlob_ImageDetails) - } - if t.AdminBlob_VideoDetails != nil { - t.AdminBlob_VideoDetails.LexiconTypeID = "com.atproto.admin.blob#videoDetails" - return json.Marshal(t.AdminBlob_VideoDetails) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *AdminBlob_View_Details) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "com.atproto.admin.blob#imageDetails": - t.AdminBlob_ImageDetails = new(AdminBlob_ImageDetails) - return json.Unmarshal(b, t.AdminBlob_ImageDetails) - case "com.atproto.admin.blob#videoDetails": - t.AdminBlob_VideoDetails = new(AdminBlob_VideoDetails) - return json.Unmarshal(b, t.AdminBlob_VideoDetails) - - default: - return nil - } -} diff --git a/api/atproto/admindefs.go b/api/atproto/admindefs.go new file mode 100644 index 000000000..c52e0d230 --- /dev/null +++ b/api/atproto/admindefs.go @@ -0,0 +1,331 @@ +package atproto + +import ( + "encoding/json" + "fmt" + + "github.com/bluesky-social/indigo/lex/util" +) + +// schema: com.atproto.admin.defs + +func init() { +} + +type AdminDefs_ActionReversal struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + CreatedBy string `json:"createdBy" cborgen:"createdBy"` + Reason string `json:"reason" cborgen:"reason"` +} + +type AdminDefs_ActionView struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Action *string `json:"action" cborgen:"action"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + CreatedBy string `json:"createdBy" cborgen:"createdBy"` + Id int64 `json:"id" cborgen:"id"` + Reason string `json:"reason" cborgen:"reason"` + ResolvedReportIds []int64 `json:"resolvedReportIds" cborgen:"resolvedReportIds"` + Reversal *AdminDefs_ActionReversal `json:"reversal,omitempty" cborgen:"reversal,omitempty"` + Subject *AdminDefs_ActionView_Subject `json:"subject" cborgen:"subject"` + SubjectBlobCids []string `json:"subjectBlobCids" cborgen:"subjectBlobCids"` +} + +type AdminDefs_ActionViewCurrent struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Action *string `json:"action" cborgen:"action"` + Id int64 `json:"id" cborgen:"id"` +} + +type AdminDefs_ActionViewDetail struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Action *string `json:"action" cborgen:"action"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + CreatedBy string `json:"createdBy" cborgen:"createdBy"` + Id int64 `json:"id" cborgen:"id"` + Reason string `json:"reason" cborgen:"reason"` + ResolvedReports []*AdminDefs_ReportView `json:"resolvedReports" cborgen:"resolvedReports"` + Reversal *AdminDefs_ActionReversal `json:"reversal,omitempty" cborgen:"reversal,omitempty"` + Subject *AdminDefs_ActionViewDetail_Subject `json:"subject" cborgen:"subject"` + SubjectBlobs []*AdminDefs_BlobView `json:"subjectBlobs" cborgen:"subjectBlobs"` +} + +type AdminDefs_ActionViewDetail_Subject struct { + AdminDefs_RepoView *AdminDefs_RepoView + AdminDefs_RecordView *AdminDefs_RecordView +} + +func (t *AdminDefs_ActionViewDetail_Subject) MarshalJSON() ([]byte, error) { + if t.AdminDefs_RepoView != nil { + t.AdminDefs_RepoView.LexiconTypeID = "com.atproto.admin.defs#repoView" + return json.Marshal(t.AdminDefs_RepoView) + } + if t.AdminDefs_RecordView != nil { + t.AdminDefs_RecordView.LexiconTypeID = "com.atproto.admin.defs#recordView" + return json.Marshal(t.AdminDefs_RecordView) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *AdminDefs_ActionViewDetail_Subject) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.admin.defs#repoView": + t.AdminDefs_RepoView = new(AdminDefs_RepoView) + return json.Unmarshal(b, t.AdminDefs_RepoView) + case "com.atproto.admin.defs#recordView": + t.AdminDefs_RecordView = new(AdminDefs_RecordView) + return json.Unmarshal(b, t.AdminDefs_RecordView) + + default: + return nil + } +} + +type AdminDefs_ActionView_Subject struct { + AdminDefs_RepoRef *AdminDefs_RepoRef + RepoStrongRef *RepoStrongRef +} + +func (t *AdminDefs_ActionView_Subject) MarshalJSON() ([]byte, error) { + if t.AdminDefs_RepoRef != nil { + t.AdminDefs_RepoRef.LexiconTypeID = "com.atproto.admin.defs#repoRef" + return json.Marshal(t.AdminDefs_RepoRef) + } + if t.RepoStrongRef != nil { + t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef" + return json.Marshal(t.RepoStrongRef) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *AdminDefs_ActionView_Subject) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.admin.defs#repoRef": + t.AdminDefs_RepoRef = new(AdminDefs_RepoRef) + return json.Unmarshal(b, t.AdminDefs_RepoRef) + case "com.atproto.repo.strongRef": + t.RepoStrongRef = new(RepoStrongRef) + return json.Unmarshal(b, t.RepoStrongRef) + + default: + return nil + } +} + +type AdminDefs_BlobView struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cid string `json:"cid" cborgen:"cid"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Details *AdminDefs_BlobView_Details `json:"details,omitempty" cborgen:"details,omitempty"` + MimeType string `json:"mimeType" cborgen:"mimeType"` + Moderation *AdminDefs_Moderation `json:"moderation,omitempty" cborgen:"moderation,omitempty"` + Size int64 `json:"size" cborgen:"size"` +} + +type AdminDefs_BlobView_Details struct { + AdminDefs_ImageDetails *AdminDefs_ImageDetails + AdminDefs_VideoDetails *AdminDefs_VideoDetails +} + +func (t *AdminDefs_BlobView_Details) MarshalJSON() ([]byte, error) { + if t.AdminDefs_ImageDetails != nil { + t.AdminDefs_ImageDetails.LexiconTypeID = "com.atproto.admin.defs#imageDetails" + return json.Marshal(t.AdminDefs_ImageDetails) + } + if t.AdminDefs_VideoDetails != nil { + t.AdminDefs_VideoDetails.LexiconTypeID = "com.atproto.admin.defs#videoDetails" + return json.Marshal(t.AdminDefs_VideoDetails) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *AdminDefs_BlobView_Details) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.admin.defs#imageDetails": + t.AdminDefs_ImageDetails = new(AdminDefs_ImageDetails) + return json.Unmarshal(b, t.AdminDefs_ImageDetails) + case "com.atproto.admin.defs#videoDetails": + t.AdminDefs_VideoDetails = new(AdminDefs_VideoDetails) + return json.Unmarshal(b, t.AdminDefs_VideoDetails) + + default: + return nil + } +} + +type AdminDefs_ImageDetails struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Height int64 `json:"height" cborgen:"height"` + Width int64 `json:"width" cborgen:"width"` +} + +type AdminDefs_Moderation struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + CurrentAction *AdminDefs_ActionViewCurrent `json:"currentAction,omitempty" cborgen:"currentAction,omitempty"` +} + +type AdminDefs_ModerationDetail struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Actions []*AdminDefs_ActionView `json:"actions" cborgen:"actions"` + CurrentAction *AdminDefs_ActionViewCurrent `json:"currentAction,omitempty" cborgen:"currentAction,omitempty"` + Reports []*AdminDefs_ReportView `json:"reports" cborgen:"reports"` +} + +type AdminDefs_RecordView struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + BlobCids []string `json:"blobCids" cborgen:"blobCids"` + Cid string `json:"cid" cborgen:"cid"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` + Moderation *AdminDefs_Moderation `json:"moderation" cborgen:"moderation"` + Repo *AdminDefs_RepoView `json:"repo" cborgen:"repo"` + Uri string `json:"uri" cborgen:"uri"` + Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` +} + +type AdminDefs_RecordViewDetail struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Blobs []*AdminDefs_BlobView `json:"blobs" cborgen:"blobs"` + Cid string `json:"cid" cborgen:"cid"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` + Moderation *AdminDefs_ModerationDetail `json:"moderation" cborgen:"moderation"` + Repo *AdminDefs_RepoView `json:"repo" cborgen:"repo"` + Uri string `json:"uri" cborgen:"uri"` + Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` +} + +type AdminDefs_RepoRef struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Did string `json:"did" cborgen:"did"` +} + +type AdminDefs_RepoView struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Did string `json:"did" cborgen:"did"` + Email *string `json:"email,omitempty" cborgen:"email,omitempty"` + Handle string `json:"handle" cborgen:"handle"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` + Moderation *AdminDefs_Moderation `json:"moderation" cborgen:"moderation"` + RelatedRecords []*util.LexiconTypeDecoder `json:"relatedRecords" cborgen:"relatedRecords"` +} + +type AdminDefs_RepoViewDetail struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Did string `json:"did" cborgen:"did"` + Email *string `json:"email,omitempty" cborgen:"email,omitempty"` + Handle string `json:"handle" cborgen:"handle"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` + Moderation *AdminDefs_ModerationDetail `json:"moderation" cborgen:"moderation"` + RelatedRecords []*util.LexiconTypeDecoder `json:"relatedRecords" cborgen:"relatedRecords"` +} + +type AdminDefs_ReportView struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Id int64 `json:"id" cborgen:"id"` + Reason *string `json:"reason,omitempty" cborgen:"reason,omitempty"` + ReasonType *string `json:"reasonType" cborgen:"reasonType"` + ReportedBy string `json:"reportedBy" cborgen:"reportedBy"` + ResolvedByActionIds []int64 `json:"resolvedByActionIds" cborgen:"resolvedByActionIds"` + Subject *AdminDefs_ReportView_Subject `json:"subject" cborgen:"subject"` +} + +type AdminDefs_ReportViewDetail struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Id int64 `json:"id" cborgen:"id"` + Reason *string `json:"reason,omitempty" cborgen:"reason,omitempty"` + ReasonType *string `json:"reasonType" cborgen:"reasonType"` + ReportedBy string `json:"reportedBy" cborgen:"reportedBy"` + ResolvedByActions []*AdminDefs_ActionView `json:"resolvedByActions" cborgen:"resolvedByActions"` + Subject *AdminDefs_ReportViewDetail_Subject `json:"subject" cborgen:"subject"` +} + +type AdminDefs_ReportViewDetail_Subject struct { + AdminDefs_RepoView *AdminDefs_RepoView + AdminDefs_RecordView *AdminDefs_RecordView +} + +func (t *AdminDefs_ReportViewDetail_Subject) MarshalJSON() ([]byte, error) { + if t.AdminDefs_RepoView != nil { + t.AdminDefs_RepoView.LexiconTypeID = "com.atproto.admin.defs#repoView" + return json.Marshal(t.AdminDefs_RepoView) + } + if t.AdminDefs_RecordView != nil { + t.AdminDefs_RecordView.LexiconTypeID = "com.atproto.admin.defs#recordView" + return json.Marshal(t.AdminDefs_RecordView) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *AdminDefs_ReportViewDetail_Subject) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.admin.defs#repoView": + t.AdminDefs_RepoView = new(AdminDefs_RepoView) + return json.Unmarshal(b, t.AdminDefs_RepoView) + case "com.atproto.admin.defs#recordView": + t.AdminDefs_RecordView = new(AdminDefs_RecordView) + return json.Unmarshal(b, t.AdminDefs_RecordView) + + default: + return nil + } +} + +type AdminDefs_ReportView_Subject struct { + AdminDefs_RepoRef *AdminDefs_RepoRef + RepoStrongRef *RepoStrongRef +} + +func (t *AdminDefs_ReportView_Subject) MarshalJSON() ([]byte, error) { + if t.AdminDefs_RepoRef != nil { + t.AdminDefs_RepoRef.LexiconTypeID = "com.atproto.admin.defs#repoRef" + return json.Marshal(t.AdminDefs_RepoRef) + } + if t.RepoStrongRef != nil { + t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef" + return json.Marshal(t.RepoStrongRef) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *AdminDefs_ReportView_Subject) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.admin.defs#repoRef": + t.AdminDefs_RepoRef = new(AdminDefs_RepoRef) + return json.Unmarshal(b, t.AdminDefs_RepoRef) + case "com.atproto.repo.strongRef": + t.RepoStrongRef = new(RepoStrongRef) + return json.Unmarshal(b, t.RepoStrongRef) + + default: + return nil + } +} + +type AdminDefs_VideoDetails struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Height int64 `json:"height" cborgen:"height"` + Length int64 `json:"length" cborgen:"length"` + Width int64 `json:"width" cborgen:"width"` +} diff --git a/api/atproto/admingetModerationAction.go b/api/atproto/admingetModerationAction.go index 2ce487bb3..1dc31a742 100644 --- a/api/atproto/admingetModerationAction.go +++ b/api/atproto/admingetModerationAction.go @@ -10,8 +10,8 @@ import ( func init() { } -func AdminGetModerationAction(ctx context.Context, c *xrpc.Client, id int64) (*AdminModerationAction_ViewDetail, error) { - var out AdminModerationAction_ViewDetail +func AdminGetModerationAction(ctx context.Context, c *xrpc.Client, id int64) (*AdminDefs_ActionViewDetail, error) { + var out AdminDefs_ActionViewDetail params := map[string]interface{}{ "id": id, diff --git a/api/atproto/admingetModerationActions.go b/api/atproto/admingetModerationActions.go index e7e195486..ba46ea8f6 100644 --- a/api/atproto/admingetModerationActions.go +++ b/api/atproto/admingetModerationActions.go @@ -12,16 +12,16 @@ func init() { } type AdminGetModerationActions_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Actions []*AdminModerationAction_View `json:"actions" cborgen:"actions"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Actions []*AdminDefs_ActionView `json:"actions" cborgen:"actions"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` } -func AdminGetModerationActions(ctx context.Context, c *xrpc.Client, before string, limit int64, subject string) (*AdminGetModerationActions_Output, error) { +func AdminGetModerationActions(ctx context.Context, c *xrpc.Client, cursor string, limit int64, subject string) (*AdminGetModerationActions_Output, error) { var out AdminGetModerationActions_Output params := map[string]interface{}{ - "before": before, + "cursor": cursor, "limit": limit, "subject": subject, } diff --git a/api/atproto/admingetModerationReport.go b/api/atproto/admingetModerationReport.go index aeb607492..6f6444889 100644 --- a/api/atproto/admingetModerationReport.go +++ b/api/atproto/admingetModerationReport.go @@ -10,8 +10,8 @@ import ( func init() { } -func AdminGetModerationReport(ctx context.Context, c *xrpc.Client, id int64) (*AdminModerationReport_ViewDetail, error) { - var out AdminModerationReport_ViewDetail +func AdminGetModerationReport(ctx context.Context, c *xrpc.Client, id int64) (*AdminDefs_ReportViewDetail, error) { + var out AdminDefs_ReportViewDetail params := map[string]interface{}{ "id": id, diff --git a/api/atproto/admingetModerationReports.go b/api/atproto/admingetModerationReports.go index 80c5988d0..42ae249e9 100644 --- a/api/atproto/admingetModerationReports.go +++ b/api/atproto/admingetModerationReports.go @@ -12,16 +12,16 @@ func init() { } type AdminGetModerationReports_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Reports []*AdminModerationReport_View `json:"reports" cborgen:"reports"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Reports []*AdminDefs_ReportView `json:"reports" cborgen:"reports"` } -func AdminGetModerationReports(ctx context.Context, c *xrpc.Client, before string, limit int64, resolved bool, subject string) (*AdminGetModerationReports_Output, error) { +func AdminGetModerationReports(ctx context.Context, c *xrpc.Client, cursor string, limit int64, resolved bool, subject string) (*AdminGetModerationReports_Output, error) { var out AdminGetModerationReports_Output params := map[string]interface{}{ - "before": before, + "cursor": cursor, "limit": limit, "resolved": resolved, "subject": subject, diff --git a/api/atproto/admingetRecord.go b/api/atproto/admingetRecord.go index f8b5628ee..eb8e236b7 100644 --- a/api/atproto/admingetRecord.go +++ b/api/atproto/admingetRecord.go @@ -10,8 +10,8 @@ import ( func init() { } -func AdminGetRecord(ctx context.Context, c *xrpc.Client, cid string, uri string) (*AdminRecord_ViewDetail, error) { - var out AdminRecord_ViewDetail +func AdminGetRecord(ctx context.Context, c *xrpc.Client, cid string, uri string) (*AdminDefs_RecordViewDetail, error) { + var out AdminDefs_RecordViewDetail params := map[string]interface{}{ "cid": cid, diff --git a/api/atproto/admingetRepo.go b/api/atproto/admingetRepo.go index 0892b5279..cd9914fec 100644 --- a/api/atproto/admingetRepo.go +++ b/api/atproto/admingetRepo.go @@ -10,8 +10,8 @@ import ( func init() { } -func AdminGetRepo(ctx context.Context, c *xrpc.Client, did string) (*AdminRepo_ViewDetail, error) { - var out AdminRepo_ViewDetail +func AdminGetRepo(ctx context.Context, c *xrpc.Client, did string) (*AdminDefs_RepoViewDetail, error) { + var out AdminDefs_RepoViewDetail params := map[string]interface{}{ "did": did, diff --git a/api/atproto/adminmoderationAction.go b/api/atproto/adminmoderationAction.go deleted file mode 100644 index be478830d..000000000 --- a/api/atproto/adminmoderationAction.go +++ /dev/null @@ -1,122 +0,0 @@ -package atproto - -import ( - "encoding/json" - "fmt" - - "github.com/bluesky-social/indigo/lex/util" -) - -// schema: com.atproto.admin.moderationAction - -func init() { -} - -type AdminModerationAction_Reversal struct { - LexiconTypeID string `json:"$type,omitempty"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - CreatedBy string `json:"createdBy" cborgen:"createdBy"` - Reason string `json:"reason" cborgen:"reason"` -} - -type AdminModerationAction_View struct { - LexiconTypeID string `json:"$type,omitempty"` - Action *string `json:"action" cborgen:"action"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - CreatedBy string `json:"createdBy" cborgen:"createdBy"` - Id int64 `json:"id" cborgen:"id"` - Reason string `json:"reason" cborgen:"reason"` - ResolvedReportIds []int64 `json:"resolvedReportIds" cborgen:"resolvedReportIds"` - Reversal *AdminModerationAction_Reversal `json:"reversal,omitempty" cborgen:"reversal"` - Subject *AdminModerationAction_View_Subject `json:"subject" cborgen:"subject"` - SubjectBlobCids []string `json:"subjectBlobCids" cborgen:"subjectBlobCids"` -} - -type AdminModerationAction_ViewCurrent struct { - LexiconTypeID string `json:"$type,omitempty"` - Action *string `json:"action" cborgen:"action"` - Id int64 `json:"id" cborgen:"id"` -} - -type AdminModerationAction_ViewDetail struct { - LexiconTypeID string `json:"$type,omitempty"` - Action *string `json:"action" cborgen:"action"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - CreatedBy string `json:"createdBy" cborgen:"createdBy"` - Id int64 `json:"id" cborgen:"id"` - Reason string `json:"reason" cborgen:"reason"` - ResolvedReports []*AdminModerationReport_View `json:"resolvedReports" cborgen:"resolvedReports"` - Reversal *AdminModerationAction_Reversal `json:"reversal,omitempty" cborgen:"reversal"` - Subject *AdminModerationAction_ViewDetail_Subject `json:"subject" cborgen:"subject"` - SubjectBlobs []*AdminBlob_View `json:"subjectBlobs" cborgen:"subjectBlobs"` -} - -type AdminModerationAction_ViewDetail_Subject struct { - AdminRepo_View *AdminRepo_View - AdminRecord_View *AdminRecord_View -} - -func (t *AdminModerationAction_ViewDetail_Subject) MarshalJSON() ([]byte, error) { - if t.AdminRepo_View != nil { - t.AdminRepo_View.LexiconTypeID = "com.atproto.admin.repo#view" - return json.Marshal(t.AdminRepo_View) - } - if t.AdminRecord_View != nil { - t.AdminRecord_View.LexiconTypeID = "com.atproto.admin.record#view" - return json.Marshal(t.AdminRecord_View) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *AdminModerationAction_ViewDetail_Subject) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "com.atproto.admin.repo#view": - t.AdminRepo_View = new(AdminRepo_View) - return json.Unmarshal(b, t.AdminRepo_View) - case "com.atproto.admin.record#view": - t.AdminRecord_View = new(AdminRecord_View) - return json.Unmarshal(b, t.AdminRecord_View) - - default: - return nil - } -} - -type AdminModerationAction_View_Subject struct { - RepoRepoRef *RepoRepoRef - RepoStrongRef *RepoStrongRef -} - -func (t *AdminModerationAction_View_Subject) MarshalJSON() ([]byte, error) { - if t.RepoRepoRef != nil { - t.RepoRepoRef.LexiconTypeID = "com.atproto.repo.repoRef" - return json.Marshal(t.RepoRepoRef) - } - if t.RepoStrongRef != nil { - t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef" - return json.Marshal(t.RepoStrongRef) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *AdminModerationAction_View_Subject) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "com.atproto.repo.repoRef": - t.RepoRepoRef = new(RepoRepoRef) - return json.Unmarshal(b, t.RepoRepoRef) - case "com.atproto.repo.strongRef": - t.RepoStrongRef = new(RepoStrongRef) - return json.Unmarshal(b, t.RepoStrongRef) - - default: - return nil - } -} diff --git a/api/atproto/adminmoderationReport.go b/api/atproto/adminmoderationReport.go deleted file mode 100644 index 8c06bf756..000000000 --- a/api/atproto/adminmoderationReport.go +++ /dev/null @@ -1,105 +0,0 @@ -package atproto - -import ( - "encoding/json" - "fmt" - - "github.com/bluesky-social/indigo/lex/util" -) - -// schema: com.atproto.admin.moderationReport - -func init() { -} - -type AdminModerationReport_View struct { - LexiconTypeID string `json:"$type,omitempty"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Id int64 `json:"id" cborgen:"id"` - Reason *string `json:"reason,omitempty" cborgen:"reason"` - ReasonType *string `json:"reasonType" cborgen:"reasonType"` - ReportedByDid string `json:"reportedByDid" cborgen:"reportedByDid"` - ResolvedByActionIds []int64 `json:"resolvedByActionIds" cborgen:"resolvedByActionIds"` - Subject *AdminModerationReport_View_Subject `json:"subject" cborgen:"subject"` -} - -type AdminModerationReport_ViewDetail struct { - LexiconTypeID string `json:"$type,omitempty"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Id int64 `json:"id" cborgen:"id"` - Reason *string `json:"reason,omitempty" cborgen:"reason"` - ReasonType *string `json:"reasonType" cborgen:"reasonType"` - ReportedByDid string `json:"reportedByDid" cborgen:"reportedByDid"` - ResolvedByActions []*AdminModerationAction_View `json:"resolvedByActions" cborgen:"resolvedByActions"` - Subject *AdminModerationReport_ViewDetail_Subject `json:"subject" cborgen:"subject"` -} - -type AdminModerationReport_ViewDetail_Subject struct { - AdminRepo_View *AdminRepo_View - AdminRecord_View *AdminRecord_View -} - -func (t *AdminModerationReport_ViewDetail_Subject) MarshalJSON() ([]byte, error) { - if t.AdminRepo_View != nil { - t.AdminRepo_View.LexiconTypeID = "com.atproto.admin.repo#view" - return json.Marshal(t.AdminRepo_View) - } - if t.AdminRecord_View != nil { - t.AdminRecord_View.LexiconTypeID = "com.atproto.admin.record#view" - return json.Marshal(t.AdminRecord_View) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *AdminModerationReport_ViewDetail_Subject) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "com.atproto.admin.repo#view": - t.AdminRepo_View = new(AdminRepo_View) - return json.Unmarshal(b, t.AdminRepo_View) - case "com.atproto.admin.record#view": - t.AdminRecord_View = new(AdminRecord_View) - return json.Unmarshal(b, t.AdminRecord_View) - - default: - return nil - } -} - -type AdminModerationReport_View_Subject struct { - RepoRepoRef *RepoRepoRef - RepoStrongRef *RepoStrongRef -} - -func (t *AdminModerationReport_View_Subject) MarshalJSON() ([]byte, error) { - if t.RepoRepoRef != nil { - t.RepoRepoRef.LexiconTypeID = "com.atproto.repo.repoRef" - return json.Marshal(t.RepoRepoRef) - } - if t.RepoStrongRef != nil { - t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef" - return json.Marshal(t.RepoStrongRef) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *AdminModerationReport_View_Subject) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "com.atproto.repo.repoRef": - t.RepoRepoRef = new(RepoRepoRef) - return json.Unmarshal(b, t.RepoRepoRef) - case "com.atproto.repo.strongRef": - t.RepoStrongRef = new(RepoStrongRef) - return json.Unmarshal(b, t.RepoStrongRef) - - default: - return nil - } -} diff --git a/api/atproto/adminrecord.go b/api/atproto/adminrecord.go deleted file mode 100644 index 3b403e375..000000000 --- a/api/atproto/adminrecord.go +++ /dev/null @@ -1,44 +0,0 @@ -package atproto - -import ( - "github.com/bluesky-social/indigo/lex/util" -) - -// schema: com.atproto.admin.record - -func init() { -} - -type AdminRecord_Moderation struct { - LexiconTypeID string `json:"$type,omitempty"` - CurrentAction *AdminModerationAction_ViewCurrent `json:"currentAction,omitempty" cborgen:"currentAction"` -} - -type AdminRecord_ModerationDetail struct { - LexiconTypeID string `json:"$type,omitempty"` - Actions []*AdminModerationAction_View `json:"actions" cborgen:"actions"` - CurrentAction *AdminModerationAction_ViewCurrent `json:"currentAction,omitempty" cborgen:"currentAction"` - Reports []*AdminModerationReport_View `json:"reports" cborgen:"reports"` -} - -type AdminRecord_View struct { - LexiconTypeID string `json:"$type,omitempty"` - BlobCids []string `json:"blobCids" cborgen:"blobCids"` - Cid string `json:"cid" cborgen:"cid"` - IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` - Moderation *AdminRecord_Moderation `json:"moderation" cborgen:"moderation"` - Repo *AdminRepo_View `json:"repo" cborgen:"repo"` - Uri string `json:"uri" cborgen:"uri"` - Value util.LexiconTypeDecoder `json:"value" cborgen:"value"` -} - -type AdminRecord_ViewDetail struct { - LexiconTypeID string `json:"$type,omitempty"` - Blobs []*AdminBlob_View `json:"blobs" cborgen:"blobs"` - Cid string `json:"cid" cborgen:"cid"` - IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` - Moderation *AdminRecord_ModerationDetail `json:"moderation" cborgen:"moderation"` - Repo *AdminRepo_View `json:"repo" cborgen:"repo"` - Uri string `json:"uri" cborgen:"uri"` - Value util.LexiconTypeDecoder `json:"value" cborgen:"value"` -} diff --git a/api/atproto/adminrepo.go b/api/atproto/adminrepo.go deleted file mode 100644 index 7ff67ad3c..000000000 --- a/api/atproto/adminrepo.go +++ /dev/null @@ -1,47 +0,0 @@ -package atproto - -import ( - "github.com/bluesky-social/indigo/lex/util" -) - -// schema: com.atproto.admin.repo - -func init() { -} - -type AdminRepo_Account struct { - LexiconTypeID string `json:"$type,omitempty"` - Email string `json:"email" cborgen:"email"` -} - -type AdminRepo_Moderation struct { - LexiconTypeID string `json:"$type,omitempty"` - CurrentAction *AdminModerationAction_ViewCurrent `json:"currentAction,omitempty" cborgen:"currentAction"` -} - -type AdminRepo_ModerationDetail struct { - LexiconTypeID string `json:"$type,omitempty"` - Actions []*AdminModerationAction_View `json:"actions" cborgen:"actions"` - CurrentAction *AdminModerationAction_ViewCurrent `json:"currentAction,omitempty" cborgen:"currentAction"` - Reports []*AdminModerationReport_View `json:"reports" cborgen:"reports"` -} - -type AdminRepo_View struct { - LexiconTypeID string `json:"$type,omitempty"` - Account *AdminRepo_Account `json:"account,omitempty" cborgen:"account"` - Did string `json:"did" cborgen:"did"` - Handle string `json:"handle" cborgen:"handle"` - IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` - Moderation *AdminRepo_Moderation `json:"moderation" cborgen:"moderation"` - RelatedRecords []util.LexiconTypeDecoder `json:"relatedRecords" cborgen:"relatedRecords"` -} - -type AdminRepo_ViewDetail struct { - LexiconTypeID string `json:"$type,omitempty"` - Account *AdminRepo_Account `json:"account,omitempty" cborgen:"account"` - Did string `json:"did" cborgen:"did"` - Handle string `json:"handle" cborgen:"handle"` - IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` - Moderation *AdminRepo_ModerationDetail `json:"moderation" cborgen:"moderation"` - RelatedRecords []util.LexiconTypeDecoder `json:"relatedRecords" cborgen:"relatedRecords"` -} diff --git a/api/atproto/adminresolveModerationReports.go b/api/atproto/adminresolveModerationReports.go index b52a4f31e..cc860e9b5 100644 --- a/api/atproto/adminresolveModerationReports.go +++ b/api/atproto/adminresolveModerationReports.go @@ -12,14 +12,14 @@ func init() { } type AdminResolveModerationReports_Input struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` ActionId int64 `json:"actionId" cborgen:"actionId"` CreatedBy string `json:"createdBy" cborgen:"createdBy"` ReportIds []int64 `json:"reportIds" cborgen:"reportIds"` } -func AdminResolveModerationReports(ctx context.Context, c *xrpc.Client, input *AdminResolveModerationReports_Input) (*AdminModerationAction_View, error) { - var out AdminModerationAction_View +func AdminResolveModerationReports(ctx context.Context, c *xrpc.Client, input *AdminResolveModerationReports_Input) (*AdminDefs_ActionView, error) { + var out AdminDefs_ActionView if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.admin.resolveModerationReports", nil, input, &out); err != nil { return nil, err } diff --git a/api/atproto/adminreverseModerationAction.go b/api/atproto/adminreverseModerationAction.go index 939e5ca3f..ec7e08f63 100644 --- a/api/atproto/adminreverseModerationAction.go +++ b/api/atproto/adminreverseModerationAction.go @@ -12,14 +12,14 @@ func init() { } type AdminReverseModerationAction_Input struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` CreatedBy string `json:"createdBy" cborgen:"createdBy"` Id int64 `json:"id" cborgen:"id"` Reason string `json:"reason" cborgen:"reason"` } -func AdminReverseModerationAction(ctx context.Context, c *xrpc.Client, input *AdminReverseModerationAction_Input) (*AdminModerationAction_View, error) { - var out AdminModerationAction_View +func AdminReverseModerationAction(ctx context.Context, c *xrpc.Client, input *AdminReverseModerationAction_Input) (*AdminDefs_ActionView, error) { + var out AdminDefs_ActionView if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.admin.reverseModerationAction", nil, input, &out); err != nil { return nil, err } diff --git a/api/atproto/adminsearchRepos.go b/api/atproto/adminsearchRepos.go index ae648967f..993a9246a 100644 --- a/api/atproto/adminsearchRepos.go +++ b/api/atproto/adminsearchRepos.go @@ -12,16 +12,16 @@ func init() { } type AdminSearchRepos_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Repos []*AdminRepo_View `json:"repos" cborgen:"repos"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Repos []*AdminDefs_RepoView `json:"repos" cborgen:"repos"` } -func AdminSearchRepos(ctx context.Context, c *xrpc.Client, before string, limit int64, term string) (*AdminSearchRepos_Output, error) { +func AdminSearchRepos(ctx context.Context, c *xrpc.Client, cursor string, limit int64, term string) (*AdminSearchRepos_Output, error) { var out AdminSearchRepos_Output params := map[string]interface{}{ - "before": before, + "cursor": cursor, "limit": limit, "term": term, } diff --git a/api/atproto/admintakeModerationAction.go b/api/atproto/admintakeModerationAction.go index 5ad83149b..686182a9f 100644 --- a/api/atproto/admintakeModerationAction.go +++ b/api/atproto/admintakeModerationAction.go @@ -15,27 +15,27 @@ func init() { } type AdminTakeModerationAction_Input struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Action string `json:"action" cborgen:"action"` CreatedBy string `json:"createdBy" cborgen:"createdBy"` Reason string `json:"reason" cborgen:"reason"` Subject *AdminTakeModerationAction_Input_Subject `json:"subject" cborgen:"subject"` - SubjectBlobCids []string `json:"subjectBlobCids,omitempty" cborgen:"subjectBlobCids"` + SubjectBlobCids []string `json:"subjectBlobCids,omitempty" cborgen:"subjectBlobCids,omitempty"` } type AdminTakeModerationAction_Input_Subject struct { - RepoRepoRef *RepoRepoRef - RepoRecordRef *RepoRecordRef + AdminDefs_RepoRef *AdminDefs_RepoRef + RepoStrongRef *RepoStrongRef } func (t *AdminTakeModerationAction_Input_Subject) MarshalJSON() ([]byte, error) { - if t.RepoRepoRef != nil { - t.RepoRepoRef.LexiconTypeID = "com.atproto.repo.repoRef" - return json.Marshal(t.RepoRepoRef) + if t.AdminDefs_RepoRef != nil { + t.AdminDefs_RepoRef.LexiconTypeID = "com.atproto.admin.defs#repoRef" + return json.Marshal(t.AdminDefs_RepoRef) } - if t.RepoRecordRef != nil { - t.RepoRecordRef.LexiconTypeID = "com.atproto.repo.recordRef" - return json.Marshal(t.RepoRecordRef) + if t.RepoStrongRef != nil { + t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef" + return json.Marshal(t.RepoStrongRef) } return nil, fmt.Errorf("cannot marshal empty enum") } @@ -46,20 +46,20 @@ func (t *AdminTakeModerationAction_Input_Subject) UnmarshalJSON(b []byte) error } switch typ { - case "com.atproto.repo.repoRef": - t.RepoRepoRef = new(RepoRepoRef) - return json.Unmarshal(b, t.RepoRepoRef) - case "com.atproto.repo.recordRef": - t.RepoRecordRef = new(RepoRecordRef) - return json.Unmarshal(b, t.RepoRecordRef) + case "com.atproto.admin.defs#repoRef": + t.AdminDefs_RepoRef = new(AdminDefs_RepoRef) + return json.Unmarshal(b, t.AdminDefs_RepoRef) + case "com.atproto.repo.strongRef": + t.RepoStrongRef = new(RepoStrongRef) + return json.Unmarshal(b, t.RepoStrongRef) default: return nil } } -func AdminTakeModerationAction(ctx context.Context, c *xrpc.Client, input *AdminTakeModerationAction_Input) (*AdminModerationAction_View, error) { - var out AdminModerationAction_View +func AdminTakeModerationAction(ctx context.Context, c *xrpc.Client, input *AdminTakeModerationAction_Input) (*AdminDefs_ActionView, error) { + var out AdminDefs_ActionView if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.admin.takeModerationAction", nil, input, &out); err != nil { return nil, err } diff --git a/api/atproto/blobupload.go b/api/atproto/blobupload.go deleted file mode 100644 index 883df6f8d..000000000 --- a/api/atproto/blobupload.go +++ /dev/null @@ -1,27 +0,0 @@ -package atproto - -import ( - "context" - "io" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.blob.upload - -func init() { -} - -type BlobUpload_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid string `json:"cid" cborgen:"cid"` -} - -func BlobUpload(ctx context.Context, c *xrpc.Client, input io.Reader) (*BlobUpload_Output, error) { - var out BlobUpload_Output - if err := c.Do(ctx, xrpc.Procedure, "*/*", "com.atproto.blob.upload", nil, input, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/atproto/cbor_gen.go b/api/atproto/cbor_gen.go index 5dfd84020..6e73365f3 100644 --- a/api/atproto/cbor_gen.go +++ b/api/atproto/cbor_gen.go @@ -8,6 +8,7 @@ import ( "math" "sort" + util "github.com/bluesky-social/indigo/lex/util" cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" @@ -25,8 +26,13 @@ func (t *RepoStrongRef) MarshalCBOR(w io.Writer) error { } cw := cbg.NewCborWriter(w) + fieldCount := 3 - if _, err := cw.Write([]byte{163}); err != nil { + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } @@ -77,26 +83,29 @@ func (t *RepoStrongRef) MarshalCBOR(w io.Writer) error { } // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") - } + if t.LexiconTypeID != "" { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { - return err - } + if len("$type") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"$type\" was too long") + } - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") - } + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("$type")); err != nil { + return err + } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { - return err + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } } return nil } @@ -162,7 +171,1654 @@ func (t *RepoStrongRef) UnmarshalCBOR(r io.Reader) (err error) { t.Uri = string(sval) } // t.LexiconTypeID (string) (string) - case "LexiconTypeID": + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *SyncSubscribeRepos_Commit) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 11 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Ops ([]*atproto.SyncSubscribeRepos_RepoOp) (slice) + if len("ops") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"ops\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ops"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("ops")); err != nil { + return err + } + + if len(t.Ops) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Ops was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Ops))); err != nil { + return err + } + for _, v := range t.Ops { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Seq (int64) (int64) + if len("seq") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"seq\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("seq"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("seq")); err != nil { + return err + } + + if t.Seq >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Seq)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Seq-1)); err != nil { + return err + } + } + + // t.Prev (util.LexLink) (struct) + if len("prev") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"prev\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("prev"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("prev")); err != nil { + return err + } + + if err := t.Prev.MarshalCBOR(cw); err != nil { + return err + } + + // t.Repo (string) (string) + if len("repo") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"repo\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repo"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("repo")); err != nil { + return err + } + + if len(t.Repo) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Repo was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repo))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Repo)); err != nil { + return err + } + + // t.Time (string) (string) + if len("time") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"time\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("time"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("time")); err != nil { + return err + } + + if len(t.Time) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Time was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Time))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Time)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + + // t.Blobs ([]util.LexLink) (slice) + if len("blobs") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"blobs\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("blobs"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("blobs")); err != nil { + return err + } + + if len(t.Blobs) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Blobs was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Blobs))); err != nil { + return err + } + for _, v := range t.Blobs { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Blocks (util.LexBytes) (slice) + if len("blocks") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"blocks\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("blocks"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("blocks")); err != nil { + return err + } + + if len(t.Blocks) > cbg.ByteArrayMaxLen { + return xerrors.Errorf("Byte array in field t.Blocks was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Blocks))); err != nil { + return err + } + + if _, err := cw.Write(t.Blocks[:]); err != nil { + return err + } + + // t.Commit (util.LexLink) (struct) + if len("commit") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"commit\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("commit"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("commit")); err != nil { + return err + } + + if err := t.Commit.MarshalCBOR(cw); err != nil { + return err + } + + // t.Rebase (bool) (bool) + if len("rebase") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"rebase\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("rebase"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("rebase")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.Rebase); err != nil { + return err + } + + // t.TooBig (bool) (bool) + if len("tooBig") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"tooBig\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("tooBig"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("tooBig")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.TooBig); err != nil { + return err + } + return nil +} + +func (t *SyncSubscribeRepos_Commit) UnmarshalCBOR(r io.Reader) (err error) { + *t = SyncSubscribeRepos_Commit{} + + 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("SyncSubscribeRepos_Commit: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.Ops ([]*atproto.SyncSubscribeRepos_RepoOp) (slice) + case "ops": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Ops: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Ops = make([]*SyncSubscribeRepos_RepoOp, extra) + } + + for i := 0; i < int(extra); i++ { + + var v SyncSubscribeRepos_RepoOp + if err := v.UnmarshalCBOR(cr); err != nil { + return err + } + + t.Ops[i] = &v + } + + // t.Seq (int64) (int64) + case "seq": + { + maj, extra, err := cr.ReadHeader() + var extraI int64 + if err != nil { + return err + } + 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.Seq = int64(extraI) + } + // t.Prev (util.LexLink) (struct) + case "prev": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Prev = new(util.LexLink) + if err := t.Prev.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Prev pointer: %w", err) + } + } + + } + // t.Repo (string) (string) + case "repo": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Repo = string(sval) + } + // t.Time (string) (string) + case "time": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Time = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Blobs ([]util.LexLink) (slice) + case "blobs": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Blobs: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Blobs = make([]util.LexLink, extra) + } + + for i := 0; i < int(extra); i++ { + + var v util.LexLink + if err := v.UnmarshalCBOR(cr); err != nil { + return err + } + + t.Blobs[i] = v + } + + // t.Blocks (util.LexBytes) (slice) + case "blocks": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > cbg.ByteArrayMaxLen { + return fmt.Errorf("t.Blocks: byte array too large (%d)", extra) + } + if maj != cbg.MajByteString { + return fmt.Errorf("expected byte array") + } + + if extra > 0 { + t.Blocks = make([]uint8, extra) + } + + if _, err := io.ReadFull(cr, t.Blocks[:]); err != nil { + return err + } + // t.Commit (util.LexLink) (struct) + case "commit": + + { + + if err := t.Commit.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Commit: %w", err) + } + + } + // t.Rebase (bool) (bool) + case "rebase": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.Rebase = false + case 21: + t.Rebase = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + // t.TooBig (bool) (bool) + case "tooBig": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.TooBig = false + case 21: + t.TooBig = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *SyncSubscribeRepos_Handle) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 5 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Did (string) (string) + if len("did") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"did\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("did"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("did")); err != nil { + return err + } + + if len(t.Did) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Did was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Did))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Did)); err != nil { + return err + } + + // t.Seq (int64) (int64) + if len("seq") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"seq\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("seq"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("seq")); err != nil { + return err + } + + if t.Seq >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Seq)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Seq-1)); err != nil { + return err + } + } + + // t.Time (string) (string) + if len("time") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"time\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("time"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("time")); err != nil { + return err + } + + if len(t.Time) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Time was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Time))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Time)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + + // t.Handle (string) (string) + if len("handle") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"handle\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("handle"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("handle")); err != nil { + return err + } + + if len(t.Handle) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Handle was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Handle))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Handle)); err != nil { + return err + } + return nil +} + +func (t *SyncSubscribeRepos_Handle) UnmarshalCBOR(r io.Reader) (err error) { + *t = SyncSubscribeRepos_Handle{} + + 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("SyncSubscribeRepos_Handle: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.Did (string) (string) + case "did": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Did = string(sval) + } + // t.Seq (int64) (int64) + case "seq": + { + maj, extra, err := cr.ReadHeader() + var extraI int64 + if err != nil { + return err + } + 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.Seq = int64(extraI) + } + // t.Time (string) (string) + case "time": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Time = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Handle (string) (string) + case "handle": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Handle = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *SyncSubscribeRepos_Info) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 3 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if t.Message == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Name (string) (string) + if len("name") > cbg.MaxLength { + 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 := io.WriteString(w, string("name")); err != nil { + return err + } + + if len(t.Name) > cbg.MaxLength { + 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 := io.WriteString(w, string(t.Name)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + + // t.Message (string) (string) + if t.Message != nil { + + if len("message") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"message\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("message"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("message")); err != nil { + return err + } + + if t.Message == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Message) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Message was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Message))); err != nil { + return err + } + if _, err := io.WriteString(w, string(*t.Message)); err != nil { + return err + } + } + } + return nil +} + +func (t *SyncSubscribeRepos_Info) UnmarshalCBOR(r io.Reader) (err error) { + *t = SyncSubscribeRepos_Info{} + + 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("SyncSubscribeRepos_Info: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.Name (string) (string) + case "name": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Name = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Message (string) (string) + case "message": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Message = (*string)(&sval) + } + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *SyncSubscribeRepos_Migrate) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 5 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Did (string) (string) + if len("did") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"did\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("did"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("did")); err != nil { + return err + } + + if len(t.Did) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Did was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Did))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Did)); err != nil { + return err + } + + // t.Seq (int64) (int64) + if len("seq") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"seq\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("seq"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("seq")); err != nil { + return err + } + + if t.Seq >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Seq)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Seq-1)); err != nil { + return err + } + } + + // t.Time (string) (string) + if len("time") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"time\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("time"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("time")); err != nil { + return err + } + + if len(t.Time) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Time was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Time))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Time)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + + // t.MigrateTo (string) (string) + if len("migrateTo") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"migrateTo\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("migrateTo"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("migrateTo")); err != nil { + return err + } + + if t.MigrateTo == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.MigrateTo) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.MigrateTo was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.MigrateTo))); err != nil { + return err + } + if _, err := io.WriteString(w, string(*t.MigrateTo)); err != nil { + return err + } + } + return nil +} + +func (t *SyncSubscribeRepos_Migrate) UnmarshalCBOR(r io.Reader) (err error) { + *t = SyncSubscribeRepos_Migrate{} + + 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("SyncSubscribeRepos_Migrate: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.Did (string) (string) + case "did": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Did = string(sval) + } + // t.Seq (int64) (int64) + case "seq": + { + maj, extra, err := cr.ReadHeader() + var extraI int64 + if err != nil { + return err + } + 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.Seq = int64(extraI) + } + // t.Time (string) (string) + case "time": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Time = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.MigrateTo (string) (string) + case "migrateTo": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.MigrateTo = (*string)(&sval) + } + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *SyncSubscribeRepos_RepoOp) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 4 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Cid (util.LexLink) (struct) + if len("cid") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"cid\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("cid"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("cid")); err != nil { + return err + } + + if err := t.Cid.MarshalCBOR(cw); err != nil { + return err + } + + // t.Path (string) (string) + if len("path") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"path\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("path"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("path")); err != nil { + return err + } + + if len(t.Path) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Path was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Path))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Path)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + + // t.Action (string) (string) + if len("action") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"action\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("action"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("action")); err != nil { + return err + } + + if len(t.Action) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Action was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Action))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Action)); err != nil { + return err + } + return nil +} + +func (t *SyncSubscribeRepos_RepoOp) UnmarshalCBOR(r io.Reader) (err error) { + *t = SyncSubscribeRepos_RepoOp{} + + 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("SyncSubscribeRepos_RepoOp: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.Cid (util.LexLink) (struct) + case "cid": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Cid = new(util.LexLink) + if err := t.Cid.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Cid pointer: %w", err) + } + } + + } + // t.Path (string) (string) + case "path": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Path = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Action (string) (string) + case "action": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Action = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *SyncSubscribeRepos_Tombstone) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 4 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Did (string) (string) + if len("did") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"did\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("did"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("did")); err != nil { + return err + } + + if len(t.Did) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Did was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Did))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Did)); err != nil { + return err + } + + // t.Seq (int64) (int64) + if len("seq") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"seq\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("seq"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("seq")); err != nil { + return err + } + + if t.Seq >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Seq)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Seq-1)); err != nil { + return err + } + } + + // t.Time (string) (string) + if len("time") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"time\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("time"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("time")); err != nil { + return err + } + + if len(t.Time) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Time was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Time))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Time)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + return nil +} + +func (t *SyncSubscribeRepos_Tombstone) UnmarshalCBOR(r io.Reader) (err error) { + *t = SyncSubscribeRepos_Tombstone{} + + 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("SyncSubscribeRepos_Tombstone: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.Did (string) (string) + case "did": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Did = string(sval) + } + // t.Seq (int64) (int64) + case "seq": + { + maj, extra, err := cr.ReadHeader() + var extraI int64 + if err != nil { + return err + } + 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.Seq = int64(extraI) + } + // t.Time (string) (string) + case "time": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Time = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": { sval, err := cbg.ReadString(cr) diff --git a/api/atproto/handleresolve.go b/api/atproto/handleresolve.go deleted file mode 100644 index fdcaf4d09..000000000 --- a/api/atproto/handleresolve.go +++ /dev/null @@ -1,30 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.handle.resolve - -func init() { -} - -type HandleResolve_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Did string `json:"did" cborgen:"did"` -} - -func HandleResolve(ctx context.Context, c *xrpc.Client, handle string) (*HandleResolve_Output, error) { - var out HandleResolve_Output - - params := map[string]interface{}{ - "handle": handle, - } - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.handle.resolve", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/atproto/handleupdate.go b/api/atproto/handleupdate.go deleted file mode 100644 index 9141fa4c1..000000000 --- a/api/atproto/handleupdate.go +++ /dev/null @@ -1,25 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.handle.update - -func init() { -} - -type HandleUpdate_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Handle string `json:"handle" cborgen:"handle"` -} - -func HandleUpdate(ctx context.Context, c *xrpc.Client, input *HandleUpdate_Input) error { - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.handle.update", nil, input, nil); err != nil { - return err - } - - return nil -} diff --git a/api/atproto/identityresolveHandle.go b/api/atproto/identityresolveHandle.go new file mode 100644 index 000000000..6d2519ea1 --- /dev/null +++ b/api/atproto/identityresolveHandle.go @@ -0,0 +1,30 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.identity.resolveHandle + +func init() { +} + +type IdentityResolveHandle_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Did string `json:"did" cborgen:"did"` +} + +func IdentityResolveHandle(ctx context.Context, c *xrpc.Client, handle string) (*IdentityResolveHandle_Output, error) { + var out IdentityResolveHandle_Output + + params := map[string]interface{}{ + "handle": handle, + } + if err := c.Do(ctx, xrpc.Query, "", "com.atproto.identity.resolveHandle", params, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/atproto/identityupdateHandle.go b/api/atproto/identityupdateHandle.go new file mode 100644 index 000000000..71f231ce5 --- /dev/null +++ b/api/atproto/identityupdateHandle.go @@ -0,0 +1,25 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.identity.updateHandle + +func init() { +} + +type IdentityUpdateHandle_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Handle string `json:"handle" cborgen:"handle"` +} + +func IdentityUpdateHandle(ctx context.Context, c *xrpc.Client, input *IdentityUpdateHandle_Input) error { + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.identity.updateHandle", nil, input, nil); err != nil { + return err + } + + return nil +} diff --git a/api/atproto/moderationcreateReport.go b/api/atproto/moderationcreateReport.go new file mode 100644 index 000000000..c74d6a9cb --- /dev/null +++ b/api/atproto/moderationcreateReport.go @@ -0,0 +1,111 @@ +package atproto + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/bluesky-social/indigo/lex/util" + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.moderation.createReport + +func init() { +} + +type ModerationCreateReport_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Reason *string `json:"reason,omitempty" cborgen:"reason,omitempty"` + ReasonType *string `json:"reasonType" cborgen:"reasonType"` + Subject *ModerationCreateReport_Input_Subject `json:"subject" cborgen:"subject"` +} + +type ModerationCreateReport_Input_Subject struct { + AdminDefs_RepoRef *AdminDefs_RepoRef + RepoStrongRef *RepoStrongRef +} + +func (t *ModerationCreateReport_Input_Subject) MarshalJSON() ([]byte, error) { + if t.AdminDefs_RepoRef != nil { + t.AdminDefs_RepoRef.LexiconTypeID = "com.atproto.admin.defs#repoRef" + return json.Marshal(t.AdminDefs_RepoRef) + } + if t.RepoStrongRef != nil { + t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef" + return json.Marshal(t.RepoStrongRef) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *ModerationCreateReport_Input_Subject) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.admin.defs#repoRef": + t.AdminDefs_RepoRef = new(AdminDefs_RepoRef) + return json.Unmarshal(b, t.AdminDefs_RepoRef) + case "com.atproto.repo.strongRef": + t.RepoStrongRef = new(RepoStrongRef) + return json.Unmarshal(b, t.RepoStrongRef) + + default: + return nil + } +} + +type ModerationCreateReport_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Id int64 `json:"id" cborgen:"id"` + Reason *string `json:"reason,omitempty" cborgen:"reason,omitempty"` + ReasonType *string `json:"reasonType" cborgen:"reasonType"` + ReportedBy string `json:"reportedBy" cborgen:"reportedBy"` + Subject *ModerationCreateReport_Output_Subject `json:"subject" cborgen:"subject"` +} + +type ModerationCreateReport_Output_Subject struct { + AdminDefs_RepoRef *AdminDefs_RepoRef + RepoStrongRef *RepoStrongRef +} + +func (t *ModerationCreateReport_Output_Subject) MarshalJSON() ([]byte, error) { + if t.AdminDefs_RepoRef != nil { + t.AdminDefs_RepoRef.LexiconTypeID = "com.atproto.admin.defs#repoRef" + return json.Marshal(t.AdminDefs_RepoRef) + } + if t.RepoStrongRef != nil { + t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef" + return json.Marshal(t.RepoStrongRef) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *ModerationCreateReport_Output_Subject) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.admin.defs#repoRef": + t.AdminDefs_RepoRef = new(AdminDefs_RepoRef) + return json.Unmarshal(b, t.AdminDefs_RepoRef) + case "com.atproto.repo.strongRef": + t.RepoStrongRef = new(RepoStrongRef) + return json.Unmarshal(b, t.RepoStrongRef) + + default: + return nil + } +} + +func ModerationCreateReport(ctx context.Context, c *xrpc.Client, input *ModerationCreateReport_Input) (*ModerationCreateReport_Output, error) { + var out ModerationCreateReport_Output + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.moderation.createReport", nil, input, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/atproto/moderationdefs.go b/api/atproto/moderationdefs.go new file mode 100644 index 000000000..d2c1d3388 --- /dev/null +++ b/api/atproto/moderationdefs.go @@ -0,0 +1,6 @@ +package atproto + +// schema: com.atproto.moderation.defs + +func init() { +} diff --git a/api/atproto/repoapplyWrites.go b/api/atproto/repoapplyWrites.go new file mode 100644 index 000000000..7ea7f8bfe --- /dev/null +++ b/api/atproto/repoapplyWrites.go @@ -0,0 +1,94 @@ +package atproto + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/bluesky-social/indigo/lex/util" + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.repo.applyWrites + +func init() { +} + +type RepoApplyWrites_Create struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Collection string `json:"collection" cborgen:"collection"` + Rkey *string `json:"rkey,omitempty" cborgen:"rkey,omitempty"` + Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` +} + +type RepoApplyWrites_Delete struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Collection string `json:"collection" cborgen:"collection"` + Rkey string `json:"rkey" cborgen:"rkey"` +} + +type RepoApplyWrites_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Repo string `json:"repo" cborgen:"repo"` + SwapCommit *string `json:"swapCommit,omitempty" cborgen:"swapCommit,omitempty"` + Validate *bool `json:"validate,omitempty" cborgen:"validate,omitempty"` + Writes []*RepoApplyWrites_Input_Writes_Elem `json:"writes" cborgen:"writes"` +} + +type RepoApplyWrites_Input_Writes_Elem struct { + RepoApplyWrites_Create *RepoApplyWrites_Create + RepoApplyWrites_Update *RepoApplyWrites_Update + RepoApplyWrites_Delete *RepoApplyWrites_Delete +} + +func (t *RepoApplyWrites_Input_Writes_Elem) MarshalJSON() ([]byte, error) { + if t.RepoApplyWrites_Create != nil { + t.RepoApplyWrites_Create.LexiconTypeID = "com.atproto.repo.applyWrites#create" + return json.Marshal(t.RepoApplyWrites_Create) + } + if t.RepoApplyWrites_Update != nil { + t.RepoApplyWrites_Update.LexiconTypeID = "com.atproto.repo.applyWrites#update" + return json.Marshal(t.RepoApplyWrites_Update) + } + if t.RepoApplyWrites_Delete != nil { + t.RepoApplyWrites_Delete.LexiconTypeID = "com.atproto.repo.applyWrites#delete" + return json.Marshal(t.RepoApplyWrites_Delete) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *RepoApplyWrites_Input_Writes_Elem) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "com.atproto.repo.applyWrites#create": + t.RepoApplyWrites_Create = new(RepoApplyWrites_Create) + return json.Unmarshal(b, t.RepoApplyWrites_Create) + case "com.atproto.repo.applyWrites#update": + t.RepoApplyWrites_Update = new(RepoApplyWrites_Update) + return json.Unmarshal(b, t.RepoApplyWrites_Update) + case "com.atproto.repo.applyWrites#delete": + t.RepoApplyWrites_Delete = new(RepoApplyWrites_Delete) + return json.Unmarshal(b, t.RepoApplyWrites_Delete) + + default: + return fmt.Errorf("closed enums must have a matching value") + } +} + +type RepoApplyWrites_Update struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Collection string `json:"collection" cborgen:"collection"` + Rkey string `json:"rkey" cborgen:"rkey"` + Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` +} + +func RepoApplyWrites(ctx context.Context, c *xrpc.Client, input *RepoApplyWrites_Input) error { + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.repo.applyWrites", nil, input, nil); err != nil { + return err + } + + return nil +} diff --git a/api/atproto/repobatchWrite.go b/api/atproto/repobatchWrite.go deleted file mode 100644 index e16b72d68..000000000 --- a/api/atproto/repobatchWrite.go +++ /dev/null @@ -1,96 +0,0 @@ -package atproto - -import ( - "context" - "encoding/json" - "fmt" - - "github.com/bluesky-social/indigo/lex/util" - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.repo.batchWrite - -func init() { -} - -type RepoBatchWrite_Create struct { - LexiconTypeID string `json:"$type,omitempty"` - Action string `json:"action" cborgen:"action"` - Collection string `json:"collection" cborgen:"collection"` - Rkey *string `json:"rkey,omitempty" cborgen:"rkey"` - Value util.LexiconTypeDecoder `json:"value" cborgen:"value"` -} - -type RepoBatchWrite_Delete struct { - LexiconTypeID string `json:"$type,omitempty"` - Action string `json:"action" cborgen:"action"` - Collection string `json:"collection" cborgen:"collection"` - Rkey string `json:"rkey" cborgen:"rkey"` -} - -type RepoBatchWrite_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Did string `json:"did" cborgen:"did"` - Validate *bool `json:"validate,omitempty" cborgen:"validate"` - Writes []*RepoBatchWrite_Input_Writes_Elem `json:"writes" cborgen:"writes"` -} - -type RepoBatchWrite_Input_Writes_Elem struct { - RepoBatchWrite_Create *RepoBatchWrite_Create - RepoBatchWrite_Update *RepoBatchWrite_Update - RepoBatchWrite_Delete *RepoBatchWrite_Delete -} - -func (t *RepoBatchWrite_Input_Writes_Elem) MarshalJSON() ([]byte, error) { - if t.RepoBatchWrite_Create != nil { - t.RepoBatchWrite_Create.LexiconTypeID = "com.atproto.repo.batchWrite#create" - return json.Marshal(t.RepoBatchWrite_Create) - } - if t.RepoBatchWrite_Update != nil { - t.RepoBatchWrite_Update.LexiconTypeID = "com.atproto.repo.batchWrite#update" - return json.Marshal(t.RepoBatchWrite_Update) - } - if t.RepoBatchWrite_Delete != nil { - t.RepoBatchWrite_Delete.LexiconTypeID = "com.atproto.repo.batchWrite#delete" - return json.Marshal(t.RepoBatchWrite_Delete) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *RepoBatchWrite_Input_Writes_Elem) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "com.atproto.repo.batchWrite#create": - t.RepoBatchWrite_Create = new(RepoBatchWrite_Create) - return json.Unmarshal(b, t.RepoBatchWrite_Create) - case "com.atproto.repo.batchWrite#update": - t.RepoBatchWrite_Update = new(RepoBatchWrite_Update) - return json.Unmarshal(b, t.RepoBatchWrite_Update) - case "com.atproto.repo.batchWrite#delete": - t.RepoBatchWrite_Delete = new(RepoBatchWrite_Delete) - return json.Unmarshal(b, t.RepoBatchWrite_Delete) - - default: - return fmt.Errorf("closed enums must have a matching value") - } -} - -type RepoBatchWrite_Update struct { - LexiconTypeID string `json:"$type,omitempty"` - Action string `json:"action" cborgen:"action"` - Collection string `json:"collection" cborgen:"collection"` - Rkey string `json:"rkey" cborgen:"rkey"` - Value util.LexiconTypeDecoder `json:"value" cborgen:"value"` -} - -func RepoBatchWrite(ctx context.Context, c *xrpc.Client, input *RepoBatchWrite_Input) error { - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.repo.batchWrite", nil, input, nil); err != nil { - return err - } - - return nil -} diff --git a/api/atproto/repocreateRecord.go b/api/atproto/repocreateRecord.go index dc728bd42..c23af0f60 100644 --- a/api/atproto/repocreateRecord.go +++ b/api/atproto/repocreateRecord.go @@ -13,15 +13,17 @@ func init() { } type RepoCreateRecord_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Collection string `json:"collection" cborgen:"collection"` - Did string `json:"did" cborgen:"did"` - Record util.LexiconTypeDecoder `json:"record" cborgen:"record"` - Validate *bool `json:"validate,omitempty" cborgen:"validate"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Collection string `json:"collection" cborgen:"collection"` + Record *util.LexiconTypeDecoder `json:"record" cborgen:"record"` + Repo string `json:"repo" cborgen:"repo"` + Rkey *string `json:"rkey,omitempty" cborgen:"rkey,omitempty"` + SwapCommit *string `json:"swapCommit,omitempty" cborgen:"swapCommit,omitempty"` + Validate *bool `json:"validate,omitempty" cborgen:"validate,omitempty"` } type RepoCreateRecord_Output struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Cid string `json:"cid" cborgen:"cid"` Uri string `json:"uri" cborgen:"uri"` } diff --git a/api/atproto/repodeleteRecord.go b/api/atproto/repodeleteRecord.go index d988ae6e2..5aa232434 100644 --- a/api/atproto/repodeleteRecord.go +++ b/api/atproto/repodeleteRecord.go @@ -12,10 +12,12 @@ func init() { } type RepoDeleteRecord_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Collection string `json:"collection" cborgen:"collection"` - Did string `json:"did" cborgen:"did"` - Rkey string `json:"rkey" cborgen:"rkey"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Collection string `json:"collection" cborgen:"collection"` + Repo string `json:"repo" cborgen:"repo"` + Rkey string `json:"rkey" cborgen:"rkey"` + SwapCommit *string `json:"swapCommit,omitempty" cborgen:"swapCommit,omitempty"` + SwapRecord *string `json:"swapRecord,omitempty" cborgen:"swapRecord,omitempty"` } func RepoDeleteRecord(ctx context.Context, c *xrpc.Client, input *RepoDeleteRecord_Input) error { diff --git a/api/atproto/repodescribe.go b/api/atproto/repodescribe.go deleted file mode 100644 index 1097ab1ff..000000000 --- a/api/atproto/repodescribe.go +++ /dev/null @@ -1,35 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/lex/util" - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.repo.describe - -func init() { -} - -type RepoDescribe_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Collections []string `json:"collections" cborgen:"collections"` - Did string `json:"did" cborgen:"did"` - DidDoc util.LexiconTypeDecoder `json:"didDoc" cborgen:"didDoc"` - Handle string `json:"handle" cborgen:"handle"` - HandleIsCorrect bool `json:"handleIsCorrect" cborgen:"handleIsCorrect"` -} - -func RepoDescribe(ctx context.Context, c *xrpc.Client, user string) (*RepoDescribe_Output, error) { - var out RepoDescribe_Output - - params := map[string]interface{}{ - "user": user, - } - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.repo.describe", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/atproto/repodescribeRepo.go b/api/atproto/repodescribeRepo.go new file mode 100644 index 000000000..1ccba150c --- /dev/null +++ b/api/atproto/repodescribeRepo.go @@ -0,0 +1,35 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/lex/util" + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.repo.describeRepo + +func init() { +} + +type RepoDescribeRepo_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Collections []string `json:"collections" cborgen:"collections"` + Did string `json:"did" cborgen:"did"` + DidDoc *util.LexiconTypeDecoder `json:"didDoc" cborgen:"didDoc"` + Handle string `json:"handle" cborgen:"handle"` + HandleIsCorrect bool `json:"handleIsCorrect" cborgen:"handleIsCorrect"` +} + +func RepoDescribeRepo(ctx context.Context, c *xrpc.Client, repo string) (*RepoDescribeRepo_Output, error) { + var out RepoDescribeRepo_Output + + params := map[string]interface{}{ + "repo": repo, + } + if err := c.Do(ctx, xrpc.Query, "", "com.atproto.repo.describeRepo", params, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/atproto/repogetRecord.go b/api/atproto/repogetRecord.go index d30838bb4..278dcf841 100644 --- a/api/atproto/repogetRecord.go +++ b/api/atproto/repogetRecord.go @@ -13,20 +13,20 @@ func init() { } type RepoGetRecord_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid *string `json:"cid,omitempty" cborgen:"cid"` - Uri string `json:"uri" cborgen:"uri"` - Value util.LexiconTypeDecoder `json:"value" cborgen:"value"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"` + Uri string `json:"uri" cborgen:"uri"` + Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` } -func RepoGetRecord(ctx context.Context, c *xrpc.Client, cid string, collection string, rkey string, user string) (*RepoGetRecord_Output, error) { +func RepoGetRecord(ctx context.Context, c *xrpc.Client, cid string, collection string, repo string, rkey string) (*RepoGetRecord_Output, error) { var out RepoGetRecord_Output params := map[string]interface{}{ "cid": cid, "collection": collection, + "repo": repo, "rkey": rkey, - "user": user, } if err := c.Do(ctx, xrpc.Query, "", "com.atproto.repo.getRecord", params, nil, &out); err != nil { return nil, err diff --git a/api/atproto/repolistRecords.go b/api/atproto/repolistRecords.go index 3dd1b99f2..e45f4ba8a 100644 --- a/api/atproto/repolistRecords.go +++ b/api/atproto/repolistRecords.go @@ -13,28 +13,28 @@ func init() { } type RepoListRecords_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` Records []*RepoListRecords_Record `json:"records" cborgen:"records"` } type RepoListRecords_Record struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid string `json:"cid" cborgen:"cid"` - Uri string `json:"uri" cborgen:"uri"` - Value util.LexiconTypeDecoder `json:"value" cborgen:"value"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cid string `json:"cid" cborgen:"cid"` + Uri string `json:"uri" cborgen:"uri"` + Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` } -func RepoListRecords(ctx context.Context, c *xrpc.Client, after string, before string, collection string, limit int64, reverse bool, user string) (*RepoListRecords_Output, error) { +func RepoListRecords(ctx context.Context, c *xrpc.Client, collection string, limit int64, repo string, reverse bool, rkeyEnd string, rkeyStart string) (*RepoListRecords_Output, error) { var out RepoListRecords_Output params := map[string]interface{}{ - "after": after, - "before": before, "collection": collection, "limit": limit, + "repo": repo, "reverse": reverse, - "user": user, + "rkeyEnd": rkeyEnd, + "rkeyStart": rkeyStart, } if err := c.Do(ctx, xrpc.Query, "", "com.atproto.repo.listRecords", params, nil, &out); err != nil { return nil, err diff --git a/api/atproto/repoputRecord.go b/api/atproto/repoputRecord.go index 28b241c7c..9d9ea1806 100644 --- a/api/atproto/repoputRecord.go +++ b/api/atproto/repoputRecord.go @@ -13,16 +13,18 @@ func init() { } type RepoPutRecord_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Collection string `json:"collection" cborgen:"collection"` - Did string `json:"did" cborgen:"did"` - Record util.LexiconTypeDecoder `json:"record" cborgen:"record"` - Rkey string `json:"rkey" cborgen:"rkey"` - Validate *bool `json:"validate,omitempty" cborgen:"validate"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Collection string `json:"collection" cborgen:"collection"` + Record *util.LexiconTypeDecoder `json:"record" cborgen:"record"` + Repo string `json:"repo" cborgen:"repo"` + Rkey string `json:"rkey" cborgen:"rkey"` + SwapCommit *string `json:"swapCommit,omitempty" cborgen:"swapCommit,omitempty"` + SwapRecord *string `json:"swapRecord" cborgen:"swapRecord"` + Validate *bool `json:"validate,omitempty" cborgen:"validate,omitempty"` } type RepoPutRecord_Output struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Cid string `json:"cid" cborgen:"cid"` Uri string `json:"uri" cborgen:"uri"` } diff --git a/api/atproto/reporecordRef.go b/api/atproto/reporecordRef.go deleted file mode 100644 index 55e23ca91..000000000 --- a/api/atproto/reporecordRef.go +++ /dev/null @@ -1,12 +0,0 @@ -package atproto - -// schema: com.atproto.repo.recordRef - -func init() { -} - -type RepoRecordRef struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid *string `json:"cid,omitempty" cborgen:"cid"` - Uri string `json:"uri" cborgen:"uri"` -} diff --git a/api/atproto/reporepoRef.go b/api/atproto/reporepoRef.go deleted file mode 100644 index 205c941bd..000000000 --- a/api/atproto/reporepoRef.go +++ /dev/null @@ -1,11 +0,0 @@ -package atproto - -// schema: com.atproto.repo.repoRef - -func init() { -} - -type RepoRepoRef struct { - LexiconTypeID string `json:"$type,omitempty"` - Did string `json:"did" cborgen:"did"` -} diff --git a/api/atproto/reportcreate.go b/api/atproto/reportcreate.go deleted file mode 100644 index bb133b3cd..000000000 --- a/api/atproto/reportcreate.go +++ /dev/null @@ -1,111 +0,0 @@ -package atproto - -import ( - "context" - "encoding/json" - "fmt" - - "github.com/bluesky-social/indigo/lex/util" - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.report.create - -func init() { -} - -type ReportCreate_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Reason *string `json:"reason,omitempty" cborgen:"reason"` - ReasonType *string `json:"reasonType" cborgen:"reasonType"` - Subject *ReportCreate_Input_Subject `json:"subject" cborgen:"subject"` -} - -type ReportCreate_Input_Subject struct { - RepoRepoRef *RepoRepoRef - RepoRecordRef *RepoRecordRef -} - -func (t *ReportCreate_Input_Subject) MarshalJSON() ([]byte, error) { - if t.RepoRepoRef != nil { - t.RepoRepoRef.LexiconTypeID = "com.atproto.repo.repoRef" - return json.Marshal(t.RepoRepoRef) - } - if t.RepoRecordRef != nil { - t.RepoRecordRef.LexiconTypeID = "com.atproto.repo.recordRef" - return json.Marshal(t.RepoRecordRef) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *ReportCreate_Input_Subject) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "com.atproto.repo.repoRef": - t.RepoRepoRef = new(RepoRepoRef) - return json.Unmarshal(b, t.RepoRepoRef) - case "com.atproto.repo.recordRef": - t.RepoRecordRef = new(RepoRecordRef) - return json.Unmarshal(b, t.RepoRecordRef) - - default: - return nil - } -} - -type ReportCreate_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Id int64 `json:"id" cborgen:"id"` - Reason *string `json:"reason,omitempty" cborgen:"reason"` - ReasonType *string `json:"reasonType" cborgen:"reasonType"` - ReportedByDid string `json:"reportedByDid" cborgen:"reportedByDid"` - Subject *ReportCreate_Output_Subject `json:"subject" cborgen:"subject"` -} - -type ReportCreate_Output_Subject struct { - RepoRepoRef *RepoRepoRef - RepoStrongRef *RepoStrongRef -} - -func (t *ReportCreate_Output_Subject) MarshalJSON() ([]byte, error) { - if t.RepoRepoRef != nil { - t.RepoRepoRef.LexiconTypeID = "com.atproto.repo.repoRef" - return json.Marshal(t.RepoRepoRef) - } - if t.RepoStrongRef != nil { - t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef" - return json.Marshal(t.RepoStrongRef) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *ReportCreate_Output_Subject) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "com.atproto.repo.repoRef": - t.RepoRepoRef = new(RepoRepoRef) - return json.Unmarshal(b, t.RepoRepoRef) - case "com.atproto.repo.strongRef": - t.RepoStrongRef = new(RepoStrongRef) - return json.Unmarshal(b, t.RepoStrongRef) - - default: - return nil - } -} - -func ReportCreate(ctx context.Context, c *xrpc.Client, input *ReportCreate_Input) (*ReportCreate_Output, error) { - var out ReportCreate_Output - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.report.create", nil, input, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/atproto/reportreasonType.go b/api/atproto/reportreasonType.go deleted file mode 100644 index 66e539938..000000000 --- a/api/atproto/reportreasonType.go +++ /dev/null @@ -1,6 +0,0 @@ -package atproto - -// schema: com.atproto.report.reasonType - -func init() { -} diff --git a/api/atproto/reportsubject.go b/api/atproto/reportsubject.go deleted file mode 100644 index cf034feb2..000000000 --- a/api/atproto/reportsubject.go +++ /dev/null @@ -1,25 +0,0 @@ -package atproto - -// schema: com.atproto.report.subject - -func init() { -} - -type ReportSubject_Record struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid *string `json:"cid,omitempty" cborgen:"cid"` - Collection string `json:"collection" cborgen:"collection"` - Did string `json:"did" cborgen:"did"` - Rkey string `json:"rkey" cborgen:"rkey"` -} - -type ReportSubject_RecordRef struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid string `json:"cid" cborgen:"cid"` - Uri string `json:"uri" cborgen:"uri"` -} - -type ReportSubject_Repo struct { - LexiconTypeID string `json:"$type,omitempty"` - Did string `json:"did" cborgen:"did"` -} diff --git a/api/atproto/repostrongRef.go b/api/atproto/repostrongRef.go index e68bf7783..907187bc1 100644 --- a/api/atproto/repostrongRef.go +++ b/api/atproto/repostrongRef.go @@ -6,7 +6,7 @@ func init() { } type RepoStrongRef struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Cid string `json:"cid" cborgen:"cid"` Uri string `json:"uri" cborgen:"uri"` } diff --git a/api/atproto/repouploadBlob.go b/api/atproto/repouploadBlob.go new file mode 100644 index 000000000..1200bf4ea --- /dev/null +++ b/api/atproto/repouploadBlob.go @@ -0,0 +1,28 @@ +package atproto + +import ( + "context" + "io" + + "github.com/bluesky-social/indigo/lex/util" + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.repo.uploadBlob + +func init() { +} + +type RepoUploadBlob_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Blob *util.LexBlob `json:"blob" cborgen:"blob"` +} + +func RepoUploadBlob(ctx context.Context, c *xrpc.Client, input io.Reader) (*RepoUploadBlob_Output, error) { + var out RepoUploadBlob_Output + if err := c.Do(ctx, xrpc.Procedure, "*/*", "com.atproto.repo.uploadBlob", nil, input, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/atproto/accountcreate.go b/api/atproto/servercreateAccount.go similarity index 57% rename from api/atproto/accountcreate.go rename to api/atproto/servercreateAccount.go index 6716c24ba..3c73f10c2 100644 --- a/api/atproto/accountcreate.go +++ b/api/atproto/servercreateAccount.go @@ -6,31 +6,31 @@ import ( "github.com/bluesky-social/indigo/xrpc" ) -// schema: com.atproto.account.create +// schema: com.atproto.server.createAccount func init() { } -type AccountCreate_Input struct { - LexiconTypeID string `json:"$type,omitempty"` +type ServerCreateAccount_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Email string `json:"email" cborgen:"email"` Handle string `json:"handle" cborgen:"handle"` - InviteCode *string `json:"inviteCode,omitempty" cborgen:"inviteCode"` + InviteCode *string `json:"inviteCode,omitempty" cborgen:"inviteCode,omitempty"` Password string `json:"password" cborgen:"password"` - RecoveryKey *string `json:"recoveryKey,omitempty" cborgen:"recoveryKey"` + RecoveryKey *string `json:"recoveryKey,omitempty" cborgen:"recoveryKey,omitempty"` } -type AccountCreate_Output struct { - LexiconTypeID string `json:"$type,omitempty"` +type ServerCreateAccount_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` AccessJwt string `json:"accessJwt" cborgen:"accessJwt"` Did string `json:"did" cborgen:"did"` Handle string `json:"handle" cborgen:"handle"` RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` } -func AccountCreate(ctx context.Context, c *xrpc.Client, input *AccountCreate_Input) (*AccountCreate_Output, error) { - var out AccountCreate_Output - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.account.create", nil, input, &out); err != nil { +func ServerCreateAccount(ctx context.Context, c *xrpc.Client, input *ServerCreateAccount_Input) (*ServerCreateAccount_Output, error) { + var out ServerCreateAccount_Output + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.server.createAccount", nil, input, &out); err != nil { return nil, err } diff --git a/api/atproto/servercreateInviteCode.go b/api/atproto/servercreateInviteCode.go new file mode 100644 index 000000000..20a1af8ef --- /dev/null +++ b/api/atproto/servercreateInviteCode.go @@ -0,0 +1,31 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.server.createInviteCode + +func init() { +} + +type ServerCreateInviteCode_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + UseCount int64 `json:"useCount" cborgen:"useCount"` +} + +type ServerCreateInviteCode_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Code string `json:"code" cborgen:"code"` +} + +func ServerCreateInviteCode(ctx context.Context, c *xrpc.Client, input *ServerCreateInviteCode_Input) (*ServerCreateInviteCode_Output, error) { + var out ServerCreateInviteCode_Output + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.server.createInviteCode", nil, input, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/atproto/sessioncreate.go b/api/atproto/servercreateSession.go similarity index 51% rename from api/atproto/sessioncreate.go rename to api/atproto/servercreateSession.go index 95e1ccb47..8e8f53433 100644 --- a/api/atproto/sessioncreate.go +++ b/api/atproto/servercreateSession.go @@ -6,28 +6,28 @@ import ( "github.com/bluesky-social/indigo/xrpc" ) -// schema: com.atproto.session.create +// schema: com.atproto.server.createSession func init() { } -type SessionCreate_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Identifier *string `json:"identifier,omitempty" cborgen:"identifier"` +type ServerCreateSession_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Identifier *string `json:"identifier,omitempty" cborgen:"identifier,omitempty"` Password string `json:"password" cborgen:"password"` } -type SessionCreate_Output struct { - LexiconTypeID string `json:"$type,omitempty"` +type ServerCreateSession_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` AccessJwt string `json:"accessJwt" cborgen:"accessJwt"` Did string `json:"did" cborgen:"did"` Handle string `json:"handle" cborgen:"handle"` RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` } -func SessionCreate(ctx context.Context, c *xrpc.Client, input *SessionCreate_Input) (*SessionCreate_Output, error) { - var out SessionCreate_Output - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.session.create", nil, input, &out); err != nil { +func ServerCreateSession(ctx context.Context, c *xrpc.Client, input *ServerCreateSession_Input) (*ServerCreateSession_Output, error) { + var out ServerCreateSession_Output + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.server.createSession", nil, input, &out); err != nil { return nil, err } diff --git a/api/atproto/accountdelete.go b/api/atproto/serverdeleteAccount.go similarity index 52% rename from api/atproto/accountdelete.go rename to api/atproto/serverdeleteAccount.go index b62607f2d..2d9f0a822 100644 --- a/api/atproto/accountdelete.go +++ b/api/atproto/serverdeleteAccount.go @@ -6,20 +6,20 @@ import ( "github.com/bluesky-social/indigo/xrpc" ) -// schema: com.atproto.account.delete +// schema: com.atproto.server.deleteAccount func init() { } -type AccountDelete_Input struct { - LexiconTypeID string `json:"$type,omitempty"` +type ServerDeleteAccount_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Did string `json:"did" cborgen:"did"` Password string `json:"password" cborgen:"password"` Token string `json:"token" cborgen:"token"` } -func AccountDelete(ctx context.Context, c *xrpc.Client, input *AccountDelete_Input) error { - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.account.delete", nil, input, nil); err != nil { +func ServerDeleteAccount(ctx context.Context, c *xrpc.Client, input *ServerDeleteAccount_Input) error { + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.server.deleteAccount", nil, input, nil); err != nil { return err } diff --git a/api/atproto/serverdeleteSession.go b/api/atproto/serverdeleteSession.go new file mode 100644 index 000000000..1ef4ee632 --- /dev/null +++ b/api/atproto/serverdeleteSession.go @@ -0,0 +1,19 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.server.deleteSession + +func init() { +} +func ServerDeleteSession(ctx context.Context, c *xrpc.Client) error { + if err := c.Do(ctx, xrpc.Procedure, "", "com.atproto.server.deleteSession", nil, nil, nil); err != nil { + return err + } + + return nil +} diff --git a/api/atproto/serverdescribeServer.go b/api/atproto/serverdescribeServer.go new file mode 100644 index 000000000..88aa2f3d1 --- /dev/null +++ b/api/atproto/serverdescribeServer.go @@ -0,0 +1,34 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.server.describeServer + +func init() { +} + +type ServerDescribeServer_Links struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + PrivacyPolicy *string `json:"privacyPolicy,omitempty" cborgen:"privacyPolicy,omitempty"` + TermsOfService *string `json:"termsOfService,omitempty" cborgen:"termsOfService,omitempty"` +} + +type ServerDescribeServer_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + AvailableUserDomains []string `json:"availableUserDomains" cborgen:"availableUserDomains"` + InviteCodeRequired *bool `json:"inviteCodeRequired,omitempty" cborgen:"inviteCodeRequired,omitempty"` + Links *ServerDescribeServer_Links `json:"links,omitempty" cborgen:"links,omitempty"` +} + +func ServerDescribeServer(ctx context.Context, c *xrpc.Client) (*ServerDescribeServer_Output, error) { + var out ServerDescribeServer_Output + if err := c.Do(ctx, xrpc.Query, "", "com.atproto.server.describeServer", nil, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/atproto/servergetAccountsConfig.go b/api/atproto/servergetAccountsConfig.go deleted file mode 100644 index 463bdc9ab..000000000 --- a/api/atproto/servergetAccountsConfig.go +++ /dev/null @@ -1,34 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.server.getAccountsConfig - -func init() { -} - -type ServerGetAccountsConfig_Links struct { - LexiconTypeID string `json:"$type,omitempty"` - PrivacyPolicy *string `json:"privacyPolicy,omitempty" cborgen:"privacyPolicy"` - TermsOfService *string `json:"termsOfService,omitempty" cborgen:"termsOfService"` -} - -type ServerGetAccountsConfig_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - AvailableUserDomains []string `json:"availableUserDomains" cborgen:"availableUserDomains"` - InviteCodeRequired *bool `json:"inviteCodeRequired,omitempty" cborgen:"inviteCodeRequired"` - Links *ServerGetAccountsConfig_Links `json:"links,omitempty" cborgen:"links"` -} - -func ServerGetAccountsConfig(ctx context.Context, c *xrpc.Client) (*ServerGetAccountsConfig_Output, error) { - var out ServerGetAccountsConfig_Output - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.server.getAccountsConfig", nil, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/atproto/servergetSession.go b/api/atproto/servergetSession.go new file mode 100644 index 000000000..45cb62e0e --- /dev/null +++ b/api/atproto/servergetSession.go @@ -0,0 +1,27 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.server.getSession + +func init() { +} + +type ServerGetSession_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Did string `json:"did" cborgen:"did"` + Handle string `json:"handle" cborgen:"handle"` +} + +func ServerGetSession(ctx context.Context, c *xrpc.Client) (*ServerGetSession_Output, error) { + var out ServerGetSession_Output + if err := c.Do(ctx, xrpc.Query, "", "com.atproto.server.getSession", nil, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/atproto/serverrefreshSession.go b/api/atproto/serverrefreshSession.go new file mode 100644 index 000000000..e48b8bedd --- /dev/null +++ b/api/atproto/serverrefreshSession.go @@ -0,0 +1,29 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.server.refreshSession + +func init() { +} + +type ServerRefreshSession_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + AccessJwt string `json:"accessJwt" cborgen:"accessJwt"` + Did string `json:"did" cborgen:"did"` + Handle string `json:"handle" cborgen:"handle"` + RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` +} + +func ServerRefreshSession(ctx context.Context, c *xrpc.Client) (*ServerRefreshSession_Output, error) { + var out ServerRefreshSession_Output + if err := c.Do(ctx, xrpc.Procedure, "", "com.atproto.server.refreshSession", nil, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/atproto/serverrequestAccountDelete.go b/api/atproto/serverrequestAccountDelete.go new file mode 100644 index 000000000..fb2bf4e16 --- /dev/null +++ b/api/atproto/serverrequestAccountDelete.go @@ -0,0 +1,19 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.server.requestAccountDelete + +func init() { +} +func ServerRequestAccountDelete(ctx context.Context, c *xrpc.Client) error { + if err := c.Do(ctx, xrpc.Procedure, "", "com.atproto.server.requestAccountDelete", nil, nil, nil); err != nil { + return err + } + + return nil +} diff --git a/api/atproto/serverrequestPasswordReset.go b/api/atproto/serverrequestPasswordReset.go new file mode 100644 index 000000000..cb5b26125 --- /dev/null +++ b/api/atproto/serverrequestPasswordReset.go @@ -0,0 +1,25 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.server.requestPasswordReset + +func init() { +} + +type ServerRequestPasswordReset_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Email string `json:"email" cborgen:"email"` +} + +func ServerRequestPasswordReset(ctx context.Context, c *xrpc.Client, input *ServerRequestPasswordReset_Input) error { + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.server.requestPasswordReset", nil, input, nil); err != nil { + return err + } + + return nil +} diff --git a/api/atproto/serverresetPassword.go b/api/atproto/serverresetPassword.go new file mode 100644 index 000000000..f71e98910 --- /dev/null +++ b/api/atproto/serverresetPassword.go @@ -0,0 +1,26 @@ +package atproto + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: com.atproto.server.resetPassword + +func init() { +} + +type ServerResetPassword_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Password string `json:"password" cborgen:"password"` + Token string `json:"token" cborgen:"token"` +} + +func ServerResetPassword(ctx context.Context, c *xrpc.Client, input *ServerResetPassword_Input) error { + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.server.resetPassword", nil, input, nil); err != nil { + return err + } + + return nil +} diff --git a/api/atproto/sessiondelete.go b/api/atproto/sessiondelete.go deleted file mode 100644 index 097a7ab12..000000000 --- a/api/atproto/sessiondelete.go +++ /dev/null @@ -1,19 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.session.delete - -func init() { -} -func SessionDelete(ctx context.Context, c *xrpc.Client) error { - if err := c.Do(ctx, xrpc.Procedure, "", "com.atproto.session.delete", nil, nil, nil); err != nil { - return err - } - - return nil -} diff --git a/api/atproto/sessionget.go b/api/atproto/sessionget.go deleted file mode 100644 index bd8521dbe..000000000 --- a/api/atproto/sessionget.go +++ /dev/null @@ -1,27 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.session.get - -func init() { -} - -type SessionGet_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Did string `json:"did" cborgen:"did"` - Handle string `json:"handle" cborgen:"handle"` -} - -func SessionGet(ctx context.Context, c *xrpc.Client) (*SessionGet_Output, error) { - var out SessionGet_Output - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.session.get", nil, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/atproto/sessionrefresh.go b/api/atproto/sessionrefresh.go deleted file mode 100644 index e77d77fd0..000000000 --- a/api/atproto/sessionrefresh.go +++ /dev/null @@ -1,29 +0,0 @@ -package atproto - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: com.atproto.session.refresh - -func init() { -} - -type SessionRefresh_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - AccessJwt string `json:"accessJwt" cborgen:"accessJwt"` - Did string `json:"did" cborgen:"did"` - Handle string `json:"handle" cborgen:"handle"` - RefreshJwt string `json:"refreshJwt" cborgen:"refreshJwt"` -} - -func SessionRefresh(ctx context.Context, c *xrpc.Client) (*SessionRefresh_Output, error) { - var out SessionRefresh_Output - if err := c.Do(ctx, xrpc.Procedure, "", "com.atproto.session.refresh", nil, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/atproto/syncgetBlob.go b/api/atproto/syncgetBlob.go index 7aa807bf9..de11a0622 100644 --- a/api/atproto/syncgetBlob.go +++ b/api/atproto/syncgetBlob.go @@ -11,7 +11,6 @@ import ( func init() { } - func SyncGetBlob(ctx context.Context, c *xrpc.Client, cid string, did string) ([]byte, error) { buf := new(bytes.Buffer) diff --git a/api/atproto/syncgetCommitPath.go b/api/atproto/syncgetCommitPath.go index 89d4d3ea0..e4eb9e31f 100644 --- a/api/atproto/syncgetCommitPath.go +++ b/api/atproto/syncgetCommitPath.go @@ -12,7 +12,7 @@ func init() { } type SyncGetCommitPath_Output struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Commits []string `json:"commits" cborgen:"commits"` } diff --git a/api/atproto/syncgetHead.go b/api/atproto/syncgetHead.go index eeea4c67d..c3cc3b535 100644 --- a/api/atproto/syncgetHead.go +++ b/api/atproto/syncgetHead.go @@ -12,7 +12,7 @@ func init() { } type SyncGetHead_Output struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Root string `json:"root" cborgen:"root"` } diff --git a/api/atproto/synclistBlobs.go b/api/atproto/synclistBlobs.go index fefaee957..c465c2e3e 100644 --- a/api/atproto/synclistBlobs.go +++ b/api/atproto/synclistBlobs.go @@ -12,7 +12,7 @@ func init() { } type SyncListBlobs_Output struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Cids []string `json:"cids" cborgen:"cids"` } diff --git a/api/atproto/syncsubscribeAllRepos.go b/api/atproto/syncsubscribeAllRepos.go deleted file mode 100644 index d0508490a..000000000 --- a/api/atproto/syncsubscribeAllRepos.go +++ /dev/null @@ -1,13 +0,0 @@ -package atproto - -// schema: com.atproto.sync.subscribeAllRepos - -func init() { -} - -type SyncSubscribeAllRepos_RepoOp struct { - LexiconTypeID string `json:"$type,omitempty"` - Action string `json:"action" cborgen:"action"` - Cid string `json:"cid" cborgen:"cid"` - Path string `json:"path" cborgen:"path"` -} diff --git a/api/atproto/syncsubscribeRepos.go b/api/atproto/syncsubscribeRepos.go new file mode 100644 index 000000000..3deb22c57 --- /dev/null +++ b/api/atproto/syncsubscribeRepos.go @@ -0,0 +1,60 @@ +package atproto + +import ( + "github.com/bluesky-social/indigo/lex/util" +) + +// schema: com.atproto.sync.subscribeRepos + +func init() { +} + +type SyncSubscribeRepos_Commit struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Blobs []util.LexLink `json:"blobs" cborgen:"blobs"` + Blocks util.LexBytes `json:"blocks" cborgen:"blocks"` + Commit util.LexLink `json:"commit" cborgen:"commit"` + Ops []*SyncSubscribeRepos_RepoOp `json:"ops" cborgen:"ops"` + Prev *util.LexLink `json:"prev" cborgen:"prev"` + Rebase bool `json:"rebase" cborgen:"rebase"` + Repo string `json:"repo" cborgen:"repo"` + Seq int64 `json:"seq" cborgen:"seq"` + Time string `json:"time" cborgen:"time"` + TooBig bool `json:"tooBig" cborgen:"tooBig"` +} + +type SyncSubscribeRepos_Handle struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Did string `json:"did" cborgen:"did"` + Handle string `json:"handle" cborgen:"handle"` + Seq int64 `json:"seq" cborgen:"seq"` + Time string `json:"time" cborgen:"time"` +} + +type SyncSubscribeRepos_Info struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Message *string `json:"message,omitempty" cborgen:"message,omitempty"` + Name string `json:"name" cborgen:"name"` +} + +type SyncSubscribeRepos_Migrate struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Did string `json:"did" cborgen:"did"` + MigrateTo *string `json:"migrateTo" cborgen:"migrateTo"` + Seq int64 `json:"seq" cborgen:"seq"` + Time string `json:"time" cborgen:"time"` +} + +type SyncSubscribeRepos_RepoOp struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Action string `json:"action" cborgen:"action"` + Cid *util.LexLink `json:"cid" cborgen:"cid"` + Path string `json:"path" cborgen:"path"` +} + +type SyncSubscribeRepos_Tombstone struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Did string `json:"did" cborgen:"did"` + Seq int64 `json:"seq" cborgen:"seq"` + Time string `json:"time" cborgen:"time"` +} diff --git a/api/bsky/actordefs.go b/api/bsky/actordefs.go new file mode 100644 index 000000000..36a9bf51c --- /dev/null +++ b/api/bsky/actordefs.go @@ -0,0 +1,48 @@ +package bsky + +// schema: app.bsky.actor.defs + +func init() { +} + +type ActorDefs_ProfileView struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Avatar *string `json:"avatar,omitempty" cborgen:"avatar,omitempty"` + Description *string `json:"description,omitempty" cborgen:"description,omitempty"` + Did string `json:"did" cborgen:"did"` + DisplayName *string `json:"displayName,omitempty" cborgen:"displayName,omitempty"` + Handle string `json:"handle" cborgen:"handle"` + IndexedAt *string `json:"indexedAt,omitempty" cborgen:"indexedAt,omitempty"` + Viewer *ActorDefs_ViewerState `json:"viewer,omitempty" cborgen:"viewer,omitempty"` +} + +type ActorDefs_ProfileViewBasic struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Avatar *string `json:"avatar,omitempty" cborgen:"avatar,omitempty"` + Did string `json:"did" cborgen:"did"` + DisplayName *string `json:"displayName,omitempty" cborgen:"displayName,omitempty"` + Handle string `json:"handle" cborgen:"handle"` + Viewer *ActorDefs_ViewerState `json:"viewer,omitempty" cborgen:"viewer,omitempty"` +} + +type ActorDefs_ProfileViewDetailed struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Avatar *string `json:"avatar,omitempty" cborgen:"avatar,omitempty"` + Banner *string `json:"banner,omitempty" cborgen:"banner,omitempty"` + Description *string `json:"description,omitempty" cborgen:"description,omitempty"` + Did string `json:"did" cborgen:"did"` + DisplayName *string `json:"displayName,omitempty" cborgen:"displayName,omitempty"` + FollowersCount *int64 `json:"followersCount,omitempty" cborgen:"followersCount,omitempty"` + FollowsCount *int64 `json:"followsCount,omitempty" cborgen:"followsCount,omitempty"` + Handle string `json:"handle" cborgen:"handle"` + IndexedAt *string `json:"indexedAt,omitempty" cborgen:"indexedAt,omitempty"` + PostsCount *int64 `json:"postsCount,omitempty" cborgen:"postsCount,omitempty"` + Viewer *ActorDefs_ViewerState `json:"viewer,omitempty" cborgen:"viewer,omitempty"` +} + +type ActorDefs_ViewerState struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + FollowedBy *string `json:"followedBy,omitempty" cborgen:"followedBy,omitempty"` + Following *string `json:"following,omitempty" cborgen:"following,omitempty"` + Muted *bool `json:"muted,omitempty" cborgen:"muted,omitempty"` +} diff --git a/api/bsky/actorgetProfile.go b/api/bsky/actorgetProfile.go index 937b66eaa..b07b5becf 100644 --- a/api/bsky/actorgetProfile.go +++ b/api/bsky/actorgetProfile.go @@ -10,8 +10,8 @@ import ( func init() { } -func ActorGetProfile(ctx context.Context, c *xrpc.Client, actor string) (*ActorProfile_View, error) { - var out ActorProfile_View +func ActorGetProfile(ctx context.Context, c *xrpc.Client, actor string) (*ActorDefs_ProfileViewDetailed, error) { + var out ActorDefs_ProfileViewDetailed params := map[string]interface{}{ "actor": actor, diff --git a/api/bsky/actorgetProfiles.go b/api/bsky/actorgetProfiles.go index 2d3954eb1..ffa9952b5 100644 --- a/api/bsky/actorgetProfiles.go +++ b/api/bsky/actorgetProfiles.go @@ -12,8 +12,8 @@ func init() { } type ActorGetProfiles_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Profiles []*ActorProfile_View `json:"profiles" cborgen:"profiles"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Profiles []*ActorDefs_ProfileViewDetailed `json:"profiles" cborgen:"profiles"` } func ActorGetProfiles(ctx context.Context, c *xrpc.Client, actors []string) (*ActorGetProfiles_Output, error) { diff --git a/api/bsky/actorgetSuggestions.go b/api/bsky/actorgetSuggestions.go index 03b8f82cb..e4844f4f5 100644 --- a/api/bsky/actorgetSuggestions.go +++ b/api/bsky/actorgetSuggestions.go @@ -12,9 +12,9 @@ func init() { } type ActorGetSuggestions_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Actors []*ActorProfile_ViewBasic `json:"actors" cborgen:"actors"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Actors []*ActorDefs_ProfileView `json:"actors" cborgen:"actors"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` } func ActorGetSuggestions(ctx context.Context, c *xrpc.Client, cursor string, limit int64) (*ActorGetSuggestions_Output, error) { diff --git a/api/bsky/actorprofile.go b/api/bsky/actorprofile.go index edb1bb338..21c422edb 100644 --- a/api/bsky/actorprofile.go +++ b/api/bsky/actorprofile.go @@ -12,52 +12,9 @@ func init() { // RECORDTYPE: ActorProfile type ActorProfile struct { - LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.actor.profile"` - Avatar *util.Blob `json:"avatar,omitempty" cborgen:"avatar"` - Banner *util.Blob `json:"banner,omitempty" cborgen:"banner"` - Description *string `json:"description,omitempty" cborgen:"description"` - DisplayName string `json:"displayName" cborgen:"displayName"` -} - -type ActorProfile_MyState struct { - LexiconTypeID string `json:"$type,omitempty"` - Follow *string `json:"follow,omitempty" cborgen:"follow"` - Muted *bool `json:"muted,omitempty" cborgen:"muted"` -} - -type ActorProfile_View struct { - LexiconTypeID string `json:"$type,omitempty"` - Avatar *string `json:"avatar,omitempty" cborgen:"avatar"` - Banner *string `json:"banner,omitempty" cborgen:"banner"` - Creator string `json:"creator" cborgen:"creator"` - Declaration *SystemDeclRef `json:"declaration" cborgen:"declaration"` - Description *string `json:"description,omitempty" cborgen:"description"` - Did string `json:"did" cborgen:"did"` - DisplayName *string `json:"displayName,omitempty" cborgen:"displayName"` - FollowersCount int64 `json:"followersCount" cborgen:"followersCount"` - FollowsCount int64 `json:"followsCount" cborgen:"followsCount"` - Handle string `json:"handle" cborgen:"handle"` - IndexedAt *string `json:"indexedAt,omitempty" cborgen:"indexedAt"` - MyState *ActorProfile_MyState `json:"myState,omitempty" cborgen:"myState"` - PostsCount int64 `json:"postsCount" cborgen:"postsCount"` - Viewer *ActorProfile_ViewerState `json:"viewer,omitempty" cborgen:"viewer"` -} - -type ActorProfile_ViewBasic struct { - LexiconTypeID string `json:"$type,omitempty"` - Avatar *string `json:"avatar,omitempty" cborgen:"avatar"` - Declaration *SystemDeclRef `json:"declaration" cborgen:"declaration"` - Description *string `json:"description,omitempty" cborgen:"description"` - Did string `json:"did" cborgen:"did"` - DisplayName *string `json:"displayName,omitempty" cborgen:"displayName"` - Handle string `json:"handle" cborgen:"handle"` - IndexedAt *string `json:"indexedAt,omitempty" cborgen:"indexedAt"` - Viewer *ActorProfile_ViewerState `json:"viewer,omitempty" cborgen:"viewer"` -} - -type ActorProfile_ViewerState struct { - LexiconTypeID string `json:"$type,omitempty"` - FollowedBy *string `json:"followedBy,omitempty" cborgen:"followedBy"` - Following *string `json:"following,omitempty" cborgen:"following"` - Muted *bool `json:"muted,omitempty" cborgen:"muted"` + LexiconTypeID string `json:"$type,const=app.bsky.actor.profile" cborgen:"$type,const=app.bsky.actor.profile"` + Avatar *util.LexBlob `json:"avatar,omitempty" cborgen:"avatar,omitempty"` + Banner *util.LexBlob `json:"banner,omitempty" cborgen:"banner,omitempty"` + Description *string `json:"description,omitempty" cborgen:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty" cborgen:"displayName,omitempty"` } diff --git a/api/bsky/actorref.go b/api/bsky/actorref.go deleted file mode 100644 index 5fafedc88..000000000 --- a/api/bsky/actorref.go +++ /dev/null @@ -1,29 +0,0 @@ -package bsky - -// schema: app.bsky.actor.ref - -func init() { -} - -type ActorRef struct { - LexiconTypeID string `json:"$type,omitempty"` - DeclarationCid string `json:"declarationCid" cborgen:"declarationCid"` - Did string `json:"did" cborgen:"did"` -} - -type ActorRef_ViewerState struct { - LexiconTypeID string `json:"$type,omitempty"` - FollowedBy *string `json:"followedBy,omitempty" cborgen:"followedBy"` - Following *string `json:"following,omitempty" cborgen:"following"` - Muted *bool `json:"muted,omitempty" cborgen:"muted"` -} - -type ActorRef_WithInfo struct { - LexiconTypeID string `json:"$type,omitempty"` - Avatar *string `json:"avatar,omitempty" cborgen:"avatar"` - Declaration *SystemDeclRef `json:"declaration" cborgen:"declaration"` - Did string `json:"did" cborgen:"did"` - DisplayName *string `json:"displayName,omitempty" cborgen:"displayName"` - Handle string `json:"handle" cborgen:"handle"` - Viewer *ActorRef_ViewerState `json:"viewer,omitempty" cborgen:"viewer"` -} diff --git a/api/bsky/actorsearch.go b/api/bsky/actorsearch.go deleted file mode 100644 index 705cda653..000000000 --- a/api/bsky/actorsearch.go +++ /dev/null @@ -1,33 +0,0 @@ -package bsky - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: app.bsky.actor.search - -func init() { -} - -type ActorSearch_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Users []*ActorProfile_ViewBasic `json:"users" cborgen:"users"` -} - -func ActorSearch(ctx context.Context, c *xrpc.Client, before string, limit int64, term string) (*ActorSearch_Output, error) { - var out ActorSearch_Output - - params := map[string]interface{}{ - "before": before, - "limit": limit, - "term": term, - } - if err := c.Do(ctx, xrpc.Query, "", "app.bsky.actor.search", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/bsky/actorsearchActors.go b/api/bsky/actorsearchActors.go new file mode 100644 index 000000000..67b9aae9d --- /dev/null +++ b/api/bsky/actorsearchActors.go @@ -0,0 +1,33 @@ +package bsky + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: app.bsky.actor.searchActors + +func init() { +} + +type ActorSearchActors_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Actors []*ActorDefs_ProfileView `json:"actors" cborgen:"actors"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` +} + +func ActorSearchActors(ctx context.Context, c *xrpc.Client, cursor string, limit int64, term string) (*ActorSearchActors_Output, error) { + var out ActorSearchActors_Output + + params := map[string]interface{}{ + "cursor": cursor, + "limit": limit, + "term": term, + } + if err := c.Do(ctx, xrpc.Query, "", "app.bsky.actor.searchActors", params, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/bsky/actorsearchActorsTypeahead.go b/api/bsky/actorsearchActorsTypeahead.go new file mode 100644 index 000000000..0f22fe7f8 --- /dev/null +++ b/api/bsky/actorsearchActorsTypeahead.go @@ -0,0 +1,31 @@ +package bsky + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: app.bsky.actor.searchActorsTypeahead + +func init() { +} + +type ActorSearchActorsTypeahead_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Actors []*ActorDefs_ProfileViewBasic `json:"actors" cborgen:"actors"` +} + +func ActorSearchActorsTypeahead(ctx context.Context, c *xrpc.Client, limit int64, term string) (*ActorSearchActorsTypeahead_Output, error) { + var out ActorSearchActorsTypeahead_Output + + params := map[string]interface{}{ + "limit": limit, + "term": term, + } + if err := c.Do(ctx, xrpc.Query, "", "app.bsky.actor.searchActorsTypeahead", params, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/bsky/actorsearchTypeahead.go b/api/bsky/actorsearchTypeahead.go deleted file mode 100644 index cbab6fc6d..000000000 --- a/api/bsky/actorsearchTypeahead.go +++ /dev/null @@ -1,31 +0,0 @@ -package bsky - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: app.bsky.actor.searchTypeahead - -func init() { -} - -type ActorSearchTypeahead_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Users []*ActorRef_WithInfo `json:"users" cborgen:"users"` -} - -func ActorSearchTypeahead(ctx context.Context, c *xrpc.Client, limit int64, term string) (*ActorSearchTypeahead_Output, error) { - var out ActorSearchTypeahead_Output - - params := map[string]interface{}{ - "limit": limit, - "term": term, - } - if err := c.Do(ctx, xrpc.Query, "", "app.bsky.actor.searchTypeahead", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/bsky/actorupdateProfile.go b/api/bsky/actorupdateProfile.go deleted file mode 100644 index f678880e8..000000000 --- a/api/bsky/actorupdateProfile.go +++ /dev/null @@ -1,37 +0,0 @@ -package bsky - -import ( - "context" - - "github.com/bluesky-social/indigo/lex/util" - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: app.bsky.actor.updateProfile - -func init() { -} - -type ActorUpdateProfile_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Avatar *util.Blob `json:"avatar,omitempty" cborgen:"avatar"` - Banner *util.Blob `json:"banner,omitempty" cborgen:"banner"` - Description *string `json:"description,omitempty" cborgen:"description"` - DisplayName *string `json:"displayName,omitempty" cborgen:"displayName"` -} - -type ActorUpdateProfile_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid string `json:"cid" cborgen:"cid"` - Record util.LexiconTypeDecoder `json:"record" cborgen:"record"` - Uri string `json:"uri" cborgen:"uri"` -} - -func ActorUpdateProfile(ctx context.Context, c *xrpc.Client, input *ActorUpdateProfile_Input) (*ActorUpdateProfile_Output, error) { - var out ActorUpdateProfile_Output - if err := c.Do(ctx, xrpc.Procedure, "application/json", "app.bsky.actor.updateProfile", nil, input, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/bsky/cbor_gen.go b/api/bsky/cbor_gen.go index 29b71fb72..922d8ce0d 100644 --- a/api/bsky/cbor_gen.go +++ b/api/bsky/cbor_gen.go @@ -27,8 +27,25 @@ func (t *FeedPost) MarshalCBOR(w io.Writer) error { } cw := cbg.NewCborWriter(w) + fieldCount := 7 - if _, err := cw.Write([]byte{166}); err != nil { + if t.Embed == nil { + fieldCount-- + } + + if t.Entities == nil { + fieldCount-- + } + + if t.Facets == nil { + fieldCount-- + } + + if t.Reply == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } @@ -75,60 +92,97 @@ func (t *FeedPost) MarshalCBOR(w io.Writer) error { } // t.Embed (bsky.FeedPost_Embed) (struct) - if len("embed") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"embed\" was too long") - } + if t.Embed != nil { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("embed"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("embed")); err != nil { - return err - } + if len("embed") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"embed\" was too long") + } - if err := t.Embed.MarshalCBOR(cw); err != nil { - return err + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("embed"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("embed")); err != nil { + return err + } + + if err := t.Embed.MarshalCBOR(cw); err != nil { + return err + } } // t.Reply (bsky.FeedPost_ReplyRef) (struct) - if len("reply") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"reply\" was too long") - } + if t.Reply != nil { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("reply"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("reply")); err != nil { - return err + if len("reply") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"reply\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("reply"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("reply")); err != nil { + return err + } + + if err := t.Reply.MarshalCBOR(cw); err != nil { + return err + } } - if err := t.Reply.MarshalCBOR(cw); err != nil { - return err + // t.Facets ([]*bsky.RichtextFacet) (slice) + if t.Facets != nil { + + if len("facets") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"facets\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("facets"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("facets")); err != nil { + return err + } + + if len(t.Facets) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Facets was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Facets))); err != nil { + return err + } + for _, v := range t.Facets { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + } } // t.Entities ([]*bsky.FeedPost_Entity) (slice) - if len("entities") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"entities\" was too long") - } + if t.Entities != nil { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("entities"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("entities")); err != nil { - return err - } + if len("entities") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"entities\" was too long") + } - if len(t.Entities) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Entities was too long") - } + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("entities"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("entities")); err != nil { + return err + } - if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Entities))); err != nil { - return err - } - for _, v := range t.Entities { - if err := v.MarshalCBOR(cw); err != nil { + if len(t.Entities) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Entities was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Entities))); err != nil { return err } + for _, v := range t.Entities { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + } } // t.CreatedAt (string) (string) @@ -256,6 +310,36 @@ func (t *FeedPost) UnmarshalCBOR(r io.Reader) (err error) { } } + // t.Facets ([]*bsky.RichtextFacet) (slice) + case "facets": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Facets: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Facets = make([]*RichtextFacet, extra) + } + + for i := 0; i < int(extra); i++ { + + var v RichtextFacet + if err := v.UnmarshalCBOR(cr); err != nil { + return err + } + + t.Facets[i] = &v + } + // t.Entities ([]*bsky.FeedPost_Entity) (slice) case "entities": @@ -467,103 +551,115 @@ func (t *FeedRepost) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *FeedVote) MarshalCBOR(w io.Writer) error { +func (t *FeedPost_Entity) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } cw := cbg.NewCborWriter(w) + fieldCount := 4 - if _, err := cw.Write([]byte{164}); err != nil { - return err - } - - // t.LexiconTypeID (string) (string) - if len("$type") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"$type\" was too long") + if t.LexiconTypeID == "" { + fieldCount-- } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } - if _, err := io.WriteString(w, string("$type")); err != nil { - return err + + // t.Type (string) (string) + if len("type") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"type\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.feed.vote"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("type"))); err != nil { return err } - if _, err := io.WriteString(w, string("app.bsky.feed.vote")); err != nil { + if _, err := io.WriteString(w, string("type")); err != nil { return err } - // t.Subject (atproto.RepoStrongRef) (struct) - if len("subject") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"subject\" was too long") + if len(t.Type) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Type was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Type))); err != nil { return err } - if _, err := io.WriteString(w, string("subject")); err != nil { + if _, err := io.WriteString(w, string(t.Type)); err != nil { return err } - if err := t.Subject.MarshalCBOR(cw); err != nil { - return err + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } } - // t.CreatedAt (string) (string) - if len("createdAt") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"createdAt\" was too long") + // t.Index (bsky.FeedPost_TextSlice) (struct) + if len("index") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"index\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("index"))); err != nil { return err } - if _, err := io.WriteString(w, string("createdAt")); err != nil { + if _, err := io.WriteString(w, string("index")); err != nil { return err } - if len(t.CreatedAt) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.CreatedAt was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.CreatedAt)); err != nil { + if err := t.Index.MarshalCBOR(cw); err != nil { return err } - // t.Direction (string) (string) - if len("direction") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"direction\" was too long") + // t.Value (string) (string) + if len("value") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"value\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("direction"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("value"))); err != nil { return err } - if _, err := io.WriteString(w, string("direction")); err != nil { + if _, err := io.WriteString(w, string("value")); err != nil { return err } - if len(t.Direction) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Direction was too long") + if len(t.Value) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Value was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Direction))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Value))); err != nil { return err } - if _, err := io.WriteString(w, string(t.Direction)); err != nil { + if _, err := io.WriteString(w, string(t.Value)); err != nil { return err } return nil } -func (t *FeedVote) UnmarshalCBOR(r io.Reader) (err error) { - *t = FeedVote{} +func (t *FeedPost_Entity) UnmarshalCBOR(r io.Reader) (err error) { + *t = FeedPost_Entity{} cr := cbg.NewCborReader(r) @@ -582,7 +678,7 @@ func (t *FeedVote) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("FeedVote: map struct too large (%d)", extra) + return fmt.Errorf("FeedPost_Entity: map struct too large (%d)", extra) } var name string @@ -600,7 +696,18 @@ func (t *FeedVote) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.LexiconTypeID (string) (string) + // t.Type (string) (string) + case "type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Type = string(sval) + } + // t.LexiconTypeID (string) (string) case "$type": { @@ -611,8 +718,8 @@ func (t *FeedVote) UnmarshalCBOR(r io.Reader) (err error) { t.LexiconTypeID = string(sval) } - // t.Subject (atproto.RepoStrongRef) (struct) - case "subject": + // t.Index (bsky.FeedPost_TextSlice) (struct) + case "index": { @@ -624,26 +731,15 @@ func (t *FeedVote) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.Subject = new(atproto.RepoStrongRef) - if err := t.Subject.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Subject pointer: %w", err) + t.Index = new(FeedPost_TextSlice) + if err := t.Index.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Index pointer: %w", err) } } } - // t.CreatedAt (string) (string) - case "createdAt": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.CreatedAt = string(sval) - } - // t.Direction (string) (string) - case "direction": + // t.Value (string) (string) + case "value": { sval, err := cbg.ReadString(cr) @@ -651,7 +747,7 @@ func (t *FeedVote) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.Direction = string(sval) + t.Value = string(sval) } default: @@ -662,107 +758,85 @@ func (t *FeedVote) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *FeedPost_Entity) MarshalCBOR(w io.Writer) error { +func (t *FeedPost_ReplyRef) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } cw := cbg.NewCborWriter(w) + fieldCount := 3 + + if t.LexiconTypeID == "" { + fieldCount-- + } - if _, err := cw.Write([]byte{164}); err != nil { + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } - // t.Type (string) (string) - if len("type") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"type\" was too long") + // t.Root (atproto.RepoStrongRef) (struct) + if len("root") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"root\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("type"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("root"))); err != nil { return err } - if _, err := io.WriteString(w, string("type")); err != nil { + if _, err := io.WriteString(w, string("root")); err != nil { return err } - if len(t.Type) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Type was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Type))); err != nil { + if err := t.Root.MarshalCBOR(cw); err != nil { return err } - if _, err := io.WriteString(w, string(t.Type)); err != nil { - return err + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } } - // t.Index (bsky.FeedPost_TextSlice) (struct) - if len("index") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"index\" was too long") + // t.Parent (atproto.RepoStrongRef) (struct) + if len("parent") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"parent\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("index"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("parent"))); err != nil { return err } - if _, err := io.WriteString(w, string("index")); err != nil { + if _, err := io.WriteString(w, string("parent")); err != nil { return err } - if err := t.Index.MarshalCBOR(cw); err != nil { + if err := t.Parent.MarshalCBOR(cw); err != nil { return err } + return nil +} - // t.Value (string) (string) - if len("value") > cbg.MaxLength { - 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 := io.WriteString(w, string("value")); err != nil { - return err - } - - if len(t.Value) > cbg.MaxLength { - 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 := io.WriteString(w, string(t.Value)); err != nil { - return err - } - - // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { - return err - } - - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { - return err - } - return nil -} - -func (t *FeedPost_Entity) UnmarshalCBOR(r io.Reader) (err error) { - *t = FeedPost_Entity{} +func (t *FeedPost_ReplyRef) UnmarshalCBOR(r io.Reader) (err error) { + *t = FeedPost_ReplyRef{} cr := cbg.NewCborReader(r) @@ -781,7 +855,7 @@ func (t *FeedPost_Entity) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("FeedPost_Entity: map struct too large (%d)", extra) + return fmt.Errorf("FeedPost_ReplyRef: map struct too large (%d)", extra) } var name string @@ -799,19 +873,8 @@ func (t *FeedPost_Entity) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.Type (string) (string) - case "type": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Type = string(sval) - } - // t.Index (bsky.FeedPost_TextSlice) (struct) - case "index": + // t.Root (atproto.RepoStrongRef) (struct) + case "root": { @@ -823,26 +886,15 @@ func (t *FeedPost_Entity) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.Index = new(FeedPost_TextSlice) - if err := t.Index.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Index pointer: %w", err) + t.Root = new(atproto.RepoStrongRef) + if err := t.Root.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Root pointer: %w", err) } } } - // t.Value (string) (string) - case "value": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Value = string(sval) - } // t.LexiconTypeID (string) (string) - case "LexiconTypeID": + case "$type": { sval, err := cbg.ReadString(cr) @@ -852,142 +904,6 @@ func (t *FeedPost_Entity) UnmarshalCBOR(r io.Reader) (err error) { t.LexiconTypeID = string(sval) } - - default: - // Field doesn't exist on this type, so ignore it - cbg.ScanForLinks(r, func(cid.Cid) {}) - } - } - - return nil -} -func (t *FeedPost_ReplyRef) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - - cw := cbg.NewCborWriter(w) - - if _, err := cw.Write([]byte{163}); err != nil { - return err - } - - // t.Root (atproto.RepoStrongRef) (struct) - if len("root") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"root\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("root"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("root")); err != nil { - return err - } - - if err := t.Root.MarshalCBOR(cw); err != nil { - return err - } - - // t.Parent (atproto.RepoStrongRef) (struct) - if len("parent") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"parent\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("parent"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("parent")); err != nil { - return err - } - - if err := t.Parent.MarshalCBOR(cw); err != nil { - return err - } - - // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { - return err - } - - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { - return err - } - return nil -} - -func (t *FeedPost_ReplyRef) UnmarshalCBOR(r io.Reader) (err error) { - *t = FeedPost_ReplyRef{} - - 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("FeedPost_ReplyRef: map struct too large (%d)", extra) - } - - var name string - n := extra - - for i := uint64(0); i < n; i++ { - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - name = string(sval) - } - - switch name { - // t.Root (atproto.RepoStrongRef) (struct) - case "root": - - { - - b, err := cr.ReadByte() - if err != nil { - return err - } - if b != cbg.CborNull[0] { - if err := cr.UnreadByte(); err != nil { - return err - } - t.Root = new(atproto.RepoStrongRef) - if err := t.Root.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Root pointer: %w", err) - } - } - - } // t.Parent (atproto.RepoStrongRef) (struct) case "parent": @@ -1008,17 +924,6 @@ func (t *FeedPost_ReplyRef) UnmarshalCBOR(r io.Reader) (err error) { } } - // t.LexiconTypeID (string) (string) - case "LexiconTypeID": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.LexiconTypeID = string(sval) - } default: // Field doesn't exist on this type, so ignore it @@ -1035,8 +940,13 @@ func (t *FeedPost_TextSlice) MarshalCBOR(w io.Writer) error { } cw := cbg.NewCborWriter(w) + fieldCount := 3 - if _, err := cw.Write([]byte{163}); err != nil { + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } @@ -1062,6 +972,32 @@ func (t *FeedPost_TextSlice) MarshalCBOR(w io.Writer) error { } } + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + // t.Start (int64) (int64) if len("start") > cbg.MaxLength { return xerrors.Errorf("Value in field \"start\" was too long") @@ -1083,29 +1019,6 @@ func (t *FeedPost_TextSlice) MarshalCBOR(w io.Writer) error { return err } } - - // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { - return err - } - - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { - return err - } return nil } @@ -1173,10 +1086,21 @@ func (t *FeedPost_TextSlice) UnmarshalCBOR(r io.Reader) (err error) { t.End = int64(extraI) } - // t.Start (int64) (int64) - case "start": - { - maj, extra, err := cr.ReadHeader() + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Start (int64) (int64) + case "start": + { + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -1199,17 +1123,6 @@ func (t *FeedPost_TextSlice) UnmarshalCBOR(r io.Reader) (err error) { t.Start = int64(extraI) } - // t.LexiconTypeID (string) (string) - case "LexiconTypeID": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.LexiconTypeID = string(sval) - } default: // Field doesn't exist on this type, so ignore it @@ -1231,6 +1144,25 @@ func (t *EmbedImages) MarshalCBOR(w io.Writer) error { return err } + // t.LexiconTypeID (string) (string) + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.embed.images"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("app.bsky.embed.images")); err != nil { + return err + } + // t.Images ([]*bsky.EmbedImages_Image) (slice) if len("images") > cbg.MaxLength { return xerrors.Errorf("Value in field \"images\" was too long") @@ -1255,29 +1187,6 @@ func (t *EmbedImages) MarshalCBOR(w io.Writer) error { return err } } - - // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { - return err - } - - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { - return err - } return nil } @@ -1319,7 +1228,18 @@ func (t *EmbedImages) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.Images ([]*bsky.EmbedImages_Image) (slice) + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Images ([]*bsky.EmbedImages_Image) (slice) case "images": maj, extra, err = cr.ReadHeader() @@ -1348,9 +1268,525 @@ func (t *EmbedImages) UnmarshalCBOR(r io.Reader) (err error) { t.Images[i] = &v } - + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *EmbedExternal) 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.LexiconTypeID (string) (string) + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.embed.external"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("app.bsky.embed.external")); err != nil { + return err + } + + // t.External (bsky.EmbedExternal_External) (struct) + if len("external") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"external\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("external"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("external")); err != nil { + return err + } + + if err := t.External.MarshalCBOR(cw); err != nil { + return err + } + return nil +} + +func (t *EmbedExternal) UnmarshalCBOR(r io.Reader) (err error) { + *t = EmbedExternal{} + + 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("EmbedExternal: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.External (bsky.EmbedExternal_External) (struct) + case "external": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.External = new(EmbedExternal_External) + if err := t.External.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.External pointer: %w", err) + } + } + + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *EmbedExternal_External) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 5 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if t.Thumb == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Uri (string) (string) + if len("uri") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"uri\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("uri"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("uri")); err != nil { + return err + } + + if len(t.Uri) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Uri was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Uri))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Uri)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + + // t.Thumb (util.LexBlob) (struct) + if t.Thumb != nil { + + if len("thumb") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"thumb\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("thumb"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("thumb")); err != nil { + return err + } + + if err := t.Thumb.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Title (string) (string) + if len("title") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"title\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("title"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("title")); err != nil { + return err + } + + if len(t.Title) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Title was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Title))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Title)); err != nil { + return err + } + + // t.Description (string) (string) + if len("description") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"description\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("description")); err != nil { + return err + } + + if len(t.Description) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Description was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Description))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Description)); err != nil { + return err + } + return nil +} + +func (t *EmbedExternal_External) UnmarshalCBOR(r io.Reader) (err error) { + *t = EmbedExternal_External{} + + 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("EmbedExternal_External: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.Uri (string) (string) + case "uri": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Uri = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Thumb (util.LexBlob) (struct) + case "thumb": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Thumb = new(util.LexBlob) + if err := t.Thumb.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Thumb pointer: %w", err) + } + } + + } + // t.Title (string) (string) + case "title": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Title = string(sval) + } + // t.Description (string) (string) + case "description": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Description = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *EmbedImages_Image) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 3 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Alt (string) (string) + if len("alt") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"alt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("alt"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("alt")); err != nil { + return err + } + + if len(t.Alt) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Alt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Alt))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Alt)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + + // t.Image (util.LexBlob) (struct) + if len("image") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"image\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("image"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("image")); err != nil { + return err + } + + if err := t.Image.MarshalCBOR(cw); err != nil { + return err + } + return nil +} + +func (t *EmbedImages_Image) UnmarshalCBOR(r io.Reader) (err error) { + *t = EmbedImages_Image{} + + 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("EmbedImages_Image: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.Alt (string) (string) + case "alt": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Alt = string(sval) + } // t.LexiconTypeID (string) (string) - case "LexiconTypeID": + case "$type": { sval, err := cbg.ReadString(cr) @@ -1360,6 +1796,26 @@ func (t *EmbedImages) UnmarshalCBOR(r io.Reader) (err error) { t.LexiconTypeID = string(sval) } + // t.Image (util.LexBlob) (struct) + case "image": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Image = new(util.LexBlob) + if err := t.Image.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Image pointer: %w", err) + } + } + + } default: // Field doesn't exist on this type, so ignore it @@ -1369,7 +1825,7 @@ func (t *EmbedImages) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *EmbedImages_PresentedImage) MarshalCBOR(w io.Writer) error { +func (t *GraphFollow) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err @@ -1377,106 +1833,79 @@ func (t *EmbedImages_PresentedImage) MarshalCBOR(w io.Writer) error { cw := cbg.NewCborWriter(w) - if _, err := cw.Write([]byte{164}); err != nil { - return err - } - - // t.Alt (string) (string) - if len("alt") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"alt\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("alt"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("alt")); err != nil { - return err - } - - if len(t.Alt) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Alt was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Alt))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Alt)); err != nil { + if _, err := cw.Write([]byte{163}); err != nil { return err } - // t.Thumb (string) (string) - if len("thumb") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"thumb\" was too long") + // t.LexiconTypeID (string) (string) + if len("$type") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"$type\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("thumb"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { return err } - if _, err := io.WriteString(w, string("thumb")); err != nil { + if _, err := io.WriteString(w, string("$type")); err != nil { return err } - if len(t.Thumb) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Thumb was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Thumb))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.graph.follow"))); err != nil { return err } - if _, err := io.WriteString(w, string(t.Thumb)); err != nil { + if _, err := io.WriteString(w, string("app.bsky.graph.follow")); err != nil { return err } - // t.Fullsize (string) (string) - if len("fullsize") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"fullsize\" was too long") + // t.Subject (string) (string) + if len("subject") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"subject\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("fullsize"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { return err } - if _, err := io.WriteString(w, string("fullsize")); err != nil { + if _, err := io.WriteString(w, string("subject")); err != nil { return err } - if len(t.Fullsize) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Fullsize was too long") + if len(t.Subject) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Subject was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Fullsize))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Subject))); err != nil { return err } - if _, err := io.WriteString(w, string(t.Fullsize)); err != nil { + if _, err := io.WriteString(w, string(t.Subject)); err != nil { return err } - // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") + // t.CreatedAt (string) (string) + if len("createdAt") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"createdAt\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { return err } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { + if _, err := io.WriteString(w, string("createdAt")); err != nil { return err } - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + if len(t.CreatedAt) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.CreatedAt was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { return err } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + if _, err := io.WriteString(w, string(t.CreatedAt)); err != nil { return err } return nil } -func (t *EmbedImages_PresentedImage) UnmarshalCBOR(r io.Reader) (err error) { - *t = EmbedImages_PresentedImage{} +func (t *GraphFollow) UnmarshalCBOR(r io.Reader) (err error) { + *t = GraphFollow{} cr := cbg.NewCborReader(r) @@ -1495,7 +1924,7 @@ func (t *EmbedImages_PresentedImage) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("EmbedImages_PresentedImage: map struct too large (%d)", extra) + return fmt.Errorf("GraphFollow: map struct too large (%d)", extra) } var name string @@ -1513,19 +1942,8 @@ func (t *EmbedImages_PresentedImage) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.Alt (string) (string) - case "alt": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Alt = string(sval) - } - // t.Thumb (string) (string) - case "thumb": + // t.LexiconTypeID (string) (string) + case "$type": { sval, err := cbg.ReadString(cr) @@ -1533,10 +1951,10 @@ func (t *EmbedImages_PresentedImage) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.Thumb = string(sval) + t.LexiconTypeID = string(sval) } - // t.Fullsize (string) (string) - case "fullsize": + // t.Subject (string) (string) + case "subject": { sval, err := cbg.ReadString(cr) @@ -1544,10 +1962,10 @@ func (t *EmbedImages_PresentedImage) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.Fullsize = string(sval) + t.Subject = string(sval) } - // t.LexiconTypeID (string) (string) - case "LexiconTypeID": + // t.CreatedAt (string) (string) + case "createdAt": { sval, err := cbg.ReadString(cr) @@ -1555,7 +1973,7 @@ func (t *EmbedImages_PresentedImage) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.LexiconTypeID = string(sval) + t.CreatedAt = string(sval) } default: @@ -1566,61 +1984,160 @@ func (t *EmbedImages_PresentedImage) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *EmbedExternal) MarshalCBOR(w io.Writer) error { +func (t *ActorProfile) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } cw := cbg.NewCborWriter(w) + fieldCount := 5 - if _, err := cw.Write([]byte{162}); err != nil { - return err + if t.Avatar == nil { + fieldCount-- } - // t.External (bsky.EmbedExternal_External) (struct) - if len("external") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"external\" was too long") + if t.Banner == nil { + fieldCount-- } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("external"))); err != nil { - return err + if t.Description == nil { + fieldCount-- } - if _, err := io.WriteString(w, string("external")); err != nil { - return err + + if t.DisplayName == nil { + fieldCount-- } - if err := t.External.MarshalCBOR(cw); err != nil { + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") + if len("$type") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"$type\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { return err } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { + if _, err := io.WriteString(w, string("$type")); err != nil { return err } - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.actor.profile"))); err != nil { return err } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + if _, err := io.WriteString(w, string("app.bsky.actor.profile")); err != nil { return err } + + // t.Avatar (util.LexBlob) (struct) + if t.Avatar != nil { + + if len("avatar") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"avatar\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("avatar"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("avatar")); err != nil { + return err + } + + if err := t.Avatar.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Banner (util.LexBlob) (struct) + if t.Banner != nil { + + if len("banner") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"banner\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("banner"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("banner")); err != nil { + return err + } + + if err := t.Banner.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Description (string) (string) + if t.Description != nil { + + if len("description") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"description\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("description")); err != nil { + return err + } + + if t.Description == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Description) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Description was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Description))); err != nil { + return err + } + if _, err := io.WriteString(w, string(*t.Description)); err != nil { + return err + } + } + } + + // t.DisplayName (string) (string) + if t.DisplayName != nil { + + if len("displayName") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"displayName\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("displayName"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("displayName")); err != nil { + return err + } + + if t.DisplayName == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.DisplayName) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.DisplayName was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.DisplayName))); err != nil { + return err + } + if _, err := io.WriteString(w, string(*t.DisplayName)); err != nil { + return err + } + } + } return nil } -func (t *EmbedExternal) UnmarshalCBOR(r io.Reader) (err error) { - *t = EmbedExternal{} +func (t *ActorProfile) UnmarshalCBOR(r io.Reader) (err error) { + *t = ActorProfile{} cr := cbg.NewCborReader(r) @@ -1639,7 +2156,7 @@ func (t *EmbedExternal) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("EmbedExternal: map struct too large (%d)", extra) + return fmt.Errorf("ActorProfile: map struct too large (%d)", extra) } var name string @@ -1657,8 +2174,19 @@ func (t *EmbedExternal) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.External (bsky.EmbedExternal_External) (struct) - case "external": + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Avatar (util.LexBlob) (struct) + case "avatar": { @@ -1670,23 +2198,74 @@ func (t *EmbedExternal) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.External = new(EmbedExternal_External) - if err := t.External.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.External pointer: %w", err) + t.Avatar = new(util.LexBlob) + if err := t.Avatar.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Avatar pointer: %w", err) } } } - // t.LexiconTypeID (string) (string) - case "LexiconTypeID": + // t.Banner (util.LexBlob) (struct) + case "banner": { - sval, err := cbg.ReadString(cr) + + b, err := cr.ReadByte() if err != nil { return err } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Banner = new(util.LexBlob) + if err := t.Banner.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Banner pointer: %w", err) + } + } - t.LexiconTypeID = string(sval) + } + // t.Description (string) (string) + case "description": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.Description = (*string)(&sval) + } + } + // t.DisplayName (string) (string) + case "displayName": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.DisplayName = (*string)(&sval) + } } default: @@ -1697,7 +2276,7 @@ func (t *EmbedExternal) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *EmbedExternal_External) MarshalCBOR(w io.Writer) error { +func (t *EmbedRecord) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err @@ -1705,122 +2284,49 @@ func (t *EmbedExternal_External) MarshalCBOR(w io.Writer) error { cw := cbg.NewCborWriter(w) - if _, err := cw.Write([]byte{165}); err != nil { - return err - } - - // t.Uri (string) (string) - if len("uri") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"uri\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("uri"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("uri")); err != nil { - return err - } - - if len(t.Uri) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Uri was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Uri))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Uri)); err != nil { - return err - } - - // t.Thumb (util.Blob) (struct) - if len("thumb") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"thumb\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("thumb"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("thumb")); err != nil { - return err - } - - if err := t.Thumb.MarshalCBOR(cw); err != nil { - return err - } - - // t.Title (string) (string) - if len("title") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"title\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("title"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("title")); err != nil { - return err - } - - if len(t.Title) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Title was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Title))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Title)); err != nil { + if _, err := cw.Write([]byte{162}); err != nil { return err } - // t.Description (string) (string) - if len("description") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"description\" was too long") + // t.LexiconTypeID (string) (string) + if len("$type") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"$type\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { return err } - if _, err := io.WriteString(w, string("description")); err != nil { + if _, err := io.WriteString(w, string("$type")); err != nil { return err } - if len(t.Description) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Description was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Description))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.embed.record"))); err != nil { return err } - if _, err := io.WriteString(w, string(t.Description)); err != nil { + if _, err := io.WriteString(w, string("app.bsky.embed.record")); err != nil { return err } - // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") + // t.Record (atproto.RepoStrongRef) (struct) + if len("record") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"record\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("record"))); err != nil { return err } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { + if _, err := io.WriteString(w, string("record")); err != nil { return err } - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + if err := t.Record.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *EmbedExternal_External) UnmarshalCBOR(r io.Reader) (err error) { - *t = EmbedExternal_External{} +func (t *EmbedRecord) UnmarshalCBOR(r io.Reader) (err error) { + *t = EmbedRecord{} cr := cbg.NewCborReader(r) @@ -1839,7 +2345,7 @@ func (t *EmbedExternal_External) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("EmbedExternal_External: map struct too large (%d)", extra) + return fmt.Errorf("EmbedRecord: map struct too large (%d)", extra) } var name string @@ -1857,8 +2363,8 @@ func (t *EmbedExternal_External) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.Uri (string) (string) - case "uri": + // t.LexiconTypeID (string) (string) + case "$type": { sval, err := cbg.ReadString(cr) @@ -1866,10 +2372,10 @@ func (t *EmbedExternal_External) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.Uri = string(sval) + t.LexiconTypeID = string(sval) } - // t.Thumb (util.Blob) (struct) - case "thumb": + // t.Record (atproto.RepoStrongRef) (struct) + case "record": { @@ -1881,46 +2387,13 @@ func (t *EmbedExternal_External) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.Thumb = new(util.Blob) - if err := t.Thumb.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Thumb pointer: %w", err) + t.Record = new(atproto.RepoStrongRef) + if err := t.Record.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Record pointer: %w", err) } } } - // t.Title (string) (string) - case "title": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Title = string(sval) - } - // t.Description (string) (string) - case "description": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Description = string(sval) - } - // t.LexiconTypeID (string) (string) - case "LexiconTypeID": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.LexiconTypeID = string(sval) - } default: // Field doesn't exist on this type, so ignore it @@ -1930,7 +2403,7 @@ func (t *EmbedExternal_External) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *EmbedImages_Image) MarshalCBOR(w io.Writer) error { +func (t *FeedLike) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err @@ -1942,72 +2415,68 @@ func (t *EmbedImages_Image) MarshalCBOR(w io.Writer) error { return err } - // t.Alt (string) (string) - if len("alt") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"alt\" was too long") + // t.LexiconTypeID (string) (string) + if len("$type") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"$type\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("alt"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { return err } - if _, err := io.WriteString(w, string("alt")); err != nil { + if _, err := io.WriteString(w, string("$type")); err != nil { return err } - if len(t.Alt) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Alt was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Alt))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.feed.like"))); err != nil { return err } - if _, err := io.WriteString(w, string(t.Alt)); err != nil { + if _, err := io.WriteString(w, string("app.bsky.feed.like")); err != nil { return err } - // t.Image (util.Blob) (struct) - if len("image") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"image\" was too long") + // t.Subject (atproto.RepoStrongRef) (struct) + if len("subject") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"subject\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("image"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { return err } - if _, err := io.WriteString(w, string("image")); err != nil { + if _, err := io.WriteString(w, string("subject")); err != nil { return err } - if err := t.Image.MarshalCBOR(cw); err != nil { + if err := t.Subject.MarshalCBOR(cw); err != nil { return err } - // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") + // t.CreatedAt (string) (string) + if len("createdAt") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"createdAt\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { return err } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { + if _, err := io.WriteString(w, string("createdAt")); err != nil { return err } - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + if len(t.CreatedAt) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.CreatedAt was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { return err } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + if _, err := io.WriteString(w, string(t.CreatedAt)); err != nil { return err } return nil } -func (t *EmbedImages_Image) UnmarshalCBOR(r io.Reader) (err error) { - *t = EmbedImages_Image{} +func (t *FeedLike) UnmarshalCBOR(r io.Reader) (err error) { + *t = FeedLike{} cr := cbg.NewCborReader(r) @@ -2026,7 +2495,7 @@ func (t *EmbedImages_Image) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("EmbedImages_Image: map struct too large (%d)", extra) + return fmt.Errorf("FeedLike: map struct too large (%d)", extra) } var name string @@ -2044,8 +2513,8 @@ func (t *EmbedImages_Image) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.Alt (string) (string) - case "alt": + // t.LexiconTypeID (string) (string) + case "$type": { sval, err := cbg.ReadString(cr) @@ -2053,10 +2522,10 @@ func (t *EmbedImages_Image) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.Alt = string(sval) + t.LexiconTypeID = string(sval) } - // t.Image (util.Blob) (struct) - case "image": + // t.Subject (atproto.RepoStrongRef) (struct) + case "subject": { @@ -2068,15 +2537,15 @@ func (t *EmbedImages_Image) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.Image = new(util.Blob) - if err := t.Image.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Image pointer: %w", err) + t.Subject = new(atproto.RepoStrongRef) + if err := t.Subject.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Subject pointer: %w", err) } } } - // t.LexiconTypeID (string) (string) - case "LexiconTypeID": + // t.CreatedAt (string) (string) + case "createdAt": { sval, err := cbg.ReadString(cr) @@ -2084,7 +2553,7 @@ func (t *EmbedImages_Image) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.LexiconTypeID = string(sval) + t.CreatedAt = string(sval) } default: @@ -2095,80 +2564,94 @@ func (t *EmbedImages_Image) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *GraphFollow) MarshalCBOR(w io.Writer) error { +func (t *RichtextFacet) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } cw := cbg.NewCborWriter(w) + fieldCount := 3 - if _, err := cw.Write([]byte{163}); err != nil { + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } // t.LexiconTypeID (string) (string) - if len("$type") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"$type\" was too long") - } + if t.LexiconTypeID != "" { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("$type")); err != nil { - return err - } + if len("$type") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"$type\" was too long") + } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.graph.follow"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("app.bsky.graph.follow")); err != nil { - return err + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } } - // t.Subject (bsky.ActorRef) (struct) - if len("subject") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"subject\" was too long") + // t.Index (bsky.RichtextFacet_ByteSlice) (struct) + if len("index") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"index\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("index"))); err != nil { return err } - if _, err := io.WriteString(w, string("subject")); err != nil { + if _, err := io.WriteString(w, string("index")); err != nil { return err } - if err := t.Subject.MarshalCBOR(cw); err != nil { + if err := t.Index.MarshalCBOR(cw); err != nil { return err } - // t.CreatedAt (string) (string) - if len("createdAt") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"createdAt\" was too long") + // t.Features ([]*bsky.RichtextFacet_Features_Elem) (slice) + if len("features") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"features\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("features"))); err != nil { return err } - if _, err := io.WriteString(w, string("createdAt")); err != nil { + if _, err := io.WriteString(w, string("features")); err != nil { return err } - if len(t.CreatedAt) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.CreatedAt was too long") + if len(t.Features) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Features was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Features))); err != nil { return err } - if _, err := io.WriteString(w, string(t.CreatedAt)); err != nil { - return err + for _, v := range t.Features { + if err := v.MarshalCBOR(cw); err != nil { + return err + } } return nil } -func (t *GraphFollow) UnmarshalCBOR(r io.Reader) (err error) { - *t = GraphFollow{} +func (t *RichtextFacet) UnmarshalCBOR(r io.Reader) (err error) { + *t = RichtextFacet{} cr := cbg.NewCborReader(r) @@ -2187,7 +2670,7 @@ func (t *GraphFollow) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("GraphFollow: map struct too large (%d)", extra) + return fmt.Errorf("RichtextFacet: map struct too large (%d)", extra) } var name string @@ -2216,8 +2699,8 @@ func (t *GraphFollow) UnmarshalCBOR(r io.Reader) (err error) { t.LexiconTypeID = string(sval) } - // t.Subject (bsky.ActorRef) (struct) - case "subject": + // t.Index (bsky.RichtextFacet_ByteSlice) (struct) + case "index": { @@ -2229,23 +2712,41 @@ func (t *GraphFollow) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.Subject = new(ActorRef) - if err := t.Subject.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Subject pointer: %w", err) + t.Index = new(RichtextFacet_ByteSlice) + if err := t.Index.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Index pointer: %w", err) } } } - // t.CreatedAt (string) (string) - case "createdAt": + // t.Features ([]*bsky.RichtextFacet_Features_Elem) (slice) + case "features": - { - sval, err := cbg.ReadString(cr) - if err != nil { + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Features: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Features = make([]*RichtextFacet_Features_Elem, extra) + } + + for i := 0; i < int(extra); i++ { + + var v RichtextFacet_Features_Elem + if err := v.UnmarshalCBOR(cr); err != nil { return err } - t.CreatedAt = string(sval) + t.Features[i] = &v } default: @@ -2256,91 +2757,97 @@ func (t *GraphFollow) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *ActorRef) MarshalCBOR(w io.Writer) error { +func (t *RichtextFacet_ByteSlice) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } cw := cbg.NewCborWriter(w) + fieldCount := 3 - if _, err := cw.Write([]byte{163}); err != nil { - return err - } - - // t.Did (string) (string) - if len("did") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"did\" was too long") + if t.LexiconTypeID == "" { + fieldCount-- } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("did"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("did")); err != nil { + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } - if len(t.Did) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Did was too long") - } + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Did))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Did)); err != nil { - return err - } + if len("$type") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"$type\" was too long") + } - // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") - } + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("$type")); err != nil { + return err + } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { - return err + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } } - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + // t.ByteEnd (int64) (int64) + if len("byteEnd") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"byteEnd\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("byteEnd"))); err != nil { return err } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + if _, err := io.WriteString(w, string("byteEnd")); err != nil { return err } - // t.DeclarationCid (string) (string) - if len("declarationCid") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"declarationCid\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("declarationCid"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("declarationCid")); err != nil { - return err + if t.ByteEnd >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.ByteEnd)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.ByteEnd-1)); err != nil { + return err + } } - if len(t.DeclarationCid) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.DeclarationCid was too long") + // t.ByteStart (int64) (int64) + if len("byteStart") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"byteStart\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.DeclarationCid))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("byteStart"))); err != nil { return err } - if _, err := io.WriteString(w, string(t.DeclarationCid)); err != nil { + if _, err := io.WriteString(w, string("byteStart")); err != nil { return err } + + if t.ByteStart >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.ByteStart)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.ByteStart-1)); err != nil { + return err + } + } return nil } -func (t *ActorRef) UnmarshalCBOR(r io.Reader) (err error) { - *t = ActorRef{} +func (t *RichtextFacet_ByteSlice) UnmarshalCBOR(r io.Reader) (err error) { + *t = RichtextFacet_ByteSlice{} cr := cbg.NewCborReader(r) @@ -2359,7 +2866,7 @@ func (t *ActorRef) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("ActorRef: map struct too large (%d)", extra) + return fmt.Errorf("RichtextFacet_ByteSlice: map struct too large (%d)", extra) } var name string @@ -2377,8 +2884,8 @@ func (t *ActorRef) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.Did (string) (string) - case "did": + // t.LexiconTypeID (string) (string) + case "$type": { sval, err := cbg.ReadString(cr) @@ -2386,29 +2893,59 @@ func (t *ActorRef) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.Did = string(sval) + t.LexiconTypeID = string(sval) } - // t.LexiconTypeID (string) (string) - case "LexiconTypeID": - + // t.ByteEnd (int64) (int64) + case "byteEnd": { - sval, err := cbg.ReadString(cr) + maj, extra, err := cr.ReadHeader() + var extraI int64 if err != nil { return err } + 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.LexiconTypeID = string(sval) + t.ByteEnd = int64(extraI) } - // t.DeclarationCid (string) (string) - case "declarationCid": - + // t.ByteStart (int64) (int64) + case "byteStart": { - sval, err := cbg.ReadString(cr) + maj, extra, err := cr.ReadHeader() + var extraI int64 if err != nil { return err } + 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.DeclarationCid = string(sval) + t.ByteStart = int64(extraI) } default: @@ -2419,7 +2956,7 @@ func (t *ActorRef) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *ActorProfile) MarshalCBOR(w io.Writer) error { +func (t *RichtextFacet_Features_Elem) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err @@ -2427,117 +2964,46 @@ func (t *ActorProfile) MarshalCBOR(w io.Writer) error { cw := cbg.NewCborWriter(w) - if _, err := cw.Write([]byte{165}); err != nil { - return err - } - - // t.LexiconTypeID (string) (string) - if len("$type") > cbg.MaxLength { - 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 := io.WriteString(w, string("$type")); err != nil { - return err - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.actor.profile"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("app.bsky.actor.profile")); err != nil { - return err - } - - // t.Avatar (util.Blob) (struct) - if len("avatar") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"avatar\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("avatar"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("avatar")); err != nil { - return err - } - - if err := t.Avatar.MarshalCBOR(cw); err != nil { + if _, err := cw.Write([]byte{162}); err != nil { return err } - // t.Banner (util.Blob) (struct) - if len("banner") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"banner\" was too long") + // t.RichtextFacet_Link (bsky.RichtextFacet_Link) (struct) + if len("RichtextFacet_Link") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"RichtextFacet_Link\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("banner"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("banner")); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("RichtextFacet_Link"))); err != nil { return err } - - if err := t.Banner.MarshalCBOR(cw); err != nil { + if _, err := io.WriteString(w, string("RichtextFacet_Link")); err != nil { return err } - // t.Description (string) (string) - if len("description") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"description\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { + if err := t.RichtextFacet_Link.MarshalCBOR(cw); err != nil { return err } - if _, err := io.WriteString(w, string("description")); err != nil { - return err - } - - if t.Description == nil { - if _, err := cw.Write(cbg.CborNull); err != nil { - return err - } - } else { - if len(*t.Description) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Description was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Description))); err != nil { - return err - } - if _, err := io.WriteString(w, string(*t.Description)); err != nil { - return err - } - } - // t.DisplayName (string) (string) - if len("displayName") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"displayName\" was too long") + // t.RichtextFacet_Mention (bsky.RichtextFacet_Mention) (struct) + if len("RichtextFacet_Mention") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"RichtextFacet_Mention\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("displayName"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("RichtextFacet_Mention"))); err != nil { return err } - if _, err := io.WriteString(w, string("displayName")); err != nil { + if _, err := io.WriteString(w, string("RichtextFacet_Mention")); err != nil { return err } - if len(t.DisplayName) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.DisplayName was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.DisplayName))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.DisplayName)); err != nil { + if err := t.RichtextFacet_Mention.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *ActorProfile) UnmarshalCBOR(r io.Reader) (err error) { - *t = ActorProfile{} +func (t *RichtextFacet_Features_Elem) UnmarshalCBOR(r io.Reader) (err error) { + *t = RichtextFacet_Features_Elem{} cr := cbg.NewCborReader(r) @@ -2556,7 +3022,7 @@ func (t *ActorProfile) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("ActorProfile: map struct too large (%d)", extra) + return fmt.Errorf("RichtextFacet_Features_Elem: map struct too large (%d)", extra) } var name string @@ -2574,19 +3040,8 @@ func (t *ActorProfile) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.LexiconTypeID (string) (string) - case "$type": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.LexiconTypeID = string(sval) - } - // t.Avatar (util.Blob) (struct) - case "avatar": + // t.RichtextFacet_Link (bsky.RichtextFacet_Link) (struct) + case "RichtextFacet_Link": { @@ -2598,15 +3053,15 @@ func (t *ActorProfile) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.Avatar = new(util.Blob) - if err := t.Avatar.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Avatar pointer: %w", err) + t.RichtextFacet_Link = new(RichtextFacet_Link) + if err := t.RichtextFacet_Link.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.RichtextFacet_Link pointer: %w", err) } } } - // t.Banner (util.Blob) (struct) - case "banner": + // t.RichtextFacet_Mention (bsky.RichtextFacet_Mention) (struct) + case "RichtextFacet_Mention": { @@ -2618,44 +3073,12 @@ func (t *ActorProfile) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.Banner = new(util.Blob) - if err := t.Banner.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Banner pointer: %w", err) - } - } - - } - // t.Description (string) (string) - case "description": - - { - b, err := cr.ReadByte() - if err != nil { - return err - } - if b != cbg.CborNull[0] { - if err := cr.UnreadByte(); err != nil { - return err - } - - sval, err := cbg.ReadString(cr) - if err != nil { - return err + t.RichtextFacet_Mention = new(RichtextFacet_Mention) + if err := t.RichtextFacet_Mention.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.RichtextFacet_Mention pointer: %w", err) } - - t.Description = (*string)(&sval) - } - } - // t.DisplayName (string) (string) - case "displayName": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err } - t.DisplayName = string(sval) } default: @@ -2666,64 +3089,76 @@ func (t *ActorProfile) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *SystemDeclaration) MarshalCBOR(w io.Writer) error { +func (t *RichtextFacet_Link) 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.LexiconTypeID (string) (string) - if len("$type") > cbg.MaxLength { - 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 := io.WriteString(w, string("$type")); err != nil { - return err - } + cw := cbg.NewCborWriter(w) + fieldCount := 2 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.system.declaration"))); err != nil { - return err + if t.LexiconTypeID == "" { + fieldCount-- } - if _, err := io.WriteString(w, string("app.bsky.system.declaration")); err != nil { + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } - // t.ActorType (string) (string) - if len("actorType") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"actorType\" was too long") + // t.Uri (string) (string) + if len("uri") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"uri\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("actorType"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("uri"))); err != nil { return err } - if _, err := io.WriteString(w, string("actorType")); err != nil { + if _, err := io.WriteString(w, string("uri")); err != nil { return err } - if len(t.ActorType) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.ActorType was too long") + if len(t.Uri) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Uri was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.ActorType))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Uri))); err != nil { return err } - if _, err := io.WriteString(w, string(t.ActorType)); err != nil { + if _, err := io.WriteString(w, string(t.Uri)); err != nil { return err } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } return nil } -func (t *SystemDeclaration) UnmarshalCBOR(r io.Reader) (err error) { - *t = SystemDeclaration{} +func (t *RichtextFacet_Link) UnmarshalCBOR(r io.Reader) (err error) { + *t = RichtextFacet_Link{} cr := cbg.NewCborReader(r) @@ -2742,7 +3177,7 @@ func (t *SystemDeclaration) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("SystemDeclaration: map struct too large (%d)", extra) + return fmt.Errorf("RichtextFacet_Link: map struct too large (%d)", extra) } var name string @@ -2760,8 +3195,8 @@ func (t *SystemDeclaration) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.LexiconTypeID (string) (string) - case "$type": + // t.Uri (string) (string) + case "uri": { sval, err := cbg.ReadString(cr) @@ -2769,10 +3204,10 @@ func (t *SystemDeclaration) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.LexiconTypeID = string(sval) + t.Uri = string(sval) } - // t.ActorType (string) (string) - case "actorType": + // t.LexiconTypeID (string) (string) + case "$type": { sval, err := cbg.ReadString(cr) @@ -2780,7 +3215,7 @@ func (t *SystemDeclaration) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.ActorType = string(sval) + t.LexiconTypeID = string(sval) } default: @@ -2791,103 +3226,76 @@ func (t *SystemDeclaration) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *GraphAssertion) MarshalCBOR(w io.Writer) error { +func (t *RichtextFacet_Mention) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } cw := cbg.NewCborWriter(w) + fieldCount := 2 - if _, err := cw.Write([]byte{164}); err != nil { - return err - } - - // t.LexiconTypeID (string) (string) - if len("$type") > cbg.MaxLength { - 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 := io.WriteString(w, string("$type")); err != nil { - return err + if t.LexiconTypeID == "" { + fieldCount-- } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.graph.assertion"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("app.bsky.graph.assertion")); err != nil { + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } - // t.Subject (bsky.ActorRef) (struct) - if len("subject") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"subject\" was too long") + // t.Did (string) (string) + if len("did") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"did\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("subject")); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("did"))); err != nil { return err } - - if err := t.Subject.MarshalCBOR(cw); err != nil { + if _, err := io.WriteString(w, string("did")); err != nil { return err } - // t.Assertion (string) (string) - if len("assertion") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"assertion\" was too long") + if len(t.Did) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Did was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("assertion"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Did))); err != nil { return err } - if _, err := io.WriteString(w, string("assertion")); err != nil { + if _, err := io.WriteString(w, string(t.Did)); err != nil { return err } - if len(t.Assertion) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Assertion was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Assertion))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Assertion)); err != nil { - return err - } + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { - // t.CreatedAt (string) (string) - if len("createdAt") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"createdAt\" was too long") - } + if len("$type") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"$type\" was too long") + } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("createdAt")); err != nil { - return err - } + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("$type")); err != nil { + return err + } - if len(t.CreatedAt) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.CreatedAt was too long") - } + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.CreatedAt)); err != nil { - return err + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } } return nil } -func (t *GraphAssertion) UnmarshalCBOR(r io.Reader) (err error) { - *t = GraphAssertion{} +func (t *RichtextFacet_Mention) UnmarshalCBOR(r io.Reader) (err error) { + *t = RichtextFacet_Mention{} cr := cbg.NewCborReader(r) @@ -2906,7 +3314,7 @@ func (t *GraphAssertion) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("GraphAssertion: map struct too large (%d)", extra) + return fmt.Errorf("RichtextFacet_Mention: map struct too large (%d)", extra) } var name string @@ -2924,39 +3332,8 @@ func (t *GraphAssertion) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.LexiconTypeID (string) (string) - case "$type": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.LexiconTypeID = string(sval) - } - // t.Subject (bsky.ActorRef) (struct) - case "subject": - - { - - b, err := cr.ReadByte() - if err != nil { - return err - } - if b != cbg.CborNull[0] { - if err := cr.UnreadByte(); err != nil { - return err - } - t.Subject = new(ActorRef) - if err := t.Subject.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Subject pointer: %w", err) - } - } - - } - // t.Assertion (string) (string) - case "assertion": + // t.Did (string) (string) + case "did": { sval, err := cbg.ReadString(cr) @@ -2964,10 +3341,10 @@ func (t *GraphAssertion) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.Assertion = string(sval) + t.Did = string(sval) } - // t.CreatedAt (string) (string) - case "createdAt": + // t.LexiconTypeID (string) (string) + case "$type": { sval, err := cbg.ReadString(cr) @@ -2975,7 +3352,7 @@ func (t *GraphAssertion) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.CreatedAt = string(sval) + t.LexiconTypeID = string(sval) } default: @@ -2986,7 +3363,7 @@ func (t *GraphAssertion) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *GraphConfirmation) MarshalCBOR(w io.Writer) error { +func (t *EmbedRecordWithMedia) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err @@ -2994,7 +3371,7 @@ func (t *GraphConfirmation) MarshalCBOR(w io.Writer) error { cw := cbg.NewCborWriter(w) - if _, err := cw.Write([]byte{164}); err != nil { + if _, err := cw.Write([]byte{163}); err != nil { return err } @@ -3010,72 +3387,49 @@ func (t *GraphConfirmation) MarshalCBOR(w io.Writer) error { return err } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.graph.confirmation"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("app.bsky.embed.recordWithMedia"))); err != nil { return err } - if _, err := io.WriteString(w, string("app.bsky.graph.confirmation")); err != nil { + if _, err := io.WriteString(w, string("app.bsky.embed.recordWithMedia")); err != nil { return err } - // t.Assertion (atproto.RepoStrongRef) (struct) - if len("assertion") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"assertion\" was too long") + // t.Media (bsky.EmbedRecordWithMedia_Media) (struct) + if len("media") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"media\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("assertion"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("media"))); err != nil { return err } - if _, err := io.WriteString(w, string("assertion")); err != nil { + if _, err := io.WriteString(w, string("media")); err != nil { return err } - if err := t.Assertion.MarshalCBOR(cw); err != nil { - return err - } - - // t.CreatedAt (string) (string) - if len("createdAt") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"createdAt\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("createdAt")); err != nil { - return err - } - - if len(t.CreatedAt) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.CreatedAt was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.CreatedAt)); err != nil { + if err := t.Media.MarshalCBOR(cw); err != nil { return err } - // t.Originator (bsky.ActorRef) (struct) - if len("originator") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"originator\" was too long") + // t.Record (bsky.EmbedRecord) (struct) + if len("record") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"record\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("originator"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("record"))); err != nil { return err } - if _, err := io.WriteString(w, string("originator")); err != nil { + if _, err := io.WriteString(w, string("record")); err != nil { return err } - if err := t.Originator.MarshalCBOR(cw); err != nil { + if err := t.Record.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *GraphConfirmation) UnmarshalCBOR(r io.Reader) (err error) { - *t = GraphConfirmation{} +func (t *EmbedRecordWithMedia) UnmarshalCBOR(r io.Reader) (err error) { + *t = EmbedRecordWithMedia{} cr := cbg.NewCborReader(r) @@ -3094,7 +3448,7 @@ func (t *GraphConfirmation) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("GraphConfirmation: map struct too large (%d)", extra) + return fmt.Errorf("EmbedRecordWithMedia: map struct too large (%d)", extra) } var name string @@ -3123,8 +3477,8 @@ func (t *GraphConfirmation) UnmarshalCBOR(r io.Reader) (err error) { t.LexiconTypeID = string(sval) } - // t.Assertion (atproto.RepoStrongRef) (struct) - case "assertion": + // t.Media (bsky.EmbedRecordWithMedia_Media) (struct) + case "media": { @@ -3136,26 +3490,15 @@ func (t *GraphConfirmation) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.Assertion = new(atproto.RepoStrongRef) - if err := t.Assertion.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Assertion pointer: %w", err) + t.Media = new(EmbedRecordWithMedia_Media) + if err := t.Media.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Media pointer: %w", err) } } } - // t.CreatedAt (string) (string) - case "createdAt": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.CreatedAt = string(sval) - } - // t.Originator (bsky.ActorRef) (struct) - case "originator": + // t.Record (bsky.EmbedRecord) (struct) + case "record": { @@ -3167,9 +3510,9 @@ func (t *GraphConfirmation) UnmarshalCBOR(r io.Reader) (err error) { if err := cr.UnreadByte(); err != nil { return err } - t.Originator = new(ActorRef) - if err := t.Originator.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Originator pointer: %w", err) + t.Record = new(EmbedRecord) + if err := t.Record.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Record pointer: %w", err) } } @@ -3183,61 +3526,92 @@ func (t *GraphConfirmation) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *EmbedRecord) MarshalCBOR(w io.Writer) error { +func (t *FeedDefs_NotFoundPost) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } cw := cbg.NewCborWriter(w) + fieldCount := 3 - if _, err := cw.Write([]byte{162}); err != nil { - return err + if t.LexiconTypeID == "" { + fieldCount-- } - // t.Record (atproto.RepoStrongRef) (struct) - if len("record") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"record\" was too long") + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("record"))); err != nil { - return err + // t.Uri (string) (string) + if len("uri") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"uri\" was too long") } - if _, err := io.WriteString(w, string("record")); err != nil { + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("uri"))); err != nil { return err } - - if err := t.Record.MarshalCBOR(cw); err != nil { + if _, err := io.WriteString(w, string("uri")); err != nil { return err } - // t.LexiconTypeID (string) (string) - if len("LexiconTypeID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"LexiconTypeID\" was too long") + if len(t.Uri) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Uri was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LexiconTypeID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Uri))); err != nil { return err } - if _, err := io.WriteString(w, string("LexiconTypeID")); err != nil { + if _, err := io.WriteString(w, string(t.Uri)); err != nil { return err } - if len(t.LexiconTypeID) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + } + + // t.NotFound (bool) (bool) + if len("notFound") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"notFound\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("notFound"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("notFound")); err != nil { return err } - if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + + if err := cbg.WriteBool(w, t.NotFound); err != nil { return err } return nil } -func (t *EmbedRecord) UnmarshalCBOR(r io.Reader) (err error) { - *t = EmbedRecord{} +func (t *FeedDefs_NotFoundPost) UnmarshalCBOR(r io.Reader) (err error) { + *t = FeedDefs_NotFoundPost{} cr := cbg.NewCborReader(r) @@ -3256,7 +3630,7 @@ func (t *EmbedRecord) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("EmbedRecord: map struct too large (%d)", extra) + return fmt.Errorf("FeedDefs_NotFoundPost: map struct too large (%d)", extra) } var name string @@ -3274,28 +3648,19 @@ func (t *EmbedRecord) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.Record (atproto.RepoStrongRef) (struct) - case "record": + // t.Uri (string) (string) + case "uri": { - - b, err := cr.ReadByte() + sval, err := cbg.ReadString(cr) if err != nil { return err } - if b != cbg.CborNull[0] { - if err := cr.UnreadByte(); err != nil { - return err - } - t.Record = new(atproto.RepoStrongRef) - if err := t.Record.UnmarshalCBOR(cr); err != nil { - return xerrors.Errorf("unmarshaling t.Record pointer: %w", err) - } - } + t.Uri = string(sval) } // t.LexiconTypeID (string) (string) - case "LexiconTypeID": + case "$type": { sval, err := cbg.ReadString(cr) @@ -3305,6 +3670,24 @@ func (t *EmbedRecord) UnmarshalCBOR(r io.Reader) (err error) { t.LexiconTypeID = string(sval) } + // t.NotFound (bool) (bool) + case "notFound": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.NotFound = false + case 21: + t.NotFound = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } default: // Field doesn't exist on this type, so ignore it diff --git a/api/bsky/embedexternal.go b/api/bsky/embedexternal.go index 99713cea7..562e47aad 100644 --- a/api/bsky/embedexternal.go +++ b/api/bsky/embedexternal.go @@ -7,30 +7,32 @@ import ( // schema: app.bsky.embed.external func init() { + util.RegisterType("app.bsky.embed.external#main", &EmbedExternal{}) } +// RECORDTYPE: EmbedExternal type EmbedExternal struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,const=app.bsky.embed.external" cborgen:"$type,const=app.bsky.embed.external"` External *EmbedExternal_External `json:"external" cborgen:"external"` } type EmbedExternal_External struct { - LexiconTypeID string `json:"$type,omitempty"` - Description string `json:"description" cborgen:"description"` - Thumb *util.Blob `json:"thumb,omitempty" cborgen:"thumb"` - Title string `json:"title" cborgen:"title"` - Uri string `json:"uri" cborgen:"uri"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Description string `json:"description" cborgen:"description"` + Thumb *util.LexBlob `json:"thumb,omitempty" cborgen:"thumb,omitempty"` + Title string `json:"title" cborgen:"title"` + Uri string `json:"uri" cborgen:"uri"` } -type EmbedExternal_Presented struct { - LexiconTypeID string `json:"$type,omitempty"` - External *EmbedExternal_PresentedExternal `json:"external" cborgen:"external"` +type EmbedExternal_View struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + External *EmbedExternal_ViewExternal `json:"external" cborgen:"external"` } -type EmbedExternal_PresentedExternal struct { - LexiconTypeID string `json:"$type,omitempty"` +type EmbedExternal_ViewExternal struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Description string `json:"description" cborgen:"description"` - Thumb *string `json:"thumb,omitempty" cborgen:"thumb"` + Thumb *string `json:"thumb,omitempty" cborgen:"thumb,omitempty"` Title string `json:"title" cborgen:"title"` Uri string `json:"uri" cborgen:"uri"` } diff --git a/api/bsky/embedimages.go b/api/bsky/embedimages.go index ae5ed4d91..2bf9da12f 100644 --- a/api/bsky/embedimages.go +++ b/api/bsky/embedimages.go @@ -7,26 +7,28 @@ import ( // schema: app.bsky.embed.images func init() { + util.RegisterType("app.bsky.embed.images#main", &EmbedImages{}) } +// RECORDTYPE: EmbedImages type EmbedImages struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,const=app.bsky.embed.images" cborgen:"$type,const=app.bsky.embed.images"` Images []*EmbedImages_Image `json:"images" cborgen:"images"` } type EmbedImages_Image struct { - LexiconTypeID string `json:"$type,omitempty"` - Alt string `json:"alt" cborgen:"alt"` - Image *util.Blob `json:"image" cborgen:"image"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Alt string `json:"alt" cborgen:"alt"` + Image *util.LexBlob `json:"image" cborgen:"image"` } -type EmbedImages_Presented struct { - LexiconTypeID string `json:"$type,omitempty"` - Images []*EmbedImages_PresentedImage `json:"images" cborgen:"images"` +type EmbedImages_View struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Images []*EmbedImages_ViewImage `json:"images" cborgen:"images"` } -type EmbedImages_PresentedImage struct { - LexiconTypeID string `json:"$type,omitempty"` +type EmbedImages_ViewImage struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Alt string `json:"alt" cborgen:"alt"` Fullsize string `json:"fullsize" cborgen:"fullsize"` Thumb string `json:"thumb" cborgen:"thumb"` diff --git a/api/bsky/embedrecord.go b/api/bsky/embedrecord.go index 710c58b00..99e9526c7 100644 --- a/api/bsky/embedrecord.go +++ b/api/bsky/embedrecord.go @@ -11,60 +11,115 @@ import ( // schema: app.bsky.embed.record func init() { + util.RegisterType("app.bsky.embed.record#main", &EmbedRecord{}) } +// RECORDTYPE: EmbedRecord type EmbedRecord struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,const=app.bsky.embed.record" cborgen:"$type,const=app.bsky.embed.record"` Record *comatprototypes.RepoStrongRef `json:"record" cborgen:"record"` } -type EmbedRecord_Presented struct { - LexiconTypeID string `json:"$type,omitempty"` - Record *EmbedRecord_Presented_Record `json:"record" cborgen:"record"` +type EmbedRecord_View struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Record *EmbedRecord_View_Record `json:"record" cborgen:"record"` } -type EmbedRecord_PresentedNotFound struct { - LexiconTypeID string `json:"$type,omitempty"` +type EmbedRecord_ViewNotFound struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Uri string `json:"uri" cborgen:"uri"` } -type EmbedRecord_PresentedRecord struct { - LexiconTypeID string `json:"$type,omitempty"` - Author *ActorRef_WithInfo `json:"author" cborgen:"author"` - Cid string `json:"cid" cborgen:"cid"` - Record util.LexiconTypeDecoder `json:"record" cborgen:"record"` - Uri string `json:"uri" cborgen:"uri"` +type EmbedRecord_ViewRecord struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Author *ActorDefs_ProfileViewBasic `json:"author" cborgen:"author"` + Cid string `json:"cid" cborgen:"cid"` + Embeds []*EmbedRecord_ViewRecord_Embeds_Elem `json:"embeds,omitempty" cborgen:"embeds,omitempty"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` + Uri string `json:"uri" cborgen:"uri"` + Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` } -type EmbedRecord_Presented_Record struct { - EmbedRecord_PresentedRecord *EmbedRecord_PresentedRecord - EmbedRecord_PresentedNotFound *EmbedRecord_PresentedNotFound +type EmbedRecord_ViewRecord_Embeds_Elem struct { + EmbedImages_View *EmbedImages_View + EmbedExternal_View *EmbedExternal_View + EmbedRecord_View *EmbedRecord_View + EmbedRecordWithMedia_View *EmbedRecordWithMedia_View } -func (t *EmbedRecord_Presented_Record) MarshalJSON() ([]byte, error) { - if t.EmbedRecord_PresentedRecord != nil { - t.EmbedRecord_PresentedRecord.LexiconTypeID = "app.bsky.embed.record#presentedRecord" - return json.Marshal(t.EmbedRecord_PresentedRecord) +func (t *EmbedRecord_ViewRecord_Embeds_Elem) MarshalJSON() ([]byte, error) { + if t.EmbedImages_View != nil { + t.EmbedImages_View.LexiconTypeID = "app.bsky.embed.images#view" + return json.Marshal(t.EmbedImages_View) } - if t.EmbedRecord_PresentedNotFound != nil { - t.EmbedRecord_PresentedNotFound.LexiconTypeID = "app.bsky.embed.record#presentedNotFound" - return json.Marshal(t.EmbedRecord_PresentedNotFound) + if t.EmbedExternal_View != nil { + t.EmbedExternal_View.LexiconTypeID = "app.bsky.embed.external#view" + return json.Marshal(t.EmbedExternal_View) + } + if t.EmbedRecord_View != nil { + t.EmbedRecord_View.LexiconTypeID = "app.bsky.embed.record#view" + return json.Marshal(t.EmbedRecord_View) + } + if t.EmbedRecordWithMedia_View != nil { + t.EmbedRecordWithMedia_View.LexiconTypeID = "app.bsky.embed.recordWithMedia#view" + return json.Marshal(t.EmbedRecordWithMedia_View) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *EmbedRecord_ViewRecord_Embeds_Elem) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "app.bsky.embed.images#view": + t.EmbedImages_View = new(EmbedImages_View) + return json.Unmarshal(b, t.EmbedImages_View) + case "app.bsky.embed.external#view": + t.EmbedExternal_View = new(EmbedExternal_View) + return json.Unmarshal(b, t.EmbedExternal_View) + case "app.bsky.embed.record#view": + t.EmbedRecord_View = new(EmbedRecord_View) + return json.Unmarshal(b, t.EmbedRecord_View) + case "app.bsky.embed.recordWithMedia#view": + t.EmbedRecordWithMedia_View = new(EmbedRecordWithMedia_View) + return json.Unmarshal(b, t.EmbedRecordWithMedia_View) + + default: + return nil + } +} + +type EmbedRecord_View_Record struct { + EmbedRecord_ViewRecord *EmbedRecord_ViewRecord + EmbedRecord_ViewNotFound *EmbedRecord_ViewNotFound +} + +func (t *EmbedRecord_View_Record) MarshalJSON() ([]byte, error) { + if t.EmbedRecord_ViewRecord != nil { + t.EmbedRecord_ViewRecord.LexiconTypeID = "app.bsky.embed.record#viewRecord" + return json.Marshal(t.EmbedRecord_ViewRecord) + } + if t.EmbedRecord_ViewNotFound != nil { + t.EmbedRecord_ViewNotFound.LexiconTypeID = "app.bsky.embed.record#viewNotFound" + return json.Marshal(t.EmbedRecord_ViewNotFound) } return nil, fmt.Errorf("cannot marshal empty enum") } -func (t *EmbedRecord_Presented_Record) UnmarshalJSON(b []byte) error { +func (t *EmbedRecord_View_Record) UnmarshalJSON(b []byte) error { typ, err := util.TypeExtract(b) if err != nil { return err } switch typ { - case "app.bsky.embed.record#presentedRecord": - t.EmbedRecord_PresentedRecord = new(EmbedRecord_PresentedRecord) - return json.Unmarshal(b, t.EmbedRecord_PresentedRecord) - case "app.bsky.embed.record#presentedNotFound": - t.EmbedRecord_PresentedNotFound = new(EmbedRecord_PresentedNotFound) - return json.Unmarshal(b, t.EmbedRecord_PresentedNotFound) + case "app.bsky.embed.record#viewRecord": + t.EmbedRecord_ViewRecord = new(EmbedRecord_ViewRecord) + return json.Unmarshal(b, t.EmbedRecord_ViewRecord) + case "app.bsky.embed.record#viewNotFound": + t.EmbedRecord_ViewNotFound = new(EmbedRecord_ViewNotFound) + return json.Unmarshal(b, t.EmbedRecord_ViewNotFound) default: return nil diff --git a/api/bsky/embedrecordWithMedia.go b/api/bsky/embedrecordWithMedia.go new file mode 100644 index 000000000..9ee05c176 --- /dev/null +++ b/api/bsky/embedrecordWithMedia.go @@ -0,0 +1,133 @@ +package bsky + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + + "github.com/bluesky-social/indigo/lex/util" + cbg "github.com/whyrusleeping/cbor-gen" +) + +// schema: app.bsky.embed.recordWithMedia + +func init() { + util.RegisterType("app.bsky.embed.recordWithMedia#main", &EmbedRecordWithMedia{}) +} + +// RECORDTYPE: EmbedRecordWithMedia +type EmbedRecordWithMedia struct { + LexiconTypeID string `json:"$type,const=app.bsky.embed.recordWithMedia" cborgen:"$type,const=app.bsky.embed.recordWithMedia"` + Media *EmbedRecordWithMedia_Media `json:"media" cborgen:"media"` + Record *EmbedRecord `json:"record" cborgen:"record"` +} + +type EmbedRecordWithMedia_Media struct { + EmbedImages *EmbedImages + EmbedExternal *EmbedExternal +} + +func (t *EmbedRecordWithMedia_Media) MarshalJSON() ([]byte, error) { + if t.EmbedImages != nil { + t.EmbedImages.LexiconTypeID = "app.bsky.embed.images" + return json.Marshal(t.EmbedImages) + } + if t.EmbedExternal != nil { + t.EmbedExternal.LexiconTypeID = "app.bsky.embed.external" + return json.Marshal(t.EmbedExternal) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *EmbedRecordWithMedia_Media) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "app.bsky.embed.images": + t.EmbedImages = new(EmbedImages) + return json.Unmarshal(b, t.EmbedImages) + case "app.bsky.embed.external": + t.EmbedExternal = new(EmbedExternal) + return json.Unmarshal(b, t.EmbedExternal) + + default: + return nil + } +} + +func (t *EmbedRecordWithMedia_Media) MarshalCBOR(w io.Writer) error { + + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if t.EmbedImages != nil { + return t.EmbedImages.MarshalCBOR(w) + } + if t.EmbedExternal != nil { + return t.EmbedExternal.MarshalCBOR(w) + } + return fmt.Errorf("cannot cbor marshal empty enum") +} +func (t *EmbedRecordWithMedia_Media) UnmarshalCBOR(r io.Reader) error { + typ, b, err := util.CborTypeExtractReader(r) + if err != nil { + return err + } + + switch typ { + case "app.bsky.embed.images": + t.EmbedImages = new(EmbedImages) + return t.EmbedImages.UnmarshalCBOR(bytes.NewReader(b)) + case "app.bsky.embed.external": + t.EmbedExternal = new(EmbedExternal) + return t.EmbedExternal.UnmarshalCBOR(bytes.NewReader(b)) + + default: + return nil + } +} + +type EmbedRecordWithMedia_View struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Media *EmbedRecordWithMedia_View_Media `json:"media" cborgen:"media"` + Record *EmbedRecord_View `json:"record" cborgen:"record"` +} + +type EmbedRecordWithMedia_View_Media struct { + EmbedImages_View *EmbedImages_View + EmbedExternal_View *EmbedExternal_View +} + +func (t *EmbedRecordWithMedia_View_Media) MarshalJSON() ([]byte, error) { + if t.EmbedImages_View != nil { + t.EmbedImages_View.LexiconTypeID = "app.bsky.embed.images#view" + return json.Marshal(t.EmbedImages_View) + } + if t.EmbedExternal_View != nil { + t.EmbedExternal_View.LexiconTypeID = "app.bsky.embed.external#view" + return json.Marshal(t.EmbedExternal_View) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *EmbedRecordWithMedia_View_Media) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "app.bsky.embed.images#view": + t.EmbedImages_View = new(EmbedImages_View) + return json.Unmarshal(b, t.EmbedImages_View) + case "app.bsky.embed.external#view": + t.EmbedExternal_View = new(EmbedExternal_View) + return json.Unmarshal(b, t.EmbedExternal_View) + + default: + return nil + } +} diff --git a/api/bsky/feeddefs.go b/api/bsky/feeddefs.go new file mode 100644 index 000000000..6668ff36a --- /dev/null +++ b/api/bsky/feeddefs.go @@ -0,0 +1,213 @@ +package bsky + +import ( + "encoding/json" + "fmt" + + "github.com/bluesky-social/indigo/lex/util" +) + +// schema: app.bsky.feed.defs + +func init() { +} + +type FeedDefs_FeedViewPost struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Post *FeedDefs_PostView `json:"post" cborgen:"post"` + Reason *FeedDefs_FeedViewPost_Reason `json:"reason,omitempty" cborgen:"reason,omitempty"` + Reply *FeedDefs_ReplyRef `json:"reply,omitempty" cborgen:"reply,omitempty"` +} + +type FeedDefs_FeedViewPost_Reason struct { + FeedDefs_ReasonRepost *FeedDefs_ReasonRepost +} + +func (t *FeedDefs_FeedViewPost_Reason) MarshalJSON() ([]byte, error) { + if t.FeedDefs_ReasonRepost != nil { + t.FeedDefs_ReasonRepost.LexiconTypeID = "app.bsky.feed.defs#reasonRepost" + return json.Marshal(t.FeedDefs_ReasonRepost) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *FeedDefs_FeedViewPost_Reason) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "app.bsky.feed.defs#reasonRepost": + t.FeedDefs_ReasonRepost = new(FeedDefs_ReasonRepost) + return json.Unmarshal(b, t.FeedDefs_ReasonRepost) + + default: + return nil + } +} + +type FeedDefs_NotFoundPost struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + NotFound bool `json:"notFound" cborgen:"notFound"` + Uri string `json:"uri" cborgen:"uri"` +} + +type FeedDefs_PostView struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Author *ActorDefs_ProfileViewBasic `json:"author" cborgen:"author"` + Cid string `json:"cid" cborgen:"cid"` + Embed *FeedDefs_PostView_Embed `json:"embed,omitempty" cborgen:"embed,omitempty"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` + LikeCount *int64 `json:"likeCount,omitempty" cborgen:"likeCount,omitempty"` + Record *util.LexiconTypeDecoder `json:"record" cborgen:"record"` + ReplyCount *int64 `json:"replyCount,omitempty" cborgen:"replyCount,omitempty"` + RepostCount *int64 `json:"repostCount,omitempty" cborgen:"repostCount,omitempty"` + Uri string `json:"uri" cborgen:"uri"` + Viewer *FeedDefs_ViewerState `json:"viewer,omitempty" cborgen:"viewer,omitempty"` +} + +type FeedDefs_PostView_Embed struct { + EmbedImages_View *EmbedImages_View + EmbedExternal_View *EmbedExternal_View + EmbedRecord_View *EmbedRecord_View + EmbedRecordWithMedia_View *EmbedRecordWithMedia_View +} + +func (t *FeedDefs_PostView_Embed) MarshalJSON() ([]byte, error) { + if t.EmbedImages_View != nil { + t.EmbedImages_View.LexiconTypeID = "app.bsky.embed.images#view" + return json.Marshal(t.EmbedImages_View) + } + if t.EmbedExternal_View != nil { + t.EmbedExternal_View.LexiconTypeID = "app.bsky.embed.external#view" + return json.Marshal(t.EmbedExternal_View) + } + if t.EmbedRecord_View != nil { + t.EmbedRecord_View.LexiconTypeID = "app.bsky.embed.record#view" + return json.Marshal(t.EmbedRecord_View) + } + if t.EmbedRecordWithMedia_View != nil { + t.EmbedRecordWithMedia_View.LexiconTypeID = "app.bsky.embed.recordWithMedia#view" + return json.Marshal(t.EmbedRecordWithMedia_View) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *FeedDefs_PostView_Embed) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "app.bsky.embed.images#view": + t.EmbedImages_View = new(EmbedImages_View) + return json.Unmarshal(b, t.EmbedImages_View) + case "app.bsky.embed.external#view": + t.EmbedExternal_View = new(EmbedExternal_View) + return json.Unmarshal(b, t.EmbedExternal_View) + case "app.bsky.embed.record#view": + t.EmbedRecord_View = new(EmbedRecord_View) + return json.Unmarshal(b, t.EmbedRecord_View) + case "app.bsky.embed.recordWithMedia#view": + t.EmbedRecordWithMedia_View = new(EmbedRecordWithMedia_View) + return json.Unmarshal(b, t.EmbedRecordWithMedia_View) + + default: + return nil + } +} + +type FeedDefs_ReasonRepost struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + By *ActorDefs_ProfileViewBasic `json:"by" cborgen:"by"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` +} + +type FeedDefs_ReplyRef struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Parent *FeedDefs_PostView `json:"parent" cborgen:"parent"` + Root *FeedDefs_PostView `json:"root" cborgen:"root"` +} + +type FeedDefs_ThreadViewPost struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Parent *FeedDefs_ThreadViewPost_Parent `json:"parent,omitempty" cborgen:"parent,omitempty"` + Post *FeedDefs_PostView `json:"post" cborgen:"post"` + Replies []*FeedDefs_ThreadViewPost_Replies_Elem `json:"replies,omitempty" cborgen:"replies,omitempty"` +} + +type FeedDefs_ThreadViewPost_Parent struct { + FeedDefs_ThreadViewPost *FeedDefs_ThreadViewPost + FeedDefs_NotFoundPost *FeedDefs_NotFoundPost +} + +func (t *FeedDefs_ThreadViewPost_Parent) MarshalJSON() ([]byte, error) { + if t.FeedDefs_ThreadViewPost != nil { + t.FeedDefs_ThreadViewPost.LexiconTypeID = "app.bsky.feed.defs#threadViewPost" + return json.Marshal(t.FeedDefs_ThreadViewPost) + } + if t.FeedDefs_NotFoundPost != nil { + t.FeedDefs_NotFoundPost.LexiconTypeID = "app.bsky.feed.defs#notFoundPost" + return json.Marshal(t.FeedDefs_NotFoundPost) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *FeedDefs_ThreadViewPost_Parent) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "app.bsky.feed.defs#threadViewPost": + t.FeedDefs_ThreadViewPost = new(FeedDefs_ThreadViewPost) + return json.Unmarshal(b, t.FeedDefs_ThreadViewPost) + case "app.bsky.feed.defs#notFoundPost": + t.FeedDefs_NotFoundPost = new(FeedDefs_NotFoundPost) + return json.Unmarshal(b, t.FeedDefs_NotFoundPost) + + default: + return nil + } +} + +type FeedDefs_ThreadViewPost_Replies_Elem struct { + FeedDefs_ThreadViewPost *FeedDefs_ThreadViewPost + FeedDefs_NotFoundPost *FeedDefs_NotFoundPost +} + +func (t *FeedDefs_ThreadViewPost_Replies_Elem) MarshalJSON() ([]byte, error) { + if t.FeedDefs_ThreadViewPost != nil { + t.FeedDefs_ThreadViewPost.LexiconTypeID = "app.bsky.feed.defs#threadViewPost" + return json.Marshal(t.FeedDefs_ThreadViewPost) + } + if t.FeedDefs_NotFoundPost != nil { + t.FeedDefs_NotFoundPost.LexiconTypeID = "app.bsky.feed.defs#notFoundPost" + return json.Marshal(t.FeedDefs_NotFoundPost) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *FeedDefs_ThreadViewPost_Replies_Elem) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "app.bsky.feed.defs#threadViewPost": + t.FeedDefs_ThreadViewPost = new(FeedDefs_ThreadViewPost) + return json.Unmarshal(b, t.FeedDefs_ThreadViewPost) + case "app.bsky.feed.defs#notFoundPost": + t.FeedDefs_NotFoundPost = new(FeedDefs_NotFoundPost) + return json.Unmarshal(b, t.FeedDefs_NotFoundPost) + + default: + return nil + } +} + +type FeedDefs_ViewerState struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Like *string `json:"like,omitempty" cborgen:"like,omitempty"` + Repost *string `json:"repost,omitempty" cborgen:"repost,omitempty"` +} diff --git a/api/bsky/feedfeedViewPost.go b/api/bsky/feedfeedViewPost.go deleted file mode 100644 index a8dba0a70..000000000 --- a/api/bsky/feedfeedViewPost.go +++ /dev/null @@ -1,59 +0,0 @@ -package bsky - -import ( - "encoding/json" - "fmt" - - "github.com/bluesky-social/indigo/lex/util" -) - -// schema: app.bsky.feed.feedViewPost - -func init() { -} - -type FeedFeedViewPost struct { - LexiconTypeID string `json:"$type,omitempty"` - Post *FeedPost_View `json:"post" cborgen:"post"` - Reason *FeedFeedViewPost_Reason `json:"reason,omitempty" cborgen:"reason"` - Reply *FeedFeedViewPost_ReplyRef `json:"reply,omitempty" cborgen:"reply"` -} - -type FeedFeedViewPost_Reason struct { - FeedFeedViewPost_ReasonRepost *FeedFeedViewPost_ReasonRepost -} - -func (t *FeedFeedViewPost_Reason) MarshalJSON() ([]byte, error) { - if t.FeedFeedViewPost_ReasonRepost != nil { - t.FeedFeedViewPost_ReasonRepost.LexiconTypeID = "app.bsky.feed.feedViewPost#reasonRepost" - return json.Marshal(t.FeedFeedViewPost_ReasonRepost) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *FeedFeedViewPost_Reason) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "app.bsky.feed.feedViewPost#reasonRepost": - t.FeedFeedViewPost_ReasonRepost = new(FeedFeedViewPost_ReasonRepost) - return json.Unmarshal(b, t.FeedFeedViewPost_ReasonRepost) - - default: - return nil - } -} - -type FeedFeedViewPost_ReasonRepost struct { - LexiconTypeID string `json:"$type,omitempty"` - By *ActorRef_WithInfo `json:"by" cborgen:"by"` - IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` -} - -type FeedFeedViewPost_ReplyRef struct { - LexiconTypeID string `json:"$type,omitempty"` - Parent *FeedPost_View `json:"parent" cborgen:"parent"` - Root *FeedPost_View `json:"root" cborgen:"root"` -} diff --git a/api/bsky/feedgetAuthorFeed.go b/api/bsky/feedgetAuthorFeed.go index a2e91d8e3..43bfde844 100644 --- a/api/bsky/feedgetAuthorFeed.go +++ b/api/bsky/feedgetAuthorFeed.go @@ -12,17 +12,17 @@ func init() { } type FeedGetAuthorFeed_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Feed []*FeedFeedViewPost `json:"feed" cborgen:"feed"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Feed []*FeedDefs_FeedViewPost `json:"feed" cborgen:"feed"` } -func FeedGetAuthorFeed(ctx context.Context, c *xrpc.Client, author string, before string, limit int64) (*FeedGetAuthorFeed_Output, error) { +func FeedGetAuthorFeed(ctx context.Context, c *xrpc.Client, actor string, cursor string, limit int64) (*FeedGetAuthorFeed_Output, error) { var out FeedGetAuthorFeed_Output params := map[string]interface{}{ - "author": author, - "before": before, + "actor": actor, + "cursor": cursor, "limit": limit, } if err := c.Do(ctx, xrpc.Query, "", "app.bsky.feed.getAuthorFeed", params, nil, &out); err != nil { diff --git a/api/bsky/feedgetLikes.go b/api/bsky/feedgetLikes.go new file mode 100644 index 000000000..3d84939a0 --- /dev/null +++ b/api/bsky/feedgetLikes.go @@ -0,0 +1,43 @@ +package bsky + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: app.bsky.feed.getLikes + +func init() { +} + +type FeedGetLikes_Like struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Actor *ActorDefs_ProfileView `json:"actor" cborgen:"actor"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` +} + +type FeedGetLikes_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Likes []*FeedGetLikes_Like `json:"likes" cborgen:"likes"` + Uri string `json:"uri" cborgen:"uri"` +} + +func FeedGetLikes(ctx context.Context, c *xrpc.Client, cid string, cursor string, limit int64, uri string) (*FeedGetLikes_Output, error) { + var out FeedGetLikes_Output + + params := map[string]interface{}{ + "cid": cid, + "cursor": cursor, + "limit": limit, + "uri": uri, + } + if err := c.Do(ctx, xrpc.Query, "", "app.bsky.feed.getLikes", params, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/bsky/feedgetPostThread.go b/api/bsky/feedgetPostThread.go index 3bfc3d744..f1bef1af3 100644 --- a/api/bsky/feedgetPostThread.go +++ b/api/bsky/feedgetPostThread.go @@ -14,30 +14,24 @@ import ( func init() { } -type FeedGetPostThread_NotFoundPost struct { - LexiconTypeID string `json:"$type,omitempty"` - NotFound bool `json:"notFound" cborgen:"notFound"` - Uri string `json:"uri" cborgen:"uri"` -} - type FeedGetPostThread_Output struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Thread *FeedGetPostThread_Output_Thread `json:"thread" cborgen:"thread"` } type FeedGetPostThread_Output_Thread struct { - FeedGetPostThread_ThreadViewPost *FeedGetPostThread_ThreadViewPost - FeedGetPostThread_NotFoundPost *FeedGetPostThread_NotFoundPost + FeedDefs_ThreadViewPost *FeedDefs_ThreadViewPost + FeedDefs_NotFoundPost *FeedDefs_NotFoundPost } func (t *FeedGetPostThread_Output_Thread) MarshalJSON() ([]byte, error) { - if t.FeedGetPostThread_ThreadViewPost != nil { - t.FeedGetPostThread_ThreadViewPost.LexiconTypeID = "app.bsky.feed.getPostThread#threadViewPost" - return json.Marshal(t.FeedGetPostThread_ThreadViewPost) + if t.FeedDefs_ThreadViewPost != nil { + t.FeedDefs_ThreadViewPost.LexiconTypeID = "app.bsky.feed.defs#threadViewPost" + return json.Marshal(t.FeedDefs_ThreadViewPost) } - if t.FeedGetPostThread_NotFoundPost != nil { - t.FeedGetPostThread_NotFoundPost.LexiconTypeID = "app.bsky.feed.getPostThread#notFoundPost" - return json.Marshal(t.FeedGetPostThread_NotFoundPost) + if t.FeedDefs_NotFoundPost != nil { + t.FeedDefs_NotFoundPost.LexiconTypeID = "app.bsky.feed.defs#notFoundPost" + return json.Marshal(t.FeedDefs_NotFoundPost) } return nil, fmt.Errorf("cannot marshal empty enum") } @@ -48,89 +42,12 @@ func (t *FeedGetPostThread_Output_Thread) UnmarshalJSON(b []byte) error { } switch typ { - case "app.bsky.feed.getPostThread#threadViewPost": - t.FeedGetPostThread_ThreadViewPost = new(FeedGetPostThread_ThreadViewPost) - return json.Unmarshal(b, t.FeedGetPostThread_ThreadViewPost) - case "app.bsky.feed.getPostThread#notFoundPost": - t.FeedGetPostThread_NotFoundPost = new(FeedGetPostThread_NotFoundPost) - return json.Unmarshal(b, t.FeedGetPostThread_NotFoundPost) - - default: - return nil - } -} - -type FeedGetPostThread_ThreadViewPost struct { - LexiconTypeID string `json:"$type,omitempty"` - Parent *FeedGetPostThread_ThreadViewPost_Parent `json:"parent,omitempty" cborgen:"parent"` - Post *FeedPost_View `json:"post" cborgen:"post"` - Replies []*FeedGetPostThread_ThreadViewPost_Replies_Elem `json:"replies,omitempty" cborgen:"replies"` -} - -type FeedGetPostThread_ThreadViewPost_Parent struct { - FeedGetPostThread_ThreadViewPost *FeedGetPostThread_ThreadViewPost - FeedGetPostThread_NotFoundPost *FeedGetPostThread_NotFoundPost -} - -func (t *FeedGetPostThread_ThreadViewPost_Parent) MarshalJSON() ([]byte, error) { - if t.FeedGetPostThread_ThreadViewPost != nil { - t.FeedGetPostThread_ThreadViewPost.LexiconTypeID = "app.bsky.feed.getPostThread#threadViewPost" - return json.Marshal(t.FeedGetPostThread_ThreadViewPost) - } - if t.FeedGetPostThread_NotFoundPost != nil { - t.FeedGetPostThread_NotFoundPost.LexiconTypeID = "app.bsky.feed.getPostThread#notFoundPost" - return json.Marshal(t.FeedGetPostThread_NotFoundPost) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *FeedGetPostThread_ThreadViewPost_Parent) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "app.bsky.feed.getPostThread#threadViewPost": - t.FeedGetPostThread_ThreadViewPost = new(FeedGetPostThread_ThreadViewPost) - return json.Unmarshal(b, t.FeedGetPostThread_ThreadViewPost) - case "app.bsky.feed.getPostThread#notFoundPost": - t.FeedGetPostThread_NotFoundPost = new(FeedGetPostThread_NotFoundPost) - return json.Unmarshal(b, t.FeedGetPostThread_NotFoundPost) - - default: - return nil - } -} - -type FeedGetPostThread_ThreadViewPost_Replies_Elem struct { - FeedGetPostThread_ThreadViewPost *FeedGetPostThread_ThreadViewPost - FeedGetPostThread_NotFoundPost *FeedGetPostThread_NotFoundPost -} - -func (t *FeedGetPostThread_ThreadViewPost_Replies_Elem) MarshalJSON() ([]byte, error) { - if t.FeedGetPostThread_ThreadViewPost != nil { - t.FeedGetPostThread_ThreadViewPost.LexiconTypeID = "app.bsky.feed.getPostThread#threadViewPost" - return json.Marshal(t.FeedGetPostThread_ThreadViewPost) - } - if t.FeedGetPostThread_NotFoundPost != nil { - t.FeedGetPostThread_NotFoundPost.LexiconTypeID = "app.bsky.feed.getPostThread#notFoundPost" - return json.Marshal(t.FeedGetPostThread_NotFoundPost) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *FeedGetPostThread_ThreadViewPost_Replies_Elem) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "app.bsky.feed.getPostThread#threadViewPost": - t.FeedGetPostThread_ThreadViewPost = new(FeedGetPostThread_ThreadViewPost) - return json.Unmarshal(b, t.FeedGetPostThread_ThreadViewPost) - case "app.bsky.feed.getPostThread#notFoundPost": - t.FeedGetPostThread_NotFoundPost = new(FeedGetPostThread_NotFoundPost) - return json.Unmarshal(b, t.FeedGetPostThread_NotFoundPost) + case "app.bsky.feed.defs#threadViewPost": + t.FeedDefs_ThreadViewPost = new(FeedDefs_ThreadViewPost) + return json.Unmarshal(b, t.FeedDefs_ThreadViewPost) + case "app.bsky.feed.defs#notFoundPost": + t.FeedDefs_NotFoundPost = new(FeedDefs_NotFoundPost) + return json.Unmarshal(b, t.FeedDefs_NotFoundPost) default: return nil diff --git a/api/bsky/feedgetRepostedBy.go b/api/bsky/feedgetRepostedBy.go index aed694a37..1d7b1429e 100644 --- a/api/bsky/feedgetRepostedBy.go +++ b/api/bsky/feedgetRepostedBy.go @@ -12,19 +12,19 @@ func init() { } type FeedGetRepostedBy_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid *string `json:"cid,omitempty" cborgen:"cid"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - RepostedBy []*ActorRef_WithInfo `json:"repostedBy" cborgen:"repostedBy"` - Uri string `json:"uri" cborgen:"uri"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + RepostedBy []*ActorDefs_ProfileView `json:"repostedBy" cborgen:"repostedBy"` + Uri string `json:"uri" cborgen:"uri"` } -func FeedGetRepostedBy(ctx context.Context, c *xrpc.Client, before string, cid string, limit int64, uri string) (*FeedGetRepostedBy_Output, error) { +func FeedGetRepostedBy(ctx context.Context, c *xrpc.Client, cid string, cursor string, limit int64, uri string) (*FeedGetRepostedBy_Output, error) { var out FeedGetRepostedBy_Output params := map[string]interface{}{ - "before": before, "cid": cid, + "cursor": cursor, "limit": limit, "uri": uri, } diff --git a/api/bsky/feedgetTimeline.go b/api/bsky/feedgetTimeline.go index 271e55eff..861305157 100644 --- a/api/bsky/feedgetTimeline.go +++ b/api/bsky/feedgetTimeline.go @@ -12,17 +12,17 @@ func init() { } type FeedGetTimeline_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Feed []*FeedFeedViewPost `json:"feed" cborgen:"feed"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Feed []*FeedDefs_FeedViewPost `json:"feed" cborgen:"feed"` } -func FeedGetTimeline(ctx context.Context, c *xrpc.Client, algorithm string, before string, limit int64) (*FeedGetTimeline_Output, error) { +func FeedGetTimeline(ctx context.Context, c *xrpc.Client, algorithm string, cursor string, limit int64) (*FeedGetTimeline_Output, error) { var out FeedGetTimeline_Output params := map[string]interface{}{ "algorithm": algorithm, - "before": before, + "cursor": cursor, "limit": limit, } if err := c.Do(ctx, xrpc.Query, "", "app.bsky.feed.getTimeline", params, nil, &out); err != nil { diff --git a/api/bsky/feedgetVotes.go b/api/bsky/feedgetVotes.go deleted file mode 100644 index fa74f3660..000000000 --- a/api/bsky/feedgetVotes.go +++ /dev/null @@ -1,45 +0,0 @@ -package bsky - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: app.bsky.feed.getVotes - -func init() { -} - -type FeedGetVotes_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cid *string `json:"cid,omitempty" cborgen:"cid"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Uri string `json:"uri" cborgen:"uri"` - Votes []*FeedGetVotes_Vote `json:"votes" cborgen:"votes"` -} - -type FeedGetVotes_Vote struct { - LexiconTypeID string `json:"$type,omitempty"` - Actor *ActorRef_WithInfo `json:"actor" cborgen:"actor"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Direction string `json:"direction" cborgen:"direction"` - IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` -} - -func FeedGetVotes(ctx context.Context, c *xrpc.Client, before string, cid string, direction string, limit int64, uri string) (*FeedGetVotes_Output, error) { - var out FeedGetVotes_Output - - params := map[string]interface{}{ - "before": before, - "cid": cid, - "direction": direction, - "limit": limit, - "uri": uri, - } - if err := c.Do(ctx, xrpc.Query, "", "app.bsky.feed.getVotes", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/bsky/feedvote.go b/api/bsky/feedlike.go similarity index 50% rename from api/bsky/feedvote.go rename to api/bsky/feedlike.go index 06d4734b2..1bfc90b9a 100644 --- a/api/bsky/feedvote.go +++ b/api/bsky/feedlike.go @@ -5,16 +5,15 @@ import ( "github.com/bluesky-social/indigo/lex/util" ) -// schema: app.bsky.feed.vote +// schema: app.bsky.feed.like func init() { - util.RegisterType("app.bsky.feed.vote", &FeedVote{}) + util.RegisterType("app.bsky.feed.like", &FeedLike{}) } -// RECORDTYPE: FeedVote -type FeedVote struct { - LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.feed.vote"` +// RECORDTYPE: FeedLike +type FeedLike struct { + LexiconTypeID string `json:"$type,const=app.bsky.feed.like" cborgen:"$type,const=app.bsky.feed.like"` CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Direction string `json:"direction" cborgen:"direction"` Subject *comatprototypes.RepoStrongRef `json:"subject" cborgen:"subject"` } diff --git a/api/bsky/feedpost.go b/api/bsky/feedpost.go index b43ff7f54..99107b891 100644 --- a/api/bsky/feedpost.go +++ b/api/bsky/feedpost.go @@ -19,18 +19,20 @@ func init() { // RECORDTYPE: FeedPost type FeedPost struct { - LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.feed.post"` + LexiconTypeID string `json:"$type,const=app.bsky.feed.post" cborgen:"$type,const=app.bsky.feed.post"` CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Embed *FeedPost_Embed `json:"embed,omitempty" cborgen:"embed"` - Entities []*FeedPost_Entity `json:"entities,omitempty" cborgen:"entities"` - Reply *FeedPost_ReplyRef `json:"reply,omitempty" cborgen:"reply"` + Embed *FeedPost_Embed `json:"embed,omitempty" cborgen:"embed,omitempty"` + Entities []*FeedPost_Entity `json:"entities,omitempty" cborgen:"entities,omitempty"` + Facets []*RichtextFacet `json:"facets,omitempty" cborgen:"facets,omitempty"` + Reply *FeedPost_ReplyRef `json:"reply,omitempty" cborgen:"reply,omitempty"` Text string `json:"text" cborgen:"text"` } type FeedPost_Embed struct { - EmbedImages *EmbedImages - EmbedExternal *EmbedExternal - EmbedRecord *EmbedRecord + EmbedImages *EmbedImages + EmbedExternal *EmbedExternal + EmbedRecord *EmbedRecord + EmbedRecordWithMedia *EmbedRecordWithMedia } func (t *FeedPost_Embed) MarshalJSON() ([]byte, error) { @@ -46,6 +48,10 @@ func (t *FeedPost_Embed) MarshalJSON() ([]byte, error) { t.EmbedRecord.LexiconTypeID = "app.bsky.embed.record" return json.Marshal(t.EmbedRecord) } + if t.EmbedRecordWithMedia != nil { + t.EmbedRecordWithMedia.LexiconTypeID = "app.bsky.embed.recordWithMedia" + return json.Marshal(t.EmbedRecordWithMedia) + } return nil, fmt.Errorf("cannot marshal empty enum") } func (t *FeedPost_Embed) UnmarshalJSON(b []byte) error { @@ -64,6 +70,9 @@ func (t *FeedPost_Embed) UnmarshalJSON(b []byte) error { case "app.bsky.embed.record": t.EmbedRecord = new(EmbedRecord) return json.Unmarshal(b, t.EmbedRecord) + case "app.bsky.embed.recordWithMedia": + t.EmbedRecordWithMedia = new(EmbedRecordWithMedia) + return json.Unmarshal(b, t.EmbedRecordWithMedia) default: return nil @@ -85,6 +94,9 @@ func (t *FeedPost_Embed) MarshalCBOR(w io.Writer) error { if t.EmbedRecord != nil { return t.EmbedRecord.MarshalCBOR(w) } + if t.EmbedRecordWithMedia != nil { + return t.EmbedRecordWithMedia.MarshalCBOR(w) + } return fmt.Errorf("cannot cbor marshal empty enum") } func (t *FeedPost_Embed) UnmarshalCBOR(r io.Reader) error { @@ -103,6 +115,9 @@ func (t *FeedPost_Embed) UnmarshalCBOR(r io.Reader) error { case "app.bsky.embed.record": t.EmbedRecord = new(EmbedRecord) return t.EmbedRecord.UnmarshalCBOR(bytes.NewReader(b)) + case "app.bsky.embed.recordWithMedia": + t.EmbedRecordWithMedia = new(EmbedRecordWithMedia) + return t.EmbedRecordWithMedia.UnmarshalCBOR(bytes.NewReader(b)) default: return nil @@ -110,85 +125,20 @@ func (t *FeedPost_Embed) UnmarshalCBOR(r io.Reader) error { } type FeedPost_Entity struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Index *FeedPost_TextSlice `json:"index" cborgen:"index"` Type string `json:"type" cborgen:"type"` Value string `json:"value" cborgen:"value"` } type FeedPost_ReplyRef struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` Parent *comatprototypes.RepoStrongRef `json:"parent" cborgen:"parent"` Root *comatprototypes.RepoStrongRef `json:"root" cborgen:"root"` } type FeedPost_TextSlice struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` End int64 `json:"end" cborgen:"end"` Start int64 `json:"start" cborgen:"start"` } - -type FeedPost_View struct { - LexiconTypeID string `json:"$type,omitempty"` - Author *ActorRef_WithInfo `json:"author" cborgen:"author"` - Cid string `json:"cid" cborgen:"cid"` - DownvoteCount int64 `json:"downvoteCount" cborgen:"downvoteCount"` - Embed *FeedPost_View_Embed `json:"embed,omitempty" cborgen:"embed"` - IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` - Record util.LexiconTypeDecoder `json:"record" cborgen:"record"` - ReplyCount int64 `json:"replyCount" cborgen:"replyCount"` - RepostCount int64 `json:"repostCount" cborgen:"repostCount"` - UpvoteCount int64 `json:"upvoteCount" cborgen:"upvoteCount"` - Uri string `json:"uri" cborgen:"uri"` - Viewer *FeedPost_ViewerState `json:"viewer" cborgen:"viewer"` -} - -type FeedPost_View_Embed struct { - EmbedImages_Presented *EmbedImages_Presented - EmbedExternal_Presented *EmbedExternal_Presented - EmbedRecord_Presented *EmbedRecord_Presented -} - -func (t *FeedPost_View_Embed) MarshalJSON() ([]byte, error) { - if t.EmbedImages_Presented != nil { - t.EmbedImages_Presented.LexiconTypeID = "app.bsky.embed.images#presented" - return json.Marshal(t.EmbedImages_Presented) - } - if t.EmbedExternal_Presented != nil { - t.EmbedExternal_Presented.LexiconTypeID = "app.bsky.embed.external#presented" - return json.Marshal(t.EmbedExternal_Presented) - } - if t.EmbedRecord_Presented != nil { - t.EmbedRecord_Presented.LexiconTypeID = "app.bsky.embed.record#presented" - return json.Marshal(t.EmbedRecord_Presented) - } - return nil, fmt.Errorf("cannot marshal empty enum") -} -func (t *FeedPost_View_Embed) UnmarshalJSON(b []byte) error { - typ, err := util.TypeExtract(b) - if err != nil { - return err - } - - switch typ { - case "app.bsky.embed.images#presented": - t.EmbedImages_Presented = new(EmbedImages_Presented) - return json.Unmarshal(b, t.EmbedImages_Presented) - case "app.bsky.embed.external#presented": - t.EmbedExternal_Presented = new(EmbedExternal_Presented) - return json.Unmarshal(b, t.EmbedExternal_Presented) - case "app.bsky.embed.record#presented": - t.EmbedRecord_Presented = new(EmbedRecord_Presented) - return json.Unmarshal(b, t.EmbedRecord_Presented) - - default: - return nil - } -} - -type FeedPost_ViewerState struct { - LexiconTypeID string `json:"$type,omitempty"` - Downvote *string `json:"downvote,omitempty" cborgen:"downvote"` - Repost *string `json:"repost,omitempty" cborgen:"repost"` - Upvote *string `json:"upvote,omitempty" cborgen:"upvote"` -} diff --git a/api/bsky/feedrepost.go b/api/bsky/feedrepost.go index 15501c5c1..e49fdc14e 100644 --- a/api/bsky/feedrepost.go +++ b/api/bsky/feedrepost.go @@ -13,7 +13,7 @@ func init() { // RECORDTYPE: FeedRepost type FeedRepost struct { - LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.feed.repost"` + LexiconTypeID string `json:"$type,const=app.bsky.feed.repost" cborgen:"$type,const=app.bsky.feed.repost"` CreatedAt string `json:"createdAt" cborgen:"createdAt"` Subject *comatprototypes.RepoStrongRef `json:"subject" cborgen:"subject"` } diff --git a/api/bsky/feedsetVote.go b/api/bsky/feedsetVote.go deleted file mode 100644 index 8695e8dee..000000000 --- a/api/bsky/feedsetVote.go +++ /dev/null @@ -1,34 +0,0 @@ -package bsky - -import ( - "context" - - comatprototypes "github.com/bluesky-social/indigo/api/atproto" - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: app.bsky.feed.setVote - -func init() { -} - -type FeedSetVote_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - Direction string `json:"direction" cborgen:"direction"` - Subject *comatprototypes.RepoStrongRef `json:"subject" cborgen:"subject"` -} - -type FeedSetVote_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Downvote *string `json:"downvote,omitempty" cborgen:"downvote"` - Upvote *string `json:"upvote,omitempty" cborgen:"upvote"` -} - -func FeedSetVote(ctx context.Context, c *xrpc.Client, input *FeedSetVote_Input) (*FeedSetVote_Output, error) { - var out FeedSetVote_Output - if err := c.Do(ctx, xrpc.Procedure, "application/json", "app.bsky.feed.setVote", nil, input, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/bsky/graphassertCreator.go b/api/bsky/graphassertCreator.go deleted file mode 100644 index 5835fed7d..000000000 --- a/api/bsky/graphassertCreator.go +++ /dev/null @@ -1,8 +0,0 @@ -package bsky - -// schema: app.bsky.graph.assertCreator - -func init() { -} - -const GraphAssertCreator = "app.bsky.graph.assertCreator" diff --git a/api/bsky/graphassertMember.go b/api/bsky/graphassertMember.go deleted file mode 100644 index dea162dc4..000000000 --- a/api/bsky/graphassertMember.go +++ /dev/null @@ -1,8 +0,0 @@ -package bsky - -// schema: app.bsky.graph.assertMember - -func init() { -} - -const GraphAssertMember = "app.bsky.graph.assertMember" diff --git a/api/bsky/graphassertion.go b/api/bsky/graphassertion.go deleted file mode 100644 index 7c3124af4..000000000 --- a/api/bsky/graphassertion.go +++ /dev/null @@ -1,19 +0,0 @@ -package bsky - -import ( - "github.com/bluesky-social/indigo/lex/util" -) - -// schema: app.bsky.graph.assertion - -func init() { - util.RegisterType("app.bsky.graph.assertion", &GraphAssertion{}) -} - -// RECORDTYPE: GraphAssertion -type GraphAssertion struct { - LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.graph.assertion"` - Assertion string `json:"assertion" cborgen:"assertion"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Subject *ActorRef `json:"subject" cborgen:"subject"` -} diff --git a/api/bsky/graphconfirmation.go b/api/bsky/graphconfirmation.go deleted file mode 100644 index 8a61383c2..000000000 --- a/api/bsky/graphconfirmation.go +++ /dev/null @@ -1,20 +0,0 @@ -package bsky - -import ( - comatprototypes "github.com/bluesky-social/indigo/api/atproto" - "github.com/bluesky-social/indigo/lex/util" -) - -// schema: app.bsky.graph.confirmation - -func init() { - util.RegisterType("app.bsky.graph.confirmation", &GraphConfirmation{}) -} - -// RECORDTYPE: GraphConfirmation -type GraphConfirmation struct { - LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.graph.confirmation"` - Assertion *comatprototypes.RepoStrongRef `json:"assertion" cborgen:"assertion"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Originator *ActorRef `json:"originator" cborgen:"originator"` -} diff --git a/api/bsky/graphfollow.go b/api/bsky/graphfollow.go index 1786532dc..07e16d638 100644 --- a/api/bsky/graphfollow.go +++ b/api/bsky/graphfollow.go @@ -12,7 +12,7 @@ func init() { // RECORDTYPE: GraphFollow type GraphFollow struct { - LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.graph.follow"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Subject *ActorRef `json:"subject" cborgen:"subject"` + LexiconTypeID string `json:"$type,const=app.bsky.graph.follow" cborgen:"$type,const=app.bsky.graph.follow"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Subject string `json:"subject" cborgen:"subject"` } diff --git a/api/bsky/graphgetFollowers.go b/api/bsky/graphgetFollowers.go index c2ba51a6a..1e06b88b1 100644 --- a/api/bsky/graphgetFollowers.go +++ b/api/bsky/graphgetFollowers.go @@ -12,19 +12,19 @@ func init() { } type GraphGetFollowers_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Followers []*ActorRef_WithInfo `json:"followers" cborgen:"followers"` - Subject *ActorRef_WithInfo `json:"subject" cborgen:"subject"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Followers []*ActorDefs_ProfileView `json:"followers" cborgen:"followers"` + Subject *ActorDefs_ProfileView `json:"subject" cborgen:"subject"` } -func GraphGetFollowers(ctx context.Context, c *xrpc.Client, before string, limit int64, user string) (*GraphGetFollowers_Output, error) { +func GraphGetFollowers(ctx context.Context, c *xrpc.Client, actor string, cursor string, limit int64) (*GraphGetFollowers_Output, error) { var out GraphGetFollowers_Output params := map[string]interface{}{ - "before": before, + "actor": actor, + "cursor": cursor, "limit": limit, - "user": user, } if err := c.Do(ctx, xrpc.Query, "", "app.bsky.graph.getFollowers", params, nil, &out); err != nil { return nil, err diff --git a/api/bsky/graphgetFollows.go b/api/bsky/graphgetFollows.go index c38ae6f5a..bcbc6c5ba 100644 --- a/api/bsky/graphgetFollows.go +++ b/api/bsky/graphgetFollows.go @@ -12,19 +12,19 @@ func init() { } type GraphGetFollows_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Follows []*ActorRef_WithInfo `json:"follows" cborgen:"follows"` - Subject *ActorRef_WithInfo `json:"subject" cborgen:"subject"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Follows []*ActorDefs_ProfileView `json:"follows" cborgen:"follows"` + Subject *ActorDefs_ProfileView `json:"subject" cborgen:"subject"` } -func GraphGetFollows(ctx context.Context, c *xrpc.Client, before string, limit int64, user string) (*GraphGetFollows_Output, error) { +func GraphGetFollows(ctx context.Context, c *xrpc.Client, actor string, cursor string, limit int64) (*GraphGetFollows_Output, error) { var out GraphGetFollows_Output params := map[string]interface{}{ - "before": before, + "actor": actor, + "cursor": cursor, "limit": limit, - "user": user, } if err := c.Do(ctx, xrpc.Query, "", "app.bsky.graph.getFollows", params, nil, &out); err != nil { return nil, err diff --git a/api/bsky/graphgetMutes.go b/api/bsky/graphgetMutes.go index bbc3ba028..f24ac7be3 100644 --- a/api/bsky/graphgetMutes.go +++ b/api/bsky/graphgetMutes.go @@ -12,16 +12,16 @@ func init() { } type GraphGetMutes_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Mutes []*ActorRef_WithInfo `json:"mutes" cborgen:"mutes"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Mutes []*ActorDefs_ProfileView `json:"mutes" cborgen:"mutes"` } -func GraphGetMutes(ctx context.Context, c *xrpc.Client, before string, limit int64) (*GraphGetMutes_Output, error) { +func GraphGetMutes(ctx context.Context, c *xrpc.Client, cursor string, limit int64) (*GraphGetMutes_Output, error) { var out GraphGetMutes_Output params := map[string]interface{}{ - "before": before, + "cursor": cursor, "limit": limit, } if err := c.Do(ctx, xrpc.Query, "", "app.bsky.graph.getMutes", params, nil, &out); err != nil { diff --git a/api/bsky/graphmute.go b/api/bsky/graphmute.go deleted file mode 100644 index f2d049932..000000000 --- a/api/bsky/graphmute.go +++ /dev/null @@ -1,25 +0,0 @@ -package bsky - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: app.bsky.graph.mute - -func init() { -} - -type GraphMute_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - User string `json:"user" cborgen:"user"` -} - -func GraphMute(ctx context.Context, c *xrpc.Client, input *GraphMute_Input) error { - if err := c.Do(ctx, xrpc.Procedure, "application/json", "app.bsky.graph.mute", nil, input, nil); err != nil { - return err - } - - return nil -} diff --git a/api/bsky/graphmuteActor.go b/api/bsky/graphmuteActor.go new file mode 100644 index 000000000..17222c60a --- /dev/null +++ b/api/bsky/graphmuteActor.go @@ -0,0 +1,25 @@ +package bsky + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: app.bsky.graph.muteActor + +func init() { +} + +type GraphMuteActor_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Actor string `json:"actor" cborgen:"actor"` +} + +func GraphMuteActor(ctx context.Context, c *xrpc.Client, input *GraphMuteActor_Input) error { + if err := c.Do(ctx, xrpc.Procedure, "application/json", "app.bsky.graph.muteActor", nil, input, nil); err != nil { + return err + } + + return nil +} diff --git a/api/bsky/graphunmute.go b/api/bsky/graphunmute.go deleted file mode 100644 index 1d73b851a..000000000 --- a/api/bsky/graphunmute.go +++ /dev/null @@ -1,25 +0,0 @@ -package bsky - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: app.bsky.graph.unmute - -func init() { -} - -type GraphUnmute_Input struct { - LexiconTypeID string `json:"$type,omitempty"` - User string `json:"user" cborgen:"user"` -} - -func GraphUnmute(ctx context.Context, c *xrpc.Client, input *GraphUnmute_Input) error { - if err := c.Do(ctx, xrpc.Procedure, "application/json", "app.bsky.graph.unmute", nil, input, nil); err != nil { - return err - } - - return nil -} diff --git a/api/bsky/graphunmuteActor.go b/api/bsky/graphunmuteActor.go new file mode 100644 index 000000000..9bf4ef1bb --- /dev/null +++ b/api/bsky/graphunmuteActor.go @@ -0,0 +1,25 @@ +package bsky + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: app.bsky.graph.unmuteActor + +func init() { +} + +type GraphUnmuteActor_Input struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Actor string `json:"actor" cborgen:"actor"` +} + +func GraphUnmuteActor(ctx context.Context, c *xrpc.Client, input *GraphUnmuteActor_Input) error { + if err := c.Do(ctx, xrpc.Procedure, "application/json", "app.bsky.graph.unmuteActor", nil, input, nil); err != nil { + return err + } + + return nil +} diff --git a/api/bsky/notificationgetCount.go b/api/bsky/notificationgetCount.go deleted file mode 100644 index 17215b552..000000000 --- a/api/bsky/notificationgetCount.go +++ /dev/null @@ -1,26 +0,0 @@ -package bsky - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: app.bsky.notification.getCount - -func init() { -} - -type NotificationGetCount_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Count int64 `json:"count" cborgen:"count"` -} - -func NotificationGetCount(ctx context.Context, c *xrpc.Client) (*NotificationGetCount_Output, error) { - var out NotificationGetCount_Output - if err := c.Do(ctx, xrpc.Query, "", "app.bsky.notification.getCount", nil, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/bsky/notificationgetUnreadCount.go b/api/bsky/notificationgetUnreadCount.go new file mode 100644 index 000000000..47acd34b2 --- /dev/null +++ b/api/bsky/notificationgetUnreadCount.go @@ -0,0 +1,26 @@ +package bsky + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: app.bsky.notification.getUnreadCount + +func init() { +} + +type NotificationGetUnreadCount_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Count int64 `json:"count" cborgen:"count"` +} + +func NotificationGetUnreadCount(ctx context.Context, c *xrpc.Client) (*NotificationGetUnreadCount_Output, error) { + var out NotificationGetUnreadCount_Output + if err := c.Do(ctx, xrpc.Query, "", "app.bsky.notification.getUnreadCount", nil, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/bsky/notificationlist.go b/api/bsky/notificationlist.go deleted file mode 100644 index 67fb789dc..000000000 --- a/api/bsky/notificationlist.go +++ /dev/null @@ -1,45 +0,0 @@ -package bsky - -import ( - "context" - - "github.com/bluesky-social/indigo/lex/util" - "github.com/bluesky-social/indigo/xrpc" -) - -// schema: app.bsky.notification.list - -func init() { -} - -type NotificationList_Notification struct { - LexiconTypeID string `json:"$type,omitempty"` - Author *ActorRef_WithInfo `json:"author" cborgen:"author"` - Cid string `json:"cid" cborgen:"cid"` - IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` - IsRead bool `json:"isRead" cborgen:"isRead"` - Reason string `json:"reason" cborgen:"reason"` - ReasonSubject *string `json:"reasonSubject,omitempty" cborgen:"reasonSubject"` - Record util.LexiconTypeDecoder `json:"record" cborgen:"record"` - Uri string `json:"uri" cborgen:"uri"` -} - -type NotificationList_Output struct { - LexiconTypeID string `json:"$type,omitempty"` - Cursor *string `json:"cursor,omitempty" cborgen:"cursor"` - Notifications []*NotificationList_Notification `json:"notifications" cborgen:"notifications"` -} - -func NotificationList(ctx context.Context, c *xrpc.Client, before string, limit int64) (*NotificationList_Output, error) { - var out NotificationList_Output - - params := map[string]interface{}{ - "before": before, - "limit": limit, - } - if err := c.Do(ctx, xrpc.Query, "", "app.bsky.notification.list", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/api/bsky/notificationlistNotifications.go b/api/bsky/notificationlistNotifications.go new file mode 100644 index 000000000..0d7ec3c94 --- /dev/null +++ b/api/bsky/notificationlistNotifications.go @@ -0,0 +1,45 @@ +package bsky + +import ( + "context" + + "github.com/bluesky-social/indigo/lex/util" + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: app.bsky.notification.listNotifications + +func init() { +} + +type NotificationListNotifications_Notification struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Author *ActorDefs_ProfileView `json:"author" cborgen:"author"` + Cid string `json:"cid" cborgen:"cid"` + IndexedAt string `json:"indexedAt" cborgen:"indexedAt"` + IsRead bool `json:"isRead" cborgen:"isRead"` + Reason string `json:"reason" cborgen:"reason"` + ReasonSubject *string `json:"reasonSubject,omitempty" cborgen:"reasonSubject,omitempty"` + Record *util.LexiconTypeDecoder `json:"record" cborgen:"record"` + Uri string `json:"uri" cborgen:"uri"` +} + +type NotificationListNotifications_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Notifications []*NotificationListNotifications_Notification `json:"notifications" cborgen:"notifications"` +} + +func NotificationListNotifications(ctx context.Context, c *xrpc.Client, cursor string, limit int64) (*NotificationListNotifications_Output, error) { + var out NotificationListNotifications_Output + + params := map[string]interface{}{ + "cursor": cursor, + "limit": limit, + } + if err := c.Do(ctx, xrpc.Query, "", "app.bsky.notification.listNotifications", params, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/bsky/notificationupdateSeen.go b/api/bsky/notificationupdateSeen.go index 3c731ead1..6c9a777fe 100644 --- a/api/bsky/notificationupdateSeen.go +++ b/api/bsky/notificationupdateSeen.go @@ -12,7 +12,7 @@ func init() { } type NotificationUpdateSeen_Input struct { - LexiconTypeID string `json:"$type,omitempty"` + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` SeenAt string `json:"seenAt" cborgen:"seenAt"` } diff --git a/api/bsky/richtextfacet.go b/api/bsky/richtextfacet.go new file mode 100644 index 000000000..110eb3dfe --- /dev/null +++ b/api/bsky/richtextfacet.go @@ -0,0 +1,70 @@ +package bsky + +import ( + "encoding/json" + "fmt" + + "github.com/bluesky-social/indigo/lex/util" +) + +// schema: app.bsky.richtext.facet + +func init() { +} + +type RichtextFacet struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Features []*RichtextFacet_Features_Elem `json:"features" cborgen:"features"` + Index *RichtextFacet_ByteSlice `json:"index" cborgen:"index"` +} + +type RichtextFacet_ByteSlice struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + ByteEnd int64 `json:"byteEnd" cborgen:"byteEnd"` + ByteStart int64 `json:"byteStart" cborgen:"byteStart"` +} + +type RichtextFacet_Features_Elem struct { + RichtextFacet_Mention *RichtextFacet_Mention + RichtextFacet_Link *RichtextFacet_Link +} + +func (t *RichtextFacet_Features_Elem) MarshalJSON() ([]byte, error) { + if t.RichtextFacet_Mention != nil { + t.RichtextFacet_Mention.LexiconTypeID = "app.bsky.richtext.facet#mention" + return json.Marshal(t.RichtextFacet_Mention) + } + if t.RichtextFacet_Link != nil { + t.RichtextFacet_Link.LexiconTypeID = "app.bsky.richtext.facet#link" + return json.Marshal(t.RichtextFacet_Link) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *RichtextFacet_Features_Elem) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "app.bsky.richtext.facet#mention": + t.RichtextFacet_Mention = new(RichtextFacet_Mention) + return json.Unmarshal(b, t.RichtextFacet_Mention) + case "app.bsky.richtext.facet#link": + t.RichtextFacet_Link = new(RichtextFacet_Link) + return json.Unmarshal(b, t.RichtextFacet_Link) + + default: + return nil + } +} + +type RichtextFacet_Link struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Uri string `json:"uri" cborgen:"uri"` +} + +type RichtextFacet_Mention struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Did string `json:"did" cborgen:"did"` +} diff --git a/api/bsky/systemactorUser.go b/api/bsky/systemactorUser.go deleted file mode 100644 index d4f60b8d7..000000000 --- a/api/bsky/systemactorUser.go +++ /dev/null @@ -1,8 +0,0 @@ -package bsky - -// schema: app.bsky.system.actorUser - -func init() { -} - -const SystemActorUser = "app.bsky.system.actorUser" diff --git a/api/bsky/systemdeclRef.go b/api/bsky/systemdeclRef.go deleted file mode 100644 index e949db16a..000000000 --- a/api/bsky/systemdeclRef.go +++ /dev/null @@ -1,12 +0,0 @@ -package bsky - -// schema: app.bsky.system.declRef - -func init() { -} - -type SystemDeclRef struct { - LexiconTypeID string `json:"$type,omitempty"` - ActorType string `json:"actorType" cborgen:"actorType"` - Cid string `json:"cid" cborgen:"cid"` -} diff --git a/api/bsky/systemdeclaration.go b/api/bsky/systemdeclaration.go deleted file mode 100644 index 6465e2e73..000000000 --- a/api/bsky/systemdeclaration.go +++ /dev/null @@ -1,17 +0,0 @@ -package bsky - -import ( - "github.com/bluesky-social/indigo/lex/util" -) - -// schema: app.bsky.system.declaration - -func init() { - util.RegisterType("app.bsky.system.declaration", &SystemDeclaration{}) -} - -// RECORDTYPE: SystemDeclaration -type SystemDeclaration struct { - LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.system.declaration"` - ActorType string `json:"actorType" cborgen:"actorType"` -} diff --git a/api/bsky/unspeccedgetPopular.go b/api/bsky/unspeccedgetPopular.go new file mode 100644 index 000000000..2caddfd7e --- /dev/null +++ b/api/bsky/unspeccedgetPopular.go @@ -0,0 +1,32 @@ +package bsky + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// schema: app.bsky.unspecced.getPopular + +func init() { +} + +type UnspeccedGetPopular_Output struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,omitempty"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Feed []*FeedDefs_FeedViewPost `json:"feed" cborgen:"feed"` +} + +func UnspeccedGetPopular(ctx context.Context, c *xrpc.Client, cursor string, limit int64) (*UnspeccedGetPopular_Output, error) { + var out UnspeccedGetPopular_Output + + params := map[string]interface{}{ + "cursor": cursor, + "limit": limit, + } + if err := c.Do(ctx, xrpc.Query, "", "app.bsky.unspecced.getPopular", params, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/extra.go b/api/extra.go index 4744e1caf..f55cdf354 100644 --- a/api/extra.go +++ b/api/extra.go @@ -49,7 +49,7 @@ func ResolveDidToHandle(ctx context.Context, xrpcc *xrpc.Client, pls *PLCServer, return "", "", fmt.Errorf("our XRPC client is authed for a different pds (%s != %s)", svc.ServiceEndpoint, xrpcc.Host) } - verdid, err := comatproto.HandleResolve(ctx, xrpcc, handle) + verdid, err := comatproto.IdentityResolveHandle(ctx, xrpcc, handle) if err != nil { return "", "", err } diff --git a/bgs/bgs.go b/bgs/bgs.go index 41e9d5ccc..082e450b4 100644 --- a/bgs/bgs.go +++ b/bgs/bgs.go @@ -168,7 +168,7 @@ func (bgs *BGS) Start(listen string) error { // TODO: this API is temporary until we formalize what we want here - e.GET("/xrpc/com.atproto.sync.subscribeAllRepos", bgs.EventsHandler) + e.GET("/xrpc/com.atproto.sync.subscribeRepos", bgs.EventsHandler) e.GET("/xrpc/com.atproto.sync.getCheckout", bgs.HandleComAtprotoSyncGetCheckout) e.GET("/xrpc/com.atproto.sync.getCommitPath", bgs.HandleComAtprotoSyncGetCommitPath) @@ -235,7 +235,7 @@ func (bgs *BGS) EventsHandler(c echo.Context) error { } defer cancel() - header := events.EventHeader{Op: events.EvtKindRepoAppend} + header := events.EventHeader{Op: events.EvtKindMessage} for { select { case evt := <-evts: @@ -247,15 +247,24 @@ func (bgs *BGS) EventsHandler(c echo.Context) error { var obj lexutil.CBOR switch { - case evt.RepoAppend != nil: - header.Op = events.EvtKindRepoAppend - obj = evt.RepoAppend case evt.Error != nil: header.Op = events.EvtKindErrorFrame obj = evt.Error - case evt.Info != nil: - header.Op = events.EvtKindInfoFrame - obj = evt.Info + case evt.RepoCommit != nil: + header.MsgType = "#commit" + obj = evt.RepoCommit + case evt.RepoHandle != nil: + header.MsgType = "#handle" + obj = evt.RepoHandle + case evt.RepoInfo != nil: + header.MsgType = "#info" + obj = evt.RepoInfo + case evt.RepoMigrate != nil: + header.MsgType = "#migrate" + obj = evt.RepoMigrate + case evt.RepoTombstone != nil: + header.MsgType = "#tombstone" + obj = evt.RepoTombstone default: return fmt.Errorf("unrecognized event kind") } @@ -315,8 +324,8 @@ func (bgs *BGS) handleFedEvent(ctx context.Context, host *models.PDS, env *event defer span.End() switch { - case env.RepoAppend != nil: - evt := env.RepoAppend + case env.RepoCommit != nil: + evt := env.RepoCommit log.Infof("bgs got repo append event %d from %q: %s\n", evt.Seq, host.Host, evt.Repo) u, err := bgs.lookupUserByDid(ctx, evt.Repo) if err != nil { @@ -334,18 +343,9 @@ func (bgs *BGS) handleFedEvent(ctx context.Context, host *models.PDS, env *event u.Did = evt.Repo } - var prevcid *cid.Cid - if evt.Prev != nil { - c, err := cid.Decode(*evt.Prev) - if err != nil { - return fmt.Errorf("invalid value for prev cid in event: %w", err) - } - prevcid = &c - } - // TODO: if the user is already in the 'slow' path, we shouldnt even bother trying to fast path this event - if err := bgs.repoman.HandleExternalUserEvent(ctx, host.ID, u.ID, u.Did, prevcid, evt.Blocks); err != nil { + if err := bgs.repoman.HandleExternalUserEvent(ctx, host.ID, u.ID, u.Did, (*cid.Cid)(evt.Prev), evt.Blocks); err != nil { log.Warnw("failed handling event", "err", err, "host", host.Host, "seq", evt.Seq) if !errors.Is(err, carstore.ErrRepoBaseMismatch) { return fmt.Errorf("handle user event failed: %w", err) @@ -363,7 +363,11 @@ func (bgs *BGS) handleFedEvent(ctx context.Context, host *models.PDS, env *event // sync blobs if len(evt.Blobs) > 0 { - if err := bgs.syncUserBlobs(ctx, host, u.ID, evt.Blobs); err != nil { + var blobStrs []string + for _, b := range evt.Blobs { + blobStrs = append(blobStrs, b.String()) + } + if err := bgs.syncUserBlobs(ctx, host, u.ID, blobStrs); err != nil { return err } } @@ -435,7 +439,7 @@ func (s *BGS) createExternalUser(ctx context.Context, did string) (*models.Actor if peering.ID == 0 { - cfg, err := atproto.ServerGetAccountsConfig(ctx, c) + cfg, err := atproto.ServerDescribeServer(ctx, c) if err != nil { // TODO: failing this shouldnt halt our indexing return nil, fmt.Errorf("failed to check unrecognized pds: %w", err) @@ -468,7 +472,7 @@ func (s *BGS) createExternalUser(ctx context.Context, did string) (*models.Actor handle := hurl.Host - res, err := atproto.HandleResolve(ctx, c, handle) + res, err := atproto.IdentityResolveHandle(ctx, c, handle) if err != nil { return nil, fmt.Errorf("failed to resolve users claimed handle (%q) on pds: %w", handle, err) } @@ -509,7 +513,6 @@ func (s *BGS) createExternalUser(ctx context.Context, did string) (*models.Actor Handle: handle, DisplayName: "", //*profile.DisplayName, Did: did, - DeclRefCid: "", // profile.Declaration.Cid, Type: "", PDS: peering.ID, } diff --git a/bgs/fedmgr.go b/bgs/fedmgr.go index 1314825b5..f680daeb9 100644 --- a/bgs/fedmgr.go +++ b/bgs/fedmgr.go @@ -8,8 +8,10 @@ import ( "sync" "time" + comatproto "github.com/bluesky-social/indigo/api/atproto" "github.com/bluesky-social/indigo/events" "github.com/bluesky-social/indigo/models" + "github.com/gorilla/websocket" "gorm.io/gorm" ) @@ -68,7 +70,7 @@ func (s *Slurper) SubscribeToPds(ctx context.Context, host string, reg bool) err if !peering.Registered && reg { peering.Registered = true - if err := s.db.Model(models.PDS{}).Where("id = ?").Update("registered", true).Error; err != nil { + if err := s.db.Model(models.PDS{}).Where("id = ?", peering.ID).Update("registered", true).Error; err != nil { return err } } @@ -115,7 +117,7 @@ func (s *Slurper) subscribeWithRedialer(host *models.PDS) { var backoff int for { - url := fmt.Sprintf("%s://%s/xrpc/com.atproto.sync.subscribeAllRepos?cursor=%d", protocol, host.Host, cursor) + url := fmt.Sprintf("%s://%s/xrpc/com.atproto.sync.subscribeRepos?cursor=%d", protocol, host.Host, cursor) con, res, err := d.Dial(url, nil) if err != nil { log.Warnf("dialing %q failed: %s", host.Host, err) @@ -157,11 +159,11 @@ func (s *Slurper) handleConnection(host *models.PDS, con *websocket.Conn, lastCu defer cancel() return events.HandleRepoStream(ctx, con, &events.RepoStreamCallbacks{ - RepoAppend: func(evt *events.RepoAppend) error { + RepoCommit: func(evt *comatproto.SyncSubscribeRepos_Commit) error { log.Infow("got remote repo event", "host", host.Host, "repo", evt.Repo) if err := s.cb(context.TODO(), host, &events.XRPCStreamEvent{ - RepoAppend: evt, + RepoCommit: evt, }); err != nil { log.Errorf("failed handling event from %q (%d): %s", host.Host, evt.Seq, err) } @@ -173,10 +175,11 @@ func (s *Slurper) handleConnection(host *models.PDS, con *websocket.Conn, lastCu return nil }, - Info: func(info *events.InfoFrame) error { - log.Infow("info event", "info", info.Info, "message", info.Message, "host", host.Host) + RepoInfo: func(info *comatproto.SyncSubscribeRepos_Info) error { + log.Infow("info event", "name", info.Name, "message", info.Message, "host", host.Host) return nil }, + // TODO: all the other event types (handle change, migration, etc) Error: func(errf *events.ErrorFrame) error { return fmt.Errorf("error frame: %s: %s", errf.Error, errf.Message) }, diff --git a/cmd/beemo/main.go b/cmd/beemo/main.go index 8e46dd933..56a18e21d 100644 --- a/cmd/beemo/main.go +++ b/cmd/beemo/main.go @@ -107,7 +107,7 @@ func pollNewReports(cctx *cli.Context) error { Auth: &xrpc.AuthInfo{Handle: cctx.String("handle")}, } - auth, err := comatproto.SessionCreate(context.TODO(), xrpcc, &comatproto.SessionCreate_Input{ + auth, err := comatproto.ServerCreateSession(context.TODO(), xrpcc, &comatproto.ServerCreateSession_Input{ Identifier: &xrpcc.Auth.Handle, Password: cctx.String("password"), }) @@ -134,7 +134,7 @@ func pollNewReports(cctx *cli.Context) error { for { // refresh session xrpcc.Auth.AccessJwt = xrpcc.Auth.RefreshJwt - refresh, err := comatproto.SessionRefresh(context.TODO(), xrpcc) + refresh, err := comatproto.ServerRefreshSession(context.TODO(), xrpcc) if err != nil { return err } diff --git a/cmd/bigsky/main.go b/cmd/bigsky/main.go index 69fa377ed..628c36e7d 100644 --- a/cmd/bigsky/main.go +++ b/cmd/bigsky/main.go @@ -37,9 +37,8 @@ import ( var log = logging.Logger("bigsky") func init() { + // control log level using, eg, GOLOG_LOG_LEVEL=debug //logging.SetAllLoggers(logging.LevelDebug) - //logging.SetAllLoggers(logging.LevelInfo) - logging.SetAllLoggers(logging.LevelWarn) } func main() { diff --git a/cmd/fakermaker/main.go b/cmd/fakermaker/main.go index cebc394a8..9bf856a49 100644 --- a/cmd/fakermaker/main.go +++ b/cmd/fakermaker/main.go @@ -118,7 +118,7 @@ func run(args []string) { &cli.IntFlag{ Name: "max-follows", Usage: "create up to this many follows for each account", - Value: 100, + Value: 90, }, &cli.IntFlag{ Name: "max-mutes", @@ -220,7 +220,7 @@ func accountXrpcClient(cctx *cli.Context, ac *AccountContext) (*xrpc.Client, err UserAgent: &ua, } // use XRPC client to re-auth using user/pass - auth, err := comatproto.SessionCreate(context.TODO(), xrpcc, &comatproto.SessionCreate_Input{ + auth, err := comatproto.ServerCreateSession(context.TODO(), xrpcc, &comatproto.ServerCreateSession_Input{ Identifier: &ac.Auth.Handle, Password: ac.Password, }) @@ -313,7 +313,7 @@ func pdsGenAccount(xrpcc *xrpc.Client, index int, accountType string) (*AccountC email := gofakeit.Email() password := gofakeit.Password(true, true, true, true, true, 24) ctx := context.TODO() - resp, err := comatproto.AccountCreate(ctx, xrpcc, &comatproto.AccountCreate_Input{ + resp, err := comatproto.ServerCreateAccount(ctx, xrpcc, &comatproto.ServerCreateAccount_Input{ Email: email, Handle: handle, Password: password, @@ -415,36 +415,43 @@ func pdsGenProfile(xrpcc *xrpc.Client, acc *AccountContext, genAvatar, genBanner name = gofakeit.Name() } - var avatar *lexutil.Blob + var avatar *lexutil.LexBlob if genAvatar { img := gofakeit.ImagePng(200, 200) - resp, err := comatproto.BlobUpload(context.TODO(), xrpcc, bytes.NewReader(img)) + resp, err := comatproto.RepoUploadBlob(context.TODO(), xrpcc, bytes.NewReader(img)) if err != nil { return err } - avatar = &lexutil.Blob{ - Cid: resp.Cid, + avatar = &lexutil.LexBlob{ + Ref: resp.Blob.Ref, MimeType: "image/png", + Size: resp.Blob.Size, } } - var banner *lexutil.Blob + var banner *lexutil.LexBlob if genBanner { img := gofakeit.ImageJpeg(800, 200) - resp, err := comatproto.BlobUpload(context.TODO(), xrpcc, bytes.NewReader(img)) + resp, err := comatproto.RepoUploadBlob(context.TODO(), xrpcc, bytes.NewReader(img)) if err != nil { return err } - avatar = &lexutil.Blob{ - Cid: resp.Cid, + banner = &lexutil.LexBlob{ + Ref: resp.Blob.Ref, MimeType: "image/jpeg", + Size: resp.Blob.Size, } } - _, err := appbsky.ActorUpdateProfile(context.TODO(), xrpcc, &appbsky.ActorUpdateProfile_Input{ - Description: &desc, - DisplayName: &name, - Avatar: avatar, - Banner: banner, + _, err := comatproto.RepoPutRecord(context.TODO(), xrpcc, &comatproto.RepoPutRecord_Input{ + Repo: acc.Auth.Did, + Collection: "app.bsky.actor.profile", + Rkey: "self", + Record: &lexutil.LexiconTypeDecoder{&appbsky.ActorProfile{ + Description: &desc, + DisplayName: &name, + Avatar: avatar, + Banner: banner, + }}, }) return err } @@ -529,15 +536,16 @@ func pdsGenPosts(xrpcc *xrpc.Client, catalog *AccountCatalog, acc *AccountContex var images []*appbsky.EmbedImages_Image if fracImage > 0.0 && rand.Float64() < fracImage { img := gofakeit.ImageJpeg(800, 800) - resp, err := comatproto.BlobUpload(context.TODO(), xrpcc, bytes.NewReader(img)) + resp, err := comatproto.RepoUploadBlob(context.TODO(), xrpcc, bytes.NewReader(img)) if err != nil { return err } images = append(images, &appbsky.EmbedImages_Image{ Alt: gofakeit.Lunch(), - Image: &lexutil.Blob{ - Cid: resp.Cid, + Image: &lexutil.LexBlob{ + Ref: resp.Blob.Ref, MimeType: "image/jpeg", + Size: resp.Blob.Size, }, }) } @@ -557,8 +565,8 @@ func pdsGenPosts(xrpcc *xrpc.Client, catalog *AccountCatalog, acc *AccountContex } if _, err := comatproto.RepoCreateRecord(ctx, xrpcc, &comatproto.RepoCreateRecord_Input{ Collection: "app.bsky.feed.post", - Did: acc.Auth.Did, - Record: lexutil.LexiconTypeDecoder{&post}, + Repo: acc.Auth.Did, + Record: &lexutil.LexiconTypeDecoder{&post}, }); err != nil { return err } @@ -570,34 +578,35 @@ func pdsGenPosts(xrpcc *xrpc.Client, catalog *AccountCatalog, acc *AccountContex func pdsCreateFollow(xrpcc *xrpc.Client, tgt *AccountContext) error { follow := &appbsky.GraphFollow{ CreatedAt: time.Now().Format(time.RFC3339), - Subject: &appbsky.ActorRef{ - Did: tgt.Auth.Did, - // TODO: this should be a public exported const, not hardcoded here - DeclarationCid: "bafyreid27zk7lbis4zw5fz4podbvbs4fc5ivwji3dmrwa6zggnj4bnd57u", - }, + Subject: tgt.Auth.Did, } _, err := comatproto.RepoCreateRecord(context.TODO(), xrpcc, &comatproto.RepoCreateRecord_Input{ Collection: "app.bsky.graph.follow", - Did: xrpcc.Auth.Did, - Record: lexutil.LexiconTypeDecoder{follow}, + Repo: xrpcc.Auth.Did, + Record: &lexutil.LexiconTypeDecoder{follow}, }) return err } -func pdsCreateLike(xrpcc *xrpc.Client, viewPost *appbsky.FeedFeedViewPost) error { - vote := &appbsky.FeedSetVote_Input{ - Direction: "up", +func pdsCreateLike(xrpcc *xrpc.Client, viewPost *appbsky.FeedDefs_FeedViewPost) error { + ctx := context.TODO() + like := appbsky.FeedLike{ Subject: &comatproto.RepoStrongRef{ Uri: viewPost.Post.Uri, Cid: viewPost.Post.Cid, }, + CreatedAt: time.Now().Format(time.RFC3339), } - // TODO: may have already voted? in that case should ignore error - _, err := appbsky.FeedSetVote(context.TODO(), xrpcc, vote) + // TODO: may have already like? in that case should ignore error + _, err := comatproto.RepoCreateRecord(ctx, xrpcc, &comatproto.RepoCreateRecord_Input{ + Collection: "app.bsky.feed.like", + Repo: xrpcc.Auth.Did, + Record: &lexutil.LexiconTypeDecoder{&like}, + }) return err } -func pdsCreateRepost(xrpcc *xrpc.Client, viewPost *appbsky.FeedFeedViewPost) error { +func pdsCreateRepost(xrpcc *xrpc.Client, viewPost *appbsky.FeedDefs_FeedViewPost) error { repost := &appbsky.FeedRepost{ CreatedAt: time.Now().Format(time.RFC3339), Subject: &comatproto.RepoStrongRef{ @@ -607,13 +616,13 @@ func pdsCreateRepost(xrpcc *xrpc.Client, viewPost *appbsky.FeedFeedViewPost) err } _, err := comatproto.RepoCreateRecord(context.TODO(), xrpcc, &comatproto.RepoCreateRecord_Input{ Collection: "app.bsky.feed.repost", - Did: xrpcc.Auth.Did, - Record: lexutil.LexiconTypeDecoder{repost}, + Repo: xrpcc.Auth.Did, + Record: &lexutil.LexiconTypeDecoder{repost}, }) return err } -func pdsCreateReply(xrpcc *xrpc.Client, viewPost *appbsky.FeedFeedViewPost) error { +func pdsCreateReply(xrpcc *xrpc.Client, viewPost *appbsky.FeedDefs_FeedViewPost) error { text := gofakeit.Sentence(10) if len(text) > 200 { text = text[0:200] @@ -639,8 +648,8 @@ func pdsCreateReply(xrpcc *xrpc.Client, viewPost *appbsky.FeedFeedViewPost) erro } _, err := comatproto.RepoCreateRecord(context.TODO(), xrpcc, &comatproto.RepoCreateRecord_Input{ Collection: "app.bsky.feed.post", - Did: xrpcc.Auth.Did, - Record: lexutil.LexiconTypeDecoder{replyPost}, + Repo: xrpcc.Auth.Did, + Record: &lexutil.LexiconTypeDecoder{replyPost}, }) return err } @@ -695,7 +704,7 @@ func pdsGenFollowsAndMutes(xrpcc *xrpc.Client, catalog *AccountCatalog, acc *Acc if tgt.Auth.Did == acc.Auth.Did { continue } - if err := appbsky.GraphMute(context.TODO(), xrpcc, &appbsky.GraphMute_Input{User: tgt.Auth.Did}); err != nil { + if err := appbsky.GraphMuteActor(context.TODO(), xrpcc, &appbsky.GraphMuteActor_Input{Actor: tgt.Auth.Did}); err != nil { return err } } @@ -807,7 +816,7 @@ func genInteractions(cctx *cli.Context) error { func browseAccount(xrpcc *xrpc.Client, acc *AccountContext) error { // fetch notifications maxNotif := 50 - resp, err := appbsky.NotificationList(context.TODO(), xrpcc, "", int64(maxNotif)) + resp, err := appbsky.NotificationListNotifications(context.TODO(), xrpcc, "", int64(maxNotif)) if err != nil { return err } @@ -877,7 +886,7 @@ func browseAccount(xrpcc *xrpc.Client, acc *AccountContext) error { t2(len(timelineResp.Feed)) // notification count for good measure - _, err = appbsky.NotificationGetCount(context.TODO(), xrpcc) + _, err = appbsky.NotificationGetUnreadCount(context.TODO(), xrpcc) return err } diff --git a/cmd/gosky/debug.go b/cmd/gosky/debug.go index 59e5d2309..39c3ae339 100644 --- a/cmd/gosky/debug.go +++ b/cmd/gosky/debug.go @@ -9,10 +9,13 @@ import ( "net/http" "strconv" + comatproto "github.com/bluesky-social/indigo/api/atproto" "github.com/bluesky-social/indigo/events" "github.com/bluesky-social/indigo/repo" "github.com/bluesky-social/indigo/repomgr" + "github.com/gorilla/websocket" + "github.com/ipfs/go-cid" "github.com/ipld/go-car/v2" cli "github.com/urfave/cli/v2" ) @@ -44,7 +47,7 @@ var inspectEventCmd = &cli.Command{ h := cctx.String("host") - url := fmt.Sprintf("%s/xrpc/com.atproto.sync.subscribeAllRepos?cursor=%d", h, n-1) + url := fmt.Sprintf("%s/xrpc/com.atproto.sync.subscribeRepos?cursor=%d", h, n-1) d := websocket.DefaultDialer con, _, err := d.Dial(url, http.Header{}) if err != nil { @@ -53,11 +56,11 @@ var inspectEventCmd = &cli.Command{ var errFoundIt = fmt.Errorf("gotem") - var match *events.RepoAppend + var match *comatproto.SyncSubscribeRepos_Commit ctx := context.TODO() err = events.HandleRepoStream(ctx, con, &events.RepoStreamCallbacks{ - RepoAppend: func(evt *events.RepoAppend) error { + RepoCommit: func(evt *comatproto.SyncSubscribeRepos_Commit) error { n := int64(n) if evt.Seq == n { match = evt @@ -69,9 +72,10 @@ var inspectEventCmd = &cli.Command{ return nil }, - Info: func(evt *events.InfoFrame) error { + RepoInfo: func(evt *comatproto.SyncSubscribeRepos_Info) error { return nil }, + // TODO: all the other Repo* event types Error: func(evt *events.ErrorFrame) error { return fmt.Errorf("%s: %s", evt.Error, evt.Message) }, @@ -122,7 +126,7 @@ var inspectEventCmd = &cli.Command{ if err != nil { return fmt.Errorf("loading %q: %w", op.Path, err) } - if rcid.String() != *op.Cid { + if rcid != cid.Cid(*op.Cid) { return fmt.Errorf("mismatch in record cid %s != %s", rcid, *op.Cid) } fmt.Printf("%s (%s): %s\n", op.Action, op.Path, *op.Cid) diff --git a/cmd/gosky/main.go b/cmd/gosky/main.go index 1a5e7d36f..fd6f3b96d 100644 --- a/cmd/gosky/main.go +++ b/cmd/gosky/main.go @@ -20,6 +20,7 @@ import ( "github.com/bluesky-social/indigo/events" lexutil "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/repo" + "github.com/bluesky-social/indigo/util" "github.com/bluesky-social/indigo/version" "github.com/gorilla/websocket" "github.com/ipfs/go-cid" @@ -105,7 +106,7 @@ var newAccountCmd = &cli.Command{ invite = &inv } - acc, err := comatproto.AccountCreate(context.TODO(), xrpcc, &comatproto.AccountCreate_Input{ + acc, err := comatproto.ServerCreateAccount(context.TODO(), xrpcc, &comatproto.ServerCreateAccount_Input{ Email: email, Handle: handle, InviteCode: invite, @@ -134,7 +135,7 @@ var createSessionCmd = &cli.Command{ handle := cctx.Args().Get(0) password := cctx.Args().Get(1) - ses, err := comatproto.SessionCreate(context.TODO(), xrpcc, &comatproto.SessionCreate_Input{ + ses, err := comatproto.ServerCreateSession(context.TODO(), xrpcc, &comatproto.ServerCreateSession_Input{ Identifier: &handle, Password: password, }) @@ -166,8 +167,8 @@ var postCmd = &cli.Command{ resp, err := comatproto.RepoCreateRecord(context.TODO(), xrpcc, &comatproto.RepoCreateRecord_Input{ Collection: "app.bsky.feed.post", - Did: auth.Did, - Record: lexutil.LexiconTypeDecoder{&appbsky.FeedPost{ + Repo: auth.Did, + Record: &lexutil.LexiconTypeDecoder{&appbsky.FeedPost{ Text: text, CreatedAt: time.Now().Format("2006-01-02T15:04:05.000Z"), }}, @@ -356,7 +357,7 @@ func jsonPrint(i any) { fmt.Println(string(b)) } -func prettyPrintPost(p *appbsky.FeedFeedViewPost, uris bool) { +func prettyPrintPost(p *appbsky.FeedDefs_FeedViewPost, uris bool) { fmt.Println(strings.Repeat("-", 60)) rec := p.Post.Record.Val.(*appbsky.FeedPost) fmt.Printf("%s (%s)", p.Post.Author.Handle, rec.CreatedAt) @@ -504,13 +505,21 @@ var feedSetVoteCmd = &cli.Command{ return fmt.Errorf("getting record: %w", err) } - _, err = appbsky.FeedSetVote(ctx, xrpcc, &appbsky.FeedSetVote_Input{ - Subject: &comatproto.RepoStrongRef{Uri: resp.Uri, Cid: *resp.Cid}, - Direction: dir, + out, err := comatproto.RepoCreateRecord(ctx, xrpcc, &comatproto.RepoCreateRecord_Input{ + LexiconTypeID: "com.atproto.feed.like", + Collection: "com.atproto.feed.like", + Repo: did, + Record: &lexutil.LexiconTypeDecoder{ + Val: &appbsky.FeedLike{ + CreatedAt: time.Now().Format(util.ISO8601), + Subject: &comatproto.RepoStrongRef{Uri: resp.Uri, Cid: *resp.Cid}, + }, + }, }) if err != nil { return err } + _ = out return nil }, @@ -529,7 +538,7 @@ var refreshAuthTokenCmd = &cli.Command{ a.AccessJwt = a.RefreshJwt ctx := context.TODO() - nauth, err := comatproto.SessionRefresh(ctx, xrpcc) + nauth, err := comatproto.ServerRefreshSession(ctx, xrpcc) if err != nil { return err } @@ -569,7 +578,7 @@ var deletePostCmd = &cli.Command{ } return comatproto.RepoDeleteRecord(context.TODO(), xrpcc, &comatproto.RepoDeleteRecord_Input{ - Did: xrpcc.Auth.Did, + Repo: xrpcc.Auth.Did, Collection: schema, Rkey: rkey, }) @@ -674,7 +683,7 @@ var getNotificationsCmd = &cli.Command{ return err } - notifs, err := appbsky.NotificationList(ctx, xrpcc, "", 50) + notifs, err := appbsky.NotificationListNotifications(ctx, xrpcc, "", 50) if err != nil { return err } @@ -714,16 +723,13 @@ var followsAddCmd = &cli.Command{ follow := appbsky.GraphFollow{ LexiconTypeID: "app.bsky.graph.follow", CreatedAt: time.Now().Format(time.RFC3339), - Subject: &appbsky.ActorRef{ - DeclarationCid: "bafyreid27zk7lbis4zw5fz4podbvbs4fc5ivwji3dmrwa6zggnj4bnd57u", - Did: user, - }, + Subject: user, } resp, err := comatproto.RepoCreateRecord(context.TODO(), xrpcc, &comatproto.RepoCreateRecord_Input{ Collection: "app.bsky.graph.follow", - Did: xrpcc.Auth.Did, - Record: lexutil.LexiconTypeDecoder{&follow}, + Repo: xrpcc.Auth.Did, + Record: &lexutil.LexiconTypeDecoder{&follow}, }) if err != nil { return err @@ -749,7 +755,7 @@ var followsListCmd = &cli.Command{ } ctx := context.TODO() - resp, err := appbsky.GraphGetFollows(ctx, xrpcc, "", 100, user) + resp, err := appbsky.GraphGetFollows(ctx, xrpcc, user, "", 100) if err != nil { return err } @@ -793,7 +799,7 @@ var resetPasswordCmd = &cli.Command{ email := cctx.Args().Get(0) - err = comatproto.AccountRequestPasswordReset(ctx, xrpcc, &comatproto.AccountRequestPasswordReset_Input{ + err = comatproto.ServerRequestPasswordReset(ctx, xrpcc, &comatproto.ServerRequestPasswordReset_Input{ Email: email, }) if err != nil { @@ -809,7 +815,7 @@ var resetPasswordCmd = &cli.Command{ inp.Scan() npass := inp.Text() - if err := comatproto.AccountResetPassword(ctx, xrpcc, &comatproto.AccountResetPassword_Input{ + if err := comatproto.ServerResetPassword(ctx, xrpcc, &comatproto.ServerResetPassword_Input{ Password: npass, Token: code, }); err != nil { @@ -832,7 +838,7 @@ var updateHandleCmd = &cli.Command{ handle := cctx.Args().Get(0) - err = comatproto.HandleUpdate(ctx, xrpcc, &comatproto.HandleUpdate_Input{ + err = comatproto.IdentityUpdateHandle(ctx, xrpcc, &comatproto.IdentityUpdateHandle_Input{ Handle: handle, }) if err != nil { @@ -855,8 +861,8 @@ var readRepoStreamCmd = &cli.Command{ defer stop() arg := cctx.Args().First() - if !strings.Contains(arg, "subscribeAllRepos") { - arg = arg + "/xrpc/com.atproto.sync.subscribeAllRepos" + if !strings.Contains(arg, "subscribeRepos") { + arg = arg + "/xrpc/com.atproto.sync.subscribeRepos" } if len(cctx.Args().Slice()) == 2 { arg = fmt.Sprintf("%s?cursor=%s", arg, cctx.Args().Get(1)) @@ -882,7 +888,7 @@ var readRepoStreamCmd = &cli.Command{ }() return events.HandleRepoStream(ctx, con, &events.RepoStreamCallbacks{ - RepoAppend: func(evt *events.RepoAppend) error { + RepoCommit: func(evt *comatproto.SyncSubscribeRepos_Commit) error { if jsonfmt { b, err := json.Marshal(evt) if err != nil { @@ -902,15 +908,15 @@ var readRepoStreamCmd = &cli.Command{ } else { pstr := "" - if evt.Prev != nil { - pstr = *evt.Prev + if evt.Prev != nil && evt.Prev.Defined() { + pstr = evt.Prev.String() } fmt.Printf("(%d) RepoAppend: %s (%s -> %s)\n", evt.Seq, evt.Repo, pstr, evt.Commit) } return nil }, - Info: func(info *events.InfoFrame) error { + RepoInfo: func(info *comatproto.SyncSubscribeRepos_Info) error { if jsonfmt { b, err := json.Marshal(info) if err != nil { @@ -918,11 +924,12 @@ var readRepoStreamCmd = &cli.Command{ } fmt.Println(string(b)) } else { - fmt.Printf("INFO: %s: %s\n", info.Info, info.Message) + fmt.Printf("INFO: %s: %v\n", info.Name, info.Message) } return nil }, + // TODO: all the other event types Error: func(errf *events.ErrorFrame) error { return fmt.Errorf("error frame: %s: %s", errf.Error, errf.Message) }, diff --git a/cmd/stress/main.go b/cmd/stress/main.go index ed2b360c4..5975059f1 100644 --- a/cmd/stress/main.go +++ b/cmd/stress/main.go @@ -95,7 +95,7 @@ var postingCmd = &cli.Command{ invite = &inv } - cfg, err := comatproto.ServerGetAccountsConfig(ctx, xrpcc) + cfg, err := comatproto.ServerDescribeServer(ctx, xrpcc) if err != nil { return err } @@ -103,7 +103,7 @@ var postingCmd = &cli.Command{ domain := cfg.AvailableUserDomains[0] fmt.Println("domain: ", domain) - resp, err := comatproto.AccountCreate(ctx, xrpcc, &comatproto.AccountCreate_Input{ + resp, err := comatproto.ServerCreateAccount(ctx, xrpcc, &comatproto.ServerCreateAccount_Input{ Email: fmt.Sprintf("user-%s@test.com", id), Handle: "user-" + id + domain, Password: "password", @@ -131,8 +131,8 @@ var postingCmd = &cli.Command{ res, err := comatproto.RepoCreateRecord(context.TODO(), xrpcc, &comatproto.RepoCreateRecord_Input{ Collection: "app.bsky.feed.post", - Did: xrpcc.Auth.Did, - Record: lexutil.LexiconTypeDecoder{&appbsky.FeedPost{ + Repo: xrpcc.Auth.Did, + Record: &lexutil.LexiconTypeDecoder{&appbsky.FeedPost{ Text: hex.EncodeToString(buf), CreatedAt: time.Now().Format(time.RFC3339), }}, diff --git a/events/cbor_gen.go b/events/cbor_gen.go index 226e4ed9f..c304ec0c3 100644 --- a/events/cbor_gen.go +++ b/events/cbor_gen.go @@ -26,7 +26,30 @@ func (t *EventHeader) MarshalCBOR(w io.Writer) error { cw := cbg.NewCborWriter(w) - if _, err := cw.Write([]byte{161}); err != nil { + if _, err := cw.Write([]byte{162}); err != nil { + return err + } + + // t.MsgType (string) (string) + if len("t") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"t\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("t"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("t")); err != nil { + return err + } + + if len(t.MsgType) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.MsgType was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MsgType))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.MsgType)); err != nil { return err } @@ -92,7 +115,18 @@ func (t *EventHeader) UnmarshalCBOR(r io.Reader) (err error) { } switch name { - // t.Op (int64) (int64) + // t.MsgType (string) (string) + case "t": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.MsgType = string(sval) + } + // t.Op (int64) (int64) case "op": { maj, extra, err := cr.ReadHeader() @@ -127,808 +161,6 @@ func (t *EventHeader) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *RepoAppend) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - - cw := cbg.NewCborWriter(w) - - if _, err := cw.Write([]byte{170}); err != nil { - return err - } - - // t.Ops ([]*events.RepoOp) (slice) - if len("ops") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"ops\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ops"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("ops")); err != nil { - return err - } - - if len(t.Ops) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Ops was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Ops))); err != nil { - return err - } - for _, v := range t.Ops { - if err := v.MarshalCBOR(cw); err != nil { - return err - } - } - - // t.Seq (int64) (int64) - if len("seq") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"seq\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("seq"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("seq")); err != nil { - return err - } - - if t.Seq >= 0 { - if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Seq)); err != nil { - return err - } - } else { - if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Seq-1)); err != nil { - return err - } - } - - // t.Prev (string) (string) - if len("prev") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"prev\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("prev"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("prev")); err != nil { - return err - } - - if t.Prev == nil { - if _, err := cw.Write(cbg.CborNull); err != nil { - return err - } - } else { - if len(*t.Prev) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Prev was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Prev))); err != nil { - return err - } - if _, err := io.WriteString(w, string(*t.Prev)); err != nil { - return err - } - } - - // t.Repo (string) (string) - if len("repo") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"repo\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repo"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("repo")); err != nil { - return err - } - - if len(t.Repo) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Repo was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repo))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Repo)); err != nil { - return err - } - - // t.Time (string) (string) - if len("time") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"time\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("time"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("time")); err != nil { - return err - } - - if len(t.Time) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Time was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Time))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Time)); err != nil { - return err - } - - // t.Blobs ([]string) (slice) - if len("blobs") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"blobs\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("blobs"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("blobs")); err != nil { - return err - } - - if len(t.Blobs) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Blobs was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Blobs))); err != nil { - return err - } - for _, v := range t.Blobs { - if len(v) > cbg.MaxLength { - return xerrors.Errorf("Value in field v was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { - return err - } - if _, err := io.WriteString(w, string(v)); err != nil { - return err - } - } - - // t.Event (string) (string) - if len("event") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"event\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("event"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("event")); err != nil { - return err - } - - if len(t.Event) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Event was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Event))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Event)); err != nil { - return err - } - - // t.Blocks ([]uint8) (slice) - if len("blocks") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"blocks\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("blocks"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("blocks")); err != nil { - return err - } - - if len(t.Blocks) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.Blocks was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Blocks))); err != nil { - return err - } - - if _, err := cw.Write(t.Blocks[:]); err != nil { - return err - } - - // t.Commit (string) (string) - if len("commit") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"commit\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("commit"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("commit")); err != nil { - return err - } - - if len(t.Commit) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Commit was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Commit))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Commit)); err != nil { - return err - } - - // t.TooBig (bool) (bool) - if len("tooBig") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"tooBig\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("tooBig"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("tooBig")); err != nil { - return err - } - - if err := cbg.WriteBool(w, t.TooBig); err != nil { - return err - } - return nil -} - -func (t *RepoAppend) UnmarshalCBOR(r io.Reader) (err error) { - *t = RepoAppend{} - - 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("RepoAppend: map struct too large (%d)", extra) - } - - var name string - n := extra - - for i := uint64(0); i < n; i++ { - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - name = string(sval) - } - - switch name { - // t.Ops ([]*events.RepoOp) (slice) - case "ops": - - maj, extra, err = cr.ReadHeader() - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Ops: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.Ops = make([]*RepoOp, extra) - } - - for i := 0; i < int(extra); i++ { - - var v RepoOp - if err := v.UnmarshalCBOR(cr); err != nil { - return err - } - - t.Ops[i] = &v - } - - // t.Seq (int64) (int64) - case "seq": - { - maj, extra, err := cr.ReadHeader() - var extraI int64 - if err != nil { - return err - } - 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.Seq = int64(extraI) - } - // t.Prev (string) (string) - case "prev": - - { - b, err := cr.ReadByte() - if err != nil { - return err - } - if b != cbg.CborNull[0] { - if err := cr.UnreadByte(); err != nil { - return err - } - - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Prev = (*string)(&sval) - } - } - // t.Repo (string) (string) - case "repo": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Repo = string(sval) - } - // t.Time (string) (string) - case "time": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Time = string(sval) - } - // t.Blobs ([]string) (slice) - case "blobs": - - maj, extra, err = cr.ReadHeader() - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Blobs: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.Blobs = make([]string, extra) - } - - for i := 0; i < int(extra); i++ { - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Blobs[i] = string(sval) - } - } - - // t.Event (string) (string) - case "event": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Event = string(sval) - } - // t.Blocks ([]uint8) (slice) - case "blocks": - - maj, extra, err = cr.ReadHeader() - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.Blocks: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - - if extra > 0 { - t.Blocks = make([]uint8, extra) - } - - if _, err := io.ReadFull(cr, t.Blocks[:]); err != nil { - return err - } - // t.Commit (string) (string) - case "commit": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Commit = string(sval) - } - // t.TooBig (bool) (bool) - case "tooBig": - - maj, extra, err = cr.ReadHeader() - if err != nil { - return err - } - if maj != cbg.MajOther { - return fmt.Errorf("booleans must be major type 7") - } - switch extra { - case 20: - t.TooBig = false - case 21: - t.TooBig = true - default: - return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) - } - - default: - // Field doesn't exist on this type, so ignore it - cbg.ScanForLinks(r, func(cid.Cid) {}) - } - } - - return nil -} -func (t *RepoOp) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - - cw := cbg.NewCborWriter(w) - - if _, err := cw.Write([]byte{163}); err != nil { - return err - } - - // t.Cid (string) (string) - if len("cid") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"cid\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("cid"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("cid")); err != nil { - return err - } - - if t.Cid == nil { - if _, err := cw.Write(cbg.CborNull); err != nil { - return err - } - } else { - if len(*t.Cid) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Cid was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Cid))); err != nil { - return err - } - if _, err := io.WriteString(w, string(*t.Cid)); err != nil { - return err - } - } - - // t.Path (string) (string) - if len("path") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"path\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("path"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("path")); err != nil { - return err - } - - if len(t.Path) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Path was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Path))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Path)); err != nil { - return err - } - - // t.Action (string) (string) - if len("action") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"action\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("action"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("action")); err != nil { - return err - } - - if len(t.Action) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Action was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Action))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Action)); err != nil { - return err - } - return nil -} - -func (t *RepoOp) UnmarshalCBOR(r io.Reader) (err error) { - *t = RepoOp{} - - 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("RepoOp: map struct too large (%d)", extra) - } - - var name string - n := extra - - for i := uint64(0); i < n; i++ { - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - name = string(sval) - } - - switch name { - // t.Cid (string) (string) - case "cid": - - { - b, err := cr.ReadByte() - if err != nil { - return err - } - if b != cbg.CborNull[0] { - if err := cr.UnreadByte(); err != nil { - return err - } - - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Cid = (*string)(&sval) - } - } - // t.Path (string) (string) - case "path": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Path = string(sval) - } - // t.Action (string) (string) - case "action": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Action = string(sval) - } - - default: - // Field doesn't exist on this type, so ignore it - cbg.ScanForLinks(r, func(cid.Cid) {}) - } - } - - return nil -} -func (t *InfoFrame) 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.Info (string) (string) - if len("info") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"info\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("info"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("info")); err != nil { - return err - } - - if len(t.Info) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Info was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Info))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Info)); err != nil { - return err - } - - // t.Message (string) (string) - if len("message") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"message\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("message"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("message")); err != nil { - return err - } - - if len(t.Message) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Message was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Message))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Message)); err != nil { - return err - } - return nil -} - -func (t *InfoFrame) UnmarshalCBOR(r io.Reader) (err error) { - *t = InfoFrame{} - - 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("InfoFrame: map struct too large (%d)", extra) - } - - var name string - n := extra - - for i := uint64(0); i < n; i++ { - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - name = string(sval) - } - - switch name { - // t.Info (string) (string) - case "info": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Info = string(sval) - } - // t.Message (string) (string) - case "message": - - { - sval, err := cbg.ReadString(cr) - if err != nil { - return err - } - - t.Message = string(sval) - } - - default: - // Field doesn't exist on this type, so ignore it - cbg.ScanForLinks(r, func(cid.Cid) {}) - } - } - - return nil -} func (t *ErrorFrame) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) diff --git a/events/consumer.go b/events/consumer.go index f90c508fd..344cce74c 100644 --- a/events/consumer.go +++ b/events/consumer.go @@ -5,14 +5,19 @@ import ( "fmt" "time" + comatproto "github.com/bluesky-social/indigo/api/atproto" + "github.com/gorilla/websocket" ) type RepoStreamCallbacks struct { - RepoAppend func(evt *RepoAppend) error - LabelBatch func(evt *LabelBatch) error - Info func(evt *InfoFrame) error - Error func(evt *ErrorFrame) error + RepoCommit func(evt *comatproto.SyncSubscribeRepos_Commit) error + RepoHandle func(evt *comatproto.SyncSubscribeRepos_Handle) error + RepoInfo func(evt *comatproto.SyncSubscribeRepos_Info) error + RepoMigrate func(evt *comatproto.SyncSubscribeRepos_Migrate) error + RepoTombstone func(evt *comatproto.SyncSubscribeRepos_Tombstone) error + LabelBatch func(evt *LabelBatch) error + Error func(evt *ErrorFrame) error } func HandleRepoStream(ctx context.Context, con *websocket.Conn, cbs *RepoStreamCallbacks) error { @@ -55,54 +60,79 @@ func HandleRepoStream(ctx context.Context, con *websocket.Conn, cbs *RepoStreamC } switch header.Op { - case EvtKindRepoAppend: - var evt RepoAppend - if err := evt.UnmarshalCBOR(r); err != nil { - return fmt.Errorf("reading repoAppend event: %w", err) - } + case EvtKindMessage: + switch header.MsgType { + case "#commit": + var evt comatproto.SyncSubscribeRepos_Commit + if err := evt.UnmarshalCBOR(r); err != nil { + return fmt.Errorf("reading repoCommit event: %w", err) + } - if evt.Seq < lastSeq { - log.Errorf("Got events out of order from stream (seq = %d, prev = %d)", evt.Seq, lastSeq) - } + if evt.Seq < lastSeq { + log.Errorf("Got events out of order from stream (seq = %d, prev = %d)", evt.Seq, lastSeq) + } - lastSeq = evt.Seq + lastSeq = evt.Seq - if cbs.RepoAppend != nil { - if err := cbs.RepoAppend(&evt); err != nil { + if cbs.RepoCommit != nil { + if err := cbs.RepoCommit(&evt); err != nil { + return err + } + } else { + log.Warnf("received repo commit event with nil commit object (seq %d)", evt.Seq) + } + case "#info": + var evt comatproto.SyncSubscribeRepos_Info + if err := evt.UnmarshalCBOR(r); err != nil { return err } - } else { - log.Warnf("received repo append event with nil append object (seq %d)", evt.Seq) - } - case EvtKindLabelBatch: - var evt LabelBatch - if err := evt.UnmarshalCBOR(r); err != nil { - return fmt.Errorf("reading LabelBatch event: %w", err) - } - - if evt.Seq < lastSeq { - log.Errorf("Got events out of order from stream (seq = %d, prev = %d)", evt.Seq, lastSeq) - } - - lastSeq = evt.Seq - if cbs.RepoAppend != nil { - if err := cbs.LabelBatch(&evt); err != nil { + if cbs.RepoInfo != nil { + if err := cbs.RepoInfo(&evt); err != nil { + return err + } + } + case "#migrate": + var evt comatproto.SyncSubscribeRepos_Migrate + if err := evt.UnmarshalCBOR(r); err != nil { return err } - } else { - log.Warnf("received label event with nil append object (seq %d)", evt.Seq) - } - case EvtKindInfoFrame: - var info InfoFrame - if err := info.UnmarshalCBOR(r); err != nil { - return err - } - if cbs.Info != nil { - if err := cbs.Info(&info); err != nil { + if cbs.RepoMigrate != nil { + if err := cbs.RepoMigrate(&evt); err != nil { + return err + } + } + case "#tombstone": + var evt comatproto.SyncSubscribeRepos_Tombstone + if err := evt.UnmarshalCBOR(r); err != nil { return err } + + if cbs.RepoMigrate != nil { + if err := cbs.RepoTombstone(&evt); err != nil { + return err + } + } + case "#labebatch": + var evt LabelBatch + if err := evt.UnmarshalCBOR(r); err != nil { + return fmt.Errorf("reading LabelBatch event: %w", err) + } + + if evt.Seq < lastSeq { + log.Errorf("Got events out of order from stream (seq = %d, prev = %d)", evt.Seq, lastSeq) + } + + lastSeq = evt.Seq + + if cbs.LabelBatch != nil { + if err := cbs.LabelBatch(&evt); err != nil { + return err + } + } else { + log.Warnf("received label event with nil append object (seq %d)", evt.Seq) + } } case EvtKindErrorFrame: diff --git a/events/dbpersist.go b/events/dbpersist.go index fecc3302b..99e4287f5 100644 --- a/events/dbpersist.go +++ b/events/dbpersist.go @@ -7,9 +7,12 @@ import ( "fmt" "time" + comatproto "github.com/bluesky-social/indigo/api/atproto" "github.com/bluesky-social/indigo/carstore" + lexutil "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/models" "github.com/bluesky-social/indigo/util" + cid "github.com/ipfs/go-cid" "gorm.io/gorm" ) @@ -57,11 +60,11 @@ func NewDbPersistence(db *gorm.DB, cs *carstore.CarStore) (*DbPersistence, error } func (p *DbPersistence) Persist(ctx context.Context, e *XRPCStreamEvent) error { - if e.RepoAppend == nil { + if e.RepoCommit == nil { return nil } - evt := e.RepoAppend + evt := e.RepoCommit // TODO: hack hack hack if len(evt.Ops) > 8192 { @@ -75,18 +78,8 @@ func (p *DbPersistence) Persist(ctx context.Context, e *XRPCStreamEvent) error { } var prev *util.DbCID - if evt.Prev != nil { - c, err := cid.Decode(*evt.Prev) - if err != nil { - return fmt.Errorf("decoding prev cid (%q): %w", *evt.Prev, err) - } - - prev = &util.DbCID{c} - } - - com, err := cid.Decode(evt.Commit) - if err != nil { - return err + if evt.Prev != nil && evt.Prev.Defined() { + prev = &util.DbCID{cid.Cid(*evt.Prev)} } var blobs []byte @@ -104,23 +97,18 @@ func (p *DbPersistence) Persist(ctx context.Context, e *XRPCStreamEvent) error { } rer := RepoEventRecord{ - Commit: util.DbCID{com}, + Commit: util.DbCID{cid.Cid(evt.Commit)}, Prev: prev, Repo: uid, - Event: evt.Event, + Event: "repo_append", // TODO: refactor to "#commit"? can "rebase" come through this path? Blobs: blobs, Time: t, } for _, op := range evt.Ops { var rec *util.DbCID - if op.Cid != nil { - c, err := cid.Decode(*op.Cid) - if err != nil { - return err - } - - rec = &util.DbCID{c} + if op.Cid != nil && op.Cid.Defined() { + rec = &util.DbCID{cid.Cid(*op.Cid)} } rer.Ops = append(rer.Ops, RepoOpRecord{ Path: op.Path, @@ -132,7 +120,7 @@ func (p *DbPersistence) Persist(ctx context.Context, e *XRPCStreamEvent) error { return err } - e.RepoAppend.Seq = int64(rer.Seq) + e.RepoCommit.Seq = int64(rer.Seq) return nil } @@ -162,7 +150,7 @@ func (p *DbPersistence) Playback(ctx context.Context, since int64, cb func(*XRPC return err } - if err := cb(&XRPCStreamEvent{RepoAppend: ra}); err != nil { + if err := cb(&XRPCStreamEvent{RepoCommit: ra}); err != nil { return err } } @@ -188,46 +176,54 @@ func (p *DbPersistence) didForUid(ctx context.Context, uid util.Uid) (string, er return u.Did, nil } -func (p *DbPersistence) hydrateRepoEvent(ctx context.Context, rer *RepoEventRecord) (*RepoAppend, error) { +func (p *DbPersistence) hydrateRepoEvent(ctx context.Context, rer *RepoEventRecord) (*comatproto.SyncSubscribeRepos_Commit, error) { var blobs []string if len(rer.Blobs) > 0 { if err := json.Unmarshal(rer.Blobs, &blobs); err != nil { return nil, err } } + var blobCIDs []lexutil.LexLink + for _, b := range blobs { + c, err := cid.Decode(b) + if err != nil { + return nil, err + } + blobCIDs = append(blobCIDs, lexutil.LexLink(c)) + } did, err := p.didForUid(ctx, rer.Repo) if err != nil { return nil, err } - var prev *string - if rer.Prev != nil { - s := rer.Prev.CID.String() - prev = &s + var prevCID *lexutil.LexLink + if rer != nil && rer.Prev != nil && rer.Prev.CID.Defined() { + tmp := lexutil.LexLink(rer.Prev.CID) + prevCID = &tmp } - out := &RepoAppend{ + out := &comatproto.SyncSubscribeRepos_Commit{ Seq: int64(rer.Seq), Repo: did, - Commit: rer.Commit.CID.String(), - Prev: prev, + Commit: lexutil.LexLink(rer.Commit.CID), + Prev: prevCID, Time: rer.Time.Format(util.ISO8601), - Blobs: blobs, - Event: rer.Event, + Blobs: blobCIDs, + // TODO: there was previously an Event field here. are these all Commit, or are some other events? } for _, op := range rer.Ops { - var rec *string + var recCID *lexutil.LexLink if op.Rec != nil { - s := op.Rec.CID.String() - rec = &s + tmp := lexutil.LexLink(op.Rec.CID) + recCID = &tmp } - out.Ops = append(out.Ops, &RepoOp{ + out.Ops = append(out.Ops, &comatproto.SyncSubscribeRepos_RepoOp{ Path: op.Path, Action: op.Action, - Cid: rec, + Cid: recCID, }) } diff --git a/events/events.go b/events/events.go index 23c77ffb5..579e77c40 100644 --- a/events/events.go +++ b/events/events.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" + comatproto "github.com/bluesky-social/indigo/api/atproto" + "github.com/bluesky-social/indigo/util" logging "github.com/ipfs/go-log" "go.opentelemetry.io/otel" @@ -96,20 +98,22 @@ type Subscriber struct { const ( EvtKindErrorFrame = -1 - EvtKindRepoAppend = 1 - EvtKindInfoFrame = 2 - EvtKindLabelBatch = 3 + EvtKindMessage = 1 ) type EventHeader struct { - Op int64 `cborgen:"op"` + Op int64 `cborgen:"op"` + MsgType string `cborgen:"t"` } type XRPCStreamEvent struct { - RepoAppend *RepoAppend - Info *InfoFrame - Error *ErrorFrame - LabelBatch *LabelBatch + Error *ErrorFrame + RepoCommit *comatproto.SyncSubscribeRepos_Commit + RepoHandle *comatproto.SyncSubscribeRepos_Handle + RepoInfo *comatproto.SyncSubscribeRepos_Info + RepoMigrate *comatproto.SyncSubscribeRepos_Migrate + RepoTombstone *comatproto.SyncSubscribeRepos_Tombstone + LabelBatch *LabelBatch // some private fields for internal routing perf PrivUid util.Uid `json:"-" cborgen:"-"` @@ -117,44 +121,11 @@ type XRPCStreamEvent struct { PrivRelevantPds []uint `json:"-" cborgen:"-"` } -type RepoAppend struct { - Seq int64 `cborgen:"seq"` - - Event string `cborgen:"event"` - - // Repo is the DID of the repo this event is about - Repo string `cborgen:"repo"` - - Commit string `cborgen:"commit"` - Prev *string `cborgen:"prev"` - //Commit cid.Cid `cborgen:"commit"` - //Prev *cid.Cid `cborgen:"prev"` - - Ops []*RepoOp `cborgen:"ops"` - Blocks []byte `cborgen:"blocks"` - TooBig bool `cborgen:"tooBig"` - - Blobs []string `cborgen:"blobs"` - - Time string `cborgen:"time"` -} - -type RepoOp struct { - Path string `cborgen:"path"` - Action string `cborgen:"action"` - Cid *string `cborgen:"cid"` -} - type LabelBatch struct { Seq int64 `cborgen:"seq"` Labels []Label `cborgen:"labels"` } -type InfoFrame struct { - Info string `cborgen:"info"` - Message string `cborgen:"message"` -} - type ErrorFrame struct { Error string `cborgen:"error"` Message string `cborgen:"message"` diff --git a/events/persist.go b/events/persist.go index 62eae7728..fdc0acc04 100644 --- a/events/persist.go +++ b/events/persist.go @@ -29,8 +29,14 @@ func (mp *MemPersister) Persist(ctx context.Context, e *XRPCStreamEvent) error { defer mp.lk.Unlock() mp.seq++ switch { - case e.RepoAppend != nil: - e.RepoAppend.Seq = mp.seq + case e.RepoCommit != nil: + e.RepoCommit.Seq = mp.seq + case e.RepoHandle != nil: + e.RepoHandle.Seq = mp.seq + case e.RepoMigrate != nil: + e.RepoMigrate.Seq = mp.seq + case e.RepoTombstone != nil: + e.RepoTombstone.Seq = mp.seq case e.LabelBatch != nil: e.LabelBatch.Seq = mp.seq default: diff --git a/events/repostream.go b/events/repostream.go index acd9f6e84..4d609bf76 100644 --- a/events/repostream.go +++ b/events/repostream.go @@ -5,8 +5,11 @@ import ( "context" "fmt" + comatproto "github.com/bluesky-social/indigo/api/atproto" + lexutil "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/repo" "github.com/bluesky-social/indigo/repomgr" + "github.com/gorilla/websocket" cid "github.com/ipfs/go-cid" ) @@ -15,7 +18,7 @@ type LiteStreamHandleFunc func(op repomgr.EventKind, seq int64, path string, did func ConsumeRepoStreamLite(ctx context.Context, con *websocket.Conn, cb LiteStreamHandleFunc) error { return HandleRepoStream(ctx, con, &RepoStreamCallbacks{ - RepoAppend: func(evt *RepoAppend) error { + RepoCommit: func(evt *comatproto.SyncSubscribeRepos_Commit) error { if evt.TooBig { log.Errorf("skipping too big events for now: %d", evt.Seq) return nil @@ -36,7 +39,7 @@ func ConsumeRepoStreamLite(ctx context.Context, con *websocket.Conn, cb LiteStre return nil } - if rc.String() != *op.Cid { + if lexutil.LexLink(rc) != *op.Cid { return fmt.Errorf("mismatch in record and op cid: %s != %s", rc, *op.Cid) } diff --git a/gen/main.go b/gen/main.go index 96c66bf4e..fa0c9b8e4 100644 --- a/gen/main.go +++ b/gen/main.go @@ -24,19 +24,36 @@ func main() { panic(err) } - if err := cbg.WriteMapEncodersToFile("api/bsky/cbor_gen.go", "bsky", bsky.FeedPost{}, bsky.FeedRepost{}, bsky.FeedVote{}, bsky.FeedPost_Entity{}, bsky.FeedPost_ReplyRef{}, bsky.FeedPost_TextSlice{}, bsky.EmbedImages{}, bsky.EmbedImages_PresentedImage{}, bsky.EmbedExternal{}, bsky.EmbedExternal_External{}, bsky.EmbedImages_Image{}, bsky.GraphFollow{}, bsky.ActorRef{}, bsky.ActorProfile{}, bsky.SystemDeclaration{}, bsky.GraphAssertion{}, bsky.GraphConfirmation{}, bsky.EmbedRecord{}); err != nil { + if err := cbg.WriteMapEncodersToFile("api/bsky/cbor_gen.go", "bsky", + bsky.FeedPost{}, bsky.FeedRepost{}, bsky.FeedPost_Entity{}, + bsky.FeedPost_ReplyRef{}, bsky.FeedPost_TextSlice{}, bsky.EmbedImages{}, + bsky.EmbedExternal{}, bsky.EmbedExternal_External{}, + bsky.EmbedImages_Image{}, bsky.GraphFollow{}, bsky.ActorProfile{}, + bsky.EmbedRecord{}, bsky.FeedLike{}, bsky.RichtextFacet{}, + bsky.RichtextFacet_ByteSlice{}, bsky.RichtextFacet_Features_Elem{}, + bsky.RichtextFacet_Link{}, bsky.RichtextFacet_Mention{}, + bsky.EmbedRecordWithMedia{}, + bsky.FeedDefs_NotFoundPost{}, + /*bsky.EmbedImages_View{}, + bsky.EmbedRecord_View{}, bsky.EmbedRecordWithMedia_View{}, + bsky.EmbedExternal_View{}, bsky.EmbedImages_ViewImage{}, + bsky.EmbedExternal_ViewExternal{}, bsky.EmbedRecord_ViewNotFound{}, + bsky.FeedDefs_ThreadViewPost{}, bsky.EmbedRecord_ViewRecord{}, + bsky.FeedDefs_PostView{}, bsky.ActorDefs_ProfileViewBasic{}, + */ + ); err != nil { panic(err) } - if err := cbg.WriteMapEncodersToFile("api/atproto/cbor_gen.go", "atproto", atproto.RepoStrongRef{}); err != nil { + if err := cbg.WriteMapEncodersToFile("api/atproto/cbor_gen.go", "atproto", atproto.RepoStrongRef{}, atproto.SyncSubscribeRepos_Commit{}, atproto.SyncSubscribeRepos_Handle{}, atproto.SyncSubscribeRepos_Info{}, atproto.SyncSubscribeRepos_Migrate{}, atproto.SyncSubscribeRepos_RepoOp{}, atproto.SyncSubscribeRepos_Tombstone{}); err != nil { panic(err) } - if err := cbg.WriteMapEncodersToFile("lex/util/cbor_gen.go", "util", lexutil.CborChecker{}, lexutil.Blob{}); err != nil { + if err := cbg.WriteMapEncodersToFile("lex/util/cbor_gen.go", "util", lexutil.CborChecker{}, lexutil.LegacyBlob{}, lexutil.BlobSchema{}); err != nil { panic(err) } - if err := cbg.WriteMapEncodersToFile("events/cbor_gen.go", "events", events.EventHeader{}, events.RepoAppend{}, events.RepoOp{}, events.InfoFrame{}, events.ErrorFrame{}, events.Label{}, events.LabelBatch{}); err != nil { + if err := cbg.WriteMapEncodersToFile("events/cbor_gen.go", "events", events.EventHeader{}, events.ErrorFrame{}, events.Label{}, events.LabelBatch{}); err != nil { panic(err) } } diff --git a/go.mod b/go.mod index 3c4087ccf..b70456096 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/prometheus/client_golang v1.14.0 github.com/stretchr/testify v1.8.1 github.com/urfave/cli/v2 v2.23.7 - github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa + github.com/whyrusleeping/cbor-gen v0.0.0-20230331140348-1f892b517e70 github.com/whyrusleeping/go-did v0.0.0-20230301193428-2146016fc220 go.opentelemetry.io/otel v1.11.2 go.opentelemetry.io/otel/exporters/jaeger v1.11.2 diff --git a/go.sum b/go.sum index 13b36908d..bbb6d87f1 100644 --- a/go.sum +++ b/go.sum @@ -627,6 +627,10 @@ github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvS github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 h1:5HZfQkwe0mIfyDmc1Em5GqlNRzcdtlv4HTNmdpt7XH0= github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa h1:EyA027ZAkuaCLoxVX4r1TZMPy1d31fM6hbfQ4OU4I5o= github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= +github.com/whyrusleeping/cbor-gen v0.0.0-20230331140123-68b8a684906e h1:66UCBX90o0vfhi4olXkxlZZa0MPkhIyAsJg3YFTU3Q4= +github.com/whyrusleeping/cbor-gen v0.0.0-20230331140123-68b8a684906e/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= +github.com/whyrusleeping/cbor-gen v0.0.0-20230331140348-1f892b517e70 h1:iNBzUKTsJc9RqStEVX2VYgVHATTU39IuB7g0e8OPWXU= +github.com/whyrusleeping/cbor-gen v0.0.0-20230331140348-1f892b517e70/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= github.com/whyrusleeping/go-did v0.0.0-20230301193428-2146016fc220 h1:EO/9z3yDvx1van1/0esdcqhalZZQGRj3I1BPTWr5k3A= github.com/whyrusleeping/go-did v0.0.0-20230301193428-2146016fc220/go.mod h1:qPtRyexGM5XMHFIfjH+EiA/A/1n2JakWEdMPC53pJAE= diff --git a/indexer/crawler.go b/indexer/crawler.go index e5f9d9e81..96908a707 100644 --- a/indexer/crawler.go +++ b/indexer/crawler.go @@ -3,9 +3,10 @@ package indexer import ( "context" - "github.com/bluesky-social/indigo/events" + comatproto "github.com/bluesky-social/indigo/api/atproto" "github.com/bluesky-social/indigo/models" "github.com/bluesky-social/indigo/util" + "go.opentelemetry.io/otel" ) @@ -40,7 +41,7 @@ func (c *CrawlDispatcher) Run() { } type catchupJob struct { - evt *events.RepoAppend + evt *comatproto.SyncSubscribeRepos_Commit host *models.PDS user *models.ActorInfo } @@ -181,7 +182,7 @@ func (c *CrawlDispatcher) Crawl(ctx context.Context, ai *models.ActorInfo) error } } -func (c *CrawlDispatcher) AddToCatchupQueue(ctx context.Context, host *models.PDS, u *models.ActorInfo, evt *events.RepoAppend) error { +func (c *CrawlDispatcher) AddToCatchupQueue(ctx context.Context, host *models.PDS, u *models.ActorInfo, evt *comatproto.SyncSubscribeRepos_Commit) error { if u.PDS == 0 { panic("not okay") } diff --git a/indexer/indexer.go b/indexer/indexer.go index d07ae1b26..d3711807c 100644 --- a/indexer/indexer.go +++ b/indexer/indexer.go @@ -8,16 +8,18 @@ import ( "strings" "time" - atproto "github.com/bluesky-social/indigo/api/atproto" + comatproto "github.com/bluesky-social/indigo/api/atproto" bsky "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/carstore" "github.com/bluesky-social/indigo/events" + lexutil "github.com/bluesky-social/indigo/lex/util" "github.com/bluesky-social/indigo/models" "github.com/bluesky-social/indigo/notifs" "github.com/bluesky-social/indigo/plc" "github.com/bluesky-social/indigo/repomgr" "github.com/bluesky-social/indigo/util" "github.com/bluesky-social/indigo/xrpc" + "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log" "go.opentelemetry.io/otel" @@ -80,17 +82,13 @@ func (ix *Indexer) HandleRepoEvent(ctx context.Context, evt *repomgr.RepoEvent) log.Infow("Handling Repo Event!", "uid", evt.User) - var outops []*events.RepoOp + var outops []*comatproto.SyncSubscribeRepos_RepoOp for _, op := range evt.Ops { - var cc *string - if op.RecCid != nil { - s := op.RecCid.String() - cc = &s - } - outops = append(outops, &events.RepoOp{ + link := (*lexutil.LexLink)(op.RecCid) + outops = append(outops, &comatproto.SyncSubscribeRepos_RepoOp{ Path: op.Collection + "/" + op.Rkey, Action: string(op.Kind), - Cid: cc, + Cid: link, }) switch op.Kind { @@ -131,13 +129,6 @@ func (ix *Indexer) HandleRepoEvent(ctx context.Context, evt *repomgr.RepoEvent) return err } - // TODO: these should be cids on the wire - var prevstr *string - if evt.OldRoot != nil { - s := evt.OldRoot.String() - prevstr = &s - } - toobig := false slice := evt.RepoSlice if len(slice) > carstore.MaxSliceLength { @@ -148,11 +139,11 @@ func (ix *Indexer) HandleRepoEvent(ctx context.Context, evt *repomgr.RepoEvent) log.Infow("Sending event", "did", did) if err := ix.events.AddEvent(ctx, &events.XRPCStreamEvent{ - RepoAppend: &events.RepoAppend{ + RepoCommit: &comatproto.SyncSubscribeRepos_Commit{ Repo: did, - Prev: prevstr, + Prev: (*lexutil.LexLink)(evt.OldRoot), Blocks: slice, - Commit: evt.NewRoot.String(), + Commit: lexutil.LexLink(evt.NewRoot), Time: time.Now().Format(util.ISO8601), Ops: outops, TooBig: toobig, @@ -204,7 +195,7 @@ func (ix *Indexer) handleRecordDelete(ctx context.Context, evt *repomgr.RepoEven */ case "app.bsky.feed.vote": - return ix.handleRecordDeleteFeedVote(ctx, evt, op) + return ix.handleRecordDeleteFeedLike(ctx, evt, op) case "app.bsky.graph.follow": return ix.handleRecordDeleteGraphFollow(ctx, evt, op) case "app.bsky.graph.confirmation": @@ -215,7 +206,7 @@ func (ix *Indexer) handleRecordDelete(ctx context.Context, evt *repomgr.RepoEven return nil } -func (ix *Indexer) handleRecordDeleteFeedVote(ctx context.Context, evt *repomgr.RepoEvent, op *repomgr.RepoOp) error { +func (ix *Indexer) handleRecordDeleteFeedLike(ctx context.Context, evt *repomgr.RepoEvent, op *repomgr.RepoOp) error { var vr models.VoteRecord if err := ix.db.Find(&vr, "voter = ? AND rkey = ?", evt.User, op.Rkey).Error; err != nil { return err @@ -292,18 +283,12 @@ func (ix *Indexer) handleRecordCreate(ctx context.Context, evt *repomgr.RepoEven return nil, err } - case *bsky.FeedVote: - return nil, ix.handleRecordCreateFeedVote(ctx, rec, evt, op) + case *bsky.FeedLike: + return nil, ix.handleRecordCreateFeedLike(ctx, rec, evt, op) case *bsky.GraphFollow: return out, ix.handleRecordCreateGraphFollow(ctx, rec, evt, op) case *bsky.ActorProfile: log.Infof("TODO: got actor profile record creation, need to do something with this") - case *bsky.SystemDeclaration: - log.Infof("TODO: got system declaration record creation, need to do something with this") - case *bsky.GraphAssertion: - log.Infof("TODO: got graph assertion record creation, need to do something with this") - case *bsky.GraphConfirmation: - log.Infof("TODO: got graph confirmation record creation, need to do something with this") default: return nil, fmt.Errorf("unrecognized record type: %T", rec) } @@ -360,7 +345,7 @@ func (ix *Indexer) crawlRecordReferences(ctx context.Context, op *repomgr.RepoOp } } return nil - case *bsky.FeedVote: + case *bsky.FeedLike: if rec.Subject != nil { if err := ix.crawlAtUriRef(ctx, rec.Subject.Uri); err != nil { log.Infow("failed to crawl vote subject", "cid", op.RecCid, "subjecturi", rec.Subject.Uri, "err", err) @@ -368,38 +353,20 @@ func (ix *Indexer) crawlRecordReferences(ctx context.Context, op *repomgr.RepoOp } return nil case *bsky.GraphFollow: - if rec.Subject != nil { - _, err := ix.GetUserOrMissing(ctx, rec.Subject.Did) - if err != nil { - log.Infow("failed to crawl follow subject", "cid", op.RecCid, "subjectdid", rec.Subject.Did, "err", err) - } + _, err := ix.GetUserOrMissing(ctx, rec.Subject) + if err != nil { + log.Infow("failed to crawl follow subject", "cid", op.RecCid, "subjectdid", rec.Subject, "err", err) } return nil case *bsky.ActorProfile: return nil - case *bsky.SystemDeclaration: - return nil - case *bsky.GraphAssertion: - return nil - case *bsky.GraphConfirmation: - return nil default: log.Warnf("unrecognized record type: %T", rec) return nil } } -func (ix *Indexer) handleRecordCreateFeedVote(ctx context.Context, rec *bsky.FeedVote, evt *repomgr.RepoEvent, op *repomgr.RepoOp) error { - var dbdir models.VoteDir - switch rec.Direction { - case "up": - dbdir = models.VoteDirUp - case "down": - return nil - default: - return fmt.Errorf("invalid vote direction: %q", rec.Direction) - } - +func (ix *Indexer) handleRecordCreateFeedLike(ctx context.Context, rec *bsky.FeedLike, evt *repomgr.RepoEvent, op *repomgr.RepoOp) error { post, err := ix.GetPostOrMissing(ctx, rec.Subject.Uri) if err != nil { return err @@ -411,7 +378,6 @@ func (ix *Indexer) handleRecordCreateFeedVote(ctx context.Context, rec *bsky.Fee } vr := models.VoteRecord{ - Dir: dbdir, Voter: evt.User, Post: post.ID, Created: rec.CreatedAt, @@ -422,26 +388,24 @@ func (ix *Indexer) handleRecordCreateFeedVote(ctx context.Context, rec *bsky.Fee return err } - if rec.Direction == "up" { - if err := ix.db.Model(models.FeedPost{}).Where("id = ?", post.ID).Update("up_count", gorm.Expr("up_count + 1")).Error; err != nil { - return err - } - if err := ix.addNewVoteNotification(ctx, act.Uid, &vr); err != nil { - return err - } + if err := ix.db.Model(models.FeedPost{}).Where("id = ?", post.ID).Update("up_count", gorm.Expr("up_count + 1")).Error; err != nil { + return err + } + if err := ix.addNewVoteNotification(ctx, act.Uid, &vr); err != nil { + return err } return nil } func (ix *Indexer) handleRecordCreateGraphFollow(ctx context.Context, rec *bsky.GraphFollow, evt *repomgr.RepoEvent, op *repomgr.RepoOp) error { - subj, err := ix.LookupUserByDid(ctx, rec.Subject.Did) + subj, err := ix.LookupUserByDid(ctx, rec.Subject) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { return fmt.Errorf("failed to lookup user: %w", err) } - nu, err := ix.createMissingUserRecord(ctx, rec.Subject.Did) + nu, err := ix.createMissingUserRecord(ctx, rec.Subject) if err != nil { return fmt.Errorf("create external user: %w", err) } @@ -524,7 +488,7 @@ func (ix *Indexer) handleRecordUpdate(ctx context.Context, evt *repomgr.RepoEven return err } - case *bsky.FeedVote: + case *bsky.FeedLike: var vr models.VoteRecord if err := ix.db.Find(&vr, "voted = ? AND rkey = ?", evt.User, op.Rkey).Error; err != nil { return err @@ -537,23 +501,14 @@ func (ix *Indexer) handleRecordUpdate(ctx context.Context, evt *repomgr.RepoEven if vr.Post != fp.ID { // vote is on a completely different post, delete old one, create new one - if err := ix.handleRecordDeleteFeedVote(ctx, evt, op); err != nil { + if err := ix.handleRecordDeleteFeedLike(ctx, evt, op); err != nil { return err } - return ix.handleRecordCreateFeedVote(ctx, rec, evt, op) - } - - if vr.Dir.String() == rec.Direction { - // do nothing? - return nil - } - - if rec.Direction != "up" { - return ix.handleRecordDeleteFeedVote(ctx, evt, op) + return ix.handleRecordCreateFeedLike(ctx, rec, evt, op) } - return ix.handleRecordCreateFeedVote(ctx, rec, evt, op) + return ix.handleRecordCreateFeedLike(ctx, rec, evt, op) case *bsky.GraphFollow: if err := ix.handleRecordDeleteGraphFollow(ctx, evt, op); err != nil { return err @@ -562,12 +517,6 @@ func (ix *Indexer) handleRecordUpdate(ctx context.Context, evt *repomgr.RepoEven return ix.handleRecordCreateGraphFollow(ctx, rec, evt, op) case *bsky.ActorProfile: log.Infof("TODO: got actor profile record update, need to do something with this") - case *bsky.SystemDeclaration: - log.Infof("TODO: got system declaration record update, need to do something with this") - case *bsky.GraphAssertion: - log.Infof("TODO: got graph assertion record update, need to do something with this") - case *bsky.GraphConfirmation: - log.Infof("TODO: got graph confirmation record update, need to do something with this") default: return fmt.Errorf("unrecognized record type: %T", rec) } @@ -802,7 +751,6 @@ func (ix *Indexer) handleInitActor(ctx context.Context, evt *repomgr.RepoEvent, Handle: ai.Handle, Did: ai.Did, DisplayName: ai.DisplayName, - DeclRefCid: ai.DeclRefCid, Type: ai.Type, PDS: evt.PDS, }).Error; err != nil { @@ -903,7 +851,7 @@ func (ix *Indexer) FetchAndIndexRepo(ctx context.Context, job *crawlWork) error } // TODO: max size on these? A malicious PDS could just send us a petabyte sized repo here and kill us - repo, err := atproto.SyncGetRepo(ctx, c, ai.Did, from, "") + repo, err := comatproto.SyncGetRepo(ctx, c, ai.Did, from, "") if err != nil { return fmt.Errorf("failed to fetch repo: %w", err) } diff --git a/indexer/keymgr.go b/indexer/keymgr.go index 2d22e9c21..b13b980d6 100644 --- a/indexer/keymgr.go +++ b/indexer/keymgr.go @@ -34,7 +34,11 @@ func (km *KeyManager) VerifyUserSignature(ctx context.Context, did string, sig [ return err } - return k.Verify(msg, sig) + err = k.Verify(msg, sig) + if err != nil { + log.Warnw("signature failed to verify", "err", err, "did", did, "pubKey", k, "sigBytes", sig, "msgBytes", msg) + } + return err } func (km *KeyManager) getKey(ctx context.Context, did string) (*did.PubKey, error) { diff --git a/labeling/hiveai.go b/labeling/hiveai.go index 862f659a1..af4e16f4d 100644 --- a/labeling/hiveai.go +++ b/labeling/hiveai.go @@ -98,14 +98,14 @@ func (resp *HiveAIResp) SummarizeLabels() []string { return labels } -func (hal *HiveAILabeler) LabelBlob(ctx context.Context, blob lexutil.Blob, blobBytes []byte) ([]string, error) { +func (hal *HiveAILabeler) LabelBlob(ctx context.Context, blob lexutil.LexBlob, blobBytes []byte) ([]string, error) { - log.Infof("sending blob to thehive.ai cid=%s mimetype=%s size=%d", blob.Cid, blob.MimeType, len(blobBytes)) + log.Infof("sending blob to thehive.ai cid=%s mimetype=%s size=%d", blob.Ref, blob.MimeType, len(blobBytes)) // generic HTTP form file upload, then parse the response JSON body := &bytes.Buffer{} writer := multipart.NewWriter(body) - part, err := writer.CreateFormFile("media", blob.Cid) + part, err := writer.CreateFormFile("media", blob.Ref.String()) if err != nil { return nil, err } @@ -142,13 +142,13 @@ func (hal *HiveAILabeler) LabelBlob(ctx context.Context, blob lexutil.Blob, blob return nil, fmt.Errorf("failed to read HiveAI resp body: %v", err) } - log.Debugf("HiveAI raw result cid=%s body=%v", blob.Cid, string(respBytes)) + log.Debugf("HiveAI raw result cid=%s body=%v", blob.Ref, string(respBytes)) var respObj HiveAIResp if err := json.Unmarshal(respBytes, &respObj); err != nil { return nil, fmt.Errorf("failed to parse HiveAI resp JSON: %v", err) } respJson, _ := json.Marshal(respObj.Status[0].Response.Output[0]) - log.Infof("HiveAI result cid=%s json=%v", blob.Cid, string(respJson)) + log.Infof("HiveAI result cid=%s json=%v", blob.Ref, string(respJson)) return respObj.SummarizeLabels(), nil } diff --git a/labeling/keyword_labeler.go b/labeling/keyword_labeler.go index ee85ceeb1..435712bb1 100644 --- a/labeling/keyword_labeler.go +++ b/labeling/keyword_labeler.go @@ -30,7 +30,10 @@ func (kl KeywordLabeler) LabelPost(p appbsky.FeedPost) []string { } func (kl KeywordLabeler) LabelProfile(ap appbsky.ActorProfile) []string { - txt := ap.DisplayName + var txt string + if ap.DisplayName != nil { + txt += *ap.DisplayName + } if ap.Description != nil { txt += *ap.Description } diff --git a/labeling/keyword_labeler_test.go b/labeling/keyword_labeler_test.go index a1f37bb80..e7d7baf1a 100644 --- a/labeling/keyword_labeler_test.go +++ b/labeling/keyword_labeler_test.go @@ -28,16 +28,19 @@ func TestKeywordFilter(t *testing.T) { } } - var desc = "yadda yadda" - var descRude = "yadda yadda 🍆" + desc := "yadda yadda" + descRude := "yadda yadda 🍆" + name := "Robyn Hood" + nameSexy := "Sexy Robyn Hood" profileCases := []struct { record bsky.ActorProfile expected []string }{ - {bsky.ActorProfile{DisplayName: "Robyn Hood"}, []string{}}, - {bsky.ActorProfile{DisplayName: "Robyn Hood", Description: &desc}, []string{}}, - {bsky.ActorProfile{DisplayName: "Robyn Hood", Description: &descRude}, []string{"rude"}}, - {bsky.ActorProfile{DisplayName: "Sexy Robyn Hood"}, []string{"rude"}}, + {bsky.ActorProfile{DisplayName: &name}, []string{}}, + {bsky.ActorProfile{DisplayName: &name, Description: &desc}, []string{}}, + {bsky.ActorProfile{DisplayName: &name, Description: &descRude}, []string{"rude"}}, + {bsky.ActorProfile{DisplayName: &nameSexy}, []string{"rude"}}, + {bsky.ActorProfile{DisplayName: &nameSexy, Description: &descRude}, []string{"rude"}}, } for _, c := range profileCases { diff --git a/labeling/micro_nsfw_img.go b/labeling/micro_nsfw_img.go index 4617c56e7..535f21a09 100644 --- a/labeling/micro_nsfw_img.go +++ b/labeling/micro_nsfw_img.go @@ -59,14 +59,14 @@ func (resp *MicroNSFWImgResp) SummarizeLabels() []string { return labels } -func (mnil *MicroNSFWImgLabeler) LabelBlob(ctx context.Context, blob lexutil.Blob, blobBytes []byte) ([]string, error) { +func (mnil *MicroNSFWImgLabeler) LabelBlob(ctx context.Context, blob lexutil.LexBlob, blobBytes []byte) ([]string, error) { - log.Infof("sending blob to micro-NSFW-img cid=%s mimetype=%s size=%d", blob.Cid, blob.MimeType, len(blobBytes)) + log.Infof("sending blob to micro-NSFW-img cid=%s mimetype=%s size=%d", blob.Ref, blob.MimeType, len(blobBytes)) // generic HTTP form file upload, then parse the response JSON body := &bytes.Buffer{} writer := multipart.NewWriter(body) - part, err := writer.CreateFormFile("file", blob.Cid) + part, err := writer.CreateFormFile("file", blob.Ref.String()) if err != nil { return nil, err } @@ -105,6 +105,6 @@ func (mnil *MicroNSFWImgLabeler) LabelBlob(ctx context.Context, blob lexutil.Blo return nil, fmt.Errorf("failed to parse micro-NSFW-img resp JSON: %v", err) } scoreJson, _ := json.Marshal(nsfwScore) - log.Infof("micro-NSFW-img result cid=%s scores=%v", blob.Cid, string(scoreJson)) + log.Infof("micro-NSFW-img result cid=%s scores=%v", blob.Ref, string(scoreJson)) return nsfwScore.SummarizeLabels(), nil } diff --git a/labeling/service.go b/labeling/service.go index 810ab6ad3..742baa831 100644 --- a/labeling/service.go +++ b/labeling/service.go @@ -10,6 +10,7 @@ import ( "time" "github.com/bluesky-social/indigo/api" + comatproto "github.com/bluesky-social/indigo/api/atproto" appbsky "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/bgs" "github.com/bluesky-social/indigo/carstore" @@ -23,7 +24,6 @@ import ( util "github.com/bluesky-social/indigo/util" cbg "github.com/whyrusleeping/cbor-gen" - "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" @@ -79,7 +79,7 @@ func NewServer(db *gorm.DB, cs *carstore.CarStore, repoUser RepoConfig, plcURL, // NOTE: doesn't need to have app.bsky profile and actor config, this is just expediant (reusing an existing helper function) ctx := context.Background() head, _ := s.repoman.GetRepoRoot(ctx, s.user.UserId) - if head == cid.Undef { + if !head.Defined() { log.Info("initializing labelmaker repo") if err := s.repoman.InitNewActor(ctx, s.user.UserId, s.user.Handle, s.user.Did, "Label Maker", pds.UserActorDeclCid, pds.UserActorDeclType); err != nil { return nil, fmt.Errorf("creating labelmaker repo: %w", err) @@ -127,7 +127,7 @@ func (s *Server) SubscribeBGS(ctx context.Context, bgsURL string, useWss bool) { } // efficiency predicate to quickly discard events we know that we shouldn't even bother parsing -func (s *Server) wantAnyRecords(ctx context.Context, ra *events.RepoAppend) bool { +func (s *Server) wantAnyRecords(ctx context.Context, ra *comatproto.SyncSubscribeRepos_Commit) bool { for _, op := range ra.Ops { if op.Action != "create" && op.Action != "update" { @@ -147,7 +147,7 @@ func (s *Server) wantAnyRecords(ctx context.Context, ra *events.RepoAppend) bool } // should we bother to fetch blob for processing? -func (s *Server) wantBlob(ctx context.Context, blob *lexutil.Blob) bool { +func (s *Server) wantBlob(ctx context.Context, blob *lexutil.LexBlob) bool { log.Debugf("wantBlob blob=%v", blob) // images if blob.MimeType == "image/png" || blob.MimeType == "image/jpeg" { @@ -159,10 +159,10 @@ func (s *Server) wantBlob(ctx context.Context, blob *lexutil.Blob) bool { return false } -func (s *Server) labelRecord(ctx context.Context, did, nsid, uri, cid string, rec cbg.CBORMarshaler) ([]string, error) { +func (s *Server) labelRecord(ctx context.Context, did, nsid, uri, cidStr string, rec cbg.CBORMarshaler) ([]string, error) { log.Infof("labeling record: %v", uri) var labelVals []string - var blobs []lexutil.Blob + var blobs []lexutil.LexBlob switch nsid { case "app.bsky.feed.post": post, suc := rec.(*appbsky.FeedPost) @@ -223,12 +223,12 @@ func (s *Server) labelRecord(ctx context.Context, did, nsid, uri, cid string, re log.Infof("will process %d blobs", len(blobs)) for _, blob := range blobs { - if blob.Cid == "" { + if !blob.Ref.Defined() { return nil, fmt.Errorf("received stub blob (CID undefined)") } if !s.wantBlob(ctx, &blob) { - log.Infof("skipping blob: cid=%s", blob.Cid) + log.Infof("skipping blob: cid=%s", blob.Ref.String()) continue } // download image for process @@ -248,21 +248,21 @@ func (s *Server) labelRecord(ctx context.Context, did, nsid, uri, cid string, re return dedupeStrings(labelVals), nil } -func (s *Server) downloadRepoBlob(ctx context.Context, did string, blob *lexutil.Blob) ([]byte, error) { +func (s *Server) downloadRepoBlob(ctx context.Context, did string, blob *lexutil.LexBlob) ([]byte, error) { var blobBytes []byte - if blob.Cid == "" { + if !blob.Ref.Defined() { return nil, fmt.Errorf("invalid blob to download (CID undefined)") } - log.Infof("downloading blob pds=%s did=%s cid=%s", s.blobPdsURL, did, blob.Cid) + log.Infof("downloading blob pds=%s did=%s cid=%s", s.blobPdsURL, did, blob.Ref.String()) // TODO(bnewbold): more robust blob fetch code, by constructing query param // properly; looking up DID doc; using xrpc.Client (with persistend HTTP // client); etc. // blocked on getBlob atproto branch landing, with new Lexicon. // for now, just fetching from configured PDS (aka our single PDS) - xrpcURL := fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", s.blobPdsURL, did, blob.Cid) + xrpcURL := fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", s.blobPdsURL, did, blob.Ref.String()) resp, err := http.Get(xrpcURL) if err != nil { @@ -271,7 +271,7 @@ func (s *Server) downloadRepoBlob(ctx context.Context, did string, blob *lexutil defer resp.Body.Close() if resp.StatusCode != 200 { - return nil, fmt.Errorf("failed to fetch blob from PDS. did=%s cid=%s statusCode=%d", did, blob.Cid, resp.StatusCode) + return nil, fmt.Errorf("failed to fetch blob from PDS. did=%s cid=%s statusCode=%d", did, blob.Ref.String(), resp.StatusCode) } blobBytes, err = io.ReadAll(resp.Body) @@ -282,11 +282,11 @@ func (s *Server) downloadRepoBlob(ctx context.Context, did string, blob *lexutil return blobBytes, nil } -func (s *Server) labelBlob(ctx context.Context, did string, blob lexutil.Blob, blobBytes []byte) ([]string, error) { +func (s *Server) labelBlob(ctx context.Context, did string, blob lexutil.LexBlob, blobBytes []byte) ([]string, error) { var labelVals []string - if blob.Cid == "" { + if !blob.Ref.Defined() { return nil, fmt.Errorf("invalid blob to label (CID undefined)") } @@ -316,18 +316,18 @@ func (s *Server) labelBlob(ctx context.Context, did string, blob lexutil.Blob, b // labeling routine, and then persists and broadcasts any resulting labels func (s *Server) handleBgsRepoEvent(ctx context.Context, pds *models.PDS, evt *events.XRPCStreamEvent) error { - if evt.RepoAppend == nil { + if evt.RepoCommit == nil { // TODO(bnewbold): is this really invalid? do we need to handle Info and Error events here? - return fmt.Errorf("invalid repo append event") + return fmt.Errorf("invalid repo commit event") } // quick check if we can skip processing the CAR slice entirely - if !s.wantAnyRecords(ctx, evt.RepoAppend) { + if !s.wantAnyRecords(ctx, evt.RepoCommit) { return nil } // use an in-memory blockstore with repo wrapper to parse CAR slice - sliceRepo, err := repo.ReadRepoFromCar(ctx, bytes.NewReader(evt.RepoAppend.Blocks)) + sliceRepo, err := repo.ReadRepoFromCar(ctx, bytes.NewReader(evt.RepoCommit.Blocks)) if err != nil { log.Warnw("failed to parse CAR slice", "repoErr", err) return err @@ -336,8 +336,8 @@ func (s *Server) handleBgsRepoEvent(ctx context.Context, pds *models.PDS, evt *e now := time.Now().Format(util.ISO8601) labels := []events.Label{} - for _, op := range evt.RepoAppend.Ops { - uri := "at://" + evt.RepoAppend.Repo + "/" + op.Path + for _, op := range evt.RepoCommit.Ops { + uri := "at://" + evt.RepoCommit.Repo + "/" + op.Path nsid := strings.SplitN(op.Path, "/", 2)[0] if !(op.Action == "create" || op.Action == "update") { @@ -349,7 +349,7 @@ func (s *Server) handleBgsRepoEvent(ctx context.Context, pds *models.PDS, evt *e return fmt.Errorf("record not in CAR slice: %s", uri) } cidStr := cid.String() - labelVals, err := s.labelRecord(ctx, evt.RepoAppend.Repo, nsid, uri, cidStr, rec) + labelVals, err := s.labelRecord(ctx, evt.RepoCommit.Repo, nsid, uri, cidStr, rec) if err != nil { return err } @@ -359,7 +359,7 @@ func (s *Server) handleBgsRepoEvent(ctx context.Context, pds *models.PDS, evt *e val = strings.SplitN(val, ":", 2)[1] labels = append(labels, events.Label{ SourceDid: s.user.Did, - SubjectUri: "at://" + evt.RepoAppend.Repo, + SubjectUri: "at://" + evt.RepoCommit.Repo, Value: val, Timestamp: now, }) diff --git a/labeling/ws_endpoints.go b/labeling/ws_endpoints.go index 7c4a50714..f684d2308 100644 --- a/labeling/ws_endpoints.go +++ b/labeling/ws_endpoints.go @@ -36,7 +36,7 @@ func (s *Server) EventsLabelsWebsocket(c echo.Context) error { } defer cancel() - header := events.EventHeader{Op: events.EvtKindLabelBatch} + header := events.EventHeader{Op: events.EvtKindMessage} for { select { case evt := <-evts: @@ -48,15 +48,15 @@ func (s *Server) EventsLabelsWebsocket(c echo.Context) error { var obj lexutil.CBOR switch { - case evt.LabelBatch != nil: - header.Op = events.EvtKindLabelBatch - obj = evt.LabelBatch case evt.Error != nil: header.Op = events.EvtKindErrorFrame obj = evt.Error - case evt.Info != nil: - header.Op = events.EvtKindInfoFrame - obj = evt.Info + case evt.RepoInfo != nil: + header.MsgType = "#info" + obj = evt.RepoInfo + case evt.LabelBatch != nil: + header.MsgType = "#labelbatch" + obj = evt.LabelBatch default: return fmt.Errorf("unrecognized event kind") } diff --git a/labeling/xrpc_endpoints.go b/labeling/xrpc_endpoints.go index d0fc45b6f..e49ec0b39 100644 --- a/labeling/xrpc_endpoints.go +++ b/labeling/xrpc_endpoints.go @@ -1,7 +1,6 @@ package labeling import ( - "io" "strconv" atproto "github.com/bluesky-social/indigo/api/atproto" @@ -11,50 +10,37 @@ import ( ) func (s *Server) RegisterHandlersComAtproto(e *echo.Echo) error { - e.GET("/xrpc/com.atproto.account.get", s.HandleComAtprotoAccountGet) - e.GET("/xrpc/com.atproto.handle.resolve", s.HandleComAtprotoHandleResolve) - e.GET("/xrpc/com.atproto.repo.describe", s.HandleComAtprotoRepoDescribe) + e.GET("/xrpc/com.atproto.identity.resolveHandle", s.HandleComAtprotoIdentityResolveHandle) + e.GET("/xrpc/com.atproto.repo.describeRepo", s.HandleComAtprotoRepoDescribeRepo) e.GET("/xrpc/com.atproto.repo.getRecord", s.HandleComAtprotoRepoGetRecord) e.GET("/xrpc/com.atproto.repo.listRecords", s.HandleComAtprotoRepoListRecords) - e.GET("/xrpc/com.atproto.server.getAccountsConfig", s.HandleComAtprotoServerGetAccountsConfig) + e.GET("/xrpc/com.atproto.server.describeServer", s.HandleComAtprotoServerDescribeServer) e.GET("/xrpc/com.atproto.sync.getHead", s.HandleComAtprotoSyncGetHead) return nil } -func (s *Server) HandleComAtprotoAccountGet(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAccountGet") - defer span.End() - var handleErr error - // func (s *Server) handleComAtprotoAccountGet(ctx context.Context) error - handleErr = s.handleComAtprotoAccountGet(ctx) - if handleErr != nil { - return handleErr - } - return nil -} - -func (s *Server) HandleComAtprotoHandleResolve(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoHandleResolve") +func (s *Server) HandleComAtprotoIdentityResolveHandle(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoIdentityResolveHandle") defer span.End() handle := c.QueryParam("handle") - var out *atproto.HandleResolve_Output + var out *atproto.IdentityResolveHandle_Output var handleErr error - // func (s *Server) handleComAtprotoHandleResolve(ctx context.Context,handle string) (*atproto.HandleResolve_Output, error) - out, handleErr = s.handleComAtprotoHandleResolve(ctx, handle) + // func (s *Server) handleComAtprotoIdentityResolveHandle(ctx context.Context,handle string) (*atproto.IdentityResolveHandle_Output, error) + out, handleErr = s.handleComAtprotoIdentityResolveHandle(ctx, handle) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleComAtprotoRepoDescribe(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoDescribe") +func (s *Server) HandleComAtprotoRepoDescribeRepo(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoDescribeRepo") defer span.End() - user := c.QueryParam("user") - var out *atproto.RepoDescribe_Output + repo := c.QueryParam("repo") + var out *atproto.RepoDescribeRepo_Output var handleErr error - // func (s *Server) handleComAtprotoRepoDescribe(ctx context.Context,user string) (*atproto.RepoDescribe_Output, error) - out, handleErr = s.handleComAtprotoRepoDescribe(ctx, user) + // func (s *Server) handleComAtprotoRepoDescribeRepo(ctx context.Context,repo string) (*atproto.RepoDescribeRepo_Output, error) + out, handleErr = s.handleComAtprotoRepoDescribeRepo(ctx, repo) if handleErr != nil { return handleErr } @@ -66,12 +52,12 @@ func (s *Server) HandleComAtprotoRepoGetRecord(c echo.Context) error { defer span.End() cid := c.QueryParam("cid") collection := c.QueryParam("collection") + repo := c.QueryParam("repo") rkey := c.QueryParam("rkey") - user := c.QueryParam("user") var out *atproto.RepoGetRecord_Output var handleErr error - // func (s *Server) handleComAtprotoRepoGetRecord(ctx context.Context,cid string,collection string,rkey string,user string) (*atproto.RepoGetRecord_Output, error) - out, handleErr = s.handleComAtprotoRepoGetRecord(ctx, cid, collection, rkey, user) + // func (s *Server) handleComAtprotoRepoGetRecord(ctx context.Context,cid string,collection string,repo string,rkey string) (*atproto.RepoGetRecord_Output, error) + out, handleErr = s.handleComAtprotoRepoGetRecord(ctx, cid, collection, repo, rkey) if handleErr != nil { return handleErr } @@ -81,8 +67,6 @@ func (s *Server) HandleComAtprotoRepoGetRecord(c echo.Context) error { func (s *Server) HandleComAtprotoRepoListRecords(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoListRecords") defer span.End() - after := c.QueryParam("after") - before := c.QueryParam("before") collection := c.QueryParam("collection") var limit int @@ -95,6 +79,7 @@ func (s *Server) HandleComAtprotoRepoListRecords(c echo.Context) error { } else { limit = 50 } + repo := c.QueryParam("repo") var reverse *bool if p := c.QueryParam("reverse"); p != "" { @@ -104,53 +89,38 @@ func (s *Server) HandleComAtprotoRepoListRecords(c echo.Context) error { } reverse = &reverse_val } - user := c.QueryParam("user") + rkeyEnd := c.QueryParam("rkeyEnd") + rkeyStart := c.QueryParam("rkeyStart") var out *atproto.RepoListRecords_Output var handleErr error - // func (s *Server) handleComAtprotoRepoListRecords(ctx context.Context,after string,before string,collection string,limit int,reverse *bool,user string) (*atproto.RepoListRecords_Output, error) - out, handleErr = s.handleComAtprotoRepoListRecords(ctx, after, before, collection, limit, reverse, user) + // func (s *Server) handleComAtprotoRepoListRecords(ctx context.Context,collection string,limit int,repo string,reverse *bool,rkeyEnd string,rkeyStart string) (*comatprototypes.RepoListRecords_Output, error) + out, handleErr = s.handleComAtprotoRepoListRecords(ctx, collection, limit, repo, reverse, rkeyEnd, rkeyStart) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleComAtprotoServerGetAccountsConfig(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerGetAccountsConfig") +func (s *Server) HandleComAtprotoServerDescribeServer(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerDescribeServer") defer span.End() - var out *atproto.ServerGetAccountsConfig_Output + var out *atproto.ServerDescribeServer_Output var handleErr error - // func (s *Server) handleComAtprotoServerGetAccountsConfig(ctx context.Context) (*atproto.ServerGetAccountsConfig_Output, error) - out, handleErr = s.handleComAtprotoServerGetAccountsConfig(ctx) + // func (s *Server) handleComAtprotoServerDescribeServer(ctx context.Context) (*atproto.ServerDescribeServer_Output, error) + out, handleErr = s.handleComAtprotoServerDescribeServer(ctx) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleComAtprotoSyncGetRepo(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSyncGetRepo") - defer span.End() - did := c.QueryParam("did") - earliest := c.QueryParam("earliest") - latest := c.QueryParam("latest") - var out io.Reader - var handleErr error - // func (s *Server) handleComAtprotoSyncGetRepo(ctx context.Context,did string,earliest string,latest string) (io.Reader, error) - out, handleErr = s.handleComAtprotoSyncGetRepo(ctx, did, earliest, latest) - if handleErr != nil { - return handleErr - } - return c.Stream(200, "application/vnd.ipld.car", out) -} - func (s *Server) HandleComAtprotoSyncGetHead(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSyncGetHead") defer span.End() did := c.QueryParam("did") var out *atproto.SyncGetHead_Output var handleErr error - // func (s *Server) handleComAtprotoSyncGetHead(ctx context.Context,did string) (*comatprototypes.SyncGetHead_Output, error) + // func (s *Server) handleComAtprotoSyncGetHead(ctx context.Context,did string) (*atproto.SyncGetHead_Output, error) out, handleErr = s.handleComAtprotoSyncGetHead(ctx, did) if handleErr != nil { return handleErr diff --git a/labeling/xrpc_handlers.go b/labeling/xrpc_handlers.go index 86d478e3f..372c17a21 100644 --- a/labeling/xrpc_handlers.go +++ b/labeling/xrpc_handlers.go @@ -13,36 +13,31 @@ import ( "github.com/ipfs/go-cid" ) -func (s *Server) handleComAtprotoAccountGet(ctx context.Context) error { - // TODO: implementation - return nil -} - -func (s *Server) handleComAtprotoHandleResolve(ctx context.Context, handle string) (*atproto.HandleResolve_Output, error) { +func (s *Server) handleComAtprotoIdentityResolveHandle(ctx context.Context, handle string) (*atproto.IdentityResolveHandle_Output, error) { // only the one handle, for labelmaker if handle == "" { - return &atproto.HandleResolve_Output{Did: s.user.SigningKey.Public().DID()}, nil + return &atproto.IdentityResolveHandle_Output{Did: s.user.SigningKey.Public().DID()}, nil } else if handle == s.user.Handle { - return &atproto.HandleResolve_Output{Did: s.user.Did}, nil + return &atproto.IdentityResolveHandle_Output{Did: s.user.Did}, nil } else { return nil, fmt.Errorf("handle not found: %s", handle) } } -func (s *Server) handleComAtprotoRepoDescribe(ctx context.Context, user string) (*atproto.RepoDescribe_Output, error) { +func (s *Server) handleComAtprotoRepoDescribeRepo(ctx context.Context, repo string) (*atproto.RepoDescribeRepo_Output, error) { panic("not yet implemented") } -func (s *Server) handleComAtprotoRepoListRecords(ctx context.Context, after string, before string, collection string, limit int, reverse *bool, user string) (*atproto.RepoListRecords_Output, error) { +func (s *Server) handleComAtprotoRepoListRecords(ctx context.Context, collection string, limit int, repo string, reverse *bool, rkeyEnd string, rkeyStart string) (*atproto.RepoListRecords_Output, error) { panic("not yet implemented") } -func (s *Server) handleComAtprotoServerGetAccountsConfig(ctx context.Context) (*atproto.ServerGetAccountsConfig_Output, error) { +func (s *Server) handleComAtprotoServerDescribeServer(ctx context.Context) (*atproto.ServerDescribeServer_Output, error) { invcode := true - return &atproto.ServerGetAccountsConfig_Output{ + return &atproto.ServerDescribeServer_Output{ InviteCodeRequired: &invcode, AvailableUserDomains: []string{}, - Links: &atproto.ServerGetAccountsConfig_Links{}, + Links: &atproto.ServerDescribeServer_Links{}, }, nil } @@ -100,7 +95,7 @@ func (s *Server) handleComAtprotoRepoGetRecord(ctx context.Context, c string, co return &atproto.RepoGetRecord_Output{ Cid: &ccstr, Uri: "at://" + s.user.Did + "/" + collection + "/" + rkey, - Value: lexutil.LexiconTypeDecoder{rec}, + Value: &lexutil.LexiconTypeDecoder{rec}, }, nil } diff --git a/lex/gen.go b/lex/gen.go index 8e6fd4971..e0edaa587 100644 --- a/lex/gen.go +++ b/lex/gen.go @@ -29,6 +29,7 @@ type Schema struct { Defs map[string]*TypeSchema `json:"defs"` } +// TODO(bnewbold): suspect this param needs updating for lex refactors type Param struct { Type string `json:"type"` Maximum int `json:"maximum"` @@ -63,6 +64,7 @@ type TypeSchema struct { Ref string `json:"ref"` Refs []string `json:"refs"` Required []string `json:"required"` + Nullable []string `json:"nullable"` Properties map[string]*TypeSchema `json:"properties"` MaxLength int `json:"maxLength"` Items *TypeSchema `json:"items"` @@ -96,7 +98,14 @@ func (s *Schema) AllTypes(prefix string, defMap map[string]*ExtDef) []outputType panic(fmt.Sprintf("nil type schema in %q (%s)", name, s.ID)) } - ts.record = record + if record { + fmt.Println("Setting to record: ", name) + if name == "EmbedImages_View" { + panic("not ok") + } + ts.record = true + } + ts.prefix = prefix ts.id = s.ID ts.defMap = defMap @@ -105,16 +114,16 @@ func (s *Schema) AllTypes(prefix string, defMap map[string]*ExtDef) []outputType out = append(out, outputType{ Name: name, Type: ts, - Record: record, + Record: ts.record, }) } for childname, val := range ts.Properties { - walk(name+"_"+strings.Title(childname), val, record) + walk(name+"_"+strings.Title(childname), val, ts.record) } if ts.Items != nil { - walk(name+"_Elem", ts.Items, record) + walk(name+"_Elem", ts.Items, ts.record) } if ts.Input != nil { @@ -123,7 +132,7 @@ func (s *Schema) AllTypes(prefix string, defMap map[string]*ExtDef) []outputType panic(fmt.Sprintf("strange input type def in %s", s.ID)) } } else { - walk(name+"_Input", ts.Input.Schema, record) + walk(name+"_Input", ts.Input.Schema, ts.record) } } @@ -133,7 +142,7 @@ func (s *Schema) AllTypes(prefix string, defMap map[string]*ExtDef) []outputType panic(fmt.Sprintf("strange output type def in %s", s.ID)) } } else { - walk(name+"_Output", ts.Output.Schema, record) + walk(name+"_Output", ts.Output.Schema, ts.record) } } @@ -224,7 +233,10 @@ func FixRecordReferences(schemas []*Schema, defmap map[string]*ExtDef, prefix st if _, known := defmap[r]; known != true { panic(fmt.Sprintf("reference to unknown record type: %s", r)) } - defmap[r].Type.record = true + + if t.Record { + defmap[r].Type.record = true + } } } } @@ -236,7 +248,6 @@ func GenCodeForSchema(pkg string, prefix string, fname string, reqcode bool, s * s.prefix = prefix for _, d := range s.Defs { - fmt.Println("def id: ", d.id) d.prefix = prefix } @@ -266,7 +277,7 @@ func GenCodeForSchema(pkg string, prefix string, fname string, reqcode bool, s * return tps[i].Name < tps[j].Name }) for _, ot := range tps { - fmt.Println("TYPE: ", ot.Name) + fmt.Println("TYPE: ", ot.Name, ot.Record) if err := ot.Type.WriteType(ot.Name, buf); err != nil { return err } @@ -409,7 +420,7 @@ func (s *TypeSchema) WriteRPC(w io.Writer, typename string) error { params = fmt.Sprintf("%s, input *%s_Input", params, fname) default: - return fmt.Errorf("unsupported input encoding: %q", s.Input.Encoding) + return fmt.Errorf("unsupported input encoding (RPC input): %q", s.Input.Encoding) } } @@ -441,7 +452,7 @@ func (s *TypeSchema) WriteRPC(w io.Writer, typename string) error { out = fmt.Sprintf("(*%s, error)", outname) default: - return fmt.Errorf("unrecognized encoding scheme: %q", s.Output.Encoding) + return fmt.Errorf("unrecognized encoding scheme (RPC output): %q", s.Output.Encoding) } } @@ -467,7 +478,7 @@ func (s *TypeSchema) WriteRPC(w io.Writer, typename string) error { errRet = "nil, err" outRet = "&out, nil" default: - return fmt.Errorf("unrecognized output encoding: %q", s.Output.Encoding) + return fmt.Errorf("unrecognized output encoding (func signature): %q", s.Output.Encoding) } } @@ -574,7 +585,8 @@ func WriteServerHandlers(w io.Writer, schemas []*Schema, pkg string, impmap map[ main, ok := s.Defs["main"] if !ok { - return fmt.Errorf("2 schema %q doesn't have a main def", s.ID) + fmt.Printf("WARNING: schema %q doesn't have a main def\n", s.ID) + continue } if main.Type == "procedure" || main.Type == "query" { @@ -703,12 +715,13 @@ func (s *TypeSchema) WriteHandlerStub(w io.Writer, fname, shortname, impname str case "string": paramtypes = append(paramtypes, k+" string") case "integer": + // TODO(bnewbold) could be handling "nullable" here if required != nil && !required[k] { paramtypes = append(paramtypes, k+" *int") } else { paramtypes = append(paramtypes, k+" int") } - case "number": + case "float": return fmt.Errorf("non-integer numbers currently unsupported") case "array": paramtypes = append(paramtypes, k+"[]"+t.Items.Type) @@ -729,10 +742,10 @@ func (s *TypeSchema) WriteHandlerStub(w io.Writer, fname, shortname, impname str outname = s.typeNameFromRef(s.Output.Schema.Ref) } returndef = fmt.Sprintf("(*%s.%s, error)", impname, outname) - case "application/cbor", "application/vnd.ipld.car": + case "application/cbor", "application/vnd.ipld.car", "*/*": returndef = fmt.Sprintf("(io.Reader, error)") default: - return fmt.Errorf("unrecognized output encoding: %q", s.Output.Encoding) + return fmt.Errorf("unrecognized output encoding (handler stub): %q", s.Output.Encoding) } } @@ -763,6 +776,7 @@ func (s *TypeSchema) WriteRPCHandler(w io.Writer, fname, shortname, impname stri params := []string{"ctx"} if s.Type == "query" { if s.Parameters != nil { + // TODO(bnewbold): could be handling 'nullable' here required := make(map[string]bool) for _, r := range s.Parameters.Required { required[r] = true @@ -818,7 +832,7 @@ if err != nil { `, k, k) } - case "number": + case "float": return fmt.Errorf("non-integer numbers currently unsupported") case "boolean": params = append(params, k) @@ -925,7 +939,7 @@ if err := c.Bind(&body); err != nil { fmt.Fprintf(w, "var out io.Reader\n") returndef = "(io.Reader, error)" default: - return fmt.Errorf("unrecognized output encoding (1): %q", s.Output.Encoding) + return fmt.Errorf("unrecognized output encoding (RPC output handler): %q", s.Output.Encoding) } } fmt.Fprintf(w, "var handleErr error\n") @@ -944,7 +958,7 @@ if err := c.Bind(&body); err != nil { case EncodingCAR: fmt.Fprintf(w, "return c.Stream(200, \"application/vnd.ipld.car\", out)\n}\n\n") default: - return fmt.Errorf("unrecognized output encoding (2): %q", s.Output.Encoding) + return fmt.Errorf("unrecognized output encoding (RPC output handler return): %q", s.Output.Encoding) } } else { fmt.Fprintf(w, "return nil\n}\n\n") @@ -1000,7 +1014,7 @@ func (s *TypeSchema) typeNameForField(name, k string, v TypeSchema) (string, err switch v.Type { case "string": return "string", nil - case "number": + case "float": return "float64", nil case "integer": return "int64", nil @@ -1014,13 +1028,11 @@ func (s *TypeSchema) typeNameForField(name, k string, v TypeSchema) (string, err // TODO: maybe do a native type? return "string", nil case "unknown": - return "util.LexiconTypeDecoder", nil + return "*util.LexiconTypeDecoder", nil case "union": return "*" + name + "_" + strings.Title(k), nil - case "image": - return "*util.Blob", nil case "blob": - return "*util.Blob", nil + return "*util.LexBlob", nil case "array": subt, err := s.typeNameForField(name+"_"+strings.Title(k), "Elem", *v.Items) if err != nil { @@ -1028,8 +1040,12 @@ func (s *TypeSchema) typeNameForField(name, k string, v TypeSchema) (string, err } return "[]" + subt, nil + case "cid-link": + return "util.LexLink", nil + case "bytes": + return "util.LexBytes", nil default: - return "", fmt.Errorf("field %q in %s has unsupported type name", k, name) + return "", fmt.Errorf("field %q in %s has unsupported type name (%s)", k, name, v.Type) } } @@ -1066,7 +1082,7 @@ func (ts *TypeSchema) writeTypeDefinition(name string, w io.Writer) error { case "string": // TODO: deal with max length fmt.Fprintf(w, "type %s string\n", name) - case "number": + case "float": fmt.Fprintf(w, "type %s float64\n", name) case "integer": fmt.Fprintf(w, "type %s int64\n", name) @@ -1085,9 +1101,9 @@ func (ts *TypeSchema) writeTypeDefinition(name string, w io.Writer) error { fmt.Fprintf(w, "type %s struct {\n", name) if ts.record { - fmt.Fprintf(w, "\tLexiconTypeID string `json:\"$type\" cborgen:\"$type,const=%s\"`\n", ts.id) + fmt.Fprintf(w, "\tLexiconTypeID string `json:\"$type,const=%s\" cborgen:\"$type,const=%s\"`\n", ts.id, ts.id) } else { - fmt.Fprintf(w, "\tLexiconTypeID string `json:\"$type,omitempty\"`\n") + fmt.Fprintf(w, "\tLexiconTypeID string `json:\"$type,omitempty\" cborgen:\"$type,omitempty\"`\n") } required := make(map[string]bool) @@ -1095,6 +1111,11 @@ func (ts *TypeSchema) writeTypeDefinition(name string, w io.Writer) error { required[req] = true } + nullable := make(map[string]bool) + for _, req := range ts.Nullable { + nullable[req] = true + } + if err := orderedMapIter[*TypeSchema](ts.Properties, func(k string, v *TypeSchema) error { goname := strings.Title(k) @@ -1111,8 +1132,14 @@ func (ts *TypeSchema) writeTypeDefinition(name string, w io.Writer) error { ptr = "*" } } + if nullable[k] { + omit = "" + if !strings.HasPrefix(tname, "*") && !strings.HasPrefix(tname, "[]") { + ptr = "*" + } + } - fmt.Fprintf(w, "\t%s %s%s `json:\"%s%s\" cborgen:\"%s\"`\n", goname, ptr, tname, k, omit, k) + fmt.Fprintf(w, "\t%s %s%s `json:\"%s%s\" cborgen:\"%s%s\"`\n", goname, ptr, tname, k, omit, k, omit) return nil }); err != nil { return err @@ -1146,7 +1173,7 @@ func (ts *TypeSchema) writeTypeDefinition(name string, w io.Writer) error { func (ts *TypeSchema) writeTypeMethods(name string, w io.Writer) error { switch ts.Type { - case "string", "number", "array", "boolean", "integer": + case "string", "float", "array", "boolean", "integer": return nil case "object": if err := ts.writeJsonMarshalerObject(name, w); err != nil { diff --git a/lex/util/cbor_gen.go b/lex/util/cbor_gen.go index fcfc0d570..c8235649b 100644 --- a/lex/util/cbor_gen.go +++ b/lex/util/cbor_gen.go @@ -113,7 +113,7 @@ func (t *CborChecker) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *Blob) MarshalCBOR(w io.Writer) error { +func (t *LegacyBlob) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err @@ -173,8 +173,8 @@ func (t *Blob) MarshalCBOR(w io.Writer) error { return nil } -func (t *Blob) UnmarshalCBOR(r io.Reader) (err error) { - *t = Blob{} +func (t *LegacyBlob) UnmarshalCBOR(r io.Reader) (err error) { + *t = LegacyBlob{} cr := cbg.NewCborReader(r) @@ -193,7 +193,7 @@ func (t *Blob) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("Blob: map struct too large (%d)", extra) + return fmt.Errorf("LegacyBlob: map struct too large (%d)", extra) } var name string @@ -242,3 +242,206 @@ func (t *Blob) UnmarshalCBOR(r io.Reader) (err error) { return nil } +func (t *BlobSchema) 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.Ref (util.LexLink) (struct) + if len("ref") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"ref\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ref"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("ref")); err != nil { + return err + } + + if err := t.Ref.MarshalCBOR(cw); err != nil { + return err + } + + // t.Size (int64) (int64) + if len("size") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"size\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("size"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("size")); err != nil { + return err + } + + if t.Size >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Size)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Size-1)); err != nil { + return err + } + } + + // t.LexiconTypeID (string) (string) + if len("$type") > cbg.MaxLength { + 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 := io.WriteString(w, string("$type")); err != nil { + return err + } + + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { + return err + } + + // t.MimeType (string) (string) + if len("mimeType") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"mimeType\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mimeType"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("mimeType")); err != nil { + return err + } + + if len(t.MimeType) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.MimeType was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MimeType))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.MimeType)); err != nil { + return err + } + return nil +} + +func (t *BlobSchema) UnmarshalCBOR(r io.Reader) (err error) { + *t = BlobSchema{} + + 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("BlobSchema: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.Ref (util.LexLink) (struct) + case "ref": + + { + + if err := t.Ref.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Ref: %w", err) + } + + } + // t.Size (int64) (int64) + case "size": + { + maj, extra, err := cr.ReadHeader() + var extraI int64 + if err != nil { + return err + } + 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.Size = int64(extraI) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.MimeType (string) (string) + case "mimeType": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.MimeType = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} diff --git a/lex/util/cbor_gen_test.go b/lex/util/cbor_gen_test.go new file mode 100644 index 000000000..43d4abe9d --- /dev/null +++ b/lex/util/cbor_gen_test.go @@ -0,0 +1,768 @@ +// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. + +package util + +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 *basicSchema) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 7 + + if t.D == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.A (string) (string) + if len("a") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"a\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("a"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("a")); err != nil { + return err + } + + if len(t.A) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.A was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.A))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.A)); err != nil { + return err + } + + // t.B (int64) (int64) + if len("b") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"b\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("b"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("b")); err != nil { + return err + } + + if t.B >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.B)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.B-1)); err != nil { + return err + } + } + + // t.C (bool) (bool) + if len("c") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"c\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("c"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("c")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.C); err != nil { + return err + } + + // t.D (string) (string) + if t.D != nil { + + if len("d") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"d\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("d"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("d")); err != nil { + return err + } + + if t.D == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.D) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.D was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.D))); err != nil { + return err + } + if _, err := io.WriteString(w, string(*t.D)); err != nil { + return err + } + } + } + + // t.E (string) (string) + if len("e") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"e\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("e"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("e")); err != nil { + return err + } + + if t.E == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.E) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.E was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.E))); err != nil { + return err + } + if _, err := io.WriteString(w, string(*t.E)); err != nil { + return err + } + } + + // t.F ([]string) (slice) + if len("f") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"f\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("f"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("f")); err != nil { + return err + } + + if len(t.F) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.F was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.F))); err != nil { + return err + } + for _, v := range t.F { + if len(v) > cbg.MaxLength { + return xerrors.Errorf("Value in field v was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { + return err + } + if _, err := io.WriteString(w, string(v)); err != nil { + return err + } + } + + // t.G (util.basicSchemaInner) (struct) + if len("g") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"g\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("g"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("g")); err != nil { + return err + } + + if err := t.G.MarshalCBOR(cw); err != nil { + return err + } + return nil +} + +func (t *basicSchema) UnmarshalCBOR(r io.Reader) (err error) { + *t = basicSchema{} + + 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("basicSchema: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.A (string) (string) + case "a": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.A = string(sval) + } + // t.B (int64) (int64) + case "b": + { + maj, extra, err := cr.ReadHeader() + var extraI int64 + if err != nil { + return err + } + 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.B = int64(extraI) + } + // t.C (bool) (bool) + case "c": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.C = false + case 21: + t.C = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + // t.D (string) (string) + case "d": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.D = (*string)(&sval) + } + } + // t.E (string) (string) + case "e": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.E = (*string)(&sval) + } + } + // t.F ([]string) (slice) + case "f": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.F: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.F = make([]string, extra) + } + + for i := 0; i < int(extra); i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.F[i] = string(sval) + } + } + + // t.G (util.basicSchemaInner) (struct) + case "g": + + { + + if err := t.G.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.G: %w", err) + } + + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *basicSchemaInner) 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.H (string) (string) + if len("h") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"h\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("h"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("h")); err != nil { + return err + } + + if len(t.H) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.H was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.H))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.H)); err != nil { + return err + } + + // t.I (int64) (int64) + if len("i") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"i\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("i"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("i")); err != nil { + return err + } + + if t.I >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.I)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.I-1)); err != nil { + return err + } + } + + // t.J (bool) (bool) + if len("j") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"j\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("j"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("j")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.J); err != nil { + return err + } + + // t.K ([]string) (slice) + if len("k") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"k\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("k"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("k")); err != nil { + return err + } + + if len(t.K) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.K was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.K))); err != nil { + return err + } + for _, v := range t.K { + if len(v) > cbg.MaxLength { + return xerrors.Errorf("Value in field v was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { + return err + } + if _, err := io.WriteString(w, string(v)); err != nil { + return err + } + } + return nil +} + +func (t *basicSchemaInner) UnmarshalCBOR(r io.Reader) (err error) { + *t = basicSchemaInner{} + + 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("basicSchemaInner: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.H (string) (string) + case "h": + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.H = string(sval) + } + // t.I (int64) (int64) + case "i": + { + maj, extra, err := cr.ReadHeader() + var extraI int64 + if err != nil { + return err + } + 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.I = int64(extraI) + } + // t.J (bool) (bool) + case "j": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.J = false + case 21: + t.J = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + // t.K ([]string) (slice) + case "k": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.K: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.K = make([]string, extra) + } + + for i := 0; i < int(extra); i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + t.K[i] = string(sval) + } + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} +func (t *ipldSchema) 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.A (util.LexLink) (struct) + if len("a") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"a\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("a"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("a")); err != nil { + return err + } + + if err := t.A.MarshalCBOR(cw); err != nil { + return err + } + + // t.B (util.LexBytes) (slice) + if len("b") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"b\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("b"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("b")); err != nil { + return err + } + + if len(t.B) > cbg.ByteArrayMaxLen { + return xerrors.Errorf("Byte array in field t.B was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.B))); err != nil { + return err + } + + if _, err := cw.Write(t.B[:]); err != nil { + return err + } + return nil +} + +func (t *ipldSchema) UnmarshalCBOR(r io.Reader) (err error) { + *t = ipldSchema{} + + 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("ipldSchema: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadString(cr) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.A (util.LexLink) (struct) + case "a": + + { + + if err := t.A.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.A: %w", err) + } + + } + // t.B (util.LexBytes) (slice) + case "b": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > cbg.ByteArrayMaxLen { + return fmt.Errorf("t.B: byte array too large (%d)", extra) + } + if maj != cbg.MajByteString { + return fmt.Errorf("expected byte array") + } + + if extra > 0 { + t.B = make([]uint8, extra) + } + + if _, err := io.ReadFull(cr, t.B[:]); err != nil { + return err + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } + } + + return nil +} diff --git a/lex/util/decoder.go b/lex/util/decoder.go index 8b1c4b3e2..6f15263c6 100644 --- a/lex/util/decoder.go +++ b/lex/util/decoder.go @@ -14,6 +14,7 @@ var lexTypesMap map[string]reflect.Type func init() { lexTypesMap = make(map[string]reflect.Type) + RegisterType("blob", &LexBlob{}) } func RegisterType(id string, val cbg.CBORMarshaler) { diff --git a/lex/util/lex_test.go b/lex/util/lex_test.go new file mode 100644 index 000000000..3d7811ee1 --- /dev/null +++ b/lex/util/lex_test.go @@ -0,0 +1,288 @@ +package util + +import ( + "bytes" + "encoding/json" + "testing" + + "github.com/ipfs/go-cid" + "github.com/stretchr/testify/assert" + cbg "github.com/whyrusleeping/cbor-gen" +) + +type basicSchema struct { + A string `json:"a" cborgen:"a"` + B int64 `json:"b" cborgen:"b"` + C bool `json:"c" cborgen:"c"` + D *string `json:"d,omitempty" cborgen:"d,omitempty"` + E *string `json:"e" cborgen:"e"` + F []string `json:"f" cborgen:"f"` + G basicSchemaInner `json:"g" cborgen:"g"` +} + +type basicSchemaInner struct { + H string `json:"h" cborgen:"h"` + I int64 `json:"i" cborgen:"i"` + J bool `json:"j" cborgen:"j"` + K []string `json:"k" cborgen:"k"` +} + +type ipldSchema struct { + A LexLink `json:"a" cborgen:"a"` + B LexBytes `json:"b" cborgen:"b"` +} + +type ipldNestedSchema struct { + A ipldNestedSchemaInner `json:"a" cborgen:"a"` +} + +type ipldNestedSchemaInner struct { + B []ipldNestedSchemaInnerInner `json:"b" cborgen:"b"` +} + +type ipldNestedSchemaInnerInner struct { + C *string `json:"c,omitempty" cborgen:"c,omitempty"` + D []LexLink `json:"d" cborgen:"d"` + E []LexBytes `json:"e" cborgen:"e"` +} + +func TestCborGen(t *testing.T) { + if err := cbg.WriteMapEncodersToFile("cbor_gen_test.go", "util", basicSchema{}, basicSchemaInner{}, ipldSchema{}); err != nil { + t.Fatal(err) + } +} + +func TestInteropBasicSchema(t *testing.T) { + assert := assert.New(t) + jsonStr := `{ + "a": "abc", + "b": 123, + "c": true, + "e": null, + "f": ["abc", "def", "ghi"], + "g": { + "h": "abc", + "i": 123, + "j": true, + "k": ["abc", "def", "ghi"] + } + }` + goObj := basicSchema{ + A: "abc", + B: 123, + C: true, + D: nil, + E: nil, + F: []string{"abc", "def", "ghi"}, + G: basicSchemaInner{ + H: "abc", + I: 123, + J: true, + K: []string{"abc", "def", "ghi"}, + }, + } + cborBytes := []byte{166, 97, 97, 99, 97, 98, 99, 97, 98, 24, 123, 97, 99, 245, 97, 101, 246, + 97, 102, 131, 99, 97, 98, 99, 99, 100, 101, 102, 99, 103, 104, 105, 97, + 103, 164, 97, 104, 99, 97, 98, 99, 97, 105, 24, 123, 97, 106, 245, 97, + 107, 131, 99, 97, 98, 99, 99, 100, 101, 102, 99, 103, 104, 105} + cidStr := "bafyreiaioukcatdbdltzqznmyqmwgpgmoex62tkwqtdmganxgv3v5bn2o4" + + // easier commenting out of code during development + _ = assert + _ = jsonStr + _ = goObj + _ = cidStr + _ = bytes.NewReader(cborBytes) + + // basic parsing + jsonObj := basicSchema{} + assert.NoError(json.Unmarshal([]byte(jsonStr), &jsonObj)) + cborObj := basicSchema{} + assert.NoError(cborObj.UnmarshalCBOR(bytes.NewReader(cborBytes))) + + // compare parsed against known object + assert.Equal(goObj, jsonObj) + assert.Equal(goObj, cborObj) + + // reproduce CBOR serialization + goCborBytes := new(bytes.Buffer) + assert.NoError(goObj.MarshalCBOR(goCborBytes)) + assert.Equal(cborBytes, goCborBytes.Bytes()) + // 0x71 = dag-cbor, 0x12 = sha2-256, 0 = default length + cidBuilder := cid.V1Builder{0x71, 0x12, 0} + goCborCid, err := cidBuilder.Sum(goCborBytes.Bytes()) + assert.NoError(err) + assert.Equal(cidStr, goCborCid.String()) + + // reproduce JSON serialization + var jsonAll interface{} + assert.NoError(json.Unmarshal([]byte(jsonStr), &jsonAll)) + goJsonBytes, err := json.Marshal(goObj) + assert.NoError(err) + var goJsonAll interface{} + assert.NoError(json.Unmarshal(goJsonBytes, &goJsonAll)) + assert.Equal(jsonAll, goJsonAll) +} + +func TestInteropIpldSchema(t *testing.T) { + assert := assert.New(t) + + jsonStr := `{ + "a": { + "$link": "bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a" + }, + "b": { + "$bytes": "nFERjvLLiw9qm45JrqH9QTzyC2Lu1Xb4ne6+sBrCzI0" + } + }` + cidOne, err := cid.Decode("bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a") + assert.NoError(err) + goObj := ipldSchema{ + A: LexLink(cidOne), + B: LexBytes([]byte{ + 156, 81, 17, 142, 242, 203, 139, 15, 106, 155, 142, 73, 174, 161, 253, + 65, 60, 242, 11, 98, 238, 213, 118, 248, 157, 238, 190, 176, 26, 194, + 204, 141, + }), + } + cborBytes := []byte{162, 97, 97, 216, 42, 88, 37, 0, 1, 113, 18, 32, 101, 6, 42, 90, 90, 0, + 252, 22, 215, 60, 105, 68, 35, 124, 203, 193, 91, 28, 74, 114, 52, 72, + 147, 54, 137, 29, 9, 23, 65, 162, 57, 208, 97, 98, 88, 32, 156, 81, 17, + 142, 242, 203, 139, 15, 106, 155, 142, 73, 174, 161, 253, 65, 60, 242, 11, + 98, 238, 213, 118, 248, 157, 238, 190, 176, 26, 194, 204, 141} + cidStr := "bafyreif37nlcsyb4ckm2i7y3w2ctnebzkib7ekzmv3tvl3mo5og2gxot5y" + + // easier commenting out of code during development + _ = assert + _ = jsonStr + _ = goObj + _ = cidStr + _ = bytes.NewReader(cborBytes) + + // basic parsing + jsonObj := ipldSchema{} + assert.NoError(json.Unmarshal([]byte(jsonStr), &jsonObj)) + cborObj := ipldSchema{} + assert.NoError(cborObj.UnmarshalCBOR(bytes.NewReader(cborBytes))) + + // compare parsed against known object + assert.Equal(goObj, jsonObj) + assert.Equal(goObj, cborObj) + + // reproduce CBOR serialization + goCborBytes := new(bytes.Buffer) + assert.NoError(goObj.MarshalCBOR(goCborBytes)) + assert.Equal(cborBytes, goCborBytes.Bytes()) + // 0x71 = dag-cbor, 0x12 = sha2-256, 0 = default length + cidBuilder := cid.V1Builder{0x71, 0x12, 0} + goCborCid, err := cidBuilder.Sum(goCborBytes.Bytes()) + assert.NoError(err) + assert.Equal(cidStr, goCborCid.String()) + + // reproduce JSON serialization + var jsonAll interface{} + assert.NoError(json.Unmarshal([]byte(jsonStr), &jsonAll)) + goJsonBytes, err := json.Marshal(goObj) + assert.NoError(err) + var goJsonAll interface{} + assert.NoError(json.Unmarshal(goJsonBytes, &goJsonAll)) + assert.Equal(jsonAll, goJsonAll) +} + +func TestInteropIpldNestedSchema(t *testing.T) { + assert := assert.New(t) + + jsonStr := `{ + "a": { + "b": [ + { + "d": [ + {"$link": "bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a"}, + {"$link": "bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a"} + ], + "e": [ + { "$bytes": "nFERjvLLiw9qm45JrqH9QTzyC2Lu1Xb4ne6+sBrCzI0" }, + { "$bytes": "iE+sPoHobU9tSIqGI+309LLCcWQIRmEXwxcoDt19tas" } + ] + } + ] + } + }` + cidOne, err := cid.Decode("bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a") + assert.NoError(err) + cidTwo, err := cid.Decode("bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a") + assert.NoError(err) + goObj := ipldNestedSchema{ + A: ipldNestedSchemaInner{ + B: []ipldNestedSchemaInnerInner{ + ipldNestedSchemaInnerInner{ + D: []LexLink{ + LexLink(cidOne), + LexLink(cidTwo), + }, + E: []LexBytes{ + LexBytes([]byte{ + 156, 81, 17, 142, 242, 203, 139, 15, 106, 155, 142, 73, 174, + 161, 253, 65, 60, 242, 11, 98, 238, 213, 118, 248, 157, 238, + 190, 176, 26, 194, 204, 141, + }), + LexBytes([]byte{ + 136, 79, 172, 62, 129, 232, 109, 79, 109, 72, 138, 134, 35, 237, + 244, 244, 178, 194, 113, 100, 8, 70, 97, 23, 195, 23, 40, 14, + 221, 125, 181, 171, + }), + }, + }, + }, + }, + } + cborBytes := []byte{161, 97, 97, 161, 97, 98, 129, 162, 97, 100, 130, 216, 42, 88, 37, 0, 1, + 113, 18, 32, 101, 6, 42, 90, 90, 0, 252, 22, 215, 60, 105, 68, 35, 124, + 203, 193, 91, 28, 74, 114, 52, 72, 147, 54, 137, 29, 9, 23, 65, 162, 57, + 208, 216, 42, 88, 37, 0, 1, 113, 18, 32, 101, 6, 42, 90, 90, 0, 252, 22, + 215, 60, 105, 68, 35, 124, 203, 193, 91, 28, 74, 114, 52, 72, 147, 54, + 137, 29, 9, 23, 65, 162, 57, 208, 97, 101, 130, 88, 32, 156, 81, 17, 142, + 242, 203, 139, 15, 106, 155, 142, 73, 174, 161, 253, 65, 60, 242, 11, 98, + 238, 213, 118, 248, 157, 238, 190, 176, 26, 194, 204, 141, 88, 32, 136, + 79, 172, 62, 129, 232, 109, 79, 109, 72, 138, 134, 35, 237, 244, 244, 178, + 194, 113, 100, 8, 70, 97, 23, 195, 23, 40, 14, 221, 125, 181, 171} + cidStr := "bafyreid3imdulnhgeytpf6uk7zahjvrsqlofkmm5b5ub2maw4kqus6jp4i" + + // easier commenting out of code during development + _ = assert + _ = jsonStr + _ = goObj + _ = cidStr + _ = bytes.NewReader(cborBytes) + + // basic parsing + jsonObj := ipldNestedSchema{} + assert.NoError(json.Unmarshal([]byte(jsonStr), &jsonObj)) + + // compare parsed against known object + assert.Equal(goObj, jsonObj) + + // reproduce JSON serialization + var jsonAll interface{} + assert.NoError(json.Unmarshal([]byte(jsonStr), &jsonAll)) + goJsonBytes, err := json.Marshal(goObj) + assert.NoError(err) + var goJsonAll interface{} + assert.NoError(json.Unmarshal(goJsonBytes, &goJsonAll)) + assert.Equal(jsonAll, goJsonAll) + + // TODO: CBOR codegen and validation with array-of-byte-arrays + /* + cborObj := ipldNestedSchema{} + assert.NoError(cborObj.UnmarshalCBOR(bytes.NewReader(cborBytes))) + assert.Equal(goObj, cborObj) + goCborBytes := new(bytes.Buffer) + assert.NoError(goObj.MarshalCBOR(goCborBytes)) + assert.Equal(cborBytes, goCborBytes.Bytes()) + // 0x71 = dag-cbor, 0x12 = sha2-256, 0 = default length + cidBuilder := cid.V1Builder{ 0x71, 0x12, 0 } + goCborCid, err := cidBuilder.Sum(goCborBytes.Bytes()) + assert.NoError(err) + assert.Equal(cidStr, goCborCid.String()) + */ +} diff --git a/lex/util/lex_types.go b/lex/util/lex_types.go new file mode 100644 index 000000000..3dc513f1a --- /dev/null +++ b/lex/util/lex_types.go @@ -0,0 +1,273 @@ +package util + +import ( + "bytes" + "encoding/base64" + "encoding/json" + "fmt" + "io" + + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + xerrors "golang.org/x/xerrors" +) + +const ( + // TODO: this is an arbitrary size. lexicons can set more realistic limits, + // and we should pass those limits through and only fall back to this when + // undefined. + MAX_BYTE_ARRAY_SIZE = 128 * 1024 * 1024 +) + +type LexLink cid.Cid + +type jsonLink struct { + Link string `json:"$link"` +} + +// convenience helper +func (ll LexLink) String() string { + return cid.Cid(ll).String() +} + +// convenience helper +func (ll LexLink) Defined() bool { + return cid.Cid(ll).Defined() +} + +func (ll LexLink) MarshalJSON() ([]byte, error) { + if !ll.Defined() { + return nil, xerrors.Errorf("tried to marshal nil or undefined cid-link") + } + jl := jsonLink{ + Link: ll.String(), + } + return json.Marshal(jl) +} + +func (ll *LexLink) UnmarshalJSON(raw []byte) error { + var jl jsonLink + if err := json.Unmarshal(raw, &jl); err != nil { + return xerrors.Errorf("parsing cid-link JSON: %v", err) + } + + c, err := cid.Decode(jl.Link) + if err != nil { + return xerrors.Errorf("parsing cid-link CID: %v", err) + } + *ll = LexLink(c) + return nil +} + +func (ll *LexLink) MarshalCBOR(w io.Writer) error { + if ll == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if !ll.Defined() { + return xerrors.Errorf("tried to marshal nil or undefined cid-link") + } + cw := cbg.NewCborWriter(w) + if err := cbg.WriteCid(cw, cid.Cid(*ll)); err != nil { + return xerrors.Errorf("failed to write cid-link as CBOR: %w", err) + } + return nil +} + +func (ll *LexLink) UnmarshalCBOR(r io.Reader) error { + cr := cbg.NewCborReader(r) + c, err := cbg.ReadCid(cr) + if err != nil { + return xerrors.Errorf("failed to read cid-link from CBOR: %w", err) + } + *ll = LexLink(c) + return nil +} + +type LexBytes []byte + +type JsonBytes struct { + Bytes string `json:"$bytes"` +} + +func (lb LexBytes) MarshalJSON() ([]byte, error) { + if lb == nil { + return nil, xerrors.Errorf("tried to marshal nil $bytes") + } + jb := JsonBytes{ + Bytes: base64.RawStdEncoding.EncodeToString([]byte(lb)), + } + return json.Marshal(jb) +} + +func (lb *LexBytes) UnmarshalJSON(raw []byte) error { + var jb JsonBytes + err := json.Unmarshal(raw, &jb) + if err != nil { + return xerrors.Errorf("parsing $bytes JSON: %v", err) + } + out, err := base64.RawStdEncoding.DecodeString(jb.Bytes) + if err != nil { + return xerrors.Errorf("parsing $bytes base64: %v", err) + } + *lb = LexBytes(out) + return nil +} + +func (lb *LexBytes) MarshalCBOR(w io.Writer) error { + if lb == nil { + _, err := w.Write(cbg.CborNull) + return err + } + cw := cbg.NewCborWriter(w) + if err := cbg.WriteByteArray(cw, ([]byte)(*lb)); err != nil { + return xerrors.Errorf("failed to write $bytes as CBOR: %w", err) + } + return nil +} + +func (lb *LexBytes) UnmarshalCBOR(r io.Reader) error { + cr := cbg.NewCborReader(r) + b, err := cbg.ReadByteArray(cr, MAX_BYTE_ARRAY_SIZE) + if err != nil { + return xerrors.Errorf("failed to read $bytes from CBOR: %w", err) + } + *lb = LexBytes(b) + return nil +} + +// used in schemas, and can represent either a legacy blob or a "new" (lex +// refactor) blob. size=-1 indicates that this is (and should be serialized as) +// a legacy blob (string CID, no size, etc). +type LexBlob struct { + Ref LexLink `json:"ref" cborgen:"ref"` + MimeType string `json:"mimeType" cborgen:"mimeType"` + Size int64 `json:"size" cborgen:"size"` +} + +type LegacyBlob struct { + Cid string `json:"cid" cborgen:"cid"` + MimeType string `json:"mimeType" cborgen:"mimeType"` +} + +type BlobSchema struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type"` + Ref LexLink `json:"ref" cborgen:"ref"` + MimeType string `json:"mimeType" cborgen:"mimeType"` + Size int64 `json:"size" cborgen:"size"` +} + +func (b *LexBlob) MarshalJSON() ([]byte, error) { + if b.Size < 0 { + lb := LegacyBlob{ + Cid: b.Ref.String(), + MimeType: b.MimeType, + } + return json.Marshal(lb) + } else { + nb := BlobSchema{ + LexiconTypeID: "blob", + Ref: b.Ref, + MimeType: b.MimeType, + Size: b.Size, + } + return json.Marshal(nb) + } +} + +func (b *LexBlob) UnmarshalJSON(raw []byte) error { + typ, err := TypeExtract(raw) + if err != nil { + return xerrors.Errorf("parsing blob type: %v", err) + } + + if typ == "blob" { + var bs BlobSchema + err := json.Unmarshal(raw, &bs) + if err != nil { + return xerrors.Errorf("parsing blob JSON: %v", err) + } + b.Ref = bs.Ref + b.MimeType = bs.MimeType + b.Size = bs.Size + if bs.Size < 0 { + return xerrors.Errorf("parsing blob: negative size: %d", bs.Size) + } + } else { + var legacy *LegacyBlob + err := json.Unmarshal(raw, legacy) + if err != nil { + return xerrors.Errorf("parsing legacy blob: %v", err) + } + refCid, err := cid.Decode(legacy.Cid) + if err != nil { + return xerrors.Errorf("parsing CID in legacy blob: %v", err) + } + b.Ref = LexLink(refCid) + b.MimeType = legacy.MimeType + b.Size = -1 + } + return nil +} + +func (b *LexBlob) MarshalCBOR(w io.Writer) error { + if b == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if b.Size < 0 { + lb := LegacyBlob{ + Cid: b.Ref.String(), + MimeType: b.MimeType, + } + return lb.MarshalCBOR(w) + } else { + fmt.Println("MARSHAL BLOB: ", b.Ref, b.MimeType, b.Size) + bs := BlobSchema{ + LexiconTypeID: "blob", + Ref: b.Ref, + MimeType: b.MimeType, + Size: b.Size, + } + return bs.MarshalCBOR(w) + } +} + +func (lb *LexBlob) UnmarshalCBOR(r io.Reader) error { + typ, b, err := CborTypeExtractReader(r) + if err != nil { + return xerrors.Errorf("parsing $blob CBOR type: %w", err) + } + + fmt.Println("LEX BLOB TYPE: ", typ) + *lb = LexBlob{} + if typ == "blob" { + var bs BlobSchema + err := bs.UnmarshalCBOR(bytes.NewReader(b)) + if err != nil { + return xerrors.Errorf("parsing $blob CBOR: %v", err) + } + fmt.Println("BLOB SCHEMA: ", bs.Ref) + lb.Ref = bs.Ref + lb.MimeType = bs.MimeType + lb.Size = bs.Size + if bs.Size < 0 { + return xerrors.Errorf("parsing $blob CBOR: negative size: %d", bs.Size) + } + } else { + legacy := LegacyBlob{} + err := legacy.UnmarshalCBOR(bytes.NewReader(b)) + if err != nil { + return xerrors.Errorf("parsing legacy blob CBOR: %v", err) + } + refCid, err := cid.Decode(legacy.Cid) + if err != nil { + return xerrors.Errorf("parsing CID in legacy blob CBOR: %v", err) + } + lb.Ref = LexLink(refCid) + lb.MimeType = legacy.MimeType + lb.Size = -1 + } + + return nil +} diff --git a/lex/util/util.go b/lex/util/util.go index d8298f3ce..b7396f38b 100644 --- a/lex/util/util.go +++ b/lex/util/util.go @@ -20,11 +20,6 @@ func TypeExtract(b []byte) (string, error) { return te.Type, nil } -type Blob struct { - Cid string `json:"cid" cborgen:"cid"` - MimeType string `json:"mimeType" cborgen:"mimeType"` -} - type CborChecker struct { Type string `json:"$type" cborgen:"$type"` } diff --git a/models/models.go b/models/models.go index cd932c656..f7a006bce 100644 --- a/models/models.go +++ b/models/models.go @@ -43,18 +43,22 @@ type ActorInfo struct { Following int64 Followers int64 Posts int64 - DeclRefCid string Type string PDS uint } -func (ai *ActorInfo) ActorRef() *bsky.ActorRef_WithInfo { - return &bsky.ActorRef_WithInfo{ - Did: ai.Did, - Declaration: &bsky.SystemDeclRef{ - Cid: ai.DeclRefCid, - ActorType: ai.Type, - }, +func (ai *ActorInfo) ActorRef() *bsky.ActorDefs_ProfileViewBasic { + return &bsky.ActorDefs_ProfileViewBasic{ + Did: ai.Did, + Handle: ai.Handle, + DisplayName: &ai.DisplayName, + } +} + +// TODO: this is just s stub; needs to populate more info +func (ai *ActorInfo) ActorView() *bsky.ActorDefs_ProfileView { + return &bsky.ActorDefs_ProfileView{ + Did: ai.Did, Handle: ai.Handle, DisplayName: &ai.DisplayName, } diff --git a/notifs/notifs.go b/notifs/notifs.go index 5912eaf07..b613d8095 100644 --- a/notifs/notifs.go +++ b/notifs/notifs.go @@ -16,7 +16,7 @@ import ( ) type NotificationManager interface { - GetNotifications(ctx context.Context, user bsutil.Uid) ([]*appbskytypes.NotificationList_Notification, error) + GetNotifications(ctx context.Context, user bsutil.Uid) ([]*appbskytypes.NotificationListNotifications_Notification, error) GetCount(ctx context.Context, user bsutil.Uid) (int64, error) UpdateSeen(ctx context.Context, usr bsutil.Uid, seen time.Time) error AddReplyTo(ctx context.Context, user bsutil.Uid, replyid uint, replyto *models.FeedPost) error @@ -36,6 +36,7 @@ type DBNotifMan struct { type GetRecord func(ctx context.Context, user bsutil.Uid, collection string, rkey string, maybeCid cid.Cid) (cid.Cid, cbg.CBORMarshaler, error) func NewNotificationManager(db *gorm.DB, getrec GetRecord) *DBNotifMan { + db.AutoMigrate(&NotifRecord{}) db.AutoMigrate(&NotifSeen{}) @@ -74,12 +75,12 @@ type HydratedNotification struct { IndexedAt time.Time Uri string Cid string - Author *appbskytypes.ActorRef_WithInfo + Author *appbskytypes.ActorDefs_ProfileViewBasic Reason string ReasonSubject *string } -func (nm *DBNotifMan) GetNotifications(ctx context.Context, user bsutil.Uid) ([]*appbskytypes.NotificationList_Notification, error) { +func (nm *DBNotifMan) GetNotifications(ctx context.Context, user bsutil.Uid) ([]*appbskytypes.NotificationListNotifications_Notification, error) { var lastSeen time.Time if err := nm.db.Model(NotifSeen{}).Where("usr = ?", user).Select("last_seen").Scan(&lastSeen).Error; err != nil { return nil, err @@ -101,7 +102,7 @@ func (nm *DBNotifMan) GetNotifications(ctx context.Context, user bsutil.Uid) ([] ReasonSubject *string `json:"reasonSubject" cborgen:"reasonSubject"` */ - out := []*appbskytypes.NotificationList_Notification{} + out := []*appbskytypes.NotificationListNotifications_Notification{} for _, n := range notifs { hn, err := nm.hydrateNotification(ctx, &n, lastSeen) @@ -110,14 +111,14 @@ func (nm *DBNotifMan) GetNotifications(ctx context.Context, user bsutil.Uid) ([] } // TODO: muting - hn.Author.Viewer = &appbskytypes.ActorRef_ViewerState{} + hn.Author.Viewer = &appbskytypes.ActorDefs_ViewerState{} out = append(out, hn) } return out, nil } -func (nm *DBNotifMan) hydrateNotification(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationList_Notification, error) { +func (nm *DBNotifMan) hydrateNotification(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationListNotifications_Notification, error) { switch nrec.Kind { case NotifKindReply: @@ -145,7 +146,7 @@ func (nm *DBNotifMan) getActor(ctx context.Context, act bsutil.Uid) (*models.Act return &ai, nil } -func (nm *DBNotifMan) hydrateNotificationUpVote(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationList_Notification, error) { +func (nm *DBNotifMan) hydrateNotificationUpVote(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationListNotifications_Notification, error) { var votedOn models.FeedPost if err := nm.db.First(&votedOn, "id = ?", nrec.Record).Error; err != nil { return nil, err @@ -173,19 +174,19 @@ func (nm *DBNotifMan) hydrateNotificationUpVote(ctx context.Context, nrec *Notif rsub := "at://" + postAuthor.Did + "/app.bsky.feed.post/" + votedOn.Rkey - return &appbskytypes.NotificationList_Notification{ - Record: lexutil.LexiconTypeDecoder{Val: rec}, + return &appbskytypes.NotificationListNotifications_Notification{ + Record: &lexutil.LexiconTypeDecoder{Val: rec}, IsRead: nrec.CreatedAt.Before(lastSeen), IndexedAt: nrec.CreatedAt.Format(time.RFC3339), Uri: "at://" + voter.Did + "/app.bsky.feed.vote/" + vote.Rkey, Cid: vote.Cid, - Author: voter.ActorRef(), + Author: voter.ActorView(), Reason: "vote", ReasonSubject: &rsub, }, nil } -func (nm *DBNotifMan) hydrateNotificationRepost(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationList_Notification, error) { +func (nm *DBNotifMan) hydrateNotificationRepost(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationListNotifications_Notification, error) { var reposted models.FeedPost if err := nm.db.First(&reposted, "id = ?", nrec.Record).Error; err != nil { return nil, err @@ -213,19 +214,19 @@ func (nm *DBNotifMan) hydrateNotificationRepost(ctx context.Context, nrec *Notif rsub := "at://" + postAuthor.Did + "/app.bsky.feed.post/" + reposted.Rkey - return &appbskytypes.NotificationList_Notification{ - Record: lexutil.LexiconTypeDecoder{rec}, + return &appbskytypes.NotificationListNotifications_Notification{ + Record: &lexutil.LexiconTypeDecoder{rec}, IsRead: nrec.CreatedAt.Before(lastSeen), IndexedAt: nrec.CreatedAt.Format(time.RFC3339), Uri: "at://" + reposter.Did + "/app.bsky.feed.repost/" + repost.Rkey, Cid: repost.RecCid, - Author: reposter.ActorRef(), + Author: reposter.ActorView(), Reason: "repost", ReasonSubject: &rsub, }, nil } -func (nm *DBNotifMan) hydrateNotificationReply(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationList_Notification, error) { +func (nm *DBNotifMan) hydrateNotificationReply(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationListNotifications_Notification, error) { var fp models.FeedPost if err := nm.db.First(&fp, "id = ?", nrec.Record).Error; err != nil { return nil, err @@ -253,19 +254,19 @@ func (nm *DBNotifMan) hydrateNotificationReply(ctx context.Context, nrec *NotifR rsub := "at://" + opAuthor.Did + "/app.bsky.feed.post/" + replyTo.Rkey - return &appbskytypes.NotificationList_Notification{ - Record: lexutil.LexiconTypeDecoder{rec}, + return &appbskytypes.NotificationListNotifications_Notification{ + Record: &lexutil.LexiconTypeDecoder{rec}, IsRead: nrec.CreatedAt.Before(lastSeen), IndexedAt: nrec.CreatedAt.Format(time.RFC3339), Uri: "at://" + author.Did + "/app.bsky.feed.post/" + fp.Rkey, Cid: fp.Cid, - Author: author.ActorRef(), + Author: author.ActorView(), Reason: "reply", ReasonSubject: &rsub, }, nil } -func (nm *DBNotifMan) hydrateNotificationFollow(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationList_Notification, error) { +func (nm *DBNotifMan) hydrateNotificationFollow(ctx context.Context, nrec *NotifRecord, lastSeen time.Time) (*appbskytypes.NotificationListNotifications_Notification, error) { var frec models.FollowRecord if err := nm.db.First(&frec, "id = ?", nrec.Record).Error; err != nil { return nil, err @@ -281,13 +282,13 @@ func (nm *DBNotifMan) hydrateNotificationFollow(ctx context.Context, nrec *Notif return nil, err } - return &appbskytypes.NotificationList_Notification{ - Record: lexutil.LexiconTypeDecoder{rec}, + return &appbskytypes.NotificationListNotifications_Notification{ + Record: &lexutil.LexiconTypeDecoder{rec}, IsRead: nrec.CreatedAt.Before(lastSeen), IndexedAt: nrec.CreatedAt.Format(time.RFC3339), Uri: "at://" + follower.Did + "/app.bsky.graph.follow/" + frec.Rkey, Cid: frec.Cid, - Author: follower.ActorRef(), + Author: follower.ActorView(), Reason: "follow", }, nil diff --git a/notifs/null.go b/notifs/null.go index 25f2a68fe..f29f8c5bf 100644 --- a/notifs/null.go +++ b/notifs/null.go @@ -15,7 +15,7 @@ type NullNotifs struct { var _ NotificationManager = (*NullNotifs)(nil) -func (nn *NullNotifs) GetNotifications(ctx context.Context, user util.Uid) ([]*appbskytypes.NotificationList_Notification, error) { +func (nn *NullNotifs) GetNotifications(ctx context.Context, user util.Uid) ([]*appbskytypes.NotificationListNotifications_Notification, error) { return nil, fmt.Errorf("no notifications engine loaded") } diff --git a/pds/auth.go b/pds/auth.go index f28a5c239..6da1924c7 100644 --- a/pds/auth.go +++ b/pds/auth.go @@ -12,8 +12,6 @@ import ( "github.com/lestrrat-go/jwx/v2/jwt" ) -const actorUserDeclarationCid = "bafyreid27zk7lbis4zw5fz4podbvbs4fc5ivwji3dmrwa6zggnj4bnd57u" - func makeToken(subject string, scope string, exp time.Time) jwt.Token { tok := jwt.New() tok.Set("scope", scope) diff --git a/pds/feedgen.go b/pds/feedgen.go index 4ed7c096e..49d7984bb 100644 --- a/pds/feedgen.go +++ b/pds/feedgen.go @@ -37,7 +37,7 @@ type ReadRecordFunc func(context.Context, bsutil.Uid, cid.Cid) (lexutil.CBOR, er /* type HydratedFeedItem struct { Uri string - RepostedBy *bsky.ActorRef_WithInfo + RepostedBy *bsky.ActorDefs_ProfileViewBasic Record any ReplyCount int64 RepostCount int64 @@ -45,15 +45,15 @@ type HydratedFeedItem struct { DownvoteCount int64 MyState *bsky.FeedGetAuthorFeed_MyState Cid string - Author *bsky.ActorRef_WithInfo - TrendedBy *bsky.ActorRef_WithInfo + Author *bsky.ActorDefs_ProfileViewBasic + TrendedBy *bsky.ActorDefs_ProfileViewBasic Embed *bsky.FeedEmbed IndexedAt string } */ -func (fg *FeedGenerator) hydrateFeed(ctx context.Context, items []*models.FeedPost, reposts []*models.RepostRecord) ([]*bsky.FeedFeedViewPost, error) { - out := make([]*bsky.FeedFeedViewPost, 0, len(items)) +func (fg *FeedGenerator) hydrateFeed(ctx context.Context, items []*models.FeedPost, reposts []*models.RepostRecord) ([]*bsky.FeedDefs_FeedViewPost, error) { + out := make([]*bsky.FeedDefs_FeedViewPost, 0, len(items)) for _, it := range items { hit, err := fg.hydrateItem(ctx, it) if err != nil { @@ -80,8 +80,8 @@ func (fg *FeedGenerator) hydrateFeed(ctx context.Context, items []*models.FeedPo return nil, err } - fvp.Reason = &bsky.FeedFeedViewPost_Reason{ - FeedFeedViewPost_ReasonRepost: &bsky.FeedFeedViewPost_ReasonRepost{ + fvp.Reason = &bsky.FeedDefs_FeedViewPost_Reason{ + FeedDefs_ReasonRepost: &bsky.FeedDefs_ReasonRepost{ By: reposter, IndexedAt: rp.CreatedAt.Format(time.RFC3339), }, @@ -104,7 +104,7 @@ func (fg *FeedGenerator) didForUser(ctx context.Context, user bsutil.Uid) (strin return ai.Did, nil } -func (fg *FeedGenerator) getActorRefInfo(ctx context.Context, user bsutil.Uid) (*bsky.ActorRef_WithInfo, error) { +func (fg *FeedGenerator) getActorRefInfo(ctx context.Context, user bsutil.Uid) (*bsky.ActorDefs_ProfileViewBasic, error) { // TODO: cache the shit out of this too var ai models.ActorInfo if err := fg.db.First(&ai, "uid = ?", user).Error; err != nil { @@ -114,22 +114,21 @@ func (fg *FeedGenerator) getActorRefInfo(ctx context.Context, user bsutil.Uid) ( return ai.ActorRef(), nil } -func (fg *FeedGenerator) hydrateItem(ctx context.Context, item *models.FeedPost) (*bsky.FeedFeedViewPost, error) { +func (fg *FeedGenerator) hydrateItem(ctx context.Context, item *models.FeedPost) (*bsky.FeedDefs_FeedViewPost, error) { authorDid, err := fg.didForUser(ctx, item.Author) if err != nil { return nil, err } - out := &bsky.FeedFeedViewPost{} + out := &bsky.FeedDefs_FeedViewPost{} - out.Post = &bsky.FeedPost_View{ - Uri: "at://" + authorDid + "/app.bsky.feed.post/" + item.Rkey, - ReplyCount: item.ReplyCount, - RepostCount: item.RepostCount, - UpvoteCount: item.UpCount, - DownvoteCount: 0, - Cid: item.Cid, - IndexedAt: item.UpdatedAt.Format(time.RFC3339), + out.Post = &bsky.FeedDefs_PostView{ + Uri: "at://" + authorDid + "/app.bsky.feed.post/" + item.Rkey, + ReplyCount: &item.ReplyCount, + RepostCount: &item.RepostCount, + LikeCount: &item.UpCount, + Cid: item.Cid, + IndexedAt: item.UpdatedAt.Format(time.RFC3339), } author, err := fg.getActorRefInfo(ctx, item.Author) @@ -149,13 +148,13 @@ func (fg *FeedGenerator) hydrateItem(ctx context.Context, item *models.FeedPost) return nil, err } - out.Post.Record = lexutil.LexiconTypeDecoder{rec} + out.Post.Record = &lexutil.LexiconTypeDecoder{rec} return out, nil } -func (fg *FeedGenerator) getPostViewerState(ctx context.Context, item uint, viewer bsutil.Uid, viewerDid string) (*bsky.FeedPost_ViewerState, error) { - var out bsky.FeedPost_ViewerState +func (fg *FeedGenerator) getPostViewerState(ctx context.Context, item uint, viewer bsutil.Uid, viewerDid string) (*bsky.FeedDefs_ViewerState, error) { + var out bsky.FeedDefs_ViewerState var vote models.VoteRecord if err := fg.db.Find(&vote, "post = ? AND voter = ?", item, viewer).Error; err != nil { @@ -164,12 +163,7 @@ func (fg *FeedGenerator) getPostViewerState(ctx context.Context, item uint, view if vote.ID != 0 { vuri := fmt.Sprintf("at://%s/app.bsky.feed.vote/%s", viewerDid, vote.Rkey) - switch vote.Dir { - case models.VoteDirUp: - out.Upvote = &vuri - case models.VoteDirDown: - out.Downvote = &vuri - } + out.Like = &vuri } var rep models.RepostRecord @@ -185,7 +179,7 @@ func (fg *FeedGenerator) getPostViewerState(ctx context.Context, item uint, view return &out, nil } -func (fg *FeedGenerator) GetTimeline(ctx context.Context, user *User, algo string, before string, limit int) ([]*bsky.FeedFeedViewPost, error) { +func (fg *FeedGenerator) GetTimeline(ctx context.Context, user *User, algo string, before string, limit int) ([]*bsky.FeedDefs_FeedViewPost, error) { ctx, span := otel.Tracer("feedgen").Start(context.Background(), "GetTimeline") defer span.End() @@ -219,7 +213,7 @@ func (fg *FeedGenerator) GetTimeline(ctx context.Context, user *User, algo strin return fg.personalizeFeed(ctx, fout, user) } -func (fg *FeedGenerator) personalizeFeed(ctx context.Context, feed []*bsky.FeedFeedViewPost, viewer *User) ([]*bsky.FeedFeedViewPost, error) { +func (fg *FeedGenerator) personalizeFeed(ctx context.Context, feed []*bsky.FeedDefs_FeedViewPost, viewer *User) ([]*bsky.FeedDefs_FeedViewPost, error) { for _, p := range feed { // TODO: its inefficient to have to call 'GetPost' again here when we could instead be doing that inside the 'hydrateFeed' call earlier. @@ -244,7 +238,7 @@ func (fg *FeedGenerator) personalizeFeed(ctx context.Context, feed []*bsky.FeedF return feed, nil } -func (fg *FeedGenerator) GetAuthorFeed(ctx context.Context, user *User, before string, limit int) ([]*bsky.FeedFeedViewPost, error) { +func (fg *FeedGenerator) GetAuthorFeed(ctx context.Context, user *User, before string, limit int) ([]*bsky.FeedDefs_FeedViewPost, error) { ctx, span := otel.Tracer("feedgen").Start(context.Background(), "GetAuthorFeed") defer span.End() @@ -294,7 +288,7 @@ func (fg *FeedGenerator) GetActorProfile(ctx context.Context, actor string) (*mo } type ThreadPost struct { - Post *bsky.FeedFeedViewPost + Post *bsky.FeedDefs_FeedViewPost PostID uint ParentUri string @@ -339,7 +333,7 @@ func (fg *FeedGenerator) GetPostThread(ctx context.Context, uri string, depth in } type HydratedVote struct { - Actor *bsky.ActorRef_WithInfo + Actor *bsky.ActorDefs_ProfileViewBasic Direction string IndexedAt time.Time CreatedAt string @@ -359,7 +353,7 @@ func (fg *FeedGenerator) hydrateVote(ctx context.Context, v *models.VoteRecord) }, nil } -func (fg *FeedGenerator) GetVotes(ctx context.Context, uri string, pcid cid.Cid, dir string, limit int, before string) ([]*HydratedVote, error) { +func (fg *FeedGenerator) GetVotes(ctx context.Context, uri string, pcid cid.Cid, limit int, before string) ([]*HydratedVote, error) { if before != "" { log.Warn("not respecting 'before' yet") } @@ -373,18 +367,8 @@ func (fg *FeedGenerator) GetVotes(ctx context.Context, uri string, pcid cid.Cid, return nil, fmt.Errorf("listing likes of old post versions not supported") } - var dbdir models.VoteDir - switch dir { - case "up": - dbdir = models.VoteDirUp - case "down": - dbdir = models.VoteDirDown - default: - return nil, fmt.Errorf("there are only two directions, up or down") - } - var voterecs []models.VoteRecord - if err := fg.db.Limit(limit).Find(&voterecs, "dir = ? AND post = ?", dbdir, p.ID).Error; err != nil { + if err := fg.db.Limit(limit).Find(&voterecs, "post = ?", p.ID).Error; err != nil { return nil, err } @@ -401,8 +385,8 @@ func (fg *FeedGenerator) GetVotes(ctx context.Context, uri string, pcid cid.Cid, } type FollowInfo struct { - Follower *bsky.ActorRef_WithInfo - Subject *bsky.ActorRef_WithInfo + Follower *bsky.ActorDefs_ProfileViewBasic + Subject *bsky.ActorDefs_ProfileViewBasic CreatedAt string IndexedAt string } diff --git a/pds/handlers.go b/pds/handlers.go index 206ef48e7..0bd6ccb2d 100644 --- a/pds/handlers.go +++ b/pds/handlers.go @@ -14,83 +14,31 @@ import ( "github.com/lestrrat-go/jwx/v2/jwt" ) -func (s *Server) handleAppBskyActorGetProfile(ctx context.Context, actor string) (*appbskytypes.ActorProfile_View, error) { +func (s *Server) handleAppBskyActorGetProfile(ctx context.Context, actor string) (*appbskytypes.ActorDefs_ProfileViewDetailed, error) { profile, err := s.feedgen.GetActorProfile(ctx, actor) if err != nil { return nil, err } - return &appbskytypes.ActorProfile_View{ - MyState: nil, //*ActorGetProfile_MyState `json:"myState" cborgen:"myState"` - Did: profile.Did, - Declaration: &appbskytypes.SystemDeclRef{ - Cid: profile.DeclRefCid, - ActorType: profile.Type, - }, + return &appbskytypes.ActorDefs_ProfileViewDetailed{ + Viewer: nil, //*ActorGetProfile_MyState `json:"myState" cborgen:"myState"` + Did: profile.Did, Description: nil, - PostsCount: profile.Posts, - FollowsCount: profile.Following, + PostsCount: &profile.Posts, + FollowsCount: &profile.Following, Handle: profile.Handle, - Creator: "", //TODO: DisplayName: &profile.DisplayName, - FollowersCount: profile.Followers, + FollowersCount: &profile.Followers, }, nil } func (s *Server) handleAppBskyActorGetSuggestions(ctx context.Context, cursor string, limit int) (*appbskytypes.ActorGetSuggestions_Output, error) { var out appbskytypes.ActorGetSuggestions_Output - out.Actors = []*appbskytypes.ActorProfile_ViewBasic{} + out.Actors = []*appbskytypes.ActorDefs_ProfileView{} return &out, nil } -func (s *Server) handleAppBskyActorSearch(ctx context.Context, before string, limit int, term string) (*appbskytypes.ActorSearch_Output, error) { - panic("not yet implemented") -} - -func (s *Server) handleAppBskyActorSearchTypeahead(ctx context.Context, limit int, term string) (*appbskytypes.ActorSearchTypeahead_Output, error) { - panic("not yet implemented") -} - -func (s *Server) handleAppBskyActorUpdateProfile(ctx context.Context, input *appbskytypes.ActorUpdateProfile_Input) (*appbskytypes.ActorUpdateProfile_Output, error) { - u, err := s.getUser(ctx) - if err != nil { - return nil, err - } - - profile, err := s.repoman.GetProfile(ctx, u.ID) - if err != nil { - return nil, err - } - - if input.DisplayName != nil { - profile.DisplayName = *input.DisplayName - } - - if input.DisplayName != nil { - profile.Description = input.Description - } - - if input.Avatar != nil { - profile.Avatar = input.Avatar - } - - if input.Banner != nil { - profile.Banner = input.Banner - } - - ncid, err := s.repoman.UpdateRecord(ctx, u.ID, "app.bsky.actor.profile", "self", profile) - if err != nil { - return nil, err - } - - return &appbskytypes.ActorUpdateProfile_Output{ - Cid: ncid.String(), - Uri: "at://" + u.Did + "/app.bsky.actor.profile/self", - Record: lexutil.LexiconTypeDecoder{profile}, - }, nil -} - func (s *Server) handleAppBskyFeedGetAuthorFeed(ctx context.Context, author string, before string, limit int) (*appbskytypes.FeedGetAuthorFeed_Output, error) { _, err := s.getUser(ctx) if err != nil { @@ -133,8 +81,8 @@ func (s *Server) handleAppBskyFeedGetPostThread(ctx context.Context, depth *int, fmt.Println("TODO: replies") - var convertToOutputType func(thr *ThreadPost) (*appbskytypes.FeedGetPostThread_ThreadViewPost, error) - convertToOutputType = func(thr *ThreadPost) (*appbskytypes.FeedGetPostThread_ThreadViewPost, error) { + var convertToOutputType func(thr *ThreadPost) (*appbskytypes.FeedDefs_ThreadViewPost, error) + convertToOutputType = func(thr *ThreadPost) (*appbskytypes.FeedDefs_ThreadViewPost, error) { p := thr.Post vs, err := s.feedgen.getPostViewerState(ctx, thr.PostID, u.ID, u.Did) @@ -144,14 +92,14 @@ func (s *Server) handleAppBskyFeedGetPostThread(ctx context.Context, depth *int, p.Post.Viewer = vs - out := &appbskytypes.FeedGetPostThread_ThreadViewPost{ + out := &appbskytypes.FeedDefs_ThreadViewPost{ Post: p.Post, } if thr.ParentUri != "" { if thr.Parent == nil { - out.Parent = &appbskytypes.FeedGetPostThread_ThreadViewPost_Parent{ - FeedGetPostThread_NotFoundPost: &appbskytypes.FeedGetPostThread_NotFoundPost{ + out.Parent = &appbskytypes.FeedDefs_ThreadViewPost_Parent{ + FeedDefs_NotFoundPost: &appbskytypes.FeedDefs_NotFoundPost{ Uri: thr.ParentUri, NotFound: true, }, @@ -162,8 +110,8 @@ func (s *Server) handleAppBskyFeedGetPostThread(ctx context.Context, depth *int, return nil, err } - out.Parent = &appbskytypes.FeedGetPostThread_ThreadViewPost_Parent{ - FeedGetPostThread_ThreadViewPost: othr, + out.Parent = &appbskytypes.FeedDefs_ThreadViewPost_Parent{ + FeedDefs_ThreadViewPost: othr, } } } @@ -178,7 +126,7 @@ func (s *Server) handleAppBskyFeedGetPostThread(ctx context.Context, depth *int, out := appbskytypes.FeedGetPostThread_Output{ Thread: &appbskytypes.FeedGetPostThread_Output_Thread{ - FeedGetPostThread_ThreadViewPost: othr, + FeedDefs_ThreadViewPost: othr, //FeedGetPostThread_NotFoundPost: &appbskytypes.FeedGetPostThread_NotFoundPost{}, }, } @@ -207,25 +155,25 @@ func (s *Server) handleAppBskyFeedGetTimeline(ctx context.Context, algorithm str return &out, nil } -func (s *Server) handleAppBskyFeedGetVotes(ctx context.Context, before string, cc string, direction string, limit int, uri string) (*appbskytypes.FeedGetVotes_Output, error) { +func (s *Server) handleAppBskyFeedGetLikes(ctx context.Context, cc string, cursor string, limit int, uri string) (*appbskytypes.FeedGetLikes_Output, error) { + // func (s *Server) handleAppBskyFeedGetLikes(ctx context.Context,cid string,cursor string,limit int,uri string) (*appbskytypes.FeedGetLikes_Output, error) pcid, err := cid.Decode(cc) if err != nil { return nil, err } - votes, err := s.feedgen.GetVotes(ctx, uri, pcid, direction, limit, before) + votes, err := s.feedgen.GetVotes(ctx, uri, pcid, limit, cursor) if err != nil { return nil, err } - var out appbskytypes.FeedGetVotes_Output + var out appbskytypes.FeedGetLikes_Output out.Uri = uri - out.Votes = []*appbskytypes.FeedGetVotes_Vote{} + out.Likes = []*appbskytypes.FeedGetLikes_Like{} for _, v := range votes { - out.Votes = append(out.Votes, &appbskytypes.FeedGetVotes_Vote{ - Actor: v.Actor, - Direction: v.Direction, + out.Likes = append(out.Likes, &appbskytypes.FeedGetLikes_Like{ + Actor: s.actorBasicToView(ctx, v.Actor), IndexedAt: v.IndexedAt.Format(time.RFC3339), CreatedAt: v.CreatedAt, }) @@ -234,60 +182,27 @@ func (s *Server) handleAppBskyFeedGetVotes(ctx context.Context, before string, c return &out, nil } -func (s *Server) handleAppBskyFeedSetVote(ctx context.Context, input *appbskytypes.FeedSetVote_Input) (*appbskytypes.FeedSetVote_Output, error) { - u, err := s.getUser(ctx) - if err != nil { - return nil, err - } - - // TODO: check subject actually exists maybe? - vote := &appbskytypes.FeedVote{ - Direction: input.Direction, - CreatedAt: time.Now().Format(time.RFC3339), - Subject: input.Subject, - } - - rpath, _, err := s.repoman.CreateRecord(ctx, u.ID, "app.bsky.feed.vote", vote) - if err != nil { - return nil, err - } - - uri := "at://" + u.Did + "/" + rpath - if input.Direction == "up" { - return &appbskytypes.FeedSetVote_Output{ - Upvote: &uri, - }, nil - } else if input.Direction == "down" { - return &appbskytypes.FeedSetVote_Output{ - Downvote: &uri, - }, nil - } else { - return nil, fmt.Errorf("strange place to catch an invalid vote direction") - } -} - -func (s *Server) handleAppBskyGraphGetFollowers(ctx context.Context, before string, limit int, user string) (*appbskytypes.GraphGetFollowers_Output, error) { +func (s *Server) handleAppBskyGraphGetFollowers(ctx context.Context, actor string, cursor string, limit int) (*appbskytypes.GraphGetFollowers_Output, error) { panic("not yet implemented") } -func (s *Server) handleAppBskyGraphGetFollows(ctx context.Context, before string, limit int, user string) (*appbskytypes.GraphGetFollows_Output, error) { - follows, err := s.feedgen.GetFollows(ctx, user, limit, before) +func (s *Server) handleAppBskyGraphGetFollows(ctx context.Context, actor string, cursor string, limit int) (*appbskytypes.GraphGetFollows_Output, error) { + follows, err := s.feedgen.GetFollows(ctx, actor, limit, cursor) if err != nil { return nil, err } - ai, err := s.feedgen.GetActorProfile(ctx, user) + ai, err := s.feedgen.GetActorProfile(ctx, actor) if err != nil { return nil, err } var out appbskytypes.GraphGetFollows_Output - out.Subject = ai.ActorRef() + out.Subject = s.actorBasicToView(ctx, ai.ActorRef()) - out.Follows = []*appbskytypes.ActorRef_WithInfo{} + out.Follows = []*appbskytypes.ActorDefs_ProfileView{} for _, f := range follows { - out.Follows = append(out.Follows, &appbskytypes.ActorRef_WithInfo{ - Declaration: f.Subject.Declaration, + out.Follows = append(out.Follows, &appbskytypes.ActorDefs_ProfileView{ Handle: f.Subject.Handle, DisplayName: f.Subject.DisplayName, Did: f.Subject.Did, @@ -301,15 +216,15 @@ func (s *Server) handleAppBskyGraphGetMutes(ctx context.Context, before string, panic("not yet implemented") } -func (s *Server) handleAppBskyGraphMute(ctx context.Context, input *appbskytypes.GraphMute_Input) error { +func (s *Server) handleAppBskyGraphMuteActor(ctx context.Context, input *appbskytypes.GraphMuteActor_Input) error { panic("not yet implemented") } -func (s *Server) handleAppBskyGraphUnmute(ctx context.Context, input *appbskytypes.GraphUnmute_Input) error { +func (s *Server) handleAppBskyGraphUnmuteActor(ctx context.Context, input *appbskytypes.GraphUnmuteActor_Input) error { panic("not yet implemented") } -func (s *Server) handleAppBskyNotificationGetCount(ctx context.Context) (*appbskytypes.NotificationGetCount_Output, error) { +func (s *Server) handleAppBskyNotificationGetUnreadCount(ctx context.Context) (*appbskytypes.NotificationGetUnreadCount_Output, error) { u, err := s.getUser(ctx) if err != nil { return nil, err @@ -321,12 +236,12 @@ func (s *Server) handleAppBskyNotificationGetCount(ctx context.Context) (*appbsk } fmt.Println("notif count: ", u.Handle, count) - return &appbskytypes.NotificationGetCount_Output{ + return &appbskytypes.NotificationGetUnreadCount_Output{ Count: count, }, nil } -func (s *Server) handleAppBskyNotificationList(ctx context.Context, before string, limit int) (*appbskytypes.NotificationList_Output, error) { +func (s *Server) handleAppBskyNotificationListNotifications(ctx context.Context, cursor string, limit int) (*appbskytypes.NotificationListNotifications_Output, error) { u, err := s.getUser(ctx) if err != nil { return nil, err @@ -337,7 +252,7 @@ func (s *Server) handleAppBskyNotificationList(ctx context.Context, before strin return nil, err } - return &appbskytypes.NotificationList_Output{ + return &appbskytypes.NotificationListNotifications_Output{ Notifications: notifs, }, nil } @@ -356,17 +271,17 @@ func (s *Server) handleAppBskyNotificationUpdateSeen(ctx context.Context, input return s.notifman.UpdateSeen(ctx, u.ID, seen) } -func (s *Server) handleComAtprotoAccountCreate(ctx context.Context, input *comatprototypes.AccountCreate_Input) (*comatprototypes.AccountCreate_Output, error) { +func (s *Server) handleComAtprotoServerCreateAccount(ctx context.Context, body *comatprototypes.ServerCreateAccount_Input) (*comatprototypes.ServerCreateAccount_Output, error) { - if err := validateEmail(input.Email); err != nil { + if err := validateEmail(body.Email); err != nil { return nil, err } - if err := s.validateHandle(input.Handle); err != nil { + if err := s.validateHandle(body.Handle); err != nil { return nil, err } - _, err := s.lookupUserByHandle(ctx, input.Handle) + _, err := s.lookupUserByHandle(ctx, body.Handle) switch err { default: return nil, err @@ -377,15 +292,15 @@ func (s *Server) handleComAtprotoAccountCreate(ctx context.Context, input *comat } var recoveryKey string - if input.RecoveryKey != nil { - recoveryKey = *input.RecoveryKey + if body.RecoveryKey != nil { + recoveryKey = *body.RecoveryKey } u := User{ - Handle: input.Handle, - Password: input.Password, + Handle: body.Handle, + Password: body.Password, RecoveryKey: recoveryKey, - Email: input.Email, + Email: body.Email, } if err := s.db.Create(&u).Error; err != nil { return nil, err @@ -395,7 +310,7 @@ func (s *Server) handleComAtprotoAccountCreate(ctx context.Context, input *comat recoveryKey = s.signingKey.Public().DID() } - d, err := s.plc.CreateDID(ctx, s.signingKey, recoveryKey, input.Handle, s.serviceUrl) + d, err := s.plc.CreateDID(ctx, s.signingKey, recoveryKey, body.Handle, s.serviceUrl) if err != nil { return nil, fmt.Errorf("create did: %w", err) } @@ -409,20 +324,20 @@ func (s *Server) handleComAtprotoAccountCreate(ctx context.Context, input *comat return nil, err } - tok, err := s.createAuthTokenForUser(ctx, input.Handle, d) + tok, err := s.createAuthTokenForUser(ctx, body.Handle, d) if err != nil { return nil, err } - return &comatprototypes.AccountCreate_Output{ - Handle: input.Handle, + return &comatprototypes.ServerCreateAccount_Output{ + Handle: body.Handle, Did: d, AccessJwt: tok.AccessJwt, RefreshJwt: tok.RefreshJwt, }, nil } -func (s *Server) handleComAtprotoAccountCreateInviteCode(ctx context.Context, input *comatprototypes.AccountCreateInviteCode_Input) (*comatprototypes.AccountCreateInviteCode_Output, error) { +func (s *Server) handleComAtprotoServerCreateInviteCode(ctx context.Context, body *comatprototypes.ServerCreateInviteCode_Input) (*comatprototypes.ServerCreateInviteCode_Output, error) { u, err := s.getUser(ctx) if err != nil { return nil, err @@ -433,53 +348,49 @@ func (s *Server) handleComAtprotoAccountCreateInviteCode(ctx context.Context, in return nil, fmt.Errorf("invite codes not currently supported") } -func (s *Server) handleComAtprotoAccountDelete(ctx context.Context, input *comatprototypes.AccountDelete_Input) error { +func (s *Server) handleComAtprotoServerRequestAccountDelete(ctx context.Context) error { panic("not yet implemented") } -func (s *Server) handleComAtprotoAccountGet(ctx context.Context) error { - return nil -} - -func (s *Server) handleComAtprotoAccountRequestDelete(ctx context.Context) error { +func (s *Server) handleComAtprotoServerDeleteAccount(ctx context.Context, body *comatprototypes.ServerDeleteAccount_Input) error { panic("not yet implemented") } -func (s *Server) handleComAtprotoAccountRequestPasswordReset(ctx context.Context, input *comatprototypes.AccountRequestPasswordReset_Input) error { +func (s *Server) handleComAtprotoServerRequestPasswordReset(ctx context.Context, body *comatprototypes.ServerRequestPasswordReset_Input) error { panic("not yet implemented") } -func (s *Server) handleComAtprotoAccountResetPassword(ctx context.Context, input *comatprototypes.AccountResetPassword_Input) error { +func (s *Server) handleComAtprotoServerResetPassword(ctx context.Context, body *comatprototypes.ServerResetPassword_Input) error { panic("not yet implemented") } -func (s *Server) handleComAtprotoBlobUpload(ctx context.Context, r io.Reader, ctype string) (*comatprototypes.BlobUpload_Output, error) { +func (s *Server) handleComAtprotoRepoUploadBlob(ctx context.Context, r io.Reader, contentType string) (*comatprototypes.RepoUploadBlob_Output, error) { panic("not yet implemented") } -func (s *Server) handleComAtprotoHandleResolve(ctx context.Context, handle string) (*comatprototypes.HandleResolve_Output, error) { +func (s *Server) handleComAtprotoIdentityResolveHandle(ctx context.Context, handle string) (*comatprototypes.IdentityResolveHandle_Output, error) { if handle == "" { - return &comatprototypes.HandleResolve_Output{Did: s.signingKey.Public().DID()}, nil + return &comatprototypes.IdentityResolveHandle_Output{Did: s.signingKey.Public().DID()}, nil } u, err := s.lookupUserByHandle(ctx, handle) if err != nil { return nil, err } - return &comatprototypes.HandleResolve_Output{Did: u.Did}, nil + return &comatprototypes.IdentityResolveHandle_Output{Did: u.Did}, nil } -func (s *Server) handleComAtprotoRepoBatchWrite(ctx context.Context, input *comatprototypes.RepoBatchWrite_Input) error { +func (s *Server) handleComAtprotoRepoApplyWrites(ctx context.Context, body *comatprototypes.RepoApplyWrites_Input) error { u, err := s.getUser(ctx) if err != nil { return err } - if u.Did != input.Did { + if u.Did != body.Repo { return fmt.Errorf("writes for non-user actors not supported (DID mismatch)") } - return s.repoman.BatchWrite(ctx, u.ID, input.Writes) + return s.repoman.BatchWrite(ctx, u.ID, body.Writes) } func (s *Server) handleComAtprotoRepoCreateRecord(ctx context.Context, input *comatprototypes.RepoCreateRecord_Input) (*comatprototypes.RepoCreateRecord_Output, error) { @@ -505,19 +416,15 @@ func (s *Server) handleComAtprotoRepoDeleteRecord(ctx context.Context, input *co return err } - if u.Did != input.Did { + if u.Did != input.Repo { return fmt.Errorf("specified DID did not match authed user") } return s.repoman.DeleteRecord(ctx, u.ID, input.Collection, input.Rkey) } -func (s *Server) handleComAtprotoRepoDescribe(ctx context.Context, user string) (*comatprototypes.RepoDescribe_Output, error) { - panic("not yet implemented") -} - -func (s *Server) handleComAtprotoRepoGetRecord(ctx context.Context, c string, collection string, rkey string, user string) (*comatprototypes.RepoGetRecord_Output, error) { - targetUser, err := s.lookupUser(ctx, user) +func (s *Server) handleComAtprotoRepoGetRecord(ctx context.Context, c string, collection string, repo string, rkey string) (*comatprototypes.RepoGetRecord_Output, error) { + targetUser, err := s.lookupUser(ctx, repo) if err != nil { return nil, err } @@ -540,11 +447,11 @@ func (s *Server) handleComAtprotoRepoGetRecord(ctx context.Context, c string, co return &comatprototypes.RepoGetRecord_Output{ Cid: &ccstr, Uri: "at://" + targetUser.Did + "/" + collection + "/" + rkey, - Value: lexutil.LexiconTypeDecoder{rec}, + Value: &lexutil.LexiconTypeDecoder{rec}, }, nil } -func (s *Server) handleComAtprotoRepoListRecords(ctx context.Context, after string, before string, collection string, limit int, reverse *bool, user string) (*comatprototypes.RepoListRecords_Output, error) { +func (s *Server) handleComAtprotoRepoListRecords(ctx context.Context, collection string, limit int, repo string, reverse *bool, rkeyEnd string, rkeyStart string) (*comatprototypes.RepoListRecords_Output, error) { panic("not yet implemented") } @@ -552,57 +459,57 @@ func (s *Server) handleComAtprotoRepoPutRecord(ctx context.Context, input *comat panic("not yet implemented") } -func (s *Server) handleComAtprotoServerGetAccountsConfig(ctx context.Context) (*comatprototypes.ServerGetAccountsConfig_Output, error) { +func (s *Server) handleComAtprotoServerDescribeServer(ctx context.Context) (*comatprototypes.ServerDescribeServer_Output, error) { invcode := false - return &comatprototypes.ServerGetAccountsConfig_Output{ + return &comatprototypes.ServerDescribeServer_Output{ InviteCodeRequired: &invcode, AvailableUserDomains: []string{ s.handleSuffix, }, - Links: &comatprototypes.ServerGetAccountsConfig_Links{}, + Links: &comatprototypes.ServerDescribeServer_Links{}, }, nil } -func (s *Server) handleComAtprotoSessionCreate(ctx context.Context, input *comatprototypes.SessionCreate_Input) (*comatprototypes.SessionCreate_Output, error) { - u, err := s.lookupUserByHandle(ctx, *input.Identifier) +func (s *Server) handleComAtprotoServerCreateSession(ctx context.Context, body *comatprototypes.ServerCreateSession_Input) (*comatprototypes.ServerCreateSession_Output, error) { + u, err := s.lookupUserByHandle(ctx, *body.Identifier) if err != nil { return nil, err } - if input.Password != u.Password { + if body.Password != u.Password { return nil, fmt.Errorf("invalid username or password") } - tok, err := s.createAuthTokenForUser(ctx, *input.Identifier, u.Did) + tok, err := s.createAuthTokenForUser(ctx, *body.Identifier, u.Did) if err != nil { return nil, err } - return &comatprototypes.SessionCreate_Output{ - Handle: *input.Identifier, + return &comatprototypes.ServerCreateSession_Output{ + Handle: *body.Identifier, Did: u.Did, AccessJwt: tok.AccessJwt, RefreshJwt: tok.RefreshJwt, }, nil } -func (s *Server) handleComAtprotoSessionDelete(ctx context.Context) error { +func (s *Server) handleComAtprotoServerDeleteSession(ctx context.Context) error { panic("not yet implemented") } -func (s *Server) handleComAtprotoSessionGet(ctx context.Context) (*comatprototypes.SessionGet_Output, error) { +func (s *Server) handleComAtprotoServerGetSession(ctx context.Context) (*comatprototypes.ServerGetSession_Output, error) { u, err := s.getUser(ctx) if err != nil { return nil, err } - return &comatprototypes.SessionGet_Output{ + return &comatprototypes.ServerGetSession_Output{ Handle: u.Handle, Did: u.Did, }, nil } -func (s *Server) handleComAtprotoSessionRefresh(ctx context.Context) (*comatprototypes.SessionRefresh_Output, error) { +func (s *Server) handleComAtprotoServerRefreshSession(ctx context.Context) (*comatprototypes.ServerRefreshSession_Output, error) { u, err := s.getUser(ctx) if err != nil { return nil, err @@ -631,7 +538,7 @@ func (s *Server) handleComAtprotoSessionRefresh(ctx context.Context) (*comatprot return nil, err } - return &comatprototypes.SessionRefresh_Output{ + return &comatprototypes.ServerRefreshSession_Output{ Handle: u.Handle, Did: u.Did, AccessJwt: outTok.AccessJwt, @@ -710,43 +617,36 @@ func (s *Server) handleAppBskyActorGetProfiles(ctx context.Context, actors []str panic("nyi") } -func (s *Server) handleComAtprotoAdminGetModerationAction(ctx context.Context, id int) (*comatprototypes.AdminModerationAction_ViewDetail, error) { +func (s *Server) handleComAtprotoAdminGetModerationAction(ctx context.Context, id int) (*comatprototypes.AdminDefs_ActionViewDetail, error) { panic("nyi") } func (s *Server) handleComAtprotoAdminGetModerationActions(ctx context.Context, before string, limit int, subject string) (*comatprototypes.AdminGetModerationActions_Output, error) { panic("nyi") } -func (s *Server) handleComAtprotoAdminGetModerationReport(ctx context.Context, id int) (*comatprototypes.AdminModerationReport_ViewDetail, error) { +func (s *Server) handleComAtprotoAdminGetModerationReport(ctx context.Context, id int) (*comatprototypes.AdminDefs_ReportViewDetail, error) { panic("nyi") } func (s *Server) handleComAtprotoAdminGetModerationReports(ctx context.Context, before string, limit int, resolved *bool, subject string) (*comatprototypes.AdminGetModerationReports_Output, error) { panic("nyi") } -func (s *Server) handleComAtprotoAdminGetRecord(ctx context.Context, cid string, uri string) (*comatprototypes.AdminRecord_ViewDetail, error) { +func (s *Server) handleComAtprotoAdminGetRecord(ctx context.Context, cid string, uri string) (*comatprototypes.AdminDefs_RecordViewDetail, error) { panic("nyi") } -func (s *Server) handleComAtprotoAdminGetRepo(ctx context.Context, did string) (*comatprototypes.AdminRepo_ViewDetail, error) { +func (s *Server) handleComAtprotoAdminGetRepo(ctx context.Context, did string) (*comatprototypes.AdminDefs_RepoViewDetail, error) { panic("nyi") } -func (s *Server) handleComAtprotoAdminResolveModerationReports(ctx context.Context, body *comatprototypes.AdminResolveModerationReports_Input) (*comatprototypes.AdminModerationAction_View, error) { +func (s *Server) handleComAtprotoAdminResolveModerationReports(ctx context.Context, body *comatprototypes.AdminResolveModerationReports_Input) (*comatprototypes.AdminDefs_ActionView, error) { panic("nyi") } -func (s *Server) handleComAtprotoAdminReverseModerationAction(ctx context.Context, body *comatprototypes.AdminReverseModerationAction_Input) (*comatprototypes.AdminModerationAction_View, error) { +func (s *Server) handleComAtprotoAdminReverseModerationAction(ctx context.Context, body *comatprototypes.AdminReverseModerationAction_Input) (*comatprototypes.AdminDefs_ActionView, error) { panic("nyi") } func (s *Server) handleComAtprotoAdminSearchRepos(ctx context.Context, before string, limit int, term string) (*comatprototypes.AdminSearchRepos_Output, error) { panic("nyi") } -func (s *Server) handleComAtprotoAdminTakeModerationAction(ctx context.Context, body *comatprototypes.AdminTakeModerationAction_Input) (*comatprototypes.AdminModerationAction_View, error) { - panic("nyi") -} -func (s *Server) handleComAtprotoReportCreate(ctx context.Context, body *comatprototypes.ReportCreate_Input) (*comatprototypes.ReportCreate_Output, error) { - panic("nyi") -} - -func (s *Server) handleComAtprotoHandleUpdate(ctx context.Context, body *comatprototypes.HandleUpdate_Input) error { +func (s *Server) handleComAtprotoAdminTakeModerationAction(ctx context.Context, body *comatprototypes.AdminTakeModerationAction_Input) (*comatprototypes.AdminDefs_ActionView, error) { panic("nyi") } @@ -769,3 +669,27 @@ func (s *Server) handleComAtprotoSyncGetBlob(ctx context.Context, cid string, di func (s *Server) handleComAtprotoSyncListBlobs(ctx context.Context, did string, earliest string, latest string) (*comatprototypes.SyncListBlobs_Output, error) { panic("nyi") } + +func (s *Server) handleAppBskyActorSearchActors(ctx context.Context, cursor string, limit int, term string) (*appbskytypes.ActorSearchActors_Output, error) { + panic("nyi") +} + +func (s *Server) handleAppBskyActorSearchActorsTypeahead(ctx context.Context, limit int, term string) (*appbskytypes.ActorSearchActorsTypeahead_Output, error) { + panic("nyi") +} + +func (s *Server) handleAppBskyUnspeccedGetPopular(ctx context.Context, cursor string, limit int) (*appbskytypes.UnspeccedGetPopular_Output, error) { + panic("nyi") +} + +func (s *Server) handleComAtprotoIdentityUpdateHandle(ctx context.Context, body *comatprototypes.IdentityUpdateHandle_Input) error { + panic("nyi") +} + +func (s *Server) handleComAtprotoModerationCreateReport(ctx context.Context, body *comatprototypes.ModerationCreateReport_Input) (*comatprototypes.ModerationCreateReport_Output, error) { + panic("nyi") +} + +func (s *Server) handleComAtprotoRepoDescribeRepo(ctx context.Context, repo string) (*comatprototypes.RepoDescribeRepo_Output, error) { + panic("nyi") +} diff --git a/pds/server.go b/pds/server.go index 7f76cde91..e8ceaa7cc 100644 --- a/pds/server.go +++ b/pds/server.go @@ -12,7 +12,7 @@ import ( "strings" "time" - atproto "github.com/bluesky-social/indigo/api/atproto" + comatproto "github.com/bluesky-social/indigo/api/atproto" bsky "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/carstore" "github.com/bluesky-social/indigo/events" @@ -125,8 +125,8 @@ func (s *Server) Shutdown(ctx context.Context) error { func (s *Server) handleFedEvent(ctx context.Context, host *Peering, env *events.XRPCStreamEvent) error { fmt.Printf("[%s] got fed event from %q\n", s.serviceUrl, host.Host) switch { - case env.RepoAppend != nil: - evt := env.RepoAppend + case env.RepoCommit != nil: + evt := env.RepoCommit u, err := s.lookupUserByDid(ctx, evt.Repo) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { @@ -142,17 +142,7 @@ func (s *Server) handleFedEvent(ctx context.Context, host *Peering, env *events. u.ID = subj.Uid } - var pcid *cid.Cid - if evt.Prev != nil { - prev, err := cid.Decode(*evt.Prev) - if err != nil { - return err - } - - pcid = &prev - } - - return s.repoman.HandleExternalUserEvent(ctx, host.ID, u.ID, u.Did, pcid, evt.Blocks) + return s.repoman.HandleExternalUserEvent(ctx, host.ID, u.ID, u.Did, (*cid.Cid)(evt.Prev), evt.Blocks) default: return fmt.Errorf("invalid fed event") } @@ -183,7 +173,7 @@ func (s *Server) createExternalUser(ctx context.Context, did string) (*models.Ac c := &xrpc.Client{Host: svc.ServiceEndpoint} if peering.ID == 0 { - pdsdid, err := atproto.HandleResolve(ctx, c, "") + pdsdid, err := comatproto.IdentityResolveHandle(ctx, c, "") if err != nil { // TODO: failing this shouldnt halt our indexing return nil, fmt.Errorf("failed to get accounts config for unrecognized pds: %w", err) @@ -235,7 +225,6 @@ func (s *Server) createExternalUser(ctx context.Context, did string) (*models.Ac Handle: handle, DisplayName: *profile.DisplayName, Did: did, - DeclRefCid: profile.Declaration.Cid, Type: "", PDS: peering.ID, } @@ -246,20 +235,14 @@ func (s *Server) createExternalUser(ctx context.Context, did string) (*models.Ac return subj, nil } -func (s *Server) repoEventToFedEvent(ctx context.Context, evt *repomgr.RepoEvent) (*events.RepoAppend, error) { +func (s *Server) repoEventToFedEvent(ctx context.Context, evt *repomgr.RepoEvent) (*comatproto.SyncSubscribeRepos_Commit, error) { did, err := s.indexer.DidForUser(ctx, evt.User) if err != nil { return nil, err } - var prevcid *string - if evt.OldRoot != nil { - s := evt.OldRoot.String() - prevcid = &s - } - - out := &events.RepoAppend{ - Prev: prevcid, + out := &comatproto.SyncSubscribeRepos_Commit{ + Prev: (*lexutil.LexLink)(evt.OldRoot), Blocks: evt.RepoSlice, Repo: did, Time: time.Now().Format(bsutil.ISO8601), @@ -267,16 +250,10 @@ func (s *Server) repoEventToFedEvent(ctx context.Context, evt *repomgr.RepoEvent } for _, op := range evt.Ops { - var s *string - if op.RecCid != nil { - cs := op.RecCid.String() - s = &cs - } - - out.Ops = append(out.Ops, &events.RepoOp{ + out.Ops = append(out.Ops, &comatproto.SyncSubscribeRepos_RepoOp{ Path: op.Collection + "/" + op.Rkey, Action: string(op.Kind), - Cid: s, + Cid: (*lexutil.LexLink)(op.RecCid), }) } @@ -345,15 +322,15 @@ func (s *Server) RunAPI(listen string) error { switch c.Path() { case "/xrpc/_health": return true - case "/xrpc/com.atproto.sync.subscribeAllRepos": + case "/xrpc/com.atproto.sync.subscribeRepos": return true case "/xrpc/com.atproto.account.create": return true - case "/xrpc/com.atproto.handle.resolve": + case "/xrpc/com.atproto.identity.resolveHandle": return true - case "/xrpc/com.atproto.session.create": + case "/xrpc/com.atproto.server.createAccount": return true - case "/xrpc/com.atproto.server.getAccountsConfig": + case "/xrpc/com.atproto.server.describeServer": return true case "/xrpc/app.bsky.actor.getProfile": fmt.Println("TODO: currently not requiring auth on get profile endpoint") @@ -385,7 +362,7 @@ func (s *Server) RunAPI(listen string) error { e.Use(middleware.JWTWithConfig(cfg), s.userCheckMiddleware) s.RegisterHandlersComAtproto(e) s.RegisterHandlersAppBsky(e) - e.GET("/xrpc/com.atproto.sync.subscribeAllRepos", s.EventsHandler) + e.GET("/xrpc/com.atproto.sync.subscribeRepos", s.EventsHandler) e.GET("/xrpc/_health", s.HandleHealthCheck) return e.Start(listen) @@ -650,7 +627,7 @@ func (s *Server) EventsHandler(c echo.Context) error { } defer cancel() - header := events.EventHeader{Op: events.EvtKindRepoAppend} + header := events.EventHeader{Op: events.EvtKindMessage} for evt := range evts { wc, err := conn.NextWriter(websocket.BinaryMessage) if err != nil { @@ -660,15 +637,24 @@ func (s *Server) EventsHandler(c echo.Context) error { var obj lexutil.CBOR switch { - case evt.RepoAppend != nil: - header.Op = events.EvtKindRepoAppend - obj = evt.RepoAppend - case evt.Info != nil: - header.Op = events.EvtKindInfoFrame - obj = evt.Info case evt.Error != nil: header.Op = events.EvtKindErrorFrame obj = evt.Error + case evt.RepoCommit != nil: + header.MsgType = "#commit" + obj = evt.RepoCommit + case evt.RepoHandle != nil: + header.MsgType = "#handle" + obj = evt.RepoHandle + case evt.RepoInfo != nil: + header.MsgType = "#info" + obj = evt.RepoInfo + case evt.RepoMigrate != nil: + header.MsgType = "#migrate" + obj = evt.RepoMigrate + case evt.RepoTombstone != nil: + header.MsgType = "#tombstone" + obj = evt.RepoTombstone default: return fmt.Errorf("unrecognized event kind") } diff --git a/pds/stubs.go b/pds/stubs.go index 1a718c25d..1edbb935d 100644 --- a/pds/stubs.go +++ b/pds/stubs.go @@ -14,23 +14,22 @@ func (s *Server) RegisterHandlersAppBsky(e *echo.Echo) error { e.GET("/xrpc/app.bsky.actor.getProfile", s.HandleAppBskyActorGetProfile) e.GET("/xrpc/app.bsky.actor.getProfiles", s.HandleAppBskyActorGetProfiles) e.GET("/xrpc/app.bsky.actor.getSuggestions", s.HandleAppBskyActorGetSuggestions) - e.GET("/xrpc/app.bsky.actor.search", s.HandleAppBskyActorSearch) - e.GET("/xrpc/app.bsky.actor.searchTypeahead", s.HandleAppBskyActorSearchTypeahead) - e.POST("/xrpc/app.bsky.actor.updateProfile", s.HandleAppBskyActorUpdateProfile) + e.GET("/xrpc/app.bsky.actor.searchActors", s.HandleAppBskyActorSearchActors) + e.GET("/xrpc/app.bsky.actor.searchActorsTypeahead", s.HandleAppBskyActorSearchActorsTypeahead) e.GET("/xrpc/app.bsky.feed.getAuthorFeed", s.HandleAppBskyFeedGetAuthorFeed) + e.GET("/xrpc/app.bsky.feed.getLikes", s.HandleAppBskyFeedGetLikes) e.GET("/xrpc/app.bsky.feed.getPostThread", s.HandleAppBskyFeedGetPostThread) e.GET("/xrpc/app.bsky.feed.getRepostedBy", s.HandleAppBskyFeedGetRepostedBy) e.GET("/xrpc/app.bsky.feed.getTimeline", s.HandleAppBskyFeedGetTimeline) - e.GET("/xrpc/app.bsky.feed.getVotes", s.HandleAppBskyFeedGetVotes) - e.POST("/xrpc/app.bsky.feed.setVote", s.HandleAppBskyFeedSetVote) e.GET("/xrpc/app.bsky.graph.getFollowers", s.HandleAppBskyGraphGetFollowers) e.GET("/xrpc/app.bsky.graph.getFollows", s.HandleAppBskyGraphGetFollows) e.GET("/xrpc/app.bsky.graph.getMutes", s.HandleAppBskyGraphGetMutes) - e.POST("/xrpc/app.bsky.graph.mute", s.HandleAppBskyGraphMute) - e.POST("/xrpc/app.bsky.graph.unmute", s.HandleAppBskyGraphUnmute) - e.GET("/xrpc/app.bsky.notification.getCount", s.HandleAppBskyNotificationGetCount) - e.GET("/xrpc/app.bsky.notification.list", s.HandleAppBskyNotificationList) + e.POST("/xrpc/app.bsky.graph.muteActor", s.HandleAppBskyGraphMuteActor) + e.POST("/xrpc/app.bsky.graph.unmuteActor", s.HandleAppBskyGraphUnmuteActor) + e.GET("/xrpc/app.bsky.notification.getUnreadCount", s.HandleAppBskyNotificationGetUnreadCount) + e.GET("/xrpc/app.bsky.notification.listNotifications", s.HandleAppBskyNotificationListNotifications) e.POST("/xrpc/app.bsky.notification.updateSeen", s.HandleAppBskyNotificationUpdateSeen) + e.GET("/xrpc/app.bsky.unspecced.getPopular", s.HandleAppBskyUnspeccedGetPopular) return nil } @@ -38,9 +37,9 @@ func (s *Server) HandleAppBskyActorGetProfile(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyActorGetProfile") defer span.End() actor := c.QueryParam("actor") - var out *appbskytypes.ActorProfile_View + var out *appbskytypes.ActorDefs_ProfileViewDetailed var handleErr error - // func (s *Server) handleAppBskyActorGetProfile(ctx context.Context,actor string) (*appbskytypes.ActorProfile_View, error) + // func (s *Server) handleAppBskyActorGetProfile(ctx context.Context,actor string) (*appbskytypes.ActorDefs_ProfileViewDetailed, error) out, handleErr = s.handleAppBskyActorGetProfile(ctx, actor) if handleErr != nil { return handleErr @@ -88,10 +87,10 @@ func (s *Server) HandleAppBskyActorGetSuggestions(c echo.Context) error { return c.JSON(200, out) } -func (s *Server) HandleAppBskyActorSearch(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyActorSearch") +func (s *Server) HandleAppBskyActorSearchActors(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyActorSearchActors") defer span.End() - before := c.QueryParam("before") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -104,18 +103,18 @@ func (s *Server) HandleAppBskyActorSearch(c echo.Context) error { limit = 50 } term := c.QueryParam("term") - var out *appbskytypes.ActorSearch_Output + var out *appbskytypes.ActorSearchActors_Output var handleErr error - // func (s *Server) handleAppBskyActorSearch(ctx context.Context,before string,limit int,term string) (*appbskytypes.ActorSearch_Output, error) - out, handleErr = s.handleAppBskyActorSearch(ctx, before, limit, term) + // func (s *Server) handleAppBskyActorSearchActors(ctx context.Context,cursor string,limit int,term string) (*appbskytypes.ActorSearchActors_Output, error) + out, handleErr = s.handleAppBskyActorSearchActors(ctx, cursor, limit, term) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleAppBskyActorSearchTypeahead(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyActorSearchTypeahead") +func (s *Server) HandleAppBskyActorSearchActorsTypeahead(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyActorSearchActorsTypeahead") defer span.End() var limit int @@ -129,39 +128,47 @@ func (s *Server) HandleAppBskyActorSearchTypeahead(c echo.Context) error { limit = 50 } term := c.QueryParam("term") - var out *appbskytypes.ActorSearchTypeahead_Output + var out *appbskytypes.ActorSearchActorsTypeahead_Output var handleErr error - // func (s *Server) handleAppBskyActorSearchTypeahead(ctx context.Context,limit int,term string) (*appbskytypes.ActorSearchTypeahead_Output, error) - out, handleErr = s.handleAppBskyActorSearchTypeahead(ctx, limit, term) + // func (s *Server) handleAppBskyActorSearchActorsTypeahead(ctx context.Context,limit int,term string) (*appbskytypes.ActorSearchActorsTypeahead_Output, error) + out, handleErr = s.handleAppBskyActorSearchActorsTypeahead(ctx, limit, term) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleAppBskyActorUpdateProfile(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyActorUpdateProfile") +func (s *Server) HandleAppBskyFeedGetAuthorFeed(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyFeedGetAuthorFeed") defer span.End() + actor := c.QueryParam("actor") + cursor := c.QueryParam("cursor") - var body appbskytypes.ActorUpdateProfile_Input - if err := c.Bind(&body); err != nil { - return err + var limit int + if p := c.QueryParam("limit"); p != "" { + var err error + limit, err = strconv.Atoi(p) + if err != nil { + return err + } + } else { + limit = 50 } - var out *appbskytypes.ActorUpdateProfile_Output + var out *appbskytypes.FeedGetAuthorFeed_Output var handleErr error - // func (s *Server) handleAppBskyActorUpdateProfile(ctx context.Context,body *appbskytypes.ActorUpdateProfile_Input) (*appbskytypes.ActorUpdateProfile_Output, error) - out, handleErr = s.handleAppBskyActorUpdateProfile(ctx, &body) + // func (s *Server) handleAppBskyFeedGetAuthorFeed(ctx context.Context,actor string,cursor string,limit int) (*appbskytypes.FeedGetAuthorFeed_Output, error) + out, handleErr = s.handleAppBskyFeedGetAuthorFeed(ctx, actor, cursor, limit) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleAppBskyFeedGetAuthorFeed(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyFeedGetAuthorFeed") +func (s *Server) HandleAppBskyFeedGetLikes(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyFeedGetLikes") defer span.End() - author := c.QueryParam("author") - before := c.QueryParam("before") + cid := c.QueryParam("cid") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -173,10 +180,11 @@ func (s *Server) HandleAppBskyFeedGetAuthorFeed(c echo.Context) error { } else { limit = 50 } - var out *appbskytypes.FeedGetAuthorFeed_Output + uri := c.QueryParam("uri") + var out *appbskytypes.FeedGetLikes_Output var handleErr error - // func (s *Server) handleAppBskyFeedGetAuthorFeed(ctx context.Context,author string,before string,limit int) (*appbskytypes.FeedGetAuthorFeed_Output, error) - out, handleErr = s.handleAppBskyFeedGetAuthorFeed(ctx, author, before, limit) + // func (s *Server) handleAppBskyFeedGetLikes(ctx context.Context,cid string,cursor string,limit int,uri string) (*appbskytypes.FeedGetLikes_Output, error) + out, handleErr = s.handleAppBskyFeedGetLikes(ctx, cid, cursor, limit, uri) if handleErr != nil { return handleErr } @@ -209,8 +217,8 @@ func (s *Server) HandleAppBskyFeedGetPostThread(c echo.Context) error { func (s *Server) HandleAppBskyFeedGetRepostedBy(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyFeedGetRepostedBy") defer span.End() - before := c.QueryParam("before") cid := c.QueryParam("cid") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -225,8 +233,8 @@ func (s *Server) HandleAppBskyFeedGetRepostedBy(c echo.Context) error { uri := c.QueryParam("uri") var out *appbskytypes.FeedGetRepostedBy_Output var handleErr error - // func (s *Server) handleAppBskyFeedGetRepostedBy(ctx context.Context,before string,cid string,limit int,uri string) (*appbskytypes.FeedGetRepostedBy_Output, error) - out, handleErr = s.handleAppBskyFeedGetRepostedBy(ctx, before, cid, limit, uri) + // func (s *Server) handleAppBskyFeedGetRepostedBy(ctx context.Context,cid string,cursor string,limit int,uri string) (*appbskytypes.FeedGetRepostedBy_Output, error) + out, handleErr = s.handleAppBskyFeedGetRepostedBy(ctx, cid, cursor, limit, uri) if handleErr != nil { return handleErr } @@ -237,7 +245,7 @@ func (s *Server) HandleAppBskyFeedGetTimeline(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyFeedGetTimeline") defer span.End() algorithm := c.QueryParam("algorithm") - before := c.QueryParam("before") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -251,54 +259,8 @@ func (s *Server) HandleAppBskyFeedGetTimeline(c echo.Context) error { } var out *appbskytypes.FeedGetTimeline_Output var handleErr error - // func (s *Server) handleAppBskyFeedGetTimeline(ctx context.Context,algorithm string,before string,limit int) (*appbskytypes.FeedGetTimeline_Output, error) - out, handleErr = s.handleAppBskyFeedGetTimeline(ctx, algorithm, before, limit) - if handleErr != nil { - return handleErr - } - return c.JSON(200, out) -} - -func (s *Server) HandleAppBskyFeedGetVotes(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyFeedGetVotes") - defer span.End() - before := c.QueryParam("before") - cid := c.QueryParam("cid") - direction := c.QueryParam("direction") - - var limit int - if p := c.QueryParam("limit"); p != "" { - var err error - limit, err = strconv.Atoi(p) - if err != nil { - return err - } - } else { - limit = 50 - } - uri := c.QueryParam("uri") - var out *appbskytypes.FeedGetVotes_Output - var handleErr error - // func (s *Server) handleAppBskyFeedGetVotes(ctx context.Context,before string,cid string,direction string,limit int,uri string) (*appbskytypes.FeedGetVotes_Output, error) - out, handleErr = s.handleAppBskyFeedGetVotes(ctx, before, cid, direction, limit, uri) - if handleErr != nil { - return handleErr - } - return c.JSON(200, out) -} - -func (s *Server) HandleAppBskyFeedSetVote(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyFeedSetVote") - defer span.End() - - var body appbskytypes.FeedSetVote_Input - if err := c.Bind(&body); err != nil { - return err - } - var out *appbskytypes.FeedSetVote_Output - var handleErr error - // func (s *Server) handleAppBskyFeedSetVote(ctx context.Context,body *appbskytypes.FeedSetVote_Input) (*appbskytypes.FeedSetVote_Output, error) - out, handleErr = s.handleAppBskyFeedSetVote(ctx, &body) + // func (s *Server) handleAppBskyFeedGetTimeline(ctx context.Context,algorithm string,cursor string,limit int) (*appbskytypes.FeedGetTimeline_Output, error) + out, handleErr = s.handleAppBskyFeedGetTimeline(ctx, algorithm, cursor, limit) if handleErr != nil { return handleErr } @@ -308,7 +270,8 @@ func (s *Server) HandleAppBskyFeedSetVote(c echo.Context) error { func (s *Server) HandleAppBskyGraphGetFollowers(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyGraphGetFollowers") defer span.End() - before := c.QueryParam("before") + actor := c.QueryParam("actor") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -320,11 +283,10 @@ func (s *Server) HandleAppBskyGraphGetFollowers(c echo.Context) error { } else { limit = 50 } - user := c.QueryParam("user") var out *appbskytypes.GraphGetFollowers_Output var handleErr error - // func (s *Server) handleAppBskyGraphGetFollowers(ctx context.Context,before string,limit int,user string) (*appbskytypes.GraphGetFollowers_Output, error) - out, handleErr = s.handleAppBskyGraphGetFollowers(ctx, before, limit, user) + // func (s *Server) handleAppBskyGraphGetFollowers(ctx context.Context,actor string,cursor string,limit int) (*appbskytypes.GraphGetFollowers_Output, error) + out, handleErr = s.handleAppBskyGraphGetFollowers(ctx, actor, cursor, limit) if handleErr != nil { return handleErr } @@ -334,7 +296,8 @@ func (s *Server) HandleAppBskyGraphGetFollowers(c echo.Context) error { func (s *Server) HandleAppBskyGraphGetFollows(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyGraphGetFollows") defer span.End() - before := c.QueryParam("before") + actor := c.QueryParam("actor") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -346,11 +309,10 @@ func (s *Server) HandleAppBskyGraphGetFollows(c echo.Context) error { } else { limit = 50 } - user := c.QueryParam("user") var out *appbskytypes.GraphGetFollows_Output var handleErr error - // func (s *Server) handleAppBskyGraphGetFollows(ctx context.Context,before string,limit int,user string) (*appbskytypes.GraphGetFollows_Output, error) - out, handleErr = s.handleAppBskyGraphGetFollows(ctx, before, limit, user) + // func (s *Server) handleAppBskyGraphGetFollows(ctx context.Context,actor string,cursor string,limit int) (*appbskytypes.GraphGetFollows_Output, error) + out, handleErr = s.handleAppBskyGraphGetFollows(ctx, actor, cursor, limit) if handleErr != nil { return handleErr } @@ -360,7 +322,7 @@ func (s *Server) HandleAppBskyGraphGetFollows(c echo.Context) error { func (s *Server) HandleAppBskyGraphGetMutes(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyGraphGetMutes") defer span.End() - before := c.QueryParam("before") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -374,65 +336,65 @@ func (s *Server) HandleAppBskyGraphGetMutes(c echo.Context) error { } var out *appbskytypes.GraphGetMutes_Output var handleErr error - // func (s *Server) handleAppBskyGraphGetMutes(ctx context.Context,before string,limit int) (*appbskytypes.GraphGetMutes_Output, error) - out, handleErr = s.handleAppBskyGraphGetMutes(ctx, before, limit) + // func (s *Server) handleAppBskyGraphGetMutes(ctx context.Context,cursor string,limit int) (*appbskytypes.GraphGetMutes_Output, error) + out, handleErr = s.handleAppBskyGraphGetMutes(ctx, cursor, limit) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleAppBskyGraphMute(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyGraphMute") +func (s *Server) HandleAppBskyGraphMuteActor(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyGraphMuteActor") defer span.End() - var body appbskytypes.GraphMute_Input + var body appbskytypes.GraphMuteActor_Input if err := c.Bind(&body); err != nil { return err } var handleErr error - // func (s *Server) handleAppBskyGraphMute(ctx context.Context,body *appbskytypes.GraphMute_Input) error - handleErr = s.handleAppBskyGraphMute(ctx, &body) + // func (s *Server) handleAppBskyGraphMuteActor(ctx context.Context,body *appbskytypes.GraphMuteActor_Input) error + handleErr = s.handleAppBskyGraphMuteActor(ctx, &body) if handleErr != nil { return handleErr } return nil } -func (s *Server) HandleAppBskyGraphUnmute(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyGraphUnmute") +func (s *Server) HandleAppBskyGraphUnmuteActor(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyGraphUnmuteActor") defer span.End() - var body appbskytypes.GraphUnmute_Input + var body appbskytypes.GraphUnmuteActor_Input if err := c.Bind(&body); err != nil { return err } var handleErr error - // func (s *Server) handleAppBskyGraphUnmute(ctx context.Context,body *appbskytypes.GraphUnmute_Input) error - handleErr = s.handleAppBskyGraphUnmute(ctx, &body) + // func (s *Server) handleAppBskyGraphUnmuteActor(ctx context.Context,body *appbskytypes.GraphUnmuteActor_Input) error + handleErr = s.handleAppBskyGraphUnmuteActor(ctx, &body) if handleErr != nil { return handleErr } return nil } -func (s *Server) HandleAppBskyNotificationGetCount(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyNotificationGetCount") +func (s *Server) HandleAppBskyNotificationGetUnreadCount(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyNotificationGetUnreadCount") defer span.End() - var out *appbskytypes.NotificationGetCount_Output + var out *appbskytypes.NotificationGetUnreadCount_Output var handleErr error - // func (s *Server) handleAppBskyNotificationGetCount(ctx context.Context) (*appbskytypes.NotificationGetCount_Output, error) - out, handleErr = s.handleAppBskyNotificationGetCount(ctx) + // func (s *Server) handleAppBskyNotificationGetUnreadCount(ctx context.Context) (*appbskytypes.NotificationGetUnreadCount_Output, error) + out, handleErr = s.handleAppBskyNotificationGetUnreadCount(ctx) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleAppBskyNotificationList(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyNotificationList") +func (s *Server) HandleAppBskyNotificationListNotifications(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyNotificationListNotifications") defer span.End() - before := c.QueryParam("before") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -444,10 +406,10 @@ func (s *Server) HandleAppBskyNotificationList(c echo.Context) error { } else { limit = 50 } - var out *appbskytypes.NotificationList_Output + var out *appbskytypes.NotificationListNotifications_Output var handleErr error - // func (s *Server) handleAppBskyNotificationList(ctx context.Context,before string,limit int) (*appbskytypes.NotificationList_Output, error) - out, handleErr = s.handleAppBskyNotificationList(ctx, before, limit) + // func (s *Server) handleAppBskyNotificationListNotifications(ctx context.Context,cursor string,limit int) (*appbskytypes.NotificationListNotifications_Output, error) + out, handleErr = s.handleAppBskyNotificationListNotifications(ctx, cursor, limit) if handleErr != nil { return handleErr } @@ -471,14 +433,32 @@ func (s *Server) HandleAppBskyNotificationUpdateSeen(c echo.Context) error { return nil } +func (s *Server) HandleAppBskyUnspeccedGetPopular(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleAppBskyUnspeccedGetPopular") + defer span.End() + cursor := c.QueryParam("cursor") + + var limit int + if p := c.QueryParam("limit"); p != "" { + var err error + limit, err = strconv.Atoi(p) + if err != nil { + return err + } + } else { + limit = 50 + } + var out *appbskytypes.UnspeccedGetPopular_Output + var handleErr error + // func (s *Server) handleAppBskyUnspeccedGetPopular(ctx context.Context,cursor string,limit int) (*appbskytypes.UnspeccedGetPopular_Output, error) + out, handleErr = s.handleAppBskyUnspeccedGetPopular(ctx, cursor, limit) + if handleErr != nil { + return handleErr + } + return c.JSON(200, out) +} + func (s *Server) RegisterHandlersComAtproto(e *echo.Echo) error { - e.POST("/xrpc/com.atproto.account.create", s.HandleComAtprotoAccountCreate) - e.POST("/xrpc/com.atproto.account.createInviteCode", s.HandleComAtprotoAccountCreateInviteCode) - e.POST("/xrpc/com.atproto.account.delete", s.HandleComAtprotoAccountDelete) - e.GET("/xrpc/com.atproto.account.get", s.HandleComAtprotoAccountGet) - e.POST("/xrpc/com.atproto.account.requestDelete", s.HandleComAtprotoAccountRequestDelete) - e.POST("/xrpc/com.atproto.account.requestPasswordReset", s.HandleComAtprotoAccountRequestPasswordReset) - e.POST("/xrpc/com.atproto.account.resetPassword", s.HandleComAtprotoAccountResetPassword) e.GET("/xrpc/com.atproto.admin.getModerationAction", s.HandleComAtprotoAdminGetModerationAction) e.GET("/xrpc/com.atproto.admin.getModerationActions", s.HandleComAtprotoAdminGetModerationActions) e.GET("/xrpc/com.atproto.admin.getModerationReport", s.HandleComAtprotoAdminGetModerationReport) @@ -489,22 +469,28 @@ func (s *Server) RegisterHandlersComAtproto(e *echo.Echo) error { e.POST("/xrpc/com.atproto.admin.reverseModerationAction", s.HandleComAtprotoAdminReverseModerationAction) e.GET("/xrpc/com.atproto.admin.searchRepos", s.HandleComAtprotoAdminSearchRepos) e.POST("/xrpc/com.atproto.admin.takeModerationAction", s.HandleComAtprotoAdminTakeModerationAction) - e.POST("/xrpc/com.atproto.blob.upload", s.HandleComAtprotoBlobUpload) - e.GET("/xrpc/com.atproto.handle.resolve", s.HandleComAtprotoHandleResolve) - e.POST("/xrpc/com.atproto.handle.update", s.HandleComAtprotoHandleUpdate) - e.POST("/xrpc/com.atproto.repo.batchWrite", s.HandleComAtprotoRepoBatchWrite) + e.GET("/xrpc/com.atproto.identity.resolveHandle", s.HandleComAtprotoIdentityResolveHandle) + e.POST("/xrpc/com.atproto.identity.updateHandle", s.HandleComAtprotoIdentityUpdateHandle) + e.POST("/xrpc/com.atproto.moderation.createReport", s.HandleComAtprotoModerationCreateReport) + e.POST("/xrpc/com.atproto.repo.applyWrites", s.HandleComAtprotoRepoApplyWrites) e.POST("/xrpc/com.atproto.repo.createRecord", s.HandleComAtprotoRepoCreateRecord) e.POST("/xrpc/com.atproto.repo.deleteRecord", s.HandleComAtprotoRepoDeleteRecord) - e.GET("/xrpc/com.atproto.repo.describe", s.HandleComAtprotoRepoDescribe) + e.GET("/xrpc/com.atproto.repo.describeRepo", s.HandleComAtprotoRepoDescribeRepo) e.GET("/xrpc/com.atproto.repo.getRecord", s.HandleComAtprotoRepoGetRecord) e.GET("/xrpc/com.atproto.repo.listRecords", s.HandleComAtprotoRepoListRecords) e.POST("/xrpc/com.atproto.repo.putRecord", s.HandleComAtprotoRepoPutRecord) - e.POST("/xrpc/com.atproto.report.create", s.HandleComAtprotoReportCreate) - e.GET("/xrpc/com.atproto.server.getAccountsConfig", s.HandleComAtprotoServerGetAccountsConfig) - e.POST("/xrpc/com.atproto.session.create", s.HandleComAtprotoSessionCreate) - e.POST("/xrpc/com.atproto.session.delete", s.HandleComAtprotoSessionDelete) - e.GET("/xrpc/com.atproto.session.get", s.HandleComAtprotoSessionGet) - e.POST("/xrpc/com.atproto.session.refresh", s.HandleComAtprotoSessionRefresh) + e.POST("/xrpc/com.atproto.repo.uploadBlob", s.HandleComAtprotoRepoUploadBlob) + e.POST("/xrpc/com.atproto.server.createAccount", s.HandleComAtprotoServerCreateAccount) + e.POST("/xrpc/com.atproto.server.createInviteCode", s.HandleComAtprotoServerCreateInviteCode) + e.POST("/xrpc/com.atproto.server.createSession", s.HandleComAtprotoServerCreateSession) + e.POST("/xrpc/com.atproto.server.deleteAccount", s.HandleComAtprotoServerDeleteAccount) + e.POST("/xrpc/com.atproto.server.deleteSession", s.HandleComAtprotoServerDeleteSession) + e.GET("/xrpc/com.atproto.server.describeServer", s.HandleComAtprotoServerDescribeServer) + e.GET("/xrpc/com.atproto.server.getSession", s.HandleComAtprotoServerGetSession) + e.POST("/xrpc/com.atproto.server.refreshSession", s.HandleComAtprotoServerRefreshSession) + e.POST("/xrpc/com.atproto.server.requestAccountDelete", s.HandleComAtprotoServerRequestAccountDelete) + e.POST("/xrpc/com.atproto.server.requestPasswordReset", s.HandleComAtprotoServerRequestPasswordReset) + e.POST("/xrpc/com.atproto.server.resetPassword", s.HandleComAtprotoServerResetPassword) e.GET("/xrpc/com.atproto.sync.getBlob", s.HandleComAtprotoSyncGetBlob) e.GET("/xrpc/com.atproto.sync.getBlocks", s.HandleComAtprotoSyncGetBlocks) e.GET("/xrpc/com.atproto.sync.getCheckout", s.HandleComAtprotoSyncGetCheckout) @@ -518,117 +504,6 @@ func (s *Server) RegisterHandlersComAtproto(e *echo.Echo) error { return nil } -func (s *Server) HandleComAtprotoAccountCreate(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAccountCreate") - defer span.End() - - var body comatprototypes.AccountCreate_Input - if err := c.Bind(&body); err != nil { - return err - } - var out *comatprototypes.AccountCreate_Output - var handleErr error - // func (s *Server) handleComAtprotoAccountCreate(ctx context.Context,body *comatprototypes.AccountCreate_Input) (*comatprototypes.AccountCreate_Output, error) - out, handleErr = s.handleComAtprotoAccountCreate(ctx, &body) - if handleErr != nil { - return handleErr - } - return c.JSON(200, out) -} - -func (s *Server) HandleComAtprotoAccountCreateInviteCode(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAccountCreateInviteCode") - defer span.End() - - var body comatprototypes.AccountCreateInviteCode_Input - if err := c.Bind(&body); err != nil { - return err - } - var out *comatprototypes.AccountCreateInviteCode_Output - var handleErr error - // func (s *Server) handleComAtprotoAccountCreateInviteCode(ctx context.Context,body *comatprototypes.AccountCreateInviteCode_Input) (*comatprototypes.AccountCreateInviteCode_Output, error) - out, handleErr = s.handleComAtprotoAccountCreateInviteCode(ctx, &body) - if handleErr != nil { - return handleErr - } - return c.JSON(200, out) -} - -func (s *Server) HandleComAtprotoAccountDelete(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAccountDelete") - defer span.End() - - var body comatprototypes.AccountDelete_Input - if err := c.Bind(&body); err != nil { - return err - } - var handleErr error - // func (s *Server) handleComAtprotoAccountDelete(ctx context.Context,body *comatprototypes.AccountDelete_Input) error - handleErr = s.handleComAtprotoAccountDelete(ctx, &body) - if handleErr != nil { - return handleErr - } - return nil -} - -func (s *Server) HandleComAtprotoAccountGet(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAccountGet") - defer span.End() - var handleErr error - // func (s *Server) handleComAtprotoAccountGet(ctx context.Context) error - handleErr = s.handleComAtprotoAccountGet(ctx) - if handleErr != nil { - return handleErr - } - return nil -} - -func (s *Server) HandleComAtprotoAccountRequestDelete(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAccountRequestDelete") - defer span.End() - var handleErr error - // func (s *Server) handleComAtprotoAccountRequestDelete(ctx context.Context) error - handleErr = s.handleComAtprotoAccountRequestDelete(ctx) - if handleErr != nil { - return handleErr - } - return nil -} - -func (s *Server) HandleComAtprotoAccountRequestPasswordReset(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAccountRequestPasswordReset") - defer span.End() - - var body comatprototypes.AccountRequestPasswordReset_Input - if err := c.Bind(&body); err != nil { - return err - } - var handleErr error - // func (s *Server) handleComAtprotoAccountRequestPasswordReset(ctx context.Context,body *comatprototypes.AccountRequestPasswordReset_Input) error - handleErr = s.handleComAtprotoAccountRequestPasswordReset(ctx, &body) - if handleErr != nil { - return handleErr - } - return nil -} - -func (s *Server) HandleComAtprotoAccountResetPassword(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAccountResetPassword") - defer span.End() - - var body comatprototypes.AccountResetPassword_Input - if err := c.Bind(&body); err != nil { - return err - } - var handleErr error - // func (s *Server) handleComAtprotoAccountResetPassword(ctx context.Context,body *comatprototypes.AccountResetPassword_Input) error - handleErr = s.handleComAtprotoAccountResetPassword(ctx, &body) - if handleErr != nil { - return handleErr - } - return nil -} - func (s *Server) HandleComAtprotoAdminGetModerationAction(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAdminGetModerationAction") defer span.End() @@ -637,9 +512,9 @@ func (s *Server) HandleComAtprotoAdminGetModerationAction(c echo.Context) error if err != nil { return err } - var out *comatprototypes.AdminModerationAction_ViewDetail + var out *comatprototypes.AdminDefs_ActionViewDetail var handleErr error - // func (s *Server) handleComAtprotoAdminGetModerationAction(ctx context.Context,id int) (*comatprototypes.AdminModerationAction_ViewDetail, error) + // func (s *Server) handleComAtprotoAdminGetModerationAction(ctx context.Context,id int) (*comatprototypes.AdminDefs_ActionViewDetail, error) out, handleErr = s.handleComAtprotoAdminGetModerationAction(ctx, id) if handleErr != nil { return handleErr @@ -650,7 +525,7 @@ func (s *Server) HandleComAtprotoAdminGetModerationAction(c echo.Context) error func (s *Server) HandleComAtprotoAdminGetModerationActions(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAdminGetModerationActions") defer span.End() - before := c.QueryParam("before") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -665,8 +540,8 @@ func (s *Server) HandleComAtprotoAdminGetModerationActions(c echo.Context) error subject := c.QueryParam("subject") var out *comatprototypes.AdminGetModerationActions_Output var handleErr error - // func (s *Server) handleComAtprotoAdminGetModerationActions(ctx context.Context,before string,limit int,subject string) (*comatprototypes.AdminGetModerationActions_Output, error) - out, handleErr = s.handleComAtprotoAdminGetModerationActions(ctx, before, limit, subject) + // func (s *Server) handleComAtprotoAdminGetModerationActions(ctx context.Context,cursor string,limit int,subject string) (*comatprototypes.AdminGetModerationActions_Output, error) + out, handleErr = s.handleComAtprotoAdminGetModerationActions(ctx, cursor, limit, subject) if handleErr != nil { return handleErr } @@ -681,9 +556,9 @@ func (s *Server) HandleComAtprotoAdminGetModerationReport(c echo.Context) error if err != nil { return err } - var out *comatprototypes.AdminModerationReport_ViewDetail + var out *comatprototypes.AdminDefs_ReportViewDetail var handleErr error - // func (s *Server) handleComAtprotoAdminGetModerationReport(ctx context.Context,id int) (*comatprototypes.AdminModerationReport_ViewDetail, error) + // func (s *Server) handleComAtprotoAdminGetModerationReport(ctx context.Context,id int) (*comatprototypes.AdminDefs_ReportViewDetail, error) out, handleErr = s.handleComAtprotoAdminGetModerationReport(ctx, id) if handleErr != nil { return handleErr @@ -694,7 +569,7 @@ func (s *Server) HandleComAtprotoAdminGetModerationReport(c echo.Context) error func (s *Server) HandleComAtprotoAdminGetModerationReports(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAdminGetModerationReports") defer span.End() - before := c.QueryParam("before") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -718,8 +593,8 @@ func (s *Server) HandleComAtprotoAdminGetModerationReports(c echo.Context) error subject := c.QueryParam("subject") var out *comatprototypes.AdminGetModerationReports_Output var handleErr error - // func (s *Server) handleComAtprotoAdminGetModerationReports(ctx context.Context,before string,limit int,resolved *bool,subject string) (*comatprototypes.AdminGetModerationReports_Output, error) - out, handleErr = s.handleComAtprotoAdminGetModerationReports(ctx, before, limit, resolved, subject) + // func (s *Server) handleComAtprotoAdminGetModerationReports(ctx context.Context,cursor string,limit int,resolved *bool,subject string) (*comatprototypes.AdminGetModerationReports_Output, error) + out, handleErr = s.handleComAtprotoAdminGetModerationReports(ctx, cursor, limit, resolved, subject) if handleErr != nil { return handleErr } @@ -731,9 +606,9 @@ func (s *Server) HandleComAtprotoAdminGetRecord(c echo.Context) error { defer span.End() cid := c.QueryParam("cid") uri := c.QueryParam("uri") - var out *comatprototypes.AdminRecord_ViewDetail + var out *comatprototypes.AdminDefs_RecordViewDetail var handleErr error - // func (s *Server) handleComAtprotoAdminGetRecord(ctx context.Context,cid string,uri string) (*comatprototypes.AdminRecord_ViewDetail, error) + // func (s *Server) handleComAtprotoAdminGetRecord(ctx context.Context,cid string,uri string) (*comatprototypes.AdminDefs_RecordViewDetail, error) out, handleErr = s.handleComAtprotoAdminGetRecord(ctx, cid, uri) if handleErr != nil { return handleErr @@ -745,9 +620,9 @@ func (s *Server) HandleComAtprotoAdminGetRepo(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAdminGetRepo") defer span.End() did := c.QueryParam("did") - var out *comatprototypes.AdminRepo_ViewDetail + var out *comatprototypes.AdminDefs_RepoViewDetail var handleErr error - // func (s *Server) handleComAtprotoAdminGetRepo(ctx context.Context,did string) (*comatprototypes.AdminRepo_ViewDetail, error) + // func (s *Server) handleComAtprotoAdminGetRepo(ctx context.Context,did string) (*comatprototypes.AdminDefs_RepoViewDetail, error) out, handleErr = s.handleComAtprotoAdminGetRepo(ctx, did) if handleErr != nil { return handleErr @@ -763,9 +638,9 @@ func (s *Server) HandleComAtprotoAdminResolveModerationReports(c echo.Context) e if err := c.Bind(&body); err != nil { return err } - var out *comatprototypes.AdminModerationAction_View + var out *comatprototypes.AdminDefs_ActionView var handleErr error - // func (s *Server) handleComAtprotoAdminResolveModerationReports(ctx context.Context,body *comatprototypes.AdminResolveModerationReports_Input) (*comatprototypes.AdminModerationAction_View, error) + // func (s *Server) handleComAtprotoAdminResolveModerationReports(ctx context.Context,body *comatprototypes.AdminResolveModerationReports_Input) (*comatprototypes.AdminDefs_ActionView, error) out, handleErr = s.handleComAtprotoAdminResolveModerationReports(ctx, &body) if handleErr != nil { return handleErr @@ -781,9 +656,9 @@ func (s *Server) HandleComAtprotoAdminReverseModerationAction(c echo.Context) er if err := c.Bind(&body); err != nil { return err } - var out *comatprototypes.AdminModerationAction_View + var out *comatprototypes.AdminDefs_ActionView var handleErr error - // func (s *Server) handleComAtprotoAdminReverseModerationAction(ctx context.Context,body *comatprototypes.AdminReverseModerationAction_Input) (*comatprototypes.AdminModerationAction_View, error) + // func (s *Server) handleComAtprotoAdminReverseModerationAction(ctx context.Context,body *comatprototypes.AdminReverseModerationAction_Input) (*comatprototypes.AdminDefs_ActionView, error) out, handleErr = s.handleComAtprotoAdminReverseModerationAction(ctx, &body) if handleErr != nil { return handleErr @@ -794,7 +669,7 @@ func (s *Server) HandleComAtprotoAdminReverseModerationAction(c echo.Context) er func (s *Server) HandleComAtprotoAdminSearchRepos(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoAdminSearchRepos") defer span.End() - before := c.QueryParam("before") + cursor := c.QueryParam("cursor") var limit int if p := c.QueryParam("limit"); p != "" { @@ -809,8 +684,8 @@ func (s *Server) HandleComAtprotoAdminSearchRepos(c echo.Context) error { term := c.QueryParam("term") var out *comatprototypes.AdminSearchRepos_Output var handleErr error - // func (s *Server) handleComAtprotoAdminSearchRepos(ctx context.Context,before string,limit int,term string) (*comatprototypes.AdminSearchRepos_Output, error) - out, handleErr = s.handleComAtprotoAdminSearchRepos(ctx, before, limit, term) + // func (s *Server) handleComAtprotoAdminSearchRepos(ctx context.Context,cursor string,limit int,term string) (*comatprototypes.AdminSearchRepos_Output, error) + out, handleErr = s.handleComAtprotoAdminSearchRepos(ctx, cursor, limit, term) if handleErr != nil { return handleErr } @@ -825,9 +700,9 @@ func (s *Server) HandleComAtprotoAdminTakeModerationAction(c echo.Context) error if err := c.Bind(&body); err != nil { return err } - var out *comatprototypes.AdminModerationAction_View + var out *comatprototypes.AdminDefs_ActionView var handleErr error - // func (s *Server) handleComAtprotoAdminTakeModerationAction(ctx context.Context,body *comatprototypes.AdminTakeModerationAction_Input) (*comatprototypes.AdminModerationAction_View, error) + // func (s *Server) handleComAtprotoAdminTakeModerationAction(ctx context.Context,body *comatprototypes.AdminTakeModerationAction_Input) (*comatprototypes.AdminDefs_ActionView, error) out, handleErr = s.handleComAtprotoAdminTakeModerationAction(ctx, &body) if handleErr != nil { return handleErr @@ -835,63 +710,66 @@ func (s *Server) HandleComAtprotoAdminTakeModerationAction(c echo.Context) error return c.JSON(200, out) } -func (s *Server) HandleComAtprotoBlobUpload(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoBlobUpload") +func (s *Server) HandleComAtprotoIdentityResolveHandle(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoIdentityResolveHandle") defer span.End() - body := c.Request().Body - contentType := c.Request().Header.Get("Content-Type") - var out *comatprototypes.BlobUpload_Output + handle := c.QueryParam("handle") + var out *comatprototypes.IdentityResolveHandle_Output var handleErr error - // func (s *Server) handleComAtprotoBlobUpload(ctx context.Context,r io.Reader,contentType string) (*comatprototypes.BlobUpload_Output, error) - out, handleErr = s.handleComAtprotoBlobUpload(ctx, body, contentType) + // func (s *Server) handleComAtprotoIdentityResolveHandle(ctx context.Context,handle string) (*comatprototypes.IdentityResolveHandle_Output, error) + out, handleErr = s.handleComAtprotoIdentityResolveHandle(ctx, handle) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleComAtprotoHandleResolve(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoHandleResolve") +func (s *Server) HandleComAtprotoIdentityUpdateHandle(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoIdentityUpdateHandle") defer span.End() - handle := c.QueryParam("handle") - var out *comatprototypes.HandleResolve_Output + + var body comatprototypes.IdentityUpdateHandle_Input + if err := c.Bind(&body); err != nil { + return err + } var handleErr error - // func (s *Server) handleComAtprotoHandleResolve(ctx context.Context,handle string) (*comatprototypes.HandleResolve_Output, error) - out, handleErr = s.handleComAtprotoHandleResolve(ctx, handle) + // func (s *Server) handleComAtprotoIdentityUpdateHandle(ctx context.Context,body *comatprototypes.IdentityUpdateHandle_Input) error + handleErr = s.handleComAtprotoIdentityUpdateHandle(ctx, &body) if handleErr != nil { return handleErr } - return c.JSON(200, out) + return nil } -func (s *Server) HandleComAtprotoHandleUpdate(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoHandleUpdate") +func (s *Server) HandleComAtprotoModerationCreateReport(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoModerationCreateReport") defer span.End() - var body comatprototypes.HandleUpdate_Input + var body comatprototypes.ModerationCreateReport_Input if err := c.Bind(&body); err != nil { return err } + var out *comatprototypes.ModerationCreateReport_Output var handleErr error - // func (s *Server) handleComAtprotoHandleUpdate(ctx context.Context,body *comatprototypes.HandleUpdate_Input) error - handleErr = s.handleComAtprotoHandleUpdate(ctx, &body) + // func (s *Server) handleComAtprotoModerationCreateReport(ctx context.Context,body *comatprototypes.ModerationCreateReport_Input) (*comatprototypes.ModerationCreateReport_Output, error) + out, handleErr = s.handleComAtprotoModerationCreateReport(ctx, &body) if handleErr != nil { return handleErr } - return nil + return c.JSON(200, out) } -func (s *Server) HandleComAtprotoRepoBatchWrite(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoBatchWrite") +func (s *Server) HandleComAtprotoRepoApplyWrites(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoApplyWrites") defer span.End() - var body comatprototypes.RepoBatchWrite_Input + var body comatprototypes.RepoApplyWrites_Input if err := c.Bind(&body); err != nil { return err } var handleErr error - // func (s *Server) handleComAtprotoRepoBatchWrite(ctx context.Context,body *comatprototypes.RepoBatchWrite_Input) error - handleErr = s.handleComAtprotoRepoBatchWrite(ctx, &body) + // func (s *Server) handleComAtprotoRepoApplyWrites(ctx context.Context,body *comatprototypes.RepoApplyWrites_Input) error + handleErr = s.handleComAtprotoRepoApplyWrites(ctx, &body) if handleErr != nil { return handleErr } @@ -933,14 +811,14 @@ func (s *Server) HandleComAtprotoRepoDeleteRecord(c echo.Context) error { return nil } -func (s *Server) HandleComAtprotoRepoDescribe(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoDescribe") +func (s *Server) HandleComAtprotoRepoDescribeRepo(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoDescribeRepo") defer span.End() - user := c.QueryParam("user") - var out *comatprototypes.RepoDescribe_Output + repo := c.QueryParam("repo") + var out *comatprototypes.RepoDescribeRepo_Output var handleErr error - // func (s *Server) handleComAtprotoRepoDescribe(ctx context.Context,user string) (*comatprototypes.RepoDescribe_Output, error) - out, handleErr = s.handleComAtprotoRepoDescribe(ctx, user) + // func (s *Server) handleComAtprotoRepoDescribeRepo(ctx context.Context,repo string) (*comatprototypes.RepoDescribeRepo_Output, error) + out, handleErr = s.handleComAtprotoRepoDescribeRepo(ctx, repo) if handleErr != nil { return handleErr } @@ -952,12 +830,12 @@ func (s *Server) HandleComAtprotoRepoGetRecord(c echo.Context) error { defer span.End() cid := c.QueryParam("cid") collection := c.QueryParam("collection") + repo := c.QueryParam("repo") rkey := c.QueryParam("rkey") - user := c.QueryParam("user") var out *comatprototypes.RepoGetRecord_Output var handleErr error - // func (s *Server) handleComAtprotoRepoGetRecord(ctx context.Context,cid string,collection string,rkey string,user string) (*comatprototypes.RepoGetRecord_Output, error) - out, handleErr = s.handleComAtprotoRepoGetRecord(ctx, cid, collection, rkey, user) + // func (s *Server) handleComAtprotoRepoGetRecord(ctx context.Context,cid string,collection string,repo string,rkey string) (*comatprototypes.RepoGetRecord_Output, error) + out, handleErr = s.handleComAtprotoRepoGetRecord(ctx, cid, collection, repo, rkey) if handleErr != nil { return handleErr } @@ -967,8 +845,6 @@ func (s *Server) HandleComAtprotoRepoGetRecord(c echo.Context) error { func (s *Server) HandleComAtprotoRepoListRecords(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoListRecords") defer span.End() - after := c.QueryParam("after") - before := c.QueryParam("before") collection := c.QueryParam("collection") var limit int @@ -981,6 +857,7 @@ func (s *Server) HandleComAtprotoRepoListRecords(c echo.Context) error { } else { limit = 50 } + repo := c.QueryParam("repo") var reverse *bool if p := c.QueryParam("reverse"); p != "" { @@ -990,11 +867,12 @@ func (s *Server) HandleComAtprotoRepoListRecords(c echo.Context) error { } reverse = &reverse_val } - user := c.QueryParam("user") + rkeyEnd := c.QueryParam("rkeyEnd") + rkeyStart := c.QueryParam("rkeyStart") var out *comatprototypes.RepoListRecords_Output var handleErr error - // func (s *Server) handleComAtprotoRepoListRecords(ctx context.Context,after string,before string,collection string,limit int,reverse *bool,user string) (*comatprototypes.RepoListRecords_Output, error) - out, handleErr = s.handleComAtprotoRepoListRecords(ctx, after, before, collection, limit, reverse, user) + // func (s *Server) handleComAtprotoRepoListRecords(ctx context.Context,collection string,limit int,repo string,reverse *bool,rkeyEnd string,rkeyStart string) (*comatprototypes.RepoListRecords_Output, error) + out, handleErr = s.handleComAtprotoRepoListRecords(ctx, collection, limit, repo, reverse, rkeyEnd, rkeyStart) if handleErr != nil { return handleErr } @@ -1019,93 +897,189 @@ func (s *Server) HandleComAtprotoRepoPutRecord(c echo.Context) error { return c.JSON(200, out) } -func (s *Server) HandleComAtprotoReportCreate(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoReportCreate") +func (s *Server) HandleComAtprotoRepoUploadBlob(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoRepoUploadBlob") + defer span.End() + body := c.Request().Body + contentType := c.Request().Header.Get("Content-Type") + var out *comatprototypes.RepoUploadBlob_Output + var handleErr error + // func (s *Server) handleComAtprotoRepoUploadBlob(ctx context.Context,r io.Reader,contentType string) (*comatprototypes.RepoUploadBlob_Output, error) + out, handleErr = s.handleComAtprotoRepoUploadBlob(ctx, body, contentType) + if handleErr != nil { + return handleErr + } + return c.JSON(200, out) +} + +func (s *Server) HandleComAtprotoServerCreateAccount(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerCreateAccount") defer span.End() - var body comatprototypes.ReportCreate_Input + var body comatprototypes.ServerCreateAccount_Input if err := c.Bind(&body); err != nil { return err } - var out *comatprototypes.ReportCreate_Output + var out *comatprototypes.ServerCreateAccount_Output var handleErr error - // func (s *Server) handleComAtprotoReportCreate(ctx context.Context,body *comatprototypes.ReportCreate_Input) (*comatprototypes.ReportCreate_Output, error) - out, handleErr = s.handleComAtprotoReportCreate(ctx, &body) + // func (s *Server) handleComAtprotoServerCreateAccount(ctx context.Context,body *comatprototypes.ServerCreateAccount_Input) (*comatprototypes.ServerCreateAccount_Output, error) + out, handleErr = s.handleComAtprotoServerCreateAccount(ctx, &body) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleComAtprotoServerGetAccountsConfig(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerGetAccountsConfig") +func (s *Server) HandleComAtprotoServerCreateInviteCode(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerCreateInviteCode") defer span.End() - var out *comatprototypes.ServerGetAccountsConfig_Output + + var body comatprototypes.ServerCreateInviteCode_Input + if err := c.Bind(&body); err != nil { + return err + } + var out *comatprototypes.ServerCreateInviteCode_Output var handleErr error - // func (s *Server) handleComAtprotoServerGetAccountsConfig(ctx context.Context) (*comatprototypes.ServerGetAccountsConfig_Output, error) - out, handleErr = s.handleComAtprotoServerGetAccountsConfig(ctx) + // func (s *Server) handleComAtprotoServerCreateInviteCode(ctx context.Context,body *comatprototypes.ServerCreateInviteCode_Input) (*comatprototypes.ServerCreateInviteCode_Output, error) + out, handleErr = s.handleComAtprotoServerCreateInviteCode(ctx, &body) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleComAtprotoSessionCreate(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSessionCreate") +func (s *Server) HandleComAtprotoServerCreateSession(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerCreateSession") defer span.End() - var body comatprototypes.SessionCreate_Input + var body comatprototypes.ServerCreateSession_Input if err := c.Bind(&body); err != nil { return err } - var out *comatprototypes.SessionCreate_Output + var out *comatprototypes.ServerCreateSession_Output var handleErr error - // func (s *Server) handleComAtprotoSessionCreate(ctx context.Context,body *comatprototypes.SessionCreate_Input) (*comatprototypes.SessionCreate_Output, error) - out, handleErr = s.handleComAtprotoSessionCreate(ctx, &body) + // func (s *Server) handleComAtprotoServerCreateSession(ctx context.Context,body *comatprototypes.ServerCreateSession_Input) (*comatprototypes.ServerCreateSession_Output, error) + out, handleErr = s.handleComAtprotoServerCreateSession(ctx, &body) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleComAtprotoSessionDelete(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSessionDelete") +func (s *Server) HandleComAtprotoServerDeleteAccount(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerDeleteAccount") + defer span.End() + + var body comatprototypes.ServerDeleteAccount_Input + if err := c.Bind(&body); err != nil { + return err + } + var handleErr error + // func (s *Server) handleComAtprotoServerDeleteAccount(ctx context.Context,body *comatprototypes.ServerDeleteAccount_Input) error + handleErr = s.handleComAtprotoServerDeleteAccount(ctx, &body) + if handleErr != nil { + return handleErr + } + return nil +} + +func (s *Server) HandleComAtprotoServerDeleteSession(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerDeleteSession") defer span.End() var handleErr error - // func (s *Server) handleComAtprotoSessionDelete(ctx context.Context) error - handleErr = s.handleComAtprotoSessionDelete(ctx) + // func (s *Server) handleComAtprotoServerDeleteSession(ctx context.Context) error + handleErr = s.handleComAtprotoServerDeleteSession(ctx) if handleErr != nil { return handleErr } return nil } -func (s *Server) HandleComAtprotoSessionGet(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSessionGet") +func (s *Server) HandleComAtprotoServerDescribeServer(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerDescribeServer") defer span.End() - var out *comatprototypes.SessionGet_Output + var out *comatprototypes.ServerDescribeServer_Output var handleErr error - // func (s *Server) handleComAtprotoSessionGet(ctx context.Context) (*comatprototypes.SessionGet_Output, error) - out, handleErr = s.handleComAtprotoSessionGet(ctx) + // func (s *Server) handleComAtprotoServerDescribeServer(ctx context.Context) (*comatprototypes.ServerDescribeServer_Output, error) + out, handleErr = s.handleComAtprotoServerDescribeServer(ctx) if handleErr != nil { return handleErr } return c.JSON(200, out) } -func (s *Server) HandleComAtprotoSessionRefresh(c echo.Context) error { - ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSessionRefresh") +func (s *Server) HandleComAtprotoServerGetSession(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerGetSession") defer span.End() - var out *comatprototypes.SessionRefresh_Output + var out *comatprototypes.ServerGetSession_Output var handleErr error - // func (s *Server) handleComAtprotoSessionRefresh(ctx context.Context) (*comatprototypes.SessionRefresh_Output, error) - out, handleErr = s.handleComAtprotoSessionRefresh(ctx) + // func (s *Server) handleComAtprotoServerGetSession(ctx context.Context) (*comatprototypes.ServerGetSession_Output, error) + out, handleErr = s.handleComAtprotoServerGetSession(ctx) if handleErr != nil { return handleErr } return c.JSON(200, out) } +func (s *Server) HandleComAtprotoServerRefreshSession(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerRefreshSession") + defer span.End() + var out *comatprototypes.ServerRefreshSession_Output + var handleErr error + // func (s *Server) handleComAtprotoServerRefreshSession(ctx context.Context) (*comatprototypes.ServerRefreshSession_Output, error) + out, handleErr = s.handleComAtprotoServerRefreshSession(ctx) + if handleErr != nil { + return handleErr + } + return c.JSON(200, out) +} + +func (s *Server) HandleComAtprotoServerRequestAccountDelete(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerRequestAccountDelete") + defer span.End() + var handleErr error + // func (s *Server) handleComAtprotoServerRequestAccountDelete(ctx context.Context) error + handleErr = s.handleComAtprotoServerRequestAccountDelete(ctx) + if handleErr != nil { + return handleErr + } + return nil +} + +func (s *Server) HandleComAtprotoServerRequestPasswordReset(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerRequestPasswordReset") + defer span.End() + + var body comatprototypes.ServerRequestPasswordReset_Input + if err := c.Bind(&body); err != nil { + return err + } + var handleErr error + // func (s *Server) handleComAtprotoServerRequestPasswordReset(ctx context.Context,body *comatprototypes.ServerRequestPasswordReset_Input) error + handleErr = s.handleComAtprotoServerRequestPasswordReset(ctx, &body) + if handleErr != nil { + return handleErr + } + return nil +} + +func (s *Server) HandleComAtprotoServerResetPassword(c echo.Context) error { + ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoServerResetPassword") + defer span.End() + + var body comatprototypes.ServerResetPassword_Input + if err := c.Bind(&body); err != nil { + return err + } + var handleErr error + // func (s *Server) handleComAtprotoServerResetPassword(ctx context.Context,body *comatprototypes.ServerResetPassword_Input) error + handleErr = s.handleComAtprotoServerResetPassword(ctx, &body) + if handleErr != nil { + return handleErr + } + return nil +} + func (s *Server) HandleComAtprotoSyncGetBlob(c echo.Context) error { ctx, span := otel.Tracer("server").Start(c.Request().Context(), "HandleComAtprotoSyncGetBlob") defer span.End() diff --git a/pds/type_helpers.go b/pds/type_helpers.go new file mode 100644 index 000000000..acbeef28d --- /dev/null +++ b/pds/type_helpers.go @@ -0,0 +1,22 @@ +package pds + +import ( + "context" + + appbsky "github.com/bluesky-social/indigo/api/bsky" +) + +// TODO: this is a quick helper to transform bsky.ActorDefs_ProfileViewBasic to +// bsky.ActorDefs_ProfileView, written during the lexicon refactor (March +// 2023). It probably needs to be updated to actually populate all the +// additional fields (eg, via additional database queries) +func (s *Server) actorBasicToView(ctx context.Context, basic *appbsky.ActorDefs_ProfileViewBasic) *appbsky.ActorDefs_ProfileView { + view := &appbsky.ActorDefs_ProfileView{ + Avatar: basic.Avatar, + Did: basic.Did, + DisplayName: basic.DisplayName, + Handle: basic.Handle, + Viewer: basic.Viewer, + } + return view +} diff --git a/repomgr/repomgr.go b/repomgr/repomgr.go index c23288dc4..9e959667e 100644 --- a/repomgr/repomgr.go +++ b/repomgr/repomgr.go @@ -66,7 +66,6 @@ type ActorInfo struct { Did string Handle string DisplayName string - DeclRefCid string Type string } @@ -395,7 +394,7 @@ func (rm *RepoManager) InitNewActor(ctx context.Context, user util.Uid, handle, r := repo.NewRepo(ctx, did, ds) profile := &bsky.ActorProfile{ - DisplayName: displayname, + DisplayName: &displayname, } _, err = r.PutRecord(ctx, "app.bsky.actor.profile/self", profile) @@ -403,20 +402,6 @@ func (rm *RepoManager) InitNewActor(ctx context.Context, user util.Uid, handle, return fmt.Errorf("setting initial actor profile: %w", err) } - decl := &bsky.SystemDeclaration{ - ActorType: actortype, - } - dc, err := r.PutRecord(ctx, "app.bsky.system.declaration/self", decl) - if err != nil { - return fmt.Errorf("setting initial actor profile: %w", err) - } - - if dc.String() != declcid { - log.Warn("DECL CID MISMATCH: ", dc, declcid) - } - - // TODO: set declaration? - root, err := r.Commit(ctx, rm.kmgr.SignForUser) if err != nil { return fmt.Errorf("committing repo for actor init: %w", err) @@ -444,7 +429,6 @@ func (rm *RepoManager) InitNewActor(ctx context.Context, user util.Uid, handle, Did: did, Handle: handle, DisplayName: displayname, - DeclRefCid: declcid, Type: actortype, }, }}, @@ -585,7 +569,6 @@ func (rm *RepoManager) HandleExternalUserEvent(ctx context.Context, pdsid uint, Did: ai.Did, Handle: ai.Handle, DisplayName: ai.DisplayName, - DeclRefCid: ai.DeclRefCid, Type: ai.Type, }, }) @@ -624,7 +607,6 @@ func (rm *RepoManager) HandleExternalUserEvent(ctx context.Context, pdsid uint, Did: ai.Did, Handle: ai.Handle, DisplayName: ai.DisplayName, - DeclRefCid: ai.DeclRefCid, Type: ai.Type, }, }) @@ -681,7 +663,7 @@ func rkeyForCollection(collection string) string { return repo.NextTID() } -func (rm *RepoManager) BatchWrite(ctx context.Context, user util.Uid, writes []*atproto.RepoBatchWrite_Input_Writes_Elem) error { +func (rm *RepoManager) BatchWrite(ctx context.Context, user util.Uid, writes []*atproto.RepoApplyWrites_Input_Writes_Elem) error { ctx, span := otel.Tracer("repoman").Start(ctx, "BatchWrite") defer span.End() @@ -706,8 +688,8 @@ func (rm *RepoManager) BatchWrite(ctx context.Context, user util.Uid, writes []* var ops []RepoOp for _, w := range writes { switch { - case w.RepoBatchWrite_Create != nil: - c := w.RepoBatchWrite_Create + case w.RepoApplyWrites_Create != nil: + c := w.RepoApplyWrites_Create var rkey string if c.Rkey != nil { rkey = *c.Rkey @@ -728,8 +710,8 @@ func (rm *RepoManager) BatchWrite(ctx context.Context, user util.Uid, writes []* RecCid: &cc, Record: c.Value.Val, }) - case w.RepoBatchWrite_Update != nil: - u := w.RepoBatchWrite_Update + case w.RepoApplyWrites_Update != nil: + u := w.RepoApplyWrites_Update cc, err := r.PutRecord(ctx, u.Collection+"/"+u.Rkey, u.Value.Val) if err != nil { @@ -743,8 +725,8 @@ func (rm *RepoManager) BatchWrite(ctx context.Context, user util.Uid, writes []* RecCid: &cc, Record: u.Value.Val, }) - case w.RepoBatchWrite_Delete != nil: - d := w.RepoBatchWrite_Delete + case w.RepoApplyWrites_Delete != nil: + d := w.RepoApplyWrites_Delete if err := r.DeleteRecord(ctx, d.Collection+"/"+d.Rkey); err != nil { return err @@ -833,7 +815,7 @@ func (rm *RepoManager) ImportNewRepo(ctx context.Context, user util.Uid, repoDid return fmt.Errorf("commit serialization failed: %w", err) } if err := rm.kmgr.VerifyUserSignature(ctx, repoDid, scom.Sig, sb); err != nil { - return fmt.Errorf("signature check failed: %w", err) + return fmt.Errorf("new user signature check failed: %w", err) } diffops, err := r.DiffSince(ctx, old) @@ -1077,6 +1059,10 @@ func walkTree(ctx context.Context, skip map[cid.Cid]bool, root cid.Cid, bs block var links []cid.Cid if err := cbg.ScanForLinks(bytes.NewReader(blk.RawData()), func(c cid.Cid) { + if c.Prefix().Codec == cid.Raw { + log.Debugw("skipping 'raw' CID in record", "recordCid", root, "rawCid", c) + return + } if skip[c] { return } diff --git a/testing/feedpost_test.go b/testing/feedpost_test.go new file mode 100644 index 000000000..09068a49d --- /dev/null +++ b/testing/feedpost_test.go @@ -0,0 +1,125 @@ +package testing + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "os" + "testing" + + comatproto "github.com/bluesky-social/indigo/api/atproto" + appbsky "github.com/bluesky-social/indigo/api/bsky" + lexutil "github.com/bluesky-social/indigo/lex/util" + "github.com/ipfs/go-cid" + + "github.com/stretchr/testify/assert" +) + +func TestFeedPostParse(t *testing.T) { + assert := assert.New(t) + + // this is a post-lex-refactor app.bsky.feed.post record + inFile, err := os.Open("test_files/feedpost_record.cbor") + assert.NoError(err) + cborBytes, err := io.ReadAll(inFile) + assert.NoError(err) + + var fp appbsky.FeedPost + assert.NoError(fp.UnmarshalCBOR(bytes.NewReader(cborBytes))) + + assert.Equal("app.bsky.feed.post", fp.LexiconTypeID) + assert.Equal("Who the hell do you think you are", fp.Text) + assert.Equal("2023-03-29T20:59:19.417Z", fp.CreatedAt) + assert.Nil(fp.Entities) + assert.Nil(fp.Facets) + assert.Nil(fp.Reply) + assert.Nil(fp.Embed.EmbedImages) + assert.Nil(fp.Embed.EmbedExternal) + assert.Nil(fp.Embed.EmbedRecord) + assert.NotNil(fp.Embed.EmbedRecordWithMedia) + assert.Equal("app.bsky.embed.recordWithMedia", fp.Embed.EmbedRecordWithMedia.LexiconTypeID) + + cc, err := cid.Decode("bafkreieqq463374bbcbeq7gpmet5rvrpeqow6t4rtjzrkhnlumdylagaqa") + if err != nil { + t.Fatal(err) + } + + assert.Equal( + &appbsky.EmbedRecordWithMedia{ + LexiconTypeID: "app.bsky.embed.recordWithMedia", + Media: &appbsky.EmbedRecordWithMedia_Media{ + EmbedImages: &appbsky.EmbedImages{ + LexiconTypeID: "app.bsky.embed.images", + Images: []*appbsky.EmbedImages_Image{ + &appbsky.EmbedImages_Image{ + Image: &lexutil.LexBlob{ + //LexiconTypeID: "blob", + Ref: lexutil.LexLink(cc), // 000155122090873DBDFF810882487CCF6127D8D62F241D6F4F919A73151DABA3078580C080 + Size: 751473, + MimeType: "image/jpeg", + }, + }, + }, + }, + }, + Record: &appbsky.EmbedRecord{ + LexiconTypeID: "app.bsky.embed.record", + Record: &comatproto.RepoStrongRef{ + Cid: "bafyreiaku7udekkiijxcuue3sn6esz7qijqj637rigz4xqdw57fk5houji", + Uri: "at://did:plc:rbtury4cp2sdk4tvnedaqu54/app.bsky.feed.post/3jilislho4s2k", + }, + }, + }, + fp.Embed.EmbedRecordWithMedia, + ) + + // re-encode as CBOR, check against input bytes + outCborBytes := new(bytes.Buffer) + assert.NoError(fp.MarshalCBOR(outCborBytes)) + assert.Equal(cborBytes, outCborBytes.Bytes()) + + fmt.Printf("OUTPUT: %x\n", outCborBytes.Bytes()) + + // marshal as JSON, compare against expected + expectedJson := `{ + "$type": "app.bsky.feed.post", + "createdAt": "2023-03-29T20:59:19.417Z", + "embed": { + "$type": "app.bsky.embed.recordWithMedia", + "media": { + "$type": "app.bsky.embed.images", + "images": [ + { + "alt": "", + "image": { + "$type": "blob", + "ref": { + "$link": "bafkreieqq463374bbcbeq7gpmet5rvrpeqow6t4rtjzrkhnlumdylagaqa" + }, + "mimeType": "image/jpeg", + "size": 751473 + } + } + ] + }, + "record": { + "$type": "app.bsky.embed.record", + "record": { + "cid": "bafyreiaku7udekkiijxcuue3sn6esz7qijqj637rigz4xqdw57fk5houji", + "uri": "at://did:plc:rbtury4cp2sdk4tvnedaqu54/app.bsky.feed.post/3jilislho4s2k" + } + } + }, + "text": "Who the hell do you think you are" + }` + + outJsonBytes, err := json.Marshal(fp) + assert.NoError(err) + fmt.Println(string(outJsonBytes)) + var outJsonObj map[string]interface{} + assert.NoError(json.Unmarshal(outJsonBytes, &outJsonObj)) + var expectedJsonObj map[string]interface{} + assert.NoError(json.Unmarshal([]byte(expectedJson), &expectedJsonObj)) + assert.Equal(expectedJsonObj, outJsonObj) +} diff --git a/testing/integ_test.go b/testing/integ_test.go index 4b1441820..dff7cf730 100644 --- a/testing/integ_test.go +++ b/testing/integ_test.go @@ -17,6 +17,9 @@ func init() { } func TestBGSBasic(t *testing.T) { + if testing.Short() { + t.Skip("skipping BGS test in 'short' test mode") + } assert := assert.New(t) didr := testPLC(t) p1 := mustSetupPDS(t, "localhost:5155", ".tpds", didr) @@ -46,23 +49,23 @@ func TestBGSBasic(t *testing.T) { fmt.Println("event 1") e1 := evts.Next() - assert.NotNil(e1.RepoAppend) - assert.Equal(e1.RepoAppend.Repo, bob.DID()) + assert.NotNil(e1.RepoCommit) + assert.Equal(e1.RepoCommit.Repo, bob.DID()) fmt.Println("event 2") e2 := evts.Next() - assert.NotNil(e2.RepoAppend) - assert.Equal(e2.RepoAppend.Repo, alice.DID()) + assert.NotNil(e2.RepoCommit) + assert.Equal(e2.RepoCommit.Repo, alice.DID()) fmt.Println("event 3") e3 := evts.Next() - assert.Equal(e3.RepoAppend.Repo, bob.DID()) - //assert.Equal(e3.RepoAppend.Ops[0].Kind, "createRecord") + assert.Equal(e3.RepoCommit.Repo, bob.DID()) + //assert.Equal(e3.RepoCommit.Ops[0].Kind, "createRecord") fmt.Println("event 4") e4 := evts.Next() - assert.Equal(e4.RepoAppend.Repo, alice.DID()) - //assert.Equal(e4.RepoAppend.Ops[0].Kind, "createRecord") + assert.Equal(e4.RepoCommit.Repo, alice.DID()) + //assert.Equal(e4.RepoCommit.Ops[0].Kind, "createRecord") // playback pbevts := b1.Events(t, 2) @@ -104,7 +107,10 @@ func socialSim(t *testing.T, users []*testUser, postiter, likeiter int) []*atpro } func TestBGSMultiPDS(t *testing.T) { - t.Skip("test too sleepy to run in CI for now") + if testing.Short() { + t.Skip("skipping BGS test in 'short' test mode") + } + //t.Skip("test too sleepy to run in CI for now") assert := assert.New(t) _ = assert @@ -119,7 +125,7 @@ func TestBGSMultiPDS(t *testing.T) { b1.Run(t) p1.RequestScraping(t, b1) - time.Sleep(time.Millisecond * 50) + time.Sleep(time.Millisecond * 100) var users []*testUser for i := 0; i < 5; i++ { @@ -166,7 +172,10 @@ func TestBGSMultiPDS(t *testing.T) { } func TestBGSMultiGap(t *testing.T) { - t.Skip("test too sleepy to run in CI for now") + if testing.Short() { + t.Skip("skipping BGS test in 'short' test mode") + } + //t.Skip("test too sleepy to run in CI for now") assert := assert.New(t) _ = assert didr := testPLC(t) @@ -191,7 +200,7 @@ func TestBGSMultiGap(t *testing.T) { p2posts := socialSim(t, users2, 10, 0) users[0].Reply(t, p2posts[0], p2posts[0], "what a wonderful life") - time.Sleep(time.Millisecond * 50) + time.Sleep(time.Millisecond * 100) ctx := context.Background() _, err := b1.bgs.Index.GetPost(ctx, p2posts[3].Uri) diff --git a/testing/repo_slice_test.go b/testing/repo_slice_test.go index 7973d8af5..ee89f57db 100644 --- a/testing/repo_slice_test.go +++ b/testing/repo_slice_test.go @@ -17,7 +17,7 @@ import ( func TestRepoSliceParse(t *testing.T) { ctx := context.TODO() - fi, err := os.Open("repo_slice.car") + fi, err := os.Open("test_files/repo_slice.car") if err != nil { t.Fatal(err) } @@ -47,11 +47,11 @@ func TestRepoSliceParse(t *testing.T) { t.Fatal("didn't get expected Alt text") } - if img.Image.Cid == "" { - t.Fatal("got nil Cid on image") + if !img.Image.Ref.Defined() { + t.Fatal("got nil CID on image") } - if img.Image.Cid != "bafkreiblkobl6arfg3j7eft3akdhn2hmr2qmzfkefcgu4agnswvssg4a6a" { - t.Fatal("didn't get expected image blob Cid") + if img.Image.Ref.String() != "bafkreiblkobl6arfg3j7eft3akdhn2hmr2qmzfkefcgu4agnswvssg4a6a" { + t.Fatal("didn't get expected image blob CID") } if img.Image.MimeType != "image/jpeg" { t.Fatal("didn't get expected image blob mimetype") diff --git a/testing/sig_test.go b/testing/sig_test.go index 38e3ed64a..2ce3c717d 100644 --- a/testing/sig_test.go +++ b/testing/sig_test.go @@ -2,18 +2,27 @@ package testing import ( "context" + "crypto/elliptic" + "encoding/base64" "encoding/json" + "fmt" "os" + "strings" "testing" "github.com/bluesky-social/indigo/repo" + "github.com/ipfs/go-datastore" blockstore "github.com/ipfs/go-ipfs-blockstore" + "github.com/multiformats/go-multibase" + "github.com/stretchr/testify/assert" "github.com/whyrusleeping/go-did" ) func TestVerification(t *testing.T) { - fi, err := os.Open("divy.repo") + assert := assert.New(t) + + fi, err := os.Open("test_files/divy.repo") if err != nil { t.Fatal(err) } @@ -47,6 +56,8 @@ func TestVerification(t *testing.T) { t.Fatal(err) } + assert.Equal(pk.Type, "EcdsaSecp256k1VerificationKey2019") + scom := r.SignedCommit() msg, err := scom.Unsigned().BytesForSigning() @@ -58,3 +69,123 @@ func TestVerification(t *testing.T) { t.Fatal(err) } } + +func TestVerificationK256(t *testing.T) { + // 2023-03-30T11:18:20.605-0700 WARN indexer indexer/keymgr.go:37 trying to verify sig {"key": {"Raw":"BBKybGcJOMvsIyPaKglHtcocOFN7QrlppYHN3i4fW5PfLmfUFCXNcNKMk/MjT/cnquZS1APwxr6QUR7LE8/bJC8=","Type":"EcdsaSecp256k1VerificationKey2019"}, "sigBytes": "1ZJM8YFVmHJksi+liHFn62GBfUd7zDio0BVej0JTjtJUdYMgmV8Mg4/4RNfL9VFM8bXMhzusJ1qpu2kTyHoliA==", "msgBytes": "pGNkaWR4IGRpZDpwbGM6cHVydnZqNXV0N2hyeGo1ejdtbTZyNGd0ZGRhdGHYKlglAAFxEiAG8t9fbFkSGKBhEXYLZLC5njldpEfHGg2hheTdR9VLi2RwcmV22CpYJQABcRIgtJroXREnp3TZxxf8xZTQC+w4+vnfz1KIkWVitinSPOFndmVyc2lvbgI="} + + assert := assert.New(t) + keyBytes, err := base64.StdEncoding.DecodeString("BBKybGcJOMvsIyPaKglHtcocOFN7QrlppYHN3i4fW5PfLmfUFCXNcNKMk/MjT/cnquZS1APwxr6QUR7LE8/bJC8=") + assert.NoError(err) + msgBytes, err := base64.StdEncoding.DecodeString("pGNkaWR4IGRpZDpwbGM6cHVydnZqNXV0N2hyeGo1ejdtbTZyNGd0ZGRhdGHYKlglAAFxEiAG8t9fbFkSGKBhEXYLZLC5njldpEfHGg2hheTdR9VLi2RwcmV22CpYJQABcRIgtJroXREnp3TZxxf8xZTQC+w4+vnfz1KIkWVitinSPOFndmVyc2lvbgI=") + assert.NoError(err) + sigBytes, err := base64.StdEncoding.DecodeString("1ZJM8YFVmHJksi+liHFn62GBfUd7zDio0BVej0JTjtJUdYMgmV8Mg4/4RNfL9VFM8bXMhzusJ1qpu2kTyHoliA==") + assert.NoError(err) + + key := did.PubKey{ + Type: "EcdsaSecp256k1VerificationKey2019", // k1 -> K256 + Raw: keyBytes, + } + + assert.NoError(key.Verify(msgBytes, sigBytes)) +} + +func parseKeyFromMultibase(t *testing.T, s, keyType string) did.PubKey { + _, data, err := multibase.Decode(s) + if err != nil { + t.Fatal(err) + } + return did.PubKey{ + Type: keyType, + Raw: data, + } +} + +func parseDidKey(t *testing.T, s string) did.PubKey { + parts := strings.SplitN(s, ":", 3) + _, data, err := multibase.Decode(parts[2]) + if err != nil { + t.Fatal(err) + } + switch { + case data[0] == 0x80 && data[1] == 0x24: + // p256; need to "uncompress" + curve := elliptic.P256() + x, y := elliptic.UnmarshalCompressed(curve, data[2:]) + return did.PubKey{ + Type: "EcdsaSecp256r1VerificationKey2019", + Raw: elliptic.Marshal(curve, x, y), + } + case data[0] == 0xE7 && data[1] == 0x01: + // k256; apparently don't need to uncompress + return did.PubKey{ + Type: "EcdsaSecp256k1VerificationKey2019", + Raw: data[2:], + } + default: + t.Fatal(fmt.Errorf("unhandled did:key type: %d %d", data[0], data[1])) + } + panic("unreachable") +} + +func TestInteropSignatures(t *testing.T) { + assert := assert.New(t) + + testTable := []struct { + description string + keyType string + docType string + didKey string + multibaseKey string + msgBase64 string + sigBase64 string + }{ + { + description: "p256/secp256r1", + keyType: "ES256", + docType: "EcdsaSecp256r1VerificationKey2019", + didKey: "did:key:zDnaebKg3xzqP4DnpjCjaUpPkCVridQJufGQqwYWi623VPxcN", + multibaseKey: "zQi6N7wGYuk7GhUfU17jkaitpAPzeGyCufAyz9i7jT4T2XSC1KjbAA2QridVGidGbfXdV9X9fWotHmmkVwbeXRujR", + msgBase64: "oWVoZWxsb2V3b3JsZA", + sigBase64: "/SbeL+Tx6TXUZGC7uHHkI9b+1ARoLcqTzkUYJmPBqlCVAvKkxkPowfqKwnJWpZcuF4g3MT7eVgdBROHgdUplIQ", + }, + { + description: "k256/secp256k1", + keyType: "ES256K", + docType: "EcdsaSecp256k1VerificationKey2019", + didKey: "did:key:zQ3shueETAVp1HCdE7pcrUD1wEHNhfaQiDJmWeJgCxZRmDJuy", + multibaseKey: "zRvvEWNhRDxCYpkWWKzvrCP5Sca54yhgXjLcSgfJsWW9Jk8Wq79d5h2PTW3BQDmNQv4prqGjRkXiEDwnfpq2tTsmp", + msgBase64: "oWVoZWxsb2V3b3JsZA", + sigBase64: "FbKI9u/VoY9SFHvtsuYsZULkt3QiNRrPUP3N4bX0xTxfWIUccyoNJ7egTITlaD1xBhXAvDdBnbyC6aOZ0jyjEA", + }, + } + + for _, row := range testTable { + pkDid := parseDidKey(t, row.didKey) + pkMultibase := parseKeyFromMultibase(t, row.multibaseKey, row.docType) + msgBytes, err := base64.RawStdEncoding.DecodeString(row.msgBase64) + assert.NoError(err) + sigBytes, err := base64.RawStdEncoding.DecodeString(row.sigBase64) + assert.NoError(err) + + assert.NoError(pkDid.Verify(msgBytes, sigBytes), "keyType=%v format=%v", row.description, "did:key") + assert.NoError(pkMultibase.Verify(msgBytes, sigBytes), "keyType=%v format=%v", row.description, "multibase") + assert.Error(pkMultibase.Verify(msgBytes, []byte{1, 2, 3}), "keyType=%v format=%v", row.description, "multibase") + assert.Error(pkMultibase.Verify([]byte{1, 2, 3}, sigBytes), "keyType=%v format=%v", row.description, "multibase") + + // TODO: investigate these additional tests, which partially fail, instead of "continue" + /* + assert.Equal(pkDid, pkMultibase, row.description) + assert.NotEqual(pkDid.MultibaseString(), "", "keyType=%v format=%v", row.description, "did:key") + assert.NotEqual(pkMultibase.MultibaseString(), "", "keyType=%v format=%v", row.description, "multibase") + + // check that keys round-trip ok + assert.Equal(row.didKey, pkDid.DID(), "export keyType=%v format=%v", row.description, "did:key") + assert.Equal(row.multibaseKey, pkDid.MultibaseString(), "export keyType=%v format=%v", row.description, "multibase") + pkDid = parseDidKey(t, pkDid.DID()) + pkMultibase = parseKeyFromMultibase(t, pkMultibase.MultibaseString(), row.docType) + + assert.NoError(pkDid.Verify(msgBytes, sigBytes), "round-trip keyType=%v format=%v", row.description, "did:key") + assert.NoError(pkMultibase.Verify(msgBytes, sigBytes), "round-trip keyType=%v format=%v", row.description, "multibase") + */ + } +} diff --git a/testing/test_files/bafyreieovfuizojpw3zresz7sx3nk4trm2by23pt5rxbey3jme4uo5ogiu.car b/testing/test_files/bafyreieovfuizojpw3zresz7sx3nk4trm2by23pt5rxbey3jme4uo5ogiu.car new file mode 100644 index 000000000..e8569b9ce Binary files /dev/null and b/testing/test_files/bafyreieovfuizojpw3zresz7sx3nk4trm2by23pt5rxbey3jme4uo5ogiu.car differ diff --git a/testing/test_files/did_plc_z5vnbioquyhivxirw3bbljmu.didDoc.json b/testing/test_files/did_plc_z5vnbioquyhivxirw3bbljmu.didDoc.json new file mode 100644 index 000000000..055c2895b --- /dev/null +++ b/testing/test_files/did_plc_z5vnbioquyhivxirw3bbljmu.didDoc.json @@ -0,0 +1 @@ +{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/suites/secp256k1-2019/v1"],"id":"did:plc:z5vnbioquyhivxirw3bbljmu","alsoKnownAs":["at://koch5149-c5.test"],"verificationMethod":[{"id":"#atproto","type":"EcdsaSecp256k1VerificationKey2019","controller":"did:plc:z5vnbioquyhivxirw3bbljmu","publicKeyMultibase":"zPgFC4hKo2MFLkBRQuHewXRDp94MSrd3yuiJ1En87qTeF68T92DPWvWSjxjMuMiB4qz8UzE8wWTNvZq7mgr7BsjW9"}],"service":[{"id":"#atproto_pds","type":"AtprotoPersonalDataServer","serviceEndpoint":"http://localhost:2583"}]} \ No newline at end of file diff --git a/testing/divy.repo b/testing/test_files/divy.repo similarity index 100% rename from testing/divy.repo rename to testing/test_files/divy.repo diff --git a/testing/test_files/feedpost_record.cbor b/testing/test_files/feedpost_record.cbor new file mode 100644 index 000000000..e0a61d0fa Binary files /dev/null and b/testing/test_files/feedpost_record.cbor differ diff --git a/testing/repo_slice.car b/testing/test_files/repo_slice.car similarity index 100% rename from testing/repo_slice.car rename to testing/test_files/repo_slice.car diff --git a/testing/repo_slice_record.json b/testing/test_files/repo_slice_record.json similarity index 100% rename from testing/repo_slice_record.json rename to testing/test_files/repo_slice_record.json diff --git a/testing/utils.go b/testing/utils.go index 1cd5d0707..029c22ab1 100644 --- a/testing/utils.go +++ b/testing/utils.go @@ -194,7 +194,7 @@ func (tp *testPDS) NewUser(handle string) (*testUser, error) { } fmt.Println("HOST: ", c.Host) - out, err := atproto.AccountCreate(ctx, c, &atproto.AccountCreate_Input{ + out, err := atproto.ServerCreateAccount(ctx, c, &atproto.ServerCreateAccount_Input{ Email: handle + "@fake.com", Handle: handle, Password: "password", @@ -224,8 +224,8 @@ func (u *testUser) Reply(t *testing.T, replyto, root *atproto.RepoStrongRef, bod ctx := context.TODO() resp, err := atproto.RepoCreateRecord(ctx, u.client, &atproto.RepoCreateRecord_Input{ Collection: "app.bsky.feed.post", - Did: u.did, - Record: lexutil.LexiconTypeDecoder{&bsky.FeedPost{ + Repo: u.did, + Record: &lexutil.LexiconTypeDecoder{&bsky.FeedPost{ CreatedAt: time.Now().Format(time.RFC3339), Text: body, Reply: &bsky.FeedPost_ReplyRef{ @@ -251,8 +251,8 @@ func (u *testUser) Post(t *testing.T, body string) *atproto.RepoStrongRef { ctx := context.TODO() resp, err := atproto.RepoCreateRecord(ctx, u.client, &atproto.RepoCreateRecord_Input{ Collection: "app.bsky.feed.post", - Did: u.did, - Record: lexutil.LexiconTypeDecoder{&bsky.FeedPost{ + Repo: u.did, + Record: &lexutil.LexiconTypeDecoder{&bsky.FeedPost{ CreatedAt: time.Now().Format(time.RFC3339), Text: body, }}, @@ -274,11 +274,10 @@ func (u *testUser) Like(t *testing.T, post *atproto.RepoStrongRef) { ctx := context.TODO() _, err := atproto.RepoCreateRecord(ctx, u.client, &atproto.RepoCreateRecord_Input{ Collection: "app.bsky.feed.vote", - Did: u.did, - Record: lexutil.LexiconTypeDecoder{&bsky.FeedVote{ + Repo: u.did, + Record: &lexutil.LexiconTypeDecoder{&bsky.FeedLike{ LexiconTypeID: "app.bsky.feed.vote", CreatedAt: time.Now().Format(time.RFC3339), - Direction: "up", Subject: post, }}, }) @@ -294,13 +293,10 @@ func (u *testUser) Follow(t *testing.T, did string) string { ctx := context.TODO() resp, err := atproto.RepoCreateRecord(ctx, u.client, &atproto.RepoCreateRecord_Input{ Collection: "app.bsky.graph.follow", - Did: u.did, - Record: lexutil.LexiconTypeDecoder{&bsky.GraphFollow{ + Repo: u.did, + Record: &lexutil.LexiconTypeDecoder{&bsky.GraphFollow{ CreatedAt: time.Now().Format(time.RFC3339), - Subject: &bsky.ActorRef{ - DeclarationCid: "bafyreid27zk7lbis4zw5fz4podbvbs4fc5ivwji3dmrwa6zggnj4bnd57u", - Did: did, - }, + Subject: did, }}, }) @@ -311,7 +307,7 @@ func (u *testUser) Follow(t *testing.T, did string) string { return resp.Uri } -func (u *testUser) GetFeed(t *testing.T) []*bsky.FeedFeedViewPost { +func (u *testUser) GetFeed(t *testing.T) []*bsky.FeedDefs_FeedViewPost { t.Helper() ctx := context.TODO() @@ -323,11 +319,11 @@ func (u *testUser) GetFeed(t *testing.T) []*bsky.FeedFeedViewPost { return resp.Feed } -func (u *testUser) GetNotifs(t *testing.T) []*bsky.NotificationList_Notification { +func (u *testUser) GetNotifs(t *testing.T) []*bsky.NotificationListNotifications_Notification { t.Helper() ctx := context.TODO() - resp, err := bsky.NotificationList(ctx, u.client, "", 100) + resp, err := bsky.NotificationListNotifications(ctx, u.client, "", 100) if err != nil { t.Fatal(err) } @@ -448,7 +444,7 @@ func (b *testBGS) Events(t *testing.T, since int64) *eventStream { q = fmt.Sprintf("?cursor=%d", since) } - con, resp, err := d.Dial("ws://"+b.host+"/xrpc/com.atproto.sync.subscribeAllRepos"+q, h) + con, resp, err := d.Dial("ws://"+b.host+"/xrpc/com.atproto.sync.subscribeRepos"+q, h) if err != nil { t.Fatal(err) } @@ -470,10 +466,10 @@ func (b *testBGS) Events(t *testing.T, since int64) *eventStream { go func() { if err := events.HandleRepoStream(ctx, con, &events.RepoStreamCallbacks{ - RepoAppend: func(evt *events.RepoAppend) error { + RepoCommit: func(evt *atproto.SyncSubscribeRepos_Commit) error { fmt.Println("received event: ", evt.Seq, evt.Repo) es.lk.Lock() - es.events = append(es.events, &events.XRPCStreamEvent{RepoAppend: evt}) + es.events = append(es.events, &events.XRPCStreamEvent{RepoCommit: evt}) es.lk.Unlock() return nil }, @@ -722,9 +718,8 @@ func GenerateFakeRepo(r *repo.Repo, size int) (cid.Cid, error) { return cid.Undef, err } case "like": - _, _, err := r.CreateRecord(ctx, "app.bsky.feed.vote", &bsky.FeedVote{ + _, _, err := r.CreateRecord(ctx, "app.bsky.feed.vote", &bsky.FeedLike{ CreatedAt: time.Now().Format(bsutil.ISO8601), - Direction: "up", Subject: &atproto.RepoStrongRef{ Uri: RandFakeAtUri("app.bsky.feed.post", ""), Cid: RandFakeCid().String(), diff --git a/xrpc/xrpc.go b/xrpc/xrpc.go index 3ec590f2f..4275d39dd 100644 --- a/xrpc/xrpc.go +++ b/xrpc/xrpc.go @@ -32,11 +32,10 @@ func (c *Client) getClient() *http.Client { type XRPCRequestType int type AuthInfo struct { - AccessJwt string `json:"accessJwt"` - RefreshJwt string `json:"refreshJwt"` - Handle string `json:"handle"` - Did string `json:"did"` - DeclarationCid string `json:"declarationCid"` + AccessJwt string `json:"accessJwt"` + RefreshJwt string `json:"refreshJwt"` + Handle string `json:"handle"` + Did string `json:"did"` } const (