@ztimson/utils 0.27.14 → 0.27.15
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 +38 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +38 -53
- package/dist/index.mjs.map +1 -1
- package/dist/path-events.d.ts +11 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1958,7 +1958,7 @@ ${opts.message || this.desc}`;
|
|
|
1958
1958
|
Object.assign(this, PathEvent.pathEventCache.get(e));
|
|
1959
1959
|
return;
|
|
1960
1960
|
}
|
|
1961
|
-
let [p, method] = e.replaceAll(
|
|
1961
|
+
let [p, method] = e.replaceAll(/(^|\/)\*+\/?$/g, "").split(":");
|
|
1962
1962
|
if (!method) method = "*";
|
|
1963
1963
|
if (p === "" || p === void 0 || p === "*") {
|
|
1964
1964
|
this.module = "";
|
|
@@ -1979,27 +1979,19 @@ ${opts.message || this.desc}`;
|
|
|
1979
1979
|
this.methods = new ASet(method.split(""));
|
|
1980
1980
|
PathEvent.pathEventCache.set(e, this);
|
|
1981
1981
|
}
|
|
1982
|
-
/** Clear the cache of all PathEvents */
|
|
1983
|
-
static clearCache() {
|
|
1984
|
-
PathEvent.pathEventCache.clear();
|
|
1985
|
-
}
|
|
1986
|
-
/** Clear the permission cache */
|
|
1987
|
-
static clearPermissionCache() {
|
|
1988
|
-
PathEvent.permissionCache.clear();
|
|
1989
|
-
}
|
|
1990
1982
|
/**
|
|
1991
|
-
*
|
|
1983
|
+
* Check if a filter pattern matches a target path
|
|
1992
1984
|
* @private
|
|
1993
1985
|
*/
|
|
1994
|
-
static
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
return
|
|
1986
|
+
static matches(pattern, target) {
|
|
1987
|
+
const methodsMatch = pattern.all || target.all || pattern.methods.intersection(target.methods).length > 0;
|
|
1988
|
+
if (!methodsMatch) return false;
|
|
1989
|
+
if (!pattern.hasGlob && !target.hasGlob) {
|
|
1990
|
+
const last = pattern.fullPath[target.fullPath.length];
|
|
1991
|
+
return pattern.fullPath.startsWith(target.fullPath) && (last == null || last == "/");
|
|
1992
|
+
}
|
|
1993
|
+
if (pattern.hasGlob) return this.pathMatchesGlob(target.fullPath, pattern.fullPath);
|
|
1994
|
+
return this.pathMatchesGlob(pattern.fullPath, target.fullPath);
|
|
2003
1995
|
}
|
|
2004
1996
|
/**
|
|
2005
1997
|
* Check if a path matches a glob pattern
|
|
@@ -2014,14 +2006,9 @@ ${opts.message || this.desc}`;
|
|
|
2014
2006
|
while (patternIdx < patternParts.length && pathIdx < pathParts.length) {
|
|
2015
2007
|
const patternPart = patternParts[patternIdx];
|
|
2016
2008
|
if (patternPart === "**") {
|
|
2017
|
-
if (patternIdx === patternParts.length - 1)
|
|
2018
|
-
return true;
|
|
2019
|
-
}
|
|
2020
|
-
patternParts[patternIdx + 1];
|
|
2009
|
+
if (patternIdx === patternParts.length - 1) return true;
|
|
2021
2010
|
while (pathIdx < pathParts.length) {
|
|
2022
|
-
if (PathEvent.pathMatchesGlob(pathParts.slice(pathIdx).join("/"), patternParts.slice(patternIdx + 1).join("/")))
|
|
2023
|
-
return true;
|
|
2024
|
-
}
|
|
2011
|
+
if (PathEvent.pathMatchesGlob(pathParts.slice(pathIdx).join("/"), patternParts.slice(patternIdx + 1).join("/"))) return true;
|
|
2025
2012
|
pathIdx++;
|
|
2026
2013
|
}
|
|
2027
2014
|
return false;
|
|
@@ -2029,18 +2016,36 @@ ${opts.message || this.desc}`;
|
|
|
2029
2016
|
pathIdx++;
|
|
2030
2017
|
patternIdx++;
|
|
2031
2018
|
} else {
|
|
2032
|
-
if (patternPart !== pathParts[pathIdx])
|
|
2033
|
-
return false;
|
|
2034
|
-
}
|
|
2019
|
+
if (patternPart !== pathParts[pathIdx]) return false;
|
|
2035
2020
|
pathIdx++;
|
|
2036
2021
|
patternIdx++;
|
|
2037
2022
|
}
|
|
2038
2023
|
}
|
|
2039
|
-
if (patternIdx < patternParts.length)
|
|
2040
|
-
return patternParts.slice(patternIdx).every((p) => p === "**");
|
|
2041
|
-
}
|
|
2024
|
+
if (patternIdx < patternParts.length) return patternParts.slice(patternIdx).every((p) => p === "**");
|
|
2042
2025
|
return pathIdx === pathParts.length;
|
|
2043
2026
|
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Score a path for specificity ranking (lower = more specific = higher priority)
|
|
2029
|
+
* @private
|
|
2030
|
+
*/
|
|
2031
|
+
static scoreSpecificity(path) {
|
|
2032
|
+
if (path === "**" || path === "") return Number.MAX_SAFE_INTEGER;
|
|
2033
|
+
const segments = path.split("/").filter((p) => !!p);
|
|
2034
|
+
let score = -segments.length;
|
|
2035
|
+
segments.forEach((seg) => {
|
|
2036
|
+
if (seg === "**") score += 0.5;
|
|
2037
|
+
else if (seg === "*") score += 0.25;
|
|
2038
|
+
});
|
|
2039
|
+
return score;
|
|
2040
|
+
}
|
|
2041
|
+
/** Clear the cache of all PathEvents */
|
|
2042
|
+
static clearCache() {
|
|
2043
|
+
PathEvent.pathEventCache.clear();
|
|
2044
|
+
}
|
|
2045
|
+
/** Clear the permission cache */
|
|
2046
|
+
static clearPermissionCache() {
|
|
2047
|
+
PathEvent.permissionCache.clear();
|
|
2048
|
+
}
|
|
2044
2049
|
/**
|
|
2045
2050
|
* Combine multiple events into one parsed object. Longest path takes precedent, but all subsequent methods are
|
|
2046
2051
|
* combined until a "none" is reached
|
|
@@ -2061,9 +2066,7 @@ ${opts.message || this.desc}`;
|
|
|
2061
2066
|
result = p;
|
|
2062
2067
|
} else {
|
|
2063
2068
|
if (result.fullPath.startsWith(p.fullPath)) {
|
|
2064
|
-
if (p.none)
|
|
2065
|
-
break;
|
|
2066
|
-
}
|
|
2069
|
+
if (p.none) break;
|
|
2067
2070
|
result.methods = new ASet([...result.methods, ...p.methods]);
|
|
2068
2071
|
}
|
|
2069
2072
|
}
|
|
@@ -2082,24 +2085,6 @@ ${opts.message || this.desc}`;
|
|
|
2082
2085
|
const parsedFilter = makeArray(filter).map((pe) => pe instanceof PathEvent ? pe : new PathEvent(pe));
|
|
2083
2086
|
return parsedTarget.filter((t) => !!parsedFilter.find((r) => PathEvent.matches(r, t)));
|
|
2084
2087
|
}
|
|
2085
|
-
/**
|
|
2086
|
-
* Check if a filter pattern matches a target path
|
|
2087
|
-
* @private
|
|
2088
|
-
*/
|
|
2089
|
-
static matches(pattern, target) {
|
|
2090
|
-
if (pattern.fullPath === "" || target.fullPath === "") return false;
|
|
2091
|
-
if (pattern.fullPath === "**") return pattern.methods.has("*") || pattern.methods.intersection(target.methods).length > 0;
|
|
2092
|
-
if (target.fullPath === "**") return pattern.methods.has("*") || target.methods.has("*") || pattern.methods.intersection(target.methods).length > 0;
|
|
2093
|
-
const methodsMatch = pattern.all || target.all || pattern.methods.intersection(target.methods).length > 0;
|
|
2094
|
-
if (!methodsMatch) return false;
|
|
2095
|
-
if (!pattern.hasGlob && !target.hasGlob) {
|
|
2096
|
-
return pattern.fullPath === target.fullPath;
|
|
2097
|
-
}
|
|
2098
|
-
if (pattern.hasGlob) {
|
|
2099
|
-
return this.pathMatchesGlob(target.fullPath, pattern.fullPath);
|
|
2100
|
-
}
|
|
2101
|
-
return this.pathMatchesGlob(pattern.fullPath, target.fullPath);
|
|
2102
|
-
}
|
|
2103
2088
|
/**
|
|
2104
2089
|
* Squash 2 sets of paths & return true if any overlap is found
|
|
2105
2090
|
*
|