paravel v0.5.7
Paravel 
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.
Deferredis just a promise withresolveandrejectmethods.Emitterextends EventEmitter to supportemitter.on('*', ...).Fluentis a wrapper around arrays with chained methods that modify and copy the underlying array.Kindscontains kind constants and related utility functions.LRUCacheis an implementation of an LRU cache.Queueis an implementation of an asynchronous queue.Relayscontains utilities related to relays.Routeris a utility for selecting relay urls based on user preferences and protocol hints.TagsandTagextendFluentto provide a convenient way to access and modify tags.Toolsis a collection of general-purpose utility functions.
/connect
Utilities having to do with connection management and nostr messages.
ConnectionMetatracks stats for a givenConnection.Connectionis a wrapper forSocketwith send and receive queues, and aConnectionMetainstance.Executorimplements common nostr flows ontargetPoolis a thin wrapper aroundMapfor use withRelays.Socketis a wrapper around isomorphic-ws that handles json parsing/serialization.Subscriptionis 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.
Multiallows you to compose multiple targets together.Plextakes an array of urls and aConnectionand sends and receives wrapped nostr messages over that connection.Relaytakes aConnectionand provides listeners for different verbs.Relaystakes an array ofConnections 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})
}
}2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago