Skip to content
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
88 changes: 44 additions & 44 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"include": ["docs", "packages/*"],
"ignore": [
".github",
".gitignore",
".vitepress",
".vscode",
"*.md",
"*.toml",
"build",
"dist",
"node_modules",
"package.json",
"tsconfig.json",
"packages/lexicons/src/lib/lexicons.ts"
]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"indentStyle": "space",
"lineWidth": 80,
"lineEnding": "crlf"
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"javascript": {
"formatter": {
"quoteStyle": "single"
}
}
}
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"include": ["docs", "packages/*"],
"ignore": [
".github",
".gitignore",
".vitepress",
".vscode",
"*.md",
"*.toml",
"build",
"dist",
"node_modules",
"package.json",
"tsconfig.json",
"packages/lexicons/src/lib/lexicons.ts"
]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"indentStyle": "space",
"lineWidth": 80,
"lineEnding": "lf"
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"javascript": {
"formatter": {
"quoteStyle": "single"
}
}
}
100 changes: 50 additions & 50 deletions packages/client/src/bsky/feed.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
import type {
AppBskyFeedGetFeed,
AppBskyFeedGetTimeline,
} from '@tsky/lexicons';
import type { Client } from '~/tsky/client';
import { Paginator } from '~/tsky/paginator';
export class Feed {
constructor(private client: Client) {}
/**
* Get a hydrated feed from an actor's selected feed generator. Implemented by App View.
*/
async getFeed(
params: AppBskyFeedGetFeed.Params,
options?: AppBskyFeedGetFeed.Input,
): Promise<Paginator<AppBskyFeedGetFeed.Output>> {
return Paginator.init(async (cursor) => {
const res = await this.client.get('app.bsky.feed.getFeed', {
...(options ?? {}),
params: {
cursor,
...params,
},
});
return res.data;
});
}
/**
* Get a view of the requesting account's home timeline. This is expected to be some form of reverse-chronological feed.
*/
getTimeline(
params: AppBskyFeedGetTimeline.Params,
options?: AppBskyFeedGetTimeline.Input,
): Promise<Paginator<AppBskyFeedGetTimeline.Output>> {
return Paginator.init(async (cursor) => {
const res = await this.client.get('app.bsky.feed.getTimeline', {
...(options ?? {}),
params: {
cursor,
...params,
},
});
return res.data;
});
}
}
import type {
AppBskyFeedGetFeed,
AppBskyFeedGetTimeline,
} from '@tsky/lexicons';
import type { Client } from '~/tsky/client';
import { Paginator } from '~/tsky/paginator';

export class Feed {
constructor(private client: Client) {}

/**
* Get a hydrated feed from an actor's selected feed generator. Implemented by App View.
*/
async getFeed(
params: AppBskyFeedGetFeed.Params,
options?: AppBskyFeedGetFeed.Input,
): Promise<Paginator<AppBskyFeedGetFeed.Output>> {
return Paginator.init(async (cursor) => {
const res = await this.client.get('app.bsky.feed.getFeed', {
...(options ?? {}),
params: {
cursor,
...params,
},
});

return res.data;
});
}

/**
* Get a view of the requesting account's home timeline. This is expected to be some form of reverse-chronological feed.
*/
getTimeline(
params: AppBskyFeedGetTimeline.Params,
options?: AppBskyFeedGetTimeline.Input,
): Promise<Paginator<AppBskyFeedGetTimeline.Output>> {
return Paginator.init(async (cursor) => {
const res = await this.client.get('app.bsky.feed.getTimeline', {
...(options ?? {}),
params: {
cursor,
...params,
},
});

return res.data;
});
}
}
158 changes: 79 additions & 79 deletions packages/client/src/bsky/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
import { CredentialManager } from '@atcute/client';
import { describe, expect, it } from 'vitest';
import { Tsky } from '~/index';
const formatSecret = (secret: string | undefined) => {
if (!secret) {
throw new Error('Secret is required');
}
return secret.replace(/^tsky /g, '').trim();
};
const TEST_CREDENTIALS = {
alice: {
handle: 'alice.tsky.dev',
did: 'did:plc:jguhdmnjclquqf5lsvkyxqy3',
password: 'alice_and_bob',
},
bob: {
handle: 'bob.tsky.dev',
did: 'did:plc:2ig7akkyfq256j42uxvc4g2h',
password: 'alice_and_bob',
},
};
async function getAliceTsky() {
const manager = new CredentialManager({ service: 'https://bsky.social' });
await manager.login({
identifier: TEST_CREDENTIALS.alice.handle,
password: TEST_CREDENTIALS.alice.password,
});
return new Tsky(manager);
}
describe('bsky', () => {
it('.profile()', async () => {
const tsky = await getAliceTsky();
const profile = await tsky.bsky.profile(TEST_CREDENTIALS.alice.did);
expect(profile).toBeDefined();
expect(profile).toHaveProperty('handle', TEST_CREDENTIALS.alice.handle);
});
describe('feed', () => {
it('.timeline()', async () => {
const tsky = await getAliceTsky();
const paginator = await tsky.bsky.feed.getTimeline({
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); // 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');
});
});
});
import { CredentialManager } from '@atcute/client';
import { describe, expect, it } from 'vitest';
import { Tsky } from '~/index';

const formatSecret = (secret: string | undefined) => {
if (!secret) {
throw new Error('Secret is required');
}

return secret.replace(/^tsky /g, '').trim();
};

const TEST_CREDENTIALS = {
alice: {
handle: 'alice.tsky.dev',
did: 'did:plc:jguhdmnjclquqf5lsvkyxqy3',
password: 'alice_and_bob',
},
bob: {
handle: 'bob.tsky.dev',
did: 'did:plc:2ig7akkyfq256j42uxvc4g2h',
password: 'alice_and_bob',
},
};

async function getAliceTsky() {
const manager = new CredentialManager({ service: 'https://bsky.social' });
await manager.login({
identifier: TEST_CREDENTIALS.alice.handle,
password: TEST_CREDENTIALS.alice.password,
});

return new Tsky(manager);
}

describe('bsky', () => {
it('.profile()', async () => {
const tsky = await getAliceTsky();
const profile = await tsky.bsky.profile(TEST_CREDENTIALS.alice.did);

expect(profile).toBeDefined();
expect(profile).toHaveProperty('handle', TEST_CREDENTIALS.alice.handle);
});

describe('feed', () => {
it('.timeline()', async () => {
const tsky = await getAliceTsky();

const paginator = await tsky.bsky.feed.getTimeline({
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); // 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');
});
});
});
Loading
Loading