forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic workspace saved objects client wrapper
Signed-off-by: Lin Wang <[email protected]>
- Loading branch information
Showing
3 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
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
106 changes: 106 additions & 0 deletions
106
src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.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,106 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
SavedObject, | ||
SavedObjectsBaseOptions, | ||
SavedObjectsBulkCreateObject, | ||
SavedObjectsBulkGetObject, | ||
SavedObjectsBulkResponse, | ||
SavedObjectsClientWrapperFactory, | ||
SavedObjectsCreateOptions, | ||
SavedObjectsDeleteOptions, | ||
SavedObjectsFindOptions, | ||
SavedObjectsUpdateOptions, | ||
SavedObjectsUpdateResponse, | ||
SavedObjectsBulkUpdateObject, | ||
SavedObjectsBulkUpdateResponse, | ||
SavedObjectsBulkUpdateOptions, | ||
} from '../../../../core/server'; | ||
|
||
export class WorkspaceSavedObjectsClientWrapper { | ||
public wrapperFactory: SavedObjectsClientWrapperFactory = (wrapperOptions) => { | ||
const deleteWithWorkspacePermissionControl = async ( | ||
type: string, | ||
id: string, | ||
options: SavedObjectsDeleteOptions = {} | ||
) => { | ||
return await wrapperOptions.client.delete(type, id, options); | ||
}; | ||
|
||
const updateWithWorkspacePermissionControl = async <T = unknown>( | ||
type: string, | ||
id: string, | ||
attributes: Partial<T>, | ||
options: SavedObjectsUpdateOptions = {} | ||
): Promise<SavedObjectsUpdateResponse<T>> => { | ||
return await wrapperOptions.client.update(type, id, attributes, options); | ||
}; | ||
|
||
const bulkUpdateWithWorkspacePermissionControl = async <T = unknown>( | ||
objects: Array<SavedObjectsBulkUpdateObject<T>>, | ||
options?: SavedObjectsBulkUpdateOptions | ||
): Promise<SavedObjectsBulkUpdateResponse<T>> => { | ||
return await wrapperOptions.client.bulkUpdate(objects, options); | ||
}; | ||
|
||
const bulkCreateWithWorkspacePermissionControl = async <T = unknown>( | ||
objects: Array<SavedObjectsBulkCreateObject<T>>, | ||
options: SavedObjectsCreateOptions = {} | ||
): Promise<SavedObjectsBulkResponse<T>> => { | ||
return await wrapperOptions.client.bulkCreate(objects, options); | ||
}; | ||
|
||
const createWithWorkspacePermissionControl = async <T = unknown>( | ||
type: string, | ||
attributes: T, | ||
options?: SavedObjectsCreateOptions | ||
) => { | ||
return await wrapperOptions.client.create(type, attributes, options); | ||
}; | ||
|
||
const getWithWorkspacePermissionControl = async <T = unknown>( | ||
type: string, | ||
id: string, | ||
options: SavedObjectsBaseOptions = {} | ||
): Promise<SavedObject<T>> => { | ||
const objectToGet = await wrapperOptions.client.get<T>(type, id, options); | ||
return objectToGet; | ||
}; | ||
|
||
const bulkGetWithWorkspacePermissionControl = async <T = unknown>( | ||
objects: SavedObjectsBulkGetObject[] = [], | ||
options: SavedObjectsBaseOptions = {} | ||
): Promise<SavedObjectsBulkResponse<T>> => { | ||
const objectToBulkGet = await wrapperOptions.client.bulkGet<T>(objects, options); | ||
|
||
return objectToBulkGet; | ||
}; | ||
|
||
const findWithWorkspacePermissionControl = async <T = unknown>( | ||
options: SavedObjectsFindOptions | ||
) => { | ||
return await wrapperOptions.client.find<T>(options); | ||
}; | ||
|
||
return { | ||
...wrapperOptions.client, | ||
get: getWithWorkspacePermissionControl, | ||
checkConflicts: wrapperOptions.client.checkConflicts, | ||
find: findWithWorkspacePermissionControl, | ||
bulkGet: bulkGetWithWorkspacePermissionControl, | ||
errors: wrapperOptions.client.errors, | ||
addToNamespaces: wrapperOptions.client.addToNamespaces, | ||
deleteFromNamespaces: wrapperOptions.client.deleteFromNamespaces, | ||
create: createWithWorkspacePermissionControl, | ||
bulkCreate: bulkCreateWithWorkspacePermissionControl, | ||
delete: deleteWithWorkspacePermissionControl, | ||
update: updateWithWorkspacePermissionControl, | ||
bulkUpdate: bulkUpdateWithWorkspacePermissionControl, | ||
}; | ||
}; | ||
|
||
constructor() {} | ||
} |