Rename to SwarmAPI
This commit is contained in:
parent
830040021d
commit
a1aa94424a
6
.babelrc
6
.babelrc
|
@ -4,11 +4,11 @@
|
|||
"env": {
|
||||
"browser": {
|
||||
"ignore": [
|
||||
"src/swarmjs.js",
|
||||
"src/swarmapi.js",
|
||||
"src/index.js",
|
||||
"src/node/index.js",
|
||||
"src/standalone/index.js",
|
||||
"bin/swarmjs"
|
||||
"bin/swarmapi"
|
||||
],
|
||||
"plugins": [
|
||||
["@babel/plugin-transform-runtime", {
|
||||
|
@ -27,7 +27,7 @@
|
|||
"ignore": [
|
||||
"src/browser.js",
|
||||
"src/standalone/index.js",
|
||||
"bin/swarmjs"
|
||||
"bin/swarmapi"
|
||||
],
|
||||
"plugins": [
|
||||
["@babel/plugin-transform-runtime", {
|
||||
|
|
|
@ -33,8 +33,8 @@ package
|
|||
.vscode
|
||||
.eslintrc.json
|
||||
|
||||
swarmjs.min.js
|
||||
swarmjs-*.tgz
|
||||
swarmapi.min.js
|
||||
swarmapi-*.tgz
|
||||
NOTES
|
||||
npm-debug.log
|
||||
TODO
|
||||
|
|
24
README.md
24
README.md
|
@ -1,27 +1,27 @@
|
|||
# SwarmJS
|
||||
# SwarmAPI
|
||||
A javascript library for interacting with [Swarm](https://swarm-guide.readthedocs.io/en/latest/), a decentralised and distributed storage platform.
|
||||
|
||||
Under the hood, SwarmJS uses the Swarm HTTP API to communicate with the Swarm gateway.
|
||||
Under the hood, SwarmAPI uses the Swarm HTTP API to communicate with the Swarm gateway.
|
||||
## Installation
|
||||
```
|
||||
npm install swarmjs --save
|
||||
npm install swarmapi --save
|
||||
```
|
||||
|
||||
## Basic usage
|
||||
First, import SwarmJS.
|
||||
First, import SwarmAPI.
|
||||
|
||||
Using **CommonJS**:
|
||||
```
|
||||
const SwarmJS = require('swarmjs');
|
||||
const SwarmAPI = require('swarmapi');
|
||||
```
|
||||
Or, with **ES6**:
|
||||
```
|
||||
import SwarmJS from 'swarmjs';
|
||||
import SwarmAPI from 'swarmapi';
|
||||
```
|
||||
Then instantiate SwarmJS, specifying the gateway you'd like to connect to. *If you are [running your own node](https://swarm-guide.readthedocs.io/en/latest/gettingstarted.html) (recommended), the node should be started before proceeding.*
|
||||
Then instantiate SwarmAPI, specifying the gateway you'd like to connect to. *If you are [running your own node](https://swarm-guide.readthedocs.io/en/latest/gettingstarted.html) (recommended), the node should be started before proceeding.*
|
||||
```
|
||||
// instantiate SwarmJS
|
||||
const swarmjs = new SwarmJS({ gateway: 'http://localhost:8500' });
|
||||
// instantiate SwarmAPI
|
||||
const swarmapi = new SwarmAPI({ gateway: 'http://localhost:8500' });
|
||||
```
|
||||
Available options:
|
||||
|
||||
|
@ -33,7 +33,7 @@ NOTE: If no options are provided, the default gateway URL will be `https://swarm
|
|||
##### Check gateway availability
|
||||
```
|
||||
// Check gateway availability
|
||||
swarmjs.isAvailable((err, isAvailable) => {
|
||||
swarmapi.isAvailable((err, isAvailable) => {
|
||||
if(err) return console.error('Error checking Swarm availability', err);
|
||||
console.log(`Gateway at 'http://localhost:8500' is ${isAvailable ? '' : 'un'}available`);
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ swarmjs.isAvailable((err, isAvailable) => {
|
|||
```
|
||||
// Upload of raw content
|
||||
let testHash;
|
||||
swarmjs.uploadRaw('test', (err, hash) => {
|
||||
swarmapi.uploadRaw('test', (err, hash) => {
|
||||
if(err) return console.error('Error uploading contents', err);
|
||||
testHash = hash;
|
||||
console.log(`test can now be accessed from 'http://localhost:8500/bzz-raw:/${hash}'`);
|
||||
|
@ -76,7 +76,7 @@ swarm.uploadDirectory('dist/', (err, hash) => {
|
|||
##### Download content
|
||||
```
|
||||
// Download content via hash
|
||||
swarmjs.downloadRaw(testHash, (err, content) => {
|
||||
swarmapi.downloadRaw(testHash, (err, content) => {
|
||||
if(err) return console.error(err);
|
||||
console.log(`contents of our test: ${content}`);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const SwarmJS = require('../src/index.js');
|
||||
const SwarmAPI = require('../src/index.js');
|
||||
const swarmhash = require('swarmhash');
|
||||
const fs = require('fs');
|
||||
|
||||
|
@ -34,7 +34,7 @@ const yargs = require('yargs')
|
|||
const argv = yargs.argv;
|
||||
const gateway = argv.gateway;
|
||||
const command = argv._[0];
|
||||
const swarmjs = new SwarmJS({gateway});
|
||||
const swarmapi = new SwarmAPI({gateway});
|
||||
|
||||
function abort(msg) {
|
||||
console.log(msg || 'Error occured');
|
||||
|
@ -43,7 +43,7 @@ function abort(msg) {
|
|||
|
||||
switch (command) {
|
||||
case 'get':
|
||||
swarmjs.downloadRaw(argv.hash, function (err, ret) {
|
||||
swarmapi.downloadRaw(argv.hash, function (err, ret) {
|
||||
if (err) {
|
||||
abort('Failed to download: ' + err);
|
||||
} else {
|
||||
|
@ -52,7 +52,7 @@ switch (command) {
|
|||
});
|
||||
break;
|
||||
case 'put':
|
||||
swarmjs.uploadRaw(fs.readFileSync(argv.filename), function (err, ret) {
|
||||
swarmapi.uploadRaw(fs.readFileSync(argv.filename), function (err, ret) {
|
||||
if (err) {
|
||||
console.log('Failed to upload: ' + err);
|
||||
} else {
|
||||
|
@ -64,5 +64,5 @@ switch (command) {
|
|||
console.log('Swarm hash: ' + swarmhash(fs.readFileSync(argv.filename)).toString('hex'));
|
||||
break;
|
||||
default:
|
||||
console.log('Invalid arguments. Type \'swarmjs --help\' for valid options');
|
||||
console.log('Invalid arguments. Type \'swarmapi --help\' for valid options');
|
||||
}
|
|
@ -2,8 +2,8 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>SwarmJS — standalone</title>
|
||||
<script src="swarmjs.min.js"></script>
|
||||
<title>SwarmAPI — standalone</title>
|
||||
<script src="swarmapi.min.js"></script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
|
|
16
package.json
16
package.json
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "swarmjs",
|
||||
"name": "swarmapi",
|
||||
"version": "0.0.1",
|
||||
"description": "JavaScript library for easily interacting with Swarm distributed storage.",
|
||||
"main": "dist/node/index.js",
|
||||
|
@ -8,7 +8,7 @@
|
|||
"./dist/node/index.js": "./dist/browser/browser.js"
|
||||
},
|
||||
"bin": {
|
||||
"swarmjs": "./bin/swarmjs"
|
||||
"swarmapi": "./bin/swarmapi"
|
||||
},
|
||||
"browserslist": [
|
||||
"last 1 version",
|
||||
|
@ -17,8 +17,8 @@
|
|||
],
|
||||
"files": [
|
||||
"dist",
|
||||
"swarmjs.min.js",
|
||||
"bin/swarmjs",
|
||||
"swarmapi.min.js",
|
||||
"bin/swarmapi",
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
|
@ -27,7 +27,7 @@
|
|||
"babel:browser": "cross-env BABEL_ENV=browser babel --out-dir dist/browser src",
|
||||
"babel:node": "cross-env BABEL_ENV=node babel --out-dir dist src",
|
||||
"build": "npm run clean && npm run babel && npm run webpack",
|
||||
"clean": "rimraf dist swarmjs-*.tgz package",
|
||||
"clean": "rimraf dist swarmapi-*.tgz package",
|
||||
"http-server": "http-server",
|
||||
"prepare": "npm run build",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
|
@ -35,7 +35,7 @@
|
|||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/embark-framework/swarmjs.git"
|
||||
"url": "git+https://github.com/embark-framework/swarmapi.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
|
@ -47,9 +47,9 @@
|
|||
"serverless"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/embark-framework/swarmjs/issues"
|
||||
"url": "https://github.com/embark-framework/swarmapi/issues"
|
||||
},
|
||||
"homepage": "https://github.com/embark-framework/swarmjs#readme",
|
||||
"homepage": "https://github.com/embark-framework/swarmapi#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime-corejs2": "7.0.0-rc.1",
|
||||
"klaw": "^3.0.0",
|
||||
|
|
12
src/index.js
12
src/index.js
|
@ -1,13 +1,13 @@
|
|||
/* eslint no-useless-constructor: "off" */
|
||||
const resolve = require('path').resolve;
|
||||
import _SwarmJS from './shared';
|
||||
import _SwarmAPI from './shared';
|
||||
import fs from 'fs';
|
||||
import klaw from 'klaw';
|
||||
import through2 from 'through2';
|
||||
|
||||
class SwarmJS extends _SwarmJS {
|
||||
class SwarmAPI extends _SwarmAPI {
|
||||
|
||||
constructor(opts){
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,9 @@ class SwarmJS extends _SwarmJS {
|
|||
klaw(directory)
|
||||
.pipe(excludeDirFilter)
|
||||
.on('data', (item) => {
|
||||
const itemRelPath = item.path.replace(directory, '');
|
||||
const itemRelPath = item.path.replace(directory, '');
|
||||
readables[itemRelPath.replace('/\\', '_')] = {
|
||||
value: fs.createReadStream(item.path),
|
||||
value: fs.createReadStream(item.path),
|
||||
options: {
|
||||
filepath: itemRelPath
|
||||
}
|
||||
|
@ -54,4 +54,4 @@ class SwarmJS extends _SwarmJS {
|
|||
}
|
||||
}
|
||||
|
||||
export default SwarmJS;
|
||||
export default SwarmAPI;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const request = require('request');
|
||||
|
||||
class _SwarmJS {
|
||||
class SwarmAPI {
|
||||
|
||||
constructor(opts) {
|
||||
this.opts = opts || {};
|
||||
|
@ -83,4 +83,4 @@ class _SwarmJS {
|
|||
}
|
||||
}
|
||||
}
|
||||
export default _SwarmJS;
|
||||
export default SwarmAPI;
|
||||
|
|
|
@ -7,9 +7,9 @@ const standalone = {
|
|||
// minimize: false
|
||||
// },
|
||||
output: {
|
||||
filename: 'swarmjs.min.js',
|
||||
filename: 'swarmapi.min.js',
|
||||
globalObject: 'typeof self !== \'undefined\' ? self : this',
|
||||
library: 'SwarmJS',
|
||||
library: 'SwarmAPI',
|
||||
libraryTarget: 'umd',
|
||||
libraryExport: 'default',
|
||||
path: __dirname,
|
||||
|
|
Loading…
Reference in New Issue