Skip to content

Commit ecea34b

Browse files
[Lens as code] Align public API meta with dashboard APIs (elastic#260846)
## Summary Follows changes in elastic#260789 Changes: - Cleans up public route `meta` schema and types to use the shared versions. - Remove generic typings for extra `meta` properties. - Removes saved object client error checking. This is not needed for the methods we use, mainly just `/bulk`. - Internal routes still pass Lens-specific `meta` properties but this can be cleaned later. - Content Management still returns camelCased meta, this can be changed when internal routes are removed. Closes elastic#260792 ### 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 - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
1 parent 8b1f3e1 commit ecea34b

12 files changed

Lines changed: 37 additions & 72 deletions

File tree

src/platform/packages/shared/as-code/shared-schemas/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
export { asCodeIdSchema, asCodeMetaSchema, getMeta } from './src/schemas';
10+
export { asCodeIdSchema, asCodeMetaSchema, getMeta, type AsCodeMeta } from './src/schemas';

src/platform/packages/shared/as-code/shared-schemas/src/schemas/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
*/
99

1010
export { asCodeIdSchema } from './id';
11-
export { asCodeMetaSchema, getMeta } from './meta';
11+
export { asCodeMetaSchema, getMeta, type AsCodeMeta } from './meta';

src/platform/packages/shared/as-code/shared-schemas/src/schemas/meta/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
*/
99

1010
export { getMeta } from './get_meta';
11-
export { asCodeMetaSchema } from './schema';
11+
export { asCodeMetaSchema, type AsCodeMeta } from './schema';

x-pack/platform/plugins/shared/lens/moon.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ dependsOn:
151151
- '@kbn/field-formats-common'
152152
- '@kbn/calculate-auto'
153153
- '@kbn/esql-language'
154+
- '@kbn/as-code-shared-schemas'
154155
- '@kbn/core-http-browser'
155156
tags:
156157
- plugin

x-pack/platform/plugins/shared/lens/public/persistence/lens_client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { getLensBuilder } from '../lazy_builder';
3232

3333
export interface LensItemResponse<M extends Record<string, string | boolean> = {}> {
3434
item: LensItem;
35+
// TODO: align meta with public routes when internal routes are removed
3536
meta: LensItemMeta & M;
3637
}
3738

x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/create.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
LENS_API_TAG,
1818
} from '../../../../common/constants';
1919
import type { LensCreateIn, LensSavedObject } from '../../../content_management';
20-
import type { LensCreateResponseBody, RegisterAPIRouteFn } from '../../../types';
20+
import type { RegisterAPIRouteFn } from '../../types';
21+
import type { LensCreateResponseBody } from './types';
2122
import { getLensRequestConfig, getLensResponseItem } from './utils';
2223
import {
2324
lensCreateRequestBodySchema,
@@ -95,12 +96,8 @@ export const registerLensVisualizationsCreateAPIRoute: RegisterAPIRouteFn = (
9596
const { references, ...data } = getLensRequestConfig(builder, req.body);
9697
const options: LensCreateIn['options'] = { ...req.query, references };
9798
const { result } = await client.create(data, options);
98-
99-
if (result.item.error) {
100-
throw result.item.error;
101-
}
102-
10399
const responseItem = getLensResponseItem(builder, result.item);
100+
104101
return res.created<LensCreateResponseBody>({
105102
body: responseItem,
106103
});

x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/get.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ export const registerLensVisualizationsGetAPIRoute: RegisterAPIRouteFn = (
8282

8383
try {
8484
const { result } = await client.get(req.params.id);
85-
86-
if (result.item.error) {
87-
throw result.item.error;
88-
}
89-
9085
const responseItem = getLensResponseItem(builder, result.item);
9186

9287
return res.ok<TypeOf<typeof lensGetResponseBodySchema>>({

x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/common.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,20 @@
77

88
import { schema } from '@kbn/config-schema';
99
import { lensApiStateSchema } from '@kbn/lens-embeddable-utils';
10+
import { asCodeMetaSchema } from '@kbn/as-code-shared-schemas';
1011

1112
import { lensCommonSavedObjectSchemaV2 } from '../../../../content_management';
1213

1314
const savedObjectProps = lensCommonSavedObjectSchemaV2.getPropSchemas();
1415

15-
/**
16-
* The Lens item meta returned from the server
17-
*/
18-
export const lensItemMetaSchema = schema.object(
19-
{
20-
type: savedObjectProps.type,
21-
created_at: savedObjectProps.createdAt,
22-
updated_at: savedObjectProps.updatedAt,
23-
created_by: savedObjectProps.createdBy,
24-
updated_by: savedObjectProps.updatedBy,
25-
origin_id: savedObjectProps.originId,
26-
managed: savedObjectProps.managed,
27-
},
28-
{ unknowns: 'forbid', meta: { id: 'lensItemMeta', title: 'Visualization Meta' } }
29-
);
30-
3116
/**
3217
* The Lens response item returned from the server
3318
*/
3419
export const lensResponseItemSchema = schema.object(
3520
{
3621
id: savedObjectProps.id,
3722
data: lensApiStateSchema,
38-
meta: lensItemMetaSchema,
23+
meta: asCodeMetaSchema,
3924
},
4025
{ unknowns: 'forbid', meta: { id: 'lensResponseItem', title: 'Visualization Response' } }
4126
);

x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ import type {
2222
lensUpdateRequestParamsSchema,
2323
lensUpdateResponseBodySchema,
2424
} from './schema';
25-
import type { lensItemMetaSchema, lensResponseItemSchema } from './schema/common';
25+
import type { lensResponseItemSchema } from './schema/common';
2626

27-
export type LensItemMeta = TypeOf<typeof lensItemMetaSchema>;
2827
export type LensResponseItem = TypeOf<typeof lensResponseItemSchema>;
2928

3029
export type LensCreateRequestQuery = TypeOf<typeof lensCreateRequestQuerySchema>;

x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/update.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import {
2020
LENS_API_TAG,
2121
} from '../../../../common/constants';
2222
import type { LensUpdateIn, LensSavedObject } from '../../../content_management';
23-
import type { LensUpdateResponseBody, RegisterAPIRouteFn } from '../../../types';
23+
24+
import type { RegisterAPIRouteFn } from '../../types';
25+
import type { LensUpdateResponseBody } from './types';
2426
import {
2527
lensUpdateRequestBodySchema,
2628
lensUpdateRequestParamsSchema,
@@ -119,11 +121,6 @@ export const registerLensVisualizationsUpdateAPIRoute: RegisterAPIRouteFn = (
119121

120122
try {
121123
const { result } = await client.update(req.params.id, data, options);
122-
123-
if (result.item.error) {
124-
throw result.item.error;
125-
}
126-
127124
const responseItem = getLensResponseItem(builder, result.item);
128125

129126
if (createdNew) {

0 commit comments

Comments
 (0)