@atproto/xrpc 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 ADDED
@@ -0,0 +1,66 @@
1
+ # XRPC API
2
+
3
+ ## Usage
4
+
5
+ ```typescript
6
+ import xrpc from '@atproto/xrpc'
7
+
8
+ xrpc.addLexicon({
9
+ lexicon: 1,
10
+ id: 'io.example.ping',
11
+ defs: {
12
+ main: {
13
+ type: 'query',
14
+ description: 'Ping the server',
15
+ parameters: {
16
+ type: 'params',
17
+ properties: {message: { type: 'string' }}
18
+ },
19
+ output: {
20
+ encoding: 'application/json',
21
+ schema: {
22
+ type: 'object',
23
+ required: ['message'],
24
+ properties: {message: { type: 'string' }},
25
+ },
26
+ }
27
+ },
28
+ },
29
+ })
30
+
31
+ const res1 = await xrpc.call('https://example.com', 'io.example.ping', {message: 'hello world'})
32
+ res1.encoding // => 'application/json'
33
+ res1.body // => {message: 'hello world'}
34
+ const res2 = await xrpc.service('https://example.com').call('io.example.ping', {message: 'hello world'})
35
+ res2.encoding // => 'application/json'
36
+ res2.body // => {message: 'hello world'}
37
+
38
+ xrpc.addLexicon({
39
+ lexicon: 1,
40
+ id: 'io.example.writeJsonFile',
41
+ defs: {
42
+ main: {
43
+ type: 'procedure',
44
+ description: 'Write a JSON file',
45
+ parameters: {
46
+ type: 'params',
47
+ properties: {fileName: { type: 'string' }},
48
+ },
49
+ input: {
50
+ encoding: 'application/json'
51
+ },
52
+ },
53
+ },
54
+ })
55
+
56
+ const res3 = await xrpc
57
+ .service('https://example.com')
58
+ .call('io.example.writeJsonFile',
59
+ {fileName: 'foo.json'}, // query parameters
60
+ {hello: 'world', thisIs: 'the file to write'} // input body
61
+ )
62
+ ```
63
+
64
+ ## License
65
+
66
+ MIT
@@ -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
+ })