eventric
Version:
behavior-first application development
87 lines (53 loc) • 2.21 kB
text/coffeescript
remoteInmemory = require 'eventric-remote-inmemory'
logger = require 'eventric/logger'
Projection = require 'eventric/projection'
class Remote
: [
'command'
'query'
'findDomainEventsByName'
'findDomainEventsByNameAndAggregateId'
]
constructor: () ->
=
= {}
= {}
= {}
= {}
= new Projection @
remoteInmemory.client
()
_exposeRpcOperationsAsMemberFunctions: ->
Remote.ALLOWED_RPC_OPERATIONS.forEach (rpcOperation) =>
@[rpcOperation] = =>
rpcOperation, arguments
subscribeToAllDomainEvents: (handlerFn) ->
.subscribe , handlerFn
subscribeToDomainEvent: (domainEventName, handlerFn) ->
.subscribe , domainEventName, handlerFn
subscribeToDomainEventWithAggregateId: (domainEventName, aggregateId, handlerFn) ->
.subscribe , domainEventName, aggregateId, handlerFn
unsubscribeFromDomainEvent: (subscriberId) ->
.unsubscribe subscriberId
_rpc: (functionName, args) ->
.rpc
contextName:
functionName: functionName
args: Array.prototype.slice.call args
setClient: (client) ->
= client
@
addProjection: (projectionName, projectionClass) ->
[projectionName] = projectionClass
@
initializeProjection: (projectionObject, params) ->
.initializeInstance '', projectionObject, params
initializeProjectionInstance: (projectionName, params) ->
if not [projectionName]
return Promise.reject new Error "Given projection #{projectionName} not registered on remote"
.initializeInstance projectionName, [projectionName], params
getProjectionInstance: (projectionId) ->
.getInstance projectionId
destroyProjectionInstance: (projectionId) ->
.destroyInstance projectionId, @
module.exports = Remote