Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
break
default:
throw new Error(
`Incorrect process.env.ADAPTER = ${process.env.ADAPTER}`
)
}
const storage = createStorage({
pathToFile: path.join(__dirname, 'event-storage.db')
})
const eventStore = createEventStore({ storage })
const connectorName = 'default-adapter'
const readModelName = 'default-read-model'
const query = createQuery({
eventStore,
viewModels: [],
readModelConnectors: {
[connectorName]: adapter
},
readModels: [
{
name: readModelName,
connectorName,
projection,
resolvers
}
]
})
await query.read({
import createQueryExecutor from 'resolve-query'
import eventStore from './event_store'
import snapshotAdapter from './snapshot_adapter'
import { viewModels, readModels } from './assemblies'
const queryExecutor = createQueryExecutor({
eventStore,
viewModels,
readModels,
snapshotAdapter
})
export default queryExecutor
import createEventStore from 'resolve-es';
import storageAdapter from 'resolve-storage-lite';
import busAdapter from 'resolve-bus-zmq';
import query from 'resolve-query';
import { readModel } from 'todo-common';
import config from '../config';
const storage = storageAdapter(config.esFile);
const bus = busAdapter(config.zmq);
const eventStore = createEventStore({ storage, bus });
const queries = query({
eventStore,
readModel
});
process.on('message', (message) => {
queries('query { View }')
.then(state =>
process.send({
id: message.id,
state
})
)
.catch(err =>
process.send({
id: message.id,
state: null
return await executeScheduleCommand(...args)
} else {
return await executeCommand(...args)
}
}
const sagaProvider = Object.create(Object.prototype, {
executeCommand: { get: () => executeCommandOrScheduler, enumerable: true },
executeQuery: { get: () => executeQuery, enumerable: true },
eventProperties: { get: () => eventProperties, enumerable: true }
})
const regularSagas = wrapRegularSagas(sagas, sagaProvider)
const schedulerSagas = createSchedulerSagas(schedulers, sagaProvider)
const executeListener = createQuery({
eventStore,
readModelConnectors,
snapshotAdapter,
readModels: [...regularSagas, ...schedulerSagas],
viewModels: [],
performanceTracer
})
const updateByEvents = async (
sagaName,
events,
remainingTime,
properties
) => {
eventProperties = properties
const result = await executeListener.updateByEvents(
viewModels
} = resolve
const snapshotAdapter = createSnapshotAdapter()
const readModelAdapters = {}
for (const { name, factory } of readModelAdaptersCreators) {
readModelAdapters[name] = factory()
}
const executeCommand = createCommandExecutor({
eventStore,
aggregates,
snapshotAdapter
})
const executeQuery = createQueryExecutor({
eventStore,
viewModels,
customReadModels,
readModels,
readModelAdapters,
snapshotAdapter
})
Object.assign(resolve, {
executeCommand,
executeQuery
})
Object.defineProperties(resolve, {
readModelAdapters: { value: readModelAdapters },
snapshotAdapter: { value: snapshotAdapter }
function generateSyncExecutor(storage, bus, readModels) {
const loadDonePromise = new Promise((resolve) => {
const originalLoadEventsByTypes = storage.loadEventsByTypes.bind(storage);
storage.loadEventsByTypes = (...args) =>
originalLoadEventsByTypes(...args).then((result) => {
resolve();
return result;
});
});
const eventStore = createEventStore({
storage,
bus
});
const execute = createExecutor({ eventStore, readModels });
return async (...args) => {
await loadDonePromise;
return execute(...args);
};
}
const readModelConnectors = {}
for (const name of Object.keys(readModelConnectorsCreators)) {
readModelConnectors[name] = readModelConnectorsCreators[name]({
performanceTracer
})
}
const executeCommand = createCommandExecutor({
eventStore,
aggregates,
snapshotAdapter,
performanceTracer
})
const executeQuery = createQueryExecutor({
eventStore,
readModelConnectors,
snapshotAdapter,
readModels,
viewModels,
performanceTracer
})
const executeSaga = createSagaExecutor({
executeCommand,
executeQuery,
eventStore,
readModelConnectors,
snapshotAdapter,
schedulers,
sagas,
const app = express();
app.use(express.static('static'));
const eventStore = createStore({
driver: esDriver({ pathToFile: './event_store.json' })
});
const bus = createBus({ driver: busDriver() });
const execute = commandHandler({
store: eventStore,
bus,
aggregates: [todoCardAggregate, todoItemAggregate]
});
const queries = query({
store: eventStore,
bus,
projections: [cardsProjection, cardDetailsProjection]
});
setupMiddlewares(app);
app.get('/', (req, res) =>
queries('cards').then(inventoryItems =>
res.render('index', {
items: Object.values(inventoryItems)
})
)
);
app.get('/:card', (req, res) =>
aggregates,
snapshotAdapter
})
const doUpdateRequest = async (pool, readModelName) => {
const executor = pool.getExecutor(pool, readModelName)
Promise.resolve()
.then(executor.read.bind(null, { isBulkRead: true }))
.then(invokeLambdaSelf.bind(null, { Records: [] }))
.catch(error => {
resolveLog('error', 'Update lambda invocation error', error)
})
}
const executeQuery = createQueryExecutor({
eventStore,
viewModels,
readModels,
readModelAdapters,
snapshotAdapter,
doUpdateRequest
})
Object.assign(resolve, {
executeCommand,
executeQuery,
eventStore
})
Object.defineProperties(resolve, {
readModelAdapters: { value: readModelAdapters },
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'
})