Skip to content

Commit

Permalink
Merge pull request #284 from myrotvorets/renovate/linters
Browse files Browse the repository at this point in the history
chore(deps): update dependency @myrotvorets/eslint-config-myrotvorets-ts to ^2.22.4
  • Loading branch information
myrotvorets-team authored Oct 13, 2023
2 parents 5b2484c + 42d0e4d commit 5749bf2
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 94 deletions.
67 changes: 4 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
"@myrotvorets/facex": "^2.6.1",
"@myrotvorets/oav-installer": "^4.1.0",
"@myrotvorets/opentelemetry-configurator": "^6.4.1",
"@opentelemetry/instrumentation-express": "^0.33.1",
"@opentelemetry/instrumentation-http": "^0.44.0",
"envalid": "^8.0.0",
"express": "^4.18.2",
"express-openapi-validator": "^5.0.6",
"morgan": "^1.10.0"
},
"devDependencies": {
"@myrotvorets/eslint-config-myrotvorets-ts": "^2.21.0",
"@myrotvorets/eslint-config-myrotvorets-ts": "^2.22.4",
"@types/chai": "^4.3.8",
"@types/chai-as-promised": "^7.1.6",
"@types/express": "^4.17.19",
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/video.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface UploadResponse {
function uploadHandler(service: VideoService): RequestHandler {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
return async (req: Request, res: Response<UploadResponse>): Promise<void> => {
const guid = await service.upload((req.files as Express.Multer.File[])[0]);
const guid = await service.upload((req.files as Express.Multer.File[])[0]!);
res.json({
success: true,
guid,
Expand Down
10 changes: 2 additions & 8 deletions src/lib/tracing.mts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
/* c8 ignore start */
import { OpenTelemetryConfigurator } from '@myrotvorets/opentelemetry-configurator';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';

if (!+(process.env.ENABLE_TRACING || 0)) {
process.env.OTEL_SDK_DISABLED = 'true';
}
import { OpenTelemetryConfigurator, getExpressInstrumentations } from '@myrotvorets/opentelemetry-configurator';

const configurator = new OpenTelemetryConfigurator({
serviceName: 'psb-api-videntigraf',
instrumentations: [new ExpressInstrumentation(), new HttpInstrumentation()],
instrumentations: [...getExpressInstrumentations()],
});

configurator.start();
Expand Down
14 changes: 9 additions & 5 deletions src/middleware/error.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@ import { BadRequestError } from '../lib/badrequesterror.mjs';
export function faceXErrorHandlerMiddleware(err: unknown, req: Request, res: Response, next: NextFunction): void {
if (err && typeof err === 'object') {
if (err instanceof UploadError) {
return next({
next({
success: false,
status: 400,
code: 'UPLOAD_FAILED',
message: `${err.message} (${err.file})`,
});
return;
}

if (err instanceof HttpError || err instanceof NetworkError || err instanceof BadResponseError) {
return next(badGatewayFromError(err));
next(badGatewayFromError(err));
return;
}

if (err instanceof BadRequestError) {
return next({
next({
success: false,
status: 400,
code: 'BAD_REQUEST',
message: `${err.message}`,
});
return;
}

if (err instanceof FaceXError) {
return next(errorResponseFromFaceXError(err));
next(errorResponseFromFaceXError(err));
return;
}
}

return next(err);
next(err);
}
6 changes: 3 additions & 3 deletions src/middleware/upload.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export function uploadErrorHandlerMiddleware(err: unknown, _req: Request, _res:
break;
}

return next(response);
next(response);
} else {
next(err);
}

return next(err);
}
2 changes: 1 addition & 1 deletion src/server.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function configureApp(app: Express): Promise<void> {
);

/* c8 ignore start */
if (process.env.HAVE_SWAGGER === 'true') {
if (process.env['HAVE_SWAGGER'] === 'true') {
app.get('/', (_req, res) => res.redirect('/swagger/'));
}
/* c8 ignore stop */
Expand Down
8 changes: 4 additions & 4 deletions src/services/video.mts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export class VideoService {

const attrs = response.attributes();
return {
detections: +attrs.d || 0,
matches: +attrs.m || 0,
d_archives: +attrs.d_arx || 0,
m_archives: +attrs.m_arx || 0,
detections: +(attrs['d'] ?? 0),
matches: +(attrs['m'] ?? 0),
d_archives: +(attrs['d_arx'] ?? 0),
m_archives: +(attrs['m_arx'] ?? 0),
};
}

Expand Down
5 changes: 2 additions & 3 deletions test/functional/controllers/monitoring.test.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import express, { type Express } from 'express';
import { expect } from 'chai';
import request from 'supertest';
import type { HealthChecker } from '@cloudnative/health-connect';
import { healthChecker, monitoringController } from '../../../src/controllers/monitoring.mjs';

describe('MonitoringController', function () {
Expand All @@ -15,7 +14,7 @@ describe('MonitoringController', function () {

beforeEach(function () {
expect(healthChecker).not.to.be.undefined;
(healthChecker as HealthChecker).shutdownRequested = false;
healthChecker!.shutdownRequested = false;
});

afterEach(function () {
Expand All @@ -26,7 +25,7 @@ describe('MonitoringController', function () {
request(app).get(`/monitoring/${endpoint}`).expect('Content-Type', /json/u).expect(200);

const checker503 = (endpoint: string): Promise<unknown> => {
(healthChecker as HealthChecker).shutdownRequested = true;
healthChecker!.shutdownRequested = true;
return request(app).get(`/monitoring/${endpoint}`).expect('Content-Type', /json/u).expect(503);
};

Expand Down
6 changes: 3 additions & 3 deletions test/unit/services/fakeclient.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export const getVideoStatus = func<typeof FaceXVideoClient.prototype.getVideoSta
export const getVideoResult = func<typeof FaceXVideoClient.prototype.getVideoResult>();

export class FakeFaceXVideoClient extends FaceXVideoClient {
public uploadVideo(video: VideoType, priority?: VideoUploadPriority): Promise<VideoUploadAck> {
public override uploadVideo(video: VideoType, priority?: VideoUploadPriority): Promise<VideoUploadAck> {
return uploadVideo(video, priority);
}

public getVideoStatus(guid: string): Promise<VideoStatus> {
public override getVideoStatus(guid: string): Promise<VideoStatus> {
return getVideoStatus(guid);
}

public getVideoResult(guid: string, type: VideoResultType, archiveNumber?: number): Promise<VideoResult> {
public override getVideoResult(guid: string, type: VideoResultType, archiveNumber?: number): Promise<VideoResult> {
return getVideoResult(guid, type, archiveNumber);
}
}
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"noUnusedLocals": true,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
Expand Down

0 comments on commit 5749bf2

Please sign in to comment.