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

parsegraph-stream

v3.0.25

Published

stream

Downloads

102

Readme

parsegraph-stream

This project builds a client-side library to receive Parsegraph server events and update a local graph accordingly. It also allows for the client to callback the server based on graph interaction.

This module allows live updates from a Parsegraph server to multiple connected clients.

It also contains a server used to stream Parsegraph server events.

The problem

Parsegraph applications can be written solely on the client, with callbacks embedded in the application. However, it becomes challenging to add sharing of the Parsegraph environment to other users, because updates to the graph must be maintained.

Parsegraph stream inverts this problem by making all graph updates come from the server. It provides means to add callbacks to the graph, completing a round-trip of serving an initial graph, letting the user invoke graph actions, and sending graph updates back to the client once the callback is complete.

How to use

Run a server, either locally or within a container, and navigate to /. You should see a Parsegraph client. This will show the Parsegraph for the content root. The content root is set by the CONTENT_ROOT environment variable.

Hosting a container

The container will run the demo server.

make build-container
docker run -d --net bridge --name parsegraph -e SITE_HOST=0.0.0.0 -e CONTENT_ROOT=/usr/src --expose 3000 -p=127.0.0.1:15000:3000/tcp localhost/parsegraph-stream:latest

interface ParsegraphServer

A Parsegraph server manages a collection of proxy Parsegraph objects, and is able to stream changes to those Parsegraph objects to callbacks.

server.setCallbackUrl(callbackUrl: string): void

Sets the callback URL used by the server

server.connect(cb:(...args: any) => void): () => void

Stream server events as arguments back to the given callback.

server.forEach(cb:(...args: any) => void): void

Send all saved server events back to the given callback.

server.callback(callbackIndex: number, val?: any): void

Invokes the server callback

server.state(): ParsegraphServerState

Returns the server state.

interface ParsegraphServerState

The Parsegraph server state contains the current state of the Parsegraph, and provides methods to update the state using Parsegraph proxy objects.

server.state().setBackgroundColor(r:number, g:number, b:number, a:number): void

Sets the background color in RGBA space. Numbers are expected to be in range [0, 1].

server.state().newCaret(type?: any): ParsegraphCaret

Returns a Parsegraph caret, using the given type as the initial value of the caret root node.

server.state().setRoot(n: ParsegraphNode): void

Sets the root to the given Parsegraph node.

script.js module methods

These are the two methods imported from script.js, used to create new ParsegraphServers.

streamPath(mainPath: string, subPath: string): ParsegraphServer

Returns a Parsegraph server designed for streaming and callbacks.

A new Parsegraph streaming server is launched for the subPath if necessary.

  • mainPath - the contentRoot.
  • subPath - the URL part specific to the stream.

servePath(mainPath: string, subPath: string): ParsegraphServer

Returns a Parsegraph server designed for caching.

A new Parsegraph server is launched for the subPath if necessary.

  • mainPath - the contentRoot.
  • subPath - the URL part specific to the stream.

API Endpoints

GET /testroute: text/plain endpoint

health check.

Responds 200 with "testroute from server" on success.

GET /parsegraph/(.*): EventStream endpoint

Connect to a Parsegraph streaming server named by the URL and stream Parsegraph events back to the client.

GET /events/(.*) EventStream endpoint

Content to a Parsegraph server named by the URL and stream Parsegraph events back to the client.

GET /graph/(.*) text/plain endpoint

Connects to a Parsegraph server and writes all saved events back to the client, and close the connection.

GET /raw/(.*) Raw content

Stream raw content from the given path, under the content root.

POST /callback/(.*)?cb=123 JSON request

Finds a Parsegraph streaming server named by the URL, and calls callback by index, passing the request body as the argument.

The cb query parameter is the callback index.

  • Responds 500 on server error
  • Responds 200 on success

POST /splice/(.*) JSON request

Takes a JSON request of the following form:

interface SpliceRequest {
    offset: number;
    len: number;
    val: string;
}

And splices val in the file at the named subPath, under the content root. Both the Parsegraph servers and streaming server are replaced.

  • Responds 200 if the splice is successful.
  • Responds 500 on server error
  • Responds 400 if the offset or len are NaN.