@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/errors.d.ts CHANGED
@@ -1,11 +1,35 @@
1
1
  import { LexError, LexErrorCode, LexErrorData } from '@atproto/lex-data';
2
2
  import { InferMethodError, Procedure, Query, ResultFailure } from '@atproto/lex-schema';
3
- import { XrpcPayload } from './util.js';
3
+ import { XrpcResponsePayload } from './util.js';
4
4
  import { WWWAuthenticate } from './www-authenticate.js';
5
+ /**
6
+ * HTTP status codes that indicate a transient error that may succeed on retry.
7
+ *
8
+ * Includes:
9
+ * - 408 Request Timeout
10
+ * - 425 Too Early
11
+ * - 429 Too Many Requests (rate limited)
12
+ * - 500 Internal Server Error
13
+ * - 502 Bad Gateway
14
+ * - 503 Service Unavailable
15
+ * - 504 Gateway Timeout
16
+ * - 522 Connection Timed Out (Cloudflare)
17
+ * - 524 A Timeout Occurred (Cloudflare)
18
+ */
5
19
  export declare const RETRYABLE_HTTP_STATUS_CODES: ReadonlySet<number>;
6
20
  export { LexError };
7
21
  export type { LexErrorCode, LexErrorData };
8
- export type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> = XrpcPayload<LexErrorData<N>, 'application/json'>;
22
+ /**
23
+ * The payload structure for XRPC error responses.
24
+ *
25
+ * All XRPC errors return JSON with an `error` code and optional `message`.
26
+ *
27
+ * @typeParam N - The specific error code type
28
+ */
29
+ export type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> = {
30
+ body: LexErrorData<N>;
31
+ encoding: 'application/json';
32
+ };
9
33
  /**
10
34
  * All unsuccessful responses should follow a standard error response
11
35
  * schema. The Content-Type should be application/json, and the payload
@@ -18,7 +42,21 @@ export type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> = XrpcPayloa
18
42
  *
19
43
  * This function checks whether a given payload matches this schema.
20
44
  */
21
- export declare function isXrpcErrorPayload(payload: XrpcPayload | null): payload is XrpcErrorPayload;
45
+ export declare function isXrpcErrorPayload(payload: XrpcResponsePayload | null | undefined): payload is XrpcErrorPayload;
46
+ /**
47
+ * Abstract base class for all XRPC errors.
48
+ *
49
+ * Extends {@link LexError} and implements {@link ResultFailure} for use with
50
+ * safe/result-based error handling patterns.
51
+ *
52
+ * @typeParam M - The XRPC method type (Procedure or Query)
53
+ * @typeParam N - The error code type
54
+ * @typeParam TReason - The reason type for ResultFailure
55
+ *
56
+ * @see {@link XrpcResponseError} - For valid XRPC error responses
57
+ * @see {@link XrpcUpstreamError} - For invalid/unexpected responses
58
+ * @see {@link XrpcInternalError} - For network/internal errors
59
+ */
22
60
  export declare abstract class XrpcError<M extends Procedure | Query = Procedure | Query, N extends LexErrorCode = LexErrorCode, TReason = unknown> extends LexError<N> implements ResultFailure<TReason> {
23
61
  readonly method: M;
24
62
  name: string;
@@ -38,8 +76,28 @@ export declare abstract class XrpcError<M extends Procedure | Query = Procedure
38
76
  matchesSchema(): this is XrpcError<M, InferMethodError<M>>;
39
77
  }
40
78
  /**
41
- * Class used to represent an HTTP request that resulted in an XRPC method
42
- * error. That is, a non-2xx response with a valid XRPC error payload.
79
+ * Error class for valid XRPC error responses from the server.
80
+ *
81
+ * This represents a properly formatted XRPC error where the server returned
82
+ * a non-2xx status with a valid JSON error payload containing `error` and
83
+ * optional `message` fields.
84
+ *
85
+ * Use {@link matchesSchema} to check if the error matches the method's declared
86
+ * error types for type-safe error handling.
87
+ *
88
+ * @typeParam M - The XRPC method type
89
+ * @typeParam N - The error code type (inferred from method or generic)
90
+ *
91
+ * @example Handling specific errors
92
+ * ```typescript
93
+ * try {
94
+ * await client.xrpc(someMethod, options)
95
+ * } catch (err) {
96
+ * if (err instanceof XrpcResponseError && err.error === 'RecordNotFound') {
97
+ * // Handle not found case
98
+ * }
99
+ * }
100
+ * ```
43
101
  */
44
102
  export declare class XrpcResponseError<M extends Procedure | Query = Procedure | Query, N extends LexErrorCode = InferMethodError<M> | LexErrorCode> extends XrpcError<M, N, XrpcResponseError<M, N>> {
45
103
  readonly response: Response;
@@ -53,25 +111,81 @@ export declare class XrpcResponseError<M extends Procedure | Query = Procedure |
53
111
  get body(): LexErrorData;
54
112
  }
55
113
  export type { WWWAuthenticate };
114
+ /**
115
+ * Error class for 401 Unauthorized XRPC responses.
116
+ *
117
+ * Extends {@link XrpcResponseError} with access to parsed WWW-Authenticate header
118
+ * information, useful for implementing authentication flows.
119
+ *
120
+ * Authentication errors are never retryable as they require user intervention
121
+ * (e.g., re-authentication, token refresh).
122
+ *
123
+ * @typeParam M - The XRPC method type
124
+ * @typeParam N - The error code type
125
+ *
126
+ * @example Handling authentication errors
127
+ * ```typescript
128
+ * try {
129
+ * await client.xrpc(someMethod, options)
130
+ * } catch (err) {
131
+ * if (err instanceof XrpcAuthenticationError) {
132
+ * const { DPoP } = err.wwwAuthenticate
133
+ * if (DPoP?.error === 'use_dpop_nonce') {
134
+ * // Handle DPoP nonce requirement
135
+ * }
136
+ * }
137
+ * }
138
+ * ```
139
+ */
56
140
  export declare class XrpcAuthenticationError<M extends Procedure | Query = Procedure | Query, N extends LexErrorCode = LexErrorCode> extends XrpcResponseError<M, N> {
57
141
  #private;
58
142
  name: string;
59
143
  shouldRetry(): boolean;
144
+ /**
145
+ * Parsed WWW-Authenticate header from the response.
146
+ * Contains authentication scheme parameters (e.g., Bearer realm, DPoP nonce).
147
+ */
60
148
  get wwwAuthenticate(): WWWAuthenticate;
61
149
  }
62
150
  /**
63
- * This class represents invalid or unprocessable XRPC response from the
64
- * upstream server.
151
+ * Error class for invalid or unprocessable XRPC responses from upstream servers.
152
+ *
153
+ * This occurs when the server returns a response that doesn't conform to the
154
+ * XRPC protocol, such as:
155
+ * - Missing or invalid Content-Type header
156
+ * - Response body that doesn't match the method's output schema
157
+ * - Non-JSON error responses
158
+ * - Responses from non-XRPC endpoints
159
+ *
160
+ * The error code is always 'UpstreamFailure' and maps to HTTP 502 Bad Gateway
161
+ * when converted to a response.
162
+ *
163
+ * @typeParam M - The XRPC method type
65
164
  */
66
165
  export declare class XrpcUpstreamError<M extends Procedure | Query = Procedure | Query> extends XrpcError<M, 'UpstreamFailure', XrpcUpstreamError<M>> {
67
166
  readonly response: Response;
68
- readonly payload: XrpcPayload | null;
167
+ readonly payload: XrpcResponsePayload | null;
69
168
  name: string;
70
- constructor(method: M, response: Response, payload: XrpcPayload | null, message?: string, options?: ErrorOptions);
169
+ constructor(method: M, response: Response, payload?: XrpcResponsePayload | null, message?: string, options?: ErrorOptions);
71
170
  get reason(): this;
72
171
  shouldRetry(): boolean;
73
172
  toResponse(): Response;
74
173
  }
174
+ /**
175
+ * Error class for internal/client-side errors during XRPC requests.
176
+ *
177
+ * This represents errors that occur before or during the request that are not
178
+ * server responses, such as:
179
+ * - Network errors (connection refused, DNS failure)
180
+ * - Request timeouts
181
+ * - Request aborted via AbortSignal
182
+ * - Invalid request construction
183
+ *
184
+ * The error code is always 'InternalServerError' and these errors are
185
+ * optimistically considered retryable.
186
+ *
187
+ * @typeParam M - The XRPC method type
188
+ */
75
189
  export declare class XrpcInternalError<M extends Procedure | Query = Procedure | Query> extends XrpcError<M, 'InternalServerError', XrpcInternalError<M>> {
76
190
  name: string;
77
191
  constructor(method: M, message?: string, options?: ErrorOptions);
@@ -79,6 +193,45 @@ export declare class XrpcInternalError<M extends Procedure | Query = Procedure |
79
193
  shouldRetry(): true;
80
194
  toResponse(): Response;
81
195
  }
196
+ /**
197
+ * Union type of all possible XRPC failure types.
198
+ *
199
+ * Used as the return type for safe/non-throwing XRPC methods. Check the
200
+ * `success` property to distinguish between success and failure:
201
+ *
202
+ * @typeParam M - The XRPC method type
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * const result = await client.xrpcSafe(someMethod, options)
207
+ * if (result.success) {
208
+ * console.log(result.body) // XrpcResponse
209
+ * } else {
210
+ * // result is XrpcFailure (XrpcResponseError | XrpcUpstreamError | XrpcInternalError)
211
+ * console.error(result.error, result.message)
212
+ * }
213
+ * ```
214
+ */
82
215
  export type XrpcFailure<M extends Procedure | Query = Procedure | Query> = XrpcResponseError<M> | XrpcUpstreamError<M> | XrpcInternalError<M>;
216
+ /**
217
+ * Converts an unknown error into an appropriate {@link XrpcFailure} type.
218
+ *
219
+ * If the error is already an XrpcFailure for the given method, returns it as-is.
220
+ * Otherwise, wraps it in an {@link XrpcInternalError}.
221
+ *
222
+ * @param method - The XRPC method that was called
223
+ * @param cause - The error to convert
224
+ * @returns An XrpcFailure instance
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * try {
229
+ * const response = await fetch(...)
230
+ * // ... process response
231
+ * } catch (err) {
232
+ * return asXrpcFailure(method, err)
233
+ * }
234
+ * ```
235
+ */
83
236
  export declare function asXrpcFailure<M extends Procedure | Query>(method: M, cause: unknown): XrpcFailure<M>;
84
237
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,KAAK,EACL,aAAa,EAEd,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EACL,eAAe,EAEhB,MAAM,uBAAuB,CAAA;AAE9B,eAAO,MAAM,2BAA2B,EAAE,WAAW,CAAC,MAAM,CAE1D,CAAA;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAA;AACnB,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,CAAA;AAE1C,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAChE,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAA;AAElD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,WAAW,GAA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,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAS/D,IAAa,MAAM,IAAI,IAAI,CAE1B;IAEQ,WAAW,IAAI,IAAI;IAQnB,UAAU,IAAI,QAAQ;CAIhC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,IAEnE,iBAAiB,CAAC,CAAC,CAAC,GAEpB,iBAAiB,CAAC,CAAC,CAAC,GAEpB,iBAAiB,CAAC,CAAC,CAAC,CAAA;AAExB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,EACvD,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,GACb,WAAW,CAAC,CAAC,CAAC,CAUhB"}
package/dist/errors.js CHANGED
@@ -7,6 +7,20 @@ const lex_data_1 = require("@atproto/lex-data");
7
7
  Object.defineProperty(exports, "LexError", { enumerable: true, get: function () { return lex_data_1.LexError; } });
8
8
  const lex_schema_1 = require("@atproto/lex-schema");
9
9
  const www_authenticate_js_1 = require("./www-authenticate.js");
10
+ /**
11
+ * HTTP status codes that indicate a transient error that may succeed on retry.
12
+ *
13
+ * Includes:
14
+ * - 408 Request Timeout
15
+ * - 425 Too Early
16
+ * - 429 Too Many Requests (rate limited)
17
+ * - 500 Internal Server Error
18
+ * - 502 Bad Gateway
19
+ * - 503 Service Unavailable
20
+ * - 504 Gateway Timeout
21
+ * - 522 Connection Timed Out (Cloudflare)
22
+ * - 524 A Timeout Occurred (Cloudflare)
23
+ */
10
24
  exports.RETRYABLE_HTTP_STATUS_CODES = new Set([
11
25
  408, 425, 429, 500, 502, 503, 504, 522, 524,
12
26
  ]);
@@ -23,10 +37,24 @@ exports.RETRYABLE_HTTP_STATUS_CODES = new Set([
23
37
  * This function checks whether a given payload matches this schema.
24
38
  */
25
39
  function isXrpcErrorPayload(payload) {
26
- return (payload !== null &&
40
+ return (payload != null &&
27
41
  payload.encoding === 'application/json' &&
28
42
  lex_schema_1.lexErrorDataSchema.matches(payload.body));
29
43
  }
44
+ /**
45
+ * Abstract base class for all XRPC errors.
46
+ *
47
+ * Extends {@link LexError} and implements {@link ResultFailure} for use with
48
+ * safe/result-based error handling patterns.
49
+ *
50
+ * @typeParam M - The XRPC method type (Procedure or Query)
51
+ * @typeParam N - The error code type
52
+ * @typeParam TReason - The reason type for ResultFailure
53
+ *
54
+ * @see {@link XrpcResponseError} - For valid XRPC error responses
55
+ * @see {@link XrpcUpstreamError} - For invalid/unexpected responses
56
+ * @see {@link XrpcInternalError} - For network/internal errors
57
+ */
30
58
  class XrpcError extends lex_data_1.LexError {
31
59
  method;
32
60
  name = 'XrpcError';
@@ -44,8 +72,28 @@ class XrpcError extends lex_data_1.LexError {
44
72
  }
45
73
  exports.XrpcError = XrpcError;
46
74
  /**
47
- * Class used to represent an HTTP request that resulted in an XRPC method
48
- * error. That is, a non-2xx response with a valid XRPC error payload.
75
+ * Error class for valid XRPC error responses from the server.
76
+ *
77
+ * This represents a properly formatted XRPC error where the server returned
78
+ * a non-2xx status with a valid JSON error payload containing `error` and
79
+ * optional `message` fields.
80
+ *
81
+ * Use {@link matchesSchema} to check if the error matches the method's declared
82
+ * error types for type-safe error handling.
83
+ *
84
+ * @typeParam M - The XRPC method type
85
+ * @typeParam N - The error code type (inferred from method or generic)
86
+ *
87
+ * @example Handling specific errors
88
+ * ```typescript
89
+ * try {
90
+ * await client.xrpc(someMethod, options)
91
+ * } catch (err) {
92
+ * if (err instanceof XrpcResponseError && err.error === 'RecordNotFound') {
93
+ * // Handle not found case
94
+ * }
95
+ * }
96
+ * ```
49
97
  */
50
98
  class XrpcResponseError extends XrpcError {
51
99
  response;
@@ -83,27 +131,68 @@ class XrpcResponseError extends XrpcError {
83
131
  }
84
132
  }
85
133
  exports.XrpcResponseError = XrpcResponseError;
134
+ /**
135
+ * Error class for 401 Unauthorized XRPC responses.
136
+ *
137
+ * Extends {@link XrpcResponseError} with access to parsed WWW-Authenticate header
138
+ * information, useful for implementing authentication flows.
139
+ *
140
+ * Authentication errors are never retryable as they require user intervention
141
+ * (e.g., re-authentication, token refresh).
142
+ *
143
+ * @typeParam M - The XRPC method type
144
+ * @typeParam N - The error code type
145
+ *
146
+ * @example Handling authentication errors
147
+ * ```typescript
148
+ * try {
149
+ * await client.xrpc(someMethod, options)
150
+ * } catch (err) {
151
+ * if (err instanceof XrpcAuthenticationError) {
152
+ * const { DPoP } = err.wwwAuthenticate
153
+ * if (DPoP?.error === 'use_dpop_nonce') {
154
+ * // Handle DPoP nonce requirement
155
+ * }
156
+ * }
157
+ * }
158
+ * ```
159
+ */
86
160
  class XrpcAuthenticationError extends XrpcResponseError {
87
161
  name = 'XrpcAuthenticationError';
88
162
  shouldRetry() {
89
163
  return false;
90
164
  }
91
- #wwwAuthenticate;
165
+ #wwwAuthenticateCached;
166
+ /**
167
+ * Parsed WWW-Authenticate header from the response.
168
+ * Contains authentication scheme parameters (e.g., Bearer realm, DPoP nonce).
169
+ */
92
170
  get wwwAuthenticate() {
93
- return (this.#wwwAuthenticate ??=
171
+ return (this.#wwwAuthenticateCached ??=
94
172
  (0, www_authenticate_js_1.parseWWWAuthenticateHeader)(this.response.headers.get('www-authenticate')) ?? {});
95
173
  }
96
174
  }
97
175
  exports.XrpcAuthenticationError = XrpcAuthenticationError;
98
176
  /**
99
- * This class represents invalid or unprocessable XRPC response from the
100
- * upstream server.
177
+ * Error class for invalid or unprocessable XRPC responses from upstream servers.
178
+ *
179
+ * This occurs when the server returns a response that doesn't conform to the
180
+ * XRPC protocol, such as:
181
+ * - Missing or invalid Content-Type header
182
+ * - Response body that doesn't match the method's output schema
183
+ * - Non-JSON error responses
184
+ * - Responses from non-XRPC endpoints
185
+ *
186
+ * The error code is always 'UpstreamFailure' and maps to HTTP 502 Bad Gateway
187
+ * when converted to a response.
188
+ *
189
+ * @typeParam M - The XRPC method type
101
190
  */
102
191
  class XrpcUpstreamError extends XrpcError {
103
192
  response;
104
193
  payload;
105
194
  name = 'XrpcUpstreamError';
106
- constructor(method, response, payload, message = `Unexpected upstream XRPC response`, options) {
195
+ constructor(method, response, payload = null, message = `Unexpected upstream XRPC response`, options) {
107
196
  super(method, 'UpstreamFailure', message, options);
108
197
  this.response = response;
109
198
  this.payload = payload;
@@ -119,6 +208,21 @@ class XrpcUpstreamError extends XrpcError {
119
208
  }
120
209
  }
121
210
  exports.XrpcUpstreamError = XrpcUpstreamError;
211
+ /**
212
+ * Error class for internal/client-side errors during XRPC requests.
213
+ *
214
+ * This represents errors that occur before or during the request that are not
215
+ * server responses, such as:
216
+ * - Network errors (connection refused, DNS failure)
217
+ * - Request timeouts
218
+ * - Request aborted via AbortSignal
219
+ * - Invalid request construction
220
+ *
221
+ * The error code is always 'InternalServerError' and these errors are
222
+ * optimistically considered retryable.
223
+ *
224
+ * @typeParam M - The XRPC method type
225
+ */
122
226
  class XrpcInternalError extends XrpcError {
123
227
  name = 'XrpcInternalError';
124
228
  constructor(method, message, options) {
@@ -140,6 +244,26 @@ class XrpcInternalError extends XrpcError {
140
244
  }
141
245
  }
142
246
  exports.XrpcInternalError = XrpcInternalError;
247
+ /**
248
+ * Converts an unknown error into an appropriate {@link XrpcFailure} type.
249
+ *
250
+ * If the error is already an XrpcFailure for the given method, returns it as-is.
251
+ * Otherwise, wraps it in an {@link XrpcInternalError}.
252
+ *
253
+ * @param method - The XRPC method that was called
254
+ * @param cause - The error to convert
255
+ * @returns An XrpcFailure instance
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * try {
260
+ * const response = await fetch(...)
261
+ * // ... process response
262
+ * } catch (err) {
263
+ * return asXrpcFailure(method, err)
264
+ * }
265
+ * ```
266
+ */
143
267
  function asXrpcFailure(method, cause) {
144
268
  if (cause instanceof XrpcResponseError ||
145
269
  cause instanceof XrpcUpstreamError ||
@@ -1 +1 @@
1
- {"version":3,"file":"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AAA;IACb,CAAC;IAEQ,UAAU;QACjB,6DAA6D;QAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IAC9D,CAAC;CACF;AA9BD,8CA8BC;AAUD,SAAgB,aAAa,CAC3B,MAAS,EACT,KAAc;IAEd,IACE,KAAK,YAAY,iBAAiB;QAClC,KAAK,YAAY,iBAAiB;QAClC,KAAK,YAAY,iBAAiB,EAClC,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO,KAAK,CAAA;IAC3C,CAAC;IAED,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;AAC5D,CAAC","sourcesContent":["import { LexError, LexErrorCode, LexErrorData } from '@atproto/lex-data'\nimport {\n InferMethodError,\n Procedure,\n Query,\n ResultFailure,\n lexErrorDataSchema,\n} from '@atproto/lex-schema'\nimport { XrpcPayload } from './util.js'\nimport {\n WWWAuthenticate,\n parseWWWAuthenticateHeader,\n} from './www-authenticate.js'\n\nexport const RETRYABLE_HTTP_STATUS_CODES: ReadonlySet<number> = new Set([\n 408, 425, 429, 500, 502, 503, 504, 522, 524,\n])\n\nexport { LexError }\nexport type { LexErrorCode, LexErrorData }\n\nexport type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> =\n XrpcPayload<LexErrorData<N>, 'application/json'>\n\n/**\n * All unsuccessful responses should follow a standard error response\n * schema. The Content-Type should be application/json, and the payload\n * should be a JSON object with the following fields:\n *\n * - `error` (string, required): type name of the error (generic ASCII\n * constant, no whitespace)\n * - `message` (string, optional): description of the error, appropriate for\n * display to humans\n *\n * This function checks whether a given payload matches this schema.\n */\nexport function isXrpcErrorPayload(\n payload: XrpcPayload | null,\n): payload is XrpcErrorPayload {\n return (\n payload !== null &&\n payload.encoding === 'application/json' &&\n lexErrorDataSchema.matches(payload.body)\n )\n}\n\nexport abstract class XrpcError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = LexErrorCode,\n TReason = unknown,\n >\n extends LexError<N>\n implements ResultFailure<TReason>\n{\n name = 'XrpcError'\n\n constructor(\n readonly method: M,\n error: N,\n message: string = `${error} Lexicon RPC error`,\n options?: ErrorOptions,\n ) {\n super(error, message, options)\n }\n\n /**\n * @see {@link ResultFailure.success}\n */\n readonly success = false as const\n\n /**\n * @see {@link ResultFailure.reason}\n */\n abstract readonly reason: TReason\n\n /**\n * Indicates whether the error is transient and can be retried.\n */\n abstract shouldRetry(): boolean\n\n matchesSchema(): this is XrpcError<M, InferMethodError<M>> {\n return this.method.errors?.includes(this.error) ?? false\n }\n}\n\n/**\n * Class used to represent an HTTP request that resulted in an XRPC method\n * error. That is, a non-2xx response with a valid XRPC error payload.\n */\nexport class XrpcResponseError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = InferMethodError<M> | LexErrorCode,\n> extends XrpcError<M, N, XrpcResponseError<M, N>> {\n name = 'XrpcResponseError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload: XrpcErrorPayload<N>,\n options?: ErrorOptions,\n ) {\n const { error, message } = payload.body\n super(method, error, message, options)\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return RETRYABLE_HTTP_STATUS_CODES.has(this.response.status)\n }\n\n override toJSON() {\n return this.payload.body\n }\n\n override toResponse(): Response {\n // Re-expose schema-valid errors as-is to downstream clients\n if (this.matchesSchema()) {\n const status = this.response.status >= 500 ? 502 : this.response.status\n return Response.json(this.toJSON(), { status })\n }\n\n return this.response.status >= 500\n ? // The upstream server had an error, return a generic upstream failure\n Response.json({ error: 'UpstreamFailure' }, { status: 502 })\n : // If the error is on our side, return a generic internal server error\n Response.json({ error: 'InternalServerError' }, { status: 500 })\n }\n\n get body(): LexErrorData {\n return this.payload.body\n }\n}\n\nexport type { WWWAuthenticate }\nexport class XrpcAuthenticationError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = LexErrorCode,\n> extends XrpcResponseError<M, N> {\n name = 'XrpcAuthenticationError'\n\n override shouldRetry(): boolean {\n return false\n }\n\n #wwwAuthenticate?: WWWAuthenticate\n get wwwAuthenticate(): WWWAuthenticate {\n return (this.#wwwAuthenticate ??=\n parseWWWAuthenticateHeader(\n this.response.headers.get('www-authenticate'),\n ) ?? {})\n }\n}\n\n/**\n * This class represents invalid or unprocessable XRPC response from the\n * upstream server.\n */\nexport class XrpcUpstreamError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'UpstreamFailure', XrpcUpstreamError<M>> {\n name = 'XrpcUpstreamError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload: XrpcPayload | null,\n message: string = `Unexpected upstream XRPC response`,\n options?: ErrorOptions,\n ) {\n super(method, 'UpstreamFailure', message, options)\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return RETRYABLE_HTTP_STATUS_CODES.has(this.response.status)\n }\n\n override toResponse(): Response {\n return Response.json(this.toJSON(), { status: 502 })\n }\n}\n\nexport class XrpcInternalError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'InternalServerError', XrpcInternalError<M>> {\n name = 'XrpcInternalError'\n\n constructor(method: M, message?: string, options?: ErrorOptions) {\n super(\n method,\n 'InternalServerError',\n message ?? 'Unable to fulfill XRPC request',\n options,\n )\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): true {\n // Ideally, we would inspect the reason to determine if it's retryable\n // (by detecting network errors, timeouts, etc.). Since these cases are\n // highly platform-dependent, we optimistically assume all internal\n // errors are retryable.\n return true\n }\n\n override toResponse(): Response {\n // Do not expose internal error details to downstream clients\n return Response.json({ error: this.error }, { status: 500 })\n }\n}\n\nexport type XrpcFailure<M extends Procedure | Query = Procedure | Query> =\n // The server returned a valid XRPC error response\n | XrpcResponseError<M>\n // The response was not a valid XRPC response, or it does not match the schema\n | XrpcUpstreamError<M>\n // Something went wrong (network error, etc.)\n | XrpcInternalError<M>\n\nexport function asXrpcFailure<M extends Procedure | Query>(\n method: M,\n cause: unknown,\n): XrpcFailure<M> {\n if (\n cause instanceof XrpcResponseError ||\n cause instanceof XrpcUpstreamError ||\n cause instanceof XrpcInternalError\n ) {\n if (cause.method === method) return cause\n }\n\n return new XrpcInternalError(method, undefined, { cause })\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AA2DA,gDAQC;AA0TD,sCAaC;AA1YD,gDAAwE;AAgC/D,yFAhCA,mBAAQ,OAgCA;AA/BjB,oDAM4B;AAE5B,+DAG8B;AAE9B;;;;;;;;;;;;;GAaG;AACU,QAAA,2BAA2B,GAAwB,IAAI,GAAG,CAAC;IACtE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;CAC5C,CAAC,CAAA;AAiBF;;;;;;;;;;;GAWG;AACH,SAAgB,kBAAkB,CAChC,OAA+C;IAE/C,OAAO,CACL,OAAO,IAAI,IAAI;QACf,OAAO,CAAC,QAAQ,KAAK,kBAAkB;QACvC,+BAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CACzC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAsB,SAKpB,SAAQ,mBAAW;IAMR;IAHX,IAAI,GAAG,WAAW,CAAA;IAElB,YACW,MAAS,EAClB,KAAQ,EACR,UAAkB,GAAG,KAAK,oBAAoB,EAC9C,OAAsB;QAEtB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QALrB,WAAM,GAAN,MAAM,CAAG;IAMpB,CAAC;IAED;;OAEG;IACM,OAAO,GAAG,KAAc,CAAA;IAYjC,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,Q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,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IACtD,CAAC;CACF;AA1BD,8CA0BC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAa,iBAEX,SAAQ,SAAyD;IACjE,IAAI,GAAG,mBAAmB,CAAA;IAE1B,YAAY,MAAS,EAAE,OAAgB,EAAE,OAAsB;QAC7D,KAAK,CACH,MAAM,EACN,qBAAqB,EACrB,OAAO,IAAI,gCAAgC,EAC3C,OAAO,CACR,CAAA;IACH,CAAC;IAED,IAAa,MAAM;QACjB,OAAO,IAAI,CAAA;IACb,CAAC;IAEQ,WAAW;QAClB,sEAAsE;QACtE,uEAAuE;QACvE,mEAAmE;QACnE,wBAAwB;QACxB,OAAO,IAAI,CAAA;IACb,CAAC;IAEQ,UAAU;QACjB,6DAA6D;QAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IAC9D,CAAC;CACF;AA9BD,8CA8BC;AA6BD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,aAAa,CAC3B,MAAS,EACT,KAAc;IAEd,IACE,KAAK,YAAY,iBAAiB;QAClC,KAAK,YAAY,iBAAiB;QAClC,KAAK,YAAY,iBAAiB,EAClC,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO,KAAK,CAAA;IAC3C,CAAC;IAED,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;AAC5D,CAAC","sourcesContent":["import { LexError, LexErrorCode, LexErrorData } from '@atproto/lex-data'\nimport {\n InferMethodError,\n Procedure,\n Query,\n ResultFailure,\n lexErrorDataSchema,\n} from '@atproto/lex-schema'\nimport { XrpcResponsePayload } from './util.js'\nimport {\n WWWAuthenticate,\n parseWWWAuthenticateHeader,\n} from './www-authenticate.js'\n\n/**\n * HTTP status codes that indicate a transient error that may succeed on retry.\n *\n * Includes:\n * - 408 Request Timeout\n * - 425 Too Early\n * - 429 Too Many Requests (rate limited)\n * - 500 Internal Server Error\n * - 502 Bad Gateway\n * - 503 Service Unavailable\n * - 504 Gateway Timeout\n * - 522 Connection Timed Out (Cloudflare)\n * - 524 A Timeout Occurred (Cloudflare)\n */\nexport const RETRYABLE_HTTP_STATUS_CODES: ReadonlySet<number> = new Set([\n 408, 425, 429, 500, 502, 503, 504, 522, 524,\n])\n\nexport { LexError }\nexport type { LexErrorCode, LexErrorData }\n\n/**\n * The payload structure for XRPC error responses.\n *\n * All XRPC errors return JSON with an `error` code and optional `message`.\n *\n * @typeParam N - The specific error code type\n */\nexport type XrpcErrorPayload<N extends LexErrorCode = LexErrorCode> = {\n body: LexErrorData<N>\n encoding: 'application/json'\n}\n\n/**\n * All unsuccessful responses should follow a standard error response\n * schema. The Content-Type should be application/json, and the payload\n * should be a JSON object with the following fields:\n *\n * - `error` (string, required): type name of the error (generic ASCII\n * constant, no whitespace)\n * - `message` (string, optional): description of the error, appropriate for\n * display to humans\n *\n * This function checks whether a given payload matches this schema.\n */\nexport function isXrpcErrorPayload(\n payload: XrpcResponsePayload | null | undefined,\n): payload is XrpcErrorPayload {\n return (\n payload != null &&\n payload.encoding === 'application/json' &&\n lexErrorDataSchema.matches(payload.body)\n )\n}\n\n/**\n * Abstract base class for all XRPC errors.\n *\n * Extends {@link LexError} and implements {@link ResultFailure} for use with\n * safe/result-based error handling patterns.\n *\n * @typeParam M - The XRPC method type (Procedure or Query)\n * @typeParam N - The error code type\n * @typeParam TReason - The reason type for ResultFailure\n *\n * @see {@link XrpcResponseError} - For valid XRPC error responses\n * @see {@link XrpcUpstreamError} - For invalid/unexpected responses\n * @see {@link XrpcInternalError} - For network/internal errors\n */\nexport abstract class XrpcError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = LexErrorCode,\n TReason = unknown,\n >\n extends LexError<N>\n implements ResultFailure<TReason>\n{\n name = 'XrpcError'\n\n constructor(\n readonly method: M,\n error: N,\n message: string = `${error} Lexicon RPC error`,\n options?: ErrorOptions,\n ) {\n super(error, message, options)\n }\n\n /**\n * @see {@link ResultFailure.success}\n */\n readonly success = false as const\n\n /**\n * @see {@link ResultFailure.reason}\n */\n abstract readonly reason: TReason\n\n /**\n * Indicates whether the error is transient and can be retried.\n */\n abstract shouldRetry(): boolean\n\n matchesSchema(): this is XrpcError<M, InferMethodError<M>> {\n return this.method.errors?.includes(this.error) ?? false\n }\n}\n\n/**\n * Error class for valid XRPC error responses from the server.\n *\n * This represents a properly formatted XRPC error where the server returned\n * a non-2xx status with a valid JSON error payload containing `error` and\n * optional `message` fields.\n *\n * Use {@link matchesSchema} to check if the error matches the method's declared\n * error types for type-safe error handling.\n *\n * @typeParam M - The XRPC method type\n * @typeParam N - The error code type (inferred from method or generic)\n *\n * @example Handling specific errors\n * ```typescript\n * try {\n * await client.xrpc(someMethod, options)\n * } catch (err) {\n * if (err instanceof XrpcResponseError && err.error === 'RecordNotFound') {\n * // Handle not found case\n * }\n * }\n * ```\n */\nexport class XrpcResponseError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = InferMethodError<M> | LexErrorCode,\n> extends XrpcError<M, N, XrpcResponseError<M, N>> {\n name = 'XrpcResponseError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload: XrpcErrorPayload<N>,\n options?: ErrorOptions,\n ) {\n const { error, message } = payload.body\n super(method, error, message, options)\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return RETRYABLE_HTTP_STATUS_CODES.has(this.response.status)\n }\n\n override toJSON() {\n return this.payload.body\n }\n\n override toResponse(): Response {\n // Re-expose schema-valid errors as-is to downstream clients\n if (this.matchesSchema()) {\n const status = this.response.status >= 500 ? 502 : this.response.status\n return Response.json(this.toJSON(), { status })\n }\n\n return this.response.status >= 500\n ? // The upstream server had an error, return a generic upstream failure\n Response.json({ error: 'UpstreamFailure' }, { status: 502 })\n : // If the error is on our side, return a generic internal server error\n Response.json({ error: 'InternalServerError' }, { status: 500 })\n }\n\n get body(): LexErrorData {\n return this.payload.body\n }\n}\n\nexport type { WWWAuthenticate }\n\n/**\n * Error class for 401 Unauthorized XRPC responses.\n *\n * Extends {@link XrpcResponseError} with access to parsed WWW-Authenticate header\n * information, useful for implementing authentication flows.\n *\n * Authentication errors are never retryable as they require user intervention\n * (e.g., re-authentication, token refresh).\n *\n * @typeParam M - The XRPC method type\n * @typeParam N - The error code type\n *\n * @example Handling authentication errors\n * ```typescript\n * try {\n * await client.xrpc(someMethod, options)\n * } catch (err) {\n * if (err instanceof XrpcAuthenticationError) {\n * const { DPoP } = err.wwwAuthenticate\n * if (DPoP?.error === 'use_dpop_nonce') {\n * // Handle DPoP nonce requirement\n * }\n * }\n * }\n * ```\n */\nexport class XrpcAuthenticationError<\n M extends Procedure | Query = Procedure | Query,\n N extends LexErrorCode = LexErrorCode,\n> extends XrpcResponseError<M, N> {\n name = 'XrpcAuthenticationError'\n\n override shouldRetry(): boolean {\n return false\n }\n\n #wwwAuthenticateCached?: WWWAuthenticate\n /**\n * Parsed WWW-Authenticate header from the response.\n * Contains authentication scheme parameters (e.g., Bearer realm, DPoP nonce).\n */\n get wwwAuthenticate(): WWWAuthenticate {\n return (this.#wwwAuthenticateCached ??=\n parseWWWAuthenticateHeader(\n this.response.headers.get('www-authenticate'),\n ) ?? {})\n }\n}\n\n/**\n * Error class for invalid or unprocessable XRPC responses from upstream servers.\n *\n * This occurs when the server returns a response that doesn't conform to the\n * XRPC protocol, such as:\n * - Missing or invalid Content-Type header\n * - Response body that doesn't match the method's output schema\n * - Non-JSON error responses\n * - Responses from non-XRPC endpoints\n *\n * The error code is always 'UpstreamFailure' and maps to HTTP 502 Bad Gateway\n * when converted to a response.\n *\n * @typeParam M - The XRPC method type\n */\nexport class XrpcUpstreamError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'UpstreamFailure', XrpcUpstreamError<M>> {\n name = 'XrpcUpstreamError'\n\n constructor(\n method: M,\n readonly response: Response,\n readonly payload: XrpcResponsePayload | null = null,\n message: string = `Unexpected upstream XRPC response`,\n options?: ErrorOptions,\n ) {\n super(method, 'UpstreamFailure', message, options)\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): boolean {\n return RETRYABLE_HTTP_STATUS_CODES.has(this.response.status)\n }\n\n override toResponse(): Response {\n return Response.json(this.toJSON(), { status: 502 })\n }\n}\n\n/**\n * Error class for internal/client-side errors during XRPC requests.\n *\n * This represents errors that occur before or during the request that are not\n * server responses, such as:\n * - Network errors (connection refused, DNS failure)\n * - Request timeouts\n * - Request aborted via AbortSignal\n * - Invalid request construction\n *\n * The error code is always 'InternalServerError' and these errors are\n * optimistically considered retryable.\n *\n * @typeParam M - The XRPC method type\n */\nexport class XrpcInternalError<\n M extends Procedure | Query = Procedure | Query,\n> extends XrpcError<M, 'InternalServerError', XrpcInternalError<M>> {\n name = 'XrpcInternalError'\n\n constructor(method: M, message?: string, options?: ErrorOptions) {\n super(\n method,\n 'InternalServerError',\n message ?? 'Unable to fulfill XRPC request',\n options,\n )\n }\n\n override get reason(): this {\n return this\n }\n\n override shouldRetry(): true {\n // Ideally, we would inspect the reason to determine if it's retryable\n // (by detecting network errors, timeouts, etc.). Since these cases are\n // highly platform-dependent, we optimistically assume all internal\n // errors are retryable.\n return true\n }\n\n override toResponse(): Response {\n // Do not expose internal error details to downstream clients\n return Response.json({ error: this.error }, { status: 500 })\n }\n}\n\n/**\n * Union type of all possible XRPC failure types.\n *\n * Used as the return type for safe/non-throwing XRPC methods. Check the\n * `success` property to distinguish between success and failure:\n *\n * @typeParam M - The XRPC method type\n *\n * @example\n * ```typescript\n * const result = await client.xrpcSafe(someMethod, options)\n * if (result.success) {\n * console.log(result.body) // XrpcResponse\n * } else {\n * // result is XrpcFailure (XrpcResponseError | XrpcUpstreamError | XrpcInternalError)\n * console.error(result.error, result.message)\n * }\n * ```\n */\nexport type XrpcFailure<M extends Procedure | Query = Procedure | Query> =\n // The server returned a valid XRPC error response\n | XrpcResponseError<M>\n // The response was not a valid XRPC response, or it does not match the schema\n | XrpcUpstreamError<M>\n // Something went wrong (network error, etc.)\n | XrpcInternalError<M>\n\n/**\n * Converts an unknown error into an appropriate {@link XrpcFailure} type.\n *\n * If the error is already an XrpcFailure for the given method, returns it as-is.\n * Otherwise, wraps it in an {@link XrpcInternalError}.\n *\n * @param method - The XRPC method that was called\n * @param cause - The error to convert\n * @returns An XrpcFailure instance\n *\n * @example\n * ```typescript\n * try {\n * const response = await fetch(...)\n * // ... process response\n * } catch (err) {\n * return asXrpcFailure(method, err)\n * }\n * ```\n */\nexport function asXrpcFailure<M extends Procedure | Query>(\n method: M,\n cause: unknown,\n): XrpcFailure<M> {\n if (\n cause instanceof XrpcResponseError ||\n cause instanceof XrpcUpstreamError ||\n cause instanceof XrpcInternalError\n ) {\n if (cause.method === method) return cause\n }\n\n return new XrpcInternalError(method, undefined, { cause })\n}\n"]}
@@ -4,30 +4,30 @@ declare const $nsid = "com.atproto.repo.createRecord";
4
4
  export { $nsid };
5
5
  /** Create a single new repository record. Requires auth, implemented by PDS. */
6
6
  declare const main: l.Procedure<"com.atproto.repo.createRecord", l.ParamsSchema<{}>, l.Payload<"application/json", l.ObjectSchema<{
7
- readonly repo: l.StringSchema<{
7
+ repo: l.StringSchema<{
8
8
  readonly format: "at-identifier";
9
9
  }>;
10
- readonly collection: l.StringSchema<{
10
+ collection: l.StringSchema<{
11
11
  readonly format: "nsid";
12
12
  }>;
13
- readonly rkey: l.OptionalSchema<l.StringSchema<{
13
+ rkey: l.OptionalSchema<l.StringSchema<{
14
14
  readonly format: "record-key";
15
15
  readonly maxLength: 512;
16
16
  }>>;
17
- readonly validate: l.OptionalSchema<l.BooleanSchema>;
18
- readonly record: l.UnknownObjectSchema;
19
- readonly swapCommit: l.OptionalSchema<l.StringSchema<{
17
+ validate: l.OptionalSchema<l.BooleanSchema>;
18
+ record: l.UnknownObjectSchema;
19
+ swapCommit: l.OptionalSchema<l.StringSchema<{
20
20
  readonly format: "cid";
21
21
  }>>;
22
22
  }>>, l.Payload<"application/json", l.ObjectSchema<{
23
- readonly uri: l.StringSchema<{
23
+ uri: l.StringSchema<{
24
24
  readonly format: "at-uri";
25
25
  }>;
26
- readonly cid: l.StringSchema<{
26
+ cid: l.StringSchema<{
27
27
  readonly format: "cid";
28
28
  }>;
29
- readonly commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
30
- readonly validationStatus: l.OptionalSchema<l.StringSchema<{}>>;
29
+ commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
30
+ validationStatus: l.OptionalSchema<l.StringSchema<{}>>;
31
31
  }>>, readonly ["InvalidSwap"]>;
32
32
  export { main };
33
33
  export type Params = l.InferMethodParams<typeof main>;
@@ -36,29 +36,29 @@ export type InputBody = l.InferMethodInputBody<typeof main>;
36
36
  export type Output = l.InferMethodOutput<typeof main>;
37
37
  export type OutputBody = l.InferMethodOutputBody<typeof main>;
38
38
  export declare const $lxm: "com.atproto.repo.createRecord", $params: l.ParamsSchema<{}>, $input: l.Payload<"application/json", l.ObjectSchema<{
39
- readonly repo: l.StringSchema<{
39
+ repo: l.StringSchema<{
40
40
  readonly format: "at-identifier";
41
41
  }>;
42
- readonly collection: l.StringSchema<{
42
+ collection: l.StringSchema<{
43
43
  readonly format: "nsid";
44
44
  }>;
45
- readonly rkey: l.OptionalSchema<l.StringSchema<{
45
+ rkey: l.OptionalSchema<l.StringSchema<{
46
46
  readonly format: "record-key";
47
47
  readonly maxLength: 512;
48
48
  }>>;
49
- readonly validate: l.OptionalSchema<l.BooleanSchema>;
50
- readonly record: l.UnknownObjectSchema;
51
- readonly swapCommit: l.OptionalSchema<l.StringSchema<{
49
+ validate: l.OptionalSchema<l.BooleanSchema>;
50
+ record: l.UnknownObjectSchema;
51
+ swapCommit: l.OptionalSchema<l.StringSchema<{
52
52
  readonly format: "cid";
53
53
  }>>;
54
54
  }>>, $output: l.Payload<"application/json", l.ObjectSchema<{
55
- readonly uri: l.StringSchema<{
55
+ uri: l.StringSchema<{
56
56
  readonly format: "at-uri";
57
57
  }>;
58
- readonly cid: l.StringSchema<{
58
+ cid: l.StringSchema<{
59
59
  readonly format: "cid";
60
60
  }>;
61
- readonly commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
62
- readonly validationStatus: l.OptionalSchema<l.StringSchema<{}>>;
61
+ commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
62
+ validationStatus: l.OptionalSchema<l.StringSchema<{}>>;
63
63
  }>>;
64
64
  //# sourceMappingURL=createRecord.defs.d.ts.map
@@ -4,23 +4,23 @@ declare const $nsid = "com.atproto.repo.deleteRecord";
4
4
  export { $nsid };
5
5
  /** Delete a repository record, or ensure it doesn't exist. Requires auth, implemented by PDS. */
6
6
  declare const main: l.Procedure<"com.atproto.repo.deleteRecord", l.ParamsSchema<{}>, l.Payload<"application/json", l.ObjectSchema<{
7
- readonly repo: l.StringSchema<{
7
+ repo: l.StringSchema<{
8
8
  readonly format: "at-identifier";
9
9
  }>;
10
- readonly collection: l.StringSchema<{
10
+ collection: l.StringSchema<{
11
11
  readonly format: "nsid";
12
12
  }>;
13
- readonly rkey: l.StringSchema<{
13
+ rkey: l.StringSchema<{
14
14
  readonly format: "record-key";
15
15
  }>;
16
- readonly swapRecord: l.OptionalSchema<l.StringSchema<{
16
+ swapRecord: l.OptionalSchema<l.StringSchema<{
17
17
  readonly format: "cid";
18
18
  }>>;
19
- readonly swapCommit: l.OptionalSchema<l.StringSchema<{
19
+ swapCommit: l.OptionalSchema<l.StringSchema<{
20
20
  readonly format: "cid";
21
21
  }>>;
22
22
  }>>, l.Payload<"application/json", l.ObjectSchema<{
23
- readonly commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
23
+ commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
24
24
  }>>, readonly ["InvalidSwap"]>;
25
25
  export { main };
26
26
  export type Params = l.InferMethodParams<typeof main>;
@@ -29,22 +29,22 @@ export type InputBody = l.InferMethodInputBody<typeof main>;
29
29
  export type Output = l.InferMethodOutput<typeof main>;
30
30
  export type OutputBody = l.InferMethodOutputBody<typeof main>;
31
31
  export declare const $lxm: "com.atproto.repo.deleteRecord", $params: l.ParamsSchema<{}>, $input: l.Payload<"application/json", l.ObjectSchema<{
32
- readonly repo: l.StringSchema<{
32
+ repo: l.StringSchema<{
33
33
  readonly format: "at-identifier";
34
34
  }>;
35
- readonly collection: l.StringSchema<{
35
+ collection: l.StringSchema<{
36
36
  readonly format: "nsid";
37
37
  }>;
38
- readonly rkey: l.StringSchema<{
38
+ rkey: l.StringSchema<{
39
39
  readonly format: "record-key";
40
40
  }>;
41
- readonly swapRecord: l.OptionalSchema<l.StringSchema<{
41
+ swapRecord: l.OptionalSchema<l.StringSchema<{
42
42
  readonly format: "cid";
43
43
  }>>;
44
- readonly swapCommit: l.OptionalSchema<l.StringSchema<{
44
+ swapCommit: l.OptionalSchema<l.StringSchema<{
45
45
  readonly format: "cid";
46
46
  }>>;
47
47
  }>>, $output: l.Payload<"application/json", l.ObjectSchema<{
48
- readonly commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
48
+ commit: l.OptionalSchema<l.RefSchema<l.Validator<RepoDefs.CommitMeta, RepoDefs.CommitMeta>>>;
49
49
  }>>;
50
50
  //# sourceMappingURL=deleteRecord.defs.d.ts.map