diff --git a/packages/xrpc-server/README.md b/packages/xrpc-server/README.md index 7c53339bc12..1228b425d2d 100644 --- a/packages/xrpc-server/README.md +++ b/packages/xrpc-server/README.md @@ -8,11 +8,11 @@ TypeScript library for implementing [atproto](https://atproto.com) HTTP API serv ## Usage ```typescript +import { LexiconDoc } from '@atproto/lexicon' import * as xrpc from '@atproto/xrpc-server' import express from 'express' -// create xrpc server -const server = xrpc.createServer([ +const lexicons: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.ping', @@ -29,7 +29,10 @@ const server = xrpc.createServer([ }, }, }, -]) +] + +// create xrpc server +const server = xrpc.createServer(lexicons) function ping(ctx: { auth: xrpc.HandlerAuth | undefined diff --git a/packages/xrpc-server/tests/auth.test.ts b/packages/xrpc-server/tests/auth.test.ts index 53f3a6c6d24..bbd202d1024 100644 --- a/packages/xrpc-server/tests/auth.test.ts +++ b/packages/xrpc-server/tests/auth.test.ts @@ -6,6 +6,7 @@ import KeyEncoder from 'key-encoder' import * as ui8 from 'uint8arrays' import { MINUTE } from '@atproto/common' import { Secp256k1Keypair } from '@atproto/crypto' +import { LexiconDoc } from '@atproto/lexicon' import xrpc, { ServiceClient, XRPCError } from '@atproto/xrpc' import * as xrpcServer from '../src' import { @@ -15,7 +16,7 @@ import { basicAuthHeaders, } from './_util' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.authTest', diff --git a/packages/xrpc-server/tests/bodies.test.ts b/packages/xrpc-server/tests/bodies.test.ts index 725146907e2..072299cdcd7 100644 --- a/packages/xrpc-server/tests/bodies.test.ts +++ b/packages/xrpc-server/tests/bodies.test.ts @@ -2,6 +2,7 @@ import * as http from 'http' import { Readable } from 'stream' import { gzipSync } from 'zlib' import getPort from 'get-port' +import { LexiconDoc } from '@atproto/lexicon' import xrpc, { ServiceClient } from '@atproto/xrpc' import { bytesToStream, cidForCbor } from '@atproto/common' import { randomBytes } from '@atproto/crypto' @@ -9,7 +10,7 @@ import { createServer, closeServer } from './_util' import * as xrpcServer from '../src' import logger from '../src/logger' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.validationTest', diff --git a/packages/xrpc-server/tests/errors.test.ts b/packages/xrpc-server/tests/errors.test.ts index 4703c5231f0..c7781e71907 100644 --- a/packages/xrpc-server/tests/errors.test.ts +++ b/packages/xrpc-server/tests/errors.test.ts @@ -1,5 +1,6 @@ import * as http from 'http' import getPort from 'get-port' +import { LexiconDoc } from '@atproto/lexicon' import { createServer, closeServer } from './_util' import * as xrpcServer from '../src' import xrpc, { @@ -9,7 +10,7 @@ import xrpc, { XRPCInvalidResponseError, } from '@atproto/xrpc' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.error', diff --git a/packages/xrpc-server/tests/ipld.test.ts b/packages/xrpc-server/tests/ipld.test.ts index 2c84e8ed5dc..4ba1fec867e 100644 --- a/packages/xrpc-server/tests/ipld.test.ts +++ b/packages/xrpc-server/tests/ipld.test.ts @@ -1,11 +1,12 @@ import * as http from 'http' +import { LexiconDoc } from '@atproto/lexicon' import xrpc, { ServiceClient } from '@atproto/xrpc' import { CID } from 'multiformats/cid' import getPort from 'get-port' import { createServer, closeServer } from './_util' import * as xrpcServer from '../src' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.ipld', diff --git a/packages/xrpc-server/tests/parameters.test.ts b/packages/xrpc-server/tests/parameters.test.ts index a6575f121da..6ab2066ae8f 100644 --- a/packages/xrpc-server/tests/parameters.test.ts +++ b/packages/xrpc-server/tests/parameters.test.ts @@ -1,10 +1,11 @@ import * as http from 'http' import getPort from 'get-port' +import { LexiconDoc } from '@atproto/lexicon' import xrpc, { ServiceClient } from '@atproto/xrpc' import { createServer, closeServer } from './_util' import * as xrpcServer from '../src' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.paramTest', diff --git a/packages/xrpc-server/tests/procedures.test.ts b/packages/xrpc-server/tests/procedures.test.ts index 6d4cef19d02..df38fc855f9 100644 --- a/packages/xrpc-server/tests/procedures.test.ts +++ b/packages/xrpc-server/tests/procedures.test.ts @@ -1,11 +1,12 @@ import * as http from 'http' import { Readable } from 'stream' +import { LexiconDoc } from '@atproto/lexicon' import xrpc, { ServiceClient } from '@atproto/xrpc' import getPort from 'get-port' import { createServer, closeServer } from './_util' import * as xrpcServer from '../src' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.pingOne', diff --git a/packages/xrpc-server/tests/queries.test.ts b/packages/xrpc-server/tests/queries.test.ts index a80e813ec4e..fd45d812e00 100644 --- a/packages/xrpc-server/tests/queries.test.ts +++ b/packages/xrpc-server/tests/queries.test.ts @@ -1,10 +1,11 @@ import * as http from 'http' import getPort from 'get-port' +import { LexiconDoc } from '@atproto/lexicon' import xrpc, { ServiceClient } from '@atproto/xrpc' import { createServer, closeServer } from './_util' import * as xrpcServer from '../src' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.pingOne', diff --git a/packages/xrpc-server/tests/rate-limiter.test.ts b/packages/xrpc-server/tests/rate-limiter.test.ts index 09a235a38b9..20610c95688 100644 --- a/packages/xrpc-server/tests/rate-limiter.test.ts +++ b/packages/xrpc-server/tests/rate-limiter.test.ts @@ -1,12 +1,13 @@ import * as http from 'http' import getPort from 'get-port' +import { LexiconDoc } from '@atproto/lexicon' import xrpc, { ServiceClient } from '@atproto/xrpc' import { createServer, closeServer } from './_util' import * as xrpcServer from '../src' import { RateLimiter } from '../src' import { MINUTE } from '@atproto/common' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.routeLimit', diff --git a/packages/xrpc-server/tests/responses.test.ts b/packages/xrpc-server/tests/responses.test.ts index 0eaccba0633..b61467dca22 100644 --- a/packages/xrpc-server/tests/responses.test.ts +++ b/packages/xrpc-server/tests/responses.test.ts @@ -1,11 +1,12 @@ import * as http from 'http' import getPort from 'get-port' +import { LexiconDoc } from '@atproto/lexicon' import xrpc, { ServiceClient } from '@atproto/xrpc' import { byteIterableToStream } from '@atproto/common' import { createServer, closeServer } from './_util' import * as xrpcServer from '../src' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.readableStream', diff --git a/packages/xrpc-server/tests/subscriptions.test.ts b/packages/xrpc-server/tests/subscriptions.test.ts index 13b0301ca87..e23cef5e3d4 100644 --- a/packages/xrpc-server/tests/subscriptions.test.ts +++ b/packages/xrpc-server/tests/subscriptions.test.ts @@ -2,6 +2,7 @@ import * as http from 'http' import { WebSocket, WebSocketServer, createWebSocketStream } from 'ws' import getPort from 'get-port' import { wait } from '@atproto/common' +import { LexiconDoc } from '@atproto/lexicon' import { byFrame, MessageFrame, ErrorFrame, Frame, Subscription } from '../src' import { createServer, @@ -11,7 +12,7 @@ import { } from './_util' import * as xrpcServer from '../src' -const LEXICONS = [ +const LEXICONS: LexiconDoc[] = [ { lexicon: 1, id: 'io.example.streamOne', diff --git a/packages/xrpc/README.md b/packages/xrpc/README.md index 31b66e7f32c..17c48c93735 100644 --- a/packages/xrpc/README.md +++ b/packages/xrpc/README.md @@ -8,9 +8,10 @@ TypeScript client library for talking to [atproto](https://atproto.com) services ## Usage ```typescript +import { LexiconDoc } from '@atproto/lexicon' import xrpc from '@atproto/xrpc' -xrpc.addLexicon({ +const pingLexicon: LexiconDoc = { lexicon: 1, id: 'io.example.ping', defs: { @@ -31,7 +32,8 @@ xrpc.addLexicon({ }, }, }, -}) +} +xrpc.addLexicon(pingLexicon) const res1 = await xrpc.call('https://example.com', 'io.example.ping', { message: 'hello world', @@ -44,7 +46,7 @@ const res2 = await xrpc res2.encoding // => 'application/json' res2.body // => {message: 'hello world'} -xrpc.addLexicon({ +const writeJsonLexicon: LexiconDoc = { lexicon: 1, id: 'io.example.writeJsonFile', defs: { @@ -60,7 +62,8 @@ xrpc.addLexicon({ }, }, }, -}) +} +xrpc.addLexicon(writeJsonLexicon) const res3 = await xrpc.service('https://example.com').call( 'io.example.writeJsonFile',