ores.cpp.history-provider-registrar.history_provider_registrar_implementation

Table of Contents

Per-entity history-provider registrar implementation. Defines register_<entity>_history_provider() which registers the entity's history provider under the product.component.entity_singular key. The provider body constructs the entity's service from the scoped context, reads the entity's version history through the service, and renders each version through the presentation mapper, via ores::history::service::build_entity_history_versions().

Each entity's registrar includes only that entity's service and mapper headers, so a compile failure in one entity's provider cannot block the rest of the service.

A compound-key entity emits a registrar with an empty body. Its rows have no single-string id on the history_provider interface, so nothing can be registered until a composite-key representation exists. The direct service call carries the full key.

Model inputs consumed by this template:

The product, component, and entity_singular composition mirrors the SQL create trigger verbatim, so the server-side provider key and the row-change side of the history pipeline can never drift out of sync.

See the Template variable reference for the complete list of available variables and their semantics.

1. Template

The full template source. Edit here and re-tangle with compass build --direct tangle_codegen_templates to regenerate library/templates/cpp_history_provider_registrar.cpp.mustache.

{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/ores.cpp.history-provider-registrar.history_provider_registrar_implementation.org. Edit the org source. }}
{{{cpp_license}}}
{{#domain_entity}}
#include "ores.{{component_core}}/messaging/{{entity_singular}}_history_provider_registrar.hpp"
{{^primary_key.is_compound}}
#include "ores.{{component_core}}/presentation/{{entity_singular}}_history_field_mapper.hpp"
#include "ores.{{component_core}}/service/{{entity_singular}}_service.hpp"
#include "ores.history.api/service/version_builder.hpp"
{{/primary_key.is_compound}}

namespace ores::{{component}}::messaging {

void register_{{entity_singular}}_history_provider(
    ores::history::service::dispatch_registry& registry) {
{{#primary_key.is_compound}}
    // A compound-key row has no single-string id on the history_provider
    // interface, so nothing is registered for it yet. The direct service
    // call carries the full key; a provider shape is a composite-key
    // representation decision that stays open until a consumer exists.
    (void)registry;
{{/primary_key.is_compound}}
{{^primary_key.is_compound}}
    registry.register_history_provider(
        "{{product}}.{{component}}.{{entity_singular}}",
        [](const ores::database::context& scoped_ctx, const std::string& entity_id) {
            service::{{entity_singular}}_service svc(scoped_ctx);
            auto versions = svc.get_{{entity_singular_short}}_history(entity_id);
            return ores::history::service::build_entity_history_versions(
                versions, presentation::render_{{entity_singular}}_fields);
        });
{{/primary_key.is_compound}}
}

} // namespace ores::{{component}}::messaging
{{/domain_entity}}

2. See also

Emacs 29.3 (Org mode 9.6.15)