@hostlink/light 2.11.0 → 2.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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,69 +115,69 @@ 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 a = (c) => h[c] ? h[c]() : null;
119
119
  return {
120
- field: o,
120
+ field: a,
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)
131
- if (typeof a == "string") {
132
- const l = o(a);
130
+ for (const o of c)
131
+ if (typeof o == "string") {
132
+ const l = a(o);
133
133
  l && n.push(l.getGQLField());
134
- } else typeof a == "object" && n.push(a);
134
+ } else typeof o == "object" && n.push(o);
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) {
149
- const l = o(a);
148
+ for (let o of c) {
149
+ const l = a(o);
150
150
  l && n.push(l);
151
151
  }
152
152
  return n;
153
153
  },
154
- async get(u, n) {
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);
154
+ async get(c, n) {
155
+ const o = (await Promise.resolve().then(() => B)).default, l = o(s, i, O(n));
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) {
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);
160
+ async list(c, n) {
161
+ const o = (await Promise.resolve().then(() => B)).default, l = o(s, i, O(n));
162
+ for (const [u, d] of Object.entries(c))
163
+ l.where(u, "==", d);
164
164
  return await l.all();
165
165
  }
166
166
  };
167
167
  };
168
168
  function T(t) {
169
169
  t = "<~" + t + "~>";
170
- var e, r, s, i, h, f = String, o = 255;
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();
170
+ var e, r, s, i, h, f = String, a = 255;
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(a & r >> 24, a & r >> 16, a & r >> 8, a & r);
172
+ return function(c, n) {
173
+ for (var o = n; o > 0; o--) c.pop();
174
174
  }(s, e.length), f.fromCharCode.apply(f, s);
175
175
  }
176
176
  const D = (t = "") => {
177
177
  const e = t, r = (s = "application/octet-stream") => {
178
178
  const i = new Uint8Array(e.length);
179
- for (let o = 0; o < e.length; o++)
180
- i[o] = e.charCodeAt(o);
179
+ for (let a = 0; a < e.length; a++)
180
+ i[a] = e.charCodeAt(a);
181
181
  const h = new Blob([i], { type: s });
182
182
  return URL.createObjectURL(h);
183
183
  };
@@ -241,32 +241,32 @@ const p = async (t, e, r = null, s = []) => {
241
241
  const h = new FormData();
242
242
  let f = !1;
243
243
  if (r) {
244
- const n = {}, a = {}, l = {};
245
- let c = 0;
244
+ const n = {}, o = {}, l = {};
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), o[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), o[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), o[u] = ["variables." + y], h.append(u.toString(), w), l[y] = "Upload!", u++) : n[d][y] = w;
255
255
  })) : _ !== void 0 && (n[d] = _);
256
- }), i[e].__args = n, i.__variables = l, f && h.append("map", JSON.stringify(a));
256
+ }), i[e].__args = n, i.__variables = l, f && h.append("map", JSON.stringify(o));
257
257
  }
258
- Object.entries(O(s)).forEach(([n, a]) => {
259
- i[e][n] = a;
258
+ Object.entries(O(s)).forEach(([n, o]) => {
259
+ i[e][n] = o;
260
260
  }), Object.entries(i[e]).length === 0 && (i[e] = !0);
261
- let o = null;
262
- const u = E({ mutation: i });
261
+ let a = null;
262
+ const c = E({ mutation: i });
263
263
  if (f ? (h.append("operations", JSON.stringify({
264
- query: u
265
- })), o = await t.post("", h)) : o = await t.post("", {
266
- query: u
267
- }), o.data.errors)
268
- throw new Error(o.data.errors[0].message);
269
- return o.data.data[e];
264
+ query: c
265
+ })), a = await t.post("", h)) : a = await t.post("", {
266
+ query: c
267
+ }), a.data.errors)
268
+ throw new Error(a.data.errors[0].message);
269
+ return a.data.data[e];
270
270
  }, z = (t) => ({
271
271
  uploadTempFile: (e) => p(t, "fsUploadTempFile", {
272
272
  file: 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;
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,
369
+ const [a, c] = f;
370
+ h[a] = () => ({
371
+ name: c.name ? c.name : a,
372
+ raw: c,
373
+ getName: () => c.name ? c.name : a,
374
+ getGQLField: () => c.gqlField !== void 0 ? c.gqlField : c.name || a,
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
- const a = this.getValue(n);
383
- return u.format ? u.format(a) : a;
382
+ const o = this.getValue(n);
383
+ return c.format ? c.format(o) : o;
384
384
  }
385
385
  });
386
386
  }
@@ -505,8 +505,8 @@ j().macro("whereContains", function(t, e) {
505
505
  g.prototype.fetchData = async function() {
506
506
  try {
507
507
  if (this._batchData) {
508
- const o = this._batchData;
509
- return this.meta = o.meta, j(o.data);
508
+ const a = this._batchData;
509
+ return this.meta = a.meta, j(a.data);
510
510
  }
511
511
  let t = {
512
512
  meta: {
@@ -518,16 +518,16 @@ g.prototype.fetchData = async function() {
518
518
  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);
519
519
  const e = this.data_path.split(".");
520
520
  let r = {}, s = r, i = e[e.length - 1];
521
- for (const o of e) {
522
- if (o === i) {
523
- s[o] = t;
521
+ for (const a of e) {
522
+ if (a === i) {
523
+ s[a] = t;
524
524
  break;
525
525
  }
526
- s[o] = {}, s = s[o];
526
+ s[a] = {}, s = s[a];
527
527
  }
528
528
  let f = await m(this.axios, r);
529
- for (const o of e)
530
- f = f[o];
529
+ for (const a of e)
530
+ f = f[a];
531
531
  return this.meta = f.meta, j(f.data);
532
532
  } catch (t) {
533
533
  throw console.error("Error fetching collection data:", t), t;
@@ -772,27 +772,30 @@ 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 a = (n) => !n || typeof n != "object" ? !1 : Object.values(n).some((o) => o && typeof o == "object" && Object.keys(o).some((l) => l.startsWith("_"))), c = () => i.length === 0 ? (i.unshift({}), i[0]) : (a(i[0]) && i.unshift({}), i[0]);
776
776
  return {
777
+ async fetchFirst() {
778
+ return await this.limit(1).fetch().then((o) => Array.isArray(o) && o.length > 0 ? o[0] : null);
779
+ },
777
780
  async fetchWithMeta() {
778
- let a = await m(t, this.toQuery(!0));
781
+ let o = await m(t, this.toQuery(!0));
779
782
  if (f) {
780
783
  const l = f.split(".");
781
- for (const c of l)
782
- a = a[c];
783
- return a;
784
+ for (const u of l)
785
+ o = o[u];
786
+ return o;
784
787
  }
785
- return a[`list${e}`];
788
+ return o[`list${e}`];
786
789
  },
787
790
  async fetch() {
788
- let a = await m(t, this.toQuery());
791
+ let o = await m(t, this.toQuery());
789
792
  if (f) {
790
793
  const l = f.split(".");
791
- for (const c of l)
792
- a = a[c];
793
- return a.data;
794
+ for (const u of l)
795
+ o = o[u];
796
+ return o.data;
794
797
  }
795
- return a[`list${e}`].data;
798
+ return o[`list${e}`].data;
796
799
  },
797
800
  dataPath(n) {
798
801
  return n && typeof n == "string" && (f = n), this;
@@ -806,8 +809,8 @@ function et(t, e, r) {
806
809
  // where can be called as:
807
810
  // where('key', value) -> exact match
808
811
  // where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
809
- where(n, a, l) {
810
- const c = (d, _, y) => {
812
+ where(n, o, l) {
813
+ const u = (d, _, y) => {
811
814
  const A = {
812
815
  ">": "_gt",
813
816
  "<": "_lt",
@@ -820,37 +823,37 @@ function et(t, e, r) {
820
823
  A && i.push({ [d]: { [A]: y } });
821
824
  };
822
825
  if (l !== void 0)
823
- c(n, String(a), l);
826
+ u(n, String(o), l);
824
827
  else {
825
- const d = u(), _ = C(d, { [n]: a });
828
+ const d = c(), _ = C(d, { [n]: o });
826
829
  i[0] = _;
827
830
  }
828
831
  return this;
829
832
  },
830
833
  // whereContains adds a _contains filter for a specific field
831
834
  // If the same field is used multiple times, it merges them into an array
832
- whereContains(n, a) {
835
+ whereContains(n, o) {
833
836
  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;
837
+ const l = c(), u = { _contains: o };
838
+ l[n] ? Array.isArray(l[n]) ? l[n].push(u) : l[n] = [l[n], u] : l[n] = [u], i[0] = l;
836
839
  }
837
840
  return this;
838
841
  },
839
842
  // ...existing code...
840
843
  // whereIn adds an _in filter for a specific field
841
844
  // If the same field is used multiple times, it merges them into an array
842
- whereIn(n, a) {
843
- 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;
845
+ whereIn(n, o) {
846
+ if (n && typeof n == "string" && Array.isArray(o)) {
847
+ const l = c(), u = { _in: o };
848
+ l[n] ? Array.isArray(l[n]) ? l[n].push(u) : l[n] = [l[n], u] : l[n] = [u], i[0] = l;
846
849
  }
847
850
  return this;
848
851
  },
849
852
  // whereBetween adds a _between filter for a specific field
850
- whereBetween(n, a, l) {
853
+ whereBetween(n, o, l) {
851
854
  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;
855
+ const u = c(), d = { _between: [o, l] };
856
+ u[n] ? Array.isArray(u[n]) ? u[n].push(d) : u[n] = [u[n], d] : u[n] = d, i[0] = u;
854
857
  }
855
858
  return this;
856
859
  },
@@ -863,12 +866,12 @@ function et(t, e, r) {
863
866
  return typeof n == "number" && Number.isFinite(n) && (s = C(s || {}, { offset: n })), this;
864
867
  },
865
868
  toQuery(n = !1) {
866
- 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]);
869
+ let o;
870
+ const l = i.length > 0 && Object.keys(i[0] || {}).length > 0, u = l ? 1 : 0, d = i.length > u;
871
+ l && d ? o = i : d ? o = i.slice(u) : l && (o = i[0]);
869
872
  const _ = C(
870
873
  h ? { sort: h } : {},
871
- a ? { filters: a } : {}
874
+ o ? { filters: o } : {}
872
875
  ), y = {
873
876
  data: {
874
877
  ...r
@@ -900,20 +903,20 @@ const at = (t) => {
900
903
  baseURL: t,
901
904
  withCredentials: !0
902
905
  });
903
- e && (s.interceptors.request.use((o) => (o.withCredentials = !0, r.length > 0 && (o.headers.Cookie = r.join("; ")), o)), s.interceptors.response.use((o) => {
904
- if (o.headers["set-cookie"]) {
905
- const u = o.headers["set-cookie"].map((a) => a.split(";")[0]), n = /* @__PURE__ */ new Map();
906
- r.forEach((a) => {
907
- const l = a.split("=")[0];
908
- n.set(l, a);
909
- }), u.forEach((a) => {
910
- const l = a.split("=")[0];
911
- n.set(l, a);
906
+ e && (s.interceptors.request.use((a) => (a.withCredentials = !0, r.length > 0 && (a.headers.Cookie = r.join("; ")), a)), s.interceptors.response.use((a) => {
907
+ if (a.headers["set-cookie"]) {
908
+ const c = a.headers["set-cookie"].map((o) => o.split(";")[0]), n = /* @__PURE__ */ new Map();
909
+ r.forEach((o) => {
910
+ const l = o.split("=")[0];
911
+ n.set(l, o);
912
+ }), c.forEach((o) => {
913
+ const l = o.split("=")[0];
914
+ n.set(l, o);
912
915
  }), r = Array.from(n.values());
913
916
  }
914
- return o;
917
+ return a;
915
918
  }));
916
- const i = (o, u = null, n = []) => p(s, o, u, n), h = (o) => m(s, o), f = V(s);
919
+ const i = (a, c = null, n = []) => p(s, a, c, n), h = (a) => m(s, a), f = V(s);
917
920
  return {
918
921
  baseURL: t,
919
922
  axios: s,
@@ -925,47 +928,47 @@ const at = (t) => {
925
928
  users: K(s),
926
929
  fs: z(s),
927
930
  models: f,
928
- model(o) {
929
- return f.get(o);
931
+ model(a) {
932
+ return f.get(a);
930
933
  },
931
934
  roles: H(s),
932
- collect: (o, u) => {
933
- const n = N(o, s, u);
934
- return n.data_path = f.get(o).getDataPath(), n;
935
+ collect: (a, c) => {
936
+ const n = N(a, s, c);
937
+ return n.data_path = f.get(a).getDataPath(), n;
935
938
  },
936
- list: (o, u) => et(s, o, u).dataPath(f.get(o).getDataPath()),
937
- drive(o) {
938
- return x(o, s);
939
+ list: (a, c) => et(s, a, c).dataPath(f.get(a).getDataPath()),
940
+ drive(a) {
941
+ return x(a, s);
939
942
  },
940
- async collects(o) {
941
- const u = {}, n = {};
942
- 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];
943
+ async collects(a) {
944
+ const c = {}, n = {};
945
+ for (const l in a) {
946
+ const u = a[l].getQueryPayload();
947
+ n[l] = u.data_path, c[l] = {};
948
+ const d = u.data_path.split(".");
949
+ let _ = d[d.length - 1], y = c[l];
947
950
  for (const w of d) {
948
951
  if (w === _) {
949
- y[w] = c.query;
952
+ y[w] = u.query;
950
953
  break;
951
954
  }
952
955
  y[w] = y[w] || {};
953
956
  }
954
- u[l].__aliasFor = d[0];
957
+ c[l].__aliasFor = d[0];
955
958
  }
956
- const a = await m(s, u);
957
- 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) {
959
+ const o = await m(s, c);
960
+ for (const l in a) {
961
+ const u = n[l].split(".");
962
+ let d = u[u.length - 1], _ = o[l];
963
+ for (const y of u) {
961
964
  if (y === d) {
962
- o[l]._batchData = a[l][y];
965
+ a[l]._batchData = o[l][y];
963
966
  break;
964
967
  }
965
968
  _[y] = _[y] || {};
966
969
  }
967
970
  }
968
- return o;
971
+ return a;
969
972
  }
970
973
  };
971
974
  };
@@ -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(){return await this.limit(1).fetch().then(a=>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.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"