Skip to content

Commit

Permalink
Merge pull request #684 from bluesky-social/lex/optional-agg-fields
Browse files Browse the repository at this point in the history
Lexicon: optional aggregated fields on views
  • Loading branch information
devinivy committed Mar 18, 2023
2 parents f4d3869 + e1e2d22 commit bb02c10
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 199 deletions.
13 changes: 2 additions & 11 deletions lexicons/app/bsky/actor/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"profileView": {
"type": "object",
"required": ["did", "handle", "creator", "followersCount", "followsCount", "postsCount"],
"required": ["did", "handle", "creator"],
"properties": {
"did": {"type": "string", "format": "did"},
"handle": {"type": "string"},
Expand All @@ -38,8 +38,7 @@
"postsCount": {"type": "integer"},
"creator": {"type": "string"},
"indexedAt": {"type": "string", "format": "datetime"},
"viewer": {"type": "ref", "ref": "#viewerState"},
"myState": {"type": "ref", "ref": "#myState", "description": "Deprecated"}
"viewer": {"type": "ref", "ref": "#viewerState"}
}
},
"profileViewBasic": {
Expand Down Expand Up @@ -68,14 +67,6 @@
"following": {"type": "string", "format": "at-uri"},
"followedBy": {"type": "string", "format": "at-uri"}
}
},
"myState": {
"type": "object",
"description": "Deprecated in favor of #viewerState",
"properties": {
"follow": {"type": "string", "format": "at-uri"},
"muted": {"type": "boolean"}
}
}
}
}
4 changes: 2 additions & 2 deletions lexicons/app/bsky/feed/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"defs": {
"postView": {
"type": "object",
"required": ["uri", "cid", "author", "record", "replyCount", "repostCount", "likeCount", "indexedAt", "viewer"],
"required": ["uri", "cid", "author", "record", "indexedAt"],
"properties": {
"uri": {"type": "string"},
"cid": {"type": "string"},
Expand Down Expand Up @@ -78,4 +78,4 @@
}
}
}
}
}
39 changes: 2 additions & 37 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2381,14 +2381,7 @@ export const schemaDict = {
},
profileView: {
type: 'object',
required: [
'did',
'handle',
'creator',
'followersCount',
'followsCount',
'postsCount',
],
required: ['did', 'handle', 'creator'],
properties: {
did: {
type: 'string',
Expand Down Expand Up @@ -2431,11 +2424,6 @@ export const schemaDict = {
type: 'ref',
ref: 'lex:app.bsky.actor.defs#viewerState',
},
myState: {
type: 'ref',
ref: 'lex:app.bsky.actor.defs#myState',
description: 'Deprecated',
},
},
},
profileViewBasic: {
Expand Down Expand Up @@ -2486,19 +2474,6 @@ export const schemaDict = {
},
},
},
myState: {
type: 'object',
description: 'Deprecated in favor of #viewerState',
properties: {
follow: {
type: 'string',
format: 'at-uri',
},
muted: {
type: 'boolean',
},
},
},
},
},
AppBskyActorGetProfile: {
Expand Down Expand Up @@ -3011,17 +2986,7 @@ export const schemaDict = {
defs: {
postView: {
type: 'object',
required: [
'uri',
'cid',
'author',
'record',
'replyCount',
'repostCount',
'likeCount',
'indexedAt',
'viewer',
],
required: ['uri', 'cid', 'author', 'record', 'indexedAt'],
properties: {
uri: {
type: 'string',
Expand Down
24 changes: 3 additions & 21 deletions packages/api/src/client/types/app/bsky/actor/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ export interface ProfileView {
description?: string
avatar?: string
banner?: string
followersCount: number
followsCount: number
postsCount: number
followersCount?: number
followsCount?: number
postsCount?: number
creator: string
indexedAt?: string
viewer?: ViewerState
myState?: MyState
[k: string]: unknown
}

Expand Down Expand Up @@ -96,20 +95,3 @@ export function isViewerState(v: unknown): v is ViewerState {
export function validateViewerState(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.actor.defs#viewerState', v)
}

/** Deprecated in favor of #viewerState */
export interface MyState {
follow?: string
muted?: boolean
[k: string]: unknown
}

export function isMyState(v: unknown): v is MyState {
return (
isObj(v) && hasProp(v, '$type') && v.$type === 'app.bsky.actor.defs#myState'
)
}

export function validateMyState(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.actor.defs#myState', v)
}
8 changes: 4 additions & 4 deletions packages/api/src/client/types/app/bsky/feed/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export interface PostView {
| AppBskyEmbedExternal.Presented
| AppBskyEmbedRecord.Presented
| { $type: string; [k: string]: unknown }
replyCount: number
repostCount: number
likeCount: number
replyCount?: number
repostCount?: number
likeCount?: number
indexedAt: string
viewer: ViewerState
viewer?: ViewerState
[k: string]: unknown
}

Expand Down
4 changes: 0 additions & 4 deletions packages/pds/src/app-view/services/actor/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ export class ActorViews {
following: profileInfo?.requesterFollowing || undefined,
followedBy: profileInfo?.requesterFollowedBy || undefined,
},
myState: {
follow: profileInfo?.requesterFollowing || undefined,
muted: !!profileInfo?.requesterMuted,
},
}
})

Expand Down
39 changes: 2 additions & 37 deletions packages/pds/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2381,14 +2381,7 @@ export const schemaDict = {
},
profileView: {
type: 'object',
required: [
'did',
'handle',
'creator',
'followersCount',
'followsCount',
'postsCount',
],
required: ['did', 'handle', 'creator'],
properties: {
did: {
type: 'string',
Expand Down Expand Up @@ -2431,11 +2424,6 @@ export const schemaDict = {
type: 'ref',
ref: 'lex:app.bsky.actor.defs#viewerState',
},
myState: {
type: 'ref',
ref: 'lex:app.bsky.actor.defs#myState',
description: 'Deprecated',
},
},
},
profileViewBasic: {
Expand Down Expand Up @@ -2486,19 +2474,6 @@ export const schemaDict = {
},
},
},
myState: {
type: 'object',
description: 'Deprecated in favor of #viewerState',
properties: {
follow: {
type: 'string',
format: 'at-uri',
},
muted: {
type: 'boolean',
},
},
},
},
},
AppBskyActorGetProfile: {
Expand Down Expand Up @@ -3011,17 +2986,7 @@ export const schemaDict = {
defs: {
postView: {
type: 'object',
required: [
'uri',
'cid',
'author',
'record',
'replyCount',
'repostCount',
'likeCount',
'indexedAt',
'viewer',
],
required: ['uri', 'cid', 'author', 'record', 'indexedAt'],
properties: {
uri: {
type: 'string',
Expand Down
24 changes: 3 additions & 21 deletions packages/pds/src/lexicon/types/app/bsky/actor/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ export interface ProfileView {
description?: string
avatar?: string
banner?: string
followersCount: number
followsCount: number
postsCount: number
followersCount?: number
followsCount?: number
postsCount?: number
creator: string
indexedAt?: string
viewer?: ViewerState
myState?: MyState
[k: string]: unknown
}

Expand Down Expand Up @@ -96,20 +95,3 @@ export function isViewerState(v: unknown): v is ViewerState {
export function validateViewerState(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.actor.defs#viewerState', v)
}

/** Deprecated in favor of #viewerState */
export interface MyState {
follow?: string
muted?: boolean
[k: string]: unknown
}

export function isMyState(v: unknown): v is MyState {
return (
isObj(v) && hasProp(v, '$type') && v.$type === 'app.bsky.actor.defs#myState'
)
}

export function validateMyState(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.actor.defs#myState', v)
}
8 changes: 4 additions & 4 deletions packages/pds/src/lexicon/types/app/bsky/feed/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export interface PostView {
| AppBskyEmbedExternal.Presented
| AppBskyEmbedRecord.Presented
| { $type: string; [k: string]: unknown }
replyCount: number
repostCount: number
likeCount: number
replyCount?: number
repostCount?: number
likeCount?: number
indexedAt: string
viewer: ViewerState
viewer?: ViewerState
[k: string]: unknown
}

Expand Down
9 changes: 0 additions & 9 deletions packages/pds/tests/__snapshots__/indexing.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ Object {
"followsCount": 0,
"handle": "dan.test",
"indexedAt": "1970-01-01T00:00:00.000Z",
"myState": Object {
"muted": false,
},
"postsCount": 0,
"viewer": Object {
"muted": false,
Expand All @@ -144,9 +141,6 @@ Object {
"followsCount": 0,
"handle": "dan.test",
"indexedAt": "1970-01-01T00:00:00.000Z",
"myState": Object {
"muted": false,
},
"postsCount": 0,
"viewer": Object {
"muted": false,
Expand All @@ -161,9 +155,6 @@ Object {
"followersCount": 0,
"followsCount": 0,
"handle": "dan.test",
"myState": Object {
"muted": false,
},
"postsCount": 0,
"viewer": Object {
"muted": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`pds author feed views fetches full author feeds for self (sorted, minimal myState). 1`] = `
exports[`pds author feed views fetches full author feeds for self (sorted, minimal viewer state). 1`] = `
Array [
Object {
"post": Object {
Expand Down Expand Up @@ -237,7 +237,7 @@ Array [
]
`;

exports[`pds author feed views fetches full author feeds for self (sorted, minimal myState). 2`] = `
exports[`pds author feed views fetches full author feeds for self (sorted, minimal viewer state). 2`] = `
Array [
Object {
"post": Object {
Expand Down Expand Up @@ -405,7 +405,7 @@ Array [
]
`;

exports[`pds author feed views fetches full author feeds for self (sorted, minimal myState). 3`] = `
exports[`pds author feed views fetches full author feeds for self (sorted, minimal viewer state). 3`] = `
Array [
Object {
"post": Object {
Expand Down Expand Up @@ -604,7 +604,7 @@ Array [
]
`;

exports[`pds author feed views fetches full author feeds for self (sorted, minimal myState). 4`] = `
exports[`pds author feed views fetches full author feeds for self (sorted, minimal viewer state). 4`] = `
Array [
Object {
"post": Object {
Expand Down
Loading

0 comments on commit bb02c10

Please sign in to comment.