@midwayjs/info 4.0.0-alpha.1 → 4.0.0-beta.1

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
@@ -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,6 +12,7 @@ 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");
@@ -23,25 +24,35 @@ let InfoService = class InfoService {
23
24
  });
24
25
  }
25
26
  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());
27
+ const allInfo = [];
28
+ allInfo.push(this.projectInfo());
29
+ allInfo.push(this.systemInfo());
30
+ allInfo.push(this.resourceOccupationInfo());
31
+ allInfo.push(this.softwareInfo());
32
+ allInfo.push(this.midwayConfig());
33
+ allInfo.push(this.midwayService());
34
+ allInfo.push(this.timeInfo());
35
+ allInfo.push(this.envInfo());
36
+ allInfo.push(this.dependenciesInfo());
37
+ allInfo.push(this.networkInfo());
38
+ // 过滤自定义隐藏的key
39
+ const newInfo = allInfo.map(({ type, info }) => {
40
+ const infoKeys = Object.keys(info);
41
+ const keys = infoKeys.filter(k => !this.ignoreKey.includes(k));
42
+ const infoByIgnore = {};
43
+ for (const key of keys) {
44
+ infoByIgnore[key] = info[key];
45
+ }
46
+ return { type, info: infoByIgnore };
47
+ });
37
48
  if (infoValueType === 'html') {
38
- return (0, utils_1.renderToHtml)(info, this.titleConfig);
49
+ return (0, utils_1.renderToHtml)(newInfo, this.titleConfig);
39
50
  }
40
- return info;
51
+ return newInfo;
41
52
  }
42
53
  projectInfo() {
43
54
  return {
44
- type: 'Project',
55
+ type: interface_1.InfoType.PROJECT,
45
56
  info: {
46
57
  Project: this.midwayInformationService.getProjectName(),
47
58
  AppDir: this.midwayInformationService.getAppDir(),
@@ -54,7 +65,7 @@ let InfoService = class InfoService {
54
65
  systemInfo() {
55
66
  const _platform = process.platform;
56
67
  return {
57
- type: 'System',
68
+ type: interface_1.InfoType.SYSTEM,
58
69
  info: {
59
70
  Platform: _platform === 'win32' ? 'Windows' : _platform,
60
71
  Node: process.versions.node,
@@ -72,7 +83,7 @@ let InfoService = class InfoService {
72
83
  const memory = process.memoryUsage();
73
84
  const cpu = (0, os_1.cpus)();
74
85
  return {
75
- type: 'Memory & CPU',
86
+ type: interface_1.InfoType.MEMORY_CPU,
76
87
  info: {
77
88
  'Memory Total Occupy': (0, utils_1.bitToMB)(memory.rss),
78
89
  'Heap Total Occupy': (0, utils_1.bitToMB)(memory.heapTotal),
@@ -110,7 +121,7 @@ let InfoService = class InfoService {
110
121
  }
111
122
  }
112
123
  return {
113
- type: 'Software',
124
+ type: interface_1.InfoType.SOFTWARE,
114
125
  info,
115
126
  };
116
127
  }
@@ -120,14 +131,14 @@ let InfoService = class InfoService {
120
131
  env[envName] = this.filterSecretContent(envName, process.env[envName]);
121
132
  });
122
133
  return {
123
- type: 'Environment Variable',
134
+ type: interface_1.InfoType.ENVIRONMENT_VARIABLE,
124
135
  info: env,
125
136
  };
126
137
  }
127
138
  timeInfo() {
128
139
  const t = new Date().toString().split(' ');
129
140
  return {
130
- type: 'Time',
141
+ type: interface_1.InfoType.TIME,
131
142
  info: {
132
143
  Current: Date.now(),
133
144
  Uptime: (0, os_1.uptime)(),
@@ -164,7 +175,7 @@ let InfoService = class InfoService {
164
175
  .join(' / ');
165
176
  });
166
177
  return {
167
- type: 'Network',
178
+ type: interface_1.InfoType.NETWORK,
168
179
  info,
169
180
  };
170
181
  }
@@ -177,7 +188,7 @@ let InfoService = class InfoService {
177
188
  info[modName] = `${modInfo.version || 'Not Found'}(${dependencies[modName]})`;
178
189
  });
179
190
  return {
180
- type: 'Dependencies',
191
+ type: interface_1.InfoType.DEPENDENCIES,
181
192
  info,
182
193
  };
183
194
  }
@@ -191,7 +202,7 @@ let InfoService = class InfoService {
191
202
  }
192
203
  }
193
204
  return {
194
- type: 'Midway Service',
205
+ type: interface_1.InfoType.MIDWAY_SERVICE,
195
206
  info,
196
207
  };
197
208
  }
@@ -202,7 +213,7 @@ let InfoService = class InfoService {
202
213
  info[key] = this.safeJson(this.filterSecretContent(key, config[key]));
203
214
  });
204
215
  return {
205
- type: 'Midway Config',
216
+ type: interface_1.InfoType.MIDWAY_CONFIG,
206
217
  info,
207
218
  };
208
219
  }
@@ -267,12 +278,16 @@ __decorate([
267
278
  ], InfoService.prototype, "environment", void 0);
268
279
  __decorate([
269
280
  (0, core_1.Config)('info.title'),
270
- __metadata("design:type", Object)
281
+ __metadata("design:type", String)
271
282
  ], InfoService.prototype, "titleConfig", void 0);
272
283
  __decorate([
273
284
  (0, core_1.Config)('info.hiddenKey'),
274
285
  __metadata("design:type", Array)
275
286
  ], InfoService.prototype, "defaultHiddenKey", void 0);
287
+ __decorate([
288
+ (0, core_1.Config)('info.ignoreKey'),
289
+ __metadata("design:type", Array)
290
+ ], InfoService.prototype, "ignoreKey", void 0);
276
291
  __decorate([
277
292
  (0, core_1.ApplicationContext)(),
278
293
  __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;
@@ -43,7 +43,7 @@ let InfoMiddleware = class InfoMiddleware {
43
43
  exports.InfoMiddleware = InfoMiddleware;
44
44
  __decorate([
45
45
  (0, core_1.Config)('info.infoPath'),
46
- __metadata("design:type", Object)
46
+ __metadata("design:type", String)
47
47
  ], InfoMiddleware.prototype, "infoPath", void 0);
48
48
  __decorate([
49
49
  (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/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.1",
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.1",
17
+ "@midwayjs/express": "^4.0.0-beta.1",
18
+ "@midwayjs/koa": "^4.0.0-beta.1",
19
+ "@midwayjs/mock": "^4.0.0-beta.1"
20
20
  },
21
21
  "keywords": [
22
22
  "midway"
@@ -37,5 +37,5 @@
37
37
  "type": "git",
38
38
  "url": "https://github.com/midwayjs/midway.git"
39
39
  },
40
- "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
40
+ "gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
41
41
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2013 - Now midwayjs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.