Skip to content

feat: release v0.10.0 #962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 60 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
d97ff7d
docs: fix typo in README (#682)
lucasltv Mar 24, 2021
803c151
docs: fix code example in README (#683)
lucasltv Mar 24, 2021
59ebe8f
docs: fix typo in README (#674)
FriendlyUser Mar 24, 2021
33b54fd
build(deps-dev): bump ts-jest from 26.1.4 to 26.5.4 (#679)
dependabot[bot] Mar 24, 2021
182e859
build(deps): bump urijs from 1.19.5 to 1.19.6 (#666)
dependabot[bot] Mar 24, 2021
40e935e
docs: fix broken link in README (#668)
wuchangming Mar 24, 2021
af0cdf8
feat: load TSX files in `importClassesFormDirectories` (#629)
11joselu Mar 24, 2021
71149b4
feat: add cast array to expected array query params
BenjD90 Mar 12, 2021
ce2cb72
feat: add cast array to expected array query param
BenjD90 Mar 25, 2021
d00d837
feat: add documentation for array query param and query params
BenjD90 Mar 25, 2021
d4ba6bb
test: Add test on the boolean query params
BenjD90 Mar 29, 2021
8e211f3
fix: Fix support of array whitelist query param
BenjD90 Mar 29, 2021
4715d74
build(deps): bump y18n from 4.0.0 to 4.0.1
dependabot[bot] Mar 31, 2021
71a0efb
fix: lockfiles
loriswit Apr 8, 2021
b03d7b4
fix: uuid support added with test
ivanproskuryakov Apr 13, 2021
5701639
fix: cs & linter
ivanproskuryakov Apr 13, 2021
1a3618b
fix: adding more test cases according to the feedback provided, cs im…
ivanproskuryakov Apr 15, 2021
9861f71
fix: adding more test cases according to the feedback provided, negat…
ivanproskuryakov Apr 15, 2021
239fb0d
fix: fixing cs with running prettier:fix
ivanproskuryakov Apr 15, 2021
c4bb9c8
fix: code review ref: https://github.com/typestack/routing-controller…
ivanproskuryakov Apr 19, 2021
2da2757
build(deps): bump lodash from 4.17.19 to 4.17.21
dependabot[bot] May 6, 2021
01761f7
docs: update use of glob patterns in docs
vedraan Jun 11, 2021
a18cffa
fix: fixing the bug caused by wrong controller assignment in action.t…
ivanproskuryakov Jul 4, 2021
f8d8920
fix: Fixed example in README.md
ArtemLavrentii Jul 4, 2021
33f0e01
fix: Update src/ActionParameterHandler.ts Co-authored-by: Rustam Mama…
ivanproskuryakov Jul 20, 2021
670e23c
fix: Update src/ActionParameterHandler.ts
ivanproskuryakov Jul 20, 2021
796fe9b
fix: Update src/ActionParameterHandler.ts Co-authored-by: Rustam Mama…
ivanproskuryakov Jul 20, 2021
af9a973
Merge pull request #741 from ivanproskuryakov/736-inheritance-bugfix-2
jotamorais Aug 4, 2021
f163c34
Merge pull request #753 from ivanproskuryakov/uuid-parameters-703
jotamorais Aug 4, 2021
08e7aa0
Merge pull request #677 from BenjD90/fix-query-params-parsing
jotamorais Aug 4, 2021
839dcc2
Merge pull request #693 from typestack/dependabot/npm_and_yarn/y18n-4…
jotamorais Aug 4, 2021
b57213f
Merge pull request #702 from loriswit/develop
jotamorais Aug 4, 2021
33f6026
build(deps-dev): bump handlebars from 4.7.6 to 4.7.7
dependabot[bot] Aug 4, 2021
53becca
build(deps): bump glob-parent from 5.1.1 to 5.1.2
dependabot[bot] Aug 4, 2021
f85a208
Merge pull request #716 from typestack/dependabot/npm_and_yarn/lodash…
jotamorais Aug 4, 2021
eff00b2
Merge pull request #729 from typestack/dependabot/npm_and_yarn/glob-p…
jotamorais Aug 4, 2021
8fae22a
Merge pull request #715 from typestack/dependabot/npm_and_yarn/handle…
jotamorais Aug 4, 2021
f4fe9f1
Merge pull request #731 from vedraan/patch-1
jotamorais Aug 4, 2021
cf1117d
Merge pull request #743 from ArtemLavrentii/patch-1
jotamorais Aug 4, 2021
5b1fce3
fix: check if number is NaN
borjapazr Dec 2, 2021
98173dd
Merge pull request #815 from borjapazr/fix/action-parameter-handler
jotamorais Jan 12, 2022
12b766c
fix: chinese docs (#766)
Feb 17, 2022
202a54f
refactor: comments and log (#804)
sksmta Feb 17, 2022
f682579
Update README.md (#712)
lucasltv Feb 17, 2022
175d02f
docs: format README with prettier (#847)
attilaorosz Feb 17, 2022
f9cf7e3
fix: null typecheck in parameter validation (#849)
attilaorosz Mar 9, 2022
547fb4a
refactor: remove redundant controller options assignment when creatin…
ron-tayler Apr 3, 2022
6c490e0
chore: update class-validator and class-transformer (#932)
attilaorosz Nov 26, 2022
a2da458
chore: update optional dependencies (#946)
attilaorosz Nov 26, 2022
102b0d3
build: update workflow files to use lts version (#952)
NoNameProvided Dec 3, 2022
d43bf9a
chore: update dev dependencies (#948)
attilaorosz Dec 5, 2022
7c517af
fix: use route prefix when registering middlewares (#931)
attilaorosz Dec 5, 2022
504baa3
build(deps-dev): bump @types/jest from 29.2.3 to 29.2.4 (#955)
dependabot[bot] Dec 5, 2022
ed65e9a
fix: disable keepAlive in test requests until axios is fixed (#956)
attilaorosz Dec 6, 2022
4090c77
build(deps-dev): bump @typescript-eslint/parser from 5.44.0 to 5.45.1…
dependabot[bot] Dec 6, 2022
8836350
chore: update koa dependencies (#959)
kyle-seongwoo-jun Dec 9, 2022
1390042
build(deps): bump qs from 6.5.2 to 6.5.3 (#960)
dependabot[bot] Dec 9, 2022
9e61bfc
fix: koa deps (#963)
attilaorosz Dec 9, 2022
f4914c1
docs: add changelog for v0.10.0
attilaorosz Dec 9, 2022
fe049f7
build: bump version to v0.10.0
attilaorosz Dec 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extends:
- 'plugin:@typescript-eslint/recommended-requiring-type-checking'
- 'plugin:jest/recommended'
- 'prettier'
- 'prettier/@typescript-eslint'
rules:
'@typescript-eslint/explicit-member-accessibility': off
'@typescript-eslint/no-angle-bracket-type-assertion': off
Expand All @@ -32,3 +31,5 @@ rules:
'@typescript-eslint/no-unsafe-call': off
'@typescript-eslint/no-unsafe-member-access': off
'@typescript-eslint/explicit-module-boundary-types': off
'@typescript-eslint/no-unsafe-argument': off
'@typescript-eslint/no-var-requires': off
7 changes: 4 additions & 3 deletions .github/workflows/continuous-deployment-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ jobs:
name: Publish to NPM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org
- run: npm ci --ignore-scripts
- run: npm run prettier:check
Expand All @@ -23,4 +24,4 @@ jobs:
- run: jq 'del(.devDependencies) | del(.scripts)' package.json > build/package.json
- run: npm publish ./build
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
24 changes: 14 additions & 10 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ jobs:
name: Linters
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
- run: npm ci --ignore-scripts
- run: npm run prettier:check
- run: npm run lint:check
Expand All @@ -15,27 +17,29 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['10.x', '12.x', '14.x']
node-version: ['lts/*', 'current']
fail-fast: false
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Setting up Node.js (v${{ matrix.node-version }}.x)
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci --ignore-scripts
- run: npm run test:ci
- run: npm install codecov -g
if: ${{ matrix.node-version == '14.x' }}
if: ${{ matrix.node-version == 'current' }}
- run: codecov -f ./coverage/clover.xml -t ${{ secrets.CODECOV_TOKEN }} --commit=$GITHUB_SHA --branch=${GITHUB_REF##*/}
if: ${{ matrix.node-version == '14.x' }}
if: ${{ matrix.node-version == 'current' }}
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
- run: npm ci --ignore-scripts
- run: npm run build:es2015
- run: npm run build:cjs
- run: npm run build:types
- run: npm run build:types
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog and release notes

## [0.10.0](https://github.com/typestack/routing-controllers/compare/v0.9.0...v0.10.0) (2022-12-9)

### Added

- `isArray` option for `@QueryParam`

### Changed

- `class-transformer` package updated to `0.5.1` from `0.3.1`
- `class-validator` package updated to `0.13.2` from `0.12.2`
- `cookie` package updated to `0.5.0` from `0.4.0`
- `glob` package updated to `8.0.3` from `7.1.4`
- `express` package updated to `4.18.2` from `4.17.1` and moved to `optionalDependencies`
- `express-session` package updated to `1.17.1` from `1.17.3` and moved to `optionalDependencies`
- `body-parser` package updated to `1.20.1` from `1.19.0`
- `multer` package updated to `1.4.4` from `1.4.2`
- `koa` package updated to `2.13.4` from `2.8.2`
- `koa-multer` package replaced with `@koa/multer`
- `koa-router` package replaced with `@koa/router`
- updated various dev dependencies

### Fixed

- Fixed parsing uuid as route parameter
- Fixed `target` property not set during controller inheritance
- Fixed `NaN` check for number route parameters
- Added missing null value handling in parameters
- Fixed middlewares not using the defined route prefix

### 0.9.0

#### Features
Expand Down
73 changes: 51 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
[![npm version](https://badge.fury.io/js/routing-controllers.svg)](https://badge.fury.io/js/routing-controllers)
[![Dependency Status](https://david-dm.org/typestack/routing-controllers.svg)](https://david-dm.org/typestack/routing-controllers)

<center>
<span>English</span> |
[中文](./docs/lang/chinese/README.md)
</center>
English | [中文](./docs/lang/chinese/README.md)

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

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

```typescript
```
```typescript
import 'reflect-metadata';
```

3. Install framework:

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

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

`npm install koa koa-router koa-bodyparser koa-multer`
`npm install koa @koa/router koa-bodyparser @koa/multer`

Optionally you can also install their typings:

`npm install -D @types/koa @types/koa-router @types/koa-bodyparser`
`npm install -D @types/koa @types/koa-bodyparser`

4. Install peer dependencies:

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

```typescript
import { createExpressServer } from 'routing-controllers';
import path from 'path';

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

Expand Down Expand Up @@ -378,8 +377,30 @@ getUsers(@QueryParam("limit") limit: number) {
}
```

You can use `isArray` option to get a query param array. This will cast the query param :

```typescript
@Get("/users/by-multiple-ids")
getUsers(@QueryParam("ids", { isArray: true}) ids: string[]) {
}
```

`GET /users/by-multiple-ids?ids=a` → `ids = ['a']`
`GET /users/by-multiple-ids?ids=a&ids=b` → `ids = ['a', 'b']`

You can combine use `isArray` option with `type` option to get a query param array of one type. This will cast the query param :

```typescript
@Get("/users/by-multiple-ids")
getUsers(@QueryParam("ids", { isArray: true, type: Number}) ids: number[]) {
}
```

`GET /users/by-multiple-ids?ids=1` → `ids = [1]`
`GET /users/by-multiple-ids?ids=1&ids=3.5` → `ids = [1, 3.5]`

If you want to inject all query parameters use `@QueryParams()` decorator.
The bigest benefit of this approach is that you can perform validation of the params.
The biggest benefit of this approach is that you can perform validation of the params.

```typescript
enum Roles {
Expand All @@ -402,12 +423,17 @@ class GetUsersQuery {
@IsBoolean()
isActive: boolean;

@IsArray()
@IsNumber(undefined, { each: true })
@Type(() => Number)
ids: number[];
}

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

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

```typescript
// to keep code clean better to extract this function into separate file
export const fileUploadOptions = () => {
export const fileUploadOptions = () => ({
storage: multer.diskStorage({
destination: (req: any, file: any, cb: any) => { ...
},
Expand All @@ -523,7 +549,7 @@ export const fileUploadOptions = () => {
fieldNameSize: 255,
fileSize: 1024 * 1024 * 2
}
};
});

// use options this way:
@Post("/files")
Expand Down Expand Up @@ -782,7 +808,7 @@ app.listen(3000);
```

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

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

```typescript
import { createExpressServer } from 'routing-controllers';
import path from 'path';

createExpressServer({
controllers: [__dirname + '/controllers/**/*.js'],
middlewares: [__dirname + '/middlewares/**/*.js'],
interceptors: [__dirname + '/interceptors/**/*.js'],
controllers: [path.join(__dirname, '/controllers/**/*.js')],
middlewares: [path.join(__dirname, '/middlewares/**/*.js')],
interceptors: [path.join(__dirname, '/interceptors/**/*.js')],
}).listen(3000);
```

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

## Controller Inheritance

Often your application may need to have an option to inherit controller from another to reuse code and void duplication.
Often your application may need to have an option to inherit controller from another to reuse code and avoid duplication.
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.

```typescript
Expand All @@ -1227,7 +1255,7 @@ abstract class AbstractControllerTemplate {
@Post()
public create() {}

@Read()
@Get()
public read() {}

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

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

// create and run server
createExpressServer({
controllers: [__dirname + '/controllers/*.js'],
middlewares: [__dirname + '/middlewares/*.js'],
interceptors: [__dirname + '/interceptors/*.js'],
controllers: [path.join(__dirname, '/controllers/*.js')],
middlewares: [path.join(__dirname, '/middlewares/*.js')],
interceptors: [path.join(__dirname, '/interceptors/*.js')],
}).listen(3000);
```

Expand Down Expand Up @@ -1535,7 +1564,7 @@ export class QuestionController {

| Signature | Example | Description |
| ---------------------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `@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. | |
| `@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. |
| `@CurrentUser(options?: { required?: boolean })` | get(@CurrentUser({ required: true }) user: User) | Injects currently authorized user. `currentUserChecker` should be defined in routing-controllers options. |
| `@Header(headerName: string, headerValue: string)` | `@Header("Cache-Control", "private")` get() | Allows to explicitly set any HTTP header returned in the response. |
| `@ContentType(contentType: string)` | `@ContentType("text/csv")` get() | Allows to explicitly set HTTP Content-Type returned in the response. |
Expand Down
36 changes: 19 additions & 17 deletions docs/lang/chinese/READEME.md → docs/lang/chinese/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
并确认在使用 routing-controllers 前引入

```typescript

```

3. 安装框架:
Expand All @@ -101,11 +102,11 @@

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

`npm install koa koa-router koa-bodyparser koa-multer`
`npm install koa @koa/router koa-bodyparser @koa/multer`

可选装它们的类型声明:

`npm install -D @types/koa @types/koa-router @types/koa-bodyparser`
`npm install -D @types/koa @types/koa-bodyparser`

4. 可选依赖

Expand Down Expand Up @@ -944,23 +945,24 @@ app.listen(3000);

第二种,声明一个类:

```typescript
import { KoaMiddlewareInterface } from 'routing-controllers';

```typescript
import { KoaMiddlewareInterface } from "routing-controllers";

export class MyMiddleware implements KoaMiddlewareInterface { // 接口声明可选

use(context: any, next: (err?: any) => Promise<any>): Promise<any> {
console.log("do something before execution...");
return next().then(() => {
console.log("do something after execution");
}).catch(error => {
console.log("error handling is also here");
});
}
export class MyMiddleware implements KoaMiddlewareInterface {
// 接口声明可选

}
```
use(context: any, next: (err?: any) => Promise<any>): Promise<any> {
console.log('do something before execution...');
return next()
.then(() => {
console.log('do something after execution');
})
.catch(error => {
console.log('error handling is also here');
});
}
}
```

2. 应用:

Expand Down
14 changes: 8 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverageFrom: ['src/**/*.ts', '!src/**/index.ts', '!src/**/*.interface.ts'],
globals: {
'ts-jest': {
tsConfig: 'tsconfig.spec.json',
},
},
setupFilesAfterEnv: ["./jest.setup.js"]
globals: {},
setupFilesAfterEnv: ["./jest.setup.js"],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{tsconfig: './tsconfig.spec.json'},
],
}
};
Loading