@atproto/xrpc-server 0.0.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/README.md +42 -0
- package/babel.config.js +1 -0
- package/build.js +22 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +34790 -0
- package/dist/index.js.map +7 -0
- package/dist/logger.d.ts +2 -0
- package/dist/server.d.ts +19 -0
- package/dist/types.d.ts +115 -0
- package/dist/util.d.ts +10 -0
- package/jest.config.js +6 -0
- package/package.json +35 -0
- package/src/index.ts +2 -0
- package/src/logger.ts +5 -0
- package/src/server.ts +253 -0
- package/src/types.ts +159 -0
- package/src/util.ts +237 -0
- package/tests/_util.ts +20 -0
- package/tests/auth.test.ts +155 -0
- package/tests/bodies.test.ts +240 -0
- package/tests/errors.test.ts +214 -0
- package/tests/parameters.test.ts +189 -0
- package/tests/procedures.test.ts +165 -0
- package/tests/queries.test.ts +117 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +14 -0
- package/update-pkg.js +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# XRPC Server API
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import * as xrpc from '@atproto/xrpc-server'
|
|
7
|
+
import express from 'express'
|
|
8
|
+
|
|
9
|
+
// create xrpc server
|
|
10
|
+
const server = xrpc.createServer([{
|
|
11
|
+
lexicon: 1,
|
|
12
|
+
id: 'io.example.ping',
|
|
13
|
+
defs: {
|
|
14
|
+
main: {
|
|
15
|
+
type: 'query',
|
|
16
|
+
parameters: {
|
|
17
|
+
type: 'params',
|
|
18
|
+
properties: { message: { type: 'string' } },
|
|
19
|
+
},
|
|
20
|
+
output: {
|
|
21
|
+
encoding: 'application/json',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
function ping(ctx: {auth: xrpc.HandlerAuth | undefined, params: xrpc.Params, input: xrpc.HandlerInput | undefined, req: express.Request, res: express.Response}) {
|
|
29
|
+
return { encoding: 'application/json', body: {message: ctx.params.message }}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
server.method('io.example.ping', ping)
|
|
33
|
+
|
|
34
|
+
// mount in express
|
|
35
|
+
const app = express()
|
|
36
|
+
app.use(server.router)
|
|
37
|
+
app.listen(8080)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT
|
package/babel.config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../babel.config.js')
|
package/build.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const pkgJson = require('@npmcli/package-json')
|
|
2
|
+
const { nodeExternalsPlugin } = require('esbuild-node-externals')
|
|
3
|
+
|
|
4
|
+
const buildShallow =
|
|
5
|
+
process.argv.includes('--shallow') || process.env.ATP_BUILD_SHALLOW === 'true'
|
|
6
|
+
|
|
7
|
+
if (process.argv.includes('--update-main-to-dist')) {
|
|
8
|
+
return pkgJson
|
|
9
|
+
.load(__dirname)
|
|
10
|
+
.then((pkg) => pkg.update({ main: 'dist/index.js' }))
|
|
11
|
+
.then((pkg) => pkg.save())
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
require('esbuild').build({
|
|
15
|
+
logLevel: 'info',
|
|
16
|
+
entryPoints: ['src/index.ts'],
|
|
17
|
+
bundle: true,
|
|
18
|
+
sourcemap: true,
|
|
19
|
+
outdir: 'dist',
|
|
20
|
+
platform: 'node',
|
|
21
|
+
plugins: buildShallow ? [nodeExternalsPlugin()] : [],
|
|
22
|
+
})
|
package/dist/index.d.ts
ADDED