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

How to use PubSub on TypeScript ? #546

Open
acsses opened this issue May 22, 2024 · 3 comments
Open

How to use PubSub on TypeScript ? #546

acsses opened this issue May 22, 2024 · 3 comments

Comments

@acsses
Copy link

acsses commented May 22, 2024

How to use PubSub on TypeScript ?

I want to use PubSub on Typescript and try to use the sample code on this page

https://helia.io/modules/_helia_ipns.html

However when I run the code, Some issues emerged.
These error is below .These error happend during compile .

src/main.ts:347:5 - error TS18048: 'libp2pOptions.services' is possibly 'undefined'.

347     libp2pOptions.services.pubsub = gossipsub()
        ~~~~~~~~~~~~~~~~~~~~~~

src/main.ts:363:11 - error TS18046: 'helia.libp2p.services.keychain' is of type 'unknown'.

363     await helia.libp2p.services.keychain.importKey("self_key_pair",exported,user_name)
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/main.ts:368:18 - error TS2345: Argument of type 'HeliaLibp2p<Libp2p<ServiceMap>>' is not assignable to parameter of type 'PubsubRoutingComponents'.
  The types of 'libp2p.services' are incompatible between these types.
    Property 'pubsub' is missing in type 'ServiceMap' but required in type '{ pubsub: PubSub<PubSubEvents>; }'.

368           pubsub(helia)
                     ~~~~~

  node_modules/@helia/ipns/dist/src/routing/pubsub.d.ts:10:13
    10             pubsub: PubSub;
                   ~~~~~~
    'pubsub' is declared here.

src/main.ts:375:9 - error TS2322: Type 'HeliaLibp2p<Libp2p<ServiceMap>>' is not assignable to type 'HeliaLibp2p<Libp2p<DefaultLibp2pServices>>'.
  Type 'Libp2p<ServiceMap>' is not assignable to type 'Libp2p<DefaultLibp2pServices>'.
    Type 'ServiceMap' is missing the following properties from type 'DefaultLibp2pServices': autoNAT, dcutr, delegatedRouting, dht, and 5 more.

375         helia: helia,
            ~~~~~

  src/main.ts:34:5
    34     helia:HeliaLibp2p,
           ~~~~~
    The expected type comes from property 'helia' which is declared here on type 'peer_ctx'


Found 4 errors in the same file, starting at: src/main.ts:347
@SgtPooki
Copy link
Member

Is this issue still occuring with the latest? We had an issue with typings a few months ago that I believe is now resolved. Can you try again and share repro code if you are still seeing issues?

@SgtPooki SgtPooki added the need/author-input Needs input from the original author label Aug 29, 2024
Copy link
Contributor

github-actions bot commented Sep 5, 2024

Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.

@acsses
Copy link
Author

acsses commented Sep 7, 2024

By building Helia node myself, It move.

like:

var libp2p = await createLibp2p({
    services: {
      autoNAT: autoNAT(),
      dcutr: dcutr(),
      delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev'),
      dht: kadDHT({
        validators: {
          ipns: ipnsValidator
        },
        selectors: {
          ipns: ipnsSelector
        }
      }),
      identify: identify({
          agentVersion
      }),
      ping: ping(),
      relay: circuitRelayServer({
          advertise: true
      }),
      pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }),
      keychain: keychain()
    },
})

const helia = await createHelia({libp2p})


name = ipns(helia,{
    routers: [
      pubsub({
        datastore: helia.datastore,
        libp2p: {
          peerId: helia.libp2p.peerId,
          services: {
            pubsub: helia.libp2p.services.pubsub as PubSub
          }
        }
      })
    ]
})

fs = unixfs(helia)

@ipfs ipfs deleted a comment from github-actions bot Sep 16, 2024
@ipfs ipfs deleted a comment from github-actions bot Sep 23, 2024
@achingbrain achingbrain removed need/author-input Needs input from the original author kind/stale labels Sep 23, 2024
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

No branches or pull requests

3 participants