@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/procedures.test.ts
CHANGED
|
@@ -5,9 +5,14 @@ import { Readable } from 'node:stream'
|
|
|
5
5
|
import { LexiconDoc } from '@atproto/lexicon'
|
|
6
6
|
import { XrpcClient } from '@atproto/xrpc'
|
|
7
7
|
import * as xrpcServer from '../src'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
buildAddLexicons,
|
|
10
|
+
buildMethodLexicons,
|
|
11
|
+
closeServer,
|
|
12
|
+
createServer,
|
|
13
|
+
} from './_util'
|
|
9
14
|
|
|
10
|
-
const LEXICONS
|
|
15
|
+
const LEXICONS = [
|
|
11
16
|
{
|
|
12
17
|
lexicon: 1,
|
|
13
18
|
id: 'io.example.pingOne',
|
|
@@ -81,18 +86,16 @@ const LEXICONS: LexiconDoc[] = [
|
|
|
81
86
|
},
|
|
82
87
|
},
|
|
83
88
|
},
|
|
84
|
-
]
|
|
89
|
+
] as const satisfies LexiconDoc[]
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const server = xrpcServer.createServer(LEXICONS)
|
|
89
|
-
server.method('io.example.pingOne', (ctx) => {
|
|
91
|
+
const handlers = {
|
|
92
|
+
'io.example.pingOne': (ctx: xrpcServer.HandlerContext) => {
|
|
90
93
|
return { encoding: 'text/plain', body: ctx.params.message }
|
|
91
|
-
}
|
|
92
|
-
|
|
94
|
+
},
|
|
95
|
+
'io.example.pingTwo': (ctx: xrpcServer.HandlerContext) => {
|
|
93
96
|
return { encoding: 'text/plain', body: ctx.input?.body }
|
|
94
|
-
}
|
|
95
|
-
|
|
97
|
+
},
|
|
98
|
+
'io.example.pingThree': async (ctx: xrpcServer.HandlerContext) => {
|
|
96
99
|
assert(ctx.input?.body instanceof Readable, 'Input not readable')
|
|
97
100
|
const buffers: Buffer[] = []
|
|
98
101
|
for await (const data of ctx.input.body) {
|
|
@@ -102,56 +105,72 @@ describe('Procedures', () => {
|
|
|
102
105
|
encoding: 'application/octet-stream',
|
|
103
106
|
body: Buffer.concat(buffers),
|
|
104
107
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
108
|
+
},
|
|
109
|
+
'io.example.pingFour': (ctx: xrpcServer.HandlerContext) => {
|
|
107
110
|
return {
|
|
108
111
|
encoding: 'application/json',
|
|
109
112
|
body: { message: ctx.input?.body?.['message'] },
|
|
110
113
|
}
|
|
111
|
-
}
|
|
114
|
+
},
|
|
115
|
+
}
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
s
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
for (const buildServer of [buildMethodLexicons, buildAddLexicons]) {
|
|
118
|
+
describe(buildServer, () => {
|
|
119
|
+
let s: http.Server
|
|
120
|
+
let client: XrpcClient
|
|
121
|
+
let url: string
|
|
122
|
+
beforeAll(async () => {
|
|
123
|
+
const server = await buildServer(LEXICONS, handlers)
|
|
124
|
+
s = await createServer(server)
|
|
125
|
+
const { port } = s.address() as AddressInfo
|
|
126
|
+
url = `http://localhost:${port}`
|
|
127
|
+
client = new XrpcClient(url, LEXICONS)
|
|
128
|
+
})
|
|
129
|
+
afterAll(async () => {
|
|
130
|
+
if (s) await closeServer(s)
|
|
131
|
+
})
|
|
122
132
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
test('io.example.pingOne', async () => {
|
|
134
|
+
const res = await client.call('io.example.pingOne', {
|
|
135
|
+
message: 'hello world',
|
|
136
|
+
})
|
|
137
|
+
expect(res.success).toBeTruthy()
|
|
138
|
+
expect(res.headers['content-type']).toBe('text/plain; charset=utf-8')
|
|
139
|
+
expect(res.data).toBe('hello world')
|
|
126
140
|
})
|
|
127
|
-
expect(res1.success).toBeTruthy()
|
|
128
|
-
expect(res1.headers['content-type']).toBe('text/plain; charset=utf-8')
|
|
129
|
-
expect(res1.data).toBe('hello world')
|
|
130
141
|
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
test('io.example.pingTwo', async () => {
|
|
143
|
+
const res = await client.call('io.example.pingTwo', {}, 'hello world', {
|
|
144
|
+
encoding: 'text/plain',
|
|
145
|
+
})
|
|
146
|
+
expect(res.success).toBeTruthy()
|
|
147
|
+
expect(res.headers['content-type']).toBe('text/plain; charset=utf-8')
|
|
148
|
+
expect(res.data).toBe('hello world')
|
|
133
149
|
})
|
|
134
|
-
expect(res2.success).toBeTruthy()
|
|
135
|
-
expect(res2.headers['content-type']).toBe('text/plain; charset=utf-8')
|
|
136
|
-
expect(res2.data).toBe('hello world')
|
|
137
150
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
test('io.example.pingThree', async () => {
|
|
152
|
+
const res = await client.call(
|
|
153
|
+
'io.example.pingThree',
|
|
154
|
+
{},
|
|
155
|
+
new TextEncoder().encode('hello world'),
|
|
156
|
+
{ encoding: 'application/octet-stream' },
|
|
157
|
+
)
|
|
158
|
+
expect(res.success).toBeTruthy()
|
|
159
|
+
expect(res.headers['content-type']).toBe('application/octet-stream')
|
|
160
|
+
expect(new TextDecoder().decode(res.data)).toBe('hello world')
|
|
161
|
+
})
|
|
147
162
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
163
|
+
test('io.example.pingFour', async () => {
|
|
164
|
+
const res = await client.call(
|
|
165
|
+
'io.example.pingFour',
|
|
166
|
+
{},
|
|
167
|
+
{ message: 'hello world' },
|
|
168
|
+
)
|
|
169
|
+
expect(res.success).toBeTruthy()
|
|
170
|
+
expect(res.headers['content-type']).toBe(
|
|
171
|
+
'application/json; charset=utf-8',
|
|
172
|
+
)
|
|
173
|
+
expect(res.data?.message).toBe('hello world')
|
|
174
|
+
})
|
|
156
175
|
})
|
|
157
|
-
}
|
|
176
|
+
}
|
package/tests/queries.test.ts
CHANGED
|
@@ -3,9 +3,14 @@ import { AddressInfo } from 'node:net'
|
|
|
3
3
|
import { LexiconDoc } from '@atproto/lexicon'
|
|
4
4
|
import { XrpcClient } from '@atproto/xrpc'
|
|
5
5
|
import * as xrpcServer from '../src'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
buildAddLexicons,
|
|
8
|
+
buildMethodLexicons,
|
|
9
|
+
closeServer,
|
|
10
|
+
createServer,
|
|
11
|
+
} from './_util'
|
|
7
12
|
|
|
8
|
-
const LEXICONS
|
|
13
|
+
const LEXICONS = [
|
|
9
14
|
{
|
|
10
15
|
lexicon: 1,
|
|
11
16
|
id: 'io.example.pingOne',
|
|
@@ -65,59 +70,71 @@ const LEXICONS: LexiconDoc[] = [
|
|
|
65
70
|
},
|
|
66
71
|
},
|
|
67
72
|
},
|
|
68
|
-
]
|
|
73
|
+
] as const satisfies LexiconDoc[]
|
|
69
74
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const server = xrpcServer.createServer(LEXICONS)
|
|
73
|
-
server.method('io.example.pingOne', (ctx) => {
|
|
75
|
+
const handlers = {
|
|
76
|
+
'io.example.pingOne': (ctx: xrpcServer.HandlerContext) => {
|
|
74
77
|
return { encoding: 'text/plain', body: ctx.params.message }
|
|
75
|
-
}
|
|
76
|
-
|
|
78
|
+
},
|
|
79
|
+
'io.example.pingTwo': (ctx: xrpcServer.HandlerContext) => {
|
|
77
80
|
return {
|
|
78
81
|
encoding: 'application/octet-stream',
|
|
79
82
|
body: new TextEncoder().encode(String(ctx.params.message)),
|
|
80
83
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
84
|
+
},
|
|
85
|
+
'io.example.pingThree': (ctx: xrpcServer.HandlerContext) => {
|
|
83
86
|
return {
|
|
84
87
|
encoding: 'application/json',
|
|
85
88
|
body: { message: ctx.params.message },
|
|
86
89
|
headers: { 'x-test-header-name': 'test-value' },
|
|
87
90
|
}
|
|
88
|
-
}
|
|
91
|
+
},
|
|
92
|
+
}
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
s
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
for (const buildServer of [buildMethodLexicons, buildAddLexicons]) {
|
|
95
|
+
describe(buildServer, () => {
|
|
96
|
+
let s: http.Server
|
|
97
|
+
let client: XrpcClient
|
|
98
|
+
let url: string
|
|
99
|
+
beforeAll(async () => {
|
|
100
|
+
const server = await buildServer(LEXICONS, handlers)
|
|
101
|
+
s = await createServer(server)
|
|
102
|
+
const { port } = s.address() as AddressInfo
|
|
103
|
+
url = `http://localhost:${port}`
|
|
104
|
+
client = new XrpcClient(url, LEXICONS)
|
|
105
|
+
})
|
|
106
|
+
afterAll(async () => {
|
|
107
|
+
if (s) await closeServer(s)
|
|
108
|
+
})
|
|
99
109
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
test('io.example.pingOne', async () => {
|
|
111
|
+
const res = await client.call('io.example.pingOne', {
|
|
112
|
+
message: 'hello world',
|
|
113
|
+
})
|
|
114
|
+
expect(res.success).toBeTruthy()
|
|
115
|
+
expect(res.headers['content-type']).toBe('text/plain; charset=utf-8')
|
|
116
|
+
expect(res.data).toBe('hello world')
|
|
103
117
|
})
|
|
104
|
-
expect(res1.success).toBeTruthy()
|
|
105
|
-
expect(res1.headers['content-type']).toBe('text/plain; charset=utf-8')
|
|
106
|
-
expect(res1.data).toBe('hello world')
|
|
107
118
|
|
|
108
|
-
|
|
109
|
-
|
|
119
|
+
test('io.example.pingTwo', async () => {
|
|
120
|
+
const res = await client.call('io.example.pingTwo', {
|
|
121
|
+
message: 'hello world',
|
|
122
|
+
})
|
|
123
|
+
expect(res.success).toBeTruthy()
|
|
124
|
+
expect(res.headers['content-type']).toBe('application/octet-stream')
|
|
125
|
+
expect(new TextDecoder().decode(res.data)).toBe('hello world')
|
|
110
126
|
})
|
|
111
|
-
expect(res2.success).toBeTruthy()
|
|
112
|
-
expect(res2.headers['content-type']).toBe('application/octet-stream')
|
|
113
|
-
expect(new TextDecoder().decode(res2.data)).toBe('hello world')
|
|
114
127
|
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
test('io.example.pingThree', async () => {
|
|
129
|
+
const res = await client.call('io.example.pingThree', {
|
|
130
|
+
message: 'hello world',
|
|
131
|
+
})
|
|
132
|
+
expect(res.success).toBeTruthy()
|
|
133
|
+
expect(res.headers['content-type']).toBe(
|
|
134
|
+
'application/json; charset=utf-8',
|
|
135
|
+
)
|
|
136
|
+
expect(res.data?.message).toBe('hello world')
|
|
137
|
+
expect(res.headers['x-test-header-name']).toEqual('test-value')
|
|
117
138
|
})
|
|
118
|
-
expect(res3.success).toBeTruthy()
|
|
119
|
-
expect(res3.headers['content-type']).toBe('application/json; charset=utf-8')
|
|
120
|
-
expect(res3.data?.message).toBe('hello world')
|
|
121
|
-
expect(res3.headers['x-test-header-name']).toEqual('test-value')
|
|
122
139
|
})
|
|
123
|
-
}
|
|
140
|
+
}
|