Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.1 KB
Raw Blame
import {
  GetFlowQueryParamsRequest,
  isNil,
  PopulatedFlow,
  tryCatch,
} from '@activepieces/shared';

export type RunDiscardDeps = {
  flow: { id: string; publishedVersionId?: string | null };
  savePendingEdits: () => Promise<void>;
  overWriteDraftWithVersion: (params: {
    flowId: string;
    versionId: string;
  }) => Promise<unknown>;
  fetchFlow: (
    flowId: string,
    request: GetFlowQueryParamsRequest,
  ) => Promise<PopulatedFlow>;
  setFlow: (flow: PopulatedFlow) => void;
  setVersion: (version: PopulatedFlow['version']) => void;
};

export async function runDiscard(deps: RunDiscardDeps): Promise<void> {
  const { flow } = deps;
  if (!flow.publishedVersionId) {
    return;
  }
  const { error: saveError } = await tryCatch(deps.savePendingEdits);
  if (!isNil(saveError)) {
    return;
  }
  await deps.overWriteDraftWithVersion({
    flowId: flow.id,
    versionId: flow.publishedVersionId,
  });
  const published = await deps.fetchFlow(flow.id, {
    versionId: flow.publishedVersionId,
  });
  deps.setFlow(published);
  deps.setVersion(published.version);
}