@atproto/lex-client 0.0.1 → 0.0.3
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 +28 -0
- package/dist/agent.d.ts +3 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js.map +1 -1
- package/dist/client.d.ts +62 -234
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/error.d.ts +12 -16
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +7 -5
- package/dist/error.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +12 -58
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js +10 -12
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/defs.defs.d.ts +3 -3
- package/dist/lexicons/com/atproto/repo/defs.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/defs.defs.js +1 -1
- package/dist/lexicons/com/atproto/repo/defs.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +8 -36
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +7 -4
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +4 -40
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js +5 -4
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +13 -41
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js +8 -11
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +12 -60
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js +10 -15
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +8 -12
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +3 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/xrpc.d.ts +2 -2
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js +1 -1
- package/dist/xrpc.js.map +1 -1
- package/package.json +20 -12
- package/src/agent.ts +3 -3
- package/src/client.ts +29 -27
- package/src/error.ts +13 -22
- package/src/lexicons/com/atproto/repo/createRecord.defs.ts +58 -0
- package/src/lexicons/com/atproto/repo/createRecord.ts +6 -0
- package/src/lexicons/com/atproto/repo/defs.defs.ts +28 -0
- package/src/lexicons/com/atproto/repo/defs.ts +6 -0
- package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +54 -0
- package/src/lexicons/com/atproto/repo/deleteRecord.ts +6 -0
- package/src/lexicons/com/atproto/repo/getRecord.defs.ts +42 -0
- package/src/lexicons/com/atproto/repo/getRecord.ts +6 -0
- package/src/lexicons/com/atproto/repo/listRecords.defs.ts +63 -0
- package/src/lexicons/com/atproto/repo/listRecords.ts +6 -0
- package/src/lexicons/com/atproto/repo/putRecord.defs.ts +59 -0
- package/src/lexicons/com/atproto/repo/putRecord.ts +6 -0
- package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +35 -0
- package/src/lexicons/com/atproto/repo/uploadBlob.ts +6 -0
- package/src/lexicons/com/atproto/repo.ts +11 -0
- package/src/lexicons/com/atproto.ts +5 -0
- package/src/lexicons/com.ts +5 -0
- package/src/types.ts +4 -4
- package/src/xrpc.ts +3 -3
- package/jest.config.js +0 -5
- package/scripts/lex-build.mjs +0 -40
- package/tests/client.test.ts +0 -370
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.tests.tsbuildinfo +0 -1
package/dist/xrpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrpc.js","sourceRoot":"","sources":["../src/xrpc.ts"],"names":[],"mappings":";;AAqCA,oBAWC;AAQD,wCAWC;AAED,8CASC;AASD,0CA8CC;AAED,gDAqBC;AAqBD,kDAuGC;AAED,0CAIC;AAUD,4CAsCC;AA7UD,gDAA0D;AAC1D,oDAU4B;AAE5B,yCAKmB;AACnB,+CAA8D;AAC9D,yCAAqE;AAgB9D,KAAK,UAAU,IAAI,CACxB,KAAY,EACZ,EAAgB,EAChB,UAA0B,EAAoB;IAE9C,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAA;IAChC,MAAM,MAAM,GAAG,IAAA,kBAAO,EAAC,EAAE,CAAC,CAAA;IAC1B,MAAM,GAAG,GAAG,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC3C,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACvD,OAAO,mBAAmB,CAAI,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AAC1D,CAAC;AAQD,SAAgB,cAAc,CAC5B,MAAS,EACT,OAAiC;IAEjC,MAAM,IAAI,GAAG,SAAS,MAAM,CAAC,IAAI,EAAE,CAAA;IAEnC,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM;QAChC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,UAAU,EAAE,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AAS,CAAA;YAC/B,MAAM,MAAM,CAAC,MAAM,EAAE,CAAA,CAAC,gDAAgD;QACxE,CAAC;QAED,MAAM,IAAI,WAAW,CAAC,iDAAiD,CAAC,CAAA;IAC1E,CAAC;IAED,IAAI,QAAQ,KAAK,kBAAkB,EAAE,CAAC;QACpC,4EAA4E;QAC5E,wEAAwE;QACxE,kCAAkC;QAElC,+BAA+B;QAC/B,OAAO,IAAA,mBAAQ,EAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAA;AACrD,CAAC","sourcesContent":["import { LexValue } from '@atproto/lex-data'\nimport { lexParse, lexStringify } from '@atproto/lex-json'\nimport {\n Did,\n InferParamsSchema,\n InferPayloadBody,\n Params,\n ParamsSchema,\n Procedure,\n Query,\n Restricted,\n Subscription,\n} from '@atproto/lex-schema'\nimport { Agent } from './agent.js'\nimport {\n KnownError,\n XrpcResponseError,\n XrpcServiceError,\n xrpcErrorBodySchema,\n} from './error.js'\nimport { XrpcResponse, XrpcResponseBody } from './response.js'\nimport { CallOptions, Namespace, Service, getMain } from './types.js'\n\nexport type XrpcOptions<M extends Procedure | Query = Procedure | Query> =\n CallOptions & XrpcRequestUrlOptions<M> & XrpcRequestInitOptions<M>\n\nexport async function xrpc<const M extends Query | Procedure>(\n agent: Agent,\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Namespace<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n): Promise<XrpcResponse<M>>\nexport async function xrpc<const M extends Query | Procedure>(\n agent: Agent,\n ns: Namespace<M>,\n options: XrpcOptions<M>,\n): Promise<XrpcResponse<M>>\nexport async function xrpc<const M extends Query | Procedure>(\n agent: Agent,\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n): Promise<XrpcResponse<M>> {\n options.signal?.throwIfAborted()\n const method = getMain(ns)\n const url = xrpcRequestUrl(method, options)\n const request = xrpcRequestInit(method, options)\n const response = await agent.fetchHandler(url, request)\n return xrpcResponseHandler<M>(response, method, options)\n}\n\nexport type XrpcRequestUrlOptions<M extends Query | Procedure | Subscription> =\n CallOptions &\n (undefined extends InferParamsSchema<M['parameters']>\n ? { params?: InferParamsSchema<M['parameters']> }\n : { params: InferParamsSchema<M['parameters']> })\n\nexport function xrpcRequestUrl<M extends Procedure | Query | Subscription>(\n method: M,\n options: XrpcRequestUrlOptions<M>,\n) {\n const path = `/xrpc/${method.nsid}`\n\n const queryString = options.params\n ? xrpcRequestParams(method.parameters, options.params, options)\n : undefined\n\n return queryString ? `${path}?${queryString}` : path\n}\n\nexport function xrpcRequestParams(\n schema: ParamsSchema | undefined,\n params: Params | undefined,\n options: CallOptions,\n): undefined | string {\n const urlSearchParams = schema?.toURLSearchParams(\n options.validateRequest ? schema.parse(params) : (params as any),\n )\n return urlSearchParams?.size ? urlSearchParams.toString() : undefined\n}\n\nexport type XrpcRequestInitOptions<T extends Query | Procedure> = CallOptions &\n (T extends Procedure\n ? never extends InferPayloadBody<T['input']>\n ? { body?: InferPayloadBody<T['input']> }\n : { body: InferPayloadBody<T['input']> }\n : { body?: never })\n\nexport function xrpcRequestInit<T extends Procedure | Query>(\n schema: T,\n options: XrpcRequestInitOptions<T>,\n): RequestInit & { duplex?: 'half' } {\n const headers = xrpcRequestHeaders(options)\n\n // Requests with body\n if ('input' in schema && schema.input?.encoding) {\n if (\n options.validateRequest &&\n schema.input == null &&\n options.body !== undefined\n ) {\n throw new TypeError(\n `XRPC method ${schema.nsid} does not accept a request body`,\n )\n }\n\n headers.set('content-type', schema.input.encoding)\n return {\n duplex: 'half',\n redirect: 'follow',\n referrerPolicy: 'strict-origin-when-cross-origin', // (default)\n mode: 'cors', // (default)\n signal: options.signal,\n method: 'POST',\n headers,\n body: xrpcRequestBody(\n schema.input?.encoding,\n options.validateRequest\n ? schema.input?.body.parse(options.body)\n : options.body,\n ),\n }\n }\n\n // Requests without body\n return {\n duplex: 'half',\n redirect: 'follow',\n referrerPolicy: 'strict-origin-when-cross-origin', // (default)\n mode: 'cors', // (default)\n signal: options.signal,\n method: schema instanceof Query ? 'GET' : 'POST',\n headers,\n }\n}\n\nexport function xrpcRequestHeaders(options: {\n headers?: HeadersInit\n service?: Service\n labelers?: Iterable<Did>\n}): Headers {\n const headers = new Headers(options.headers)\n\n if (options.service && !headers.has('atproto-proxy')) {\n headers.set('atproto-proxy', options.service)\n }\n\n if (options.labelers) {\n headers.set(\n 'atproto-accept-labelers',\n [...options.labelers, headers.get('atproto-accept-labelers')?.trim()]\n .filter(Boolean)\n .join(', '),\n )\n }\n\n return headers\n}\n\nfunction xrpcRequestBody(\n encoding: string | undefined,\n body: LexValue | undefined,\n): BodyInit | null {\n if (encoding === undefined) {\n return null\n }\n\n if (encoding === 'application/json') {\n if (body !== undefined) return lexStringify(body)\n } else if (encoding.startsWith('text/')) {\n if (typeof body === 'string') return body\n } else {\n if (ArrayBuffer.isView(body) || body instanceof ArrayBuffer) return body\n }\n\n throw new TypeError(`Invalid ${typeof body} body for ${encoding} encoding`)\n}\n\nexport async function xrpcResponseHandler<M extends Procedure | Query>(\n response: Response,\n schema: M,\n options?: { validateResponse?: boolean },\n): Promise<XrpcResponse<M>> {\n // @NOTE The body MUST either be read or canceled to avoid resource leaks.\n // Since nothing should cause an exception before \"readXrpcResponseBody\" is\n // called, we can safely not use a try/finally here.\n\n const encoding = extractEncoding(response.headers)\n\n const body = await readResponseBody(response, encoding).catch((cause) => {\n throw new XrpcServiceError(\n KnownError.InvalidResponse,\n response.status,\n response.headers,\n undefined,\n 'Failed to read XRPC response',\n { cause },\n )\n })\n\n // @NOTE redirect is set to 'follow', so we shouldn't get 3xx responses here\n if (response.status < 200 || response.status >= 300) {\n // All unsuccessful responses should follow a standard error response\n // schema. The Content-Type should be application/json, and the payload\n // should be a JSON object with the following fields:\n // - error (string, required): type name of the error (generic ASCII\n // constant, no whitespace)\n // - message (string, optional): description of the error, appropriate for\n // display to humans\n if (\n body != null &&\n encoding === 'application/json' &&\n xrpcErrorBodySchema.check(body)\n ) {\n throw new XrpcResponseError(\n response.status,\n response.headers,\n encoding,\n body,\n )\n }\n\n throw new XrpcServiceError(\n response.status >= 500\n ? KnownError.InternalServerError\n : KnownError.InvalidResponse,\n response.status,\n response.headers,\n body,\n )\n }\n\n // Check response encoding\n if (schema.output.encoding !== encoding) {\n throw new XrpcServiceError(\n KnownError.InvalidResponse,\n response.status,\n response.headers,\n body,\n `Expected response with content-type ${schema.output.encoding}, got ${encoding}`,\n )\n }\n\n if (schema.output.encoding == null) {\n if (body !== undefined) {\n throw new XrpcServiceError(\n KnownError.InvalidResponse,\n response.status,\n response.headers,\n body,\n `Expected empty response body`,\n )\n }\n\n return new XrpcResponse<M>(\n schema,\n response.status,\n response.headers,\n undefined as XrpcResponseBody<M>,\n )\n } else {\n // @NOTE this should already be enforced by readXrpcResponseBody\n if (body === undefined) {\n throw new XrpcServiceError(\n KnownError.InvalidResponse,\n response.status,\n response.headers,\n body,\n `Expected non-empty response body`,\n )\n }\n\n return new XrpcResponse<M>(\n schema,\n response.status,\n response.headers,\n schema.output.schema == null || options?.validateResponse === false\n ? (body as XrpcResponseBody<M>)\n : (schema.output.schema.parse(body) as XrpcResponseBody<M>),\n )\n }\n}\n\nexport function extractEncoding(headers: Headers): string | undefined {\n const contentType = headers.get('content-type')\n if (!contentType) return undefined\n return contentType.split(';')[0].trim()\n}\n\nexport async function readResponseBody(\n response: Response,\n encoding: string,\n): Promise<LexValue>\nexport async function readResponseBody(\n response: Response,\n encoding: string | undefined,\n): Promise<LexValue | undefined>\nexport async function readResponseBody(\n response: Response,\n encoding: string | undefined,\n): Promise<LexValue | undefined> {\n // When encoding is undefined or empty, we expect no body\n if (encoding == null) {\n if (response.body == null) return undefined\n\n // Let's make sure the body is empty (while avoiding reading it all).\n if (!('getReader' in response.body)) {\n // Some environments may not support body.getReader(), fall back to\n // reading the whole body.\n const buffer = await response.arrayBuffer()\n if (buffer.byteLength === 0) return undefined\n } else {\n const reader = response.body.getReader()\n const next = await reader.read()\n if (next.done) return undefined\n await reader.cancel() // Drain the rest of the (non-empty) body stream\n }\n\n throw new SyntaxError('Content-type is undefined but body is not empty')\n }\n\n if (encoding === 'application/json') {\n // @NOTE Using `lexParse(text)` (instead of `jsonToLex(json)`) here as using\n // a reviver function during JSON.parse should be faster than parsing to\n // JSON then converting to Lex (?)\n\n // @TODO verify statement above\n return lexParse(await response.text())\n }\n\n if (encoding.startsWith('text/')) {\n return response.text()\n }\n\n return new Uint8Array(await response.arrayBuffer())\n}\n"]}
|
|
1
|
+
{"version":3,"file":"xrpc.js","sourceRoot":"","sources":["../src/xrpc.ts"],"names":[],"mappings":";;AAqCA,oBAWC;AAQD,wCAWC;AAED,8CASC;AASD,0CA8CC;AAED,gDAqBC;AAqBD,kDAuGC;AAED,0CAIC;AAUD,4CAsCC;AA7UD,gDAA0D;AAC1D,oDAU4B;AAE5B,yCAKmB;AACnB,+CAA8D;AAC9D,yCAAqE;AAgB9D,KAAK,UAAU,IAAI,CACxB,KAAY,EACZ,EAAgB,EAChB,UAA0B,EAAoB;IAE9C,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAA;IAChC,MAAM,MAAM,GAAG,IAAA,kBAAO,EAAC,EAAE,CAAC,CAAA;IAC1B,MAAM,GAAG,GAAG,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC3C,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACvD,OAAO,mBAAmB,CAAI,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,C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;gBAAE,OAAO,SAAS,CAAA;QAC/C,CAAC;aAAM,CAAC;YACN,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAA;YACxC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;YAChC,IAAI,IAAI,CAAC,IAAI;gBAAE,OAAO,SAAS,CAAA;YAC/B,MAAM,MAAM,CAAC,MAAM,EAAE,CAAA,CAAC,gDAAgD;QACxE,CAAC;QAED,MAAM,IAAI,WAAW,CAAC,iDAAiD,CAAC,CAAA;IAC1E,CAAC;IAED,IAAI,QAAQ,KAAK,kBAAkB,EAAE,CAAC;QACpC,4EAA4E;QAC5E,wEAAwE;QACxE,kCAAkC;QAElC,+BAA+B;QAC/B,OAAO,IAAA,mBAAQ,EAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAA;AACrD,CAAC","sourcesContent":["import { LexValue } from '@atproto/lex-data'\nimport { lexParse, lexStringify } from '@atproto/lex-json'\nimport {\n DidString,\n InferParamsSchema,\n InferPayloadBody,\n Params,\n ParamsSchema,\n Procedure,\n Query,\n Restricted,\n Subscription,\n} from '@atproto/lex-schema'\nimport { Agent } from './agent.js'\nimport {\n KnownError,\n XrpcResponseError,\n XrpcServiceError,\n xrpcErrorBodySchema,\n} from './error.js'\nimport { XrpcResponse, XrpcResponseBody } from './response.js'\nimport { CallOptions, Namespace, Service, getMain } from './types.js'\n\nexport type XrpcOptions<M extends Procedure | Query = Procedure | Query> =\n CallOptions & XrpcRequestUrlOptions<M> & XrpcRequestInitOptions<M>\n\nexport async function xrpc<const M extends Query | Procedure>(\n agent: Agent,\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Namespace<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n): Promise<XrpcResponse<M>>\nexport async function xrpc<const M extends Query | Procedure>(\n agent: Agent,\n ns: Namespace<M>,\n options: XrpcOptions<M>,\n): Promise<XrpcResponse<M>>\nexport async function xrpc<const M extends Query | Procedure>(\n agent: Agent,\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n): Promise<XrpcResponse<M>> {\n options.signal?.throwIfAborted()\n const method = getMain(ns)\n const url = xrpcRequestUrl(method, options)\n const request = xrpcRequestInit(method, options)\n const response = await agent.fetchHandler(url, request)\n return xrpcResponseHandler<M>(response, method, options)\n}\n\nexport type XrpcRequestUrlOptions<M extends Query | Procedure | Subscription> =\n CallOptions &\n (undefined extends InferParamsSchema<M['parameters']>\n ? { params?: InferParamsSchema<M['parameters']> }\n : { params: InferParamsSchema<M['parameters']> })\n\nexport function xrpcRequestUrl<M extends Procedure | Query | Subscription>(\n method: M,\n options: XrpcRequestUrlOptions<M>,\n) {\n const path = `/xrpc/${method.nsid}`\n\n const queryString = options.params\n ? xrpcRequestParams(method.parameters, options.params, options)\n : undefined\n\n return queryString ? `${path}?${queryString}` : path\n}\n\nexport function xrpcRequestParams(\n schema: ParamsSchema | undefined,\n params: Params | undefined,\n options: CallOptions,\n): undefined | string {\n const urlSearchParams = schema?.toURLSearchParams(\n options.validateRequest ? schema.parse(params) : (params as any),\n )\n return urlSearchParams?.size ? urlSearchParams.toString() : undefined\n}\n\nexport type XrpcRequestInitOptions<T extends Query | Procedure> = CallOptions &\n (T extends Procedure\n ? never extends InferPayloadBody<T['input']>\n ? { body?: InferPayloadBody<T['input']> }\n : { body: InferPayloadBody<T['input']> }\n : { body?: never })\n\nexport function xrpcRequestInit<T extends Procedure | Query>(\n schema: T,\n options: XrpcRequestInitOptions<T>,\n): RequestInit & { duplex?: 'half' } {\n const headers = xrpcRequestHeaders(options)\n\n // Requests with body\n if ('input' in schema && schema.input?.encoding) {\n if (\n options.validateRequest &&\n schema.input == null &&\n options.body !== undefined\n ) {\n throw new TypeError(\n `XRPC method ${schema.nsid} does not accept a request body`,\n )\n }\n\n headers.set('content-type', schema.input.encoding)\n return {\n duplex: 'half',\n redirect: 'follow',\n referrerPolicy: 'strict-origin-when-cross-origin', // (default)\n mode: 'cors', // (default)\n signal: options.signal,\n method: 'POST',\n headers,\n body: xrpcRequestBody(\n schema.input?.encoding,\n options.validateRequest\n ? schema.input?.body.parse(options.body)\n : options.body,\n ),\n }\n }\n\n // Requests without body\n return {\n duplex: 'half',\n redirect: 'follow',\n referrerPolicy: 'strict-origin-when-cross-origin', // (default)\n mode: 'cors', // (default)\n signal: options.signal,\n method: schema instanceof Query ? 'GET' : 'POST',\n headers,\n }\n}\n\nexport function xrpcRequestHeaders(options: {\n headers?: HeadersInit\n service?: Service\n labelers?: Iterable<DidString>\n}): Headers {\n const headers = new Headers(options.headers)\n\n if (options.service && !headers.has('atproto-proxy')) {\n headers.set('atproto-proxy', options.service)\n }\n\n if (options.labelers) {\n headers.set(\n 'atproto-accept-labelers',\n [...options.labelers, headers.get('atproto-accept-labelers')?.trim()]\n .filter(Boolean)\n .join(', '),\n )\n }\n\n return headers\n}\n\nfunction xrpcRequestBody(\n encoding: string | undefined,\n body: LexValue | undefined,\n): BodyInit | null {\n if (encoding === undefined) {\n return null\n }\n\n if (encoding === 'application/json') {\n if (body !== undefined) return lexStringify(body)\n } else if (encoding.startsWith('text/')) {\n if (typeof body === 'string') return body\n } else {\n if (ArrayBuffer.isView(body) || body instanceof ArrayBuffer) return body\n }\n\n throw new TypeError(`Invalid ${typeof body} body for ${encoding} encoding`)\n}\n\nexport async function xrpcResponseHandler<M extends Procedure | Query>(\n response: Response,\n schema: M,\n options?: { validateResponse?: boolean },\n): Promise<XrpcResponse<M>> {\n // @NOTE The body MUST either be read or canceled to avoid resource leaks.\n // Since nothing should cause an exception before \"readXrpcResponseBody\" is\n // called, we can safely not use a try/finally here.\n\n const encoding = extractEncoding(response.headers)\n\n const body = await readResponseBody(response, encoding).catch((cause) => {\n throw new XrpcServiceError(\n KnownError.InvalidResponse,\n response.status,\n response.headers,\n undefined,\n 'Failed to read XRPC response',\n { cause },\n )\n })\n\n // @NOTE redirect is set to 'follow', so we shouldn't get 3xx responses here\n if (response.status < 200 || response.status >= 300) {\n // All unsuccessful responses should follow a standard error response\n // schema. The Content-Type should be application/json, and the payload\n // should be a JSON object with the following fields:\n // - error (string, required): type name of the error (generic ASCII\n // constant, no whitespace)\n // - message (string, optional): description of the error, appropriate for\n // display to humans\n if (\n body != null &&\n encoding === 'application/json' &&\n xrpcErrorBodySchema.matches(body)\n ) {\n throw new XrpcResponseError(\n response.status,\n response.headers,\n encoding,\n body,\n )\n }\n\n throw new XrpcServiceError(\n response.status >= 500\n ? KnownError.InternalServerError\n : KnownError.InvalidResponse,\n response.status,\n response.headers,\n body,\n )\n }\n\n // Check response encoding\n if (schema.output.encoding !== encoding) {\n throw new XrpcServiceError(\n KnownError.InvalidResponse,\n response.status,\n response.headers,\n body,\n `Expected response with content-type ${schema.output.encoding}, got ${encoding}`,\n )\n }\n\n if (schema.output.encoding == null) {\n if (body !== undefined) {\n throw new XrpcServiceError(\n KnownError.InvalidResponse,\n response.status,\n response.headers,\n body,\n `Expected empty response body`,\n )\n }\n\n return new XrpcResponse<M>(\n schema,\n response.status,\n response.headers,\n undefined as XrpcResponseBody<M>,\n )\n } else {\n // @NOTE this should already be enforced by readXrpcResponseBody\n if (body === undefined) {\n throw new XrpcServiceError(\n KnownError.InvalidResponse,\n response.status,\n response.headers,\n body,\n `Expected non-empty response body`,\n )\n }\n\n return new XrpcResponse<M>(\n schema,\n response.status,\n response.headers,\n schema.output.schema == null || options?.validateResponse === false\n ? (body as XrpcResponseBody<M>)\n : (schema.output.schema.parse(body) as XrpcResponseBody<M>),\n )\n }\n}\n\nexport function extractEncoding(headers: Headers): string | undefined {\n const contentType = headers.get('content-type')\n if (!contentType) return undefined\n return contentType.split(';')[0].trim()\n}\n\nexport async function readResponseBody(\n response: Response,\n encoding: string,\n): Promise<LexValue>\nexport async function readResponseBody(\n response: Response,\n encoding: string | undefined,\n): Promise<LexValue | undefined>\nexport async function readResponseBody(\n response: Response,\n encoding: string | undefined,\n): Promise<LexValue | undefined> {\n // When encoding is undefined or empty, we expect no body\n if (encoding == null) {\n if (response.body == null) return undefined\n\n // Let's make sure the body is empty (while avoiding reading it all).\n if (!('getReader' in response.body)) {\n // Some environments may not support body.getReader(), fall back to\n // reading the whole body.\n const buffer = await response.arrayBuffer()\n if (buffer.byteLength === 0) return undefined\n } else {\n const reader = response.body.getReader()\n const next = await reader.read()\n if (next.done) return undefined\n await reader.cancel() // Drain the rest of the (non-empty) body stream\n }\n\n throw new SyntaxError('Content-type is undefined but body is not empty')\n }\n\n if (encoding === 'application/json') {\n // @NOTE Using `lexParse(text)` (instead of `jsonToLex(json)`) here as using\n // a reviver function during JSON.parse should be faster than parsing to\n // JSON then converting to Lex (?)\n\n // @TODO verify statement above\n return lexParse(await response.text())\n }\n\n if (encoding.startsWith('text/')) {\n return response.text()\n }\n\n return new Uint8Array(await response.arrayBuffer())\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "HTTP client for interacting with Lexicon based APIs",
|
|
6
6
|
"keywords": [
|
|
@@ -15,17 +15,14 @@
|
|
|
15
15
|
"url": "https://github.com/bluesky-social/atproto",
|
|
16
16
|
"directory": "packages/lex/lex-client"
|
|
17
17
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"@atproto/lex-cbor": "0.0.1",
|
|
27
|
-
"@atproto/lex-builder": "0.0.1"
|
|
28
|
-
},
|
|
18
|
+
"files": [
|
|
19
|
+
"./src",
|
|
20
|
+
"./tsconfig.build.json",
|
|
21
|
+
"./tsconfig.tests.json",
|
|
22
|
+
"./tsconfig.json",
|
|
23
|
+
"./dist",
|
|
24
|
+
"./CHANGELOG.md"
|
|
25
|
+
],
|
|
29
26
|
"sideEffects": false,
|
|
30
27
|
"type": "commonjs",
|
|
31
28
|
"main": "./dist/index.js",
|
|
@@ -38,6 +35,17 @@
|
|
|
38
35
|
"types": "./dist/index.d.ts"
|
|
39
36
|
}
|
|
40
37
|
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"tslib": "^2.8.1",
|
|
40
|
+
"@atproto/lex-data": "0.0.2",
|
|
41
|
+
"@atproto/lex-json": "0.0.2",
|
|
42
|
+
"@atproto/lex-schema": "0.0.3"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"jest": "^28.1.2",
|
|
46
|
+
"@atproto/lex-cbor": "0.0.2",
|
|
47
|
+
"@atproto/lex-builder": "0.0.5"
|
|
48
|
+
},
|
|
41
49
|
"scripts": {
|
|
42
50
|
"prebuild": "node ./scripts/lex-build.mjs",
|
|
43
51
|
"build": "tsc --build tsconfig.build.json",
|
package/src/agent.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DidString } from '@atproto/lex-schema'
|
|
2
2
|
|
|
3
3
|
export interface Agent {
|
|
4
|
-
did?:
|
|
4
|
+
did?: DidString
|
|
5
5
|
|
|
6
6
|
fetchHandler: (
|
|
7
7
|
this: Agent,
|
|
@@ -19,7 +19,7 @@ export type AgentConfig = {
|
|
|
19
19
|
/**
|
|
20
20
|
* The identifier (DID) of the user represented by this agent.
|
|
21
21
|
*/
|
|
22
|
-
did?:
|
|
22
|
+
did?: DidString
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* The service URL to make requests to. This can be a string, URL, or a
|
package/src/client.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { LexMap, LexValue } from '@atproto/lex-data'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
AtIdentifierString,
|
|
4
|
+
DidString,
|
|
5
5
|
Infer,
|
|
6
6
|
InferProcedureInputBody,
|
|
7
7
|
InferProcedureOutputBody,
|
|
8
8
|
InferQueryOutputBody,
|
|
9
9
|
InferQueryParameters,
|
|
10
10
|
InferRecordKey,
|
|
11
|
-
|
|
11
|
+
LexiconRecordKey,
|
|
12
|
+
NsidString,
|
|
12
13
|
Params,
|
|
13
14
|
Procedure,
|
|
14
15
|
Query,
|
|
15
|
-
RecordKey,
|
|
16
16
|
RecordSchema,
|
|
17
17
|
Restricted,
|
|
18
|
-
|
|
18
|
+
Schema,
|
|
19
19
|
} from '@atproto/lex-schema'
|
|
20
20
|
import { Agent, AgentOptions, buildAgent } from './agent.js'
|
|
21
21
|
import {
|
|
@@ -30,7 +30,7 @@ import { CallOptions, Namespace, Service, getMain } from './types.js'
|
|
|
30
30
|
import { XrpcOptions, xrpc, xrpcRequestHeaders } from './xrpc.js'
|
|
31
31
|
|
|
32
32
|
export type ClientOptions = {
|
|
33
|
-
labelers?: Iterable<
|
|
33
|
+
labelers?: Iterable<DidString>
|
|
34
34
|
headers?: HeadersInit
|
|
35
35
|
service?: Service
|
|
36
36
|
}
|
|
@@ -46,30 +46,30 @@ export type InferActionOutput<A extends Action> =
|
|
|
46
46
|
A extends Action<any, infer O> ? O : never
|
|
47
47
|
|
|
48
48
|
export type CreateRecordOptions = CallOptions & {
|
|
49
|
-
repo?:
|
|
49
|
+
repo?: AtIdentifierString
|
|
50
50
|
swapCommit?: string
|
|
51
51
|
validate?: boolean
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
export type DeleteRecordOptions = CallOptions & {
|
|
55
|
-
repo?:
|
|
55
|
+
repo?: AtIdentifierString
|
|
56
56
|
swapCommit?: string
|
|
57
57
|
swapRecord?: string
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export type GetRecordOptions = CallOptions & {
|
|
61
|
-
repo?:
|
|
61
|
+
repo?: AtIdentifierString
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export type PutRecordOptions = CallOptions & {
|
|
65
|
-
repo?:
|
|
65
|
+
repo?: AtIdentifierString
|
|
66
66
|
swapCommit?: string
|
|
67
67
|
swapRecord?: string
|
|
68
68
|
validate?: boolean
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
export type ListRecordsOptions = CallOptions & {
|
|
72
|
-
repo?:
|
|
72
|
+
repo?: AtIdentifierString
|
|
73
73
|
limit?: number
|
|
74
74
|
cursor?: string
|
|
75
75
|
reverse?: boolean
|
|
@@ -77,7 +77,7 @@ export type ListRecordsOptions = CallOptions & {
|
|
|
77
77
|
|
|
78
78
|
export type RecordKeyOptions<
|
|
79
79
|
T extends RecordSchema,
|
|
80
|
-
AlsoOptionalWhenRecordKeyIs extends
|
|
80
|
+
AlsoOptionalWhenRecordKeyIs extends LexiconRecordKey = never,
|
|
81
81
|
> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs
|
|
82
82
|
? { rkey?: InferRecordKey<T> }
|
|
83
83
|
: { rkey: InferRecordKey<T> }
|
|
@@ -119,19 +119,19 @@ export type ListRecord<T extends RecordSchema> =
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
export class Client implements Agent {
|
|
122
|
-
static appLabelers: readonly
|
|
122
|
+
static appLabelers: readonly DidString[] = []
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* Configures the Client (or its sub classes) globally.
|
|
126
126
|
*/
|
|
127
|
-
static configure(opts: { appLabelers?: Iterable<
|
|
127
|
+
static configure(opts: { appLabelers?: Iterable<DidString> }) {
|
|
128
128
|
if (opts.appLabelers) this.appLabelers = [...opts.appLabelers]
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
public readonly agent: Agent
|
|
132
132
|
public readonly headers: Headers
|
|
133
133
|
public readonly service?: Service
|
|
134
|
-
public readonly labelers: Set<
|
|
134
|
+
public readonly labelers: Set<DidString>
|
|
135
135
|
|
|
136
136
|
constructor(agent: Agent | AgentOptions, options: ClientOptions = {}) {
|
|
137
137
|
this.agent =
|
|
@@ -143,25 +143,25 @@ export class Client implements Agent {
|
|
|
143
143
|
this.headers = new Headers(options.headers)
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
get did():
|
|
146
|
+
get did(): DidString | undefined {
|
|
147
147
|
return this.agent.did
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
get assertDid():
|
|
150
|
+
get assertDid(): DidString {
|
|
151
151
|
this.assertAuthenticated()
|
|
152
152
|
return this.did
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
public assertAuthenticated(): asserts this is { did:
|
|
155
|
+
public assertAuthenticated(): asserts this is { did: DidString } {
|
|
156
156
|
if (!this.did) throw new XrpcError(KnownError.AuthenticationRequired)
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
public setLabelers(labelers: Iterable<
|
|
159
|
+
public setLabelers(labelers: Iterable<DidString> = []) {
|
|
160
160
|
this.clearLabelers()
|
|
161
161
|
this.addLabelers(labelers)
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
public addLabelers(labelers: Iterable<
|
|
164
|
+
public addLabelers(labelers: Iterable<DidString>) {
|
|
165
165
|
for (const labeler of labelers) this.labelers.add(labeler)
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -226,7 +226,7 @@ export class Client implements Agent {
|
|
|
226
226
|
* @param rkey Leave `undefined` to have the server generate a TID.
|
|
227
227
|
*/
|
|
228
228
|
public async createRecord(
|
|
229
|
-
record: { $type:
|
|
229
|
+
record: { $type: NsidString } & LexMap,
|
|
230
230
|
rkey?: string,
|
|
231
231
|
options?: CreateRecordOptions,
|
|
232
232
|
) {
|
|
@@ -250,7 +250,7 @@ export class Client implements Agent {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
async deleteRecord(
|
|
253
|
-
collection:
|
|
253
|
+
collection: NsidString,
|
|
254
254
|
rkey: string,
|
|
255
255
|
options?: DeleteRecordOptions,
|
|
256
256
|
) {
|
|
@@ -273,7 +273,7 @@ export class Client implements Agent {
|
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
public async getRecord(
|
|
276
|
-
collection:
|
|
276
|
+
collection: NsidString,
|
|
277
277
|
rkey: string,
|
|
278
278
|
options?: GetRecordOptions,
|
|
279
279
|
) {
|
|
@@ -294,7 +294,7 @@ export class Client implements Agent {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
async putRecord(
|
|
297
|
-
record: { $type:
|
|
297
|
+
record: { $type: NsidString } & LexMap,
|
|
298
298
|
rkey: string,
|
|
299
299
|
options?: PutRecordOptions,
|
|
300
300
|
) {
|
|
@@ -318,7 +318,7 @@ export class Client implements Agent {
|
|
|
318
318
|
)
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
async listRecords(nsid:
|
|
321
|
+
async listRecords(nsid: NsidString, options?: ListRecordsOptions) {
|
|
322
322
|
return this.xrpc(com.atproto.repo.listRecords.main, {
|
|
323
323
|
...options,
|
|
324
324
|
params: {
|
|
@@ -348,7 +348,9 @@ export class Client implements Agent {
|
|
|
348
348
|
): Promise<InferQueryOutputBody<T>>
|
|
349
349
|
public async call<const T extends Query>(
|
|
350
350
|
ns: Namespace<T>,
|
|
351
|
-
params: InferQueryParameters<T
|
|
351
|
+
params: NonNullable<unknown> extends InferQueryParameters<T>
|
|
352
|
+
? InferQueryParameters<T> | undefined
|
|
353
|
+
: InferQueryParameters<T>,
|
|
352
354
|
options?: CallOptions,
|
|
353
355
|
): Promise<InferQueryOutputBody<T>>
|
|
354
356
|
public async call(
|
|
@@ -478,7 +480,7 @@ export class Client implements Agent {
|
|
|
478
480
|
const invalid: LexMap[] = []
|
|
479
481
|
|
|
480
482
|
for (const record of body.records) {
|
|
481
|
-
const parsed = schema
|
|
483
|
+
const parsed = (schema as Schema<Infer<T>>).safeParse(record.value)
|
|
482
484
|
if (parsed.success) {
|
|
483
485
|
records.push({ ...record, value: parsed.value })
|
|
484
486
|
} else {
|
package/src/error.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { LexValue } from '@atproto/lex-data'
|
|
2
|
-
import {
|
|
3
|
-
Infer,
|
|
4
|
-
ObjectSchema,
|
|
5
|
-
Procedure,
|
|
6
|
-
Query,
|
|
7
|
-
ResultFailure,
|
|
8
|
-
StringSchema,
|
|
9
|
-
Validator,
|
|
10
|
-
} from '@atproto/lex-schema'
|
|
2
|
+
import { l } from '@atproto/lex-schema'
|
|
11
3
|
|
|
12
4
|
export enum KnownError {
|
|
13
5
|
Unknown = 'Unknown',
|
|
@@ -27,24 +19,23 @@ export enum KnownError {
|
|
|
27
19
|
XRPCNotSupported = 'XRPCNotSupported',
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
export type XrpcFailure<N extends string, E> = ResultFailure<E> & {
|
|
22
|
+
export type XrpcFailure<N extends string, E> = l.ResultFailure<E> & {
|
|
31
23
|
name: N
|
|
32
24
|
}
|
|
33
25
|
|
|
34
|
-
export type XrpcErrorName =
|
|
35
|
-
export const xrpcErrorNameSchema =
|
|
26
|
+
export type XrpcErrorName = l.UnknownString | KnownError
|
|
27
|
+
export const xrpcErrorNameSchema = l.string({
|
|
36
28
|
minLength: 1,
|
|
37
|
-
knownValues: Object.keys(KnownError) as KnownError[],
|
|
38
29
|
})
|
|
39
30
|
|
|
40
31
|
export type XrpcErrorBody<N extends XrpcErrorName = XrpcErrorName> = {
|
|
41
32
|
error: N
|
|
42
33
|
message?: string
|
|
43
34
|
}
|
|
44
|
-
export const xrpcErrorBodySchema =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
35
|
+
export const xrpcErrorBodySchema = l.object({
|
|
36
|
+
error: xrpcErrorNameSchema,
|
|
37
|
+
message: l.optional(l.string()),
|
|
38
|
+
})
|
|
48
39
|
|
|
49
40
|
/**
|
|
50
41
|
* @implements {XrpcFailure<N, XrpcError<N>>} for convenience in result handling contexts.
|
|
@@ -68,10 +59,10 @@ export class XrpcError<N extends XrpcErrorName = XrpcErrorName>
|
|
|
68
59
|
super(message, options)
|
|
69
60
|
}
|
|
70
61
|
|
|
71
|
-
/** @see {@link ResultFailure.success} */
|
|
62
|
+
/** @see {@link l.ResultFailure.success} */
|
|
72
63
|
readonly success = false as const
|
|
73
64
|
|
|
74
|
-
/** @see {@link ResultFailure.error} */
|
|
65
|
+
/** @see {@link l.ResultFailure.error} */
|
|
75
66
|
get error(): this {
|
|
76
67
|
return this
|
|
77
68
|
}
|
|
@@ -118,7 +109,7 @@ export class XrpcResponseError<
|
|
|
118
109
|
}
|
|
119
110
|
}
|
|
120
111
|
|
|
121
|
-
export type XrpcRequestFailure<M extends Procedure | Query> =
|
|
112
|
+
export type XrpcRequestFailure<M extends l.Procedure | l.Query> =
|
|
122
113
|
// The server responded with a declared error.
|
|
123
114
|
| (M extends { errors: readonly (infer N extends string)[] }
|
|
124
115
|
? XrpcResponseError<N> // implements XrpcRequestFailure<N, XrpcResponseError<N>>
|
|
@@ -129,7 +120,7 @@ export type XrpcRequestFailure<M extends Procedure | Query> =
|
|
|
129
120
|
// An unexpected error occurred (e.g., network error, invalid response, etc.)
|
|
130
121
|
| XrpcFailure<'UnexpectedError', unknown>
|
|
131
122
|
|
|
132
|
-
export function asXrpcRequestFailureFor<M extends Procedure | Query>(
|
|
123
|
+
export function asXrpcRequestFailureFor<M extends l.Procedure | l.Query>(
|
|
133
124
|
schema: M,
|
|
134
125
|
) {
|
|
135
126
|
// Performance: Using .bind instead of arrow function to avoid creating a closure
|
|
@@ -138,7 +129,7 @@ export function asXrpcRequestFailureFor<M extends Procedure | Query>(
|
|
|
138
129
|
) => XrpcRequestFailure<M>
|
|
139
130
|
}
|
|
140
131
|
|
|
141
|
-
function asXrpcRequestFailure<M extends Procedure | Query>(
|
|
132
|
+
function asXrpcRequestFailure<M extends l.Procedure | l.Query>(
|
|
142
133
|
this: M,
|
|
143
134
|
error: unknown,
|
|
144
135
|
): XrpcRequestFailure<M> {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { l } from '@atproto/lex-schema'
|
|
6
|
+
import * as RepoDefs from './defs.defs.js'
|
|
7
|
+
|
|
8
|
+
const $nsid = 'com.atproto.repo.createRecord'
|
|
9
|
+
|
|
10
|
+
export { $nsid }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a single new repository record. Requires auth, implemented by PDS.
|
|
14
|
+
*/
|
|
15
|
+
const main =
|
|
16
|
+
/*#__PURE__*/
|
|
17
|
+
l.procedure(
|
|
18
|
+
$nsid,
|
|
19
|
+
/*#__PURE__*/ l.params({}),
|
|
20
|
+
/*#__PURE__*/ l.payload(
|
|
21
|
+
'application/json',
|
|
22
|
+
/*#__PURE__*/ l.object({
|
|
23
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
24
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
25
|
+
rkey: /*#__PURE__*/ l.optional(
|
|
26
|
+
/*#__PURE__*/ l.string({ format: 'record-key', maxLength: 512 }),
|
|
27
|
+
),
|
|
28
|
+
validate: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
|
|
29
|
+
record: /*#__PURE__*/ l.unknownObject(),
|
|
30
|
+
swapCommit: /*#__PURE__*/ l.optional(
|
|
31
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
32
|
+
),
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
/*#__PURE__*/ l.payload(
|
|
36
|
+
'application/json',
|
|
37
|
+
/*#__PURE__*/ l.object({
|
|
38
|
+
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
39
|
+
cid: /*#__PURE__*/ l.string({ format: 'cid' }),
|
|
40
|
+
commit: /*#__PURE__*/ l.optional(
|
|
41
|
+
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
42
|
+
(() => RepoDefs.commitMeta) as any,
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
validationStatus: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
['InvalidSwap'],
|
|
49
|
+
)
|
|
50
|
+
export { main }
|
|
51
|
+
|
|
52
|
+
export const $params = /*#__PURE__*/ main.parameters,
|
|
53
|
+
$input = /*#__PURE__*/ main.input,
|
|
54
|
+
$output = /*#__PURE__*/ main.output
|
|
55
|
+
|
|
56
|
+
export type Params = l.InferProcedureParameters<typeof main>
|
|
57
|
+
export type Input = l.InferProcedureInputBody<typeof main>
|
|
58
|
+
export type Output = l.InferProcedureOutputBody<typeof main>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { l } from '@atproto/lex-schema'
|
|
6
|
+
|
|
7
|
+
const $nsid = 'com.atproto.repo.defs'
|
|
8
|
+
|
|
9
|
+
export { $nsid }
|
|
10
|
+
|
|
11
|
+
type CommitMeta = {
|
|
12
|
+
$type?: 'com.atproto.repo.defs#commitMeta'
|
|
13
|
+
cid: l.CidString
|
|
14
|
+
rev: l.TidString
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { CommitMeta }
|
|
18
|
+
|
|
19
|
+
const commitMeta = /*#__PURE__*/ l.typedObject<CommitMeta>(
|
|
20
|
+
$nsid,
|
|
21
|
+
'commitMeta',
|
|
22
|
+
/*#__PURE__*/ l.object({
|
|
23
|
+
cid: /*#__PURE__*/ l.string({ format: 'cid' }),
|
|
24
|
+
rev: /*#__PURE__*/ l.string({ format: 'tid' }),
|
|
25
|
+
}),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
export { commitMeta }
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { l } from '@atproto/lex-schema'
|
|
6
|
+
import * as RepoDefs from './defs.defs.js'
|
|
7
|
+
|
|
8
|
+
const $nsid = 'com.atproto.repo.deleteRecord'
|
|
9
|
+
|
|
10
|
+
export { $nsid }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Delete a repository record, or ensure it doesn't exist. Requires auth, implemented by PDS.
|
|
14
|
+
*/
|
|
15
|
+
const main =
|
|
16
|
+
/*#__PURE__*/
|
|
17
|
+
l.procedure(
|
|
18
|
+
$nsid,
|
|
19
|
+
/*#__PURE__*/ l.params({}),
|
|
20
|
+
/*#__PURE__*/ l.payload(
|
|
21
|
+
'application/json',
|
|
22
|
+
/*#__PURE__*/ l.object({
|
|
23
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
24
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
25
|
+
rkey: /*#__PURE__*/ l.string({ format: 'record-key' }),
|
|
26
|
+
swapRecord: /*#__PURE__*/ l.optional(
|
|
27
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
28
|
+
),
|
|
29
|
+
swapCommit: /*#__PURE__*/ l.optional(
|
|
30
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
31
|
+
),
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
/*#__PURE__*/ l.payload(
|
|
35
|
+
'application/json',
|
|
36
|
+
/*#__PURE__*/ l.object({
|
|
37
|
+
commit: /*#__PURE__*/ l.optional(
|
|
38
|
+
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
39
|
+
(() => RepoDefs.commitMeta) as any,
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
44
|
+
['InvalidSwap'],
|
|
45
|
+
)
|
|
46
|
+
export { main }
|
|
47
|
+
|
|
48
|
+
export const $params = /*#__PURE__*/ main.parameters,
|
|
49
|
+
$input = /*#__PURE__*/ main.input,
|
|
50
|
+
$output = /*#__PURE__*/ main.output
|
|
51
|
+
|
|
52
|
+
export type Params = l.InferProcedureParameters<typeof main>
|
|
53
|
+
export type Input = l.InferProcedureInputBody<typeof main>
|
|
54
|
+
export type Output = l.InferProcedureOutputBody<typeof main>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { l } from '@atproto/lex-schema'
|
|
6
|
+
|
|
7
|
+
const $nsid = 'com.atproto.repo.getRecord'
|
|
8
|
+
|
|
9
|
+
export { $nsid }
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get a single record from a repository. Does not require auth.
|
|
13
|
+
*/
|
|
14
|
+
const main =
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
l.query(
|
|
17
|
+
$nsid,
|
|
18
|
+
/*#__PURE__*/ l.params({
|
|
19
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
20
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
21
|
+
rkey: /*#__PURE__*/ l.string({ format: 'record-key' }),
|
|
22
|
+
cid: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
23
|
+
}),
|
|
24
|
+
/*#__PURE__*/ l.payload(
|
|
25
|
+
'application/json',
|
|
26
|
+
/*#__PURE__*/ l.object({
|
|
27
|
+
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
28
|
+
cid: /*#__PURE__*/ l.optional(
|
|
29
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
30
|
+
),
|
|
31
|
+
value: /*#__PURE__*/ l.unknownObject(),
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
['RecordNotFound'],
|
|
35
|
+
)
|
|
36
|
+
export { main }
|
|
37
|
+
|
|
38
|
+
export const $params = main.parameters,
|
|
39
|
+
$output = main.output
|
|
40
|
+
|
|
41
|
+
export type Params = l.InferQueryParameters<typeof main>
|
|
42
|
+
export type Output = l.InferQueryOutputBody<typeof main>
|