import * as http_data from "./http-data";
import * as urlModule from "url";
const transferrers = {};

function transfer(request) {
  // url - the resource URI to send a message to
  // options.method   - the method to use for transferring
  // options.form     - the Form API object representing the form data submission
  //                    converted to a message body via encoding (see: options.enctype)
  // options.enctype  - the encoding to use to encode form into message body
  // options.body     - an already encoded message body
  //                    if both body and form are present, form is ignored
  if (!request) throw new Error("'request' param is required.");
  
  var url = request.url;
  var options = request.options;
  
  if (!url) throw new Error("'request.url' param is required.");
  
  var protocol = urlModule.parse(url).protocol;
  if (!protocol) throw new Error("'request.url' param must have a protocol scheme.");
  
  protocol = protocol.replace(":", "");
  if (protocol in transferrers === false) throw new Error("No transferrer registered for protocol: " + protocol);
  
  var transferrer = transferrers[protocol];
  return transferrer(request);
}

transfer.register = function registerTransferrer(scheme, transferrer) {
  transferrers[scheme] = transferrer;
};

transfer.register("http", http_data.transfer);
transfer.register("data", http_data.transfer);

export { transfer };

@@ -72,33 +72,8 @@
 rl%22;
-%0Aconst transferrers = %7B%7D;
 %0A%0Afu
@@ -985,19 +985,29 @@
 transfer
+.
 re
-r
+gistration
 s === fa
@@ -1114,19 +1114,29 @@
 transfer
+.
 re
-r
+gistration
 s%5Bprotoc
@@ -1174,16 +1174,46 @@
 st);%0A%7D%0A%0A
+transfer.registrations = %7B%7D;%0A%0A
 transfer
@@ -1253,22 +1253,24 @@
 sferrer(
-scheme
+protocol
 , transf
@@ -1292,19 +1292,31 @@
 sfer
+.
 re
-rs%5Bscheme
+gistrations%5Bprotocol
 %5D = 

Make Transfer Consistent w/ Views