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

Rich text comments #108

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
51 changes: 51 additions & 0 deletions lexicons/app/bsky/richtext/facet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"lexicon": 1,
"id": "app.bsky.richtext.facet",
"defs": {
"main": {
"type": "object",
"description": "Annotation of a sub-string within rich text.",
"required": ["index", "features"],
"properties": {
"index": { "type": "ref", "ref": "#byteSlice" },
"features": {
"type": "array",
"items": { "type": "union", "refs": ["#mention", "#link", "#tag"] }
}
}
},
"mention": {
"type": "object",
"description": "Facet feature for mention of another account. The text is usually a handle, including a '@' prefix, but the facet reference is a DID.",
"required": ["did"],
"properties": {
"did": { "type": "string", "format": "did" }
}
},
"link": {
"type": "object",
"description": "Facet feature for a URL. The text URL may have been simplified or truncated, but the facet reference should be a complete URL.",
"required": ["uri"],
"properties": {
"uri": { "type": "string", "format": "uri" }
}
},
"tag": {
"type": "object",
"description": "Facet feature for a hashtag. The text usually includes a '#' prefix, but the facet reference should not (except in the case of 'double hash tags').",
"required": ["tag"],
"properties": {
"tag": { "type": "string", "maxLength": 640, "maxGraphemes": 64 }
}
},
"byteSlice": {
"type": "object",
"description": "Specifies the sub-string range a facet feature applies to. Start index is inclusive, end index is exclusive. Indices are zero-indexed, counting bytes of the UTF-8 encoded text. NOTE: some languages, like Javascript, use UTF-16 or Unicode codepoints for string slice indexing; in these languages, convert to byte arrays before working with facets.",
"required": ["byteStart", "byteEnd"],
"properties": {
"byteStart": { "type": "integer", "minimum": 0 },
"byteEnd": { "type": "integer", "minimum": 0 }
}
}
}
}
2 changes: 1 addition & 1 deletion lexicons/com/atproto/repo/applyWrites.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"required": ["collection", "value"],
"properties": {
"collection": { "type": "string", "format": "nsid" },
"rkey": { "type": "string", "maxLength": 15 },
"rkey": { "type": "string", "maxLength": 512 },
"value": { "type": "unknown" }
}
},
Expand Down
2 changes: 1 addition & 1 deletion lexicons/com/atproto/repo/createRecord.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"rkey": {
"type": "string",
"description": "The Record Key.",
"maxLength": 15
"maxLength": 512
},
"validate": {
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion lexicons/com/atproto/repo/putRecord.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"rkey": {
"type": "string",
"description": "The Record Key.",
"maxLength": 15
"maxLength": 512
},
"validate": {
"type": "boolean",
Expand Down
5 changes: 5 additions & 0 deletions lexicons/fyi/unravel/frontpage/comment.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"maxGraphemes": 10000,
"description": "The content of the comment."
},
"facets": {
"type": "array",
"description": "Annotations of text (mentions, URLs, hashtags, etc)",
"items": { "type": "ref", "ref": "app.bsky.richtext.facet" }
},
"createdAt": {
"type": "string",
"format": "datetime",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontpage-atproto-client/fetch-lexicons.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from "node:fs/promises";
import path from "node:path";
import AdmZip from "adm-zip";

const LEXICON_PREFIXES_TO_FETCH = ["com/atproto/repo"];
const LEXICON_PREFIXES_TO_FETCH = ["com/atproto/repo", "app/bsky/richtext"];
const LEXICON_OUTPUT_PATH = path.resolve(import.meta.dirname, "../../lexicons");

const isWorkingDirectoryClean = await new Promise<boolean>((resolve, reject) =>
Expand Down
32 changes: 32 additions & 0 deletions packages/frontpage-atproto-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { XrpcClient, FetchHandler, FetchHandlerOptions } from "@atproto/xrpc";
import { schemas } from "./lexicons";
import { CID } from "multiformats/cid";
import * as AppBskyRichtextFacet from "./types/app/bsky/richtext/facet";
import * as ComAtprotoRepoApplyWrites from "./types/com/atproto/repo/applyWrites";
import * as ComAtprotoRepoCreateRecord from "./types/com/atproto/repo/createRecord";
import * as ComAtprotoRepoDefs from "./types/com/atproto/repo/defs";
Expand All @@ -20,6 +21,7 @@ import * as FyiUnravelFrontpageComment from "./types/fyi/unravel/frontpage/comme
import * as FyiUnravelFrontpagePost from "./types/fyi/unravel/frontpage/post";
import * as FyiUnravelFrontpageVote from "./types/fyi/unravel/frontpage/vote";

export * as AppBskyRichtextFacet from "./types/app/bsky/richtext/facet";
export * as ComAtprotoRepoApplyWrites from "./types/com/atproto/repo/applyWrites";
export * as ComAtprotoRepoCreateRecord from "./types/com/atproto/repo/createRecord";
export * as ComAtprotoRepoDefs from "./types/com/atproto/repo/defs";
Expand All @@ -37,11 +39,13 @@ export * as FyiUnravelFrontpagePost from "./types/fyi/unravel/frontpage/post";
export * as FyiUnravelFrontpageVote from "./types/fyi/unravel/frontpage/vote";

export class AtpBaseClient extends XrpcClient {
app: AppNS;
com: ComNS;
fyi: FyiNS;

constructor(options: FetchHandler | FetchHandlerOptions) {
super(options, schemas);
this.app = new AppNS(this);
this.com = new ComNS(this);
this.fyi = new FyiNS(this);
}
Expand All @@ -52,6 +56,34 @@ export class AtpBaseClient extends XrpcClient {
}
}

export class AppNS {
_client: XrpcClient;
bsky: AppBskyNS;

constructor(client: XrpcClient) {
this._client = client;
this.bsky = new AppBskyNS(client);
}
}

export class AppBskyNS {
_client: XrpcClient;
richtext: AppBskyRichtextNS;

constructor(client: XrpcClient) {
this._client = client;
this.richtext = new AppBskyRichtextNS(client);
}
}

export class AppBskyRichtextNS {
_client: XrpcClient;

constructor(client: XrpcClient) {
this._client = client;
}
}

export class ComNS {
_client: XrpcClient;
atproto: ComAtprotoNS;
Expand Down
97 changes: 94 additions & 3 deletions packages/frontpage-atproto-client/src/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,87 @@
import { LexiconDoc, Lexicons } from "@atproto/lexicon";

export const schemaDict = {
AppBskyRichtextFacet: {
lexicon: 1,
id: "app.bsky.richtext.facet",
defs: {
main: {
type: "object",
description: "Annotation of a sub-string within rich text.",
required: ["index", "features"],
properties: {
index: {
type: "ref",
ref: "lex:app.bsky.richtext.facet#byteSlice",
},
features: {
type: "array",
items: {
type: "union",
refs: [
"lex:app.bsky.richtext.facet#mention",
"lex:app.bsky.richtext.facet#link",
"lex:app.bsky.richtext.facet#tag",
],
},
},
},
},
mention: {
type: "object",
description:
"Facet feature for mention of another account. The text is usually a handle, including a '@' prefix, but the facet reference is a DID.",
required: ["did"],
properties: {
did: {
type: "string",
format: "did",
},
},
},
link: {
type: "object",
description:
"Facet feature for a URL. The text URL may have been simplified or truncated, but the facet reference should be a complete URL.",
required: ["uri"],
properties: {
uri: {
type: "string",
format: "uri",
},
},
},
tag: {
type: "object",
description:
"Facet feature for a hashtag. The text usually includes a '#' prefix, but the facet reference should not (except in the case of 'double hash tags').",
required: ["tag"],
properties: {
tag: {
type: "string",
maxLength: 640,
maxGraphemes: 64,
},
},
},
byteSlice: {
type: "object",
description:
"Specifies the sub-string range a facet feature applies to. Start index is inclusive, end index is exclusive. Indices are zero-indexed, counting bytes of the UTF-8 encoded text. NOTE: some languages, like Javascript, use UTF-16 or Unicode codepoints for string slice indexing; in these languages, convert to byte arrays before working with facets.",
required: ["byteStart", "byteEnd"],
properties: {
byteStart: {
type: "integer",
minimum: 0,
},
byteEnd: {
type: "integer",
minimum: 0,
},
},
},
},
},
ComAtprotoRepoApplyWrites: {
lexicon: 1,
id: "com.atproto.repo.applyWrites",
Expand Down Expand Up @@ -94,7 +175,7 @@ export const schemaDict = {
},
rkey: {
type: "string",
maxLength: 15,
maxLength: 512,
},
value: {
type: "unknown",
Expand Down Expand Up @@ -203,7 +284,7 @@ export const schemaDict = {
rkey: {
type: "string",
description: "The Record Key.",
maxLength: 15,
maxLength: 512,
},
validate: {
type: "boolean",
Expand Down Expand Up @@ -654,7 +735,7 @@ export const schemaDict = {
rkey: {
type: "string",
description: "The Record Key.",
maxLength: 15,
maxLength: 512,
},
validate: {
type: "boolean",
Expand Down Expand Up @@ -778,6 +859,15 @@ export const schemaDict = {
maxGraphemes: 10000,
description: "The content of the comment.",
},
facets: {
type: "array",
description:
"Annotations of text (mentions, URLs, hashtags, etc)",
items: {
type: "ref",
ref: "lex:app.bsky.richtext.facet",
},
},
createdAt: {
type: "string",
format: "datetime",
Expand Down Expand Up @@ -862,6 +952,7 @@ export const schemaDict = {
export const schemas: LexiconDoc[] = Object.values(schemaDict) as LexiconDoc[];
export const lexicons: Lexicons = new Lexicons(schemas);
export const ids = {
AppBskyRichtextFacet: "app.bsky.richtext.facet",
ComAtprotoRepoApplyWrites: "com.atproto.repo.applyWrites",
ComAtprotoRepoCreateRecord: "com.atproto.repo.createRecord",
ComAtprotoRepoDefs: "com.atproto.repo.defs",
Expand Down
Loading
Loading