Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from feedhenry/remove-fh-mbaas-express
Browse files Browse the repository at this point in the history
Proposed restructuring for removal of fh-mbaas-express issue #2
  • Loading branch information
wtrocki authored May 17, 2017
2 parents b559f2d + 482679a commit 7ca3e60
Show file tree
Hide file tree
Showing 69 changed files with 108 additions and 3,299 deletions.
35 changes: 17 additions & 18 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function(grunt) {
'use strict';

function makeTestArgs(testFile) {
return ['-u exports --recursive -t 10000 ./test/setup.js', testFile].join(' ');
return ['-u exports --recursive -t 10000 ', testFile].join(' ');
}

function makeUnits(testArgString) {
Expand All @@ -18,23 +18,22 @@ module.exports = function(grunt) {
// TODO: move these to use the grunt-mocha-test plugin

var tests = [ /* If updating this list of tests, also update test_win.cmd for Windows */
'./test/test_init.js',
'./test/sync/test_mongodbQueue.js',
'./test/sync/test_index.js',
'./test/sync/test_worker.js',
'./test/sync/test_sync-processor.js',
'./test/sync/test_sync-scheduler.js',
'./test/sync/test_ack-processor.js',
'./test/sync/test_pending-processor.js',
'./test/sync/test_hashProvider.js',
'./test/sync/test_api-sync.js',
'./test/sync/test_dataHandlers.js',
'./test/sync/test_api-syncRecords.js',
'./test/sync/test_default-dataHandlers.js',
'./test/sync/test_interceptors.js',
'./test/sync/test_lock.js',
'./test/sync/test_datasetClientsCleaner.js',
'./test/sync/test_sync-metrics.js'
'./test/test_mongodbQueue.js',
'./test/test_index.js',
'./test/test_worker.js',
'./test/test_sync-processor.js',
'./test/test_sync-scheduler.js',
'./test/test_ack-processor.js',
'./test/test_pending-processor.js',
'./test/test_hashProvider.js',
'./test/test_api-sync.js',
'./test/test_dataHandlers.js',
'./test/test_api-syncRecords.js',
'./test/test_default-dataHandlers.js',
'./test/test_interceptors.js',
'./test/test_lock.js',
'./test/test_datasetClientsCleaner.js',
'./test/test_sync-metrics.js'
];
var unit_args = _.map(tests, makeTestArgs);
var test_runner = '_mocha';
Expand Down
68 changes: 33 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
# fh-sync cloud
# fh-sync

Node.js and express.js based mobile app data synchronization library.
Node.js implementation of the FeedHenry Data Syncronisation Server.
To be used in conjunction with the FeedHenry Data Syncronisation Client.

*Note* WIP. This repo targets to decouple fh-sync from other API's in fh-mbaas-api package.
For official and supported version of fh-sync please refer to fh-mbaas-api npm package.
*Note* WIP. The goal of this repo is to decouple fh-sync from other API's in fh-mbaas-api package.
For the currently maintained fh-sync implementation, please refer to https://github.com/feedhenry/fh-mbaas-api.

## Usage
fh-sync is included as standard with your cloud app code.

```
npm install --save fh-sync-cloud
npm install --save fh-sync
```

This will install the latest version of fh-sync-cloud and save the installed version in your package.json
This will install the latest version of fh-sync and save the installed version in your package.json

## Documentation
Documentation for the fh-sync-cloud API is maintained at the [FeedHenry API Docs.](http://docs.feedhenry.com/v3/api/cloud_api.html)
To use sync in your application, require it and call `connect`.

```js
var sync = require('fh-sync');

## Tests
In order to run the tests, please make sure you have [Docker](https://www.docker.com/) installed.

Before running tests do:
var mongodbConnectionString = 'mongodb://127.0.0.1:27017/sync';
var redisUrl = 'redis://127.0.0.1:6379';

```
npm install
npm install -g grunt-cli
sync.api.connect(mongodbConnectionString, {}, redisUrl, function(){});
```

Then to run the tests use ```npm test```
To configure a dataset for syncing, wait for the `sync:ready` event, then `init` the dataset.

## Caveats
```js
sync.api.getEventEmitter().on('sync:ready', function() {
console.log('sync ready');

### Two sync loops per sync frequency
Two sync loops may be invoked per sync frequency if the server-side sync frequency
differs from the client-side frequency.
sync.api.init('myDataset', {
syncFrequency: 10 // seconds
}, function() {});
});
```

This is because the client and server sync frequencies are set independently.
Setting a long frequency on a client does not change the sync frequency on the
server.
*TODO*

The `syncFrequency` value of the dataset on the server should be set to the
`sync_frequency` value of the corresponding dataset on the client to avoid this.
* mounting routes in an express application that `invoke` sync on demand
* hooking up a FeedHenry Data Syncronisation Client to the server

For example:
* `sync_frequency` on the client-side dataset is also set to 120 seconds.
* `syncFrequency` on the server-side dataset is set to 120 seconds.
## Tests
In order to run the tests, please make sure you have [Docker](https://www.docker.com/) installed.

## API logging
Before running tests do:

Users of the fh-mbaas-api can then enable logging if they would like to see more output. This is useful for debugging purposes.
It's possible to pass environment variables to enable the logging according the rules specified for [debug](https://www.npmjs.com/package/debug) module:

```
DEBUG="fh-mbaas-api:*" ./yourscript
npm install
npm install -g grunt-cli
```
If `DEBUG_COLORS=0` is passed also it will print log messages with proper timestamps. This is automatically enabled outside properly supported terminal.

Then to run the tests use ```npm test```

14 changes: 14 additions & 0 deletions example/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var sync = require('../lib');

var mongodbConnectionString = 'mongodb://127.0.0.1:27017/sync';
var redisUrl = 'redis://127.0.0.1:6379';

sync.api.connect(mongodbConnectionString, {}, redisUrl, function(){});

sync.api.getEventEmitter().on('sync:ready', function() {
console.log('sync ready');

sync.api.init('myDataset', {
syncFrequency: 10 // seconds
}, function() {});
});
2 changes: 1 addition & 1 deletion integration/sync/helper.js → integration/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var MongoClient = require('mongodb').MongoClient;
var storageModule = require('../../lib/sync/storage');
var storageModule = require('../lib/storage');
var async = require('async');

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ var async = require('async');
var assert = require('assert');
var sinon = require('sinon');
var _ = require('underscore');
var defaultDataHandlersModule = require('../../lib/sync/default-dataHandlers');
var dataHandlersModule = require('../../lib/sync/dataHandlers');
var sync = require('../../lib/sync/');
var defaultDataHandlersModule = require('../lib/default-dataHandlers');
var dataHandlersModule = require('../lib/dataHandlers');
var sync = require('../lib/');

var DATASETID = "collisionHandlersTest";
var MONGODB_URL = "mongodb://127.0.0.1:27017/test_collision";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ var assert = require('assert');
var async = require('async');
var helper = require('./helper');
var sinon = require('sinon');
var sync = require('../../lib/sync');
var syncUitl = require('../../lib/sync/util');
var sync = require('../lib');
var syncUitl = require('../lib/util');

var MONGODB_URL = "mongodb://127.0.0.1:27017/test_dataHandler_overrides";
var DATASETID = 'syncDataHandlerOverridesTest';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var storageModule = require('../../lib/sync/storage');
var lockModule = require('../../lib/sync/lock');
var storageModule = require('../lib/storage');
var lockModule = require('../lib/lock');
var async = require('async');
var assert = require('assert');
var _ = require('underscore');
var helper = require('./helper');
var datasetClientCleanerModule = require('../../lib/sync/datasetClientsCleaner');
var DatasetClient = require('../../lib/sync/DatasetClient')
var datasetClientCleanerModule = require('../lib/datasetClientsCleaner');
var DatasetClient = require('../lib/DatasetClient')

var DATASETID = "datasetClientCleanerTest";
var DATASETCLIENTS_COLLECTION = storageModule.DATASETCLIENTS_COLLECTION;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var sync = require('../../lib/sync');
var sync = require('../lib');
var helper = require('./helper');
var assert = require('assert');
var util = require('util');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var assert = require('assert');
var async = require('async');
var helper = require('./helper');
var sync = require('../../lib/sync');
var sync = require('../lib');

var MONGODB_URL = "mongodb://127.0.0.1:27017/test_interceptors";
var DATASETID = 'syncInterceptors';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var MongodbQueue = require('../../lib/sync/mongodbQueue');
var metrics = require('../../lib/sync/sync-metrics').init({}, null);
var MongodbQueue = require('../lib/mongodbQueue');
var metrics = require('../lib/sync-metrics').init({}, null);
var async = require('async');
var assert = require('assert');
var helper = require('./helper');
var lockModule = require('../../lib/sync/lock');
var lockModule = require('../lib/lock');

var queueName = 'test_mongodb_queue';
var mongoDBUrl = 'mongodb://127.0.0.1:27017/' + queueName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var storageModule = require('../../lib/sync/storage');
var cacheClientModule = require('../../lib/sync/sync-cache');
var storageModule = require('../lib/storage');
var cacheClientModule = require('../lib/sync-cache');
var MongoClient = require('mongodb').MongoClient;
var async = require('async');
var assert = require('assert');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var sync = require('../../lib/sync');
var sync = require('../lib');
var assert = require('assert');
var util = require('util');
var async = require('async');
var helper = require('./helper');
var syncUtil = require('../../lib/sync/util');
var storageModule = require('../../lib/sync/storage');
var syncUtil = require('../lib/util');
var storageModule = require('../lib/storage');
var _ = require('underscore');

var mongoDBUrl = 'mongodb://127.0.0.1:27017/test_sync_api';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
102 changes: 0 additions & 102 deletions lib/api.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions lib/init.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7ca3e60

Please sign in to comment.