@hasna/events 0.1.10 → 0.1.12
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/README.md +5 -1
- package/dist/cli/index.js +18 -5
- package/dist/commander.js +18 -5
- package/dist/filter.js +18 -5
- package/dist/index.js +18 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hasna/events
|
|
2
2
|
|
|
3
|
-
Shared event envelopes, subscription config, webhook delivery, and command
|
|
3
|
+
Shared event envelopes, subscription config, webhook delivery, and command transports for Hasna open-source apps.
|
|
4
4
|
|
|
5
5
|
This package is local-first. By default it stores JSON files under `~/.hasna/events`:
|
|
6
6
|
|
|
@@ -123,6 +123,10 @@ window.
|
|
|
123
123
|
## Command Transport
|
|
124
124
|
|
|
125
125
|
Command channels run a local process and pass the event on stdin and environment variables.
|
|
126
|
+
For production task-created automation, route to tested package commands such as
|
|
127
|
+
`loops events handle todos-task` rather than long-lived local scripts. Scripts
|
|
128
|
+
like `scripts/handle-event.ts` are useful prototypes; repeated behavior should
|
|
129
|
+
move into the owning `open-*` package with tests and bounded evidence.
|
|
126
130
|
|
|
127
131
|
```ts
|
|
128
132
|
await events.addChannel({
|
package/dist/cli/index.js
CHANGED
|
@@ -18,6 +18,19 @@ function getPathValue(input, path) {
|
|
|
18
18
|
return;
|
|
19
19
|
}, input);
|
|
20
20
|
}
|
|
21
|
+
function getFieldValues(input, path) {
|
|
22
|
+
const values = [];
|
|
23
|
+
const push = (value) => {
|
|
24
|
+
if (!values.some((item) => Object.is(item, value)))
|
|
25
|
+
values.push(value);
|
|
26
|
+
};
|
|
27
|
+
if (path.includes(".") && path in input)
|
|
28
|
+
push(input[path]);
|
|
29
|
+
const nestedValue = getPathValue(input, path);
|
|
30
|
+
if (nestedValue !== undefined || !path.includes("."))
|
|
31
|
+
push(nestedValue);
|
|
32
|
+
return values;
|
|
33
|
+
}
|
|
21
34
|
function wildcardToRegExp(pattern, options = {}) {
|
|
22
35
|
let body = "";
|
|
23
36
|
for (let index = 0;index < pattern.length; index += 1) {
|
|
@@ -47,15 +60,15 @@ function matchRecord(input, matcher) {
|
|
|
47
60
|
if (!matcher)
|
|
48
61
|
return true;
|
|
49
62
|
return Object.entries(matcher).every(([path, expected]) => {
|
|
50
|
-
const
|
|
51
|
-
return matchField(
|
|
63
|
+
const actualValues = getFieldValues(input, path);
|
|
64
|
+
return matchField(actualValues, expected, path);
|
|
52
65
|
});
|
|
53
66
|
}
|
|
54
|
-
function matchField(
|
|
67
|
+
function matchField(actualValues, expected, path) {
|
|
55
68
|
if (isNegativeMatcher(expected)) {
|
|
56
|
-
return !matchPositiveField(actual, expected.not, path);
|
|
69
|
+
return !actualValues.some((actual) => matchPositiveField(actual, expected.not, path));
|
|
57
70
|
}
|
|
58
|
-
return matchPositiveField(actual, expected, path);
|
|
71
|
+
return actualValues.some((actual) => matchPositiveField(actual, expected, path));
|
|
59
72
|
}
|
|
60
73
|
function matchPositiveField(actual, expected, path) {
|
|
61
74
|
if (typeof expected === "string" || Array.isArray(expected)) {
|
package/dist/commander.js
CHANGED
|
@@ -8,6 +8,19 @@ function getPathValue(input, path) {
|
|
|
8
8
|
return;
|
|
9
9
|
}, input);
|
|
10
10
|
}
|
|
11
|
+
function getFieldValues(input, path) {
|
|
12
|
+
const values = [];
|
|
13
|
+
const push = (value) => {
|
|
14
|
+
if (!values.some((item) => Object.is(item, value)))
|
|
15
|
+
values.push(value);
|
|
16
|
+
};
|
|
17
|
+
if (path.includes(".") && path in input)
|
|
18
|
+
push(input[path]);
|
|
19
|
+
const nestedValue = getPathValue(input, path);
|
|
20
|
+
if (nestedValue !== undefined || !path.includes("."))
|
|
21
|
+
push(nestedValue);
|
|
22
|
+
return values;
|
|
23
|
+
}
|
|
11
24
|
function wildcardToRegExp(pattern, options = {}) {
|
|
12
25
|
let body = "";
|
|
13
26
|
for (let index = 0;index < pattern.length; index += 1) {
|
|
@@ -37,15 +50,15 @@ function matchRecord(input, matcher) {
|
|
|
37
50
|
if (!matcher)
|
|
38
51
|
return true;
|
|
39
52
|
return Object.entries(matcher).every(([path, expected]) => {
|
|
40
|
-
const
|
|
41
|
-
return matchField(
|
|
53
|
+
const actualValues = getFieldValues(input, path);
|
|
54
|
+
return matchField(actualValues, expected, path);
|
|
42
55
|
});
|
|
43
56
|
}
|
|
44
|
-
function matchField(
|
|
57
|
+
function matchField(actualValues, expected, path) {
|
|
45
58
|
if (isNegativeMatcher(expected)) {
|
|
46
|
-
return !matchPositiveField(actual, expected.not, path);
|
|
59
|
+
return !actualValues.some((actual) => matchPositiveField(actual, expected.not, path));
|
|
47
60
|
}
|
|
48
|
-
return matchPositiveField(actual, expected, path);
|
|
61
|
+
return actualValues.some((actual) => matchPositiveField(actual, expected, path));
|
|
49
62
|
}
|
|
50
63
|
function matchPositiveField(actual, expected, path) {
|
|
51
64
|
if (typeof expected === "string" || Array.isArray(expected)) {
|
package/dist/filter.js
CHANGED
|
@@ -8,6 +8,19 @@ function getPathValue(input, path) {
|
|
|
8
8
|
return;
|
|
9
9
|
}, input);
|
|
10
10
|
}
|
|
11
|
+
function getFieldValues(input, path) {
|
|
12
|
+
const values = [];
|
|
13
|
+
const push = (value) => {
|
|
14
|
+
if (!values.some((item) => Object.is(item, value)))
|
|
15
|
+
values.push(value);
|
|
16
|
+
};
|
|
17
|
+
if (path.includes(".") && path in input)
|
|
18
|
+
push(input[path]);
|
|
19
|
+
const nestedValue = getPathValue(input, path);
|
|
20
|
+
if (nestedValue !== undefined || !path.includes("."))
|
|
21
|
+
push(nestedValue);
|
|
22
|
+
return values;
|
|
23
|
+
}
|
|
11
24
|
function wildcardToRegExp(pattern, options = {}) {
|
|
12
25
|
let body = "";
|
|
13
26
|
for (let index = 0;index < pattern.length; index += 1) {
|
|
@@ -37,15 +50,15 @@ function matchRecord(input, matcher) {
|
|
|
37
50
|
if (!matcher)
|
|
38
51
|
return true;
|
|
39
52
|
return Object.entries(matcher).every(([path, expected]) => {
|
|
40
|
-
const
|
|
41
|
-
return matchField(
|
|
53
|
+
const actualValues = getFieldValues(input, path);
|
|
54
|
+
return matchField(actualValues, expected, path);
|
|
42
55
|
});
|
|
43
56
|
}
|
|
44
|
-
function matchField(
|
|
57
|
+
function matchField(actualValues, expected, path) {
|
|
45
58
|
if (isNegativeMatcher(expected)) {
|
|
46
|
-
return !matchPositiveField(actual, expected.not, path);
|
|
59
|
+
return !actualValues.some((actual) => matchPositiveField(actual, expected.not, path));
|
|
47
60
|
}
|
|
48
|
-
return matchPositiveField(actual, expected, path);
|
|
61
|
+
return actualValues.some((actual) => matchPositiveField(actual, expected, path));
|
|
49
62
|
}
|
|
50
63
|
function matchPositiveField(actual, expected, path) {
|
|
51
64
|
if (typeof expected === "string" || Array.isArray(expected)) {
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,19 @@ function getPathValue(input, path) {
|
|
|
8
8
|
return;
|
|
9
9
|
}, input);
|
|
10
10
|
}
|
|
11
|
+
function getFieldValues(input, path) {
|
|
12
|
+
const values = [];
|
|
13
|
+
const push = (value) => {
|
|
14
|
+
if (!values.some((item) => Object.is(item, value)))
|
|
15
|
+
values.push(value);
|
|
16
|
+
};
|
|
17
|
+
if (path.includes(".") && path in input)
|
|
18
|
+
push(input[path]);
|
|
19
|
+
const nestedValue = getPathValue(input, path);
|
|
20
|
+
if (nestedValue !== undefined || !path.includes("."))
|
|
21
|
+
push(nestedValue);
|
|
22
|
+
return values;
|
|
23
|
+
}
|
|
11
24
|
function wildcardToRegExp(pattern, options = {}) {
|
|
12
25
|
let body = "";
|
|
13
26
|
for (let index = 0;index < pattern.length; index += 1) {
|
|
@@ -37,15 +50,15 @@ function matchRecord(input, matcher) {
|
|
|
37
50
|
if (!matcher)
|
|
38
51
|
return true;
|
|
39
52
|
return Object.entries(matcher).every(([path, expected]) => {
|
|
40
|
-
const
|
|
41
|
-
return matchField(
|
|
53
|
+
const actualValues = getFieldValues(input, path);
|
|
54
|
+
return matchField(actualValues, expected, path);
|
|
42
55
|
});
|
|
43
56
|
}
|
|
44
|
-
function matchField(
|
|
57
|
+
function matchField(actualValues, expected, path) {
|
|
45
58
|
if (isNegativeMatcher(expected)) {
|
|
46
|
-
return !matchPositiveField(actual, expected.not, path);
|
|
59
|
+
return !actualValues.some((actual) => matchPositiveField(actual, expected.not, path));
|
|
47
60
|
}
|
|
48
|
-
return matchPositiveField(actual, expected, path);
|
|
61
|
+
return actualValues.some((actual) => matchPositiveField(actual, expected, path));
|
|
49
62
|
}
|
|
50
63
|
function matchPositiveField(actual, expected, path) {
|
|
51
64
|
if (typeof expected === "string" || Array.isArray(expected)) {
|