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.
Files changed (83) hide show
  1. package/README.md +196 -1
  2. package/core/array.js +79 -142
  3. package/core/bash.js +208 -259
  4. package/core/chart.js +26 -16
  5. package/core/cron.js +14 -3
  6. package/core/date.js +15 -44
  7. package/core/encrypt.js +19 -9
  8. package/core/file.js +42 -29
  9. package/core/lhs.js +32 -6
  10. package/core/meta.js +213 -289
  11. package/core/msg.js +20 -7
  12. package/core/number.js +105 -103
  13. package/core/obj.js +15 -12
  14. package/core/random.js +9 -6
  15. package/core/role.js +69 -77
  16. package/core/thread.js +12 -2
  17. package/core/type.js +300 -261
  18. package/core/url.js +20 -12
  19. package/core/validate.js +29 -26
  20. package/db/db.js +297 -227
  21. package/db/entity.js +631 -963
  22. package/db/gridfs.js +120 -166
  23. package/design/add_default_field_attr.md +56 -0
  24. package/http/context.js +22 -8
  25. package/http/cors.js +25 -8
  26. package/http/error.js +27 -9
  27. package/http/express.js +70 -41
  28. package/http/params.js +70 -42
  29. package/http/router.js +51 -40
  30. package/http/session.js +59 -36
  31. package/index.js +85 -9
  32. package/package.json +2 -2
  33. package/router/clone.js +28 -36
  34. package/router/create.js +21 -26
  35. package/router/delete.js +24 -28
  36. package/router/read.js +137 -123
  37. package/router/update.js +38 -56
  38. package/setting.js +22 -6
  39. package/skills/array.md +155 -0
  40. package/skills/bash.md +91 -0
  41. package/skills/chart.md +54 -0
  42. package/skills/code.md +422 -0
  43. package/skills/context.md +177 -0
  44. package/skills/date.md +58 -0
  45. package/skills/express.md +255 -0
  46. package/skills/file.md +60 -0
  47. package/skills/lhs.md +54 -0
  48. package/skills/meta.md +1023 -0
  49. package/skills/msg.md +30 -0
  50. package/skills/number.md +88 -0
  51. package/skills/obj.md +36 -0
  52. package/skills/params.md +206 -0
  53. package/skills/random.md +22 -0
  54. package/skills/role.md +59 -0
  55. package/skills/session.md +281 -0
  56. package/skills/storage.md +743 -0
  57. package/skills/thread.md +22 -0
  58. package/skills/type.md +547 -0
  59. package/skills/url.md +34 -0
  60. package/skills/validate.md +48 -0
  61. package/test/cleanup/close-db.js +5 -0
  62. package/test/core/array.js +226 -0
  63. package/test/core/chart.js +51 -0
  64. package/test/core/file.js +59 -0
  65. package/test/core/lhs.js +44 -0
  66. package/test/core/number.js +167 -12
  67. package/test/core/obj.js +47 -0
  68. package/test/core/random.js +24 -0
  69. package/test/core/thread.js +20 -0
  70. package/test/core/type.js +216 -0
  71. package/test/core/validate.js +67 -0
  72. package/test/db/db-ops.js +99 -0
  73. package/test/db/pipe_test.txt +0 -0
  74. package/test/db/test_case_design.md +528 -0
  75. package/test/db/test_db_class.js +613 -0
  76. package/test/db/test_entity_class.js +414 -0
  77. package/test/db/test_gridfs_class.js +234 -0
  78. package/test/entity/create.js +1 -1
  79. package/test/entity/delete-mixed.js +156 -0
  80. package/test/entity/ref-filter.js +63 -0
  81. package/tool/gen_i18n.js +55 -21
  82. package/test/crud/router.js +0 -99
  83. 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
- * Format the date object time part using HH:MM
6
- * @param {date object to be formatted} date
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
- * Format data obj using yyyymmdd hh:mm:ss
33
- * @param {date object to be formatted} date
34
- * @returns
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 the date object using yyyymmdd format
42
- * @param {date str to be parsed} 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 = parseInt(date.substr(0, 4));
47
- const month = parseInt(date.substr(4, 2));
48
- const day = parseInt(date.substr(6, 2));
49
- const dateObj = new Date();
50
- dateObj.setFullYear(year, month - 1, day);
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
- const md5 = (content) => {
5
- const md5 = crypto.createHash('md5');
6
- return md5.update(content).digest('hex');
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
- const str = `BGT*&+${password}&76w${crypto_key}`;
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
- const fs = require('fs');
2
- const fs_promises = require('fs').promises;
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
- const file_extension = file_name => file_name ? file_name.split('.').pop() : "";
7
- const file_prefix = file_name => file_name ? file_name.split('.')[0] : "";
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
- const read_from_zip_by_extension = async (path, extension) => {
10
- const directory = await unzipper.Open.file(path);
11
- return directory.files.filter(file => extension == file_extension(file.path));
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
- const read_from_zip_by_prefix = async (path, prefix) => {
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(file => file_prefix(file.path) == prefix);
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 the file exist or not
21
- * @param {the file path} path
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
- try {
26
- fs.accessSync(path, fs.F_OK);
27
- } catch (e) {
28
- return false;
29
- }
30
- return true;
31
- }
32
-
33
- const get_file_size = async (path) => {
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
- const get_context = () => { return { range: range, scale: scale, space: space } }
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
- return null;
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 };