hola-server 1.0.11 → 3.0.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/README.md +382 -1
- package/dist/config/index.d.ts +46 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +55 -0
- package/dist/config/index.js.map +1 -0
- package/dist/core/array.d.ts +27 -0
- package/dist/core/array.d.ts.map +1 -0
- package/dist/core/array.js +66 -0
- package/dist/core/array.js.map +1 -0
- package/dist/core/bash.d.ts +51 -0
- package/dist/core/bash.d.ts.map +1 -0
- package/dist/core/bash.js +161 -0
- package/dist/core/bash.js.map +1 -0
- package/dist/core/chart.d.ts +11 -0
- package/dist/core/chart.d.ts.map +1 -0
- package/dist/core/chart.js +35 -0
- package/dist/core/chart.js.map +1 -0
- package/dist/core/date.d.ts +11 -0
- package/dist/core/date.d.ts.map +1 -0
- package/dist/core/date.js +18 -0
- package/dist/core/date.js.map +1 -0
- package/dist/core/encrypt.d.ts +18 -0
- package/dist/core/encrypt.d.ts.map +1 -0
- package/dist/core/encrypt.js +50 -0
- package/dist/core/encrypt.js.map +1 -0
- package/dist/core/file.d.ts +22 -0
- package/dist/core/file.d.ts.map +1 -0
- package/dist/core/file.js +21 -0
- package/dist/core/file.js.map +1 -0
- package/dist/core/lhs.d.ts +17 -0
- package/dist/core/lhs.d.ts.map +1 -0
- package/dist/core/lhs.js +30 -0
- package/dist/core/lhs.js.map +1 -0
- package/dist/core/meta.d.ts +200 -0
- package/dist/core/meta.d.ts.map +1 -0
- package/dist/core/meta.js +336 -0
- package/dist/core/meta.js.map +1 -0
- package/dist/core/number.d.ts +37 -0
- package/dist/core/number.d.ts.map +1 -0
- package/dist/core/number.js +99 -0
- package/dist/core/number.js.map +1 -0
- package/dist/core/obj.d.ts +9 -0
- package/dist/core/obj.d.ts.map +1 -0
- package/dist/core/obj.js +15 -0
- package/dist/core/obj.js.map +1 -0
- package/dist/core/random.d.ts +7 -0
- package/dist/core/random.d.ts.map +1 -0
- package/dist/core/random.js +7 -0
- package/dist/core/random.js.map +1 -0
- package/dist/core/role.d.ts +42 -0
- package/dist/core/role.d.ts.map +1 -0
- package/dist/core/role.js +81 -0
- package/dist/core/role.js.map +1 -0
- package/dist/core/thread.d.ts +7 -0
- package/dist/core/thread.d.ts.map +1 -0
- package/dist/core/thread.js +7 -0
- package/dist/core/thread.js.map +1 -0
- package/dist/core/type.d.ts +46 -0
- package/dist/core/type.d.ts.map +1 -0
- package/dist/core/type.js +281 -0
- package/dist/core/type.js.map +1 -0
- package/dist/core/url.d.ts +20 -0
- package/dist/core/url.d.ts.map +1 -0
- package/dist/core/url.js +24 -0
- package/dist/core/url.js.map +1 -0
- package/dist/core/validate.d.ts +11 -0
- package/dist/core/validate.d.ts.map +1 -0
- package/dist/core/validate.js +19 -0
- package/dist/core/validate.js.map +1 -0
- package/dist/db/db.d.ts +72 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +225 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/entity.d.ts +77 -0
- package/dist/db/entity.d.ts.map +1 -0
- package/dist/db/entity.js +671 -0
- package/dist/db/entity.js.map +1 -0
- package/dist/db/gridfs.d.ts +29 -0
- package/dist/db/gridfs.d.ts.map +1 -0
- package/dist/db/gridfs.js +125 -0
- package/dist/db/gridfs.js.map +1 -0
- package/dist/db/index.d.ts +8 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +8 -0
- package/dist/db/index.js.map +1 -0
- package/dist/errors/auth.d.ts +15 -0
- package/dist/errors/auth.d.ts.map +1 -0
- package/dist/errors/auth.js +21 -0
- package/dist/errors/auth.js.map +1 -0
- package/dist/errors/http.d.ts +15 -0
- package/dist/errors/http.d.ts.map +1 -0
- package/dist/errors/http.js +21 -0
- package/dist/errors/http.js.map +1 -0
- package/dist/errors/index.d.ts +18 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +18 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/validation.d.ts +11 -0
- package/dist/errors/validation.d.ts.map +1 -0
- package/dist/errors/validation.js +15 -0
- package/dist/errors/validation.js.map +1 -0
- package/dist/http/code.d.ts +21 -0
- package/dist/http/code.d.ts.map +1 -0
- package/dist/http/code.js +27 -0
- package/dist/http/code.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/meta/index.d.ts +9 -0
- package/dist/meta/index.d.ts.map +1 -0
- package/dist/meta/index.js +11 -0
- package/dist/meta/index.js.map +1 -0
- package/dist/meta/router.d.ts +26 -0
- package/dist/meta/router.d.ts.map +1 -0
- package/dist/meta/router.js +258 -0
- package/dist/meta/router.js.map +1 -0
- package/dist/meta/schema.d.ts +41 -0
- package/dist/meta/schema.d.ts.map +1 -0
- package/dist/meta/schema.js +69 -0
- package/dist/meta/schema.js.map +1 -0
- package/dist/plugins/auth.d.ts +248 -0
- package/dist/plugins/auth.d.ts.map +1 -0
- package/dist/plugins/auth.js +121 -0
- package/dist/plugins/auth.js.map +1 -0
- package/dist/plugins/body.d.ts +47 -0
- package/dist/plugins/body.d.ts.map +1 -0
- package/dist/plugins/body.js +36 -0
- package/dist/plugins/body.js.map +1 -0
- package/dist/plugins/cors.d.ts +62 -0
- package/dist/plugins/cors.d.ts.map +1 -0
- package/dist/plugins/cors.js +17 -0
- package/dist/plugins/cors.js.map +1 -0
- package/dist/plugins/error.d.ts +51 -0
- package/dist/plugins/error.d.ts.map +1 -0
- package/dist/plugins/error.js +51 -0
- package/dist/plugins/error.js.map +1 -0
- package/dist/plugins/index.d.ts +9 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +9 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/setting.d.ts +66 -0
- package/dist/setting.d.ts.map +1 -0
- package/dist/setting.js +27 -0
- package/dist/setting.js.map +1 -0
- package/dist/tool/gen_i18n.d.ts +10 -0
- package/dist/tool/gen_i18n.d.ts.map +1 -0
- package/dist/tool/gen_i18n.js +51 -0
- package/dist/tool/gen_i18n.js.map +1 -0
- package/dist/tool/vector_store.d.ts +72 -0
- package/dist/tool/vector_store.d.ts.map +1 -0
- package/dist/tool/vector_store.js +203 -0
- package/dist/tool/vector_store.js.map +1 -0
- package/package.json +38 -23
- package/core/array.js +0 -187
- package/core/bash.js +0 -345
- package/core/chart.js +0 -36
- package/core/cron.js +0 -10
- package/core/date.js +0 -55
- package/core/encrypt.js +0 -16
- package/core/file.js +0 -38
- package/core/lhs.js +0 -27
- package/core/meta.js +0 -359
- package/core/msg.js +0 -11
- package/core/number.js +0 -179
- package/core/obj.js +0 -22
- package/core/random.js +0 -9
- package/core/role.js +0 -116
- package/core/thread.js +0 -3
- package/core/type.js +0 -329
- package/core/url.js +0 -22
- package/core/validate.js +0 -32
- package/db/db.js +0 -376
- package/db/entity.js +0 -1252
- package/db/gridfs.js +0 -221
- package/http/code.js +0 -18
- package/http/context.js +0 -17
- package/http/cors.js +0 -15
- package/http/error.js +0 -21
- package/http/express.js +0 -75
- package/http/params.js +0 -57
- package/http/router.js +0 -72
- package/http/session.js +0 -50
- package/index.js +0 -36
- package/router/clone.js +0 -73
- package/router/create.js +0 -59
- package/router/delete.js +0 -53
- package/router/read.js +0 -177
- package/router/update.js +0 -107
- package/setting.js +0 -51
- package/test/core/date.js +0 -37
- package/test/core/encrypt.js +0 -14
- package/test/core/meta.js +0 -594
- package/test/core/number.js +0 -17
- package/test/crud/router.js +0 -99
- package/test/db/db.js +0 -72
- package/test/entity/create.js +0 -442
- package/test/entity/delete.js +0 -480
- package/test/entity/read.js +0 -285
- package/test/entity/update.js +0 -252
- package/test/router/role.js +0 -15
- package/test/router/user.js +0 -17
- package/tool/gen_i18n.js +0 -30
- package/tool/test.json +0 -25
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bash command execution and SSH utility functions.
|
|
3
|
+
* @module core/bash
|
|
4
|
+
*/
|
|
5
|
+
import { $ } from 'bun';
|
|
6
|
+
import { random_code } from './random.js';
|
|
7
|
+
import { is_log_debug, is_log_error, log_debug, log_error } from '../db/db.js';
|
|
8
|
+
const LOG_BASH = "bash";
|
|
9
|
+
const SSH_OPTIONS = "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no";
|
|
10
|
+
/** Execute command using Bun's native shell. */
|
|
11
|
+
const exec_cmd = async (cmd, error_msg, success_msg, log_extra) => {
|
|
12
|
+
try {
|
|
13
|
+
const result = await $ `${{ raw: cmd }}`.quiet();
|
|
14
|
+
const stdout = result.text();
|
|
15
|
+
if (is_log_debug())
|
|
16
|
+
log_debug(LOG_BASH, `${success_msg}, stdout:${stdout}`, log_extra);
|
|
17
|
+
return { stdout };
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
const proc = error;
|
|
21
|
+
const stdout = proc.stdout?.toString() ?? '';
|
|
22
|
+
if (is_log_error())
|
|
23
|
+
log_error(LOG_BASH, `${error_msg}, error:${error}`, log_extra);
|
|
24
|
+
return { stdout, err: `${error_msg}, error:${error}` };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/** Run command on local host. */
|
|
28
|
+
export const run_local_cmd = (cmd, log_extra) => {
|
|
29
|
+
return exec_cmd(cmd, `error running on local host cmd:${cmd}`, `executing on local host cmd:${cmd}`, log_extra);
|
|
30
|
+
};
|
|
31
|
+
/** Run simple command locally and get trimmed result. */
|
|
32
|
+
export const run_simple_local_cmd = async (cmd, log_extra) => {
|
|
33
|
+
const { err, stdout } = await run_local_cmd(cmd, log_extra);
|
|
34
|
+
return err ? null : stdout.trim();
|
|
35
|
+
};
|
|
36
|
+
/** Get temporary log file path. */
|
|
37
|
+
const get_log_file = async () => {
|
|
38
|
+
const home = await run_simple_local_cmd("echo ~");
|
|
39
|
+
const log_dir = `${home}/.hola/ssh`;
|
|
40
|
+
await run_local_cmd(`mkdir -p ${log_dir}`);
|
|
41
|
+
return `${log_dir}/l_${random_code()}.log`;
|
|
42
|
+
};
|
|
43
|
+
/** Build SSH command prefix. */
|
|
44
|
+
const build_ssh_prefix = (host) => `ssh ${host.auth} ${SSH_OPTIONS} -p ${host.port} ${host.user}@${host.ip}`;
|
|
45
|
+
/** Build SCP command. */
|
|
46
|
+
const build_scp_cmd = (host, src, dest, to_remote) => {
|
|
47
|
+
const remote_path = `${host.user}@${host.ip}:${to_remote ? dest : src}`;
|
|
48
|
+
const local_path = to_remote ? src : dest;
|
|
49
|
+
const [first, second] = to_remote ? [local_path, remote_path] : [remote_path, local_path];
|
|
50
|
+
return `scp ${host.auth} ${SSH_OPTIONS} -P ${host.port} -q ${first} ${second}`;
|
|
51
|
+
};
|
|
52
|
+
/** Run script on remote host via SSH. */
|
|
53
|
+
export const run_script = (host, script, log_extra) => {
|
|
54
|
+
const cmd = `${build_ssh_prefix(host)} /bin/bash <<'EOT'\n ${script} \nEOT\n`;
|
|
55
|
+
return exec_cmd(cmd, `error running on host:${host.name} script:${script}`, `executing on host:${host.name}, script:${script}`, log_extra);
|
|
56
|
+
};
|
|
57
|
+
/** Run script on remote host with file redirect to avoid progress bar issues. */
|
|
58
|
+
export const run_script_extra = async (host, script, log_extra) => {
|
|
59
|
+
const log_file = await get_log_file();
|
|
60
|
+
const cmd = `${build_ssh_prefix(host)} /bin/bash <<'EOT' > ${log_file} \n ${script} \nEOT\n`;
|
|
61
|
+
try {
|
|
62
|
+
await $ `${{ raw: cmd }}`.quiet();
|
|
63
|
+
const output = await Bun.file(log_file).text();
|
|
64
|
+
if (is_log_debug())
|
|
65
|
+
log_debug(LOG_BASH, `executing on host:${host.name}, script:${script}, stdout:${output}`, log_extra);
|
|
66
|
+
await Bun.file(log_file).unlink?.() ?? $ `rm ${log_file}`.quiet();
|
|
67
|
+
return { stdout: output };
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const proc = error;
|
|
71
|
+
const stdout = proc.stdout?.toString() ?? '';
|
|
72
|
+
if (is_log_error())
|
|
73
|
+
log_error(LOG_BASH, `error running on host:${host.name} script:${script}, error:${error}`, log_extra);
|
|
74
|
+
return { stdout, err: `error running script:${script}, error:${error}` };
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/** Run script file on remote host. */
|
|
78
|
+
export const run_script_file = (host, script_file, log_extra) => {
|
|
79
|
+
const cmd = `${build_ssh_prefix(host)} /bin/bash < ${script_file}`;
|
|
80
|
+
return exec_cmd(cmd, `error running on host:${host.name} script_file:${script_file}`, `executing on host:${host.name}, script_file:${script_file}`, log_extra);
|
|
81
|
+
};
|
|
82
|
+
/** SCP remote file to local. */
|
|
83
|
+
export const scp = (host, remote_file, local_file, log_extra) => {
|
|
84
|
+
const cmd = build_scp_cmd(host, remote_file, local_file, false);
|
|
85
|
+
return exec_cmd(cmd, `error scp on host:${host.name} remote:${remote_file}, local:${local_file}`, `executing scp on host:${host.name}, remote:${remote_file}, local:${local_file}`, log_extra);
|
|
86
|
+
};
|
|
87
|
+
/** SCP local file to remote. */
|
|
88
|
+
export const scpr = (host, local_file, remote_file, log_extra) => {
|
|
89
|
+
const cmd = build_scp_cmd(host, local_file, remote_file, true);
|
|
90
|
+
return exec_cmd(cmd, `error scpr on host:${host.name} remote:${remote_file}, local:${local_file}`, `executing scpr on host:${host.name}, remote:${remote_file}, local:${local_file}`, log_extra);
|
|
91
|
+
};
|
|
92
|
+
/** Run simple command on remote host and get trimmed result. */
|
|
93
|
+
export const run_simple_cmd = async (host, cmd, log_extra) => {
|
|
94
|
+
const { err, stdout } = await run_script(host, cmd, log_extra);
|
|
95
|
+
return err ? null : stdout.trim();
|
|
96
|
+
};
|
|
97
|
+
/** Extract info from stdout using regex pattern matching. */
|
|
98
|
+
export const get_info = (stdout, key, log_extra) => {
|
|
99
|
+
const word_key = key.split(" ").join("\\s+");
|
|
100
|
+
const regex = new RegExp(`\n\\s?${word_key}\\s?:(.*)\\s`, 'g');
|
|
101
|
+
if (is_log_debug())
|
|
102
|
+
log_debug(LOG_BASH, `get_info regex:${JSON.stringify(regex)}`, log_extra);
|
|
103
|
+
const matched = [...stdout.matchAll(regex)].map(result => result[1].trim());
|
|
104
|
+
if (is_log_debug())
|
|
105
|
+
log_debug(LOG_BASH, `get_info matched:${JSON.stringify(matched)}`, log_extra);
|
|
106
|
+
return matched;
|
|
107
|
+
};
|
|
108
|
+
/** Read key-value pairs from stdout. */
|
|
109
|
+
export const read_key_value_line = (stdout, delimiter = ":", lines, config, exclude_mode) => {
|
|
110
|
+
if (!stdout)
|
|
111
|
+
return {};
|
|
112
|
+
const contents = stdout.toString().split(/(?:\r\n|\r|\n)/g);
|
|
113
|
+
const line_texts = lines ? lines.map(i => contents[i]) : contents;
|
|
114
|
+
return line_texts.reduce((obj, content) => {
|
|
115
|
+
const key_value = content.split(delimiter);
|
|
116
|
+
if (key_value.length !== 2)
|
|
117
|
+
return obj;
|
|
118
|
+
const key = key_value[0].trim();
|
|
119
|
+
const should_include = !config ||
|
|
120
|
+
(exclude_mode !== true && config[key]) ||
|
|
121
|
+
(exclude_mode === true && !config[`!${key}`]);
|
|
122
|
+
if (key && should_include)
|
|
123
|
+
obj[key] = key_value[1].trim();
|
|
124
|
+
return obj;
|
|
125
|
+
}, {});
|
|
126
|
+
};
|
|
127
|
+
/** Read structured lines into array of objects. */
|
|
128
|
+
export const read_obj_line = (stdout, keys, ignore = 1, delimiter = " ") => {
|
|
129
|
+
if (!stdout)
|
|
130
|
+
return [];
|
|
131
|
+
return stdout.toString().split(/(?:\r\n|\r|\n)/g)
|
|
132
|
+
.slice(ignore)
|
|
133
|
+
.filter(content => content.trim().length > 0)
|
|
134
|
+
.map(content => {
|
|
135
|
+
const attrs = content.split(delimiter).filter(f => f.trim().length > 0);
|
|
136
|
+
return keys.reduce((obj, key, i) => {
|
|
137
|
+
if (attrs[i])
|
|
138
|
+
obj[key] = attrs[i].trim();
|
|
139
|
+
return obj;
|
|
140
|
+
}, {});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
/** Get multiple system attributes from remote host. */
|
|
144
|
+
export const get_system_attributes = async (host, attrs, log_extra) => {
|
|
145
|
+
const results = await Promise.all(attrs.map(attr => run_simple_cmd(host, attr.cmd, log_extra)));
|
|
146
|
+
return attrs.reduce((obj, attr, i) => {
|
|
147
|
+
if (results[i])
|
|
148
|
+
obj[attr.name] = results[i];
|
|
149
|
+
return obj;
|
|
150
|
+
}, {});
|
|
151
|
+
};
|
|
152
|
+
/** Stop process on remote host if running. */
|
|
153
|
+
export const stop_process = async (host, process_name, stop_cmd, using_full, log_extra) => {
|
|
154
|
+
const grep_cmd = using_full ? `pgrep -f "${process_name}" | wc -l` : `pgrep ${process_name} | wc -l`;
|
|
155
|
+
const { stdout } = await run_script(host, grep_cmd, log_extra);
|
|
156
|
+
const has_process = stdout && parseInt(stdout) > 0 ? true : false;
|
|
157
|
+
if (has_process)
|
|
158
|
+
await run_script(host, stop_cmd, log_extra);
|
|
159
|
+
return has_process;
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=bash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../src/core/bash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM/E,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,MAAM,WAAW,GAAG,6DAA6D,CAAC;AAoBlF,gDAAgD;AAChD,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAW,EAAE,SAAiB,EAAE,WAAmB,EAAE,SAAoB,EAA0B,EAAE;IACzH,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAA,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC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CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,IAAU,EAAE,YAAoB,EAAE,QAAgB,EAAE,UAAoB,EAAE,SAAoB,EAAoB,EAAE;IACnJ,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,aAAa,YAAY,WAAW,CAAC,CAAC,CAAC,SAAS,YAAY,UAAU,CAAC;IACrG,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC/D,MAAM,WAAW,GAAG,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,IAAI,WAAW;QAAE,MAAM,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC7D,OAAO,WAAW,CAAC;AACvB,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart data processing utility functions.
|
|
3
|
+
* @module core/chart
|
|
4
|
+
*/
|
|
5
|
+
type ChartData = string[][];
|
|
6
|
+
/** Set chart header prefix for all columns except the first. */
|
|
7
|
+
export declare const set_chart_header: (arr: ChartData, prefix: string) => void;
|
|
8
|
+
/** Merge two chart data arrays by combining columns. */
|
|
9
|
+
export declare const merge_chart_data: (arr1: ChartData, arr2: ChartData) => void;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.d.ts","sourceRoot":"","sources":["../../src/core/chart.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,KAAK,SAAS,GAAG,MAAM,EAAE,EAAE,CAAC;AAE5B,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,GAAI,KAAK,SAAS,EAAE,QAAQ,MAAM,KAAG,IAOjE,CAAC;AAEF,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,GAAI,MAAM,SAAS,EAAE,MAAM,SAAS,KAAG,IAiBnE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart data processing utility functions.
|
|
3
|
+
* @module core/chart
|
|
4
|
+
*/
|
|
5
|
+
import { has_value } from './validate.js';
|
|
6
|
+
/** Set chart header prefix for all columns except the first. */
|
|
7
|
+
export const set_chart_header = (arr, prefix) => {
|
|
8
|
+
if (!arr || arr.length < 1)
|
|
9
|
+
return;
|
|
10
|
+
const headers = arr[0];
|
|
11
|
+
if (!headers || headers.length < 1)
|
|
12
|
+
return;
|
|
13
|
+
for (let i = 1; i < headers.length; i++) {
|
|
14
|
+
headers[i] = `${prefix}${headers[i]}`;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/** Merge two chart data arrays by combining columns. */
|
|
18
|
+
export const merge_chart_data = (arr1, arr2) => {
|
|
19
|
+
if (!arr1 || arr1.length < 2 || !arr2 || arr2.length < 2)
|
|
20
|
+
return;
|
|
21
|
+
const max = Math.max(arr1.length, arr2.length);
|
|
22
|
+
const arr1_cols = arr1[0].length;
|
|
23
|
+
const arr2_cols = arr2[0].length;
|
|
24
|
+
for (let i = 0; i < max; i++) {
|
|
25
|
+
if (!has_value(arr1[i])) {
|
|
26
|
+
arr1[i] = [...new Array(arr1_cols)].map(() => "");
|
|
27
|
+
arr1[i][0] = arr2[i][0];
|
|
28
|
+
}
|
|
29
|
+
if (!has_value(arr2[i])) {
|
|
30
|
+
arr2[i] = [...new Array(arr2_cols)].map(() => "");
|
|
31
|
+
}
|
|
32
|
+
arr1[i] = [...arr1[i], ...arr2[i].splice(1)];
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.js","sourceRoot":"","sources":["../../src/core/chart.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,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S,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YAClD,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date formatting and parsing utility functions.
|
|
3
|
+
* @module core/date
|
|
4
|
+
*/
|
|
5
|
+
export declare const format_time: (date: Date | string | number) => string;
|
|
6
|
+
export declare const simple_date: (date: Date | string | number) => string;
|
|
7
|
+
export declare const format_date: (date: Date | string | number) => string;
|
|
8
|
+
export declare const format_date_time: (date: Date | string | number) => string;
|
|
9
|
+
/** Parse yyyymmdd formatted string to Date object. */
|
|
10
|
+
export declare const parse_date: (date: string) => Date;
|
|
11
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/core/date.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,KAAG,MAAmC,CAAC;AAC/F,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,KAAG,MAAmC,CAAC;AAC/F,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,KAAG,MAAsC,CAAC;AAClG,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,KAAG,MAA+C,CAAC;AAEhH,sDAAsD;AACtD,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,IAMzC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date formatting and parsing utility functions.
|
|
3
|
+
* @module core/date
|
|
4
|
+
*/
|
|
5
|
+
import dateformat from 'dateformat';
|
|
6
|
+
export const format_time = (date) => dateformat(date, "HH:MM");
|
|
7
|
+
export const simple_date = (date) => dateformat(date, "mm/dd");
|
|
8
|
+
export const format_date = (date) => dateformat(date, "yyyymmdd");
|
|
9
|
+
export const format_date_time = (date) => dateformat(date, "yyyymmdd HH:MM:ss");
|
|
10
|
+
/** Parse yyyymmdd formatted string to Date object. */
|
|
11
|
+
export const parse_date = (date) => {
|
|
12
|
+
const [year, month, day] = [date.slice(0, 4), date.slice(4, 6), date.slice(6, 8)].map(Number);
|
|
13
|
+
const date_obj = new Date();
|
|
14
|
+
date_obj.setFullYear(year, month - 1, day);
|
|
15
|
+
date_obj.setHours(0, 0, 0, 0);
|
|
16
|
+
return date_obj;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/core/date.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAA4B,EAAU,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAA4B,EAAU,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAA4B,EAAU,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAClG,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAA4B,EAAU,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;AAEhH,sDAAsD;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAQ,EAAE;IAC7C,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9F,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9B,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption and hashing utility functions.
|
|
3
|
+
* @module core/encrypt
|
|
4
|
+
*/
|
|
5
|
+
/** Generate MD5 hash of content using Bun's native CryptoHasher. */
|
|
6
|
+
export declare const md5: (content: string) => string;
|
|
7
|
+
/** Encrypt password using MD5 with salt. (One-way hashing for passwords) */
|
|
8
|
+
export declare const encrypt_pwd: (password: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Encrypt a secret using AES-256-CBC (reversible encryption).
|
|
11
|
+
* Use this for API tokens, secrets that need to be retrieved later.
|
|
12
|
+
*/
|
|
13
|
+
export declare const encrypt_secret: (plaintext: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Decrypt a secret encrypted with encrypt_secret.
|
|
16
|
+
*/
|
|
17
|
+
export declare const decrypt_secret: (encrypted: string) => string;
|
|
18
|
+
//# sourceMappingURL=encrypt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../src/core/encrypt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,oEAAoE;AACpE,eAAO,MAAM,GAAG,GAAI,SAAS,MAAM,KAAG,MAIrC,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,WAAW,GAAI,UAAU,MAAM,KAAG,MAG9C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,MAWlD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,MAUlD,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption and hashing utility functions.
|
|
3
|
+
* @module core/encrypt
|
|
4
|
+
*/
|
|
5
|
+
import { get_settings } from '../setting.js';
|
|
6
|
+
import crypto from 'crypto';
|
|
7
|
+
/** Generate MD5 hash of content using Bun's native CryptoHasher. */
|
|
8
|
+
export const md5 = (content) => {
|
|
9
|
+
const hasher = new Bun.CryptoHasher('md5');
|
|
10
|
+
hasher.update(content);
|
|
11
|
+
return hasher.digest('hex');
|
|
12
|
+
};
|
|
13
|
+
/** Encrypt password using MD5 with salt. (One-way hashing for passwords) */
|
|
14
|
+
export const encrypt_pwd = (password) => {
|
|
15
|
+
const crypto_key = get_settings().encrypt.key;
|
|
16
|
+
return md5(`BGT*&+${password}&76w${crypto_key}`);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Encrypt a secret using AES-256-CBC (reversible encryption).
|
|
20
|
+
* Use this for API tokens, secrets that need to be retrieved later.
|
|
21
|
+
*/
|
|
22
|
+
export const encrypt_secret = (plaintext) => {
|
|
23
|
+
if (!plaintext)
|
|
24
|
+
return '';
|
|
25
|
+
const key = get_settings().encrypt.key;
|
|
26
|
+
// Derive a 32-byte key from the settings key
|
|
27
|
+
const keyBuffer = crypto.createHash('sha256').update(key).digest();
|
|
28
|
+
const iv = crypto.randomBytes(16);
|
|
29
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', keyBuffer, iv);
|
|
30
|
+
let encrypted = cipher.update(plaintext, 'utf8', 'hex');
|
|
31
|
+
encrypted += cipher.final('hex');
|
|
32
|
+
// Prepend IV to the encrypted text for decryption
|
|
33
|
+
return iv.toString('hex') + ':' + encrypted;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Decrypt a secret encrypted with encrypt_secret.
|
|
37
|
+
*/
|
|
38
|
+
export const decrypt_secret = (encrypted) => {
|
|
39
|
+
if (!encrypted || !encrypted.includes(':'))
|
|
40
|
+
return '';
|
|
41
|
+
const key = get_settings().encrypt.key;
|
|
42
|
+
const keyBuffer = crypto.createHash('sha256').update(key).digest();
|
|
43
|
+
const [ivHex, encryptedText] = encrypted.split(':');
|
|
44
|
+
const iv = Buffer.from(ivHex, 'hex');
|
|
45
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', keyBuffer, iv);
|
|
46
|
+
let decrypted = decipher.update(encryptedText, 'hex', 'utf8');
|
|
47
|
+
decrypted += decipher.final('utf8');
|
|
48
|
+
return decrypted;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=encrypt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../../src/core/encrypt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B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C;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAiB,EAAU,EAAE;IACxD,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IACtD,MAAM,GAAG,GAAG,YAAY,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;IACnE,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpD,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IACvE,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9D,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File system utility functions.
|
|
3
|
+
* @module core/file
|
|
4
|
+
*/
|
|
5
|
+
interface ZipEntry {
|
|
6
|
+
path: string;
|
|
7
|
+
buffer(): Promise<Buffer>;
|
|
8
|
+
}
|
|
9
|
+
/** Get file extension from filename. */
|
|
10
|
+
export declare const file_extension: (file_name: string) => string;
|
|
11
|
+
/** Get file name without extension. */
|
|
12
|
+
export declare const file_prefix: (file_name: string) => string;
|
|
13
|
+
/** Read files from zip archive with filter. */
|
|
14
|
+
export declare const read_from_zip: (path: string, predicate: (file: ZipEntry) => boolean) => Promise<ZipEntry[]>;
|
|
15
|
+
export declare const read_from_zip_by_extension: (path: string, extension: string) => Promise<ZipEntry[]>;
|
|
16
|
+
export declare const read_from_zip_by_prefix: (path: string, prefix: string) => Promise<ZipEntry[]>;
|
|
17
|
+
/** Check if file exists at path using Bun's native file API. */
|
|
18
|
+
export declare const is_file_exist: (path: string) => Promise<boolean>;
|
|
19
|
+
/** Get file size in bytes using Bun's native file API. */
|
|
20
|
+
export declare const get_file_size: (path: string) => number;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/core/file.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,UAAU,QAAQ;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED,wCAAwC;AACxC,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,MAA2D,CAAC;AAE/G,uCAAuC;AACvC,eAAO,MAAM,WAAW,GAAI,WAAW,MAAM,KAAG,MAAkD,CAAC;AAEnG,+CAA+C;AAC/C,eAAO,MAAM,aAAa,GAAU,MAAM,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,KAAG,OAAO,CAAC,QAAQ,EAAE,CAG5G,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAI,MAAM,MAAM,EAAE,WAAW,MAAM,wBAAyE,CAAC;AACpJ,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,wBAAmE,CAAC;AAExI,gEAAgE;AAChE,eAAO,MAAM,aAAa,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,OAAO,CAAkC,CAAC;AAErG,0DAA0D;AAC1D,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAA6B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File system utility functions.
|
|
3
|
+
* @module core/file
|
|
4
|
+
*/
|
|
5
|
+
import unzipper from 'unzipper';
|
|
6
|
+
/** Get file extension from filename. */
|
|
7
|
+
export const file_extension = (file_name) => file_name ? file_name.split('.').pop() ?? "" : "";
|
|
8
|
+
/** Get file name without extension. */
|
|
9
|
+
export const file_prefix = (file_name) => file_name ? file_name.split('.')[0] : "";
|
|
10
|
+
/** Read files from zip archive with filter. */
|
|
11
|
+
export const read_from_zip = async (path, predicate) => {
|
|
12
|
+
const directory = await unzipper.Open.file(path);
|
|
13
|
+
return directory.files.filter(predicate);
|
|
14
|
+
};
|
|
15
|
+
export const read_from_zip_by_extension = (path, extension) => read_from_zip(path, file => file_extension(file.path) === extension);
|
|
16
|
+
export const read_from_zip_by_prefix = (path, prefix) => read_from_zip(path, file => file_prefix(file.path) === prefix);
|
|
17
|
+
/** Check if file exists at path using Bun's native file API. */
|
|
18
|
+
export const is_file_exist = async (path) => await Bun.file(path).exists();
|
|
19
|
+
/** Get file size in bytes using Bun's native file API. */
|
|
20
|
+
export const get_file_size = (path) => Bun.file(path).size;
|
|
21
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/core/file.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAQ,MAAM,UAAU,CAAC;AAOhC,wCAAwC;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAiB,EAAU,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAE/G,uCAAuC;AACvC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAU,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAEnG,+CAA+C;AAC/C,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,IAAY,EAAE,SAAsC,EAAuB,EAAE;IAC7G,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,IAAY,EAAE,SAAiB,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC;AACpJ,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,CAAC;AAExI,gEAAgE;AAChE,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,IAAY,EAAoB,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;AAErG,0DAA0D;AAC1D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template execution utilities using Node.js VM.
|
|
3
|
+
* @module core/lhs
|
|
4
|
+
*/
|
|
5
|
+
/** Context value types for VM execution. */
|
|
6
|
+
export type ContextValue = string | number | boolean | null | undefined | ((...args: any[]) => any) | ContextValue[] | {
|
|
7
|
+
[key: string]: ContextValue;
|
|
8
|
+
};
|
|
9
|
+
/** Get default context with number utilities. */
|
|
10
|
+
export declare const get_context: () => Record<string, ContextValue>;
|
|
11
|
+
/** Run code in VM context. */
|
|
12
|
+
export declare const run_in_context: (code: string, ctx: Record<string, ContextValue>) => Record<string, ContextValue>;
|
|
13
|
+
/** Verify template string is valid JavaScript. Returns error message if invalid, null if valid. */
|
|
14
|
+
export declare const verify_template: (template: string, knob: Record<string, ContextValue>) => string | null;
|
|
15
|
+
/** Execute template string and return result. */
|
|
16
|
+
export declare const execute_template: (template: string, knob: Record<string, ContextValue>) => string;
|
|
17
|
+
//# sourceMappingURL=lhs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lhs.d.ts","sourceRoot":"","sources":["../../src/core/lhs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,4CAA4C;AAE5C,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,GAAG,YAAY,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,CAAC;AAEvJ,iDAAiD;AACjD,eAAO,MAAM,WAAW,QAAO,MAAM,CAAC,MAAM,EAAE,YAAY,CAA8B,CAAC;AAEzF,8BAA8B;AAC9B,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAI3G,CAAC;AAEF,mGAAmG;AACnG,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,KAAG,MAAM,GAAG,IAO/F,CAAC;AAEF,iDAAiD;AACjD,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,KAAG,MAGvF,CAAC"}
|
package/dist/core/lhs.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template execution utilities using Node.js VM.
|
|
3
|
+
* @module core/lhs
|
|
4
|
+
*/
|
|
5
|
+
import vm from 'node:vm';
|
|
6
|
+
import { range, scale, space } from './number.js';
|
|
7
|
+
/** Get default context with number utilities. */
|
|
8
|
+
export const get_context = () => ({ range, scale, space });
|
|
9
|
+
/** Run code in VM context. */
|
|
10
|
+
export const run_in_context = (code, ctx) => {
|
|
11
|
+
vm.createContext(ctx);
|
|
12
|
+
vm.runInContext(code, ctx);
|
|
13
|
+
return ctx;
|
|
14
|
+
};
|
|
15
|
+
/** Verify template string is valid JavaScript. Returns error message if invalid, null if valid. */
|
|
16
|
+
export const verify_template = (template, knob) => {
|
|
17
|
+
try {
|
|
18
|
+
run_in_context("__output__=`" + template + "`;", knob);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
return err.message;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/** Execute template string and return result. */
|
|
26
|
+
export const execute_template = (template, knob) => {
|
|
27
|
+
const ctx = run_in_context("__output__=`" + template + "`;", knob);
|
|
28
|
+
return ctx["__output__"];
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=lhs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lhs.js","sourceRoot":"","sources":["../../src/core/lhs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAMlD,iDAAiD;AACjD,MAAM,CAAC,MAAM,WAAW,GAAG,GAAiC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAEzF,8BAA8B;AAC9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