use crate::{
DefinitionError, DefinitionTokenKind, ParameterValueKind, definition_token, validate_token,
};
pub const MAX_SCOPED_COMPONENTS: usize = 256;
pub const MAX_LATE_BOUND_INPUTS: usize = 64;
pub const MAX_SELECTOR_PATH_BYTES: usize = 1_024;
pub const MAX_SELECTOR_PATH_SEGMENTS: usize = 32;
#[must_use]
pub fn selector_path_is_valid(segments: &[String]) -> bool {
if segments.is_empty() || segments.len() > MAX_SELECTOR_PATH_SEGMENTS {
return false;
}
let bytes = segments
.iter()
.map(String::len)
.sum::<usize>()
.saturating_add(segments.len().saturating_sub(1));
bytes <= MAX_SELECTOR_PATH_BYTES
&& segments.iter().all(|segment| {
!segment.is_empty()
&& segment.trim() == segment
&& !segment.chars().any(char::is_control)
})
}
definition_token!(
ScopedComponentId,
DefinitionTokenKind::Component,
"Stable logical identity of one job- or step-scoped component."
);
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum ScopeKind {
Job,
Step,
}
impl ScopeKind {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Job => "job",
Self::Step => "step",
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum ScopeFrameworkSource {
JobInstanceId,
JobExecutionId,
StepExecutionId,
Attempt,
DefinitionRevision,
DefinitionFingerprint,
LogicalNodeId,
StepName,
}
impl ScopeFrameworkSource {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::JobInstanceId => "job_instance_id",
Self::JobExecutionId => "job_execution_id",
Self::StepExecutionId => "step_execution_id",
Self::Attempt => "attempt",
Self::DefinitionRevision => "definition_revision",
Self::DefinitionFingerprint => "definition_fingerprint",
Self::LogicalNodeId => "logical_node_id",
Self::StepName => "step_name",
}
}
#[must_use]
pub const fn value_kind(self) -> ParameterValueKind {
match self {
Self::JobInstanceId | Self::JobExecutionId | Self::StepExecutionId | Self::Attempt => {
ParameterValueKind::U64
}
Self::DefinitionRevision
| Self::DefinitionFingerprint
| Self::LogicalNodeId
| Self::StepName => ParameterValueKind::String,
}
}
}