Skip to content

Commit

Permalink
docs: update 3.17
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Aug 30, 2024
1 parent 21faf25 commit f5809e5
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 12 deletions.
1 change: 0 additions & 1 deletion scripts/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const data = JSON.parse(originData);
const finished = [];

async function syncPackage(pkg) {
await execa('tnpm', ['sync', pkg]);
await execa('cnpm', ['sync', pkg]);
finished.push(pkg);
console.log(`[${finished.length}/${data.length}] ${pkg} sync finished`);
Expand Down
10 changes: 0 additions & 10 deletions scripts/sync_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@ const execa = require('execa');
const originData = execSync('npx lerna ls --json').toString();
const data = JSON.parse(originData);

const failed = [];
const cnpmFailed = [];
const finished = [];

async function checkSyncStatus(pkg) {
const npmVersion = await execa('npm', ['show', pkg, 'version']);
const tnpmVersion = await execa('tnpm', ['show', pkg, 'version']);
const cnpmVersion = await execa('cnpm', ['show', pkg, 'version']);

finished.push(pkg);
console.log(`[${finished.length}/${data.length}] ---->`, pkg);
if (npmVersion.stdout !== tnpmVersion.stdout) {
console.log(`===> npm: ${npmVersion.stdout}, tnpm: ${tnpmVersion.stdout}`);
failed.push(pkg);
}
if (npmVersion.stdout !== cnpmVersion.stdout) {
console.log(`===> npm: ${npmVersion.stdout}, cnpm: ${cnpmVersion.stdout}`);
cnpmFailed.push(pkg);
Expand All @@ -33,10 +27,6 @@ async function start() {
const task = packages.map((pkg) => checkSyncStatus(pkg));
await Promise.all(task);

if (failed.length) {
console.log(`output command => tnpm sync ${failed.join(' ')}`);
}

if (cnpmFailed.length) {
console.log(`output command => cnpm sync ${cnpmFailed.join(' ')}`);
}
Expand Down
2 changes: 1 addition & 1 deletion site/blog/2024-05-07-release-3.16.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ class Photo {
* 修复了一个健康检查服务丢失 this 的问题
* 参数装饰器增加了一个当前实例的参数

以及一大批依赖进行了更新,可以参考我们的 [ChangeLog](https://midwayjs.org/changelog/v3.15.0)
以及一大批依赖进行了更新,可以参考我们的 [ChangeLog](https://midwayjs.org/changelog/v3.16.0)
103 changes: 103 additions & 0 deletions site/blog/2024-08-29-release-3.17.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
slug: release/3.17.0
title: Release 3.17.0
authors: [harry]
tags: [release]


---

升级请参考 [如何更新 Midway](/docs/how_to_update_midway) 中描述,请不要单独升级某个组件包。

本次 3.17 版本,我们增加了一些新的特性,以及修复了一些问题。


## 定制服务端响应格式

在 3.17 版本中,我们增加了一个新的特性,可以定制服务端的响应的通用格式。

在之前的版本中,我们依靠中间件和过滤器来实现这个功能,但是这种方式有一些局限性,代码也会分散在不同的地方。

如果由一个统一的可调整的返回逻辑,可能更为合理,为此,添加了 `ServerResponse``HttpServerResponse` 的实现。

```typescript
import { ServerResponse, HttpServerResponse } from '@midwayjs/core';

@Controller()
export class HomeController {
@Inject()
ctx: Context;

@Get('/')
async index() {
return new HttpServerResponse(this.ctx).json({
success: true,
data: 'hello world',
});
}
}
```

`HttpServerResponse``ServerResponse` 的一个 Http 实现,提供了一些常用的方法。

最为特殊的是他可以针对不同的数据格式,设置成功和失败的模版。

比如针对 JSON 数据,框架提供了以下的默认结构。

```typescript
HttpServerResponse.JSON_TPL = (data, isSuccess) => {
if (isSuccess) {
return {
success: 'true',
data,
};
} else {
return {
success: 'false',
message: data || 'fail',
};
}
};
```

这样,当返回 JSON 格式时,就会按照这个模版进行返回。

```typescript
// 失败的返回
return new HttpServerResponse(this.ctx).fail().json('hello world');
```

就会获取到以下的数据。

```typescript
{
success: 'false',
message: 'hello world',
}
```

此外,基于这个模式,也同时实现了 SSE 的响应返回。


## 上传组件

由于在小文件场景下上传碰到一些问题,从 v3.17 开始,基于 [busboy](https://github.com/mscdex/busboy) 实现了一个新的上传组件,替换原有的 `@midwayjs/upload`

和原有的组件比有一些不同。

* 1、不再默认加载中间件,因为上传只是少部分接口的特殊逻辑,不需要全局加载
* 2、配置的 key 为了避免冲突,从 `upload` 变为 `busboy`
* 3、原有上传的数据中的 `filedName`,在流式模式下不再提供

其余的使用方式和原有的上传组件一致,

更多细节请访问 [文档](/docs/extensions/busboy)



## 更多的变化

* 修复了一个健康检查服务丢失 this 的问题
* 参数装饰器增加了一个当前实例的参数

以及一大批依赖进行了更新,可以参考我们的 [ChangeLog](https://midwayjs.org/changelog/v3.17.0)

0 comments on commit f5809e5

Please sign in to comment.