Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import mongoDbDriver from 'resolve-es-mongo';
import createEs from 'resolve-es';
import { INFO_TOKEN, DONE_TOKEN, ERR_TOKEN } from './constants';
import config from './config';
const TYPES = config.GENERATED_EVENT_TYPES;
const store = createEs({
driver: mongoDbDriver({
url: config.MONGODB_CONNECTION_URL,
collection: config.MONGODB_COLLECTION_NAME
})
});
let eventCounter = 0;
let lastReportedEvents = 0;
function reporterHandler() {
if (lastReportedEvents !== eventCounter) {
const tickSize = eventCounter - lastReportedEvents;
// eslint-disable-next-line no-console
console.log(INFO_TOKEN, tickSize);
lastReportedEvents = eventCounter;
}
this.storage = createEsStorage({ databaseFile: ":memory:" });
} else {
this.storage = this.schema.storage;
}
if (this.schema.aggregateName) {
this.aggregateName = this.schema.aggregateName;
} else {
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
);
case 'mongo':
adapter = createMongoDBAdapter({
url: process.env.MONGO_URL
})
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
}
import createEventStore from 'resolve-es'
import config from '../configs/server.config.js'
const storage = config.storage.adapter(config.storage.params)
const busAdapter = config.bus.adapter
const bus = busAdapter(config.bus.params)
const eventStore = createEventStore({ storage, bus })
const subscribe = async (eventDescriptors, callback) => {
if (Array.isArray(eventDescriptors.types) && eventDescriptors.ids === '*') {
return await eventStore.subscribeByEventType(
eventDescriptors.types,
callback,
{
onlyBus: true
}
)
} else if (
Array.isArray(eventDescriptors.types) &&
Array.isArray(eventDescriptors.ids)
) {
return await eventStore.subscribeByAggregateId(
eventDescriptors.ids,
import createEventStore from 'resolve-es'
import { storageAdapter, busAdapter } from './assemblies'
const createStorageAdapter = storageAdapter.module
const storageAdapterOptions = storageAdapter.options
const createBusAdapter = busAdapter.module
const busAdapterOptions = busAdapter.options
const storage = createStorageAdapter(storageAdapterOptions)
const bus = createBusAdapter(busAdapterOptions)
const eventStore = createEventStore({ storage, bus })
export default eventStore
const initEventStore = async (
{ storageAdapter: createStorageAdapter, busAdapter: createBusAdapter },
resolve
) => {
Object.assign(resolve, {
eventStore: createEventStore({
storage: createStorageAdapter(),
bus: createBusAdapter()
})
})
}
import todoCardAggregate from './aggregates/TodoCard';
import todoItemAggregate from './aggregates/TodoItem';
import cardsProjection from './projections/cards';
import cardDetailsProjection from './projections/cardDetails';
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]
});
import createEventStore from 'resolve-es'
import { storageAdapter, busAdapter } from './assemblies'
const createStorageAdapter = storageAdapter.module
const storageAdapterOptions = storageAdapter.options
const createBusAdapter = busAdapter.module
const busAdapterOptions = busAdapter.options
const storage = createStorageAdapter(storageAdapterOptions)
const bus = createBusAdapter(busAdapterOptions)
const eventStore = createEventStore({ storage, bus })
export default eventStore
const initResolve = async (
{
snapshotAdapter: createSnapshotAdapter,
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)
import createEventStore from 'resolve-es';
import storageAdapter from 'resolve-storage-lite';
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({