From bfbac2431214a0c96dad104e7310ea10c863ac08 Mon Sep 17 00:00:00 2001 From: Daniel Holmgren Date: Fri, 30 Aug 2024 13:18:43 -0500 Subject: [PATCH] Repo write commit metadata (#2745) * schemas & codegen * impl * bundle commit & rev --- lexicons/com/atproto/repo/applyWrites.json | 4 ++ lexicons/com/atproto/repo/createRecord.json | 4 ++ lexicons/com/atproto/repo/defs.json | 14 ++++++ lexicons/com/atproto/repo/deleteRecord.json | 12 +++++ lexicons/com/atproto/repo/putRecord.json | 4 ++ packages/api/src/client/index.ts | 2 + packages/api/src/client/lexicons.ts | 44 +++++++++++++++++++ .../types/com/atproto/repo/applyWrites.ts | 2 + .../types/com/atproto/repo/createRecord.ts | 2 + .../src/client/types/com/atproto/repo/defs.ts | 25 +++++++++++ .../types/com/atproto/repo/deleteRecord.ts | 7 +++ .../types/com/atproto/repo/putRecord.ts | 2 + packages/bsky/src/lexicon/lexicons.ts | 44 +++++++++++++++++++ .../types/com/atproto/repo/applyWrites.ts | 2 + .../types/com/atproto/repo/createRecord.ts | 2 + .../lexicon/types/com/atproto/repo/defs.ts | 25 +++++++++++ .../types/com/atproto/repo/deleteRecord.ts | 14 +++++- .../types/com/atproto/repo/putRecord.ts | 2 + packages/ozone/src/lexicon/lexicons.ts | 44 +++++++++++++++++++ .../types/com/atproto/repo/applyWrites.ts | 2 + .../types/com/atproto/repo/createRecord.ts | 2 + .../lexicon/types/com/atproto/repo/defs.ts | 25 +++++++++++ .../types/com/atproto/repo/deleteRecord.ts | 14 +++++- .../types/com/atproto/repo/putRecord.ts | 2 + .../src/api/com/atproto/repo/applyWrites.ts | 4 ++ .../src/api/com/atproto/repo/createRecord.ts | 4 ++ .../src/api/com/atproto/repo/deleteRecord.ts | 11 +++++ .../pds/src/api/com/atproto/repo/putRecord.ts | 6 +++ packages/pds/src/lexicon/lexicons.ts | 44 +++++++++++++++++++ .../types/com/atproto/repo/applyWrites.ts | 2 + .../types/com/atproto/repo/createRecord.ts | 2 + .../lexicon/types/com/atproto/repo/defs.ts | 25 +++++++++++ .../types/com/atproto/repo/deleteRecord.ts | 14 +++++- .../types/com/atproto/repo/putRecord.ts | 2 + 34 files changed, 411 insertions(+), 3 deletions(-) create mode 100644 lexicons/com/atproto/repo/defs.json create mode 100644 packages/api/src/client/types/com/atproto/repo/defs.ts create mode 100644 packages/bsky/src/lexicon/types/com/atproto/repo/defs.ts create mode 100644 packages/ozone/src/lexicon/types/com/atproto/repo/defs.ts create mode 100644 packages/pds/src/lexicon/types/com/atproto/repo/defs.ts diff --git a/lexicons/com/atproto/repo/applyWrites.json b/lexicons/com/atproto/repo/applyWrites.json index 6e7aafe0fb6..26dd96c5346 100644 --- a/lexicons/com/atproto/repo/applyWrites.json +++ b/lexicons/com/atproto/repo/applyWrites.json @@ -42,6 +42,10 @@ "type": "object", "required": [], "properties": { + "commit": { + "type": "ref", + "ref": "com.atproto.repo.defs#commitMeta" + }, "results": { "type": "array", "items": { diff --git a/lexicons/com/atproto/repo/createRecord.json b/lexicons/com/atproto/repo/createRecord.json index a1e91229e1e..7290085711f 100644 --- a/lexicons/com/atproto/repo/createRecord.json +++ b/lexicons/com/atproto/repo/createRecord.json @@ -50,6 +50,10 @@ "properties": { "uri": { "type": "string", "format": "at-uri" }, "cid": { "type": "string", "format": "cid" }, + "commit": { + "type": "ref", + "ref": "com.atproto.repo.defs#commitMeta" + }, "validationStatus": { "type": "string", "knownValues": ["valid", "unknown"] diff --git a/lexicons/com/atproto/repo/defs.json b/lexicons/com/atproto/repo/defs.json new file mode 100644 index 00000000000..0f5128fb9e4 --- /dev/null +++ b/lexicons/com/atproto/repo/defs.json @@ -0,0 +1,14 @@ +{ + "lexicon": 1, + "id": "com.atproto.repo.defs", + "defs": { + "commitMeta": { + "type": "object", + "required": ["cid", "rev"], + "properties": { + "cid": { "type": "string", "format": "cid" }, + "rev": { "type": "string" } + } + } + } +} diff --git a/lexicons/com/atproto/repo/deleteRecord.json b/lexicons/com/atproto/repo/deleteRecord.json index 65b9f8f9536..fb9b90b720d 100644 --- a/lexicons/com/atproto/repo/deleteRecord.json +++ b/lexicons/com/atproto/repo/deleteRecord.json @@ -38,6 +38,18 @@ } } }, + "output": { + "encoding": "application/json", + "schema": { + "type": "object", + "properties": { + "commit": { + "type": "ref", + "ref": "com.atproto.repo.defs#commitMeta" + } + } + } + }, "errors": [{ "name": "InvalidSwap" }] } } diff --git a/lexicons/com/atproto/repo/putRecord.json b/lexicons/com/atproto/repo/putRecord.json index aefc125e703..9a841f6a8df 100644 --- a/lexicons/com/atproto/repo/putRecord.json +++ b/lexicons/com/atproto/repo/putRecord.json @@ -56,6 +56,10 @@ "properties": { "uri": { "type": "string", "format": "at-uri" }, "cid": { "type": "string", "format": "cid" }, + "commit": { + "type": "ref", + "ref": "com.atproto.repo.defs#commitMeta" + }, "validationStatus": { "type": "string", "knownValues": ["valid", "unknown"] diff --git a/packages/api/src/client/index.ts b/packages/api/src/client/index.ts index 50c6c0f3a2f..1d86ef6d8ad 100644 --- a/packages/api/src/client/index.ts +++ b/packages/api/src/client/index.ts @@ -32,6 +32,7 @@ import * as ComAtprotoModerationCreateReport from './types/com/atproto/moderatio import * as ComAtprotoModerationDefs from './types/com/atproto/moderation/defs' 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' import * as ComAtprotoRepoDeleteRecord from './types/com/atproto/repo/deleteRecord' import * as ComAtprotoRepoDescribeRepo from './types/com/atproto/repo/describeRepo' import * as ComAtprotoRepoGetRecord from './types/com/atproto/repo/getRecord' @@ -237,6 +238,7 @@ export * as ComAtprotoModerationCreateReport from './types/com/atproto/moderatio export * as ComAtprotoModerationDefs from './types/com/atproto/moderation/defs' 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' export * as ComAtprotoRepoDeleteRecord from './types/com/atproto/repo/deleteRecord' export * as ComAtprotoRepoDescribeRepo from './types/com/atproto/repo/describeRepo' export * as ComAtprotoRepoGetRecord from './types/com/atproto/repo/getRecord' diff --git a/packages/api/src/client/lexicons.ts b/packages/api/src/client/lexicons.ts index 6ba34d1040e..5111b619dea 100644 --- a/packages/api/src/client/lexicons.ts +++ b/packages/api/src/client/lexicons.ts @@ -1284,6 +1284,10 @@ export const schemaDict = { type: 'object', required: [], properties: { + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, results: { type: 'array', items: { @@ -1461,6 +1465,10 @@ export const schemaDict = { type: 'string', format: 'cid', }, + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, validationStatus: { type: 'string', knownValues: ['valid', 'unknown'], @@ -1478,6 +1486,25 @@ export const schemaDict = { }, }, }, + ComAtprotoRepoDefs: { + lexicon: 1, + id: 'com.atproto.repo.defs', + defs: { + commitMeta: { + type: 'object', + required: ['cid', 'rev'], + properties: { + cid: { + type: 'string', + format: 'cid', + }, + rev: { + type: 'string', + }, + }, + }, + }, + }, ComAtprotoRepoDeleteRecord: { lexicon: 1, id: 'com.atproto.repo.deleteRecord', @@ -1522,6 +1549,18 @@ export const schemaDict = { }, }, }, + output: { + encoding: 'application/json', + schema: { + type: 'object', + properties: { + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, + }, + }, + }, errors: [ { name: 'InvalidSwap', @@ -1878,6 +1917,10 @@ export const schemaDict = { type: 'string', format: 'cid', }, + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, validationStatus: { type: 'string', knownValues: ['valid', 'unknown'], @@ -12151,6 +12194,7 @@ export const ids = { ComAtprotoModerationDefs: 'com.atproto.moderation.defs', ComAtprotoRepoApplyWrites: 'com.atproto.repo.applyWrites', ComAtprotoRepoCreateRecord: 'com.atproto.repo.createRecord', + ComAtprotoRepoDefs: 'com.atproto.repo.defs', ComAtprotoRepoDeleteRecord: 'com.atproto.repo.deleteRecord', ComAtprotoRepoDescribeRepo: 'com.atproto.repo.describeRepo', ComAtprotoRepoGetRecord: 'com.atproto.repo.getRecord', diff --git a/packages/api/src/client/types/com/atproto/repo/applyWrites.ts b/packages/api/src/client/types/com/atproto/repo/applyWrites.ts index f1fcd43a81d..edebf199a44 100644 --- a/packages/api/src/client/types/com/atproto/repo/applyWrites.ts +++ b/packages/api/src/client/types/com/atproto/repo/applyWrites.ts @@ -6,6 +6,7 @@ import { ValidationResult, BlobRef } from '@atproto/lexicon' import { isObj, hasProp } from '../../../../util' import { lexicons } from '../../../../lexicons' import { CID } from 'multiformats/cid' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -21,6 +22,7 @@ export interface InputSchema { } export interface OutputSchema { + commit?: ComAtprotoRepoDefs.CommitMeta results?: (CreateResult | UpdateResult | DeleteResult)[] [k: string]: unknown } diff --git a/packages/api/src/client/types/com/atproto/repo/createRecord.ts b/packages/api/src/client/types/com/atproto/repo/createRecord.ts index 485e3a13cb0..b0f921ef986 100644 --- a/packages/api/src/client/types/com/atproto/repo/createRecord.ts +++ b/packages/api/src/client/types/com/atproto/repo/createRecord.ts @@ -6,6 +6,7 @@ import { ValidationResult, BlobRef } from '@atproto/lexicon' import { isObj, hasProp } from '../../../../util' import { lexicons } from '../../../../lexicons' import { CID } from 'multiformats/cid' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -28,6 +29,7 @@ export interface InputSchema { export interface OutputSchema { uri: string cid: string + commit?: ComAtprotoRepoDefs.CommitMeta validationStatus?: 'valid' | 'unknown' | (string & {}) [k: string]: unknown } diff --git a/packages/api/src/client/types/com/atproto/repo/defs.ts b/packages/api/src/client/types/com/atproto/repo/defs.ts new file mode 100644 index 00000000000..d4dfaceabf3 --- /dev/null +++ b/packages/api/src/client/types/com/atproto/repo/defs.ts @@ -0,0 +1,25 @@ +/** + * 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 CommitMeta { + cid: string + rev: string + [k: string]: unknown +} + +export function isCommitMeta(v: unknown): v is CommitMeta { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'com.atproto.repo.defs#commitMeta' + ) +} + +export function validateCommitMeta(v: unknown): ValidationResult { + return lexicons.validate('com.atproto.repo.defs#commitMeta', v) +} diff --git a/packages/api/src/client/types/com/atproto/repo/deleteRecord.ts b/packages/api/src/client/types/com/atproto/repo/deleteRecord.ts index 5ce29976c95..ed06cbc83fc 100644 --- a/packages/api/src/client/types/com/atproto/repo/deleteRecord.ts +++ b/packages/api/src/client/types/com/atproto/repo/deleteRecord.ts @@ -6,6 +6,7 @@ import { ValidationResult, BlobRef } from '@atproto/lexicon' import { isObj, hasProp } from '../../../../util' import { lexicons } from '../../../../lexicons' import { CID } from 'multiformats/cid' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -23,6 +24,11 @@ export interface InputSchema { [k: string]: unknown } +export interface OutputSchema { + commit?: ComAtprotoRepoDefs.CommitMeta + [k: string]: unknown +} + export interface CallOptions { signal?: AbortSignal headers?: HeadersMap @@ -33,6 +39,7 @@ export interface CallOptions { export interface Response { success: boolean headers: HeadersMap + data: OutputSchema } export class InvalidSwapError extends XRPCError { diff --git a/packages/api/src/client/types/com/atproto/repo/putRecord.ts b/packages/api/src/client/types/com/atproto/repo/putRecord.ts index 01ab0cd63c1..9cadf9a2c4d 100644 --- a/packages/api/src/client/types/com/atproto/repo/putRecord.ts +++ b/packages/api/src/client/types/com/atproto/repo/putRecord.ts @@ -6,6 +6,7 @@ import { ValidationResult, BlobRef } from '@atproto/lexicon' import { isObj, hasProp } from '../../../../util' import { lexicons } from '../../../../lexicons' import { CID } from 'multiformats/cid' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -30,6 +31,7 @@ export interface InputSchema { export interface OutputSchema { uri: string cid: string + commit?: ComAtprotoRepoDefs.CommitMeta validationStatus?: 'valid' | 'unknown' | (string & {}) [k: string]: unknown } diff --git a/packages/bsky/src/lexicon/lexicons.ts b/packages/bsky/src/lexicon/lexicons.ts index f4f8d41095a..295d5beccdf 100644 --- a/packages/bsky/src/lexicon/lexicons.ts +++ b/packages/bsky/src/lexicon/lexicons.ts @@ -1284,6 +1284,10 @@ export const schemaDict = { type: 'object', required: [], properties: { + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, results: { type: 'array', items: { @@ -1461,6 +1465,10 @@ export const schemaDict = { type: 'string', format: 'cid', }, + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, validationStatus: { type: 'string', knownValues: ['valid', 'unknown'], @@ -1478,6 +1486,25 @@ export const schemaDict = { }, }, }, + ComAtprotoRepoDefs: { + lexicon: 1, + id: 'com.atproto.repo.defs', + defs: { + commitMeta: { + type: 'object', + required: ['cid', 'rev'], + properties: { + cid: { + type: 'string', + format: 'cid', + }, + rev: { + type: 'string', + }, + }, + }, + }, + }, ComAtprotoRepoDeleteRecord: { lexicon: 1, id: 'com.atproto.repo.deleteRecord', @@ -1522,6 +1549,18 @@ export const schemaDict = { }, }, }, + output: { + encoding: 'application/json', + schema: { + type: 'object', + properties: { + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, + }, + }, + }, errors: [ { name: 'InvalidSwap', @@ -1878,6 +1917,10 @@ export const schemaDict = { type: 'string', format: 'cid', }, + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, validationStatus: { type: 'string', knownValues: ['valid', 'unknown'], @@ -10433,6 +10476,7 @@ export const ids = { ComAtprotoModerationDefs: 'com.atproto.moderation.defs', ComAtprotoRepoApplyWrites: 'com.atproto.repo.applyWrites', ComAtprotoRepoCreateRecord: 'com.atproto.repo.createRecord', + ComAtprotoRepoDefs: 'com.atproto.repo.defs', ComAtprotoRepoDeleteRecord: 'com.atproto.repo.deleteRecord', ComAtprotoRepoDescribeRepo: 'com.atproto.repo.describeRepo', ComAtprotoRepoGetRecord: 'com.atproto.repo.getRecord', diff --git a/packages/bsky/src/lexicon/types/com/atproto/repo/applyWrites.ts b/packages/bsky/src/lexicon/types/com/atproto/repo/applyWrites.ts index acfae03c439..4e3c8dcef3d 100644 --- a/packages/bsky/src/lexicon/types/com/atproto/repo/applyWrites.ts +++ b/packages/bsky/src/lexicon/types/com/atproto/repo/applyWrites.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -22,6 +23,7 @@ export interface InputSchema { } export interface OutputSchema { + commit?: ComAtprotoRepoDefs.CommitMeta results?: (CreateResult | UpdateResult | DeleteResult)[] [k: string]: unknown } diff --git a/packages/bsky/src/lexicon/types/com/atproto/repo/createRecord.ts b/packages/bsky/src/lexicon/types/com/atproto/repo/createRecord.ts index 29e98673f0a..5cac0848bf1 100644 --- a/packages/bsky/src/lexicon/types/com/atproto/repo/createRecord.ts +++ b/packages/bsky/src/lexicon/types/com/atproto/repo/createRecord.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -29,6 +30,7 @@ export interface InputSchema { export interface OutputSchema { uri: string cid: string + commit?: ComAtprotoRepoDefs.CommitMeta validationStatus?: 'valid' | 'unknown' | (string & {}) [k: string]: unknown } diff --git a/packages/bsky/src/lexicon/types/com/atproto/repo/defs.ts b/packages/bsky/src/lexicon/types/com/atproto/repo/defs.ts new file mode 100644 index 00000000000..8357fe2a611 --- /dev/null +++ b/packages/bsky/src/lexicon/types/com/atproto/repo/defs.ts @@ -0,0 +1,25 @@ +/** + * 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 CommitMeta { + cid: string + rev: string + [k: string]: unknown +} + +export function isCommitMeta(v: unknown): v is CommitMeta { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'com.atproto.repo.defs#commitMeta' + ) +} + +export function validateCommitMeta(v: unknown): ValidationResult { + return lexicons.validate('com.atproto.repo.defs#commitMeta', v) +} diff --git a/packages/bsky/src/lexicon/types/com/atproto/repo/deleteRecord.ts b/packages/bsky/src/lexicon/types/com/atproto/repo/deleteRecord.ts index 3bb97be0aad..e594cd00adf 100644 --- a/packages/bsky/src/lexicon/types/com/atproto/repo/deleteRecord.ts +++ b/packages/bsky/src/lexicon/types/com/atproto/repo/deleteRecord.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -24,18 +25,29 @@ export interface InputSchema { [k: string]: unknown } +export interface OutputSchema { + commit?: ComAtprotoRepoDefs.CommitMeta + [k: string]: unknown +} + export interface HandlerInput { encoding: 'application/json' body: InputSchema } +export interface HandlerSuccess { + encoding: 'application/json' + body: OutputSchema + headers?: { [key: string]: string } +} + export interface HandlerError { status: number message?: string error?: 'InvalidSwap' } -export type HandlerOutput = HandlerError | void +export type HandlerOutput = HandlerError | HandlerSuccess | HandlerPipeThrough export type HandlerReqCtx = { auth: HA params: QueryParams diff --git a/packages/bsky/src/lexicon/types/com/atproto/repo/putRecord.ts b/packages/bsky/src/lexicon/types/com/atproto/repo/putRecord.ts index 2f7aa21df28..5cde768d7c2 100644 --- a/packages/bsky/src/lexicon/types/com/atproto/repo/putRecord.ts +++ b/packages/bsky/src/lexicon/types/com/atproto/repo/putRecord.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -31,6 +32,7 @@ export interface InputSchema { export interface OutputSchema { uri: string cid: string + commit?: ComAtprotoRepoDefs.CommitMeta validationStatus?: 'valid' | 'unknown' | (string & {}) [k: string]: unknown } diff --git a/packages/ozone/src/lexicon/lexicons.ts b/packages/ozone/src/lexicon/lexicons.ts index 6ba34d1040e..5111b619dea 100644 --- a/packages/ozone/src/lexicon/lexicons.ts +++ b/packages/ozone/src/lexicon/lexicons.ts @@ -1284,6 +1284,10 @@ export const schemaDict = { type: 'object', required: [], properties: { + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, results: { type: 'array', items: { @@ -1461,6 +1465,10 @@ export const schemaDict = { type: 'string', format: 'cid', }, + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, validationStatus: { type: 'string', knownValues: ['valid', 'unknown'], @@ -1478,6 +1486,25 @@ export const schemaDict = { }, }, }, + ComAtprotoRepoDefs: { + lexicon: 1, + id: 'com.atproto.repo.defs', + defs: { + commitMeta: { + type: 'object', + required: ['cid', 'rev'], + properties: { + cid: { + type: 'string', + format: 'cid', + }, + rev: { + type: 'string', + }, + }, + }, + }, + }, ComAtprotoRepoDeleteRecord: { lexicon: 1, id: 'com.atproto.repo.deleteRecord', @@ -1522,6 +1549,18 @@ export const schemaDict = { }, }, }, + output: { + encoding: 'application/json', + schema: { + type: 'object', + properties: { + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, + }, + }, + }, errors: [ { name: 'InvalidSwap', @@ -1878,6 +1917,10 @@ export const schemaDict = { type: 'string', format: 'cid', }, + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, validationStatus: { type: 'string', knownValues: ['valid', 'unknown'], @@ -12151,6 +12194,7 @@ export const ids = { ComAtprotoModerationDefs: 'com.atproto.moderation.defs', ComAtprotoRepoApplyWrites: 'com.atproto.repo.applyWrites', ComAtprotoRepoCreateRecord: 'com.atproto.repo.createRecord', + ComAtprotoRepoDefs: 'com.atproto.repo.defs', ComAtprotoRepoDeleteRecord: 'com.atproto.repo.deleteRecord', ComAtprotoRepoDescribeRepo: 'com.atproto.repo.describeRepo', ComAtprotoRepoGetRecord: 'com.atproto.repo.getRecord', diff --git a/packages/ozone/src/lexicon/types/com/atproto/repo/applyWrites.ts b/packages/ozone/src/lexicon/types/com/atproto/repo/applyWrites.ts index acfae03c439..4e3c8dcef3d 100644 --- a/packages/ozone/src/lexicon/types/com/atproto/repo/applyWrites.ts +++ b/packages/ozone/src/lexicon/types/com/atproto/repo/applyWrites.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -22,6 +23,7 @@ export interface InputSchema { } export interface OutputSchema { + commit?: ComAtprotoRepoDefs.CommitMeta results?: (CreateResult | UpdateResult | DeleteResult)[] [k: string]: unknown } diff --git a/packages/ozone/src/lexicon/types/com/atproto/repo/createRecord.ts b/packages/ozone/src/lexicon/types/com/atproto/repo/createRecord.ts index 29e98673f0a..5cac0848bf1 100644 --- a/packages/ozone/src/lexicon/types/com/atproto/repo/createRecord.ts +++ b/packages/ozone/src/lexicon/types/com/atproto/repo/createRecord.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -29,6 +30,7 @@ export interface InputSchema { export interface OutputSchema { uri: string cid: string + commit?: ComAtprotoRepoDefs.CommitMeta validationStatus?: 'valid' | 'unknown' | (string & {}) [k: string]: unknown } diff --git a/packages/ozone/src/lexicon/types/com/atproto/repo/defs.ts b/packages/ozone/src/lexicon/types/com/atproto/repo/defs.ts new file mode 100644 index 00000000000..8357fe2a611 --- /dev/null +++ b/packages/ozone/src/lexicon/types/com/atproto/repo/defs.ts @@ -0,0 +1,25 @@ +/** + * 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 CommitMeta { + cid: string + rev: string + [k: string]: unknown +} + +export function isCommitMeta(v: unknown): v is CommitMeta { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'com.atproto.repo.defs#commitMeta' + ) +} + +export function validateCommitMeta(v: unknown): ValidationResult { + return lexicons.validate('com.atproto.repo.defs#commitMeta', v) +} diff --git a/packages/ozone/src/lexicon/types/com/atproto/repo/deleteRecord.ts b/packages/ozone/src/lexicon/types/com/atproto/repo/deleteRecord.ts index 3bb97be0aad..e594cd00adf 100644 --- a/packages/ozone/src/lexicon/types/com/atproto/repo/deleteRecord.ts +++ b/packages/ozone/src/lexicon/types/com/atproto/repo/deleteRecord.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -24,18 +25,29 @@ export interface InputSchema { [k: string]: unknown } +export interface OutputSchema { + commit?: ComAtprotoRepoDefs.CommitMeta + [k: string]: unknown +} + export interface HandlerInput { encoding: 'application/json' body: InputSchema } +export interface HandlerSuccess { + encoding: 'application/json' + body: OutputSchema + headers?: { [key: string]: string } +} + export interface HandlerError { status: number message?: string error?: 'InvalidSwap' } -export type HandlerOutput = HandlerError | void +export type HandlerOutput = HandlerError | HandlerSuccess | HandlerPipeThrough export type HandlerReqCtx = { auth: HA params: QueryParams diff --git a/packages/ozone/src/lexicon/types/com/atproto/repo/putRecord.ts b/packages/ozone/src/lexicon/types/com/atproto/repo/putRecord.ts index 2f7aa21df28..5cde768d7c2 100644 --- a/packages/ozone/src/lexicon/types/com/atproto/repo/putRecord.ts +++ b/packages/ozone/src/lexicon/types/com/atproto/repo/putRecord.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -31,6 +32,7 @@ export interface InputSchema { export interface OutputSchema { uri: string cid: string + commit?: ComAtprotoRepoDefs.CommitMeta validationStatus?: 'valid' | 'unknown' | (string & {}) [k: string]: unknown } diff --git a/packages/pds/src/api/com/atproto/repo/applyWrites.ts b/packages/pds/src/api/com/atproto/repo/applyWrites.ts index 9d299e02247..7fa537c3791 100644 --- a/packages/pds/src/api/com/atproto/repo/applyWrites.ts +++ b/packages/pds/src/api/com/atproto/repo/applyWrites.ts @@ -134,6 +134,10 @@ export default function (server: Server, ctx: AppContext) { return { encoding: 'application/json', body: { + commit: { + cid: commit.cid.toString(), + rev: commit.rev, + }, results: writes.map(writeToOutputResult), }, } diff --git a/packages/pds/src/api/com/atproto/repo/createRecord.ts b/packages/pds/src/api/com/atproto/repo/createRecord.ts index 04b0db67f86..38d90d7482c 100644 --- a/packages/pds/src/api/com/atproto/repo/createRecord.ts +++ b/packages/pds/src/api/com/atproto/repo/createRecord.ts @@ -106,6 +106,10 @@ export default function (server: Server, ctx: AppContext) { body: { uri: write.uri.toString(), cid: write.cid.toString(), + commit: { + cid: commit.cid.toString(), + rev: commit.rev, + }, validationStatus: write.validationStatus, }, } diff --git a/packages/pds/src/api/com/atproto/repo/deleteRecord.ts b/packages/pds/src/api/com/atproto/repo/deleteRecord.ts index d23f0f834dd..bef27a5ede3 100644 --- a/packages/pds/src/api/com/atproto/repo/deleteRecord.ts +++ b/packages/pds/src/api/com/atproto/repo/deleteRecord.ts @@ -71,6 +71,17 @@ export default function (server: Server, ctx: AppContext) { await ctx.sequencer.sequenceCommit(did, commit, [write]) await ctx.accountManager.updateRepoRoot(did, commit.cid, commit.rev) } + return { + encoding: 'application/json', + body: { + commit: commit + ? { + cid: commit.cid.toString(), + rev: commit.rev, + } + : undefined, + }, + } }, }) } diff --git a/packages/pds/src/api/com/atproto/repo/putRecord.ts b/packages/pds/src/api/com/atproto/repo/putRecord.ts index 2ba93b27d56..927d27f6992 100644 --- a/packages/pds/src/api/com/atproto/repo/putRecord.ts +++ b/packages/pds/src/api/com/atproto/repo/putRecord.ts @@ -130,6 +130,12 @@ export default function (server: Server, ctx: AppContext) { body: { uri: write.uri.toString(), cid: write.cid.toString(), + commit: commit + ? { + cid: commit.cid.toString(), + rev: commit.rev, + } + : undefined, validationStatus: write.validationStatus, }, } diff --git a/packages/pds/src/lexicon/lexicons.ts b/packages/pds/src/lexicon/lexicons.ts index 6ba34d1040e..5111b619dea 100644 --- a/packages/pds/src/lexicon/lexicons.ts +++ b/packages/pds/src/lexicon/lexicons.ts @@ -1284,6 +1284,10 @@ export const schemaDict = { type: 'object', required: [], properties: { + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, results: { type: 'array', items: { @@ -1461,6 +1465,10 @@ export const schemaDict = { type: 'string', format: 'cid', }, + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, validationStatus: { type: 'string', knownValues: ['valid', 'unknown'], @@ -1478,6 +1486,25 @@ export const schemaDict = { }, }, }, + ComAtprotoRepoDefs: { + lexicon: 1, + id: 'com.atproto.repo.defs', + defs: { + commitMeta: { + type: 'object', + required: ['cid', 'rev'], + properties: { + cid: { + type: 'string', + format: 'cid', + }, + rev: { + type: 'string', + }, + }, + }, + }, + }, ComAtprotoRepoDeleteRecord: { lexicon: 1, id: 'com.atproto.repo.deleteRecord', @@ -1522,6 +1549,18 @@ export const schemaDict = { }, }, }, + output: { + encoding: 'application/json', + schema: { + type: 'object', + properties: { + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, + }, + }, + }, errors: [ { name: 'InvalidSwap', @@ -1878,6 +1917,10 @@ export const schemaDict = { type: 'string', format: 'cid', }, + commit: { + type: 'ref', + ref: 'lex:com.atproto.repo.defs#commitMeta', + }, validationStatus: { type: 'string', knownValues: ['valid', 'unknown'], @@ -12151,6 +12194,7 @@ export const ids = { ComAtprotoModerationDefs: 'com.atproto.moderation.defs', ComAtprotoRepoApplyWrites: 'com.atproto.repo.applyWrites', ComAtprotoRepoCreateRecord: 'com.atproto.repo.createRecord', + ComAtprotoRepoDefs: 'com.atproto.repo.defs', ComAtprotoRepoDeleteRecord: 'com.atproto.repo.deleteRecord', ComAtprotoRepoDescribeRepo: 'com.atproto.repo.describeRepo', ComAtprotoRepoGetRecord: 'com.atproto.repo.getRecord', diff --git a/packages/pds/src/lexicon/types/com/atproto/repo/applyWrites.ts b/packages/pds/src/lexicon/types/com/atproto/repo/applyWrites.ts index acfae03c439..4e3c8dcef3d 100644 --- a/packages/pds/src/lexicon/types/com/atproto/repo/applyWrites.ts +++ b/packages/pds/src/lexicon/types/com/atproto/repo/applyWrites.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -22,6 +23,7 @@ export interface InputSchema { } export interface OutputSchema { + commit?: ComAtprotoRepoDefs.CommitMeta results?: (CreateResult | UpdateResult | DeleteResult)[] [k: string]: unknown } diff --git a/packages/pds/src/lexicon/types/com/atproto/repo/createRecord.ts b/packages/pds/src/lexicon/types/com/atproto/repo/createRecord.ts index 29e98673f0a..5cac0848bf1 100644 --- a/packages/pds/src/lexicon/types/com/atproto/repo/createRecord.ts +++ b/packages/pds/src/lexicon/types/com/atproto/repo/createRecord.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -29,6 +30,7 @@ export interface InputSchema { export interface OutputSchema { uri: string cid: string + commit?: ComAtprotoRepoDefs.CommitMeta validationStatus?: 'valid' | 'unknown' | (string & {}) [k: string]: unknown } diff --git a/packages/pds/src/lexicon/types/com/atproto/repo/defs.ts b/packages/pds/src/lexicon/types/com/atproto/repo/defs.ts new file mode 100644 index 00000000000..8357fe2a611 --- /dev/null +++ b/packages/pds/src/lexicon/types/com/atproto/repo/defs.ts @@ -0,0 +1,25 @@ +/** + * 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 CommitMeta { + cid: string + rev: string + [k: string]: unknown +} + +export function isCommitMeta(v: unknown): v is CommitMeta { + return ( + isObj(v) && + hasProp(v, '$type') && + v.$type === 'com.atproto.repo.defs#commitMeta' + ) +} + +export function validateCommitMeta(v: unknown): ValidationResult { + return lexicons.validate('com.atproto.repo.defs#commitMeta', v) +} diff --git a/packages/pds/src/lexicon/types/com/atproto/repo/deleteRecord.ts b/packages/pds/src/lexicon/types/com/atproto/repo/deleteRecord.ts index 3bb97be0aad..e594cd00adf 100644 --- a/packages/pds/src/lexicon/types/com/atproto/repo/deleteRecord.ts +++ b/packages/pds/src/lexicon/types/com/atproto/repo/deleteRecord.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -24,18 +25,29 @@ export interface InputSchema { [k: string]: unknown } +export interface OutputSchema { + commit?: ComAtprotoRepoDefs.CommitMeta + [k: string]: unknown +} + export interface HandlerInput { encoding: 'application/json' body: InputSchema } +export interface HandlerSuccess { + encoding: 'application/json' + body: OutputSchema + headers?: { [key: string]: string } +} + export interface HandlerError { status: number message?: string error?: 'InvalidSwap' } -export type HandlerOutput = HandlerError | void +export type HandlerOutput = HandlerError | HandlerSuccess | HandlerPipeThrough export type HandlerReqCtx = { auth: HA params: QueryParams diff --git a/packages/pds/src/lexicon/types/com/atproto/repo/putRecord.ts b/packages/pds/src/lexicon/types/com/atproto/repo/putRecord.ts index 2f7aa21df28..5cde768d7c2 100644 --- a/packages/pds/src/lexicon/types/com/atproto/repo/putRecord.ts +++ b/packages/pds/src/lexicon/types/com/atproto/repo/putRecord.ts @@ -7,6 +7,7 @@ import { lexicons } from '../../../../lexicons' import { isObj, hasProp } from '../../../../util' import { CID } from 'multiformats/cid' import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server' +import * as ComAtprotoRepoDefs from './defs' export interface QueryParams {} @@ -31,6 +32,7 @@ export interface InputSchema { export interface OutputSchema { uri: string cid: string + commit?: ComAtprotoRepoDefs.CommitMeta validationStatus?: 'valid' | 'unknown' | (string & {}) [k: string]: unknown }