# parsegraph-stream

> stream

Latest version **3.0.25** (published 2023-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install parsegraph-stream
pnpm add parsegraph-stream
yarn add parsegraph-stream
bun add parsegraph-stream
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.25 |
| Published | 2023-02-01 |
| First published | 2022-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 7.8 MB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Rainback, Inc. |
| Maintainers | dafrito |

## Links

- npm: https://www.npmjs.com/package/parsegraph-stream
- Repository: https://github.com/parsegraph/stream
- Homepage: https://github.com/parsegraph/stream#readme
- Issues: https://github.com/parsegraph/stream/issues
- npm.io page: https://npm.io/package/parsegraph-stream

## Dependencies (12)

- [yaml](https://npm.io/package/yaml.md) ^2.1.1
- [react](https://npm.io/package/react.md) ^18.2.0
- [espree](https://npm.io/package/espree.md) ^9.4.1
- [esprima](https://npm.io/package/esprima.md) ^4.0.1
- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^4.0.9
- [parsegraph-block](https://npm.io/package/parsegraph-block.md) ^4.6.23
- [parsegraph-color](https://npm.io/package/parsegraph-color.md) ^1.4.13
- [react-reconciler](https://npm.io/package/react-reconciler.md) ^0.29.0
- [parsegraph-artist](https://npm.io/package/parsegraph-artist.md) ^3.4.65
- [parsegraph-direction](https://npm.io/package/parsegraph-direction.md) ^2.2.6
- [parsegraph-blockpainter](https://npm.io/package/parsegraph-blockpainter.md) ^1.7.12
- [webpack-bundle-analyzer](https://npm.io/package/webpack-bundle-analyzer.md) ^4.7.0

## Recent versions

- 3.0.25 (latest) — 2023-02-01
- 3.0.25-dev (dev) — 2023-02-01
- 3.0.24 — 2023-02-01
- 3.0.24-dev — 2023-02-01
- 3.0.23 — 2023-02-01
- 3.0.23-dev — 2023-02-01
- 3.0.22 — 2023-02-01
- 3.0.22-dev — 2023-02-01
- 3.0.21 — 2023-01-24
- 3.0.21-dev — 2023-01-24
- 3.0.20 — 2023-01-24
- 3.0.20-dev — 2023-01-24
- 3.0.17 — 2023-01-23
- 3.0.17-dev — 2023-01-23
- 3.0.16 — 2023-01-23
- … 32 more at https://npm.io/package/parsegraph-stream/versions

## 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.

---
_Source: https://npm.io/package/parsegraph-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
