Skip to content

Commit

Permalink
Merge pull request #15 from datproject/datarchive
Browse files Browse the repository at this point in the history
DatArchive / Promise support
  • Loading branch information
RangerMauve authored Aug 27, 2019
2 parents a1dd113 + 6918055 commit 0c38782
Show file tree
Hide file tree
Showing 7 changed files with 695 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ typings/

package-lock.json
test-bundle.js

uls-scratch
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sdk
The official Dat SDK (WIP)
The official Dat SDK

[<img src="https://datproject.github.io/design/downloads/dat-logo.png" align="right" width="140">][Dat Project]

## Why use this?

Expand All @@ -18,7 +20,29 @@ The Dat SDK combines the lower level pieces of the Dat ecosystem into high level
- React-Native?
- Electron?

## API/Examples
## API/Examples (Promise)

```js
// Auto-detects sane defaults based on your environment
// Uses Beaker's APIs if they are if they are available
// DatArchive is the same as Beaker
// https://beakerbrowser.com/docs/apis/dat
const {DatArchive} = require('dat-sdk/auto')

const archive = await DatArchive.load('dat://dat.foundation')

const someData = await DatArchive.readFile('/dat.json', 'utf8')

console.log('Dat foundation dat.json:', someData)

const myArchive = await DatArchive.create({
title: 'My Archive'
})

await myArchive.writeFile('/example.txt', 'Hello World!')
```

## API/Examples (Callbacks)

```js
const SDK = require('../')
Expand Down Expand Up @@ -160,6 +184,10 @@ trie.put('key', 'value', () => {
- [x] Ability to close drives
- [x] Check that hypercore replication is working
- [x] Release v0.2.0
- [x] Initial Promise API / Beaker support
- [x] Implement DatArchive API over CB based SDK
- [x] Expose 'auto' module that automatically configures the SDK
- [x] Release
- [ ] New Hyperdrive and Hyperswarm and Corestore
- [ ] Add corestore for replication
- [ ] virtual-corestore API
Expand All @@ -172,8 +200,8 @@ trie.put('key', 'value', () => {
- [ ] Test that hypercore still works using web storage / proxying
- [ ] Make sure tests work in Node / Web / Beaker
- [ ] Release
- [ ] Initial Promise API
- [ ] Draft API (Hyperdrive, Hypercore, DNS, Corestore)
- [ ] Promise API for new data types
- [ ] Draft API (Hypercore, DNS, Corestore)
- [ ] Create wrappers over Callback API
- [ ] Auto-detect presence of Beaker APIs and use those
- [ ] Release
Expand All @@ -191,3 +219,5 @@ trie.put('key', 'value', () => {
- [ ] Electron support with auto-spawning
- [ ] React-native support with node.js thread running daemon
- [ ] Web-Daemon

[Dat Project]: https://dat.foundation
10 changes: 10 additions & 0 deletions auto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const global = require('global')

if (global.DatArchive) {
module.exports = {
DatArchive: global.DatArchive,
destroy: () => void 0
}
} else {
module.exports = require('./promise')()
}
2 changes: 2 additions & 0 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const SDK = require('../')
const { Hypercore, Hyperdrive, resolveName, deleteStorage, destroy } = SDK()

process.once('SIGINT', destroy)

const archive = Hyperdrive(null, {
// This archive will disappear after the process exits
// This is here so that running the example doesn't clog up your history
Expand Down
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "dat-sdk",
"version": "0.2.2",
"description": "The official Dat SDK (WIP)",
"description": "The official Dat SDK",
"main": "index.js",
"scripts": {
"test": "node test",
"test": "node test && node test-promise",
"build-test": "browserify -d test.js > test-bundle.js"
},
"repository": {
Expand All @@ -28,14 +28,23 @@
},
"homepage": "https://github.com/datproject/sdk#readme",
"dependencies": {
"concat-stream": "^2.0.0",
"dat-dns": "^4.0.0",
"dat-encoding": "^5.0.1",
"dom-event-target": "^1.0.0",
"global": "^4.4.0",
"hex-to-32": "^2.0.0",
"hypercore": "^7.5.0",
"hypercore-crypto": "^1.0.0",
"hyperdiscovery": "^10.0.0",
"hyperdrive": "^9.16.0",
"node-dat-archive": "^2.2.0",
"pauls-dat-api": "^8.1.0",
"random-access-memory": "^3.1.1",
"universal-dat-storage": "^1.3.1"
"universal-dat-storage": "^1.3.1",
"universal-localstorage": "^1.0.2",
"universal-prompt": "^1.0.0",
"url-parse": "^1.4.7"
},
"devDependencies": {
"browserify": "^16.2.3",
Expand Down
Loading

0 comments on commit 0c38782

Please sign in to comment.