Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cm] annotations onboarding #159658

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
};
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 src/plugins/event_annotation/common/content_management/index.ts
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';
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';
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';
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' }
)
),
},
},
},
};
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';
126 changes: 126 additions & 0 deletions src/plugins/event_annotation/common/content_management/v1/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* 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;
tags: 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>;
1 change: 1 addition & 0 deletions src/plugins/event_annotation/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export type {
EventAnnotationGroupAttributes,
} from './types';

export type { EventAnnotationGroupSavedObjectAttributes } from './content_management';
export { EVENT_ANNOTATION_GROUP_TYPE, ANNOTATIONS_LISTING_VIEW_ID } from './constants';
Loading