v2.0.0
rx-nostr major update!🎉
New Features
Automatically closing unused WebSocket connections
Unused WebSocket connections are automatically disconnected. This behavior can be partially disabled with keepAliveDefaultRelayConnections
.
"WebSocket connections is not being used" means that there is neither an ongoing REQ nor waiting OK associated with EVENT publishing on the WebSocket. Such WebSockets get to be dormant.
keepAliveDefaultRelayConnections
ensures that WebSocket connections on default relays doesn't get to be dormant. Default relays are relays that can be set by setDefaultRelay()
and are always used if temporary relays described below are not given.
Temporary relays can be dormant unless they are included in default relays.
Temporary relays
Temporary relays are relays that can be given in relays
option in use()
and send()
. If temporary relays are given, rx-nostr uses the relays to subscribe or publish.
For examle, this is useful to query events associated with nevent1.
Nip11Registry
rx-nostr automatically fetches NIP-11 relay information and uses it to optimize REQ subscriptions. Now, through the Nip11Registry
, the acquisition of NIP-11 information can be more finely controlled and manual fallback values can be specified.
If you want to know the detailed API, please refer to the doc comment.
More user-friendly MessagePacket
All MessagePacket
are now discriminated union. This makes createAllMessageObservable()
easier to use.
They still contain the from
and message
fields, but now also have a common type
("EVENT" | "EOSE" | "OK" | ...
) field and an additional alias field for each type
to access each element of the message
tuple.
rxNostr.createAllMessageObservable().subscribe((packet) => {
if (packet.type === "NOTICE") {
// TypeScript does not complain about this
console.log(packet.notice); // is equivalent to packet.message[1]
}
});
// In above case, `filterByType()` also works well
rxNostr
.createAllMessageObservable()
.pipe(filterByType("NOTICE"))
.subscribe((packet) => {
console.log(packet.notice);
});
Auto verification
All events are automatically signature verified. This behaviour can be disabled with skipVerify
option.
Auto filter condition check
All events are automatically verified to ensure that they truly match the conditions of the filter that queried them. This behaviour can be disabled with skipValidateFilterMatching
option.
Auto expiration check
All events are automatically checked whether it is expired or not based on NIP-40. This behaviour can be disabled with skipExpirationCheck
option.
tie()
operator and its familly
New tie()
operator records on which relays the same event has been seen so far, marking duplicate events.
See here for examples of usage.
RxNostrError
Exceptions caused by rx-nostr have been grouped under a single abstract class.
Deprecated Features
switchRelays()
and its familly methods
switchRelays()
and its utility wrapper addRelay()
, removeRelay()
is now deprecated. Use setDefaultRelays()
, addDefaultRelays()
, and removeDefaultRelays()
instead.
Opposed to deprecated methods, these new methods are all synchronous. If communication with the relay is attempted immediately after setDefaultRelays()
is executed, the message will be buffered and sent after WebSocket is actually established.
getRelays()
and its familly methods
getRelays()
and its utility wrapper hasRelay()
, canWriteRelay()
, and canReadRelay()
is now deprecated. Use getDefaultRelay()
or getDefaultRelays()
instead.
Renamed symbols
Some symbol are renamed for consistency. This can be roughly summarized as follows:
- An object that is set once when an instance is created and never changed is consistently called
*Config
. - An object as an optional argument of methods are consistently called
*Options
. - The relays used when
use()
orsend()
is called withoutrelays
option are calledDefaultRelay
.
Some of the exisiting symbols are retained for backward compatibility, but will be removed in v3.0.
BREAKING CHANGES
Moved feature
- In
RxNostrConfig
(ex-RxNostrOptions
) ...timeout
is renamed toeoseTimeout
globalRelayConfig.disableAutoFetchNip11Limitations
is moved toskipFetchNip11
globalRelayConfig.maxConcurrentReqsFallback
is removed.Nip11Registry.setDefault()
can be used instead.
- In
RxNostr
...fetchAllRelaysInfo()
is removed.Nip11Registry.getOrFetch()
can be used instead.
Removed features
- In
RxNostr
...setGlobalEventPacketPipe()
is removed. This is temporary.scope
option inuse()
andsend()
Methods whose signature are changed
- In
RxNostr
...getRelayState()
may returnundefined
ConnectionState
is now more detailed
Some previously existing ConnectionState
have been renamed or subdivided.
initialized
: Initialization has been completed and the connection can now be made.connecting
: Attempting to connect for reasons other than auto-retry.connected
: Connected.waiting-for-retrying
: Closed unexpectedly and the next auto-retry is scheduled.retrying
: Attempting to connect because of auto-retry.dormant
: Closed temporary because there is no active messaging.error
: Closed unexpectedly after the maximum number of retries. You can try toreconnect()
manually.rejected
: Closed by a relay with closing code 4000. You can try to reconnect, but should not do.terminated
: Closed because ofdispose()
. Never reconnect.
Refs
- refactor: rename operators by @penpenpng in #79
- feat: expiration check based on NIP-40 by @penpenpng in #80
- feat: add alias fields in MessagePackets by @penpenpng in #81
- feat: tie operator by @penpenpng in #82
Full Changelog: v1.8.1...v2.0.0