From 5e5b489cb97892def5455b7fb2fcf173453ef2cf Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 26 Nov 2020 17:03:18 +0000 Subject: [PATCH] elasticsearch end to end --- packages/server/package.json | 1 + packages/server/src/integrations/couchdb.js | 43 +++++++++++++++++++ .../server/src/integrations/elasticsearch.js | 41 ++++++++++++++++++ packages/server/src/integrations/index.js | 8 +++- packages/server/yarn.lock | 21 +++++++++ 5 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 packages/server/src/integrations/couchdb.js create mode 100644 packages/server/src/integrations/elasticsearch.js diff --git a/packages/server/package.json b/packages/server/package.json index eedcb89973..7b9e5c61bf 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -51,6 +51,7 @@ "license": "AGPL-3.0-or-later", "dependencies": { "@budibase/client": "^0.3.8", + "@elastic/elasticsearch": "^7.10.0", "@koa/router": "^8.0.0", "@sendgrid/mail": "^7.1.1", "@sentry/node": "^5.19.2", diff --git a/packages/server/src/integrations/couchdb.js b/packages/server/src/integrations/couchdb.js new file mode 100644 index 0000000000..e44cf9e34c --- /dev/null +++ b/packages/server/src/integrations/couchdb.js @@ -0,0 +1,43 @@ +// const PouchDB = require("pouchdb") + +// const COUCHDB_OPTIONS = { +// url: { +// type: "string", +// required: true, +// default: "localhost", +// }, +// database: { +// type: "string", +// required: true, +// }, +// // query: { +// // type: "query", +// // required: true, +// // }, +// } + +// class ElasticSearchIntegration { +// constructor(config) { +// this.config = config +// this.client = new Client({ node: config.url }) +// } + +// async query() { +// try { +// const result = await this.client.search({ +// index: this.config.index, +// body: JSON.parse(this.config.query), +// }) +// return result +// } finally { +// await this.client.close() +// } +// } +// } + +// module.exports = { +// schema: ELASTICSEARCH_OPTIONS, +// integration: ElasticSearchIntegration, +// } + + diff --git a/packages/server/src/integrations/elasticsearch.js b/packages/server/src/integrations/elasticsearch.js new file mode 100644 index 0000000000..d030bae9c8 --- /dev/null +++ b/packages/server/src/integrations/elasticsearch.js @@ -0,0 +1,41 @@ +const { Client } = require("@elastic/elasticsearch") + +const ELASTICSEARCH_OPTIONS = { + url: { + type: "string", + required: true, + default: "localhost", + }, + index: { + type: "string", + required: true, + }, + query: { + type: "query", + required: true, + }, +} + +class ElasticSearchIntegration { + constructor(config) { + this.config = config + this.client = new Client({ node: config.url }) + } + + async query() { + try { + const result = await this.client.search({ + index: this.config.index, + body: JSON.parse(this.config.query), + }) + return result.body.hits.hits.map(({ _source }) => _source) + } finally { + await this.client.close() + } + } +} + +module.exports = { + schema: ELASTICSEARCH_OPTIONS, + integration: ElasticSearchIntegration, +} diff --git a/packages/server/src/integrations/index.js b/packages/server/src/integrations/index.js index 373176b864..4cdb78f703 100644 --- a/packages/server/src/integrations/index.js +++ b/packages/server/src/integrations/index.js @@ -1,21 +1,25 @@ const postgres = require("./postgres") const dynamodb = require("./dynamodb") const mongodb = require("./mongodb") +const elasticsearch = require("./elasticsearch") +const couchdb = require("./couchdb") // const redis = require("./redis") -// const couchdb = require("./couchdb") -// const elasticsearch = require("./elasticsearch") // const s3 = require("./s3") const DEFINITIONS = { POSTGRES: postgres.schema, DYNAMODB: dynamodb.schema, MONGODB: mongodb.schema, + ELASTICSEARCH: elasticsearch.schema, + COUCHDB: couchdb.schema, } const INTEGRATIONS = { POSTGRES: postgres.integration, DYNAMODB: dynamodb.integration, MONGODB: mongodb.integration, + ELASTICSEARCH: elasticsearch.integration, + COUCHDB: couchdb.integration, } module.exports = { diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index e931128f0c..5e7317cd19 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -225,6 +225,17 @@ ajv "^6.12.0" ajv-keywords "^3.4.1" +"@elastic/elasticsearch@^7.10.0": + version "7.10.0" + resolved "https://registry.yarnpkg.com/@elastic/elasticsearch/-/elasticsearch-7.10.0.tgz#da105a9c1f14146f9f2cab4e7026cb7949121b8d" + integrity sha512-vXtMAQf5/DwqeryQgRriMtnFppJNLc/R7/R0D8E+wG5/kGM5i7mg+Hi7TM4NZEuXgtzZ2a/Nf7aR0vLyrxOK/w== + dependencies: + debug "^4.1.1" + hpagent "^0.1.1" + ms "^2.1.1" + pump "^3.0.0" + secure-json-parse "^2.1.0" + "@electron/get@^1.0.1": version "1.12.2" resolved "https://registry.yarnpkg.com/@electron/get/-/get-1.12.2.tgz#6442066afb99be08cefb9a281e4b4692b33764f3" @@ -3650,6 +3661,11 @@ hosted-git-info@^3.0.5: dependencies: lru-cache "^6.0.0" +hpagent@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/hpagent/-/hpagent-0.1.1.tgz#66f67f16e5c7a8b59a068e40c2658c2c749ad5e2" + integrity sha512-IxJWQiY0vmEjetHdoE9HZjD4Cx+mYTr25tR7JCxXaiI3QxW0YqYyM11KyZbHufoa/piWhMb2+D3FGpMgmA2cFQ== + html-encoding-sniffer@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/html-encoding-sniffer/-/html-encoding-sniffer-1.0.2.tgz#e70d84b94da53aa375e11fe3a351be6642ca46f8" @@ -6987,6 +7003,11 @@ sax@>=0.6.0, sax@^1.2.4: resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== +secure-json-parse@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-2.1.0.tgz#ae76f5624256b5c497af887090a5d9e156c9fb20" + integrity sha512-GckO+MS/wT4UogDyoI/H/S1L0MCcKS1XX/vp48wfmU7Nw4woBmb8mIpu4zPBQjKlRT88/bt9xdoV4111jPpNJA== + seek-bzip@^1.0.5: version "1.0.6" resolved "https://registry.yarnpkg.com/seek-bzip/-/seek-bzip-1.0.6.tgz#35c4171f55a680916b52a07859ecf3b5857f21c4"