Implement autogenerated Record Namespaces
MarshalX opened this issue · comments
Provide autogenerated Record Namespaces with more high-level work with basic operations upon records (CRUD + list records)
this is how we work with records now:
self.com.atproto.repo.delete_record(
models.ComAtprotoRepoDeleteRecord.Data(
collection=ids.AppBskyFeedPost,
repo=uri.hostname,
rkey=uri.rkey,
)
)
this is how it could be (.post
is autogenerated PostRecordNamespace
):
self.bsky.feed.post.delete(repo, rkey)
let's think about the benefits.
- you write less and simpler code
- you don't need to care about "collection" arg
- you definitely know which record type is required for input. good auto-completion and type annotating
- you definitely know which record type will be returned. good auto-completion and type annotating
- return models are isolated from models of AT Protocol
create
low lvl API:
post_record = models.AppBskyFeedPost.Main(text='test record namespaces', created_at=client.get_current_time_iso())
client.com.atproto.repo.create_record(
models.ComAtprotoRepoCreateRecord.Data(
repo=client.me.did,
collection=ids.AppBskyFeedPost,
record=post_record
)
)
sugar:
post_record = models.AppBskyFeedPost.Main(text='test record namespaces', created_at=client.get_current_time_iso())
new_post = client.app.bsky.feed.post.create(client.me.did, post_record)
get
low lvl API:
post = client.com.atproto.repo.get_record(
models.ComAtprotoRepoGetRecord.Params(
collection=ids.AppBskyFeedPost,
repo=client.me.did,
rkey=rkey,
)
)
sugar:
post = client.app.bsky.feed.post.get(client.me.did, rkey)
delete
low lvl API:
self.com.atproto.repo.delete_record(
models.ComAtprotoRepoDeleteRecord.Data(
collection=ids.AppBskyFeedPost,
repo=did,
rkey=rkey,
)
)
sugar:
client.app.bsky.feed.post.delete(did, rkey)
list
low lvl API:
posts = client.com.atproto.repo.list_records(
models.ComAtprotoRepoListRecords.Params(
collection=ids.AppBskyFeedPost,
repo=client.me.did
)
)
sugar:
posts = client.app.bsky.feed.post.list(client.me.did)