| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #pragma once
- #include "db_gateway.hpp"
- #include "function_record.hpp"
- #include <optional>
- #include <string>
- #include <vector>
- namespace svapi {
- /// Project-scoped function registry.
- class FunctionRegistry {
- public:
- explicit FunctionRegistry(DbGateway& db);
- /// Ensure the registry collection for `project` exists (idempotent).
- void ensure(const std::string& project);
- /// Re-open every project's function collection. The database only surfaces
- /// a collection through find()/list() once it has been opened in the current
- /// process, so without this a restart leaves every registry invisible even
- /// though the data survives (same reason CollectionRegistry::bootstrap
- /// exists).
- void bootstrap(const std::vector<std::string>& projects);
- std::optional<FunctionRecord> get(const std::string& project, const std::string& functionId);
- std::vector<FunctionRecord> list(const std::string& project);
- /// Store a code push, preserving server-held policy via mergeForCodePush.
- /// Returns the record as stored.
- FunctionRecord put(const std::string& project, const FunctionRecord& incoming,
- const KeyScope& projectDefault);
- /// Replace a function's policy. Admin-only at the HTTP layer; this is the
- /// only way a policy ever changes.
- bool setPolicy(const std::string& project, const std::string& functionId,
- const KeyScope& policy);
- bool setEnabled(const std::string& project, const std::string& functionId, bool enabled);
- bool remove(const std::string& project, const std::string& functionId);
- private:
- DbGateway& db_;
- std::string coll(const std::string& project) const {
- return qualify(project, "vectorapi_functions");
- }
- };
- } // namespace svapi
|