diff --git a/.gitignore b/.gitignore index 6542feb..69ce0a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -lib +./lib node_modules npm-debug.log \ No newline at end of file diff --git a/package.json b/package.json index 523fa45..20b2c60 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "sinon": "~1.17.3" }, "dependencies": { + "elasticsearch": "~11.0.1", "joi": "~8.0.5" } } diff --git a/src/index.js b/src/index.js index d58bd6b..4f231e2 100644 --- a/src/index.js +++ b/src/index.js @@ -1,31 +1,17 @@ import events from 'events'; -import Joi from 'joi'; +import validateSchema from './lib/validate_schema'; export default class Elastique extends events.EventEmitter { constructor(options = {}) { super(); - var schema = Joi.object({ - url: Joi.string().uri({ scheme: ['http', 'https'] }).default('http://localhost:9200'), - index: Joi.string().required(), - interval: Joi.string().default('1w'), - timeout: Joi.number().min(10000).default(10000), - }).default(); - - const validateSchema = () => new Promise(function (resolve, reject) { - schema.validate(options, (err, settings) => { - if (err) return reject(err); - resolve(settings); - }) - }) - this.ready = true; + // initalize the module Promise.all([ - validateSchema() + validateSchema(options) ]) .then(([ settings ]) => { - console.log('settings', settings); this.settings = settings; }) .catch((err) => { diff --git a/src/lib/validate_schema.js b/src/lib/validate_schema.js new file mode 100644 index 0000000..9a76ed1 --- /dev/null +++ b/src/lib/validate_schema.js @@ -0,0 +1,17 @@ +import Joi from 'joi'; + +var schema = Joi.object({ + url: Joi.string().uri({ scheme: ['http', 'https'] }).default('http://localhost:9200'), + index: Joi.string().required(), + interval: Joi.string().default('1w'), + timeout: Joi.number().min(10000).default(10000), +}).default(); + +const validateSchema = (options) => new Promise(function (resolve, reject) { + schema.validate(options, (err, settings) => { + if (err) return reject(err); + resolve(settings); + }) +}) + +export default validateSchema; \ No newline at end of file