Skip to content

JS client: change envs and interfaces into readonly maps#1557

Closed
pileks wants to merge 14 commits into
origin-devfrom
pileks/feat/js-client-config-unique-maps
Closed

JS client: change envs and interfaces into readonly maps#1557
pileks wants to merge 14 commits into
origin-devfrom
pileks/feat/js-client-config-unique-maps

Conversation

@pileks
Copy link
Copy Markdown
Contributor

@pileks pileks commented Feb 16, 2023

Closes #1283

This PR aims to change the envs and interfaces collections inside CoreClientConfig into readonly unique maps/map-like structures.

envs is now essentially:

Record<string, Record<string, unknown>>

interfaces is now essentially:

Record<string, string[]>

Everything that can be is marked as readonly in order to relay the intended readonly nature of the CoreClientConfig.

Some comments/feedback needed:

  • I'm not 100% sure I like having everything as strings, but implementing some custom URI-Map seems like a worse idea. This does leave us vulnerable to people mixing wrap://xyz/... and xyz/... as two separate objects within the maps, but that's something that should be handled by the ClientConfigBuilder.
    • Again, I feel like this is something to think about as the ClientConfigBuilder is not always used yet, and I know some devs want to simply build their own config.
  • We might want to think about interfaces being a Record<string, Uri[]> instead. Thoughts?

@pileks pileks changed the base branch from origin-dev to pileks/feat/workflow-manifest-0.2.0 February 16, 2023 17:47
@pileks pileks changed the base branch from pileks/feat/workflow-manifest-0.2.0 to origin-dev February 24, 2023 19:08
@pileks pileks marked this pull request as ready for review February 24, 2023 19:09
@pileks pileks changed the title Pileks/feat/js client config unique maps JS client: change envs and interfaces into readonly maps Feb 24, 2023
@pileks pileks self-assigned this Feb 25, 2023
@pileks pileks added this to the origin-qa milestone Feb 25, 2023
krisbitney
krisbitney previously approved these changes Mar 1, 2023
Copy link
Copy Markdown
Contributor

@krisbitney krisbitney left a comment

Choose a reason for hiding this comment

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

Everything looks good. This is well done! The use of objects instead of arrays looks really clean.

Before merging, I think the question about using string vs. Uri should be resolved, just because of the recent decision to use Uri in the core.

I think making the implementations array of type Uri[] instead of string[] makes sense.

describe.each(supportedImplementations)(
"client <-> wrappers end to end",
(i) => {
typeTestCases(i);
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.

Oops, need to revert this

*
* @returns an array of interfaces and their registered implementations
*/
getInterfaces(): readonly InterfaceImplementations[] | undefined;
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.

I noticed some inconsistencies in this file when it comes to readonly and ReadOnly<...> usage. Could we please use it the same in all methods / properties? If I'm missing some nuances please inform :)

}

return envs.find((environment) => Uri.equals(environment.uri, uriUri));
return envs[uri.uri];
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.

This will probably treat "wrap://ens/" and "ens/" as different URIs

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.

We could maybe sanitize this stuff in the constructor

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.

JS Client: Client Config Should Use Unique Maps Instead Of Unique Arrays

4 participants