sched: extract shared input traversal behind SourceResolver seam (T03)
This commit is contained in:
@@ -7,17 +7,14 @@ from wf_core.conditions import safe_resolve_path
|
||||
from wf_core.errors import WorkflowExecutionError
|
||||
from wf_core.local_paths import LocalPathError, set_local_value
|
||||
from wf_core.models.input_bindings import (
|
||||
ArrayExpression,
|
||||
InputExpression,
|
||||
InputExpressionBinding,
|
||||
InputPathBinding,
|
||||
InputValueBinding,
|
||||
LiteralExpression,
|
||||
ObjectExpression,
|
||||
PathExpression,
|
||||
StepInputBinding,
|
||||
)
|
||||
from wf_core.models.json_values import JsonValue, validate_strict_json_value
|
||||
from wf_core.models.json_values import JsonValue
|
||||
from wf_core.runtime.input_sources import SourceResolver
|
||||
|
||||
|
||||
def resolve_input_expression(
|
||||
@@ -30,45 +27,32 @@ def resolve_input_expression(
|
||||
location: str,
|
||||
) -> JsonValue:
|
||||
"""Resolve one composite expression while preserving its payload location."""
|
||||
from wf_core.runtime.input_sources import (
|
||||
GraphSourceResolver,
|
||||
resolve_composed_expression,
|
||||
)
|
||||
|
||||
if isinstance(expression, LiteralExpression):
|
||||
return expression.value
|
||||
if isinstance(expression, PathExpression):
|
||||
try:
|
||||
value = safe_resolve_path(
|
||||
str(expression.path),
|
||||
state=state,
|
||||
workflow_input=workflow_input,
|
||||
context=context,
|
||||
)
|
||||
return validate_strict_json_value(value)
|
||||
except (ValueError, WorkflowExecutionError) as exc:
|
||||
raise WorkflowExecutionError(f"{label} {location}: {exc}") from exc
|
||||
if isinstance(expression, ArrayExpression):
|
||||
return [
|
||||
resolve_input_expression(
|
||||
item,
|
||||
state=state,
|
||||
workflow_input=workflow_input,
|
||||
context=context,
|
||||
label=label,
|
||||
location=f"{location}[{index}]",
|
||||
)
|
||||
for index, item in enumerate(expression.items)
|
||||
]
|
||||
if isinstance(expression, ObjectExpression):
|
||||
return {
|
||||
field: resolve_input_expression(
|
||||
value,
|
||||
state=state,
|
||||
workflow_input=workflow_input,
|
||||
context=context,
|
||||
label=label,
|
||||
location=f"{location}.{field}",
|
||||
)
|
||||
for field, value in expression.fields.items()
|
||||
}
|
||||
raise WorkflowExecutionError(f"unsupported input expression for {label} {location}")
|
||||
resolver = GraphSourceResolver(
|
||||
state=state, workflow_input=workflow_input, context=context
|
||||
)
|
||||
return resolve_composed_expression(
|
||||
expression, resolver=resolver, label=label, location=location
|
||||
)
|
||||
|
||||
|
||||
def resolve_input_expression_with_resolver(
|
||||
expression: InputExpression,
|
||||
*,
|
||||
resolver: SourceResolver,
|
||||
label: str,
|
||||
location: str,
|
||||
) -> JsonValue:
|
||||
"""Resolve one expression through an explicit typed source resolver."""
|
||||
from wf_core.runtime.input_sources import resolve_composed_expression
|
||||
|
||||
return resolve_composed_expression(
|
||||
expression, resolver=resolver, label=label, location=location
|
||||
)
|
||||
|
||||
|
||||
def resolve_step_input_bindings(
|
||||
|
||||
Reference in New Issue
Block a user