SkynetLabs / gundb-relay

5 stars 4 forks source link

SkyDB These functions have only been implemented for Browser JS at the moment, and not in NodeJS! #1

Open parajbs opened 2 years ago

parajbs commented 2 years ago

Hello everyone,

I found errors in zenbase-2.1.6 see here: https://github.com/Fluffy9/Zenbase/issues/5 !!!Please read link!!!

I looked at the code from "SkynetLabs/gundb-relay" / also looked at "SkynetLabs/skynet-js" and "SkynetLabs/nodejs-skynet"!

I also looked through the documentation of sdk skynet and there you can read under SkyDB ( Link: https://sdk.skynetlabs.com/#skydb ):

"These functions have only been implemented for Browser JS at the moment."

!!!WARNING!!! VERY IMPORTANT !!!! This means that skydb the commands "client.db.getJSON(publicKey, dataKey);" and "client.db.setJSON(privateKey, dataKey, json);" is only implemented in the browser version (skynet-js) and NOT in the NODEJS version (nodejs-skynet)!!!!

The "gundb-relay" is a NODEJS version, so it shouldn't work at the moment!!!

You should also define how the "gundb-relay" should work!

In Monet, only the "gundb-relay" works as a gun server, but without zenbase having implemented a skynet-skdb in nodejs-version, and because the zenbase module is loaded, gundb does not use radisk (no radata) used!

In order for the gundb server to keep the data after a restart, radisk (radata) must work! Or SkyDB must first be implemented in the NODEJS version "SkynetLabs/nodejs-skynet", then it could work, maybe even without radisk!

If SkyDB is implemented, there is certainly a possibility that zenbase and radisk will work together! I'll see if I can find another solution before implementing SkyDB in NODEJS!

gundb works as it should!

With friendly greetings parajbs

dghelm commented 2 years ago

We might need to adjust the language of the documentation.

When written, the nodejs SDK did not implement SkyDB, but in recent versions, skynet-nodejs actually loads skynet-js and binds several of the methods which do work fine in a nodejs context.

Hope this helps bring some clarity.

You should also define how the "gundb-relay" should work!

We're still reviewing if this is the best pattern for combining Skynet and Gun. If there aren't ways that better serve developers, we will spend more time documenting.

dghelm commented 2 years ago

@parajbs I think I may have been wrong above. For better clarity, I've started to revise a branch that uses @skynetlabs/skynet-nodejs only. This might be a good place to start looking:

https://github.com/SkynetLabs/gundb-relay/pull/2 https://github.com/SkynetLabs/gundb-adapter/pull/1

parajbs commented 2 years ago

hello dghelm, I'm working on it too! and also with "@skynetlabs/skynet-nodejs"!

What I've already managed to do: -getJSON Works great for me!

What doesn't work: -setJSON

But I have already found out where the error happens, namely in the "src/skydb.ts" / " function getOrCreateRegistryEntry" in line 526 this command "const file = new File([JSON.stringify(fullData)], dk :${dataKeyHex}, { type: "application/json" });"

I did some research and found out that "new File()" doesn't work in nodejs, only in some browsers!

I'm trying to write with "fs" but I can't do it because I don't know the "new File()" command very well!

Glad if someone helps! I also have a test repo!

Check out their links now!

parajbs commented 2 years ago

What I've already managed to do: -deleteJSON Works great for me too! I have also integrated others!

parajbs commented 2 years ago

hello dghelm,

I tried your new repo "gundb-relay"! Works so far!

getJSON and setJSON are ok!

But if you include the lines below in your server.js and then let it run, you'll see the InMemory(graph) of Gun!

###########

function logIn(msg){ console.log(in msg:${JSON.stringify(msg)}.........); } function logOut(msg){ console.log(out msg:${JSON.stringify(msg)}.........); } function logData() { console.log(In Memory: ${JSON.stringify(gundb._.graph)});} setInterval(logData, 20000); //Log gun graph every 20 secs gundb..on('in', logIn); gundb..on('out', logOut);

#######

Now to the problem: If I just run "gun.get", then I get a result back on the client! On the server, when debug=true, it picks up a result from skynet and sends it to the client! So far ok, but nothing can be seen in Gun's InMemory(graph)!!!!

Now for the "gun.put":

  1. If I just run "gun.put" on the client, I don't get any message whether it worked or not! I think the bug here is that the new data is sent to Gun's InMemory(graph) or at least to Gun's InMemory(graph) as well and not just to the "gundb-adapter"!

You can see this after executing "gun.put" in the log from the server in "InMemory(graph) of Gun", the data is now there until the server is rebooted! This means that the next command "gun.get" gets the data from "InMemory(graph) from Gun" or even duplicate data from the client!

In my opinion, something is still wrong! Or is this intentional in the gun relay? But then with "gun.get"/"getJSON" the result data should be brought into the "InMemory(graph) of Gun"!

How exactly I'm not sure, think about a "gun.put" command maybe???

If this is not what you want: Then something is wrong with "gun.put"/"setJSON", since the data is also in the "InMemory(graph) of Gun" and not only in the "gundb-adapter"! As I think it should be!

Therefore we should clarify how the skynet-gundb-relay should work (with or without InMemory(graph) from Gun)!!!!! I'm not sure if this is possible with Gun!

Thank you for your link to the improved version! Cool!

parajbs commented 2 years ago

Sorry the lines to paste into server.js were displayed incorrectly on github so here is a link : https://siasky.net/AAATav-0_IkLE8fjf5EV35bKem9rH1mBk_pj_oUu5G7yYw

parajbs commented 2 years ago

hello dghelm,

IMPORTANT NOTICE!!! ATTENTION!!!

There's another problem: the "gundb-adapter" is no longer compatible for the browser, and also no longer to "Fluffy9/Zenbase" and also no longer to my fork "parajbs/Zenbase"!!

The problem is that the data you upload with the "gundb-adapter" is different than when you use the db.setJSON command!!!! You can read the data format of skydb.setJSON in the sdk at https://sdk.skynetlabs.com/#getting-data-from-skydb, but be careful you see it in the DOC this response data: { data: { example: "This is some example JSON data." }, dataLink: "sia://CABAB_1Dt0FJsxqsu_J4TodNCbCGvtFf1Uys_3EgzOlTcg" } But Skydb uploaded this data to skynet from: {"_data":{"example":"This is some example JSON data."},"_v":2}

skydb "gundb-adapter" uploaded file should look like this!!!:

{"_data": {"example":"This is some example JSON data."} ,"_v":2}

  1. {"_data":
  2. {"example":"gundb-adapter-DATA"}
  3. ,"_v":2}

below further examples:

####### Links / data from "gundb-adapter" ##########

Link1: first run "gundb-adapter" https://siasky.net/AQBZHnP-nlhzOjYTb7N5tNX_ipVBY4BYUdCWUFMPo_nxFA Link1 data: {"hello3432\u001bname":{"":{":":"wo53367",">":1650085792019}}}

Link2: second run "gundb-adapter" https://siasky.net/AQBZHnP-nlhzOjYTb7N5tNX_ipVBY4BYUdCWUFMPo_nxFA Link2 data: {"hello3432":{"\u001bname":{"":{":":"wo53367",">":1650085792019}},"4\u001bname":{"":{":":"w2o53367" ,">":1650139393319}}}}

######### Links / data from my fork "parajbs/Zenbase" in the browser:

Link3: first run "parajbs/Zenbase" in the browser https://siasky.net/AADE8vFIGnLDj19GRUmwYo823dci58hGgAYaKosHDdKV2g Link3 data: {"_data":{"hello3432\u001bname":{"":{":":"wo53367",">":1650140322561}}},"_v":2}

Link4: second run "parajbs/Zenbase" in the browser https://siasky.net/AACzZLOiUnZ7Ge95bBn44Ah1kPA2j49sdmjpSVCZMjuZzw Link4 data: {"_data":{"hello3432":{"\u001bname":{"":{":":"wo53367",">":1650140379466}},"4\u001bname":{"":{": ":"w2o53367",">":1650141091892}}}},"_v":2}

#########

Here is the example from sdk.skynetlabs.com "Getting Data From SkyDB": Link5: https://siasky.net/AAC-Antw7HK6Xy2fMlWShgkw_ybTEf9C9N58nhBU-K53LQ

Link5 data: {"_data":{"example":"This is some example JSON data."},"_v":2}

#########

The link6 below happened when I sed the data via browser (setJSON), and then via the "gundb-adapter"!!! Link6: gundb-adapter / Browser skynet-js / gundb-adapter https://siasky.net/AQAGo5tN_H6ZIseo7hpftkaLmsRc5dvop4E6xYdOBiAtXg Link6 data: defective {"_data":{"test\u001bpaste":{"":{":":"okay",">":1650065036537}},"hello3432\u001bname":{"":{":":"world2443332tt ",">":1650082619679}}},"_v":2,"hello3432\u001bname":{"":{":":"wo5335",">":1650083199061}}}

parajbs commented 2 years ago

Hello dghelm and other developers,

Maybe I have to explain it differently! First great work that makes her there!

To the problem: I have created a webapp with "skynet-js", with the same SECRET, as I set it in the "skynetlabs/gundb-relay"! I would like to retrieve the data in the browser via "db.getJSON" by "skynet-js"! but it does not work!

I have researched, and seen that the data is different from "skynetlabs/gundb-relay" (data on siaksy.net uploaded) as if the data is "db.setjson" from "skynet-js" in the browser on siasky.net come!

Here are example data from "skynetlabs/gundb-relay": {"example": "This is some example JSON Data."}

Here Example Data from "db.setjson" of "skynet-js" in the browser: {"_data":{"example": "This is some example JSON Data."},"_v":2}

This must be inserted before the data of "skynetlabs/gundb-relay":

{"_data":

This must be inserted behind the Data of "skynetlabs/gundb-relay":

,"_v":2}

#######

If this correction is made in "store.put"-area, at the site before you upload the data to siasky.net, then the data from "skynetlabs/gundb-relay" compatible to "skynet-js" in the Browser! As it should be!

I hope you put it now what I mean, and make it compatible!