function_registry.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include "db_gateway.hpp"
  3. #include "function_record.hpp"
  4. #include <optional>
  5. #include <string>
  6. #include <vector>
  7. namespace svapi {
  8. /// Project-scoped function registry.
  9. class FunctionRegistry {
  10. public:
  11. explicit FunctionRegistry(DbGateway& db);
  12. /// Ensure the registry collection for `project` exists (idempotent).
  13. void ensure(const std::string& project);
  14. /// Re-open every project's function collection. The database only surfaces
  15. /// a collection through find()/list() once it has been opened in the current
  16. /// process, so without this a restart leaves every registry invisible even
  17. /// though the data survives (same reason CollectionRegistry::bootstrap
  18. /// exists).
  19. void bootstrap(const std::vector<std::string>& projects);
  20. std::optional<FunctionRecord> get(const std::string& project, const std::string& functionId);
  21. std::vector<FunctionRecord> list(const std::string& project);
  22. /// Store a code push, preserving server-held policy via mergeForCodePush.
  23. /// Returns the record as stored.
  24. FunctionRecord put(const std::string& project, const FunctionRecord& incoming,
  25. const KeyScope& projectDefault);
  26. /// Replace a function's policy. Admin-only at the HTTP layer; this is the
  27. /// only way a policy ever changes.
  28. bool setPolicy(const std::string& project, const std::string& functionId,
  29. const KeyScope& policy);
  30. bool setEnabled(const std::string& project, const std::string& functionId, bool enabled);
  31. bool remove(const std::string& project, const std::string& functionId);
  32. private:
  33. DbGateway& db_;
  34. std::string coll(const std::string& project) const {
  35. return qualify(project, "vectorapi_functions");
  36. }
  37. };
  38. } // namespace svapi