Skip to content

Commit

Permalink
Merge pull request #227 from agco/feature/update-master
Browse files Browse the repository at this point in the history
Feature/update master
  • Loading branch information
ShurakaiSoft authored Sep 28, 2017
2 parents e036a16 + aaa0143 commit 7cfa4b0
Show file tree
Hide file tree
Showing 56 changed files with 11,397 additions and 5,769 deletions.
36 changes: 36 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"plugins": ["node"],
"extends": ["eslint:recommended", "plugin:node/recommended"],
"rules": {
"node/exports-style": ["error", "module.exports"],
"semi": 2,
"indent": ["error", 2],
"no-console": 0,
"node/no-unpublished-require": ["error", {
"allowModules": [
"supertest",
"should",
"chai",
"chai-http",
"agco-event-source-stream",
"before",
"sinon",
"nock",
"request-debug",
"profanity-util"
],
"tryExtensions": [".js", ".json", ".node"]
}]
},
"globals": {
"describe": true,
"before": true,
"it": true,
"expect": true,
"beforeEach": true,
"afterEach": true,
"supertest": true,
"context": true,
"chai": true
}
}
25 changes: 7 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
language: node_js
node_js:
- '4.2.0'
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
env:
- CXX=g++-4.8 DEBUG=events-reader MONGODB_URL=mongodb://127.0.0.1:27017/test OPLOG_MONGODB_URL=mongodb://127.0.0.1:27017/local
- '8.4.0'
services:
- docker
before_script:
- mongo --version
- mkdir -p db/test
- mongod --port 27017 --dbpath db/test --replSet rs0 --oplogSize 20 --noprealloc --fork --smallfiles --logpath mongodb.log
- sleep 3
- mongo admin --eval 'printjson(rs.initiate());'
- sleep 20
script: ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
- docker-compose -f docker-compose.test.yml up -d db
- docker-compose -f docker-compose.test.yml up initReplicaset
- docker-compose -f docker-compose.test.yml build test
script: docker-compose -f docker-compose.test.yml run test
deploy:
provider: npm
email: [email protected]
Expand All @@ -27,4 +17,3 @@ deploy:
tags: true
repo: agco/harvesterjs
branch: master

13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:8.4.0

ENV HOME=/home/app/

COPY package.json $HOME/harvesterjs/

WORKDIR $HOME/harvesterjs/

RUN npm install --progress=false

COPY . $HOME/harvesterjs/

CMD ["npm", "test"]
17 changes: 17 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "2"
services:
test:
build: .
command: bash -c "sleep 20 && npm test"
depends_on:
- db
environment:
- DEBUG=
- MONGODB_URL=mongodb://db:27017/test
- OPLOG_MONGODB_URL=mongodb://db:27017/local
db:
image: mongo:3.4.0
command: mongod --replSet rs0 --oplogSize 20 --smallfiles --nojournal
initReplicaset:
image: mongo:3.4.0
command: bash -c "sleep 10 && mongo admin --host db:27017 --eval 'printjson(rs.initiate());'"
73 changes: 37 additions & 36 deletions examples/artists_insertAndStream.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
var harvester = require('../lib/harvester');
'use strict';
// eslint-disable-next-line
let harvester = require('../lib/harvester');

var dockerHostURL = process.env.DOCKER_HOST;
var mongodbHostname;
let dockerHostURL = process.env.DOCKER_HOST;
let mongodbHostname;
// if Mongodb is being run from Docker the DOCKER_HOST env variable should be set
// use this value to derive the hostname for the Mongodb connection params
if (dockerHostURL) {
mongodbHostname = require('url').parse(dockerHostURL).hostname;
mongodbHostname = require('url').parse(dockerHostURL).hostname;
} else {
// fallback if Mongodb is being run from the host machine
mongodbHostname = "127.0.0.1";
// fallback if Mongodb is being run from the host machine
mongodbHostname = '127.0.0.1';
}

var apiPort = process.argv[2] || 1337;
var apiHost = "http://localhost:" + apiPort;
let apiPort = process.argv[2] || 1337;
let apiHost = 'http://localhost:' + apiPort;

// boot up harvester
harvester({
adapter: 'mongodb',
connectionString: "mongodb://" + mongodbHostname + ":27017/test",
oplogConnectionString: "mongodb://" + mongodbHostname + ":27017/local"
adapter: 'mongodb',
connectionString: 'mongodb://' + mongodbHostname + ':27017/test',
oplogConnectionString: 'mongodb://' + mongodbHostname + ':27017/local',
})
.resource('artists', {
name: String
})
.listen(apiPort);

.resource('artists', {
name: String,
})
.listen(apiPort);

// subscribe to the artists change events stream (SSE)
var ess = require('agco-event-source-stream');

ess(apiHost + '/artists/changes/stream')
.on('data', function(data) {
console.log('recevied artist change event', data)
});
let ess = require('agco-event-source-stream');

ess(apiHost + '/artists/changes/stream').on('data', function(data) {
console.log('recevied artist change event', data);
});

// add some data
var $http = require('http-as-promised');

var sepultura = {
artists: [{
name: "Sepultura"
}]
let $http = require('http-as-promised');

let sepultura = {
artists: [
{
name: 'Sepultura',
},
],
};

// wait a bit for the event stream to open before posting the artist
setTimeout(function() {
$http.post(apiHost + '/artists', {json: sepultura})
.spread(function (response, body) {
console.log(body);
})
.catch(function (error) {
console.error(error);
});
$http
.post(apiHost + '/artists', { json: sepultura })
.spread(function(response, body) {
console.log(body);
})
.catch(function(error) {
console.error(error);
});
}, 2000);

5 changes: 4 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
},
"version": "1.0.0",
"author": "",
"license": "ISC"
"license": "ISC",
"engines": {
"node": ">=4.2.0"
}
}
71 changes: 37 additions & 34 deletions lib/adapter.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var Promise = require('bluebird');
'use strict';
let Promise = require('bluebird');

// Pre-defined adapters
var adapters = {
let adapters = {
mongodb: './adapters/mongodb',
mysql: 'fortune-relational',
psql: 'fortune-relational',
postgres: 'fortune-relational',
sqlite: 'fortune-relational'
sqlite: 'fortune-relational',
};


/*!
/* !
* Adapter for persistence layers. Adapters must implement a
* private `_init` method, as well as a few methods that are
* accessed publicly:
Expand All @@ -22,14 +22,14 @@ var adapters = {
* @param {Object} options
* @constructor
*/
function Adapter (options) {
var key;
var methods = {};
function Adapter(options) {
let key;
let methods = {};

if (options.adapter) {
if (typeof options.adapter === 'string' && !!adapters[options.adapter]) {
//methods = require(adapters[options.adapter]);
methods = new require('./adapters/mongodb')();
// methods = require(adapters[options.adapter]);
methods = new require('./adapters/mongodb')();
} else if (typeof options.adapter === 'object') {
methods = options.adapter;
}
Expand All @@ -43,14 +43,12 @@ function Adapter (options) {
this._init(options);
}


/**
* Constructor method.
*
* @api private
*/
Adapter.prototype._init = function () {};

Adapter.prototype._init = function() {};

/**
* Transform harvester schema into a schema or model of the underlying adapter. Although this method is actually called from another module, it should not be called manually, so it is marked as private.
Expand All @@ -61,8 +59,7 @@ Adapter.prototype._init = function () {};
* @param {Object} [options] optional schema options to pass to the adapter
* @return {Object}
*/
Adapter.prototype.schema = function () {};

Adapter.prototype.schema = function() {};

/**
* Set up the underlying model. If no schema is passed, it returns an existing model. Although this method is actually called from another module, it should not be called manually, so it is marked as private.
Expand All @@ -72,8 +69,7 @@ Adapter.prototype.schema = function () {};
* @param {Object} [schema] if no schema is passed, this returns a model with the corresponding name
* @return {Object}
*/
Adapter.prototype.model = function () {};

Adapter.prototype.model = function() {};

/**
* Create a resource, with an optional ID.
Expand All @@ -83,8 +79,9 @@ Adapter.prototype.model = function () {};
* @param {Object} resource a single resource in JSON API format
* @return {Promise}
*/
Adapter.prototype.create = function () { return stubPromise(); };

Adapter.prototype.create = function() {
return stubPromise();
};

/**
* Update a resource by ID.
Expand All @@ -94,8 +91,9 @@ Adapter.prototype.create = function () { return stubPromise(); };
* @param {Object} update a partial resource in JSON API format
* @return {Promise}
*/
Adapter.prototype.update = function () { return stubPromise(); };

Adapter.prototype.update = function() {
return stubPromise();
};

/**
* Delete a resource by ID.
Expand All @@ -104,8 +102,9 @@ Adapter.prototype.update = function () { return stubPromise(); };
* @param {String} id the resource ID
* @return {Promise}
*/
Adapter.prototype.delete = function () { return stubPromise(); };

Adapter.prototype.delete = function() {
return stubPromise();
};

/**
* Find a single resource by ID or arbitrary query.
Expand All @@ -114,8 +113,9 @@ Adapter.prototype.delete = function () { return stubPromise(); };
* @param {String|Object} query if the query is a string, then it is assumed that it's the ID
* @return {Promise}
*/
Adapter.prototype.find = function () { return stubPromise(); };

Adapter.prototype.find = function() {
return stubPromise();
};

/**
* Find multiple resources by IDs or an arbitrary query.
Expand All @@ -128,8 +128,9 @@ Adapter.prototype.find = function () { return stubPromise(); };
* @return {Promise}
*/
Adapter.prototype.findMany = function () { return stubPromise(); };

Adapter.prototype.findMany = function() {
return stubPromise();
};

/**
* Sometimes we need to wait for the database connection first.
Expand All @@ -138,8 +139,9 @@ Adapter.prototype.findMany = function () { return stubPromise(); };
*
* @return {Promise}
*/
Adapter.prototype.awaitConnection = function () { return stubPromise(true); };

Adapter.prototype.awaitConnection = function() {
return stubPromise(true);
};

/**
* Stub promise returner.
Expand All @@ -148,11 +150,12 @@ Adapter.prototype.awaitConnection = function () { return stubPromise(true); };
* @param {Boolean} silent
* @return {Promise}
*/
function stubPromise (silent) {
if (!silent) console.warn('Warning: method not implemented.');
function stubPromise(silent) {
if (!silent) {
console.warn('Warning: method not implemented.');
}
return Promise.resolve();
}


exports = module.exports = Adapter;
exports.adapters = adapters;
module.exports = module.exports = Adapter;
module.exports.adapters = adapters;
Loading

0 comments on commit 7cfa4b0

Please sign in to comment.