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
function getConfigField(field, defaultVal?) {
function getConfigField(field: string, defaultVal?: any) {
let val = defaultVal;
if(process.env[field] !== undefined) {

2
server/src/controllers/alerts_controller.ts

@ -2,7 +2,7 @@
* Alarting is not supported yet
*/
throw new console.error("Not supported");
throw new Error('not supported');
// 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';
const taskMap = {};
const taskMap = new Map<string, any>();
let nextTaskId = 0;
let analyticsService: AnalyticsService = undefined;
@ -14,9 +14,9 @@ function onTaskResult(taskResult: any) {
let status = taskResult.status;
if(status === 'SUCCESS' || status === 'FAILED') {
if(taskId in taskMap) {
let resolver = taskMap[taskId];
let resolver: any = taskMap.get(taskId);
resolver(taskResult);
delete taskMap[taskId];
taskMap.delete(taskId);
}
}
}
@ -49,7 +49,7 @@ export function terminate() {
analyticsService.close();
}
async function runTask(task): Promise<any> {
async function runTask(task: any): Promise<any> {
// let anomaly: AnalyticUnit.AnalyticUnit = await AnalyticUnit.findById(task.analyticUnitId);
// task.metric = {
// 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);
}
export async function insertSegments(id: AnalyticUnitId, segments: Segment[]) {
export async function insertSegments(segments: Segment[]) {
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 {
let segmentsUpdate = ctx.request.body;
let id = segmentsUpdate.id;
let addedIds = insertSegments(id, segmentsUpdate.addedSegments);
let addedIds = insertSegments(segmentsUpdate.addedSegments);
// removeSegments(id, segmentsUpdate.removedSegments);
ctx.response.body = { addedIds };
runLearning(id);

8
server/src/services/analytics_service.ts

@ -29,8 +29,8 @@ export class AnalyticsService {
private _requester: any;
private _ready: boolean = false;
private _pingResponded = false;
private _zmqConnectionString = null;
private _ipcPath = null;
private _zmqConnectionString: string = null;
private _ipcPath: string = null;
private _analyticsPinger: NodeJS.Timer = null;
private _isClosed = false;
@ -55,7 +55,7 @@ export class AnalyticsService {
strMessage = 'PING';
}
return new Promise<void>((resolve, reject) => {
this._requester.send(strMessage, undefined, (err) => {
this._requester.send(strMessage, undefined, (err: any) => {
if(err) {
reject(err);
} else {
@ -184,7 +184,7 @@ export class AnalyticsService {
}
}
private _onAnalyticsMessage(data: any, error) {
private _onAnalyticsMessage(data: any) {
if(data.toString() === 'PONG') {
this._pingResponded = true;
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) => {
return new Promise<string>((resolve, reject) => {
db[collection].insert(doc, (err, newDoc) => {
db.get(collection).insert(doc, (err, newDoc: any) => {
if(err) {
reject(err);
} else {
@ -64,7 +64,7 @@ let dbInsertOne = (collection: Collection, doc: object) => {
let dbInsertMany = (collection: Collection, docs: object[]) => {
return new Promise<string[]>((resolve, reject) => {
db[collection].insert(docs, (err, newDocs: any[]) => {
db.get(collection).insert(docs, (err, newDocs: any[]) => {
if(err) {
reject(err);
} else {
@ -77,7 +77,7 @@ let dbInsertMany = (collection: Collection, docs: object[]) => {
let dbUpdateOne = (collection: Collection, query: string | object, updateQuery: object) => {
query = wrapIdToQuery(query);
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) {
reject(err);
} else {
@ -90,7 +90,7 @@ let dbUpdateOne = (collection: Collection, query: string | object, updateQuery:
let dbFindOne = (collection: Collection, query: string | object) => {
query = wrapIdToQuery(query);
return new Promise<any>((resolve, reject) => {
db[collection].findOne(query, (err, doc) => {
db.get(collection).findOne(query, (err, doc) => {
if(err) {
reject(err);
} else {
@ -103,7 +103,7 @@ let dbFindOne = (collection: Collection, query: string | object) => {
let dbFindMany = (collection: Collection, query: string[] | object) => {
query = wrapIdsToQuery(query);
return new Promise<any[]>((resolve, reject) => {
db[collection].findOne(query, (err, docs) => {
db.get(collection).findOne(query, (err, docs: any[]) => {
if(err) {
reject(err);
} else {
@ -116,7 +116,7 @@ let dbFindMany = (collection: Collection, query: string[] | object) => {
let dbRemoveOne = (collection: Collection, id: string) => {
let query = { _id: id };
return new Promise<boolean>((resolve, reject) => {
db[collection].remove(query, (err, numRemoved) => {
db.get(collection).remove(query, (err, numRemoved) => {
if(err) {
reject(err);
} else {
@ -133,7 +133,7 @@ let dbRemoveOne = (collection: Collection, id: string) => {
let dbRemoveMany = (collection: Collection, query: string[] | object) => {
query = wrapIdsToQuery(query);
return new Promise<number>((resolve, reject) => {
db[collection].remove(query, (err, numRemoved) => {
db.get(collection).remove(query, (err, numRemoved) => {
if(err) {
reject(err);
} else {
@ -161,5 +161,5 @@ function checkDataFolders(): void {
checkDataFolders();
// 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[Collection.SEGMENTS] = new nedb({ filename: config.SEGMENTS_DATABASE_PATH, autoload: true });
db.set(Collection.ANALYTIC_UNITS, new nedb({ filename: config.ANALYTIC_UNITS_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';
// TODO: send notification with payload without dep to AnalyticUnit
export async function sendNotification(predictorId, active) {
let anomalyName = (await findById(predictorId)).name
export async function sendNotification(id: AnalyticUnitId, active: boolean) {
let anomalyName = (await findById(id)).name
console.log('Notification ' + anomalyName);
let notification = {

6
server/src/services/process_service.ts

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

4
server/tsconfig.json

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

Loading…
Cancel
Save