From 6a8ce485654147d75cc85ea976ff66eedf7f0179 Mon Sep 17 00:00:00 2001 From: rozetko Date: Thu, 27 May 2021 16:02:54 +0300 Subject: [PATCH 1/5] update typescript --- server/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/package.json b/server/package.json index db2cefc..8653d59 100644 --- a/server/package.json +++ b/server/package.json @@ -54,7 +54,7 @@ "nodemon": "^1.17.5", "ts-jest": "^23.1.1", "ts-loader": "^4.4.1", - "typescript": "^3.9.5", + "typescript": "^4.3.2", "url": "^0.11.0", "webpack": "^4.12.0", "webpack-cli": "^3.0.8", From bfee62daf22a9371da7a0afa122330f52c78c121 Mon Sep 17 00:00:00 2001 From: rozetko Date: Thu, 27 May 2021 16:03:11 +0300 Subject: [PATCH 2/5] fix typescript errors --- server/src/routes/analytic_units_router.ts | 10 ++++++---- server/src/routes/data_router.ts | 14 +++++++------- server/src/routes/detections_router.ts | 2 +- server/src/routes/panel_router.ts | 2 +- server/src/routes/segments_router.ts | 2 +- server/src/services/data_layer/nedb.ts | 2 +- server/src/services/json_service.ts | 2 +- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/server/src/routes/analytic_units_router.ts b/server/src/routes/analytic_units_router.ts index 7d95637..4d392c5 100644 --- a/server/src/routes/analytic_units_router.ts +++ b/server/src/routes/analytic_units_router.ts @@ -8,7 +8,7 @@ import * as _ from 'lodash'; async function getStatus(ctx: Router.IRouterContext) { - let analyticUnitId = ctx.request.query.id; + let analyticUnitId = ctx.request.query.id as string; if(analyticUnitId === undefined) { throw new Error('Cannot get status of undefined id'); } @@ -23,12 +23,14 @@ async function getStatus(ctx: Router.IRouterContext) { }; if(analyticUnit.status === AnalyticUnit.AnalyticUnitStatus.FAILED) { - ctx.response.body.errorMessage = analyticUnit.error; + ctx.response.body = { + errorMessage: analyticUnit.error + }; } } async function getUnits(ctx: Router.IRouterContext) { - const panelId = ctx.request.query.panelId; + const panelId = ctx.request.query.panelId as string; if(panelId === undefined) { throw new Error('Cannot get units of undefined panelId'); } @@ -118,7 +120,7 @@ async function updateAlert(ctx: Router.IRouterContext) { } async function deleteUnit(ctx: Router.IRouterContext) { - const analyticUnitId = ctx.request.query.id; + const analyticUnitId = ctx.request.query.id as string; if(analyticUnitId === undefined) { throw new Error('Cannot delete undefined id'); } diff --git a/server/src/routes/data_router.ts b/server/src/routes/data_router.ts index 0fb2586..73acc45 100644 --- a/server/src/routes/data_router.ts +++ b/server/src/routes/data_router.ts @@ -6,24 +6,24 @@ import * as Router from 'koa-router'; async function query(ctx: Router.IRouterContext) { - let from = ctx.request.query.from; - let to = ctx.request.query.to; - const analyticUnitId = ctx.request.query.analyticUnitId; + let queryFrom = ctx.request.query.from as string; + let queryTo = ctx.request.query.to as string; + const analyticUnitId = ctx.request.query.analyticUnitId as string; if(analyticUnitId === undefined) { throw new Error(`data router error: request must contain analyticUnitId`); } - if(from === undefined) { + if(queryFrom === undefined) { throw new Error(`data router error: request must contain 'from'`) } - if(to === undefined) { + if(queryTo === undefined) { throw new Error(`data router error: request must contain 'to'`) } - from = +from; - to = +to; + const from = +queryFrom; + const to = +queryTo; if(from === NaN) { throw new Error(`from must be not NaN`); diff --git a/server/src/routes/detections_router.ts b/server/src/routes/detections_router.ts index 05480a0..84ade36 100644 --- a/server/src/routes/detections_router.ts +++ b/server/src/routes/detections_router.ts @@ -10,7 +10,7 @@ declare type DetectionSpansResponse = { } export async function getDetectionSpans(ctx: Router.IRouterContext) { - let id: AnalyticUnitId = ctx.request.query.id; + const id = ctx.request.query.id as AnalyticUnitId; if(id === undefined || id === '') { throw new Error('analyticUnitId (id) is missing'); } diff --git a/server/src/routes/panel_router.ts b/server/src/routes/panel_router.ts index 68909b9..633601a 100644 --- a/server/src/routes/panel_router.ts +++ b/server/src/routes/panel_router.ts @@ -5,7 +5,7 @@ import * as Router from 'koa-router'; async function exportGrafanaPanelTemplate(ctx: Router.IRouterContext) { - let panelId = ctx.request.query.panelId; + const panelId = ctx.request.query.panelId as string; if(panelId === undefined) { throw new Error('Cannot export analytic units with undefined panelId'); } diff --git a/server/src/routes/segments_router.ts b/server/src/routes/segments_router.ts index d3e7110..6dc4a64 100644 --- a/server/src/routes/segments_router.ts +++ b/server/src/routes/segments_router.ts @@ -7,7 +7,7 @@ import * as Router from 'koa-router'; export async function getSegments(ctx: Router.IRouterContext) { - let id: AnalyticUnitId = ctx.request.query.id; + const id = ctx.request.query.id as AnalyticUnitId; if(id === undefined || id === '') { throw new Error('analyticUnitId (id) is missing'); } diff --git a/server/src/services/data_layer/nedb.ts b/server/src/services/data_layer/nedb.ts index cf4cbe6..d0572f7 100644 --- a/server/src/services/data_layer/nedb.ts +++ b/server/src/services/data_layer/nedb.ts @@ -36,7 +36,7 @@ export class NeDbQueryWrapper implements DbQueryWrapper { // https://github.com/louischatriot/nedb#updating-documents let nedbUpdateQuery = { $set: updateQuery } query = wrapIdToQuery(query); - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { nd.update( query, nedbUpdateQuery, diff --git a/server/src/services/json_service.ts b/server/src/services/json_service.ts index f51d1a2..9b49892 100644 --- a/server/src/services/json_service.ts +++ b/server/src/services/json_service.ts @@ -22,7 +22,7 @@ async function getJsonData(filename: string): Promise { } function writeJsonData(filename: string, data: Object) { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { fs.writeFile(filename, JSON.stringify(data), 'utf8', (err) => { if(err) { console.error(err); From ece873ade2a6bc6a0515e2e94c1899b52c812c17 Mon Sep 17 00:00:00 2001 From: rozetko Date: Thu, 27 May 2021 16:08:47 +0300 Subject: [PATCH 3/5] freeze mongodb version so that it doesn't depend on `mongodb-client-encryption` --- server/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/package.json b/server/package.json index 8653d59..bcc0266 100644 --- a/server/package.json +++ b/server/package.json @@ -48,7 +48,7 @@ "koa-bodyparser": "^4.2.0", "koa-router": "^7.0.31", "lodash": "^4.17.10", - "mongodb": "^3.3.2", + "mongodb": "3.3.2", "nedb": "^1.8.0", "node-loader": "^0.6.0", "nodemon": "^1.17.5", From e5017924c388c99d4018c9ab94dc2925e4235fbe Mon Sep 17 00:00:00 2001 From: rozetko Date: Thu, 27 May 2021 16:09:01 +0300 Subject: [PATCH 4/5] filter more build warnings --- server/build/webpack.base.conf.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/build/webpack.base.conf.js b/server/build/webpack.base.conf.js index 9a4d38a..5e52ee7 100644 --- a/server/build/webpack.base.conf.js +++ b/server/build/webpack.base.conf.js @@ -42,7 +42,8 @@ module.exports = { stats: { warningsFilter: [ 'mongodb-client-encryption', - 'saslprep', + /ws\/lib/, + /mongodb\/lib\/core/, /require_optional/ ] }, From 1654199048924452e4cd8218c9b3a216ff9c7ae7 Mon Sep 17 00:00:00 2001 From: rozetko Date: Thu, 27 May 2021 16:14:57 +0300 Subject: [PATCH 5/5] use proper id type in requests --- server/src/routes/detections_router.ts | 2 +- server/src/routes/segments_router.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/routes/detections_router.ts b/server/src/routes/detections_router.ts index 84ade36..0f6f53d 100644 --- a/server/src/routes/detections_router.ts +++ b/server/src/routes/detections_router.ts @@ -10,7 +10,7 @@ declare type DetectionSpansResponse = { } export async function getDetectionSpans(ctx: Router.IRouterContext) { - const id = ctx.request.query.id as AnalyticUnitId; + const id = ctx.request.query.id as string; if(id === undefined || id === '') { throw new Error('analyticUnitId (id) is missing'); } diff --git a/server/src/routes/segments_router.ts b/server/src/routes/segments_router.ts index 6dc4a64..79736d7 100644 --- a/server/src/routes/segments_router.ts +++ b/server/src/routes/segments_router.ts @@ -7,7 +7,7 @@ import * as Router from 'koa-router'; export async function getSegments(ctx: Router.IRouterContext) { - const id = ctx.request.query.id as AnalyticUnitId; + const id = ctx.request.query.id as string; if(id === undefined || id === '') { throw new Error('analyticUnitId (id) is missing'); }