jiftechnify / nostr-fetch

A utility library that allows JS/TS apps to effortlessly fetch past events from Nostr relays.
MIT License
49 stars 2 forks source link

adapter-ndk might be out of date #138

Closed dskvr closed 7 months ago

dskvr commented 11 months ago

Having issues with this adapter and noticed a peer dependency of ^0.8.4 in adapter-ndk. ndk is presently 2.0.5, didn't look into your testing suite but possible it has fallen out of sync.

When using fetchAllEvents with the adapter, as according to the docs

await fetcher.fetchAllEvents(
      relaysArr, //array of relay urls
      { kinds: [ 2, 3, 10002 ] },
      { since }, //timestamp
      { sort: true }
    )

I get the following errors for confirmed-online relays.

[wss://relay.damus.io/] FetchTillEoseFailedSignal: failed to ensure connection to the relay
[wss://nostr-pub.wellorder.net/] FetchTillEoseFailedSignal: failed to ensure connection to the relay
[wss://nostr.mom/] FetchTillEoseFailedSignal: failed to ensure connection to the relay

When I use ndk directly as a drop-in on existing logic with same data, I get successful connections.

If the adapter needs to be updated, would be willing to take a look. Let me know if you have some knowledge to drop before I dive in

jiftechnify commented 10 months ago

Thank you for reporting the issue, and sorry for late reply.

I tested @nostr-fetch/adapter-ndk@0.13.1 with @nostr-dev-kit/ndk@2.0.5, and even ndk@2.2.0 (the latest version as of today) with the code below, but it seems to work as expected (except a type error, discussed later).

import NDK from "@nostr-dev-kit/ndk"; // 2.0.5 or 2.2.0
import { ndkAdapter } from "@nostr-fetch/adapter-ndk"; // 0.13.1
import { NostrFetcher } from "nostr-fetch"; // 0.13.1

import "websocket-polyfill";

const nHoursAgo = (hrs: number): number =>
  Math.floor((Date.now() - hrs * 60 * 60 * 1000) / 1000);

const main = async () => {
  const relays = [
    "wss://relay.damus.io/",
    "wss://nsotr-pub.wellorder.net/",
    "wss://nostr.mom/"
  ];
  const ndk = new NDK();
  await ndk.connect();
  const fetcher = NostrFetcher.withCustomPool(ndkAdapter(ndk), { minLogLevel: "verbose" });

  const evs = await fetcher.fetchAllEvents(
    relays,
    { kinds: [2, 3, 10002] },
    { since: nHoursAgo(1) },
    { sort: true },
  );
  console.log(evs.length);

  fetcher.shutdown();
};

main()
  .then(() => console.log("fin"))
  .catch((e) => {
    console.error(e);
    process.exit(1);
  });

If you don't mind, can you share complete code to reproduce the issue?

jiftechnify commented 10 months ago

BTW, seems that the type of NDK in v0 and in v1/v2 are incompatible due to a removal of a property, so I'll bump the minimum supported version of NDK in next release. It has been done in 0.14.1.

dskvr commented 9 months ago

Sorry for the delay, I moved to the nostr-tools adapter so I cannot provide the code.

jiftechnify commented 7 months ago

I'll close this for now.