mirror of
https://github.com/cool-team-official/cool-admin-midway-packages.git
synced 2025-12-27 09:00:17 +00:00
兼容MIdway最新的启动方式,修复多数据源报错
This commit is contained in:
parent
af0ee28433
commit
ce91a3f16d
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cool-midway/core",
|
||||
"version": "7.1.8",
|
||||
"version": "7.1.10",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"typings": "index.d.ts",
|
||||
@ -28,28 +28,28 @@
|
||||
"url": "https://cool-js.com"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@midwayjs/cli": "1.3.21",
|
||||
"@midwayjs/core": "^3.9.0",
|
||||
"@midwayjs/decorator": "^3.9.0",
|
||||
"@midwayjs/koa": "^3.9.0",
|
||||
"@midwayjs/mock": "^3.9.0",
|
||||
"@midwayjs/typeorm": "^3.9.0",
|
||||
"@midwayjs/cli": "2.1.1",
|
||||
"@midwayjs/core": "^3.15.0",
|
||||
"@midwayjs/decorator": "^3.15.0",
|
||||
"@midwayjs/koa": "^3.15.2",
|
||||
"@midwayjs/mock": "^3.15.2",
|
||||
"@midwayjs/typeorm": "^3.15.2",
|
||||
"@types/download": "^8.0.5",
|
||||
"@types/jest": "^29.2.4",
|
||||
"@types/node": "^18.11.15",
|
||||
"aedes": "^0.48.1",
|
||||
"@types/jest": "^29.5.12",
|
||||
"@types/node": "^20.11.30",
|
||||
"aedes": "^0.51.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"jest": "^29.3.1",
|
||||
"jest": "^29.7.0",
|
||||
"mwts": "^1.3.0",
|
||||
"ts-jest": "^29.0.3",
|
||||
"typeorm": "^0.3.19",
|
||||
"typescript": "~4.9.4"
|
||||
"ts-jest": "^29.1.2",
|
||||
"typeorm": "^0.3.20",
|
||||
"typescript": "~5.4.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@cool-midway/cache-manager-fs-hash": "^7.0.0",
|
||||
"@midwayjs/cache": "^3.14.0",
|
||||
"@midwayjs/cache-manager": "^3.15.0",
|
||||
"axios": "^1.6.5",
|
||||
"@midwayjs/cache-manager": "^3.15.2",
|
||||
"axios": "^1.6.8",
|
||||
"decompress": "^4.2.1",
|
||||
"download": "^8.0.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
|
||||
@ -55,9 +55,7 @@ export class CoolConfiguration implements ILifeCycle {
|
||||
this.app.useFilter([CoolExceptionFilter]);
|
||||
// 装饰器
|
||||
await container.getAsync(CoolDecorator);
|
||||
// 实体与路径
|
||||
const eps: CoolEps = await container.getAsync(CoolEps);
|
||||
eps.init();
|
||||
|
||||
// 缓存设置为全局
|
||||
// global["COOL-CACHE"] = await container.getAsync(CacheManager);
|
||||
// 清除 location
|
||||
@ -72,7 +70,10 @@ export class CoolConfiguration implements ILifeCycle {
|
||||
mainApp?: IMidwayBaseApplication<Context>
|
||||
) {}
|
||||
|
||||
async onServerReady() {
|
||||
async onServerReady(container: IMidwayContainer) {
|
||||
// 实体与路径
|
||||
const eps: CoolEps = await container.getAsync(CoolEps);
|
||||
eps.init();
|
||||
this.coolEventManager.emit("onServerReady");
|
||||
location.clean();
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { MiddlewareParamArray } from "@midwayjs/core";
|
||||
import { AedesOptions } from "aedes";
|
||||
// @ts-ignore
|
||||
import { PublishPacket } from "packet";
|
||||
|
||||
/**
|
||||
@ -20,7 +21,7 @@ export interface ModuleConfig {
|
||||
|
||||
export interface CoolConfig {
|
||||
/** 短信 */
|
||||
sms?: CoolSmsConfig,
|
||||
sms?: CoolSmsConfig;
|
||||
/** 是否自动导入数据库 */
|
||||
initDB?: boolean;
|
||||
/** Eps */
|
||||
@ -38,7 +39,7 @@ export interface CoolConfig {
|
||||
/** 分页查询每页条数 */
|
||||
pageSize: number;
|
||||
/** 插入方式 */
|
||||
upsert : 'normal' | 'save'
|
||||
upsert: "normal" | "save";
|
||||
// 多租户
|
||||
// tenant: boolean;
|
||||
};
|
||||
@ -221,7 +222,7 @@ export interface AWSConfig {
|
||||
/** conditions */
|
||||
conditions?: any[];
|
||||
/** expires */
|
||||
expires?: number
|
||||
expires?: number;
|
||||
/** publicDomain */
|
||||
publicDomain?: string;
|
||||
/** forcePathStyle */
|
||||
@ -339,7 +340,6 @@ export interface CoolIotConfig {
|
||||
serve?: AedesOptions;
|
||||
}
|
||||
|
||||
|
||||
export interface CoolSmsConfig {
|
||||
/**
|
||||
* 阿里云短信配置
|
||||
@ -443,4 +443,3 @@ export interface CoolSmsYpConfig {
|
||||
*/
|
||||
template?: string;
|
||||
}
|
||||
|
||||
|
||||
@ -44,9 +44,9 @@ export class CoolModuleConfig {
|
||||
const modulePath = `${moduleBasePath}/${module}`;
|
||||
const dirStats = fs.statSync(modulePath);
|
||||
if (dirStats.isDirectory()) {
|
||||
const configPath = `${modulePath}/config.${
|
||||
this.app.getEnv() == "local" ? "ts" : "js"
|
||||
}`;
|
||||
const configPath = fs.existsSync(`${modulePath}/config.ts`)
|
||||
? `${modulePath}/config.ts`
|
||||
: `${modulePath}/config.js`;
|
||||
if (fs.existsSync(configPath)) {
|
||||
const moduleConfig: ModuleConfig = require(configPath).default({
|
||||
app: this.app,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cool-midway/core",
|
||||
"version": "7.1.8",
|
||||
"version": "7.1.10",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"typings": "index.d.ts",
|
||||
|
||||
@ -3,11 +3,15 @@ import {
|
||||
getClassMetadata,
|
||||
listModule,
|
||||
Provide,
|
||||
Scope,
|
||||
ScopeEnum,
|
||||
} from "@midwayjs/decorator";
|
||||
import * as _ from "lodash";
|
||||
import { Config, Inject, MidwayWebRouterService } from "@midwayjs/core";
|
||||
import {
|
||||
Scope,
|
||||
ScopeEnum,
|
||||
Config,
|
||||
Inject,
|
||||
MidwayWebRouterService,
|
||||
} from "@midwayjs/core";
|
||||
import { TypeORMDataSourceManager } from "@midwayjs/typeorm";
|
||||
import { CoolUrlTagData } from "../tag/data";
|
||||
import { TagTypes } from "../decorator/tag";
|
||||
@ -30,10 +34,10 @@ export class CoolEps {
|
||||
@Inject()
|
||||
typeORMDataSourceManager: TypeORMDataSourceManager;
|
||||
|
||||
@Config('cool.eps')
|
||||
@Config("cool.eps")
|
||||
epsConfig: boolean;
|
||||
|
||||
@Config('module')
|
||||
@Config("module")
|
||||
moduleConfig: any;
|
||||
|
||||
@Inject()
|
||||
@ -41,7 +45,7 @@ export class CoolEps {
|
||||
|
||||
// @Init()
|
||||
async init() {
|
||||
if(!this.epsConfig) return;
|
||||
if (!this.epsConfig) return;
|
||||
const entitys = await this.entity();
|
||||
const controllers = await this.controller();
|
||||
const routers = await this.router();
|
||||
@ -54,10 +58,10 @@ export class CoolEps {
|
||||
(_.startsWith(prefix, "/admin/") ? adminArr : appArr).push({
|
||||
module,
|
||||
info: {
|
||||
type: {
|
||||
name: prefix.split("/").pop(),
|
||||
description: routerOptions?.description || "" ,
|
||||
},
|
||||
type: {
|
||||
name: prefix.split("/").pop(),
|
||||
description: routerOptions?.description || "",
|
||||
},
|
||||
},
|
||||
api: routers[prefix],
|
||||
name,
|
||||
@ -71,17 +75,17 @@ export class CoolEps {
|
||||
|
||||
/**
|
||||
* 模块信息
|
||||
* @param module
|
||||
* @param module
|
||||
*/
|
||||
async modules(module?: string) {
|
||||
for(const key in this.moduleConfig){
|
||||
for (const key in this.moduleConfig) {
|
||||
const config = this.moduleConfig[key];
|
||||
this.module[key] = {
|
||||
name: config.name,
|
||||
description: config.description,
|
||||
}
|
||||
};
|
||||
}
|
||||
return module? this.module[module]: this.module;
|
||||
return module ? this.module[module] : this.module;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,11 +107,11 @@ export class CoolEps {
|
||||
*/
|
||||
async router() {
|
||||
let ignoreUrls: string[] = this.coolUrlTagData.byKey(TagTypes.IGNORE_TOKEN);
|
||||
if(_.isEmpty(ignoreUrls)){
|
||||
if (_.isEmpty(ignoreUrls)) {
|
||||
ignoreUrls = [];
|
||||
}
|
||||
return _.groupBy(
|
||||
(await await this.midwayWebRouterService.getFlattenRouterTable()).map(
|
||||
(await this.midwayWebRouterService.getFlattenRouterTable()).map(
|
||||
(item) => {
|
||||
return {
|
||||
method: item.requestMethod,
|
||||
@ -116,7 +120,7 @@ export class CoolEps {
|
||||
dts: {},
|
||||
tag: "",
|
||||
prefix: item.prefix,
|
||||
ignoreToken: ignoreUrls.includes(item.prefix+item.url),
|
||||
ignoreToken: ignoreUrls.includes(item.prefix + item.url),
|
||||
};
|
||||
}
|
||||
),
|
||||
@ -138,7 +142,7 @@ export class CoolEps {
|
||||
for (const entityMetadata of entityMetadatas) {
|
||||
const commColums = [];
|
||||
let columns = entityMetadata.columns;
|
||||
if(entityMetadata.tableType != 'regular') continue;
|
||||
if (entityMetadata.tableType != "regular") continue;
|
||||
columns = _.filter(
|
||||
columns.map((e) => {
|
||||
return {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user