Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Feb 7, 2021
1 parent 10a50e0 commit ce2dc30
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 267 deletions.
472 changes: 259 additions & 213 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,44 @@
"author": "Myrotvorets <support@myrotvorets.center> (https://myrotvorets.center/)",
"license": "MIT",
"dependencies": {
"@bugsnag/js": "^7.5.6",
"@myrotvorets/envalidators": "^1.3.1",
"@myrotvorets/opentelemetry-configurator": "^1.1.3",
"@myrotvorets/opentelemetry-plugin-knex": "^0.4.0",
"@opentelemetry/api": "^0.14.0",
"@opentelemetry/core": "^0.14.0",
"@opentelemetry/semantic-conventions": "^0.14.0",
"@bugsnag/js": "^7.6.0",
"@myrotvorets/envalidators": "^1.4.0",
"@myrotvorets/opentelemetry-configurator": "^1.1.4",
"@myrotvorets/opentelemetry-plugin-knex": "^0.5.0",
"@opentelemetry/api": "^0.16.0",
"@opentelemetry/core": "^0.16.0",
"@opentelemetry/semantic-conventions": "^0.16.0",
"debug": "^4.3.2",
"envalid": "^6.0.2",
"knex": "^0.21.16",
"envalid": "^7.0.0",
"knex": "^0.21.17",
"knex-mariadb": "^2.0.0",
"mariadb": "^2.5.2",
"node-fetch": "^2.6.1",
"shimmer": "^1.2.1",
"telegraf": "^4.0.1"
"telegraf": "^4.0.2"
},
"devDependencies": {
"@myrotvorets/eslint-config-myrotvorets-ts": "^2.2.4",
"@myrotvorets/eslint-config-myrotvorets-ts": "^2.2.5",
"@types/debug": "^4.1.5",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.21",
"@types/node": "^14.14.25",
"@types/node-fetch": "^2.5.8",
"@types/shimmer": "^1.0.1",
"@types/sqlite3": "^3.1.6",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"eslint": "^7.18.0",
"@types/sqlite3": "^3.1.7",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"eslint": "^7.19.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-sonarjs": "^0.5.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
"lint-staged": "^10.5.3",
"lint-staged": "^10.5.4",
"merge": "^2.1.0",
"nodemon": "^2.0.7",
"prettier": "^2.2.1",
"sqlite3": "^5.0.1",
"ts-jest": "^26.4.4",
"ts-jest": "^26.5.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Bugsnag from '@bugsnag/js';
import debug from 'debug';
import knex from 'knex';
import { Telegraf } from 'telegraf';
import api from '@opentelemetry/api';
import api, { context, setSpan } from '@opentelemetry/api';
import { InlineKeyboardMarkup } from 'telegraf/typings/telegram-types';
import { addPost, checkPostExists } from '../lib/db';
import { Environment } from '../lib/environment';
Expand Down Expand Up @@ -57,7 +57,7 @@ export function lifecycle(env: Environment, bot: Telegraf<BotContext>): void {
const inner = (): void => {
const tracer = api.trace.getTracer('tracer');
const span = tracer.startSpan('Get posts');
void tracer.withSpan(span, async () => {
void context.with(setSpan(context.active(), span), async () => {
try {
const posts = await getNewPosts(env.NEWS_ENDPOINT, bot.context.db as knex);
dbg('Got %d new posts', posts.length);
Expand Down
23 changes: 8 additions & 15 deletions src/knexfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ import type { Client, Config } from 'knex';
import type { Database } from 'sqlite3';
import { cleanEnv, str } from 'envalid';

const env = cleanEnv(
process.env,
{
NODE_ENV: str({ default: 'development' }),
KNEX_DRIVER: str({ default: 'sqlite3', choices: ['sqlite3', 'mysql', 'mariadb'] }), // ! Run `npm i driver` if any other driver is needed
KNEX_DATABASE: str(),
KNEX_HOST: str({ default: 'localhost' }),
KNEX_USER: str({ default: '' }),
KNEX_PASSWORD: str({ default: '' }),
},
{
strict: true,
dotEnvPath: null,
},
);
const env = cleanEnv(process.env, {
NODE_ENV: str({ default: 'development' }),
KNEX_DRIVER: str({ default: 'sqlite3', choices: ['sqlite3', 'mysql', 'mariadb'] }), // ! Run `npm i driver` if any other driver is needed
KNEX_DATABASE: str(),
KNEX_HOST: str({ default: 'localhost' }),
KNEX_USER: str({ default: '' }),
KNEX_PASSWORD: str({ default: '' }),
});

export function buildKnexConfig(): Config {
// eslint-disable-next-line sonarjs/no-small-switch
Expand Down
30 changes: 12 additions & 18 deletions src/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,18 @@ let env: Environment | undefined;

export function getEnvironment(): Environment {
if (!env) {
env = cleanEnv(
process.env,
{
NODE_ENV: str({ default: 'development' }),
BUGSNAG_API_KEY: str(),
BOT_TOKEN: str(),
CHAT_ID: num(),
WEBHOOK_DOMAIN: str({ default: '' }),
WEBHOOK_PORT: portOrZero({ default: 0 }),
LISTEN_HOST: host({ default: '127.0.0.1' }),
NEWS_ENDPOINT: url(),
FETCH_INTERVAL: num({ default: 600_000 }),
PATH_PREFIX: str({ default: '' }),
},
{
strict: true,
},
);
env = cleanEnv(process.env, {
NODE_ENV: str({ default: 'development' }),
BUGSNAG_API_KEY: str(),
BOT_TOKEN: str(),
CHAT_ID: num(),
WEBHOOK_DOMAIN: str({ default: '' }),
WEBHOOK_PORT: portOrZero({ default: 0 }),
LISTEN_HOST: host({ default: '127.0.0.1' }),
NEWS_ENDPOINT: url(),
FETCH_INTERVAL: num({ default: 600_000 }),
PATH_PREFIX: str({ default: '' }),
});

process.env.NODE_ENV = env.NODE_ENV;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ot-telegraf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StatusCode, context, setActiveSpan } from '@opentelemetry/api';
import { StatusCode, context, setSpan } from '@opentelemetry/api';
import { BasePlugin } from '@opentelemetry/core';
import type Telegraf from 'telegraf';
import shimmer from 'shimmer';
Expand Down Expand Up @@ -61,7 +61,7 @@ export class TelegrafPlugin extends BasePlugin<typeof Telegraf> {
const self = this;
return function handleUpdate(this: typeof Telegraf, update: Update, ...params): ReturnType<typeof original> {
const span = self._tracer.startSpan(`telegraf.handleUpdate(${update.update_id})`);
return context.with(setActiveSpan(context.active(), span), () =>
return context.with(setSpan(context.active(), span), () =>
original.apply(this, [update, ...params]).then(
(result) => {
span.setStatus({ code: StatusCode.OK }).end();
Expand Down

0 comments on commit ce2dc30

Please sign in to comment.