protoblast
Advanced tools
Comparing version 0.7.17 to 0.7.18
@@ -0,1 +1,8 @@ | ||
## 0.7.18 (2022-06-16) | ||
* Add `Array#findAllByPath(path, value)` | ||
* Add `Function#setAbstractMethod(name)` | ||
* Make server-side requests retry dns lookups if they fail | ||
* Fix `Cache#set()` not setting the MAX_AGE of entries | ||
## 0.7.17 (2022-03-21) | ||
@@ -2,0 +9,0 @@ |
@@ -870,3 +870,3 @@ /** | ||
* @since 0.3.8 | ||
* @version 0.6.0 | ||
* @version 0.7.18 | ||
* | ||
@@ -879,13 +879,29 @@ * @param {String} path | ||
Blast.definePrototype('Array', function findByPath(path, value) { | ||
return Bound.Array.findAllByPath(this, path, value)[0]; | ||
}); | ||
var entries, | ||
/** | ||
* Search the array and return all values | ||
* | ||
* @author Jelle De Loecker <jelle@elevenways.be> | ||
* @since 0.7.18 | ||
* @version 0.7.18 | ||
* | ||
* @param {String} path | ||
* @param {Mixed} value | ||
* | ||
* @return {Array} | ||
*/ | ||
Blast.definePrototype('Array', function findAllByPath(path, value) { | ||
let entries, | ||
results, | ||
length, | ||
entry, | ||
key, | ||
i; | ||
length = this.length; | ||
const length = this.length; | ||
// If path is an object, it contains multiple filters | ||
if (path && typeof path == 'object') { | ||
let key; | ||
@@ -908,3 +924,3 @@ // Do all keys in the path | ||
if (!entries.length) { | ||
return; | ||
break; | ||
} | ||
@@ -920,13 +936,11 @@ | ||
if (!results.length) { | ||
return; | ||
break; | ||
} | ||
} | ||
if (!results || !results.length) { | ||
return; | ||
} else { | ||
return results[0]; | ||
} | ||
return results || []; | ||
} | ||
results = []; | ||
for (i = 0; i < length; i++) { | ||
@@ -936,5 +950,7 @@ entry = Obj.path(this[i], path); | ||
if (entry == value) { | ||
return this[i]; | ||
results.push(this[i]); | ||
} | ||
} | ||
return results; | ||
}); | ||
@@ -941,0 +957,0 @@ |
@@ -11,3 +11,3 @@ var empty = Symbol('empty'), | ||
max_idle_symbol = Symbol('max_idle'), | ||
set_for_get = Symbol('set_for_get'), | ||
set_for_get_symbol= Symbol('set_for_get'), | ||
length_symbol = length, | ||
@@ -292,3 +292,3 @@ getEntryByKey = Symbol('getEntryByKey'), | ||
* @since 0.6.0 | ||
* @version 0.6.0 | ||
* @version 0.7.18 | ||
* | ||
@@ -328,7 +328,7 @@ * @param {Mixed} key | ||
this[length]++; | ||
} | ||
// See if we have to apply a default max age | ||
if (max_age == null && this[max_age_symbol]) { | ||
max_age = this[max_age_symbol]; | ||
} | ||
// See if we have to apply a default max age | ||
if (max_age == null && this[max_age_symbol]) { | ||
max_age = this[max_age_symbol]; | ||
} | ||
@@ -343,3 +343,3 @@ | ||
// Is this `set` called within `get`? | ||
if (max_age === set_for_get) { | ||
if (max_age === set_for_get_symbol) { | ||
max_age = null; | ||
@@ -506,3 +506,3 @@ } else { | ||
if (entry) { | ||
this.set(key, entry.value, set_for_get); | ||
this.set(key, entry.value, set_for_get_symbol); | ||
return entry.value; | ||
@@ -509,0 +509,0 @@ } |
@@ -1280,2 +1280,19 @@ var finished_constitutors = new WeakMap(), | ||
/** | ||
* Set an abstract method | ||
* | ||
* @author Jelle De Loecker <jelle@develry.be> | ||
* @since 0.7.18 | ||
* @version 0.7.18 | ||
* | ||
* @param {Function} constructor Constructor to modify prototype of | ||
* @param {String} name The name of the method | ||
*/ | ||
defClassMethod(function setAbstractMethod(constructor, name) { | ||
Fn.setMethod(constructor, name, function abstractMethod() { | ||
let message = 'The `' + name + '` method has not been implemented in the `' + this.constructor.name + '` class.'; | ||
throw new Error(message); | ||
}); | ||
}); | ||
/** | ||
* Apply a decoration object | ||
@@ -1282,0 +1299,0 @@ * |
@@ -25,7 +25,8 @@ var dns_cache, | ||
* @since 0.7.10 | ||
* @version 0.7.12 | ||
* @version 0.7.18 | ||
*/ | ||
Request.setStatic(function lookup(hostname, options, callback) { | ||
let pledge; | ||
let attempt = 0, | ||
pledge; | ||
@@ -54,3 +55,17 @@ if (!dns_cache) { | ||
dns.lookup(hostname, options, (...response) => { | ||
dns.lookup(hostname, options, function handleDnsResponse(...response) { | ||
let err = response[0]; | ||
if (err) { | ||
if (attempt < 10) { | ||
attempt++; | ||
console.log('Retrying DNS lookup, attempt', attempt); | ||
return setTimeout(() => { | ||
dns.lookup(hostname, options, handleDnsResponse); | ||
}, 10); | ||
} | ||
} | ||
dns_cache.set(key, response); | ||
@@ -57,0 +72,0 @@ resolve(response); |
{ | ||
"name": "protoblast", | ||
"description": "Native object expansion library", | ||
"version": "0.7.17", | ||
"version": "0.7.18", | ||
"author": "Jelle De Loecker <jelle@elevenways.be>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
739760
30612