Skip to content

Commit

Permalink
defaultRegistry -> globalSingletonRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
mechanical-turk committed Nov 29, 2023
1 parent 352647e commit 35bcae3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
2 changes: 2 additions & 0 deletions examples/cloudflare-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { NexusServer } from "@whatsgood/nexus";
// TODO: add onboarding & UX. (setup admin access, login, etc)
// TODO: add tests for the worker

// TODO: add documentation for registry extensions

type Env = Record<string, string>;

const server = NexusServer.create<Env>({
Expand Down
4 changes: 2 additions & 2 deletions packages/nexus/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { defaultRegistry } from "./registry/default-registry";
import { globalSingletonRegistry } from "./registry/global-singleton-registry";
import type { Registry } from "./registry";
import { toUpperSnakeCase } from "./utils";

Expand Down Expand Up @@ -104,7 +104,7 @@ export class Config {
params.globalAccessKey || env.NEXUS_GLOBAL_ACCESS_KEY;
this.recoveryMode = params.recoveryMode ?? "cycle";

this.registry = params.registry || defaultRegistry;
this.registry = params.registry || globalSingletonRegistry;
}

private getEnvSecretKeyName(name: string): string {
Expand Down
1 change: 1 addition & 0 deletions packages/nexus/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./nexus";
export * from "./config";
export * from "./registry";
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Registry } from "./registry";

export const defaultRegistry = new Registry();
export const globalSingletonRegistry = new Registry();

defaultRegistry
globalSingletonRegistry
.network("ethereum", ["eth"])
.chain(1, "mainnet")
.chain(4, "rinkeby")
Expand All @@ -19,7 +19,7 @@ defaultRegistry
.network("local", ["hardhat", "foundry"])
.chain(31337, "local");

defaultRegistry
globalSingletonRegistry
.provider("alchemy")
.support(1, {
baseURL: "https://eth-mainnet.alchemyapi.io/v2",
Expand Down
2 changes: 1 addition & 1 deletion packages/nexus/src/registry/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./registry";
export * from "./default-registry";
export * from "./global-singleton-registry";
1 change: 1 addition & 0 deletions packages/nexus/src/registry/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ describe("registry", () => {
it("should override existing service provider chain support", () => {
const registry = new Registry();
const config = new Config({
registry,
chains: [1],
providers: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { defaultRegistry } from "../registry/default-registry";
import { globalSingletonRegistry } from "../registry/global-singleton-registry";
import { Config } from "../config";
import { RpcEndpointPoolFactory } from "./rpc-endpoint-pool-factory";

Expand All @@ -22,15 +22,15 @@ describe("provider factory", () => {
const factory = new RpcEndpointPoolFactory(config);

const chains = {
ethMainnet: defaultRegistry.getChainByNames("ethereum", "mainnet"),
baseGoerli: defaultRegistry.getChainByNames("base", "goerli"),
rinkeby: defaultRegistry.getChainByNames("ethereum", "rinkeby"),
ethMainnet: globalSingletonRegistry.getChainByNames("ethereum", "mainnet"),
baseGoerli: globalSingletonRegistry.getChainByNames("base", "goerli"),
rinkeby: globalSingletonRegistry.getChainByNames("ethereum", "rinkeby"),
};
const providers = {
alchemy: defaultRegistry.getServiceProviderByName("alchemy"),
infura: defaultRegistry.getServiceProviderByName("infura"),
ankr: defaultRegistry.getServiceProviderByName("ankr"),
base: defaultRegistry.getServiceProviderByName("base"),
alchemy: globalSingletonRegistry.getServiceProviderByName("alchemy"),
infura: globalSingletonRegistry.getServiceProviderByName("infura"),
ankr: globalSingletonRegistry.getServiceProviderByName("ankr"),
base: globalSingletonRegistry.getServiceProviderByName("base"),
};

describe("routes", () => {
Expand Down

0 comments on commit 35bcae3

Please sign in to comment.