0.5.7 • Published 2 months ago

paravel v0.5.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Paravel version

A nostr toolkit focused on creating highly a configurable client system. What paravel provides is less a library of code than a library of abstractions. Odds are you will end up creating a custom implementation of every component to suit your needs, but if you start with paravel that will be much easier than if you pile on parameters over time.

/util

Some general-purpose utilities used in paravel.

  • Deferred is just a promise with resolve and reject methods.
  • Emitter extends EventEmitter to support emitter.on('*', ...).
  • Fluent is a wrapper around arrays with chained methods that modify and copy the underlying array.
  • Kinds contains kind constants and related utility functions.
  • LRUCache is an implementation of an LRU cache.
  • Queue is an implementation of an asynchronous queue.
  • Relays contains utilities related to relays.
  • Router is a utility for selecting relay urls based on user preferences and protocol hints.
  • Tags and Tag extend Fluent to provide a convenient way to access and modify tags.
  • Tools is a collection of general-purpose utility functions.

/connect

Utilities having to do with connection management and nostr messages.

  • ConnectionMeta tracks stats for a given Connection.
  • Connection is a wrapper for Socket with send and receive queues, and a ConnectionMeta instance.
  • Executor implements common nostr flows on target
  • Pool is a thin wrapper around Map for use with Relays.
  • Socket is a wrapper around isomorphic-ws that handles json parsing/serialization.
  • Subscription is a higher-level utility for making requests against multiple nostr relays.

/connect/target

Executor targets extend Emitter, and have a send method, a cleanup method, and a connections getter. They are intended to be passed to an Executor for use.

  • Multi allows you to compose multiple targets together.
  • Plex takes an array of urls and a Connection and sends and receives wrapped nostr messages over that connection.
  • Relay takes a Connection and provides listeners for different verbs.
  • Relays takes an array of Connections and provides listeners for different verbs, merging all events into a single stream.

Example

Functionality is split into small chunks to allow for changing out implementations as needed. This is useful when attempting to support novel use cases. Here's a simple implementation of an agent that can use a multiplexer if enabled, or can fall back to communicating directly with all relays.

class Agent {
  pool = new Pool()

  constructor(readonly multiplexerUrl: string) {}

  getTarget(urls) {
    return this.multiplexerUrl
      ? new Plex(urls, this.pool.get(this.multiplexerUrl))
      : new Relays(urls.map(url => this.pool.get(url)))
  }

  subscribe(urls, filters, id, {onEvent, onEose}) {
    const executor = new Executor(this.getTarget(urls))

    return executor.subscribe(filters, id, {onEvent, onEose})
  }
}
0.5.7

2 months ago

0.5.6

2 months ago

0.5.5

2 months ago

0.5.4

2 months ago

0.5.3

2 months ago

0.5.2

2 months ago

0.5.0

2 months ago

0.5.1

2 months ago

0.4.21

2 months ago

0.4.20

3 months ago

0.4.19

3 months ago

0.4.18

4 months ago

0.4.17

4 months ago

0.4.16

5 months ago

0.4.15

5 months ago

0.4.14

5 months ago

0.4.9

5 months ago

0.4.8

6 months ago

0.3.8

7 months ago

0.3.7

7 months ago

0.3.9

7 months ago

0.4.10

5 months ago

0.4.13

5 months ago

0.4.11

5 months ago

0.4.12

5 months ago

0.4.5

6 months ago

0.4.4

6 months ago

0.4.7

6 months ago

0.4.6

6 months ago

0.4.1

6 months ago

0.4.0

7 months ago

0.4.3

6 months ago

0.4.2

6 months ago

0.3.6

8 months ago

0.3.5

8 months ago

0.3.4

8 months ago

0.3.3

8 months ago

0.3.0

9 months ago

0.2.1

9 months ago

0.2.0

10 months ago

0.1.16

10 months ago

0.1.17

10 months ago

0.1.18

10 months ago

0.1.19

10 months ago

0.3.2

9 months ago

0.2.3

9 months ago

0.3.1

9 months ago

0.2.2

9 months ago

0.1.14

1 year ago

0.1.15

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago