@midwayjs/info 4.0.0-alpha.1 → 4.0.0-beta.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.
package/README.md CHANGED
@@ -29,4 +29,4 @@ Your can curl `/_info` to show it.
29
29
 
30
30
  ## License
31
31
 
32
- [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
32
+ [MIT](https://github.com/midwayjs/midway/blob/master/LICENSE)
@@ -6,5 +6,6 @@ exports.info = {
6
6
  title: 'Midway Info',
7
7
  infoPath: '/_info',
8
8
  hiddenKey: interface_1.DefaultHiddenKey,
9
+ ignoreKey: [],
9
10
  };
10
11
  //# sourceMappingURL=config.default.js.map
@@ -14,6 +14,7 @@ const core_1 = require("@midwayjs/core");
14
14
  const info_middleware_1 = require("./middleware/info.middleware");
15
15
  const DefaultConfig = require("./config.default");
16
16
  let InfoConfiguration = class InfoConfiguration {
17
+ applicationManager;
17
18
  async onReady() {
18
19
  this.applicationManager
19
20
  .getApplications(['koa', 'faas', 'express', 'egg'])
@@ -1,15 +1,19 @@
1
1
  import { MidwayInformationService, IMidwayContainer, MidwayConfigService, MidwayEnvironmentService } from '@midwayjs/core';
2
- import { InfoValueType, TypeInfo } from './interface';
2
+ import { InfoType, InfoValueType, TypeInfo } from './interface';
3
3
  export declare class InfoService {
4
4
  midwayInformationService: MidwayInformationService;
5
5
  configService: MidwayConfigService;
6
6
  environment: MidwayEnvironmentService;
7
- titleConfig: any;
7
+ titleConfig: string;
8
8
  defaultHiddenKey: string[];
9
+ ignoreKey: string[];
9
10
  secretMatchList: Array<any>;
10
11
  container: IMidwayContainer;
11
12
  init(): Promise<void>;
12
- info(infoValueType?: InfoValueType): string | TypeInfo[];
13
+ info(infoValueType?: InfoValueType): string | {
14
+ type: string;
15
+ info: {};
16
+ }[];
13
17
  projectInfo(): TypeInfo;
14
18
  systemInfo(): TypeInfo;
15
19
  resourceOccupationInfo(): TypeInfo;
@@ -19,14 +23,14 @@ export declare class InfoService {
19
23
  networkInfo(): TypeInfo;
20
24
  dependenciesInfo(): TypeInfo;
21
25
  midwayService(): {
22
- type: string;
26
+ type: InfoType;
23
27
  info: {};
24
28
  };
25
29
  midwayConfig(): {
26
- type: string;
30
+ type: InfoType;
27
31
  info: {};
28
32
  };
29
- protected filterSecretContent(key: any, value: any): any;
33
+ protected filterSecretContent(key: string, value: any): any;
30
34
  protected safeJson(value: any): string;
31
35
  }
32
36
  //# sourceMappingURL=infoService.d.ts.map
@@ -12,36 +12,55 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.InfoService = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
14
  const core_2 = require("@midwayjs/core");
15
+ const interface_1 = require("./interface");
15
16
  const utils_1 = require("./utils");
16
17
  const os_1 = require("os");
17
18
  const path_1 = require("path");
18
19
  const pm = require("picomatch");
19
20
  let InfoService = class InfoService {
21
+ midwayInformationService;
22
+ configService;
23
+ environment;
24
+ titleConfig;
25
+ defaultHiddenKey;
26
+ ignoreKey;
27
+ secretMatchList;
28
+ container;
20
29
  async init() {
21
30
  this.secretMatchList = Array.from(new Set(this.defaultHiddenKey)).map(pattern => {
22
31
  return pm(pattern);
23
32
  });
24
33
  }
25
34
  info(infoValueType) {
26
- const info = [];
27
- info.push(this.projectInfo());
28
- info.push(this.systemInfo());
29
- info.push(this.resourceOccupationInfo());
30
- info.push(this.softwareInfo());
31
- info.push(this.midwayConfig());
32
- info.push(this.midwayService());
33
- info.push(this.timeInfo());
34
- info.push(this.envInfo());
35
- info.push(this.dependenciesInfo());
36
- info.push(this.networkInfo());
35
+ const allInfo = [];
36
+ allInfo.push(this.projectInfo());
37
+ allInfo.push(this.systemInfo());
38
+ allInfo.push(this.resourceOccupationInfo());
39
+ allInfo.push(this.softwareInfo());
40
+ allInfo.push(this.midwayConfig());
41
+ allInfo.push(this.midwayService());
42
+ allInfo.push(this.timeInfo());
43
+ allInfo.push(this.envInfo());
44
+ allInfo.push(this.dependenciesInfo());
45
+ allInfo.push(this.networkInfo());
46
+ // 过滤自定义隐藏的key
47
+ const newInfo = allInfo.map(({ type, info }) => {
48
+ const infoKeys = Object.keys(info);
49
+ const keys = infoKeys.filter(k => !this.ignoreKey.includes(k));
50
+ const infoByIgnore = {};
51
+ for (const key of keys) {
52
+ infoByIgnore[key] = info[key];
53
+ }
54
+ return { type, info: infoByIgnore };
55
+ });
37
56
  if (infoValueType === 'html') {
38
- return (0, utils_1.renderToHtml)(info, this.titleConfig);
57
+ return (0, utils_1.renderToHtml)(newInfo, this.titleConfig);
39
58
  }
40
- return info;
59
+ return newInfo;
41
60
  }
42
61
  projectInfo() {
43
62
  return {
44
- type: 'Project',
63
+ type: interface_1.InfoType.PROJECT,
45
64
  info: {
46
65
  Project: this.midwayInformationService.getProjectName(),
47
66
  AppDir: this.midwayInformationService.getAppDir(),
@@ -54,7 +73,7 @@ let InfoService = class InfoService {
54
73
  systemInfo() {
55
74
  const _platform = process.platform;
56
75
  return {
57
- type: 'System',
76
+ type: interface_1.InfoType.SYSTEM,
58
77
  info: {
59
78
  Platform: _platform === 'win32' ? 'Windows' : _platform,
60
79
  Node: process.versions.node,
@@ -72,7 +91,7 @@ let InfoService = class InfoService {
72
91
  const memory = process.memoryUsage();
73
92
  const cpu = (0, os_1.cpus)();
74
93
  return {
75
- type: 'Memory & CPU',
94
+ type: interface_1.InfoType.MEMORY_CPU,
76
95
  info: {
77
96
  'Memory Total Occupy': (0, utils_1.bitToMB)(memory.rss),
78
97
  'Heap Total Occupy': (0, utils_1.bitToMB)(memory.heapTotal),
@@ -110,7 +129,7 @@ let InfoService = class InfoService {
110
129
  }
111
130
  }
112
131
  return {
113
- type: 'Software',
132
+ type: interface_1.InfoType.SOFTWARE,
114
133
  info,
115
134
  };
116
135
  }
@@ -120,14 +139,14 @@ let InfoService = class InfoService {
120
139
  env[envName] = this.filterSecretContent(envName, process.env[envName]);
121
140
  });
122
141
  return {
123
- type: 'Environment Variable',
142
+ type: interface_1.InfoType.ENVIRONMENT_VARIABLE,
124
143
  info: env,
125
144
  };
126
145
  }
127
146
  timeInfo() {
128
147
  const t = new Date().toString().split(' ');
129
148
  return {
130
- type: 'Time',
149
+ type: interface_1.InfoType.TIME,
131
150
  info: {
132
151
  Current: Date.now(),
133
152
  Uptime: (0, os_1.uptime)(),
@@ -164,7 +183,7 @@ let InfoService = class InfoService {
164
183
  .join(' / ');
165
184
  });
166
185
  return {
167
- type: 'Network',
186
+ type: interface_1.InfoType.NETWORK,
168
187
  info,
169
188
  };
170
189
  }
@@ -177,7 +196,7 @@ let InfoService = class InfoService {
177
196
  info[modName] = `${modInfo.version || 'Not Found'}(${dependencies[modName]})`;
178
197
  });
179
198
  return {
180
- type: 'Dependencies',
199
+ type: interface_1.InfoType.DEPENDENCIES,
181
200
  info,
182
201
  };
183
202
  }
@@ -191,7 +210,7 @@ let InfoService = class InfoService {
191
210
  }
192
211
  }
193
212
  return {
194
- type: 'Midway Service',
213
+ type: interface_1.InfoType.MIDWAY_SERVICE,
195
214
  info,
196
215
  };
197
216
  }
@@ -202,7 +221,7 @@ let InfoService = class InfoService {
202
221
  info[key] = this.safeJson(this.filterSecretContent(key, config[key]));
203
222
  });
204
223
  return {
205
- type: 'Midway Config',
224
+ type: interface_1.InfoType.MIDWAY_CONFIG,
206
225
  info,
207
226
  };
208
227
  }
@@ -267,12 +286,16 @@ __decorate([
267
286
  ], InfoService.prototype, "environment", void 0);
268
287
  __decorate([
269
288
  (0, core_1.Config)('info.title'),
270
- __metadata("design:type", Object)
289
+ __metadata("design:type", String)
271
290
  ], InfoService.prototype, "titleConfig", void 0);
272
291
  __decorate([
273
292
  (0, core_1.Config)('info.hiddenKey'),
274
293
  __metadata("design:type", Array)
275
294
  ], InfoService.prototype, "defaultHiddenKey", void 0);
295
+ __decorate([
296
+ (0, core_1.Config)('info.ignoreKey'),
297
+ __metadata("design:type", Array)
298
+ ], InfoService.prototype, "ignoreKey", void 0);
276
299
  __decorate([
277
300
  (0, core_1.ApplicationContext)(),
278
301
  __metadata("design:type", Object)
@@ -10,5 +10,19 @@ export interface InfoConfigOptions {
10
10
  title: string;
11
11
  infoPath: string;
12
12
  hiddenKey: Array<string>;
13
+ ignoreKey: Array<string>;
14
+ }
15
+ export declare enum InfoType {
16
+ PROJECT = "Project",
17
+ SYSTEM = "System",
18
+ MEMORY_CPU = "Memory & CPU",
19
+ SOFTWARE = "Software",
20
+ ENVIRONMENT_VARIABLE = "Environment Variable",
21
+ TIME = "Time",
22
+ NETWORK = "Network",
23
+ RESOURCE = "Resource",
24
+ DEPENDENCIES = "Dependencies",
25
+ MIDWAY_SERVICE = "Midway Service",
26
+ MIDWAY_CONFIG = "Midway Config"
13
27
  }
14
28
  //# sourceMappingURL=interface.d.ts.map
package/dist/interface.js CHANGED
@@ -1,5 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultHiddenKey = void 0;
3
+ exports.InfoType = exports.DefaultHiddenKey = void 0;
4
4
  exports.DefaultHiddenKey = ['keys', '*key', '*token', '*secret*', 'pass*'];
5
+ var InfoType;
6
+ (function (InfoType) {
7
+ InfoType["PROJECT"] = "Project";
8
+ InfoType["SYSTEM"] = "System";
9
+ InfoType["MEMORY_CPU"] = "Memory & CPU";
10
+ InfoType["SOFTWARE"] = "Software";
11
+ InfoType["ENVIRONMENT_VARIABLE"] = "Environment Variable";
12
+ InfoType["TIME"] = "Time";
13
+ InfoType["NETWORK"] = "Network";
14
+ InfoType["RESOURCE"] = "Resource";
15
+ InfoType["DEPENDENCIES"] = "Dependencies";
16
+ InfoType["MIDWAY_SERVICE"] = "Midway Service";
17
+ InfoType["MIDWAY_CONFIG"] = "Midway Config";
18
+ })(InfoType || (exports.InfoType = InfoType = {}));
5
19
  //# sourceMappingURL=interface.js.map
@@ -1,6 +1,6 @@
1
1
  import { InfoService } from '../infoService';
2
2
  export declare class InfoMiddleware {
3
- protected infoPath: any;
3
+ protected infoPath: string;
4
4
  protected infoService: InfoService;
5
5
  resolve(app: any): ((req: any, res: any, next: any) => Promise<void>) | ((ctx: any, next: any) => Promise<any>);
6
6
  static getName(): string;
@@ -13,6 +13,8 @@ exports.InfoMiddleware = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
14
  const infoService_1 = require("../infoService");
15
15
  let InfoMiddleware = class InfoMiddleware {
16
+ infoPath;
17
+ infoService;
16
18
  resolve(app) {
17
19
  if ('express' === app.getNamespace()) {
18
20
  return async (req, res, next) => {
@@ -43,7 +45,7 @@ let InfoMiddleware = class InfoMiddleware {
43
45
  exports.InfoMiddleware = InfoMiddleware;
44
46
  __decorate([
45
47
  (0, core_1.Config)('info.infoPath'),
46
- __metadata("design:type", Object)
48
+ __metadata("design:type", String)
47
49
  ], InfoMiddleware.prototype, "infoPath", void 0);
48
50
  __decorate([
49
51
  (0, core_1.Inject)(),
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TypeInfo } from './interface';
2
2
  export declare function safeRequire(mod: string, defaultValue?: any): any;
3
3
  export declare function bitToMB(bit: number): string;
4
- export declare function renderToHtml(infoList: TypeInfo[], title: any): string;
4
+ export declare function renderToHtml(infoList: TypeInfo[], title: string): string;
5
5
  export declare function safeContent(value?: string): string;
6
6
  //# sourceMappingURL=utils.d.ts.map
package/dist/utils.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safeContent = exports.renderToHtml = exports.bitToMB = exports.safeRequire = void 0;
3
+ exports.safeRequire = safeRequire;
4
+ exports.bitToMB = bitToMB;
5
+ exports.renderToHtml = renderToHtml;
6
+ exports.safeContent = safeContent;
4
7
  const fs_1 = require("fs");
5
8
  function safeRequire(mod, defaultValue) {
6
9
  try {
@@ -13,11 +16,9 @@ function safeRequire(mod, defaultValue) {
13
16
  return defaultValue;
14
17
  }
15
18
  }
16
- exports.safeRequire = safeRequire;
17
19
  function bitToMB(bit) {
18
20
  return Number((bit || 0) / 1024 / 1024).toFixed(2) + ' MB';
19
21
  }
20
- exports.bitToMB = bitToMB;
21
22
  function renderToHtml(infoList, title) {
22
23
  let html = `<div style="padding: 24px; font-size: 36px;background: #9999cb;font-weight: bold;">${title}</div>`;
23
24
  html += infoList
@@ -37,7 +38,6 @@ function renderToHtml(infoList, title) {
37
38
  .infoValue {vertical-align: top;background:#d8d8d8;padding: 12px;word-break:break-all;}
38
39
  </style><div style="margin: 24px auto;max-width: 720px;min-width: 440px;">${html}</div>`;
39
40
  }
40
- exports.renderToHtml = renderToHtml;
41
41
  function safeContent(value = '') {
42
42
  if (value.length < 3) {
43
43
  return '*'.repeat(value.length);
@@ -55,5 +55,4 @@ function safeContent(value = '') {
55
55
  return value.slice(0, 3) + '*'.repeat(value.length - 6) + value.slice(-3);
56
56
  }
57
57
  }
58
- exports.safeContent = safeContent;
59
58
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midwayjs/info",
3
3
  "description": "midway info",
4
- "version": "4.0.0-alpha.1",
4
+ "version": "4.0.0-beta.10",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
@@ -13,10 +13,10 @@
13
13
  "picomatch": "2.3.1"
14
14
  },
15
15
  "devDependencies": {
16
- "@midwayjs/core": "^4.0.0-alpha.1",
17
- "@midwayjs/express": "^4.0.0-alpha.1",
18
- "@midwayjs/koa": "^4.0.0-alpha.1",
19
- "@midwayjs/mock": "^4.0.0-alpha.1"
16
+ "@midwayjs/core": "^4.0.0-beta.10",
17
+ "@midwayjs/express": "^4.0.0-beta.10",
18
+ "@midwayjs/koa": "^4.0.0-beta.10",
19
+ "@midwayjs/mock": "^4.0.0-beta.10"
20
20
  },
21
21
  "keywords": [
22
22
  "midway"
@@ -31,11 +31,11 @@
31
31
  "lint": "mwts check"
32
32
  },
33
33
  "engines": {
34
- "node": ">=12"
34
+ "node": ">=20"
35
35
  },
36
36
  "repository": {
37
37
  "type": "git",
38
38
  "url": "https://github.com/midwayjs/midway.git"
39
39
  },
40
- "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
40
+ "gitHead": "1b1856629913703f67304155aaf611ec936a81ac"
41
41
  }