blockstack-storage
Advanced tools
Comparing version
@@ -31,2 +31,4 @@ 'use strict'; | ||
require('localstorage-polyfill'); | ||
var http = require('http'); | ||
@@ -97,3 +99,3 @@ var uuid4 = require('uuid/v4'); | ||
* @param options (Object) set of HTTP request options | ||
* @param result_schema (Object) JSON schema of the expected result | ||
* @param result_schema (Object) JSON schema of the expected result | ||
* | ||
@@ -281,3 +283,3 @@ * Returns a structured JSON response on success, conformant to the result_schema. | ||
* @param hostport (String) the host:port | ||
* | ||
* | ||
* Returns an object with: | ||
@@ -495,3 +497,3 @@ * .host | ||
* * (optional) device_id (string) the device ID | ||
* | ||
* | ||
* OR: | ||
@@ -528,3 +530,3 @@ * | ||
if (!sessionToken) { | ||
// load from user data | ||
// load from user data | ||
var userData = getUserData(); | ||
@@ -615,3 +617,3 @@ | ||
// this is required for testing purposes, since the core session token will not have been set | ||
// this is required for testing purposes, since the core session token will not have been set | ||
var _userData = getUserData(); | ||
@@ -634,11 +636,2 @@ if (!_userData.coreSessionToken) { | ||
function getUserData() { | ||
var localStorage = null; | ||
if (typeof window === 'undefined' || window === null) { | ||
var LocalStorage = require('node-localstorage').LocalStorage; | ||
localStorage = new LocalStorage('./scratch'); | ||
} else { | ||
localStorage = window.localStorage; | ||
} | ||
var userData = localStorage.getItem(LOCAL_STORAGE_ID); | ||
@@ -657,11 +650,2 @@ if (userData === null) { | ||
function setUserData(userData) { | ||
var localStorage = null; | ||
if (typeof window === 'undefined' || window === null) { | ||
var LocalStorage = require('node-localstorage').LocalStorage; | ||
localStorage = new LocalStorage('./scratch'); | ||
} else { | ||
localStorage = window.localStorage; | ||
} | ||
localStorage.setItem(LOCAL_STORAGE_ID, JSON.stringify(userData)); | ||
@@ -975,3 +959,3 @@ } | ||
// decode | ||
// decode | ||
var session = jsontokens.decodeToken(sessionToken).payload; | ||
@@ -996,3 +980,3 @@ assert(session.blockchain_id); | ||
// sanity check | ||
// sanity check | ||
var _iteratorNormalCompletion9 = true; | ||
@@ -1056,3 +1040,3 @@ var _didIteratorError9 = false; | ||
// find satisfactory storage drivers | ||
// find satisfactory storage drivers | ||
if (Object.keys(session.storage.preferences).includes(session.app_domain)) { | ||
@@ -1105,3 +1089,3 @@ | ||
} else if (datastore_ctx.error) { | ||
// some other error | ||
// some other error | ||
var errorMsg = datastore_ctx.error || 'UNKNOWN'; | ||
@@ -1118,4 +1102,4 @@ var errorNo = datastore_ctx.errno || 'UNKNOWN'; | ||
/* | ||
* Path lookup | ||
* | ||
* Path lookup | ||
* | ||
* @param ds (Object) a datastore context | ||
@@ -1254,3 +1238,3 @@ * @param path (String) the path to the inode | ||
/* | ||
/* | ||
* Stat a file or directory (i.e. get the inode header) | ||
@@ -1324,3 +1308,3 @@ * | ||
/* | ||
/* | ||
* Get an undifferentiated file or directory and its data. | ||
@@ -1471,3 +1455,3 @@ * Low-level method, not meant for external consumption. | ||
* | ||
* @param ds (Object) a datastore context | ||
* @param ds (Object) a datastore context | ||
* @param operation (String) the specific operation being carried out. | ||
@@ -1628,3 +1612,3 @@ * @param path (String) the path of the operation | ||
// get parent dir | ||
// get parent dir | ||
return getParent(path, opts).then(function (parent_dir) { | ||
@@ -1662,3 +1646,3 @@ if (parent_dir.error) { | ||
// new | ||
// new | ||
inode_uuid = uuid4(); | ||
@@ -1720,3 +1704,3 @@ new_parent_dir_inode = (0, _inode.inodeDirLink)(parent_dir, _schemas.MUTABLE_DATUM_FILE_TYPE, child_name, inode_uuid, false); | ||
// must not exist | ||
// must not exist | ||
if (Object.keys(parent_dir['idata']['children']).includes(child_name)) { | ||
@@ -1726,3 +1710,3 @@ return { 'error': 'File or directory exists', 'errno': EEXIST }; | ||
// make the directory inode information | ||
// make the directory inode information | ||
var inode_uuid = uuid4(); | ||
@@ -1732,3 +1716,3 @@ var inode_info = (0, _inode.makeDirInodeBlob)(datastore_id, datastore_id, inode_uuid, {}, device_id); | ||
// make the new parent directory information | ||
// make the new parent directory information | ||
var new_parent_dir_inode = (0, _inode.inodeDirLink)(parent_dir, _schemas.MUTABLE_DATUM_DIR_TYPE, child_name, inode_uuid); | ||
@@ -1738,3 +1722,3 @@ var new_parent_info = (0, _inode.makeDirInodeBlob)(datastore_id, new_parent_dir_inode['owner'], new_parent_dir_inode['uuid'], new_parent_dir_inode['idata']['children'], device_id, new_parent_dir_inode['version'] + 1); | ||
// post them | ||
// post them | ||
return datastoreOperation(ds, 'mkdir', path, [inode_info['header'], new_parent_info['header']], [inode_info['idata'], new_parent_info['idata']], [inode_sig, new_parent_sig], []); | ||
@@ -1746,3 +1730,3 @@ }); | ||
/* | ||
* Delete a file | ||
* Delete a file | ||
* | ||
@@ -1791,3 +1775,3 @@ * @param ds (Object) datastore context | ||
// unlink | ||
// unlink | ||
var new_parent_dir_inode = (0, _inode.inodeDirUnlink)(parent_dir, child_name); | ||
@@ -1797,7 +1781,7 @@ var new_parent_info = (0, _inode.makeDirInodeBlob)(datastore_id, new_parent_dir_inode['owner'], new_parent_dir_inode['uuid'], new_parent_dir_inode['idata']['children'], device_id, new_parent_dir_inode['version'] + 1); | ||
// make tombstones | ||
// make tombstones | ||
var tombstones = (0, _inode.makeInodeTombstones)(datastore_id, inode_uuid, all_device_ids); | ||
var signed_tombstones = (0, _inode.signMutableDataTombstones)(tombstones, privkey_hex); | ||
// post them | ||
// post them | ||
return datastoreOperation(ds, 'deleteFile', path, [new_parent_info['header']], [new_parent_info['idata']], [new_parent_sig], signed_tombstones); | ||
@@ -1809,3 +1793,3 @@ }); | ||
/* | ||
* Remove a directory | ||
* Remove a directory | ||
* | ||
@@ -1854,3 +1838,3 @@ * @param ds (Object) datastore context | ||
// unlink | ||
// unlink | ||
var new_parent_dir_inode = (0, _inode.inodeDirUnlink)(parent_dir, child_name); | ||
@@ -1860,7 +1844,7 @@ var new_parent_info = (0, _inode.makeDirInodeBlob)(datastore_id, new_parent_dir_inode['owner'], new_parent_dir_inode['uuid'], new_parent_dir_inode['idata']['children'], device_id, new_parent_dir_inode['version'] + 1); | ||
// make tombstones | ||
// make tombstones | ||
var tombstones = (0, _inode.makeInodeTombstones)(datastore_id, inode_uuid, all_device_ids); | ||
var signed_tombstones = (0, _inode.signMutableDataTombstones)(tombstones, privkey_hex); | ||
// post them | ||
// post them | ||
return datastoreOperation(ds, 'rmdir', path, [new_parent_info['header']], [new_parent_info['idata']], [new_parent_sig], signed_tombstones); | ||
@@ -1867,0 +1851,0 @@ }); |
{ | ||
"name": "blockstack-storage", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "The Blockstack Javascript library for storage.", | ||
@@ -65,2 +65,3 @@ "main": "lib/index", | ||
"fetch-mock": "^5.5.0", | ||
"localstorage-polyfill": "^1.0.1", | ||
"node-fetch": "^1.6.3", | ||
@@ -75,5 +76,4 @@ "tape": "^4.6.3" | ||
"jsontokens": "^0.7.4", | ||
"node-localstorage": "^1.3.0", | ||
"uuid": "^3.0.1" | ||
} | ||
} |
6
-14.29%130374
-0.4%10
11.11%3141
-0.41%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed