@univerjs/network 0.8.2 → 0.8.3-nightly.202506271607
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +169 -163
- package/lib/index.js +169 -163
- package/lib/types/controllers/config.schema.d.ts +22 -0
- package/lib/types/index.d.ts +10 -9
- package/lib/types/plugin.d.ts +4 -20
- package/lib/umd/index.js +2 -2
- package/package.json +4 -4
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`).forEach(r=>{const[t,s]=r.split(":");t&&s&&this._setHeader(t,s)})}_handleHeadersConstructorProps(n){Object.entries(n).forEach(([r,t])=>this._setHeader(r,t))}_handleHeaders(n){n.forEach((r,t)=>this._setHeader(t,r))}}const U=p.createIdentifier("network.http-implementation");class M{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>{const r=this.params[n];return Array.isArray(r)?r.map(t=>`${n}=${t}`).join("&"):`${n}=${r}`}).join("&"):""}}let J=0;class O{constructor(n,r,t){f(this,"uid",J++);this.method=n,this.url=r,this.requestParams=t}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var r,t;const n=(t=(r=this.requestParams)==null?void 0:r.params)==null?void 0:t.toString();return n?`${this.url}${this.url.includes("?")?"&":"?"}${n}`:this.url}getBody(){var t,s;const n=(t=this.headers.get("Content-Type"))!=null?t:A,r=(s=this.requestParams)==null?void 0:s.body;return r instanceof FormData?r:V(n)&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){var r;return this.headers.toHeadersInit((r=this.requestParams)==null?void 0:r.body)}}var z=Object.getOwnPropertyDescriptor,K=(e,n,r,t)=>{for(var s=t>1?void 0:t?z(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},Y=(e,n)=>(r,t)=>n(r,t,e);exports.HTTPService=class extends p.Disposable{constructor(r){super();f(this,"_interceptors",[]);f(this,"_pipe");this._http=r}registerHTTPInterceptor(r){if(this._interceptors.indexOf(r)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(r),this._interceptors=this._interceptors.sort((t,s)=>{var o,i;return((o=t.priority)!=null?o:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,p.toDisposable(()=>p.remove(this._interceptors,r))}get(r,t){return this.request("GET",r,t)}post(r,t){return this.request("POST",r,t)}put(r,t){return this.request("PUT",r,t)}delete(r,t){return this.request("DELETE",r,t)}patch(r,t){return this.request("PATCH",r,t)}async request(r,t,s){var u,h;const o=new _(s==null?void 0:s.headers),i=new M(s==null?void 0:s.params),c=new O(r,t,{headers:o,params:i,withCredentials:(u=s==null?void 0:s.withCredentials)!=null?u:!1,responseType:(h=s==null?void 0:s.responseType)!=null?h:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),y=w.of(c).pipe(E.concatMap(a=>this._runInterceptorsAndImplementation(a)));return await w.firstValueFrom(y)}stream(r,t,s){return this.getSSE(r,t,s)}getSSE(r,t,s){var y,l;const o=new _(s==null?void 0:s.headers),i=new M(s==null?void 0:s.params),c=new O(r,t,{headers:o,params:i,withCredentials:(y=s==null?void 0:s.withCredentials)!=null?y:!1,reportProgress:!0,responseType:(l=s==null?void 0:s.responseType)!=null?l:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body});return w.of(c).pipe(E.concatMap(u=>this._runInterceptorsAndImplementation(u)))}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(t=>t.interceptor).reduceRight((t,s)=>Q(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}};exports.HTTPService=K([Y(0,U)],exports.HTTPService);function Q(e,n){return(r,t)=>n(r,s=>e(s,t))}const Z=200,P=300;var x=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.Ok=200]="Ok",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.ImUsed=226]="ImUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.Unused=306]="Unused",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.PayloadTooLarge=413]="PayloadTooLarge",e[e.UriTooLong=414]="UriTooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HttpVersionNotSupported=505]="HttpVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(x||{}),D=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(D||{});class L{constructor({body:n,headers:r,status:t,statusText:s}){f(this,"type",1);f(this,"body");f(this,"headers");f(this,"status");f(this,"statusText");this.body=n,this.headers=r,this.status=t,this.statusText=s}}class j{constructor(n,r,t){f(this,"type",0);this.total=n,this.loaded=r,this.partialText=t}}class B{constructor(n,r,t){this.headers=n,this.status=r,this.statusText=t}}class I{constructor({request:n,headers:r,status:t,statusText:s,error:o}){f(this,"request");f(this,"headers");f(this,"status");f(this,"statusText");f(this,"error");this.request=n,this.headers=r,this.status=t,this.statusText=s,this.error=o}}function X(e){return{method:e.method,headers:e.getHeadersInit(),body:e.getBody(),credentials:e.withCredentials?"include":void 0}}var H=Object.getOwnPropertyDescriptor,S=(e,n,r,t)=>{for(var s=t>1?void 0:t?H(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},C=(e,n)=>(r,t)=>n(r,t,e);exports.FetchHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new w.Observable(r=>{const t=new AbortController;return this._send(n,r,t).catch(s=>{r.error(new I({error:s,request:n}))}),()=>t.abort()})}async _send(n,r,t){var u,h;let s;try{const a=X(n),m=n.getUrlWithParams(),g=fetch(m,{signal:t.signal,...a});this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${m} with params ${a}`),s=await g}catch(a){const m=new I({request:n,error:a,status:(u=a.status)!=null?u:0,statusText:(h=a.statusText)!=null?h:"Unknown Error",headers:a.headers});this._logService.error("[FetchHTTPImplementation]: network error",m),r.error(m);return}const o=new _(s.headers),i=s.status,c=s.statusText;let y=null;if(s.body&&(y=await this._readBody(n,s,r)),i>=x.Ok&&i<x.MultipleChoices)r.next(new L({body:y,headers:o,status:i,statusText:c}));else{const a=new I({request:n,error:y,status:i,statusText:c,headers:o});this._logService.error("[FetchHTTPImplementation]: network error",a),r.error(a)}r.complete()}async _readBody(n,r,t){var m,g;const s=[],o=r.body.getReader(),i=r.headers.get("content-length");let c=0;const y=(m=n.requestParams)==null?void 0:m.reportProgress,l=n.responseType;let u,h;for(;;){const{done:v,value:d}=await o.read();if(v)break;s.push(d),c+=d.length,y&&l==="text"&&(u=(u!=null?u:"")+(h!=null?h:h=new TextDecoder).decode(d,{stream:!0}),t.next(new j(i?Number.parseInt(i,10):void 0,c,u)))}const a=T(s,c);try{const v=(g=r.headers.get("content-type"))!=null?g:"";return re(n,a,v)}catch(v){const d=new I({request:n,error:v,status:r.status,statusText:r.statusText,headers:new _(r.headers)});return this._logService.error("[FetchHTTPImplementation]: network error",d),t.error(d),null}}};exports.FetchHTTPImplementation=S([C(0,p.ILogService)],exports.FetchHTTPImplementation);function T(e,n){const r=new Uint8Array(n);let t=0;for(const s of e)r.set(s,t),t+=s.length;return r}const ee=/^\)\]\}',?\n/;function re(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(ee,"");return t===""?null:JSON.parse(t);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:r});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}var te=Object.getOwnPropertyDescriptor,ne=(e,n,r,t)=>{for(var s=t>1?void 0:t?te(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},se=(e,n)=>(r,t)=>n(r,t,e);exports.XHRHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new w.Observable(r=>{const t=new XMLHttpRequest,s=n.getUrlWithParams(),o=X(n),{responseType:i}=n;t.open(n.method,s),n.withCredentials&&(t.withCredentials=!0),o.headers&&Object.entries(o.headers).forEach(([h,a])=>t.setRequestHeader(h,a));const c=()=>{const h=t.statusText||"OK",a=new _(t.getAllResponseHeaders());return new B(a,t.status,h)},y=()=>{const{headers:h,statusText:a,status:m}=c();let g=null,v=null;m!==x.NoContent&&(g=typeof t.response>"u"?t.responseText:t.response);let d=m>=Z&&m<P;if(i==="json"&&typeof g=="string"){const b=g;try{g=g?JSON.parse(g):null}catch(R){d=!1,g=b,v=R}}if(i==="blob"&&!(g instanceof Blob)&&(d=!1,v=new Error("Response is not a Blob object")),d)r.next(new L({body:g,headers:h,status:m,statusText:a}));else{const b=new I({request:n,error:v,headers:h,status:m,statusText:a});this._logService.error("[XHRHTTPImplementation]: network error",b),r.error(b)}},l=h=>{const a=new I({request:n,error:h,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:c().headers});this._logService.error("[XHRHTTPImplementation]: network error",a),r.error(a)};t.responseType=i||"",t.addEventListener("load",y),t.addEventListener("error",l),t.addEventListener("abort",l),t.addEventListener("timeout",l);const u=n.getBody();return t.send(u),this._logService.debug("[XHRHTTPImplementation]",`sending request to url ${s} with params ${o}`),()=>{t.readyState!==t.DONE&&t.abort(),t.removeEventListener("load",y),t.removeEventListener("error",l),t.removeEventListener("abort",l),t.removeEventListener("timeout",l)}})}};exports.XHRHTTPImplementation=ne([se(0,p.ILogService)],exports.XHRHTTPImplementation);var oe=Object.getOwnPropertyDescriptor,ie=(e,n,r,t)=>{for(var s=t>1?void 0:t?oe(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},$=(e,n)=>(r,t)=>n(r,t,e),k;exports.UniverNetworkPlugin=(k=class extends p.Plugin{constructor(n=void 0,r,t){super(),this._config=n,this._logger=r,this._injector=t}onStarting(){var t,s,o;if(this._injector.get(exports.HTTPService,p.Quantity.OPTIONAL,p.LookUp.SKIP_SELF)&&!((t=this._config)!=null&&t.forceUseNewInstance)){this._logger.warn("[UniverNetworkPlugin]",'HTTPService is already registered in an ancestor interceptor. Skipping registration. If you want to force a new instance, set "forceUseNewInstance" to true in the plugin configuration.');return}const r=(s=this._config)!=null&&s.useFetchImpl?exports.FetchHTTPImplementation:typeof window<"u"?exports.XHRHTTPImplementation:exports.FetchHTTPImplementation;p.registerDependencies(this._injector,p.mergeOverrideWithDependencies([[exports.HTTPService],[U,{useClass:r}]],(o=this._config)==null?void 0:o.override))}},f(k,"pluginName","UNIVER_NETWORK_PLUGIN"),k);exports.UniverNetworkPlugin=ie([$(1,p.ILogService),$(2,p.Inject(p.Injector))],exports.UniverNetworkPlugin);const ce=p.createIdentifier("univer.network.socket.service");class ae extends p.Disposable{createSocket(n){try{const r=new WebSocket(n),t=new p.DisposableCollection;return{URL:n,close:(o,i)=>{r.close(o,i),t.dispose()},send:o=>{r.send(o)},open$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("open",i),t.add(p.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(E.share()),close$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("close",i),t.add(p.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(E.share()),error$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("error",i),t.add(p.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(E.share()),message$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("message",i),t.add(p.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(E.share())}}catch(r){return console.error(r),null}}}const le=3,he=1e3,pe=e=>{var t,s;const n=(t=e==null?void 0:e.maxRetryAttempts)!=null?t:le,r=(s=e==null?void 0:e.delayInterval)!=null?s:he;return(o,i)=>i(o).pipe(E.retry({delay:r,count:n}))},de=e=>{const n=[],r=new Set,t=()=>{var s;for(;r.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&n.length>0;){const o=n.shift();r.add(o),o()}};return(s,o)=>new w.Observable(i=>{const c=()=>o(s).subscribe({next:l=>i.next(l),error:l=>i.error(l),complete:()=>i.complete()}),y=()=>{r.delete(c),p.remove(n,c),t()};return n.push(c),t(),y})},ue=e=>{const{errorStatusCodes:n,onAuthError:r}=e;return(s,o)=>o(s).pipe(w.catchError(i=>(i instanceof I&&n.some(c=>c===i.status)&&r(),w.throwError(()=>i))))},ge=(e=300)=>{let r=()=>{};return t=>new Promise(s=>{r();const o=setTimeout(()=>{s(!0)},e);r=()=>{clearTimeout(o),s(!1)}})},me=()=>(e,n)=>n.map(r=>({config:r,result:e})),ye=(e,n={})=>{const{isMatch:r,getParamsFromRequest:t,mergeParamsToRequest:s}=e,{fetchCheck:o=ge(300),distributeResult:i=me()}=n,c=[],y=l=>l.map(u=>u.config);return(l,u)=>r(l)?new w.Observable(h=>{const a=t(l);c.push({next:g=>h.next(g),error:g=>h.error(g),config:a});const m=y(c);o(l).then(g=>{if(g){const v=[];m.forEach(d=>{const b=c.findIndex(R=>R.config===d);if(b>=0){const[R]=c.splice(b,1);v.push(R)}}),u(s(m,l)).subscribe({next:d=>{if(d.type===D.Response){const b=d.body,R=i(b,m);v.forEach(F=>{const q=R.find(N=>N.config===F.config);if(q){const N=new L({body:q.result,headers:d.headers,status:d.status,statusText:d.statusText});F.next(N)}else F.error("batch error")})}},complete:()=>h.complete(),error:d=>h.error(d)})}})}):u(l)};exports.AuthInterceptorFactory=ue;exports.HTTPEventType=D;exports.HTTPHeaders=_;exports.HTTPProgress=j;exports.HTTPRequest=O;exports.HTTPResponse=L;exports.HTTPResponseError=I;exports.HTTPStatusCode=x;exports.IHTTPImplementation=U;exports.ISocketService=ce;exports.MergeInterceptorFactory=ye;exports.ResponseHeader=B;exports.RetryInterceptorFactory=pe;exports.ThresholdInterceptorFactory=de;exports.WebSocketService=ae;
|
|
1
|
+
"use strict";var W=Object.defineProperty;var V=(e,n,r)=>n in e?W(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var y=(e,n,r)=>V(e,typeof n!="symbol"?n+"":n,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@univerjs/core"),w=require("rxjs"),_=require("rxjs/operators"),J="network.config",$={},A="application/json";function K(e){return Array.isArray(e)?e.some(n=>n.includes(A)):e.includes(A)}class E{constructor(n){y(this,"_headers",new Map);typeof n=="string"?this._handleHeadersString(n):n instanceof Headers?this._handleHeaders(n):n&&this._handleHeadersConstructorProps(n)}forEach(n){this._headers.forEach((r,t)=>n(t,r))}has(n){return!!this._headers.has(n.toLowerCase())}get(n){const r=n.toLowerCase();return this._headers.has(r)?this._headers.get(r):null}set(n,r){this._setHeader(n,r)}toHeadersInit(n){var t,s;const r={};return this._headers.forEach((o,i)=>{r[i]=o.join(",")}),(t=r.accept)!=null||(r.accept="application/json, text/plain, */*"),n instanceof FormData||(s=r["content-type"])!=null||(r["content-type"]="application/json;charset=UTF-8"),r}_setHeader(n,r){const t=n.toLowerCase();this._headers.has(t)?this._headers.get(t).push(r.toString()):this._headers.set(t,[r.toString()])}_handleHeadersString(n){n.split(`
|
|
2
|
+
`).forEach(r=>{const[t,s]=r.split(":");t&&s&&this._setHeader(t,s)})}_handleHeadersConstructorProps(n){Object.entries(n).forEach(([r,t])=>this._setHeader(r,t))}_handleHeaders(n){n.forEach((r,t)=>this._setHeader(t,r))}}const D=h.createIdentifier("network.http-implementation");class j{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>{const r=this.params[n];return Array.isArray(r)?r.map(t=>`${n}=${t}`).join("&"):`${n}=${r}`}).join("&"):""}}let z=0;class U{constructor(n,r,t){y(this,"uid",z++);this.method=n,this.url=r,this.requestParams=t}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var r,t;const n=(t=(r=this.requestParams)==null?void 0:r.params)==null?void 0:t.toString();return n?`${this.url}${this.url.includes("?")?"&":"?"}${n}`:this.url}getBody(){var t,s;const n=(t=this.headers.get("Content-Type"))!=null?t:A,r=(s=this.requestParams)==null?void 0:s.body;return r instanceof FormData?r:K(n)&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){var r;return this.headers.toHeadersInit((r=this.requestParams)==null?void 0:r.body)}}var Y=Object.getOwnPropertyDescriptor,P=(e,n,r,t)=>{for(var s=t>1?void 0:t?Y(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},Q=(e,n)=>(r,t)=>n(r,t,e);exports.HTTPService=class extends h.Disposable{constructor(r){super();y(this,"_interceptors",[]);y(this,"_pipe");this._http=r}registerHTTPInterceptor(r){if(this._interceptors.indexOf(r)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(r),this._interceptors=this._interceptors.sort((t,s)=>{var o,i;return((o=t.priority)!=null?o:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,h.toDisposable(()=>h.remove(this._interceptors,r))}get(r,t){return this.request("GET",r,t)}post(r,t){return this.request("POST",r,t)}put(r,t){return this.request("PUT",r,t)}delete(r,t){return this.request("DELETE",r,t)}patch(r,t){return this.request("PATCH",r,t)}async request(r,t,s){var u,p;const o=new E(s==null?void 0:s.headers),i=new j(s==null?void 0:s.params),c=new U(r,t,{headers:o,params:i,withCredentials:(u=s==null?void 0:s.withCredentials)!=null?u:!1,responseType:(p=s==null?void 0:s.responseType)!=null?p:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),m=w.of(c).pipe(_.concatMap(a=>this._runInterceptorsAndImplementation(a)));return await w.firstValueFrom(m)}stream(r,t,s){return this.getSSE(r,t,s)}getSSE(r,t,s){var m,l;const o=new E(s==null?void 0:s.headers),i=new j(s==null?void 0:s.params),c=new U(r,t,{headers:o,params:i,withCredentials:(m=s==null?void 0:s.withCredentials)!=null?m:!1,reportProgress:!0,responseType:(l=s==null?void 0:s.responseType)!=null?l:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body});return w.of(c).pipe(_.concatMap(u=>this._runInterceptorsAndImplementation(u)))}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(t=>t.interceptor).reduceRight((t,s)=>Z(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}};exports.HTTPService=P([Q(0,D)],exports.HTTPService);function Z(e,n){return(r,t)=>n(r,s=>e(s,t))}const H=200,S=300;var x=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.Ok=200]="Ok",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.ImUsed=226]="ImUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.Unused=306]="Unused",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.PayloadTooLarge=413]="PayloadTooLarge",e[e.UriTooLong=414]="UriTooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HttpVersionNotSupported=505]="HttpVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(x||{}),q=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(q||{});class L{constructor({body:n,headers:r,status:t,statusText:s}){y(this,"type",1);y(this,"body");y(this,"headers");y(this,"status");y(this,"statusText");this.body=n,this.headers=r,this.status=t,this.statusText=s}}class B{constructor(n,r,t){y(this,"type",0);this.total=n,this.loaded=r,this.partialText=t}}class G{constructor(n,r,t){this.headers=n,this.status=r,this.statusText=t}}class b{constructor({request:n,headers:r,status:t,statusText:s,error:o}){y(this,"request");y(this,"headers");y(this,"status");y(this,"statusText");y(this,"error");this.request=n,this.headers=r,this.status=t,this.statusText=s,this.error=o}}function X(e){return{method:e.method,headers:e.getHeadersInit(),body:e.getBody(),credentials:e.withCredentials?"include":void 0}}var C=Object.getOwnPropertyDescriptor,T=(e,n,r,t)=>{for(var s=t>1?void 0:t?C(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},ee=(e,n)=>(r,t)=>n(r,t,e);exports.FetchHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new w.Observable(r=>{const t=new AbortController;return this._send(n,r,t).catch(s=>{r.error(new b({error:s,request:n}))}),()=>t.abort()})}async _send(n,r,t){var u,p;let s;try{const a=X(n),f=n.getUrlWithParams(),g=fetch(f,{signal:t.signal,...a});this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${f} with params ${a}`),s=await g}catch(a){const f=new b({request:n,error:a,status:(u=a.status)!=null?u:0,statusText:(p=a.statusText)!=null?p:"Unknown Error",headers:a.headers});this._logService.error("[FetchHTTPImplementation]: network error",f),r.error(f);return}const o=new E(s.headers),i=s.status,c=s.statusText;let m=null;if(s.body&&(m=await this._readBody(n,s,r)),i>=x.Ok&&i<x.MultipleChoices)r.next(new L({body:m,headers:o,status:i,statusText:c}));else{const a=new b({request:n,error:m,status:i,statusText:c,headers:o});this._logService.error("[FetchHTTPImplementation]: network error",a),r.error(a)}r.complete()}async _readBody(n,r,t){var f,g;const s=[],o=r.body.getReader(),i=r.headers.get("content-length");let c=0;const m=(f=n.requestParams)==null?void 0:f.reportProgress,l=n.responseType;let u,p;for(;;){const{done:v,value:d}=await o.read();if(v)break;s.push(d),c+=d.length,m&&l==="text"&&(u=(u!=null?u:"")+(p!=null?p:p=new TextDecoder).decode(d,{stream:!0}),t.next(new B(i?Number.parseInt(i,10):void 0,c,u)))}const a=re(s,c);try{const v=(g=r.headers.get("content-type"))!=null?g:"";return ne(n,a,v)}catch(v){const d=new b({request:n,error:v,status:r.status,statusText:r.statusText,headers:new E(r.headers)});return this._logService.error("[FetchHTTPImplementation]: network error",d),t.error(d),null}}};exports.FetchHTTPImplementation=T([ee(0,h.ILogService)],exports.FetchHTTPImplementation);function re(e,n){const r=new Uint8Array(n);let t=0;for(const s of e)r.set(s,t),t+=s.length;return r}const te=/^\)\]\}',?\n/;function ne(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(te,"");return t===""?null:JSON.parse(t);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:r});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}var se=Object.getOwnPropertyDescriptor,oe=(e,n,r,t)=>{for(var s=t>1?void 0:t?se(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},ie=(e,n)=>(r,t)=>n(r,t,e);exports.XHRHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new w.Observable(r=>{const t=new XMLHttpRequest,s=n.getUrlWithParams(),o=X(n),{responseType:i}=n;t.open(n.method,s),n.withCredentials&&(t.withCredentials=!0),o.headers&&Object.entries(o.headers).forEach(([p,a])=>t.setRequestHeader(p,a));const c=()=>{const p=t.statusText||"OK",a=new E(t.getAllResponseHeaders());return new G(a,t.status,p)},m=()=>{const{headers:p,statusText:a,status:f}=c();let g=null,v=null;f!==x.NoContent&&(g=typeof t.response>"u"?t.responseText:t.response);let d=f>=H&&f<S;if(i==="json"&&typeof g=="string"){const I=g;try{g=g?JSON.parse(g):null}catch(R){d=!1,g=I,v=R}}if(i==="blob"&&!(g instanceof Blob)&&(d=!1,v=new Error("Response is not a Blob object")),d)r.next(new L({body:g,headers:p,status:f,statusText:a}));else{const I=new b({request:n,error:v,headers:p,status:f,statusText:a});this._logService.error("[XHRHTTPImplementation]: network error",I),r.error(I)}},l=p=>{const a=new b({request:n,error:p,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:c().headers});this._logService.error("[XHRHTTPImplementation]: network error",a),r.error(a)};t.responseType=i||"",t.addEventListener("load",m),t.addEventListener("error",l),t.addEventListener("abort",l),t.addEventListener("timeout",l);const u=n.getBody();return t.send(u),this._logService.debug("[XHRHTTPImplementation]",`sending request to url ${s} with params ${o}`),()=>{t.readyState!==t.DONE&&t.abort(),t.removeEventListener("load",m),t.removeEventListener("error",l),t.removeEventListener("abort",l),t.removeEventListener("timeout",l)}})}};exports.XHRHTTPImplementation=oe([ie(0,h.ILogService)],exports.XHRHTTPImplementation);var ce=Object.getOwnPropertyDescriptor,ae=(e,n,r,t)=>{for(var s=t>1?void 0:t?ce(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},k=(e,n)=>(r,t)=>n(r,t,e),O;exports.UniverNetworkPlugin=(O=class extends h.Plugin{constructor(n=$,r,t,s){super(),this._config=n,this._logger=r,this._injector=t,this._configService=s;const{...o}=h.merge({},$,this._config);this._configService.setConfig(J,o)}onStarting(){var t,s,o;if(this._injector.get(exports.HTTPService,h.Quantity.OPTIONAL,h.LookUp.SKIP_SELF)&&!((t=this._config)!=null&&t.forceUseNewInstance)){this._logger.warn("[UniverNetworkPlugin]",'HTTPService is already registered in an ancestor interceptor. Skipping registration. If you want to force a new instance, set "forceUseNewInstance" to true in the plugin configuration.');return}const r=(s=this._config)!=null&&s.useFetchImpl?exports.FetchHTTPImplementation:typeof window<"u"?exports.XHRHTTPImplementation:exports.FetchHTTPImplementation;h.registerDependencies(this._injector,h.mergeOverrideWithDependencies([[exports.HTTPService],[D,{useClass:r}]],(o=this._config)==null?void 0:o.override))}},y(O,"pluginName","UNIVER_NETWORK_PLUGIN"),O);exports.UniverNetworkPlugin=ae([k(1,h.ILogService),k(2,h.Inject(h.Injector)),k(3,h.IConfigService)],exports.UniverNetworkPlugin);const le=e=>{const{errorStatusCodes:n,onAuthError:r}=e;return(s,o)=>o(s).pipe(w.catchError(i=>(i instanceof b&&n.some(c=>c===i.status)&&r(),w.throwError(()=>i))))},he=(e=300)=>{let r=()=>{};return t=>new Promise(s=>{r();const o=setTimeout(()=>{s(!0)},e);r=()=>{clearTimeout(o),s(!1)}})},pe=()=>(e,n)=>n.map(r=>({config:r,result:e})),de=(e,n={})=>{const{isMatch:r,getParamsFromRequest:t,mergeParamsToRequest:s}=e,{fetchCheck:o=he(300),distributeResult:i=pe()}=n,c=[],m=l=>l.map(u=>u.config);return(l,u)=>r(l)?new w.Observable(p=>{const a=t(l);c.push({next:g=>p.next(g),error:g=>p.error(g),config:a});const f=m(c);o(l).then(g=>{if(g){const v=[];f.forEach(d=>{const I=c.findIndex(R=>R.config===d);if(I>=0){const[R]=c.splice(I,1);v.push(R)}}),u(s(f,l)).subscribe({next:d=>{if(d.type===q.Response){const I=d.body,R=i(I,f);v.forEach(F=>{const M=R.find(N=>N.config===F.config);if(M){const N=new L({body:M.result,headers:d.headers,status:d.status,statusText:d.statusText});F.next(N)}else F.error("batch error")})}},complete:()=>p.complete(),error:d=>p.error(d)})}})}):u(l)},ue=3,ge=1e3,fe=e=>{var t,s;const n=(t=e==null?void 0:e.maxRetryAttempts)!=null?t:ue,r=(s=e==null?void 0:e.delayInterval)!=null?s:ge;return(o,i)=>i(o).pipe(_.retry({delay:r,count:n}))},me=e=>{const n=[],r=new Set,t=()=>{var s;for(;r.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&n.length>0;){const o=n.shift();r.add(o),o()}};return(s,o)=>new w.Observable(i=>{const c=()=>o(s).subscribe({next:l=>i.next(l),error:l=>i.error(l),complete:()=>i.complete()}),m=()=>{r.delete(c),h.remove(n,c),t()};return n.push(c),t(),m})},ye=h.createIdentifier("univer.network.socket.service");class we extends h.Disposable{createSocket(n){try{const r=new WebSocket(n),t=new h.DisposableCollection;return{URL:n,close:(o,i)=>{r.close(o,i),t.dispose()},send:o=>{r.send(o)},open$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("open",i),t.add(h.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(_.share()),close$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("close",i),t.add(h.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(_.share()),error$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("error",i),t.add(h.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(_.share()),message$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("message",i),t.add(h.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(_.share())}}catch(r){return console.error(r),null}}}exports.AuthInterceptorFactory=le;exports.HTTPEventType=q;exports.HTTPHeaders=E;exports.HTTPProgress=B;exports.HTTPRequest=U;exports.HTTPResponse=L;exports.HTTPResponseError=b;exports.HTTPStatusCode=x;exports.IHTTPImplementation=D;exports.ISocketService=ye;exports.MergeInterceptorFactory=de;exports.ResponseHeader=G;exports.RetryInterceptorFactory=fe;exports.ThresholdInterceptorFactory=me;exports.WebSocketService=we;
|
package/lib/es/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var u = (e, t, r) =>
|
|
4
|
-
import { createIdentifier as
|
|
5
|
-
import { of as
|
|
6
|
-
import { concatMap as
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
return Array.isArray(e) ? e.some((t) => t.includes(
|
|
1
|
+
var P = Object.defineProperty;
|
|
2
|
+
var S = (e, t, r) => t in e ? P(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var u = (e, t, r) => S(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { createIdentifier as J, Disposable as K, toDisposable as R, remove as z, ILogService as $, Inject as H, Injector as C, IConfigService as T, Plugin as ee, merge as re, Quantity as te, LookUp as ne, registerDependencies as se, mergeOverrideWithDependencies as oe, DisposableCollection as ie } from "@univerjs/core";
|
|
5
|
+
import { of as M, firstValueFrom as ce, Observable as m, catchError as ae, throwError as le } from "rxjs";
|
|
6
|
+
import { concatMap as B, retry as he, share as b } from "rxjs/operators";
|
|
7
|
+
const pe = "network.config", G = {}, O = "application/json";
|
|
8
|
+
function de(e) {
|
|
9
|
+
return Array.isArray(e) ? e.some((t) => t.includes(O)) : e.includes(O);
|
|
10
10
|
}
|
|
11
11
|
class I {
|
|
12
12
|
constructor(t) {
|
|
@@ -51,8 +51,8 @@ class I {
|
|
|
51
51
|
t.forEach((r, n) => this._setHeader(n, r));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
const
|
|
55
|
-
class
|
|
54
|
+
const Y = J("network.http-implementation");
|
|
55
|
+
class W {
|
|
56
56
|
constructor(t) {
|
|
57
57
|
this.params = t;
|
|
58
58
|
}
|
|
@@ -63,10 +63,10 @@ class B {
|
|
|
63
63
|
}).join("&") : "";
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
let
|
|
67
|
-
class
|
|
66
|
+
let ue = 0;
|
|
67
|
+
class X {
|
|
68
68
|
constructor(t, r, n) {
|
|
69
|
-
u(this, "uid",
|
|
69
|
+
u(this, "uid", ue++);
|
|
70
70
|
this.method = t, this.url = r, this.requestParams = n;
|
|
71
71
|
}
|
|
72
72
|
get headers() {
|
|
@@ -85,20 +85,20 @@ class G {
|
|
|
85
85
|
}
|
|
86
86
|
getBody() {
|
|
87
87
|
var n, s;
|
|
88
|
-
const t = (n = this.headers.get("Content-Type")) != null ? n :
|
|
89
|
-
return r instanceof FormData ? r :
|
|
88
|
+
const t = (n = this.headers.get("Content-Type")) != null ? n : O, r = (s = this.requestParams) == null ? void 0 : s.body;
|
|
89
|
+
return r instanceof FormData ? r : de(t) && r && typeof r == "object" ? JSON.stringify(r) : r ? `${r}` : null;
|
|
90
90
|
}
|
|
91
91
|
getHeadersInit() {
|
|
92
92
|
var r;
|
|
93
93
|
return this.headers.toHeadersInit((r = this.requestParams) == null ? void 0 : r.body);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
var
|
|
97
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
96
|
+
var ge = Object.getOwnPropertyDescriptor, fe = (e, t, r, n) => {
|
|
97
|
+
for (var s = n > 1 ? void 0 : n ? ge(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
98
98
|
(i = e[o]) && (s = i(s) || s);
|
|
99
99
|
return s;
|
|
100
|
-
},
|
|
101
|
-
let x = class extends
|
|
100
|
+
}, ye = (e, t) => (r, n) => t(r, n, e);
|
|
101
|
+
let x = class extends K {
|
|
102
102
|
constructor(t) {
|
|
103
103
|
super();
|
|
104
104
|
u(this, "_interceptors", []);
|
|
@@ -145,17 +145,17 @@ let x = class extends J {
|
|
|
145
145
|
*/
|
|
146
146
|
async request(t, r, n) {
|
|
147
147
|
var l, h;
|
|
148
|
-
const s = new I(n == null ? void 0 : n.headers), o = new
|
|
148
|
+
const s = new I(n == null ? void 0 : n.headers), o = new W(n == null ? void 0 : n.params), i = new X(t, r, {
|
|
149
149
|
headers: s,
|
|
150
150
|
params: o,
|
|
151
151
|
withCredentials: (l = n == null ? void 0 : n.withCredentials) != null ? l : !1,
|
|
152
152
|
// default value for withCredentials is false by MDN
|
|
153
153
|
responseType: (h = n == null ? void 0 : n.responseType) != null ? h : "json",
|
|
154
154
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
155
|
-
}), c =
|
|
156
|
-
|
|
155
|
+
}), c = M(i).pipe(
|
|
156
|
+
B((a) => this._runInterceptorsAndImplementation(a))
|
|
157
157
|
);
|
|
158
|
-
return await
|
|
158
|
+
return await ce(c);
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Send an HTTP request. It returns an observable that emits HTTP events. For example, it can be used to
|
|
@@ -180,7 +180,7 @@ let x = class extends J {
|
|
|
180
180
|
*/
|
|
181
181
|
getSSE(t, r, n) {
|
|
182
182
|
var c, d;
|
|
183
|
-
const s = new I(n == null ? void 0 : n.headers), o = new
|
|
183
|
+
const s = new I(n == null ? void 0 : n.headers), o = new W(n == null ? void 0 : n.params), i = new X(t, r, {
|
|
184
184
|
headers: s,
|
|
185
185
|
params: o,
|
|
186
186
|
withCredentials: (c = n == null ? void 0 : n.withCredentials) != null ? c : !1,
|
|
@@ -188,12 +188,12 @@ let x = class extends J {
|
|
|
188
188
|
responseType: (d = n == null ? void 0 : n.responseType) != null ? d : "json",
|
|
189
189
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
190
190
|
});
|
|
191
|
-
return
|
|
191
|
+
return M(i).pipe(B((l) => this._runInterceptorsAndImplementation(l)));
|
|
192
192
|
}
|
|
193
193
|
// eslint-disable-next-line ts/no-explicit-any
|
|
194
194
|
_runInterceptorsAndImplementation(t) {
|
|
195
195
|
return this._pipe || (this._pipe = this._interceptors.map((r) => r.interceptor).reduceRight(
|
|
196
|
-
(r, n) =>
|
|
196
|
+
(r, n) => we(r, n),
|
|
197
197
|
(r, n) => n(r)
|
|
198
198
|
)), this._pipe(
|
|
199
199
|
t,
|
|
@@ -202,15 +202,15 @@ let x = class extends J {
|
|
|
202
202
|
);
|
|
203
203
|
}
|
|
204
204
|
};
|
|
205
|
-
x =
|
|
206
|
-
|
|
205
|
+
x = fe([
|
|
206
|
+
ye(0, Y)
|
|
207
207
|
], x);
|
|
208
|
-
function
|
|
208
|
+
function we(e, t) {
|
|
209
209
|
return (r, n) => t(r, (s) => e(s, n));
|
|
210
210
|
}
|
|
211
|
-
const
|
|
212
|
-
var L = /* @__PURE__ */ ((e) => (e[e.Continue = 100] = "Continue", e[e.SwitchingProtocols = 101] = "SwitchingProtocols", e[e.Processing = 102] = "Processing", e[e.EarlyHints = 103] = "EarlyHints", e[e.Ok = 200] = "Ok", e[e.Created = 201] = "Created", e[e.Accepted = 202] = "Accepted", e[e.NonAuthoritativeInformation = 203] = "NonAuthoritativeInformation", e[e.NoContent = 204] = "NoContent", e[e.ResetContent = 205] = "ResetContent", e[e.PartialContent = 206] = "PartialContent", e[e.MultiStatus = 207] = "MultiStatus", e[e.AlreadyReported = 208] = "AlreadyReported", e[e.ImUsed = 226] = "ImUsed", e[e.MultipleChoices = 300] = "MultipleChoices", e[e.MovedPermanently = 301] = "MovedPermanently", e[e.Found = 302] = "Found", e[e.SeeOther = 303] = "SeeOther", e[e.NotModified = 304] = "NotModified", e[e.UseProxy = 305] = "UseProxy", e[e.Unused = 306] = "Unused", e[e.TemporaryRedirect = 307] = "TemporaryRedirect", e[e.PermanentRedirect = 308] = "PermanentRedirect", e[e.BadRequest = 400] = "BadRequest", e[e.Unauthorized = 401] = "Unauthorized", e[e.PaymentRequired = 402] = "PaymentRequired", e[e.Forbidden = 403] = "Forbidden", e[e.NotFound = 404] = "NotFound", e[e.MethodNotAllowed = 405] = "MethodNotAllowed", e[e.NotAcceptable = 406] = "NotAcceptable", e[e.ProxyAuthenticationRequired = 407] = "ProxyAuthenticationRequired", e[e.RequestTimeout = 408] = "RequestTimeout", e[e.Conflict = 409] = "Conflict", e[e.Gone = 410] = "Gone", e[e.LengthRequired = 411] = "LengthRequired", e[e.PreconditionFailed = 412] = "PreconditionFailed", e[e.PayloadTooLarge = 413] = "PayloadTooLarge", e[e.UriTooLong = 414] = "UriTooLong", e[e.UnsupportedMediaType = 415] = "UnsupportedMediaType", e[e.RangeNotSatisfiable = 416] = "RangeNotSatisfiable", e[e.ExpectationFailed = 417] = "ExpectationFailed", e[e.ImATeapot = 418] = "ImATeapot", e[e.MisdirectedRequest = 421] = "MisdirectedRequest", e[e.UnprocessableEntity = 422] = "UnprocessableEntity", e[e.Locked = 423] = "Locked", e[e.FailedDependency = 424] = "FailedDependency", e[e.TooEarly = 425] = "TooEarly", e[e.UpgradeRequired = 426] = "UpgradeRequired", e[e.PreconditionRequired = 428] = "PreconditionRequired", e[e.TooManyRequests = 429] = "TooManyRequests", e[e.RequestHeaderFieldsTooLarge = 431] = "RequestHeaderFieldsTooLarge", e[e.UnavailableForLegalReasons = 451] = "UnavailableForLegalReasons", e[e.InternalServerError = 500] = "InternalServerError", e[e.NotImplemented = 501] = "NotImplemented", e[e.BadGateway = 502] = "BadGateway", e[e.ServiceUnavailable = 503] = "ServiceUnavailable", e[e.GatewayTimeout = 504] = "GatewayTimeout", e[e.HttpVersionNotSupported = 505] = "HttpVersionNotSupported", e[e.VariantAlsoNegotiates = 506] = "VariantAlsoNegotiates", e[e.InsufficientStorage = 507] = "InsufficientStorage", e[e.LoopDetected = 508] = "LoopDetected", e[e.NotExtended = 510] = "NotExtended", e[e.NetworkAuthenticationRequired = 511] = "NetworkAuthenticationRequired", e))(L || {}),
|
|
213
|
-
class
|
|
211
|
+
const me = 200, ve = 300;
|
|
212
|
+
var L = /* @__PURE__ */ ((e) => (e[e.Continue = 100] = "Continue", e[e.SwitchingProtocols = 101] = "SwitchingProtocols", e[e.Processing = 102] = "Processing", e[e.EarlyHints = 103] = "EarlyHints", e[e.Ok = 200] = "Ok", e[e.Created = 201] = "Created", e[e.Accepted = 202] = "Accepted", e[e.NonAuthoritativeInformation = 203] = "NonAuthoritativeInformation", e[e.NoContent = 204] = "NoContent", e[e.ResetContent = 205] = "ResetContent", e[e.PartialContent = 206] = "PartialContent", e[e.MultiStatus = 207] = "MultiStatus", e[e.AlreadyReported = 208] = "AlreadyReported", e[e.ImUsed = 226] = "ImUsed", e[e.MultipleChoices = 300] = "MultipleChoices", e[e.MovedPermanently = 301] = "MovedPermanently", e[e.Found = 302] = "Found", e[e.SeeOther = 303] = "SeeOther", e[e.NotModified = 304] = "NotModified", e[e.UseProxy = 305] = "UseProxy", e[e.Unused = 306] = "Unused", e[e.TemporaryRedirect = 307] = "TemporaryRedirect", e[e.PermanentRedirect = 308] = "PermanentRedirect", e[e.BadRequest = 400] = "BadRequest", e[e.Unauthorized = 401] = "Unauthorized", e[e.PaymentRequired = 402] = "PaymentRequired", e[e.Forbidden = 403] = "Forbidden", e[e.NotFound = 404] = "NotFound", e[e.MethodNotAllowed = 405] = "MethodNotAllowed", e[e.NotAcceptable = 406] = "NotAcceptable", e[e.ProxyAuthenticationRequired = 407] = "ProxyAuthenticationRequired", e[e.RequestTimeout = 408] = "RequestTimeout", e[e.Conflict = 409] = "Conflict", e[e.Gone = 410] = "Gone", e[e.LengthRequired = 411] = "LengthRequired", e[e.PreconditionFailed = 412] = "PreconditionFailed", e[e.PayloadTooLarge = 413] = "PayloadTooLarge", e[e.UriTooLong = 414] = "UriTooLong", e[e.UnsupportedMediaType = 415] = "UnsupportedMediaType", e[e.RangeNotSatisfiable = 416] = "RangeNotSatisfiable", e[e.ExpectationFailed = 417] = "ExpectationFailed", e[e.ImATeapot = 418] = "ImATeapot", e[e.MisdirectedRequest = 421] = "MisdirectedRequest", e[e.UnprocessableEntity = 422] = "UnprocessableEntity", e[e.Locked = 423] = "Locked", e[e.FailedDependency = 424] = "FailedDependency", e[e.TooEarly = 425] = "TooEarly", e[e.UpgradeRequired = 426] = "UpgradeRequired", e[e.PreconditionRequired = 428] = "PreconditionRequired", e[e.TooManyRequests = 429] = "TooManyRequests", e[e.RequestHeaderFieldsTooLarge = 431] = "RequestHeaderFieldsTooLarge", e[e.UnavailableForLegalReasons = 451] = "UnavailableForLegalReasons", e[e.InternalServerError = 500] = "InternalServerError", e[e.NotImplemented = 501] = "NotImplemented", e[e.BadGateway = 502] = "BadGateway", e[e.ServiceUnavailable = 503] = "ServiceUnavailable", e[e.GatewayTimeout = 504] = "GatewayTimeout", e[e.HttpVersionNotSupported = 505] = "HttpVersionNotSupported", e[e.VariantAlsoNegotiates = 506] = "VariantAlsoNegotiates", e[e.InsufficientStorage = 507] = "InsufficientStorage", e[e.LoopDetected = 508] = "LoopDetected", e[e.NotExtended = 510] = "NotExtended", e[e.NetworkAuthenticationRequired = 511] = "NetworkAuthenticationRequired", e))(L || {}), Q = /* @__PURE__ */ ((e) => (e[e.DownloadProgress = 0] = "DownloadProgress", e[e.Response = 1] = "Response", e))(Q || {});
|
|
213
|
+
class q {
|
|
214
214
|
constructor({
|
|
215
215
|
body: t,
|
|
216
216
|
headers: r,
|
|
@@ -225,13 +225,13 @@ class $ {
|
|
|
225
225
|
this.body = t, this.headers = r, this.status = n, this.statusText = s;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
class
|
|
228
|
+
class _e {
|
|
229
229
|
constructor(t, r, n) {
|
|
230
230
|
u(this, "type", 0);
|
|
231
231
|
this.total = t, this.loaded = r, this.partialText = n;
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
class
|
|
234
|
+
class Ee {
|
|
235
235
|
constructor(t, r, n) {
|
|
236
236
|
this.headers = t, this.status = r, this.statusText = n;
|
|
237
237
|
}
|
|
@@ -252,7 +252,7 @@ class v {
|
|
|
252
252
|
this.request = t, this.headers = r, this.status = n, this.statusText = s, this.error = o;
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
function
|
|
255
|
+
function Z(e) {
|
|
256
256
|
return {
|
|
257
257
|
method: e.method,
|
|
258
258
|
headers: e.getHeadersInit(),
|
|
@@ -260,11 +260,11 @@ function Q(e) {
|
|
|
260
260
|
credentials: e.withCredentials ? "include" : void 0
|
|
261
261
|
};
|
|
262
262
|
}
|
|
263
|
-
var
|
|
264
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
263
|
+
var Re = Object.getOwnPropertyDescriptor, Ie = (e, t, r, n) => {
|
|
264
|
+
for (var s = n > 1 ? void 0 : n ? Re(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
265
265
|
(i = e[o]) && (s = i(s) || s);
|
|
266
266
|
return s;
|
|
267
|
-
},
|
|
267
|
+
}, be = (e, t) => (r, n) => t(r, n, e);
|
|
268
268
|
let N = class {
|
|
269
269
|
constructor(e) {
|
|
270
270
|
this._logService = e;
|
|
@@ -284,7 +284,7 @@ let N = class {
|
|
|
284
284
|
var l, h;
|
|
285
285
|
let n;
|
|
286
286
|
try {
|
|
287
|
-
const a =
|
|
287
|
+
const a = Z(e), g = e.getUrlWithParams(), p = fetch(g, {
|
|
288
288
|
signal: r.signal,
|
|
289
289
|
...a
|
|
290
290
|
});
|
|
@@ -303,7 +303,7 @@ let N = class {
|
|
|
303
303
|
const s = new I(n.headers), o = n.status, i = n.statusText;
|
|
304
304
|
let c = null;
|
|
305
305
|
if (n.body && (c = await this._readBody(e, n, t)), o >= L.Ok && o < L.MultipleChoices)
|
|
306
|
-
t.next(new
|
|
306
|
+
t.next(new q({
|
|
307
307
|
body: c,
|
|
308
308
|
headers: s,
|
|
309
309
|
status: o,
|
|
@@ -330,16 +330,16 @@ let N = class {
|
|
|
330
330
|
for (; ; ) {
|
|
331
331
|
const { done: f, value: y } = await s.read();
|
|
332
332
|
if (f) break;
|
|
333
|
-
n.push(y), i += y.length, c && d === "text" && (l = (l != null ? l : "") + (h != null ? h : h = new TextDecoder()).decode(y, { stream: !0 }), r.next(new
|
|
333
|
+
n.push(y), i += y.length, c && d === "text" && (l = (l != null ? l : "") + (h != null ? h : h = new TextDecoder()).decode(y, { stream: !0 }), r.next(new _e(
|
|
334
334
|
o ? Number.parseInt(o, 10) : void 0,
|
|
335
335
|
i,
|
|
336
336
|
l
|
|
337
337
|
)));
|
|
338
338
|
}
|
|
339
|
-
const a =
|
|
339
|
+
const a = xe(n, i);
|
|
340
340
|
try {
|
|
341
341
|
const f = (p = t.headers.get("content-type")) != null ? p : "";
|
|
342
|
-
return
|
|
342
|
+
return Ne(e, a, f);
|
|
343
343
|
} catch (f) {
|
|
344
344
|
const y = new v({
|
|
345
345
|
request: e,
|
|
@@ -352,21 +352,21 @@ let N = class {
|
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
354
|
};
|
|
355
|
-
N =
|
|
356
|
-
|
|
355
|
+
N = Ie([
|
|
356
|
+
be(0, $)
|
|
357
357
|
], N);
|
|
358
|
-
function
|
|
358
|
+
function xe(e, t) {
|
|
359
359
|
const r = new Uint8Array(t);
|
|
360
360
|
let n = 0;
|
|
361
361
|
for (const s of e)
|
|
362
362
|
r.set(s, n), n += s.length;
|
|
363
363
|
return r;
|
|
364
364
|
}
|
|
365
|
-
const
|
|
366
|
-
function
|
|
365
|
+
const Le = /^\)\]\}',?\n/;
|
|
366
|
+
function Ne(e, t, r) {
|
|
367
367
|
switch (e.responseType) {
|
|
368
368
|
case "json":
|
|
369
|
-
const n = new TextDecoder().decode(t).replace(
|
|
369
|
+
const n = new TextDecoder().decode(t).replace(Le, "");
|
|
370
370
|
return n === "" ? null : JSON.parse(n);
|
|
371
371
|
case "text":
|
|
372
372
|
return new TextDecoder().decode(t);
|
|
@@ -378,38 +378,38 @@ function Ie(e, t, r) {
|
|
|
378
378
|
throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`);
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
|
-
var
|
|
382
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
381
|
+
var Ae = Object.getOwnPropertyDescriptor, Fe = (e, t, r, n) => {
|
|
382
|
+
for (var s = n > 1 ? void 0 : n ? Ae(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
383
383
|
(i = e[o]) && (s = i(s) || s);
|
|
384
384
|
return s;
|
|
385
|
-
},
|
|
386
|
-
let
|
|
385
|
+
}, ke = (e, t) => (r, n) => t(r, n, e);
|
|
386
|
+
let D = class {
|
|
387
387
|
constructor(e) {
|
|
388
388
|
this._logService = e;
|
|
389
389
|
}
|
|
390
390
|
send(e) {
|
|
391
391
|
return new m((t) => {
|
|
392
|
-
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s =
|
|
392
|
+
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = Z(e), { responseType: o } = e;
|
|
393
393
|
r.open(e.method, n), e.withCredentials && (r.withCredentials = !0), s.headers && Object.entries(s.headers).forEach(([h, a]) => r.setRequestHeader(h, a));
|
|
394
394
|
const i = () => {
|
|
395
395
|
const h = r.statusText || "OK", a = new I(r.getAllResponseHeaders());
|
|
396
|
-
return new
|
|
396
|
+
return new Ee(a, r.status, h);
|
|
397
397
|
}, c = () => {
|
|
398
398
|
const { headers: h, statusText: a, status: g } = i();
|
|
399
399
|
let p = null, f = null;
|
|
400
400
|
g !== L.NoContent && (p = typeof r.response > "u" ? r.responseText : r.response);
|
|
401
|
-
let y = g >=
|
|
401
|
+
let y = g >= me && g < ve;
|
|
402
402
|
if (o === "json" && typeof p == "string") {
|
|
403
403
|
const w = p;
|
|
404
404
|
try {
|
|
405
405
|
p = p ? JSON.parse(p) : null;
|
|
406
|
-
} catch (
|
|
407
|
-
y = !1, p = w, f =
|
|
406
|
+
} catch (_) {
|
|
407
|
+
y = !1, p = w, f = _;
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
if (o === "blob" && !(p instanceof Blob) && (y = !1, f = new Error("Response is not a Blob object")), y)
|
|
411
411
|
t.next(
|
|
412
|
-
new
|
|
412
|
+
new q({
|
|
413
413
|
body: p,
|
|
414
414
|
headers: h,
|
|
415
415
|
status: g,
|
|
@@ -444,101 +444,51 @@ let O = class {
|
|
|
444
444
|
});
|
|
445
445
|
}
|
|
446
446
|
};
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
],
|
|
450
|
-
var
|
|
451
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
447
|
+
D = Fe([
|
|
448
|
+
ke(0, $)
|
|
449
|
+
], D);
|
|
450
|
+
var Ue = Object.getOwnPropertyDescriptor, Oe = (e, t, r, n) => {
|
|
451
|
+
for (var s = n > 1 ? void 0 : n ? Ue(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
452
452
|
(i = e[o]) && (s = i(s) || s);
|
|
453
453
|
return s;
|
|
454
|
-
},
|
|
455
|
-
let
|
|
456
|
-
constructor(e =
|
|
457
|
-
super(), this._config = e, this._logger = t, this._injector = r;
|
|
454
|
+
}, k = (e, t) => (r, n) => t(r, n, e), U;
|
|
455
|
+
let V = (U = class extends ee {
|
|
456
|
+
constructor(e = G, t, r, n) {
|
|
457
|
+
super(), this._config = e, this._logger = t, this._injector = r, this._configService = n;
|
|
458
|
+
const { ...s } = re(
|
|
459
|
+
{},
|
|
460
|
+
G,
|
|
461
|
+
this._config
|
|
462
|
+
);
|
|
463
|
+
this._configService.setConfig(pe, s);
|
|
458
464
|
}
|
|
459
465
|
onStarting() {
|
|
460
466
|
var r, n, s;
|
|
461
|
-
if (this._injector.get(x,
|
|
467
|
+
if (this._injector.get(x, te.OPTIONAL, ne.SKIP_SELF) && !((r = this._config) != null && r.forceUseNewInstance)) {
|
|
462
468
|
this._logger.warn(
|
|
463
469
|
"[UniverNetworkPlugin]",
|
|
464
470
|
'HTTPService is already registered in an ancestor interceptor. Skipping registration. If you want to force a new instance, set "forceUseNewInstance" to true in the plugin configuration.'
|
|
465
471
|
);
|
|
466
472
|
return;
|
|
467
473
|
}
|
|
468
|
-
const t = (n = this._config) != null && n.useFetchImpl ? N : typeof window < "u" ?
|
|
469
|
-
|
|
474
|
+
const t = (n = this._config) != null && n.useFetchImpl ? N : typeof window < "u" ? D : N;
|
|
475
|
+
se(this._injector, oe([
|
|
470
476
|
[x],
|
|
471
|
-
[
|
|
477
|
+
[Y, { useClass: t }]
|
|
472
478
|
], (s = this._config) == null ? void 0 : s.override));
|
|
473
479
|
}
|
|
474
|
-
}, u(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
createSocket(t) {
|
|
482
|
-
try {
|
|
483
|
-
const r = new WebSocket(t), n = new ne();
|
|
484
|
-
return {
|
|
485
|
-
URL: t,
|
|
486
|
-
close: (o, i) => {
|
|
487
|
-
r.close(o, i), n.dispose();
|
|
488
|
-
},
|
|
489
|
-
send: (o) => {
|
|
490
|
-
r.send(o);
|
|
491
|
-
},
|
|
492
|
-
open$: new m((o) => {
|
|
493
|
-
const i = (c) => o.next(c);
|
|
494
|
-
r.addEventListener("open", i), n.add(R(() => r.removeEventListener("open", i)));
|
|
495
|
-
}).pipe(b()),
|
|
496
|
-
close$: new m((o) => {
|
|
497
|
-
const i = (c) => o.next(c);
|
|
498
|
-
r.addEventListener("close", i), n.add(R(() => r.removeEventListener("close", i)));
|
|
499
|
-
}).pipe(b()),
|
|
500
|
-
error$: new m((o) => {
|
|
501
|
-
const i = (c) => o.next(c);
|
|
502
|
-
r.addEventListener("error", i), n.add(R(() => r.removeEventListener("error", i)));
|
|
503
|
-
}).pipe(b()),
|
|
504
|
-
message$: new m((o) => {
|
|
505
|
-
const i = (c) => o.next(c);
|
|
506
|
-
r.addEventListener("message", i), n.add(R(() => r.removeEventListener("message", i)));
|
|
507
|
-
}).pipe(b())
|
|
508
|
-
};
|
|
509
|
-
} catch (r) {
|
|
510
|
-
return console.error(r), null;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
515
|
-
var n, s;
|
|
516
|
-
const t = (n = e == null ? void 0 : e.maxRetryAttempts) != null ? n : Fe, r = (s = e == null ? void 0 : e.delayInterval) != null ? s : ke;
|
|
517
|
-
return (o, i) => i(o).pipe(ce({ delay: r, count: t }));
|
|
518
|
-
}, We = (e) => {
|
|
519
|
-
const t = [], r = /* @__PURE__ */ new Set(), n = () => {
|
|
520
|
-
var s;
|
|
521
|
-
for (; r.size < ((s = e == null ? void 0 : e.maxParallel) != null ? s : 1) && t.length > 0; ) {
|
|
522
|
-
const o = t.shift();
|
|
523
|
-
r.add(o), o();
|
|
524
|
-
}
|
|
525
|
-
};
|
|
526
|
-
return (s, o) => new m((i) => {
|
|
527
|
-
const c = () => o(s).subscribe({
|
|
528
|
-
next: (l) => i.next(l),
|
|
529
|
-
error: (l) => i.error(l),
|
|
530
|
-
complete: () => i.complete()
|
|
531
|
-
}), d = () => {
|
|
532
|
-
r.delete(c), z(t, c), n();
|
|
533
|
-
};
|
|
534
|
-
return t.push(c), n(), d;
|
|
535
|
-
});
|
|
536
|
-
}, Xe = (e) => {
|
|
480
|
+
}, u(U, "pluginName", "UNIVER_NETWORK_PLUGIN"), U);
|
|
481
|
+
V = Oe([
|
|
482
|
+
k(1, $),
|
|
483
|
+
k(2, H(C)),
|
|
484
|
+
k(3, T)
|
|
485
|
+
], V);
|
|
486
|
+
const Xe = (e) => {
|
|
537
487
|
const { errorStatusCodes: t, onAuthError: r } = e;
|
|
538
488
|
return (s, o) => o(s).pipe(
|
|
539
|
-
|
|
489
|
+
ae((i) => (i instanceof v && t.some((c) => c === i.status) && r(), le(() => i)))
|
|
540
490
|
);
|
|
541
|
-
},
|
|
491
|
+
}, De = (e = 300) => {
|
|
542
492
|
let r = () => {
|
|
543
493
|
};
|
|
544
494
|
return (n) => new Promise((s) => {
|
|
@@ -550,8 +500,8 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
550
500
|
clearTimeout(o), s(!1);
|
|
551
501
|
};
|
|
552
502
|
});
|
|
553
|
-
},
|
|
554
|
-
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o =
|
|
503
|
+
}, $e = () => (e, t) => t.map((r) => ({ config: r, result: e })), Ve = (e, t = {}) => {
|
|
504
|
+
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = De(300), distributeResult: i = $e() } = t, c = [], d = (l) => l.map((h) => h.config);
|
|
555
505
|
return (l, h) => r(l) ? new m((a) => {
|
|
556
506
|
const g = n(l);
|
|
557
507
|
c.push({
|
|
@@ -564,20 +514,20 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
564
514
|
if (f) {
|
|
565
515
|
const y = [];
|
|
566
516
|
p.forEach((w) => {
|
|
567
|
-
const
|
|
568
|
-
if (
|
|
569
|
-
const [
|
|
570
|
-
y.push(
|
|
517
|
+
const _ = c.findIndex((E) => E.config === w);
|
|
518
|
+
if (_ >= 0) {
|
|
519
|
+
const [E] = c.splice(_, 1);
|
|
520
|
+
y.push(E);
|
|
571
521
|
}
|
|
572
522
|
}), h(s(p, l)).subscribe({
|
|
573
523
|
next: (w) => {
|
|
574
|
-
if (w.type ===
|
|
575
|
-
const
|
|
524
|
+
if (w.type === Q.Response) {
|
|
525
|
+
const _ = w.body, E = i(_, p);
|
|
576
526
|
y.forEach((A) => {
|
|
577
|
-
const
|
|
578
|
-
if (
|
|
579
|
-
const F = new
|
|
580
|
-
body:
|
|
527
|
+
const j = E.find((F) => F.config === A.config);
|
|
528
|
+
if (j) {
|
|
529
|
+
const F = new q({
|
|
530
|
+
body: j.result,
|
|
581
531
|
headers: w.headers,
|
|
582
532
|
status: w.status,
|
|
583
533
|
statusText: w.statusText
|
|
@@ -594,25 +544,81 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
594
544
|
}
|
|
595
545
|
});
|
|
596
546
|
}) : h(l);
|
|
597
|
-
}
|
|
547
|
+
}, qe = 3, je = 1e3, Je = (e) => {
|
|
548
|
+
var n, s;
|
|
549
|
+
const t = (n = e == null ? void 0 : e.maxRetryAttempts) != null ? n : qe, r = (s = e == null ? void 0 : e.delayInterval) != null ? s : je;
|
|
550
|
+
return (o, i) => i(o).pipe(he({ delay: r, count: t }));
|
|
551
|
+
}, Ke = (e) => {
|
|
552
|
+
const t = [], r = /* @__PURE__ */ new Set(), n = () => {
|
|
553
|
+
var s;
|
|
554
|
+
for (; r.size < ((s = e == null ? void 0 : e.maxParallel) != null ? s : 1) && t.length > 0; ) {
|
|
555
|
+
const o = t.shift();
|
|
556
|
+
r.add(o), o();
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
return (s, o) => new m((i) => {
|
|
560
|
+
const c = () => o(s).subscribe({
|
|
561
|
+
next: (l) => i.next(l),
|
|
562
|
+
error: (l) => i.error(l),
|
|
563
|
+
complete: () => i.complete()
|
|
564
|
+
}), d = () => {
|
|
565
|
+
r.delete(c), z(t, c), n();
|
|
566
|
+
};
|
|
567
|
+
return t.push(c), n(), d;
|
|
568
|
+
});
|
|
569
|
+
}, ze = J("univer.network.socket.service");
|
|
570
|
+
class Ye extends K {
|
|
571
|
+
createSocket(t) {
|
|
572
|
+
try {
|
|
573
|
+
const r = new WebSocket(t), n = new ie();
|
|
574
|
+
return {
|
|
575
|
+
URL: t,
|
|
576
|
+
close: (o, i) => {
|
|
577
|
+
r.close(o, i), n.dispose();
|
|
578
|
+
},
|
|
579
|
+
send: (o) => {
|
|
580
|
+
r.send(o);
|
|
581
|
+
},
|
|
582
|
+
open$: new m((o) => {
|
|
583
|
+
const i = (c) => o.next(c);
|
|
584
|
+
r.addEventListener("open", i), n.add(R(() => r.removeEventListener("open", i)));
|
|
585
|
+
}).pipe(b()),
|
|
586
|
+
close$: new m((o) => {
|
|
587
|
+
const i = (c) => o.next(c);
|
|
588
|
+
r.addEventListener("close", i), n.add(R(() => r.removeEventListener("close", i)));
|
|
589
|
+
}).pipe(b()),
|
|
590
|
+
error$: new m((o) => {
|
|
591
|
+
const i = (c) => o.next(c);
|
|
592
|
+
r.addEventListener("error", i), n.add(R(() => r.removeEventListener("error", i)));
|
|
593
|
+
}).pipe(b()),
|
|
594
|
+
message$: new m((o) => {
|
|
595
|
+
const i = (c) => o.next(c);
|
|
596
|
+
r.addEventListener("message", i), n.add(R(() => r.removeEventListener("message", i)));
|
|
597
|
+
}).pipe(b())
|
|
598
|
+
};
|
|
599
|
+
} catch (r) {
|
|
600
|
+
return console.error(r), null;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
598
604
|
export {
|
|
599
605
|
Xe as AuthInterceptorFactory,
|
|
600
606
|
N as FetchHTTPImplementation,
|
|
601
|
-
|
|
607
|
+
Q as HTTPEventType,
|
|
602
608
|
I as HTTPHeaders,
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
609
|
+
_e as HTTPProgress,
|
|
610
|
+
X as HTTPRequest,
|
|
611
|
+
q as HTTPResponse,
|
|
606
612
|
v as HTTPResponseError,
|
|
607
613
|
x as HTTPService,
|
|
608
614
|
L as HTTPStatusCode,
|
|
609
|
-
|
|
610
|
-
|
|
615
|
+
Y as IHTTPImplementation,
|
|
616
|
+
ze as ISocketService,
|
|
611
617
|
Ve as MergeInterceptorFactory,
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
+
Ee as ResponseHeader,
|
|
619
|
+
Je as RetryInterceptorFactory,
|
|
620
|
+
Ke as ThresholdInterceptorFactory,
|
|
621
|
+
V as UniverNetworkPlugin,
|
|
622
|
+
Ye as WebSocketService,
|
|
623
|
+
D as XHRHTTPImplementation
|
|
618
624
|
};
|