@hostlink/light 2.10.0 → 2.11.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.
package/dist/light.js CHANGED
@@ -115,52 +115,52 @@ const U = (t) => ({
115
115
  }), Q = (t, e, r) => {
116
116
  const s = e, i = t, h = r;
117
117
  let f = "list" + e;
118
- const o = (c) => h[c] ? h[c]() : null;
118
+ const o = (u) => h[u] ? h[u]() : null;
119
119
  return {
120
120
  field: o,
121
121
  $fields: h,
122
- setDataPath(c) {
123
- return f = c, f;
122
+ setDataPath(u) {
123
+ return f = u, f;
124
124
  },
125
125
  getDataPath() {
126
126
  return f;
127
127
  },
128
- gqlFields(c) {
128
+ gqlFields(u) {
129
129
  const n = [];
130
- for (const a of c)
130
+ for (const a of u)
131
131
  if (typeof a == "string") {
132
132
  const l = o(a);
133
133
  l && n.push(l.getGQLField());
134
134
  } else typeof a == "object" && n.push(a);
135
135
  return n;
136
136
  },
137
- async update(c, n) {
138
- return await p(i, "update" + s, { id: c, data: n });
137
+ async update(u, n) {
138
+ return await p(i, "update" + s, { id: u, data: n });
139
139
  },
140
- async delete(c) {
141
- return await p(i, "delete" + s, { id: c });
140
+ async delete(u) {
141
+ return await p(i, "delete" + s, { id: u });
142
142
  },
143
- async add(c) {
144
- return await p(i, "add" + s, { data: c });
143
+ async add(u) {
144
+ return await p(i, "add" + s, { data: u });
145
145
  },
146
- fields(c) {
146
+ fields(u) {
147
147
  let n = [];
148
- for (let a of c) {
148
+ for (let a of u) {
149
149
  const l = o(a);
150
150
  l && n.push(l);
151
151
  }
152
152
  return n;
153
153
  },
154
- async get(c, n) {
154
+ async get(u, n) {
155
155
  const a = (await Promise.resolve().then(() => B)).default, l = a(s, i, O(n));
156
- for (const [u, d] of Object.entries(c))
157
- l.where(u, "==", d);
156
+ for (const [c, d] of Object.entries(u))
157
+ l.where(c, "==", d);
158
158
  return await l.first();
159
159
  },
160
- async list(c, n) {
160
+ async list(u, n) {
161
161
  const a = (await Promise.resolve().then(() => B)).default, l = a(s, i, O(n));
162
- for (const [u, d] of Object.entries(c))
163
- l.where(u, "==", d);
162
+ for (const [c, d] of Object.entries(u))
163
+ l.where(c, "==", d);
164
164
  return await l.all();
165
165
  }
166
166
  };
@@ -169,8 +169,8 @@ function T(t) {
169
169
  t = "<~" + t + "~>";
170
170
  var e, r, s, i, h, f = String, o = 255;
171
171
  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, h = t.length; h > 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(o & r >> 24, o & r >> 16, o & r >> 8, o & r);
172
- return function(c, n) {
173
- for (var a = n; a > 0; a--) c.pop();
172
+ return function(u, n) {
173
+ for (var a = n; a > 0; a--) u.pop();
174
174
  }(s, e.length), f.fromCharCode.apply(f, s);
175
175
  }
176
176
  const D = (t = "") => {
@@ -242,16 +242,16 @@ const p = async (t, e, r = null, s = []) => {
242
242
  let f = !1;
243
243
  if (r) {
244
244
  const n = {}, a = {}, l = {};
245
- let u = 0;
245
+ let c = 0;
246
246
  Object.entries(r).forEach(([d, _]) => {
247
247
  if (_ instanceof Array && W(_)) {
248
248
  f = !0;
249
249
  let y = 0;
250
250
  _.forEach((w) => {
251
- w instanceof File && (n[d] = new k(d), a[u] = ["variables." + d + "." + y], h.append(u.toString(), w), u++);
251
+ w instanceof File && (n[d] = new k(d), a[c] = ["variables." + d + "." + y], h.append(c.toString(), w), c++);
252
252
  }), l[d] = "[Upload!]!";
253
- } else _ instanceof File ? (f = !0, n[d] = new k(d), a[u] = ["variables." + d], h.append(u.toString(), _), l[d] = "Upload!", u++) : _ instanceof Object && $(_) ? (f = !0, n[d] = {}, Object.entries(_).forEach(([y, w]) => {
254
- w instanceof File ? (n[d][y] = new k(y), a[u] = ["variables." + y], h.append(u.toString(), w), l[y] = "Upload!", u++) : n[d][y] = w;
253
+ } else _ instanceof File ? (f = !0, n[d] = new k(d), a[c] = ["variables." + d], h.append(c.toString(), _), l[d] = "Upload!", c++) : _ instanceof Object && $(_) ? (f = !0, n[d] = {}, Object.entries(_).forEach(([y, w]) => {
254
+ w instanceof File ? (n[d][y] = new k(y), a[c] = ["variables." + y], h.append(c.toString(), w), l[y] = "Upload!", c++) : n[d][y] = w;
255
255
  })) : _ !== void 0 && (n[d] = _);
256
256
  }), i[e].__args = n, i.__variables = l, f && h.append("map", JSON.stringify(a));
257
257
  }
@@ -259,11 +259,11 @@ const p = async (t, e, r = null, s = []) => {
259
259
  i[e][n] = a;
260
260
  }), Object.entries(i[e]).length === 0 && (i[e] = !0);
261
261
  let o = null;
262
- const c = E({ mutation: i });
262
+ const u = E({ mutation: i });
263
263
  if (f ? (h.append("operations", JSON.stringify({
264
- query: c
264
+ query: u
265
265
  })), o = await t.post("", h)) : o = await t.post("", {
266
- query: c
266
+ query: u
267
267
  }), o.data.errors)
268
268
  throw new Error(o.data.errors[0].message);
269
269
  return o.data.data[e];
@@ -366,21 +366,21 @@ const p = async (t, e, r = null, s = []) => {
366
366
  r[s] = null;
367
367
  let h = {};
368
368
  for (const f of Object.entries(i)) {
369
- const [o, c] = f;
369
+ const [o, u] = f;
370
370
  h[o] = () => ({
371
- name: c.name ? c.name : o,
372
- raw: c,
373
- getName: () => c.name ? c.name : o,
374
- getGQLField: () => c.gqlField !== void 0 ? c.gqlField : c.name || o,
371
+ name: u.name ? u.name : o,
372
+ raw: u,
373
+ getName: () => u.name ? u.name : o,
374
+ getGQLField: () => u.gqlField !== void 0 ? u.gqlField : u.name || o,
375
375
  getRaw() {
376
- return c;
376
+ return u;
377
377
  },
378
378
  getValue(n) {
379
- return c.field && typeof c.field == "function" ? c.field(n) : c.field && typeof c.field == "string" ? n[c.field] : n[this.getName()];
379
+ return u.field && typeof u.field == "function" ? u.field(n) : u.field && typeof u.field == "string" ? n[u.field] : n[this.getName()];
380
380
  },
381
381
  getFormattedValue(n) {
382
382
  const a = this.getValue(n);
383
- return c.format ? c.format(a) : a;
383
+ return u.format ? u.format(a) : a;
384
384
  }
385
385
  });
386
386
  }
@@ -772,14 +772,15 @@ function tt(t) {
772
772
  const C = tt();
773
773
  function et(t, e, r) {
774
774
  let s, i = [], h, f;
775
- const o = (n) => !n || typeof n != "object" ? !1 : Object.values(n).some((a) => a && typeof a == "object" && Object.keys(a).some((l) => l.startsWith("_"))), c = () => i.length === 0 ? (i.unshift({}), i[0]) : (o(i[0]) && i.unshift({}), i[0]);
775
+ const o = (n) => !n || typeof n != "object" ? !1 : Object.values(n).some((a) => a && typeof a == "object" && Object.keys(a).some((l) => l.startsWith("_"))), u = () => i.length === 0 ? (i.unshift({}), i[0]) : (o(i[0]) && i.unshift({}), i[0]);
776
776
  return {
777
777
  async fetchWithMeta() {
778
778
  let a = await m(t, this.toQuery(!0));
779
779
  if (f) {
780
780
  const l = f.split(".");
781
- for (const u of l)
782
- a = a[u];
781
+ for (const c of l)
782
+ a = a[c];
783
+ return a;
783
784
  }
784
785
  return a[`list${e}`];
785
786
  },
@@ -787,8 +788,9 @@ function et(t, e, r) {
787
788
  let a = await m(t, this.toQuery());
788
789
  if (f) {
789
790
  const l = f.split(".");
790
- for (const u of l)
791
- a = a[u];
791
+ for (const c of l)
792
+ a = a[c];
793
+ return a.data;
792
794
  }
793
795
  return a[`list${e}`].data;
794
796
  },
@@ -805,7 +807,7 @@ function et(t, e, r) {
805
807
  // where('key', value) -> exact match
806
808
  // where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
807
809
  where(n, a, l) {
808
- const u = (d, _, y) => {
810
+ const c = (d, _, y) => {
809
811
  const A = {
810
812
  ">": "_gt",
811
813
  "<": "_lt",
@@ -818,9 +820,9 @@ function et(t, e, r) {
818
820
  A && i.push({ [d]: { [A]: y } });
819
821
  };
820
822
  if (l !== void 0)
821
- u(n, String(a), l);
823
+ c(n, String(a), l);
822
824
  else {
823
- const d = c(), _ = C(d, { [n]: a });
825
+ const d = u(), _ = C(d, { [n]: a });
824
826
  i[0] = _;
825
827
  }
826
828
  return this;
@@ -829,8 +831,8 @@ function et(t, e, r) {
829
831
  // If the same field is used multiple times, it merges them into an array
830
832
  whereContains(n, a) {
831
833
  if (n && typeof n == "string") {
832
- const l = c(), u = { _contains: a };
833
- l[n] ? Array.isArray(l[n]) ? l[n].push(u) : l[n] = [l[n], u] : l[n] = [u], i[0] = l;
834
+ const l = u(), c = { _contains: a };
835
+ l[n] ? Array.isArray(l[n]) ? l[n].push(c) : l[n] = [l[n], c] : l[n] = [c], i[0] = l;
834
836
  }
835
837
  return this;
836
838
  },
@@ -839,16 +841,16 @@ function et(t, e, r) {
839
841
  // If the same field is used multiple times, it merges them into an array
840
842
  whereIn(n, a) {
841
843
  if (n && typeof n == "string" && Array.isArray(a)) {
842
- const l = c(), u = { _in: a };
843
- l[n] ? Array.isArray(l[n]) ? l[n].push(u) : l[n] = [l[n], u] : l[n] = [u], i[0] = l;
844
+ const l = u(), c = { _in: a };
845
+ l[n] ? Array.isArray(l[n]) ? l[n].push(c) : l[n] = [l[n], c] : l[n] = [c], i[0] = l;
844
846
  }
845
847
  return this;
846
848
  },
847
849
  // whereBetween adds a _between filter for a specific field
848
850
  whereBetween(n, a, l) {
849
851
  if (n && typeof n == "string") {
850
- const u = c(), d = { _between: [a, l] };
851
- u[n] ? Array.isArray(u[n]) ? u[n].push(d) : u[n] = [u[n], d] : u[n] = d, i[0] = u;
852
+ const c = u(), d = { _between: [a, l] };
853
+ c[n] ? Array.isArray(c[n]) ? c[n].push(d) : c[n] = [c[n], d] : c[n] = d, i[0] = c;
852
854
  }
853
855
  return this;
854
856
  },
@@ -862,8 +864,8 @@ function et(t, e, r) {
862
864
  },
863
865
  toQuery(n = !1) {
864
866
  let a;
865
- const l = i.length > 0 && Object.keys(i[0] || {}).length > 0, u = l ? 1 : 0, d = i.length > u;
866
- l && d ? a = i : d ? a = i.slice(u) : l && (a = i[0]);
867
+ const l = i.length > 0 && Object.keys(i[0] || {}).length > 0, c = l ? 1 : 0, d = i.length > c;
868
+ l && d ? a = i : d ? a = i.slice(c) : l && (a = i[0]);
867
869
  const _ = C(
868
870
  h ? { sort: h } : {},
869
871
  a ? { filters: a } : {}
@@ -900,18 +902,18 @@ const at = (t) => {
900
902
  });
901
903
  e && (s.interceptors.request.use((o) => (o.withCredentials = !0, r.length > 0 && (o.headers.Cookie = r.join("; ")), o)), s.interceptors.response.use((o) => {
902
904
  if (o.headers["set-cookie"]) {
903
- const c = o.headers["set-cookie"].map((a) => a.split(";")[0]), n = /* @__PURE__ */ new Map();
905
+ const u = o.headers["set-cookie"].map((a) => a.split(";")[0]), n = /* @__PURE__ */ new Map();
904
906
  r.forEach((a) => {
905
907
  const l = a.split("=")[0];
906
908
  n.set(l, a);
907
- }), c.forEach((a) => {
909
+ }), u.forEach((a) => {
908
910
  const l = a.split("=")[0];
909
911
  n.set(l, a);
910
912
  }), r = Array.from(n.values());
911
913
  }
912
914
  return o;
913
915
  }));
914
- const i = (o, c = null, n = []) => p(s, o, c, n), h = (o) => m(s, o), f = V(s);
916
+ const i = (o, u = null, n = []) => p(s, o, u, n), h = (o) => m(s, o), f = V(s);
915
917
  return {
916
918
  baseURL: t,
917
919
  axios: s,
@@ -927,35 +929,35 @@ const at = (t) => {
927
929
  return f.get(o);
928
930
  },
929
931
  roles: H(s),
930
- collect: (o, c) => {
931
- const n = N(o, s, c);
932
+ collect: (o, u) => {
933
+ const n = N(o, s, u);
932
934
  return n.data_path = f.get(o).getDataPath(), n;
933
935
  },
934
- list: (o, c) => et(s, o, c).dataPath(f.get(o).getDataPath()),
936
+ list: (o, u) => et(s, o, u).dataPath(f.get(o).getDataPath()),
935
937
  drive(o) {
936
938
  return x(o, s);
937
939
  },
938
940
  async collects(o) {
939
- const c = {}, n = {};
941
+ const u = {}, n = {};
940
942
  for (const l in o) {
941
- const u = o[l].getQueryPayload();
942
- n[l] = u.data_path, c[l] = {};
943
- const d = u.data_path.split(".");
944
- let _ = d[d.length - 1], y = c[l];
943
+ const c = o[l].getQueryPayload();
944
+ n[l] = c.data_path, u[l] = {};
945
+ const d = c.data_path.split(".");
946
+ let _ = d[d.length - 1], y = u[l];
945
947
  for (const w of d) {
946
948
  if (w === _) {
947
- y[w] = u.query;
949
+ y[w] = c.query;
948
950
  break;
949
951
  }
950
952
  y[w] = y[w] || {};
951
953
  }
952
- c[l].__aliasFor = d[0];
954
+ u[l].__aliasFor = d[0];
953
955
  }
954
- const a = await m(s, c);
956
+ const a = await m(s, u);
955
957
  for (const l in o) {
956
- const u = n[l].split(".");
957
- let d = u[u.length - 1], _ = a[l];
958
- for (const y of u) {
958
+ const c = n[l].split(".");
959
+ let d = c[c.length - 1], _ = a[l];
960
+ for (const y of c) {
959
961
  if (y === d) {
960
962
  o[l]._batchData = a[l][y];
961
963
  break;
@@ -1 +1 @@
1
- (function(_,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):(_=typeof globalThis<"u"?globalThis:_||self,m(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,m,O,P){"use strict";var rt=Object.defineProperty;var st=(_,m,O)=>m in _?rt(_,m,{enumerable:!0,configurable:!0,writable:!0,value:O}):_[m]=O;var C=(_,m,O)=>st(_,typeof m!="symbol"?m+"":m,O);const q=t=>({assertion:async()=>{const{app:s}=await b(t,{app:{auth:{webAuthnRequestOptions:!0}}}),i=s.auth.webAuthnRequestOptions,h=PublicKeyCredential.parseRequestOptionsFromJSON(i);return await navigator.credentials.get({publicKey:h})},attestation:async()=>{const{app:s}=await b(t,{app:{auth:{webAuthnCreationOptions:!0}}}),i=PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:i})}}),L=t=>{const{assertion:e,attestation:r}=q(t);return{login:async()=>{const s=await e();await p(t,"webAuthnAssertion",{assertion:s.toJSON()})},register:async()=>{const s=await r();await p(t,"webAuthnRegister",{registration:s.toJSON()})}}},U=t=>({WebAuthn:L(t),google:{unlink:()=>p(t,"lightAuthUnlinkGoogle"),login:e=>p(t,"lightAuthLoginGoogle",{credential:e}),register:e=>p(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>p(t,"lightAuthUnlinkFacebook"),login:e=>p(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>p(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>p(t,"lightAuthUnlinkMicrosoft"),login:e=>p(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>p(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>p(t,"login",{username:e,password:r,code:s}),logout:()=>p(t,"logout"),changeExpiredPassword:(e,r,s)=>p(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>p(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>p(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>p(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return p(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await b(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}}),J=(t,e,r)=>{const s=e,i=t,h=r;let f="list"+e;const o=u=>h[u]?h[u]():null;return{field:o,$fields:h,setDataPath(u){return f=u,f},getDataPath(){return f},gqlFields(u){const n=[];for(const a of u)if(typeof a=="string"){const l=o(a);l&&n.push(l.getGQLField())}else typeof a=="object"&&n.push(a);return n},async update(u,n){return await p(i,"update"+s,{id:u,data:n})},async delete(u){return await p(i,"delete"+s,{id:u})},async add(u){return await p(i,"add"+s,{data:u})},fields(u){let n=[];for(let a of u){const l=o(a);l&&n.push(l)}return n},async get(u,n){const a=(await Promise.resolve().then(()=>R)).default,l=a(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.first()},async list(u,n){const a=(await Promise.resolve().then(()=>R)).default,l=a(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.all()}}};function M(t){t="<~"+t+"~>";var e,r,s,i,h,f=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=[],i=0,h=t.length;h>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(o&r>>24,o&r>>16,o&r>>8,o&r);return function(u,n){for(var a=n;a>0;a--)u.pop()}(s,e.length),f.fromCharCode.apply(f,s)}const D=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let o=0;o<e.length;o++)i[o]=e.charCodeAt(o);const h=new Blob([i],{type:s});return URL.createObjectURL(h)};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")}}},T={fromBase85:t=>D(M(t)),fromBase64:t=>D(atob(t)),fromString:t=>D(t)},S=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(S(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]=S(s)}),e)},k=t=>S(t),b=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 W(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function Q(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const p=async(t,e,r=null,s=[])=>{let i={[e]:{}};const h=new FormData;let f=!1;if(r){const n={},a={},l={};let c=0;Object.entries(r).forEach(([d,w])=>{if(w instanceof Array&&W(w)){f=!0;let y=0;w.forEach(A=>{A instanceof File&&(n[d]=new m.VariableType(d),a[c]=["variables."+d+"."+y],h.append(c.toString(),A),c++)}),l[d]="[Upload!]!"}else w instanceof File?(f=!0,n[d]=new m.VariableType(d),a[c]=["variables."+d],h.append(c.toString(),w),l[d]="Upload!",c++):w instanceof Object&&Q(w)?(f=!0,n[d]={},Object.entries(w).forEach(([y,A])=>{A instanceof File?(n[d][y]=new m.VariableType(y),a[c]=["variables."+y],h.append(c.toString(),A),l[y]="Upload!",c++):n[d][y]=A})):w!==void 0&&(n[d]=w)}),i[e].__args=n,i.__variables=l,f&&h.append("map",JSON.stringify(a))}Object.entries(k(s)).forEach(([n,a])=>{i[e][n]=a}),Object.entries(i[e]).length===0&&(i[e]=!0);let o=null;const u=m.jsonToGraphQLQuery({mutation:i});if(f?(h.append("operations",JSON.stringify({query:u})),o=await t.post("",h)):o=await t.post("",{query:u}),o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data[e]},$=t=>({uploadTempFile:e=>p(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await b(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>p(t,"fsCreateFolder",{path:e}),delete:e=>p(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>p(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await b(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 b(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>p(t,"fsWriteFile",{path:e,content:r}),delete:e=>p(t,"fsDeleteFile",{path:e}),rename:(e,r)=>p(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>p(t,"fsMoveFile",{source:e,target:r})}}),z=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),I=t=>({send:(e,r,s)=>p(t,"sendMail",{email:e,subject:r,message:s})}),K=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()}}),G=t=>{const e=t,r={};return{create(s,i){r[s]=null;let h={};for(const f of Object.entries(i)){const[o,u]=f;h[o]=()=>({name:u.name?u.name:o,raw:u,getName:()=>u.name?u.name:o,getGQLField:()=>u.gqlField!==void 0?u.gqlField:u.name||o,getRaw(){return u},getValue(n){return u.field&&typeof u.field=="function"?u.field(n):u.field&&typeof u.field=="string"?n[u.field]:n[this.getName()]},getFormattedValue(n){const a=this.getValue(n);return u.format?u.format(a):a}})}r[s]=J(e,s,h)},get(s){return r[s]||this.create(s,{}),r[s]}}},V=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await b(t,{app:{roles:e}});return r}}),H="list",X=["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"],Y=["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{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}}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},P().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 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,i=e[e.length-1];for(const o of e){if(o===i){s[o]=t;break}s[o]={},s=s[o]}let f=await b(this.axios,r);for(const o of e)f=f[o];return this.meta=f.meta,P(f.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 X)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Y)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],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},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 j=(t,e,r)=>{const s=new g(r,e);return s.data_path=H+t,s},R=Object.freeze(Object.defineProperty({__proto__:null,default:j},Symbol.toStringTag,{value:"Module"})),Z=(t,e)=>({uploadTempFile:r=>p(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await b(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>p(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>p(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await b(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 b(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await b(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)=>p(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>p(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>p(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}});function N(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 B(t,e,r=".",s){if(!N(e))return B(t,{},r,s);const i=Object.assign({},e);for(const h in t){if(h==="__proto__"||h==="constructor")continue;const f=t[h];f!=null&&(s&&s(i,h,f,r)||(Array.isArray(f)&&Array.isArray(i[h])?i[h]=[...f,...i[h]]:N(f)&&N(i[h])?i[h]=B(f,i[h],(r?`${r}.`:"")+h.toString(),s):i[h]=f))}return i}function x(t){return(...e)=>e.reduce((r,s)=>B(r,s,"",t),{})}const v=x();function tt(t,e,r){let s,i=[],h,f;const o=n=>!n||typeof n!="object"?!1:Object.values(n).some(a=>a&&typeof a=="object"&&Object.keys(a).some(l=>l.startsWith("_"))),u=()=>i.length===0?(i.unshift({}),i[0]):(o(i[0])&&i.unshift({}),i[0]);return{async fetchWithMeta(){let a=await b(t,this.toQuery(!0));if(f){const l=f.split(".");for(const c of l)a=a[c]}return a[`list${e}`]},async fetch(){let a=await b(t,this.toQuery());if(f){const l=f.split(".");for(const c of l)a=a[c]}return a[`list${e}`].data},dataPath(n){return n&&typeof n=="string"&&(f=n),this},sort(n){return n&&typeof n=="string"&&(h=n),this},filters(n){return n&&typeof n=="object"&&(i=[n]),this},where(n,a,l){const c=(d,w,y)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[w];F&&i.push({[d]:{[F]:y}})};if(l!==void 0)c(n,String(a),l);else{const d=u(),w=v(d,{[n]:a});i[0]=w}return this},whereContains(n,a){if(n&&typeof n=="string"){const l=u(),c={_contains:a};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereIn(n,a){if(n&&typeof n=="string"&&Array.isArray(a)){const l=u(),c={_in:a};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereBetween(n,a,l){if(n&&typeof n=="string"){const c=u(),d={_between:[a,l]};c[n]?Array.isArray(c[n])?c[n].push(d):c[n]=[c[n],d]:c[n]=d,i[0]=c}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{offset:n})),this},toQuery(n=!1){let a;const l=i.length>0&&Object.keys(i[0]||{}).length>0,c=l?1:0,d=i.length>c;l&&d?a=i:d?a=i.slice(c):l&&(a=i[0]);const w=v(h?{sort:h}:{},a?{filters:a}:{}),y={data:{...r}};if(s&&(y.data.__args=s),Object.keys(w).length>0&&(y.__args=w),n&&(y.meta={total:!0,key:!0,name:!0}),f){const A=f.split(".");let F=y;for(let E=A.length-1;E>=0;E--)F={[A[E]]:F};return F}return{[`list${e}`]:y}}}}const et=t=>{const e=typeof window>"u";let r=[];const s=O.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(o=>(o.withCredentials=!0,r.length>0&&(o.headers.Cookie=r.join("; ")),o)),s.interceptors.response.use(o=>{if(o.headers["set-cookie"]){const u=o.headers["set-cookie"].map(a=>a.split(";")[0]),n=new Map;r.forEach(a=>{const l=a.split("=")[0];n.set(l,a)}),u.forEach(a=>{const l=a.split("=")[0];n.set(l,a)}),r=Array.from(n.values())}return o}));const i=(o,u=null,n=[])=>p(s,o,u,n),h=o=>b(s,o),f=G(s);return{baseURL:t,axios:s,auth:U(s),mutation:i,query:h,config:z(h),mail:I(s),users:K(s),fs:$(s),models:f,model(o){return f.get(o)},roles:V(s),collect:(o,u)=>{const n=j(o,s,u);return n.data_path=f.get(o).getDataPath(),n},list:(o,u)=>tt(s,o,u).dataPath(f.get(o).getDataPath()),drive(o){return Z(o,s)},async collects(o){const u={},n={};for(const l in o){const c=o[l].getQueryPayload();n[l]=c.data_path,u[l]={};const d=c.data_path.split(".");let w=d[d.length-1],y=u[l];for(const A of d){if(A===w){y[A]=c.query;break}y[A]=y[A]||{}}u[l].__aliasFor=d[0]}const a=await b(s,u);for(const l in o){const c=n[l].split(".");let d=c[c.length-1],w=a[l];for(const y of c){if(y===d){o[l]._batchData=a[l][y];break}w[y]=w[y]||{}}}return o}}};_.File=T,_.createClient=et,_.createCollection=j,_.file=D,_.mutation=p,_.query=b,_.toQuery=k,_.useWebAuthn=q,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
1
+ (function(_,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):(_=typeof globalThis<"u"?globalThis:_||self,m(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,m,O,P){"use strict";var rt=Object.defineProperty;var st=(_,m,O)=>m in _?rt(_,m,{enumerable:!0,configurable:!0,writable:!0,value:O}):_[m]=O;var C=(_,m,O)=>st(_,typeof m!="symbol"?m+"":m,O);const q=t=>({assertion:async()=>{const{app:s}=await b(t,{app:{auth:{webAuthnRequestOptions:!0}}}),i=s.auth.webAuthnRequestOptions,h=PublicKeyCredential.parseRequestOptionsFromJSON(i);return await navigator.credentials.get({publicKey:h})},attestation:async()=>{const{app:s}=await b(t,{app:{auth:{webAuthnCreationOptions:!0}}}),i=PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:i})}}),L=t=>{const{assertion:e,attestation:r}=q(t);return{login:async()=>{const s=await e();await p(t,"webAuthnAssertion",{assertion:s.toJSON()})},register:async()=>{const s=await r();await p(t,"webAuthnRegister",{registration:s.toJSON()})}}},U=t=>({WebAuthn:L(t),google:{unlink:()=>p(t,"lightAuthUnlinkGoogle"),login:e=>p(t,"lightAuthLoginGoogle",{credential:e}),register:e=>p(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>p(t,"lightAuthUnlinkFacebook"),login:e=>p(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>p(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>p(t,"lightAuthUnlinkMicrosoft"),login:e=>p(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>p(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>p(t,"login",{username:e,password:r,code:s}),logout:()=>p(t,"logout"),changeExpiredPassword:(e,r,s)=>p(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>p(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>p(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>p(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return p(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await b(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}}),J=(t,e,r)=>{const s=e,i=t,h=r;let f="list"+e;const a=u=>h[u]?h[u]():null;return{field:a,$fields:h,setDataPath(u){return f=u,f},getDataPath(){return f},gqlFields(u){const n=[];for(const o of u)if(typeof o=="string"){const l=a(o);l&&n.push(l.getGQLField())}else typeof o=="object"&&n.push(o);return n},async update(u,n){return await p(i,"update"+s,{id:u,data:n})},async delete(u){return await p(i,"delete"+s,{id:u})},async add(u){return await p(i,"add"+s,{data:u})},fields(u){let n=[];for(let o of u){const l=a(o);l&&n.push(l)}return n},async get(u,n){const o=(await Promise.resolve().then(()=>R)).default,l=o(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.first()},async list(u,n){const o=(await Promise.resolve().then(()=>R)).default,l=o(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.all()}}};function M(t){t="<~"+t+"~>";var e,r,s,i,h,f=String,a=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,h=t.length;h>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(a&r>>24,a&r>>16,a&r>>8,a&r);return function(u,n){for(var o=n;o>0;o--)u.pop()}(s,e.length),f.fromCharCode.apply(f,s)}const D=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let a=0;a<e.length;a++)i[a]=e.charCodeAt(a);const h=new Blob([i],{type:s});return URL.createObjectURL(h)};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")}}},T={fromBase85:t=>D(M(t)),fromBase64:t=>D(atob(t)),fromString:t=>D(t)},S=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(S(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]=S(s)}),e)},k=t=>S(t),b=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 W(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function Q(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const p=async(t,e,r=null,s=[])=>{let i={[e]:{}};const h=new FormData;let f=!1;if(r){const n={},o={},l={};let c=0;Object.entries(r).forEach(([d,w])=>{if(w instanceof Array&&W(w)){f=!0;let y=0;w.forEach(A=>{A instanceof File&&(n[d]=new m.VariableType(d),o[c]=["variables."+d+"."+y],h.append(c.toString(),A),c++)}),l[d]="[Upload!]!"}else w instanceof File?(f=!0,n[d]=new m.VariableType(d),o[c]=["variables."+d],h.append(c.toString(),w),l[d]="Upload!",c++):w instanceof Object&&Q(w)?(f=!0,n[d]={},Object.entries(w).forEach(([y,A])=>{A instanceof File?(n[d][y]=new m.VariableType(y),o[c]=["variables."+y],h.append(c.toString(),A),l[y]="Upload!",c++):n[d][y]=A})):w!==void 0&&(n[d]=w)}),i[e].__args=n,i.__variables=l,f&&h.append("map",JSON.stringify(o))}Object.entries(k(s)).forEach(([n,o])=>{i[e][n]=o}),Object.entries(i[e]).length===0&&(i[e]=!0);let a=null;const u=m.jsonToGraphQLQuery({mutation:i});if(f?(h.append("operations",JSON.stringify({query:u})),a=await t.post("",h)):a=await t.post("",{query:u}),a.data.errors)throw new Error(a.data.errors[0].message);return a.data.data[e]},$=t=>({uploadTempFile:e=>p(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await b(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>p(t,"fsCreateFolder",{path:e}),delete:e=>p(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>p(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await b(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 b(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>p(t,"fsWriteFile",{path:e,content:r}),delete:e=>p(t,"fsDeleteFile",{path:e}),rename:(e,r)=>p(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>p(t,"fsMoveFile",{source:e,target:r})}}),z=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),I=t=>({send:(e,r,s)=>p(t,"sendMail",{email:e,subject:r,message:s})}),K=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()}}),G=t=>{const e=t,r={};return{create(s,i){r[s]=null;let h={};for(const f of Object.entries(i)){const[a,u]=f;h[a]=()=>({name:u.name?u.name:a,raw:u,getName:()=>u.name?u.name:a,getGQLField:()=>u.gqlField!==void 0?u.gqlField:u.name||a,getRaw(){return u},getValue(n){return u.field&&typeof u.field=="function"?u.field(n):u.field&&typeof u.field=="string"?n[u.field]:n[this.getName()]},getFormattedValue(n){const o=this.getValue(n);return u.format?u.format(o):o}})}r[s]=J(e,s,h)},get(s){return r[s]||this.create(s,{}),r[s]}}},V=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await b(t,{app:{roles:e}});return r}}),H="list",X=["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"],Y=["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{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}}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},P().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 a=this._batchData;return this.meta=a.meta,P(a.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 a of e){if(a===i){s[a]=t;break}s[a]={},s=s[a]}let f=await b(this.axios,r);for(const a of e)f=f[a];return this.meta=f.meta,P(f.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 X)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Y)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],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},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 j=(t,e,r)=>{const s=new g(r,e);return s.data_path=H+t,s},R=Object.freeze(Object.defineProperty({__proto__:null,default:j},Symbol.toStringTag,{value:"Module"})),Z=(t,e)=>({uploadTempFile:r=>p(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await b(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>p(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>p(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await b(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 b(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await b(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)=>p(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>p(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>p(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}});function N(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 B(t,e,r=".",s){if(!N(e))return B(t,{},r,s);const i=Object.assign({},e);for(const h in t){if(h==="__proto__"||h==="constructor")continue;const f=t[h];f!=null&&(s&&s(i,h,f,r)||(Array.isArray(f)&&Array.isArray(i[h])?i[h]=[...f,...i[h]]:N(f)&&N(i[h])?i[h]=B(f,i[h],(r?`${r}.`:"")+h.toString(),s):i[h]=f))}return i}function x(t){return(...e)=>e.reduce((r,s)=>B(r,s,"",t),{})}const v=x();function tt(t,e,r){let s,i=[],h,f;const a=n=>!n||typeof n!="object"?!1:Object.values(n).some(o=>o&&typeof o=="object"&&Object.keys(o).some(l=>l.startsWith("_"))),u=()=>i.length===0?(i.unshift({}),i[0]):(a(i[0])&&i.unshift({}),i[0]);return{async fetchWithMeta(){let o=await b(t,this.toQuery(!0));if(f){const l=f.split(".");for(const c of l)o=o[c];return o}return o[`list${e}`]},async fetch(){let o=await b(t,this.toQuery());if(f){const l=f.split(".");for(const c of l)o=o[c];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"&&(h=n),this},filters(n){return n&&typeof n=="object"&&(i=[n]),this},where(n,o,l){const c=(d,w,y)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[w];F&&i.push({[d]:{[F]:y}})};if(l!==void 0)c(n,String(o),l);else{const d=u(),w=v(d,{[n]:o});i[0]=w}return this},whereContains(n,o){if(n&&typeof n=="string"){const l=u(),c={_contains:o};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereIn(n,o){if(n&&typeof n=="string"&&Array.isArray(o)){const l=u(),c={_in:o};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereBetween(n,o,l){if(n&&typeof n=="string"){const c=u(),d={_between:[o,l]};c[n]?Array.isArray(c[n])?c[n].push(d):c[n]=[c[n],d]:c[n]=d,i[0]=c}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{offset:n})),this},toQuery(n=!1){let o;const l=i.length>0&&Object.keys(i[0]||{}).length>0,c=l?1:0,d=i.length>c;l&&d?o=i:d?o=i.slice(c):l&&(o=i[0]);const w=v(h?{sort:h}:{},o?{filters:o}:{}),y={data:{...r}};if(s&&(y.data.__args=s),Object.keys(w).length>0&&(y.__args=w),n&&(y.meta={total:!0,key:!0,name:!0}),f){const A=f.split(".");let F=y;for(let E=A.length-1;E>=0;E--)F={[A[E]]:F};return F}return{[`list${e}`]:y}}}}const et=t=>{const e=typeof window>"u";let r=[];const s=O.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(a=>(a.withCredentials=!0,r.length>0&&(a.headers.Cookie=r.join("; ")),a)),s.interceptors.response.use(a=>{if(a.headers["set-cookie"]){const u=a.headers["set-cookie"].map(o=>o.split(";")[0]),n=new Map;r.forEach(o=>{const l=o.split("=")[0];n.set(l,o)}),u.forEach(o=>{const l=o.split("=")[0];n.set(l,o)}),r=Array.from(n.values())}return a}));const i=(a,u=null,n=[])=>p(s,a,u,n),h=a=>b(s,a),f=G(s);return{baseURL:t,axios:s,auth:U(s),mutation:i,query:h,config:z(h),mail:I(s),users:K(s),fs:$(s),models:f,model(a){return f.get(a)},roles:V(s),collect:(a,u)=>{const n=j(a,s,u);return n.data_path=f.get(a).getDataPath(),n},list:(a,u)=>tt(s,a,u).dataPath(f.get(a).getDataPath()),drive(a){return Z(a,s)},async collects(a){const u={},n={};for(const l in a){const c=a[l].getQueryPayload();n[l]=c.data_path,u[l]={};const d=c.data_path.split(".");let w=d[d.length-1],y=u[l];for(const A of d){if(A===w){y[A]=c.query;break}y[A]=y[A]||{}}u[l].__aliasFor=d[0]}const o=await b(s,u);for(const l in a){const c=n[l].split(".");let d=c[c.length-1],w=o[l];for(const y of c){if(y===d){a[l]._batchData=o[l][y];break}w[y]=w[y]||{}}}return a}}};_.File=T,_.createClient=et,_.createCollection=j,_.file=D,_.mutation=p,_.query=b,_.toQuery=k,_.useWebAuthn=q,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"