@univerjs/network 0.1.15 → 0.1.17
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 +1 -1
- package/lib/es/index.js +2 -3
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var O=Object.defineProperty;var D=(e,t,r)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var p=(e,t,r)=>
|
|
1
|
+
"use strict";var O=Object.defineProperty;var D=(e,t,r)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var p=(e,t,r)=>D(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),y=require("rxjs"),g=require("rxjs/operators"),q=require("@wendellhu/redi"),L="application/json";class E{constructor(t){p(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,i)=>{t[i]=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
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 F=q.createIdentifier("network.http-implementation");class A{constructor(t){this.params=t}toString(){return this.params?Object.keys(this.params).map(t=>`${t}=${this.params[t]}`).join("&"):""}}let M=0;class I{constructor(t,r,n){p(this,"uid",M++);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:L,r=(s=this.requestParams)==null?void 0:s.body;return t===L&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}var j=Object.defineProperty,B=Object.getOwnPropertyDescriptor,$=(e,t,r,n)=>{for(var s=n>1?void 0:n?B(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(n?o(t,r,s):o(s))||s);return n&&s&&j(t,r,s),s},G=(e,t)=>(r,n)=>t(r,n,e);exports.HTTPService=class extends m.Disposable{constructor(r){super();p(this,"_interceptors",[]);p(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 i,o;return((i=n.priority)!=null?i:0)-((o=s.priority)!=null?o:0)}),this._pipe=null,m.toDisposable(()=>m.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 c,l;const i=new E(s==null?void 0:s.headers),o=new A(s==null?void 0:s.params),a=new I(r,n,{headers:i,params:o,withCredentials:(c=s==null?void 0:s.withCredentials)!=null?c:!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(g.concatMap(h=>this._runInterceptorsAndImplementation(h)))}async _request(r,n,s){var h,u;const i=new E(s==null?void 0:s.headers),o=new A(s==null?void 0:s.params),a=new I(r,n,{headers:i,params:o,withCredentials:(h=s==null?void 0:s.withCredentials)!=null?h:!1,responseType:(u=s==null?void 0:s.responseType)!=null?u:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),c=y.of(a).pipe(g.concatMap(d=>this._runInterceptorsAndImplementation(d)));return await y.firstValueFrom(c)}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(n=>n.interceptor).reduceRight((n,s)=>V(n,s),(n,s)=>s(n))),this._pipe(r,n=>this._http.send(n))}};exports.HTTPService=$([G(0,F)],exports.HTTPService);function V(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 x{constructor({body:t,headers:r,status:n,statusText:s}){p(this,"type",1);p(this,"body");p(this,"headers");p(this,"status");p(this,"statusText");this.body=t,this.headers=r,this.status=n,this.statusText=s}}class U{constructor(t,r,n){p(this,"type",0);this.total=t,this.loaded=r,this.partialText=n}}class k{constructor(t,r,n){this.headers=t,this.status=r,this.statusText=n}}class w{constructor({headers:t,status:r,statusText:n,error:s}){p(this,"headers");p(this,"status");p(this,"statusText");p(this,"error");this.headers=t,this.status=r,this.statusText=n,this.error=s}}const W=200,X=300;var _=(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))(_||{});class z{send(t){return new y.Observable(r=>{const n=new AbortController;return this._send(t,r,n).then(()=>{},s=>{r.error(new w({error:s}))}),()=>n.abort()})}async _send(t,r,n){var h,u;let s;try{const d=this._parseFetchParamsFromRequest(t);s=await fetch(t.getUrlWithParams(),{signal:n.signal,...d})}catch(d){r.error(new w({error:d,status:(h=d.status)!=null?h:0,statusText:(u=d.statusText)!=null?u:"Unknown Error",headers:d.headers}));return}const i=new E(s.headers),o=s.status,a=s.statusText;let c=null;s.body&&(c=await this._readBody(t,s,r)),o>=_.Ok&&o<_.MultipleChoices?r.next(new x({body:c,headers:i,status:o,statusText:a})):r.error(new w({error:c,status:o,statusText:a,headers:i})),r.complete()}async _readBody(t,r,n){var v,R;const s=[],i=r.body.getReader(),o=r.headers.get("content-length");let a=0;const c=(v=t.requestParams)==null?void 0:v.reportProgress,l=t.responseType;let h,u;for(;;){const{done:f,value:b}=await i.read();if(f)break;s.push(b),a+=b.length,c&&l==="text"&&(h=(h!=null?h:"")+(u!=null?u:u=new TextDecoder).decode(b,{stream:!0}),n.next(new U(o?Number.parseInt(o,10):void 0,a,h)))}const d=J(s,a);try{const f=(R=r.headers.get("content-type"))!=null?R:"";return K(t,d,f)}catch(f){return n.error(new w({error:f,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 J(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 Y=/^\)\]\}',?\n/;function K(e,t,r){switch(e.responseType){case"json":const n=new TextDecoder().decode(t).replace(Y,"");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 Q{send(t){return new y.Observable(r=>{const n=new XMLHttpRequest;n.open(t.method,t.getUrlWithParams()),t.withCredentials&&(n.withCredentials=!0),t.headers.forEach((c,l)=>n.setRequestHeader(c,l.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 c=n.statusText||"OK",l=new E(n.getAllResponseHeaders());return new k(l,n.status,c)},i=()=>{const{headers:c,statusText:l,status:h}=s(),{responseType:u}=t;let d=null,v=null;h!==_.NoContent&&(d=typeof n.response>"u"?n.responseText:n.response);let R=h>=W&&h<X;if(u==="json"&&typeof d=="string"){const f=d;try{d=d?JSON.parse(d):null}catch(b){R=!1,d=f,v=b}}R?r.next(new x({body:d,headers:c,status:h,statusText:l})):r.error(new w({error:v,headers:c,status:h,statusText:l}))},o=c=>{const l=new w({error:c,status:n.status||0,statusText:n.statusText||"Unknown Error",headers:s().headers});r.error(l)};n.addEventListener("load",i),n.addEventListener("error",o),n.addEventListener("abort",o),n.addEventListener("timeout",o);const a=t.getBody();return n.send(a),()=>{n.readyState!==n.DONE&&n.abort(),n.removeEventListener("load",i),n.removeEventListener("error",o),n.removeEventListener("abort",o),n.removeEventListener("timeout",o)}})}}const Z=q.createIdentifier("univer.socket");class P extends m.Disposable{createSocket(t){try{const r=new WebSocket(t),n=new m.DisposableCollection;return{URL:t,close:(i,o)=>{r.close(i,o),n.dispose()},send:i=>{r.send(i)},open$:new y.Observable(i=>{const o=a=>i.next(a);r.addEventListener("open",o),n.add(m.toDisposable(()=>r.removeEventListener("open",o)))}).pipe(g.share()),close$:new y.Observable(i=>{const o=a=>i.next(a);r.addEventListener("close",o),n.add(m.toDisposable(()=>r.removeEventListener("close",o)))}).pipe(g.share()),error$:new y.Observable(i=>{const o=a=>i.next(a);r.addEventListener("error",o),n.add(m.toDisposable(()=>r.removeEventListener("error",o)))}).pipe(g.share()),message$:new y.Observable(i=>{const o=a=>i.next(a);r.addEventListener("message",o),n.add(m.toDisposable(()=>r.removeEventListener("message",o)))}).pipe(g.share())}}catch(r){return console.error(r),null}}}const H=3,S=1e3,C=(e,t)=>{var s,i;const r=(s=t==null?void 0:t.maxRetryAttempts)!=null?s:H,n=(i=t==null?void 0:t.delayInterval)!=null?i:S;return(o,a)=>a(o).pipe(g.retry({delay:n,count:r}))},T=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 i=t.shift();r.add(i),i()}};return(s,i)=>new y.Observable(o=>{const a=()=>i(s).subscribe({next:l=>o.next(l),error:l=>o.next(l),complete:()=>o.complete()}),c=()=>{r.delete(a),m.remove(t,a),n()};return t.push(a),n(),c})},ee=e=>{const{errorStatusCodes:t,onAuthError:r}=e;return(s,i)=>i(s).pipe(y.catchError(o=>(o instanceof w&&t.some(a=>a===o.status)&&r(),y.throwError(()=>o))))};exports.AuthInterceptorFactory=ee;exports.FetchHTTPImplementation=z;exports.HTTPEventType=N;exports.HTTPHeaders=E;exports.HTTPProgress=U;exports.HTTPRequest=I;exports.HTTPResponse=x;exports.HTTPResponseError=w;exports.HTTPStatusCode=_;exports.IHTTPImplementation=F;exports.ISocketService=Z;exports.ResponseHeader=k;exports.RetryInterceptorFactory=C;exports.ThresholdInterceptorFactory=T;exports.WebSocketService=P;exports.XHRHTTPImplementation=Q;
|
package/lib/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var D = Object.defineProperty;
|
|
2
2
|
var O = (e, r, n) => r in e ? D(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n;
|
|
3
|
-
var p = (e, r, n) =>
|
|
3
|
+
var p = (e, r, n) => O(e, typeof r != "symbol" ? r + "" : r, n);
|
|
4
4
|
import { Disposable as q, toDisposable as _, remove as U, DisposableCollection as j } from "@univerjs/core";
|
|
5
5
|
import { of as b, firstValueFrom as B, Observable as u, catchError as $, throwError as G } from "rxjs";
|
|
6
6
|
import { concatMap as I, share as v, retry as V } from "rxjs/operators";
|
|
@@ -266,8 +266,7 @@ class le {
|
|
|
266
266
|
let h, y;
|
|
267
267
|
for (; ; ) {
|
|
268
268
|
const { done: m, value: g } = await o.read();
|
|
269
|
-
if (m)
|
|
270
|
-
break;
|
|
269
|
+
if (m) break;
|
|
271
270
|
s.push(g), a += g.length, c && l === "text" && (h = (h != null ? h : "") + (y != null ? y : y = new TextDecoder()).decode(g, { stream: !0 }), t.next(new P(
|
|
272
271
|
i ? Number.parseInt(i, 10) : void 0,
|
|
273
272
|
a,
|
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(o,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("rxjs"),require("rxjs/operators"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","rxjs/operators","@wendellhu/redi"],l):(o=typeof globalThis<"u"?globalThis:o||self,l(o.UniverNetwork={},o.UniverCore,o.rxjs,o.rxjs.operators,o["@wendellhu/redi"]))})(this,function(o,l,y,g,q){"use strict";var ee=Object.defineProperty;var re=(o,l,y)=>l in o?ee(o,l,{enumerable:!0,configurable:!0,writable:!0,value:y}):o[l]=y;var m=(o,l,y)=>
|
|
1
|
+
(function(o,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("rxjs"),require("rxjs/operators"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","rxjs/operators","@wendellhu/redi"],l):(o=typeof globalThis<"u"?globalThis:o||self,l(o.UniverNetwork={},o.UniverCore,o.rxjs,o.rxjs.operators,o["@wendellhu/redi"]))})(this,function(o,l,y,g,q){"use strict";var ee=Object.defineProperty;var re=(o,l,y)=>l in o?ee(o,l,{enumerable:!0,configurable:!0,writable:!0,value:y}):o[l]=y;var m=(o,l,y)=>re(o,typeof l!="symbol"?l+"":l,y);const F="application/json";class E{constructor(n){m(this,"_headers",new Map);typeof n=="string"?this._handleHeadersString(n):n instanceof Headers?this._handleHeaders(n):n&&this._handleHeadersConstructorProps(n)}forEach(n){this._headers.forEach((t,r)=>n(r,t))}has(n){return!!this._headers.has(n.toLowerCase())}get(n){const t=n.toLowerCase();return this._headers.has(t)?this._headers.get(t):null}toHeadersInit(){var t,r;const n={};return this._headers.forEach((s,a)=>{n[a]=s.join(",")}),(t=n.accept)!=null||(n.accept="application/json, text/plain, */*"),(r=n["content-type"])!=null||(n["content-type"]="application/json;charset=UTF-8"),n}_setHeader(n,t){const r=n.toLowerCase();this._headers.has(r)?this._headers.get(r).push(t.toString()):this._headers.set(r,[t.toString()])}_handleHeadersString(n){n.split(`
|
|
2
2
|
`).forEach(t=>{const[r,s]=t.split(":");r&&s&&this._setHeader(r,s)})}_handleHeadersConstructorProps(n){Object.entries(n).forEach(([t,r])=>this._setHeader(t,r))}_handleHeaders(n){n.forEach((t,r)=>this._setHeader(r,t))}}const N=q.createIdentifier("network.http-implementation");class U{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>`${n}=${this.params[n]}`).join("&"):""}}let D=0;class L{constructor(n,t,r){m(this,"uid",D++);this.method=n,this.url=t,this.requestParams=r}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var t,r;const n=(r=(t=this.requestParams)==null?void 0:t.params)==null?void 0:r.toString();return n?`${this.url}${this.url.includes("?")?"&":"?"}${n}`:this.url}getBody(){var r,s;const n=(r=this.headers.get("Content-Type"))!=null?r:F,t=(s=this.requestParams)==null?void 0:s.body;return n===F&&t&&typeof t=="object"?JSON.stringify(t):t?`${t}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}var M=Object.defineProperty,j=Object.getOwnPropertyDescriptor,B=(e,n,t,r)=>{for(var s=r>1?void 0:r?j(n,t):n,a=e.length-1,i;a>=0;a--)(i=e[a])&&(s=(r?i(n,t,s):i(s))||s);return r&&s&&M(n,t,s),s},$=(e,n)=>(t,r)=>n(t,r,e);o.HTTPService=class extends l.Disposable{constructor(t){super();m(this,"_interceptors",[]);m(this,"_pipe");this._http=t}registerHTTPInterceptor(t){if(this._interceptors.indexOf(t)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(t),this._interceptors=this._interceptors.sort((r,s)=>{var a,i;return((a=r.priority)!=null?a:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,l.toDisposable(()=>l.remove(this._interceptors,t))}get(t,r){return this._request("GET",t,r)}post(t,r){return this._request("POST",t,r)}put(t,r){return this._request("PUT",t,r)}delete(t,r){return this._request("DELETE",t,r)}patch(t,r){return this._request("PATCH",t,r)}getSSE(t,r,s){var h,d;const a=new E(s==null?void 0:s.headers),i=new U(s==null?void 0:s.params),c=new L(t,r,{headers:a,params:i,withCredentials:(h=s==null?void 0:s.withCredentials)!=null?h:!1,reportProgress:!0,responseType:(d=s==null?void 0:s.responseType)!=null?d:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body});return y.of(c).pipe(g.concatMap(p=>this._runInterceptorsAndImplementation(p)))}async _request(t,r,s){var p,f;const a=new E(s==null?void 0:s.headers),i=new U(s==null?void 0:s.params),c=new L(t,r,{headers:a,params:i,withCredentials:(p=s==null?void 0:s.withCredentials)!=null?p:!1,responseType:(f=s==null?void 0:s.responseType)!=null?f:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body}),h=y.of(c).pipe(g.concatMap(u=>this._runInterceptorsAndImplementation(u)));return await y.firstValueFrom(h)}_runInterceptorsAndImplementation(t){return this._pipe||(this._pipe=this._interceptors.map(r=>r.interceptor).reduceRight((r,s)=>G(r,s),(r,s)=>s(r))),this._pipe(t,r=>this._http.send(r))}},o.HTTPService=B([$(0,N)],o.HTTPService);function G(e,n){return(t,r)=>n(t,s=>e(s,r))}var x=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(x||{});class A{constructor({body:n,headers:t,status:r,statusText:s}){m(this,"type",1);m(this,"body");m(this,"headers");m(this,"status");m(this,"statusText");this.body=n,this.headers=t,this.status=r,this.statusText=s}}class k{constructor(n,t,r){m(this,"type",0);this.total=n,this.loaded=t,this.partialText=r}}class O{constructor(n,t,r){this.headers=n,this.status=t,this.statusText=r}}class w{constructor({headers:n,status:t,statusText:r,error:s}){m(this,"headers");m(this,"status");m(this,"statusText");m(this,"error");this.headers=n,this.status=t,this.statusText=r,this.error=s}}const V=200,W=300;var _=(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))(_||{});class X{send(n){return new y.Observable(t=>{const r=new AbortController;return this._send(n,t,r).then(()=>{},s=>{t.error(new w({error:s}))}),()=>r.abort()})}async _send(n,t,r){var p,f;let s;try{const u=this._parseFetchParamsFromRequest(n);s=await fetch(n.getUrlWithParams(),{signal:r.signal,...u})}catch(u){t.error(new w({error:u,status:(p=u.status)!=null?p:0,statusText:(f=u.statusText)!=null?f:"Unknown Error",headers:u.headers}));return}const a=new E(s.headers),i=s.status,c=s.statusText;let h=null;s.body&&(h=await this._readBody(n,s,t)),i>=_.Ok&&i<_.MultipleChoices?t.next(new A({body:h,headers:a,status:i,statusText:c})):t.error(new w({error:h,status:i,statusText:c,headers:a})),t.complete()}async _readBody(n,t,r){var R,I;const s=[],a=t.body.getReader(),i=t.headers.get("content-length");let c=0;const h=(R=n.requestParams)==null?void 0:R.reportProgress,d=n.responseType;let p,f;for(;;){const{done:v,value:b}=await a.read();if(v)break;s.push(b),c+=b.length,h&&d==="text"&&(p=(p!=null?p:"")+(f!=null?f:f=new TextDecoder).decode(b,{stream:!0}),r.next(new k(i?Number.parseInt(i,10):void 0,c,p)))}const u=z(s,c);try{const v=(I=t.headers.get("content-type"))!=null?I:"";return Y(n,u,v)}catch(v){return r.error(new w({error:v,status:t.status,statusText:t.statusText,headers:new E(t.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 t=new Uint8Array(n);let r=0;for(const s of e)t.set(s,r),r+=s.length;return t}const J=/^\)\]\}',?\n/;function Y(e,n,t){switch(e.responseType){case"json":const r=new TextDecoder().decode(n).replace(J,"");return r===""?null:JSON.parse(r);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:t});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class K{send(n){return new y.Observable(t=>{const r=new XMLHttpRequest;r.open(n.method,n.getUrlWithParams()),n.withCredentials&&(r.withCredentials=!0),n.headers.forEach((h,d)=>r.setRequestHeader(h,d.join(","))),n.headers.has("Accept")||r.setRequestHeader("Accept","application/json, text/plain, */*"),n.headers.has("Content-Type")||r.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const h=r.statusText||"OK",d=new E(r.getAllResponseHeaders());return new O(d,r.status,h)},a=()=>{const{headers:h,statusText:d,status:p}=s(),{responseType:f}=n;let u=null,R=null;p!==_.NoContent&&(u=typeof r.response>"u"?r.responseText:r.response);let I=p>=V&&p<W;if(f==="json"&&typeof u=="string"){const v=u;try{u=u?JSON.parse(u):null}catch(b){I=!1,u=v,R=b}}I?t.next(new A({body:u,headers:h,status:p,statusText:d})):t.error(new w({error:R,headers:h,status:p,statusText:d}))},i=h=>{const d=new w({error:h,status:r.status||0,statusText:r.statusText||"Unknown Error",headers:s().headers});t.error(d)};r.addEventListener("load",a),r.addEventListener("error",i),r.addEventListener("abort",i),r.addEventListener("timeout",i);const c=n.getBody();return r.send(c),()=>{r.readyState!==r.DONE&&r.abort(),r.removeEventListener("load",a),r.removeEventListener("error",i),r.removeEventListener("abort",i),r.removeEventListener("timeout",i)}})}}const Q=q.createIdentifier("univer.socket");class Z extends l.Disposable{createSocket(n){try{const t=new WebSocket(n),r=new l.DisposableCollection;return{URL:n,close:(a,i)=>{t.close(a,i),r.dispose()},send:a=>{t.send(a)},open$:new y.Observable(a=>{const i=c=>a.next(c);t.addEventListener("open",i),r.add(l.toDisposable(()=>t.removeEventListener("open",i)))}).pipe(g.share()),close$:new y.Observable(a=>{const i=c=>a.next(c);t.addEventListener("close",i),r.add(l.toDisposable(()=>t.removeEventListener("close",i)))}).pipe(g.share()),error$:new y.Observable(a=>{const i=c=>a.next(c);t.addEventListener("error",i),r.add(l.toDisposable(()=>t.removeEventListener("error",i)))}).pipe(g.share()),message$:new y.Observable(a=>{const i=c=>a.next(c);t.addEventListener("message",i),r.add(l.toDisposable(()=>t.removeEventListener("message",i)))}).pipe(g.share())}}catch(t){return console.error(t),null}}}const P=3,H=1e3,S=(e,n)=>{var s,a;const t=(s=n==null?void 0:n.maxRetryAttempts)!=null?s:P,r=(a=n==null?void 0:n.delayInterval)!=null?a:H;return(i,c)=>c(i).pipe(g.retry({delay:r,count:t}))},C=e=>{const n=[],t=new Set,r=()=>{var s;for(;t.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&n.length>0;){const a=n.shift();t.add(a),a()}};return(s,a)=>new y.Observable(i=>{const c=()=>a(s).subscribe({next:d=>i.next(d),error:d=>i.next(d),complete:()=>i.complete()}),h=()=>{t.delete(c),l.remove(n,c),r()};return n.push(c),r(),h})},T=e=>{const{errorStatusCodes:n,onAuthError:t}=e;return(s,a)=>a(s).pipe(y.catchError(i=>(i instanceof w&&n.some(c=>c===i.status)&&t(),y.throwError(()=>i))))};o.AuthInterceptorFactory=T,o.FetchHTTPImplementation=X,o.HTTPEventType=x,o.HTTPHeaders=E,o.HTTPProgress=k,o.HTTPRequest=L,o.HTTPResponse=A,o.HTTPResponseError=w,o.HTTPStatusCode=_,o.IHTTPImplementation=N,o.ISocketService=Q,o.ResponseHeader=O,o.RetryInterceptorFactory=S,o.ThresholdInterceptorFactory=C,o.WebSocketService=Z,o.XHRHTTPImplementation=K,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/network",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -47,16 +47,16 @@
|
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@wendellhu/redi": "0.15.4",
|
|
49
49
|
"rxjs": ">=7.0.0",
|
|
50
|
-
"@univerjs/core": "0.1.
|
|
50
|
+
"@univerjs/core": "0.1.17"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@wendellhu/redi": "0.15.4",
|
|
54
54
|
"rxjs": "^7.8.1",
|
|
55
55
|
"typescript": "^5.4.5",
|
|
56
|
-
"vite": "^5.
|
|
56
|
+
"vite": "^5.3.1",
|
|
57
57
|
"vitest": "^1.6.0",
|
|
58
|
-
"@univerjs/core": "0.1.
|
|
59
|
-
"@univerjs/shared": "0.1.
|
|
58
|
+
"@univerjs/core": "0.1.17",
|
|
59
|
+
"@univerjs/shared": "0.1.17"
|
|
60
60
|
},
|
|
61
61
|
"univerSpace": {
|
|
62
62
|
".": {
|