From 200f6a9945ccce4985635794b3506ba4b8a72f75 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Thu, 5 Dec 2024 16:37:12 -0800 Subject: [PATCH 1/2] goat: update to use agnostic helpers --- cmd/goat/account_migrate.go | 13 ++--- cmd/goat/account_plc.go | 9 ++-- cmd/goat/actorgetPreferences.go | 28 ---------- cmd/goat/actorputPreferences.go | 25 --------- cmd/goat/bsky_prefs.go | 6 ++- .../identitygetRecommendedDidCredentials.go | 23 -------- cmd/goat/identitysignPlcOperation.go | 38 ------------- cmd/goat/identitysubmitPlcOperation.go | 26 --------- cmd/goat/net.go | 3 +- cmd/goat/record.go | 9 ++-- cmd/goat/repocreateRecord.go | 51 ------------------ cmd/goat/repogetRecord.go | 42 --------------- cmd/goat/repolistRecords.go | 53 ------------------- cmd/goat/repoputRecord.go | 47 ---------------- 14 files changed, 23 insertions(+), 350 deletions(-) delete mode 100644 cmd/goat/actorgetPreferences.go delete mode 100644 cmd/goat/actorputPreferences.go delete mode 100644 cmd/goat/identitygetRecommendedDidCredentials.go delete mode 100644 cmd/goat/identitysignPlcOperation.go delete mode 100644 cmd/goat/identitysubmitPlcOperation.go delete mode 100644 cmd/goat/repocreateRecord.go delete mode 100644 cmd/goat/repogetRecord.go delete mode 100644 cmd/goat/repolistRecords.go delete mode 100644 cmd/goat/repoputRecord.go diff --git a/cmd/goat/account_migrate.go b/cmd/goat/account_migrate.go index fa3d60535..08925f48b 100644 --- a/cmd/goat/account_migrate.go +++ b/cmd/goat/account_migrate.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/bluesky-social/indigo/api/agnostic" comatproto "github.com/bluesky-social/indigo/api/atproto" "github.com/bluesky-social/indigo/atproto/syntax" "github.com/bluesky-social/indigo/xrpc" @@ -166,11 +167,11 @@ func runAccountMigrate(cctx *cli.Context) error { slog.Info("migrating preferences") // TODO: service proxy header for AppView? - prefResp, err := ActorGetPreferences(ctx, oldClient) + prefResp, err := agnostic.ActorGetPreferences(ctx, oldClient) if err != nil { return fmt.Errorf("failed fetching old preferences: %w", err) } - err = ActorPutPreferences(ctx, &newClient, &ActorPutPreferences_Input{ + err = agnostic.ActorPutPreferences(ctx, &newClient, &agnostic.ActorPutPreferences_Input{ Preferences: prefResp.Preferences, }) if err != nil { @@ -214,7 +215,7 @@ func runAccountMigrate(cctx *cli.Context) error { // NOTE: to work with did:web or non-PDS-managed did:plc, need to do manual migraiton process slog.Info("updating identity to new host") - credsResp, err := IdentityGetRecommendedDidCredentials(ctx, &newClient) + credsResp, err := agnostic.IdentityGetRecommendedDidCredentials(ctx, &newClient) if err != nil { return fmt.Errorf("failed fetching new credentials: %w", err) } @@ -223,7 +224,7 @@ func runAccountMigrate(cctx *cli.Context) error { return nil } - var unsignedOp IdentitySignPlcOperation_Input + var unsignedOp agnostic.IdentitySignPlcOperation_Input if err = json.Unmarshal(credsBytes, &unsignedOp); err != nil { return fmt.Errorf("failed parsing PLC op: %w", err) } @@ -231,12 +232,12 @@ func runAccountMigrate(cctx *cli.Context) error { // NOTE: could add additional sanity checks here that any extra rotation keys were retained, and that old alsoKnownAs and service entries are retained? The stakes aren't super high for the later, as PLC has the full history. PLC and the new PDS already implement some basic sanity checks. - signedPlcOpResp, err := IdentitySignPlcOperation(ctx, oldClient, &unsignedOp) + signedPlcOpResp, err := agnostic.IdentitySignPlcOperation(ctx, oldClient, &unsignedOp) if err != nil { return fmt.Errorf("failed requesting PLC operation signature: %w", err) } - err = IdentitySubmitPlcOperation(ctx, &newClient, &IdentitySubmitPlcOperation_Input{ + err = agnostic.IdentitySubmitPlcOperation(ctx, &newClient, &agnostic.IdentitySubmitPlcOperation_Input{ Operation: signedPlcOpResp.Operation, }) if err != nil { diff --git a/cmd/goat/account_plc.go b/cmd/goat/account_plc.go index a0dde653b..5ce62903a 100644 --- a/cmd/goat/account_plc.go +++ b/cmd/goat/account_plc.go @@ -6,6 +6,7 @@ import ( "fmt" "os" + "github.com/bluesky-social/indigo/api/agnostic" comatproto "github.com/bluesky-social/indigo/api/atproto" "github.com/urfave/cli/v2" @@ -56,7 +57,7 @@ func runAccountPlcRecommended(cctx *cli.Context) error { return err } - resp, err := IdentityGetRecommendedDidCredentials(ctx, xrpcc) + resp, err := agnostic.IdentityGetRecommendedDidCredentials(ctx, xrpcc) if err != nil { return err } @@ -109,7 +110,7 @@ func runAccountPlcSign(cctx *cli.Context) error { return err } - var body IdentitySignPlcOperation_Input + var body agnostic.IdentitySignPlcOperation_Input if err = json.Unmarshal(fileBytes, &body); err != nil { return fmt.Errorf("failed decoding PLC op JSON: %w", err) } @@ -119,7 +120,7 @@ func runAccountPlcSign(cctx *cli.Context) error { body.Token = &token } - resp, err := IdentitySignPlcOperation(ctx, xrpcc, &body) + resp, err := agnostic.IdentitySignPlcOperation(ctx, xrpcc, &body) if err != nil { return err } @@ -158,7 +159,7 @@ func runAccountPlcSubmit(cctx *cli.Context) error { return fmt.Errorf("failed decoding PLC op JSON: %w", err) } - err = IdentitySubmitPlcOperation(ctx, xrpcc, &IdentitySubmitPlcOperation_Input{ + err = agnostic.IdentitySubmitPlcOperation(ctx, xrpcc, &agnostic.IdentitySubmitPlcOperation_Input{ Operation: &op, }) if err != nil { diff --git a/cmd/goat/actorgetPreferences.go b/cmd/goat/actorgetPreferences.go deleted file mode 100644 index bd6e8a18c..000000000 --- a/cmd/goat/actorgetPreferences.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copied from indigo:api/atproto/actorgetPreferences.go - -package main - -// schema: app.bsky.actor.getPreferences - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// ActorGetPreferences_Output is the output of a app.bsky.actor.getPreferences call. -type ActorGetPreferences_Output struct { - Preferences []map[string]any `json:"preferences" cborgen:"preferences"` -} - -// ActorGetPreferences calls the XRPC method "app.bsky.actor.getPreferences". -func ActorGetPreferences(ctx context.Context, c *xrpc.Client) (*ActorGetPreferences_Output, error) { - var out ActorGetPreferences_Output - - params := map[string]interface{}{} - if err := c.Do(ctx, xrpc.Query, "", "app.bsky.actor.getPreferences", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/cmd/goat/actorputPreferences.go b/cmd/goat/actorputPreferences.go deleted file mode 100644 index 24042236d..000000000 --- a/cmd/goat/actorputPreferences.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copied from indigo:api/atproto/actorputPreferences.go - -package main - -// schema: app.bsky.actor.putPreferences - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// ActorPutPreferences_Input is the input argument to a app.bsky.actor.putPreferences call. -type ActorPutPreferences_Input struct { - Preferences []map[string]any `json:"preferences" cborgen:"preferences"` -} - -// ActorPutPreferences calls the XRPC method "app.bsky.actor.putPreferences". -func ActorPutPreferences(ctx context.Context, c *xrpc.Client, input *ActorPutPreferences_Input) error { - if err := c.Do(ctx, xrpc.Procedure, "application/json", "app.bsky.actor.putPreferences", nil, input, nil); err != nil { - return err - } - - return nil -} diff --git a/cmd/goat/bsky_prefs.go b/cmd/goat/bsky_prefs.go index 725072344..789609125 100644 --- a/cmd/goat/bsky_prefs.go +++ b/cmd/goat/bsky_prefs.go @@ -6,6 +6,8 @@ import ( "fmt" "os" + "github.com/bluesky-social/indigo/api/agnostic" + "github.com/urfave/cli/v2" ) @@ -39,7 +41,7 @@ func runBskyPrefsExport(cctx *cli.Context) error { } // TODO: does indigo API code crash with unsupported preference '$type'? Eg "Lexicon decoder" with unsupported type. - resp, err := ActorGetPreferences(ctx, xrpcc) + resp, err := agnostic.ActorGetPreferences(ctx, xrpcc) if err != nil { return fmt.Errorf("failed fetching old preferences: %w", err) } @@ -77,7 +79,7 @@ func runBskyPrefsImport(cctx *cli.Context) error { return err } - err = ActorPutPreferences(ctx, xrpcc, &ActorPutPreferences_Input{ + err = agnostic.ActorPutPreferences(ctx, xrpcc, &agnostic.ActorPutPreferences_Input{ Preferences: prefsArray, }) if err != nil { diff --git a/cmd/goat/identitygetRecommendedDidCredentials.go b/cmd/goat/identitygetRecommendedDidCredentials.go deleted file mode 100644 index 75abcc522..000000000 --- a/cmd/goat/identitygetRecommendedDidCredentials.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copied from indigo:api/atproto/identitygetRecommendedDidCredentials.go - -package main - -// schema: com.atproto.identity.getRecommendedDidCredentials - -import ( - "context" - "encoding/json" - - "github.com/bluesky-social/indigo/xrpc" -) - -// IdentityGetRecommendedDidCredentials calls the XRPC method "com.atproto.identity.getRecommendedDidCredentials". -func IdentityGetRecommendedDidCredentials(ctx context.Context, c *xrpc.Client) (*json.RawMessage, error) { - var out json.RawMessage - - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.identity.getRecommendedDidCredentials", nil, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/cmd/goat/identitysignPlcOperation.go b/cmd/goat/identitysignPlcOperation.go deleted file mode 100644 index f9c96bea2..000000000 --- a/cmd/goat/identitysignPlcOperation.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copied from indigo:api/atproto/identitysignPlcOperation.go - -package main - -// schema: com.atproto.identity.signPlcOperation - -import ( - "context" - "encoding/json" - - "github.com/bluesky-social/indigo/xrpc" -) - -// IdentitySignPlcOperation_Input is the input argument to a com.atproto.identity.signPlcOperation call. -type IdentitySignPlcOperation_Input struct { - AlsoKnownAs []string `json:"alsoKnownAs,omitempty" cborgen:"alsoKnownAs,omitempty"` - RotationKeys []string `json:"rotationKeys,omitempty" cborgen:"rotationKeys,omitempty"` - Services *json.RawMessage `json:"services,omitempty" cborgen:"services,omitempty"` - // token: A token received through com.atproto.identity.requestPlcOperationSignature - Token *string `json:"token,omitempty" cborgen:"token,omitempty"` - VerificationMethods *json.RawMessage `json:"verificationMethods,omitempty" cborgen:"verificationMethods,omitempty"` -} - -// IdentitySignPlcOperation_Output is the output of a com.atproto.identity.signPlcOperation call. -type IdentitySignPlcOperation_Output struct { - // operation: A signed DID PLC operation. - Operation *json.RawMessage `json:"operation" cborgen:"operation"` -} - -// IdentitySignPlcOperation calls the XRPC method "com.atproto.identity.signPlcOperation". -func IdentitySignPlcOperation(ctx context.Context, c *xrpc.Client, input *IdentitySignPlcOperation_Input) (*IdentitySignPlcOperation_Output, error) { - var out IdentitySignPlcOperation_Output - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.identity.signPlcOperation", nil, input, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/cmd/goat/identitysubmitPlcOperation.go b/cmd/goat/identitysubmitPlcOperation.go deleted file mode 100644 index 9f15e8adc..000000000 --- a/cmd/goat/identitysubmitPlcOperation.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copied from indigo:api/atproto/identitysubmitPlcOperation.go - -package main - -// schema: com.atproto.identity.submitPlcOperation - -import ( - "context" - "encoding/json" - - "github.com/bluesky-social/indigo/xrpc" -) - -// IdentitySubmitPlcOperation_Input is the input argument to a com.atproto.identity.submitPlcOperation call. -type IdentitySubmitPlcOperation_Input struct { - Operation *json.RawMessage `json:"operation" cborgen:"operation"` -} - -// IdentitySubmitPlcOperation calls the XRPC method "com.atproto.identity.submitPlcOperation". -func IdentitySubmitPlcOperation(ctx context.Context, c *xrpc.Client, input *IdentitySubmitPlcOperation_Input) error { - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.identity.submitPlcOperation", nil, input, nil); err != nil { - return err - } - - return nil -} diff --git a/cmd/goat/net.go b/cmd/goat/net.go index d7bb8e8f1..f0f2d9c4d 100644 --- a/cmd/goat/net.go +++ b/cmd/goat/net.go @@ -5,6 +5,7 @@ import ( "fmt" "log/slog" + "github.com/bluesky-social/indigo/api/agnostic" "github.com/bluesky-social/indigo/atproto/data" "github.com/bluesky-social/indigo/atproto/identity" "github.com/bluesky-social/indigo/atproto/syntax" @@ -17,7 +18,7 @@ func fetchRecord(ctx context.Context, ident identity.Identity, aturi syntax.ATUR xrpcc := xrpc.Client{ Host: ident.PDSEndpoint(), } - resp, err := RepoGetRecord(ctx, &xrpcc, "", aturi.Collection().String(), ident.DID.String(), aturi.RecordKey().String()) + resp, err := agnostic.RepoGetRecord(ctx, &xrpcc, "", aturi.Collection().String(), ident.DID.String(), aturi.RecordKey().String()) if err != nil { return nil, err } diff --git a/cmd/goat/record.go b/cmd/goat/record.go index 013913aa2..0caee8552 100644 --- a/cmd/goat/record.go +++ b/cmd/goat/record.go @@ -6,6 +6,7 @@ import ( "fmt" "os" + "github.com/bluesky-social/indigo/api/agnostic" comatproto "github.com/bluesky-social/indigo/api/atproto" "github.com/bluesky-social/indigo/atproto/data" "github.com/bluesky-social/indigo/atproto/identity" @@ -179,7 +180,7 @@ func runRecordList(cctx *cli.Context) error { cursor := "" for { // collection string, cursor string, limit int64, repo string, reverse bool, rkeyEnd string, rkeyStart string - resp, err := RepoListRecords(ctx, &xrpcc, nsid, cursor, 100, ident.DID.String(), false, "", "") + resp, err := agnostic.RepoListRecords(ctx, &xrpcc, nsid, cursor, 100, ident.DID.String(), false, "", "") if err != nil { return err } @@ -246,7 +247,7 @@ func runRecordCreate(cctx *cli.Context) error { } validate := !cctx.Bool("no-validate") - resp, err := RepoCreateRecord(ctx, xrpcc, &RepoCreateRecord_Input{ + resp, err := agnostic.RepoCreateRecord(ctx, xrpcc, &agnostic.RepoCreateRecord_Input{ Collection: nsid, Repo: xrpcc.Auth.Did, Record: recordVal, @@ -293,7 +294,7 @@ func runRecordUpdate(cctx *cli.Context) error { rkey := cctx.String("rkey") // NOTE: need to fetch existing record CID to perform swap. this is optional in theory, but golang can't deal with "optional" and "nullable", so we always need to set this (?) - existing, err := RepoGetRecord(ctx, xrpcc, "", nsid, xrpcc.Auth.Did, rkey) + existing, err := agnostic.RepoGetRecord(ctx, xrpcc, "", nsid, xrpcc.Auth.Did, rkey) if err != nil { return err } @@ -305,7 +306,7 @@ func runRecordUpdate(cctx *cli.Context) error { validate := !cctx.Bool("no-validate") - resp, err := RepoPutRecord(ctx, xrpcc, &RepoPutRecord_Input{ + resp, err := agnostic.RepoPutRecord(ctx, xrpcc, &agnostic.RepoPutRecord_Input{ Collection: nsid, Repo: xrpcc.Auth.Did, Record: recordVal, diff --git a/cmd/goat/repocreateRecord.go b/cmd/goat/repocreateRecord.go deleted file mode 100644 index c1fa67a39..000000000 --- a/cmd/goat/repocreateRecord.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copied from indigo:api/atproto/repocreateRecords.go - -package main - -// schema: com.atproto.repo.createRecord - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// RepoDefs_CommitMeta is a "commitMeta" in the com.atproto.repo.defs schema. -type RepoDefs_CommitMeta struct { - Cid string `json:"cid" cborgen:"cid"` - Rev string `json:"rev" cborgen:"rev"` -} - -// RepoCreateRecord_Input is the input argument to a com.atproto.repo.createRecord call. -type RepoCreateRecord_Input struct { - // collection: The NSID of the record collection. - Collection string `json:"collection" cborgen:"collection"` - // record: The record itself. Must contain a $type field. - Record map[string]any `json:"record" cborgen:"record"` - // repo: The handle or DID of the repo (aka, current account). - Repo string `json:"repo" cborgen:"repo"` - // rkey: The Record Key. - Rkey *string `json:"rkey,omitempty" cborgen:"rkey,omitempty"` - // swapCommit: Compare and swap with the previous commit by CID. - SwapCommit *string `json:"swapCommit,omitempty" cborgen:"swapCommit,omitempty"` - // validate: Can be set to 'false' to skip Lexicon schema validation of record data, 'true' to require it, or leave unset to validate only for known Lexicons. - Validate *bool `json:"validate,omitempty" cborgen:"validate,omitempty"` -} - -// RepoCreateRecord_Output is the output of a com.atproto.repo.createRecord call. -type RepoCreateRecord_Output struct { - Cid string `json:"cid" cborgen:"cid"` - Commit *RepoDefs_CommitMeta `json:"commit,omitempty" cborgen:"commit,omitempty"` - Uri string `json:"uri" cborgen:"uri"` - ValidationStatus *string `json:"validationStatus,omitempty" cborgen:"validationStatus,omitempty"` -} - -// RepoCreateRecord calls the XRPC method "com.atproto.repo.createRecord". -func RepoCreateRecord(ctx context.Context, c *xrpc.Client, input *RepoCreateRecord_Input) (*RepoCreateRecord_Output, error) { - var out RepoCreateRecord_Output - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.repo.createRecord", nil, input, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/cmd/goat/repogetRecord.go b/cmd/goat/repogetRecord.go deleted file mode 100644 index e3b857cd5..000000000 --- a/cmd/goat/repogetRecord.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copied from indigo:api/atproto/repolistRecords.go - -package main - -// schema: com.atproto.repo.getRecord - -import ( - "context" - "encoding/json" - - "github.com/bluesky-social/indigo/xrpc" -) - -// RepoGetRecord_Output is the output of a com.atproto.repo.getRecord call. -type RepoGetRecord_Output struct { - Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"` - Uri string `json:"uri" cborgen:"uri"` - // NOTE: changed from lex decoder to json.RawMessage - Value *json.RawMessage `json:"value" cborgen:"value"` -} - -// RepoGetRecord calls the XRPC method "com.atproto.repo.getRecord". -// -// cid: The CID of the version of the record. If not specified, then return the most recent version. -// collection: The NSID of the record collection. -// repo: The handle or DID of the repo. -// rkey: The Record Key. -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, - } - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.repo.getRecord", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/cmd/goat/repolistRecords.go b/cmd/goat/repolistRecords.go deleted file mode 100644 index 3cfdd9b24..000000000 --- a/cmd/goat/repolistRecords.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copied from indigo:api/atproto/repolistRecords.go - -package main - -// schema: com.atproto.repo.listRecords - -import ( - "context" - "encoding/json" - - "github.com/bluesky-social/indigo/xrpc" -) - -// RepoListRecords_Output is the output of a com.atproto.repo.listRecords call. -type RepoListRecords_Output struct { - Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` - Records []*RepoListRecords_Record `json:"records" cborgen:"records"` -} - -// RepoListRecords_Record is a "record" in the com.atproto.repo.listRecords schema. -type RepoListRecords_Record struct { - Cid string `json:"cid" cborgen:"cid"` - Uri string `json:"uri" cborgen:"uri"` - // NOTE: changed from lex decoder to json.RawMessage - Value *json.RawMessage `json:"value" cborgen:"value"` -} - -// RepoListRecords calls the XRPC method "com.atproto.repo.listRecords". -// -// collection: The NSID of the record type. -// limit: The number of records to return. -// repo: The handle or DID of the repo. -// reverse: Flag to reverse the order of the returned records. -// rkeyEnd: DEPRECATED: The highest sort-ordered rkey to stop at (exclusive) -// rkeyStart: DEPRECATED: The lowest sort-ordered rkey to start from (exclusive) -func RepoListRecords(ctx context.Context, c *xrpc.Client, collection string, cursor string, limit int64, repo string, reverse bool, rkeyEnd string, rkeyStart string) (*RepoListRecords_Output, error) { - var out RepoListRecords_Output - - params := map[string]interface{}{ - "collection": collection, - "cursor": cursor, - "limit": limit, - "repo": repo, - "reverse": reverse, - "rkeyEnd": rkeyEnd, - "rkeyStart": rkeyStart, - } - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.repo.listRecords", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/cmd/goat/repoputRecord.go b/cmd/goat/repoputRecord.go deleted file mode 100644 index 34011797b..000000000 --- a/cmd/goat/repoputRecord.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copied from indigo:api/atproto/repoputRecords.go - -package main - -// schema: com.atproto.repo.putRecord - -import ( - "context" - - "github.com/bluesky-social/indigo/xrpc" -) - -// RepoPutRecord_Input is the input argument to a com.atproto.repo.putRecord call. -type RepoPutRecord_Input struct { - // collection: The NSID of the record collection. - Collection string `json:"collection" cborgen:"collection"` - // record: The record to write. - Record map[string]any `json:"record" cborgen:"record"` - // repo: The handle or DID of the repo (aka, current account). - Repo string `json:"repo" cborgen:"repo"` - // rkey: The Record Key. - Rkey string `json:"rkey" cborgen:"rkey"` - // swapCommit: Compare and swap with the previous commit by CID. - SwapCommit *string `json:"swapCommit,omitempty" cborgen:"swapCommit,omitempty"` - // swapRecord: Compare and swap with the previous record by CID. WARNING: nullable and optional field; may cause problems with golang implementation - SwapRecord *string `json:"swapRecord" cborgen:"swapRecord"` - // validate: Can be set to 'false' to skip Lexicon schema validation of record data, 'true' to require it, or leave unset to validate only for known Lexicons. - Validate *bool `json:"validate,omitempty" cborgen:"validate,omitempty"` -} - -// RepoPutRecord_Output is the output of a com.atproto.repo.putRecord call. -type RepoPutRecord_Output struct { - Cid string `json:"cid" cborgen:"cid"` - Commit *RepoDefs_CommitMeta `json:"commit,omitempty" cborgen:"commit,omitempty"` - Uri string `json:"uri" cborgen:"uri"` - ValidationStatus *string `json:"validationStatus,omitempty" cborgen:"validationStatus,omitempty"` -} - -// RepoPutRecord calls the XRPC method "com.atproto.repo.putRecord". -func RepoPutRecord(ctx context.Context, c *xrpc.Client, input *RepoPutRecord_Input) (*RepoPutRecord_Output, error) { - var out RepoPutRecord_Output - if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.repo.putRecord", nil, input, &out); err != nil { - return nil, err - } - - return &out, nil -} From e0b494894e88fa584ad1dd7739da0a2e53966a8e Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Thu, 5 Dec 2024 16:38:29 -0800 Subject: [PATCH 2/2] astrolabe: updates to use agnostic API helpers --- cmd/astrolabe/handlers.go | 5 +-- cmd/astrolabe/repogetRecord.go | 42 ------------------------- cmd/astrolabe/repolistRecords.go | 53 -------------------------------- 3 files changed, 3 insertions(+), 97 deletions(-) delete mode 100644 cmd/astrolabe/repogetRecord.go delete mode 100644 cmd/astrolabe/repolistRecords.go diff --git a/cmd/astrolabe/handlers.go b/cmd/astrolabe/handlers.go index f7732fe4e..f974fcf4c 100644 --- a/cmd/astrolabe/handlers.go +++ b/cmd/astrolabe/handlers.go @@ -6,6 +6,7 @@ import ( "net/http" "strings" + "github.com/bluesky-social/indigo/api/agnostic" comatproto "github.com/bluesky-social/indigo/api/atproto" _ "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/atproto/data" @@ -161,7 +162,7 @@ func (srv *Server) WebRepoCollection(c echo.Context) error { cursor := c.QueryParam("cursor") // collection string, cursor string, limit int64, repo string, reverse bool, rkeyEnd string, rkeyStart string - resp, err := RepoListRecords(ctx, &xrpcc, collection.String(), cursor, 100, ident.DID.String(), false, "", "") + resp, err := agnostic.RepoListRecords(ctx, &xrpcc, collection.String(), cursor, 100, ident.DID.String(), false, "", "") if err != nil { return err } @@ -218,7 +219,7 @@ func (srv *Server) WebRepoRecord(c echo.Context) error { xrpcc := xrpc.Client{ Host: ident.PDSEndpoint(), } - resp, err := RepoGetRecord(ctx, &xrpcc, "", collection.String(), ident.DID.String(), rkey.String()) + resp, err := agnostic.RepoGetRecord(ctx, &xrpcc, "", collection.String(), ident.DID.String(), rkey.String()) if err != nil { return echo.NewHTTPError(400, fmt.Sprintf("failed to load record: %s", err)) } diff --git a/cmd/astrolabe/repogetRecord.go b/cmd/astrolabe/repogetRecord.go deleted file mode 100644 index e3b857cd5..000000000 --- a/cmd/astrolabe/repogetRecord.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copied from indigo:api/atproto/repolistRecords.go - -package main - -// schema: com.atproto.repo.getRecord - -import ( - "context" - "encoding/json" - - "github.com/bluesky-social/indigo/xrpc" -) - -// RepoGetRecord_Output is the output of a com.atproto.repo.getRecord call. -type RepoGetRecord_Output struct { - Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"` - Uri string `json:"uri" cborgen:"uri"` - // NOTE: changed from lex decoder to json.RawMessage - Value *json.RawMessage `json:"value" cborgen:"value"` -} - -// RepoGetRecord calls the XRPC method "com.atproto.repo.getRecord". -// -// cid: The CID of the version of the record. If not specified, then return the most recent version. -// collection: The NSID of the record collection. -// repo: The handle or DID of the repo. -// rkey: The Record Key. -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, - } - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.repo.getRecord", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -} diff --git a/cmd/astrolabe/repolistRecords.go b/cmd/astrolabe/repolistRecords.go deleted file mode 100644 index 3cfdd9b24..000000000 --- a/cmd/astrolabe/repolistRecords.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copied from indigo:api/atproto/repolistRecords.go - -package main - -// schema: com.atproto.repo.listRecords - -import ( - "context" - "encoding/json" - - "github.com/bluesky-social/indigo/xrpc" -) - -// RepoListRecords_Output is the output of a com.atproto.repo.listRecords call. -type RepoListRecords_Output struct { - Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` - Records []*RepoListRecords_Record `json:"records" cborgen:"records"` -} - -// RepoListRecords_Record is a "record" in the com.atproto.repo.listRecords schema. -type RepoListRecords_Record struct { - Cid string `json:"cid" cborgen:"cid"` - Uri string `json:"uri" cborgen:"uri"` - // NOTE: changed from lex decoder to json.RawMessage - Value *json.RawMessage `json:"value" cborgen:"value"` -} - -// RepoListRecords calls the XRPC method "com.atproto.repo.listRecords". -// -// collection: The NSID of the record type. -// limit: The number of records to return. -// repo: The handle or DID of the repo. -// reverse: Flag to reverse the order of the returned records. -// rkeyEnd: DEPRECATED: The highest sort-ordered rkey to stop at (exclusive) -// rkeyStart: DEPRECATED: The lowest sort-ordered rkey to start from (exclusive) -func RepoListRecords(ctx context.Context, c *xrpc.Client, collection string, cursor string, limit int64, repo string, reverse bool, rkeyEnd string, rkeyStart string) (*RepoListRecords_Output, error) { - var out RepoListRecords_Output - - params := map[string]interface{}{ - "collection": collection, - "cursor": cursor, - "limit": limit, - "repo": repo, - "reverse": reverse, - "rkeyEnd": rkeyEnd, - "rkeyStart": rkeyStart, - } - if err := c.Do(ctx, xrpc.Query, "", "com.atproto.repo.listRecords", params, nil, &out); err != nil { - return nil, err - } - - return &out, nil -}