How to use resolve-query - 10 common examples

To help you get started, we’ve selected a few resolve-query 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 reimagined / resolve / tests / read-models-transactional / worker.js View on Github external
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({
github reimagined / resolve / packages / core / resolve-scripts / src / runtime / query_executor.js View on Github external
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
github reimagined / resolve / examples / todo / server / query / index.js View on Github external
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
github reimagined / resolve / packages / core / resolve-saga / src / index.js View on Github external
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(
github reimagined / resolve / packages / core / resolve-runtime / src / local_entry.js View on Github external
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 }
github reimagined / resolve / benchmarks / event-circuit-speed / worker.js View on Github external
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);
    };
}
github reimagined / resolve / packages / core / resolve-runtime / src / common / init-resolve.js View on Github external
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,
github reimagined / resolve / examples / todolist / index.js View on Github external
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) =>
github reimagined / resolve / packages / core / resolve-runtime / src / cloud_entry.js View on Github external
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 },
github reimagined / resolve / packages / resolve-scripts / src / server / express.js View on Github external
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'
})

resolve-query

Provides an interface used to create and querry read models and view models in a reSolve application.

MIT
Latest version published 4 years ago

Package Health Score

48 / 100
Full package analysis