@univerjs/network 0.1.12 → 0.1.13-nightly.202406041140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +260 -242
- package/lib/types/services/http/http.service.d.ts +4 -0
- package/lib/types/services/http/request.d.ts +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +5 -5
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var N=Object.defineProperty;var F=(e,n,r)=>n in e?N(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var
|
|
2
|
-
`).forEach(r=>{const[t,s]=r.split(":");t&&s&&this._setHeader(t,s)})}_handleHeadersConstructorProps(n){Object.keys(n).forEach(([r,t])=>{this._setHeader(r,t)})}_handleHeaders(n){n.forEach((r,t)=>{this._setHeader(t,r)})}}const I=x.createIdentifier("network.http-implementation");class k{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>`${n}=${this.params[n]}`).join("&"):""}}let U=0;class L{constructor(n,r,t){d(this,"uid",U++);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:E,r=(s=this.requestParams)==null?void 0:s.body;return n===E&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}class v{constructor({body:n,headers:r,status:t,statusText:s}){d(this,"body");d(this,"headers");d(this,"status");d(this,"statusText");this.body=n,this.headers=r,this.status=t,this.statusText=s}}class w{constructor({headers:n,status:r,statusText:t,error:s}){d(this,"headers");d(this,"status");d(this,"statusText");d(this,"error");this.headers=n,this.status=r,this.statusText=t,this.error=s}}class O{constructor(n,r,t){this.headers=n,this.status=r,this.statusText=t}}var M=Object.defineProperty,D=Object.getOwnPropertyDescriptor,j=(e,n,r,t)=>{for(var s=t>1?void 0:t?D(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&&M(n,r,s),s},B=(e,n)=>(r,t)=>n(r,t,e);exports.HTTPService=class extends y.Disposable{constructor(r){super();d(this,"_interceptors",[]);d(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,y.toDisposable(()=>y.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)}async _request(r,t,s){var h,u;const o=new g(s==null?void 0:s.headers),i=new k(s==null?void 0:s.params),l=new L(r,t,{headers:o,params:i,withCredentials:(h=s==null?void 0:s.withCredentials)!=null?h:!1,responseType:(u=s==null?void 0:s.responseType)!=null?u:"json",body:r==="GET"||s==null?void 0:s.body}),a=m.of(l).pipe(f.concatMap(p=>this._runInterceptorsAndImplementation(p))),c=await m.firstValueFrom(a);if(c instanceof v)return c;throw new Error(`${c.error}`)}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(t=>t.interceptor).reduceRight((t,s)=>$(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}};exports.HTTPService=j([B(0,I)],exports.HTTPService);function $(e,n){return(r,t)=>n(r,s=>e(s,t))}const G=200,W=300;var b=(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))(b||{});class V{send(n){return new m.Observable(r=>{const t=new AbortController;return this._send(n,r,t).then(()=>{},s=>{r.error(new w({error:s}))}),()=>t.abort()})}async _send(n,r,t){var h,u;let s;try{const p=this._parseFetchParamsFromRequest(n);s=await fetch(n.getUrlWithParams(),{signal:t.signal,...p})}catch(p){r.error(new w({error:p,status:(h=p.status)!=null?h:0,statusText:(u=p.statusText)!=null?u:"Unknown Error",headers:p.headers}));return}const o=new g(s.headers),i=s.status,l=s.statusText;let a=null;s.body&&(a=await this._readBody(n,s,r)),i>=b.Ok&&i<b.MultipleChoices?r.next(new v({body:a,headers:o,status:i,statusText:l})):r.error(new w({error:a,status:i,statusText:l,headers:o})),r.complete()}async _readBody(n,r,t){var a;const s=[],o=r.body.getReader();let i=0;for(;;){const{done:c,value:h}=await o.read();if(c)break;s.push(h),i+=h.length}const l=X(s,i);try{const c=(a=r.headers.get("content-type"))!=null?a:"";return J(n,l,c)}catch(c){return t.error(new w({error:c,status:r.status,statusText:r.statusText,headers:new g(r.headers)})),null}}_parseFetchParamsFromRequest(n){return{method:n.method,headers:n.getHeadersInit(),body:n.getBody(),credentials:n.withCredentials?"include":void 0}}}function X(e,n){const r=new Uint8Array(n);let t=0;for(const s of e)r.set(s,t),t+=s.length;return r}const z=/^\)\]\}',?\n/;function J(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(z,"");return t===""?null:JSON.parse(t);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:r});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class Y{send(n){return new m.Observable(r=>{const t=new XMLHttpRequest;t.open(n.method,n.getUrlWithParams()),n.withCredentials&&(t.withCredentials=!0),n.headers.forEach((a,c)=>t.setRequestHeader(a,c.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 a=t.statusText||"OK",c=new g(t.getAllResponseHeaders());return new O(c,t.status,a)},o=()=>{const{headers:a,statusText:c,status:h}=s(),{responseType:u}=n;let p=null,_=null;h!==b.NoContent&&(p=typeof t.response>"u"?t.responseText:t.response);let R=h>=G&&h<W;if(u==="json"&&typeof p=="string"){const q=p;try{p=p?JSON.parse(p):null}catch(A){R=!1,p=q,_=A}}R?r.next(new v({body:p,headers:a,status:h,statusText:c})):r.next(new w({error:_,headers:a,status:h,statusText:c}))},i=a=>{const c=new w({error:a,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:s().headers});r.next(c)};t.addEventListener("load",o),t.addEventListener("error",i),t.addEventListener("abort",i),t.addEventListener("timeout",i);const l=n.getBody();return t.send(l),()=>{t.readyState!==t.DONE&&t.abort(),t.removeEventListener("load",o),t.removeEventListener("error",i),t.removeEventListener("abort",i),t.removeEventListener("timeout",i)}})}}const K=x.createIdentifier("univer.socket");class Q extends y.Disposable{createSocket(n){try{const r=new WebSocket(n),t=new y.DisposableCollection;return{URL:n,close:(o,i)=>{r.close(o,i),t.dispose()},send:o=>{r.send(o)},open$:new m.Observable(o=>{const i=l=>o.next(l);r.addEventListener("open",i),t.add(y.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(f.share()),close$:new m.Observable(o=>{const i=l=>o.next(l);r.addEventListener("close",i),t.add(y.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(f.share()),error$:new m.Observable(o=>{const i=l=>o.next(l);r.addEventListener("error",i),t.add(y.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(f.share()),message$:new m.Observable(o=>{const i=l=>o.next(l);r.addEventListener("message",i),t.add(y.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(f.share())}}catch(r){return console.error(r),null}}}const Z=2,P=1e3,H=(e,n)=>n(e).pipe(f.retryWhen(r=>r.pipe(f.concatMap((t,s)=>s>Z?m.throwError(t):m.of(t)),m.delay(P)))),S=(e,n)=>{const r=[],t=new Set,s=()=>{var o;for(;t.size<((o=n==null?void 0:n.maxParallel)!=null?o:1)&&r.length>0;){const i=r.shift();t.add(i),i()}};return(o,i)=>new m.Observable(l=>{const a=()=>i(o).subscribe({next:h=>l.next(h),error:h=>l.next(h),complete:()=>l.complete()}),c=()=>{t.delete(a),y.remove(r,a),s()};return r.push(a),s(),c})};exports.FetchHTTPImplementation=V;exports.HTTPHeaders=g;exports.HTTPRequest=L;exports.HTTPResponse=v;exports.HTTPResponseError=w;exports.HTTPStatusCode=b;exports.IHTTPImplementation=I;exports.ISocketService=K;exports.ThresholdInterceptorFactory=S;exports.WebSocketService=Q;exports.XHRHTTPImplementation=Y;exports.retryInterceptor=H;
|
|
1
|
+
"use strict";var N=Object.defineProperty;var F=(e,n,r)=>n in e?N(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var p=(e,n,r)=>(F(e,typeof n!="symbol"?n+"":n,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),y=require("rxjs"),u=require("rxjs/operators"),L=require("@wendellhu/redi"),I="application/json";class g{constructor(n){p(this,"_headers",new Map);typeof n=="string"?this._handleHeadersString(n):n instanceof Headers?this._handleHeaders(n):n&&this._handleHeadersConstructorProps(n)}forEach(n){this._headers.forEach((r,t)=>n(t,r))}has(n){return!!this._headers.has(n.toLowerCase())}get(n){const r=n.toLowerCase();return this._headers.has(r)?this._headers.get(r):null}toHeadersInit(){var r,t;const n={};return this._headers.forEach((s,a)=>{n[a]=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 q=L.createIdentifier("network.http-implementation");class x{constructor(n){this.params=n}toString(){return this.params?Object.keys(this.params).map(n=>`${n}=${this.params[n]}`).join("&"):""}}let U=0;class R{constructor(n,r,t){p(this,"uid",U++);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:I,r=(s=this.requestParams)==null?void 0:s.body;return n===I&&r&&typeof r=="object"?JSON.stringify(r):r?`${r}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}class E{constructor({body:n,headers:r,status:t,statusText:s}){p(this,"body");p(this,"headers");p(this,"status");p(this,"statusText");this.body=n,this.headers=r,this.status=t,this.statusText=s}}class w{constructor({headers:n,status:r,statusText:t,error:s}){p(this,"headers");p(this,"status");p(this,"statusText");p(this,"error");this.headers=n,this.status=r,this.statusText=t,this.error=s}}class M{constructor(n,r,t){this.headers=n,this.status=r,this.statusText=t}}var O=(e,n,r,t)=>{for(var s=n,a=e.length-1,i;a>=0;a--)(i=e[a])&&(s=i(s)||s);return s},D=(e,n)=>(r,t)=>n(r,t,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((t,s)=>{var a,i;return((a=t.priority)!=null?a:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,m.toDisposable(()=>m.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 c,l;const a=new g(s==null?void 0:s.headers),i=new x(s==null?void 0:s.params),h=new R(r,t,{headers:a,params:i,withCredentials:(c=s==null?void 0:s.withCredentials)!=null?c:!1,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(h).pipe(u.concatMap(o=>this._runInterceptorsAndImplementation(o)),u.map(o=>{if(o instanceof w)throw o;return o}))}async _request(r,t,s){var o,f;const a=new g(s==null?void 0:s.headers),i=new x(s==null?void 0:s.params),h=new R(r,t,{headers:a,params:i,withCredentials:(o=s==null?void 0:s.withCredentials)!=null?o:!1,responseType:(f=s==null?void 0:s.responseType)!=null?f:"json",body:["GET","DELETE"].includes(r)||s==null?void 0:s.body}),c=y.of(h).pipe(u.concatMap(d=>this._runInterceptorsAndImplementation(d))),l=await y.firstValueFrom(c);if(l instanceof E)return l;throw new Error(`${l.error}`)}_runInterceptorsAndImplementation(r){return this._pipe||(this._pipe=this._interceptors.map(t=>t.interceptor).reduceRight((t,s)=>j(t,s),(t,s)=>s(t))),this._pipe(r,t=>this._http.send(t))}};exports.HTTPService=O([D(0,q)],exports.HTTPService);function j(e,n){return(r,t)=>n(r,s=>e(s,t))}const B=200,$=300;var b=(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))(b||{});class G{send(n){return new y.Observable(r=>{const t=new AbortController;return this._send(n,r,t).then(()=>{},s=>{r.error(new w({error:s}))}),()=>t.abort()})}async _send(n,r,t){var o,f;let s;try{const d=this._parseFetchParamsFromRequest(n);s=await fetch(n.getUrlWithParams(),{signal:t.signal,...d})}catch(d){r.error(new w({error:d,status:(o=d.status)!=null?o:0,statusText:(f=d.statusText)!=null?f:"Unknown Error",headers:d.headers}));return}const a=new g(s.headers),i=s.status,h=s.statusText;let c=null;s.body&&(c=await this._readBody(n,s,r)),i>=b.Ok&&i<b.MultipleChoices?r.next(new E({body:c,headers:a,status:i,statusText:h})):r.error(new w({error:c,status:i,statusText:h,headers:a})),r.complete()}async _readBody(n,r,t){var c;const s=[],a=r.body.getReader();let i=0;for(;;){const{done:l,value:o}=await a.read();if(l)break;s.push(o),i+=o.length}const h=W(s,i);try{const l=(c=r.headers.get("content-type"))!=null?c:"";return X(n,h,l)}catch(l){return t.error(new w({error:l,status:r.status,statusText:r.statusText,headers:new g(r.headers)})),null}}_parseFetchParamsFromRequest(n){return{method:n.method,headers:n.getHeadersInit(),body:n.getBody(),credentials:n.withCredentials?"include":void 0}}}function W(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 V=/^\)\]\}',?\n/;function X(e,n,r){switch(e.responseType){case"json":const t=new TextDecoder().decode(n).replace(V,"");return t===""?null:JSON.parse(t);case"text":return new TextDecoder().decode(n);case"blob":return new Blob([n],{type:r});case"arraybuffer":return n.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class z{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((c,l)=>t.setRequestHeader(c,l.join(","))),n.headers.has("Accept")||t.setRequestHeader("Accept","application/json, text/plain, */*"),n.headers.has("Content-Type")||t.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const c=t.statusText||"OK",l=new g(t.getAllResponseHeaders());return new M(l,t.status,c)},a=()=>{const{headers:c,statusText:l,status:o}=s(),{responseType:f}=n;let d=null,v=null;o!==b.NoContent&&(d=typeof t.response>"u"?t.responseText:t.response);let _=o>=B&&o<$;if(f==="json"&&typeof d=="string"){const k=d;try{d=d?JSON.parse(d):null}catch(A){_=!1,d=k,v=A}}_?r.next(new E({body:d,headers:c,status:o,statusText:l})):r.error(new w({error:v,headers:c,status:o,statusText:l}))},i=c=>{const l=new w({error:c,status:t.status||0,statusText:t.statusText||"Unknown Error",headers:s().headers});r.error(l)};t.addEventListener("load",a),t.addEventListener("error",i),t.addEventListener("abort",i),t.addEventListener("timeout",i);const h=n.getBody();return t.send(h),()=>{t.readyState!==t.DONE&&t.abort(),t.removeEventListener("load",a),t.removeEventListener("error",i),t.removeEventListener("abort",i),t.removeEventListener("timeout",i)}})}}const J=L.createIdentifier("univer.socket");class Y extends m.Disposable{createSocket(n){try{const r=new WebSocket(n),t=new m.DisposableCollection;return{URL:n,close:(a,i)=>{r.close(a,i),t.dispose()},send:a=>{r.send(a)},open$:new y.Observable(a=>{const i=h=>a.next(h);r.addEventListener("open",i),t.add(m.toDisposable(()=>r.removeEventListener("open",i)))}).pipe(u.share()),close$:new y.Observable(a=>{const i=h=>a.next(h);r.addEventListener("close",i),t.add(m.toDisposable(()=>r.removeEventListener("close",i)))}).pipe(u.share()),error$:new y.Observable(a=>{const i=h=>a.next(h);r.addEventListener("error",i),t.add(m.toDisposable(()=>r.removeEventListener("error",i)))}).pipe(u.share()),message$:new y.Observable(a=>{const i=h=>a.next(h);r.addEventListener("message",i),t.add(m.toDisposable(()=>r.removeEventListener("message",i)))}).pipe(u.share())}}catch(r){return console.error(r),null}}}const K=2,Q=1e3,Z=(e,n)=>n(e).pipe(u.retryWhen(r=>r.pipe(u.concatMap((t,s)=>s>K?y.throwError(t):y.of(t)),y.delay(Q)))),P=(e,n)=>{const r=[],t=new Set,s=()=>{var a;for(;t.size<((a=n==null?void 0:n.maxParallel)!=null?a:1)&&r.length>0;){const i=r.shift();t.add(i),i()}};return(a,i)=>new y.Observable(h=>{const c=()=>i(a).subscribe({next:o=>h.next(o),error:o=>h.next(o),complete:()=>h.complete()}),l=()=>{t.delete(c),m.remove(r,c),s()};return r.push(c),s(),l})};exports.FetchHTTPImplementation=G;exports.HTTPHeaders=g;exports.HTTPRequest=R;exports.HTTPResponse=E;exports.HTTPResponseError=w;exports.HTTPStatusCode=b;exports.IHTTPImplementation=q;exports.ISocketService=J;exports.ThresholdInterceptorFactory=P;exports.WebSocketService=Y;exports.XHRHTTPImplementation=z;exports.retryInterceptor=Z;
|
package/lib/es/index.js
CHANGED
|
@@ -1,57 +1,53 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Disposable as
|
|
5
|
-
import { of as
|
|
6
|
-
import { concatMap as
|
|
7
|
-
import { createIdentifier as
|
|
8
|
-
const
|
|
9
|
-
class
|
|
1
|
+
var O = Object.defineProperty;
|
|
2
|
+
var j = (e, r, n) => r in e ? O(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n;
|
|
3
|
+
var p = (e, r, n) => (j(e, typeof r != "symbol" ? r + "" : r, n), n);
|
|
4
|
+
import { Disposable as q, toDisposable as f, remove as N, DisposableCollection as D } from "@univerjs/core";
|
|
5
|
+
import { of as R, firstValueFrom as B, Observable as m, throwError as $, delay as G } from "rxjs";
|
|
6
|
+
import { concatMap as v, map as V, share as g, retryWhen as W } from "rxjs/operators";
|
|
7
|
+
import { createIdentifier as U } from "@wendellhu/redi";
|
|
8
|
+
const L = "application/json";
|
|
9
|
+
class u {
|
|
10
10
|
constructor(r) {
|
|
11
|
-
|
|
11
|
+
p(this, "_headers", /* @__PURE__ */ new Map());
|
|
12
12
|
typeof r == "string" ? this._handleHeadersString(r) : r instanceof Headers ? this._handleHeaders(r) : r && this._handleHeadersConstructorProps(r);
|
|
13
13
|
}
|
|
14
14
|
forEach(r) {
|
|
15
|
-
this._headers.forEach((
|
|
15
|
+
this._headers.forEach((n, t) => r(t, n));
|
|
16
16
|
}
|
|
17
17
|
has(r) {
|
|
18
18
|
return !!this._headers.has(r.toLowerCase());
|
|
19
19
|
}
|
|
20
20
|
get(r) {
|
|
21
|
-
const
|
|
22
|
-
return this._headers.has(
|
|
21
|
+
const n = r.toLowerCase();
|
|
22
|
+
return this._headers.has(n) ? this._headers.get(n) : null;
|
|
23
23
|
}
|
|
24
24
|
toHeadersInit() {
|
|
25
|
-
var t;
|
|
25
|
+
var n, t;
|
|
26
26
|
const r = {};
|
|
27
|
-
return this._headers.forEach((
|
|
28
|
-
r[
|
|
29
|
-
}), (
|
|
27
|
+
return this._headers.forEach((s, a) => {
|
|
28
|
+
r[a] = s.join(",");
|
|
29
|
+
}), (n = r.accept) != null || (r.accept = "application/json, text/plain, */*"), (t = r["content-type"]) != null || (r["content-type"] = "application/json;charset=UTF-8"), r;
|
|
30
30
|
}
|
|
31
|
-
_setHeader(r,
|
|
32
|
-
const
|
|
33
|
-
this._headers.has(
|
|
31
|
+
_setHeader(r, n) {
|
|
32
|
+
const t = r.toLowerCase();
|
|
33
|
+
this._headers.has(t) ? this._headers.get(t).push(n.toString()) : this._headers.set(t, [n.toString()]);
|
|
34
34
|
}
|
|
35
35
|
_handleHeadersString(r) {
|
|
36
36
|
r.split(`
|
|
37
|
-
`).forEach((
|
|
38
|
-
const [
|
|
39
|
-
|
|
37
|
+
`).forEach((n) => {
|
|
38
|
+
const [t, s] = n.split(":");
|
|
39
|
+
t && s && this._setHeader(t, s);
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
_handleHeadersConstructorProps(r) {
|
|
43
|
-
Object.
|
|
44
|
-
this._setHeader(t, n);
|
|
45
|
-
});
|
|
43
|
+
Object.entries(r).forEach(([n, t]) => this._setHeader(n, t));
|
|
46
44
|
}
|
|
47
45
|
_handleHeaders(r) {
|
|
48
|
-
r.forEach((
|
|
49
|
-
this._setHeader(n, t);
|
|
50
|
-
});
|
|
46
|
+
r.forEach((n, t) => this._setHeader(t, n));
|
|
51
47
|
}
|
|
52
48
|
}
|
|
53
|
-
const
|
|
54
|
-
class
|
|
49
|
+
const X = U("network.http-implementation");
|
|
50
|
+
class I {
|
|
55
51
|
constructor(r) {
|
|
56
52
|
this.params = r;
|
|
57
53
|
}
|
|
@@ -59,11 +55,11 @@ class V {
|
|
|
59
55
|
return this.params ? Object.keys(this.params).map((r) => `${r}=${this.params[r]}`).join("&") : "";
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
|
-
let
|
|
63
|
-
class
|
|
64
|
-
constructor(r,
|
|
65
|
-
|
|
66
|
-
this.method = r, this.url =
|
|
58
|
+
let z = 0;
|
|
59
|
+
class k {
|
|
60
|
+
constructor(r, n, t) {
|
|
61
|
+
p(this, "uid", z++);
|
|
62
|
+
this.method = r, this.url = n, this.requestParams = t;
|
|
67
63
|
}
|
|
68
64
|
get headers() {
|
|
69
65
|
return this.requestParams.headers;
|
|
@@ -75,63 +71,63 @@ class X {
|
|
|
75
71
|
return this.requestParams.responseType;
|
|
76
72
|
}
|
|
77
73
|
getUrlWithParams() {
|
|
78
|
-
var
|
|
79
|
-
const r = (
|
|
74
|
+
var n, t;
|
|
75
|
+
const r = (t = (n = this.requestParams) == null ? void 0 : n.params) == null ? void 0 : t.toString();
|
|
80
76
|
return r ? `${this.url}${this.url.includes("?") ? "&" : "?"}${r}` : this.url;
|
|
81
77
|
}
|
|
82
78
|
getBody() {
|
|
83
|
-
var
|
|
84
|
-
const r = (
|
|
85
|
-
return r ===
|
|
79
|
+
var t, s;
|
|
80
|
+
const r = (t = this.headers.get("Content-Type")) != null ? t : L, n = (s = this.requestParams) == null ? void 0 : s.body;
|
|
81
|
+
return r === L && n && typeof n == "object" ? JSON.stringify(n) : n ? `${n}` : null;
|
|
86
82
|
}
|
|
87
83
|
getHeadersInit() {
|
|
88
84
|
return this.headers.toHeadersInit();
|
|
89
85
|
}
|
|
90
86
|
}
|
|
91
|
-
class
|
|
87
|
+
class x {
|
|
92
88
|
constructor({
|
|
93
89
|
body: r,
|
|
94
|
-
headers:
|
|
95
|
-
status:
|
|
90
|
+
headers: n,
|
|
91
|
+
status: t,
|
|
96
92
|
statusText: s
|
|
97
93
|
}) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.body = r, this.headers =
|
|
94
|
+
p(this, "body");
|
|
95
|
+
p(this, "headers");
|
|
96
|
+
p(this, "status");
|
|
97
|
+
p(this, "statusText");
|
|
98
|
+
this.body = r, this.headers = n, this.status = t, this.statusText = s;
|
|
103
99
|
}
|
|
104
100
|
}
|
|
105
|
-
class
|
|
101
|
+
class y {
|
|
106
102
|
constructor({
|
|
107
103
|
headers: r,
|
|
108
|
-
status:
|
|
109
|
-
statusText:
|
|
104
|
+
status: n,
|
|
105
|
+
statusText: t,
|
|
110
106
|
error: s
|
|
111
107
|
}) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.headers = r, this.status =
|
|
108
|
+
p(this, "headers");
|
|
109
|
+
p(this, "status");
|
|
110
|
+
p(this, "statusText");
|
|
111
|
+
p(this, "error");
|
|
112
|
+
this.headers = r, this.status = n, this.statusText = t, this.error = s;
|
|
117
113
|
}
|
|
118
114
|
}
|
|
119
|
-
class
|
|
120
|
-
constructor(r,
|
|
121
|
-
this.headers = r, this.status =
|
|
115
|
+
class J {
|
|
116
|
+
constructor(r, n, t) {
|
|
117
|
+
this.headers = r, this.status = n, this.statusText = t;
|
|
122
118
|
}
|
|
123
119
|
}
|
|
124
|
-
var
|
|
125
|
-
for (var s =
|
|
126
|
-
(i = e[
|
|
127
|
-
return
|
|
128
|
-
},
|
|
129
|
-
let
|
|
120
|
+
var Y = (e, r, n, t) => {
|
|
121
|
+
for (var s = r, a = e.length - 1, i; a >= 0; a--)
|
|
122
|
+
(i = e[a]) && (s = i(s) || s);
|
|
123
|
+
return s;
|
|
124
|
+
}, K = (e, r) => (n, t) => r(n, t, e);
|
|
125
|
+
let A = class extends q {
|
|
130
126
|
constructor(r) {
|
|
131
127
|
super();
|
|
132
|
-
|
|
128
|
+
p(this, "_interceptors", []);
|
|
133
129
|
// eslint-disable-next-line ts/no-explicit-any
|
|
134
|
-
|
|
130
|
+
p(this, "_pipe");
|
|
135
131
|
this._http = r;
|
|
136
132
|
}
|
|
137
133
|
/**
|
|
@@ -143,124 +139,146 @@ let b = class extends L {
|
|
|
143
139
|
registerHTTPInterceptor(r) {
|
|
144
140
|
if (this._interceptors.indexOf(r) !== -1)
|
|
145
141
|
throw new Error("[HTTPService]: The interceptor has already been registered!");
|
|
146
|
-
return this._interceptors.push(r), this._interceptors = this._interceptors.sort((
|
|
147
|
-
var s,
|
|
148
|
-
return ((s =
|
|
149
|
-
}), this._pipe = null,
|
|
142
|
+
return this._interceptors.push(r), this._interceptors = this._interceptors.sort((n, t) => {
|
|
143
|
+
var s, a;
|
|
144
|
+
return ((s = n.priority) != null ? s : 0) - ((a = t.priority) != null ? a : 0);
|
|
145
|
+
}), this._pipe = null, f(() => N(this._interceptors, r));
|
|
146
|
+
}
|
|
147
|
+
get(r, n) {
|
|
148
|
+
return this._request("GET", r, n);
|
|
150
149
|
}
|
|
151
|
-
|
|
152
|
-
return this._request("
|
|
150
|
+
post(r, n) {
|
|
151
|
+
return this._request("POST", r, n);
|
|
153
152
|
}
|
|
154
|
-
|
|
155
|
-
return this._request("
|
|
153
|
+
put(r, n) {
|
|
154
|
+
return this._request("PUT", r, n);
|
|
156
155
|
}
|
|
157
|
-
|
|
158
|
-
return this._request("
|
|
156
|
+
delete(r, n) {
|
|
157
|
+
return this._request("DELETE", r, n);
|
|
159
158
|
}
|
|
160
|
-
|
|
161
|
-
return this._request("
|
|
159
|
+
patch(r, n) {
|
|
160
|
+
return this._request("PATCH", r, n);
|
|
161
|
+
}
|
|
162
|
+
getSSE(r, n, t) {
|
|
163
|
+
var l, c;
|
|
164
|
+
const s = new u(t == null ? void 0 : t.headers), a = new I(t == null ? void 0 : t.params), i = new k(r, n, {
|
|
165
|
+
headers: s,
|
|
166
|
+
params: a,
|
|
167
|
+
withCredentials: (l = t == null ? void 0 : t.withCredentials) != null ? l : !1,
|
|
168
|
+
// default value for withCredentials is false by MDN
|
|
169
|
+
responseType: (c = t == null ? void 0 : t.responseType) != null ? c : "json",
|
|
170
|
+
body: ["GET", "DELETE"].includes(r) || t == null ? void 0 : t.body
|
|
171
|
+
});
|
|
172
|
+
return R(i).pipe(
|
|
173
|
+
v((o) => this._runInterceptorsAndImplementation(o)),
|
|
174
|
+
V((o) => {
|
|
175
|
+
if (o instanceof y)
|
|
176
|
+
throw o;
|
|
177
|
+
return o;
|
|
178
|
+
})
|
|
179
|
+
);
|
|
162
180
|
}
|
|
163
181
|
/** The HTTP request implementations */
|
|
164
|
-
async _request(r,
|
|
165
|
-
var
|
|
166
|
-
const s = new
|
|
182
|
+
async _request(r, n, t) {
|
|
183
|
+
var o, h;
|
|
184
|
+
const s = new u(t == null ? void 0 : t.headers), a = new I(t == null ? void 0 : t.params), i = new k(r, n, {
|
|
167
185
|
headers: s,
|
|
168
|
-
params:
|
|
169
|
-
withCredentials: (
|
|
186
|
+
params: a,
|
|
187
|
+
withCredentials: (o = t == null ? void 0 : t.withCredentials) != null ? o : !1,
|
|
170
188
|
// default value for withCredentials is false by MDN
|
|
171
|
-
responseType: (h =
|
|
172
|
-
body:
|
|
173
|
-
}),
|
|
174
|
-
|
|
175
|
-
),
|
|
176
|
-
if (
|
|
177
|
-
return
|
|
178
|
-
throw new Error(`${
|
|
189
|
+
responseType: (h = t == null ? void 0 : t.responseType) != null ? h : "json",
|
|
190
|
+
body: ["GET", "DELETE"].includes(r) || t == null ? void 0 : t.body
|
|
191
|
+
}), l = R(i).pipe(
|
|
192
|
+
v((w) => this._runInterceptorsAndImplementation(w))
|
|
193
|
+
), c = await B(l);
|
|
194
|
+
if (c instanceof x)
|
|
195
|
+
return c;
|
|
196
|
+
throw new Error(`${c.error}`);
|
|
179
197
|
}
|
|
180
198
|
// eslint-disable-next-line ts/no-explicit-any
|
|
181
199
|
_runInterceptorsAndImplementation(r) {
|
|
182
|
-
return this._pipe || (this._pipe = this._interceptors.map((
|
|
183
|
-
(
|
|
184
|
-
(
|
|
200
|
+
return this._pipe || (this._pipe = this._interceptors.map((n) => n.interceptor).reduceRight(
|
|
201
|
+
(n, t) => Q(n, t),
|
|
202
|
+
(n, t) => t(n)
|
|
185
203
|
)), this._pipe(
|
|
186
204
|
r,
|
|
187
|
-
(
|
|
205
|
+
(n) => this._http.send(n)
|
|
188
206
|
/* final handler */
|
|
189
207
|
);
|
|
190
208
|
}
|
|
191
209
|
};
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
],
|
|
195
|
-
function
|
|
196
|
-
return (
|
|
210
|
+
A = Y([
|
|
211
|
+
K(0, X)
|
|
212
|
+
], A);
|
|
213
|
+
function Q(e, r) {
|
|
214
|
+
return (n, t) => r(n, (s) => e(s, t));
|
|
197
215
|
}
|
|
198
|
-
const
|
|
199
|
-
var
|
|
216
|
+
const Z = 200, P = 300;
|
|
217
|
+
var E = /* @__PURE__ */ ((e) => (e[e.Continue = 100] = "Continue", e[e.SwitchingProtocols = 101] = "SwitchingProtocols", e[e.Processing = 102] = "Processing", e[e.EarlyHints = 103] = "EarlyHints", e[e.Ok = 200] = "Ok", e[e.Created = 201] = "Created", e[e.Accepted = 202] = "Accepted", e[e.NonAuthoritativeInformation = 203] = "NonAuthoritativeInformation", e[e.NoContent = 204] = "NoContent", e[e.ResetContent = 205] = "ResetContent", e[e.PartialContent = 206] = "PartialContent", e[e.MultiStatus = 207] = "MultiStatus", e[e.AlreadyReported = 208] = "AlreadyReported", e[e.ImUsed = 226] = "ImUsed", e[e.MultipleChoices = 300] = "MultipleChoices", e[e.MovedPermanently = 301] = "MovedPermanently", e[e.Found = 302] = "Found", e[e.SeeOther = 303] = "SeeOther", e[e.NotModified = 304] = "NotModified", e[e.UseProxy = 305] = "UseProxy", e[e.Unused = 306] = "Unused", e[e.TemporaryRedirect = 307] = "TemporaryRedirect", e[e.PermanentRedirect = 308] = "PermanentRedirect", e[e.BadRequest = 400] = "BadRequest", e[e.Unauthorized = 401] = "Unauthorized", e[e.PaymentRequired = 402] = "PaymentRequired", e[e.Forbidden = 403] = "Forbidden", e[e.NotFound = 404] = "NotFound", e[e.MethodNotAllowed = 405] = "MethodNotAllowed", e[e.NotAcceptable = 406] = "NotAcceptable", e[e.ProxyAuthenticationRequired = 407] = "ProxyAuthenticationRequired", e[e.RequestTimeout = 408] = "RequestTimeout", e[e.Conflict = 409] = "Conflict", e[e.Gone = 410] = "Gone", e[e.LengthRequired = 411] = "LengthRequired", e[e.PreconditionFailed = 412] = "PreconditionFailed", e[e.PayloadTooLarge = 413] = "PayloadTooLarge", e[e.UriTooLong = 414] = "UriTooLong", e[e.UnsupportedMediaType = 415] = "UnsupportedMediaType", e[e.RangeNotSatisfiable = 416] = "RangeNotSatisfiable", e[e.ExpectationFailed = 417] = "ExpectationFailed", e[e.ImATeapot = 418] = "ImATeapot", e[e.MisdirectedRequest = 421] = "MisdirectedRequest", e[e.UnprocessableEntity = 422] = "UnprocessableEntity", e[e.Locked = 423] = "Locked", e[e.FailedDependency = 424] = "FailedDependency", e[e.TooEarly = 425] = "TooEarly", e[e.UpgradeRequired = 426] = "UpgradeRequired", e[e.PreconditionRequired = 428] = "PreconditionRequired", e[e.TooManyRequests = 429] = "TooManyRequests", e[e.RequestHeaderFieldsTooLarge = 431] = "RequestHeaderFieldsTooLarge", e[e.UnavailableForLegalReasons = 451] = "UnavailableForLegalReasons", e[e.InternalServerError = 500] = "InternalServerError", e[e.NotImplemented = 501] = "NotImplemented", e[e.BadGateway = 502] = "BadGateway", e[e.ServiceUnavailable = 503] = "ServiceUnavailable", e[e.GatewayTimeout = 504] = "GatewayTimeout", e[e.HttpVersionNotSupported = 505] = "HttpVersionNotSupported", e[e.VariantAlsoNegotiates = 506] = "VariantAlsoNegotiates", e[e.InsufficientStorage = 507] = "InsufficientStorage", e[e.LoopDetected = 508] = "LoopDetected", e[e.NotExtended = 510] = "NotExtended", e[e.NetworkAuthenticationRequired = 511] = "NetworkAuthenticationRequired", e))(E || {});
|
|
200
218
|
class ae {
|
|
201
219
|
send(r) {
|
|
202
|
-
return new m((
|
|
203
|
-
const
|
|
204
|
-
return this._send(r,
|
|
220
|
+
return new m((n) => {
|
|
221
|
+
const t = new AbortController();
|
|
222
|
+
return this._send(r, n, t).then(() => {
|
|
205
223
|
}, (s) => {
|
|
206
|
-
|
|
224
|
+
n.error(new y({
|
|
207
225
|
error: s
|
|
208
226
|
}));
|
|
209
|
-
}), () =>
|
|
227
|
+
}), () => t.abort();
|
|
210
228
|
});
|
|
211
229
|
}
|
|
212
|
-
async _send(r,
|
|
213
|
-
var h,
|
|
230
|
+
async _send(r, n, t) {
|
|
231
|
+
var h, w;
|
|
214
232
|
let s;
|
|
215
233
|
try {
|
|
216
|
-
const
|
|
234
|
+
const d = this._parseFetchParamsFromRequest(r);
|
|
217
235
|
s = await fetch(r.getUrlWithParams(), {
|
|
218
|
-
signal:
|
|
219
|
-
...
|
|
236
|
+
signal: t.signal,
|
|
237
|
+
...d
|
|
220
238
|
});
|
|
221
|
-
} catch (
|
|
222
|
-
|
|
223
|
-
error:
|
|
224
|
-
status: (h =
|
|
225
|
-
statusText: (
|
|
226
|
-
headers:
|
|
239
|
+
} catch (d) {
|
|
240
|
+
n.error(new y({
|
|
241
|
+
error: d,
|
|
242
|
+
status: (h = d.status) != null ? h : 0,
|
|
243
|
+
statusText: (w = d.statusText) != null ? w : "Unknown Error",
|
|
244
|
+
headers: d.headers
|
|
227
245
|
}));
|
|
228
246
|
return;
|
|
229
247
|
}
|
|
230
|
-
const
|
|
231
|
-
let
|
|
232
|
-
s.body && (
|
|
233
|
-
body:
|
|
234
|
-
headers:
|
|
248
|
+
const a = new u(s.headers), i = s.status, l = s.statusText;
|
|
249
|
+
let c = null;
|
|
250
|
+
s.body && (c = await this._readBody(r, s, n)), i >= E.Ok && i < E.MultipleChoices ? n.next(new x({
|
|
251
|
+
body: c,
|
|
252
|
+
headers: a,
|
|
235
253
|
status: i,
|
|
236
|
-
statusText:
|
|
237
|
-
})) :
|
|
238
|
-
error:
|
|
254
|
+
statusText: l
|
|
255
|
+
})) : n.error(new y({
|
|
256
|
+
error: c,
|
|
239
257
|
status: i,
|
|
240
|
-
statusText:
|
|
241
|
-
headers:
|
|
242
|
-
})),
|
|
258
|
+
statusText: l,
|
|
259
|
+
headers: a
|
|
260
|
+
})), n.complete();
|
|
243
261
|
}
|
|
244
|
-
async _readBody(r,
|
|
245
|
-
var
|
|
246
|
-
const s = [],
|
|
262
|
+
async _readBody(r, n, t) {
|
|
263
|
+
var c;
|
|
264
|
+
const s = [], a = n.body.getReader();
|
|
247
265
|
let i = 0;
|
|
248
266
|
for (; ; ) {
|
|
249
|
-
const { done:
|
|
250
|
-
if (
|
|
267
|
+
const { done: o, value: h } = await a.read();
|
|
268
|
+
if (o)
|
|
251
269
|
break;
|
|
252
270
|
s.push(h), i += h.length;
|
|
253
271
|
}
|
|
254
|
-
const
|
|
272
|
+
const l = H(s, i);
|
|
255
273
|
try {
|
|
256
|
-
const
|
|
257
|
-
return
|
|
258
|
-
} catch (
|
|
259
|
-
return
|
|
260
|
-
error:
|
|
261
|
-
status:
|
|
262
|
-
statusText:
|
|
263
|
-
headers: new
|
|
274
|
+
const o = (c = n.headers.get("content-type")) != null ? c : "";
|
|
275
|
+
return C(r, l, o);
|
|
276
|
+
} catch (o) {
|
|
277
|
+
return t.error(new y({
|
|
278
|
+
error: o,
|
|
279
|
+
status: n.status,
|
|
280
|
+
statusText: n.statusText,
|
|
281
|
+
headers: new u(n.headers)
|
|
264
282
|
})), null;
|
|
265
283
|
}
|
|
266
284
|
}
|
|
@@ -273,23 +291,23 @@ class ae {
|
|
|
273
291
|
};
|
|
274
292
|
}
|
|
275
293
|
}
|
|
276
|
-
function
|
|
277
|
-
const
|
|
278
|
-
let
|
|
294
|
+
function H(e, r) {
|
|
295
|
+
const n = new Uint8Array(r);
|
|
296
|
+
let t = 0;
|
|
279
297
|
for (const s of e)
|
|
280
|
-
|
|
281
|
-
return
|
|
298
|
+
n.set(s, t), t += s.length;
|
|
299
|
+
return n;
|
|
282
300
|
}
|
|
283
|
-
const
|
|
284
|
-
function
|
|
301
|
+
const S = /^\)\]\}',?\n/;
|
|
302
|
+
function C(e, r, n) {
|
|
285
303
|
switch (e.responseType) {
|
|
286
304
|
case "json":
|
|
287
|
-
const
|
|
288
|
-
return
|
|
305
|
+
const t = new TextDecoder().decode(r).replace(S, "");
|
|
306
|
+
return t === "" ? null : JSON.parse(t);
|
|
289
307
|
case "text":
|
|
290
308
|
return new TextDecoder().decode(r);
|
|
291
309
|
case "blob":
|
|
292
|
-
return new Blob([r], { type:
|
|
310
|
+
return new Blob([r], { type: n });
|
|
293
311
|
case "arraybuffer":
|
|
294
312
|
return r.buffer;
|
|
295
313
|
default:
|
|
@@ -298,128 +316,128 @@ function T(e, r, t) {
|
|
|
298
316
|
}
|
|
299
317
|
class ce {
|
|
300
318
|
send(r) {
|
|
301
|
-
return new m((
|
|
302
|
-
const
|
|
303
|
-
|
|
319
|
+
return new m((n) => {
|
|
320
|
+
const t = new XMLHttpRequest();
|
|
321
|
+
t.open(r.method, r.getUrlWithParams()), r.withCredentials && (t.withCredentials = !0), r.headers.forEach((c, o) => t.setRequestHeader(c, o.join(","))), r.headers.has("Accept") || t.setRequestHeader("Accept", "application/json, text/plain, */*"), r.headers.has("Content-Type") || t.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
304
322
|
const s = () => {
|
|
305
|
-
const
|
|
306
|
-
return new
|
|
307
|
-
},
|
|
308
|
-
const { headers:
|
|
309
|
-
let
|
|
310
|
-
h !==
|
|
311
|
-
let
|
|
312
|
-
if (
|
|
313
|
-
const
|
|
323
|
+
const c = t.statusText || "OK", o = new u(t.getAllResponseHeaders());
|
|
324
|
+
return new J(o, t.status, c);
|
|
325
|
+
}, a = () => {
|
|
326
|
+
const { headers: c, statusText: o, status: h } = s(), { responseType: w } = r;
|
|
327
|
+
let d = null, _ = null;
|
|
328
|
+
h !== E.NoContent && (d = typeof t.response > "u" ? t.responseText : t.response);
|
|
329
|
+
let b = h >= Z && h < P;
|
|
330
|
+
if (w === "json" && typeof d == "string") {
|
|
331
|
+
const F = d;
|
|
314
332
|
try {
|
|
315
|
-
|
|
316
|
-
} catch (
|
|
317
|
-
|
|
333
|
+
d = d ? JSON.parse(d) : null;
|
|
334
|
+
} catch (M) {
|
|
335
|
+
b = !1, d = F, _ = M;
|
|
318
336
|
}
|
|
319
337
|
}
|
|
320
|
-
|
|
321
|
-
new
|
|
322
|
-
body:
|
|
323
|
-
headers:
|
|
338
|
+
b ? n.next(
|
|
339
|
+
new x({
|
|
340
|
+
body: d,
|
|
341
|
+
headers: c,
|
|
324
342
|
status: h,
|
|
325
|
-
statusText:
|
|
343
|
+
statusText: o
|
|
326
344
|
})
|
|
327
|
-
) :
|
|
328
|
-
new
|
|
329
|
-
error:
|
|
330
|
-
headers:
|
|
345
|
+
) : n.error(
|
|
346
|
+
new y({
|
|
347
|
+
error: _,
|
|
348
|
+
headers: c,
|
|
331
349
|
status: h,
|
|
332
|
-
statusText:
|
|
350
|
+
statusText: o
|
|
333
351
|
})
|
|
334
352
|
);
|
|
335
|
-
}, i = (
|
|
336
|
-
const
|
|
337
|
-
error:
|
|
338
|
-
status:
|
|
339
|
-
statusText:
|
|
353
|
+
}, i = (c) => {
|
|
354
|
+
const o = new y({
|
|
355
|
+
error: c,
|
|
356
|
+
status: t.status || 0,
|
|
357
|
+
statusText: t.statusText || "Unknown Error",
|
|
340
358
|
headers: s().headers
|
|
341
359
|
});
|
|
342
|
-
|
|
360
|
+
n.error(o);
|
|
343
361
|
};
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
return
|
|
347
|
-
|
|
362
|
+
t.addEventListener("load", a), t.addEventListener("error", i), t.addEventListener("abort", i), t.addEventListener("timeout", i);
|
|
363
|
+
const l = r.getBody();
|
|
364
|
+
return t.send(l), () => {
|
|
365
|
+
t.readyState !== t.DONE && t.abort(), t.removeEventListener("load", a), t.removeEventListener("error", i), t.removeEventListener("abort", i), t.removeEventListener("timeout", i);
|
|
348
366
|
};
|
|
349
367
|
});
|
|
350
368
|
}
|
|
351
369
|
}
|
|
352
|
-
const
|
|
353
|
-
class
|
|
370
|
+
const oe = U("univer.socket");
|
|
371
|
+
class le extends q {
|
|
354
372
|
createSocket(r) {
|
|
355
373
|
try {
|
|
356
|
-
const
|
|
374
|
+
const n = new WebSocket(r), t = new D();
|
|
357
375
|
return {
|
|
358
376
|
URL: r,
|
|
359
|
-
close: (
|
|
360
|
-
|
|
377
|
+
close: (a, i) => {
|
|
378
|
+
n.close(a, i), t.dispose();
|
|
361
379
|
},
|
|
362
|
-
send: (
|
|
363
|
-
|
|
380
|
+
send: (a) => {
|
|
381
|
+
n.send(a);
|
|
364
382
|
},
|
|
365
|
-
open$: new m((
|
|
366
|
-
const i = (
|
|
367
|
-
|
|
368
|
-
}).pipe(
|
|
369
|
-
close$: new m((
|
|
370
|
-
const i = (
|
|
371
|
-
|
|
372
|
-
}).pipe(
|
|
373
|
-
error$: new m((
|
|
374
|
-
const i = (
|
|
375
|
-
|
|
376
|
-
}).pipe(
|
|
377
|
-
message$: new m((
|
|
378
|
-
const i = (
|
|
379
|
-
|
|
380
|
-
}).pipe(
|
|
383
|
+
open$: new m((a) => {
|
|
384
|
+
const i = (l) => a.next(l);
|
|
385
|
+
n.addEventListener("open", i), t.add(f(() => n.removeEventListener("open", i)));
|
|
386
|
+
}).pipe(g()),
|
|
387
|
+
close$: new m((a) => {
|
|
388
|
+
const i = (l) => a.next(l);
|
|
389
|
+
n.addEventListener("close", i), t.add(f(() => n.removeEventListener("close", i)));
|
|
390
|
+
}).pipe(g()),
|
|
391
|
+
error$: new m((a) => {
|
|
392
|
+
const i = (l) => a.next(l);
|
|
393
|
+
n.addEventListener("error", i), t.add(f(() => n.removeEventListener("error", i)));
|
|
394
|
+
}).pipe(g()),
|
|
395
|
+
message$: new m((a) => {
|
|
396
|
+
const i = (l) => a.next(l);
|
|
397
|
+
n.addEventListener("message", i), t.add(f(() => n.removeEventListener("message", i)));
|
|
398
|
+
}).pipe(g())
|
|
381
399
|
};
|
|
382
|
-
} catch (
|
|
383
|
-
return console.error(
|
|
400
|
+
} catch (n) {
|
|
401
|
+
return console.error(n), null;
|
|
384
402
|
}
|
|
385
403
|
}
|
|
386
404
|
}
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
405
|
+
const T = 2, ee = 1e3, he = (e, r) => r(e).pipe(
|
|
406
|
+
W((n) => n.pipe(
|
|
407
|
+
v((t, s) => s > T ? $(t) : R(t)),
|
|
408
|
+
G(ee)
|
|
391
409
|
))
|
|
392
410
|
), de = (e, r) => {
|
|
393
|
-
const
|
|
394
|
-
var
|
|
395
|
-
for (;
|
|
396
|
-
const i =
|
|
397
|
-
|
|
411
|
+
const n = [], t = /* @__PURE__ */ new Set(), s = () => {
|
|
412
|
+
var a;
|
|
413
|
+
for (; t.size < ((a = r == null ? void 0 : r.maxParallel) != null ? a : 1) && n.length > 0; ) {
|
|
414
|
+
const i = n.shift();
|
|
415
|
+
t.add(i), i();
|
|
398
416
|
}
|
|
399
417
|
};
|
|
400
|
-
return (
|
|
401
|
-
const
|
|
402
|
-
next: (h) =>
|
|
403
|
-
error: (h) =>
|
|
404
|
-
complete: () =>
|
|
405
|
-
}),
|
|
406
|
-
|
|
418
|
+
return (a, i) => new m((l) => {
|
|
419
|
+
const c = () => i(a).subscribe({
|
|
420
|
+
next: (h) => l.next(h),
|
|
421
|
+
error: (h) => l.next(h),
|
|
422
|
+
complete: () => l.complete()
|
|
423
|
+
}), o = () => {
|
|
424
|
+
t.delete(c), N(n, c), s();
|
|
407
425
|
};
|
|
408
|
-
return
|
|
426
|
+
return n.push(c), s(), o;
|
|
409
427
|
});
|
|
410
428
|
};
|
|
411
429
|
export {
|
|
412
430
|
ae as FetchHTTPImplementation,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
431
|
+
u as HTTPHeaders,
|
|
432
|
+
k as HTTPRequest,
|
|
433
|
+
x as HTTPResponse,
|
|
434
|
+
y as HTTPResponseError,
|
|
435
|
+
A as HTTPService,
|
|
436
|
+
E as HTTPStatusCode,
|
|
437
|
+
X as IHTTPImplementation,
|
|
438
|
+
oe as ISocketService,
|
|
421
439
|
de as ThresholdInterceptorFactory,
|
|
422
|
-
|
|
440
|
+
le as WebSocketService,
|
|
423
441
|
ce as XHRHTTPImplementation,
|
|
424
|
-
|
|
442
|
+
he as retryInterceptor
|
|
425
443
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Disposable } from '@univerjs/core';
|
|
2
2
|
import { IDisposable } from '@wendellhu/redi';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
3
4
|
import { HTTPResponseType } from './http';
|
|
4
5
|
import { IHTTPImplementation } from './implementations/implementation';
|
|
6
|
+
import { HTTPRequestMethod } from './request';
|
|
5
7
|
import { HTTPResponse } from './response';
|
|
6
8
|
import { HTTPInterceptorFn } from './interceptor';
|
|
7
9
|
|
|
@@ -55,6 +57,8 @@ export declare class HTTPService extends Disposable {
|
|
|
55
57
|
post<T>(url: string, options?: IPostRequestParams): Promise<HTTPResponse<T>>;
|
|
56
58
|
put<T>(url: string, options?: IPostRequestParams): Promise<HTTPResponse<T>>;
|
|
57
59
|
delete<T>(url: string, options?: IRequestParams): Promise<HTTPResponse<T>>;
|
|
60
|
+
patch<T>(url: string, options?: IPostRequestParams): Promise<HTTPResponse<T>>;
|
|
61
|
+
getSSE<T>(method: HTTPRequestMethod, url: string, options?: IPostRequestParams): Observable<HTTPResponse<T>>;
|
|
58
62
|
/** The HTTP request implementations */
|
|
59
63
|
private _request;
|
|
60
64
|
private _runInterceptorsAndImplementation;
|
|
@@ -2,7 +2,7 @@ import { HTTPHeaders } from './headers';
|
|
|
2
2
|
import { HTTPResponseType } from './http';
|
|
3
3
|
import { HTTPParams } from './params';
|
|
4
4
|
|
|
5
|
-
export type HTTPRequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
5
|
+
export type HTTPRequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
6
6
|
export interface IHTTPRequestParams {
|
|
7
7
|
body?: any;
|
|
8
8
|
headers: HTTPHeaders;
|
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`).forEach(n=>{const[r,s]=n.split(":");r&&s&&this._setHeader(r,s)})}_handleHeadersConstructorProps(t){Object.keys(t).forEach(([n,r])=>{this._setHeader(n,r)})}_handleHeaders(t){t.forEach((n,r)=>{this._setHeader(r,n)})}}const L=E.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 x=0;class q{constructor(t,n,r){u(this,"uid",x++);this.method=t,this.url=n,this.requestParams=r}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var n,r;const t=(r=(n=this.requestParams)==null?void 0:n.params)==null?void 0:r.toString();return t?`${this.url}${this.url.includes("?")?"&":"?"}${t}`:this.url}getBody(){var r,s;const t=(r=this.headers.get("Content-Type"))!=null?r:I,n=(s=this.requestParams)==null?void 0:s.body;return t===I&&n&&typeof n=="object"?JSON.stringify(n):n?`${n}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}class _{constructor({body:t,headers:n,status:r,statusText:s}){u(this,"body");u(this,"headers");u(this,"status");u(this,"statusText");this.body=t,this.headers=n,this.status=r,this.statusText=s}}class w{constructor({headers:t,status:n,statusText:r,error:s}){u(this,"headers");u(this,"status");u(this,"statusText");u(this,"error");this.headers=t,this.status=n,this.statusText=r,this.error=s}}class U{constructor(t,n,r){this.headers=t,this.status=n,this.statusText=r}}var k=Object.defineProperty,F=Object.getOwnPropertyDescriptor,O=(e,t,n,r)=>{for(var s=r>1?void 0:r?F(t,n):t,o=e.length-1,i;o>=0;o--)(i=e[o])&&(s=(r?i(t,n,s):i(s))||s);return r&&s&&k(t,n,s),s},M=(e,t)=>(n,r)=>t(n,r,e);a.HTTPService=class extends c.Disposable{constructor(n){super();u(this,"_interceptors",[]);u(this,"_pipe");this._http=n}registerHTTPInterceptor(n){if(this._interceptors.indexOf(n)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(n),this._interceptors=this._interceptors.sort((r,s)=>{var o,i;return((o=r.priority)!=null?o:0)-((i=s.priority)!=null?i:0)}),this._pipe=null,c.toDisposable(()=>c.remove(this._interceptors,n))}get(n,r){return this._request("GET",n,r)}post(n,r){return this._request("POST",n,r)}put(n,r){return this._request("PUT",n,r)}delete(n,r){return this._request("DELETE",n,r)}async _request(n,r,s){var p,v;const o=new g(s==null?void 0:s.headers),i=new A(s==null?void 0:s.params),d=new q(n,r,{headers:o,params:i,withCredentials:(p=s==null?void 0:s.withCredentials)!=null?p:!1,responseType:(v=s==null?void 0:s.responseType)!=null?v:"json",body:n==="GET"||s==null?void 0:s.body}),l=m.of(d).pipe(f.concatMap(y=>this._runInterceptorsAndImplementation(y))),h=await m.firstValueFrom(l);if(h instanceof _)return h;throw new Error(`${h.error}`)}_runInterceptorsAndImplementation(n){return this._pipe||(this._pipe=this._interceptors.map(r=>r.interceptor).reduceRight((r,s)=>D(r,s),(r,s)=>s(r))),this._pipe(n,r=>this._http.send(r))}},a.HTTPService=O([M(0,L)],a.HTTPService);function D(e,t){return(n,r)=>t(n,s=>e(s,r))}const j=200,B=300;var b=(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))(b||{});class ${send(t){return new m.Observable(n=>{const r=new AbortController;return this._send(t,n,r).then(()=>{},s=>{n.error(new w({error:s}))}),()=>r.abort()})}async _send(t,n,r){var p,v;let s;try{const y=this._parseFetchParamsFromRequest(t);s=await fetch(t.getUrlWithParams(),{signal:r.signal,...y})}catch(y){n.error(new w({error:y,status:(p=y.status)!=null?p:0,statusText:(v=y.statusText)!=null?v:"Unknown Error",headers:y.headers}));return}const o=new g(s.headers),i=s.status,d=s.statusText;let l=null;s.body&&(l=await this._readBody(t,s,n)),i>=b.Ok&&i<b.MultipleChoices?n.next(new _({body:l,headers:o,status:i,statusText:d})):n.error(new w({error:l,status:i,statusText:d,headers:o})),n.complete()}async _readBody(t,n,r){var l;const s=[],o=n.body.getReader();let i=0;for(;;){const{done:h,value:p}=await o.read();if(h)break;s.push(p),i+=p.length}const d=G(s,i);try{const h=(l=n.headers.get("content-type"))!=null?l:"";return V(t,d,h)}catch(h){return r.error(new w({error:h,status:n.status,statusText:n.statusText,headers:new g(n.headers)})),null}}_parseFetchParamsFromRequest(t){return{method:t.method,headers:t.getHeadersInit(),body:t.getBody(),credentials:t.withCredentials?"include":void 0}}}function G(e,t){const n=new Uint8Array(t);let r=0;for(const s of e)n.set(s,r),r+=s.length;return n}const W=/^\)\]\}',?\n/;function V(e,t,n){switch(e.responseType){case"json":const r=new TextDecoder().decode(t).replace(W,"");return r===""?null:JSON.parse(r);case"text":return new TextDecoder().decode(t);case"blob":return new Blob([t],{type:n});case"arraybuffer":return t.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class X{send(t){return new m.Observable(n=>{const r=new XMLHttpRequest;r.open(t.method,t.getUrlWithParams()),t.withCredentials&&(r.withCredentials=!0),t.headers.forEach((l,h)=>r.setRequestHeader(l,h.join(","))),t.headers.has("Accept")||r.setRequestHeader("Accept","application/json, text/plain, */*"),t.headers.has("Content-Type")||r.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const l=r.statusText||"OK",h=new g(r.getAllResponseHeaders());return new U(h,r.status,l)},o=()=>{const{headers:l,statusText:h,status:p}=s(),{responseType:v}=t;let y=null,R=null;p!==b.NoContent&&(y=typeof r.response>"u"?r.responseText:r.response);let N=p>=j&&p<B;if(v==="json"&&typeof y=="string"){const P=y;try{y=y?JSON.parse(y):null}catch(H){N=!1,y=P,R=H}}N?n.next(new _({body:y,headers:l,status:p,statusText:h})):n.next(new w({error:R,headers:l,status:p,statusText:h}))},i=l=>{const h=new w({error:l,status:r.status||0,statusText:r.statusText||"Unknown Error",headers:s().headers});n.next(h)};r.addEventListener("load",o),r.addEventListener("error",i),r.addEventListener("abort",i),r.addEventListener("timeout",i);const d=t.getBody();return r.send(d),()=>{r.readyState!==r.DONE&&r.abort(),r.removeEventListener("load",o),r.removeEventListener("error",i),r.removeEventListener("abort",i),r.removeEventListener("timeout",i)}})}}const z=E.createIdentifier("univer.socket");class J extends c.Disposable{createSocket(t){try{const n=new WebSocket(t),r=new c.DisposableCollection;return{URL:t,close:(o,i)=>{n.close(o,i),r.dispose()},send:o=>{n.send(o)},open$:new m.Observable(o=>{const i=d=>o.next(d);n.addEventListener("open",i),r.add(c.toDisposable(()=>n.removeEventListener("open",i)))}).pipe(f.share()),close$:new m.Observable(o=>{const i=d=>o.next(d);n.addEventListener("close",i),r.add(c.toDisposable(()=>n.removeEventListener("close",i)))}).pipe(f.share()),error$:new m.Observable(o=>{const i=d=>o.next(d);n.addEventListener("error",i),r.add(c.toDisposable(()=>n.removeEventListener("error",i)))}).pipe(f.share()),message$:new m.Observable(o=>{const i=d=>o.next(d);n.addEventListener("message",i),r.add(c.toDisposable(()=>n.removeEventListener("message",i)))}).pipe(f.share())}}catch(n){return console.error(n),null}}}const Y=2,K=1e3,Q=(e,t)=>t(e).pipe(f.retryWhen(n=>n.pipe(f.concatMap((r,s)=>s>Y?m.throwError(r):m.of(r)),m.delay(K)))),Z=(e,t)=>{const n=[],r=new Set,s=()=>{var o;for(;r.size<((o=t==null?void 0:t.maxParallel)!=null?o:1)&&n.length>0;){const i=n.shift();r.add(i),i()}};return(o,i)=>new m.Observable(d=>{const l=()=>i(o).subscribe({next:p=>d.next(p),error:p=>d.next(p),complete:()=>d.complete()}),h=()=>{r.delete(l),c.remove(n,l),s()};return n.push(l),s(),h})};a.FetchHTTPImplementation=$,a.HTTPHeaders=g,a.HTTPRequest=q,a.HTTPResponse=_,a.HTTPResponseError=w,a.HTTPStatusCode=b,a.IHTTPImplementation=L,a.ISocketService=z,a.ThresholdInterceptorFactory=Z,a.WebSocketService=J,a.XHRHTTPImplementation=X,a.retryInterceptor=Q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(c,d){typeof exports=="object"&&typeof module<"u"?d(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"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c.UniverNetwork={},c.UniverCore,c.rxjs,c.rxjs.operators,c["@wendellhu/redi"]))})(this,function(c,d,y,f,I){"use strict";var P=Object.defineProperty;var H=(c,d,y)=>d in c?P(c,d,{enumerable:!0,configurable:!0,writable:!0,value:y}):c[d]=y;var u=(c,d,y)=>(H(c,typeof d!="symbol"?d+"":d,y),y);const L="application/json";class g{constructor(t){u(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((n,r)=>t(r,n))}has(t){return!!this._headers.has(t.toLowerCase())}get(t){const n=t.toLowerCase();return this._headers.has(n)?this._headers.get(n):null}toHeadersInit(){var n,r;const t={};return this._headers.forEach((s,a)=>{t[a]=s.join(",")}),(n=t.accept)!=null||(t.accept="application/json, text/plain, */*"),(r=t["content-type"])!=null||(t["content-type"]="application/json;charset=UTF-8"),t}_setHeader(t,n){const r=t.toLowerCase();this._headers.has(r)?this._headers.get(r).push(n.toString()):this._headers.set(r,[n.toString()])}_handleHeadersString(t){t.split(`
|
|
2
|
+
`).forEach(n=>{const[r,s]=n.split(":");r&&s&&this._setHeader(r,s)})}_handleHeadersConstructorProps(t){Object.entries(t).forEach(([n,r])=>this._setHeader(n,r))}_handleHeaders(t){t.forEach((n,r)=>this._setHeader(r,n))}}const q=I.createIdentifier("network.http-implementation");class k{constructor(t){this.params=t}toString(){return this.params?Object.keys(this.params).map(t=>`${t}=${this.params[t]}`).join("&"):""}}let N=0;class R{constructor(t,n,r){u(this,"uid",N++);this.method=t,this.url=n,this.requestParams=r}get headers(){return this.requestParams.headers}get withCredentials(){return this.requestParams.withCredentials}get responseType(){return this.requestParams.responseType}getUrlWithParams(){var n,r;const t=(r=(n=this.requestParams)==null?void 0:n.params)==null?void 0:r.toString();return t?`${this.url}${this.url.includes("?")?"&":"?"}${t}`:this.url}getBody(){var r,s;const t=(r=this.headers.get("Content-Type"))!=null?r:L,n=(s=this.requestParams)==null?void 0:s.body;return t===L&&n&&typeof n=="object"?JSON.stringify(n):n?`${n}`:null}getHeadersInit(){return this.headers.toHeadersInit()}}class b{constructor({body:t,headers:n,status:r,statusText:s}){u(this,"body");u(this,"headers");u(this,"status");u(this,"statusText");this.body=t,this.headers=n,this.status=r,this.statusText=s}}class w{constructor({headers:t,status:n,statusText:r,error:s}){u(this,"headers");u(this,"status");u(this,"statusText");u(this,"error");this.headers=t,this.status=n,this.statusText=r,this.error=s}}class U{constructor(t,n,r){this.headers=t,this.status=n,this.statusText=r}}var F=(e,t,n,r)=>{for(var s=t,a=e.length-1,i;a>=0;a--)(i=e[a])&&(s=i(s)||s);return s},x=(e,t)=>(n,r)=>t(n,r,e);c.HTTPService=class extends d.Disposable{constructor(n){super();u(this,"_interceptors",[]);u(this,"_pipe");this._http=n}registerHTTPInterceptor(n){if(this._interceptors.indexOf(n)!==-1)throw new Error("[HTTPService]: The interceptor has already been registered!");return this._interceptors.push(n),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,d.toDisposable(()=>d.remove(this._interceptors,n))}get(n,r){return this._request("GET",n,r)}post(n,r){return this._request("POST",n,r)}put(n,r){return this._request("PUT",n,r)}delete(n,r){return this._request("DELETE",n,r)}patch(n,r){return this._request("PATCH",n,r)}getSSE(n,r,s){var l,h;const a=new g(s==null?void 0:s.headers),i=new k(s==null?void 0:s.params),p=new R(n,r,{headers:a,params:i,withCredentials:(l=s==null?void 0:s.withCredentials)!=null?l:!1,responseType:(h=s==null?void 0:s.responseType)!=null?h:"json",body:["GET","DELETE"].includes(n)||s==null?void 0:s.body});return y.of(p).pipe(f.concatMap(o=>this._runInterceptorsAndImplementation(o)),f.map(o=>{if(o instanceof w)throw o;return o}))}async _request(n,r,s){var o,v;const a=new g(s==null?void 0:s.headers),i=new k(s==null?void 0:s.params),p=new R(n,r,{headers:a,params:i,withCredentials:(o=s==null?void 0:s.withCredentials)!=null?o:!1,responseType:(v=s==null?void 0:s.responseType)!=null?v:"json",body:["GET","DELETE"].includes(n)||s==null?void 0:s.body}),l=y.of(p).pipe(f.concatMap(m=>this._runInterceptorsAndImplementation(m))),h=await y.firstValueFrom(l);if(h instanceof b)return h;throw new Error(`${h.error}`)}_runInterceptorsAndImplementation(n){return this._pipe||(this._pipe=this._interceptors.map(r=>r.interceptor).reduceRight((r,s)=>M(r,s),(r,s)=>s(r))),this._pipe(n,r=>this._http.send(r))}},c.HTTPService=F([x(0,q)],c.HTTPService);function M(e,t){return(n,r)=>t(n,s=>e(s,r))}const O=200,D=300;var E=(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))(E||{});class j{send(t){return new y.Observable(n=>{const r=new AbortController;return this._send(t,n,r).then(()=>{},s=>{n.error(new w({error:s}))}),()=>r.abort()})}async _send(t,n,r){var o,v;let s;try{const m=this._parseFetchParamsFromRequest(t);s=await fetch(t.getUrlWithParams(),{signal:r.signal,...m})}catch(m){n.error(new w({error:m,status:(o=m.status)!=null?o:0,statusText:(v=m.statusText)!=null?v:"Unknown Error",headers:m.headers}));return}const a=new g(s.headers),i=s.status,p=s.statusText;let l=null;s.body&&(l=await this._readBody(t,s,n)),i>=E.Ok&&i<E.MultipleChoices?n.next(new b({body:l,headers:a,status:i,statusText:p})):n.error(new w({error:l,status:i,statusText:p,headers:a})),n.complete()}async _readBody(t,n,r){var l;const s=[],a=n.body.getReader();let i=0;for(;;){const{done:h,value:o}=await a.read();if(h)break;s.push(o),i+=o.length}const p=B(s,i);try{const h=(l=n.headers.get("content-type"))!=null?l:"";return G(t,p,h)}catch(h){return r.error(new w({error:h,status:n.status,statusText:n.statusText,headers:new g(n.headers)})),null}}_parseFetchParamsFromRequest(t){return{method:t.method,headers:t.getHeadersInit(),body:t.getBody(),credentials:t.withCredentials?"include":void 0}}}function B(e,t){const n=new Uint8Array(t);let r=0;for(const s of e)n.set(s,r),r+=s.length;return n}const $=/^\)\]\}',?\n/;function G(e,t,n){switch(e.responseType){case"json":const r=new TextDecoder().decode(t).replace($,"");return r===""?null:JSON.parse(r);case"text":return new TextDecoder().decode(t);case"blob":return new Blob([t],{type:n});case"arraybuffer":return t.buffer;default:throw new Error(`[FetchHTTPImplementation]: unknown response type: ${e.responseType}.`)}}class W{send(t){return new y.Observable(n=>{const r=new XMLHttpRequest;r.open(t.method,t.getUrlWithParams()),t.withCredentials&&(r.withCredentials=!0),t.headers.forEach((l,h)=>r.setRequestHeader(l,h.join(","))),t.headers.has("Accept")||r.setRequestHeader("Accept","application/json, text/plain, */*"),t.headers.has("Content-Type")||r.setRequestHeader("Content-Type","application/json;charset=UTF-8");const s=()=>{const l=r.statusText||"OK",h=new g(r.getAllResponseHeaders());return new U(h,r.status,l)},a=()=>{const{headers:l,statusText:h,status:o}=s(),{responseType:v}=t;let m=null,_=null;o!==E.NoContent&&(m=typeof r.response>"u"?r.responseText:r.response);let A=o>=O&&o<D;if(v==="json"&&typeof m=="string"){const Q=m;try{m=m?JSON.parse(m):null}catch(Z){A=!1,m=Q,_=Z}}A?n.next(new b({body:m,headers:l,status:o,statusText:h})):n.error(new w({error:_,headers:l,status:o,statusText:h}))},i=l=>{const h=new w({error:l,status:r.status||0,statusText:r.statusText||"Unknown Error",headers:s().headers});n.error(h)};r.addEventListener("load",a),r.addEventListener("error",i),r.addEventListener("abort",i),r.addEventListener("timeout",i);const p=t.getBody();return r.send(p),()=>{r.readyState!==r.DONE&&r.abort(),r.removeEventListener("load",a),r.removeEventListener("error",i),r.removeEventListener("abort",i),r.removeEventListener("timeout",i)}})}}const V=I.createIdentifier("univer.socket");class X extends d.Disposable{createSocket(t){try{const n=new WebSocket(t),r=new d.DisposableCollection;return{URL:t,close:(a,i)=>{n.close(a,i),r.dispose()},send:a=>{n.send(a)},open$:new y.Observable(a=>{const i=p=>a.next(p);n.addEventListener("open",i),r.add(d.toDisposable(()=>n.removeEventListener("open",i)))}).pipe(f.share()),close$:new y.Observable(a=>{const i=p=>a.next(p);n.addEventListener("close",i),r.add(d.toDisposable(()=>n.removeEventListener("close",i)))}).pipe(f.share()),error$:new y.Observable(a=>{const i=p=>a.next(p);n.addEventListener("error",i),r.add(d.toDisposable(()=>n.removeEventListener("error",i)))}).pipe(f.share()),message$:new y.Observable(a=>{const i=p=>a.next(p);n.addEventListener("message",i),r.add(d.toDisposable(()=>n.removeEventListener("message",i)))}).pipe(f.share())}}catch(n){return console.error(n),null}}}const z=2,J=1e3,Y=(e,t)=>t(e).pipe(f.retryWhen(n=>n.pipe(f.concatMap((r,s)=>s>z?y.throwError(r):y.of(r)),y.delay(J)))),K=(e,t)=>{const n=[],r=new Set,s=()=>{var a;for(;r.size<((a=t==null?void 0:t.maxParallel)!=null?a:1)&&n.length>0;){const i=n.shift();r.add(i),i()}};return(a,i)=>new y.Observable(p=>{const l=()=>i(a).subscribe({next:o=>p.next(o),error:o=>p.next(o),complete:()=>p.complete()}),h=()=>{r.delete(l),d.remove(n,l),s()};return n.push(l),s(),h})};c.FetchHTTPImplementation=j,c.HTTPHeaders=g,c.HTTPRequest=R,c.HTTPResponse=b,c.HTTPResponseError=w,c.HTTPStatusCode=E,c.IHTTPImplementation=q,c.ISocketService=V,c.ThresholdInterceptorFactory=K,c.WebSocketService=X,c.XHRHTTPImplementation=W,c.retryInterceptor=Y,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.1.
|
|
3
|
+
"version": "0.1.13-nightly.202406041140",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -51,16 +51,16 @@
|
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@wendellhu/redi": "0.15.2",
|
|
53
53
|
"rxjs": ">=7.0.0",
|
|
54
|
-
"@univerjs/core": "0.1.
|
|
54
|
+
"@univerjs/core": "0.1.13-nightly.202406041140"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@wendellhu/redi": "0.15.2",
|
|
58
58
|
"rxjs": "^7.8.1",
|
|
59
59
|
"typescript": "^5.4.5",
|
|
60
|
-
"vite": "^5.2.
|
|
60
|
+
"vite": "^5.2.12",
|
|
61
61
|
"vitest": "^1.6.0",
|
|
62
|
-
"@univerjs/core": "0.1.
|
|
63
|
-
"@univerjs/shared": "0.1.
|
|
62
|
+
"@univerjs/core": "0.1.13-nightly.202406041140",
|
|
63
|
+
"@univerjs/shared": "0.1.13"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|