Giter VIP home page Giter VIP logo

rx-nostr's Introduction

rx-nostr GitHub Release npm publish

rx-nostr is a library based on RxJS, which allows Nostr applications to easily communicate with relays. It wraps REQ subscriptions and other primitive operations of Nostr application in the RxJS subscription model, and provides high-level interfaces. It helps developers focus on the application logic, freeing them from tedious tasks such as relay pool management and WebSocket reconnection.

Getting Started

Please follow the documentation!

License

MIT

rx-nostr's People

Contributors

akiomik avatar jiftechnify avatar mattn avatar ocknamo avatar penpenpng avatar snowcait avatar tsukemonogit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rx-nostr's Issues

Teardown test cases properly

$ yarn test
...
A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.

Mixed subscription issue

Thanks for providing this cool library.

I was trying [email protected] with the code in app/main.ts, but when I do two or more subscriptions at the same time, the events get mixed up.

import { debounceTime } from 'rxjs';
import { Relays, BackwardReq, MonoFilterAccumulater, uniq } from 'rx-nostr';
import { webcrypto } from 'crypto';
import WebSocket from 'ws';

global.WebSocket = WebSocket;
global.crypto = webcrypto;

const relays = new Relays([
  "wss://relay-jp.nostr.wirednet.jp",
  "wss://nostr-relay.nokotaro.com",
]);

const acc0 = new MonoFilterAccumulater({ kinds: [0], limit: 5 });
const req0 = BackwardReq.from(acc0, debounceTime(500));

const acc1 = new MonoFilterAccumulater({ kinds: [1], limit: 5 });
const req1 = BackwardReq.from(acc1, debounceTime(500));

relays.observeReq(req0).pipe(uniq()).subscribe((e) => console.log('req0', e.message[2].kind));
relays.observeReq(req1).pipe(uniq()).subscribe((e) => console.log('req1', e.message[2].kind));
# output
# req0 expects to get only kind0 and req1 expects to get only kind1
req0 1
req1 1
req0 1
req1 1
req0 1
req1 1
req0 1
req1 1
req0 1
req1 1
req0 0
req1 0
req0 0
req1 0
req0 0
req1 0
req0 0
req1 0
req0 0
req1 0

Am I using it incorrectly?
As far as I've tried, it reproduced in both node and browser.

Full code is here: https://github.com/akiomik/rx-nostr-playground/blob/859e6be14512023b788eddf650070c2e24683736/main.js

sourcemap doesn't work

ref. note1g63p0ny60fsg2yfvqrmzde675dadwgvm65sgpp0sdus0ccj6zz9q6nq8w5

テストでrx-nostrがなんか上手く動かない問題、デバッガ使って追跡しようとしてるけどなんかトランスパイル後のコードに飛んじゃう sourcemapあるのに

Respect `limitation.max_filters`

  • Connection レイヤーで REQ を割って投げて、まとめてから返す
  • MessageSize 上限も気にしてあげられるとなおいい
  • ほとんど同じことだが max_limit にも対応してあげたい

ReqPacket `now` modifier

Provide an option to lazily evaluate since or until time when the REQ is (re)sent.

Like that enableTimeShift: true

Hooks for logging

note1n0uf87xu2a0xadjt3dhgrafujyjx7dw24hc3sy2hntkc34plwgrs2jt7fk

  • REQ 等の送受信の生の値を console.log 出力できてもいい

Batch extension for backward req

  • extend(req, batchMixin(interval))
  • .update(filters => newFilters)

or

  • .pipe(bufferFilter(mergeFilter, toChunks), throttle(interval))

v0.1.0 seems to be a mismatch

I tried v0.1.0 with the code from app/main.ts but it didn't work.

The following objects should be exported in dist/index.es.js at v0.1.0 (3c48c0b).

export {
  pe as Nostr,
  so as RxBackwardReq,
  co as RxForwardReq,
  ao as createRxNostr,
  io as filterKind,
  ro as latest,
  no as uniq,
  oo as verify
};

In practice it looks like this:

export {
  Je as BackwardReq,
  Ke as ForwardReq,
  $r as MonoFilterAccumulater,
  Nt as Nostr,
  Pr as Relays,
  zr as Req,
  Vr as collect,
  Mr as filterKind,
  Dr as latest,
  Zt as normalizeFilter,
  Kt as normalizeFilters,
  Wr as pickEvent,
  jr as uniq,
  Fr as verify
};

(ref: https://www.npmjs.com/package/rx-nostr?activeTab=code)

Please fix v0.1.0 or release a new version.

Extensible RxReq

createRx*Req({ ...options, extend: { /* extended interface */ } })

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.