Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/connorgiles/lambda-func
https://github.com/connorgiles/lambda-func
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/connorgiles/lambda-func
- Owner: connorgiles
- Created: 2021-12-27T03:59:18.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-30T03:22:52.000Z (almost 3 years ago)
- Last Synced: 2024-07-28T17:24:00.890Z (4 months ago)
- Language: TypeScript
- Size: 365 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-zod - `@lambda-func/zod` - A middleware to use zod for type parsing. (APIs and Servers)
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)`.