@atproto/lex-client 0.0.4 → 0.0.5

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 (105) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/agent.d.ts +9 -8
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js.map +1 -1
  5. package/dist/client.d.ts +32 -96
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +31 -31
  8. package/dist/client.js.map +1 -1
  9. package/dist/index.d.ts +0 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +0 -2
  12. package/dist/index.js.map +1 -1
  13. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +7 -7
  14. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
  15. package/dist/lexicons/com/atproto/repo/createRecord.defs.js +3 -5
  16. package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
  17. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +7 -7
  18. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
  19. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +3 -5
  20. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
  21. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +5 -6
  22. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
  23. package/dist/lexicons/com/atproto/repo/getRecord.defs.js +3 -5
  24. package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
  25. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +5 -6
  26. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
  27. package/dist/lexicons/com/atproto/repo/listRecords.defs.js +3 -5
  28. package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
  29. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +7 -7
  30. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
  31. package/dist/lexicons/com/atproto/repo/putRecord.defs.js +3 -5
  32. package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
  33. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +7 -7
  34. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
  35. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +3 -5
  36. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
  37. package/dist/lexicons/com/atproto/sync/getBlob.d.ts +3 -0
  38. package/dist/lexicons/com/atproto/sync/getBlob.d.ts.map +1 -0
  39. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts +25 -0
  40. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts.map +1 -0
  41. package/dist/lexicons/com/atproto/sync/getBlob.defs.js +27 -0
  42. package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -0
  43. package/dist/lexicons/com/atproto/sync/getBlob.js +10 -0
  44. package/dist/lexicons/com/atproto/sync/getBlob.js.map +1 -0
  45. package/dist/lexicons/com/atproto/sync.d.ts +2 -0
  46. package/dist/lexicons/com/atproto/sync.d.ts.map +1 -0
  47. package/dist/lexicons/com/atproto/sync.js +9 -0
  48. package/dist/lexicons/com/atproto/sync.js.map +1 -0
  49. package/dist/lexicons/com/atproto.d.ts +1 -0
  50. package/dist/lexicons/com/atproto.d.ts.map +1 -1
  51. package/dist/lexicons/com/atproto.js +2 -1
  52. package/dist/lexicons/com/atproto.js.map +1 -1
  53. package/dist/lexicons.d.ts +2 -0
  54. package/dist/lexicons.d.ts.map +1 -0
  55. package/dist/lexicons.js +6 -0
  56. package/dist/lexicons.js.map +1 -0
  57. package/dist/types.d.ts +18 -0
  58. package/dist/types.d.ts.map +1 -1
  59. package/dist/types.js.map +1 -1
  60. package/dist/util.d.ts +14 -0
  61. package/dist/util.d.ts.map +1 -0
  62. package/dist/util.js +65 -0
  63. package/dist/util.js.map +1 -0
  64. package/dist/xrpc-error.d.ts +87 -0
  65. package/dist/xrpc-error.d.ts.map +1 -0
  66. package/dist/xrpc-error.js +127 -0
  67. package/dist/xrpc-error.js.map +1 -0
  68. package/dist/xrpc-response.d.ts +35 -0
  69. package/dist/xrpc-response.d.ts.map +1 -0
  70. package/dist/xrpc-response.js +140 -0
  71. package/dist/xrpc-response.js.map +1 -0
  72. package/dist/xrpc.d.ts +29 -32
  73. package/dist/xrpc.d.ts.map +1 -1
  74. package/dist/xrpc.js +119 -125
  75. package/dist/xrpc.js.map +1 -1
  76. package/package.json +6 -6
  77. package/src/agent.ts +12 -12
  78. package/src/client.ts +92 -77
  79. package/src/index.ts +0 -2
  80. package/src/lexicons/com/atproto/repo/createRecord.defs.ts +9 -8
  81. package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +9 -8
  82. package/src/lexicons/com/atproto/repo/getRecord.defs.ts +7 -7
  83. package/src/lexicons/com/atproto/repo/listRecords.defs.ts +7 -6
  84. package/src/lexicons/com/atproto/repo/putRecord.defs.ts +9 -8
  85. package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +9 -8
  86. package/src/lexicons/com/atproto/sync/getBlob.defs.ts +37 -0
  87. package/src/lexicons/com/atproto/sync/getBlob.ts +6 -0
  88. package/src/lexicons/com/atproto/sync.ts +5 -0
  89. package/src/lexicons/com/atproto.ts +1 -0
  90. package/src/lexicons.ts +1 -0
  91. package/src/types.ts +27 -0
  92. package/src/util.ts +84 -0
  93. package/src/xrpc-error.ts +195 -0
  94. package/src/xrpc-response.ts +213 -0
  95. package/src/xrpc.ts +209 -220
  96. package/dist/error.d.ts +0 -66
  97. package/dist/error.d.ts.map +0 -1
  98. package/dist/error.js +0 -100
  99. package/dist/error.js.map +0 -1
  100. package/dist/response.d.ts +0 -21
  101. package/dist/response.d.ts.map +0 -1
  102. package/dist/response.js +0 -31
  103. package/dist/response.js.map +0 -1
  104. package/src/error.ts +0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AAkC;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"]}
1
+ {"version":3,"file":"xrpc.js","sourceRoot":"","sources":["../src/xrpc.ts"],"names":[],"mappings":";;AA2FA,oBAUC;AAaD,4BAMC;;AAxHD,gDAAwE;AACxE,gDAAgD;AAahD,yCAA4E;AAC5E,uCAMkB;AAClB,mDAIwB;AACxB,yDAAiD;AAEjD,0DAA+B;AAC/B,6DAAkC;AAiClC;;;;;GAKG;AACH,SAAS,aAAa,CACpB,GAAY;IAEZ,IAAI,GAAG,YAAY,iCAAiB;QAAE,OAAO,GAAG,CAAA;IAChD,IAAI,GAAG,YAAY,wCAAwB;QAAE,OAAO,GAAG,CAAA;IACvD,OAAO,mCAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACtC,CAAC;AAgBM,KAAK,UAAU,IAAI,CACxB,KAAY,EACZ,EAAgB,EAChB,UAA0B,EAAoB;IAE9C,IAAI,CAAC;QACH,OAAO,MAAM,WAAW,CAAI,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;IACjD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,aAAa,CAAI,GAAG,CAAC,CAAA;IAC7B,CAAC;AACH,CAAC;AAaM,KAAK,UAAU,QAAQ,CAC5B,KAAY,EACZ,EAAgB,EAChB,UAA0B,EAAoB;IAE9C,OAAO,WAAW,CAAI,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAA,aAAgB,CAAA,CAAC,CAAA;AACnE,CAAC;AAED,KAAK,UAAU,WAAW,CACxB,KAAY,EACZ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E,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,SAAS,CACjB,yCAAyC,YAAY,UAAU,MAAM,CAAC,QAAQ,YAAY,CAC3F,CAAA;QACH,CAAC;QACD,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,WAAW;IAEX,IAAI,MAAM,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;QAC9B,OAAO,0BAA0B,CAAA;IACnC,CAAC;IAED,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YAClC,CAAC,CAAC,2BAA2B;YAC7B,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,iBAAiB,CAAA;IACzC,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,OAAO,MAAM,CAAC,QAAQ,CAAA;IACxB,CAAC;IAED,MAAM,IAAI,SAAS,CACjB,yFAAyF,MAAM,CAAC,QAAQ,GAAG,CAC5G,CAAA;AACH,CAAC","sourcesContent":["import { LexValue, isLexScalar, isPlainObject } from '@atproto/lex-data'\nimport { lexStringify } from '@atproto/lex-json'\nimport {\n InferMethodInput,\n InferMethodParams,\n Params,\n ParamsSchema,\n Payload as LexPayload,\n Procedure,\n Query,\n Restricted,\n Subscription,\n} from '@atproto/lex-schema'\nimport { Agent } from './agent.js'\nimport { BinaryBodyInit, CallOptions, Namespace, getMain } from './types.js'\nimport {\n Payload,\n buildAtprotoHeaders,\n isAsyncIterable,\n isBlobLike,\n toReadableStream,\n} from './util.js'\nimport {\n XrpcInvalidResponseError,\n XrpcResponseError,\n XrpcUnexpectedError,\n} from './xrpc-error.js'\nimport { XrpcResponse } from './xrpc-response.js'\n\nexport * from './xrpc-error.js'\nexport * from './xrpc-response.js'\n\n// If all params are optional, allow omitting the params object\ntype XrpcParamsOptions<P extends Params> =\n NonNullable<unknown> extends P ? { params?: P } : { params: P }\n\ntype XrpcRequestPayload<M extends Procedure | Query> = InferMethodInput<\n M,\n BinaryBodyInit\n>\n\ntype XrpcInputOptions<In> = In extends { body: infer B; encoding: infer E }\n ? // encoding will be inferred from the schema at runtime if not provided\n { body: B; encoding?: E }\n : { body?: undefined; encoding?: undefined }\n\nexport type XrpcOptions<M extends Procedure | Query = Procedure | Query> =\n CallOptions &\n XrpcInputOptions<XrpcRequestPayload<M>> &\n XrpcParamsOptions<InferMethodParams<M>>\n\nexport type XrpcFailure<M extends Procedure | Query> =\n // The server returned a valid XRPC error response\n | XrpcResponseError<M>\n // The response was not a valid XRPC response, or it does not match the schema\n | XrpcInvalidResponseError\n // Something went wrong (network error, etc.)\n | XrpcUnexpectedError\n\nexport type XrpcResult<M extends Procedure | Query> =\n | XrpcResponse<M>\n | XrpcFailure<M>\n\n/**\n * Utility method to type cast the error thrown by {@link xrpc} to an\n * {@link XrpcFailure} matching the provided method. Only use this function\n * inside a catch block right after calling {@link xrpc}, and use the same\n * method type parameter as used in the {@link xrpc} call.\n */\nfunction asXrpcFailure<M extends Procedure | Query>(\n err: unknown,\n): XrpcFailure<M> {\n if (err instanceof XrpcResponseError) return err\n if (err instanceof XrpcInvalidResponseError) return err\n return XrpcUnexpectedError.from(err)\n}\n\n/**\n * @throws XrpcFailure<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 try {\n return await xrpcRequest<M>(agent, ns, options)\n } catch (err) {\n throw asXrpcFailure<M>(err)\n }\n}\n\nexport async function xrpcSafe<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<XrpcResult<M>>\nexport async function xrpcSafe<const M extends Query | Procedure>(\n agent: Agent,\n ns: Namespace<M>,\n options: XrpcOptions<M>,\n): Promise<XrpcResult<M>>\nexport async function xrpcSafe<const M extends Query | Procedure>(\n agent: Agent,\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n): Promise<XrpcResult<M>> {\n return xrpcRequest<M>(agent, ns, options).catch(asXrpcFailure<M>)\n}\n\nasync function xrpcRequest<const M extends Query | Procedure>(\n agent: Agent,\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n): Promise<XrpcResponse<M>> {\n const method = getMain(ns)\n options.signal?.throwIfAborted()\n const url = xrpcRequestUrl(method, options)\n const request = xrpcRequestInit(method, options)\n const response = await agent.fetchHandler(url, request)\n return XrpcResponse.fromFetchResponse<M>(method, response, options)\n}\n\nfunction xrpcRequestUrl<M extends Procedure | Query | Subscription>(\n method: M,\n options: CallOptions & { params?: Params },\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\nfunction 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\nfunction xrpcRequestInit<T extends Procedure | Query>(\n schema: T,\n options: CallOptions & {\n body?: LexValue | BinaryBodyInit\n encoding?: string\n },\n): RequestInit & { duplex?: 'half' } {\n const headers = buildAtprotoHeaders(options)\n\n // Tell the server what type of response we're expecting\n if (schema.output.encoding) {\n headers.set('accept', schema.output.encoding)\n }\n\n // Caller should not set content-type header\n if (headers.has('content-type')) {\n const contentType = headers.get('content-type')\n throw new TypeError(`Unexpected content-type header (${contentType})`)\n }\n\n // Requests with body\n if ('input' in schema) {\n const encodingHint = options.encoding\n const input = xrpcProcedureInput(schema, options, encodingHint)\n\n if (input) {\n headers.set('content-type', input.encoding)\n } else if (encodingHint != null) {\n throw new TypeError(`Unexpected encoding hint (${encodingHint})`)\n }\n\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: input?.body,\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: 'GET',\n headers,\n }\n}\n\nfunction xrpcProcedureInput(\n method: Procedure,\n options: CallOptions & { body?: LexValue | BinaryBodyInit },\n encodingHint?: string,\n): null | Payload<BodyInit> {\n const { input } = method\n const { body } = options\n\n if (options.validateRequest) {\n input.schema?.check(body)\n }\n\n // Special handling for endpoints expecting application/json input\n if (input.encoding === 'application/json') {\n // @NOTE **NOT** using isLexValue here to avoid deep checks in order to\n // distinguish between LexValue and BinaryBodyInit.\n if (!isLexScalar(body) && !isPlainObject(body) && !Array.isArray(body)) {\n throw new TypeError(`Expected LexValue body, got ${typeof body}`)\n }\n\n return buildPayload(input, lexStringify(body), encodingHint)\n }\n\n // Other encodings will be sent unaltered (ie. as binary data)\n switch (typeof body) {\n case 'undefined':\n case 'string':\n return buildPayload(input, body, encodingHint)\n case 'object': {\n if (body === null) break\n if (\n ArrayBuffer.isView(body) ||\n body instanceof ArrayBuffer ||\n body instanceof ReadableStream\n ) {\n return buildPayload(input, body, encodingHint)\n } else if (isAsyncIterable(body)) {\n return buildPayload(input, toReadableStream(body), encodingHint)\n } else if (isBlobLike(body)) {\n return buildPayload(input, body, encodingHint || body.type)\n }\n }\n }\n\n throw new TypeError(\n `Invalid ${typeof body} body for ${input.encoding} encoding`,\n )\n}\n\nfunction buildPayload(\n schema: LexPayload,\n body: undefined | BodyInit,\n encodingHint?: string,\n): null | Payload<BodyInit> {\n if (schema.encoding === undefined) {\n if (body !== undefined) {\n throw new TypeError(\n `Cannot send a ${typeof body} body with undefined encoding`,\n )\n }\n\n return null\n }\n\n if (body === undefined) {\n // This error would be returned by the server, but we can catch it earlier\n // to avoid un-necessary requests. Note that a content-length of 0 does not\n // necessary mean that the body is \"empty\" (e.g. an empty txt file).\n throw new TypeError(`A request body is expected but none was provided`)\n }\n\n const encoding = buildEncoding(schema, encodingHint)\n return { encoding, body }\n}\n\nfunction buildEncoding(schema: LexPayload, encodingHint?: string): string {\n // Should never happen (required for type safety)\n if (!schema.encoding) {\n throw new TypeError('Unexpected payload')\n }\n\n if (encodingHint?.length) {\n if (!schema.matchesEncoding(encodingHint)) {\n throw new TypeError(\n `Cannot send a body with content-type \"${encodingHint}\" for \"${schema.encoding}\" encoding`,\n )\n }\n return encodingHint\n }\n\n // Fallback\n\n if (schema.encoding === '*/*') {\n return 'application/octet-stream'\n }\n\n if (schema.encoding.startsWith('text/')) {\n return schema.encoding.includes('*')\n ? 'text/plain; charset=utf-8'\n : `${schema.encoding}; charset=utf-8`\n }\n\n if (!schema.encoding.includes('*')) {\n return schema.encoding\n }\n\n throw new TypeError(\n `Unable to determine payload encoding. Please provide a 'content-type' header matching ${schema.encoding}.`,\n )\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex-client",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "description": "HTTP client for interacting with Lexicon based APIs",
6
6
  "keywords": [
@@ -37,14 +37,14 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "tslib": "^2.8.1",
40
- "@atproto/lex-data": "0.0.3",
41
- "@atproto/lex-json": "0.0.3",
42
- "@atproto/lex-schema": "0.0.4"
40
+ "@atproto/lex-data": "0.0.4",
41
+ "@atproto/lex-json": "0.0.4",
42
+ "@atproto/lex-schema": "0.0.5"
43
43
  },
44
44
  "devDependencies": {
45
45
  "jest": "^28.1.2",
46
- "@atproto/lex-cbor": "0.0.3",
47
- "@atproto/lex-builder": "0.0.6"
46
+ "@atproto/lex-cbor": "0.0.4",
47
+ "@atproto/lex-builder": "0.0.7"
48
48
  },
49
49
  "scripts": {
50
50
  "prebuild": "node ./scripts/lex-build.mjs",
package/src/agent.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import { DidString } from '@atproto/lex-schema'
2
2
 
3
- export interface Agent {
4
- did?: DidString
3
+ export type FetchHandler = (
4
+ /**
5
+ * The URL (pathname + query parameters) to make the request to, without the
6
+ * origin. The origin (protocol, hostname, and port) must be added by this
7
+ * {@link FetchHandler}, typically based on authentication or other factors.
8
+ */
9
+ path: string,
10
+ init: RequestInit,
11
+ ) => Promise<Response>
5
12
 
6
- fetchHandler: (
7
- this: Agent,
8
- /**
9
- * The URL (pathname + query parameters) to make the request to, without the
10
- * origin. The origin (protocol, hostname, and port) must be added by this
11
- * {@link FetchHandler}, typically based on authentication or other factors.
12
- */
13
- path: string,
14
- init: RequestInit,
15
- ) => Promise<Response>
13
+ export interface Agent {
14
+ readonly did?: DidString
15
+ fetchHandler: FetchHandler
16
16
  }
17
17
 
18
18
  export type AgentConfig = {
package/src/client.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { LexMap, LexValue } from '@atproto/lex-data'
2
2
  import {
3
3
  AtIdentifierString,
4
+ CidString,
4
5
  DidString,
5
6
  Infer,
6
- InferProcedureInputBody,
7
- InferProcedureOutputBody,
8
- InferQueryOutputBody,
9
- InferQueryParameters,
7
+ InferMethodInputBody,
8
+ InferMethodOutputBody,
9
+ InferMethodParams,
10
10
  InferRecordKey,
11
11
  LexiconRecordKey,
12
12
  NsidString,
@@ -18,16 +18,24 @@ import {
18
18
  Schema,
19
19
  } from '@atproto/lex-schema'
20
20
  import { Agent, AgentOptions, buildAgent } from './agent.js'
21
+ import { com } from './lexicons.js'
21
22
  import {
22
- KnownError,
23
- XrpcError,
24
- XrpcRequestFailure,
25
- asXrpcRequestFailureFor,
26
- } from './error.js'
27
- import * as com from './lexicons/com.js'
28
- import { XrpcResponse, XrpcResponseBody } from './response.js'
29
- import { CallOptions, Namespace, Service, getMain } from './types.js'
30
- import { XrpcOptions, xrpc, xrpcRequestHeaders } from './xrpc.js'
23
+ BinaryBodyInit,
24
+ CallOptions,
25
+ Namespace,
26
+ Service,
27
+ getMain,
28
+ } from './types.js'
29
+ import { buildAtprotoHeaders } from './util.js'
30
+ import { XrpcError } from './xrpc-error.js'
31
+ import {
32
+ XrpcFailure,
33
+ XrpcOptions,
34
+ XrpcResponse,
35
+ XrpcResponseBody,
36
+ xrpc,
37
+ xrpcSafe,
38
+ } from './xrpc.js'
31
39
 
32
40
  export type ClientOptions = {
33
41
  labelers?: Iterable<DidString>
@@ -84,29 +92,35 @@ export type RecordKeyOptions<
84
92
 
85
93
  export type CreateOptions<T extends RecordSchema> = CreateRecordOptions &
86
94
  RecordKeyOptions<T, 'tid'>
87
- export type CreateOutput = XrpcResponseBody<
88
- typeof com.atproto.repo.createRecord.main
95
+ export type CreateOutput = InferMethodOutputBody<
96
+ typeof com.atproto.repo.createRecord.main,
97
+ Uint8Array
89
98
  >
90
99
 
91
100
  export type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions &
92
101
  RecordKeyOptions<T>
93
- export type DeleteOutput = XrpcResponseBody<
94
- typeof com.atproto.repo.deleteRecord.main
102
+ export type DeleteOutput = InferMethodOutputBody<
103
+ typeof com.atproto.repo.deleteRecord.main,
104
+ Uint8Array
95
105
  >
96
106
  export type GetOptions<T extends RecordSchema> = GetRecordOptions &
97
107
  RecordKeyOptions<T>
98
108
  export type GetOutput<T extends RecordSchema> = Omit<
99
- XrpcResponseBody<typeof com.atproto.repo.getRecord.main>,
109
+ InferMethodOutputBody<typeof com.atproto.repo.getRecord.main, Uint8Array>,
100
110
  'value'
101
111
  > & { value: Infer<T> }
102
112
 
103
113
  export type PutOptions<T extends RecordSchema> = PutRecordOptions &
104
114
  RecordKeyOptions<T>
105
- export type PutOutput = XrpcResponseBody<typeof com.atproto.repo.putRecord.main>
115
+ export type PutOutput = InferMethodOutputBody<
116
+ typeof com.atproto.repo.putRecord.main,
117
+ Uint8Array
118
+ >
106
119
 
107
120
  export type ListOptions = ListRecordsOptions
108
- export type ListOutput<T extends RecordSchema> = XrpcResponseBody<
109
- typeof com.atproto.repo.listRecords.main
121
+ export type ListOutput<T extends RecordSchema> = InferMethodOutputBody<
122
+ typeof com.atproto.repo.listRecords.main,
123
+ Uint8Array
110
124
  > & {
111
125
  records: ListRecord<T>[]
112
126
  // @NOTE Because the schema uses "type": "unknown" instead of an open union,
@@ -153,7 +167,7 @@ export class Client implements Agent {
153
167
  }
154
168
 
155
169
  public assertAuthenticated(): asserts this is { did: DidString } {
156
- if (!this.did) throw new XrpcError(KnownError.AuthenticationRequired)
170
+ if (!this.did) throw new XrpcError('AuthenticationRequired')
157
171
  }
158
172
 
159
173
  public setLabelers(labelers: Iterable<DidString> = []) {
@@ -170,7 +184,7 @@ export class Client implements Agent {
170
184
  }
171
185
 
172
186
  public fetchHandler(path: string, init: RequestInit): Promise<Response> {
173
- const headers = xrpcRequestHeaders({
187
+ const headers = buildAtprotoHeaders({
174
188
  headers: init.headers,
175
189
  service: this.service,
176
190
  labelers: [
@@ -186,9 +200,13 @@ export class Client implements Agent {
186
200
  if (!headers.has(key)) headers.set(key, value)
187
201
  }
188
202
 
203
+ // @NOTE The agent here could be another Client instance.
189
204
  return this.agent.fetchHandler(path, { ...init, headers })
190
205
  }
191
206
 
207
+ /**
208
+ * @throws {XrpcFailure<M>} when the request fails or the response is an error
209
+ */
192
210
  async xrpc<const M extends Query | Procedure>(
193
211
  ns: NonNullable<unknown> extends XrpcOptions<M>
194
212
  ? Namespace<M>
@@ -209,17 +227,16 @@ export class Client implements Agent {
209
227
  ns: NonNullable<unknown> extends XrpcOptions<M>
210
228
  ? Namespace<M>
211
229
  : Restricted<'This XRPC method requires an "options" argument'>,
212
- ): Promise<XrpcResponse<M> | XrpcRequestFailure<M>>
230
+ ): Promise<XrpcResponse<M> | XrpcFailure<M>>
213
231
  async xrpcSafe<const M extends Query | Procedure>(
214
232
  ns: Namespace<M>,
215
233
  options: XrpcOptions<M>,
216
- ): Promise<XrpcResponse<M> | XrpcRequestFailure<M>>
234
+ ): Promise<XrpcResponse<M> | XrpcFailure<M>>
217
235
  async xrpcSafe<const M extends Query | Procedure>(
218
236
  ns: Namespace<M>,
219
237
  options: XrpcOptions<M> = {} as XrpcOptions<M>,
220
- ): Promise<unknown> {
221
- const schema = getMain(ns)
222
- return this.xrpc(schema, options).catch(asXrpcRequestFailureFor(schema))
238
+ ): Promise<XrpcResponse<M> | XrpcFailure<M>> {
239
+ return xrpcSafe(this, ns, options)
223
240
  }
224
241
 
225
242
  /**
@@ -243,12 +260,6 @@ export class Client implements Agent {
243
260
  })
244
261
  }
245
262
 
246
- async createRecordsSafe(...args: Parameters<Client['createRecord']>) {
247
- return this.createRecord(...args).catch(
248
- asXrpcRequestFailureFor(com.atproto.repo.createRecord.main),
249
- )
250
- }
251
-
252
263
  async deleteRecord(
253
264
  collection: NsidString,
254
265
  rkey: string,
@@ -266,12 +277,6 @@ export class Client implements Agent {
266
277
  })
267
278
  }
268
279
 
269
- async deleteRecordsSafe(...args: Parameters<Client['deleteRecord']>) {
270
- return this.deleteRecord(...args).catch(
271
- asXrpcRequestFailureFor(com.atproto.repo.deleteRecord.main),
272
- )
273
- }
274
-
275
280
  public async getRecord(
276
281
  collection: NsidString,
277
282
  rkey: string,
@@ -287,12 +292,6 @@ export class Client implements Agent {
287
292
  })
288
293
  }
289
294
 
290
- async getRecordsSafe(...args: Parameters<Client['getRecord']>) {
291
- return this.getRecord(...args).catch(
292
- asXrpcRequestFailureFor(com.atproto.repo.getRecord.main),
293
- )
294
- }
295
-
296
295
  async putRecord(
297
296
  record: { $type: NsidString } & LexMap,
298
297
  rkey: string,
@@ -312,12 +311,6 @@ export class Client implements Agent {
312
311
  })
313
312
  }
314
313
 
315
- async putRecordsSafe(...args: Parameters<Client['putRecord']>) {
316
- return this.putRecord(...args).catch(
317
- asXrpcRequestFailureFor(com.atproto.repo.putRecord.main),
318
- )
319
- }
320
-
321
314
  async listRecords(nsid: NsidString, options?: ListRecordsOptions) {
322
315
  return this.xrpc(com.atproto.repo.listRecords.main, {
323
316
  ...options,
@@ -331,28 +324,52 @@ export class Client implements Agent {
331
324
  })
332
325
  }
333
326
 
334
- public async call<const T extends Action>(
335
- ns: Namespace<T>,
336
- input: InferActionInput<T>,
337
- options?: CallOptions,
338
- ): Promise<InferActionOutput<T>>
339
- public async call<const T extends Procedure>(
340
- ns: Namespace<T>,
341
- body: InferProcedureInputBody<T>,
342
- options?: CallOptions,
343
- ): Promise<InferProcedureOutputBody<T>>
327
+ async uploadBlob(
328
+ body: BinaryBodyInit,
329
+ options?: CallOptions & { encoding?: `${string}/${string}` },
330
+ ) {
331
+ return this.xrpc(com.atproto.repo.uploadBlob.main, {
332
+ ...options,
333
+ body,
334
+ })
335
+ }
336
+
337
+ async getBlob(did: DidString, cid: CidString, options?: CallOptions) {
338
+ return this.xrpc(com.atproto.sync.getBlob.main, {
339
+ ...options,
340
+ params: { did, cid },
341
+ })
342
+ }
343
+
344
344
  public async call<const T extends Query>(
345
- ns: NonNullable<unknown> extends InferQueryParameters<T>
345
+ ns: NonNullable<unknown> extends InferMethodParams<T>
346
346
  ? Namespace<T>
347
347
  : Restricted<'This query type requires a "params" argument'>,
348
- ): Promise<InferQueryOutputBody<T>>
349
- public async call<const T extends Query>(
348
+ ): Promise<XrpcResponseBody<T>>
349
+ public async call<const T extends Action>(
350
+ ns: void extends InferActionInput<T>
351
+ ? Namespace<T>
352
+ : Restricted<'This action type requires an "input" argument'>,
353
+ ): Promise<InferActionOutput<T>>
354
+ public async call<const T extends Action | Procedure | Query>(
350
355
  ns: Namespace<T>,
351
- params: NonNullable<unknown> extends InferQueryParameters<T>
352
- ? InferQueryParameters<T> | undefined
353
- : InferQueryParameters<T>,
356
+ arg: T extends Action
357
+ ? InferActionInput<T>
358
+ : T extends Procedure
359
+ ? InferMethodInputBody<T, Uint8Array>
360
+ : T extends Query
361
+ ? InferMethodParams<T>
362
+ : never,
354
363
  options?: CallOptions,
355
- ): Promise<InferQueryOutputBody<T>>
364
+ ): Promise<
365
+ T extends Action
366
+ ? InferActionOutput<T>
367
+ : T extends Procedure
368
+ ? XrpcResponseBody<T>
369
+ : T extends Query
370
+ ? XrpcResponseBody<T>
371
+ : never
372
+ >
356
373
  public async call(
357
374
  ns: Namespace<Action> | Namespace<Procedure> | Namespace<Query>,
358
375
  arg?: LexValue | Params,
@@ -365,12 +382,10 @@ export class Client implements Agent {
365
382
  }
366
383
 
367
384
  if (method instanceof Procedure) {
368
- const body = arg as LexValue | undefined
369
- const result = await this.xrpc(method, { ...options, body })
385
+ const result = await this.xrpc(method, { ...options, body: arg as any })
370
386
  return result.body
371
387
  } else if (method instanceof Query) {
372
- const params = arg as Params | undefined
373
- const result = await this.xrpc(method, { ...options, params })
388
+ const result = await this.xrpc(method, { ...options, params: arg as any })
374
389
  return result.body
375
390
  } else {
376
391
  throw new TypeError('Invalid lexicon')
@@ -394,9 +409,8 @@ export class Client implements Agent {
394
409
  options: CreateOptions<T> = {} as CreateOptions<T>,
395
410
  ): Promise<CreateOutput> {
396
411
  const schema: T = getMain(ns)
397
- const record = options.validate
398
- ? schema.parse(schema.build(input))
399
- : schema.build(input)
412
+ const record = schema.build(input)
413
+ if (options.validateRequest) schema.assert(record)
400
414
  const rkey = options.rkey ?? getDefaultRecordKey(schema)
401
415
  if (rkey !== undefined) schema.keySchema.assert(rkey)
402
416
  const response = await this.createRecord(record, rkey, options)
@@ -462,8 +476,9 @@ export class Client implements Agent {
462
476
  input: Omit<Infer<T>, '$type'>,
463
477
  options: PutOptions<T> = {} as PutOptions<T>,
464
478
  ): Promise<PutOutput> {
465
- const schema = getMain(ns)
479
+ const schema: T = getMain(ns)
466
480
  const record = schema.build(input)
481
+ if (options.validateRequest) schema.assert(record)
467
482
  const rkey = options.rkey ?? getLiteralRecordKey(schema)
468
483
  const response = await this.putRecord(record, rkey, options)
469
484
  return response.body
package/src/index.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  export * from './agent.js'
2
2
  export * from './client.js'
3
- export * from './error.js'
4
- export * from './response.js'
5
3
  export * from './types.js'
6
4
  export * from './xrpc.js'
@@ -9,9 +9,7 @@ const $nsid = 'com.atproto.repo.createRecord'
9
9
 
10
10
  export { $nsid }
11
11
 
12
- /**
13
- * Create a single new repository record. Requires auth, implemented by PDS.
14
- */
12
+ /** Create a single new repository record. Requires auth, implemented by PDS. */
15
13
  const main =
16
14
  /*#__PURE__*/
17
15
  l.procedure(
@@ -49,10 +47,13 @@ const main =
49
47
  )
50
48
  export { main }
51
49
 
52
- export const $params = /*#__PURE__*/ main.parameters,
50
+ export type Params = l.InferMethodParams<typeof main>
51
+ export type Input = l.InferMethodInput<typeof main>
52
+ export type InputBody = l.InferMethodInputBody<typeof main>
53
+ export type Output = l.InferMethodOutput<typeof main>
54
+ export type OutputBody = l.InferMethodOutputBody<typeof main>
55
+
56
+ export const $lxm = /*#__PURE__*/ main.nsid,
57
+ $params = /*#__PURE__*/ main.parameters,
53
58
  $input = /*#__PURE__*/ main.input,
54
59
  $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>
@@ -9,9 +9,7 @@ const $nsid = 'com.atproto.repo.deleteRecord'
9
9
 
10
10
  export { $nsid }
11
11
 
12
- /**
13
- * Delete a repository record, or ensure it doesn't exist. Requires auth, implemented by PDS.
14
- */
12
+ /** Delete a repository record, or ensure it doesn't exist. Requires auth, implemented by PDS. */
15
13
  const main =
16
14
  /*#__PURE__*/
17
15
  l.procedure(
@@ -45,10 +43,13 @@ const main =
45
43
  )
46
44
  export { main }
47
45
 
48
- export const $params = /*#__PURE__*/ main.parameters,
46
+ export type Params = l.InferMethodParams<typeof main>
47
+ export type Input = l.InferMethodInput<typeof main>
48
+ export type InputBody = l.InferMethodInputBody<typeof main>
49
+ export type Output = l.InferMethodOutput<typeof main>
50
+ export type OutputBody = l.InferMethodOutputBody<typeof main>
51
+
52
+ export const $lxm = /*#__PURE__*/ main.nsid,
53
+ $params = /*#__PURE__*/ main.parameters,
49
54
  $input = /*#__PURE__*/ main.input,
50
55
  $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>
@@ -8,9 +8,7 @@ const $nsid = 'com.atproto.repo.getRecord'
8
8
 
9
9
  export { $nsid }
10
10
 
11
- /**
12
- * Get a single record from a repository. Does not require auth.
13
- */
11
+ /** Get a single record from a repository. Does not require auth. */
14
12
  const main =
15
13
  /*#__PURE__*/
16
14
  l.query(
@@ -35,8 +33,10 @@ const main =
35
33
  )
36
34
  export { main }
37
35
 
38
- export const $params = main.parameters,
39
- $output = main.output
36
+ export type Params = l.InferMethodParams<typeof main>
37
+ export type Output = l.InferMethodOutput<typeof main>
38
+ export type OutputBody = l.InferMethodOutputBody<typeof main>
40
39
 
41
- export type Params = l.InferQueryParameters<typeof main>
42
- export type Output = l.InferQueryOutputBody<typeof main>
40
+ export const $lxm = /*#__PURE__*/ main.nsid,
41
+ $params = main.parameters,
42
+ $output = main.output
@@ -8,9 +8,7 @@ const $nsid = 'com.atproto.repo.listRecords'
8
8
 
9
9
  export { $nsid }
10
10
 
11
- /**
12
- * List a range of records in a repository, matching a specific collection. Does not require auth.
13
- */
11
+ /** List a range of records in a repository, matching a specific collection. Does not require auth. */
14
12
  const main =
15
13
  /*#__PURE__*/
16
14
  l.query(
@@ -36,11 +34,14 @@ const main =
36
34
  )
37
35
  export { main }
38
36
 
39
- export const $params = main.parameters,
37
+ export type Params = l.InferMethodParams<typeof main>
38
+ export type Output = l.InferMethodOutput<typeof main>
39
+ export type OutputBody = l.InferMethodOutputBody<typeof main>
40
+
41
+ export const $lxm = /*#__PURE__*/ main.nsid,
42
+ $params = main.parameters,
40
43
  $output = main.output
41
44
 
42
- export type Params = l.InferQueryParameters<typeof main>
43
- export type Output = l.InferQueryOutputBody<typeof main>
44
45
  type Def$0 = {
45
46
  $type?: 'com.atproto.repo.listRecords#record'
46
47
  uri: l.AtUriString
@@ -9,9 +9,7 @@ const $nsid = 'com.atproto.repo.putRecord'
9
9
 
10
10
  export { $nsid }
11
11
 
12
- /**
13
- * Write a repository record, creating or updating it as needed. Requires auth, implemented by PDS.
14
- */
12
+ /** Write a repository record, creating or updating it as needed. Requires auth, implemented by PDS. */
15
13
  const main =
16
14
  /*#__PURE__*/
17
15
  l.procedure(
@@ -50,10 +48,13 @@ const main =
50
48
  )
51
49
  export { main }
52
50
 
53
- export const $params = /*#__PURE__*/ main.parameters,
51
+ export type Params = l.InferMethodParams<typeof main>
52
+ export type Input = l.InferMethodInput<typeof main>
53
+ export type InputBody = l.InferMethodInputBody<typeof main>
54
+ export type Output = l.InferMethodOutput<typeof main>
55
+ export type OutputBody = l.InferMethodOutputBody<typeof main>
56
+
57
+ export const $lxm = /*#__PURE__*/ main.nsid,
58
+ $params = /*#__PURE__*/ main.parameters,
54
59
  $input = /*#__PURE__*/ main.input,
55
60
  $output = /*#__PURE__*/ main.output
56
-
57
- export type Params = l.InferProcedureParameters<typeof main>
58
- export type Input = l.InferProcedureInputBody<typeof main>
59
- export type Output = l.InferProcedureOutputBody<typeof main>
@@ -8,9 +8,7 @@ const $nsid = 'com.atproto.repo.uploadBlob'
8
8
 
9
9
  export { $nsid }
10
10
 
11
- /**
12
- * Upload a new blob, to be referenced from a repository record. The blob will be deleted if it is not referenced within a time window (eg, minutes). Blob restrictions (mimetype, size, etc) are enforced when the reference is created. Requires auth, implemented by PDS.
13
- */
11
+ /** Upload a new blob, to be referenced from a repository record. The blob will be deleted if it is not referenced within a time window (eg, minutes). Blob restrictions (mimetype, size, etc) are enforced when the reference is created. Requires auth, implemented by PDS. */
14
12
  const main =
15
13
  /*#__PURE__*/
16
14
  l.procedure(
@@ -26,10 +24,13 @@ const main =
26
24
  )
27
25
  export { main }
28
26
 
29
- export const $params = /*#__PURE__*/ main.parameters,
27
+ export type Params = l.InferMethodParams<typeof main>
28
+ export type Input = l.InferMethodInput<typeof main>
29
+ export type InputBody = l.InferMethodInputBody<typeof main>
30
+ export type Output = l.InferMethodOutput<typeof main>
31
+ export type OutputBody = l.InferMethodOutputBody<typeof main>
32
+
33
+ export const $lxm = /*#__PURE__*/ main.nsid,
34
+ $params = /*#__PURE__*/ main.parameters,
30
35
  $input = /*#__PURE__*/ main.input,
31
36
  $output = /*#__PURE__*/ main.output
32
-
33
- export type Params = l.InferProcedureParameters<typeof main>
34
- export type Input = l.InferProcedureInputBody<typeof main>
35
- export type Output = l.InferProcedureOutputBody<typeof main>