@atproto/xrpc-server 0.10.14 → 0.10.16
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.
- package/CHANGELOG.md +23 -0
- package/dist/auth.d.ts +3 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +18 -0
- package/dist/auth.js.map +1 -1
- package/dist/errors.d.ts +7 -14
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +19 -6
- package/dist/errors.js.map +1 -1
- package/dist/server.d.ts +27 -11
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +115 -78
- package/dist/server.js.map +1 -1
- package/dist/stream/frames.d.ts +5 -1
- package/dist/stream/frames.d.ts.map +1 -1
- package/dist/stream/frames.js +32 -5
- package/dist/stream/frames.js.map +1 -1
- package/dist/stream/types.d.ts +18 -44
- package/dist/stream/types.d.ts.map +1 -1
- package/dist/stream/types.js +10 -10
- package/dist/stream/types.js.map +1 -1
- package/dist/types.d.ts +47 -70
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +28 -15
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +18 -9
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +180 -37
- package/dist/util.js.map +1 -1
- package/package.json +11 -7
- package/src/auth.ts +28 -2
- package/src/errors.ts +23 -7
- package/src/server.ts +307 -111
- package/src/stream/frames.ts +39 -6
- package/src/stream/types.ts +14 -14
- package/src/types.ts +106 -25
- package/src/util.ts +272 -60
- package/tests/_util.ts +62 -5
- package/tests/bodies.test.ts +442 -387
- package/tests/procedures.test.ts +71 -52
- package/tests/queries.test.ts +56 -39
- package/tests/subscriptions.test.ts +234 -221
package/tests/_util.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { once } from 'node:events'
|
|
2
2
|
import * as http from 'node:http'
|
|
3
3
|
import express from 'express'
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
LexiconDocument,
|
|
6
|
+
LexiconIterableIndexer,
|
|
7
|
+
LexiconSchemaBuilder,
|
|
8
|
+
} from '@atproto/lex-document'
|
|
9
|
+
import { LexiconDoc } from '@atproto/lexicon'
|
|
10
|
+
import {
|
|
11
|
+
AuthRequiredError,
|
|
12
|
+
MethodConfigOrHandler,
|
|
13
|
+
Options,
|
|
14
|
+
Server,
|
|
15
|
+
StreamConfigOrHandler,
|
|
16
|
+
} from '../src'
|
|
6
17
|
|
|
7
|
-
export async function createServer({
|
|
8
|
-
router,
|
|
9
|
-
}: xrpc.Server): Promise<http.Server> {
|
|
18
|
+
export async function createServer({ router }: Server): Promise<http.Server> {
|
|
10
19
|
const app = express()
|
|
11
20
|
app.use(router)
|
|
12
21
|
const httpServer = app.listen(0)
|
|
@@ -53,3 +62,51 @@ export function basicAuthHeaders(creds: {
|
|
|
53
62
|
Buffer.from(`${creds.username}:${creds.password}`).toString('base64'),
|
|
54
63
|
}
|
|
55
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Builds a lexicon server based on an `@atproto/lexicon`
|
|
68
|
+
* {@link import('@atproto/lexicon').Lexicons} instance. Validation will be
|
|
69
|
+
* performed by {@link import('@atproto/lexicon').Lexicons}'s various assertion
|
|
70
|
+
* methods. This allows for testing the server's integration with
|
|
71
|
+
* `@atproto/lexicon`.
|
|
72
|
+
*/
|
|
73
|
+
export async function buildMethodLexicons(
|
|
74
|
+
lexicons: LexiconDoc[],
|
|
75
|
+
handlers: Record<string, MethodConfigOrHandler | StreamConfigOrHandler>,
|
|
76
|
+
options?: Options,
|
|
77
|
+
) {
|
|
78
|
+
const server = new Server(structuredClone(lexicons), options)
|
|
79
|
+
for (const [id, handler] of Object.entries(handlers)) {
|
|
80
|
+
const def = server.lex.getDef(id)
|
|
81
|
+
if (def?.type === 'subscription') {
|
|
82
|
+
server.addStreamMethod(id, handler as StreamConfigOrHandler)
|
|
83
|
+
} else {
|
|
84
|
+
server.method(id, handler as MethodConfigOrHandler)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return server
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Builds a lexicon server based on `@atproto/lex`'s
|
|
92
|
+
* {@link import('@atproto/lex').Query},
|
|
93
|
+
* {@link import('@atproto/lex').Procedure}, and
|
|
94
|
+
* {@link import('@atproto/lex').Subscription} method definitions. Validation
|
|
95
|
+
* will be performed through built schema verifiers created by
|
|
96
|
+
* {@link LexiconSchemaBuilder}. This helper allows for testing the server's
|
|
97
|
+
* integration with `@atproto/lex`.
|
|
98
|
+
*/
|
|
99
|
+
export async function buildAddLexicons(
|
|
100
|
+
lexicons: LexiconDocument[],
|
|
101
|
+
handlers: Record<string, MethodConfigOrHandler | StreamConfigOrHandler>,
|
|
102
|
+
options?: Options,
|
|
103
|
+
) {
|
|
104
|
+
const server = new Server(undefined, options)
|
|
105
|
+
await using indexer = new LexiconIterableIndexer(structuredClone(lexicons))
|
|
106
|
+
await using builder = new LexiconSchemaBuilder(indexer)
|
|
107
|
+
for (const [id, handler] of Object.entries(handlers)) {
|
|
108
|
+
const schema = await builder.buildFullRef(`${id}#main`)
|
|
109
|
+
server.add(schema as any, handler as any)
|
|
110
|
+
}
|
|
111
|
+
return server
|
|
112
|
+
}
|