diff --git a/indexedDb/impl/state/callbacks.go b/indexedDb/impl/state/callbacks.go index 0cd6ab2fc1384c23dbc1aa7326bc2e8cef9b26b5..73dbc2a50ec2e45237803259a50066e239acc0ef 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 e5ba9f9add4bd0f55c092a8ddd40ce97d936ebf0..14aab3a896ea8dc248f8d7f8b9f7c2bf6b42b87d 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 7dbf631c9deee97f3ef79b731832aab142820fbc..d9c2fa8ed1eeb32ee7a71a879e5ae2e405f01e69 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 b4842ae5ca954e1bfead70a483690b88fbf1974d..3ed7ac513204b26912f17a298d320b089d1fbf4e 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)