Skip to content

Commit

Permalink
Merge pull request #24 from aktos-io/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ceremcem authored Sep 22, 2017
2 parents 081f548 + 8d121de commit 515960a
Show file tree
Hide file tree
Showing 91 changed files with 3,913 additions and 1,890 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "aktos-dcs-design"]
path = aktos-dcs-design
path = aktos-dcs
url = https://github.com/aktos-io/aktos-dcs-design
[submodule "protocols/siemens/nodeS7"]
path = protocols/siemens/nodeS7
path = connectors/siemens/nodeS7
url = https://github.com/ceremcem/nodeS7
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ Implements the following features:
* Browser Actors
* Message routing by subscriptions

# Status

This library is intended to stay as a dependency of [ScadaJS](https://github.com/aktos-io/scada.js). In the near future, it will be able to be used in any NodeJS project.

# Contact

info@aktos.io
17 changes: 8 additions & 9 deletions browser.ls
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
require! './src/actor': {Actor}
require! './src/io-actor': {IoActor}
require! './src/socketio-browser': {SocketIOBrowser}
require! './src/filters': {FpsExec}
require! './src/signal': {Signal}
require! './src/find-actor': {find-actor}
require! './src/couch-dcs/couch-dcs-client': {CouchDcsClient}
require! './connectors/socketio/browser': {SocketIOBrowser}
require! './connectors/socketio/server': {SocketIOServer}
require! './connectors/couch-dcs/client': {CouchDcsClient}
require! './src/topic-match': {topic-match}
require! './src/filters': {FpsExec}
require! './src/ractive-actor': {RactiveActor}

module.exports = {
IoActor, SocketIOBrowser, Signal, Actor
find-actor, CouchDcsClient
Actor
Signal
SocketIOBrowser, SocketIOServer
CouchDcsClient
topic-match
FpsExec
RactiveActor
}
6 changes: 6 additions & 0 deletions connectors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# TODO

- [ ] email
- [ ] sms
- [ ] udp
- [ ] webrtc
121 changes: 121 additions & 0 deletions connectors/couch-dcs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Couch DCS

This server and client libraries are created to be able to use CouchDB over DCS network.

In addition to changing transport layer from HTTP to DCS, this library aims to [address some CouchDB limitations](./addressing-couchdb-limitations.md).

## Usage


1. Run `CouchDcsServer` instance on your server:


```ls
new CouchDcsServer do
user:
name: 'your-couchdb-username'
password: 'your-password'
url: "IP-OR-ADDRESS-OF-YOUR-COUCHDB-INSTANCE"
database: 'your-db-name'
```

2. Create a `CouchDcsClient` instance use it as if it was a regular CouchDB driver:

```ls
db = new CouchDcsClient 'document-type'
console.log "getting the document with 'your-document-id':"
err, res <~ db.get 'your-document-id'
console.log "response is: ", res
```

3. In order to make it work, ensure that your user have `db.document-type.**` permissions.

# API

`CouchDcsClient` has the following API:

* `.get 'document-id', [opts, ] callback`
* `.put doc, callback`
* `.view 'designName/yourView', [opts, ] callback`
* `.all callback`
* `.getAttachment 'document-id', 'attachment-name', callback`

Callbacks will be called with `error, response` parameters.

# Additional Functionalities

## Create documents with `AUTOINCREMENT`ed ID's

Suppose you will save documents by autoincrementing the ID field. Follow the steps:

### 1. Setup

Create a view with name `short` in `autoincrement` design document in your db:

```ls
views:
short:
map: (doc) ->
prefix = doc._id.split /[0-9]+/ .0
if prefix
seq = if doc._id.split prefix .1 => parse-int that else 0
prefix = prefix.split /[^a-zA-Z]+/ .0.to-upper-case!
emit [prefix, seq], null
```


### Creating a document

1. If you want to assign an autoincremented ID, append '#' character to your document's `_id` field:

```js
{
_id: 'foo-####',
type: 'bar',
hello: 'there'
}
```

2. Save your document with `CouchDcsClient.put` method, as usual.

Your document id will be something like `foo-1358`

### Notes

1. *On save*: Your prefix is calculated by splitting right before first '#'
character and grabbing left side of the result.

| Autoincrement ID | Calculated Prefix | Example ID |
| ---- | ----- | ---- |
| `foo###` | `foo` | `foo1234` |
| `foo-###` | `foo-` | `foo-1234` |
| `Foo-###` | `Foo-` | `Foo-1234` |

2. *On calculating next ID*: Current biggest ID is calculated by splitting right before any alphanumeric characters, grabbing left side, converting to upper case.

For example, we have `foo-5` in the database. Following autoincremented IDs will be assigned for the IDs:

| Seq. | Provided `doc._id` | Saved as |
| ---- | ----- | ----- |
| 1 | `foo-#` | `foo-6` |
| 2 | `foo-#` | `foo-7` |
| 3 | `foo#` | `foo8`
| 4 | `FoO---###` | `FoO---9` |
| 5 | `fooo-#` | `fooo-1` |
| 6 | `fOO#####` | `fOO10` |

### Troubleshooting

To verify that your view returns the correct ID, use the following filter to get latest ID:

```
http://example.com/yourdb/_design/autoincrement/_view/short?descending=true&startkey=["FOO",{}]&endkey=["FOO"]
```

# Roadmap

- [ ] Add document deduplication support
- [ ] Provide a way to resume interrupted downloads/uploads
- [ ] Stream videos directly from database
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require! '../actor': {Actor}
require! '../../src/actor': {Actor}


export class CouchDcsClient extends Actor
Expand Down Expand Up @@ -37,7 +37,7 @@ export class CouchDcsClient extends Actor
# end of normalization

err, msg <~ @send-request {
topic: "#{@topic}.put"
topic: "#{@topic}.put"
timeout: opts.timeout or 20_000ms}, {put: doc}
callback (err or msg?.payload.err), msg?.payload.res

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require! 'prelude-ls': {flatten, join, split}
require! 'nano'
require! 'colors': {bg-red, bg-green, bg-yellow, bg-blue}
require! 'aea': {sleep, pack, logger, EventEmitter}
require! '../../lib': {Logger, sleep, pack, EventEmitter}

export class CouchNano extends EventEmitter
"""
Expand All @@ -15,7 +15,7 @@ export class CouchNano extends EventEmitter
"""
(@cfg) ->
super!
@log = new logger "db:#{@cfg.database}"
@log = new Logger "db:#{@cfg.database}"
@username = @cfg.user.name
@password = @cfg.user.password
@db-name = @cfg.database
Expand Down
Loading

0 comments on commit 515960a

Please sign in to comment.