Skip to content

Commit

Permalink
Apply strict rules
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Oct 12, 2023
1 parent 128c4a8 commit de95114
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/handlers.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const remoteUserHandler: TokenHandler = (req) => {
if (auth) {
const match = re.exec(auth);
if (match) {
const credentials = Buffer.from(match[1], 'base64').toString().split(':', 2);
const credentials = Buffer.from(match[1]!, 'base64').toString().split(':', 2);
return credentials.length === 2 ? credentials[0] : undefined;
}
}
Expand All @@ -63,11 +63,11 @@ export const resHandler: TokenHandler = (_req, res, param) => {
export const statusHandler: TokenHandler = (_req, res) => (res.headersSent ? res.statusCode.toString() : undefined);

export const totalTimeHandler: TokenHandler = (_req, res) => {
if (res.locals._hrl_start_time) {
if (res.locals['_hrl_start_time']) {
const now = hrtime.bigint();
const start = res.locals._hrl_start_time as unknown;
const start = res.locals['_hrl_start_time'] as unknown;
if (typeof start === 'bigint') {
const diff = now - (res.locals._hrl_start_time as bigint);
const diff = now - (res.locals['_hrl_start_time'] as bigint);
return Number(diff / BigInt(1e6)).toFixed(3);
}
}
Expand Down
5 changes: 3 additions & 2 deletions test/total-time.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ describe(':total-time', function () {
stream,
}),
(_req, res, next) => {
delete (res as Response).locals._hrl_start_time;
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete (res as Response).locals['_hrl_start_time'];
next();
},
genericHandler,
Expand All @@ -68,7 +69,7 @@ describe(':total-time', function () {
stream,
}),
(_req, res, next) => {
(res as Response).locals._hrl_start_time = 'borked';
(res as Response).locals['_hrl_start_time'] = 'borked';
next();
},
genericHandler,
Expand Down
5 changes: 5 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"noUnusedLocals": true,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"exactOptionalPropertyTypes": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
Expand Down

0 comments on commit de95114

Please sign in to comment.