Skip to content

Instantly share code, notes, and snippets.

@jeremydmiller
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremydmiller/716aa056a94f81b5715b to your computer and use it in GitHub Desktop.
Save jeremydmiller/716aa056a94f81b5715b to your computer and use it in GitHub Desktop.
Possible client API for appending events
var client = require('pg-events-client'); // just pretend this is what it is
/*
id is unnecessary if it's a new stream, but obviously required
to append to an existing stream
streamType is quasi necessary just to route events to projections.
We can build an "Options" that allows
you to specify a default streamType if it's undefined
We could also create a mapping of allowable event types to stream types
I'm starting to think that we create some kind of Stream and Event functions
to act as a domain model that would work well w/ the EventStorage
*/
var evt = {
$type: 'QuestStarted',
location: 'Rivendell'
};
// UNDERLYING TRANSPORT REGARDLESS THAT YOU CAN USE RUBY HASHROCKET STYLE
// All overloads are going to end up sending this message one way or another
client.append({
id: SOMEGUID, // not mandatory if it's a new stream
type: 'the stream type', // again, not completely mandatory
data: [evt]
});
// Also for events in multiple streams/aggregates at one time:
client.batch({
id1: {type: 'the stream type', data: []},
id2: {type: 'the stream type', data: []}
});
// OPTION #1: be cute with overloads -- building batch support in right off the bat
// would do a typeof is string for the arg in the [1] position
client.append(id, streamType, evt1, evt2, evt3, ...);
// streamType will either be the existing stream type (easy), the default stream
// type according to the configured options, or based on the event type
client.append(id, evt1, evt2, ...);
// again, do some trickery to see that it's not of type string or uuid
client.append(evt1, evt2, evt3);
// OPTION #2: be cute with method chaining with something like
// one of the following
client.id(id).streamType(type).append(evt1, evt2, evt3);
client.appendTo(id).ofType(streamType).data(events);
client.newStream.ofType(streamType).data(events);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment