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

@logsn/client

v0.0.20

Published

The Log Store Network Client

Downloads

64

Readme

Documentation for the Logstore Client:

The Logstore Client is a Javascript library which serves to adds functionality for interacting with LogStore and has the following methods.

**constructor(config?: LogStoreClientConfig)**

This is the constructor for the LogStoreClient class. It takes an optional configuration object, config ****of type LogStoreClientConfig, which can be used to configure the client. .

import { StreamrClientConfig } from '@streamr/sdk;

export interface LogStoreClientConfig extends StreamrClientConfig {
	contracts?: StreamrClientConfig['contracts'] & {
		logStoreNodeManagerChainAddress?: string;
		logStoreStoreManagerChainAddress?: string;
		logStoreTheGraphUrl?: string;
	};
}

**queryStake(amount: BigNumberish, options = { usd: false })**

Stakes the specified amount of funds in order to perform queries. amount is a BigNumberish type and options is an object with a single optional property, usd, which is a boolean indicating whether the amount is in USD.

query(streamDefinition: StreamDefinition, options: QueryOptions, onMessage?: MessageListener)

Queries a stream for historical data.

streamDefinition is an object containing the stream ID and partition that should be queried. options is an object that defines the query options.

onMessage is an optional callback function that is called for each message retrieved from the stream.

Returns a Promise that resolves to a MessageStream object that provides an alternative way of iterating through the messages.

stakeOrCreateStore(streamIdOrPath: string, amount: BigNumberish)

Creates a stream in LogStore and/or stake some funds to the provided stream.

streamIdOrPath is the ID or path of the stream to be added.

amount is a BigNumberish type representing the amount to be staked on the stream.

async removeStreamFromLogStore(streamIdOrPath: string)

Removes a stream from LogStore.

streamIdOrPath is the ID or path of the stream to be removed.

isLogStoreStream(streamIdOrPath: string)

Checks if a stream is assigned to a storage node.

streamIdOrPath is the ID or path of the stream to check.

getLogStoreStreams()

Gets all streams assigned to a storage node.

Returns a Promise that resolves to an object with a blockNumber property indicating the current blockchain state and a Stream[] property representing the list of streams stored on LogStore nodes.

Code Examples and Snippets

import { LogStoreClient } from '@logsn/client';

// Initialize the logstore client
const logStoreClient = new LogStoreClient({
	auth: {
		privateKey: '0xabc123...',
	},
});

// Create a new stream
const newStream = await logStoreClient.createStream({
	id: 'domain/streamId',
});

// Adding the stream to logstore and staking some tokens to it
await logStoreClient.addStreamToLogStore(newStream.id, STAKE_AMOUNT);

// Staking some funds for the purpose of making a query
await logStoreClient.queryStake(STAKE_AMOUNT);

Using the HTTP Query API

The Logstore provides two methods to query data: Server-Sent Events (SSE) and HTTP GET requests.

// Create a query URL
const queryUrl = await logstoreClient.createQueryUrl(
  'http://some-broker-endpoint.com',
  { streamId, partition },
  "Last",
  { count: NUM_OF_LAST_MESSAGES },
);

Server-Sent Events (SSE)

// Fetch data using SSE
const streamResponse = await axios.get(queryUrl, {
  headers: { Authorization: `Basic ${token}`, Accept: "text/event-stream" },
  responseType: "stream",
});

HTTP GET Requests

// Fetch data using HTTP GET
const response = await axios.get(queryUrl, {
  headers: { Authorization: `Basic ${token}` },
}).then(({ data }) => data as HTTPQueryJSONResponse);

The API supports different types of queries and response formats. Regular HTTP responses are limited to 5000 messages per request. For real-time or incremental processing, use SSE.

For more detailed information, please refer to the Logstore API Reference.

Contributing

Installation

pnpm i

This will execute the modules NPM script which will produce the modules directory. modules contains the raw files of the streamr-network required to build the Log Store Client.

Browser Compatibility - modules

pnpm modules - used to install the source code as a dependency for browser compat.

Babel powered browser bundle currently does not emit tsyringe Typeinfo, and therefore causes bugs when imported to be extended. By including Streamr classes in bundle, we enable Babel to transpile with source.

Node Compatibility

"@streamr-client": "file:../../node_artifacts/fork-streamr-client-8.1.0.tgz", included in package.json. This way Node code can pick up forked streamr-client at @streamr-client.

Typescript can compile the forked streamr-client included in ../../node_artifacts for with Node.js. Also used for development speed as modules takes longer to setup.

pnpm build:modules - is also available for Node.

Building

For Node: pnpm build

For Browser: pnpm build-browser-production