* Changed alerting API endpoints urls, bodies and params to follow Kibana STYLEGUIDE * Changed alerting REST API to keep the pattern 'alerts/alert/{id}' * fixed tests * fixed tests * Fixed jest tests * Renamed plugin from alerting to alerts * fixed tests * fixed tests * Fixed alert type check error * Fixed find api * fixed type checks * fixed tests security issues * Fixed view in app * - Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
27 lines
885 B
TypeScript
27 lines
885 B
TypeScript
/*
|
|
* 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()
|
|
);
|