@domain.js/main 1.0.0-alpha.4 → 1.0.0-arpha.7

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/.husky/pre-commit CHANGED
@@ -1,8 +1,2 @@
1
- #!/bin/sh
2
- if [ ! -f "$(dirname "$0")/_/husky.sh" ]; then
3
- npx husky install
4
- fi
5
- . "$(dirname "$0")/_/husky.sh"
6
-
7
1
  ts-node src/cli/index.ts loadDeps ./src/deps ts && npm run lint-staged && npm run build
8
2
  # npm tst
@@ -1,4 +1,4 @@
1
- import * as cronParser from "cron-parser";
1
+ import { CronExpressionParser } from "cron-parser";
2
2
  import human = require("human-interval");
3
3
  interface Cnf {
4
4
  cron?: {
@@ -14,7 +14,7 @@ interface callbackArg {
14
14
  cronJob: [Error | null, any, number];
15
15
  }
16
16
  interface Deps {
17
- cronParser: typeof cronParser;
17
+ cronParser: typeof CronExpressionParser;
18
18
  humanInterval: typeof human;
19
19
  myCia: {
20
20
  regist: (name: string, validator: any, waiters: waiter[]) => void;
@@ -21,7 +21,7 @@ exports.timeout = timeout;
21
21
  function Main(cnf, deps) {
22
22
  const { cron = {} } = cnf;
23
23
  const ciaTaskType = "cronJob";
24
- const { myCia, humanInterval: human, cronParser: parser } = deps;
24
+ const { myCia, humanInterval: human, cronParser: CronParser } = deps;
25
25
  const { tz = "Asia/Shanghai" } = cron;
26
26
  // 注册信息
27
27
  const registed = {};
@@ -29,7 +29,7 @@ function Main(cnf, deps) {
29
29
  let startedAt;
30
30
  // 计算具体下次执行还有多少毫秒
31
31
  const calcNextMS = (intervalStr) => {
32
- const interval = human(intervalStr) || parser.parseExpression(intervalStr, { tz });
32
+ const interval = human(intervalStr) || CronParser.parse(intervalStr, { tz });
33
33
  if (typeof interval === "number")
34
34
  return interval;
35
35
  // * * * * * *
@@ -7,7 +7,7 @@ export declare function Main(cnf: Cnf, deps: {
7
7
  httpCodes: HttpCodes;
8
8
  makeProfileHook?: (obj: Profile, req: FastifyRequest) => any;
9
9
  socketLogger?: (...args: any[]) => void;
10
- }): () => import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>> & {
10
+ }): () => import("fastify").FastifyInstance<import("node:http").Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse>, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("node:http").Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse>, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>> & {
11
11
  __linterBrands: "SafePromiseLike";
12
12
  };
13
13
  declare module "fastify" {
@@ -23,7 +23,9 @@ export declare function Utils(cnf: Cnf): {
23
23
  Querystring: Record<string, any>;
24
24
  Params: Record<string, any>;
25
25
  Body: Record<string, any>;
26
- }>): Promise<{}>;
26
+ }>): Promise<{
27
+ [x: string]: any;
28
+ }>;
27
29
  /**
28
30
  *
29
31
  * 输出csv相关
@@ -150,26 +150,42 @@ function Utils(cnf) {
150
150
  else if (req.body) {
151
151
  params.__raw = req.body;
152
152
  }
153
- // 逗号分隔的属性,自动转换为 array
154
- for (const k of str2arr) {
155
- if (params[k] && lodash_1.default.isString(params[k]))
156
- params[k] = params[k].split(",");
157
- }
158
- // 检查请求是否包含文件上传
153
+ // 处理 multipart:同时解析字段与文件
159
154
  let files = {};
160
155
  try {
161
- // 只有在 multipart 请求时才处理文件
162
156
  if ((_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.includes("multipart/form-data")) {
163
- const uploadedFile = await req.file();
164
- if (uploadedFile) {
165
- files = await RestifyFileConvertUploadFiles(uploadedFile);
157
+ const fields = {};
158
+ const parts = req.parts();
159
+ for await (const part of parts) {
160
+ if (part.type === "file") {
161
+ const saved = await RestifyFileConvertUploadFiles(part);
162
+ Object.assign(files, saved);
163
+ }
164
+ else if (part.type === "field") {
165
+ const key = part.fieldname;
166
+ const value = part.value;
167
+ if (fields[key] !== undefined) {
168
+ fields[key] = Array.isArray(fields[key])
169
+ ? [...fields[key], value]
170
+ : [fields[key], value];
171
+ }
172
+ else {
173
+ fields[key] = value;
174
+ }
175
+ }
166
176
  }
177
+ // 将表单字段合并进 params
178
+ params = { ...fields, ...params };
167
179
  }
168
180
  }
169
181
  catch (error) {
170
- // 如果文件处理出错,记录错误但不中断请求处理
171
182
  console.warn("File upload processing error:", error);
172
183
  }
184
+ // 逗号分隔的属性,自动转换为 array(在合并字段之后处理)
185
+ for (const k of str2arr) {
186
+ if (params[k] && lodash_1.default.isString(params[k]))
187
+ params[k] = params[k].split(",");
188
+ }
173
189
  // 将上传文件附加到 params 中
174
190
  return { ...params, ...files };
175
191
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-arpha.7",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -10,7 +10,6 @@
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
14
  "lint-staged:js": "eslint --no-warn-ignored src/**/*.ts",
16
15
  "loadDeps": "ts-node src/cli/index.ts loadDeps ./src/deps ts"
@@ -18,29 +17,33 @@
18
17
  "author": "Redstone Zhao",
19
18
  "license": "MIT",
20
19
  "devDependencies": {
21
- "@babel/eslint-parser": "^7.28.0",
20
+ "@babel/eslint-parser": "^7.28.6",
21
+ "@eslint/js": "^10.0.1",
22
+ "@types/async": "^3.2.25",
22
23
  "@types/jest": "^30.0.0",
23
- "@types/node": "24.1.0",
24
- "@typescript-eslint/eslint-plugin": "^8.38.0",
25
- "@typescript-eslint/parser": "^8.38.0",
26
- "codecov": "^3.8.3",
27
- "eslint": "^9.32.0",
24
+ "@types/lodash": "^4.17.24",
25
+ "@types/node": "25.3.0",
26
+ "@types/validator": "^13.15.10",
27
+ "@types/ws": "^8.18.1",
28
+ "@typescript-eslint/eslint-plugin": "^8.56.0",
29
+ "@typescript-eslint/parser": "^8.56.0",
30
+ "eslint": "^10.0.1",
28
31
  "eslint-config-airbnb": "^19.0.4",
29
32
  "eslint-config-alloy": "^5.1.2",
30
33
  "eslint-config-prettier": "^10.1.8",
31
34
  "eslint-plugin-import": "^2.32.0",
32
35
  "eslint-plugin-jsx-a11y": "^6.10.2",
33
- "eslint-plugin-prettier": "^5.5.3",
36
+ "eslint-plugin-prettier": "^5.5.5",
34
37
  "eslint-plugin-react": "^7.37.5",
35
38
  "eslint-plugin-simple-import-sort": "^12.1.1",
36
- "eslint-plugin-unused-imports": "^4.1.4",
39
+ "eslint-plugin-unused-imports": "^4.4.1",
37
40
  "husky": "^9.1.7",
38
- "jest": "^30.0.5",
39
- "lint-staged": "^16.1.2",
40
- "prettier": "^3.6.2",
41
- "ts-jest": "^29.4.0",
41
+ "jest": "^30.2.0",
42
+ "lint-staged": "^16.2.7",
43
+ "prettier": "^3.8.1",
44
+ "ts-jest": "^29.4.6",
42
45
  "ts-node": "^10.9.2",
43
- "typescript": "^5.8.3"
46
+ "typescript": "^5.9.3"
44
47
  },
45
48
  "prettier": {
46
49
  "printWidth": 100,
@@ -53,26 +56,23 @@
53
56
  ]
54
57
  },
55
58
  "dependencies": {
56
- "@fastify/multipart": "^9.0.3",
57
- "@types/async": "^3.2.25",
58
- "@types/lodash": "^4.17.20",
59
- "@types/validator": "^13.7.0",
60
- "ajv": "^8.17.1",
59
+ "@fastify/multipart": "^9.4.0",
60
+ "ajv": "^8.18.0",
61
61
  "ajv-formats": "^3.0.1",
62
62
  "ajv-keywords": "^5.1.0",
63
63
  "async": "^3.2.6",
64
- "cron-parser": "^4.1.0",
65
- "csv-stringify": "^6.0.2",
66
- "dayjs": "^1.11.13",
67
- "fastify": "^5.4.0",
64
+ "cron-parser": "^5.5.0",
65
+ "csv-stringify": "^6.6.0",
66
+ "dayjs": "^1.11.19",
67
+ "fastify": "^5.7.4",
68
68
  "fastify-socket.io": "^5.1.0",
69
69
  "human-interval": "^2.0.1",
70
- "ioredis": "^5.7.0",
71
- "lodash": "^4.17.21",
72
- "lru-cache": "^11.1.0",
73
- "mysql2": "^3.14.3",
70
+ "ioredis": "^5.9.3",
71
+ "lodash": "^4.17.23",
72
+ "lru-cache": "^11.2.6",
73
+ "mysql2": "^3.17.4",
74
74
  "sequelize": "^6.37.7",
75
- "socket.io": "^4.8.1",
75
+ "socket.io": "^4.8.3",
76
76
  "xlsx": "^0.18.5"
77
77
  }
78
78
  }