@atproto/lex-client 0.0.11 → 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 (45) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/agent.d.ts +67 -0
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +31 -0
  5. package/dist/agent.js.map +1 -1
  6. package/dist/client.d.ts +438 -44
  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 +162 -9
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/errors.js +132 -8
  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 +14 -4
  21. package/dist/response.d.ts.map +1 -1
  22. package/dist/response.js +19 -9
  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 +23 -0
  32. package/dist/www-authenticate.d.ts.map +1 -1
  33. package/dist/www-authenticate.js.map +1 -1
  34. package/dist/xrpc.d.ts +81 -1
  35. package/dist/xrpc.d.ts.map +1 -1
  36. package/dist/xrpc.js.map +1 -1
  37. package/package.json +7 -7
  38. package/src/agent.ts +67 -0
  39. package/src/client.ts +420 -7
  40. package/src/errors.ts +165 -12
  41. package/src/response.ts +22 -19
  42. package/src/types.ts +52 -0
  43. package/src/util.ts +50 -5
  44. package/src/www-authenticate.ts +24 -0
  45. package/src/xrpc.ts +83 -4
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
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
4
  import { XrpcFailure } from './errors.js';
@@ -6,38 +6,118 @@ import { com } from './lexicons/index.js';
6
6
  import { XrpcResponse, XrpcResponseBody } from './response.js';
7
7
  import { BinaryBodyInit, CallOptions, Service } from './types.js';
8
8
  import { XrpcOptions, XrpcRequestParams } from './xrpc.js';
9
- export type { AtIdentifierString, CidString, DidString, InferMethodInputBody, InferMethodOutputBody, InferRecordKey, LexMap, LexValue, LexiconRecordKey, NsidString, Params, Procedure, Query, RecordSchema, Restricted, };
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
+ */
10
22
  export type ClientOptions = {
23
+ /** Labeler DIDs to include in requests for content moderation. */
11
24
  labelers?: Iterable<DidString>;
25
+ /** Custom headers to include in all requests made by this client. */
12
26
  headers?: HeadersInit;
27
+ /** Service proxy identifier for routing requests through a specific service. */
13
28
  service?: Service;
14
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
+ */
15
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
+ */
16
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
+ */
17
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
+ */
18
63
  export type CreateRecordOptions = CallOptions & {
64
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
19
65
  repo?: AtIdentifierString;
66
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
20
67
  swapCommit?: string;
68
+ /** Whether to validate the record against its lexicon schema. */
21
69
  validate?: boolean;
22
70
  };
71
+ /**
72
+ * Options for deleting a record from an AT Protocol repository.
73
+ *
74
+ * @see {@link Client.deleteRecord}
75
+ */
23
76
  export type DeleteRecordOptions = CallOptions & {
77
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
24
78
  repo?: AtIdentifierString;
79
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
25
80
  swapCommit?: string;
81
+ /** Compare-and-swap on the record CID. If specified, must match current record. */
26
82
  swapRecord?: string;
27
83
  };
84
+ /**
85
+ * Options for retrieving a record from an AT Protocol repository.
86
+ *
87
+ * @see {@link Client.getRecord}
88
+ */
28
89
  export type GetRecordOptions = CallOptions & {
90
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
29
91
  repo?: AtIdentifierString;
30
92
  };
93
+ /**
94
+ * Options for creating or updating a record in an AT Protocol repository.
95
+ *
96
+ * @see {@link Client.putRecord}
97
+ */
31
98
  export type PutRecordOptions = CallOptions & {
99
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
32
100
  repo?: AtIdentifierString;
101
+ /** Compare-and-swap on the repo commit. If specified, must match current commit. */
33
102
  swapCommit?: string;
103
+ /** Compare-and-swap on the record CID. If specified, must match current record. */
34
104
  swapRecord?: string;
105
+ /** Whether to validate the record against its lexicon schema. */
35
106
  validate?: boolean;
36
107
  };
108
+ /**
109
+ * Options for listing records in an AT Protocol repository collection.
110
+ *
111
+ * @see {@link Client.listRecords}
112
+ */
37
113
  export type ListRecordsOptions = CallOptions & {
114
+ /** Repository identifier (DID or handle). Defaults to authenticated user's DID. */
38
115
  repo?: AtIdentifierString;
116
+ /** Maximum number of records to return. */
39
117
  limit?: number;
118
+ /** Pagination cursor from a previous response. */
40
119
  cursor?: string;
120
+ /** If true, returns records in reverse chronological order. */
41
121
  reverse?: boolean;
42
122
  };
43
123
  export type RecordKeyOptions<T extends RecordSchema, AlsoOptionalWhenRecordKeyIs extends LexiconRecordKey = never> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs ? {
@@ -45,24 +125,85 @@ export type RecordKeyOptions<T extends RecordSchema, AlsoOptionalWhenRecordKeyIs
45
125
  } : {
46
126
  rkey: InferRecordKey<T>;
47
127
  };
128
+ /**
129
+ * Type-safe options for {@link Client.create}, combining record options with key requirements.
130
+ * @typeParam T - The record schema type
131
+ */
48
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
+ */
49
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
+ */
50
142
  export type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions & RecordKeyOptions<T>;
143
+ /**
144
+ * Output type for record deletion operations.
145
+ */
51
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
+ */
52
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
+ */
53
157
  export type GetOutput<T extends RecordSchema> = Omit<InferMethodOutputBody<typeof com.atproto.repo.getRecord.main, Uint8Array>, 'value'> & {
54
158
  value: Infer<T>;
55
159
  };
160
+ /**
161
+ * Type-safe options for {@link Client.put}, combining put options with key requirements.
162
+ * @typeParam T - The record schema type
163
+ */
56
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
+ */
57
169
  export type PutOutput = InferMethodOutputBody<typeof com.atproto.repo.putRecord.main, Uint8Array>;
170
+ /**
171
+ * Options for {@link Client.list} operations.
172
+ */
58
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
+ */
59
179
  export type ListOutput<T extends RecordSchema> = InferMethodOutputBody<typeof com.atproto.repo.listRecords.main, Uint8Array> & {
180
+ /** Records that successfully validated against the schema. */
60
181
  records: ListRecord<Infer<T>>[];
182
+ /** Records that failed schema validation. */
61
183
  invalid: UnknownObject[];
62
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
+ */
63
189
  export type ListRecord<Value extends LexMap> = com.atproto.repo.listRecords.Record & {
64
190
  value: Value;
65
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
+ */
66
207
  export declare class Client implements Agent {
67
208
  static appLabelers: readonly DidString[];
68
209
  /**
@@ -71,77 +212,199 @@ export declare class Client implements Agent {
71
212
  static configure(opts: {
72
213
  appLabelers?: Iterable<DidString>;
73
214
  }): void;
215
+ /** The underlying agent used for making requests. */
74
216
  readonly agent: Agent;
217
+ /** Custom headers included in all requests. */
75
218
  readonly headers: Headers;
219
+ /** Optional service identifier for routing requests. */
76
220
  readonly service?: Service;
221
+ /** Set of labeler DIDs specific to this client instance. */
77
222
  readonly labelers: Set<DidString>;
78
223
  constructor(agent: Agent | AgentOptions, options?: ClientOptions);
224
+ /**
225
+ * The DID of the authenticated user, or `undefined` if not authenticated.
226
+ */
79
227
  get did(): DidString | undefined;
228
+ /**
229
+ * The DID of the authenticated user.
230
+ * @throws {LexError} with code 'AuthenticationRequired' if not authenticated
231
+ */
80
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
+ */
81
246
  assertAuthenticated(): asserts this is {
82
247
  did: DidString;
83
248
  };
249
+ /**
250
+ * Replaces all labelers with the given set.
251
+ * @param labelers - Iterable of labeler DIDs
252
+ */
84
253
  setLabelers(labelers?: Iterable<DidString>): void;
254
+ /**
255
+ * Adds labelers to the current set.
256
+ * @param labelers - Iterable of labeler DIDs to add
257
+ */
85
258
  addLabelers(labelers: Iterable<DidString>): void;
259
+ /**
260
+ * Removes all labelers from this client instance.
261
+ */
86
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
+ */
87
268
  fetchHandler(path: string, init: RequestInit): Promise<Response>;
88
269
  /**
89
- * @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
90
297
  */
91
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>>;
92
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
+ */
93
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>>;
94
324
  xrpcSafe<const M extends Query | Procedure>(ns: Main<M>, options: XrpcOptions<M>): Promise<XrpcResponse<M> | XrpcFailure<M>>;
95
325
  /**
96
- * @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
97
344
  */
98
- createRecord(record: {
99
- $type: NsidString;
100
- } & 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<{
101
- 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<{
102
347
  readonly format: "at-identifier";
103
348
  }>;
104
- readonly collection: import("@atproto/lex-schema").StringSchema<{
349
+ collection: import("@atproto/lex-schema").StringSchema<{
105
350
  readonly format: "nsid";
106
351
  }>;
107
- readonly rkey: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
352
+ rkey: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
108
353
  readonly format: "record-key";
109
354
  readonly maxLength: 512;
110
355
  }>>;
111
- readonly validate: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
112
- readonly record: import("@atproto/lex-schema").UnknownObjectSchema;
113
- 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<{
114
359
  readonly format: "cid";
115
360
  }>>;
116
361
  }>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
117
- readonly uri: import("@atproto/lex-schema").StringSchema<{
362
+ uri: import("@atproto/lex-schema").StringSchema<{
118
363
  readonly format: "at-uri";
119
364
  }>;
120
- readonly cid: import("@atproto/lex-schema").StringSchema<{
365
+ cid: import("@atproto/lex-schema").StringSchema<{
121
366
  readonly format: "cid";
122
367
  }>;
123
- 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>>>;
124
- 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<{}>>;
125
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
+ */
126
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<{
127
- readonly repo: import("@atproto/lex-schema").StringSchema<{
381
+ repo: import("@atproto/lex-schema").StringSchema<{
128
382
  readonly format: "at-identifier";
129
383
  }>;
130
- readonly collection: import("@atproto/lex-schema").StringSchema<{
384
+ collection: import("@atproto/lex-schema").StringSchema<{
131
385
  readonly format: "nsid";
132
386
  }>;
133
- readonly rkey: import("@atproto/lex-schema").StringSchema<{
387
+ rkey: import("@atproto/lex-schema").StringSchema<{
134
388
  readonly format: "record-key";
135
389
  }>;
136
- readonly swapRecord: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
390
+ swapRecord: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
137
391
  readonly format: "cid";
138
392
  }>>;
139
- readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
393
+ swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
140
394
  readonly format: "cid";
141
395
  }>>;
142
396
  }>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
143
- 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>>>;
144
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
+ */
145
408
  getRecord(collection: NsidString, rkey: string, options?: GetRecordOptions): Promise<XrpcResponse<Query<"com.atproto.repo.getRecord", import("@atproto/lex-schema").ParamsSchema<{
146
409
  readonly repo: import("@atproto/lex-schema").StringSchema<{
147
410
  readonly format: "at-identifier";
@@ -156,45 +419,60 @@ export declare class Client implements Agent {
156
419
  readonly format: "cid";
157
420
  }>>;
158
421
  }>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
159
- readonly uri: import("@atproto/lex-schema").StringSchema<{
422
+ uri: import("@atproto/lex-schema").StringSchema<{
160
423
  readonly format: "at-uri";
161
424
  }>;
162
- readonly cid: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
425
+ cid: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
163
426
  readonly format: "cid";
164
427
  }>>;
165
- readonly value: import("@atproto/lex-schema").UnknownObjectSchema;
428
+ value: import("@atproto/lex-schema").UnknownObjectSchema;
166
429
  }>>, readonly ["RecordNotFound"]>>>;
167
- putRecord(record: {
168
- $type: NsidString;
169
- } & 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<{
170
- 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<{
171
441
  readonly format: "at-identifier";
172
442
  }>;
173
- readonly collection: import("@atproto/lex-schema").StringSchema<{
443
+ collection: import("@atproto/lex-schema").StringSchema<{
174
444
  readonly format: "nsid";
175
445
  }>;
176
- readonly rkey: import("@atproto/lex-schema").StringSchema<{
446
+ rkey: import("@atproto/lex-schema").StringSchema<{
177
447
  readonly format: "record-key";
178
448
  readonly maxLength: 512;
179
449
  }>;
180
- readonly validate: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
181
- readonly record: import("@atproto/lex-schema").UnknownObjectSchema;
182
- 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<{
183
453
  readonly format: "cid";
184
454
  }>>>;
185
- readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
455
+ swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
186
456
  readonly format: "cid";
187
457
  }>>;
188
458
  }>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
189
- readonly uri: import("@atproto/lex-schema").StringSchema<{
459
+ uri: import("@atproto/lex-schema").StringSchema<{
190
460
  readonly format: "at-uri";
191
461
  }>;
192
- readonly cid: import("@atproto/lex-schema").StringSchema<{
462
+ cid: import("@atproto/lex-schema").StringSchema<{
193
463
  readonly format: "cid";
194
464
  }>;
195
- 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>>>;
196
- 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<{}>>;
197
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
+ */
198
476
  listRecords(nsid: NsidString, options?: ListRecordsOptions): Promise<XrpcResponse<Query<"com.atproto.repo.listRecords", import("@atproto/lex-schema").ParamsSchema<{
199
477
  readonly repo: import("@atproto/lex-schema").StringSchema<{
200
478
  readonly format: "at-identifier";
@@ -203,19 +481,42 @@ export declare class Client implements Agent {
203
481
  readonly format: "nsid";
204
482
  }>;
205
483
  readonly limit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").WithDefaultSchema<import("@atproto/lex-schema").IntegerSchema>>;
206
- 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>>;
207
485
  readonly reverse: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
208
486
  }>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
209
- readonly cursor: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
210
- 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>>>;
211
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
+ */
212
506
  uploadBlob(body: BinaryBodyInit, options?: CallOptions & {
213
507
  encoding?: `${string}/${string}`;
214
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<{
215
- readonly blob: import("@atproto/lex-schema").BlobSchema<{
509
+ blob: import("@atproto/lex-schema").BlobSchema<{
216
510
  allowLegacy: false;
217
511
  }>;
218
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
+ */
219
520
  getBlob(did: DidString, cid: CidString, options?: CallOptions): Promise<XrpcResponse<Query<"com.atproto.sync.getBlob", import("@atproto/lex-schema").ParamsSchema<{
220
521
  readonly did: import("@atproto/lex-schema").StringSchema<{
221
522
  readonly format: "did";
@@ -224,18 +525,111 @@ export declare class Client implements Agent {
224
525
  readonly format: "cid";
225
526
  }>;
226
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
+ */
227
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>>;
228
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>>;
229
556
  call<const T extends Action>(ns: void extends InferActionInput<T> ? Main<T> : Restricted<'This action type requires an "input" argument'>): Promise<InferActionOutput<T>>;
230
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
+ */
231
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>;
232
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
+ */
233
591
  delete<const T extends RecordSchema>(ns: NonNullable<unknown> extends DeleteOptions<T> ? Main<T> : Restricted<'This record type requires an "options" argument'>): Promise<DeleteOutput>;
234
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
+ */
235
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>>;
236
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
+ */
237
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>;
238
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
+ */
239
633
  list<const T extends RecordSchema>(ns: Main<T>, options?: ListOptions): Promise<ListOutput<T>>;
240
634
  }
241
635
  //# sourceMappingURL=client.d.ts.map