Convert CommonJS exports to ES6-compatible exports

We use `export default` begrudgingly here. Ideally we'd use just `export`, though this entire SDK expects things to be exported as a default. Instead of breaking everything, we'll sacrifice our export pattern for a smaller diff - a later commit can always do the default export -> regular export conversion.
This commit is contained in:
Travis Ralston 2019-12-19 17:45:24 -07:00
parent 0b0fe92b17
commit 344dac4fb9
147 changed files with 649 additions and 620 deletions

View file

@ -432,77 +432,73 @@ function selectQuery(store, keyRange, resultMapper) {
});
}
module.exports = {
/**
* Configure rage shaking support for sending bug reports.
* Modifies globals.
* @return {Promise} Resolves when set up.
*/
init: function() {
if (global.mx_rage_initPromise) {
return global.mx_rage_initPromise;
}
global.mx_rage_logger = new ConsoleLogger();
global.mx_rage_logger.monkeyPatch(window.console);
// just *accessing* indexedDB throws an exception in firefox with
// indexeddb disabled.
let indexedDB;
try {
indexedDB = window.indexedDB;
} catch (e) {}
if (indexedDB) {
global.mx_rage_store = new IndexedDBLogStore(indexedDB, global.mx_rage_logger);
global.mx_rage_initPromise = global.mx_rage_store.connect();
return global.mx_rage_initPromise;
}
global.mx_rage_initPromise = Promise.resolve();
/**
* Configure rage shaking support for sending bug reports.
* Modifies globals.
* @return {Promise} Resolves when set up.
*/
export function init() {
if (global.mx_rage_initPromise) {
return global.mx_rage_initPromise;
},
}
global.mx_rage_logger = new ConsoleLogger();
global.mx_rage_logger.monkeyPatch(window.console);
flush: function() {
if (!global.mx_rage_store) {
return;
}
global.mx_rage_store.flush();
},
// just *accessing* indexedDB throws an exception in firefox with
// indexeddb disabled.
let indexedDB;
try {
indexedDB = window.indexedDB;
} catch (e) {}
/**
* Clean up old logs.
* @return Promise Resolves if cleaned logs.
*/
cleanup: async function() {
if (!global.mx_rage_store) {
return;
}
await global.mx_rage_store.consume();
},
if (indexedDB) {
global.mx_rage_store = new IndexedDBLogStore(indexedDB, global.mx_rage_logger);
global.mx_rage_initPromise = global.mx_rage_store.connect();
return global.mx_rage_initPromise;
}
global.mx_rage_initPromise = Promise.resolve();
return global.mx_rage_initPromise;
}
/**
* Get a recent snapshot of the logs, ready for attaching to a bug report
*
* @return {Array<{lines: string, id, string}>} list of log data
*/
getLogsForReport: async function() {
if (!global.mx_rage_logger) {
throw new Error(
"No console logger, did you forget to call init()?",
);
}
// If in incognito mode, store is null, but we still want bug report
// sending to work going off the in-memory console logs.
if (global.mx_rage_store) {
// flush most recent logs
await global.mx_rage_store.flush();
return await global.mx_rage_store.consume();
} else {
return [{
lines: global.mx_rage_logger.flush(true),
id: "-",
}];
}
},
};
export function flush() {
if (!global.mx_rage_store) {
return;
}
global.mx_rage_store.flush();
}
/**
* Clean up old logs.
* @return Promise Resolves if cleaned logs.
*/
export async function cleanup() {
if (!global.mx_rage_store) {
return;
}
await global.mx_rage_store.consume();
}
/**
* Get a recent snapshot of the logs, ready for attaching to a bug report
*
* @return {Array<{lines: string, id, string}>} list of log data
*/
export async function getLogsForReport() {
if (!global.mx_rage_logger) {
throw new Error(
"No console logger, did you forget to call init()?",
);
}
// If in incognito mode, store is null, but we still want bug report
// sending to work going off the in-memory console logs.
if (global.mx_rage_store) {
// flush most recent logs
await global.mx_rage_store.flush();
return await global.mx_rage_store.consume();
} else {
return [{
lines: global.mx_rage_logger.flush(true),
id: "-",
}];
}
}