UNPKG

vdi-ngify-http

Version:
5 lines (4 loc) 31.1 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var A=require("@wendellhu/redi"),p=require("rxjs"),B=function(r,e){return B=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])},B(r,e)};function K(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");B(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}var I=function(){return I=Object.assign||function(e){for(var t,n=1,s=arguments.length;n<s;n++){t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},I.apply(this,arguments)};function Ee(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(r);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(r,n[s])&&(t[n[s]]=r[n[s]]);return t}function xe(r,e,t,n){function s(o){return o instanceof t?o:new t(function(i){i(o)})}return new(t||(t=Promise))(function(o,i){function c(f){try{l(n.next(f))}catch(h){i(h)}}function a(f){try{l(n.throw(f))}catch(h){i(h)}}function l(f){f.done?o(f.value):s(f.value).then(c,a)}l((n=n.apply(r,e||[])).next())})}function se(r,e){var t={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,s,o,i;return i={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function c(l){return function(f){return a([l,f])}}function a(l){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,s&&(o=l[0]&2?s.return:l[0]?s.throw||((o=s.return)&&o.call(s),0):s.next)&&!(o=o.call(s,l[1])).done)return o;switch(s=0,o&&(l=[l[0]&2,o.value]),l[0]){case 0:case 1:o=l;break;case 4:return t.label++,{value:l[1],done:!1};case 5:t.label++,s=l[1],l=[0];continue;case 7:l=t.ops.pop(),t.trys.pop();continue;default:if(o=t.trys,!(o=o.length>0&&o[o.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!o||l[1]>o[0]&&l[1]<o[3])){t.label=l[1];break}if(l[0]===6&&t.label<o[1]){t.label=o[1],o=l;break}if(o&&t.label<o[2]){t.label=o[2],t.ops.push(l);break}o[2]&&t.ops.pop(),t.trys.pop();continue}l=e.call(r,t)}catch(f){l=[6,f],s=0}finally{n=o=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}function C(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function L(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),s,o=[],i;try{for(;(e===void 0||e-- >0)&&!(s=n.next()).done;)o.push(s.value)}catch(c){i={error:c}}finally{try{s&&!s.done&&(t=n.return)&&t.call(n)}finally{if(i)throw i.error}}return o}function N(r,e,t){if(t||arguments.length===2)for(var n=0,s=e.length,o;n<s;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return r.concat(o||Array.prototype.slice.call(e))}function O(r){return this instanceof O?(this.v=r,this):new O(r)}function Pe(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),s,o=[];return s={},i("next"),i("throw"),i("return"),s[Symbol.asyncIterator]=function(){return this},s;function i(u){n[u]&&(s[u]=function(d){return new Promise(function(b,y){o.push([u,d,b,y])>1||c(u,d)})})}function c(u,d){try{a(n[u](d))}catch(b){h(o[0][3],b)}}function a(u){u.value instanceof O?Promise.resolve(u.value.v).then(l,f):h(o[0][2],u)}function l(u){c("next",u)}function f(u){c("throw",u)}function h(u,d){u(d),o.shift(),o.length&&c(o[0][0],o[0][1])}}function Se(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof C=="function"?C(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(o){t[o]=r[o]&&function(i){return new Promise(function(c,a){i=r[o](i),s(c,a,i.done,i.value)})}}function s(o,i,c,a){Promise.resolve(a).then(function(l){o({value:l,done:c})},i)}}function m(r){return typeof r=="function"}function He(r){var e=function(n){Error.call(n),n.stack=new Error().stack},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var k=He(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription: `+t.map(function(n,s){return s+1+") "+n.toString()}).join(` `):"",this.name="UnsubscriptionError",this.errors=t}});function Q(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var G=function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,s,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var c=C(i),a=c.next();!a.done;a=c.next()){var l=a.value;l.remove(this)}}catch(y){e={error:y}}finally{try{a&&!a.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else i.remove(this);var f=this.initialTeardown;if(m(f))try{f()}catch(y){o=y instanceof k?y.errors:[y]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var u=C(h),d=u.next();!d.done;d=u.next()){var b=d.value;try{Z(b)}catch(y){o=o!=null?o:[],y instanceof k?o=N(N([],L(o)),L(y.errors)):o.push(y)}}}catch(y){n={error:y}}finally{try{d&&!d.done&&(s=u.return)&&s.call(u)}finally{if(n)throw n.error}}}if(o)throw new k(o)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Z(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&Q(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&Q(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=function(){var e=new r;return e.closed=!0,e}(),r}();G.EMPTY;function ie(r){return r instanceof G||r&&"closed"in r&&m(r.remove)&&m(r.add)&&m(r.unsubscribe)}function Z(r){m(r)?r():r.unsubscribe()}var ae={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},M={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];var s=M.delegate;return s!=null&&s.setTimeout?s.setTimeout.apply(s,N([r,e],L(t))):setTimeout.apply(void 0,N([r,e],L(t)))},clearTimeout:function(r){var e=M.delegate;return((e==null?void 0:e.clearTimeout)||clearTimeout)(r)},delegate:void 0};function ce(r){M.setTimeout(function(){throw r})}function q(){}function Oe(r){r()}var V=function(r){K(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,ie(t)&&t.add(n)):n.destination=Ae,n}return e.create=function(t,n,s){return new z(t,n,s)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(G),Ce=Function.prototype.bind;function D(r,e){return Ce.call(r,e)}var Re=function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){_(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){_(n)}else _(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){_(t)}},r}(),z=function(r){K(e,r);function e(t,n,s){var o=r.call(this)||this,i;if(m(t)||!t)i={next:t!=null?t:void 0,error:n!=null?n:void 0,complete:s!=null?s:void 0};else{var c;o&&ae.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return o.unsubscribe()},i={next:t.next&&D(t.next,c),error:t.error&&D(t.error,c),complete:t.complete&&D(t.complete,c)}):i=t}return o.destination=new Re(i),o}return e}(V);function _(r){ce(r)}function _e(r){throw r}var Ae={closed:!0,next:q,error:_e,complete:q};function Ie(r,e,t,n,s){return new Le(r,e,t,n,s)}var Le=function(r){K(e,r);function e(t,n,s,o,i,c){var a=r.call(this,t)||this;return a.onFinalize=i,a.shouldUnsubscribe=c,a._next=n?function(l){try{n(l)}catch(f){t.error(f)}}:r.prototype._next,a._error=o?function(l){try{o(l)}catch(f){t.error(f)}finally{this.unsubscribe()}}:r.prototype._error,a._complete=s?function(){try{s()}catch(l){t.error(l)}finally{this.unsubscribe()}}:r.prototype._complete,a}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e}(V),$=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ne(r){return r}function Ue(r){return r.length===0?Ne:r.length===1?r[0]:function(t){return r.reduce(function(n,s){return s(n)},t)}}var H=function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,n){var s=this,o=ke(e)?e:new z(e,t,n);return Oe(function(){var i=s,c=i.operator,a=i.source;o.add(c?c.call(o,a):a?s._subscribe(o):s._trySubscribe(o))}),o},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var n=this;return t=ee(t),new t(function(s,o){var i=new z({next:function(c){try{e(c)}catch(a){o(a),i.unsubscribe()}},error:o,complete:s});n.subscribe(i)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[$]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ue(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=ee(e),new e(function(n,s){var o;t.subscribe(function(i){return o=i},function(i){return s(i)},function(){return n(o)})})},r.create=function(e){return new r(e)},r}();function ee(r){var e;return(e=r!=null?r:ae.Promise)!==null&&e!==void 0?e:Promise}function je(r){return r&&m(r.next)&&m(r.error)&&m(r.complete)}function ke(r){return r&&r instanceof V||je(r)&&ie(r)}var De=function(r){return r&&typeof r.length=="number"&&typeof r!="function"};function Fe(r){return m(r==null?void 0:r.then)}function Be(r){return m(r[$])}function Me(r){return Symbol.asyncIterator&&m(r==null?void 0:r[Symbol.asyncIterator])}function ze(r){return new TypeError("You provided "+(r!==null&&typeof r=="object"?"an invalid object":"'"+r+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function We(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Xe=We();function Ke(r){return m(r==null?void 0:r[Xe])}function Ge(r){return Pe(this,arguments,function(){var t,n,s,o;return se(this,function(i){switch(i.label){case 0:t=r.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,O(t.read())];case 3:return n=i.sent(),s=n.value,o=n.done,o?[4,O(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,O(s)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function Ve(r){return m(r==null?void 0:r.getReader)}function $e(r){if(r instanceof H)return r;if(r!=null){if(Be(r))return Ye(r);if(De(r))return Je(r);if(Fe(r))return Qe(r);if(Me(r))return le(r);if(Ke(r))return Ze(r);if(Ve(r))return qe(r)}throw ze(r)}function Ye(r){return new H(function(e){var t=r[$]();if(m(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Je(r){return new H(function(e){for(var t=0;t<r.length&&!e.closed;t++)e.next(r[t]);e.complete()})}function Qe(r){return new H(function(e){r.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,ce)})}function Ze(r){return new H(function(e){var t,n;try{for(var s=C(r),o=s.next();!o.done;o=s.next()){var i=o.value;if(e.next(i),e.closed)return}}catch(c){t={error:c}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}e.complete()})}function le(r){return new H(function(e){et(r,e).catch(function(t){return e.error(t)})})}function qe(r){return le(Ge(r))}function et(r,e){var t,n,s,o;return xe(this,void 0,void 0,function(){var i,c;return se(this,function(a){switch(a.label){case 0:a.trys.push([0,5,6,11]),t=Se(r),a.label=1;case 1:return[4,t.next()];case 2:if(n=a.sent(),!!n.done)return[3,4];if(i=n.value,e.next(i),e.closed)return[2];a.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return c=a.sent(),s={error:c},[3,11];case 6:return a.trys.push([6,,9,10]),n&&!n.done&&(o=t.return)?[4,o.call(t)]:[3,8];case 7:a.sent(),a.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function tt(r,e){e===void 0&&(e={});var t=e.selector,n=Ee(e,["selector"]);return new H(function(s){var o=new AbortController,i=o.signal,c=!0,a=n.signal;if(a)if(a.aborted)o.abort();else{var l=function(){i.aborted||o.abort()};a.addEventListener("abort",l),s.add(function(){return a.removeEventListener("abort",l)})}var f=I(I({},n),{signal:i}),h=function(u){c=!1,s.error(u)};return fetch(r,f).then(function(u){t?$e(t(u)).subscribe(Ie(s,void 0,function(){c=!1,s.complete()},h)):(c=!1,s.next(u),s.complete())}).catch(h),function(){c&&o.abort()}})}class R{constructor(e){this.defaultValue=e}}class ue{constructor(){this.map=new Map}set(e,t){return this.map.set(e,t!=null?t:e.defaultValue()),this}get(e){return this.map.has(e)||this.map.set(e,e.defaultValue()),this.map.get(e)}delete(e){return this.map.delete(e),this}has(e){return this.map.has(e)}keys(){return this.map.keys()}forEach(e){this.map.forEach((t,n)=>e(n,t))}}class g{constructor(e){this.headers=new Map,this.normalizedNames=new Map,typeof e=="string"?e.split(` `).forEach(t=>{if(t.includes(":")){const[n,s]=t.split(/:\s/,2),o=n.toLowerCase(),i=this.headers.get(o)||[];i.push(s),this.headers.set(o,i),this.setNormalizedName(o,n)}}):e&&Object.keys(e).forEach(t=>{const n=t.toLowerCase(),s=e[t];this.headers.set(n,Array.isArray(s)?s:[s]),this.setNormalizedName(n,t)})}append(e,t){const n=this.clone(),s=e.toLowerCase(),o=n.headers.get(s)||[];return o.push(...Array.isArray(t)?t:[t]),n.headers.set(s,o),n.setNormalizedName(s,e),n}set(e,t){const n=this.clone(),s=e.toLowerCase();return n.headers.set(s,Array.isArray(t)?t:[t]),n.setNormalizedName(s,e),n}delete(e){const t=this.clone(),n=e.toLowerCase();return t.headers.delete(n),t.normalizedNames.delete(n),t}get(e){const t=this.headers.get(e.toLowerCase());return(t==null?void 0:t[0])||null}getAll(e){return this.headers.get(e.toLowerCase())||null}has(e){return this.headers.has(e.toLowerCase())}forEach(e){this.headers.forEach((t,n)=>e(this.normalizedNames.get(n),t))}keys(){return Array.from(this.normalizedNames.values())}clone(){const e=new g;return this.headers.forEach((t,n)=>{e.headers.set(n,[...t]),e.normalizedNames.set(n,this.normalizedNames.get(n))}),e}setNormalizedName(e,t){this.normalizedNames.has(e)||this.normalizedNames.set(e,t)}}exports.HttpEventType=void 0;(function(r){r[r.Sent=0]="Sent",r[r.UploadProgress=1]="UploadProgress",r[r.ResponseHeader=2]="ResponseHeader",r[r.DownloadProgress=3]="DownloadProgress",r[r.Response=4]="Response",r[r.User=5]="User"})(exports.HttpEventType||(exports.HttpEventType={}));class U{constructor(e,t=200,n="OK"){this.url=e.url||null,this.status=e.status!==void 0?e.status:t,this.statusText=e.statusText||n,this.headers=e.headers||new g,this.ok=this.status>=200&&this.status<300}}class S extends U{constructor(e={}){super(e),this.type=exports.HttpEventType.ResponseHeader}clone(e={}){return new S({url:e.url||this.url||void 0,status:e.status!==void 0?e.status:this.status,statusText:e.statusText||this.statusText,headers:e.headers||this.headers})}}class E extends U{constructor(e={}){super(e),this.type=exports.HttpEventType.Response,this.body=e.body!==void 0?e.body:null}clone(e={}){return new E({url:e.url||this.url||void 0,body:e.body!==void 0?e.body:this.body,status:e.status||this.status,statusText:e.statusText||this.statusText,headers:e.headers||this.headers})}}class w extends U{constructor(e){super(e,0,"Unknown Error"),this.name="HttpErrorResponse",this.ok=!1,this.status>=200&&this.status<300?this.message=`Http failure during parsing for ${e.url||"(unknown url)"}`:this.message=`Http failure response for ${e.url||"(unknown url)"}: ${e.status} ${e.statusText}`,this.error=e.error||null}}const fe=new R(()=>({}));class rt{handle(e){if(e.reportProgress)throw Error("Fetch API does not currently support report progress");let t,n,s,o;return p.of({type:exports.HttpEventType.Sent}).pipe(p.concatMap(()=>tt(e.urlWithParams,Object.assign({selector:void 0,method:e.method,headers:e.headers.keys().reduce((i,c)=>(i[c]=e.headers.getAll(c).join(","),i),{}),body:e.serializeBody()},e.context.get(fe)))),p.switchMap(i=>{switch(t=i.url,n=i.status,s=i.statusText,o=new g,i.headers.forEach((c,a)=>o.set(a,c)),e.responseType){case"arraybuffer":return p.from(i.arrayBuffer());case"blob":return p.from(i.blob());case"json":return p.from(i.json());case"text":return p.from(i.text())}}),p.map(i=>new E({body:i,headers:o,status:n,statusText:s,url:t})),p.catchError(i=>i instanceof w?p.throwError(()=>i):p.throwError(()=>new w({url:t,error:i,status:n,statusText:s,headers:o}))))}}const W=new R(()=>({})),X=new R(()=>({})),de=new R(()=>({}));class nt{handle(e){return e.method==="POST"&&e.context.has(W)?this.upload(e):e.method==="GET"&&e.context.has(X)?this.download(e):this.request(e)}upload(e){return new p.Observable(t=>{const n=({header:l})=>{t.next(new S({url:e.url,headers:new g(l)}))},s=({totalBytesSent:l,totalBytesExpectedToSend:f})=>{t.next({type:exports.HttpEventType.UploadProgress,loaded:l,total:f})},{filePath:o,fileName:i,timeout:c}=e.context.get(W),a=wx.uploadFile({url:e.urlWithParams,filePath:o,name:i,header:this.buildHeaders(e),formData:e.body,timeout:c,success:({data:l,statusCode:f,errMsg:h})=>{let u=f>=200&&f<300,d=null;if(e.responseType==="json"&&typeof l=="string"&&l!=="")try{d=JSON.parse(l)}catch(b){u&&(u=!1,d={error:b,text:d})}u?(t.next(new E({url:e.url,body:d,status:f,statusText:h})),t.complete()):t.error(new w({url:e.url,error:d,status:f,statusText:h}))},fail:({errMsg:l})=>{t.error(new w({url:e.url,statusText:l}))}});return t.next({type:exports.HttpEventType.Sent}),e.reportProgress&&(a.onHeadersReceived(n),a.onProgressUpdate(s)),()=>{e.reportProgress&&(a.offHeadersReceived(n),a.offProgressUpdate(s)),a.abort()}})}download(e){return new p.Observable(t=>{const n=({header:a})=>{t.next(new S({url:e.url,headers:new g(a)}))},s=({totalBytesWritten:a,totalBytesExpectedToWrite:l})=>{t.next({type:exports.HttpEventType.DownloadProgress,loaded:a,total:l})},{filePath:o,timeout:i}=e.context.get(X),c=wx.downloadFile({url:e.urlWithParams,filePath:o,header:this.buildHeaders(e),timeout:i,success:({statusCode:a,errMsg:l})=>{a>=200&&a<300?(t.next(new E({url:e.url,status:a,statusText:l})),t.complete()):t.error(new w({url:e.url,status:a,statusText:l}))},fail:({errMsg:a})=>{t.error(new w({url:e.url,statusText:a}))}});return t.next({type:exports.HttpEventType.Sent}),e.reportProgress&&(c.onHeadersReceived(n),c.onProgressUpdate(s)),()=>{e.reportProgress&&(c.offHeadersReceived(n),c.offProgressUpdate(s)),c.abort()}})}request(e){return new p.Observable(t=>{if(e.method==="PATCH")throw Error("WeChat MiniProgram does not support http method as "+e.method);const n=({header:o})=>{t.next(new S({url:e.url,headers:new g(o)}))},s=wx.request(Object.assign({url:e.urlWithParams,method:e.method,data:e.body,header:this.buildHeaders(e),responseType:e.responseType==="arraybuffer"?e.responseType:"text",dataType:e.responseType==="json"?e.responseType:"\u5176\u4ED6",success:({data:o,header:i,statusCode:c,errMsg:a})=>{const l=c>=200&&c<300,f=new g(i);l?(t.next(new E({url:e.url,body:o,status:c,statusText:a,headers:f})),t.complete()):t.error(new w({url:e.url,error:o,status:c,statusText:a,headers:f}))},fail:({errMsg:o})=>{t.error(new w({url:e.url,statusText:o}))}},e.context.get(de)));return t.next({type:exports.HttpEventType.Sent}),e.reportProgress&&s.onHeadersReceived(n),()=>{e.reportProgress&&s.offHeadersReceived(n),s.abort()}})}buildHeaders(e){return e.headers.keys().reduce((t,n)=>(t[n]=e.headers.getAll(n).join(","),t),{})}}const ot=/^\)\]\}',?\n/;function st(r){return"responseURL"in r&&r.responseURL?r.responseURL:/^X-Request-URL:/m.test(r.getAllResponseHeaders())?r.getResponseHeader("X-Request-URL"):null}class he{constructor(e){this.factory=e||(()=>new XMLHttpRequest)}handle(e){return new p.Observable(t=>{const n=this.factory();if(n.open(e.method,e.urlWithParams),e.withCredentials&&(n.withCredentials=!0),e.headers.forEach((u,d)=>n.setRequestHeader(u,d.join(","))),e.headers.has("Accept")||n.setRequestHeader("Accept","application/json, text/plain, */*"),!e.headers.has("Content-Type")){const u=e.detectContentTypeHeader();u!==null&&n.setRequestHeader("Content-Type",u)}if(e.responseType){const u=e.responseType.toLowerCase();n.responseType=u!=="json"?u:"text"}const s=e.serializeBody();let o=null;const i=()=>{if(o!==null)return o;const u=n.status,d=n.statusText||"OK",b=new g(n.getAllResponseHeaders()),y=st(n)||e.url;return o=new S({headers:b,status:u,statusText:d,url:y}),o},c=()=>{let{headers:u,status:d,statusText:b,url:y}=i(),v=null;d!==204&&(v=typeof n.response=="undefined"?n.responseText:n.response),d===0&&(d=v?200:0);let j=d>=200&&d<300;if(e.responseType==="json"&&typeof v=="string"){const we=v;v=v.replace(ot,"");try{v=v!==""?JSON.parse(v):null}catch(Te){v=we,j&&(j=!1,v={error:Te,text:v})}}j?(t.next(new E({body:v,headers:u,status:d,statusText:b,url:y||void 0})),t.complete()):t.error(new w({error:v,headers:u,status:d,statusText:b,url:y||void 0}))},a=u=>{const{url:d}=i(),b=new w({error:u,status:n.status||0,statusText:n.statusText||"Unknown Error",url:d||void 0});t.error(b)};let l=!1;const f=u=>{l||(t.next(i()),l=!0);let d={type:exports.HttpEventType.DownloadProgress,loaded:u.loaded};u.lengthComputable&&(d.total=u.total),e.responseType==="text"&&!!n.responseText&&(d.partialText=n.responseText),t.next(d)},h=u=>{let d={type:exports.HttpEventType.UploadProgress,loaded:u.loaded};u.lengthComputable&&(d.total=u.total),t.next(d)};return n.addEventListener("load",c),n.addEventListener("error",a),n.addEventListener("timeout",a),n.addEventListener("abort",a),e.reportProgress&&(n.addEventListener("progress",f),s!==null&&n.upload&&n.upload.addEventListener("progress",h)),n.send(s),t.next({type:exports.HttpEventType.Sent}),()=>{n.removeEventListener("error",a),n.removeEventListener("abort",a),n.removeEventListener("load",c),n.removeEventListener("timeout",a),e.reportProgress&&(n.removeEventListener("progress",f),s!==null&&n.upload&&n.upload.removeEventListener("progress",h)),n.readyState!==n.DONE&&n.abort()}})}}const pe={},ye=r=>Object.assign(pe,r);class me{constructor(e,t){this.interceptor=e,this.next=t}handle(e){return this.interceptor.intercept(e,this.next)}}const it=/%(\d[a-f0-9])/gi,at={"40":"@","3A":":","24":"$","2C":",","3B":";","3D":"=","3F":"?","2F":"/"},te=r=>encodeURIComponent(r).replace(it,(e,t)=>{var n;return(n=at[t])!==null&&n!==void 0?n:e}),x=r=>r==null?"":`${r}`;class be{encodeKey(e){return te(e)}encodeValue(e){return te(e)}decodeKey(e){return decodeURIComponent(e)}decodeValue(e){return decodeURIComponent(e)}}class P{constructor(e,t){this.map=new Map,this.encoder=t!=null?t:new be,typeof e=="string"?e.replace(/^\?/,"").split("&").forEach(n=>{const[s,o]=n.split(/=(.*)/,2).map((c,a)=>c===void 0?"":a===0?this.encoder.decodeKey(c):this.encoder.decodeValue(c)),i=this.map.get(s)||[];i.push(o),this.map.set(s,i)}):e&&Object.keys(e).forEach(n=>{const s=e[n];this.map.set(n,Array.isArray(s)?s.map(x):[x(s)])})}has(e){return this.map.has(e)}get(e){const t=this.map.get(e);return(t==null?void 0:t[0])||null}getAll(e){return this.map.get(e)||null}keys(){return Array.from(this.map.keys())}append(e,t){const n=this.clone(),s=n.map.get(e)||[];return s.push(x(t)),n.map.set(e,s),n}appendAll(e){const t=this.clone();return Object.keys(e).forEach(n=>{const s=e[n],o=t.map.get(n)||[];o.push(...Array.isArray(s)?s.map(x):[x(s)]),t.map.set(n,o)}),t}set(e,t){const n=this.clone();return n.map.set(e,Array.isArray(t)?t.map(x):[x(t)]),n}delete(e,t){const n=this.clone();if(t!==void 0){const s=(n.map.get(e)||[]).filter(o=>o!==x(t));s.length>0?n.map.set(e,s):n.map.delete(e)}else n.map.delete(e);return n}toString(){return this.keys().map(e=>this.map.get(e).map(t=>this.encoder.encodeKey(e)+"="+this.encoder.encodeValue(t)).join("&")).filter(e=>e!=="").join("&")}clone(){const e=new P(null,this.encoder);return this.map.forEach((t,n)=>{e.map.set(n,[...t])}),e}}function re(r){return typeof ArrayBuffer!="undefined"&&r instanceof ArrayBuffer}function ne(r){return typeof Blob!="undefined"&&r instanceof Blob}function oe(r){return typeof FormData!="undefined"&&r instanceof FormData}function ct(r){return typeof URLSearchParams!="undefined"&&r instanceof URLSearchParams}class T{constructor(e,t,n){this.method=e,this.url=t;const{body:s,params:o,headers:i,context:c,responseType:a,reportProgress:l,withCredentials:f}=n||{};this.body=s!==void 0?s:null,this.params=o instanceof P?o:new P(o||void 0),this.headers=i instanceof g?i:new g(i),this.context=c||new ue,this.responseType=a||"json",this.reportProgress=!!l,this.withCredentials=!!f;const h=this.params.toString();if(h.length===0)this.urlWithParams=t;else{const u=t.indexOf("?"),d=u===-1?"?":u<t.length-1?"&":"";this.urlWithParams=t+d+h}}detectContentTypeHeader(){return this.body===null||oe(this.body)?null:ne(this.body)?this.body.type||null:re(this.body)?null:typeof this.body=="string"?"text/plain":this.body instanceof P?"application/x-www-form-urlencoded;charset=UTF-8":["object","number","boolean"].includes(typeof this.body)?"application/json":null}serializeBody(){return this.body===null?null:re(this.body)||ne(this.body)||oe(this.body)||ct(this.body)||typeof this.body=="string"?this.body:this.body instanceof P?this.body.toString():typeof this.body=="object"||typeof this.body=="boolean"||Array.isArray(this.body)?JSON.stringify(this.body):this.body.toString()}clone(e={}){return new T(e.method||this.method,e.url||this.url,{body:e.body!==void 0?e.body:this.body,params:e.params||this.params,headers:e.headers||this.headers,context:e.context||this.context,responseType:e.responseType||this.responseType,reportProgress:e.reportProgress!==void 0?e.reportProgress:this.reportProgress,withCredentials:e.withCredentials!==void 0?e.withCredentials:this.withCredentials})}}class ve{constructor(e,t){var n;t||(t=(n=pe.backend)!==null&&n!==void 0?n:new he),e?this.handler=e.reduceRight((s,o)=>new me(o,s),t):this.handler=t}request(e,t={}){const n=p.of(e).pipe(p.concatMap(o=>this.handler.handle(o))),s=n.pipe(p.filter(o=>o instanceof E));switch(t.observe||"body"){case"body":return s.pipe(p.map(o=>o.body));case"events":return n;case"response":return s}}delete(e,t,n={}){const{body:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l,observe:f}=n;return this.request(new T("DELETE",e,{body:s,params:t,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l}),{observe:f})}get(e,t,n={}){const{body:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l,observe:f}=n;return this.request(new T("GET",e,{body:s,params:t,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l}),{observe:f})}head(e,t,n={}){const{body:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l,observe:f}=n;return this.request(new T("HEAD",e,{body:s,params:t,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l}),{observe:f})}options(e,t,n={}){const{body:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l,observe:f}=n;return this.request(new T("OPTIONS",e,{body:s,params:t,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l}),{observe:f})}post(e,t,n={}){const{params:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l,observe:f}=n;return this.request(new T("POST",e,{body:t,params:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l}),{observe:f})}put(e,t,n={}){const{params:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l,observe:f}=n;return this.request(new T("PUT",e,{body:t,params:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l}),{observe:f})}patch(e,t,n={}){const{params:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l,observe:f}=n;return this.request(new T("PATCH",e,{body:t,params:s,headers:o,context:i,responseType:c,reportProgress:a,withCredentials:l}),{observe:f})}}const Y=A.createIdentifier("HTTP_CLIENT_CONFIG"),lt={},J=A.createIdentifier("HTTP_INTERCEPTOR");class ge{intercept(e,t){return t.handle(e)}}var ut=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,dt=(r,e,t,n)=>{for(var s=n>1?void 0:n?ft(e,t):e,o=r.length-1,i;o>=0;o--)(i=r[o])&&(s=(n?i(e,t,s):i(s))||s);return n&&s&&ut(e,t,s),s},F=(r,e)=>(t,n)=>e(t,n,r);exports.NgHttp=class extends ve{constructor(r,e){super(r),this.interceptors=r,this.config=e,this.config&&ye(this.config)}get getInterceptors(){return this.interceptors}};exports.NgHttp=dt([F(0,A.Many()),F(0,J),F(1,A.Optional(Y))],exports.NgHttp);class ht{static forRoot(e={}){return{providers:[[Y,{useValue:e}],[J,{useClass:ge}],[exports.NgHttp]],vueModule:exports.NgHttp}}}exports.FETCH_TOKEN=fe;exports.HTTP_CLIENT_CONFIG=Y;exports.HTTP_INTERCEPTOR=J;exports.HttpClient=ve;exports.HttpClientModule=ht;exports.HttpContext=ue;exports.HttpContextToken=R;exports.HttpErrorResponse=w;exports.HttpFetchBackend=rt;exports.HttpHeaderResponse=S;exports.HttpHeaders=g;exports.HttpInterceptorHandler=me;exports.HttpParams=P;exports.HttpRequest=T;exports.HttpResponse=E;exports.HttpResponseBase=U;exports.HttpUrlEncodingCodec=be;exports.HttpWxBackend=nt;exports.HttpXhrBackend=he;exports.NoopInterceptor=ge;exports.WX_DOWNLOAD_FILE_TOKEN=X;exports.WX_REQUSET_TOKEN=de;exports.WX_UPLOAD_FILE_TOKEN=W;exports.defaultConfig=lt;exports.setupConfig=ye;