ipfs-cluster-api
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "ipfs-cluster-api", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A JS client library for the IPFS Cluster HTTP API.", | ||
@@ -20,2 +20,3 @@ "leadMaintainer": "Vaibhav Saini <vasa@towardsblockchain.com>", | ||
"once": "^1.4.0", | ||
"promisify-es6": "^1.0.3", | ||
"pull-to-stream": "^0.1.1", | ||
@@ -26,5 +27,23 @@ "pump": "^3.0.0", | ||
"devDependencies": { | ||
"@babel/core": "^7.4.4", | ||
"@babel/preset-env": "^7.4.4", | ||
"babel-core": "^6.26.3", | ||
"babel-preset-env": "^1.7.0", | ||
"babelify": "^10.0.0", | ||
"browserify": "^16.2.3", | ||
"chai": "^4.2.0", | ||
"mocha": "^6.1.4" | ||
"gulp": "^4.0.2", | ||
"gulp-babel": "^8.0.0", | ||
"gulp-rename": "^1.4.0", | ||
"gulp-sourcemaps": "^2.6.5", | ||
"gulp-uglify": "^3.0.2", | ||
"mocha": "^6.1.4", | ||
"vinyl-buffer": "^1.0.1", | ||
"vinyl-source-stream": "^2.0.0" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"@babel/preset-env" | ||
] | ||
}, | ||
"keywords": [ | ||
@@ -35,3 +54,4 @@ "ipfs", | ||
"ipfs-cluster-api", | ||
"js", | ||
"js-ipfs-cluster", | ||
"js-ipfs-http-client", | ||
"clusterlabs" | ||
@@ -38,0 +58,0 @@ ], |
@@ -25,2 +25,3 @@ | ||
- [Importing the module and usage](#importing-the-module-and-usage) | ||
- [In a web browser through Browserify](#in-a-web-browser) | ||
- [Usage](#usage) | ||
@@ -65,3 +66,3 @@ - [API Docs](#api) | ||
To interact with the API, you need to have a daemon running. It needs to be open on the right port. `9094` is the default, and is used in the examples below, but it can be set to whatever you need. You can setup `ipfs-cluster-service` by following [**this installation guide**]([https://github.com/ipfs/ipfs-cluster#install](https://github.com/ipfs/ipfs-cluster#install)). | ||
To interact with the API, you need to have a daemon running. It needs to be open on the right port. `9094` is the default, and is used in the examples below, but it can be set to whatever you need. You can setup `ipfs-cluster-service` by following [**this installation guide**](https://github.com/ipfs/ipfs-cluster#install). | ||
@@ -89,5 +90,46 @@ After installing run the daemon. | ||
// or specifying a specific API path | ||
var ipfs = ipfsClient({ host: '1.1.1.1', port: '80', 'api-path': '/some/api/path' }) | ||
``` | ||
### In a web browser | ||
**through Browserify** | ||
Same as in Node.js, you just have to [browserify](http://browserify.org/) to bundle the code before serving it. | ||
> Note: The code uses `es6`, so you have to use [babel](https://babeljs.io/) to convert the code into `es5` before using `browserify`. | ||
**through webpack** | ||
Same as in Node.js, you just have to [webpack](https://webpack.js.org/) to bundle the the code before serving it. | ||
> Note: The code uses `es6`, so you have to use [babel](https://babeljs.io/) to convert the code into `es5` before using `webpack`. | ||
**from CDN** | ||
Instead of a local installation (and browserification) you may request a remote copy of IPFS API from unpkg CDN. | ||
To always request the latest version, use the following: | ||
``` | ||
<!-- loading the minified version --> | ||
<script src="https://unpkg.com/ipfs-cluster-api/dist/src/index.min.js"></script> | ||
<!-- loading the human-readable (not minified) version --> | ||
<script src="https://unpkg.com/ipfs-cluster-api/dist/src/index.js"></script> | ||
``` | ||
CDN-based IPFS Cluster API provides the `IpfsClusterAPI` constructor as a method of the global `window` object. Example: | ||
``` | ||
const cluster = IpfsClusterAPI('127.0.0.1', '9094', {protocol: 'http'}) | ||
``` | ||
If you omit the host and port, the client will parse `window.host`, and use this information. This also works, and can be useful if you want to write apps that can be run from multiple different gateways: | ||
``` | ||
const ipfs = window.IpfsHttpClient() | ||
``` | ||
## Usage | ||
@@ -136,4 +178,12 @@ | ||
`callback` must follow `function (err, res) {}` signature, where `err` is an error if the operation was not successful. If successful, `res` will be an empty array `[]`, as the Go implementation of `ipfs-cluster` APIs returns `nil` as response. | ||
`callback` must follow `function (err, res) {}` signature, where `err` is an error if the operation was not successful. If successful, `res` will return an object of following form: | ||
``` | ||
{ | ||
path: '/path/to/file/foo.txt', | ||
hash: 'QmRG3FXAW76xD7ZrjCWk8FKVaTRPYdMtwzJHZ9gArzHK5f', | ||
size: 2417 | ||
} | ||
``` | ||
If no `callback` is passed, a promise is returned. | ||
@@ -140,0 +190,0 @@ |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
const ConcatStream = require('concat-stream') | ||
@@ -14,3 +14,3 @@ const once = require('once') | ||
const add = util.promisify((_files, options, _callback) => { | ||
const add = promisify((_files, options, _callback) => { | ||
if (typeof options === 'function') { | ||
@@ -17,0 +17,0 @@ _callback = options |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
module.exports = (send) => { | ||
return util.promisify((opts, callback) => { | ||
return promisify((opts, callback) => { | ||
if (typeof opts == 'function') { | ||
@@ -9,0 +9,0 @@ callback = opts |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
module.exports = (send) => { | ||
return util.promisify((arg, opts, callback) => { | ||
return promisify((arg, opts, callback) => { | ||
if (typeof opts == 'function') { | ||
@@ -9,0 +9,0 @@ callback = opts |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
const moduleConfig = require('./utils/module-config') | ||
@@ -9,3 +9,3 @@ | ||
return util.promisify((opts, callback) => { | ||
return promisify((opts, callback) => { | ||
if (typeof opts == 'function') { | ||
@@ -12,0 +12,0 @@ callback = opts |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
module.exports = (send) => { | ||
return util.promisify((arg, opts, callback) => { | ||
return promisify((arg, opts, callback) => { | ||
if (typeof opts == 'function') { | ||
@@ -8,0 +8,0 @@ callback = opts |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
module.exports = (send) => { | ||
return util.promisify((opts, callback) => { | ||
return promisify((opts, callback) => { | ||
if (typeof opts == 'function') { | ||
@@ -8,0 +8,0 @@ callback = opts |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
module.exports = (send) => { | ||
return util.promisify((arg, opts, callback) => { | ||
return promisify((arg, opts, callback) => { | ||
if (typeof opts == 'function') { | ||
@@ -8,0 +8,0 @@ callback = opts |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
module.exports = (send) => { | ||
return util.promisify((arg, opts, callback) => { | ||
return promisify((arg, opts, callback) => { | ||
if (typeof opts == 'function') { | ||
@@ -8,0 +8,0 @@ callback = opts |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
module.exports = (send) => { | ||
return util.promisify((opts, callback) => { | ||
return promisify((opts, callback) => { | ||
@@ -8,0 +8,0 @@ if(typeof opts === 'function') { |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
module.exports = (send) => { | ||
return util.promisify((arg, opts, callback) => { | ||
return promisify((arg, opts, callback) => { | ||
if (typeof opts == 'function') { | ||
@@ -8,0 +8,0 @@ callback = opts |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
const moduleConfig = require('./utils/module-config') | ||
@@ -9,3 +9,3 @@ | ||
return util.promisify((args, opts, callback) => { | ||
return promisify((args, opts, callback) => { | ||
@@ -12,0 +12,0 @@ if (typeof args == 'function') { |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
const moduleConfig = require('./utils/module-config') | ||
@@ -9,3 +9,3 @@ | ||
return util.promisify((cid, opts, callback) => { | ||
return promisify((cid, opts, callback) => { | ||
if (typeof cid === 'function') { | ||
@@ -12,0 +12,0 @@ callback = cid |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
const moduleConfig = require('./utils/module-config') | ||
@@ -9,3 +9,3 @@ | ||
return util.promisify((cid, opts, callback) => { | ||
return promisify((cid, opts, callback) => { | ||
if (typeof cid == 'function') { | ||
@@ -12,0 +12,0 @@ callback = cid |
@@ -13,2 +13,2 @@ 'use strict' | ||
} | ||
} | ||
} |
@@ -13,5 +13,5 @@ 'use strict' | ||
{ | ||
Name: '/path/to/file/foo.txt', | ||
Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' | ||
Size: '20' | ||
name: '/path/to/file/foo.txt', | ||
cid: { '/': 'QmRG3FXAW76xD7ZrjCWk8FKVaTRPYdMtwzJHZ9gArzHK5f' }, | ||
size: 2417 | ||
} | ||
@@ -22,4 +22,4 @@ | ||
path: '/path/to/file/foo.txt', | ||
hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', | ||
size: 20 | ||
hash: 'QmRG3FXAW76xD7ZrjCWk8FKVaTRPYdMtwzJHZ9gArzHK5f', | ||
size: 2417 | ||
} | ||
@@ -34,3 +34,3 @@ */ | ||
_transform (obj, enc, callback) { | ||
if (!obj.Hash) { | ||
if (!obj.name) { | ||
return callback() | ||
@@ -40,5 +40,5 @@ } | ||
callback(null, { | ||
path: obj.Name, | ||
hash: obj.Hash, | ||
size: parseInt(obj.Size, 10) | ||
path: obj.name, | ||
hash: obj.cid['/'], | ||
size: parseInt(obj.size, 10) | ||
}) | ||
@@ -45,0 +45,0 @@ } |
'use strict' | ||
const getConfig = require('./default-config') | ||
const requestAPI = require('./request-api') | ||
module.exports = (arg) => { | ||
const config = getConfig() | ||
@@ -9,0 +7,0 @@ if (typeof arg === 'function') { |
@@ -12,3 +12,3 @@ 'use strict' | ||
const pump = require('pump') | ||
const log = require('debug')('ipfs-http-client:request') | ||
const log = require('debug')('ipfs-cluster-api:request') | ||
@@ -51,3 +51,2 @@ function parseError (res, cb) { | ||
if (stream && !buffer) { | ||
//console.log("LOG_0: ", res) | ||
return cb(null, res) | ||
@@ -72,3 +71,2 @@ } | ||
}) | ||
//console.log("LOG_1: ", outputStream) | ||
return cb(null, outputStream) | ||
@@ -79,3 +77,2 @@ } | ||
if (isJson) { | ||
//console.log("LOG_2: ", res) | ||
return streamToJsonValue(res, cb) | ||
@@ -82,0 +79,0 @@ } |
'use strict' | ||
const util = require('util') | ||
const promisify = require('promisify-es6') | ||
const moduleConfig = require('./utils/module-config') | ||
@@ -9,3 +9,3 @@ | ||
return util.promisify((opts, callback) => { | ||
return promisify((opts, callback) => { | ||
if (typeof opts == 'function') { | ||
@@ -12,0 +12,0 @@ callback = opts |
Sorry, the diff of this file is not supported yet
66013
48
603
12
15
1269
+ Addedpromisify-es6@^1.0.3
+ Addedpromisify-es6@1.0.3(transitive)