@markhaehnel/resolver-pipe
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

Resolver Pipe

TypeScript logo

npm Resolver Pipe CI Status License


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

Readme

Keywords

Package Sidebar

Install

npm i @markhaehnel/resolver-pipe

Weekly Downloads

21

Version

1.1.3

License

MIT

Unpacked Size

29.7 kB

Total Files

7

Last publish

Collaborators

  • markhaehnel