Skip to content

Commit

Permalink
Support firehose feed algorithm (bluesky-social#205)
Browse files Browse the repository at this point in the history
* Split getFeed() into getAuthorFeed() and getHomeFeed()

* Remove unused getFeed codegen file

* Unify queries for getHomeFeed and getAuthorFeed

* Factor out common query parts for building feeds

* Test firehose and default feed algorithm

* Fix api tsconfig reference
  • Loading branch information
devinivy authored Oct 4, 2022
1 parent c70911a commit d64e4f6
Show file tree
Hide file tree
Showing 17 changed files with 1,037 additions and 224 deletions.
32 changes: 23 additions & 9 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import * as TodoAdxSyncGetRoot from './types/todo/adx/syncGetRoot'
import * as TodoAdxSyncUpdateRepo from './types/todo/adx/syncUpdateRepo'
import * as TodoSocialBadge from './types/todo/social/badge'
import * as TodoSocialFollow from './types/todo/social/follow'
import * as TodoSocialGetFeed from './types/todo/social/getFeed'
import * as TodoSocialGetAuthorFeed from './types/todo/social/getAuthorFeed'
import * as TodoSocialGetHomeFeed from './types/todo/social/getHomeFeed'
import * as TodoSocialGetLikedBy from './types/todo/social/getLikedBy'
import * as TodoSocialGetNotificationCount from './types/todo/social/getNotificationCount'
import * as TodoSocialGetNotifications from './types/todo/social/getNotifications'
Expand Down Expand Up @@ -62,7 +63,8 @@ export * as TodoAdxSyncGetRoot from './types/todo/adx/syncGetRoot'
export * as TodoAdxSyncUpdateRepo from './types/todo/adx/syncUpdateRepo'
export * as TodoSocialBadge from './types/todo/social/badge'
export * as TodoSocialFollow from './types/todo/social/follow'
export * as TodoSocialGetFeed from './types/todo/social/getFeed'
export * as TodoSocialGetAuthorFeed from './types/todo/social/getAuthorFeed'
export * as TodoSocialGetHomeFeed from './types/todo/social/getHomeFeed'
export * as TodoSocialGetLikedBy from './types/todo/social/getLikedBy'
export * as TodoSocialGetNotificationCount from './types/todo/social/getNotificationCount'
export * as TodoSocialGetNotifications from './types/todo/social/getNotifications'
Expand Down Expand Up @@ -366,15 +368,27 @@ export class SocialNS {
this.repost = new RepostRecord(service)
}

getFeed(
params: TodoSocialGetFeed.QueryParams,
data?: TodoSocialGetFeed.InputSchema,
opts?: TodoSocialGetFeed.CallOptions
): Promise<TodoSocialGetFeed.Response> {
getAuthorFeed(
params: TodoSocialGetAuthorFeed.QueryParams,
data?: TodoSocialGetAuthorFeed.InputSchema,
opts?: TodoSocialGetAuthorFeed.CallOptions
): Promise<TodoSocialGetAuthorFeed.Response> {
return this._service.xrpc
.call('todo.social.getFeed', params, data, opts)
.call('todo.social.getAuthorFeed', params, data, opts)
.catch((e) => {
throw TodoSocialGetFeed.toKnownErr(e)
throw TodoSocialGetAuthorFeed.toKnownErr(e)
})
}

getHomeFeed(
params: TodoSocialGetHomeFeed.QueryParams,
data?: TodoSocialGetHomeFeed.InputSchema,
opts?: TodoSocialGetHomeFeed.CallOptions
): Promise<TodoSocialGetHomeFeed.Response> {
return this._service.xrpc
.call('todo.social.getHomeFeed', params, data, opts)
.catch((e) => {
throw TodoSocialGetHomeFeed.toKnownErr(e)
})
}

Expand Down
170 changes: 168 additions & 2 deletions packages/api/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,178 @@ export const methodSchemas: MethodSchema[] = [
},
{
lexicon: 1,
id: 'todo.social.getFeed',
id: 'todo.social.getAuthorFeed',
type: 'query',
description: "A computed view of the home feed or a user's feed",
description: "A view of a user's feed",
parameters: {
author: {
type: 'string',
required: true,
},
limit: {
type: 'number',
maximum: 100,
},
before: {
type: 'string',
},
},
output: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['feed'],
properties: {
feed: {
type: 'array',
items: {
$ref: '#/$defs/feedItem',
},
},
},
$defs: {
feedItem: {
type: 'object',
required: [
'uri',
'author',
'record',
'replyCount',
'repostCount',
'likeCount',
'indexedAt',
],
properties: {
cursor: {
type: 'string',
},
uri: {
type: 'string',
},
author: {
$ref: '#/$defs/user',
},
repostedBy: {
$ref: '#/$defs/user',
},
record: {
type: 'object',
},
embed: {
oneOf: [
{
$ref: '#/$defs/recordEmbed',
},
{
$ref: '#/$defs/externalEmbed',
},
{
$ref: '#/$defs/unknownEmbed',
},
],
},
replyCount: {
type: 'number',
},
repostCount: {
type: 'number',
},
likeCount: {
type: 'number',
},
indexedAt: {
type: 'string',
format: 'date-time',
},
myState: {
type: 'object',
properties: {
repost: {
type: 'string',
},
like: {
type: 'string',
},
},
},
},
},
user: {
type: 'object',
required: ['did', 'name'],
properties: {
did: {
type: 'string',
},
name: {
type: 'string',
},
displayName: {
type: 'string',
maxLength: 64,
},
},
},
recordEmbed: {
type: 'object',
required: ['type', 'author', 'record'],
properties: {
type: {
const: 'record',
},
author: {
$ref: '#/$defs/user',
},
record: {
type: 'object',
},
},
},
externalEmbed: {
type: 'object',
required: ['type', 'uri', 'title', 'description', 'imageUri'],
properties: {
type: {
const: 'external',
},
uri: {
type: 'string',
},
title: {
type: 'string',
},
description: {
type: 'string',
},
imageUri: {
type: 'string',
},
},
},
unknownEmbed: {
type: 'object',
required: ['type'],
properties: {
type: {
type: 'string',
not: {
enum: ['record', 'external'],
},
},
},
},
},
},
},
},
{
lexicon: 1,
id: 'todo.social.getHomeFeed',
type: 'query',
description: "A view of the user's home feed",
parameters: {
algorithm: {
type: 'string',
},
limit: {
type: 'number',
Expand Down
68 changes: 68 additions & 0 deletions packages/api/src/types/todo/social/getAuthorFeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { Headers, XRPCError } from '@adxp/xrpc'

export interface QueryParams {
author: string;
limit?: number;
before?: string;
}

export interface CallOptions {
headers?: Headers;
}

export type InputSchema = undefined

export interface OutputSchema {
feed: FeedItem[];
}
export interface FeedItem {
cursor?: string;
uri: string;
author: User;
repostedBy?: User;
record: {};
embed?: RecordEmbed | ExternalEmbed | UnknownEmbed;
replyCount: number;
repostCount: number;
likeCount: number;
indexedAt: string;
myState?: {
repost?: string,
like?: string,
};
}
export interface User {
did: string;
name: string;
displayName?: string;
}
export interface RecordEmbed {
type: 'record';
author: User;
record: {};
}
export interface ExternalEmbed {
type: 'external';
uri: string;
title: string;
description: string;
imageUri: string;
}
export interface UnknownEmbed {
type: string;
}

export interface Response {
success: boolean;
headers: Headers;
data: OutputSchema;
}

export function toKnownErr(e: any) {
if (e instanceof XRPCError) {
}
return e
}
68 changes: 68 additions & 0 deletions packages/api/src/types/todo/social/getHomeFeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { Headers, XRPCError } from '@adxp/xrpc'

export interface QueryParams {
algorithm?: string;
limit?: number;
before?: string;
}

export interface CallOptions {
headers?: Headers;
}

export type InputSchema = undefined

export interface OutputSchema {
feed: FeedItem[];
}
export interface FeedItem {
cursor?: string;
uri: string;
author: User;
repostedBy?: User;
record: {};
embed?: RecordEmbed | ExternalEmbed | UnknownEmbed;
replyCount: number;
repostCount: number;
likeCount: number;
indexedAt: string;
myState?: {
repost?: string,
like?: string,
};
}
export interface User {
did: string;
name: string;
displayName?: string;
}
export interface RecordEmbed {
type: 'record';
author: User;
record: {};
}
export interface ExternalEmbed {
type: 'external';
uri: string;
title: string;
description: string;
imageUri: string;
}
export interface UnknownEmbed {
type: string;
}

export interface Response {
success: boolean;
headers: Headers;
data: OutputSchema;
}

export function toKnownErr(e: any) {
if (e instanceof XRPCError) {
}
return e
}
4 changes: 2 additions & 2 deletions packages/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"include": ["./src"],
"references": [
{ "path": "../xrpc/tsconfig.build.json" },
{ "path": "../xrpc-cli/tsconfig.build.json" },
{ "path": "../lex-cli/tsconfig.build.json" }
]
}
}
Loading

0 comments on commit d64e4f6

Please sign in to comment.