Scratch space for learning atproto app development
1/**
2 * GENERATED CODE - DO NOT MODIFY
3 */
4import {
5 createServer as createXrpcServer,
6 Server as XrpcServer,
7 Options as XrpcOptions,
8 AuthVerifier,
9 StreamAuthVerifier,
10} from '@atproto/xrpc-server'
11import { schemas } from './lexicons'
12
13export function createServer(options?: XrpcOptions): Server {
14 return new Server(options)
15}
16
17export class Server {
18 xrpc: XrpcServer
19 example: ExampleNS
20
21 constructor(options?: XrpcOptions) {
22 this.xrpc = createXrpcServer(schemas, options)
23 this.example = new ExampleNS(this)
24 }
25}
26
27export class ExampleNS {
28 _server: Server
29 lexicon: ExampleLexiconNS
30
31 constructor(server: Server) {
32 this._server = server
33 this.lexicon = new ExampleLexiconNS(server)
34 }
35}
36
37export class ExampleLexiconNS {
38 _server: Server
39
40 constructor(server: Server) {
41 this._server = server
42 }
43}
44
45type SharedRateLimitOpts<T> = {
46 name: string
47 calcKey?: (ctx: T) => string
48 calcPoints?: (ctx: T) => number
49}
50type RouteRateLimitOpts<T> = {
51 durationMs: number
52 points: number
53 calcKey?: (ctx: T) => string
54 calcPoints?: (ctx: T) => number
55}
56type HandlerOpts = { blobLimit?: number }
57type HandlerRateLimitOpts<T> = SharedRateLimitOpts<T> | RouteRateLimitOpts<T>
58type ConfigOf<Auth, Handler, ReqCtx> =
59 | Handler
60 | {
61 auth?: Auth
62 opts?: HandlerOpts
63 rateLimit?: HandlerRateLimitOpts<ReqCtx> | HandlerRateLimitOpts<ReqCtx>[]
64 handler: Handler
65 }
66type ExtractAuth<AV extends AuthVerifier | StreamAuthVerifier> = Extract<
67 Awaited<ReturnType<AV>>,
68 { credentials: unknown }
69>