@domain.js/main 0.3.20 → 0.3.23

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.
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "typescript.tsdk": "node_modules/typescript/lib",
3
3
  "[markdown]": {
4
- "editor.quickSuggestions": true
4
+ "editor.quickSuggestions": {
5
+ "comments": "on",
6
+ "strings": "on",
7
+ "other": "on"
8
+ }
5
9
  },
6
10
  "editor.quickSuggestions": {
7
11
  "other": true,
@@ -1,4 +1,4 @@
1
- import * as _ from "lodash";
1
+ import _ from "lodash";
2
2
  import { v4 } from "uuid";
3
3
  interface Cnf {
4
4
  logger: {
@@ -1,34 +1,19 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
21
5
  Object.defineProperty(exports, "__esModule", { value: true });
22
6
  exports.Deps = exports.Main = void 0;
23
- const fs = __importStar(require("fs"));
24
- const path = __importStar(require("path"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const util_1 = require("util");
25
10
  const date = (offset = 0) => new Date(Date.now() + (offset | 0)).toISOString();
26
11
  function Main(cnf, deps) {
27
12
  const { logger: { errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
28
13
  const { _, uuid: { v4: uuid }, } = deps;
29
14
  const makeDir = _.memoize((dir) => {
30
- if (!fs.existsSync(dir))
31
- fs.mkdirSync(dir);
15
+ if (!fs_1.default.existsSync(dir))
16
+ fs_1.default.mkdirSync(dir);
32
17
  });
33
18
  const ignores = new Set(ignoreErrors);
34
19
  const error = (e, extra) => {
@@ -42,18 +27,30 @@ function Main(cnf, deps) {
42
27
  // 忽略某些错误
43
28
  if (ignores.has(code))
44
29
  return;
45
- const dir = path.resolve(errorLogPath, today);
30
+ const dir = path_1.default.resolve(errorLogPath, today);
46
31
  makeDir(dir);
47
- const file = path.resolve(dir, `${code}.err`);
32
+ const file = path_1.default.resolve(dir, `${code}.err`);
48
33
  const content = [time, clientId, e.message];
49
- if (e.data)
50
- content.push(JSON.stringify(e.data));
51
- if (extra != null)
52
- content.push(JSON.stringify(extra));
34
+ if (e.data) {
35
+ try {
36
+ content.push(JSON.stringify(e.data));
37
+ }
38
+ catch (err) {
39
+ content.push((0, util_1.format)(e.data));
40
+ }
41
+ }
42
+ if (extra !== null || extra !== undefined) {
43
+ try {
44
+ content.push(JSON.stringify(extra));
45
+ }
46
+ catch (e) {
47
+ content.push((0, util_1.format)(extra));
48
+ }
49
+ }
53
50
  if (e.stack)
54
51
  content.push(JSON.stringify(e.stack));
55
52
  try {
56
- fs.appendFileSync(file, `${content.join("\t")}\n`);
53
+ fs_1.default.appendFileSync(file, `${content.join("\t")}\n`);
57
54
  }
58
55
  catch (err) {
59
56
  console.error("Logger.error appendFileSync faid: %o", err);
@@ -62,14 +59,21 @@ function Main(cnf, deps) {
62
59
  const info = (message, extra) => {
63
60
  const time = date();
64
61
  const today = time.split("T")[0];
65
- const dir = path.resolve(infoLogPath, today);
62
+ const dir = path_1.default.resolve(infoLogPath, today);
66
63
  makeDir(dir);
67
- const file = path.resolve(dir, "info.log");
64
+ const file = path_1.default.resolve(dir, "info.log");
68
65
  const content = [time, clientId, message];
69
- if (extra != null)
70
- content.push(JSON.stringify(extra));
66
+ // eslint-disable-next-line no-eq-null
67
+ if (extra !== null || extra !== undefined) {
68
+ try {
69
+ content.push(JSON.stringify(extra));
70
+ }
71
+ catch (e) {
72
+ content.push((0, util_1.format)(extra));
73
+ }
74
+ }
71
75
  try {
72
- fs.appendFileSync(file, `${content.join("\t")}\n`);
76
+ fs_1.default.appendFileSync(file, `${content.join("\t")}\n`);
73
77
  }
74
78
  catch (e) {
75
79
  console.error("Logger.info appendFileSync faid: %o", e);
@@ -6,7 +6,7 @@ interface Deps {
6
6
  _: typeof _;
7
7
  Sequelize: Pick<typeof Sequelize, "literal" | "and" | "fn">;
8
8
  }
9
- export declare function Stats(cnf: {}, deps: Deps, utils: ReturnType<typeof Utils>): <T extends ModelBase<any, any>>(Model: ModelStatic<T>, params: Record<string, any>, where?: any, conf?: {
9
+ export declare function Stats(_cnf: any, deps: Deps, utils: ReturnType<typeof Utils>): <T extends ModelBase<any, any>>(Model: ModelStatic<T>, params: Record<string, any>, where?: any, conf?: {
10
10
  dimensions?: Record<string, string> | undefined;
11
11
  metrics: Record<string, string>;
12
12
  pagination?: {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stats = void 0;
4
- function Stats(cnf, deps, utils) {
4
+ function Stats(_cnf, deps, utils) {
5
5
  const defaultPagination = {
6
6
  maxResults: 10,
7
7
  maxStartIndex: 10000,
@@ -24,6 +24,16 @@ export interface ModelSort<Fields extends string> {
24
24
  allow: Fields[];
25
25
  defaultDirection?: "DESC" | "ASC";
26
26
  }
27
+ /** Model 上的 stats 设定类型 */
28
+ export interface ModelStats<Fields extends string> {
29
+ dimensions?: Record<string, Fields>;
30
+ metrics: Record<string, string>;
31
+ pagination?: {
32
+ maxResults: number;
33
+ maxStartIndex: number;
34
+ maxResultsLimit: number;
35
+ };
36
+ }
27
37
  /**
28
38
  * Model 基类
29
39
  */
@@ -122,6 +122,8 @@ function Utils(cnf) {
122
122
  if (params[k] && lodash_1.default.isString(params[k]))
123
123
  params[k] = params[k].split(",");
124
124
  }
125
+ if (params.__files)
126
+ throw Error("Params.__files disallow assignment");
125
127
  if (lodash_1.default.size(req.files))
126
128
  params.__files = req.files;
127
129
  return params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.3.20",
3
+ "version": "0.3.23",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {