Skip to content

Commit

Permalink
style(dx): apply eslint and prettier formatting and fixes
Browse files Browse the repository at this point in the history
refs #223
  • Loading branch information
ygrishajev committed Jun 8, 2024
1 parent 2c7089b commit e51169d
Show file tree
Hide file tree
Showing 723 changed files with 4,147 additions and 4,137 deletions.
33 changes: 17 additions & 16 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import packageJson from "../package.json";
import { isProd } from "./utils/constants";
import * as Sentry from "@sentry/node";
import { Scheduler } from "./scheduler";
import { apiRouter } from "./routers/apiRouter";
import { userRouter } from "./routers/userRouter";
import { web3IndexRouter } from "./routers/web3indexRouter";
import { bytesToHumanReadableSize } from "./utils/files";
import { env } from "./utils/env";
import { chainDb, syncUserSchema, userDb } from "./db/dbConnection";
import { dashboardRouter } from "./routers/dashboardRouter";
import { Hono } from "hono";
import { cors } from "hono/cors";
import { serve } from "@hono/node-server";
import { legacyRouter } from "./routers/legacyRouter";
// TODO: find out how to properly import this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import { sentry } from "@hono/sentry";
import * as Sentry from "@sentry/node";
import { Hono } from "hono";
import { cors } from "hono/cors";

import packageJson from "../package.json";
import { chainDb, syncUserSchema, userDb } from "./db/dbConnection";
import { apiRouter } from "./routers/apiRouter";
import { dashboardRouter } from "./routers/dashboardRouter";
import { internalRouter } from "./routers/internalRouter";
import { legacyRouter } from "./routers/legacyRouter";
import { userRouter } from "./routers/userRouter";
import { web3IndexRouter } from "./routers/web3indexRouter";
import { isProd } from "./utils/constants";
import { env } from "./utils/env";
import { bytesToHumanReadableSize } from "./utils/files";
import { Scheduler } from "./scheduler";

const appHono = new Hono();
appHono.use(
Expand Down Expand Up @@ -59,7 +60,7 @@ appHono.use(
sentry({
dsn: env.SentryDSN,
environment: env.NODE_ENV,
beforeSend: (event) => {
beforeSend: event => {
event.server_name = env.SentryServerName;
return event;
},
Expand All @@ -76,7 +77,7 @@ appHono.route("/web3-index", web3IndexRouter);
appHono.route("/dashboard", dashboardRouter);
appHono.route("/internal", internalRouter);

appHono.get("/status", (c) => {
appHono.get("/status", c => {
const version = packageJson.version;
const tasksStatus = scheduler.getTasksStatus();
const memoryInBytes = process.memoryUsage();
Expand Down
7 changes: 4 additions & 3 deletions apps/api/src/caching/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Sentry from "@sentry/node";
import { differenceInSeconds } from "date-fns";

import MemoryCacheEngine from "./memoryCacheEngine";
import * as Sentry from "@sentry/node";

export const cacheEngine = new MemoryCacheEngine();
const pendingRequests: { [key: string]: Promise<unknown> } = {};
Expand Down Expand Up @@ -36,11 +37,11 @@ export async function cacheResponse<T>(seconds: number, key: string, refreshRequ
if ((!cachedObject || cacheExpired) && !(key in pendingRequests)) {
// console.log(`Making request: ${key}`);
pendingRequests[key] = refreshRequest()
.then((data) => {
.then(data => {
cacheEngine.storeInCache(key, { date: new Date(), data: data }, keepData ? undefined : duration);
return data;
})
.catch((err) => {
.catch(err => {
// console.log(`Error making cache request ${err}`);
Sentry.captureException(err);
})
Expand Down
13 changes: 7 additions & 6 deletions apps/api/src/db/dbConnection.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { chainDefinitions } from "@akashnetwork/cloudmos-shared/chainDefinitions";
import { chainModels, getChainModels, userModels } from "@akashnetwork/cloudmos-shared/dbSchemas";
import { Template, TemplateFavorite, UserAddressName, UserSetting } from "@akashnetwork/cloudmos-shared/dbSchemas/user";
import pg from "pg";
import { env } from "@src/utils/env";
import { Transaction as DbTransaction } from "sequelize";
import { Sequelize } from "sequelize-typescript";
import { chainModels, getChainModels, userModels } from "@akashnetwork/cloudmos-shared/dbSchemas";
import { Template, TemplateFavorite, UserAddressName, UserSetting } from "@akashnetwork/cloudmos-shared/dbSchemas/user";
import { chainDefinitions } from "@akashnetwork/cloudmos-shared/chainDefinitions";

import { env } from "@src/utils/env";

function isValidNetwork(network: string): network is keyof typeof csMap {
return network in csMap;
Expand Down Expand Up @@ -37,7 +38,7 @@ export const chainDb = new Sequelize(csMap[env.Network], {
});

export const chainDbs: { [key: string]: Sequelize } = Object.keys(chainDefinitions)
.filter((x) => chainDefinitions[x].connectionString)
.filter(x => chainDefinitions[x].connectionString)
.reduce(
(obj, chain) => ({
...obj,
Expand Down Expand Up @@ -74,4 +75,4 @@ export async function syncUserSchema() {
await TemplateFavorite.sync();
}

export const closeConnections = async () => await Promise.all([chainDb.close(), userDb.close(), ...Object.values(chainDbs).map((db) => db.close())]);
export const closeConnections = async () => await Promise.all([chainDb.close(), userDb.close(), ...Object.values(chainDbs).map(db => db.close())]);
3 changes: 2 additions & 1 deletion apps/api/src/middlewares/privateMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { env } from "@src/utils/env";
import { Context, Next } from "hono";

import { env } from "@src/utils/env";

export async function privateMiddleware(c: Context, next: Next) {
if (!env.SecretToken) {
await next();
Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/middlewares/userMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { env } from "@src/utils/env";
import { getPayloadFromContext, verifyRsaJwt } from "../verify-rsa-jwt-cloudflare-worker-main";
import { Context } from "hono";

import { cacheEngine } from "@src/caching/helpers";
import { env } from "@src/utils/env";
import { getPayloadFromContext, verifyRsaJwt } from "../verify-rsa-jwt-cloudflare-worker-main";

export const kvStore = {
async get(key: string, format: string) {
Expand Down
9 changes: 5 additions & 4 deletions apps/api/src/routers/apiRouter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { OpenAPIHono } from "@hono/zod-openapi";
import { swaggerUI } from "@hono/swagger-ui";
import routesV1 from "../routes/v1";
import { OpenAPIHono } from "@hono/zod-openapi";

import { env } from "@src/utils/env";
import routesV1 from "../routes/v1";

export const apiRouter = new OpenAPIHono();

Expand All @@ -20,9 +21,9 @@ function registerApiVersion(version: string, baseRouter: OpenAPIHono, versionRou
const swaggerInstance = swaggerUI({ url: `/${version}/doc` });

versionRouter.get(`/swagger`, swaggerInstance);
versionRouter.get(`/swagger/`, (c) => c.redirect(`/${version}/swagger`));
versionRouter.get(`/swagger/`, c => c.redirect(`/${version}/swagger`));

versionRoutes.forEach((route) => versionRouter.route(`/`, route));
versionRoutes.forEach(route => versionRouter.route(`/`, route));
baseRouter.route(`/${version}`, versionRouter);
}

Expand Down
5 changes: 3 additions & 2 deletions apps/api/src/routers/dashboardRouter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Template, UserSetting } from "@akashnetwork/cloudmos-shared/dbSchemas/user";
import { privateMiddleware } from "@src/middlewares/privateMiddleware";
import { Hono } from "hono";

import { privateMiddleware } from "@src/middlewares/privateMiddleware";

export const dashboardRouter = new Hono();

dashboardRouter.use("*", privateMiddleware);

dashboardRouter.get("/stats", async (c) => {
dashboardRouter.get("/stats", async c => {
const userCountRequest = UserSetting.count();
const publicTemplateCountRequest = Template.count({
where: { isPublic: true }
Expand Down
7 changes: 4 additions & 3 deletions apps/api/src/routers/internalRouter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { OpenAPIHono } from "@hono/zod-openapi";
import { swaggerUI } from "@hono/swagger-ui";
import routes from "../routes/internal";
import { OpenAPIHono } from "@hono/zod-openapi";

import { env } from "@src/utils/env";
import routes from "../routes/internal";

export const internalRouter = new OpenAPIHono();

Expand All @@ -19,4 +20,4 @@ const swaggerInstance = swaggerUI({ url: `/internal/doc` });

internalRouter.get(`/swagger`, swaggerInstance);

routes.forEach((route) => internalRouter.route(`/`, route));
routes.forEach(route => internalRouter.route(`/`, route));
70 changes: 35 additions & 35 deletions apps/api/src/routers/legacyRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,53 @@ export const legacyRouter = new Hono();

const redirectStatusCode = 302; // Temporary Redirect

legacyRouter.get("/blocks", async (c) => {
legacyRouter.get("/blocks", async c => {
const limit = c.req.query("limit");
return c.redirect(`/v1/blocks${limit ? `?limit=${limit}` : ""}`, redirectStatusCode);
});

legacyRouter.get("/blocks/:height", async (c) => {
legacyRouter.get("/blocks/:height", async c => {
const height = c.req.param("height");
return c.redirect(`/v1/blocks/${height}`, redirectStatusCode);
});

legacyRouter.get("/predicted-block-date/:height/:blockWindow?", async (c) => {
legacyRouter.get("/predicted-block-date/:height/:blockWindow?", async c => {
const height = c.req.param("height");
const blockWindow = c.req.param("blockWindow");

return c.redirect(`/v1/predicted-block-date/${height}${blockWindow ? `?blockWindow=${blockWindow}` : ""}`, redirectStatusCode);
});

legacyRouter.get("/predicted-date-height/:date/:blockWindow?", async (c) => {
legacyRouter.get("/predicted-date-height/:date/:blockWindow?", async c => {
const date = c.req.param("date");
const blockWindow = c.req.param("blockWindow");

return c.redirect(`/v1/predicted-date-height/${date}${blockWindow ? `?blockWindow=${blockWindow}` : ""}`, redirectStatusCode);
});

legacyRouter.get("/transactions", async (c) => {
legacyRouter.get("/transactions", async c => {
const limit = c.req.query("limit");
return c.redirect(`/v1/transactions${limit ? `?limit=${limit}` : ""}`, redirectStatusCode);
});

legacyRouter.get("/transactions/:hash", async (c) => {
legacyRouter.get("/transactions/:hash", async c => {
const hash = c.req.param("hash");
return c.redirect(`/v1/transactions/${hash}`, redirectStatusCode);
});

legacyRouter.get("/addresses/:address", async (c) => {
legacyRouter.get("/addresses/:address", async c => {
const address = c.req.param("address");
return c.redirect(`/v1/addresses/${address}`, redirectStatusCode);
});

legacyRouter.get("/addresses/:address/transactions/:skip/:limit", async (c) => {
legacyRouter.get("/addresses/:address/transactions/:skip/:limit", async c => {
const address = c.req.param("address");
const skip = c.req.param("skip");
const limit = c.req.param("limit");
return c.redirect(`/v1/addresses/${address}/transactions/${skip}/${limit}`, redirectStatusCode);
});

legacyRouter.get("/addresses/:address/deployments/:skip/:limit", async (c) => {
legacyRouter.get("/addresses/:address/deployments/:skip/:limit", async c => {
const address = c.req.param("address");
const skip = c.req.param("skip");
const limit = c.req.param("limit");
Expand All @@ -72,118 +72,118 @@ legacyRouter.get("/addresses/:address/deployments/:skip/:limit", async (c) => {
return c.redirect(`/v1/addresses/${address}/deployments/${skip}/${limit}${q ? "?" + q : ""}`, redirectStatusCode);
});

legacyRouter.get("/providers/:address", async (c) => {
legacyRouter.get("/providers/:address", async c => {
const address = c.req.param("address");
return c.redirect(`/v1/providers/${address}`, redirectStatusCode);
});

legacyRouter.get("/providers", async (c) => {
legacyRouter.get("/providers", async c => {
return c.redirect("/v1/providers", redirectStatusCode);
});

legacyRouter.get("/providers/:provider/deployments/:skip/:limit/:status?", async (c) => {
legacyRouter.get("/providers/:provider/deployments/:skip/:limit/:status?", async c => {
const provider = c.req.param("provider");
const skip = c.req.param("skip");
const limit = c.req.param("limit");
const status = c.req.param("status");
return c.redirect(`/v1/providers/${provider}/deployments/${skip}/${limit}${status ? `?status=${status}` : ""}`, redirectStatusCode);
});

legacyRouter.get("/provider-attributes-schema", async (c) => {
legacyRouter.get("/provider-attributes-schema", async c => {
return c.redirect("/v1/provider-attributes-schema", redirectStatusCode);
});

legacyRouter.get("/provider-regions", async (c) => {
legacyRouter.get("/provider-regions", async c => {
return c.redirect("/v1/provider-regions", redirectStatusCode);
});

legacyRouter.get("/validators", async (c) => {
legacyRouter.get("/validators", async c => {
return c.redirect("/v1/validators", redirectStatusCode);
});

legacyRouter.get("/validators/:address", async (c) => {
legacyRouter.get("/validators/:address", async c => {
const address = c.req.param("address");
return c.redirect(`/v1/validators/${address}`, redirectStatusCode);
});

legacyRouter.get("/proposals", async (c) => {
legacyRouter.get("/proposals", async c => {
return c.redirect("/v1/proposals", redirectStatusCode);
});

legacyRouter.get("/proposals/:id", async (c) => {
legacyRouter.get("/proposals/:id", async c => {
const id = c.req.param("id");
return c.redirect(`/v1/proposals/${id}`, redirectStatusCode);
});

legacyRouter.get("/templates", async (c) => {
legacyRouter.get("/templates", async c => {
return c.redirect("/v1/templates", redirectStatusCode);
});

legacyRouter.get("/getNetworkCapacity", async (c) => {
legacyRouter.get("/getNetworkCapacity", async c => {
return c.redirect("/v1/network-capacity", redirectStatusCode);
});

legacyRouter.get("/marketData", async (c) => {
legacyRouter.get("/marketData", async c => {
return c.redirect("/v1/market-data", redirectStatusCode);
});

legacyRouter.get("/dashboardData", async (c) => {
legacyRouter.get("/dashboardData", async c => {
return c.redirect("/v1/dashboard-data", redirectStatusCode);
});

legacyRouter.post("/pricing", async (c) => {
legacyRouter.post("/pricing", async c => {
return c.redirect("/v1/pricing", 307);
});

legacyRouter.get("/getAuditors", async (c) => {
legacyRouter.get("/getAuditors", async c => {
return c.redirect("/v1/auditors", redirectStatusCode);
});

legacyRouter.get("/getMainnetNodes", async (c) => {
legacyRouter.get("/getMainnetNodes", async c => {
return c.redirect("/v1/nodes/mainnet", redirectStatusCode);
});

legacyRouter.get("/getSandboxNodes", async (c) => {
legacyRouter.get("/getSandboxNodes", async c => {
return c.redirect("/v1/nodes/sandbox", redirectStatusCode);
});

legacyRouter.get("/getTestnetNodes", async (c) => {
legacyRouter.get("/getTestnetNodes", async c => {
return c.redirect("/v1/nodes/testnet", redirectStatusCode);
});

legacyRouter.get("/getProviderAttributesSchema", async (c) => {
legacyRouter.get("/getProviderAttributesSchema", async c => {
return c.redirect("/v1/provider-attributes-schema", redirectStatusCode);
});

legacyRouter.get("/getMainnetVersion", async (c) => {
legacyRouter.get("/getMainnetVersion", async c => {
return c.redirect("/v1/version/mainnet", redirectStatusCode);
});

legacyRouter.get("/getSandboxVersion", async (c) => {
legacyRouter.get("/getSandboxVersion", async c => {
return c.redirect("/v1/version/sandbox", redirectStatusCode);
});

legacyRouter.get("/getTestnetVersion", async (c) => {
legacyRouter.get("/getTestnetVersion", async c => {
return c.redirect("/v1/version/testnet", redirectStatusCode);
});

legacyRouter.get("/deployment/:owner/:dseq", async (c) => {
legacyRouter.get("/deployment/:owner/:dseq", async c => {
const owner = c.req.param("owner");
const dseq = c.req.param("dseq");
return c.redirect(`/v1/deployment/${owner}/${dseq}`, redirectStatusCode);
});

legacyRouter.get("/getProviderGraphData/:dataName", async (c) => {
legacyRouter.get("/getProviderGraphData/:dataName", async c => {
const dataName = c.req.param("dataName");
return c.redirect(`/v1/provider-graph-data/${dataName}`, redirectStatusCode);
});

legacyRouter.get("/getProviderActiveLeasesGraphData/:address", async (c) => {
legacyRouter.get("/getProviderActiveLeasesGraphData/:address", async c => {
const address = c.req.param("address");
return c.redirect(`/v1/provider-active-leases-graph-data/${address}`, redirectStatusCode);
});

legacyRouter.get("/getGraphData/:dataName", async (c) => {
legacyRouter.get("/getGraphData/:dataName", async c => {
const dataName = c.req.param("dataName");
return c.redirect(`/v1/graph-data/${dataName}`, redirectStatusCode);
});
Loading

0 comments on commit e51169d

Please sign in to comment.