@hostlink/light 2.13.2 → 3.0.1

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(_,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):(_=typeof globalThis<"u"?globalThis:_||self,b(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,b,D,E){"use strict";var at=Object.defineProperty;var ot=(_,b,D)=>b in _?at(_,b,{enumerable:!0,configurable:!0,writable:!0,value:D}):_[b]=D;var A=(_,b,D)=>ot(_,typeof b!="symbol"?b+"":b,D);const L=t=>({assertion:async()=>{const{app:s}=await O(t,{app:{auth:{webAuthnRequestOptions:!0}}}),i=s.auth.webAuthnRequestOptions,c=PublicKeyCredential.parseRequestOptionsFromJSON(i);return await navigator.credentials.get({publicKey:c})},attestation:async()=>{const{app:s}=await O(t,{app:{auth:{webAuthnCreationOptions:!0}}}),i=PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:i})}});function q(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=".",s){if(!q(e))return S(t,{},r,s);const i=Object.assign({},e);for(const c in t){if(c==="__proto__"||c==="constructor")continue;const f=t[c];f!=null&&(s&&s(i,c,f,r)||(Array.isArray(f)&&Array.isArray(i[c])?i[c]=[...f,...i[c]]:q(f)&&q(i[c])?i[c]=S(f,i[c],(r?`${r}.`:"")+c.toString(),s):i[c]=f))}return i}function J(t){return(...e)=>e.reduce((r,s)=>S(r,s,"",t),{})}const C=J(),B=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(B(r)).forEach(([s,i])=>{e[s]=i})}),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]=B(s)}),e)},M=t=>B(t),O=async(t,e)=>{let r=b.jsonToGraphQLQuery(M(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 k(t,e,r){let s,i=[],c,f;const l=n=>!n||typeof n!="object"?!1:Object.values(n).some(o=>o&&typeof o=="object"&&Object.keys(o).some(a=>a.startsWith("_"))),p=()=>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 o=await this.limit(1).fetch();return Array.isArray(o)&&o.length>0?o[0]:null},async fetchWithMeta(){let o=await O(t,this.toQuery(!0));if(f){const a=f.split(".");for(const u of a)o=o[u];return o}return o[`list${e}`]},async fetch(){let o=await O(t,this.toQuery());if(f){const a=f.split(".");for(const u of a)o=o[u];return o.data}return o[`list${e}`].data},dataPath(n){return n&&typeof n=="string"&&(f=n),this},sort(n){return n&&typeof n=="string"&&(c=n),this},filters(n){return n&&typeof n=="object"&&(i=[n]),this},where(n,o,a){const u=(h,g,y)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[g];F&&i.push({[h]:{[F]:y}})};if(a!==void 0)u(n,String(o),a);else{const h=p(),g=C(h,{[n]:o});i[0]=g}return this},whereContains(n,o){if(n&&typeof n=="string"){const a=p(),u={_contains:o};a[n]?Array.isArray(a[n])?a[n].push(u):a[n]=[a[n],u]:a[n]=[u],i[0]=a}return this},whereIn(n,o){if(n&&typeof n=="string"&&Array.isArray(o)){const a=p(),u={_in:o};a[n]?Array.isArray(a[n])?a[n].push(u):a[n]=[a[n],u]:a[n]=[u],i[0]=a}return this},whereBetween(n,o,a){if(n&&typeof n=="string"){const u=p(),h={_between:[o,a]};u[n]?Array.isArray(u[n])?u[n].push(h):u[n]=[u[n],h]:u[n]=h,i[0]=u}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(s=C(s||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(s=C(s||{},{offset:n})),this},toQuery(n=!1){let o;const a=i.length>0&&Object.keys(i[0]||{}).length>0,u=a?1:0,h=i.length>u;a&&h?o=i:h?o=i.slice(u):a&&(o=i[0]);const g=C(c?{sort:c}:{},o?{filters:o}:{}),y={data:{...r}};if(s&&(y.data.__args=s),Object.keys(g).length>0&&(y.__args=g),n&&(y.meta={total:!0,key:!0,name:!0}),f){const m=f.split(".");let F=y;for(let R=m.length-1;R>=0;R--)F={[m[R]]:F};return F}return{[`list${e}`]:y}}}}const U=(t,e,r)=>{const s=e,i=t,c=r;let f="list"+e;const l=p=>c[p]?c[p]:null;return{field:l,$fields:c,setDataPath(p){return f=p,f},getDataPath(){return f},gqlFields(p){let n={};for(const o of p)if(typeof o=="string"){const a=l(o);a&&(n=C(n,a.gqlField?typeof a.gqlField=="string"?{[a.gqlField]:!0}:a.gqlField:{[a.name||o]:!0}))}else typeof o=="object"&&(n=C(n,o));return n},async update(p,n){return await d(i,"update"+s,{id:p,data:n})},async delete(p){return await d(i,"delete"+s,{id:p})},async add(p){return await d(i,"add"+s,{data:p})},fields(p){let n=[];for(let o of p){const a=l(o);a&&n.push(a)}return n},async get(p,n){const o=(await Promise.resolve().then(()=>st)).default,a=o(s,i,M(n));for(const[u,h]of Object.entries(p))a.where(u,"==",h);return await a.first()},list(p){let n=p;const o={};Object.entries(p).forEach(([h])=>{c[h]&&(o[h]=c[h],c[h].gqlField&&(delete n[h],n=C(n,c[h].gqlField)),c[h].gql&&(n=C(n,c[h].gql),delete n[h]))});const a=k(i,s,n).dataPath(f),u=a.fetch.bind(a);return{...a,async fetch(){return(await u()).map(g=>{const y={...g};return Object.entries(o).forEach(([m,F])=>{F.format&&typeof F.format=="function"&&(y[m]=F.format(g))}),y})},async fetchFirst(){const g=await a.fetchFirst.bind(a)();if(!g)return g;const y={...g};return Object.entries(o).forEach(([m,F])=>{F.format&&typeof F.format=="function"&&(y[m]=F.format(g))}),y}}}}},j={},P=(t,e=!1)=>{const r=t,s={};return{create(i,c){const f=U(r,i,c);s[i]=f,e&&(j[i]=f)},get(i){return s[i]||(e&&j[i]?s[i]=j[i]:this.create(i,{})),s[i]},has(i){return!!s[i]||e&&!!j[i]},list(){const i=Object.keys(s),c=e?Object.keys(j):[];return[...new Set([...i,...c])]},clear(){Object.keys(s).forEach(i=>delete s[i])}}},T=t=>{const e=P(t,!1);return{manager:e,createModel:e.create,getModel:e.get,hasModel:e.has,listModels:e.list,clearModels:e.clear,defineModel(r,s){return e.create(r,s),e.get(r)},defineModels(r){Object.entries(r).forEach(([s,i])=>{e.create(s,i)})}}},W=t=>{const e=P(t,!0);return{manager:e,createModel:e.create,getModel:e.get,hasModel:e.has,listModels:e.list,clearModels:e.clear,defineModel(r,s){return e.create(r,s),e.get(r)},defineModels(r){Object.entries(r).forEach(([s,i])=>{e.create(s,i)})}}},I=t=>({define(e,r){const s=U(t,e,r);return j[e]=s,s},get(e){return j[e]},has(e){return!!j[e]},list(){return Object.keys(j)},clear(){Object.keys(j).forEach(e=>delete j[e])}}),$=t=>{const{assertion:e,attestation:r}=L(t);return{login:async()=>{const s=await e();await d(t,"webAuthnAssertion",{assertion:s.toJSON()})},register:async()=>{const s=await r();await d(t,"webAuthnRegister",{registration:s.toJSON()})}}},Q=t=>({WebAuthn:$(t),google:{unlink:()=>d(t,"lightAuthUnlinkGoogle"),login:e=>d(t,"lightAuthLoginGoogle",{credential:e}),register:e=>d(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>d(t,"lightAuthUnlinkFacebook"),login:e=>d(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>d(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>d(t,"lightAuthUnlinkMicrosoft"),login:e=>d(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>d(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>d(t,"login",{username:e,password:r,code:s}),logout:()=>d(t,"logout"),changeExpiredPassword:(e,r,s)=>d(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>d(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>d(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>d(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return d(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await O(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}});function K(t){t="<~"+t+"~>";var e,r,s,i,c,f=String,l=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=[],i=0,c=t.length;c>i;i+=5)r=52200625*(t.charCodeAt(i)-33)+614125*(t.charCodeAt(i+1)-33)+7225*(t.charCodeAt(i+2)-33)+85*(t.charCodeAt(i+3)-33)+(t.charCodeAt(i+4)-33),s.push(l&r>>24,l&r>>16,l&r>>8,l&r);return function(p,n){for(var o=n;o>0;o--)p.pop()}(s,e.length),f.fromCharCode.apply(f,s)}const v=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let l=0;l<e.length;l++)i[l]=e.charCodeAt(l);const c=new Blob([i],{type:s});return URL.createObjectURL(c)};return{getContent:()=>e,getURL:r,download:s=>{const i=document.createElement("a");i.download=s,i.href=r(),document.body.appendChild(i),i.click(),document.body.removeChild(i)},open:s=>{window.open(r(s),"_blank")}}},z={fromBase85:t=>v(K(t)),fromBase64:t=>v(atob(t)),fromString:t=>v(t)};function G(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function H(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const d=async(t,e,r=null,s=[])=>{let i={[e]:{}};const c=new FormData;let f=!1;if(r){const n={},o={},a={};let u=0;Object.entries(r).forEach(([h,g])=>{if(g instanceof Array&&G(g)){f=!0;let y=0;g.forEach(m=>{m instanceof File&&(n[h]=new b.VariableType(h),o[u]=["variables."+h+"."+y],c.append(u.toString(),m),u++)}),a[h]="[Upload!]!"}else g instanceof File?(f=!0,n[h]=new b.VariableType(h),o[u]=["variables."+h],c.append(u.toString(),g),a[h]="Upload!",u++):g instanceof Object&&H(g)?(f=!0,n[h]={},Object.entries(g).forEach(([y,m])=>{m instanceof File?(n[h][y]=new b.VariableType(y),o[u]=["variables."+y],c.append(u.toString(),m),a[y]="Upload!",u++):n[h][y]=m})):g!==void 0&&(n[h]=g)}),i[e].__args=n,i.__variables=a,f&&c.append("map",JSON.stringify(o))}Object.entries(M(s)).forEach(([n,o])=>{i[e][n]=o}),Object.entries(i[e]).length===0&&(i[e]=!0);let l=null;const p=b.jsonToGraphQLQuery({mutation:i});if(f?(c.append("operations",JSON.stringify({query:p})),l=await t.post("",c)):l=await t.post("",{query:p}),l.data.errors)throw new Error(l.data.errors[0].message);return l.data.data[e]},V=t=>({uploadTempFile:e=>d(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await O(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>d(t,"fsCreateFolder",{path:e}),delete:e=>d(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>d(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await O(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 O(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>d(t,"fsWriteFile",{path:e,content:r}),delete:e=>d(t,"fsDeleteFile",{path:e}),rename:(e,r)=>d(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>d(t,"fsMoveFile",{source:e,target:r})}}),X=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),Y=t=>({send:(e,r,s)=>d(t,"sendMail",{email:e,subject:r,message:s})}),Z=t=>({list:(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>k(t,"Users",e).dataPath("app.users")}),x=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await O(t,{app:{roles:e}});return r}}),tt="list",et=["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"],rt=["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 w{constructor(e,r){A(this,"_batchData",null);A(this,"data_path","");A(this,"axios");A(this,"filters");A(this,"steps");A(this,"fields");A(this,"already_limit",!1);A(this,"already_offset",!1);A(this,"limit",null);A(this,"offset",null);A(this,"_sort",null);A(this,"_sortDesc",!1);A(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}w.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}},w.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},w.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},w.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},E().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),w.prototype.fetchData=async function(){try{if(this._batchData){const l=this._batchData;return this.meta=l.meta,E(l.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,i=e[e.length-1];for(const l of e){if(l===i){s[l]=t;break}s[l]={},s=s[l]}let f=await O(this.axios,r);for(const l of e)f=f[l];return this.meta=f.meta,E(f.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},w.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},w.prototype.all=async function(){return(await this.processData()).all()};for(const t of et)w.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of rt)w.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};w.prototype.average=w.prototype.avg,w.prototype.first=async function(){return this.take(1),(await this.processData()).first()},w.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},w.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],i=t[2];switch(s){case"==":this.filters[r]=i;break;case"<":this.filters[r]={lt:i};break;case"<=":this.filters[r]={lte:i};break;case">":this.filters[r]={gt:i};break;case">=":this.filters[r]={gte:i};break;case"!==":this.filters[r]={ne:i};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},w.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},w.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)},w.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},w.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},w.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},w.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},w.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},w.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},w.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},w.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)},w.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 N=(t,e,r)=>{const s=new w(r,e);return s.data_path=tt+t,s},st=Object.freeze(Object.defineProperty({__proto__:null,default:N},Symbol.toStringTag,{value:"Module"})),nt=(t,e)=>({uploadTempFile:r=>d(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await O(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>d(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>d(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>d(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await O(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 O(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await O(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)=>d(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>d(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>d(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>d(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),it=t=>{const e=typeof window>"u";let r=[];const s=D.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(l=>(l.withCredentials=!0,r.length>0&&(l.headers.Cookie=r.join("; ")),l)),s.interceptors.response.use(l=>{if(l.headers["set-cookie"]){const p=l.headers["set-cookie"].map(o=>o.split(";")[0]),n=new Map;r.forEach(o=>{const a=o.split("=")[0];n.set(a,o)}),p.forEach(o=>{const a=o.split("=")[0];n.set(a,o)}),r=Array.from(n.values())}return l}));const i=(l,p=null,n=[])=>d(s,l,p,n),c=l=>O(s,l),f=P(s);return{baseURL:t,axios:s,auth:Q(s),mutation:i,query:c,config:X(c),mail:Y(s),users:Z(s),fs:V(s),models:f,model(l){return f.get(l)},roles:x(s),collect:(l,p)=>{const n=N(l,s,p);return n.data_path=f.get(l).getDataPath(),n},list:(l,p)=>k(s,l,p).dataPath(f.get(l).getDataPath()),drive(l){return nt(l,s)},async collects(l){const p={},n={};for(const a in l){const u=l[a].getQueryPayload();n[a]=u.data_path,p[a]={};const h=u.data_path.split(".");let g=h[h.length-1],y=p[a];for(const m of h){if(m===g){y[m]=u.query;break}y[m]=y[m]||{}}p[a].__aliasFor=h[0]}const o=await O(s,p);for(const a in l){const u=n[a].split(".");let h=u[u.length-1],g=o[a];for(const y of u){if(y===h){l[a]._batchData=o[a][y];break}g[y]=g[y]||{}}}return l}}};_.File=z,_.createClient=it,_.createCollection=N,_.createList=k,_.createModelManager=P,_.file=v,_.mutation=d,_.query=O,_.toQuery=M,_.useGlobalModel=W,_.useGlobalModels=I,_.useModel=T,_.useWebAuthn=L,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,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):(h=typeof globalThis<"u"?globalThis:h||self,m(h.light={},h.jsonToGraphqlQuery,h.axios,h.collect))})(this,(function(h,m,_t,U){"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=".",n){if(!E(e))return S(t,{},r,n);const o=Object.assign({},e);for(const p in t){if(p==="__proto__"||p==="constructor")continue;const a=t[p];a!=null&&(n&&n(o,p,a,r)||(Array.isArray(a)&&Array.isArray(o[p])?o[p]=[...a,...o[p]]:E(a)&&E(o[p])?o[p]=S(a,o[p],(r?`${r}.`:"")+p.toString(),n):o[p]=a))}return o}function yt(t){return(...e)=>e.reduce((r,n)=>S(r,n,"",t),{})}const A=yt();let j=null;const L=t=>{j=t},v=()=>{if(!j)throw new Error("Api client not initialized. Call setApiClient() first.");return j},wt=()=>j;function C(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function T(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&C(t[e]))return!0;return!1}function $(t,e,r,n,o){if(!(!t||typeof t!="object"))for(let p in t){const a=t[p];if(a&&typeof a=="object"){if("__args"in a){const u=a.__args,s={};Object.entries(u).forEach(([i,c])=>{if(c instanceof Array&&C(c)){s[i]=new m.VariableType(i);let l=0;c.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),n.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else c instanceof File?(s[i]=new m.VariableType(i),r[o.current]=["variables."+i],n.append(o.current.toString(),c),e[i]="Upload!",o.current++):c instanceof Object&&T(c)?(s[i]={},Object.entries(c).forEach(([l,f])=>{if(f instanceof Array&&C(f)){s[i][l]=new m.VariableType(l);let y=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+y),n.append(o.current.toString(),_),o.current++,y++)}),e[l]="[Upload!]!"}else f instanceof File?(s[i][l]=new m.VariableType(l),r[o.current]=["variables."+l],n.append(o.current.toString(),f),e[l]="Upload!",o.current++):s[i][l]=f})):c!=null&&(s[i]=c)}),a.__args=s}$(a,e,r,n,o)}}}const w=async t=>{const e=v(),r=t,n=new FormData;let o=!1;const p={},a={};$(r,p,a,n,{current:0}),o=Object.keys(p).length>0,o&&(r.__variables=p);let s=null;const i={query:r},c=m.jsonToGraphQLQuery(i);if(o?(n.append("map",JSON.stringify(a)),n.append("operations",JSON.stringify({query:c})),s=await e.axios.post("",n)):s=await e.axios.post("",{query:c}),s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function M(t,e){let r,n=[],o,p;const a=s=>!s||typeof s!="object"?!1:Object.values(s).some(i=>i&&typeof i=="object"&&Object.keys(i).some(c=>c.startsWith("_"))),u=()=>n.length===0?(n.unshift({}),n[0]):(a(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(p){const c=p.split(".");for(const l of c)i=i[l];return i}return i[`list${t}`]},async fetch(){let i=await w(this.toQuery());if(p){const c=p.split(".");for(const l of c)i=i[l];return i.data}return i[`list${t}`].data},dataPath(s){return s&&typeof s=="string"&&(p=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,c){const l=(f,y,_)=>{const D={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[y];D&&n.push({[f]:{[D]:_}})};if(c!==void 0)l(s,String(i),c);else{const f=u(),y=A(f,{[s]:i});n[0]=y}return this},whereContains(s,i){if(s&&typeof s=="string"){const c=u(),l={_contains:i};c[s]?Array.isArray(c[s])?c[s].push(l):c[s]=[c[s],l]:c[s]=[l],n[0]=c}return this},whereIn(s,i){if(s&&typeof s=="string"&&Array.isArray(i)){const c=u(),l={_in:i};c[s]?Array.isArray(c[s])?c[s].push(l):c[s]=[c[s],l]:c[s]=[l],n[0]=c}return this},whereBetween(s,i,c){if(s&&typeof s=="string"){const l=u(),f={_between:[i,c]};l[s]?Array.isArray(l[s])?l[s].push(f):l[s]=[l[s],f]:l[s]=f,n[0]=l}return this},limit(s){return typeof s=="number"&&Number.isFinite(s)&&(r=A(r||{},{limit:s})),this},offset(s){return typeof s=="number"&&Number.isFinite(s)&&(r=A(r||{},{offset:s})),this},toQuery(s=!1){let i;const c=n.length>0&&Object.keys(n[0]||{}).length>0,l=c?1:0,f=n.length>l;c&&f?i=n:f?i=n.slice(l):c&&(i=n[0]);const y=A(o?{sort:o}:{},i?{filters:i}:{}),_={data:{...e}};if(r&&(_.data.__args=r),Object.keys(y).length>0&&(_.__args=y),s&&(_.meta={total:!0,key:!0,name:!0}),p){const b=p.split(".");let D=_;for(let J=b.length-1;J>=0;J--)D={[b[J]]:D};return D}return{[`list${t}`]:_}}}}const W=(t,e)=>{const r=t,n=e;let o="list"+t;const p=a=>n[a]?n[a]:null;return{field:p,$fields:n,setDataPath(a){return o=a,o},getDataPath(){return o},gqlFields(a){let u={};for(const s of a)if(typeof s=="string"){const i=p(s);i&&(u=A(u,i.gqlField?typeof i.gqlField=="string"?{[i.gqlField]:!0}:i.gqlField:{[i.name||s]:!0}))}else typeof s=="object"&&(u=A(u,s));return u},update(a,u){return d({["update"+r]:{__args:{id:a,data:u}}}).then(s=>s["update"+r])},async delete(a){return d({["delete"+r]:{__args:{id:a}}}).then(u=>u["delete"+r])},add(a){return d({["add"+r]:{__args:{data:a}}}).then(u=>u["add"+r])},fields(a){let u=[];for(let s of a){const i=p(s);i&&u.push(i)}return u},async get(a,u){const s=(await Promise.resolve().then(()=>St)).default,i=s(r,gt(u));for(const[c,l]of Object.entries(a))i.where(c,"==",l);return await i.first()},list(a){let u=a;const s={};Object.entries(a).forEach(([l])=>{n[l]&&(s[l]=n[l],n[l].gqlField&&(delete u[l],u=A(u,n[l].gqlField)),n[l].gql&&(u=A(u,n[l].gql),delete u[l]))});const i=M(r,u).dataPath(o),c=i.fetch.bind(i);return{...i,async fetch(){return(await c()).map(f=>{const y={...f};return Object.entries(s).forEach(([_,b])=>{b.format&&typeof b.format=="function"&&(y[_]=b.format(f))}),y})},async fetchFirst(){const f=await i.fetchFirst.bind(i)();if(!f)return f;const y={...f};return Object.entries(s).forEach(([_,b])=>{b.format&&typeof b.format=="function"&&(y[_]=b.format(f))}),y}}}}},F={},k=(t=!1)=>{const e={};return{create(r,n){const o=W(r,n);e[r]=o,t&&(F[r]=o)},get(r){return e[r]||(t&&F[r]?e[r]=F[r]:this.create(r,{})),e[r]},has(r){return!!e[r]||t&&!!F[r]},list(){const r=Object.keys(e),n=t?Object.keys(F):[];return[...new Set([...r,...n])]},clear(){Object.keys(e).forEach(r=>delete e[r])}}},bt=()=>{const t=k(!1);return{manager:t,createModel:t.create,getModel:t.get,hasModel:t.has,listModels:t.list,clearModels:t.clear,defineModel(e,r){return t.create(e,r),t.get(e)},defineModels(e){Object.entries(e).forEach(([r,n])=>{t.create(r,n)})}}},mt=()=>{const t=k(!0);return{manager:t,createModel:t.create,getModel:t.get,hasModel:t.has,listModels:t.list,clearModels:t.clear,defineModel(e,r){return t.create(e,r),t.get(e)},defineModels(e){Object.entries(e).forEach(([r,n])=>{t.create(r,n)})}}},Ft=()=>({define(t,e){const r=W(t,e);return F[t]=r,r},get(t){return F[t]},has(t){return!!F[t]},list(){return Object.keys(F)},clear(){Object.keys(F).forEach(t=>delete F[t])}}),At=()=>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})},R=Object.freeze(Object.defineProperty({__proto__:null,assertion:z,attestation:Q,login:async()=>{const t=await z();return await d({webAuthnAssertion:{assertion:t.toJSON()}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await Q();return await d({webAuthnRegister:{registration:t.toJSON()}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),G=(t=q)=>w({my:t}).then(e=>e.my),H=(t,e,r="")=>d({login:{__args:{username:t,password:e,code:r}}}).then(n=>n.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(n=>n.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(n=>n.resetPassword),K=(t,e)=>d({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),I=(t,e)=>d({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),x=t=>w({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),tt=()=>({getCurrentUser:G,webAuthn:R,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:K,verifyCode:I,granted:x}),et={name:!0,path:!0,size:!0,mime:!0,url:!0},rt=(t,e,r=et)=>w({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(n=>n.app.drive.files),O=t=>({list:(e,r=et)=>rt(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),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)}),st={name:!0,path:!0},Ot=(t,e,r=st)=>w({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(n=>n.app.drive.folders),P=t=>({list:(e,r=st)=>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(n=>n.lightDriveRenameFolder)}),Dt=()=>w({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),nt=t=>({listFiles:O(t).list,getFile:O(t).get,readFile:O(t).read,writeFile:O(t).write,deleteFile:O(t).delete,renameFile:O(t).rename,moveFile:O(t).move,listFolders:P(t).list,createFolder:P(t).create,deleteFolder:P(t).delete,renameFolder:P(t).rename,uploadTempFile:e=>d({lightDriveUploadTempFile:{__args:{index:t,file:e},name:!0,path:!0,size:!0,mime:!0}}).then(r=>r.lightDriveUploadTempFile),folders:P(t),files:O(t)}),q={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},it=t=>d({addUser:{__args:t}}).then(e=>e.addUser),ot=t=>d({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),at=(t=q)=>M("Users",t).dataPath("app.listUser").fetch(),ct=(t,e)=>d({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Ct=()=>({list:at,create:it,delete:ot,update:ct}),lt=t=>w({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Pt={name:!0},ut=(t=Pt)=>w({app:{roles:t}}).then(e=>e.app.roles),ht=(t,e)=>d({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),ft=t=>d({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),jt=()=>({list:ut,create:ht,delete:ft});function pt(t,e,r,n,o){if(!(!t||typeof t!="object"))for(let p in t){const a=t[p];if(a&&typeof a=="object"){if("__args"in a){const u=a.__args,s={};Object.entries(u).forEach(([i,c])=>{if(c instanceof Array&&C(c)){s[i]=new m.VariableType(i);let l=0;c.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),n.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else c instanceof File?(s[i]=new m.VariableType(i),r[o.current]=["variables."+i],n.append(o.current.toString(),c),e[i]="Upload!",o.current++):c instanceof Object&&T(c)?(s[i]={},Object.entries(c).forEach(([l,f])=>{if(f instanceof Array&&C(f)){s[i][l]=new m.VariableType(l);let y=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+y),n.append(o.current.toString(),_),o.current++,y++)}),e[l]="[Upload!]!"}else f instanceof File?(s[i][l]=new m.VariableType(l),r[o.current]=["variables."+l],n.append(o.current.toString(),f),e[l]="Upload!",o.current++):s[i][l]=f})):c!=null&&(s[i]=c)}),a.__args=s}pt(a,e,r,n,o)}}}const d=async t=>{const r=v().axios,n=t,o=new FormData;let p=!1;const a={},u={};pt(n,a,u,o,{current:0}),p=Object.keys(a).length>0,p&&(n.__variables=a);let i=null;const c={mutation:n},l=m.jsonToGraphQLQuery(c);if(p?(o.append("map",JSON.stringify(u)),o.append("operations",JSON.stringify({query:l})),i=await r.post("",o)):i=await r.post("",{query:l}),i.data.errors)throw new Error(i.data.errors[0].message);return i.data.data},dt=(t,e,r)=>d({sendMail:{__args:{email:t,subject:e,message:r}}}).then(n=>n.sendMail),Mt={send:dt},N=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(N(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]=N(n)}),e)},gt=t=>N(t),kt="list",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"],Et=["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 g{_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}}g.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}},g.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},g.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},g.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},U().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),g.prototype.fetchData=async function(){try{if(this._batchData){const u=this._batchData;return this.meta=u.meta,U(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 a=await w(r);for(const u of e)a=a[u];return this.meta=a.meta,U(a.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},g.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},g.prototype.all=async function(){return(await this.processData()).all()};for(const t of Ut)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Et)g.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};g.prototype.average=g.prototype.avg,g.prototype.first=async function(){return this.take(1),(await this.processData()).first()},g.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},g.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},g.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},g.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)},g.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},g.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},g.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},g.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},g.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},g.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},g.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},g.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)},g.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 B=(t,e)=>{const r=new g(e);return r.data_path=kt+t,r},St=Object.freeze(Object.defineProperty({__proto__:null,default:B},Symbol.toStringTag,{value:"Module"})),vt=t=>{const e=typeof window>"u";let r=[];const n=_t.create({baseURL:t,withCredentials:!0});e&&(n.interceptors.request.use(a=>(a.withCredentials=!0,r.length>0&&(a.headers.Cookie=r.join("; ")),a)),n.interceptors.response.use(a=>{if(a.headers["set-cookie"]){const u=a.headers["set-cookie"].map(i=>i.split(";")[0]),s=new Map;r.forEach(i=>{const c=i.split("=")[0];s.set(c,i)}),u.forEach(i=>{const c=i.split("=")[0];s.set(c,i)}),r=Array.from(s.values())}return a}));const o=k(),p={post:n.post,baseURL:t,axios:n,auth:tt(),mutation:d,query:w,config:lt,mail:Mt,users:Ct(),models:o,model(a){return o.get(a)},roles:jt(),collect:(a,u)=>{const s=B(a,u);return s.data_path=o.get(a).getDataPath(),s},list:(a,u)=>M(a,u).dataPath(o.get(a).getDataPath()),drive:nt,async collects(a){const u={},s={};for(const c in a){const l=a[c].getQueryPayload();s[c]=l.data_path,u[c]={};const f=l.data_path.split(".");let y=f[f.length-1],_=u[c];for(const b of f){if(b===y){_[b]=l.query;break}_[b]=_[b]||{}}u[c].__aliasFor=f[0]}const i=await w(u);for(const c in a){const l=s[c].split(".");let f=l[l.length-1],y=i[c];for(const _ of l){if(_===f){a[c]._batchData=i[c][_];break}y[_]=y[_]||{}}}return a}};return L(p),p};h.auth=tt,h.changeExpiredPassword=X,h.createClient=vt,h.createCollection=B,h.createList=M,h.createModelManager=k,h.createRole=ht,h.createUser=it,h.defaultUserFields=q,h.deleteRole=ft,h.deleteUser=ot,h.forgetPassword=K,h.getApiClient=v,h.getApiClientOptional=wt,h.getConfig=lt,h.getCurrentUser=G,h.getDrive=nt,h.granted=x,h.listDrives=Dt,h.listFiles=rt,h.listPermissions=At,h.listRoles=ut,h.listUsers=at,h.login=H,h.logout=V,h.mutation=d,h.query=w,h.resetPassword=Z,h.sendMail=dt,h.setApiClient=L,h.toQuery=gt,h.updatePassword=Y,h.updateUser=ct,h.useGlobalModel=mt,h.useGlobalModels=Ft,h.useModel=bt,h.verifyCode=I,h.webAuthn=R,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
package/dist/mail.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { AxiosInstance } from 'axios';
2
- declare const _default: (axios: AxiosInstance) => {
1
+ export declare const sendMail: (email: string, subject: string, message: string) => Promise<any>;
2
+ declare const _default: {
3
3
  send: (email: string, subject: string, message: string) => Promise<any>;
4
4
  };
5
5
  export default _default;
package/dist/model.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { AxiosInstance } from 'axios';
2
1
  import { Fields } from '.';
3
2
  export type Field = {
4
3
  name?: string;
@@ -14,7 +13,7 @@ export type Model = {
14
13
  name: string;
15
14
  fields: Record<string, Field>;
16
15
  };
17
- declare const _default: (axios: AxiosInstance, name: string, fields: Record<string, Field>) => {
16
+ declare const _default: (name: string, fields: Record<string, Field>) => {
18
17
  field: (f: string) => Field | null;
19
18
  $fields: Record<string, Field>;
20
19
  setDataPath(path: string): string;
@@ -1,4 +1,3 @@
1
- import { AxiosInstance } from 'axios';
2
1
  import { Field } from './model';
3
2
  export interface ModelManager {
4
3
  create: (name: string, fields: Record<string, Field>) => void;
@@ -12,13 +11,13 @@ export interface ModelManager {
12
11
  * @param axios AxiosInstance 實例
13
12
  * @returns ModelManager 實例
14
13
  */
15
- export declare const createModelManager: (axios: AxiosInstance, useGlobal?: boolean) => ModelManager;
14
+ export declare const createModelManager: (useGlobal?: boolean) => ModelManager;
16
15
  /**
17
16
  * 主要的 useModel hook
18
17
  * @param axios AxiosInstance 實例
19
18
  * @returns 模型管理器和便利方法
20
19
  */
21
- export declare const useModel: (axios: AxiosInstance) => {
20
+ export declare const useModel: () => {
22
21
  manager: ModelManager;
23
22
  createModel: (name: string, fields: Record<string, Field>) => void;
24
23
  getModel: (name: string) => any;
@@ -43,7 +42,7 @@ export declare const useModel: (axios: AxiosInstance) => {
43
42
  * @param axios AxiosInstance 實例
44
43
  * @returns 使用全域模型的管理器
45
44
  */
46
- export declare const useGlobalModel: (axios: AxiosInstance) => {
45
+ export declare const useGlobalModel: () => {
47
46
  manager: ModelManager;
48
47
  createModel: (name: string, fields: Record<string, Field>) => void;
49
48
  getModel: (name: string) => any;
@@ -67,7 +66,7 @@ export declare const useGlobalModel: (axios: AxiosInstance) => {
67
66
  * 全域模型管理器 - 用於跨組件共享模型
68
67
  * 所有創建的模型都會儲存在全域範圍內,可以在不同的組件或模組中共享
69
68
  */
70
- export declare const useGlobalModels: (axios: AxiosInstance) => {
69
+ export declare const useGlobalModels: () => {
71
70
  /**
72
71
  * 創建全域模型
73
72
  * @param name 模型名稱
@@ -1,6 +1,2 @@
1
- import { AxiosInstance } from 'axios';
2
- import { Fields } from '.';
3
- declare const _default: (axios: AxiosInstance, operation: string, args?: {
4
- [key: string]: any;
5
- } | null, fields?: Fields) => Promise<any>;
1
+ declare const _default: (q: Record<string, any>) => Promise<any>;
6
2
  export default _default;
@@ -0,0 +1,5 @@
1
+ export declare const listPermissions: () => Promise<Array<string>>;
2
+ declare const _default: () => {
3
+ list: () => Promise<Array<string>>;
4
+ };
5
+ export default _default;
package/dist/query.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- import { AxiosInstance } from 'axios';
2
- declare const _default: (axios: AxiosInstance, q: Object | Array<string | Object>) => Promise<any>;
1
+ declare const _default: (q: Record<string, any>) => Promise<any>;
3
2
  export default _default;
package/dist/role.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { UserFields } from './users';
2
+ export type RoleFields = {
3
+ name?: string;
4
+ canDelete?: boolean;
5
+ canUpdate?: boolean;
6
+ children?: boolean;
7
+ user?: UserFields;
8
+ };
9
+ export type QueryRoleFields = Partial<Record<keyof RoleFields, boolean>>;
10
+ export declare const listRoles: (fields?: QueryRoleFields) => Promise<Array<RoleFields>>;
11
+ export declare const createRole: (name: string, childs: string[]) => Promise<boolean>;
12
+ export declare const deleteRole: (name: string) => Promise<boolean>;
13
+ declare const _default: () => {
14
+ list: (fields?: QueryRoleFields) => Promise<Array<RoleFields>>;
15
+ create: (name: string, childs: string[]) => Promise<boolean>;
16
+ delete: (name: string) => Promise<boolean>;
17
+ };
18
+ export default _default;
package/dist/toQuery.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { Fields } from '.';
2
- declare const _default: (query: Fields) => any;
2
+ declare const _default: (query: Fields) => Record<string, any>;
3
3
  export default _default;
@@ -0,0 +1 @@
1
+ export {};
package/dist/users.d.ts CHANGED
@@ -1,28 +1,29 @@
1
- import { AxiosInstance } from 'axios';
2
1
  export type UserFields = {
3
- user_id?: boolean;
4
- username?: boolean;
5
- first_name?: boolean;
6
- last_name?: boolean;
7
- status?: boolean;
2
+ user_id?: number;
3
+ username?: string;
4
+ first_name?: string;
5
+ last_name?: string;
6
+ status?: number;
7
+ password?: string;
8
+ join_date?: string;
8
9
  };
9
- declare const _default: (axios: AxiosInstance) => {
10
- list: (fields?: UserFields) => {
11
- first(): Promise<any>;
12
- all(): Promise<any[]>;
13
- fetchFirst(): Promise<any>;
14
- fetchWithMeta(): Promise<any>;
15
- fetch(): Promise<any[]>;
16
- dataPath(dataPath?: string): /*elided*/ any;
17
- sort(sortStr: string): /*elided*/ any;
18
- filters(filterObj: Record<string, any>): /*elided*/ any;
19
- where(key: string, opOrVal?: any, maybeVal?: any): /*elided*/ any;
20
- whereContains(field: string, val: any): /*elided*/ any;
21
- whereIn(field: string, vals: any[]): /*elided*/ any;
22
- whereBetween(field: string, min: any, max: any): /*elided*/ any;
23
- limit(n: number): /*elided*/ any;
24
- offset(n: number): /*elided*/ any;
25
- toQuery(includeMeta?: boolean): any;
26
- };
10
+ export type QueryUserFieldsUserFields = Partial<Record<keyof UserFields, boolean>>;
11
+ export declare const defaultUserFields: QueryUserFieldsUserFields;
12
+ export type CreateUserFields = {
13
+ username: string;
14
+ first_name: string;
15
+ last_name?: string;
16
+ password: string;
17
+ join_date: string;
18
+ };
19
+ export declare const createUser: (fields: CreateUserFields) => Promise<any>;
20
+ export declare const deleteUser: (id: Number) => Promise<boolean>;
21
+ export declare const listUsers: (fields?: QueryUserFieldsUserFields) => Promise<any[]>;
22
+ export declare const updateUser: (id: number, fields: Partial<CreateUserFields>) => Promise<any>;
23
+ declare const _default: () => {
24
+ list: (fields?: QueryUserFieldsUserFields) => Promise<any[]>;
25
+ create: (fields: CreateUserFields) => Promise<any>;
26
+ delete: (id: Number) => Promise<boolean>;
27
+ update: (id: number, fields: Partial<CreateUserFields>) => Promise<any>;
27
28
  };
28
29
  export default _default;
@@ -1,6 +1,4 @@
1
- import { AxiosInstance } from 'axios';
2
- declare const _default: (axios: AxiosInstance) => {
3
- login: () => Promise<void>;
4
- register: () => Promise<void>;
5
- };
6
- export default _default;
1
+ export declare const assertion: () => Promise<PublicKeyCredential>;
2
+ export declare const attestation: () => Promise<PublicKeyCredential>;
3
+ export declare const login: () => Promise<any>;
4
+ export declare const register: () => Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "2.13.2",
3
+ "version": "3.0.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -24,9 +24,9 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "^5.8.3",
27
- "vite": "^5.4.19",
27
+ "vite": "^7.2.1",
28
28
  "vite-plugin-dts": "^4.5.4",
29
- "vitest": "^2.1.9"
29
+ "vitest": "^4.0.7"
30
30
  },
31
31
  "dependencies": {
32
32
  "axios": "^1.11.0",
package/dist/fs.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- export type FSFile = {
3
- name: string;
4
- path: string;
5
- size: number;
6
- mime: string;
7
- canPreview: boolean;
8
- imagePath: string;
9
- };
10
- export type FSFolder = {
11
- name: String;
12
- path: String;
13
- };
14
- declare const _default: (axios: AxiosInstance) => {
15
- uploadTempFile: (file: File) => Promise<any>;
16
- folders: {
17
- list: (path: string) => Promise<any>;
18
- create: (path: string) => Promise<any>;
19
- delete: (path: string) => Promise<any>;
20
- rename: (path: string, name: string) => Promise<any>;
21
- };
22
- files: {
23
- list: (path: string) => Promise<FSFile[]>;
24
- read: (path: string) => Promise<string>;
25
- write: (path: string, content: string) => Promise<any>;
26
- delete: (path: string) => Promise<any>;
27
- rename: (path: string, name: string) => Promise<any>;
28
- move: (source: string, target: string) => Promise<any>;
29
- };
30
- };
31
- export default _default;
package/dist/roles.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import { UserFields } from './users';
3
- export type RoleFields = {
4
- name?: boolean;
5
- canDelete?: boolean;
6
- canUpdate?: boolean;
7
- children?: boolean;
8
- user?: UserFields;
9
- };
10
- declare const _default: (axios: AxiosInstance) => {
11
- list: (fields?: RoleFields) => Promise<any>;
12
- };
13
- export default _default;
@@ -1,6 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- declare const _default: (axios: AxiosInstance) => {
3
- assertion: () => Promise<PublicKeyCredential>;
4
- attestation: () => Promise<PublicKeyCredential>;
5
- };
6
- export default _default;
File without changes
File without changes