UNPKG

@fabric-es/fabric-cqrs

Version:

Hyperledger Fabric middleware for event sourcing and cqrs pattern

29 lines 1.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = __importDefault(require("util")); const redux_observable_1 = require("redux-observable"); const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const utils_1 = require("../../../utils"); const projection_1 = require("../../projection"); const action_1 = require("../action"); const { MERGE_ENTITY_BATCH, reconcileSuccess, reconcileError } = action_1.action; exports.default = (action$, _, { logger }) => action$.pipe(redux_observable_1.ofType(MERGE_ENTITY_BATCH), operators_1.map(({ payload }) => payload), operators_1.mergeMap(({ tx_id, args: { entityName, commits }, store }) => rxjs_1.from(utils_1.dispatcher((payload) => projection_1.action.mergeEntityBatch(payload), { SuccessAction: projection_1.action.MERGE_ENTITY_BATCH_SUCCESS, ErrorAction: projection_1.action.MERGE_ENTITY_BATCH_ERROR, logger, name: 'merge_entity_batch', slice: 'projection', store, })({ entityName, commits }) .then(({ status, data, error }) => status === 'OK' ? reconcileSuccess({ tx_id, result: data }) : reconcileError({ tx_id, error })) .catch((error) => { logger.error(util_1.default.format('[store/reconcile/mergeEntityBatch.js] fail to %s: %j', projection_1.action.MERGE_ENTITY_BATCH, error)); return reconcileError({ tx_id, error: error.message }); })))); //# sourceMappingURL=mergeEntityBatch.js.map