-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from MathRobin/esm-only
Esm only
- Loading branch information
Showing
31 changed files
with
4,166 additions
and
3,797 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# GENERATED FILE - Do not edit manually | ||
root = true | ||
|
||
[*] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
# GENERATED FILE - Do not edit manually | ||
env: | ||
node: true | ||
es2021: true | ||
es2023: true | ||
jest/globals: true | ||
plugins: | ||
- jest | ||
ignorePatterns: | ||
- "**/*.test.js" | ||
- json | ||
extends: | ||
- eslint:recommended | ||
- prettier | ||
- plugin:json/recommended | ||
parserOptions: | ||
ecmaVersion: 2021 | ||
ecmaVersion: 2022 | ||
sourceType: module | ||
requireConfigFile: false | ||
babelOptions: | ||
plugins: | ||
- '@babel/plugin-syntax-import-assertions' | ||
parser: '@babel/eslint-parser' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.yarn/** linguist-vendored | ||
/.yarn/releases/* binary | ||
/.yarn/plugins/**/* binary | ||
/.pnp.* binary linguist-generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
18.13.0 | ||
18.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# GENERATED FILE - Do not edit manually | ||
# Ignore artifacts: | ||
build | ||
coverage |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
defaultSemverRangePrefix: "" | ||
compressionLevel: mixed | ||
|
||
defaultSemverRangePrefix: '' | ||
|
||
enableGlobalCache: false | ||
|
||
nmMode: classic | ||
|
||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.6.4.cjs | ||
yarnPath: .yarn/releases/yarn-4.0.2.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,102 @@ | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
![Static Badge](https://img.shields.io/badge/coverage-100-brightgreen) | ||
![Static Badge](https://img.shields.io/badge/release-3.0.1-blue) | ||
[![test](https://github.com/mathrobin/lambda-returns/actions/workflows/test.yml/badge.svg)](https://github.com/mathrobin/lambda-returns/actions/workflows/test.yml) | ||
|
||
# lambda-returns | ||
|
||
Provides shorthand to manage AWS lambda result. And provides test helper methods too! | ||
|
||
ESM only since v3. Typings included. | ||
|
||
## Usage | ||
|
||
Deadly simple | ||
|
||
```javascript | ||
import { ok, internalServerError } from 'lambda-returns'; | ||
|
||
export default async () => { | ||
try { | ||
return ok({ | ||
status: 'success', | ||
}); | ||
} catch (err) { | ||
return internalServerError({ | ||
status: 'error', | ||
error: err, | ||
}); | ||
} | ||
}; | ||
``` | ||
|
||
instead of that non-funny code: | ||
|
||
```javascript | ||
export default async () => { | ||
try { | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
status: 'success', | ||
}), | ||
}; | ||
} catch (err) { | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify({ | ||
status: 'error', | ||
error: err, | ||
}), | ||
}; | ||
} | ||
}; | ||
``` | ||
|
||
### Test helpers methods | ||
|
||
Not enough for you? For me too. This package provides a simple way to test your return result from your AWS lambda | ||
handler method. | ||
|
||
```javascript | ||
import { isOk, isBadRequest } from 'lambda-returns'; | ||
|
||
expect(isOk(result)).toBeTruthy(); | ||
expect(isBadRequest(result)).toBeTruthy(); | ||
``` | ||
|
||
## Pros | ||
|
||
- No prod dependency | ||
- Typings provided | ||
- lower than 45kB unpacked | ||
|
||
### Stop remember codes | ||
|
||
You don't have to remember status code values. Just the name which is more "menaningful". Who really knows the code of: | ||
|
||
- insufficientStorage | ||
- partialContent | ||
- imATeapot | ||
|
||
You ? Me no. And don't want/need to. | ||
|
||
### Stop polluting your business logic | ||
|
||
Moreover, into vanilla AWS lambda way, you need to return a string as body. But just stringify your result is dangerous, | ||
if you have a dynamic result, maybe is null, maybe is undefined, maybe you already have a string. | ||
|
||
F\*ck! I don't want to care of it in my business logic! `lambda-returns` manages it for you. | ||
|
||
## Cons | ||
|
||
There is only one known pitfall. We can't technically export "continue" status due to it's a reserved word in | ||
JavaScript. | ||
|
||
```javascript | ||
export const continue = {}; // or whatever; | ||
``` | ||
|
||
This is just forbidden. If you knwon any way to go over this problem, tell me. | ||
|
||
Despite to this problem, test helper method `isContinue` is available. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
export default { | ||
continue: 100, | ||
switchingProtocols: 101, | ||
processing: 102, | ||
ok: 200, | ||
created: 201, | ||
accepted: 202, | ||
nonAuthoritativeInformation: 203, | ||
noContent: 204, | ||
resetContent: 205, | ||
partialContent: 206, | ||
multiStatus: 207, | ||
multipleChoices: 300, | ||
movedPermanently: 301, | ||
movedTemporarily: 302, | ||
seeOther: 303, | ||
notModified: 304, | ||
useProxy: 305, | ||
temporaryRedirect: 307, | ||
badRequest: 400, | ||
unauthorized: 401, | ||
paymentRequired: 402, | ||
forbidden: 403, | ||
notFound: 404, | ||
methodNotAllowed: 405, | ||
notAcceptable: 406, | ||
proxyAuthenticationRequired: 407, | ||
requestTimeOut: 408, | ||
conflict: 409, | ||
gone: 410, | ||
lengthRequired: 411, | ||
preconditionFailed: 412, | ||
requestEntityTooLarge: 413, | ||
requestUriTooLarge: 414, | ||
unsupportedMediaType: 415, | ||
requestedRangeNotSatisfiable: 416, | ||
expectationFailed: 417, | ||
imATeapot: 418, | ||
unprocessableEntity: 422, | ||
locked: 423, | ||
failedDependency: 424, | ||
unorderedCollection: 425, | ||
upgradeRequired: 426, | ||
preconditionRequired: 428, | ||
tooManyRequests: 429, | ||
requestHeaderFieldsTooLarge: 431, | ||
internalServerError: 500, | ||
notImplemented: 501, | ||
badGateway: 502, | ||
serviceUnavailable: 503, | ||
gatewayTimeOut: 504, | ||
httpVersionNotSupported: 505, | ||
variantAlsoNegotiates: 506, | ||
insufficientStorage: 507, | ||
bandwidthLimitExceeded: 509, | ||
notExtended: 510, | ||
networkAuthenticationRequired: 511, | ||
}; |
Oops, something went wrong.