@domain.js/main 0.1.0 → 0.1.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 (59) hide show
  1. package/.husky/pre-commit +1 -1
  2. package/dist/Errors/index.d.ts +16 -0
  3. package/dist/Errors/index.js +27 -0
  4. package/dist/basic-errors.d.ts +1 -0
  5. package/dist/basic-errors.js +10 -0
  6. package/dist/cfg/index.d.ts +6 -0
  7. package/dist/cfg/index.js +26 -0
  8. package/dist/defaults.d.ts +102 -0
  9. package/dist/defaults.js +36 -0
  10. package/dist/deps/cache/After.d.ts +1 -2
  11. package/dist/deps/cache/Before.js +3 -3
  12. package/dist/deps/cache/Define.d.ts +2 -0
  13. package/dist/deps/cache/index.js +2 -2
  14. package/dist/deps/checker/index.d.ts +4 -0
  15. package/dist/deps/checker/index.js +2 -3
  16. package/dist/deps/cia/index.d.ts +8 -0
  17. package/dist/deps/cia/index.js +3 -6
  18. package/dist/deps/cron/index.d.ts +4 -0
  19. package/dist/deps/cron/index.js +2 -4
  20. package/dist/deps/defines.d.ts +2 -2
  21. package/dist/deps/defines.js +2 -2
  22. package/dist/deps/errors/index.d.ts +1 -0
  23. package/dist/deps/errors/index.js +10 -0
  24. package/dist/deps/logger/index.d.ts +12 -1
  25. package/dist/deps/logger/index.js +6 -6
  26. package/dist/deps/parallel/index.d.ts +22 -4
  27. package/dist/deps/parallel/index.js +20 -11
  28. package/dist/deps/redis/index.d.ts +12 -1
  29. package/dist/deps/redis/index.js +12 -4
  30. package/dist/deps/request/index.d.ts +43 -0
  31. package/dist/deps/request/index.js +67 -0
  32. package/dist/deps/rest/index.d.ts +16 -3
  33. package/dist/deps/rest/index.js +41 -2
  34. package/dist/deps/rest/stats.d.ts +8 -1
  35. package/dist/deps/rest/stats.js +9 -2
  36. package/dist/deps/rest/utils.d.ts +8 -0
  37. package/dist/deps/rest/utils.js +1 -3
  38. package/dist/deps/schema/index.d.ts +20 -5
  39. package/dist/deps/schema/index.js +35 -11
  40. package/dist/deps/sequelize/index.d.ts +7 -2
  41. package/dist/deps/sequelize/index.js +3 -4
  42. package/dist/deps/signer/index.d.ts +33 -8
  43. package/dist/deps/signer/index.js +50 -27
  44. package/dist/dm/index.d.ts +16 -1
  45. package/dist/dm/index.js +15 -0
  46. package/dist/errors/index.d.ts +16 -0
  47. package/dist/errors/index.js +27 -0
  48. package/dist/errors.d.ts +1 -0
  49. package/dist/errors.js +10 -0
  50. package/dist/http/defines.d.ts +45 -0
  51. package/dist/http/defines.js +2 -0
  52. package/dist/index.d.ts +12 -8
  53. package/dist/index.js +11 -4
  54. package/dist/npms.d.ts +88 -0
  55. package/dist/npms.js +31 -0
  56. package/dist/utils/index.d.ts +55 -13
  57. package/dist/utils/index.js +61 -15
  58. package/jest.config.js +8 -1
  59. package/package.json +13 -12
@@ -7,7 +7,11 @@ const RAND_STR_DICT = {
7
7
  normal: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
8
8
  strong: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&’()*+,-./:;<=>?@[]^_`{|}~",
9
9
  };
10
- /** 计算给定字符串的md5值 */
10
+ /**
11
+ * Calculates the MD5 value of the given string
12
+ * @param str string or An object that contains a toString method that returns a string
13
+ * @returns hex md5 string
14
+ */
11
15
  const md5 = (str) => {
12
16
  const hash = crypto.createHash("md5");
13
17
  return hash.update(str.toString()).digest().toString("hex");
@@ -25,19 +29,43 @@ function randStr(len, type) {
25
29
  .join("");
26
30
  }
27
31
  exports.randStr = randStr;
28
- /** 将字符串里的换行,制表符替换为普通空格 */
32
+ /**
33
+ * Replace line breaks and tabs in the string with ordinary spaces
34
+ * @param value string that will be replaced
35
+ * @returns has been replaced string
36
+ */
29
37
  const nt2space = (value) => value.replace(/(\\[ntrfv]|\s)+/g, " ").trim();
30
38
  exports.nt2space = nt2space;
31
- /** 首字符大写 */
39
+ /**
40
+ * The first character of the string is capitalized
41
+ * @param value string
42
+ * @returns string
43
+ * @example ufrist("hello"); // Return a string is: "Hello"
44
+ * @see lcfirst
45
+ */
32
46
  const ucfirst = (value) => value[0].toUpperCase() + value.substring(1);
33
47
  exports.ucfirst = ucfirst;
34
- /** 首字符小写 */
48
+ /**
49
+ * The first character of the string is lowercase
50
+ * @param value string
51
+ * @returns string
52
+ * @example ufrist("Hello"); // Return a string is: "hello"
53
+ * @see ucfirst
54
+ */
35
55
  const lcfirst = (value) => value[0].toLowerCase() + value.substring(1);
36
56
  exports.lcfirst = lcfirst;
37
- /** 睡眠等待 */
57
+ /**
58
+ * Pause, waiting
59
+ * @param ms The time you want to wait, in milliseconds
60
+ * @returns None
61
+ */
38
62
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
39
63
  exports.sleep = sleep;
40
- /** 深度冻结一个对象,防止被不小心篡改 */
64
+ /**
65
+ * Freeze a object and deepth
66
+ * @param object The object that will be freezed
67
+ * @returns freezed object
68
+ */
41
69
  const deepFreeze = (object) => {
42
70
  // Retrieve the property names defined on object
43
71
  const propNames = Object.getOwnPropertyNames(object);
@@ -50,24 +78,42 @@ const deepFreeze = (object) => {
50
78
  return Object.freeze(object);
51
79
  };
52
80
  exports.deepFreeze = deepFreeze;
53
- const tryCatchLog = (fn, errorLog) => async (...args) => {
54
- try {
55
- await fn(...args);
56
- }
57
- catch (e) {
58
- errorLog(e);
59
- }
81
+ /**
82
+ * Mask exceptions of functions
83
+ * @param fn The function will be mask exceptions
84
+ * @param errorLog Error handle function, when has happed throw exception
85
+ * @returns Wrapped function
86
+ */
87
+ const tryCatchLog = (fn, errorLog) => {
88
+ const wrapped = async (...args) => {
89
+ try {
90
+ await fn(...args);
91
+ }
92
+ catch (e) {
93
+ errorLog(e);
94
+ }
95
+ };
96
+ return wrapped;
60
97
  };
61
98
  exports.tryCatchLog = tryCatchLog;
62
99
  /**
63
- 判断某个秒级时间戳是否已过期,基于当前时间
100
+ * Determine whether a second timestamp has expired
101
+ * @param time timestamp
102
+ * @param life Effective time, seconds
103
+ * @returns true or false
64
104
  */
65
105
  const inExpired = (time, life) => {
66
106
  const now = (Date.now() / 1000) | 0;
67
107
  return time < now - life;
68
108
  };
69
109
  exports.inExpired = inExpired;
70
- /** 修改指定url上添加一些参数 */
110
+ /**
111
+ * Modify a URL address, add some attributes and delete some attributes
112
+ * @param address URL address
113
+ * @param adds The params will be expand to address
114
+ * @param removes The string list will be remove from address
115
+ * @returns Modified address
116
+ */
71
117
  const modifiyURL = (address, adds, removes) => {
72
118
  const obj = new URL(address);
73
119
  if (typeof adds === "object") {
package/jest.config.js CHANGED
@@ -2,5 +2,12 @@
2
2
  module.exports = {
3
3
  preset: "ts-jest",
4
4
  testEnvironment: "node",
5
- forceExit: true,
5
+ // forceExit: true,
6
+ collectCoverageFrom: [
7
+ "src/utils/*.ts",
8
+ "src/deps/**/*.ts",
9
+ "src/dm/index.ts",
10
+ "src/http/**/*.ts",
11
+ "src/cli/*.ts",
12
+ ],
6
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -15,16 +15,6 @@
15
15
  "author": "Redstone Zhao",
16
16
  "license": "MIT",
17
17
  "devDependencies": {
18
- "@types/async": "^3.2.10",
19
- "@types/crypto-js": "^4.0.2",
20
- "@types/ioredis": "^4.28.1",
21
- "@types/jest": "^27.0.3",
22
- "@types/lodash": "^4.14.177",
23
- "@types/lru-cache": "^5.1.1",
24
- "@types/restify": "^8.5.4",
25
- "@types/restify-errors": "^4.3.4",
26
- "@types/uuid": "^8.3.3",
27
- "@types/validator": "^13.7.0",
28
18
  "@typescript-eslint/eslint-plugin": "^4.22.0",
29
19
  "@typescript-eslint/parser": "^4.22.0",
30
20
  "babel-eslint": "^10.1.0",
@@ -42,6 +32,7 @@
42
32
  "prettier": "^2.3.0",
43
33
  "sequelize-json-schema": "^2.1.1",
44
34
  "ts-jest": "^27.0.7",
35
+ "ts-node": "^10.4.0",
45
36
  "typescript": "^4.5.2"
46
37
  },
47
38
  "prettier": {
@@ -55,6 +46,16 @@
55
46
  ]
56
47
  },
57
48
  "dependencies": {
49
+ "@types/async": "^3.2.10",
50
+ "@types/crypto-js": "^4.0.2",
51
+ "@types/ioredis": "^4.28.1",
52
+ "@types/jest": "^27.0.3",
53
+ "@types/lodash": "^4.14.177",
54
+ "@types/lru-cache": "^5.1.1",
55
+ "@types/restify": "^8.5.4",
56
+ "@types/restify-errors": "^4.3.4",
57
+ "@types/uuid": "^8.3.3",
58
+ "@types/validator": "^13.7.0",
58
59
  "ajv": "^8.8.1",
59
60
  "ajv-formats": "^2.1.1",
60
61
  "async": "^3.2.2",
@@ -72,7 +73,7 @@
72
73
  "restify-errors": "^8.0.2",
73
74
  "sequelize": "^6.9.0",
74
75
  "swagger-ui-restify": "^3.0.8",
75
- "ts-node": "^10.4.0",
76
+ "type-fest": "^2.8.0",
76
77
  "uuid": "^8.3.2",
77
78
  "xlsx": "^0.17.4"
78
79
  }