@domain.js/main 0.3.23 → 0.3.26

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.
@@ -2,6 +2,7 @@ import _ from "lodash";
2
2
  import { v4 } from "uuid";
3
3
  interface Cnf {
4
4
  logger: {
5
+ level?: "info" | "error" | "none";
5
6
  clientId: string;
6
7
  errorLogPath: string;
7
8
  infoLogPath: string;
@@ -4,19 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Deps = exports.Main = void 0;
7
- const fs_1 = __importDefault(require("fs"));
7
+ const fs_1 = require("fs");
8
+ const promises_1 = __importDefault(require("fs/promises"));
8
9
  const path_1 = __importDefault(require("path"));
9
10
  const util_1 = require("util");
10
11
  const date = (offset = 0) => new Date(Date.now() + (offset | 0)).toISOString();
11
12
  function Main(cnf, deps) {
12
- const { logger: { errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
13
+ const { logger: { level, errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
13
14
  const { _, uuid: { v4: uuid }, } = deps;
14
15
  const makeDir = _.memoize((dir) => {
15
- if (!fs_1.default.existsSync(dir))
16
- fs_1.default.mkdirSync(dir);
16
+ if (!(0, fs_1.existsSync)(dir))
17
+ (0, fs_1.mkdirSync)(dir);
17
18
  });
18
19
  const ignores = new Set(ignoreErrors);
19
20
  const error = (e, extra) => {
21
+ if (level === "none")
22
+ return;
20
23
  if (!e) {
21
24
  console.trace("Logger.error but error is null or undefined");
22
25
  return;
@@ -49,14 +52,11 @@ function Main(cnf, deps) {
49
52
  }
50
53
  if (e.stack)
51
54
  content.push(JSON.stringify(e.stack));
52
- try {
53
- fs_1.default.appendFileSync(file, `${content.join("\t")}\n`);
54
- }
55
- catch (err) {
56
- console.error("Logger.error appendFileSync faid: %o", err);
57
- }
55
+ promises_1.default.appendFile(file, `${content.join("\t")}\n`).catch(console.error);
58
56
  };
59
57
  const info = (message, extra) => {
58
+ if (level === "none" || level === "error")
59
+ return;
60
60
  const time = date();
61
61
  const today = time.split("T")[0];
62
62
  const dir = path_1.default.resolve(infoLogPath, today);
@@ -72,14 +72,11 @@ function Main(cnf, deps) {
72
72
  content.push((0, util_1.format)(extra));
73
73
  }
74
74
  }
75
- try {
76
- fs_1.default.appendFileSync(file, `${content.join("\t")}\n`);
77
- }
78
- catch (e) {
79
- console.error("Logger.info appendFileSync faid: %o", e);
80
- }
75
+ promises_1.default.appendFile(file, `${content.join("\t")}\n`).catch(console.error);
81
76
  };
82
77
  const logger = (fn, name, isAsync = false, transform = (x) => x, errorHandler = (e) => (e instanceof Error ? e.message : ""), argsHandler = JSON.stringify) => {
78
+ if (level === "none")
79
+ return fn;
83
80
  if (isAsync) {
84
81
  const handler = {
85
82
  async apply(fn, me, args) {
@@ -116,15 +116,12 @@ function BridgeSocket(io, domain) {
116
116
  try {
117
117
  if (!client.profile || !client.inited)
118
118
  return;
119
- const res = await entrance({ roomId, ...client.profile }, client);
119
+ const res = await entrance({ ...client.profile, roomId }, client);
120
120
  client.profile.roomId = roomId;
121
121
  client.roomId = roomId;
122
122
  client.emit("entranced", res);
123
123
  }
124
124
  catch (e) {
125
- client.roomId = undefined;
126
- if (client.profile)
127
- client.profile.roomId = undefined;
128
125
  if (e instanceof MyError) {
129
126
  client.emit("internalError", e.message, e.code || "unknown");
130
127
  return;
@@ -126,7 +126,8 @@ function Utils(cnf) {
126
126
  throw Error("Params.__files disallow assignment");
127
127
  if (lodash_1.default.size(req.files))
128
128
  params.__files = req.files;
129
- return params;
129
+ // 将上传文件附加到 params
130
+ return { ...params, ...req.files };
130
131
  },
131
132
  /**
132
133
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.3.23",
3
+ "version": "0.3.26",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {