Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix private member #refreshSessionPromise error #35

Merged
merged 5 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/client/src/bsky/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -60,5 +58,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');
});
});
});
113 changes: 56 additions & 57 deletions packages/client/src/tsky/client.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
import {
type FetchHandler,
type RPCOptions,
XRPC,
type XRPCRequestOptions,
type XRPCResponse,
} from '@atcute/client';
import type { Procedures, Queries } from '@tsky/lexicons';

// From @atcute/client
type OutputOf<T> = T extends {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
output: any;
}
? T['output']
: never;

export class Client<Q = Queries, P = Procedures> {
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<K extends keyof Q>(
nsid: K,
options: RPCOptions<Q[K]>,
): Promise<XRPCResponse<OutputOf<Q[K]>>> {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
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<K extends keyof P>(
nsid: K,
options: RPCOptions<P[K]>,
): Promise<XRPCResponse<OutputOf<P[K]>>> {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
return this.xrpc.call(nsid as any, options);
}

/** Makes a request to the XRPC service */
async request(options: XRPCRequestOptions): Promise<XRPCResponse> {
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> = T extends {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
output: any;
}
? T['output']
: never;

export class Client<Q = Queries, P = Procedures> {
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<K extends keyof Q>(
nsid: K,
options: RPCOptions<Q[K]>,
): Promise<XRPCResponse<OutputOf<Q[K]>>> {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
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<K extends keyof P>(
nsid: K,
options: RPCOptions<P[K]>,
): Promise<XRPCResponse<OutputOf<P[K]>>> {
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
return this.xrpc.call(nsid as any, options);
}

/** Makes a request to the XRPC service */
async request(options: XRPCRequestOptions): Promise<XRPCResponse> {
return this.xrpc.request(options);
}
}
8 changes: 5 additions & 3 deletions packages/client/src/tsky/tsky.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { FetchHandler } 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';

export class Tsky {
client: Client<Queries>;

constructor({ handle }: { handle: FetchHandler }) {
this.client = new Client(handle);
constructor(manager: CredentialManager) {
const xrpc = new XRPC({ handler: manager });
this.client = new Client(xrpc);
}

get bsky() {
Expand Down
Loading