Documentation, comments, and removing extraneous logging

This commit is contained in:
Mitra Ardron 2018-05-30 20:11:33 -07:00
parent d56508d889
commit 1d35e12ee7
10 changed files with 93 additions and 99 deletions

35
API.md
View File

@ -421,24 +421,9 @@ start,end Inclusive byte range wanted - passed to
relay If first transport fails, try and retrieve on 2nd, then store on 1st, and so on. relay If first transport fails, try and retrieve on 2nd, then store on 1st, and so on.
``` ```
##TransportHTTP ## httptools
A subclass of Transport for handling HTTP connections - both directly and for contenthash: urls. A utility class to support HTTP with or without TransportHTTP
e.g. `httptools.http().p_httpfetch("http://foo.com/bar", {method: 'GET'} )`
It looks at `options { http }` for its options.
Option|Default|Meaning
------|-------|-------
urlbase|https://gateway.dweb.me:443|Connect to gateway.dweb.me for contenthash urls
supportURLS = `http:*, https:*, contenthash:*` (TODO: may in the future support `dweb:/contenthash/*`)
supportFunctions:
`fetch, store, add, list, reverse, newlisturls, get, set, keys, getall, delete, newtable, newdatabase`
supportFeatures:
`fetch.range` i.e. it will fetch a range of bytes if specified in {start, end} to p_rawfetch()
###Other useful functions
The HTTP Transport can be used for utility functions as well as via the Transports interface.
e.g. Transports.http().p_httpfetch("http://foo.com/bar", {method: 'GET'} )
##### p_httpfetch(url, init, verbose) ##### p_httpfetch(url, init, verbose)
Fetch a url. Fetch a url.
@ -467,6 +452,20 @@ Shortcut to do a HTTP/HTTPS POST. sets same options as p_GET
data: Data to send to fetch, typically the body, data: Data to send to fetch, typically the body,
type: Currently not passed as header{Content-type} because fetch appears to ignore it. type: Currently not passed as header{Content-type} because fetch appears to ignore it.
## TransportHTTP
A subclass of Transport for handling HTTP connections - both directly and for contenthash: urls.
It looks at `options { http }` for its options.
Option|Default|Meaning
------|-------|-------
urlbase|https://gateway.dweb.me:443|Connect to gateway.dweb.me for contenthash urls
supportURLS|http:*, https:*, contenthash:*}| (TODO: may in the future support `dweb:/contenthash/*`)
supportFunctions|fetch, store, add, list, reverse, newlisturls, get, set, keys, getall, delete, newtable, newdatabase|
supportFeatures|fetch.range|it will fetch a range of bytes if specified in {start, end} to p_rawfetch()
## TransportIPFS ## TransportIPFS
A subclass of Transport for handling IPFS connections A subclass of Transport for handling IPFS connections

View File

@ -18,8 +18,8 @@ decentralized transports.
to your package.json file in the dependencies section. to your package.json file in the dependencies section.
* `npm install dweb-transports` will install the dependencies including IPFS & WebTorrent * `npm install dweb-transports` will install the dependencies including IPFS & WebTorrent
`const DwebTransports = require(dweb-transport)` will add all Transports to a Javascript file. `const DwebTransports = require("dweb-transports")` will add all Transports to a Javascript file.
* TODO writeup how to require only some of the transports. * TODO-API writeup how to require only some of the transports.
* Then see usage API below * Then see usage API below
### Installation and usage in the Browser ### Installation and usage in the Browser

View File

@ -53,7 +53,7 @@ class Transport {
return t.p_setup2(verbose, cb); // And connect return t.p_setup2(verbose, cb); // And connect
} }
togglePaused(cb) { //TODO-SW move to Transports > TransportsProxy > UI togglePaused(cb) {
/* /*
Switch the state of the transport between STATUS_CONNECTED and STATUS_PAUSED, Switch the state of the transport between STATUS_CONNECTED and STATUS_PAUSED,
in the paused state it will not be used for transport but, in some cases, will still do background tasks like serving files. in the paused state it will not be used for transport but, in some cases, will still do background tasks like serving files.

View File

@ -89,8 +89,8 @@ class TransportHTTP extends Transport {
//if (!(url && url.includes(':') )) //if (!(url && url.includes(':') ))
// throw new errors.CodingError("TransportHTTP.p_rawfetch bad url: "+url); // throw new errors.CodingError("TransportHTTP.p_rawfetch bad url: "+url);
if (((typeof url === "string") ? url : url.href).includes('/getall/table')) { if (((typeof url === "string") ? url : url.href).includes('/getall/table')) {
console.log("XXX@176 - probably dont want to be calling p_rawfetch on a KeyValueTable, especially since dont know if its keyvaluetable or subclass"); //TODO-NAMING throw new Error("Probably dont want to be calling p_rawfetch on a KeyValueTable, especially since dont know if its keyvaluetable or subclass"); //TODO-NAMING
return { return { // I'm not sure what this return would have done - looks half finished to me?
table: "keyvaluetable", table: "keyvaluetable",
} }
} else { } else {
@ -122,7 +122,7 @@ class TransportHTTP extends Transport {
} }
p_rawadd(url, sig, {verbose=false}={}) { //TODO-BACKPORT turn date into ISO before adding p_rawadd(url, sig, {verbose=false}={}) {
//verbose=true; //verbose=true;
if (!url || !sig) throw new errors.CodingError("TransportHTTP.p_rawadd: invalid parms",url, sig); if (!url || !sig) throw new errors.CodingError("TransportHTTP.p_rawadd: invalid parms",url, sig);
if (verbose) console.log("rawadd", url, sig); if (verbose) console.log("rawadd", url, sig);
@ -166,7 +166,7 @@ class TransportHTTP extends Transport {
} }
//TODO-KEYVALUE needs signing with private key of list //TODO-KEYVALUE needs signing with private key of list
async p_set(url, keyvalues, value, {verbose=false}={}) { // url = yjs:/yjs/database/table/key //TODO-KEYVALUE-API async p_set(url, keyvalues, value, {verbose=false}={}) { // url = yjs:/yjs/database/table/key
if (!url || !keyvalues) throw new errors.CodingError("TransportHTTP.p_set: invalid parms",url, keyvalyes); if (!url || !keyvalues) throw new errors.CodingError("TransportHTTP.p_set: invalid parms",url, keyvalyes);
if (verbose) console.log("p_set", url, keyvalues, value); if (verbose) console.log("p_set", url, keyvalues, value);
if (typeof keyvalues === "string") { if (typeof keyvalues === "string") {
@ -188,7 +188,7 @@ class TransportHTTP extends Transport {
return Array.isArray(keys) ? res : res[keys] return Array.isArray(keys) ? res : res[keys]
} }
async p_delete(url, keys, {verbose=false}={}) { //TODO-KEYVALUE-API need to think this one through async p_delete(url, keys, {verbose=false}={}) {
if (!url && keys) throw new errors.CodingError("TransportHTTP.p_get: requires url and at least one key"); if (!url && keys) throw new errors.CodingError("TransportHTTP.p_get: requires url and at least one key");
let parmstr = keys.map(k => this._keyparm(k)).join('&'); let parmstr = keys.map(k => this._keyparm(k)).join('&');
await httptools.p_GET(this._url(url, servercommands.delete, parmstr), {verbose}); await httptools.p_GET(this._url(url, servercommands.delete, parmstr), {verbose});

View File

@ -190,7 +190,7 @@ class TransportIPFS extends Transport {
throw new errors.CodingError(`TransportIPFS.ipfsFrom: Cant convert url ${url} into a path starting /ipfs/`); throw new errors.CodingError(`TransportIPFS.ipfsFrom: Cant convert url ${url} into a path starting /ipfs/`);
} }
static ipfsGatewayFrom(url) { //TODO-API static ipfsGatewayFrom(url) {
/* /*
url: CID, Url, or a string url: CID, Url, or a string
returns: https://ipfs.io/ipfs/<cid> returns: https://ipfs.io/ipfs/<cid>

View File

@ -239,7 +239,6 @@ class TransportWEBTORRENT extends Transport {
let filet = await this._p_fileTorrentFromUrl(url); let filet = await this._p_fileTorrentFromUrl(url);
let self = this; let self = this;
if (wanturl) { if (wanturl) {
console.log("XXX@WT:242 returning",url)
return url; return url;
} else { } else {
return function (opts) { return self.createReadStream(filet, opts, verbose); }; return function (opts) { return self.createReadStream(filet, opts, verbose); };

View File

@ -252,7 +252,7 @@ class TransportYJS extends Transport {
return { privateurl: `${database.privateurl}/${table}`, publicurl: `${database.publicurl}/${table}`} // No action required to create it return { privateurl: `${database.privateurl}/${table}`, publicurl: `${database.publicurl}/${table}`} // No action required to create it
} }
async p_set(url, keyvalues, value, {verbose=false}={}) { // url = yjs:/yjs/database/table/key //TODO-KEYVALUE-API async p_set(url, keyvalues, value, {verbose=false}={}) { // url = yjs:/yjs/database/table/key
let y = await this.p_connection(url, verbose); let y = await this.p_connection(url, verbose);
if (typeof keyvalues === "string") { if (typeof keyvalues === "string") {
y.share.map.set(keyvalues, JSON.stringify(value)); y.share.map.set(keyvalues, JSON.stringify(value));
@ -272,11 +272,11 @@ class TransportYJS extends Transport {
return typeof val === "string" ? JSON.parse(val) : val; // Surprisingly this is sync, the p_connection should have synchronised return typeof val === "string" ? JSON.parse(val) : val; // Surprisingly this is sync, the p_connection should have synchronised
} }
} }
async p_get(url, keys, {verbose=false}={}) { //TODO-KEYVALUE-API - return dict or single async p_get(url, keys, {verbose=false}={}) {
return this._p_get(await this.p_connection(url, verbose), keys, {verbose}); return this._p_get(await this.p_connection(url, verbose), keys, {verbose});
} }
async p_delete(url, keys, {verbose=false}={}) { //TODO-KEYVALUE-API async p_delete(url, keys, {verbose=false}={}) {
let y = await this.p_connection(url, verbose); let y = await this.p_connection(url, verbose);
if (typeof keys === "string") { if (typeof keys === "string") {
y.share.map.delete(keys); y.share.map.delete(keys);

View File

@ -328,7 +328,7 @@ class Transports {
} }
} }
static async p_delete(urls, keys, {verbose=false}={}) { //TODO-KEYVALUE-API static async p_delete(urls, keys, {verbose=false}={}) {
/* Delete a key or a list of keys /* Delete a key or a list of keys
kv: Either dict or a string kv: Either dict or a string
value: if kv is a string, this is the value to set value: if kv is a string, this is the value to set
@ -555,7 +555,7 @@ class Transports {
if (verbose) console.groupEnd("p_connect ---"); if (verbose) console.groupEnd("p_connect ---");
} }
static async p_urlsFrom(url) { //TODO backport to main repo - copy from htmlutils to utils static async p_urlsFrom(url) {
/* Utility to convert to urls form wanted for Transports functions, e.g. from user input /* Utility to convert to urls form wanted for Transports functions, e.g. from user input
url: Array of urls, or string representing url or representing array of urls url: Array of urls, or string representing url or representing array of urls
return: Array of strings representing url return: Array of strings representing url

View File

@ -1,8 +1,6 @@
const nodefetch = require('node-fetch'); // Note, were using node-fetch-npm which had a warning in webpack see https://github.com/bitinn/node-fetch/issues/421 and is intended for clients const nodefetch = require('node-fetch'); // Note, were using node-fetch-npm which had a warning in webpack see https://github.com/bitinn/node-fetch/issues/421 and is intended for clients
const errors = require('./Errors'); // Standard Dweb Errors const errors = require('./Errors'); // Standard Dweb Errors
//TODO-API move separate out httptools to own part of API.md
//var fetch,Headers,Request; //var fetch,Headers,Request;
//if (typeof(Window) === "undefined") { //if (typeof(Window) === "undefined") {
if (typeof(fetch) === "undefined") { if (typeof(fetch) === "undefined") {

View File

@ -93,9 +93,7 @@ async function test_files_cat(cid, expected, expectfailure) {
if (expectfailure && !tryexpectedfailures) return; if (expectfailure && !tryexpectedfailures) return;
console.log("testing via files.cat") console.log("testing via files.cat")
cid = ipfsFrom(cid); // Turn it into the /ipfs/Q... form that files.cat now expects cid = ipfsFrom(cid); // Turn it into the /ipfs/Q... form that files.cat now expects
console.log("XXX@95 passing cid=",cid);
buff = await ipfs.files.cat(cid); //Error: Groups are not supported in the blocks case - never returns from this call. buff = await ipfs.files.cat(cid); //Error: Groups are not supported in the blocks case - never returns from this call.
console.log("XXX@97")
check_result("files.cat", buff, expected, expectfailure); check_result("files.cat", buff, expected, expectfailure);
} catch(err) { } catch(err) {
console.log("Error thrown in files.cat", err); console.log("Error thrown in files.cat", err);