12#include <asio/awaitable.hpp>
22namespace neograph::program {
24enum class ModuleLifecycle : std::uint8_t {
31NEOGRAPH_PROGRAM_API std::string_view to_string(ModuleLifecycle state)
noexcept;
32NEOGRAPH_PROGRAM_API ModuleLifecycle module_lifecycle_from_string(std::string_view value);
37 ContractRecord contract;
39 bool operator==(
const ModulePort&)
const =
default;
45 std::string program_version_id;
46 std::vector<ModulePort> inputs;
47 std::vector<ModulePort> outputs;
48 std::vector<std::string> required_capabilities;
49 std::vector<std::string> required_effects;
60struct ProgramModuleData {
61 std::string owner_scope;
63 std::string attestation_id;
64 ModuleLifecycle lifecycle = ModuleLifecycle::Active;
65 std::vector<ModuleCoordinate> dependencies;
71 std::optional<std::string> pure_javascript_source;
72 std::vector<ChildProgramDescriptor> children;
73 std::vector<std::string> allowed_capabilities;
74 std::vector<std::string> declared_effects;
84 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
89 const std::string& owner_scope()
const noexcept;
91 const std::string& attestation_id()
const noexcept;
92 ModuleLifecycle lifecycle()
const noexcept;
93 const std::vector<ModuleCoordinate>& dependencies()
const noexcept;
94 const std::vector<ChildProgramDescriptor>& children()
const noexcept;
95 const std::optional<std::string>& pure_javascript_source()
const noexcept;
96 const std::vector<std::string>& allowed_capabilities()
const noexcept;
97 const std::vector<std::string>& declared_effects()
const noexcept;
98 const std::string& id()
const noexcept;
99 std::string serialize_canonical()
const;
106 std::shared_ptr<const Impl> impl_;
113 std::vector<ProgramModule> modules;
114 std::vector<DependencyReceipt> receipts;
116 std::string dependency_merkle_root()
const;
117 std::vector<ImportRef> imports()
const;
118 std::vector<ModuleCoordinate> coordinates()
const;
137 std::optional<ModuleCoordinate> resolve(std::string_view source_id)
const;
141 std::unique_ptr<Impl> impl_;
146 std::string child_name;
147 ProgramBundle bundle;
148 ProgramVersion version;
155 std::vector<ChildProgramBinding> children;
176 std::string owner_scope;
177 std::string parent_module_id;
178 std::string dependency_merkle_root;
179 std::string child_name;
180 std::string child_program_version_id;
181 std::string child_bundle_id;
182 std::string child_input_contract_fingerprint;
183 std::string child_output_contract_fingerprint;
184 std::vector<std::string> granted_capabilities;
185 std::vector<std::string> granted_effects;
190class NEOGRAPH_PROGRAM_API ModuleLinkReceipt final {
192 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
195 static ModuleLinkReceipt parse(std::string_view stored_bytes);
197 const std::string& owner_scope() const noexcept;
198 const std::
string& parent_module_id() const noexcept;
199 const std::
string& dependency_merkle_root() const noexcept;
200 const std::
string& child_name() const noexcept;
201 const std::
string& child_program_version_id() const noexcept;
202 const std::
string& child_bundle_id() const noexcept;
203 const std::
string& child_input_contract_fingerprint() const noexcept;
204 const std::
string& child_output_contract_fingerprint() const noexcept;
205 const std::vector<std::
string>& granted_capabilities() const noexcept;
206 const std::vector<std::
string>& granted_effects() const noexcept;
207 const BudgetLimits& budget() const noexcept;
209 const std::
string&
id() const noexcept;
210 std::
string serialize_canonical() const;
214 explicit ModuleLinkReceipt(std::shared_ptr<const Impl> impl);
216 std::shared_ptr<const Impl> impl_;
221 ModuleLinkReceipt receipt;
222 ProgramVersion version;
225using ProgramChildBindingResolver = std::function<std::optional<ProgramRuntimeChildBinding>(
226 std::string_view owner_scope,
227 std::string_view parent_program_version_id,
228 std::string_view child_binding_name)>;
238 std::string_view child_name,
239 const ProgramBundle& child_bundle,
240 const ProgramVersion& child);
250 [[nodiscard]]
virtual asio::awaitable<void> publish(
const ProgramModule& module) = 0;
251 [[nodiscard]]
virtual asio::awaitable<std::optional<ProgramModule>> get(
252 std::string_view content_identity)
const = 0;
254 [[nodiscard]]
virtual asio::awaitable<std::optional<ProgramModule>>
get(
255 std::string_view owner_scope,
256 std::string_view content_identity)
const {
257 if (owner_scope.empty())
co_return std::nullopt;
258 const auto module = co_await get(content_identity);
259 if (!module || module->owner_scope() != owner_scope)
co_return std::nullopt;
262 [[nodiscard]]
virtual asio::awaitable<void> set_lifecycle(
263 std::string_view content_identity,
264 ModuleLifecycle lifecycle) = 0;
275 virtual std::optional<ProgramModule> get_sync(std::string_view content_identity)
const = 0;
276 virtual std::optional<ProgramModule> get_sync(
277 std::string_view owner_scope,
278 std::string_view content_identity)
const {
279 if (owner_scope.empty())
return std::nullopt;
280 const auto module = get_sync(content_identity);
281 if (!module || module->owner_scope() != owner_scope)
return std::nullopt;
284 virtual void set_lifecycle_sync(std::string_view content_identity, ModuleLifecycle lifecycle) = 0;
288 [[nodiscard]] asio::awaitable<void> publish(
const ProgramModule& module)
final;
289 [[nodiscard]] asio::awaitable<std::optional<ProgramModule>> get(std::string_view content_identity)
const final;
290 [[nodiscard]] asio::awaitable<std::optional<ProgramModule>>
get(
291 std::string_view owner_scope,
292 std::string_view content_identity)
const final;
293 [[nodiscard]] asio::awaitable<void> set_lifecycle(
294 std::string_view content_identity,
295 ModuleLifecycle lifecycle)
final;
302 virtual bool offloads() const noexcept {
return false; }
315 const std::shared_ptr<ModuleStore>& store() const noexcept {
return store_; }
317 void publish(
const ProgramModule& module)
const;
318 std::optional<ProgramModule> get(std::string_view content_identity)
const;
319 std::optional<ProgramModule> get(
320 std::string_view owner_scope,
321 std::string_view content_identity)
const;
322 void set_lifecycle(std::string_view content_identity, ModuleLifecycle lifecycle)
const;
325 std::shared_ptr<ModuleStore> store_;
326 SyncModuleStore* sync_ =
nullptr;
327 BlockingStorePolicy policy_;
341 std::optional<ProgramModule> get_sync(std::string_view content_identity)
const override;
342 std::optional<ProgramModule> get_sync(std::string_view owner_scope,
343 std::string_view content_identity)
const override;
344 void set_lifecycle_sync(std::string_view content_identity, ModuleLifecycle lifecycle)
override;
348 std::unique_ptr<Impl> impl_;
357 explicit ModuleResolver(std::shared_ptr<const ModuleStore> store);
360 const PolicySnapshot& policy)
const;
366 std::shared_ptr<const ModuleStore> store_;
367 bool synchronous_ =
false;
Immutable Program admission and policy snapshots.
ExecutionGuarantee
The lowest recoverability/integrity class reachable through an executable closure.
A ModuleStore for a caller that cannot suspend.
BlockingModuleStore(ModuleStore &store, BlockingStorePolicy policy={})
A view of a store that outlives it.
Small durable-boundary-compatible store used by the in-process resolver.
Resolves exact, pinned modules.
asio::awaitable< ModuleResolution > resolve_async(ModuleCoordinate root, PolicySnapshot policy) const
The same resolution, awaiting the module store; the arguments are taken by value.
The store of sealed Program modules, as the catalog uses it (#556).
virtual asio::awaitable< std::optional< ProgramModule > > get(std::string_view owner_scope, std::string_view content_identity) const
Wrong-owner module lookups are indistinguishable from absence.
Immutable module metadata.
Base of a ModuleStore whose backend is synchronous.
virtual bool offloads() const noexcept
True for a backend that blocks for long: each operation then runs on a pool thread.
asio::awaitable< std::optional< ProgramModule > > get(std::string_view owner_scope, std::string_view content_identity) const final
Wrong-owner module lookups are indistinguishable from absence.
bool completes_at_once() const noexcept
True when every awaitable operation completes at once on the calling thread, not on a pool thread.
Immutable allowlist view over a verified ModuleResolution.
Immutable content-addressed coordinates for reusable Program modules.
NEOGRAPH_PROGRAM_API ModuleLinkReceipt link_module_child(const ModuleResolution &resolution, const ProgramModule &parent, std::string_view child_name, const ProgramBundle &child_bundle, const ProgramVersion &child)
Link one child descriptor from a verified module closure to an exact admitted ProgramVersion.
NEOGRAPH_PROGRAM_API void validate_program_composition(const ProgramBundle &parent_bundle, const ProgramComposition &composition)
Validate the whole composed Program before any GraphEngine materialization.
NEOGRAPH_PROGRAM_API void validate_module_resolution(const ModuleResolution &resolution)
Validate a resolver-produced closure, including its pinned graph and receipts.
How a Program store call is awaited, and how a synchronous caller waits for one (#556).
When a Blocking...Store may wait for a store call that does not complete at once.
A child version and its immutable bundle, paired before dispatch.
Child authority and budget are a strict attenuation of the parent module.
ExecutionGuarantee minimum_execution_guarantee
Weakest child guarantee the parent explicitly accepts.
Exact module address; the content identity is never selected by a range.
Immutable proof that one child descriptor was linked to one exact admitted Program version.
Result of resolving one module and its complete pinned dependency closure.
Complete pre-dispatch composition proof for one parent Program.
Runtime-only immutable child binding supplied by an owning resolver.
Immutable stored binding between a Program bundle and admission receipts.