npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

streamr-client-protocol

v13.0.0

Published

JavaScript classes implementing the Streamr client-to-node protocol

Downloads

829

Readme

streamr-client-protocol

TypeScript implementations of Streamr Protocol messages and their serialization and deserialization. This is shared code used by other packages in this monorepo.

The package is available on npm as streamr-client-protocol.

Table of Contents

Use

Creating messages from arguments

Every message type from both the Control Layer and the Message Layer is defined as a class and has a static create method that takes class-specific arguments to build an instance of the latest version of the message type. The arguments for each message type are defined in the protocol documentation and in the definition of the create method.

This example shows how to create a StreamMessage and encapsulate it in a PublishRequest.

const streamMessage = new StreamMessage({
    messageId: new MessageID(...),
    content
})
const publishRequest = new PublishRequest({
    requestId: 'requestId', 
    streamMessage, 
})

Serializing messages to strings

Every message type from both the Control Layer and the Message Layer has a serialize method, which takes as argument the version to serialize to. By default, it serializes to the latest version of the message type. The serialize methods return a string.

const streamMessage = new StreamMessage({...})
streamMessage.serialize() // to latest version
// > '[31,["streamId",0,1529549961116,"publisherId","msgChainId"],null,27,0,{"foo":"bar"},0,null]'
streamMessage.serialize(30) // to MessageLayer version 30
// > '[30,["streamId",0,1529549961116,"publisherId","msgChainId"],null,27,{"foo":"bar"},0,null]'

const subscribeRequest = new SubscribeRequest({
    streamId: 'streamId', 
    streamPartition: 0, 
    sessionToken: 'sessionToken',
})
subscribeRequest.serialize() // to latest version
// > '[2,9,"requestId","streamId",0,"sessionToken"]'
subscribeRequest.serialize(1) // to ControlLayer version 1
// > '[1,9,"streamId",0,"sessionToken"]'

Parsing messages from strings

For deserialization, use the static deserialize method that is present in ControlMessage for the ControlLayer and StreamMessage for the Message Layer. The deserialize method accepts both strings and arrays as input.

const serializedStreamMessage = '[30,["streamId",0,1529549961116,"publisherId","msgChainId"],null,27,{"foo":"bar"},0,null]'
const streamMessage = StreamMessage.deserialize(serializedStreamMessage)

On the other hand, the Control Layer has many different message types. So we can only know that the deserialize method will return a ControlMessage. We can use the type field to differentiate.

const serializedMessage = '[1,9,"streamId",0,"sessionToken"]'
const controlMessage = ControlMessage.deserialize(serializedMessage)
if (controlMessage.type === ControlMessage.TYPES.UnicastMessage) {
    //treat it as a UnicastMessage
} else if (controlMessage.type === ControlMessage.TYPES.SubscribeRequest) {
    //treat it as a SubscribeRequest
} else if (...) {
    
} else {
    throw new Error(`Unknown type: ${controlMessage.type}`)
}

Release

Publishing to NPM is automated via Github Actions. Follow the steps below to publish stable (latest) or beta.

Publishing stable (latest)

  1. git checkout master && git pull
  2. Update version with either npm version [patch|minor|major]. Use semantic versioning https://semver.org/. Files package.json and package-lock.json will be automatically updated, and an appropriate git commit and tag created.
  3. git push --follow-tags
  4. Wait for Github Actions to run tests
  5. If tests passed, Github Actions will publish the new version to NPM

Publishing beta

  1. Update version with either npm version [prepatch|preminor|premajor] --preid=beta. Use semantic versioning https://semver.org/. Files package.json and package-lock.json will be automatically updated, and an appropriate git commit and tag created.
  2. git push --follow-tags
  3. Wait for Github Actions to run tests
  4. If tests passed, Github Actions will publish the new version to NPM