Skip to content

Commit 856cac8

Browse files
feat: restructuring the api (#52)
1 parent b9c7c9e commit 856cac8

File tree

30 files changed

+130
-176
lines changed

30 files changed

+130
-176
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
AppBskyActorDefs,
33
AppBskyFeedGetAuthorFeed,
44
} from '@tsky/lexicons';
5-
import type { Client } from '~/tsky/client';
5+
import type { Client } from '~/agent/client';
66
import type { RPCOptions } from '~/types';
77
import { Paginator } from '~/utils';
88

packages/client/src/agent/agent.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { type CredentialManager, XRPC } from '@atcute/client';
2+
import type { Queries } from '@tsky/lexicons';
3+
import { Actor } from '~/actor';
4+
import { Feed } from '~/feed';
5+
import { List } from '~/list';
6+
import { StarterPack } from '~/starterpack';
7+
import { User } from '~/user';
8+
import { Video } from '~/video';
9+
import { Client } from './client';
10+
11+
export class Agent {
12+
private client: Client<Queries>;
13+
14+
constructor(private handler: CredentialManager) {
15+
// Initialize the client
16+
const xrpc = new XRPC({ handler: this.handler });
17+
this.client = new Client(xrpc);
18+
}
19+
20+
get session() {
21+
return this.handler.session;
22+
}
23+
24+
actor(identifier: string) {
25+
return new Actor(this.client, identifier);
26+
}
27+
28+
list(uri: string) {
29+
return new List(this.client, uri);
30+
}
31+
32+
get feed() {
33+
return new Feed(this.client);
34+
}
35+
36+
get user() {
37+
if (!this.session) {
38+
throw new Error('There is no active session');
39+
}
40+
41+
return new User(this.client, this.session.handle);
42+
}
43+
44+
get video() {
45+
if (!this.session) {
46+
throw new Error('There is no active session');
47+
}
48+
49+
return new Video(this.client);
50+
}
51+
52+
get starterpack() {
53+
return new StarterPack(this.client);
54+
}
55+
}

packages/client/src/agent/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './agent';

packages/client/src/auth/auth.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

packages/client/src/auth/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/client/src/bsky/bsky.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/client/src/bsky/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/client/src/bsky/feed/feed.test.ts renamed to packages/client/src/feed/feed.test.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { Tsky } from '~/index';
2+
import { createAgent } from '~/tsky';
33

44
const TEST_CREDENTIALS = {
55
alice: {
@@ -14,21 +14,13 @@ const TEST_CREDENTIALS = {
1414
},
1515
};
1616

17-
async function getAliceTsky() {
18-
const tsky = new Tsky();
19-
20-
await tsky.auth.login(
21-
TEST_CREDENTIALS.alice.handle,
22-
TEST_CREDENTIALS.alice.password,
23-
);
24-
25-
return tsky;
26-
}
27-
2817
describe('feed', () => {
2918
it('.getFeed()', async () => {
30-
const tsky = await getAliceTsky();
31-
const paginator = await tsky.bsky.feed.get({
19+
const agent = await createAgent({
20+
identifier: TEST_CREDENTIALS.alice.handle,
21+
password: TEST_CREDENTIALS.alice.password,
22+
});
23+
const paginator = await agent.feed.get({
3224
// "Birds! 🦉" custom feed
3325
// - https://bsky.app/profile/daryllmarie.bsky.social/feed/aaagllxbcbsje
3426
feed: 'at://did:plc:ffkgesg3jsv2j7aagkzrtcvt/app.bsky.feed.generator/aaagllxbcbsje',

0 commit comments

Comments
 (0)