https://github.com/mikeal/sleep
Implementation of the SLEEP protocol.
https://github.com/mikeal/sleep
Last synced: 2 months ago
JSON representation
Implementation of the SLEEP protocol.
- Host: GitHub
- URL: https://github.com/mikeal/sleep
- Owner: mikeal
- Created: 2013-07-06T22:37:03.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-07-11T22:03:13.000Z (almost 8 years ago)
- Last Synced: 2024-10-18T09:13:55.100Z (8 months ago)
- Language: JavaScript
- Size: 38.1 KB
- Stars: 29
- Watchers: 10
- Forks: 6
- Open Issues: 6
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## SLEEP
[](https://travis-ci.org/mikeal/SLEEP) [](https://david-dm.org/mikeal/SLEEP) [](http://badge.fury.io/js/sleep-ref)
[](https://nodei.co/npm/sleep-ref/)SLEEP is a protocol envisioned by @maxogden for open data publication and synchronization. It stands for Syncasble Lightweight Event Emitting Persistence, but is mostly just a pun on REST.
The official SLEEP spec lives [on dataprotocols.org](http://dataprotocols.org/sleep/). `sleep-ref` doesn't necessarily follow the spec as it is currently written -- consider this to be more experimental.
This project is meant to iterate on the spec through implementation and also to produce a module that is easily usable by other databases to expose their data with SLEEP.
### Server
```javascript
var sleep = require('sleep-ref')
, http = require('http')
, net = require('net')
;function getSequences (opts) {
var c = mydatabase.getChangesStream(opts) // emits {id:'uuid', seq:1}, {id:'uuid2', seq:3}
// if opts.include_data it emits e.g. c.data = mydatabase.get(c.id)
return c
}var sl = sleep(getSequences)
http.createServer(function (req, resp) {
sl.httpHandler(req, resp)
})net.createServer(function (socket) {
sl.netHandler(socket)
})
```### Client
```javascript
var sleep = require('sleep-ref')
, changes = sleep.client('http://localhost:8888/', { include_data: true })
;
changes.on('data', function (entry) { console.log(entry) })
changes.on('end', function () { console.log('up to date') })
````sleep.client(url[, opts])` takes all valid SLEEP options. The url responds to the following protocols: `http:`, `https:`, `tcp:`, and `tls:`. You can pass tls options to `opts` via the `tls` property.
### Tests
% make test
or if you don't have `make`:
% npm install
% npm test