|
|
|
|
@@ -40,6 +40,7 @@ export function PE(str: TemplateStringsArray, ...args: any[]) {
|
|
|
|
|
* @param {TemplateStringsArray} str
|
|
|
|
|
* @param {string} args
|
|
|
|
|
* @return {string}
|
|
|
|
|
* @constructor
|
|
|
|
|
*/
|
|
|
|
|
export function PES(str: TemplateStringsArray, ...args: any[]) {
|
|
|
|
|
let combined = [];
|
|
|
|
|
@@ -118,25 +119,13 @@ export class PathEvent {
|
|
|
|
|
if(!method) method = '*';
|
|
|
|
|
|
|
|
|
|
// Handle special cases
|
|
|
|
|
if(p === '' || p === undefined) {
|
|
|
|
|
// Empty string matches nothing
|
|
|
|
|
this.module = '';
|
|
|
|
|
this.path = '';
|
|
|
|
|
this.fullPath = '';
|
|
|
|
|
this.name = '';
|
|
|
|
|
this.methods = new ASet<Method>(['n']);
|
|
|
|
|
this.hasGlob = false;
|
|
|
|
|
PathEvent.pathEventCache.set(e, this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(p === '*') {
|
|
|
|
|
// Wildcard means any path any event
|
|
|
|
|
if(p === '' || p === undefined || p === '*') {
|
|
|
|
|
// Empty string with methods (e.g., ":*") matches the root level/everything
|
|
|
|
|
this.module = '';
|
|
|
|
|
this.path = '';
|
|
|
|
|
this.fullPath = '**';
|
|
|
|
|
this.name = '';
|
|
|
|
|
this.methods = new ASet<Method>(['*']);
|
|
|
|
|
this.methods = new ASet<Method>(p === '*' ? ['*'] : <any>method.split(''));
|
|
|
|
|
this.hasGlob = true;
|
|
|
|
|
PathEvent.pathEventCache.set(e, this);
|
|
|
|
|
return;
|
|
|
|
|
@@ -292,11 +281,7 @@ export class PathEvent {
|
|
|
|
|
static filter(target: string | PathEvent | (string | PathEvent)[], ...filter: (string | PathEvent)[]): PathEvent[] {
|
|
|
|
|
const parsedTarget = makeArray(target).map(pe => pe instanceof PathEvent ? pe : new PathEvent(pe));
|
|
|
|
|
const parsedFilter = makeArray(filter).map(pe => pe instanceof PathEvent ? pe : new PathEvent(pe));
|
|
|
|
|
|
|
|
|
|
return parsedTarget.filter(t => {
|
|
|
|
|
const combined = PathEvent.combine(t);
|
|
|
|
|
return !!parsedFilter.find(r => PathEvent.matches(r, combined));
|
|
|
|
|
});
|
|
|
|
|
return parsedTarget.filter(t => !!parsedFilter.find(r => PathEvent.matches(r, t)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -306,7 +291,8 @@ export class PathEvent {
|
|
|
|
|
private static matches(pattern: PathEvent, target: PathEvent): boolean {
|
|
|
|
|
// Handle special cases
|
|
|
|
|
if(pattern.fullPath === '' || target.fullPath === '') return false;
|
|
|
|
|
if (pattern.fullPath === '*' || target.fullPath === '*') return pattern.methods.has('*') || target.methods.has('*') || pattern.methods.intersection(target.methods).length > 0;
|
|
|
|
|
if(pattern.fullPath === '**') return pattern.methods.has('*') || pattern.methods.intersection(target.methods).length > 0;
|
|
|
|
|
if(target.fullPath === '**') return pattern.methods.has('*') || target.methods.has('*') || pattern.methods.intersection(target.methods).length > 0;
|
|
|
|
|
|
|
|
|
|
// Check methods
|
|
|
|
|
const methodsMatch = pattern.all || target.all || pattern.methods.intersection(target.methods).length > 0;
|
|
|
|
|
@@ -338,10 +324,8 @@ export class PathEvent {
|
|
|
|
|
const parsedTarget = makeArray(target).map(pe => pe instanceof PathEvent ? pe : new PathEvent(pe));
|
|
|
|
|
const parsedRequired = makeArray(has).map(pe => pe instanceof PathEvent ? pe : new PathEvent(pe));
|
|
|
|
|
|
|
|
|
|
// If target is a single item, check directly; if multiple, combine first
|
|
|
|
|
const effectiveTarget = parsedTarget.length === 1 ? parsedTarget[0] : PathEvent.combine(...parsedTarget);
|
|
|
|
|
|
|
|
|
|
return !!parsedRequired.find(r => PathEvent.matches(r, effectiveTarget));
|
|
|
|
|
// Check if any target permission matches any required permission
|
|
|
|
|
return !!parsedRequired.find(r => !!parsedTarget.find(t => PathEvent.matches(r, t)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|