Skip to content

Commit

Permalink
Rename ObjectStore -> KVStore
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba committed Apr 7, 2023
1 parent 0ebce7a commit cc89dba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ComputeRuntime

extension Fastly {
public struct ObjectStore: Sendable {
public struct KVStore: Sendable {

internal let handle: WasiHandle

Expand All @@ -21,7 +21,7 @@ extension Fastly {
self.name = name
}

public func lookup(_ key: String) throws -> Body? {
public func lookup(_ key: String) async throws -> Body? {
do {
var bodyHandle: WasiHandle = InvalidWasiHandle
try wasi(fastly_object_store__lookup(handle, key, key.utf8.count, &bodyHandle))
Expand All @@ -31,14 +31,14 @@ extension Fastly {
}
}

public func insert(_ key: String, body: Body) throws {
public func insert(_ key: String, body: Body) async throws {
try wasi(fastly_object_store__insert(handle, key, key.utf8.count, body.handle))
}

public func insert(_ key: String, bytes: [UInt8]) throws {
public func insert(_ key: String, bytes: [UInt8]) async throws {
var body = try Body()
try body.write(bytes)
try insert(key, body: body)
try await insert(key, body: body)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// ObjectStore.swift
// KVStore.swift
//
//
// Created by Andrew Barba on 3/31/22.
//

public struct ObjectStore: Sendable {
public struct KVStore: Sendable {

internal let store: Fastly.ObjectStore
internal let store: Fastly.KVStore

public init(name: String) throws {
store = try .init(name: name)
Expand All @@ -20,7 +20,7 @@ public struct ObjectStore: Sendable {

// MARK: - Entry

extension ObjectStore {
extension KVStore {

public struct Entry: Sendable {

Expand All @@ -30,17 +30,17 @@ extension ObjectStore {

// MARK: - Read

extension ObjectStore {
extension KVStore {

public func get(_ key: String) async throws -> Entry? {
guard let body = try store.lookup(key) else {
guard let body = try await store.lookup(key) else {
return nil
}
return .init(body: ReadableWasiBody(body))
}

public func has(_ key: String) async throws -> Bool {
switch try store.lookup(key) {
switch try await store.lookup(key) {
case .some:
return true
case .none:
Expand All @@ -51,14 +51,14 @@ extension ObjectStore {

// MARK: - Update

extension ObjectStore {
extension KVStore {

public func put(_ key: String, body: ReadableBody) async throws {
try await store.insert(key, body: body.body)
}

public func put(_ key: String, bytes: [UInt8]) async throws {
try store.insert(key, bytes: bytes)
try await store.insert(key, bytes: bytes)
}

public func put(_ key: String, data: Data) async throws {
Expand Down

0 comments on commit cc89dba

Please sign in to comment.