Compare commits

...

1 Commits

Author SHA1 Message Date
2240c93db5 Fixed path events
All checks were successful
Build / Publish Docs (push) Successful in 48s
Build / Build NPM Project (push) Successful in 1m6s
Build / Tag Version (push) Successful in 9s
2025-11-29 20:03:45 -05:00
3 changed files with 26 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.27.13", "version": "0.27.14",
"description": "Utility library", "description": "Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",

View File

@@ -119,25 +119,13 @@ export class PathEvent {
if(!method) method = '*'; if(!method) method = '*';
// Handle special cases // Handle special cases
if(p === '' || p === undefined) { if(p === '' || p === undefined || p === '*') {
// Empty string matches nothing // Empty string with methods (e.g., ":*") matches the root level/everything
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
this.module = ''; this.module = '';
this.path = ''; this.path = '';
this.fullPath = '**'; this.fullPath = '**';
this.name = ''; this.name = '';
this.methods = new ASet<Method>(['*']); this.methods = new ASet<Method>(p === '*' ? ['*'] : <any>method.split(''));
this.hasGlob = true; this.hasGlob = true;
PathEvent.pathEventCache.set(e, this); PathEvent.pathEventCache.set(e, this);
return; return;
@@ -303,7 +291,8 @@ export class PathEvent {
private static matches(pattern: PathEvent, target: PathEvent): boolean { private static matches(pattern: PathEvent, target: PathEvent): boolean {
// Handle special cases // Handle special cases
if(pattern.fullPath === '' || target.fullPath === '') return false; 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 // Check methods
const methodsMatch = pattern.all || target.all || pattern.methods.intersection(target.methods).length > 0; const methodsMatch = pattern.all || target.all || pattern.methods.intersection(target.methods).length > 0;

View File

@@ -48,10 +48,9 @@ describe('Path Events', () => {
expect(pe.hasAll('module:c', 'some/path:ud')).toBeTruthy(); expect(pe.hasAll('module:c', 'some/path:ud')).toBeTruthy();
}); });
it('parses empty string as none', () => { it('parses empty string as wildcard', () => {
const pe = new PathEvent(''); const pe = new PathEvent('');
expect(pe.none).toBe(true); expect(pe.has('any/path:c')).toBe(true);
expect(pe.fullPath).toBe('');
}); });
it('parses none method', () => { it('parses none method', () => {