@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.
Files changed (45) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/auth.js +11 -11
  3. package/dist/auth.js.map +1 -1
  4. package/dist/errors.d.ts +67 -0
  5. package/dist/errors.d.ts.map +1 -0
  6. package/dist/errors.js +202 -0
  7. package/dist/errors.js.map +1 -0
  8. package/dist/index.d.ts +4 -3
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +5 -3
  11. package/dist/index.js.map +1 -1
  12. package/dist/rate-limiter.d.ts +69 -32
  13. package/dist/rate-limiter.d.ts.map +1 -1
  14. package/dist/rate-limiter.js +58 -41
  15. package/dist/rate-limiter.js.map +1 -1
  16. package/dist/server.d.ts +19 -14
  17. package/dist/server.d.ts.map +1 -1
  18. package/dist/server.js +151 -137
  19. package/dist/server.js.map +1 -1
  20. package/dist/types.d.ts +80 -178
  21. package/dist/types.d.ts.map +1 -1
  22. package/dist/types.js +9 -226
  23. package/dist/types.js.map +1 -1
  24. package/dist/util.d.ts +9 -8
  25. package/dist/util.d.ts.map +1 -1
  26. package/dist/util.js +148 -108
  27. package/dist/util.js.map +1 -1
  28. package/package.json +4 -3
  29. package/src/auth.ts +1 -1
  30. package/src/errors.ts +293 -0
  31. package/src/index.ts +9 -3
  32. package/src/rate-limiter.ts +188 -96
  33. package/src/server.ts +198 -154
  34. package/src/types.ts +144 -439
  35. package/src/util.ts +176 -125
  36. package/tests/auth.test.ts +2 -2
  37. package/tests/bodies.test.ts +18 -27
  38. package/tests/errors.test.ts +1 -1
  39. package/tests/ipld.test.ts +15 -14
  40. package/tests/parameters.test.ts +4 -7
  41. package/tests/procedures.test.ts +22 -34
  42. package/tests/queries.test.ts +9 -12
  43. package/tests/rate-limiter.test.ts +7 -7
  44. package/tests/responses.test.ts +12 -15
  45. package/tsconfig.build.tsbuildinfo +1 -1
@@ -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: { params: xrpcServer.Params }) => {
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: { params: xrpcServer.Params }) => {
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
- 'io.example.pingThree',
84
- (ctx: { params: xrpcServer.Params }) => {
85
- return {
86
- encoding: 'application/json',
87
- body: { message: ctx.params.message },
88
- headers: { 'x-test-header-name': 'test-value' },
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 { RateLimiter } from '../src'
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) => RateLimiter.memory(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: { params: xrpcServer.Params }) => ({
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: xrpcServer.XRPCReqContext) => {
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: { params: xrpcServer.Params }) => ({
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: { params: xrpcServer.Params }) => ({
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: { params: xrpcServer.Params }) => ({
212
+ handler: (ctx) => ({
213
213
  encoding: 'json',
214
214
  body: ctx.params,
215
215
  }),
@@ -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
- 'io.example.readableStream',
35
- async (ctx: { params: xrpcServer.Params }) => {
36
- async function* iter(): AsyncIterable<Uint8Array> {
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
- return {
45
- encoding: 'application/vnd.ipld.car',
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"}