Skip to content

Commit

Permalink
[Detach] Lexicons (#2664)
Browse files Browse the repository at this point in the history
* Define new detach record

* Codegen

* Add limit of 1k

* Codegen

* add protos

* tweak schema

* Add changeset

---------

Co-authored-by: dholms <[email protected]>
  • Loading branch information
estrattonbailey and dholms authored Jul 31, 2024
1 parent a5fbd8c commit ff803fd
Show file tree
Hide file tree
Showing 14 changed files with 505 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/hot-cycles-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@atproto/ozone": patch
"@atproto/bsky": patch
"@atproto/api": patch
"@atproto/pds": patch
---

Adds `app.bsky.feed.detach` record lexicons.
32 changes: 32 additions & 0 deletions lexicons/app/bsky/feed/detach.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"lexicon": 1,
"id": "app.bsky.feed.detach",
"defs": {
"main": {
"type": "record",
"key": "tid",
"description": "Record defining post URIs detached from a root post. The record key (rkey) of the detach record must match the record key of the root post in question, and that record must be in the same repository.",
"record": {
"type": "object",
"required": ["post", "targets", "updatedAt"],
"properties": {
"post": {
"type": "string",
"format": "at-uri",
"description": "Reference (AT-URI) to the post record."
},
"targets": {
"type": "array",
"maxLength": 50,
"items": {
"type": "string",
"format": "at-uri"
},
"description": "List of detached post URIs."
},
"updatedAt": { "type": "string", "format": "datetime" }
}
}
}
}
}
65 changes: 65 additions & 0 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import * as AppBskyEmbedRecord from './types/app/bsky/embed/record'
import * as AppBskyEmbedRecordWithMedia from './types/app/bsky/embed/recordWithMedia'
import * as AppBskyFeedDefs from './types/app/bsky/feed/defs'
import * as AppBskyFeedDescribeFeedGenerator from './types/app/bsky/feed/describeFeedGenerator'
import * as AppBskyFeedDetach from './types/app/bsky/feed/detach'
import * as AppBskyFeedGenerator from './types/app/bsky/feed/generator'
import * as AppBskyFeedGetActorFeeds from './types/app/bsky/feed/getActorFeeds'
import * as AppBskyFeedGetActorLikes from './types/app/bsky/feed/getActorLikes'
Expand Down Expand Up @@ -298,6 +299,7 @@ export * as AppBskyEmbedRecord from './types/app/bsky/embed/record'
export * as AppBskyEmbedRecordWithMedia from './types/app/bsky/embed/recordWithMedia'
export * as AppBskyFeedDefs from './types/app/bsky/feed/defs'
export * as AppBskyFeedDescribeFeedGenerator from './types/app/bsky/feed/describeFeedGenerator'
export * as AppBskyFeedDetach from './types/app/bsky/feed/detach'
export * as AppBskyFeedGenerator from './types/app/bsky/feed/generator'
export * as AppBskyFeedGetActorFeeds from './types/app/bsky/feed/getActorFeeds'
export * as AppBskyFeedGetActorLikes from './types/app/bsky/feed/getActorLikes'
Expand Down Expand Up @@ -1567,6 +1569,7 @@ export class AppBskyEmbedNS {

export class AppBskyFeedNS {
_service: AtpServiceClient
detach: DetachRecord
generator: GeneratorRecord
like: LikeRecord
post: PostRecord
Expand All @@ -1575,6 +1578,7 @@ export class AppBskyFeedNS {

constructor(service: AtpServiceClient) {
this._service = service
this.detach = new DetachRecord(service)
this.generator = new GeneratorRecord(service)
this.like = new LikeRecord(service)
this.post = new PostRecord(service)
Expand Down Expand Up @@ -1770,6 +1774,67 @@ export class AppBskyFeedNS {
}
}

export class DetachRecord {
_service: AtpServiceClient

constructor(service: AtpServiceClient) {
this._service = service
}

async list(
params: Omit<ComAtprotoRepoListRecords.QueryParams, 'collection'>,
): Promise<{
cursor?: string
records: { uri: string; value: AppBskyFeedDetach.Record }[]
}> {
const res = await this._service.xrpc.call('com.atproto.repo.listRecords', {
collection: 'app.bsky.feed.detach',
...params,
})
return res.data
}

async get(
params: Omit<ComAtprotoRepoGetRecord.QueryParams, 'collection'>,
): Promise<{ uri: string; cid: string; value: AppBskyFeedDetach.Record }> {
const res = await this._service.xrpc.call('com.atproto.repo.getRecord', {
collection: 'app.bsky.feed.detach',
...params,
})
return res.data
}

async create(
params: Omit<
ComAtprotoRepoCreateRecord.InputSchema,
'collection' | 'record'
>,
record: AppBskyFeedDetach.Record,
headers?: Record<string, string>,
): Promise<{ uri: string; cid: string }> {
record.$type = 'app.bsky.feed.detach'
const res = await this._service.xrpc.call(
'com.atproto.repo.createRecord',
undefined,
{ collection: 'app.bsky.feed.detach', ...params, record },
{ encoding: 'application/json', headers },
)
return res.data
}

async delete(
params: Omit<ComAtprotoRepoDeleteRecord.InputSchema, 'collection'>,
headers?: Record<string, string>,
): Promise<void> {
await this._service.xrpc.call(
'com.atproto.repo.deleteRecord',
undefined,
{ collection: 'app.bsky.feed.detach', ...params },
{ headers },
)
}
}

export class GeneratorRecord {
_service: AtpServiceClient

Expand Down
37 changes: 37 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5596,6 +5596,42 @@ export const schemaDict = {
},
},
},
AppBskyFeedDetach: {
lexicon: 1,
id: 'app.bsky.feed.detach',
defs: {
main: {
type: 'record',
key: 'tid',
description:
'Record defining post URIs detached from a root post. The record key (rkey) of the detach record must match the record key of the root post in question, and that record must be in the same repository.',
record: {
type: 'object',
required: ['post', 'targets', 'updatedAt'],
properties: {
post: {
type: 'string',
format: 'at-uri',
description: 'Reference (AT-URI) to the post record.',
},
targets: {
type: 'array',
maxLength: 50,
items: {
type: 'string',
format: 'at-uri',
},
description: 'List of detached post URIs.',
},
updatedAt: {
type: 'string',
format: 'datetime',
},
},
},
},
},
},
AppBskyFeedGenerator: {
lexicon: 1,
id: 'app.bsky.feed.generator',
Expand Down Expand Up @@ -11762,6 +11798,7 @@ export const ids = {
AppBskyEmbedRecordWithMedia: 'app.bsky.embed.recordWithMedia',
AppBskyFeedDefs: 'app.bsky.feed.defs',
AppBskyFeedDescribeFeedGenerator: 'app.bsky.feed.describeFeedGenerator',
AppBskyFeedDetach: 'app.bsky.feed.detach',
AppBskyFeedGenerator: 'app.bsky.feed.generator',
AppBskyFeedGetActorFeeds: 'app.bsky.feed.getActorFeeds',
AppBskyFeedGetActorLikes: 'app.bsky.feed.getActorLikes',
Expand Down
29 changes: 29 additions & 0 deletions packages/api/src/client/types/app/bsky/feed/detach.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'
import { CID } from 'multiformats/cid'

export interface Record {
/** Reference (AT-URI) to the post record. */
post: string
/** List of detached post URIs. */
targets: string[]
updatedAt: string
[k: string]: unknown
}

export function isRecord(v: unknown): v is Record {
return (
isObj(v) &&
hasProp(v, '$type') &&
(v.$type === 'app.bsky.feed.detach#main' ||
v.$type === 'app.bsky.feed.detach')
)
}

export function validateRecord(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.feed.detach#main', v)
}
9 changes: 9 additions & 0 deletions packages/bsky/proto/bsky.proto
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ message GetThreadGateRecordsResponse {
repeated Record records = 1;
}

message GetDetachRecordsRequest {
repeated string uris = 1;
}

message GetDetachRecordsResponse {
repeated Record records = 1;
}

message GetLabelerRecordsRequest {
repeated string uris = 1;
}
Expand Down Expand Up @@ -1068,6 +1076,7 @@ service Service {
rpc GetActorChatDeclarationRecords(GetActorChatDeclarationRecordsRequest) returns (GetActorChatDeclarationRecordsResponse);
rpc GetRepostRecords(GetRepostRecordsRequest) returns (GetRepostRecordsResponse);
rpc GetThreadGateRecords(GetThreadGateRecordsRequest) returns (GetThreadGateRecordsResponse);
rpc GetDetachRecords(GetDetachRecordsRequest) returns (GetDetachRecordsResponse);
rpc GetLabelerRecords(GetLabelerRecordsRequest) returns (GetLabelerRecordsResponse);
rpc GetStarterPackRecords(GetStarterPackRecordsRequest) returns (GetStarterPackRecordsResponse);

Expand Down
37 changes: 37 additions & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5596,6 +5596,42 @@ export const schemaDict = {
},
},
},
AppBskyFeedDetach: {
lexicon: 1,
id: 'app.bsky.feed.detach',
defs: {
main: {
type: 'record',
key: 'tid',
description:
'Record defining post URIs detached from a root post. The record key (rkey) of the detach record must match the record key of the root post in question, and that record must be in the same repository.',
record: {
type: 'object',
required: ['post', 'targets', 'updatedAt'],
properties: {
post: {
type: 'string',
format: 'at-uri',
description: 'Reference (AT-URI) to the post record.',
},
targets: {
type: 'array',
maxLength: 50,
items: {
type: 'string',
format: 'at-uri',
},
description: 'List of detached post URIs.',
},
updatedAt: {
type: 'string',
format: 'datetime',
},
},
},
},
},
},
AppBskyFeedGenerator: {
lexicon: 1,
id: 'app.bsky.feed.generator',
Expand Down Expand Up @@ -10044,6 +10080,7 @@ export const ids = {
AppBskyEmbedRecordWithMedia: 'app.bsky.embed.recordWithMedia',
AppBskyFeedDefs: 'app.bsky.feed.defs',
AppBskyFeedDescribeFeedGenerator: 'app.bsky.feed.describeFeedGenerator',
AppBskyFeedDetach: 'app.bsky.feed.detach',
AppBskyFeedGenerator: 'app.bsky.feed.generator',
AppBskyFeedGetActorFeeds: 'app.bsky.feed.getActorFeeds',
AppBskyFeedGetActorLikes: 'app.bsky.feed.getActorLikes',
Expand Down
29 changes: 29 additions & 0 deletions packages/bsky/src/lexicon/types/app/bsky/feed/detach.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { lexicons } from '../../../../lexicons'
import { isObj, hasProp } from '../../../../util'
import { CID } from 'multiformats/cid'

export interface Record {
/** Reference (AT-URI) to the post record. */
post: string
/** List of detached post URIs. */
targets: string[]
updatedAt: string
[k: string]: unknown
}

export function isRecord(v: unknown): v is Record {
return (
isObj(v) &&
hasProp(v, '$type') &&
(v.$type === 'app.bsky.feed.detach#main' ||
v.$type === 'app.bsky.feed.detach')
)
}

export function validateRecord(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.feed.detach#main', v)
}
11 changes: 11 additions & 0 deletions packages/bsky/src/proto/bsky_connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import {
GetBlocksResponse,
GetCountsForUsersRequest,
GetCountsForUsersResponse,
GetDetachRecordsRequest,
GetDetachRecordsResponse,
GetDidsByHandlesRequest,
GetDidsByHandlesResponse,
GetFeedGeneratorRecordsRequest,
Expand Down Expand Up @@ -309,6 +311,15 @@ export const Service = {
O: GetThreadGateRecordsResponse,
kind: MethodKind.Unary,
},
/**
* @generated from rpc bsky.Service.GetDetachRecords
*/
getDetachRecords: {
name: 'GetDetachRecords',
I: GetDetachRecordsRequest,
O: GetDetachRecordsResponse,
kind: MethodKind.Unary,
},
/**
* @generated from rpc bsky.Service.GetLabelerRecords
*/
Expand Down
Loading

0 comments on commit ff803fd

Please sign in to comment.