Skip to content

Commit

Permalink
Unify pagination interface across all methods (bluesky-social#242)
Browse files Browse the repository at this point in the history
* Update lexicons for cursor convention, fix minor cid usage in interface

* Liked by cursor pagination, temp fix for other tests

* Home and author feed cursor pagination

* Paginate crud list w/ cursor, minor adjustments to lex and xrpc

* Paginate notifications view w/ cursor

* Paginate reposts view w/ cursor

* Paginate follow views w/ cursor

* Paginate user search view w/ cursor

* Fix notification tests

* Make repoListRecords order desc by default for consistency

* Paginate badge memebers view w/ cursor
  • Loading branch information
devinivy authored Oct 17, 2022
1 parent 60a537a commit 0820013
Show file tree
Hide file tree
Showing 62 changed files with 539 additions and 410 deletions.
3 changes: 2 additions & 1 deletion lexicons/atproto.com/repoListRecords.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"type": "object",
"required": ["records"],
"properties": {
"cursor": {"type": "string"},
"records": {
"type": "array",
"items": {
Expand All @@ -32,4 +33,4 @@
}
}
}
}
}
6 changes: 3 additions & 3 deletions lexicons/bsky.app/getAuthorFeed.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"type": "object",
"required": ["feed"],
"properties": {
"cursor": {"type": "string"},
"feed": {
"type": "array",
"items": {"$ref": "#/defs/feedItem"}
Expand All @@ -24,9 +25,8 @@
"defs": {
"feedItem": {
"type": "object",
"required": ["cursor", "uri", "cid", "author", "record", "replyCount", "repostCount", "likeCount", "indexedAt"],
"required": ["uri", "cid", "author", "record", "replyCount", "repostCount", "likeCount", "indexedAt"],
"properties": {
"cursor": {"type": "string"},
"uri": {"type": "string"},
"cid": {"type": "string"},
"author": {"$ref": "#/defs/user"},
Expand Down Expand Up @@ -95,4 +95,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion lexicons/bsky.app/getBadgeMembers.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"properties": {
"uri": {"type": "string"},
"cid": {"type": "string"},
"cursor": {"type": "string"},
"members": {
"type": "array",
"items": {
Expand All @@ -36,4 +37,4 @@
}
}
}
}
}
6 changes: 3 additions & 3 deletions lexicons/bsky.app/getHomeFeed.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"type": "object",
"required": ["feed"],
"properties": {
"cursor": {"type": "string"},
"feed": {
"type": "array",
"items": {"$ref": "#/defs/feedItem"}
Expand All @@ -24,9 +25,8 @@
"defs": {
"feedItem": {
"type": "object",
"required": ["cursor", "uri", "cid", "author", "record", "replyCount", "repostCount", "likeCount", "indexedAt"],
"required": ["uri", "cid", "author", "record", "replyCount", "repostCount", "likeCount", "indexedAt"],
"properties": {
"cursor": {"type": "string"},
"uri": {"type": "string"},
"cid": {"type": "string"},
"author": {"$ref": "#/defs/user"},
Expand Down Expand Up @@ -95,4 +95,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion lexicons/bsky.app/getLikedBy.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"properties": {
"uri": {"type": "string"},
"cid": {"type": "string"},
"cursor": {"type": "string"},
"likedBy": {
"type": "array",
"items": {
Expand All @@ -36,4 +37,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion lexicons/bsky.app/getNotifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"type": "object",
"required": ["notifications"],
"properties": {
"cursor": {"type": "string"},
"notifications": {
"type": "array",
"items": {"$ref": "#/defs/notification"}
Expand Down Expand Up @@ -49,4 +50,4 @@
}
}
}
}
}
4 changes: 3 additions & 1 deletion lexicons/bsky.app/getRepostedBy.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"required": ["uri", "repostedBy"],
"properties": {
"uri": {"type": "string"},
"cid": {"type": "string"},
"cursor": {"type": "string"},
"repostedBy": {
"type": "array",
"items": {
Expand All @@ -35,4 +37,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion lexicons/bsky.app/getUserFollowers.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
}
}
},
"cursor": {"type": "string"},
"followers": {
"type": "array",
"items": {
Expand All @@ -46,4 +47,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion lexicons/bsky.app/getUserFollows.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
}
}
},
"cursor": {"type": "string"},
"follows": {
"type": "array",
"items": {
Expand All @@ -46,4 +47,4 @@
}
}
}
}
}
6 changes: 3 additions & 3 deletions lexicons/bsky.app/getUsersSearch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
"type": "object",
"required": ["users"],
"properties": {
"cursor": {"type": "string"},
"users": {
"type": "array",
"items": {
"type": "object",
"required": ["did", "name", "createdAt", "indexedAt", "cursor"],
"required": ["did", "name", "createdAt", "indexedAt"],
"properties": {
"did": {"type": "string"},
"name": {"type": "string"},
Expand All @@ -28,8 +29,7 @@
},
"description": {"type": "string"},
"createdAt": {"type": "string", "format": "date-time"},
"indexedAt": {"type": "string", "format": "date-time"},
"cursor": {"type": "string"}
"indexedAt": {"type": "string", "format": "date-time"}
}
}
}
Expand Down
45 changes: 36 additions & 9 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,10 @@ export class BadgeRecord {

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>
): Promise<{ records: { uri: string, value: AppBskyBadge.Record }[] }> {
): Promise<{
cursor?: string,
records: { uri: string, value: AppBskyBadge.Record }[],
}> {
const res = await this._service.xrpc.call('com.atproto.repoListRecords', {
collection: 'app.bsky.badge',
...params,
Expand Down Expand Up @@ -681,7 +684,10 @@ export class BadgeAcceptRecord {

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>
): Promise<{ records: { uri: string, value: AppBskyBadgeAccept.Record }[] }> {
): Promise<{
cursor?: string,
records: { uri: string, value: AppBskyBadgeAccept.Record }[],
}> {
const res = await this._service.xrpc.call('com.atproto.repoListRecords', {
collection: 'app.bsky.badgeAccept',
...params,
Expand Down Expand Up @@ -736,7 +742,10 @@ export class BadgeOfferRecord {

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>
): Promise<{ records: { uri: string, value: AppBskyBadgeOffer.Record }[] }> {
): Promise<{
cursor?: string,
records: { uri: string, value: AppBskyBadgeOffer.Record }[],
}> {
const res = await this._service.xrpc.call('com.atproto.repoListRecords', {
collection: 'app.bsky.badgeOffer',
...params,
Expand Down Expand Up @@ -791,7 +800,10 @@ export class FollowRecord {

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>
): Promise<{ records: { uri: string, value: AppBskyFollow.Record }[] }> {
): Promise<{
cursor?: string,
records: { uri: string, value: AppBskyFollow.Record }[],
}> {
const res = await this._service.xrpc.call('com.atproto.repoListRecords', {
collection: 'app.bsky.follow',
...params,
Expand Down Expand Up @@ -846,7 +858,10 @@ export class LikeRecord {

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>
): Promise<{ records: { uri: string, value: AppBskyLike.Record }[] }> {
): Promise<{
cursor?: string,
records: { uri: string, value: AppBskyLike.Record }[],
}> {
const res = await this._service.xrpc.call('com.atproto.repoListRecords', {
collection: 'app.bsky.like',
...params,
Expand Down Expand Up @@ -901,7 +916,10 @@ export class MediaEmbedRecord {

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>
): Promise<{ records: { uri: string, value: AppBskyMediaEmbed.Record }[] }> {
): Promise<{
cursor?: string,
records: { uri: string, value: AppBskyMediaEmbed.Record }[],
}> {
const res = await this._service.xrpc.call('com.atproto.repoListRecords', {
collection: 'app.bsky.mediaEmbed',
...params,
Expand Down Expand Up @@ -956,7 +974,10 @@ export class PostRecord {

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>
): Promise<{ records: { uri: string, value: AppBskyPost.Record }[] }> {
): Promise<{
cursor?: string,
records: { uri: string, value: AppBskyPost.Record }[],
}> {
const res = await this._service.xrpc.call('com.atproto.repoListRecords', {
collection: 'app.bsky.post',
...params,
Expand Down Expand Up @@ -1011,7 +1032,10 @@ export class ProfileRecord {

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>
): Promise<{ records: { uri: string, value: AppBskyProfile.Record }[] }> {
): Promise<{
cursor?: string,
records: { uri: string, value: AppBskyProfile.Record }[],
}> {
const res = await this._service.xrpc.call('com.atproto.repoListRecords', {
collection: 'app.bsky.profile',
...params,
Expand Down Expand Up @@ -1066,7 +1090,10 @@ export class RepostRecord {

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>
): Promise<{ records: { uri: string, value: AppBskyRepost.Record }[] }> {
): Promise<{
cursor?: string,
records: { uri: string, value: AppBskyRepost.Record }[],
}> {
const res = await this._service.xrpc.call('com.atproto.repoListRecords', {
collection: 'app.bsky.repost',
...params,
Expand Down
Loading

0 comments on commit 0820013

Please sign in to comment.