/** * Copyright 2022 Gravwell, Inc. All rights reserved. * * Contact: [legal@gravwell.io](mailto:legal@gravwell.io) * * This software may be modified and distributed under the terms of the MIT * license. See the LICENSE file for details. */ import { isInteger, isUndefined } from 'lodash'; import { isNumericID } from '~/value-objects/id'; import { PersistentSearchDataState } from './persistent-search-data'; import { Search2 } from './search2'; export const isPersistentSearchData = (value: unknown): value is Search2 => { try { const s = value as Search2; return ( isNumericID(s.userID) && (isUndefined(s.groupID) || isNumericID(s.groupID)) && s.states.every(isPersistentSearchState) && isInteger(s.attachedClients) && isInteger(s.storedData) ); } catch { return false; } }; const isPersistentSearchState = (value: any): value is PersistentSearchDataState => (['active', 'dormant', 'backgrounded', 'saved', 'saving', 'attached'] as Array).includes( value, );