h1v3 0.1.0
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/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/browser/event-store/modular.js +82 -0
- package/dist/browser/web/events.js +7 -0
- package/dist/browser/web/login.js +48 -0
- package/dist/browser/web/system.js +67 -0
- package/dist/browser/web-ui/components/login.html.js +44 -0
- package/dist/browser/web-ui/components/login.js +74 -0
- package/dist/browser/web-ui/components/notification.html.js +12 -0
- package/dist/browser/web-ui/components/notification.js +25 -0
- package/dist/browser/web-ui/components/partials/wa-utils.js +17 -0
- package/dist/browser/web-ui/errors.js +23 -0
- package/dist/browser/web-ui/system.js +20 -0
- package/package.json +22 -0
- package/scripts/dist-client.js +31 -0
- package/src/client/index.js +2 -0
- package/src/client/modular.js +82 -0
- package/src/client/node.js +29 -0
- package/src/client/web/events.js +7 -0
- package/src/client/web/login.js +48 -0
- package/src/client/web/system.js +67 -0
- package/src/client/web-ui/components/login.html.js +44 -0
- package/src/client/web-ui/components/login.js +74 -0
- package/src/client/web-ui/components/notification.html.js +12 -0
- package/src/client/web-ui/components/notification.js +25 -0
- package/src/client/web-ui/components/partials/wa-utils.js +17 -0
- package/src/client/web-ui/errors.js +23 -0
- package/src/client/web-ui/system.js +20 -0
- package/src/commands/generate-rules.js +80 -0
- package/src/commands/list-event-stores.js +24 -0
- package/src/commands/vendor.js +54 -0
- package/src/event-store/initialise.js +28 -0
- package/src/event-store/projections.js +38 -0
- package/src/exec-eventstore.js +65 -0
- package/src/index.js +18 -0
- package/src/load-configuration.js +21 -0
- package/src/schema.js +66 -0
- package/src/system/json.js +23 -0
- package/src/system/main.js +76 -0
package/src/schema.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Does the schema contain this dot-notated path?
|
|
2
|
+
export function schemaAllowsPath(schema, path) {
|
|
3
|
+
|
|
4
|
+
const parts = path.split('.');
|
|
5
|
+
let cur = schema;
|
|
6
|
+
|
|
7
|
+
for (let i = 0; i < parts.length; i++) {
|
|
8
|
+
const key = parts[i];
|
|
9
|
+
|
|
10
|
+
// must be an object schema at this step
|
|
11
|
+
if (cur && typeof cur === 'object' && !Array.isArray(cur)) {
|
|
12
|
+
if (!(key in cur)) return false;
|
|
13
|
+
cur = cur[key];
|
|
14
|
+
} else {
|
|
15
|
+
// if we hit a leaf constructor (String/Number/...) before the end, it's invalid
|
|
16
|
+
return i === parts.length - 1 && typeof cur === 'function';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// valid if leaf is a constructor or object schema
|
|
20
|
+
return typeof cur === 'function' || (cur && typeof cur === 'object');
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Delete a value by dot-notated path (no-ops if missing)
|
|
25
|
+
export function deleteByPath(obj, path) {
|
|
26
|
+
|
|
27
|
+
const parts = path.split('.');
|
|
28
|
+
let cur = obj;
|
|
29
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
30
|
+
|
|
31
|
+
if (!cur || typeof cur !== 'object') return; // nothing to delete
|
|
32
|
+
cur = cur[parts[i]];
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
if (cur && typeof cur === 'object') delete cur[parts[parts.length - 1]];
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function filterBySchema(schema, obj) {
|
|
40
|
+
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const key in schema) {
|
|
43
|
+
|
|
44
|
+
const expected = schema[key];
|
|
45
|
+
const value = obj[key];
|
|
46
|
+
|
|
47
|
+
if (expected === String) {
|
|
48
|
+
if (typeof value === "string") result[key] = value;
|
|
49
|
+
} else if (expected === Number) {
|
|
50
|
+
if (typeof value === "number") result[key] = value;
|
|
51
|
+
} else if (expected === Boolean) {
|
|
52
|
+
if (typeof value === "boolean") result[key] = value;
|
|
53
|
+
} else if (expected === Array) {
|
|
54
|
+
if (Array.isArray(value)) result[key] = value;
|
|
55
|
+
} else if (expected && typeof expected === "object") {
|
|
56
|
+
// nested schema
|
|
57
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
58
|
+
const nested = filterBySchema(expected, value);
|
|
59
|
+
if (Object.keys(nested).length > 0) result[key] = nested;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
|
|
66
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
|
|
3
|
+
export function readJSON(path) {
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
|
|
7
|
+
return JSON.parse(readFileSync(path));
|
|
8
|
+
|
|
9
|
+
} catch (err) {
|
|
10
|
+
|
|
11
|
+
if (err?.code === "ENOENT") {
|
|
12
|
+
|
|
13
|
+
return {};
|
|
14
|
+
|
|
15
|
+
} else {
|
|
16
|
+
|
|
17
|
+
throw err;
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import minimist from "minimist";
|
|
2
|
+
import { loadConfiguration } from "../load-configuration.js";
|
|
3
|
+
|
|
4
|
+
export async function main(commands) {
|
|
5
|
+
|
|
6
|
+
const argv = minimist(process.argv.slice(2));
|
|
7
|
+
if (argv._.length) {
|
|
8
|
+
|
|
9
|
+
for (const verb of argv._) {
|
|
10
|
+
|
|
11
|
+
await invoke(commands, verb, argv);
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
} else {
|
|
16
|
+
|
|
17
|
+
displayHelp(commands);
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function invoke(commands, verb, argv) {
|
|
24
|
+
|
|
25
|
+
if (!(verb in commands)) {
|
|
26
|
+
|
|
27
|
+
displayHelp(commands);
|
|
28
|
+
console.log("");
|
|
29
|
+
console.error(`Unknown command: ${verb}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
if (commands[verb].loadConfig === false) {
|
|
34
|
+
|
|
35
|
+
commands[verb].strategy(argv);
|
|
36
|
+
|
|
37
|
+
} else {
|
|
38
|
+
|
|
39
|
+
const config = await loadConfiguration(argv);
|
|
40
|
+
commands[verb].strategy(argv, config);
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function displayHelp(commands) {
|
|
47
|
+
|
|
48
|
+
console.log("Help:");
|
|
49
|
+
console.log("");
|
|
50
|
+
|
|
51
|
+
Object.entries(commands).forEach(([name, { description, parameters } = {}] = []) => {
|
|
52
|
+
|
|
53
|
+
let indent = " ";
|
|
54
|
+
console.log(`${indent}${name}: ${description}`);
|
|
55
|
+
indent += " ".repeat(name.length + 2);
|
|
56
|
+
Object.entries(parameters).forEach(([name, { description, defaultValue, examples }]) => {
|
|
57
|
+
|
|
58
|
+
const maybeExamples = examples?.length ?examples.map(x => `--${name}="${x}"`).join(", ") : "";
|
|
59
|
+
console.log(`${indent}--${name}: ${description}`);
|
|
60
|
+
indent += " ".repeat(name.length + 4);
|
|
61
|
+
if (maybeExamples) {
|
|
62
|
+
|
|
63
|
+
console.log(`${indent}(e.g. ${maybeExamples})`);
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
if (defaultValue) {
|
|
67
|
+
|
|
68
|
+
console.log(`${indent}DEFAULT: ${defaultValue}`);
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
}
|