Comparing version 3.0.4 to 3.1.0
{ | ||
"name": "enmap", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,13 +22,25 @@ const _ = require('lodash'); | ||
this.fetchAll = options.fetchAll !== undefined ? options.fetchAll : true; | ||
Object.defineProperty(this, 'fetchAll', { | ||
value: options.fetchAll !== undefined ? options.fetchAll : true, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
if (options.provider) { | ||
this.persistent = true; | ||
this.db = options.provider; | ||
Object.defineProperties(this, { | ||
persistent: { value: true, writable: false, enumerable: false, configurable: false }, | ||
db: { value: options.provider, writable: false, enumerable: false, configurable: false }, | ||
defer: { value: this.db.defer, writable: false, enumerable: false, configurable: false }, | ||
name: { value: this.db.name, writable: false, enumerable: false, configurable: false } | ||
}); | ||
this.db.fetchAll = this.fetchAll; | ||
this.defer = this.db.defer; | ||
this.db.init(this); | ||
this.name = this.db.name; | ||
} else { | ||
this.name = 'MemoryBasedEnmap'; | ||
Object.defineProperty(this, 'name', { | ||
value: 'MemoryBasedEnmap', | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
} | ||
@@ -98,2 +110,14 @@ } | ||
/** | ||
* Removes a key from the cache - useful when using the fetchAll feature. | ||
* @param {*} keyOrArrayOfKeys A single key or array of keys to remove from the cache. | ||
*/ | ||
evict(keyOrArrayOfKeys) { | ||
if (_.isArray(keyOrArrayOfKeys)) { | ||
keyOrArrayOfKeys.forEach(key => super.delete(key)); | ||
} else { | ||
super.delete(keyOrArrayOfKeys); | ||
} | ||
} | ||
/** | ||
* Generates an automatic numerical key for inserting a new value. | ||
@@ -176,2 +200,3 @@ * @example | ||
setProp(key, path, val) { | ||
if (path == undefined) throw new Err(`No path provided to set a property in "${key}" of enmap "${this.name}"`); | ||
return this.set(key, val, path); | ||
@@ -223,2 +248,3 @@ } | ||
pushIn(key, path, val, allowDupes = false) { | ||
if (path == undefined) throw new Err(`No path provided to push a value in "${key}" of enmap "${this.name}"`); | ||
return this.push(key, val, path, allowDupes); | ||
@@ -348,2 +374,3 @@ } | ||
getProp(key, path) { | ||
if (path == undefined) throw new Err(`No path provided get a property from "${key}" of enmap "${this.name}"`); | ||
return this.get(key, path); | ||
@@ -385,2 +412,3 @@ } | ||
hasProp(key, path) { | ||
if (path == undefined) throw new Err(`No path provided to check for a property in "${key}" of enmap "${this.name}"`); | ||
return this.has(key, path); | ||
@@ -433,2 +461,3 @@ } | ||
deleteProp(key, path) { | ||
if (path == undefined) throw new Err(`No path provided to delete a property in "${key}" of enmap "${this.name}"`); | ||
this.delete(key, path); | ||
@@ -498,2 +527,3 @@ } | ||
removeFrom(key, path, val) { | ||
if (path == undefined) throw new Err(`No path provided to remove an array element in "${key}" of enmap "${this.name}"`); | ||
return this.remove(key, val, path); | ||
@@ -500,0 +530,0 @@ } |
114843
1461