@atproto/lex-client 0.0.5 → 0.0.6
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.
- package/CHANGELOG.md +15 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +3 -0
- package/dist/agent.js.map +1 -1
- package/dist/client.d.ts +30 -28
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +9 -13
- package/dist/client.js.map +1 -1
- package/dist/{xrpc-error.d.ts → errors.d.ts} +22 -27
- package/dist/errors.d.ts.map +1 -0
- package/dist/{xrpc-error.js → errors.js} +38 -33
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js +5 -7
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +5 -7
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js +3 -5
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js +2 -3
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js +5 -7
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +3 -4
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
- package/dist/response.d.ts +38 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/{xrpc-response.js → response.js} +24 -20
- package/dist/response.js.map +1 -0
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -4
- package/dist/types.js.map +1 -1
- package/dist/xrpc.d.ts +23 -17
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js +15 -17
- package/dist/xrpc.js.map +1 -1
- package/package.json +10 -10
- package/src/agent.ts +6 -2
- package/src/client.ts +67 -61
- package/src/{xrpc-error.ts → errors.ts} +59 -48
- package/src/index.ts +2 -0
- package/src/lexicons/com/atproto/repo/createRecord.defs.ts +22 -28
- package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +18 -24
- package/src/lexicons/com/atproto/repo/getRecord.defs.ts +5 -10
- package/src/lexicons/com/atproto/repo/listRecords.defs.ts +6 -9
- package/src/lexicons/com/atproto/repo/putRecord.defs.ts +23 -29
- package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +4 -7
- package/src/{xrpc-response.ts → response.ts} +45 -30
- package/src/types.ts +0 -6
- package/src/xrpc.ts +56 -57
- package/tsconfig.tests.json +4 -7
- package/dist/xrpc-error.d.ts.map +0 -1
- package/dist/xrpc-error.js.map +0 -1
- package/dist/xrpc-response.d.ts +0 -35
- package/dist/xrpc-response.d.ts.map +0 -1
- package/dist/xrpc-response.js.map +0 -1
package/src/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LexMap, LexValue } from '@atproto/lex-data'
|
|
1
|
+
import { LexError, LexMap, LexValue } from '@atproto/lex-data'
|
|
2
2
|
import {
|
|
3
3
|
AtIdentifierString,
|
|
4
4
|
CidString,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
InferMethodParams,
|
|
10
10
|
InferRecordKey,
|
|
11
11
|
LexiconRecordKey,
|
|
12
|
+
Main,
|
|
12
13
|
NsidString,
|
|
13
14
|
Params,
|
|
14
15
|
Procedure,
|
|
@@ -16,26 +17,34 @@ import {
|
|
|
16
17
|
RecordSchema,
|
|
17
18
|
Restricted,
|
|
18
19
|
Schema,
|
|
20
|
+
getMain,
|
|
19
21
|
} from '@atproto/lex-schema'
|
|
20
22
|
import { Agent, AgentOptions, buildAgent } from './agent.js'
|
|
21
23
|
import { com } from './lexicons.js'
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
CallOptions,
|
|
25
|
-
Namespace,
|
|
26
|
-
Service,
|
|
27
|
-
getMain,
|
|
28
|
-
} from './types.js'
|
|
24
|
+
import { LexRpcResponse, LexRpcResponseBody } from './response.js'
|
|
25
|
+
import { BinaryBodyInit, CallOptions, Service } from './types.js'
|
|
29
26
|
import { buildAtprotoHeaders } from './util.js'
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
import { LexRpcFailure, LexRpcOptions, xrpc, xrpcSafe } from './xrpc.js'
|
|
28
|
+
|
|
29
|
+
export type {
|
|
30
|
+
AtIdentifierString,
|
|
31
|
+
CidString,
|
|
32
|
+
DidString,
|
|
33
|
+
InferMethodInputBody,
|
|
34
|
+
InferMethodOutputBody,
|
|
35
|
+
InferMethodParams,
|
|
36
|
+
InferRecordKey,
|
|
37
|
+
LexMap,
|
|
38
|
+
LexValue,
|
|
39
|
+
LexiconRecordKey,
|
|
40
|
+
NsidString,
|
|
41
|
+
Params,
|
|
42
|
+
Procedure,
|
|
43
|
+
Query,
|
|
44
|
+
RecordSchema,
|
|
45
|
+
Restricted,
|
|
46
|
+
Schema,
|
|
47
|
+
}
|
|
39
48
|
|
|
40
49
|
export type ClientOptions = {
|
|
41
50
|
labelers?: Iterable<DidString>
|
|
@@ -148,10 +157,7 @@ export class Client implements Agent {
|
|
|
148
157
|
public readonly labelers: Set<DidString>
|
|
149
158
|
|
|
150
159
|
constructor(agent: Agent | AgentOptions, options: ClientOptions = {}) {
|
|
151
|
-
this.agent =
|
|
152
|
-
typeof agent === 'object' && 'fetchHandler' in agent
|
|
153
|
-
? agent
|
|
154
|
-
: buildAgent(agent)
|
|
160
|
+
this.agent = buildAgent(agent)
|
|
155
161
|
this.service = options.service
|
|
156
162
|
this.labelers = new Set(options.labelers)
|
|
157
163
|
this.headers = new Headers(options.headers)
|
|
@@ -167,7 +173,7 @@ export class Client implements Agent {
|
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
public assertAuthenticated(): asserts this is { did: DidString } {
|
|
170
|
-
if (!this.did) throw new
|
|
176
|
+
if (!this.did) throw new LexError('AuthenticationRequired')
|
|
171
177
|
}
|
|
172
178
|
|
|
173
179
|
public setLabelers(labelers: Iterable<DidString> = []) {
|
|
@@ -205,37 +211,37 @@ export class Client implements Agent {
|
|
|
205
211
|
}
|
|
206
212
|
|
|
207
213
|
/**
|
|
208
|
-
* @throws {
|
|
214
|
+
* @throws {LexRpcFailure<M>} when the request fails or the response is an error
|
|
209
215
|
*/
|
|
210
216
|
async xrpc<const M extends Query | Procedure>(
|
|
211
|
-
ns: NonNullable<unknown> extends
|
|
212
|
-
?
|
|
217
|
+
ns: NonNullable<unknown> extends LexRpcOptions<M>
|
|
218
|
+
? Main<M>
|
|
213
219
|
: Restricted<'This XRPC method requires an "options" argument'>,
|
|
214
|
-
): Promise<
|
|
220
|
+
): Promise<LexRpcResponse<M>>
|
|
215
221
|
async xrpc<const M extends Query | Procedure>(
|
|
216
|
-
ns:
|
|
217
|
-
options:
|
|
218
|
-
): Promise<
|
|
222
|
+
ns: Main<M>,
|
|
223
|
+
options: LexRpcOptions<M>,
|
|
224
|
+
): Promise<LexRpcResponse<M>>
|
|
219
225
|
async xrpc<const M extends Query | Procedure>(
|
|
220
|
-
ns:
|
|
221
|
-
options:
|
|
222
|
-
): Promise<
|
|
226
|
+
ns: Main<M>,
|
|
227
|
+
options: LexRpcOptions<M> = {} as LexRpcOptions<M>,
|
|
228
|
+
): Promise<LexRpcResponse<M>> {
|
|
223
229
|
return xrpc(this, ns, options)
|
|
224
230
|
}
|
|
225
231
|
|
|
226
232
|
async xrpcSafe<const M extends Query | Procedure>(
|
|
227
|
-
ns: NonNullable<unknown> extends
|
|
228
|
-
?
|
|
233
|
+
ns: NonNullable<unknown> extends LexRpcOptions<M>
|
|
234
|
+
? Main<M>
|
|
229
235
|
: Restricted<'This XRPC method requires an "options" argument'>,
|
|
230
|
-
): Promise<
|
|
236
|
+
): Promise<LexRpcResponse<M> | LexRpcFailure<M>>
|
|
231
237
|
async xrpcSafe<const M extends Query | Procedure>(
|
|
232
|
-
ns:
|
|
233
|
-
options:
|
|
234
|
-
): Promise<
|
|
238
|
+
ns: Main<M>,
|
|
239
|
+
options: LexRpcOptions<M>,
|
|
240
|
+
): Promise<LexRpcResponse<M> | LexRpcFailure<M>>
|
|
235
241
|
async xrpcSafe<const M extends Query | Procedure>(
|
|
236
|
-
ns:
|
|
237
|
-
options:
|
|
238
|
-
): Promise<
|
|
242
|
+
ns: Main<M>,
|
|
243
|
+
options: LexRpcOptions<M> = {} as LexRpcOptions<M>,
|
|
244
|
+
): Promise<LexRpcResponse<M> | LexRpcFailure<M>> {
|
|
239
245
|
return xrpcSafe(this, ns, options)
|
|
240
246
|
}
|
|
241
247
|
|
|
@@ -343,16 +349,16 @@ export class Client implements Agent {
|
|
|
343
349
|
|
|
344
350
|
public async call<const T extends Query>(
|
|
345
351
|
ns: NonNullable<unknown> extends InferMethodParams<T>
|
|
346
|
-
?
|
|
352
|
+
? Main<T>
|
|
347
353
|
: Restricted<'This query type requires a "params" argument'>,
|
|
348
|
-
): Promise<
|
|
354
|
+
): Promise<LexRpcResponseBody<T>>
|
|
349
355
|
public async call<const T extends Action>(
|
|
350
356
|
ns: void extends InferActionInput<T>
|
|
351
|
-
?
|
|
357
|
+
? Main<T>
|
|
352
358
|
: Restricted<'This action type requires an "input" argument'>,
|
|
353
359
|
): Promise<InferActionOutput<T>>
|
|
354
360
|
public async call<const T extends Action | Procedure | Query>(
|
|
355
|
-
ns:
|
|
361
|
+
ns: Main<T>,
|
|
356
362
|
arg: T extends Action
|
|
357
363
|
? InferActionInput<T>
|
|
358
364
|
: T extends Procedure
|
|
@@ -365,13 +371,13 @@ export class Client implements Agent {
|
|
|
365
371
|
T extends Action
|
|
366
372
|
? InferActionOutput<T>
|
|
367
373
|
: T extends Procedure
|
|
368
|
-
?
|
|
374
|
+
? LexRpcResponseBody<T>
|
|
369
375
|
: T extends Query
|
|
370
|
-
?
|
|
376
|
+
? LexRpcResponseBody<T>
|
|
371
377
|
: never
|
|
372
378
|
>
|
|
373
379
|
public async call(
|
|
374
|
-
ns:
|
|
380
|
+
ns: Main<Action> | Main<Procedure> | Main<Query>,
|
|
375
381
|
arg?: LexValue | Params,
|
|
376
382
|
options: CallOptions = {},
|
|
377
383
|
): Promise<unknown> {
|
|
@@ -394,17 +400,17 @@ export class Client implements Agent {
|
|
|
394
400
|
|
|
395
401
|
public async create<const T extends RecordSchema>(
|
|
396
402
|
ns: NonNullable<unknown> extends CreateOptions<T>
|
|
397
|
-
?
|
|
403
|
+
? Main<T>
|
|
398
404
|
: Restricted<'This record type requires an "options" argument'>,
|
|
399
405
|
input: Omit<Infer<T>, '$type'>,
|
|
400
406
|
): Promise<CreateOutput>
|
|
401
407
|
public async create<const T extends RecordSchema>(
|
|
402
|
-
ns:
|
|
408
|
+
ns: Main<T>,
|
|
403
409
|
input: Omit<Infer<T>, '$type'>,
|
|
404
410
|
options: CreateOptions<T>,
|
|
405
411
|
): Promise<CreateOutput>
|
|
406
412
|
public async create<const T extends RecordSchema>(
|
|
407
|
-
ns:
|
|
413
|
+
ns: Main<T>,
|
|
408
414
|
input: Omit<Infer<T>, '$type'>,
|
|
409
415
|
options: CreateOptions<T> = {} as CreateOptions<T>,
|
|
410
416
|
): Promise<CreateOutput> {
|
|
@@ -419,15 +425,15 @@ export class Client implements Agent {
|
|
|
419
425
|
|
|
420
426
|
public async delete<const T extends RecordSchema>(
|
|
421
427
|
ns: NonNullable<unknown> extends DeleteOptions<T>
|
|
422
|
-
?
|
|
428
|
+
? Main<T>
|
|
423
429
|
: Restricted<'This record type requires an "options" argument'>,
|
|
424
430
|
): Promise<DeleteOutput>
|
|
425
431
|
public async delete<const T extends RecordSchema>(
|
|
426
|
-
ns:
|
|
432
|
+
ns: Main<T>,
|
|
427
433
|
options?: DeleteOptions<T>,
|
|
428
434
|
): Promise<DeleteOutput>
|
|
429
435
|
public async delete<const T extends RecordSchema>(
|
|
430
|
-
ns:
|
|
436
|
+
ns: Main<T>,
|
|
431
437
|
options: DeleteOptions<T> = {} as DeleteOptions<T>,
|
|
432
438
|
): Promise<DeleteOutput> {
|
|
433
439
|
const schema = getMain(ns)
|
|
@@ -440,15 +446,15 @@ export class Client implements Agent {
|
|
|
440
446
|
|
|
441
447
|
public async get<const T extends RecordSchema>(
|
|
442
448
|
ns: T['key'] extends `literal:${string}`
|
|
443
|
-
?
|
|
449
|
+
? Main<T>
|
|
444
450
|
: Restricted<'This record type requires an "options" argument'>,
|
|
445
451
|
): Promise<GetOutput<T>>
|
|
446
452
|
public async get<const T extends RecordSchema>(
|
|
447
|
-
ns:
|
|
453
|
+
ns: Main<T>,
|
|
448
454
|
options?: GetOptions<T>,
|
|
449
455
|
): Promise<GetOutput<T>>
|
|
450
456
|
public async get<const T extends RecordSchema>(
|
|
451
|
-
ns:
|
|
457
|
+
ns: Main<T>,
|
|
452
458
|
options: GetOptions<T> = {} as GetOptions<T>,
|
|
453
459
|
): Promise<GetOutput<T>> {
|
|
454
460
|
const schema = getMain(ns)
|
|
@@ -462,17 +468,17 @@ export class Client implements Agent {
|
|
|
462
468
|
|
|
463
469
|
public async put<const T extends RecordSchema>(
|
|
464
470
|
ns: NonNullable<unknown> extends PutOptions<T>
|
|
465
|
-
?
|
|
471
|
+
? Main<T>
|
|
466
472
|
: Restricted<'This record type requires an "options" argument'>,
|
|
467
473
|
input: Omit<Infer<T>, '$type'>,
|
|
468
474
|
): Promise<PutOutput>
|
|
469
475
|
public async put<const T extends RecordSchema>(
|
|
470
|
-
ns:
|
|
476
|
+
ns: Main<T>,
|
|
471
477
|
input: Omit<Infer<T>, '$type'>,
|
|
472
478
|
options: PutOptions<T>,
|
|
473
479
|
): Promise<PutOutput>
|
|
474
480
|
public async put<const T extends RecordSchema>(
|
|
475
|
-
ns:
|
|
481
|
+
ns: Main<T>,
|
|
476
482
|
input: Omit<Infer<T>, '$type'>,
|
|
477
483
|
options: PutOptions<T> = {} as PutOptions<T>,
|
|
478
484
|
): Promise<PutOutput> {
|
|
@@ -485,7 +491,7 @@ export class Client implements Agent {
|
|
|
485
491
|
}
|
|
486
492
|
|
|
487
493
|
async list<const T extends RecordSchema>(
|
|
488
|
-
ns:
|
|
494
|
+
ns: Main<T>,
|
|
489
495
|
options?: ListOptions,
|
|
490
496
|
): Promise<ListOutput<T>> {
|
|
491
497
|
const schema = getMain(ns)
|
|
@@ -1,37 +1,26 @@
|
|
|
1
|
+
import { LexError, LexErrorCode, LexErrorData } from '@atproto/lex-data'
|
|
1
2
|
import { l } from '@atproto/lex-schema'
|
|
2
3
|
import { Payload } from './util.js'
|
|
3
4
|
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export type LexRpcErrorPayload<N extends LexErrorCode = LexErrorCode> = Payload<
|
|
6
|
+
LexErrorData<N>,
|
|
7
|
+
'application/json'
|
|
8
|
+
>
|
|
8
9
|
|
|
9
|
-
export class
|
|
10
|
-
|
|
10
|
+
export class LexRpcError<
|
|
11
|
+
N extends LexErrorCode = LexErrorCode,
|
|
12
|
+
> extends LexError<N> {
|
|
13
|
+
name = 'LexRpcError'
|
|
11
14
|
|
|
12
15
|
constructor(
|
|
13
|
-
|
|
14
|
-
message: string =
|
|
16
|
+
error: N,
|
|
17
|
+
message: string = `${error} Lexicon RPC error`,
|
|
15
18
|
options?: ErrorOptions,
|
|
16
19
|
) {
|
|
17
|
-
super(message, options)
|
|
20
|
+
super(error, message, options)
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
export type XrpcErrorBody<N extends XrpcErrorCode = XrpcErrorCode> = {
|
|
22
|
-
error: N
|
|
23
|
-
message?: string
|
|
24
|
-
}
|
|
25
|
-
export type XrpcErrorPayload<N extends XrpcErrorCode = XrpcErrorCode> = {
|
|
26
|
-
encoding: 'application/json'
|
|
27
|
-
body: XrpcErrorBody<N>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const xrpcErrorBodySchema: l.Schema<XrpcErrorBody> = l.object({
|
|
31
|
-
error: xrpcErrorCodeSchema,
|
|
32
|
-
message: l.optional(l.string()),
|
|
33
|
-
})
|
|
34
|
-
|
|
35
24
|
/**
|
|
36
25
|
* All unsuccessful responses should follow a standard error response
|
|
37
26
|
* schema. The Content-Type should be application/json, and the payload
|
|
@@ -44,20 +33,20 @@ const xrpcErrorBodySchema: l.Schema<XrpcErrorBody> = l.object({
|
|
|
44
33
|
*
|
|
45
34
|
* This function checks whether a given payload matches this schema.
|
|
46
35
|
*/
|
|
47
|
-
export function
|
|
36
|
+
export function isLexRpcErrorPayload(
|
|
48
37
|
payload: Payload | null,
|
|
49
|
-
): payload is
|
|
38
|
+
): payload is LexRpcErrorPayload {
|
|
50
39
|
return (
|
|
51
40
|
payload !== null &&
|
|
52
41
|
payload.encoding === 'application/json' &&
|
|
53
|
-
|
|
42
|
+
l.lexErrorData.matches(payload.body)
|
|
54
43
|
)
|
|
55
44
|
}
|
|
56
45
|
|
|
57
46
|
/**
|
|
58
47
|
* Interface representing a failed XRPC request result.
|
|
59
48
|
*/
|
|
60
|
-
type
|
|
49
|
+
type LexRpcFailureResult<N extends LexErrorCode, E> = l.ResultFailure<E> & {
|
|
61
50
|
readonly error: N
|
|
62
51
|
shouldRetry(): boolean
|
|
63
52
|
matchesSchema(): boolean
|
|
@@ -67,20 +56,20 @@ type XrpcFailureResult<N extends XrpcErrorCode, E> = l.ResultFailure<E> & {
|
|
|
67
56
|
* Class used to represent an HTTP request that resulted in an XRPC method error
|
|
68
57
|
* That is, a non-2xx response with a valid XRPC error payload.
|
|
69
58
|
*/
|
|
70
|
-
export class
|
|
59
|
+
export class LexRpcResponseError<
|
|
71
60
|
M extends l.Procedure | l.Query = l.Procedure | l.Query,
|
|
72
|
-
N extends
|
|
61
|
+
N extends LexErrorCode = LexErrorCode,
|
|
73
62
|
>
|
|
74
|
-
extends
|
|
75
|
-
implements
|
|
63
|
+
extends LexRpcError<N>
|
|
64
|
+
implements LexRpcFailureResult<N, LexRpcResponseError<M, N>>
|
|
76
65
|
{
|
|
77
|
-
name = '
|
|
66
|
+
name = 'LexRpcResponseError'
|
|
78
67
|
|
|
79
68
|
constructor(
|
|
80
69
|
readonly method: M,
|
|
81
70
|
readonly status: number,
|
|
82
71
|
readonly headers: Headers,
|
|
83
|
-
readonly payload:
|
|
72
|
+
readonly payload: LexRpcErrorPayload<N>,
|
|
84
73
|
options?: ErrorOptions,
|
|
85
74
|
) {
|
|
86
75
|
const { error, message } = payload.body
|
|
@@ -93,14 +82,14 @@ export class XrpcResponseError<
|
|
|
93
82
|
return this as this
|
|
94
83
|
}
|
|
95
84
|
|
|
96
|
-
get body():
|
|
85
|
+
get body(): LexErrorData {
|
|
97
86
|
return this.payload.body
|
|
98
87
|
}
|
|
99
88
|
|
|
100
89
|
matchesSchema(): this is M extends {
|
|
101
90
|
errors: readonly (infer E extends string)[]
|
|
102
91
|
}
|
|
103
|
-
?
|
|
92
|
+
? LexRpcResponseError<M, E>
|
|
104
93
|
: never {
|
|
105
94
|
return this.method.errors?.includes(this.error) ?? false
|
|
106
95
|
}
|
|
@@ -111,16 +100,29 @@ export class XrpcResponseError<
|
|
|
111
100
|
|
|
112
101
|
return true
|
|
113
102
|
}
|
|
103
|
+
|
|
104
|
+
toJSON() {
|
|
105
|
+
return this.payload.body
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
toResponse(): Response {
|
|
109
|
+
const { status, headers } = this
|
|
110
|
+
return Response.json(this.toJSON(), { status, headers })
|
|
111
|
+
}
|
|
114
112
|
}
|
|
115
113
|
|
|
116
114
|
/**
|
|
117
115
|
* This class represents an invalid XRPC response from the server.
|
|
118
116
|
*/
|
|
119
|
-
export class
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
export class LexRpcUpstreamError<
|
|
118
|
+
N extends 'InvalidResponse' | 'UpstreamFailure' =
|
|
119
|
+
| 'InvalidResponse'
|
|
120
|
+
| 'UpstreamFailure',
|
|
121
|
+
>
|
|
122
|
+
extends LexRpcError<N>
|
|
123
|
+
implements LexRpcFailureResult<N, LexRpcUpstreamError<N>>
|
|
122
124
|
{
|
|
123
|
-
name = '
|
|
125
|
+
name = 'LexRpcUpstreamError' as const
|
|
124
126
|
|
|
125
127
|
// For debugging purposes, we keep the response details here
|
|
126
128
|
readonly response: {
|
|
@@ -130,12 +132,13 @@ export class XrpcInvalidResponseError
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
constructor(
|
|
135
|
+
error: N,
|
|
133
136
|
message: string,
|
|
134
137
|
response: { status: number; headers: Headers },
|
|
135
138
|
payload: Payload | null,
|
|
136
139
|
options?: ErrorOptions,
|
|
137
140
|
) {
|
|
138
|
-
super(
|
|
141
|
+
super(error, message, { cause: options?.cause })
|
|
139
142
|
this.response = {
|
|
140
143
|
status: response.status,
|
|
141
144
|
headers: response.headers,
|
|
@@ -157,13 +160,17 @@ export class XrpcInvalidResponseError
|
|
|
157
160
|
// Do not retry client errors
|
|
158
161
|
return this.response.status >= 500
|
|
159
162
|
}
|
|
163
|
+
|
|
164
|
+
toResponse(): Response {
|
|
165
|
+
return Response.json(this.toJSON(), { status: 502 })
|
|
166
|
+
}
|
|
160
167
|
}
|
|
161
168
|
|
|
162
|
-
export class
|
|
163
|
-
extends
|
|
164
|
-
implements
|
|
169
|
+
export class LexRpcUnexpectedError
|
|
170
|
+
extends LexRpcError<'InternalServerError'>
|
|
171
|
+
implements LexRpcFailureResult<'InternalServerError', unknown>
|
|
165
172
|
{
|
|
166
|
-
name = '
|
|
173
|
+
name = 'LexRpcUnexpectedError' as const
|
|
167
174
|
|
|
168
175
|
protected constructor(message: string, options: Required<ErrorOptions>) {
|
|
169
176
|
super('InternalServerError', message, options)
|
|
@@ -183,13 +190,17 @@ export class XrpcUnexpectedError
|
|
|
183
190
|
return true
|
|
184
191
|
}
|
|
185
192
|
|
|
193
|
+
toResponse(): Response {
|
|
194
|
+
return Response.json(this.toJSON(), { status: 500 })
|
|
195
|
+
}
|
|
196
|
+
|
|
186
197
|
static from(
|
|
187
198
|
cause: unknown,
|
|
188
|
-
message: string = cause instanceof
|
|
199
|
+
message: string = cause instanceof LexError
|
|
189
200
|
? cause.message
|
|
190
201
|
: 'XRPC request failed',
|
|
191
|
-
):
|
|
192
|
-
if (cause instanceof
|
|
193
|
-
return new
|
|
202
|
+
): LexRpcUnexpectedError {
|
|
203
|
+
if (cause instanceof LexRpcUnexpectedError) return cause
|
|
204
|
+
return new LexRpcUnexpectedError(message, { cause })
|
|
194
205
|
}
|
|
195
206
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,35 +14,29 @@ const main =
|
|
|
14
14
|
/*#__PURE__*/
|
|
15
15
|
l.procedure(
|
|
16
16
|
$nsid,
|
|
17
|
-
/*#__PURE__*/ l.params(
|
|
18
|
-
/*#__PURE__*/ l.
|
|
19
|
-
'
|
|
20
|
-
/*#__PURE__*/ l.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
/*#__PURE__*/ l.params(),
|
|
18
|
+
/*#__PURE__*/ l.jsonPayload({
|
|
19
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
20
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
21
|
+
rkey: /*#__PURE__*/ l.optional(
|
|
22
|
+
/*#__PURE__*/ l.string({ format: 'record-key', maxLength: 512 }),
|
|
23
|
+
),
|
|
24
|
+
validate: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
|
|
25
|
+
record: /*#__PURE__*/ l.unknownObject(),
|
|
26
|
+
swapCommit: /*#__PURE__*/ l.optional(
|
|
27
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
28
|
+
),
|
|
29
|
+
}),
|
|
30
|
+
/*#__PURE__*/ l.jsonPayload({
|
|
31
|
+
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
32
|
+
cid: /*#__PURE__*/ l.string({ format: 'cid' }),
|
|
33
|
+
commit: /*#__PURE__*/ l.optional(
|
|
34
|
+
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
35
|
+
(() => RepoDefs.commitMeta) as any,
|
|
25
36
|
),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
30
|
-
),
|
|
31
|
-
}),
|
|
32
|
-
),
|
|
33
|
-
/*#__PURE__*/ l.payload(
|
|
34
|
-
'application/json',
|
|
35
|
-
/*#__PURE__*/ l.object({
|
|
36
|
-
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
37
|
-
cid: /*#__PURE__*/ l.string({ format: 'cid' }),
|
|
38
|
-
commit: /*#__PURE__*/ l.optional(
|
|
39
|
-
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
40
|
-
(() => RepoDefs.commitMeta) as any,
|
|
41
|
-
),
|
|
42
|
-
),
|
|
43
|
-
validationStatus: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
44
|
-
}),
|
|
45
|
-
),
|
|
37
|
+
),
|
|
38
|
+
validationStatus: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
39
|
+
}),
|
|
46
40
|
['InvalidSwap'],
|
|
47
41
|
)
|
|
48
42
|
export { main }
|
|
@@ -14,31 +14,25 @@ const main =
|
|
|
14
14
|
/*#__PURE__*/
|
|
15
15
|
l.procedure(
|
|
16
16
|
$nsid,
|
|
17
|
-
/*#__PURE__*/ l.params(
|
|
18
|
-
/*#__PURE__*/ l.
|
|
19
|
-
'
|
|
20
|
-
/*#__PURE__*/ l.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
/*#__PURE__*/ l.params(),
|
|
18
|
+
/*#__PURE__*/ l.jsonPayload({
|
|
19
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
20
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
21
|
+
rkey: /*#__PURE__*/ l.string({ format: 'record-key' }),
|
|
22
|
+
swapRecord: /*#__PURE__*/ l.optional(
|
|
23
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
24
|
+
),
|
|
25
|
+
swapCommit: /*#__PURE__*/ l.optional(
|
|
26
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
27
|
+
),
|
|
28
|
+
}),
|
|
29
|
+
/*#__PURE__*/ l.jsonPayload({
|
|
30
|
+
commit: /*#__PURE__*/ l.optional(
|
|
31
|
+
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
32
|
+
(() => RepoDefs.commitMeta) as any,
|
|
26
33
|
),
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
),
|
|
30
|
-
}),
|
|
31
|
-
),
|
|
32
|
-
/*#__PURE__*/ l.payload(
|
|
33
|
-
'application/json',
|
|
34
|
-
/*#__PURE__*/ l.object({
|
|
35
|
-
commit: /*#__PURE__*/ l.optional(
|
|
36
|
-
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
37
|
-
(() => RepoDefs.commitMeta) as any,
|
|
38
|
-
),
|
|
39
|
-
),
|
|
40
|
-
}),
|
|
41
|
-
),
|
|
34
|
+
),
|
|
35
|
+
}),
|
|
42
36
|
['InvalidSwap'],
|
|
43
37
|
)
|
|
44
38
|
export { main }
|
|
@@ -19,16 +19,11 @@ const main =
|
|
|
19
19
|
rkey: /*#__PURE__*/ l.string({ format: 'record-key' }),
|
|
20
20
|
cid: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
21
21
|
}),
|
|
22
|
-
/*#__PURE__*/ l.
|
|
23
|
-
'
|
|
24
|
-
/*#__PURE__*/ l.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
28
|
-
),
|
|
29
|
-
value: /*#__PURE__*/ l.unknownObject(),
|
|
30
|
-
}),
|
|
31
|
-
),
|
|
22
|
+
/*#__PURE__*/ l.jsonPayload({
|
|
23
|
+
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
24
|
+
cid: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
25
|
+
value: /*#__PURE__*/ l.unknownObject(),
|
|
26
|
+
}),
|
|
32
27
|
['RecordNotFound'],
|
|
33
28
|
)
|
|
34
29
|
export { main }
|
|
@@ -22,15 +22,12 @@ const main =
|
|
|
22
22
|
cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
23
23
|
reverse: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
|
|
24
24
|
}),
|
|
25
|
-
/*#__PURE__*/ l.
|
|
26
|
-
|
|
27
|
-
/*#__PURE__*/ l.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
),
|
|
32
|
-
}),
|
|
33
|
-
),
|
|
25
|
+
/*#__PURE__*/ l.jsonPayload({
|
|
26
|
+
cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
27
|
+
records: /*#__PURE__*/ l.array(
|
|
28
|
+
/*#__PURE__*/ l.ref<Def$0>((() => def$0) as any),
|
|
29
|
+
),
|
|
30
|
+
}),
|
|
34
31
|
)
|
|
35
32
|
export { main }
|
|
36
33
|
|