Created
August 18, 2014 15:47
-
-
Save thefringeninja/31c0c471120053cc09c3 to your computer and use it in GitHub Desktop.
Sample GES Projection That "Unrolls" NES Commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"BucketId": "b", | |
"StreamId": "1b42e222-92d6-4242-a528-53a8e61fa524", | |
"StreamRevision": 2, | |
"CommitId": "0b7efcaa-9923-4813-a780-380fb23ad04a", | |
"CommitSequence": 1, | |
"CommitStamp": "2014-08-18T15:36:43.5386215Z", | |
"Headers": { | |
"A header": "A string value", | |
"Another header": 2 | |
}, | |
"Events": { | |
"$type": "System.Collections.ObjectModel.Collection`1[[NEventStore.EventMessage, NEventStore]], mscorlib", | |
"$values": [ | |
{ | |
"Headers": {}, | |
"Body": { | |
"$type": "NEventStore.Persistence.AcceptanceTests.ExtensionMethods+SomeDomainEvent, NEventStore.Persistence.AcceptanceTests", | |
"SomeProperty": "Test" | |
} | |
}, | |
{ | |
"Headers": {}, | |
"Body": { | |
"$type": "NEventStore.Persistence.AcceptanceTests.ExtensionMethods+SomeDomainEvent, NEventStore.Persistence.AcceptanceTests", | |
"SomeProperty": "Test2" | |
} | |
} | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EventType: ExtensionMethods+SomeDomainEvent, Position: 1 | |
{ | |
"$type": "NEventStore.Persistence.AcceptanceTests.ExtensionMethods+SomeDomainEvent, NEventStore.Persistence.AcceptanceTests", | |
"SomeProperty": "Test2" | |
} | |
// EventType: ExtensionMethods+SomeDomainEvent, Position: 0 | |
{ | |
"$type": "NEventStore.Persistence.AcceptanceTests.ExtensionMethods+SomeDomainEvent, NEventStore.Persistence.AcceptanceTests", | |
"SomeProperty": "Test" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fromStream("$et-NEventStoreCommit") | |
.partitionBy(function(e){ | |
return e.body.BucketId + "-" + e.body.StreamId; | |
}) | |
.when({ | |
NEventStoreCommit: function(s, e) { | |
if (!e.body || !e.body.Events) return; | |
var events = e.body.Events.$values || e.body.Events || []; | |
for (var i=0; i < events.length; i++) { | |
var eventMessage = events[i]; | |
var data = eventMessage.Body; | |
var metadata = eventMessage.Headers; | |
var clrType = data.$type; | |
if (!clrType) return; | |
var fullTypeName = clrType.split(",")[0]; | |
var type = fullTypeName.split(".").pop(); | |
if (!type) return; | |
emit("flattened-" + e.body.BucketId + "." + e.body.StreamId, type, data, metadata); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment