Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
c38e0b8
improve CM class to be easier to extend and override defaults
nickofthyme Jul 26, 2025
a0df8cb
improve CM rpc types to satisfy generic type instead of be the generi…
nickofthyme Jul 26, 2025
d2af505
fix spelling errors
nickofthyme Jul 26, 2025
dd1d576
move and add constants
nickofthyme Jul 26, 2025
9dee933
update CM common schema
nickofthyme Jul 26, 2025
06ac9d2
update storage context params
nickofthyme Jul 26, 2025
0e1d797
cleanup `getMSearchClientFactory`
nickofthyme Jul 26, 2025
ff9d7bd
use api path constants
nickofthyme Jul 26, 2025
5ce1467
allow initial `v0` for `down` transforms
nickofthyme Jul 26, 2025
ab47bfd
refactor visualizations plugin clients
nickofthyme Jul 26, 2025
31dc07f
add content management schema
nickofthyme Jul 26, 2025
08313f2
add lens vis route schema
nickofthyme Jul 26, 2025
6628892
refactor types to use schema definitions
nickofthyme Jul 26, 2025
52615b0
update imports, constants and types
nickofthyme Jul 26, 2025
b25d312
update lens SO mappings to add new version property
nickofthyme Jul 26, 2025
aa7bd3f
implement all lens CM CRUD operations with latest CM schema
nickofthyme Jul 26, 2025
5b80de2
update lens CRUD apis
nickofthyme Jul 26, 2025
091a840
update CM service with v0 Item transforms
nickofthyme Jul 26, 2025
f2be004
add config builder stub
nickofthyme Jul 26, 2025
ce9493f
cleanup public constants and types
nickofthyme Jul 26, 2025
207e4c3
refactor lens public client
nickofthyme Jul 26, 2025
77e51b7
more type cleanup
nickofthyme Jul 27, 2025
dd1ed49
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine Jul 27, 2025
099929a
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Jul 27, 2025
fe7241d
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Jul 28, 2025
fdc5fc4
chore: fix type check and linting errors
nickofthyme Jul 28, 2025
6844da9
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Jul 28, 2025
8fc9721
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Jul 28, 2025
dd050dc
chore: fix more type errors
nickofthyme Jul 30, 2025
17794ab
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Jul 30, 2025
f8278e4
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jul 30, 2025
7797b90
fix: import error
nickofthyme Jul 30, 2025
443b1c6
allow accessing props outside of schema
nickofthyme Aug 1, 2025
dae73c7
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 1, 2025
2965fb5
fix test and type errors
nickofthyme Aug 2, 2025
f4028ea
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 2, 2025
efaafb1
fix type and linting issues
nickofthyme Aug 2, 2025
c7d83b8
update register type
nickofthyme Aug 2, 2025
5a4e0d9
fix more type issues
nickofthyme Aug 2, 2025
836e7a5
fix more type errors and version issues
nickofthyme Aug 3, 2025
e331545
remove erroneous lens attributes
nickofthyme Aug 3, 2025
414125f
fix another type issue
nickofthyme Aug 3, 2025
16a3153
fix lens attribute versioning
nickofthyme Aug 3, 2025
1db8129
fix bad imports
nickofthyme Aug 3, 2025
297ab25
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 3, 2025
92e3a3b
permit unknown SO versioning
nickofthyme Aug 3, 2025
c53a9f3
fix another build errors
nickofthyme Aug 3, 2025
74374c0
Merge remote-tracking branch 'origin/lens-transforms-phase-1' into le…
nickofthyme Aug 3, 2025
72a54a8
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Aug 3, 2025
bb697f2
fix: permit old SO shape on create
nickofthyme Aug 3, 2025
f9990e3
fix: lens doc services should return doc from request
nickofthyme Aug 3, 2025
3e7aa5b
Merge remote-tracking branch 'origin/lens-transforms-phase-1' into le…
nickofthyme Aug 3, 2025
c25ed7a
revert required version attribute changes
nickofthyme Aug 3, 2025
eb0ebad
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Aug 3, 2025
af221ab
chore: remove versions in cb files
nickofthyme Aug 5, 2025
fe582c0
temporary limit bump
nickofthyme Aug 5, 2025
5974f43
make version optional
nickofthyme Aug 5, 2025
592e795
allow passing old SO to create route
nickofthyme Aug 5, 2025
20e70b1
chore: remove erroneous props
nickofthyme Aug 5, 2025
dcbe8a0
Merge remote-tracking branch 'origin/lens-transforms-phase-1' into le…
nickofthyme Aug 5, 2025
432ac1f
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Aug 5, 2025
a525495
chore: move CM files and schema from common/ to server/
nickofthyme Aug 5, 2025
9d439b9
Revert "temporary limit bump"
nickofthyme Aug 5, 2025
cd51aa7
update registered types
nickofthyme Aug 5, 2025
0ddbc6a
Merge remote-tracking branch 'origin/lens-transforms-phase-1' into le…
nickofthyme Aug 5, 2025
82cec36
fix: lens save error
nickofthyme Aug 6, 2025
4867753
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 6, 2025
4a5f037
chore: move CM transforms to common
nickofthyme Aug 6, 2025
1fe4751
restore server package types
nickofthyme Aug 6, 2025
600f77c
add ts expected errors
nickofthyme Aug 6, 2025
76a223d
restore changes to obj transforms
nickofthyme Aug 6, 2025
9d060b2
add `v0` CM service definition
nickofthyme Aug 6, 2025
28dee89
fix import error
nickofthyme Aug 7, 2025
9595989
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 7, 2025
fe7fffe
test: fix failing tests
nickofthyme Aug 10, 2025
c7c128b
test: fix failing test with bad mock
nickofthyme Aug 7, 2025
2768b1b
test: fix and add tests for mSearch changes
nickofthyme Aug 6, 2025
191c61a
test: update tests with changes and add test cases
nickofthyme Aug 8, 2025
66012ec
test: fix more failing tests
nickofthyme Aug 10, 2025
aa18a2c
fix: cases issue adding lens vis
nickofthyme Aug 10, 2025
1b48af1
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 10, 2025
b617032
fix merge type errors
nickofthyme Aug 10, 2025
251ef00
test: fix test type errors
nickofthyme Aug 10, 2025
5f01c8b
chore: update lens api tests with changes to api format
nickofthyme Aug 11, 2025
8f7775b
fix import issue and loosen schema properties
nickofthyme Aug 12, 2025
3c62e2a
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 12, 2025
4a83f29
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Aug 12, 2025
f49ec00
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 12, 2025
bb6b0dc
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 12, 2025
b2ee74b
remove changes from split-off prs
nickofthyme Aug 12, 2025
663d0a7
minor code cleanup
nickofthyme Aug 12, 2025
2bc949a
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 12, 2025
8006475
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 14, 2025
d271b9e
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 26, 2025
65e82e1
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 27, 2025
8598916
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Aug 27, 2025
0642315
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Aug 27, 2025
1718047
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine Aug 27, 2025
55bcaed
fix type error
nickofthyme Aug 27, 2025
0ce24ef
chore: apply suggestions from code review
nickofthyme Aug 27, 2025
6b25f27
lens doc service update `save` return
nickofthyme Aug 27, 2025
09c845a
chore: address pr review comments
nickofthyme Aug 27, 2025
16b2429
Merge remote-tracking branch 'origin/lens-transforms-phase-1' into le…
nickofthyme Aug 27, 2025
de4125f
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Sep 3, 2025
edbeaa3
chore: remove `isNewApiFormat` from saved state
nickofthyme Sep 3, 2025
7bd7988
chore: update lens mappings
nickofthyme Sep 4, 2025
7508682
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Sep 4, 2025
43a5207
chore: update lens SO mappings
nickofthyme Sep 4, 2025
3bcea70
Merge remote-tracking branch 'origin/lens-transforms-phase-1' into le…
nickofthyme Sep 4, 2025
59d6a3b
chore: update lens SO mappings to not set index to false
nickofthyme Sep 4, 2025
e06d7c7
chore: update lens so mappings
nickofthyme Sep 5, 2025
db701f4
Merge branch 'main' into lens-transforms-phase-1
nickofthyme Sep 5, 2025
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
Expand Up @@ -2584,6 +2584,7 @@
}
},
"lens": {
"dynamic": false,
Comment thread
nickofthyme marked this conversation as resolved.
"properties": {
"description": {
"type": "text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"inventory-view": "e125c6e6e49729055421e7b3a0544f24330d8dc6",
"kql-telemetry": "92d6357aa3ce28727492f86a54783f802dc38893",
"legacy-url-alias": "9b8cca3fbb2da46fd12823d3cd38fdf1c9f24bc8",
"lens": "6fa6bdc5de12859815de6e50488fa2a7b038278a",
"lens": "1914604f1afd63e23cbd0628757c809e641400a0",
"lens-ui-telemetry": "d6c4e330d170eefc6214dbf77a53de913fa3eebc",
"links": "53ae5a770d69eee34d842617be761cd059ab4b51",
"maintenance-window": "f3f19d1828e91418d13703ce6009e9c76a1686f9",
Expand Down Expand Up @@ -833,8 +833,9 @@ describe('checking migration metadata changes on all registered SO types', () =>
"legacy-url-alias|8.2.0: 4c58be29493363cb48eb37fa5612fb3fb0eed77e",
"================================================================",
"lens|global: 0267d37678684c5f234bd74f0f6ae2a5f6180eb4",
"lens|mappings: ccf7f3aea93efcf8d26faffa63e4bf6f0748ea80",
"lens|mappings: 5edb12dfc3770ed521bc96b28103e325f04cf9f6",
"lens|schemas: da39a3ee5e6b4b0d3255bfef95601890afd80709",
"lens|10.1.0: e053504b39aceec3b665388bb586e89e162e5a60",
"lens|8.9.0: f6592efb2500e39d1d31b1effdfad7d7ad1eca32",
"lens|8.6.0: 54c152a2584673672445346cf69d72bda587cc52",
"lens|8.5.0: 54c152a2584673672445346cf69d72bda587cc52",
Expand Down Expand Up @@ -1293,7 +1294,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"inventory-view": "10.2.0",
"kql-telemetry": "10.0.0",
"legacy-url-alias": "10.0.0",
"lens": "10.0.0",
"lens": "10.1.0",
"lens-ui-telemetry": "10.0.0",
"links": "10.0.0",
"maintenance-window": "10.2.0",
Expand Down Expand Up @@ -1438,7 +1439,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"inventory-view": "10.2.0",
"kql-telemetry": "0.0.0",
"legacy-url-alias": "8.2.0",
"lens": "8.9.0",
"lens": "10.1.0",
"lens-ui-telemetry": "0.0.0",
"links": "0.0.0",
"maintenance-window": "10.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { SOContentStorage } from './saved_object_content_storage';
import type { CMCrudTypes } from './types';
import type { MockedLogger } from '@kbn/logging-mocks';
import { loggerMock } from '@kbn/logging-mocks';
import type { MockedLogger } from '@kbn/logging-mocks';

import { SOContentStorage } from './saved_object_content_storage';
import type { ContentManagementCrudTypes } from './types';

import { schema } from '@kbn/config-schema';
import type {
Expand All @@ -21,9 +22,15 @@ import { getContentManagementServicesTransforms } from '@kbn/object-versioning';
import { savedObjectSchema, objectTypeToGetResultSchema, createResultSchema } from './schema';

import { coreMock } from '@kbn/core/server/mocks';
import type { SavedObject } from '@kbn/core/server';
import type { RequestHandlerContext, SavedObject } from '@kbn/core/server';
import { mockRouter } from '@kbn/core-http-router-server-mocks';

interface MockAttributes {
title: string;
description: string | null;
}
type MockCrudTypes = ContentManagementCrudTypes<'content-id', MockAttributes, {}, {}, {}>;

const testAttributesSchema = schema.object(
{
title: schema.string(),
Expand Down Expand Up @@ -78,7 +85,7 @@ export const cmServicesDefinition: { [version: Version]: ServicesDefinition } =

const transforms = getContentManagementServicesTransforms(cmServicesDefinition, 1);

class TestSOContentStorage extends SOContentStorage<CMCrudTypes> {
class TestSOContentStorage extends SOContentStorage<MockCrudTypes> {
constructor({
throwOnResultValidationError,
logger,
Expand All @@ -97,11 +104,10 @@ class TestSOContentStorage extends SOContentStorage<CMCrudTypes> {
const setup = ({ storage }: { storage?: TestSOContentStorage } = {}) => {
storage = storage ?? new TestSOContentStorage();
const requestHandlerCoreContext = coreMock.createRequestHandlerContext();

const requestHandlerContext = {
const requestHandlerContext = jest.mocked<RequestHandlerContext>({
core: Promise.resolve(requestHandlerCoreContext),
resolve: jest.fn(),
};
});

return {
get: (mockSavedObject: SavedObject) => {
Expand All @@ -125,7 +131,7 @@ const setup = ({ storage }: { storage?: TestSOContentStorage } = {}) => {
mockSavedObject.id
);
},
create: (mockSavedObject: SavedObject<{}>) => {
create: (mockSavedObject: SavedObject<MockAttributes>) => {
requestHandlerCoreContext.savedObjects.client.create.mockResolvedValue(mockSavedObject);

return storage!.create(
Expand All @@ -144,7 +150,7 @@ const setup = ({ storage }: { storage?: TestSOContentStorage } = {}) => {
{}
);
},
update: (mockSavedObject: SavedObject<{}>) => {
update: (mockSavedObject: SavedObject<MockAttributes>) => {
requestHandlerCoreContext.savedObjects.client.update.mockResolvedValue(mockSavedObject);

return storage!.update(
Expand All @@ -164,7 +170,7 @@ const setup = ({ storage }: { storage?: TestSOContentStorage } = {}) => {
{}
);
},
search: (mockSavedObject: SavedObject<{}>) => {
search: (mockSavedObject: SavedObject<MockAttributes>) => {
requestHandlerCoreContext.savedObjects.client.find.mockResolvedValue({
saved_objects: [{ ...mockSavedObject, score: 100 }],
total: 1,
Expand All @@ -188,7 +194,7 @@ const setup = ({ storage }: { storage?: TestSOContentStorage } = {}) => {
{}
);
},
mSearch: async (mockSavedObject: SavedObject<{}>) => {
mSearch: async (mockSavedObject: SavedObject<MockAttributes>) => {
return storage!.mSearch!.toItemResult(
{
request: mockRouter.createFakeKibanaRequest({}),
Expand Down
Comment thread
nickofthyme marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -32,66 +32,10 @@ import type {
} from './types';
import { tagsToFindOptions } from './utils';

const savedObjectClientFromRequest = async (ctx: StorageContext) => {
Comment thread
nickofthyme marked this conversation as resolved.
if (!ctx.requestHandlerContext) {
throw new Error('Storage context.requestHandlerContext missing.');
}

const { savedObjects } = await ctx.requestHandlerContext.core;
return savedObjects.client;
};

type PartialSavedObject<T> = Omit<SavedObject<Partial<T>>, 'references'> & {
references: SavedObjectReference[] | undefined;
};

function savedObjectToItem<Attributes extends object, Item extends SOWithMetadata>(
savedObject: SavedObject<Attributes>,
allowedSavedObjectAttributes: string[],
partial: false
): Item;

function savedObjectToItem<Attributes extends object, PartialItem extends SOWithMetadata>(
savedObject: PartialSavedObject<Attributes>,
allowedSavedObjectAttributes: string[],
partial: true
): PartialItem;

function savedObjectToItem<Attributes extends object>(
savedObject: SavedObject<Attributes> | PartialSavedObject<Attributes>,
allowedSavedObjectAttributes: string[]
): SOWithMetadata | SOWithMetadataPartial {
Comment thread
nickofthyme marked this conversation as resolved.
const {
id,
type,
updated_at: updatedAt,
updated_by: updatedBy,
created_at: createdAt,
created_by: createdBy,
attributes,
references,
error,
namespaces,
version,
managed,
} = savedObject;

return {
id,
type,
managed,
updatedBy,
updatedAt,
createdAt,
createdBy,
attributes: pick(attributes, allowedSavedObjectAttributes),
references,
error,
namespaces,
version,
};
}

export interface SearchArgsToSOFindOptionsOptionsDefault {
fields?: string[];
searchFields?: string[];
Expand Down Expand Up @@ -138,7 +82,7 @@ export interface SOContentStorageConstructorParams<Types extends CMCrudTypes> {
savedObjectType: string;
cmServicesDefinition: ServicesDefinitionSet;
// this is necessary since unexpected saved object attributes could cause schema validation to fail
allowedSavedObjectAttributes: string[];
allowedSavedObjectAttributes: Array<keyof Types['Attributes']>;
createArgsToSoCreateOptions?: CreateArgsToSoCreateOptions<Types>;
updateArgsToSoUpdateOptions?: UpdateArgsToSoUpdateOptions<Types>;
searchArgsToSOFindOptions?: SearchArgsToSOFindOptions<Types>;
Expand Down Expand Up @@ -193,10 +137,8 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
toItemResult: (ctx: StorageContext, savedObject: SavedObjectsFindResult): Types['Item'] => {
const transforms = ctx.utils.getTransforms(this.cmServicesDefinition);

const contentItem = savedObjectToItem(
savedObject as SavedObjectsFindResult<Types['Attributes']>,
this.allowedSavedObjectAttributes,
false
const contentItem = this.savedObjectToItem(
savedObject as SavedObjectsFindResult<Types['Attributes']>
);

const validationError = transforms.mSearch.out.result.validate(contentItem);
Expand Down Expand Up @@ -228,14 +170,62 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
}
}

private throwOnResultValidationError: boolean;
private logger: Logger;
private savedObjectType: SOContentStorageConstructorParams<Types>['savedObjectType'];
private cmServicesDefinition: SOContentStorageConstructorParams<Types>['cmServicesDefinition'];
private createArgsToSoCreateOptions: CreateArgsToSoCreateOptions<Types>;
private updateArgsToSoUpdateOptions: UpdateArgsToSoUpdateOptions<Types>;
private searchArgsToSOFindOptions: SearchArgsToSOFindOptions<Types>;
private allowedSavedObjectAttributes: string[];
protected static getSOClientFromRequest = async (ctx: StorageContext) => {
if (!ctx.requestHandlerContext) {
throw new Error('Storage context.requestHandlerContext missing.');
}

const { savedObjects } = await ctx.requestHandlerContext.core;
return savedObjects.client;
};

protected readonly throwOnResultValidationError: boolean;
protected readonly logger: Logger;
protected readonly savedObjectType: SOContentStorageConstructorParams<Types>['savedObjectType'];
protected readonly cmServicesDefinition: SOContentStorageConstructorParams<Types>['cmServicesDefinition'];
protected readonly createArgsToSoCreateOptions: CreateArgsToSoCreateOptions<Types>;
protected readonly updateArgsToSoUpdateOptions: UpdateArgsToSoUpdateOptions<Types>;
protected readonly searchArgsToSOFindOptions: SearchArgsToSOFindOptions<Types>;
protected readonly allowedSavedObjectAttributes: Array<keyof Types['Attributes']>;
Comment thread
nickofthyme marked this conversation as resolved.

protected savedObjectToItem(savedObject: SavedObject<Types['Attributes']>): Types['Item'];
protected savedObjectToItem(
savedObject: PartialSavedObject<Types['Attributes']>,
partial: true
): Types['PartialItem'];
protected savedObjectToItem(
savedObject: SavedObject<Types['Attributes']> | PartialSavedObject<Types['Attributes']>
Comment thread
nickofthyme marked this conversation as resolved.
): SOWithMetadata | SOWithMetadataPartial {
const {
id,
type,
updated_at: updatedAt,
updated_by: updatedBy,
created_at: createdAt,
created_by: createdBy,
attributes,
references,
error,
namespaces,
version,
managed,
} = savedObject;

return {
id,
type,
managed,
updatedBy,
updatedAt,
createdAt,
createdBy,
attributes: pick(attributes, this.allowedSavedObjectAttributes),
references,
error,
namespaces,
version,
};
}

mSearch?: {
savedObjectType: string;
Expand All @@ -245,7 +235,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>

async get(ctx: StorageContext, id: string): Promise<Types['GetOut']> {
const transforms = ctx.utils.getTransforms(this.cmServicesDefinition);
const soClient = await savedObjectClientFromRequest(ctx);
const soClient = await SOContentStorage.getSOClientFromRequest(ctx);

// Save data in DB
const {
Expand All @@ -256,7 +246,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
} = await soClient.resolve<Types['Attributes']>(this.savedObjectType, id);

const response: Types['GetOut'] = {
item: savedObjectToItem(savedObject, this.allowedSavedObjectAttributes, false),
item: this.savedObjectToItem(savedObject),
meta: {
aliasPurpose,
aliasTargetId,
Expand Down Expand Up @@ -301,7 +291,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
options: Types['CreateOptions']
): Promise<Types['CreateOut']> {
const transforms = ctx.utils.getTransforms(this.cmServicesDefinition);
const soClient = await savedObjectClientFromRequest(ctx);
const soClient = await SOContentStorage.getSOClientFromRequest(ctx);

// Validate input (data & options) & UP transform them to the latest version
const { value: dataToLatest, error: dataError } = transforms.create.in.data.up<
Expand Down Expand Up @@ -330,7 +320,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
);

const result = {
item: savedObjectToItem(savedObject, this.allowedSavedObjectAttributes, false),
item: this.savedObjectToItem(savedObject),
};

const validationError = transforms.create.out.result.validate(result);
Expand Down Expand Up @@ -366,7 +356,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
options: Types['UpdateOptions']
): Promise<Types['UpdateOut']> {
const transforms = ctx.utils.getTransforms(this.cmServicesDefinition);
const soClient = await savedObjectClientFromRequest(ctx);
const soClient = await SOContentStorage.getSOClientFromRequest(ctx);

// Validate input (data & options) & UP transform them to the latest version
const { value: dataToLatest, error: dataError } = transforms.update.in.data.up<
Expand Down Expand Up @@ -396,7 +386,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
);

const result = {
item: savedObjectToItem(partialSavedObject, this.allowedSavedObjectAttributes, true),
item: this.savedObjectToItem(partialSavedObject, true),
};

const validationError = transforms.update.out.result.validate(result);
Expand Down Expand Up @@ -431,7 +421,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
// force is necessary to delete saved objects that exist in multiple namespaces
options?: { force: boolean }
): Promise<Types['DeleteOut']> {
const soClient = await savedObjectClientFromRequest(ctx);
const soClient = await SOContentStorage.getSOClientFromRequest(ctx);
await soClient.delete(this.savedObjectType, id, { force: options?.force ?? false });
return { success: true };
}
Expand All @@ -442,7 +432,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
options: Types['SearchOptions'] = {}
): Promise<Types['SearchOut']> {
const transforms = ctx.utils.getTransforms(this.cmServicesDefinition);
const soClient = await savedObjectClientFromRequest(ctx);
const soClient = await SOContentStorage.getSOClientFromRequest(ctx);

// Validate and UP transform the options
const { value: optionsToLatest, error: optionsError } = transforms.search.in.options.up<
Expand All @@ -461,9 +451,7 @@ export abstract class SOContentStorage<Types extends CMCrudTypes>
// Execute the query in the DB
const soResponse = await soClient.find<Types['Attributes']>(soQuery);
const response = {
hits: soResponse.saved_objects.map((so) =>
savedObjectToItem(so, this.allowedSavedObjectAttributes, false)
),
hits: soResponse.saved_objects.map((so) => this.savedObjectToItem(so)),
pagination: {
total: soResponse.total,
},
Expand Down
Loading