Skip to content

Refactor: ClientConfigBuilder-specific BuilderConfig object for configuration handling#1480

Merged
pileks merged 69 commits intoorigin-devfrom
pileks/refactor-client-updates
Feb 3, 2023
Merged

Refactor: ClientConfigBuilder-specific BuilderConfig object for configuration handling#1480
pileks merged 69 commits intoorigin-devfrom
pileks/refactor-client-updates

Conversation

@pileks
Copy link
Copy Markdown
Contributor

@pileks pileks commented Jan 11, 2023

This is a continuation of #1465. Huge props to @Niraj-Kamdar for doing the bulk of the work around this.

This PR introduces the concept of BuilderConfig, which is a ClientConfigBuilder-specific configuration object wherein the individual configuration sections take the shape of a Record<string, SectionType>.

This allows us to configure the client in a very readable fashion.
Let's take config.envs as an example.
Before, we used to write:

const envs = [
  {
    uri: Uri.from("wrap://ens/hello-world.polywrap.eth"),
    env: {
      foo: "bar",
    },
  },
  {
    uri: Uri.from("ens/ethereum.polywrap.eth"),
    env: {
      connection: {
        node: "https://mainnet.infura.io/v3/some_api_key",
        networkNameOrChainId: "mainnet",
      },
    },
  },
];

const config = new ClientConfigBuilder()
  .addDefaults()
  .addEnvs(envs)
  .build();

const client = new PolywrapClient(config);

Now we can write a much more succint form of the configuration:

const envs = {
      "ens/ethereum.polywrap.eth": {
        connection: {
          networkNameOrChainId: "mainnet",
          node: "https://mainnet.infura.io/v3/some_api_key",
        },
      },
      "ens/hello-world.polywrap.eth": { foo: "bar" },
    };

const config = new ClientConfigBuilder()
  .addDefaults()
  .addEnvs(envs)
  .build();

const client = new PolywrapClient(config);

This can also be seen as precursor work to #1283 as it lays the foundation of the "ideal" layout of our final config objects.

Thank you @krisbitney for the note that this PR does a few more things than the description initially explained, these are:

  • replace Uri | string with Uri
  • remove tracing from core
  • fix http server infra build

Copy link
Copy Markdown
Contributor

@nerfZael nerfZael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this looks great.
I left two comments.
Additionally, I find the Generic** types really awkward

Comment thread packages/js/client-config-builder/src/types/IClientConfigBuilder.ts
Comment thread packages/js/client-config-builder/src/BaseClientConfigBuilder.ts Outdated
@pileks
Copy link
Copy Markdown
Contributor Author

pileks commented Feb 1, 2023

Most of this looks great. I left two comments. Additionally, I find the Generic** types really awkward

We will delete those in a future PR:
#1506

Copy link
Copy Markdown
Contributor

@cbrzn cbrzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking solid 👏 - i share the sentiment of Jure of having the two types but I think it's fine to fix this in another PR so we don't get things bigger.

The only idea I would give is that, since we want to fix the TUri generic not going in through the entire client, we maybe have this generic only in the builder, and this takes care of sanitizing the URIs, the client would only expect an URI and wont know about any generics. Making the core types just expect Uri instead of TUri

Just one minor thing to change (an unused dependency) and we're good to go

Comment thread packages/js/client-config-builder/package.json Outdated
@pileks pileks force-pushed the pileks/refactor-client-updates branch from 13bd143 to f876383 Compare February 2, 2023 21:43
@pileks pileks requested review from cbrzn and nerfZael February 2, 2023 22:37
@Niraj-Kamdar
Copy link
Copy Markdown
Contributor

If tracing is only implemented in PolywrapClient, how does that affect the usefullness of the tracing? If it's no longer effective, should we discuss removing tracing altogether?

It will still be beneficial to trace subinvocation traces, tryResolverUri, loadWrapper, or any other top-level functions.

@cbrzn
Copy link
Copy Markdown
Contributor

cbrzn commented Feb 3, 2023

If tracing is only implemented in PolywrapClient, how does that affect the usefullness of the tracing? If it's no longer effective, should we discuss removing tracing altogether?

It will still be beneficial to trace subinvocation traces, tryResolverUri, loadWrapper, or any other top-level functions.

tbh i feel we're not really using the tracing - i think discussing to improve/remove it is worth it


// $start: Uri-toString
/** @returns Uri string representation */
public toString(): string /* $ */ {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll assume that this would render the URI as a string within interpolated strings, but that's as far as I can fathom this.

TBH I've only now seen this and it's something that's been in the Uri class before, it's just been moved from lines 104-115 to here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I noticed that but not sure we need this functions in the first place

Copy link
Copy Markdown
Contributor

@Niraj-Kamdar Niraj-Kamdar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Let's get this merged and then cleanup legacy

@pileks pileks dismissed krisbitney’s stale review February 3, 2023 10:40

I've completed the requested changes, github is just being weird :)

@pileks pileks merged commit 0e10502 into origin-dev Feb 3, 2023
@dOrgJelli dOrgJelli deleted the pileks/refactor-client-updates branch April 10, 2023 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants