@seriousme/opifex 1.9.0 → 1.9.2
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/trie/trie.d.ts +58 -0
- package/dist/trie/trie.d.ts.map +1 -1
- package/dist/trie/trie.js +54 -1
- package/dist/trie/trie.js.map +1 -1
- package/package.json +1 -1
- package/trie/trie.ts +61 -4
package/dist/trie/trie.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Trie data structure implementation that supports wildcard matching
|
|
3
|
+
* @template T The type of values stored in the trie
|
|
4
|
+
*/
|
|
1
5
|
type Parts = string[];
|
|
6
|
+
/**
|
|
7
|
+
* Trie class for storing and matching hierarchical key-value pairs with wildcard support
|
|
8
|
+
* @template T The type of values stored in the trie
|
|
9
|
+
*/
|
|
2
10
|
export declare class Trie<T> {
|
|
3
11
|
#private;
|
|
4
12
|
private separator;
|
|
@@ -6,15 +14,65 @@ export declare class Trie<T> {
|
|
|
6
14
|
private wildcardSubtree;
|
|
7
15
|
private reservedPrefix;
|
|
8
16
|
private looseCompare;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new Trie instance
|
|
19
|
+
* @param looseCompare Whether to use loose comparison for object values
|
|
20
|
+
*/
|
|
9
21
|
constructor(looseCompare?: boolean);
|
|
22
|
+
/**
|
|
23
|
+
* Matches a child node with the given key parts
|
|
24
|
+
* @param child The child node key to match
|
|
25
|
+
* @param parts Remaining parts of the key to match
|
|
26
|
+
* @returns Array of matched values
|
|
27
|
+
*/
|
|
10
28
|
matchChild(child: string, parts: Parts): Array<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Matches a key against the trie
|
|
31
|
+
* @param key The key to match
|
|
32
|
+
* @returns Array of matched values
|
|
33
|
+
*/
|
|
11
34
|
match(key: string): T[];
|
|
35
|
+
/**
|
|
36
|
+
* Internal method to match reserved prefix keys
|
|
37
|
+
* @param parts Parts of the key to match
|
|
38
|
+
* @returns Array of matched values
|
|
39
|
+
*/
|
|
12
40
|
private _matchPrefix;
|
|
41
|
+
/**
|
|
42
|
+
* Internal method to match keys with wildcard support
|
|
43
|
+
* @param parts Parts of the key to match
|
|
44
|
+
* @returns Array of matched values
|
|
45
|
+
*/
|
|
13
46
|
private _match;
|
|
47
|
+
/**
|
|
48
|
+
* Adds a value to the trie at the specified key
|
|
49
|
+
* @param key The key to add the value at
|
|
50
|
+
* @param value The value to add
|
|
51
|
+
*/
|
|
14
52
|
add(key: string, value: T): void;
|
|
53
|
+
/**
|
|
54
|
+
* Internal method to recursively add a value
|
|
55
|
+
* @param parts Parts of the key to add at
|
|
56
|
+
* @param value The value to add
|
|
57
|
+
*/
|
|
15
58
|
private _add;
|
|
59
|
+
/**
|
|
60
|
+
* Removes a value from the trie at the specified key
|
|
61
|
+
* @param key The key to remove the value from
|
|
62
|
+
* @param value The value to remove
|
|
63
|
+
*/
|
|
16
64
|
remove(key: string, value: T): void;
|
|
65
|
+
/**
|
|
66
|
+
* Internal method to recursively remove a value
|
|
67
|
+
* @param parts Parts of the key to remove from
|
|
68
|
+
* @param value The value to remove
|
|
69
|
+
*/
|
|
17
70
|
private _remove;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a filter function for removing values
|
|
73
|
+
* @param value The value to filter against
|
|
74
|
+
* @returns Filter function
|
|
75
|
+
*/
|
|
18
76
|
private filter;
|
|
19
77
|
}
|
|
20
78
|
export {};
|
package/dist/trie/trie.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trie.d.ts","sourceRoot":"","sources":["../../trie/trie.ts"],"names":[],"mappings":"AAAA,KAAK,KAAK,GAAG,MAAM,EAAE,CAAC;AAEtB,qBAAa,IAAI,CAAC,CAAC;;IAGjB,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,eAAe,CAAO;IAC9B,OAAO,CAAC,cAAc,CAAO;IAC7B,OAAO,CAAC,YAAY,CAAU;
|
|
1
|
+
{"version":3,"file":"trie.d.ts","sourceRoot":"","sources":["../../trie/trie.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,KAAK,KAAK,GAAG,MAAM,EAAE,CAAC;AAEtB;;;GAGG;AACH,qBAAa,IAAI,CAAC,CAAC;;IAGjB,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,eAAe,CAAO;IAC9B,OAAO,CAAC,cAAc,CAAO;IAC7B,OAAO,CAAC,YAAY,CAAU;IAE9B;;;OAGG;gBACS,YAAY,UAAQ;IAMhC;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;IAKjD;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE;IAQvB;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAQpB;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAYd;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAIhC;;;;OAIG;IACH,OAAO,CAAC,IAAI;IAiBZ;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAInC;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAgBf;;;;OAIG;IACH,OAAO,CAAC,MAAM;CAaf"}
|
package/dist/trie/trie.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trie class for storing and matching hierarchical key-value pairs with wildcard support
|
|
3
|
+
* @template T The type of values stored in the trie
|
|
4
|
+
*/
|
|
1
5
|
export class Trie {
|
|
2
6
|
#value;
|
|
3
7
|
#children;
|
|
@@ -6,23 +10,42 @@ export class Trie {
|
|
|
6
10
|
wildcardSubtree = "#";
|
|
7
11
|
reservedPrefix = "$";
|
|
8
12
|
looseCompare;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new Trie instance
|
|
15
|
+
* @param looseCompare Whether to use loose comparison for object values
|
|
16
|
+
*/
|
|
9
17
|
constructor(looseCompare = false) {
|
|
10
18
|
this.#value = [];
|
|
11
19
|
this.#children = new Map();
|
|
12
20
|
this.looseCompare = looseCompare;
|
|
13
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Matches a child node with the given key parts
|
|
24
|
+
* @param child The child node key to match
|
|
25
|
+
* @param parts Remaining parts of the key to match
|
|
26
|
+
* @returns Array of matched values
|
|
27
|
+
*/
|
|
14
28
|
matchChild(child, parts) {
|
|
15
29
|
const childNode = this.#children.get(child);
|
|
16
30
|
return childNode ? childNode._match(parts) : [];
|
|
17
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Matches a key against the trie
|
|
34
|
+
* @param key The key to match
|
|
35
|
+
* @returns Array of matched values
|
|
36
|
+
*/
|
|
18
37
|
match(key) {
|
|
19
38
|
const parts = key.split(this.separator);
|
|
20
|
-
// toplevel wildcards are not allowed to match toplevel reserved topics
|
|
21
39
|
if (parts.length > 0 && parts[0].charAt(0) === this.reservedPrefix) {
|
|
22
40
|
return this._matchPrefix(parts);
|
|
23
41
|
}
|
|
24
42
|
return this._match(parts);
|
|
25
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Internal method to match reserved prefix keys
|
|
46
|
+
* @param parts Parts of the key to match
|
|
47
|
+
* @returns Array of matched values
|
|
48
|
+
*/
|
|
26
49
|
_matchPrefix(parts) {
|
|
27
50
|
if (parts.length === 0) {
|
|
28
51
|
return this.#value ? this.#value : [];
|
|
@@ -30,6 +53,11 @@ export class Trie {
|
|
|
30
53
|
const [first, ...rest] = parts;
|
|
31
54
|
return this.matchChild(first, rest);
|
|
32
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Internal method to match keys with wildcard support
|
|
58
|
+
* @param parts Parts of the key to match
|
|
59
|
+
* @returns Array of matched values
|
|
60
|
+
*/
|
|
33
61
|
_match(parts) {
|
|
34
62
|
if (parts.length === 0) {
|
|
35
63
|
return this.#value ? this.#value : [];
|
|
@@ -41,9 +69,19 @@ export class Trie {
|
|
|
41
69
|
const results = exact.concat(single, subtree);
|
|
42
70
|
return results;
|
|
43
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Adds a value to the trie at the specified key
|
|
74
|
+
* @param key The key to add the value at
|
|
75
|
+
* @param value The value to add
|
|
76
|
+
*/
|
|
44
77
|
add(key, value) {
|
|
45
78
|
return this._add(key.split(this.separator), value);
|
|
46
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Internal method to recursively add a value
|
|
82
|
+
* @param parts Parts of the key to add at
|
|
83
|
+
* @param value The value to add
|
|
84
|
+
*/
|
|
47
85
|
_add(parts, value) {
|
|
48
86
|
if (parts.length === 0) {
|
|
49
87
|
this.#value = this.#value.concat(value);
|
|
@@ -61,9 +99,19 @@ export class Trie {
|
|
|
61
99
|
}
|
|
62
100
|
return;
|
|
63
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Removes a value from the trie at the specified key
|
|
104
|
+
* @param key The key to remove the value from
|
|
105
|
+
* @param value The value to remove
|
|
106
|
+
*/
|
|
64
107
|
remove(key, value) {
|
|
65
108
|
return this._remove(key.split(this.separator), value);
|
|
66
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Internal method to recursively remove a value
|
|
112
|
+
* @param parts Parts of the key to remove from
|
|
113
|
+
* @param value The value to remove
|
|
114
|
+
*/
|
|
67
115
|
_remove(parts, value) {
|
|
68
116
|
if (parts.length === 0) {
|
|
69
117
|
const arr = this.#value || [];
|
|
@@ -79,6 +127,11 @@ export class Trie {
|
|
|
79
127
|
}
|
|
80
128
|
}
|
|
81
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Creates a filter function for removing values
|
|
132
|
+
* @param value The value to filter against
|
|
133
|
+
* @returns Filter function
|
|
134
|
+
*/
|
|
82
135
|
filter(value) {
|
|
83
136
|
if (this.looseCompare && typeof value === "object") {
|
|
84
137
|
return (item) => {
|
package/dist/trie/trie.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../trie/trie.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../trie/trie.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,OAAO,IAAI;IACf,MAAM,CAAW;IACjB,SAAS,CAAuB;IACxB,SAAS,GAAG,GAAG,CAAC;IAChB,WAAW,GAAG,GAAG,CAAC;IAClB,eAAe,GAAG,GAAG,CAAC;IACtB,cAAc,GAAG,GAAG,CAAC;IACrB,YAAY,CAAU;IAE9B;;;OAGG;IACH,YAAY,YAAY,GAAG,KAAK;QAC9B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,KAAa,EAAE,KAAY;QACpC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC5C,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,GAAW;QACf,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,cAAc,EAAE,CAAC;YACnE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QACD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AK,CAAC;QAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1B,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBAC1D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,KAAQ;QACrB,IAAI,IAAI,CAAC,YAAY,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACnD,OAAO,CAAC,IAAI,EAAE,EAAE;gBACd,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;oBACxB,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;wBAC7B,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,KAAK,CAAC;IAClC,CAAC;CACF"}
|
package/package.json
CHANGED
package/trie/trie.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Trie data structure implementation that supports wildcard matching
|
|
3
|
+
* @template T The type of values stored in the trie
|
|
4
|
+
*/
|
|
1
5
|
type Parts = string[];
|
|
2
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Trie class for storing and matching hierarchical key-value pairs with wildcard support
|
|
9
|
+
* @template T The type of values stored in the trie
|
|
10
|
+
*/
|
|
3
11
|
export class Trie<T> {
|
|
4
12
|
#value: Array<T>;
|
|
5
13
|
#children: Map<string, Trie<T>>;
|
|
@@ -9,26 +17,45 @@ export class Trie<T> {
|
|
|
9
17
|
private reservedPrefix = "$";
|
|
10
18
|
private looseCompare: boolean;
|
|
11
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new Trie instance
|
|
22
|
+
* @param looseCompare Whether to use loose comparison for object values
|
|
23
|
+
*/
|
|
12
24
|
constructor(looseCompare = false) {
|
|
13
25
|
this.#value = [];
|
|
14
26
|
this.#children = new Map();
|
|
15
27
|
this.looseCompare = looseCompare;
|
|
16
28
|
}
|
|
17
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Matches a child node with the given key parts
|
|
32
|
+
* @param child The child node key to match
|
|
33
|
+
* @param parts Remaining parts of the key to match
|
|
34
|
+
* @returns Array of matched values
|
|
35
|
+
*/
|
|
18
36
|
matchChild(child: string, parts: Parts): Array<T> {
|
|
19
37
|
const childNode = this.#children.get(child);
|
|
20
38
|
return childNode ? childNode._match(parts) : [];
|
|
21
39
|
}
|
|
22
40
|
|
|
23
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Matches a key against the trie
|
|
43
|
+
* @param key The key to match
|
|
44
|
+
* @returns Array of matched values
|
|
45
|
+
*/
|
|
46
|
+
match(key: string): T[] {
|
|
24
47
|
const parts = key.split(this.separator);
|
|
25
|
-
// toplevel wildcards are not allowed to match toplevel reserved topics
|
|
26
48
|
if (parts.length > 0 && parts[0].charAt(0) === this.reservedPrefix) {
|
|
27
49
|
return this._matchPrefix(parts);
|
|
28
50
|
}
|
|
29
51
|
return this._match(parts);
|
|
30
52
|
}
|
|
31
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Internal method to match reserved prefix keys
|
|
56
|
+
* @param parts Parts of the key to match
|
|
57
|
+
* @returns Array of matched values
|
|
58
|
+
*/
|
|
32
59
|
private _matchPrefix(parts: Parts): Array<T> {
|
|
33
60
|
if (parts.length === 0) {
|
|
34
61
|
return this.#value ? this.#value : [];
|
|
@@ -37,6 +64,11 @@ export class Trie<T> {
|
|
|
37
64
|
return this.matchChild(first, rest);
|
|
38
65
|
}
|
|
39
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Internal method to match keys with wildcard support
|
|
69
|
+
* @param parts Parts of the key to match
|
|
70
|
+
* @returns Array of matched values
|
|
71
|
+
*/
|
|
40
72
|
private _match(parts: Parts): Array<T> {
|
|
41
73
|
if (parts.length === 0) {
|
|
42
74
|
return this.#value ? this.#value : [];
|
|
@@ -49,10 +81,20 @@ export class Trie<T> {
|
|
|
49
81
|
return results;
|
|
50
82
|
}
|
|
51
83
|
|
|
52
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Adds a value to the trie at the specified key
|
|
86
|
+
* @param key The key to add the value at
|
|
87
|
+
* @param value The value to add
|
|
88
|
+
*/
|
|
89
|
+
add(key: string, value: T): void {
|
|
53
90
|
return this._add(key.split(this.separator), value);
|
|
54
91
|
}
|
|
55
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Internal method to recursively add a value
|
|
95
|
+
* @param parts Parts of the key to add at
|
|
96
|
+
* @param value The value to add
|
|
97
|
+
*/
|
|
56
98
|
private _add(parts: Parts, value: T) {
|
|
57
99
|
if (parts.length === 0) {
|
|
58
100
|
this.#value = this.#value.concat(value);
|
|
@@ -70,10 +112,20 @@ export class Trie<T> {
|
|
|
70
112
|
return;
|
|
71
113
|
}
|
|
72
114
|
|
|
73
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Removes a value from the trie at the specified key
|
|
117
|
+
* @param key The key to remove the value from
|
|
118
|
+
* @param value The value to remove
|
|
119
|
+
*/
|
|
120
|
+
remove(key: string, value: T): void {
|
|
74
121
|
return this._remove(key.split(this.separator), value);
|
|
75
122
|
}
|
|
76
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Internal method to recursively remove a value
|
|
126
|
+
* @param parts Parts of the key to remove from
|
|
127
|
+
* @param value The value to remove
|
|
128
|
+
*/
|
|
77
129
|
private _remove(parts: Parts, value: T): void {
|
|
78
130
|
if (parts.length === 0) {
|
|
79
131
|
const arr = this.#value || [];
|
|
@@ -90,6 +142,11 @@ export class Trie<T> {
|
|
|
90
142
|
}
|
|
91
143
|
}
|
|
92
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Creates a filter function for removing values
|
|
147
|
+
* @param value The value to filter against
|
|
148
|
+
* @returns Filter function
|
|
149
|
+
*/
|
|
93
150
|
private filter(value: T): (value: T, index: number, array: T[]) => boolean {
|
|
94
151
|
if (this.looseCompare && typeof value === "object") {
|
|
95
152
|
return (item) => {
|