Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!viewModel.serializeState || !viewModel.deserializeState) {
raiseError(message.viewModelSerializable, viewModel)
}
let snapshotAdapter, snapshotBucketSize
if (viewModel.snapshotAdapter) {
const createSnapshotAdapter = viewModel.snapshotAdapter.module
const snapshotAdapterOptions = viewModel.snapshotAdapter.options
snapshotAdapter = createSnapshotAdapter(snapshotAdapterOptions)
snapshotBucketSize = snapshotAdapterOptions.bucketSize
}
const facade = createViewModel({
projection: viewModel.projection,
snapshotAdapter,
snapshotBucketSize,
eventStore
})
viewModelQueryExecutors[viewModel.name] = {
read: facade.read,
serializeState: viewModel.serializeState
}
})
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'
})
}
if (!viewModel.serializeState || !viewModel.deserializeState) {
raiseError(message.viewModelSerializable, viewModel)
}
let snapshotAdapter, snapshotBucketSize
if (viewModel.snapshotAdapter) {
const createSnapshotAdapter = viewModel.snapshotAdapter.module
const snapshotAdapterOptions = viewModel.snapshotAdapter.options
snapshotAdapter = createSnapshotAdapter(snapshotAdapterOptions)
snapshotBucketSize = snapshotAdapterOptions.bucketSize
}
const facade = createViewModel({
projection: viewModel.projection,
invariantHash: viewModel.invariantHash,
snapshotAdapter,
snapshotBucketSize,
eventStore
})
viewModelQueryExecutors[viewModel.name] = {
read: facade.read,
serializeState: viewModel.serializeState
}
})