Browse Source

Remove serialized types (#857)

pull/1/head
Alexander Velikiy 5 years ago committed by GitHub
parent
commit
5c500c02a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      server/src/models/analytic_unit_cache_model.ts
  2. 9
      server/src/models/analytic_units/analytic_unit_model.ts
  3. 4
      server/src/models/analytic_units/db.ts
  4. 4
      server/src/models/analytic_units/index.ts
  5. 24
      server/src/models/analytic_units/types.ts
  6. 1
      server/src/models/detection_model.ts
  7. 2
      server/src/models/panel_model.ts
  8. 1
      server/src/models/segment_model.ts
  9. 7
      server/src/types.ts

1
server/src/models/analytic_unit_cache_model.ts

@ -82,7 +82,6 @@ export async function create(id: AnalyticUnitId): Promise<AnalyticUnitId> {
return db.insertOne(cache.toObject()); return db.insertOne(cache.toObject());
} }
// TODO: SerializedCache type
export async function insertMany(caches: any[]): Promise<AnalyticUnitId[]> { export async function insertMany(caches: any[]): Promise<AnalyticUnitId[]> {
return db.insertMany(caches); return db.insertMany(caches);
} }

9
server/src/models/analytic_units/analytic_unit_model.ts

@ -1,6 +1,5 @@
import { import {
AnalyticUnitId, AnalyticUnitStatus, DetectorType, AnalyticUnitId, AnalyticUnitStatus, DetectorType
SerializedAnalyticUnit, SerializedPanelAnalyticUnit
} from './types'; } from './types';
import { Metric } from 'grafana-datasource-kit'; import { Metric } from 'grafana-datasource-kit';
@ -43,7 +42,7 @@ export abstract class AnalyticUnit {
} }
} }
public toObject(): SerializedAnalyticUnit { public toObject(): any {
let metric; let metric;
if(this.metric !== undefined) { if(this.metric !== undefined) {
metric = this.metric.toObject(); metric = this.metric.toObject();
@ -68,7 +67,7 @@ export abstract class AnalyticUnit {
}; };
} }
public toPanelObject(): SerializedPanelAnalyticUnit { public toPanelObject(): any {
return { return {
id: this.id, id: this.id,
name: this.name, name: this.name,
@ -82,7 +81,7 @@ export abstract class AnalyticUnit {
}; };
} }
public toTemplate(): SerializedAnalyticUnit { public toTemplate(): any {
const obj = _.cloneDeep(this.toObject()); const obj = _.cloneDeep(this.toObject());
obj.grafanaUrl = '${GRAFANA_URL}'; obj.grafanaUrl = '${GRAFANA_URL}';

4
server/src/models/analytic_units/db.ts

@ -1,6 +1,6 @@
import { createAnalyticUnitFromObject } from './utils'; import { createAnalyticUnitFromObject } from './utils';
import { AnalyticUnit } from './analytic_unit_model'; import { AnalyticUnit } from './analytic_unit_model';
import { AnalyticUnitId, FindManyQuery, SerializedAnalyticUnit } from './types'; import { AnalyticUnitId, FindManyQuery } from './types';
import { Collection, makeDBQ, SortingOrder } from '../../services/data_service'; import { Collection, makeDBQ, SortingOrder } from '../../services/data_service';
import { Metric } from 'grafana-datasource-kit'; import { Metric } from 'grafana-datasource-kit';
@ -41,7 +41,7 @@ export async function create(unit: AnalyticUnit): Promise<AnalyticUnitId> {
return db.insertOne(obj); return db.insertOne(obj);
} }
export async function insertMany(analyticUnits: SerializedAnalyticUnit[]): Promise<AnalyticUnitId[]> { export async function insertMany(analyticUnits: any[]): Promise<AnalyticUnitId[]> {
return db.insertMany(analyticUnits); return db.insertMany(analyticUnits);
} }

4
server/src/models/analytic_units/index.ts

@ -1,7 +1,6 @@
import { createAnalyticUnitFromObject } from './utils'; import { createAnalyticUnitFromObject } from './utils';
import { import {
AnalyticUnitId, AnalyticUnitStatus, DetectorType, ANALYTIC_UNIT_TYPES, AnalyticUnitId, AnalyticUnitStatus, DetectorType, ANALYTIC_UNIT_TYPES
SerializedAnalyticUnit, SerializedPanelAnalyticUnit
} from './types'; } from './types';
import { AnalyticUnit } from './analytic_unit_model'; import { AnalyticUnit } from './analytic_unit_model';
import { PatternAnalyticUnit } from './pattern_analytic_unit_model'; import { PatternAnalyticUnit } from './pattern_analytic_unit_model';
@ -23,7 +22,6 @@ import {
export { export {
AnalyticUnit, PatternAnalyticUnit, ThresholdAnalyticUnit, AnomalyAnalyticUnit, AnalyticUnit, PatternAnalyticUnit, ThresholdAnalyticUnit, AnomalyAnalyticUnit,
SerializedAnalyticUnit, SerializedPanelAnalyticUnit,
AnalyticUnitId, AnalyticUnitStatus, Bound, DetectorType, ANALYTIC_UNIT_TYPES, AnalyticUnitId, AnalyticUnitStatus, Bound, DetectorType, ANALYTIC_UNIT_TYPES,
createAnalyticUnitFromObject, Condition, createAnalyticUnitFromObject, Condition,
findById, findMany, findById, findMany,

24
server/src/models/analytic_units/types.ts

@ -1,5 +1,3 @@
import { Omit } from '../../types';
import { Metric } from 'grafana-datasource-kit'; import { Metric } from 'grafana-datasource-kit';
@ -73,25 +71,3 @@ export enum DetectorType {
ANOMALY = 'anomaly', ANOMALY = 'anomaly',
THRESHOLD = 'threshold' THRESHOLD = 'threshold'
}; };
export type SerializedPanelAnalyticUnit = {
id: AnalyticUnitId;
name: string;
type: string;
alert: boolean;
labeledColor?: string;
deletedColor?: string;
detectorType?: DetectorType;
visible?: boolean;
collapsed?: boolean;
}
export type SerializedAnalyticUnit = Omit<SerializedPanelAnalyticUnit, 'id'> & {
grafanaUrl: string;
panelId: string;
metric?: Metric;
_id?: AnalyticUnitId;
lastDetectionTime?: number;
status?: AnalyticUnitStatus;
error?: string;
}

1
server/src/models/detection_model.ts

@ -162,7 +162,6 @@ export async function insertSpan(span: DetectionSpan): Promise<SpanId> {
return db.insertOne(spanToInsert); return db.insertOne(spanToInsert);
} }
// TODO: SerializedDetectionSpan type
export async function insertMany(detectionSpans: any[]): Promise<SpanId[]> { export async function insertMany(detectionSpans: any[]): Promise<SpanId[]> {
return db.insertMany(detectionSpans); return db.insertMany(detectionSpans);
} }

2
server/src/models/panel_model.ts

@ -4,7 +4,7 @@ import * as DetectionSpan from '../models/detection_model';
import * as Segment from '../models/segment_model'; import * as Segment from '../models/segment_model';
export type PanelTemplate = { export type PanelTemplate = {
analyticUnits: AnalyticUnit.SerializedAnalyticUnit[], analyticUnits: AnalyticUnit.AnalyticUnit[],
caches: AnalyticUnitCache.AnalyticUnitCache[], caches: AnalyticUnitCache.AnalyticUnitCache[],
detectionSpans: DetectionSpan.DetectionSpan[], detectionSpans: DetectionSpan.DetectionSpan[],
segments: Segment.Segment[] segments: Segment.Segment[]

1
server/src/models/segment_model.ts

@ -232,7 +232,6 @@ export async function mergeAndInsertSegments(segments: Segment[]): Promise<{
}; };
} }
// TODO: SerializedSegment type
export async function insertMany(segments: any[]): Promise<SegmentId[]> { export async function insertMany(segments: any[]): Promise<SegmentId[]> {
return db.insertMany(segments); return db.insertMany(segments);
} }

7
server/src/types.ts

@ -1,7 +0,0 @@
// We should remove Omit definition when we'll be updating TypeScript
// It was introduced in TS v3.5.1:
// https://devblogs.microsoft.com/typescript/announcing-typescript-3-5/#the-omit-helper-type
/**
* Construct a type with the properties of T except for those in type K.
*/
export type Omit<T, K extends string | number | symbol> = { [P in Exclude<keyof T, K>]: T[P]; }
Loading…
Cancel
Save