From 8d783660c42976a92242ea57d5e57254e717971d Mon Sep 17 00:00:00 2001 From: jbhusson <jonah@elixxir.io> Date: Wed, 7 Jun 2023 17:04:44 -0400 Subject: [PATCH] Use reduced interface in impl --- indexedDb/impl/state/callbacks.go | 4 ++-- indexedDb/impl/state/init.go | 3 +-- indexedDb/impl/utils.go | 7 +++++++ indexedDb/worker/state/init.go | 11 +++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/indexedDb/impl/state/callbacks.go b/indexedDb/impl/state/callbacks.go index 0cd6ab2f..73dbc2a5 100644 --- a/indexedDb/impl/state/callbacks.go +++ b/indexedDb/impl/state/callbacks.go @@ -12,7 +12,7 @@ package main import ( "encoding/json" "github.com/pkg/errors" - "gitlab.com/elixxir/wasm-utils/storage" + "gitlab.com/elixxir/xxdk-wasm/indexedDb/impl" stateWorker "gitlab.com/elixxir/xxdk-wasm/indexedDb/worker/state" "gitlab.com/elixxir/xxdk-wasm/worker" @@ -22,7 +22,7 @@ import ( // send information between the model and the main thread. type manager struct { wtm *worker.ThreadManager - model storage.LocalStorage + model impl.WebState } // registerCallbacks registers all the reception callbacks to manage messages diff --git a/indexedDb/impl/state/init.go b/indexedDb/impl/state/init.go index e5ba9f9a..14aab3a8 100644 --- a/indexedDb/impl/state/init.go +++ b/indexedDb/impl/state/init.go @@ -12,7 +12,6 @@ package main import ( "github.com/hack-pad/go-indexeddb/idb" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/v4/storage/utility" "gitlab.com/elixxir/xxdk-wasm/indexedDb/impl" "syscall/js" ) @@ -23,7 +22,7 @@ const currentVersion uint = 1 // NewState returns a [utility.WebState] backed by IndexedDb. // The name should be a base64 encoding of the users public key. -func NewState(databaseName string) (utility.WebState, error) { +func NewState(databaseName string) (impl.WebState, error) { return newState(databaseName) } diff --git a/indexedDb/impl/utils.go b/indexedDb/impl/utils.go index 7dbf631c..d9c2fa8e 100644 --- a/indexedDb/impl/utils.go +++ b/indexedDb/impl/utils.go @@ -32,6 +32,13 @@ const ( ErrDoesNotExist = "result is undefined" ) +// WebState defines an interface for setting persistent state in a KV format +// specifically for web-based implementations. +type WebState interface { + Get(key string) ([]byte, error) + Set(key string, value []byte) error +} + // NewContext builds a context for indexedDb operations. func NewContext() (context.Context, context.CancelFunc) { return context.WithTimeout(context.Background(), dbTimeout) diff --git a/indexedDb/worker/state/init.go b/indexedDb/worker/state/init.go index b4842ae5..3ed7ac51 100644 --- a/indexedDb/worker/state/init.go +++ b/indexedDb/worker/state/init.go @@ -11,11 +11,11 @@ package dm import ( "encoding/json" + "gitlab.com/elixxir/xxdk-wasm/indexedDb/impl" "time" "github.com/pkg/errors" - "gitlab.com/elixxir/client/v4/storage/utility" "gitlab.com/elixxir/xxdk-wasm/storage" "gitlab.com/elixxir/xxdk-wasm/worker" ) @@ -29,9 +29,16 @@ type NewStateMessage struct { DatabaseName string `json:"databaseName"` } +// WebState defines an interface for setting persistent state in a KV format +// specifically for web-based implementations. +type WebState interface { + Get(key string) ([]byte, error) + Set(key string, value []byte) error +} + // NewState returns a [utility.WebState] backed by indexeddb. // The name should be a base64 encoding of the users public key. -func NewState(path, wasmJsPath string) (utility.WebState, error) { +func NewState(path, wasmJsPath string) (impl.WebState, error) { databaseName := path + databaseSuffix wh, err := worker.NewManager(wasmJsPath, "stateIndexedDb", true) -- GitLab