Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/connorgiles/lambda-func


https://github.com/connorgiles/lambda-func

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# Lambda Middleware

[![@lambda-func CI/CD](https://github.com/connorgiles/lambda-func/actions/workflows/ci.yml/badge.svg)](https://github.com/connorgiles/lambda-func/actions/workflows/ci.yml)

This monorepo contains the a set of higher order functions and utilities to create composable middleware for lambda functions.

## Published Packages

[View published pacakges here](https://www.npmjs.com/org/lambda-func)

## Usage

```typescript
import { z } from 'zod'
import { compose, Controller } from '@lambda-func/core'
import { sqs } from '@lambda-func/sqs'
import { inject } from '@lambda-func/inject'
import { select } from '@lambda-func/select'
import { zodParser } from '@lambda-func/zod'

import { Database, Logger } from '../services'

const wrapper = compose(
sqs(),
select((record) => record.body),
zodParser(
z.object({
id: z.string(),
name: z.string()
})
),
inject('db', Database),
inject('logger', Logger)
)

// easily testable controller
export const controller: Controller = async (record, { logger, db }) => {
logger.info('Saving record to database')
await db.save(record)
}

export const handler = wrapper(controller)
```

## Rush

This repo uses [rush](https://rushjs.io/) to maintain a monorepo of packages. [Learn the basics 👉](https://rushjs.io/pages/developer/new_developer/)

### Installation

```
npm i -g @microsoft/rush
```

### Useful Commands

- `rush build` - build pacakges that need it
- `rush test` - test all packages
- `rush create-package --name package-name` - create a new package based on the provided [template](./internals/template/)
- `rush rebuild` - builds all packages
- `rush publish` - publish all packages
- `rush purge` - to clean up temporary files created by rush

### Installing Dependencies

With rush, you often will work from the directory of the individual "project" (package) you are working on. If you want to add a dependency to to that project then you run `rush add --package example-package (--dev)`.