Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into frommiddlewarek
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Sep 6, 2023
2 parents 070ed05 + e294ef1 commit 62ba7b8
Show file tree
Hide file tree
Showing 27 changed files with 933 additions and 89 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.log
node_modules
lib
es6
dev
coverage
dist
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ cannot be made. A few examples of such mistakes could be:
```ts
import * as express from 'express'
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import { toRequestHandler } from 'hyper-ts/lib/express'
import * as M from 'hyper-ts/Middleware'
import { toRequestHandler } from 'hyper-ts/express'
import { pipe } from 'fp-ts/function'

const hello: M.Middleware<H.StatusOpen, H.ResponseEnded, never, void> = pipe(
Expand Down Expand Up @@ -103,7 +103,7 @@ During the connection lifecycle the following flow is statically enforced
StatusOpen -> HeadersOpen -> BodyOpen -> ResponseEnded
```

**Note**. `hyper-ts` supports [express 4.x](http://expressjs.com/) by default by exporting a `Connection` instance from the `hyper-ts/lib/express` module.
**Note**. `hyper-ts` supports [express 4.x](http://expressjs.com/) by default by exporting a `Connection` instance from the `hyper-ts/express` module.

## Middleware

Expand Down Expand Up @@ -152,7 +152,7 @@ Input validation/decoding is done by defining a decoding function with the follo

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as E from 'fp-ts/Either'

const isUnknownRecord = (u: unknown): u is Record<string, unknown> => typeof u === 'object' && u !== null
Expand All @@ -167,7 +167,7 @@ You can also use [io-ts](https://github.com/gcanti/io-ts) decoders.

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as t from 'io-ts'

// returns a middleware validating `req.param.user_id`
Expand All @@ -181,8 +181,8 @@ Here I'm using `t.string` but you can pass _any_ `io-ts` runtime type

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import { IntFromString } from 'io-ts-types/lib/IntFromString'
import * as M from 'hyper-ts/Middleware'
import { IntFromString } from 'io-ts-types/IntFromString'

// validation succeeds only if `req.param.user_id` can be parsed to an integer
export const middleware3: M.Middleware<
Expand All @@ -197,7 +197,7 @@ export const middleware3: M.Middleware<

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as t from 'io-ts'

// returns a middleware validating both `req.param.user_id` and `req.param.user_name`
Expand All @@ -213,7 +213,7 @@ export const middleware = M.decodeParams(

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as t from 'io-ts'

// return a middleware validating the query "order=desc&shoe[color]=blue&shoe[type]=converse"
Expand All @@ -232,7 +232,7 @@ export const middleware = M.decodeQuery(

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as t from 'io-ts'

// return a middleware validating `req.body`
Expand Down
20 changes: 10 additions & 10 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ cannot be made. A few examples of such mistakes could be:
```ts
import * as express from 'express'
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import { toRequestHandler } from 'hyper-ts/lib/express'
import * as M from 'hyper-ts/Middleware'
import { toRequestHandler } from 'hyper-ts/express'
import { pipe } from 'fp-ts/function'

const hello: M.Middleware<H.StatusOpen, H.ResponseEnded, never, void> = pipe(
Expand Down Expand Up @@ -108,7 +108,7 @@ During the connection lifecycle the following flow is statically enforced
StatusOpen -> HeadersOpen -> BodyOpen -> ResponseEnded
```

**Note**. `hyper-ts` supports [express 4.x](http://expressjs.com/) by default by exporting a `Connection` instance from the `hyper-ts/lib/express` module.
**Note**. `hyper-ts` supports [express 4.x](http://expressjs.com/) by default by exporting a `Connection` instance from the `hyper-ts/express` module.

## Middleware

Expand Down Expand Up @@ -157,7 +157,7 @@ Input validation/decoding is done by defining a decoding function with the follo

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as E from 'fp-ts/Either'

const isUnknownRecord = (u: unknown): u is Record<string, unknown> => typeof u === 'object' && u !== null
Expand All @@ -172,7 +172,7 @@ You can also use [io-ts](https://github.com/gcanti/io-ts) decoders.

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as t from 'io-ts'

// returns a middleware validating `req.param.user_id`
Expand All @@ -186,8 +186,8 @@ Here I'm using `t.string` but you can pass _any_ `io-ts` runtime type

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import { IntFromString } from 'io-ts-types/lib/IntFromString'
import * as M from 'hyper-ts/Middleware'
import { IntFromString } from 'io-ts-types/IntFromString'

// validation succeeds only if `req.param.user_id` can be parsed to an integer
export const middleware3: M.Middleware<
Expand All @@ -202,7 +202,7 @@ export const middleware3: M.Middleware<

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as t from 'io-ts'

// returns a middleware validating both `req.param.user_id` and `req.param.user_name`
Expand All @@ -218,7 +218,7 @@ export const middleware = M.decodeParams(

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as t from 'io-ts'

// return a middleware validating the query "order=desc&shoe[color]=blue&shoe[type]=converse"
Expand All @@ -237,7 +237,7 @@ export const middleware = M.decodeQuery(

```ts
import * as H from 'hyper-ts'
import * as M from 'hyper-ts/lib/Middleware'
import * as M from 'hyper-ts/Middleware'
import * as t from 'io-ts'

// return a middleware validating `req.body`
Expand Down
103 changes: 98 additions & 5 deletions docs/modules/Middleware.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Added in v0.7.0
- [Apply](#apply)
- [ap](#ap)
- [apW](#apw)
- [iap](#iap)
- [iapW](#iapw)
- [Bifunctor](#bifunctor)
- [bimap](#bimap)
- [mapLeft](#mapleft)
Expand Down Expand Up @@ -68,6 +70,10 @@ Added in v0.7.0
- [flattenW](#flattenw)
- [fromIOK](#fromiok)
- [fromTaskK](#fromtaskk)
- [iapFirst](#iapfirst)
- [iapFirstW](#iapfirstw)
- [iapSecond](#iapsecond)
- [iapSecondW](#iapsecondw)
- [ichainFirst](#ichainfirst)
- [ichainFirstW](#ichainfirstw)
- [iflatten](#iflatten)
Expand Down Expand Up @@ -207,6 +213,34 @@ export declare const apW: <I, E2, A>(
Added in v0.7.0
## iap
Indexed version of [`ap`](#ap).
**Signature**
```ts
export declare const iap: <O, Z, E, A>(
fa: Middleware<O, Z, E, A>
) => <I, B>(fab: Middleware<I, O, E, (a: A) => B>) => Middleware<I, Z, E, B>
```
Added in v0.7.9
## iapW
Less strict version of [`iap`](#iap).
**Signature**
```ts
export declare const iapW: <O, Z, E2, A>(
fa: Middleware<O, Z, E2, A>
) => <I, E1, B>(fab: Middleware<I, O, E1, (a: A) => B>) => Middleware<I, Z, E2 | E1, B>
```
Added in v0.7.9
# Bifunctor
## bimap
Expand Down Expand Up @@ -439,8 +473,8 @@ Derivable from `Chain`.
**Signature**

```ts
export declare const chainFirst: <A, R, E, B>(
f: (a: A) => Middleware<R, R, E, B>
export declare const chainFirst: <A, R, E, _>(
f: (a: A) => Middleware<R, R, E, _>
) => (first: Middleware<R, R, E, A>) => Middleware<R, R, E, A>
```

Expand Down Expand Up @@ -720,6 +754,62 @@ export declare const fromTaskK: <A, B>(f: (...a: A) => T.Task<B>) => <R, E>(...a

Added in v0.7.0

## iapFirst

Indexed version of [`apFirst`](#apfirst).

**Signature**

```ts
export declare const iapFirst: <O, Z, E, B>(
second: Middleware<O, Z, E, B>
) => <I, A>(first: Middleware<I, O, E, A>) => Middleware<I, Z, E, A>
```

Added in v0.7.9

## iapFirstW

Less strict version of [`iapFirst`](#iapfirst).

**Signature**

```ts
export declare const iapFirstW: <O, Z, E2, B>(
second: Middleware<O, Z, E2, B>
) => <I, E1, A>(first: Middleware<I, O, E1, A>) => Middleware<I, Z, E2 | E1, A>
```

Added in v0.7.1

## iapSecond

Indexed version of [`apSecond`](#apsecond).

**Signature**

```ts
export declare const iapSecond: <O, Z, E, B>(
second: Middleware<O, Z, E, B>
) => <I, A>(first: Middleware<I, O, E, A>) => Middleware<I, Z, E, B>
```

Added in v0.7.9

## iapSecondW

Less strict version of [`iapSecond`](#iapsecond).

**Signature**

```ts
export declare const iapSecondW: <O, Z, E2, B>(
second: Middleware<O, Z, E2, B>
) => <I, E1, A>(first: Middleware<I, O, E1, A>) => Middleware<I, Z, E2 | E1, B>
```

Added in v0.7.9

## ichainFirst

Indexed version of [`chainFirst`](#chainfirst).
Expand Down Expand Up @@ -1066,7 +1156,10 @@ Returns a middleware that pipes a stream to the response object.
**Signature**

```ts
export declare function pipeStream<E>(stream: NodeJS.ReadableStream): Middleware<BodyOpen, ResponseEnded, E, void>
export declare function pipeStream<E>(
stream: NodeJS.ReadableStream,
onError: (err: unknown) => IO<void>
): Middleware<BodyOpen, ResponseEnded, E, void>
```

Added in v0.7.0
Expand Down Expand Up @@ -1361,7 +1454,7 @@ Added in v0.7.0
**Signature**

```ts
export declare const fromIO: <R, E, A>(fa: IO<A>) => Middleware<R, R, E, A>
export declare const fromIO: <A, R, E>(fa: IO<A>) => Middleware<R, R, E, A>
```

Added in v0.7.0
Expand Down Expand Up @@ -1391,7 +1484,7 @@ Added in v0.7.0
**Signature**

```ts
export declare const fromTask: <R, E, A>(fa: T.Task<A>) => Middleware<R, R, E, A>
export declare const fromTask: <A, R, E>(fa: T.Task<A>) => Middleware<R, R, E, A>
```

Added in v0.7.0
Expand Down
Loading

0 comments on commit 62ba7b8

Please sign in to comment.