Skip to content

Commit

Permalink
change acronyms in symbol names to be proper camelCase/PascalCase
Browse files Browse the repository at this point in the history
fixes #136
  • Loading branch information
d-fischer committed Jul 10, 2020
1 parent 9d0adb1 commit c497452
Show file tree
Hide file tree
Showing 43 changed files with 528 additions and 477 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,3 +1,4 @@
node_modules
/packages/*/es
/packages/*/lib
.eslintrc.js
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -9,10 +9,10 @@
"license": "MIT",
"devDependencies": {
"@d-fischer/documen.ts": "^0.9.3",
"@d-fischer/eslint-config": "^1.0.11",
"@d-fischer/eslint-config": "^2.0.0",
"@types/node": "^12.12.47",
"electron": "^9.1.0",
"eslint": "^6.6.0",
"eslint": "^7.4.0",
"eslint-import-resolver-lerna": "^1.1.0",
"husky": "^4.2.5",
"lerna": "^3.22.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/easy-twitch-bot/src/index.ts
Expand Up @@ -3,11 +3,11 @@
import { deprecateClass } from '@d-fischer/shared-utils';

import { Bot } from './Bot';
/** @deprecated Please use the named export `Bot` instead */
const DeprecatedBot = deprecateClass(Bot, 'Please use the named export `Bot` instead');
/** @deprecated Please use the named export `Bot` instead */
/** @deprecated Use the named export `Bot` instead. */
const DeprecatedBot = deprecateClass(Bot, 'Use the named export `Bot` instead.');
/** @deprecated Use the named export `Bot` instead. */
type DeprecatedBot = Bot;
/** @deprecated Please use the named export `Bot` instead */
/** @deprecated Use the named export `Bot` instead. */
export default DeprecatedBot;
export { Bot };

Expand Down
27 changes: 24 additions & 3 deletions packages/twitch-chat-client/src/ChatClient.ts
Expand Up @@ -1901,7 +1901,7 @@ export class ChatClient extends IRCClient {
* @param channel The channel to give the user VIP status in.
* @param user The user to give VIP status.
*/
async addVIP(channel: string, user: string) {
async addVip(channel: string, user: string) {
channel = toUserName(channel);
user = toUserName(user);
return new Promise<void>((resolve, reject) => {
Expand All @@ -1919,13 +1919,20 @@ export class ChatClient extends IRCClient {
});
}

/** @deprecated Use addVip instead. */
// eslint-disable-next-line @typescript-eslint/naming-convention
async addVIP(channel: string, user: string) {
deprecate('[twitch-chat-client] ChatClient#addVIP', 'Use `addVip` instead.');
return this.addVip(channel, user);
}

/**
* Takes VIP status from a user in a channel.
*
* @param channel The channel to remove the user's VIP status in.
* @param user The user to take VIP status from.
*/
async removeVIP(channel: string, user: string) {
async removeVip(channel: string, user: string) {
channel = toUserName(channel);
user = toUserName(user);
return new Promise<void>((resolve, reject) => {
Expand All @@ -1943,12 +1950,19 @@ export class ChatClient extends IRCClient {
});
}

/** @deprecated Use removeVip instead. */
// eslint-disable-next-line @typescript-eslint/naming-convention
async removeVIP(channel: string, user: string) {
deprecate('[twitch-chat-client] ChatClient#removeVIP', 'Use `removeVip` instead.');
return this.removeVip(channel, user);
}

/**
* Retrieves a list of VIPs in a channel.
*
* @param channel The channel to retrieve the VIPs of.
*/
async getVIPs(channel: string) {
async getVips(channel: string) {
channel = toUserName(channel);
return new Promise<string[]>(resolve => {
const e = this._onVipsResult((_channel, vips) => {
Expand All @@ -1961,6 +1975,13 @@ export class ChatClient extends IRCClient {
});
}

/** @deprecated Use getVips instead. */
// eslint-disable-next-line @typescript-eslint/naming-convention
async getVIPs(channel: string) {
deprecate('[twitch-chat-client] ChatClient#getVIPs', 'Use `getVips` instead.');
return this.getVips(channel);
}

/**
* Sends a message to a channel.
*
Expand Down
8 changes: 4 additions & 4 deletions packages/twitch-chat-client/src/index.ts
Expand Up @@ -2,11 +2,11 @@
import { deprecateClass } from '@d-fischer/shared-utils';

import { ChatClient } from './ChatClient';
/** @deprecated Please use the named export `ChatClient` instead */
const DeprecatedChatClient = deprecateClass(ChatClient, 'Please use the named export `ChatClient` instead');
/** @deprecated Please use the named export `ChatClient` instead */
/** @deprecated Use the named export `ChatClient` instead. */
const DeprecatedChatClient = deprecateClass(ChatClient, 'Use the named export `ChatClient` instead.');
/** @deprecated Use the named export `ChatClient` instead. */
type DeprecatedChatClient = ChatClient;
/** @deprecated Please use the named export `ChatClient` instead */
/** @deprecated Use the named export `ChatClient` instead. */
export default DeprecatedChatClient;
export { ChatClient };

Expand Down
35 changes: 28 additions & 7 deletions packages/twitch-electron-auth-provider/src/ElectronAuthProvider.ts
Expand Up @@ -18,8 +18,19 @@ interface AuthorizeParams {
}

export interface TwitchClientCredentials {
/**
* The client ID of your application.
*/
clientId: string;
redirectURI: string;

/**
* A redirect URI that was added to your application.
*/
redirectUri?: string;

/** @deprecated Use redirectUri instead. */
// eslint-disable-next-line @typescript-eslint/naming-convention
redirectURI?: string;
}

const defaultOptions: BaseOptions & Partial<WindowStyleOptions & WindowOptions> = {
Expand All @@ -32,15 +43,25 @@ export class ElectronAuthProvider implements AuthProvider {
private readonly _currentScopes = new Set<string>();
private readonly _options: BaseOptions & Partial<WindowOptions & WindowStyleOptions>;
private _allowUserChange = false;
private readonly _clientId: string;
private readonly _redirectUri: string;

readonly tokenType: AuthProviderTokenType = 'user';

constructor(clientCredentials: TwitchClientCredentials, options?: ElectronAuthProviderOptions);
constructor(clientCredentials: TwitchClientCredentials, options?: ElectronAuthProviderOptions<WindowOptions>);
constructor(
private readonly _clientCredentials: TwitchClientCredentials,
clientCredentials: TwitchClientCredentials,
options?: ElectronAuthProviderOptions | ElectronAuthProviderOptions<WindowOptions>
) {
this._clientId = clientCredentials.clientId;
if (clientCredentials.redirectUri) {
this._redirectUri = clientCredentials.redirectUri;
} else if (clientCredentials.redirectURI) {
this._redirectUri = clientCredentials.redirectURI;
} else {
throw new Error('Please supply a redirect URI');
}
this._options = { ...defaultOptions, ...options };
}

Expand All @@ -49,7 +70,7 @@ export class ElectronAuthProvider implements AuthProvider {
}

get clientId() {
return this._clientCredentials.clientId;
return this._clientId;
}

get currentScopes() {
Expand All @@ -69,7 +90,7 @@ export class ElectronAuthProvider implements AuthProvider {
return;
}

const redir = encodeURIComponent(this._clientCredentials.redirectURI);
const redir = encodeURIComponent(this._redirectUri);
const queryParams: AuthorizeParams = {
response_type: 'token',
client_id: this.clientId,
Expand Down Expand Up @@ -117,15 +138,15 @@ export class ElectronAuthProvider implements AuthProvider {
}

authWindow.webContents.session.webRequest.onBeforeRequest(
{ urls: [this._clientCredentials.redirectURI] },
{ urls: [this._redirectUri] },
(details, callback) => {
const url = new URL(details.url);
const match = url.origin + url.pathname;

// sometimes, electron seems to intercept too much... we catch this here
if (match !== this._clientCredentials.redirectURI) {
if (match !== this._redirectUri) {
// the trailing slash might be too much in the pathname
if (url.pathname !== '/' || url.origin !== this._clientCredentials.redirectURI) {
if (url.pathname !== '/' || url.origin !== this._redirectUri) {
callback({});
return;
}
Expand Down
9 changes: 5 additions & 4 deletions packages/twitch-electron-auth-provider/src/index.ts
Expand Up @@ -2,15 +2,16 @@
import { deprecateClass } from '@d-fischer/shared-utils';

import { ElectronAuthProvider } from './ElectronAuthProvider';
/** @deprecated Please use the named export `ElectronAuthProvider` instead */
/** @deprecated Use the named export `ElectronAuthProvider` instead. */
const DeprecatedElectronAuthProvider = deprecateClass(
ElectronAuthProvider,
'Please use the named export `ElectronAuthProvider` instead'
'Use the named export `ElectronAuthProvider` instead.'
);
/** @deprecated Please use the named export `ElectronAuthProvider` instead */
/** @deprecated Use the named export `ElectronAuthProvider` instead. */
type DeprecatedElectronAuthProvider = ElectronAuthProvider;
/** @deprecated Please use the named export `ElectronAuthProvider` instead */
/** @deprecated Use the named export `ElectronAuthProvider` instead. */
export default DeprecatedElectronAuthProvider;
export { ElectronAuthProvider };

export { TwitchClientCredentials } from './ElectronAuthProvider';
export { ElectronAuthProviderOptions } from './ElectronAuthProviderOptions';
8 changes: 4 additions & 4 deletions packages/twitch-pubsub-client/src/index.ts
Expand Up @@ -2,11 +2,11 @@
import { deprecateClass } from '@d-fischer/shared-utils';

import { PubSubClient } from './PubSubClient';
/** @deprecated Please use the named export `PubSubClient` instead */
const DeprecatedPubSubClient = deprecateClass(PubSubClient, 'Please use the named export `PubSubClient` instead');
/** @deprecated Please use the named export `PubSubClient` instead */
/** @deprecated Use the named export `PubSubClient` instead. */
const DeprecatedPubSubClient = deprecateClass(PubSubClient, 'Use the named export `PubSubClient` instead.');
/** @deprecated Use the named export `PubSubClient` instead. */
type DeprecatedPubSubClient = PubSubClient;
/** @deprecated Please use the named export `PubSubClient` instead */
/** @deprecated Use the named export `PubSubClient` instead. */
export default DeprecatedPubSubClient;
export { PubSubClient };

Expand Down
11 changes: 4 additions & 7 deletions packages/twitch-webhooks/src/index.ts
Expand Up @@ -2,14 +2,11 @@
import { deprecateClass } from '@d-fischer/shared-utils';

import { WebHookListener } from './WebHookListener';
/** @deprecated Please use the named export `WebHookListener` instead */
const DeprecatedWebHookListener = deprecateClass(
WebHookListener,
'Please use the named export `WebHookListener` instead'
);
/** @deprecated Please use the named export `WebHookListener` instead */
/** @deprecated Use the named export `WebHookListener` instead. */
const DeprecatedWebHookListener = deprecateClass(WebHookListener, 'Use the named export `WebHookListener` instead.');
/** @deprecated Use the named export `WebHookListener` instead. */
type DeprecatedWebHookListener = WebHookListener;
/** @deprecated Please use the named export `WebHookListener` instead */
/** @deprecated Use the named export `WebHookListener` instead. */
export default DeprecatedWebHookListener;
export { WebHookListener };

Expand Down
1 change: 1 addition & 0 deletions packages/twitch/package.json
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"@d-fischer/cache-decorators": "^2.0.0",
"@d-fischer/cross-fetch": "^4.0.1",
"@d-fischer/deprecate": "^2.0.1",
"@d-fischer/logger": "^2.0.0",
"@d-fischer/qs": "^7.0.2",
"@d-fischer/rate-limiter": "^0.2.5",
Expand Down
@@ -1,7 +1,7 @@
import { Cacheable, Cached } from '@d-fischer/cache-decorators';
import { extractUserId, UserIdResolvable } from '../../Toolkit/UserTools';
import { TwitchAPICallType } from '../../TwitchClient';
import { BaseAPI } from '../BaseAPI';
import { TwitchApiCallType } from '../../TwitchClient';
import { BaseApi } from '../BaseApi';
import { ChatBadgeList, ChatBadgeListData } from './ChatBadgeList';

/**
Expand All @@ -16,18 +16,20 @@ import { ChatBadgeList, ChatBadgeListData } from './ChatBadgeList';
* ```
*/
@Cacheable
export class BadgesAPI extends BaseAPI {
export class BadgesApi extends BaseApi {
/**
* Retrieves all globally applicable chat badges.
*
* @param language The language of the retrieved badge descriptions.
*/
@Cached(3600)
async getGlobalBadges(language?: string) {
const data = await this._client.callAPI<{ badge_sets: ChatBadgeListData }>({
const data = await this._client.callApi<{ badge_sets: ChatBadgeListData }>({
url: 'https://badges.twitch.tv/v1/badges/global/display',
query: {
language
},
type: TwitchAPICallType.Custom
type: TwitchApiCallType.Custom
});

return new ChatBadgeList(data.badge_sets, this._client);
Expand All @@ -38,15 +40,16 @@ export class BadgesAPI extends BaseAPI {
*
* @param channel The channel to retrieve the chat badges for.
* @param includeGlobal Whether to include global badges in the result list.
* @param language The language of the retrieved badge descriptions.
*/
@Cached(3600)
async getChannelBadges(channel: UserIdResolvable, includeGlobal: boolean = true, language?: string) {
const data = await this._client.callAPI<{ badge_sets: ChatBadgeListData }>({
const data = await this._client.callApi<{ badge_sets: ChatBadgeListData }>({
url: `https://badges.twitch.tv/v1/badges/channels/${extractUserId(channel)}/display`,
query: {
language
},
type: TwitchAPICallType.Custom
type: TwitchApiCallType.Custom
});

const channelBadges = new ChatBadgeList(data.badge_sets, this._client);
Expand Down
Expand Up @@ -2,7 +2,7 @@ import { Enumerable } from '@d-fischer/shared-utils';
import { TwitchClient } from '../TwitchClient';

/** @private */
export class BaseAPI {
export class BaseApi {
@Enumerable(false) protected readonly _client: TwitchClient;

constructor(client: TwitchClient) {
Expand Down
@@ -1,5 +1,5 @@
import { TwitchAPICallType } from '../../../TwitchClient';
import { BaseAPI } from '../../BaseAPI';
import { TwitchApiCallType } from '../../../TwitchClient';
import { BaseApi } from '../../BaseApi';
import { HelixBitsLeaderboard, HelixBitsLeaderboardResponse } from './HelixBitsLeaderboard';

/**
Expand Down Expand Up @@ -47,16 +47,16 @@ export interface HelixBitsLeaderboardQuery {
* const leaderboard = await client.helix.bits.getLeaderboard({ period: 'day' });
* ```
*/
export class HelixBitsAPI extends BaseAPI {
export class HelixBitsApi extends BaseApi {
/**
* Gets a bits leaderboard of your channel.
*
* @expandParams
*/
async getLeaderboard(params: HelixBitsLeaderboardQuery = {}) {
const { count = 10, period = 'all', startDate, contextUserId } = params;
const result = await this._client.callAPI<HelixBitsLeaderboardResponse>({
type: TwitchAPICallType.Helix,
const result = await this._client.callApi<HelixBitsLeaderboardResponse>({
type: TwitchApiCallType.Helix,
url: 'bits/leaderboard',
scope: 'bits:read',
query: {
Expand Down
@@ -1,5 +1,5 @@
import { TwitchAPICallType } from '../../../TwitchClient';
import { BaseAPI } from '../../BaseAPI';
import { TwitchApiCallType } from '../../../TwitchClient';
import { BaseApi } from '../../BaseApi';
import { HelixPaginatedRequest } from '../HelixPaginatedRequest';
import { createPaginatedResult } from '../HelixPaginatedResult';
import { HelixPaginatedResponse } from '../HelixResponse';
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface HelixClipCreateResponse {
* const clipId = await client.helix.clips.createClip({ channelId: '125328655' });
* ```
*/
export class HelixClipAPI extends BaseAPI {
export class HelixClipApi extends BaseApi {
/**
* Retrieves the latest clips for the specified broadcaster.
*
Expand Down Expand Up @@ -162,8 +162,8 @@ export class HelixClipAPI extends BaseAPI {
*/
async createClip(params: HelixClipCreateParams) {
const { channelId, createAfterDelay = false } = params;
const result = await this._client.callAPI<{ data: [HelixClipCreateResponse] }>({
type: TwitchAPICallType.Helix,
const result = await this._client.callApi<{ data: [HelixClipCreateResponse] }>({
type: TwitchApiCallType.Helix,
url: 'clips',
method: 'POST',
scope: 'clips:edit',
Expand All @@ -179,8 +179,8 @@ export class HelixClipAPI extends BaseAPI {
private async _getClips(params: HelixClipIdFilter) {
const { filterType, ids, startDate, endDate, limit = 20 } = params;

const result = await this._client.callAPI<HelixPaginatedResponse<HelixClipData>>({
type: TwitchAPICallType.Helix,
const result = await this._client.callApi<HelixPaginatedResponse<HelixClipData>>({
type: TwitchApiCallType.Helix,
url: 'clips',
query: {
[filterType]: ids,
Expand Down

0 comments on commit c497452

Please sign in to comment.