GithubHelp home page GithubHelp logo

dat-ecosystem-archive / dat-js Goto Github PK

View Code? Open in Web Editor NEW
142.0 142.0 19.0 257 KB

A pure JavaScript browser-friendly api for using dat [ DEPRECATED - see https://github.com/datproject/sdk for similar functionality. More info on active projects and modules at https://dat-ecosystem.org/ ]

Home Page: https://datproject.org

JavaScript 98.89% HTML 1.11%

dat-js's People

Contributors

aschrijver avatar douganderson444 avatar dpaez avatar etienne-martin avatar joehand avatar karissa avatar ninabreznik avatar okdistribute avatar rangermauve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dat-js's Issues

Does dat-js still create a Dat prototype on the window object?

The Dat website says that you can just reference
<script type="text/javascript" src="https://bundle.run/dat-js@7"></script>
and you get
a Dat prototype on the window object
...is this still valid with the updates? Mind showing a gist of how to instantiate? It it something like
var dat = window.Dat()? (Since I can't seem to get it to work :/) Thanks!

Prefix files in the storage with the dat key

As per the conversation on IRC, we don't currently prefix the file names per archive, so if a user passes in something like random-access-idb into the Dat-js constructor, it'll cause issues with archives overwriting each other's files.

In order to fix this we should:

  • Wrap the calls to storage inside the repo to prefix files with the key, similar to what I did before in dat-polyfill
  • In order to do that we need to create keys for new archives before initializing hyperdrive. Similar to what I did in dat-archive-web
  • Make a working example of using persistent storage through random-access-idb

Is there any way to listen for changes

I looked through the documentation and I can't seem to find any information about how to listen to changes like you can with node.js API. Is that possible in the browser version as well?

Question: Possible to interact with DAT protocol over HTTP?

Is it possible to interact with something DAT in a webapp (some static files) over HTTP? Not just be shown a data replication, but actually interact, like one or several people updating a a hyperDB, living ini indexedDB.

The reason for the question is that not many people use Beaker Browser, and not many people will install a plugin for Firefox / Chrome. Kind of "How to get the future to everyone, now" ๐Ÿ˜„

Info about dat-js

Hi I'm really interested in dat protocol, in particular I'm interested in dat-js, browser version.
I'd like to develop little app for the browser but:

  • I can't find source of dat-js, althought I've found only minimized version
  • I like to know if browser version cache file of others clients, like nodejs version:
    I explain me better:
    for example: I run 10 browser with simple data shared, the there're all online, well after a while one of this browser will shut down.
    Are data of the last client even available, even if only 3 or 4 of all have browsed content.
    thanks

What's the alternative if it's "out of date"?

The first thing this repo says is it's out of date. Is this approach permanently discontinued? Or is there an alternative elsewhere I should look at?

Would love to start playing with Dat!

Archive this repo?

This repo is confusing some users! Could we explain in the readme why it's out of date, and archive it?

EDIT: rewrote to be less abrupt.

`readFile` doesn't call the callback in some case

First of all: awesome work!

Second, the issue: repo.archive.readFile doesn't call the callback in some case.

Reproduction

  • Put the code below in an html file.
  • Uncomment all comments (don't forget the comment at the end //)}).
  • Open the file in the browser. You'll see the log correctly.
  • Re-comment the code & open the file in the browser. The problem: nothing gets logged.
<title>Check Chrome Console</title>
<script type="text/javascript" src="https://bundle.run/[email protected]"></script>
<script type="text/javascript" src="https://bundle.run/[email protected]"></script>

<script>
var Dat = datJs
/*var db = randomAccessIdb('dats')

var dat = new Dat()

var repo = dat.create({
  db: db
})

repo.archive.writeFile('/example.txt', 'Hello World!', () => {
  // Save it for later
  localStorage.setItem('My_Repo', repo.url)*/
  var db2 = randomAccessIdb('dats')
  var dat2 = new Dat()
  var repo2 = dat2.get(localStorage.getItem('My_Repo'), {
    db: db2
  })

  repo2.archive.readFile('/example.txt', 'utf-8', (err, data) => {
    console.log(`It's still there: ${data}`)
  })
//})
</script>

Using with Webpack

Hi, I'm getting the following error with dat-js

Version: 8

 ERROR  Failed to compile with 1 errors                               8:14:59 PM

 error  in ./node_modules/@sammacbeth/random-access-idb-mutable-file/src/random-access-idb-mutable-file.js

Module parse failed: Unexpected token (4:12)
You may need an appropriate loader to handle this file type.
| 
| import RandomAccess from "random-access-storage"
> import type {
|   Stat,
|   Request,

 @ ./node_modules/random-access-web/index.js 38:24-77
 @ ./node_modules/dat-js/index.js
 @ ./src/boot/dat.js
 @ ./.quasar/client-entry.js
 @ multi (webpack)-dev-server/client?http://0.0.0.0:8080 (webpack)/hot/dev-server.js ./.quasar/client-entry.js

package.json

  "name": "qdat",
  "version": "0.0.1",
  "scripts": {
    "test": "echo \"No test specified\" && exit 0"
  },
  "dependencies": {
    "@quasar/extras": "^1.0.0",
    "dat-js": "^8.0.0",
    "quasar": "^1.0.0-beta.0"
  },
  "devDependencies": {
    "@quasar/app": "^1.0.0-beta.0",
    "devtron": "1.4.0",
    "electron": "4.0.5",
    "electron-debug": "2.1.0",
    "electron-devtools-installer": "2.2.4",
    "strip-ansi": "=3.0.1"
  },
  "engines": {
    "node": ">= 8.9.0",
    "npm": ">= 5.6.0",
    "yarn": ">= 1.6.0"
  },
  "browserslist": [
    "last 1 version, not dead, ie >= 11"
  ],
  "resolutions": {
    "ajv": "6.8.1"
  }
}

I don't get the same issue with dat-js v 7.1.1

API redesign suggestion: get rid of `Dat` class

This issue is to suggest removing Dat class and to expose Repo directly.

Arguments I see for keeping it:

  1. To make it possible to push default opts that apply to each newly-created Repo.
  2. Having one close function.
  3. dat-js is meant to be this one interface for the developer that has everything, such as this one close.

Arguments I see for removing it:

  1. (1) could be dangerous as turned out in #20.
  2. For (2), the design style of the dat ecosystem seems to prefer doing just one thing really well in each module/npm library.
  3. For (3), actually, the developer ends up mostly using Repo APIs anyway. create and get could be static methods on Repo (like DatArchive).
  4. As long as there's no shared state/variables between the repos, I think providing Dat adds complexity, and may actually encourage us to add shared state/variables when there could've been none.

So, my opinion would be to remove it.

What do you think?

Create gateway and signalhubws instances under Dat domains.

dat-js is currently making use of a gateway and signalhubws instance that I set up on a server I have lying around.

I'm totally OK with this setup, but I think that it would be better going forward if it was using instances that were under the datproject domain to make it more obvious to users what it is and where to go if it's down. (Also in case I get run over by a bus).

Steps to get this done:

  • Register subdomains on datproject
  • Set up a VM with the services
  • Set up a letsencrypt certificate with auto-renewal (I did this with nginx)
  • Update dat-js and docs to point to the new domains

cc: @Karissa @joehand

hope more example

i plan build a app with dat-js ,i know dat-node ,but most user not know node ,and i hope user just open and use it ,so,,just hope enhance dat-js

Duplicate Peers

Hi, I'm noticing an issue with how connected peers are being managed. I'm attempting to log the number of connected peers for a given archive, and am getting some unexpected results. It looks like peers are being added twice as duplicates. Furthermore, they are only removed once, leaving a copy still in the peer list. The following reproducible code snippet illustrates what I'm seeing:

const dat1 = new Dat()
const dat2 = new Dat()

const archive = dat1.create()

archive.ready(() => {
  archive.metadata.on('peer-add', onPeerAdded)
  archive.metadata.on('peer-remove', onPeerRemoved)
  
  dat2.get(archive.url) // trigger peer-add event
})

// Here's the weird thing. This handler gets called twice when dat2 joins.
// The first time it'll log an array of one peer as expected.
// The second time it'll log an array of two duplicate peers
function onPeerAdded() {
  console.log('peers after adding', archive.metadata.peers)

  dat2.close() // trigger peer-remove event
}

// Only called once as expected, however the log will show that only one
// of the duplicate peers is removed. The other remains in the list
function onPeerRemoved() {
  console.log('peers after removing', archive.metadata.peers)
}

Here is a codesandbox running the snippet: https://codesandbox.io/s/nervous-turing-wppi3

Please let me know if I can be of any more help.
As an aside, this project is super cool, and I am excited to see it mature.

npm docs & readme are sparse

The dat-node package has a sample for dat creation and replication. It would be nice if this package had something similar.

feedback

I'm actually really liking this API - I feel it makes sense as it turns dat into a manager of multiple hyperdrive archives that are exposed over hyperdiscovery. Simple and to the point.

I think the only change I'd make would be to rename dat.add to dat.create / dat.createRepo as it's closer to the hyperdrive terminology of drive.createArchive. - I'd use this repo ๐Ÿ˜

WebSocket Error

Not sure how crucial this is (everything still seems to work), but when I create a new Dat

const dat = new Dat({
          persist: true, 
          gateway:  'ws://gateway.mauve.moe:3000'
})

I keep getting a websocket error in the browser Dev Console:

WebSocket connection to 'ws://localhost:3472/' failed: 
Error in connection establishment: 
net::ERR_CONNECTION_REFUSED

Tried to dig through the code to find where this is called, but can't seem to find it. I'm using Glitch.com, but not sure why the Dat-JS is calling localhost for a websocket.

example dosn't work

hi, test exmlpe for dat-js and understend why not work.

test.html have code:

<script type="text/javascript" src="https://bundle.run/dat-js@7"></script>
<script>
var dat= new datJs({
  gateway: 'ws://gateway.mauve.moe:3000'
})
var url = 'dat://13f1d1ba5be8723edb4b9499c97a16fbb061d5fc72afe5e7e107d020cb7b34f5'
var repo = dat.get(url)
repo.ready(() => {
  console.log('ready')
  repo.archive.readFile('/1.jpg', function (err, data) {
    console.log(data.toString(), err) // prints 'world'
  })
  var readStream = repo.archive.createReadStream('1.jpg')
  readStream.on('data', console.log)
})

console.log(repo.archive)
</script>

in console chrome no error logs. event .ready succesfull emited, but readFile callback no.

At computer succesfull start

Exiting the Dat program...nemozar@nemozar-PC:~/Pictures/test$ dat share ./
dat v13.12.2
dat://13f1d1ba5be8723edb4b9499c97a16fbb061d5fc72afe5e7e107d020cb7b34f5

TypeError: path is undefined

I followed the example on https://docs.dat.foundation/docs/browser-intro but i get TypeError: path is undefined, using this code:

var dat = new Dat()
var archive = dat.create({
    persist: true
})
archive.writeFile('/example.txt', 'Hello World!', () => {
    localStorage.setItem('My_Repo', archive.url)
})

Removing .posix in hyperdrive seemed to do the trick but I'm not sure if anything else needs to be updated as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.