-
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.
content management - event annotations (#159692)
- Loading branch information
Showing
20 changed files
with
899 additions
and
84 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/plugins/event_annotation/common/content_management/cm_services.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,21 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { | ||
ContentManagementServicesDefinition as ServicesDefinition, | ||
Version, | ||
} from '@kbn/object-versioning'; | ||
|
||
// We export the versioned service definition from this file and not the barrel to avoid adding | ||
// the schemas in the "public" js bundle | ||
|
||
import { serviceDefinition as v1 } from './v1/cm_services'; | ||
|
||
export const cmServicesDefinition: { [version: Version]: ServicesDefinition } = { | ||
1: v1, | ||
}; |
11 changes: 11 additions & 0 deletions
11
src/plugins/event_annotation/common/content_management/constants.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,11 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const LATEST_VERSION = 1; | ||
|
||
export const CONTENT_ID = 'event-annotation-group'; |
32 changes: 32 additions & 0 deletions
32
src/plugins/event_annotation/common/content_management/index.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,32 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { LATEST_VERSION, CONTENT_ID } from './constants'; | ||
|
||
export type { EventAnnotationGroupContentType } from './types'; | ||
|
||
export type { | ||
EventAnnotationGroupSavedObject, | ||
PartialEventAnnotationGroupSavedObject, | ||
EventAnnotationGroupSavedObjectAttributes, | ||
EventAnnotationGroupGetIn, | ||
EventAnnotationGroupGetOut, | ||
EventAnnotationGroupCreateIn, | ||
EventAnnotationGroupCreateOut, | ||
CreateOptions, | ||
EventAnnotationGroupUpdateIn, | ||
EventAnnotationGroupUpdateOut, | ||
UpdateOptions, | ||
EventAnnotationGroupDeleteIn, | ||
EventAnnotationGroupDeleteOut, | ||
EventAnnotationGroupSearchIn, | ||
EventAnnotationGroupSearchOut, | ||
EventAnnotationGroupSearchQuery, | ||
} from './latest'; | ||
|
||
export * as EventAnnotationGroupV1 from './v1'; |
9 changes: 9 additions & 0 deletions
9
src/plugins/event_annotation/common/content_management/latest.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,9 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export * from './v1'; |
9 changes: 9 additions & 0 deletions
9
src/plugins/event_annotation/common/content_management/types.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,9 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export type EventAnnotationGroupContentType = 'event-annotation-group'; |
141 changes: 141 additions & 0 deletions
141
src/plugins/event_annotation/common/content_management/v1/cm_services.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,141 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import type { ContentManagementServicesDefinition as ServicesDefinition } from '@kbn/object-versioning'; | ||
|
||
const apiError = schema.object({ | ||
error: schema.string(), | ||
message: schema.string(), | ||
statusCode: schema.number(), | ||
metadata: schema.object({}, { unknowns: 'allow' }), | ||
}); | ||
|
||
const referenceSchema = schema.object( | ||
{ | ||
name: schema.maybe(schema.string()), | ||
type: schema.string(), | ||
id: schema.string(), | ||
}, | ||
{ unknowns: 'forbid' } | ||
); | ||
|
||
const referencesSchema = schema.arrayOf(referenceSchema); | ||
|
||
const eventAnnotationGroupAttributesSchema = schema.object( | ||
{ | ||
title: schema.string(), | ||
description: schema.maybe(schema.string()), | ||
ignoreGlobalFilters: schema.boolean(), | ||
annotations: schema.arrayOf(schema.any()), | ||
dataViewSpec: schema.maybe(schema.any()), | ||
}, | ||
{ unknowns: 'forbid' } | ||
); | ||
|
||
const eventAnnotationGroupSavedObjectSchema = schema.object( | ||
{ | ||
id: schema.string(), | ||
type: schema.string(), | ||
version: schema.maybe(schema.string()), | ||
createdAt: schema.maybe(schema.string()), | ||
updatedAt: schema.maybe(schema.string()), | ||
error: schema.maybe(apiError), | ||
attributes: eventAnnotationGroupAttributesSchema, | ||
references: referencesSchema, | ||
namespaces: schema.maybe(schema.arrayOf(schema.string())), | ||
originId: schema.maybe(schema.string()), | ||
}, | ||
{ unknowns: 'allow' } | ||
); | ||
|
||
const getResultSchema = schema.object( | ||
{ | ||
item: eventAnnotationGroupSavedObjectSchema, | ||
meta: schema.object( | ||
{ | ||
outcome: schema.oneOf([ | ||
schema.literal('exactMatch'), | ||
schema.literal('aliasMatch'), | ||
schema.literal('conflict'), | ||
]), | ||
aliasTargetId: schema.maybe(schema.string()), | ||
aliasPurpose: schema.maybe( | ||
schema.oneOf([ | ||
schema.literal('savedObjectConversion'), | ||
schema.literal('savedObjectImport'), | ||
]) | ||
), | ||
}, | ||
{ unknowns: 'forbid' } | ||
), | ||
}, | ||
{ unknowns: 'forbid' } | ||
); | ||
|
||
const createOptionsSchema = schema.object({ | ||
overwrite: schema.maybe(schema.boolean()), | ||
references: schema.maybe(referencesSchema), | ||
}); | ||
|
||
// Content management service definition. | ||
// We need it for BWC support between different versions of the content | ||
export const serviceDefinition: ServicesDefinition = { | ||
get: { | ||
out: { | ||
result: { | ||
schema: getResultSchema, | ||
}, | ||
}, | ||
}, | ||
create: { | ||
in: { | ||
options: { | ||
schema: createOptionsSchema, | ||
}, | ||
data: { | ||
schema: eventAnnotationGroupAttributesSchema, | ||
}, | ||
}, | ||
out: { | ||
result: { | ||
schema: schema.object( | ||
{ | ||
item: eventAnnotationGroupSavedObjectSchema, | ||
}, | ||
{ unknowns: 'forbid' } | ||
), | ||
}, | ||
}, | ||
}, | ||
update: { | ||
in: { | ||
options: { | ||
schema: createOptionsSchema, // same schema as "create" | ||
}, | ||
data: { | ||
schema: eventAnnotationGroupAttributesSchema, | ||
}, | ||
}, | ||
}, | ||
search: { | ||
in: { | ||
options: { | ||
schema: schema.maybe( | ||
schema.object( | ||
{ | ||
searchFields: schema.maybe(schema.arrayOf(schema.string())), | ||
types: schema.maybe(schema.arrayOf(schema.string())), | ||
}, | ||
{ unknowns: 'forbid' } | ||
) | ||
), | ||
}, | ||
}, | ||
}, | ||
}; |
27 changes: 27 additions & 0 deletions
27
src/plugins/event_annotation/common/content_management/v1/index.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,27 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export type { | ||
EventAnnotationGroupSavedObject as EventAnnotationGroupSavedObject, | ||
PartialEventAnnotationGroupSavedObject, | ||
EventAnnotationGroupSavedObjectAttributes, | ||
EventAnnotationGroupGetIn, | ||
EventAnnotationGroupGetOut, | ||
EventAnnotationGroupCreateIn, | ||
EventAnnotationGroupCreateOut, | ||
CreateOptions, | ||
EventAnnotationGroupUpdateIn, | ||
EventAnnotationGroupUpdateOut, | ||
UpdateOptions, | ||
EventAnnotationGroupDeleteIn, | ||
EventAnnotationGroupDeleteOut, | ||
EventAnnotationGroupSearchIn, | ||
EventAnnotationGroupSearchOut, | ||
EventAnnotationGroupSearchQuery, | ||
Reference, | ||
} from './types'; |
125 changes: 125 additions & 0 deletions
125
src/plugins/event_annotation/common/content_management/v1/types.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,125 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { | ||
GetIn, | ||
CreateIn, | ||
SearchIn, | ||
UpdateIn, | ||
DeleteIn, | ||
DeleteResult, | ||
SearchResult, | ||
GetResult, | ||
CreateResult, | ||
UpdateResult, | ||
} from '@kbn/content-management-plugin/common'; | ||
|
||
import type { DataViewSpec } from '@kbn/data-views-plugin/common'; | ||
import { EventAnnotationGroupContentType } from '../types'; | ||
import { EventAnnotationConfig } from '../../types'; | ||
|
||
export interface Reference { | ||
type: string; | ||
id: string; | ||
name: string; | ||
} | ||
|
||
export interface EventAnnotationGroupSavedObjectAttributes { | ||
title: string; | ||
description: string; | ||
ignoreGlobalFilters: boolean; | ||
annotations: EventAnnotationConfig[]; | ||
dataViewSpec?: DataViewSpec; | ||
} | ||
|
||
export interface EventAnnotationGroupSavedObject { | ||
id: string; | ||
type: string; | ||
version?: string; | ||
updatedAt?: string; | ||
createdAt?: string; | ||
attributes: EventAnnotationGroupSavedObjectAttributes; | ||
references: Reference[]; | ||
namespaces?: string[]; | ||
originId?: string; | ||
error?: { | ||
error: string; | ||
message: string; | ||
statusCode: number; | ||
metadata?: Record<string, unknown>; | ||
}; | ||
} | ||
|
||
export type PartialEventAnnotationGroupSavedObject = Omit< | ||
EventAnnotationGroupSavedObject, | ||
'attributes' | 'references' | ||
> & { | ||
attributes: Partial<EventAnnotationGroupSavedObjectAttributes>; | ||
references: Reference[] | undefined; | ||
}; | ||
// ----------- GET -------------- | ||
|
||
export type EventAnnotationGroupGetIn = GetIn<EventAnnotationGroupContentType>; | ||
|
||
export type EventAnnotationGroupGetOut = GetResult< | ||
EventAnnotationGroupSavedObject, | ||
{ | ||
outcome: 'exactMatch' | 'aliasMatch' | 'conflict'; | ||
aliasTargetId?: string; | ||
aliasPurpose?: 'savedObjectConversion' | 'savedObjectImport'; | ||
} | ||
>; | ||
|
||
// ----------- CREATE -------------- | ||
|
||
export interface CreateOptions { | ||
/** If a document with the given `id` already exists, overwrite it's contents (default=false). */ | ||
overwrite?: boolean; | ||
/** Array of referenced saved objects. */ | ||
references?: Reference[]; | ||
} | ||
|
||
export type EventAnnotationGroupCreateIn = CreateIn< | ||
EventAnnotationGroupContentType, | ||
EventAnnotationGroupSavedObjectAttributes, | ||
CreateOptions | ||
>; | ||
|
||
export type EventAnnotationGroupCreateOut = CreateResult<EventAnnotationGroupSavedObject>; | ||
|
||
// ----------- UPDATE -------------- | ||
|
||
export interface UpdateOptions { | ||
/** Array of referenced saved objects. */ | ||
references?: Reference[]; | ||
} | ||
|
||
export type EventAnnotationGroupUpdateIn = UpdateIn< | ||
EventAnnotationGroupContentType, | ||
EventAnnotationGroupSavedObjectAttributes, | ||
UpdateOptions | ||
>; | ||
|
||
export type EventAnnotationGroupUpdateOut = UpdateResult<PartialEventAnnotationGroupSavedObject>; | ||
|
||
// ----------- DELETE -------------- | ||
|
||
export type EventAnnotationGroupDeleteIn = DeleteIn<EventAnnotationGroupContentType>; | ||
|
||
export type EventAnnotationGroupDeleteOut = DeleteResult; | ||
|
||
// ----------- SEARCH -------------- | ||
|
||
export interface EventAnnotationGroupSearchQuery { | ||
types?: string[]; | ||
searchFields?: string[]; | ||
} | ||
|
||
export type EventAnnotationGroupSearchIn = SearchIn<EventAnnotationGroupContentType, {}>; | ||
|
||
export type EventAnnotationGroupSearchOut = SearchResult<EventAnnotationGroupSavedObject>; |
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
Oops, something went wrong.