MCPcopy Create free account
hub / github.com/apache/pouchdb / parseAdapter

Function parseAdapter

lib/index.js:2536–2577  ·  view source on GitHub ↗
(name, opts)

Source from the content-addressed store, hash-verified

2534}
2535
2536function parseAdapter(name, opts) {
2537 var match = name.match(/([a-z-]*):\/\/(.*)/);
2538 if (match) {
2539 // the http adapter expects the fully qualified name
2540 return {
2541 name: /https?/.test(match[1]) ? match[1] + '://' + match[2] : match[2],
2542 adapter: match[1]
2543 };
2544 }
2545
2546 var adapters = PouchDB.adapters;
2547 var preferredAdapters = PouchDB.preferredAdapters;
2548 var prefix = PouchDB.prefix;
2549 var adapterName = opts.adapter;
2550
2551 if (!adapterName) { // automatically determine adapter
2552 for (var i = 0; i < preferredAdapters.length; ++i) {
2553 adapterName = preferredAdapters[i];
2554 // check for browsers that have been upgraded from websql-only to websql+idb
2555 /* istanbul ignore if */
2556 if (adapterName === 'idb' && 'websql' in adapters &&
2557 hasLocalStorage() && localStorage['_pouch__websqldb_' + prefix + name]) {
2558 // log it, because this can be confusing during development
2559 guardedConsole('log', 'PouchDB is downgrading "' + name + '" to WebSQL to' +
2560 ' avoid data loss, because it was already opened with WebSQL.');
2561 continue; // keep using websql to avoid user data loss
2562 }
2563 break;
2564 }
2565 }
2566
2567 var adapter = adapters[adapterName];
2568
2569 // if adapter is invalid, then an error will be thrown later
2570 var usePrefix = (adapter && 'use_prefix' in adapter) ?
2571 adapter.use_prefix : true;
2572
2573 return {
2574 name: usePrefix ? (prefix + name) : name,
2575 adapter: adapterName
2576 };
2577}
2578
2579function inherits(A, B) {
2580 A.prototype = Object.create(B.prototype, {

Callers 1

_setupMethod · 0.70

Calls 2

hasLocalStorageFunction · 0.70
guardedConsoleFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…