-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Migrate index pattern server side to typescript #43155
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,25 +17,38 @@ | |
* under the License. | ||
*/ | ||
|
||
import Hapi from 'hapi'; | ||
import { APICaller } from 'src/core/server'; | ||
import { Legacy } from 'kibana'; | ||
import KbnServer from 'src/legacy/server/kbn_server'; | ||
import { IndexPatternsService } from './service'; | ||
|
||
import { | ||
createFieldsForWildcardRoute, | ||
createFieldsForTimePatternRoute, | ||
} from './routes'; | ||
import { createFieldsForWildcardRoute, createFieldsForTimePatternRoute } from './routes'; | ||
|
||
export function indexPatternsMixin(kbnServer, server) { | ||
const pre = { | ||
export type IndexPatternsServiceFactory = (args: { | ||
callCluster: (endpoint: string, clientParams: any, options: any) => Promise<any>; | ||
}) => IndexPatternsService; | ||
|
||
interface IndexPatternRequest extends Legacy.Request { | ||
getIndexPatternsService: () => IndexPatternsService; | ||
} | ||
|
||
interface ServerWithFactory extends Legacy.Server { | ||
addMemoizedFactoryToRequest: (...args: any) => void; | ||
} | ||
|
||
export function indexPatternsMixin(kbnServer: KbnServer, server: ServerWithFactory) { | ||
const pre: Record<string, Hapi.RouteOptionsPreAllOptions> = { | ||
/** | ||
* Create an instance of the `indexPatterns` service | ||
* @type {Hapi.Pre} | ||
*/ | ||
* Create an instance of the `indexPatterns` service | ||
* @type {Hapi.Pre} | ||
*/ | ||
getIndexPatternsService: { | ||
assign: 'indexPatterns', | ||
method(request) { | ||
method(request: IndexPatternRequest) { | ||
return request.getIndexPatternsService(); | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
|
||
/** | ||
|
@@ -44,9 +57,13 @@ export function indexPatternsMixin(kbnServer, server) { | |
* @method server.indexPatternsServiceFactory | ||
* @type {IndexPatternsService} | ||
*/ | ||
server.decorate('server', 'indexPatternsServiceFactory', ({ callCluster }) => { | ||
return new IndexPatternsService(callCluster); | ||
}); | ||
server.decorate( | ||
'server', | ||
'indexPatternsServiceFactory', | ||
({ callCluster }: { callCluster: APICaller }) => { | ||
return new IndexPatternsService(callCluster); | ||
} | ||
); | ||
|
||
/** | ||
* Get an instance of the IndexPatternsService configured for use | ||
|
@@ -55,9 +72,10 @@ export function indexPatternsMixin(kbnServer, server) { | |
* @method request.getIndexPatternsService | ||
* @type {IndexPatternsService} | ||
*/ | ||
server.addMemoizedFactoryToRequest('getIndexPatternsService', request => { | ||
server.addMemoizedFactoryToRequest('getIndexPatternsService', (request: Legacy.Request) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
const { callWithRequest } = request.server.plugins.elasticsearch.getCluster('data'); | ||
const callCluster = (...args) => callWithRequest(request, ...args); | ||
const callCluster = (endpoint: string, params: any, options: any) => | ||
callWithRequest(request, endpoint, params, options); | ||
return server.indexPatternsServiceFactory({ callCluster }); | ||
}); | ||
|
||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ | |
* under the License. | ||
*/ | ||
|
||
export { indexPatternsMixin } from './mixin'; | ||
export * from './index_patterns_service'; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lukeelmers There's an error I can't figure about the Request types here, can you take a look?