1.1.3 • Published 2 years ago

@markhaehnel/resolver-pipe v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Resolver Pipe

This is a functional pipe that makes it easier and cleaner to write complex resolvers in TypeScript. A pipe automatically pipes the output of one function into the next function.

Including a wrapper for easy input validation with zod.

Installation

To install resolver-pipe:

npm install @markhaehnel/resolver-pipe

Usage

import resolver from "@markhaehnel/resolver-pipe";

const myPipe = resolver.pipe(
  (a: number, b: number) => a + b,
  (id: number) => `/article/${id}`
);

await myPipe(1, 3); // => "/article/4"

With validation

import resolver from "@markhaehnel/resolver-pipe";
import { z } from "zod";

const SearchProductParams = z.object({
  query: z.string().min(2),
  maxPrice: z.number().positive(),
  limit: z.number().int().optional(),
});

const searchProductPipe = resolver.pipe(
  resolver.zod(SearchProductParams),
  normalizeQuery,
  makeSearchRequest,
  filterProducts
);

// throws if validation fails
await searchProductPipe({ query: "usb charger", maxPrice: 16.5 });

Mentions

This is heavily inspired by the resolver pipe of blitz.js. ❤️

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Created by Mark Hähnel and released under the terms of the MIT

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago