@domain.js/main 0.7.15 → 1.0.0-alpha.10

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 (76) hide show
  1. package/.husky/pre-commit +1 -7
  2. package/.prettierignore +34 -0
  3. package/.prettierrc +11 -0
  4. package/.vscode/extensions.json +7 -0
  5. package/.vscode/settings.json +27 -1
  6. package/dist/Errors/index.d.ts +1 -1
  7. package/dist/Errors/index.js +1 -2
  8. package/dist/basic-errors.d.ts +1 -1
  9. package/dist/basic-errors.js +1 -0
  10. package/dist/cfg/index.js +1 -2
  11. package/dist/cli/index.js +22 -8
  12. package/dist/defaults.d.ts +0 -30
  13. package/dist/defaults.js +22 -18
  14. package/dist/deps/aes/index.js +63 -14
  15. package/dist/deps/cache/index.d.ts +29 -4
  16. package/dist/deps/cache/index.js +34 -13
  17. package/dist/deps/counter/index.js +2 -2
  18. package/dist/deps/cron/index.d.ts +3 -3
  19. package/dist/deps/cron/index.js +4 -4
  20. package/dist/deps/defines.d.ts +0 -2
  21. package/dist/deps/defines.js +38 -26
  22. package/dist/deps/frequency/index.js +2 -2
  23. package/dist/deps/graceful/index.d.ts +1 -1
  24. package/dist/deps/graceful/index.js +2 -2
  25. package/dist/deps/hash/index.js +2 -2
  26. package/dist/deps/logger/index.d.ts +1 -9
  27. package/dist/deps/logger/index.js +8 -8
  28. package/dist/deps/myCia/errors.d.ts +1 -1
  29. package/dist/deps/myCia/errors.js +22 -8
  30. package/dist/deps/myCia/index.d.ts +2 -10
  31. package/dist/deps/myCia/index.js +15 -12
  32. package/dist/deps/parallel/index.d.ts +1 -8
  33. package/dist/deps/parallel/index.js +31 -16
  34. package/dist/deps/redis/index.js +2 -2
  35. package/dist/deps/request/index.d.ts +2 -2
  36. package/dist/deps/request/index.js +2 -2
  37. package/dist/deps/rest/Before.d.ts +2 -2
  38. package/dist/deps/rest/Before.js +1 -2
  39. package/dist/deps/rest/index.d.ts +12 -19
  40. package/dist/deps/rest/index.js +4 -5
  41. package/dist/deps/rest/stats.d.ts +1 -9
  42. package/dist/deps/rest/stats.js +1 -2
  43. package/dist/deps/rest/utils.d.ts +3 -17
  44. package/dist/deps/rest/utils.js +77 -59
  45. package/dist/deps/schema/index.d.ts +2 -2
  46. package/dist/deps/schema/index.js +24 -10
  47. package/dist/deps/sequelize/index.d.ts +3 -3
  48. package/dist/deps/sequelize/index.js +2 -2
  49. package/dist/deps/signer/index.js +24 -10
  50. package/dist/dm/index.d.ts +1 -1
  51. package/dist/dm/index.js +24 -11
  52. package/dist/http/defines.d.ts +13 -0
  53. package/dist/http/index.d.ts +11 -3
  54. package/dist/http/index.js +53 -50
  55. package/dist/http/router.d.ts +20 -20
  56. package/dist/http/router.js +42 -97
  57. package/dist/http/socket.d.ts +2 -2
  58. package/dist/http/socket.js +1 -2
  59. package/dist/http/utils.d.ts +13 -7
  60. package/dist/http/utils.js +104 -24
  61. package/dist/index.d.ts +20 -61
  62. package/dist/index.js +30 -12
  63. package/dist/types/index.d.ts +2 -2
  64. package/dist/utils/index.d.ts +3 -3
  65. package/dist/utils/index.js +24 -10
  66. package/eslint.config.js +117 -0
  67. package/package.json +59 -55
  68. package/.eslintrc.js +0 -33
  69. package/dist/deps/cache/After.d.ts +0 -2
  70. package/dist/deps/cache/After.js +0 -29
  71. package/dist/deps/cache/Before.d.ts +0 -4
  72. package/dist/deps/cache/Before.js +0 -16
  73. package/dist/deps/cache/Define.d.ts +0 -30
  74. package/dist/deps/cache/Define.js +0 -2
  75. package/dist/deps/checker/index.d.ts +0 -15
  76. package/dist/deps/checker/index.js +0 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.7.15",
3
+ "version": "1.0.0-alpha.10",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -10,77 +10,81 @@
10
10
  "build": "rm -rf ./dist/* && tsc",
11
11
  "test": "export NODE_ENV=test && jest ./src --coverage",
12
12
  "test:watch": "export NODE_ENV=test && jest ./src --watch",
13
- "prepare": "husky install",
14
13
  "lint-staged": "lint-staged",
15
- "lint-staged:js": "eslint --ext .js,.ts",
14
+ "lint-staged:js": "eslint --no-warn-ignored src/**/*.ts",
16
15
  "loadDeps": "ts-node src/cli/index.ts loadDeps ./src/deps ts"
17
16
  },
18
17
  "author": "Redstone Zhao",
19
18
  "license": "MIT",
20
- "devDependencies": {
21
- "@typescript-eslint/eslint-plugin": "^5.11.0",
22
- "@typescript-eslint/parser": "^5.11.0",
23
- "babel-eslint": "^10.1.0",
24
- "codecov": "^3.8.3",
25
- "eslint-config-airbnb": "^18.2.0",
26
- "eslint-config-alloy": "^4.4.0",
27
- "eslint-config-prettier": "^8.3.0",
28
- "eslint-plugin-import": "^2.22.1",
29
- "eslint-plugin-jsx-a11y": "^6.3.1",
30
- "eslint-plugin-prettier": "^3.4.0",
31
- "eslint-plugin-react": "^7.21.4",
32
- "eslint-plugin-simple-import-sort": "^7.0.0",
33
- "eslint-plugin-unused-imports": "^2.0.0",
34
- "eslint": "^8.8.0",
35
- "husky": "^7.0.0",
36
- "jest": "^27.3.1",
37
- "lint-staged": "^11.0.0",
38
- "prettier": "^2.3.0",
39
- "sequelize-json-schema": "^2.1.1",
40
- "ts-jest": "^27.0.7",
41
- "ts-node": "^10.5.0",
42
- "typescript": "^4.5.5"
43
- },
44
19
  "prettier": {
45
20
  "printWidth": 100,
46
21
  "trailingComma": "all"
47
22
  },
48
23
  "lint-staged": {
49
- "**/*.{js,ts}": [
24
+ "src/**/*.{js,ts}": [
50
25
  "prettier --write",
51
26
  "eslint --fix"
52
27
  ]
53
28
  },
29
+ "devDependencies": {
30
+ "@babel/eslint-parser": "^7.28.6",
31
+ "@eslint/js": "^10.0.1",
32
+ "@fastify/multipart": "^9.4.0",
33
+ "@types/async": "^3.2.25",
34
+ "@types/jest": "^30.0.0",
35
+ "@types/lodash": "^4.17.24",
36
+ "@types/node": "25.3.0",
37
+ "@types/validator": "^13.15.10",
38
+ "@types/ws": "^8.18.1",
39
+ "@typescript-eslint/eslint-plugin": "^8.56.0",
40
+ "@typescript-eslint/parser": "^8.56.0",
41
+ "async": "^3.2.6",
42
+ "axios": "^1.13.5",
43
+ "eslint": "^10.0.1",
44
+ "eslint-config-airbnb": "^19.0.4",
45
+ "eslint-config-alloy": "^5.1.2",
46
+ "eslint-config-prettier": "^10.1.8",
47
+ "eslint-plugin-import": "^2.32.0",
48
+ "eslint-plugin-jsx-a11y": "^6.10.2",
49
+ "eslint-plugin-prettier": "^5.5.5",
50
+ "eslint-plugin-react": "^7.37.5",
51
+ "eslint-plugin-simple-import-sort": "^12.1.1",
52
+ "eslint-plugin-unused-imports": "^4.4.1",
53
+ "fastify": "^5.7.4",
54
+ "husky": "^9.1.7",
55
+ "ioredis": "^5.9.3",
56
+ "jest": "^30.2.0",
57
+ "lint-staged": "^16.2.7",
58
+ "lodash": "^4.17.23",
59
+ "mysql2": "^3.17.4",
60
+ "prettier": "^3.8.1",
61
+ "sequelize": "^6.37.5",
62
+ "socket.io": "^4.8.3",
63
+ "ts-jest": "^29.4.6",
64
+ "ts-node": "^10.9.2",
65
+ "typescript": "^5.9.3"
66
+ },
54
67
  "dependencies": {
55
- "@types/async": "^3.2.10",
56
- "@types/crypto-js": "^4.0.2",
57
- "@types/jest": "^27.0.3",
58
- "@types/lodash": "^4.14.177",
59
- "@types/lru-cache": "^5.1.1",
60
- "@types/restify-errors": "^4.3.4",
61
- "@types/restify": "^8.5.4",
62
- "@types/uuid": "^8.3.3",
63
- "@types/validator": "^13.7.0",
64
- "ajv": "^8.8.1",
65
- "ajv-formats": "^2.1.1",
68
+ "ajv": "^8.18.0",
69
+ "ajv-formats": "^3.0.1",
66
70
  "ajv-keywords": "^5.1.0",
67
- "async": "^3.2.2",
68
- "axios": "^0.24.0",
69
- "cron-parser": "^4.1.0",
70
- "crypto-js": "^4.1.1",
71
- "csv-stringify": "^6.0.2",
71
+ "cron-parser": "^5.5.0",
72
+ "csv-stringify": "^6.6.0",
73
+ "dayjs": "^1.11.19",
74
+ "fastify-socket.io": "^5.1.0",
72
75
  "human-interval": "^2.0.1",
73
- "ioredis": "^5.4.1",
74
- "lodash": "^4.17.21",
75
- "lru-cache": "^6.0.0",
76
- "moment": "^2.29.1",
77
- "mysql2": "^2.3.3",
78
- "restify": "^11.1.0",
79
- "restify-errors": "^8.0.2",
80
- "sequelize": "^6.37.5",
81
- "socket.io": "^4.4.1",
82
- "type-fest": "^2.8.0",
83
- "uuid": "^8.3.2",
76
+ "lru-cache": "^11.2.6",
84
77
  "xlsx": "^0.18.5"
78
+ },
79
+ "peerDependencies": {
80
+ "@fastify/multipart": "^9.4.0",
81
+ "async": "^3.2.6",
82
+ "axios": "^1.13.5",
83
+ "fastify": "^5.7.4",
84
+ "ioredis": "^5.9.3",
85
+ "lodash": "^4.17.23",
86
+ "mysql2": "^3.17.4",
87
+ "sequelize": "^6.37.5",
88
+ "socket.io": "^4.8.3"
85
89
  }
86
90
  }
package/.eslintrc.js DELETED
@@ -1,33 +0,0 @@
1
- module.exports = {
2
- parser: "@typescript-eslint/parser", // 解析ts 代码编译器,将ts 语法树转化为 eslint 期望的
3
- extends: ["alloy", "alloy/typescript"],
4
- plugins: ["simple-import-sort", "unused-imports"],
5
- env: {
6
- // Your environments (which contains several predefined global variables)
7
- //
8
- node: true,
9
- commonjs: true,
10
- es6: true,
11
- jest: true,
12
- },
13
- globals: {
14
- // Your global variables (setting to false means it's not allowed to be reassigned)
15
- //
16
- // myGlobal: false
17
- },
18
- rules: {
19
- // Customize your rules
20
- "spaced-comment": "off", // 注释前有空白检查
21
- "simple-import-sort/imports": "error", // 优化import 顺序
22
- "simple-import-sort/exports": "error", // 优化 export 顺序
23
- "no-multiple-empty-lines": ["warn", { max: 2 }], // 强制最大连续空行数为 2
24
- complexity: ["error", 20], // https://cn.eslint.org/docs/rules/complexity
25
- "no-template-curly-in-string": "error", //禁止在常规字符串中出现模板字面量占位符语法
26
- "unused-imports/no-unused-imports": "warn",
27
- "@typescript-eslint/explicit-member-accessibility": "off", // 不强制设置类成员的可访问性
28
- "@typescript-eslint/member-ordering": "off", // 不严格限制类成员顺序
29
- "max-params": ["error", 6], // 函数最多6个参数
30
- "@typescript-eslint/no-require-imports": "off", // 部分第三方库不支持 esModuleInterop 编译选项
31
- "@typescript-eslint/prefer-optional-chain": "off", // 过多使用可选操作符降低代码可读性 foo?.a?.b?.c
32
- },
33
- };
@@ -1,2 +0,0 @@
1
- import { Cache, CnfDef, DepsDef, PubSubDef } from "./Define";
2
- export declare const After: (lru: Pick<Cache, "del">, cnf: CnfDef, deps: Pick<DepsDef, "logger">, pubsub?: PubSubDef | undefined) => void;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.After = void 0;
4
- const After = (lru, cnf, deps, pubsub) => {
5
- const { cache = {} } = cnf;
6
- const { isMulti = false, delSignalChannel = "LRU_DEL_SIGNAL_CHANNEL" } = cache;
7
- // 如果不是多节点分部署部署,则不需要处理
8
- // 开启多节点分布式部署后,要通过redis广播cache的del事件,以此来保持cache的有效性
9
- if (!isMulti || !pubsub)
10
- return;
11
- const { logger } = deps;
12
- const { pub, sub } = pubsub;
13
- sub.subscribe(delSignalChannel, (err, count) => {
14
- logger.info("cache.redis.subscribe", { chanels: delSignalChannel, count });
15
- if (err)
16
- return logger.error(err);
17
- return logger.info(`cache.redis.subscribe succeed, channel count: ${count}`);
18
- });
19
- const del = lru.del.bind(lru);
20
- lru.del = (key) => {
21
- del(key);
22
- pub.publish(delSignalChannel, key);
23
- };
24
- sub.on("message", async (channel, key) => {
25
- if (channel === delSignalChannel)
26
- del(key);
27
- });
28
- };
29
- exports.After = After;
@@ -1,4 +0,0 @@
1
- import { CnfDef, DepsDef, PubSubDef } from "./Define";
2
- declare type returns = [CnfDef, DepsDef, PubSubDef?];
3
- export declare const Before: (cnf: CnfDef, deps: DepsDef) => returns;
4
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Before = void 0;
4
- const Before = (cnf, deps) => {
5
- const { cache = {}, redis } = cnf;
6
- const { isMulti = false } = cache;
7
- if (!isMulti)
8
- return [cnf, deps];
9
- const { IORedis } = deps;
10
- // 如果不是多节点分部署部署,则不需要处理
11
- // 开启多节点分布式部署后,要通过redis广播cache的del事件,依次来保持cache的有效性
12
- const pub = new IORedis(redis);
13
- const sub = new IORedis(redis);
14
- return [cnf, deps, { pub, sub }];
15
- };
16
- exports.Before = Before;
@@ -1,30 +0,0 @@
1
- import Redis from "ioredis";
2
- import LRU from "lru-cache";
3
- import { SetRequired } from "type-fest";
4
- export interface CnfDef {
5
- cache?: {
6
- isMulti?: boolean;
7
- delSignalChannel?: string;
8
- } & LRU.Options<string, string>;
9
- redis?: any;
10
- }
11
- export interface DepsDef {
12
- LRU: typeof LRU;
13
- IORedis: typeof Redis;
14
- logger: {
15
- info: (message: string, extra?: any) => void;
16
- error: (error: Error, extra?: any) => void;
17
- };
18
- }
19
- export interface PubSubDef {
20
- pub: SetRequired<Partial<Redis>, "publish">;
21
- sub: SetRequired<Partial<Redis>, "on" | "subscribe">;
22
- }
23
- export interface Cache extends LRU<string, string> {
24
- caching: <T extends (...args: any[]) => Promise<any>>(func: T, life: number, getKey: (...args: Parameters<T>) => string, hit?: (hited: boolean) => void) => T;
25
- hitCount: () => {
26
- hits: number;
27
- misseds: number;
28
- };
29
- needToBroad: boolean;
30
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +0,0 @@
1
- import { someSeries } from "async";
2
- interface Deps {
3
- async: {
4
- someSeries: typeof someSeries;
5
- };
6
- errors: {
7
- notAllowed(...args: any[]): Error;
8
- };
9
- }
10
- export declare function Main(cnf: {}, deps: Deps): {
11
- equal: (v1: any, v2: any) => boolean;
12
- privacy: (fns: [Function, ...any[]][], error?: Error) => Promise<void>;
13
- };
14
- export declare const Deps: string[];
15
- export {};
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Deps = exports.Main = void 0;
4
- function Main(cnf, deps) {
5
- const { async, errors } = deps;
6
- /** 检测两个值是否相等 */
7
- const equal = (v1, v2) => v1 === v2;
8
- /** 判断判断,一次执行数组里的函数 遇到成功的立刻停止,否则抛出信息 */
9
- const PRIVACY_DEFAULT_ERROR = errors.notAllowed("权限不足");
10
- const privacy = async (fns, error = PRIVACY_DEFAULT_ERROR) => {
11
- const passed = (await async.someSeries(fns, async ([fn, ...args]) => {
12
- const ret = await fn(...args);
13
- return ret;
14
- }));
15
- if (!passed)
16
- throw error;
17
- };
18
- return {
19
- equal,
20
- privacy,
21
- };
22
- }
23
- exports.Main = Main;
24
- exports.Deps = ["errors", "async"];