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

Commit 7ca3e60

Browse files
authored
Merge pull request #6 from feedhenry/remove-fh-mbaas-express
Proposed restructuring for removal of fh-mbaas-express issue #2
2 parents b559f2d + 482679a commit 7ca3e60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+108
-3299
lines changed

Gruntfile.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = function(grunt) {
44
'use strict';
55

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

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

2020
var tests = [ /* If updating this list of tests, also update test_win.cmd for Windows */
21-
'./test/test_init.js',
22-
'./test/sync/test_mongodbQueue.js',
23-
'./test/sync/test_index.js',
24-
'./test/sync/test_worker.js',
25-
'./test/sync/test_sync-processor.js',
26-
'./test/sync/test_sync-scheduler.js',
27-
'./test/sync/test_ack-processor.js',
28-
'./test/sync/test_pending-processor.js',
29-
'./test/sync/test_hashProvider.js',
30-
'./test/sync/test_api-sync.js',
31-
'./test/sync/test_dataHandlers.js',
32-
'./test/sync/test_api-syncRecords.js',
33-
'./test/sync/test_default-dataHandlers.js',
34-
'./test/sync/test_interceptors.js',
35-
'./test/sync/test_lock.js',
36-
'./test/sync/test_datasetClientsCleaner.js',
37-
'./test/sync/test_sync-metrics.js'
21+
'./test/test_mongodbQueue.js',
22+
'./test/test_index.js',
23+
'./test/test_worker.js',
24+
'./test/test_sync-processor.js',
25+
'./test/test_sync-scheduler.js',
26+
'./test/test_ack-processor.js',
27+
'./test/test_pending-processor.js',
28+
'./test/test_hashProvider.js',
29+
'./test/test_api-sync.js',
30+
'./test/test_dataHandlers.js',
31+
'./test/test_api-syncRecords.js',
32+
'./test/test_default-dataHandlers.js',
33+
'./test/test_interceptors.js',
34+
'./test/test_lock.js',
35+
'./test/test_datasetClientsCleaner.js',
36+
'./test/test_sync-metrics.js'
3837
];
3938
var unit_args = _.map(tests, makeTestArgs);
4039
var test_runner = '_mocha';

README.md

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,56 @@
1-
# fh-sync cloud
1+
# fh-sync
22

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

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

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

1111
```
12-
npm install --save fh-sync-cloud
12+
npm install --save fh-sync
1313
```
1414

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

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

19+
```js
20+
var sync = require('fh-sync');
2021

21-
## Tests
22-
In order to run the tests, please make sure you have [Docker](https://www.docker.com/) installed.
23-
24-
Before running tests do:
22+
var mongodbConnectionString = 'mongodb://127.0.0.1:27017/sync';
23+
var redisUrl = 'redis://127.0.0.1:6379';
2524

26-
```
27-
npm install
28-
npm install -g grunt-cli
25+
sync.api.connect(mongodbConnectionString, {}, redisUrl, function(){});
2926
```
3027

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

33-
## Caveats
30+
```js
31+
sync.api.getEventEmitter().on('sync:ready', function() {
32+
console.log('sync ready');
3433

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

39-
This is because the client and server sync frequencies are set independently.
40-
Setting a long frequency on a client does not change the sync frequency on the
41-
server.
40+
*TODO*
4241

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

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

50-
## API logging
48+
Before running tests do:
5149

52-
Users of the fh-mbaas-api can then enable logging if they would like to see more output. This is useful for debugging purposes.
53-
It's possible to pass environment variables to enable the logging according the rules specified for [debug](https://www.npmjs.com/package/debug) module:
54-
5550
```
56-
DEBUG="fh-mbaas-api:*" ./yourscript
51+
npm install
52+
npm install -g grunt-cli
5753
```
58-
If `DEBUG_COLORS=0` is passed also it will print log messages with proper timestamps. This is automatically enabled outside properly supported terminal.
54+
55+
Then to run the tests use ```npm test```
56+

example/server.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var sync = require('../lib');
2+
3+
var mongodbConnectionString = 'mongodb://127.0.0.1:27017/sync';
4+
var redisUrl = 'redis://127.0.0.1:6379';
5+
6+
sync.api.connect(mongodbConnectionString, {}, redisUrl, function(){});
7+
8+
sync.api.getEventEmitter().on('sync:ready', function() {
9+
console.log('sync ready');
10+
11+
sync.api.init('myDataset', {
12+
syncFrequency: 10 // seconds
13+
}, function() {});
14+
});

integration/sync/helper.js renamed to integration/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var MongoClient = require('mongodb').MongoClient;
2-
var storageModule = require('../../lib/sync/storage');
2+
var storageModule = require('../lib/storage');
33
var async = require('async');
44

55
/**

integration/sync/test_collision-handlers.js renamed to integration/test_collision-handlers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ var async = require('async');
22
var assert = require('assert');
33
var sinon = require('sinon');
44
var _ = require('underscore');
5-
var defaultDataHandlersModule = require('../../lib/sync/default-dataHandlers');
6-
var dataHandlersModule = require('../../lib/sync/dataHandlers');
7-
var sync = require('../../lib/sync/');
5+
var defaultDataHandlersModule = require('../lib/default-dataHandlers');
6+
var dataHandlersModule = require('../lib/dataHandlers');
7+
var sync = require('../lib/');
88

99
var DATASETID = "collisionHandlersTest";
1010
var MONGODB_URL = "mongodb://127.0.0.1:27017/test_collision";

integration/sync/test_dataHandler_overrides.js renamed to integration/test_dataHandler_overrides.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ var assert = require('assert');
22
var async = require('async');
33
var helper = require('./helper');
44
var sinon = require('sinon');
5-
var sync = require('../../lib/sync');
6-
var syncUitl = require('../../lib/sync/util');
5+
var sync = require('../lib');
6+
var syncUitl = require('../lib/util');
77

88
var MONGODB_URL = "mongodb://127.0.0.1:27017/test_dataHandler_overrides";
99
var DATASETID = 'syncDataHandlerOverridesTest';

integration/sync/test_datasetClientCleaner.js renamed to integration/test_datasetClientCleaner.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var storageModule = require('../../lib/sync/storage');
2-
var lockModule = require('../../lib/sync/lock');
1+
var storageModule = require('../lib/storage');
2+
var lockModule = require('../lib/lock');
33
var async = require('async');
44
var assert = require('assert');
55
var _ = require('underscore');
66
var helper = require('./helper');
7-
var datasetClientCleanerModule = require('../../lib/sync/datasetClientsCleaner');
8-
var DatasetClient = require('../../lib/sync/DatasetClient')
7+
var datasetClientCleanerModule = require('../lib/datasetClientsCleaner');
8+
var DatasetClient = require('../lib/DatasetClient')
99

1010
var DATASETID = "datasetClientCleanerTest";
1111
var DATASETCLIENTS_COLLECTION = storageModule.DATASETCLIENTS_COLLECTION;

integration/sync/test_index.js renamed to integration/test_index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var sync = require('../../lib/sync');
1+
var sync = require('../lib');
22
var helper = require('./helper');
33
var assert = require('assert');
44
var util = require('util');

integration/sync/test_interceptor_overrides.js renamed to integration/test_interceptor_overrides.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var assert = require('assert');
22
var async = require('async');
33
var helper = require('./helper');
4-
var sync = require('../../lib/sync');
4+
var sync = require('../lib');
55

66
var MONGODB_URL = "mongodb://127.0.0.1:27017/test_interceptors";
77
var DATASETID = 'syncInterceptors';

integration/sync/test_mongodbQueue.js renamed to integration/test_mongodbQueue.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var MongodbQueue = require('../../lib/sync/mongodbQueue');
2-
var metrics = require('../../lib/sync/sync-metrics').init({}, null);
1+
var MongodbQueue = require('../lib/mongodbQueue');
2+
var metrics = require('../lib/sync-metrics').init({}, null);
33
var async = require('async');
44
var assert = require('assert');
55
var helper = require('./helper');
6-
var lockModule = require('../../lib/sync/lock');
6+
var lockModule = require('../lib/lock');
77

88
var queueName = 'test_mongodb_queue';
99
var mongoDBUrl = 'mongodb://127.0.0.1:27017/' + queueName;

0 commit comments

Comments
 (0)