UNPKG

@atproto/lexicon-resolver

Version:

ATProto Lexicon resolution

99 lines (95 loc) 2.47 kB
/** * GENERATED CODE - DO NOT MODIFY */ import { type LexiconDoc, Lexicons, ValidationError, type ValidationResult, } from '@atproto/lexicon' import { type $Typed, is$typed, maybe$typed } from './util.js' export const schemaDict = { ComAtprotoSyncGetRecord: { lexicon: 1, id: 'com.atproto.sync.getRecord', defs: { main: { type: 'query', description: 'Get data blocks needed to prove the existence or non-existence of record in the current version of repo. Does not require auth.', parameters: { type: 'params', required: ['did', 'collection', 'rkey'], properties: { did: { type: 'string', format: 'did', description: 'The DID of the repo.', }, collection: { type: 'string', format: 'nsid', }, rkey: { type: 'string', description: 'Record Key', format: 'record-key', }, }, }, output: { encoding: 'application/vnd.ipld.car', }, errors: [ { name: 'RecordNotFound', }, { name: 'RepoNotFound', }, { name: 'RepoTakendown', }, { name: 'RepoSuspended', }, { name: 'RepoDeactivated', }, ], }, }, }, } as const satisfies Record<string, LexiconDoc> export const schemas = Object.values(schemaDict) satisfies LexiconDoc[] export const lexicons: Lexicons = new Lexicons(schemas) export function validate<T extends { $type: string }>( v: unknown, id: string, hash: string, requiredType: true, ): ValidationResult<T> export function validate<T extends { $type?: string }>( v: unknown, id: string, hash: string, requiredType?: false, ): ValidationResult<T> export function validate( v: unknown, id: string, hash: string, requiredType?: boolean, ): ValidationResult { return (requiredType ? is$typed : maybe$typed)(v, id, hash) ? lexicons.validate(`${id}#${hash}`, v) : { success: false, error: new ValidationError( `Must be an object with "${hash === 'main' ? id : `${id}#${hash}`}" $type property`, ), } } export const ids = { ComAtprotoSyncGetRecord: 'com.atproto.sync.getRecord', } as const