@univerjs/network 0.8.0-nightly.202506071606 → 0.8.0-nightly.202506091607
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 +121 -121
- package/lib/index.js +121 -121
- package/lib/umd/index.js +2 -2
- package/package.json +2 -2
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var G=Object.defineProperty;var W=(e,n,r)=>n in e?G(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;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){y(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();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,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)}getSSE(r,t,s){var d,u;const o=new E(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:(d=s==null?void 0:s.withCredentials)!=null?d:!1,reportProgress:!0,responseType:(u=s==null?void 0:s.responseType)!=null?u:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body});return w.of(c).pipe(_.concatMap(a=>this._runInterceptorsAndImplementation(a)))}async _request(r,t,s){var a,l;const o=new E(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:(a=s==null?void 0:s.withCredentials)!=null?a:!1,responseType:(l=s==null?void 0:s.responseType)!=null?l:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),d=w.of(c).pipe(_.concatMap(h=>this._runInterceptorsAndImplementation(h)));return await w.firstValueFrom(d)}_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}){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 j{constructor(n,r,t){y(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 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 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 b({error:s,request:n}))}),()=>t.abort()})}async _send(n,r,t){var a,l;let s;try{const h=X(n),f=n.getUrlWithParams(),m=fetch(f,{signal:t.signal,...h});this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${f} with params ${h}`),s=await m}catch(h){const f=new b({request:n,error:h,status:(a=h.status)!=null?a:0,statusText:(l=h.statusText)!=null?l:"Unknown Error",headers:h.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 d=null;if(s.body&&(d=await this._readBody(n,s,r)),i>=x.Ok&&i<x.MultipleChoices)r.next(new L({body:d,headers:o,status:i,statusText:c}));else{const h=new b({request:n,error:d,status:i,statusText:c,headers:o});this._logService.error("[FetchHTTPImplementation]: network error",h),r.error(h)}r.complete()}async _readBody(n,r,t){var f,m;const s=[],o=r.body.getReader(),i=r.headers.get("content-length");let c=0;const d=(f=n.requestParams)==null?void 0:f.reportProgress,u=n.responseType;let a,l;for(;;){const{done:v,value:g}=await o.read();if(v)break;s.push(g),c+=g.length,d&&u==="text"&&(a=(a!=null?a:"")+(l!=null?l:l=new TextDecoder).decode(g,{stream:!0}),t.next(new j(i?Number.parseInt(i,10):void 0,c,a)))}const h=T(s,c);try{const v=(m=r.headers.get("content-type"))!=null?m:"";return re(n,h,v)}catch(v){const g=new b({request:n,error:v,status:r.status,statusText:r.statusText,headers:new E(r.headers)});return this._logService.error("[FetchHTTPImplementation]: network error",g),t.error(g),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);t.open(n.method,s),n.withCredentials&&(t.withCredentials=!0),o.headers&&Object.entries(o.headers).forEach(([a,l])=>t.setRequestHeader(a,l));const i=()=>{const a=t.statusText||"OK",l=new E(t.getAllResponseHeaders());return new B(l,t.status,a)},c=()=>{const{headers:a,statusText:l,status:h}=i(),{responseType:f}=n;let m=null,v=null;h!==x.NoContent&&(m=typeof t.response>"u"?t.responseText:t.response);let g=h>=Z&&h<P;if(f==="json"&&typeof m=="string"){const I=m;try{m=m?JSON.parse(m):null}catch(R){g=!1,m=I,v=R}}if(g)r.next(new L({body:m,headers:a,status:h,statusText:l}));else{const I=new b({request:n,error:v,headers:a,status:h,statusText:l});this._logService.error("[XHRHTTPImplementation]: network error",I),r.error(I)}},d=a=>{const l=new b({request:n,error:a,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:i().headers});this._logService.error("[XHRHTTPImplementation]: network error",l),r.error(l)};t.addEventListener("load",c),t.addEventListener("error",d),t.addEventListener("abort",d),t.addEventListener("timeout",d);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",c),t.removeEventListener("error",d),t.removeEventListener("abort",d),t.removeEventListener("timeout",d)}})}};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))}},y(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(_.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(_.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(_.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(_.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(_.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:u=>i.next(u),error:u=>i.error(u),complete:()=>i.complete()}),d=()=>{r.delete(c),p.remove(n,c),t()};return n.push(c),t(),d})},ue=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))))},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=[],d=u=>u.map(a=>a.config);return(u,a)=>r(u)?new w.Observable(l=>{const h=t(u);c.push({next:m=>l.next(m),error:m=>l.error(m),config:h});const f=d(c);o(u).then(m=>{if(m){const v=[];f.forEach(g=>{const I=c.findIndex(R=>R.config===g);if(I>=0){const[R]=c.splice(I,1);v.push(R)}}),a(s(f,u)).subscribe({next:g=>{if(g.type===D.Response){const I=g.body,R=i(I,f);v.forEach(F=>{const q=R.find(N=>N.config===F.config);if(q){const N=new L({body:q.result,headers:g.headers,status:g.status,statusText:g.statusText});F.next(N)}else F.error("batch error")})}},complete:()=>l.complete(),error:g=>l.error(g)})}})}):a(u)};exports.AuthInterceptorFactory=ue;exports.HTTPEventType=D;exports.HTTPHeaders=E;exports.HTTPProgress=j;exports.HTTPRequest=O;exports.HTTPResponse=L;exports.HTTPResponseError=b;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 G=Object.defineProperty;var W=(e,n,r)=>n in e?G(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var f=(e,n,r)=>W(e,typeof n!="symbol"?n+"":n,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@univerjs/core"),w=require("rxjs"),_=require("rxjs/operators"),A="application/json";function V(e){return Array.isArray(e)?e.some(n=>n.includes(A)):e.includes(A)}class E{constructor(n){f(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 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)}getSSE(r,t,s){var y,l;const o=new E(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(_.concatMap(u=>this._runInterceptorsAndImplementation(u)))}async _request(r,t,s){var u,h;const o=new E(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(_.concatMap(a=>this._runInterceptorsAndImplementation(a)));return await w.firstValueFrom(y)}_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 E(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 E(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 E(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(_.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(_.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(_.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(_.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(_.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=E;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;
|
package/lib/es/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var Z = Object.defineProperty;
|
|
2
2
|
var P = (e, t, r) => t in e ? Z(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
3
|
+
var u = (e, t, r) => P(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { createIdentifier as V, Disposable as J, toDisposable as R, remove as z, ILogService as D, Inject as S, Injector as H, Plugin as C, Quantity as T, LookUp as ee, registerDependencies as re, mergeOverrideWithDependencies as te, DisposableCollection as ne } from "@univerjs/core";
|
|
5
|
-
import { of as
|
|
6
|
-
import { concatMap as
|
|
5
|
+
import { of as j, firstValueFrom as se, Observable as m, catchError as oe, throwError as ie } from "rxjs";
|
|
6
|
+
import { concatMap as M, share as b, retry as ce } from "rxjs/operators";
|
|
7
7
|
const U = "application/json";
|
|
8
8
|
function ae(e) {
|
|
9
9
|
return Array.isArray(e) ? e.some((t) => t.includes(U)) : e.includes(U);
|
|
10
10
|
}
|
|
11
11
|
class I {
|
|
12
12
|
constructor(t) {
|
|
13
|
-
|
|
13
|
+
u(this, "_headers", /* @__PURE__ */ new Map());
|
|
14
14
|
typeof t == "string" ? this._handleHeadersString(t) : t instanceof Headers ? this._handleHeaders(t) : t && this._handleHeadersConstructorProps(t);
|
|
15
15
|
}
|
|
16
16
|
forEach(t) {
|
|
@@ -66,7 +66,7 @@ class B {
|
|
|
66
66
|
let le = 0;
|
|
67
67
|
class G {
|
|
68
68
|
constructor(t, r, n) {
|
|
69
|
-
|
|
69
|
+
u(this, "uid", le++);
|
|
70
70
|
this.method = t, this.url = r, this.requestParams = n;
|
|
71
71
|
}
|
|
72
72
|
get headers() {
|
|
@@ -93,17 +93,17 @@ class G {
|
|
|
93
93
|
return this.headers.toHeadersInit((r = this.requestParams) == null ? void 0 : r.body);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
var he = Object.getOwnPropertyDescriptor,
|
|
96
|
+
var he = Object.getOwnPropertyDescriptor, pe = (e, t, r, n) => {
|
|
97
97
|
for (var s = n > 1 ? void 0 : n ? he(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
|
-
},
|
|
100
|
+
}, de = (e, t) => (r, n) => t(r, n, e);
|
|
101
101
|
let x = class extends J {
|
|
102
102
|
constructor(t) {
|
|
103
103
|
super();
|
|
104
|
-
|
|
104
|
+
u(this, "_interceptors", []);
|
|
105
105
|
// eslint-disable-next-line ts/no-explicit-any
|
|
106
|
-
|
|
106
|
+
u(this, "_pipe");
|
|
107
107
|
this._http = t;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
@@ -136,29 +136,29 @@ let x = class extends J {
|
|
|
136
136
|
return this._request("PATCH", t, r);
|
|
137
137
|
}
|
|
138
138
|
getSSE(t, r, n) {
|
|
139
|
-
var c,
|
|
139
|
+
var c, d;
|
|
140
140
|
const s = new I(n == null ? void 0 : n.headers), o = new B(n == null ? void 0 : n.params), i = new G(t, r, {
|
|
141
141
|
headers: s,
|
|
142
142
|
params: o,
|
|
143
143
|
withCredentials: (c = n == null ? void 0 : n.withCredentials) != null ? c : !1,
|
|
144
144
|
reportProgress: !0,
|
|
145
|
-
responseType: (
|
|
145
|
+
responseType: (d = n == null ? void 0 : n.responseType) != null ? d : "json",
|
|
146
146
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
147
147
|
});
|
|
148
|
-
return
|
|
148
|
+
return j(i).pipe(M((l) => this._runInterceptorsAndImplementation(l)));
|
|
149
149
|
}
|
|
150
150
|
/** The HTTP request implementations */
|
|
151
151
|
async _request(t, r, n) {
|
|
152
|
-
var
|
|
152
|
+
var l, h;
|
|
153
153
|
const s = new I(n == null ? void 0 : n.headers), o = new B(n == null ? void 0 : n.params), i = new G(t, r, {
|
|
154
154
|
headers: s,
|
|
155
155
|
params: o,
|
|
156
|
-
withCredentials: (
|
|
156
|
+
withCredentials: (l = n == null ? void 0 : n.withCredentials) != null ? l : !1,
|
|
157
157
|
// default value for withCredentials is false by MDN
|
|
158
158
|
responseType: (h = n == null ? void 0 : n.responseType) != null ? h : "json",
|
|
159
159
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
160
|
-
}), c =
|
|
161
|
-
|
|
160
|
+
}), c = j(i).pipe(
|
|
161
|
+
M((a) => this._runInterceptorsAndImplementation(a))
|
|
162
162
|
);
|
|
163
163
|
return await se(c);
|
|
164
164
|
}
|
|
@@ -174,8 +174,8 @@ let x = class extends J {
|
|
|
174
174
|
);
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
|
-
x =
|
|
178
|
-
|
|
177
|
+
x = pe([
|
|
178
|
+
de(0, K)
|
|
179
179
|
], x);
|
|
180
180
|
function ue(e, t) {
|
|
181
181
|
return (r, n) => t(r, (s) => e(s, n));
|
|
@@ -189,17 +189,17 @@ class $ {
|
|
|
189
189
|
status: n,
|
|
190
190
|
statusText: s
|
|
191
191
|
}) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
u(this, "type", 1);
|
|
193
|
+
u(this, "body");
|
|
194
|
+
u(this, "headers");
|
|
195
|
+
u(this, "status");
|
|
196
|
+
u(this, "statusText");
|
|
197
197
|
this.body = t, this.headers = r, this.status = n, this.statusText = s;
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
class ye {
|
|
201
201
|
constructor(t, r, n) {
|
|
202
|
-
|
|
202
|
+
u(this, "type", 0);
|
|
203
203
|
this.total = t, this.loaded = r, this.partialText = n;
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -216,11 +216,11 @@ class v {
|
|
|
216
216
|
statusText: s,
|
|
217
217
|
error: o
|
|
218
218
|
}) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
u(this, "request");
|
|
220
|
+
u(this, "headers");
|
|
221
|
+
u(this, "status");
|
|
222
|
+
u(this, "statusText");
|
|
223
|
+
u(this, "error");
|
|
224
224
|
this.request = t, this.headers = r, this.status = n, this.statusText = s, this.error = o;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
@@ -253,23 +253,23 @@ let N = class {
|
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
255
|
async _send(e, t, r) {
|
|
256
|
-
var
|
|
256
|
+
var l, h;
|
|
257
257
|
let n;
|
|
258
258
|
try {
|
|
259
|
-
const
|
|
259
|
+
const a = Q(e), g = e.getUrlWithParams(), p = fetch(g, {
|
|
260
260
|
signal: r.signal,
|
|
261
|
-
...
|
|
261
|
+
...a
|
|
262
262
|
});
|
|
263
|
-
this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${
|
|
264
|
-
} catch (
|
|
265
|
-
const
|
|
263
|
+
this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${g} with params ${a}`), n = await p;
|
|
264
|
+
} catch (a) {
|
|
265
|
+
const g = new v({
|
|
266
266
|
request: e,
|
|
267
|
-
error:
|
|
268
|
-
status: (
|
|
269
|
-
statusText: (h =
|
|
270
|
-
headers:
|
|
267
|
+
error: a,
|
|
268
|
+
status: (l = a.status) != null ? l : 0,
|
|
269
|
+
statusText: (h = a.statusText) != null ? h : "Unknown Error",
|
|
270
|
+
headers: a.headers
|
|
271
271
|
});
|
|
272
|
-
this._logService.error("[FetchHTTPImplementation]: network error",
|
|
272
|
+
this._logService.error("[FetchHTTPImplementation]: network error", g), t.error(g);
|
|
273
273
|
return;
|
|
274
274
|
}
|
|
275
275
|
const s = new I(n.headers), o = n.status, i = n.statusText;
|
|
@@ -282,45 +282,45 @@ let N = class {
|
|
|
282
282
|
statusText: i
|
|
283
283
|
}));
|
|
284
284
|
else {
|
|
285
|
-
const
|
|
285
|
+
const a = new v({
|
|
286
286
|
request: e,
|
|
287
287
|
error: c,
|
|
288
288
|
status: o,
|
|
289
289
|
statusText: i,
|
|
290
290
|
headers: s
|
|
291
291
|
});
|
|
292
|
-
this._logService.error("[FetchHTTPImplementation]: network error",
|
|
292
|
+
this._logService.error("[FetchHTTPImplementation]: network error", a), t.error(a);
|
|
293
293
|
}
|
|
294
294
|
t.complete();
|
|
295
295
|
}
|
|
296
296
|
async _readBody(e, t, r) {
|
|
297
|
-
var
|
|
297
|
+
var g, p;
|
|
298
298
|
const n = [], s = t.body.getReader(), o = t.headers.get("content-length");
|
|
299
299
|
let i = 0;
|
|
300
|
-
const c = (
|
|
301
|
-
let
|
|
300
|
+
const c = (g = e.requestParams) == null ? void 0 : g.reportProgress, d = e.responseType;
|
|
301
|
+
let l, h;
|
|
302
302
|
for (; ; ) {
|
|
303
|
-
const { done:
|
|
304
|
-
if (
|
|
305
|
-
n.push(
|
|
303
|
+
const { done: f, value: y } = await s.read();
|
|
304
|
+
if (f) break;
|
|
305
|
+
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 ye(
|
|
306
306
|
o ? Number.parseInt(o, 10) : void 0,
|
|
307
307
|
i,
|
|
308
|
-
|
|
308
|
+
l
|
|
309
309
|
)));
|
|
310
310
|
}
|
|
311
|
-
const
|
|
311
|
+
const a = Ee(n, i);
|
|
312
312
|
try {
|
|
313
|
-
const
|
|
314
|
-
return Ie(e,
|
|
315
|
-
} catch (
|
|
316
|
-
const
|
|
313
|
+
const f = (p = t.headers.get("content-type")) != null ? p : "";
|
|
314
|
+
return Ie(e, a, f);
|
|
315
|
+
} catch (f) {
|
|
316
|
+
const y = new v({
|
|
317
317
|
request: e,
|
|
318
|
-
error:
|
|
318
|
+
error: f,
|
|
319
319
|
status: t.status,
|
|
320
320
|
statusText: t.statusText,
|
|
321
321
|
headers: new I(t.headers)
|
|
322
322
|
});
|
|
323
|
-
return this._logService.error("[FetchHTTPImplementation]: network error",
|
|
323
|
+
return this._logService.error("[FetchHTTPImplementation]: network error", y), r.error(y), null;
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
};
|
|
@@ -361,57 +361,57 @@ let O = class {
|
|
|
361
361
|
}
|
|
362
362
|
send(e) {
|
|
363
363
|
return new m((t) => {
|
|
364
|
-
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = Q(e);
|
|
365
|
-
r.open(e.method, n), e.withCredentials && (r.withCredentials = !0), s.headers && Object.entries(s.headers).forEach(([
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
return new we(
|
|
369
|
-
},
|
|
370
|
-
const { headers:
|
|
371
|
-
let
|
|
372
|
-
|
|
373
|
-
let
|
|
374
|
-
if (
|
|
375
|
-
const
|
|
364
|
+
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = Q(e), { responseType: o } = e;
|
|
365
|
+
r.open(e.method, n), e.withCredentials && (r.withCredentials = !0), s.headers && Object.entries(s.headers).forEach(([h, a]) => r.setRequestHeader(h, a));
|
|
366
|
+
const i = () => {
|
|
367
|
+
const h = r.statusText || "OK", a = new I(r.getAllResponseHeaders());
|
|
368
|
+
return new we(a, r.status, h);
|
|
369
|
+
}, c = () => {
|
|
370
|
+
const { headers: h, statusText: a, status: g } = i();
|
|
371
|
+
let p = null, f = null;
|
|
372
|
+
g !== L.NoContent && (p = typeof r.response > "u" ? r.responseText : r.response);
|
|
373
|
+
let y = g >= ge && g < fe;
|
|
374
|
+
if (o === "json" && typeof p == "string") {
|
|
375
|
+
const w = p;
|
|
376
376
|
try {
|
|
377
|
-
|
|
377
|
+
p = p ? JSON.parse(p) : null;
|
|
378
378
|
} catch (_) {
|
|
379
|
-
|
|
379
|
+
y = !1, p = w, f = _;
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
if (f)
|
|
382
|
+
if (o === "blob" && !(p instanceof Blob) && (y = !1, f = new Error("Response is not a Blob object")), y)
|
|
383
383
|
t.next(
|
|
384
384
|
new $({
|
|
385
|
-
body:
|
|
386
|
-
headers:
|
|
387
|
-
status:
|
|
388
|
-
statusText:
|
|
385
|
+
body: p,
|
|
386
|
+
headers: h,
|
|
387
|
+
status: g,
|
|
388
|
+
statusText: a
|
|
389
389
|
})
|
|
390
390
|
);
|
|
391
391
|
else {
|
|
392
|
-
const
|
|
392
|
+
const w = new v({
|
|
393
393
|
request: e,
|
|
394
|
-
error:
|
|
395
|
-
headers:
|
|
396
|
-
status:
|
|
397
|
-
statusText:
|
|
394
|
+
error: f,
|
|
395
|
+
headers: h,
|
|
396
|
+
status: g,
|
|
397
|
+
statusText: a
|
|
398
398
|
});
|
|
399
|
-
this._logService.error("[XHRHTTPImplementation]: network error",
|
|
399
|
+
this._logService.error("[XHRHTTPImplementation]: network error", w), t.error(w);
|
|
400
400
|
}
|
|
401
|
-
},
|
|
402
|
-
const
|
|
401
|
+
}, d = (h) => {
|
|
402
|
+
const a = new v({
|
|
403
403
|
request: e,
|
|
404
|
-
error:
|
|
404
|
+
error: h,
|
|
405
405
|
status: r.status || 0,
|
|
406
406
|
statusText: r.statusText || "Unknown Error",
|
|
407
|
-
headers:
|
|
407
|
+
headers: i().headers
|
|
408
408
|
});
|
|
409
|
-
this._logService.error("[XHRHTTPImplementation]: network error",
|
|
409
|
+
this._logService.error("[XHRHTTPImplementation]: network error", a), t.error(a);
|
|
410
410
|
};
|
|
411
|
-
r.addEventListener("load",
|
|
412
|
-
const
|
|
413
|
-
return r.send(
|
|
414
|
-
r.readyState !== r.DONE && r.abort(), r.removeEventListener("load",
|
|
411
|
+
r.responseType = o || "", r.addEventListener("load", c), r.addEventListener("error", d), r.addEventListener("abort", d), r.addEventListener("timeout", d);
|
|
412
|
+
const l = e.getBody();
|
|
413
|
+
return r.send(l), this._logService.debug("[XHRHTTPImplementation]", `sending request to url ${n} with params ${s}`), () => {
|
|
414
|
+
r.readyState !== r.DONE && r.abort(), r.removeEventListener("load", c), r.removeEventListener("error", d), r.removeEventListener("abort", d), r.removeEventListener("timeout", d);
|
|
415
415
|
};
|
|
416
416
|
});
|
|
417
417
|
}
|
|
@@ -443,12 +443,12 @@ let X = (k = class extends C {
|
|
|
443
443
|
[K, { useClass: t }]
|
|
444
444
|
], (s = this._config) == null ? void 0 : s.override));
|
|
445
445
|
}
|
|
446
|
-
},
|
|
446
|
+
}, u(k, "pluginName", "UNIVER_NETWORK_PLUGIN"), k);
|
|
447
447
|
X = Ae([
|
|
448
448
|
W(1, D),
|
|
449
449
|
W(2, S(H))
|
|
450
450
|
], X);
|
|
451
|
-
const
|
|
451
|
+
const Me = V("univer.network.socket.service");
|
|
452
452
|
class Be extends J {
|
|
453
453
|
createSocket(t) {
|
|
454
454
|
try {
|
|
@@ -497,13 +497,13 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
497
497
|
};
|
|
498
498
|
return (s, o) => new m((i) => {
|
|
499
499
|
const c = () => o(s).subscribe({
|
|
500
|
-
next: (
|
|
501
|
-
error: (
|
|
500
|
+
next: (l) => i.next(l),
|
|
501
|
+
error: (l) => i.error(l),
|
|
502
502
|
complete: () => i.complete()
|
|
503
|
-
}),
|
|
503
|
+
}), d = () => {
|
|
504
504
|
r.delete(c), z(t, c), n();
|
|
505
505
|
};
|
|
506
|
-
return t.push(c), n(),
|
|
506
|
+
return t.push(c), n(), d;
|
|
507
507
|
});
|
|
508
508
|
}, Xe = (e) => {
|
|
509
509
|
const { errorStatusCodes: t, onAuthError: r } = e;
|
|
@@ -523,36 +523,36 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
523
523
|
};
|
|
524
524
|
});
|
|
525
525
|
}, Oe = () => (e, t) => t.map((r) => ({ config: r, result: e })), Ve = (e, t = {}) => {
|
|
526
|
-
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = Ue(300), distributeResult: i = Oe() } = t, c = [],
|
|
527
|
-
return (
|
|
528
|
-
const
|
|
526
|
+
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = Ue(300), distributeResult: i = Oe() } = t, c = [], d = (l) => l.map((h) => h.config);
|
|
527
|
+
return (l, h) => r(l) ? new m((a) => {
|
|
528
|
+
const g = n(l);
|
|
529
529
|
c.push({
|
|
530
|
-
next: (
|
|
531
|
-
error: (
|
|
532
|
-
config:
|
|
530
|
+
next: (f) => a.next(f),
|
|
531
|
+
error: (f) => a.error(f),
|
|
532
|
+
config: g
|
|
533
533
|
});
|
|
534
|
-
const
|
|
535
|
-
o(
|
|
536
|
-
if (
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
const _ = c.findIndex((E) => E.config ===
|
|
534
|
+
const p = d(c);
|
|
535
|
+
o(l).then((f) => {
|
|
536
|
+
if (f) {
|
|
537
|
+
const y = [];
|
|
538
|
+
p.forEach((w) => {
|
|
539
|
+
const _ = c.findIndex((E) => E.config === w);
|
|
540
540
|
if (_ >= 0) {
|
|
541
541
|
const [E] = c.splice(_, 1);
|
|
542
|
-
|
|
542
|
+
y.push(E);
|
|
543
543
|
}
|
|
544
|
-
}), h(s(
|
|
545
|
-
next: (
|
|
546
|
-
if (
|
|
547
|
-
const _ =
|
|
548
|
-
|
|
544
|
+
}), h(s(p, l)).subscribe({
|
|
545
|
+
next: (w) => {
|
|
546
|
+
if (w.type === Y.Response) {
|
|
547
|
+
const _ = w.body, E = i(_, p);
|
|
548
|
+
y.forEach((A) => {
|
|
549
549
|
const q = E.find((F) => F.config === A.config);
|
|
550
550
|
if (q) {
|
|
551
551
|
const F = new $({
|
|
552
552
|
body: q.result,
|
|
553
|
-
headers:
|
|
554
|
-
status:
|
|
555
|
-
statusText:
|
|
553
|
+
headers: w.headers,
|
|
554
|
+
status: w.status,
|
|
555
|
+
statusText: w.statusText
|
|
556
556
|
});
|
|
557
557
|
A.next(F);
|
|
558
558
|
} else
|
|
@@ -560,12 +560,12 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
560
560
|
});
|
|
561
561
|
}
|
|
562
562
|
},
|
|
563
|
-
complete: () =>
|
|
564
|
-
error: (
|
|
563
|
+
complete: () => a.complete(),
|
|
564
|
+
error: (w) => a.error(w)
|
|
565
565
|
});
|
|
566
566
|
}
|
|
567
567
|
});
|
|
568
|
-
}) : h(
|
|
568
|
+
}) : h(l);
|
|
569
569
|
};
|
|
570
570
|
export {
|
|
571
571
|
Xe as AuthInterceptorFactory,
|
|
@@ -579,7 +579,7 @@ export {
|
|
|
579
579
|
x as HTTPService,
|
|
580
580
|
L as HTTPStatusCode,
|
|
581
581
|
K as IHTTPImplementation,
|
|
582
|
-
|
|
582
|
+
Me as ISocketService,
|
|
583
583
|
Ve as MergeInterceptorFactory,
|
|
584
584
|
we as ResponseHeader,
|
|
585
585
|
Ge as RetryInterceptorFactory,
|
package/lib/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var Z = Object.defineProperty;
|
|
2
2
|
var P = (e, t, r) => t in e ? Z(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
3
|
+
var u = (e, t, r) => P(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { createIdentifier as V, Disposable as J, toDisposable as R, remove as z, ILogService as D, Inject as S, Injector as H, Plugin as C, Quantity as T, LookUp as ee, registerDependencies as re, mergeOverrideWithDependencies as te, DisposableCollection as ne } from "@univerjs/core";
|
|
5
|
-
import { of as
|
|
6
|
-
import { concatMap as
|
|
5
|
+
import { of as j, firstValueFrom as se, Observable as m, catchError as oe, throwError as ie } from "rxjs";
|
|
6
|
+
import { concatMap as M, share as b, retry as ce } from "rxjs/operators";
|
|
7
7
|
const U = "application/json";
|
|
8
8
|
function ae(e) {
|
|
9
9
|
return Array.isArray(e) ? e.some((t) => t.includes(U)) : e.includes(U);
|
|
10
10
|
}
|
|
11
11
|
class I {
|
|
12
12
|
constructor(t) {
|
|
13
|
-
|
|
13
|
+
u(this, "_headers", /* @__PURE__ */ new Map());
|
|
14
14
|
typeof t == "string" ? this._handleHeadersString(t) : t instanceof Headers ? this._handleHeaders(t) : t && this._handleHeadersConstructorProps(t);
|
|
15
15
|
}
|
|
16
16
|
forEach(t) {
|
|
@@ -66,7 +66,7 @@ class B {
|
|
|
66
66
|
let le = 0;
|
|
67
67
|
class G {
|
|
68
68
|
constructor(t, r, n) {
|
|
69
|
-
|
|
69
|
+
u(this, "uid", le++);
|
|
70
70
|
this.method = t, this.url = r, this.requestParams = n;
|
|
71
71
|
}
|
|
72
72
|
get headers() {
|
|
@@ -93,17 +93,17 @@ class G {
|
|
|
93
93
|
return this.headers.toHeadersInit((r = this.requestParams) == null ? void 0 : r.body);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
var he = Object.getOwnPropertyDescriptor,
|
|
96
|
+
var he = Object.getOwnPropertyDescriptor, pe = (e, t, r, n) => {
|
|
97
97
|
for (var s = n > 1 ? void 0 : n ? he(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
|
-
},
|
|
100
|
+
}, de = (e, t) => (r, n) => t(r, n, e);
|
|
101
101
|
let x = class extends J {
|
|
102
102
|
constructor(t) {
|
|
103
103
|
super();
|
|
104
|
-
|
|
104
|
+
u(this, "_interceptors", []);
|
|
105
105
|
// eslint-disable-next-line ts/no-explicit-any
|
|
106
|
-
|
|
106
|
+
u(this, "_pipe");
|
|
107
107
|
this._http = t;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
@@ -136,29 +136,29 @@ let x = class extends J {
|
|
|
136
136
|
return this._request("PATCH", t, r);
|
|
137
137
|
}
|
|
138
138
|
getSSE(t, r, n) {
|
|
139
|
-
var c,
|
|
139
|
+
var c, d;
|
|
140
140
|
const s = new I(n == null ? void 0 : n.headers), o = new B(n == null ? void 0 : n.params), i = new G(t, r, {
|
|
141
141
|
headers: s,
|
|
142
142
|
params: o,
|
|
143
143
|
withCredentials: (c = n == null ? void 0 : n.withCredentials) != null ? c : !1,
|
|
144
144
|
reportProgress: !0,
|
|
145
|
-
responseType: (
|
|
145
|
+
responseType: (d = n == null ? void 0 : n.responseType) != null ? d : "json",
|
|
146
146
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
147
147
|
});
|
|
148
|
-
return
|
|
148
|
+
return j(i).pipe(M((l) => this._runInterceptorsAndImplementation(l)));
|
|
149
149
|
}
|
|
150
150
|
/** The HTTP request implementations */
|
|
151
151
|
async _request(t, r, n) {
|
|
152
|
-
var
|
|
152
|
+
var l, h;
|
|
153
153
|
const s = new I(n == null ? void 0 : n.headers), o = new B(n == null ? void 0 : n.params), i = new G(t, r, {
|
|
154
154
|
headers: s,
|
|
155
155
|
params: o,
|
|
156
|
-
withCredentials: (
|
|
156
|
+
withCredentials: (l = n == null ? void 0 : n.withCredentials) != null ? l : !1,
|
|
157
157
|
// default value for withCredentials is false by MDN
|
|
158
158
|
responseType: (h = n == null ? void 0 : n.responseType) != null ? h : "json",
|
|
159
159
|
body: ["GET", "DELETE"].includes(t) || n == null ? void 0 : n.body
|
|
160
|
-
}), c =
|
|
161
|
-
|
|
160
|
+
}), c = j(i).pipe(
|
|
161
|
+
M((a) => this._runInterceptorsAndImplementation(a))
|
|
162
162
|
);
|
|
163
163
|
return await se(c);
|
|
164
164
|
}
|
|
@@ -174,8 +174,8 @@ let x = class extends J {
|
|
|
174
174
|
);
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
|
-
x =
|
|
178
|
-
|
|
177
|
+
x = pe([
|
|
178
|
+
de(0, K)
|
|
179
179
|
], x);
|
|
180
180
|
function ue(e, t) {
|
|
181
181
|
return (r, n) => t(r, (s) => e(s, n));
|
|
@@ -189,17 +189,17 @@ class $ {
|
|
|
189
189
|
status: n,
|
|
190
190
|
statusText: s
|
|
191
191
|
}) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
u(this, "type", 1);
|
|
193
|
+
u(this, "body");
|
|
194
|
+
u(this, "headers");
|
|
195
|
+
u(this, "status");
|
|
196
|
+
u(this, "statusText");
|
|
197
197
|
this.body = t, this.headers = r, this.status = n, this.statusText = s;
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
class ye {
|
|
201
201
|
constructor(t, r, n) {
|
|
202
|
-
|
|
202
|
+
u(this, "type", 0);
|
|
203
203
|
this.total = t, this.loaded = r, this.partialText = n;
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -216,11 +216,11 @@ class v {
|
|
|
216
216
|
statusText: s,
|
|
217
217
|
error: o
|
|
218
218
|
}) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
u(this, "request");
|
|
220
|
+
u(this, "headers");
|
|
221
|
+
u(this, "status");
|
|
222
|
+
u(this, "statusText");
|
|
223
|
+
u(this, "error");
|
|
224
224
|
this.request = t, this.headers = r, this.status = n, this.statusText = s, this.error = o;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
@@ -253,23 +253,23 @@ let N = class {
|
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
255
|
async _send(e, t, r) {
|
|
256
|
-
var
|
|
256
|
+
var l, h;
|
|
257
257
|
let n;
|
|
258
258
|
try {
|
|
259
|
-
const
|
|
259
|
+
const a = Q(e), g = e.getUrlWithParams(), p = fetch(g, {
|
|
260
260
|
signal: r.signal,
|
|
261
|
-
...
|
|
261
|
+
...a
|
|
262
262
|
});
|
|
263
|
-
this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${
|
|
264
|
-
} catch (
|
|
265
|
-
const
|
|
263
|
+
this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${g} with params ${a}`), n = await p;
|
|
264
|
+
} catch (a) {
|
|
265
|
+
const g = new v({
|
|
266
266
|
request: e,
|
|
267
|
-
error:
|
|
268
|
-
status: (
|
|
269
|
-
statusText: (h =
|
|
270
|
-
headers:
|
|
267
|
+
error: a,
|
|
268
|
+
status: (l = a.status) != null ? l : 0,
|
|
269
|
+
statusText: (h = a.statusText) != null ? h : "Unknown Error",
|
|
270
|
+
headers: a.headers
|
|
271
271
|
});
|
|
272
|
-
this._logService.error("[FetchHTTPImplementation]: network error",
|
|
272
|
+
this._logService.error("[FetchHTTPImplementation]: network error", g), t.error(g);
|
|
273
273
|
return;
|
|
274
274
|
}
|
|
275
275
|
const s = new I(n.headers), o = n.status, i = n.statusText;
|
|
@@ -282,45 +282,45 @@ let N = class {
|
|
|
282
282
|
statusText: i
|
|
283
283
|
}));
|
|
284
284
|
else {
|
|
285
|
-
const
|
|
285
|
+
const a = new v({
|
|
286
286
|
request: e,
|
|
287
287
|
error: c,
|
|
288
288
|
status: o,
|
|
289
289
|
statusText: i,
|
|
290
290
|
headers: s
|
|
291
291
|
});
|
|
292
|
-
this._logService.error("[FetchHTTPImplementation]: network error",
|
|
292
|
+
this._logService.error("[FetchHTTPImplementation]: network error", a), t.error(a);
|
|
293
293
|
}
|
|
294
294
|
t.complete();
|
|
295
295
|
}
|
|
296
296
|
async _readBody(e, t, r) {
|
|
297
|
-
var
|
|
297
|
+
var g, p;
|
|
298
298
|
const n = [], s = t.body.getReader(), o = t.headers.get("content-length");
|
|
299
299
|
let i = 0;
|
|
300
|
-
const c = (
|
|
301
|
-
let
|
|
300
|
+
const c = (g = e.requestParams) == null ? void 0 : g.reportProgress, d = e.responseType;
|
|
301
|
+
let l, h;
|
|
302
302
|
for (; ; ) {
|
|
303
|
-
const { done:
|
|
304
|
-
if (
|
|
305
|
-
n.push(
|
|
303
|
+
const { done: f, value: y } = await s.read();
|
|
304
|
+
if (f) break;
|
|
305
|
+
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 ye(
|
|
306
306
|
o ? Number.parseInt(o, 10) : void 0,
|
|
307
307
|
i,
|
|
308
|
-
|
|
308
|
+
l
|
|
309
309
|
)));
|
|
310
310
|
}
|
|
311
|
-
const
|
|
311
|
+
const a = Ee(n, i);
|
|
312
312
|
try {
|
|
313
|
-
const
|
|
314
|
-
return Ie(e,
|
|
315
|
-
} catch (
|
|
316
|
-
const
|
|
313
|
+
const f = (p = t.headers.get("content-type")) != null ? p : "";
|
|
314
|
+
return Ie(e, a, f);
|
|
315
|
+
} catch (f) {
|
|
316
|
+
const y = new v({
|
|
317
317
|
request: e,
|
|
318
|
-
error:
|
|
318
|
+
error: f,
|
|
319
319
|
status: t.status,
|
|
320
320
|
statusText: t.statusText,
|
|
321
321
|
headers: new I(t.headers)
|
|
322
322
|
});
|
|
323
|
-
return this._logService.error("[FetchHTTPImplementation]: network error",
|
|
323
|
+
return this._logService.error("[FetchHTTPImplementation]: network error", y), r.error(y), null;
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
};
|
|
@@ -361,57 +361,57 @@ let O = class {
|
|
|
361
361
|
}
|
|
362
362
|
send(e) {
|
|
363
363
|
return new m((t) => {
|
|
364
|
-
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = Q(e);
|
|
365
|
-
r.open(e.method, n), e.withCredentials && (r.withCredentials = !0), s.headers && Object.entries(s.headers).forEach(([
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
return new we(
|
|
369
|
-
},
|
|
370
|
-
const { headers:
|
|
371
|
-
let
|
|
372
|
-
|
|
373
|
-
let
|
|
374
|
-
if (
|
|
375
|
-
const
|
|
364
|
+
const r = new XMLHttpRequest(), n = e.getUrlWithParams(), s = Q(e), { responseType: o } = e;
|
|
365
|
+
r.open(e.method, n), e.withCredentials && (r.withCredentials = !0), s.headers && Object.entries(s.headers).forEach(([h, a]) => r.setRequestHeader(h, a));
|
|
366
|
+
const i = () => {
|
|
367
|
+
const h = r.statusText || "OK", a = new I(r.getAllResponseHeaders());
|
|
368
|
+
return new we(a, r.status, h);
|
|
369
|
+
}, c = () => {
|
|
370
|
+
const { headers: h, statusText: a, status: g } = i();
|
|
371
|
+
let p = null, f = null;
|
|
372
|
+
g !== L.NoContent && (p = typeof r.response > "u" ? r.responseText : r.response);
|
|
373
|
+
let y = g >= ge && g < fe;
|
|
374
|
+
if (o === "json" && typeof p == "string") {
|
|
375
|
+
const w = p;
|
|
376
376
|
try {
|
|
377
|
-
|
|
377
|
+
p = p ? JSON.parse(p) : null;
|
|
378
378
|
} catch (_) {
|
|
379
|
-
|
|
379
|
+
y = !1, p = w, f = _;
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
if (f)
|
|
382
|
+
if (o === "blob" && !(p instanceof Blob) && (y = !1, f = new Error("Response is not a Blob object")), y)
|
|
383
383
|
t.next(
|
|
384
384
|
new $({
|
|
385
|
-
body:
|
|
386
|
-
headers:
|
|
387
|
-
status:
|
|
388
|
-
statusText:
|
|
385
|
+
body: p,
|
|
386
|
+
headers: h,
|
|
387
|
+
status: g,
|
|
388
|
+
statusText: a
|
|
389
389
|
})
|
|
390
390
|
);
|
|
391
391
|
else {
|
|
392
|
-
const
|
|
392
|
+
const w = new v({
|
|
393
393
|
request: e,
|
|
394
|
-
error:
|
|
395
|
-
headers:
|
|
396
|
-
status:
|
|
397
|
-
statusText:
|
|
394
|
+
error: f,
|
|
395
|
+
headers: h,
|
|
396
|
+
status: g,
|
|
397
|
+
statusText: a
|
|
398
398
|
});
|
|
399
|
-
this._logService.error("[XHRHTTPImplementation]: network error",
|
|
399
|
+
this._logService.error("[XHRHTTPImplementation]: network error", w), t.error(w);
|
|
400
400
|
}
|
|
401
|
-
},
|
|
402
|
-
const
|
|
401
|
+
}, d = (h) => {
|
|
402
|
+
const a = new v({
|
|
403
403
|
request: e,
|
|
404
|
-
error:
|
|
404
|
+
error: h,
|
|
405
405
|
status: r.status || 0,
|
|
406
406
|
statusText: r.statusText || "Unknown Error",
|
|
407
|
-
headers:
|
|
407
|
+
headers: i().headers
|
|
408
408
|
});
|
|
409
|
-
this._logService.error("[XHRHTTPImplementation]: network error",
|
|
409
|
+
this._logService.error("[XHRHTTPImplementation]: network error", a), t.error(a);
|
|
410
410
|
};
|
|
411
|
-
r.addEventListener("load",
|
|
412
|
-
const
|
|
413
|
-
return r.send(
|
|
414
|
-
r.readyState !== r.DONE && r.abort(), r.removeEventListener("load",
|
|
411
|
+
r.responseType = o || "", r.addEventListener("load", c), r.addEventListener("error", d), r.addEventListener("abort", d), r.addEventListener("timeout", d);
|
|
412
|
+
const l = e.getBody();
|
|
413
|
+
return r.send(l), this._logService.debug("[XHRHTTPImplementation]", `sending request to url ${n} with params ${s}`), () => {
|
|
414
|
+
r.readyState !== r.DONE && r.abort(), r.removeEventListener("load", c), r.removeEventListener("error", d), r.removeEventListener("abort", d), r.removeEventListener("timeout", d);
|
|
415
415
|
};
|
|
416
416
|
});
|
|
417
417
|
}
|
|
@@ -443,12 +443,12 @@ let X = (k = class extends C {
|
|
|
443
443
|
[K, { useClass: t }]
|
|
444
444
|
], (s = this._config) == null ? void 0 : s.override));
|
|
445
445
|
}
|
|
446
|
-
},
|
|
446
|
+
}, u(k, "pluginName", "UNIVER_NETWORK_PLUGIN"), k);
|
|
447
447
|
X = Ae([
|
|
448
448
|
W(1, D),
|
|
449
449
|
W(2, S(H))
|
|
450
450
|
], X);
|
|
451
|
-
const
|
|
451
|
+
const Me = V("univer.network.socket.service");
|
|
452
452
|
class Be extends J {
|
|
453
453
|
createSocket(t) {
|
|
454
454
|
try {
|
|
@@ -497,13 +497,13 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
497
497
|
};
|
|
498
498
|
return (s, o) => new m((i) => {
|
|
499
499
|
const c = () => o(s).subscribe({
|
|
500
|
-
next: (
|
|
501
|
-
error: (
|
|
500
|
+
next: (l) => i.next(l),
|
|
501
|
+
error: (l) => i.error(l),
|
|
502
502
|
complete: () => i.complete()
|
|
503
|
-
}),
|
|
503
|
+
}), d = () => {
|
|
504
504
|
r.delete(c), z(t, c), n();
|
|
505
505
|
};
|
|
506
|
-
return t.push(c), n(),
|
|
506
|
+
return t.push(c), n(), d;
|
|
507
507
|
});
|
|
508
508
|
}, Xe = (e) => {
|
|
509
509
|
const { errorStatusCodes: t, onAuthError: r } = e;
|
|
@@ -523,36 +523,36 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
523
523
|
};
|
|
524
524
|
});
|
|
525
525
|
}, Oe = () => (e, t) => t.map((r) => ({ config: r, result: e })), Ve = (e, t = {}) => {
|
|
526
|
-
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = Ue(300), distributeResult: i = Oe() } = t, c = [],
|
|
527
|
-
return (
|
|
528
|
-
const
|
|
526
|
+
const { isMatch: r, getParamsFromRequest: n, mergeParamsToRequest: s } = e, { fetchCheck: o = Ue(300), distributeResult: i = Oe() } = t, c = [], d = (l) => l.map((h) => h.config);
|
|
527
|
+
return (l, h) => r(l) ? new m((a) => {
|
|
528
|
+
const g = n(l);
|
|
529
529
|
c.push({
|
|
530
|
-
next: (
|
|
531
|
-
error: (
|
|
532
|
-
config:
|
|
530
|
+
next: (f) => a.next(f),
|
|
531
|
+
error: (f) => a.error(f),
|
|
532
|
+
config: g
|
|
533
533
|
});
|
|
534
|
-
const
|
|
535
|
-
o(
|
|
536
|
-
if (
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
const _ = c.findIndex((E) => E.config ===
|
|
534
|
+
const p = d(c);
|
|
535
|
+
o(l).then((f) => {
|
|
536
|
+
if (f) {
|
|
537
|
+
const y = [];
|
|
538
|
+
p.forEach((w) => {
|
|
539
|
+
const _ = c.findIndex((E) => E.config === w);
|
|
540
540
|
if (_ >= 0) {
|
|
541
541
|
const [E] = c.splice(_, 1);
|
|
542
|
-
|
|
542
|
+
y.push(E);
|
|
543
543
|
}
|
|
544
|
-
}), h(s(
|
|
545
|
-
next: (
|
|
546
|
-
if (
|
|
547
|
-
const _ =
|
|
548
|
-
|
|
544
|
+
}), h(s(p, l)).subscribe({
|
|
545
|
+
next: (w) => {
|
|
546
|
+
if (w.type === Y.Response) {
|
|
547
|
+
const _ = w.body, E = i(_, p);
|
|
548
|
+
y.forEach((A) => {
|
|
549
549
|
const q = E.find((F) => F.config === A.config);
|
|
550
550
|
if (q) {
|
|
551
551
|
const F = new $({
|
|
552
552
|
body: q.result,
|
|
553
|
-
headers:
|
|
554
|
-
status:
|
|
555
|
-
statusText:
|
|
553
|
+
headers: w.headers,
|
|
554
|
+
status: w.status,
|
|
555
|
+
statusText: w.statusText
|
|
556
556
|
});
|
|
557
557
|
A.next(F);
|
|
558
558
|
} else
|
|
@@ -560,12 +560,12 @@ const Fe = 3, ke = 1e3, Ge = (e) => {
|
|
|
560
560
|
});
|
|
561
561
|
}
|
|
562
562
|
},
|
|
563
|
-
complete: () =>
|
|
564
|
-
error: (
|
|
563
|
+
complete: () => a.complete(),
|
|
564
|
+
error: (w) => a.error(w)
|
|
565
565
|
});
|
|
566
566
|
}
|
|
567
567
|
});
|
|
568
|
-
}) : h(
|
|
568
|
+
}) : h(l);
|
|
569
569
|
};
|
|
570
570
|
export {
|
|
571
571
|
Xe as AuthInterceptorFactory,
|
|
@@ -579,7 +579,7 @@ export {
|
|
|
579
579
|
x as HTTPService,
|
|
580
580
|
L as HTTPStatusCode,
|
|
581
581
|
K as IHTTPImplementation,
|
|
582
|
-
|
|
582
|
+
Me as ISocketService,
|
|
583
583
|
Ve as MergeInterceptorFactory,
|
|
584
584
|
we as ResponseHeader,
|
|
585
585
|
Ge as RetryInterceptorFactory,
|
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(c,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("rxjs"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","rxjs/operators"],a):(c=typeof globalThis<"u"?globalThis:c||self,a(c.UniverNetwork={},c.UniverCore,c.rxjs,c.rxjs.operators))})(this,function(c,a,
|
|
2
|
-
`).forEach(t=>{const[r,s]=t.split(":");r&&s&&this._setHeader(r,s)})}_handleHeadersConstructorProps(n){Object.entries(n).forEach(([t,r])=>this._setHeader(t,r))}_handleHeaders(n){n.forEach((t,r)=>this._setHeader(r,t))}}const A=a.createIdentifier("network.http-implementation");class ${constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>{const t=this.params[n];return Array.isArray(t)?t.map(r=>`${n}=${r}`).join("&"):`${n}=${t}`}).join("&"):""}}let V=0;class O{constructor(n,t,r){w(this,"uid",V++);this.method=n,this.url=t,this.requestParams=r}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var t,r;const n=(r=(t=this.requestParams)==null?void 0:t.params)==null?void 0:r.toString();return n?`${this.url}${this.url.includes("?")?"&":"?"}${n}`:this.url}getBody(){var r,s;const n=(r=this.headers.get("Content-Type"))!=null?r:k,t=(s=this.requestParams)==null?void 0:s.body;return t instanceof FormData?t:W(n)&&t&&typeof t=="object"?JSON.stringify(t):t?`${t}`:null}getHeadersInit(){var t;return this.headers.toHeadersInit((t=this.requestParams)==null?void 0:t.body)}}var J=Object.getOwnPropertyDescriptor,z=(e,n,t,r)=>{for(var s=r>1?void 0:r?J(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},K=(e,n)=>(t,r)=>n(t,r,e);c.HTTPService=class extends a.Disposable{constructor(t){super();w(this,"_interceptors",[]);w(this,"_pipe");this._http=t}registerHTTPInterceptor(t){if(this._interceptors.indexOf(t)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(t),this._interceptors=this._interceptors.sort((r,s)=>{var i,o;return((i=r.priority)!=null?i:0)-((o=s.priority)!=null?o:0)}),this._pipe=null,a.toDisposable(()=>a.remove(this._interceptors,t))}get(t,r){return this._request("GET",t,r)}post(t,r){return this._request("POST",t,r)}put(t,r){return this._request("PUT",t,r)}delete(t,r){return this._request("DELETE",t,r)}patch(t,r){return this._request("PATCH",t,r)}getSSE(t,r,s){var u,g;const i=new L(s==null?void 0:s.headers),o=new $(s==null?void 0:s.params),l=new O(t,r,{headers:i,params:o,withCredentials:(u=s==null?void 0:s.withCredentials)!=null?u:!1,reportProgress:!0,responseType:(g=s==null?void 0:s.responseType)!=null?g:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body});return y.of(l).pipe(_.concatMap(h=>this._runInterceptorsAndImplementation(h)))}async _request(t,r,s){var h,d;const i=new L(s==null?void 0:s.headers),o=new $(s==null?void 0:s.params),l=new O(t,r,{headers:i,params:o,withCredentials:(h=s==null?void 0:s.withCredentials)!=null?h:!1,responseType:(d=s==null?void 0:s.responseType)!=null?d:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body}),u=y.of(l).pipe(_.concatMap(p=>this._runInterceptorsAndImplementation(p)));return await y.firstValueFrom(u)}_runInterceptorsAndImplementation(t){return this._pipe||(this._pipe=this._interceptors.map(r=>r.interceptor).reduceRight((r,s)=>Y(r,s),(r,s)=>s(r))),this._pipe(t,r=>this._http.send(r))}},c.HTTPService=z([K(0,A)],c.HTTPService);function Y(e,n){return(t,r)=>n(t,s=>e(s,r))}const Q=200,Z=300;var F=(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))(F||{}),U=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(U||{});class N{constructor({body:n,headers:t,status:r,statusText:s}){w(this,"type",1);w(this,"body");w(this,"headers");w(this,"status");w(this,"statusText");this.body=n,this.headers=t,this.status=r,this.statusText=s}}class j{constructor(n,t,r){w(this,"type",0);this.total=n,this.loaded=t,this.partialText=r}}class x{constructor(n,t,r){this.headers=n,this.status=t,this.statusText=r}}class R{constructor({request:n,headers:t,status:r,statusText:s,error:i}){w(this,"request");w(this,"headers");w(this,"status");w(this,"statusText");w(this,"error");this.request=n,this.headers=t,this.status=r,this.statusText=s,this.error=i}}function B(e){return{method:e.method,headers:e.getHeadersInit(),body:e.getBody(),credentials:e.withCredentials?"include":void 0}}var P=Object.getOwnPropertyDescriptor,H=(e,n,t,r)=>{for(var s=r>1?void 0:r?P(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},S=(e,n)=>(t,r)=>n(t,r,e);c.FetchHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new y.Observable(t=>{const r=new AbortController;return this._send(n,t,r).catch(s=>{t.error(new R({error:s,request:n}))}),()=>r.abort()})}async _send(n,t,r){var h,d;let s;try{const p=B(n),v=n.getUrlWithParams(),m=fetch(v,{signal:r.signal,...p});this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${v} with params ${p}`),s=await m}catch(p){const v=new R({request:n,error:p,status:(h=p.status)!=null?h:0,statusText:(d=p.statusText)!=null?d:"Unknown Error",headers:p.headers});this._logService.error("[FetchHTTPImplementation]: network error",v),t.error(v);return}const i=new L(s.headers),o=s.status,l=s.statusText;let u=null;if(s.body&&(u=await this._readBody(n,s,t)),o>=F.Ok&&o<F.MultipleChoices)t.next(new N({body:u,headers:i,status:o,statusText:l}));else{const p=new R({request:n,error:u,status:o,statusText:l,headers:i});this._logService.error("[FetchHTTPImplementation]: network error",p),t.error(p)}t.complete()}async _readBody(n,t,r){var v,m;const s=[],i=t.body.getReader(),o=t.headers.get("content-length");let l=0;const u=(v=n.requestParams)==null?void 0:v.reportProgress,g=n.responseType;let h,d;for(;;){const{done:I,value:f}=await i.read();if(I)break;s.push(f),l+=f.length,u&&g==="text"&&(h=(h!=null?h:"")+(d!=null?d:d=new TextDecoder).decode(f,{stream:!0}),r.next(new j(o?Number.parseInt(o,10):void 0,l,h)))}const p=C(s,l);try{const I=(m=t.headers.get("content-type"))!=null?m:"";return ee(n,p,I)}catch(I){const f=new R({request:n,error:I,status:t.status,statusText:t.statusText,headers:new L(t.headers)});return this._logService.error("[FetchHTTPImplementation]: network error",f),r.error(f),null}}},c.FetchHTTPImplementation=H([S(0,a.ILogService)],c.FetchHTTPImplementation);function C(e,n){const t=new Uint8Array(n);let r=0;for(const s of e)t.set(s,r),r+=s.length;return t}const T=/^\)\]\}',?\n/;function ee(e,n,t){switch(e.responseType){case"json":const r=new TextDecoder().decode(n).replace(T,"");return r===""?null:JSON.parse(r);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:t});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}var te=Object.getOwnPropertyDescriptor,re=(e,n,t,r)=>{for(var s=r>1?void 0:r?te(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},ne=(e,n)=>(t,r)=>n(t,r,e);c.XHRHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new y.Observable(t=>{const r=new XMLHttpRequest,s=n.getUrlWithParams(),i=B(n);r.open(n.method,s),n.withCredentials&&(r.withCredentials=!0),i.headers&&Object.entries(i.headers).forEach(([h,d])=>r.setRequestHeader(h,d));const o=()=>{const h=r.statusText||"OK",d=new L(r.getAllResponseHeaders());return new x(d,r.status,h)},l=()=>{const{headers:h,statusText:d,status:p}=o(),{responseType:v}=n;let m=null,I=null;p!==F.NoContent&&(m=typeof r.response>"u"?r.responseText:r.response);let f=p>=Q&&p<Z;if(v==="json"&&typeof m=="string"){const b=m;try{m=m?JSON.parse(m):null}catch(E){f=!1,m=b,I=E}}if(f)t.next(new N({body:m,headers:h,status:p,statusText:d}));else{const b=new R({request:n,error:I,headers:h,status:p,statusText:d});this._logService.error("[XHRHTTPImplementation]: network error",b),t.error(b)}},u=h=>{const d=new R({request:n,error:h,status:r.status||0,statusText:r.statusText||"Unknown Error",headers:o().headers});this._logService.error("[XHRHTTPImplementation]: network error",d),t.error(d)};r.addEventListener("load",l),r.addEventListener("error",u),r.addEventListener("abort",u),r.addEventListener("timeout",u);const g=n.getBody();return r.send(g),this._logService.debug("[XHRHTTPImplementation]",`sending request to url ${s} with params ${i}`),()=>{r.readyState!==r.DONE&&r.abort(),r.removeEventListener("load",l),r.removeEventListener("error",u),r.removeEventListener("abort",u),r.removeEventListener("timeout",u)}})}},c.XHRHTTPImplementation=re([ne(0,a.ILogService)],c.XHRHTTPImplementation);var se=Object.getOwnPropertyDescriptor,ie=(e,n,t,r)=>{for(var s=r>1?void 0:r?se(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},X=(e,n)=>(t,r)=>n(t,r,e);c.UniverNetworkPlugin=(D=class extends a.Plugin{constructor(n=void 0,t,r){super(),this._config=n,this._logger=t,this._injector=r}onStarting(){var r,s,i;if(this._injector.get(c.HTTPService,a.Quantity.OPTIONAL,a.LookUp.SKIP_SELF)&&!((r=this._config)!=null&&r.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 t=(s=this._config)!=null&&s.useFetchImpl?c.FetchHTTPImplementation:typeof window<"u"?c.XHRHTTPImplementation:c.FetchHTTPImplementation;a.registerDependencies(this._injector,a.mergeOverrideWithDependencies([[c.HTTPService],[A,{useClass:t}]],(i=this._config)==null?void 0:i.override))}},w(D,"pluginName","UNIVER_NETWORK_PLUGIN"),D),c.UniverNetworkPlugin=ie([X(1,a.ILogService),X(2,a.Inject(a.Injector))],c.UniverNetworkPlugin);const oe=a.createIdentifier("univer.network.socket.service");class ce extends a.Disposable{createSocket(n){try{const t=new WebSocket(n),r=new a.DisposableCollection;return{URL:n,close:(i,o)=>{t.close(i,o),r.dispose()},send:i=>{t.send(i)},open$:new y.Observable(i=>{const o=l=>i.next(l);t.addEventListener("open",o),r.add(a.toDisposable(()=>t.removeEventListener("open",o)))}).pipe(_.share()),close$:new y.Observable(i=>{const o=l=>i.next(l);t.addEventListener("close",o),r.add(a.toDisposable(()=>t.removeEventListener("close",o)))}).pipe(_.share()),error$:new y.Observable(i=>{const o=l=>i.next(l);t.addEventListener("error",o),r.add(a.toDisposable(()=>t.removeEventListener("error",o)))}).pipe(_.share()),message$:new y.Observable(i=>{const o=l=>i.next(l);t.addEventListener("message",o),r.add(a.toDisposable(()=>t.removeEventListener("message",o)))}).pipe(_.share())}}catch(t){return console.error(t),null}}}const ae=3,le=1e3,he=e=>{var r,s;const n=(r=e==null?void 0:e.maxRetryAttempts)!=null?r:ae,t=(s=e==null?void 0:e.delayInterval)!=null?s:le;return(i,o)=>o(i).pipe(_.retry({delay:t,count:n}))},de=e=>{const n=[],t=new Set,r=()=>{var s;for(;t.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&n.length>0;){const i=n.shift();t.add(i),i()}};return(s,i)=>new y.Observable(o=>{const l=()=>i(s).subscribe({next:g=>o.next(g),error:g=>o.error(g),complete:()=>o.complete()}),u=()=>{t.delete(l),a.remove(n,l),r()};return n.push(l),r(),u})},pe=e=>{const{errorStatusCodes:n,onAuthError:t}=e;return(s,i)=>i(s).pipe(y.catchError(o=>(o instanceof R&&n.some(l=>l===o.status)&&t(),y.throwError(()=>o))))},ue=(e=300)=>{let t=()=>{};return r=>new Promise(s=>{t();const i=setTimeout(()=>{s(!0)},e);t=()=>{clearTimeout(i),s(!1)}})},ge=()=>(e,n)=>n.map(t=>({config:t,result:e})),fe=(e,n={})=>{const{isMatch:t,getParamsFromRequest:r,mergeParamsToRequest:s}=e,{fetchCheck:i=ue(300),distributeResult:o=ge()}=n,l=[],u=g=>g.map(h=>h.config);return(g,h)=>t(g)?new y.Observable(d=>{const p=r(g);l.push({next:m=>d.next(m),error:m=>d.error(m),config:p});const v=u(l);i(g).then(m=>{if(m){const I=[];v.forEach(f=>{const b=l.findIndex(E=>E.config===f);if(b>=0){const[E]=l.splice(b,1);I.push(E)}}),h(s(v,g)).subscribe({next:f=>{if(f.type===U.Response){const b=f.body,E=o(b,v);I.forEach(q=>{const G=E.find(M=>M.config===q.config);if(G){const M=new N({body:G.result,headers:f.headers,status:f.status,statusText:f.statusText});q.next(M)}else q.error("batch error")})}},complete:()=>d.complete(),error:f=>d.error(f)})}})}):h(g)};c.AuthInterceptorFactory=pe,c.HTTPEventType=U,c.HTTPHeaders=L,c.HTTPProgress=j,c.HTTPRequest=O,c.HTTPResponse=N,c.HTTPResponseError=R,c.HTTPStatusCode=F,c.IHTTPImplementation=A,c.ISocketService=oe,c.MergeInterceptorFactory=fe,c.ResponseHeader=x,c.RetryInterceptorFactory=he,c.ThresholdInterceptorFactory=de,c.WebSocketService=ce,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(c,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("rxjs"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","rxjs/operators"],a):(c=typeof globalThis<"u"?globalThis:c||self,a(c.UniverNetwork={},c.UniverCore,c.rxjs,c.rxjs.operators))})(this,function(c,a,m,_){"use strict";var me=Object.defineProperty;var ye=(c,a,m)=>a in c?me(c,a,{enumerable:!0,configurable:!0,writable:!0,value:m}):c[a]=m;var v=(c,a,m)=>ye(c,typeof a!="symbol"?a+"":a,m);var D;const k="application/json";function W(e){return Array.isArray(e)?e.some(n=>n.includes(k)):e.includes(k)}class L{constructor(n){v(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((t,r)=>n(r,t))}has(n){return!!this._headers.has(n.toLowerCase())}get(n){const t=n.toLowerCase();return this._headers.has(t)?this._headers.get(t):null}set(n,t){this._setHeader(n,t)}toHeadersInit(n){var r,s;const t={};return this._headers.forEach((i,o)=>{t[o]=i.join(",")}),(r=t.accept)!=null||(t.accept="application/json, text/plain, */*"),n instanceof FormData||(s=t["content-type"])!=null||(t["content-type"]="application/json;charset=UTF-8"),t}_setHeader(n,t){const r=n.toLowerCase();this._headers.has(r)?this._headers.get(r).push(t.toString()):this._headers.set(r,[t.toString()])}_handleHeadersString(n){n.split(`
|
|
2
|
+
`).forEach(t=>{const[r,s]=t.split(":");r&&s&&this._setHeader(r,s)})}_handleHeadersConstructorProps(n){Object.entries(n).forEach(([t,r])=>this._setHeader(t,r))}_handleHeaders(n){n.forEach((t,r)=>this._setHeader(r,t))}}const A=a.createIdentifier("network.http-implementation");class ${constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>{const t=this.params[n];return Array.isArray(t)?t.map(r=>`${n}=${r}`).join("&"):`${n}=${t}`}).join("&"):""}}let V=0;class O{constructor(n,t,r){v(this,"uid",V++);this.method=n,this.url=t,this.requestParams=r}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var t,r;const n=(r=(t=this.requestParams)==null?void 0:t.params)==null?void 0:r.toString();return n?`${this.url}${this.url.includes("?")?"&":"?"}${n}`:this.url}getBody(){var r,s;const n=(r=this.headers.get("Content-Type"))!=null?r:k,t=(s=this.requestParams)==null?void 0:s.body;return t instanceof FormData?t:W(n)&&t&&typeof t=="object"?JSON.stringify(t):t?`${t}`:null}getHeadersInit(){var t;return this.headers.toHeadersInit((t=this.requestParams)==null?void 0:t.body)}}var J=Object.getOwnPropertyDescriptor,z=(e,n,t,r)=>{for(var s=r>1?void 0:r?J(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},K=(e,n)=>(t,r)=>n(t,r,e);c.HTTPService=class extends a.Disposable{constructor(t){super();v(this,"_interceptors",[]);v(this,"_pipe");this._http=t}registerHTTPInterceptor(t){if(this._interceptors.indexOf(t)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(t),this._interceptors=this._interceptors.sort((r,s)=>{var i,o;return((i=r.priority)!=null?i:0)-((o=s.priority)!=null?o:0)}),this._pipe=null,a.toDisposable(()=>a.remove(this._interceptors,t))}get(t,r){return this._request("GET",t,r)}post(t,r){return this._request("POST",t,r)}put(t,r){return this._request("PUT",t,r)}delete(t,r){return this._request("DELETE",t,r)}patch(t,r){return this._request("PATCH",t,r)}getSSE(t,r,s){var w,d;const i=new L(s==null?void 0:s.headers),o=new $(s==null?void 0:s.params),l=new O(t,r,{headers:i,params:o,withCredentials:(w=s==null?void 0:s.withCredentials)!=null?w:!1,reportProgress:!0,responseType:(d=s==null?void 0:s.responseType)!=null?d:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body});return m.of(l).pipe(_.concatMap(f=>this._runInterceptorsAndImplementation(f)))}async _request(t,r,s){var f,p;const i=new L(s==null?void 0:s.headers),o=new $(s==null?void 0:s.params),l=new O(t,r,{headers:i,params:o,withCredentials:(f=s==null?void 0:s.withCredentials)!=null?f:!1,responseType:(p=s==null?void 0:s.responseType)!=null?p:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body}),w=m.of(l).pipe(_.concatMap(h=>this._runInterceptorsAndImplementation(h)));return await m.firstValueFrom(w)}_runInterceptorsAndImplementation(t){return this._pipe||(this._pipe=this._interceptors.map(r=>r.interceptor).reduceRight((r,s)=>Y(r,s),(r,s)=>s(r))),this._pipe(t,r=>this._http.send(r))}},c.HTTPService=z([K(0,A)],c.HTTPService);function Y(e,n){return(t,r)=>n(t,s=>e(s,r))}const Q=200,Z=300;var F=(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))(F||{}),U=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(U||{});class N{constructor({body:n,headers:t,status:r,statusText:s}){v(this,"type",1);v(this,"body");v(this,"headers");v(this,"status");v(this,"statusText");this.body=n,this.headers=t,this.status=r,this.statusText=s}}class j{constructor(n,t,r){v(this,"type",0);this.total=n,this.loaded=t,this.partialText=r}}class x{constructor(n,t,r){this.headers=n,this.status=t,this.statusText=r}}class R{constructor({request:n,headers:t,status:r,statusText:s,error:i}){v(this,"request");v(this,"headers");v(this,"status");v(this,"statusText");v(this,"error");this.request=n,this.headers=t,this.status=r,this.statusText=s,this.error=i}}function B(e){return{method:e.method,headers:e.getHeadersInit(),body:e.getBody(),credentials:e.withCredentials?"include":void 0}}var P=Object.getOwnPropertyDescriptor,H=(e,n,t,r)=>{for(var s=r>1?void 0:r?P(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},S=(e,n)=>(t,r)=>n(t,r,e);c.FetchHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new m.Observable(t=>{const r=new AbortController;return this._send(n,t,r).catch(s=>{t.error(new R({error:s,request:n}))}),()=>r.abort()})}async _send(n,t,r){var f,p;let s;try{const h=B(n),y=n.getUrlWithParams(),g=fetch(y,{signal:r.signal,...h});this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${y} with params ${h}`),s=await g}catch(h){const y=new R({request:n,error:h,status:(f=h.status)!=null?f:0,statusText:(p=h.statusText)!=null?p:"Unknown Error",headers:h.headers});this._logService.error("[FetchHTTPImplementation]: network error",y),t.error(y);return}const i=new L(s.headers),o=s.status,l=s.statusText;let w=null;if(s.body&&(w=await this._readBody(n,s,t)),o>=F.Ok&&o<F.MultipleChoices)t.next(new N({body:w,headers:i,status:o,statusText:l}));else{const h=new R({request:n,error:w,status:o,statusText:l,headers:i});this._logService.error("[FetchHTTPImplementation]: network error",h),t.error(h)}t.complete()}async _readBody(n,t,r){var y,g;const s=[],i=t.body.getReader(),o=t.headers.get("content-length");let l=0;const w=(y=n.requestParams)==null?void 0:y.reportProgress,d=n.responseType;let f,p;for(;;){const{done:b,value:u}=await i.read();if(b)break;s.push(u),l+=u.length,w&&d==="text"&&(f=(f!=null?f:"")+(p!=null?p:p=new TextDecoder).decode(u,{stream:!0}),r.next(new j(o?Number.parseInt(o,10):void 0,l,f)))}const h=C(s,l);try{const b=(g=t.headers.get("content-type"))!=null?g:"";return ee(n,h,b)}catch(b){const u=new R({request:n,error:b,status:t.status,statusText:t.statusText,headers:new L(t.headers)});return this._logService.error("[FetchHTTPImplementation]: network error",u),r.error(u),null}}},c.FetchHTTPImplementation=H([S(0,a.ILogService)],c.FetchHTTPImplementation);function C(e,n){const t=new Uint8Array(n);let r=0;for(const s of e)t.set(s,r),r+=s.length;return t}const T=/^\)\]\}',?\n/;function ee(e,n,t){switch(e.responseType){case"json":const r=new TextDecoder().decode(n).replace(T,"");return r===""?null:JSON.parse(r);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:t});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}var te=Object.getOwnPropertyDescriptor,re=(e,n,t,r)=>{for(var s=r>1?void 0:r?te(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},ne=(e,n)=>(t,r)=>n(t,r,e);c.XHRHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new m.Observable(t=>{const r=new XMLHttpRequest,s=n.getUrlWithParams(),i=B(n),{responseType:o}=n;r.open(n.method,s),n.withCredentials&&(r.withCredentials=!0),i.headers&&Object.entries(i.headers).forEach(([p,h])=>r.setRequestHeader(p,h));const l=()=>{const p=r.statusText||"OK",h=new L(r.getAllResponseHeaders());return new x(h,r.status,p)},w=()=>{const{headers:p,statusText:h,status:y}=l();let g=null,b=null;y!==F.NoContent&&(g=typeof r.response>"u"?r.responseText:r.response);let u=y>=Q&&y<Z;if(o==="json"&&typeof g=="string"){const I=g;try{g=g?JSON.parse(g):null}catch(E){u=!1,g=I,b=E}}if(o==="blob"&&!(g instanceof Blob)&&(u=!1,b=new Error("Response is not a Blob object")),u)t.next(new N({body:g,headers:p,status:y,statusText:h}));else{const I=new R({request:n,error:b,headers:p,status:y,statusText:h});this._logService.error("[XHRHTTPImplementation]: network error",I),t.error(I)}},d=p=>{const h=new R({request:n,error:p,status:r.status||0,statusText:r.statusText||"Unknown Error",headers:l().headers});this._logService.error("[XHRHTTPImplementation]: network error",h),t.error(h)};r.responseType=o||"",r.addEventListener("load",w),r.addEventListener("error",d),r.addEventListener("abort",d),r.addEventListener("timeout",d);const f=n.getBody();return r.send(f),this._logService.debug("[XHRHTTPImplementation]",`sending request to url ${s} with params ${i}`),()=>{r.readyState!==r.DONE&&r.abort(),r.removeEventListener("load",w),r.removeEventListener("error",d),r.removeEventListener("abort",d),r.removeEventListener("timeout",d)}})}},c.XHRHTTPImplementation=re([ne(0,a.ILogService)],c.XHRHTTPImplementation);var se=Object.getOwnPropertyDescriptor,ie=(e,n,t,r)=>{for(var s=r>1?void 0:r?se(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},X=(e,n)=>(t,r)=>n(t,r,e);c.UniverNetworkPlugin=(D=class extends a.Plugin{constructor(n=void 0,t,r){super(),this._config=n,this._logger=t,this._injector=r}onStarting(){var r,s,i;if(this._injector.get(c.HTTPService,a.Quantity.OPTIONAL,a.LookUp.SKIP_SELF)&&!((r=this._config)!=null&&r.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 t=(s=this._config)!=null&&s.useFetchImpl?c.FetchHTTPImplementation:typeof window<"u"?c.XHRHTTPImplementation:c.FetchHTTPImplementation;a.registerDependencies(this._injector,a.mergeOverrideWithDependencies([[c.HTTPService],[A,{useClass:t}]],(i=this._config)==null?void 0:i.override))}},v(D,"pluginName","UNIVER_NETWORK_PLUGIN"),D),c.UniverNetworkPlugin=ie([X(1,a.ILogService),X(2,a.Inject(a.Injector))],c.UniverNetworkPlugin);const oe=a.createIdentifier("univer.network.socket.service");class ce extends a.Disposable{createSocket(n){try{const t=new WebSocket(n),r=new a.DisposableCollection;return{URL:n,close:(i,o)=>{t.close(i,o),r.dispose()},send:i=>{t.send(i)},open$:new m.Observable(i=>{const o=l=>i.next(l);t.addEventListener("open",o),r.add(a.toDisposable(()=>t.removeEventListener("open",o)))}).pipe(_.share()),close$:new m.Observable(i=>{const o=l=>i.next(l);t.addEventListener("close",o),r.add(a.toDisposable(()=>t.removeEventListener("close",o)))}).pipe(_.share()),error$:new m.Observable(i=>{const o=l=>i.next(l);t.addEventListener("error",o),r.add(a.toDisposable(()=>t.removeEventListener("error",o)))}).pipe(_.share()),message$:new m.Observable(i=>{const o=l=>i.next(l);t.addEventListener("message",o),r.add(a.toDisposable(()=>t.removeEventListener("message",o)))}).pipe(_.share())}}catch(t){return console.error(t),null}}}const ae=3,le=1e3,he=e=>{var r,s;const n=(r=e==null?void 0:e.maxRetryAttempts)!=null?r:ae,t=(s=e==null?void 0:e.delayInterval)!=null?s:le;return(i,o)=>o(i).pipe(_.retry({delay:t,count:n}))},de=e=>{const n=[],t=new Set,r=()=>{var s;for(;t.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&n.length>0;){const i=n.shift();t.add(i),i()}};return(s,i)=>new m.Observable(o=>{const l=()=>i(s).subscribe({next:d=>o.next(d),error:d=>o.error(d),complete:()=>o.complete()}),w=()=>{t.delete(l),a.remove(n,l),r()};return n.push(l),r(),w})},pe=e=>{const{errorStatusCodes:n,onAuthError:t}=e;return(s,i)=>i(s).pipe(m.catchError(o=>(o instanceof R&&n.some(l=>l===o.status)&&t(),m.throwError(()=>o))))},ue=(e=300)=>{let t=()=>{};return r=>new Promise(s=>{t();const i=setTimeout(()=>{s(!0)},e);t=()=>{clearTimeout(i),s(!1)}})},fe=()=>(e,n)=>n.map(t=>({config:t,result:e})),ge=(e,n={})=>{const{isMatch:t,getParamsFromRequest:r,mergeParamsToRequest:s}=e,{fetchCheck:i=ue(300),distributeResult:o=fe()}=n,l=[],w=d=>d.map(f=>f.config);return(d,f)=>t(d)?new m.Observable(p=>{const h=r(d);l.push({next:g=>p.next(g),error:g=>p.error(g),config:h});const y=w(l);i(d).then(g=>{if(g){const b=[];y.forEach(u=>{const I=l.findIndex(E=>E.config===u);if(I>=0){const[E]=l.splice(I,1);b.push(E)}}),f(s(y,d)).subscribe({next:u=>{if(u.type===U.Response){const I=u.body,E=o(I,y);b.forEach(q=>{const G=E.find(M=>M.config===q.config);if(G){const M=new N({body:G.result,headers:u.headers,status:u.status,statusText:u.statusText});q.next(M)}else q.error("batch error")})}},complete:()=>p.complete(),error:u=>p.error(u)})}})}):f(d)};c.AuthInterceptorFactory=pe,c.HTTPEventType=U,c.HTTPHeaders=L,c.HTTPProgress=j,c.HTTPRequest=O,c.HTTPResponse=N,c.HTTPResponseError=R,c.HTTPStatusCode=F,c.IHTTPImplementation=A,c.ISocketService=oe,c.MergeInterceptorFactory=ge,c.ResponseHeader=x,c.RetryInterceptorFactory=he,c.ThresholdInterceptorFactory=de,c.WebSocketService=ce,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/network",
|
|
3
|
-
"version": "0.8.0-nightly.
|
|
3
|
+
"version": "0.8.0-nightly.202506091607",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/core": "0.8.0-nightly.
|
|
60
|
+
"@univerjs/core": "0.8.0-nightly.202506091607"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"rxjs": "^7.8.2",
|