Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

refactor(snoowrap.js): Convert to TypeScript #214

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"@babel/plugin-transform-template-literals": "^7.0.0",
"@babel/plugin-transform-typescript": "^7.0.0",
"@babel/register": "^7.5.5",
"@types/bluebird": "^3.5.27",
"@types/lodash": "^4.14.138",
"@types/request": "^2.48.2",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^1.13.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Promise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Promise from 'bluebird';
import {Promise} from 'bluebird';

const PromiseCopy = Promise.getNewLibraryCopy();
PromiseCopy.config({cancellation: true, warnings: false});
Expand Down
13 changes: 13 additions & 0 deletions src/create_config.js → src/create_config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// @ts-ignore
import {addSnakeCaseShadowProps} from './helpers.js';

export interface ConfigOptions {
endpointDomain: string;
requestDelay: number;
requestTimeout: number;
continueAfterRatelimitError: boolean;
retryErrorCodes: number[];
maxRetryAttempts: number;
warnings: boolean;
debug: boolean;
proxies: boolean;
}

export default function () {
const config = Object.create(null);
config.endpointDomain = 'reddit.com';
Expand Down
1 change: 1 addition & 0 deletions src/objects/ModmailConversation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default class ModmailConversation extends RedditContent<ModmailConversati
numMessages: number;
messages?: ModmailMessage[];

static _getConversationObjects(conversation: unknown, response: unknown): any
getParticipant(): Promise<ModmailConversationAuthor>;

isRead(): boolean;
Expand Down
21 changes: 14 additions & 7 deletions src/objects/Subreddit.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseSearchOptions, ModAction, Sort, SubmitLinkOptions, SubmitSelfPostOptions } from '../snoowrap';
import { Snoowrap } from '../snoowrap';
import Comment from './Comment';
import Listing, { ListingOptions } from './Listing';
import PrivateMessage from './PrivateMessage';
Expand Down Expand Up @@ -69,7 +69,7 @@ export default class Subreddit extends RedditContent<Subreddit> {
submit_text: string;
subreddit_type: SubredditType;
subscribers: number;
suggested_comment_sort: Sort | null;
suggested_comment_sort: Snoowrap.Sort | null;
title: string;
url: string;
user_can_flair_in_sr: boolean;
Expand Down Expand Up @@ -115,7 +115,7 @@ export default class Subreddit extends RedditContent<Subreddit> {
getEdited(options?: ListingOptions & { only?: 'links' | 'comments' }): Promise<Listing<Submission | Comment>>;
getHot(options?: ListingOptions): Promise<Listing<Submission>>;
getLinkFlairTemplates(linkId: string): Promise<FlairTemplate[]>;
getModerationLog(opts?: ListingOptions & { mods?: string[]; type?: ModActionType}): Promise<Listing<ModAction>>;
getModerationLog(opts?: ListingOptions & { mods?: string[]; type?: ModActionType}): Promise<Listing<Snoowrap.ModAction>>;
getModerators(options?: ListingOptions & { name?: string }): RedditUser[];
getModmail(options?: ListingOptions): Promise<Listing<PrivateMessage>>;
getNewModmailConversations(options?: ListingOptions): Promise<Listing<ModmailConversation>>;
Expand Down Expand Up @@ -153,7 +153,7 @@ export default class Subreddit extends RedditContent<Subreddit> {
removeModerator(options: { name: string; }): Promise<this>;
removeWikiContributor(options: { name: string; }): Promise<this>;
revokeModeratorInvite(options: { name: string; }): Promise<this>;
search(options: BaseSearchOptions): Promise<Listing<Submission>>;
search(options: Snoowrap.BaseSearchOptions): Promise<Listing<Submission>>;
selectMyFlair(options: { flair_template_id: string; text?: string; }): Promise<this>;
setModeratorPermissions(options: { name: string; permissions: ModeratorPermission; }): Promise<this>;
setMultipleUserFlairs(flairs: Array<{
Expand All @@ -162,8 +162,8 @@ export default class Subreddit extends RedditContent<Subreddit> {
cssClass: string;
}>): Promise<this>;
showMyFlair(): Promise<this>;
submitLink(options: SubmitLinkOptions): Promise<Submission>;
submitSelfPost(options: SubmitSelfPostOptions): Promise<Submission>;
submitLink(options: Snoowrap.SubmitLinkOptions): Promise<Submission>;
submitSelfPost(options: Snoowrap.SubmitSelfPostOptions): Promise<Submission>;
subscribe(): Promise<this>;
unbanUser(options: { name: string; }): Promise<this>;
unmuteUser(options: { name: string; }): Promise<this>;
Expand Down Expand Up @@ -225,6 +225,13 @@ export interface SubredditSettings {
title: string;
public_description: string;
description: string;
sr?: string;
captcha?: string;
captcha_iden?: string;
comment_score_hide_mins?: number;
'header-title': string;
show_media_preview: boolean;
allow_images?: boolean;
submit_text?: string;
hide_ads?: boolean;
lang?: string;
Expand All @@ -244,7 +251,7 @@ export interface SubredditSettings {
exclude_banned_modqueue?: boolean;
public_traffic?: boolean;
collapse_deleted_comments?: boolean;
suggested_comment_sort?: Sort; // TODO rename AvailableSorts?
suggested_comment_sort?: Snoowrap.Sort; // TODO rename AvailableSorts?
spoilers_enabled?: boolean;
}

Expand Down
8 changes: 8 additions & 0 deletions src/request_handler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import { Options as RequestOptions } from 'request';

declare function oauthRequest(options: RequestOptions, attempts: number): Promise<unknown>;
declare function credentialedClientRequest(options: RequestOptions): Promise<unknown>;
declare function unauthenticatedRequest(options: RequestOptions): Promise<unknown>;
declare function updateAccessToken(): Promise<unknown>;
declare const rawRequest: Promise<unknown>;
Loading