Browse Source

strict any checks

pull/1/head
Coin de Gamma 6 years ago
parent
commit
590f3fdf76
  1. 2
      server/src/config.ts
  2. 2
      server/src/controllers/alerts_controller.ts
  3. 8
      server/src/controllers/analytics_controller.ts
  4. 2
      server/src/models/segment_model.ts
  5. 2
      server/src/routes/segments_router.ts
  6. 8
      server/src/services/analytics_service.ts
  7. 18
      server/src/services/data_service.ts
  8. 6
      server/src/services/notification_service.ts
  9. 6
      server/src/services/process_service.ts
  10. 4
      server/tsconfig.json

2
server/src/config.ts

@ -21,7 +21,7 @@ export const ZMQ_DEV_PORT = getConfigField('ZMQ_DEV_PORT', '8002');
export const ANLYTICS_PING_INTERVAL = 500; // ms export const ANLYTICS_PING_INTERVAL = 500; // ms
function getConfigField(field, defaultVal?) { function getConfigField(field: string, defaultVal?: any) {
let val = defaultVal; let val = defaultVal;
if(process.env[field] !== undefined) { if(process.env[field] !== undefined) {

2
server/src/controllers/alerts_controller.ts

@ -2,7 +2,7 @@
* Alarting is not supported yet * Alarting is not supported yet
*/ */
throw new console.error("Not supported"); throw new Error('not supported');
// import { runPredict } from './analytics_controller'; // import { runPredict } from './analytics_controller';

8
server/src/controllers/analytics_controller.ts

@ -3,7 +3,7 @@ import * as AnalyticUnit from '../models/analytic_unit_model'
import { AnalyticsService, AnalyticsMessage } from '../services/analytics_service'; import { AnalyticsService, AnalyticsMessage } from '../services/analytics_service';
const taskMap = {}; const taskMap = new Map<string, any>();
let nextTaskId = 0; let nextTaskId = 0;
let analyticsService: AnalyticsService = undefined; let analyticsService: AnalyticsService = undefined;
@ -14,9 +14,9 @@ function onTaskResult(taskResult: any) {
let status = taskResult.status; let status = taskResult.status;
if(status === 'SUCCESS' || status === 'FAILED') { if(status === 'SUCCESS' || status === 'FAILED') {
if(taskId in taskMap) { if(taskId in taskMap) {
let resolver = taskMap[taskId]; let resolver: any = taskMap.get(taskId);
resolver(taskResult); resolver(taskResult);
delete taskMap[taskId]; taskMap.delete(taskId);
} }
} }
} }
@ -49,7 +49,7 @@ export function terminate() {
analyticsService.close(); analyticsService.close();
} }
async function runTask(task): Promise<any> { async function runTask(task: any): Promise<any> {
// let anomaly: AnalyticUnit.AnalyticUnit = await AnalyticUnit.findById(task.analyticUnitId); // let anomaly: AnalyticUnit.AnalyticUnit = await AnalyticUnit.findById(task.analyticUnitId);
// task.metric = { // task.metric = {
// datasource: anomaly.metric.datasource, // datasource: anomaly.metric.datasource,

2
server/src/models/segment_model.ts

@ -68,7 +68,7 @@ export async function findMany(id: AnalyticUnitId, query: FindManyQuery): Promis
return segs.map(Segment.fromObject); return segs.map(Segment.fromObject);
} }
export async function insertSegments(id: AnalyticUnitId, segments: Segment[]) { export async function insertSegments(segments: Segment[]) {
return db.insertMany(segments.map(s => s.toObject())); return db.insertMany(segments.map(s => s.toObject()));
} }

2
server/src/routes/segments_router.ts

@ -27,7 +27,7 @@ async function updateSegments(ctx: Router.IRouterContext) {
try { try {
let segmentsUpdate = ctx.request.body; let segmentsUpdate = ctx.request.body;
let id = segmentsUpdate.id; let id = segmentsUpdate.id;
let addedIds = insertSegments(id, segmentsUpdate.addedSegments); let addedIds = insertSegments(segmentsUpdate.addedSegments);
// removeSegments(id, segmentsUpdate.removedSegments); // removeSegments(id, segmentsUpdate.removedSegments);
ctx.response.body = { addedIds }; ctx.response.body = { addedIds };
runLearning(id); runLearning(id);

8
server/src/services/analytics_service.ts

@ -29,8 +29,8 @@ export class AnalyticsService {
private _requester: any; private _requester: any;
private _ready: boolean = false; private _ready: boolean = false;
private _pingResponded = false; private _pingResponded = false;
private _zmqConnectionString = null; private _zmqConnectionString: string = null;
private _ipcPath = null; private _ipcPath: string = null;
private _analyticsPinger: NodeJS.Timer = null; private _analyticsPinger: NodeJS.Timer = null;
private _isClosed = false; private _isClosed = false;
@ -55,7 +55,7 @@ export class AnalyticsService {
strMessage = 'PING'; strMessage = 'PING';
} }
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
this._requester.send(strMessage, undefined, (err) => { this._requester.send(strMessage, undefined, (err: any) => {
if(err) { if(err) {
reject(err); reject(err);
} else { } else {
@ -184,7 +184,7 @@ export class AnalyticsService {
} }
} }
private _onAnalyticsMessage(data: any, error) { private _onAnalyticsMessage(data: any) {
if(data.toString() === 'PONG') { if(data.toString() === 'PONG') {
this._pingResponded = true; this._pingResponded = true;
if(!this._ready) { if(!this._ready) {

18
server/src/services/data_service.ts

@ -52,7 +52,7 @@ const db = new Map<Collection, nedb>();
let dbInsertOne = (collection: Collection, doc: object) => { let dbInsertOne = (collection: Collection, doc: object) => {
return new Promise<string>((resolve, reject) => { return new Promise<string>((resolve, reject) => {
db[collection].insert(doc, (err, newDoc) => { db.get(collection).insert(doc, (err, newDoc: any) => {
if(err) { if(err) {
reject(err); reject(err);
} else { } else {
@ -64,7 +64,7 @@ let dbInsertOne = (collection: Collection, doc: object) => {
let dbInsertMany = (collection: Collection, docs: object[]) => { let dbInsertMany = (collection: Collection, docs: object[]) => {
return new Promise<string[]>((resolve, reject) => { return new Promise<string[]>((resolve, reject) => {
db[collection].insert(docs, (err, newDocs: any[]) => { db.get(collection).insert(docs, (err, newDocs: any[]) => {
if(err) { if(err) {
reject(err); reject(err);
} else { } else {
@ -77,7 +77,7 @@ let dbInsertMany = (collection: Collection, docs: object[]) => {
let dbUpdateOne = (collection: Collection, query: string | object, updateQuery: object) => { let dbUpdateOne = (collection: Collection, query: string | object, updateQuery: object) => {
query = wrapIdToQuery(query); query = wrapIdToQuery(query);
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
db[collection].update(query, updateQuery, { /* options */ }, (err: Error) => { db.get(collection).update(query, updateQuery, { /* options */ }, (err: Error) => {
if(err) { if(err) {
reject(err); reject(err);
} else { } else {
@ -90,7 +90,7 @@ let dbUpdateOne = (collection: Collection, query: string | object, updateQuery:
let dbFindOne = (collection: Collection, query: string | object) => { let dbFindOne = (collection: Collection, query: string | object) => {
query = wrapIdToQuery(query); query = wrapIdToQuery(query);
return new Promise<any>((resolve, reject) => { return new Promise<any>((resolve, reject) => {
db[collection].findOne(query, (err, doc) => { db.get(collection).findOne(query, (err, doc) => {
if(err) { if(err) {
reject(err); reject(err);
} else { } else {
@ -103,7 +103,7 @@ let dbFindOne = (collection: Collection, query: string | object) => {
let dbFindMany = (collection: Collection, query: string[] | object) => { let dbFindMany = (collection: Collection, query: string[] | object) => {
query = wrapIdsToQuery(query); query = wrapIdsToQuery(query);
return new Promise<any[]>((resolve, reject) => { return new Promise<any[]>((resolve, reject) => {
db[collection].findOne(query, (err, docs) => { db.get(collection).findOne(query, (err, docs: any[]) => {
if(err) { if(err) {
reject(err); reject(err);
} else { } else {
@ -116,7 +116,7 @@ let dbFindMany = (collection: Collection, query: string[] | object) => {
let dbRemoveOne = (collection: Collection, id: string) => { let dbRemoveOne = (collection: Collection, id: string) => {
let query = { _id: id }; let query = { _id: id };
return new Promise<boolean>((resolve, reject) => { return new Promise<boolean>((resolve, reject) => {
db[collection].remove(query, (err, numRemoved) => { db.get(collection).remove(query, (err, numRemoved) => {
if(err) { if(err) {
reject(err); reject(err);
} else { } else {
@ -133,7 +133,7 @@ let dbRemoveOne = (collection: Collection, id: string) => {
let dbRemoveMany = (collection: Collection, query: string[] | object) => { let dbRemoveMany = (collection: Collection, query: string[] | object) => {
query = wrapIdsToQuery(query); query = wrapIdsToQuery(query);
return new Promise<number>((resolve, reject) => { return new Promise<number>((resolve, reject) => {
db[collection].remove(query, (err, numRemoved) => { db.get(collection).remove(query, (err, numRemoved) => {
if(err) { if(err) {
reject(err); reject(err);
} else { } else {
@ -161,5 +161,5 @@ function checkDataFolders(): void {
checkDataFolders(); checkDataFolders();
// TODO: it's better if models request db which we create if it`s needed // TODO: it's better if models request db which we create if it`s needed
db[Collection.ANALYTIC_UNITS] = new nedb({ filename: config.ANALYTIC_UNITS_DATABASE_PATH, autoload: true }); db.set(Collection.ANALYTIC_UNITS, new nedb({ filename: config.ANALYTIC_UNITS_DATABASE_PATH, autoload: true }));
db[Collection.SEGMENTS] = new nedb({ filename: config.SEGMENTS_DATABASE_PATH, autoload: true }); db.set(Collection.SEGMENTS, new nedb({ filename: config.SEGMENTS_DATABASE_PATH, autoload: true }));

6
server/src/services/notification_service.ts

@ -1,11 +1,11 @@
import { findById } from '../models/analytic_unit_model'; import { findById, AnalyticUnitId } from '../models/analytic_unit_model';
import axios from 'axios'; import axios from 'axios';
// TODO: send notification with payload without dep to AnalyticUnit // TODO: send notification with payload without dep to AnalyticUnit
export async function sendNotification(predictorId, active) { export async function sendNotification(id: AnalyticUnitId, active: boolean) {
let anomalyName = (await findById(predictorId)).name let anomalyName = (await findById(id)).name
console.log('Notification ' + anomalyName); console.log('Notification ' + anomalyName);
let notification = { let notification = {

6
server/src/services/process_service.ts

@ -1,6 +1,6 @@
var exitHandlers = [] var exitHandlers: (() => void)[] = [];
var exitHandled = false; var exitHandled = false;
/** /**
@ -12,7 +12,7 @@ export function registerExitHandler(callback: () => void) {
exitHandlers.push(callback); exitHandlers.push(callback);
} }
function exitHandler(options, err?) { function exitHandler(options: any, err?: any) {
if(exitHandled) { if(exitHandled) {
return; return;
} }
@ -24,7 +24,7 @@ function exitHandler(options, err?) {
process.exit(); process.exit();
} }
function catchException(options, err) { function catchException(options: any, err: any) {
console.log('Server exception:'); console.log('Server exception:');
console.log(err); console.log(err);
exitHandler({ exit: true }); exitHandler({ exit: true });

4
server/tsconfig.json

@ -1,9 +1,9 @@
{ {
"compilerOptions": { "compilerOptions": {
"sourceMap": true, "sourceMap": true,
"noImplicitAny": false, "noImplicitAny": true,
"module": "commonjs", "module": "commonjs",
"target": "es6", "target": "es6",
"allowJs": true "allowJs": true,
} }
} }

Loading…
Cancel
Save