@hlw-midway/core 1.0.0

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.
Files changed (77) hide show
  1. package/README.md +4 -0
  2. package/dist/bin/check.d.ts +4 -0
  3. package/dist/bin/check.js +41 -0
  4. package/dist/bin/entity.d.ts +8 -0
  5. package/dist/bin/entity.js +50 -0
  6. package/dist/bin/index.d.ts +2 -0
  7. package/dist/bin/index.js +49 -0
  8. package/dist/bin/obfuscate.d.ts +1 -0
  9. package/dist/bin/obfuscate.js +69 -0
  10. package/dist/cache/store.d.ts +18 -0
  11. package/dist/cache/store.js +38 -0
  12. package/dist/config/config.default.d.ts +8 -0
  13. package/dist/config/config.default.js +22 -0
  14. package/dist/configuration.d.ts +17 -0
  15. package/dist/configuration.js +106 -0
  16. package/dist/constant/global.d.ts +59 -0
  17. package/dist/constant/global.js +85 -0
  18. package/dist/controller/base.d.ts +107 -0
  19. package/dist/controller/base.js +236 -0
  20. package/dist/decorator/cache.d.ts +2 -0
  21. package/dist/decorator/cache.js +10 -0
  22. package/dist/decorator/controller.d.ts +71 -0
  23. package/dist/decorator/controller.js +169 -0
  24. package/dist/decorator/event.d.ts +21 -0
  25. package/dist/decorator/event.js +39 -0
  26. package/dist/decorator/index.d.ts +22 -0
  27. package/dist/decorator/index.js +120 -0
  28. package/dist/decorator/tag.d.ts +22 -0
  29. package/dist/decorator/tag.js +40 -0
  30. package/dist/decorator/transaction.d.ts +8 -0
  31. package/dist/decorator/transaction.js +10 -0
  32. package/dist/entity/base.d.ts +10 -0
  33. package/dist/entity/base.js +41 -0
  34. package/dist/entity/mongo.d.ts +10 -0
  35. package/dist/entity/mongo.js +35 -0
  36. package/dist/entity/typeorm.d.ts +3 -0
  37. package/dist/entity/typeorm.js +7 -0
  38. package/dist/event/index.d.ts +53 -0
  39. package/dist/event/index.js +188 -0
  40. package/dist/exception/base.d.ts +8 -0
  41. package/dist/exception/base.js +15 -0
  42. package/dist/exception/comm.d.ts +7 -0
  43. package/dist/exception/comm.js +15 -0
  44. package/dist/exception/core.d.ts +7 -0
  45. package/dist/exception/core.js +15 -0
  46. package/dist/exception/filter.d.ts +11 -0
  47. package/dist/exception/filter.js +42 -0
  48. package/dist/exception/validate.d.ts +7 -0
  49. package/dist/exception/validate.js +15 -0
  50. package/dist/index.d.ts +31 -0
  51. package/dist/index.js +60 -0
  52. package/dist/interface.d.ts +432 -0
  53. package/dist/interface.js +24 -0
  54. package/dist/module/config.d.ts +21 -0
  55. package/dist/module/config.js +109 -0
  56. package/dist/module/import.d.ts +64 -0
  57. package/dist/module/import.js +244 -0
  58. package/dist/module/menu.d.ts +54 -0
  59. package/dist/module/menu.js +178 -0
  60. package/dist/rest/eps.d.ts +51 -0
  61. package/dist/rest/eps.js +269 -0
  62. package/dist/service/base.d.ts +167 -0
  63. package/dist/service/base.js +281 -0
  64. package/dist/service/mysql.d.ts +143 -0
  65. package/dist/service/mysql.js +524 -0
  66. package/dist/service/postgres.d.ts +160 -0
  67. package/dist/service/postgres.js +639 -0
  68. package/dist/service/sqlite.d.ts +142 -0
  69. package/dist/service/sqlite.js +560 -0
  70. package/dist/tag/data.d.ts +25 -0
  71. package/dist/tag/data.js +85 -0
  72. package/dist/util/func.d.ts +8 -0
  73. package/dist/util/func.js +44 -0
  74. package/dist/util/location.d.ts +26 -0
  75. package/dist/util/location.js +113 -0
  76. package/index.d.ts +10 -0
  77. package/package.json +68 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * URL标签
3
+ */
4
+ export declare class HlwUrlTagData {
5
+ data: {};
6
+ /**
7
+ * 初始化
8
+ */
9
+ init(): Promise<void>;
10
+ /**
11
+ * 类标记
12
+ */
13
+ classTag(): Promise<void>;
14
+ /**
15
+ * 方法标记
16
+ */
17
+ methodTag(): Promise<void>;
18
+ /**
19
+ * 根据键获得
20
+ * @param key
21
+ * @param type
22
+ * @returns
23
+ */
24
+ byKey(key: string, type?: 'app' | 'admin'): string[];
25
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.HlwUrlTagData = void 0;
10
+ const tag_1 = require("./../decorator/tag");
11
+ const core_1 = require("@midwayjs/core");
12
+ const tag_2 = require("../decorator/tag");
13
+ const _ = require("lodash");
14
+ /**
15
+ * URL标签
16
+ */
17
+ let HlwUrlTagData = class HlwUrlTagData {
18
+ constructor() {
19
+ this.data = {};
20
+ }
21
+ /**
22
+ * 初始化
23
+ */
24
+ async init() {
25
+ // 类标记
26
+ await this.classTag();
27
+ // 方法标记
28
+ await this.methodTag();
29
+ }
30
+ /**
31
+ * 类标记
32
+ */
33
+ async classTag() {
34
+ const tags = (0, core_1.listModule)(tag_2.HLW_URL_TAG_KEY);
35
+ for (const controller of tags) {
36
+ // class的标记
37
+ const controllerOption = (0, core_1.getClassMetadata)(core_1.CONTROLLER_KEY, controller);
38
+ const tagOption = (0, core_1.getClassMetadata)(tag_2.HLW_URL_TAG_KEY, controller);
39
+ if (tagOption === null || tagOption === void 0 ? void 0 : tagOption.key) {
40
+ const data = this.data[tagOption.key] || [];
41
+ this.data[tagOption.key] = _.uniq(data.concat(((tagOption === null || tagOption === void 0 ? void 0 : tagOption.value) || []).map(e => {
42
+ return (controllerOption.prefix + '/' + e).toLowerCase();
43
+ })));
44
+ }
45
+ }
46
+ }
47
+ /**
48
+ * 方法标记
49
+ */
50
+ async methodTag() {
51
+ const controllers = (0, core_1.listModule)(core_1.CONTROLLER_KEY);
52
+ for (const controller of controllers) {
53
+ const controllerOption = (0, core_1.getClassMetadata)(core_1.CONTROLLER_KEY, controller);
54
+ // 方法标记
55
+ const listPropertyMetas = (0, core_1.listPropertyDataFromClass)(tag_1.HLW_METHOD_TAG_KEY, controller);
56
+ const requestMetas = (0, core_1.getClassMetadata)(core_1.WEB_ROUTER_KEY, controller);
57
+ for (const propertyMeta of listPropertyMetas) {
58
+ const _data = this.data[propertyMeta.tag] || [];
59
+ const requestMeta = _.find(requestMetas, { method: propertyMeta.key });
60
+ if (requestMeta && controllerOption) {
61
+ const fullUrl = (controllerOption.prefix + requestMeta.path).toLowerCase();
62
+ console.log('[HlwUrlTagData] tag:', propertyMeta.tag, 'url:', fullUrl);
63
+ this.data[propertyMeta.tag] = _.uniq(_data.concat(fullUrl));
64
+ }
65
+ }
66
+ }
67
+ }
68
+ /**
69
+ * 根据键获得
70
+ * @param key
71
+ * @param type
72
+ * @returns
73
+ */
74
+ byKey(key, type) {
75
+ var _a;
76
+ return (_a = this.data[key]) === null || _a === void 0 ? void 0 : _a.filter(e => {
77
+ return type ? _.startsWith(e, `/${type}/`) : true;
78
+ });
79
+ }
80
+ };
81
+ exports.HlwUrlTagData = HlwUrlTagData;
82
+ exports.HlwUrlTagData = HlwUrlTagData = __decorate([
83
+ (0, core_1.Provide)(),
84
+ (0, core_1.Scope)(core_1.ScopeEnum.Singleton)
85
+ ], HlwUrlTagData);
@@ -0,0 +1,8 @@
1
+ import { ILogger } from '@midwayjs/core';
2
+ /**
3
+ * 常用函数处理
4
+ */
5
+ export declare class FuncUtil {
6
+ coreLogger: ILogger;
7
+ init(): Promise<void>;
8
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FuncUtil = void 0;
13
+ const core_1 = require("@midwayjs/core");
14
+ const moment = require("moment");
15
+ /**
16
+ * 常用函数处理
17
+ */
18
+ let FuncUtil = class FuncUtil {
19
+ async init() {
20
+ Date.prototype.toJSON = function () {
21
+ return moment(this).format('YYYY-MM-DD HH:mm:ss');
22
+ };
23
+ // 新增String支持replaceAll方法
24
+ String.prototype['replaceAll'] = function (s1, s2) {
25
+ return this.replace(new RegExp(s1, 'gm'), s2);
26
+ };
27
+ this.coreLogger.info('\x1B[36m [hlw:core] midwayjs hlw core func handler \x1B[0m');
28
+ }
29
+ };
30
+ exports.FuncUtil = FuncUtil;
31
+ __decorate([
32
+ (0, core_1.Logger)(),
33
+ __metadata("design:type", Object)
34
+ ], FuncUtil.prototype, "coreLogger", void 0);
35
+ __decorate([
36
+ (0, core_1.Init)(),
37
+ __metadata("design:type", Function),
38
+ __metadata("design:paramtypes", []),
39
+ __metadata("design:returntype", Promise)
40
+ ], FuncUtil.prototype, "init", null);
41
+ exports.FuncUtil = FuncUtil = __decorate([
42
+ (0, core_1.Provide)(),
43
+ (0, core_1.Scope)(core_1.ScopeEnum.Singleton)
44
+ ], FuncUtil);
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Location 工具类
3
+ */
4
+ export declare class LocationUtil {
5
+ private locationCache;
6
+ distPath: string;
7
+ init(): Promise<void>;
8
+ /**
9
+ * 获取编译后的文件路径
10
+ * @returns 编译后的文件路径
11
+ */
12
+ getDistPath(): string;
13
+ /**
14
+ * 获取目标类的定义位置
15
+ * @param target 目标类
16
+ * @returns 目标类的定义位置
17
+ */
18
+ scriptPath(target: any): Promise<any>;
19
+ /**
20
+ * 获取使用此包的项目的真实根目录路径
21
+ * @returns 项目根目录的绝对路径
22
+ */
23
+ getRunPath(): string;
24
+ }
25
+ declare const _default: LocationUtil;
26
+ export default _default;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LocationUtil = void 0;
13
+ const core_1 = require("@midwayjs/core");
14
+ const fs = require("fs");
15
+ const path = require("path");
16
+ /**
17
+ * Location 工具类
18
+ */
19
+ let LocationUtil = class LocationUtil {
20
+ constructor() {
21
+ this.locationCache = new Map();
22
+ }
23
+ async init() {
24
+ this.distPath = this.getRunPath();
25
+ }
26
+ /**
27
+ * 获取编译后的文件路径
28
+ * @returns 编译后的文件路径
29
+ */
30
+ getDistPath() {
31
+ return this.distPath;
32
+ }
33
+ /**
34
+ * 获取目标类的定义位置
35
+ * @param target 目标类
36
+ * @returns 目标类的定义位置
37
+ */
38
+ async scriptPath(target) {
39
+ const targetName = target.name;
40
+ // 检查缓存
41
+ if (this.locationCache.has(targetName)) {
42
+ return this.locationCache.get(targetName);
43
+ }
44
+ const originalPrepareStackTrace = Error.prepareStackTrace;
45
+ let targetFile;
46
+ try {
47
+ Error.prepareStackTrace = (error, stack) => stack;
48
+ const stack = new Error().stack;
49
+ for (const site of stack) {
50
+ const fileName = site.getFileName();
51
+ // 如果文件名不存在,则跳过
52
+ if (!fileName || !fs.existsSync(fileName))
53
+ continue;
54
+ if (!fileName.includes('/modules/') &&
55
+ !fileName.includes('\\modules\\'))
56
+ continue;
57
+ targetFile = {
58
+ path: fileName,
59
+ line: site.getLineNumber(),
60
+ column: site.getColumnNumber(),
61
+ source: `file://${fileName}`,
62
+ };
63
+ this.locationCache.set(targetName, targetFile);
64
+ break;
65
+ }
66
+ }
67
+ finally {
68
+ Error.prepareStackTrace = originalPrepareStackTrace;
69
+ }
70
+ return targetFile;
71
+ }
72
+ /**
73
+ * 获取使用此包的项目的真实根目录路径
74
+ * @returns 项目根目录的绝对路径
75
+ */
76
+ getRunPath() {
77
+ // 从自身文件路径向上查找项目根目录
78
+ // 兼容:node_modules 安装、file: 本地包引用、dev 模式直接运行 src
79
+ let current = __dirname;
80
+ // 先处理 node_modules 场景
81
+ const nodeModulesIndex = current.indexOf('/node_modules/') !== -1
82
+ ? current.indexOf('/node_modules/')
83
+ : current.indexOf('\\node_modules\\');
84
+ if (nodeModulesIndex !== -1) {
85
+ return path.join(current.substring(0, nodeModulesIndex), 'dist');
86
+ }
87
+ // 本地包或 dev 模式:向上查找含 packages/ 子目录的项目根
88
+ while (current !== path.dirname(current)) {
89
+ const pkgPath = path.join(current, 'package.json');
90
+ const packagesDir = path.join(current, 'packages');
91
+ if (fs.existsSync(pkgPath) &&
92
+ !current.includes(path.sep + 'packages' + path.sep) &&
93
+ fs.existsSync(packagesDir)) {
94
+ return path.join(current, 'dist');
95
+ }
96
+ current = path.dirname(current);
97
+ }
98
+ return __dirname;
99
+ }
100
+ };
101
+ exports.LocationUtil = LocationUtil;
102
+ __decorate([
103
+ (0, core_1.Init)(),
104
+ __metadata("design:type", Function),
105
+ __metadata("design:paramtypes", []),
106
+ __metadata("design:returntype", Promise)
107
+ ], LocationUtil.prototype, "init", null);
108
+ exports.LocationUtil = LocationUtil = __decorate([
109
+ (0, core_1.Provide)(),
110
+ (0, core_1.Scope)(core_1.ScopeEnum.Singleton)
111
+ ], LocationUtil);
112
+ // 不再需要单例模式,直接导出实例即可
113
+ exports.default = new LocationUtil();
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from './dist/index';
2
+
3
+ declare module '@midwayjs/core/dist/interface' {
4
+ interface MidwayConfig {
5
+ book?: PowerPartial<{
6
+ a: number;
7
+ b: string;
8
+ }>;
9
+ }
10
+ }
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@hlw-midway/core",
3
+ "version": "1.0.0",
4
+ "description": "hlw-admin midway core",
5
+ "main": "dist/index.js",
6
+ "typings": "index.d.ts",
7
+ "bin": {
8
+ "hlw": "dist/bin/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "mwtsc --cleanOutDir",
12
+ "test": "cross-env NODE_ENV=unittest jest",
13
+ "cov": "jest --coverage",
14
+ "lint": "mwts check",
15
+ "lint:fix": "mwts fix"
16
+ },
17
+ "keywords": [
18
+ "hlw",
19
+ "hlw-admin"
20
+ ],
21
+ "author": "HLW",
22
+ "files": [
23
+ "dist/**/*.js",
24
+ "dist/**/*.d.ts",
25
+ "index.d.ts"
26
+ ],
27
+ "readme": "README.md",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://cn.vuejs.org/"
32
+ },
33
+ "devDependencies": {
34
+ "@midwayjs/core": "^3.20.0",
35
+ "@midwayjs/koa": "^3.20.0",
36
+ "@midwayjs/logger": "^3.4.2",
37
+ "@midwayjs/mock": "^3.20.0",
38
+ "@midwayjs/typeorm": "^3.20.0",
39
+ "@types/download": "^8.0.5",
40
+ "@types/jest": "^29.5.14",
41
+ "@types/node": "^22.10.7",
42
+ "aedes": "^0.51.3",
43
+ "cross-env": "^7.0.3",
44
+ "jest": "^29.7.0",
45
+ "mwts": "^1.3.0",
46
+ "mwtsc": "^1.15.1",
47
+ "ts-jest": "^29.2.5",
48
+ "typeorm": "^0.3.20",
49
+ "typescript": "~5.7.3"
50
+ },
51
+ "dependencies": {
52
+ "@hlw-midway/cache-manager-fs-hash": "file:../cache-manager-fs-hash",
53
+ "@midwayjs/cache-manager": "^3.20.0",
54
+ "axios": "^1.7.9",
55
+ "commander": "^13.1.0",
56
+ "download": "^8.0.0",
57
+ "glob": "^11.0.1",
58
+ "javascript-obfuscator": "^4.1.1",
59
+ "jsonwebtoken": "^9.0.2",
60
+ "lodash": "^4.17.21",
61
+ "md5": "^2.3.0",
62
+ "moment": "^2.30.1",
63
+ "pm2": "^5.4.3",
64
+ "sqlstring": "^2.3.3",
65
+ "uuid": "^11.0.5",
66
+ "ws": "^8.18.0"
67
+ }
68
+ }