Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
feat: implements useValidatedBody
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmarrec committed Jun 12, 2022
1 parent 3b6a9ee commit e6ed0b5
Show file tree
Hide file tree
Showing 6 changed files with 481 additions and 224 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -23,3 +23,7 @@ jobs:
- run: pnpm build
- run: pnpm test:coverage
- uses: codecov/codecov-action@v3
- if: github.event_name == 'push' && startsWith(github.event.head_commit.message, 'chore(release)')
run: pnpm publish -q --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
34 changes: 21 additions & 13 deletions README.md
Expand Up @@ -7,32 +7,40 @@

> JSON schema validation for [h3](https://github.com/unjs/h3), using [typebox](https://github.com/sinclairzx81/typebox) & [ajv](https://github.com/ajv-validator/ajv).
## Usage

Install package:
## Install

```sh
# npm
# Using npm
npm install h3-typebox

# yarn
# Using yarn
yarn install h3-typebox

# pnpm
# Using pnpm
pnpm install h3-typebox
```

Import:
## Usage

```js
// ESM
import { } from 'h3-typebox'

// CommonJS
const { } = require('h3-typebox')
import { createServer } from 'http'
import { createApp } from 'h3'
import { useValidatedBody, Type } from 'h3-typebox'

const app = createApp()
app.use('/', aynsc (req) => {
const body = await useValidatedBody(req, Type.Object({
optional: Type.Optional(Type.String()),
required: Type.Boolean(),
}))
})

createServer(app).listen(process.env.PORT || 3000)
```

## 💻 Development
See how to define your schema with `Type` on [TypeBox documentation](https://github.com/sinclairzx81/typebox#usage).

## Development 💻

- Clone this repository
- Install dependencies using `pnpm install`
Expand Down
10 changes: 8 additions & 2 deletions package.json
Expand Up @@ -26,15 +26,21 @@
"test": "vitest run",
"test:coverage": "pnpm test -- --reporter verbose --coverage"
},
"dependencies": {},
"dependencies": {
"@sinclair/typebox": "^0.23.5",
"ajv": "^8.11.0",
"h3": "^0.7.9"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"@types/supertest": "latest",
"c8": "latest",
"eslint": "latest",
"standard-version": "latest",
"supertest": "latest",
"typescript": "latest",
"unbuild": "latest",
"vitest": "latest"
},
"packageManager": "pnpm@7.0.0"
"packageManager": "pnpm@7.2.0"
}

0 comments on commit e6ed0b5

Please sign in to comment.