Something went wrong. Try again.
tiny REST API that resolves AT Protocol Lexicon schemas from NSIDs lex.desertthunder.dev
lexicon atproto rest jsx dns hono htmx
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import { resolver } from 'hono-openapi';import * as v from 'valibot';
export const NsidParamSchema = v.object({ nsid: v.pipe(v.string(), v.description('Lexicon schema NSID, such as app.bsky.feed.post'))});
export const UriQuerySchema = v.object({ uri: v.optional(v.pipe(v.string(), v.description('AT URI or HTTPS URL for a com.atproto.lexicon.schema record')))});
const VersionSchema = v.pipe(v.string(), v.description('lexdns package version'));
const ParsedNsidSchema = v.object({ nsid: v.string(), authority: v.string(), domain: v.string(), name: v.string(), dnsName: v.string()});
const TxtRecordSchema = v.object({ name: v.string(), data: v.string(), ttl: v.optional(v.number()) });
const TraceFetchSchema = v.object({ url: v.nullable(v.string()), status: v.nullable(v.number()) });
const ApiErrorCodeSchema = v.picklist(['bad_request', 'not_found', 'upstream_error', 'internal_error']);
const TraceFinalSchema = v.object({ success: v.boolean(), code: v.optional(ApiErrorCodeSchema), message: v.string() });
export const ResolutionTraceSchema = v.object({ dnsName: v.nullable(v.string()), txtRecords: v.array(TxtRecordSchema), selectedDid: v.nullable(v.string()), didDocument: TraceFetchSchema, pdsEndpoint: v.nullable(v.string()), repoGetRecord: TraceFetchSchema, final: TraceFinalSchema});
const LexiconDocumentSchema = v.objectWithRest( { lexicon: v.literal(1), id: v.string(), defs: v.record(v.string(), v.unknown()) }, v.unknown());
const LinksSchema = v.object({ self: v.object({ href: v.string() }), source: v.object({ href: v.string() }) });
export const ResolvedLexiconResponseSchema = v.object({ version: VersionSchema, nsid: v.string(), parsed: ParsedNsidSchema, hash: v.string(), fetchedAt: v.string(), source: v.object({ name: v.string(), url: v.string() }), lexicon: LexiconDocumentSchema, cache: v.picklist(['hit', 'miss']), trace: ResolutionTraceSchema, _links: LinksSchema});
export const ErrorResponseSchema = v.object({ version: VersionSchema, error: v.object({ code: ApiErrorCodeSchema, message: v.string() }), trace: v.optional(ResolutionTraceSchema)});
export const JSON_CONTENT = { 'application/json': { schema: resolver(ResolvedLexiconResponseSchema) } };
export const ERROR_JSON_CONTENT = { 'application/json': { schema: resolver(ErrorResponseSchema) } };