-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SecuritySolution] Decouple more timeline saved objects types from th…
…eir API representations (#159398) ## Summary Continuation of #158566. Tracked in elastic/security-team#6479. In this PR we're separating the types for the `Note` and `PinnedEvent` saved object and the type of it's API response equivalent. Doing so will allow us to make changes to either representations individually which is necessary for versioning the SO and routes (individually) in the future. The saved object definition and their representative API equivalent now live in `*/saved_object.ts` and `*/api.ts` respectively. A clean cut of these two, now distinct types. You will encounter some duplication of types in these files which is unavoidable. In the future, depending on how both representations evolve when versioned, these two definitions will diverge. You will notice that only few types (and values) defined in `saved_object.ts` are exported. They are only used for the conversion logic. They are not exported so they're not accidentally required by frontend or server code that is not dealing with the conversion. The exported types all start with `SavedObject*` to clearly mark them as SO representations. The conversion files have been updated to use the new representations and there is no implicit conversion between them (e.g. through spreading or rest parameters). The bulk of the changes are updates of import statements to change the import to `**/api.ts`. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
1 parent
160fa42
commit 0c4906a
Showing
30 changed files
with
420 additions
and
378 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
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/security_solution/common/types/timeline/note/api.ts
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,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
|
||
import * as runtimeTypes from 'io-ts'; | ||
import type { Maybe } from '../../../search_strategy/common'; | ||
|
||
import { unionWithNullType } from '../../../utility_types'; | ||
|
||
export const BareNoteSchema = runtimeTypes.intersection([ | ||
runtimeTypes.type({ | ||
timelineId: unionWithNullType(runtimeTypes.string), | ||
}), | ||
runtimeTypes.partial({ | ||
eventId: unionWithNullType(runtimeTypes.string), | ||
note: unionWithNullType(runtimeTypes.string), | ||
created: unionWithNullType(runtimeTypes.number), | ||
createdBy: unionWithNullType(runtimeTypes.string), | ||
updated: unionWithNullType(runtimeTypes.number), | ||
updatedBy: unionWithNullType(runtimeTypes.string), | ||
}), | ||
]); | ||
|
||
export interface BareNote extends runtimeTypes.TypeOf<typeof BareNoteSchema> {} | ||
|
||
/** | ||
* This type represents a note type stored in a saved object that does not include any fields that reference | ||
* other saved objects. | ||
*/ | ||
export type BareNoteWithoutExternalRefs = Omit<BareNote, 'timelineId'>; | ||
|
||
export const NoteRuntimeType = runtimeTypes.intersection([ | ||
BareNoteSchema, | ||
runtimeTypes.type({ | ||
noteId: runtimeTypes.string, | ||
version: runtimeTypes.string, | ||
}), | ||
runtimeTypes.partial({ | ||
timelineVersion: unionWithNullType(runtimeTypes.string), | ||
}), | ||
]); | ||
|
||
export interface Note extends runtimeTypes.TypeOf<typeof NoteRuntimeType> {} | ||
|
||
export interface ResponseNote { | ||
code?: Maybe<number>; | ||
|
||
message?: Maybe<string>; | ||
|
||
note: Note; | ||
} |
150 changes: 0 additions & 150 deletions
150
x-pack/plugins/security_solution/common/types/timeline/note/index.ts
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/security_solution/common/types/timeline/note/saved_object.ts
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,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
|
||
import * as runtimeTypes from 'io-ts'; | ||
|
||
import { unionWithNullType } from '../../../utility_types'; | ||
|
||
/* | ||
* Note Types | ||
*/ | ||
const SavedNoteRuntimeType = runtimeTypes.intersection([ | ||
runtimeTypes.type({ | ||
timelineId: unionWithNullType(runtimeTypes.string), | ||
}), | ||
runtimeTypes.partial({ | ||
eventId: unionWithNullType(runtimeTypes.string), | ||
note: unionWithNullType(runtimeTypes.string), | ||
created: unionWithNullType(runtimeTypes.number), | ||
createdBy: unionWithNullType(runtimeTypes.string), | ||
updated: unionWithNullType(runtimeTypes.number), | ||
updatedBy: unionWithNullType(runtimeTypes.string), | ||
}), | ||
]); | ||
|
||
/** | ||
* Note Saved object type with metadata | ||
*/ | ||
export const SavedObjectNoteRuntimeType = runtimeTypes.intersection([ | ||
runtimeTypes.type({ | ||
id: runtimeTypes.string, | ||
attributes: SavedNoteRuntimeType, | ||
version: runtimeTypes.string, | ||
}), | ||
runtimeTypes.partial({ | ||
noteId: runtimeTypes.string, | ||
timelineVersion: runtimeTypes.union([ | ||
runtimeTypes.string, | ||
runtimeTypes.null, | ||
runtimeTypes.undefined, | ||
]), | ||
}), | ||
]); | ||
|
||
interface SavedObjectNote extends runtimeTypes.TypeOf<typeof SavedNoteRuntimeType> {} | ||
|
||
/** | ||
* This type represents a note type stored in a saved object that does not include any fields that reference | ||
* other saved objects. | ||
*/ | ||
export type SavedObjectNoteWithoutExternalRefs = Omit<SavedObjectNote, 'timelineId'>; |
51 changes: 51 additions & 0 deletions
51
x-pack/plugins/security_solution/common/types/timeline/pinned_event/api.ts
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,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
/* eslint-disable @typescript-eslint/no-empty-interface */ | ||
|
||
import * as runtimeTypes from 'io-ts'; | ||
|
||
import { unionWithNullType } from '../../../utility_types'; | ||
|
||
/* | ||
* Note Types | ||
*/ | ||
export const BarePinnedEventType = runtimeTypes.intersection([ | ||
runtimeTypes.type({ | ||
timelineId: runtimeTypes.string, | ||
eventId: runtimeTypes.string, | ||
}), | ||
runtimeTypes.partial({ | ||
created: unionWithNullType(runtimeTypes.number), | ||
createdBy: unionWithNullType(runtimeTypes.string), | ||
updated: unionWithNullType(runtimeTypes.number), | ||
updatedBy: unionWithNullType(runtimeTypes.string), | ||
}), | ||
]); | ||
|
||
export interface BarePinnedEvent extends runtimeTypes.TypeOf<typeof BarePinnedEventType> {} | ||
|
||
/** | ||
* This type represents a pinned event type stored in a saved object that does not include any fields that reference | ||
* other saved objects. | ||
*/ | ||
export type BarePinnedEventWithoutExternalRefs = Omit<BarePinnedEvent, 'timelineId'>; | ||
|
||
export const PinnedEventRuntimeType = runtimeTypes.intersection([ | ||
runtimeTypes.type({ | ||
pinnedEventId: runtimeTypes.string, | ||
version: runtimeTypes.string, | ||
}), | ||
BarePinnedEventType, | ||
runtimeTypes.partial({ | ||
timelineVersion: unionWithNullType(runtimeTypes.string), | ||
}), | ||
]); | ||
|
||
export interface PinnedEvent extends runtimeTypes.TypeOf<typeof PinnedEventRuntimeType> {} | ||
|
||
export type PinnedEventResponse = PinnedEvent & { code: number; message?: string }; |
Oops, something went wrong.