@ztimson/utils 0.25.18 → 0.25.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +49 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +49 -12
- package/dist/index.mjs.map +1 -1
- package/dist/path-events.d.ts +26 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -543,14 +543,7 @@ class Cache {
|
|
|
543
543
|
if (options.storage instanceof Table) {
|
|
544
544
|
(async () => {
|
|
545
545
|
var _a2;
|
|
546
|
-
return (await ((_a2 = options.storage) == null ? void 0 : _a2.getAll()))
|
|
547
|
-
if (v) {
|
|
548
|
-
try {
|
|
549
|
-
this.add(v);
|
|
550
|
-
} catch {
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
});
|
|
546
|
+
return this.addAll(await ((_a2 = options.storage) == null ? void 0 : _a2.getAll()));
|
|
554
547
|
})();
|
|
555
548
|
} else if (options.storageKey) {
|
|
556
549
|
const stored = (_a = options.storage) == null ? void 0 : _a.getItem(options.storageKey);
|
|
@@ -1781,7 +1774,13 @@ class PathEvent {
|
|
|
1781
1774
|
static filter(target, ...filter) {
|
|
1782
1775
|
const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
|
|
1783
1776
|
const parsedFilter = makeArray(filter).map((pe) => new PathEvent(pe));
|
|
1784
|
-
return parsedTarget.filter((t) => !!parsedFilter.find((
|
|
1777
|
+
return parsedTarget.filter((t) => !!parsedFilter.find((r) => {
|
|
1778
|
+
const wildcard = r.fullPath == "*" || t.fullPath == "*";
|
|
1779
|
+
const p1 = r.fullPath.slice(0, r.fullPath.indexOf("*")), p2 = t.fullPath.slice(0, t.fullPath.indexOf("*"));
|
|
1780
|
+
const scope = p1.startsWith(p2) || p2.startsWith(p1);
|
|
1781
|
+
const methods = r.all || t.all || r.methods.intersection(t.methods).length;
|
|
1782
|
+
return (wildcard || scope) && methods;
|
|
1783
|
+
}));
|
|
1785
1784
|
}
|
|
1786
1785
|
/**
|
|
1787
1786
|
* Squash 2 sets of paths & return true if any overlap is found
|
|
@@ -1793,9 +1792,13 @@ class PathEvent {
|
|
|
1793
1792
|
static has(target, ...has) {
|
|
1794
1793
|
const parsedTarget = makeArray(target).map((pe) => new PathEvent(pe));
|
|
1795
1794
|
const parsedRequired = makeArray(has).map((pe) => new PathEvent(pe));
|
|
1796
|
-
return !!parsedRequired.find((r) => !!parsedTarget.find(
|
|
1797
|
-
|
|
1798
|
-
|
|
1795
|
+
return !!parsedRequired.find((r) => !!parsedTarget.find((t) => {
|
|
1796
|
+
const wildcard = r.fullPath == "*" || t.fullPath == "*";
|
|
1797
|
+
const p1 = r.fullPath.slice(0, r.fullPath.indexOf("*")), p2 = t.fullPath.slice(0, t.fullPath.indexOf("*"));
|
|
1798
|
+
const scope = p1.startsWith(p2);
|
|
1799
|
+
const methods = r.all || t.all || r.methods.intersection(t.methods).length;
|
|
1800
|
+
return (wildcard || scope) && methods;
|
|
1801
|
+
}));
|
|
1799
1802
|
}
|
|
1800
1803
|
/**
|
|
1801
1804
|
* Squash 2 sets of paths & return true if the target has all paths
|
|
@@ -1838,6 +1841,40 @@ class PathEvent {
|
|
|
1838
1841
|
if (methods == null ? void 0 : methods.length) p += `:${makeArray(methods).map((m) => m.toLowerCase()).join("")}`;
|
|
1839
1842
|
return p;
|
|
1840
1843
|
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Squash 2 sets of paths & return true if any overlap is found
|
|
1846
|
+
*
|
|
1847
|
+
* @param has Target must have at least one of these path
|
|
1848
|
+
* @return {boolean} Whether there is any overlap
|
|
1849
|
+
*/
|
|
1850
|
+
has(...has) {
|
|
1851
|
+
return PathEvent.has(this, ...has);
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Squash 2 sets of paths & return true if the target has all paths
|
|
1855
|
+
*
|
|
1856
|
+
* @param has Target must have all these paths
|
|
1857
|
+
* @return {boolean} Whether there is any overlap
|
|
1858
|
+
*/
|
|
1859
|
+
hasAll(...has) {
|
|
1860
|
+
return PathEvent.hasAll(this, ...has);
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* Same as `has` but raises an error if there is no overlap
|
|
1864
|
+
*
|
|
1865
|
+
* @param has Target must have at least one of these path
|
|
1866
|
+
*/
|
|
1867
|
+
hasFatal(...has) {
|
|
1868
|
+
return PathEvent.hasFatal(this, ...has);
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Same as `hasAll` but raises an error if the target is missing any paths
|
|
1872
|
+
*
|
|
1873
|
+
* @param has Target must have all these paths
|
|
1874
|
+
*/
|
|
1875
|
+
hasAllFatal(...has) {
|
|
1876
|
+
return PathEvent.hasAllFatal(this, ...has);
|
|
1877
|
+
}
|
|
1841
1878
|
/**
|
|
1842
1879
|
* Filter a set of paths based on this event
|
|
1843
1880
|
*
|