Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Add TypeDeclarations #58

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Add TypeDeclarations #58

wants to merge 15 commits into from

Conversation

timhc22
Copy link

@timhc22 timhc22 commented Mar 18, 2021

We should check all these work properly before merging.
I have tested by importing in my own project using this npm package (from which I am doing the pull request):

@unegma/[email protected]

Please let me know if you need help with knowing how to test, you should be able to do something like this:

import Web3 from "web3";
import ENS, { getEnsAddress } from '@unegma/ensjs';

const web3 = new Web3(
  new Web3.providers.WebsocketProvider(
    `${INFURA_ENDPOINT}${INFURA_APP_KEY}`,
    {
      timeout: 30000, // ms

      clientConfig: {
        // Useful if requests are large
        maxReceivedFrameSize: 100000000, // bytes - default: 1MiB
        maxReceivedMessageSize: 100000000, // bytes - default: 8MiB

        // Useful to keep a connection alive
        keepalive: true,
        keepaliveInterval: 60000, // ms
      },

      // Enable auto reconnection
      reconnect: {
        auto: true,
        delay: 5000, // ms
        maxAttempts: 5,
        onTimeout: false,
      },
    }
  )
);

const provider = web3.eth._provider; // todo is there a better way to get the provider from the web3 object?


const ens = new ENS({ provider }); // typescript benefit 1: typescript is checking the type is correct here, so if you try and pass a provider not of the "import { provider } from 'web3-core'"; type, then it will not work (we may want to add an 'any' type in the ens project)
let name = ens.get... // typescript benefit 2: this should bring up a list of methods specific to the ENS class (if you are using an IDE)

The provider argument can be of type 'provider' from web3-core (e.g httpProvider).

We may want to allow 'any' here
Apologies, I wiped this out whilst testing. We will need to bump the version number though.

I have not included any .d.ts definition files in the project itself, but they are added to the dist folder on build.
I can't think of any reason to add them to version control, even though some other projects do (aws-sdk)
We will probably need to go through and check carefully which parameters are optional for all exported classes/functions
We should also double check that all the types are correct (or ask someone very familar with the library who would be happy to QA everything)
src/utils/records.js Outdated Show resolved Hide resolved
src/utils/records.js Outdated Show resolved Hide resolved
@@ -1,6 +1,20 @@
import { addressUtils } from '@0xproject/utils'
import { validateContent } from './contents'

/**
* @typedef { "address" | "content" | "oldcontent" } recordType
Copy link
Member

Choose a reason for hiding this comment

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

I think you mixed up type and contentType (oldcontent| contenthash | null).

Copy link
Author

Choose a reason for hiding this comment

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

Good spot. Should recordType have just the following: * @typedef { "address" | "content" } recordType?

Copy link
Member

Choose a reason for hiding this comment

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

I think recordType can be null as well.

Copy link
Author

Choose a reason for hiding this comment

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

should be added now

src/index.js Outdated
@@ -239,6 +334,11 @@ class Name {
}
}

/**
* Get Resolver
* @param {string} coinId
Copy link
Member

Choose a reason for hiding this comment

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

Can you make coinId of getAddress() to be optional? It falls back to ETH if it doesn't have an argument so something like https://github.com/ensdomains/ensjs/blob/master/src/__tests__/ens.test.js#L224 will fail

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Done. Question actually, do most smart contracts these days prevent sending to 0x000.. ?

Copy link
Member

Choose a reason for hiding this comment

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

Question actually, do most smart contracts these days prevent sending to 0x000.. ? that is not relevant to this code

Copy link
Author

Choose a reason for hiding this comment

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

Ah yes you are right, it is the resolver address, not the smart contract address. I wasn't quite sure if resolvers were smart contracts too or not. Thanks for the clarification

@taylorjdawson
Copy link

@timhc22 @makoto How close is this? Need any help pushing it across the finish line?

@timhc22
Copy link
Author

timhc22 commented Jul 23, 2021

There was a conversation about rebuilding the entire library in typescript at some point, @makoto would have a better idea whether this is going ahead or not. How involved would you be interested in getting @taylorjdawson if needed?

@taylorjdawson
Copy link

@timhc22 I would be interested in helping with the rebuild 👍🏾 cc @makoto

@taylorjdawson
Copy link

@timhc22 @makoto
As part of the rewrite I would like to suggest two very important changes I believe should be made:

  1. Allow this to be used as reader only, e.g. not requiring a signer
  2. remove reliance on node builtins -- makes it difficult for build tools such as vite

@timhc22
Copy link
Author

timhc22 commented Dec 4, 2021

@taylorjdawson apologies for not getting back sooner, is this something you fancy doing, or know anyone who could?

@gomesalexandre
Copy link

gomesalexandre commented Jan 22, 2022

What's the status on the TS conversion / rewrite @makoto @taylorjdawson ? @timhc22 If there is any help needed, I'd be happy to.

@timhc22
Copy link
Author

timhc22 commented Feb 11, 2022

@gomesalexandre @taylorjdawson, the integration which I wrote was just to add type declarations, however, @makoto was interested in rewriting the whole library in Typescript, so what I did can probably be discarded if it can be superseded by something better. Alternately, things might be working differently now that ens has switched over to a dao model.

@gomesalexandre
Copy link

@gomesalexandre @taylorjdawson, the integration which I wrote was just to add type declarations, however, @makoto was interested in rewriting the whole library in Typescript, so what I did can probably be discarded if it can be superseded by something better. Alternately, things might be working differently now that ens has switched over to a dao model.

That's a good point on ENS being a DAO now. I'll get involved there to see what's the path forward on this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants