Skip to content

Commit

Permalink
refactor: merge all env.ts files into a single package @blobscan/env
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloCastellano committed Jun 2, 2024
1 parent 238c4c4 commit a19327d
Show file tree
Hide file tree
Showing 53 changed files with 271 additions and 329 deletions.
1 change: 1 addition & 0 deletions apps/rest-api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"license": "MIT",
"dependencies": {
"@blobscan/api": "workspace:^0.9.0",
"@blobscan/env": "workspace:^0.0.1",
"@blobscan/logger": "workspace:^0.1.0",
"@blobscan/open-telemetry": "workspace:^0.0.7",
"@blobscan/stats-syncer": "workspace:^0.1.8",
Expand Down
2 changes: 1 addition & 1 deletion apps/rest-api-server/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from "@sentry/node";

import { env } from "./src/env";
import { env } from "@blobscan/env";

Sentry.init({
dsn: env.SENTRY_DSN_API,
Expand Down
49 changes: 0 additions & 49 deletions apps/rest-api-server/src/env.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/rest-api-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
metricsHandler,
gracefulShutdown as apiGracefulShutdown,
} from "@blobscan/api";
import { env } from "@blobscan/env";
import { collectDefaultMetrics } from "@blobscan/open-telemetry";
import { StatsSyncer } from "@blobscan/stats-syncer";

import { env } from "./env";
import { logger } from "./logger";
import { morganMiddleware } from "./morgan";
import { openApiDocument } from "./openapi";
Expand Down
3 changes: 1 addition & 2 deletions apps/rest-api-server/src/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { generateOpenApiDocument } from "trpc-openapi";

import { appRouter } from "@blobscan/api";

import { env } from "./env";
import { env } from "@blobscan/env";

// Generate OpenAPI schema document
export const openApiDocument = generateOpenApiDocument(appRouter, {
Expand Down
3 changes: 1 addition & 2 deletions apps/rest-api-server/src/scripts/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";

import { env } from "@blobscan/env";
import { setUpOpenTelemetry } from "@blobscan/open-telemetry";

import { env } from "../env";

if (env.TRACES_ENABLED) {
setUpOpenTelemetry("blobscan_rest_api", {
instrumentations: [new ExpressInstrumentation()],
Expand Down
7 changes: 2 additions & 5 deletions apps/rest-api-server/src/scripts/print-banner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { env as apiEnv } from "@blobscan/api";

import { env as restEnv } from "../env";
import { env } from "@blobscan/env";

function run() {
console.log(" ____ _ _");
Expand All @@ -11,8 +9,7 @@ function run() {
console.log("Blobscan REST API (EIP-4844 blob explorer) - blobscan.com");
console.log("====================================================\n");

restEnv.display();
apiEnv.display();
env.display();
}

run();
2 changes: 1 addition & 1 deletion apps/rest-api-server/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Environment } from "./env";
import type { Environment } from "@blobscan/env";

export function getNetworkDencunForkSlot(
networkName: Environment["NETWORK_NAME"]
Expand Down
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@blobscan/api": "workspace:^0.9.2",
"@blobscan/blob-decoder": "workspace:^0.1.0",
"@blobscan/dayjs": "workspace:^0.0.2",
"@blobscan/env": "workspace:^0.0.1",
"@blobscan/open-telemetry": "workspace:^0.0.7",
"@fontsource/inter": "^4.5.15",
"@fontsource/public-sans": "^4.5.12",
Expand Down
2 changes: 1 addition & 1 deletion clis/blob-propagation-jobs-cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import type {
BlobPropagationQueue,
} from "@blobscan/blob-propagator";
import { prisma } from "@blobscan/db";
import { env } from "@blobscan/env";

import type { QueueHumanName } from "../Context";
import { context } from "../context-instance";
import { env } from "../env";
import type { Command } from "../types";
import {
blobHashOptionDef,
Expand Down
2 changes: 1 addition & 1 deletion clis/blob-propagation-jobs-cli/src/context-instance.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { $Enums } from "@blobscan/db";
import { BlobStorage } from "@blobscan/db";
import { env } from "@blobscan/env";

import { Context } from "./Context";
import { env } from "./env";

const availableStorages: $Enums.BlobStorage[] = [];

Expand Down
23 changes: 0 additions & 23 deletions clis/blob-propagation-jobs-cli/src/env.ts

This file was deleted.

2 changes: 1 addition & 1 deletion clis/blob-propagation-jobs-cli/test/commands/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import IORedis from "ioredis";
import { afterAll, beforeEach, describe, expect, it } from "vitest";

import type { BlobPropagationWorker } from "@blobscan/blob-propagator";
import { env } from "@blobscan/env";

import { retry, retryCommandUsage } from "../../src/commands";
import { context } from "../../src/context-instance";
import { env } from "../../src/env";
import {
processJobsManually,
argHelpTest,
Expand Down
10 changes: 8 additions & 2 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
extends:
file: docker-compose.yml
service: web
image: blossomlabs/blobscan:local
build: .
ports:
- 5556:5556 # Prisma studio
Expand All @@ -15,7 +14,6 @@ services:
extends:
file: docker-compose.yml
service: api
image: blossomlabs/blobscan:local
build: .
depends_on:
- postgres
Expand All @@ -24,6 +22,8 @@ services:

postgres:
image: postgres:15
profiles:
- dev
ports:
- 5432:5432
volumes:
Expand All @@ -35,6 +35,8 @@ services:

storage:
image: fsouza/fake-gcs-server
profiles:
- dev
ports:
- "4443:4443"
command: ["-scheme", "http", "-port", "4443", "-data", "/data"]
Expand All @@ -46,6 +48,8 @@ services:

redis:
image: "redis:alpine"
profiles:
- dev
command: redis-server /usr/local/etc/redis/redis.conf
ports:
- "6379:6379"
Expand All @@ -59,6 +63,8 @@ services:

collector:
image: otel/opentelemetry-collector:0.23.0
profiles:
- dev
command: "--config /etc/otel-config.yaml"
volumes:
- ./otel-config.yaml:/etc/otel-config.yaml
Expand Down
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3.7"

services:
web:
image: blossomlabs/blobscan:stable
image: blossomlabs/blobscan:${BLOBSCAN_TAG}
command: web
restart: always
ports:
Expand All @@ -12,7 +12,7 @@ services:
- ".env"

api:
image: blossomlabs/blobscan:stable
image: blossomlabs/blobscan:${BLOBSCAN_TAG}
command: api
restart: always
ports:
Expand All @@ -23,6 +23,8 @@ services:
timeout: 10s
retries: 5
start_period: 5s
volumes:
- /tmp/blobscan-blobs:/tmp/blobscan-blobs
env_file:
- ".env"

Expand Down
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@blobscan/blob-storage-manager": "workspace:^0.3.2",
"@blobscan/dayjs": "workspace:^0.0.2",
"@blobscan/db": "workspace:^0.7.0",
"@blobscan/env": "workspace:^0.0.1",
"@blobscan/logger": "workspace:^0.1.0",
"@blobscan/open-telemetry": "workspace:^0.0.7",
"@blobscan/zod": "workspace:^0.1.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import jwt from "jsonwebtoken";
import { getBlobPropagator } from "@blobscan/blob-propagator";
import { getBlobStorageManager } from "@blobscan/blob-storage-manager";
import { prisma } from "@blobscan/db";

import { env } from "./env";
import { env } from "@blobscan/env";

export type CreateContextOptions =
| NodeHTTPCreateContextFnOptions<NodeHTTPRequest, NodeHTTPResponse>
Expand Down
32 changes: 0 additions & 32 deletions packages/api/src/env.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type {

export * from "@trpc/server/adapters/express";

export { env } from "./env";
export { gracefulShutdown } from "./graceful-shutdown";
export { metricsHandler } from "./instrumentation";
export type {
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import type {

import { prisma } from "@blobscan/db";
import type { MetricsClient } from "@blobscan/db";
import { env } from "@blobscan/env";
import { api, promRegister } from "@blobscan/open-telemetry";

import { env } from "./env";

const scopeName = "blobscan_api";

function hasMetricsClient(
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routers/indexer/indexData.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type {
WithoutTimestampFields,
} from "@blobscan/db";
import { Prisma, Rollup } from "@blobscan/db";
import { env } from "@blobscan/env";

import { env } from "../../env";
import type { IndexDataFormattedInput } from "./indexData";

const MIN_BLOB_BASE_FEE = BigInt(1);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { describe, expect, it } from "vitest";

import { createBlobPropagator } from "@blobscan/blob-propagator/src/blob-propagator";
import type { Rollup } from "@blobscan/db";
import { env } from "@blobscan/env";

import { env } from "../src";
import { createTRPCContext } from "../src/context";
import type { ZodExpandEnum } from "../src/middlewares/withExpands";
import type { FiltersSchema } from "../src/middlewares/withFilters";
Expand Down
1 change: 1 addition & 0 deletions packages/blob-propagator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dependencies": {
"@blobscan/blob-storage-manager": "workspace:^0.3.2",
"@blobscan/db": "workspace:^0.7.0",
"@blobscan/env": "workspace:^0.0.1",
"@blobscan/logger": "workspace:^0.1.0",
"@blobscan/open-telemetry": "workspace:^0.0.7",
"@blobscan/zod": "workspace:^0.1.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/blob-propagator/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Queue } from "bullmq";
import IORedis from "ioredis";
import { afterAll } from "vitest";

import { env } from "@blobscan/env";

import { FINALIZER_WORKER_NAME, STORAGE_WORKER_NAMES } from "./src/constants";
import { env } from "./src/env";

afterAll(async () => {
const queues = [
Expand Down
2 changes: 1 addition & 1 deletion packages/blob-propagator/src/blob-propagator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
import type { BlobStorageManager } from "@blobscan/blob-storage-manager";
import { prisma } from "@blobscan/db";
import type { BlobscanPrismaClient } from "@blobscan/db";
import { env } from "@blobscan/env";

import { BlobPropagator } from "./BlobPropagator";
import { env } from "./env";

async function createBlobPropagator(
blobStorageManager: BlobStorageManager,
Expand Down
3 changes: 1 addition & 2 deletions packages/blob-propagator/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { JobsOptions, WorkerOptions } from "bullmq";

import { $Enums } from "@blobscan/db";

import { env } from "./env";
import { env } from "@blobscan/env";

export const STORAGE_WORKER_NAMES = Object.values($Enums.BlobStorage).reduce<
Record<$Enums.BlobStorage, string>
Expand Down
Loading

0 comments on commit a19327d

Please sign in to comment.