Skip to content

Commit

Permalink
move types to common/types.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
peluja1012 committed Jan 27, 2020
1 parent 919e304 commit 1063eda
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 60 deletions.
52 changes: 52 additions & 0 deletions x-pack/plugins/endpoint/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
* you may not use this file except in compliance with the Elastic License.
*/

/**
* A deep readonly type that will make all children of a given object readonly recursively
*/
export type Immutable<T> = T extends undefined | null | boolean | string | number
? T
: T extends Array<infer U>
? ImmutableArray<U>
: T extends Map<infer K, infer V>
? ImmutableMap<K, V>
: T extends Set<infer M>
? ImmutableSet<M>
: ImmutableObject<T>;

export type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
export type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
export type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
export type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };

export class EndpointAppConstants {
static ENDPOINT_INDEX_NAME = 'endpoint-agent*';
}
Expand Down Expand Up @@ -44,3 +62,37 @@ export interface EndpointMetadata {
};
};
}

export type AlertData = Immutable<{
value: {
source: {
endgame: {
data: {
file_operation: string;
malware_classification: {
score: number;
};
};
metadata: {
key: string;
};
timestamp_utc: Date;
};
labels: {
endpoint_id: string;
};
host: {
hostname: string;
ip: string;
os: {
name: string;
};
};
};
};
}>;

/**
* The PageId type is used for the payload when firing userNavigatedToPage actions
*/
export type PageId = 'alertsPage' | 'endpointListPage';
54 changes: 0 additions & 54 deletions x-pack/plugins/endpoint/endpoint_app_types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AlertData } from '../../../../../endpoint_app_types';
import { AlertData } from '../../../../../common/types';

interface ServerReturnedAlertsData {
readonly type: 'serverReturnedAlertsData';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { Dispatch, MiddlewareAPI } from 'redux';
import { CoreStart } from 'kibana/public';
import { AlertData } from '../../../../../endpoint_app_types';
import { AlertData } from '../../../../../common/types';
import { GlobalState } from '../reducer';
import { AppAction } from '../action';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AlertData, Immutable } from '../../../../../endpoint_app_types';
import { Immutable, AlertData } from '../../../../../common/types';

export type AlertListState = Immutable<{
alerts: AlertData[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PageId } from '../../../../../endpoint_app_types';
import { PageId } from '../../../../../common/types';

interface UserNavigatedToPage {
readonly type: 'userNavigatedToPage';

readonly payload: PageId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { PageId } from '../../../../endpoint_app_types';
import { PageId } from '../../../../common/types';
import { RoutingAction } from '../store/routing';

/**
Expand Down

0 comments on commit 1063eda

Please sign in to comment.