eventric
Version:
behavior-first application development
112 lines (73 loc) • 2.8 kB
text/coffeescript
class Remote
: [
'command'
'query'
'findDomainEventsByName'
'findDomainEventsByNameAndAggregateId'
]
constructor: (, ) ->
=
= require './inmemory'
= {}
= {}
= {}
= {}
= {}
= new .Projection
'inmemory', .client
'default client', 'inmemory'
()
_exposeRpcOperationsAsMemberFunctions: ->
Remote.ALLOWED_RPC_OPERATIONS.forEach (rpcOperation) =>
@[rpcOperation] = =>
rpcOperation, arguments
set: (key, value) ->
[key] = value
@
get: (key) ->
[key]
subscribeToAllDomainEvents: (handlerFn) ->
clientName = 'default client'
client = clientName
client.subscribe , handlerFn
subscribeToDomainEvent: (domainEventName, handlerFn) ->
clientName = 'default client'
client = clientName
client.subscribe , domainEventName, handlerFn
subscribeToDomainEventWithAggregateId: (domainEventName, aggregateId, handlerFn) ->
clientName = 'default client'
client = clientName
client.subscribe , domainEventName, aggregateId, handlerFn
unsubscribeFromDomainEvent: (subscriberId) ->
clientName = 'default client'
client = clientName
client.unsubscribe subscriberId
_rpc: (method, params) ->
clientName = 'default client'
client = clientName
client.rpc
contextName:
method: method
params: Array.prototype.slice.call params
addClient: (clientName, client) ->
[clientName] = client
@
getClient: (clientName) ->
[clientName]
addProjection: (projectionName, projectionClass) ->
[projectionName] = projectionClass
@
initializeProjection: (projectionObject, params) ->
.initializeInstance '', projectionObject, params, @
initializeProjectionInstance: (projectionName, params) ->
if not [projectionName]
err = "Given projection #{projectionName} not registered on remote"
.log.error err
err = new Error err
return err
.initializeInstance projectionName, [projectionName], params, @
getProjectionInstance: (projectionId) ->
.getInstance projectionId
destroyProjectionInstance: (projectionId) ->
.destroyInstance projectionId, @
module.exports = Remote