Skip to content

Commit

Permalink
[server/indexPatterns] expose indexPatternService getter/factory (#13012
Browse files Browse the repository at this point in the history
)
  • Loading branch information
spalger authored Jul 31, 2017
1 parent abcc055 commit 9389f0b
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/server/index_patterns/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,35 @@ export function indexPatternsMixin(kbnServer, server) {
*/
getIndexPatternsService: {
assign: 'indexPatterns',
method(req, reply) {
const dataCluster = req.server.plugins.elasticsearch.getCluster('data');
const callDataCluster = (...args) => (
dataCluster.callWithRequest(req, ...args)
);

reply(new IndexPatternsService(callDataCluster));
method(request, reply) {
reply(request.getIndexPatternsService());
}
}
};

/**
* Create an instance of the IndexPatternsService
*
* @method server.indexPatternsServiceFactory
* @type {IndexPatternsService}
*/
server.decorate('server', 'indexPatternsServiceFactory', ({ callCluster }) => {
return new IndexPatternsService(callCluster);
});

/**
* Get an instance of the IndexPatternsService configured for use
* the current request
*
* @method request.getIndexPatternsService
* @type {IndexPatternsService}
*/
server.addMemoizedFactoryToRequest('getIndexPatternsService', request => {
const { callWithRequest } = request.server.plugins.elasticsearch.getCluster('data');
const callCluster = (...args) => callWithRequest(request, ...args);
return server.indexPatternsServiceFactory({ callCluster });
});

server.route(createFieldsForWildcardRoute(pre));
server.route(createFieldsForTimePatternRoute(pre));
}

0 comments on commit 9389f0b

Please sign in to comment.