Skip to content

Commit fcffd7b

Browse files
authored
fix: fix private member #refreshSessionPromise error (#35)
1 parent 2cda0c3 commit fcffd7b

File tree

3 files changed

+79
-62
lines changed

3 files changed

+79
-62
lines changed

packages/client/src/bsky/index.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ const TEST_CREDENTIALS = {
2424
},
2525
};
2626

27-
console.log('env keys', Object.keys(process.env));
28-
2927
async function getAliceTsky() {
3028
const manager = new CredentialManager({ service: 'https://bsky.social' });
3129
await manager.login({
@@ -60,5 +58,23 @@ describe('bsky', () => {
6058
expect(paginator.values[0].feed.length).toBeGreaterThan(0); // alice has some posts ;)
6159
expect(paginator.values[0].feed[0]).toHaveProperty('post');
6260
});
61+
62+
it('.feed()', async () => {
63+
const tsky = await getAliceTsky();
64+
65+
const paginator = await tsky.bsky.feed.getFeed({
66+
// "Birds! 🦉" custom feed
67+
// - https://bsky.app/profile/daryllmarie.bsky.social/feed/aaagllxbcbsje
68+
feed: 'at://did:plc:ffkgesg3jsv2j7aagkzrtcvt/app.bsky.feed.generator/aaagllxbcbsje',
69+
limit: 30,
70+
});
71+
72+
expect(paginator).toBeDefined();
73+
expect(paginator.values).toBeDefined();
74+
expect(paginator.values).toBeInstanceOf(Array);
75+
expect(paginator.values.length).toBe(1); // we should get the first page from the paginator
76+
expect(paginator.values[0].feed.length).toBeGreaterThan(0); // we found some birds posts ;)
77+
expect(paginator.values[0].feed[0]).toHaveProperty('post');
78+
});
6379
});
6480
});

packages/client/src/tsky/client.ts

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,56 @@
1-
import {
2-
type FetchHandler,
3-
type RPCOptions,
4-
XRPC,
5-
type XRPCRequestOptions,
6-
type XRPCResponse,
7-
} from '@atcute/client';
8-
import type { Procedures, Queries } from '@tsky/lexicons';
9-
10-
// From @atcute/client
11-
type OutputOf<T> = T extends {
12-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
13-
output: any;
14-
}
15-
? T['output']
16-
: never;
17-
18-
export class Client<Q = Queries, P = Procedures> {
19-
xrpc: XRPC;
20-
21-
constructor(handler: FetchHandler) {
22-
this.xrpc = new XRPC({ handler });
23-
}
24-
25-
/**
26-
* Makes a query (GET) request
27-
* @param nsid Namespace ID of a query endpoint
28-
* @param options Options to include like parameters
29-
* @returns The response of the request
30-
*/
31-
async get<K extends keyof Q>(
32-
nsid: K,
33-
options: RPCOptions<Q[K]>,
34-
): Promise<XRPCResponse<OutputOf<Q[K]>>> {
35-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
36-
return this.xrpc.get(nsid as any, options);
37-
}
38-
39-
/**
40-
* Makes a procedure (POST) request
41-
* @param nsid Namespace ID of a procedure endpoint
42-
* @param options Options to include like input body or parameters
43-
* @returns The response of the request
44-
*/
45-
async call<K extends keyof P>(
46-
nsid: K,
47-
options: RPCOptions<P[K]>,
48-
): Promise<XRPCResponse<OutputOf<P[K]>>> {
49-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
50-
return this.xrpc.call(nsid as any, options);
51-
}
52-
53-
/** Makes a request to the XRPC service */
54-
async request(options: XRPCRequestOptions): Promise<XRPCResponse> {
55-
return this.xrpc.request(options);
56-
}
57-
}
1+
import type {
2+
RPCOptions,
3+
XRPC,
4+
XRPCRequestOptions,
5+
XRPCResponse,
6+
} from '@atcute/client';
7+
import type { Procedures, Queries } from '@tsky/lexicons';
8+
9+
// From @atcute/client
10+
type OutputOf<T> = T extends {
11+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
12+
output: any;
13+
}
14+
? T['output']
15+
: never;
16+
17+
export class Client<Q = Queries, P = Procedures> {
18+
xrpc: XRPC;
19+
20+
constructor(xrpc: XRPC) {
21+
this.xrpc = xrpc;
22+
}
23+
24+
/**
25+
* Makes a query (GET) request
26+
* @param nsid Namespace ID of a query endpoint
27+
* @param options Options to include like parameters
28+
* @returns The response of the request
29+
*/
30+
async get<K extends keyof Q>(
31+
nsid: K,
32+
options: RPCOptions<Q[K]>,
33+
): Promise<XRPCResponse<OutputOf<Q[K]>>> {
34+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
35+
return this.xrpc.get(nsid as any, options);
36+
}
37+
38+
/**
39+
* Makes a procedure (POST) request
40+
* @param nsid Namespace ID of a procedure endpoint
41+
* @param options Options to include like input body or parameters
42+
* @returns The response of the request
43+
*/
44+
async call<K extends keyof P>(
45+
nsid: K,
46+
options: RPCOptions<P[K]>,
47+
): Promise<XRPCResponse<OutputOf<P[K]>>> {
48+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
49+
return this.xrpc.call(nsid as any, options);
50+
}
51+
52+
/** Makes a request to the XRPC service */
53+
async request(options: XRPCRequestOptions): Promise<XRPCResponse> {
54+
return this.xrpc.request(options);
55+
}
56+
}

packages/client/src/tsky/tsky.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import type { FetchHandler } from '@atcute/client';
1+
import type { CredentialManager } from '@atcute/client';
2+
import { XRPC } from '@atcute/client';
23
import type { Queries } from '@tsky/lexicons';
34
import { Bsky } from '~/bsky';
45
import { Client } from './client';
56

67
export class Tsky {
78
client: Client<Queries>;
89

9-
constructor({ handle }: { handle: FetchHandler }) {
10-
this.client = new Client(handle);
10+
constructor(manager: CredentialManager) {
11+
const xrpc = new XRPC({ handler: manager });
12+
this.client = new Client(xrpc);
1113
}
1214

1315
get bsky() {

0 commit comments

Comments
 (0)