From e44cc0535ad4a07e81a3719caa4f5d4a97a0a044 Mon Sep 17 00:00:00 2001 From: Christopher Angelo Date: Thu, 13 Aug 2020 02:02:38 +0700 Subject: [PATCH 1/4] initial typings expansion Signed-off-by: Christopher Angelo --- index.d.ts | 392 ++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- yarn.lock | 7 +- 3 files changed, 395 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index d3151f4..8b02235 100644 --- a/index.d.ts +++ b/index.d.ts @@ -32,6 +32,13 @@ import { EventEmitter } from 'events'; import * as OAuth from 'oauth-1.0a'; +declare class Stream extends EventEmitter { + constructor(); + + parse(buffer: Buffer): void; + destroy(): void; +} + export default class Twitter { private authType: AuthType; private url: string; @@ -87,6 +94,7 @@ export default class Twitter { * @returns {Promise} Promise resolving to the response from the Twitter API. * The `_header` property will be set to the Response headers (useful for checking rate limits) */ + public post(resource: K, body: PostResources[K][0]): Promise public post(resource: string, body: object): Promise; /** @@ -170,9 +178,385 @@ interface AccessTokenResponse { screen_name: string; } -declare class Stream extends EventEmitter { - constructor(); - parse(buffer: Buffer): void; - destroy(): void; +//#region PostRequestBody + +interface BasePostBody { + /** + * Desired status ID to do the action + */ + id?: string | number, +} + +interface PostGeneralTweetBody extends BasePostBody { + /** + * Whether each tweet returned in a timeline will include a user object including only the status authors numerical ID. + * Omit this parameter to receive the complete user object. + */ + trim_user?: boolean +} + +interface PostLikeTweetBody extends BasePostBody { + /** + * The entities node will be omitted when set to false + */ + include_entities?: boolean +} + +interface PostUpdateTweetBody{ + /** + * The content of the tweet + */ + status: string, + + /** + * The ID of an existing tweet that the update is in reply to + * Will be ignored if the tweet didn't include the replied tweet's author + */ + in_reply_to_status_id?: string, + + /** + * If set to `true` and used with `in_reply_to_status_id`, leading @mentions will be looked up from the original Tweet and added to the new Tweet from there. + * This will append @mentions into the metadata of an extended Tweet as a reply chain grows, until the limit on @mentions is reached. + * In cases where the original Tweet has been deleted, the reply will fail. + */ + auto_populate_reply_metadata?: boolean, + + /** + * When used with auto_populate_reply_metadata, a comma-separated list of user ids which will be removed from the server-generated @mentions prefix on an extended Tweet. Note that the leading @mention cannot be removed as it would break the in-reply-to-status-id semantics. Attempting to remove it will be silently ignored. + */ + exclude_reply_user_ids?: string, + + /** + * In order for a URL to not be counted in the status body of an extended Tweet, provide a URL as a Tweet attachment. This URL must be a Tweet permalink, or Direct Message deep link. Arbitrary, non-Twitter URLs must remain in the status text. URLs passed to the attachment_url parameter not matching either a Tweet permalink or Direct Message deep link will fail at Tweet creation and cause an exception + */ + attatchment_url?: string, + + /** + * A comma-delimited list of media_ids to associate with the Tweet. You may include up to 4 photos or 1 animated GIF or 1 video in a Tweet. See Uploading Media for further details on uploading media + */ + media_ids?: string, + + /** + * If you upload Tweet media that might be considered sensitive content such as nudity, or medical procedures, you must set this value to true. See Media setting and best practices for more context. + */ + possibly_sensitive?: boolean, + + /** + * The latitude of the location this Tweet refers to. This parameter will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there is no corresponding long parameter. + */ + lat?: number, + + /** + * The longitude of the location this Tweet refers to. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive. This parameter will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there no corresponding lat parameter. + */ + long?: number, + + /** + * A place in the world + */ + place_id?: string, + + /** + * Whether or not to put a pin on the exact coordinates a Tweet has been sent from + */ + display_coordinates?: boolean, + + + /** + * Whether the response will include a user object including only the author's ID. Omit this parameter to receive the complete user object. + */ + trim_user?: boolean, + + /** + * When set to true, enables shortcode commands for sending Direct Messages as part of the status text to send a Direct Message to a user. When set to false, disables this behavior and includes any leading characters in the status text that is posted + */ + enable_dmcommands?: boolean, + + /** + * When set to true, causes any status text that starts with shortcode commands to return an API error. When set to false, allows shortcode commands to be sent in the status text and acted on by the API. + */ + fail_dmcommands?: boolean, + + /** + * Associate an ads card with the Tweet using the card_uri value from any ads card response. + */ + card_uri?: string +} + +//#endregion + +//#region AbstractTypes + +/** + * Also known as Favorites + */ +interface Likes { + +} + +// Generated with Quicktype and humanly adapted +// https://app.quicktype.io?share=3JFdoOmOYKfUzjTjk1dk + +/** + * A Tweet Response + */ +export interface Tweet { + /** + * Whether the tweet contains coordinate + */ + coordinates: PointCoordinates | PolygonCoordinates | null; + + /** + * Whether the tweet is Liked by the current user + */ + favorited: boolean; + + /** + * The date of tweet creation + */ + created_at: string; + + /** + * Whether the tweet is truncated + * TODO: Figure out why some tweets are truncated + */ + truncated: boolean; + + /** + * The tweet's ID + */ + id_str: string; + + // TODO: Figure out these + entities: TweetEntities; + + /** + * The UserID of the person which the tweet is replying to + */ + in_reply_to_user_id_str: null | string; + + /** + * The tweet content + */ + text: string; + + // TODO: Figure out these + contributors: null; + + /** + * How many times has the tweet been retweeted + */ + retweet_count: number; + + /** + * The tweet's ID. + * Consider using `id_str` + */ + id: number; + + /** + * String representation of `in_reply_to_user_id` + */ + in_reply_to_status_id_str: null | string; + + /** + * The coordinates of the tweet + */ + geo: Coordinates | null; + + /** + * Whether the tweet is has been retweeted by the current user + */ + retweeted: boolean; + + /** + * The TweetID of the tweet which the current tweet is replying to + * Consider using `in_reply_to_user_id_str` instead + */ + in_reply_to_user_id: number | null; + + /** + * Whether the tweet might be sensitive + */ + possibly_sensitive?: boolean; + + /** + * The GeoPlace of the tweet + * TODO: Find an example of a GeoPlace + */ + place: null; + + /** + * The author of the Tweet + */ + user: User; + possibly_sensitive_editable?: boolean; + source: string; + in_reply_to_screen_name: null | string; + in_reply_to_status_id: number | null; + extended_entities?: ExtendedEntities; + is_quote_status?: boolean; + favorite_count?: number; + possibly_sensitive_appealable?: boolean; + lang?: string; + _headers?: Headers; +} + +export interface Headers { +} + +export interface PointCoordinates { + type: 'Point'; + coordinates: number[]; +} +export interface PolygonCoordinates { + type: 'Polygon'; + coordinates: number[][]; +} + +export interface TweetEntities { + urls: Url[]; + hashtags: Hashtag[]; + user_mentions: any[]; + symbols?: any[]; + media?: Media[]; +} + +export interface Hashtag { + text: string; + indices: number[]; +} + +export interface Media { + id: number; + id_str: string; + indices: number[]; + media_url: string; + media_url_https: string; + url: string; + display_url: string; + expanded_url: string; + type: string; + sizes: MediaSize; +} + +export interface MediaSize { + medium: MediaResolution; + small: MediaResolution; + thumb: MediaResolution; + large: MediaResolution; +} + +export interface MediaResolution { + w: number; + h: number; + resize: string; +} + +export interface Url { + expanded_url: string; + url: string; + indices: number[]; + display_url: string; +} + +export interface ExtendedEntities { + media: Media[]; +} + +export interface User { + name: string; + profile_sidebar_border_color: string; + profile_sidebar_fill_color: string; + profile_background_tile: boolean; + profile_image_url: string; + created_at: string; + location: string; + is_translator: boolean; + follow_request_sent: boolean; + id_str: string; + profile_link_color: string; + entities: UserEntities; + default_profile: boolean; + contributors_enabled: boolean; + url: null | string; + favourites_count: number; + utc_offset: number | null; + id: number; + profile_image_url_https: string; + profile_use_background_image: boolean; + listed_count: number; + profile_text_color: string; + protected: boolean; + lang: null | string; + followers_count: number; + time_zone: null | string; + profile_background_image_url_https: null | string; + verified: boolean; + profile_background_color: string; + notifications: boolean; + description: string; + geo_enabled: boolean; + statuses_count: number; + default_profile_image: boolean; + friends_count: number; + profile_background_image_url: null | string; + show_all_inline_media?: boolean; + screen_name: string; + following: boolean; + is_translation_enabled?: boolean; + profile_banner_url?: string; + has_extended_profile?: boolean; + translator_type?: string; +} + +export interface UserEntities { + url?: Description; + description: Description; +} + +export interface Description { + urls: Url[]; +} + + +//#endregion + +// APIEndpoint: [[Array of possible body], [Array of possible response]] +interface PostResources { + // Tweets - https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference + 'statuses/update': [[PostUpdateTweetBody], [Tweet]], + 'statuses/destroy': [[PostGeneralTweetBody], [Tweet]], + 'statuses/retweet': [[PostGeneralTweetBody], [Tweet]], + 'statuses/unretweet': [[PostGeneralTweetBody], [Tweet]], + 'favorites/create': [[], [Likes]], + 'favorites/destroy': [[], [Likes]], + 'statuses/update_with_media': [[], []], // Deprecated + + // TODO: Comeplete everything below + + // Friendships - https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference + // Also known as following someone + 'friendships/create': [[], []], + 'friendships/destroy': [[], []], + 'friendships/update': [[], []], + + // Mute / Block - https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/mute-block-report-users/api-reference + 'blocks/create': [[], []], + 'blocks/destroy': [[], []], + 'mutes/users/create': [[], []], + 'mutes/users/destroy': [[], []], + 'users/report_spam': [[], []], + + // Lists - https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference + 'list/create': [[], []], + 'list/destroy': [[], []], + 'list/members/create': [[], []], + 'list/members/create_all': [[], []], + 'list/members/destroy': [[], []], + 'list/members/destroy_all': [[], []], + 'list/subscribers/delete': [[], []], + 'list/subscribers/destroy': [[], []], + 'list/update': [[], []], } diff --git a/package.json b/package.json index 420812d..a75b60c 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "devDependencies": { "@types/jest": "^25.2.1", - "@types/node": "^13.13.4", + "@types/node": "^14.0.27", "bundlesize": "^0.18.0", "dotenv": "^8.2.0", "eslint": "^6.8.0", diff --git a/yarn.lock b/yarn.lock index 591b456..2412687 100644 --- a/yarn.lock +++ b/yarn.lock @@ -589,11 +589,16 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339" integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA== -"@types/node@*", "@types/node@^13.13.4": +"@types/node@*": version "13.13.4" resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.4.tgz#1581d6c16e3d4803eb079c87d4ac893ee7501c2c" integrity sha512-x26ur3dSXgv5AwKS0lNfbjpCakGIduWU1DU91Zz58ONRWrIKGunmZBNv4P7N+e27sJkiGDsw/3fT4AtsqQBrBA== +"@types/node@^14.0.27": + version "14.0.27" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.27.tgz#a151873af5a5e851b51b3b065c9e63390a9e0eb1" + integrity sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g== + "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" From 887100a57c9124eadb95c74e40d917a94003c638 Mon Sep 17 00:00:00 2001 From: Christopher Angelo Date: Fri, 14 Aug 2020 02:19:55 +0700 Subject: [PATCH 2/4] move typings to a separate folder and add more things Signed-off-by: Christopher Angelo --- package.json | 2 +- tsconfig.json | 2 +- index.d.ts => typings/index.d.ts | 174 +++++++++++++++++++------------ 3 files changed, 112 insertions(+), 66 deletions(-) rename index.d.ts => typings/index.d.ts (83%) diff --git a/package.json b/package.json index a75b60c..ee0f6a6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "source": "twitter.js", "main": "dist/twitter.js", "module": "dist/twitter.m.js", - "types": "index.d.ts", + "types": "./typings/index.d.ts", "files": [ "dist", "index.d.ts" diff --git a/tsconfig.json b/tsconfig.json index bf3e3fc..078210a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,6 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts" + "typings/index.d.ts" ] } \ No newline at end of file diff --git a/index.d.ts b/typings/index.d.ts similarity index 83% rename from index.d.ts rename to typings/index.d.ts index 8b02235..cd954e5 100644 --- a/index.d.ts +++ b/typings/index.d.ts @@ -94,8 +94,8 @@ export default class Twitter { * @returns {Promise} Promise resolving to the response from the Twitter API. * The `_header` property will be set to the Response headers (useful for checking rate limits) */ - public post(resource: K, body: PostResources[K][0]): Promise - public post(resource: string, body: object): Promise; + public post(resource: K, body: PostEndpoints[K][0]): Promise + // public post(resource: string, body: object): Promise; /** * Send a PUT request @@ -181,107 +181,107 @@ interface AccessTokenResponse { //#region PostRequestBody -interface BasePostBody { +export class BasePostBody { /** * Desired status ID to do the action */ - id?: string | number, + id?: string | number; } -interface PostGeneralTweetBody extends BasePostBody { +export class GeneralTweetPostBody extends BasePostBody { /** * Whether each tweet returned in a timeline will include a user object including only the status authors numerical ID. * Omit this parameter to receive the complete user object. */ - trim_user?: boolean + trim_user?: boolean; } -interface PostLikeTweetBody extends BasePostBody { +export class GeneralPostBody extends BasePostBody { /** * The entities node will be omitted when set to false */ - include_entities?: boolean + include_entities?: boolean; } -interface PostUpdateTweetBody{ +export class UpdateTweetPostBody { /** * The content of the tweet */ - status: string, + status: string; /** * The ID of an existing tweet that the update is in reply to * Will be ignored if the tweet didn't include the replied tweet's author */ - in_reply_to_status_id?: string, + in_reply_to_status_id?: string; /** * If set to `true` and used with `in_reply_to_status_id`, leading @mentions will be looked up from the original Tweet and added to the new Tweet from there. * This will append @mentions into the metadata of an extended Tweet as a reply chain grows, until the limit on @mentions is reached. * In cases where the original Tweet has been deleted, the reply will fail. */ - auto_populate_reply_metadata?: boolean, + auto_populate_reply_metadata?: boolean; /** * When used with auto_populate_reply_metadata, a comma-separated list of user ids which will be removed from the server-generated @mentions prefix on an extended Tweet. Note that the leading @mention cannot be removed as it would break the in-reply-to-status-id semantics. Attempting to remove it will be silently ignored. */ - exclude_reply_user_ids?: string, + exclude_reply_user_ids?: string; /** * In order for a URL to not be counted in the status body of an extended Tweet, provide a URL as a Tweet attachment. This URL must be a Tweet permalink, or Direct Message deep link. Arbitrary, non-Twitter URLs must remain in the status text. URLs passed to the attachment_url parameter not matching either a Tweet permalink or Direct Message deep link will fail at Tweet creation and cause an exception */ - attatchment_url?: string, + attatchment_url?: string; /** * A comma-delimited list of media_ids to associate with the Tweet. You may include up to 4 photos or 1 animated GIF or 1 video in a Tweet. See Uploading Media for further details on uploading media */ - media_ids?: string, + media_ids?: string; /** * If you upload Tweet media that might be considered sensitive content such as nudity, or medical procedures, you must set this value to true. See Media setting and best practices for more context. */ - possibly_sensitive?: boolean, + possibly_sensitive?: boolean; /** * The latitude of the location this Tweet refers to. This parameter will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there is no corresponding long parameter. */ - lat?: number, + lat?: number; /** * The longitude of the location this Tweet refers to. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive. This parameter will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there no corresponding lat parameter. */ - long?: number, + long?: number; /** * A place in the world */ - place_id?: string, + place_id?: string; /** * Whether or not to put a pin on the exact coordinates a Tweet has been sent from */ - display_coordinates?: boolean, + display_coordinates?: boolean; /** * Whether the response will include a user object including only the author's ID. Omit this parameter to receive the complete user object. */ - trim_user?: boolean, + trim_user?: boolean; /** * When set to true, enables shortcode commands for sending Direct Messages as part of the status text to send a Direct Message to a user. When set to false, disables this behavior and includes any leading characters in the status text that is posted */ - enable_dmcommands?: boolean, + enable_dmcommands?: boolean; /** * When set to true, causes any status text that starts with shortcode commands to return an API error. When set to false, allows shortcode commands to be sent in the status text and acted on by the API. */ - fail_dmcommands?: boolean, + fail_dmcommands?: boolean; /** * Associate an ads card with the Tweet using the card_uri value from any ads card response. */ - card_uri?: string + card_uri?: string; } //#endregion @@ -305,7 +305,7 @@ export interface Tweet { /** * Whether the tweet contains coordinate */ - coordinates: PointCoordinates | PolygonCoordinates | null; + coordinates: TweetPointCoordinates | TweetPolygonCoordinates | null; /** * Whether the tweet is Liked by the current user @@ -390,12 +390,12 @@ export interface Tweet { /** * The author of the Tweet */ - user: User; + user: TwitterUser; possibly_sensitive_editable?: boolean; source: string; in_reply_to_screen_name: null | string; in_reply_to_status_id: number | null; - extended_entities?: ExtendedEntities; + extended_entities?: TweetExtendedEntities; is_quote_status?: boolean; favorite_count?: number; possibly_sensitive_appealable?: boolean; @@ -406,29 +406,29 @@ export interface Tweet { export interface Headers { } -export interface PointCoordinates { +export interface TweetPointCoordinates { type: 'Point'; coordinates: number[]; } -export interface PolygonCoordinates { +export interface TweetPolygonCoordinates { type: 'Polygon'; coordinates: number[][]; } export interface TweetEntities { - urls: Url[]; - hashtags: Hashtag[]; + urls: TweetUrl[]; + hashtags: TweetHashtag[]; user_mentions: any[]; symbols?: any[]; - media?: Media[]; + media?: TweetMedia[]; } -export interface Hashtag { - text: string; +export interface TweetHashtag { + text: string; indices: number[]; } -export interface Media { +export interface TweetMedia { id: number; id_str: string; indices: number[]; @@ -438,61 +438,107 @@ export interface Media { display_url: string; expanded_url: string; type: string; - sizes: MediaSize; + sizes: TweetMediaSize; } -export interface MediaSize { - medium: MediaResolution; - small: MediaResolution; - thumb: MediaResolution; - large: MediaResolution; +export interface TweetMediaSize { + medium: TweetMediaResolution; + small: TweetMediaResolution; + thumb: TweetMediaResolution; + large: TweetMediaResolution; } -export interface MediaResolution { +export interface TweetMediaResolution { w: number; h: number; resize: string; } -export interface Url { +/** + * Twitter shortened link + * Starts with `t.co` + */ +export interface TweetUrl { expanded_url: string; url: string; indices: number[]; display_url: string; } -export interface ExtendedEntities { - media: Media[]; +export interface TweetExtendedEntities { + media: TweetMedia[]; } -export interface User { - name: string; +// Might not have the full detail (User data from Tweet) +export interface TwitterUser { + /** + * The User's display name + */ + name: string; profile_sidebar_border_color: string; profile_sidebar_fill_color: string; profile_background_tile: boolean; - profile_image_url: string; + + /** + * The URL of the User's profile picture + */ + profile_image_url: string; created_at: string; - location: string; + + /** + * The User's location + */ + location: string; is_translator: boolean; - follow_request_sent: boolean; - id_str: string; + + /** + * Whether the current account has sent a follow request to the user + */ + follow_request_sent: boolean; + + /** + * The User's ID represented as string + */ + id_str: string; profile_link_color: string; entities: UserEntities; default_profile: boolean; contributors_enabled: boolean; - url: null | string; - favourites_count: number; + + /** + * The User's twitter profile URL + * TODO: Figure out why this sometimes is null + */ + url: null | string; + + /** + * The User's amount of liked tweet + */ + favourites_count: number; utc_offset: number | null; - id: number; + + /** + * The User's ID + * Consider using `id_str` + */ + id: number; profile_image_url_https: string; profile_use_background_image: boolean; listed_count: number; profile_text_color: string; protected: boolean; lang: null | string; - followers_count: number; + + /** + * The amount of followers the user have + */ + followers_count: number; time_zone: null | string; profile_background_image_url_https: null | string; + + /** + * Whether the User is verified on Twitter + */ verified: boolean; profile_background_color: string; notifications: boolean; @@ -517,24 +563,24 @@ export interface UserEntities { } export interface Description { - urls: Url[]; + urls: TweetUrl[]; } //#endregion // APIEndpoint: [[Array of possible body], [Array of possible response]] -interface PostResources { +interface PostEndpoints { // Tweets - https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference - 'statuses/update': [[PostUpdateTweetBody], [Tweet]], - 'statuses/destroy': [[PostGeneralTweetBody], [Tweet]], - 'statuses/retweet': [[PostGeneralTweetBody], [Tweet]], - 'statuses/unretweet': [[PostGeneralTweetBody], [Tweet]], - 'favorites/create': [[], [Likes]], - 'favorites/destroy': [[], [Likes]], + 'statuses/update': [UpdateTweetPostBody, Tweet], + 'statuses/destroy': [GeneralTweetPostBody, Tweet], + 'statuses/retweet': [GeneralTweetPostBody, Tweet], + 'statuses/unretweet': [GeneralTweetPostBody, Tweet], + 'favorites/create': [GeneralPostBody, Tweet], + 'favorites/destroy': [GeneralPostBody, Tweet], 'statuses/update_with_media': [[], []], // Deprecated - // TODO: Comeplete everything below + // TODO: Complete everything below // Friendships - https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference // Also known as following someone From 1aadf29f6ae0a85eacba58647756e1cb1217dbed Mon Sep 17 00:00:00 2001 From: Christopher Angelo Date: Fri, 14 Aug 2020 02:20:44 +0700 Subject: [PATCH 3/4] add typings test file Signed-off-by: Christopher Angelo --- typings/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 typings/index.ts diff --git a/typings/index.ts b/typings/index.ts new file mode 100644 index 0000000..3084a7f --- /dev/null +++ b/typings/index.ts @@ -0,0 +1,6 @@ +/// +import Twitter from 'twitter-lite' + +const client = new Twitter({ + +}) \ No newline at end of file From 3ac15e37061f321d75234d5b00ba0c11d70b7440 Mon Sep 17 00:00:00 2001 From: Angelo Date: Mon, 19 Oct 2020 18:53:18 +0700 Subject: [PATCH 4/4] typings: TwitterStream --- typings/index.d.ts | 52 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index cd954e5..6dcc2af 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -32,11 +32,19 @@ import { EventEmitter } from 'events'; import * as OAuth from 'oauth-1.0a'; -declare class Stream extends EventEmitter { +declare class StatusesStream extends EventEmitter { constructor(); parse(buffer: Buffer): void; destroy(): void; + + public on(event: 'ping', listener: () => void): this + public on(event: 'data', listener: (data: Tweet) => void): this + public on(event: 'error', listener: (error: Error) => void): this + + public once(event: 'ping', listener: () => void): this + public once(event: 'data', listener: (data: Tweet) => void): this + public once(event: 'error', listener: (error: Error) => void): this } export default class Twitter { @@ -116,9 +124,9 @@ export default class Twitter { * * @param {string} resource - endpoint, e.g. `statuses/filter` * @param {object} parameters - * @returns {Stream} + * @returns {StatusesStream} The stream */ - public stream(resource: string, parameters: object): Stream; + public stream(resource: 'statuses/filter', parameters: TwitterStreamParams): StatusesStream; } /* In reality snowflakes are BigInts. Once BigInt is supported by browsers and Node per default, we could adjust this type. @@ -178,6 +186,44 @@ interface AccessTokenResponse { screen_name: string; } +interface TwitterStreamParams { + /** + * A comma-separated, case-insensitive and order-insensitive list of phrases used to filter seperated by spaces. + * Think of commas as Logical ORs while spaces are logical ANDs + * + * * Phrases must be between 1 and 60 bytes, inclusive + * * Exact matching of phrases is not supported + * + * @see [Twitter API - Track Stream Parameter](https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/basic-stream-parameters#track) + * @example `the twitter` - `the` AND `twitter` + * @example `the,twitter` - `the` OR `twitter` + * @example `the,this twitter` - (`the` OR `this`) `twitter` + */ + track?: string + + /** + * Twitter UserID to filter, seperated with a `,` + * @see https://tweeterid.com/ + * @example `422297024,873788249839370240` + */ + follow?: string + + /** + * A set of location bounding box to track + * @see [Twitter API - Locations](https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters) + * @example `-122.75,36.8,-121.75,37.8` + */ + locations?: string + + delimited?: 'length' + + /** + * Amount of backfill of missed messages which occurred during the disconnect period between `-150000` to `150000` + * + * @requires Twitter API elevated access + */ + count?: string +} //#region PostRequestBody