@feathersjs/client
Version:
A module that consolidates Feathers client modules for REST (jQuery, Request, Superagent) and Websocket (Socket.io, Primus) connections
1,445 lines (1,211 loc) • 44.5 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["feathers"] = factory();
else
root["feathers"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./src/socketio.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "../../node_modules/debug/src/browser.js":
/*!**************************************************************************************!*\
!*** /Users/daffl/Development/feathersjs/feathers/node_modules/debug/src/browser.js ***!
\**************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/* eslint-env browser */
/**
* This is the web browser implementation of `debug()`.
*/
exports.log = log;
exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
exports.storage = localstorage();
/**
* Colors.
*/
exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
/**
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
* and the Firebug extension (any Firefox version) are known
* to support "%c" CSS customizations.
*
* TODO: add a `localStorage` variable to explicitly enable/disable colors
*/
// eslint-disable-next-line complexity
function useColors() {
// NB: In an Electron preload script, document will be defined but not fully
// initialized. Since we know we're in Chrome, we'll just detect this case
// explicitly
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
return true;
} // Internet Explorer and Edge do not support colors.
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
return false;
} // Is webkit? http://stackoverflow.com/a/16459606/376773
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
}
/**
* Colorize log arguments if enabled.
*
* @api public
*/
function formatArgs(args) {
args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
if (!this.useColors) {
return;
}
var c = 'color: ' + this.color;
args.splice(1, 0, c, 'color: inherit'); // The final "%c" is somewhat tricky, because there could be other
// arguments passed either before or after the %c, so we need to
// figure out the correct index to insert the CSS into
var index = 0;
var lastC = 0;
args[0].replace(/%[a-zA-Z%]/g, function (match) {
if (match === '%%') {
return;
}
index++;
if (match === '%c') {
// We only are interested in the *last* %c
// (the user may have provided their own)
lastC = index;
}
});
args.splice(lastC, 0, c);
}
/**
* Invokes `console.log()` when available.
* No-op when `console.log` is not a "function".
*
* @api public
*/
function log() {
var _console;
// This hackery is required for IE8/9, where
// the `console.log` function doesn't have 'apply'
return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
}
/**
* Save `namespaces`.
*
* @param {String} namespaces
* @api private
*/
function save(namespaces) {
try {
if (namespaces) {
exports.storage.setItem('debug', namespaces);
} else {
exports.storage.removeItem('debug');
}
} catch (error) {// Swallow
// XXX (@Qix-) should we be logging these?
}
}
/**
* Load `namespaces`.
*
* @return {String} returns the previously persisted debug modes
* @api private
*/
function load() {
var r;
try {
r = exports.storage.getItem('debug');
} catch (error) {// Swallow
// XXX (@Qix-) should we be logging these?
} // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
if (!r && typeof process !== 'undefined' && 'env' in process) {
r = process.env.DEBUG;
}
return r;
}
/**
* Localstorage attempts to return the localstorage.
*
* This is necessary because safari throws
* when a user disables cookies/localstorage
* and you attempt to access it.
*
* @return {LocalStorage}
* @api private
*/
function localstorage() {
try {
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
// The Browser also has localStorage in the global context.
return localStorage;
} catch (error) {// Swallow
// XXX (@Qix-) should we be logging these?
}
}
module.exports = __webpack_require__(/*! ./common */ "../../node_modules/debug/src/common.js")(exports);
var formatters = module.exports.formatters;
/**
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
*/
formatters.j = function (v) {
try {
return JSON.stringify(v);
} catch (error) {
return '[UnexpectedJSONParseError]: ' + error.message;
}
};
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../process/browser.js */ "../../node_modules/process/browser.js")))
/***/ }),
/***/ "../../node_modules/debug/src/common.js":
/*!*************************************************************************************!*\
!*** /Users/daffl/Development/feathersjs/feathers/node_modules/debug/src/common.js ***!
\*************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**
* This is the common logic for both the Node.js and web browser
* implementations of `debug()`.
*/
function setup(env) {
createDebug.debug = createDebug;
createDebug.default = createDebug;
createDebug.coerce = coerce;
createDebug.disable = disable;
createDebug.enable = enable;
createDebug.enabled = enabled;
createDebug.humanize = __webpack_require__(/*! ms */ "../../node_modules/ms/index.js");
Object.keys(env).forEach(function (key) {
createDebug[key] = env[key];
});
/**
* Active `debug` instances.
*/
createDebug.instances = [];
/**
* The currently active debug mode names, and names to skip.
*/
createDebug.names = [];
createDebug.skips = [];
/**
* Map of special "%n" handling functions, for the debug "format" argument.
*
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
*/
createDebug.formatters = {};
/**
* Selects a color for a debug namespace
* @param {String} namespace The namespace string for the for the debug instance to be colored
* @return {Number|String} An ANSI color code for the given namespace
* @api private
*/
function selectColor(namespace) {
var hash = 0;
for (var i = 0; i < namespace.length; i++) {
hash = (hash << 5) - hash + namespace.charCodeAt(i);
hash |= 0; // Convert to 32bit integer
}
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
}
createDebug.selectColor = selectColor;
/**
* Create a debugger with the given `namespace`.
*
* @param {String} namespace
* @return {Function}
* @api public
*/
function createDebug(namespace) {
var prevTime;
function debug() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
// Disabled?
if (!debug.enabled) {
return;
}
var self = debug; // Set `diff` timestamp
var curr = Number(new Date());
var ms = curr - (prevTime || curr);
self.diff = ms;
self.prev = prevTime;
self.curr = curr;
prevTime = curr;
args[0] = createDebug.coerce(args[0]);
if (typeof args[0] !== 'string') {
// Anything else let's inspect with %O
args.unshift('%O');
} // Apply any `formatters` transformations
var index = 0;
args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
// If we encounter an escaped % then don't increase the array index
if (match === '%%') {
return match;
}
index++;
var formatter = createDebug.formatters[format];
if (typeof formatter === 'function') {
var val = args[index];
match = formatter.call(self, val); // Now we need to remove `args[index]` since it's inlined in the `format`
args.splice(index, 1);
index--;
}
return match;
}); // Apply env-specific formatting (colors, etc.)
createDebug.formatArgs.call(self, args);
var logFn = self.log || createDebug.log;
logFn.apply(self, args);
}
debug.namespace = namespace;
debug.enabled = createDebug.enabled(namespace);
debug.useColors = createDebug.useColors();
debug.color = selectColor(namespace);
debug.destroy = destroy;
debug.extend = extend; // Debug.formatArgs = formatArgs;
// debug.rawLog = rawLog;
// env-specific initialization logic for debug instances
if (typeof createDebug.init === 'function') {
createDebug.init(debug);
}
createDebug.instances.push(debug);
return debug;
}
function destroy() {
var index = createDebug.instances.indexOf(this);
if (index !== -1) {
createDebug.instances.splice(index, 1);
return true;
}
return false;
}
function extend(namespace, delimiter) {
var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
newDebug.log = this.log;
return newDebug;
}
/**
* Enables a debug mode by namespaces. This can include modes
* separated by a colon and wildcards.
*
* @param {String} namespaces
* @api public
*/
function enable(namespaces) {
createDebug.save(namespaces);
createDebug.names = [];
createDebug.skips = [];
var i;
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
var len = split.length;
for (i = 0; i < len; i++) {
if (!split[i]) {
// ignore empty strings
continue;
}
namespaces = split[i].replace(/\*/g, '.*?');
if (namespaces[0] === '-') {
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
} else {
createDebug.names.push(new RegExp('^' + namespaces + '$'));
}
}
for (i = 0; i < createDebug.instances.length; i++) {
var instance = createDebug.instances[i];
instance.enabled = createDebug.enabled(instance.namespace);
}
}
/**
* Disable debug output.
*
* @return {String} namespaces
* @api public
*/
function disable() {
var namespaces = [].concat(_toConsumableArray(createDebug.names.map(toNamespace)), _toConsumableArray(createDebug.skips.map(toNamespace).map(function (namespace) {
return '-' + namespace;
}))).join(',');
createDebug.enable('');
return namespaces;
}
/**
* Returns true if the given mode name is enabled, false otherwise.
*
* @param {String} name
* @return {Boolean}
* @api public
*/
function enabled(name) {
if (name[name.length - 1] === '*') {
return true;
}
var i;
var len;
for (i = 0, len = createDebug.skips.length; i < len; i++) {
if (createDebug.skips[i].test(name)) {
return false;
}
}
for (i = 0, len = createDebug.names.length; i < len; i++) {
if (createDebug.names[i].test(name)) {
return true;
}
}
return false;
}
/**
* Convert regexp to namespace
*
* @param {RegExp} regxep
* @return {String} namespace
* @api private
*/
function toNamespace(regexp) {
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
}
/**
* Coerce `val`.
*
* @param {Mixed} val
* @return {Mixed}
* @api private
*/
function coerce(val) {
if (val instanceof Error) {
return val.stack || val.message;
}
return val;
}
createDebug.enable(createDebug.load());
return createDebug;
}
module.exports = setup;
/***/ }),
/***/ "../../node_modules/ms/index.js":
/*!*****************************************************************************!*\
!*** /Users/daffl/Development/feathersjs/feathers/node_modules/ms/index.js ***!
\*****************************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
/**
* Helpers.
*/
var s = 1000;
var m = s * 60;
var h = m * 60;
var d = h * 24;
var w = d * 7;
var y = d * 365.25;
/**
* Parse or format the given `val`.
*
* Options:
*
* - `long` verbose formatting [false]
*
* @param {String|Number} val
* @param {Object} [options]
* @throws {Error} throw an error if val is not a non-empty string or a number
* @return {String|Number}
* @api public
*/
module.exports = function(val, options) {
options = options || {};
var type = typeof val;
if (type === 'string' && val.length > 0) {
return parse(val);
} else if (type === 'number' && isFinite(val)) {
return options.long ? fmtLong(val) : fmtShort(val);
}
throw new Error(
'val is not a non-empty string or a valid number. val=' +
JSON.stringify(val)
);
};
/**
* Parse the given `str` and return milliseconds.
*
* @param {String} str
* @return {Number}
* @api private
*/
function parse(str) {
str = String(str);
if (str.length > 100) {
return;
}
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
str
);
if (!match) {
return;
}
var n = parseFloat(match[1]);
var type = (match[2] || 'ms').toLowerCase();
switch (type) {
case 'years':
case 'year':
case 'yrs':
case 'yr':
case 'y':
return n * y;
case 'weeks':
case 'week':
case 'w':
return n * w;
case 'days':
case 'day':
case 'd':
return n * d;
case 'hours':
case 'hour':
case 'hrs':
case 'hr':
case 'h':
return n * h;
case 'minutes':
case 'minute':
case 'mins':
case 'min':
case 'm':
return n * m;
case 'seconds':
case 'second':
case 'secs':
case 'sec':
case 's':
return n * s;
case 'milliseconds':
case 'millisecond':
case 'msecs':
case 'msec':
case 'ms':
return n;
default:
return undefined;
}
}
/**
* Short format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api private
*/
function fmtShort(ms) {
var msAbs = Math.abs(ms);
if (msAbs >= d) {
return Math.round(ms / d) + 'd';
}
if (msAbs >= h) {
return Math.round(ms / h) + 'h';
}
if (msAbs >= m) {
return Math.round(ms / m) + 'm';
}
if (msAbs >= s) {
return Math.round(ms / s) + 's';
}
return ms + 'ms';
}
/**
* Long format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api private
*/
function fmtLong(ms) {
var msAbs = Math.abs(ms);
if (msAbs >= d) {
return plural(ms, msAbs, d, 'day');
}
if (msAbs >= h) {
return plural(ms, msAbs, h, 'hour');
}
if (msAbs >= m) {
return plural(ms, msAbs, m, 'minute');
}
if (msAbs >= s) {
return plural(ms, msAbs, s, 'second');
}
return ms + ' ms';
}
/**
* Pluralization helper.
*/
function plural(ms, msAbs, n, name) {
var isPlural = msAbs >= n * 1.5;
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
}
/***/ }),
/***/ "../../node_modules/process/browser.js":
/*!************************************************************************************!*\
!*** /Users/daffl/Development/feathersjs/feathers/node_modules/process/browser.js ***!
\************************************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ }),
/***/ "../errors/lib/index.js":
/*!******************************!*\
!*** ../errors/lib/index.js ***!
\******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var debug = __webpack_require__(/*! debug */ "../../node_modules/debug/src/browser.js")('@feathersjs/errors');
function FeathersError(msg, name, code, className, data) {
msg = msg || 'Error';
var errors;
var message;
var newData;
if (msg instanceof Error) {
message = msg.message || 'Error'; // NOTE (EK): This is typically to handle validation errors
if (msg.errors) {
errors = msg.errors;
}
} else if (_typeof(msg) === 'object') {
// Support plain old objects
message = msg.message || 'Error';
data = msg;
} else {
// message is just a string
message = msg;
}
if (data) {
// NOTE(EK): To make sure that we are not messing
// with immutable data, just make a copy.
// https://github.com/feathersjs/errors/issues/19
newData = JSON.parse(JSON.stringify(data));
if (newData.errors) {
errors = newData.errors;
delete newData.errors;
} else if (data.errors) {
// The errors property from data could be
// stripped away while cloning resulting newData not to have it
// For example: when cloning arrays this property
errors = JSON.parse(JSON.stringify(data.errors));
}
} // NOTE (EK): Babel doesn't support this so
// we have to pass in the class name manually.
// this.name = this.constructor.name;
this.type = 'FeathersError';
this.name = name;
this.message = message;
this.code = code;
this.className = className;
this.data = newData;
this.errors = errors || {};
debug("".concat(this.name, "(").concat(this.code, "): ").concat(this.message));
debug(this.errors);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, FeathersError);
} else {
this.stack = new Error().stack;
}
}
function inheritsFrom(Child, Parent) {
Child.prototype = Object.create(Parent.prototype);
Child.prototype.constructor = Child;
}
inheritsFrom(FeathersError, Error); // NOTE (EK): A little hack to get around `message` not
// being included in the default toJSON call.
Object.defineProperty(FeathersError.prototype, 'toJSON', {
value: function value() {
return {
name: this.name,
message: this.message,
code: this.code,
className: this.className,
data: this.data,
errors: this.errors
};
}
}); // 400 - Bad Request
function BadRequest(message, data) {
FeathersError.call(this, message, 'BadRequest', 400, 'bad-request', data);
}
inheritsFrom(BadRequest, FeathersError); // 401 - Not Authenticated
function NotAuthenticated(message, data) {
FeathersError.call(this, message, 'NotAuthenticated', 401, 'not-authenticated', data);
}
inheritsFrom(NotAuthenticated, FeathersError); // 402 - Payment Error
function PaymentError(message, data) {
FeathersError.call(this, message, 'PaymentError', 402, 'payment-error', data);
}
inheritsFrom(PaymentError, FeathersError); // 403 - Forbidden
function Forbidden(message, data) {
FeathersError.call(this, message, 'Forbidden', 403, 'forbidden', data);
}
inheritsFrom(Forbidden, FeathersError); // 404 - Not Found
function NotFound(message, data) {
FeathersError.call(this, message, 'NotFound', 404, 'not-found', data);
}
inheritsFrom(NotFound, FeathersError); // 405 - Method Not Allowed
function MethodNotAllowed(message, data) {
FeathersError.call(this, message, 'MethodNotAllowed', 405, 'method-not-allowed', data);
}
inheritsFrom(MethodNotAllowed, FeathersError); // 406 - Not Acceptable
function NotAcceptable(message, data) {
FeathersError.call(this, message, 'NotAcceptable', 406, 'not-acceptable', data);
}
inheritsFrom(NotAcceptable, FeathersError); // 408 - Timeout
function Timeout(message, data) {
FeathersError.call(this, message, 'Timeout', 408, 'timeout', data);
}
inheritsFrom(Timeout, FeathersError); // 409 - Conflict
function Conflict(message, data) {
FeathersError.call(this, message, 'Conflict', 409, 'conflict', data);
}
inheritsFrom(Conflict, FeathersError); // 410 - Gone
function Gone(message, data) {
FeathersError(this, message, 'Gone', 410, 'gone', data);
}
inheritsFrom(Gone, FeathersError); // 411 - Length Required
function LengthRequired(message, data) {
FeathersError.call(this, message, 'LengthRequired', 411, 'length-required', data);
}
inheritsFrom(LengthRequired, FeathersError); // 422 Unprocessable
function Unprocessable(message, data) {
FeathersError.call(this, message, 'Unprocessable', 422, 'unprocessable', data);
}
inheritsFrom(Unprocessable, FeathersError); // 429 Too Many Requests
function TooManyRequests(message, data) {
FeathersError.call(this, message, 'TooManyRequests', 429, 'too-many-requests', data);
}
inheritsFrom(TooManyRequests, FeathersError); // 500 - General Error
function GeneralError(message, data) {
FeathersError.call(this, message, 'GeneralError', 500, 'general-error', data);
}
inheritsFrom(GeneralError, FeathersError); // 501 - Not Implemented
function NotImplemented(message, data) {
FeathersError.call(this, message, 'NotImplemented', 501, 'not-implemented', data);
}
inheritsFrom(NotImplemented, FeathersError); // 502 - Bad Gateway
function BadGateway(message, data) {
FeathersError.call(this, message, 'BadGateway', 502, 'bad-gateway', data);
}
inheritsFrom(BadGateway, FeathersError); // 503 - Unavailable
function Unavailable(message, data) {
FeathersError.call(this, message, 'Unavailable', 503, 'unavailable', data);
}
inheritsFrom(Unavailable, FeathersError);
var errors = {
FeathersError: FeathersError,
BadRequest: BadRequest,
NotAuthenticated: NotAuthenticated,
PaymentError: PaymentError,
Forbidden: Forbidden,
NotFound: NotFound,
MethodNotAllowed: MethodNotAllowed,
NotAcceptable: NotAcceptable,
Timeout: Timeout,
Conflict: Conflict,
Gone: Gone,
LengthRequired: LengthRequired,
Unprocessable: Unprocessable,
TooManyRequests: TooManyRequests,
GeneralError: GeneralError,
NotImplemented: NotImplemented,
BadGateway: BadGateway,
Unavailable: Unavailable,
400: BadRequest,
401: NotAuthenticated,
402: PaymentError,
403: Forbidden,
404: NotFound,
405: MethodNotAllowed,
406: NotAcceptable,
408: Timeout,
409: Conflict,
410: Gone,
411: LengthRequired,
422: Unprocessable,
429: TooManyRequests,
500: GeneralError,
501: NotImplemented,
502: BadGateway,
503: Unavailable
};
function convert(error) {
if (!error) {
return error;
}
var FeathersError = errors[error.name];
var result = FeathersError ? new FeathersError(error.message, error.data) : new Error(error.message || error);
if (_typeof(error) === 'object') {
Object.assign(result, error);
}
return result;
}
module.exports = Object.assign({
convert: convert
}, errors);
/***/ }),
/***/ "../socketio-client/lib/index.js":
/*!***************************************!*\
!*** ../socketio-client/lib/index.js ***!
\***************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
var Service = __webpack_require__(/*! @feathersjs/transport-commons/client */ "../transport-commons/client.js");
function socketioClient(connection, options) {
if (!connection) {
throw new Error('Socket.io connection needs to be provided');
}
var defaultService = function defaultService(name) {
var _this = this;
var events = Object.keys(this.eventMappings || {}).map(function (method) {
return _this.eventMappings[method];
});
var settings = Object.assign({}, options, {
events: events,
name: name,
connection: connection,
method: 'emit'
});
return new Service(settings);
};
var initialize = function initialize(app) {
if (typeof app.defaultService === 'function') {
throw new Error('Only one default client provider can be configured');
}
app.io = connection;
app.defaultService = defaultService;
};
initialize.Service = Service;
initialize.service = defaultService;
return initialize;
}
module.exports = socketioClient;
module.exports.default = socketioClient;
/***/ }),
/***/ "../transport-commons/client.js":
/*!**************************************!*\
!*** ../transport-commons/client.js ***!
\**************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! ./lib/client */ "../transport-commons/lib/client.js").Service;
/***/ }),
/***/ "../transport-commons/lib/client.js":
/*!******************************************!*\
!*** ../transport-commons/lib/client.js ***!
\******************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Service = void 0;
var debug_1 = __importDefault(__webpack_require__(/*! debug */ "../../node_modules/debug/src/browser.js"));
var errors_1 = __webpack_require__(/*! @feathersjs/errors */ "../errors/lib/index.js");
var debug = debug_1.default('@feathersjs/transport-commons/client');
var namespacedEmitterMethods = ['addListener', 'emit', 'listenerCount', 'listeners', 'on', 'once', 'prependListener', 'prependOnceListener', 'removeAllListeners', 'removeListener'];
var otherEmitterMethods = ['eventNames', 'getMaxListeners', 'setMaxListeners'];
var addEmitterMethods = function addEmitterMethods(service) {
otherEmitterMethods.forEach(function (method) {
service[method] = function () {
var _this$connection;
if (typeof this.connection[method] !== 'function') {
throw new Error("Can not call '".concat(method, "' on the client service connection"));
}
return (_this$connection = this.connection)[method].apply(_this$connection, arguments);
};
}); // Methods that should add the namespace (service path)
namespacedEmitterMethods.forEach(function (method) {
service[method] = function (name) {
var _this$connection2;
if (typeof this.connection[method] !== 'function') {
throw new Error("Can not call '".concat(method, "' on the client service connection"));
}
var eventName = "".concat(this.path, " ").concat(name);
debug("Calling emitter method ".concat(method, " with ") + "namespaced event '".concat(eventName, "'"));
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var result = (_this$connection2 = this.connection)[method].apply(_this$connection2, [eventName].concat(args));
return result === this.connection ? this : result;
};
});
};
var Service = /*#__PURE__*/function () {
function Service(options) {
_classCallCheck(this, Service);
this.events = options.events;
this.path = options.name;
this.connection = options.connection;
this.method = options.method;
this.timeout = options.timeout || 5000;
addEmitterMethods(this);
}
_createClass(Service, [{
key: "send",
value: function send(method) {
var _this = this;
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
return new Promise(function (resolve, reject) {
var _this$connection3;
var timeoutId = setTimeout(function () {
return reject(new errors_1.Timeout("Timeout of ".concat(_this.timeout, "ms exceeded calling ").concat(method, " on ").concat(_this.path), {
timeout: _this.timeout,
method: method,
path: _this.path
}));
}, _this.timeout);
args.unshift(method, _this.path);
args.push(function (error, data) {
error = errors_1.convert(error);
clearTimeout(timeoutId);
return error ? reject(error) : resolve(data);
});
debug("Sending socket.".concat(_this.method), args);
(_this$connection3 = _this.connection)[_this.method].apply(_this$connection3, args);
});
}
}, {
key: "find",
value: function find() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return this.send('find', params.query || {});
}
}, {
key: "get",
value: function get(id) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return this.send('get', id, params.query || {});
}
}, {
key: "create",
value: function create(data) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return this.send('create', data, params.query || {});
}
}, {
key: "update",
value: function update(id, data) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return this.send('update', id, data, params.query || {});
}
}, {
key: "patch",
value: function patch(id, data) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return this.send('patch', id, data, params.query || {});
}
}, {
key: "remove",
value: function remove(id) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return this.send('remove', id, params.query || {});
} // `off` is actually not part of the Node event emitter spec
// but we are adding it since everybody is expecting it because
// of the emitter-component Socket.io is using
}, {
key: "off",
value: function off(name) {
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
args[_key3 - 1] = arguments[_key3];
}
if (typeof this.connection.off === 'function') {
var _this$connection4;
var result = (_this$connection4 = this.connection).off.apply(_this$connection4, ["".concat(this.path, " ").concat(name)].concat(args));
return result === this.connection ? this : result;
} else if (args.length === 0) {
// @ts-ignore
return this.removeAllListeners(name);
} // @ts-ignore
return this.removeListener.apply(this, [name].concat(args));
}
}]);
return Service;
}();
exports.Service = Service;
/***/ }),
/***/ "./src/socketio.js":
/*!*************************!*\
!*** ./src/socketio.js ***!
\*************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! @feathersjs/socketio-client */ "../socketio-client/lib/index.js");
/***/ })
/******/ });
});
//# sourceMappingURL=socketio.js.map