{"version":3,"file":"workflow-CGzYGZnr.mjs","names":["createState"],"sources":["../../document-models/workflow/v1/gen/controller.ts","../../document-models/workflow/v1/gen/ph-factories.ts","../../document-models/workflow/v1/hooks.ts"],"sourcesContent":["/**\n * WARNING: DO NOT EDIT\n * This file is auto-generated and updated by codegen\n */\nimport { PHDocumentController } from \"document-model\";\nimport { Workflow } from \"../module.js\";\nimport type { WorkflowAction, WorkflowPHState } from \"./types.js\";\n\nexport const WorkflowController = PHDocumentController.forDocumentModel<\n  WorkflowPHState,\n  WorkflowAction\n>(Workflow);\n","/**\n * WARNING: DO NOT EDIT\n * This file is auto-generated and updated by codegen\n * Factory methods for creating WorkflowDocument instances\n */\nimport type { PHAuthState, PHBaseState, PHDocumentState } from \"document-model\";\nimport { createBaseState, defaultBaseState } from \"document-model\";\nimport type {\n  WorkflowDocument,\n  WorkflowGlobalState,\n  WorkflowLocalState,\n  WorkflowPHState,\n} from \"./types.js\";\nimport { utils } from \"./utils.js\";\n\nexport function defaultGlobalState(): WorkflowGlobalState {\n  return {\n    name: \"\",\n    description: null,\n    status: \"DRAFT\",\n    version: 0,\n    trigger: null,\n    steps: [],\n    edges: [],\n    variables: [],\n    policy: {\n      concurrency: \"QUEUE\",\n      maxParallelRuns: null,\n      runTimeoutSeconds: 3600,\n      maxSuspensionDays: 30,\n      defaultRetry: {\n        maxAttempts: 1,\n        backoff: \"FIXED\",\n        initialDelaySeconds: 5,\n        maxDelaySeconds: 300,\n        retryOn: [],\n      },\n      onFailure: \"PARK\",\n      retainRunsDays: 30,\n      journalAsDocument: false,\n    },\n    published: null,\n    lastRunAt: null,\n    lastRunStatus: null,\n  };\n}\n\nexport function defaultLocalState(): WorkflowLocalState {\n  return {};\n}\n\nexport function defaultPHState(): WorkflowPHState {\n  return {\n    ...defaultBaseState(),\n    global: defaultGlobalState(),\n    local: defaultLocalState(),\n  };\n}\n\nexport function createGlobalState(\n  state?: Partial<WorkflowGlobalState>,\n): WorkflowGlobalState {\n  return {\n    ...defaultGlobalState(),\n    ...(state || {}),\n  };\n}\n\nexport function createLocalState(\n  state?: Partial<WorkflowLocalState>,\n): WorkflowLocalState {\n  return {\n    ...defaultLocalState(),\n    ...(state || {}),\n  } as WorkflowLocalState;\n}\n\nexport function createState(\n  baseState?: Partial<PHBaseState>,\n  globalState?: Partial<WorkflowGlobalState>,\n  localState?: Partial<WorkflowLocalState>,\n): WorkflowPHState {\n  return {\n    ...createBaseState(baseState?.auth, baseState?.document),\n    global: createGlobalState(globalState),\n    local: createLocalState(localState),\n  };\n}\n\n/**\n * Creates a WorkflowDocument with custom global and local state\n * This properly handles the PHBaseState requirements while allowing\n * document-specific state to be set.\n */\nexport function createWorkflowDocument(\n  state?: Partial<{\n    auth?: Partial<PHAuthState>;\n    document?: Partial<PHDocumentState>;\n    global?: Partial<WorkflowGlobalState>;\n    local?: Partial<WorkflowLocalState>;\n  }>,\n): WorkflowDocument {\n  const document = utils.createDocument(\n    createState(\n      createBaseState(state?.auth, { version: 1, ...state?.document }),\n      state?.global,\n      state?.local,\n    ),\n  );\n\n  return document;\n}\n","/**\n * WARNING: DO NOT EDIT\n * This file is auto-generated and updated by codegen\n */\nimport type { DocumentDispatch } from \"@powerhousedao/reactor-browser\";\nimport {\n  useDocumentById,\n  useDocumentsInSelectedDrive,\n  useDocumentsInSelectedFolder,\n  useSelectedDocument,\n} from \"@powerhousedao/reactor-browser\";\nimport type {\n  WorkflowAction,\n  WorkflowDocument,\n} from \"document-models/workflow/v1\";\nimport {\n  assertIsWorkflowDocument,\n  isWorkflowDocument,\n} from \"./gen/document-schema.js\";\n\n/** Hook to get a Workflow document by its id */\nexport function useWorkflowDocumentById(\n  documentId: string | null | undefined,\n):\n  | [WorkflowDocument, DocumentDispatch<WorkflowAction>]\n  | [undefined, undefined] {\n  const [document, dispatch] = useDocumentById(documentId);\n  if (!isWorkflowDocument(document)) return [undefined, undefined];\n  return [document, dispatch];\n}\n\n/** Hook to get the selected Workflow document */\nexport function useSelectedWorkflowDocument(): [\n  WorkflowDocument,\n  DocumentDispatch<WorkflowAction>,\n] {\n  const [document, dispatch] = useSelectedDocument();\n\n  assertIsWorkflowDocument(document);\n  return [document, dispatch] as const;\n}\n\n/** Hook to get all Workflow documents in the selected drive */\nexport function useWorkflowDocumentsInSelectedDrive() {\n  const documentsInSelectedDrive = useDocumentsInSelectedDrive();\n  return documentsInSelectedDrive?.filter(isWorkflowDocument);\n}\n\n/** Hook to get all Workflow documents in the selected folder */\nexport function useWorkflowDocumentsInSelectedFolder() {\n  const documentsInSelectedFolder = useDocumentsInSelectedFolder();\n  return documentsInSelectedFolder?.filter(isWorkflowDocument);\n}\n"],"mappings":";;;;;;;;AAQA,MAAa,qBAAqB,qBAAqB,iBAGrD,QAAQ;;;ACIV,SAAgB,qBAA0C;CACxD,OAAO;EACL,MAAM;EACN,aAAa;EACb,QAAQ;EACR,SAAS;EACT,SAAS;EACT,OAAO,CAAC;EACR,OAAO,CAAC;EACR,WAAW,CAAC;EACZ,QAAQ;GACN,aAAa;GACb,iBAAiB;GACjB,mBAAmB;GACnB,mBAAmB;GACnB,cAAc;IACZ,aAAa;IACb,SAAS;IACT,qBAAqB;IACrB,iBAAiB;IACjB,SAAS,CAAC;GACZ;GACA,WAAW;GACX,gBAAgB;GAChB,mBAAmB;EACrB;EACA,WAAW;EACX,WAAW;EACX,eAAe;CACjB;AACF;AAEA,SAAgB,oBAAwC;CACtD,OAAO,CAAC;AACV;AAEA,SAAgB,iBAAkC;CAChD,OAAO;EACL,GAAG,iBAAiB;EACpB,QAAQ,mBAAmB;EAC3B,OAAO,kBAAkB;CAC3B;AACF;AAEA,SAAgB,kBACd,OACqB;CACrB,OAAO;EACL,GAAG,mBAAmB;EACtB,GAAI,SAAS,CAAC;CAChB;AACF;AAEA,SAAgB,iBACd,OACoB;CACpB,OAAO;EACL,GAAG,kBAAkB;EACrB,GAAI,SAAS,CAAC;CAChB;AACF;AAEA,SAAgBA,cACd,WACA,aACA,YACiB;CACjB,OAAO;EACL,GA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