Comparing version 1.0.0 to 1.0.1
@@ -1,1 +0,1 @@ | ||
var e={187:e=>{var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,e.exports.once=function(e,t){return new Promise((function(n,r){function i(n){e.removeListener(t,o),r(n)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}v(e,t,o,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&v(e,"error",t,{once:!0})}(e,i)}))},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var s=10;function u(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function a(e,t,n,r){var i,o,s,a;if(u(n),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),s=o[t]),void 0===s)s=o[t]=n,++e._eventsCount;else if("function"==typeof s?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(i=c(e))>0&&s.length>i&&!s.warned){s.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=s.length,a=l,console&&console.warn&&console.warn(a)}return e}function l(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function h(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=l.bind(r);return i.listener=n,r.wrapFn=i,i}function f(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):p(i,i.length)}function d(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function p(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function v(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function i(o){r.once&&e.removeEventListener(t,i),n(o)}))}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");s=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return c(this)},o.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var u=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw u.context=s,u}var c=o[e];if(void 0===c)return!1;if("function"==typeof c)r(c,this,t);else{var a=c.length,l=p(c,a);for(n=0;n<a;++n)r(l[n],this,t)}return!0},o.prototype.addListener=function(e,t){return a(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return a(this,e,t,!0)},o.prototype.once=function(e,t){return u(t),this.on(e,h(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return u(t),this.prependListener(e,h(this,e,t)),this},o.prototype.removeListener=function(e,t){var n,r,i,o,s;if(u(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===t||n[o].listener===t){s=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},o.prototype.listeners=function(e){return f(this,e,!0)},o.prototype.rawListeners=function(e){return f(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},o.prototype.listenerCount=d,o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},607:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(505));t.default=i.default},505:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function u(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}c((r=r.apply(e,t||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=i(n(638));function s(e){return e.startsWith("system.")||e.startsWith("aria2.")||(e="aria2."+e),e}function u(e){return e.split("aria2.")[1]||e}class c extends o.default{addSecret(e){let t=this.secret?["token:"+this.secret]:[];return Array.isArray(e)&&(t=t.concat(e)),t}_onnotification(e){const{method:t,params:n}=e,r=u(t);return r!==t&&this.emit(r,n),super._onnotification(e)}call(e,...t){const n=Object.create(null,{call:{get:()=>super.call}});return r(this,void 0,void 0,(function*(){return n.call.call(this,s(e),this.addSecret(t))}))}multicall(e){const t=Object.create(null,{call:{get:()=>super.call}});return r(this,void 0,void 0,(function*(){const n=[e.map((([e,...t])=>({methodName:s(e),params:this.addSecret(t)})))];return t.call.call(this,"system.multicall",n)}))}batch(e){const t=Object.create(null,{batch:{get:()=>super.batch}});return r(this,void 0,void 0,(function*(){return t.batch.call(this,e.map((([e,...t])=>[s(e),this.addSecret(t)])))}))}listNotifications(){return r(this,void 0,void 0,(function*(){return(yield this.call("system.listNotifications")).map((e=>u(e)))}))}listMethods(){return r(this,void 0,void 0,(function*(){return(yield this.call("system.listMethods")).map((e=>u(e)))}))}}Object.assign(c,{prefix:s,unprefix:u}),c.defaultOptions=Object.assign({},o.default.defaultOptions,{secure:!1,host:"localhost",port:6800,secret:"",path:"/jsonrpc"}),t.default=c},169:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t}))}}},638:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function u(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}c((r=r.apply(e,t||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(187),s=i(n(169)),u=i(n(82)),c=i(n(941));class a extends o.EventEmitter{constructor(e){var t;super(),this.deferreds={},this.deferreds={},this.lastId=0,this.defaultOptions=this.constructor.defaultOptions,Object.assign(this,{WebSocket:null===n.g||void 0===n.g?void 0:n.g.WebSocket,fetch:null===(t=null===n.g||void 0===n.g?void 0:n.g.fetch)||void 0===t?void 0:t.bind(this)},this.defaultOptions,e)}id(){return this.lastId++}url(e){return e+(this.secure?"s":"")+"://"+this.host+":"+this.port+this.path}websocket(e){return new Promise(((t,n)=>{const r=e=>{e?n(e):t()};this.socket.send(JSON.stringify(e),r),this.WebSocket&&this.socket instanceof this.WebSocket&&r()}))}http(e){return r(this,void 0,void 0,(function*(){const t=yield this.fetch(this.url("http"),{method:"POST",body:JSON.stringify(e),headers:{Accept:"application/json","Content-Type":"application/json"}});return t.json().then((e=>this._onmessage(e))).catch((e=>{this.emit("error",e)})),t}))}_buildMessage(e,t){if("string"!=typeof e)throw new TypeError(e+" is not a string");const n={method:e,"json-rpc":"2.0",id:this.id()};return t&&Object.assign(n,{params:t}),n}batch(e){return r(this,void 0,void 0,(function*(){const t=e.map((([e,...t])=>this._buildMessage(e,t)));return yield this._send(t),t.map((({id:e})=>{const{promise:t}=this.deferreds[e]=new s.default;return t}))}))}call(e,t){return r(this,void 0,void 0,(function*(){const n=this._buildMessage(e,t);yield this._send(n);const{promise:r}=this.deferreds[n.id]=new s.default;return r}))}_send(e){return r(this,void 0,void 0,(function*(){this.emit("output",e);const{socket:t}=this;return t&&1===t.readyState?this.websocket(e):this.http(e)}))}_onresponse({id:e,error:t,result:n}){const r=this.deferreds[e];r&&(t?r.reject(new c.default(t)):r.resolve(n),delete this.deferreds[e])}_onrequest({method:e,params:t}){return this.onrequest(e,t)}_onnotification({method:e,params:t}){this.emit(e,t)}_onmessage(e){if(this.emit("input",e),Array.isArray(e))for(const t of e)this._onobject(t);else this._onobject(e)}_onobject(e){void 0===e.method?this._onresponse(e):void 0===e.id?this._onnotification(e):this._onrequest(e)}open(){return r(this,void 0,void 0,(function*(){const e=this.socket=new this.WebSocket(this.url("ws"));return e.onclose=(...e)=>{this.emit("close",...e)},e.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch(e){return void this.emit("error",e)}this._onmessage(t)},e.onopen=(...e)=>{this.emit("open",...e)},e.onerror=(...e)=>{this.emit("error",...e)},(0,u.default)(this,"open")}))}close(){return r(this,void 0,void 0,(function*(){const{socket:e}=this;return e.close(),(0,u.default)(this,"close")}))}}a.defaultOptions={secure:!1,host:"localhost",port:80,secret:"",path:"/jsonrpc"},t.default=a},941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});class n extends Error{constructor(e){const{message:t,code:n,data:r}=e;super(t),this.code=n,r&&(this.data=r),this.name=this.constructor.name}}t.default=n},82:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise(((n,r)=>{function i(){e.removeListener(t,o),e.removeListener("error",s)}function o(e){n(e),i()}function s(e){r(e),i()}e.addListener(t,o),e.addListener("error",s)}))}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n(607); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(self,(()=>(()=>{"use strict";var e={187:e=>{var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,e.exports.once=function(e,t){return new Promise((function(n,r){function i(n){e.removeListener(t,o),r(n)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}v(e,t,o,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&v(e,"error",t,{once:!0})}(e,i)}))},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var s=10;function u(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function a(e,t,n,r){var i,o,s,a;if(u(n),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),s=o[t]),void 0===s)s=o[t]=n,++e._eventsCount;else if("function"==typeof s?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(i=c(e))>0&&s.length>i&&!s.warned){s.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=e,f.type=t,f.count=s.length,a=f,console&&console.warn&&console.warn(a)}return e}function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function l(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}function h(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):p(i,i.length)}function d(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function p(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function v(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function i(o){r.once&&e.removeEventListener(t,i),n(o)}))}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");s=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return c(this)},o.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var u=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw u.context=s,u}var c=o[e];if(void 0===c)return!1;if("function"==typeof c)r(c,this,t);else{var a=c.length,f=p(c,a);for(n=0;n<a;++n)r(f[n],this,t)}return!0},o.prototype.addListener=function(e,t){return a(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return a(this,e,t,!0)},o.prototype.once=function(e,t){return u(t),this.on(e,l(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return u(t),this.prependListener(e,l(this,e,t)),this},o.prototype.removeListener=function(e,t){var n,r,i,o,s;if(u(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===t||n[o].listener===t){s=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},o.prototype.listeners=function(e){return h(this,e,!0)},o.prototype.rawListeners=function(e){return h(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},o.prototype.listenerCount=d,o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},607:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(n(505));t.default=i.default},505:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function u(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}c((r=r.apply(e,t||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=i(n(638));function s(e){return e.startsWith("system.")||e.startsWith("aria2.")||(e="aria2."+e),e}function u(e){return e.split("aria2.")[1]||e}class c extends o.default{addSecret(e){let t=this.secret?["token:"+this.secret]:[];return Array.isArray(e)&&(t=t.concat(e)),t}_onnotification(e){const{method:t,params:n}=e,r=u(t);return r!==t&&this.emit(r,n),super._onnotification(e)}call(e,...t){const n=Object.create(null,{call:{get:()=>super.call}});return r(this,void 0,void 0,(function*(){return n.call.call(this,s(e),this.addSecret(t))}))}multicall(e){const t=Object.create(null,{call:{get:()=>super.call}});return r(this,void 0,void 0,(function*(){const n=[e.map((([e,...t])=>({methodName:s(e),params:this.addSecret(t)})))];return t.call.call(this,"system.multicall",n)}))}batch(e){const t=Object.create(null,{batch:{get:()=>super.batch}});return r(this,void 0,void 0,(function*(){return t.batch.call(this,e.map((([e,...t])=>[s(e),this.addSecret(t)])))}))}listNotifications(){return r(this,void 0,void 0,(function*(){return(yield this.call("system.listNotifications")).map((e=>u(e)))}))}listMethods(){return r(this,void 0,void 0,(function*(){return(yield this.call("system.listMethods")).map((e=>u(e)))}))}}Object.assign(c,{prefix:s,unprefix:u}),c.defaultOptions=Object.assign({},o.default.defaultOptions,{secure:!1,host:"localhost",port:6800,secret:"",path:"/jsonrpc"}),t.default=c},169:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t}))}}},638:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function u(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}c((r=r.apply(e,t||[])).next())}))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=n(187),s=i(n(169)),u=i(n(82)),c=i(n(941));class a extends o.EventEmitter{constructor(e){var t;super(),this.deferreds={},this.deferreds={},this.lastId=0,this.defaultOptions=this.constructor.defaultOptions,Object.assign(this,{WebSocket:null===n.g||void 0===n.g?void 0:n.g.WebSocket,fetch:null===(t=null===n.g||void 0===n.g?void 0:n.g.fetch)||void 0===t?void 0:t.bind(this)},this.defaultOptions,e)}id(){return this.lastId++}url(e){return e+(this.secure?"s":"")+"://"+this.host+":"+this.port+this.path}websocket(e){return new Promise(((t,n)=>{const r=e=>{e?n(e):t()};this.socket.send(JSON.stringify(e),r),this.WebSocket&&this.socket instanceof this.WebSocket&&r()}))}http(e){return r(this,void 0,void 0,(function*(){const t=yield this.fetch(this.url("http"),{method:"POST",body:JSON.stringify(e),headers:{Accept:"application/json","Content-Type":"application/json"}});return t.json().then((e=>this._onmessage(e))).catch((e=>{this.emit("error",e)})),t}))}_buildMessage(e,t){if("string"!=typeof e)throw new TypeError(e+" is not a string");const n={method:e,"json-rpc":"2.0",id:this.id()};return t&&Object.assign(n,{params:t}),n}batch(e){return r(this,void 0,void 0,(function*(){const t=e.map((([e,...t])=>this._buildMessage(e,t)));return yield this._send(t),t.map((({id:e})=>{const{promise:t}=this.deferreds[e]=new s.default;return t}))}))}call(e,t){return r(this,void 0,void 0,(function*(){const n=this._buildMessage(e,t);yield this._send(n);const{promise:r}=this.deferreds[n.id]=new s.default;return r}))}_send(e){return r(this,void 0,void 0,(function*(){this.emit("output",e);const{socket:t}=this;return t&&1===t.readyState?this.websocket(e):this.http(e)}))}_onresponse({id:e,error:t,result:n}){const r=this.deferreds[e];r&&(t?r.reject(new c.default(t)):r.resolve(n),delete this.deferreds[e])}_onrequest({method:e,params:t}){return this.onrequest(e,t)}_onnotification({method:e,params:t}){this.emit(e,t)}_onmessage(e){if(this.emit("input",e),Array.isArray(e))for(const t of e)this._onobject(t);else this._onobject(e)}_onobject(e){void 0===e.method?this._onresponse(e):void 0===e.id?this._onnotification(e):this._onrequest(e)}open(){return r(this,void 0,void 0,(function*(){const e=this.socket=new this.WebSocket(this.url("ws"));return e.onclose=(...e)=>{this.emit("close",...e)},e.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch(e){return void this.emit("error",e)}this._onmessage(t)},e.onopen=(...e)=>{this.emit("open",...e)},e.onerror=(...e)=>{this.emit("error",...e)},(0,u.default)(this,"open")}))}close(){return r(this,void 0,void 0,(function*(){const{socket:e}=this;return e.close(),(0,u.default)(this,"close")}))}}a.defaultOptions={secure:!1,host:"localhost",port:80,secret:"",path:"/jsonrpc"},t.default=a},941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});class n extends Error{constructor(e){const{message:t,code:n,data:r}=e;super(t),this.code=n,r&&(this.data=r),this.name=this.constructor.name}}t.default=n},82:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise(((n,r)=>{function i(){e.removeListener(t,o),e.removeListener("error",s)}function o(e){n(e),i()}function s(e){r(e),i()}e.addListener(t,o),e.addListener("error",s)}))}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}();var r=n(607);return r.default})())); |
{ | ||
"name": "aria2-lib", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "./dist/cjs/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/mjs/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41218