import CID from 'cids' ; import { StreamID } from './stream-id' ; import { CommitID } from './commit-id' ; import * as uint8arrays from 'uint8arrays' ; /**
 * Ensure there is some resemblance in CommitID and StreamID APIs.
 */ export interface StreamRef { readonly type : number ; readonly typeName : string ; readonly cid : CID ; readonly bytes : Uint8Array ; readonly baseID : StreamID ; atCommit ( commit ) : CommitID ; equals ( other ) : boolean ; toString ( ) : string ; toUrl ( ) : string ; } /**
 * Return result of `f` or null if it fails.
 */ function tryCatch < A > ( f ) { try { return f ( ) ; } catch { return null ; } } export namespace StreamRef { /**
     * Try to parse `input` into CommitID or StreamID.
     */ export function from ( input ) { if ( StreamID . isInstance ( input ) ) { return input ; } else if ( CommitID . isInstance ( input ) ) { return input ; } else if ( input instanceof Uint8Array ) { const commitId = CommitID . fromBytesNoThrow ( input ) ; if ( commitId instanceof Error ) { return StreamID . fromBytes ( input ) ; } return commitId ; } else if ( typeof input === 'string' ) { const commitId = CommitID . fromStringNoThrow ( input ) ; if ( commitId instanceof Error ) { return StreamID . fromString ( input ) ; } return commitId ; } else { throw new Error ( `Can not build CommitID or StreamID` ) ; } } }