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