Skip to content

Commit 4aaae63

Browse files
Jake ChampionJakeChampion
authored andcommitted
add host_api implementation for kvstore delete functionality
1 parent 1cc43d7 commit 4aaae63

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

runtime/js-compute-runtime/host_interface/host_api.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,21 @@ Result<AsyncHandle> ObjectStore::lookup_async(std::string_view name) {
11631163
return res;
11641164
}
11651165

1166+
Result<AsyncHandle> ObjectStore::delete_async(std::string_view name) {
1167+
Result<AsyncHandle> res;
1168+
1169+
auto name_str = string_view_to_world_string(name);
1170+
fastly_compute_at_edge_object_store_pending_handle_t ret;
1171+
fastly_compute_at_edge_types_error_t err;
1172+
if (!fastly_compute_at_edge_object_store_delete_async(this->handle, &name_str, &ret, &err)) {
1173+
res.emplace_err(err);
1174+
} else {
1175+
res.emplace(ret);
1176+
}
1177+
1178+
return res;
1179+
}
1180+
11661181
Result<Void> ObjectStore::insert(std::string_view name, HttpBody body) {
11671182
Result<Void> res;
11681183

@@ -1195,6 +1210,21 @@ Result<std::optional<HttpBody>, FastlyError> ObjectStorePendingLookup::wait() {
11951210

11961211
AsyncHandle ObjectStorePendingLookup::async_handle() const { return AsyncHandle{this->handle}; }
11971212

1213+
Result<Void> ObjectStorePendingDelete::wait() {
1214+
Result<Void> res;
1215+
1216+
fastly_compute_at_edge_types_error_t err;
1217+
if (!fastly_compute_at_edge_object_store_pending_delete_wait(this->handle, &err)) {
1218+
res.emplace_err(err);
1219+
} else {
1220+
res.emplace(Void{});
1221+
}
1222+
1223+
return res;
1224+
}
1225+
1226+
AsyncHandle ObjectStorePendingDelete::async_handle() const { return AsyncHandle{this->handle}; }
1227+
11981228
static_assert(std::is_same_v<Secret::Handle, fastly_compute_at_edge_secret_store_secret_handle_t>);
11991229
static_assert(
12001230
std::is_same_v<SecretStore::Handle, fastly_compute_at_edge_secret_store_store_handle_t>);

runtime/js-compute-runtime/host_interface/host_api.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ class ObjectStore final {
601601

602602
Result<std::optional<HttpBody>> lookup(std::string_view name);
603603
Result<AsyncHandle> lookup_async(std::string_view name);
604+
Result<AsyncHandle> delete_async(std::string_view name);
604605

605606
Result<Void> insert(std::string_view name, HttpBody body);
606607
};
@@ -624,6 +625,25 @@ class ObjectStorePendingLookup final {
624625
AsyncHandle async_handle() const;
625626
};
626627

628+
class ObjectStorePendingDelete final {
629+
public:
630+
using Handle = uint32_t;
631+
632+
static constexpr Handle invalid = UINT32_MAX - 1;
633+
634+
Handle handle = invalid;
635+
636+
ObjectStorePendingDelete() = default;
637+
explicit ObjectStorePendingDelete(Handle handle) : handle{handle} {}
638+
explicit ObjectStorePendingDelete(AsyncHandle async) : handle{async.handle} {}
639+
640+
/// Block until the response is ready.
641+
Result<Void> wait();
642+
643+
/// Fetch the AsyncHandle for this pending request.
644+
AsyncHandle async_handle() const;
645+
};
646+
627647
class Secret final {
628648
public:
629649
using Handle = uint32_t;

0 commit comments

Comments
 (0)