@basmilius/http-client 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
var Ut=Object.defineProperty;var Vt=Object.getOwnPropertyDescriptor;var It=t=>{throw TypeError(t)};var I=(t,e,r,n)=>{for(var o=n>1?void 0:n?Vt(e,r):e,s=t.length-1,u;s>=0;s--)(u=t[s])&&(o=(n?u(e,r,o):u(o))||o);return n&&o&&Ut(e,r,o),o};var St=(t,e,r)=>e.has(t)||It("Cannot "+r);var l=(t,e,r)=>(St(t,e,"read from private field"),r?r.call(t):e.get(t)),f=(t,e,r)=>e.has(t)?It("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),d=(t,e,r,n)=>(St(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r);function ft(t){return class extends t{constructor(...e){throw new Error("@adapter: cannot create instance of class.")}}}function $t(){return(t,e)=>{t[e]=t[e].bind(t)}}function Jt(t){return(e,r,n)=>{n.value=vt(n.value,t,e)}}function vt(t,e,r){let n=[],o=[],s=null;return(...u)=>(clearTimeout(s),s=setTimeout(async()=>{try{let p=await t.apply(r,u);n.forEach(w=>w(p))}catch(p){o.forEach(w=>w(p))}n=[],o=[]},e),new Promise((p,w)=>{n.push(p),o.push(w)}))}import{DateTime as Xt}from"luxon";function F(t){return t=t||Xt.now(),t.toFormat("yyyy-MM-dd HH-mm-ss")}function bt(t){let e={};do{if(t.name==="")break;for(let[r,n]of Object.entries(Object.getOwnPropertyDescriptors(t.prototype)))["constructor","clone","toJSON"].includes(r)||!n.get&&!n.set||(e[r]=n)}while(t=Object.getPrototypeOf(t));return e}function j(t,e,r){t.prototype[e]=r}function M(t,e,r){Object.defineProperty(t,e,{value:r})}var O=Symbol(),R=Symbol(),T=Symbol(),y=Symbol(),a=Symbol(),m=Symbol(),c=Symbol(),N=Symbol(),b=Symbol(),tt=Symbol(),et=Symbol();function i(t){return t&&typeof t=="object"&&t[a]}function dt(t,e){return!i(t)||!i(e)?t===e:JSON.stringify(t)===JSON.stringify(e)}function h(t){if(!i(t))throw new Error("@dto assert given object is not a class decorated with @Dto.")}var yt=Symbol();function _(t,e=0,r){return function(...n){let o=yt in t,s=t[yt]??=new WeakMap,u=n[e],p=r!==void 0?n[r]:"self";if(typeof u!="object")return t.call(this,...n);if(s.has(u)||s.set(u,[]),s.get(u).includes(p)){!1;return}s.get(u).push(p);let w=t.call(this,...n);return!o&&delete t[yt],w}}function Et(t){return h(t),t.clone()}function B(t){return h(t),t[y]}var At=_(function(t,e,r,n){let o=t[et];o(t,e,r,n),!1,t[m]&&At(t[m],t[c],t[m][t[c]])},0,1),x=At;var Pt=_(function(t){h(t),t[y]&&(t[y]=!1,!1,x(t,y,!1,!0)),!(!t[R]||t[R].length===0)&&t[R].filter(B).forEach(Pt)}),rt=Pt;async function kt(t,e){!i(t)||!B(t)||(await e(t),rt(t))}function ht(t){return t?.value??t}function Ct(t){return h(t),!t[y]}var Ot=_(function(t,e){h(t),t[y]||(t[y]=!0,!1,x(t,y,!0,!1)),t[m]&&Ot(t[m],t[c])}),E=Ot;function Dt(t,e,r){e[R]??=[],!e[R].includes(t)&&e[R].push(t),t[m]!==e&&(t[m]=e),t[c]!==r&&(t[c]=r)}function nt(t,e,r){i(r)?Dt(r,t,e):Array.isArray(r)&&(r.some(i)&&r.filter(i).forEach(n=>Dt(n,t,e)),r[m]=t,r[c]=e)}function H(t,e){let r=t[tt];r(t,e),!1}function Rt(t,e){if(R in e){let r=e[R].indexOf(t);e[R].splice(r,1)}t[m]=void 0,t[c]=void 0}function gt(t,e){i(e)?Rt(e,t):Array.isArray(e)&&(e.some(i)&&e.filter(i).forEach(r=>Rt(r,t)),e[m]=void 0,e[c]=void 0)}var A={};import{customRef as jt,markRaw as te}from"vue";var ot={deleteProperty(t,e){if(Reflect.deleteProperty(t,e),wt(t,e))return!0;let r=t[m];return r&&x(r,t[c],r[t[c]]),r&&E(r,t[c]),!0},get(t,e,r){if(e===b)return!0;if(wt(t,e))return Reflect.get(t,e,r);let n=t[m];return n&&H(n,t[c]),Reflect.get(t,e)},set(t,e,r,n){if(wt(t,e))return Reflect.set(t,e,r,n);let o=t[m];return o&&x(o,t[c],o[t[c]]),o&&E(o,t[c]),Reflect.set(t,e,r)}};function wt(t,e){return typeof e=="symbol"||typeof t[e]=="function"||e==="length"}var Nt={get(t,e,r){if(e===b)return!0;if(typeof e=="symbol")return Reflect.get(t,e,r);let n=t[T][e];if(!n||!n.get)return Reflect.get(t,e,r);let o=n.get.call(t);return!1,H(t,e),nt(t,e,o),o},getOwnPropertyDescriptor(t,e){return t[T][e]},ownKeys(t){return t[N]},set(t,e,r,n){if(typeof e=="symbol")return Reflect.set(t,e,r,n);let o=t[T][e];if(!o||!o.set)return Reflect.set(t,e,r,n);let s=o.get?.call(t)??void 0;return dt(r,s)||(gt(t,s),Array.isArray(r)&&!r[b]&&(r=new Proxy(r,ot)),!1,o.set.call(t,r),nt(t,e,r),E(t,e),x(t,e,r,s)),!0}};var _t={get(t,e,r){return e==="__v_isRef"?!1:e===b?!0:e in t?Reflect.get(t,e,r):Reflect.get(t.value,e)},getOwnPropertyDescriptor(t,e){return Reflect.getOwnPropertyDescriptor(t.value,e)},ownKeys(t){return Reflect.ownKeys(t.value)},set(t,e,r,n){return e in t?Reflect.set(t,e,r,n):Reflect.set(t.value,e,r)}};var Bt={construct(t,e,r){e=e.map(o=>Array.isArray(o)?new Proxy(o,ot):o);let n=jt((o,s)=>{let u=te(Reflect.construct(t,e,r));u[O]=e,u[y]=!1,u[tt]=o,u[et]=s;let p=new Proxy(u,Nt);return{get:()=>(o(),p),set:()=>{}}});return new Proxy(n,_t)}};function Ht(){let t=this;h(t);let e=A[t[a]],r=new e(...t[O]);return Object.entries(this[T]).filter(([,n])=>!!n.set).map(([n])=>n).forEach(n=>r[n]=i(this[n])?this[n].clone():this[n]),r}function Gt(t){for(let e in t){let r=this[T][e];i(this[e])&&typeof t[e]=="object"?this[e].fill(t[e]):r&&r.set&&(this[e]=t[e])}}function qt(){return Object.fromEntries(this[N].map(t=>{let e=Reflect.get.call(this,this,t,this);return i(e)&&(e=e.toJSON()),[t,e]}))}function P(t){re(t);let e=Object.freeze(bt(t)),r=Object.keys(e);return M(t.prototype,T,e),M(t.prototype,a,t.name),M(t.prototype,N,r),M(t,Symbol.hasInstance,n=>typeof n=="object"&&n?.[a]===t.name),j(t,"clone",Ht),j(t,"fill",Gt),j(t,"toJSON",qt),ee(t)}function ee(t){let e=new Proxy(t,Bt);return A[t.name]=e,e}function re(t){let e=Object.getPrototypeOf(t.prototype);if(a in e)throw new Error(`\u26D4\uFE0F @dto ${t.name} cannot extend parent class which is also decorated with @dto ${e[a]}.`)}if(!1){let t=console.error.bind(console),e=console.info.bind(console),r=console.log.bind(console),n=console.warn.bind(console),o=s=>(...u)=>{for(let p=u.length-1;p>=0;--p){let w=u[p];if(!i(w))continue;let xt=ht(w);u.splice(p,1,`\u{1F4E6} ${xt[a]}`,xt.toJSON())}return s(...u)};console.error=o(t),console.info=o(e),console.log=o(r),console.warn=o(n)}function it(t){return t.map(G)}import{DateTime as ne}from"luxon";function Lt([,t]){return ne.fromISO(t)}function st(t){return Object.fromEntries(Object.entries(t).map(([e,r])=>[e,G(r)]).filter(([,e])=>e!==void 0))}var Tt={};function zt([,t,e,r,n]){if(!(e in A))throw new Error(`[@marveld/http] Cannot restore @dto. Dto ${e} was not found.`);if(t in Tt)return Tt[t];!1;let o=A[e],s=new o(...it(n));return s.fill(st(r)),!1,Tt[t]=s,s}function Ft(t){return Array.isArray(t)&&t[0]===3058}function Mt(t){return Array.isArray(t)&&t[0]===3057}function G(t){switch(!0){case t===null:return null;case Array.isArray(t):switch(!0){case Ft(t):return Lt(t);case Mt(t):return zt(t);default:return it(t)}case typeof t=="object":return st(t);default:return t}}function Yt(t){return G(JSON.parse(t))}import{DateTime as ue}from"luxon";import{DateTime as se}from"luxon";function ut(t){return[3058,t.toISO({extendedZone:!0,includeOffset:!0})]}import{toRaw as ie}from"vue";function at(t){return Object.fromEntries(Object.entries(t).map(([e,r])=>[e,q(r)]).filter(([,e])=>e!==void 0))}function Kt(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t=>(+t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+t/4).toString(16))}function ct(t){t=ie(t);let e=t.toJSON();return[3057,Kt(),t[a],at(e),mt(t[O])]}function mt(t){switch(!0){case t.every(i):return t.map(ct);case t.every(se.isDateTime):return t.map(ut);default:return t.map(q)}}function q(t){switch(!0){case t===null:return null;case Array.isArray(t):return mt(t);case i(t):return ct(t);case ue.isDateTime(t):return ut(t);case typeof t=="object":return at(t);case typeof t=="boolean":case typeof t=="number":case typeof t=="string":return t;default:return}}function Qt(t){return JSON.stringify(q(t))}var Y,K,k=class{constructor(e,r){f(this,Y);f(this,K);d(this,Y,e),d(this,K,r)}get blob(){return l(this,Y)}get name(){return l(this,K)}};Y=new WeakMap,K=new WeakMap,k=I([P],k);var Q,U,V,$,J,C=class{constructor(e,r,n,o,s){f(this,Q);f(this,U);f(this,V);f(this,$);f(this,J);d(this,Q,e),d(this,U,r),d(this,V,n),d(this,$,o),d(this,J,s)}get items(){return l(this,Q)}get page(){return l(this,U)}get pageSize(){return l(this,V)}get pages(){return l(this,$)}get totalItems(){return l(this,J)}};Q=new WeakMap,U=new WeakMap,V=new WeakMap,$=new WeakMap,J=new WeakMap,C=I([P],C);var S=class{static parsePaginatedAdapter(e,r){return new C(e.items.map(r),e.page,e.pageSize,e.pages,e.totalItems)}static parseFileNameFromContentDispositionHeader(e){if(!e.startsWith("attachment"))return`download-${F()}`;let n=/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(e);return(n?.length||0)<2?`download-${F()}`:n[1].replaceAll("'","").replaceAll('"',"").replaceAll("/","-").replaceAll(":","-")}};S=I([ft],S);var g=class{get data(){return this.#t}get headers(){return this.#e.headers}get ok(){return this.statusCode>=200&&this.statusCode<300}get response(){return this.#e}get statusCode(){return this.#e.status}#t;#e;constructor(e,r){this.#t=e,this.#e=r}};var L=class t{get authToken(){return this.#t}set authToken(e){this.#t=e}get baseUrl(){return this.#r}get timezone(){return this.#e}set timezone(e){this.#e=e}#t;#e;#r;constructor(e,r){this.#t=e,this.#r=r,this.#e=Intl.DateTimeFormat().resolvedOptions().timeZone}onException(e,r){}onRequest(e){return e}onResponse(e){}static get instance(){if(t.#n===null)throw new Error("There is currently no HttpClient instance registered. Register one using the HttpClient.register() function.");return t.#n}static#n=null;static register(e){t.#n=e}};var v,X,W,Z,D=class{constructor(e,r,n,o){f(this,v);f(this,X);f(this,W);f(this,Z);d(this,v,e),d(this,X,r),d(this,W,n),d(this,Z,o)}get code(){return l(this,v)}get error(){return l(this,X)}get errorDescription(){return l(this,W)}get statusCode(){return l(this,Z)}};v=new WeakMap,X=new WeakMap,W=new WeakMap,Z=new WeakMap,D=I([P],D);var z=class t{get client(){return this.#t}get options(){return this.#r}get path(){return this.#e}set path(e){this.#e=e}get query(){return this.#n}set query(e){this.#n=e}#t;#e;#r={};#n=null;constructor(e,r){this.#t=r??L.instance,this.#r.cache="no-cache",this.#r.method="get",this.#e=e}bearerToken(e){return e=e??this.#t.authToken,e?this.header("Authorization",`Bearer ${e}`):(this.#r.headers&&"Authorization"in this.#r.headers&&delete this.#r.headers.Authorization,this)}body(e,r="application/octet-stream"){return e instanceof FormData?r=null:(Array.isArray(e)||typeof e=="object")&&(e=JSON.stringify(e),r="application/json"),this.#r.body=e,r!==null?this.header("Content-Type",r):this}asOrganization(e){return this.header("X-Organization-Id",e)}header(e,r){return this.#r.headers=this.#r.headers||{},this.#r.headers[e]=r,this}method(e){return this.#r.method=e,this}queryString(e){return this.#n=e,this}async fetch(){return this.#i().then(e=>e.json())}async fetchBlob(){let e=await this.#i();if(e.status!==200){let n=await e.json();throw"code"in n&&"error"in n&&"error_description"in n?new D(n.code,n.error,n.error_description,e.status):new D(-1,"failed_without_info","Request failed without any information from the backend.",e.status)}let r=e.headers.has("content-disposition")?S.parseFileNameFromContentDispositionHeader(e.headers.get("content-disposition")):`download-${F()}`;return new k(await e.blob(),r)}async run(){let{data:e,response:r}=await this.#o();return new g(e,r)}async runAdapter(e){let{data:r,response:n}=await this.#o();return new g(e(r),n)}async runArrayAdapter(e){return this.runAdapter(r=>r.map(e))}async runEmpty(){return await this.#o()}async runPaginatedAdapter(e){return this.runAdapter(r=>S.parsePaginatedAdapter(r,e))}async runData(){return await this.#o()}async runDataKey(e){let{data:r,response:n}=await this.#o();return new g(r[e],n)}async runStatusCode(){return(await this.#o()).statusCode}async#i(){let e=this.#t.onRequest(this),r=e.path;return e.query!==null&&(r+=`?${e.query.build()}`),await fetch(e.client.baseUrl+r,e.options).catch(n=>{throw this.#t.onException(n,e),n})}async#o(){return await this.#i().then(t.#s).then(e=>(this.#t.onResponse(e),e))}static async#s(e){if(e.status===204)return new g(null,e);if(e.headers.has("content-type")&&e.headers.get("content-type").startsWith("application/json")){let n=await e.json();if("code"in n&&"error"in n&&"error_description"in n)throw new D(n.code,n.error,n.error_description,e.status);return new g(n,e)}if(e.status===401||e.status===403)return new g(null,e);if((await e.text()).length===0&&e.status>=200&&e.status<300)return new g(null,e);throw new D(-1,"not_a_json_response","The response was not a JSON response.",e.status)}};var pt=class{request(e,r){return new z(e,r)}};var lt=class t{#t;constructor(){this.#t=new URLSearchParams}build(){return this.#t.toString()}append(e,r){return this.#e(this.#t.append.bind(this.#t),e,r)}appendArray(e,r){return r==null?this:(r.forEach(n=>this.append(e,n)),this)}delete(e){return this.#t.delete(e),this}get(e){return this.#t.get(e)}getAll(e){return this.#t.getAll(e)}has(e){return this.#t.has(e)}set(e,r){return this.#e(this.#t.set.bind(this.#t),e,r)}#e(e,r,n){if(!n&&n!==!1)return this;switch(typeof n){case"boolean":e(r,n?"true":"false");break;case"number":e(r,n.toString(10));break;case"string":e(r,n);break}return this}static builder(){return new t}};function ae(t){return t instanceof D}function ce(t){return t instanceof D&&(t=t.statusCode),t===403||t===401}export{g as BaseResponse,pt as BaseService,k as BlobResponse,S as HttpAdapter,L as HttpClient,C as Paginated,lt as QueryString,z as RequestBuilder,D as RequestError,ft as adapter,h as assertDto,$t as bound,Et as cloneDto,Jt as debounce,Yt as deserialize,P as dto,kt as executeIfDtoDirtyAndMarkClean,i as isDto,Ct as isDtoClean,B as isDtoDirty,ae as isRequestError,ce as isUnsanctionedRequest,rt as markDtoClean,E as markDtoDirty,Qt as serialize};
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=http-client.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basmilius/http-client",
|
|
3
3
|
"description": "Http client for Vue projects.",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.2",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"funding": "https://github.com/sponsors/basmilius",
|
|
7
|
+
"homepage": "https://github.com/basmilius/http-client",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/basmilius/http-client.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"http",
|
|
14
|
+
"http client",
|
|
15
|
+
"http dto",
|
|
16
|
+
"dto",
|
|
17
|
+
"vue",
|
|
18
|
+
"vue 3"
|
|
19
|
+
],
|
|
5
20
|
"engines": {
|
|
6
21
|
"node": ">=22"
|
|
7
22
|
},
|
|
@@ -9,15 +24,19 @@
|
|
|
9
24
|
"dist/*"
|
|
10
25
|
],
|
|
11
26
|
"type": "module",
|
|
12
|
-
"main": "./dist/
|
|
13
|
-
"module": "./dist/
|
|
27
|
+
"main": "./dist/http-client.js",
|
|
28
|
+
"module": "./dist/http-client.js",
|
|
14
29
|
"types": "./dist/index.d.ts",
|
|
15
30
|
"exports": {
|
|
16
31
|
".": {
|
|
17
32
|
"types": "./dist/index.d.ts",
|
|
18
|
-
"default": "./dist/
|
|
33
|
+
"default": "./dist/http-client.js"
|
|
19
34
|
}
|
|
20
35
|
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"provenance": true
|
|
39
|
+
},
|
|
21
40
|
"sideEffects": false,
|
|
22
41
|
"devDependencies": {
|
|
23
42
|
"@types/luxon": "^3.4.2",
|
|
@@ -25,16 +44,16 @@
|
|
|
25
44
|
"luxon": "^3.5.0",
|
|
26
45
|
"tsc-alias": "^1.8.10",
|
|
27
46
|
"typescript": "^5.6.2",
|
|
28
|
-
"vue": "^3.5.
|
|
47
|
+
"vue": "^3.5.6"
|
|
29
48
|
},
|
|
30
49
|
"peerDependencies": {
|
|
31
50
|
"luxon": "^3.5.0",
|
|
32
|
-
"vue": "^3.5.
|
|
51
|
+
"vue": "^3.5.6"
|
|
33
52
|
},
|
|
34
53
|
"scripts": {
|
|
35
54
|
"build": "pnpm esbuild && pnpm gentypes",
|
|
36
55
|
"dev": "pnpm esbuild --watch",
|
|
37
|
-
"esbuild": "esbuild src/index.ts --bundle --minify --metafile=meta.json --sourcemap --target=esnext --external:luxon --external:vue --platform=browser --format=esm --outfile=dist/
|
|
56
|
+
"esbuild": "esbuild src/index.ts --bundle --minify --metafile=meta.json --sourcemap --target=esnext --external:luxon --external:vue --platform=browser --format=esm --outfile=dist/http-client.js",
|
|
38
57
|
"gentypes": "tsc --noCheck && tsc-alias"
|
|
39
58
|
}
|
|
40
59
|
}
|
|
File without changes
|