Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(decision): use ipfs-repo interface
- Loading branch information
1 parent
5e20682
commit abec856
Showing
15 changed files
with
449 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,6 @@ build/Release | |
node_modules | ||
|
||
dist | ||
lib | ||
lib | ||
|
||
test/test-repo-for* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict' | ||
|
||
const async = require('async') | ||
const store = require('idb-plus-blob-store') | ||
const _ = require('lodash') | ||
const IPFSRepo = require('ipfs-repo') | ||
|
||
const repoContext = require.context('buffer!./test-repo', true) | ||
|
||
const idb = window.indexedDB || | ||
window.mozIndexedDB || | ||
window.webkitIndexedDB || | ||
window.msIndexedDB | ||
|
||
// book keeping | ||
const dbs = [] | ||
|
||
function createRepo (id, done) { | ||
const repoData = [] | ||
repoContext.keys().forEach(function (key) { | ||
repoData.push({ | ||
key: key.replace('./', ''), | ||
value: repoContext(key) | ||
}) | ||
}) | ||
|
||
const mainBlob = store(id) | ||
const blocksBlob = store(`${id}/blocks`) | ||
|
||
dbs.push(id) | ||
|
||
async.eachSeries(repoData, (file, cb) => { | ||
if (_.startsWith(file.key, 'datastore/')) { | ||
return cb() | ||
} | ||
|
||
const blocks = _.startsWith(file.key, 'blocks/') | ||
const blob = blocks ? blocksBlob : mainBlob | ||
|
||
const key = blocks ? file.key.replace(/^blocks\//, '') : file.key | ||
|
||
blob.createWriteStream({ | ||
key: key | ||
}).end(file.value, cb) | ||
}, () => { | ||
const repo = new IPFSRepo(id, {stores: store}) | ||
done(null, repo) | ||
}) | ||
} | ||
|
||
function removeRepos (done) { | ||
dbs.forEach((db) => { | ||
idb.deleteDatabase(db) | ||
idb.deleteDatabase(`${db}/blocks`) | ||
}) | ||
done() | ||
} | ||
|
||
require('./decision/engine-test')({ | ||
create: createRepo, | ||
remove: removeRepos | ||
}) |
Oops, something went wrong.