How to use resolve-command - 10 common examples

To help you get started, we’ve selected a few resolve-command examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davidnussio / moleculer-cqrs / src / cqrs-event-sourcing.js View on Github external
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]
        );
      }
    },
github reimagined / resolve / packages / resolve-scripts / src / server / express.js View on Github external
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]
github reimagined / resolve / packages / core / resolve-runtime / src / cloud_entry.js View on Github external
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)
      })
  }
github reimagined / resolve / examples / todo / server / command / index.js View on Github external
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
github reimagined / resolve / packages / core / resolve-scripts / src / runtime / command_executor.js View on Github external
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
github reimagined / resolve / examples / todolist / index.js View on Github external
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', {
github reimagined / resolve / packages / core / resolve-runtime / src / common / init-resolve.js View on Github external
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({
github reimagined / resolve / packages / core / resolve-saga / src / index.js View on Github external
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 },
github reimagined / resolve / packages / resolve-scripts / src / runtime / server / command_executor.js View on Github external
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
github reimagined / resolve / benchmarks / event-circuit-speed / preparer.js View on Github external
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)
    );
}

resolve-command

Creates a function that handles commands in a reSolve application.

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis

Popular resolve-command functions