Skip to content

Commit

Permalink
Use type-only Imports
Browse files Browse the repository at this point in the history
  • Loading branch information
deptyped committed Mar 1, 2023
1 parent f9863bf commit 48fd4f5
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"prefer-arrow-callback": "off",
"consistent-return": "off",
"import/prefer-default-export": "off",
"import/extensions": "off"
"import/extensions": "off",
"no-underscore-dangle": "off"
},
"settings": {
"import/parsers": {
Expand Down
10 changes: 3 additions & 7 deletions src/bot/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Update, UserFromGetMe } from "@grammyjs/types";
import { UserPayload } from "@prisma/client";
import { Api, Context as DefaultContext, RawApi, SessionFlavor } from "grammy";
import { Container } from "~/container";
import { Context as DefaultContext, SessionFlavor, type Api } from "grammy";
import type { Container } from "~/container";
import { Logger } from "~/logger";

import { AutoChatActionFlavor } from "@grammyjs/auto-chat-action";
Expand Down Expand Up @@ -65,9 +65,5 @@ export function createContextConstructor(container: Container) {
});
this.scope = {};
}
} as unknown as new (
update: Update,
api: Api<RawApi>,
me: UserFromGetMe
) => Context;
} as unknown as new (update: Update, api: Api, me: UserFromGetMe) => Context;
}
2 changes: 1 addition & 1 deletion src/bot/features/bot-admin.feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Role } from "@prisma/client";
import { Composer, Keyboard } from "grammy";
import { or } from "grammy-guard";
import _ from "lodash";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";
import { isAdminUser, isOwnerUser } from "~/bot/filters";
import {
DEFAULT_LANGUAGE_CODE,
Expand Down
2 changes: 1 addition & 1 deletion src/bot/features/language.feature.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Composer } from "grammy";
import { changeLanguageData } from "~/bot/callback-data";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";
import { logHandle } from "~/bot/helpers/logging";
import { i18n } from "~/bot/i18n";
import { createChangeLanguageKeyboard } from "~/bot/keyboards";
Expand Down
2 changes: 1 addition & 1 deletion src/bot/features/welcome.feature.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Composer } from "grammy";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";
import { logHandle } from "~/bot/helpers/logging";

const composer = new Composer<Context>();
Expand Down
2 changes: 1 addition & 1 deletion src/bot/handlers/error.handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ErrorHandler } from "grammy";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";
import { getFullMetadata } from "~/bot/helpers/logging";

export const errorHandler: ErrorHandler<Context> = (error) => {
Expand Down
4 changes: 2 additions & 2 deletions src/bot/handlers/unhandled.handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";

export const unhandledHandler = <C extends Context>(ctx: C) =>
ctx.reply(ctx.t("unhandled"));
ctx.chat && ctx.reply(ctx.t("unhandled"));
2 changes: 1 addition & 1 deletion src/bot/helpers/logging.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Middleware } from "grammy";
import _ from "lodash";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";
import { updateHandledCounter } from "~/metrics";

export const getChatInfo = (ctx: Context) => {
Expand Down
2 changes: 1 addition & 1 deletion src/bot/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { I18n } from "@grammyjs/i18n";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";

export const i18n = new I18n<Context>({
defaultLocale: "en",
Expand Down
2 changes: 1 addition & 1 deletion src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
setScope,
updateLogger,
} from "~/bot/middlewares";
import { Container } from "~/container";
import type { Container } from "~/container";

type Dependencies = {
container: Container;
Expand Down
2 changes: 1 addition & 1 deletion src/bot/keyboards/change-language.keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { InlineKeyboard } from "grammy";
import ISO6391 from "iso-639-1";
import _ from "lodash";
import { changeLanguageData } from "~/bot/callback-data";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";
import { i18n } from "~/bot/i18n";

export const createChangeLanguageKeyboard = async (ctx: Context) => {
Expand Down
2 changes: 1 addition & 1 deletion src/bot/middlewares/i18n.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Middleware } from "grammy";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";
import { i18n as i18nProvider } from "~/bot/i18n";

export const i18n = (): Middleware<Context> => i18nProvider;
2 changes: 1 addition & 1 deletion src/bot/middlewares/metrics.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Middleware } from "grammy";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";
import { updateCounter, updateFailedCounter } from "~/metrics";

export const metrics = (): Middleware<Context> => async (ctx, next) => {
Expand Down
2 changes: 1 addition & 1 deletion src/bot/middlewares/session.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Middleware, session as createSession, StorageAdapter } from "grammy";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";

export const session = (
storage: StorageAdapter<unknown>
Expand Down
2 changes: 1 addition & 1 deletion src/bot/middlewares/set-scope.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Middleware } from "grammy";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";

export const setScope = (): Middleware<Context> => async (ctx, next) => {
if (ctx.from?.is_bot === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/bot/middlewares/update-logger.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Middleware } from "grammy";
import { Context } from "~/bot/context";
import type { Context } from "~/bot/context";
import { getFullMetadata } from "~/bot/helpers/logging";

export const updateLogger = (): Middleware<Context> => (ctx, next) => {
Expand Down
2 changes: 1 addition & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BotError, webhookCallback } from "grammy";
import { register } from "prom-client";
import type { Bot } from "~/bot";
import { errorHandler } from "~/bot/handlers";
import { Container } from "~/container";
import type { Container } from "~/container";

export const createServer = async (bot: Bot, container: Container) => {
const { logger, prisma } = container.items;
Expand Down

0 comments on commit 48fd4f5

Please sign in to comment.