Skip to content

Commit

Permalink
Update restless to use new sanitizers (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
sz-piotr authored Aug 8, 2019
1 parent 565695b commit 3e5d5f9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
7 changes: 4 additions & 3 deletions restless/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Express.js api, validations and more.

```javascript
import express from 'express'
import { asyncHandler, responseOf, sanitize, asString } from '@restless/restless'
import { asyncHandler, responseOf, sanitize } from '@restless/restless'
import { asNumber } from '@restless/sanitizers'

const app = express()
app.get('/add/:a/:b', asyncHandler(
Expand Down Expand Up @@ -51,7 +52,6 @@ yarn add @restless/restless
- [`responseOfBuffer`](#responseofbuffer)
- [`sanitize`](#sanitize)
- [`SanitizeError`](#sanitizeerror)
- All of the [@restless/sanitizers](https://github.com/EthWorks/restless/tree/master/sanitizers) library

### `asyncHandler`

Expand Down Expand Up @@ -120,7 +120,8 @@ The `sanitize` function is a transformer. It transforms the request into an obje
Example:
```javascript
import express from 'express'
import { asyncHandler, responseOf, asObject, asNumber } from '@restless/restless'
import { asyncHandler, responseOf, sanitize } from '@restless/restless'
import { asObject, asNumber } from '@restless/sanitizers'

const app = express()
app.get('/:foo', asyncHandler(
Expand Down
4 changes: 2 additions & 2 deletions restless/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@restless/restless",
"version": "0.3.4",
"version": "0.4.0",
"author": "Piotr Szlachciak <[email protected]>",
"description": "Express.js api, validations and more",
"license": "Unlicense",
Expand Down Expand Up @@ -30,7 +30,7 @@
"lint": "tslint --project tsconfig.json \"src/**/*.ts\" \"test/**/*.ts\""
},
"dependencies": {
"@restless/sanitizers": "^0.1.0",
"@restless/sanitizers": "^0.2.0",
"@types/express": "^4.16.0",
"express": "^4.16.0"
},
Expand Down
1 change: 0 additions & 1 deletion restless/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { asyncHandler } from './asyncHandler'
export { ResponseFunction, responseOf, responseOfBuffer } from './response'
export { sanitize, SanitizeError } from './sanitize'
export * from '@restless/sanitizers'
8 changes: 4 additions & 4 deletions restless/src/sanitize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Either, SanitizerFailure, Schema, SchemaResult } from '@restless/sanitizers'
import { Result, SanitizerFailure, Schema, SchemaResult } from '@restless/sanitizers'
import { Request } from 'express'

export class SanitizeError extends Error {
Expand All @@ -22,10 +22,10 @@ export const sanitize = <S extends Schema<any>>(schema: S) =>
} else {
result = schema[key](req.params[key], `params.${key}`)
}
if (Either.isRight(result)) {
sanitized[key] = result.right
if (Result.isOk(result)) {
sanitized[key] = result.ok
} else {
errors.push(...result.left)
errors.push(...result.error)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions restless/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
esutils "^2.0.2"
js-tokens "^4.0.0"

"@restless/sanitizers@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@restless/sanitizers/-/sanitizers-0.1.0.tgz#7b1af5bbb15cabb3975b33a3539f04f295637f20"
integrity sha512-aMxomLCELnv115RMW4Xksn5By6WmVdqQK0GdZDa09sUdsHpoVP8/lyAtcAZY9amP91rEtkL7oksp3hrQ0pNftg==
"@restless/sanitizers@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@restless/sanitizers/-/sanitizers-0.2.0.tgz#f66ba872f8215a869fcf1290f5547c06b5a7eef5"
integrity sha512-b11WcVDC+xFn8p5uKhNwKv5La+L9+I4kjQDIyiWC4HIgwhcTtP5RT/7UJPjSpV+9k0Dr6BtVUnwEueS5kI3pZQ==

"@types/body-parser@*":
version "1.17.0"
Expand Down

0 comments on commit 3e5d5f9

Please sign in to comment.