@atproto/xrpc-server 0.8.0 → 0.9.1
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 +34 -0
- package/dist/auth.js +11 -11
- package/dist/auth.js.map +1 -1
- package/dist/errors.d.ts +67 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +202 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/rate-limiter.d.ts +69 -32
- package/dist/rate-limiter.d.ts.map +1 -1
- package/dist/rate-limiter.js +58 -41
- package/dist/rate-limiter.js.map +1 -1
- package/dist/server.d.ts +19 -14
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +151 -137
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +80 -178
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -226
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +9 -8
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +148 -108
- package/dist/util.js.map +1 -1
- package/package.json +4 -3
- package/src/auth.ts +1 -1
- package/src/errors.ts +293 -0
- package/src/index.ts +9 -3
- package/src/rate-limiter.ts +188 -96
- package/src/server.ts +198 -154
- package/src/types.ts +144 -439
- package/src/util.ts +176 -125
- package/tests/auth.test.ts +2 -2
- package/tests/bodies.test.ts +18 -27
- package/tests/errors.test.ts +1 -1
- package/tests/ipld.test.ts +15 -14
- package/tests/parameters.test.ts +4 -7
- package/tests/procedures.test.ts +22 -34
- package/tests/queries.test.ts +9 -12
- package/tests/rate-limiter.test.ts +7 -7
- package/tests/responses.test.ts +12 -15
- package/tsconfig.build.tsbuildinfo +1 -1
package/tests/queries.test.ts
CHANGED
|
@@ -70,25 +70,22 @@ const LEXICONS: LexiconDoc[] = [
|
|
|
70
70
|
describe('Queries', () => {
|
|
71
71
|
let s: http.Server
|
|
72
72
|
const server = xrpcServer.createServer(LEXICONS)
|
|
73
|
-
server.method('io.example.pingOne', (ctx
|
|
73
|
+
server.method('io.example.pingOne', (ctx) => {
|
|
74
74
|
return { encoding: 'text/plain', body: ctx.params.message }
|
|
75
75
|
})
|
|
76
|
-
server.method('io.example.pingTwo', (ctx
|
|
76
|
+
server.method('io.example.pingTwo', (ctx) => {
|
|
77
77
|
return {
|
|
78
78
|
encoding: 'application/octet-stream',
|
|
79
79
|
body: new TextEncoder().encode(String(ctx.params.message)),
|
|
80
80
|
}
|
|
81
81
|
})
|
|
82
|
-
server.method(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
)
|
|
82
|
+
server.method('io.example.pingThree', (ctx) => {
|
|
83
|
+
return {
|
|
84
|
+
encoding: 'application/json',
|
|
85
|
+
body: { message: ctx.params.message },
|
|
86
|
+
headers: { 'x-test-header-name': 'test-value' },
|
|
87
|
+
}
|
|
88
|
+
})
|
|
92
89
|
|
|
93
90
|
let client: XrpcClient
|
|
94
91
|
beforeAll(async () => {
|
|
@@ -4,7 +4,7 @@ import { MINUTE } from '@atproto/common'
|
|
|
4
4
|
import { LexiconDoc } from '@atproto/lexicon'
|
|
5
5
|
import { XrpcClient } from '@atproto/xrpc'
|
|
6
6
|
import * as xrpcServer from '../src'
|
|
7
|
-
import {
|
|
7
|
+
import { MemoryRateLimiter } from '../src'
|
|
8
8
|
import { closeServer, createServer } from './_util'
|
|
9
9
|
|
|
10
10
|
const LEXICONS: LexiconDoc[] = [
|
|
@@ -132,7 +132,7 @@ describe('Parameters', () => {
|
|
|
132
132
|
let s: http.Server
|
|
133
133
|
const server = xrpcServer.createServer(LEXICONS, {
|
|
134
134
|
rateLimits: {
|
|
135
|
-
creator: (opts) =>
|
|
135
|
+
creator: (opts) => new MemoryRateLimiter(opts),
|
|
136
136
|
bypass: ({ req }) => req.headers['x-ratelimit-bypass'] === 'bypass',
|
|
137
137
|
shared: [
|
|
138
138
|
{
|
|
@@ -156,7 +156,7 @@ describe('Parameters', () => {
|
|
|
156
156
|
points: 5,
|
|
157
157
|
calcKey: ({ params }) => params.str as string,
|
|
158
158
|
},
|
|
159
|
-
handler: (ctx
|
|
159
|
+
handler: (ctx) => ({
|
|
160
160
|
encoding: 'json',
|
|
161
161
|
body: ctx.params,
|
|
162
162
|
}),
|
|
@@ -166,7 +166,7 @@ describe('Parameters', () => {
|
|
|
166
166
|
durationMs: 5 * MINUTE,
|
|
167
167
|
points: 2,
|
|
168
168
|
},
|
|
169
|
-
handler: (ctx
|
|
169
|
+
handler: (ctx) => {
|
|
170
170
|
if (ctx.params.count === 1) {
|
|
171
171
|
ctx.resetRouteRateLimits()
|
|
172
172
|
}
|
|
@@ -182,7 +182,7 @@ describe('Parameters', () => {
|
|
|
182
182
|
name: 'shared-limit',
|
|
183
183
|
calcPoints: ({ params }) => params.points as number,
|
|
184
184
|
},
|
|
185
|
-
handler: (ctx
|
|
185
|
+
handler: (ctx) => ({
|
|
186
186
|
encoding: 'json',
|
|
187
187
|
body: ctx.params,
|
|
188
188
|
}),
|
|
@@ -192,7 +192,7 @@ describe('Parameters', () => {
|
|
|
192
192
|
name: 'shared-limit',
|
|
193
193
|
calcPoints: ({ params }) => params.points as number,
|
|
194
194
|
},
|
|
195
|
-
handler: (ctx
|
|
195
|
+
handler: (ctx) => ({
|
|
196
196
|
encoding: 'json',
|
|
197
197
|
body: ctx.params,
|
|
198
198
|
}),
|
|
@@ -209,7 +209,7 @@ describe('Parameters', () => {
|
|
|
209
209
|
points: 10,
|
|
210
210
|
},
|
|
211
211
|
],
|
|
212
|
-
handler: (ctx
|
|
212
|
+
handler: (ctx) => ({
|
|
213
213
|
encoding: 'json',
|
|
214
214
|
body: ctx.params,
|
|
215
215
|
}),
|
package/tests/responses.test.ts
CHANGED
|
@@ -30,23 +30,20 @@ const LEXICONS: LexiconDoc[] = [
|
|
|
30
30
|
describe('Responses', () => {
|
|
31
31
|
let s: http.Server
|
|
32
32
|
const server = xrpcServer.createServer(LEXICONS)
|
|
33
|
-
server.method(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
for (let i = 0; i < 5; i++) {
|
|
38
|
-
yield new Uint8Array([i])
|
|
39
|
-
}
|
|
40
|
-
if (ctx.params.shouldErr) {
|
|
41
|
-
throw new Error('error')
|
|
42
|
-
}
|
|
33
|
+
server.method('io.example.readableStream', async (ctx) => {
|
|
34
|
+
async function* iter(): AsyncIterable<Uint8Array> {
|
|
35
|
+
for (let i = 0; i < 5; i++) {
|
|
36
|
+
yield new Uint8Array([i])
|
|
43
37
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
body: byteIterableToStream(iter()),
|
|
38
|
+
if (ctx.params.shouldErr) {
|
|
39
|
+
throw new Error('error')
|
|
47
40
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
encoding: 'application/vnd.ipld.car',
|
|
44
|
+
body: byteIterableToStream(iter()),
|
|
45
|
+
}
|
|
46
|
+
})
|
|
50
47
|
|
|
51
48
|
let client: XrpcClient
|
|
52
49
|
beforeAll(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/auth.ts","./src/index.ts","./src/logger.ts","./src/rate-limiter.ts","./src/server.ts","./src/types.ts","./src/util.ts","./src/stream/frames.ts","./src/stream/index.ts","./src/stream/logger.ts","./src/stream/server.ts","./src/stream/stream.ts","./src/stream/subscription.ts","./src/stream/types.ts","./src/stream/websocket-keepalive.ts"],"version":"5.8.2"}
|
|
1
|
+
{"root":["./src/auth.ts","./src/errors.ts","./src/index.ts","./src/logger.ts","./src/rate-limiter.ts","./src/server.ts","./src/types.ts","./src/util.ts","./src/stream/frames.ts","./src/stream/index.ts","./src/stream/logger.ts","./src/stream/server.ts","./src/stream/stream.ts","./src/stream/subscription.ts","./src/stream/types.ts","./src/stream/websocket-keepalive.ts"],"version":"5.8.2"}
|