Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
01dfcf60
Commit
01dfcf60
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
add dump prints for debugging purposes
parent
0ebe5e2d
No related branches found
No related tags found
2 merge requests
!60
Revert "Fail a test to be sure it works"
,
!4
Xx 4114/index db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
indexedDb/implementation.go
+53
-8
53 additions, 8 deletions
indexedDb/implementation.go
indexedDb/init.go
+6
-2
6 additions, 2 deletions
indexedDb/init.go
with
59 additions
and
10 deletions
indexedDb/implementation.go
+
53
−
8
View file @
01dfcf60
...
@@ -40,6 +40,17 @@ func newContext() (context.Context, context.CancelFunc) {
...
@@ -40,6 +40,17 @@ func newContext() (context.Context, context.CancelFunc) {
return
context
.
WithTimeout
(
context
.
Background
(),
dbTimeout
)
return
context
.
WithTimeout
(
context
.
Background
(),
dbTimeout
)
}
}
// convertJsonToJs is a helper that converts JSON bytes input
// to a [js.Value] of the object subtype.
func
convertJsonToJs
(
inputJson
[]
byte
)
(
js
.
Value
,
error
)
{
jsObj
:=
make
(
map
[
string
]
interface
{})
err
:=
json
.
Unmarshal
(
inputJson
,
&
jsObj
)
if
err
!=
nil
{
return
js
.
Value
{},
err
}
return
js
.
ValueOf
(
jsObj
),
nil
}
// JoinChannel is called whenever a channel is joined locally.
// JoinChannel is called whenever a channel is joined locally.
func
(
w
*
wasmModel
)
JoinChannel
(
channel
*
cryptoBroadcast
.
Channel
)
{
func
(
w
*
wasmModel
)
JoinChannel
(
channel
*
cryptoBroadcast
.
Channel
)
{
parentErr
:=
errors
.
New
(
"failed to JoinChannel"
)
parentErr
:=
errors
.
New
(
"failed to JoinChannel"
)
...
@@ -58,11 +69,10 @@ func (w *wasmModel) JoinChannel(channel *cryptoBroadcast.Channel) {
...
@@ -58,11 +69,10 @@ func (w *wasmModel) JoinChannel(channel *cryptoBroadcast.Channel) {
"Unable to marshal Channel: %+v"
,
err
))
"Unable to marshal Channel: %+v"
,
err
))
return
return
}
}
channelObj
:=
make
(
map
[
string
]
interface
{})
channelObj
,
err
:=
convertJsonToJs
(
newChannelJson
)
err
=
json
.
Unmarshal
(
newChannelJson
,
&
channelObj
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to
un
marshal Channel: %+v"
,
err
))
"Unable to marshal Channel: %+v"
,
err
))
return
return
}
}
...
@@ -81,7 +91,7 @@ func (w *wasmModel) JoinChannel(channel *cryptoBroadcast.Channel) {
...
@@ -81,7 +91,7 @@ func (w *wasmModel) JoinChannel(channel *cryptoBroadcast.Channel) {
}
}
// Perform the operation
// Perform the operation
_
,
err
=
store
.
Add
(
js
.
ValueOf
(
channelObj
)
)
_
,
err
=
store
.
Add
(
channelObj
)
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
jww
.
ERROR
.
Printf
(
"%+v"
,
errors
.
WithMessagef
(
parentErr
,
"Unable to Add Channel: %+v"
,
err
))
"Unable to Add Channel: %+v"
,
err
))
...
@@ -97,6 +107,8 @@ func (w *wasmModel) JoinChannel(channel *cryptoBroadcast.Channel) {
...
@@ -97,6 +107,8 @@ func (w *wasmModel) JoinChannel(channel *cryptoBroadcast.Channel) {
"Adding Channel failed: %+v"
,
err
))
"Adding Channel failed: %+v"
,
err
))
return
return
}
}
jww
.
DEBUG
.
Printf
(
"Successfully added channel: %s"
,
channel
.
ReceptionID
.
String
())
}
}
// LeaveChannel is called whenever a channel is left locally.
// LeaveChannel is called whenever a channel is left locally.
...
@@ -134,6 +146,7 @@ func (w *wasmModel) LeaveChannel(channelID *id.ID) {
...
@@ -134,6 +146,7 @@ func (w *wasmModel) LeaveChannel(channelID *id.ID) {
"Deleting Channel failed: %+v"
,
err
))
"Deleting Channel failed: %+v"
,
err
))
return
return
}
}
jww
.
DEBUG
.
Printf
(
"Successfully deleted channel: %s"
,
channelID
.
String
())
}
}
// ReceiveMessage is called whenever a message is received on a given channel
// ReceiveMessage is called whenever a message is received on a given channel
...
@@ -227,10 +240,9 @@ func (w *wasmModel) receiveHelper(newMessage *Message) error {
...
@@ -227,10 +240,9 @@ func (w *wasmModel) receiveHelper(newMessage *Message) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Errorf
(
"Unable to marshal Message: %+v"
,
err
)
return
errors
.
Errorf
(
"Unable to marshal Message: %+v"
,
err
)
}
}
messageObj
:=
make
(
map
[
string
]
interface
{})
messageObj
,
err
:=
convertJsonToJs
(
newMessageJson
)
err
=
json
.
Unmarshal
(
newMessageJson
,
&
messageObj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Errorf
(
"Unable to
un
marshal Message: %+v"
,
err
)
return
errors
.
Errorf
(
"Unable to marshal Message: %+v"
,
err
)
}
}
// Prepare the Transaction
// Prepare the Transaction
...
@@ -244,7 +256,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message) error {
...
@@ -244,7 +256,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message) error {
}
}
// Perform the upsert (put) operation
// Perform the upsert (put) operation
_
,
err
=
store
.
Put
(
js
.
ValueOf
(
messageObj
)
)
_
,
err
=
store
.
Put
(
messageObj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Errorf
(
"Unable to upsert Message: %+v"
,
err
)
return
errors
.
Errorf
(
"Unable to upsert Message: %+v"
,
err
)
}
}
...
@@ -256,5 +268,38 @@ func (w *wasmModel) receiveHelper(newMessage *Message) error {
...
@@ -256,5 +268,38 @@ func (w *wasmModel) receiveHelper(newMessage *Message) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Errorf
(
"Upserting Message failed: %+v"
,
err
)
return
errors
.
Errorf
(
"Upserting Message failed: %+v"
,
err
)
}
}
jww
.
DEBUG
.
Printf
(
"Successfully received message: %s"
,
newMessage
.
Id
)
return
nil
return
nil
}
}
// dump is used to output given ObjectStore contents to log for debugging
func
(
w
*
wasmModel
)
dump
(
objectStoreName
string
)
{
txn
,
err
:=
w
.
db
.
Transaction
(
idb
.
TransactionReadOnly
,
objectStoreName
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to create Transaction: %+v"
,
err
)
}
store
,
err
:=
txn
.
ObjectStore
(
objectStoreName
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to get ObjectStore: %+v"
,
err
)
}
cursorRequest
,
err
:=
store
.
OpenCursor
(
idb
.
CursorNext
)
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to open Cursor: %+v"
,
err
)
}
// Run the query
jww
.
INFO
.
Printf
(
"%s values:"
,
objectStoreName
)
ctx
,
cancel
:=
newContext
()
err
=
cursorRequest
.
Iter
(
ctx
,
func
(
cursor
*
idb
.
CursorWithValue
)
error
{
value
,
err
:=
cursor
.
Value
()
if
err
!=
nil
{
return
err
}
jww
.
INFO
.
Printf
(
"- %v"
,
js
.
Global
()
.
Get
(
"JSON"
)
.
Call
(
"stringify"
,
value
))
return
nil
})
cancel
()
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"Failed to dump ObjectStore: %+v"
,
err
)
}
}
This diff is collapsed.
Click to expand it.
indexedDb/init.go
+
6
−
2
View file @
01dfcf60
...
@@ -11,7 +11,6 @@
...
@@ -11,7 +11,6 @@
package
indexedDb
package
indexedDb
import
(
import
(
"context"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
...
@@ -29,10 +28,15 @@ const (
...
@@ -29,10 +28,15 @@ const (
// NewWasmEventModel returns a [channels.EventModel] backed by a wasmModel
// NewWasmEventModel returns a [channels.EventModel] backed by a wasmModel
func
NewWasmEventModel
(
username
string
)
(
channels
.
EventModel
,
error
)
{
func
NewWasmEventModel
(
username
string
)
(
channels
.
EventModel
,
error
)
{
ctx
:=
context
.
Background
()
databaseName
:=
username
+
databaseSuffix
databaseName
:=
username
+
databaseSuffix
return
newWasmModel
(
databaseName
)
}
// newWasmModel creates the given [idb.Database] and returns a wasmModel
func
newWasmModel
(
databaseName
string
)
(
*
wasmModel
,
error
)
{
// Attempt to open database object
// Attempt to open database object
ctx
,
cancel
:=
newContext
()
defer
cancel
()
openRequest
,
_
:=
idb
.
Global
()
.
Open
(
ctx
,
databaseName
,
currentVersion
,
openRequest
,
_
:=
idb
.
Global
()
.
Open
(
ctx
,
databaseName
,
currentVersion
,
func
(
db
*
idb
.
Database
,
oldVersion
,
newVersion
uint
)
error
{
func
(
db
*
idb
.
Database
,
oldVersion
,
newVersion
uint
)
error
{
if
oldVersion
==
newVersion
{
if
oldVersion
==
newVersion
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment