openquiver_graph/value.rs
1//! What a data pin carries, and the literals that can be given to one.
2
3use serde::{Deserialize, Serialize};
4use ts_rs::TS;
5
6/// What a data pin carries.
7///
8/// The vocabulary lives beside [`Value`] because the two answer to each other:
9/// a literal in a configuration block has to be checkable against the pin it is
10/// given to. Resolved types are never stored on wires — the compiler derives
11/// them, and a second copy would go stale.
12///
13/// `TS` is derived here rather than on a duplicate enum in the editor: the
14/// editor's view embeds this type directly, and a second enum mirroring its
15/// variants would be the same fact told twice, free to drift the moment one
16/// side gains a variant.
17#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, TS)]
18#[ts(export, export_to = "../../../clients/web/src/lib/api/")]
19pub enum DataType {
20 Text,
21 Number,
22 Bool,
23 /// Arbitrary structured data. The escape hatch for anything not worth
24 /// naming yet.
25 Json,
26 Array(Box<DataType>),
27 /// A handle to a connected agent process.
28 AgentRef,
29 /// A handle to an ACP session. The value is the handle's id, not the object:
30 /// a session has to survive being written to the journal and read back
31 /// after the process that owned it is gone.
32 SessionRef,
33 FileRef,
34 /// The name of a secret, never its value.
35 SecretRef,
36 /// Adopts the type of whatever it is first connected to, then propagates.
37 Wildcard,
38}
39
40/// A literal in a node's configuration block.
41///
42/// Configuration entries *are* the node's data inputs: a pin either takes a
43/// literal here or receives a wire, never both. Modelling them as one thing
44/// removes the separate notion of a "default value on an unconnected pin" that
45/// would otherwise have to exist and be kept in step.
46#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
47#[ts(export, export_to = "../../../clients/web/src/lib/api/")]
48pub enum Value {
49 Text(String),
50 Number(f64),
51 Bool(bool),
52 Array(Vec<Value>),
53 /// The *name* of a secret, resolved from the environment or a keychain when
54 /// the workflow runs.
55 ///
56 /// Never the secret itself. A graph carrying a key would leak it the moment
57 /// the repository is shared — and sharing the repository is the entire
58 /// collaboration story.
59 Secret(String),
60}