-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Enables access to the Alert State, which allows us to see which current Alert Instances are active. This includes: 1. Addition of a `get` api on Task Manager 2. Typing and validation on Serialisation & Deserialisation of the State of an Alert's underlying Task 3. Addition of the `getAlertState` api on AlertsClient
- Loading branch information
Showing
33 changed files
with
958 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { DateFromString } from './types'; | ||
import { right, isLeft } from 'fp-ts/lib/Either'; | ||
|
||
describe('DateFromString', () => { | ||
test('validated and parses a string into a Date', () => { | ||
const date = new Date(1973, 10, 30); | ||
expect(DateFromString.decode(date.toISOString())).toEqual(right(date)); | ||
}); | ||
|
||
test('validated and returns a failure for an actual Date', () => { | ||
const date = new Date(1973, 10, 30); | ||
expect(isLeft(DateFromString.decode(date))).toEqual(true); | ||
}); | ||
|
||
test('validated and returns a failure for an invalid Date string', () => { | ||
expect(isLeft(DateFromString.decode('1234-23-45'))).toEqual(true); | ||
}); | ||
|
||
test('validated and returns a failure for a null value', () => { | ||
expect(isLeft(DateFromString.decode(null))).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import * as t from 'io-ts'; | ||
import { either } from 'fp-ts/lib/Either'; | ||
// represents a Date from an ISO string | ||
export const DateFromString = new t.Type<Date, string, unknown>( | ||
'DateFromString', | ||
// detect the type | ||
(value): value is Date => value instanceof Date, | ||
(valueToDecode, context) => | ||
either.chain( | ||
// validate this is a string | ||
t.string.validate(valueToDecode, context), | ||
// decode | ||
value => { | ||
const decoded = new Date(value); | ||
return isNaN(decoded.getTime()) ? t.failure(valueToDecode, context) : t.success(decoded); | ||
} | ||
), | ||
valueToEncode => valueToEncode.toISOString() | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.