@hostlink/light 3.0.9 → 3.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/light.js +79 -79
- package/dist/light.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/light.js
CHANGED
|
@@ -30,7 +30,7 @@ function H(t) {
|
|
|
30
30
|
e.reduce((r, n) => E(r, n, "", t), {})
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const b = H();
|
|
34
34
|
let O = null;
|
|
35
35
|
const X = (t) => {
|
|
36
36
|
O = t;
|
|
@@ -38,7 +38,7 @@ const X = (t) => {
|
|
|
38
38
|
if (!O)
|
|
39
39
|
throw new Error("Api client not initialized. Call setApiClient() first.");
|
|
40
40
|
return O;
|
|
41
|
-
},
|
|
41
|
+
}, Nt = () => O;
|
|
42
42
|
function A(t) {
|
|
43
43
|
for (let e = 0; e < t.length; e++)
|
|
44
44
|
if (t[e] instanceof File)
|
|
@@ -59,7 +59,7 @@ function Y(t) {
|
|
|
59
59
|
for (var a = i; a > 0; a--) s.pop();
|
|
60
60
|
})(n, e.length), l.fromCharCode.apply(l, n);
|
|
61
61
|
}
|
|
62
|
-
const
|
|
62
|
+
const M = (t = "") => {
|
|
63
63
|
const e = t, r = (n = "application/octet-stream") => {
|
|
64
64
|
const o = new Uint8Array(e.length);
|
|
65
65
|
for (let h = 0; h < e.length; h++)
|
|
@@ -78,8 +78,8 @@ const N = (t = "") => {
|
|
|
78
78
|
window.open(r(n), "_blank");
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
}, Jt = (t) =>
|
|
82
|
-
function
|
|
81
|
+
}, Jt = (t) => M(atob(t)), Lt = (t) => M(Y(t));
|
|
82
|
+
function N(t, e, r, n, o) {
|
|
83
83
|
if (!(!t || typeof t != "object"))
|
|
84
84
|
for (let c in t) {
|
|
85
85
|
const l = t[c];
|
|
@@ -96,15 +96,15 @@ function M(t, e, r, n, o) {
|
|
|
96
96
|
} else a instanceof File ? (s[i] = new w(i), r[o.current] = ["variables." + i], n.append(o.current.toString(), a), e[i] = "Upload!", o.current++) : a instanceof Object && B(a) ? (s[i] = {}, Object.entries(a).forEach(([u, p]) => {
|
|
97
97
|
if (p instanceof Array && A(p)) {
|
|
98
98
|
s[i][u] = new w(u);
|
|
99
|
-
let
|
|
100
|
-
p.forEach((
|
|
101
|
-
|
|
99
|
+
let d = 0;
|
|
100
|
+
p.forEach((g) => {
|
|
101
|
+
g instanceof File && (r[o.current] || (r[o.current] = []), r[o.current].push("variables." + u + "." + d), n.append(o.current.toString(), g), o.current++, d++);
|
|
102
102
|
}), e[u] = "[Upload!]!";
|
|
103
103
|
} else p instanceof File ? (s[i][u] = new w(u), r[o.current] = ["variables." + u], n.append(o.current.toString(), p), e[u] = "Upload!", o.current++) : s[i][u] = p;
|
|
104
104
|
})) : a != null && (s[i] = a);
|
|
105
105
|
}), l.__args = s;
|
|
106
106
|
}
|
|
107
|
-
|
|
107
|
+
N(l, e, r, n, o);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -112,7 +112,7 @@ const y = async (t) => {
|
|
|
112
112
|
const { axios: e } = q(), r = t, n = new FormData();
|
|
113
113
|
let o = !1;
|
|
114
114
|
const c = {}, l = {};
|
|
115
|
-
|
|
115
|
+
N(r, c, l, n, { current: 0 }), o = Object.keys(c).length > 0, o && (r.__variables = c);
|
|
116
116
|
let s = null;
|
|
117
117
|
const a = v({ query: r });
|
|
118
118
|
if (o ? (n.append("map", JSON.stringify(l)), n.append("operations", JSON.stringify({
|
|
@@ -170,7 +170,7 @@ function C(t, e) {
|
|
|
170
170
|
// where('key', value) -> exact match
|
|
171
171
|
// where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
|
|
172
172
|
where(s, i, a) {
|
|
173
|
-
const u = (p,
|
|
173
|
+
const u = (p, d, g) => {
|
|
174
174
|
const F = {
|
|
175
175
|
">": "_gt",
|
|
176
176
|
"<": "_lt",
|
|
@@ -179,14 +179,14 @@ function C(t, e) {
|
|
|
179
179
|
"!=": "_ne",
|
|
180
180
|
in: "_in",
|
|
181
181
|
contains: "_contains"
|
|
182
|
-
}[
|
|
183
|
-
F && n.push({ [p]: { [F]:
|
|
182
|
+
}[d];
|
|
183
|
+
F && n.push({ [p]: { [F]: g } });
|
|
184
184
|
};
|
|
185
185
|
if (a !== void 0)
|
|
186
186
|
u(s, String(i), a);
|
|
187
187
|
else {
|
|
188
|
-
const p = h(),
|
|
189
|
-
n[0] =
|
|
188
|
+
const p = h(), d = b(p, { [s]: i });
|
|
189
|
+
n[0] = d;
|
|
190
190
|
}
|
|
191
191
|
return this;
|
|
192
192
|
},
|
|
@@ -219,31 +219,31 @@ function C(t, e) {
|
|
|
219
219
|
},
|
|
220
220
|
// limit sets paging/limit for the data selection
|
|
221
221
|
limit(s) {
|
|
222
|
-
return typeof s == "number" && Number.isFinite(s) && (r =
|
|
222
|
+
return typeof s == "number" && Number.isFinite(s) && (r = b(r || {}, { limit: s })), this;
|
|
223
223
|
},
|
|
224
224
|
// offset sets the starting index for the data selection
|
|
225
225
|
offset(s) {
|
|
226
|
-
return typeof s == "number" && Number.isFinite(s) && (r =
|
|
226
|
+
return typeof s == "number" && Number.isFinite(s) && (r = b(r || {}, { offset: s })), this;
|
|
227
227
|
},
|
|
228
228
|
toQuery(s = !1) {
|
|
229
229
|
let i;
|
|
230
230
|
const a = n.length > 0 && Object.keys(n[0] || {}).length > 0, u = a ? 1 : 0, p = n.length > u;
|
|
231
231
|
a && p ? i = n : p ? i = n.slice(u) : a && (i = n[0]);
|
|
232
|
-
const
|
|
232
|
+
const d = b(
|
|
233
233
|
o ? { sort: o } : {},
|
|
234
234
|
i ? { filters: i } : {}
|
|
235
|
-
),
|
|
235
|
+
), g = {
|
|
236
236
|
data: {
|
|
237
237
|
...e
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
|
-
if (r && (
|
|
240
|
+
if (r && (g.data.__args = r), Object.keys(d).length > 0 && (g.__args = d), s && (g.meta = {
|
|
241
241
|
total: !0,
|
|
242
242
|
key: !0,
|
|
243
243
|
name: !0
|
|
244
244
|
}), c) {
|
|
245
245
|
const D = c.split(".");
|
|
246
|
-
let F =
|
|
246
|
+
let F = g;
|
|
247
247
|
for (let k = D.length - 1; k >= 0; k--)
|
|
248
248
|
F = {
|
|
249
249
|
[D[k]]: F
|
|
@@ -251,7 +251,7 @@ function C(t, e) {
|
|
|
251
251
|
return F;
|
|
252
252
|
}
|
|
253
253
|
return {
|
|
254
|
-
[`list${t}`]:
|
|
254
|
+
[`list${t}`]: g
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
257
|
};
|
|
@@ -310,7 +310,7 @@ const Z = "list", V = [
|
|
|
310
310
|
"implode",
|
|
311
311
|
"partition"
|
|
312
312
|
];
|
|
313
|
-
class
|
|
313
|
+
class _ {
|
|
314
314
|
_batchData = null;
|
|
315
315
|
data_path = "";
|
|
316
316
|
filters;
|
|
@@ -327,7 +327,7 @@ class g {
|
|
|
327
327
|
this.filters = {}, this.steps = [], this.fields = e;
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
-
|
|
330
|
+
_.prototype.getQueryPayload = function() {
|
|
331
331
|
let t = {
|
|
332
332
|
meta: {
|
|
333
333
|
total: !0,
|
|
@@ -341,22 +341,22 @@ g.prototype.getQueryPayload = function() {
|
|
|
341
341
|
steps: this.steps
|
|
342
342
|
};
|
|
343
343
|
};
|
|
344
|
-
|
|
344
|
+
_.prototype.dataPath = function(t) {
|
|
345
345
|
const e = this.clone();
|
|
346
346
|
return e.data_path = t, e;
|
|
347
347
|
};
|
|
348
|
-
|
|
348
|
+
_.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
|
-
|
|
352
|
+
_.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
|
-
|
|
359
|
+
_.prototype.fetchData = async function() {
|
|
360
360
|
try {
|
|
361
361
|
if (this._batchData) {
|
|
362
362
|
const h = this._batchData;
|
|
@@ -387,32 +387,32 @@ g.prototype.fetchData = async function() {
|
|
|
387
387
|
throw console.error("Error fetching collection data:", t), t;
|
|
388
388
|
}
|
|
389
389
|
};
|
|
390
|
-
|
|
390
|
+
_.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
|
-
|
|
396
|
+
_.prototype.all = async function() {
|
|
397
397
|
return (await this.processData()).all();
|
|
398
398
|
};
|
|
399
399
|
for (const t of V)
|
|
400
|
-
|
|
400
|
+
_.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 I)
|
|
405
|
-
|
|
405
|
+
_.prototype[t] = async function(...e) {
|
|
406
406
|
return (await this.clone().processData())[t](...e);
|
|
407
407
|
};
|
|
408
|
-
|
|
409
|
-
|
|
408
|
+
_.prototype.average = _.prototype.avg;
|
|
409
|
+
_.prototype.first = async function() {
|
|
410
410
|
return this.take(1), (await this.processData()).first();
|
|
411
411
|
};
|
|
412
|
-
|
|
412
|
+
_.prototype._handleBatchData = function(t, e) {
|
|
413
413
|
return this._batchData ? (this.steps.push({ type: t, args: e }), this) : null;
|
|
414
414
|
};
|
|
415
|
-
|
|
415
|
+
_.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 @@ g.prototype.where = function(...t) {
|
|
|
444
444
|
}
|
|
445
445
|
return this;
|
|
446
446
|
};
|
|
447
|
-
|
|
447
|
+
_.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
|
-
|
|
451
|
+
_.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
|
-
|
|
454
|
+
_.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
|
-
|
|
458
|
+
_.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
|
-
|
|
462
|
+
_.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
|
-
|
|
466
|
+
_.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
|
-
|
|
470
|
+
_.prototype.sortBy = function(t) {
|
|
471
471
|
return this.steps.push({ type: "sortBy", args: [t] }), typeof t == "string" && (this._sort = t), this;
|
|
472
472
|
};
|
|
473
|
-
|
|
473
|
+
_.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
|
-
|
|
476
|
+
_.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
|
-
|
|
481
|
+
_.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
|
-
|
|
486
|
+
_.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 J = (t, e) => {
|
|
490
|
-
const r = new
|
|
490
|
+
const r = new _(e);
|
|
491
491
|
return r.data_path = Z + t, r;
|
|
492
492
|
}, K = (t, e = {}) => {
|
|
493
493
|
const r = e;
|
|
@@ -507,8 +507,8 @@ const J = (t, e) => {
|
|
|
507
507
|
for (const h of c)
|
|
508
508
|
if (typeof h == "string") {
|
|
509
509
|
const s = o(h);
|
|
510
|
-
s && (l =
|
|
511
|
-
} else typeof h == "object" && (l =
|
|
510
|
+
s && (l = b(l, s.gqlField ? typeof s.gqlField == "string" ? { [s.gqlField]: !0 } : s.gqlField : { [s.name || h]: !0 }));
|
|
511
|
+
} else typeof h == "object" && (l = b(l, h));
|
|
512
512
|
return l;
|
|
513
513
|
},
|
|
514
514
|
update(c, l) {
|
|
@@ -550,7 +550,7 @@ const J = (t, e) => {
|
|
|
550
550
|
let l = c;
|
|
551
551
|
const h = {};
|
|
552
552
|
Object.entries(c).forEach(([a]) => {
|
|
553
|
-
r[a] && (h[a] = r[a], r[a].gqlField && (delete l[a], l =
|
|
553
|
+
r[a] && (h[a] = r[a], r[a].gqlField && (delete l[a], l = b(l, r[a].gqlField)), r[a].gql && (delete l[a], l = b(l, r[a].gql)));
|
|
554
554
|
});
|
|
555
555
|
const s = C(t, l).dataPath(n), i = s.fetch.bind(s);
|
|
556
556
|
return {
|
|
@@ -558,8 +558,8 @@ const J = (t, e) => {
|
|
|
558
558
|
async fetch() {
|
|
559
559
|
return (await i()).map((u) => {
|
|
560
560
|
const p = { ...u };
|
|
561
|
-
return Object.entries(h).forEach(([
|
|
562
|
-
|
|
561
|
+
return Object.entries(h).forEach(([d, g]) => {
|
|
562
|
+
g.format && typeof g.format == "function" && (p[d] = g.format(u[d], u));
|
|
563
563
|
}), p;
|
|
564
564
|
});
|
|
565
565
|
},
|
|
@@ -567,18 +567,18 @@ const J = (t, e) => {
|
|
|
567
567
|
const u = await s.fetchFirst.bind(s)();
|
|
568
568
|
if (!u) return u;
|
|
569
569
|
const p = { ...u };
|
|
570
|
-
return Object.entries(h).forEach(([
|
|
571
|
-
|
|
570
|
+
return Object.entries(h).forEach(([d, g]) => {
|
|
571
|
+
g.format && typeof g.format == "function" && (p[d] = g.format(u));
|
|
572
572
|
}), p;
|
|
573
573
|
}
|
|
574
574
|
};
|
|
575
575
|
}
|
|
576
576
|
};
|
|
577
|
-
},
|
|
577
|
+
}, m = {}, L = (t, e) => {
|
|
578
578
|
const r = K(t, e);
|
|
579
|
-
return
|
|
580
|
-
}, P = (t) =>
|
|
581
|
-
Object.keys(
|
|
579
|
+
return m[t] = r, r;
|
|
580
|
+
}, P = (t) => m[t] ? m[t] : L(t, {}), $t = (t) => !!m[t], Qt = () => Object.keys(m), Gt = () => {
|
|
581
|
+
Object.keys(m).forEach((t) => delete m[t]);
|
|
582
582
|
}, Tt = (t) => {
|
|
583
583
|
Object.entries(t).forEach(([e, r]) => {
|
|
584
584
|
L(e, r);
|
|
@@ -809,11 +809,11 @@ const J = (t, e) => {
|
|
|
809
809
|
first_name: !0,
|
|
810
810
|
last_name: !0,
|
|
811
811
|
status: !0
|
|
812
|
-
},
|
|
812
|
+
}, bt = (t) => f({
|
|
813
813
|
addUser: {
|
|
814
814
|
__args: t
|
|
815
815
|
}
|
|
816
|
-
}).then((e) => e.addUser),
|
|
816
|
+
}).then((e) => e.addUser), mt = (t) => f({
|
|
817
817
|
deleteUser: {
|
|
818
818
|
__args: { id: t }
|
|
819
819
|
}
|
|
@@ -823,8 +823,8 @@ const J = (t, e) => {
|
|
|
823
823
|
}
|
|
824
824
|
}).then((r) => r.updateUser), Ot = {
|
|
825
825
|
list: Ft,
|
|
826
|
-
create:
|
|
827
|
-
delete:
|
|
826
|
+
create: bt,
|
|
827
|
+
delete: mt,
|
|
828
828
|
update: At
|
|
829
829
|
}, Ct = (t) => y({
|
|
830
830
|
app: {
|
|
@@ -881,9 +881,9 @@ function W(t, e, r, n, o) {
|
|
|
881
881
|
} else a instanceof File ? (s[i] = new w(i), r[o.current] = ["variables." + i], n.append(o.current.toString(), a), e[i] = "Upload!", o.current++) : a instanceof Object && B(a) ? (s[i] = {}, Object.entries(a).forEach(([u, p]) => {
|
|
882
882
|
if (p instanceof Array && A(p)) {
|
|
883
883
|
s[i][u] = new w(u);
|
|
884
|
-
let
|
|
885
|
-
p.forEach((
|
|
886
|
-
|
|
884
|
+
let d = 0;
|
|
885
|
+
p.forEach((g) => {
|
|
886
|
+
g instanceof File && (r[o.current] || (r[o.current] = []), r[o.current].push("variables." + u + "." + d), n.append(o.current.toString(), g), o.current++, d++);
|
|
887
887
|
}), e[u] = "[Upload!]!";
|
|
888
888
|
} else p instanceof File ? (s[i][u] = new w(u), r[o.current] = ["variables." + u], n.append(o.current.toString(), p), e[u] = "Upload!", o.current++) : s[i][u] = p;
|
|
889
889
|
})) : a != null && (s[i] = a);
|
|
@@ -972,13 +972,13 @@ const f = async (t) => {
|
|
|
972
972
|
const a = c[i].getQueryPayload();
|
|
973
973
|
h[i] = a.data_path, l[i] = {};
|
|
974
974
|
const u = a.data_path.split(".");
|
|
975
|
-
let p = u[u.length - 1],
|
|
976
|
-
for (const
|
|
977
|
-
if (
|
|
978
|
-
|
|
975
|
+
let p = u[u.length - 1], d = l[i];
|
|
976
|
+
for (const g of u) {
|
|
977
|
+
if (g === p) {
|
|
978
|
+
d[g] = a.query;
|
|
979
979
|
break;
|
|
980
980
|
}
|
|
981
|
-
|
|
981
|
+
d[g] = d[g] || {};
|
|
982
982
|
}
|
|
983
983
|
l[i].__aliasFor = u[0];
|
|
984
984
|
}
|
|
@@ -986,12 +986,12 @@ const f = async (t) => {
|
|
|
986
986
|
for (const i in c) {
|
|
987
987
|
const a = h[i].split(".");
|
|
988
988
|
let u = a[a.length - 1], p = s[i];
|
|
989
|
-
for (const
|
|
990
|
-
if (
|
|
991
|
-
c[i]._batchData = s[i][
|
|
989
|
+
for (const d of a) {
|
|
990
|
+
if (d === u) {
|
|
991
|
+
c[i]._batchData = s[i][d];
|
|
992
992
|
break;
|
|
993
993
|
}
|
|
994
|
-
p[
|
|
994
|
+
p[d] = p[d] || {};
|
|
995
995
|
}
|
|
996
996
|
}
|
|
997
997
|
return c;
|
|
@@ -1008,18 +1008,18 @@ export {
|
|
|
1008
1008
|
J as createCollection,
|
|
1009
1009
|
Jt as createFileFromBase64,
|
|
1010
1010
|
Lt as createFileFromBase85,
|
|
1011
|
-
|
|
1011
|
+
M as createFileFromString,
|
|
1012
1012
|
C as createList,
|
|
1013
1013
|
jt as createRole,
|
|
1014
|
-
|
|
1014
|
+
bt as createUser,
|
|
1015
1015
|
R as defaultUserFields,
|
|
1016
1016
|
L as defineModel,
|
|
1017
1017
|
Tt as defineModels,
|
|
1018
1018
|
Pt as deleteRole,
|
|
1019
|
-
|
|
1019
|
+
mt as deleteUser,
|
|
1020
1020
|
ct as forgetPassword,
|
|
1021
1021
|
q as getApiClient,
|
|
1022
|
-
|
|
1022
|
+
Nt as getApiClientOptional,
|
|
1023
1023
|
Ct as getConfig,
|
|
1024
1024
|
rt as getCurrentUser,
|
|
1025
1025
|
wt as getDrive,
|
package/dist/light.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,b){typeof exports=="object"&&typeof module<"u"?b(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"],b):(f=typeof globalThis<"u"?globalThis:f||self,b(f.light={},f.jsonToGraphqlQuery,f.collect,f.axios))})(this,(function(f,b,k,wt){"use strict";function U(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 j(t,e,r=".",n){if(!U(e))return j(t,{},r,n);const i=Object.assign({},e);for(const c in t){if(c==="__proto__"||c==="constructor")continue;const l=t[c];l!=null&&(n&&n(i,c,l,r)||(Array.isArray(l)&&Array.isArray(i[c])?i[c]=[...l,...i[c]]:U(l)&&U(i[c])?i[c]=j(l,i[c],(r?`${r}.`:"")+c.toString(),n):i[c]=l))}return i}function bt(t){return(...e)=>e.reduce((r,n)=>j(r,n,"",t),{})}const m=bt();let D=null;const T=t=>{D=t},v=()=>{if(!D)throw new Error("Api client not initialized. Call setApiClient() first.");return D},mt=()=>D;function A(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function E(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&A(t[e]))return!0;return!1}function Ft(t){t="<~"+t+"~>";var e,r,n,i,c,l=String,h=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,n=[],i=0,c=t.length;c>i;i+=5)r=52200625*(t.charCodeAt(i)-33)+614125*(t.charCodeAt(i+1)-33)+7225*(t.charCodeAt(i+2)-33)+85*(t.charCodeAt(i+3)-33)+(t.charCodeAt(i+4)-33),n.push(h&r>>24,h&r>>16,h&r>>8,h&r);return(function(s,o){for(var a=o;a>0;a--)s.pop()})(n,e.length),l.fromCharCode.apply(l,n)}const S=(t="")=>{const e=t,r=(n="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let h=0;h<e.length;h++)i[h]=e.charCodeAt(h);const c=new Blob([i],{type:n});return URL.createObjectURL(c)};return{getContent:()=>e,getURL:r,download:n=>{const i=document.createElement("a");i.download=n,i.href=r(),document.body.appendChild(i),i.click(),document.body.removeChild(i)},open:n=>{window.open(r(n),"_blank")}}},At=t=>S(atob(t)),Ct=t=>S(Ft(t));function $(t,e,r,n,i){if(!(!t||typeof t!="object"))for(let c in t){const l=t[c];if(l&&typeof l=="object"){if("__args"in l){const h=l.__args,s={};Object.entries(h).forEach(([o,a])=>{if(a instanceof Array&&A(a)){s[o]=new b.VariableType(o);let u=0;a.forEach(p=>{p instanceof File&&(r[i.current]||(r[i.current]=[]),r[i.current].push("variables."+o+"."+u),n.append(i.current.toString(),p),i.current++,u++)}),e[o]="[Upload!]!"}else a instanceof File?(s[o]=new b.VariableType(o),r[i.current]=["variables."+o],n.append(i.current.toString(),a),e[o]="Upload!",i.current++):a instanceof Object&&E(a)?(s[o]={},Object.entries(a).forEach(([u,p])=>{if(p instanceof Array&&A(p)){s[o][u]=new b.VariableType(u);let y=0;p.forEach(_=>{_ instanceof File&&(r[i.current]||(r[i.current]=[]),r[i.current].push("variables."+u+"."+y),n.append(i.current.toString(),_),i.current++,y++)}),e[u]="[Upload!]!"}else p instanceof File?(s[o][u]=new b.VariableType(u),r[i.current]=["variables."+u],n.append(i.current.toString(),p),e[u]="Upload!",i.current++):s[o][u]=p})):a!=null&&(s[o]=a)}),l.__args=s}$(l,e,r,n,i)}}}const w=async t=>{const{axios:e}=v(),r=t,n=new FormData;let i=!1;const c={},l={};$(r,c,l,n,{current:0}),i=Object.keys(c).length>0,i&&(r.__variables=c);let s=null;const o={query:r},a=b.jsonToGraphQLQuery(o);if(i?(n.append("map",JSON.stringify(l)),n.append("operations",JSON.stringify({query:a})),s=await e.post("",n)):s=await e.post("",{query:a}),s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function O(t,e){let r,n=[],i,c;const l=s=>!s||typeof s!="object"?!1:Object.values(s).some(o=>o&&typeof o=="object"&&Object.keys(o).some(a=>a.startsWith("_"))),h=()=>n.length===0?(n.unshift({}),n[0]):(l(n[0])&&n.unshift({}),n[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const o=await this.limit(1).fetch();return Array.isArray(o)&&o.length>0?o[0]:null},async fetchWithMeta(){let o=await w(this.toQuery(!0));if(c){const a=c.split(".");for(const u of a)o=o[u];return o}return o[`list${t}`]},async fetch(){let o=await w(this.toQuery());if(c){const a=c.split(".");for(const u of a)o=o[u];return o.data}return o[`list${t}`].data},dataPath(s){return s&&typeof s=="string"&&(c=s),this},sort(s){return s&&typeof s=="string"&&(i=s),this},filters(s){return s&&typeof s=="object"&&(n=[s]),this},where(s,o,a){const u=(p,y,_)=>{const C={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[y];C&&n.push({[p]:{[C]:_}})};if(a!==void 0)u(s,String(o),a);else{const p=h(),y=m(p,{[s]:o});n[0]=y}return this},whereContains(s,o){if(s&&typeof s=="string"){const a=h(),u={_contains:o};a[s]?Array.isArray(a[s])?a[s].push(u):a[s]=[a[s],u]:a[s]=[u],n[0]=a}return this},whereIn(s,o){if(s&&typeof s=="string"&&Array.isArray(o)){const a=h(),u={_in:o};a[s]?Array.isArray(a[s])?a[s].push(u):a[s]=[a[s],u]:a[s]=[u],n[0]=a}return this},whereBetween(s,o,a){if(s&&typeof s=="string"){const u=h(),p={_between:[o,a]};u[s]?Array.isArray(u[s])?u[s].push(p):u[s]=[u[s],p]:u[s]=p,n[0]=u}return this},limit(s){return typeof s=="number"&&Number.isFinite(s)&&(r=m(r||{},{limit:s})),this},offset(s){return typeof s=="number"&&Number.isFinite(s)&&(r=m(r||{},{offset:s})),this},toQuery(s=!1){let o;const a=n.length>0&&Object.keys(n[0]||{}).length>0,u=a?1:0,p=n.length>u;a&&p?o=n:p?o=n.slice(u):a&&(o=n[0]);const y=m(i?{sort:i}:{},o?{filters:o}:{}),_={data:{...e}};if(r&&(_.data.__args=r),Object.keys(y).length>0&&(_.__args=y),s&&(_.meta={total:!0,key:!0,name:!0}),c){const L=c.split(".");let C=_;for(let J=L.length-1;J>=0;J--)C={[L[J]]:C};return C}return{[`list${t}`]:_}}}}const Ot="list",Dt=["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 g{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}g.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},g.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},g.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},g.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},k().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 h=this._batchData;return this.meta=h.meta,k(h.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},n=r,i=e[e.length-1];for(const h of e){if(h===i){n[h]=t;break}n[h]={},n=n[h]}let l=await w(r);for(const h of e)l=l[h];return this.meta=l.meta,k(l.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 Dt)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Pt)g.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};g.prototype.average=g.prototype.avg,g.prototype.first=async function(){return this.take(1),(await this.processData()).first()},g.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},g.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],n=t[1],i=t[2];switch(n){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: ${n}`)}}return this},g.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},g.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},g.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},g.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},g.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},g.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},g.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},g.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},g.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},g.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},g.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const M=(t,e)=>{const r=new g(e);return r.data_path=Ot+t,r},kt=(t,e={})=>{const r=e;let n="list"+t;const i=c=>r[c]?r[c]:null;return{field:i,$fields:r,setDataPath(c){return n=c,n},getDataPath(){return n},gqlFields(c){let l={};for(const h of c)if(typeof h=="string"){const s=i(h);s&&(l=m(l,s.gqlField?typeof s.gqlField=="string"?{[s.gqlField]:!0}:s.gqlField:{[s.name||h]:!0}))}else typeof h=="object"&&(l=m(l,h));return l},update(c,l){return d({["update"+t]:{__args:{id:c,data:l}}}).then(h=>h["update"+t])},async delete(c){return d({["delete"+t]:{__args:{id:c}}}).then(l=>l["delete"+t])},add(c){return d({["add"+t]:{__args:{data:c}}}).then(l=>l["add"+t])},fields(c){let l=[];for(let h of c){const s=i(h);s&&l.push(s)}return l},async get(c,l){const h=M(t,yt(l));for(const[s,o]of Object.entries(c))h.where(s,"==",o);return await h.first()},list(c){let l=c;const h={};Object.entries(c).forEach(([a])=>{r[a]&&(h[a]=r[a],r[a].gqlField&&(delete l[a],l=m(l,r[a].gqlField)),r[a].gql&&(delete l[a],l=m(l,r[a].gql)))});const s=O(t,l).dataPath(n),o=s.fetch.bind(s);return{...s,async fetch(){return(await o()).map(u=>{const p={...u};return Object.entries(h).forEach(([y,_])=>{_.format&&typeof _.format=="function"&&(p[y]=_.format(u))}),p})},async fetchFirst(){const u=await s.fetchFirst.bind(s)();if(!u)return u;const p={...u};return Object.entries(h).forEach(([y,_])=>{_.format&&typeof _.format=="function"&&(p[y]=_.format(u))}),p}}}}},F={},B=(t,e)=>{const r=kt(t,e);return F[t]=r,r},P=t=>F[t]?F[t]:B(t,{}),Ut=t=>!!F[t],jt=()=>Object.keys(F),vt=()=>{Object.keys(F).forEach(t=>delete F[t])},Et=t=>{Object.entries(t).forEach(([e,r])=>{B(e,r)})},St=()=>w({app:{permissions:!0}}).then(t=>t.app.permissions),R=async()=>{const{app:t}=await w({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},W=async()=>{const{app:t}=await w({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},z=Object.freeze(Object.defineProperty({__proto__:null,assertion:R,attestation:W,login:async()=>{const t=await R();return await d({webAuthnAssertion:{__args:{assertion:t.toJSON()}}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await W();return await d({webAuthnRegister:{__args:{registration:t.toJSON()}}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),Q=(t=q)=>w({my:t}).then(e=>e.my),G=(t,e,r="")=>d({login:{__args:{username:t,password:e,code:r}}}).then(n=>n.login),H=()=>d({logout:!0}).then(t=>t.logout),V=(t,e,r)=>d({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(n=>n.changeExpiredPassword),X=(t,e)=>d({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),Y=(t,e,r)=>d({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(n=>n.resetPassword),Z=(t,e)=>d({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),I=(t,e)=>d({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),K=t=>w({my:{granted:{__args:{right:t}}}}).then(e=>e.my.granted),x=t=>w({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),tt={getCurrentUser:Q,webAuthn:z,google:{unlink:()=>d({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>d({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>d({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>d({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>d({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>d({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>d({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>d({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>d({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:G,logout:H,changeExpiredPassword:V,updatePassword:X,resetPassword:Y,forgetPassword:Z,verifyCode:I,grantedRights:x,isGranted:K},et={name:!0,path:!0,size:!0,mime:!0,url:!0},rt=(t,e,r=et)=>w({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(n=>n.app.drive.files),st=(t,e)=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}}).then(r=>r.app.drive?.file?.base64Content),Mt=t=>({list:(e,r=et)=>rt(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(n=>n.app.drive.file),readFileAsBase64(e){return st(t,e)},read:async e=>{let r=await w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>d({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(n=>n.lightDriveWriteFile),delete:e=>d({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>d({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFile),move:(e,r)=>d({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(n=>n.lightDriveMoveFile)}),nt={name:!0,path:!0},it=(t,e,r=nt)=>w({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(n=>n.app.drive.folders),Bt=t=>({list:(e,r=nt)=>it(t,e,r),create:e=>d({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>d({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>d({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFolder)}),qt=()=>w({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),ot=t=>{const e=Mt(t),r=Bt(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:n=>d({lightDriveUploadTempFile:{__args:{index:t,file:n},name:!0,path:!0,size:!0,mime:!0}}).then(i=>i.lightDriveUploadTempFile)}},q={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},at=t=>d({addUser:{__args:t}}).then(e=>e.addUser),ct=t=>d({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),lt=(t=q)=>O("Users",t).dataPath("app.listUser").fetch(),ut=(t,e)=>d({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Nt={list:lt,create:at,delete:ct,update:ut},ht=t=>w({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Lt={name:!0},ft=(t=Lt)=>w({app:{roles:t}}).then(e=>e.app.roles),pt=(t,e)=>d({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),dt=t=>d({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),Jt=()=>({list:ft,create:pt,delete:dt});function gt(t,e,r,n,i){if(!(!t||typeof t!="object"))for(let c in t){const l=t[c];if(l&&typeof l=="object"){if("__args"in l){const h=l.__args,s={};Object.entries(h).forEach(([o,a])=>{if(a instanceof Array&&A(a)){s[o]=new b.VariableType(o);let u=0;a.forEach(p=>{p instanceof File&&(r[i.current]||(r[i.current]=[]),r[i.current].push("variables."+o+"."+u),n.append(i.current.toString(),p),i.current++,u++)}),e[o]="[Upload!]!"}else a instanceof File?(s[o]=new b.VariableType(o),r[i.current]=["variables."+o],n.append(i.current.toString(),a),e[o]="Upload!",i.current++):a instanceof Object&&E(a)?(s[o]={},Object.entries(a).forEach(([u,p])=>{if(p instanceof Array&&A(p)){s[o][u]=new b.VariableType(u);let y=0;p.forEach(_=>{_ instanceof File&&(r[i.current]||(r[i.current]=[]),r[i.current].push("variables."+u+"."+y),n.append(i.current.toString(),_),i.current++,y++)}),e[u]="[Upload!]!"}else p instanceof File?(s[o][u]=new b.VariableType(u),r[i.current]=["variables."+u],n.append(i.current.toString(),p),e[u]="Upload!",i.current++):s[o][u]=p})):a!=null&&(s[o]=a)}),l.__args=s}gt(l,e,r,n,i)}}}const d=async t=>{const{axios:e}=v(),r=t,n=new FormData;let i=!1;const c={},l={};gt(r,c,l,n,{current:0}),i=Object.keys(c).length>0,i&&(r.__variables=c);let s=null;const o={mutation:r},a=b.jsonToGraphQLQuery(o);if(i?(n.append("map",JSON.stringify(l)),n.append("operations",JSON.stringify({query:a})),s=await e.post("",n)):s=await e.post("",{query:a}),s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data},_t=(t,e,r)=>d({sendMail:{__args:{email:t,subject:e,message:r}}}).then(n=>n.sendMail),Tt={send:_t},N=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(N(r)).forEach(([n,i])=>{e[n]=i})}),e):(Object.entries(t).forEach(([r,n])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=n;return}if(typeof n=="boolean"){e[r]=n;return}e[r]=N(n)}),e)},yt=t=>N(t),$t=t=>{const e=typeof window>"u";let r=[];const n=wt.create({baseURL:t,withCredentials:!0});e&&(n.interceptors.request.use(c=>(c.withCredentials=!0,r.length>0&&(c.headers.Cookie=r.join("; ")),c)),n.interceptors.response.use(c=>{if(c.headers["set-cookie"]){const l=c.headers["set-cookie"].map(s=>s.split(";")[0]),h=new Map;r.forEach(s=>{const o=s.split("=")[0];h.set(o,s)}),l.forEach(s=>{const o=s.split("=")[0];h.set(o,s)}),r=Array.from(h.values())}return c}));const i={post:n.post,baseURL:t,axios:n,auth:tt,mutation:d,query:w,config:ht,mail:Tt,users:Nt,model(c){return P(c)},roles:Jt(),collect:(c,l)=>{const h=M(c,l);return h.data_path=P(c).getDataPath(),h},list:(c,l)=>O(c,l).dataPath(P(c).getDataPath()),drive:ot,async collects(c){const l={},h={};for(const o in c){const a=c[o].getQueryPayload();h[o]=a.data_path,l[o]={};const u=a.data_path.split(".");let p=u[u.length-1],y=l[o];for(const _ of u){if(_===p){y[_]=a.query;break}y[_]=y[_]||{}}l[o].__aliasFor=u[0]}const s=await w(l);for(const o in c){const a=h[o].split(".");let u=a[a.length-1],p=s[o];for(const y of a){if(y===u){c[o]._batchData=s[o][y];break}p[y]=p[y]||{}}}return c}};return T(i),i},Rt=O;f.arrayHasFile=A,f.auth=tt,f.changeExpiredPassword=V,f.clearModels=vt,f.createClient=$t,f.createCollection=M,f.createFileFromBase64=At,f.createFileFromBase85=Ct,f.createFileFromString=S,f.createList=O,f.createRole=pt,f.createUser=at,f.defaultUserFields=q,f.defineModel=B,f.defineModels=Et,f.deleteRole=dt,f.deleteUser=ct,f.forgetPassword=Z,f.getApiClient=v,f.getApiClientOptional=mt,f.getConfig=ht,f.getCurrentUser=Q,f.getDrive=ot,f.getGrantedRights=x,f.getModel=P,f.hasModel=Ut,f.isGranted=K,f.list=Rt,f.listDrives=qt,f.listFiles=rt,f.listFolders=it,f.listModels=jt,f.listPermissions=St,f.listRoles=ft,f.listUsers=lt,f.login=G,f.logout=H,f.mutation=d,f.objectHasFile=E,f.query=w,f.readFileAsBase64=st,f.resetPassword=Y,f.sendMail=_t,f.setApiClient=T,f.toQuery=yt,f.updatePassword=X,f.updateUser=ut,f.verifyCode=I,f.webAuthn=z,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(f,b){typeof exports=="object"&&typeof module<"u"?b(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"],b):(f=typeof globalThis<"u"?globalThis:f||self,b(f.light={},f.jsonToGraphqlQuery,f.collect,f.axios))})(this,(function(f,b,k,wt){"use strict";function U(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 j(t,e,r=".",n){if(!U(e))return j(t,{},r,n);const i=Object.assign({},e);for(const c in t){if(c==="__proto__"||c==="constructor")continue;const l=t[c];l!=null&&(n&&n(i,c,l,r)||(Array.isArray(l)&&Array.isArray(i[c])?i[c]=[...l,...i[c]]:U(l)&&U(i[c])?i[c]=j(l,i[c],(r?`${r}.`:"")+c.toString(),n):i[c]=l))}return i}function bt(t){return(...e)=>e.reduce((r,n)=>j(r,n,"",t),{})}const m=bt();let D=null;const T=t=>{D=t},v=()=>{if(!D)throw new Error("Api client not initialized. Call setApiClient() first.");return D},mt=()=>D;function A(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function E(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&A(t[e]))return!0;return!1}function Ft(t){t="<~"+t+"~>";var e,r,n,i,c,l=String,h=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,n=[],i=0,c=t.length;c>i;i+=5)r=52200625*(t.charCodeAt(i)-33)+614125*(t.charCodeAt(i+1)-33)+7225*(t.charCodeAt(i+2)-33)+85*(t.charCodeAt(i+3)-33)+(t.charCodeAt(i+4)-33),n.push(h&r>>24,h&r>>16,h&r>>8,h&r);return(function(s,o){for(var a=o;a>0;a--)s.pop()})(n,e.length),l.fromCharCode.apply(l,n)}const S=(t="")=>{const e=t,r=(n="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let h=0;h<e.length;h++)i[h]=e.charCodeAt(h);const c=new Blob([i],{type:n});return URL.createObjectURL(c)};return{getContent:()=>e,getURL:r,download:n=>{const i=document.createElement("a");i.download=n,i.href=r(),document.body.appendChild(i),i.click(),document.body.removeChild(i)},open:n=>{window.open(r(n),"_blank")}}},At=t=>S(atob(t)),Ct=t=>S(Ft(t));function $(t,e,r,n,i){if(!(!t||typeof t!="object"))for(let c in t){const l=t[c];if(l&&typeof l=="object"){if("__args"in l){const h=l.__args,s={};Object.entries(h).forEach(([o,a])=>{if(a instanceof Array&&A(a)){s[o]=new b.VariableType(o);let u=0;a.forEach(p=>{p instanceof File&&(r[i.current]||(r[i.current]=[]),r[i.current].push("variables."+o+"."+u),n.append(i.current.toString(),p),i.current++,u++)}),e[o]="[Upload!]!"}else a instanceof File?(s[o]=new b.VariableType(o),r[i.current]=["variables."+o],n.append(i.current.toString(),a),e[o]="Upload!",i.current++):a instanceof Object&&E(a)?(s[o]={},Object.entries(a).forEach(([u,p])=>{if(p instanceof Array&&A(p)){s[o][u]=new b.VariableType(u);let _=0;p.forEach(y=>{y instanceof File&&(r[i.current]||(r[i.current]=[]),r[i.current].push("variables."+u+"."+_),n.append(i.current.toString(),y),i.current++,_++)}),e[u]="[Upload!]!"}else p instanceof File?(s[o][u]=new b.VariableType(u),r[i.current]=["variables."+u],n.append(i.current.toString(),p),e[u]="Upload!",i.current++):s[o][u]=p})):a!=null&&(s[o]=a)}),l.__args=s}$(l,e,r,n,i)}}}const w=async t=>{const{axios:e}=v(),r=t,n=new FormData;let i=!1;const c={},l={};$(r,c,l,n,{current:0}),i=Object.keys(c).length>0,i&&(r.__variables=c);let s=null;const o={query:r},a=b.jsonToGraphQLQuery(o);if(i?(n.append("map",JSON.stringify(l)),n.append("operations",JSON.stringify({query:a})),s=await e.post("",n)):s=await e.post("",{query:a}),s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function O(t,e){let r,n=[],i,c;const l=s=>!s||typeof s!="object"?!1:Object.values(s).some(o=>o&&typeof o=="object"&&Object.keys(o).some(a=>a.startsWith("_"))),h=()=>n.length===0?(n.unshift({}),n[0]):(l(n[0])&&n.unshift({}),n[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const o=await this.limit(1).fetch();return Array.isArray(o)&&o.length>0?o[0]:null},async fetchWithMeta(){let o=await w(this.toQuery(!0));if(c){const a=c.split(".");for(const u of a)o=o[u];return o}return o[`list${t}`]},async fetch(){let o=await w(this.toQuery());if(c){const a=c.split(".");for(const u of a)o=o[u];return o.data}return o[`list${t}`].data},dataPath(s){return s&&typeof s=="string"&&(c=s),this},sort(s){return s&&typeof s=="string"&&(i=s),this},filters(s){return s&&typeof s=="object"&&(n=[s]),this},where(s,o,a){const u=(p,_,y)=>{const C={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[_];C&&n.push({[p]:{[C]:y}})};if(a!==void 0)u(s,String(o),a);else{const p=h(),_=m(p,{[s]:o});n[0]=_}return this},whereContains(s,o){if(s&&typeof s=="string"){const a=h(),u={_contains:o};a[s]?Array.isArray(a[s])?a[s].push(u):a[s]=[a[s],u]:a[s]=[u],n[0]=a}return this},whereIn(s,o){if(s&&typeof s=="string"&&Array.isArray(o)){const a=h(),u={_in:o};a[s]?Array.isArray(a[s])?a[s].push(u):a[s]=[a[s],u]:a[s]=[u],n[0]=a}return this},whereBetween(s,o,a){if(s&&typeof s=="string"){const u=h(),p={_between:[o,a]};u[s]?Array.isArray(u[s])?u[s].push(p):u[s]=[u[s],p]:u[s]=p,n[0]=u}return this},limit(s){return typeof s=="number"&&Number.isFinite(s)&&(r=m(r||{},{limit:s})),this},offset(s){return typeof s=="number"&&Number.isFinite(s)&&(r=m(r||{},{offset:s})),this},toQuery(s=!1){let o;const a=n.length>0&&Object.keys(n[0]||{}).length>0,u=a?1:0,p=n.length>u;a&&p?o=n:p?o=n.slice(u):a&&(o=n[0]);const _=m(i?{sort:i}:{},o?{filters:o}:{}),y={data:{...e}};if(r&&(y.data.__args=r),Object.keys(_).length>0&&(y.__args=_),s&&(y.meta={total:!0,key:!0,name:!0}),c){const L=c.split(".");let C=y;for(let J=L.length-1;J>=0;J--)C={[L[J]]:C};return C}return{[`list${t}`]:y}}}}const Ot="list",Dt=["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 g{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}g.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},g.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},g.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},g.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},k().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 h=this._batchData;return this.meta=h.meta,k(h.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},n=r,i=e[e.length-1];for(const h of e){if(h===i){n[h]=t;break}n[h]={},n=n[h]}let l=await w(r);for(const h of e)l=l[h];return this.meta=l.meta,k(l.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 Dt)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Pt)g.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};g.prototype.average=g.prototype.avg,g.prototype.first=async function(){return this.take(1),(await this.processData()).first()},g.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},g.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],n=t[1],i=t[2];switch(n){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: ${n}`)}}return this},g.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},g.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},g.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},g.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},g.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},g.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},g.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},g.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},g.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},g.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},g.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const M=(t,e)=>{const r=new g(e);return r.data_path=Ot+t,r},kt=(t,e={})=>{const r=e;let n="list"+t;const i=c=>r[c]?r[c]:null;return{field:i,$fields:r,setDataPath(c){return n=c,n},getDataPath(){return n},gqlFields(c){let l={};for(const h of c)if(typeof h=="string"){const s=i(h);s&&(l=m(l,s.gqlField?typeof s.gqlField=="string"?{[s.gqlField]:!0}:s.gqlField:{[s.name||h]:!0}))}else typeof h=="object"&&(l=m(l,h));return l},update(c,l){return d({["update"+t]:{__args:{id:c,data:l}}}).then(h=>h["update"+t])},async delete(c){return d({["delete"+t]:{__args:{id:c}}}).then(l=>l["delete"+t])},add(c){return d({["add"+t]:{__args:{data:c}}}).then(l=>l["add"+t])},fields(c){let l=[];for(let h of c){const s=i(h);s&&l.push(s)}return l},async get(c,l){const h=M(t,yt(l));for(const[s,o]of Object.entries(c))h.where(s,"==",o);return await h.first()},list(c){let l=c;const h={};Object.entries(c).forEach(([a])=>{r[a]&&(h[a]=r[a],r[a].gqlField&&(delete l[a],l=m(l,r[a].gqlField)),r[a].gql&&(delete l[a],l=m(l,r[a].gql)))});const s=O(t,l).dataPath(n),o=s.fetch.bind(s);return{...s,async fetch(){return(await o()).map(u=>{const p={...u};return Object.entries(h).forEach(([_,y])=>{y.format&&typeof y.format=="function"&&(p[_]=y.format(u[_],u))}),p})},async fetchFirst(){const u=await s.fetchFirst.bind(s)();if(!u)return u;const p={...u};return Object.entries(h).forEach(([_,y])=>{y.format&&typeof y.format=="function"&&(p[_]=y.format(u))}),p}}}}},F={},B=(t,e)=>{const r=kt(t,e);return F[t]=r,r},P=t=>F[t]?F[t]:B(t,{}),Ut=t=>!!F[t],jt=()=>Object.keys(F),vt=()=>{Object.keys(F).forEach(t=>delete F[t])},Et=t=>{Object.entries(t).forEach(([e,r])=>{B(e,r)})},St=()=>w({app:{permissions:!0}}).then(t=>t.app.permissions),R=async()=>{const{app:t}=await w({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},W=async()=>{const{app:t}=await w({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},z=Object.freeze(Object.defineProperty({__proto__:null,assertion:R,attestation:W,login:async()=>{const t=await R();return await d({webAuthnAssertion:{__args:{assertion:t.toJSON()}}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await W();return await d({webAuthnRegister:{__args:{registration:t.toJSON()}}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),Q=(t=q)=>w({my:t}).then(e=>e.my),G=(t,e,r="")=>d({login:{__args:{username:t,password:e,code:r}}}).then(n=>n.login),H=()=>d({logout:!0}).then(t=>t.logout),V=(t,e,r)=>d({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(n=>n.changeExpiredPassword),X=(t,e)=>d({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),Y=(t,e,r)=>d({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(n=>n.resetPassword),Z=(t,e)=>d({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),I=(t,e)=>d({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),K=t=>w({my:{granted:{__args:{right:t}}}}).then(e=>e.my.granted),x=t=>w({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),tt={getCurrentUser:Q,webAuthn:z,google:{unlink:()=>d({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>d({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>d({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>d({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>d({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>d({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>d({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>d({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>d({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:G,logout:H,changeExpiredPassword:V,updatePassword:X,resetPassword:Y,forgetPassword:Z,verifyCode:I,grantedRights:x,isGranted:K},et={name:!0,path:!0,size:!0,mime:!0,url:!0},rt=(t,e,r=et)=>w({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(n=>n.app.drive.files),st=(t,e)=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}}).then(r=>r.app.drive?.file?.base64Content),Mt=t=>({list:(e,r=et)=>rt(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(n=>n.app.drive.file),readFileAsBase64(e){return st(t,e)},read:async e=>{let r=await w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>d({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(n=>n.lightDriveWriteFile),delete:e=>d({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>d({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFile),move:(e,r)=>d({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(n=>n.lightDriveMoveFile)}),nt={name:!0,path:!0},it=(t,e,r=nt)=>w({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(n=>n.app.drive.folders),Bt=t=>({list:(e,r=nt)=>it(t,e,r),create:e=>d({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>d({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>d({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFolder)}),qt=()=>w({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),ot=t=>{const e=Mt(t),r=Bt(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:n=>d({lightDriveUploadTempFile:{__args:{index:t,file:n},name:!0,path:!0,size:!0,mime:!0}}).then(i=>i.lightDriveUploadTempFile)}},q={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},at=t=>d({addUser:{__args:t}}).then(e=>e.addUser),ct=t=>d({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),lt=(t=q)=>O("Users",t).dataPath("app.listUser").fetch(),ut=(t,e)=>d({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Nt={list:lt,create:at,delete:ct,update:ut},ht=t=>w({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Lt={name:!0},ft=(t=Lt)=>w({app:{roles:t}}).then(e=>e.app.roles),pt=(t,e)=>d({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),dt=t=>d({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),Jt=()=>({list:ft,create:pt,delete:dt});function gt(t,e,r,n,i){if(!(!t||typeof t!="object"))for(let c in t){const l=t[c];if(l&&typeof l=="object"){if("__args"in l){const h=l.__args,s={};Object.entries(h).forEach(([o,a])=>{if(a instanceof Array&&A(a)){s[o]=new b.VariableType(o);let u=0;a.forEach(p=>{p instanceof File&&(r[i.current]||(r[i.current]=[]),r[i.current].push("variables."+o+"."+u),n.append(i.current.toString(),p),i.current++,u++)}),e[o]="[Upload!]!"}else a instanceof File?(s[o]=new b.VariableType(o),r[i.current]=["variables."+o],n.append(i.current.toString(),a),e[o]="Upload!",i.current++):a instanceof Object&&E(a)?(s[o]={},Object.entries(a).forEach(([u,p])=>{if(p instanceof Array&&A(p)){s[o][u]=new b.VariableType(u);let _=0;p.forEach(y=>{y instanceof File&&(r[i.current]||(r[i.current]=[]),r[i.current].push("variables."+u+"."+_),n.append(i.current.toString(),y),i.current++,_++)}),e[u]="[Upload!]!"}else p instanceof File?(s[o][u]=new b.VariableType(u),r[i.current]=["variables."+u],n.append(i.current.toString(),p),e[u]="Upload!",i.current++):s[o][u]=p})):a!=null&&(s[o]=a)}),l.__args=s}gt(l,e,r,n,i)}}}const d=async t=>{const{axios:e}=v(),r=t,n=new FormData;let i=!1;const c={},l={};gt(r,c,l,n,{current:0}),i=Object.keys(c).length>0,i&&(r.__variables=c);let s=null;const o={mutation:r},a=b.jsonToGraphQLQuery(o);if(i?(n.append("map",JSON.stringify(l)),n.append("operations",JSON.stringify({query:a})),s=await e.post("",n)):s=await e.post("",{query:a}),s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data},_t=(t,e,r)=>d({sendMail:{__args:{email:t,subject:e,message:r}}}).then(n=>n.sendMail),Tt={send:_t},N=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(N(r)).forEach(([n,i])=>{e[n]=i})}),e):(Object.entries(t).forEach(([r,n])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=n;return}if(typeof n=="boolean"){e[r]=n;return}e[r]=N(n)}),e)},yt=t=>N(t),$t=t=>{const e=typeof window>"u";let r=[];const n=wt.create({baseURL:t,withCredentials:!0});e&&(n.interceptors.request.use(c=>(c.withCredentials=!0,r.length>0&&(c.headers.Cookie=r.join("; ")),c)),n.interceptors.response.use(c=>{if(c.headers["set-cookie"]){const l=c.headers["set-cookie"].map(s=>s.split(";")[0]),h=new Map;r.forEach(s=>{const o=s.split("=")[0];h.set(o,s)}),l.forEach(s=>{const o=s.split("=")[0];h.set(o,s)}),r=Array.from(h.values())}return c}));const i={post:n.post,baseURL:t,axios:n,auth:tt,mutation:d,query:w,config:ht,mail:Tt,users:Nt,model(c){return P(c)},roles:Jt(),collect:(c,l)=>{const h=M(c,l);return h.data_path=P(c).getDataPath(),h},list:(c,l)=>O(c,l).dataPath(P(c).getDataPath()),drive:ot,async collects(c){const l={},h={};for(const o in c){const a=c[o].getQueryPayload();h[o]=a.data_path,l[o]={};const u=a.data_path.split(".");let p=u[u.length-1],_=l[o];for(const y of u){if(y===p){_[y]=a.query;break}_[y]=_[y]||{}}l[o].__aliasFor=u[0]}const s=await w(l);for(const o in c){const a=h[o].split(".");let u=a[a.length-1],p=s[o];for(const _ of a){if(_===u){c[o]._batchData=s[o][_];break}p[_]=p[_]||{}}}return c}};return T(i),i},Rt=O;f.arrayHasFile=A,f.auth=tt,f.changeExpiredPassword=V,f.clearModels=vt,f.createClient=$t,f.createCollection=M,f.createFileFromBase64=At,f.createFileFromBase85=Ct,f.createFileFromString=S,f.createList=O,f.createRole=pt,f.createUser=at,f.defaultUserFields=q,f.defineModel=B,f.defineModels=Et,f.deleteRole=dt,f.deleteUser=ct,f.forgetPassword=Z,f.getApiClient=v,f.getApiClientOptional=mt,f.getConfig=ht,f.getCurrentUser=Q,f.getDrive=ot,f.getGrantedRights=x,f.getModel=P,f.hasModel=Ut,f.isGranted=K,f.list=Rt,f.listDrives=qt,f.listFiles=rt,f.listFolders=it,f.listModels=jt,f.listPermissions=St,f.listRoles=ft,f.listUsers=lt,f.login=G,f.logout=H,f.mutation=d,f.objectHasFile=E,f.query=w,f.readFileAsBase64=st,f.resetPassword=Y,f.sendMail=_t,f.setApiClient=T,f.toQuery=yt,f.updatePassword=X,f.updateUser=ut,f.verifyCode=I,f.webAuthn=z,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|