Skip to content

Commit

Permalink
add typeRegistry to SavedObjectClientWrapperOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Feb 25, 2020
1 parent 6c8a015 commit 18f5c05
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface SavedObjectsClientWrapperOptions
| --- | --- | --- |
| [client](./kibana-plugin-server.savedobjectsclientwrapperoptions.client.md) | <code>SavedObjectsClientContract</code> | |
| [request](./kibana-plugin-server.savedobjectsclientwrapperoptions.request.md) | <code>KibanaRequest</code> | |
| [typeRegistry](./kibana-plugin-server.savedobjectsclientwrapperoptions.typeregistry.md) | <code>ISavedObjectTypeRegistry</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsClientWrapperOptions](./kibana-plugin-server.savedobjectsclientwrapperoptions.md) &gt; [typeRegistry](./kibana-plugin-server.savedobjectsclientwrapperoptions.typeregistry.md)

## SavedObjectsClientWrapperOptions.typeRegistry property

<b>Signature:</b>

```typescript
typeRegistry: ISavedObjectTypeRegistry;
```
1 change: 1 addition & 0 deletions src/core/server/saved_objects/saved_objects_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ export class SavedObjectsService
const repository = repositoryFactory.createScopedRepository(request);
return new SavedObjectsClient(repository);
},
typeRegistry: this.typeRegistry,
});
if (this.clientFactoryProvider) {
const clientFactory = this.clientFactoryProvider(repositoryFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { SavedObjectsClientProvider } from './scoped_client_provider';
import { typeRegistryMock } from '../../saved_objects_type_registry.mock';

test(`uses default client factory when one isn't set`, () => {
const returnValue = Symbol();
Expand All @@ -26,6 +27,7 @@ test(`uses default client factory when one isn't set`, () => {

const clientProvider = new SavedObjectsClientProvider({
defaultClientFactory: defaultClientFactoryMock,
typeRegistry: typeRegistryMock.create(),
});
const result = clientProvider.getClient(request);

Expand All @@ -44,6 +46,7 @@ test(`uses custom client factory when one is set`, () => {

const clientProvider = new SavedObjectsClientProvider({
defaultClientFactory: defaultClientFactoryMock,
typeRegistry: typeRegistryMock.create(),
});
clientProvider.setClientFactory(customClientFactoryMock);
const result = clientProvider.getClient(request);
Expand All @@ -68,6 +71,7 @@ test(`throws error when registering a wrapper with a duplicate id`, () => {
const defaultClientFactoryMock = jest.fn();
const clientProvider = new SavedObjectsClientProvider({
defaultClientFactory: defaultClientFactoryMock,
typeRegistry: typeRegistryMock.create(),
});
const firstClientWrapperFactoryMock = jest.fn();
const secondClientWrapperFactoryMock = jest.fn();
Expand All @@ -80,9 +84,11 @@ test(`throws error when registering a wrapper with a duplicate id`, () => {

test(`invokes and uses wrappers in specified order`, () => {
const defaultClient = Symbol();
const typeRegistry = typeRegistryMock.create();
const defaultClientFactoryMock = jest.fn().mockReturnValue(defaultClient);
const clientProvider = new SavedObjectsClientProvider({
defaultClientFactory: defaultClientFactoryMock,
typeRegistry,
});
const firstWrappedClient = Symbol('first client');
const firstClientWrapperFactoryMock = jest.fn().mockReturnValue(firstWrappedClient);
Expand All @@ -98,18 +104,22 @@ test(`invokes and uses wrappers in specified order`, () => {
expect(firstClientWrapperFactoryMock).toHaveBeenCalledWith({
request,
client: secondWrapperClient,
typeRegistry,
});
expect(secondClientWrapperFactoryMock).toHaveBeenCalledWith({
request,
client: defaultClient,
typeRegistry,
});
});

test(`does not invoke or use excluded wrappers`, () => {
const defaultClient = Symbol();
const typeRegistry = typeRegistryMock.create();
const defaultClientFactoryMock = jest.fn().mockReturnValue(defaultClient);
const clientProvider = new SavedObjectsClientProvider({
defaultClientFactory: defaultClientFactoryMock,
typeRegistry,
});
const firstWrappedClient = Symbol('first client');
const firstClientWrapperFactoryMock = jest.fn().mockReturnValue(firstWrappedClient);
Expand All @@ -128,6 +138,7 @@ test(`does not invoke or use excluded wrappers`, () => {
expect(firstClientWrapperFactoryMock).toHaveBeenCalledWith({
request,
client: defaultClient,
typeRegistry,
});
expect(secondClientWrapperFactoryMock).not.toHaveBeenCalled();
});
Expand All @@ -137,6 +148,7 @@ test(`allows all wrappers to be excluded`, () => {
const defaultClientFactoryMock = jest.fn().mockReturnValue(defaultClient);
const clientProvider = new SavedObjectsClientProvider({
defaultClientFactory: defaultClientFactoryMock,
typeRegistry: typeRegistryMock.create(),
});
const firstWrappedClient = Symbol('first client');
const firstClientWrapperFactoryMock = jest.fn().mockReturnValue(firstWrappedClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { PriorityCollection } from './priority_collection';
import { SavedObjectsClientContract } from '../../types';
import { SavedObjectsRepositoryFactory } from '../../saved_objects_service';
import { ISavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import { KibanaRequest } from '../../../http';

/**
Expand All @@ -27,6 +28,7 @@ import { KibanaRequest } from '../../../http';
*/
export interface SavedObjectsClientWrapperOptions {
client: SavedObjectsClientContract;
typeRegistry: ISavedObjectTypeRegistry;
request: KibanaRequest;
}

Expand Down Expand Up @@ -84,9 +86,17 @@ export class SavedObjectsClientProvider {
}>();
private _clientFactory: SavedObjectsClientFactory;
private readonly _originalClientFactory: SavedObjectsClientFactory;

constructor({ defaultClientFactory }: { defaultClientFactory: SavedObjectsClientFactory }) {
private readonly _typeRegistry: ISavedObjectTypeRegistry;

constructor({
defaultClientFactory,
typeRegistry,
}: {
defaultClientFactory: SavedObjectsClientFactory;
typeRegistry: ISavedObjectTypeRegistry;
}) {
this._originalClientFactory = this._clientFactory = defaultClientFactory;
this._typeRegistry = typeRegistry;
}

addClientWrapperFactory(
Expand Down Expand Up @@ -129,6 +139,7 @@ export class SavedObjectsClientProvider {
return factory({
request,
client: clientToWrap,
typeRegistry: this._typeRegistry,
});
}, client);
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,8 @@ export interface SavedObjectsClientWrapperOptions {
client: SavedObjectsClientContract;
// (undocumented)
request: KibanaRequest;
// (undocumented)
typeRegistry: ISavedObjectTypeRegistry;
}

// @public
Expand Down

0 comments on commit 18f5c05

Please sign in to comment.