@univerjs/network 0.2.3 → 0.2.4-alpha.0
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 +45 -46
- package/lib/types/services/http/__testing__/http-testing-utils.d.ts +1 -2
- package/lib/types/services/http/http.service.d.ts +1 -2
- package/lib/types/services/http/implementations/implementation.d.ts +1 -1
- package/lib/types/services/web-socket/web-socket.service.d.ts +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +6 -8
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`).forEach(r=>{const[n,s]=r.split(":");n&&s&&this._setHeader(n,s)})}_handleHeadersConstructorProps(t){Object.entries(t).forEach(([r,n])=>this._setHeader(r,n))}_handleHeaders(t){t.forEach((r,n)=>this._setHeader(n,r))}}const M=O.createIdentifier("network.http-implementation");class D{constructor(t){this.params=t}toString(){return this.params?Object.keys(this.params).map(t=>`${t}=${this.params[t]}`).join("&"):""}}let V=0;class q{constructor(t,r,n){y(this,"uid",V++);this.method=t,this.url=r,this.requestParams=n}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var r,n;const t=(n=(r=this.requestParams)==null?void 0:r.params)==null?void 0:n.toString();return t?`${this.url}${this.url.includes("?")?"&":"?"}${t}`:this.url}getBody(){var n,s;const t=(n=this.headers.get("Content-Type"))!=null?n:U,r=(s=this.requestParams)==null?void 0:s.body;return t===U&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}var W=Object.defineProperty,X=Object.getOwnPropertyDescriptor,z=(e,t,r,n)=>{for(var s=n>1?void 0:n?X(t,r):t,c=e.length-1,o;c>=0;c--)(o=e[c])&&(s=(n?o(t,r,s):o(s))||s);return n&&s&&W(t,r,s),s},J=(e,t)=>(r,n)=>t(r,n,e);exports.HTTPService=class extends b.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((n,s)=>{var c,o;return((c=n.priority)!=null?c:0)-((o=s.priority)!=null?o:0)}),this._pipe=null,b.toDisposable(()=>b.remove(this._interceptors,r))}get(r,n){return this._request("GET",r,n)}post(r,n){return this._request("POST",r,n)}put(r,n){return this._request("PUT",r,n)}delete(r,n){return this._request("DELETE",r,n)}patch(r,n){return this._request("PATCH",r,n)}getSSE(r,n,s){var h,a;const c=new E(s==null?void 0:s.headers),o=new D(s==null?void 0:s.params),i=new q(r,n,{headers:c,params:o,withCredentials:(h=s==null?void 0:s.withCredentials)!=null?h:!1,reportProgress:!0,responseType:(a=s==null?void 0:s.responseType)!=null?a:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body});return m.of(i).pipe(v.concatMap(l=>this._runInterceptorsAndImplementation(l)))}async _request(r,n,s){var l,p;const c=new E(s==null?void 0:s.headers),o=new D(s==null?void 0:s.params),i=new q(r,n,{headers:c,params:o,withCredentials:(l=s==null?void 0:s.withCredentials)!=null?l:!1,responseType:(p=s==null?void 0:s.responseType)!=null?p:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),h=m.of(i).pipe(v.concatMap(d=>this._runInterceptorsAndImplementation(d)));return await m.firstValueFrom(h)}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(n=>n.interceptor).reduceRight((n,s)=>Y(n,s),(n,s)=>s(n))),this._pipe(r,n=>this._http.send(n))}};exports.HTTPService=z([J(0,M)],exports.HTTPService);function Y(e,t){return(r,n)=>t(r,s=>e(s,n))}var N=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(N||{});class L{constructor({body:t,headers:r,status:n,statusText:s}){y(this,"type",1);y(this,"body");y(this,"headers");y(this,"status");y(this,"statusText");this.body=t,this.headers=r,this.status=n,this.statusText=s}}class j{constructor(t,r,n){y(this,"type",0);this.total=t,this.loaded=r,this.partialText=n}}class B{constructor(t,r,n){this.headers=t,this.status=r,this.statusText=n}}class R{constructor({headers:t,status:r,statusText:n,error:s}){y(this,"headers");y(this,"status");y(this,"statusText");y(this,"error");this.headers=t,this.status=r,this.statusText=n,this.error=s}}const K=200,Q=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||{});class Z{send(t){return new m.Observable(r=>{const n=new AbortController;return this._send(t,r,n).then(()=>{},s=>{r.error(new R({error:s}))}),()=>n.abort()})}async _send(t,r,n){var l,p;let s;try{const d=this._parseFetchParamsFromRequest(t);s=await fetch(t.getUrlWithParams(),{signal:n.signal,...d})}catch(d){r.error(new R({error:d,status:(l=d.status)!=null?l:0,statusText:(p=d.statusText)!=null?p:"Unknown Error",headers:d.headers}));return}const c=new E(s.headers),o=s.status,i=s.statusText;let h=null;s.body&&(h=await this._readBody(t,s,r)),o>=x.Ok&&o<x.MultipleChoices?r.next(new L({body:h,headers:c,status:o,statusText:i})):r.error(new R({error:h,status:o,statusText:i,headers:c})),r.complete()}async _readBody(t,r,n){var w,f;const s=[],c=r.body.getReader(),o=r.headers.get("content-length");let i=0;const h=(w=t.requestParams)==null?void 0:w.reportProgress,a=t.responseType;let l,p;for(;;){const{done:g,value:u}=await c.read();if(g)break;s.push(u),i+=u.length,h&&a==="text"&&(l=(l!=null?l:"")+(p!=null?p:p=new TextDecoder).decode(u,{stream:!0}),n.next(new j(o?Number.parseInt(o,10):void 0,i,l)))}const d=P(s,i);try{const g=(f=r.headers.get("content-type"))!=null?f:"";return S(t,d,g)}catch(g){return n.error(new R({error:g,status:r.status,statusText:r.statusText,headers:new E(r.headers)})),null}}_parseFetchParamsFromRequest(t){return{method:t.method,headers:t.getHeadersInit(),body:t.getBody(),credentials:t.withCredentials?"include":void 0}}}function P(e,t){const r=new Uint8Array(t);let n=0;for(const s of e)r.set(s,n),n+=s.length;return r}const H=/^\)\]\}',?\n/;function S(e,t,r){switch(e.responseType){case"json":const n=new TextDecoder().decode(t).replace(H,"");return n===""?null:JSON.parse(n);case"text":return new TextDecoder().decode(t);case"blob":return new Blob([t],{type:r});case"arraybuffer":return t.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class C{send(t){return new m.Observable(r=>{const n=new XMLHttpRequest;n.open(t.method,t.getUrlWithParams()),t.withCredentials&&(n.withCredentials=!0),t.headers.forEach((h,a)=>n.setRequestHeader(h,a.join(","))),t.headers.has("Accept")||n.setRequestHeader("Accept","application/json, text/plain, */*"),t.headers.has("Content-Type")||n.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const h=n.statusText||"OK",a=new E(n.getAllResponseHeaders());return new B(a,n.status,h)},c=()=>{const{headers:h,statusText:a,status:l}=s(),{responseType:p}=t;let d=null,w=null;l!==x.NoContent&&(d=typeof n.response>"u"?n.responseText:n.response);let f=l>=K&&l<Q;if(p==="json"&&typeof d=="string"){const g=d;try{d=d?JSON.parse(d):null}catch(u){f=!1,d=g,w=u}}f?r.next(new L({body:d,headers:h,status:l,statusText:a})):r.error(new R({error:w,headers:h,status:l,statusText:a}))},o=h=>{const a=new R({error:h,status:n.status||0,statusText:n.statusText||"Unknown Error",headers:s().headers});r.error(a)};n.addEventListener("load",c),n.addEventListener("error",o),n.addEventListener("abort",o),n.addEventListener("timeout",o);const i=t.getBody();return n.send(i),()=>{n.readyState!==n.DONE&&n.abort(),n.removeEventListener("load",c),n.removeEventListener("error",o),n.removeEventListener("abort",o),n.removeEventListener("timeout",o)}})}}const T=O.createIdentifier("univer.socket");class ee extends b.Disposable{createSocket(t){try{const r=new WebSocket(t),n=new b.DisposableCollection;return{URL:t,close:(c,o)=>{r.close(c,o),n.dispose()},send:c=>{r.send(c)},open$:new m.Observable(c=>{const o=i=>c.next(i);r.addEventListener("open",o),n.add(b.toDisposable(()=>r.removeEventListener("open",o)))}).pipe(v.share()),close$:new m.Observable(c=>{const o=i=>c.next(i);r.addEventListener("close",o),n.add(b.toDisposable(()=>r.removeEventListener("close",o)))}).pipe(v.share()),error$:new m.Observable(c=>{const o=i=>c.next(i);r.addEventListener("error",o),n.add(b.toDisposable(()=>r.removeEventListener("error",o)))}).pipe(v.share()),message$:new m.Observable(c=>{const o=i=>c.next(i);r.addEventListener("message",o),n.add(b.toDisposable(()=>r.removeEventListener("message",o)))}).pipe(v.share())}}catch(r){return console.error(r),null}}}const re=3,te=1e3,ne=(e,t)=>{var s,c;const r=(s=t==null?void 0:t.maxRetryAttempts)!=null?s:re,n=(c=t==null?void 0:t.delayInterval)!=null?c:te;return(o,i)=>i(o).pipe(v.retry({delay:n,count:r}))},se=e=>{const t=[],r=new Set,n=()=>{var s;for(;r.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&t.length>0;){const c=t.shift();r.add(c),c()}};return(s,c)=>new m.Observable(o=>{const i=()=>c(s).subscribe({next:a=>o.next(a),error:a=>o.next(a),complete:()=>o.complete()}),h=()=>{r.delete(i),b.remove(t,i),n()};return t.push(i),n(),h})},oe=e=>{const{errorStatusCodes:t,onAuthError:r}=e;return(s,c)=>c(s).pipe(m.catchError(o=>(o instanceof R&&t.some(i=>i===o.status)&&r(),m.throwError(()=>o))))},ce=(e=300)=>{let r=()=>{};return n=>new Promise(s=>{r();const c=setTimeout(()=>{s(!0)},e);r=()=>{clearTimeout(c),s(!1)}})},ie=()=>(e,t)=>t.map(r=>({config:r,result:e})),ae=(e,t={})=>{const{isMatch:r,getParamsFromRequest:n,mergeParamsToRequest:s}=e,{fetchCheck:c=ce(300),distributeResult:o=ie()}=t,i=[],h=a=>a.map(l=>l.config);return(a,l)=>r(a)?new m.Observable(p=>{const d=n(a);i.push({next:f=>p.next(f),error:f=>p.error(f),config:d});const w=h(i);c(a).then(f=>{if(f){const g=[];w.forEach(u=>{const I=i.findIndex(_=>_.config===u);if(I>=0){const[_]=i.splice(I,1);g.push(_)}}),l(s(w,a)).subscribe({next:u=>{if(u.type===N.Response){const I=u.body,_=o(I,w);g.forEach(F=>{const k=_.find(A=>A.config===F.config);if(k){const A=new L({body:k.result,headers:u.headers,status:u.status,statusText:u.statusText});F.next(A)}else F.error("batch error")})}},complete:()=>p.complete(),error:u=>p.error(u)})}})}):l(a)};exports.AuthInterceptorFactory=oe;exports.FetchHTTPImplementation=Z;exports.HTTPEventType=N;exports.HTTPHeaders=E;exports.HTTPProgress=j;exports.HTTPRequest=q;exports.HTTPResponse=L;exports.HTTPResponseError=R;exports.HTTPStatusCode=x;exports.IHTTPImplementation=M;exports.ISocketService=T;exports.MergeInterceptorFactory=ae;exports.ResponseHeader=B;exports.RetryInterceptorFactory=ne;exports.ThresholdInterceptorFactory=se;exports.WebSocketService=ee;exports.XHRHTTPImplementation=C;
|
|
1
|
+
"use strict";var B=Object.defineProperty;var $=(e,t,r)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var y=(e,t,r)=>$(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@univerjs/core"),m=require("rxjs"),v=require("rxjs/operators"),U="application/json";class E{constructor(t){y(this,"_headers",new Map);typeof t=="string"?this._handleHeadersString(t):t instanceof Headers?this._handleHeaders(t):t&&this._handleHeadersConstructorProps(t)}forEach(t){this._headers.forEach((r,n)=>t(n,r))}has(t){return!!this._headers.has(t.toLowerCase())}get(t){const r=t.toLowerCase();return this._headers.has(r)?this._headers.get(r):null}toHeadersInit(){var r,n;const t={};return this._headers.forEach((s,c)=>{t[c]=s.join(",")}),(r=t.accept)!=null||(t.accept="application/json, text/plain, */*"),(n=t["content-type"])!=null||(t["content-type"]="application/json;charset=UTF-8"),t}_setHeader(t,r){const n=t.toLowerCase();this._headers.has(n)?this._headers.get(n).push(r.toString()):this._headers.set(n,[r.toString()])}_handleHeadersString(t){t.split(`
|
|
2
|
+
`).forEach(r=>{const[n,s]=r.split(":");n&&s&&this._setHeader(n,s)})}_handleHeadersConstructorProps(t){Object.entries(t).forEach(([r,n])=>this._setHeader(r,n))}_handleHeaders(t){t.forEach((r,n)=>this._setHeader(n,r))}}const O=f.createIdentifier("network.http-implementation");class D{constructor(t){this.params=t}toString(){return this.params?Object.keys(this.params).map(t=>`${t}=${this.params[t]}`).join("&"):""}}let G=0;class q{constructor(t,r,n){y(this,"uid",G++);this.method=t,this.url=r,this.requestParams=n}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var r,n;const t=(n=(r=this.requestParams)==null?void 0:r.params)==null?void 0:n.toString();return t?`${this.url}${this.url.includes("?")?"&":"?"}${t}`:this.url}getBody(){var n,s;const t=(n=this.headers.get("Content-Type"))!=null?n:U,r=(s=this.requestParams)==null?void 0:s.body;return t===U&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,X=(e,t,r,n)=>{for(var s=n>1?void 0:n?W(t,r):t,c=e.length-1,o;c>=0;c--)(o=e[c])&&(s=(n?o(t,r,s):o(s))||s);return n&&s&&V(t,r,s),s},z=(e,t)=>(r,n)=>t(r,n,e);exports.HTTPService=class extends f.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((n,s)=>{var c,o;return((c=n.priority)!=null?c:0)-((o=s.priority)!=null?o:0)}),this._pipe=null,f.toDisposable(()=>f.remove(this._interceptors,r))}get(r,n){return this._request("GET",r,n)}post(r,n){return this._request("POST",r,n)}put(r,n){return this._request("PUT",r,n)}delete(r,n){return this._request("DELETE",r,n)}patch(r,n){return this._request("PATCH",r,n)}getSSE(r,n,s){var h,a;const c=new E(s==null?void 0:s.headers),o=new D(s==null?void 0:s.params),i=new q(r,n,{headers:c,params:o,withCredentials:(h=s==null?void 0:s.withCredentials)!=null?h:!1,reportProgress:!0,responseType:(a=s==null?void 0:s.responseType)!=null?a:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body});return m.of(i).pipe(v.concatMap(l=>this._runInterceptorsAndImplementation(l)))}async _request(r,n,s){var l,d;const c=new E(s==null?void 0:s.headers),o=new D(s==null?void 0:s.params),i=new q(r,n,{headers:c,params:o,withCredentials:(l=s==null?void 0:s.withCredentials)!=null?l:!1,responseType:(d=s==null?void 0:s.responseType)!=null?d:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),h=m.of(i).pipe(v.concatMap(p=>this._runInterceptorsAndImplementation(p)));return await m.firstValueFrom(h)}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(n=>n.interceptor).reduceRight((n,s)=>J(n,s),(n,s)=>s(n))),this._pipe(r,n=>this._http.send(n))}};exports.HTTPService=X([z(0,O)],exports.HTTPService);function J(e,t){return(r,n)=>t(r,s=>e(s,n))}var N=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(N||{});class L{constructor({body:t,headers:r,status:n,statusText:s}){y(this,"type",1);y(this,"body");y(this,"headers");y(this,"status");y(this,"statusText");this.body=t,this.headers=r,this.status=n,this.statusText=s}}class M{constructor(t,r,n){y(this,"type",0);this.total=t,this.loaded=r,this.partialText=n}}class j{constructor(t,r,n){this.headers=t,this.status=r,this.statusText=n}}class R{constructor({headers:t,status:r,statusText:n,error:s}){y(this,"headers");y(this,"status");y(this,"statusText");y(this,"error");this.headers=t,this.status=r,this.statusText=n,this.error=s}}const Y=200,K=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||{});class Q{send(t){return new m.Observable(r=>{const n=new AbortController;return this._send(t,r,n).then(()=>{},s=>{r.error(new R({error:s}))}),()=>n.abort()})}async _send(t,r,n){var l,d;let s;try{const p=this._parseFetchParamsFromRequest(t);s=await fetch(t.getUrlWithParams(),{signal:n.signal,...p})}catch(p){r.error(new R({error:p,status:(l=p.status)!=null?l:0,statusText:(d=p.statusText)!=null?d:"Unknown Error",headers:p.headers}));return}const c=new E(s.headers),o=s.status,i=s.statusText;let h=null;s.body&&(h=await this._readBody(t,s,r)),o>=x.Ok&&o<x.MultipleChoices?r.next(new L({body:h,headers:c,status:o,statusText:i})):r.error(new R({error:h,status:o,statusText:i,headers:c})),r.complete()}async _readBody(t,r,n){var g,w;const s=[],c=r.body.getReader(),o=r.headers.get("content-length");let i=0;const h=(g=t.requestParams)==null?void 0:g.reportProgress,a=t.responseType;let l,d;for(;;){const{done:b,value:u}=await c.read();if(b)break;s.push(u),i+=u.length,h&&a==="text"&&(l=(l!=null?l:"")+(d!=null?d:d=new TextDecoder).decode(u,{stream:!0}),n.next(new M(o?Number.parseInt(o,10):void 0,i,l)))}const p=Z(s,i);try{const b=(w=r.headers.get("content-type"))!=null?w:"";return H(t,p,b)}catch(b){return n.error(new R({error:b,status:r.status,statusText:r.statusText,headers:new E(r.headers)})),null}}_parseFetchParamsFromRequest(t){return{method:t.method,headers:t.getHeadersInit(),body:t.getBody(),credentials:t.withCredentials?"include":void 0}}}function Z(e,t){const r=new Uint8Array(t);let n=0;for(const s of e)r.set(s,n),n+=s.length;return r}const P=/^\)\]\}',?\n/;function H(e,t,r){switch(e.responseType){case"json":const n=new TextDecoder().decode(t).replace(P,"");return n===""?null:JSON.parse(n);case"text":return new TextDecoder().decode(t);case"blob":return new Blob([t],{type:r});case"arraybuffer":return t.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class S{send(t){return new m.Observable(r=>{const n=new XMLHttpRequest;n.open(t.method,t.getUrlWithParams()),t.withCredentials&&(n.withCredentials=!0),t.headers.forEach((h,a)=>n.setRequestHeader(h,a.join(","))),t.headers.has("Accept")||n.setRequestHeader("Accept","application/json, text/plain, */*"),t.headers.has("Content-Type")||n.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const h=n.statusText||"OK",a=new E(n.getAllResponseHeaders());return new j(a,n.status,h)},c=()=>{const{headers:h,statusText:a,status:l}=s(),{responseType:d}=t;let p=null,g=null;l!==x.NoContent&&(p=typeof n.response>"u"?n.responseText:n.response);let w=l>=Y&&l<K;if(d==="json"&&typeof p=="string"){const b=p;try{p=p?JSON.parse(p):null}catch(u){w=!1,p=b,g=u}}w?r.next(new L({body:p,headers:h,status:l,statusText:a})):r.error(new R({error:g,headers:h,status:l,statusText:a}))},o=h=>{const a=new R({error:h,status:n.status||0,statusText:n.statusText||"Unknown Error",headers:s().headers});r.error(a)};n.addEventListener("load",c),n.addEventListener("error",o),n.addEventListener("abort",o),n.addEventListener("timeout",o);const i=t.getBody();return n.send(i),()=>{n.readyState!==n.DONE&&n.abort(),n.removeEventListener("load",c),n.removeEventListener("error",o),n.removeEventListener("abort",o),n.removeEventListener("timeout",o)}})}}const C=f.createIdentifier("univer.socket");class T extends f.Disposable{createSocket(t){try{const r=new WebSocket(t),n=new f.DisposableCollection;return{URL:t,close:(c,o)=>{r.close(c,o),n.dispose()},send:c=>{r.send(c)},open$:new m.Observable(c=>{const o=i=>c.next(i);r.addEventListener("open",o),n.add(f.toDisposable(()=>r.removeEventListener("open",o)))}).pipe(v.share()),close$:new m.Observable(c=>{const o=i=>c.next(i);r.addEventListener("close",o),n.add(f.toDisposable(()=>r.removeEventListener("close",o)))}).pipe(v.share()),error$:new m.Observable(c=>{const o=i=>c.next(i);r.addEventListener("error",o),n.add(f.toDisposable(()=>r.removeEventListener("error",o)))}).pipe(v.share()),message$:new m.Observable(c=>{const o=i=>c.next(i);r.addEventListener("message",o),n.add(f.toDisposable(()=>r.removeEventListener("message",o)))}).pipe(v.share())}}catch(r){return console.error(r),null}}}const ee=3,re=1e3,te=(e,t)=>{var s,c;const r=(s=t==null?void 0:t.maxRetryAttempts)!=null?s:ee,n=(c=t==null?void 0:t.delayInterval)!=null?c:re;return(o,i)=>i(o).pipe(v.retry({delay:n,count:r}))},ne=e=>{const t=[],r=new Set,n=()=>{var s;for(;r.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&t.length>0;){const c=t.shift();r.add(c),c()}};return(s,c)=>new m.Observable(o=>{const i=()=>c(s).subscribe({next:a=>o.next(a),error:a=>o.next(a),complete:()=>o.complete()}),h=()=>{r.delete(i),f.remove(t,i),n()};return t.push(i),n(),h})},se=e=>{const{errorStatusCodes:t,onAuthError:r}=e;return(s,c)=>c(s).pipe(m.catchError(o=>(o instanceof R&&t.some(i=>i===o.status)&&r(),m.throwError(()=>o))))},oe=(e=300)=>{let r=()=>{};return n=>new Promise(s=>{r();const c=setTimeout(()=>{s(!0)},e);r=()=>{clearTimeout(c),s(!1)}})},ce=()=>(e,t)=>t.map(r=>({config:r,result:e})),ie=(e,t={})=>{const{isMatch:r,getParamsFromRequest:n,mergeParamsToRequest:s}=e,{fetchCheck:c=oe(300),distributeResult:o=ce()}=t,i=[],h=a=>a.map(l=>l.config);return(a,l)=>r(a)?new m.Observable(d=>{const p=n(a);i.push({next:w=>d.next(w),error:w=>d.error(w),config:p});const g=h(i);c(a).then(w=>{if(w){const b=[];g.forEach(u=>{const I=i.findIndex(_=>_.config===u);if(I>=0){const[_]=i.splice(I,1);b.push(_)}}),l(s(g,a)).subscribe({next:u=>{if(u.type===N.Response){const I=u.body,_=o(I,g);b.forEach(F=>{const k=_.find(A=>A.config===F.config);if(k){const A=new L({body:k.result,headers:u.headers,status:u.status,statusText:u.statusText});F.next(A)}else F.error("batch error")})}},complete:()=>d.complete(),error:u=>d.error(u)})}})}):l(a)};exports.AuthInterceptorFactory=se;exports.FetchHTTPImplementation=Q;exports.HTTPEventType=N;exports.HTTPHeaders=E;exports.HTTPProgress=M;exports.HTTPRequest=q;exports.HTTPResponse=L;exports.HTTPResponseError=R;exports.HTTPStatusCode=x;exports.IHTTPImplementation=O;exports.ISocketService=C;exports.MergeInterceptorFactory=ie;exports.ResponseHeader=j;exports.RetryInterceptorFactory=te;exports.ThresholdInterceptorFactory=ne;exports.WebSocketService=T;exports.XHRHTTPImplementation=S;
|
package/lib/es/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
var V = Object.defineProperty;
|
|
2
2
|
var W = (e, r, n) => r in e ? V(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n;
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
3
|
+
var y = (e, r, n) => W(e, typeof r != "symbol" ? r + "" : r, n);
|
|
4
|
+
import { createIdentifier as j, Disposable as B, toDisposable as _, remove as $, DisposableCollection as X } from "@univerjs/core";
|
|
5
5
|
import { of as U, firstValueFrom as z, Observable as g, catchError as J, throwError as Y } from "rxjs";
|
|
6
6
|
import { concatMap as k, share as v, retry as K } from "rxjs/operators";
|
|
7
|
-
import { createIdentifier as $ } from "@wendellhu/redi";
|
|
8
7
|
const q = "application/json";
|
|
9
8
|
class x {
|
|
10
9
|
constructor(r) {
|
|
11
|
-
|
|
10
|
+
y(this, "_headers", /* @__PURE__ */ new Map());
|
|
12
11
|
typeof r == "string" ? this._handleHeadersString(r) : r instanceof Headers ? this._handleHeaders(r) : r && this._handleHeadersConstructorProps(r);
|
|
13
12
|
}
|
|
14
13
|
forEach(r) {
|
|
@@ -46,7 +45,7 @@ class x {
|
|
|
46
45
|
r.forEach((n, t) => this._setHeader(t, n));
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
const Q =
|
|
48
|
+
const Q = j("network.http-implementation");
|
|
50
49
|
class M {
|
|
51
50
|
constructor(r) {
|
|
52
51
|
this.params = r;
|
|
@@ -58,7 +57,7 @@ class M {
|
|
|
58
57
|
let Z = 0;
|
|
59
58
|
class D {
|
|
60
59
|
constructor(r, n, t) {
|
|
61
|
-
|
|
60
|
+
y(this, "uid", Z++);
|
|
62
61
|
this.method = r, this.url = n, this.requestParams = t;
|
|
63
62
|
}
|
|
64
63
|
get headers() {
|
|
@@ -89,12 +88,12 @@ var P = Object.defineProperty, S = Object.getOwnPropertyDescriptor, H = (e, r, n
|
|
|
89
88
|
(o = e[i]) && (s = (t ? o(r, n, s) : o(s)) || s);
|
|
90
89
|
return t && s && P(r, n, s), s;
|
|
91
90
|
}, C = (e, r) => (n, t) => r(n, t, e);
|
|
92
|
-
let O = class extends
|
|
91
|
+
let O = class extends B {
|
|
93
92
|
constructor(r) {
|
|
94
93
|
super();
|
|
95
|
-
|
|
94
|
+
y(this, "_interceptors", []);
|
|
96
95
|
// eslint-disable-next-line ts/no-explicit-any
|
|
97
|
-
|
|
96
|
+
y(this, "_pipe");
|
|
98
97
|
this._http = r;
|
|
99
98
|
}
|
|
100
99
|
/**
|
|
@@ -109,7 +108,7 @@ let O = class extends j {
|
|
|
109
108
|
return this._interceptors.push(r), this._interceptors = this._interceptors.sort((n, t) => {
|
|
110
109
|
var s, i;
|
|
111
110
|
return ((s = n.priority) != null ? s : 0) - ((i = t.priority) != null ? i : 0);
|
|
112
|
-
}), this._pipe = null, _(() =>
|
|
111
|
+
}), this._pipe = null, _(() => $(this._interceptors, r));
|
|
113
112
|
}
|
|
114
113
|
get(r, n) {
|
|
115
114
|
return this._request("GET", r, n);
|
|
@@ -179,17 +178,17 @@ class F {
|
|
|
179
178
|
status: t,
|
|
180
179
|
statusText: s
|
|
181
180
|
}) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
181
|
+
y(this, "type", 1);
|
|
182
|
+
y(this, "body");
|
|
183
|
+
y(this, "headers");
|
|
184
|
+
y(this, "status");
|
|
185
|
+
y(this, "statusText");
|
|
187
186
|
this.body = r, this.headers = n, this.status = t, this.statusText = s;
|
|
188
187
|
}
|
|
189
188
|
}
|
|
190
189
|
class ee {
|
|
191
190
|
constructor(r, n, t) {
|
|
192
|
-
|
|
191
|
+
y(this, "type", 0);
|
|
193
192
|
this.total = r, this.loaded = n, this.partialText = t;
|
|
194
193
|
}
|
|
195
194
|
}
|
|
@@ -205,16 +204,16 @@ class E {
|
|
|
205
204
|
statusText: t,
|
|
206
205
|
error: s
|
|
207
206
|
}) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
207
|
+
y(this, "headers");
|
|
208
|
+
y(this, "status");
|
|
209
|
+
y(this, "statusText");
|
|
210
|
+
y(this, "error");
|
|
212
211
|
this.headers = r, this.status = n, this.statusText = t, this.error = s;
|
|
213
212
|
}
|
|
214
213
|
}
|
|
215
214
|
const te = 200, ne = 300;
|
|
216
215
|
var L = /* @__PURE__ */ ((e) => (e[e.Continue = 100] = "Continue", e[e.SwitchingProtocols = 101] = "SwitchingProtocols", e[e.Processing = 102] = "Processing", e[e.EarlyHints = 103] = "EarlyHints", e[e.Ok = 200] = "Ok", e[e.Created = 201] = "Created", e[e.Accepted = 202] = "Accepted", e[e.NonAuthoritativeInformation = 203] = "NonAuthoritativeInformation", e[e.NoContent = 204] = "NoContent", e[e.ResetContent = 205] = "ResetContent", e[e.PartialContent = 206] = "PartialContent", e[e.MultiStatus = 207] = "MultiStatus", e[e.AlreadyReported = 208] = "AlreadyReported", e[e.ImUsed = 226] = "ImUsed", e[e.MultipleChoices = 300] = "MultipleChoices", e[e.MovedPermanently = 301] = "MovedPermanently", e[e.Found = 302] = "Found", e[e.SeeOther = 303] = "SeeOther", e[e.NotModified = 304] = "NotModified", e[e.UseProxy = 305] = "UseProxy", e[e.Unused = 306] = "Unused", e[e.TemporaryRedirect = 307] = "TemporaryRedirect", e[e.PermanentRedirect = 308] = "PermanentRedirect", e[e.BadRequest = 400] = "BadRequest", e[e.Unauthorized = 401] = "Unauthorized", e[e.PaymentRequired = 402] = "PaymentRequired", e[e.Forbidden = 403] = "Forbidden", e[e.NotFound = 404] = "NotFound", e[e.MethodNotAllowed = 405] = "MethodNotAllowed", e[e.NotAcceptable = 406] = "NotAcceptable", e[e.ProxyAuthenticationRequired = 407] = "ProxyAuthenticationRequired", e[e.RequestTimeout = 408] = "RequestTimeout", e[e.Conflict = 409] = "Conflict", e[e.Gone = 410] = "Gone", e[e.LengthRequired = 411] = "LengthRequired", e[e.PreconditionFailed = 412] = "PreconditionFailed", e[e.PayloadTooLarge = 413] = "PayloadTooLarge", e[e.UriTooLong = 414] = "UriTooLong", e[e.UnsupportedMediaType = 415] = "UnsupportedMediaType", e[e.RangeNotSatisfiable = 416] = "RangeNotSatisfiable", e[e.ExpectationFailed = 417] = "ExpectationFailed", e[e.ImATeapot = 418] = "ImATeapot", e[e.MisdirectedRequest = 421] = "MisdirectedRequest", e[e.UnprocessableEntity = 422] = "UnprocessableEntity", e[e.Locked = 423] = "Locked", e[e.FailedDependency = 424] = "FailedDependency", e[e.TooEarly = 425] = "TooEarly", e[e.UpgradeRequired = 426] = "UpgradeRequired", e[e.PreconditionRequired = 428] = "PreconditionRequired", e[e.TooManyRequests = 429] = "TooManyRequests", e[e.RequestHeaderFieldsTooLarge = 431] = "RequestHeaderFieldsTooLarge", e[e.UnavailableForLegalReasons = 451] = "UnavailableForLegalReasons", e[e.InternalServerError = 500] = "InternalServerError", e[e.NotImplemented = 501] = "NotImplemented", e[e.BadGateway = 502] = "BadGateway", e[e.ServiceUnavailable = 503] = "ServiceUnavailable", e[e.GatewayTimeout = 504] = "GatewayTimeout", e[e.HttpVersionNotSupported = 505] = "HttpVersionNotSupported", e[e.VariantAlsoNegotiates = 506] = "VariantAlsoNegotiates", e[e.InsufficientStorage = 507] = "InsufficientStorage", e[e.LoopDetected = 508] = "LoopDetected", e[e.NotExtended = 510] = "NotExtended", e[e.NetworkAuthenticationRequired = 511] = "NetworkAuthenticationRequired", e))(L || {});
|
|
217
|
-
class
|
|
216
|
+
class me {
|
|
218
217
|
send(r) {
|
|
219
218
|
return new g((n) => {
|
|
220
219
|
const t = new AbortController();
|
|
@@ -259,7 +258,7 @@ class fe {
|
|
|
259
258
|
})), n.complete();
|
|
260
259
|
}
|
|
261
260
|
async _readBody(r, n, t) {
|
|
262
|
-
var f,
|
|
261
|
+
var f, m;
|
|
263
262
|
const s = [], i = n.body.getReader(), o = n.headers.get("content-length");
|
|
264
263
|
let c = 0;
|
|
265
264
|
const l = (f = r.requestParams) == null ? void 0 : f.reportProgress, a = r.responseType;
|
|
@@ -275,7 +274,7 @@ class fe {
|
|
|
275
274
|
}
|
|
276
275
|
const d = se(s, c);
|
|
277
276
|
try {
|
|
278
|
-
const w = (
|
|
277
|
+
const w = (m = n.headers.get("content-type")) != null ? m : "";
|
|
279
278
|
return ie(r, d, w);
|
|
280
279
|
} catch (w) {
|
|
281
280
|
return t.error(new E({
|
|
@@ -318,7 +317,7 @@ function ie(e, r, n) {
|
|
|
318
317
|
throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`);
|
|
319
318
|
}
|
|
320
319
|
}
|
|
321
|
-
class
|
|
320
|
+
class fe {
|
|
322
321
|
send(r) {
|
|
323
322
|
return new g((n) => {
|
|
324
323
|
const t = new XMLHttpRequest();
|
|
@@ -330,16 +329,16 @@ class we {
|
|
|
330
329
|
const { headers: l, statusText: a, status: h } = s(), { responseType: u } = r;
|
|
331
330
|
let d = null, f = null;
|
|
332
331
|
h !== L.NoContent && (d = typeof t.response > "u" ? t.responseText : t.response);
|
|
333
|
-
let
|
|
332
|
+
let m = h >= te && h < ne;
|
|
334
333
|
if (u === "json" && typeof d == "string") {
|
|
335
334
|
const w = d;
|
|
336
335
|
try {
|
|
337
336
|
d = d ? JSON.parse(d) : null;
|
|
338
337
|
} catch (p) {
|
|
339
|
-
|
|
338
|
+
m = !1, d = w, f = p;
|
|
340
339
|
}
|
|
341
340
|
}
|
|
342
|
-
|
|
341
|
+
m ? n.next(
|
|
343
342
|
new F({
|
|
344
343
|
body: d,
|
|
345
344
|
headers: l,
|
|
@@ -371,8 +370,8 @@ class we {
|
|
|
371
370
|
});
|
|
372
371
|
}
|
|
373
372
|
}
|
|
374
|
-
const
|
|
375
|
-
class
|
|
373
|
+
const we = j("univer.socket");
|
|
374
|
+
class ge extends B {
|
|
376
375
|
createSocket(r) {
|
|
377
376
|
try {
|
|
378
377
|
const n = new WebSocket(r), t = new X();
|
|
@@ -406,11 +405,11 @@ class Ee extends j {
|
|
|
406
405
|
}
|
|
407
406
|
}
|
|
408
407
|
}
|
|
409
|
-
const ce = 3, ae = 1e3,
|
|
408
|
+
const ce = 3, ae = 1e3, Ee = (e, r) => {
|
|
410
409
|
var s, i;
|
|
411
410
|
const n = (s = r == null ? void 0 : r.maxRetryAttempts) != null ? s : ce, t = (i = r == null ? void 0 : r.delayInterval) != null ? i : ae;
|
|
412
411
|
return (o, c) => c(o).pipe(K({ delay: t, count: n }));
|
|
413
|
-
},
|
|
412
|
+
}, Re = (e) => {
|
|
414
413
|
const r = [], n = /* @__PURE__ */ new Set(), t = () => {
|
|
415
414
|
var s;
|
|
416
415
|
for (; n.size < ((s = e == null ? void 0 : e.maxParallel) != null ? s : 1) && r.length > 0; ) {
|
|
@@ -424,11 +423,11 @@ const ce = 3, ae = 1e3, Re = (e, r) => {
|
|
|
424
423
|
error: (a) => o.next(a),
|
|
425
424
|
complete: () => o.complete()
|
|
426
425
|
}), l = () => {
|
|
427
|
-
n.delete(c),
|
|
426
|
+
n.delete(c), $(r, c), t();
|
|
428
427
|
};
|
|
429
428
|
return r.push(c), t(), l;
|
|
430
429
|
});
|
|
431
|
-
},
|
|
430
|
+
}, _e = (e) => {
|
|
432
431
|
const { errorStatusCodes: r, onAuthError: n } = e;
|
|
433
432
|
return (s, i) => i(s).pipe(
|
|
434
433
|
J((o) => (o instanceof E && r.some((c) => c === o.status) && n(), Y(() => o)))
|
|
@@ -445,18 +444,18 @@ const ce = 3, ae = 1e3, Re = (e, r) => {
|
|
|
445
444
|
clearTimeout(i), s(!1);
|
|
446
445
|
};
|
|
447
446
|
});
|
|
448
|
-
}, he = () => (e, r) => r.map((n) => ({ config: n, result: e })),
|
|
447
|
+
}, he = () => (e, r) => r.map((n) => ({ config: n, result: e })), xe = (e, r = {}) => {
|
|
449
448
|
const { isMatch: n, getParamsFromRequest: t, mergeParamsToRequest: s } = e, { fetchCheck: i = le(300), distributeResult: o = he() } = r, c = [], l = (a) => a.map((h) => h.config);
|
|
450
449
|
return (a, h) => n(a) ? new g((u) => {
|
|
451
450
|
const d = t(a);
|
|
452
451
|
c.push({
|
|
453
|
-
next: (
|
|
454
|
-
error: (
|
|
452
|
+
next: (m) => u.next(m),
|
|
453
|
+
error: (m) => u.error(m),
|
|
455
454
|
config: d
|
|
456
455
|
});
|
|
457
456
|
const f = l(c);
|
|
458
|
-
i(a).then((
|
|
459
|
-
if (
|
|
457
|
+
i(a).then((m) => {
|
|
458
|
+
if (m) {
|
|
460
459
|
const w = [];
|
|
461
460
|
f.forEach((p) => {
|
|
462
461
|
const b = c.findIndex((R) => R.config === p);
|
|
@@ -491,8 +490,8 @@ const ce = 3, ae = 1e3, Re = (e, r) => {
|
|
|
491
490
|
}) : h(a);
|
|
492
491
|
};
|
|
493
492
|
export {
|
|
494
|
-
|
|
495
|
-
|
|
493
|
+
_e as AuthInterceptorFactory,
|
|
494
|
+
me as FetchHTTPImplementation,
|
|
496
495
|
G as HTTPEventType,
|
|
497
496
|
x as HTTPHeaders,
|
|
498
497
|
ee as HTTPProgress,
|
|
@@ -502,11 +501,11 @@ export {
|
|
|
502
501
|
O as HTTPService,
|
|
503
502
|
L as HTTPStatusCode,
|
|
504
503
|
Q as IHTTPImplementation,
|
|
505
|
-
|
|
506
|
-
|
|
504
|
+
we as ISocketService,
|
|
505
|
+
xe as MergeInterceptorFactory,
|
|
507
506
|
re as ResponseHeader,
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
507
|
+
Ee as RetryInterceptorFactory,
|
|
508
|
+
Re as ThresholdInterceptorFactory,
|
|
509
|
+
ge as WebSocketService,
|
|
510
|
+
fe as XHRHTTPImplementation
|
|
512
511
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import { Disposable } from '@univerjs/core';
|
|
3
|
-
import { Injector } from '@wendellhu/redi';
|
|
2
|
+
import { Disposable, Injector } from '@univerjs/core';
|
|
4
3
|
import { IHTTPImplementation } from '../implementations/implementation';
|
|
5
4
|
import { HTTPRequest } from '../request';
|
|
6
5
|
import { HTTPEvent, HTTPResponse, HTTPResponseError } from '../response';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Disposable } from '@univerjs/core';
|
|
2
|
-
import { IDisposable } from '@wendellhu/redi';
|
|
1
|
+
import { IDisposable, Disposable } from '@univerjs/core';
|
|
3
2
|
import { Observable } from 'rxjs';
|
|
4
3
|
import { HTTPResponseType } from './http';
|
|
5
4
|
import { IHTTPImplementation } from './implementations/implementation';
|
|
@@ -12,4 +12,4 @@ export interface IHTTPImplementation {
|
|
|
12
12
|
*/
|
|
13
13
|
send(request: HTTPRequest): Observable<HTTPEvent<any>>;
|
|
14
14
|
}
|
|
15
|
-
export declare const IHTTPImplementation: import('@
|
|
15
|
+
export declare const IHTTPImplementation: import('@univerjs/core').IdentifierDecorator<IHTTPImplementation>;
|
|
@@ -5,7 +5,7 @@ export type SocketBodyType = string | ArrayBufferLike | Blob | ArrayBufferView;
|
|
|
5
5
|
/**
|
|
6
6
|
* This service is responsible for establishing bidi-directional connection to a remote server.
|
|
7
7
|
*/
|
|
8
|
-
export declare const ISocketService: import('@
|
|
8
|
+
export declare const ISocketService: import('@univerjs/core').IdentifierDecorator<ISocketService>;
|
|
9
9
|
export interface ISocketService {
|
|
10
10
|
createSocket(url: string): Nullable<ISocket>;
|
|
11
11
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
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 O=k.createIdentifier("network.http-implementation");class M{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>`${n}=${this.params[n]}`).join("&"):""}}let G=0;class x{constructor(n,r,t){w(this,"uid",G++);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:D,r=(s=this.requestParams)==null?void 0:s.body;return n===D&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,X=(e,n,r,t)=>{for(var s=t>1?void 0:t?W(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(t?i(n,r,s):i(s))||s);return t&&s&&V(n,r,s),s},z=(e,n)=>(r,t)=>n(r,t,e);c.HTTPService=class extends p.Disposable{constructor(r){super();w(this,"_interceptors",[]);w(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,l;const o=new _(s==null?void 0:s.headers),i=new M(s==null?void 0:s.params),a=new x(r,t,{headers:o,params:i,withCredentials:(d=s==null?void 0:s.withCredentials)!=null?d:!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 y.of(a).pipe(E.concatMap(h=>this._runInterceptorsAndImplementation(h)))}async _request(r,t,s){var h,m;const o=new _(s==null?void 0:s.headers),i=new M(s==null?void 0:s.params),a=new x(r,t,{headers:o,params:i,withCredentials:(h=s==null?void 0:s.withCredentials)!=null?h:!1,responseType:(m=s==null?void 0:s.responseType)!=null?m:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),d=y.of(a).pipe(E.concatMap(u=>this._runInterceptorsAndImplementation(u)));return await y.firstValueFrom(d)}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(t=>t.interceptor).reduceRight((t,s)=>J(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}},c.HTTPService=X([z(0,O)],c.HTTPService);function J(e,n){return(r,t)=>n(r,s=>e(s,t))}var q=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(q||{});class F{constructor({body:n,headers:r,status:t,statusText:s}){w(this,"type",1);w(this,"body");w(this,"headers");w(this,"status");w(this,"statusText");this.body=n,this.headers=r,this.status=t,this.statusText=s}}class j{constructor(n,r,t){w(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 R{constructor({headers:n,status:r,statusText:t,error:s}){w(this,"headers");w(this,"status");w(this,"statusText");w(this,"error");this.headers=n,this.status=r,this.statusText=t,this.error=s}}const Y=200,K=300;var I=(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))(I||{});class Q{send(n){return new y.Observable(r=>{const t=new AbortController;return this._send(n,r,t).then(()=>{},s=>{r.error(new R({error:s}))}),()=>t.abort()})}async _send(n,r,t){var h,m;let s;try{const u=this._parseFetchParamsFromRequest(n);s=await fetch(n.getUrlWithParams(),{signal:t.signal,...u})}catch(u){r.error(new R({error:u,status:(h=u.status)!=null?h:0,statusText:(m=u.statusText)!=null?m:"Unknown Error",headers:u.headers}));return}const o=new _(s.headers),i=s.status,a=s.statusText;let d=null;s.body&&(d=await this._readBody(n,s,r)),i>=I.Ok&&i<I.MultipleChoices?r.next(new F({body:d,headers:o,status:i,statusText:a})):r.error(new R({error:d,status:i,statusText:a,headers:o})),r.complete()}async _readBody(n,r,t){var b,g;const s=[],o=r.body.getReader(),i=r.headers.get("content-length");let a=0;const d=(b=n.requestParams)==null?void 0:b.reportProgress,l=n.responseType;let h,m;for(;;){const{done:v,value:f}=await o.read();if(v)break;s.push(f),a+=f.length,d&&l==="text"&&(h=(h!=null?h:"")+(m!=null?m:m=new TextDecoder).decode(f,{stream:!0}),t.next(new j(i?Number.parseInt(i,10):void 0,a,h)))}const u=Z(s,a);try{const v=(g=r.headers.get("content-type"))!=null?g:"";return H(n,u,v)}catch(v){return t.error(new R({error:v,status:r.status,statusText:r.statusText,headers:new _(r.headers)})),null}}_parseFetchParamsFromRequest(n){return{method:n.method,headers:n.getHeadersInit(),body:n.getBody(),credentials:n.withCredentials?"include":void 0}}}function Z(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 P=/^\)\]\}',?\n/;function H(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(P,"");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}.`)}}class S{send(n){return new y.Observable(r=>{const t=new XMLHttpRequest;t.open(n.method,n.getUrlWithParams()),n.withCredentials&&(t.withCredentials=!0),n.headers.forEach((d,l)=>t.setRequestHeader(d,l.join(","))),n.headers.has("Accept")||t.setRequestHeader("Accept","application/json, text/plain, */*"),n.headers.has("Content-Type")||t.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const d=t.statusText||"OK",l=new _(t.getAllResponseHeaders());return new B(l,t.status,d)},o=()=>{const{headers:d,statusText:l,status:h}=s(),{responseType:m}=n;let u=null,b=null;h!==I.NoContent&&(u=typeof t.response>"u"?t.responseText:t.response);let g=h>=Y&&h<K;if(m==="json"&&typeof u=="string"){const v=u;try{u=u?JSON.parse(u):null}catch(f){g=!1,u=v,b=f}}g?r.next(new F({body:u,headers:d,status:h,statusText:l})):r.error(new R({error:b,headers:d,status:h,statusText:l}))},i=d=>{const l=new R({error:d,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:s().headers});r.error(l)};t.addEventListener("load",o),t.addEventListener("error",i),t.addEventListener("abort",i),t.addEventListener("timeout",i);const a=n.getBody();return t.send(a),()=>{t.readyState!==t.DONE&&t.abort(),t.removeEventListener("load",o),t.removeEventListener("error",i),t.removeEventListener("abort",i),t.removeEventListener("timeout",i)}})}}const C=k.createIdentifier("univer.socket");class T 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 y.Observable(o=>{const i=a=>o.next(a);r.addEventListener("open",i),t.add(p.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(E.share()),close$:new y.Observable(o=>{const i=a=>o.next(a);r.addEventListener("close",i),t.add(p.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(E.share()),error$:new y.Observable(o=>{const i=a=>o.next(a);r.addEventListener("error",i),t.add(p.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(E.share()),message$:new y.Observable(o=>{const i=a=>o.next(a);r.addEventListener("message",i),t.add(p.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(E.share())}}catch(r){return console.error(r),null}}}const ee=3,re=1e3,te=(e,n)=>{var s,o;const r=(s=n==null?void 0:n.maxRetryAttempts)!=null?s:ee,t=(o=n==null?void 0:n.delayInterval)!=null?o:re;return(i,a)=>a(i).pipe(E.retry({delay:t,count:r}))},ne=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 y.Observable(i=>{const a=()=>o(s).subscribe({next:l=>i.next(l),error:l=>i.next(l),complete:()=>i.complete()}),d=()=>{r.delete(a),p.remove(n,a),t()};return n.push(a),t(),d})},se=e=>{const{errorStatusCodes:n,onAuthError:r}=e;return(s,o)=>o(s).pipe(y.catchError(i=>(i instanceof R&&n.some(a=>a===i.status)&&r(),y.throwError(()=>i))))},ie=(e=300)=>{let r=()=>{};return t=>new Promise(s=>{r();const o=setTimeout(()=>{s(!0)},e);r=()=>{clearTimeout(o),s(!1)}})},oe=()=>(e,n)=>n.map(r=>({config:r,result:e})),ce=(e,n={})=>{const{isMatch:r,getParamsFromRequest:t,mergeParamsToRequest:s}=e,{fetchCheck:o=ie(300),distributeResult:i=oe()}=n,a=[],d=l=>l.map(h=>h.config);return(l,h)=>r(l)?new y.Observable(m=>{const u=t(l);a.push({next:g=>m.next(g),error:g=>m.error(g),config:u});const b=d(a);o(l).then(g=>{if(g){const v=[];b.forEach(f=>{const A=a.findIndex(L=>L.config===f);if(A>=0){const[L]=a.splice(A,1);v.push(L)}}),h(s(b,l)).subscribe({next:f=>{if(f.type===q.Response){const A=f.body,L=i(A,b);v.forEach(N=>{const $=L.find(U=>U.config===N.config);if($){const U=new F({body:$.result,headers:f.headers,status:f.status,statusText:f.statusText});N.next(U)}else N.error("batch error")})}},complete:()=>m.complete(),error:f=>m.error(f)})}})}):h(l)};c.AuthInterceptorFactory=se,c.FetchHTTPImplementation=Q,c.HTTPEventType=q,c.HTTPHeaders=_,c.HTTPProgress=j,c.HTTPRequest=x,c.HTTPResponse=F,c.HTTPResponseError=R,c.HTTPStatusCode=I,c.IHTTPImplementation=O,c.ISocketService=C,c.MergeInterceptorFactory=ce,c.ResponseHeader=B,c.RetryInterceptorFactory=te,c.ThresholdInterceptorFactory=ne,c.WebSocketService=T,c.XHRHTTPImplementation=S,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(a,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("@univerjs/core"),require("rxjs"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","rxjs/operators"],h):(a=typeof globalThis<"u"?globalThis:a||self,h(a.UniverNetwork={},a.UniverCore,a.rxjs,a.rxjs.operators))})(this,function(a,h,y,E){"use strict";var ae=Object.defineProperty;var ce=(a,h,y)=>h in a?ae(a,h,{enumerable:!0,configurable:!0,writable:!0,value:y}):a[h]=y;var w=(a,h,y)=>ce(a,typeof h!="symbol"?h+"":h,y);const k="application/json";class _{constructor(n){w(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}toHeadersInit(){var r,t;const n={};return this._headers.forEach((s,o)=>{n[o]=s.join(",")}),(r=n.accept)!=null||(n.accept="application/json, text/plain, */*"),(t=n["content-type"])!=null||(n["content-type"]="application/json;charset=UTF-8"),n}_setHeader(n,r){const t=n.toLowerCase();this._headers.has(t)?this._headers.get(t).push(r.toString()):this._headers.set(t,[r.toString()])}_handleHeadersString(n){n.split(`
|
|
2
|
+
`).forEach(r=>{const[t,s]=r.split(":");t&&s&&this._setHeader(t,s)})}_handleHeadersConstructorProps(n){Object.entries(n).forEach(([r,t])=>this._setHeader(r,t))}_handleHeaders(n){n.forEach((r,t)=>this._setHeader(t,r))}}const D=h.createIdentifier("network.http-implementation");class O{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>`${n}=${this.params[n]}`).join("&"):""}}let $=0;class x{constructor(n,r,t){w(this,"uid",$++);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:k,r=(s=this.requestParams)==null?void 0:s.body;return n===k&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}var G=Object.defineProperty,V=Object.getOwnPropertyDescriptor,W=(e,n,r,t)=>{for(var s=t>1?void 0:t?V(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(t?i(n,r,s):i(s))||s);return t&&s&&G(n,r,s),s},X=(e,n)=>(r,t)=>n(r,t,e);a.HTTPService=class extends h.Disposable{constructor(r){super();w(this,"_interceptors",[]);w(this,"_pipe");this._http=r}registerHTTPInterceptor(r){if(this._interceptors.indexOf(r)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(r),this._interceptors=this._interceptors.sort((t,s)=>{var o,i;return((o=t.priority)!=null?o:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,h.toDisposable(()=>h.remove(this._interceptors,r))}get(r,t){return this._request("GET",r,t)}post(r,t){return this._request("POST",r,t)}put(r,t){return this._request("PUT",r,t)}delete(r,t){return this._request("DELETE",r,t)}patch(r,t){return this._request("PATCH",r,t)}getSSE(r,t,s){var p,l;const o=new _(s==null?void 0:s.headers),i=new O(s==null?void 0:s.params),c=new x(r,t,{headers:o,params:i,withCredentials:(p=s==null?void 0:s.withCredentials)!=null?p:!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 y.of(c).pipe(E.concatMap(d=>this._runInterceptorsAndImplementation(d)))}async _request(r,t,s){var d,m;const o=new _(s==null?void 0:s.headers),i=new O(s==null?void 0:s.params),c=new x(r,t,{headers:o,params:i,withCredentials:(d=s==null?void 0:s.withCredentials)!=null?d:!1,responseType:(m=s==null?void 0:s.responseType)!=null?m:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),p=y.of(c).pipe(E.concatMap(u=>this._runInterceptorsAndImplementation(u)));return await y.firstValueFrom(p)}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(t=>t.interceptor).reduceRight((t,s)=>z(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}},a.HTTPService=W([X(0,D)],a.HTTPService);function z(e,n){return(r,t)=>n(r,s=>e(s,t))}var N=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(N||{});class F{constructor({body:n,headers:r,status:t,statusText:s}){w(this,"type",1);w(this,"body");w(this,"headers");w(this,"status");w(this,"statusText");this.body=n,this.headers=r,this.status=t,this.statusText=s}}class M{constructor(n,r,t){w(this,"type",0);this.total=n,this.loaded=r,this.partialText=t}}class j{constructor(n,r,t){this.headers=n,this.status=r,this.statusText=t}}class R{constructor({headers:n,status:r,statusText:t,error:s}){w(this,"headers");w(this,"status");w(this,"statusText");w(this,"error");this.headers=n,this.status=r,this.statusText=t,this.error=s}}const J=200,Y=300;var I=(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))(I||{});class K{send(n){return new y.Observable(r=>{const t=new AbortController;return this._send(n,r,t).then(()=>{},s=>{r.error(new R({error:s}))}),()=>t.abort()})}async _send(n,r,t){var d,m;let s;try{const u=this._parseFetchParamsFromRequest(n);s=await fetch(n.getUrlWithParams(),{signal:t.signal,...u})}catch(u){r.error(new R({error:u,status:(d=u.status)!=null?d:0,statusText:(m=u.statusText)!=null?m:"Unknown Error",headers:u.headers}));return}const o=new _(s.headers),i=s.status,c=s.statusText;let p=null;s.body&&(p=await this._readBody(n,s,r)),i>=I.Ok&&i<I.MultipleChoices?r.next(new F({body:p,headers:o,status:i,statusText:c})):r.error(new R({error:p,status:i,statusText:c,headers:o})),r.complete()}async _readBody(n,r,t){var b,g;const s=[],o=r.body.getReader(),i=r.headers.get("content-length");let c=0;const p=(b=n.requestParams)==null?void 0:b.reportProgress,l=n.responseType;let d,m;for(;;){const{done:v,value:f}=await o.read();if(v)break;s.push(f),c+=f.length,p&&l==="text"&&(d=(d!=null?d:"")+(m!=null?m:m=new TextDecoder).decode(f,{stream:!0}),t.next(new M(i?Number.parseInt(i,10):void 0,c,d)))}const u=Q(s,c);try{const v=(g=r.headers.get("content-type"))!=null?g:"";return P(n,u,v)}catch(v){return t.error(new R({error:v,status:r.status,statusText:r.statusText,headers:new _(r.headers)})),null}}_parseFetchParamsFromRequest(n){return{method:n.method,headers:n.getHeadersInit(),body:n.getBody(),credentials:n.withCredentials?"include":void 0}}}function Q(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 Z=/^\)\]\}',?\n/;function P(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(Z,"");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}.`)}}class H{send(n){return new y.Observable(r=>{const t=new XMLHttpRequest;t.open(n.method,n.getUrlWithParams()),n.withCredentials&&(t.withCredentials=!0),n.headers.forEach((p,l)=>t.setRequestHeader(p,l.join(","))),n.headers.has("Accept")||t.setRequestHeader("Accept","application/json, text/plain, */*"),n.headers.has("Content-Type")||t.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const p=t.statusText||"OK",l=new _(t.getAllResponseHeaders());return new j(l,t.status,p)},o=()=>{const{headers:p,statusText:l,status:d}=s(),{responseType:m}=n;let u=null,b=null;d!==I.NoContent&&(u=typeof t.response>"u"?t.responseText:t.response);let g=d>=J&&d<Y;if(m==="json"&&typeof u=="string"){const v=u;try{u=u?JSON.parse(u):null}catch(f){g=!1,u=v,b=f}}g?r.next(new F({body:u,headers:p,status:d,statusText:l})):r.error(new R({error:b,headers:p,status:d,statusText:l}))},i=p=>{const l=new R({error:p,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:s().headers});r.error(l)};t.addEventListener("load",o),t.addEventListener("error",i),t.addEventListener("abort",i),t.addEventListener("timeout",i);const c=n.getBody();return t.send(c),()=>{t.readyState!==t.DONE&&t.abort(),t.removeEventListener("load",o),t.removeEventListener("error",i),t.removeEventListener("abort",i),t.removeEventListener("timeout",i)}})}}const S=h.createIdentifier("univer.socket");class C extends h.Disposable{createSocket(n){try{const r=new WebSocket(n),t=new h.DisposableCollection;return{URL:n,close:(o,i)=>{r.close(o,i),t.dispose()},send:o=>{r.send(o)},open$:new y.Observable(o=>{const i=c=>o.next(c);r.addEventListener("open",i),t.add(h.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(E.share()),close$:new y.Observable(o=>{const i=c=>o.next(c);r.addEventListener("close",i),t.add(h.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(E.share()),error$:new y.Observable(o=>{const i=c=>o.next(c);r.addEventListener("error",i),t.add(h.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(E.share()),message$:new y.Observable(o=>{const i=c=>o.next(c);r.addEventListener("message",i),t.add(h.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(E.share())}}catch(r){return console.error(r),null}}}const T=3,ee=1e3,re=(e,n)=>{var s,o;const r=(s=n==null?void 0:n.maxRetryAttempts)!=null?s:T,t=(o=n==null?void 0:n.delayInterval)!=null?o:ee;return(i,c)=>c(i).pipe(E.retry({delay:t,count:r}))},te=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 y.Observable(i=>{const c=()=>o(s).subscribe({next:l=>i.next(l),error:l=>i.next(l),complete:()=>i.complete()}),p=()=>{r.delete(c),h.remove(n,c),t()};return n.push(c),t(),p})},ne=e=>{const{errorStatusCodes:n,onAuthError:r}=e;return(s,o)=>o(s).pipe(y.catchError(i=>(i instanceof R&&n.some(c=>c===i.status)&&r(),y.throwError(()=>i))))},se=(e=300)=>{let r=()=>{};return t=>new Promise(s=>{r();const o=setTimeout(()=>{s(!0)},e);r=()=>{clearTimeout(o),s(!1)}})},ie=()=>(e,n)=>n.map(r=>({config:r,result:e})),oe=(e,n={})=>{const{isMatch:r,getParamsFromRequest:t,mergeParamsToRequest:s}=e,{fetchCheck:o=se(300),distributeResult:i=ie()}=n,c=[],p=l=>l.map(d=>d.config);return(l,d)=>r(l)?new y.Observable(m=>{const u=t(l);c.push({next:g=>m.next(g),error:g=>m.error(g),config:u});const b=p(c);o(l).then(g=>{if(g){const v=[];b.forEach(f=>{const A=c.findIndex(L=>L.config===f);if(A>=0){const[L]=c.splice(A,1);v.push(L)}}),d(s(b,l)).subscribe({next:f=>{if(f.type===N.Response){const A=f.body,L=i(A,b);v.forEach(q=>{const B=L.find(U=>U.config===q.config);if(B){const U=new F({body:B.result,headers:f.headers,status:f.status,statusText:f.statusText});q.next(U)}else q.error("batch error")})}},complete:()=>m.complete(),error:f=>m.error(f)})}})}):d(l)};a.AuthInterceptorFactory=ne,a.FetchHTTPImplementation=K,a.HTTPEventType=N,a.HTTPHeaders=_,a.HTTPProgress=M,a.HTTPRequest=x,a.HTTPResponse=F,a.HTTPResponseError=R,a.HTTPStatusCode=I,a.IHTTPImplementation=D,a.ISocketService=S,a.MergeInterceptorFactory=oe,a.ResponseHeader=j,a.RetryInterceptorFactory=re,a.ThresholdInterceptorFactory=te,a.WebSocketService=C,a.XHRHTTPImplementation=H,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/network",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4-alpha.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -45,18 +45,16 @@
|
|
|
45
45
|
"lib"
|
|
46
46
|
],
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@wendellhu/redi": "0.15.5",
|
|
49
48
|
"rxjs": ">=7.0.0",
|
|
50
|
-
"@univerjs/core": "0.2.
|
|
49
|
+
"@univerjs/core": "0.2.4-alpha.0"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
|
-
"@wendellhu/redi": "0.15.5",
|
|
54
52
|
"rxjs": "^7.8.1",
|
|
55
53
|
"typescript": "^5.5.3",
|
|
56
|
-
"vite": "^5.3.
|
|
57
|
-
"vitest": "^
|
|
58
|
-
"@univerjs/core": "0.2.
|
|
59
|
-
"@univerjs/shared": "0.2.
|
|
54
|
+
"vite": "^5.3.4",
|
|
55
|
+
"vitest": "^2.0.3",
|
|
56
|
+
"@univerjs/core": "0.2.4-alpha.0",
|
|
57
|
+
"@univerjs/shared": "0.2.4-alpha.0"
|
|
60
58
|
},
|
|
61
59
|
"univerSpace": {
|
|
62
60
|
".": {
|