@atproto/lex-client 0.0.11 → 0.0.13

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 (71) hide show
  1. package/CHANGELOG.md +26 -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 +443 -45
  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 +29 -25
  15. package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
  16. package/dist/lexicons/com/atproto/repo/createRecord.defs.js +3 -2
  17. package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
  18. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +17 -17
  19. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
  20. package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
  21. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +9 -9
  22. package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
  23. package/dist/lexicons/com/atproto/repo/getRecord.defs.js +1 -1
  24. package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
  25. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +8 -8
  26. package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
  27. package/dist/lexicons/com/atproto/repo/listRecords.defs.js +1 -1
  28. package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
  29. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +31 -27
  30. package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
  31. package/dist/lexicons/com/atproto/repo/putRecord.defs.js +3 -2
  32. package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
  33. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +7 -7
  34. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
  35. package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
  36. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts +3 -3
  37. package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts.map +1 -1
  38. package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -1
  39. package/dist/response.d.ts +14 -4
  40. package/dist/response.d.ts.map +1 -1
  41. package/dist/response.js +19 -9
  42. package/dist/response.js.map +1 -1
  43. package/dist/types.d.ts +51 -0
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/types.js.map +1 -1
  46. package/dist/util.d.ts +40 -5
  47. package/dist/util.d.ts.map +1 -1
  48. package/dist/util.js +22 -0
  49. package/dist/util.js.map +1 -1
  50. package/dist/www-authenticate.d.ts +23 -0
  51. package/dist/www-authenticate.d.ts.map +1 -1
  52. package/dist/www-authenticate.js.map +1 -1
  53. package/dist/xrpc.d.ts +81 -1
  54. package/dist/xrpc.d.ts.map +1 -1
  55. package/dist/xrpc.js.map +1 -1
  56. package/package.json +7 -7
  57. package/src/agent.ts +67 -0
  58. package/src/client.ts +424 -11
  59. package/src/errors.ts +165 -12
  60. package/src/lexicons/com/atproto/repo/createRecord.defs.ts +15 -7
  61. package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +11 -5
  62. package/src/lexicons/com/atproto/repo/getRecord.defs.ts +7 -4
  63. package/src/lexicons/com/atproto/repo/listRecords.defs.ts +8 -5
  64. package/src/lexicons/com/atproto/repo/putRecord.defs.ts +15 -7
  65. package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +11 -5
  66. package/src/lexicons/com/atproto/sync/getBlob.defs.ts +6 -3
  67. package/src/response.ts +22 -19
  68. package/src/types.ts +52 -0
  69. package/src/util.ts +50 -5
  70. package/src/www-authenticate.ts +24 -0
  71. package/src/xrpc.ts +83 -4
package/dist/client.d.ts CHANGED
@@ -1,43 +1,123 @@
1
- import { LexMap, LexValue } from '@atproto/lex-data';
2
- import { AtIdentifierString, CidString, DidString, Infer, InferMethodInputBody, InferMethodOutputBody, InferRecordKey, LexiconRecordKey, Main, NsidString, Params, Procedure, Query, RecordSchema, Restricted, UnknownObject } from '@atproto/lex-schema';
1
+ import { LexMap, LexValue, TypedLexMap } from '@atproto/lex-data';
2
+ import { AtIdentifierString, CidString, DidString, Infer, InferMethodInputBody, InferMethodOutputBody, InferRecordKey, LexiconRecordKey, Main, NsidString, Params, Procedure, Query, RecordSchema, Restricted } from '@atproto/lex-schema';
3
3
  import { Agent, AgentOptions } from './agent.js';
4
4
  import { XrpcFailure } from './errors.js';
5
5
  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>>[];
61
- invalid: UnknownObject[];
182
+ /** Records that failed schema validation. */
183
+ invalid: LexMap[];
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,201 @@ 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").LexMapSchema;
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<{
370
+ knownValues: ["valid", "unknown"];
371
+ }>>;
125
372
  }>>, readonly ["InvalidSwap"]>>>;
373
+ /**
374
+ * Deletes a record from an AT Protocol repository.
375
+ *
376
+ * @param collection - The collection NSID
377
+ * @param rkey - The record key
378
+ * @param options - Delete options including repo, swapCommit, swapRecord
379
+ *
380
+ * @see {@link delete} for a higher-level typed alternative
381
+ */
126
382
  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<{
383
+ repo: import("@atproto/lex-schema").StringSchema<{
128
384
  readonly format: "at-identifier";
129
385
  }>;
130
- readonly collection: import("@atproto/lex-schema").StringSchema<{
386
+ collection: import("@atproto/lex-schema").StringSchema<{
131
387
  readonly format: "nsid";
132
388
  }>;
133
- readonly rkey: import("@atproto/lex-schema").StringSchema<{
389
+ rkey: import("@atproto/lex-schema").StringSchema<{
134
390
  readonly format: "record-key";
135
391
  }>;
136
- readonly swapRecord: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
392
+ swapRecord: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
137
393
  readonly format: "cid";
138
394
  }>>;
139
- readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
395
+ swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
140
396
  readonly format: "cid";
141
397
  }>>;
142
398
  }>>, 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>>>;
399
+ 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
400
  }>>, readonly ["InvalidSwap"]>>>;
401
+ /**
402
+ * Retrieves a record from an AT Protocol repository.
403
+ *
404
+ * @param collection - The collection NSID
405
+ * @param rkey - The record key
406
+ * @param options - Get options including repo
407
+ *
408
+ * @see {@link get} for a higher-level typed alternative
409
+ */
145
410
  getRecord(collection: NsidString, rkey: string, options?: GetRecordOptions): Promise<XrpcResponse<Query<"com.atproto.repo.getRecord", import("@atproto/lex-schema").ParamsSchema<{
146
411
  readonly repo: import("@atproto/lex-schema").StringSchema<{
147
412
  readonly format: "at-identifier";
@@ -156,45 +421,62 @@ export declare class Client implements Agent {
156
421
  readonly format: "cid";
157
422
  }>>;
158
423
  }>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
159
- readonly uri: import("@atproto/lex-schema").StringSchema<{
424
+ uri: import("@atproto/lex-schema").StringSchema<{
160
425
  readonly format: "at-uri";
161
426
  }>;
162
- readonly cid: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
427
+ cid: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
163
428
  readonly format: "cid";
164
429
  }>>;
165
- readonly value: import("@atproto/lex-schema").UnknownObjectSchema;
430
+ value: import("@atproto/lex-schema").LexMapSchema;
166
431
  }>>, 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<{
432
+ /**
433
+ * Creates or updates a record in a repository.
434
+ *
435
+ * @param record - The record to put, must include an {@link NsidString} `$type`
436
+ * @param rkey - The record key
437
+ * @param options - Put options including repo, swapCommit, swapRecord, validate
438
+ *
439
+ * @see {@link put} for a higher-level typed alternative
440
+ */
441
+ 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<{
442
+ repo: import("@atproto/lex-schema").StringSchema<{
171
443
  readonly format: "at-identifier";
172
444
  }>;
173
- readonly collection: import("@atproto/lex-schema").StringSchema<{
445
+ collection: import("@atproto/lex-schema").StringSchema<{
174
446
  readonly format: "nsid";
175
447
  }>;
176
- readonly rkey: import("@atproto/lex-schema").StringSchema<{
448
+ rkey: import("@atproto/lex-schema").StringSchema<{
177
449
  readonly format: "record-key";
178
450
  readonly maxLength: 512;
179
451
  }>;
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<{
452
+ validate: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
453
+ record: import("@atproto/lex-schema").LexMapSchema;
454
+ swapRecord: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").NullableSchema<import("@atproto/lex-schema").StringSchema<{
183
455
  readonly format: "cid";
184
456
  }>>>;
185
- readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
457
+ swapCommit: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
186
458
  readonly format: "cid";
187
459
  }>>;
188
460
  }>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
189
- readonly uri: import("@atproto/lex-schema").StringSchema<{
461
+ uri: import("@atproto/lex-schema").StringSchema<{
190
462
  readonly format: "at-uri";
191
463
  }>;
192
- readonly cid: import("@atproto/lex-schema").StringSchema<{
464
+ cid: import("@atproto/lex-schema").StringSchema<{
193
465
  readonly format: "cid";
194
466
  }>;
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<{}>>;
467
+ 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>>>;
468
+ validationStatus: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{
469
+ knownValues: ["valid", "unknown"];
470
+ }>>;
197
471
  }>>, readonly ["InvalidSwap"]>>>;
472
+ /**
473
+ * Lists records in a collection.
474
+ *
475
+ * @param nsid - The collection NSID
476
+ * @param options - List options including repo, limit, cursor, reverse
477
+ *
478
+ * @see {@link list} for a higher-level typed alternative
479
+ */
198
480
  listRecords(nsid: NsidString, options?: ListRecordsOptions): Promise<XrpcResponse<Query<"com.atproto.repo.listRecords", import("@atproto/lex-schema").ParamsSchema<{
199
481
  readonly repo: import("@atproto/lex-schema").StringSchema<{
200
482
  readonly format: "at-identifier";
@@ -206,16 +488,39 @@ export declare class Client implements Agent {
206
488
  readonly cursor: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
207
489
  readonly reverse: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").BooleanSchema>;
208
490
  }>, 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>>>;
491
+ cursor: import("@atproto/lex-schema").OptionalSchema<import("@atproto/lex-schema").StringSchema<{}>>;
492
+ 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
493
  }>>, undefined>>>;
494
+ /**
495
+ * Uploads a blob to an AT Protocol repository.
496
+ *
497
+ * @param body - The blob data (Uint8Array, ReadableStream, Blob, etc.)
498
+ * @param options - Upload options including encoding hint
499
+ * @returns Response containing the blob reference
500
+ *
501
+ * @example
502
+ * ```typescript
503
+ * const imageData = await fetch('image.png').then(r => r.arrayBuffer())
504
+ * const response = await client.uploadBlob(new Uint8Array(imageData), {
505
+ * encoding: 'image/png'
506
+ * })
507
+ * console.log(response.body.blob) // Use this ref in records
508
+ * ```
509
+ */
212
510
  uploadBlob(body: BinaryBodyInit, options?: CallOptions & {
213
511
  encoding?: `${string}/${string}`;
214
512
  }): 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<{
513
+ blob: import("@atproto/lex-schema").BlobSchema<{
216
514
  allowLegacy: false;
217
515
  }>;
218
516
  }>>, undefined>>>;
517
+ /**
518
+ * Retrieves a blob by DID and CID.
519
+ *
520
+ * @param did - The DID of the repository containing the blob
521
+ * @param cid - The CID of the blob
522
+ * @param options - Call options
523
+ */
219
524
  getBlob(did: DidString, cid: CidString, options?: CallOptions): Promise<XrpcResponse<Query<"com.atproto.sync.getBlob", import("@atproto/lex-schema").ParamsSchema<{
220
525
  readonly did: import("@atproto/lex-schema").StringSchema<{
221
526
  readonly format: "did";
@@ -224,18 +529,111 @@ export declare class Client implements Agent {
224
529
  readonly format: "cid";
225
530
  }>;
226
531
  }>, import("@atproto/lex-schema").Payload<"*/*", undefined>, readonly ["BlobNotFound", "RepoNotFound", "RepoTakendown", "RepoSuspended", "RepoDeactivated"]>>>;
532
+ /**
533
+ * Universal call method for queries, procedures, and custom actions.
534
+ * Automatically determines the call type based on the lexicon definition.
535
+ *
536
+ * @param ns - The lexicon method or action definition
537
+ * @param arg - The input argument (params for queries, body for procedures, input for actions)
538
+ * @param options - Call options
539
+ * @returns The method response body or action output
540
+ * @see {@link xrpc} if you need access to the full response object
541
+ *
542
+ * @example Query
543
+ * ```typescript
544
+ * const profile = await client.call(app.bsky.actor.getProfile.main, {
545
+ * actor: 'alice.bsky.social'
546
+ * })
547
+ * ```
548
+ *
549
+ * @example Procedure
550
+ * ```typescript
551
+ * const result = await client.call(com.atproto.repo.createRecord.main, {
552
+ * repo: did,
553
+ * collection: 'app.bsky.feed.post',
554
+ * record: { text: 'Hello!' }
555
+ * })
556
+ * ```
557
+ */
227
558
  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
559
  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
560
  call<const T extends Action>(ns: void extends InferActionInput<T> ? Main<T> : Restricted<'This action type requires an "input" argument'>): Promise<InferActionOutput<T>>;
230
561
  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>;
562
+ /**
563
+ * Creates a new record with full type safety based on the schema.
564
+ *
565
+ * @param ns - The record schema definition
566
+ * @param input - The record data (without `$type`, which is added automatically)
567
+ * @param options - Create options including rkey (required for some record types)
568
+ * @returns The create output including URI and CID
569
+ *
570
+ * @example Creating a post
571
+ * ```typescript
572
+ * const result = await client.create(app.bsky.feed.post.main, {
573
+ * text: 'Hello, world!',
574
+ * createdAt: new Date().toISOString()
575
+ * })
576
+ * console.log(result.uri)
577
+ * ```
578
+ *
579
+ * @example Creating a record with explicit rkey
580
+ * ```typescript
581
+ * const result = await client.create(app.bsky.actor.profile.main, {
582
+ * displayName: 'Alice'
583
+ * }, { rkey: 'self' })
584
+ * ```
585
+ */
231
586
  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
587
  create<const T extends RecordSchema>(ns: Main<T>, input: Omit<Infer<T>, '$type'>, options: CreateOptions<T>): Promise<CreateOutput>;
588
+ /**
589
+ * Deletes a record with type-safe options.
590
+ *
591
+ * @param ns - The record schema definition
592
+ * @param options - Delete options (rkey required for non-literal keys)
593
+ * @returns The delete output
594
+ */
233
595
  delete<const T extends RecordSchema>(ns: NonNullable<unknown> extends DeleteOptions<T> ? Main<T> : Restricted<'This record type requires an "options" argument'>): Promise<DeleteOutput>;
234
596
  delete<const T extends RecordSchema>(ns: Main<T>, options?: DeleteOptions<T>): Promise<DeleteOutput>;
597
+ /**
598
+ * Retrieves a record with type-safe validation.
599
+ *
600
+ * @param ns - The record schema definition
601
+ * @param options - Get options (rkey required for non-literal keys)
602
+ * @returns The record data validated against the schema
603
+ *
604
+ * @example
605
+ * ```typescript
606
+ * const profile = await client.get(app.bsky.actor.profile.main)
607
+ * // profile.value is typed as app.bsky.actor.profile.Record
608
+ * console.log(profile.value.displayName)
609
+ * ```
610
+ */
235
611
  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
612
  get<const T extends RecordSchema>(ns: Main<T>, options?: GetOptions<T>): Promise<GetOutput<T>>;
613
+ /**
614
+ * Creates or updates a record with full type safety.
615
+ *
616
+ * @param ns - The record schema definition
617
+ * @param input - The record data
618
+ * @param options - Put options (rkey required for non-literal keys)
619
+ * @returns The put output including URI and CID
620
+ */
237
621
  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
622
  put<const T extends RecordSchema>(ns: Main<T>, input: Omit<Infer<T>, '$type'>, options: PutOptions<T>): Promise<PutOutput>;
623
+ /**
624
+ * Lists records with type-safe validation and separation of valid/invalid records.
625
+ *
626
+ * @param ns - The record schema definition
627
+ * @param options - List options
628
+ * @returns Records split into valid (matching schema) and invalid arrays
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * const result = await client.list(app.bsky.feed.post.main, { limit: 100 })
633
+ * console.log(`Found ${result.records.length} valid posts`)
634
+ * console.log(`Found ${result.invalid.length} invalid records`)
635
+ * ```
636
+ */
239
637
  list<const T extends RecordSchema>(ns: Main<T>, options?: ListOptions): Promise<ListOutput<T>>;
240
638
  }
241
639
  //# sourceMappingURL=client.d.ts.map