Skip to content

Commit fd489cb

Browse files
committed
fix(client): attempt to fix type errors
1 parent 5aeb250 commit fd489cb

File tree

4 files changed

+47
-64
lines changed

4 files changed

+47
-64
lines changed

packages/client/src/actor/actor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
ComAtprotoRepoStrongRef,
88
} from '@tsky/lexicons';
99
import type { Client } from '~/agent/client';
10-
import { List } from '~/list';
1110
import type { RPCOptions } from '~/types';
1211
import { Paginator } from '~/utils';
1312

packages/client/src/agent/agent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
AppBskyGraphGetStarterPack,
44
AppBskyGraphGetStarterPacks,
55
At,
6-
Queries,
76
} from '@tsky/lexicons';
87
import { ActorWithProfileFunction } from '~/actor';
98
import { Feed } from '~/feed';
@@ -15,7 +14,7 @@ import { Video } from '~/video';
1514
import { Client } from './client';
1615

1716
export class Agent {
18-
client: Client<Queries>;
17+
client: Client;
1918

2019
constructor(private handler: CredentialManager) {
2120
// Initialize the client

packages/client/src/agent/client.ts

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
} from '@atcute/client';
88
import type { At, Procedures, Queries } from '@tsky/lexicons';
99
import { parseAtUri } from '~/utils';
10-
import type { RPCOptions as GenericReqOptions, StrongRef } from '../types';
10+
import type { RPCOptions as GenericReqOptions } from '../types';
1111

1212
// From @atcute/client
1313
type OutputOf<T> = T extends {
@@ -19,7 +19,7 @@ type OutputOf<T> = T extends {
1919
const NO_SESSION_ERROR =
2020
'No session found. Please login to perform this action.';
2121

22-
export class Client<Q = Queries, P = Procedures> {
22+
export class Client {
2323
xrpc: XRPC;
2424
crenditials: CredentialManager;
2525

@@ -34,10 +34,10 @@ export class Client<Q = Queries, P = Procedures> {
3434
* @param options Options to include like parameters
3535
* @returns The response of the request
3636
*/
37-
async get<K extends keyof Q>(
37+
async get<K extends keyof Queries>(
3838
nsid: K,
39-
options: RPCOptions<Q[K]>,
40-
): Promise<XRPCResponse<OutputOf<Q[K]>>> {
39+
options: RPCOptions<Queries[K]>,
40+
): Promise<XRPCResponse<OutputOf<Queries[K]>>> {
4141
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
4242
return this.xrpc.get(nsid as any, options);
4343
}
@@ -48,10 +48,10 @@ export class Client<Q = Queries, P = Procedures> {
4848
* @param options Options to include like input body or parameters
4949
* @returns The response of the request
5050
*/
51-
async call<K extends keyof P>(
51+
async call<K extends keyof Procedures>(
5252
nsid: K,
53-
options: RPCOptions<P[K]>,
54-
): Promise<XRPCResponse<OutputOf<P[K]>>> {
53+
options: RPCOptions<Procedures[K]>,
54+
): Promise<XRPCResponse<OutputOf<Procedures[K]>>> {
5555
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
5656
return this.xrpc.call(nsid as any, options);
5757
}
@@ -68,27 +68,26 @@ export class Client<Q = Queries, P = Procedures> {
6868
* @param rkey The rkey to use.
6969
* @returns The record's AT URI and CID.
7070
*/
71-
async createRecord<K extends keyof P>(
71+
async createRecord<K extends keyof Procedures>(
7272
nsid: K,
73-
record: Omit<RPCOptions<P[K]>, '$type' | 'createdAt'>,
73+
record: Omit<RPCOptions<Procedures[K]>, '$type' | 'createdAt'>,
7474
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,
8986
},
90-
} as unknown as RPCOptions<P[keyof P]>,
91-
);
87+
repo: this.crenditials.session.did,
88+
...(rkey ? { rkey } : {}),
89+
},
90+
});
9291
return response.data;
9392
}
9493

@@ -103,23 +102,22 @@ export class Client<Q = Queries, P = Procedures> {
103102
nsid: string,
104103
record: object,
105104
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,
120116
},
121-
} as unknown as RPCOptions<P[keyof P]>,
122-
);
117+
repo: this.crenditials.session.did,
118+
rkey,
119+
},
120+
});
123121
return response.data;
124122
}
125123

@@ -132,14 +130,12 @@ export class Client<Q = Queries, P = Procedures> {
132130
options: GenericReqOptions = {},
133131
): Promise<void> {
134132
const { host: repo, collection, rkey } = parseAtUri(uri);
135-
if (repo !== this.crenditials.session?.did)
133+
if (repo !== this.crenditials.session?.did) {
136134
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+
});
144140
}
145141
}

packages/client/src/types.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
11
export type RPCOptions = { signal?: AbortSignal; headers?: HeadersInit };
2-
3-
/**
4-
* A reference to a record.
5-
*/
6-
export interface StrongRef {
7-
/** The record's AT URI. */
8-
uri: string;
9-
10-
/** The record's CID. */
11-
cid: string;
12-
}

0 commit comments

Comments
 (0)