@atproto/lex-client 0.0.0-spaces-alpha-20260818021221

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/CHANGELOG.md +456 -0
  2. package/LICENSE.txt +7 -0
  3. package/README.md +19 -0
  4. package/dist/agent.d.ts +127 -0
  5. package/dist/agent.d.ts.map +1 -0
  6. package/dist/agent.js +41 -0
  7. package/dist/agent.js.map +1 -0
  8. package/dist/client.d.ts +685 -0
  9. package/dist/client.d.ts.map +1 -0
  10. package/dist/client.js +511 -0
  11. package/dist/client.js.map +1 -0
  12. package/dist/errors.d.ts +277 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +388 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/index.d.ts +7 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +7 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/lexicons/com/atproto/repo/applyWrites.d.ts +3 -0
  21. package/dist/lexicons/com/atproto/repo/applyWrites.d.ts.map +1 -0
  22. package/dist/lexicons/com/atproto/repo/applyWrites.defs.d.ts +103 -0
  23. package/dist/lexicons/com/atproto/repo/applyWrites.defs.d.ts.map +1 -0
  24. package/dist/lexicons/com/atproto/repo/applyWrites.defs.js +82 -0
  25. package/dist/lexicons/com/atproto/repo/applyWrites.defs.js.map +1 -0
  26. package/dist/lexicons/com/atproto/repo/applyWrites.js +6 -0
  27. package/dist/lexicons/com/atproto/repo/applyWrites.js.map +1 -0
  28. package/dist/lexicons/com/atproto/repo/createRecord.d.ts +3 -0
  29. package/dist/lexicons/com/atproto/repo/createRecord.d.ts.map +1 -0
  30. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +74 -0
  31. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -0
  32. package/dist/lexicons/com/atproto/repo/createRecord.defs.js +34 -0
  33. package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -0
  34. package/dist/lexicons/com/atproto/repo/createRecord.js +6 -0
  35. package/dist/lexicons/com/atproto/repo/createRecord.js.map +1 -0
  36. package/dist/lexicons/com/atproto/repo/defs.d.ts +2 -0
  37. package/dist/lexicons/com/atproto/repo/defs.d.ts.map +1 -0
  38. package/dist/lexicons/com/atproto/repo/defs.defs.d.ts +13 -0
  39. package/dist/lexicons/com/atproto/repo/defs.defs.d.ts.map +1 -0
  40. package/dist/lexicons/com/atproto/repo/defs.defs.js +13 -0
  41. package/dist/lexicons/com/atproto/repo/defs.defs.js.map +1 -0
  42. package/dist/lexicons/com/atproto/repo/defs.js +5 -0
  43. package/dist/lexicons/com/atproto/repo/defs.js.map +1 -0
  44. package/dist/lexicons/com/atproto/repo/deleteRecord.d.ts +3 -0
  45. package/dist/lexicons/com/atproto/repo/deleteRecord.d.ts.map +1 -0
  46. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +56 -0
  47. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -0
  48. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +29 -0
  49. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -0
  50. package/dist/lexicons/com/atproto/repo/deleteRecord.js +6 -0
  51. package/dist/lexicons/com/atproto/repo/deleteRecord.js.map +1 -0
  52. package/dist/lexicons/com/atproto/repo/getRecord.d.ts +3 -0
  53. package/dist/lexicons/com/atproto/repo/getRecord.d.ts.map +1 -0
  54. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +58 -0
  55. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -0
  56. package/dist/lexicons/com/atproto/repo/getRecord.defs.js +23 -0
  57. package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -0
  58. package/dist/lexicons/com/atproto/repo/getRecord.js +6 -0
  59. package/dist/lexicons/com/atproto/repo/getRecord.js.map +1 -0
  60. package/dist/lexicons/com/atproto/repo/listRecords.d.ts +3 -0
  61. package/dist/lexicons/com/atproto/repo/listRecords.d.ts.map +1 -0
  62. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +51 -0
  63. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -0
  64. package/dist/lexicons/com/atproto/repo/listRecords.defs.js +33 -0
  65. package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -0
  66. package/dist/lexicons/com/atproto/repo/listRecords.js +6 -0
  67. package/dist/lexicons/com/atproto/repo/listRecords.js.map +1 -0
  68. package/dist/lexicons/com/atproto/repo/putRecord.d.ts +3 -0
  69. package/dist/lexicons/com/atproto/repo/putRecord.d.ts.map +1 -0
  70. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +80 -0
  71. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -0
  72. package/dist/lexicons/com/atproto/repo/putRecord.defs.js +35 -0
  73. package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -0
  74. package/dist/lexicons/com/atproto/repo/putRecord.js +6 -0
  75. package/dist/lexicons/com/atproto/repo/putRecord.js.map +1 -0
  76. package/dist/lexicons/com/atproto/repo/uploadBlob.d.ts +3 -0
  77. package/dist/lexicons/com/atproto/repo/uploadBlob.d.ts.map +1 -0
  78. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +23 -0
  79. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -0
  80. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +17 -0
  81. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -0
  82. package/dist/lexicons/com/atproto/repo/uploadBlob.js +6 -0
  83. package/dist/lexicons/com/atproto/repo/uploadBlob.js.map +1 -0
  84. package/dist/lexicons/com/atproto/repo.d.ts +9 -0
  85. package/dist/lexicons/com/atproto/repo.d.ts.map +1 -0
  86. package/dist/lexicons/com/atproto/repo.js +12 -0
  87. package/dist/lexicons/com/atproto/repo.js.map +1 -0
  88. package/dist/lexicons/com/atproto/sync/getBlob.d.ts +3 -0
  89. package/dist/lexicons/com/atproto/sync/getBlob.d.ts.map +1 -0
  90. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts +30 -0
  91. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts.map +1 -0
  92. package/dist/lexicons/com/atproto/sync/getBlob.defs.js +23 -0
  93. package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -0
  94. package/dist/lexicons/com/atproto/sync/getBlob.js +6 -0
  95. package/dist/lexicons/com/atproto/sync/getBlob.js.map +1 -0
  96. package/dist/lexicons/com/atproto/sync.d.ts +2 -0
  97. package/dist/lexicons/com/atproto/sync.d.ts.map +1 -0
  98. package/dist/lexicons/com/atproto/sync.js +5 -0
  99. package/dist/lexicons/com/atproto/sync.js.map +1 -0
  100. package/dist/lexicons/com/atproto.d.ts +3 -0
  101. package/dist/lexicons/com/atproto.d.ts.map +1 -0
  102. package/dist/lexicons/com/atproto.js +6 -0
  103. package/dist/lexicons/com/atproto.js.map +1 -0
  104. package/dist/lexicons/com.d.ts +2 -0
  105. package/dist/lexicons/com.d.ts.map +1 -0
  106. package/dist/lexicons/com.js +5 -0
  107. package/dist/lexicons/com.js.map +1 -0
  108. package/dist/lexicons/index.d.ts +2 -0
  109. package/dist/lexicons/index.d.ts.map +1 -0
  110. package/dist/lexicons/index.js +5 -0
  111. package/dist/lexicons/index.js.map +1 -0
  112. package/dist/response.d.ts +124 -0
  113. package/dist/response.d.ts.map +1 -0
  114. package/dist/response.js +178 -0
  115. package/dist/response.js.map +1 -0
  116. package/dist/types.d.ts +54 -0
  117. package/dist/types.d.ts.map +1 -0
  118. package/dist/types.js +16 -0
  119. package/dist/types.js.map +1 -0
  120. package/dist/util.d.ts +85 -0
  121. package/dist/util.d.ts.map +1 -0
  122. package/dist/util.js +194 -0
  123. package/dist/util.js.map +1 -0
  124. package/dist/write-operation-builder.d.ts +19 -0
  125. package/dist/write-operation-builder.d.ts.map +1 -0
  126. package/dist/write-operation-builder.js +35 -0
  127. package/dist/write-operation-builder.js.map +1 -0
  128. package/dist/www-authenticate.d.ts +35 -0
  129. package/dist/www-authenticate.d.ts.map +1 -0
  130. package/dist/www-authenticate.js +54 -0
  131. package/dist/www-authenticate.js.map +1 -0
  132. package/dist/xrpc.d.ts +194 -0
  133. package/dist/xrpc.d.ts.map +1 -0
  134. package/dist/xrpc.js +235 -0
  135. package/dist/xrpc.js.map +1 -0
  136. package/package.json +51 -0
@@ -0,0 +1,685 @@
1
+ import type { LexMap, LexValue, TypedLexMap } from '@atproto/lex-data';
2
+ import type { AtIdentifierString, AtUriString, CidString, DidString, Infer, InferMethodInputBody, InferMethodOutputBody, InferRecordKey, LexiconRecordKey, Main, NsidString, Params, Restricted } from '@atproto/lex-schema';
3
+ import { Procedure, Query, RecordSchema } from '@atproto/lex-schema';
4
+ import type { Agent, AgentOptions } from './agent.js';
5
+ import type { XrpcFailure } from './errors.js';
6
+ import applyWrites from './lexicons/com/atproto/repo/applyWrites.js';
7
+ import createRecord from './lexicons/com/atproto/repo/createRecord.js';
8
+ import deleteRecord from './lexicons/com/atproto/repo/deleteRecord.js';
9
+ import getRecord from './lexicons/com/atproto/repo/getRecord.js';
10
+ import listRecords from './lexicons/com/atproto/repo/listRecords.js';
11
+ import putRecord from './lexicons/com/atproto/repo/putRecord.js';
12
+ import uploadBlob from './lexicons/com/atproto/repo/uploadBlob.js';
13
+ import getBlob from './lexicons/com/atproto/sync/getBlob.js';
14
+ import type { XrpcResponse, XrpcResponseBody, XrpcResponseOptions } from './response.js';
15
+ import { type BinaryBodyInit, type Service } from './types.js';
16
+ import { type RecordKeyOptions, type XrpcRequestHeadersOptions } from './util.js';
17
+ import { type WriteOperation, type WriteOperationCreateOptions, type WriteOperationDeleteOptions, WriteOperationHelper, type WriteOperationUpdateOptions, type WriteOperationsFactory } from './write-operation-builder.js';
18
+ import { type XrpcOptions, type XrpcRequestParams, type XrpcRequestProcessingOptions } from './xrpc.js';
19
+ export { type AtIdentifierString, type CidString, type DidString, type Infer, type InferMethodInputBody, type InferMethodOutputBody, type InferRecordKey, type LexMap, type LexValue, type LexiconRecordKey, type Main, type NsidString, type Params, Procedure, Query, RecordSchema, type Restricted, type TypedLexMap, type WriteOperation, type WriteOperationCreateOptions, type WriteOperationDeleteOptions, WriteOperationHelper, type WriteOperationUpdateOptions, type WriteOperationsFactory, };
20
+ /**
21
+ * Configuration options for creating a {@link Client}.
22
+ *
23
+ * @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}.
24
+ * @property {@link ClientOptions.service} - An optional service identifier (DID or URL) for routing requests with service proxying.
25
+ * @property {@link ClientOptions.headers} - Custom headers to include in all requests made by this client instance.
26
+ * @property {@link ClientOptions.validateRequest} - If true, validates request bodies against their lexicon schemas before sending. Defaults to false for performance.
27
+ * @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.
28
+ * @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.
29
+ *
30
+ * @see {@link XrpcRequestHeadersOptions}
31
+ * @see {@link XrpcRequestProcessingOptions}
32
+ * @see {@link XrpcResponseOptions}
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const options: ClientOptions = {
37
+ * labelers: ['did:plc:labeler1'],
38
+ * service: 'did:web:api.bsky.app#bsky_appview',
39
+ * headers: { 'X-Custom-Header': 'value' },
40
+ * validateRequest: false,
41
+ * validateResponse: true,
42
+ * strictResponseProcessing: false,
43
+ * }
44
+ * ```
45
+ */
46
+ export type ClientOptions = XrpcRequestHeadersOptions & Pick<XrpcRequestProcessingOptions, 'validateRequest'> & XrpcResponseOptions;
47
+ export type ActionOptions = {
48
+ /** AbortSignal to cancel the request. */
49
+ signal?: AbortSignal;
50
+ };
51
+ /**
52
+ * A composable action that can be invoked via {@link Client.call}.
53
+ *
54
+ * Actions provide a way to define custom operations that integrate with the
55
+ * Client's call interface, enabling type-safe, reusable business logic.
56
+ *
57
+ * @typeParam I - The input type for the action
58
+ * @typeParam O - The output type for the action
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const myAction: Action<{ userId: string }, { profile: Profile }> = async (client, input, options) => {
63
+ * const response = await client.xrpc(someMethod, { params: { actor: input.userId }, ...options })
64
+ * return { profile: response.body }
65
+ * }
66
+ * ```
67
+ */
68
+ export type Action<I = any, O = any> = (client: Client, input: I, options: ActionOptions) => O | Promise<O>;
69
+ /**
70
+ * Extracts the input type from an {@link Action}.
71
+ * @typeParam A - The Action type to extract from
72
+ */
73
+ export type InferActionInput<A extends Action> = A extends Action<infer I, any> ? I : never;
74
+ /**
75
+ * Extracts the output type from an {@link Action}.
76
+ * @typeParam A - The Action type to extract from
77
+ */
78
+ export type InferActionOutput<A extends Action> = A extends Action<any, infer O> ? O : never;
79
+ /**
80
+ * Options for creating a record in an AT Protocol repository.
81
+ *
82
+ * @see {@link Client.createRecord}
83
+ */
84
+ export type CreateRecordOptions = Omit<XrpcOptions<typeof createRecord>, 'body'> & {
85
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
86
+ repo?: AtIdentifierString;
87
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
88
+ swapCommit?: string;
89
+ /**
90
+ * Whether the PDS should validate the record against its lexicon schema.
91
+ * When `true`, the PDS is asked to explicitly validate the record. When
92
+ * `false`, the PDS is asked to explicitly skip validation. When `undefined`
93
+ * (default), the PDS decides -- typically validating only collections whose
94
+ * schemas it knows. This is server-side validation; for client-side
95
+ * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.
96
+ */
97
+ validate?: boolean;
98
+ };
99
+ /**
100
+ * Options for deleting a record from an AT Protocol repository.
101
+ *
102
+ * @see {@link Client.deleteRecord}
103
+ */
104
+ export type DeleteRecordOptions = Omit<XrpcOptions<typeof deleteRecord>, 'body'> & {
105
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
106
+ repo?: AtIdentifierString;
107
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
108
+ swapCommit?: string;
109
+ /** Compare-and-swap on the record CID. If specified, must match current record. */
110
+ swapRecord?: string;
111
+ };
112
+ /**
113
+ * Options for retrieving a record from an AT Protocol repository.
114
+ *
115
+ * @see {@link Client.getRecord}
116
+ */
117
+ export type GetRecordOptions = Omit<XrpcOptions<typeof getRecord>, 'params'> & {
118
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
119
+ repo?: AtIdentifierString;
120
+ };
121
+ /**
122
+ * Options for creating or updating a record in an AT Protocol repository.
123
+ *
124
+ * @see {@link Client.putRecord}
125
+ */
126
+ export type PutRecordOptions = Omit<XrpcOptions<typeof putRecord>, 'body'> & {
127
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
128
+ repo?: AtIdentifierString;
129
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
130
+ swapCommit?: string;
131
+ /** Compare-and-swap on the record CID. If specified, must match current record. */
132
+ swapRecord?: string;
133
+ /**
134
+ * Whether the PDS should validate the record against its lexicon schema.
135
+ * When `true`, the PDS is asked to explicitly validate the record. When
136
+ * `false`, the PDS is asked to explicitly skip validation. When `undefined`
137
+ * (default), the PDS decides — typically validating only collections whose
138
+ * schemas it knows. This is server-side validation; for client-side
139
+ * validation before sending, use {@link XrpcRequestProcessingOptions.validateRequest}.
140
+ */
141
+ validate?: boolean;
142
+ };
143
+ /**
144
+ * Options for listing records in an AT Protocol repository collection.
145
+ *
146
+ * @see {@link Client.listRecords}
147
+ */
148
+ export type ListRecordsOptions = Omit<XrpcOptions<typeof listRecords>, 'params'> & {
149
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
150
+ repo?: AtIdentifierString;
151
+ /** Maximum number of records to return. */
152
+ limit?: number;
153
+ /** Pagination cursor from a previous response. */
154
+ cursor?: string;
155
+ /** If true, returns records in reverse chronological order. */
156
+ reverse?: boolean;
157
+ };
158
+ /**
159
+ * Options for applying a batch of writes (create/update/delete) to an AT Protocol repository.
160
+ *
161
+ * @see {@link Client.applyWrites}
162
+ */
163
+ export type ApplyWritesOptions = Omit<XrpcOptions<typeof applyWrites>, 'body'> & {
164
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
165
+ repo?: AtIdentifierString;
166
+ /**
167
+ * Whether the PDS should validate the records against their lexicon schemas.
168
+ * When `true`, the PDS is asked to explicitly validate every record. When
169
+ * `false`, the PDS is asked to explicitly skip validation. When `undefined`
170
+ * (default), the PDS decides — typically validating only collections whose
171
+ * schemas it knows.
172
+ */
173
+ validate?: boolean;
174
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
175
+ swapCommit?: CidString;
176
+ };
177
+ export type UploadBlobOptions = Omit<XrpcOptions<typeof uploadBlob>, 'body'>;
178
+ export type GetBlobOptions = Omit<XrpcOptions<typeof getBlob>, 'params'>;
179
+ /**
180
+ * Type-safe options for {@link Client.create}, combining record options with key requirements.
181
+ * @typeParam T - The record schema type
182
+ * @see {@link CreateRecordOptions}
183
+ */
184
+ export type CreateOptions<T extends RecordSchema> = CreateRecordOptions & RecordKeyOptions<T, 'tid' | 'any'>;
185
+ /**
186
+ * Output type for record creation operations.
187
+ * Contains the URI and CID of the newly created record.
188
+ */
189
+ export type CreateOutput = InferMethodOutputBody<typeof createRecord, Uint8Array>;
190
+ /**
191
+ * Type-safe options for {@link Client.delete}, combining delete options with key requirements.
192
+ * @typeParam T - The record schema type
193
+ */
194
+ export type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions & RecordKeyOptions<T>;
195
+ /**
196
+ * Output type for record deletion operations.
197
+ */
198
+ export type DeleteOutput = InferMethodOutputBody<typeof deleteRecord, Uint8Array>;
199
+ /**
200
+ * Type-safe options for {@link Client.get}, combining get options with key requirements.
201
+ * @typeParam T - The record schema type
202
+ */
203
+ export type GetOptions<T extends RecordSchema> = GetRecordOptions & RecordKeyOptions<T>;
204
+ /**
205
+ * Output type for record retrieval operations.
206
+ * Contains the record value validated against the schema type.
207
+ * @typeParam T - The record schema type
208
+ */
209
+ export type GetOutput<T extends RecordSchema> = Omit<InferMethodOutputBody<typeof getRecord, Uint8Array>, 'value'> & {
210
+ value: Infer<T>;
211
+ };
212
+ /**
213
+ * Type-safe options for {@link Client.put}, combining put options with key requirements.
214
+ * @typeParam T - The record schema type
215
+ */
216
+ export type PutOptions<T extends RecordSchema> = PutRecordOptions & RecordKeyOptions<T>;
217
+ /**
218
+ * Output type for record put (create/update) operations.
219
+ * Contains the URI and CID of the record.
220
+ */
221
+ export type PutOutput = InferMethodOutputBody<typeof putRecord, Uint8Array>;
222
+ /**
223
+ * Options for {@link Client.list} operations.
224
+ */
225
+ export type ListOptions = ListRecordsOptions;
226
+ /**
227
+ * Output type for record listing operations.
228
+ * Contains validated records and any invalid records that failed schema validation.
229
+ * @typeParam T - The record schema type
230
+ */
231
+ export type ListOutput<T extends RecordSchema> = Omit<InferMethodOutputBody<typeof listRecords>, 'records'> & {
232
+ /** Records that successfully validated against the schema. */
233
+ records: ListRecordItem<Infer<T>>[];
234
+ };
235
+ /**
236
+ * A discriminated union type representing the result of a record listing
237
+ * operation.
238
+ */
239
+ export type ListRecordItem<Value extends LexMap> = {
240
+ uri: AtUriString;
241
+ cid: CidString;
242
+ valid: true;
243
+ value: Value;
244
+ } | {
245
+ uri: AtUriString;
246
+ cid: CidString;
247
+ valid: false;
248
+ value: LexMap;
249
+ };
250
+ /**
251
+ * The Client class is the primary interface for interacting with AT Protocol
252
+ * services. It provides type-safe methods for XRPC calls, record operations,
253
+ * and blob handling.
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * import { Client } from '@atproto/lex'
258
+ * import { app } from '#/lexicons
259
+ *
260
+ * const client = new Client(oauthSession)
261
+ *
262
+ * const response = await client.xrpc(app.bsky.feed.getTimeline, {
263
+ * params: { limit: 50 }
264
+ * })
265
+ * ```
266
+ */
267
+ export declare class Client {
268
+ static appLabelers: readonly DidString[];
269
+ /**
270
+ * Configures the Client (or its sub classes) globally.
271
+ */
272
+ static configure(opts: {
273
+ appLabelers?: Iterable<DidString>;
274
+ }): void;
275
+ /** The underlying agent used for making requests. */
276
+ readonly agent: Agent;
277
+ /** Default header values to include in all requests made by this client instance. */
278
+ readonly headers: Headers;
279
+ /** Default {@link XrpcOptions} for this client instance. */
280
+ readonly xrpcDefaults: Readonly<{
281
+ service: Service | null;
282
+ labelers: Set<DidString>;
283
+ appLabelers?: null | Iterable<DidString>;
284
+ validateRequest: boolean;
285
+ validateResponse: boolean;
286
+ strictResponseProcessing: boolean;
287
+ }>;
288
+ constructor(agent: Agent | AgentOptions, options?: ClientOptions);
289
+ /**
290
+ * The DID of the authenticated user, or `undefined` if not authenticated.
291
+ */
292
+ get did(): DidString | undefined;
293
+ /**
294
+ * The DID of the authenticated user.
295
+ * @throws {Error} if not authenticated
296
+ */
297
+ get assertDid(): DidString;
298
+ get service(): Service | null;
299
+ get labelers(): Set<DidString>;
300
+ /**
301
+ * Asserts that the client is authenticated.
302
+ * Use as a type guard when you need to ensure authentication.
303
+ *
304
+ * @throws {Error} if not authenticated
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * client.assertAuthenticated()
309
+ * // TypeScript now knows client.did is defined
310
+ * console.log(client.did)
311
+ * ```
312
+ */
313
+ assertAuthenticated(): asserts this is {
314
+ did: DidString;
315
+ };
316
+ /**
317
+ * Replaces all labelers with the given set.
318
+ * @param labelers - Iterable of labeler DIDs
319
+ */
320
+ setLabelers(labelers?: Iterable<DidString>): void;
321
+ /**
322
+ * Adds labelers to the current set.
323
+ * @param labelers - Iterable of labeler DIDs to add
324
+ */
325
+ addLabelers(labelers: Iterable<DidString>): void;
326
+ /**
327
+ * Removes all labelers from this client instance.
328
+ */
329
+ clearLabelers(): void;
330
+ /**
331
+ * Makes an XRPC request. Throws on failure.
332
+ *
333
+ * @param ns - The lexicon method definition (e.g., `app.bsky.feed.getTimeline`)
334
+ * @param options - Request options including params and body
335
+ * @returns The successful XRPC response
336
+ * @throws {XrpcFailure} when the request fails or returns an error
337
+ *
338
+ * @example Query with parameters
339
+ * ```typescript
340
+ * const response = await client.xrpc(app.bsky.feed.getTimeline, {
341
+ * params: { limit: 50, cursor: 'abc123' }
342
+ * })
343
+ * console.log(response.body.feed)
344
+ * ```
345
+ *
346
+ * @example Procedure with body
347
+ * ```typescript
348
+ * const response = await client.xrpc(com.atproto.repo.createRecord, {
349
+ * body: {
350
+ * repo: client.assertDid,
351
+ * collection: 'app.bsky.feed.post',
352
+ * record: { text: 'Hello!', createdAt: new Date().toISOString() }
353
+ * }
354
+ * })
355
+ * ```
356
+ *
357
+ * @see {@link xrpcSafe} for a non-throwing variant
358
+ */
359
+ xrpc<const M extends Query | Procedure>(ns: NonNullable<unknown> extends XrpcOptions<M> ? Main<M> : Restricted<'This XRPC method requires an "options" argument'>): Promise<XrpcResponse<M>>;
360
+ xrpc<const M extends Query | Procedure>(ns: Main<M>, options: XrpcOptions<M>): Promise<XrpcResponse<M>>;
361
+ /**
362
+ * Makes an XRPC request without throwing on failure.
363
+ * Returns either a successful response or a failure object.
364
+ *
365
+ * @param ns - The lexicon method definition
366
+ * @param options - Request options
367
+ * @returns Either an XrpcResponse on success or XrpcFailure on failure
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * const result = await client.xrpcSafe(app.bsky.actor.getProfile, {
372
+ * params: { actor: 'alice.bsky.social' }
373
+ * })
374
+ *
375
+ * if (result.success) {
376
+ * console.log(result.body.displayName)
377
+ * } else {
378
+ * console.error('Failed:', result.error)
379
+ * }
380
+ * ```
381
+ *
382
+ * @see {@link xrpc} for a throwing variant
383
+ */
384
+ xrpcSafe<const M extends Query | Procedure>(ns: NonNullable<unknown> extends XrpcOptions<M> ? Main<M> : Restricted<'This XRPC method requires an "options" argument'>): Promise<XrpcResponse<M> | XrpcFailure<M>>;
385
+ xrpcSafe<const M extends Query | Procedure>(ns: Main<M>, options: XrpcOptions<M>): Promise<XrpcResponse<M> | XrpcFailure<M>>;
386
+ protected buildXrpcOptions<M extends Query | Procedure>(options: XrpcOptions<M>): XrpcOptions<M>;
387
+ /**
388
+ * Creates a new record in an AT Protocol repository.
389
+ *
390
+ * @param record - The record to create, must include an {@link NsidString} `$type`
391
+ * @param rkey - Optional record key; if omitted, server generates a TID
392
+ * @param options - Create options including repo, swapCommit, validate
393
+ * @returns The XRPC response containing the created record's URI and CID
394
+ *
395
+ * @example
396
+ * ```typescript
397
+ * const response = await client.createRecord(
398
+ * { $type: 'app.bsky.feed.post', text: 'Hello!', createdAt: new Date().toISOString() },
399
+ * undefined, // Let server generate rkey
400
+ * { validate: true }
401
+ * )
402
+ * console.log(response.body.uri)
403
+ * ```
404
+ *
405
+ * @see {@link create} for a higher-level typed alternative
406
+ *
407
+ * @note This method will ignore the `service` and `labelers` instance wide
408
+ * defaults, and will always use `null` unless explicitly overridden in the
409
+ * options.
410
+ */
411
+ createRecord(record: TypedLexMap<NsidString>, rkey?: string, { service, labelers, ...options }?: CreateRecordOptions): Promise<XrpcResponse<typeof createRecord>>;
412
+ /**
413
+ * Deletes a record from an AT Protocol repository.
414
+ *
415
+ * @param collection - The collection NSID
416
+ * @param rkey - The record key
417
+ * @param options - Delete options including repo, swapCommit, swapRecord
418
+ *
419
+ * @see {@link delete} for a higher-level typed alternative
420
+ *
421
+ * @note This method will ignore the `service` and `labelers` instance wide
422
+ * defaults, and will always use `null` unless explicitly overridden in the
423
+ * options.
424
+ */
425
+ deleteRecord(collection: NsidString, rkey: string, { service, labelers, ...options }?: DeleteRecordOptions): Promise<XrpcResponse<typeof deleteRecord>>;
426
+ /**
427
+ * Retrieves a record from an AT Protocol repository.
428
+ *
429
+ * @param collection - The collection NSID
430
+ * @param rkey - The record key
431
+ * @param options - Get options including repo
432
+ *
433
+ * @see {@link get} for a higher-level typed alternative
434
+ *
435
+ * @note This method will ignore the `service` and `labelers` instance wide
436
+ * defaults, and will always use `null` unless explicitly overridden in the
437
+ * options.
438
+ */
439
+ getRecord(collection: NsidString, rkey: string, { service, labelers, ...options }?: GetRecordOptions): Promise<XrpcResponse<typeof getRecord>>;
440
+ /**
441
+ * Creates or updates a record in a repository.
442
+ *
443
+ * @param record - The record to put, must include an {@link NsidString} `$type`
444
+ * @param rkey - The record key
445
+ * @param options - Put options including repo, swapCommit, swapRecord, validate
446
+ *
447
+ * @see {@link put} for a higher-level typed alternative
448
+ *
449
+ * @note This method will ignore the `service` and `labelers` instance wide
450
+ * defaults, and will always use `null` unless explicitly overridden in the
451
+ * options.
452
+ */
453
+ putRecord(record: TypedLexMap<NsidString>, rkey: string, { service, labelers, ...options }?: PutRecordOptions): Promise<XrpcResponse<typeof putRecord>>;
454
+ /**
455
+ * Lists records in a collection.
456
+ *
457
+ * @param nsid - The collection NSID
458
+ * @param options - List options including repo, limit, cursor, reverse
459
+ *
460
+ * @see {@link list} for a higher-level typed alternative
461
+ *
462
+ * @note This method will ignore the `service` and `labelers` instance wide
463
+ * defaults, and will always use `null` unless explicitly overridden in the
464
+ * options.
465
+ */
466
+ listRecords(nsid: NsidString, { service, labelers, ...options }?: ListRecordsOptions): Promise<XrpcResponse<typeof listRecords>>;
467
+ /**
468
+ * Performs an atomic batch of create, update, and delete operations on records in a repository.
469
+ *
470
+ * @param builder - A function that receives an {@link ApplyWritesOperations} instance to build the operations
471
+ * @param options - ApplyWrites options including repo, validate, swapCommit
472
+ * @returns The XRPC response from the applyWrites call
473
+ *
474
+ * @example
475
+ * ```typescript
476
+ * const response = await client.applyWrites((op) => [
477
+ * op.create(app.bsky.feed.post, { text: 'Hello!' }),
478
+ * op.update(app.bsky.feed.post, { text: 'Updated text' }, { rkey: 'post123' }),
479
+ * op.delete(app.bsky.feed.post, 'post456'),
480
+ * op.update(app.bsky.actor.profile, { displayName: 'Alice' }),
481
+ * ], {
482
+ * validate: true,
483
+ * })
484
+ *
485
+ * for (const result of response.body.results) {
486
+ * console.log(result.uri)
487
+ * }
488
+ * ```
489
+ *
490
+ * @note This method will ignore the `service` and `labelers` instance wide
491
+ * defaults, and will always use `null` unless explicitly overridden in the
492
+ * options.
493
+ */
494
+ applyWrites(factory: WriteOperationsFactory, { service, labelers, ...options }?: ApplyWritesOptions): Promise<XrpcResponse<typeof applyWrites>>;
495
+ /**
496
+ * Uploads a blob to an AT Protocol repository.
497
+ *
498
+ * @param body - The blob data (Uint8Array, ReadableStream, Blob, etc.)
499
+ * @param options - Upload options including encoding hint
500
+ * @returns Response containing the blob reference
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * const imageData = await fetch('image.png').then(r => r.arrayBuffer())
505
+ * const response = await client.uploadBlob(new Uint8Array(imageData), {
506
+ * encoding: 'image/png'
507
+ * })
508
+ * console.log(response.body.blob) // Use this ref in records
509
+ * ```
510
+ *
511
+ * @note This method will ignore the `service` and `labelers` instance wide
512
+ * defaults, and will always use `null` unless explicitly overridden in the
513
+ * options.
514
+ */
515
+ uploadBlob(body: BinaryBodyInit, { service, labelers, ...options }?: UploadBlobOptions): Promise<XrpcResponse<typeof uploadBlob>>;
516
+ /**
517
+ * Retrieves a blob by DID and CID.
518
+ *
519
+ * @param did - The DID of the repository containing the blob
520
+ * @param cid - The CID of the blob
521
+ * @param options - Call options
522
+ *
523
+ * @note This method will ignore the `service` and `labelers` instance wide
524
+ * defaults, and will always use `null` unless explicitly overridden in the
525
+ * options.
526
+ */
527
+ getBlob(did: DidString, cid: CidString, { service, labelers, ...options }?: GetBlobOptions): Promise<XrpcResponse<typeof getBlob>>;
528
+ /**
529
+ * Universal call method for queries, procedures, and custom actions.
530
+ * Automatically determines the call type based on the lexicon definition.
531
+ *
532
+ * @param ns - The lexicon method or action definition
533
+ * @param arg - The input argument (params for queries, body for procedures, input for actions)
534
+ * @param options - Call options
535
+ * @returns The method response body or action output
536
+ * @see {@link xrpc} if you need access to the full response object
537
+ *
538
+ * @example Query
539
+ * ```typescript
540
+ * const profile = await client.call(app.bsky.actor.getProfile, {
541
+ * actor: 'alice.bsky.social'
542
+ * })
543
+ * ```
544
+ *
545
+ * @example Procedure
546
+ * ```typescript
547
+ * const result = await client.call(com.atproto.repo.createRecord, {
548
+ * repo: did,
549
+ * collection: 'app.bsky.feed.post',
550
+ * record: { text: 'Hello!' }
551
+ * })
552
+ * ```
553
+ *
554
+ * @example Action
555
+ * ```typescript
556
+ * const result = await client.call(updateProfile, (profile) => {
557
+ * profile.displayName = 'Alice'
558
+ * })
559
+ * ```
560
+ */
561
+ call<const T extends Query>(ns: NonNullable<unknown> extends XrpcRequestParams<T> ? Main<T> : Restricted<'This query type requires a "params" argument'>): Promise<XrpcResponseBody<T>>;
562
+ call<const T extends Procedure>(ns: undefined extends InferMethodInputBody<T, Uint8Array> ? Main<T> : Restricted<'This procedure type requires an "input" argument'>): Promise<XrpcResponseBody<T>>;
563
+ call<const T extends Action>(ns: void extends InferActionInput<T> ? Main<T> : Restricted<'This action type requires an "input" argument'>): Promise<InferActionOutput<T>>;
564
+ call<const T extends Action | Procedure | Query>(ns: Main<T>, arg: T extends Action ? InferActionInput<T> : T extends Procedure ? InferMethodInputBody<T, Uint8Array> : T extends Query ? XrpcRequestParams<T> : never, options?: T extends Action ? ActionOptions : T extends Procedure ? Omit<XrpcOptions<T>, 'body'> : T extends Query ? Omit<XrpcOptions<T>, 'params'> : never): Promise<T extends Action ? InferActionOutput<T> : T extends Procedure ? XrpcResponseBody<T> : T extends Query ? XrpcResponseBody<T> : never>;
565
+ /**
566
+ * Creates a new record with full type safety based on the schema.
567
+ *
568
+ * @param ns - The record schema definition
569
+ * @param input - The record data (without `$type`, which is added automatically)
570
+ * @param options - Create options including rkey (required for some record types)
571
+ * @returns The create output including URI and CID
572
+ *
573
+ * @example Creating a post
574
+ * ```typescript
575
+ * const result = await client.create(app.bsky.feed.post, {
576
+ * text: 'Hello, world!',
577
+ * createdAt: new Date().toISOString()
578
+ * })
579
+ * console.log(result.uri)
580
+ * ```
581
+ *
582
+ * @example Creating a record with explicit rkey
583
+ * ```typescript
584
+ * const result = await client.create(app.bsky.actor.profile, {
585
+ * displayName: 'Alice'
586
+ * }, { rkey: 'self' })
587
+ * ```
588
+ *
589
+ * @see {@link createRecord} for a lower-level method that returns the raw response without schema validation
590
+ */
591
+ create<const T extends RecordSchema>(ns: NonNullable<unknown> extends CreateOptions<T> ? Main<T> : Restricted<'This record type requires an "options" argument'>, input: Omit<Infer<T>, '$type'>): Promise<CreateOutput>;
592
+ create<const T extends RecordSchema>(ns: Main<T>, input: Omit<Infer<T>, '$type'>, options: CreateOptions<T>): Promise<CreateOutput>;
593
+ /**
594
+ * Deletes a record with type-safe options.
595
+ *
596
+ * @param ns - The record schema definition
597
+ * @param options - Delete options (rkey required for non-literal keys)
598
+ * @returns The delete output
599
+ *
600
+ * @see {@link deleteRecord} for a lower-level method that returns the raw response without schema validation
601
+ */
602
+ delete<const T extends RecordSchema>(ns: NonNullable<unknown> extends DeleteOptions<T> ? Main<T> : Restricted<'This record type requires an "options" argument'>): Promise<DeleteOutput>;
603
+ delete<const T extends RecordSchema>(ns: Main<T>, options?: DeleteOptions<T>): Promise<DeleteOutput>;
604
+ /**
605
+ * Retrieves a record with type-safe validation.
606
+ *
607
+ * @param ns - The record schema definition
608
+ * @param options - Get options (rkey required for non-literal keys)
609
+ * @returns The record data validated against the schema
610
+ *
611
+ * @example
612
+ * ```typescript
613
+ * const profile = await client.get(app.bsky.actor.profile)
614
+ * // profile.value is typed as app.bsky.actor.profile.Record
615
+ * console.log(profile.value.displayName)
616
+ * ```
617
+ *
618
+ * @see {@link getRecord} for a lower-level method that returns the raw record without schema validation
619
+ */
620
+ get<const T extends RecordSchema>(ns: T['key'] extends `literal:${string}` ? Main<T> : Restricted<'This record type requires an "options" argument'>): Promise<GetOutput<T>>;
621
+ get<const T extends RecordSchema>(ns: Main<T>, options: GetOptions<T>): Promise<GetOutput<T>>;
622
+ /**
623
+ * Creates or updates a record with full type safety.
624
+ *
625
+ * @param ns - The record schema definition
626
+ * @param input - The record data
627
+ * @param options - Put options (rkey required for non-literal keys)
628
+ * @returns The put output including URI and CID
629
+ *
630
+ * @example Creating a new record
631
+ * ```typescript
632
+ * const result = await client.put(app.bsky.feed.post, {
633
+ * text: 'Hello, world!',
634
+ * createdAt: new Date().toISOString()
635
+ * })
636
+ * console.log(result.uri)
637
+ * ```
638
+ *
639
+ * @example Updating an existing record with explicit rkey
640
+ * ```typescript
641
+ * const result = await client.put(app.bsky.actor.profile, {
642
+ * displayName: 'Alice'
643
+ * }, { rkey: 'self' })
644
+ * ```
645
+ *
646
+ * @see {@link putRecord} for a lower-level method that returns the raw record without schema validation
647
+ */
648
+ put<const T extends RecordSchema>(ns: NonNullable<unknown> extends PutOptions<T> ? Main<T> : Restricted<'This record type requires an "options" argument'>, input: Omit<Infer<T>, '$type'>): Promise<PutOutput>;
649
+ put<const T extends RecordSchema>(ns: Main<T>, input: Omit<Infer<T>, '$type'>, options: PutOptions<T>): Promise<PutOutput>;
650
+ /**
651
+ * Lists records with type-safe validation and separation of valid/invalid records.
652
+ *
653
+ * @param ns - The record schema definition
654
+ * @param options - List options
655
+ * @returns Records validated against the schema, with invalid records included as LexMap
656
+ *
657
+ * @example
658
+ * ```typescript
659
+ * const result = await client.list(app.bsky.feed.post, { limit: 100 })
660
+ * for (const record of result.records) {
661
+ * if (record.valid) {
662
+ * record.value // Fully typed
663
+ * } else {
664
+ * record.value // Invalid record, typed as LexMap
665
+ * }
666
+ * }
667
+ * ```
668
+ *
669
+ * @see {@link listRecords} for a lower-level method that returns the raw records without schema validation
670
+ */
671
+ list<const T extends RecordSchema>(ns: Main<T>, options?: ListOptions): Promise<ListOutput<T>>;
672
+ /**
673
+ * Asynchronously iterates over all records in a collection, handling
674
+ * pagination automatically.
675
+ *
676
+ * @param ns - The record schema definition
677
+ * @param options - List options including limit and cursor
678
+ * @returns An async generator yielding each record validated against the schema
679
+ *
680
+ * @see {@link list} for a method that returns a single page of records
681
+ * @see {@link listRecords} for a lower-level method that returns raw records without schema validation
682
+ */
683
+ listAll<const T extends RecordSchema>(ns: Main<T>, { maxRetries, ...options }?: ListOptions): AsyncGenerator<ListRecordItem<Infer<T>>, void, unknown>;
684
+ }
685
+ //# sourceMappingURL=client.d.ts.map