From 756d261e5dd79e78962b3ac894b05b26fa13f5c7 Mon Sep 17 00:00:00 2001 From: KONFeature Date: Tue, 27 Aug 2024 21:01:38 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Update=20types=20+=20optional=20`se?= =?UTF-8?q?rver`=20and=20`metrics`=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/real-dots-love.md | 5 ++++ .changeset/serious-hornets-sin.md | 5 ++++ src/cli/commands/generate.ts | 20 +++++++++++++++ src/cli/utils/assertion/index.ts | 24 ++++++++++++++++++ src/config.ts | 41 ++++++++++++++++++++++++++++--- src/generatedTypes/erpcTypes.ts | 8 ++++-- 6 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 .changeset/real-dots-love.md create mode 100644 .changeset/serious-hornets-sin.md diff --git a/.changeset/real-dots-love.md b/.changeset/real-dots-love.md new file mode 100644 index 0000000..b3b17f4 --- /dev/null +++ b/.changeset/real-dots-love.md @@ -0,0 +1,5 @@ +--- +"@konfeature/erpc-config-generator": patch +--- + +Optional `server` and `metrics` field in the root config object + generation info diff --git a/.changeset/serious-hornets-sin.md b/.changeset/serious-hornets-sin.md new file mode 100644 index 0000000..132a0c6 --- /dev/null +++ b/.changeset/serious-hornets-sin.md @@ -0,0 +1,5 @@ +--- +"@konfeature/erpc-config-generator": patch +--- + +Update erpc types for erpc `v0.0.18` diff --git a/src/cli/commands/generate.ts b/src/cli/commands/generate.ts index c5f55e1..4aca080 100644 --- a/src/cli/commands/generate.ts +++ b/src/cli/commands/generate.ts @@ -49,6 +49,26 @@ export async function generateCmd({ print, parameters }: GluegunToolbox) { print.info("Config:"); print.info(` - Projects: ${stats.projects}`); print.info(` - Rate limiters: ${stats.rateLimiters}`); + if (stats.server) { + print.info( + ` - Server IPv4: ${stats.server.hostV4}:${stats.server.port}` + ); + print.info( + ` - Server IPv6: ${stats.server.hostV6}:${stats.server.port}` + ); + } else { + print.info(" - Server: Will use default from eRPC config"); + } + if (stats.metrics) { + print.info( + ` - Metrics IPv4: ${stats.metrics.hostV4}:${stats.metrics.port}` + ); + print.info( + ` - Metrics IPv6: ${stats.metrics.hostV6}:${stats.metrics.port}` + ); + } else { + print.info(" - Metrics: Not enable or not set in the config"); + } // Write the erpc config spinner.text = "Writing eRPC config file"; diff --git a/src/cli/utils/assertion/index.ts b/src/cli/utils/assertion/index.ts index 68e6863..d10aab9 100644 --- a/src/cli/utils/assertion/index.ts +++ b/src/cli/utils/assertion/index.ts @@ -11,6 +11,16 @@ type ConfigCheckResult = { stats: { projects: number; rateLimiters: number; + server?: { + port: number; + hostV4: string; + hostV6: string; + }; + metrics?: { + port: number; + hostV4: string; + hostV6: string; + }; }; }; @@ -64,6 +74,20 @@ export function checkConfigValidity(config: Config): ConfigCheckResult { // Update our stats object stats.projects = config.projects.length; stats.rateLimiters = config.rateLimiters?.budgets?.length ?? 0; + stats.server = config.server + ? { + port: config.server.httpPort, + hostV4: config.server.httpHostV4, + hostV6: config.server.httpHostV6, + } + : undefined; + stats.metrics = config.metrics?.enabled + ? { + port: config.metrics.port, + hostV4: config.metrics.hostV4, + hostV6: config.metrics.hostV6, + } + : undefined; // Check for projects duplication errors.push(...checkProjectsDuplication(config)); diff --git a/src/config.ts b/src/config.ts index 2e52319..2643cf3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,8 +1,43 @@ -import type { Config } from "./generatedTypes/erpcTypes"; +import type { + Config, + MetricsConfig, + ServerConfig, +} from "./generatedTypes/erpcTypes"; +import type { OptionalField } from "./types/utils"; + +type ConfigWithOptionalServer = Omit & { + server?: OptionalField< + ServerConfig, + "httpPort" | "httpHostV4" | "httpHostV6" + >; + metrics?: OptionalField; +}; + +// Default config for metrics and server +const defaultServerConfig = { + httpPort: 4000, + httpHostV4: "0.0.0.0", + httpHostV6: "[::]", +}; +const defaultMetricsCofnig = { + port: 4001, + hostV4: "0.0.0.0", + hostV6: "[::]", +}; /** * Build the globel erpc config */ -export function buildErpcConfig({ config }: { config: Config }) { - return config; +export function buildErpcConfig({ + config, +}: { config: ConfigWithOptionalServer }) { + return { + ...config, + server: config?.server + ? { ...defaultServerConfig, ...config.server } + : undefined, + metrics: config?.metrics + ? { ...defaultMetricsCofnig, ...config.metrics } + : undefined, + }; } diff --git a/src/generatedTypes/erpcTypes.ts b/src/generatedTypes/erpcTypes.ts index 765141c..b5195f0 100644 --- a/src/generatedTypes/erpcTypes.ts +++ b/src/generatedTypes/erpcTypes.ts @@ -16,7 +16,8 @@ export interface Config { admin?: AdminConfig; } export interface ServerConfig { - httpHost: string; + httpHostV4: string; + httpHostV6: string; httpPort: number /* int */; maxTimeout: string; } @@ -216,7 +217,8 @@ export interface NetworkStrategyConfig { } export interface MetricsConfig { enabled: boolean; - host: string; + hostV4: string; + hostV6: string; port: number /* int */; } @@ -243,6 +245,8 @@ export type Network = any; export type UpstreamType = string; export const UpstreamTypeEvm: UpstreamType = "evm"; export const UpstreamTypeEvmAlchemy: UpstreamType = "evm+alchemy"; +export const UpstreamTypeEvmDrpc: UpstreamType = "evm+drpc"; +export const UpstreamTypeEvmBlastapi: UpstreamType = "evm+blastapi"; export const UpstreamTypeEvmEnvio: UpstreamType = "evm+envio"; export const UpstreamTypeEvmPimlico: UpstreamType = "evm+pimlico"; export const UpstreamTypeEvmThirdweb: UpstreamType = "evm+thirdweb";