x-cubed / event-store-client

JS client library for connecting to Event Store over TCP/IP
The Unlicense
71 stars 24 forks source link
event-store nodejs

Event Store Client

Author: Carey Bishop

Connects to an Event Store server over TCP/IP, to send and receive event information.

The Javascript API is intended to mimic the .Net API as closely as possible.

For an example of how to use it, see example.js.

Installation

At the command-line:

npm install event-store-client

In your Node.js application:

var EventStore = require('event-store-client');

A Typescript type definition is available in event-store-client.d.ts. Add this line to the top of your Typescript application:

/// <reference path='node_modules/event-store-client/event-store-client.d.ts'/>

API

Connection object

The core class in this library, represents a single TCP connection to an Event Store server.

new EventStore.Connection(options)

Creates a new Connection object and establishes a binary TCP connection to the Event Store server.

Options is an object containing the following properties:

new EventStore.TlsConnection(options)

Creates a new TLS Secured Connection object and establishes a binary TCP connection over SSL to the Event Store server. SERVER MUST USE VALID CERTIFICATE

Options is an object containing the following properties:

Connection.close()

Closes the TCP connection. To re-establish the connection, construct a new Connection object.

Connection.createGuid()

Helper function to generate GUIDs as Buffer objects, for use as the eventId value for new events.

Connection.sendPing()

Sends a ping request to the server.

Connection.subscribeToStream()

Subscribes to a stream to receive notifications as soon as an event is written to the stream.

Returns a Buffer containing a GUID that identifies the subscription, for use with unsubscribeStream().

Connection.subscribeToStreamFrom()

Executes a catch-up subscription on the given stream, reading events from a given event number, and continuing with a live subscription when all historical events have been read.

Returns an instance representing the catch-up subscription (EventStoreStreamCatchUpSubscription).

Connection.readAllEventsBackward() / Connection.readAllEventsForward()

Reads events from across all streams, in order (backward = newest first, forward = oldest first).

Connection.readStreamEventsBackward() / Connection.readStreamEventsForward()

Reads events from a specific stream, in order (backward = newest first, forward = oldest first).

Connection.unsubscribeFromStream()

Cancels an existing subscription to a stream.

Connection.writeEvents()

Writes one or more events to a stream, creating the stream if it doesn't exist.

Event class

Represents an event either before or after it has been stored.

StoredEvent class

Represents an event as it exists on the Event Store server. Inherits from Event and adds the following properties:

ICredentials interface

An object containing credentials for access to secured resources.

ISubscriptionConfirmation interface

Passed to the onConfirmed callback used by subscribeToStream() when a subscription is successfully created.

ISubscriptionDropped interface

Passed to the onDropped callback used by subscribeToStream() when a subscription terminates, or cannot be established.

ISubscriptionNotHandled interface

Passed to the onNotHandled callback used by subscribeToStream() when a request to subscribe fails.

CatchUpSubscriptionSettings class

A property bag of settings passed when creating a new catch-up subscription.

EventStoreStreamCatchUpSubscription class

Represents a catch-up subscription to a single stream.

EventStoreStreamCatchUpSubscription.start()

Initiate start of the catch-up subscription.

EventStoreStreamCatchUpSubscription.stop()

Request to stop the catch-up subscription.

EventStoreStreamCatchUpSubscription.getCorrelationId()

Get the subscription ID of the underlying Event Store subscription, in order to pass it back to the Connection object, for example.