From ddba3abc614f0f5bc7cbb23ce228f6aee03e6a71 Mon Sep 17 00:00:00 2001 From: Ewout Stortenbeker Date: Wed, 12 Feb 2020 18:06:16 +0100 Subject: [PATCH] fixed node value getting and locking issue --- src/storage-localstorage.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/storage-localstorage.js b/src/storage-localstorage.js index dc1f974..460cf68 100644 --- a/src/storage-localstorage.js +++ b/src/storage-localstorage.js @@ -1,7 +1,7 @@ const { debug, ID, PathReference, PathInfo, ascii85 } = require('acebase-core'); const { NodeInfo } = require('./node-info'); const { VALUE_TYPES } = require('./node-value-types'); -const { Storage, StorageSettings } = require('./storage'); +const { Storage, StorageSettings, NodeNotFoundError } = require('./storage'); class LocalStorageSettings extends StorageSettings { constructor(settings) { @@ -76,7 +76,7 @@ class LocalStorage extends Storage { } }) .then(() => { - return this.indexes.load(); + return this.indexes.supported && this.indexes.load(); }) .then(() => { this.emit('ready'); @@ -622,15 +622,15 @@ class LocalStorage extends Storage { const targetRow = this._readNode(path); if (!targetRow) { // Lookup parent node - if (path === '') { return null; } // path is root. There is no parent. + if (path === '') { return { value: null }; } // path is root. There is no parent. return lock.moveToParent() .then(parentLock => { lock = parentLock; let parentNode = this._readNode(pathInfo.parentPath); - if ([VALUE_TYPES.OBJECT, VALUE_TYPES.ARRAY].includes(parentNode.type) && pathInfo.key in parentNode) { - return parentNode[pathInfo.key]; + if (parentNode && [VALUE_TYPES.OBJECT, VALUE_TYPES.ARRAY].includes(parentNode.type) && pathInfo.key in parentNode) { + return { revision: parentNode.revision, value: parentNode.value[pathInfo.key] }; } - return null; + return { value: null }; }); } @@ -740,8 +740,6 @@ class LocalStorage extends Storage { throw new Error(`multiple records found for non-object value!`); } - lock.release(); - // Post process filters to remove any data that got though because they were // not stored in dedicated records. This will happen with smaller values because // they are stored inline in their parent node. @@ -784,6 +782,10 @@ class LocalStorage extends Storage { } return result; }) + .then(result => { + lock.release(); + return result; + }) .catch(err => { lock.release(); throw err;