Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexicon: optional aggregated fields on views #684

Merged
merged 3 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

"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 @@ -121,9 +121,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 @@ -140,9 +137,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 @@ -157,9 +151,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 @@ -235,7 +235,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 @@ -403,7 +403,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 @@ -600,7 +600,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