Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Append, Read, and Subscribe Options #5

Merged
merged 20 commits into from
Sep 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
811b467
Updated readme to reflect nodejs nature
bmavity Sep 4, 2014
de75794
Pulled TCP Payload parsing into its own module
bmavity Sep 4, 2014
2ad6512
Heartbeat message response will now keep connection open
bmavity Sep 4, 2014
e1c6a67
ES errors no longer cause connection test failure after the test has …
bmavity Sep 5, 2014
675c442
Removed logging from flag/command converters
bmavity Sep 5, 2014
5697f91
Bad Expected Version handled on write
bmavity Sep 5, 2014
b4f1f5a
Can now successfully write to a stream
bmavity Sep 5, 2014
a362951
Separated read and append test files
bmavity Sep 5, 2014
0b857b5
Implemented argument checking on read stream events forward
bmavity Sep 5, 2014
28c0bc2
Implemented more read event stream forward tests
bmavity Sep 5, 2014
0f16c27
append_to_stream tests that don't involve deleting streams now pass
bmavity Sep 5, 2014
9b3bd20
Added goal .cs files to ignore
bmavity Sep 5, 2014
f20ee30
Extracted range into its own module
bmavity Sep 6, 2014
d03c886
All append_to_stream tests passing except for once involving deleted …
bmavity Sep 6, 2014
877e944
Bumped es-test-helper version
bmavity Sep 6, 2014
360a231
appending to implicitly created stream now implemented
bmavity Sep 7, 2014
3d4f205
Basic subscribe implemented execept for ones dealing with deleted str…
bmavity Sep 7, 2014
730dd9c
Updated README to reflect current status
bmavity Sep 8, 2014
09ad54f
Updated port numbers on tests
bmavity Sep 8, 2014
5a2188d
Small readme update
bmavity Sep 8, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.sublime-*
node_modules
.OpenIDE
EventStore
EventStore
goal
56 changes: 45 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ges-client
=======

**A client library for [(Get) Event Store](http://geteventstore.com)**
**A nodejs client library for [(Get) Event Store](http://geteventstore.com)**


[![Build Status](https://secure.travis-ci.org/bmavity/ges-client.svg)](http://travis-ci.org/bmavity/ges-client)
Expand All @@ -12,6 +12,7 @@ ges-client
* <a href="#intro">Introduction</a>
* <a href="#basic">Basic usage</a>
* <a href="#licence">Licence &amp; copyright</a>
* <a href="#thanks">Special Thanks</a>

<a name="intro"></a>
Introduction
Expand All @@ -29,26 +30,52 @@ Install
$ npm install ges-client
```

Read from an event stream
Append and read from an event stream

```js
var ges = require('ges-client')

// 1) Create a connection to a running EventStore
// using default connection options and credentials
var es = ges()
var connection = ges()
, stream = 'intro-events'

// 2)
// 2) Append events that can be read
var thingsThatHappened = [array of events]
es.appendToStream('intro-events', thingsThatHappened, function (err) {
if (err) return console.log('Ooops!', err) // connection error
connection.on('connect', function() {
connection.appendToStream(stream, ges.expectedVersion.emptyStream, thingsThatHappened, function(err, appendResult) {
if(err) return console.log('Ooops!', err) // connection error

// 3) Read first events from the stream
connection.readStreamEventsForward(stream, { start: 0, count: 1 }, function(err, readResult) {
if(err) return console.log('Ooops!', err) // connection error or stream does not exist

// ta da!
console.log(readResult.Events)
})
})
})
```

Subscribe to stream updates

```js
var ges = require('ges-client')

// 3) Read all events from the stream
es.readStreamForward('intro-events', function (err, events) {
if (err) return console.log('Ooops!', err) // connection error or stream does not exist
// 1) Create a connection to a running EventStore
// using default connection options and credentials
var connection = ges()
, stream = 'intro-events'

// 2) Create a subscription
var thingsThatHappened = [array of events]
connection.on('connect', function() {
var subscription = connection.subscribeToStream(stream)

// ta da!
console.log(events)
// 3) Listen for events
subscription.on('event', function(evt) {
// ta da!
console.log(evt)
})
})
```
Expand All @@ -62,4 +89,11 @@ Copyright (c) 2014 Brian Mavity.
ges-client is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.


<a name="thanks"></a>
Special Thanks
-----------

Special thanks to Ken Pratt for writing the first version of this over at https://github.com/kenpratt/nodejs-EventStore .
It made early development go by much faster.


17 changes: 17 additions & 0 deletions eventData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = function EventData(eventId, type, isJson, data, metadata) {
if(!(this instanceof EventData)) {
return new EventData(eventId, type, isJson, data, metadata)
}

isJson = !!isJson
data = data || new Buffer(0)
metadata = metadata || new Buffer(0)

Object.defineProperties(this, {
EventId: { value: eventId, enumerable: true }
, Type: { value: type, enumerable: true }
, IsJson: { value: isJson, enumerable: true }
, Data: { value: data, enumerable: true }
, Metadata: { value: metadata, enumerable: true }
})
}
20 changes: 20 additions & 0 deletions ges-client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
var tcpConnect = require('./tcp/connection')
, expectedVersion = {}
, streamPosition = {}

module.exports = createConnection


Object.defineProperties(module.exports, {
expectedVersion: { value: expectedVersion }
, maxRecordCount: { value: 2147483647 }
, streamPosition: { value: streamPosition }
})

Object.defineProperties(streamPosition, {
start: { value: 0 }
, end: { value: -1 }
})

Object.defineProperties(expectedVersion, {
any: { value: -2 }
, noStream: { value: -1 }
, emptyStream: { value: -1 }
})


function createConnection(opts) {
return tcpConnect(opts)
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
"request": "2.34.x"
},
"devDependencies": {
"async": "^0.9.0",
"ges-test-helper": "^0.1.2",
"mocha": "^1.21.4",
"should": "^4.0.4",
"ges-test-helper": "^0.1.1"
"should": "^4.0.4"
},
"engines": {
"node": "0.10.x"
},
"scripts": {
"test": "mocha -r should -R tap -t 10s test/**/*.js",
"watch": "mocha -w -r should -R spec test/**/*.js"
"watch": "mocha -w -r should -R spec -t 10s test/**/*.js"
},
"keywords": [],
"license": "MIT +no-false-attribs, +no-advertising License",
Expand Down
Loading