-
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.
- Loading branch information
Showing
27 changed files
with
854 additions
and
97 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/lens/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,20 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
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, | ||
}; |
10 changes: 10 additions & 0 deletions
10
x-pack/plugins/lens/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,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const LATEST_VERSION = 1; | ||
|
||
export const CONTENT_ID = 'lens'; |
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,31 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { LATEST_VERSION, CONTENT_ID } from './constants'; | ||
|
||
export type { LensContentType } from './types'; | ||
|
||
export type { | ||
LensSavedObject, | ||
PartialLensSavedObject, | ||
LensSavedObjectAttributes, | ||
LensGetIn, | ||
LensGetOut, | ||
LensCreateIn, | ||
LensCreateOut, | ||
CreateOptions, | ||
LensUpdateIn, | ||
LensUpdateOut, | ||
UpdateOptions, | ||
LensDeleteIn, | ||
LensDeleteOut, | ||
LensSearchIn, | ||
LensSearchOut, | ||
LensSearchQuery, | ||
} from './latest'; | ||
|
||
export * as LensV1 from './v1'; |
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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './v1'; |
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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export type LensContentType = 'lens'; |
141 changes: 141 additions & 0 deletions
141
x-pack/plugins/lens/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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
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 lensAttributesSchema = schema.object( | ||
{ | ||
title: schema.string(), | ||
description: schema.maybe(schema.string()), | ||
visualizationType: schema.maybe(schema.string()), | ||
state: schema.maybe(schema.any()), | ||
uiStateJSON: schema.maybe(schema.string()), | ||
visState: schema.maybe(schema.string()), | ||
savedSearchRefName: schema.maybe(schema.string()), | ||
}, | ||
{ unknowns: 'forbid' } | ||
); | ||
|
||
const lensSavedObjectSchema = 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: lensAttributesSchema, | ||
references: referencesSchema, | ||
namespaces: schema.maybe(schema.arrayOf(schema.string())), | ||
originId: schema.maybe(schema.string()), | ||
}, | ||
{ unknowns: 'allow' } | ||
); | ||
|
||
const getResultSchema = schema.object( | ||
{ | ||
item: lensSavedObjectSchema, | ||
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: lensAttributesSchema, | ||
}, | ||
}, | ||
out: { | ||
result: { | ||
schema: schema.object( | ||
{ | ||
item: lensSavedObjectSchema, | ||
}, | ||
{ unknowns: 'forbid' } | ||
), | ||
}, | ||
}, | ||
}, | ||
update: { | ||
in: { | ||
options: { | ||
schema: createOptionsSchema, // same schema as "create" | ||
}, | ||
data: { | ||
schema: lensAttributesSchema, | ||
}, | ||
}, | ||
}, | ||
search: { | ||
in: { | ||
options: { | ||
schema: schema.maybe( | ||
schema.object( | ||
{ | ||
searchFields: schema.maybe(schema.arrayOf(schema.string())), | ||
types: schema.maybe(schema.arrayOf(schema.string())), | ||
}, | ||
{ unknowns: 'forbid' } | ||
) | ||
), | ||
}, | ||
}, | ||
}, | ||
}; |
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,26 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export type { | ||
LensSavedObject, | ||
PartialLensSavedObject, | ||
LensSavedObjectAttributes, | ||
LensGetIn, | ||
LensGetOut, | ||
LensCreateIn, | ||
LensCreateOut, | ||
CreateOptions, | ||
LensUpdateIn, | ||
LensUpdateOut, | ||
UpdateOptions, | ||
LensDeleteIn, | ||
LensDeleteOut, | ||
LensSearchIn, | ||
LensSearchOut, | ||
LensSearchQuery, | ||
Reference, | ||
} from './types'; |
111 changes: 111 additions & 0 deletions
111
x-pack/plugins/lens/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,111 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { | ||
GetIn, | ||
CreateIn, | ||
SearchIn, | ||
UpdateIn, | ||
DeleteIn, | ||
DeleteResult, | ||
SearchResult, | ||
GetResult, | ||
CreateResult, | ||
UpdateResult, | ||
} from '@kbn/content-management-plugin/common'; | ||
|
||
import { LensContentType } from '../types'; | ||
|
||
export interface Reference { | ||
type: string; | ||
id: string; | ||
name: string; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export type LensSavedObjectAttributes = { | ||
title: string; | ||
description?: string; | ||
visualizationType: string | null; | ||
state?: unknown; | ||
}; | ||
|
||
export interface LensSavedObject { | ||
id: string; | ||
type: string; | ||
version?: string; | ||
updatedAt?: string; | ||
createdAt?: string; | ||
attributes: LensSavedObjectAttributes; | ||
references: Reference[]; | ||
namespaces?: string[]; | ||
originId?: string; | ||
error?: { | ||
error: string; | ||
message: string; | ||
statusCode: number; | ||
metadata?: Record<string, unknown>; | ||
}; | ||
} | ||
|
||
export type PartialLensSavedObject = Omit<LensSavedObject, 'attributes' | 'references'> & { | ||
attributes: Partial<LensSavedObjectAttributes>; | ||
references: Reference[] | undefined; | ||
}; | ||
// ----------- GET -------------- | ||
|
||
export type LensGetIn = GetIn<LensContentType>; | ||
|
||
export type LensGetOut = GetResult< | ||
LensSavedObject, | ||
{ | ||
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 LensCreateIn = CreateIn<LensContentType, LensSavedObjectAttributes, CreateOptions>; | ||
|
||
export type LensCreateOut = CreateResult<LensSavedObject>; | ||
|
||
// ----------- UPDATE -------------- | ||
|
||
export interface UpdateOptions { | ||
/** Array of referenced saved objects. */ | ||
references?: Reference[]; | ||
} | ||
|
||
export type LensUpdateIn = UpdateIn<LensContentType, LensSavedObjectAttributes, UpdateOptions>; | ||
|
||
export type LensUpdateOut = UpdateResult<PartialLensSavedObject>; | ||
|
||
// ----------- DELETE -------------- | ||
|
||
export type LensDeleteIn = DeleteIn<LensContentType>; | ||
|
||
export type LensDeleteOut = DeleteResult; | ||
|
||
// ----------- SEARCH -------------- | ||
|
||
export interface LensSearchQuery { | ||
types?: string[]; | ||
searchFields?: string[]; | ||
} | ||
|
||
export type LensSearchIn = SearchIn<LensContentType, {}>; | ||
|
||
export type LensSearchOut = SearchResult<LensSavedObject>; |
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
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.