@univerjs/network 0.5.1 → 0.5.2

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.
@@ -0,0 +1,52 @@
1
+ import { HTTPEvent, HTTPRequestMethod, HTTPResponse, IPostRequestParams, IRequestParams, HTTPService } from '@univerjs/network';
2
+ import { Observable } from 'rxjs';
3
+ import { FBase, Injector } from '@univerjs/core';
4
+ export declare class FNetwork extends FBase {
5
+ protected readonly _injector: Injector;
6
+ protected readonly _httpService: HTTPService;
7
+ constructor(_injector: Injector, _httpService: HTTPService);
8
+ /**
9
+ * Send GET request to the server.
10
+ * @param url The requested URL
11
+ * @param params Query parameters
12
+ * @returns Network response
13
+ */
14
+ get<T>(url: string, params?: IRequestParams): Promise<HTTPResponse<T>>;
15
+ /**
16
+ * Send POST request to the server.
17
+ * @param url The requested URL
18
+ * @param params Query parameters
19
+ * @returns Network response
20
+ */
21
+ post<T>(url: string, params?: IPostRequestParams): Promise<HTTPResponse<T>>;
22
+ /**
23
+ * Send PUT request to the server.
24
+ * @param url The requested URL
25
+ * @param params Query parameters
26
+ * @returns Network response
27
+ */
28
+ put<T>(url: string, params?: IPostRequestParams): Promise<HTTPResponse<T>>;
29
+ /**
30
+ * Send DELETE request to the server.
31
+ * @param url The requested URL
32
+ * @param params Query parameters
33
+ * @returns Network response
34
+ */
35
+ delete<T>(url: string, params?: IRequestParams): Promise<HTTPResponse<T>>;
36
+ /**
37
+ * Send PATCH request to the server.
38
+ * @param url The requested URL
39
+ * @param params Query parameters
40
+ * @returns Network response
41
+ */
42
+ patch<T>(url: string, params?: IPostRequestParams): Promise<HTTPResponse<T>>;
43
+ /**
44
+ * Request for a stream of server-sent events. Instead of a single response, the server sends a stream of responses,
45
+ * Univer wraps the stream in an [`Observable`](https://rxjs.dev/guide/observable) which you can call `subscribe` on.
46
+ * @param method HTTP request method
47
+ * @param url The requested URL
48
+ * @param params Query parameters
49
+ * @returns An observable that emits the network response
50
+ */
51
+ getSSE<T>(method: HTTPRequestMethod, url: string, params?: IPostRequestParams): Observable<HTTPEvent<T>>;
52
+ }
@@ -0,0 +1,16 @@
1
+ import { FUniver } from '@univerjs/core';
2
+ import { FNetwork } from './f-network';
3
+ interface IFUniverNetworkMixin {
4
+ /**
5
+ * Get the network API of Univer, with the help of which you can send HTTP requests.
6
+ */
7
+ getNetwork(): FNetwork;
8
+ }
9
+ export declare class FUniverNetworkMixin extends FUniver implements IFUniverNetworkMixin {
10
+ getNetwork(): FNetwork;
11
+ }
12
+ declare module '@univerjs/core' {
13
+ interface FUniver extends IFUniverNetworkMixin {
14
+ }
15
+ }
16
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import './f-univer';
17
+ import './f-network';
18
+ export type { FNetwork } from './f-network';
@@ -1,5 +1,9 @@
1
- import { DependencyOverride, Injector, Plugin } from '@univerjs/core';
1
+ import { DependencyOverride, ILogService, Injector, Plugin } from '@univerjs/core';
2
2
  export interface IUniverNetworkPluginConfig {
3
+ /**
4
+ * Use fetch instead of XMLHttpRequest. By default, Univer will use fetch on Node.js and XMLHttpRequest in browser.
5
+ */
6
+ useFetchImpl?: boolean;
3
7
  /**
4
8
  * Build in dependencies that can be overridden:
5
9
  *
@@ -7,14 +11,20 @@ export interface IUniverNetworkPluginConfig {
7
11
  * - {@link IHTTPImplementation}
8
12
  */
9
13
  override?: DependencyOverride;
14
+ /**
15
+ * Force to use a new instance of {@link HTTPService} and {@link IHTTPImplementation} even if
16
+ * an ancestor injector already has them registered.
17
+ */
18
+ forceUseNewInstance?: boolean;
10
19
  }
11
20
  /**
12
21
  * This plugin add network services to the Univer instance.
13
22
  */
14
23
  export declare class UniverNetworkPlugin extends Plugin {
15
24
  private readonly _config;
25
+ private readonly _logger;
16
26
  protected readonly _injector: Injector;
17
27
  static pluginName: string;
18
- constructor(_config: Partial<IUniverNetworkPluginConfig> | undefined, _injector: Injector);
28
+ constructor(_config: Partial<IUniverNetworkPluginConfig> | undefined, _logger: ILogService, _injector: Injector);
19
29
  onStarting(): void;
20
30
  }
@@ -1,10 +1,10 @@
1
1
  import { IDisposable, Disposable } from '@univerjs/core';
2
2
  import { Observable } from 'rxjs';
3
3
  import { HTTPResponseType } from './http';
4
- import { IHTTPImplementation } from './implementations/implementation';
4
+ import { HTTPInterceptorFn } from './interceptor';
5
5
  import { HTTPRequestMethod } from './request';
6
6
  import { HTTPEvent } from './response';
7
- import { HTTPInterceptorFn } from './interceptor';
7
+ import { IHTTPImplementation } from './implementations/implementation';
8
8
  export interface IRequestParams {
9
9
  /** Query params. These params would be append to the url before the request is sent. */
10
10
  params?: {
@@ -60,8 +60,8 @@ export declare class HTTPService extends Disposable {
60
60
  post<T>(url: string, params?: IPostRequestParams): Promise<HTTPEvent<T>>;
61
61
  put<T>(url: string, params?: IPostRequestParams): Promise<HTTPEvent<T>>;
62
62
  delete<T>(url: string, params?: IRequestParams): Promise<HTTPEvent<T>>;
63
- patch<T>(url: string, options?: IPostRequestParams): Promise<HTTPEvent<T>>;
64
- getSSE<T>(method: HTTPRequestMethod, url: string, options?: IPostRequestParams): Observable<HTTPEvent<T>>;
63
+ patch<T>(url: string, params?: IPostRequestParams): Promise<HTTPEvent<T>>;
64
+ getSSE<T>(method: HTTPRequestMethod, url: string, _params?: IPostRequestParams): Observable<HTTPEvent<T>>;
65
65
  /** The HTTP request implementations */
66
66
  private _request;
67
67
  private _runInterceptorsAndImplementation;
@@ -1,15 +1,17 @@
1
- import { Observable } from 'rxjs';
2
1
  import { HTTPRequest } from '../request';
3
2
  import { HTTPEvent } from '../response';
4
3
  import { IHTTPImplementation } from './implementation';
4
+ import { ILogService } from '@univerjs/core';
5
+ import { Observable } from 'rxjs';
5
6
  /**
6
7
  * An HTTP implementation using Fetch API. This implementation can both run in browser and Node.js.
7
8
  *
8
9
  * It does not support streaming response yet (May 12, 2024).
9
10
  */
10
11
  export declare class FetchHTTPImplementation implements IHTTPImplementation {
12
+ private readonly _logService;
13
+ constructor(_logService: ILogService);
11
14
  send(request: HTTPRequest): Observable<HTTPEvent<any>>;
12
15
  private _send;
13
16
  private _readBody;
14
- private _parseFetchParamsFromRequest;
15
17
  }
@@ -0,0 +1,2 @@
1
+ import { HTTPRequest } from '../request';
2
+ export declare function parseFetchParamsFromRequest(request: HTTPRequest): RequestInit;
@@ -1,10 +1,13 @@
1
- import { Observable } from 'rxjs';
2
1
  import { HTTPRequest } from '../request';
3
2
  import { HTTPEvent } from '../response';
4
3
  import { IHTTPImplementation } from './implementation';
4
+ import { ILogService } from '@univerjs/core';
5
+ import { Observable } from 'rxjs';
5
6
  /**
6
7
  * An HTTP implementation using XHR. HTTP service provided by this service could only be async (we do not support sync XHR now).
7
8
  */
8
9
  export declare class XHRHTTPImplementation implements IHTTPImplementation {
10
+ private readonly _logService;
11
+ constructor(_logService: ILogService);
9
12
  send(request: HTTPRequest): Observable<HTTPEvent<any>>;
10
13
  }
@@ -1,4 +1,5 @@
1
1
  import { HTTPHeaders } from './headers';
2
+ import { HTTPRequest } from './request';
2
3
  export type HTTPEvent<T> = HTTPResponse<T> | HTTPProgress;
3
4
  export declare enum HTTPEventType {
4
5
  DownloadProgress = 0,
@@ -68,11 +69,13 @@ export declare class ResponseHeader {
68
69
  constructor(headers: HTTPHeaders, status: number, statusText: string);
69
70
  }
70
71
  export declare class HTTPResponseError {
72
+ readonly request: HTTPRequest;
71
73
  readonly headers?: HTTPHeaders;
72
74
  readonly status?: number;
73
75
  readonly statusText?: string;
74
76
  readonly error: any;
75
- constructor({ headers, status, statusText, error, }: {
77
+ constructor({ request, headers, status, statusText, error, }: {
78
+ request: HTTPRequest;
76
79
  headers?: HTTPHeaders;
77
80
  status?: number;
78
81
  statusText?: string;
@@ -0,0 +1 @@
1
+ (function(r,u){typeof exports=="object"&&typeof module<"u"?u(require("@univerjs/core"),require("@univerjs/network")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/network"],u):(r=typeof globalThis<"u"?globalThis:r||self,u(r.UniverCore,r.UniverNetwork))})(this,function(r,u){"use strict";var o=Object.defineProperty,_=Object.getOwnPropertyDescriptor,f=(t,e,n,s)=>{for(var i=s>1?void 0:s?_(e,n):e,p=t.length-1,v;p>=0;p--)(v=t[p])&&(i=(s?v(e,n,i):v(i))||i);return s&&i&&o(e,n,i),i},h=(t,e)=>(n,s)=>e(n,s,t);let c=class extends r.FBase{constructor(t,e){super(),this._injector=t,this._httpService=e}get(t,e){return this._httpService.get(t,e)}post(t,e){return this._httpService.post(t,e)}put(t,e){return this._httpService.put(t,e)}delete(t,e){return this._httpService.delete(t,e)}patch(t,e){return this._httpService.patch(t,e)}getSSE(t,e,n){return this._httpService.getSSE(t,e,n)}};c=f([h(0,r.Inject(r.Injector)),h(1,r.Inject(u.HTTPService))],c);class d extends r.FUniver{getNetwork(){return this._injector.createInstance(c)}}r.FUniver.extend(d)});
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("rxjs"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","rxjs/operators"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a.UniverNetwork={},a.UniverCore,a.rxjs,a.rxjs.operators))})(this,function(a,l,y,R){"use strict";var pe=Object.defineProperty;var ue=(a,l,y)=>l in a?pe(a,l,{enumerable:!0,configurable:!0,writable:!0,value:y}):a[l]=y;var g=(a,l,y)=>ue(a,typeof l!="symbol"?l+"":l,y);var q;const x="application/json";class E{constructor(n){g(this,"_headers",new Map);typeof n=="string"?this._handleHeadersString(n):n instanceof Headers?this._handleHeaders(n):n&&this._handleHeadersConstructorProps(n)}forEach(n){this._headers.forEach((r,t)=>n(t,r))}has(n){return!!this._headers.has(n.toLowerCase())}get(n){const r=n.toLowerCase();return this._headers.has(r)?this._headers.get(r):null}set(n,r){this._setHeader(n,r)}toHeadersInit(){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 A=l.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 W=0;class U{constructor(n,r,t){g(this,"uid",W++);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:x,r=(s=this.requestParams)==null?void 0:s.body;return n===x&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}var V=Object.defineProperty,X=Object.getOwnPropertyDescriptor,z=(e,n,r,t)=>{for(var s=t>1?void 0:t?X(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},J=(e,n)=>(r,t)=>n(r,t,e);a.HTTPService=class extends l.Disposable{constructor(r){super();g(this,"_interceptors",[]);g(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,l.toDisposable(()=>l.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,h;const o=new E(s==null?void 0:s.headers),i=new M(s==null?void 0:s.params),c=new U(r,t,{headers:o,params:i,withCredentials:(p=s==null?void 0:s.withCredentials)!=null?p:!1,reportProgress:!0,responseType:(h=s==null?void 0:s.responseType)!=null?h:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body});return y.of(c).pipe(R.concatMap(d=>this._runInterceptorsAndImplementation(d)))}async _request(r,t,s){var d,f;const o=new E(s==null?void 0:s.headers),i=new M(s==null?void 0:s.params),c=new U(r,t,{headers:o,params:i,withCredentials:(d=s==null?void 0:s.withCredentials)!=null?d:!1,responseType:(f=s==null?void 0:s.responseType)!=null?f:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),p=y.of(c).pipe(R.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)=>K(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}},a.HTTPService=z([J(0,A)],a.HTTPService);function K(e,n){return(r,t)=>n(r,s=>e(s,t))}const Y=200,Q=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||{}),O=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(O||{});class N{constructor({body:n,headers:r,status:t,statusText:s}){g(this,"type",1);g(this,"body");g(this,"headers");g(this,"status");g(this,"statusText");this.body=n,this.headers=r,this.status=t,this.statusText=s}}class j{constructor(n,r,t){g(this,"type",0);this.total=n,this.loaded=r,this.partialText=t}}class ${constructor(n,r,t){this.headers=n,this.status=r,this.statusText=t}}class b{constructor({headers:n,status:r,statusText:t,error:s}){g(this,"headers");g(this,"status");g(this,"statusText");g(this,"error");this.headers=n,this.status=r,this.statusText=t,this.error=s}}class B{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,h)=>t.setRequestHeader(p,h.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",h=new E(t.getAllResponseHeaders());return new $(h,t.status,p)},o=()=>{const{headers:p,statusText:h,status:d}=s(),{responseType:f}=n;let u=null,v=null;d!==I.NoContent&&(u=typeof t.response>"u"?t.responseText:t.response);let w=d>=Y&&d<Q;if(f==="json"&&typeof u=="string"){const _=u;try{u=u?JSON.parse(u):null}catch(m){w=!1,u=_,v=m}}w?r.next(new N({body:u,headers:p,status:d,statusText:h})):r.error(new b({error:v,headers:p,status:d,statusText:h}))},i=p=>{const h=new b({error:p,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:s().headers});r.error(h)};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)}})}}var Z=Object.defineProperty,P=Object.getOwnPropertyDescriptor,H=(e,n,r,t)=>{for(var s=t>1?void 0:t?P(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&&Z(n,r,s),s},S=(e,n)=>(r,t)=>n(r,t,e);a.UniverNetworkPlugin=(q=class extends l.Plugin{constructor(n=void 0,r){super(),this._config=n,this._injector=r}onStarting(){var n;l.registerDependencies(this._injector,l.mergeOverrideWithDependencies([[a.HTTPService],[A,{useClass:B}]],(n=this._config)==null?void 0:n.override))}},g(q,"pluginName","UNIVER_NETWORK_PLUGIN"),q),a.UniverNetworkPlugin=H([S(1,l.Inject(l.Injector))],a.UniverNetworkPlugin);class C{send(n){return new y.Observable(r=>{const t=new AbortController;return this._send(n,r,t).then(()=>{},s=>{r.error(new b({error:s}))}),()=>t.abort()})}async _send(n,r,t){var d,f;let s;try{const u=this._parseFetchParamsFromRequest(n);s=await fetch(n.getUrlWithParams(),{signal:t.signal,...u})}catch(u){r.error(new b({error:u,status:(d=u.status)!=null?d:0,statusText:(f=u.statusText)!=null?f:"Unknown Error",headers:u.headers}));return}const o=new E(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 N({body:p,headers:o,status:i,statusText:c})):r.error(new b({error:p,status:i,statusText:c,headers:o})),r.complete()}async _readBody(n,r,t){var v,w;const s=[],o=r.body.getReader(),i=r.headers.get("content-length");let c=0;const p=(v=n.requestParams)==null?void 0:v.reportProgress,h=n.responseType;let d,f;for(;;){const{done:_,value:m}=await o.read();if(_)break;s.push(m),c+=m.length,p&&h==="text"&&(d=(d!=null?d:"")+(f!=null?f:f=new TextDecoder).decode(m,{stream:!0}),t.next(new j(i?Number.parseInt(i,10):void 0,c,d)))}const u=T(s,c);try{const _=(w=r.headers.get("content-type"))!=null?w:"";return re(n,u,_)}catch(_){return t.error(new b({error:_,status:r.status,statusText:r.statusText,headers:new E(r.headers)})),null}}_parseFetchParamsFromRequest(n){return{method:n.method,headers:n.getHeadersInit(),body:n.getBody(),credentials:n.withCredentials?"include":void 0}}}function T(e,n){const r=new Uint8Array(n);let t=0;for(const s of e)r.set(s,t),t+=s.length;return r}const ee=/^\)\]\}',?\n/;function re(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(ee,"");return t===""?null:JSON.parse(t);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:r});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}const te=l.createIdentifier("univer.socket");class ne extends l.Disposable{createSocket(n){try{const r=new WebSocket(n),t=new l.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(l.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(R.share()),close$:new y.Observable(o=>{const i=c=>o.next(c);r.addEventListener("close",i),t.add(l.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(R.share()),error$:new y.Observable(o=>{const i=c=>o.next(c);r.addEventListener("error",i),t.add(l.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(R.share()),message$:new y.Observable(o=>{const i=c=>o.next(c);r.addEventListener("message",i),t.add(l.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(R.share())}}catch(r){return console.error(r),null}}}const se=3,ie=1e3,oe=e=>{var t,s;const n=(t=e==null?void 0:e.maxRetryAttempts)!=null?t:se,r=(s=e==null?void 0:e.delayInterval)!=null?s:ie;return(o,i)=>i(o).pipe(R.retry({delay:r,count:n}))},ae=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:h=>i.next(h),error:h=>i.error(h),complete:()=>i.complete()}),p=()=>{r.delete(c),l.remove(n,c),t()};return n.push(c),t(),p})},ce=e=>{const{errorStatusCodes:n,onAuthError:r}=e;return(s,o)=>o(s).pipe(y.catchError(i=>(i instanceof b&&n.some(c=>c===i.status)&&r(),y.throwError(()=>i))))},le=(e=300)=>{let r=()=>{};return t=>new Promise(s=>{r();const o=setTimeout(()=>{s(!0)},e);r=()=>{clearTimeout(o),s(!1)}})},he=()=>(e,n)=>n.map(r=>({config:r,result:e})),de=(e,n={})=>{const{isMatch:r,getParamsFromRequest:t,mergeParamsToRequest:s}=e,{fetchCheck:o=le(300),distributeResult:i=he()}=n,c=[],p=h=>h.map(d=>d.config);return(h,d)=>r(h)?new y.Observable(f=>{const u=t(h);c.push({next:w=>f.next(w),error:w=>f.error(w),config:u});const v=p(c);o(h).then(w=>{if(w){const _=[];v.forEach(m=>{const F=c.findIndex(L=>L.config===m);if(F>=0){const[L]=c.splice(F,1);_.push(L)}}),d(s(v,h)).subscribe({next:m=>{if(m.type===O.Response){const F=m.body,L=i(F,v);_.forEach(D=>{const G=L.find(k=>k.config===D.config);if(G){const k=new N({body:G.result,headers:m.headers,status:m.status,statusText:m.statusText});D.next(k)}else D.error("batch error")})}},complete:()=>f.complete(),error:m=>f.error(m)})}})}):d(h)};a.AuthInterceptorFactory=ce,a.FetchHTTPImplementation=C,a.HTTPEventType=O,a.HTTPHeaders=E,a.HTTPProgress=j,a.HTTPRequest=U,a.HTTPResponse=N,a.HTTPResponseError=b,a.HTTPStatusCode=I,a.IHTTPImplementation=A,a.ISocketService=te,a.MergeInterceptorFactory=de,a.ResponseHeader=$,a.RetryInterceptorFactory=oe,a.ThresholdInterceptorFactory=ae,a.WebSocketService=ne,a.XHRHTTPImplementation=B,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("rxjs"),require("rxjs/operators")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","rxjs/operators"],a):(c=typeof globalThis<"u"?globalThis:c||self,a(c.UniverNetwork={},c.UniverCore,c.rxjs,c.rxjs.operators))})(this,function(c,a,y,R){"use strict";var we=Object.defineProperty;var Ie=(c,a,y)=>a in c?we(c,a,{enumerable:!0,configurable:!0,writable:!0,value:y}):c[a]=y;var v=(c,a,y)=>Ie(c,typeof a!="symbol"?a+"":a,y);var D;const $="application/json";class L{constructor(n){v(this,"_headers",new Map);typeof n=="string"?this._handleHeadersString(n):n instanceof Headers?this._handleHeaders(n):n&&this._handleHeadersConstructorProps(n)}forEach(n){this._headers.forEach((t,r)=>n(r,t))}has(n){return!!this._headers.has(n.toLowerCase())}get(n){const t=n.toLowerCase();return this._headers.has(t)?this._headers.get(t):null}set(n,t){this._setHeader(n,t)}toHeadersInit(){var t,r;const n={};return this._headers.forEach((s,i)=>{n[i]=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
+ `).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 O=a.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 W=0;class U{constructor(n,t,r){v(this,"uid",W++);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:$,t=(s=this.requestParams)==null?void 0:s.body;return n===$&&t&&typeof t=="object"?JSON.stringify(t):t?`${t}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}var V=Object.defineProperty,P=Object.getOwnPropertyDescriptor,z=(e,n,t,r)=>{for(var s=r>1?void 0:r?P(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(n,t,s):o(s))||s);return r&&s&&V(n,t,s),s},J=(e,n)=>(t,r)=>n(t,r,e);c.HTTPService=class extends a.Disposable{constructor(t){super();v(this,"_interceptors",[]);v(this,"_pipe");this._http=t}registerHTTPInterceptor(t){if(this._interceptors.indexOf(t)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(t),this._interceptors=this._interceptors.sort((r,s)=>{var i,o;return((i=r.priority)!=null?i:0)-((o=s.priority)!=null?o:0)}),this._pipe=null,a.toDisposable(()=>a.remove(this._interceptors,t))}get(t,r){return this._request("GET",t,r)}post(t,r){return this._request("POST",t,r)}put(t,r){return this._request("PUT",t,r)}delete(t,r){return this._request("DELETE",t,r)}patch(t,r){return this._request("PATCH",t,r)}getSSE(t,r,s){var u,f;const i=new L(s==null?void 0:s.headers),o=new M(s==null?void 0:s.params),l=new U(t,r,{headers:i,params:o,withCredentials:(u=s==null?void 0:s.withCredentials)!=null?u:!1,reportProgress:!0,responseType:(f=s==null?void 0:s.responseType)!=null?f:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body});return y.of(l).pipe(R.concatMap(h=>this._runInterceptorsAndImplementation(h)))}async _request(t,r,s){var h,d;const i=new L(s==null?void 0:s.headers),o=new M(s==null?void 0:s.params),l=new U(t,r,{headers:i,params:o,withCredentials:(h=s==null?void 0:s.withCredentials)!=null?h:!1,responseType:(d=s==null?void 0:s.responseType)!=null?d:"json",body:["GET","DELETE"].includes(t)||s==null?void 0:s.body}),u=y.of(l).pipe(R.concatMap(p=>this._runInterceptorsAndImplementation(p)));return await y.firstValueFrom(u)}_runInterceptorsAndImplementation(t){return this._pipe||(this._pipe=this._interceptors.map(r=>r.interceptor).reduceRight((r,s)=>K(r,s),(r,s)=>s(r))),this._pipe(t,r=>this._http.send(r))}},c.HTTPService=z([J(0,O)],c.HTTPService);function K(e,n){return(t,r)=>n(t,s=>e(s,r))}const Y=200,Q=300;var F=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.Ok=200]="Ok",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.ImUsed=226]="ImUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.Unused=306]="Unused",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.PayloadTooLarge=413]="PayloadTooLarge",e[e.UriTooLong=414]="UriTooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HttpVersionNotSupported=505]="HttpVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(F||{}),A=(e=>(e[e.DownloadProgress=0]="DownloadProgress",e[e.Response=1]="Response",e))(A||{});class N{constructor({body:n,headers:t,status:r,statusText:s}){v(this,"type",1);v(this,"body");v(this,"headers");v(this,"status");v(this,"statusText");this.body=n,this.headers=t,this.status=r,this.statusText=s}}class j{constructor(n,t,r){v(this,"type",0);this.total=n,this.loaded=t,this.partialText=r}}class x{constructor(n,t,r){this.headers=n,this.status=t,this.statusText=r}}class b{constructor({request:n,headers:t,status:r,statusText:s,error:i}){v(this,"request");v(this,"headers");v(this,"status");v(this,"statusText");v(this,"error");this.request=n,this.headers=t,this.status=r,this.statusText=s,this.error=i}}function B(e){return{method:e.method,headers:e.getHeadersInit(),body:e.getBody(),credentials:e.withCredentials?"include":void 0}}var Z=Object.defineProperty,H=Object.getOwnPropertyDescriptor,S=(e,n,t,r)=>{for(var s=r>1?void 0:r?H(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(n,t,s):o(s))||s);return r&&s&&Z(n,t,s),s},C=(e,n)=>(t,r)=>n(t,r,e);c.FetchHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new y.Observable(t=>{const r=new AbortController;return this._send(n,t,r).catch(s=>{t.error(new b({error:s,request:n}))}),()=>r.abort()})}async _send(n,t,r){var h,d;let s;try{const p=B(n),w=n.getUrlWithParams(),m=fetch(w,{signal:r.signal,...p});this._logService.debug(`[FetchHTTPImplementation]: sending request to url ${w} with params ${p}`),s=await m}catch(p){const w=new b({request:n,error:p,status:(h=p.status)!=null?h:0,statusText:(d=p.statusText)!=null?d:"Unknown Error",headers:p.headers});this._logService.error("[FetchHTTPImplementation]: network error",w),t.error(w);return}const i=new L(s.headers),o=s.status,l=s.statusText;let u=null;if(s.body&&(u=await this._readBody(n,s,t)),o>=F.Ok&&o<F.MultipleChoices)t.next(new N({body:u,headers:i,status:o,statusText:l}));else{const p=new b({request:n,error:u,status:o,statusText:l,headers:i});this._logService.error("[FetchHTTPImplementation]: network error",p),t.error(p)}t.complete()}async _readBody(n,t,r){var w,m;const s=[],i=t.body.getReader(),o=t.headers.get("content-length");let l=0;const u=(w=n.requestParams)==null?void 0:w.reportProgress,f=n.responseType;let h,d;for(;;){const{done:I,value:g}=await i.read();if(I)break;s.push(g),l+=g.length,u&&f==="text"&&(h=(h!=null?h:"")+(d!=null?d:d=new TextDecoder).decode(g,{stream:!0}),r.next(new j(o?Number.parseInt(o,10):void 0,l,h)))}const p=T(s,l);try{const I=(m=t.headers.get("content-type"))!=null?m:"";return te(n,p,I)}catch(I){const g=new b({request:n,error:I,status:t.status,statusText:t.statusText,headers:new L(t.headers)});return this._logService.error("[FetchHTTPImplementation]: network error",g),r.error(g),null}}},c.FetchHTTPImplementation=S([C(0,a.ILogService)],c.FetchHTTPImplementation);function T(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 ee=/^\)\]\}',?\n/;function te(e,n,t){switch(e.responseType){case"json":const r=new TextDecoder().decode(n).replace(ee,"");return r===""?null:JSON.parse(r);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:t});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}var re=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,se=(e,n,t,r)=>{for(var s=r>1?void 0:r?ne(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(n,t,s):o(s))||s);return r&&s&&re(n,t,s),s},ie=(e,n)=>(t,r)=>n(t,r,e);c.XHRHTTPImplementation=class{constructor(n){this._logService=n}send(n){return new y.Observable(t=>{const r=new XMLHttpRequest,s=n.getUrlWithParams(),i=B(n);r.open(n.method,s),n.withCredentials&&(r.withCredentials=!0),i.headers&&Object.entries(i.headers).forEach(([h,d])=>r.setRequestHeader(h,d));const o=()=>{const h=r.statusText||"OK",d=new L(r.getAllResponseHeaders());return new x(d,r.status,h)},l=()=>{const{headers:h,statusText:d,status:p}=o(),{responseType:w}=n;let m=null,I=null;p!==F.NoContent&&(m=typeof r.response>"u"?r.responseText:r.response);let g=p>=Y&&p<Q;if(w==="json"&&typeof m=="string"){const _=m;try{m=m?JSON.parse(m):null}catch(E){g=!1,m=_,I=E}}if(g)t.next(new N({body:m,headers:h,status:p,statusText:d}));else{const _=new b({request:n,error:I,headers:h,status:p,statusText:d});this._logService.error("[XHRHTTPImplementation]: network error",_),t.error(_)}},u=h=>{const d=new b({request:n,error:h,status:r.status||0,statusText:r.statusText||"Unknown Error",headers:o().headers});this._logService.error("[XHRHTTPImplementation]: network error",d),t.error(d)};r.addEventListener("load",l),r.addEventListener("error",u),r.addEventListener("abort",u),r.addEventListener("timeout",u);const f=n.getBody();return r.send(f),this._logService.debug(`[XHRHTTPImplementation]: sending request to url ${s} with params ${i}`),()=>{r.readyState!==r.DONE&&r.abort(),r.removeEventListener("load",l),r.removeEventListener("error",u),r.removeEventListener("abort",u),r.removeEventListener("timeout",u)}})}},c.XHRHTTPImplementation=se([ie(0,a.ILogService)],c.XHRHTTPImplementation);var oe=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,ae=(e,n,t,r)=>{for(var s=r>1?void 0:r?ce(n,t):n,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=(r?o(n,t,s):o(s))||s);return r&&s&&oe(n,t,s),s},X=(e,n)=>(t,r)=>n(t,r,e);c.UniverNetworkPlugin=(D=class extends a.Plugin{constructor(n=void 0,t,r){super(),this._config=n,this._logger=t,this._injector=r}onStarting(){var r,s,i;if(this._injector.get(c.HTTPService,a.Quantity.OPTIONAL,a.LookUp.SKIP_SELF)&&!((r=this._config)!=null&&r.forceUseNewInstance)){this._logger.warn("[UniverNetworkPlugin]",'HTTPService is already registered in an ancestor interceptor. Skipping registration. If you want to force a new instance, set "forceUseNewInstance" to true in the plugin configuration.');return}const t=(s=this._config)!=null&&s.useFetchImpl?c.FetchHTTPImplementation:typeof window<"u"?c.XHRHTTPImplementation:c.FetchHTTPImplementation;a.registerDependencies(this._injector,a.mergeOverrideWithDependencies([[c.HTTPService],[O,{useClass:t}]],(i=this._config)==null?void 0:i.override))}},v(D,"pluginName","UNIVER_NETWORK_PLUGIN"),D),c.UniverNetworkPlugin=ae([X(1,a.ILogService),X(2,a.Inject(a.Injector))],c.UniverNetworkPlugin);const le=a.createIdentifier("univer.network.socket.service");class he extends a.Disposable{createSocket(n){try{const t=new WebSocket(n),r=new a.DisposableCollection;return{URL:n,close:(i,o)=>{t.close(i,o),r.dispose()},send:i=>{t.send(i)},open$:new y.Observable(i=>{const o=l=>i.next(l);t.addEventListener("open",o),r.add(a.toDisposable(()=>t.removeEventListener("open",o)))}).pipe(R.share()),close$:new y.Observable(i=>{const o=l=>i.next(l);t.addEventListener("close",o),r.add(a.toDisposable(()=>t.removeEventListener("close",o)))}).pipe(R.share()),error$:new y.Observable(i=>{const o=l=>i.next(l);t.addEventListener("error",o),r.add(a.toDisposable(()=>t.removeEventListener("error",o)))}).pipe(R.share()),message$:new y.Observable(i=>{const o=l=>i.next(l);t.addEventListener("message",o),r.add(a.toDisposable(()=>t.removeEventListener("message",o)))}).pipe(R.share())}}catch(t){return console.error(t),null}}}const de=3,pe=1e3,ue=e=>{var r,s;const n=(r=e==null?void 0:e.maxRetryAttempts)!=null?r:de,t=(s=e==null?void 0:e.delayInterval)!=null?s:pe;return(i,o)=>o(i).pipe(R.retry({delay:t,count:n}))},fe=e=>{const n=[],t=new Set,r=()=>{var s;for(;t.size<((s=e==null?void 0:e.maxParallel)!=null?s:1)&&n.length>0;){const i=n.shift();t.add(i),i()}};return(s,i)=>new y.Observable(o=>{const l=()=>i(s).subscribe({next:f=>o.next(f),error:f=>o.error(f),complete:()=>o.complete()}),u=()=>{t.delete(l),a.remove(n,l),r()};return n.push(l),r(),u})},ge=e=>{const{errorStatusCodes:n,onAuthError:t}=e;return(s,i)=>i(s).pipe(y.catchError(o=>(o instanceof b&&n.some(l=>l===o.status)&&t(),y.throwError(()=>o))))},me=(e=300)=>{let t=()=>{};return r=>new Promise(s=>{t();const i=setTimeout(()=>{s(!0)},e);t=()=>{clearTimeout(i),s(!1)}})},ye=()=>(e,n)=>n.map(t=>({config:t,result:e})),ve=(e,n={})=>{const{isMatch:t,getParamsFromRequest:r,mergeParamsToRequest:s}=e,{fetchCheck:i=me(300),distributeResult:o=ye()}=n,l=[],u=f=>f.map(h=>h.config);return(f,h)=>t(f)?new y.Observable(d=>{const p=r(f);l.push({next:m=>d.next(m),error:m=>d.error(m),config:p});const w=u(l);i(f).then(m=>{if(m){const I=[];w.forEach(g=>{const _=l.findIndex(E=>E.config===g);if(_>=0){const[E]=l.splice(_,1);I.push(E)}}),h(s(w,f)).subscribe({next:g=>{if(g.type===A.Response){const _=g.body,E=o(_,w);I.forEach(k=>{const G=E.find(q=>q.config===k.config);if(G){const q=new N({body:G.result,headers:g.headers,status:g.status,statusText:g.statusText});k.next(q)}else k.error("batch error")})}},complete:()=>d.complete(),error:g=>d.error(g)})}})}):h(f)};c.AuthInterceptorFactory=ge,c.HTTPEventType=A,c.HTTPHeaders=L,c.HTTPProgress=j,c.HTTPRequest=U,c.HTTPResponse=N,c.HTTPResponseError=b,c.HTTPStatusCode=F,c.IHTTPImplementation=O,c.ISocketService=le,c.MergeInterceptorFactory=ve,c.ResponseHeader=x,c.RetryInterceptorFactory=ue,c.ThresholdInterceptorFactory=fe,c.WebSocketService=he,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/network",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "private": false,
5
5
  "author": "DreamNum <developer@univer.ai>",
6
6
  "license": "Apache-2.0",
@@ -30,6 +30,11 @@
30
30
  "require": "./lib/cjs/*",
31
31
  "types": "./lib/types/index.d.ts"
32
32
  },
33
+ "./facade": {
34
+ "import": "./lib/es/facade.js",
35
+ "require": "./lib/cjs/facade.js",
36
+ "types": "./lib/types/facade/index.d.ts"
37
+ },
33
38
  "./lib/*": "./lib/*"
34
39
  },
35
40
  "main": "./lib/es/index.js",
@@ -47,14 +52,14 @@
47
52
  "rxjs": ">=7.0.0"
48
53
  },
49
54
  "dependencies": {
50
- "@univerjs/core": "0.5.1"
55
+ "@univerjs/core": "0.5.2"
51
56
  },
52
57
  "devDependencies": {
53
58
  "rxjs": "^7.8.1",
54
59
  "typescript": "^5.7.2",
55
- "vite": "^6.0.1",
56
- "vitest": "^2.1.6",
57
- "@univerjs-infra/shared": "0.5.1"
60
+ "vite": "^6.0.3",
61
+ "vitest": "^2.1.8",
62
+ "@univerjs-infra/shared": "0.5.2"
58
63
  },
59
64
  "space": {
60
65
  ".": {
@@ -67,6 +72,11 @@
67
72
  "require": "./lib/cjs/*",
68
73
  "types": "./lib/types/index.d.ts"
69
74
  },
75
+ "./facade": {
76
+ "import": "./lib/es/facade.js",
77
+ "require": "./lib/cjs/facade.js",
78
+ "types": "./lib/types/facade/index.d.ts"
79
+ },
70
80
  "./lib/*": "./lib/*"
71
81
  },
72
82
  "scripts": {