-
Notifications
You must be signed in to change notification settings - Fork 4
Description
EventStoreDB provides a projection API that can project one or multiple streams into new streams by emitting new events, see https://eventstore.com/docs/projections/user-defined-projections/index.html#functions
The API could also provide an emit function that will effectively just do a commit to a given different stream (needs to be checked to avoid circular projecting).
Right now, something like this can be achieved with a stream definition like:
eventstore.createEventStream('my-stream-projection', e => {
if (e ...) {
eventstore.commit('my-projected-stream', [new MyProjectedEvent(...)]);
}
});With the drawback, that an empty stream index my-stream-projection will be created.
Optimally, the API would not depend on the eventstore global variable, which could be solved by passing an emit function as second argument:
eventstore.createEventStream('my-stream-projection', (e, emit) => {
if (e ...) {
emit('my-projected-stream', [new MyProjectedEvent(...)]);
}
});Even better would be, if the intermediary stream index wouldn't be necessary at all:
eventstore.createEventStream('my-projected-stream', (e, emit) => {
if (e ...) {
emit([new MyProjectedEvent(...)]);
}
});That would mean, that the projection is written into the stream index of the write stream it builds. The issue here is, that the projection invocation happens in the storage layer, but the emit needs to be at the EventStore layer.