Skip to content

Commit 60b88a5

Browse files
committed
Copy dateAsStringRt to observability plugin (elastic#82839)
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 elastic#80508.
1 parent a79c57e commit 60b88a5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

x-pack/plugins/observability/common/annotations.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@
55
*/
66

77
import * as t from 'io-ts';
8-
import { dateAsStringRt } from '../../apm/common/runtime_types/date_as_string_rt';
8+
import { either } from 'fp-ts/lib/Either';
9+
10+
/**
11+
* Checks whether a string is a valid ISO timestamp,
12+
* but doesn't convert it into a Date object when decoding.
13+
*
14+
* Copied from x-pack/plugins/apm/common/runtime_types/date_as_string_rt.ts.
15+
*/
16+
const dateAsStringRt = new t.Type<string, string, unknown>(
17+
'DateAsString',
18+
t.string.is,
19+
(input, context) =>
20+
either.chain(t.string.validate(input, context), (str) => {
21+
const date = new Date(str);
22+
return isNaN(date.getTime()) ? t.failure(input, context) : t.success(str);
23+
}),
24+
t.identity
25+
);
926

1027
export const createAnnotationRt = t.intersection([
1128
t.type({

0 commit comments

Comments
 (0)