Skip to content

Commit dd93e36

Browse files
authored
merge: release v0.10.0 (#962)
2 parents f8e00f3 + fe049f7 commit dd93e36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+13389
-11249
lines changed

.eslintrc.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extends:
1212
- 'plugin:@typescript-eslint/recommended-requiring-type-checking'
1313
- 'plugin:jest/recommended'
1414
- 'prettier'
15-
- 'prettier/@typescript-eslint'
1615
rules:
1716
'@typescript-eslint/explicit-member-accessibility': off
1817
'@typescript-eslint/no-angle-bracket-type-assertion': off
@@ -32,3 +31,5 @@ rules:
3231
'@typescript-eslint/no-unsafe-call': off
3332
'@typescript-eslint/no-unsafe-member-access': off
3433
'@typescript-eslint/explicit-module-boundary-types': off
34+
'@typescript-eslint/no-unsafe-argument': off
35+
'@typescript-eslint/no-var-requires': off

.github/workflows/continuous-deployment-workflow.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ jobs:
77
name: Publish to NPM
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v1
11-
- uses: actions/setup-node@v1
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-node@v3
1212
with:
13+
node-version: 'lts/*'
1314
registry-url: https://registry.npmjs.org
1415
- run: npm ci --ignore-scripts
1516
- run: npm run prettier:check
@@ -23,4 +24,4 @@ jobs:
2324
- run: jq 'del(.devDependencies) | del(.scripts)' package.json > build/package.json
2425
- run: npm publish ./build
2526
env:
26-
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
27+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

.github/workflows/continuous-integration-workflow.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ jobs:
55
name: Linters
66
runs-on: ubuntu-latest
77
steps:
8-
- uses: actions/checkout@v1
9-
- uses: actions/setup-node@v1
8+
- uses: actions/checkout@v3
9+
- uses: actions/setup-node@v3
10+
with:
11+
node-version: 'lts/*'
1012
- run: npm ci --ignore-scripts
1113
- run: npm run prettier:check
1214
- run: npm run lint:check
@@ -15,27 +17,29 @@ jobs:
1517
runs-on: ubuntu-latest
1618
strategy:
1719
matrix:
18-
node-version: ['10.x', '12.x', '14.x']
20+
node-version: ['lts/*', 'current']
1921
fail-fast: false
2022
steps:
21-
- uses: actions/checkout@v1
23+
- uses: actions/checkout@v3
2224
- name: Setting up Node.js (v${{ matrix.node-version }}.x)
23-
uses: actions/setup-node@v1
25+
uses: actions/setup-node@v3
2426
with:
2527
node-version: ${{ matrix.node-version }}
2628
- run: npm ci --ignore-scripts
2729
- run: npm run test:ci
2830
- run: npm install codecov -g
29-
if: ${{ matrix.node-version == '14.x' }}
31+
if: ${{ matrix.node-version == 'current' }}
3032
- run: codecov -f ./coverage/clover.xml -t ${{ secrets.CODECOV_TOKEN }} --commit=$GITHUB_SHA --branch=${GITHUB_REF##*/}
31-
if: ${{ matrix.node-version == '14.x' }}
33+
if: ${{ matrix.node-version == 'current' }}
3234
build:
3335
name: Build
3436
runs-on: ubuntu-latest
3537
steps:
36-
- uses: actions/checkout@v1
37-
- uses: actions/setup-node@v1
38+
- uses: actions/checkout@v3
39+
- uses: actions/setup-node@v3
40+
with:
41+
node-version: 'lts/*'
3842
- run: npm ci --ignore-scripts
3943
- run: npm run build:es2015
4044
- run: npm run build:cjs
41-
- run: npm run build:types
45+
- run: npm run build:types

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
# Changelog and release notes
22

3+
## [0.10.0](https://github.com/typestack/routing-controllers/compare/v0.9.0...v0.10.0) (2022-12-9)
4+
5+
### Added
6+
7+
- `isArray` option for `@QueryParam`
8+
9+
### Changed
10+
11+
- `class-transformer` package updated to `0.5.1` from `0.3.1`
12+
- `class-validator` package updated to `0.13.2` from `0.12.2`
13+
- `cookie` package updated to `0.5.0` from `0.4.0`
14+
- `glob` package updated to `8.0.3` from `7.1.4`
15+
- `express` package updated to `4.18.2` from `4.17.1` and moved to `optionalDependencies`
16+
- `express-session` package updated to `1.17.1` from `1.17.3` and moved to `optionalDependencies`
17+
- `body-parser` package updated to `1.20.1` from `1.19.0`
18+
- `multer` package updated to `1.4.4` from `1.4.2`
19+
- `koa` package updated to `2.13.4` from `2.8.2`
20+
- `koa-multer` package replaced with `@koa/multer`
21+
- `koa-router` package replaced with `@koa/router`
22+
- updated various dev dependencies
23+
24+
### Fixed
25+
26+
- Fixed parsing uuid as route parameter
27+
- Fixed `target` property not set during controller inheritance
28+
- Fixed `NaN` check for number route parameters
29+
- Added missing null value handling in parameters
30+
- Fixed middlewares not using the defined route prefix
31+
332
### 0.9.0
433

534
#### Features

README.md

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
[![npm version](https://badge.fury.io/js/routing-controllers.svg)](https://badge.fury.io/js/routing-controllers)
66
[![Dependency Status](https://david-dm.org/typestack/routing-controllers.svg)](https://david-dm.org/typestack/routing-controllers)
77

8-
<center>
9-
<span>English</span> |
10-
[中文](./docs/lang/chinese/README.md)
11-
</center>
8+
English | [中文](./docs/lang/chinese/README.md)
129

1310
Allows to create controller classes with methods as actions that handle requests.
1411
You can use routing-controllers with [express.js][1] or [koa.js][2].
@@ -87,8 +84,9 @@ You can use routing-controllers with [express.js][1] or [koa.js][2].
8784

8885
and make sure to import it before you use routing-controllers:
8986

90-
```typescript
91-
```
87+
```typescript
88+
import 'reflect-metadata';
89+
```
9290

9391
3. Install framework:
9492

@@ -102,11 +100,11 @@ You can use routing-controllers with [express.js][1] or [koa.js][2].
102100

103101
**b. If you want to use routing-controllers with _koa 2_, then install it and all required dependencies:**
104102

105-
`npm install koa koa-router koa-bodyparser koa-multer`
103+
`npm install koa @koa/router koa-bodyparser @koa/multer`
106104

107105
Optionally you can also install their typings:
108106

109-
`npm install -D @types/koa @types/koa-router @types/koa-bodyparser`
107+
`npm install -D @types/koa @types/koa-bodyparser`
110108

111109
4. Install peer dependencies:
112110

@@ -321,9 +319,10 @@ You can load all controllers from directories, by specifying array of directorie
321319

322320
```typescript
323321
import { createExpressServer } from 'routing-controllers';
322+
import path from 'path';
324323

325324
createExpressServer({
326-
controllers: [__dirname + '/controllers/*.js'],
325+
controllers: [path.join(__dirname + '/controllers/*.js')],
327326
}).listen(3000); // register controllers routes in our express application
328327
```
329328

@@ -378,8 +377,30 @@ getUsers(@QueryParam("limit") limit: number) {
378377
}
379378
```
380379

380+
You can use `isArray` option to get a query param array. This will cast the query param :
381+
382+
```typescript
383+
@Get("/users/by-multiple-ids")
384+
getUsers(@QueryParam("ids", { isArray: true}) ids: string[]) {
385+
}
386+
```
387+
388+
`GET /users/by-multiple-ids?ids=a``ids = ['a']`
389+
`GET /users/by-multiple-ids?ids=a&ids=b``ids = ['a', 'b']`
390+
391+
You can combine use `isArray` option with `type` option to get a query param array of one type. This will cast the query param :
392+
393+
```typescript
394+
@Get("/users/by-multiple-ids")
395+
getUsers(@QueryParam("ids", { isArray: true, type: Number}) ids: number[]) {
396+
}
397+
```
398+
399+
`GET /users/by-multiple-ids?ids=1``ids = [1]`
400+
`GET /users/by-multiple-ids?ids=1&ids=3.5``ids = [1, 3.5]`
401+
381402
If you want to inject all query parameters use `@QueryParams()` decorator.
382-
The bigest benefit of this approach is that you can perform validation of the params.
403+
The biggest benefit of this approach is that you can perform validation of the params.
383404

384405
```typescript
385406
enum Roles {
@@ -402,12 +423,17 @@ class GetUsersQuery {
402423
@IsBoolean()
403424
isActive: boolean;
404425

426+
@IsArray()
427+
@IsNumber(undefined, { each: true })
428+
@Type(() => Number)
429+
ids: number[];
405430
}
406431

407432
@Get("/users")
408433
getUsers(@QueryParams() query: GetUsersQuery) {
409434
// here you can access query.role, query.limit
410435
// and others valid query parameters
436+
// query.ids will be an array, of numbers, even with one element
411437
}
412438
```
413439

@@ -510,7 +536,7 @@ You can also specify uploading options to multer this way:
510536

511537
```typescript
512538
// to keep code clean better to extract this function into separate file
513-
export const fileUploadOptions = () => {
539+
export const fileUploadOptions = () => ({
514540
storage: multer.diskStorage({
515541
destination: (req: any, file: any, cb: any) => { ...
516542
},
@@ -523,7 +549,7 @@ export const fileUploadOptions = () => {
523549
fieldNameSize: 255,
524550
fileSize: 1024 * 1024 * 2
525551
}
526-
};
552+
});
527553

528554
// use options this way:
529555
@Post("/files")
@@ -782,7 +808,7 @@ app.listen(3000);
782808
```
783809

784810
To use cors you need to install its module.
785-
For express its `npm i cors`, for koa its `npm i kcors`.
811+
For express its `npm i cors`, for koa its `npm i @koa/cors`.
786812
You can pass cors options as well:
787813

788814
```typescript
@@ -1089,10 +1115,12 @@ Also you can load middlewares from directories. Also you can use glob patterns:
10891115

10901116
```typescript
10911117
import { createExpressServer } from 'routing-controllers';
1118+
import path from 'path';
1119+
10921120
createExpressServer({
1093-
controllers: [__dirname + '/controllers/**/*.js'],
1094-
middlewares: [__dirname + '/middlewares/**/*.js'],
1095-
interceptors: [__dirname + '/interceptors/**/*.js'],
1121+
controllers: [path.join(__dirname, '/controllers/**/*.js')],
1122+
middlewares: [path.join(__dirname, '/middlewares/**/*.js')],
1123+
interceptors: [path.join(__dirname, '/interceptors/**/*.js')],
10961124
}).listen(3000);
10971125
```
10981126

@@ -1215,7 +1243,7 @@ If you want to disable it simply pass `classTransformer: false` to createExpress
12151243

12161244
## Controller Inheritance
12171245

1218-
Often your application may need to have an option to inherit controller from another to reuse code and void duplication.
1246+
Often your application may need to have an option to inherit controller from another to reuse code and avoid duplication.
12191247
A good example of the use is the CRUD operations which can be hidden inside `AbstractBaseController` with the possibility to add new and overload methods, the template method pattern.
12201248

12211249
```typescript
@@ -1227,7 +1255,7 @@ abstract class AbstractControllerTemplate {
12271255
@Post()
12281256
public create() {}
12291257

1230-
@Read()
1258+
@Get()
12311259
public read() {}
12321260

12331261
@Put()
@@ -1385,16 +1413,17 @@ Here is example how to integrate routing-controllers with [typedi](https://githu
13851413
```typescript
13861414
import { createExpressServer, useContainer } from 'routing-controllers';
13871415
import { Container } from 'typedi';
1416+
import path from 'path';
13881417

13891418
// its important to set container before any operation you do with routing-controllers,
13901419
// including importing controllers
13911420
useContainer(Container);
13921421

13931422
// create and run server
13941423
createExpressServer({
1395-
controllers: [__dirname + '/controllers/*.js'],
1396-
middlewares: [__dirname + '/middlewares/*.js'],
1397-
interceptors: [__dirname + '/interceptors/*.js'],
1424+
controllers: [path.join(__dirname, '/controllers/*.js')],
1425+
middlewares: [path.join(__dirname, '/middlewares/*.js')],
1426+
interceptors: [path.join(__dirname, '/interceptors/*.js')],
13981427
}).listen(3000);
13991428
```
14001429

@@ -1535,7 +1564,7 @@ export class QuestionController {
15351564

15361565
| Signature | Example | Description |
15371566
| ---------------------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
1538-
| `@Authorized(roles?: string\|string[])` | `@Authorized("SUPER_ADMIN")` get() | Checks if user is authorized and has given roles on a given route. `authorizationChecker` should be defined in routing-controllers options. | |
1567+
| `@Authorized(roles?: string\|string[])` | `@Authorized("SUPER_ADMIN")` get() | Checks if user is authorized and has given roles on a given route. `authorizationChecker` should be defined in routing-controllers options. |
15391568
| `@CurrentUser(options?: { required?: boolean })` | get(@CurrentUser({ required: true }) user: User) | Injects currently authorized user. `currentUserChecker` should be defined in routing-controllers options. |
15401569
| `@Header(headerName: string, headerValue: string)` | `@Header("Cache-Control", "private")` get() | Allows to explicitly set any HTTP header returned in the response. |
15411570
| `@ContentType(contentType: string)` | `@ContentType("text/csv")` get() | Allows to explicitly set HTTP Content-Type returned in the response. |

docs/lang/chinese/READEME.md renamed to docs/lang/chinese/README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
并确认在使用 routing-controllers 前引入
8888

8989
```typescript
90+
9091
```
9192

9293
3. 安装框架:
@@ -101,11 +102,11 @@
101102

102103
**b. 在 _koa 2_ 中使用 routing-controllers,需要安装以下依赖:**
103104

104-
`npm install koa koa-router koa-bodyparser koa-multer`
105+
`npm install koa @koa/router koa-bodyparser @koa/multer`
105106

106107
可选装它们的类型声明:
107108

108-
`npm install -D @types/koa @types/koa-router @types/koa-bodyparser`
109+
`npm install -D @types/koa @types/koa-bodyparser`
109110

110111
4. 可选依赖
111112

@@ -944,23 +945,24 @@ app.listen(3000);
944945

945946
第二种,声明一个类:
946947

948+
```typescript
949+
import { KoaMiddlewareInterface } from 'routing-controllers';
947950

948-
```typescript
949-
import { KoaMiddlewareInterface } from "routing-controllers";
950-
951-
export class MyMiddleware implements KoaMiddlewareInterface { // 接口声明可选
952-
953-
use(context: any, next: (err?: any) => Promise<any>): Promise<any> {
954-
console.log("do something before execution...");
955-
return next().then(() => {
956-
console.log("do something after execution");
957-
}).catch(error => {
958-
console.log("error handling is also here");
959-
});
960-
}
951+
export class MyMiddleware implements KoaMiddlewareInterface {
952+
// 接口声明可选
961953

962-
}
963-
```
954+
use(context: any, next: (err?: any) => Promise<any>): Promise<any> {
955+
console.log('do something before execution...');
956+
return next()
957+
.then(() => {
958+
console.log('do something after execution');
959+
})
960+
.catch(error => {
961+
console.log('error handling is also here');
962+
});
963+
}
964+
}
965+
```
964966

965967
2. 应用:
966968

jest.config.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
44
collectCoverageFrom: ['src/**/*.ts', '!src/**/index.ts', '!src/**/*.interface.ts'],
5-
globals: {
6-
'ts-jest': {
7-
tsConfig: 'tsconfig.spec.json',
8-
},
9-
},
10-
setupFilesAfterEnv: ["./jest.setup.js"]
5+
globals: {},
6+
setupFilesAfterEnv: ["./jest.setup.js"],
7+
transform: {
8+
'^.+\\.tsx?$': [
9+
'ts-jest',
10+
{tsconfig: './tsconfig.spec.json'},
11+
],
12+
}
1113
};

0 commit comments

Comments
 (0)