|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
What the UI service's client and server share (spec 5 §12): content hashes, the bundle's manifest, and the bodies of the ui-hello, ui-catalog and ui-fetch envelopes, with their bounds and their parsers. More...
#include <algorithm>#include <cstddef>#include <cstdint>#include <expected>#include <functional>#include <glaze/glaze.hpp>#include <initializer_list>#include <map>#include <memory>#include <optional>#include <set>#include <string>#include <string_view>#include <tuple>#include <utility>#include <variant>#include <vector>#include "../core/wire.hpp"#include "../session/session_auth.hpp"#include "document.hpp"#include "value.hpp"Go to the source code of this file.
Classes | |
| struct | morph::ui::ManifestFile |
| One file of a manifest. More... | |
| struct | morph::ui::Manifest |
| A bundle's manifest: every file the application serves, by its hash (spec 5 §12, "Content addressing"). More... | |
| struct | morph::ui::HelloRequest |
| The body of a ui-hello request: what the client speaks and carries. More... | |
| struct | morph::ui::HelloReply |
| The body of a ui-hello reply. More... | |
| struct | morph::ui::EvaluateReply |
| The body of a ui-evaluate reply: what ActionDispatcher::evaluate answered. More... | |
| struct | morph::ui::FileRequest |
| The body of a ui-file request: one step of an upload or a download, named by op. More... | |
| struct | morph::ui::FileReply |
| The body of a ui-file reply: the members its op answers, the others absent. More... | |
| struct | morph::ui::CatalogEntry |
| One catalog entry (spec 6 §8). More... | |
| struct | morph::ui::CatalogReply |
| The body of a ui-catalog reply: the catalog filtered for the principal, and the facts a client's load-time validation reads (ui::Catalog). More... | |
| struct | morph::ui::FetchRequest |
| The body of a ui-fetch request. More... | |
Functions | |
| std::string | morph::ui::contentHash (std::string_view bytes) |
The content hash of bytes: sha256: and the SHA-256 digest in 64 lower-case hexadecimal digits. | |
| bool | morph::ui::isContentHash (std::string_view text) |
Whether text is a well-formed content hash. | |
| std::optional< std::string > | morph::ui::detail::mustUnderstand (Json const &json, std::string_view where) |
| The must-understand key (!name) of one object, if it has one. | |
| std::optional< std::string > | morph::ui::detail::mustUnderstandIn (Json const &root, std::string_view what, std::initializer_list< std::string_view > arrays, std::initializer_list< std::string_view > maps) |
| The must-understand keys of a message: its top level, every element of its listed arrays and every value of its listed maps. | |
| template<typename T> | |
| std::expected< T, std::string > | morph::ui::detail::readMessage (std::string_view text, std::string_view what, std::initializer_list< std::string_view > arrays, std::initializer_list< std::string_view > maps) |
| Reads a message: bounded depth, must-understand keys refused, unknown keys ignored. | |
| template<typename T> | |
| std::string | morph::ui::detail::writeMessage (T const &value) |
| Writes a message as JSON, escaping control bytes as wire::encode does. | |
| std::optional< std::string > | morph::ui::detail::checkName (std::string_view name, std::string_view what) |
| Checks a name's length. | |
| std::optional< std::string > | morph::ui::detail::checkNames (std::vector< std::string > const &names, std::size_t limit, std::string_view list, std::string_view item) |
| Checks a list of names: its length and each name's. | |
| std::optional< std::string > | morph::ui::detail::checkHostNames (std::map< std::string, std::int64_t, std::less<> > const &names, std::string_view list, std::string_view item) |
| Checks a map of host names to versions: its size and each name's length. | |
| std::string | morph::ui::manifestText (Manifest const &manifest) |
| The manifest's text: the JSON its digest is the hash of. Equal manifests write equal text. | |
| std::expected< Manifest, std::string > | morph::ui::parseManifest (std::string_view text) |
| Reads a manifest a server sent. | |
| std::expected< HelloRequest, std::string > | morph::ui::parseHelloRequest (std::string_view text) |
| Reads a ui-hello request body. | |
| std::expected< HelloReply, std::string > | morph::ui::parseHelloReply (std::string_view text) |
| Reads a ui-hello reply body. | |
| std::expected< EvaluateReply, std::string > | morph::ui::parseEvaluateReply (std::string_view text) |
| Reads a ui-evaluate reply body. | |
| std::expected< FileRequest, std::string > | morph::ui::parseFileRequest (std::string_view text) |
| Reads a ui-file request body. | |
| std::expected< FileReply, std::string > | morph::ui::parseFileReply (std::string_view text) |
| Reads a ui-file reply body. | |
| std::expected< CatalogReply, std::string > | morph::ui::parseCatalogReply (std::string_view text) |
| Reads a ui-catalog reply body. | |
| std::expected< FetchRequest, std::string > | morph::ui::parseFetchRequest (std::string_view text) |
| Reads a ui-fetch request body. | |
Variables | |
| constexpr std::string_view | morph::ui::kExprVocabulary = "expr/1" |
| The expression vocabulary every bundle needs alongside ui/1. | |
| constexpr std::string_view | morph::ui::kHelloKind = "ui-hello" |
| The envelope kind of the handshake. | |
| constexpr std::string_view | morph::ui::kCatalogKind = "ui-catalog" |
| The envelope kind of the catalog. | |
| constexpr std::string_view | morph::ui::kFetchKind = "ui-fetch" |
| The envelope kind that fetches a file by its hash. | |
| constexpr std::string_view | morph::ui::kEvaluateKind = "ui-evaluate" |
| The envelope kind that evaluates an action body without running it (spec 5 §7). | |
| constexpr std::string_view | morph::ui::kFileKind = "ui-file" |
| The envelope kind of the file side channel (files/1, spec 6 §18): uploads and downloads in chunks. | |
| constexpr std::string_view | morph::ui::kServiceModel = "ui" |
| The pseudo-model the service's envelopes are authorised under: authorize(session, "ui", <action>). | |
| constexpr std::string_view | morph::ui::kHelloAction = "hello" |
| The pseudo-action that gates ui-hello, and the fetch of a public file or the manifest. | |
| constexpr std::string_view | morph::ui::kCatalogAction = "catalog" |
| The pseudo-action that gates ui-catalog. | |
| constexpr std::string_view | morph::ui::kFetchAction = "fetch" |
| The pseudo-action that gates the fetch of a file that is not public. | |
| constexpr std::string_view | morph::ui::kHashPrefix = "sha256:" |
| The prefix of a content hash. | |
| constexpr std::size_t | morph::ui::kHashDigits = 64 |
| The hexadecimal digits of a SHA-256 digest. | |
| constexpr std::size_t | morph::ui::kMaxFileChunkBytes = std::size_t{256} * 1024 |
| The most file bytes one ui-file chunk carries, before base64url. | |
| constexpr std::size_t | morph::ui::kMaxFileRequestBytes = (kMaxFileChunkBytes / 3 * 4) + (std::size_t{4} * 1024) |
| The largest ui-file request body a server reads: a chunk in base64url, and the rest of the request. | |
| constexpr std::size_t | morph::ui::kMaxRequestBytes = std::size_t{64} * 1024 |
| The largest request body (ui-hello, ui-fetch) a server reads. | |
| constexpr std::size_t | morph::ui::kMaxFileBytes = std::size_t{4} * 1024 * 1024 |
| The largest file a bundle may hold, and a client accepts. | |
| constexpr std::size_t | morph::ui::kMaxBundleFiles = 4096 |
| The most files a manifest, and entries a catalog, may list. | |
| constexpr std::size_t | morph::ui::kMaxCatalogFacts = 16384 |
| The most action ids, model facts or action facts a catalog may carry. | |
| constexpr std::size_t | morph::ui::kMaxListItems = 256 |
| The most items of a list or map in a ui-hello (vocabularies, host components, commands, values). | |
| constexpr std::size_t | morph::ui::kMaxNameBytes = 256 |
| The longest name: an id, a kind, a vocabulary, a host name, an application id or version. | |
| constexpr std::string_view | morph::ui::kScreenFile = "screen" |
| The file kinds of a manifest. | |
| constexpr std::string_view | morph::ui::kAppFile = "app" |
| The app document (spec 6 §5). | |
| constexpr std::string_view | morph::ui::kThemeFile = "theme" |
| A theme (ui-theme/1, spec 6 §6). | |
| constexpr std::string_view | morph::ui::kMessagesFile = "messages" |
| A message catalogue. | |
| constexpr std::string_view | morph::ui::kComponentFile = "component" |
| A delivered custom component (spec 5 §10). | |
| constexpr std::string_view | morph::ui::kIconFile = "icon" |
| An icon of a theme's icon set: SVG text. | |
| constexpr std::size_t | morph::ui::kMaxIconBytes = std::size_t{64} * 1024 |
| The largest icon file a bundle may hold. | |
What the UI service's client and server share (spec 5 §12): content hashes, the bundle's manifest, and the bodies of the ui-hello, ui-catalog and ui-fetch envelopes, with their bounds and their parsers.
Specified in docs/spec/ui/service.md.
Definition in file bundle.hpp.
|
inlinenodiscard |
The content hash of bytes: sha256: and the SHA-256 digest in 64 lower-case hexadecimal digits.
| bytes | The bytes. |
Definition at line 99 of file bundle.hpp.
|
inlinenodiscard |
Whether text is a well-formed content hash.
| text | The text. |
Definition at line 115 of file bundle.hpp.
|
inlinenodiscard |
The must-understand key (!name) of one object, if it has one.
| json | The value; anything but an object has none. |
| where | What the object is, for the reason. |
Definition at line 369 of file bundle.hpp.
|
inlinenodiscard |
The must-understand keys of a message: its top level, every element of its listed arrays and every value of its listed maps.
| root | The parsed message. |
| what | What the message is. |
| arrays | The keys of arrays whose elements are objects this layer defines. |
| maps | The keys of maps whose values are objects this layer defines. |
Definition at line 391 of file bundle.hpp.
|
nodiscard |
Reads a message: bounded depth, must-understand keys refused, unknown keys ignored.
| T | The message type. |
| text | The JSON text. |
| what | What the message is, for the reason. |
| arrays | The keys of arrays whose elements are objects this layer defines. |
| maps | The keys of maps whose values are objects this layer defines. |
Definition at line 437 of file bundle.hpp.
|
nodiscard |
Writes a message as JSON, escaping control bytes as wire::encode does.
| T | The message type. |
| value | The message. |
Definition at line 459 of file bundle.hpp.
|
inlinenodiscard |
Checks a name's length.
| name | The name. |
| what | What it names, for the reason. |
Definition at line 471 of file bundle.hpp.
|
inlinenodiscard |
Checks a list of names: its length and each name's.
| names | The names. |
| limit | The most names allowed. |
| list | What the list is, for the reason. |
| item | What one name is, for the reason. |
Definition at line 485 of file bundle.hpp.
|
inlinenodiscard |
Checks a map of host names to versions: its size and each name's length.
| names | The map. |
| list | What the map holds, for the reason. |
| item | What one name is, for the reason. |
Definition at line 503 of file bundle.hpp.
|
inlinenodiscard |
The manifest's text: the JSON its digest is the hash of. Equal manifests write equal text.
| manifest | The manifest; its files should be sorted by kind then id. |
Definition at line 523 of file bundle.hpp.
|
inlinenodiscard |
Reads a manifest a server sent.
Refused: text that is not JSON or nests deeper than kMaxJsonDepth, a must-understand key at the top or in a file, more than kMaxBundleFiles files, a name longer than kMaxNameBytes, a malformed hash, a size above kMaxFileBytes, or two files of one kind with one id. Unknown keys are ignored.
| text | The manifest's text, already verified against its digest. |
Definition at line 532 of file bundle.hpp.
|
inlinenodiscard |
Reads a ui-hello request body.
Refused: a body longer than kMaxRequestBytes, text that is not JSON or nests too deep, a must-understand key, more than kMaxListItems vocabularies or host names of a kind, or a name longer than kMaxNameBytes.
| text | The request body; empty reads as a client that speaks nothing. |
Definition at line 574 of file bundle.hpp.
|
inlinenodiscard |
Reads a ui-hello reply body.
Refused: text that is not JSON or nests too deep, a must-understand key, more than kMaxListItems vocabularies, a name longer than kMaxNameBytes, or a digest that is not a content hash.
| text | The reply body. |
Definition at line 607 of file bundle.hpp.
|
inlinenodiscard |
Reads a ui-evaluate reply body.
Refused: text that is not JSON or nests too deep, a must-understand key at the top, a body that is not an object, or more than kMaxCatalogFacts field errors.
| text | The reply body. |
Definition at line 633 of file bundle.hpp.
|
inlinenodiscard |
Reads a ui-file request body.
Refused: a body longer than kMaxFileRequestBytes, text that is not JSON or nests too deep, a must-understand key, or an op that is not begin, chunk, end or read.
| text | The request body. |
Definition at line 654 of file bundle.hpp.
|
inlinenodiscard |
Reads a ui-file reply body.
| text | The reply body. |
Definition at line 672 of file bundle.hpp.
|
inlinenodiscard |
Reads a ui-catalog reply body.
Refused: text that is not JSON or nests too deep, a must-understand key at the top, in an entry or in a model's or action's facts, more than kMaxBundleFiles entries, more than kMaxCatalogFacts permitted actions, model facts or action facts, or an entry id longer than kMaxNameBytes.
| text | The reply body. |
Definition at line 683 of file bundle.hpp.
|
inlinenodiscard |
Reads a ui-fetch request body.
Refused: a body longer than kMaxRequestBytes, text that is not JSON or nests too deep, a must-understand key, or a hash that is not a content hash.
| text | The request body. |
Definition at line 714 of file bundle.hpp.
|
inlineconstexpr |
The expression vocabulary every bundle needs alongside ui/1.
Definition at line 36 of file bundle.hpp.
|
inlineconstexpr |
The envelope kind of the handshake.
Definition at line 39 of file bundle.hpp.
|
inlineconstexpr |
The envelope kind of the catalog.
Definition at line 41 of file bundle.hpp.
|
inlineconstexpr |
The envelope kind that fetches a file by its hash.
Definition at line 43 of file bundle.hpp.
|
inlineconstexpr |
The envelope kind that evaluates an action body without running it (spec 5 §7).
Definition at line 45 of file bundle.hpp.
|
inlineconstexpr |
The envelope kind of the file side channel (files/1, spec 6 §18): uploads and downloads in chunks.
Definition at line 47 of file bundle.hpp.
|
inlineconstexpr |
The pseudo-model the service's envelopes are authorised under: authorize(session, "ui", <action>).
Definition at line 50 of file bundle.hpp.
|
inlineconstexpr |
The pseudo-action that gates ui-hello, and the fetch of a public file or the manifest.
Definition at line 52 of file bundle.hpp.
|
inlineconstexpr |
The pseudo-action that gates ui-catalog.
Definition at line 54 of file bundle.hpp.
|
inlineconstexpr |
The pseudo-action that gates the fetch of a file that is not public.
Definition at line 56 of file bundle.hpp.
|
inlineconstexpr |
The prefix of a content hash.
Definition at line 59 of file bundle.hpp.
|
inlineconstexpr |
The hexadecimal digits of a SHA-256 digest.
Definition at line 61 of file bundle.hpp.
|
inlineconstexpr |
The most file bytes one ui-file chunk carries, before base64url.
Definition at line 64 of file bundle.hpp.
|
inlineconstexpr |
The largest ui-file request body a server reads: a chunk in base64url, and the rest of the request.
Definition at line 66 of file bundle.hpp.
|
inlineconstexpr |
The largest request body (ui-hello, ui-fetch) a server reads.
Definition at line 69 of file bundle.hpp.
|
inlineconstexpr |
The largest file a bundle may hold, and a client accepts.
Definition at line 71 of file bundle.hpp.
|
inlineconstexpr |
The most files a manifest, and entries a catalog, may list.
Definition at line 73 of file bundle.hpp.
|
inlineconstexpr |
The most action ids, model facts or action facts a catalog may carry.
Definition at line 75 of file bundle.hpp.
|
inlineconstexpr |
The most items of a list or map in a ui-hello (vocabularies, host components, commands, values).
Definition at line 77 of file bundle.hpp.
|
inlineconstexpr |
The longest name: an id, a kind, a vocabulary, a host name, an application id or version.
Definition at line 79 of file bundle.hpp.
|
inlineconstexpr |
The file kinds of a manifest.
Definition at line 82 of file bundle.hpp.
|
inlineconstexpr |
The app document (spec 6 §5).
Definition at line 84 of file bundle.hpp.
|
inlineconstexpr |
A theme (ui-theme/1, spec 6 §6).
Definition at line 86 of file bundle.hpp.
|
inlineconstexpr |
A message catalogue.
Definition at line 88 of file bundle.hpp.
|
inlineconstexpr |
A delivered custom component (spec 5 §10).
Definition at line 90 of file bundle.hpp.
|
inlineconstexpr |
An icon of a theme's icon set: SVG text.
Definition at line 92 of file bundle.hpp.
|
inlineconstexpr |
The largest icon file a bundle may hold.
Definition at line 94 of file bundle.hpp.