@atproto/lex-server 0.0.0-spaces-alpha-20260818163953

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,597 @@
1
+ import { type DidString, type InferMethodInput, type InferMethodMessage, type InferMethodOutput, type InferMethodOutputBody, type InferMethodOutputEncoding, type InferMethodParams, type Main, type NsidString, type Procedure, type Query, type Subscription } from '@atproto/lex-schema';
2
+ import { LexServerError } from './errors.js';
3
+ type Awaitable<T> = T | Promise<T>;
4
+ /**
5
+ * Union type representing the supported Lexicon method types.
6
+ *
7
+ * - `Query`: Read-only methods invoked via HTTP GET
8
+ * - `Procedure`: Methods that may modify state, invoked via HTTP POST
9
+ * - `Subscription`: Real-time streaming methods over WebSocket
10
+ */
11
+ export type LexMethod = Query | Procedure | Subscription;
12
+ /**
13
+ * Network address for TCP or UDP connections.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const addr: NetAddr = {
18
+ * hostname: '127.0.0.1',
19
+ * port: 3000,
20
+ * transport: 'tcp'
21
+ * }
22
+ * ```
23
+ */
24
+ export type NetAddr = {
25
+ /** The hostname or IP address of the connection. */
26
+ hostname: string;
27
+ /** The port number of the connection. */
28
+ port: number;
29
+ /** The transport protocol used. */
30
+ transport: 'tcp' | 'udp';
31
+ };
32
+ /**
33
+ * Unix domain socket address.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const addr: UnixAddr = {
38
+ * path: '/var/run/app.sock',
39
+ * transport: 'unix'
40
+ * }
41
+ * ```
42
+ */
43
+ export type UnixAddr = {
44
+ /** The filesystem path to the Unix socket. */
45
+ path: string;
46
+ /** The transport protocol used. */
47
+ transport: 'unix' | 'unixpacket';
48
+ };
49
+ /**
50
+ * Union type for all supported address types.
51
+ *
52
+ * Can be a network address ({@link NetAddr}), Unix socket address ({@link UnixAddr}),
53
+ * or `undefined` when the address is not available.
54
+ */
55
+ export type Addr = NetAddr | UnixAddr | undefined;
56
+ /**
57
+ * Metadata about the client connection for an incoming request.
58
+ *
59
+ * @typeParam A - The address type, defaults to {@link Addr}
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const info: ConnectionInfo<NetAddr> = {
64
+ * remoteAddr: { hostname: '192.168.1.1', port: 54321, transport: 'tcp' },
65
+ * completed: new Promise((resolve) => socket.on('close', resolve))
66
+ * }
67
+ * ```
68
+ */
69
+ export type ConnectionInfo<A extends Addr = Addr> = {
70
+ /** The remote address of the client, if available. */
71
+ remoteAddr: A;
72
+ /** Promise that resolves when the connection is fully closed. */
73
+ completed: Promise<void>;
74
+ };
75
+ /**
76
+ * Function signature for handling HTTP requests in the XRPC router.
77
+ *
78
+ * This is the standard fetch-style handler that processes incoming requests
79
+ * and returns responses. It is used both internally by the router and can
80
+ * be used to integrate with other HTTP frameworks.
81
+ *
82
+ * @param request - The incoming HTTP request
83
+ * @param connection - Optional connection metadata including remote address
84
+ * @returns A promise resolving to the HTTP response
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const handler: FetchHandler = async (request, connection) => {
89
+ * console.log('Request from:', connection?.remoteAddr)
90
+ * return new Response('Hello, World!')
91
+ * }
92
+ * ```
93
+ */
94
+ export type FetchHandler = (request: Request, connection?: ConnectionInfo) => Promise<Response>;
95
+ /**
96
+ * Context object passed to XRPC method handlers.
97
+ *
98
+ * Contains all the information needed to process a request, including
99
+ * parsed parameters, authentication credentials, and the raw request object.
100
+ *
101
+ * @typeParam Method - The Lexicon method type (Query, Procedure, or Subscription)
102
+ * @typeParam Credentials - The type of authentication credentials, determined by the auth handler
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const handler: LexRouterMethodHandler<MyMethod, UserCredentials> = async (ctx) => {
107
+ * const { credentials, params, input, signal } = ctx
108
+ * // credentials.userId is available if auth handler returns UserCredentials
109
+ * // params contains validated query parameters
110
+ * // input contains the request body (for procedures)
111
+ * // signal can be used to abort long-running operations
112
+ * return { body: { result: 'success' } }
113
+ * }
114
+ * ```
115
+ */
116
+ export type LexRouterHandlerContext<Method extends LexMethod, Credentials> = {
117
+ /** Authentication credentials returned by the auth handler. */
118
+ credentials: Credentials;
119
+ /** Parsed and validated request input (body for procedures, undefined for queries). */
120
+ input: InferMethodInput<Method, Body>;
121
+ /** Parsed and validated URL query parameters. */
122
+ params: InferMethodParams<Method>;
123
+ /** The original HTTP request object. */
124
+ request: Request;
125
+ /** Abort signal that is triggered when the request is cancelled. */
126
+ signal: AbortSignal;
127
+ /** Connection metadata including remote address. */
128
+ connection?: ConnectionInfo;
129
+ };
130
+ type AsOptionalPayloadOptions<T> = T extends undefined | void ? {
131
+ encoding?: undefined;
132
+ body?: undefined;
133
+ } : T;
134
+ /**
135
+ * Return type for XRPC method handlers (queries and procedures).
136
+ *
137
+ * Handlers can return either:
138
+ * - A raw {@link Response} object for full control over the HTTP response
139
+ * - An object with `body`, optional `encoding`, and optional `headers`
140
+ *
141
+ * For JSON methods, the body is automatically serialized. For other encodings,
142
+ * the body must be a valid {@link BodyInit} type.
143
+ *
144
+ * @typeParam Method - The Lexicon method type (Query or Procedure)
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Return JSON body (most common)
149
+ * return { body: { users: [...] } }
150
+ *
151
+ * // Return with custom headers
152
+ * return {
153
+ * body: { data: 'value' },
154
+ * headers: { 'Cache-Control': 'max-age=3600' }
155
+ * }
156
+ *
157
+ * // Return raw Response for full control
158
+ * return new Response(binaryData, {
159
+ * headers: { 'Content-Type': 'application/octet-stream' }
160
+ * })
161
+ * ```
162
+ */
163
+ export type LexRouterHandlerOutput<Method extends Query | Procedure> = Response | ({
164
+ headers?: HeadersInit;
165
+ } & (InferMethodOutputEncoding<Method> extends 'application/json' ? {
166
+ encoding?: 'application/json';
167
+ body: InferMethodOutputBody<Method>;
168
+ } : AsOptionalPayloadOptions<InferMethodOutput<Method, BodyInit>>));
169
+ /**
170
+ * Handler function for XRPC query and procedure methods.
171
+ *
172
+ * Receives a context object with request details and credentials,
173
+ * and returns either a Response or a structured output object.
174
+ *
175
+ * @typeParam Method - The Lexicon method type (Query or Procedure)
176
+ * @typeParam Credentials - The type of authentication credentials
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const getProfile: LexRouterMethodHandler<GetProfileMethod, UserCredentials> = async (ctx) => {
181
+ * const profile = await db.getProfile(ctx.params.actor)
182
+ * return { body: profile }
183
+ * }
184
+ * ```
185
+ */
186
+ export type LexRouterMethodHandler<Method extends Query | Procedure = Query | Procedure, Credentials = unknown> = (ctx: LexRouterHandlerContext<Method, Credentials>) => Awaitable<LexRouterHandlerOutput<Method>>;
187
+ /**
188
+ * Configuration object for registering an XRPC method with authentication.
189
+ *
190
+ * Used when you need to specify both a handler and an auth function.
191
+ *
192
+ * @typeParam Method - The Lexicon method type (Query or Procedure)
193
+ * @typeParam Credentials - The type of authentication credentials
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const config: LexRouterMethodConfig<GetProfileMethod, UserCredentials> = {
198
+ * handler: async (ctx) => {
199
+ * return { body: await getProfile(ctx.params.actor) }
200
+ * },
201
+ * auth: async ({ request }) => {
202
+ * return verifyToken(request.headers.get('authorization'))
203
+ * }
204
+ * }
205
+ * ```
206
+ */
207
+ export type LexRouterMethodConfig<Method extends Query | Procedure = Query | Procedure, Credentials = unknown> = {
208
+ /** The handler function that processes the request. */
209
+ handler: LexRouterMethodHandler<Method, Credentials>;
210
+ /** Authentication function that validates credentials before the handler runs. */
211
+ auth: LexRouterAuth<Credentials, Method>;
212
+ };
213
+ /**
214
+ * Handler function for XRPC subscription methods (WebSocket streams).
215
+ *
216
+ * Returns an async iterable that yields messages to be sent over the WebSocket.
217
+ * The connection remains open until the iterable completes or an error occurs.
218
+ *
219
+ * @typeParam Method - The Lexicon subscription method type
220
+ * @typeParam Credentials - The type of authentication credentials
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * const subscribeRepos: LexRouterSubscriptionHandler<SubscribeReposMethod> = async function* (ctx) {
225
+ * const cursor = ctx.params.cursor ?? 0
226
+ * for await (const event of eventStream.since(cursor)) {
227
+ * if (ctx.signal.aborted) break
228
+ * yield { $type: 'com.atproto.sync.subscribeRepos#commit', ...event }
229
+ * }
230
+ * }
231
+ * ```
232
+ */
233
+ export type LexRouterSubscriptionHandler<Method extends Subscription = Subscription, Credentials = unknown> = (ctx: LexRouterHandlerContext<Method, Credentials>) => AsyncIterable<InferMethodMessage<Method>>;
234
+ /**
235
+ * Configuration object for registering an XRPC subscription with authentication.
236
+ *
237
+ * Used when you need to specify both a handler and an auth function for subscriptions.
238
+ *
239
+ * @typeParam Method - The Lexicon subscription method type
240
+ * @typeParam Credentials - The type of authentication credentials
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const config: LexRouterSubscriptionConfig<SubscribeReposMethod, ServiceCredentials> = {
245
+ * handler: async function* (ctx) {
246
+ * for await (const event of eventStream) {
247
+ * yield event
248
+ * }
249
+ * },
250
+ * auth: async ({ request }) => {
251
+ * return verifyServiceAuth(request)
252
+ * }
253
+ * }
254
+ * ```
255
+ */
256
+ export type LexRouterSubscriptionConfig<Method extends Subscription = Subscription, Credentials = unknown> = {
257
+ /** The handler function that yields subscription messages. */
258
+ handler: LexRouterSubscriptionHandler<Method, Credentials>;
259
+ /** Authentication function that validates credentials before the handler runs. */
260
+ auth: LexRouterAuth<Credentials, Method>;
261
+ };
262
+ /**
263
+ * Context object passed to authentication handlers.
264
+ *
265
+ * Contains the information needed to authenticate a request before
266
+ * the main handler is invoked.
267
+ *
268
+ * @typeParam Method - The Lexicon method type
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * const authHandler: LexRouterAuth<UserCredentials> = async (ctx) => {
273
+ * const token = ctx.request.headers.get('authorization')
274
+ * if (!token) throw new LexServerAuthError('AuthenticationRequired', 'Missing token')
275
+ * return { userId: await verifyToken(token) }
276
+ * }
277
+ * ```
278
+ */
279
+ export type LexRouterAuthContext<Method extends LexMethod = LexMethod> = {
280
+ /** The Lexicon method definition being called. */
281
+ method: Method;
282
+ /** Parsed and validated URL query parameters. */
283
+ params: InferMethodParams<Method>;
284
+ /** The original HTTP request object. */
285
+ request: Request;
286
+ /** Connection metadata including remote address. */
287
+ connection?: ConnectionInfo;
288
+ };
289
+ /**
290
+ * Authentication handler function for XRPC methods.
291
+ *
292
+ * Called before the main handler to validate authentication credentials.
293
+ * Should return the validated credentials or throw an error if authentication fails.
294
+ *
295
+ * @typeParam Credentials - The type of credentials to return on success
296
+ * @typeParam Method - The Lexicon method type
297
+ *
298
+ * @example
299
+ * ```typescript
300
+ * // Simple token-based auth
301
+ * const tokenAuth: LexRouterAuth<{ userId: string }> = async ({ request }) => {
302
+ * const token = request.headers.get('authorization')?.replace('Bearer ', '')
303
+ * if (!token) throw new LexServerAuthError('AuthenticationRequired', 'Token required')
304
+ * const userId = await verifyToken(token)
305
+ * if (!userId) throw new LexServerAuthError('AuthenticationRequired', 'Invalid token')
306
+ * return { userId }
307
+ * }
308
+ *
309
+ * // Using with serviceAuth for AT Protocol service authentication
310
+ * import { serviceAuth } from '@atproto/lex-server'
311
+ * const auth = serviceAuth({ audience: 'did:web:example.com', unique: checkNonce })
312
+ * ```
313
+ */
314
+ export type LexRouterAuth<Credentials = unknown, Method extends LexMethod = LexMethod> = (ctx: LexRouterAuthContext<Method>) => Credentials | Promise<Credentials>;
315
+ /**
316
+ * Context object passed to error handler callbacks.
317
+ *
318
+ * Used for logging and monitoring errors that occur during request handling.
319
+ */
320
+ export type HandlerErrorContext = {
321
+ request: Request;
322
+ method: LexMethod;
323
+ error: LexServerError;
324
+ };
325
+ export type HandlerErrorHook = (ctx: HandlerErrorContext) => void | Promise<void>;
326
+ export type SocketErrorContext = {
327
+ request: Request;
328
+ method: Subscription;
329
+ error: unknown;
330
+ };
331
+ export type SocketErrorHook = (ctx: SocketErrorContext) => void | Promise<void>;
332
+ /**
333
+ * Function that upgrades an HTTP request to a WebSocket connection.
334
+ *
335
+ * This is platform-specific: Deno provides this natively, while Node.js
336
+ * requires the `upgradeWebSocket` function from this package.
337
+ *
338
+ * @param request - The HTTP request to upgrade
339
+ * @returns An object containing the WebSocket and the upgrade response
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * // In Node.js, use the provided upgradeWebSocket function
344
+ * import { upgradeWebSocket } from '@atproto/lex-server/nodejs'
345
+ *
346
+ * const router = new LexRouter({ upgradeWebSocket })
347
+ * ```
348
+ */
349
+ export type UpgradeWebSocket = (request: Request) => {
350
+ /** The WebSocket instance for bidirectional communication. */
351
+ socket: WebSocket;
352
+ /** The HTTP response to return (101 Switching Protocols). */
353
+ response: Response;
354
+ };
355
+ export type HealthCheckHandler = (request: Request) => Awaitable<{
356
+ [x: string]: unknown;
357
+ status: 'ok';
358
+ }>;
359
+ /**
360
+ * Configuration options for the {@link LexRouter}.
361
+ *
362
+ * @example
363
+ * ```typescript
364
+ * const options: LexRouterOptions = {
365
+ * upgradeWebSocket,
366
+ * onHandlerError: async ({ error, request, method }) => {
367
+ * console.error(`Error in ${method.nsid}:`, error)
368
+ * await reportToSentry(error)
369
+ * },
370
+ * highWaterMark: 64 * 1024, // 64KB
371
+ * lowWaterMark: 16 * 1024 // 16KB
372
+ * }
373
+ * ```
374
+ */
375
+ export type LexRouterOptions = {
376
+ /**
377
+ * Function to upgrade HTTP requests to WebSocket connections. Required for
378
+ * subscription methods. Defaults to Deno's built-in
379
+ * {@link globalThis.upgradeWebSocket} if available. For NodeJS, use the
380
+ * homonymous export from `@atproto/lex-server/nodejs`.
381
+ */
382
+ upgradeWebSocket?: UpgradeWebSocket;
383
+ /**
384
+ * Callback invoked when an error occurs during request handling. Useful for
385
+ * logging and error reporting. Not called for client-induced errors (e.g.,
386
+ * request abortion).
387
+ */
388
+ onHandlerError?: HandlerErrorHook;
389
+ /**
390
+ * Optional hook for handling errors during generation of WebSocket messages.
391
+ */
392
+ onSocketError?: SocketErrorHook;
393
+ /**
394
+ * Optional health check handler. If provided, this function will be called
395
+ * for requests to the /xrpc/_health endpoint, allowing for custom health
396
+ * check logic and responses.
397
+ *
398
+ * If not provided, the server will respond to /xrpc/_health requests with a
399
+ * default JSON response of `{ status: 'ok' }`.
400
+ */
401
+ healthCheck?: HealthCheckHandler;
402
+ /**
403
+ * Optional fallback handler for requests that are not /xrpc/ paths. Can be
404
+ * used to serve static files or other routes. If not provided, non-/xrpc/
405
+ * requests will return 404 responses.
406
+ */
407
+ fallback?: FetchHandler;
408
+ /**
409
+ * High water mark for WebSocket backpressure (in bytes). When buffered data
410
+ * exceeds this, the handler will wait before sending more.
411
+ */
412
+ highWaterMark?: number;
413
+ /**
414
+ * Low water mark for WebSocket backpressure (in bytes). The handler resumes
415
+ * sending when buffered data drops below this.
416
+ */
417
+ lowWaterMark?: number;
418
+ };
419
+ /**
420
+ * XRPC router for handling AT Protocol Lexicon methods.
421
+ *
422
+ * The router handles HTTP routing, parameter parsing, input validation,
423
+ * authentication, and response serialization for XRPC methods. It supports
424
+ * queries (GET), procedures (POST), and subscriptions (WebSocket).
425
+ *
426
+ * @example Setting up a basic XRPC server
427
+ * ```typescript
428
+ * import { LexRouter } from '@atproto/lex-server'
429
+ * import { serve, upgradeWebSocket } from '@atproto/lex-server/nodejs'
430
+ * import { getProfile, createPost, subscribeRepos } from './lexicons.js'
431
+ *
432
+ * const router = new LexRouter({ upgradeWebSocket })
433
+ *
434
+ * // Register a query handler (GET request)
435
+ * router.add(getProfile, async (ctx) => {
436
+ * const profile = await db.getProfile(ctx.params.actor)
437
+ * return { body: profile }
438
+ * })
439
+ *
440
+ * // Register a procedure handler with authentication (POST request)
441
+ * router.add(createPost, {
442
+ * handler: async (ctx) => {
443
+ * const post = await db.createPost(ctx.credentials.did, ctx.input.body)
444
+ * return { body: { uri: post.uri, cid: post.cid } }
445
+ * },
446
+ * auth: async ({ request }) => {
447
+ * return verifyAccessToken(request)
448
+ * }
449
+ * })
450
+ *
451
+ * // Register a subscription handler (WebSocket)
452
+ * router.add(subscribeRepos, async function* (ctx) {
453
+ * for await (const event of eventStream.since(ctx.params.cursor)) {
454
+ * if (ctx.signal.aborted) break
455
+ * yield event
456
+ * }
457
+ * })
458
+ *
459
+ * // Start the server
460
+ * const server = await serve(router, { port: 3000 })
461
+ * console.log('XRPC server listening on port 3000')
462
+ * ```
463
+ *
464
+ * @example Using with service authentication
465
+ * ```typescript
466
+ * import { LexRouter, serviceAuth } from '@atproto/lex-server'
467
+ *
468
+ * const router = new LexRouter()
469
+ *
470
+ * const auth = serviceAuth({
471
+ * audience: 'did:web:api.example.com',
472
+ * unique: async (nonce) => {
473
+ * // Check and record nonce uniqueness
474
+ * return await nonceStore.checkAndAdd(nonce)
475
+ * }
476
+ * })
477
+ *
478
+ * router.add(protectedMethod, {
479
+ * handler: async (ctx) => {
480
+ * // ctx.credentials contains { did, didDocument, jwt }
481
+ * return { body: { callerDid: ctx.credentials.did } }
482
+ * },
483
+ * auth
484
+ * })
485
+ * ```
486
+ */
487
+ export declare class LexRouter {
488
+ /** Map of NSID strings to their fetch handlers. */
489
+ readonly handlers: Map<NsidString, FetchHandler>;
490
+ options: LexRouterOptions;
491
+ /**
492
+ * Creates a new XRPC router.
493
+ *
494
+ * @param options - Router configuration options
495
+ */
496
+ constructor(options?: LexRouterOptions);
497
+ /**
498
+ * Registers a subscription handler without authentication.
499
+ *
500
+ * @param ns - The Lexicon namespace definition for the subscription
501
+ * @param handler - Async generator function that yields subscription messages
502
+ * @returns This router instance for chaining
503
+ */
504
+ add<M extends Subscription>(ns: Main<M>, handler: LexRouterSubscriptionHandler<M, void>): this;
505
+ /**
506
+ * Registers a subscription handler with authentication.
507
+ *
508
+ * @param ns - The Lexicon namespace definition for the subscription
509
+ * @param config - Configuration object with handler and auth function
510
+ * @returns This router instance for chaining
511
+ */
512
+ add<M extends Subscription, Credentials>(ns: Main<M>, config: LexRouterSubscriptionConfig<M, Credentials>): this;
513
+ /**
514
+ * Registers a query or procedure handler without authentication.
515
+ *
516
+ * @param ns - The Lexicon namespace definition for the method
517
+ * @param handler - Handler function that processes requests
518
+ * @returns This router instance for chaining
519
+ */
520
+ add<M extends Query | Procedure>(ns: Main<M>, handler: LexRouterMethodHandler<M, void>): this;
521
+ /**
522
+ * Registers a query or procedure handler with authentication.
523
+ *
524
+ * @param ns - The Lexicon namespace definition for the method
525
+ * @param config - Configuration object with handler and auth function
526
+ * @returns This router instance for chaining
527
+ */
528
+ add<M extends Query | Procedure, Credentials>(ns: Main<M>, config: LexRouterMethodConfig<M, Credentials>): this;
529
+ /**
530
+ * Registers a Lexicon method handler.
531
+ *
532
+ * This is the unified overload that accepts any method type with optional authentication.
533
+ *
534
+ * @param ns - The Lexicon namespace definition
535
+ * @param config - Handler function or configuration object
536
+ * @returns This router instance for chaining
537
+ *
538
+ * @throws {TypeError} If a method with the same NSID is already registered
539
+ *
540
+ * @example
541
+ * ```typescript
542
+ * // Register without auth (credentials will be void)
543
+ * router.add(myQuery, async (ctx) => {
544
+ * return { body: { data: 'value' } }
545
+ * })
546
+ *
547
+ * // Register with auth
548
+ * router.add(myProcedure, {
549
+ * handler: async (ctx) => {
550
+ * console.log('Caller:', ctx.credentials.userId)
551
+ * return { body: { success: true } }
552
+ * },
553
+ * auth: async ({ request }) => ({ userId: await verifyToken(request) })
554
+ * })
555
+ * ```
556
+ */
557
+ add<M extends LexMethod, Credentials = unknown>(ns: Main<M>, config: M extends Subscription ? LexRouterSubscriptionHandler<M, Credentials> | LexRouterSubscriptionConfig<M, Credentials> : M extends Query | Procedure ? LexRouterMethodHandler<M, Credentials> | LexRouterMethodConfig<M, Credentials> : never): this;
558
+ private buildMethodHandler;
559
+ private buildSubscriptionHandler;
560
+ private handlerError;
561
+ /**
562
+ * The main fetch handler for processing XRPC requests.
563
+ *
564
+ * Routes incoming requests to the appropriate method handler based on the
565
+ * NSID in the URL path. Returns appropriate error responses for invalid
566
+ * paths or unimplemented methods.
567
+ *
568
+ * This handler can be used directly with HTTP servers that support the
569
+ * fetch API pattern, or converted to a Node.js request listener using
570
+ * `toRequestListener()`.
571
+ *
572
+ * @param request - The incoming HTTP request
573
+ * @param connection - Optional connection metadata
574
+ * @returns A promise resolving to the HTTP response
575
+ *
576
+ * @example
577
+ * ```typescript
578
+ * // Use with Deno
579
+ * Deno.serve(router.fetch)
580
+ *
581
+ * // Use with Bun
582
+ * Bun.serve({ fetch: router.fetch })
583
+ *
584
+ * // Use with Node.js
585
+ * import { toRequestListener } from '@atproto/lex-server/nodejs'
586
+ * const listener = toRequestListener(router.fetch)
587
+ * http.createServer(listener).listen(3000)
588
+ * ```
589
+ */
590
+ fetch: FetchHandler;
591
+ }
592
+ export type ServiceProxyInfo = {
593
+ did: DidString;
594
+ serviceId: string;
595
+ };
596
+ export {};
597
+ //# sourceMappingURL=lex-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lex-router.d.ts","sourceRoot":"","sources":["../src/lex-router.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,YAAY,EAIlB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAM5C,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAElC;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,YAAY,CAAA;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAA;IAChB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,mCAAmC;IACnC,SAAS,EAAE,KAAK,GAAG,KAAK,CAAA;CACzB,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,QAAQ,GAAG;I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