oxide_batch_core/
scope.rs1use crate::{
8 DefinitionError, DefinitionTokenKind, ParameterValueKind, definition_token, validate_token,
9};
10
11pub const MAX_SCOPED_COMPONENTS: usize = 256;
13pub const MAX_LATE_BOUND_INPUTS: usize = 64;
15pub const MAX_SELECTOR_PATH_BYTES: usize = 1_024;
17pub const MAX_SELECTOR_PATH_SEGMENTS: usize = 32;
19
20#[must_use]
25pub fn selector_path_is_valid(segments: &[String]) -> bool {
26 if segments.is_empty() || segments.len() > MAX_SELECTOR_PATH_SEGMENTS {
27 return false;
28 }
29 let bytes = segments
30 .iter()
31 .map(String::len)
32 .sum::<usize>()
33 .saturating_add(segments.len().saturating_sub(1));
34 bytes <= MAX_SELECTOR_PATH_BYTES
35 && segments.iter().all(|segment| {
36 !segment.is_empty()
37 && segment.trim() == segment
38 && !segment.chars().any(char::is_control)
39 })
40}
41
42definition_token!(
43 ScopedComponentId,
44 DefinitionTokenKind::Component,
45 "Stable logical identity of one job- or step-scoped component."
46);
47
48#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
50#[non_exhaustive]
51pub enum ScopeKind {
52 Job,
54 Step,
56}
57
58impl ScopeKind {
59 #[must_use]
61 pub const fn as_str(self) -> &'static str {
62 match self {
63 Self::Job => "job",
64 Self::Step => "step",
65 }
66 }
67}
68
69#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
71#[non_exhaustive]
72pub enum ScopeFrameworkSource {
73 JobInstanceId,
75 JobExecutionId,
77 StepExecutionId,
79 Attempt,
81 DefinitionRevision,
83 DefinitionFingerprint,
85 LogicalNodeId,
87 StepName,
89}
90
91impl ScopeFrameworkSource {
92 #[must_use]
94 pub const fn as_str(self) -> &'static str {
95 match self {
96 Self::JobInstanceId => "job_instance_id",
97 Self::JobExecutionId => "job_execution_id",
98 Self::StepExecutionId => "step_execution_id",
99 Self::Attempt => "attempt",
100 Self::DefinitionRevision => "definition_revision",
101 Self::DefinitionFingerprint => "definition_fingerprint",
102 Self::LogicalNodeId => "logical_node_id",
103 Self::StepName => "step_name",
104 }
105 }
106
107 #[must_use]
109 pub const fn value_kind(self) -> ParameterValueKind {
110 match self {
111 Self::JobInstanceId | Self::JobExecutionId | Self::StepExecutionId | Self::Attempt => {
112 ParameterValueKind::U64
113 }
114 Self::DefinitionRevision
115 | Self::DefinitionFingerprint
116 | Self::LogicalNodeId
117 | Self::StepName => ParameterValueKind::String,
118 }
119 }
120}