Skip to content

Commit

Permalink
Merge pull request #381 from n0th1ng-else/remove-lambda
Browse files Browse the repository at this point in the history
fix(lambda): Delete lambda implementation
  • Loading branch information
n0th1ng-else committed Apr 7, 2024
2 parents fb9ff8c + e34fb6e commit c332dc0
Show file tree
Hide file tree
Showing 16 changed files with 2,997 additions and 5,041 deletions.
5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npm run format -- .
7,588 changes: 2,938 additions & 4,650 deletions package-lock.json

Large diffs are not rendered by default.

54 changes: 25 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Telegram Bot Converts Voice Messages Into Text",
"version": "1.0.0",
"engines": {
"node": ">=20.11.0"
"node": ">=20.10.0"
},
"type": "module",
"scripts": {
Expand All @@ -30,57 +30,53 @@
"test:unit:watch": "npm run test:runner -- --watch --selectProjects=unit",
"test:e2e:watch": "npm run test:runner -- --watch --selectProjects=e2e",
"test": "npm run test:runner -- --coverage --runInBand",
"prepare": "husky install"
"prepare": "husky"
},
"dependencies": {
"@amplitude/node": "1.10.2",
"@google-cloud/pubsub": "2.16.1",
"@google-cloud/secret-manager": "3.9.0",
"@google-cloud/speech": "4.5.5",
"@sentry/node": "7.94.1",
"@sentry/profiling-node": "1.3.5",
"@sentry/node": "7.109.0",
"@sentry/profiling-node": "7.109.0",
"aws-sdk": "2.1310.0",
"axios": "1.6.5",
"dotenv": "16.3.2",
"fastify": "4.26.0",
"express": "4.18.2",
"axios": "1.6.8",
"dotenv": "16.4.5",
"fastify": "4.26.2",
"express": "4.19.2",
"ffmpeg-static": "5.2.0",
"nanoid": "5.0.4",
"newrelic": "11.9.0",
"nanoid": "5.0.6",
"newrelic": "11.14.0",
"ngrok": "5.0.0-beta.2",
"node-telegram-bot-api": "0.64.0",
"pg": "8.11.3",
"pg": "8.11.5",
"picocolors": "1.0.0",
"prism-media": "1.3.5",
"signal-exit": "4.1.0",
"strip-ansi": "7.1.0",
"ts-node": "10.9.2",
"typescript": "5.3.3",
"winston": "3.11.0",
"typescript": "5.4.4",
"winston": "3.13.0",
"winston-logsene": "2.1.2",
"zod": "3.22.4"
},
"devDependencies": {
"@types/express": "4.17.21",
"@types/node": "20.11.5",
"@types/node-telegram-bot-api": "0.64.2",
"@types/node": "20.12.5",
"@types/parse": "3.0.9",
"@types/pg": "8.10.9",
"@types/pg": "8.11.4",
"@types/supertest": "6.0.2",
"@typescript-eslint/eslint-plugin": "6.19.0",
"@typescript-eslint/parser": "6.19.0",
"artillery": "2.0.4",
"@typescript-eslint/eslint-plugin": "7.5.0",
"@typescript-eslint/parser": "7.5.0",
"artillery": "2.0.9",
"artillery-plugin-expect": "2.3.3",
"eslint": "8.56.0",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"husky": "8.0.3",
"husky": "9.0.11",
"jest": "29.7.0",
"jest-sonar": "0.2.16",
"lint-staged": "15.2.0",
"nock": "13.5.0",
"prettier": "3.2.4",
"ts-jest": "29.1.1",
"query-string": "8.1.0",
"lint-staged": "15.2.2",
"nock": "13.5.4",
"prettier": "3.2.5",
"ts-jest": "29.1.2",
"query-string": "9.0.0",
"supertest": "6.3.4"
},
"lint-staged": {
Expand Down
2 changes: 0 additions & 2 deletions src/__mocks__/env.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { randomIntFromInterval } from "../common/timer.js";

process.env.NTBA_FIX_319 = "true"; // Disable some weird logic from "node-telegram-bot-api" package

export const appPort = 3000;

export const appVersion = `BotVersion-${randomIntFromInterval(1, 10000)}`;
Expand Down
8 changes: 3 additions & 5 deletions src/db/sql/donations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ export class DonationsDb {

constructor(private readonly pool: Pool) {}

public init(): Promise<void> {
public async init(): Promise<void> {
const query = DonationsSql.createTable;
const values = [];
return this.pool.query(query, values).then(() => {
this.initialized = true;
});
await this.pool.query(query);
this.initialized = true;
}

public createRow(chatId: number, price: number): Promise<DonationRowScheme> {
Expand Down
25 changes: 10 additions & 15 deletions src/db/sql/durations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ export class DurationsDb {

constructor(private readonly pool: Pool) {}

public init(): Promise<void> {
public async init(): Promise<void> {
const query = DurationsSql.createTable;
const values = [];
return this.pool.query(query, values).then(() => {
this.initialized = true;
});
await this.pool.query(query);
this.initialized = true;
}

public createRow(
public async createRow(
chatId: number,
duration: number,
): Promise<DurationRowScheme> {
Expand All @@ -37,15 +35,12 @@ export class DurationsDb {
const createdAt = new Date();
const updatedAt = createdAt;
const values = [durationId, chatId, duration, createdAt, updatedAt];
return this.pool
.query<DurationRowScheme>(query, values)
.then((queryData) => {
const row = queryData.rows.shift();
if (!row) {
return Promise.reject(new Error("Unable to get created row info"));
}
return row;
});
const queryData = await this.pool.query<DurationRowScheme>(query, values);
const row = queryData.rows.shift();
if (!row) {
return Promise.reject(new Error("Unable to get created row info"));
}
return row;
}

public getId(row: DurationRowScheme): string {
Expand Down
11 changes: 5 additions & 6 deletions src/db/sql/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ export class UsedEmailDb {

constructor(private readonly pool: Pool) {}

public init(): Promise<void> {
public async init(): Promise<void> {
const query = UsedEmailsSql.createTable;
const values = [];
return this.pool.query(query, values).then(() => {
return this.pool.query(query).then(() => {
this.initialized = true;
});
}

public createRow(email: string): Promise<UsedEmailRowScheme> {
public async createRow(email: string): Promise<UsedEmailRowScheme> {
if (!this.initialized) {
return Promise.reject(
new Error("The table usedemails is not initialized yet"),
Expand All @@ -42,7 +41,7 @@ export class UsedEmailDb {
});
}

public updateRow(emailId: number): Promise<UsedEmailRowScheme> {
public async updateRow(emailId: number): Promise<UsedEmailRowScheme> {
if (!this.initialized) {
return Promise.reject(
new Error("The table usedemails is not initialized yet"),
Expand All @@ -63,7 +62,7 @@ export class UsedEmailDb {
});
}

public getRows(email: string): Promise<UsedEmailRowScheme[]> {
public async getRows(email: string): Promise<UsedEmailRowScheme[]> {
if (!this.initialized) {
return Promise.reject(
new Error("The table usedemails is not initialized yet"),
Expand Down
7 changes: 3 additions & 4 deletions src/db/sql/ignoredchats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ export class IgnoredChatsDb {

constructor(private readonly pool: Pool) {}

public init(): Promise<void> {
public async init(): Promise<void> {
const query = IgnoredChatsSql.createTable;
const values = [];
return this.pool.query(query, values).then(() => {
return this.pool.query(query).then(() => {
this.initialized = true;
});
}

public getRow(chatId: number): Promise<IgnoredChatsRowScheme | null> {
public async getRow(chatId: number): Promise<IgnoredChatsRowScheme | null> {
if (!this.initialized) {
return Promise.reject(
new Error("The table ignoredchats is not initialized yet"),
Expand Down
11 changes: 5 additions & 6 deletions src/db/sql/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ export class NodesDb {

constructor(private readonly pool: Pool) {}

public init(): Promise<void> {
public async init(): Promise<void> {
const query = NodesSql.createTable;
const values = [];
return this.pool.query(query, values).then(() => {
return this.pool.query(query).then(() => {
this.initialized = true;
});
}

public createRow(
public async createRow(
selfUrl: string,
isActive: boolean,
version: string,
Expand All @@ -48,7 +47,7 @@ export class NodesDb {
});
}

public updateRow(
public async updateRow(
nodeId: string,
isActive: boolean,
version: string,
Expand All @@ -70,7 +69,7 @@ export class NodesDb {
});
}

public getRows(selfUrl: string): Promise<NodeRowScheme[]> {
public async getRows(selfUrl: string): Promise<NodeRowScheme[]> {
if (!this.initialized) {
return Promise.reject(
new Error("The table nodes is not initialized yet"),
Expand Down
15 changes: 7 additions & 8 deletions src/db/sql/usages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ export class UsagesDb {

constructor(private readonly pool: Pool) {}

public init(): Promise<void> {
public async init(): Promise<void> {
const query = UsagesSql.createTable;
const values = [];
return this.pool.query(query, values).then(() => {
return this.pool.query(query).then(() => {
this.initialized = true;
});
}

public createRow(
public async createRow(
chatId: number,
langId: string,
username: string,
Expand Down Expand Up @@ -59,7 +58,7 @@ export class UsagesDb {
});
}

public updateRow(
public async updateRow(
usageId: string,
langId: string,
usageCount: number,
Expand All @@ -85,7 +84,7 @@ export class UsagesDb {
/**
* @deprecated Use it only for migration
*/
public updateRowWithDate(
public async updateRowWithDate(
usageId: string,
langId: string,
usageCount: number,
Expand Down Expand Up @@ -116,7 +115,7 @@ export class UsagesDb {
});
}

public getRows(chatId: number): Promise<UsageRowScheme[]> {
public async getRows(chatId: number): Promise<UsageRowScheme[]> {
if (!this.initialized) {
return Promise.reject(
new Error("The table usages is not initialized yet"),
Expand All @@ -137,7 +136,7 @@ export class UsagesDb {
/**
* @deprecated Use it only for chart
*/
public statRows(
public async statRows(
from: Date,
to: Date,
usageCountFrom: number,
Expand Down
2 changes: 0 additions & 2 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
process.env.NTBA_FIX_319 = "true"; // Disable some weird logic from "node-telegram-bot-api" package

export const appPort: number = Number(process.env.PORT) || 3000;

export const appVersion: string = process.env.APP_VERSION || "dev";
Expand Down
82 changes: 0 additions & 82 deletions src/lambda/encodeToText.js

This file was deleted.

Loading

0 comments on commit c332dc0

Please sign in to comment.