-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@whook/aws-lambda): add a better query parser
- Loading branch information
Showing
6 changed files
with
45 additions
and
35 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
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,37 @@ | ||
import { initializer } from 'knifecycle'; | ||
import qs from 'qs'; | ||
import { WhookQueryStringParser } from '@whook/http-router'; | ||
import { castParameterValue } from '../wrappers/awsHTTPLambda'; | ||
|
||
// A custom query parser that mimic the AWS one behavior | ||
// for local development | ||
// WARNING: AWS API Gateway Lambda Proxy does not support | ||
// query params repetition (ie foo=bar&foo=bar2) | ||
// TODO: this parser should reflect that | ||
export default initializer( | ||
{ | ||
name: 'QUERY_PARSER', | ||
type: 'service', | ||
inject: [], | ||
}, | ||
async () => { | ||
return ((parameters, search) => { | ||
const queryStringParameters = qs.parse(search.slice(1)); | ||
|
||
return castParameters( | ||
parameters ? parameters.filter(p => 'query' === (p as any).in) : [], | ||
queryStringParameters, | ||
); | ||
}) as WhookQueryStringParser; | ||
}, | ||
); | ||
|
||
function castParameters(parameters, values) { | ||
(parameters || []).forEach(parameter => { | ||
values[parameter.name] = castParameterValue( | ||
parameter, | ||
values[parameter.name], | ||
); | ||
}); | ||
return values; | ||
} |
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
8 changes: 4 additions & 4 deletions
8
packages/whook-create/src/services/__snapshots__/createWhook.test.ts.snap
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
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