@univerjs/network 0.17.0 → 0.18.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/facade.js +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/es/facade.js +1 -85
- package/lib/es/index.js +2 -627
- package/lib/facade.js +1 -85
- package/lib/index.js +2 -627
- package/lib/types/config/config.d.ts +16 -1
- package/lib/types/facade/f-network.d.ts +18 -2
- package/lib/types/facade/f-univer.d.ts +16 -1
- package/lib/types/plugin.d.ts +16 -1
- package/lib/types/services/http/__testing__/http-testing-utils.d.ts +17 -2
- package/lib/types/services/http/http.service.d.ts +22 -6
- package/lib/types/services/http/implementations/fetch.d.ts +18 -3
- package/lib/types/services/http/implementations/implementation.d.ts +19 -4
- package/lib/types/services/http/implementations/util.d.ts +16 -1
- package/lib/types/services/http/implementations/xhr.d.ts +18 -3
- package/lib/types/services/http/interceptor.d.ts +18 -3
- package/lib/types/services/http/interceptors/auth-interceptor.d.ts +16 -1
- package/lib/types/services/http/interceptors/merge-interceptor.d.ts +18 -3
- package/lib/types/services/http/interceptors/retry-interceptor.d.ts +17 -2
- package/lib/types/services/http/interceptors/threshold-interceptor.d.ts +17 -2
- package/lib/types/services/http/request.d.ts +17 -2
- package/lib/types/services/http/response.d.ts +17 -2
- package/lib/types/services/web-socket/web-socket.service.d.ts +18 -2
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +7 -6
- package/lib/types/services/http/__testing__/http-params.spec.d.ts +0 -16
- package/lib/types/services/http/__testing__/http.service.spec.d.ts +0 -16
- package/lib/types/services/http/__testing__/request.spec.d.ts +0 -16
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
let e=require(`@univerjs/core/facade`),t=require(`@univerjs/network`),n=require(`@univerjs/core`);function r(e,t){return function(n,r){t(n,r,e)}}function i(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let a=class extends e.FBase{constructor(e,t){super(),this._injector=e,this._httpService=t}get(e,t){return this._httpService.get(e,t)}post(e,t){return this._httpService.post(e,t)}put(e,t){return this._httpService.put(e,t)}delete(e,t){return this._httpService.delete(e,t)}patch(e,t){return this._httpService.patch(e,t)}getSSE(e,t,n){return this._httpService.getSSE(e,t,n)}};a=i([r(0,(0,n.Inject)(n.Injector)),r(1,(0,n.Inject)(t.HTTPService))],a);var o=class extends e.FUniver{getNetwork(){return this._injector.createInstance(a)}createSocket(e){let n=this._injector.createInstance(t.WebSocketService).createSocket(e);if(!n)throw Error(`[WebSocketService]: failed to create socket!`);return n}};e.FUniver.extend(o);
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
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 B{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 Q=0;class U{constructor(n,r,t){f(this,"uid",Q++);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:P(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,H=(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},S=(e,n)=>(r,t)=>n(r,t,e);exports.HTTPService=class extends h.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,h.toDisposable(()=>h.remove(this._interceptors,r))}get(r,t){return this.request("GET",r,t)}post(r,t){return this.request("POST",r,t)}put(r,t){return this.request("PUT",r,t)}delete(r,t){return this.request("DELETE",r,t)}patch(r,t){return this.request("PATCH",r,t)}async request(r,t,s){var u,p;const o=new E(s==null?void 0:s.headers),i=new B(s==null?void 0:s.params),c=new U(r,t,{headers:o,params:i,withCredentials:(u=s==null?void 0:s.withCredentials)!=null?u:!1,responseType:(p=s==null?void 0:s.responseType)!=null?p:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),y=w.of(c).pipe(_.concatMap(a=>this._runInterceptorsAndImplementation(a)));return await w.firstValueFrom(y)}stream(r,t,s){return this.getSSE(r,t,s)}getSSE(r,t,s){var y,l;const o=new E(s==null?void 0:s.headers),i=new B(s==null?void 0:s.params),c=new U(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)))}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(t=>t.interceptor).reduceRight((t,s)=>C(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}};exports.HTTPService=H([S(0,D)],exports.HTTPService);function C(e,n){return(r,t)=>n(r,s=>e(s,t))}const T=200,ee=300;var L=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.Ok=200]="Ok",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.ImUsed=226]="ImUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.Unused=306]="Unused",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.PayloadTooLarge=413]="PayloadTooLarge",e[e.UriTooLong=414]="UriTooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HttpVersionNotSupported=505]="HttpVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(L||{}),q=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(q||{});class F{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 G{constructor(n,r,t){f(this,"type",0);this.total=n,this.loaded=r,this.partialText=t}}class X{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 W(e){return{method:e.method,headers:e.getHeadersInit(),body:e.getBody(),credentials:e.withCredentials?"include":void 0}}var re=Object.getOwnPropertyDescriptor,te=(e,n,r,t)=>{for(var s=t>1?void 0:t?re(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},ne=(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,p;let s;try{const a=W(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:(p=a.statusText)!=null?p:"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>=L.Ok&&i<L.MultipleChoices)r.next(new F({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,p;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:"")+(p!=null?p:p=new TextDecoder).decode(d,{stream:!0}),t.next(new G(i?Number.parseInt(i,10):void 0,c,u)))}const a=se(s,c);try{const v=(g=r.headers.get("content-type"))!=null?g:"";return ie(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=te([ne(0,h.ILogService)],exports.FetchHTTPImplementation);function se(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 oe=/^\)\]\}',?\n/;function ie(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(oe,"");return t===""?null:JSON.parse(t);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n.buffer],{type:r});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}var ce=Object.getOwnPropertyDescriptor,ae=(e,n,r,t)=>{for(var s=t>1?void 0:t?ce(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},le=(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=W(n),{responseType:i}=n;t.open(n.method,s),n.withCredentials&&(t.withCredentials=!0),o.headers&&Object.entries(o.headers).forEach(([p,a])=>t.setRequestHeader(p,a));const c=()=>{const p=t.statusText||"OK",a=new E(t.getAllResponseHeaders());return new X(a,t.status,p)},y=()=>{const{headers:p,statusText:a,status:m}=c();let g=null,v=null;m!==L.NoContent&&(g=typeof t.response>"u"?t.responseText:t.response);let d=m>=T&&m<ee;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 F({body:g,headers:p,status:m,statusText:a}));else{const b=new I({request:n,error:v,headers:p,status:m,statusText:a});this._logService.error("[XHRHTTPImplementation]: network error",b),r.error(b)}},l=p=>{const a=new I({request:n,error:p,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:c().headers});this._logService.error("[XHRHTTPImplementation]: network error",a),r.error(a)};t.responseType=i||"",t.addEventListener("load",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=ae([le(0,h.ILogService)],exports.XHRHTTPImplementation);var he=Object.getOwnPropertyDescriptor,pe=(e,n,r,t)=>{for(var s=t>1?void 0:t?he(n,r):n,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=i(s)||s);return s},O=(e,n)=>(r,t)=>n(r,t,e),x;exports.UniverNetworkPlugin=(x=class extends h.Plugin{constructor(n=$,r,t,s){super(),this._config=n,this._logger=r,this._injector=t,this._configService=s;const{...o}=h.merge({},$,this._config);this._configService.setConfig(Y,o)}onStarting(){var t,s,o;if(this._injector.get(exports.HTTPService,h.Quantity.OPTIONAL,h.LookUp.SKIP_SELF)&&!((t=this._config)!=null&&t.forceUseNewInstance)){this._logger.warn("[UniverNetworkPlugin]",'HTTPService is already registered in an ancestor interceptor. Skipping registration. If you want to force a new instance, set "forceUseNewInstance" to true in the plugin configuration.');return}const r=(s=this._config)!=null&&s.useFetchImpl?exports.FetchHTTPImplementation:typeof window<"u"?exports.XHRHTTPImplementation:exports.FetchHTTPImplementation;h.registerDependencies(this._injector,h.mergeOverrideWithDependencies([[exports.HTTPService],[D,{useClass:r}]],(o=this._config)==null?void 0:o.override))}},f(x,"pluginName","UNIVER_NETWORK_PLUGIN"),f(x,"packageName",M.name),f(x,"version",M.version),x);exports.UniverNetworkPlugin=pe([O(1,h.ILogService),O(2,h.Inject(h.Injector)),O(3,h.IConfigService)],exports.UniverNetworkPlugin);const de=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))))},ue=(e=300)=>{let r=()=>{};return t=>new Promise(s=>{r();const o=setTimeout(()=>{s(!0)},e);r=()=>{clearTimeout(o),s(!1)}})},ge=()=>(e,n)=>n.map(r=>({config:r,result:e})),fe=(e,n={})=>{const{isMatch:r,getParamsFromRequest:t,mergeParamsToRequest:s}=e,{fetchCheck:o=ue(300),distributeResult:i=ge()}=n,c=[],y=l=>l.map(u=>u.config);return(l,u)=>r(l)?new w.Observable(p=>{const a=t(l);c.push({next:g=>p.next(g),error:g=>p.error(g),config:a});const 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===q.Response){const b=d.body,R=i(b,m);v.forEach(N=>{const j=R.find(k=>k.config===N.config);if(j){const k=new F({body:j.result,headers:d.headers,status:d.status,statusText:d.statusText});N.next(k)}else N.error("batch error")})}},complete:()=>p.complete(),error:d=>p.error(d)})}})}):u(l)},me=3,ye=1e3,we=e=>{var t,s;const n=(t=e==null?void 0:e.maxRetryAttempts)!=null?t:me,r=(s=e==null?void 0:e.delayInterval)!=null?s:ye;return(o,i)=>i(o).pipe(_.retry({delay:r,count:n}))},ve=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),h.remove(n,c),t()};return n.push(c),t(),y})},be=h.createIdentifier("univer.network.socket.service");class Ie extends h.Disposable{createSocket(n){try{const r=new WebSocket(n),t=new h.DisposableCollection;return{URL:n,close:(o,i)=>{r.close(o,i),t.dispose()},send:o=>{r.send(o)},open$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("open",i),t.add(h.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(_.share()),close$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("close",i),t.add(h.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(_.share()),error$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("error",i),t.add(h.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(_.share()),message$:new w.Observable(o=>{const i=c=>o.next(c);r.addEventListener("message",i),t.add(h.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(_.share())}}catch(r){return console.error(r),null}}}exports.AuthInterceptorFactory=de;exports.HTTPEventType=q;exports.HTTPHeaders=E;exports.HTTPProgress=G;exports.HTTPRequest=U;exports.HTTPResponse=F;exports.HTTPResponseError=I;exports.HTTPStatusCode=L;exports.IHTTPImplementation=D;exports.ISocketService=be;exports.MergeInterceptorFactory=fe;exports.ResponseHeader=X;exports.RetryInterceptorFactory=we;exports.ThresholdInterceptorFactory=ve;exports.WebSocketService=Ie;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`rxjs`),n=require(`rxjs/operators`);var r=`@univerjs/network`,i=`0.18.0`;const a=`network.config`;Symbol(a);const o={};function s(e){"@babel/helpers - typeof";return s=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},s(e)}function c(e,t){if(s(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(s(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function l(e){var t=c(e,`string`);return s(t)==`symbol`?t:t+``}function u(e,t,n){return(t=l(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const d=`application/json`;function f(e){return Array.isArray(e)?e.some(e=>e.includes(d)):e.includes(d)}var p=class{constructor(e){u(this,`_headers`,new Map),typeof e==`string`?this._handleHeadersString(e):e instanceof Headers?this._handleHeaders(e):e&&this._handleHeadersConstructorProps(e)}forEach(e){this._headers.forEach((t,n)=>e(n,t))}has(e){return!!this._headers.has(e.toLowerCase())}get(e){let t=e.toLowerCase();return this._headers.has(t)?this._headers.get(t):null}set(e,t){this._setHeader(e,t)}toHeadersInit(e){let t={};return this._headers.forEach((e,n)=>{t[n]=e.join(`,`)}),t.accept!=null||(t.accept=`application/json, text/plain, */*`),!(e instanceof FormData)&&(t[`content-type`]!=null||(t[`content-type`]=`application/json;charset=UTF-8`)),t}_setHeader(e,t){let n=e.toLowerCase();this._headers.has(n)?this._headers.get(n).push(t.toString()):this._headers.set(n,[t.toString()])}_handleHeadersString(e){e.split(`
|
|
2
|
+
`).forEach(e=>{let[t,n]=e.split(`:`);t&&n&&this._setHeader(t,n)})}_handleHeadersConstructorProps(e){Object.entries(e).forEach(([e,t])=>this._setHeader(e,t))}_handleHeaders(e){e.forEach((e,t)=>this._setHeader(t,e))}};const m=(0,e.createIdentifier)(`network.http-implementation`);var h=class{constructor(e){this.params=e}toString(){return this.params?Object.keys(this.params).map(e=>{let t=this.params[e];return Array.isArray(t)?t.map(t=>`${e}=${t}`).join(`&`):`${e}=${t}`}).join(`&`):``}};let g=0;var _=class{get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}constructor(e,t,n){this.method=e,this.url=t,this.requestParams=n,u(this,`uid`,g++)}getUrlWithParams(){var e;let t=(e=this.requestParams)==null||(e=e.params)==null?void 0:e.toString();return t?`${this.url}${this.url.includes(`?`)?`&`:`?`}${t}`:this.url}getBody(){var e,t;let n=(e=this.headers.get(`Content-Type`))==null?d:e,r=(t=this.requestParams)==null?void 0:t.body;return r instanceof FormData?r:f(n)&&r&&typeof r==`object`?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){var e;return this.headers.toHeadersInit((e=this.requestParams)==null?void 0:e.body)}};function v(e,t){return function(n,r){t(n,r,e)}}function y(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let b=class extends e.Disposable{constructor(e){super(),this._http=e,u(this,`_interceptors`,[]),u(this,`_pipe`,void 0)}registerHTTPInterceptor(t){if(this._interceptors.indexOf(t)!==-1)throw Error(`[HTTPService]: The interceptor has already been registered!`);return this._interceptors.push(t),this._interceptors=this._interceptors.sort((e,t)=>{var n,r;return((n=e.priority)==null?0:n)-((r=t.priority)==null?0:r)}),this._pipe=null,(0,e.toDisposable)(()=>(0,e.remove)(this._interceptors,t))}get(e,t){return this.request(`GET`,e,t)}post(e,t){return this.request(`POST`,e,t)}put(e,t){return this.request(`PUT`,e,t)}delete(e,t){return this.request(`DELETE`,e,t)}patch(e,t){return this.request(`PATCH`,e,t)}async request(e,r,i){var a,o;return await(0,t.firstValueFrom)((0,t.of)(new _(e,r,{headers:new p(i==null?void 0:i.headers),params:new h(i==null?void 0:i.params),withCredentials:(a=i==null?void 0:i.withCredentials)==null?!1:a,responseType:(o=i==null?void 0:i.responseType)==null?`json`:o,body:[`GET`,`DELETE`].includes(e)||i==null?void 0:i.body})).pipe((0,n.concatMap)(e=>this._runInterceptorsAndImplementation(e))))}stream(e,t,n){return this.getSSE(e,t,n)}getSSE(e,r,i){var a,o;return(0,t.of)(new _(e,r,{headers:new p(i==null?void 0:i.headers),params:new h(i==null?void 0:i.params),withCredentials:(a=i==null?void 0:i.withCredentials)==null?!1:a,reportProgress:!0,responseType:(o=i==null?void 0:i.responseType)==null?`json`:o,body:[`GET`,`DELETE`].includes(e)||i==null?void 0:i.body})).pipe((0,n.concatMap)(e=>this._runInterceptorsAndImplementation(e)))}_runInterceptorsAndImplementation(e){return this._pipe||(this._pipe=this._interceptors.map(e=>e.interceptor).reduceRight((e,t)=>x(e,t),(e,t)=>t(e))),this._pipe(e,e=>this._http.send(e))}};b=y([v(0,m)],b);function x(e,t){return(n,r)=>t(n,t=>e(t,r))}let S=function(e){return 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}({}),C=function(e){return e[e.DownloadProgress=0]=`DownloadProgress`,e[e.Response=1]=`Response`,e}({});var w=class{constructor({body:e,headers:t,status:n,statusText:r}){u(this,`type`,C.Response),u(this,`body`,void 0),u(this,`headers`,void 0),u(this,`status`,void 0),u(this,`statusText`,void 0),this.body=e,this.headers=t,this.status=n,this.statusText=r}},T=class{constructor(e,t,n){this.total=e,this.loaded=t,this.partialText=n,u(this,`type`,C.DownloadProgress)}},E=class{constructor(e,t,n){this.headers=e,this.status=t,this.statusText=n}},D=class{constructor({request:e,headers:t,status:n,statusText:r,error:i}){u(this,`request`,void 0),u(this,`headers`,void 0),u(this,`status`,void 0),u(this,`statusText`,void 0),u(this,`error`,void 0),this.request=e,this.headers=t,this.status=n,this.statusText=r,this.error=i}};function O(e){return{method:e.method,headers:e.getHeadersInit(),body:e.getBody(),credentials:e.withCredentials?`include`:void 0}}let k=class{constructor(e){this._logService=e}send(e){return new t.Observable(t=>{let n=new AbortController;return this._send(e,t,n).catch(n=>{t.error(new D({error:n,request:e}))}),()=>n.abort()})}async _send(e,t,n){let r;try{let t=O(e),i=e.getUrlWithParams(),a=fetch(i,{signal:n.signal,...t});this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${i} with params ${t}`),r=await a}catch(n){var i,a;let r=new D({request:e,error:n,status:(i=n.status)==null?0:i,statusText:(a=n.statusText)==null?`Unknown Error`:a,headers:n.headers});this._logService.error(`[FetchHTTPImplementation]: network error`,r),t.error(r);return}let o=new p(r.headers),s=r.status,c=r.statusText,l=null;if(r.body&&(l=await this._readBody(e,r,t)),s>=S.Ok&&s<S.MultipleChoices)t.next(new w({body:l,headers:o,status:s,statusText:c}));else{let n=new D({request:e,error:l,status:s,statusText:c,headers:o});this._logService.error(`[FetchHTTPImplementation]: network error`,n),t.error(n)}t.complete()}async _readBody(e,t,n){var r;let i=[],a=t.body.getReader(),o=t.headers.get(`content-length`),s=0,c=(r=e.requestParams)==null?void 0:r.reportProgress,l=e.responseType,u,d;for(;;){let{done:e,value:t}=await a.read();if(e)break;if(i.push(t),s+=t.length,c&&l===`text`){var f,m;u=((f=u)==null?``:f)+((m=d)==null?d=new TextDecoder:m).decode(t,{stream:!0}),n.next(new T(o?Number.parseInt(o,10):void 0,s,u))}}let h=A(i,s);try{var g;return M(e,h,(g=t.headers.get(`content-type`))==null?``:g)}catch(r){let i=new D({request:e,error:r,status:t.status,statusText:t.statusText,headers:new p(t.headers)});return this._logService.error(`[FetchHTTPImplementation]: network error`,i),n.error(i),null}}};k=y([v(0,e.ILogService)],k);function A(e,t){let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}const j=/^\)\]\}',?\n/;function M(e,t,n){switch(e.responseType){case`json`:let r=new TextDecoder().decode(t).replace(j,``);return r===``?null:JSON.parse(r);case`text`:return new TextDecoder().decode(t);case`blob`:return new Blob([t.buffer],{type:n});case`arraybuffer`:return t.buffer;default:throw Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}let N=class{constructor(e){this._logService=e}send(e){return new t.Observable(t=>{let n=new XMLHttpRequest,r=e.getUrlWithParams(),i=O(e),{responseType:a}=e;n.open(e.method,r),e.withCredentials&&(n.withCredentials=!0),i.headers&&Object.entries(i.headers).forEach(([e,t])=>n.setRequestHeader(e,t));let o=()=>{let e=n.statusText||`OK`;return new E(new p(n.getAllResponseHeaders()),n.status,e)},s=()=>{let{headers:r,statusText:i,status:s}=o(),c=null,l=null;s!==S.NoContent&&(c=n.response===void 0?n.responseText:n.response);let u=s>=200&&s<300;if(a===`json`&&typeof c==`string`){let e=c;try{c=c?JSON.parse(c):null}catch(t){u=!1,c=e,l=t}}if(a===`blob`&&!(c instanceof Blob)&&(u=!1,l=Error(`Response is not a Blob object`)),u)t.next(new w({body:c,headers:r,status:s,statusText:i}));else{let n=new D({request:e,error:l,headers:r,status:s,statusText:i});this._logService.error(`[XHRHTTPImplementation]: network error`,n),t.error(n)}},c=r=>{let i=new D({request:e,error:r,status:n.status||0,statusText:n.statusText||`Unknown Error`,headers:o().headers});this._logService.error(`[XHRHTTPImplementation]: network error`,i),t.error(i)};n.responseType=a||``,n.addEventListener(`load`,s),n.addEventListener(`error`,c),n.addEventListener(`abort`,c),n.addEventListener(`timeout`,c);let l=e.getBody();return n.send(l),this._logService.debug(`[XHRHTTPImplementation]`,`sending request to url ${r} with params ${i}`),()=>{n.readyState!==n.DONE&&n.abort(),n.removeEventListener(`load`,s),n.removeEventListener(`error`,c),n.removeEventListener(`abort`,c),n.removeEventListener(`timeout`,c)}})}};N=y([v(0,e.ILogService)],N);let P=class extends e.Plugin{constructor(t=o,n,r,i){super(),this._config=t,this._logger=n,this._injector=r,this._configService=i;let{...s}=(0,e.merge)({},o,this._config);this._configService.setConfig(a,s)}onStarting(){var t,n,r;if(this._injector.get(b,e.Quantity.OPTIONAL,e.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}let i=(n=this._config)!=null&&n.useFetchImpl?k:typeof window<`u`?N:k;(0,e.registerDependencies)(this._injector,(0,e.mergeOverrideWithDependencies)([[b],[m,{useClass:i}]],(r=this._config)==null?void 0:r.override))}};u(P,`pluginName`,`UNIVER_NETWORK_PLUGIN`),u(P,`packageName`,r),u(P,`version`,i),P=y([v(1,e.ILogService),v(2,(0,e.Inject)(e.Injector)),v(3,e.IConfigService)],P);const F=e=>{let{errorStatusCodes:n,onAuthError:r}=e;return(e,i)=>i(e).pipe((0,t.catchError)(e=>(e instanceof D&&n.some(t=>t===e.status)&&r(),(0,t.throwError)(()=>e))))},I=(e=300)=>{let t=()=>{};return n=>new Promise(n=>{t();let r=setTimeout(()=>{n(!0)},e);t=()=>{clearTimeout(r),n(!1)}})},L=()=>(e,t)=>t.map(t=>({config:t,result:e})),R=(e,n={})=>{let{isMatch:r,getParamsFromRequest:i,mergeParamsToRequest:a}=e,{fetchCheck:o=I(300),distributeResult:s=L()}=n,c=[],l=e=>e.map(e=>e.config);return(e,n)=>r(e)?new t.Observable(t=>{let r=i(e);c.push({next:e=>t.next(e),error:e=>t.error(e),config:r});let u=l(c);o(e).then(r=>{if(r){let r=[];u.forEach(e=>{let t=c.findIndex(t=>t.config===e);if(t>=0){let[e]=c.splice(t,1);r.push(e)}}),n(a(u,e)).subscribe({next:e=>{if(e.type===C.Response){let t=e.body,n=s(t,u);r.forEach(t=>{let r=n.find(e=>e.config===t.config);if(r){let n=new w({body:r.result,headers:e.headers,status:e.status,statusText:e.statusText});t.next(n)}else t.error(`batch error`)})}},complete:()=>t.complete(),error:e=>t.error(e)})}})}):n(e)},z=e=>{var t,r;let i=(t=e==null?void 0:e.maxRetryAttempts)==null?3:t,a=(r=e==null?void 0:e.delayInterval)==null?1e3:r;return(e,t)=>t(e).pipe((0,n.retry)({delay:a,count:i}))},B=n=>{let r=[],i=new Set,a=()=>{for(var e;i.size<((e=n==null?void 0:n.maxParallel)==null?1:e)&&r.length>0;){let e=r.shift();i.add(e),e()}};return(n,o)=>new t.Observable(t=>{let s=()=>o(n).subscribe({next:e=>t.next(e),error:e=>t.error(e),complete:()=>t.complete()});return r.push(s),a(),()=>{i.delete(s),(0,e.remove)(r,s),a()}})},V=(0,e.createIdentifier)(`univer.network.socket.service`);var H=class extends e.Disposable{createSocket(r){try{let i=new WebSocket(r),a=new e.DisposableCollection;return{URL:r,close:(e,t)=>{i.close(e,t),a.dispose()},send:e=>{i.send(e)},open$:new t.Observable(t=>{let n=e=>t.next(e);i.addEventListener(`open`,n),a.add((0,e.toDisposable)(()=>i.removeEventListener(`open`,n)))}).pipe((0,n.share)()),close$:new t.Observable(t=>{let n=e=>t.next(e);i.addEventListener(`close`,n),a.add((0,e.toDisposable)(()=>i.removeEventListener(`close`,n)))}).pipe((0,n.share)()),error$:new t.Observable(t=>{let n=e=>t.next(e);i.addEventListener(`error`,n),a.add((0,e.toDisposable)(()=>i.removeEventListener(`error`,n)))}).pipe((0,n.share)()),message$:new t.Observable(t=>{let n=e=>t.next(e);i.addEventListener(`message`,n),a.add((0,e.toDisposable)(()=>i.removeEventListener(`message`,n)))}).pipe((0,n.share)())}}catch(e){return console.error(e),null}}};exports.AuthInterceptorFactory=F,Object.defineProperty(exports,`FetchHTTPImplementation`,{enumerable:!0,get:function(){return k}}),exports.HTTPEventType=C,exports.HTTPHeaders=p,exports.HTTPProgress=T,exports.HTTPRequest=_,exports.HTTPResponse=w,exports.HTTPResponseError=D,Object.defineProperty(exports,`HTTPService`,{enumerable:!0,get:function(){return b}}),exports.HTTPStatusCode=S,exports.IHTTPImplementation=m,exports.ISocketService=V,exports.MergeInterceptorFactory=R,exports.ResponseHeader=E,exports.RetryInterceptorFactory=z,exports.ThresholdInterceptorFactory=B,Object.defineProperty(exports,`UniverNetworkPlugin`,{enumerable:!0,get:function(){return P}}),exports.WebSocketService=H,Object.defineProperty(exports,`XHRHTTPImplementation`,{enumerable:!0,get:function(){return N}});
|
package/lib/es/facade.js
CHANGED
|
@@ -1,85 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { HTTPService as S, WebSocketService as _ } from "@univerjs/network";
|
|
3
|
-
import { Inject as h, Injector as u } from "@univerjs/core";
|
|
4
|
-
var w = Object.getOwnPropertyDescriptor, l = (t, e, c, r) => {
|
|
5
|
-
for (var i = r > 1 ? void 0 : r ? w(e, c) : e, s = t.length - 1, o; s >= 0; s--)
|
|
6
|
-
(o = t[s]) && (i = o(i) || i);
|
|
7
|
-
return i;
|
|
8
|
-
}, a = (t, e) => (c, r) => e(c, r, t);
|
|
9
|
-
let n = class extends v {
|
|
10
|
-
constructor(t, e) {
|
|
11
|
-
super(), this._injector = t, this._httpService = e;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Send a GET request to the server.
|
|
15
|
-
* @param {string} url - The requested URL.
|
|
16
|
-
* @param {IRequestParams} [params] - Query parameters.
|
|
17
|
-
* @returns {Promise<HTTPResponse>} Network response.
|
|
18
|
-
*/
|
|
19
|
-
get(t, e) {
|
|
20
|
-
return this._httpService.get(t, e);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Send a POST request to the server.
|
|
24
|
-
* @param {string} url - The requested URL.
|
|
25
|
-
* @param {IPostRequestParams} [params] - Query parameters.
|
|
26
|
-
* @returns {Promise<HTTPResponse>} Network response.
|
|
27
|
-
*/
|
|
28
|
-
post(t, e) {
|
|
29
|
-
return this._httpService.post(t, e);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Send a PUT request to the server.
|
|
33
|
-
* @param {string} url - The requested URL
|
|
34
|
-
* @param {IPostRequestParams} [params] - Query parameters
|
|
35
|
-
* @returns {Promise<HTTPResponse>} Network response
|
|
36
|
-
*/
|
|
37
|
-
put(t, e) {
|
|
38
|
-
return this._httpService.put(t, e);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Send DELETE request to the server.
|
|
42
|
-
* @param {string} url - The requested URL
|
|
43
|
-
* @param {IRequestParams} [params] - Query parameters
|
|
44
|
-
* @returns {Promise<HTTPResponse>} Network response
|
|
45
|
-
*/
|
|
46
|
-
delete(t, e) {
|
|
47
|
-
return this._httpService.delete(t, e);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Send PATCH request to the server.
|
|
51
|
-
* @param {string} url - The requested URL
|
|
52
|
-
* @param {IPostRequestParams} [params] - Query parameters
|
|
53
|
-
* @returns {Promise<HTTPResponse>} Network response
|
|
54
|
-
*/
|
|
55
|
-
patch(t, e) {
|
|
56
|
-
return this._httpService.patch(t, e);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Request for a stream of server-sent events. Instead of a single response, the server sends a stream of responses,
|
|
60
|
-
* Univer wraps the stream in an [`Observable`](https://rxjs.dev/guide/observable) which you can call `subscribe` on.
|
|
61
|
-
* @param {HTTPRequestMethod} method - HTTP request method
|
|
62
|
-
* @param {string} url - The requested URL
|
|
63
|
-
* @param {IPostRequestParams} [params] - params Query parameters
|
|
64
|
-
* @returns {Observable<HTTPEvent>} An observable that emits the network response.
|
|
65
|
-
*/
|
|
66
|
-
getSSE(t, e, c) {
|
|
67
|
-
return this._httpService.getSSE(t, e, c);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
n = l([
|
|
71
|
-
a(0, h(u)),
|
|
72
|
-
a(1, h(S))
|
|
73
|
-
], n);
|
|
74
|
-
class f extends p {
|
|
75
|
-
getNetwork() {
|
|
76
|
-
return this._injector.createInstance(n);
|
|
77
|
-
}
|
|
78
|
-
createSocket(e) {
|
|
79
|
-
const r = this._injector.createInstance(_).createSocket(e);
|
|
80
|
-
if (!r)
|
|
81
|
-
throw new Error("[WebSocketService]: failed to create socket!");
|
|
82
|
-
return r;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
p.extend(f);
|
|
1
|
+
import{FBase as e,FUniver as t}from"@univerjs/core/facade";import{HTTPService as n,WebSocketService as r}from"@univerjs/network";import{Inject as i,Injector as a}from"@univerjs/core";function o(e,t){return function(n,r){t(n,r,e)}}function s(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let c=class extends e{constructor(e,t){super(),this._injector=e,this._httpService=t}get(e,t){return this._httpService.get(e,t)}post(e,t){return this._httpService.post(e,t)}put(e,t){return this._httpService.put(e,t)}delete(e,t){return this._httpService.delete(e,t)}patch(e,t){return this._httpService.patch(e,t)}getSSE(e,t,n){return this._httpService.getSSE(e,t,n)}};c=s([o(0,i(a)),o(1,i(n))],c);var l=class extends t{getNetwork(){return this._injector.createInstance(c)}createSocket(e){let t=this._injector.createInstance(r).createSocket(e);if(!t)throw Error(`[WebSocketService]: failed to create socket!`);return t}};t.extend(l);export{};
|