Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/markhaehnel/resolver-pipe
A functional pipe with validators for TypeScript
https://github.com/markhaehnel/resolver-pipe
functional-programming typescript validator
Last synced: about 1 month ago
JSON representation
A functional pipe with validators for TypeScript
- Host: GitHub
- URL: https://github.com/markhaehnel/resolver-pipe
- Owner: markhaehnel
- License: mit
- Created: 2022-03-22T12:46:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-08T14:53:12.000Z (almost 2 years ago)
- Last Synced: 2024-09-18T20:19:31.415Z (about 2 months ago)
- Topics: functional-programming, typescript, validator
- Language: TypeScript
- Homepage:
- Size: 1.12 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/colinhacks/zod).
## Installation
To install resolver-pipe:
```bash
npm install @markhaehnel/resolver-pipe
```## Usage
```ts
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
```ts
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](https://blitzjs.com/docs/resolver-server-utilities#resolver-pipe) of [blitz.js](https://blitzjs.com/). ❤️
## 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](https://choosealicense.com/licenses/mit/)