2018-03-29 11:41:22 +08:00
|
|
|
const clsHooked = require('cls-hooked');
|
|
|
|
const namespace = clsHooked.createNamespace("trilium");
|
|
|
|
|
|
|
|
async function init(callback) {
|
|
|
|
return await namespace.runAndReturn(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
function wrap(callback) {
|
|
|
|
return async () => await init(callback);
|
|
|
|
}
|
|
|
|
|
2018-03-31 01:20:36 +08:00
|
|
|
function getSourceId() {
|
|
|
|
return namespace.get('sourceId');
|
|
|
|
}
|
|
|
|
|
2018-11-27 05:27:57 +08:00
|
|
|
function disableEntityEvents() {
|
|
|
|
namespace.set('disableEntityEvents', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isEntityEventsDisabled() {
|
|
|
|
return !!namespace.get('disableEntityEvents');
|
|
|
|
}
|
|
|
|
|
2018-07-23 01:56:20 +08:00
|
|
|
function reset() {
|
|
|
|
clsHooked.reset();
|
|
|
|
}
|
|
|
|
|
2018-03-29 11:41:22 +08:00
|
|
|
module.exports = {
|
|
|
|
init,
|
|
|
|
wrap,
|
2018-03-31 01:20:36 +08:00
|
|
|
namespace,
|
2018-07-23 01:56:20 +08:00
|
|
|
getSourceId,
|
2018-11-27 05:27:57 +08:00
|
|
|
disableEntityEvents,
|
|
|
|
isEntityEventsDisabled,
|
2018-07-23 01:56:20 +08:00
|
|
|
reset
|
2018-03-29 11:41:22 +08:00
|
|
|
};
|