|
|
|
@ -6,19 +6,37 @@ const Store = require("../storage/file"); |
|
|
|
const Util = require("../common-util"); |
|
|
|
const nThen = require("nthen"); |
|
|
|
const Meta = require("../metadata"); |
|
|
|
const Pins = require("../pins"); |
|
|
|
|
|
|
|
const Env = {}; |
|
|
|
|
|
|
|
var ready = false; |
|
|
|
var store; |
|
|
|
const init = function (config, cb) { |
|
|
|
var pinStore; |
|
|
|
const init = function (config, _cb) { |
|
|
|
const cb = Util.once(Util.mkAsync(_cb)); |
|
|
|
if (!config) { |
|
|
|
return void cb('E_INVALID_CONFIG'); |
|
|
|
} |
|
|
|
|
|
|
|
Store.create(config, function (err, _store) { |
|
|
|
if (err) { return void cb(err); } |
|
|
|
store = _store; |
|
|
|
nThen(function (w) { |
|
|
|
Store.create(config, w(function (err, _store) { |
|
|
|
if (err) { |
|
|
|
w.abort(); |
|
|
|
return void cb(err); |
|
|
|
} |
|
|
|
store = _store; |
|
|
|
})); |
|
|
|
Store.create({ |
|
|
|
filePath: config.pinPath, |
|
|
|
}, w(function (err, _pinStore) { |
|
|
|
if (err) { |
|
|
|
w.abort(); |
|
|
|
return void cb(err); |
|
|
|
} |
|
|
|
pinStore = _pinStore; |
|
|
|
})); |
|
|
|
}).nThen(function () { |
|
|
|
cb(); |
|
|
|
}); |
|
|
|
}; |
|
|
|
@ -187,10 +205,24 @@ const getOlderHistory = function (data, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
const getPinState = function (data, cb, errorHandler) { |
|
|
|
const safeKey = data.key; |
|
|
|
|
|
|
|
var ref = {}; |
|
|
|
var lineHandler = Pins.createLineHandler(ref, errorHandler); |
|
|
|
|
|
|
|
// if channels aren't in memory. load them from disk
|
|
|
|
// TODO replace with readMessagesBin
|
|
|
|
pinStore.getMessages(safeKey, lineHandler, function () { |
|
|
|
cb(void 0, ref.pins); // FIXME no error handling?
|
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
const COMMANDS = { |
|
|
|
COMPUTE_INDEX: computeIndex, |
|
|
|
COMPUTE_METADATA: computeMetadata, |
|
|
|
GET_OLDER_HISTORY: getOlderHistory, |
|
|
|
GET_PIN_STATE: getPinState, |
|
|
|
}; |
|
|
|
|
|
|
|
process.on('message', function (data) { |
|
|
|
@ -201,13 +233,8 @@ process.on('message', function (data) { |
|
|
|
} |
|
|
|
|
|
|
|
const cb = function (err, value) { |
|
|
|
if (err) { |
|
|
|
return void process.send({ |
|
|
|
txid: data.txid, |
|
|
|
error: err, |
|
|
|
}); |
|
|
|
} |
|
|
|
process.send({ |
|
|
|
error: err, |
|
|
|
txid: data.txid, |
|
|
|
value: value, |
|
|
|
}); |
|
|
|
|