@feathersjs/client
Version:
A module that consolidates Feathers client modules for REST (jQuery, Request, Superagent) and Websocket (Socket.io, Primus) connections
1 lines • 16.3 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.feathers=t():e.feathers=t()}(this,(function(){return n={},e.m=t=[function(e,t,n){(function(r){function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}t.log=function(){var e;return"object"===("undefined"==typeof console?"undefined":o(console))&&console.log&&(e=console).log.apply(e,arguments)},t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),this.useColors){var n="color: "+this.color;t.splice(1,0,n,"color: inherit");var r=0,o=0;t[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(r++,"%c"===e&&(o=r))})),t.splice(o,0,n)}},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){var e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&31<=parseInt(RegExp.$1,10)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.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"],e.exports=n(6)(t),e.exports.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this,n(5))},function(e,t,n){e.exports=n(2)},function(e,t,n){var r=n(3);function o(e,t){if(!e)throw new Error("Socket.io connection needs to be provided");function n(n){var o=this,i=Object.keys(this.eventMappings||{}).map((function(e){return o.eventMappings[e]})),s=Object.assign({},t,{events:i,name:n,connection:e,method:"emit"});return new r(s)}function o(t){if("function"==typeof t.defaultService)throw new Error("Only one default client provider can be configured");t.io=e,t.defaultService=n}return o.Service=r,o.service=n,o}e.exports=o,e.exports.default=o},function(e,t,n){e.exports=n(4).Service},function(e,t,n){"use strict";function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Service=void 0;var i=o(n(0)),s=n(8),c=i.default("@feathersjs/transport-commons/client"),a=["addListener","emit","listenerCount","listeners","on","once","prependListener","prependOnceListener","removeAllListeners","removeListener"],u=["eventNames","getMaxListeners","setMaxListeners"],l=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.events=t.events,this.path=t.name,this.connection=t.connection,this.method=t.method,this.timeout=t.timeout||5e3,function(e){u.forEach((function(t){e[t]=function(){var e;if("function"!=typeof this.connection[t])throw new Error("Can not call '".concat(t,"' on the client service connection"));return(e=this.connection)[t].apply(e,arguments)}})),a.forEach((function(t){e[t]=function(e){var n;if("function"!=typeof this.connection[t])throw new Error("Can not call '".concat(t,"' on the client service connection"));var r="".concat(this.path," ").concat(e);c("Calling emitter method ".concat(t," with ")+"namespaced event '".concat(r,"'"));for(var o=arguments.length,i=new Array(1<o?o-1:0),s=1;s<o;s++)i[s-1]=arguments[s];var a=(n=this.connection)[t].apply(n,[r].concat(i));return a===this.connection?this:a}}))}(this)}var t,n;return t=e,(n=[{key:"send",value:function(e){for(var t=this,n=arguments.length,r=new Array(1<n?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return new Promise((function(n,o){var i,a=setTimeout((function(){return o(new s.Timeout("Timeout of ".concat(t.timeout,"ms exceeded calling ").concat(e," on ").concat(t.path),{timeout:t.timeout,method:e,path:t.path}))}),t.timeout);r.unshift(e,t.path),r.push((function(e,t){return e=s.convert(e),clearTimeout(a),e?o(e):n(t)})),c("Sending socket.".concat(t.method),r),(i=t.connection)[t.method].apply(i,r)}))}},{key:"find",value:function(e){var t=0<arguments.length&&void 0!==e?e:{};return this.send("find",t.query||{})}},{key:"get",value:function(e,t){var n=1<arguments.length&&void 0!==t?t:{};return this.send("get",e,n.query||{})}},{key:"create",value:function(e,t){var n=1<arguments.length&&void 0!==t?t:{};return this.send("create",e,n.query||{})}},{key:"update",value:function(e,t,n){var r=2<arguments.length&&void 0!==n?n:{};return this.send("update",e,t,r.query||{})}},{key:"patch",value:function(e,t,n){var r=2<arguments.length&&void 0!==n?n:{};return this.send("patch",e,t,r.query||{})}},{key:"remove",value:function(e,t){var n=1<arguments.length&&void 0!==t?t:{};return this.send("remove",e,n.query||{})}},{key:"off",value:function(e){for(var t=arguments.length,n=new Array(1<t?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if("function"!=typeof this.connection.off)return 0===n.length?this.removeAllListeners(e):this.removeListener.apply(this,[e].concat(n));var o,i=(o=this.connection).off.apply(o,["".concat(this.path," ").concat(e)].concat(n));return i===this.connection?this:i}}])&&r(t.prototype,n),e}();t.Service=l},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function c(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var a,u=[],l=!1,f=-1;function d(){l&&a&&(l=!1,a.length?u=a.concat(u):f=-1,u.length&&h())}function h(){if(!l){var e=c(d);l=!0;for(var t=u.length;t;){for(a=u,u=[];++f<t;)a&&a[f].run();f=-1,t=u.length}a=null,l=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function m(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];u.push(new p(e,t)),1!==u.length||l||c(h)},p.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=m,o.addListener=m,o.once=m,o.off=m,o.removeListener=m,o.removeAllListeners=m,o.emit=m,o.prependListener=m,o.prependOnceListener=m,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,t,n){function r(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}(e)||function(){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 o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}e.exports=function(e){function t(e){for(var t=0,n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return o.colors[Math.abs(t)%o.colors.length]}function o(e){var n;function r(){for(var e,t,i,s,c=arguments.length,a=new Array(c),u=0;u<c;u++)a[u]=arguments[u];r.enabled&&(e=r,i=(t=Number(new Date))-(n||t),e.diff=i,e.prev=n,e.curr=t,n=t,a[0]=o.coerce(a[0]),"string"!=typeof a[0]&&a.unshift("%O"),a[s=0]=a[0].replace(/%([a-zA-Z%])/g,(function(t,n){if("%%"===t)return t;s++;var r,i=o.formatters[n];return"function"==typeof i&&(r=a[s],t=i.call(e,r),a.splice(s,1),s--),t})),o.formatArgs.call(e,a),(e.log||o.log).apply(e,a))}return r.namespace=e,r.enabled=o.enabled(e),r.useColors=o.useColors(),r.color=t(e),r.destroy=i,r.extend=s,"function"==typeof o.init&&o.init(r),o.instances.push(r),r}function i(){var e=o.instances.indexOf(this);return-1!==e&&(o.instances.splice(e,1),!0)}function s(e,t){var n=o(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n}function c(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return((o.debug=o).default=o).coerce=function(e){return e instanceof Error?e.stack||e.message:e},o.disable=function(){var e=[].concat(r(o.names.map(c)),r(o.skips.map(c).map((function(e){return"-"+e})))).join(",");return o.enable(""),e},o.enable=function(e){var t;o.save(e),o.names=[],o.skips=[];var n=("string"==typeof e?e:"").split(/[\s,]+/),r=n.length;for(t=0;t<r;t++)n[t]&&("-"===(e=n[t].replace(/\*/g,".*?"))[0]?o.skips.push(new RegExp("^"+e.substr(1)+"$")):o.names.push(new RegExp("^"+e+"$")));for(t=0;t<o.instances.length;t++){var i=o.instances[t];i.enabled=o.enabled(i.namespace)}},o.enabled=function(e){if("*"===e[e.length-1])return!0;var t,n;for(t=0,n=o.skips.length;t<n;t++)if(o.skips[t].test(e))return!1;for(t=0,n=o.names.length;t<n;t++)if(o.names[t].test(e))return!0;return!1},o.humanize=n(7),Object.keys(e).forEach((function(t){o[t]=e[t]})),o.instances=[],o.names=[],o.skips=[],o.formatters={},o.selectColor=t,o.enable(o.load()),o}},function(e,t){var n=36e5,r=864e5;function o(e,t,n,r){var o=1.5*n<=t;return Math.round(e/n)+" "+r+(o?"s":"")}e.exports=function(e,t){t=t||{};var i=typeof e;if("string"==i&&0<e.length)return function(e){if(!(100<(e=String(e)).length)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var o=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*o;case"weeks":case"week":case"w":return 6048e5*o;case"days":case"day":case"d":return o*r;case"hours":case"hour":case"hrs":case"hr":case"h":return o*n;case"minutes":case"minute":case"mins":case"min":case"m":return 6e4*o;case"seconds":case"second":case"secs":case"sec":case"s":return 1e3*o;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:return}}}}(e);if("number"==i&&isFinite(e))return(t.long?function(e){var t=Math.abs(e);return r<=t?o(e,t,r,"day"):n<=t?o(e,t,n,"hour"):6e4<=t?o(e,t,6e4,"minute"):1e3<=t?o(e,t,1e3,"second"):e+" ms"}:function(e){var t=Math.abs(e);return r<=t?Math.round(e/r)+"d":n<=t?Math.round(e/n)+"h":6e4<=t?Math.round(e/6e4)+"m":1e3<=t?Math.round(e/1e3)+"s":e+"ms"})(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,n){function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var o=n(0)("@feathersjs/errors");function i(e,t,n,s,c){var a,u,l;(e=e||"Error")instanceof Error?(u=e.message||"Error",e.errors&&(a=e.errors)):"object"===r(e)?(u=e.message||"Error",c=e):u=e,c&&((l=JSON.parse(JSON.stringify(c))).errors?(a=l.errors,delete l.errors):c.errors&&(a=JSON.parse(JSON.stringify(c.errors)))),this.type="FeathersError",this.name=t,this.message=u,this.code=n,this.className=s,this.data=l,this.errors=a||{},o("".concat(this.name,"(").concat(this.code,"): ").concat(this.message)),o(this.errors),Error.captureStackTrace?Error.captureStackTrace(this,i):this.stack=(new Error).stack}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e}function c(e,t){i.call(this,e,"BadRequest",400,"bad-request",t)}function a(e,t){i.call(this,e,"NotAuthenticated",401,"not-authenticated",t)}function u(e,t){i.call(this,e,"PaymentError",402,"payment-error",t)}function l(e,t){i.call(this,e,"Forbidden",403,"forbidden",t)}function f(e,t){i.call(this,e,"NotFound",404,"not-found",t)}function d(e,t){i.call(this,e,"MethodNotAllowed",405,"method-not-allowed",t)}function h(e,t){i.call(this,e,"NotAcceptable",406,"not-acceptable",t)}function p(e,t){i.call(this,e,"Timeout",408,"timeout",t)}function m(e,t){i.call(this,e,"Conflict",409,"conflict",t)}function y(e,t){i(this,e,"Gone",410,"gone")}function v(e,t){i.call(this,e,"LengthRequired",411,"length-required",t)}function C(e,t){i.call(this,e,"Unprocessable",422,"unprocessable",t)}function g(e,t){i.call(this,e,"TooManyRequests",429,"too-many-requests",t)}function b(e,t){i.call(this,e,"GeneralError",500,"general-error",t)}function w(e,t){i.call(this,e,"NotImplemented",501,"not-implemented",t)}function F(e,t){i.call(this,e,"BadGateway",502,"bad-gateway",t)}function S(e,t){i.call(this,e,"Unavailable",503,"unavailable",t)}s(i,Error),Object.defineProperty(i.prototype,"toJSON",{value:function(){return{name:this.name,message:this.message,code:this.code,className:this.className,data:this.data,errors:this.errors}}}),s(c,i),s(a,i),s(u,i),s(l,i),s(f,i),s(d,i),s(h,i),s(p,i),s(m,i),s(y,i),s(v,i),s(C,i),s(g,i),s(b,i),s(w,i),s(F,i),s(S,i);var E={FeathersError:i,BadRequest:c,NotAuthenticated:a,PaymentError:u,Forbidden:l,NotFound:f,MethodNotAllowed:d,NotAcceptable:h,Timeout:p,Conflict:m,Gone:y,LengthRequired:v,Unprocessable:C,TooManyRequests:g,GeneralError:b,NotImplemented:w,BadGateway:F,Unavailable:S,400:c,401:a,402:u,403:l,404:f,405:d,406:h,408:p,409:m,410:y,411:v,422:C,429:g,500:b,501:w,502:F,503:S};e.exports=Object.assign({convert:function(e){if(!e)return e;var t=E[e.name],n=t?new t(e.message,e.data):new Error(e.message||e);return"object"===r(e)&&Object.assign(n,e),n}},E)}],e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(e){return t[e]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},e.p="",e(e.s=1);function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var t,n}));