diff --git a/packages/core/src/actor.ts b/packages/core/src/actor.ts deleted file mode 100644 index 5c29f56..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. - */ - knownFollowers( - 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..ecad643 --- /dev/null +++ b/packages/core/src/bsky/Actor.ts @@ -0,0 +1,48 @@ +import type { + 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); + } +} diff --git a/packages/core/src/bsky/BaseActor.ts b/packages/core/src/bsky/BaseActor.ts new file mode 100644 index 0000000..1501d63 --- /dev/null +++ b/packages/core/src/bsky/BaseActor.ts @@ -0,0 +1,143 @@ +import type { + AppBskyFeedGetActorFeeds, + AppBskyFeedGetActorLikes, + AppBskyFeedGetAuthorFeed, + AppBskyGraphGetRelationships, + AppBskyNS, +} from '@atproto/api'; +import { Paginator } from '~/tsky/Paginator'; +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); + } +} 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..8a16766 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/Paginator'; 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..3f60bec 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/Paginator'; 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 bbbd66c..ee7ca1d 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/Paginator'; 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..2bfa10f 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/Paginator'; 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..c9c4921 --- /dev/null +++ b/packages/core/src/bsky/Suggestions.ts @@ -0,0 +1,53 @@ +import type { + AppBskyFeedGetSuggestedFeeds, + AppBskyGraphGetSuggestedFollowsByActor, + AppBskyNS, +} from '@atproto/api'; +import { Paginator } from '~/tsky/Paginator'; + +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; + }); + } +} diff --git a/packages/core/src/bsky/Thread.ts b/packages/core/src/bsky/Thread.ts new file mode 100644 index 0000000..2c42c23 --- /dev/null +++ b/packages/core/src/bsky/Thread.ts @@ -0,0 +1,26 @@ +import type { + 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); + } +} diff --git a/packages/core/src/bsky/User.ts b/packages/core/src/bsky/User.ts new file mode 100644 index 0000000..05b0686 --- /dev/null +++ b/packages/core/src/bsky/User.ts @@ -0,0 +1,94 @@ +import type { + AppBskyGraphGetKnownFollowers, + AppBskyGraphGetListBlocks, + AppBskyGraphGetListMutes, + AppBskyGraphGetMutes, +} from '@atproto/api'; +import { Paginator } from '~/tsky/Paginator'; +import { BaseActor } from './BaseActor'; +import { Preferences } from './Preferences'; +import { Suggestions } from './Suggestions'; + +export class User extends BaseActor { + /** + * Enumerates accounts which follow a specified account (actor) and are followed by the viewer. + */ + knownFollowers( + 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); + } +} 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..b26cf91 --- /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'; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 4fb83e4..f8ce004 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,86 +1,4 @@ -import type { - AppBskyActorDefs, - AppBskyActorGetProfile, - AppBskyActorGetProfiles, - AppBskyActorSearchActors, - AppBskyActorSearchActorsTypeahead, - AppBskyNS, -} from '@atproto/api'; -import { Paginator } from './paginate'; +export * from './bsky'; +export * from './tsky'; -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 { TSky as default } from './tsky'; diff --git a/packages/core/src/paginate.ts b/packages/core/src/tsky/Paginator.ts similarity index 100% rename from packages/core/src/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 new file mode 100644 index 0000000..22faaad --- /dev/null +++ b/packages/core/src/tsky/TSky.ts @@ -0,0 +1,86 @@ +import type { + AppBskyActorDefs, + AppBskyActorGetProfile, + AppBskyActorGetProfiles, + AppBskyActorSearchActors, + AppBskyActorSearchActorsTypeahead, + AppBskyNS, +} from '@atproto/api'; +import { Paginator } from './Paginator'; + +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; + }); + } +} diff --git a/packages/core/src/tsky/index.ts b/packages/core/src/tsky/index.ts new file mode 100644 index 0000000..41bddaa --- /dev/null +++ b/packages/core/src/tsky/index.ts @@ -0,0 +1,2 @@ +export * from './Paginator'; +export * from './TSky'; diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json new file mode 100644 index 0000000..ba26124 --- /dev/null +++ b/packages/core/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "~/*": ["src/*"] + } + } +}