/* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ import { Reference } from '@kbn/content-management-utils'; import { MaybePromise } from '@kbn/utility-types'; /** * A package containing the serialized Embeddable state, with references extracted. When saving Embeddables using any * strategy, this is the format that should be used. */ export interface SerializedPanelState { references?: Reference[]; rawState: RawStateType; } export interface HasSerializableState { /** * Serializes all state into a format that can be saved into * some external store. The opposite of `deserialize` in the {@link ReactEmbeddableFactory} */ serializeState: () => MaybePromise>; } export const apiHasSerializableState = (api: unknown | null): api is HasSerializableState => { return Boolean((api as HasSerializableState)?.serializeState); }; export interface HasSnapshottableState { /** * Serializes all runtime state exactly as it appears. This can be used * to rehydrate a component's state without needing to serialize then deserialize it. */ snapshotRuntimeState: () => RuntimeState; } export const apiHasSnapshottableState = (api: unknown | null): api is HasSnapshottableState => { return Boolean((api as HasSnapshottableState)?.snapshotRuntimeState); };