From 025fd648fc7a07c5e620266c0cbb4de4c3a965e0 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Wed, 8 Jan 2025 23:05:05 +0900 Subject: [PATCH 1/5] chore: fix lint errors fro type import --- packages/client/src/tsky/client.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/client/src/tsky/client.ts b/packages/client/src/tsky/client.ts index 20fe1cd..81d24ba 100644 --- a/packages/client/src/tsky/client.ts +++ b/packages/client/src/tsky/client.ts @@ -1,9 +1,8 @@ -import { - type FetchHandler, - type RPCOptions, +import type { + RPCOptions, XRPC, - type XRPCRequestOptions, - type XRPCResponse, + XRPCRequestOptions, + XRPCResponse, } from '@atcute/client'; import type { Procedures, Queries } from '@tsky/lexicons'; From 8d0e9d69be12f2aba1d4395b772234f8abf0ec3d Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Wed, 8 Jan 2025 23:26:22 +0900 Subject: [PATCH 2/5] fix: fix private member #refreshSessionPromise error --- packages/client/src/bsky/index.test.ts | 6 +- packages/client/src/tsky/client.ts | 112 ++++++++++++------------- packages/client/src/tsky/tsky.ts | 6 +- 3 files changed, 63 insertions(+), 61 deletions(-) diff --git a/packages/client/src/bsky/index.test.ts b/packages/client/src/bsky/index.test.ts index ba1319e..40686dd 100644 --- a/packages/client/src/bsky/index.test.ts +++ b/packages/client/src/bsky/index.test.ts @@ -1,4 +1,4 @@ -import { CredentialManager } from '@atcute/client'; +import { CredentialManager, XRPC } from '@atcute/client'; import { describe, expect, it } from 'vitest'; import { Tsky } from '~/index'; @@ -33,7 +33,9 @@ async function getAliceTsky() { password: TEST_CREDENTIALS.alice.appPassword, }); - return new Tsky(manager); + const xrpc = new XRPC({ handler: manager }); + + return new Tsky(xrpc); } describe('bsky', () => { diff --git a/packages/client/src/tsky/client.ts b/packages/client/src/tsky/client.ts index 81d24ba..d83d372 100644 --- a/packages/client/src/tsky/client.ts +++ b/packages/client/src/tsky/client.ts @@ -1,56 +1,56 @@ -import type { - RPCOptions, - XRPC, - XRPCRequestOptions, - XRPCResponse, -} from '@atcute/client'; -import type { Procedures, Queries } from '@tsky/lexicons'; - -// From @atcute/client -type OutputOf = T extends { - // biome-ignore lint/suspicious/noExplicitAny: - output: any; -} - ? T['output'] - : never; - -export class Client { - xrpc: XRPC; - - constructor(handler: FetchHandler) { - this.xrpc = new XRPC({ handler }); - } - - /** - * Makes a query (GET) request - * @param nsid Namespace ID of a query endpoint - * @param options Options to include like parameters - * @returns The response of the request - */ - async get( - nsid: K, - options: RPCOptions, - ): Promise>> { - // biome-ignore lint/suspicious/noExplicitAny: - return this.xrpc.get(nsid as any, options); - } - - /** - * Makes a procedure (POST) request - * @param nsid Namespace ID of a procedure endpoint - * @param options Options to include like input body or parameters - * @returns The response of the request - */ - async call( - nsid: K, - options: RPCOptions, - ): Promise>> { - // biome-ignore lint/suspicious/noExplicitAny: - return this.xrpc.call(nsid as any, options); - } - - /** Makes a request to the XRPC service */ - async request(options: XRPCRequestOptions): Promise { - return this.xrpc.request(options); - } -} +import type { + RPCOptions, + XRPC, + XRPCRequestOptions, + XRPCResponse, +} from '@atcute/client'; +import type { Procedures, Queries } from '@tsky/lexicons'; + +// From @atcute/client +type OutputOf = T extends { + // biome-ignore lint/suspicious/noExplicitAny: + output: any; +} + ? T['output'] + : never; + +export class Client { + xrpc: XRPC; + + constructor(xrpc: XRPC) { + this.xrpc = xrpc; + } + + /** + * Makes a query (GET) request + * @param nsid Namespace ID of a query endpoint + * @param options Options to include like parameters + * @returns The response of the request + */ + async get( + nsid: K, + options: RPCOptions, + ): Promise>> { + // biome-ignore lint/suspicious/noExplicitAny: + return this.xrpc.get(nsid as any, options); + } + + /** + * Makes a procedure (POST) request + * @param nsid Namespace ID of a procedure endpoint + * @param options Options to include like input body or parameters + * @returns The response of the request + */ + async call( + nsid: K, + options: RPCOptions, + ): Promise>> { + // biome-ignore lint/suspicious/noExplicitAny: + return this.xrpc.call(nsid as any, options); + } + + /** Makes a request to the XRPC service */ + async request(options: XRPCRequestOptions): Promise { + return this.xrpc.request(options); + } +} diff --git a/packages/client/src/tsky/tsky.ts b/packages/client/src/tsky/tsky.ts index c221827..0c4873b 100644 --- a/packages/client/src/tsky/tsky.ts +++ b/packages/client/src/tsky/tsky.ts @@ -1,4 +1,4 @@ -import type { FetchHandler } from '@atcute/client'; +import type { XRPC } from '@atcute/client'; import type { Queries } from '@tsky/lexicons'; import { Bsky } from '~/bsky'; import { Client } from './client'; @@ -6,8 +6,8 @@ import { Client } from './client'; export class Tsky { client: Client; - constructor({ handle }: { handle: FetchHandler }) { - this.client = new Client(handle); + constructor(xrpc: XRPC) { + this.client = new Client(xrpc); } get bsky() { From 28f9a1e759718f1a191325248cf06da0bc8a7653 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Wed, 8 Jan 2025 23:35:07 +0900 Subject: [PATCH 3/5] chore: remove debug log --- packages/client/src/bsky/index.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/client/src/bsky/index.test.ts b/packages/client/src/bsky/index.test.ts index 40686dd..207bd81 100644 --- a/packages/client/src/bsky/index.test.ts +++ b/packages/client/src/bsky/index.test.ts @@ -24,8 +24,6 @@ const TEST_CREDENTIALS = { }, }; -console.log('env keys', Object.keys(process.env)); - async function getAliceTsky() { const manager = new CredentialManager({ service: 'https://bsky.social' }); await manager.login({ From 54afc7aeb740a269d58b2813ec7b93f773de7edb Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Thu, 9 Jan 2025 00:05:56 +0900 Subject: [PATCH 4/5] test: add test for `tsky.bsky.feed.getFeed()` --- packages/client/src/bsky/index.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/client/src/bsky/index.test.ts b/packages/client/src/bsky/index.test.ts index 207bd81..75ca6e6 100644 --- a/packages/client/src/bsky/index.test.ts +++ b/packages/client/src/bsky/index.test.ts @@ -60,5 +60,23 @@ describe('bsky', () => { expect(paginator.values[0].feed.length).toBeGreaterThan(0); // alice has some posts ;) expect(paginator.values[0].feed[0]).toHaveProperty('post'); }); + + it('.feed()', async () => { + const tsky = await getAliceTsky(); + + const paginator = await tsky.bsky.feed.getFeed({ + // "Birds! 🦉" custom feed + // - https://bsky.app/profile/daryllmarie.bsky.social/feed/aaagllxbcbsje + feed: 'at://did:plc:ffkgesg3jsv2j7aagkzrtcvt/app.bsky.feed.generator/aaagllxbcbsje', + limit: 30, + }); + + expect(paginator).toBeDefined(); + expect(paginator.values).toBeDefined(); + expect(paginator.values).toBeInstanceOf(Array); + expect(paginator.values.length).toBe(1); // we should get the first page from the paginator + expect(paginator.values[0].feed.length).toBeGreaterThan(0); // we found some birds posts ;) + expect(paginator.values[0].feed[0]).toHaveProperty('post'); + }); }); }); From c9c94e7093fa642f3a49215d51356e78091e2da1 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Thu, 9 Jan 2025 16:23:36 +0900 Subject: [PATCH 5/5] refactor: initialize `XRPC` within `Tsky` constructor --- packages/client/src/bsky/index.test.ts | 6 ++---- packages/client/src/tsky/tsky.ts | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/client/src/bsky/index.test.ts b/packages/client/src/bsky/index.test.ts index 75ca6e6..4ac6f2f 100644 --- a/packages/client/src/bsky/index.test.ts +++ b/packages/client/src/bsky/index.test.ts @@ -1,4 +1,4 @@ -import { CredentialManager, XRPC } from '@atcute/client'; +import { CredentialManager } from '@atcute/client'; import { describe, expect, it } from 'vitest'; import { Tsky } from '~/index'; @@ -31,9 +31,7 @@ async function getAliceTsky() { password: TEST_CREDENTIALS.alice.appPassword, }); - const xrpc = new XRPC({ handler: manager }); - - return new Tsky(xrpc); + return new Tsky(manager); } describe('bsky', () => { diff --git a/packages/client/src/tsky/tsky.ts b/packages/client/src/tsky/tsky.ts index 0c4873b..8f123af 100644 --- a/packages/client/src/tsky/tsky.ts +++ b/packages/client/src/tsky/tsky.ts @@ -1,4 +1,5 @@ -import type { XRPC } from '@atcute/client'; +import type { CredentialManager } from '@atcute/client'; +import { XRPC } from '@atcute/client'; import type { Queries } from '@tsky/lexicons'; import { Bsky } from '~/bsky'; import { Client } from './client'; @@ -6,7 +7,8 @@ import { Client } from './client'; export class Tsky { client: Client; - constructor(xrpc: XRPC) { + constructor(manager: CredentialManager) { + const xrpc = new XRPC({ handler: manager }); this.client = new Client(xrpc); }