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

chore: refactor twitter-types, add vitest config, and bump deps #122

Merged
merged 1 commit into from
Jan 7, 2022
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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
versioning-strategy: increase
open-pull-requests-limit: 10
1,056 changes: 565 additions & 491 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@
"prepublishOnly": "npm run build && npm run zx"
},
"dependencies": {
"@discordjs/collection": "^0.3.2",
"@discordjs/collection": "^0.4.0",
"@sapphire/async-queue": "^1.1.9",
"oauth-1.0a": "^2.2.6",
"twitter-types": "^0.20.0",
"undici": "^4.12.1"
},
"devDependencies": {
"@commitlint/cli": "^15.0.0",
"@commitlint/config-angular": "^15.0.0",
"@types/node": "^16.11.12",
"@typescript-eslint/eslint-plugin": "^5.6.0",
"@typescript-eslint/parser": "^5.6.0",
"eslint": "^8.4.1",
"@commitlint/cli": "^16.0.1",
"@commitlint/config-angular": "^16.0.0",
"@types/node": "^17.0.8",
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@typescript-eslint/parser": "^5.9.0",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"lint-staged": "^12.1.2",
"lint-staged": "^12.1.6",
"prettier": "^2.5.1",
"twitter-types": "^0.19.1",
"typedoc": "^0.22.10",
"typescript": "^4.5.4",
"vitest": "^0.0.124",
"vitest": "^0.0.136",
"zx": "^4.2.0"
},
"files": [
Expand Down
6 changes: 3 additions & 3 deletions src/books/BlocksBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RequestData } from '../structures';
import type { Client } from '../client';
import type { User } from '../structures';
import type { BlocksBookOptions } from '../typings';
import type { GET_2_users_id_blocking_Query, GET_2_users_id_blocking_Response, Snowflake } from 'twitter-types';
import type { GETUsersIdBlockingQuery, GETUsersIdBlockingResponse, Snowflake } from 'twitter-types';

/**
* A class for fetching users blocked by the authorized user
Expand Down Expand Up @@ -85,15 +85,15 @@ export class BlocksBook extends BaseBook {
async #fetchPages(token?: string): Promise<Collection<Snowflake, User>> {
const blockedUsersCollection = new Collection<Snowflake, User>();
const queryParameters = this.client.options.queryParameters;
const query: GET_2_users_id_blocking_Query = {
const query: GETUsersIdBlockingQuery = {
expansions: queryParameters?.userExpansions,
'tweet.fields': queryParameters?.tweetFields,
'user.fields': queryParameters?.userFields,
pagination_token: token,
};
if (this.maxResultsPerPage) query.max_results = this.maxResultsPerPage;
const requestData = new RequestData({ query, isUserContext: true });
const data: GET_2_users_id_blocking_Response = await this.client._api.users(this.userId).blocking.get(requestData);
const data: GETUsersIdBlockingResponse = await this.client._api.users(this.userId).blocking.get(requestData);
this.#nextToken = data.meta.next_token;
this.#previousToken = data.meta.previous_token;
this.hasMore = data.meta.next_token ? true : false;
Expand Down
8 changes: 4 additions & 4 deletions src/books/ComposedTweetsBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RequestData } from '../structures';
import type { Client } from '../client';
import type { Tweet } from '../structures';
import type { ComposedTweetsBookOptions } from '../typings';
import type { GET_2_users_id_tweets_Query, GET_2_users_id_tweets_Response, Snowflake } from 'twitter-types';
import type { GETUsersIdTweetsQuery, GETUsersIdTweetsResponse, Snowflake } from 'twitter-types';

/**
* A class for fetching tweets composed by a twitter user
Expand Down Expand Up @@ -70,7 +70,7 @@ export class ComposedTweetsBook extends BaseBook {
/**
* The types of tweets that the book should not fetch
*/
exclude: GET_2_users_id_tweets_Query['exclude'] | null;
exclude: GETUsersIdTweetsQuery['exclude'] | null;

/**
* @param client The logged in {@link Client} instance
Expand Down Expand Up @@ -115,7 +115,7 @@ export class ComposedTweetsBook extends BaseBook {
async #fetchPages(token?: string): Promise<Collection<Snowflake, Tweet>> {
const tweetsCollection = new Collection<Snowflake, Tweet>();
const queryParameters = this.client.options.queryParameters;
const query: GET_2_users_id_tweets_Query = {
const query: GETUsersIdTweetsQuery = {
expansions: queryParameters?.tweetExpansions,
'media.fields': queryParameters?.mediaFields,
'place.fields': queryParameters?.placeFields,
Expand All @@ -131,7 +131,7 @@ export class ComposedTweetsBook extends BaseBook {
if (this.afterTimestamp) query.start_time = new Date(this.afterTimestamp).toISOString();
if (this.beforeTimestamp) query.end_time = new Date(this.beforeTimestamp).toISOString();
const requestData = new RequestData({ query });
const data: GET_2_users_id_tweets_Response = await this.client._api.users(this.userId).tweets.get(requestData);
const data: GETUsersIdTweetsResponse = await this.client._api.users(this.userId).tweets.get(requestData);
this.#nextToken = data.meta.next_token;
this.#previousToken = data.meta.previous_token;
this.hasMore = data.meta.next_token ? true : false;
Expand Down
8 changes: 3 additions & 5 deletions src/books/FollowersBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RequestData } from '../structures';
import type { Client } from '../client';
import type { User } from '../structures';
import type { FollowersBookOptions } from '../typings';
import type { GET_2_users_id_followers_Query, GET_2_users_id_followers_Response, Snowflake } from 'twitter-types';
import type { GETUsersIdFollowersQuery, GETUsersIdFollowersResponse, Snowflake } from 'twitter-types';

/**
* A class for fetching followers of a twitter user
Expand Down Expand Up @@ -86,17 +86,15 @@ export class FollowersBook extends BaseBook {
async #fetchPages(token?: string): Promise<Collection<Snowflake, User>> {
const followersCollection = new Collection<Snowflake, User>();
const queryParameters = this.client.options.queryParameters;
const query: GET_2_users_id_followers_Query = {
const query: GETUsersIdFollowersQuery = {
expansions: queryParameters?.userExpansions,
'tweet.fields': queryParameters?.tweetFields,
'user.fields': queryParameters?.userFields,
pagination_token: token,
};
if (this.maxResultsPerPage) query.max_results = this.maxResultsPerPage;
const requestData = new RequestData({ query });
const data: GET_2_users_id_followers_Response = await this.client._api
.users(this.userId)
.followers.get(requestData);
const data: GETUsersIdFollowersResponse = await this.client._api.users(this.userId).followers.get(requestData);
this.#nextToken = data.meta.next_token;
this.#previousToken = data.meta.previous_token;
this.hasMore = data.meta.next_token ? true : false;
Expand Down
8 changes: 3 additions & 5 deletions src/books/FollowingsBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RequestData } from '../structures';
import type { Client } from '../client';
import type { User } from '../structures';
import type { FollowingsBookOptions } from '../typings';
import type { GET_2_users_id_following_Query, GET_2_users_id_following_Response, Snowflake } from 'twitter-types';
import type { GETUsersIdFollowingQuery, GETUsersIdFollowingResponse, Snowflake } from 'twitter-types';

/**
* A class for fetching users followed by a twitter user
Expand Down Expand Up @@ -86,17 +86,15 @@ export class FollowingsBook extends BaseBook {
async #fetchPages(token?: string): Promise<Collection<Snowflake, User>> {
const followingsCollection = new Collection<Snowflake, User>();
const queryParameters = this.client.options.queryParameters;
const query: GET_2_users_id_following_Query = {
const query: GETUsersIdFollowingQuery = {
expansions: queryParameters?.userExpansions,
'tweet.fields': queryParameters?.tweetFields,
'user.fields': queryParameters?.userFields,
pagination_token: token,
};
if (this.maxResultsPerPage) query.max_results = this.maxResultsPerPage;
const requestData = new RequestData({ query });
const data: GET_2_users_id_following_Response = await this.client._api
.users(this.userId)
.following.get(requestData);
const data: GETUsersIdFollowingResponse = await this.client._api.users(this.userId).following.get(requestData);
this.#nextToken = data.meta.next_token;
this.#previousToken = data.meta.previous_token;
this.hasMore = data.meta.next_token ? true : false;
Expand Down
8 changes: 3 additions & 5 deletions src/books/LikedTweetsBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RequestData } from '../structures';
import type { Client } from '../client';
import type { Tweet } from '../structures';
import type { LikedTweetsBookOptions } from '../typings';
import type { GET_2_users_id_liked_tweets_Query, GET_2_users_id_liked_tweets_Response, Snowflake } from 'twitter-types';
import type { GETUsersIdLikedTweetsQuery, GETUsersIdLikedTweetsResponse, Snowflake } from 'twitter-types';

/**
* A class for fetching tweets liked by a twitter user
Expand Down Expand Up @@ -86,7 +86,7 @@ export class LikedTweetsBook extends BaseBook {
async #fetchPages(token?: string): Promise<Collection<Snowflake, Tweet>> {
const likedTweetsCollection = new Collection<Snowflake, Tweet>();
const queryParameters = this.client.options.queryParameters;
const query: GET_2_users_id_liked_tweets_Query = {
const query: GETUsersIdLikedTweetsQuery = {
expansions: queryParameters?.tweetExpansions,
'media.fields': queryParameters?.mediaFields,
'place.fields': queryParameters?.placeFields,
Expand All @@ -97,9 +97,7 @@ export class LikedTweetsBook extends BaseBook {
};
if (this.maxResultsPerPage) query.max_results = this.maxResultsPerPage;
const requestData = new RequestData({ query });
const data: GET_2_users_id_liked_tweets_Response = await this.client._api
.users(this.userId)
.liked_tweets.get(requestData);
const data: GETUsersIdLikedTweetsResponse = await this.client._api.users(this.userId).liked_tweets.get(requestData);
this.#nextToken = data.meta.next_token;
this.#previousToken = data.meta.previous_token;
this.hasMore = data.meta.next_token ? true : false;
Expand Down
6 changes: 3 additions & 3 deletions src/books/MentionsBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RequestData } from '../structures';
import type { Client } from '../client';
import type { Tweet } from '../structures';
import type { MentionsBookOptions } from '../typings';
import type { GET_2_users_id_mentions_Query, GET_2_users_id_mentions_Response, Snowflake } from 'twitter-types';
import type { GETUsersIdMentionsQuery, GETUsersIdMentionsResponse, Snowflake } from 'twitter-types';

/**
* A class for fetching tweets that mention a twitter user
Expand Down Expand Up @@ -109,7 +109,7 @@ export class MentionsBook extends BaseBook {
async #fetchPages(token?: string): Promise<Collection<Snowflake, Tweet>> {
const mentioningTweetsCollection = new Collection<Snowflake, Tweet>();
const queryParameters = this.client.options.queryParameters;
const query: GET_2_users_id_mentions_Query = {
const query: GETUsersIdMentionsQuery = {
expansions: queryParameters?.tweetExpansions,
'media.fields': queryParameters?.mediaFields,
'place.fields': queryParameters?.placeFields,
Expand All @@ -124,7 +124,7 @@ export class MentionsBook extends BaseBook {
if (this.afterTimestamp) query.start_time = new Date(this.afterTimestamp).toISOString();
if (this.beforeTimestamp) query.end_time = new Date(this.beforeTimestamp).toISOString();
const requestData = new RequestData({ query });
const data: GET_2_users_id_mentions_Response = await this.client._api.users(this.userId).mentions.get(requestData);
const data: GETUsersIdMentionsResponse = await this.client._api.users(this.userId).mentions.get(requestData);
this.#nextToken = data.meta.next_token;
this.#previousToken = data.meta.previous_token;
this.hasMore = data.meta.next_token ? true : false;
Expand Down
6 changes: 3 additions & 3 deletions src/books/MutesBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RequestData } from '../structures';
import type { Client } from '../client';
import type { User } from '../structures';
import type { MutesBookOptions } from '../typings';
import type { GET_2_users_id_muting_Query, GET_2_users_id_muting_Response, Snowflake } from 'twitter-types';
import type { GETUsersIdMutingQuery, GETUsersIdMutingResponse, Snowflake } from 'twitter-types';

/**
* A class for fetching users muted by the authorized user
Expand Down Expand Up @@ -85,15 +85,15 @@ export class MutesBook extends BaseBook {
async #fetchPages(token?: string): Promise<Collection<Snowflake, User>> {
const mutedUsersCollection = new Collection<Snowflake, User>();
const queryParameters = this.client.options.queryParameters;
const query: GET_2_users_id_muting_Query = {
const query: GETUsersIdMutingQuery = {
expansions: queryParameters?.userExpansions,
'tweet.fields': queryParameters?.tweetFields,
'user.fields': queryParameters?.userFields,
pagination_token: token,
};
if (this.maxResultsPerPage) query.max_results = this.maxResultsPerPage;
const requestData = new RequestData({ query, isUserContext: true });
const data: GET_2_users_id_muting_Response = await this.client._api.users(this.userId).muting.get(requestData);
const data: GETUsersIdMutingResponse = await this.client._api.users(this.userId).muting.get(requestData);
this.#nextToken = data.meta.next_token;
this.#previousToken = data.meta.previous_token;
this.hasMore = data.meta.next_token ? true : false;
Expand Down
6 changes: 3 additions & 3 deletions src/books/SearchTweetsBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RequestData } from '../structures';
import type { Client } from '../client';
import type { Tweet } from '../structures';
import type { SearchTweetsBookOptions } from '../typings';
import type { GET_2_tweets_search_recent_Query, GET_2_tweets_search_recent_Response, Snowflake } from 'twitter-types';
import type { GETTweetsSearchRecentQuery, GETTweetsSearchRecentResponse, Snowflake } from 'twitter-types';

/**
* A class for fetching tweets using search query
Expand Down Expand Up @@ -95,7 +95,7 @@ export class SearchTweetsBook extends BaseBook {
async #fetchPages(token?: string): Promise<Collection<Snowflake, Tweet>> {
const tweetsCollection = new Collection<Snowflake, Tweet>();
const queryParameters = this.client.options.queryParameters;
const query: GET_2_tweets_search_recent_Query = {
const query: GETTweetsSearchRecentQuery = {
expansions: queryParameters?.tweetExpansions,
'tweet.fields': queryParameters?.tweetFields,
'user.fields': queryParameters?.userFields,
Expand All @@ -111,7 +111,7 @@ export class SearchTweetsBook extends BaseBook {
if (this.afterTimestamp) query.start_time = new Date(this.afterTimestamp).toISOString();
if (this.beforeTimestamp) query.end_time = new Date(this.beforeTimestamp).toISOString();
const requestData = new RequestData({ query });
const data: GET_2_tweets_search_recent_Response = await this.client._api.tweets.search.recent.get(requestData);
const data: GETTweetsSearchRecentResponse = await this.client._api.tweets.search.recent.get(requestData);
this.#nextToken = data.meta.next_token;
this.hasMore = data.meta.next_token ? true : false;
if (data.meta.result_count === 0) return tweetsCollection;
Expand Down
8 changes: 4 additions & 4 deletions src/books/TweetsCountBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CustomError } from '../errors';
import { RequestData, TweetCountBucket } from '../structures';
import type { Client } from '../client';
import type { TweetsCountBookOptions } from '../typings';
import type { GET_2_tweets_counts_recent_Query, GET_2_tweets_counts_recent_Response, Snowflake } from 'twitter-types';
import type { GETTweetsCountsRecentQuery, GETTweetsCountsRecentResponse, Snowflake } from 'twitter-types';

/**
* A class for fetching number of tweets matching a search query
Expand Down Expand Up @@ -36,7 +36,7 @@ export class TweetsCountBook extends BaseBook {
/**
* The book will group buckets according to this granularity
*/
granularity: GET_2_tweets_counts_recent_Query['granularity'] | null;
granularity: GETTweetsCountsRecentQuery['granularity'] | null;

/**
* The book will fetch tweets that were created after this tweet ID
Expand Down Expand Up @@ -90,7 +90,7 @@ export class TweetsCountBook extends BaseBook {

async #fetchPages(token?: string): Promise<Array<TweetCountBucket>> {
const tweetCountBuckets: Array<TweetCountBucket> = [];
const query: GET_2_tweets_counts_recent_Query = {
const query: GETTweetsCountsRecentQuery = {
query: this.query,
next_token: token,
};
Expand All @@ -100,7 +100,7 @@ export class TweetsCountBook extends BaseBook {
if (this.afterTimestamp) query.start_time = new Date(this.afterTimestamp).toISOString();
if (this.beforeTimestamp) query.end_time = new Date(this.beforeTimestamp).toISOString();
const requestData = new RequestData({ query });
const data: GET_2_tweets_counts_recent_Response = await this.client._api.tweets.counts.recent.get(requestData);
const data: GETTweetsCountsRecentResponse = await this.client._api.tweets.counts.recent.get(requestData);
this.#nextToken = data.meta.next_token;
this.hasMore = data.meta.next_token ? true : false;
if (data.meta.total_tweet_count === 0) return tweetCountBuckets;
Expand Down
24 changes: 12 additions & 12 deletions src/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { ClientCredentials, RequestData, ClientUser, MatchingRule } from '../str
import type { Response } from 'undici';
import type { ClientCredentialsInterface, ClientOptions } from '../typings';
import type {
GET_2_tweets_sample_stream_Query,
GET_2_tweets_sample_stream_Response,
GET_2_tweets_search_stream_Query,
GET_2_tweets_search_stream_Response,
GET_2_users_me_Query,
GET_2_users_me_Response,
GETTweetsSampleStreamQuery,
GETTweetsSampleStreamResponse,
GETTweetsSearchStreamQuery,
GETTweetsSearchStreamResponse,
GETUsersMeQuery,
GETUsersMeResponse,
Snowflake,
} from 'twitter-types';

Expand Down Expand Up @@ -169,19 +169,19 @@ export class Client extends BaseClient {

async #fetchClientUser(): Promise<ClientUser> {
const queryParameters = this.options.queryParameters;
const query: GET_2_users_me_Query = {
const query: GETUsersMeQuery = {
expansions: queryParameters?.userExpansions,
'tweet.fields': queryParameters?.tweetFields,
'user.fields': queryParameters?.userFields,
};
const requestData = new RequestData({ query, isUserContext: true });
const data: GET_2_users_me_Response = await this._api.users.me.get(requestData);
const data: GETUsersMeResponse = await this._api.users.me.get(requestData);
return new ClientUser(this, data);
}

async #connectToFilteredStream(): Promise<void> {
const queryParameters = this.options.queryParameters;
const query: GET_2_tweets_search_stream_Query = {
const query: GETTweetsSearchStreamQuery = {
expansions: queryParameters?.tweetExpansions,
'media.fields': queryParameters?.mediaFields,
'place.fields': queryParameters?.placeFields,
Expand All @@ -203,7 +203,7 @@ export class Client extends BaseClient {
continue;
}
try {
const rawData: GET_2_tweets_search_stream_Response = JSON.parse(data);
const rawData: GETTweetsSearchStreamResponse = JSON.parse(data);
const tweet = this.tweets._add(rawData.data.id, rawData, false);
const matchingRules = rawData.matching_rules.reduce((col, rule) => {
col.set(rule.id, new MatchingRule(rule));
Expand All @@ -222,7 +222,7 @@ export class Client extends BaseClient {

async #connectToSampledStream(): Promise<void> {
const queryParameters = this.options.queryParameters;
const query: GET_2_tweets_sample_stream_Query = {
const query: GETTweetsSampleStreamQuery = {
expansions: queryParameters?.tweetExpansions,
'media.fields': queryParameters?.mediaFields,
'place.fields': queryParameters?.placeFields,
Expand All @@ -244,7 +244,7 @@ export class Client extends BaseClient {
continue;
}
try {
const rawTweet: GET_2_tweets_sample_stream_Response = JSON.parse(data);
const rawTweet: GETTweetsSampleStreamResponse = JSON.parse(data);
const tweet = this.tweets._add(rawTweet.data.id, rawTweet, false);
this.emit(ClientEvents.SAMPLED_TWEET_CREATE, tweet);
} catch (error) {
Expand Down
Loading