Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
config.readModels.forEach(readModel => {
if (!readModel.name && config.readModels.length === 1) {
readModel.name = 'default'
} else if (!readModel.name) {
raiseError(message.readModelMandatoryName, readModel)
} else if (queryExecutors[readModel.name]) {
raiseError(message.dublicateName, readModel)
}
const facade = createFacade({
model: createReadModel({
projection: readModel.projection,
adapter: readModel.adapter,
eventStore
}),
resolvers: readModel.resolvers
})
queryExecutors[readModel.name] = facade.executeQuery
queryExecutors[readModel.name].makeSubscriber = facade.makeReactiveReader
queryExecutors[readModel.name].mode = 'read'
})
config.viewModels.forEach(viewModel => {
if (!viewModel.name && config.viewModels.length === 1) {
viewModel.name = 'reduxinitial'
} else if (!viewModel.name) {
raiseError(message.viewModelMandatoryName, viewModel)
} else if (queryExecutors[viewModel.name]) {
raiseError(message.dublicateName, viewModel)
}
if (!viewModel.serializeState || !viewModel.deserializeState) {
raiseError(message.viewModelSerializable, viewModel)
}
const facade = createFacade({
model: createViewModel({
projection: viewModel.projection,
eventStore
}),
resolvers: {
view: async (model, { jwtToken }) =>
await viewModel.serializeState(model, jwtToken)
}
})
queryExecutors[viewModel.name] = facade.executeQuery
queryExecutors[viewModel.name].mode = 'view'
})