From ff803fd2bfad92eec5f88ee9b347c174731ef4ec Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 31 Jul 2024 16:45:20 -0500 Subject: [PATCH] [Detach] Lexicons (#2664) * Define new detach record * Codegen * Add limit of 1k * Codegen * add protos * tweak schema * Add changeset --------- Co-authored-by: dholms --- .changeset/hot-cycles-punch.md | 8 ++ lexicons/app/bsky/feed/detach.json | 32 +++++ packages/api/src/client/index.ts | 65 ++++++++++ packages/api/src/client/lexicons.ts | 37 ++++++ .../src/client/types/app/bsky/feed/detach.ts | 29 +++++ packages/bsky/proto/bsky.proto | 9 ++ packages/bsky/src/lexicon/lexicons.ts | 37 ++++++ .../src/lexicon/types/app/bsky/feed/detach.ts | 29 +++++ packages/bsky/src/proto/bsky_connect.ts | 11 ++ packages/bsky/src/proto/bsky_pb.ts | 116 ++++++++++++++++++ packages/ozone/src/lexicon/lexicons.ts | 37 ++++++ .../src/lexicon/types/app/bsky/feed/detach.ts | 29 +++++ packages/pds/src/lexicon/lexicons.ts | 37 ++++++ .../src/lexicon/types/app/bsky/feed/detach.ts | 29 +++++ 14 files changed, 505 insertions(+) create mode 100644 .changeset/hot-cycles-punch.md create mode 100644 lexicons/app/bsky/feed/detach.json create mode 100644 packages/api/src/client/types/app/bsky/feed/detach.ts create mode 100644 packages/bsky/src/lexicon/types/app/bsky/feed/detach.ts create mode 100644 packages/ozone/src/lexicon/types/app/bsky/feed/detach.ts create mode 100644 packages/pds/src/lexicon/types/app/bsky/feed/detach.ts diff --git a/.changeset/hot-cycles-punch.md b/.changeset/hot-cycles-punch.md new file mode 100644 index 00000000000..68fd19edc97 --- /dev/null +++ b/.changeset/hot-cycles-punch.md @@ -0,0 +1,8 @@ +--- +"@atproto/ozone": patch +"@atproto/bsky": patch +"@atproto/api": patch +"@atproto/pds": patch +--- + +Adds `app.bsky.feed.detach` record lexicons. diff --git a/lexicons/app/bsky/feed/detach.json b/lexicons/app/bsky/feed/detach.json new file mode 100644 index 00000000000..e2b5593844b --- /dev/null +++ b/lexicons/app/bsky/feed/detach.json @@ -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" } + } + } + } + } +} diff --git a/packages/api/src/client/index.ts b/packages/api/src/client/index.ts index 0e06d830466..6186f8d14c0 100644 --- a/packages/api/src/client/index.ts +++ b/packages/api/src/client/index.ts @@ -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' @@ -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' @@ -1567,6 +1569,7 @@ export class AppBskyEmbedNS { export class AppBskyFeedNS { _service: AtpServiceClient + detach: DetachRecord generator: GeneratorRecord like: LikeRecord post: PostRecord @@ -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) @@ -1770,6 +1774,67 @@ export class AppBskyFeedNS { } } +export class DetachRecord { + _service: AtpServiceClient + + constructor(service: AtpServiceClient) { + this._service = service + } + + async list( + params: Omit, + ): 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, + ): 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, + ): 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, + headers?: Record, + ): Promise { + await this._service.xrpc.call( + 'com.atproto.repo.deleteRecord', + undefined, + { collection: 'app.bsky.feed.detach', ...params }, + { headers }, + ) + } +} + export class GeneratorRecord { _service: AtpServiceClient diff --git a/packages/api/src/client/lexicons.ts b/packages/api/src/client/lexicons.ts index b7783a15e8b..00a33eb7134 100644 --- a/packages/api/src/client/lexicons.ts +++ b/packages/api/src/client/lexicons.ts @@ -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', @@ -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', diff --git a/packages/api/src/client/types/app/bsky/feed/detach.ts b/packages/api/src/client/types/app/bsky/feed/detach.ts new file mode 100644 index 00000000000..779d416ce77 --- /dev/null +++ b/packages/api/src/client/types/app/bsky/feed/detach.ts @@ -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) +} diff --git a/packages/bsky/proto/bsky.proto b/packages/bsky/proto/bsky.proto index e0ffb2bdfce..c776bb85763 100644 --- a/packages/bsky/proto/bsky.proto +++ b/packages/bsky/proto/bsky.proto @@ -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; } @@ -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); diff --git a/packages/bsky/src/lexicon/lexicons.ts b/packages/bsky/src/lexicon/lexicons.ts index 82346d7601c..7e2b8fce95a 100644 --- a/packages/bsky/src/lexicon/lexicons.ts +++ b/packages/bsky/src/lexicon/lexicons.ts @@ -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', @@ -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', diff --git a/packages/bsky/src/lexicon/types/app/bsky/feed/detach.ts b/packages/bsky/src/lexicon/types/app/bsky/feed/detach.ts new file mode 100644 index 00000000000..23decc37945 --- /dev/null +++ b/packages/bsky/src/lexicon/types/app/bsky/feed/detach.ts @@ -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) +} diff --git a/packages/bsky/src/proto/bsky_connect.ts b/packages/bsky/src/proto/bsky_connect.ts index 14df8872eec..48d6bb73285 100644 --- a/packages/bsky/src/proto/bsky_connect.ts +++ b/packages/bsky/src/proto/bsky_connect.ts @@ -66,6 +66,8 @@ import { GetBlocksResponse, GetCountsForUsersRequest, GetCountsForUsersResponse, + GetDetachRecordsRequest, + GetDetachRecordsResponse, GetDidsByHandlesRequest, GetDidsByHandlesResponse, GetFeedGeneratorRecordsRequest, @@ -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 */ diff --git a/packages/bsky/src/proto/bsky_pb.ts b/packages/bsky/src/proto/bsky_pb.ts index b9774bdcb06..e2baa17782a 100644 --- a/packages/bsky/src/proto/bsky_pb.ts +++ b/packages/bsky/src/proto/bsky_pb.ts @@ -1608,6 +1608,122 @@ export class GetThreadGateRecordsResponse extends Message { + /** + * @generated from field: repeated string uris = 1; + */ + uris: string[] = [] + + constructor(data?: PartialMessage) { + super() + proto3.util.initPartial(data, this) + } + + static readonly runtime: typeof proto3 = proto3 + static readonly typeName = 'bsky.GetDetachRecordsRequest' + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { + no: 1, + name: 'uris', + kind: 'scalar', + T: 9 /* ScalarType.STRING */, + repeated: true, + }, + ]) + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): GetDetachRecordsRequest { + return new GetDetachRecordsRequest().fromBinary(bytes, options) + } + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): GetDetachRecordsRequest { + return new GetDetachRecordsRequest().fromJson(jsonValue, options) + } + + static fromJsonString( + jsonString: string, + options?: Partial, + ): GetDetachRecordsRequest { + return new GetDetachRecordsRequest().fromJsonString(jsonString, options) + } + + static equals( + a: + | GetDetachRecordsRequest + | PlainMessage + | undefined, + b: + | GetDetachRecordsRequest + | PlainMessage + | undefined, + ): boolean { + return proto3.util.equals(GetDetachRecordsRequest, a, b) + } +} + +/** + * @generated from message bsky.GetDetachRecordsResponse + */ +export class GetDetachRecordsResponse extends Message { + /** + * @generated from field: repeated bsky.Record records = 1; + */ + records: Record[] = [] + + constructor(data?: PartialMessage) { + super() + proto3.util.initPartial(data, this) + } + + static readonly runtime: typeof proto3 = proto3 + static readonly typeName = 'bsky.GetDetachRecordsResponse' + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: 'records', kind: 'message', T: Record, repeated: true }, + ]) + + static fromBinary( + bytes: Uint8Array, + options?: Partial, + ): GetDetachRecordsResponse { + return new GetDetachRecordsResponse().fromBinary(bytes, options) + } + + static fromJson( + jsonValue: JsonValue, + options?: Partial, + ): GetDetachRecordsResponse { + return new GetDetachRecordsResponse().fromJson(jsonValue, options) + } + + static fromJsonString( + jsonString: string, + options?: Partial, + ): GetDetachRecordsResponse { + return new GetDetachRecordsResponse().fromJsonString(jsonString, options) + } + + static equals( + a: + | GetDetachRecordsResponse + | PlainMessage + | undefined, + b: + | GetDetachRecordsResponse + | PlainMessage + | undefined, + ): boolean { + return proto3.util.equals(GetDetachRecordsResponse, a, b) + } +} + /** * @generated from message bsky.GetLabelerRecordsRequest */ diff --git a/packages/ozone/src/lexicon/lexicons.ts b/packages/ozone/src/lexicon/lexicons.ts index b7783a15e8b..00a33eb7134 100644 --- a/packages/ozone/src/lexicon/lexicons.ts +++ b/packages/ozone/src/lexicon/lexicons.ts @@ -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', @@ -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', diff --git a/packages/ozone/src/lexicon/types/app/bsky/feed/detach.ts b/packages/ozone/src/lexicon/types/app/bsky/feed/detach.ts new file mode 100644 index 00000000000..23decc37945 --- /dev/null +++ b/packages/ozone/src/lexicon/types/app/bsky/feed/detach.ts @@ -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) +} diff --git a/packages/pds/src/lexicon/lexicons.ts b/packages/pds/src/lexicon/lexicons.ts index b7783a15e8b..00a33eb7134 100644 --- a/packages/pds/src/lexicon/lexicons.ts +++ b/packages/pds/src/lexicon/lexicons.ts @@ -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', @@ -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', diff --git a/packages/pds/src/lexicon/types/app/bsky/feed/detach.ts b/packages/pds/src/lexicon/types/app/bsky/feed/detach.ts new file mode 100644 index 00000000000..23decc37945 --- /dev/null +++ b/packages/pds/src/lexicon/types/app/bsky/feed/detach.ts @@ -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) +}