@hostlink/light 2.7.1 → 2.8.0

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 +1 @@
1
- (function(y,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):(y=typeof globalThis<"u"?globalThis:y||self,m(y.light={},y.jsonToGraphqlQuery,y.axios,y.collect))})(this,function(y,m,O,P){"use strict";var ht=Object.defineProperty;var dt=(y,m,O)=>m in y?ht(y,m,{enumerable:!0,configurable:!0,writable:!0,value:O}):y[m]=O;var D=(y,m,O)=>dt(y,typeof m!="symbol"?m+"":m,O);function J(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,s=atob(r),n=new ArrayBuffer(s.length),i=new Uint8Array(n);for(let c=0;c<s.length;c++)i[c]=s.charCodeAt(c);return n}function B(t){const e=new Uint8Array(t);let r="";for(const i of e)r+=String.fromCharCode(i);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var f="copy",A="convert";function S(t,e,r){if(e===f)return r;if(e===A)return t(r);if(e instanceof Array)return r.map(s=>S(t,e[0],s));if(e instanceof Object){const s={};for(const[n,i]of Object.entries(e)){if(i.derive){const c=i.derive(r);c!==void 0&&(r[n]=c)}if(!(n in r)){if(i.required)throw new Error(`Missing key: ${n}`);continue}if(r[n]==null){s[n]=null;continue}s[n]=S(t,i.schema,r[n])}return s}}function E(t,e){return{required:!0,schema:t,derive:e}}function h(t){return{required:!0,schema:t}}function g(t){return{required:!1,schema:t}}var T={type:h(f),id:h(A),transports:g(f)},U={appid:g(f),appidExclude:g(f),credProps:g(f)},L={appid:g(f),appidExclude:g(f),credProps:g(f)},V={publicKey:h({rp:h(f),user:h({id:h(A),name:h(f),displayName:h(f)}),challenge:h(A),pubKeyCredParams:h(f),timeout:g(f),excludeCredentials:g([T]),authenticatorSelection:g(f),attestation:g(f),extensions:g(U)}),signal:g(f)},M={type:h(f),id:h(f),rawId:h(A),authenticatorAttachment:g(f),response:h({clientDataJSON:h(A),attestationObject:h(A),transports:E(f,t=>{var e;return((e=t.getTransports)==null?void 0:e.call(t))||[]})}),clientExtensionResults:E(L,t=>t.getClientExtensionResults())},W={mediation:g(f),publicKey:h({challenge:h(A),timeout:g(f),rpId:g(f),allowCredentials:g([T]),userVerification:g(f),extensions:g(U)}),signal:g(f)},K={type:h(f),id:h(f),rawId:h(A),authenticatorAttachment:g(f),response:h({clientDataJSON:h(A),authenticatorData:h(A),signature:h(A),userHandle:h(A)}),clientExtensionResults:E(L,t=>t.getClientExtensionResults())};function I(t){return S(J,V,t)}function Q(t){return S(B,M,t)}function z(t){return S(J,W,t)}function G(t){return S(B,K,t)}async function $(t){const e=await navigator.credentials.create(t);return e.toJSON=()=>Q(e),e}async function H(t){const e=await navigator.credentials.get(t);return e.toJSON=()=>G(e),e}const X=t=>({login:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnRequestOptions:!0}}}),r=e.auth.webAuthnRequestOptions,s=z({publicKey:r}),n=await H(s);await u(t,"webAuthnAssertion",{assertion:n.toJSON()})},register:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnCreationOptions:!0}}}),r=I({publicKey:e.auth.webAuthnCreationOptions}),s=await $(r);await u(t,"webAuthnRegister",{registration:s.toJSON()})}}),Y=t=>({WebAuthn:X(t),google:{unlink:()=>u(t,"lightAuthUnlinkGoogle"),login:e=>u(t,"lightAuthLoginGoogle",{credential:e}),register:e=>u(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>u(t,"lightAuthUnlinkFacebook"),login:e=>u(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>u(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>u(t,"lightAuthUnlinkMicrosoft"),login:e=>u(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>u(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>u(t,"login",{username:e,password:r,code:s}),logout:()=>u(t,"logout"),changeExpiredPassword:(e,r,s)=>u(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>u(t,"updatePassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>u(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>u(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return u(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>(await w(t,{granted:{__args:{rights:e}}})).granted}),Z=(t,e,r)=>{const s=e,n=t,i=r;let c="list"+e;const o=a=>i[a]?i[a]():null;return{field:o,$fields:i,setDataPath(a){return c=a,c},getDataPath(){return c},gqlFields(a){const l=[];for(const p of a)if(typeof p=="string"){const b=o(p);b&&l.push(b.getGQLField())}else typeof p=="object"&&l.push(p);return l},async update(a,l){return await u(n,"update"+s,{id:a,data:l})},async delete(a){return await u(n,"delete"+s,{id:a})},async add(a){return await u(n,"add"+s,{data:a})},fields(a){let l=[];for(let p of a){const b=o(p);b&&l.push(b)}return l},async get(a,l){return(await w(n,{["list"+s]:{__args:{filters:a},data:{__args:{limit:1},...k(l)}}}))["list"+s].data[0]},async list(a,l){return(await w(n,{["list"+s]:{__args:{filters:a},data:{...k(l)}}}))["list"+s].data}}};function x(t){t="<~"+t+"~>";var e,r,s,n,i,c=String,o=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,s=[],n=0,i=t.length;i>n;n+=5)r=52200625*(t.charCodeAt(n)-33)+614125*(t.charCodeAt(n+1)-33)+7225*(t.charCodeAt(n+2)-33)+85*(t.charCodeAt(n+3)-33)+(t.charCodeAt(n+4)-33),s.push(o&r>>24,o&r>>16,o&r>>8,o&r);return function(a,l){for(var p=l;p>0;p--)a.pop()}(s,e.length),c.fromCharCode.apply(c,s)}const N=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const n=new Uint8Array(e.length);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);const i=new Blob([n],{type:s});return URL.createObjectURL(i)};return{getContent:()=>e,getURL:r,download:s=>{const n=document.createElement("a");n.download=s,n.href=r(),document.body.appendChild(n),n.click(),document.body.removeChild(n)},open:s=>{window.open(r(s),"_blank")}}},tt={fromBase85:t=>N(x(t)),fromBase64:t=>N(atob(t)),fromString:t=>N(t)},R=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(R(r)).forEach(([s,n])=>{e[s]=n})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=R(s)}),e)},k=t=>R(t),w=async(t,e)=>{let r=m.jsonToGraphQLQuery(k(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function et(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function rt(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const u=async(t,e,r=null,s=[])=>{let n={[e]:{}};const i=new FormData;let c=!1;if(r){const l={},p={},b={};let F=0;Object.entries(r).forEach(([_,C])=>{if(C instanceof Array&&et(C)){c=!0;let v=0;C.forEach(q=>{q instanceof File&&(l[_]=new m.VariableType(_),p[F]=["variables."+_+"."+v],i.append(F.toString(),q),F++)}),b[_]="[Upload!]!"}else C instanceof File?(c=!0,l[_]=new m.VariableType(_),p[F]=["variables."+_],i.append(F.toString(),C),b[_]="Upload!",F++):C instanceof Object&&rt(C)?(c=!0,l[_]={},Object.entries(C).forEach(([v,q])=>{q instanceof File?(l[_][v]=new m.VariableType(v),p[F]=["variables."+v],i.append(F.toString(),q),b[v]="Upload!",F++):l[_][v]=q})):C!==void 0&&(l[_]=C)}),n[e].__args=l,n.__variables=b,c&&i.append("map",JSON.stringify(p))}Object.entries(k(s)).forEach(([l,p])=>{n[e][l]=p}),Object.entries(n[e]).length===0&&(n[e]=!0);let o=null;const a=m.jsonToGraphQLQuery({mutation:n});if(c?(i.append("operations",JSON.stringify({query:a})),o=await t.post("",i)):o=await t.post("",{query:a}),o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data[e]},st=t=>({uploadTempFile:e=>u(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await w(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>u(t,"fsCreateFolder",{path:e}),delete:e=>u(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>u(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>(await w(t,{fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,read:async e=>{let r=await w(t,{fsFile:{__args:{path:e},base64Content:!0}});return window.atob(r.fsFile.base64Content)},write:(e,r)=>u(t,"fsWriteFile",{path:e,content:r}),delete:e=>u(t,"fsDeleteFile",{path:e}),rename:(e,r)=>u(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>u(t,"fsMoveFile",{source:e,target:r})}}),nt=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),it=t=>({send:(e,r,s)=>u(t,"sendMail",{email:e,subject:r,message:s})}),at=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=j("Users",t,e);return r.data_path="app.users",r.all()}}),ot=t=>{const e=t,r={};return{create(s,n){r[s]=null;let i={};for(const c of Object.entries(n)){const[o,a]=c;i[o]=()=>({name:a.name?a.name:o,raw:a,getName:()=>a.name?a.name:o,getGQLField:()=>a.gqlField!==void 0?a.gqlField:a.name||o,getRaw(){return a},getValue(l){return a.field&&typeof a.field=="function"?a.field(l):a.field&&typeof a.field=="string"?l[a.field]:l[this.getName()]},getFormattedValue(l){const p=this.getValue(l);return a.format?a.format(p):p}})}r[s]=Z(e,s,i)},get(s){return r[s]||this.create(s,{}),r[s]}}},lt=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await w(t,{app:{roles:e}});return r}}),ut=["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"],ct=["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","sole"];class d{constructor(e,r){D(this,"_batchData",null);D(this,"data_path","");D(this,"axios");D(this,"filters");D(this,"steps");D(this,"fields");D(this,"already_limit",!1);D(this,"already_offset",!1);D(this,"limit",null);D(this,"offset",null);D(this,"_sort",null);D(this,"_sortDesc",!1);D(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}d.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}},d.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},d.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},d.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},P().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),d.prototype.fetchData=async function(){if(this._batchData){const o=this._batchData;return this.meta=o.meta,P(o.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={},s=r,n=e[e.length-1];for(const o of e){if(o===n){s[o]=t;break}s[o]={},s=s[o]}let c=await w(this.axios,r);for(const o of e)c=c[o];return this.meta=c.meta,P(c.data)},d.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},d.prototype.all=async function(){return(await this.processData()).all()};for(const t of ut)d.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of ct)d.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};d.prototype.average=d.prototype.avg,d.prototype.first=async function(){return this.take(1),(await this.processData()).first()},d.prototype.where=function(...t){if(this._batchData)return this.steps.push({type:"where",args:t}),this;if(t.length==2)this.filters[t[0]]=t[1];else if(t.length==3){let e="==",r=t[0],s=null;t.length==3&&(e=t[1],s=t[2]),e==="=="&&(this.filters[r]=s),e==="<"&&(this.filters[r]={lt:s}),e==="<="&&(this.filters[r]={lte:s}),e===">"&&(this.filters[r]={gt:s}),e===">="&&(this.filters[r]={gte:s}),e==="!=="&&(this.filters[r]={ne:s})}return this},d.prototype.whereContains=function(t,e){return this._batchData?(this.steps.push({type:"whereContains",args:[t,e]}),this):(this.filters[t]={contains:e},this)},d.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)},d.prototype.whereIn=function(t,e){return this._batchData?(this.steps.push({type:"whereIn",args:[t,e]}),this):(this.filters[t]={in:e},this)},d.prototype.whereNotIn=function(t,e){return this._batchData?(this.steps.push({type:"whereNotIn",args:[t,e]}),this):(this.filters[t]={nin:e},this)},d.prototype.whereNotBetween=function(t,e){return this._batchData?(this.steps.push({type:"whereNotBetween",args:[t,e]}),this):(this.filters[t]={notBetween:e},this)},d.prototype.whereBetween=function(t,e){return this._batchData?(this.steps.push({type:"whereBetween",args:[t,e]}),this):(this.filters[t]={between:e},this)},d.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},d.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},d.prototype.skip=function(t){return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},d.prototype.take=function(t){return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},d.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,r)=>{const s=new d(r,e);return s.data_path="list"+t,s},ft=(t,e)=>({uploadTempFile:r=>u(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await w(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>u(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>u(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>u(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});return window.atob(s.app.drive.file.base64Content)},write:(r,s)=>u(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>u(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>u(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>u(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),pt=t=>{const e=O.create({baseURL:t,withCredentials:!0}),r=(i,c=null,o=[])=>u(e,i,c,o),s=i=>w(e,i),n=ot(e);return{baseURL:t,axios:e,auth:Y(e),mutation:r,query:s,config:nt(s),mail:it(e),users:at(e),fs:st(e),models:n,model(i){return n.get(i)},roles:lt(e),collect:(i,c)=>{const o=j(i,e,c);return o.data_path=n.get(i).getDataPath(),o},drive(i){return ft(i,e)},async collects(i){const c={},o={};for(const l in i){const p=i[l].getQueryPayload();o[l]=p.data_path,c[l]={};const b=p.data_path.split(".");let F=b[b.length-1],_=c[l];for(const C of b){if(C===F){_[C]=p.query;break}_[C]=_[C]||{}}c[l].__aliasFor=b[0]}const a=await w(e,c);for(const l in i){const p=o[l].split(".");let b=p[p.length-1],F=a[l];for(const _ of p){if(_===b){i[l]._batchData=a[l][_];break}F[_]=F[_]||{}}}return i}}};y.File=tt,y.createClient=pt,y.createCollection=j,y.file=N,y.mutation=u,y.query=w,y.toQuery=k,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
1
+ (function(_,y){typeof exports=="object"&&typeof module<"u"?y(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"],y):(_=typeof globalThis<"u"?globalThis:_||self,y(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,y,k,A){"use strict";var K=Object.defineProperty;var H=(_,y,k)=>y in _?K(_,y,{enumerable:!0,configurable:!0,writable:!0,value:k}):_[y]=k;var C=(_,y,k)=>H(_,typeof y!="symbol"?y+"":y,k);const N=t=>({login:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnRequestOptions:!0}}}),r=e.auth.webAuthnRequestOptions,s=PublicKeyCredential.parseRequestOptionsFromJSON(r),a=await navigator.credentials.get({publicKey:s});await o(t,"webAuthnAssertion",{assertion:a.toJSON()})},register:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnCreationOptions:!0}}}),r=PublicKeyCredential.parseCreationOptionsFromJSON(e.auth.webAuthnCreationOptions),s=await navigator.credentials.create({publicKey:r});await o(t,"webAuthnRegister",{registration:s.toJSON()})}}),q=t=>({WebAuthn:N(t),google:{unlink:()=>o(t,"lightAuthUnlinkGoogle"),login:e=>o(t,"lightAuthLoginGoogle",{credential:e}),register:e=>o(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>o(t,"lightAuthUnlinkFacebook"),login:e=>o(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>o(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>o(t,"lightAuthUnlinkMicrosoft"),login:e=>o(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>o(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>o(t,"login",{username:e,password:r,code:s}),logout:()=>o(t,"logout"),changeExpiredPassword:(e,r,s)=>o(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>o(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>o(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>o(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return o(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await w(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}}),B=(t,e,r)=>{const s=e,a=t,g=r;let h="list"+e;const n=i=>g[i]?g[i]():null;return{field:n,$fields:g,setDataPath(i){return h=i,h},getDataPath(){return h},gqlFields(i){const l=[];for(const c of i)if(typeof c=="string"){const u=n(c);u&&l.push(u.getGQLField())}else typeof c=="object"&&l.push(c);return l},async update(i,l){return await o(a,"update"+s,{id:i,data:l})},async delete(i){return await o(a,"delete"+s,{id:i})},async add(i){return await o(a,"add"+s,{data:i})},fields(i){let l=[];for(let c of i){const u=n(c);u&&l.push(u)}return l},async get(i,l){const c=(await Promise.resolve().then(()=>j)).default,u=c(s,a,D(l));for(const[p,d]of Object.entries(i))u.where(p,"==",d);return await u.first()},async list(i,l){const c=(await Promise.resolve().then(()=>j)).default,u=c(s,a,D(l));for(const[p,d]of Object.entries(i))u.where(p,"==",d);return await u.all()}}};function R(t){t="<~"+t+"~>";var e,r,s,a,g,h=String,n=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,s=[],a=0,g=t.length;g>a;a+=5)r=52200625*(t.charCodeAt(a)-33)+614125*(t.charCodeAt(a+1)-33)+7225*(t.charCodeAt(a+2)-33)+85*(t.charCodeAt(a+3)-33)+(t.charCodeAt(a+4)-33),s.push(n&r>>24,n&r>>16,n&r>>8,n&r);return function(i,l){for(var c=l;c>0;c--)i.pop()}(s,e.length),h.fromCharCode.apply(h,s)}const v=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const a=new Uint8Array(e.length);for(let n=0;n<e.length;n++)a[n]=e.charCodeAt(n);const g=new Blob([a],{type:s});return URL.createObjectURL(g)};return{getContent:()=>e,getURL:r,download:s=>{const a=document.createElement("a");a.download=s,a.href=r(),document.body.appendChild(a),a.click(),document.body.removeChild(a)},open:s=>{window.open(r(s),"_blank")}}},E={fromBase85:t=>v(R(t)),fromBase64:t=>v(atob(t)),fromString:t=>v(t)},P=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(P(r)).forEach(([s,a])=>{e[s]=a})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=P(s)}),e)},D=t=>P(t),w=async(t,e)=>{let r=y.jsonToGraphQLQuery(D(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function S(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function L(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const o=async(t,e,r=null,s=[])=>{let a={[e]:{}};const g=new FormData;let h=!1;if(r){const l={},c={},u={};let p=0;Object.entries(r).forEach(([d,b])=>{if(b instanceof Array&&S(b)){h=!0;let m=0;b.forEach(F=>{F instanceof File&&(l[d]=new y.VariableType(d),c[p]=["variables."+d+"."+m],g.append(p.toString(),F),p++)}),u[d]="[Upload!]!"}else b instanceof File?(h=!0,l[d]=new y.VariableType(d),c[p]=["variables."+d],g.append(p.toString(),b),u[d]="Upload!",p++):b instanceof Object&&L(b)?(h=!0,l[d]={},Object.entries(b).forEach(([m,F])=>{F instanceof File?(l[d][m]=new y.VariableType(m),c[p]=["variables."+m],g.append(p.toString(),F),u[m]="Upload!",p++):l[d][m]=F})):b!==void 0&&(l[d]=b)}),a[e].__args=l,a.__variables=u,h&&g.append("map",JSON.stringify(c))}Object.entries(D(s)).forEach(([l,c])=>{a[e][l]=c}),Object.entries(a[e]).length===0&&(a[e]=!0);let n=null;const i=y.jsonToGraphQLQuery({mutation:a});if(h?(g.append("operations",JSON.stringify({query:i})),n=await t.post("",g)):n=await t.post("",{query:i}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data[e]},U=t=>({uploadTempFile:e=>o(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await w(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>o(t,"fsCreateFolder",{path:e}),delete:e=>o(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>o(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await w(t,{app:{drive:{files:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}}}});return r.drive.files},read:async e=>{let{app:r}=await w(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>o(t,"fsWriteFile",{path:e,content:r}),delete:e=>o(t,"fsDeleteFile",{path:e}),rename:(e,r)=>o(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>o(t,"fsMoveFile",{source:e,target:r})}}),J=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),T=t=>({send:(e,r,s)=>o(t,"sendMail",{email:e,subject:r,message:s})}),M=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=O("Users",t,e);return r.data_path="app.users",r.all()}}),W=t=>{const e=t,r={};return{create(s,a){r[s]=null;let g={};for(const h of Object.entries(a)){const[n,i]=h;g[n]=()=>({name:i.name?i.name:n,raw:i,getName:()=>i.name?i.name:n,getGQLField:()=>i.gqlField!==void 0?i.gqlField:i.name||n,getRaw(){return i},getValue(l){return i.field&&typeof i.field=="function"?i.field(l):i.field&&typeof i.field=="string"?l[i.field]:l[this.getName()]},getFormattedValue(l){const c=this.getValue(l);return i.format?i.format(c):c}})}r[s]=B(e,s,g)},get(s){return r[s]||this.create(s,{}),r[s]}}},z=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await w(t,{app:{roles:e}});return r}}),Q="list",V=["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"],I=["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 f{constructor(e,r){C(this,"_batchData",null);C(this,"data_path","");C(this,"axios");C(this,"filters");C(this,"steps");C(this,"fields");C(this,"already_limit",!1);C(this,"already_offset",!1);C(this,"limit",null);C(this,"offset",null);C(this,"_sort",null);C(this,"_sortDesc",!1);C(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}f.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}},f.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},f.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},f.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},A().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),f.prototype.fetchData=async function(){try{if(this._batchData){const n=this._batchData;return this.meta=n.meta,A(n.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={},s=r,a=e[e.length-1];for(const n of e){if(n===a){s[n]=t;break}s[n]={},s=s[n]}let h=await w(this.axios,r);for(const n of e)h=h[n];return this.meta=h.meta,A(h.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},f.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},f.prototype.all=async function(){return(await this.processData()).all()};for(const t of V)f.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of I)f.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};f.prototype.average=f.prototype.avg,f.prototype.first=async function(){return this.take(1),(await this.processData()).first()},f.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},f.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],s=t[1],a=t[2];switch(s){case"==":this.filters[r]=a;break;case"<":this.filters[r]={lt:a};break;case"<=":this.filters[r]={lte:a};break;case">":this.filters[r]={gt:a};break;case">=":this.filters[r]={gte:a};break;case"!==":this.filters[r]={ne:a};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},f.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},f.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)},f.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},f.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},f.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},f.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},f.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},f.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},f.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},f.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)},f.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 O=(t,e,r)=>{const s=new f(r,e);return s.data_path=Q+t,s},j=Object.freeze(Object.defineProperty({__proto__:null,default:O},Symbol.toStringTag,{value:"Module"})),$=(t,e)=>({uploadTempFile:r=>o(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await w(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>o(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>o(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>o(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});if(!s.app.drive.file||!s.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${r}`);return typeof window<"u"&&window.atob?window.atob(s.app.drive.file.base64Content):s.app.drive.file.base64Content},write:(r,s)=>o(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>o(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>o(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>o(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),G=t=>{const e=typeof window>"u";let r=[];const s=k.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(n=>(n.withCredentials=!0,r.length>0&&(n.headers.Cookie=r.join("; ")),n)),s.interceptors.response.use(n=>{if(n.headers["set-cookie"]){const i=n.headers["set-cookie"].map(u=>u.split(";")[0]),l=r.map(u=>u.split("=")[0]),c=i.filter(u=>{const p=u.split("=")[0];return!l.includes(p)});r=[...r,...c]}return n}));const a=(n,i=null,l=[])=>o(s,n,i,l),g=n=>w(s,n),h=W(s);return{baseURL:t,axios:s,auth:q(s),mutation:a,query:g,config:J(g),mail:T(s),users:M(s),fs:U(s),models:h,model(n){return h.get(n)},roles:z(s),collect:(n,i)=>{const l=O(n,s,i);return l.data_path=h.get(n).getDataPath(),l},drive(n){return $(n,s)},async collects(n){const i={},l={};for(const u in n){const p=n[u].getQueryPayload();l[u]=p.data_path,i[u]={};const d=p.data_path.split(".");let b=d[d.length-1],m=i[u];for(const F of d){if(F===b){m[F]=p.query;break}m[F]=m[F]||{}}i[u].__aliasFor=d[0]}const c=await w(s,i);for(const u in n){const p=l[u].split(".");let d=p[p.length-1],b=c[u];for(const m of p){if(m===d){n[u]._batchData=c[u][m];break}b[m]=b[m]||{}}}return n}}};_.File=E,_.createClient=G,_.createCollection=O,_.file=v,_.mutation=o,_.query=w,_.toQuery=D,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
package/dist/model.d.ts CHANGED
@@ -31,6 +31,6 @@ declare const _default: (axios: AxiosInstance, name: string, fields: any) => {
31
31
  add(data: Object): Promise<any>;
32
32
  fields(fields: string[]): ModelField[];
33
33
  get(filters: any, fields: Fields): Promise<any>;
34
- list(filters: any, fields: Fields): Promise<any>;
34
+ list(filters: any, fields: Fields): Promise<any[]>;
35
35
  };
36
36
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "2.7.1",
3
+ "version": "2.8.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -19,18 +19,18 @@
19
19
  "build": "tsc && vite build",
20
20
  "preview": "vite preview",
21
21
  "release": "npm run build && npm publish --access public && git push --follow-tags",
22
- "test": "vitest"
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
23
24
  },
24
25
  "devDependencies": {
25
- "typescript": "^5.3.3",
26
- "vite": "^5.1.4",
27
- "vite-plugin-dts": "^4.0.3",
28
- "vitest": "^2.0.5"
26
+ "typescript": "^5.8.3",
27
+ "vite": "^5.4.19",
28
+ "vite-plugin-dts": "^4.5.4",
29
+ "vitest": "^2.1.9"
29
30
  },
30
31
  "dependencies": {
31
- "@github/webauthn-json": "^2.1.1",
32
- "axios": "^1.5.1",
32
+ "axios": "^1.11.0",
33
33
  "collect.js": "^4.36.1",
34
- "json-to-graphql-query": "^2.2.5"
34
+ "json-to-graphql-query": "^2.3.0"
35
35
  }
36
36
  }