-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Update global api #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NeaguGeorgiana23
wants to merge
30
commits into
main
Choose a base branch
from
update_global_api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
42a776d
base data structures fot hook implementation.
NeaguGeorgiana23 e968609
fix linter
NeaguGeorgiana23 334ec2a
fix linter
NeaguGeorgiana23 f110e5c
Merge branch 'main' into define-hook-data-structures
NeaguGeorgiana23 5cc878b
Update BUILD file.
NeaguGeorgiana23 bd66430
Correct include guards.
NeaguGeorgiana23 5332610
feat: Add HookData class.
NeaguGeorgiana23 c8fc92d
fix linter
NeaguGeorgiana23 3f5f4de
fix linter
NeaguGeorgiana23 b0f3a15
fix linter
NeaguGeorgiana23 e9e8852
fix linter
NeaguGeorgiana23 e333df0
add HookContext structure.
NeaguGeorgiana23 c59de28
fix linter
NeaguGeorgiana23 45ca64a
fix linter
NeaguGeorgiana23 3b93d77
add Hooks class.
NeaguGeorgiana23 a4aa1c2
fix linter.
NeaguGeorgiana23 d7cd54a
fix linter.
NeaguGeorgiana23 d6ef2c6
fix linter.
NeaguGeorgiana23 a2f7fee
fix linter.
NeaguGeorgiana23 a91afca
appli agent suggestions.
NeaguGeorgiana23 c0482f7
Merge branch 'main' into hooks
NeaguGeorgiana23 a0ca155
Merge branch 'main' into hooks
NeaguGeorgiana23 06bd51c
Add EvaluationOpton struct.
NeaguGeorgiana23 b362223
fix linter.
NeaguGeorgiana23 6942c4e
update Provider class to allow getting hooks.
NeaguGeorgiana23 49bdc17
update all classes that inharit from FeatureProvider.
NeaguGeorgiana23 dab62a0
update BUILD files and imports.
NeaguGeorgiana23 ea6a463
update GlobalAPI with hook methods.
NeaguGeorgiana23 665914a
fix linter.
NeaguGeorgiana23 0bd0f58
fix linter.
NeaguGeorgiana23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #ifndef CPP_SDK_INCLUDE_OPENFEATURE_BASE_HOOK_H_ | ||
| #define CPP_SDK_INCLUDE_OPENFEATURE_BASE_HOOK_H_ | ||
|
|
||
| namespace openfeature { | ||
|
|
||
| // Non-templated base class for all hooks. This will allow storing different | ||
| // hook types (e.g., BoolHook, | ||
| // StringHook) inside evaluation options. | ||
| class BaseHook { | ||
| public: | ||
| BaseHook() = default; | ||
| BaseHook(const BaseHook&) = delete; | ||
| BaseHook(BaseHook&&) = delete; | ||
| BaseHook& operator=(const BaseHook&) = delete; | ||
| BaseHook& operator=(BaseHook&&) = delete; | ||
| virtual ~BaseHook() = default; | ||
| }; | ||
|
|
||
| } // namespace openfeature | ||
|
|
||
| #endif // CPP_SDK_INCLUDE_OPENFEATURE_BASE_HOOK_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #ifndef CPP_SDK_INCLUDE_OPENFEATURE_EVALUATION_OPTIONS_H_ | ||
| #define CPP_SDK_INCLUDE_OPENFEATURE_EVALUATION_OPTIONS_H_ | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "openfeature/base_hook.h" | ||
| #include "openfeature/hook_hints.h" | ||
| namespace openfeature { | ||
| struct EvaluationOptions { | ||
| std::vector<std::shared_ptr<BaseHook>> hooks; | ||
| HookHints hook_hints; | ||
| }; | ||
| } // namespace openfeature | ||
| #endif // CPP_SDK_INCLUDE_OPENFEATURE_EVALUATION_OPTIONS_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include "openfeature/flag_evaluation_details.h" | ||
|
|
||
| #include <optional> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| #include "openfeature/error_code.h" | ||
| #include "openfeature/flag_metadata.h" | ||
| #include "openfeature/reason.h" | ||
| #include "openfeature/resolution_details.h" | ||
| #include "openfeature/value.h" | ||
|
|
||
| namespace openfeature { | ||
|
|
||
| template <typename T> | ||
| FlagEvaluationDetails<T>::FlagEvaluationDetails( | ||
| std::string flag_key, T value, Reason reason, | ||
| std::optional<std::string> variant, const FlagMetadata& flag_metadata, | ||
| std::optional<ErrorCode> error_code, | ||
| std::optional<std::string> error_message) | ||
| : ResolutionDetails<T>(std::move(value), reason, std::move(variant), | ||
| flag_metadata, error_code, std::move(error_message)), | ||
| flag_key_(std::move(flag_key)) {} | ||
|
|
||
| template <typename T> | ||
| FlagEvaluationDetails<T>::FlagEvaluationDetails( | ||
| std::string flag_key, const ResolutionDetails<T>& resolution_details) | ||
| : ResolutionDetails<T>(resolution_details), | ||
| flag_key_(std::move(flag_key)) {} | ||
|
|
||
| template <typename T> | ||
| std::string_view FlagEvaluationDetails<T>::GetFlagKey() const { | ||
| return flag_key_; | ||
| } | ||
|
|
||
| template class FlagEvaluationDetails<bool>; | ||
| template class FlagEvaluationDetails<std::string>; | ||
| template class FlagEvaluationDetails<int64_t>; | ||
| template class FlagEvaluationDetails<double>; | ||
| template class FlagEvaluationDetails<Value>; | ||
|
|
||
| } // namespace openfeature | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #ifndef CPP_SDK_INCLUDE_OPENFEATURE_FLAG_EVALUATION_DETAILS_H_ | ||
| #define CPP_SDK_INCLUDE_OPENFEATURE_FLAG_EVALUATION_DETAILS_H_ | ||
|
|
||
| #include <optional> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| #include "openfeature/error_code.h" | ||
| #include "openfeature/flag_metadata.h" | ||
| #include "openfeature/reason.h" | ||
| #include "openfeature/resolution_details.h" | ||
| #include "openfeature/value.h" | ||
|
|
||
| namespace openfeature { | ||
|
|
||
| template <typename T> | ||
| class FlagEvaluationDetails : public ResolutionDetails<T> { | ||
| public: | ||
| FlagEvaluationDetails( | ||
| std::string flag_key, T value, Reason reason, | ||
| std::optional<std::string> variant, const FlagMetadata& flag_metadata, | ||
| std::optional<ErrorCode> error_code = std::nullopt, | ||
| std::optional<std::string> error_message = std::nullopt); | ||
|
|
||
| FlagEvaluationDetails(std::string flag_key, | ||
| const ResolutionDetails<T>& resolution_details); | ||
|
|
||
| FlagEvaluationDetails(const FlagEvaluationDetails&) = default; | ||
| FlagEvaluationDetails& operator=(const FlagEvaluationDetails&) = default; | ||
| FlagEvaluationDetails(FlagEvaluationDetails&&) noexcept = default; | ||
| FlagEvaluationDetails& operator=(FlagEvaluationDetails&&) noexcept = default; | ||
| ~FlagEvaluationDetails() = default; | ||
| std::string_view GetFlagKey() const; | ||
|
|
||
| private: | ||
| std::string flag_key_; | ||
| }; | ||
|
|
||
| // Type aliases for common types. | ||
| using BoolFlagEvaluationDetails = FlagEvaluationDetails<bool>; | ||
| using StringFlagEvaluationDetails = FlagEvaluationDetails<std::string>; | ||
| using IntFlagEvaluationDetails = FlagEvaluationDetails<int64_t>; | ||
| using DoubleFlagEvaluationDetails = FlagEvaluationDetails<double>; | ||
| using ObjectFlagEvaluationDetails = FlagEvaluationDetails<Value>; | ||
|
|
||
| } // namespace openfeature | ||
|
|
||
| #endif // CPP_SDK_INCLUDE_OPENFEATURE_FLAG_EVALUATION_DETAILS_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #include "openfeature/hook.h" | ||
|
|
||
| namespace openfeature { | ||
|
|
||
| // Explicit template instantiations for common hook types. | ||
| template class Hook<bool>; | ||
| template class Hook<std::string>; | ||
| template class Hook<int64_t>; | ||
| template class Hook<double>; | ||
| template class Hook<Value>; | ||
|
|
||
| } // namespace openfeature |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #ifndef CPP_SDK_INCLUDE_OPENFEATURE_HOOK_H_ | ||
| #define CPP_SDK_INCLUDE_OPENFEATURE_HOOK_H_ | ||
|
|
||
| #include <cstdint> | ||
| #include <exception> | ||
| #include <optional> | ||
| #include <string> | ||
|
|
||
| #include "openfeature/base_hook.h" | ||
| #include "openfeature/evaluation_context.h" | ||
| #include "openfeature/flag_evaluation_details.h" | ||
| #include "openfeature/hook_context.h" | ||
| #include "openfeature/hook_hints.h" | ||
| #include "openfeature/value.h" | ||
|
|
||
| namespace openfeature { | ||
|
|
||
| // Hook allows application developers to add arbitrary behavior to the | ||
| // flag evaluation lifecycle. Hooks operate similarly to middleware in web | ||
| // frameworks. They are executed stack-wise with respect to flag resolution, | ||
| // prioritizing increasing specificity (API, Client, Invocation, Provider) | ||
| // first, and the order in which they were added second. | ||
| /// https://openfeature.dev/specification/sections/hooks | ||
| template <typename T> | ||
| class Hook : public BaseHook { | ||
| public: | ||
| Hook() = default; | ||
| Hook(const Hook&) = delete; | ||
| Hook& operator=(const Hook&) = delete; | ||
| Hook(Hook&&) = delete; | ||
| Hook& operator=(Hook&&) = delete; | ||
| ~Hook() override = default; | ||
|
|
||
| // Runs before the flag evaluation occurs. | ||
| virtual std::optional<EvaluationContext> Before(HookContext<T>& ctx, | ||
| const HookHints& hints) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| // Runs immediately after successful flag evaluation occurs. | ||
| virtual void After(const HookContext<T>& ctx, | ||
| const FlagEvaluationDetails<T>& details, | ||
| const HookHints& hints) {} | ||
|
|
||
| // Runs if an error occurs during flag evaluation or in `Before`/`After` | ||
| // stages. | ||
| virtual void Error(const HookContext<T>& ctx, const std::exception& error, | ||
| const HookHints& hints) {} | ||
|
|
||
| // Runs after the flag evaluation occurs, regardless of whether it was | ||
| // successful or not. | ||
| virtual void Finally(const HookContext<T>& ctx, | ||
| const FlagEvaluationDetails<T>& details, | ||
| const HookHints& hints) {} | ||
| }; | ||
|
|
||
| // Type aliases for common hook specializations. | ||
| using BoolHook = Hook<bool>; | ||
| using StringHook = Hook<std::string>; | ||
| using IntHook = Hook<int64_t>; | ||
| using DoubleHook = Hook<double>; | ||
| using ObjectHook = Hook<Value>; | ||
|
|
||
| } // namespace openfeature | ||
|
|
||
| #endif // CPP_SDK_INCLUDE_OPENFEATURE_HOOK_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: open-feature/cpp-sdk
Length of output: 575
🏁 Script executed:
sed -n '1,120p' openfeature/flag_evaluation_details.cppRepository: open-feature/cpp-sdk
Length of output: 1561
🏁 Script executed:
Repository: open-feature/cpp-sdk
Length of output: 3727
Include
<utility>forstd::move. This translation unit depends on transitive includes here; add the direct include so it stays portable.Proposed fix
`#include` <string_view> +#include <utility>📝 Committable suggestion
🤖 Prompt for AI Agents