You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Introduce the builder pattern using `initErpcConfig`
6
+
- Remove auto generated type and move to the exported type of `@erpc-cloud/config`
7
+
- Review upstreams builder helpers for a wider support of the matching pattern
8
+
- Remove YAML file generation, since erpc now support js/ts config file
9
+
- Remove free rpc benchmark for now, currently envisaging multiple way to re-introduce it later, maybe using dynamic config or the selection eval policy?
2. Run the CLI command to generate the YAML configuration:
77
+
> Note the `.build()` at the end, it's mandatory for it to export nicely and be recognized by the CLI.
78
+
79
+
2. Run the CLI command to generate the bundled JS configuration:
53
80
54
81
```bash
55
82
bunx erpc-config
56
83
```
57
84
58
-
This will read the `erpc-config.ts` file in the current directory and output the configuration to `erpc.yaml`.
85
+
This will read the `erpc-config.ts` file in the current directory and output the configuration to `erpc.js`.
86
+
87
+
> **Note:** You can bundle the configuration with the bundler of your choice (bun build, esbuild, terser, etc.)
59
88
60
89
## CLI Usage
61
90
62
91
The eRPC Config Generator CLI provides two main commands: `generate` (default) and `validate`.
63
92
64
-
### Generate Command
93
+
### Package Command
65
94
66
-
Generate an eRPC YAML config file from the TypeScript config:
95
+
Package an eRPC JS config file from the TypeScript config:
67
96
68
97
```
69
98
erpc-config [options]
70
99
```
71
100
or
72
101
```
73
-
erpc-config generate [options]
102
+
erpc-config package [options]
74
103
```
75
104
76
105
Options:
77
106
--config The path to the config file (default: "./erpc-config.ts")
78
-
--out The output file path (default: "./erpc.yaml")
107
+
--out The output file path (default: "./erpc.js")
79
108
80
109
Examples:
81
110
@@ -84,12 +113,11 @@ Examples:
84
113
bun erpc-config
85
114
86
115
# Specify custom input and output paths
87
-
bun erpc-config --config ./configs/my-erpc-config.ts --out ./configs/my-erpc-config.yaml
116
+
bun erpc-config --config ./configs/my-erpc-config.ts --out ./configs/my-erpc-config.js
88
117
89
-
# Explicitly use the generate command
90
-
bun erpc-config generate --config ./custom-config.ts
118
+
# Explicitly use the package command
119
+
bun erpc-config package --config ./custom-config.ts
91
120
```
92
-
Note: When using `evm+free` upstream type, the generator will automatically fetch and include the 15 best free RPC URLs for the specified chain in the output YAML.
93
121
94
122
### Validate Command
95
123
@@ -112,24 +140,6 @@ bun erpc-config validate
112
140
bun erpc-config validate --config ./configs/my-erpc-config.ts
113
141
```
114
142
115
-
### Free RPC Command
116
-
117
-
Fetch the 15 best free RPC URLs for a given chain:
118
-
119
-
```
120
-
erpc-config free-rpc --chain-id <chainId>
121
-
```
122
-
123
-
Options:
124
-
--chain-id The chain ID to fetch free RPC URLs for (required)
125
-
126
-
Example:
127
-
128
-
```bash
129
-
# Fetch free RPC URLs for Ethereum mainnet (chain ID 1)
130
-
bun erpc-config free-rpc --chain-id 1
131
-
```
132
-
133
143
### General CLI Options
134
144
135
145
-`--help`, `-h`: Show help information
@@ -139,13 +149,18 @@ You can run these commands using `bun`, `npm`, or any other package runner of yo
139
149
140
150
## API Overview
141
151
142
-
### Environment Variables
152
+
### Builder Methods
153
+
154
+
-**`initErpcConfig(config: InitConfig)`**: Initializes the configuration with basic settings such as `logLevel` and `server` properties.
143
155
144
-
-`envVariable(name: string)`: Helper function to reference environment variables in the config.
156
+
-**`addRateLimiters(budgets: Record\<TKeys,RateLimitRuleConfig[]>)`**: Adds rate limiters to your configuration.
145
157
146
-
### Rate Limits
158
+
-**`decorate(scope: "upstreams" | "networks", value: Record\<TStoreKey, NetworkConfig | UpstreamConfig>)`**: Adds values to the store for `networks` or `upstreams`.
147
159
148
-
-`buildRateLimit<TRpc extends RpcSchema = EIP1474Methods>({ id, rules })`: Create a rate limit configuration with customizable RPC schema, for type completion.
160
+
-**Scope**: Determines which store (`networks` or `upstreams`) to push values to.
161
+
-**Value**: The static values to add the the builder store
162
+
163
+
-**`addProject(project: ProjectConfig | ({config: Config, store: Store} => ProjectConfig))`**: Adds a project to your configuration.
149
164
150
165
### Networks
151
166
@@ -159,46 +174,22 @@ You can run these commands using `bun`, `npm`, or any other package runner of yo
159
174
-`buildEvmUpstream<TRpc extends RpcSchema>({ id, endpoint, ...options })`: Configure a generic EVM upstream provider with customizable RPC schema.
160
175
-`buildFreeUpstreams({ chains, ...options})`: Configure placeholder upstreams that will be filled with the 15 best free RPCs for the specified chain.
161
176
162
-
### Projects
163
-
164
-
-`buildProject(projectConfig)`: Create a project configuration.
-`RpcMethodWithRegex<TRpc>`: Represents RPC methods, including support for wildcard patterns.
178
-
-`OptionalRateLimit<T>`: Makes the `rateLimitBudget` field optional in a type that includes it.
179
-
180
-
All other exported types (such as `Config`, `ServerConfig`, `DatabaseConfig`, etc.) are TypeScript representations of the original eRPC Go config type definitions. These provide strong typing for configuration objects and can be imported and used in your TypeScript projects.
181
-
182
-
For a complete list of available types, refer to the type definitions in the library.
183
-
184
177
## Dependencies
185
178
186
179
This package relies on the following main dependencies:
187
180
188
181
-[viem](https://viem.sh/): (Peer Dependency) A TypeScript interface for Ethereum, providing lightweight and type-safe modules for interacting with the blockchain.
189
182
190
-
-[@ubiquity-dao/rpc-handler](https://github.com/ubiquity/rpc-handler): (Optional Peer Dependency) Used for fetching and comparing free RPC URLs from chainlist. Only required if you intend to use the free RPC features.
191
-
192
183
-[erpc](https://www.erpc.cloud/): The core RPC load balancer that this config generator is designed for. It offers fault-tolerant EVM RPC load balancing with reorg-aware permanent caching and auto-discovery of node providers.
193
184
194
185
-[gluegun](https://github.com/infinitered/gluegun): A toolkit used for building the command-line interface of this config generator, offering a robust set of utilities for creating TypeScript-powered CLI apps.
195
186
196
-
Please ensure you have the required peer dependencies installed in your project when using this package. The `@ubiquity-dao/rpc-handler` is only necessary if you plan to utilize the free RPC functionality.
197
-
198
187
## Usage examples
199
188
200
189
For a simple setup, please refer to the [simple example](example/simple.ts) in the repository.
201
190
191
+
You can check a more [complete example here](/typescript/config/example/full.ts).
192
+
202
193
## Real-World Usage
203
194
204
195
For a comprehensive, real-world example of how to use the eRPC Config Generator, you can refer to the Frak indexer repository:
@@ -216,17 +207,17 @@ The entire configuration is contained in a single file:
216
207
217
208
-`erpc-config.ts`: The main configuration file that exports the complete eRPC config
218
209
219
-
To generate the YAML configuration from this setup, the project uses:
210
+
To generate the JS configuration from this setup, the project uses:
220
211
221
212
```bash
222
-
pnpm erpc-config
213
+
bun erpc-config
223
214
```
224
215
225
-
The resulting YAML configuration is output to:
216
+
The resulting JS configuration is output to:
226
217
227
-
-`erpc.yaml`: The generated eRPC configuration file
218
+
-`erpc.js`: The generated eRPC configuration file
228
219
229
-
This example showcases how to integrate the eRPC Config Generator into a larger project, using pnpm as the package manager. It's a great reference for structuring your own eRPC configuration in a production environment.
220
+
This example showcases how to integrate the eRPC Config Generator into a larger project, using bun as the package manager. It's a great reference for structuring your own eRPC configuration in a production environment.
230
221
231
222
You can use this as a template for your own project, adjusting the network configurations, upstreams, and other settings as needed for your specific use case.
0 commit comments