Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.aggregateName = this.name;
}
const publishEvent = ctx => event => {
ctx.broker.broadcast(event.type, event);
};
this.eventStore = createEventStore({
storage: this.storage,
publishEvent: publishEvent(this),
});
if (this.settings.aggregate) {
this.aggregate = this.settings.aggregate;
delete this.settings.aggregate;
this.commandHandler = commandHandler({
eventStore: this.eventStore,
aggregates: [this.aggregate],
// snapshotAdapter
});
this.metadata.aggregate = true;
this.metadata.commands = Object.keys(this.aggregate.commands).map(
name => name
);
this.metadata.projection = Object.keys(this.aggregate.projection).map(
name => name
);
this.metadata.events = Object.keys(this.aggregate.events).map(
name => this.aggregate.events[name]
);
}
},
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'
})
const executeCommand = commandHandler({
eventStore,
aggregates: config.aggregates
})
config.sagas.forEach(saga =>
saga({
subscribeByEventType: eventStore.subscribeByEventType,
subscribeByAggregateId: eventStore.subscribeByAggregateId,
queryExecutors,
executeCommand
})
)
app.use((req, res, next) => {
req.jwtToken =
req.cookies && req.cookies[config.jwtCookie.name]
storageAdapter: createStorageAdapter,
readModelAdapters: readModelAdaptersCreators
},
resolve
) => {
const storageAdapter = createStorageAdapter()
const eventStore = createEventStore({ storage: storageAdapter })
const { aggregates, readModels, viewModels } = resolve
const snapshotAdapter = createSnapshotAdapter()
const readModelAdapters = {}
for (const { name, factory } of readModelAdaptersCreators) {
readModelAdapters[name] = factory()
}
const executeCommand = createCommandExecutor({
eventStore,
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)
})
}
import busAdapter from 'resolve-bus-zmq';
import commandHandler from 'resolve-command';
import { aggregates } from 'todo-common';
import config from '../config';
const todoCardAggregate = aggregates.TodoCard;
const todoItemAggregate = aggregates.TodoItem;
const storage = storageAdapter(config.esFile);
const bus = busAdapter(config.zmq);
const eventStore = createEventStore({ storage, bus });
const execute = commandHandler({
eventStore,
aggregates: [todoCardAggregate, todoItemAggregate]
});
process.on('message', (message) => {
execute(message.payload)
.then(() =>
process.send({
id: message.id,
state: null
})
)
.catch(err =>
process.send({
id: message.id,
state: err
import createCommandExecutor from 'resolve-command'
import eventStore from './event_store'
import snapshotAdapter from './snapshot_adapter'
import { aggregates } from './assemblies'
const commandExecutor = createCommandExecutor({
eventStore,
aggregates,
snapshotAdapter
})
export default commandExecutor
const setupMiddlewares = (app) => {
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.set('views', './views');
app.set('view engine', 'pug');
};
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', {
const eventStore = createEventStore({
storage: storageAdapter,
publishEvent: resolve.publishEvent
})
const { aggregates, readModels, schedulers, sagas, viewModels } = resolve
const snapshotAdapter = createSnapshotAdapter()
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({
const createSaga = ({
eventStore,
readModelConnectors,
snapshotAdapter,
sagas,
schedulers,
executeCommand,
executeQuery,
performanceTracer
}) => {
const schedulerAggregatesNames = new Set(schedulers.map(({ name }) => name))
let eventProperties = {}
const executeScheduleCommand = createCommand({
aggregates: createSchedulersAggregates(schedulers),
eventStore,
snapshotAdapter
})
const executeCommandOrScheduler = async (...args) => {
const aggregateName = args[0].aggregateName
if (schedulerAggregatesNames.has(aggregateName)) {
return await executeScheduleCommand(...args)
} else {
return await executeCommand(...args)
}
}
const sagaProvider = Object.create(Object.prototype, {
executeCommand: { get: () => executeCommandOrScheduler, enumerable: true },
import createCommandExecutor from 'resolve-command'
import eventStore from './event_store'
import aggregates from '$resolve.aggregates'
const commandExecutor = createCommandExecutor({
eventStore,
aggregates: aggregates.map(({ snapshotAdapter, ...aggregate }) => {
if (!snapshotAdapter) {
return aggregate
}
return {
...aggregate,
snapshotAdapter: snapshotAdapter.module(snapshotAdapter.options),
snapshotBucketSize: snapshotAdapter.options.bucketSize
}
})
})
export default commandExecutor
export default function preparer(eventsCount, reportObj) {
const storage = mongoDbAdapter({
url: config.MONGODB_CONNECTION_URL,
collection: config.MONGODB_COLLECTION_NAME
});
const bus = memoryAdapter();
const eventStore = createEventStore({
storage,
bus
});
const commandExecute = createCommandExecutor({ eventStore, aggregates });
return dropCollection(config.MONGODB_CONNECTION_URL, config.MONGODB_COLLECTION_NAME).then(() =>
commandGenerator(commandExecute, eventsWeight, eventsCount / entitiesFactor, reportObj)
);
}