dex_sdk/flow.rs
1// Copyright (c) 2026 Super Durable, Inc.
2//
3// Licensed under the Super Durable Source License 1.0.
4// You may not use this file except in compliance with the License.
5// See the LICENSE file in the repository root.
6//
7// SPDX-License-Identifier: LicenseRef-Super-Durable-1.0
8
9use crate::{PersistenceSchema, RpcList, StepList, Value, short_type_name};
10
11/// Defines a durable application Flow and its registered API surface.
12///
13/// A Flow owns a typed start input, Step list, persistence schema, and RPC list. Implementations are
14/// registered as owned values in [`crate::Registry`] and shared safely across Worker invocations.
15/// Keep [`Self::flow_type`] and all subordinate names stable while any execution is running.
16///
17/// # Examples
18///
19/// ```
20/// use dex_sdk::{Flow, StepList};
21///
22/// struct OrderFlow;
23///
24/// impl Flow for OrderFlow {
25/// type StartInput = String;
26///
27/// fn flow_type(&self) -> &'static str {
28/// "OrderFlow"
29/// }
30///
31/// fn steps(&self) -> StepList<'_, Self::StartInput> {
32/// StepList::empty()
33/// }
34/// }
35/// ```
36pub trait Flow: Send + Sync + 'static {
37 /// Value accepted by [`crate::Client::start_flow`] and the starting Step.
38 type StartInput: Value;
39
40 /// Returns the stable Flow type sent to Dex.
41 ///
42 /// The default is the final Rust type-name segment.
43 fn flow_type(&self) -> &'static str {
44 short_type_name::<Self>()
45 }
46
47 /// Returns the starting Step and all other Step definitions.
48 ///
49 /// The default is an empty list, which is valid only for Flows driven entirely by RPCs.
50 fn steps(&self) -> StepList<'_, Self::StartInput> {
51 StepList::empty()
52 }
53
54 /// Declares every Attribute and Channel used by this Flow.
55 ///
56 /// The default schema is empty.
57 fn persistence(&self) -> PersistenceSchema {
58 PersistenceSchema::new()
59 }
60
61 /// Binds public RPC names to methods on this Flow implementation.
62 ///
63 /// The default list is empty.
64 fn rpcs(&self) -> RpcList<Self>
65 where
66 Self: Sized,
67 {
68 RpcList::new()
69 }
70}