mirror of
https://github.com/fluencelabs/dweb-transports
synced 2025-04-25 06:42:17 +00:00
Documentation, comments, and removing extraneous logging
This commit is contained in:
parent
d56508d889
commit
1d35e12ee7
35
API.md
35
API.md
@ -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.
|
||||
```
|
||||
|
||||
##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` 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'} )
|
||||
## httptools
|
||||
A utility class to support HTTP with or without TransportHTTP
|
||||
e.g. `httptools.http().p_httpfetch("http://foo.com/bar", {method: 'GET'} )`
|
||||
|
||||
##### p_httpfetch(url, init, verbose)
|
||||
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,
|
||||
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
|
||||
A subclass of Transport for handling IPFS connections
|
||||
|
||||
|
@ -18,8 +18,8 @@ decentralized transports.
|
||||
to your package.json file in the dependencies section.
|
||||
* `npm install dweb-transports` will install the dependencies including IPFS & WebTorrent
|
||||
|
||||
`const DwebTransports = require(dweb-transport)` will add all Transports to a Javascript file.
|
||||
* TODO writeup how to require only some of the transports.
|
||||
`const DwebTransports = require("dweb-transports")` will add all Transports to a Javascript file.
|
||||
* TODO-API writeup how to require only some of the transports.
|
||||
* Then see usage API below
|
||||
|
||||
### Installation and usage in the Browser
|
||||
|
@ -53,7 +53,7 @@ class Transport {
|
||||
|
||||
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,
|
||||
in the paused state it will not be used for transport but, in some cases, will still do background tasks like serving files.
|
||||
|
@ -89,8 +89,8 @@ class TransportHTTP extends Transport {
|
||||
//if (!(url && url.includes(':') ))
|
||||
// throw new errors.CodingError("TransportHTTP.p_rawfetch bad url: "+url);
|
||||
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
|
||||
return {
|
||||
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 { // I'm not sure what this return would have done - looks half finished to me?
|
||||
table: "keyvaluetable",
|
||||
}
|
||||
} 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;
|
||||
if (!url || !sig) throw new errors.CodingError("TransportHTTP.p_rawadd: invalid parms",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
|
||||
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 (verbose) console.log("p_set", url, keyvalues, value);
|
||||
if (typeof keyvalues === "string") {
|
||||
@ -188,7 +188,7 @@ class TransportHTTP extends Transport {
|
||||
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");
|
||||
let parmstr = keys.map(k => this._keyparm(k)).join('&');
|
||||
await httptools.p_GET(this._url(url, servercommands.delete, parmstr), {verbose});
|
||||
|
@ -190,7 +190,7 @@ class TransportIPFS extends Transport {
|
||||
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
|
||||
returns: https://ipfs.io/ipfs/<cid>
|
||||
|
@ -239,7 +239,6 @@ class TransportWEBTORRENT extends Transport {
|
||||
let filet = await this._p_fileTorrentFromUrl(url);
|
||||
let self = this;
|
||||
if (wanturl) {
|
||||
console.log("XXX@WT:242 returning",url)
|
||||
return url;
|
||||
} else {
|
||||
return function (opts) { return self.createReadStream(filet, opts, verbose); };
|
||||
|
@ -252,7 +252,7 @@ class TransportYJS extends Transport {
|
||||
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);
|
||||
if (typeof keyvalues === "string") {
|
||||
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
|
||||
}
|
||||
}
|
||||
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});
|
||||
}
|
||||
|
||||
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);
|
||||
if (typeof keys === "string") {
|
||||
y.share.map.delete(keys);
|
||||
|
@ -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
|
||||
kv: Either dict or a string
|
||||
value: if kv is a string, this is the value to set
|
||||
@ -555,7 +555,7 @@ class Transports {
|
||||
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
|
||||
url: Array of urls, or string representing url or representing array of urls
|
||||
return: Array of strings representing url
|
||||
|
@ -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 errors = require('./Errors'); // Standard Dweb Errors
|
||||
|
||||
//TODO-API move separate out httptools to own part of API.md
|
||||
|
||||
//var fetch,Headers,Request;
|
||||
//if (typeof(Window) === "undefined") {
|
||||
if (typeof(fetch) === "undefined") {
|
||||
|
@ -93,9 +93,7 @@ async function test_files_cat(cid, expected, expectfailure) {
|
||||
if (expectfailure && !tryexpectedfailures) return;
|
||||
console.log("testing via files.cat")
|
||||
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.
|
||||
console.log("XXX@97")
|
||||
check_result("files.cat", buff, expected, expectfailure);
|
||||
} catch(err) {
|
||||
console.log("Error thrown in files.cat", err);
|
||||
|
Loading…
x
Reference in New Issue
Block a user