@fabric-es/fabric-cqrs
Version:
Hyperledger Fabric middleware for event sourcing and cqrs pattern
44 lines • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRepository = void 0;
const store_1 = require("../store");
const types_1 = require("../types");
const utils_1 = require("../utils");
const createRepository = (entity, callback, option) => {
const entityName = entity.entityName;
const reducer = types_1.getReducer(callback);
const logger = (option === null || option === void 0 ? void 0 : option.logger) || utils_1.getLogger({ name: '[fabric-cqrs] createRepository.js' });
const { queryDatabase, gateway, network, channelName, connectionProfile, wallet } = option;
const store = store_1.getStore({
queryDatabase,
network,
gateway,
reducers: { [entityName]: reducer },
logger,
});
const commandOption = {
logger,
wallet,
store,
connectionProfile,
channelName,
};
const queryOption = { logger, store };
return {
command_deleteByEntityId: utils_1.commandDeleteByEntityId(entityName, false, commandOption),
command_getByEntityName: utils_1.commandGetByEntityName(entityName, false, commandOption),
command_getByEntityIdCommitId: utils_1.commandGetByEntityIdCommitId(entityName, false, commandOption),
create: utils_1.commandCreate(entityName, false, commandOption),
disconnect: () => gateway.disconnect(),
fullTextSearchCommit: async ({ query, param, cursor, pagesize }) => utils_1.queryFullTextSearch({ store, logger, query, param, cursor, pagesize }),
fullTextSearchEntity: async ({ query, param, cursor, pagesize, entityName }) => utils_1.queryFullTextSearch({ store, logger, query, param, cursor, pagesize, entityName }),
getByEntityName: utils_1.queryGetEntityByEntityName(entityName, reducer, queryOption),
getById: utils_1.commandGetById(entityName, reducer, false, commandOption),
getCommitById: utils_1.queryGetCommitByEntityId(entityName, queryOption),
getEntityName: () => entityName,
query_deleteCommitByEntityId: utils_1.queryDeleteCommitByEntityId(entityName, queryOption),
query_deleteCommitByEntityName: utils_1.queryDeleteCommitByEntityName(entityName, queryOption),
};
};
exports.createRepository = createRepository;
//# sourceMappingURL=createRepository.js.map