10#include <reusex/core/ProjectDB.hpp>
47 virtual void set(
const std::vector<PathComponent> &components,
56 virtual void del(
const std::vector<PathComponent> &components) = 0;
66 virtual std::vector<std::string>
list()
const = 0;
76 if (index < 0 || index >=
static_cast<int>(items.size())) {
83 std::shared_ptr<reusex::ProjectDB>
db_;
106 std::shared_ptr<reusex::ProjectDB> db_;
107 std::map<std::string, std::unique_ptr<ResourceRouter>> routers_;
117std::vector<std::vector<PathComponent>>
Base interface for resource routers.
virtual ~ResourceRouter()=default
virtual void set(const std::vector< PathComponent > &components, const DataPayload &data)=0
Set resource data at the given path.
ResourceRouter(std::shared_ptr< reusex::ProjectDB > db)
virtual void del(const std::vector< PathComponent > &components)=0
Delete resource at the given path.
virtual DataPayload get(const std::vector< PathComponent > &components)=0
Get resource data at the given path.
virtual std::vector< std::string > list() const =0
List all items in this collection.
std::optional< std::string > resolve_index(int index) const
Resolve array index to item name/id.
std::shared_ptr< reusex::ProjectDB > db_
ResourceRouter & get_router(std::string_view collection)
Get router for a collection.
RouterRegistry(std::shared_ptr< reusex::ProjectDB > db)
Create routers for all resource types.
std::vector< std::vector< PathComponent > > expand_wildcards(const std::vector< PathComponent > &components, ResourceRouter &router)
Helper to expand wildcards in path components.
std::variant< std::string, std::vector< uint8_t >, nlohmann::json > DataPayload
Data payload that can be returned by routers.