@atproto/lex-client 0.3.4 → 0.3.6

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atproto/lex-client
2
2
 
3
+ ## 0.3.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`ed0b7d3`](https://github.com/bluesky-social/atproto/commit/ed0b7d38811bb24952a3f1da988b02e39934d222), [`ed0b7d3`](https://github.com/bluesky-social/atproto/commit/ed0b7d38811bb24952a3f1da988b02e39934d222)]:
8
+ - @atproto/lex-schema@0.2.7
9
+
10
+ ## 0.3.5
11
+
12
+ ### Patch Changes
13
+
14
+ - [#5449](https://github.com/bluesky-social/atproto/pull/5449) [`ec29fcd`](https://github.com/bluesky-social/atproto/commit/ec29fcdb4e0ce098fb1473feebe876a94b1c8e33) Thanks [@mozzius](https://github.com/mozzius)! - Avoid requiring `AbortSignal.throwIfAborted()` for compatibility with React Native.
15
+
3
16
  ## 0.3.4
4
17
 
5
18
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,SAAS,EACT,SAAS,EACT,KAAK,EACL,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,IAAI,EACJ,UAAU,EACV,MAAM,EACN,UAAU,EACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAW,MAAM,qBAAqB,CAAA;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA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AAO,CAAC,GAC7B,OAAO,CAAC,SAAS,CAAC,CAAA;IACR,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,YAAY,EAC3C,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,EACX,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,SAAS,CAAC,CAAA;IAcrB;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,YAAY,EACrC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,EACX,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAKxB;IAED;;;;;;;;;;OAUG;IACI,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,YAAY,EACzC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,EACX,EAAE,UAAc,EAAE,GAAG,OAAO,EAAE,GAAE,WAAgB,GAC/C,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAyBzD;CACF"}
package/dist/client.js CHANGED
@@ -12,7 +12,7 @@ import putRecord from './lexicons/com/atproto/repo/putRecord.js';
12
12
  import uploadBlob from './lexicons/com/atproto/repo/uploadBlob.js';
13
13
  import getBlob from './lexicons/com/atproto/sync/getBlob.js';
14
14
  import { isService } from './types.js';
15
- import { applyDefaults, getDefaultRecordKey, getLiteralRecordKey, mergeHeaders, } from './util.js';
15
+ import { applyDefaults, getDefaultRecordKey, getLiteralRecordKey, mergeHeaders, throwIfAborted, } from './util.js';
16
16
  import { WriteOperationHelper, } from './write-operation-builder.js';
17
17
  import { xrpc, xrpcSafe, } from './xrpc.js';
18
18
  export { Procedure, Query, RecordSchema, WriteOperationHelper, };
@@ -480,7 +480,7 @@ export class Client {
480
480
  async *listAll(ns, { maxRetries = 3, ...options } = {}) {
481
481
  const schema = getMain(ns);
482
482
  do {
483
- options.signal?.throwIfAborted();
483
+ throwIfAborted(options.signal);
484
484
  const { body } = await this.listRecords(schema.$type, {
485
485
  ...options,
486
486
  maxRetries,
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC,8EAA8E;AAC9E,8EAA8E;AAC9E,uCAAuC;AACvC,OAAO,WAAW,MAAM,4CAA4C,CAAA;AACpE,OAAO,YAAY,MAAM,6CAA6C,CAAA;AACtE,OAAO,YAAY,MAAM,6CAA6C,CAAA;AACtE,OAAO,SAAS,MAAM,0CAA0C,CAAA;AAChE,OAAO,WAAW,EAAE,EAEnB,MAAM,4CAA4C,CAAA;AACnD,OAAO,SAAS,MAAM,0CAA0C,CAAA;AAChE,OAAO,UAAU,MAAM,2CAA2C,CAAA;AAClE,OAAO,OAAO,MAAM,wCAAwC,CAAA;AAM5D,OAAO,EAAqC,SAAS,EAAE,MAAM,YAAY,CAAA;AACzE,OAAO,EAGL,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,GACb,MAAM,WAAW,CAAA;AAClB,OAAO,EAIL,oBAAoB,GAGrB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAIL,IAAI,EACJ,QAAQ,GACT,MAAM,WAAW,CAAA;AAElB,OAAO,EAcL,SAAS,EACT,KAAK,EACL,YAAY,EAMZ,oBAAoB,GAGrB,CAAA;AA0RD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,MAAM;aACV,gBAAW,GAAyB,EAAE,CAAA;IAE7C;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,IAA2C;QAC1D,IAAI,IAAI,CAAC,W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AAS,iBAAiB,CAExB,MAAyB;IAEzB,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC9C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAA;IACxD,CAAC;SAAM,CAAC;QACN,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACpC,CAAC;AACH,CAAC","sourcesContent":["import type { LexMap, LexValue, TypedLexMap } from '@atproto/lex-data'\nimport type {\n AtIdentifierString,\n AtUriString,\n CidString,\n DidString,\n Infer,\n InferMethodInputBody,\n InferMethodOutputBody,\n InferRecordKey,\n LexiconRecordKey,\n Main,\n NsidString,\n Params,\n Restricted,\n} from '@atproto/lex-schema'\nimport { Procedure, Query, RecordSchema, getMain } from '@atproto/lex-schema'\nimport type { Agent, AgentOptions } from './agent.js'\nimport { buildAgent } from './agent.js'\nimport type { XrpcFailure } from './errors.js'\n// @NOTE We could use import { com } from \"./lexicons/index.js\" here, but some\n// consumers might not know how to properly tree-shake that, so we import only\n// the needed lexicon schemas directly.\nimport applyWrites from './lexicons/com/atproto/repo/applyWrites.js'\nimport createRecord from './lexicons/com/atproto/repo/createRecord.js'\nimport deleteRecord from './lexicons/com/atproto/repo/deleteRecord.js'\nimport getRecord from './lexicons/com/atproto/repo/getRecord.js'\nimport listRecords, {\n type Record as ListRecordsRecord,\n} from './lexicons/com/atproto/repo/listRecords.js'\nimport putRecord from './lexicons/com/atproto/repo/putRecord.js'\nimport uploadBlob from './lexicons/com/atproto/repo/uploadBlob.js'\nimport getBlob from './lexicons/com/atproto/sync/getBlob.js'\nimport type {\n XrpcResponse,\n XrpcResponseBody,\n XrpcResponseOptions,\n} from './response.js'\nimport { type BinaryBodyInit, type Service, isService } from './types.js'\nimport {\n type RecordKeyOptions,\n type XrpcRequestHeadersOptions,\n applyDefaults,\n getDefaultRecordKey,\n getLiteralRecordKey,\n mergeHeaders,\n} from './util.js'\nimport {\n type WriteOperation,\n type WriteOperationCreateOptions,\n type WriteOperationDeleteOptions,\n WriteOperationHelper,\n type WriteOperationUpdateOptions,\n type WriteOperationsFactory,\n} from './write-operation-builder.js'\nimport {\n type XrpcOptions,\n type XrpcRequestParams,\n type XrpcRequestProcessingOptions,\n xrpc,\n xrpcSafe,\n} from './xrpc.js'\n\nexport {\n type AtIdentifierString,\n type CidString,\n type DidString,\n type Infer,\n type InferMethodInputBody,\n type InferMethodOutputBody,\n type InferRecordKey,\n type LexMap,\n type LexValue,\n type LexiconRecordKey,\n type Main,\n type NsidString,\n type Params,\n Procedure,\n Query,\n RecordSchema,\n type Restricted,\n type TypedLexMap,\n type WriteOperation,\n type WriteOperationCreateOptions,\n type WriteOperationDeleteOptions,\n WriteOperationHelper,\n type WriteOperationUpdateOptions,\n type WriteOperationsFactory,\n}\n\n/**\n * Configuration options for creating a {@link Client}.\n *\n * @property {@link ClientOptions.labelers} - An iterable of labeler DIDs to include in requests. These will be combined with any global app labelers configured via {@link Client.configure}.\n * @property {@link ClientOptions.service} - An optional service identifier (DID or URL) for routing requests with service proxying.\n * @property {@link ClientOptions.headers} - Custom headers to include in all requests made by this client instance.\n * @property {@link ClientOptions.validateRequest} - If true, validates request bodies against their lexicon schemas before sending. Defaults to false for performance.\n * @property {@link ClientOptions.validateResponse} - If false, skips validation of response bodies against their lexicon schemas. Defaults to true to catch errors, but can be disabled for performance if you trust the server responses. Note that defaults will not be applied if validation is disabled, which can cause typing inconsistencies, so use with caution.\n * @property {@link ClientOptions.strictResponseProcessing} - If false, relaxes certain validation rules during response processing (e.g., allowing floats, deeper nesting, etc.). Defaults to true for strict compliance with {@link https://atproto.com/specs/data-model lexicon data model}, but can be disabled to handle non-compliant responses.\n *\n * @see {@link XrpcRequestHeadersOptions}\n * @see {@link XrpcRequestProcessingOptions}\n * @see {@link XrpcResponseOptions}\n *\n * @example\n * ```typescript\n * const options: ClientOptions = {\n * labelers: ['did:plc:labeler1'],\n * service: 'did:web:api.bsky.app#bsky_appview',\n * headers: { 'X-Custom-Header': 'value' },\n * validateRequest: false,\n * validateResponse: true,\n * strictResponseProcessing: false,\n * }\n * ```\n */\nexport type ClientOptions = XrpcRequestHeadersOptions &\n Pick<XrpcRequestProcessingOptions, 'validateRequest'> &\n XrpcResponseOptions\n\nexport type ActionOptions = {\n /** AbortSignal to cancel the request. */\n signal?: AbortSignal\n}\n\n/**\n * A composable action that can be invoked via {@link Client.call}.\n *\n * Actions provide a way to define custom operations that integrate with the\n * Client's call interface, enabling type-safe, reusable business logic.\n *\n * @typeParam I - The input type for the action\n * @typeParam O - The output type for the action\n *\n * @example\n * ```typescript\n * const myAction: Action<{ userId: string }, { profile: Profile }> = async (client, input, options) => {\n * const response = await client.xrpc(someMethod, { params: { actor: input.userId }, ...options })\n * return { profile: response.body }\n * }\n * ```\n */\nexport type Action<I = any, O = any> = (\n client: Client,\n input: I,\n options: ActionOptions,\n) => O | Promise<O>\n\n/**\n * Extracts the input type from an {@link Action}.\n * @typeParam A - The Action type to extract from\n */\nexport type InferActionInput<A extends Action> =\n A extends Action<infer I, any> ? I : never\n\n/**\n * Extracts the output type from an {@link Action}.\n * @typeParam A - The Action type to extract from\n */\nexport type InferActionOutput<A extends Action> =\n A extends Action<any, infer O> ? O : never\n\n/**\n * Options for creating a record in an AT Protocol repository.\n *\n * @see {@link Client.createRecord}\n */\nexport type CreateRecordOptions = Omit<\n XrpcOptions<typeof createRecord>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /**\n * Whether the PDS should validate the record against its lexicon schema.\n * When `true`, the PDS is asked to explicitly validate the record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides -- typically validating only collections whose\n * schemas it knows. This is server-side validation; for client-side\n * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.\n */\n validate?: boolean\n}\n\n/**\n * Options for deleting a record from an AT Protocol repository.\n *\n * @see {@link Client.deleteRecord}\n */\nexport type DeleteRecordOptions = Omit<\n XrpcOptions<typeof deleteRecord>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /** Compare-and-swap on the record CID. If specified, must match current record. */\n swapRecord?: string\n}\n\n/**\n * Options for retrieving a record from an AT Protocol repository.\n *\n * @see {@link Client.getRecord}\n */\nexport type GetRecordOptions = Omit<XrpcOptions<typeof getRecord>, 'params'> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n}\n\n/**\n * Options for creating or updating a record in an AT Protocol repository.\n *\n * @see {@link Client.putRecord}\n */\nexport type PutRecordOptions = Omit<XrpcOptions<typeof putRecord>, 'body'> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /** Compare-and-swap on the record CID. If specified, must match current record. */\n swapRecord?: string\n /**\n * Whether the PDS should validate the record against its lexicon schema.\n * When `true`, the PDS is asked to explicitly validate the record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides — typically validating only collections whose\n * schemas it knows. This is server-side validation; for client-side\n * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.\n */\n validate?: boolean\n}\n\n/**\n * Options for listing records in an AT Protocol repository collection.\n *\n * @see {@link Client.listRecords}\n */\nexport type ListRecordsOptions = Omit<\n XrpcOptions<typeof listRecords>,\n 'params'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Maximum number of records to return. */\n limit?: number\n /** Pagination cursor from a previous response. */\n cursor?: string\n /** If true, returns records in reverse chronological order. */\n reverse?: boolean\n}\n\n/**\n * Options for applying a batch of writes (create/update/delete) to an AT Protocol repository.\n *\n * @see {@link Client.applyWrites}\n */\nexport type ApplyWritesOptions = Omit<\n XrpcOptions<typeof applyWrites>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /**\n * Whether the PDS should validate the records against their lexicon schemas.\n * When `true`, the PDS is asked to explicitly validate every record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides — typically validating only collections whose\n * schemas it knows.\n */\n validate?: boolean\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: CidString\n}\n\nexport type UploadBlobOptions = Omit<XrpcOptions<typeof uploadBlob>, 'body'>\n\nexport type GetBlobOptions = Omit<XrpcOptions<typeof getBlob>, 'params'>\n\n/**\n * Type-safe options for {@link Client.create}, combining record options with key requirements.\n * @typeParam T - The record schema type\n * @see {@link CreateRecordOptions}\n */\nexport type CreateOptions<T extends RecordSchema> = CreateRecordOptions &\n RecordKeyOptions<T, 'tid' | 'any'>\n\n/**\n * Output type for record creation operations.\n * Contains the URI and CID of the newly created record.\n */\nexport type CreateOutput = InferMethodOutputBody<\n typeof createRecord,\n Uint8Array\n>\n\n/**\n * Type-safe options for {@link Client.delete}, combining delete options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record deletion operations.\n */\nexport type DeleteOutput = InferMethodOutputBody<\n typeof deleteRecord,\n Uint8Array\n>\n\n/**\n * Type-safe options for {@link Client.get}, combining get options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type GetOptions<T extends RecordSchema> = GetRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record retrieval operations.\n * Contains the record value validated against the schema type.\n * @typeParam T - The record schema type\n */\nexport type GetOutput<T extends RecordSchema> = Omit<\n InferMethodOutputBody<typeof getRecord, Uint8Array>,\n 'value'\n> & { value: Infer<T> }\n\n/**\n * Type-safe options for {@link Client.put}, combining put options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type PutOptions<T extends RecordSchema> = PutRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record put (create/update) operations.\n * Contains the URI and CID of the record.\n */\nexport type PutOutput = InferMethodOutputBody<typeof putRecord, Uint8Array>\n\n/**\n * Options for {@link Client.list} operations.\n */\nexport type ListOptions = ListRecordsOptions\n\n/**\n * Output type for record listing operations.\n * Contains validated records and any invalid records that failed schema validation.\n * @typeParam T - The record schema type\n */\nexport type ListOutput<T extends RecordSchema> = Omit<\n InferMethodOutputBody<typeof listRecords>,\n 'records'\n> & {\n /** Records that successfully validated against the schema. */\n records: ListRecordItem<Infer<T>>[]\n}\n\n/**\n * A discriminated union type representing the result of a record listing\n * operation.\n */\nexport type ListRecordItem<Value extends LexMap> =\n | { uri: AtUriString; cid: CidString; valid: true; value: Value }\n | { uri: AtUriString; cid: CidString; valid: false; value: LexMap }\n\n/**\n * The Client class is the primary interface for interacting with AT Protocol\n * services. It provides type-safe methods for XRPC calls, record operations,\n * and blob handling.\n *\n * @example\n * ```typescript\n * import { Client } from '@atproto/lex'\n * import { app } from '#/lexicons\n *\n * const client = new Client(oauthSession)\n *\n * const response = await client.xrpc(app.bsky.feed.getTimeline, {\n * params: { limit: 50 }\n * })\n * ```\n */\nexport class Client {\n static appLabelers: readonly DidString[] = []\n\n /**\n * Configures the Client (or its sub classes) globally.\n */\n static configure(opts: { appLabelers?: Iterable<DidString> }): void {\n if (opts.appLabelers) this.appLabelers = [...opts.appLabelers]\n }\n\n /** The underlying agent used for making requests. */\n public readonly agent: Agent\n\n /** Default header values to include in all requests made by this client instance. */\n public readonly headers: Headers\n\n /** Default {@link XrpcOptions} for this client instance. */\n public readonly xrpcDefaults: Readonly<{\n service: Service | null\n labelers: Set<DidString>\n appLabelers?: null | Iterable<DidString>\n validateRequest: boolean\n validateResponse: boolean\n strictResponseProcessing: boolean\n }>\n\n constructor(agent: Agent | AgentOptions, options: ClientOptions = {}) {\n this.agent = buildAgent(agent)\n this.headers = new Headers(options.headers)\n\n // @NOTE An \"atproto-proxy\" header provided through the `headers` option\n // acts as fallback for the `service` option.\n const service = this.headers.get('atproto-proxy')?.trim()\n\n this.xrpcDefaults = Object.freeze({\n service:\n options.service === undefined && service != null && isService(service)\n ? service\n : (options.service ?? null),\n labelers: new Set(options.labelers),\n // @NOTE when provided (including `null`), will override the class wide\n // Client.appLabelers\n appLabelers:\n options.appLabelers != null\n ? new Set(options.appLabelers)\n : options.appLabelers,\n validateRequest: options.validateRequest ?? false,\n validateResponse: options.validateResponse ?? true,\n strictResponseProcessing: options.strictResponseProcessing ?? true,\n })\n }\n\n /**\n * The DID of the authenticated user, or `undefined` if not authenticated.\n */\n get did(): DidString | undefined {\n return this.agent.did\n }\n\n /**\n * The DID of the authenticated user.\n * @throws {Error} if not authenticated\n */\n get assertDid(): DidString {\n this.assertAuthenticated()\n return this.did\n }\n\n get service(): Service | null {\n return this.xrpcDefaults.service\n }\n\n get labelers(): Set<DidString> {\n return this.xrpcDefaults.labelers\n }\n\n /**\n * Asserts that the client is authenticated.\n * Use as a type guard when you need to ensure authentication.\n *\n * @throws {Error} if not authenticated\n *\n * @example\n * ```typescript\n * client.assertAuthenticated()\n * // TypeScript now knows client.did is defined\n * console.log(client.did)\n * ```\n */\n public assertAuthenticated(): asserts this is { did: DidString } {\n if (!this.did) throw new Error('Client is not authenticated')\n }\n\n /**\n * Replaces all labelers with the given set.\n * @param labelers - Iterable of labeler DIDs\n */\n public setLabelers(labelers: Iterable<DidString> = []): void {\n this.clearLabelers()\n this.addLabelers(labelers)\n }\n\n /**\n * Adds labelers to the current set.\n * @param labelers - Iterable of labeler DIDs to add\n */\n public addLabelers(labelers: Iterable<DidString>): void {\n for (const labeler of labelers) this.xrpcDefaults.labelers.add(labeler)\n }\n\n /**\n * Removes all labelers from this client instance.\n */\n public clearLabelers(): void {\n this.xrpcDefaults.labelers.clear()\n }\n\n /**\n * Makes an XRPC request. Throws on failure.\n *\n * @param ns - The lexicon method definition (e.g., `app.bsky.feed.getTimeline`)\n * @param options - Request options including params and body\n * @returns The successful XRPC response\n * @throws {XrpcFailure} when the request fails or returns an error\n *\n * @example Query with parameters\n * ```typescript\n * const response = await client.xrpc(app.bsky.feed.getTimeline, {\n * params: { limit: 50, cursor: 'abc123' }\n * })\n * console.log(response.body.feed)\n * ```\n *\n * @example Procedure with body\n * ```typescript\n * const response = await client.xrpc(com.atproto.repo.createRecord, {\n * body: {\n * repo: client.assertDid,\n * collection: 'app.bsky.feed.post',\n * record: { text: 'Hello!', createdAt: new Date().toISOString() }\n * }\n * })\n * ```\n *\n * @see {@link xrpcSafe} for a non-throwing variant\n */\n async xrpc<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M>> {\n return xrpc(this.agent, ns, this.buildXrpcOptions(options))\n }\n\n /**\n * Makes an XRPC request without throwing on failure.\n * Returns either a successful response or a failure object.\n *\n * @param ns - The lexicon method definition\n * @param options - Request options\n * @returns Either an XrpcResponse on success or XrpcFailure on failure\n *\n * @example\n * ```typescript\n * const result = await client.xrpcSafe(app.bsky.actor.getProfile, {\n * params: { actor: 'alice.bsky.social' }\n * })\n *\n * if (result.success) {\n * console.log(result.body.displayName)\n * } else {\n * console.error('Failed:', result.error)\n * }\n * ```\n *\n * @see {@link xrpc} for a throwing variant\n */\n async xrpcSafe<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>> {\n return xrpcSafe(this.agent, ns, this.buildXrpcOptions(options))\n }\n\n protected buildXrpcOptions<M extends Query | Procedure>(\n options: XrpcOptions<M>,\n ): XrpcOptions<M> {\n // Apply the instance-wide defaults for service, labelers, and validation\n // options.\n const combined = applyDefaults(options, this.xrpcDefaults)\n\n // Dynamically apply the class-wide appLabelers if they are not already set\n // in the combined options.\n if (combined.appLabelers === undefined) {\n combined.appLabelers = (this.constructor as typeof Client).appLabelers\n }\n\n const optionsHeaders =\n options.headers != null ? new Headers(options.headers) : null\n\n // @NOTE we allow the \"service\" options to fallback to the \"atproto-proxy\"\n // header if it is present in the request-specific headers.\n if (options.service === undefined && optionsHeaders?.has('atproto-proxy')) {\n const serviceHeader = optionsHeaders.get('atproto-proxy')?.trim()\n if (serviceHeader != null && isService(serviceHeader)) {\n combined.service = serviceHeader\n }\n }\n\n // Merge the instance-wide headers with the request-specific headers.\n // Request-specific headers take precedence. This cannot be done in the\n // applyDefaults step above because headers require special merging logic.\n combined.headers = optionsHeaders\n ? mergeHeaders(this.headers, optionsHeaders)\n : new Headers(this.headers)\n\n // @NOTE Since the combined options here always contain a defined\n // \"service\" (even if null), any \"atproto-proxy\" header in either the\n // instance-wide or request-specific headers will be overridden by the\n // \"service\" value. Note that an \"atproto-proxy\" header provided through\n // the constructor's `headers` option is used as fallback for the\n // constructor's `service` option (see constructor), making the two\n // equivalent.\n return combined\n }\n\n /**\n * Creates a new record in an AT Protocol repository.\n *\n * @param record - The record to create, must include an {@link NsidString} `$type`\n * @param rkey - Optional record key; if omitted, server generates a TID\n * @param options - Create options including repo, swapCommit, validate\n * @returns The XRPC response containing the created record's URI and CID\n *\n * @example\n * ```typescript\n * const response = await client.createRecord(\n * { $type: 'app.bsky.feed.post', text: 'Hello!', createdAt: new Date().toISOString() },\n * undefined, // Let server generate rkey\n * { validate: true }\n * )\n * console.log(response.body.uri)\n * ```\n *\n * @see {@link create} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n public async createRecord(\n record: TypedLexMap<NsidString>,\n rkey?: string,\n { service = null, labelers = null, ...options }: CreateRecordOptions = {},\n ): Promise<XrpcResponse<typeof createRecord>> {\n return this.xrpc(createRecord, {\n ...options,\n service,\n labelers,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n record,\n rkey,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n /**\n * Deletes a record from an AT Protocol repository.\n *\n * @param collection - The collection NSID\n * @param rkey - The record key\n * @param options - Delete options including repo, swapCommit, swapRecord\n *\n * @see {@link delete} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async deleteRecord(\n collection: NsidString,\n rkey: string,\n { service = null, labelers = null, ...options }: DeleteRecordOptions = {},\n ): Promise<XrpcResponse<typeof deleteRecord>> {\n return this.xrpc(deleteRecord, {\n ...options,\n service,\n labelers,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n /**\n * Retrieves a record from an AT Protocol repository.\n *\n * @param collection - The collection NSID\n * @param rkey - The record key\n * @param options - Get options including repo\n *\n * @see {@link get} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n public async getRecord(\n collection: NsidString,\n rkey: string,\n { service = null, labelers = null, ...options }: GetRecordOptions = {},\n ): Promise<XrpcResponse<typeof getRecord>> {\n return this.xrpc(getRecord, {\n ...options,\n service,\n labelers,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n },\n })\n }\n\n /**\n * Creates or updates a record in a repository.\n *\n * @param record - The record to put, must include an {@link NsidString} `$type`\n * @param rkey - The record key\n * @param options - Put options including repo, swapCommit, swapRecord, validate\n *\n * @see {@link put} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async putRecord(\n record: TypedLexMap<NsidString>,\n rkey: string,\n { service = null, labelers = null, ...options }: PutRecordOptions = {},\n ): Promise<XrpcResponse<typeof putRecord>> {\n return this.xrpc(putRecord, {\n ...options,\n service,\n labelers,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n rkey,\n record,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n /**\n * Lists records in a collection.\n *\n * @param nsid - The collection NSID\n * @param options - List options including repo, limit, cursor, reverse\n *\n * @see {@link list} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async listRecords(\n nsid: NsidString,\n { service = null, labelers = null, ...options }: ListRecordsOptions = {},\n ): Promise<XrpcResponse<typeof listRecords>> {\n return this.xrpc(listRecords, {\n ...options,\n service,\n labelers,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection: nsid,\n cursor: options?.cursor,\n limit: options?.limit,\n reverse: options?.reverse,\n },\n })\n }\n\n /**\n * Performs an atomic batch of create, update, and delete operations on records in a repository.\n *\n * @param builder - A function that receives an {@link ApplyWritesOperations} instance to build the operations\n * @param options - ApplyWrites options including repo, validate, swapCommit\n * @returns The XRPC response from the applyWrites call\n *\n * @example\n * ```typescript\n * const response = await client.applyWrites((op) => [\n * op.create(app.bsky.feed.post, { text: 'Hello!' }),\n * op.update(app.bsky.feed.post, { text: 'Updated text' }, { rkey: 'post123' }),\n * op.delete(app.bsky.feed.post, 'post456'),\n * op.update(app.bsky.actor.profile, { displayName: 'Alice' }),\n * ], {\n * validate: true,\n * })\n *\n * for (const result of response.body.results) {\n * console.log(result.uri)\n * }\n * ```\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async applyWrites(\n factory: WriteOperationsFactory,\n { service = null, labelers = null, ...options }: ApplyWritesOptions = {},\n ): Promise<XrpcResponse<typeof applyWrites>> {\n return this.xrpc(applyWrites, {\n ...options,\n service,\n labelers,\n body: {\n repo: options?.repo ?? this.assertDid,\n writes: WriteOperationHelper.build(factory),\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n /**\n * Uploads a blob to an AT Protocol repository.\n *\n * @param body - The blob data (Uint8Array, ReadableStream, Blob, etc.)\n * @param options - Upload options including encoding hint\n * @returns Response containing the blob reference\n *\n * @example\n * ```typescript\n * const imageData = await fetch('image.png').then(r => r.arrayBuffer())\n * const response = await client.uploadBlob(new Uint8Array(imageData), {\n * encoding: 'image/png'\n * })\n * console.log(response.body.blob) // Use this ref in records\n * ```\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async uploadBlob(\n body: BinaryBodyInit,\n { service = null, labelers = null, ...options }: UploadBlobOptions = {},\n ): Promise<XrpcResponse<typeof uploadBlob>> {\n return this.xrpc(uploadBlob, { ...options, service, labelers, body })\n }\n\n /**\n * Retrieves a blob by DID and CID.\n *\n * @param did - The DID of the repository containing the blob\n * @param cid - The CID of the blob\n * @param options - Call options\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async getBlob(\n did: DidString,\n cid: CidString,\n { service = null, labelers = null, ...options }: GetBlobOptions = {},\n ): Promise<XrpcResponse<typeof getBlob>> {\n return this.xrpc(getBlob, {\n ...options,\n service,\n labelers,\n params: { did, cid },\n })\n }\n\n /**\n * Universal call method for queries, procedures, and custom actions.\n * Automatically determines the call type based on the lexicon definition.\n *\n * @param ns - The lexicon method or action definition\n * @param arg - The input argument (params for queries, body for procedures, input for actions)\n * @param options - Call options\n * @returns The method response body or action output\n * @see {@link xrpc} if you need access to the full response object\n *\n * @example Query\n * ```typescript\n * const profile = await client.call(app.bsky.actor.getProfile, {\n * actor: 'alice.bsky.social'\n * })\n * ```\n *\n * @example Procedure\n * ```typescript\n * const result = await client.call(com.atproto.repo.createRecord, {\n * repo: did,\n * collection: 'app.bsky.feed.post',\n * record: { text: 'Hello!' }\n * })\n * ```\n *\n * @example Action\n * ```typescript\n * const result = await client.call(updateProfile, (profile) => {\n * profile.displayName = 'Alice'\n * })\n * ```\n */\n public async call<const T extends Query>(\n ns: NonNullable<unknown> extends XrpcRequestParams<T>\n ? Main<T>\n : Restricted<'This query type requires a \"params\" argument'>,\n ): Promise<XrpcResponseBody<T>>\n public async call<const T extends Procedure>(\n ns: undefined extends InferMethodInputBody<T, Uint8Array>\n ? Main<T>\n : Restricted<'This procedure type requires an \"input\" argument'>,\n ): Promise<XrpcResponseBody<T>>\n public async call<const T extends Action>(\n ns: void extends InferActionInput<T>\n ? Main<T>\n : Restricted<'This action type requires an \"input\" argument'>,\n ): Promise<InferActionOutput<T>>\n public async call<const T extends Action | Procedure | Query>(\n ns: Main<T>,\n arg: T extends Action\n ? InferActionInput<T>\n : T extends Procedure\n ? InferMethodInputBody<T, Uint8Array>\n : T extends Query\n ? XrpcRequestParams<T>\n : never,\n options?: T extends Action\n ? ActionOptions\n : T extends Procedure\n ? Omit<XrpcOptions<T>, 'body'>\n : T extends Query\n ? Omit<XrpcOptions<T>, 'params'>\n : never,\n ): Promise<\n T extends Action\n ? InferActionOutput<T>\n : T extends Procedure\n ? XrpcResponseBody<T>\n : T extends Query\n ? XrpcResponseBody<T>\n : never\n >\n public async call(\n ns: Main<Action> | Main<Procedure> | Main<Query>,\n arg?: LexValue | Params,\n options: ActionOptions = {},\n ): Promise<unknown> {\n const method = getMain(ns)\n\n if (typeof method === 'function') {\n return method(this, arg, options)\n }\n\n if (method instanceof Procedure) {\n const result = await this.xrpc(method, { ...options, body: arg as any })\n return result.body\n } else if (method instanceof Query) {\n const result = await this.xrpc(method, { ...options, params: arg as any })\n return result.body\n } else {\n throw new TypeError('Invalid lexicon')\n }\n }\n\n /**\n * Creates a new record with full type safety based on the schema.\n *\n * @param ns - The record schema definition\n * @param input - The record data (without `$type`, which is added automatically)\n * @param options - Create options including rkey (required for some record types)\n * @returns The create output including URI and CID\n *\n * @example Creating a post\n * ```typescript\n * const result = await client.create(app.bsky.feed.post, {\n * text: 'Hello, world!',\n * createdAt: new Date().toISOString()\n * })\n * console.log(result.uri)\n * ```\n *\n * @example Creating a record with explicit rkey\n * ```typescript\n * const result = await client.create(app.bsky.actor.profile, {\n * displayName: 'Alice'\n * }, { rkey: 'self' })\n * ```\n *\n * @see {@link createRecord} for a lower-level method that returns the raw response without schema validation\n */\n public async create<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends CreateOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T> = {} as CreateOptions<T>,\n ): Promise<CreateOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input) as TypedLexMap<NsidString>\n if (options?.validateRequest) schema.validate(record)\n const rkey = options.rkey ?? getDefaultRecordKey(schema)\n if (rkey !== undefined) schema.keySchema.assert(rkey)\n const response = await this.createRecord(record, rkey, options)\n return response.body\n }\n\n /**\n * Deletes a record with type-safe options.\n *\n * @param ns - The record schema definition\n * @param options - Delete options (rkey required for non-literal keys)\n * @returns The delete output\n *\n * @see {@link deleteRecord} for a lower-level method that returns the raw response without schema validation\n */\n public async delete<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends DeleteOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Main<T>,\n options?: DeleteOptions<T>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Main<T>,\n options: DeleteOptions<T> = {} as DeleteOptions<T>,\n ): Promise<DeleteOutput> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.deleteRecord(schema.$type, rkey, options)\n return response.body\n }\n\n /**\n * Retrieves a record with type-safe validation.\n *\n * @param ns - The record schema definition\n * @param options - Get options (rkey required for non-literal keys)\n * @returns The record data validated against the schema\n *\n * @example\n * ```typescript\n * const profile = await client.get(app.bsky.actor.profile)\n * // profile.value is typed as app.bsky.actor.profile.Record\n * console.log(profile.value.displayName)\n * ```\n *\n * @see {@link getRecord} for a lower-level method that returns the raw record without schema validation\n */\n public async get<const T extends RecordSchema>(\n ns: T['key'] extends `literal:${string}`\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Main<T>,\n options: GetOptions<T>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Main<T>,\n options: GetOptions<T> = {} as GetOptions<T>,\n ): Promise<GetOutput<T>> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.getRecord(schema.$type, rkey, options)\n const value = schema.validate(response.body.value)\n return { ...response.body, value }\n }\n\n /**\n * Creates or updates a record with full type safety.\n *\n * @param ns - The record schema definition\n * @param input - The record data\n * @param options - Put options (rkey required for non-literal keys)\n * @returns The put output including URI and CID\n *\n * @example Creating a new record\n * ```typescript\n * const result = await client.put(app.bsky.feed.post, {\n * text: 'Hello, world!',\n * createdAt: new Date().toISOString()\n * })\n * console.log(result.uri)\n * ```\n *\n * @example Updating an existing record with explicit rkey\n * ```typescript\n * const result = await client.put(app.bsky.actor.profile, {\n * displayName: 'Alice'\n * }, { rkey: 'self' })\n * ```\n *\n * @see {@link putRecord} for a lower-level method that returns the raw record without schema validation\n */\n public async put<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends PutOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T> = {} as PutOptions<T>,\n ): Promise<PutOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input) as TypedLexMap<NsidString>\n if (options?.validateRequest) schema.validate(record)\n const rkey = options.rkey ?? getLiteralRecordKey(schema)\n const response = await this.putRecord(record, rkey, options)\n return response.body\n }\n\n /**\n * Lists records with type-safe validation and separation of valid/invalid records.\n *\n * @param ns - The record schema definition\n * @param options - List options\n * @returns Records validated against the schema, with invalid records included as LexMap\n *\n * @example\n * ```typescript\n * const result = await client.list(app.bsky.feed.post, { limit: 100 })\n * for (const record of result.records) {\n * if (record.valid) {\n * record.value // Fully typed\n * } else {\n * record.value // Invalid record, typed as LexMap\n * }\n * }\n * ```\n *\n * @see {@link listRecords} for a lower-level method that returns the raw records without schema validation\n */\n async list<const T extends RecordSchema>(\n ns: Main<T>,\n options?: ListOptions,\n ): Promise<ListOutput<T>> {\n const schema = getMain(ns)\n const { body } = await this.listRecords(schema.$type, options)\n const records = body.records.map(processListRecord, schema)\n return { ...body, records }\n }\n\n /**\n * Asynchronously iterates over all records in a collection, handling\n * pagination automatically.\n *\n * @param ns - The record schema definition\n * @param options - List options including limit and cursor\n * @returns An async generator yielding each record validated against the schema\n *\n * @see {@link list} for a method that returns a single page of records\n * @see {@link listRecords} for a lower-level method that returns raw records without schema validation\n */\n async *listAll<const T extends RecordSchema>(\n ns: Main<T>,\n { maxRetries = 3, ...options }: ListOptions = {},\n ): AsyncGenerator<ListRecordItem<Infer<T>>, void, unknown> {\n const schema = getMain(ns)\n\n do {\n options.signal?.throwIfAborted()\n\n const { body } = await this.listRecords(schema.$type, {\n ...options,\n maxRetries,\n })\n\n // We don't use this.list() here so that we can lazily process records as\n // they come in, rather than mapping and yielding the entire page at once.\n for (const record of body.records) {\n yield processListRecord.call(schema, record)\n }\n\n // If the server returns the same cursor, we may be in a loop. Stop\n // iteration.\n if (body.cursor && body.cursor === options.cursor) {\n return\n }\n\n options.cursor = body.cursor\n } while (options.cursor)\n }\n}\n\nfunction processListRecord<T extends RecordSchema>(\n this: T,\n record: ListRecordsRecord,\n): ListRecordItem<Infer<T>> {\n const result = this.safeValidate(record.value)\n if (result.success) {\n return { ...record, valid: true, value: result.value }\n } else {\n return { ...record, valid: false }\n }\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC,8EAA8E;AAC9E,8EAA8E;AAC9E,uCAAuC;AACvC,OAAO,WAAW,MAAM,4CAA4C,CAAA;AACpE,OAAO,YAAY,MAAM,6CAA6C,CAAA;AACtE,OAAO,YAAY,MAAM,6CAA6C,CAAA;AACtE,OAAO,SAAS,MAAM,0CAA0C,CAAA;AAChE,OAAO,WAAW,EAAE,EAEnB,MAAM,4CAA4C,CAAA;AACnD,OAAO,SAAS,MAAM,0CAA0C,CAAA;A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AAA;YAE9B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE;gBACpD,GAAG,OAAO;gBACV,UAAU;aACX,CAAC,CAAA;YAEF,yEAAyE;YACzE,0EAA0E;YAC1E,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClC,MAAM,iBAAiB,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YAC9C,CAAC;YAED,mEAAmE;YACnE,aAAa;YACb,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;gBAClD,OAAM;YACR,CAAC;YAED,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QAC9B,CAAC,QAAQ,OAAO,CAAC,MAAM,EAAC;IAC1B,CAAC;CACF;AAED,SAAS,iBAAiB,CAExB,MAAyB;IAEzB,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC9C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAA;IACxD,CAAC;SAAM,CAAC;QACN,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACpC,CAAC;AACH,CAAC","sourcesContent":["import type { LexMap, LexValue, TypedLexMap } from '@atproto/lex-data'\nimport type {\n AtIdentifierString,\n AtUriString,\n CidString,\n DidString,\n Infer,\n InferMethodInputBody,\n InferMethodOutputBody,\n InferRecordKey,\n LexiconRecordKey,\n Main,\n NsidString,\n Params,\n Restricted,\n} from '@atproto/lex-schema'\nimport { Procedure, Query, RecordSchema, getMain } from '@atproto/lex-schema'\nimport type { Agent, AgentOptions } from './agent.js'\nimport { buildAgent } from './agent.js'\nimport type { XrpcFailure } from './errors.js'\n// @NOTE We could use import { com } from \"./lexicons/index.js\" here, but some\n// consumers might not know how to properly tree-shake that, so we import only\n// the needed lexicon schemas directly.\nimport applyWrites from './lexicons/com/atproto/repo/applyWrites.js'\nimport createRecord from './lexicons/com/atproto/repo/createRecord.js'\nimport deleteRecord from './lexicons/com/atproto/repo/deleteRecord.js'\nimport getRecord from './lexicons/com/atproto/repo/getRecord.js'\nimport listRecords, {\n type Record as ListRecordsRecord,\n} from './lexicons/com/atproto/repo/listRecords.js'\nimport putRecord from './lexicons/com/atproto/repo/putRecord.js'\nimport uploadBlob from './lexicons/com/atproto/repo/uploadBlob.js'\nimport getBlob from './lexicons/com/atproto/sync/getBlob.js'\nimport type {\n XrpcResponse,\n XrpcResponseBody,\n XrpcResponseOptions,\n} from './response.js'\nimport { type BinaryBodyInit, type Service, isService } from './types.js'\nimport {\n type RecordKeyOptions,\n type XrpcRequestHeadersOptions,\n applyDefaults,\n getDefaultRecordKey,\n getLiteralRecordKey,\n mergeHeaders,\n throwIfAborted,\n} from './util.js'\nimport {\n type WriteOperation,\n type WriteOperationCreateOptions,\n type WriteOperationDeleteOptions,\n WriteOperationHelper,\n type WriteOperationUpdateOptions,\n type WriteOperationsFactory,\n} from './write-operation-builder.js'\nimport {\n type XrpcOptions,\n type XrpcRequestParams,\n type XrpcRequestProcessingOptions,\n xrpc,\n xrpcSafe,\n} from './xrpc.js'\n\nexport {\n type AtIdentifierString,\n type CidString,\n type DidString,\n type Infer,\n type InferMethodInputBody,\n type InferMethodOutputBody,\n type InferRecordKey,\n type LexMap,\n type LexValue,\n type LexiconRecordKey,\n type Main,\n type NsidString,\n type Params,\n Procedure,\n Query,\n RecordSchema,\n type Restricted,\n type TypedLexMap,\n type WriteOperation,\n type WriteOperationCreateOptions,\n type WriteOperationDeleteOptions,\n WriteOperationHelper,\n type WriteOperationUpdateOptions,\n type WriteOperationsFactory,\n}\n\n/**\n * Configuration options for creating a {@link Client}.\n *\n * @property {@link ClientOptions.labelers} - An iterable of labeler DIDs to include in requests. These will be combined with any global app labelers configured via {@link Client.configure}.\n * @property {@link ClientOptions.service} - An optional service identifier (DID or URL) for routing requests with service proxying.\n * @property {@link ClientOptions.headers} - Custom headers to include in all requests made by this client instance.\n * @property {@link ClientOptions.validateRequest} - If true, validates request bodies against their lexicon schemas before sending. Defaults to false for performance.\n * @property {@link ClientOptions.validateResponse} - If false, skips validation of response bodies against their lexicon schemas. Defaults to true to catch errors, but can be disabled for performance if you trust the server responses. Note that defaults will not be applied if validation is disabled, which can cause typing inconsistencies, so use with caution.\n * @property {@link ClientOptions.strictResponseProcessing} - If false, relaxes certain validation rules during response processing (e.g., allowing floats, deeper nesting, etc.). Defaults to true for strict compliance with {@link https://atproto.com/specs/data-model lexicon data model}, but can be disabled to handle non-compliant responses.\n *\n * @see {@link XrpcRequestHeadersOptions}\n * @see {@link XrpcRequestProcessingOptions}\n * @see {@link XrpcResponseOptions}\n *\n * @example\n * ```typescript\n * const options: ClientOptions = {\n * labelers: ['did:plc:labeler1'],\n * service: 'did:web:api.bsky.app#bsky_appview',\n * headers: { 'X-Custom-Header': 'value' },\n * validateRequest: false,\n * validateResponse: true,\n * strictResponseProcessing: false,\n * }\n * ```\n */\nexport type ClientOptions = XrpcRequestHeadersOptions &\n Pick<XrpcRequestProcessingOptions, 'validateRequest'> &\n XrpcResponseOptions\n\nexport type ActionOptions = {\n /** AbortSignal to cancel the request. */\n signal?: AbortSignal\n}\n\n/**\n * A composable action that can be invoked via {@link Client.call}.\n *\n * Actions provide a way to define custom operations that integrate with the\n * Client's call interface, enabling type-safe, reusable business logic.\n *\n * @typeParam I - The input type for the action\n * @typeParam O - The output type for the action\n *\n * @example\n * ```typescript\n * const myAction: Action<{ userId: string }, { profile: Profile }> = async (client, input, options) => {\n * const response = await client.xrpc(someMethod, { params: { actor: input.userId }, ...options })\n * return { profile: response.body }\n * }\n * ```\n */\nexport type Action<I = any, O = any> = (\n client: Client,\n input: I,\n options: ActionOptions,\n) => O | Promise<O>\n\n/**\n * Extracts the input type from an {@link Action}.\n * @typeParam A - The Action type to extract from\n */\nexport type InferActionInput<A extends Action> =\n A extends Action<infer I, any> ? I : never\n\n/**\n * Extracts the output type from an {@link Action}.\n * @typeParam A - The Action type to extract from\n */\nexport type InferActionOutput<A extends Action> =\n A extends Action<any, infer O> ? O : never\n\n/**\n * Options for creating a record in an AT Protocol repository.\n *\n * @see {@link Client.createRecord}\n */\nexport type CreateRecordOptions = Omit<\n XrpcOptions<typeof createRecord>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /**\n * Whether the PDS should validate the record against its lexicon schema.\n * When `true`, the PDS is asked to explicitly validate the record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides -- typically validating only collections whose\n * schemas it knows. This is server-side validation; for client-side\n * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.\n */\n validate?: boolean\n}\n\n/**\n * Options for deleting a record from an AT Protocol repository.\n *\n * @see {@link Client.deleteRecord}\n */\nexport type DeleteRecordOptions = Omit<\n XrpcOptions<typeof deleteRecord>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /** Compare-and-swap on the record CID. If specified, must match current record. */\n swapRecord?: string\n}\n\n/**\n * Options for retrieving a record from an AT Protocol repository.\n *\n * @see {@link Client.getRecord}\n */\nexport type GetRecordOptions = Omit<XrpcOptions<typeof getRecord>, 'params'> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n}\n\n/**\n * Options for creating or updating a record in an AT Protocol repository.\n *\n * @see {@link Client.putRecord}\n */\nexport type PutRecordOptions = Omit<XrpcOptions<typeof putRecord>, 'body'> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: string\n /** Compare-and-swap on the record CID. If specified, must match current record. */\n swapRecord?: string\n /**\n * Whether the PDS should validate the record against its lexicon schema.\n * When `true`, the PDS is asked to explicitly validate the record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides — typically validating only collections whose\n * schemas it knows. This is server-side validation; for client-side\n * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.\n */\n validate?: boolean\n}\n\n/**\n * Options for listing records in an AT Protocol repository collection.\n *\n * @see {@link Client.listRecords}\n */\nexport type ListRecordsOptions = Omit<\n XrpcOptions<typeof listRecords>,\n 'params'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /** Maximum number of records to return. */\n limit?: number\n /** Pagination cursor from a previous response. */\n cursor?: string\n /** If true, returns records in reverse chronological order. */\n reverse?: boolean\n}\n\n/**\n * Options for applying a batch of writes (create/update/delete) to an AT Protocol repository.\n *\n * @see {@link Client.applyWrites}\n */\nexport type ApplyWritesOptions = Omit<\n XrpcOptions<typeof applyWrites>,\n 'body'\n> & {\n /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */\n repo?: AtIdentifierString\n /**\n * Whether the PDS should validate the records against their lexicon schemas.\n * When `true`, the PDS is asked to explicitly validate every record. When\n * `false`, the PDS is asked to explicitly skip validation. When `undefined`\n * (default), the PDS decides — typically validating only collections whose\n * schemas it knows.\n */\n validate?: boolean\n /** Compare-and-swap on the repo commit. If specified, must match current commit. */\n swapCommit?: CidString\n}\n\nexport type UploadBlobOptions = Omit<XrpcOptions<typeof uploadBlob>, 'body'>\n\nexport type GetBlobOptions = Omit<XrpcOptions<typeof getBlob>, 'params'>\n\n/**\n * Type-safe options for {@link Client.create}, combining record options with key requirements.\n * @typeParam T - The record schema type\n * @see {@link CreateRecordOptions}\n */\nexport type CreateOptions<T extends RecordSchema> = CreateRecordOptions &\n RecordKeyOptions<T, 'tid' | 'any'>\n\n/**\n * Output type for record creation operations.\n * Contains the URI and CID of the newly created record.\n */\nexport type CreateOutput = InferMethodOutputBody<\n typeof createRecord,\n Uint8Array\n>\n\n/**\n * Type-safe options for {@link Client.delete}, combining delete options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record deletion operations.\n */\nexport type DeleteOutput = InferMethodOutputBody<\n typeof deleteRecord,\n Uint8Array\n>\n\n/**\n * Type-safe options for {@link Client.get}, combining get options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type GetOptions<T extends RecordSchema> = GetRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record retrieval operations.\n * Contains the record value validated against the schema type.\n * @typeParam T - The record schema type\n */\nexport type GetOutput<T extends RecordSchema> = Omit<\n InferMethodOutputBody<typeof getRecord, Uint8Array>,\n 'value'\n> & { value: Infer<T> }\n\n/**\n * Type-safe options for {@link Client.put}, combining put options with key requirements.\n * @typeParam T - The record schema type\n */\nexport type PutOptions<T extends RecordSchema> = PutRecordOptions &\n RecordKeyOptions<T>\n\n/**\n * Output type for record put (create/update) operations.\n * Contains the URI and CID of the record.\n */\nexport type PutOutput = InferMethodOutputBody<typeof putRecord, Uint8Array>\n\n/**\n * Options for {@link Client.list} operations.\n */\nexport type ListOptions = ListRecordsOptions\n\n/**\n * Output type for record listing operations.\n * Contains validated records and any invalid records that failed schema validation.\n * @typeParam T - The record schema type\n */\nexport type ListOutput<T extends RecordSchema> = Omit<\n InferMethodOutputBody<typeof listRecords>,\n 'records'\n> & {\n /** Records that successfully validated against the schema. */\n records: ListRecordItem<Infer<T>>[]\n}\n\n/**\n * A discriminated union type representing the result of a record listing\n * operation.\n */\nexport type ListRecordItem<Value extends LexMap> =\n | { uri: AtUriString; cid: CidString; valid: true; value: Value }\n | { uri: AtUriString; cid: CidString; valid: false; value: LexMap }\n\n/**\n * The Client class is the primary interface for interacting with AT Protocol\n * services. It provides type-safe methods for XRPC calls, record operations,\n * and blob handling.\n *\n * @example\n * ```typescript\n * import { Client } from '@atproto/lex'\n * import { app } from '#/lexicons\n *\n * const client = new Client(oauthSession)\n *\n * const response = await client.xrpc(app.bsky.feed.getTimeline, {\n * params: { limit: 50 }\n * })\n * ```\n */\nexport class Client {\n static appLabelers: readonly DidString[] = []\n\n /**\n * Configures the Client (or its sub classes) globally.\n */\n static configure(opts: { appLabelers?: Iterable<DidString> }): void {\n if (opts.appLabelers) this.appLabelers = [...opts.appLabelers]\n }\n\n /** The underlying agent used for making requests. */\n public readonly agent: Agent\n\n /** Default header values to include in all requests made by this client instance. */\n public readonly headers: Headers\n\n /** Default {@link XrpcOptions} for this client instance. */\n public readonly xrpcDefaults: Readonly<{\n service: Service | null\n labelers: Set<DidString>\n appLabelers?: null | Iterable<DidString>\n validateRequest: boolean\n validateResponse: boolean\n strictResponseProcessing: boolean\n }>\n\n constructor(agent: Agent | AgentOptions, options: ClientOptions = {}) {\n this.agent = buildAgent(agent)\n this.headers = new Headers(options.headers)\n\n // @NOTE An \"atproto-proxy\" header provided through the `headers` option\n // acts as fallback for the `service` option.\n const service = this.headers.get('atproto-proxy')?.trim()\n\n this.xrpcDefaults = Object.freeze({\n service:\n options.service === undefined && service != null && isService(service)\n ? service\n : (options.service ?? null),\n labelers: new Set(options.labelers),\n // @NOTE when provided (including `null`), will override the class wide\n // Client.appLabelers\n appLabelers:\n options.appLabelers != null\n ? new Set(options.appLabelers)\n : options.appLabelers,\n validateRequest: options.validateRequest ?? false,\n validateResponse: options.validateResponse ?? true,\n strictResponseProcessing: options.strictResponseProcessing ?? true,\n })\n }\n\n /**\n * The DID of the authenticated user, or `undefined` if not authenticated.\n */\n get did(): DidString | undefined {\n return this.agent.did\n }\n\n /**\n * The DID of the authenticated user.\n * @throws {Error} if not authenticated\n */\n get assertDid(): DidString {\n this.assertAuthenticated()\n return this.did\n }\n\n get service(): Service | null {\n return this.xrpcDefaults.service\n }\n\n get labelers(): Set<DidString> {\n return this.xrpcDefaults.labelers\n }\n\n /**\n * Asserts that the client is authenticated.\n * Use as a type guard when you need to ensure authentication.\n *\n * @throws {Error} if not authenticated\n *\n * @example\n * ```typescript\n * client.assertAuthenticated()\n * // TypeScript now knows client.did is defined\n * console.log(client.did)\n * ```\n */\n public assertAuthenticated(): asserts this is { did: DidString } {\n if (!this.did) throw new Error('Client is not authenticated')\n }\n\n /**\n * Replaces all labelers with the given set.\n * @param labelers - Iterable of labeler DIDs\n */\n public setLabelers(labelers: Iterable<DidString> = []): void {\n this.clearLabelers()\n this.addLabelers(labelers)\n }\n\n /**\n * Adds labelers to the current set.\n * @param labelers - Iterable of labeler DIDs to add\n */\n public addLabelers(labelers: Iterable<DidString>): void {\n for (const labeler of labelers) this.xrpcDefaults.labelers.add(labeler)\n }\n\n /**\n * Removes all labelers from this client instance.\n */\n public clearLabelers(): void {\n this.xrpcDefaults.labelers.clear()\n }\n\n /**\n * Makes an XRPC request. Throws on failure.\n *\n * @param ns - The lexicon method definition (e.g., `app.bsky.feed.getTimeline`)\n * @param options - Request options including params and body\n * @returns The successful XRPC response\n * @throws {XrpcFailure} when the request fails or returns an error\n *\n * @example Query with parameters\n * ```typescript\n * const response = await client.xrpc(app.bsky.feed.getTimeline, {\n * params: { limit: 50, cursor: 'abc123' }\n * })\n * console.log(response.body.feed)\n * ```\n *\n * @example Procedure with body\n * ```typescript\n * const response = await client.xrpc(com.atproto.repo.createRecord, {\n * body: {\n * repo: client.assertDid,\n * collection: 'app.bsky.feed.post',\n * record: { text: 'Hello!', createdAt: new Date().toISOString() }\n * }\n * })\n * ```\n *\n * @see {@link xrpcSafe} for a non-throwing variant\n */\n async xrpc<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M>> {\n return xrpc(this.agent, ns, this.buildXrpcOptions(options))\n }\n\n /**\n * Makes an XRPC request without throwing on failure.\n * Returns either a successful response or a failure object.\n *\n * @param ns - The lexicon method definition\n * @param options - Request options\n * @returns Either an XrpcResponse on success or XrpcFailure on failure\n *\n * @example\n * ```typescript\n * const result = await client.xrpcSafe(app.bsky.actor.getProfile, {\n * params: { actor: 'alice.bsky.social' }\n * })\n *\n * if (result.success) {\n * console.log(result.body.displayName)\n * } else {\n * console.error('Failed:', result.error)\n * }\n * ```\n *\n * @see {@link xrpc} for a throwing variant\n */\n async xrpcSafe<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>> {\n return xrpcSafe(this.agent, ns, this.buildXrpcOptions(options))\n }\n\n protected buildXrpcOptions<M extends Query | Procedure>(\n options: XrpcOptions<M>,\n ): XrpcOptions<M> {\n // Apply the instance-wide defaults for service, labelers, and validation\n // options.\n const combined = applyDefaults(options, this.xrpcDefaults)\n\n // Dynamically apply the class-wide appLabelers if they are not already set\n // in the combined options.\n if (combined.appLabelers === undefined) {\n combined.appLabelers = (this.constructor as typeof Client).appLabelers\n }\n\n const optionsHeaders =\n options.headers != null ? new Headers(options.headers) : null\n\n // @NOTE we allow the \"service\" options to fallback to the \"atproto-proxy\"\n // header if it is present in the request-specific headers.\n if (options.service === undefined && optionsHeaders?.has('atproto-proxy')) {\n const serviceHeader = optionsHeaders.get('atproto-proxy')?.trim()\n if (serviceHeader != null && isService(serviceHeader)) {\n combined.service = serviceHeader\n }\n }\n\n // Merge the instance-wide headers with the request-specific headers.\n // Request-specific headers take precedence. This cannot be done in the\n // applyDefaults step above because headers require special merging logic.\n combined.headers = optionsHeaders\n ? mergeHeaders(this.headers, optionsHeaders)\n : new Headers(this.headers)\n\n // @NOTE Since the combined options here always contain a defined\n // \"service\" (even if null), any \"atproto-proxy\" header in either the\n // instance-wide or request-specific headers will be overridden by the\n // \"service\" value. Note that an \"atproto-proxy\" header provided through\n // the constructor's `headers` option is used as fallback for the\n // constructor's `service` option (see constructor), making the two\n // equivalent.\n return combined\n }\n\n /**\n * Creates a new record in an AT Protocol repository.\n *\n * @param record - The record to create, must include an {@link NsidString} `$type`\n * @param rkey - Optional record key; if omitted, server generates a TID\n * @param options - Create options including repo, swapCommit, validate\n * @returns The XRPC response containing the created record's URI and CID\n *\n * @example\n * ```typescript\n * const response = await client.createRecord(\n * { $type: 'app.bsky.feed.post', text: 'Hello!', createdAt: new Date().toISOString() },\n * undefined, // Let server generate rkey\n * { validate: true }\n * )\n * console.log(response.body.uri)\n * ```\n *\n * @see {@link create} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n public async createRecord(\n record: TypedLexMap<NsidString>,\n rkey?: string,\n { service = null, labelers = null, ...options }: CreateRecordOptions = {},\n ): Promise<XrpcResponse<typeof createRecord>> {\n return this.xrpc(createRecord, {\n ...options,\n service,\n labelers,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n record,\n rkey,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n /**\n * Deletes a record from an AT Protocol repository.\n *\n * @param collection - The collection NSID\n * @param rkey - The record key\n * @param options - Delete options including repo, swapCommit, swapRecord\n *\n * @see {@link delete} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async deleteRecord(\n collection: NsidString,\n rkey: string,\n { service = null, labelers = null, ...options }: DeleteRecordOptions = {},\n ): Promise<XrpcResponse<typeof deleteRecord>> {\n return this.xrpc(deleteRecord, {\n ...options,\n service,\n labelers,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n /**\n * Retrieves a record from an AT Protocol repository.\n *\n * @param collection - The collection NSID\n * @param rkey - The record key\n * @param options - Get options including repo\n *\n * @see {@link get} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n public async getRecord(\n collection: NsidString,\n rkey: string,\n { service = null, labelers = null, ...options }: GetRecordOptions = {},\n ): Promise<XrpcResponse<typeof getRecord>> {\n return this.xrpc(getRecord, {\n ...options,\n service,\n labelers,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n },\n })\n }\n\n /**\n * Creates or updates a record in a repository.\n *\n * @param record - The record to put, must include an {@link NsidString} `$type`\n * @param rkey - The record key\n * @param options - Put options including repo, swapCommit, swapRecord, validate\n *\n * @see {@link put} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async putRecord(\n record: TypedLexMap<NsidString>,\n rkey: string,\n { service = null, labelers = null, ...options }: PutRecordOptions = {},\n ): Promise<XrpcResponse<typeof putRecord>> {\n return this.xrpc(putRecord, {\n ...options,\n service,\n labelers,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n rkey,\n record,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n /**\n * Lists records in a collection.\n *\n * @param nsid - The collection NSID\n * @param options - List options including repo, limit, cursor, reverse\n *\n * @see {@link list} for a higher-level typed alternative\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async listRecords(\n nsid: NsidString,\n { service = null, labelers = null, ...options }: ListRecordsOptions = {},\n ): Promise<XrpcResponse<typeof listRecords>> {\n return this.xrpc(listRecords, {\n ...options,\n service,\n labelers,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection: nsid,\n cursor: options?.cursor,\n limit: options?.limit,\n reverse: options?.reverse,\n },\n })\n }\n\n /**\n * Performs an atomic batch of create, update, and delete operations on records in a repository.\n *\n * @param builder - A function that receives an {@link ApplyWritesOperations} instance to build the operations\n * @param options - ApplyWrites options including repo, validate, swapCommit\n * @returns The XRPC response from the applyWrites call\n *\n * @example\n * ```typescript\n * const response = await client.applyWrites((op) => [\n * op.create(app.bsky.feed.post, { text: 'Hello!' }),\n * op.update(app.bsky.feed.post, { text: 'Updated text' }, { rkey: 'post123' }),\n * op.delete(app.bsky.feed.post, 'post456'),\n * op.update(app.bsky.actor.profile, { displayName: 'Alice' }),\n * ], {\n * validate: true,\n * })\n *\n * for (const result of response.body.results) {\n * console.log(result.uri)\n * }\n * ```\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async applyWrites(\n factory: WriteOperationsFactory,\n { service = null, labelers = null, ...options }: ApplyWritesOptions = {},\n ): Promise<XrpcResponse<typeof applyWrites>> {\n return this.xrpc(applyWrites, {\n ...options,\n service,\n labelers,\n body: {\n repo: options?.repo ?? this.assertDid,\n writes: WriteOperationHelper.build(factory),\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n /**\n * Uploads a blob to an AT Protocol repository.\n *\n * @param body - The blob data (Uint8Array, ReadableStream, Blob, etc.)\n * @param options - Upload options including encoding hint\n * @returns Response containing the blob reference\n *\n * @example\n * ```typescript\n * const imageData = await fetch('image.png').then(r => r.arrayBuffer())\n * const response = await client.uploadBlob(new Uint8Array(imageData), {\n * encoding: 'image/png'\n * })\n * console.log(response.body.blob) // Use this ref in records\n * ```\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async uploadBlob(\n body: BinaryBodyInit,\n { service = null, labelers = null, ...options }: UploadBlobOptions = {},\n ): Promise<XrpcResponse<typeof uploadBlob>> {\n return this.xrpc(uploadBlob, { ...options, service, labelers, body })\n }\n\n /**\n * Retrieves a blob by DID and CID.\n *\n * @param did - The DID of the repository containing the blob\n * @param cid - The CID of the blob\n * @param options - Call options\n *\n * @note This method will ignore the `service` and `labelers` instance wide\n * defaults, and will always use `null` unless explicitly overridden in the\n * options.\n */\n async getBlob(\n did: DidString,\n cid: CidString,\n { service = null, labelers = null, ...options }: GetBlobOptions = {},\n ): Promise<XrpcResponse<typeof getBlob>> {\n return this.xrpc(getBlob, {\n ...options,\n service,\n labelers,\n params: { did, cid },\n })\n }\n\n /**\n * Universal call method for queries, procedures, and custom actions.\n * Automatically determines the call type based on the lexicon definition.\n *\n * @param ns - The lexicon method or action definition\n * @param arg - The input argument (params for queries, body for procedures, input for actions)\n * @param options - Call options\n * @returns The method response body or action output\n * @see {@link xrpc} if you need access to the full response object\n *\n * @example Query\n * ```typescript\n * const profile = await client.call(app.bsky.actor.getProfile, {\n * actor: 'alice.bsky.social'\n * })\n * ```\n *\n * @example Procedure\n * ```typescript\n * const result = await client.call(com.atproto.repo.createRecord, {\n * repo: did,\n * collection: 'app.bsky.feed.post',\n * record: { text: 'Hello!' }\n * })\n * ```\n *\n * @example Action\n * ```typescript\n * const result = await client.call(updateProfile, (profile) => {\n * profile.displayName = 'Alice'\n * })\n * ```\n */\n public async call<const T extends Query>(\n ns: NonNullable<unknown> extends XrpcRequestParams<T>\n ? Main<T>\n : Restricted<'This query type requires a \"params\" argument'>,\n ): Promise<XrpcResponseBody<T>>\n public async call<const T extends Procedure>(\n ns: undefined extends InferMethodInputBody<T, Uint8Array>\n ? Main<T>\n : Restricted<'This procedure type requires an \"input\" argument'>,\n ): Promise<XrpcResponseBody<T>>\n public async call<const T extends Action>(\n ns: void extends InferActionInput<T>\n ? Main<T>\n : Restricted<'This action type requires an \"input\" argument'>,\n ): Promise<InferActionOutput<T>>\n public async call<const T extends Action | Procedure | Query>(\n ns: Main<T>,\n arg: T extends Action\n ? InferActionInput<T>\n : T extends Procedure\n ? InferMethodInputBody<T, Uint8Array>\n : T extends Query\n ? XrpcRequestParams<T>\n : never,\n options?: T extends Action\n ? ActionOptions\n : T extends Procedure\n ? Omit<XrpcOptions<T>, 'body'>\n : T extends Query\n ? Omit<XrpcOptions<T>, 'params'>\n : never,\n ): Promise<\n T extends Action\n ? InferActionOutput<T>\n : T extends Procedure\n ? XrpcResponseBody<T>\n : T extends Query\n ? XrpcResponseBody<T>\n : never\n >\n public async call(\n ns: Main<Action> | Main<Procedure> | Main<Query>,\n arg?: LexValue | Params,\n options: ActionOptions = {},\n ): Promise<unknown> {\n const method = getMain(ns)\n\n if (typeof method === 'function') {\n return method(this, arg, options)\n }\n\n if (method instanceof Procedure) {\n const result = await this.xrpc(method, { ...options, body: arg as any })\n return result.body\n } else if (method instanceof Query) {\n const result = await this.xrpc(method, { ...options, params: arg as any })\n return result.body\n } else {\n throw new TypeError('Invalid lexicon')\n }\n }\n\n /**\n * Creates a new record with full type safety based on the schema.\n *\n * @param ns - The record schema definition\n * @param input - The record data (without `$type`, which is added automatically)\n * @param options - Create options including rkey (required for some record types)\n * @returns The create output including URI and CID\n *\n * @example Creating a post\n * ```typescript\n * const result = await client.create(app.bsky.feed.post, {\n * text: 'Hello, world!',\n * createdAt: new Date().toISOString()\n * })\n * console.log(result.uri)\n * ```\n *\n * @example Creating a record with explicit rkey\n * ```typescript\n * const result = await client.create(app.bsky.actor.profile, {\n * displayName: 'Alice'\n * }, { rkey: 'self' })\n * ```\n *\n * @see {@link createRecord} for a lower-level method that returns the raw response without schema validation\n */\n public async create<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends CreateOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T> = {} as CreateOptions<T>,\n ): Promise<CreateOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input) as TypedLexMap<NsidString>\n if (options?.validateRequest) schema.validate(record)\n const rkey = options.rkey ?? getDefaultRecordKey(schema)\n if (rkey !== undefined) schema.keySchema.assert(rkey)\n const response = await this.createRecord(record, rkey, options)\n return response.body\n }\n\n /**\n * Deletes a record with type-safe options.\n *\n * @param ns - The record schema definition\n * @param options - Delete options (rkey required for non-literal keys)\n * @returns The delete output\n *\n * @see {@link deleteRecord} for a lower-level method that returns the raw response without schema validation\n */\n public async delete<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends DeleteOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Main<T>,\n options?: DeleteOptions<T>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Main<T>,\n options: DeleteOptions<T> = {} as DeleteOptions<T>,\n ): Promise<DeleteOutput> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.deleteRecord(schema.$type, rkey, options)\n return response.body\n }\n\n /**\n * Retrieves a record with type-safe validation.\n *\n * @param ns - The record schema definition\n * @param options - Get options (rkey required for non-literal keys)\n * @returns The record data validated against the schema\n *\n * @example\n * ```typescript\n * const profile = await client.get(app.bsky.actor.profile)\n * // profile.value is typed as app.bsky.actor.profile.Record\n * console.log(profile.value.displayName)\n * ```\n *\n * @see {@link getRecord} for a lower-level method that returns the raw record without schema validation\n */\n public async get<const T extends RecordSchema>(\n ns: T['key'] extends `literal:${string}`\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Main<T>,\n options: GetOptions<T>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Main<T>,\n options: GetOptions<T> = {} as GetOptions<T>,\n ): Promise<GetOutput<T>> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.getRecord(schema.$type, rkey, options)\n const value = schema.validate(response.body.value)\n return { ...response.body, value }\n }\n\n /**\n * Creates or updates a record with full type safety.\n *\n * @param ns - The record schema definition\n * @param input - The record data\n * @param options - Put options (rkey required for non-literal keys)\n * @returns The put output including URI and CID\n *\n * @example Creating a new record\n * ```typescript\n * const result = await client.put(app.bsky.feed.post, {\n * text: 'Hello, world!',\n * createdAt: new Date().toISOString()\n * })\n * console.log(result.uri)\n * ```\n *\n * @example Updating an existing record with explicit rkey\n * ```typescript\n * const result = await client.put(app.bsky.actor.profile, {\n * displayName: 'Alice'\n * }, { rkey: 'self' })\n * ```\n *\n * @see {@link putRecord} for a lower-level method that returns the raw record without schema validation\n */\n public async put<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends PutOptions<T>\n ? Main<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Main<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T> = {} as PutOptions<T>,\n ): Promise<PutOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input) as TypedLexMap<NsidString>\n if (options?.validateRequest) schema.validate(record)\n const rkey = options.rkey ?? getLiteralRecordKey(schema)\n const response = await this.putRecord(record, rkey, options)\n return response.body\n }\n\n /**\n * Lists records with type-safe validation and separation of valid/invalid records.\n *\n * @param ns - The record schema definition\n * @param options - List options\n * @returns Records validated against the schema, with invalid records included as LexMap\n *\n * @example\n * ```typescript\n * const result = await client.list(app.bsky.feed.post, { limit: 100 })\n * for (const record of result.records) {\n * if (record.valid) {\n * record.value // Fully typed\n * } else {\n * record.value // Invalid record, typed as LexMap\n * }\n * }\n * ```\n *\n * @see {@link listRecords} for a lower-level method that returns the raw records without schema validation\n */\n async list<const T extends RecordSchema>(\n ns: Main<T>,\n options?: ListOptions,\n ): Promise<ListOutput<T>> {\n const schema = getMain(ns)\n const { body } = await this.listRecords(schema.$type, options)\n const records = body.records.map(processListRecord, schema)\n return { ...body, records }\n }\n\n /**\n * Asynchronously iterates over all records in a collection, handling\n * pagination automatically.\n *\n * @param ns - The record schema definition\n * @param options - List options including limit and cursor\n * @returns An async generator yielding each record validated against the schema\n *\n * @see {@link list} for a method that returns a single page of records\n * @see {@link listRecords} for a lower-level method that returns raw records without schema validation\n */\n async *listAll<const T extends RecordSchema>(\n ns: Main<T>,\n { maxRetries = 3, ...options }: ListOptions = {},\n ): AsyncGenerator<ListRecordItem<Infer<T>>, void, unknown> {\n const schema = getMain(ns)\n\n do {\n throwIfAborted(options.signal)\n\n const { body } = await this.listRecords(schema.$type, {\n ...options,\n maxRetries,\n })\n\n // We don't use this.list() here so that we can lazily process records as\n // they come in, rather than mapping and yielding the entire page at once.\n for (const record of body.records) {\n yield processListRecord.call(schema, record)\n }\n\n // If the server returns the same cursor, we may be in a loop. Stop\n // iteration.\n if (body.cursor && body.cursor === options.cursor) {\n return\n }\n\n options.cursor = body.cursor\n } while (options.cursor)\n }\n}\n\nfunction processListRecord<T extends RecordSchema>(\n this: T,\n record: ListRecordsRecord,\n): ListRecordItem<Infer<T>> {\n const result = this.safeValidate(record.value)\n if (result.success) {\n return { ...record, valid: true, value: result.value }\n } else {\n return { ...record, valid: false }\n }\n}\n"]}
package/dist/util.d.ts CHANGED
@@ -77,6 +77,11 @@ export type RecordKeyOptions<T extends RecordSchema, AlsoOptionalWhenRecordKeyIs
77
77
  export declare function getDefaultRecordKey<const T extends RecordSchema>(schema: T): undefined | InferRecordKey<T>;
78
78
  export declare function getLiteralRecordKey<const T extends RecordSchema>(schema: T): InferRecordKey<T>;
79
79
  export declare function mergeHeaders(defaultHeaders: HeadersInit, requestHeaders: HeadersInit): Headers;
80
+ /**
81
+ * Uses the native `AbortSignal.throwIfAborted()` when available, falling back
82
+ * for older implementations such as React Native's `abort-controller`.
83
+ */
84
+ export declare function throwIfAborted(signal?: AbortSignal): void;
80
85
  export declare function wait(ms: number, { signal }?: {
81
86
  signal?: AbortSignal;
82
87
  }): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,YAAY,EACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpD,KAAK,WAAW,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAExD,MAAM,MAAM,YAAY,CACtB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IACzC,SAAS,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,SAAS,GAAG,EAAE,CAAC,GAC5D,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,GACjD,QAAQ,CAAA;AAEZ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,IAAI,CAClB,EAAE,EAAE,MAAM,EACV,EAAE,MAAM,EAAE,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACxC,OAAO,CAAC,IAAI,CAAC,CAsBf;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1C"}
package/dist/util.js CHANGED
@@ -164,9 +164,30 @@ export function mergeHeaders(defaultHeaders, requestHeaders) {
164
164
  }
165
165
  return result;
166
166
  }
167
+ function getAbortReason(signal) {
168
+ if ('reason' in signal)
169
+ return signal.reason;
170
+ return typeof DOMException !== 'undefined'
171
+ ? new DOMException('Aborted', 'AbortError')
172
+ : new Error('Aborted');
173
+ }
174
+ /**
175
+ * Uses the native `AbortSignal.throwIfAborted()` when available, falling back
176
+ * for older implementations such as React Native's `abort-controller`.
177
+ */
178
+ export function throwIfAborted(signal) {
179
+ if (!signal)
180
+ return;
181
+ if (typeof signal.throwIfAborted === 'function') {
182
+ signal.throwIfAborted();
183
+ return;
184
+ }
185
+ if (signal.aborted)
186
+ throw getAbortReason(signal);
187
+ }
167
188
  export function wait(ms, { signal } = {}) {
168
189
  return new Promise((resolve, reject) => {
169
- signal?.throwIfAborted();
190
+ throwIfAborted(signal);
170
191
  const cleanup = () => {
171
192
  clearTimeout(timeout);
172
193
  signal?.removeEventListener('abort', onAbort);
@@ -177,13 +198,8 @@ export function wait(ms, { signal } = {}) {
177
198
  }, ms);
178
199
  const onAbort = () => {
179
200
  cleanup();
180
- reject(
181
- // @NOTE the signal exists, and the reason should be set at this point.
182
- signal?.reason ??
183
- // React Native does not have DOMException
184
- (typeof DOMException !== 'undefined'
185
- ? new DOMException('Aborted', 'AbortError')
186
- : new Error('Aborted')));
201
+ // @NOTE the signal exists because this listener came from it.
202
+ reject(getAbortReason(signal));
187
203
  };
188
204
  signal?.addEventListener('abort', onAbort);
189
205
  });
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["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C,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACxB,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,EAAU,EACV,EAAE,MAAM,EAAE,GAA6B,EAAE;IAEzC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,EAAE,cAAc,EAAE,CAAA;QAExB,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,YAAY,CAAC,OAAO,CAAC,CAAA;YACrB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC/C,CAAC,CAAA;QAED,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9B,OAAO,EAAE,CAAA;YACT,OAAO,EAAE,CAAA;QACX,CAAC,EAAE,EAAE,CAAC,CAAA;QAEN,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,OAAO,EAAE,CAAA;YACT,MAAM;YACJ,uEAAuE;YACvE,MAAM,EAAE,MAAM;gBACZ,0CAA0C;gBAC1C,CAAC,OAAO,YAAY,KAAK,WAAW;oBAClC,CAAC,CAAC,IAAI,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC;oBAC3C,CAAC,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAC5B,CAAA;QACH,CAAC,CAAA;QAED,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,KAAa;IAChC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAA;AACrB,CAAC","sourcesContent":["import type {\n InferRecordKey,\n LexiconRecordKey,\n RecordSchema,\n} from '@atproto/lex-schema'\nimport type { DidString, Service } from './types.ts'\n\ntype NonReadonly<T> = { -readonly [K in keyof T]: T[K] }\n\nexport type WithDefaults<\n TOptions extends Record<string, unknown>,\n TDefaults extends Record<string, unknown>[],\n> = TDefaults extends [infer First, ...infer Rest extends any[]]\n ? TOptions & WithDefaults<NonReadonly<First>, Rest>\n : TOptions\n\nexport function applyDefaults<\n TOptions extends Readonly<Record<string, unknown>>,\n TDefaults extends Readonly<Record<string, unknown>>[],\n>(\n options: TOptions,\n ...defaults: TDefaults\n): WithDefaults<TOptions, TDefaults> {\n const combined: Record<string, unknown> = { ...options }\n\n // @NOTE We make sure that options with an explicit `undefined` value get the\n // default, since spreading doesn't override with `undefined`. When multiple\n // defaults define the same key, the first defined value wins.\n for (const def of defaults) {\n for (const key of Object.keys(def) as (keyof typeof def)[]) {\n if (combined[key] === undefined) {\n combined[key] = def[key]\n }\n }\n }\n\n return combined as WithDefaults<TOptions, TDefaults>\n}\n\n/**\n * Type guard to check if a value is {@link Blob}-like.\n *\n * Handles both native Blobs and polyfilled Blob implementations\n * (e.g., fetch-blob from node-fetch).\n *\n * @param value - The value to check\n * @returns `true` if the value is a Blob or Blob-like object\n */\nexport function isBlobLike(value: unknown): value is Blob {\n if (value == null) return false\n if (typeof value !== 'object') return false\n if (typeof Blob === 'function' && value instanceof Blob) return true\n\n // Support for Blobs provided by libraries that don't use the native Blob\n // (e.g. fetch-blob from node-fetch).\n // https://github.com/node-fetch/fetch-blob/blob/a1a182e5978811407bef4ea1632b517567dda01f/index.js#L233-L244\n\n const tag = (value as any)[Symbol.toStringTag]\n if (tag === 'Blob' || tag === 'File') {\n return 'stream' in value && typeof value.stream === 'function'\n }\n\n return false\n}\n\nexport function isAsyncIterable<T>(\n value: T,\n): value is unknown extends T\n ? T & AsyncIterable<unknown>\n : Extract<T, AsyncIterable<any>> {\n return (\n value != null && typeof (value as any)[Symbol.asyncIterator] === 'function'\n )\n}\n\nexport function asUint8ArrayArrayBuffer(\n bytes: Uint8Array,\n): Uint8Array<ArrayBuffer> {\n // If the Uint8Array is already backed by a non-shared ArrayBuffer, we can use\n // it directly.\n if (bytes.buffer instanceof ArrayBuffer) {\n return bytes as Uint8Array<ArrayBuffer>\n }\n\n // Otherwise, we need to create a new ArrayBuffer and copy the data.\n return new Uint8Array(bytes)\n}\n\nexport type XrpcRequestHeadersOptions = {\n /**\n * Additional custom HTTP headers to include in the request.\n *\n * @note \"atproto-proxy\" and \"atproto-accept-labelers\" headers might change\n * depending on the `service` and `labelers` options, respectively, if they\n * are provided (which is always the case when using {@link Client.xrpc}).\n */\n headers?: HeadersInit\n\n /**\n * Labeler DIDs to request labels from for content moderation.\n *\n * When `undefined`, will default to the client instance's default. When\n * `null`, it will cause any existing `atproto-accept-labelers` header\n * (including one provided through the\n * {@link XrpcRequestHeadersOptions.headers} option) to be removed.\n */\n labelers?: null | Iterable<DidString>\n\n /**\n * Labeler DIDs to request labels from for content moderation. Values here\n * will always be applied with the \";redact\" suffix, which indicates that the\n * client is requesting that the labeler redact content that is deemed\n * inappropriate.\n */\n appLabelers?: null | Iterable<DidString>\n\n /**\n * Service proxy identifier for routing requests through a specific service.\n *\n * When `undefined`, will default to the client instance's default. When not\n * used against a client instance (e.g., when using the {@link xrpc} helper\n * function), the default is to not alter the `atproto-proxy` header (e.g. if\n * one is provided in the {@link XrpcRequestHeadersOptions.headers}).\n *\n * When defined (as either `null` or a string), it will override any\n * `atproto-proxy` header provided in the\n * {@link XrpcRequestHeadersOptions.headers} option.\n */\n service?: null | Service\n}\n\n/**\n * Builds HTTP headers for AT Protocol requests.\n *\n * Adds or removes the following headers based on the provided options:\n * - `atproto-proxy`: Service routing header (if service is specified)\n * - `atproto-accept-labelers`: Comma-separated list of labeler DIDs\n *\n * @see {@link XrpcRequestHeadersOptions}\n * @returns A new Headers object with AT Protocol headers added\n */\nexport function buildXrpcRequestHeaders({\n service,\n labelers,\n appLabelers,\n headers: headersInit,\n}: XrpcRequestHeadersOptions): Headers {\n const headers = new Headers(headersInit)\n\n // If provided, the \"service\" option overrides any existing \"atproto-proxy\"\n // header. If `null`, the header is removed entirely.\n if (service !== undefined) {\n if (service === null) {\n headers.delete('atproto-proxy')\n } else {\n headers.set('atproto-proxy', service)\n }\n }\n\n // Labelers are combined from the \"appLabelers\" and \"labelers\" options, as\n // well as any existing \"atproto-accept-labelers\" header. The \"appLabelers\"\n // are always added with the \";redact\" suffix, while the \"labelers\" are added\n // as-is. Existing labelers headers are not preserved if the \"labelers\" option\n // is explicitly set to null.\n const combinedLabelers = new Set<string>()\n\n if (appLabelers) {\n for (const labeler of appLabelers) {\n combinedLabelers.add(`${labeler};redact`)\n }\n }\n\n if (labelers) {\n for (const labeler of labelers) {\n combinedLabelers.add(labeler)\n }\n }\n\n if (labelers !== null) {\n const headersLabelers = headers.get('atproto-accept-labelers')\n if (headersLabelers) {\n for (const labeler of headersLabelers\n .split(',')\n .map(trim)\n .filter(Boolean)) {\n if (labeler) combinedLabelers.add(labeler)\n }\n }\n }\n\n if (combinedLabelers.size > 0) {\n headers.set(\n 'atproto-accept-labelers',\n Array.from(combinedLabelers).join(', '),\n )\n } else {\n headers.delete('atproto-accept-labelers')\n }\n\n return headers\n}\n\nexport function toReadableStream(\n data: AsyncIterable<Uint8Array>,\n): ReadableStream<Uint8Array> {\n // Use the native ReadableStream.from() if available.\n\n /* v8 ignore next -- @preserve */\n if ('from' in ReadableStream && typeof ReadableStream.from === 'function') {\n return ReadableStream.from(data)\n }\n\n /* v8 ignore next -- @preserve */\n return toReadableStreamPonyfill(data)\n}\n\nexport function toReadableStreamPonyfill(\n data: AsyncIterable<Uint8Array>,\n): ReadableStream<Uint8Array> {\n let iterator: AsyncIterator<Uint8Array> | undefined\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n iterator ??= data[Symbol.asyncIterator]()\n const result = await iterator!.next()\n if (result.done) controller.close()\n else controller.enqueue(result.value)\n } catch (err) {\n controller.error(err)\n iterator = undefined\n }\n },\n async cancel() {\n await iterator?.return?.()\n iterator = undefined\n },\n })\n}\n\nexport type RecordKeyOptions<\n T extends RecordSchema,\n AlsoOptionalWhenRecordKeyIs extends LexiconRecordKey = never,\n> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs\n ? { rkey?: InferRecordKey<T> }\n : { rkey: InferRecordKey<T> }\n\nexport function getDefaultRecordKey<const T extends RecordSchema>(\n schema: T,\n): undefined | InferRecordKey<T> {\n // Let the server generate the TID\n if (schema.key === 'tid') return undefined\n if (schema.key === 'any') return undefined\n\n return getLiteralRecordKey(schema)\n}\n\nexport function getLiteralRecordKey<const T extends RecordSchema>(\n schema: T,\n): InferRecordKey<T> {\n if (schema.key.startsWith('literal:')) {\n return schema.key.slice(8) as InferRecordKey<T>\n }\n\n throw new TypeError(\n `An \"rkey\" must be provided for record key type \"${schema.key}\" (${schema.$type})`,\n )\n}\n\nexport function mergeHeaders(\n defaultHeaders: HeadersInit,\n requestHeaders: HeadersInit,\n): Headers {\n // We don't want to alter the original Headers objects, so we create a new one\n const result = new Headers(defaultHeaders)\n\n const overrides =\n requestHeaders instanceof Headers\n ? requestHeaders\n : new Headers(requestHeaders)\n\n for (const [key, value] of overrides.entries()) {\n result.set(key, value)\n }\n\n return result\n}\n\nexport function wait(\n ms: number,\n { signal }: { signal?: AbortSignal } = {},\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n signal?.throwIfAborted()\n\n const cleanup = () => {\n clearTimeout(timeout)\n signal?.removeEventListener('abort', onAbort)\n }\n\n const timeout = setTimeout(() => {\n cleanup()\n resolve()\n }, ms)\n\n const onAbort = () => {\n cleanup()\n reject(\n // @NOTE the signal exists, and the reason should be set at this point.\n signal?.reason ??\n // React Native does not have DOMException\n (typeof DOMException !== 'undefined'\n ? new DOMException('Aborted', 'AbortError')\n : new Error('Aborted')),\n )\n }\n\n signal?.addEventListener('abort', onAbort)\n })\n}\n\nexport function trim(value: string): string {\n return value.trim()\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAgBA,MAAM,UAAU,aAAa,CAI3B,OAAiB,EACjB,GAAG,QAAmB;IAEtB,MAAM,QAAQ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,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,KAAa;IAChC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAA;AACrB,CAAC","sourcesContent":["import type {\n InferRecordKey,\n LexiconRecordKey,\n RecordSchema,\n} from '@atproto/lex-schema'\nimport type { DidString, Service } from './types.ts'\n\ntype NonReadonly<T> = { -readonly [K in keyof T]: T[K] }\n\nexport type WithDefaults<\n TOptions extends Record<string, unknown>,\n TDefaults extends Record<string, unknown>[],\n> = TDefaults extends [infer First, ...infer Rest extends any[]]\n ? TOptions & WithDefaults<NonReadonly<First>, Rest>\n : TOptions\n\nexport function applyDefaults<\n TOptions extends Readonly<Record<string, unknown>>,\n TDefaults extends Readonly<Record<string, unknown>>[],\n>(\n options: TOptions,\n ...defaults: TDefaults\n): WithDefaults<TOptions, TDefaults> {\n const combined: Record<string, unknown> = { ...options }\n\n // @NOTE We make sure that options with an explicit `undefined` value get the\n // default, since spreading doesn't override with `undefined`. When multiple\n // defaults define the same key, the first defined value wins.\n for (const def of defaults) {\n for (const key of Object.keys(def) as (keyof typeof def)[]) {\n if (combined[key] === undefined) {\n combined[key] = def[key]\n }\n }\n }\n\n return combined as WithDefaults<TOptions, TDefaults>\n}\n\n/**\n * Type guard to check if a value is {@link Blob}-like.\n *\n * Handles both native Blobs and polyfilled Blob implementations\n * (e.g., fetch-blob from node-fetch).\n *\n * @param value - The value to check\n * @returns `true` if the value is a Blob or Blob-like object\n */\nexport function isBlobLike(value: unknown): value is Blob {\n if (value == null) return false\n if (typeof value !== 'object') return false\n if (typeof Blob === 'function' && value instanceof Blob) return true\n\n // Support for Blobs provided by libraries that don't use the native Blob\n // (e.g. fetch-blob from node-fetch).\n // https://github.com/node-fetch/fetch-blob/blob/a1a182e5978811407bef4ea1632b517567dda01f/index.js#L233-L244\n\n const tag = (value as any)[Symbol.toStringTag]\n if (tag === 'Blob' || tag === 'File') {\n return 'stream' in value && typeof value.stream === 'function'\n }\n\n return false\n}\n\nexport function isAsyncIterable<T>(\n value: T,\n): value is unknown extends T\n ? T & AsyncIterable<unknown>\n : Extract<T, AsyncIterable<any>> {\n return (\n value != null && typeof (value as any)[Symbol.asyncIterator] === 'function'\n )\n}\n\nexport function asUint8ArrayArrayBuffer(\n bytes: Uint8Array,\n): Uint8Array<ArrayBuffer> {\n // If the Uint8Array is already backed by a non-shared ArrayBuffer, we can use\n // it directly.\n if (bytes.buffer instanceof ArrayBuffer) {\n return bytes as Uint8Array<ArrayBuffer>\n }\n\n // Otherwise, we need to create a new ArrayBuffer and copy the data.\n return new Uint8Array(bytes)\n}\n\nexport type XrpcRequestHeadersOptions = {\n /**\n * Additional custom HTTP headers to include in the request.\n *\n * @note \"atproto-proxy\" and \"atproto-accept-labelers\" headers might change\n * depending on the `service` and `labelers` options, respectively, if they\n * are provided (which is always the case when using {@link Client.xrpc}).\n */\n headers?: HeadersInit\n\n /**\n * Labeler DIDs to request labels from for content moderation.\n *\n * When `undefined`, will default to the client instance's default. When\n * `null`, it will cause any existing `atproto-accept-labelers` header\n * (including one provided through the\n * {@link XrpcRequestHeadersOptions.headers} option) to be removed.\n */\n labelers?: null | Iterable<DidString>\n\n /**\n * Labeler DIDs to request labels from for content moderation. Values here\n * will always be applied with the \";redact\" suffix, which indicates that the\n * client is requesting that the labeler redact content that is deemed\n * inappropriate.\n */\n appLabelers?: null | Iterable<DidString>\n\n /**\n * Service proxy identifier for routing requests through a specific service.\n *\n * When `undefined`, will default to the client instance's default. When not\n * used against a client instance (e.g., when using the {@link xrpc} helper\n * function), the default is to not alter the `atproto-proxy` header (e.g. if\n * one is provided in the {@link XrpcRequestHeadersOptions.headers}).\n *\n * When defined (as either `null` or a string), it will override any\n * `atproto-proxy` header provided in the\n * {@link XrpcRequestHeadersOptions.headers} option.\n */\n service?: null | Service\n}\n\n/**\n * Builds HTTP headers for AT Protocol requests.\n *\n * Adds or removes the following headers based on the provided options:\n * - `atproto-proxy`: Service routing header (if service is specified)\n * - `atproto-accept-labelers`: Comma-separated list of labeler DIDs\n *\n * @see {@link XrpcRequestHeadersOptions}\n * @returns A new Headers object with AT Protocol headers added\n */\nexport function buildXrpcRequestHeaders({\n service,\n labelers,\n appLabelers,\n headers: headersInit,\n}: XrpcRequestHeadersOptions): Headers {\n const headers = new Headers(headersInit)\n\n // If provided, the \"service\" option overrides any existing \"atproto-proxy\"\n // header. If `null`, the header is removed entirely.\n if (service !== undefined) {\n if (service === null) {\n headers.delete('atproto-proxy')\n } else {\n headers.set('atproto-proxy', service)\n }\n }\n\n // Labelers are combined from the \"appLabelers\" and \"labelers\" options, as\n // well as any existing \"atproto-accept-labelers\" header. The \"appLabelers\"\n // are always added with the \";redact\" suffix, while the \"labelers\" are added\n // as-is. Existing labelers headers are not preserved if the \"labelers\" option\n // is explicitly set to null.\n const combinedLabelers = new Set<string>()\n\n if (appLabelers) {\n for (const labeler of appLabelers) {\n combinedLabelers.add(`${labeler};redact`)\n }\n }\n\n if (labelers) {\n for (const labeler of labelers) {\n combinedLabelers.add(labeler)\n }\n }\n\n if (labelers !== null) {\n const headersLabelers = headers.get('atproto-accept-labelers')\n if (headersLabelers) {\n for (const labeler of headersLabelers\n .split(',')\n .map(trim)\n .filter(Boolean)) {\n if (labeler) combinedLabelers.add(labeler)\n }\n }\n }\n\n if (combinedLabelers.size > 0) {\n headers.set(\n 'atproto-accept-labelers',\n Array.from(combinedLabelers).join(', '),\n )\n } else {\n headers.delete('atproto-accept-labelers')\n }\n\n return headers\n}\n\nexport function toReadableStream(\n data: AsyncIterable<Uint8Array>,\n): ReadableStream<Uint8Array> {\n // Use the native ReadableStream.from() if available.\n\n /* v8 ignore next -- @preserve */\n if ('from' in ReadableStream && typeof ReadableStream.from === 'function') {\n return ReadableStream.from(data)\n }\n\n /* v8 ignore next -- @preserve */\n return toReadableStreamPonyfill(data)\n}\n\nexport function toReadableStreamPonyfill(\n data: AsyncIterable<Uint8Array>,\n): ReadableStream<Uint8Array> {\n let iterator: AsyncIterator<Uint8Array> | undefined\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n iterator ??= data[Symbol.asyncIterator]()\n const result = await iterator!.next()\n if (result.done) controller.close()\n else controller.enqueue(result.value)\n } catch (err) {\n controller.error(err)\n iterator = undefined\n }\n },\n async cancel() {\n await iterator?.return?.()\n iterator = undefined\n },\n })\n}\n\nexport type RecordKeyOptions<\n T extends RecordSchema,\n AlsoOptionalWhenRecordKeyIs extends LexiconRecordKey = never,\n> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs\n ? { rkey?: InferRecordKey<T> }\n : { rkey: InferRecordKey<T> }\n\nexport function getDefaultRecordKey<const T extends RecordSchema>(\n schema: T,\n): undefined | InferRecordKey<T> {\n // Let the server generate the TID\n if (schema.key === 'tid') return undefined\n if (schema.key === 'any') return undefined\n\n return getLiteralRecordKey(schema)\n}\n\nexport function getLiteralRecordKey<const T extends RecordSchema>(\n schema: T,\n): InferRecordKey<T> {\n if (schema.key.startsWith('literal:')) {\n return schema.key.slice(8) as InferRecordKey<T>\n }\n\n throw new TypeError(\n `An \"rkey\" must be provided for record key type \"${schema.key}\" (${schema.$type})`,\n )\n}\n\nexport function mergeHeaders(\n defaultHeaders: HeadersInit,\n requestHeaders: HeadersInit,\n): Headers {\n // We don't want to alter the original Headers objects, so we create a new one\n const result = new Headers(defaultHeaders)\n\n const overrides =\n requestHeaders instanceof Headers\n ? requestHeaders\n : new Headers(requestHeaders)\n\n for (const [key, value] of overrides.entries()) {\n result.set(key, value)\n }\n\n return result\n}\n\nfunction getAbortReason(signal: AbortSignal): unknown {\n if ('reason' in signal) return signal.reason\n return typeof DOMException !== 'undefined'\n ? new DOMException('Aborted', 'AbortError')\n : new Error('Aborted')\n}\n\n/**\n * Uses the native `AbortSignal.throwIfAborted()` when available, falling back\n * for older implementations such as React Native's `abort-controller`.\n */\nexport function throwIfAborted(signal?: AbortSignal): void {\n if (!signal) return\n if (typeof signal.throwIfAborted === 'function') {\n signal.throwIfAborted()\n return\n }\n if (signal.aborted) throw getAbortReason(signal)\n}\n\nexport function wait(\n ms: number,\n { signal }: { signal?: AbortSignal } = {},\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n throwIfAborted(signal)\n\n const cleanup = () => {\n clearTimeout(timeout)\n signal?.removeEventListener('abort', onAbort)\n }\n\n const timeout = setTimeout(() => {\n cleanup()\n resolve()\n }, ms)\n\n const onAbort = () => {\n cleanup()\n // @NOTE the signal exists because this listener came from it.\n reject(getAbortReason(signal!))\n }\n\n signal?.addEventListener('abort', onAbort)\n })\n}\n\nexport function trim(value: string): string {\n return value.trim()\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"xrpc.d.ts","sourceRoot":"","sources":["../src/xrpc.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,IAAI,EAET,KAAK,MAAM,EAEX,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,YAAY,EAElB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAA;AAU1D;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,YAAY,IACtE,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAA;AAG7B,KAAK,wBAAwB,CAAC,CAAC,SAAS,MAAM,IAC5C,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG;IAAE,MAAM,CA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C,CAAC,CAAC,GACtB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAsOzB;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAgB5D;AAED,MAAM,MAAM,YAAY,GAAG;IACzB;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAA;IACvE;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA"}
package/dist/xrpc.js CHANGED
@@ -4,7 +4,7 @@ import { getMain, } from '@atproto/lex-schema';
4
4
  import { buildAgent } from './agent.js';
5
5
  import { XrpcFetchError, XrpcResponseError, asXrpcFailure } from './errors.js';
6
6
  import { XrpcResponse } from './response.js';
7
- import { asUint8ArrayArrayBuffer, buildXrpcRequestHeaders, isAsyncIterable, isBlobLike, toReadableStream, wait, } from './util.js';
7
+ import { asUint8ArrayArrayBuffer, buildXrpcRequestHeaders, isAsyncIterable, isBlobLike, throwIfAborted, toReadableStream, wait, } from './util.js';
8
8
  export async function xrpc(agentOpts, ns, options = {}) {
9
9
  const response = await xrpcSafe(agentOpts, ns, options);
10
10
  if (response.success)
@@ -15,7 +15,7 @@ export async function xrpc(agentOpts, ns, options = {}) {
15
15
  export async function xrpcSafe(agentOpts, ns, options = {}) {
16
16
  const method = getMain(ns);
17
17
  for (let counter = 1;; counter++) {
18
- options.signal?.throwIfAborted();
18
+ throwIfAborted(options.signal);
19
19
  try {
20
20
  const agent = buildAgent(agentOpts);
21
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,gBAAgB,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACrD,IAAI,QAAQ,GAAG,CAAC;YAAE,OAAO,QAAQ,CAAA;IACnC,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA,CAAC,QAAQ;IACxD,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACrD,IAAI,QAAQ,GAAG,CAAC;YAAE,OAAO,QAAQ,CAAA;IACnC,CAAC;AACH,CAAC","sourcesContent":["import type { LexValue } from '@atproto/lex-data'\nimport { isLexScalar, isPlainObject } from '@atproto/lex-data'\nimport { lexStringify } from '@atproto/lex-json'\nimport {\n type InferInput,\n type InferPayload,\n type Main,\n type NsidString,\n type Params,\n type Payload,\n type Procedure,\n type Query,\n type Restricted,\n type Subscription,\n getMain,\n} from '@atproto/lex-schema'\nimport type { Agent, AgentOptions } from './agent.js'\nimport { buildAgent } from './agent.js'\nimport type { XrpcFailure } from './errors.js'\nimport { XrpcFetchError, XrpcResponseError, asXrpcFailure } from './errors.js'\nimport type { XrpcResponseOptions } from './response.js'\nimport { XrpcResponse } from './response.js'\nimport type { BinaryBodyInit } from './types.js'\nimport type { XrpcRequestHeadersOptions } from './util.js'\nimport {\n asUint8ArrayArrayBuffer,\n buildXrpcRequestHeaders,\n isAsyncIterable,\n isBlobLike,\n toReadableStream,\n wait,\n} from './util.js'\n\n/**\n * The query/path parameters type for an XRPC method, inferred from its schema.\n *\n * @typeParam M - The XRPC method type (Procedure, Query, or Subscription)\n */\nexport type XrpcRequestParams<M extends Procedure | Query | Subscription> =\n InferInput<M['parameters']>\n\n// If all params are optional, allow omitting the params object\ntype XrpcRequestParamsOptions<P extends Params> =\n NonNullable<unknown> extends P ? { params?: P } : { params: P }\n\ntype XrpcRequestPayload<M extends Procedure | Query> = M extends Procedure\n ? InferPayload<M['input'], BinaryBodyInit>\n : undefined\n\ntype XrpcRequestPayloadOptions<TPayload> = TPayload extends {\n body: infer B\n encoding: infer E\n}\n ? {\n body: B\n\n /**\n * mime type hint for binary bodies\n *\n * Only needed for endpoints that accept binary input (e.g. file uploads)\n * when the body is a Blob-like object without a type (e.g. fetch-blob's\n * Blob). If the body is a Blob-like object with a type, that type will be\n * used as the content-type header instead of this option.\n *\n * @default \"application/octet-stream\"\n */\n encoding?: E\n }\n : { body?: undefined; encoding?: undefined }\n\n/**\n * Options for making an XRPC request, based on the method schema.\n *\n * Combines {@link XrpcRequestOptions} and {@link XrpcResponseOptions} with\n * method-specific params and body requirements. The type system ensures\n * required params/body are provided based on the method schema.\n *\n * @typeParam M - The XRPC method type (Procedure or Query)\n *\n * @example Query with params\n * ```typescript\n * const options: XrpcOptions<typeof app.bsky.feed.getTimeline.main> = {\n * params: { limit: 50 }\n * }\n * ```\n *\n * @example Procedure with body\n * ```typescript\n * const options: XrpcOptions<typeof com.atproto.repo.createRecord.main> = {\n * body: { repo: did, collection: 'app.bsky.feed.post', record: { ... } }\n * }\n * ```\n */\nexport type XrpcOptions<M extends Procedure | Query = Procedure | Query> =\n XrpcRequestOptions<M> & XrpcResponseOptions & RetryOptions\n\nexport type XrpcRequestOptions<\n M extends Procedure | Query = Procedure | Query,\n> = XrpcRequestProcessingOptions &\n XrpcRequestHeadersOptions &\n XrpcRequestPayloadOptions<XrpcRequestPayload<M>> &\n XrpcRequestParamsOptions<XrpcRequestParams<M>>\n\nexport type XrpcRequestProcessingOptions = {\n /**\n * AbortSignal to cancel the request.\n */\n signal?: AbortSignal\n\n /**\n * Whether to validate the request against the method's input schema. Enabling\n * this can help catch errors early but may have a performance cost. This\n * would typically only be set to `true` in development or debugging\n * scenarios.\n *\n * @default false\n */\n validateRequest?: boolean\n}\n\n/**\n * Makes an XRPC request and throws on failure.\n *\n * This is the low-level function for making XRPC calls.\n *\n * @param agent - The {@link Agent} to use for making the request\n * @param ns - The lexicon method definition\n * @param options - Request {@link XrpcOptions options} (params, body, headers, etc.)\n * @returns The successful {@link XrpcResponse}\n * @throws {XrpcFailure} When the request fails\n *\n * @example\n * ```typescript\n * const response = await xrpc('https://bsky.network', com.atproto.identity.resolveHandle, {\n * params: { handle: \"atproto.com\" }\n * })\n * ```\n *\n * @example\n * ```typescript\n * const response = await xrpc(agent, app.bsky.feed.getTimeline.main, {\n * params: { limit: 50 }\n * })\n * ```\n */\nexport async function xrpc<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n): Promise<XrpcResponse<M>>\nexport async function xrpc<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: Main<M>,\n options: XrpcOptions<M>,\n): Promise<XrpcResponse<M>>\nexport async function xrpc<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n): Promise<XrpcResponse<M>> {\n const response = await xrpcSafe<M>(agentOpts, ns, options)\n if (response.success) return response\n else throw response\n}\n\n/**\n * Union type representing either a successful response or a failure.\n *\n * Both {@link XrpcResponse} and {@link XrpcFailure} have a `success` property\n * that can be used to discriminate between them.\n *\n * @typeParam M - The XRPC method type\n */\nexport type XrpcResult<M extends Procedure | Query> =\n XrpcResponse<M> | XrpcFailure<M>\n\n/**\n * Makes an XRPC request without throwing on failure.\n *\n * Returns a discriminated union that can be checked via the `success` property.\n * This is useful for handling errors without try/catch blocks. This also allows\n * failure results to be typed with the method schema, which can provide better\n * type safety when handling errors (e.g. checking for specific error codes).\n *\n * @param agent - The {@link Agent} to use for making the request\n * @param ns - The lexicon method definition\n * @param options - Request {@link XrpcOptions options} (params, body, headers, etc.)\n * @returns Either a successful {@link XrpcResponse} or an {@link XrpcFailure}\n *\n * @example\n * ```typescript\n * const result = await xrpcSafe('https://example.com', app.bsky.actor.getProfile, {\n * params: { actor: 'alice.bsky.social' }\n * })\n *\n * if (result.success) {\n * console.log(result.body.displayName)\n * } else {\n * console.error('Request failed:', result.error)\n * }\n * ```\n */\nexport async function xrpcSafe<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n): Promise<XrpcResult<M>>\nexport async function xrpcSafe<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: Main<M>,\n options: XrpcOptions<M>,\n): Promise<XrpcResult<M>>\nexport async function xrpcSafe<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n): Promise<XrpcResult<M>> {\n const method: M = getMain(ns)\n\n for (let counter = 1; ; counter++) {\n options.signal?.throwIfAborted()\n try {\n const agent = buildAgent(agentOpts)\n const url = xrpcRequestUrl(method, options)\n const request = xrpcRequestInit(method, options)\n const response = await agent.fetchHandler(url, request).catch((err) => {\n const cause = extractFetchErrorCause(err)\n throw new XrpcFetchError(method, cause)\n })\n return await XrpcResponse.fromFetchResponse<M>(method, response, options)\n } catch (cause) {\n const failure = asXrpcFailure(method, cause)\n\n // Cannot retry a request with a consumable body\n if (\n options.body instanceof ReadableStream ||\n isAsyncIterable(options.body)\n ) {\n return failure\n }\n\n const waitTime = getRetryWaitTime(failure, options, counter)\n if (waitTime == null) {\n return failure\n }\n\n await wait(waitTime, options)\n }\n }\n}\n\nfunction xrpcRequestUrl<M extends Procedure | Query | Subscription>(\n method: M,\n options: { params?: Params },\n): `/xrpc/${NsidString}${'' | `?${string}`}` {\n const path = `/xrpc/${method.nsid}` as const\n\n // @NOTE param.toURLSearchParams() will always validate the params in order to\n // apply default values, so we can't disable it with options.validateRequest\n\n const queryString = method.parameters\n ?.toURLSearchParams(options.params ?? {})\n .toString()\n\n return queryString ? (`${path}?${queryString}` as const) : path\n}\n\nfunction xrpcRequestInit<T extends Procedure | Query>(\n schema: T,\n options: XrpcRequestProcessingOptions &\n XrpcRequestHeadersOptions &\n XrpcProcedureInputOptions & {\n encoding?: string\n },\n): RequestInit & { duplex?: 'half' } {\n const headers = buildXrpcRequestHeaders(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\ntype XrpcProcedureInputOptions = {\n body?: LexValue | BinaryBodyInit\n validateRequest?: boolean\n}\n\nfunction xrpcProcedureInput(\n method: Procedure,\n options: XrpcProcedureInputOptions,\n encodingHint?: string,\n): null | { body: BodyInit; encoding: string } {\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 (ArrayBuffer.isView(body)) {\n return buildPayload(input, asUint8ArrayArrayBuffer(body), encodingHint)\n } else if (\n body instanceof ArrayBuffer ||\n body instanceof ReadableStream\n ) {\n return buildPayload(input, body, encodingHint)\n } else if (isAsyncIterable(body)) {\n // @NOTE While fetch() does not allow SharedArrayBuffer-backed\n // Uint8Arrays as \"body\", it **does** allow using ReadableStreams made\n // of Uint8Arrays<SharedArrayBuffer> (tested on NodeJS 22) as \"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: Payload,\n body: undefined | BodyInit,\n encodingHint?: string,\n): null | { body: BodyInit; encoding: string } {\n if (schema.encoding === undefined) {\n if (body !== undefined) {\n throw new TypeError(`Endpoint expects no payload`)\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: Payload, 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\n/**\n * Extracts the root cause from an error, unwrapping common fetch-related errors\n * such as those from undici (Node's internal fetch implementation).\n *\n * @param err - The error to extract the root cause from\n * @returns The root cause error, or the original error if no specific pattern is matched\n * @remarks This is useful for getting more specific error information from fetch-related failures, especially in Node environments using undici.\n */\nexport function extractFetchErrorCause(err: unknown): unknown {\n // Unwrap the Network error from undici (i.e. Node's internal fetch() implementation)\n // https://github.com/nodejs/undici/blob/04cb77327f7ada95c2e5b67424cddcb22d7bf882/lib/web/fetch/index.js#L234-L239\n if (\n err instanceof TypeError &&\n err.message === 'fetch failed' &&\n err.cause !== undefined\n ) {\n return err.cause\n }\n\n // @TODO Add other unwrap patterns here as needed (e.g. for other fetch\n // implementations or common network libraries, like \"node:http\", or in other\n // environments like React Native, Deno, Bun, Browser, etc.)\n\n return err\n}\n\nexport type RetryOptions = {\n /**\n * Function to determine whether a request should be retried after a failure.\n *\n * @default `(failure) => failure.shouldRetry()`\n */\n retry?: (failure: XrpcFailure, context: { counter: number }) => boolean\n /**\n * Maximum number of retries to allow.\n *\n * @default 0 (no retries)\n */\n maxRetries?: number\n /**\n * Max number of milliseconds allow between retries\n *\n * @default 30000\n */\n maxRetryTimeout?: number\n /**\n * Initial number of milliseconds to wait before retrying for the first time.\n *\n * @default 500\n */\n minRetryTimeout?: number\n /**\n * Factor to multiply the timeout factor between retries.\n *\n * @default 2\n */\n retryTimeoutFactor?: number\n /**\n * Automatically infer timeout between retries based on header values (`Retry-After`, `RateLimit-Reset`).\n *\n * @default true\n */\n retryHeaders?: boolean\n}\n\nfunction getRetryWaitTime(\n failure: XrpcFailure,\n options: RetryOptions,\n counter: number,\n): number | undefined {\n const {\n retry,\n maxRetries = 0,\n minRetryTimeout = 500,\n maxRetryTimeout = 30_000,\n retryTimeoutFactor = 2,\n retryHeaders = true,\n } = options\n\n if (counter > maxRetries) {\n return undefined\n }\n\n const shouldRetry = retry\n ? retry(failure, { counter })\n : failure.shouldRetry()\n\n if (!shouldRetry) {\n return undefined\n }\n\n const waitTime =\n retryHeaders && failure instanceof XrpcResponseError\n ? getWaitTimeFromHeaders(failure.headers)\n : undefined\n\n return Math.min(\n maxRetryTimeout,\n waitTime ?? minRetryTimeout * retryTimeoutFactor ** (counter - 1),\n )\n}\n\nfunction getWaitTimeFromHeaders(headers: Headers): number | undefined {\n const retryAfterHeader = headers.get('retry-after')\n if (retryAfterHeader) {\n const waitTime = /^\\s*\\d+\\s*$/.test(retryAfterHeader)\n ? // Retry-After is in seconds\n Number(retryAfterHeader) * 1000\n : // Retry-After is an http-date\n new Date(retryAfterHeader).getTime() - Date.now()\n if (waitTime > 0) return waitTime\n }\n\n const resetsAt = headers.get('RateLimit-Reset') // epoch\n if (resetsAt) {\n const waitTime = Number(resetsAt) * 1000 - Date.now()\n if (waitTime > 0) return waitTime\n }\n}\n"]}
1
+ {"version":3,"file":"xrpc.js","sourceRoot":"","sources":["../src/xrpc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAWL,OAAO,GACR,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE9E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAG5C,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,eAAe,EACf,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,IAAI,GACL,MAAM,WAAW,CAAA;AA6HlB,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,SAA+B,E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MAAM,QAAQ,GACZ,YAAY,IAAI,OAAO,YAAY,iBAAiB;QAClD,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,OAAO,CAAC;QACzC,CAAC,CAAC,SAAS,CAAA;IAEf,OAAO,IAAI,CAAC,GAAG,CACb,eAAe,EACf,QAAQ,IAAI,eAAe,GAAG,kBAAkB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAClE,CAAA;AACH,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAgB;IAC9C,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IACnD,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC;YACnD,CAAC,CAAC,4BAA4B;gBAC5B,MAAM,CAAC,gBAAgB,CAAC,GAAG,IAAI;YACjC,CAAC,CAAC,8BAA8B;gBAC9B,IAAI,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACrD,IAAI,QAAQ,GAAG,CAAC;YAAE,OAAO,QAAQ,CAAA;IACnC,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA,CAAC,QAAQ;IACxD,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACrD,IAAI,QAAQ,GAAG,CAAC;YAAE,OAAO,QAAQ,CAAA;IACnC,CAAC;AACH,CAAC","sourcesContent":["import type { LexValue } from '@atproto/lex-data'\nimport { isLexScalar, isPlainObject } from '@atproto/lex-data'\nimport { lexStringify } from '@atproto/lex-json'\nimport {\n type InferInput,\n type InferPayload,\n type Main,\n type NsidString,\n type Params,\n type Payload,\n type Procedure,\n type Query,\n type Restricted,\n type Subscription,\n getMain,\n} from '@atproto/lex-schema'\nimport type { Agent, AgentOptions } from './agent.js'\nimport { buildAgent } from './agent.js'\nimport type { XrpcFailure } from './errors.js'\nimport { XrpcFetchError, XrpcResponseError, asXrpcFailure } from './errors.js'\nimport type { XrpcResponseOptions } from './response.js'\nimport { XrpcResponse } from './response.js'\nimport type { BinaryBodyInit } from './types.js'\nimport type { XrpcRequestHeadersOptions } from './util.js'\nimport {\n asUint8ArrayArrayBuffer,\n buildXrpcRequestHeaders,\n isAsyncIterable,\n isBlobLike,\n throwIfAborted,\n toReadableStream,\n wait,\n} from './util.js'\n\n/**\n * The query/path parameters type for an XRPC method, inferred from its schema.\n *\n * @typeParam M - The XRPC method type (Procedure, Query, or Subscription)\n */\nexport type XrpcRequestParams<M extends Procedure | Query | Subscription> =\n InferInput<M['parameters']>\n\n// If all params are optional, allow omitting the params object\ntype XrpcRequestParamsOptions<P extends Params> =\n NonNullable<unknown> extends P ? { params?: P } : { params: P }\n\ntype XrpcRequestPayload<M extends Procedure | Query> = M extends Procedure\n ? InferPayload<M['input'], BinaryBodyInit>\n : undefined\n\ntype XrpcRequestPayloadOptions<TPayload> = TPayload extends {\n body: infer B\n encoding: infer E\n}\n ? {\n body: B\n\n /**\n * mime type hint for binary bodies\n *\n * Only needed for endpoints that accept binary input (e.g. file uploads)\n * when the body is a Blob-like object without a type (e.g. fetch-blob's\n * Blob). If the body is a Blob-like object with a type, that type will be\n * used as the content-type header instead of this option.\n *\n * @default \"application/octet-stream\"\n */\n encoding?: E\n }\n : { body?: undefined; encoding?: undefined }\n\n/**\n * Options for making an XRPC request, based on the method schema.\n *\n * Combines {@link XrpcRequestOptions} and {@link XrpcResponseOptions} with\n * method-specific params and body requirements. The type system ensures\n * required params/body are provided based on the method schema.\n *\n * @typeParam M - The XRPC method type (Procedure or Query)\n *\n * @example Query with params\n * ```typescript\n * const options: XrpcOptions<typeof app.bsky.feed.getTimeline.main> = {\n * params: { limit: 50 }\n * }\n * ```\n *\n * @example Procedure with body\n * ```typescript\n * const options: XrpcOptions<typeof com.atproto.repo.createRecord.main> = {\n * body: { repo: did, collection: 'app.bsky.feed.post', record: { ... } }\n * }\n * ```\n */\nexport type XrpcOptions<M extends Procedure | Query = Procedure | Query> =\n XrpcRequestOptions<M> & XrpcResponseOptions & RetryOptions\n\nexport type XrpcRequestOptions<\n M extends Procedure | Query = Procedure | Query,\n> = XrpcRequestProcessingOptions &\n XrpcRequestHeadersOptions &\n XrpcRequestPayloadOptions<XrpcRequestPayload<M>> &\n XrpcRequestParamsOptions<XrpcRequestParams<M>>\n\nexport type XrpcRequestProcessingOptions = {\n /**\n * AbortSignal to cancel the request.\n */\n signal?: AbortSignal\n\n /**\n * Whether to validate the request against the method's input schema. Enabling\n * this can help catch errors early but may have a performance cost. This\n * would typically only be set to `true` in development or debugging\n * scenarios.\n *\n * @default false\n */\n validateRequest?: boolean\n}\n\n/**\n * Makes an XRPC request and throws on failure.\n *\n * This is the low-level function for making XRPC calls.\n *\n * @param agent - The {@link Agent} to use for making the request\n * @param ns - The lexicon method definition\n * @param options - Request {@link XrpcOptions options} (params, body, headers, etc.)\n * @returns The successful {@link XrpcResponse}\n * @throws {XrpcFailure} When the request fails\n *\n * @example\n * ```typescript\n * const response = await xrpc('https://bsky.network', com.atproto.identity.resolveHandle, {\n * params: { handle: \"atproto.com\" }\n * })\n * ```\n *\n * @example\n * ```typescript\n * const response = await xrpc(agent, app.bsky.feed.getTimeline.main, {\n * params: { limit: 50 }\n * })\n * ```\n */\nexport async function xrpc<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n): Promise<XrpcResponse<M>>\nexport async function xrpc<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: Main<M>,\n options: XrpcOptions<M>,\n): Promise<XrpcResponse<M>>\nexport async function xrpc<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n): Promise<XrpcResponse<M>> {\n const response = await xrpcSafe<M>(agentOpts, ns, options)\n if (response.success) return response\n else throw response\n}\n\n/**\n * Union type representing either a successful response or a failure.\n *\n * Both {@link XrpcResponse} and {@link XrpcFailure} have a `success` property\n * that can be used to discriminate between them.\n *\n * @typeParam M - The XRPC method type\n */\nexport type XrpcResult<M extends Procedure | Query> =\n XrpcResponse<M> | XrpcFailure<M>\n\n/**\n * Makes an XRPC request without throwing on failure.\n *\n * Returns a discriminated union that can be checked via the `success` property.\n * This is useful for handling errors without try/catch blocks. This also allows\n * failure results to be typed with the method schema, which can provide better\n * type safety when handling errors (e.g. checking for specific error codes).\n *\n * @param agent - The {@link Agent} to use for making the request\n * @param ns - The lexicon method definition\n * @param options - Request {@link XrpcOptions options} (params, body, headers, etc.)\n * @returns Either a successful {@link XrpcResponse} or an {@link XrpcFailure}\n *\n * @example\n * ```typescript\n * const result = await xrpcSafe('https://example.com', app.bsky.actor.getProfile, {\n * params: { actor: 'alice.bsky.social' }\n * })\n *\n * if (result.success) {\n * console.log(result.body.displayName)\n * } else {\n * console.error('Request failed:', result.error)\n * }\n * ```\n */\nexport async function xrpcSafe<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Main<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n): Promise<XrpcResult<M>>\nexport async function xrpcSafe<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: Main<M>,\n options: XrpcOptions<M>,\n): Promise<XrpcResult<M>>\nexport async function xrpcSafe<const M extends Query | Procedure>(\n agentOpts: Agent | AgentOptions,\n ns: Main<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n): Promise<XrpcResult<M>> {\n const method: M = getMain(ns)\n\n for (let counter = 1; ; counter++) {\n throwIfAborted(options.signal)\n try {\n const agent = buildAgent(agentOpts)\n const url = xrpcRequestUrl(method, options)\n const request = xrpcRequestInit(method, options)\n const response = await agent.fetchHandler(url, request).catch((err) => {\n const cause = extractFetchErrorCause(err)\n throw new XrpcFetchError(method, cause)\n })\n return await XrpcResponse.fromFetchResponse<M>(method, response, options)\n } catch (cause) {\n const failure = asXrpcFailure(method, cause)\n\n // Cannot retry a request with a consumable body\n if (\n options.body instanceof ReadableStream ||\n isAsyncIterable(options.body)\n ) {\n return failure\n }\n\n const waitTime = getRetryWaitTime(failure, options, counter)\n if (waitTime == null) {\n return failure\n }\n\n await wait(waitTime, options)\n }\n }\n}\n\nfunction xrpcRequestUrl<M extends Procedure | Query | Subscription>(\n method: M,\n options: { params?: Params },\n): `/xrpc/${NsidString}${'' | `?${string}`}` {\n const path = `/xrpc/${method.nsid}` as const\n\n // @NOTE param.toURLSearchParams() will always validate the params in order to\n // apply default values, so we can't disable it with options.validateRequest\n\n const queryString = method.parameters\n ?.toURLSearchParams(options.params ?? {})\n .toString()\n\n return queryString ? (`${path}?${queryString}` as const) : path\n}\n\nfunction xrpcRequestInit<T extends Procedure | Query>(\n schema: T,\n options: XrpcRequestProcessingOptions &\n XrpcRequestHeadersOptions &\n XrpcProcedureInputOptions & {\n encoding?: string\n },\n): RequestInit & { duplex?: 'half' } {\n const headers = buildXrpcRequestHeaders(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\ntype XrpcProcedureInputOptions = {\n body?: LexValue | BinaryBodyInit\n validateRequest?: boolean\n}\n\nfunction xrpcProcedureInput(\n method: Procedure,\n options: XrpcProcedureInputOptions,\n encodingHint?: string,\n): null | { body: BodyInit; encoding: string } {\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 (ArrayBuffer.isView(body)) {\n return buildPayload(input, asUint8ArrayArrayBuffer(body), encodingHint)\n } else if (\n body instanceof ArrayBuffer ||\n body instanceof ReadableStream\n ) {\n return buildPayload(input, body, encodingHint)\n } else if (isAsyncIterable(body)) {\n // @NOTE While fetch() does not allow SharedArrayBuffer-backed\n // Uint8Arrays as \"body\", it **does** allow using ReadableStreams made\n // of Uint8Arrays<SharedArrayBuffer> (tested on NodeJS 22) as \"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: Payload,\n body: undefined | BodyInit,\n encodingHint?: string,\n): null | { body: BodyInit; encoding: string } {\n if (schema.encoding === undefined) {\n if (body !== undefined) {\n throw new TypeError(`Endpoint expects no payload`)\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: Payload, 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\n/**\n * Extracts the root cause from an error, unwrapping common fetch-related errors\n * such as those from undici (Node's internal fetch implementation).\n *\n * @param err - The error to extract the root cause from\n * @returns The root cause error, or the original error if no specific pattern is matched\n * @remarks This is useful for getting more specific error information from fetch-related failures, especially in Node environments using undici.\n */\nexport function extractFetchErrorCause(err: unknown): unknown {\n // Unwrap the Network error from undici (i.e. Node's internal fetch() implementation)\n // https://github.com/nodejs/undici/blob/04cb77327f7ada95c2e5b67424cddcb22d7bf882/lib/web/fetch/index.js#L234-L239\n if (\n err instanceof TypeError &&\n err.message === 'fetch failed' &&\n err.cause !== undefined\n ) {\n return err.cause\n }\n\n // @TODO Add other unwrap patterns here as needed (e.g. for other fetch\n // implementations or common network libraries, like \"node:http\", or in other\n // environments like React Native, Deno, Bun, Browser, etc.)\n\n return err\n}\n\nexport type RetryOptions = {\n /**\n * Function to determine whether a request should be retried after a failure.\n *\n * @default `(failure) => failure.shouldRetry()`\n */\n retry?: (failure: XrpcFailure, context: { counter: number }) => boolean\n /**\n * Maximum number of retries to allow.\n *\n * @default 0 (no retries)\n */\n maxRetries?: number\n /**\n * Max number of milliseconds allow between retries\n *\n * @default 30000\n */\n maxRetryTimeout?: number\n /**\n * Initial number of milliseconds to wait before retrying for the first time.\n *\n * @default 500\n */\n minRetryTimeout?: number\n /**\n * Factor to multiply the timeout factor between retries.\n *\n * @default 2\n */\n retryTimeoutFactor?: number\n /**\n * Automatically infer timeout between retries based on header values (`Retry-After`, `RateLimit-Reset`).\n *\n * @default true\n */\n retryHeaders?: boolean\n}\n\nfunction getRetryWaitTime(\n failure: XrpcFailure,\n options: RetryOptions,\n counter: number,\n): number | undefined {\n const {\n retry,\n maxRetries = 0,\n minRetryTimeout = 500,\n maxRetryTimeout = 30_000,\n retryTimeoutFactor = 2,\n retryHeaders = true,\n } = options\n\n if (counter > maxRetries) {\n return undefined\n }\n\n const shouldRetry = retry\n ? retry(failure, { counter })\n : failure.shouldRetry()\n\n if (!shouldRetry) {\n return undefined\n }\n\n const waitTime =\n retryHeaders && failure instanceof XrpcResponseError\n ? getWaitTimeFromHeaders(failure.headers)\n : undefined\n\n return Math.min(\n maxRetryTimeout,\n waitTime ?? minRetryTimeout * retryTimeoutFactor ** (counter - 1),\n )\n}\n\nfunction getWaitTimeFromHeaders(headers: Headers): number | undefined {\n const retryAfterHeader = headers.get('retry-after')\n if (retryAfterHeader) {\n const waitTime = /^\\s*\\d+\\s*$/.test(retryAfterHeader)\n ? // Retry-After is in seconds\n Number(retryAfterHeader) * 1000\n : // Retry-After is an http-date\n new Date(retryAfterHeader).getTime() - Date.now()\n if (waitTime > 0) return waitTime\n }\n\n const resetsAt = headers.get('RateLimit-Reset') // epoch\n if (resetsAt) {\n const waitTime = Number(resetsAt) * 1000 - Date.now()\n if (waitTime > 0) return waitTime\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex-client",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "license": "MIT",
5
5
  "description": "HTTP client for interacting with Lexicon based APIs",
6
6
  "keywords": [
@@ -35,12 +35,12 @@
35
35
  "tslib": "^2.8.1",
36
36
  "@atproto/lex-data": "^0.1.7",
37
37
  "@atproto/lex-json": "^0.1.6",
38
- "@atproto/lex-schema": "^0.2.6"
38
+ "@atproto/lex-schema": "^0.2.7"
39
39
  },
40
40
  "devDependencies": {
41
41
  "vitest": "^4.1.10",
42
- "@atproto/lex-cbor": "^0.1.6",
43
- "@atproto/lex-builder": "^0.1.13"
42
+ "@atproto/lex-builder": "^0.1.15",
43
+ "@atproto/lex-cbor": "^0.1.6"
44
44
  },
45
45
  "scripts": {
46
46
  "codegen:lex": "node ./scripts/lex-build.js",