@hostlink/light 3.0.5 → 3.0.6
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/dist/index.d.ts +1 -0
- package/dist/light.js +419 -386
- package/dist/light.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/light.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],b):(f=typeof globalThis<"u"?globalThis:f||self,b(f.light={},f.jsonToGraphqlQuery,f.axios,f.collect))})(this,(function(f,b,bt,v){"use strict";function E(t){if(t===null||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null||Symbol.iterator in t?!1:Symbol.toStringTag in t?Object.prototype.toString.call(t)==="[object Module]":!0}function S(t,e,r=".",i){if(!E(e))return S(t,{},r,i);const o=Object.assign({},e);for(const u in t){if(u==="__proto__"||u==="constructor")continue;const l=t[u];l!=null&&(i&&i(o,u,l,r)||(Array.isArray(l)&&Array.isArray(o[u])?o[u]=[...l,...o[u]]:E(l)&&E(o[u])?o[u]=S(l,o[u],(r?`${r}.`:"")+u.toString(),i):o[u]=l))}return o}function mt(t){return(...e)=>e.reduce((r,i)=>S(r,i,"",t),{})}const F=mt();let k=null;const T=t=>{k=t},M=()=>{if(!k)throw new Error("Api client not initialized. Call setApiClient() first.");return k},Ft=()=>k;function C(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function $(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&C(t[e]))return!0;return!1}function R(t,e,r,i,o){if(!(!t||typeof t!="object"))for(let u in t){const l=t[u];if(l&&typeof l=="object"){if("__args"in l){const h=l.__args,s={};Object.entries(h).forEach(([n,c])=>{if(c instanceof Array&&C(c)){s[n]=new b.VariableType(n);let a=0;c.forEach(p=>{p instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+n+"."+a),i.append(o.current.toString(),p),o.current++,a++)}),e[n]="[Upload!]!"}else c instanceof File?(s[n]=new b.VariableType(n),r[o.current]=["variables."+n],i.append(o.current.toString(),c),e[n]="Upload!",o.current++):c instanceof Object&&$(c)?(s[n]={},Object.entries(c).forEach(([a,p])=>{if(p instanceof Array&&C(p)){s[n][a]=new b.VariableType(a);let g=0;p.forEach(y=>{y instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+a+"."+g),i.append(o.current.toString(),y),o.current++,g++)}),e[a]="[Upload!]!"}else p instanceof File?(s[n][a]=new b.VariableType(a),r[o.current]=["variables."+a],i.append(o.current.toString(),p),e[a]="Upload!",o.current++):s[n][a]=p})):c!=null&&(s[n]=c)}),l.__args=s}R(l,e,r,i,o)}}}const w=async t=>{const e=M(),r=t,i=new FormData;let o=!1;const u={},l={};R(r,u,l,i,{current:0}),o=Object.keys(u).length>0,o&&(r.__variables=u);let s=null;const n={query:r},c=b.jsonToGraphQLQuery(n);if(o?(i.append("map",JSON.stringify(l)),i.append("operations",JSON.stringify({query:c})),s=await e.axios.post("",i)):s=await e.axios.post("",{query:c}),s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function P(t,e){let r,i=[],o,u;const l=s=>!s||typeof s!="object"?!1:Object.values(s).some(n=>n&&typeof n=="object"&&Object.keys(n).some(c=>c.startsWith("_"))),h=()=>i.length===0?(i.unshift({}),i[0]):(l(i[0])&&i.unshift({}),i[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const n=await this.limit(1).fetch();return Array.isArray(n)&&n.length>0?n[0]:null},async fetchWithMeta(){let n=await w(this.toQuery(!0));if(u){const c=u.split(".");for(const a of c)n=n[a];return n}return n[`list${t}`]},async fetch(){let n=await w(this.toQuery());if(u){const c=u.split(".");for(const a of c)n=n[a];return n.data}return n[`list${t}`].data},dataPath(s){return s&&typeof s=="string"&&(u=s),this},sort(s){return s&&typeof s=="string"&&(o=s),this},filters(s){return s&&typeof s=="object"&&(i=[s]),this},where(s,n,c){const a=(p,g,y)=>{const D={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[g];D&&i.push({[p]:{[D]:y}})};if(c!==void 0)a(s,String(n),c);else{const p=h(),g=F(p,{[s]:n});i[0]=g}return this},whereContains(s,n){if(s&&typeof s=="string"){const c=h(),a={_contains:n};c[s]?Array.isArray(c[s])?c[s].push(a):c[s]=[c[s],a]:c[s]=[a],i[0]=c}return this},whereIn(s,n){if(s&&typeof s=="string"&&Array.isArray(n)){const c=h(),a={_in:n};c[s]?Array.isArray(c[s])?c[s].push(a):c[s]=[c[s],a]:c[s]=[a],i[0]=c}return this},whereBetween(s,n,c){if(s&&typeof s=="string"){const a=h(),p={_between:[n,c]};a[s]?Array.isArray(a[s])?a[s].push(p):a[s]=[a[s],p]:a[s]=p,i[0]=a}return this},limit(s){return typeof s=="number"&&Number.isFinite(s)&&(r=F(r||{},{limit:s})),this},offset(s){return typeof s=="number"&&Number.isFinite(s)&&(r=F(r||{},{offset:s})),this},toQuery(s=!1){let n;const c=i.length>0&&Object.keys(i[0]||{}).length>0,a=c?1:0,p=i.length>a;c&&p?n=i:p?n=i.slice(a):c&&(n=i[0]);const g=F(o?{sort:o}:{},n?{filters:n}:{}),y={data:{...e}};if(r&&(y.data.__args=r),Object.keys(g).length>0&&(y.__args=g),s&&(y.meta={total:!0,key:!0,name:!0}),u){const m=u.split(".");let D=y;for(let L=m.length-1;L>=0;L--)D={[m[L]]:D};return D}return{[`list${t}`]:y}}}}const At=(t,e={})=>{const r=t,i=e;let o="list"+t;const u=l=>i[l]?i[l]:null;return{field:u,$fields:i,setDataPath(l){return o=l,o},getDataPath(){return o},gqlFields(l){let h={};for(const s of l)if(typeof s=="string"){const n=u(s);n&&(h=F(h,n.gqlField?typeof n.gqlField=="string"?{[n.gqlField]:!0}:n.gqlField:{[n.name||s]:!0}))}else typeof s=="object"&&(h=F(h,s));return h},update(l,h){return d({["update"+r]:{__args:{id:l,data:h}}}).then(s=>s["update"+r])},async delete(l){return d({["delete"+r]:{__args:{id:l}}}).then(h=>h["delete"+r])},add(l){return d({["add"+r]:{__args:{data:l}}}).then(h=>h["add"+r])},fields(l){let h=[];for(let s of l){const n=u(s);n&&h.push(n)}return h},async get(l,h){const s=(await Promise.resolve().then(()=>Bt)).default,n=s(r,wt(h));for(const[c,a]of Object.entries(l))n.where(c,"==",a);return await n.first()},list(l){let h=l;const s={};Object.entries(l).forEach(([a])=>{i[a]&&(s[a]=i[a],i[a].gqlField&&(delete h[a],h=F(h,i[a].gqlField)),i[a].gql&&(h=F(h,i[a].gql),delete h[a]))});const n=P(r,h).dataPath(o),c=n.fetch.bind(n);return{...n,async fetch(){return(await c()).map(p=>{const g={...p};return Object.entries(s).forEach(([y,m])=>{m.format&&typeof m.format=="function"&&(g[y]=m.format(p))}),g})},async fetchFirst(){const p=await n.fetchFirst.bind(n)();if(!p)return p;const g={...p};return Object.entries(s).forEach(([y,m])=>{m.format&&typeof m.format=="function"&&(g[y]=m.format(p))}),g}}}}},O={},q=(t,e)=>{const r=At(t,e);return O[t]=r,r},U=t=>O[t]?O[t]:q(t,{}),Ot=t=>!!O[t],Dt=()=>Object.keys(O),Ct=()=>{Object.keys(O).forEach(t=>delete O[t])},Pt=t=>{Object.entries(t).forEach(([e,r])=>{q(e,r)})},jt=()=>w({app:{permissions:!0}}).then(t=>t.app.permissions),W=async()=>{const{app:t}=await w({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},z=async()=>{const{app:t}=await w({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},Q=Object.freeze(Object.defineProperty({__proto__:null,assertion:W,attestation:z,login:async()=>{const t=await W();return await d({webAuthnAssertion:{__args:{assertion:t.toJSON()}}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await z();return await d({webAuthnRegister:{__args:{registration:t.toJSON()}}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),G=(t=N)=>w({my:t}).then(e=>e.my),H=(t,e,r="")=>d({login:{__args:{username:t,password:e,code:r}}}).then(i=>i.login),V=()=>d({logout:!0}).then(t=>t.logout),X=(t,e,r)=>d({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(i=>i.changeExpiredPassword),Y=(t,e)=>d({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),Z=(t,e,r)=>d({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(i=>i.resetPassword),I=(t,e)=>d({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),K=(t,e)=>d({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),x=t=>w({my:{granted:{__args:{right:t}}}}).then(e=>e.my.granted),tt=t=>w({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),et=()=>({getCurrentUser:G,webAuthn:Q,google:{unlink:()=>d({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>d({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>d({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>d({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>d({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>d({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>d({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>d({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>d({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:H,logout:V,changeExpiredPassword:X,updatePassword:Y,resetPassword:Z,forgetPassword:I,verifyCode:K,grantedRights:tt,isGranted:x}),rt={name:!0,path:!0,size:!0,mime:!0,url:!0},st=(t,e,r=rt)=>w({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(i=>i.app.drive.files),nt=(t,e)=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}}).then(r=>r.app.drive?.file?.base64Content),A=t=>({list:(e,r=rt)=>st(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(i=>i.app.drive.file),readFileAsBase64(e){return nt(t,e)},read:async e=>{let r=await w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>d({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(i=>i.lightDriveWriteFile),delete:e=>d({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>d({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(i=>i.lightDriveRenameFile),move:(e,r)=>d({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(i=>i.lightDriveMoveFile)}),it={name:!0,path:!0},ot=(t,e,r=it)=>w({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(i=>i.app.drive.folders),j=t=>({list:(e,r=it)=>ot(t,e,r),create:e=>d({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>d({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>d({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(i=>i.lightDriveRenameFolder)}),kt=()=>w({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),at=t=>({listFiles:A(t).list,getFile:A(t).get,readFile:A(t).read,writeFile:A(t).write,deleteFile:A(t).delete,renameFile:A(t).rename,moveFile:A(t).move,listFolders:j(t).list,createFolder:j(t).create,deleteFolder:j(t).delete,renameFolder:j(t).rename,uploadTempFile:e=>d({lightDriveUploadTempFile:{__args:{index:t,file:e},name:!0,path:!0,size:!0,mime:!0}}).then(r=>r.lightDriveUploadTempFile),folders:j(t),files:A(t)}),N={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},ct=t=>d({addUser:{__args:t}}).then(e=>e.addUser),lt=t=>d({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),ut=(t=N)=>P("Users",t).dataPath("app.listUser").fetch(),ht=(t,e)=>d({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Ut=()=>({list:ut,create:ct,delete:lt,update:ht}),ft=t=>w({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),vt={name:!0},pt=(t=vt)=>w({app:{roles:t}}).then(e=>e.app.roles),dt=(t,e)=>d({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),gt=t=>d({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),Et=()=>({list:pt,create:dt,delete:gt});function _t(t,e,r,i,o){if(!(!t||typeof t!="object"))for(let u in t){const l=t[u];if(l&&typeof l=="object"){if("__args"in l){const h=l.__args,s={};Object.entries(h).forEach(([n,c])=>{if(c instanceof Array&&C(c)){s[n]=new b.VariableType(n);let a=0;c.forEach(p=>{p instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+n+"."+a),i.append(o.current.toString(),p),o.current++,a++)}),e[n]="[Upload!]!"}else c instanceof File?(s[n]=new b.VariableType(n),r[o.current]=["variables."+n],i.append(o.current.toString(),c),e[n]="Upload!",o.current++):c instanceof Object&&$(c)?(s[n]={},Object.entries(c).forEach(([a,p])=>{if(p instanceof Array&&C(p)){s[n][a]=new b.VariableType(a);let g=0;p.forEach(y=>{y instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+a+"."+g),i.append(o.current.toString(),y),o.current++,g++)}),e[a]="[Upload!]!"}else p instanceof File?(s[n][a]=new b.VariableType(a),r[o.current]=["variables."+a],i.append(o.current.toString(),p),e[a]="Upload!",o.current++):s[n][a]=p})):c!=null&&(s[n]=c)}),l.__args=s}_t(l,e,r,i,o)}}}const d=async t=>{const r=M().axios,i=t,o=new FormData;let u=!1;const l={},h={};_t(i,l,h,o,{current:0}),u=Object.keys(l).length>0,u&&(i.__variables=l);let n=null;const c={mutation:i},a=b.jsonToGraphQLQuery(c);if(u?(o.append("map",JSON.stringify(h)),o.append("operations",JSON.stringify({query:a})),n=await r.post("",o)):n=await r.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data},yt=(t,e,r)=>d({sendMail:{__args:{email:t,subject:e,message:r}}}).then(i=>i.sendMail),St={send:yt},B=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(B(r)).forEach(([i,o])=>{e[i]=o})}),e):(Object.entries(t).forEach(([r,i])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=i;return}if(typeof i=="boolean"){e[r]=i;return}e[r]=B(i)}),e)},wt=t=>B(t),Mt="list",qt=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],Nt=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition"];class _{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}_.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},_.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},_.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},_.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},v().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),_.prototype.fetchData=async function(){try{if(this._batchData){const h=this._batchData;return this.meta=h.meta,v(h.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},i=r,o=e[e.length-1];for(const h of e){if(h===o){i[h]=t;break}i[h]={},i=i[h]}let l=await w(r);for(const h of e)l=l[h];return this.meta=l.meta,v(l.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},_.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},_.prototype.all=async function(){return(await this.processData()).all()};for(const t of qt)_.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Nt)_.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};_.prototype.average=_.prototype.avg,_.prototype.first=async function(){return this.take(1),(await this.processData()).first()},_.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},_.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],i=t[1],o=t[2];switch(i){case"==":this.filters[r]=o;break;case"<":this.filters[r]={lt:o};break;case"<=":this.filters[r]={lte:o};break;case">":this.filters[r]={gt:o};break;case">=":this.filters[r]={gte:o};break;case"!==":this.filters[r]={ne:o};break;default:throw new Error(`Unsupported operator: ${i}`)}}return this},_.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},_.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},_.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},_.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},_.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},_.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},_.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},_.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},_.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},_.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},_.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const J=(t,e)=>{const r=new _(e);return r.data_path=Mt+t,r},Bt=Object.freeze(Object.defineProperty({__proto__:null,default:J},Symbol.toStringTag,{value:"Module"})),Jt=t=>{const e=typeof window>"u";let r=[];const i=bt.create({baseURL:t,withCredentials:!0});e&&(i.interceptors.request.use(u=>(u.withCredentials=!0,r.length>0&&(u.headers.Cookie=r.join("; ")),u)),i.interceptors.response.use(u=>{if(u.headers["set-cookie"]){const l=u.headers["set-cookie"].map(s=>s.split(";")[0]),h=new Map;r.forEach(s=>{const n=s.split("=")[0];h.set(n,s)}),l.forEach(s=>{const n=s.split("=")[0];h.set(n,s)}),r=Array.from(h.values())}return u}));const o={post:i.post,baseURL:t,axios:i,auth:et(),mutation:d,query:w,config:ft,mail:St,users:Ut(),model(u){return U(u)},roles:Et(),collect:(u,l)=>{const h=J(u,l);return h.data_path=U(u).getDataPath(),h},list:(u,l)=>P(u,l).dataPath(U(u).getDataPath()),drive:at,async collects(u){const l={},h={};for(const n in u){const c=u[n].getQueryPayload();h[n]=c.data_path,l[n]={};const a=c.data_path.split(".");let p=a[a.length-1],g=l[n];for(const y of a){if(y===p){g[y]=c.query;break}g[y]=g[y]||{}}l[n].__aliasFor=a[0]}const s=await w(l);for(const n in u){const c=h[n].split(".");let a=c[c.length-1],p=s[n];for(const g of c){if(g===a){u[n]._batchData=s[n][g];break}p[g]=p[g]||{}}}return u}};return T(o),o},Lt=P;f.auth=et,f.changeExpiredPassword=X,f.clearModels=Ct,f.createClient=Jt,f.createCollection=J,f.createList=P,f.createRole=dt,f.createUser=ct,f.defaultUserFields=N,f.defineModel=q,f.defineModels=Pt,f.deleteRole=gt,f.deleteUser=lt,f.forgetPassword=I,f.getApiClient=M,f.getApiClientOptional=Ft,f.getConfig=ft,f.getCurrentUser=G,f.getDrive=at,f.getGrantedRights=tt,f.getModel=U,f.hasModel=Ot,f.isGranted=x,f.list=Lt,f.listDrives=kt,f.listFiles=st,f.listFolders=ot,f.listModels=Dt,f.listPermissions=jt,f.listRoles=pt,f.listUsers=ut,f.login=H,f.logout=V,f.mutation=d,f.query=w,f.readFileAsBase64=nt,f.resetPassword=Z,f.sendMail=yt,f.setApiClient=T,f.toQuery=wt,f.updatePassword=Y,f.updateUser=ht,f.verifyCode=K,f.webAuthn=Q,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(f,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],m):(f=typeof globalThis<"u"?globalThis:f||self,m(f.light={},f.jsonToGraphqlQuery,f.axios,f.collect))})(this,(function(f,m,bt,v){"use strict";function S(t){if(t===null||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null||Symbol.iterator in t?!1:Symbol.toStringTag in t?Object.prototype.toString.call(t)==="[object Module]":!0}function E(t,e,r=".",n){if(!S(e))return E(t,{},r,n);const o=Object.assign({},e);for(const h in t){if(h==="__proto__"||h==="constructor")continue;const l=t[h];l!=null&&(n&&n(o,h,l,r)||(Array.isArray(l)&&Array.isArray(o[h])?o[h]=[...l,...o[h]]:S(l)&&S(o[h])?o[h]=E(l,o[h],(r?`${r}.`:"")+h.toString(),n):o[h]=l))}return o}function Ft(t){return(...e)=>e.reduce((r,n)=>E(r,n,"",t),{})}const F=Ft();let k=null;const $=t=>{k=t},M=()=>{if(!k)throw new Error("Api client not initialized. Call setApiClient() first.");return k},At=()=>k;function O(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function B(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&O(t[e]))return!0;return!1}function Ct(t){t="<~"+t+"~>";var e,r,n,o,h,l=String,u=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,n=[],o=0,h=t.length;h>o;o+=5)r=52200625*(t.charCodeAt(o)-33)+614125*(t.charCodeAt(o+1)-33)+7225*(t.charCodeAt(o+2)-33)+85*(t.charCodeAt(o+3)-33)+(t.charCodeAt(o+4)-33),n.push(u&r>>24,u&r>>16,u&r>>8,u&r);return(function(s,i){for(var a=i;a>0;a--)s.pop()})(n,e.length),l.fromCharCode.apply(l,n)}const q=(t="")=>{const e=t,r=(n="application/octet-stream")=>{const o=new Uint8Array(e.length);for(let u=0;u<e.length;u++)o[u]=e.charCodeAt(u);const h=new Blob([o],{type:n});return URL.createObjectURL(h)};return{getContent:()=>e,getURL:r,download:n=>{const o=document.createElement("a");o.download=n,o.href=r(),document.body.appendChild(o),o.click(),document.body.removeChild(o)},open:n=>{window.open(r(n),"_blank")}}},Ot=t=>q(atob(t)),Dt=t=>q(Ct(t));function W(t,e,r,n,o){if(!(!t||typeof t!="object"))for(let h in t){const l=t[h];if(l&&typeof l=="object"){if("__args"in l){const u=l.__args,s={};Object.entries(u).forEach(([i,a])=>{if(a instanceof Array&&O(a)){s[i]=new m.VariableType(i);let c=0;a.forEach(p=>{p instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+c),n.append(o.current.toString(),p),o.current++,c++)}),e[i]="[Upload!]!"}else a instanceof File?(s[i]=new m.VariableType(i),r[o.current]=["variables."+i],n.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&B(a)?(s[i]={},Object.entries(a).forEach(([c,p])=>{if(p instanceof Array&&O(p)){s[i][c]=new m.VariableType(c);let g=0;p.forEach(y=>{y instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+c+"."+g),n.append(o.current.toString(),y),o.current++,g++)}),e[c]="[Upload!]!"}else p instanceof File?(s[i][c]=new m.VariableType(c),r[o.current]=["variables."+c],n.append(o.current.toString(),p),e[c]="Upload!",o.current++):s[i][c]=p})):a!=null&&(s[i]=a)}),l.__args=s}W(l,e,r,n,o)}}}const w=async t=>{const e=M(),r=t,n=new FormData;let o=!1;const h={},l={};W(r,h,l,n,{current:0}),o=Object.keys(h).length>0,o&&(r.__variables=h);let s=null;const i={query:r},a=m.jsonToGraphQLQuery(i);if(o?(n.append("map",JSON.stringify(l)),n.append("operations",JSON.stringify({query:a})),s=await e.axios.post("",n)):s=await e.axios.post("",{query:a}),s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function P(t,e){let r,n=[],o,h;const l=s=>!s||typeof s!="object"?!1:Object.values(s).some(i=>i&&typeof i=="object"&&Object.keys(i).some(a=>a.startsWith("_"))),u=()=>n.length===0?(n.unshift({}),n[0]):(l(n[0])&&n.unshift({}),n[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const i=await this.limit(1).fetch();return Array.isArray(i)&&i.length>0?i[0]:null},async fetchWithMeta(){let i=await w(this.toQuery(!0));if(h){const a=h.split(".");for(const c of a)i=i[c];return i}return i[`list${t}`]},async fetch(){let i=await w(this.toQuery());if(h){const a=h.split(".");for(const c of a)i=i[c];return i.data}return i[`list${t}`].data},dataPath(s){return s&&typeof s=="string"&&(h=s),this},sort(s){return s&&typeof s=="string"&&(o=s),this},filters(s){return s&&typeof s=="object"&&(n=[s]),this},where(s,i,a){const c=(p,g,y)=>{const D={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[g];D&&n.push({[p]:{[D]:y}})};if(a!==void 0)c(s,String(i),a);else{const p=u(),g=F(p,{[s]:i});n[0]=g}return this},whereContains(s,i){if(s&&typeof s=="string"){const a=u(),c={_contains:i};a[s]?Array.isArray(a[s])?a[s].push(c):a[s]=[a[s],c]:a[s]=[c],n[0]=a}return this},whereIn(s,i){if(s&&typeof s=="string"&&Array.isArray(i)){const a=u(),c={_in:i};a[s]?Array.isArray(a[s])?a[s].push(c):a[s]=[a[s],c]:a[s]=[c],n[0]=a}return this},whereBetween(s,i,a){if(s&&typeof s=="string"){const c=u(),p={_between:[i,a]};c[s]?Array.isArray(c[s])?c[s].push(p):c[s]=[c[s],p]:c[s]=p,n[0]=c}return this},limit(s){return typeof s=="number"&&Number.isFinite(s)&&(r=F(r||{},{limit:s})),this},offset(s){return typeof s=="number"&&Number.isFinite(s)&&(r=F(r||{},{offset:s})),this},toQuery(s=!1){let i;const a=n.length>0&&Object.keys(n[0]||{}).length>0,c=a?1:0,p=n.length>c;a&&p?i=n:p?i=n.slice(c):a&&(i=n[0]);const g=F(o?{sort:o}:{},i?{filters:i}:{}),y={data:{...e}};if(r&&(y.data.__args=r),Object.keys(g).length>0&&(y.__args=g),s&&(y.meta={total:!0,key:!0,name:!0}),h){const b=h.split(".");let D=y;for(let R=b.length-1;R>=0;R--)D={[b[R]]:D};return D}return{[`list${t}`]:y}}}}const Pt=(t,e={})=>{const r=t,n=e;let o="list"+t;const h=l=>n[l]?n[l]:null;return{field:h,$fields:n,setDataPath(l){return o=l,o},getDataPath(){return o},gqlFields(l){let u={};for(const s of l)if(typeof s=="string"){const i=h(s);i&&(u=F(u,i.gqlField?typeof i.gqlField=="string"?{[i.gqlField]:!0}:i.gqlField:{[i.name||s]:!0}))}else typeof s=="object"&&(u=F(u,s));return u},update(l,u){return d({["update"+r]:{__args:{id:l,data:u}}}).then(s=>s["update"+r])},async delete(l){return d({["delete"+r]:{__args:{id:l}}}).then(u=>u["delete"+r])},add(l){return d({["add"+r]:{__args:{data:l}}}).then(u=>u["add"+r])},fields(l){let u=[];for(let s of l){const i=h(s);i&&u.push(i)}return u},async get(l,u){const s=(await Promise.resolve().then(()=>Rt)).default,i=s(r,mt(u));for(const[a,c]of Object.entries(l))i.where(a,"==",c);return await i.first()},list(l){let u=l;const s={};Object.entries(l).forEach(([c])=>{n[c]&&(s[c]=n[c],n[c].gqlField&&(delete u[c],u=F(u,n[c].gqlField)),n[c].gql&&(u=F(u,n[c].gql),delete u[c]))});const i=P(r,u).dataPath(o),a=i.fetch.bind(i);return{...i,async fetch(){return(await a()).map(p=>{const g={...p};return Object.entries(s).forEach(([y,b])=>{b.format&&typeof b.format=="function"&&(g[y]=b.format(p))}),g})},async fetchFirst(){const p=await i.fetchFirst.bind(i)();if(!p)return p;const g={...p};return Object.entries(s).forEach(([y,b])=>{b.format&&typeof b.format=="function"&&(g[y]=b.format(p))}),g}}}}},C={},N=(t,e)=>{const r=Pt(t,e);return C[t]=r,r},U=t=>C[t]?C[t]:N(t,{}),jt=t=>!!C[t],kt=()=>Object.keys(C),Ut=()=>{Object.keys(C).forEach(t=>delete C[t])},vt=t=>{Object.entries(t).forEach(([e,r])=>{N(e,r)})},St=()=>w({app:{permissions:!0}}).then(t=>t.app.permissions),z=async()=>{const{app:t}=await w({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},Q=async()=>{const{app:t}=await w({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},G=Object.freeze(Object.defineProperty({__proto__:null,assertion:z,attestation:Q,login:async()=>{const t=await z();return await d({webAuthnAssertion:{__args:{assertion:t.toJSON()}}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await Q();return await d({webAuthnRegister:{__args:{registration:t.toJSON()}}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),H=(t=L)=>w({my:t}).then(e=>e.my),V=(t,e,r="")=>d({login:{__args:{username:t,password:e,code:r}}}).then(n=>n.login),X=()=>d({logout:!0}).then(t=>t.logout),Y=(t,e,r)=>d({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(n=>n.changeExpiredPassword),Z=(t,e)=>d({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),I=(t,e,r)=>d({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(n=>n.resetPassword),K=(t,e)=>d({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),x=(t,e)=>d({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),tt=t=>w({my:{granted:{__args:{right:t}}}}).then(e=>e.my.granted),et=t=>w({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),rt=()=>({getCurrentUser:H,webAuthn:G,google:{unlink:()=>d({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>d({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>d({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>d({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>d({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>d({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>d({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>d({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>d({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:V,logout:X,changeExpiredPassword:Y,updatePassword:Z,resetPassword:I,forgetPassword:K,verifyCode:x,grantedRights:et,isGranted:tt}),st={name:!0,path:!0,size:!0,mime:!0,url:!0},nt=(t,e,r=st)=>w({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(n=>n.app.drive.files),it=(t,e)=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}}).then(r=>r.app.drive?.file?.base64Content),A=t=>({list:(e,r=st)=>nt(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(n=>n.app.drive.file),readFileAsBase64(e){return it(t,e)},read:async e=>{let r=await w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>d({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(n=>n.lightDriveWriteFile),delete:e=>d({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>d({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFile),move:(e,r)=>d({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(n=>n.lightDriveMoveFile)}),ot={name:!0,path:!0},at=(t,e,r=ot)=>w({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(n=>n.app.drive.folders),j=t=>({list:(e,r=ot)=>at(t,e,r),create:e=>d({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>d({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>d({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFolder)}),Et=()=>w({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),ct=t=>({listFiles:A(t).list,getFile:A(t).get,readFile:A(t).read,writeFile:A(t).write,deleteFile:A(t).delete,renameFile:A(t).rename,moveFile:A(t).move,listFolders:j(t).list,createFolder:j(t).create,deleteFolder:j(t).delete,renameFolder:j(t).rename,uploadTempFile:e=>d({lightDriveUploadTempFile:{__args:{index:t,file:e},name:!0,path:!0,size:!0,mime:!0}}).then(r=>r.lightDriveUploadTempFile),folders:j(t),files:A(t)}),L={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},lt=t=>d({addUser:{__args:t}}).then(e=>e.addUser),ut=t=>d({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),ht=(t=L)=>P("Users",t).dataPath("app.listUser").fetch(),ft=(t,e)=>d({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Mt=()=>({list:ht,create:lt,delete:ut,update:ft}),pt=t=>w({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Bt={name:!0},dt=(t=Bt)=>w({app:{roles:t}}).then(e=>e.app.roles),gt=(t,e)=>d({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),_t=t=>d({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),qt=()=>({list:dt,create:gt,delete:_t});function yt(t,e,r,n,o){if(!(!t||typeof t!="object"))for(let h in t){const l=t[h];if(l&&typeof l=="object"){if("__args"in l){const u=l.__args,s={};Object.entries(u).forEach(([i,a])=>{if(a instanceof Array&&O(a)){s[i]=new m.VariableType(i);let c=0;a.forEach(p=>{p instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+c),n.append(o.current.toString(),p),o.current++,c++)}),e[i]="[Upload!]!"}else a instanceof File?(s[i]=new m.VariableType(i),r[o.current]=["variables."+i],n.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&B(a)?(s[i]={},Object.entries(a).forEach(([c,p])=>{if(p instanceof Array&&O(p)){s[i][c]=new m.VariableType(c);let g=0;p.forEach(y=>{y instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+c+"."+g),n.append(o.current.toString(),y),o.current++,g++)}),e[c]="[Upload!]!"}else p instanceof File?(s[i][c]=new m.VariableType(c),r[o.current]=["variables."+c],n.append(o.current.toString(),p),e[c]="Upload!",o.current++):s[i][c]=p})):a!=null&&(s[i]=a)}),l.__args=s}yt(l,e,r,n,o)}}}const d=async t=>{const r=M().axios,n=t,o=new FormData;let h=!1;const l={},u={};yt(n,l,u,o,{current:0}),h=Object.keys(l).length>0,h&&(n.__variables=l);let i=null;const a={mutation:n},c=m.jsonToGraphQLQuery(a);if(h?(o.append("map",JSON.stringify(u)),o.append("operations",JSON.stringify({query:c})),i=await r.post("",o)):i=await r.post("",{query:c}),i.data.errors)throw new Error(i.data.errors[0].message);return i.data.data},wt=(t,e,r)=>d({sendMail:{__args:{email:t,subject:e,message:r}}}).then(n=>n.sendMail),Nt={send:wt},J=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(J(r)).forEach(([n,o])=>{e[n]=o})}),e):(Object.entries(t).forEach(([r,n])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=n;return}if(typeof n=="boolean"){e[r]=n;return}e[r]=J(n)}),e)},mt=t=>J(t),Lt="list",Jt=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],Tt=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition"];class _{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}_.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},_.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},_.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},_.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},v().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),_.prototype.fetchData=async function(){try{if(this._batchData){const u=this._batchData;return this.meta=u.meta,v(u.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},n=r,o=e[e.length-1];for(const u of e){if(u===o){n[u]=t;break}n[u]={},n=n[u]}let l=await w(r);for(const u of e)l=l[u];return this.meta=l.meta,v(l.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},_.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},_.prototype.all=async function(){return(await this.processData()).all()};for(const t of Jt)_.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Tt)_.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};_.prototype.average=_.prototype.avg,_.prototype.first=async function(){return this.take(1),(await this.processData()).first()},_.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},_.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],n=t[1],o=t[2];switch(n){case"==":this.filters[r]=o;break;case"<":this.filters[r]={lt:o};break;case"<=":this.filters[r]={lte:o};break;case">":this.filters[r]={gt:o};break;case">=":this.filters[r]={gte:o};break;case"!==":this.filters[r]={ne:o};break;default:throw new Error(`Unsupported operator: ${n}`)}}return this},_.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},_.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},_.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},_.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},_.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},_.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},_.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},_.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},_.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},_.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},_.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const T=(t,e)=>{const r=new _(e);return r.data_path=Lt+t,r},Rt=Object.freeze(Object.defineProperty({__proto__:null,default:T},Symbol.toStringTag,{value:"Module"})),$t=t=>{const e=typeof window>"u";let r=[];const n=bt.create({baseURL:t,withCredentials:!0});e&&(n.interceptors.request.use(h=>(h.withCredentials=!0,r.length>0&&(h.headers.Cookie=r.join("; ")),h)),n.interceptors.response.use(h=>{if(h.headers["set-cookie"]){const l=h.headers["set-cookie"].map(s=>s.split(";")[0]),u=new Map;r.forEach(s=>{const i=s.split("=")[0];u.set(i,s)}),l.forEach(s=>{const i=s.split("=")[0];u.set(i,s)}),r=Array.from(u.values())}return h}));const o={post:n.post,baseURL:t,axios:n,auth:rt(),mutation:d,query:w,config:pt,mail:Nt,users:Mt(),model(h){return U(h)},roles:qt(),collect:(h,l)=>{const u=T(h,l);return u.data_path=U(h).getDataPath(),u},list:(h,l)=>P(h,l).dataPath(U(h).getDataPath()),drive:ct,async collects(h){const l={},u={};for(const i in h){const a=h[i].getQueryPayload();u[i]=a.data_path,l[i]={};const c=a.data_path.split(".");let p=c[c.length-1],g=l[i];for(const y of c){if(y===p){g[y]=a.query;break}g[y]=g[y]||{}}l[i].__aliasFor=c[0]}const s=await w(l);for(const i in h){const a=u[i].split(".");let c=a[a.length-1],p=s[i];for(const g of a){if(g===c){h[i]._batchData=s[i][g];break}p[g]=p[g]||{}}}return h}};return $(o),o},Wt=P;f.arrayHasFile=O,f.auth=rt,f.changeExpiredPassword=Y,f.clearModels=Ut,f.createClient=$t,f.createCollection=T,f.createFileFromBase64=Ot,f.createFileFromBase85=Dt,f.createFileFromString=q,f.createList=P,f.createRole=gt,f.createUser=lt,f.defaultUserFields=L,f.defineModel=N,f.defineModels=vt,f.deleteRole=_t,f.deleteUser=ut,f.forgetPassword=K,f.getApiClient=M,f.getApiClientOptional=At,f.getConfig=pt,f.getCurrentUser=H,f.getDrive=ct,f.getGrantedRights=et,f.getModel=U,f.hasModel=jt,f.isGranted=tt,f.list=Wt,f.listDrives=Et,f.listFiles=nt,f.listFolders=at,f.listModels=kt,f.listPermissions=St,f.listRoles=dt,f.listUsers=ht,f.login=V,f.logout=X,f.mutation=d,f.objectHasFile=B,f.query=w,f.readFileAsBase64=it,f.resetPassword=I,f.sendMail=wt,f.setApiClient=$,f.toQuery=mt,f.updatePassword=Z,f.updateUser=ft,f.verifyCode=x,f.webAuthn=G,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|