From d21a068dd58509074252668be0dd19dd5e4cbf27 Mon Sep 17 00:00:00 2001 From: Dominik Biedebach Date: Sat, 30 Nov 2024 07:12:49 +0100 Subject: [PATCH 1/3] refactor: move tsky class into own subfile and export all files from index --- packages/core/src/index.ts | 97 +++++--------------------------------- packages/core/src/tsky.ts | 86 +++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 86 deletions(-) create mode 100644 packages/core/src/tsky.ts diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 4fb83e4..4c6e95c 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,86 +1,11 @@ -import type { - AppBskyActorDefs, - AppBskyActorGetProfile, - AppBskyActorGetProfiles, - AppBskyActorSearchActors, - AppBskyActorSearchActorsTypeahead, - AppBskyNS, -} from '@atproto/api'; -import { Paginator } from './paginate'; - -export class TSky { - constructor(private instance: AppBskyNS) {} - - /** - * Get detailed profile view of an actor. Does not require auth, but contains relevant metadata with auth. - */ - profile( - identifier: string, - options?: AppBskyActorGetProfile.CallOptions, - ): Promise; - /** - * Get detailed profile views of multiple actors. - */ - profile( - identifiers: string[], - options?: AppBskyActorGetProfiles.CallOptions, - ): Promise; - - async profile( - identifier: string | string[], - options?: - | AppBskyActorGetProfile.CallOptions - | AppBskyActorGetProfiles.CallOptions, - ) { - if (Array.isArray(identifier)) { - const res = await this.instance.actor.getProfiles( - { actors: identifier }, - options, - ); - - return res.data.profiles; - } - - const res = await this.instance.actor.getProfile( - { actor: identifier[0] }, - options, - ); - - return res.data; - } - - /** - * Find actor suggestions for a prefix search term. Expected use is for auto-completion during text field entry. Does not require auth. - */ - async typeahead( - params: AppBskyActorSearchActorsTypeahead.QueryParams, - options?: AppBskyActorSearchActorsTypeahead.CallOptions, - ) { - const res = await this.instance.actor.searchActorsTypeahead( - params, - options, - ); - - return res.data.actors; - } - - /** - * Find actors (profiles) matching search criteria. Does not require auth. - */ - async search( - params: AppBskyActorSearchActors.QueryParams = {}, - options?: AppBskyActorSearchActors.CallOptions, - ) { - return new Paginator(async (cursor) => { - const res = await this.instance.actor.searchActors( - { - cursor, - ...params, - }, - options, - ); - - return res.data; - }); - } -} +export * from './actor' +export * from './feed' +export * from './list' +export * from './paginate' +export * from './post' +export * from './preference' +export * from './starterPack' +export * from './tsky' +export * from './video' + +export { TSky as default } from './tsky' \ No newline at end of file diff --git a/packages/core/src/tsky.ts b/packages/core/src/tsky.ts new file mode 100644 index 0000000..6dcf121 --- /dev/null +++ b/packages/core/src/tsky.ts @@ -0,0 +1,86 @@ +import type { + AppBskyActorDefs, + AppBskyActorGetProfile, + AppBskyActorGetProfiles, + AppBskyActorSearchActors, + AppBskyActorSearchActorsTypeahead, + AppBskyNS, +} from '@atproto/api'; +import { Paginator } from './paginate'; + +export class TSky { + constructor(private instance: AppBskyNS) {} + + /** + * Get detailed profile view of an actor. Does not require auth, but contains relevant metadata with auth. + */ + profile( + identifier: string, + options?: AppBskyActorGetProfile.CallOptions, + ): Promise; + /** + * Get detailed profile views of multiple actors. + */ + profile( + identifiers: string[], + options?: AppBskyActorGetProfiles.CallOptions, + ): Promise; + + async profile( + identifier: string | string[], + options?: + | AppBskyActorGetProfile.CallOptions + | AppBskyActorGetProfiles.CallOptions, + ) { + if (Array.isArray(identifier)) { + const res = await this.instance.actor.getProfiles( + { actors: identifier }, + options, + ); + + return res.data.profiles; + } + + const res = await this.instance.actor.getProfile( + { actor: identifier[0] }, + options, + ); + + return res.data; + } + + /** + * Find actor suggestions for a prefix search term. Expected use is for auto-completion during text field entry. Does not require auth. + */ + async typeahead( + params: AppBskyActorSearchActorsTypeahead.QueryParams, + options?: AppBskyActorSearchActorsTypeahead.CallOptions, + ) { + const res = await this.instance.actor.searchActorsTypeahead( + params, + options, + ); + + return res.data.actors; + } + + /** + * Find actors (profiles) matching search criteria. Does not require auth. + */ + async search( + params: AppBskyActorSearchActors.QueryParams = {}, + options?: AppBskyActorSearchActors.CallOptions, + ) { + return new Paginator(async (cursor) => { + const res = await this.instance.actor.searchActors( + { + cursor, + ...params, + }, + options, + ); + + return res.data; + }); + } +} From 5c867668f7a68859f9a81cb0368aeb024b2d9efe Mon Sep 17 00:00:00 2001 From: Dominik Biedebach Date: Sat, 30 Nov 2024 08:06:37 +0100 Subject: [PATCH 2/3] refactor: adjust directory structure and imports, add import alias --- packages/core/src/actor.ts | 347 ------------------ packages/core/src/bsky/Actor.ts | 42 +++ packages/core/src/bsky/BaseActor.ts | 137 +++++++ packages/core/src/{feed.ts => bsky/Feed.ts} | 2 +- packages/core/src/{list.ts => bsky/List.ts} | 2 +- packages/core/src/{post.ts => bsky/Post.ts} | 2 +- .../{preference.ts => bsky/Preferences.ts} | 0 .../{starterPack.ts => bsky/StarterPack.ts} | 2 +- packages/core/src/bsky/Suggestions.ts | 49 +++ packages/core/src/bsky/Thread.ts | 22 ++ packages/core/src/bsky/User.ts | 89 +++++ packages/core/src/{video.ts => bsky/Video.ts} | 0 packages/core/src/bsky/index.ts | 11 + packages/core/src/index.ts | 9 +- packages/core/src/tsky/index.ts | 2 + packages/core/src/{ => tsky}/paginate.ts | 0 packages/core/src/{ => tsky}/tsky.ts | 0 packages/core/tsconfig.json | 8 + 18 files changed, 365 insertions(+), 359 deletions(-) delete mode 100644 packages/core/src/actor.ts create mode 100644 packages/core/src/bsky/Actor.ts create mode 100644 packages/core/src/bsky/BaseActor.ts rename packages/core/src/{feed.ts => bsky/Feed.ts} (95%) rename packages/core/src/{list.ts => bsky/List.ts} (91%) rename packages/core/src/{post.ts => bsky/Post.ts} (94%) rename packages/core/src/{preference.ts => bsky/Preferences.ts} (100%) rename packages/core/src/{starterPack.ts => bsky/StarterPack.ts} (91%) create mode 100644 packages/core/src/bsky/Suggestions.ts create mode 100644 packages/core/src/bsky/Thread.ts create mode 100644 packages/core/src/bsky/User.ts rename packages/core/src/{video.ts => bsky/Video.ts} (100%) create mode 100644 packages/core/src/bsky/index.ts create mode 100644 packages/core/src/tsky/index.ts rename packages/core/src/{ => tsky}/paginate.ts (100%) rename packages/core/src/{ => tsky}/tsky.ts (100%) create mode 100644 packages/core/tsconfig.json diff --git a/packages/core/src/actor.ts b/packages/core/src/actor.ts deleted file mode 100644 index 3373d60..0000000 --- a/packages/core/src/actor.ts +++ /dev/null @@ -1,347 +0,0 @@ -import type { - AppBskyFeedGetActorFeeds, - AppBskyFeedGetActorLikes, - AppBskyFeedGetAuthorFeed, - AppBskyFeedGetSuggestedFeeds, - AppBskyGraphGetKnownFollowers, - AppBskyGraphGetListBlocks, - AppBskyGraphGetListMutes, - AppBskyGraphGetMutes, - AppBskyGraphGetRelationships, - AppBskyGraphGetSuggestedFollowsByActor, - AppBskyGraphMuteActor, - AppBskyGraphMuteActorList, - AppBskyGraphMuteThread, - AppBskyGraphUnmuteActor, - AppBskyGraphUnmuteActorList, - AppBskyGraphUnmuteThread, - AppBskyNS, -} from '@atproto/api'; -import { Paginator } from './paginate'; -import { Preferences } from './preference'; - -export class BaseActor { - constructor( - readonly instance: AppBskyNS, - readonly actor: string, - ) {} - - /** - * Get a list of starter packs created by the actor. - */ - starterPacks(limit?: number) { - return new Paginator(async (cursor) => { - const res = await this.instance.graph.getActorStarterPacks({ - cursor, - actor: this.actor, - limit, - }); - - return res.data; - }); - } - - /** - * Enumerates accounts which follow a specified account (actor). - */ - followers(limit?: number) { - return new Paginator(async (cursor) => { - const res = await this.instance.graph.getFollowers({ - cursor, - actor: this.actor, - limit, - }); - - return res.data; - }); - } - - /** - * Enumerates accounts which a specified account (actor) follows. - */ - follows(limit?: number) { - return new Paginator(async (cursor) => { - const res = await this.instance.graph.getFollows({ - cursor, - actor: this.actor, - limit, - }); - - return res.data; - }); - } - - /** - * Enumerates the lists created by a specified account (actor). - */ - lists(limit?: number) { - return new Paginator(async (cursor) => { - const res = await this.instance.graph.getLists({ - cursor, - actor: this.actor, - limit, - }); - - return res.data; - }); - } - - /** - * Enumerates public relationships between one account, and a list of other accounts. Does not require auth. - */ - async relationships( - others?: string[], - options?: AppBskyGraphGetRelationships.CallOptions, - ) { - const res = await this.instance.graph.getRelationships( - { - actor: this.actor, - others, - }, - options, - ); - - return res.data; - } - - /** - * Get a view of an actor's 'author feed' (post and reposts by the author). Does not require auth. - */ - feeds(limit?: number, options?: AppBskyFeedGetActorFeeds.CallOptions) { - return new Paginator(async (cursor) => { - const res = await this.instance.feed.getActorFeeds( - { cursor, actor: this.actor, limit }, - options, - ); - - return res.data; - }); - } - - /** - * Get a list of posts liked by an actor. Requires auth, actor must be the requesting account. - */ - likes(limit?: number, options?: AppBskyFeedGetActorLikes.CallOptions) { - return new Paginator(async (cursor) => { - const res = await this.instance.feed.getActorLikes( - { cursor, actor: this.actor, limit }, - options, - ); - - return res.data; - }); - } - - /** - * Get a list of feeds (feed generator records) created by the actor (in the actor's repo). - */ - feed( - params: AppBskyFeedGetAuthorFeed.QueryParams, - options?: AppBskyFeedGetAuthorFeed.CallOptions, - ) { - return new Paginator(async (cursor) => { - const res = await this.instance.feed.getActorFeeds( - { cursor, ...params, actor: this.actor }, - options, - ); - - return res.data; - }); - } - - thread(thread: string) { - return new Thread(this.instance, thread); - } -} - -class Thread { - constructor( - private instance: AppBskyNS, - private thread: string, - ) {} - - /** - * Mutes a thread preventing notifications from the thread and any of its children. Mutes are private in Bluesky. Requires auth. - */ - mute(options?: AppBskyGraphMuteThread.CallOptions) { - return this.instance.graph.muteThread({ root: this.thread }, options); - } - - /** - * Unmutes the specified thread. Requires auth. - */ - unmute(options?: AppBskyGraphUnmuteThread.CallOptions) { - return this.instance.graph.unmuteThread({ root: this.thread }, options); - } -} - -export class Actor extends BaseActor { - /** - * Creates a mute relationship for the specified account. Mutes are private in Bluesky. Requires auth. - */ - mute(options?: AppBskyGraphMuteActor.CallOptions) { - return this.instance.graph.muteActor({ actor: this.actor }, options); - } - - /** - * Unmutes the specified account. Requires auth. - */ - unmute(options?: AppBskyGraphUnmuteActor.CallOptions) { - return this.instance.graph.unmuteActor({ actor: this.actor }, options); - } - - /** - * Creates a mute relationship for the specified list of accounts. Mutes are private in Bluesky. Requires auth. - */ - static muteMany( - instance: AppBskyNS, - actors: string[], - options?: AppBskyGraphMuteActorList.CallOptions, - ) { - // FIXME: Shouldn't this take an array? - return instance.graph.muteActorList({ list: actors[0] }, options); - } - - /** - * Unmutes the specified list of accounts. Requires auth. - */ - static unmuteMany( - instance: AppBskyNS, - actors: string[], - options?: AppBskyGraphUnmuteActorList.CallOptions, - ) { - // FIXME: Shouldn't this take an array? - return instance.graph.unmuteActorList({ list: actors[0] }, options); - } -} - -export class User extends BaseActor { - /** - * Enumerates accounts which follow a specified account (actor) and are followed by the viewer. - */ - knowFollowers( - params: { actor: string; limit?: number }, - options?: AppBskyGraphGetKnownFollowers.CallOptions, - ) { - return new Paginator(async (cursor) => { - const res = await this.instance.graph.getKnownFollowers( - { - cursor, - ...params, - }, - options, - ); - - return res.data; - }); - } - - /** - * Get mod lists that the requesting account (actor) is blocking. Requires auth. - */ - blockedLists( - limit?: number, - options?: AppBskyGraphGetListBlocks.CallOptions, - ) { - return new Paginator(async (cursor) => { - const res = await this.instance.graph.getListBlocks( - { - cursor, - limit, - }, - options, - ); - - return res.data; - }); - } - - /** - * Enumerates mod lists that the requesting account (actor) currently has muted. Requires auth. - */ - mutedLists(limit?: number, options?: AppBskyGraphGetListMutes.CallOptions) { - return new Paginator(async (cursor) => { - const res = await this.instance.graph.getListMutes( - { - cursor, - limit, - }, - options, - ); - - return res.data; - }); - } - - /** - * Enumerates accounts that the requesting account (actor) currently has muted. Requires auth. - */ - mutedProfiles(limit?: number, options?: AppBskyGraphGetMutes.CallOptions) { - return new Paginator(async (cursor) => { - const res = await this.instance.graph.getMutes( - { - cursor, - limit, - }, - options, - ); - - return res.data; - }); - } - - suggestions() { - return new Suggestions(this.instance); - } - - preferences() { - return new Preferences(this.instance); - } -} - -class Suggestions { - constructor(private instance: AppBskyNS) {} - - /** - * Get a list of suggested actors. Expected use is discovery of accounts to follow during new account onboarding. - */ - follow(limit?: number) { - return new Paginator(async (cursor) => { - const res = await this.instance.actor.getSuggestions({ - cursor, - limit, - }); - - return res.data; - }); - } - - /** - * Enumerates follows similar to a given account (actor). Expected use is to recommend additional accounts immediately after following one account. - */ - afterFollowing( - actor: string, - options?: AppBskyGraphGetSuggestedFollowsByActor.CallOptions, - ) { - return this.instance.graph.getSuggestedFollowsByActor( - { - actor, - }, - options, - ); - } - - /** - * Get a list of suggested feeds (feed generators) for the requesting account. - */ - feeds(limit?: number, options?: AppBskyFeedGetSuggestedFeeds.CallOptions) { - return new Paginator(async (cursor) => { - const res = await this.instance.feed.getSuggestedFeeds( - { cursor, limit }, - options, - ); - - return res.data; - }); - } -} diff --git a/packages/core/src/bsky/Actor.ts b/packages/core/src/bsky/Actor.ts new file mode 100644 index 0000000..4498b27 --- /dev/null +++ b/packages/core/src/bsky/Actor.ts @@ -0,0 +1,42 @@ +import { AppBskyGraphMuteActor, AppBskyGraphMuteActorList, AppBskyGraphUnmuteActor, AppBskyGraphUnmuteActorList, AppBskyNS } from "@atproto/api"; +import { BaseActor } from "./BaseActor"; + +export class Actor extends BaseActor { + /** + * Creates a mute relationship for the specified account. Mutes are private in Bluesky. Requires auth. + */ + mute(options?: AppBskyGraphMuteActor.CallOptions) { + return this.instance.graph.muteActor({ actor: this.actor }, options); + } + + /** + * Unmutes the specified account. Requires auth. + */ + unmute(options?: AppBskyGraphUnmuteActor.CallOptions) { + return this.instance.graph.unmuteActor({ actor: this.actor }, options); + } + + /** + * Creates a mute relationship for the specified list of accounts. Mutes are private in Bluesky. Requires auth. + */ + static muteMany( + instance: AppBskyNS, + actors: string[], + options?: AppBskyGraphMuteActorList.CallOptions, + ) { + // FIXME: Shouldn't this take an array? + return instance.graph.muteActorList({ list: actors[0] }, options); + } + + /** + * Unmutes the specified list of accounts. Requires auth. + */ + static unmuteMany( + instance: AppBskyNS, + actors: string[], + options?: AppBskyGraphUnmuteActorList.CallOptions, + ) { + // FIXME: Shouldn't this take an array? + return instance.graph.unmuteActorList({ list: actors[0] }, options); + } +} \ No newline at end of file diff --git a/packages/core/src/bsky/BaseActor.ts b/packages/core/src/bsky/BaseActor.ts new file mode 100644 index 0000000..a243a39 --- /dev/null +++ b/packages/core/src/bsky/BaseActor.ts @@ -0,0 +1,137 @@ +import { AppBskyFeedGetActorFeeds, AppBskyFeedGetActorLikes, AppBskyFeedGetAuthorFeed, AppBskyGraphGetRelationships, AppBskyNS } from "@atproto/api"; +import { Paginator } from "~/tsky/paginate"; +import { Thread } from "./Thread"; + +export class BaseActor { + constructor( + readonly instance: AppBskyNS, + readonly actor: string, + ) {} + + /** + * Get a list of starter packs created by the actor. + */ + starterPacks(limit?: number) { + return new Paginator(async (cursor) => { + const res = await this.instance.graph.getActorStarterPacks({ + cursor, + actor: this.actor, + limit, + }); + + return res.data; + }); + } + + /** + * Enumerates accounts which follow a specified account (actor). + */ + followers(limit?: number) { + return new Paginator(async (cursor) => { + const res = await this.instance.graph.getFollowers({ + cursor, + actor: this.actor, + limit, + }); + + return res.data; + }); + } + + /** + * Enumerates accounts which a specified account (actor) follows. + */ + follows(limit?: number) { + return new Paginator(async (cursor) => { + const res = await this.instance.graph.getFollows({ + cursor, + actor: this.actor, + limit, + }); + + return res.data; + }); + } + + /** + * Enumerates the lists created by a specified account (actor). + */ + lists(limit?: number) { + return new Paginator(async (cursor) => { + const res = await this.instance.graph.getLists({ + cursor, + actor: this.actor, + limit, + }); + + return res.data; + }); + } + + /** + * Enumerates public relationships between one account, and a list of other accounts. Does not require auth. + */ + async relationships( + others?: string[], + options?: AppBskyGraphGetRelationships.CallOptions, + ) { + const res = await this.instance.graph.getRelationships( + { + actor: this.actor, + others, + }, + options, + ); + + return res.data; + } + + /** + * Get a view of an actor's 'author feed' (post and reposts by the author). Does not require auth. + */ + feeds(limit?: number, options?: AppBskyFeedGetActorFeeds.CallOptions) { + return new Paginator(async (cursor) => { + const res = await this.instance.feed.getActorFeeds( + { cursor, actor: this.actor, limit }, + options, + ); + + return res.data; + }); + } + + /** + * Get a list of posts liked by an actor. Requires auth, actor must be the requesting account. + */ + likes(limit?: number, options?: AppBskyFeedGetActorLikes.CallOptions) { + return new Paginator(async (cursor) => { + const res = await this.instance.feed.getActorLikes( + { cursor, actor: this.actor, limit }, + options, + ); + + return res.data; + }); + } + + /** + * Get a list of feeds (feed generator records) created by the actor (in the actor's repo). + */ + feed( + params: AppBskyFeedGetAuthorFeed.QueryParams, + options?: AppBskyFeedGetAuthorFeed.CallOptions, + ) { + return new Paginator(async (cursor) => { + const res = await this.instance.feed.getActorFeeds( + { cursor, ...params, actor: this.actor }, + options, + ); + + return res.data; + }); + } + + thread(thread: string) { + return new Thread(this.instance, thread); + } +} \ No newline at end of file diff --git a/packages/core/src/feed.ts b/packages/core/src/bsky/Feed.ts similarity index 95% rename from packages/core/src/feed.ts rename to packages/core/src/bsky/Feed.ts index 0b38ab6..75a2a4f 100644 --- a/packages/core/src/feed.ts +++ b/packages/core/src/bsky/Feed.ts @@ -8,7 +8,7 @@ import type { AppBskyFeedSendInteractions, AppBskyNS, } from '@atproto/api'; -import { Paginator } from './paginate'; +import { Paginator } from '~/tsky/paginate'; export class Feed { constructor(private instance: AppBskyNS) {} diff --git a/packages/core/src/list.ts b/packages/core/src/bsky/List.ts similarity index 91% rename from packages/core/src/list.ts rename to packages/core/src/bsky/List.ts index ce0db37..b7e4a00 100644 --- a/packages/core/src/list.ts +++ b/packages/core/src/bsky/List.ts @@ -3,7 +3,7 @@ import type { AppBskyGraphGetList, AppBskyNS, } from '@atproto/api'; -import { Paginator } from './paginate'; +import { Paginator } from '~/tsky/paginate'; export class BskyList { constructor( diff --git a/packages/core/src/post.ts b/packages/core/src/bsky/Post.ts similarity index 94% rename from packages/core/src/post.ts rename to packages/core/src/bsky/Post.ts index ac510c9..57a8132 100644 --- a/packages/core/src/post.ts +++ b/packages/core/src/bsky/Post.ts @@ -7,7 +7,7 @@ import type { AppBskyFeedSearchPosts, AppBskyNS, } from '@atproto/api' -import { Paginator } from './paginate' +import { Paginator } from '~/tsky/paginate' export class Post { constructor(private instance: AppBskyNS) {} diff --git a/packages/core/src/preference.ts b/packages/core/src/bsky/Preferences.ts similarity index 100% rename from packages/core/src/preference.ts rename to packages/core/src/bsky/Preferences.ts diff --git a/packages/core/src/starterPack.ts b/packages/core/src/bsky/StarterPack.ts similarity index 91% rename from packages/core/src/starterPack.ts rename to packages/core/src/bsky/StarterPack.ts index 8b8b10d..912dc6c 100644 --- a/packages/core/src/starterPack.ts +++ b/packages/core/src/bsky/StarterPack.ts @@ -4,7 +4,7 @@ import type { AppBskyGraphSearchStarterPacks, AppBskyNS, } from '@atproto/api'; -import { Paginator } from './paginate'; +import { Paginator } from '~/tsky/paginate'; export class StarterPack { constructor( diff --git a/packages/core/src/bsky/Suggestions.ts b/packages/core/src/bsky/Suggestions.ts new file mode 100644 index 0000000..e1123a9 --- /dev/null +++ b/packages/core/src/bsky/Suggestions.ts @@ -0,0 +1,49 @@ +import { AppBskyFeedGetSuggestedFeeds, AppBskyGraphGetSuggestedFollowsByActor, AppBskyNS } from "@atproto/api"; +import { Paginator } from "~/tsky/paginate"; + +export class Suggestions { + constructor(private instance: AppBskyNS) {} + + /** + * Get a list of suggested actors. Expected use is discovery of accounts to follow during new account onboarding. + */ + follow(limit?: number) { + return new Paginator(async (cursor) => { + const res = await this.instance.actor.getSuggestions({ + cursor, + limit, + }); + + return res.data; + }); + } + + /** + * Enumerates follows similar to a given account (actor). Expected use is to recommend additional accounts immediately after following one account. + */ + afterFollowing( + actor: string, + options?: AppBskyGraphGetSuggestedFollowsByActor.CallOptions, + ) { + return this.instance.graph.getSuggestedFollowsByActor( + { + actor, + }, + options, + ); + } + + /** + * Get a list of suggested feeds (feed generators) for the requesting account. + */ + feeds(limit?: number, options?: AppBskyFeedGetSuggestedFeeds.CallOptions) { + return new Paginator(async (cursor) => { + const res = await this.instance.feed.getSuggestedFeeds( + { cursor, limit }, + options, + ); + + return res.data; + }); + } +} \ No newline at end of file diff --git a/packages/core/src/bsky/Thread.ts b/packages/core/src/bsky/Thread.ts new file mode 100644 index 0000000..dd0afc9 --- /dev/null +++ b/packages/core/src/bsky/Thread.ts @@ -0,0 +1,22 @@ +import { AppBskyGraphMuteThread, AppBskyGraphUnmuteThread, AppBskyNS } from "@atproto/api"; + +export class Thread { + constructor( + private instance: AppBskyNS, + private thread: string, + ) {} + + /** + * Mutes a thread preventing notifications from the thread and any of its children. Mutes are private in Bluesky. Requires auth. + */ + mute(options?: AppBskyGraphMuteThread.CallOptions) { + return this.instance.graph.muteThread({ root: this.thread }, options); + } + + /** + * Unmutes the specified thread. Requires auth. + */ + unmute(options?: AppBskyGraphUnmuteThread.CallOptions) { + return this.instance.graph.unmuteThread({ root: this.thread }, options); + } +} \ No newline at end of file diff --git a/packages/core/src/bsky/User.ts b/packages/core/src/bsky/User.ts new file mode 100644 index 0000000..c2add35 --- /dev/null +++ b/packages/core/src/bsky/User.ts @@ -0,0 +1,89 @@ +import { AppBskyGraphGetKnownFollowers, AppBskyGraphGetListBlocks, AppBskyGraphGetListMutes, AppBskyGraphGetMutes } from "@atproto/api"; +import { BaseActor } from "./BaseActor"; +import { Paginator } from "~/tsky/paginate"; +import { Suggestions } from "./Suggestions"; +import { Preferences } from "./Preferences"; + +export class User extends BaseActor { + /** + * Enumerates accounts which follow a specified account (actor) and are followed by the viewer. + */ + knowFollowers( + params: { actor: string; limit?: number }, + options?: AppBskyGraphGetKnownFollowers.CallOptions, + ) { + return new Paginator(async (cursor) => { + const res = await this.instance.graph.getKnownFollowers( + { + cursor, + ...params, + }, + options, + ); + + return res.data; + }); + } + + /** + * Get mod lists that the requesting account (actor) is blocking. Requires auth. + */ + blockedLists( + limit?: number, + options?: AppBskyGraphGetListBlocks.CallOptions, + ) { + return new Paginator(async (cursor) => { + const res = await this.instance.graph.getListBlocks( + { + cursor, + limit, + }, + options, + ); + + return res.data; + }); + } + + /** + * Enumerates mod lists that the requesting account (actor) currently has muted. Requires auth. + */ + mutedLists(limit?: number, options?: AppBskyGraphGetListMutes.CallOptions) { + return new Paginator(async (cursor) => { + const res = await this.instance.graph.getListMutes( + { + cursor, + limit, + }, + options, + ); + + return res.data; + }); + } + + /** + * Enumerates accounts that the requesting account (actor) currently has muted. Requires auth. + */ + mutedProfiles(limit?: number, options?: AppBskyGraphGetMutes.CallOptions) { + return new Paginator(async (cursor) => { + const res = await this.instance.graph.getMutes( + { + cursor, + limit, + }, + options, + ); + + return res.data; + }); + } + + suggestions() { + return new Suggestions(this.instance); + } + + preferences() { + return new Preferences(this.instance); + } +} \ No newline at end of file diff --git a/packages/core/src/video.ts b/packages/core/src/bsky/Video.ts similarity index 100% rename from packages/core/src/video.ts rename to packages/core/src/bsky/Video.ts diff --git a/packages/core/src/bsky/index.ts b/packages/core/src/bsky/index.ts new file mode 100644 index 0000000..9a6d717 --- /dev/null +++ b/packages/core/src/bsky/index.ts @@ -0,0 +1,11 @@ +export * from './Actor' +export * from './BaseActor' +export * from './User' +export * from './Suggestions' +export * from './Thread' +export * from './Feed' +export * from './List' +export * from './Post' +export * from './Preferences' +export * from './StarterPack' +export * from './Video' \ No newline at end of file diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 4c6e95c..e547d07 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,11 +1,4 @@ -export * from './actor' -export * from './feed' -export * from './list' -export * from './paginate' -export * from './post' -export * from './preference' -export * from './starterPack' +export * from './bsky' export * from './tsky' -export * from './video' export { TSky as default } from './tsky' \ No newline at end of file diff --git a/packages/core/src/tsky/index.ts b/packages/core/src/tsky/index.ts new file mode 100644 index 0000000..c461a4c --- /dev/null +++ b/packages/core/src/tsky/index.ts @@ -0,0 +1,2 @@ +export * from './paginate' +export * from './tsky' \ No newline at end of file diff --git a/packages/core/src/paginate.ts b/packages/core/src/tsky/paginate.ts similarity index 100% rename from packages/core/src/paginate.ts rename to packages/core/src/tsky/paginate.ts diff --git a/packages/core/src/tsky.ts b/packages/core/src/tsky/tsky.ts similarity index 100% rename from packages/core/src/tsky.ts rename to packages/core/src/tsky/tsky.ts diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json new file mode 100644 index 0000000..a19de9d --- /dev/null +++ b/packages/core/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "~/*": ["src/*"] + } + } +} \ No newline at end of file From 2391220f20058555c47379ac7174cbfee76824ae Mon Sep 17 00:00:00 2001 From: Dominik Biedebach Date: Sat, 30 Nov 2024 08:07:19 +0100 Subject: [PATCH 3/3] refactor: adjust tsky file names to align with class names --- packages/core/src/bsky/BaseActor.ts | 2 +- packages/core/src/bsky/Feed.ts | 2 +- packages/core/src/bsky/List.ts | 2 +- packages/core/src/bsky/Post.ts | 2 +- packages/core/src/bsky/StarterPack.ts | 2 +- packages/core/src/bsky/Suggestions.ts | 2 +- packages/core/src/bsky/User.ts | 2 +- packages/core/src/tsky/{paginate.ts => Paginator.ts} | 0 packages/core/src/tsky/{tsky.ts => TSky.ts} | 2 +- packages/core/src/tsky/index.ts | 4 ++-- 10 files changed, 10 insertions(+), 10 deletions(-) rename packages/core/src/tsky/{paginate.ts => Paginator.ts} (100%) rename packages/core/src/tsky/{tsky.ts => TSky.ts} (98%) diff --git a/packages/core/src/bsky/BaseActor.ts b/packages/core/src/bsky/BaseActor.ts index a243a39..dad78ab 100644 --- a/packages/core/src/bsky/BaseActor.ts +++ b/packages/core/src/bsky/BaseActor.ts @@ -1,5 +1,5 @@ import { AppBskyFeedGetActorFeeds, AppBskyFeedGetActorLikes, AppBskyFeedGetAuthorFeed, AppBskyGraphGetRelationships, AppBskyNS } from "@atproto/api"; -import { Paginator } from "~/tsky/paginate"; +import { Paginator } from "~/tsky/Paginator"; import { Thread } from "./Thread"; export class BaseActor { diff --git a/packages/core/src/bsky/Feed.ts b/packages/core/src/bsky/Feed.ts index 75a2a4f..8a16766 100644 --- a/packages/core/src/bsky/Feed.ts +++ b/packages/core/src/bsky/Feed.ts @@ -8,7 +8,7 @@ import type { AppBskyFeedSendInteractions, AppBskyNS, } from '@atproto/api'; -import { Paginator } from '~/tsky/paginate'; +import { Paginator } from '~/tsky/Paginator'; export class Feed { constructor(private instance: AppBskyNS) {} diff --git a/packages/core/src/bsky/List.ts b/packages/core/src/bsky/List.ts index b7e4a00..3f60bec 100644 --- a/packages/core/src/bsky/List.ts +++ b/packages/core/src/bsky/List.ts @@ -3,7 +3,7 @@ import type { AppBskyGraphGetList, AppBskyNS, } from '@atproto/api'; -import { Paginator } from '~/tsky/paginate'; +import { Paginator } from '~/tsky/Paginator'; export class BskyList { constructor( diff --git a/packages/core/src/bsky/Post.ts b/packages/core/src/bsky/Post.ts index 57a8132..dc3bbb4 100644 --- a/packages/core/src/bsky/Post.ts +++ b/packages/core/src/bsky/Post.ts @@ -7,7 +7,7 @@ import type { AppBskyFeedSearchPosts, AppBskyNS, } from '@atproto/api' -import { Paginator } from '~/tsky/paginate' +import { Paginator } from '~/tsky/Paginator' export class Post { constructor(private instance: AppBskyNS) {} diff --git a/packages/core/src/bsky/StarterPack.ts b/packages/core/src/bsky/StarterPack.ts index 912dc6c..2bfa10f 100644 --- a/packages/core/src/bsky/StarterPack.ts +++ b/packages/core/src/bsky/StarterPack.ts @@ -4,7 +4,7 @@ import type { AppBskyGraphSearchStarterPacks, AppBskyNS, } from '@atproto/api'; -import { Paginator } from '~/tsky/paginate'; +import { Paginator } from '~/tsky/Paginator'; export class StarterPack { constructor( diff --git a/packages/core/src/bsky/Suggestions.ts b/packages/core/src/bsky/Suggestions.ts index e1123a9..b7b2b68 100644 --- a/packages/core/src/bsky/Suggestions.ts +++ b/packages/core/src/bsky/Suggestions.ts @@ -1,5 +1,5 @@ import { AppBskyFeedGetSuggestedFeeds, AppBskyGraphGetSuggestedFollowsByActor, AppBskyNS } from "@atproto/api"; -import { Paginator } from "~/tsky/paginate"; +import { Paginator } from "~/tsky/Paginator"; export class Suggestions { constructor(private instance: AppBskyNS) {} diff --git a/packages/core/src/bsky/User.ts b/packages/core/src/bsky/User.ts index c2add35..3cba623 100644 --- a/packages/core/src/bsky/User.ts +++ b/packages/core/src/bsky/User.ts @@ -1,6 +1,6 @@ import { AppBskyGraphGetKnownFollowers, AppBskyGraphGetListBlocks, AppBskyGraphGetListMutes, AppBskyGraphGetMutes } from "@atproto/api"; import { BaseActor } from "./BaseActor"; -import { Paginator } from "~/tsky/paginate"; +import { Paginator } from "~/tsky/Paginator"; import { Suggestions } from "./Suggestions"; import { Preferences } from "./Preferences"; diff --git a/packages/core/src/tsky/paginate.ts b/packages/core/src/tsky/Paginator.ts similarity index 100% rename from packages/core/src/tsky/paginate.ts rename to packages/core/src/tsky/Paginator.ts diff --git a/packages/core/src/tsky/tsky.ts b/packages/core/src/tsky/TSky.ts similarity index 98% rename from packages/core/src/tsky/tsky.ts rename to packages/core/src/tsky/TSky.ts index 6dcf121..96a9419 100644 --- a/packages/core/src/tsky/tsky.ts +++ b/packages/core/src/tsky/TSky.ts @@ -6,7 +6,7 @@ import type { AppBskyActorSearchActorsTypeahead, AppBskyNS, } from '@atproto/api'; -import { Paginator } from './paginate'; +import { Paginator } from './Paginator'; export class TSky { constructor(private instance: AppBskyNS) {} diff --git a/packages/core/src/tsky/index.ts b/packages/core/src/tsky/index.ts index c461a4c..e304ab9 100644 --- a/packages/core/src/tsky/index.ts +++ b/packages/core/src/tsky/index.ts @@ -1,2 +1,2 @@ -export * from './paginate' -export * from './tsky' \ No newline at end of file +export * from './Paginator' +export * from './TSky' \ No newline at end of file