# jetstream

> Jetstream Sync server framework to sync local and remote models

Latest version **0.13.4** (published 2016-03-04) · 0 weekly downloads

## Install

```sh
npm install jetstream
pnpm add jetstream
yarn add jetstream
bun add jetstream
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.13.4 |
| Published | 2016-03-04 |
| First published | 2014-10-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 20 |
| Known vulnerabilities | 0 (+11 in 5 direct dependencies) |
| Install scripts | no |
| GitHub stars | 116 |
| Author | Rob Skillington |
| Maintainers | robskillington, uber |
| Keywords | framework, realtime, modular |

## Links

- npm: https://www.npmjs.com/package/jetstream
- Repository: https://github.com/uber/jetstream
- Issues: https://github.com/uber/jetstream/issues
- npm.io page: https://npm.io/package/jetstream

## Dependencies (20)

- [ws](https://npm.io/package/ws.md) ^0.8.1
- [robb](https://npm.io/package/robb.md) ^0.2.1
- [async](https://npm.io/package/async.md) ^0.9.0
- [debug](https://npm.io/package/debug.md) ^2.2.0
- [dotty](https://npm.io/package/dotty.md) 0.0.2
- [error](https://npm.io/package/error.md) ^4.3.0
- [replr](https://npm.io/package/replr.md) ^0.2.4
- [tryit](https://npm.io/package/tryit.md) ^1.0.1
- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [rwlock](https://npm.io/package/rwlock.md) ^5.0.0
- [semver](https://npm.io/package/semver.md) ^4.0.0
- [express](https://npm.io/package/express.md) ^4.8.5
- [request](https://npm.io/package/request.md) ^2.51.0
- [winston](https://npm.io/package/winston.md) ^2.2.0
- [deepequal](https://npm.io/package/deepequal.md) 0.0.1
- [node-uuid](https://npm.io/package/node-uuid.md) ^1.4.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.6.5
- [rust-result](https://npm.io/package/rust-result.md) ^0.1.0
- [maybe-callback](https://npm.io/package/maybe-callback.md) ^1.0.0
- [callback-or-emit-error](https://npm.io/package/callback-or-emit-error.md) ^1.0.1

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.13.4 (latest) — 2016-03-04
- 0.13.3 — 2016-01-31
- 0.13.2 — 2016-01-31
- 0.13.1 — 2016-01-25
- 0.13.0 — 2016-01-24
- 0.12.0 — 2016-01-23
- 0.11.5 — 2015-12-20
- 0.11.4 — 2015-10-08
- 0.11.3 — 2015-03-10
- 0.11.2 — 2015-03-10
- 0.11.1 — 2015-03-10
- 0.11.0 — 2015-03-10
- 0.10.0 — 2015-03-09
- 0.9.12 — 2015-02-25
- 0.9.11 — 2015-02-21
- … 27 more at https://npm.io/package/jetstream/versions

## README

![Jetstream](https://raw.githubusercontent.com/uber/jetstream-ios/assets/jetstream.png)


[![Build Status](https://img.shields.io/travis/uber/jetstream.svg?style=flat)](https://travis-ci.org/uber/jetstream)

Jetstream for Node is a server that brokers syncing Jetstream models over the Jetstream Sync protocol. Out of the box it has a single Websocket transport adapter with the ability to add custom transport adapters.

## Features

- [x] Synchronize a shared set of models between many clients
- [x] Client and server message acknowledgement and resend capabilities
- [ ] Transactional application of changesets
- [x] Synchronize and validate changesets with downstream services
- [x] Modular architecture
- [x] ~~Comprehensive Unit~~ Test Coverage

## Communication

- If you **found a bug**, fix it and submit a pull request, or open an issue.
- If you **have a feature request**, implement it and submit a pull request or open an issue.
- If you **want to contribute**, submit a pull request.
- For further details see `CONTRIBUTION.md`.

## Installation

`npm install jetstream`

## Run demo

`npm start`

## Tests

`npm test`

## Documentation

See the `docs` directory. A good start is with `docs/overview.md`.

# Usage

### Creating models

Jetstream works with two basic concepts: All your model objects extend from the superclass `ModelObject` and one of your ModelObject instances will be the root for your model tree encapsulated by a `Scope`.

Let's model a canvas of shapes:

```js
var createModel = require('jetstream').model;

var Shape = createModel('Shape', function() {
    this.has('x', Number);
    this.has('y', Number);
    this.has('width', Number);
    this.has('height', Number);
    this.has('type', Number);
});

var Canvas = createModel('Canvas', function() {
    this.has('name', String);
    this.has('shapes', [Shape]);
});
```

Supported types are `String`, `Number`, `Boolean`, `Date`, `ModelObject` and `[ModelObject]`

### Creating a server

```js
var createScope = require('jetstream').scope;
var createServer = require('jetstream');
var createWebsocketTransport = require('jetstream').transport.WebsocketTransport.configure;

// Example of connecting multiple clients to a shared scope
var canvas = new Canvas();
canvas.name = 'Shapes Demo';

var scope = createScope({name: 'Canvas'});
scope.setRoot(canvas);

// Start server with default transports
var websocketTransport = createWebsocketTransport({port: 3000});
var transports = [websocketTransport];
var server = createServer({transports: transports});
server.on('session', function(session, params, callback) {
    // Accept the session, no authentication or authorization in this example
    callback();

    session.on('fetch', function(name, params, callback) {
        // Verify fetching the scope 
        if (name !== scope.name) {
            return callback(new Error('No such scope'));
        }
        callback(null, scope);
    });
});

```
### Protocol

Jetstream uses JSON-based messages to create sessions, fetch scopes and synchronize changes. In case you want to build your own client or server, refer to the [protocol documentation](https://github.com/uber/jetstream/wiki/Protocol).

# License

Jetstream is available under the MIT license. See the LICENSE file for more info.

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