UNPKG

@fabric-es/fabric-cqrs

Version:

Hyperledger Fabric middleware for event sourcing and cqrs pattern

93 lines (92 loc) 3.07 kB
import { Gateway, Network, Wallet } from 'fabric-network'; import type { FTSearchParameters } from 'redis-modules-sdk'; import type { Logger } from 'winston'; import type { QueryDatabase } from '../queryHandler/types'; import type { Commit, FabricResponse, HandlerResponse, Paginated } from '.'; export declare type RepoOption = { channelName: string; connectionProfile: string; logger?: Logger; gateway: Gateway; queryDatabase: QueryDatabase; network: Network; wallet: Wallet; }; export declare type PrivateRepoOption = { channelName: string; connectionProfile: string; gateway: Gateway; logger?: Logger; network: Network; wallet: Wallet; }; export declare type SaveFcn<TEvent> = (payload: { events: TEvent[]; signedRequest?: string; }) => Promise<HandlerResponse<Commit>>; export declare type RepoFcn<TResponse> = () => Promise<HandlerResponse<TResponse>>; export declare type RepoFcn_Id<TResponse> = (payload: { id: string; }) => Promise<HandlerResponse<TResponse>>; export declare type RepoFcn_IdCommitId<TResponse> = (payload: { id: string; commitId: string; }) => Promise<HandlerResponse<TResponse>>; export declare type Repository<TEntity = any, TOutputEntity = any, TEvent = any> = { command_deleteByEntityId: RepoFcn_Id<FabricResponse>; command_getByEntityName: RepoFcn<Commit[]>; command_getByEntityIdCommitId?: RepoFcn_IdCommitId<Commit[]>; create: (option: { enrollmentId: string; id: string; }) => { save: SaveFcn<TEvent>; }; disconnect: () => void; fullTextSearchCommit: (option: { query: string; cursor: number; pagesize: number; param?: FTSearchParameters; }) => Promise<HandlerResponse<Paginated<Commit>>>; fullTextSearchEntity: (option: { entityName: string; query: string; cursor: number; pagesize: number; param?: FTSearchParameters; }) => Promise<HandlerResponse<Paginated<TOutputEntity>>>; getByEntityName: () => Promise<HandlerResponse<TEntity[]>>; getById: (option: { enrollmentId: string; id: string; }) => Promise<{ currentState: TEntity; save: SaveFcn<TEvent>; }>; getEntityName: () => string; getCommitById: RepoFcn_Id<Commit[]>; query_deleteCommitByEntityId: RepoFcn_Id<number>; query_deleteCommitByEntityName: RepoFcn<number>; }; export declare type PrivateRepository<TEntity = any, TEvent = any> = { create: (option: { enrollmentId: string; id: string; }) => { save: SaveFcn<TEvent>; }; deleteByEntityIdCommitId: RepoFcn_IdCommitId<FabricResponse>; disconnect: () => void; getById: (option: { enrollmentId: string; id: string; }) => Promise<{ currentState: TEntity; save: SaveFcn<TEvent>; }>; getCommitByEntityName: RepoFcn<Commit[]>; getCommitByEntityIdCommitId: RepoFcn_IdCommitId<Commit[]>; getCommitById: RepoFcn_Id<Commit[]>; getEntityName: () => string; };