Skip to content

Commit a8a8edd

Browse files
authored
chore: Code cleanup and todos. (#108)
1 parent 36f56b5 commit a8a8edd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+645
-650
lines changed

apps/hello-cpp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ int main() {
100100
}
101101

102102
Client client(std::move(*config),
103-
ContextBuilder().kind("user", "ryan").build());
103+
ContextBuilder().Kind("user", "ryan").Build());
104104

105105
auto before_init = client.BoolVariationDetail("my-boolean-flag", false);
106106
// This should be the cached version from our persistence, if the

apps/sdk-contract-tests/src/client_entity.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tl::expected<nlohmann::json, std::string> ClientEntity::Identify(
3131
launchdarkly::ErrorToString(maybe_ctx.error()));
3232
}
3333

34-
if (!maybe_ctx->valid()) {
34+
if (!maybe_ctx->Valid()) {
3535
return tl::make_unexpected(maybe_ctx->errors());
3636
}
3737

@@ -41,21 +41,21 @@ tl::expected<nlohmann::json, std::string> ClientEntity::Identify(
4141

4242
static void BuildContextFromParams(launchdarkly::ContextBuilder& builder,
4343
ContextSingleParams const& single) {
44-
auto& attrs = builder.kind(single.kind.value_or("user"), single.key);
44+
auto& attrs = builder.Kind(single.kind.value_or("user"), single.key);
4545
if (single.anonymous) {
46-
attrs.anonymous(*single.anonymous);
46+
attrs.Anonymous(*single.anonymous);
4747
}
4848
if (single.name) {
49-
attrs.name(*single.name);
49+
attrs.Name(*single.name);
5050
}
5151

5252
if (single._private) {
53-
attrs.add_private_attributes(*single._private);
53+
attrs.AddPrivateAttributes(*single._private);
5454
}
5555

5656
if (single.custom) {
5757
for (auto const& [key, value] : *single.custom) {
58-
attrs.set(key, boost::json::value_to<launchdarkly::Value>(
58+
attrs.Set(key, boost::json::value_to<launchdarkly::Value>(
5959
boost::json::parse(value.dump())));
6060
}
6161
}
@@ -75,8 +75,8 @@ tl::expected<nlohmann::json, std::string> ContextBuild(
7575
BuildContextFromParams(builder, *params.single);
7676
}
7777

78-
auto ctx = builder.build();
79-
if (!ctx.valid()) {
78+
auto ctx = builder.Build();
79+
if (!ctx.Valid()) {
8080
resp.error = ctx.errors();
8181
return resp;
8282
}
@@ -105,7 +105,7 @@ tl::expected<nlohmann::json, std::string> ContextConvert(
105105
return resp;
106106
}
107107

108-
if (!maybe_ctx->valid()) {
108+
if (!maybe_ctx->Valid()) {
109109
resp.error = maybe_ctx->errors();
110110
return resp;
111111
}

libs/client-sdk/include/launchdarkly/client_side/bindings/c/sdk.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ LDClientSDK_New(LDClientConfig config, LDContext context);
3535
* Returns a boolean value indicating LaunchDarkly connection and flag state
3636
* within the client.
3737
*
38-
* [TODO Need to make WaitForReadyAsync, offline]
3938
* When you first start the client, once WaitForReadySync has returned or
4039
* WaitForReadyAsync has completed, Initialized should return true if
4140
* and only if either 1. it connected to LaunchDarkly and successfully

libs/client-sdk/include/launchdarkly/client_side/client.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class IClient {
2525
* Returns a boolean value indicating LaunchDarkly connection and flag state
2626
* within the client.
2727
*
28-
* [TODO Need to make WaitForReadyAsync, offline]
2928
* When you first start the client, once WaitForReadySync has returned or
3029
* WaitForReadyAsync has completed, Initialized should return true if
3130
* and only if either 1. it connected to LaunchDarkly and successfully

libs/client-sdk/src/client_impl.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ std::unordered_map<Client::FlagKey, Value> ClientImpl::AllFlags() const {
159159
std::unordered_map<Client::FlagKey, Value> result;
160160
for (auto& [key, descriptor] : flag_manager_.Store().GetAll()) {
161161
if (descriptor->flag) {
162-
result.try_emplace(key, descriptor->flag->detail().value());
162+
result.try_emplace(key, descriptor->flag->Detail().Value());
163163
}
164164
}
165165
return result;
@@ -171,7 +171,7 @@ void ClientImpl::TrackInternal(std::string event_name,
171171
event_processor_->SendAsync(events::TrackEventParams{
172172
std::chrono::system_clock::now(), std::move(event_name),
173173
ReadContextSynchronized(
174-
[](Context const& c) { return c.kinds_to_keys(); }),
174+
[](Context const& c) { return c.KindsToKeys(); }),
175175
std::move(data), metric_value});
176176
}
177177

@@ -269,10 +269,10 @@ EvaluationDetail<T> ClientImpl::VariationInternal(FlagKey const& key,
269269
assert(desc->flag);
270270

271271
auto const& flag = *(desc->flag);
272-
auto const& detail = flag.detail();
272+
auto const& detail = flag.Detail();
273273

274274
if (check_type && default_value.Type() != Value::Type::kNull &&
275-
detail.value().Type() != default_value.Type()) {
275+
detail.Value().Type() != default_value.Type()) {
276276
auto error_reason =
277277
EvaluationReason(EvaluationReason::ErrorKind::kWrongType);
278278
if (eval_reasons_available_) {
@@ -282,23 +282,23 @@ EvaluationDetail<T> ClientImpl::VariationInternal(FlagKey const& key,
282282
return EvaluationDetail<T>(default_value, std::nullopt, error_reason);
283283
}
284284

285-
event.value = detail.value();
286-
event.variation = detail.variation_index();
285+
event.value = detail.Value();
286+
event.variation = detail.VariationIndex();
287287

288-
if (detailed || flag.track_reason()) {
289-
event.reason = detail.reason();
288+
if (detailed || flag.TrackReason()) {
289+
event.reason = detail.Reason();
290290
}
291291

292-
event.version = flag.flag_version().value_or(flag.version());
293-
event.require_full_event = flag.track_events();
294-
if (auto date = flag.debug_events_until_date()) {
292+
event.version = flag.FlagVersion().value_or(flag.Version());
293+
event.require_full_event = flag.TrackEvents();
294+
if (auto date = flag.DebugEventsUntilDate()) {
295295
event.debug_events_until_date = events::Date{*date};
296296
}
297297

298298
event_processor_->SendAsync(std::move(event));
299299

300-
return EvaluationDetail<T>(detail.value(), detail.variation_index(),
301-
detail.reason());
300+
return EvaluationDetail<T>(detail.Value(), detail.VariationIndex(),
301+
detail.Reason());
302302
}
303303

304304
EvaluationDetail<bool> ClientImpl::BoolVariationDetail(

libs/client-sdk/src/data_sources/data_source_update_sink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ std::ostream& operator<<(std::ostream& out, ItemDescriptor const& descriptor) {
1919
ItemDescriptor::ItemDescriptor(uint64_t version) : version(version) {}
2020

2121
ItemDescriptor::ItemDescriptor(EvaluationResult flag)
22-
: version(flag.version()), flag(std::move(flag)) {}
22+
: version(flag.Version()), flag(std::move(flag)) {}
2323
} // namespace launchdarkly::client_side

libs/client-sdk/src/flag_manager/flag_persistence.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ void FlagPersistence::Init(
3939
Context const& context,
4040
std::unordered_map<std::string, ItemDescriptor> data) {
4141
sink_.Init(context, std::move(data));
42-
StoreCache(PersistenceEncodeKey(context.canonical_key()));
42+
StoreCache(PersistenceEncodeKey(context.CanonicalKey()));
4343
}
4444

4545
void FlagPersistence::Upsert(Context const& context,
4646
std::string key,
4747
ItemDescriptor item) {
4848
sink_.Upsert(context, key, item);
49-
StoreCache(PersistenceEncodeKey(context.canonical_key()));
49+
StoreCache(PersistenceEncodeKey(context.CanonicalKey()));
5050
}
5151

5252
void FlagPersistence::LoadCached(Context const& context) {
53-
if (!persistence_ || !context.valid()) {
53+
if (!persistence_ || !context.Valid()) {
5454
return;
5555
}
5656

5757
std::lock_guard lock(persistence_mutex_);
5858
auto data = persistence_->Read(
59-
environment_namespace_, PersistenceEncodeKey(context.canonical_key()));
59+
environment_namespace_, PersistenceEncodeKey(context.CanonicalKey()));
6060

6161
if (!data) {
6262
return;

libs/client-sdk/src/flag_manager/flag_updater.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Value GetValue(ItemDescriptor& descriptor) {
1111
if (descriptor.flag) {
1212
// `flag->` unwraps the first optional we know is present.
1313
// The second `value()` is not an optional.
14-
return descriptor.flag->detail().value();
14+
return descriptor.flag->Detail().Value();
1515
}
1616
return {};
1717
}
@@ -103,7 +103,7 @@ void FlagUpdater::Upsert(Context const& context,
103103
FlagValueChangeEvent(key, GetValue(item), GetValue(*existing)));
104104
} else if (item.flag) {
105105
DispatchEvent(FlagValueChangeEvent(
106-
key, item.flag.value().detail().value(), Value()));
106+
key, item.flag.value().Detail().Value(), Value()));
107107
// new flag
108108
} else if (existing && existing->flag.has_value()) {
109109
// Existed and deleted.

libs/client-sdk/tests/client_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ TEST(ClientTest, ClientConstructedWithMinimalConfigAndContext) {
1010
tl::expected<Config, Error> config = ConfigBuilder("sdk-123").Build();
1111
ASSERT_TRUE(config);
1212

13-
Context context = ContextBuilder().kind("cat", "shadow").build();
13+
Context context = ContextBuilder().Kind("cat", "shadow").Build();
1414

1515
Client client(std::move(*config), context);
1616
}
1717

1818
TEST(ClientTest, AllFlagsIsEmpty) {
1919
Client client(ConfigBuilder("sdk-123").Build().value(),
20-
ContextBuilder().kind("cat", "shadow").build());
20+
ContextBuilder().Kind("cat", "shadow").Build());
2121

2222
ASSERT_TRUE(client.AllFlags().empty());
2323
}
2424

2525
TEST(ClientTest, BoolVariationDefaultPassesThrough) {
2626
Client client(ConfigBuilder("sdk-123").Build().value(),
27-
ContextBuilder().kind("cat", "shadow").build());
27+
ContextBuilder().Kind("cat", "shadow").Build());
2828

2929
const std::string flag = "extra-cat-food";
3030
std::vector<bool> values = {true, false};
@@ -36,7 +36,7 @@ TEST(ClientTest, BoolVariationDefaultPassesThrough) {
3636

3737
TEST(ClientTest, StringVariationDefaultPassesThrough) {
3838
Client client(ConfigBuilder("sdk-123").Build().value(),
39-
ContextBuilder().kind("cat", "shadow").build());
39+
ContextBuilder().Kind("cat", "shadow").Build());
4040
const std::string flag = "treat";
4141
std::vector<std::string> values = {"chicken", "fish", "cat-grass"};
4242
for (auto const& v : values) {
@@ -47,7 +47,7 @@ TEST(ClientTest, StringVariationDefaultPassesThrough) {
4747

4848
TEST(ClientTest, IntVariationDefaultPassesThrough) {
4949
Client client(ConfigBuilder("sdk-123").Build().value(),
50-
ContextBuilder().kind("cat", "shadow").build());
50+
ContextBuilder().Kind("cat", "shadow").Build());
5151
const std::string flag = "weight";
5252
std::vector<int> values = {0, 12, 13, 24, 1000};
5353
for (auto const& v : values) {
@@ -58,7 +58,7 @@ TEST(ClientTest, IntVariationDefaultPassesThrough) {
5858

5959
TEST(ClientTest, DoubleVariationDefaultPassesThrough) {
6060
Client client(ConfigBuilder("sdk-123").Build().value(),
61-
ContextBuilder().kind("cat", "shadow").build());
61+
ContextBuilder().Kind("cat", "shadow").Build());
6262
const std::string flag = "weight";
6363
std::vector<double> values = {0.0, 12.0, 13.0, 24.0, 1000.0};
6464
for (auto const& v : values) {
@@ -69,7 +69,7 @@ TEST(ClientTest, DoubleVariationDefaultPassesThrough) {
6969

7070
TEST(ClientTest, JsonVariationDefaultPassesThrough) {
7171
Client client(ConfigBuilder("sdk-123").Build().value(),
72-
ContextBuilder().kind("cat", "shadow").build());
72+
ContextBuilder().Kind("cat", "shadow").Build());
7373

7474
const std::string flag = "assorted-values";
7575
std::vector<Value> values = {

libs/client-sdk/tests/data_source_event_handler_test.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TEST(StreamingDataHandlerTests, HandlesPutMessage) {
3636
auto test_handler = TestHandler();
3737
DataSourceStatusManager status_manager;
3838
DataSourceEventHandler stream_handler(
39-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
39+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
4040
status_manager);
4141

4242
auto res = stream_handler.HandleMessage(
@@ -57,7 +57,7 @@ TEST(StreamingDataHandlerTests, HandlesEmptyPutMessage) {
5757
auto test_handler = TestHandler();
5858
DataSourceStatusManager status_manager;
5959
DataSourceEventHandler stream_handler(
60-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
60+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
6161
status_manager);
6262

6363
auto res = stream_handler.HandleMessage("put", "{}");
@@ -73,7 +73,7 @@ TEST(StreamingDataHandlerTests, BadJsonPut) {
7373
auto test_handler = TestHandler();
7474
DataSourceStatusManager status_manager;
7575
DataSourceEventHandler stream_handler(
76-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
76+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
7777
status_manager);
7878

7979
auto res = stream_handler.HandleMessage("put", "{sorry");
@@ -87,7 +87,7 @@ TEST(StreamingDataHandlerTests, BadSchemaPut) {
8787
auto test_handler = TestHandler();
8888
DataSourceStatusManager status_manager;
8989
DataSourceEventHandler stream_handler(
90-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
90+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
9191
status_manager);
9292

9393
auto res = stream_handler.HandleMessage("put", "{\"potato\": {}}");
@@ -101,7 +101,7 @@ TEST(StreamingDataHandlerTests, HandlesPatchMessage) {
101101
auto test_handler = TestHandler();
102102
DataSourceStatusManager status_manager;
103103
DataSourceEventHandler stream_handler(
104-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
104+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
105105
status_manager);
106106

107107
auto res = stream_handler.HandleMessage(
@@ -122,7 +122,7 @@ TEST(StreamingDataHandlerTests, BadJsonPatch) {
122122
auto test_handler = TestHandler();
123123
DataSourceStatusManager status_manager;
124124
DataSourceEventHandler stream_handler(
125-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
125+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
126126
status_manager);
127127

128128
auto res = stream_handler.HandleMessage("patch", "{sorry");
@@ -136,7 +136,7 @@ TEST(StreamingDataHandlerTests, BadSchemaPatch) {
136136
auto test_handler = TestHandler();
137137
DataSourceStatusManager status_manager;
138138
DataSourceEventHandler stream_handler(
139-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
139+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
140140
status_manager);
141141

142142
auto res = stream_handler.HandleMessage("patch", R"({"potato": {}})");
@@ -150,7 +150,7 @@ TEST(StreamingDataHandlerTests, HandlesDeleteMessage) {
150150
auto test_handler = TestHandler();
151151
DataSourceStatusManager status_manager;
152152
DataSourceEventHandler stream_handler(
153-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
153+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
154154
status_manager);
155155

156156
auto res = stream_handler.HandleMessage("delete",
@@ -168,7 +168,7 @@ TEST(StreamingDataHandlerTests, BadJsonDelete) {
168168
auto test_handler = TestHandler();
169169
DataSourceStatusManager status_manager;
170170
DataSourceEventHandler stream_handler(
171-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
171+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
172172
status_manager);
173173

174174
auto res = stream_handler.HandleMessage("delete", "{sorry");
@@ -182,7 +182,7 @@ TEST(StreamingDataHandlerTests, BadSchemaDelete) {
182182
auto test_handler = TestHandler();
183183
DataSourceStatusManager status_manager;
184184
DataSourceEventHandler stream_handler(
185-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
185+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
186186
status_manager);
187187

188188
auto res = stream_handler.HandleMessage("delete", R"({"potato": {}})");
@@ -196,7 +196,7 @@ TEST(StreamingDataHandlerTests, UnrecognizedVerb) {
196196
auto test_handler = TestHandler();
197197
DataSourceStatusManager status_manager;
198198
DataSourceEventHandler stream_handler(
199-
ContextBuilder().kind("user", "user-key").build(), test_handler, logger,
199+
ContextBuilder().Kind("user", "user-key").Build(), test_handler, logger,
200200
status_manager);
201201

202202
auto res = stream_handler.HandleMessage("potato", R"({"potato": {}})");

0 commit comments

Comments
 (0)