Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2240c93db5 | |||
| 3e9052c4a7 | |||
| 326f6fe851 | |||
| 5b57b67542 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,6 +9,7 @@ node_modules
|
||||
uploads
|
||||
public/momentum*js
|
||||
junit.xml
|
||||
/docs/
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
5
.gitmodules
vendored
5
.gitmodules
vendored
@@ -1,5 +0,0 @@
|
||||
[submodule "docs"]
|
||||
path = docs
|
||||
url = ../utils.wiki.git
|
||||
branch = master
|
||||
ignore = all
|
||||
1
docs
1
docs
Submodule docs deleted from dbf5d8cd07
18
package.json
18
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.27.11",
|
||||
"version": "0.27.14",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
@@ -30,15 +30,15 @@
|
||||
"var-persist": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.12",
|
||||
"fake-indexeddb": "^6.0.1",
|
||||
"jest": "^29.7.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"fake-indexeddb": "^6.2.5",
|
||||
"jest": "^30.2.0",
|
||||
"jest-junit": "^16.0.0",
|
||||
"ts-jest": "^29.1.2",
|
||||
"typedoc": "^0.26.7",
|
||||
"typescript": "^5.3.3",
|
||||
"vite": "^5.0.12",
|
||||
"vite-plugin-dts": "^4.5.3"
|
||||
"ts-jest": "^29.4.5",
|
||||
"typedoc": "^0.28.15",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^7.2.4",
|
||||
"vite-plugin-dts": "^4.5.4"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -119,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;
|
||||
@@ -293,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)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,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;
|
||||
@@ -339,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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,12 +45,12 @@ describe('Path Events', () => {
|
||||
expect(pe.all).toBe(true);
|
||||
expect(pe.fullPath).toBe('**');
|
||||
expect(pe.methods.has('*')).toBe(true);
|
||||
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('');
|
||||
expect(pe.none).toBe(true);
|
||||
expect(pe.fullPath).toBe('');
|
||||
expect(pe.has('any/path:c')).toBe(true);
|
||||
});
|
||||
|
||||
it('parses none method', () => {
|
||||
@@ -80,6 +80,7 @@ describe('Path Events', () => {
|
||||
expect(c.methods.has('c')).toBe(true);
|
||||
expect(c.methods.has('r')).toBe(true);
|
||||
expect(c.methods.has('u')).toBe(true);
|
||||
expect(c.delete).toBe(false);
|
||||
});
|
||||
|
||||
it('combine stops at none', () => {
|
||||
@@ -94,6 +95,17 @@ describe('Path Events', () => {
|
||||
expect(d.none).toBe(false);
|
||||
});
|
||||
|
||||
it('combine works with wildcards', () => {
|
||||
expect(PathEvent.has([
|
||||
'payments/anonymous:d',
|
||||
'payments/anonymous:c',
|
||||
'payments/system:cr',
|
||||
'logs/Momentum:c',
|
||||
'products:r',
|
||||
'*'
|
||||
], 'actions/692a92d18afa11e6722e9f2e:r')).toBe(true);
|
||||
});
|
||||
|
||||
it('filter finds overlap by path and methods', () => {
|
||||
const events = [
|
||||
new PathEvent('users/sys:cr'),
|
||||
|
||||
@@ -35,7 +35,7 @@ describe('Time Utilities', () => {
|
||||
});
|
||||
|
||||
it('throws for unknown timezone', () => {
|
||||
expect(() => formatDate('YYYY', new Date(), '???')).toThrowError(/Invalid timezone/);
|
||||
expect(() => formatDate('YYYY', new Date(), '???')).toThrow(/Invalid timezone/);
|
||||
});
|
||||
|
||||
it('handles timezone by offset number', () => {
|
||||
|
||||
Reference in New Issue
Block a user