@@ -7,7 +7,7 @@ import type {
7
7
} from '@atcute/client' ;
8
8
import type { At , Procedures , Queries } from '@tsky/lexicons' ;
9
9
import { parseAtUri } from '~/utils' ;
10
- import type { RPCOptions as GenericReqOptions , StrongRef } from '../types' ;
10
+ import type { RPCOptions as GenericReqOptions } from '../types' ;
11
11
12
12
// From @atcute /client
13
13
type OutputOf < T > = T extends {
@@ -19,7 +19,7 @@ type OutputOf<T> = T extends {
19
19
const NO_SESSION_ERROR =
20
20
'No session found. Please login to perform this action.' ;
21
21
22
- export class Client < Q = Queries , P = Procedures > {
22
+ export class Client {
23
23
xrpc : XRPC ;
24
24
crenditials : CredentialManager ;
25
25
@@ -34,10 +34,10 @@ export class Client<Q = Queries, P = Procedures> {
34
34
* @param options Options to include like parameters
35
35
* @returns The response of the request
36
36
*/
37
- async get < K extends keyof Q > (
37
+ async get < K extends keyof Queries > (
38
38
nsid : K ,
39
- options : RPCOptions < Q [ K ] > ,
40
- ) : Promise < XRPCResponse < OutputOf < Q [ K ] > > > {
39
+ options : RPCOptions < Queries [ K ] > ,
40
+ ) : Promise < XRPCResponse < OutputOf < Queries [ K ] > > > {
41
41
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
42
42
return this . xrpc . get ( nsid as any , options ) ;
43
43
}
@@ -48,10 +48,10 @@ export class Client<Q = Queries, P = Procedures> {
48
48
* @param options Options to include like input body or parameters
49
49
* @returns The response of the request
50
50
*/
51
- async call < K extends keyof P > (
51
+ async call < K extends keyof Procedures > (
52
52
nsid : K ,
53
- options : RPCOptions < P [ K ] > ,
54
- ) : Promise < XRPCResponse < OutputOf < P [ K ] > > > {
53
+ options : RPCOptions < Procedures [ K ] > ,
54
+ ) : Promise < XRPCResponse < OutputOf < Procedures [ K ] > > > {
55
55
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
56
56
return this . xrpc . call ( nsid as any , options ) ;
57
57
}
@@ -68,27 +68,26 @@ export class Client<Q = Queries, P = Procedures> {
68
68
* @param rkey The rkey to use.
69
69
* @returns The record's AT URI and CID.
70
70
*/
71
- async createRecord < K extends keyof P > (
71
+ async createRecord < K extends keyof Procedures > (
72
72
nsid : K ,
73
- record : Omit < RPCOptions < P [ K ] > , '$type' | 'createdAt' > ,
73
+ record : Omit < RPCOptions < Procedures [ K ] > , '$type' | 'createdAt' > ,
74
74
rkey ?: string ,
75
- ) : Promise < StrongRef > {
76
- if ( ! this . crenditials . session ) throw new Error ( NO_SESSION_ERROR ) ;
77
- const response = await this . call (
78
- 'com.atproto.repo.createRecord' as keyof P ,
79
- {
80
- data : {
81
- collection : nsid ,
82
- record : {
83
- $type : nsid ,
84
- createdAt : new Date ( ) . toISOString ( ) ,
85
- ...record ,
86
- } ,
87
- repo : this . crenditials . session . did ,
88
- ...( rkey ? { rkey } : { } ) ,
75
+ ) : Promise < OutputOf < Procedures [ 'com.atproto.repo.createRecord' ] > > {
76
+ if ( ! this . crenditials . session ) {
77
+ throw new Error ( NO_SESSION_ERROR ) ;
78
+ }
79
+ const response = await this . call ( 'com.atproto.repo.createRecord' , {
80
+ data : {
81
+ collection : nsid ,
82
+ record : {
83
+ $type : nsid ,
84
+ createdAt : new Date ( ) . toISOString ( ) ,
85
+ ...record ,
89
86
} ,
90
- } as unknown as RPCOptions < P [ keyof P ] > ,
91
- ) ;
87
+ repo : this . crenditials . session . did ,
88
+ ...( rkey ? { rkey } : { } ) ,
89
+ } ,
90
+ } ) ;
92
91
return response . data ;
93
92
}
94
93
@@ -103,23 +102,22 @@ export class Client<Q = Queries, P = Procedures> {
103
102
nsid : string ,
104
103
record : object ,
105
104
rkey : string ,
106
- ) : Promise < StrongRef > {
107
- if ( ! this . crenditials . session ) throw new Error ( NO_SESSION_ERROR ) ;
108
- const response = await this . call (
109
- 'com.atproto.repo.putRecord' as keyof P ,
110
- {
111
- data : {
112
- collection : nsid ,
113
- record : {
114
- $type : nsid ,
115
- createdAt : new Date ( ) . toISOString ( ) ,
116
- ...record ,
117
- } ,
118
- repo : this . crenditials . session . did ,
119
- rkey,
105
+ ) : Promise < OutputOf < Procedures [ 'com.atproto.repo.putRecord' ] > > {
106
+ if ( ! this . crenditials . session ) {
107
+ throw new Error ( NO_SESSION_ERROR ) ;
108
+ }
109
+ const response = await this . call ( 'com.atproto.repo.putRecord' , {
110
+ data : {
111
+ collection : nsid ,
112
+ record : {
113
+ $type : nsid ,
114
+ createdAt : new Date ( ) . toISOString ( ) ,
115
+ ...record ,
120
116
} ,
121
- } as unknown as RPCOptions < P [ keyof P ] > ,
122
- ) ;
117
+ repo : this . crenditials . session . did ,
118
+ rkey,
119
+ } ,
120
+ } ) ;
123
121
return response . data ;
124
122
}
125
123
@@ -132,14 +130,12 @@ export class Client<Q = Queries, P = Procedures> {
132
130
options : GenericReqOptions = { } ,
133
131
) : Promise < void > {
134
132
const { host : repo , collection, rkey } = parseAtUri ( uri ) ;
135
- if ( repo !== this . crenditials . session ?. did )
133
+ if ( repo !== this . crenditials . session ?. did ) {
136
134
throw new Error ( 'Can only delete own record.' ) ;
137
- await this . call (
138
- 'com.atproto.repo.deleteRecord' as keyof P ,
139
- {
140
- data : { collection, repo, rkey } ,
141
- ...options ,
142
- } as unknown as RPCOptions < P [ keyof P ] > ,
143
- ) ;
135
+ }
136
+ await this . call ( 'com.atproto.repo.deleteRecord' , {
137
+ data : { collection, repo, rkey } ,
138
+ ...options ,
139
+ } ) ;
144
140
}
145
141
}
0 commit comments