{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/services/document-workflows/helpers/index.ts"],"sourcesContent":["import type CollectionBuilder from \"../../../libs/collection/builders/collection-builder/index.js\";\nimport type {\n\tPublishingWorkflowConfig,\n\tPublishingWorkflowStageConfig,\n} from \"../../../libs/collection/builders/collection-builder/types.js\";\n\n/**\n * Reads the configured workflow from a collection, if document workflows are enabled.\n */\nexport const getWorkflowConfig = (\n\tcollection: CollectionBuilder,\n): PublishingWorkflowConfig | undefined => collection.getData.workflow;\n\n/**\n * Finds a configured workflow stage by key without applying initial-stage fallback.\n */\nexport const getWorkflowStage = (props: {\n\tcollection: CollectionBuilder;\n\tstageKey: string;\n}): PublishingWorkflowStageConfig | undefined =>\n\tgetWorkflowConfig(props.collection)?.stages.find(\n\t\t(stage) => stage.key === props.stageKey,\n\t);\n\n/**\n * Resolves the persisted stage key, falling back to the workflow initial stage.\n */\nexport const resolveEffectiveWorkflowStage = (props: {\n\tcollection: CollectionBuilder;\n\tstageKey?: string | null;\n}): PublishingWorkflowStageConfig | undefined => {\n\tconst workflow = getWorkflowConfig(props.collection);\n\tif (!workflow) return undefined;\n\n\tconst storedStage = props.stageKey\n\t\t? workflow.stages.find((stage) => stage.key === props.stageKey)\n\t\t: undefined;\n\n\treturn (\n\t\tstoredStage ??\n\t\tworkflow.stages.find((stage) => stage.key === workflow.initial)\n\t);\n};\n\n/**\n * Checks whether the effective workflow stage allows publishing to a target.\n */\nexport const workflowStageAllowsTarget = (props: {\n\tcollection: CollectionBuilder;\n\tstageKey?: string | null;\n\ttarget: string;\n}): boolean => {\n\tconst stage = resolveEffectiveWorkflowStage({\n\t\tcollection: props.collection,\n\t\tstageKey: props.stageKey,\n\t});\n\tif (!stage) return true;\n\n\treturn stage.publishTargets.includes(props.target);\n};\n"],"mappings":"AASA,MAAa,EACZ,GAC0C,EAAW,QAAQ,SAgBjD,EAAiC,GAGG,CAChD,IAAM,EAAW,EAAkB,EAAM,UAAU,EAC9C,KAML,OAJoB,EAAM,SACvB,EAAS,OAAO,KAAM,GAAU,EAAM,MAAQ,EAAM,QAAQ,EAC5D,IAAA,KAIF,EAAS,OAAO,KAAM,GAAU,EAAM,MAAQ,EAAS,OAAO,CAEhE,EAKa,EAA6B,GAI3B,CACd,IAAM,EAAQ,EAA8B,CAC3C,WAAY,EAAM,WAClB,SAAU,EAAM,QACjB,CAAC,EAGD,MAFA,CAAK,GAEE,EAAM,eAAe,SAAS,EAAM,MAAM,CAClD"}