Skip to content

Commit

Permalink
Showing 9 changed files with 57 additions and 58 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

## 0.3.0

- **Breaking Change**
- Upgrade `fp-ts` to `^2.0.0`
6 changes: 3 additions & 3 deletions packages/typera-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typera-common",
"version": "0.2.0",
"version": "0.3.0",
"description": "TYPEd Route Assistant - Common",
"repository": "https://github.com/akheron/typera",
"author": "Petri Lehtinen <[email protected]>",
@@ -21,7 +21,7 @@
"typescript": "^3.4.5"
},
"dependencies": {
"fp-ts": "^1.18.2",
"io-ts": "^1.8.6"
"fp-ts": "^2.0.0",
"io-ts": "^2.0.0"
}
}
14 changes: 7 additions & 7 deletions packages/typera-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { foldM } from 'fp-ts/lib/Foldable2v'
import { Either, either, right } from 'fp-ts/lib/Either'
import { foldM } from 'fp-ts/lib/Foldable'
import { Either, either, right, getOrElse } from 'fp-ts/lib/Either'
import { array } from 'fp-ts/lib/Array'
import { identity } from 'fp-ts/lib/function'

@@ -33,13 +33,13 @@ export function routeHandler<
foldM(either, array)(
parsers,
right(makeRequestBase(input)),
(acc, parser) => parser(input).map(v => ({ ...acc, ...v }))
(acc, parser) => either.map(parser(input), v => ({ ...acc, ...v }))
)

return <any>((handler: any) => (input: Input) =>
parseRequest(input)
.map(handler)
.getOrElseL(identity))
return <any>(
((handler: any) => (input: Input) =>
getOrElse(identity)(either.map(parseRequest(input), handler)))
)
}

// Helpers
47 changes: 21 additions & 26 deletions packages/typera-common/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Either, left } from 'fp-ts/lib/Either'
import { Either, either, left } from 'fp-ts/lib/Either'
import * as t from 'io-ts'
import { PathReporter } from 'io-ts/lib/PathReporter'

@@ -26,12 +26,11 @@ namespace Parser {
errorHandler: ErrorHandler<ErrorResponse>
): Parser<Input, ParserOutput<'body', Codec>, ErrorResponse> {
return (input: Input) =>
codec
.decode(getBody(input))
.bimap(
errorHandler,
body => ({ body } as ParserOutput<'body', Codec>)
)
either.bimap(
codec.decode(getBody(input)),
errorHandler,
body => ({ body } as ParserOutput<'body', Codec>)
)
}
}

@@ -58,13 +57,11 @@ namespace Parser {
errorHandler: ErrorHandler<ErrorResponse>
): Parser<Input, ParserOutput<'routeParams', Codec>, ErrorResponse> {
return function(input: Input) {
return codec
.decode(getRouteParams(input))
.bimap(
errorHandler,
routeParams =>
({ routeParams } as ParserOutput<'routeParams', Codec>)
)
return either.bimap(
codec.decode(getRouteParams(input)),
errorHandler,
routeParams => ({ routeParams } as ParserOutput<'routeParams', Codec>)
)
}
}
}
@@ -85,12 +82,11 @@ namespace Parser {
errorHandler: ErrorHandler<ErrorResponse>
): Parser<Input, ParserOutput<'query', Codec>, ErrorResponse> {
return function(input: Input) {
return codec
.decode(getQuery(input))
.bimap(
errorHandler,
query => ({ query } as ParserOutput<'query', Codec>)
)
return either.bimap(
codec.decode(getQuery(input)),
errorHandler,
query => ({ query } as ParserOutput<'query', Codec>)
)
}
}
}
@@ -117,12 +113,11 @@ namespace Parser {
errorHandler: ErrorHandler<ErrorResponse>
): Parser<Input, ParserOutput<'headers', Codec>, ErrorResponse> {
return function(input: Input) {
return codec
.decode(getHeaders(input))
.bimap(
errorHandler,
headers => ({ headers } as ParserOutput<'headers', Codec>)
)
return either.bimap(
codec.decode(getHeaders(input)),
errorHandler,
headers => ({ headers } as ParserOutput<'headers', Codec>)
)
}
}
}
4 changes: 2 additions & 2 deletions packages/typera-express/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typera-express",
"version": "0.2.0",
"version": "0.3.0",
"description": "TYPEd Route Assistant - for Express",
"repository": "https://github.com/akheron/typera",
"author": "Petri Lehtinen <[email protected]>",
@@ -16,6 +16,6 @@
"dependencies": {
"@types/express": "^4.17.0",
"express": "^4.17.1",
"typera-common": "0.2.0"
"typera-common": "0.3.0"
}
}
4 changes: 2 additions & 2 deletions packages/typera-koa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typera-koa",
"version": "0.2.0",
"version": "0.3.0",
"description": "TYPEd Route Assistant - for Koa",
"repository": "https://github.com/akheron/typera",
"author": "Petri Lehtinen <[email protected]>",
@@ -18,6 +18,6 @@
"@types/koa-bodyparser": "^4.2.2",
"koa": "^2.7.0",
"koa-bodyparser": "^4.2.1",
"typera-common": "0.2.0"
"typera-common": "0.3.0"
}
}
4 changes: 2 additions & 2 deletions typing-tests/package.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"test": "ts-node run-typing-tests.ts"
},
"dependencies": {
"typera-express": "0.2.0",
"typera-koa": "0.2.0"
"typera-express": "0.3.0",
"typera-koa": "0.3.0"
}
}
12 changes: 6 additions & 6 deletions typing-tests/run-typing-tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as child_process from 'child_process'
import * as fs from 'fs'
import * as path from 'path'
import { Either, either, left, right } from 'fp-ts/lib/Either'
import { Either, either, left, right, isLeft } from 'fp-ts/lib/Either'
import { array } from 'fp-ts/lib/Array'

type TestFile =
@@ -31,21 +31,21 @@ function main(): number {
const testDir = 'tests'

const testFiles = parseTestFiles(testDir)
if (testFiles.isLeft()) {
if (isLeft(testFiles)) {
console.log('Error reading test files:')
console.log(testFiles.value)
console.log(testFiles.left)
return 1
}

const compileResult = compileProject()
if (compileResult.isLeft()) {
if (isLeft(compileResult)) {
console.log('Error building test files:')
console.log(compileResult.value)
console.log(compileResult.left)
return 1
}

let exitStatus = 0
checkTestResults(testFiles.value, compileResult.value).forEach(
checkTestResults(testFiles.right, compileResult.right).forEach(
({ ok, fileName, message, compileOutput }) => {
console.log(`${fileName}: ${message}`)
if (compileOutput != null) {
18 changes: 8 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -1599,10 +1599,10 @@ forwarded@~0.1.2:
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.1.2.tgz#98c23dab1175657b8c0573e8ceccd91b0ff18c84"
integrity sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=

fp-ts@^1.0.0, fp-ts@^1.18.2:
version "1.19.5"
resolved "https://registry.yarnpkg.com/fp-ts/-/fp-ts-1.19.5.tgz#3da865e585dfa1fdfd51785417357ac50afc520a"
integrity sha512-wDNqTimnzs8QqpldiId9OavWK2NptormjXnRJTQecNjzwfyp6P/8s/zG8e4h3ja3oqkKaY72UlTjQYt/1yXf9A==
fp-ts@^2.0.0:
version "2.0.5"
resolved "https://registry.yarnpkg.com/fp-ts/-/fp-ts-2.0.5.tgz#9560d8a6a4f53cbda9f9b31ed8d1458e41939e07"
integrity sha512-opI5r+rVlpZE7Rhk0YtqsrmxGkbIw0dRNqGca8FEAMMnjomXotG+R9QkLQg20onx7R8qhepAn4CCOP8usma/Xw==

fragment-cache@^0.2.1:
version "0.2.1"
@@ -1913,12 +1913,10 @@ invert-kv@^2.0.0:
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02"
integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==

io-ts@^1.8.6:
version "1.10.4"
resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-1.10.4.tgz#cd5401b138de88e4f920adbcb7026e2d1967e6e2"
integrity sha512-b23PteSnYXSONJ6JQXRAlvJhuw8KOtkqa87W4wDtvMrud/DTJd5X+NpOOI+O/zZwVq6v0VLAaJ+1EDViKEuN9g==
dependencies:
fp-ts "^1.0.0"
io-ts@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.0.1.tgz#1261c12f915c2f48d16393a36966636b48a45aa1"
integrity sha512-RezD+WcCfW4VkMkEcQWL/Nmy/nqsWTvTYg7oUmTGzglvSSV2P9h2z1PVeREPFf0GWNzruYleAt1XCMQZSg1xxQ==

[email protected]:
version "1.9.0"

0 comments on commit e5cf3f5

Please sign in to comment.