@hostlink/light 2.11.0 → 2.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
  type Fields = Record<string, any>;
3
3
  export default function createList(axios: AxiosInstance, entity: string, fields: Fields): {
4
+ fetchFirst(): Promise<any>;
4
5
  fetchWithMeta(): Promise<any>;
5
6
  fetch(): Promise<any>;
6
7
  dataPath(dataPath?: string): /*elided*/ any;
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 = (u) => h[u] ? h[u]() : null;
118
+ const o = (c) => h[c] ? h[c]() : null;
119
119
  return {
120
120
  field: o,
121
121
  $fields: h,
122
- setDataPath(u) {
123
- return f = u, f;
122
+ setDataPath(c) {
123
+ return f = c, f;
124
124
  },
125
125
  getDataPath() {
126
126
  return f;
127
127
  },
128
- gqlFields(u) {
128
+ gqlFields(c) {
129
129
  const n = [];
130
- for (const a of u)
130
+ for (const a of c)
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(u, n) {
138
- return await p(i, "update" + s, { id: u, data: n });
137
+ async update(c, n) {
138
+ return await p(i, "update" + s, { id: c, data: n });
139
139
  },
140
- async delete(u) {
141
- return await p(i, "delete" + s, { id: u });
140
+ async delete(c) {
141
+ return await p(i, "delete" + s, { id: c });
142
142
  },
143
- async add(u) {
144
- return await p(i, "add" + s, { data: u });
143
+ async add(c) {
144
+ return await p(i, "add" + s, { data: c });
145
145
  },
146
- fields(u) {
146
+ fields(c) {
147
147
  let n = [];
148
- for (let a of u) {
148
+ for (let a of c) {
149
149
  const l = o(a);
150
150
  l && n.push(l);
151
151
  }
152
152
  return n;
153
153
  },
154
- async get(u, n) {
154
+ async get(c, n) {
155
155
  const a = (await Promise.resolve().then(() => B)).default, l = a(s, i, O(n));
156
- for (const [c, d] of Object.entries(u))
157
- l.where(c, "==", d);
156
+ for (const [u, d] of Object.entries(c))
157
+ l.where(u, "==", d);
158
158
  return await l.first();
159
159
  },
160
- async list(u, n) {
160
+ async list(c, n) {
161
161
  const a = (await Promise.resolve().then(() => B)).default, l = a(s, i, O(n));
162
- for (const [c, d] of Object.entries(u))
163
- l.where(c, "==", d);
162
+ for (const [u, d] of Object.entries(c))
163
+ l.where(u, "==", 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(u, n) {
173
- for (var a = n; a > 0; a--) u.pop();
172
+ return function(c, n) {
173
+ for (var a = n; a > 0; a--) c.pop();
174
174
  }(s, e.length), f.fromCharCode.apply(f, s);
175
175
  }
176
176
  const D = (t = "") => {
@@ -192,7 +192,7 @@ const D = (t = "") => {
192
192
  window.open(r(s), "_blank");
193
193
  }
194
194
  };
195
- }, ot = {
195
+ }, at = {
196
196
  fromBase85: (t) => D(T(t)),
197
197
  fromBase64: (t) => D(atob(t)),
198
198
  fromString: (t) => 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 c = 0;
245
+ let u = 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[c] = ["variables." + d + "." + y], h.append(c.toString(), w), c++);
251
+ w instanceof File && (n[d] = new k(d), a[u] = ["variables." + d + "." + y], h.append(u.toString(), w), u++);
252
252
  }), l[d] = "[Upload!]!";
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;
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;
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 u = E({ mutation: i });
262
+ const c = E({ mutation: i });
263
263
  if (f ? (h.append("operations", JSON.stringify({
264
- query: u
264
+ query: c
265
265
  })), o = await t.post("", h)) : o = await t.post("", {
266
- query: u
266
+ query: c
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, u] = f;
369
+ const [o, c] = f;
370
370
  h[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,
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,
375
375
  getRaw() {
376
- return u;
376
+ return c;
377
377
  },
378
378
  getValue(n) {
379
- return u.field && typeof u.field == "function" ? u.field(n) : u.field && typeof u.field == "string" ? n[u.field] : n[this.getName()];
379
+ return c.field && typeof c.field == "function" ? c.field(n) : c.field && typeof c.field == "string" ? n[c.field] : n[this.getName()];
380
380
  },
381
381
  getFormattedValue(n) {
382
382
  const a = this.getValue(n);
383
- return u.format ? u.format(a) : a;
383
+ return c.format ? c.format(a) : a;
384
384
  }
385
385
  });
386
386
  }
@@ -772,14 +772,18 @@ 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("_"))), u = () => 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("_"))), c = () => i.length === 0 ? (i.unshift({}), i[0]) : (o(i[0]) && i.unshift({}), i[0]);
776
776
  return {
777
+ async fetchFirst() {
778
+ const a = await this.limit(1).fetch();
779
+ return Array.isArray(a) && a.length > 0 ? a[0] : null;
780
+ },
777
781
  async fetchWithMeta() {
778
782
  let a = await m(t, this.toQuery(!0));
779
783
  if (f) {
780
784
  const l = f.split(".");
781
- for (const c of l)
782
- a = a[c];
785
+ for (const u of l)
786
+ a = a[u];
783
787
  return a;
784
788
  }
785
789
  return a[`list${e}`];
@@ -788,8 +792,8 @@ function et(t, e, r) {
788
792
  let a = await m(t, this.toQuery());
789
793
  if (f) {
790
794
  const l = f.split(".");
791
- for (const c of l)
792
- a = a[c];
795
+ for (const u of l)
796
+ a = a[u];
793
797
  return a.data;
794
798
  }
795
799
  return a[`list${e}`].data;
@@ -807,7 +811,7 @@ function et(t, e, r) {
807
811
  // where('key', value) -> exact match
808
812
  // where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
809
813
  where(n, a, l) {
810
- const c = (d, _, y) => {
814
+ const u = (d, _, y) => {
811
815
  const A = {
812
816
  ">": "_gt",
813
817
  "<": "_lt",
@@ -820,9 +824,9 @@ function et(t, e, r) {
820
824
  A && i.push({ [d]: { [A]: y } });
821
825
  };
822
826
  if (l !== void 0)
823
- c(n, String(a), l);
827
+ u(n, String(a), l);
824
828
  else {
825
- const d = u(), _ = C(d, { [n]: a });
829
+ const d = c(), _ = C(d, { [n]: a });
826
830
  i[0] = _;
827
831
  }
828
832
  return this;
@@ -831,8 +835,8 @@ function et(t, e, r) {
831
835
  // If the same field is used multiple times, it merges them into an array
832
836
  whereContains(n, a) {
833
837
  if (n && typeof n == "string") {
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;
838
+ const l = c(), u = { _contains: a };
839
+ l[n] ? Array.isArray(l[n]) ? l[n].push(u) : l[n] = [l[n], u] : l[n] = [u], i[0] = l;
836
840
  }
837
841
  return this;
838
842
  },
@@ -841,16 +845,16 @@ function et(t, e, r) {
841
845
  // If the same field is used multiple times, it merges them into an array
842
846
  whereIn(n, a) {
843
847
  if (n && typeof n == "string" && Array.isArray(a)) {
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;
848
+ const l = c(), u = { _in: a };
849
+ l[n] ? Array.isArray(l[n]) ? l[n].push(u) : l[n] = [l[n], u] : l[n] = [u], i[0] = l;
846
850
  }
847
851
  return this;
848
852
  },
849
853
  // whereBetween adds a _between filter for a specific field
850
854
  whereBetween(n, a, l) {
851
855
  if (n && typeof n == "string") {
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;
856
+ const u = c(), d = { _between: [a, l] };
857
+ u[n] ? Array.isArray(u[n]) ? u[n].push(d) : u[n] = [u[n], d] : u[n] = d, i[0] = u;
854
858
  }
855
859
  return this;
856
860
  },
@@ -864,8 +868,8 @@ function et(t, e, r) {
864
868
  },
865
869
  toQuery(n = !1) {
866
870
  let a;
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]);
871
+ const l = i.length > 0 && Object.keys(i[0] || {}).length > 0, u = l ? 1 : 0, d = i.length > u;
872
+ l && d ? a = i : d ? a = i.slice(u) : l && (a = i[0]);
869
873
  const _ = C(
870
874
  h ? { sort: h } : {},
871
875
  a ? { filters: a } : {}
@@ -893,7 +897,7 @@ function et(t, e, r) {
893
897
  }
894
898
  };
895
899
  }
896
- const at = (t) => {
900
+ const ot = (t) => {
897
901
  const e = typeof window > "u";
898
902
  let r = [];
899
903
  const s = L.create({
@@ -902,18 +906,18 @@ const at = (t) => {
902
906
  });
903
907
  e && (s.interceptors.request.use((o) => (o.withCredentials = !0, r.length > 0 && (o.headers.Cookie = r.join("; ")), o)), s.interceptors.response.use((o) => {
904
908
  if (o.headers["set-cookie"]) {
905
- const u = o.headers["set-cookie"].map((a) => a.split(";")[0]), n = /* @__PURE__ */ new Map();
909
+ const c = o.headers["set-cookie"].map((a) => a.split(";")[0]), n = /* @__PURE__ */ new Map();
906
910
  r.forEach((a) => {
907
911
  const l = a.split("=")[0];
908
912
  n.set(l, a);
909
- }), u.forEach((a) => {
913
+ }), c.forEach((a) => {
910
914
  const l = a.split("=")[0];
911
915
  n.set(l, a);
912
916
  }), r = Array.from(n.values());
913
917
  }
914
918
  return o;
915
919
  }));
916
- const i = (o, u = null, n = []) => p(s, o, u, n), h = (o) => m(s, o), f = V(s);
920
+ const i = (o, c = null, n = []) => p(s, o, c, n), h = (o) => m(s, o), f = V(s);
917
921
  return {
918
922
  baseURL: t,
919
923
  axios: s,
@@ -929,35 +933,35 @@ const at = (t) => {
929
933
  return f.get(o);
930
934
  },
931
935
  roles: H(s),
932
- collect: (o, u) => {
933
- const n = N(o, s, u);
936
+ collect: (o, c) => {
937
+ const n = N(o, s, c);
934
938
  return n.data_path = f.get(o).getDataPath(), n;
935
939
  },
936
- list: (o, u) => et(s, o, u).dataPath(f.get(o).getDataPath()),
940
+ list: (o, c) => et(s, o, c).dataPath(f.get(o).getDataPath()),
937
941
  drive(o) {
938
942
  return x(o, s);
939
943
  },
940
944
  async collects(o) {
941
- const u = {}, n = {};
945
+ const c = {}, n = {};
942
946
  for (const l in o) {
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];
947
+ const u = o[l].getQueryPayload();
948
+ n[l] = u.data_path, c[l] = {};
949
+ const d = u.data_path.split(".");
950
+ let _ = d[d.length - 1], y = c[l];
947
951
  for (const w of d) {
948
952
  if (w === _) {
949
- y[w] = c.query;
953
+ y[w] = u.query;
950
954
  break;
951
955
  }
952
956
  y[w] = y[w] || {};
953
957
  }
954
- u[l].__aliasFor = d[0];
958
+ c[l].__aliasFor = d[0];
955
959
  }
956
- const a = await m(s, u);
960
+ const a = await m(s, c);
957
961
  for (const l in o) {
958
- const c = n[l].split(".");
959
- let d = c[c.length - 1], _ = a[l];
960
- for (const y of c) {
962
+ const u = n[l].split(".");
963
+ let d = u[u.length - 1], _ = a[l];
964
+ for (const y of u) {
961
965
  if (y === d) {
962
966
  o[l]._batchData = a[l][y];
963
967
  break;
@@ -970,8 +974,8 @@ const at = (t) => {
970
974
  };
971
975
  };
972
976
  export {
973
- ot as File,
974
- at as createClient,
977
+ at as File,
978
+ ot as createClient,
975
979
  N as createCollection,
976
980
  D as file,
977
981
  p as mutation,
@@ -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 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"})});
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 fetchFirst(){const a=await this.limit(1).fetch();return Array.isArray(a)&&a.length>0?a[0]:null},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}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.data}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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "2.11.0",
3
+ "version": "2.11.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"