-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Little hack to make `goat` work better with generic record data, aka when we don't know the Lexicon. In this context, just dumping the JSON to stdout (pretty printed). Sharing b/c we might want to do this generally, at least for API endpoints: `json.RawMessage` instead of `lexutil.LexiconTypeDecoder` when we encounter `unknown` schema type. Note that this won't work for records, and the schema rules do allow `unknown` in records, it just hasn't happened yet. Another place we encounter this is DID documents, which don't even have `$type` in the JSON.
- Loading branch information
Showing
4 changed files
with
106 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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 | ||
} |