Skip to content

Commit

Permalink
Copy dateAsStringRt to observability plugin
Browse files Browse the repository at this point in the history
Observability was importing `dateAsStringRt` from APM, which creates an implicit circular dependency between the two plugins.

Copy that function into where it was being used in observability to remove the dependency.

Related to #80508.
  • Loading branch information
smith committed Nov 6, 2020
1 parent 71ec5bd commit c504cca
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion x-pack/plugins/observability/common/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@
*/

import * as t from 'io-ts';
import { dateAsStringRt } from '../../apm/common/runtime_types/date_as_string_rt';
import { either } from 'fp-ts/lib/Either';

/**
* Checks whether a string is a valid ISO timestamp,
* but doesn't convert it into a Date object when decoding.
*
* Copied from x-pack/plugins/apm/common/runtime_types/date_as_string_rt.ts.
*/
const dateAsStringRt = new t.Type<string, string, unknown>(
'DateAsString',
t.string.is,
(input, context) =>
either.chain(t.string.validate(input, context), (str) => {
const date = new Date(str);
return isNaN(date.getTime()) ? t.failure(input, context) : t.success(str);
}),
t.identity
);

export const createAnnotationRt = t.intersection([
t.type({
Expand Down

0 comments on commit c504cca

Please sign in to comment.