Skip to content

Commit e8469df

Browse files
committed
Merge branch 'master' into beta
2 parents 560bbac + b1d7137 commit e8469df

File tree

2 files changed

+72
-22
lines changed

2 files changed

+72
-22
lines changed

.github/workflows/test.yaml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,49 @@
11
name: CI
2-
on: [pull_request]
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
pull_request:
9+
310
jobs:
4-
test:
5-
name: 'Test'
11+
run-tests:
612
runs-on: ubuntu-latest
13+
714
steps:
815
- name: Checkout repo
916
uses: actions/checkout@v2
17+
1018
- name: Setup Node.js
1119
uses: actions/setup-node@v2
1220
with:
1321
node-version: 12
22+
23+
- name: Get yarn cache directory path
24+
id: yarn-cache-dir-path
25+
run: echo "::set-output name=dir::$(yarn cache dir)"
26+
27+
- name: Cache yarn dependencies
28+
uses: actions/cache@v2
29+
id: yarn-cache
30+
with:
31+
path: |
32+
${{ steps.yarn-cache-dir-path.outputs.dir }}
33+
node_modules
34+
*/*/node_modules
35+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-yarn-
38+
1439
- name: Install modules
1540
run: yarn
41+
1642
- name: Run tests
17-
run: yarn test --silent
18-
- name: Upload coverage
19-
uses: codecov/[email protected]
43+
run: yarn test --silent --coverage
44+
45+
- name: Upload coverage to Codecov
46+
uses: codecov/codecov-action@v1
47+
with:
48+
# project specific codecov token
49+
token: ${{ secrets.CODECOV_TOKEN }}

README.md

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
<p align="center">
1+
<div align="center">
22
<a aria-label="Story of AMS logo" href="https://storyofams.com/" target="_blank" align="center">
33
<img src="https://storyofams.com/public/[email protected]" alt="Story of AMS" width="120">
44
</a>
55
<h1 align="center">@storyofams/next-api-decorators</h1>
6-
</p>
7-
8-
<p align="center">Collection of decorators to create typed Next.js API routes, with easy request validation and transformation.</p>
6+
<p align="center">
7+
<a aria-label="releases" href="https://GitHub.com/storyofams/next-api-decorators/releases/" target="_blank">
8+
<img src="https://github.com/storyofams/next-api-decorators/workflows/Release/badge.svg">
9+
</a>
10+
<a aria-label="npm" href="https://www.npmjs.com/package/@storyofams/next-api-decorators" target="_blank">
11+
<img src="https://img.shields.io/npm/v/@storyofams/next-api-decorators">
12+
</a>
13+
<a aria-label="codecov" href="https://codecov.io/gh/storyofams/nextjs-api-decorators" target="_blank">
14+
<img src="https://codecov.io/gh/storyofams/next-api-decorators/branch/master/graph/badge.svg?token=ZV0YT4HU5H">
15+
</a>
16+
<a aria-label="stars" href="https://github.com/storyofams/next-api-decorators/stargazers/" target="_blank">
17+
<img src="https://img.shields.io/github/stars/storyofams/next-api-decorators.svg?style=social&label=Star&maxAge=86400" />
18+
</a>
19+
</p>
20+
</div>
921

1022
---
1123

24+
Collection of decorators to create typed Next.js API routes, with easy request validation and transformation.
25+
1226
## Installation
1327

1428
Add the package to your project:
@@ -23,11 +37,17 @@ Since decorators are still in proposal state, you need to add the following plug
2337
$ yarn add -D babel-plugin-transform-typescript-metadata @babel/plugin-proposal-decorators babel-plugin-parameter-decorator
2438
```
2539

40+
Make sure to add the following lines to the `plugins` section in your babel configuration file:
41+
```json
42+
"babel-plugin-transform-typescript-metadata",
43+
["@babel/plugin-proposal-decorators", { "legacy": true }],
44+
"babel-plugin-parameter-decorator",
45+
```
46+
2647
Your `tsconfig.json` needs the following flags:
2748

2849
```json
29-
"experimentalDecorators": true,
30-
"emitDecoratorMetadata": true
50+
"experimentalDecorators": true
3151
```
3252

3353
## Usage
@@ -103,14 +123,14 @@ export default createHandler(User);
103123

104124
### Method decorators
105125

106-
| | Description |
107-
| ----------------------------------------- | -------------------------------------------------- |
108-
| `@Get()` | Marks the method as `GET` handler. |
109-
| `@Post()` | Marks the method as `POST` handler. |
110-
| `@Put()` | Marks the method as `PUT` handler. |
111-
| `@Delete()` | Marks the method as `DELETE` handler. |
112-
| `@SetHeader(name: string, value: string)` | Sets a header name/value into the route response. |
113-
| `@HttpCode(code: number)` | Sets the http code in the route response. |
126+
| | Description |
127+
| ----------------------------------------- | ------------------------------------------------- |
128+
| `@Get()` | Marks the method as `GET` handler. |
129+
| `@Post()` | Marks the method as `POST` handler. |
130+
| `@Put()` | Marks the method as `PUT` handler. |
131+
| `@Delete()` | Marks the method as `DELETE` handler. |
132+
| `@SetHeader(name: string, value: string)` | Sets a header name/value into the route response. |
133+
| `@HttpCode(code: number)` | Sets the http code in the route response. |
114134

115135
### Parameter decorators
116136

@@ -133,8 +153,8 @@ Pipes are being used to validate and transform incoming values. The pipes can be
133153

134154
⚠️ Beware that they throw when the value is invalid.
135155

136-
| | Description | Remarks |
137-
| ------------------ | -------------------------------------------- | --------------------------------------------- |
156+
| | Description | Remarks |
157+
| ------------------ | ------------------------------------------- | --------------------------------------------- |
138158
| `ParseNumberPipe` | Validates and transforms `Number` strings. | Uses `parseFloat` under the hood |
139159
| `ParseBooleanPipe` | Validates and transforms `Boolean` strings. | Allows `'true'` and `'false'` as valid values |
140160

0 commit comments

Comments
 (0)