Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
fix: add coercion on http handler (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
pevisscher authored Dec 11, 2023
1 parent 1824972 commit d96dba8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@skyleague/event-horizon-dev",
"version": "4.0.4",
"version": "4.0.11",
"description": "The accompanying development package for @skyleague/event-horizon.",
"repository": {
"type": "git",
Expand All @@ -26,7 +26,7 @@
"package.json"
],
"scripts": {
"build": "npx ts-node --esm build.config.ts",
"build": "npx tsx build.config.ts",
"build:docs": "npx typedoc",
"check:cost": "npx cost-of-modules --no-install --include-dev",
"check:coverage": "npx vitest run --coverage=true",
Expand Down Expand Up @@ -85,7 +85,8 @@
"node-standards": {
"extends": "yargs-cli",
"rules": {
"exports": false
"exports": false,
"scripts": false
}
}
}
11 changes: 11 additions & 0 deletions src/lib/event-horizon/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export function httpEvent<
event.raw.isBase64Encoded ? Buffer.from(b.toString()).toString('base64') : b
) as typeof event.raw.body
}

// force coercion
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
http.schema.body?.is?.(event.body)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
http.schema.headers?.is?.(event.headers)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
http.schema.query?.is?.(event.query)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
http.schema.path?.is?.(event.path)

event.raw.headers ??= (event.headers as typeof event.raw.headers) ?? {}

Check warning on line 56 in src/lib/event-horizon/http/http.ts

View workflow job for this annotation

GitHub Actions / typescript / check

Unnecessary conditional, expected left-hand side of `??` operator to be possibly null or undefined

Check warning on line 56 in src/lib/event-horizon/http/http.ts

View workflow job for this annotation

GitHub Actions / typescript / check

Unnecessary conditional, value is `never`
event.raw.queryStringParameters ??= (event.query as typeof event.raw.queryStringParameters) ?? {}

Check warning on line 57 in src/lib/event-horizon/http/http.ts

View workflow job for this annotation

GitHub Actions / typescript / check

Unnecessary conditional, left-hand side of `??` operator is always `null` or `undefined`
const rawEvent = event.raw
Expand Down

0 comments on commit d96dba8

Please sign in to comment.