projection.hpp 897 B

123456789101112131415161718192021222324252627
  1. #pragma once
  2. #include <nlohmann/json.hpp>
  3. #include <string>
  4. #include <vector>
  5. namespace smartbotic::database {
  6. /**
  7. * Apply view projection (include/exclude) to a document.
  8. *
  9. * Semantics:
  10. * - include non-empty: only those paths are kept (exclude ignored)
  11. * - include empty, exclude non-empty: all fields except excluded paths
  12. * - both empty: document returned unchanged
  13. *
  14. * Paths use dot notation: "user.profile.name". Stops at arrays.
  15. * Missing intermediate paths are silently skipped.
  16. *
  17. * Metadata fields (_id, _version, _created_at, _updated_at, _created_by, _updated_by)
  18. * are always preserved regardless of include/exclude.
  19. */
  20. nlohmann::json applyProjection(const nlohmann::json& document,
  21. const std::vector<std::string>& include,
  22. const std::vector<std::string>& exclude);
  23. } // namespace smartbotic::database