{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/kibana/pulls/comments/201652477","pull_request_review_id":136193743,"id":201652477,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMTY1MjQ3Nw==","diff_hunk":"@@ -0,0 +1,112 @@\n+/*\n+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n+ * or more contributor license agreements. Licensed under the Elastic License;\n+ * you may not use this file except in compliance with the Elastic License.\n+ */\n+\n+import { FrameworkRequest } from '../famework/adapter_types';\n+import {\n+  DatabaseAdapter,\n+  DatabaseBulkIndexDocumentsParams,\n+  DatabaseCreateDocumentParams,\n+  DatabaseCreateDocumentResponse,\n+  DatabaseDeleteDocumentParams,\n+  DatabaseDeleteDocumentResponse,\n+  DatabaseGetDocumentResponse,\n+  DatabaseGetParams,\n+  DatabaseIndexDocumentParams,\n+  DatabaseKbnESCluster,\n+  DatabaseKbnESPlugin,\n+  DatabaseMGetParams,\n+  DatabaseMGetResponse,\n+  DatabasePutTemplateParams,\n+  DatabaseSearchParams,\n+  DatabaseSearchResponse,\n+} from './adapter_types';\n+\n+export class KibanaDatabaseAdapter implements DatabaseAdapter {\n+  private es: DatabaseKbnESCluster;\n+\n+  constructor(kbnElasticSearch: DatabaseKbnESPlugin) {\n+    this.es = kbnElasticSearch.getCluster('admin');\n+  }\n+  public async putTemplate(\n+    req: FrameworkRequest | null,\n+    params: DatabasePutTemplateParams\n+  ): Promise<any> {\n+    const callES = this.getCallType(req);\n+    const result = await callES('indices.putTemplate', params);\n+    return result;\n+  }\n+\n+  public async get<Source>(\n+    req: FrameworkRequest | null,\n+    params: DatabaseGetParams\n+  ): Promise<DatabaseGetDocumentResponse<Source>> {\n+    const callES = this.getCallType(req);\n+    const result = await callES('get', params);\n+    return result;\n+    // todo\n+  }\n+\n+  public async mget<T>(\n+    req: FrameworkRequest | null,\n+    params: DatabaseMGetParams\n+  ): Promise<DatabaseMGetResponse<T>> {\n+    const callES = this.getCallType(req);\n+    const result = await callES('mget', params);\n+    return result;\n+    // todo\n+  }\n+\n+  public async bulk(\n+    req: FrameworkRequest | null,\n+    params: DatabaseBulkIndexDocumentsParams\n+  ): Promise<any> {\n+    const callES = this.getCallType(req);\n+    const result = await callES('bulk', params);\n+    return result;\n+  }\n+\n+  public async create(\n+    req: FrameworkRequest | null,\n+    params: DatabaseCreateDocumentParams\n+  ): Promise<DatabaseCreateDocumentResponse> {\n+    const callES = this.getCallType(req);\n+    const result = await callES('create', params);\n+    return result;\n+  }\n+  public async index<T>(\n+    req: FrameworkRequest | null,\n+    params: DatabaseIndexDocumentParams<T>\n+  ): Promise<any> {\n+    const callES = this.getCallType(req);\n+    const result = await callES('index', params);\n+    return result;\n+  }\n+  public async delete(\n+    req: FrameworkRequest | null,\n+    params: DatabaseDeleteDocumentParams\n+  ): Promise<DatabaseDeleteDocumentResponse> {\n+    const callES = this.getCallType(req);\n+    const result = await callES('delete', params);\n+    return result;\n+  }\n+\n+  public async search<Source>(\n+    req: FrameworkRequest | null,\n+    params: DatabaseSearchParams\n+  ): Promise<DatabaseSearchResponse<Source>> {\n+    const callES = this.getCallType(req);\n+    const result = await callES('search', params);\n+    return result;\n+  }\n+\n+  private getCallType(req: FrameworkRequest | null): any {","path":"x-pack/plugins/beats/server/lib/adapters/database/kibana_database_adapter.ts","position":105,"original_position":105,"commit_id":"e430b441cbd0ba13f39f1986e7a02eef06938050","original_commit_id":"e430b441cbd0ba13f39f1986e7a02eef06938050","user":{"login":"mattapperson","id":192433,"node_id":"MDQ6VXNlcjE5MjQzMw==","avatar_url":"https://avatars2.githubusercontent.com/u/192433?v=4","gravatar_id":"","url":"https://api.github.com/users/mattapperson","html_url":"https://github.com/mattapperson","followers_url":"https://api.github.com/users/mattapperson/followers","following_url":"https://api.github.com/users/mattapperson/following{/other_user}","gists_url":"https://api.github.com/users/mattapperson/gists{/gist_id}","starred_url":"https://api.github.com/users/mattapperson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattapperson/subscriptions","organizations_url":"https://api.github.com/users/mattapperson/orgs","repos_url":"https://api.github.com/users/mattapperson/repos","events_url":"https://api.github.com/users/mattapperson/events{/privacy}","received_events_url":"https://api.github.com/users/mattapperson/received_events","type":"User","site_admin":false},"body":"I did this because the typing on data returned from callWithRequest is assumed, and in fact at runtime could be very incorrect. This framework adapter is only used by other domain based adapters such as a beats or tags adapter. Those other adapters primary action is to conform the returned data and return it neatly. Thus expecting any from this (or unknown in future versions of TS) then properly formatting at runtime and returning an accurate type is IMHO a more \"honest\" approach to typing this solution.","created_at":"2018-07-11T11:17:31Z","updated_at":"2018-07-11T11:17:31Z","html_url":"https://github.com/elastic/kibana/pull/20566#discussion_r201652477","pull_request_url":"https://api.github.com/repos/elastic/kibana/pulls/20566","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/elastic/kibana/pulls/comments/201652477"},"html":{"href":"https://github.com/elastic/kibana/pull/20566#discussion_r201652477"},"pull_request":{"href":"https://api.github.com/repos/elastic/kibana/pulls/20566"}},"in_reply_to_id":201414845},"pull_request":{"url":"https://api.github.com/repos/elastic/kibana/pulls/20566","id":200147819,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAwMTQ3ODE5","html_url":"https://github.com/elastic/kibana/pull/20566","diff_url":"https://github.com/elastic/kibana/pull/20566.diff","patch_url":"https://github.com/elastic/kibana/pull/20566.patch","issue_url":"https://api.github.com/repos/elastic/kibana/issues/20566","number":20566,"state":"open","locked":false,"title":"[Beats Management] add more tests, update types, break out ES into it's own adapter","user":{"login":"mattapperson","id":192433,"node_id":"MDQ6VXNlcjE5MjQzMw==","avatar_url":"https://avatars2.githubusercontent.com/u/192433?v=4","gravatar_id":"","url":"https://api.github.com/users/mattapperson","html_url":"https://github.com/mattapperson","followers_url":"https://api.github.com/users/mattapperson/followers","following_url":"https://api.github.com/users/mattapperson/following{/other_user}","gists_url":"https://api.github.com/users/mattapperson/gists{/gist_id}","starred_url":"https://api.github.com/users/mattapperson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattapperson/subscriptions","organizations_url":"https://api.github.com/users/mattapperson/orgs","repos_url":"https://api.github.com/users/mattapperson/repos","events_url":"https://api.github.com/users/mattapperson/events{/privacy}","received_events_url":"https://api.github.com/users/mattapperson/received_events","type":"User","site_admin":false},"body":"Sorry, but this PR is sort of a catch-all for a few cleanup tasks.\r\n\r\n1) This adds a few additional tests\r\n2) It adds a lot more types, particularly around Kibana's ES plugin\r\n3) Broke out all ES related functions into its own `DatabaseAdapter`\r\n4) Broke out types related to adapters into their own TS files inside their pater folders\r\n5) Began a convention of prefixing types related to an adapter with the name of the adapter type, thus making it easier to know what types resided where when using a type too\r\n\r\nOnce the convention change is accepted I can PR a change to the docs to include said changes\r\n","created_at":"2018-07-09T16:04:00Z","updated_at":"2018-07-11T11:17:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"126ccdcdc21557284c7e575fa971e0862abde2cf","assignee":null,"assignees":[],"requested_reviewers":[{"login":"simianhacker","id":41702,"node_id":"MDQ6VXNlcjQxNzAy","avatar_url":"https://avatars2.githubusercontent.com/u/41702?v=4","gravatar_id":"","url":"https://api.github.com/users/simianhacker","html_url":"https://github.com/simianhacker","followers_url":"https://api.github.com/users/simianhacker/followers","following_url":"https://api.github.com/users/simianhacker/following{/other_user}","gists_url":"https://api.github.com/users/simianhacker/gists{/gist_id}","starred_url":"https://api.github.com/users/simianhacker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simianhacker/subscriptions","organizations_url":"https://api.github.com/users/simianhacker/orgs","repos_url":"https://api.github.com/users/simianhacker/repos","events_url":"https://api.github.com/users/simianhacker/events{/privacy}","received_events_url":"https://api.github.com/users/simianhacker/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":498301841,"node_id":"MDU6TGFiZWw0OTgzMDE4NDE=","url":"https://api.github.com/repos/elastic/kibana/labels/:Beats","name":":Beats","color":"bfdadc","default":false},{"id":981817023,"node_id":"MDU6TGFiZWw5ODE4MTcwMjM=","url":"https://api.github.com/repos/elastic/kibana/labels/:Ingest%20UI","name":":Ingest UI","color":"c5def5","default":false},{"id":470241819,"node_id":"MDU6TGFiZWw0NzAyNDE4MTk=","url":"https://api.github.com/repos/elastic/kibana/labels/:Management","name":":Management","color":"fef2c0","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/kibana/pulls/20566/commits","review_comments_url":"https://api.github.com/repos/elastic/kibana/pulls/20566/comments","review_comment_url":"https://api.github.com/repos/elastic/kibana/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/kibana/issues/20566/comments","statuses_url":"https://api.github.com/repos/elastic/kibana/statuses/e430b441cbd0ba13f39f1986e7a02eef06938050","head":{"label":"mattapperson:beats-cm-add-more-tests","ref":"beats-cm-add-more-tests","sha":"e430b441cbd0ba13f39f1986e7a02eef06938050","user":{"login":"mattapperson","id":192433,"node_id":"MDQ6VXNlcjE5MjQzMw==","avatar_url":"https://avatars2.githubusercontent.com/u/192433?v=4","gravatar_id":"","url":"https://api.github.com/users/mattapperson","html_url":"https://github.com/mattapperson","followers_url":"https://api.github.com/users/mattapperson/followers","following_url":"https://api.github.com/users/mattapperson/following{/other_user}","gists_url":"https://api.github.com/users/mattapperson/gists{/gist_id}","starred_url":"https://api.github.com/users/mattapperson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattapperson/subscriptions","organizations_url":"https://api.github.com/users/mattapperson/orgs","repos_url":"https://api.github.com/users/mattapperson/repos","events_url":"https://api.github.com/users/mattapperson/events{/privacy}","received_events_url":"https://api.github.com/users/mattapperson/received_events","type":"User","site_admin":false},"repo":{"id":105545794,"node_id":"MDEwOlJlcG9zaXRvcnkxMDU1NDU3OTQ=","name":"kibana","full_name":"mattapperson/kibana","owner":{"login":"mattapperson","id":192433,"node_id":"MDQ6VXNlcjE5MjQzMw==","avatar_url":"https://avatars2.githubusercontent.com/u/192433?v=4","gravatar_id":"","url":"https://api.github.com/users/mattapperson","html_url":"https://github.com/mattapperson","followers_url":"https://api.github.com/users/mattapperson/followers","following_url":"https://api.github.com/users/mattapperson/following{/other_user}","gists_url":"https://api.github.com/users/mattapperson/gists{/gist_id}","starred_url":"https://api.github.com/users/mattapperson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattapperson/subscriptions","organizations_url":"https://api.github.com/users/mattapperson/orgs","repos_url":"https://api.github.com/users/mattapperson/repos","events_url":"https://api.github.com/users/mattapperson/events{/privacy}","received_events_url":"https://api.github.com/users/mattapperson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mattapperson/kibana","description":":bar_chart: Kibana analytics and search dashboard for Elasticsearch","fork":true,"url":"https://api.github.com/repos/mattapperson/kibana","forks_url":"https://api.github.com/repos/mattapperson/kibana/forks","keys_url":"https://api.github.com/repos/mattapperson/kibana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mattapperson/kibana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mattapperson/kibana/teams","hooks_url":"https://api.github.com/repos/mattapperson/kibana/hooks","issue_events_url":"https://api.github.com/repos/mattapperson/kibana/issues/events{/number}","events_url":"https://api.github.com/repos/mattapperson/kibana/events","assignees_url":"https://api.github.com/repos/mattapperson/kibana/assignees{/user}","branches_url":"https://api.github.com/repos/mattapperson/kibana/branches{/branch}","tags_url":"https://api.github.com/repos/mattapperson/kibana/tags","blobs_url":"https://api.github.com/repos/mattapperson/kibana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mattapperson/kibana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mattapperson/kibana/git/refs{/sha}","trees_url":"https://api.github.com/repos/mattapperson/kibana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mattapperson/kibana/statuses/{sha}","languages_url":"https://api.github.com/repos/mattapperson/kibana/languages","stargazers_url":"https://api.github.com/repos/mattapperson/kibana/stargazers","contributors_url":"https://api.github.com/repos/mattapperson/kibana/contributors","subscribers_url":"https://api.github.com/repos/mattapperson/kibana/subscribers","subscription_url":"https://api.github.com/repos/mattapperson/kibana/subscription","commits_url":"https://api.github.com/repos/mattapperson/kibana/commits{/sha}","git_commits_url":"https://api.github.com/repos/mattapperson/kibana/git/commits{/sha}","comments_url":"https://api.github.com/repos/mattapperson/kibana/comments{/number}","issue_comment_url":"https://api.github.com/repos/mattapperson/kibana/issues/comments{/number}","contents_url":"https://api.github.com/repos/mattapperson/kibana/contents/{+path}","compare_url":"https://api.github.com/repos/mattapperson/kibana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mattapperson/kibana/merges","archive_url":"https://api.github.com/repos/mattapperson/kibana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mattapperson/kibana/downloads","issues_url":"https://api.github.com/repos/mattapperson/kibana/issues{/number}","pulls_url":"https://api.github.com/repos/mattapperson/kibana/pulls{/number}","milestones_url":"https://api.github.com/repos/mattapperson/kibana/milestones{/number}","notifications_url":"https://api.github.com/repos/mattapperson/kibana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mattapperson/kibana/labels{/name}","releases_url":"https://api.github.com/repos/mattapperson/kibana/releases{/id}","deployments_url":"https://api.github.com/repos/mattapperson/kibana/deployments","created_at":"2017-10-02T14:42:39Z","updated_at":"2017-10-02T14:42:48Z","pushed_at":"2018-07-10T09:48:09Z","git_url":"git://github.com/mattapperson/kibana.git","ssh_url":"git@github.com:mattapperson/kibana.git","clone_url":"https://github.com/mattapperson/kibana.git","svn_url":"https://github.com/mattapperson/kibana","homepage":"https://www.elastic.co/products/kibana","size":411642,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:feature/x-pack/management/beats","ref":"feature/x-pack/management/beats","sha":"95ed451ca458f9f33779ba42272ab9113c2024b0","user":{"login":"elastic","id":6764390,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3NjQzOTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":7833168,"node_id":"MDEwOlJlcG9zaXRvcnk3ODMzMTY4","name":"kibana","full_name":"elastic/kibana","owner":{"login":"elastic","id":6764390,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3NjQzOTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/kibana","description":":bar_chart: Kibana analytics and search dashboard for Elasticsearch","fork":false,"url":"https://api.github.com/repos/elastic/kibana","forks_url":"https://api.github.com/repos/elastic/kibana/forks","keys_url":"https://api.github.com/repos/elastic/kibana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/kibana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/kibana/teams","hooks_url":"https://api.github.com/repos/elastic/kibana/hooks","issue_events_url":"https://api.github.com/repos/elastic/kibana/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/kibana/events","assignees_url":"https://api.github.com/repos/elastic/kibana/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/kibana/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/kibana/tags","blobs_url":"https://api.github.com/repos/elastic/kibana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/kibana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/kibana/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/kibana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/kibana/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/kibana/languages","stargazers_url":"https://api.github.com/repos/elastic/kibana/stargazers","contributors_url":"https://api.github.com/repos/elastic/kibana/contributors","subscribers_url":"https://api.github.com/repos/elastic/kibana/subscribers","subscription_url":"https://api.github.com/repos/elastic/kibana/subscription","commits_url":"https://api.github.com/repos/elastic/kibana/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/kibana/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/kibana/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/kibana/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/kibana/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/kibana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/kibana/merges","archive_url":"https://api.github.com/repos/elastic/kibana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/kibana/downloads","issues_url":"https://api.github.com/repos/elastic/kibana/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/kibana/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/kibana/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/kibana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/kibana/labels{/name}","releases_url":"https://api.github.com/repos/elastic/kibana/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/kibana/deployments","created_at":"2013-01-26T04:00:59Z","updated_at":"2018-07-11T10:19:31Z","pushed_at":"2018-07-11T11:10:20Z","git_url":"git://github.com/elastic/kibana.git","ssh_url":"git@github.com:elastic/kibana.git","clone_url":"https://github.com/elastic/kibana.git","svn_url":"https://github.com/elastic/kibana","homepage":"https://www.elastic.co/products/kibana","size":426459,"stargazers_count":9647,"watchers_count":9647,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3775,"mirror_url":null,"archived":false,"open_issues_count":3312,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":3775,"open_issues":3312,"watchers":9647,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/kibana/pulls/20566"},"html":{"href":"https://github.com/elastic/kibana/pull/20566"},"issue":{"href":"https://api.github.com/repos/elastic/kibana/issues/20566"},"comments":{"href":"https://api.github.com/repos/elastic/kibana/issues/20566/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/kibana/pulls/20566/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/kibana/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/kibana/pulls/20566/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/kibana/statuses/e430b441cbd0ba13f39f1986e7a02eef06938050"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mattapperson"}}