diff --git a/Sources/Compute/Fastly/FastlyObjectStore.swift b/Sources/Compute/Fastly/FastlyKVStore.swift similarity index 76% rename from Sources/Compute/Fastly/FastlyObjectStore.swift rename to Sources/Compute/Fastly/FastlyKVStore.swift index 62965fd3..0f2f881e 100644 --- a/Sources/Compute/Fastly/FastlyObjectStore.swift +++ b/Sources/Compute/Fastly/FastlyKVStore.swift @@ -8,7 +8,7 @@ import ComputeRuntime extension Fastly { - public struct ObjectStore: Sendable { + public struct KVStore: Sendable { internal let handle: WasiHandle @@ -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)) @@ -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) } } } diff --git a/Sources/Compute/ObjectStore.swift b/Sources/Compute/KVStore.swift similarity index 84% rename from Sources/Compute/ObjectStore.swift rename to Sources/Compute/KVStore.swift index a27994d4..9d49e74e 100644 --- a/Sources/Compute/ObjectStore.swift +++ b/Sources/Compute/KVStore.swift @@ -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) @@ -20,7 +20,7 @@ public struct ObjectStore: Sendable { // MARK: - Entry -extension ObjectStore { +extension KVStore { public struct Entry: Sendable { @@ -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: @@ -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 {