#pragma once // Query strings. `Query` is an ordered, validated, percent-encoded parameter // list; `ListOptions` is the id-cursor paging every list call shares. // Array filters repeat the name ("project_ids=a&project_ids=b", the form the // OpenAPI document declares); names that the spec spells with brackets // ("project_ids[]" on audit logs) are passed with the brackets. #include #include #include #include #include #include "openai/admin/calls.h" namespace molo::openai::admin { class Query { public: Query& set(const std::string& name, const std::string& value); Query& set_int(const std::string& name, std::int64_t value); Query& set_bool(const std::string& name, bool value); // One "name=value" pair per entry; entries are capped. Query& add_all(const std::string& name, const std::vector& values); bool empty() const { return pairs_.empty(); } std::size_t size() const { return pairs_.size(); } const std::vector>& pairs() const { return pairs_; } bool has(const std::string& name) const; // Throws unless every name is a query parameter of the call (table). void check_against(Call call) const; // "?a=1&b=2" or "" (percent-encoded, deterministic order of insertion). std::string encoded() const; static std::string escape(const std::string& text); private: std::vector> pairs_; }; // limit / after / before / order of the id-cursor lists. Which of them a call // takes is decided by the call table; sending one the call lacks throws. struct ListOptions { std::optional limit; // 1..100 std::string after; std::string before; std::string order; // "asc" or "desc" Query to_query() const; }; } // namespace molo::openai::admin