Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kerem/config #12

Merged
merged 9 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-ligers-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whatsgood/nexus": patch
---

improved logging and error reporting
5 changes: 5 additions & 0 deletions .changeset/hip-swans-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whatsgood/nexus": minor
---

created a new unified and reusable registry class, along with builders
5 changes: 5 additions & 0 deletions .changeset/ninety-rockets-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whatsgood/nexus": minor
---

streamlined env vars for provider keys
5 changes: 5 additions & 0 deletions .changeset/silent-seahorses-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whatsgood/nexus": minor
---

simplified provider configuration via string arrays
17 changes: 2 additions & 15 deletions examples/cloudflare-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,8 @@ import { NexusServer } from "@whatsgood/nexus";
type Env = Record<string, string>;

const server = NexusServer.create<Env>({
providers: {
// alchemy: {
// disabled: true,
// },
base: {
disabled: true,
},
infura: {
disabled: true,
},
ankr: {
disabled: true,
},
},
env: (env) => env,
env: (ctx) => ctx,
providers: ["alchemy"],
});

export default { fetch: server.fetch };
1 change: 1 addition & 0 deletions examples/nodejs-standalone-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@whatsgood/nexus": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.10.0",
"typescript": "5.2.2"
}
}
4 changes: 3 additions & 1 deletion examples/nodejs-standalone-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { NexusServer } from "@whatsgood/nexus";
import { createServer } from "node:http";

const server = NexusServer.create();
const server = NexusServer.create({
providers: ["base"],
});

createServer(server).listen(4005, () => {
console.log(`🚀 Server ready at http://localhost:4005`);
Expand Down
111 changes: 0 additions & 111 deletions packages/nexus/src/chain/chain-registry.ts

This file was deleted.

83 changes: 57 additions & 26 deletions packages/nexus/src/chain/chain.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,73 @@
import type { Registry } from "@src/registry";

export class Network {
private readonly chains = new Map<string, Chain>();

private constructor(public readonly name: string) {}

public addChain(chain: Chain) {
if (this.chains.has(chain.name)) {
throw new Error(`Chain ${chain.name} already exists`);
}

this.chains.set(chain.name, chain);
}

public getChain(name: string): Chain | undefined {
return this.chains.get(name);
}

public static init(
registry: Registry,
name: string,
aliases?: string[]
): Network {
const existingNetwork = registry.getNetwork(name);
const network = existingNetwork || new Network(name);

registry.registerNetwork(network, aliases);

return network;
}
}

export interface ChainStatus {
chainId: number;
chainName: string;
networkName: string;
isDeprecated: boolean;
}

export interface Network {
name: string;
aliases: string[];
chains: Partial<Record<string, Chain>>;
// TODO: add isDeprecated
// isDeprecated: boolean;
}

export class Chain {
public readonly name: string;
public readonly chainId: number;
public readonly network: Network;
public readonly isDeprecated: boolean;

constructor(params: {
name: string;
chainId: number;
network: Network;
isDeprecated?: boolean;
}) {
const { name, chainId, network, isDeprecated } = params;

this.name = name;
this.chainId = chainId;
this.network = network;
this.isDeprecated = isDeprecated || false;
}
private constructor(
public readonly chainId: number,
public readonly network: Network,
public readonly name: string
) {}

public get status(): ChainStatus {
return {
chainName: this.name,
chainId: this.chainId,
networkName: this.network.name,
isDeprecated: this.isDeprecated,
// isDeprecated: this.isDeprecated,
};
}

public static init(
registry: Registry,
params: {
chainId: number;
network: Network;
name: string;
}
): Chain {
const chain = new Chain(params.chainId, params.network, params.name);

params.network.addChain(chain);
registry.registerChain(chain);

return chain;
}
}
1 change: 1 addition & 0 deletions packages/nexus/src/chain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./chain";
Loading