From 1ec3701072bb7ce91e3b22bebca73ac2dcc6497e Mon Sep 17 00:00:00 2001 From: Aitor Algorta Date: Fri, 9 Feb 2024 09:35:34 +0100 Subject: [PATCH] lint --- .../backend/src/app.ts | 156 +++++++++++------- .../backend/src/providers/karapace.ts | 86 +++++----- .../backend/src/types.ts | 6 +- 3 files changed, 138 insertions(+), 110 deletions(-) diff --git a/backend/components/schema-registry-manager/backend/src/app.ts b/backend/components/schema-registry-manager/backend/src/app.ts index fbf8e82ae..00857d77a 100644 --- a/backend/components/schema-registry-manager/backend/src/app.ts +++ b/backend/components/schema-registry-manager/backend/src/app.ts @@ -1,8 +1,16 @@ - -import dotenv from "dotenv"; -import express, { Express, Request, Response } from "express"; -import { SchemaProvider } from "./types"; -import { checkCompatibilityOfNewSchema, createSchema, deleteSchema, getLastMessage, getSchemaInfo, getSchemaVersions, getSchemas, updateSchema } from "./providers/karapace"; +import dotenv from 'dotenv'; +import express, {Express, Request, Response} from 'express'; +import {SchemaProvider} from './types'; +import { + checkCompatibilityOfNewSchema, + createSchema, + deleteSchema, + getLastMessage, + getSchemaInfo, + getSchemaVersions, + getSchemas, + updateSchema, +} from './providers/karapace'; dotenv.config(); @@ -15,22 +23,24 @@ const currentProvider: SchemaProvider = SchemaProvider.karapace; app.use(bodyParser.json()); app.get('/schemas.provider', (req: Request, res: Response) => { - res.status(200).send(currentProvider); + res.status(200).send(currentProvider); }); app.get('/schemas.list', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - getSchemas().then((response: string[]) => { - res.send(response); - }).catch((e: any) => { - res.status(500).send(e); - }); - break; + getSchemas() + .then((response: string[]) => { + res.send(response); + }) + .catch((e: any) => { + res.status(500).send(e); + }); + break; default: res.status(404).send('Provider Not Found'); break; - } + } }); app.get('/schemas.versions', (req: Request, res: Response) => { @@ -41,16 +51,18 @@ app.get('/schemas.versions', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - getSchemaVersions(req.query.topicName as string).then((response: any) => { - res.status(200).send(response); - }).catch((e: any) => { - res.status(500).send(e); - }); - break; + getSchemaVersions(req.query.topicName as string) + .then((response: any) => { + res.status(200).send(response); + }) + .catch((e: any) => { + res.status(500).send(e); + }); + break; default: res.status(404).send('Provider Not Found'); break; - } + } }); app.get('/schemas.info', (req: Request, res: Response) => { @@ -66,16 +78,18 @@ app.get('/schemas.info', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - getSchemaInfo(req.query.topicName as string, version).then((response: any) => { - res.status(200).send(response); - }).catch((e: any) => { - res.status(500).send(e); - }); - break; + getSchemaInfo(req.query.topicName as string, version) + .then((response: any) => { + res.status(200).send(response); + }) + .catch((e: any) => { + res.status(500).send(e); + }); + break; default: res.status(404).send('Provider Not Found'); break; - } + } }); app.post('/schemas.update', (req: Request, res: Response) => { @@ -90,16 +104,18 @@ app.post('/schemas.update', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - updateSchema(req.query.topicName as string, req.body.schema as string).then((response: any) => { - res.status(200).send(response); - }).catch((e: any) => { - res.status(500).send(e); - }); - break; + updateSchema(req.query.topicName as string, req.body.schema as string) + .then((response: any) => { + res.status(200).send(response); + }) + .catch((e: any) => { + res.status(500).send(e); + }); + break; default: res.status(404).send('Provider Not Found'); break; - } + } }); app.post('/schemas.create', (req: Request, res: Response) => { @@ -114,16 +130,18 @@ app.post('/schemas.create', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - createSchema(req.query.topicName as string, req.body.schema as string).then((response: any) => { - res.status(200).send(response); - }).catch((e: any) => { - res.status(500).send(e); - }); - break; + createSchema(req.query.topicName as string, req.body.schema as string) + .then((response: any) => { + res.status(200).send(response); + }) + .catch((e: any) => { + res.status(500).send(e); + }); + break; default: res.status(404).send('Provider Not Found'); break; - } + } }); app.post('/schemas.compatibility', (req: Request, res: Response) => { @@ -142,16 +160,22 @@ app.post('/schemas.compatibility', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - checkCompatibilityOfNewSchema(req.query.topicName as string, req.body.schema as string, req.query.version as string).then((response: any) => { - res.status(200).send(response); - }).catch((e: any) => { - res.status(500).send(e); - }); - break; + checkCompatibilityOfNewSchema( + req.query.topicName as string, + req.body.schema as string, + req.query.version as string + ) + .then((response: any) => { + res.status(200).send(response); + }) + .catch((e: any) => { + res.status(500).send(e); + }); + break; default: res.status(404).send('Provider Not Found'); break; - } + } }); app.post('/schemas.delete', (req: Request, res: Response) => { @@ -162,16 +186,18 @@ app.post('/schemas.delete', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - deleteSchema(req.query.topicName as string).then((response: any) => { - res.status(200).send(response); - }).catch((e: any) => { - res.status(500).send(e); - }); - break; + deleteSchema(req.query.topicName as string) + .then((response: any) => { + res.status(200).send(response); + }) + .catch((e: any) => { + res.status(500).send(e); + }); + break; default: res.status(404).send('Provider Not Found'); break; - } + } }); app.get('/schemas.lastMessage', (req: Request, res: Response) => { @@ -182,17 +208,19 @@ app.get('/schemas.lastMessage', (req: Request, res: Response) => { switch (currentProvider) { case SchemaProvider.karapace: - getLastMessage(req.query.topicName as string).then((response: any) => { - console.log(response); - res.status(200).send(response); - }).catch((e: any) => { - res.status(500).send(e); - }); - break; + getLastMessage(req.query.topicName as string) + .then((response: any) => { + console.log(response); + res.status(200).send(response); + }) + .catch((e: any) => { + res.status(500).send(e); + }); + break; default: res.status(404).send('Provider Not Found'); break; - } + } }); async function main() { @@ -201,4 +229,4 @@ async function main() { }); } -main().catch(console.error); \ No newline at end of file +main().catch(console.error); diff --git a/backend/components/schema-registry-manager/backend/src/providers/karapace.ts b/backend/components/schema-registry-manager/backend/src/providers/karapace.ts index 0885ca6aa..1f1792dd1 100644 --- a/backend/components/schema-registry-manager/backend/src/providers/karapace.ts +++ b/backend/components/schema-registry-manager/backend/src/providers/karapace.ts @@ -1,27 +1,27 @@ export async function getSchemas() { - return getData('subjects').then(response => { + return getData('subjects').then(response => { return response; }); -}; - +} + export async function getSchemaVersions(topicName: string) { return getData(`subjects/${topicName}/versions`).then(response => { if (response.error_code && response.error_code.toString().includes('404') && !topicName.includes('-value')) { return Promise.reject('404 Not Found'); } - return response; + return response; }); -}; +} -export async function getSchemaInfo(topicName: string, version: string) { +export async function getSchemaInfo(topicName: string, version: string) { return getData(`subjects/${topicName}/versions/${version}`).then(response => { if (response.error_code && response.error_code.toString().includes('404') && !topicName.includes('-value')) { return Promise.reject('404 Not Found'); } return response; }); -}; - +} + export async function updateSchema(topicName: string, schema: string) { const body = { schema: JSON.stringify({...JSON.parse(schema)}), @@ -34,8 +34,8 @@ export async function updateSchema(topicName: string, schema: string) { if (response.message) return Promise.reject(response.message); return Promise.reject('Unknown Error'); }); -}; - +} + export async function createSchema(topicName: string, schema: string) { const body = { schema: JSON.stringify({...JSON.parse(schema)}), @@ -49,8 +49,8 @@ export async function createSchema(topicName: string, schema: string) { .catch(e => { return Promise.reject(e); }); -}; - +} + export async function checkCompatibilityOfNewSchema(topicName: string, schema: string, version: string) { const body = { schema: JSON.stringify({...JSON.parse(schema)}), @@ -72,8 +72,8 @@ export async function checkCompatibilityOfNewSchema(topicName: string, schema: s .catch(e => { return Promise.reject(e); }); -}; - +} + export async function deleteSchema(topicName: string) { return deleteData(`subjects/${topicName}`).then(response => { if (response.error_code && response.error_code.toString().includes('404') && !topicName.includes('-value')) { @@ -81,8 +81,8 @@ export async function deleteSchema(topicName: string) { } return response; }); -}; - +} + export async function getLastMessage(topicName: string) { const body = { ksql: `PRINT '${topicName}' FROM BEGINNING LIMIT 1;`, @@ -92,30 +92,30 @@ export async function getLastMessage(topicName: string) { console.log(response); return response; }); -}; - - async function getData(url: string) { - const response = await fetch(process.env.URL + '/' + url, { - method: 'GET', - }); - return response.json(); - } - - async function deleteData(url: string) { - const response = await fetch(process.env.URL + '/' + url, { - method: 'DELETE', - }); - return response.json(); - } - - async function postData(url: string, body: any) { - const response = await fetch(process.env.URL + '/' + url, { - method: 'POST', - headers: { - 'Content-Type': 'application/vnd.schemaregistry.v1+json', - }, - body: JSON.stringify(body), - }); - - return response.json(); - } \ No newline at end of file +} + +async function getData(url: string) { + const response = await fetch(process.env.URL + '/' + url, { + method: 'GET', + }); + return response.json(); +} + +async function deleteData(url: string) { + const response = await fetch(process.env.URL + '/' + url, { + method: 'DELETE', + }); + return response.json(); +} + +async function postData(url: string, body: any) { + const response = await fetch(process.env.URL + '/' + url, { + method: 'POST', + headers: { + 'Content-Type': 'application/vnd.schemaregistry.v1+json', + }, + body: JSON.stringify(body), + }); + + return response.json(); +} diff --git a/backend/components/schema-registry-manager/backend/src/types.ts b/backend/components/schema-registry-manager/backend/src/types.ts index c4b80a6a5..b336be9b7 100644 --- a/backend/components/schema-registry-manager/backend/src/types.ts +++ b/backend/components/schema-registry-manager/backend/src/types.ts @@ -1,8 +1,8 @@ export enum SchemaProvider { - karapace = 'karapace', + karapace = 'karapace', confluentCloud = 'confluent-cloud', } module.exports = { - SchemaProvider: SchemaProvider -}; \ No newline at end of file + SchemaProvider: SchemaProvider, +};