hola-server 1.0.10 → 2.0.1
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 +196 -1
- package/core/array.js +79 -142
- package/core/bash.js +208 -259
- package/core/chart.js +26 -16
- package/core/cron.js +14 -3
- package/core/date.js +15 -44
- package/core/encrypt.js +19 -9
- package/core/file.js +42 -29
- package/core/lhs.js +32 -6
- package/core/meta.js +213 -289
- package/core/msg.js +20 -7
- package/core/number.js +105 -103
- package/core/obj.js +15 -12
- package/core/random.js +9 -6
- package/core/role.js +69 -77
- package/core/thread.js +12 -2
- package/core/type.js +300 -261
- package/core/url.js +20 -12
- package/core/validate.js +29 -26
- package/db/db.js +297 -227
- package/db/entity.js +631 -963
- package/db/gridfs.js +120 -166
- package/design/add_default_field_attr.md +56 -0
- package/http/context.js +22 -8
- package/http/cors.js +25 -8
- package/http/error.js +27 -9
- package/http/express.js +70 -41
- package/http/params.js +70 -42
- package/http/router.js +51 -40
- package/http/session.js +59 -36
- package/index.js +85 -9
- package/package.json +2 -2
- package/router/clone.js +28 -36
- package/router/create.js +21 -26
- package/router/delete.js +24 -28
- package/router/read.js +137 -123
- package/router/update.js +38 -56
- package/setting.js +22 -6
- package/skills/array.md +155 -0
- package/skills/bash.md +91 -0
- package/skills/chart.md +54 -0
- package/skills/code.md +422 -0
- package/skills/context.md +177 -0
- package/skills/date.md +58 -0
- package/skills/express.md +255 -0
- package/skills/file.md +60 -0
- package/skills/lhs.md +54 -0
- package/skills/meta.md +1023 -0
- package/skills/msg.md +30 -0
- package/skills/number.md +88 -0
- package/skills/obj.md +36 -0
- package/skills/params.md +206 -0
- package/skills/random.md +22 -0
- package/skills/role.md +59 -0
- package/skills/session.md +281 -0
- package/skills/storage.md +743 -0
- package/skills/thread.md +22 -0
- package/skills/type.md +547 -0
- package/skills/url.md +34 -0
- package/skills/validate.md +48 -0
- package/test/cleanup/close-db.js +5 -0
- package/test/core/array.js +226 -0
- package/test/core/chart.js +51 -0
- package/test/core/file.js +59 -0
- package/test/core/lhs.js +44 -0
- package/test/core/number.js +167 -12
- package/test/core/obj.js +47 -0
- package/test/core/random.js +24 -0
- package/test/core/thread.js +20 -0
- package/test/core/type.js +216 -0
- package/test/core/validate.js +67 -0
- package/test/db/db-ops.js +99 -0
- package/test/db/pipe_test.txt +0 -0
- package/test/db/test_case_design.md +528 -0
- package/test/db/test_db_class.js +613 -0
- package/test/db/test_entity_class.js +414 -0
- package/test/db/test_gridfs_class.js +234 -0
- package/test/entity/create.js +1 -1
- package/test/entity/delete-mixed.js +156 -0
- package/test/entity/ref-filter.js +63 -0
- package/tool/gen_i18n.js +55 -21
- package/test/crud/router.js +0 -99
- package/test/router/user.js +0 -17
package/core/date.js
CHANGED
|
@@ -1,55 +1,26 @@
|
|
|
1
|
-
const date_format = require("dateformat");
|
|
2
|
-
// import date_format from "dateformat";
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
* @returns
|
|
2
|
+
* @fileoverview Date formatting and parsing utility functions.
|
|
3
|
+
* @module core/date
|
|
8
4
|
*/
|
|
9
|
-
const format_time = (date) => {
|
|
10
|
-
return date_format(date, "HH:MM");
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Format date object using mm/dd
|
|
15
|
-
* @param {date object to be formatted} date
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
const simple_date = (date) => {
|
|
19
|
-
return date_format(date, "mm/dd");
|
|
20
|
-
};
|
|
21
5
|
|
|
22
|
-
|
|
23
|
-
* Format date obj using yyyymmdd
|
|
24
|
-
* @param {date object to be formatted} date
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
const format_date = (date) => {
|
|
28
|
-
return date_format(date, "yyyymmdd");
|
|
29
|
-
};
|
|
6
|
+
const date_format = require("dateformat");
|
|
30
7
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*/
|
|
36
|
-
const format_date_time = (date) => {
|
|
37
|
-
return date_format(date, "yyyymmdd HH:MM:ss");
|
|
38
|
-
};
|
|
8
|
+
const format_time = (date) => date_format(date, "HH:MM");
|
|
9
|
+
const simple_date = (date) => date_format(date, "mm/dd");
|
|
10
|
+
const format_date = (date) => date_format(date, "yyyymmdd");
|
|
11
|
+
const format_date_time = (date) => date_format(date, "yyyymmdd HH:MM:ss");
|
|
39
12
|
|
|
40
13
|
/**
|
|
41
|
-
* Parse
|
|
42
|
-
* @param {date
|
|
43
|
-
* @returns
|
|
14
|
+
* Parse yyyymmdd formatted string to Date object.
|
|
15
|
+
* @param {string} date - Date string in yyyymmdd format.
|
|
16
|
+
* @returns {Date} Parsed Date object with time set to 00:00:00.
|
|
44
17
|
*/
|
|
45
18
|
const parse_date = (date) => {
|
|
46
|
-
const year =
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
dateObj.setHours(0, 0, 0, 0);
|
|
52
|
-
return dateObj;
|
|
19
|
+
const [year, month, day] = [date.slice(0, 4), date.slice(4, 6), date.slice(6, 8)].map(Number);
|
|
20
|
+
const date_obj = new Date();
|
|
21
|
+
date_obj.setFullYear(year, month - 1, day);
|
|
22
|
+
date_obj.setHours(0, 0, 0, 0);
|
|
23
|
+
return date_obj;
|
|
53
24
|
};
|
|
54
25
|
|
|
55
26
|
module.exports = { simple_date, format_date, format_time, format_date_time, parse_date };
|
package/core/encrypt.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Encryption and hashing utility functions.
|
|
3
|
+
* @module core/encrypt
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
const crypto = require('crypto');
|
|
2
7
|
const { get_settings } = require('../setting');
|
|
3
8
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
9
|
+
/**
|
|
10
|
+
* Generate MD5 hash of content.
|
|
11
|
+
* @param {string} content - Content to hash.
|
|
12
|
+
* @returns {string} MD5 hash in hex format.
|
|
13
|
+
*/
|
|
14
|
+
const md5 = (content) => crypto.createHash('md5').update(content).digest('hex');
|
|
8
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Encrypt password using MD5 with salt.
|
|
18
|
+
* @param {string} password - Plain text password.
|
|
19
|
+
* @returns {string} Encrypted password hash.
|
|
20
|
+
*/
|
|
9
21
|
const encrypt_pwd = (password) => {
|
|
10
22
|
const crypto_key = get_settings().encrypt.key;
|
|
23
|
+
return md5(`BGT*&+${password}&76w${crypto_key}`);
|
|
24
|
+
};
|
|
11
25
|
|
|
12
|
-
|
|
13
|
-
return md5(str);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = { encrypt_pwd };
|
|
26
|
+
module.exports = { md5, encrypt_pwd };
|
package/core/file.js
CHANGED
|
@@ -1,38 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview File system utility functions.
|
|
3
|
+
* @module core/file
|
|
4
|
+
*/
|
|
3
5
|
|
|
6
|
+
const fs = require('fs');
|
|
4
7
|
const unzipper = require('unzipper');
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Get file extension from filename.
|
|
11
|
+
* @param {string} file_name - Name of the file.
|
|
12
|
+
* @returns {string} File extension without dot.
|
|
13
|
+
*/
|
|
14
|
+
const file_extension = (file_name) => file_name ? file_name.split('.').pop() : "";
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* Get file name without extension.
|
|
18
|
+
* @param {string} file_name - Name of the file.
|
|
19
|
+
* @returns {string} File name prefix.
|
|
20
|
+
*/
|
|
21
|
+
const file_prefix = (file_name) => file_name ? file_name.split('.')[0] : "";
|
|
13
22
|
|
|
14
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Read files from zip archive with filter.
|
|
25
|
+
* @param {string} path - Path to zip file.
|
|
26
|
+
* @param {Function} predicate - Filter function for files.
|
|
27
|
+
* @returns {Promise<Object[]>} Array of matching file entries.
|
|
28
|
+
*/
|
|
29
|
+
const read_from_zip = async (path, predicate) => {
|
|
15
30
|
const directory = await unzipper.Open.file(path);
|
|
16
|
-
return directory.files.filter(
|
|
17
|
-
}
|
|
31
|
+
return directory.files.filter(predicate);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const read_from_zip_by_extension = (path, extension) => read_from_zip(path, file => file_extension(file.path) === extension);
|
|
35
|
+
const read_from_zip_by_prefix = (path, prefix) => read_from_zip(path, file => file_prefix(file.path) === prefix);
|
|
18
36
|
|
|
19
37
|
/**
|
|
20
|
-
* Check
|
|
21
|
-
* @param {
|
|
22
|
-
* @returns
|
|
38
|
+
* Check if file exists at path.
|
|
39
|
+
* @param {string} path - File path to check.
|
|
40
|
+
* @returns {boolean} True if file exists, false otherwise.
|
|
23
41
|
*/
|
|
24
|
-
const is_file_exist = (path) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const stats = await fs_promises.stat(path);
|
|
35
|
-
return stats.size;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = { file_extension, file_prefix, read_from_zip_by_extension, read_from_zip_by_prefix, is_file_exist, get_file_size }
|
|
42
|
+
const is_file_exist = (path) => fs.existsSync(path);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get file size in bytes.
|
|
46
|
+
* @param {string} path - File path.
|
|
47
|
+
* @returns {Promise<number>} File size in bytes.
|
|
48
|
+
*/
|
|
49
|
+
const get_file_size = async (path) => (await fs.promises.stat(path)).size;
|
|
50
|
+
|
|
51
|
+
module.exports = { file_extension, file_prefix, read_from_zip_by_extension, read_from_zip_by_prefix, is_file_exist, get_file_size };
|
package/core/lhs.js
CHANGED
|
@@ -1,27 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Template execution utilities using Node.js VM.
|
|
3
|
+
* @module core/lhs
|
|
4
|
+
*/
|
|
1
5
|
|
|
2
6
|
const vm = require('node:vm');
|
|
3
7
|
const { range, scale, space } = require("./number");
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Get default context with number utilities.
|
|
11
|
+
* @returns {Object} Context object with range, scale, and space functions.
|
|
12
|
+
*/
|
|
13
|
+
const get_context = () => ({ range, scale, space });
|
|
6
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Run code in VM context.
|
|
17
|
+
* @param {string} code - JavaScript code to execute.
|
|
18
|
+
* @param {Object} ctx - Context object for VM.
|
|
19
|
+
* @returns {Object} Context object after execution.
|
|
20
|
+
*/
|
|
7
21
|
const run_in_context = (code, ctx) => {
|
|
8
22
|
vm.createContext(ctx);
|
|
9
23
|
vm.runInContext(code, ctx);
|
|
10
24
|
return ctx;
|
|
11
|
-
}
|
|
25
|
+
};
|
|
12
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Verify template string is valid JavaScript.
|
|
29
|
+
* @param {string} template - Template string to verify.
|
|
30
|
+
* @param {Object} knob - Variable bindings for template.
|
|
31
|
+
* @returns {string|null} Error message if invalid, null if valid.
|
|
32
|
+
*/
|
|
13
33
|
const verify_template = (template, knob) => {
|
|
14
34
|
try {
|
|
15
35
|
run_in_context("__output__=`" + template + "`;", knob);
|
|
36
|
+
return null;
|
|
16
37
|
} catch (err) {
|
|
17
38
|
return err.message;
|
|
18
39
|
}
|
|
19
|
-
|
|
20
|
-
}
|
|
40
|
+
};
|
|
21
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Execute template string and return result.
|
|
44
|
+
* @param {string} template - Template string to execute.
|
|
45
|
+
* @param {Object} knob - Variable bindings for template.
|
|
46
|
+
* @returns {string} Executed template output.
|
|
47
|
+
*/
|
|
22
48
|
const execute_template = (template, knob) => {
|
|
23
49
|
const ctx = run_in_context("__output__=`" + template + "`;", knob);
|
|
24
50
|
return ctx["__output__"];
|
|
25
|
-
}
|
|
51
|
+
};
|
|
26
52
|
|
|
27
|
-
module.exports = { get_context, run_in_context, verify_template, execute_template }
|
|
53
|
+
module.exports = { get_context, run_in_context, verify_template, execute_template };
|