walletconnect-utils
walletconnect-utils copied to clipboard
keyvaluestorage node-js constructor issue
Last string
this.databaseInitialize(this.db);
of constructor in
keyvaluestorage/src/node-js/index.ts
forces the file storage to be recreated on each call.
I got the same error.
Same for us.
Removing this.databaseInitialize(this.db)
solved this for us.
Shouldn't callback: this.database.Initialize
in Db.create
be the caller?
edit:
I now see that ./db.ts
ignores the callback being passed in case `:memory: was supplied:
private constructor(opts: DbKeyValueStorageOptions) {
if (!Lokijs) {
Lokijs = importLokijs();
}
if (opts?.db === ":memory:") {
this.database = new Lokijs(opts?.db, {});
} else {
this.database = new Lokijs(opts?.db, {
autoload: true,
autoloadCallback: opts.callback,
});
}
}
And does not relay this to Lokijs
which I'm not sure why it behaves like that.
So either in case :memory:
is used also allow to supply autoloadCallback
or edit the code to
constructor(opts?: KeyValueStorageOptions) {
// flag it so we don't manually save to file
if (opts?.database === ":memory:") {
this.inMemory = true;
}
const instance = Db.create({
db: opts?.database || opts?.table || DB_NAME,
callback: this.databaseInitialize,
});
this.db = instance.database;
if (opts?.database === ":memory:") {
this.databaseInitialize(this.db);
}
}
or something (probably code can be refactored to be more nice)