A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
plan.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef A11_FLOW_PLAN_H_
18#define A11_FLOW_PLAN_H_
19
20#include <cstddef>
21#include <optional>
22#include <string>
23#include <string_view>
24#include <vector>
25
26#include <absl/base/nullability.h>
27#include <absl/time/time.h>
28
29#include "a11/flow/syntax.h"
30
31namespace a11::flow {
32
34struct PortPlan {
35 std::string name;
38 std::string declared;
42 std::string type;
43 bool unary = true;
44 bool required = false;
45 std::string description;
47};
48
56struct FieldPlan {
57 std::string name;
58 std::string declared;
59 std::string type;
62 std::string element;
64 std::string dto_name;
65 std::string element_dto_name;
66 bool required = false;
67 bool unique = false;
69 std::string pattern;
70 bool has_pattern = false;
71 std::vector<syntax::Constant> enumeration;
72 bool has_enumeration = false;
74 bool has_default = false;
75 std::string description;
77};
78
80struct DtoPlan {
81 std::string name;
82 std::string description;
83 std::vector<FieldPlan> fields;
84 // Whether the shape holds bytes anywhere in it, directly or through another
85 // shape it names.
93 bool binary = false;
95
97 [[nodiscard]] const FieldPlan* absl_nullable Field(
98 std::string_view field_name) const;
99
101 [[nodiscard]] std::vector<std::string> FieldNames() const;
102};
103
113
121struct StepPlan {
125 std::string kind;
128 std::string label;
130 std::vector<std::string> after;
132 std::string action;
133 std::string mode;
134 std::string node_map;
135 std::optional<absl::Duration> timeout;
136 bool tolerant = false;
137 bool tee = false;
140 std::string source;
141 std::string destination;
144 std::vector<std::vector<StepPlan>> bodies;
146};
147
149struct FlowPlan {
151 std::string name;
160 bool entry = false;
161 std::string description;
162 std::vector<PortPlan> ports;
163 std::vector<HeaderPlan> headers;
165 std::vector<std::string> node_maps;
166 std::vector<StepPlan> steps;
168
170 [[nodiscard]] const PortPlan* absl_nullable Port(
171 std::string_view port_name, syntax::PortDirection direction) const;
172
174 [[nodiscard]] bool HasPort(std::string_view port_name,
176 return Port(port_name, direction) != nullptr;
177 }
178
180 [[nodiscard]] std::vector<std::string> PortNames(
182};
183
185struct Program {
186 std::string source_name;
187 std::vector<FlowPlan> flows;
194 std::vector<DtoPlan> dtos;
195
198 [[nodiscard]] const FlowPlan* absl_nullable Flow(std::string_view name) const;
199
201 [[nodiscard]] const FlowPlan* absl_nullable Entry() const;
202
204 [[nodiscard]] const DtoPlan* absl_nullable Dto(std::string_view name) const;
205};
206
208inline constexpr std::string_view kPlanFormat = "flow.plan/v1";
209
210} // namespace a11::flow
211
212#endif // A11_FLOW_PLAN_H_
std::string name
The name and its colon, which travel together because they always do.
Definition format.cc:49
std::string direction
in, out or header, as written – a shouted IN stays shouted.
Definition format.cc:47
PortDirection
Which side of the descriptor a port lands on, spelled as the plan spells it.
Definition syntax.h:728
Definition boundary.cc:32
constexpr std::string_view kPlanFormat
The format field of the plan envelope.
Definition plan.h:208
One compiled struct: a shape a port may be typed with.
Definition plan.h:80
std::string description
Definition plan.h:82
const FieldPlan *absl_nullable Field(std::string_view field_name) const
The field of this name, or nullptr.
Definition resolve.cc:3862
std::vector< std::string > FieldNames() const
Every field name, in declaration order, for a message that lists them.
Definition resolve.cc:3872
std::string name
Definition plan.h:81
syntax::Location location
Definition plan.h:94
bool binary
Whether the shape holds bytes anywhere in it, directly or through another shape it names.
Definition plan.h:93
std::vector< FieldPlan > fields
Definition plan.h:83
One field of a struct, resolved.
Definition plan.h:56
syntax::FieldRange range
Definition plan.h:68
std::string pattern
Definition plan.h:69
std::string element
The element type of a list[T], resolved, or empty where it is not a list.
Definition plan.h:62
bool has_default
Definition plan.h:74
std::string name
Definition plan.h:57
std::string element_dto_name
Definition plan.h:65
syntax::Constant default_value
Definition plan.h:73
std::string dto_name
Whether the field, or a list's element, names a declared shape.
Definition plan.h:64
std::vector< syntax::Constant > enumeration
Definition plan.h:71
bool unique
Definition plan.h:67
bool has_pattern
Definition plan.h:70
syntax::Location location
Definition plan.h:76
std::string declared
Definition plan.h:58
bool required
Definition plan.h:66
std::string description
Definition plan.h:75
std::string type
Definition plan.h:59
bool has_enumeration
Definition plan.h:72
One compiled flow: what a caller sees, and what the runtime will do.
Definition plan.h:149
std::vector< HeaderPlan > headers
Definition plan.h:163
bool HasPort(std::string_view port_name, syntax::PortDirection direction) const
Whether a port of this name is declared in that direction.
Definition plan.h:174
syntax::Location location
Definition plan.h:167
std::vector< StepPlan > steps
Definition plan.h:166
std::string description
Definition plan.h:161
bool entry
Whether this is the file's entry point, declared flow { ... }.
Definition plan.h:160
std::vector< PortPlan > ports
Definition plan.h:162
std::vector< std::string > PortNames(syntax::PortDirection direction) const
Every port name in one direction, sorted, for a message that lists them.
Definition resolve.cc:3817
std::vector< std::string > node_maps
The node maps the flow declares, in declaration order.
Definition plan.h:165
std::string name
Empty for the entry flow, which is the one flow that has no name.
Definition plan.h:151
const PortPlan *absl_nullable Port(std::string_view port_name, syntax::PortDirection direction) const
The port with this name and direction, or nullptr.
Definition resolve.cc:3807
One declared header.
Definition plan.h:105
std::string alias
Definition plan.h:107
std::string description
Definition plan.h:110
bool has_default
Definition plan.h:109
std::string name
Definition plan.h:106
syntax::Location location
Definition plan.h:111
syntax::Constant default_value
Definition plan.h:108
One declared port of a flow, resolved.
Definition plan.h:34
bool unary
Definition plan.h:43
std::string description
Definition plan.h:45
syntax::Location location
Definition plan.h:46
syntax::PortDirection direction
Definition plan.h:36
std::string type
What the type is, for the schema a caller sees: a built-in's mimetype or Python type name,...
Definition plan.h:42
bool required
Definition plan.h:44
std::string name
Definition plan.h:35
std::string declared
The type as the flow wrote it, parameters and all: list[string].
Definition plan.h:38
Every flow and shape one source file declares.
Definition plan.h:185
std::string source_name
Definition plan.h:186
const FlowPlan *absl_nullable Flow(std::string_view name) const
The flow of this name, or nullptr.
Definition resolve.cc:3829
const DtoPlan *absl_nullable Dto(std::string_view name) const
The shape of this name, or nullptr.
Definition resolve.cc:3853
std::vector< DtoPlan > dtos
The shapes, in declaration order.
Definition plan.h:194
const FlowPlan *absl_nullable Entry() const
The file's entry point, or nullptr when it declares none.
Definition resolve.cc:3844
std::vector< FlowPlan > flows
Definition plan.h:187
One resolved statement, as the plan format describes it.
Definition plan.h:121
bool tee
Definition plan.h:137
std::string node_map
Definition plan.h:134
std::vector< std::vector< StepPlan > > bodies
Bodies nested in this step, in the order the language reads them: a for or repeat has one,...
Definition plan.h:144
syntax::Location location
Definition plan.h:145
std::string action
For a call: the action, the verb, and where it goes.
Definition plan.h:132
std::string label
The name this step is known by: a bound name, or action, for, if with a #2 after it where one label i...
Definition plan.h:128
std::optional< absl::Duration > timeout
Definition plan.h:135
std::string mode
Definition plan.h:133
std::vector< std::string > after
What it waits for, by label.
Definition plan.h:130
std::string destination
Definition plan.h:141
std::string source
For a pipe/skip/wait/drain: what it reads and what it writes, as a reader would say them – search....
Definition plan.h:140
std::string kind
The kind of statement, as a11.flow.plan's Step.kind spells it: call, pipe, skip, wait,...
Definition plan.h:125
bool tolerant
Definition plan.h:136
A value the language can write out in full: what a literal is, and what folding a literal expression ...
Definition syntax.h:80
A bound on a field: 1..200, 1.., ..200.
Definition syntax.h:789
Where a piece of syntax starts, reduced to what every reader of it needs.
Definition syntax.h:49