balena-settings-storage
Version:
Balena settings storage utilities
32 lines • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStorage = void 0;
const storage_1 = require("./storage");
// use dynamic imports so that node apps have less files to read on startup.
const lazyImport = {
virtual: () => require('./stores/virtual-storage'),
local: () => require('./stores/local-storage'),
node: () => require('./stores/node-storage'),
};
const getStorage = (options) => {
let store;
if ((options === null || options === void 0 ? void 0 : options.dataDirectory) === false) {
store = lazyImport.virtual().createStore();
}
else if (typeof window !== 'undefined') {
// Even though we specify an alternative file for this in the package.json's `browser` field
// we still need to handle the `isBrowser` case in the default file for the case that the
// bundler doesn't support/use the `browser` field.
const localStore = lazyImport.local();
store = localStore.isSupported()
? localStore.createStorage(options === null || options === void 0 ? void 0 : options.dataDirectory)
: lazyImport.virtual().createStore(options === null || options === void 0 ? void 0 : options.dataDirectory);
}
else {
// Fallback to filesystem based storage if not in the browser.
store = lazyImport.node().createStorage(options === null || options === void 0 ? void 0 : options.dataDirectory);
}
return (0, storage_1.getStorage)(store);
};
exports.getStorage = getStorage;
//# sourceMappingURL=index.js.map