this repo has no description
0
fork

Configure Feed

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

goat: schema-flexible record creation, and prefs mgmt (#791)


Fixes: https://github.com/bluesky-social/indigo/issues/784

authored by

bnewbold and committed by
GitHub
12d29e93 d1686e9b

+165 -22
+2 -3
cmd/goat/account_migrate.go
··· 10 10 "time" 11 11 12 12 comatproto "github.com/bluesky-social/indigo/api/atproto" 13 - appbsky "github.com/bluesky-social/indigo/api/bsky" 14 13 "github.com/bluesky-social/indigo/atproto/syntax" 15 14 "github.com/bluesky-social/indigo/xrpc" 16 15 ··· 167 166 168 167 slog.Info("migrating preferences") 169 168 // TODO: service proxy header for AppView? 170 - prefResp, err := appbsky.ActorGetPreferences(ctx, oldClient) 169 + prefResp, err := ActorGetPreferences(ctx, oldClient) 171 170 if err != nil { 172 171 return fmt.Errorf("failed fetching old preferences: %w", err) 173 172 } 174 - err = appbsky.ActorPutPreferences(ctx, &newClient, &appbsky.ActorPutPreferences_Input{ 173 + err = ActorPutPreferences(ctx, &newClient, &ActorPutPreferences_Input{ 175 174 Preferences: prefResp.Preferences, 176 175 }) 177 176 if err != nil {
+28
cmd/goat/actorgetPreferences.go
··· 1 + // Copied from indigo:api/atproto/actorgetPreferences.go 2 + 3 + package main 4 + 5 + // schema: app.bsky.actor.getPreferences 6 + 7 + import ( 8 + "context" 9 + 10 + "github.com/bluesky-social/indigo/xrpc" 11 + ) 12 + 13 + // ActorGetPreferences_Output is the output of a app.bsky.actor.getPreferences call. 14 + type ActorGetPreferences_Output struct { 15 + Preferences []map[string]any `json:"preferences" cborgen:"preferences"` 16 + } 17 + 18 + // ActorGetPreferences calls the XRPC method "app.bsky.actor.getPreferences". 19 + func ActorGetPreferences(ctx context.Context, c *xrpc.Client) (*ActorGetPreferences_Output, error) { 20 + var out ActorGetPreferences_Output 21 + 22 + params := map[string]interface{}{} 23 + if err := c.Do(ctx, xrpc.Query, "", "app.bsky.actor.getPreferences", params, nil, &out); err != nil { 24 + return nil, err 25 + } 26 + 27 + return &out, nil 28 + }
+25
cmd/goat/actorputPreferences.go
··· 1 + // Copied from indigo:api/atproto/actorputPreferences.go 2 + 3 + package main 4 + 5 + // schema: app.bsky.actor.putPreferences 6 + 7 + import ( 8 + "context" 9 + 10 + "github.com/bluesky-social/indigo/xrpc" 11 + ) 12 + 13 + // ActorPutPreferences_Input is the input argument to a app.bsky.actor.putPreferences call. 14 + type ActorPutPreferences_Input struct { 15 + Preferences []map[string]any `json:"preferences" cborgen:"preferences"` 16 + } 17 + 18 + // ActorPutPreferences calls the XRPC method "app.bsky.actor.putPreferences". 19 + func ActorPutPreferences(ctx context.Context, c *xrpc.Client, input *ActorPutPreferences_Input) error { 20 + if err := c.Do(ctx, xrpc.Procedure, "application/json", "app.bsky.actor.putPreferences", nil, input, nil); err != nil { 21 + return err 22 + } 23 + 24 + return nil 25 + }
+4 -8
cmd/goat/bsky_prefs.go
··· 6 6 "fmt" 7 7 "os" 8 8 9 - appbsky "github.com/bluesky-social/indigo/api/bsky" 10 - 11 9 "github.com/urfave/cli/v2" 12 10 ) 13 11 ··· 41 39 } 42 40 43 41 // TODO: does indigo API code crash with unsupported preference '$type'? Eg "Lexicon decoder" with unsupported type. 44 - resp, err := appbsky.ActorGetPreferences(ctx, xrpcc) 42 + resp, err := ActorGetPreferences(ctx, xrpcc) 45 43 if err != nil { 46 44 return fmt.Errorf("failed fetching old preferences: %w", err) 47 45 } ··· 74 72 return err 75 73 } 76 74 77 - var prefsArray []appbsky.ActorDefs_Preferences_Elem 78 - err = json.Unmarshal(prefsBytes, &prefsArray) 79 - if err != nil { 75 + var prefsArray []map[string]any 76 + if err = json.Unmarshal(prefsBytes, &prefsArray); err != nil { 80 77 return err 81 78 } 82 79 83 - // WARNING: might clobber off-Lexicon or new-Lexicon data fields (which don't round-trip deserialization) 84 - err = appbsky.ActorPutPreferences(ctx, xrpcc, &appbsky.ActorPutPreferences_Input{ 80 + err = ActorPutPreferences(ctx, xrpcc, &ActorPutPreferences_Input{ 85 81 Preferences: prefsArray, 86 82 }) 87 83 if err != nil {
+8 -11
cmd/goat/record.go
··· 10 10 "github.com/bluesky-social/indigo/atproto/data" 11 11 "github.com/bluesky-social/indigo/atproto/identity" 12 12 "github.com/bluesky-social/indigo/atproto/syntax" 13 - lexutil "github.com/bluesky-social/indigo/lex/util" 14 13 "github.com/bluesky-social/indigo/xrpc" 15 14 16 15 "github.com/urfave/cli/v2" ··· 231 230 return err 232 231 } 233 232 234 - // TODO: replace this with something that allows arbitrary Lexicons, instead of needing registered types 235 - var recordVal lexutil.LexiconTypeDecoder 236 - if err = recordVal.UnmarshalJSON(recordBytes); err != nil { 233 + recordVal, err := data.UnmarshalJSON(recordBytes) 234 + if err != nil { 237 235 return err 238 236 } 239 237 ··· 248 246 } 249 247 validate := !cctx.Bool("no-validate") 250 248 251 - resp, err := comatproto.RepoCreateRecord(ctx, xrpcc, &comatproto.RepoCreateRecord_Input{ 249 + resp, err := RepoCreateRecord(ctx, xrpcc, &RepoCreateRecord_Input{ 252 250 Collection: nsid, 253 251 Repo: xrpcc.Auth.Did, 254 - Record: &recordVal, 252 + Record: recordVal, 255 253 Rkey: rkey, 256 254 Validate: &validate, 257 255 }) ··· 300 298 return err 301 299 } 302 300 303 - // TODO: replace this with something that allows arbitrary Lexicons, instead of needing registered types 304 - var recordVal lexutil.LexiconTypeDecoder 305 - if err = recordVal.UnmarshalJSON(recordBytes); err != nil { 301 + recordVal, err := data.UnmarshalJSON(recordBytes) 302 + if err != nil { 306 303 return err 307 304 } 308 305 309 306 validate := !cctx.Bool("no-validate") 310 307 311 - resp, err := comatproto.RepoPutRecord(ctx, xrpcc, &comatproto.RepoPutRecord_Input{ 308 + resp, err := RepoPutRecord(ctx, xrpcc, &RepoPutRecord_Input{ 312 309 Collection: nsid, 313 310 Repo: xrpcc.Auth.Did, 314 - Record: &recordVal, 311 + Record: recordVal, 315 312 Rkey: rkey, 316 313 Validate: &validate, 317 314 SwapRecord: existing.Cid,
+51
cmd/goat/repocreateRecord.go
··· 1 + // Copied from indigo:api/atproto/repocreateRecords.go 2 + 3 + package main 4 + 5 + // schema: com.atproto.repo.createRecord 6 + 7 + import ( 8 + "context" 9 + 10 + "github.com/bluesky-social/indigo/xrpc" 11 + ) 12 + 13 + // RepoDefs_CommitMeta is a "commitMeta" in the com.atproto.repo.defs schema. 14 + type RepoDefs_CommitMeta struct { 15 + Cid string `json:"cid" cborgen:"cid"` 16 + Rev string `json:"rev" cborgen:"rev"` 17 + } 18 + 19 + // RepoCreateRecord_Input is the input argument to a com.atproto.repo.createRecord call. 20 + type RepoCreateRecord_Input struct { 21 + // collection: The NSID of the record collection. 22 + Collection string `json:"collection" cborgen:"collection"` 23 + // record: The record itself. Must contain a $type field. 24 + Record map[string]any `json:"record" cborgen:"record"` 25 + // repo: The handle or DID of the repo (aka, current account). 26 + Repo string `json:"repo" cborgen:"repo"` 27 + // rkey: The Record Key. 28 + Rkey *string `json:"rkey,omitempty" cborgen:"rkey,omitempty"` 29 + // swapCommit: Compare and swap with the previous commit by CID. 30 + SwapCommit *string `json:"swapCommit,omitempty" cborgen:"swapCommit,omitempty"` 31 + // 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. 32 + Validate *bool `json:"validate,omitempty" cborgen:"validate,omitempty"` 33 + } 34 + 35 + // RepoCreateRecord_Output is the output of a com.atproto.repo.createRecord call. 36 + type RepoCreateRecord_Output struct { 37 + Cid string `json:"cid" cborgen:"cid"` 38 + Commit *RepoDefs_CommitMeta `json:"commit,omitempty" cborgen:"commit,omitempty"` 39 + Uri string `json:"uri" cborgen:"uri"` 40 + ValidationStatus *string `json:"validationStatus,omitempty" cborgen:"validationStatus,omitempty"` 41 + } 42 + 43 + // RepoCreateRecord calls the XRPC method "com.atproto.repo.createRecord". 44 + func RepoCreateRecord(ctx context.Context, c *xrpc.Client, input *RepoCreateRecord_Input) (*RepoCreateRecord_Output, error) { 45 + var out RepoCreateRecord_Output 46 + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.repo.createRecord", nil, input, &out); err != nil { 47 + return nil, err 48 + } 49 + 50 + return &out, nil 51 + }
+47
cmd/goat/repoputRecord.go
··· 1 + // Copied from indigo:api/atproto/repoputRecords.go 2 + 3 + package main 4 + 5 + // schema: com.atproto.repo.putRecord 6 + 7 + import ( 8 + "context" 9 + 10 + "github.com/bluesky-social/indigo/xrpc" 11 + ) 12 + 13 + // RepoPutRecord_Input is the input argument to a com.atproto.repo.putRecord call. 14 + type RepoPutRecord_Input struct { 15 + // collection: The NSID of the record collection. 16 + Collection string `json:"collection" cborgen:"collection"` 17 + // record: The record to write. 18 + Record map[string]any `json:"record" cborgen:"record"` 19 + // repo: The handle or DID of the repo (aka, current account). 20 + Repo string `json:"repo" cborgen:"repo"` 21 + // rkey: The Record Key. 22 + Rkey string `json:"rkey" cborgen:"rkey"` 23 + // swapCommit: Compare and swap with the previous commit by CID. 24 + SwapCommit *string `json:"swapCommit,omitempty" cborgen:"swapCommit,omitempty"` 25 + // swapRecord: Compare and swap with the previous record by CID. WARNING: nullable and optional field; may cause problems with golang implementation 26 + SwapRecord *string `json:"swapRecord" cborgen:"swapRecord"` 27 + // 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. 28 + Validate *bool `json:"validate,omitempty" cborgen:"validate,omitempty"` 29 + } 30 + 31 + // RepoPutRecord_Output is the output of a com.atproto.repo.putRecord call. 32 + type RepoPutRecord_Output struct { 33 + Cid string `json:"cid" cborgen:"cid"` 34 + Commit *RepoDefs_CommitMeta `json:"commit,omitempty" cborgen:"commit,omitempty"` 35 + Uri string `json:"uri" cborgen:"uri"` 36 + ValidationStatus *string `json:"validationStatus,omitempty" cborgen:"validationStatus,omitempty"` 37 + } 38 + 39 + // RepoPutRecord calls the XRPC method "com.atproto.repo.putRecord". 40 + func RepoPutRecord(ctx context.Context, c *xrpc.Client, input *RepoPutRecord_Input) (*RepoPutRecord_Output, error) { 41 + var out RepoPutRecord_Output 42 + if err := c.Do(ctx, xrpc.Procedure, "application/json", "com.atproto.repo.putRecord", nil, input, &out); err != nil { 43 + return nil, err 44 + } 45 + 46 + return &out, nil 47 + }