From ce91a3f16d8c65bb1cac0af8017c83cd86fd17ce Mon Sep 17 00:00:00 2001 From: cool Date: Wed, 20 Mar 2024 11:43:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9MIdway=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E5=90=AF=E5=8A=A8=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=A4=9A=E6=95=B0=E6=8D=AE=E6=BA=90=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/package.json | 32 +++++++++++++++---------------- core/src/configuration.ts | 9 +++++---- core/src/interface.ts | 9 ++++----- core/src/module/config.ts | 6 +++--- core/src/package.json | 2 +- core/src/rest/eps.ts | 40 +++++++++++++++++++++------------------ 6 files changed, 51 insertions(+), 47 deletions(-) diff --git a/core/package.json b/core/package.json index 115eb2f..f2015f1 100644 --- a/core/package.json +++ b/core/package.json @@ -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", diff --git a/core/src/configuration.ts b/core/src/configuration.ts index 624fd11..74cd5a9 100644 --- a/core/src/configuration.ts +++ b/core/src/configuration.ts @@ -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 ) {} - async onServerReady() { + async onServerReady(container: IMidwayContainer) { + // 实体与路径 + const eps: CoolEps = await container.getAsync(CoolEps); + eps.init(); this.coolEventManager.emit("onServerReady"); location.clean(); } diff --git a/core/src/interface.ts b/core/src/interface.ts index a9f8f46..416d79b 100644 --- a/core/src/interface.ts +++ b/core/src/interface.ts @@ -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; } - diff --git a/core/src/module/config.ts b/core/src/module/config.ts index 9e2f9c0..3f579ef 100644 --- a/core/src/module/config.ts +++ b/core/src/module/config.ts @@ -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, diff --git a/core/src/package.json b/core/src/package.json index 3e410cf..042cf38 100644 --- a/core/src/package.json +++ b/core/src/package.json @@ -1,6 +1,6 @@ { "name": "@cool-midway/core", - "version": "7.1.8", + "version": "7.1.10", "description": "", "main": "index.js", "typings": "index.d.ts", diff --git a/core/src/rest/eps.ts b/core/src/rest/eps.ts index 8def106..26c9694 100644 --- a/core/src/rest/eps.ts +++ b/core/src/rest/eps.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 {