import { SavedObjectsErrorHelpers } from '../service/lib/errors' ; import { decodeBase64 } from './base64' ; /**
 * Decode the "opaque" version string to the sequence params we
 * can use to activate optimistic concurrency in Elasticsearch
 */ export function decodeVersion ( version ? ) { try { if ( typeof version !== 'string' ) { throw new TypeError ( ) ; } const seqParams = JSON . parse ( decodeBase64 ( version ) ) as [ number , number ] ; if ( ! Array . isArray ( seqParams ) || seqParams . length !== 2 || ! Number . isInteger ( seqParams [ 0 ] ) || ! Number . isInteger ( seqParams [ 1 ] ) ) { throw new TypeError ( ) ; } return { _seq_no : seqParams [ 0 ] , _primary_term : seqParams [ 1 ] , } ; } catch ( _ ) { throw SavedObjectsErrorHelpers . createInvalidVersionError ( version ) ; } }