github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/ui/dashboard/src/utils/snapshot.ts (about)

     1  import {
     2    EXECUTION_SCHEMA_VERSION_20220614,
     3    EXECUTION_SCHEMA_VERSION_20220929,
     4    EXECUTION_SCHEMA_VERSION_20221222,
     5  } from "../constants/versions";
     6  import { PanelDefinition } from "../types";
     7  
     8  const stripObjectProperties = (obj) => {
     9    if (!obj) {
    10      return {};
    11    }
    12    const {
    13      documentation,
    14      search_path,
    15      search_path_prefix,
    16      source_definition,
    17      sql,
    18      ...rest
    19    } = obj;
    20  
    21    return { ...rest };
    22  };
    23  
    24  const stripSnapshotDataForExport = (snapshot) => {
    25    if (!snapshot) {
    26      return {};
    27    }
    28  
    29    switch (snapshot.schema_version) {
    30      case EXECUTION_SCHEMA_VERSION_20220614:
    31      case EXECUTION_SCHEMA_VERSION_20220929:
    32      case EXECUTION_SCHEMA_VERSION_20221222:
    33        const { panels, ...restSnapshot } = stripObjectProperties(snapshot);
    34        const newPanels = {};
    35        for (const [name, panel] of Object.entries(panels)) {
    36          const { properties, ...restPanel } = stripObjectProperties(
    37            panel
    38          ) as PanelDefinition;
    39          const newPanel: PanelDefinition = {
    40            ...restPanel,
    41          };
    42          if (properties) {
    43            newPanel.properties = stripObjectProperties(properties);
    44          }
    45          newPanels[name] = newPanel;
    46        }
    47  
    48        return {
    49          ...restSnapshot,
    50          panels: newPanels,
    51        };
    52      default:
    53        throw new Error(
    54          `Unsupported dashboard event schema ${snapshot.schema_version}`
    55        );
    56    }
    57  };
    58  
    59  export { stripSnapshotDataForExport };