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

[Content Management] Maps onboard #153304

Merged
merged 27 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6c1babf
Fix object versioning and contentManagement types & schemas
sebelga Apr 5, 2023
0dac967
Add plugin dependency to contentManagement
sebelga Apr 5, 2023
cf4fa6d
Create TS types + schema validation for version 1 of map content
sebelga Apr 5, 2023
131345d
Create MapsStorage class
sebelga Apr 5, 2023
0806562
Change MapSavedObjectAttributes import to use the CM versioned one
sebelga Apr 5, 2023
babe23b
[server] Register the map content in CM registry
sebelga Apr 5, 2023
18e6f23
[public] Register the map content in CM registry
sebelga Apr 5, 2023
bce26de
[public] Expose Maps client for CRUD + search operations
sebelga Apr 5, 2023
65fbda4
Expose "checkForDuplicateTitle()" handler
sebelga Apr 5, 2023
2a608b7
Replace uses of so client with maps client
sebelga Apr 5, 2023
b656baa
Replace use of checkForDuplicateTitle()
sebelga Apr 5, 2023
1393a3a
Refactor VisualizationsAppExtension to work with MapSavedObject
sebelga Apr 5, 2023
f5ea8ad
Refactor LoadListAndRender & MapsListView
sebelga Apr 5, 2023
07de887
Merge remote-tracking branch 'upstream/main' into content-management/…
sebelga Apr 10, 2023
8f0949a
Rename MapSavedObjectAttributes to MapAttributes
sebelga Apr 10, 2023
e3dbbce
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Apr 10, 2023
0725ebb
Return full map object from search
sebelga Apr 10, 2023
ac7f110
Merge branch 'content-management/maps-onboard' of github.com:sebelga/…
sebelga Apr 10, 2023
659a335
Revert refactor on LoadListAndRender
sebelga Apr 10, 2023
2627b08
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Apr 10, 2023
3f60fd1
Merge branch 'main' into content-management/maps-onboard
sebelga Apr 10, 2023
9d8a30a
Limit search to one item when checking if there are maps
sebelga Apr 11, 2023
1c69603
Merge branch 'content-management/maps-onboard' of github.com:sebelga/…
sebelga Apr 11, 2023
ce0eeaf
Merge remote-tracking branch 'upstream/main' into content-management/…
sebelga Apr 11, 2023
8e60c53
Merge branch 'main' into content-management/maps-onboard
sebelga Apr 12, 2023
5adbb64
Revert "Return full map object from search"
sebelga Apr 12, 2023
e01635a
Merge remote-tracking branch 'upstream/main' into content-management/…
sebelga Apr 12, 2023
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
28 changes: 14 additions & 14 deletions packages/kbn-object-versioning/lib/content_management_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,52 +64,52 @@ export interface ServicesDefinition {
export interface ServiceTransforms {
get: {
in: {
options: ObjectTransforms;
options: ObjectTransforms<any, any, any, any>;
};
out: {
result: ObjectTransforms;
result: ObjectTransforms<any, any, any, any>;
};
};
bulkGet: {
in: {
options: ObjectTransforms;
options: ObjectTransforms<any, any, any, any>;
};
out: {
result: ObjectTransforms;
result: ObjectTransforms<any, any, any, any>;
};
};
create: {
in: {
data: ObjectTransforms;
options: ObjectTransforms;
data: ObjectTransforms<any, any, any, any>;
options: ObjectTransforms<any, any, any, any>;
};
out: {
result: ObjectTransforms;
result: ObjectTransforms<any, any, any, any>;
};
};
update: {
in: {
data: ObjectTransforms;
options: ObjectTransforms;
data: ObjectTransforms<any, any, any, any>;
options: ObjectTransforms<any, any, any, any>;
};
out: {
result: ObjectTransforms;
result: ObjectTransforms<any, any, any, any>;
};
};
delete: {
in: {
options: ObjectTransforms;
options: ObjectTransforms<any, any, any, any>;
};
out: {
result: ObjectTransforms;
result: ObjectTransforms<any, any, any, any>;
};
};
search: {
in: {
options: ObjectTransforms;
options: ObjectTransforms<any, any, any, any>;
};
out: {
result: ObjectTransforms;
result: ObjectTransforms<any, any, any, any>;
};
};
}
Expand Down
9 changes: 2 additions & 7 deletions packages/kbn-object-versioning/lib/object_transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
import { schema } from '@kbn/config-schema';
import { initTransform } from './object_transform';

import type {
ObjectMigrationDefinition,
ObjectTransforms,
Version,
VersionableObject,
} from './types';
import type { ObjectMigrationDefinition, Version, VersionableObject } from './types';

interface FooV1 {
fullName: string;
Expand Down Expand Up @@ -58,7 +53,7 @@ const fooMigrationDef: ObjectMigrationDefinition = {

const setup = <UpIn = unknown, UpOut = unknown, DownIn = unknown, DownOut = unknown>(
browserVersion: Version
): ObjectTransforms<UpIn, UpOut, DownIn, DownOut> => {
) => {
const transformsFactory = initTransform<UpIn, UpOut, DownIn, DownOut>(browserVersion);
return transformsFactory(fooMigrationDef);
};
Expand Down
39 changes: 18 additions & 21 deletions packages/kbn-object-versioning/lib/object_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ObjectMigrationDefinition, ObjectTransform, ObjectTransforms, Version } from './types';
import { ObjectMigrationDefinition, ObjectTransform, Version } from './types';
import { validateObj, validateVersion } from './utils';

/**
Expand Down Expand Up @@ -97,11 +97,8 @@ const getTransformFns = <I = unknown, O = unknown>(
*/
export const initTransform =
<UpIn = unknown, UpOut = unknown, DownIn = unknown, DownOut = unknown>(requestVersion: Version) =>
(
migrationDefinition: ObjectMigrationDefinition
): ObjectTransforms<UpIn, UpOut, DownIn, DownOut> => {
(migrationDefinition: ObjectMigrationDefinition) => {
const { latestVersion } = getVersionsMeta(migrationDefinition);

const getVersion = (v: Version | 'latest'): Version => (v === 'latest' ? latestVersion : v);

const validateFn = (value: unknown, version: number = requestVersion) => {
Expand All @@ -120,7 +117,11 @@ export const initTransform =
};

return {
up: (obj, to = 'latest', { validate = true }: { validate?: boolean } = {}) => {
up: <I = UpIn, O = UpOut>(
obj: I,
to: number | 'latest' = 'latest',
{ validate = true }: { validate?: boolean } = {}
) => {
try {
if (!migrationDefinition[requestVersion]) {
return {
Expand All @@ -145,16 +146,12 @@ export const initTransform =
};
}

const fns = getTransformFns<UpIn, UpOut>(
requestVersion,
targetVersion,
migrationDefinition
);
const fns = getTransformFns<I, O>(requestVersion, targetVersion, migrationDefinition);

const value = fns.reduce((acc, fn) => {
const res = fn(acc as unknown as UpIn);
const res = fn(acc as unknown as I);
return res;
}, obj as unknown as UpOut);
}, obj as unknown as O);

return { value, error: null };
} catch (e) {
Expand All @@ -164,7 +161,11 @@ export const initTransform =
};
}
},
down: (obj, from = 'latest', { validate = true }: { validate?: boolean } = {}) => {
down: <I = DownIn, O = DownOut>(
obj: I,
from: number | 'latest' = 'latest',
{ validate = true }: { validate?: boolean } = {}
) => {
try {
if (!migrationDefinition[requestVersion]) {
return {
Expand All @@ -189,16 +190,12 @@ export const initTransform =
}
}

const fns = getTransformFns<DownIn, DownOut>(
fromVersion,
requestVersion,
migrationDefinition
);
const fns = getTransformFns<I, O>(fromVersion, requestVersion, migrationDefinition);

const value = fns.reduce((acc, fn) => {
const res = fn(acc as unknown as DownIn);
const res = fn(acc as unknown as I);
return res;
}, obj as unknown as DownOut);
}, obj as unknown as O);

return { value: value as any, error: null };
} catch (e) {
Expand Down
10 changes: 5 additions & 5 deletions packages/kbn-object-versioning/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ export interface ObjectTransforms<
DownIn = unknown,
DownOut = unknown
> {
up: (
obj: UpIn,
up: <I = UpIn, O = UpOut>(
obj: I,
version?: Version | 'latest',
options?: {
/** Validate the object _before_ up transform */
validate?: boolean;
}
) => TransformReturn<UpOut>;
down: (
) => TransformReturn<O>;
down: <I = DownIn, O = DownOut>(
obj: DownIn,
version?: Version | 'latest',
options?: {
/** Validate the object _before_ down transform */
validate?: boolean;
}
) => TransformReturn<DownOut>;
) => TransformReturn<O>;
validate: (obj: any, version?: Version) => ValidationError | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class RpcClient implements CrudClient {
constructor(private http: { post: HttpSetup['post'] }) {}

public get<I extends GetIn = GetIn, O = unknown, M = unknown>(input: I) {
return this.sendMessage<GetResponse<O, M>>('get', input).then((r) => r.item);
return this.sendMessage<GetResponse<O, M>>('get', input).then((r) => r.result);
}

public bulkGet<I extends BulkGetIn = BulkGetIn, O = unknown, M = unknown>(input: I) {
return this.sendMessage<BulkGetResponse<O, M>>('bulkGet', input).then((r) => r.items);
return this.sendMessage<BulkGetResponse<O, M>>('bulkGet', input).then((r) => r.result);
}

public create<I extends CreateIn = CreateIn, O = unknown, M = unknown>(input: I) {
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/content_management/server/core/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('Content Core', () => {
const { fooContentCrud, ctx, cleanUp } = setup({ registerFooType: true });

const res = await fooContentCrud!.get(ctx, '1');
expect(res.item.item).toBeUndefined();
expect(res.result.item).toBeUndefined();

cleanUp();
});
Expand All @@ -176,7 +176,7 @@ describe('Content Core', () => {
const res = await fooContentCrud!.get(ctx, '1', { forwardInResponse: { foo: 'bar' } });
expect(res).toEqual({
contentTypeId: FOO_CONTENT_ID,
item: {
result: {
item: {
// Options forwared in response
options: { foo: 'bar' },
Expand All @@ -191,7 +191,7 @@ describe('Content Core', () => {
const { fooContentCrud, ctx, cleanUp } = setup({ registerFooType: true });

const res = await fooContentCrud!.bulkGet(ctx, ['1', '2']);
expect(res.items).toEqual({
expect(res.result).toEqual({
hits: [{ item: undefined }, { item: undefined }],
});

Expand All @@ -207,7 +207,7 @@ describe('Content Core', () => {

expect(res).toEqual({
contentTypeId: FOO_CONTENT_ID,
items: {
result: {
hits: [
{
item: {
Expand All @@ -230,15 +230,15 @@ describe('Content Core', () => {
const { fooContentCrud, ctx, cleanUp } = setup({ registerFooType: true });

const res = await fooContentCrud!.get(ctx, '1234');
expect(res.item.item).toBeUndefined();
expect(res.result.item).toBeUndefined();
await fooContentCrud!.create(
ctx,
{ title: 'Hello' },
{ id: '1234' } // We send this "id" option to specify the id of the content created
);
expect(fooContentCrud!.get(ctx, '1234')).resolves.toEqual({
contentTypeId: FOO_CONTENT_ID,
item: {
result: {
item: {
id: '1234',
title: 'Hello',
Expand All @@ -256,7 +256,7 @@ describe('Content Core', () => {
await fooContentCrud!.update(ctx, '1234', { title: 'changed' });
expect(fooContentCrud!.get(ctx, '1234')).resolves.toEqual({
contentTypeId: FOO_CONTENT_ID,
item: {
result: {
item: {
id: '1234',
title: 'changed',
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('Content Core', () => {

expect(fooContentCrud!.get(ctx, '1234')).resolves.toEqual({
contentTypeId: FOO_CONTENT_ID,
item: {
result: {
item: {
id: '1234',
title: 'changed',
Expand All @@ -309,14 +309,14 @@ describe('Content Core', () => {
await fooContentCrud!.create(ctx, { title: 'Hello' }, { id: '1234' });
expect(fooContentCrud!.get(ctx, '1234')).resolves.toEqual({
contentTypeId: FOO_CONTENT_ID,
item: {
result: {
item: expect.any(Object),
},
});
await fooContentCrud!.delete(ctx, '1234');
expect(fooContentCrud!.get(ctx, '1234')).resolves.toEqual({
contentTypeId: FOO_CONTENT_ID,
item: {
result: {
item: undefined,
},
});
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/content_management/server/core/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import type { ContentStorage, StorageContext } from './types';

export interface GetResponse<T = unknown, M = void> {
contentTypeId: string;
item: GetResult<T, M>;
result: GetResult<T, M>;
}

export interface BulkGetResponse<T = unknown, M = void> {
contentTypeId: string;
items: BulkGetResult<T, M>;
result: BulkGetResult<T, M>;
}

export interface CreateItemResponse<T = unknown, M = void> {
Expand Down Expand Up @@ -89,7 +89,7 @@ export class ContentCrud<T = unknown> {
options,
});

return { contentTypeId: this.contentTypeId, item };
return { contentTypeId: this.contentTypeId, result: item };
} catch (e) {
this.eventBus.emit({
type: 'getItemError',
Expand Down Expand Up @@ -128,7 +128,7 @@ export class ContentCrud<T = unknown> {

return {
contentTypeId: this.contentTypeId,
items,
result: items,
};
} catch (e) {
this.eventBus.emit({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('RPC -> bulkGet()', () => {

expect(result).toEqual({
contentTypeId: FOO_CONTENT_ID,
items: expected,
result: expected,
});

expect(storage.bulkGet).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('RPC -> get()', () => {

expect(result).toEqual({
contentTypeId: FOO_CONTENT_ID,
item: expected,
result: expected,
});

expect(storage.get).toHaveBeenCalledWith(
Expand Down
Loading