@hostlink/light 3.2.5 → 3.2.7

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.
@@ -9,4 +9,5 @@ export declare const move: (from: string, to: string) => Promise<any>;
9
9
  export declare const exists: (location: string) => Promise<any>;
10
10
  export declare const find: (search?: string, label?: "document" | "image" | "audio" | "video" | "archive") => Promise<any>;
11
11
  export declare const list: (location: string) => Promise<any>;
12
- export declare const read: (location: string) => Promise<any>;
12
+ export declare const readFile: (location: string, type?: "text" | "base64") => Promise<any>;
13
+ export declare const uploadBase64: (location: string, base64: string) => Promise<any>;
package/dist/light.js CHANGED
@@ -14,13 +14,13 @@ function E(t, e, r = ".", s) {
14
14
  for (const u in t) {
15
15
  if (u === "__proto__" || u === "constructor")
16
16
  continue;
17
- const l = t[u];
18
- l != null && (s && s(i, u, l, r) || (Array.isArray(l) && Array.isArray(i[u]) ? i[u] = [...l, ...i[u]] : k(l) && k(i[u]) ? i[u] = E(
19
- l,
17
+ const c = t[u];
18
+ c != null && (s && s(i, u, c, r) || (Array.isArray(c) && Array.isArray(i[u]) ? i[u] = [...c, ...i[u]] : k(c) && k(i[u]) ? i[u] = E(
19
+ c,
20
20
  i[u],
21
21
  (r ? `${r}.` : "") + u.toString(),
22
22
  s
23
- ) : i[u] = l));
23
+ ) : i[u] = c));
24
24
  }
25
25
  return i;
26
26
  }
@@ -34,18 +34,18 @@ const A = X();
34
34
  let S = null;
35
35
  const Y = (t) => {
36
36
  S = t;
37
- }, N = () => {
37
+ }, M = () => {
38
38
  if (!S)
39
39
  throw new Error("Api client not initialized. Call setApiClient() first.");
40
40
  return S;
41
- }, Zt = () => S;
41
+ }, Vt = () => S;
42
42
  function D(t) {
43
43
  for (let e = 0; e < t.length; e++)
44
44
  if (t[e] instanceof File)
45
45
  return !0;
46
46
  return !1;
47
47
  }
48
- function M(t) {
48
+ function N(t) {
49
49
  for (let e in t)
50
50
  if (t[e] instanceof File || t[e] instanceof Array && D(t[e]))
51
51
  return !0;
@@ -53,11 +53,11 @@ function M(t) {
53
53
  }
54
54
  function Z(t) {
55
55
  t = "<~" + t + "~>";
56
- var e, r, s, i, u, l = String, p = 255;
56
+ var e, r, s, i, u, c = String, p = 255;
57
57
  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, u = t.length; u > 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(p & r >> 24, p & r >> 16, p & r >> 8, p & r);
58
58
  return (function(n, o) {
59
59
  for (var a = o; a > 0; a--) n.pop();
60
- })(s, e.length), l.fromCharCode.apply(l, s);
60
+ })(s, e.length), c.fromCharCode.apply(c, s);
61
61
  }
62
62
  const B = (t = "") => {
63
63
  const e = t, r = (s = "application/octet-stream") => {
@@ -78,44 +78,44 @@ const B = (t = "") => {
78
78
  window.open(r(s), "_blank");
79
79
  }
80
80
  };
81
- }, Vt = (t) => B(atob(t)), It = (t) => B(Z(t));
81
+ }, It = (t) => B(atob(t)), Kt = (t) => B(Z(t));
82
82
  function J(t, e, r, s, i) {
83
83
  if (!(!t || typeof t != "object"))
84
84
  for (let u in t) {
85
- const l = t[u];
86
- if (l && typeof l == "object") {
87
- if ("__args" in l) {
88
- const p = l.__args, n = {};
85
+ const c = t[u];
86
+ if (c && typeof c == "object") {
87
+ if ("__args" in c) {
88
+ const p = c.__args, n = {};
89
89
  Object.entries(p).forEach(([o, a]) => {
90
90
  if (a instanceof Array && D(a)) {
91
91
  n[o] = new b(o);
92
- let c = 0;
92
+ let l = 0;
93
93
  a.forEach((h) => {
94
- h instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + o + "." + c), s.append(i.current.toString(), h), i.current++, c++);
94
+ h instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + o + "." + l), s.append(i.current.toString(), h), i.current++, l++);
95
95
  }), e[o] = "[Upload!]!";
96
- } else a instanceof File ? (n[o] = new b(o), r[i.current] = ["variables." + o], s.append(i.current.toString(), a), e[o] = "Upload!", i.current++) : a instanceof Object && M(a) ? (n[o] = {}, Object.entries(a).forEach(([c, h]) => {
96
+ } else a instanceof File ? (n[o] = new b(o), r[i.current] = ["variables." + o], s.append(i.current.toString(), a), e[o] = "Upload!", i.current++) : a instanceof Object && N(a) ? (n[o] = {}, Object.entries(a).forEach(([l, h]) => {
97
97
  if (h instanceof Array && D(h)) {
98
- n[o][c] = new b(c);
98
+ n[o][l] = new b(l);
99
99
  let d = 0;
100
- h.forEach((g) => {
101
- g instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + c + "." + d), s.append(i.current.toString(), g), i.current++, d++);
102
- }), e[c] = "[Upload!]!";
103
- } else h instanceof File ? (n[o][c] = new b(c), r[i.current] = ["variables." + c], s.append(i.current.toString(), h), e[c] = "Upload!", i.current++) : n[o][c] = h;
100
+ h.forEach((_) => {
101
+ _ instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + l + "." + d), s.append(i.current.toString(), _), i.current++, d++);
102
+ }), e[l] = "[Upload!]!";
103
+ } else h instanceof File ? (n[o][l] = new b(l), r[i.current] = ["variables." + l], s.append(i.current.toString(), h), e[l] = "Upload!", i.current++) : n[o][l] = h;
104
104
  })) : a != null && (n[o] = a);
105
- }), l.__args = n;
105
+ }), c.__args = n;
106
106
  }
107
- J(l, e, r, s, i);
107
+ J(c, e, r, s, i);
108
108
  }
109
109
  }
110
110
  }
111
111
  const y = async (t) => {
112
- const { axios: e } = N(), r = t, s = new FormData();
112
+ const { axios: e } = M(), r = t, s = new FormData();
113
113
  let i = !1;
114
- const u = {}, l = {};
115
- J(r, u, l, s, { current: 0 }), i = Object.keys(u).length > 0, i && (r.__variables = u);
114
+ const u = {}, c = {};
115
+ J(r, u, c, s, { current: 0 }), i = Object.keys(u).length > 0, i && (r.__variables = u);
116
116
  let n = null;
117
117
  const a = q({ query: r });
118
- if (i ? (s.append("map", JSON.stringify(l)), s.append("operations", JSON.stringify({
118
+ if (i ? (s.append("map", JSON.stringify(c)), s.append("operations", JSON.stringify({
119
119
  query: a
120
120
  })), n = await e.post("", s)) : n = await e.post("", {
121
121
  query: a
@@ -125,7 +125,7 @@ const y = async (t) => {
125
125
  };
126
126
  function j(t, e) {
127
127
  let r, s = [], i, u;
128
- const l = (n) => !n || typeof n != "object" ? !1 : Object.values(n).some((o) => o && typeof o == "object" && Object.keys(o).some((a) => a.startsWith("_"))), p = () => s.length === 0 ? (s.unshift({}), s[0]) : (l(s[0]) && s.unshift({}), s[0]);
128
+ const c = (n) => !n || typeof n != "object" ? !1 : Object.values(n).some((o) => o && typeof o == "object" && Object.keys(o).some((a) => a.startsWith("_"))), p = () => s.length === 0 ? (s.unshift({}), s[0]) : (c(s[0]) && s.unshift({}), s[0]);
129
129
  return {
130
130
  first() {
131
131
  return this.fetchFirst();
@@ -141,8 +141,8 @@ function j(t, e) {
141
141
  let o = await y(this.toQuery(!0));
142
142
  if (u) {
143
143
  const a = u.split(".");
144
- for (const c of a)
145
- o = o[c];
144
+ for (const l of a)
145
+ o = o[l];
146
146
  return o;
147
147
  }
148
148
  return o[`list${t}`];
@@ -151,8 +151,8 @@ function j(t, e) {
151
151
  let o = await y(this.toQuery());
152
152
  if (u) {
153
153
  const a = u.split(".");
154
- for (const c of a)
155
- o = o[c];
154
+ for (const l of a)
155
+ o = o[l];
156
156
  return o.data;
157
157
  }
158
158
  return o[`list${t}`].data;
@@ -170,8 +170,8 @@ function j(t, e) {
170
170
  // where('key', value) -> exact match
171
171
  // where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
172
172
  where(n, o, a) {
173
- const c = (h, d, g) => {
174
- const m = {
173
+ const l = (h, d, _) => {
174
+ const w = {
175
175
  ">": "_gt",
176
176
  "<": "_lt",
177
177
  ">=": "_gte",
@@ -180,10 +180,10 @@ function j(t, e) {
180
180
  in: "_in",
181
181
  contains: "_contains"
182
182
  }[d];
183
- m && s.push({ [h]: { [m]: g } });
183
+ w && s.push({ [h]: { [w]: _ } });
184
184
  };
185
185
  if (a !== void 0)
186
- c(n, String(o), a);
186
+ l(n, String(o), a);
187
187
  else {
188
188
  const h = p(), d = A(h, { [n]: o });
189
189
  s[0] = d;
@@ -194,8 +194,8 @@ function j(t, e) {
194
194
  // If the same field is used multiple times, it merges them into an array
195
195
  whereContains(n, o) {
196
196
  if (n && typeof n == "string") {
197
- const a = p(), c = { _contains: o };
198
- a[n] ? Array.isArray(a[n]) ? a[n].push(c) : a[n] = [a[n], c] : a[n] = [c], s[0] = a;
197
+ const a = p(), l = { _contains: o };
198
+ a[n] ? Array.isArray(a[n]) ? a[n].push(l) : a[n] = [a[n], l] : a[n] = [l], s[0] = a;
199
199
  }
200
200
  return this;
201
201
  },
@@ -204,16 +204,16 @@ function j(t, e) {
204
204
  // If the same field is used multiple times, it merges them into an array
205
205
  whereIn(n, o) {
206
206
  if (n && typeof n == "string" && Array.isArray(o)) {
207
- const a = p(), c = { _in: o };
208
- a[n] ? Array.isArray(a[n]) ? a[n].push(c) : a[n] = [a[n], c] : a[n] = [c], s[0] = a;
207
+ const a = p(), l = { _in: o };
208
+ a[n] ? Array.isArray(a[n]) ? a[n].push(l) : a[n] = [a[n], l] : a[n] = [l], s[0] = a;
209
209
  }
210
210
  return this;
211
211
  },
212
212
  // whereBetween adds a _between filter for a specific field
213
213
  whereBetween(n, o, a) {
214
214
  if (n && typeof n == "string") {
215
- const c = p(), h = { _between: [o, a] };
216
- c[n] ? Array.isArray(c[n]) ? c[n].push(h) : c[n] = [c[n], h] : c[n] = h, s[0] = c;
215
+ const l = p(), h = { _between: [o, a] };
216
+ l[n] ? Array.isArray(l[n]) ? l[n].push(h) : l[n] = [l[n], h] : l[n] = h, s[0] = l;
217
217
  }
218
218
  return this;
219
219
  },
@@ -227,31 +227,31 @@ function j(t, e) {
227
227
  },
228
228
  toQuery(n = !1) {
229
229
  let o;
230
- const a = s.length > 0 && Object.keys(s[0] || {}).length > 0, c = a ? 1 : 0, h = s.length > c;
231
- a && h ? o = s : h ? o = s.slice(c) : a && (o = s[0]);
230
+ const a = s.length > 0 && Object.keys(s[0] || {}).length > 0, l = a ? 1 : 0, h = s.length > l;
231
+ a && h ? o = s : h ? o = s.slice(l) : a && (o = s[0]);
232
232
  const d = A(
233
233
  i ? { sort: i } : {},
234
234
  o ? { filters: o } : {}
235
- ), g = {
235
+ ), _ = {
236
236
  data: {
237
237
  ...e
238
238
  }
239
239
  };
240
- if (r && (g.data.__args = r), Object.keys(d).length > 0 && (g.__args = d), n && (g.meta = {
240
+ if (r && (_.data.__args = r), Object.keys(d).length > 0 && (_.__args = d), n && (_.meta = {
241
241
  total: !0,
242
242
  key: !0,
243
243
  name: !0
244
244
  }), u) {
245
245
  const F = u.split(".");
246
- let m = g;
247
- for (let w = F.length - 1; w >= 0; w--)
248
- m = {
249
- [F[w]]: m
246
+ let w = _;
247
+ for (let m = F.length - 1; m >= 0; m--)
248
+ w = {
249
+ [F[m]]: w
250
250
  };
251
- return m;
251
+ return w;
252
252
  }
253
253
  return {
254
- [`list${t}`]: g
254
+ [`list${t}`]: _
255
255
  };
256
256
  }
257
257
  };
@@ -310,7 +310,7 @@ const V = "list", I = [
310
310
  "implode",
311
311
  "partition"
312
312
  ];
313
- class _ {
313
+ class g {
314
314
  _batchData = null;
315
315
  data_path = "";
316
316
  filters;
@@ -327,7 +327,7 @@ class _ {
327
327
  this.filters = {}, this.steps = [], this.fields = e;
328
328
  }
329
329
  }
330
- _.prototype.getQueryPayload = function() {
330
+ g.prototype.getQueryPayload = function() {
331
331
  let t = {
332
332
  meta: {
333
333
  total: !0,
@@ -341,22 +341,22 @@ _.prototype.getQueryPayload = function() {
341
341
  steps: this.steps
342
342
  };
343
343
  };
344
- _.prototype.dataPath = function(t) {
344
+ g.prototype.dataPath = function(t) {
345
345
  const e = this.clone();
346
346
  return e.data_path = t, e;
347
347
  };
348
- _.prototype.buildArgs = function() {
348
+ g.prototype.buildArgs = function() {
349
349
  let t = {};
350
350
  return Object.keys(this.filters).length > 0 && (t.filters = this.filters), this._sort && (t.sort = this._sort, this._sortDesc && (t.sort += ":desc")), t;
351
351
  };
352
- _.prototype.clone = function() {
352
+ g.prototype.clone = function() {
353
353
  const t = Object.create(this);
354
354
  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;
355
355
  };
356
356
  U().macro("whereContains", function(t, e) {
357
357
  return this.filter((r) => r[t].toLowerCase().includes(e.toLowerCase()));
358
358
  });
359
- _.prototype.fetchData = async function() {
359
+ g.prototype.fetchData = async function() {
360
360
  try {
361
361
  if (this._batchData) {
362
362
  const p = this._batchData;
@@ -379,40 +379,40 @@ _.prototype.fetchData = async function() {
379
379
  }
380
380
  s[p] = {}, s = s[p];
381
381
  }
382
- let l = await y(r);
382
+ let c = await y(r);
383
383
  for (const p of e)
384
- l = l[p];
385
- return this.meta = l.meta, U(l.data);
384
+ c = c[p];
385
+ return this.meta = c.meta, U(c.data);
386
386
  } catch (t) {
387
387
  throw console.error("Error fetching collection data:", t), t;
388
388
  }
389
389
  };
390
- _.prototype.processData = async function() {
390
+ g.prototype.processData = async function() {
391
391
  let t = await this.fetchData();
392
392
  for (const e of this.steps)
393
393
  t = t[e.type](...e.args);
394
394
  return t;
395
395
  };
396
- _.prototype.all = async function() {
396
+ g.prototype.all = async function() {
397
397
  return (await this.processData()).all();
398
398
  };
399
399
  for (const t of I)
400
- _.prototype[t] = function(...e) {
400
+ g.prototype[t] = function(...e) {
401
401
  const r = this.clone();
402
402
  return r.steps.push({ type: t, args: e }), r;
403
403
  };
404
404
  for (const t of K)
405
- _.prototype[t] = async function(...e) {
405
+ g.prototype[t] = async function(...e) {
406
406
  return (await this.clone().processData())[t](...e);
407
407
  };
408
- _.prototype.average = _.prototype.avg;
409
- _.prototype.first = async function() {
408
+ g.prototype.average = g.prototype.avg;
409
+ g.prototype.first = async function() {
410
410
  return this.take(1), (await this.processData()).first();
411
411
  };
412
- _.prototype._handleBatchData = function(t, e) {
412
+ g.prototype._handleBatchData = function(t, e) {
413
413
  return this._batchData ? (this.steps.push({ type: t, args: e }), this) : null;
414
414
  };
415
- _.prototype.where = function(...t) {
415
+ g.prototype.where = function(...t) {
416
416
  const e = this._handleBatchData("where", t);
417
417
  if (e) return e;
418
418
  if (t.length === 2)
@@ -444,50 +444,50 @@ _.prototype.where = function(...t) {
444
444
  }
445
445
  return this;
446
446
  };
447
- _.prototype.whereContains = function(t, e) {
447
+ g.prototype.whereContains = function(t, e) {
448
448
  const r = this._handleBatchData("whereContains", [t, e]);
449
449
  return r || (this.filters[t] = { contains: e }, this);
450
450
  };
451
- _.prototype.forPage = function(t, e) {
451
+ g.prototype.forPage = function(t, e) {
452
452
  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);
453
453
  };
454
- _.prototype.whereIn = function(t, e) {
454
+ g.prototype.whereIn = function(t, e) {
455
455
  const r = this._handleBatchData("whereIn", [t, e]);
456
456
  return r || (this.filters[t] = { in: e }, this);
457
457
  };
458
- _.prototype.whereNotIn = function(t, e) {
458
+ g.prototype.whereNotIn = function(t, e) {
459
459
  const r = this._handleBatchData("whereNotIn", [t, e]);
460
460
  return r || (this.filters[t] = { nin: e }, this);
461
461
  };
462
- _.prototype.whereNotBetween = function(t, e) {
462
+ g.prototype.whereNotBetween = function(t, e) {
463
463
  const r = this._handleBatchData("whereNotBetween", [t, e]);
464
464
  return r || (this.filters[t] = { notBetween: e }, this);
465
465
  };
466
- _.prototype.whereBetween = function(t, e) {
466
+ g.prototype.whereBetween = function(t, e) {
467
467
  const r = this._handleBatchData("whereBetween", [t, e]);
468
468
  return r || (this.filters[t] = { between: e }, this);
469
469
  };
470
- _.prototype.sortBy = function(t) {
470
+ g.prototype.sortBy = function(t) {
471
471
  return this.steps.push({ type: "sortBy", args: [t] }), typeof t == "string" && (this._sort = t), this;
472
472
  };
473
- _.prototype.sortByDesc = function(t) {
473
+ g.prototype.sortByDesc = function(t) {
474
474
  return this.steps.push({ type: "sortByDesc", args: [t] }), typeof t == "string" && (this._sort = t, this._sortDesc = !0), this;
475
475
  };
476
- _.prototype.skip = function(t) {
476
+ g.prototype.skip = function(t) {
477
477
  if (t < 0)
478
478
  throw new Error("Offset must be non-negative");
479
479
  return this.already_offset && this.steps.push({ type: "skip", args: [t] }), this.offset = t, this.already_offset = !0, this;
480
480
  };
481
- _.prototype.take = function(t) {
481
+ g.prototype.take = function(t) {
482
482
  if (t < 0)
483
483
  throw new Error("Length must be non-negative");
484
484
  return this.already_limit ? (this.steps.push({ type: "take", args: [t] }), this) : (this.limit = t, this.already_limit = !0, this);
485
485
  };
486
- _.prototype.splice = function(t, e) {
486
+ g.prototype.splice = function(t, e) {
487
487
  return this.steps.push({ type: "splice", args: [t, e] }), this.offset = t, this.limit = e, this.already_limit = !0, this.already_offset = !0, this;
488
488
  };
489
489
  const L = (t, e) => {
490
- const r = new _(e);
490
+ const r = new g(e);
491
491
  return r.data_path = V + t, r;
492
492
  }, x = (t, e = {}) => {
493
493
  const r = e;
@@ -503,18 +503,18 @@ const L = (t, e) => {
503
503
  return s;
504
504
  },
505
505
  gqlFields(u) {
506
- let l = {};
506
+ let c = {};
507
507
  for (const p of u)
508
508
  if (typeof p == "string") {
509
509
  const n = i(p);
510
- n && (l = A(l, n.gqlField ? typeof n.gqlField == "string" ? { [n.gqlField]: !0 } : n.gqlField : { [n.name || p]: !0 }));
511
- } else typeof p == "object" && (l = A(l, p));
512
- return l;
510
+ n && (c = A(c, n.gqlField ? typeof n.gqlField == "string" ? { [n.gqlField]: !0 } : n.gqlField : { [n.name || p]: !0 }));
511
+ } else typeof p == "object" && (c = A(c, p));
512
+ return c;
513
513
  },
514
- update(u, l) {
514
+ update(u, c) {
515
515
  return f({
516
516
  ["update" + t]: {
517
- __args: { id: u, data: l }
517
+ __args: { id: u, data: c }
518
518
  }
519
519
  }).then((p) => p["update" + t]);
520
520
  },
@@ -523,71 +523,71 @@ const L = (t, e) => {
523
523
  ["delete" + t]: {
524
524
  __args: { id: u }
525
525
  }
526
- }).then((l) => l["delete" + t]);
526
+ }).then((c) => c["delete" + t]);
527
527
  },
528
528
  add(u) {
529
529
  return f({
530
530
  ["add" + t]: {
531
531
  __args: { data: u }
532
532
  }
533
- }).then((l) => l["add" + t]);
533
+ }).then((c) => c["add" + t]);
534
534
  },
535
535
  fields(u) {
536
- let l = [];
536
+ let c = [];
537
537
  for (let p of u) {
538
538
  const n = i(p);
539
- n && l.push(n);
539
+ n && c.push(n);
540
540
  }
541
- return l;
541
+ return c;
542
542
  },
543
- async get(u, l) {
544
- const p = L(t, zt(l));
543
+ async get(u, c) {
544
+ const p = L(t, Ht(c));
545
545
  for (const [n, o] of Object.entries(u))
546
546
  p.where(n, "==", o);
547
547
  return await p.first();
548
548
  },
549
549
  list(u) {
550
- let l = u;
550
+ let c = u;
551
551
  const p = {};
552
552
  Object.entries(u).forEach(([a]) => {
553
- r[a] && (p[a] = r[a], r[a].gqlField && (delete l[a], l = A(l, r[a].gqlField)), r[a].gql && (delete l[a], l = A(l, r[a].gql)));
553
+ r[a] && (p[a] = r[a], r[a].gqlField && (delete c[a], c = A(c, r[a].gqlField)), r[a].gql && (delete c[a], c = A(c, r[a].gql)));
554
554
  });
555
- const n = j(t, l).dataPath(s), o = n.fetch.bind(n);
555
+ const n = j(t, c).dataPath(s), o = n.fetch.bind(n);
556
556
  return {
557
557
  ...n,
558
558
  async fetch() {
559
- return (await o()).map((c) => {
560
- const h = { ...c };
561
- return Object.entries(p).forEach(([d, g]) => {
562
- g.field && typeof g.field == "function" && (h[d] = g.field(c[d], c));
559
+ return (await o()).map((l) => {
560
+ const h = { ...l };
561
+ return Object.entries(p).forEach(([d, _]) => {
562
+ _.field && typeof _.field == "function" && (h[d] = _.field(l[d], l));
563
563
  }), h;
564
564
  });
565
565
  },
566
566
  async fetchFirst() {
567
- const c = await n.fetchFirst.bind(n)();
568
- if (!c) return c;
569
- const h = { ...c };
570
- return Object.entries(p).forEach(([d, g]) => {
571
- g.field && typeof g.field == "function" && (h[d] = g.field(c[d], c));
567
+ const l = await n.fetchFirst.bind(n)();
568
+ if (!l) return l;
569
+ const h = { ...l };
570
+ return Object.entries(p).forEach(([d, _]) => {
571
+ _.field && typeof _.field == "function" && (h[d] = _.field(l[d], l));
572
572
  }), h;
573
573
  }
574
574
  };
575
575
  }
576
576
  };
577
- }, O = {}, R = (t, e) => {
577
+ }, O = {}, T = (t, e) => {
578
578
  const r = x(t, e);
579
579
  return O[t] = r, r;
580
- }, P = (t) => O[t] ? O[t] : R(t, {}), Kt = (t) => !!O[t], xt = () => Object.keys(O), te = () => {
580
+ }, P = (t) => O[t] ? O[t] : T(t, {}), xt = (t) => !!O[t], te = () => Object.keys(O), ee = () => {
581
581
  Object.keys(O).forEach((t) => delete O[t]);
582
- }, ee = (t) => {
582
+ }, re = (t) => {
583
583
  Object.entries(t).forEach(([e, r]) => {
584
- R(e, r);
584
+ T(e, r);
585
585
  });
586
- }, re = () => y({
586
+ }, se = () => y({
587
587
  app: {
588
588
  permissions: !0
589
589
  }
590
- }).then((t) => t.app.permissions), T = async () => {
590
+ }).then((t) => t.app.permissions), R = async () => {
591
591
  const { app: t } = await y({
592
592
  app: {
593
593
  auth: {
@@ -606,7 +606,7 @@ const L = (t, e) => {
606
606
  }), e = PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);
607
607
  return await navigator.credentials.create({ publicKey: e });
608
608
  }, tt = async () => {
609
- const t = await T();
609
+ const t = await R();
610
610
  return await f({
611
611
  webAuthnAssertion: {
612
612
  __args: {
@@ -625,11 +625,11 @@ const L = (t, e) => {
625
625
  }).then((e) => e.webAuthnRegister);
626
626
  }, rt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
627
627
  __proto__: null,
628
- assertion: T,
628
+ assertion: R,
629
629
  attestation: Q,
630
630
  login: tt,
631
631
  register: et
632
- }, Symbol.toStringTag, { value: "Module" })), st = (t = W) => y({ my: t }).then((e) => e.my), nt = (t, e, r = "") => f({ login: { __args: { username: t, password: e, code: r } } }).then((s) => s.login), ot = () => f({ logout: !0 }).then((t) => t.logout), it = (t, e, r) => f({ changeExpiredPassword: { __args: { username: t, old_password: e, new_password: r } } }).then((s) => s.changeExpiredPassword), at = (t, e) => f({ changeUserPassword: { __args: { old_password: t, new_password: e } } }).then((r) => r.changeUserPassword), ct = (t, e, r) => f({ resetPassword: { __args: { jwt: t, password: e, code: r } } }).then((s) => s.resetPassword), lt = (t, e) => f({ forgetPassword: { __args: { username: t, email: e } } }).then((r) => r.forgetPassword), ut = (t, e) => f({ forgetPasswordVerifyCode: { __args: { jwt: t, code: e } } }).then((r) => r.forgetPasswordVerifyCode), ht = (t) => y({
632
+ }, Symbol.toStringTag, { value: "Module" })), st = (t = G) => y({ my: t }).then((e) => e.my), nt = (t, e, r = "") => f({ login: { __args: { username: t, password: e, code: r } } }).then((s) => s.login), ot = () => f({ logout: !0 }).then((t) => t.logout), it = (t, e, r) => f({ changeExpiredPassword: { __args: { username: t, old_password: e, new_password: r } } }).then((s) => s.changeExpiredPassword), at = (t, e) => f({ changeUserPassword: { __args: { old_password: t, new_password: e } } }).then((r) => r.changeUserPassword), lt = (t, e, r) => f({ resetPassword: { __args: { jwt: t, password: e, code: r } } }).then((s) => s.resetPassword), ct = (t, e) => f({ forgetPassword: { __args: { username: t, email: e } } }).then((r) => r.forgetPassword), ut = (t, e) => f({ forgetPasswordVerifyCode: { __args: { jwt: t, code: e } } }).then((r) => r.forgetPasswordVerifyCode), ht = (t) => y({
633
633
  my: {
634
634
  granted: {
635
635
  __args: {
@@ -667,8 +667,8 @@ const L = (t, e) => {
667
667
  logout: ot,
668
668
  changeExpiredPassword: it,
669
669
  updatePassword: at,
670
- resetPassword: ct,
671
- forgetPassword: lt,
670
+ resetPassword: lt,
671
+ forgetPassword: ct,
672
672
  verifyCode: ut,
673
673
  grantedRights: pt,
674
674
  isGranted: ht
@@ -688,7 +688,7 @@ const L = (t, e) => {
688
688
  }
689
689
  }
690
690
  }
691
- }).then((s) => s.app.drive.files), gt = (t, e) => y({
691
+ }).then((s) => s.app.drive.files), _t = (t, e) => y({
692
692
  app: {
693
693
  drive: {
694
694
  __args: {
@@ -702,7 +702,7 @@ const L = (t, e) => {
702
702
  }
703
703
  }
704
704
  }
705
- }).then((r) => r.app.drive?.file?.base64Content), _t = (t) => ({
705
+ }).then((r) => r.app.drive?.file?.base64Content), gt = (t) => ({
706
706
  list: (e, r = $) => dt(t, e, r),
707
707
  get: (e, r = {
708
708
  name: !0,
@@ -726,7 +726,7 @@ const L = (t, e) => {
726
726
  }
727
727
  }).then((s) => s.app.drive.file),
728
728
  readFileAsBase64(e) {
729
- return gt(t, e);
729
+ return _t(t, e);
730
730
  },
731
731
  read: async (e) => {
732
732
  let r = await y({
@@ -752,10 +752,10 @@ const L = (t, e) => {
752
752
  delete: (e) => f({ lightDriveDeleteFile: { __args: { index: t, path: e } } }).then((r) => r.lightDriveDeleteFile),
753
753
  rename: (e, r) => f({ lightDriveRenameFile: { __args: { index: t, path: e, name: r } } }).then((s) => s.lightDriveRenameFile),
754
754
  move: (e, r) => f({ lightDriveMoveFile: { __args: { index: t, source: e, destination: r } } }).then((s) => s.lightDriveMoveFile)
755
- }), G = {
755
+ }), z = {
756
756
  name: !0,
757
757
  path: !0
758
- }, yt = (t, e, r = G) => y({
758
+ }, yt = (t, e, r = z) => y({
759
759
  app: {
760
760
  drive: {
761
761
  __args: { index: t },
@@ -765,20 +765,20 @@ const L = (t, e) => {
765
765
  }
766
766
  }
767
767
  }
768
- }).then((s) => s.app.drive.folders), wt = (t) => ({
769
- list: (e, r = G) => yt(t, e, r),
768
+ }).then((s) => s.app.drive.folders), mt = (t) => ({
769
+ list: (e, r = z) => yt(t, e, r),
770
770
  create: (e) => f({ lightDriveCreateFolder: { __args: { index: t, path: e } } }).then((r) => r.lightDriveCreateFolder),
771
771
  delete: (e) => f({ lightDriveDeleteFolder: { __args: { index: t, path: e } } }).then((r) => r.lightDriveDeleteFolder),
772
772
  rename: (e, r) => f({ lightDriveRenameFolder: { __args: { index: t, path: e, name: r } } }).then((s) => s.lightDriveRenameFolder)
773
- }), se = () => y({
773
+ }), ne = () => y({
774
774
  app: {
775
775
  drives: {
776
776
  index: !0,
777
777
  name: !0
778
778
  }
779
779
  }
780
- }).then((t) => t.app.drives), mt = (t) => {
781
- const e = _t(t), r = wt(t);
780
+ }).then((t) => t.app.drives), wt = (t) => {
781
+ const e = gt(t), r = mt(t);
782
782
  return {
783
783
  folders: r,
784
784
  files: e,
@@ -803,7 +803,7 @@ const L = (t, e) => {
803
803
  }
804
804
  }).then((i) => i.lightDriveUploadTempFile)
805
805
  };
806
- }, W = {
806
+ }, G = {
807
807
  user_id: !0,
808
808
  username: !0,
809
809
  first_name: !0,
@@ -817,7 +817,7 @@ const L = (t, e) => {
817
817
  deleteUser: {
818
818
  __args: { id: t }
819
819
  }
820
- }).then((e) => e.deleteUser), At = (t = W) => j("Users", t).dataPath("app.listUser").fetch(), Ot = (t, e) => f({
820
+ }).then((e) => e.deleteUser), At = (t = G) => j("Users", t).dataPath("app.listUser").fetch(), Ot = (t, e) => f({
821
821
  updateUser: {
822
822
  __args: { id: t, data: e }
823
823
  }
@@ -864,43 +864,43 @@ const L = (t, e) => {
864
864
  create: kt,
865
865
  delete: Pt
866
866
  });
867
- function z(t, e, r, s, i) {
867
+ function W(t, e, r, s, i) {
868
868
  if (!(!t || typeof t != "object"))
869
869
  for (let u in t) {
870
- const l = t[u];
871
- if (l && typeof l == "object") {
872
- if ("__args" in l) {
873
- const p = l.__args, n = {};
870
+ const c = t[u];
871
+ if (c && typeof c == "object") {
872
+ if ("__args" in c) {
873
+ const p = c.__args, n = {};
874
874
  Object.entries(p).forEach(([o, a]) => {
875
875
  if (a instanceof Array && D(a)) {
876
876
  n[o] = new b(o);
877
- let c = 0;
877
+ let l = 0;
878
878
  a.forEach((h) => {
879
- h instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + o + "." + c), s.append(i.current.toString(), h), i.current++, c++);
879
+ h instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + o + "." + l), s.append(i.current.toString(), h), i.current++, l++);
880
880
  }), e[o] = "[Upload!]!";
881
- } else a instanceof File ? (n[o] = new b(o), r[i.current] = ["variables." + o], s.append(i.current.toString(), a), e[o] = "Upload!", i.current++) : a instanceof Object && M(a) ? (n[o] = {}, Object.entries(a).forEach(([c, h]) => {
881
+ } else a instanceof File ? (n[o] = new b(o), r[i.current] = ["variables." + o], s.append(i.current.toString(), a), e[o] = "Upload!", i.current++) : a instanceof Object && N(a) ? (n[o] = {}, Object.entries(a).forEach(([l, h]) => {
882
882
  if (h instanceof Array && D(h)) {
883
- n[o][c] = new b(c);
883
+ n[o][l] = new b(l);
884
884
  let d = 0;
885
- h.forEach((g) => {
886
- g instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + c + "." + d), s.append(i.current.toString(), g), i.current++, d++);
887
- }), e[c] = "[Upload!]!";
888
- } else h instanceof File ? (n[o][c] = new b(c), r[i.current] = ["variables." + c], s.append(i.current.toString(), h), e[c] = "Upload!", i.current++) : n[o][c] = h;
885
+ h.forEach((_) => {
886
+ _ instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + l + "." + d), s.append(i.current.toString(), _), i.current++, d++);
887
+ }), e[l] = "[Upload!]!";
888
+ } else h instanceof File ? (n[o][l] = new b(l), r[i.current] = ["variables." + l], s.append(i.current.toString(), h), e[l] = "Upload!", i.current++) : n[o][l] = h;
889
889
  })) : a != null && (n[o] = a);
890
- }), l.__args = n;
890
+ }), c.__args = n;
891
891
  }
892
- z(l, e, r, s, i);
892
+ W(c, e, r, s, i);
893
893
  }
894
894
  }
895
895
  }
896
896
  const f = async (t) => {
897
- const { axios: e } = N(), r = t, s = new FormData();
897
+ const { axios: e } = M(), r = t, s = new FormData();
898
898
  let i = !1;
899
- const u = {}, l = {};
900
- z(r, u, l, s, { current: 0 }), i = Object.keys(u).length > 0, i && (r.__variables = u);
899
+ const u = {}, c = {};
900
+ W(r, u, c, s, { current: 0 }), i = Object.keys(u).length > 0, i && (r.__variables = u);
901
901
  let n = null;
902
902
  const a = q({ mutation: r });
903
- if (i ? (s.append("map", JSON.stringify(l)), s.append("operations", JSON.stringify({
903
+ if (i ? (s.append("map", JSON.stringify(c)), s.append("operations", JSON.stringify({
904
904
  query: a
905
905
  })), n = await e.post("", s)) : n = await e.post("", {
906
906
  query: a
@@ -913,11 +913,11 @@ const f = async (t) => {
913
913
  lightFSCreateFolder: {
914
914
  __args: { location: t }
915
915
  }
916
- }).then((e) => e.lightFSCreateFolder), Nt = (t) => f({
916
+ }).then((e) => e.lightFSCreateFolder), Mt = (t) => f({
917
917
  lightFSDeleteFolder: {
918
918
  __args: { location: t }
919
919
  }
920
- }).then((e) => e.lightFSDeleteFolder), Mt = (t, e) => f({
920
+ }).then((e) => e.lightFSDeleteFolder), Nt = (t, e) => f({
921
921
  lightFSRenameFolder: {
922
922
  __args: { location: t, newName: e }
923
923
  }
@@ -933,11 +933,11 @@ const f = async (t) => {
933
933
  lightFSUploadFile: {
934
934
  __args: { location: t, file: e }
935
935
  }
936
- }).then((r) => r.lightFSUploadFile), Rt = (t) => f({
936
+ }).then((r) => r.lightFSUploadFile), Tt = (t) => f({
937
937
  lightFSDeleteFile: {
938
938
  __args: { location: t }
939
939
  }
940
- }).then((e) => e.lightFSDeleteFile), Tt = (t, e) => f({
940
+ }).then((e) => e.lightFSDeleteFile), Rt = (t, e) => f({
941
941
  lightFSMove: {
942
942
  __args: { from: t, to: e }
943
943
  }
@@ -972,7 +972,7 @@ const f = async (t) => {
972
972
  }
973
973
  }
974
974
  }).then((s) => s.app.fs.find);
975
- }, Gt = (t) => y({
975
+ }, zt = (t) => y({
976
976
  app: {
977
977
  fs: {
978
978
  node: {
@@ -1001,32 +1001,51 @@ const f = async (t) => {
1001
1001
  }
1002
1002
  }
1003
1003
  }
1004
- }).then((r) => r.app.fs.node), Wt = (t) => y({
1004
+ }).then((r) => r.app.fs.node), Gt = (t, e = "text") => y({
1005
1005
  app: {
1006
1006
  fs: {
1007
1007
  node: {
1008
1008
  __args: { location: t },
1009
- __on: [
1010
- {
1011
- __typeName: "File",
1012
- content: !0
1013
- }
1014
- ]
1009
+ __typename: !0,
1010
+ // 獲取類型以便後續判斷
1011
+ __on: [{
1012
+ __typeName: "File",
1013
+ ...e === "text" ? { content: !0 } : { base64Content: !0 }
1014
+ }]
1015
1015
  }
1016
1016
  }
1017
1017
  }
1018
- }).then((e) => e.app.fs.node.content), ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1018
+ }).then((r) => {
1019
+ const s = r.app.fs.node;
1020
+ return s?.__typename === "File" ? e === "text" ? s.content : s.base64Content : null;
1021
+ }), Wt = (t, e) => f({
1022
+ lightFSUploadBase64: {
1023
+ __args: { location: t, base64: e },
1024
+ // 回傳 File 物件的欄位,方便前端立即顯示
1025
+ __typename: !0,
1026
+ name: !0,
1027
+ path: !0,
1028
+ location: !0,
1029
+ __on: [{
1030
+ __typename: "File",
1031
+ size: !0,
1032
+ mimeType: !0,
1033
+ lastModified: !0
1034
+ }]
1035
+ }
1036
+ }).then((r) => r.lightFSUploadBase64), oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1019
1037
  __proto__: null,
1020
1038
  createFolder: qt,
1021
- deleteFile: Rt,
1022
- deleteFolder: Nt,
1039
+ deleteFile: Tt,
1040
+ deleteFolder: Mt,
1023
1041
  exists: Qt,
1024
1042
  find: $t,
1025
- list: Gt,
1026
- move: Tt,
1027
- read: Wt,
1043
+ list: zt,
1044
+ move: Rt,
1045
+ readFile: Gt,
1028
1046
  renameFile: Bt,
1029
- renameFolder: Mt,
1047
+ renameFolder: Nt,
1048
+ uploadBase64: Wt,
1030
1049
  uploadFile: Lt,
1031
1050
  writeFile: Jt
1032
1051
  }, Symbol.toStringTag, { value: "Module" })), v = (t) => {
@@ -1046,7 +1065,7 @@ const f = async (t) => {
1046
1065
  }
1047
1066
  e[r] = v(s);
1048
1067
  }), e);
1049
- }, zt = (t) => v(t), oe = (t) => {
1068
+ }, Ht = (t) => v(t), ie = (t) => {
1050
1069
  const e = typeof window > "u";
1051
1070
  let r = [];
1052
1071
  const s = H.create({
@@ -1054,19 +1073,19 @@ const f = async (t) => {
1054
1073
  withCredentials: !0
1055
1074
  });
1056
1075
  let i = !1, u = [];
1057
- const l = (o, a = null) => {
1058
- u.forEach((c) => {
1059
- o ? c.reject(o) : c.resolve(a);
1076
+ const c = (o, a = null) => {
1077
+ u.forEach((l) => {
1078
+ o ? l.reject(o) : l.resolve(a);
1060
1079
  }), u = [];
1061
1080
  };
1062
1081
  s.interceptors.response.use(
1063
1082
  (o) => {
1064
1083
  const a = o.data.errors;
1065
- if (a && a.some((c) => c.extensions?.code === "TOKEN_EXPIRED")) {
1066
- const c = o.config;
1084
+ if (a && a.some((l) => l.extensions?.code === "TOKEN_EXPIRED")) {
1085
+ const l = o.config;
1067
1086
  return i ? new Promise((h, d) => {
1068
1087
  u.push({ resolve: h, reject: d });
1069
- }).then(() => s(c)).catch((h) => Promise.reject(h)) : (i = !0, p().then(() => (i = !1, l(null), s(c))).catch((h) => (i = !1, l(h), Promise.reject(h))));
1088
+ }).then(() => s(l)).catch((h) => Promise.reject(h)) : (i = !0, p().then(() => (i = !1, c(null), s(l))).catch((h) => (i = !1, c(h), Promise.reject(h))));
1070
1089
  }
1071
1090
  return o;
1072
1091
  },
@@ -1077,14 +1096,14 @@ const f = async (t) => {
1077
1096
  }
1078
1097
  e && (s.interceptors.request.use((o) => (o.withCredentials = !0, r.length > 0 && (o.headers.Cookie = r.join("; ")), o)), s.interceptors.response.use((o) => {
1079
1098
  if (o.headers["set-cookie"]) {
1080
- const a = o.headers["set-cookie"].map((h) => h.split(";")[0]), c = /* @__PURE__ */ new Map();
1099
+ const a = o.headers["set-cookie"].map((h) => h.split(";")[0]), l = /* @__PURE__ */ new Map();
1081
1100
  r.forEach((h) => {
1082
1101
  const d = h.split("=")[0];
1083
- c.set(d, h);
1102
+ l.set(d, h);
1084
1103
  }), a.forEach((h) => {
1085
1104
  const d = h.split("=")[0];
1086
- c.set(d, h);
1087
- }), r = Array.from(c.values());
1105
+ l.set(d, h);
1106
+ }), r = Array.from(l.values());
1088
1107
  }
1089
1108
  return o;
1090
1109
  }));
@@ -1103,91 +1122,91 @@ const f = async (t) => {
1103
1122
  },
1104
1123
  roles: Ut(),
1105
1124
  collect: (o, a) => {
1106
- const c = L(o, a);
1107
- return c.data_path = P(o).getDataPath(), c;
1125
+ const l = L(o, a);
1126
+ return l.data_path = P(o).getDataPath(), l;
1108
1127
  },
1109
1128
  list: (o, a) => j(o, a).dataPath(P(o).getDataPath()),
1110
- drive: mt,
1129
+ drive: wt,
1111
1130
  async collects(o) {
1112
- const a = {}, c = {};
1131
+ const a = {}, l = {};
1113
1132
  for (const d in o) {
1114
- const g = o[d].getQueryPayload();
1115
- c[d] = g.data_path, a[d] = {};
1116
- const F = g.data_path.split(".");
1117
- let m = F[F.length - 1], w = a[d];
1133
+ const _ = o[d].getQueryPayload();
1134
+ l[d] = _.data_path, a[d] = {};
1135
+ const F = _.data_path.split(".");
1136
+ let w = F[F.length - 1], m = a[d];
1118
1137
  for (const C of F) {
1119
- if (C === m) {
1120
- w[C] = g.query;
1138
+ if (C === w) {
1139
+ m[C] = _.query;
1121
1140
  break;
1122
1141
  }
1123
- w[C] = w[C] || {};
1142
+ m[C] = m[C] || {};
1124
1143
  }
1125
1144
  a[d].__aliasFor = F[0];
1126
1145
  }
1127
1146
  const h = await y(a);
1128
1147
  for (const d in o) {
1129
- const g = c[d].split(".");
1130
- let F = g[g.length - 1], m = h[d];
1131
- for (const w of g) {
1132
- if (w === F) {
1133
- o[d]._batchData = h[d][w];
1148
+ const _ = l[d].split(".");
1149
+ let F = _[_.length - 1], w = h[d];
1150
+ for (const m of _) {
1151
+ if (m === F) {
1152
+ o[d]._batchData = h[d][m];
1134
1153
  break;
1135
1154
  }
1136
- m[w] = m[w] || {};
1155
+ w[m] = w[m] || {};
1137
1156
  }
1138
1157
  }
1139
1158
  return o;
1140
1159
  }
1141
1160
  };
1142
1161
  return Y(n), n;
1143
- }, ie = j;
1162
+ }, ae = j;
1144
1163
  export {
1145
1164
  D as arrayHasFile,
1146
1165
  ft as auth,
1147
1166
  it as changeExpiredPassword,
1148
- te as clearModels,
1149
- oe as createClient,
1167
+ ee as clearModels,
1168
+ ie as createClient,
1150
1169
  L as createCollection,
1151
- Vt as createFileFromBase64,
1152
- It as createFileFromBase85,
1170
+ It as createFileFromBase64,
1171
+ Kt as createFileFromBase85,
1153
1172
  B as createFileFromString,
1154
1173
  j as createList,
1155
1174
  kt as createRole,
1156
1175
  Ft as createUser,
1157
- W as defaultUserFields,
1158
- R as defineModel,
1159
- ee as defineModels,
1176
+ G as defaultUserFields,
1177
+ T as defineModel,
1178
+ re as defineModels,
1160
1179
  Pt as deleteRole,
1161
1180
  bt as deleteUser,
1162
- lt as forgetPassword,
1163
- ne as fs,
1164
- N as getApiClient,
1165
- Zt as getApiClientOptional,
1181
+ ct as forgetPassword,
1182
+ oe as fs,
1183
+ M as getApiClient,
1184
+ Vt as getApiClientOptional,
1166
1185
  Ct as getConfig,
1167
1186
  st as getCurrentUser,
1168
- mt as getDrive,
1187
+ wt as getDrive,
1169
1188
  pt as getGrantedRights,
1170
1189
  P as getModel,
1171
- Kt as hasModel,
1190
+ xt as hasModel,
1172
1191
  ht as isGranted,
1173
- ie as list,
1174
- se as listDrives,
1192
+ ae as list,
1193
+ ne as listDrives,
1175
1194
  dt as listFiles,
1176
1195
  yt as listFolders,
1177
- xt as listModels,
1178
- re as listPermissions,
1196
+ te as listModels,
1197
+ se as listPermissions,
1179
1198
  jt as listRoles,
1180
1199
  At as listUsers,
1181
1200
  nt as login,
1182
1201
  ot as logout,
1183
1202
  f as mutation,
1184
- M as objectHasFile,
1203
+ N as objectHasFile,
1185
1204
  y as query,
1186
- gt as readFileAsBase64,
1187
- ct as resetPassword,
1205
+ _t as readFileAsBase64,
1206
+ lt as resetPassword,
1188
1207
  Et as sendMail,
1189
1208
  Y as setApiClient,
1190
- zt as toQuery,
1209
+ Ht as toQuery,
1191
1210
  at as updatePassword,
1192
1211
  Ot as updateUser,
1193
1212
  ut as verifyCode,
@@ -1 +1 @@
1
- (function(h,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("json-to-graphql-query"),require("collect.js"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","collect.js","axios"],w):(h=typeof globalThis<"u"?globalThis:h||self,w(h.light={},h.jsonToGraphqlQuery,h.collect,h.axios))})(this,(function(h,w,U,wt){"use strict";function v(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 E(t,e,r=".",s){if(!v(e))return E(t,{},r,s);const o=Object.assign({},e);for(const u in t){if(u==="__proto__"||u==="constructor")continue;const c=t[u];c!=null&&(s&&s(o,u,c,r)||(Array.isArray(c)&&Array.isArray(o[u])?o[u]=[...c,...o[u]]:v(c)&&v(o[u])?o[u]=E(c,o[u],(r?`${r}.`:"")+u.toString(),s):o[u]=c))}return o}function mt(t){return(...e)=>e.reduce((r,s)=>E(r,s,"",t),{})}const C=mt();let P=null;const J=t=>{P=t},M=()=>{if(!P)throw new Error("Api client not initialized. Call setApiClient() first.");return P},bt=()=>P;function D(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||t[e]instanceof Array&&D(t[e]))return!0;return!1}function At(t){t="<~"+t+"~>";var e,r,s,o,u,c=String,d=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=[],o=0,u=t.length;u>o;o+=5)r=52200625*(t.charCodeAt(o)-33)+614125*(t.charCodeAt(o+1)-33)+7225*(t.charCodeAt(o+2)-33)+85*(t.charCodeAt(o+3)-33)+(t.charCodeAt(o+4)-33),s.push(d&r>>24,d&r>>16,d&r>>8,d&r);return(function(n,i){for(var a=i;a>0;a--)n.pop()})(s,e.length),c.fromCharCode.apply(c,s)}const N=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const o=new Uint8Array(e.length);for(let d=0;d<e.length;d++)o[d]=e.charCodeAt(d);const u=new Blob([o],{type:s});return URL.createObjectURL(u)};return{getContent:()=>e,getURL:r,download:s=>{const o=document.createElement("a");o.download=s,o.href=r(),document.body.appendChild(o),o.click(),document.body.removeChild(o)},open:s=>{window.open(r(s),"_blank")}}},Ct=t=>N(atob(t)),Ot=t=>N(At(t));function $(t,e,r,s,o){if(!(!t||typeof t!="object"))for(let u in t){const c=t[u];if(c&&typeof c=="object"){if("__args"in c){const d=c.__args,n={};Object.entries(d).forEach(([i,a])=>{if(a instanceof Array&&D(a)){n[i]=new w.VariableType(i);let l=0;a.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),s.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else a instanceof File?(n[i]=new w.VariableType(i),r[o.current]=["variables."+i],s.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&q(a)?(n[i]={},Object.entries(a).forEach(([l,f])=>{if(f instanceof Array&&D(f)){n[i][l]=new w.VariableType(l);let g=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+g),s.append(o.current.toString(),_),o.current++,g++)}),e[l]="[Upload!]!"}else f instanceof File?(n[i][l]=new w.VariableType(l),r[o.current]=["variables."+l],s.append(o.current.toString(),f),e[l]="Upload!",o.current++):n[i][l]=f})):a!=null&&(n[i]=a)}),c.__args=n}$(c,e,r,s,o)}}}const F=async t=>{const{axios:e}=M(),r=t,s=new FormData;let o=!1;const u={},c={};$(r,u,c,s,{current:0}),o=Object.keys(u).length>0,o&&(r.__variables=u);let n=null;const i={query:r},a=w.jsonToGraphQLQuery(i);if(o?(s.append("map",JSON.stringify(c)),s.append("operations",JSON.stringify({query:a})),n=await e.post("",s)):n=await e.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data};function S(t,e){let r,s=[],o,u;const c=n=>!n||typeof n!="object"?!1:Object.values(n).some(i=>i&&typeof i=="object"&&Object.keys(i).some(a=>a.startsWith("_"))),d=()=>s.length===0?(s.unshift({}),s[0]):(c(s[0])&&s.unshift({}),s[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const i=await this.limit(1).fetch();return Array.isArray(i)&&i.length>0?i[0]:null},async fetchWithMeta(){let i=await F(this.toQuery(!0));if(u){const a=u.split(".");for(const l of a)i=i[l];return i}return i[`list${t}`]},async fetch(){let i=await F(this.toQuery());if(u){const a=u.split(".");for(const l of a)i=i[l];return i.data}return i[`list${t}`].data},dataPath(n){return n&&typeof n=="string"&&(u=n),this},sort(n){return n&&typeof n=="string"&&(o=n),this},filters(n){return n&&typeof n=="object"&&(s=[n]),this},where(n,i,a){const l=(f,g,_)=>{const b={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[g];b&&s.push({[f]:{[b]:_}})};if(a!==void 0)l(n,String(i),a);else{const f=d(),g=C(f,{[n]:i});s[0]=g}return this},whereContains(n,i){if(n&&typeof n=="string"){const a=d(),l={_contains:i};a[n]?Array.isArray(a[n])?a[n].push(l):a[n]=[a[n],l]:a[n]=[l],s[0]=a}return this},whereIn(n,i){if(n&&typeof n=="string"&&Array.isArray(i)){const a=d(),l={_in:i};a[n]?Array.isArray(a[n])?a[n].push(l):a[n]=[a[n],l]:a[n]=[l],s[0]=a}return this},whereBetween(n,i,a){if(n&&typeof n=="string"){const l=d(),f={_between:[i,a]};l[n]?Array.isArray(l[n])?l[n].push(f):l[n]=[l[n],f]:l[n]=f,s[0]=l}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(r=C(r||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(r=C(r||{},{offset:n})),this},toQuery(n=!1){let i;const a=s.length>0&&Object.keys(s[0]||{}).length>0,l=a?1:0,f=s.length>l;a&&f?i=s:f?i=s.slice(l):a&&(i=s[0]);const g=C(o?{sort:o}:{},i?{filters:i}:{}),_={data:{...e}};if(r&&(_.data.__args=r),Object.keys(g).length>0&&(_.__args=g),n&&(_.meta={total:!0,key:!0,name:!0}),u){const A=u.split(".");let b=_;for(let m=A.length-1;m>=0;m--)b={[A[m]]:b};return b}return{[`list${t}`]:_}}}}const Dt="list",St=["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"],Pt=["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 y{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}y.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}},y.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},y.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},y.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},U().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),y.prototype.fetchData=async function(){try{if(this._batchData){const d=this._batchData;return this.meta=d.meta,U(d.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,o=e[e.length-1];for(const d of e){if(d===o){s[d]=t;break}s[d]={},s=s[d]}let c=await F(r);for(const d of e)c=c[d];return this.meta=c.meta,U(c.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},y.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},y.prototype.all=async function(){return(await this.processData()).all()};for(const t of St)y.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Pt)y.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};y.prototype.average=y.prototype.avg,y.prototype.first=async function(){return this.take(1),(await this.processData()).first()},y.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},y.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],o=t[2];switch(s){case"==":this.filters[r]=o;break;case"<":this.filters[r]={lt:o};break;case"<=":this.filters[r]={lte:o};break;case">":this.filters[r]={gt:o};break;case">=":this.filters[r]={gte:o};break;case"!==":this.filters[r]={ne:o};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},y.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},y.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)},y.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},y.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},y.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},y.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},y.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},y.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},y.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},y.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)},y.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const B=(t,e)=>{const r=new y(e);return r.data_path=Dt+t,r},jt=(t,e={})=>{const r=e;let s="list"+t;const o=u=>r[u]?r[u]:null;return{field:o,$fields:r,setDataPath(u){return s=u,s},getDataPath(){return s},gqlFields(u){let c={};for(const d of u)if(typeof d=="string"){const n=o(d);n&&(c=C(c,n.gqlField?typeof n.gqlField=="string"?{[n.gqlField]:!0}:n.gqlField:{[n.name||d]:!0}))}else typeof d=="object"&&(c=C(c,d));return c},update(u,c){return p({["update"+t]:{__args:{id:u,data:c}}}).then(d=>d["update"+t])},async delete(u){return p({["delete"+t]:{__args:{id:u}}}).then(c=>c["delete"+t])},add(u){return p({["add"+t]:{__args:{data:u}}}).then(c=>c["add"+t])},fields(u){let c=[];for(let d of u){const n=o(d);n&&c.push(n)}return c},async get(u,c){const d=B(t,Ft(c));for(const[n,i]of Object.entries(u))d.where(n,"==",i);return await d.first()},list(u){let c=u;const d={};Object.entries(u).forEach(([a])=>{r[a]&&(d[a]=r[a],r[a].gqlField&&(delete c[a],c=C(c,r[a].gqlField)),r[a].gql&&(delete c[a],c=C(c,r[a].gql)))});const n=S(t,c).dataPath(s),i=n.fetch.bind(n);return{...n,async fetch(){return(await i()).map(l=>{const f={...l};return Object.entries(d).forEach(([g,_])=>{_.field&&typeof _.field=="function"&&(f[g]=_.field(l[g],l))}),f})},async fetchFirst(){const l=await n.fetchFirst.bind(n)();if(!l)return l;const f={...l};return Object.entries(d).forEach(([g,_])=>{_.field&&typeof _.field=="function"&&(f[g]=_.field(l[g],l))}),f}}}}},O={},R=(t,e)=>{const r=jt(t,e);return O[t]=r,r},j=t=>O[t]?O[t]:R(t,{}),kt=t=>!!O[t],Ut=()=>Object.keys(O),vt=()=>{Object.keys(O).forEach(t=>delete O[t])},Et=t=>{Object.entries(t).forEach(([e,r])=>{R(e,r)})},Mt=()=>F({app:{permissions:!0}}).then(t=>t.app.permissions),W=async()=>{const{app:t}=await F({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},z=async()=>{const{app:t}=await F({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},Q=Object.freeze(Object.defineProperty({__proto__:null,assertion:W,attestation:z,login:async()=>{const t=await W();return await p({webAuthnAssertion:{__args:{assertion:t.toJSON()}}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await z();return await p({webAuthnRegister:{__args:{registration:t.toJSON()}}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),G=(t=L)=>F({my:t}).then(e=>e.my),H=(t,e,r="")=>p({login:{__args:{username:t,password:e,code:r}}}).then(s=>s.login),V=()=>p({logout:!0}).then(t=>t.logout),X=(t,e,r)=>p({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(s=>s.changeExpiredPassword),Y=(t,e)=>p({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),Z=(t,e,r)=>p({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(s=>s.resetPassword),I=(t,e)=>p({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),K=(t,e)=>p({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),x=t=>F({my:{granted:{__args:{right:t}}}}).then(e=>e.my.granted),tt=t=>F({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),et={getCurrentUser:G,webAuthn:Q,google:{unlink:()=>p({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>p({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>p({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>p({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>p({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>p({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>p({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>p({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>p({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:H,logout:V,changeExpiredPassword:X,updatePassword:Y,resetPassword:Z,forgetPassword:I,verifyCode:K,grantedRights:tt,isGranted:x},rt={name:!0,path:!0,size:!0,mime:!0,url:!0},st=(t,e,r=rt)=>F({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(s=>s.app.drive.files),nt=(t,e)=>F({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}}).then(r=>r.app.drive?.file?.base64Content),qt=t=>({list:(e,r=rt)=>st(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>F({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(s=>s.app.drive.file),readFileAsBase64(e){return nt(t,e)},read:async e=>{let r=await F({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>p({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(s=>s.lightDriveWriteFile),delete:e=>p({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>p({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(s=>s.lightDriveRenameFile),move:(e,r)=>p({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(s=>s.lightDriveMoveFile)}),it={name:!0,path:!0},ot=(t,e,r=it)=>F({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(s=>s.app.drive.folders),Nt=t=>({list:(e,r=it)=>ot(t,e,r),create:e=>p({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>p({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>p({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(s=>s.lightDriveRenameFolder)}),Bt=()=>F({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),at=t=>{const e=qt(t),r=Nt(t);return{folders:r,files:e,listFiles:e.list,getFile:e.get,readFile:e.read,writeFile:e.write,deleteFile:e.delete,renameFile:e.rename,moveFile:e.move,listFolders:r.list,createFolder:r.create,deleteFolder:r.delete,renameFolder:r.rename,uploadTempFile:s=>p({lightDriveUploadTempFile:{__args:{index:t,file:s},name:!0,path:!0,size:!0,mime:!0}}).then(o=>o.lightDriveUploadTempFile)}},L={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},lt=t=>p({addUser:{__args:t}}).then(e=>e.addUser),ct=t=>p({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),ut=(t=L)=>S("Users",t).dataPath("app.listUser").fetch(),ht=(t,e)=>p({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Rt={list:ut,create:lt,delete:ct,update:ht},ft=t=>F({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Lt={name:!0},dt=(t=Lt)=>F({app:{roles:t}}).then(e=>e.app.roles),pt=(t,e)=>p({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),gt=t=>p({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),Tt=()=>({list:dt,create:pt,delete:gt});function _t(t,e,r,s,o){if(!(!t||typeof t!="object"))for(let u in t){const c=t[u];if(c&&typeof c=="object"){if("__args"in c){const d=c.__args,n={};Object.entries(d).forEach(([i,a])=>{if(a instanceof Array&&D(a)){n[i]=new w.VariableType(i);let l=0;a.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),s.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else a instanceof File?(n[i]=new w.VariableType(i),r[o.current]=["variables."+i],s.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&q(a)?(n[i]={},Object.entries(a).forEach(([l,f])=>{if(f instanceof Array&&D(f)){n[i][l]=new w.VariableType(l);let g=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+g),s.append(o.current.toString(),_),o.current++,g++)}),e[l]="[Upload!]!"}else f instanceof File?(n[i][l]=new w.VariableType(l),r[o.current]=["variables."+l],s.append(o.current.toString(),f),e[l]="Upload!",o.current++):n[i][l]=f})):a!=null&&(n[i]=a)}),c.__args=n}_t(c,e,r,s,o)}}}const p=async t=>{const{axios:e}=M(),r=t,s=new FormData;let o=!1;const u={},c={};_t(r,u,c,s,{current:0}),o=Object.keys(u).length>0,o&&(r.__variables=u);let n=null;const i={mutation:r},a=w.jsonToGraphQLQuery(i);if(o?(s.append("map",JSON.stringify(c)),s.append("operations",JSON.stringify({query:a})),n=await e.post("",s)):n=await e.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data},yt=(t,e,r)=>p({sendMail:{__args:{email:t,subject:e,message:r}}}).then(s=>s.sendMail),Jt={send:yt},$t=Object.freeze(Object.defineProperty({__proto__:null,createFolder:t=>p({lightFSCreateFolder:{__args:{location:t}}}).then(e=>e.lightFSCreateFolder),deleteFile:t=>p({lightFSDeleteFile:{__args:{location:t}}}).then(e=>e.lightFSDeleteFile),deleteFolder:t=>p({lightFSDeleteFolder:{__args:{location:t}}}).then(e=>e.lightFSDeleteFolder),exists:t=>F({app:{fs:{exists:{__args:{location:t}}}}}).then(e=>e.app.fs.exists),find:(t,e)=>{const r={};return t&&(r.search=t),e&&(r.label=e),F({app:{fs:{find:{__args:r,__typename:!0,name:!0,lastModified:!0,location:!0,path:!0,__on:[{__typeName:"File",size:!0,mimeType:!0},{__typeName:"Folder"}]}}}}).then(s=>s.app.fs.find)},list:t=>F({app:{fs:{node:{__args:{location:t},__typename:!0,__on:[{__typeName:"Folder",name:!0,location:!0,path:!0,children:{__typename:!0,name:!0,lastModified:!0,location:!0,path:!0,__on:[{__typeName:"File",size:!0,mimeType:!0},{__typeName:"Folder"}]}}]}}}}).then(r=>r.app.fs.node),move:(t,e)=>p({lightFSMove:{__args:{from:t,to:e}}}).then(r=>r.lightFSMove),read:t=>F({app:{fs:{node:{__args:{location:t},__on:[{__typeName:"File",content:!0}]}}}}).then(e=>e.app.fs.node.content),renameFile:(t,e)=>p({lightFSRenameFile:{__args:{location:t,newName:e}}}).then(r=>r.lightFSRenameFile),renameFolder:(t,e)=>p({lightFSRenameFolder:{__args:{location:t,newName:e}}}).then(r=>r.lightFSRenameFolder),uploadFile:(t,e)=>p({lightFSUploadFile:{__args:{location:t,file:e}}}).then(r=>r.lightFSUploadFile),writeFile:(t,e)=>p({lightFSWriteFile:{__args:{location:t,content:e}}}).then(r=>r.lightFSWriteFile)},Symbol.toStringTag,{value:"Module"})),T=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(T(r)).forEach(([s,o])=>{e[s]=o})}),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]=T(s)}),e)},Ft=t=>T(t),Wt=t=>{const e=typeof window>"u";let r=[];const s=wt.create({baseURL:t,withCredentials:!0});let o=!1,u=[];const c=(i,a=null)=>{u.forEach(l=>{i?l.reject(i):l.resolve(a)}),u=[]};s.interceptors.response.use(i=>{const a=i.data.errors;if(a&&a.some(l=>l.extensions?.code==="TOKEN_EXPIRED")){const l=i.config;return o?new Promise((f,g)=>{u.push({resolve:f,reject:g})}).then(()=>s(l)).catch(f=>Promise.reject(f)):(o=!0,d().then(()=>(o=!1,c(null),s(l))).catch(f=>(o=!1,c(f),Promise.reject(f))))}return i},i=>Promise.reject(i));function d(){return s.post("/refresh_token")}e&&(s.interceptors.request.use(i=>(i.withCredentials=!0,r.length>0&&(i.headers.Cookie=r.join("; ")),i)),s.interceptors.response.use(i=>{if(i.headers["set-cookie"]){const a=i.headers["set-cookie"].map(f=>f.split(";")[0]),l=new Map;r.forEach(f=>{const g=f.split("=")[0];l.set(g,f)}),a.forEach(f=>{const g=f.split("=")[0];l.set(g,f)}),r=Array.from(l.values())}return i}));const n={post:s.post,baseURL:t,axios:s,auth:et,mutation:p,query:F,config:ft,mail:Jt,users:Rt,model(i){return j(i)},roles:Tt(),collect:(i,a)=>{const l=B(i,a);return l.data_path=j(i).getDataPath(),l},list:(i,a)=>S(i,a).dataPath(j(i).getDataPath()),drive:at,async collects(i){const a={},l={};for(const g in i){const _=i[g].getQueryPayload();l[g]=_.data_path,a[g]={};const A=_.data_path.split(".");let b=A[A.length-1],m=a[g];for(const k of A){if(k===b){m[k]=_.query;break}m[k]=m[k]||{}}a[g].__aliasFor=A[0]}const f=await F(a);for(const g in i){const _=l[g].split(".");let A=_[_.length-1],b=f[g];for(const m of _){if(m===A){i[g]._batchData=f[g][m];break}b[m]=b[m]||{}}}return i}};return J(n),n},zt=S;h.arrayHasFile=D,h.auth=et,h.changeExpiredPassword=X,h.clearModels=vt,h.createClient=Wt,h.createCollection=B,h.createFileFromBase64=Ct,h.createFileFromBase85=Ot,h.createFileFromString=N,h.createList=S,h.createRole=pt,h.createUser=lt,h.defaultUserFields=L,h.defineModel=R,h.defineModels=Et,h.deleteRole=gt,h.deleteUser=ct,h.forgetPassword=I,h.fs=$t,h.getApiClient=M,h.getApiClientOptional=bt,h.getConfig=ft,h.getCurrentUser=G,h.getDrive=at,h.getGrantedRights=tt,h.getModel=j,h.hasModel=kt,h.isGranted=x,h.list=zt,h.listDrives=Bt,h.listFiles=st,h.listFolders=ot,h.listModels=Ut,h.listPermissions=Mt,h.listRoles=dt,h.listUsers=ut,h.login=H,h.logout=V,h.mutation=p,h.objectHasFile=q,h.query=F,h.readFileAsBase64=nt,h.resetPassword=Z,h.sendMail=yt,h.setApiClient=J,h.toQuery=Ft,h.updatePassword=Y,h.updateUser=ht,h.verifyCode=K,h.webAuthn=Q,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(h,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("json-to-graphql-query"),require("collect.js"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","collect.js","axios"],m):(h=typeof globalThis<"u"?globalThis:h||self,m(h.light={},h.jsonToGraphqlQuery,h.collect,h.axios))})(this,(function(h,m,k,mt){"use strict";function v(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 E(t,e,r=".",s){if(!v(e))return E(t,{},r,s);const o=Object.assign({},e);for(const u in t){if(u==="__proto__"||u==="constructor")continue;const c=t[u];c!=null&&(s&&s(o,u,c,r)||(Array.isArray(c)&&Array.isArray(o[u])?o[u]=[...c,...o[u]]:v(c)&&v(o[u])?o[u]=E(c,o[u],(r?`${r}.`:"")+u.toString(),s):o[u]=c))}return o}function wt(t){return(...e)=>e.reduce((r,s)=>E(r,s,"",t),{})}const C=wt();let P=null;const J=t=>{P=t},M=()=>{if(!P)throw new Error("Api client not initialized. Call setApiClient() first.");return P},bt=()=>P;function D(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function B(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&D(t[e]))return!0;return!1}function At(t){t="<~"+t+"~>";var e,r,s,o,u,c=String,d=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=[],o=0,u=t.length;u>o;o+=5)r=52200625*(t.charCodeAt(o)-33)+614125*(t.charCodeAt(o+1)-33)+7225*(t.charCodeAt(o+2)-33)+85*(t.charCodeAt(o+3)-33)+(t.charCodeAt(o+4)-33),s.push(d&r>>24,d&r>>16,d&r>>8,d&r);return(function(n,i){for(var a=i;a>0;a--)n.pop()})(s,e.length),c.fromCharCode.apply(c,s)}const q=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const o=new Uint8Array(e.length);for(let d=0;d<e.length;d++)o[d]=e.charCodeAt(d);const u=new Blob([o],{type:s});return URL.createObjectURL(u)};return{getContent:()=>e,getURL:r,download:s=>{const o=document.createElement("a");o.download=s,o.href=r(),document.body.appendChild(o),o.click(),document.body.removeChild(o)},open:s=>{window.open(r(s),"_blank")}}},Ct=t=>q(atob(t)),Ot=t=>q(At(t));function $(t,e,r,s,o){if(!(!t||typeof t!="object"))for(let u in t){const c=t[u];if(c&&typeof c=="object"){if("__args"in c){const d=c.__args,n={};Object.entries(d).forEach(([i,a])=>{if(a instanceof Array&&D(a)){n[i]=new m.VariableType(i);let l=0;a.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),s.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else a instanceof File?(n[i]=new m.VariableType(i),r[o.current]=["variables."+i],s.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&B(a)?(n[i]={},Object.entries(a).forEach(([l,f])=>{if(f instanceof Array&&D(f)){n[i][l]=new m.VariableType(l);let g=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+g),s.append(o.current.toString(),_),o.current++,g++)}),e[l]="[Upload!]!"}else f instanceof File?(n[i][l]=new m.VariableType(l),r[o.current]=["variables."+l],s.append(o.current.toString(),f),e[l]="Upload!",o.current++):n[i][l]=f})):a!=null&&(n[i]=a)}),c.__args=n}$(c,e,r,s,o)}}}const F=async t=>{const{axios:e}=M(),r=t,s=new FormData;let o=!1;const u={},c={};$(r,u,c,s,{current:0}),o=Object.keys(u).length>0,o&&(r.__variables=u);let n=null;const i={query:r},a=m.jsonToGraphQLQuery(i);if(o?(s.append("map",JSON.stringify(c)),s.append("operations",JSON.stringify({query:a})),n=await e.post("",s)):n=await e.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data};function S(t,e){let r,s=[],o,u;const c=n=>!n||typeof n!="object"?!1:Object.values(n).some(i=>i&&typeof i=="object"&&Object.keys(i).some(a=>a.startsWith("_"))),d=()=>s.length===0?(s.unshift({}),s[0]):(c(s[0])&&s.unshift({}),s[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const i=await this.limit(1).fetch();return Array.isArray(i)&&i.length>0?i[0]:null},async fetchWithMeta(){let i=await F(this.toQuery(!0));if(u){const a=u.split(".");for(const l of a)i=i[l];return i}return i[`list${t}`]},async fetch(){let i=await F(this.toQuery());if(u){const a=u.split(".");for(const l of a)i=i[l];return i.data}return i[`list${t}`].data},dataPath(n){return n&&typeof n=="string"&&(u=n),this},sort(n){return n&&typeof n=="string"&&(o=n),this},filters(n){return n&&typeof n=="object"&&(s=[n]),this},where(n,i,a){const l=(f,g,_)=>{const b={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[g];b&&s.push({[f]:{[b]:_}})};if(a!==void 0)l(n,String(i),a);else{const f=d(),g=C(f,{[n]:i});s[0]=g}return this},whereContains(n,i){if(n&&typeof n=="string"){const a=d(),l={_contains:i};a[n]?Array.isArray(a[n])?a[n].push(l):a[n]=[a[n],l]:a[n]=[l],s[0]=a}return this},whereIn(n,i){if(n&&typeof n=="string"&&Array.isArray(i)){const a=d(),l={_in:i};a[n]?Array.isArray(a[n])?a[n].push(l):a[n]=[a[n],l]:a[n]=[l],s[0]=a}return this},whereBetween(n,i,a){if(n&&typeof n=="string"){const l=d(),f={_between:[i,a]};l[n]?Array.isArray(l[n])?l[n].push(f):l[n]=[l[n],f]:l[n]=f,s[0]=l}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(r=C(r||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(r=C(r||{},{offset:n})),this},toQuery(n=!1){let i;const a=s.length>0&&Object.keys(s[0]||{}).length>0,l=a?1:0,f=s.length>l;a&&f?i=s:f?i=s.slice(l):a&&(i=s[0]);const g=C(o?{sort:o}:{},i?{filters:i}:{}),_={data:{...e}};if(r&&(_.data.__args=r),Object.keys(g).length>0&&(_.__args=g),n&&(_.meta={total:!0,key:!0,name:!0}),u){const A=u.split(".");let b=_;for(let w=A.length-1;w>=0;w--)b={[A[w]]:b};return b}return{[`list${t}`]:_}}}}const Dt="list",St=["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"],Pt=["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 y{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}y.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}},y.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},y.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},y.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},k().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),y.prototype.fetchData=async function(){try{if(this._batchData){const d=this._batchData;return this.meta=d.meta,k(d.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,o=e[e.length-1];for(const d of e){if(d===o){s[d]=t;break}s[d]={},s=s[d]}let c=await F(r);for(const d of e)c=c[d];return this.meta=c.meta,k(c.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},y.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},y.prototype.all=async function(){return(await this.processData()).all()};for(const t of St)y.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Pt)y.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};y.prototype.average=y.prototype.avg,y.prototype.first=async function(){return this.take(1),(await this.processData()).first()},y.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},y.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],o=t[2];switch(s){case"==":this.filters[r]=o;break;case"<":this.filters[r]={lt:o};break;case"<=":this.filters[r]={lte:o};break;case">":this.filters[r]={gt:o};break;case">=":this.filters[r]={gte:o};break;case"!==":this.filters[r]={ne:o};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},y.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},y.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)},y.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},y.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},y.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},y.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},y.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},y.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},y.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},y.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)},y.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const N=(t,e)=>{const r=new y(e);return r.data_path=Dt+t,r},jt=(t,e={})=>{const r=e;let s="list"+t;const o=u=>r[u]?r[u]:null;return{field:o,$fields:r,setDataPath(u){return s=u,s},getDataPath(){return s},gqlFields(u){let c={};for(const d of u)if(typeof d=="string"){const n=o(d);n&&(c=C(c,n.gqlField?typeof n.gqlField=="string"?{[n.gqlField]:!0}:n.gqlField:{[n.name||d]:!0}))}else typeof d=="object"&&(c=C(c,d));return c},update(u,c){return p({["update"+t]:{__args:{id:u,data:c}}}).then(d=>d["update"+t])},async delete(u){return p({["delete"+t]:{__args:{id:u}}}).then(c=>c["delete"+t])},add(u){return p({["add"+t]:{__args:{data:u}}}).then(c=>c["add"+t])},fields(u){let c=[];for(let d of u){const n=o(d);n&&c.push(n)}return c},async get(u,c){const d=N(t,Ft(c));for(const[n,i]of Object.entries(u))d.where(n,"==",i);return await d.first()},list(u){let c=u;const d={};Object.entries(u).forEach(([a])=>{r[a]&&(d[a]=r[a],r[a].gqlField&&(delete c[a],c=C(c,r[a].gqlField)),r[a].gql&&(delete c[a],c=C(c,r[a].gql)))});const n=S(t,c).dataPath(s),i=n.fetch.bind(n);return{...n,async fetch(){return(await i()).map(l=>{const f={...l};return Object.entries(d).forEach(([g,_])=>{_.field&&typeof _.field=="function"&&(f[g]=_.field(l[g],l))}),f})},async fetchFirst(){const l=await n.fetchFirst.bind(n)();if(!l)return l;const f={...l};return Object.entries(d).forEach(([g,_])=>{_.field&&typeof _.field=="function"&&(f[g]=_.field(l[g],l))}),f}}}}},O={},R=(t,e)=>{const r=jt(t,e);return O[t]=r,r},j=t=>O[t]?O[t]:R(t,{}),Ut=t=>!!O[t],kt=()=>Object.keys(O),vt=()=>{Object.keys(O).forEach(t=>delete O[t])},Et=t=>{Object.entries(t).forEach(([e,r])=>{R(e,r)})},Mt=()=>F({app:{permissions:!0}}).then(t=>t.app.permissions),z=async()=>{const{app:t}=await F({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},W=async()=>{const{app:t}=await F({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},Q=Object.freeze(Object.defineProperty({__proto__:null,assertion:z,attestation:W,login:async()=>{const t=await z();return await p({webAuthnAssertion:{__args:{assertion:t.toJSON()}}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await W();return await p({webAuthnRegister:{__args:{registration:t.toJSON()}}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),G=(t=T)=>F({my:t}).then(e=>e.my),H=(t,e,r="")=>p({login:{__args:{username:t,password:e,code:r}}}).then(s=>s.login),V=()=>p({logout:!0}).then(t=>t.logout),X=(t,e,r)=>p({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(s=>s.changeExpiredPassword),Y=(t,e)=>p({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),Z=(t,e,r)=>p({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(s=>s.resetPassword),I=(t,e)=>p({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),K=(t,e)=>p({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),x=t=>F({my:{granted:{__args:{right:t}}}}).then(e=>e.my.granted),tt=t=>F({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),et={getCurrentUser:G,webAuthn:Q,google:{unlink:()=>p({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>p({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>p({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>p({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>p({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>p({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>p({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>p({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>p({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:H,logout:V,changeExpiredPassword:X,updatePassword:Y,resetPassword:Z,forgetPassword:I,verifyCode:K,grantedRights:tt,isGranted:x},rt={name:!0,path:!0,size:!0,mime:!0,url:!0},st=(t,e,r=rt)=>F({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(s=>s.app.drive.files),nt=(t,e)=>F({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}}).then(r=>r.app.drive?.file?.base64Content),Bt=t=>({list:(e,r=rt)=>st(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>F({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(s=>s.app.drive.file),readFileAsBase64(e){return nt(t,e)},read:async e=>{let r=await F({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>p({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(s=>s.lightDriveWriteFile),delete:e=>p({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>p({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(s=>s.lightDriveRenameFile),move:(e,r)=>p({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(s=>s.lightDriveMoveFile)}),it={name:!0,path:!0},ot=(t,e,r=it)=>F({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(s=>s.app.drive.folders),qt=t=>({list:(e,r=it)=>ot(t,e,r),create:e=>p({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>p({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>p({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(s=>s.lightDriveRenameFolder)}),Nt=()=>F({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),at=t=>{const e=Bt(t),r=qt(t);return{folders:r,files:e,listFiles:e.list,getFile:e.get,readFile:e.read,writeFile:e.write,deleteFile:e.delete,renameFile:e.rename,moveFile:e.move,listFolders:r.list,createFolder:r.create,deleteFolder:r.delete,renameFolder:r.rename,uploadTempFile:s=>p({lightDriveUploadTempFile:{__args:{index:t,file:s},name:!0,path:!0,size:!0,mime:!0}}).then(o=>o.lightDriveUploadTempFile)}},T={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},lt=t=>p({addUser:{__args:t}}).then(e=>e.addUser),ct=t=>p({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),ut=(t=T)=>S("Users",t).dataPath("app.listUser").fetch(),ht=(t,e)=>p({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Rt={list:ut,create:lt,delete:ct,update:ht},ft=t=>F({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Tt={name:!0},dt=(t=Tt)=>F({app:{roles:t}}).then(e=>e.app.roles),pt=(t,e)=>p({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),gt=t=>p({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),Lt=()=>({list:dt,create:pt,delete:gt});function _t(t,e,r,s,o){if(!(!t||typeof t!="object"))for(let u in t){const c=t[u];if(c&&typeof c=="object"){if("__args"in c){const d=c.__args,n={};Object.entries(d).forEach(([i,a])=>{if(a instanceof Array&&D(a)){n[i]=new m.VariableType(i);let l=0;a.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),s.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else a instanceof File?(n[i]=new m.VariableType(i),r[o.current]=["variables."+i],s.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&B(a)?(n[i]={},Object.entries(a).forEach(([l,f])=>{if(f instanceof Array&&D(f)){n[i][l]=new m.VariableType(l);let g=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+g),s.append(o.current.toString(),_),o.current++,g++)}),e[l]="[Upload!]!"}else f instanceof File?(n[i][l]=new m.VariableType(l),r[o.current]=["variables."+l],s.append(o.current.toString(),f),e[l]="Upload!",o.current++):n[i][l]=f})):a!=null&&(n[i]=a)}),c.__args=n}_t(c,e,r,s,o)}}}const p=async t=>{const{axios:e}=M(),r=t,s=new FormData;let o=!1;const u={},c={};_t(r,u,c,s,{current:0}),o=Object.keys(u).length>0,o&&(r.__variables=u);let n=null;const i={mutation:r},a=m.jsonToGraphQLQuery(i);if(o?(s.append("map",JSON.stringify(c)),s.append("operations",JSON.stringify({query:a})),n=await e.post("",s)):n=await e.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data},yt=(t,e,r)=>p({sendMail:{__args:{email:t,subject:e,message:r}}}).then(s=>s.sendMail),Jt={send:yt},$t=Object.freeze(Object.defineProperty({__proto__:null,createFolder:t=>p({lightFSCreateFolder:{__args:{location:t}}}).then(e=>e.lightFSCreateFolder),deleteFile:t=>p({lightFSDeleteFile:{__args:{location:t}}}).then(e=>e.lightFSDeleteFile),deleteFolder:t=>p({lightFSDeleteFolder:{__args:{location:t}}}).then(e=>e.lightFSDeleteFolder),exists:t=>F({app:{fs:{exists:{__args:{location:t}}}}}).then(e=>e.app.fs.exists),find:(t,e)=>{const r={};return t&&(r.search=t),e&&(r.label=e),F({app:{fs:{find:{__args:r,__typename:!0,name:!0,lastModified:!0,location:!0,path:!0,__on:[{__typeName:"File",size:!0,mimeType:!0},{__typeName:"Folder"}]}}}}).then(s=>s.app.fs.find)},list:t=>F({app:{fs:{node:{__args:{location:t},__typename:!0,__on:[{__typeName:"Folder",name:!0,location:!0,path:!0,children:{__typename:!0,name:!0,lastModified:!0,location:!0,path:!0,__on:[{__typeName:"File",size:!0,mimeType:!0},{__typeName:"Folder"}]}}]}}}}).then(r=>r.app.fs.node),move:(t,e)=>p({lightFSMove:{__args:{from:t,to:e}}}).then(r=>r.lightFSMove),readFile:(t,e="text")=>F({app:{fs:{node:{__args:{location:t},__typename:!0,__on:[{__typeName:"File",...e==="text"?{content:!0}:{base64Content:!0}}]}}}}).then(r=>{const s=r.app.fs.node;return s?.__typename==="File"?e==="text"?s.content:s.base64Content:null}),renameFile:(t,e)=>p({lightFSRenameFile:{__args:{location:t,newName:e}}}).then(r=>r.lightFSRenameFile),renameFolder:(t,e)=>p({lightFSRenameFolder:{__args:{location:t,newName:e}}}).then(r=>r.lightFSRenameFolder),uploadBase64:(t,e)=>p({lightFSUploadBase64:{__args:{location:t,base64:e},__typename:!0,name:!0,path:!0,location:!0,__on:[{__typename:"File",size:!0,mimeType:!0,lastModified:!0}]}}).then(r=>r.lightFSUploadBase64),uploadFile:(t,e)=>p({lightFSUploadFile:{__args:{location:t,file:e}}}).then(r=>r.lightFSUploadFile),writeFile:(t,e)=>p({lightFSWriteFile:{__args:{location:t,content:e}}}).then(r=>r.lightFSWriteFile)},Symbol.toStringTag,{value:"Module"})),L=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(L(r)).forEach(([s,o])=>{e[s]=o})}),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]=L(s)}),e)},Ft=t=>L(t),zt=t=>{const e=typeof window>"u";let r=[];const s=mt.create({baseURL:t,withCredentials:!0});let o=!1,u=[];const c=(i,a=null)=>{u.forEach(l=>{i?l.reject(i):l.resolve(a)}),u=[]};s.interceptors.response.use(i=>{const a=i.data.errors;if(a&&a.some(l=>l.extensions?.code==="TOKEN_EXPIRED")){const l=i.config;return o?new Promise((f,g)=>{u.push({resolve:f,reject:g})}).then(()=>s(l)).catch(f=>Promise.reject(f)):(o=!0,d().then(()=>(o=!1,c(null),s(l))).catch(f=>(o=!1,c(f),Promise.reject(f))))}return i},i=>Promise.reject(i));function d(){return s.post("/refresh_token")}e&&(s.interceptors.request.use(i=>(i.withCredentials=!0,r.length>0&&(i.headers.Cookie=r.join("; ")),i)),s.interceptors.response.use(i=>{if(i.headers["set-cookie"]){const a=i.headers["set-cookie"].map(f=>f.split(";")[0]),l=new Map;r.forEach(f=>{const g=f.split("=")[0];l.set(g,f)}),a.forEach(f=>{const g=f.split("=")[0];l.set(g,f)}),r=Array.from(l.values())}return i}));const n={post:s.post,baseURL:t,axios:s,auth:et,mutation:p,query:F,config:ft,mail:Jt,users:Rt,model(i){return j(i)},roles:Lt(),collect:(i,a)=>{const l=N(i,a);return l.data_path=j(i).getDataPath(),l},list:(i,a)=>S(i,a).dataPath(j(i).getDataPath()),drive:at,async collects(i){const a={},l={};for(const g in i){const _=i[g].getQueryPayload();l[g]=_.data_path,a[g]={};const A=_.data_path.split(".");let b=A[A.length-1],w=a[g];for(const U of A){if(U===b){w[U]=_.query;break}w[U]=w[U]||{}}a[g].__aliasFor=A[0]}const f=await F(a);for(const g in i){const _=l[g].split(".");let A=_[_.length-1],b=f[g];for(const w of _){if(w===A){i[g]._batchData=f[g][w];break}b[w]=b[w]||{}}}return i}};return J(n),n},Wt=S;h.arrayHasFile=D,h.auth=et,h.changeExpiredPassword=X,h.clearModels=vt,h.createClient=zt,h.createCollection=N,h.createFileFromBase64=Ct,h.createFileFromBase85=Ot,h.createFileFromString=q,h.createList=S,h.createRole=pt,h.createUser=lt,h.defaultUserFields=T,h.defineModel=R,h.defineModels=Et,h.deleteRole=gt,h.deleteUser=ct,h.forgetPassword=I,h.fs=$t,h.getApiClient=M,h.getApiClientOptional=bt,h.getConfig=ft,h.getCurrentUser=G,h.getDrive=at,h.getGrantedRights=tt,h.getModel=j,h.hasModel=Ut,h.isGranted=x,h.list=Wt,h.listDrives=Nt,h.listFiles=st,h.listFolders=ot,h.listModels=kt,h.listPermissions=Mt,h.listRoles=dt,h.listUsers=ut,h.login=H,h.logout=V,h.mutation=p,h.objectHasFile=B,h.query=F,h.readFileAsBase64=nt,h.resetPassword=Z,h.sendMail=yt,h.setApiClient=J,h.toQuery=Ft,h.updatePassword=Y,h.updateUser=ht,h.verifyCode=K,h.webAuthn=Q,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "3.2.5",
3
+ "version": "3.2.7",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"