@opra/client 0.31.7 → 0.31.8
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/browser.js +3 -3
- package/cjs/http/fetch-backend.js +4 -1
- package/cjs/http/http-client-base.js +10 -0
- package/cjs/http/http-storage-node.js +35 -0
- package/esm/http/fetch-backend.js +5 -2
- package/esm/http/http-client-base.js +10 -0
- package/esm/http/http-storage-node.js +31 -0
- package/package.json +2 -2
- package/types/http/http-client-base.d.ts +3 -0
- package/types/http/http-storage-node.d.ts +14 -0
package/browser.js
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* http://www.panates.com
|
|
4
4
|
*****************************************/
|
|
5
5
|
|
|
6
|
-
var $=Object.defineProperty,se=Object.defineProperties;var ce=Object.getOwnPropertyDescriptors;var Y=Object.getOwnPropertySymbols;var le=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var Z=(l,r,e)=>r in l?$(l,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[r]=e,x=(l,r)=>{for(var e in r||(r={}))le.call(r,e)&&Z(l,e,r[e]);if(Y)for(var e of Y(r))de.call(r,e)&&Z(l,e,r[e]);return l},k=(l,r)=>se(l,ce(r)),d=(l,r)=>$(l,"name",{value:r,configurable:!0});var A=class A{constructor(r){this.api=r==null?void 0:r.api}};d(A,"Backend");var p=A;var he=Symbol.for("kClient"),f=Symbol.for("kBackend"),n=Symbol.for("kContext");var G=class G{constructor(r){Object.defineProperty(this,f,{enumerable:!1,value:r})}};d(G,"ClientBase");var j=G;var M=class M extends Error{constructor(r,e){super(r.message),this.cause=e,this.issues=r.issues||[],this.status=r.status,e&&(this.cause=e,e.stack&&(this.stack=e.stack))}};d(M,"ClientError");var S=M;import{Observable as me}from"rxjs";import{isReadableStreamLike as fe}from"rxjs/internal/util/isReadableStreamLike";import I from"@browsery/type-is";import{isBlob as ue,OpraURL as ne}from"@opra/common";var z=class z extends p{constructor(r,e){super(e),this.serviceUrl=r}};d(z,"HttpBackend");var R=z;var P=class P{constructor(r){this.hasBody=!1,this.headers=(r==null?void 0:r.headers)instanceof Headers?r==null?void 0:r.headers:new Headers(r==null?void 0:r.headers),this.status=(r==null?void 0:r.status)||200,this.statusText=(r==null?void 0:r.statusText)||"OK",this.url=(r==null?void 0:r.url)||null,this.ok=this.status>=200&&this.status<300,this.body=r==null?void 0:r.body,this.hasBody=(r==null?void 0:r.body)!=null||!!(r!=null&&r.hasBody),this.contentType=(this.headers.get("content-type")||"").split(";")[0]}clone(r){return new P(x(x({},this),r))}};d(P,"HttpResponse");var T=P;var i;(function(l){l.Sent="Sent",l.UploadProgress="UploadProgress",l.ResponseHeader="ResponseHeader",l.DownloadProgress="DownloadProgress",l.Response="Response",l.User="User"})(i||(i={}));var F=class F extends R{constructor(r,e){var t,s,a,c,h,g;super(r,e),this.interceptors=Array.from(new Set([...(e==null?void 0:e.interceptors)||[]])),this.defaults=k(x({},e==null?void 0:e.defaults),{headers:((t=e==null?void 0:e.defaults)==null?void 0:t.headers)instanceof Headers?(s=e==null?void 0:e.defaults)==null?void 0:s.headers:new Headers((a=e==null?void 0:e.defaults)==null?void 0:a.headers),params:((c=e==null?void 0:e.defaults)==null?void 0:c.params)instanceof URLSearchParams?(h=e==null?void 0:e.defaults)==null?void 0:h.params:new URLSearchParams((g=e==null?void 0:e.defaults)==null?void 0:g.params)})}handle(r){return new me(e=>{(async()=>{let t=this.prepareRequest(r);if(t.body&&r.reportProgress){let C=t.body,O=t.headers.get("content-length")||"0",D=parseInt(O,10)||0,w=0,q=new TransformStream({transform(b,H){H.enqueue(b),w+=b.byteLength,e.next({type:i.UploadProgress,request:t,total:D,loaded:w})}});t=new Request(t.url,{cache:t.cache,credentials:t.credentials,headers:t.headers,integrity:t.integrity,keepalive:t.keepalive,method:t.method,mode:t.mode,redirect:t.redirect,referrer:t.referrer,referrerPolicy:t.referrerPolicy,signal:t.signal,body:C.pipeThrough(q),window:r.window,duplex:"half"})}let s=this.send(t);e.next({request:t,type:i.Sent});let a=await s,c=this.createResponse({url:a.url,headers:a.headers,status:a.status,statusText:a.statusText,hasBody:!!a.body});e.next({request:t,type:i.ResponseHeader,response:c});let h;if(a.body)if(r.reportProgress){let C=a.body,O=a.headers.get("content-length")||"0",D=parseInt(O,10)||0,w=0,q=new Response(new ReadableStream({async start(b){let H=C.getReader();for(;;){let{done:ae,value:X}=await H.read();if(ae)break;w+=X.byteLength,b.enqueue(X),e.next({type:i.DownloadProgress,request:t,total:D,loaded:w})}b.close()}}));h=await this.parseBody(q)}else h=await this.parseBody(a);let g=this.createResponse({url:a.url,headers:a.headers,status:a.status,statusText:a.statusText,body:h});e.next({request:t,type:i.Response,response:g}),e.complete()})().catch(t=>e.error(t))})}send(r){return fetch(r)}prepareRequest(r){let e=r.headers||new Headers,t=k(x({},r),{headers:e});this.defaults.headers.forEach((c,h)=>{e.has(h)||e.set(h,c)});let s=new ne(t.url,this.serviceUrl);this.defaults.params.size&&(this.defaults.params.forEach((c,h)=>{s.searchParams.has(h)||s.searchParams.set(h,c)}),t.url=s.toString());let a=t.body;if(a){let c;typeof a=="string"||typeof a=="number"||typeof a=="boolean"?(c='text/plain; charset="UTF-8"',t.body=new Blob([String(a)],{type:c}),e.set("Content-Length",String(t.body.size)),delete t.duplex):fe(a)?(c="application/octet-stream",t.duplex="half"):Buffer.isBuffer(a)?(c="application/octet-stream",e.set("Content-Length",String(a.length)),delete t.duplex):ue(a)?(c=a.type||"application/octet-stream",e.set("Content-Length",String(a.size)),delete t.duplex):(c='application/json;charset="UTF-8"',t.body=new Blob([JSON.stringify(a)],{type:c}),e.set("Content-Length",String(t.body.size)),delete t.duplex),c&&!e.has("Content-Type")&&e.set("Content-Type",c)}return new Request(s.toString(),t)}createResponse(r){return new T(r)}async parseBody(r){let e,t=r.headers.get("Content-Type")||"";if(I.is(t,["json","application/*+json"]))e=await r.json(),typeof e=="string"&&(e=JSON.parse(e));else if(I.is(t,["text"]))e=await r.text();else if(I.is(t,["multipart"]))e=await r.formData();else{let s=await r.arrayBuffer();s.byteLength&&(e=s)}return e}};d(F,"FetchBackend");var v=F;import{ApiDocumentFactory as ge,ResponsiveMap as re}from"@opra/common";import{toArrayDef as u}from"putil-varhelpers";import{OpraURL as K}from"@opra/common";import{lastValueFrom as ee,Observable as ye}from"rxjs";import oe from"@browsery/type-is";import{OpraURL as xe}from"@opra/common";var y;(function(l){l.ResponseHeader="response-header",l.Response="response",l.Body="body",l.Events="events"})(y||(y={}));var J=class J{constructor(r,e){this.chain=r.reduceRight((t,s)=>(a,c)=>s.intercept(a,{handle:h=>t(h,c)}),ie),this.finalHandler=e}handle(r){return this.chain(r,e=>this.finalHandler.handle(e))}};d(J,"HttpInterceptorHandler");var E=J;function ie(l,r){return r(l)}d(ie,"chainEnd");var _=class _ extends ye{constructor(r,e){super(s=>{let a=this[n].observe;new E(r.interceptors||[],this[f]).handle(this[n]).subscribe({next(c){if(a===y.Events){s.next(c);return}if(a===y.ResponseHeader&&c.type===i.ResponseHeader){s.next(c.response),s.complete();return}if(c.type===i.Response){let{response:h}=c;if(a===y.Response){s.next(h),s.complete();return}let g=oe.is(c.response.contentType||"",["application/opra+json"]);if(h.status>=400&&h.status<600){s.error(new S({message:h.status+" "+h.statusText,status:h.status,issues:g?h.body.errors:void 0})),s.complete();return}s.next(c.response.body),s.complete()}},error(c){s.error(c)},complete(){s.complete()}})}),Object.defineProperty(this,f,{enumerable:!1,value:r});let t=new xe(e==null?void 0:e.url,r.serviceUrl.toString());Object.defineProperty(this,n,{enumerable:!1,value:k(x({},e),{observe:y.Body,headers:new Headers(e==null?void 0:e.headers),url:t})})}clone(){return new _(this[f],this[n])}options(r){return Object.assign(this[n],r),this}header(r,e){let t=this[n].headers;return typeof r=="object"?((r instanceof Headers?r:new Headers(r)).forEach((a,c)=>{c.toLowerCase()==="set-cookie"?t.append(c,a):t.set(c,a)}),this):(e==null||e===""?t.delete(r):t.append(r,String(e)),this)}param(r,e){e&&typeof e=="object"&&(e=JSON.stringify(e));let t=this[n].url.searchParams;return typeof r=="object"?((r instanceof URLSearchParams?r:new URLSearchParams(r)).forEach((a,c)=>t.set(c,a)),this):(e==null?t.delete(r):t.set(r,String(e)),this)}observe(r){if(r===this[n].observe)return this;let e=this.clone();return e[n].observe=r||y.Body,e}getBody(){return ee(this.observe(y.Body))}getResponse(){return ee(this.observe(y.Response))}};d(_,"HttpRequestObservable");var m=_;var N=class N{constructor(r,e){this._backend=r,this._path=e}create(r,e){let t=new m(this._backend,{method:"POST",url:this._path,body:r});return e!=null&&e.include&&t.param("include",u(e.include,[]).join(",")),e!=null&&e.pick&&t.param("pick",u(e.pick,[]).join(",")),e!=null&&e.omit&&t.param("omit",u(e.omit,[]).join(",")),t}delete(r){if(r==null||r==="")throw new TypeError("'id' argument must have a value");let e=new K;return e.join({resource:this._path,key:r}),new m(this._backend,{method:"DELETE",url:e})}deleteMany(r){let e=new m(this._backend,{method:"DELETE",url:this._path});return r!=null&&r.filter&&e.param("filter",String(r.filter)),e}get(r,e){if(r==null||r==="")throw new TypeError("'id' argument must have a value");let t=new K;t.join({resource:this._path,key:r});let s=new m(this._backend,{method:"GET",url:t});return e!=null&&e.include&&s.param("include",u(e.include,[]).join(",")),e!=null&&e.pick&&s.param("pick",u(e.pick,[]).join(",")),e!=null&&e.omit&&s.param("omit",u(e.omit,[]).join(",")),s}findMany(r){let e=new m(this._backend,{method:"GET",url:this._path});return r!=null&&r.include&&e.param("include",u(r.include,[]).join(",")),r!=null&&r.pick&&e.param("pick",u(r.pick,[]).join(",")),r!=null&&r.omit&&e.param("omit",u(r.omit,[]).join(",")),r!=null&&r.sort&&e.param("sort",u(r.sort,[]).join(",")),r!=null&&r.filter&&e.param("filter",String(r.filter)),(r==null?void 0:r.limit)!=null&&e.param("limit",String(r.limit)),(r==null?void 0:r.skip)!=null&&e.param("skip",String(r.skip)),(r==null?void 0:r.count)!=null&&e.param("count",String(r.count)),(r==null?void 0:r.distinct)!=null&&e.param("distinct",String(r.distinct)),e}update(r,e,t){if(r==null)throw new TypeError("'id' argument must have a value");let s=new K;s.join({resource:this._path,key:r});let a=new m(this._backend,{method:"PATCH",url:s,body:e});return t!=null&&t.include&&a.param("include",u(t.include,[]).join(",")),t!=null&&t.pick&&a.param("pick",u(t.pick,[]).join(",")),t!=null&&t.omit&&a.param("omit",u(t.omit,[]).join(",")),a}updateMany(r,e){let t=new m(this._backend,{method:"PATCH",url:this._path,body:r});return e!=null&&e.filter&&t.param("filter",String(e.filter)),t}};d(N,"HttpCollectionNode");var B=N;import{toArrayDef as o}from"putil-varhelpers";var V=class V{constructor(r,e){this._backend=r,this._path=e}create(r,e){let t=new m(this._backend,{method:"POST",url:this._path,body:r});return e!=null&&e.include&&t.param("include",o(e.include,[]).join(",")),e!=null&&e.pick&&t.param("pick",o(e.pick,[]).join(",")),e!=null&&e.omit&&t.param("omit",o(e.omit,[]).join(",")),t}delete(){return new m(this._backend,{method:"DELETE",url:this._path})}get(r){let e=new m(this._backend,{method:"GET",url:this._path});return r!=null&&r.include&&e.param("include",o(r.include,[]).join(",")),r!=null&&r.pick&&e.param("pick",o(r.pick,[]).join(",")),r!=null&&r.omit&&e.param("omit",o(r.omit,[]).join(",")),e}update(r,e){let t=new m(this._backend,{method:"PATCH",url:this._path,body:r});return e!=null&&e.include&&t.param("include",o(e.include,[]).join(",")),e!=null&&e.pick&&t.param("pick",o(e.pick,[]).join(",")),e!=null&&e.omit&&t.param("omit",o(e.omit,[]).join(",")),t}};d(V,"HttpSingletonNode");var L=V;var Q=class Q extends j{constructor(r){super(r),this._collectionCache=new re,this._singletonCache=new re}get serviceUrl(){return this[f].serviceUrl}async getMetadata(){if(this._metadataPromise)return this._metadataPromise;let r=new m(this[f],{method:"GET",url:"/",headers:new Headers({accept:"application/json"})}),e;try{this._metadataPromise=r.getBody(),e=await this._metadataPromise}catch(t){throw t.message="Error fetching metadata from url ("+this.serviceUrl+`).
|
|
7
|
-
`+t.message,t}finally{this._metadataPromise=void 0}try{let t=await
|
|
8
|
-
`+t.message,t}}collection(r){let e=this._collectionCache.get(r);return e||(e=new B(this[f],r),this._collectionCache.set(r,e)),e}singleton(r){let e=this._singletonCache.get(r);return e||(e=new L(this[f],r),this._singletonCache.set(r,e)),e}action(r,e){let t=new m(this[f],{method:"GET",url:r});return e&&(Object.keys(e).forEach(s=>e[s]=String(e[s])),t.param(e)),t}};
|
|
6
|
+
var te=Object.defineProperty,le=Object.defineProperties;var he=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable;var re=(h,r,e)=>r in h?te(h,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[r]=e,b=(h,r)=>{for(var e in r||(r={}))de.call(r,e)&&re(h,e,r[e]);if(ee)for(var e of ee(r))me.call(r,e)&&re(h,e,r[e]);return h},k=(h,r)=>le(h,he(r)),l=(h,r)=>te(h,"name",{value:r,configurable:!0});var G=class G{constructor(r){this.api=r==null?void 0:r.api}};l(G,"Backend");var p=G;var fe=Symbol.for("kClient"),f=Symbol.for("kBackend"),n=Symbol.for("kContext");var M=class M{constructor(r){Object.defineProperty(this,f,{enumerable:!1,value:r})}};l(M,"ClientBase");var j=M;var z=class z extends Error{constructor(r,e){super(r.message),this.cause=e,this.issues=r.issues||[],this.status=r.status,e&&(this.cause=e,e.stack&&(this.stack=e.stack))}};l(z,"ClientError");var S=z;import{Observable as ue}from"rxjs";import{isReadableStreamLike as ne}from"rxjs/internal/util/isReadableStreamLike";import I from"@browsery/type-is";import{isBlob as ie,isFormData as oe,OpraURL as ye}from"@opra/common";var F=class F extends p{constructor(r,e){super(e),this.serviceUrl=r}};l(F,"HttpBackend");var T=F;var _=class _{constructor(r){this.hasBody=!1,this.headers=(r==null?void 0:r.headers)instanceof Headers?r==null?void 0:r.headers:new Headers(r==null?void 0:r.headers),this.status=(r==null?void 0:r.status)||200,this.statusText=(r==null?void 0:r.statusText)||"OK",this.url=(r==null?void 0:r.url)||null,this.ok=this.status>=200&&this.status<300,this.body=r==null?void 0:r.body,this.hasBody=(r==null?void 0:r.body)!=null||!!(r!=null&&r.hasBody),this.contentType=(this.headers.get("content-type")||"").split(";")[0]}clone(r){return new _(b(b({},this),r))}};l(_,"HttpResponse");var R=_;var i;(function(h){h.Sent="Sent",h.UploadProgress="UploadProgress",h.ResponseHeader="ResponseHeader",h.DownloadProgress="DownloadProgress",h.Response="Response",h.User="User"})(i||(i={}));var J=class J extends T{constructor(r,e){var t,s,a,c,d,g;super(r,e),this.interceptors=Array.from(new Set([...(e==null?void 0:e.interceptors)||[]])),this.defaults=k(b({},e==null?void 0:e.defaults),{headers:((t=e==null?void 0:e.defaults)==null?void 0:t.headers)instanceof Headers?(s=e==null?void 0:e.defaults)==null?void 0:s.headers:new Headers((a=e==null?void 0:e.defaults)==null?void 0:a.headers),params:((c=e==null?void 0:e.defaults)==null?void 0:c.params)instanceof URLSearchParams?(d=e==null?void 0:e.defaults)==null?void 0:d.params:new URLSearchParams((g=e==null?void 0:e.defaults)==null?void 0:g.params)})}handle(r){return new ue(e=>{(async()=>{let t=this.prepareRequest(r);if(t.body&&r.reportProgress){let O=t.body,D=t.headers.get("content-length")||"0",q=parseInt(D,10)||0,w=0,H=new TransformStream({transform(x,A){A.enqueue(x),w+=x.byteLength,e.next({type:i.UploadProgress,request:t,total:q,loaded:w})}});t=new Request(t.url,{cache:t.cache,credentials:t.credentials,headers:t.headers,integrity:t.integrity,keepalive:t.keepalive,method:t.method,mode:t.mode,redirect:t.redirect,referrer:t.referrer,referrerPolicy:t.referrerPolicy,signal:t.signal,body:O.pipeThrough(H),window:r.window,duplex:"half"})}let s=this.send(t);e.next({request:t,type:i.Sent});let a=await s,c=this.createResponse({url:a.url,headers:a.headers,status:a.status,statusText:a.statusText,hasBody:!!a.body});e.next({request:t,type:i.ResponseHeader,response:c});let d;if(a.body)if(r.reportProgress){let O=a.body,D=a.headers.get("content-length")||"0",q=parseInt(D,10)||0,w=0,H=new Response(new ReadableStream({async start(x){let A=O.getReader();for(;;){let{done:ce,value:$}=await A.read();if(ce)break;w+=$.byteLength,x.enqueue($),e.next({type:i.DownloadProgress,request:t,total:q,loaded:w})}x.close()}}));d=await this.parseBody(H)}else d=await this.parseBody(a);let g=this.createResponse({url:a.url,headers:a.headers,status:a.status,statusText:a.statusText,body:d});e.next({request:t,type:i.Response,response:g}),e.complete()})().catch(t=>e.error(t))})}send(r){return fetch(r)}prepareRequest(r){let e=r.headers||new Headers,t=k(b({},r),{headers:e});this.defaults.headers.forEach((c,d)=>{e.has(d)||e.set(d,c)});let s=new ye(t.url,this.serviceUrl);this.defaults.params.size&&(this.defaults.params.forEach((c,d)=>{s.searchParams.has(d)||s.searchParams.set(d,c)}),t.url=s.toString());let a=t.body;if(a){let c="";typeof a=="string"||typeof a=="number"||typeof a=="boolean"?(c='text/plain; charset="UTF-8"',t.body=new Blob([String(a)],{type:c}),e.set("Content-Length",String(t.body.size)),delete t.duplex):ne(a)?(c="application/octet-stream",t.duplex="half"):Buffer.isBuffer(a)?(c="application/octet-stream",e.set("Content-Length",String(a.length)),delete t.duplex):ie(a)?(c=a.type||"application/octet-stream",e.set("Content-Length",String(a.size)),delete t.duplex):(oe(a)||(c='application/json;charset="UTF-8"',t.body=new Blob([JSON.stringify(a)],{type:c}),e.set("Content-Length",String(t.body.size))),delete t.duplex),c&&!e.has("Content-Type")&&e.set("Content-Type",c)}return new Request(s.toString(),t)}createResponse(r){return new R(r)}async parseBody(r){let e,t=r.headers.get("Content-Type")||"";if(I.is(t,["json","application/*+json"]))e=await r.json(),typeof e=="string"&&(e=JSON.parse(e));else if(I.is(t,["text"]))e=await r.text();else if(I.is(t,["multipart"]))e=await r.formData();else{let s=await r.arrayBuffer();s.byteLength&&(e=s)}return e}};l(J,"FetchBackend");var v=J;import{ApiDocumentFactory as ke,ResponsiveMap as X}from"@opra/common";import{toArrayDef as u}from"putil-varhelpers";import{OpraURL as V}from"@opra/common";import{lastValueFrom as ae,Observable as ge}from"rxjs";import we from"@browsery/type-is";import{OpraURL as xe}from"@opra/common";var o;(function(h){h.ResponseHeader="response-header",h.Response="response",h.Body="body",h.Events="events"})(o||(o={}));var K=class K{constructor(r,e){this.chain=r.reduceRight((t,s)=>(a,c)=>s.intercept(a,{handle:d=>t(d,c)}),be),this.finalHandler=e}handle(r){return this.chain(r,e=>this.finalHandler.handle(e))}};l(K,"HttpInterceptorHandler");var P=K;function be(h,r){return r(h)}l(be,"chainEnd");var E=class E extends ge{constructor(r,e){super(s=>{let a=this[n].observe;new P(r.interceptors||[],this[f]).handle(this[n]).subscribe({next(c){if(a===o.Events){s.next(c);return}if(a===o.ResponseHeader&&c.type===i.ResponseHeader){s.next(c.response),s.complete();return}if(c.type===i.Response){let{response:d}=c;if(a===o.Response){s.next(d),s.complete();return}let g=we.is(c.response.contentType||"",["application/opra+json"]);if(d.status>=400&&d.status<600){s.error(new S({message:d.status+" "+d.statusText,status:d.status,issues:g?d.body.errors:void 0})),s.complete();return}s.next(c.response.body),s.complete()}},error(c){s.error(c)},complete(){s.complete()}})}),Object.defineProperty(this,f,{enumerable:!1,value:r});let t=new xe(e==null?void 0:e.url,r.serviceUrl.toString());Object.defineProperty(this,n,{enumerable:!1,value:k(b({},e),{observe:o.Body,headers:new Headers(e==null?void 0:e.headers),url:t})})}clone(){return new E(this[f],this[n])}options(r){return Object.assign(this[n],r),this}header(r,e){let t=this[n].headers;return typeof r=="object"?((r instanceof Headers?r:new Headers(r)).forEach((a,c)=>{c.toLowerCase()==="set-cookie"?t.append(c,a):t.set(c,a)}),this):(e==null||e===""?t.delete(r):t.append(r,String(e)),this)}param(r,e){e&&typeof e=="object"&&(e=JSON.stringify(e));let t=this[n].url.searchParams;return typeof r=="object"?((r instanceof URLSearchParams?r:new URLSearchParams(r)).forEach((a,c)=>t.set(c,a)),this):(e==null?t.delete(r):t.set(r,String(e)),this)}observe(r){if(r===this[n].observe)return this;let e=this.clone();return e[n].observe=r||o.Body,e}getBody(){return ae(this.observe(o.Body))}getResponse(){return ae(this.observe(o.Response))}};l(E,"HttpRequestObservable");var m=E;var N=class N{constructor(r,e){this._backend=r,this._path=e}create(r,e){let t=new m(this._backend,{method:"POST",url:this._path,body:r});return e!=null&&e.include&&t.param("include",u(e.include,[]).join(",")),e!=null&&e.pick&&t.param("pick",u(e.pick,[]).join(",")),e!=null&&e.omit&&t.param("omit",u(e.omit,[]).join(",")),t}delete(r){if(r==null||r==="")throw new TypeError("'id' argument must have a value");let e=new V;return e.join({resource:this._path,key:r}),new m(this._backend,{method:"DELETE",url:e})}deleteMany(r){let e=new m(this._backend,{method:"DELETE",url:this._path});return r!=null&&r.filter&&e.param("filter",String(r.filter)),e}get(r,e){if(r==null||r==="")throw new TypeError("'id' argument must have a value");let t=new V;t.join({resource:this._path,key:r});let s=new m(this._backend,{method:"GET",url:t});return e!=null&&e.include&&s.param("include",u(e.include,[]).join(",")),e!=null&&e.pick&&s.param("pick",u(e.pick,[]).join(",")),e!=null&&e.omit&&s.param("omit",u(e.omit,[]).join(",")),s}findMany(r){let e=new m(this._backend,{method:"GET",url:this._path});return r!=null&&r.include&&e.param("include",u(r.include,[]).join(",")),r!=null&&r.pick&&e.param("pick",u(r.pick,[]).join(",")),r!=null&&r.omit&&e.param("omit",u(r.omit,[]).join(",")),r!=null&&r.sort&&e.param("sort",u(r.sort,[]).join(",")),r!=null&&r.filter&&e.param("filter",String(r.filter)),(r==null?void 0:r.limit)!=null&&e.param("limit",String(r.limit)),(r==null?void 0:r.skip)!=null&&e.param("skip",String(r.skip)),(r==null?void 0:r.count)!=null&&e.param("count",String(r.count)),(r==null?void 0:r.distinct)!=null&&e.param("distinct",String(r.distinct)),e}update(r,e,t){if(r==null)throw new TypeError("'id' argument must have a value");let s=new V;s.join({resource:this._path,key:r});let a=new m(this._backend,{method:"PATCH",url:s,body:e});return t!=null&&t.include&&a.param("include",u(t.include,[]).join(",")),t!=null&&t.pick&&a.param("pick",u(t.pick,[]).join(",")),t!=null&&t.omit&&a.param("omit",u(t.omit,[]).join(",")),a}updateMany(r,e){let t=new m(this._backend,{method:"PATCH",url:this._path,body:r});return e!=null&&e.filter&&t.param("filter",String(e.filter)),t}};l(N,"HttpCollectionNode");var B=N;import{toArrayDef as y}from"putil-varhelpers";var Q=class Q{constructor(r,e){this._backend=r,this._path=e}create(r,e){let t=new m(this._backend,{method:"POST",url:this._path,body:r});return e!=null&&e.include&&t.param("include",y(e.include,[]).join(",")),e!=null&&e.pick&&t.param("pick",y(e.pick,[]).join(",")),e!=null&&e.omit&&t.param("omit",y(e.omit,[]).join(",")),t}delete(){return new m(this._backend,{method:"DELETE",url:this._path})}get(r){let e=new m(this._backend,{method:"GET",url:this._path});return r!=null&&r.include&&e.param("include",y(r.include,[]).join(",")),r!=null&&r.pick&&e.param("pick",y(r.pick,[]).join(",")),r!=null&&r.omit&&e.param("omit",y(r.omit,[]).join(",")),e}update(r,e){let t=new m(this._backend,{method:"PATCH",url:this._path,body:r});return e!=null&&e.include&&t.param("include",y(e.include,[]).join(",")),e!=null&&e.pick&&t.param("pick",y(e.pick,[]).join(",")),e!=null&&e.omit&&t.param("omit",y(e.omit,[]).join(",")),t}};l(Q,"HttpSingletonNode");var L=Q;var W=class W{constructor(r,e){this._backend=r,this._path=e}delete(){return new m(this._backend,{method:"DELETE",url:this._path})}get(){return new m(this._backend,{method:"GET",url:this._path})}post(r){return new m(this._backend,{method:"POST",url:this._path,body:r})}};l(W,"HttpStorageNode");var C=W;var Y=class Y extends j{constructor(r){super(r),this._collectionCache=new X,this._singletonCache=new X,this._storageCache=new X}get serviceUrl(){return this[f].serviceUrl}async getMetadata(){if(this._metadataPromise)return this._metadataPromise;let r=new m(this[f],{method:"GET",url:"/",headers:new Headers({accept:"application/json"})}),e;try{this._metadataPromise=r.getBody(),e=await this._metadataPromise}catch(t){throw t.message="Error fetching metadata from url ("+this.serviceUrl+`).
|
|
7
|
+
`+t.message,t}finally{this._metadataPromise=void 0}try{let t=await ke.createDocument(e);return this[f].api=t,t}catch(t){throw t.message=`Error loading api document.
|
|
8
|
+
`+t.message,t}}collection(r){let e=this._collectionCache.get(r);return e||(e=new B(this[f],r),this._collectionCache.set(r,e)),e}singleton(r){let e=this._singletonCache.get(r);return e||(e=new L(this[f],r),this._singletonCache.set(r,e)),e}storage(r){let e=this._storageCache.get(r);return e||(e=new C(this[f],r),this._storageCache.set(r,e)),e}action(r,e){let t=new m(this[f],{method:"GET",url:r});return e&&(Object.keys(e).forEach(s=>e[s]=String(e[s])),t.param(e)),t}};l(Y,"HttpClientBase");var U=Y;var Z=class Z extends U{constructor(r,e){super(new v(r,e))}get defaults(){return this[f].defaults}};l(Z,"OpraHttpClient");var se=Z;export{p as Backend,j as ClientBase,S as ClientError,v as FetchBackend,T as HttpBackend,U as HttpClientBase,B as HttpCollectionNode,i as HttpEventType,o as HttpObserveType,m as HttpRequestObservable,R as HttpResponse,L as HttpSingletonNode,se as OpraHttpClient,f as kBackend,fe as kClient,n as kContext};
|
|
@@ -164,7 +164,7 @@ class FetchBackend extends http_backend_js_1.HttpBackend {
|
|
|
164
164
|
}
|
|
165
165
|
const body = requestInit.body;
|
|
166
166
|
if (body) {
|
|
167
|
-
let contentType;
|
|
167
|
+
let contentType = '';
|
|
168
168
|
if (typeof body === 'string' || typeof body === 'number' || typeof body === 'boolean') {
|
|
169
169
|
contentType = 'text/plain; charset="UTF-8"';
|
|
170
170
|
requestInit.body = new Blob([String(body)], { type: contentType });
|
|
@@ -185,6 +185,9 @@ class FetchBackend extends http_backend_js_1.HttpBackend {
|
|
|
185
185
|
headers.set('Content-Length', String(body.size));
|
|
186
186
|
delete requestInit.duplex;
|
|
187
187
|
}
|
|
188
|
+
else if ((0, common_1.isFormData)(body)) {
|
|
189
|
+
delete requestInit.duplex;
|
|
190
|
+
}
|
|
188
191
|
else {
|
|
189
192
|
contentType = 'application/json;charset="UTF-8"';
|
|
190
193
|
requestInit.body = new Blob([JSON.stringify(body)], { type: contentType });
|
|
@@ -7,6 +7,7 @@ const client_base_js_1 = require("../core/client-base.js");
|
|
|
7
7
|
const http_collection_node_js_1 = require("./http-collection-node.js");
|
|
8
8
|
const http_request_observable_js_1 = require("./http-request-observable.js");
|
|
9
9
|
const http_singleton_node_js_1 = require("./http-singleton-node.js");
|
|
10
|
+
const http_storage_node_js_1 = require("./http-storage-node.js");
|
|
10
11
|
/**
|
|
11
12
|
*
|
|
12
13
|
* @class OpraClientBase
|
|
@@ -17,6 +18,7 @@ class HttpClientBase extends client_base_js_1.ClientBase {
|
|
|
17
18
|
super(backend);
|
|
18
19
|
this._collectionCache = new common_1.ResponsiveMap();
|
|
19
20
|
this._singletonCache = new common_1.ResponsiveMap();
|
|
21
|
+
this._storageCache = new common_1.ResponsiveMap();
|
|
20
22
|
}
|
|
21
23
|
get serviceUrl() {
|
|
22
24
|
return this[constants_js_1.kBackend].serviceUrl;
|
|
@@ -67,6 +69,14 @@ class HttpClientBase extends client_base_js_1.ClientBase {
|
|
|
67
69
|
}
|
|
68
70
|
return node;
|
|
69
71
|
}
|
|
72
|
+
storage(path) {
|
|
73
|
+
let node = this._storageCache.get(path);
|
|
74
|
+
if (!node) {
|
|
75
|
+
node = new http_storage_node_js_1.HttpStorageNode(this[constants_js_1.kBackend], path);
|
|
76
|
+
this._storageCache.set(path, node);
|
|
77
|
+
}
|
|
78
|
+
return node;
|
|
79
|
+
}
|
|
70
80
|
action(path, params) {
|
|
71
81
|
const observable = new http_request_observable_js_1.HttpRequestObservable(this[constants_js_1.kBackend], {
|
|
72
82
|
method: 'GET',
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpStorageNode = void 0;
|
|
4
|
+
const http_request_observable_js_1 = require("./http-request-observable.js");
|
|
5
|
+
/**
|
|
6
|
+
* @class HttpStorageNode
|
|
7
|
+
*/
|
|
8
|
+
class HttpStorageNode {
|
|
9
|
+
constructor(backend, path) {
|
|
10
|
+
this._backend = backend;
|
|
11
|
+
this._path = path;
|
|
12
|
+
}
|
|
13
|
+
delete() {
|
|
14
|
+
return new http_request_observable_js_1.HttpRequestObservable(this._backend, {
|
|
15
|
+
method: 'DELETE',
|
|
16
|
+
url: this._path
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
get() {
|
|
20
|
+
const observable = new http_request_observable_js_1.HttpRequestObservable(this._backend, {
|
|
21
|
+
method: 'GET',
|
|
22
|
+
url: this._path
|
|
23
|
+
});
|
|
24
|
+
return observable;
|
|
25
|
+
}
|
|
26
|
+
post(data) {
|
|
27
|
+
const observable = new http_request_observable_js_1.HttpRequestObservable(this._backend, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
url: this._path,
|
|
30
|
+
body: data
|
|
31
|
+
});
|
|
32
|
+
return observable;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.HttpStorageNode = HttpStorageNode;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { isReadableStreamLike } from 'rxjs/internal/util/isReadableStreamLike';
|
|
4
4
|
import typeIs from '@browsery/type-is';
|
|
5
|
-
import { isBlob, OpraURL } from '@opra/common';
|
|
5
|
+
import { isBlob, isFormData, OpraURL } from '@opra/common';
|
|
6
6
|
import { HttpBackend } from './http-backend.js';
|
|
7
7
|
import { HttpResponse } from './http-response.js';
|
|
8
8
|
import { HttpEventType } from './interfaces/http-event.js';
|
|
@@ -160,7 +160,7 @@ export class FetchBackend extends HttpBackend {
|
|
|
160
160
|
}
|
|
161
161
|
const body = requestInit.body;
|
|
162
162
|
if (body) {
|
|
163
|
-
let contentType;
|
|
163
|
+
let contentType = '';
|
|
164
164
|
if (typeof body === 'string' || typeof body === 'number' || typeof body === 'boolean') {
|
|
165
165
|
contentType = 'text/plain; charset="UTF-8"';
|
|
166
166
|
requestInit.body = new Blob([String(body)], { type: contentType });
|
|
@@ -181,6 +181,9 @@ export class FetchBackend extends HttpBackend {
|
|
|
181
181
|
headers.set('Content-Length', String(body.size));
|
|
182
182
|
delete requestInit.duplex;
|
|
183
183
|
}
|
|
184
|
+
else if (isFormData(body)) {
|
|
185
|
+
delete requestInit.duplex;
|
|
186
|
+
}
|
|
184
187
|
else {
|
|
185
188
|
contentType = 'application/json;charset="UTF-8"';
|
|
186
189
|
requestInit.body = new Blob([JSON.stringify(body)], { type: contentType });
|
|
@@ -4,6 +4,7 @@ import { ClientBase } from '../core/client-base.js';
|
|
|
4
4
|
import { HttpCollectionNode } from './http-collection-node.js';
|
|
5
5
|
import { HttpRequestObservable } from './http-request-observable.js';
|
|
6
6
|
import { HttpSingletonNode } from './http-singleton-node.js';
|
|
7
|
+
import { HttpStorageNode } from './http-storage-node.js';
|
|
7
8
|
/**
|
|
8
9
|
*
|
|
9
10
|
* @class OpraClientBase
|
|
@@ -14,6 +15,7 @@ export class HttpClientBase extends ClientBase {
|
|
|
14
15
|
super(backend);
|
|
15
16
|
this._collectionCache = new ResponsiveMap();
|
|
16
17
|
this._singletonCache = new ResponsiveMap();
|
|
18
|
+
this._storageCache = new ResponsiveMap();
|
|
17
19
|
}
|
|
18
20
|
get serviceUrl() {
|
|
19
21
|
return this[kBackend].serviceUrl;
|
|
@@ -64,6 +66,14 @@ export class HttpClientBase extends ClientBase {
|
|
|
64
66
|
}
|
|
65
67
|
return node;
|
|
66
68
|
}
|
|
69
|
+
storage(path) {
|
|
70
|
+
let node = this._storageCache.get(path);
|
|
71
|
+
if (!node) {
|
|
72
|
+
node = new HttpStorageNode(this[kBackend], path);
|
|
73
|
+
this._storageCache.set(path, node);
|
|
74
|
+
}
|
|
75
|
+
return node;
|
|
76
|
+
}
|
|
67
77
|
action(path, params) {
|
|
68
78
|
const observable = new HttpRequestObservable(this[kBackend], {
|
|
69
79
|
method: 'GET',
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HttpRequestObservable } from './http-request-observable.js';
|
|
2
|
+
/**
|
|
3
|
+
* @class HttpStorageNode
|
|
4
|
+
*/
|
|
5
|
+
export class HttpStorageNode {
|
|
6
|
+
constructor(backend, path) {
|
|
7
|
+
this._backend = backend;
|
|
8
|
+
this._path = path;
|
|
9
|
+
}
|
|
10
|
+
delete() {
|
|
11
|
+
return new HttpRequestObservable(this._backend, {
|
|
12
|
+
method: 'DELETE',
|
|
13
|
+
url: this._path
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
get() {
|
|
17
|
+
const observable = new HttpRequestObservable(this._backend, {
|
|
18
|
+
method: 'GET',
|
|
19
|
+
url: this._path
|
|
20
|
+
});
|
|
21
|
+
return observable;
|
|
22
|
+
}
|
|
23
|
+
post(data) {
|
|
24
|
+
const observable = new HttpRequestObservable(this._backend, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
url: this._path,
|
|
27
|
+
body: data
|
|
28
|
+
});
|
|
29
|
+
return observable;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/client",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.8",
|
|
4
4
|
"description": "Opra Client package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@browsery/stream": "^0.6.0",
|
|
41
41
|
"@browsery/type-is": "^0.6.3",
|
|
42
42
|
"@browsery/util": "^0.4.0",
|
|
43
|
-
"@opra/common": "^0.31.
|
|
43
|
+
"@opra/common": "^0.31.8",
|
|
44
44
|
"accepts": "^1.3.8",
|
|
45
45
|
"buffer": "^6.0.3",
|
|
46
46
|
"cookie": "^0.6.0",
|
|
@@ -5,6 +5,7 @@ import { HttpBackend } from './http-backend.js';
|
|
|
5
5
|
import { HttpCollectionNode } from './http-collection-node.js';
|
|
6
6
|
import { HttpRequestObservable } from './http-request-observable.js';
|
|
7
7
|
import { HttpSingletonNode } from './http-singleton-node.js';
|
|
8
|
+
import { HttpStorageNode } from './http-storage-node.js';
|
|
8
9
|
/**
|
|
9
10
|
*
|
|
10
11
|
* @class OpraClientBase
|
|
@@ -14,12 +15,14 @@ export declare abstract class HttpClientBase<TRequestOptions = {}, TResponseExt
|
|
|
14
15
|
[kBackend]: HttpBackend;
|
|
15
16
|
protected _collectionCache: ResponsiveMap<HttpCollectionNode<any, {}, {}>>;
|
|
16
17
|
protected _singletonCache: ResponsiveMap<HttpCollectionNode<any, {}, {}>>;
|
|
18
|
+
protected _storageCache: ResponsiveMap<HttpStorageNode<any, {}, {}>>;
|
|
17
19
|
protected _metadataPromise?: Promise<any>;
|
|
18
20
|
protected constructor(backend: HttpBackend);
|
|
19
21
|
get serviceUrl(): string;
|
|
20
22
|
getMetadata(): Promise<ApiDocument>;
|
|
21
23
|
collection<TType = any>(path: string): HttpCollectionNode<TType, TRequestOptions, TResponseExt>;
|
|
22
24
|
singleton<TType = any>(path: string): HttpSingletonNode<TType, TRequestOptions, TResponseExt>;
|
|
25
|
+
storage(path: string): HttpStorageNode<any, TRequestOptions, TResponseExt>;
|
|
23
26
|
action<T = any>(path: string, params?: Record<string, any>): HttpRequestObservable<T, T, TRequestOptions, TResponseExt>;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OperationResult } from '@opra/common';
|
|
2
|
+
import { HttpBackend } from './http-backend.js';
|
|
3
|
+
import { HttpRequestObservable } from './http-request-observable.js';
|
|
4
|
+
/**
|
|
5
|
+
* @class HttpStorageNode
|
|
6
|
+
*/
|
|
7
|
+
export declare class HttpStorageNode<TType, TRequestOptions = {}, TResponseExt = {}> {
|
|
8
|
+
protected _backend: HttpBackend;
|
|
9
|
+
protected _path: string;
|
|
10
|
+
constructor(backend: HttpBackend, path: string);
|
|
11
|
+
delete(): HttpRequestObservable<OperationResult<never>, OperationResult<never>, TRequestOptions, TResponseExt>;
|
|
12
|
+
get(): HttpRequestObservable<OperationResult<TType>, OperationResult<TType>, TRequestOptions, TResponseExt>;
|
|
13
|
+
post(data: FormData): HttpRequestObservable<OperationResult<TType>, OperationResult<TType>, TRequestOptions, TResponseExt>;
|
|
14
|
+
}
|