1 | <p align="center">
|
2 | <a href="https://reacttraining.com/react-router/">
|
3 | <img alt="lambcycle" src="https://raw.githubusercontent.com/juliantellez/lambcycle/master/assets/lambcycle-logo.svg?sanitize=true" width="144">
|
4 | </a>
|
5 | </p>
|
6 |
|
7 | <p align="center">
|
8 | Lambcycle is a declarative <a href="https://aws.amazon.com/lambda/">lambda</a> middleware. Its main purpose is to let you focus on the specifics of your application by providing a configuration cycle.
|
9 | </p>
|
10 |
|
11 |
|
12 |
|
13 | <p align="center">
|
14 |
|
15 | <a href="https://www.npmjs.com/package/lambcycle">
|
16 | <img src="https://img.shields.io/npm/v/lambcycle.svg?style=flat-square" style="padding:3px">
|
17 | </a>
|
18 |
|
19 |
|
20 | <a href="https://npmcharts.com/compare/webpack?minimal=true">
|
21 | <img src="https://img.shields.io/npm/dm/lambcycle.svg?style=flat-square" style="padding:3px">
|
22 | </a>
|
23 |
|
24 |
|
25 | <a href="https://travis-ci.org/juliantellez/lambcycle/">
|
26 | <img src="https://img.shields.io/travis/juliantellez/lambcycle/master.svg?style=flat-square" style="padding:3px">
|
27 | </a>
|
28 |
|
29 |
|
30 | <a href="https://packagephobia.now.sh/result?p=lambcycle">
|
31 | <img src="https://packagephobia.now.sh/badge?p=lambcycle"style="padding:3px">
|
32 | </a>
|
33 |
|
34 |
|
35 | <a href="https://david-dm.org/juliantellez/lambcycle">
|
36 | <img src="https://david-dm.org/juliantellez/lambcycle/status.svg" style="padding:3px">
|
37 | </a>
|
38 |
|
39 |
|
40 | <a href="https://david-dm.org/juliantellez/lambcycle?type=dev">
|
41 | <img src="https://david-dm.org/juliantellez/lambcycle/dev-status.svg" style="padding:3px">
|
42 | </a>
|
43 |
|
44 |
|
45 | <a href="https://coveralls.io/github/juliantellez/lambcycle">
|
46 | <img src="https://coveralls.io/repos/github/juliantellez/lambcycle/badge.svg?branch=master" style="padding:3px">
|
47 | </a>
|
48 |
|
49 |
|
50 | <a href="https://snyk.io/test/github/juliantellez/lambcycle?targetFile=package.json">
|
51 | <img src="https://snyk.io/test/github/juliantellez/lambcycle/badge.svg?targetFile=package.json" alt="Known Vulnerabilities" style="max-width:100%; padding:3px;">
|
52 | </a>
|
53 | </p>
|
54 |
|
55 |
|
56 | <p align="center">
|
57 | <a href="https://opensource.org/licenses/MIT">
|
58 | <img src="https://opensource.org/files/osi_keyhole_300X300_90ppi_0.png" height=50 alt="MIT License">
|
59 | </a>
|
60 | </p>
|
61 |
|
62 |
|
63 |
|
64 | <h2 align="center">Getting Started</h2>
|
65 |
|
66 | <h3>Install</h3>
|
67 |
|
68 | ```bash
|
69 | # with npm
|
70 | npm install --save lambcycle
|
71 |
|
72 | # with yarn
|
73 | yarn add lambcycle
|
74 | ```
|
75 |
|
76 | ```javascript
|
77 | // with es6
|
78 |
|
79 | import lambcycle, { bodyParser, joi as lambcycleJoi, pino } from "lambcycle";
|
80 | import Joi from "joi";
|
81 |
|
82 | import applicationLogic from "./mycode";
|
83 |
|
84 | const processData = async (event, context) => {
|
85 | // beautiful application logic ...
|
86 |
|
87 | const manipulateData = event => {
|
88 | // ...
|
89 | };
|
90 |
|
91 | return await applicationLogic(manipulateData(event), context);
|
92 | };
|
93 |
|
94 | const schema = Joi.object()
|
95 | .keys({
|
96 | username: Joi.string()
|
97 | .alphanum()
|
98 | .min(3)
|
99 | .max(30)
|
100 | .required(),
|
101 | password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/),
|
102 | access_token: [Joi.string(), Joi.number()],
|
103 | birthyear: Joi.number()
|
104 | .integer()
|
105 | .min(1900)
|
106 | .max(2013),
|
107 | email: Joi.string().email({ minDomainAtoms: 2 })
|
108 | })
|
109 | .with("username", "birthyear")
|
110 | .without("password", "access_token");
|
111 |
|
112 | const handler = lambcycle(processData).register([
|
113 | pino,
|
114 | bodyParser,
|
115 | lambcycleJoi(schema)
|
116 | ]);
|
117 |
|
118 | export default handler;
|
119 | ```
|