Skip to content

Commit

Permalink
chore: Remove internal lift util
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Nov 13, 2022
1 parent fb20092 commit 869361e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
11 changes: 5 additions & 6 deletions examples/timeline-with-iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ const main = async () => {
url: 'https://example.com',
});

// You can fetch each page of timeline with `.next()`
const result = await masto.timelines.public.next();
const result = await masto.timelines.fetchPublic({
limit: 30,
});

if (result) {
// `.done` represents whether there are more pages
console.log(result.done);
// `.value` contains response object
console.log(result.value);
// More about iterators:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
}

// You can also use `for-await-of` syntax to page down the timeline
for await (const statuses of masto.timelines.public) {
// You can also use `for-await-of` syntax to iterate over the timeline
for await (const statuses of masto.timelines.getPublicIterable()) {
statuses.forEach((status) => {
masto.statuses.favourite(status.id);
});
Expand Down
22 changes: 18 additions & 4 deletions src/repositories/account-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
} from '../entities';
import { Http } from '../http';
import { Paginator } from '../paginator';
import { lift } from '../utils/lift';
import { DefaultPaginationParams, Repository } from './repository';

export interface CreateAccountParams {
Expand Down Expand Up @@ -185,7 +184,12 @@ export class AccountRepository
* @return Array of Account
* @see https://docs.joinmastodon.org/methods/accounts/
*/
fetchFollowers = lift(this.getFollowersIterable.bind(this));
fetchFollowers(
id: string,
params: DefaultPaginationParams = {},
): Promise<IteratorResult<Account[]>> {
return this.getFollowersIterable(id, params).next();
}

/**
* Accounts which the given account is following, if network is not hidden by the account owner.
Expand All @@ -194,7 +198,12 @@ export class AccountRepository
* @return Array of Account
* @see https://docs.joinmastodon.org/methods/accounts/
*/
fetchFollowing = lift(this.getFollowersIterable.bind(this));
fetchFollowing(
id: string,
params: DefaultPaginationParams = {},
): Promise<IteratorResult<Account[]>> {
return this.getFollowersIterable(id, params).next();
}

/**
* Statuses posted to the given account.
Expand All @@ -203,7 +212,12 @@ export class AccountRepository
* @return Array of Status
* @see https://docs.joinmastodon.org/methods/accounts/
*/
fetchStatuses = lift(this.getStatusesIterable.bind(this));
fetchStatuses(
id: string,
params: DefaultPaginationParams = {},
): Promise<IteratorResult<Status[]>> {
return this.getStatusesIterable(id, params).next();
}

/**
* Follow the given account.
Expand Down
5 changes: 3 additions & 2 deletions src/repositories/iterable-repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { lift } from '../utils/lift';
import { DefaultPaginationParams, Repository } from './repository';

export abstract class IterableRepository<
Expand All @@ -11,7 +10,9 @@ export abstract class IterableRepository<
{
abstract getIterator(params?: RMany): AsyncIterableIterator<T[]>;

fetchMany = lift(this.getIterator.bind(this));
fetchMany(params?: RMany): Promise<IteratorResult<T[]>> {
return this.getIterator(params).next();
}

async *[Symbol.asyncIterator]() {
if (this.getIterator != null) {
Expand Down
5 changes: 4 additions & 1 deletion src/repositories/list-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export class ListRepository
* @return Array of Account
* @see https://docs.joinmastodon.org/methods/timelines/lists/
*/
fetchAccounts(id: string, params?: DefaultPaginationParams) {
fetchAccounts(
id: string,
params?: DefaultPaginationParams,
): Promise<IteratorResult<Account[]>> {
return this.getAccountIterator(id, params).next();
}

Expand Down
19 changes: 0 additions & 19 deletions src/utils/lift.ts

This file was deleted.

0 comments on commit 869361e

Please sign in to comment.