A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
catalogue.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_CATALOGUE_H_
18#define A11_FLOW_CATALOGUE_H_
19
20#include <optional>
21#include <string>
22#include <string_view>
23#include <vector>
24
25#include <absl/base/nullability.h>
26#include <nlohmann/json_fwd.hpp>
27
28#include "a11/flow/plan.h"
29
30namespace a11::flow {
31
51namespace catalogue {
52
63struct Origin {
68 std::string file;
69 int line = 1;
70 int column = 1;
71
72 friend bool operator==(const Origin&, const Origin&) = default;
73};
74
76struct PortInfo {
77 std::string name;
80 std::string type;
81 std::string description;
82 bool required = false;
84 bool unary = true;
85};
86
88struct ActionInfo {
89 std::string name;
90 std::string description;
91 std::vector<PortInfo> inputs;
92 std::vector<PortInfo> outputs;
94 std::vector<PortInfo> headers;
96 std::optional<Origin> origin;
97
98 [[nodiscard]] const PortInfo* absl_nullable Port(
99 std::string_view port_name, syntax::PortDirection direction) const;
100 [[nodiscard]] std::vector<std::string> PortNames(
102};
103
111struct TypeInfo {
112 std::string tag;
115 std::optional<Origin> origin;
116};
117
120 public:
123 static const Catalogue& Builtin();
124
131 static Catalogue Of(std::vector<ActionInfo> actions,
132 std::vector<TypeInfo> types = {});
133
138 static Catalogue FromJson(const nlohmann::json& value);
139
145 [[nodiscard]] Catalogue MergedWith(const Catalogue& other) const;
146
147 [[nodiscard]] const ActionInfo* absl_nullable Action(
148 std::string_view name) const;
149 [[nodiscard]] const TypeInfo* absl_nullable Type(std::string_view tag) const;
150
151 [[nodiscard]] const std::vector<ActionInfo>& actions() const {
152 return actions_;
153 }
154
155 [[nodiscard]] const std::vector<TypeInfo>& types() const { return types_; }
156
157 [[nodiscard]] bool Empty() const {
158 return actions_.empty() && types_.empty();
159 }
160
161 [[nodiscard]] nlohmann::json ToJson() const;
162
163 private:
164 std::vector<ActionInfo> actions_;
165 std::vector<TypeInfo> types_;
166};
167
169inline constexpr std::string_view kCatalogueFormat = "flow.catalogue/v1";
170
171} // namespace catalogue
172} // namespace a11::flow
173
174#endif // A11_FLOW_CATALOGUE_H_
Everything the tools know about the world, in one place.
Definition catalogue.h:119
bool Empty() const
Definition catalogue.h:157
static Catalogue FromJson(const nlohmann::json &value)
The catalogue value describes, in the shape [ToJson] writes.
Definition catalogue.cc:296
const TypeInfo *absl_nullable Type(std::string_view tag) const
Definition catalogue.cc:415
const ActionInfo *absl_nullable Action(std::string_view name) const
Definition catalogue.cc:406
static Catalogue Of(std::vector< ActionInfo > actions, std::vector< TypeInfo > types={})
The catalogue these entries make.
Definition catalogue.cc:288
const std::vector< TypeInfo > & types() const
Definition catalogue.h:155
const std::vector< ActionInfo > & actions() const
Definition catalogue.h:151
Catalogue MergedWith(const Catalogue &other) const
This catalogue with other laid over it.
Definition catalogue.cc:375
static const Catalogue & Builtin()
The embedded snapshot: what a standalone tool knows with nothing configured.
Definition catalogue.cc:424
nlohmann::json ToJson() const
Definition catalogue.cc:340
std::string value
Definition discover.cc:114
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
constexpr std::string_view kCatalogueFormat
The format field of the catalogue envelope.
Definition catalogue.h:169
PortDirection
Which side of the descriptor a port lands on, spelled as the plan spells it.
Definition syntax.h:728
Definition boundary.cc:32
One compiled struct: a shape a port may be typed with.
Definition plan.h:80
One action a flow may run or call.
Definition catalogue.h:88
std::string name
Definition catalogue.h:89
std::vector< PortInfo > headers
Header names the action declares, with what each is for.
Definition catalogue.h:94
std::vector< PortInfo > inputs
Definition catalogue.h:91
std::vector< std::string > PortNames(syntax::PortDirection direction) const
Definition catalogue.cc:276
std::string description
Definition catalogue.h:90
std::optional< Origin > origin
Where the declaration is, when it was found by reading source.
Definition catalogue.h:96
std::vector< PortInfo > outputs
Definition catalogue.h:92
const PortInfo *absl_nullable Port(std::string_view port_name, syntax::PortDirection direction) const
Definition catalogue.cc:264
Where an entry was declared, for an entry that was found by reading source.
Definition catalogue.h:63
int column
Definition catalogue.h:70
int line
Definition catalogue.h:69
std::string file
The path as the host gave it to the scanner: absolute if the root was, relative if it was.
Definition catalogue.h:68
friend bool operator==(const Origin &, const Origin &)=default
One port of an action, as a tool needs to show it.
Definition catalogue.h:76
std::string description
Definition catalogue.h:81
std::string type
The type as the action's schema spells it: a Python type name, a serialisation tag,...
Definition catalogue.h:80
std::string name
Definition catalogue.h:77
bool unary
Whether the port carries one value rather than a stream.
Definition catalogue.h:84
bool required
Definition catalogue.h:82
One type the host knows, by the tag a flow writes it as.
Definition catalogue.h:111
std::optional< Origin > origin
Where the declaration is, when it was found by reading source.
Definition catalogue.h:115
DtoPlan shape
Definition catalogue.h:113
std::string tag
Definition catalogue.h:112