import { Query } from './query/query' ; import { findIndex } from './util/fn' ; export type FactReference = { type : string ; hash : string ; } ; export type FactPath = FactReference [ ] ; export type PredecessorCollection = { [ role ] : FactReference [ ] | FactReference ; } ; export type FactRecord = { type : string ; hash : string ; predecessors : PredecessorCollection ; fields : { } ; } ; export type FactSignature = { publicKey : string ; signature : string ; } ; export type FactEnvelope = { fact : FactRecord ; signatures : FactSignature [ ] ; } ; export interface Storage { save ( envelopes ) : Promise < FactEnvelope [ ] > ; query ( start , query ) : Promise < FactPath [ ] > ; exists ( fact ) : Promise < boolean > ; load ( references ) : Promise < FactRecord [ ] > ; } export interface Queue { peek ( ) : Promise < FactEnvelope [ ] > ; enqueue ( envelopes ) : Promise < void > ; dequeue ( envelopes ) : Promise < void > ; } export function factReferenceEquals ( a ) { return ( r ) => r . hash === a . hash && r . type === a . type ; } export function uniqueFactReferences ( references ) { return references . filter ( ( value , index , array ) => { return findIndex ( array , factReferenceEquals ( value ) ) === index ; } ) ; }