A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
describe.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
64#ifndef A11_ACTIONS_DESCRIBE_H_
65#define A11_ACTIONS_DESCRIBE_H_
66
67#include <string>
68#include <string_view>
69#include <vector>
70
71#include <absl/status/statusor.h>
72#include <nlohmann/json_fwd.hpp>
73
74#include "a11/actions/schema.h"
75
76namespace a11::actions {
77
78class ActionRegistry;
79
81inline constexpr std::string_view kSchemaDocumentFormat = "a11.actions/v1";
82
92enum class PortView {
93 kCallable,
94 kAll,
95};
96
105 std::vector<std::string> names;
107 std::vector<std::string> exact;
110 bool include_reserved = false;
112 bool runnable_only = false;
113};
114
121absl::StatusOr<SchemaQuery> ParseSchemaQuery(std::string_view encoded);
122
127absl::StatusOr<SchemaQuery> ParseSchemaQueryString(std::string_view query);
128
130bool SchemaQueryAccepts(const SchemaQuery& query, std::string_view name);
131
139nlohmann::json SchemaToJson(const ActionSchema& schema, bool runnable,
141
145nlohmann::json RegistryToJson(const ActionRegistry& registry,
146 const SchemaQuery& query);
147
149absl::StatusOr<std::string> RegistryToJsonText(const ActionRegistry& registry,
150 const SchemaQuery& query);
151
153absl::StatusOr<std::string> SchemaToJsonText(
154 const ActionSchema& schema, bool runnable,
156
168absl::StatusOr<ActionSchema> SchemaFromJson(const nlohmann::json& entry);
169
171absl::StatusOr<ActionSchema> SchemaFromJsonText(std::string_view encoded);
172
179absl::StatusOr<std::vector<nlohmann::json>> SchemasInDocument(
180 const nlohmann::json& document);
181
182} // namespace a11::actions
183
184#endif // A11_ACTIONS_DESCRIBE_H_
Schemas describing an action's typed interface and its settings.
A thread-safe catalogue mapping action names to schema and handler.
Definition registry.h:59
std::string name
The name and its colon, which travel together because they always do.
Definition format.cc:49
Definition action.cc:63
absl::StatusOr< std::vector< nlohmann::json > > SchemasInDocument(const nlohmann::json &envelope)
The actions entries of document, or why there are none to read.
Definition describe.cc:497
PortView
Which ports a written schema includes.
Definition describe.h:92
@ kAll
Everything the schema declares, autofills flagged.
@ kCallable
What a caller may write. The default.
nlohmann::json RegistryToJson(const ActionRegistry &registry, const SchemaQuery &request)
A whole document: every schema in registry that query accepts.
Definition describe.cc:387
absl::StatusOr< std::string > RegistryToJsonText(const ActionRegistry &registry, const SchemaQuery &request)
RegistryToJson as text, or why it could not be encoded.
Definition describe.cc:412
constexpr std::string_view kSchemaDocumentFormat
The format field of the schema document.
Definition describe.h:81
nlohmann::json SchemaToJson(const ActionSchema &schema, bool runnable, PortView ports)
One schema as an actions entry.
Definition describe.cc:336
absl::StatusOr< SchemaQuery > ParseSchemaQuery(std::string_view encoded)
Parses a SchemaQuery from the request port's JSON.
Definition describe.cc:265
absl::StatusOr< ActionSchema > SchemaFromJson(const nlohmann::json &entry)
The schema an actions entry was written from.
Definition describe.cc:427
bool SchemaQueryAccepts(const SchemaQuery &request, std::string_view name)
Whether name matches query's name filters.
Definition describe.cc:250
absl::StatusOr< ActionSchema > SchemaFromJsonText(std::string_view encoded)
SchemaFromJson, parsing encoded first.
Definition describe.cc:491
absl::StatusOr< std::string > SchemaToJsonText(const ActionSchema &schema, bool runnable, PortView ports)
One schema as a whole document, for a route that answers with one.
Definition describe.cc:417
absl::StatusOr< SchemaQuery > ParseSchemaQueryString(std::string_view query)
Parses a SchemaQuery from a URL query string.
Definition describe.cc:303
The full typed interface of an action.
Definition schema.h:138
Which schemas to write, and how much of each.
Definition describe.h:103
std::vector< std::string > exact
Exact names, in addition to names; empty adds nothing.
Definition describe.h:107
std::vector< std::string > names
Full-match name patterns; empty matches every name.
Definition describe.h:105
bool runnable_only
Omit actions registered for their schema alone, which live on a peer.
Definition describe.h:112
PortView ports
Definition describe.h:108
bool include_reserved
Include the __-prefixed reserved actions, discovery's own included.
Definition describe.h:110