more path event fixes.... i hope...
This commit is contained in:
parent
3b7d28de4b
commit
e2b8c35535
@ -140,13 +140,10 @@ export class PathEvent {
|
|||||||
*/
|
*/
|
||||||
static filter(target: string | PathEvent | (string | PathEvent)[], ...filter: (string | PathEvent)[]): PathEvent[] {
|
static filter(target: string | PathEvent | (string | PathEvent)[], ...filter: (string | PathEvent)[]): PathEvent[] {
|
||||||
const parsedTarget = makeArray(target).map(pe => new PathEvent(pe));
|
const parsedTarget = makeArray(target).map(pe => new PathEvent(pe));
|
||||||
const parsedFind = makeArray(filter).map(pe => new PathEvent(pe));
|
const parsedFilter = makeArray(filter).map(pe => new PathEvent(pe));
|
||||||
return parsedTarget.filter(t => {
|
return parsedTarget.filter(t => !!parsedFilter.find(f =>
|
||||||
if(!t.fullPath && t.all) return true;
|
(t.fullPath == '*' || f.fullPath == '*' || t.fullPath.startsWith(f.fullPath) || f.fullPath.startsWith(t.fullPath)) &&
|
||||||
return !!parsedFind.find(f =>
|
(f.all || t.all || t.methods.intersection(f.methods).length)));
|
||||||
(t.fullPath.startsWith(f.fullPath) || f.fullPath.startsWith(t.fullPath)) &&
|
|
||||||
(f.all || t.all || t.methods.intersection(f.methods).length));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,15 +154,12 @@ export class PathEvent {
|
|||||||
* @return {boolean} Whether there is any overlap
|
* @return {boolean} Whether there is any overlap
|
||||||
*/
|
*/
|
||||||
static has(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): boolean {
|
static has(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): boolean {
|
||||||
const parsedRequired = makeArray(has).map(pe => new PathEvent(pe));
|
|
||||||
const parsedTarget = makeArray(target).map(pe => new PathEvent(pe));
|
const parsedTarget = makeArray(target).map(pe => new PathEvent(pe));
|
||||||
return !!parsedRequired.find(r => {
|
const parsedRequired = makeArray(has).map(pe => new PathEvent(pe));
|
||||||
if(!r.fullPath && r.all) return true;
|
return !!parsedRequired.find(r => !!parsedTarget.find(t =>
|
||||||
const filtered = parsedTarget.filter(p => r.fullPath.startsWith(p.fullPath));
|
(r.fullPath == '*' || t.fullPath == '*' || r.fullPath.startsWith(t.fullPath) || t.fullPath.startsWith(r.fullPath)) &&
|
||||||
if(!filtered.length) return false;
|
(r.all || t.all || r.methods.intersection(t.methods).length)
|
||||||
const combined = PathEvent.combine(...filtered);
|
));
|
||||||
return (!combined.none && (combined.all || r.all)) || combined.methods.intersection(r.methods).length;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,11 +103,9 @@ describe('Path Events', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has returns true for overlapping', () => {
|
it('has returns true for overlapping', () => {
|
||||||
const events = [
|
const events = [new PathEvent('users/sys:cr')];
|
||||||
new PathEvent('users/sys:cr'),
|
expect(PathEvent.has(events, 'users/sys:r')).toBeTruthy();
|
||||||
];
|
expect(PathEvent.has(events, 'users/nope:r')).toBeFalsy();
|
||||||
expect(PathEvent.has(events, 'users/sys:r')).toBe(true);
|
|
||||||
expect(PathEvent.has(events, 'users/nope:r')).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hasAll returns true only if all overlap', () => {
|
it('hasAll returns true only if all overlap', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user