@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.
- package/README.md +4 -0
- package/dist/bin/check.d.ts +4 -0
- package/dist/bin/check.js +41 -0
- package/dist/bin/entity.d.ts +8 -0
- package/dist/bin/entity.js +50 -0
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.js +49 -0
- package/dist/bin/obfuscate.d.ts +1 -0
- package/dist/bin/obfuscate.js +69 -0
- package/dist/cache/store.d.ts +18 -0
- package/dist/cache/store.js +38 -0
- package/dist/config/config.default.d.ts +8 -0
- package/dist/config/config.default.js +22 -0
- package/dist/configuration.d.ts +17 -0
- package/dist/configuration.js +106 -0
- package/dist/constant/global.d.ts +59 -0
- package/dist/constant/global.js +85 -0
- package/dist/controller/base.d.ts +107 -0
- package/dist/controller/base.js +236 -0
- package/dist/decorator/cache.d.ts +2 -0
- package/dist/decorator/cache.js +10 -0
- package/dist/decorator/controller.d.ts +71 -0
- package/dist/decorator/controller.js +169 -0
- package/dist/decorator/event.d.ts +21 -0
- package/dist/decorator/event.js +39 -0
- package/dist/decorator/index.d.ts +22 -0
- package/dist/decorator/index.js +120 -0
- package/dist/decorator/tag.d.ts +22 -0
- package/dist/decorator/tag.js +40 -0
- package/dist/decorator/transaction.d.ts +8 -0
- package/dist/decorator/transaction.js +10 -0
- package/dist/entity/base.d.ts +10 -0
- package/dist/entity/base.js +41 -0
- package/dist/entity/mongo.d.ts +10 -0
- package/dist/entity/mongo.js +35 -0
- package/dist/entity/typeorm.d.ts +3 -0
- package/dist/entity/typeorm.js +7 -0
- package/dist/event/index.d.ts +53 -0
- package/dist/event/index.js +188 -0
- package/dist/exception/base.d.ts +8 -0
- package/dist/exception/base.js +15 -0
- package/dist/exception/comm.d.ts +7 -0
- package/dist/exception/comm.js +15 -0
- package/dist/exception/core.d.ts +7 -0
- package/dist/exception/core.js +15 -0
- package/dist/exception/filter.d.ts +11 -0
- package/dist/exception/filter.js +42 -0
- package/dist/exception/validate.d.ts +7 -0
- package/dist/exception/validate.js +15 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +60 -0
- package/dist/interface.d.ts +432 -0
- package/dist/interface.js +24 -0
- package/dist/module/config.d.ts +21 -0
- package/dist/module/config.js +109 -0
- package/dist/module/import.d.ts +64 -0
- package/dist/module/import.js +244 -0
- package/dist/module/menu.d.ts +54 -0
- package/dist/module/menu.js +178 -0
- package/dist/rest/eps.d.ts +51 -0
- package/dist/rest/eps.js +269 -0
- package/dist/service/base.d.ts +167 -0
- package/dist/service/base.js +281 -0
- package/dist/service/mysql.d.ts +143 -0
- package/dist/service/mysql.js +524 -0
- package/dist/service/postgres.d.ts +160 -0
- package/dist/service/postgres.js +639 -0
- package/dist/service/sqlite.d.ts +142 -0
- package/dist/service/sqlite.js +560 -0
- package/dist/tag/data.d.ts +25 -0
- package/dist/tag/data.js +85 -0
- package/dist/util/func.d.ts +8 -0
- package/dist/util/func.js +44 -0
- package/dist/util/location.d.ts +26 -0
- package/dist/util/location.js +113 -0
- package/index.d.ts +10 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.check = check;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
/**
|
|
8
|
+
* 检查并替换单个配置文件
|
|
9
|
+
*/
|
|
10
|
+
async function checkAndReplaceFile(config) {
|
|
11
|
+
const filePath = (0, path_1.join)(process.cwd(), config.path);
|
|
12
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let content = (0, fs_1.readFileSync)(filePath, 'utf-8');
|
|
16
|
+
if (content.includes(config.pattern)) {
|
|
17
|
+
console.log(`${config.path},key is default, auto replace it`);
|
|
18
|
+
content = content.replace(config.pattern, (0, uuid_1.v4)());
|
|
19
|
+
(0, fs_1.writeFileSync)(filePath, content, 'utf-8');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 检查配置文件
|
|
24
|
+
*/
|
|
25
|
+
async function check() {
|
|
26
|
+
const configs = [
|
|
27
|
+
{
|
|
28
|
+
path: 'src/config/config.default.ts',
|
|
29
|
+
pattern: 'hlw-admin-keys-xxxxxx',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
path: 'src/modules/system/config.ts',
|
|
33
|
+
pattern: 'hlw-admin-xxxxxx',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
path: 'src/modules/user/config.ts',
|
|
37
|
+
pattern: 'hlw-app-xxxxx',
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
await Promise.all(configs.map(config => checkAndReplaceFile(config)));
|
|
41
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateEntitiesFile = generateEntitiesFile;
|
|
4
|
+
exports.clearEntitiesFile = clearEntitiesFile;
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const glob = require("glob");
|
|
8
|
+
const MODULES_PATH = 'src/modules';
|
|
9
|
+
const OUTPUT_FILE = 'src/entities.ts';
|
|
10
|
+
/**
|
|
11
|
+
* 生成 entities.ts 文件
|
|
12
|
+
*/
|
|
13
|
+
function generateEntitiesFile() {
|
|
14
|
+
// 扫描所有的 ts 文件
|
|
15
|
+
const entityFiles = glob.sync('*/entity/**/*.ts', {
|
|
16
|
+
cwd: MODULES_PATH,
|
|
17
|
+
absolute: true,
|
|
18
|
+
});
|
|
19
|
+
// 生成导入语句和导出数组
|
|
20
|
+
const imports = entityFiles.map((file, index) => {
|
|
21
|
+
const relativePath = path
|
|
22
|
+
.relative(path.dirname(OUTPUT_FILE), file)
|
|
23
|
+
.split(path.sep)
|
|
24
|
+
.join('/');
|
|
25
|
+
return `import * as entity${index} from './${relativePath.replace(/\.ts$/, '')}';`;
|
|
26
|
+
});
|
|
27
|
+
const exportEntities = `export const entities = [
|
|
28
|
+
${entityFiles
|
|
29
|
+
.map((_, index) => `...Object.values(entity${index})`)
|
|
30
|
+
.join(',\n ')},
|
|
31
|
+
];`;
|
|
32
|
+
// 生成最终的文件内容
|
|
33
|
+
const fileContent = `// 自动生成的文件,请勿手动修改
|
|
34
|
+
${imports.join('\n')}
|
|
35
|
+
${exportEntities}
|
|
36
|
+
`;
|
|
37
|
+
// 写入文件
|
|
38
|
+
fs.writeFileSync(OUTPUT_FILE, fileContent);
|
|
39
|
+
console.log('Entities file generated successfully!');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 清空 entities.ts 文件
|
|
43
|
+
*/
|
|
44
|
+
function clearEntitiesFile() {
|
|
45
|
+
const emptyContent = `// 自动生成的文件,请勿手动修改
|
|
46
|
+
export const entities = [];
|
|
47
|
+
`;
|
|
48
|
+
fs.writeFileSync(OUTPUT_FILE, emptyContent);
|
|
49
|
+
console.log('Entities file cleared successfully!');
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const check_1 = require("./check");
|
|
6
|
+
const entity_1 = require("./entity");
|
|
7
|
+
const obfuscate_1 = require("./obfuscate");
|
|
8
|
+
const program = new commander_1.Command();
|
|
9
|
+
// 设置版本号(从 package.json 中获取)
|
|
10
|
+
program.version(require('../../package.json').version);
|
|
11
|
+
// 修改命令定义部分
|
|
12
|
+
const commands = {
|
|
13
|
+
check: async () => await (0, check_1.check)(),
|
|
14
|
+
entity: async (options = {}) => {
|
|
15
|
+
if (options.clear) {
|
|
16
|
+
await (0, entity_1.clearEntitiesFile)();
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
await (0, entity_1.generateEntitiesFile)();
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
obfuscate: async () => await (0, obfuscate_1.obfuscate)(),
|
|
23
|
+
};
|
|
24
|
+
// 移除原有的单独命令定义
|
|
25
|
+
program
|
|
26
|
+
.arguments('[cmds...]')
|
|
27
|
+
.option('--clear', 'Clear entities file when using entity command')
|
|
28
|
+
.description('Run one or multiple commands: check, entity, obfuscate')
|
|
29
|
+
.action(async (cmds, options) => {
|
|
30
|
+
if (!cmds.length) {
|
|
31
|
+
program.outputHelp();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
for (const cmd of cmds) {
|
|
35
|
+
if (cmd in commands) {
|
|
36
|
+
console.log(`Executing ${cmd}...`);
|
|
37
|
+
await commands[cmd](options);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.error(`Unknown command: ${cmd}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
// 解析命令行参数
|
|
45
|
+
program.parse(process.argv);
|
|
46
|
+
// 如果没有任何命令,显示帮助信息
|
|
47
|
+
if (!process.argv.slice(2).length) {
|
|
48
|
+
program.outputHelp();
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function obfuscate(): Promise<void>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.obfuscate = obfuscate;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const JavaScriptObfuscator = require("javascript-obfuscator");
|
|
7
|
+
// 混淆配置
|
|
8
|
+
const obfuscatorOptions = {
|
|
9
|
+
compact: true,
|
|
10
|
+
controlFlowFlattening: true,
|
|
11
|
+
controlFlowFlatteningThreshold: 0.7,
|
|
12
|
+
deadCodeInjection: true,
|
|
13
|
+
deadCodeInjectionThreshold: 0.4,
|
|
14
|
+
debugProtection: false,
|
|
15
|
+
debugProtectionInterval: 0,
|
|
16
|
+
disableConsoleOutput: true,
|
|
17
|
+
identifierNamesGenerator: 'hexadecimal',
|
|
18
|
+
log: false,
|
|
19
|
+
numbersToExpressions: true,
|
|
20
|
+
renameGlobals: false,
|
|
21
|
+
rotateStringArray: true,
|
|
22
|
+
selfDefending: true,
|
|
23
|
+
shuffleStringArray: true,
|
|
24
|
+
splitStrings: true,
|
|
25
|
+
splitStringsChunkLength: 10,
|
|
26
|
+
stringArray: true,
|
|
27
|
+
stringArrayEncoding: ['base64'],
|
|
28
|
+
stringArrayThreshold: 0.75,
|
|
29
|
+
transformObjectKeys: true,
|
|
30
|
+
unicodeEscapeSequence: false,
|
|
31
|
+
};
|
|
32
|
+
// 处理单个文件的函数
|
|
33
|
+
function obfuscateFile(filePath) {
|
|
34
|
+
try {
|
|
35
|
+
const code = fs.readFileSync(filePath, 'utf8');
|
|
36
|
+
const obfuscationResult = JavaScriptObfuscator.obfuscate(code, obfuscatorOptions);
|
|
37
|
+
fs.writeFileSync(filePath, obfuscationResult.getObfuscatedCode());
|
|
38
|
+
// console.log(`成功混淆文件: ${filePath}`);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(`处理文件 ${filePath} 时出错:`, error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// 递归处理目录的函数
|
|
45
|
+
function processDirectory(directory) {
|
|
46
|
+
const files = fs.readdirSync(directory);
|
|
47
|
+
files.forEach(file => {
|
|
48
|
+
const fullPath = path.join(directory, file);
|
|
49
|
+
const stat = fs.statSync(fullPath);
|
|
50
|
+
if (stat.isDirectory()) {
|
|
51
|
+
processDirectory(fullPath);
|
|
52
|
+
}
|
|
53
|
+
else if (path.extname(file) === '.js') {
|
|
54
|
+
obfuscateFile(fullPath);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// 导出主函数
|
|
59
|
+
async function obfuscate() {
|
|
60
|
+
const distPath = path.join(process.cwd(), 'dist');
|
|
61
|
+
if (fs.existsSync(distPath)) {
|
|
62
|
+
console.log('开始混淆 dist 目录下的 JS 文件...');
|
|
63
|
+
processDirectory(distPath);
|
|
64
|
+
console.log('混淆完成!打包成功!');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.error('错误: dist 目录不存在!');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface FsCacheStoreOptions {
|
|
2
|
+
path?: string;
|
|
3
|
+
ttl?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* hlw 基于磁盘的缓存
|
|
7
|
+
*/
|
|
8
|
+
declare class FsCacheStore {
|
|
9
|
+
options: FsCacheStoreOptions;
|
|
10
|
+
store: any;
|
|
11
|
+
constructor(options?: FsCacheStoreOptions);
|
|
12
|
+
get(key: string): Promise<any>;
|
|
13
|
+
set(key: string, value: any, ttl?: number): Promise<void>;
|
|
14
|
+
del(key: string): Promise<void>;
|
|
15
|
+
reset(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare const HlwCacheStore: (options?: FsCacheStoreOptions) => FsCacheStore;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HlwCacheStore = void 0;
|
|
4
|
+
const FsStore = require("@hlw-midway/cache-manager-fs-hash");
|
|
5
|
+
/**
|
|
6
|
+
* hlw 基于磁盘的缓存
|
|
7
|
+
*/
|
|
8
|
+
class FsCacheStore {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
options = {
|
|
11
|
+
path: 'cache',
|
|
12
|
+
ttl: -1,
|
|
13
|
+
...options,
|
|
14
|
+
};
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.store = FsStore.create(options);
|
|
17
|
+
}
|
|
18
|
+
async get(key) {
|
|
19
|
+
return await this.store.get(key);
|
|
20
|
+
}
|
|
21
|
+
async set(key, value, ttl) {
|
|
22
|
+
let t = ttl ? ttl : this.options.ttl;
|
|
23
|
+
if (t > 0) {
|
|
24
|
+
t = t / 1000;
|
|
25
|
+
}
|
|
26
|
+
await this.store.set(key, value, { ttl: t });
|
|
27
|
+
}
|
|
28
|
+
async del(key) {
|
|
29
|
+
await this.store.del(key);
|
|
30
|
+
}
|
|
31
|
+
async reset() {
|
|
32
|
+
await this.store.reset();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const HlwCacheStore = function (options = {}) {
|
|
36
|
+
return new FsCacheStore(options);
|
|
37
|
+
};
|
|
38
|
+
exports.HlwCacheStore = HlwCacheStore;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* hlw的配置
|
|
5
|
+
*/
|
|
6
|
+
exports.default = {
|
|
7
|
+
hlw: {
|
|
8
|
+
// 是否自动导入数据库
|
|
9
|
+
initDB: false,
|
|
10
|
+
// 是否自动导入模块菜单
|
|
11
|
+
initMenu: true,
|
|
12
|
+
// 判断是否初始化的方式
|
|
13
|
+
initJudge: 'db',
|
|
14
|
+
// crud配置
|
|
15
|
+
crud: {
|
|
16
|
+
// 软删除
|
|
17
|
+
softDelete: true,
|
|
18
|
+
// 分页查询每页条数
|
|
19
|
+
pageSize: 15,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ILifeCycle, ILogger, IMidwayApplication, IMidwayContainer, MidwayWebRouterService } from '@midwayjs/core';
|
|
2
|
+
import * as koa from '@midwayjs/koa';
|
|
3
|
+
import { HlwEventManager } from './event';
|
|
4
|
+
export declare class HlwConfiguration implements ILifeCycle {
|
|
5
|
+
coreLogger: ILogger;
|
|
6
|
+
app: koa.Application;
|
|
7
|
+
hlwEventManager: HlwEventManager;
|
|
8
|
+
allConfig: any;
|
|
9
|
+
webRouterService: MidwayWebRouterService;
|
|
10
|
+
onReady(container: IMidwayContainer): Promise<void>;
|
|
11
|
+
onConfigLoad(container: IMidwayContainer, app: IMidwayApplication): Promise<void>;
|
|
12
|
+
onServerReady(container: IMidwayContainer): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* 事件初始化
|
|
15
|
+
*/
|
|
16
|
+
eventInit(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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.HlwConfiguration = void 0;
|
|
13
|
+
const core_1 = require("@midwayjs/core");
|
|
14
|
+
const core_2 = require("@midwayjs/core");
|
|
15
|
+
const DefaultConfig = require("./config/config.default");
|
|
16
|
+
const filter_1 = require("./exception/filter");
|
|
17
|
+
const func_1 = require("./util/func");
|
|
18
|
+
const koa = require("@midwayjs/koa");
|
|
19
|
+
const config_1 = require("./module/config");
|
|
20
|
+
const import_1 = require("./module/import");
|
|
21
|
+
const event_1 = require("./event");
|
|
22
|
+
const eps_1 = require("./rest/eps");
|
|
23
|
+
const decorator_1 = require("./decorator");
|
|
24
|
+
const cache = require("@midwayjs/cache-manager");
|
|
25
|
+
const location_1 = require("./util/location");
|
|
26
|
+
let HlwConfiguration = class HlwConfiguration {
|
|
27
|
+
async onReady(container) {
|
|
28
|
+
this.hlwEventManager.emit('onReady');
|
|
29
|
+
this.hlwEventManager.globalEmit('onReadyOnce', true);
|
|
30
|
+
// 处理模块配置
|
|
31
|
+
await container.getAsync(config_1.HlwModuleConfig);
|
|
32
|
+
// 常用函数处理
|
|
33
|
+
await container.getAsync(func_1.FuncUtil);
|
|
34
|
+
// 异常处理
|
|
35
|
+
this.app.useFilter([filter_1.HlwExceptionFilter]);
|
|
36
|
+
// 装饰器
|
|
37
|
+
await container.getAsync(decorator_1.HlwDecorator);
|
|
38
|
+
// 注册一个路由,用于处理静态资源
|
|
39
|
+
this.webRouterService.addRouter(async (ctx) => {
|
|
40
|
+
ctx.redirect('/index.html');
|
|
41
|
+
}, {
|
|
42
|
+
url: '/',
|
|
43
|
+
requestMethod: 'GET',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async onConfigLoad(container, app) {
|
|
47
|
+
await container.getAsync(location_1.LocationUtil);
|
|
48
|
+
// 替换app的getBaseDir
|
|
49
|
+
app.getBaseDir = () => {
|
|
50
|
+
return container.get(location_1.LocationUtil).getDistPath();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async onServerReady(container) {
|
|
54
|
+
// 事件
|
|
55
|
+
await (await container.getAsync(event_1.HlwEventManager)).init();
|
|
56
|
+
// 导入模块数据
|
|
57
|
+
(await container.getAsync(import_1.HlwModuleImport)).init();
|
|
58
|
+
// 实体与路径
|
|
59
|
+
const eps = await container.getAsync(eps_1.HlwEps);
|
|
60
|
+
eps.init();
|
|
61
|
+
await this.eventInit();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 事件初始化
|
|
65
|
+
*/
|
|
66
|
+
async eventInit() {
|
|
67
|
+
this.hlwEventManager.emit('onServerReady');
|
|
68
|
+
const env = this.app.getEnv();
|
|
69
|
+
const isMainProcess = process.env.NODE_APP_INSTANCE == '0';
|
|
70
|
+
if (env == 'local' || isMainProcess) {
|
|
71
|
+
this.hlwEventManager.globalEmit('onServerReadyOnce', true);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.HlwConfiguration = HlwConfiguration;
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, core_1.Logger)(),
|
|
78
|
+
__metadata("design:type", Object)
|
|
79
|
+
], HlwConfiguration.prototype, "coreLogger", void 0);
|
|
80
|
+
__decorate([
|
|
81
|
+
(0, core_1.App)(),
|
|
82
|
+
__metadata("design:type", Object)
|
|
83
|
+
], HlwConfiguration.prototype, "app", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
(0, core_1.Inject)(),
|
|
86
|
+
__metadata("design:type", event_1.HlwEventManager)
|
|
87
|
+
], HlwConfiguration.prototype, "hlwEventManager", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, core_1.Config)(core_1.ALL),
|
|
90
|
+
__metadata("design:type", Object)
|
|
91
|
+
], HlwConfiguration.prototype, "allConfig", void 0);
|
|
92
|
+
__decorate([
|
|
93
|
+
(0, core_1.Inject)(),
|
|
94
|
+
__metadata("design:type", core_1.MidwayWebRouterService)
|
|
95
|
+
], HlwConfiguration.prototype, "webRouterService", void 0);
|
|
96
|
+
exports.HlwConfiguration = HlwConfiguration = __decorate([
|
|
97
|
+
(0, core_2.Configuration)({
|
|
98
|
+
namespace: 'hlw',
|
|
99
|
+
imports: [cache],
|
|
100
|
+
importConfigs: [
|
|
101
|
+
{
|
|
102
|
+
default: DefaultConfig,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
})
|
|
106
|
+
], HlwConfiguration);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 返回码
|
|
3
|
+
*/
|
|
4
|
+
export declare enum RESCODE {
|
|
5
|
+
SUCCESS = 1000,
|
|
6
|
+
COMMFAIL = 1001,
|
|
7
|
+
VALIDATEFAIL = 1002,
|
|
8
|
+
COREFAIL = 1003
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 返回信息
|
|
12
|
+
*/
|
|
13
|
+
export declare enum RESMESSAGE {
|
|
14
|
+
SUCCESS = "success",
|
|
15
|
+
COMMFAIL = "comm fail",
|
|
16
|
+
VALIDATEFAIL = "validate fail",
|
|
17
|
+
COREFAIL = "core fail"
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 错误提示
|
|
21
|
+
*/
|
|
22
|
+
export declare enum ERRINFO {
|
|
23
|
+
NOENTITY = "\u672A\u8BBE\u7F6E\u64CD\u4F5C\u5B9E\u4F53",
|
|
24
|
+
NOID = "\u67E5\u8BE2\u53C2\u6570[id]\u4E0D\u5B58\u5728",
|
|
25
|
+
SORTFIELD = "\u6392\u5E8F\u53C2\u6570\u4E0D\u6B63\u786E",
|
|
26
|
+
NOTFOUND = "\u6570\u636E\u4E0D\u5B58\u5728~"
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 国际化服务
|
|
30
|
+
*/
|
|
31
|
+
export declare const I18N: {
|
|
32
|
+
DEFAULT_SERVICE_URL: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* 事件
|
|
36
|
+
*/
|
|
37
|
+
export declare enum EVENT {
|
|
38
|
+
SOFT_DELETE = "onSoftDelete",
|
|
39
|
+
SERVER_READY = "onServerReady",
|
|
40
|
+
READY = "onReady",
|
|
41
|
+
ES_DATA_CHANGE = "esDataChange"
|
|
42
|
+
}
|
|
43
|
+
export declare class GlobalConfig {
|
|
44
|
+
private static instance;
|
|
45
|
+
RESCODE: {
|
|
46
|
+
SUCCESS: number;
|
|
47
|
+
COMMFAIL: number;
|
|
48
|
+
VALIDATEFAIL: number;
|
|
49
|
+
COREFAIL: number;
|
|
50
|
+
};
|
|
51
|
+
RESMESSAGE: {
|
|
52
|
+
SUCCESS: string;
|
|
53
|
+
COMMFAIL: string;
|
|
54
|
+
VALIDATEFAIL: string;
|
|
55
|
+
COREFAIL: string;
|
|
56
|
+
};
|
|
57
|
+
private constructor();
|
|
58
|
+
static getInstance(): GlobalConfig;
|
|
59
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GlobalConfig = exports.EVENT = exports.I18N = exports.ERRINFO = exports.RESMESSAGE = exports.RESCODE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 返回码
|
|
6
|
+
*/
|
|
7
|
+
var RESCODE;
|
|
8
|
+
(function (RESCODE) {
|
|
9
|
+
// 成功
|
|
10
|
+
RESCODE[RESCODE["SUCCESS"] = 1000] = "SUCCESS";
|
|
11
|
+
// 失败
|
|
12
|
+
RESCODE[RESCODE["COMMFAIL"] = 1001] = "COMMFAIL";
|
|
13
|
+
// 参数验证失败
|
|
14
|
+
RESCODE[RESCODE["VALIDATEFAIL"] = 1002] = "VALIDATEFAIL";
|
|
15
|
+
// 参数验证失败
|
|
16
|
+
RESCODE[RESCODE["COREFAIL"] = 1003] = "COREFAIL";
|
|
17
|
+
})(RESCODE || (exports.RESCODE = RESCODE = {}));
|
|
18
|
+
/**
|
|
19
|
+
* 返回信息
|
|
20
|
+
*/
|
|
21
|
+
var RESMESSAGE;
|
|
22
|
+
(function (RESMESSAGE) {
|
|
23
|
+
// 成功
|
|
24
|
+
RESMESSAGE["SUCCESS"] = "success";
|
|
25
|
+
// 失败
|
|
26
|
+
RESMESSAGE["COMMFAIL"] = "comm fail";
|
|
27
|
+
// 参数验证失败
|
|
28
|
+
RESMESSAGE["VALIDATEFAIL"] = "validate fail";
|
|
29
|
+
// 核心异常
|
|
30
|
+
RESMESSAGE["COREFAIL"] = "core fail";
|
|
31
|
+
})(RESMESSAGE || (exports.RESMESSAGE = RESMESSAGE = {}));
|
|
32
|
+
/**
|
|
33
|
+
* 错误提示
|
|
34
|
+
*/
|
|
35
|
+
var ERRINFO;
|
|
36
|
+
(function (ERRINFO) {
|
|
37
|
+
ERRINFO["NOENTITY"] = "\u672A\u8BBE\u7F6E\u64CD\u4F5C\u5B9E\u4F53";
|
|
38
|
+
ERRINFO["NOID"] = "\u67E5\u8BE2\u53C2\u6570[id]\u4E0D\u5B58\u5728";
|
|
39
|
+
ERRINFO["SORTFIELD"] = "\u6392\u5E8F\u53C2\u6570\u4E0D\u6B63\u786E";
|
|
40
|
+
ERRINFO["NOTFOUND"] = "\u6570\u636E\u4E0D\u5B58\u5728~";
|
|
41
|
+
})(ERRINFO || (exports.ERRINFO = ERRINFO = {}));
|
|
42
|
+
/**
|
|
43
|
+
* 国际化服务
|
|
44
|
+
*/
|
|
45
|
+
exports.I18N = {
|
|
46
|
+
DEFAULT_SERVICE_URL: 'https://www.baidu.com',
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* 事件
|
|
50
|
+
*/
|
|
51
|
+
var EVENT;
|
|
52
|
+
(function (EVENT) {
|
|
53
|
+
// 软删除
|
|
54
|
+
EVENT["SOFT_DELETE"] = "onSoftDelete";
|
|
55
|
+
// 服务成功启动
|
|
56
|
+
EVENT["SERVER_READY"] = "onServerReady";
|
|
57
|
+
// 服务就绪
|
|
58
|
+
EVENT["READY"] = "onReady";
|
|
59
|
+
// ES 数据改变
|
|
60
|
+
EVENT["ES_DATA_CHANGE"] = "esDataChange";
|
|
61
|
+
})(EVENT || (exports.EVENT = EVENT = {}));
|
|
62
|
+
class GlobalConfig {
|
|
63
|
+
// ... 其他的配置 ...
|
|
64
|
+
constructor() {
|
|
65
|
+
this.RESCODE = {
|
|
66
|
+
SUCCESS: 1000,
|
|
67
|
+
COMMFAIL: 1001,
|
|
68
|
+
VALIDATEFAIL: 1002,
|
|
69
|
+
COREFAIL: 1003,
|
|
70
|
+
};
|
|
71
|
+
this.RESMESSAGE = {
|
|
72
|
+
SUCCESS: 'success',
|
|
73
|
+
COMMFAIL: 'comm fail',
|
|
74
|
+
VALIDATEFAIL: 'validate fail',
|
|
75
|
+
COREFAIL: 'core fail',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
static getInstance() {
|
|
79
|
+
if (!GlobalConfig.instance) {
|
|
80
|
+
GlobalConfig.instance = new GlobalConfig();
|
|
81
|
+
}
|
|
82
|
+
return GlobalConfig.instance;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.GlobalConfig = GlobalConfig;
|