Skip to content

Commit

Permalink
Merge pull request #674 from bluesky-social/lex/richtext
Browse files Browse the repository at this point in the history
Lexicon: richtext facets, replacing post entities
  • Loading branch information
devinivy committed Mar 17, 2023
2 parents 006db84 + 57fa01f commit b0254c8
Show file tree
Hide file tree
Showing 27 changed files with 541 additions and 137 deletions.
5 changes: 5 additions & 0 deletions lexicons/app/bsky/feed/post.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
"text": {"type": "string", "maxLength": 3000, "maxGraphemes": 300},
"entities": {
"type": "array",
"description": "Deprecated: replaced by app.bsky.richtext.facet.",
"items": {"type": "ref", "ref": "#entity"}
},
"facets": {
"type": "array",
"items": {"type": "ref", "ref": "app.bsky.richtext.facet"}
},
"reply": {"type": "ref", "ref": "#replyRef"},
"embed": {
"type": "union",
Expand Down
39 changes: 39 additions & 0 deletions lexicons/app/bsky/richtext/facet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"lexicon": 1,
"id": "app.bsky.richtext.facet",
"defs": {
"main": {
"type": "object",
"required": ["index", "value"],
"properties": {
"index": {"type": "ref", "ref": "#textSlice"},
"value": {"type": "union", "refs": ["#mention", "#link"]}
}
},
"mention": {
"type": "object",
"description": "A facet value for actor mentions.",
"required": ["did"],
"properties": {
"did": {"type": "string", "format": "did"}
}
},
"link": {
"type": "object",
"description": "A facet value for links.",
"required": ["uri"],
"properties": {
"uri": {"type": "string"}
}
},
"textSlice": {
"type": "object",
"description": "A text segment. Start is inclusive, end is exclusive.",
"required": ["start", "end"],
"properties": {
"start": {"type": "integer", "minimum": 0},
"end": {"type": "integer", "minimum": 0}
}
}
}
}
12 changes: 12 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import * as AppBskyGraphUnmuteActor from './types/app/bsky/graph/unmuteActor'
import * as AppBskyNotificationGetUnreadCount from './types/app/bsky/notification/getUnreadCount'
import * as AppBskyNotificationListNotifications from './types/app/bsky/notification/listNotifications'
import * as AppBskyNotificationUpdateSeen from './types/app/bsky/notification/updateSeen'
import * as AppBskyRichtextFacet from './types/app/bsky/richtext/facet'

export * as ComAtprotoAdminDefs from './types/com/atproto/admin/defs'
export * as ComAtprotoAdminGetModerationAction from './types/com/atproto/admin/getModerationAction'
Expand Down Expand Up @@ -161,6 +162,7 @@ export * as AppBskyGraphUnmuteActor from './types/app/bsky/graph/unmuteActor'
export * as AppBskyNotificationGetUnreadCount from './types/app/bsky/notification/getUnreadCount'
export * as AppBskyNotificationListNotifications from './types/app/bsky/notification/listNotifications'
export * as AppBskyNotificationUpdateSeen from './types/app/bsky/notification/updateSeen'
export * as AppBskyRichtextFacet from './types/app/bsky/richtext/facet'

export const COM_ATPROTO_ADMIN = {
DefsTakedown: 'com.atproto.admin.defs#takedown',
Expand Down Expand Up @@ -763,6 +765,7 @@ export class BskyNS {
feed: FeedNS
graph: GraphNS
notification: NotificationNS
richtext: RichtextNS

constructor(service: AtpServiceClient) {
this._service = service
Expand All @@ -771,6 +774,7 @@ export class BskyNS {
this.feed = new FeedNS(service)
this.graph = new GraphNS(service)
this.notification = new NotificationNS(service)
this.richtext = new RichtextNS(service)
}
}

Expand Down Expand Up @@ -1337,3 +1341,11 @@ export class NotificationNS {
})
}
}

export class RichtextNS {
_service: AtpServiceClient

constructor(service: AtpServiceClient) {
this._service = service
}
}
68 changes: 68 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3479,11 +3479,19 @@ export const schemaDict = {
},
entities: {
type: 'array',
description: 'Deprecated: replaced by app.bsky.richtext.facet.',
items: {
type: 'ref',
ref: 'lex:app.bsky.feed.post#entity',
},
},
facets: {
type: 'array',
items: {
type: 'ref',
ref: 'lex:app.bsky.richtext.facet',
},
},
reply: {
type: 'ref',
ref: 'lex:app.bsky.feed.post#replyRef',
Expand Down Expand Up @@ -3944,6 +3952,65 @@ export const schemaDict = {
},
},
},
AppBskyRichtextFacet: {
lexicon: 1,
id: 'app.bsky.richtext.facet',
defs: {
main: {
type: 'object',
required: ['index', 'value'],
properties: {
index: {
type: 'ref',
ref: 'lex:app.bsky.richtext.facet#textSlice',
},
value: {
type: 'union',
refs: [
'lex:app.bsky.richtext.facet#mention',
'lex:app.bsky.richtext.facet#link',
],
},
},
},
mention: {
type: 'object',
description: 'A facet value for actor mentions.',
required: ['did'],
properties: {
did: {
type: 'string',
format: 'did',
},
},
},
link: {
type: 'object',
description: 'A facet value for links.',
required: ['uri'],
properties: {
uri: {
type: 'string',
},
},
},
textSlice: {
type: 'object',
description: 'A text segment. Start is inclusive, end is exclusive.',
required: ['start', 'end'],
properties: {
start: {
type: 'integer',
minimum: 0,
},
end: {
type: 'integer',
minimum: 0,
},
},
},
},
},
}
export const schemas: LexiconDoc[] = Object.values(schemaDict) as LexiconDoc[]
export const lexicons: Lexicons = new Lexicons(schemas)
Expand Down Expand Up @@ -4030,4 +4097,5 @@ export const ids = {
AppBskyNotificationListNotifications:
'app.bsky.notification.listNotifications',
AppBskyNotificationUpdateSeen: 'app.bsky.notification.updateSeen',
AppBskyRichtextFacet: 'app.bsky.richtext.facet',
}
3 changes: 3 additions & 0 deletions packages/api/src/client/types/app/bsky/feed/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import { ValidationResult } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'
import * as AppBskyRichtextFacet from '../richtext/facet'
import * as AppBskyEmbedImages from '../embed/images'
import * as AppBskyEmbedExternal from '../embed/external'
import * as AppBskyEmbedRecord from '../embed/record'
import * as ComAtprotoRepoStrongRef from '../../../com/atproto/repo/strongRef'

export interface Record {
text: string
/** Deprecated: replaced by app.bsky.richtext.facet. */
entities?: Entity[]
facets?: AppBskyRichtextFacet.Main[]
reply?: ReplyRef
embed?:
| AppBskyEmbedImages.Main
Expand Down
80 changes: 80 additions & 0 deletions packages/api/src/client/types/app/bsky/richtext/facet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { ValidationResult } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'

export interface Main {
index: TextSlice
value: Mention | Link | { $type: string; [k: string]: unknown }
[k: string]: unknown
}

export function isMain(v: unknown): v is Main {
return (
isObj(v) &&
hasProp(v, '$type') &&
(v.$type === 'app.bsky.richtext.facet#main' ||
v.$type === 'app.bsky.richtext.facet')
)
}

export function validateMain(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.richtext.facet#main', v)
}

/** A facet value for actor mentions. */
export interface Mention {
did: string
[k: string]: unknown
}

export function isMention(v: unknown): v is Mention {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'app.bsky.richtext.facet#mention'
)
}

export function validateMention(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.richtext.facet#mention', v)
}

/** A facet value for links. */
export interface Link {
uri: string
[k: string]: unknown
}

export function isLink(v: unknown): v is Link {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'app.bsky.richtext.facet#link'
)
}

export function validateLink(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.richtext.facet#link', v)
}

/** A text segment. Start is inclusive, end is exclusive. */
export interface TextSlice {
start: number
end: number
[k: string]: unknown
}

export function isTextSlice(v: unknown): v is TextSlice {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'app.bsky.richtext.facet#textSlice'
)
}

export function validateTextSlice(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.richtext.facet#textSlice', v)
}
2 changes: 0 additions & 2 deletions packages/pds/src/app-view/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as duplicateRecords from './tables/duplicate-record'
import * as profile from './tables/profile'
import * as post from './tables/post'
import * as postEmbed from './tables/post-embed'
import * as postEntity from './tables/post-entity'
import * as postHierarchy from './tables/post-hierarchy'
import * as repost from './tables/repost'
import * as follow from './tables/follow'
Expand All @@ -14,7 +13,6 @@ export type DatabaseSchemaType = duplicateRecords.PartialDB &
profile.PartialDB &
post.PartialDB &
postEmbed.PartialDB &
postEntity.PartialDB &
postHierarchy.PartialDB &
repost.PartialDB &
follow.PartialDB &
Expand Down
12 changes: 0 additions & 12 deletions packages/pds/src/app-view/db/tables/post-entity.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/pds/src/app-view/services/indexing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ export class IndexingService {
.select('post.uri as uri')

await Promise.all([
this.db.db
.deleteFrom('post_entity')
.where('post_entity.postUri', 'in', postByUser)
.execute(),
this.db.db
.deleteFrom('post_embed_image')
.where('post_embed_image.postUri', 'in', postByUser)
Expand Down
Loading

0 comments on commit b0254c8

Please sign in to comment.