memory-card
Version:
ES6 Map like Async API, with Swagger API Backend Support.
21 lines • 757 B
JavaScript
import { log, } from '../config.js';
import { BACKEND_FACTORY_DICT, } from './backend-config.js';
async function getStorage(name, options = {
type: 'file',
}) {
log.verbose('getStorage', 'name: %s, options: %s', name, JSON.stringify(options));
if (!name) {
if (options.type !== 'nop') {
throw new Error('storage have to be `nop` with a un-named storage');
}
name = 'nop';
}
if (!options.type || !(options.type in BACKEND_FACTORY_DICT)) {
throw new Error('backend unknown: ' + options.type);
}
const Backend = await BACKEND_FACTORY_DICT[options.type]();
const backend = new Backend(name, options);
return backend;
}
export { getStorage };
//# sourceMappingURL=get-storage.js.map