@atproto/lex-client 0.0.10 → 0.0.12

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 (48) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/agent.d.ts +72 -0
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +46 -1
  5. package/dist/agent.js.map +1 -1
  6. package/dist/client.d.ts +442 -46
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +145 -1
  9. package/dist/client.js.map +1 -1
  10. package/dist/errors.d.ts +202 -48
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/errors.js +208 -65
  13. package/dist/errors.js.map +1 -1
  14. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +20 -20
  15. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +12 -12
  16. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +6 -6
  17. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +6 -6
  18. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +22 -22
  19. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +2 -2
  20. package/dist/response.d.ts +17 -6
  21. package/dist/response.d.ts.map +1 -1
  22. package/dist/response.js +45 -32
  23. package/dist/response.js.map +1 -1
  24. package/dist/types.d.ts +51 -0
  25. package/dist/types.d.ts.map +1 -1
  26. package/dist/types.js.map +1 -1
  27. package/dist/util.d.ts +40 -5
  28. package/dist/util.d.ts.map +1 -1
  29. package/dist/util.js +22 -0
  30. package/dist/util.js.map +1 -1
  31. package/dist/www-authenticate.d.ts +35 -0
  32. package/dist/www-authenticate.d.ts.map +1 -0
  33. package/dist/www-authenticate.js +57 -0
  34. package/dist/www-authenticate.js.map +1 -0
  35. package/dist/xrpc.d.ts +82 -10
  36. package/dist/xrpc.d.ts.map +1 -1
  37. package/dist/xrpc.js +15 -28
  38. package/dist/xrpc.js.map +1 -1
  39. package/package.json +7 -7
  40. package/src/agent.ts +101 -1
  41. package/src/client.ts +428 -15
  42. package/src/errors.ts +308 -120
  43. package/src/response.ts +68 -63
  44. package/src/types.ts +52 -0
  45. package/src/util.ts +50 -5
  46. package/src/www-authenticate.test.ts +227 -0
  47. package/src/www-authenticate.ts +101 -0
  48. package/src/xrpc.ts +100 -53
package/dist/client.d.ts CHANGED
@@ -1,42 +1,123 @@
1
- import { LexMap, LexValue } from '@atproto/lex-data';
1
+ import { LexMap, LexValue, TypedLexMap } from '@atproto/lex-data';
2
2
  import { AtIdentifierString, CidString, DidString, Infer, InferMethodInputBody, InferMethodOutputBody, InferRecordKey, LexiconRecordKey, Main, NsidString, Params, Procedure, Query, RecordSchema, Restricted, UnknownObject } from '@atproto/lex-schema';
3
3
  import { Agent, AgentOptions } from './agent.js';
4
+ import { XrpcFailure } from './errors.js';
4
5
  import { com } from './lexicons/index.js';
5
6
  import { XrpcResponse, XrpcResponseBody } from './response.js';
6
7
  import { BinaryBodyInit, CallOptions, Service } from './types.js';
7
- import { XrpcFailure, XrpcOptions, XrpcRequestParams } from './xrpc.js';
8
- export type { AtIdentifierString, CidString, DidString, InferMethodInputBody, InferMethodOutputBody, InferRecordKey, LexMap, LexValue, LexiconRecordKey, NsidString, Params, Procedure, Query, RecordSchema, Restricted, };
8
+ import { XrpcOptions, XrpcRequestParams } from './xrpc.js';
9
+ export type { AtIdentifierString, CidString, DidString, Infer, InferMethodInputBody, InferMethodOutputBody, InferRecordKey, LexMap, LexValue, LexiconRecordKey, Main, NsidString, Params, Procedure, Query, RecordSchema, Restricted, TypedLexMap, };
10
+ /**
11
+ * Configuration options for creating a {@link Client}.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const options: ClientOptions = {
16
+ * labelers: ['did:plc:labeler1'],
17
+ * service: 'did:web:api.bsky.app#bsky_appview',
18
+ * headers: { 'X-Custom-Header': 'value' }
19
+ * }
20
+ * ```
21
+ */
9
22
  export type ClientOptions = {
23
+ /** Labeler DIDs to include in requests for content moderation. */
10
24
  labelers?: Iterable<DidString>;
25
+ /** Custom headers to include in all requests made by this client. */
11
26
  headers?: HeadersInit;
27
+ /** Service proxy identifier for routing requests through a specific service. */
12
28
  service?: Service;
13
29
  };
30
+ /**
31
+ * A composable action that can be invoked via {@link Client.call}.
32
+ *
33
+ * Actions provide a way to define custom operations that integrate with the
34
+ * Client's call interface, enabling type-safe, reusable business logic.
35
+ *
36
+ * @typeParam I - The input type for the action
37
+ * @typeParam O - The output type for the action
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const myAction: Action<{ userId: string }, { profile: Profile }> = async (client, input, options) => {
42
+ * const response = await client.xrpc(someMethod, { params: { actor: input.userId }, ...options })
43
+ * return { profile: response.body }
44
+ * }
45
+ * ```
46
+ */
14
47
  export type Action<I = any, O = any> = (client: Client, input: I, options: CallOptions) => O | Promise<O>;
48
+ /**
49
+ * Extracts the input type from an {@link Action}.
50
+ * @typeParam A - The Action type to extract from
51
+ */
15
52
  export type InferActionInput<A extends Action> = A extends Action<infer I, any> ? I : never;
53
+ /**
54
+ * Extracts the output type from an {@link Action}.
55
+ * @typeParam A - The Action type to extract from
56
+ */
16
57
  export type InferActionOutput<A extends Action> = A extends Action<any, infer O> ? O : never;
58
+ /**
59
+ * Options for creating a record in an AT Protocol repository.
60
+ *
61
+ * @see {@link Client.createRecord}
62
+ */
17
63
  export type CreateRecordOptions = CallOptions & {
64
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
18
65
  repo?: AtIdentifierString;
66
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
19
67
  swapCommit?: string;
68
+ /** Whether to validate the record against its lexicon schema. */
20
69
  validate?: boolean;
21
70
  };
71
+ /**
72
+ * Options for deleting a record from an AT Protocol repository.
73
+ *
74
+ * @see {@link Client.deleteRecord}
75
+ */
22
76
  export type DeleteRecordOptions = CallOptions & {
77
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
23
78
  repo?: AtIdentifierString;
79
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
24
80
  swapCommit?: string;
81
+ /** Compare-and-swap on the record CID. If specified, must match current record. */
25
82
  swapRecord?: string;
26
83
  };
84
+ /**
85
+ * Options for retrieving a record from an AT Protocol repository.
86
+ *
87
+ * @see {@link Client.getRecord}
88
+ */
27
89
  export type GetRecordOptions = CallOptions & {
90
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
28
91
  repo?: AtIdentifierString;
29
92
  };
93
+ /**
94
+ * Options for creating or updating a record in an AT Protocol repository.
95
+ *
96
+ * @see {@link Client.putRecord}
97
+ */
30
98
  export type PutRecordOptions = CallOptions & {
99
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
31
100
  repo?: AtIdentifierString;
101
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
32
102
  swapCommit?: string;
103
+ /** Compare-and-swap on the record CID. If specified, must match current record. */
33
104
  swapRecord?: string;
105
+ /** Whether to validate the record against its lexicon schema. */
34
106
  validate?: boolean;
35
107
  };
108
+ /**
109
+ * Options for listing records in an AT Protocol repository collection.
110
+ *
111
+ * @see {@link Client.listRecords}
112
+ */
36
113
  export type ListRecordsOptions = CallOptions & {
114
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
37
115
  repo?: AtIdentifierString;
116
+ /** Maximum number of records to return. */
38
117
  limit?: number;
118
+ /** Pagination cursor from a previous response. */
39
119
  cursor?: string;
120
+ /** If true, returns records in reverse chronological order. */
40
121
  reverse?: boolean;
41
122
  };
42
123
  export type RecordKeyOptions<T extends RecordSchema, AlsoOptionalWhenRecordKeyIs extends LexiconRecordKey = never> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs ? {
@@ -44,24 +125,85 @@ export type RecordKeyOptions<T extends RecordSchema, AlsoOptionalWhenRecordKeyIs
44
125
  } : {
45
126
  rkey: InferRecordKey<T>;
46
127
  };
47
- export type CreateOptions<T extends RecordSchema> = CreateRecordOptions & RecordKeyOptions<T, 'tid'>;
128
+ /**
129
+ * Type-safe options for {@link Client.create}, combining record options with key requirements.
130
+ * @typeParam T - The record schema type
131
+ */
132
+ export type CreateOptions<T extends RecordSchema> = CreateRecordOptions & RecordKeyOptions<T, 'tid' | 'any'>;
133
+ /**
134
+ * Output type for record creation operations.
135
+ * Contains the URI and CID of the newly created record.
136
+ */
48
137
  export type CreateOutput = InferMethodOutputBody<typeof com.atproto.repo.createRecord.main, Uint8Array>;
138
+ /**
139
+ * Type-safe options for {@link Client.delete}, combining delete options with key requirements.
140
+ * @typeParam T - The record schema type
141
+ */
49
142
  export type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions & RecordKeyOptions<T>;
143
+ /**
144
+ * Output type for record deletion operations.
145
+ */
50
146
  export type DeleteOutput = InferMethodOutputBody<typeof com.atproto.repo.deleteRecord.main, Uint8Array>;
147
+ /**
148
+ * Type-safe options for {@link Client.get}, combining get options with key requirements.
149
+ * @typeParam T - The record schema type
150
+ */
51
151
  export type GetOptions<T extends RecordSchema> = GetRecordOptions & RecordKeyOptions<T>;
152
+ /**
153
+ * Output type for record retrieval operations.
154
+ * Contains the record value validated against the schema type.
155
+ * @typeParam T - The record schema type
156
+ */
52
157
  export type GetOutput<T extends RecordSchema> = Omit<InferMethodOutputBody<typeof com.atproto.repo.getRecord.main, Uint8Array>, 'value'> & {
53
158
  value: Infer<T>;
54
159
  };
160
+ /**
161
+ * Type-safe options for {@link Client.put}, combining put options with key requirements.
162
+ * @typeParam T - The record schema type
163
+ */
55
164
  export type PutOptions<T extends RecordSchema> = PutRecordOptions & RecordKeyOptions<T>;
165
+ /**
166
+ * Output type for record put (create/update) operations.
167
+ * Contains the URI and CID of the record.
168
+ */
56
169
  export type PutOutput = InferMethodOutputBody<typeof com.atproto.repo.putRecord.main, Uint8Array>;
170
+ /**
171
+ * Options for {@link Client.list} operations.
172
+ */
57
173
  export type ListOptions = ListRecordsOptions;
174
+ /**
175
+ * Output type for record listing operations.
176
+ * Contains validated records and any invalid records that failed schema validation.
177
+ * @typeParam T - The record schema type
178
+ */
58
179
  export type ListOutput<T extends RecordSchema> = InferMethodOutputBody<typeof com.atproto.repo.listRecords.main, Uint8Array> & {
180
+ /** Records that successfully validated against the schema. */
59
181
  records: ListRecord<Infer<T>>[];
182
+ /** Records that failed schema validation. */
60
183
  invalid: UnknownObject[];
61
184
  };
185
+ /**
186
+ * A record from a list operation with its value typed to the schema.
187
+ * @typeParam Value - The validated record value type
188
+ */
62
189
  export type ListRecord<Value extends LexMap> = com.atproto.repo.listRecords.Record & {
63
190
  value: Value;
64
191
  };
192
+ /**
193
+ * The Client class is the primary interface for interacting with AT Protocol
194
+ * services. It provides type-safe methods for XRPC calls, record operations,
195
+ * and blob handling.
196
+ *
197
+ * @example Basic usage
198
+ * ```typescript
199
+ * import { Client } from '@atproto/lex'
200
+ *
201
+ * const client = new Client(agent)
202
+ * const response = await client.xrpc(app.bsky.feed.getTimeline.main, {
203
+ * params: { limit: 50 }
204
+ * })
205
+ * ```
206
+ */
65
207
  export declare class Client implements Agent {
66
208
  static appLabelers: readonly DidString[];
67
209
  /**
@@ -70,77 +212,199 @@ export declare class Client implements Agent {
70
212
  static configure(opts: {
71
213
  appLabelers?: Iterable<DidString>;
72
214
  }): void;
215
+ /** The underlying agent used for making requests. */
73
216
  readonly agent: Agent;
217
+ /** Custom headers included in all requests. */
74
218
  readonly headers: Headers;
219
+ /** Optional service identifier for routing requests. */
75
220
  readonly service?: Service;
221
+ /** Set of labeler DIDs specific to this client instance. */
76
222
  readonly labelers: Set<DidString>;
77
223
  constructor(agent: Agent | AgentOptions, options?: ClientOptions);
224
+ /**
225
+ * The DID of the authenticated user, or `undefined` if not authenticated.
226
+ */
78
227
  get did(): DidString | undefined;
228
+ /**
229
+ * The DID of the authenticated user.
230
+ * @throws {LexError} with code 'AuthenticationRequired' if not authenticated
231
+ */
79
232
  get assertDid(): DidString;
233
+ /**
234
+ * Asserts that the client is authenticated.
235
+ * Use as a type guard when you need to ensure authentication.
236
+ *
237
+ * @throws {LexError} with code 'AuthenticationRequired' if not authenticated
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * client.assertAuthenticated()
242
+ * // TypeScript now knows client.did is defined
243
+ * console.log(client.did)
244
+ * ```
245
+ */
80
246
  assertAuthenticated(): asserts this is {
81
247
  did: DidString;
82
248
  };
249
+ /**
250
+ * Replaces all labelers with the given set.
251
+ * @param labelers - Iterable of labeler DIDs
252
+ */
83
253
  setLabelers(labelers?: Iterable<DidString>): void;
254
+ /**
255
+ * Adds labelers to the current set.
256
+ * @param labelers - Iterable of labeler DIDs to add
257
+ */
84
258
  addLabelers(labelers: Iterable<DidString>): void;
259
+ /**
260
+ * Removes all labelers from this client instance.
261
+ */
85
262
  clearLabelers(): void;
263
+ /**
264
+ * Low-level fetch handler for making requests.
265
+ * @param path - The request path
266
+ * @param init - Request initialization options
267
+ */
86
268
  fetchHandler(path: string, init: RequestInit): Promise<Response>;
87
269
  /**
88
- * @throws {XrpcFailure<M>} when the request fails or the response is an error
270
+ * Makes an XRPC request. Throws on failure.
271
+ *
272
+ * @param ns - The lexicon method definition (e.g., `app.bsky.feed.getTimeline`)
273
+ * @param options - Request options including params and body
274
+ * @returns The successful XRPC response
275
+ * @throws {XrpcFailure} when the request fails or returns an error
276
+ *
277
+ * @example Query with parameters
278
+ * ```typescript
279
+ * const response = await client.xrpc(app.bsky.feed.getTimeline, {
280
+ * params: { limit: 50, cursor: 'abc123' }
281
+ * })
282
+ * console.log(response.body.feed)
283
+ * ```
284
+ *
285
+ * @example Procedure with body
286
+ * ```typescript
287
+ * const response = await client.xrpc(com.atproto.repo.createRecord, {
288
+ * body: {
289
+ * repo: client.assertDid,
290
+ * collection: 'app.bsky.feed.post',
291
+ * record: { text: 'Hello!', createdAt: new Date().toISOString() }
292
+ * }
293
+ * })
294
+ * ```
295
+ *
296
+ * @see {@link xrpcSafe} for a non-throwing variant
89
297
  */
90
298
  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>>;
91
299
  xrpc<const M extends Query | Procedure>(ns: Main<M>, options: XrpcOptions<M>): Promise<XrpcResponse<M>>;
300
+ /**
301
+ * Makes an XRPC request without throwing on failure.
302
+ * Returns either a successful response or a failure object.
303
+ *
304
+ * @param ns - The lexicon method definition
305
+ * @param options - Request options
306
+ * @returns Either an XrpcResponse on success or XrpcFailure on failure
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * const result = await client.xrpcSafe(app.bsky.actor.getProfile.main, {
311
+ * params: { actor: 'alice.bsky.social' }
312
+ * })
313
+ *
314
+ * if (result.success) {
315
+ * console.log(result.body.displayName)
316
+ * } else {
317
+ * console.error('Failed:', result.error)
318
+ * }
319
+ * ```
320
+ *
321
+ * @see {@link xrpc} for a throwing variant
322
+ */
92
323
  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>>;
93
324
  xrpcSafe<const M extends Query | Procedure>(ns: Main<M>, options: XrpcOptions<M>): Promise<XrpcResponse<M> | XrpcFailure<M>>;
94
325
  /**
95
- * @param rkey Leave `undefined` to have the server generate a TID.
326
+ * Creates a new record in an AT Protocol repository.
327
+ *
328
+ * @param record - The record to create, must include an {@link NsidString} `$type`
329
+ * @param rkey - Optional record key; if omitted, server generates a TID
330
+ * @param options - Create options including repo, swapCommit, validate
331
+ * @returns The XRPC response containing the created record's URI and CID
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * const response = await client.createRecord(
336
+ * { $type: 'app.bsky.feed.post', text: 'Hello!', createdAt: new Date().toISOString() },
337
+ * undefined, // Let server generate rkey
338
+ * { validate: true }
339
+ * )
340
+ * console.log(response.body.uri)
341
+ * ```
342
+ *
343
+ * @see {@link create} for a higher-level typed alternative
96
344
  */
97
- createRecord(record: {
98
- $type: NsidString;
99
- } & LexMap, rkey?: string, options?: CreateRecordOptions): Promise<XrpcResponse<Procedure<"com.atproto.repo.createRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
100
- readonly repo: import("@atproto/lex-schema").StringSchema<{
345
+ createRecord(record: TypedLexMap<NsidString>, rkey?: string, options?: CreateRecordOptions): Promise<XrpcResponse<Procedure<"com.atproto.repo.createRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
346
+ repo: import("@atproto/lex-schema").StringSchema<{
101
347
  readonly format: "at-identifier";
102
348
  }>;
103
- readonly collection: import("@atproto/lex-schema").StringSchema<{
349
+ collection: import("@atproto/lex-schema").StringSchema<{
104
350
  readonly format: "nsid";
105
351
  }>;
106
- readonly rkey: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
352
+ rkey: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
107
353
  readonly format: "record-key";
108
354
  readonly maxLength: 512;
109
355
  }>>;
110
- readonly validate: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
111
- readonly record: import("@atproto/lex-schema").UnknownObjectSchema;
112
- readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
356
+ validate: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
357
+ record: import("@atproto/lex-schema").UnknownObjectSchema;
358
+ swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
113
359
  readonly format: "cid";
114
360
  }>>;
115
361
  }>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
116
- readonly uri: import("@atproto/lex-schema").StringSchema<{
362
+ uri: import("@atproto/lex-schema").StringSchema<{
117
363
  readonly format: "at-uri";
118
364
  }>;
119
- readonly cid: import("@atproto/lex-schema").StringSchema<{
365
+ cid: import("@atproto/lex-schema").StringSchema<{
120
366
  readonly format: "cid";
121
367
  }>;
122
- readonly commit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").RefSchema<import("@atproto/lex-schema").Validator<com.atproto.repo.defs.$defs.CommitMeta, com.atproto.repo.defs.$defs.CommitMeta>>>;
123
- readonly validationStatus: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
368
+ commit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").RefSchema<import("@atproto/lex-schema").Validator<com.atproto.repo.defs.$defs.CommitMeta, com.atproto.repo.defs.$defs.CommitMeta>>>;
369
+ validationStatus: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
124
370
  }>>, readonly ["InvalidSwap"]>>>;
371
+ /**
372
+ * Deletes a record from an AT Protocol repository.
373
+ *
374
+ * @param collection - The collection NSID
375
+ * @param rkey - The record key
376
+ * @param options - Delete options including repo, swapCommit, swapRecord
377
+ *
378
+ * @see {@link delete} for a higher-level typed alternative
379
+ */
125
380
  deleteRecord(collection: NsidString, rkey: string, options?: DeleteRecordOptions): Promise<XrpcResponse<Procedure<"com.atproto.repo.deleteRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
126
- readonly repo: import("@atproto/lex-schema").StringSchema<{
381
+ repo: import("@atproto/lex-schema").StringSchema<{
127
382
  readonly format: "at-identifier";
128
383
  }>;
129
- readonly collection: import("@atproto/lex-schema").StringSchema<{
384
+ collection: import("@atproto/lex-schema").StringSchema<{
130
385
  readonly format: "nsid";
131
386
  }>;
132
- readonly rkey: import("@atproto/lex-schema").StringSchema<{
387
+ rkey: import("@atproto/lex-schema").StringSchema<{
133
388
  readonly format: "record-key";
134
389
  }>;
135
- readonly swapRecord: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
390
+ swapRecord: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
136
391
  readonly format: "cid";
137
392
  }>>;
138
- readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
393
+ swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
139
394
  readonly format: "cid";
140
395
  }>>;
141
396
  }>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
142
- readonly commit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").RefSchema<import("@atproto/lex-schema").Validator<com.atproto.repo.defs.$defs.CommitMeta, com.atproto.repo.defs.$defs.CommitMeta>>>;
397
+ commit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").RefSchema<import("@atproto/lex-schema").Validator<com.atproto.repo.defs.$defs.CommitMeta, com.atproto.repo.defs.$defs.CommitMeta>>>;
143
398
  }>>, readonly ["InvalidSwap"]>>>;
399
+ /**
400
+ * Retrieves a record from an AT Protocol repository.
401
+ *
402
+ * @param collection - The collection NSID
403
+ * @param rkey - The record key
404
+ * @param options - Get options including repo
405
+ *
406
+ * @see {@link get} for a higher-level typed alternative
407
+ */
144
408
  getRecord(collection: NsidString, rkey: string, options?: GetRecordOptions): Promise<XrpcResponse<Query<"com.atproto.repo.getRecord", import("@atproto/lex-schema").ParamsSchema<{
145
409
  readonly repo: import("@atproto/lex-schema").StringSchema<{
146
410
  readonly format: "at-identifier";
@@ -155,45 +419,60 @@ export declare class Client implements Agent {
155
419
  readonly format: "cid";
156
420
  }>>;
157
421
  }>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
158
- readonly uri: import("@atproto/lex-schema").StringSchema<{
422
+ uri: import("@atproto/lex-schema").StringSchema<{
159
423
  readonly format: "at-uri";
160
424
  }>;
161
- readonly cid: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
425
+ cid: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
162
426
  readonly format: "cid";
163
427
  }>>;
164
- readonly value: import("@atproto/lex-schema").UnknownObjectSchema;
428
+ value: import("@atproto/lex-schema").UnknownObjectSchema;
165
429
  }>>, readonly ["RecordNotFound"]>>>;
166
- putRecord(record: {
167
- $type: NsidString;
168
- } & LexMap, rkey: string, options?: PutRecordOptions): Promise<XrpcResponse<Procedure<"com.atproto.repo.putRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
169
- readonly repo: import("@atproto/lex-schema").StringSchema<{
430
+ /**
431
+ * Creates or updates a record in a repository.
432
+ *
433
+ * @param record - The record to put, must include an {@link NsidString} `$type`
434
+ * @param rkey - The record key
435
+ * @param options - Put options including repo, swapCommit, swapRecord, validate
436
+ *
437
+ * @see {@link put} for a higher-level typed alternative
438
+ */
439
+ putRecord(record: TypedLexMap<NsidString>, rkey: string, options?: PutRecordOptions): Promise<XrpcResponse<Procedure<"com.atproto.repo.putRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
440
+ repo: import("@atproto/lex-schema").StringSchema<{
170
441
  readonly format: "at-identifier";
171
442
  }>;
172
- readonly collection: import("@atproto/lex-schema").StringSchema<{
443
+ collection: import("@atproto/lex-schema").StringSchema<{
173
444
  readonly format: "nsid";
174
445
  }>;
175
- readonly rkey: import("@atproto/lex-schema").StringSchema<{
446
+ rkey: import("@atproto/lex-schema").StringSchema<{
176
447
  readonly format: "record-key";
177
448
  readonly maxLength: 512;
178
449
  }>;
179
- readonly validate: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
180
- readonly record: import("@atproto/lex-schema").UnknownObjectSchema;
181
- readonly swapRecord: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").NullableSchema<import("@atproto/lex-schema").StringSchema<{
450
+ validate: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
451
+ record: import("@atproto/lex-schema").UnknownObjectSchema;
452
+ swapRecord: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").NullableSchema<import("@atproto/lex-schema").StringSchema<{
182
453
  readonly format: "cid";
183
454
  }>>>;
184
- readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
455
+ swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
185
456
  readonly format: "cid";
186
457
  }>>;
187
458
  }>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
188
- readonly uri: import("@atproto/lex-schema").StringSchema<{
459
+ uri: import("@atproto/lex-schema").StringSchema<{
189
460
  readonly format: "at-uri";
190
461
  }>;
191
- readonly cid: import("@atproto/lex-schema").StringSchema<{
462
+ cid: import("@atproto/lex-schema").StringSchema<{
192
463
  readonly format: "cid";
193
464
  }>;
194
- readonly commit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").RefSchema<import("@atproto/lex-schema").Validator<com.atproto.repo.defs.$defs.CommitMeta, com.atproto.repo.defs.$defs.CommitMeta>>>;
195
- readonly validationStatus: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
465
+ commit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").RefSchema<import("@atproto/lex-schema").Validator<com.atproto.repo.defs.$defs.CommitMeta, com.atproto.repo.defs.$defs.CommitMeta>>>;
466
+ validationStatus: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
196
467
  }>>, readonly ["InvalidSwap"]>>>;
468
+ /**
469
+ * Lists records in a collection.
470
+ *
471
+ * @param nsid - The collection NSID
472
+ * @param options - List options including repo, limit, cursor, reverse
473
+ *
474
+ * @see {@link list} for a higher-level typed alternative
475
+ */
197
476
  listRecords(nsid: NsidString, options?: ListRecordsOptions): Promise<XrpcResponse<Query<"com.atproto.repo.listRecords", import("@atproto/lex-schema").ParamsSchema<{
198
477
  readonly repo: import("@atproto/lex-schema").StringSchema<{
199
478
  readonly format: "at-identifier";
@@ -202,19 +481,42 @@ export declare class Client implements Agent {
202
481
  readonly format: "nsid";
203
482
  }>;
204
483
  readonly limit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").WithDefaultSchema<import("@atproto/lex-schema").IntegerSchema>>;
205
- readonly cursor: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
484
+ readonly cursor: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<import("@atproto/lex-schema").StringSchemaOptions>>;
206
485
  readonly reverse: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
207
486
  }>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
208
- readonly cursor: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
209
- readonly records: import("@atproto/lex-schema").ArraySchema<import("@atproto/lex-schema").RefSchema<import("@atproto/lex-schema").Validator<com.atproto.repo.listRecords.$defs.Record, com.atproto.repo.listRecords.$defs.Record>>>;
487
+ cursor: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
488
+ records: import("@atproto/lex-schema").ArraySchema<import("@atproto/lex-schema").RefSchema<import("@atproto/lex-schema").Validator<com.atproto.repo.listRecords.$defs.Record, com.atproto.repo.listRecords.$defs.Record>>>;
210
489
  }>>, undefined>>>;
490
+ /**
491
+ * Uploads a blob to an AT Protocol repository.
492
+ *
493
+ * @param body - The blob data (Uint8Array, ReadableStream, Blob, etc.)
494
+ * @param options - Upload options including encoding hint
495
+ * @returns Response containing the blob reference
496
+ *
497
+ * @example
498
+ * ```typescript
499
+ * const imageData = await fetch('image.png').then(r => r.arrayBuffer())
500
+ * const response = await client.uploadBlob(new Uint8Array(imageData), {
501
+ * encoding: 'image/png'
502
+ * })
503
+ * console.log(response.body.blob) // Use this ref in records
504
+ * ```
505
+ */
211
506
  uploadBlob(body: BinaryBodyInit, options?: CallOptions & {
212
507
  encoding?: `${string}/${string}`;
213
508
  }): Promise<XrpcResponse<Procedure<"com.atproto.repo.uploadBlob", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"*/*", undefined>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
214
- readonly blob: import("@atproto/lex-schema").BlobSchema<{
509
+ blob: import("@atproto/lex-schema").BlobSchema<{
215
510
  allowLegacy: false;
216
511
  }>;
217
512
  }>>, undefined>>>;
513
+ /**
514
+ * Retrieves a blob by DID and CID.
515
+ *
516
+ * @param did - The DID of the repository containing the blob
517
+ * @param cid - The CID of the blob
518
+ * @param options - Call options
519
+ */
218
520
  getBlob(did: DidString, cid: CidString, options?: CallOptions): Promise<XrpcResponse<Query<"com.atproto.sync.getBlob", import("@atproto/lex-schema").ParamsSchema<{
219
521
  readonly did: import("@atproto/lex-schema").StringSchema<{
220
522
  readonly format: "did";
@@ -223,17 +525,111 @@ export declare class Client implements Agent {
223
525
  readonly format: "cid";
224
526
  }>;
225
527
  }>, import("@atproto/lex-schema").Payload<"*/*", undefined>, readonly ["BlobNotFound", "RepoNotFound", "RepoTakendown", "RepoSuspended", "RepoDeactivated"]>>>;
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.main, {
541
+ * actor: 'alice.bsky.social'
542
+ * })
543
+ * ```
544
+ *
545
+ * @example Procedure
546
+ * ```typescript
547
+ * const result = await client.call(com.atproto.repo.createRecord.main, {
548
+ * repo: did,
549
+ * collection: 'app.bsky.feed.post',
550
+ * record: { text: 'Hello!' }
551
+ * })
552
+ * ```
553
+ */
226
554
  call<const T extends Query>(ns: NonNullable<unknown> extends XrpcRequestParams<T> ? Main<T> : Restricted<'This query type requires a "params" argument'>): Promise<XrpcResponseBody<T>>;
555
+ call<const T extends Procedure>(ns: undefined extends InferMethodInputBody<T, Uint8Array> ? Main<T> : Restricted<'This procedure type requires an "input" argument'>): Promise<XrpcResponseBody<T>>;
227
556
  call<const T extends Action>(ns: void extends InferActionInput<T> ? Main<T> : Restricted<'This action type requires an "input" argument'>): Promise<InferActionOutput<T>>;
228
557
  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?: CallOptions): Promise<T extends Action ? InferActionOutput<T> : T extends Procedure ? XrpcResponseBody<T> : T extends Query ? XrpcResponseBody<T> : never>;
558
+ /**
559
+ * Creates a new record with full type safety based on the schema.
560
+ *
561
+ * @param ns - The record schema definition
562
+ * @param input - The record data (without `$type`, which is added automatically)
563
+ * @param options - Create options including rkey (required for some record types)
564
+ * @returns The create output including URI and CID
565
+ *
566
+ * @example Creating a post
567
+ * ```typescript
568
+ * const result = await client.create(app.bsky.feed.post.main, {
569
+ * text: 'Hello, world!',
570
+ * createdAt: new Date().toISOString()
571
+ * })
572
+ * console.log(result.uri)
573
+ * ```
574
+ *
575
+ * @example Creating a record with explicit rkey
576
+ * ```typescript
577
+ * const result = await client.create(app.bsky.actor.profile.main, {
578
+ * displayName: 'Alice'
579
+ * }, { rkey: 'self' })
580
+ * ```
581
+ */
229
582
  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>;
230
583
  create<const T extends RecordSchema>(ns: Main<T>, input: Omit<Infer<T>, '$type'>, options: CreateOptions<T>): Promise<CreateOutput>;
584
+ /**
585
+ * Deletes a record with type-safe options.
586
+ *
587
+ * @param ns - The record schema definition
588
+ * @param options - Delete options (rkey required for non-literal keys)
589
+ * @returns The delete output
590
+ */
231
591
  delete<const T extends RecordSchema>(ns: NonNullable<unknown> extends DeleteOptions<T> ? Main<T> : Restricted<'This record type requires an "options" argument'>): Promise<DeleteOutput>;
232
592
  delete<const T extends RecordSchema>(ns: Main<T>, options?: DeleteOptions<T>): Promise<DeleteOutput>;
593
+ /**
594
+ * Retrieves a record with type-safe validation.
595
+ *
596
+ * @param ns - The record schema definition
597
+ * @param options - Get options (rkey required for non-literal keys)
598
+ * @returns The record data validated against the schema
599
+ *
600
+ * @example
601
+ * ```typescript
602
+ * const profile = await client.get(app.bsky.actor.profile.main)
603
+ * // profile.value is typed as app.bsky.actor.profile.Record
604
+ * console.log(profile.value.displayName)
605
+ * ```
606
+ */
233
607
  get<const T extends RecordSchema>(ns: T['key'] extends `literal:${string}` ? Main<T> : Restricted<'This record type requires an "options" argument'>): Promise<GetOutput<T>>;
234
608
  get<const T extends RecordSchema>(ns: Main<T>, options?: GetOptions<T>): Promise<GetOutput<T>>;
609
+ /**
610
+ * Creates or updates a record with full type safety.
611
+ *
612
+ * @param ns - The record schema definition
613
+ * @param input - The record data
614
+ * @param options - Put options (rkey required for non-literal keys)
615
+ * @returns The put output including URI and CID
616
+ */
235
617
  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>;
236
618
  put<const T extends RecordSchema>(ns: Main<T>, input: Omit<Infer<T>, '$type'>, options: PutOptions<T>): Promise<PutOutput>;
619
+ /**
620
+ * Lists records with type-safe validation and separation of valid/invalid records.
621
+ *
622
+ * @param ns - The record schema definition
623
+ * @param options - List options
624
+ * @returns Records split into valid (matching schema) and invalid arrays
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * const result = await client.list(app.bsky.feed.post.main, { limit: 100 })
629
+ * console.log(`Found ${result.records.length} valid posts`)
630
+ * console.log(`Found ${result.invalid.length} invalid records`)
631
+ * ```
632
+ */
237
633
  list<const T extends RecordSchema>(ns: Main<T>, options?: ListOptions): Promise<ListOutput<T>>;
238
634
  }
239
635
  //# sourceMappingURL=client.d.ts.map