pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.37k stars 1.04k forks source link

given leveldown is no valid adapter #67

Closed RickCarlino closed 7 years ago

RickCarlino commented 7 years ago

I'm upgrading to the newest version of RxDB for a localstorage project and hit this error:

Uncaught (in promise) Error: given leveldown is no valid adapter
    at Object.isLevelDown (http://localhost:3002/js/main.bundle.js:30906:107)
    at Object._callee9$ (http://localhost:3002/js/main.bundle.js:29691:31)
    at tryCatch (http://localhost:3002/js/main.bundle.js:28246:41)
    at Generator.invoke [as _invoke] (http://localhost:3002/js/main.bundle.js:28481:23)
    at Generator.prototype.(anonymous function) [as next] (http://localhost:3002/js/main.bundle.js:28298:22)
    at step (http://localhost:3002/js/main.bundle.js:28929:31)
    at http://localhost:3002/js/main.bundle.js:28947:15
    at F (http://localhost:3002/js/main.bundle.js:27075:29)
    at Object.<anonymous> (http://localhost:3002/js/main.bundle.js:28926:13)
    at Object.create (http://localhost:3002/js/main.bundle.js:29733:23)

within this function:

    /**
     * check if the given module is a leveldown-adapter
     * throws if not
     */
    function isLevelDown(adapter) {
        if (!adapter || typeof adapter.super_ !== 'function' || typeof adapter.destroy !== 'function') throw new Error('given leveldown is no valid adapter');
    }function fastUnsecureHash(obj) {
        if (typeof obj !== 'string') obj = JSON.stringify(obj);
        var hash = 0,
            i = void 0,
            chr = void 0,
            len = void 0;
        if (obj.length === 0) return hash;
        for (i = 0, len = obj.length; i < len; i++) {
            chr = obj.charCodeAt(i);
            hash = (hash << 5) - hash + chr;
            hash |= 0; // Convert to 32bit integer
        }
        if (hash < 0) hash = hash * -1;
        return hash;
    }

I'm not using LevelDB anywhere in my app, so I was surprised to see this come up. Is it a bug, or is it possible that I have misconfigured a setting somewhere?

pubkey commented 7 years ago

Could you post the code where you call RxDB.create() ? It should work like this:

RxDB.create({
  name: 'mydb',
  adapter: 'localstorage'
});
pubkey commented 7 years ago

@RickCarlino status?

RickCarlino commented 7 years ago

@pubkey Sorry for the slow response - it's been hectic at work. I have not had time to write a good, runable sample for this one. I will get to it between now and Monday.

RickCarlino commented 7 years ago

@pubkey Sorry for the slow response.

Here's the smallest example I could get running:

import { create, plugin } from "rxdb";

plugin(require("pouchdb-adapter-localstorage"));
create({ name: "foo", storageEngine: "localStorage" });
pubkey commented 7 years ago

Is storageEngine written anywhere in the docs? Because this attribute does not exist.

pubkey commented 7 years ago

Ah, i've seen its written in the typings. I will fix.