eventric
Version:
Build JavaScript applications with Behaviour-driven Domain Design. Based on DDD, BDD, CQRS and EventSourcing.
138 lines (89 loc) • 3.28 kB
text/coffeescript
eventric = require 'eventric'
PubSub = require 'eventric/src/pub_sub'
projectionService = require 'eventric/src/projection'
class Remote extends PubSub
constructor: () ->
super
=
= {}
= {}
= {}
= {}
= {}
'inmemory', (require 'eventric/src/remote/inmemory').client
'default client', 'inmemory'
set: (key, value) ->
[key] = value
@
get: (key) ->
[key]
command: ->
'command', arguments
query: ->
'query', arguments
findAllDomainEvents: ->
'findAllDomainEvents', arguments
findDomainEventsByName: ->
'findDomainEventsByName', arguments
findDomainEventsByAggregateId: ->
'findDomainEventsByAggregateId', arguments
findDomainEventsByAggregateName: ->
'findDomainEventsByAggregateName', arguments
findDomainEventsByNameAndAggregateId: ->
'findDomainEventsByNameAndAggregateId', arguments
subscribeToAllDomainEvents: (handlerFn, options = {}) ->
clientName = 'default client'
client = clientName
client.subscribe , handlerFn
subscribeToDomainEvent: (domainEventName, handlerFn, options = {}) ->
clientName = 'default client'
client = clientName
client.subscribe , domainEventName, handlerFn
subscribeToDomainEventWithAggregateId: (domainEventName, aggregateId, handlerFn, options = {}) ->
clientName = 'default client'
client = clientName
client.subscribe , domainEventName, aggregateId, handlerFn
unsubscribeFromDomainEvent: (subscriberId) ->
clientName = 'default client'
client = clientName
client.unsubscribe subscriberId
_rpc: (method, params) ->
new Promise (resolve, reject) =>
clientName = 'default client'
client = clientName
client.rpc
contextName:
method: method
params: Array.prototype.slice.call params
, (err, result) ->
if err
reject err
else
resolve result
addClient: (clientName, client) ->
[clientName] = client
@
getClient: (clientName) ->
[clientName]
addProjection: (projectionName, projectionClass) ->
[projectionName] = projectionClass
@
initializeProjection: (projectionObject) ->
projectionService.initializeInstance
object: projectionObject
, null, @
initializeProjectionInstance: (projectionName, params) ->
if not [projectionName]
err = "Given projection #{projectionName} not registered on remote"
eventric.log.error err
err = new Error err
return err
projectionService.initializeInstance
name: projectionName
class: [projectionName]
, params, @
getProjectionInstance: (projectionId) ->
projectionService.getInstance projectionId
destroyProjectionInstance: (projectionId) ->
projectionService.destroyInstance projectionId, @
module.exports = Remote