@hostlink/light 2.10.0 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createList.d.ts +1 -0
- package/dist/light.js +94 -89
- package/dist/light.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/createList.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
2
|
type Fields = Record<string, any>;
|
|
3
3
|
export default function createList(axios: AxiosInstance, entity: string, fields: Fields): {
|
|
4
|
+
fetchFirst(): Promise<any>;
|
|
4
5
|
fetchWithMeta(): Promise<any>;
|
|
5
6
|
fetch(): Promise<any>;
|
|
6
7
|
dataPath(dataPath?: string): /*elided*/ any;
|
package/dist/light.js
CHANGED
|
@@ -115,9 +115,9 @@ const U = (t) => ({
|
|
|
115
115
|
}), Q = (t, e, r) => {
|
|
116
116
|
const s = e, i = t, h = r;
|
|
117
117
|
let f = "list" + e;
|
|
118
|
-
const
|
|
118
|
+
const a = (c) => h[c] ? h[c]() : null;
|
|
119
119
|
return {
|
|
120
|
-
field:
|
|
120
|
+
field: a,
|
|
121
121
|
$fields: h,
|
|
122
122
|
setDataPath(c) {
|
|
123
123
|
return f = c, f;
|
|
@@ -127,11 +127,11 @@ const U = (t) => ({
|
|
|
127
127
|
},
|
|
128
128
|
gqlFields(c) {
|
|
129
129
|
const n = [];
|
|
130
|
-
for (const
|
|
131
|
-
if (typeof
|
|
132
|
-
const l = o
|
|
130
|
+
for (const o of c)
|
|
131
|
+
if (typeof o == "string") {
|
|
132
|
+
const l = a(o);
|
|
133
133
|
l && n.push(l.getGQLField());
|
|
134
|
-
} else typeof
|
|
134
|
+
} else typeof o == "object" && n.push(o);
|
|
135
135
|
return n;
|
|
136
136
|
},
|
|
137
137
|
async update(c, n) {
|
|
@@ -145,20 +145,20 @@ const U = (t) => ({
|
|
|
145
145
|
},
|
|
146
146
|
fields(c) {
|
|
147
147
|
let n = [];
|
|
148
|
-
for (let
|
|
149
|
-
const l = o
|
|
148
|
+
for (let o of c) {
|
|
149
|
+
const l = a(o);
|
|
150
150
|
l && n.push(l);
|
|
151
151
|
}
|
|
152
152
|
return n;
|
|
153
153
|
},
|
|
154
154
|
async get(c, n) {
|
|
155
|
-
const
|
|
155
|
+
const o = (await Promise.resolve().then(() => B)).default, l = o(s, i, O(n));
|
|
156
156
|
for (const [u, d] of Object.entries(c))
|
|
157
157
|
l.where(u, "==", d);
|
|
158
158
|
return await l.first();
|
|
159
159
|
},
|
|
160
160
|
async list(c, n) {
|
|
161
|
-
const
|
|
161
|
+
const o = (await Promise.resolve().then(() => B)).default, l = o(s, i, O(n));
|
|
162
162
|
for (const [u, d] of Object.entries(c))
|
|
163
163
|
l.where(u, "==", d);
|
|
164
164
|
return await l.all();
|
|
@@ -167,17 +167,17 @@ const U = (t) => ({
|
|
|
167
167
|
};
|
|
168
168
|
function T(t) {
|
|
169
169
|
t = "<~" + t + "~>";
|
|
170
|
-
var e, r, s, i, h, f = String,
|
|
171
|
-
for (t.slice(0, 2) === "<~" && t.slice(-2), t = t.slice(2, -2).replace(/\s/g, "").replace("z", "!!!!!"), e = "uuuuu".slice(t.length % 5 || 5), t += e, s = [], i = 0, h = t.length; h > i; i += 5) r = 52200625 * (t.charCodeAt(i) - 33) + 614125 * (t.charCodeAt(i + 1) - 33) + 7225 * (t.charCodeAt(i + 2) - 33) + 85 * (t.charCodeAt(i + 3) - 33) + (t.charCodeAt(i + 4) - 33), s.push(
|
|
170
|
+
var e, r, s, i, h, f = String, a = 255;
|
|
171
|
+
for (t.slice(0, 2) === "<~" && t.slice(-2), t = t.slice(2, -2).replace(/\s/g, "").replace("z", "!!!!!"), e = "uuuuu".slice(t.length % 5 || 5), t += e, s = [], i = 0, h = t.length; h > i; i += 5) r = 52200625 * (t.charCodeAt(i) - 33) + 614125 * (t.charCodeAt(i + 1) - 33) + 7225 * (t.charCodeAt(i + 2) - 33) + 85 * (t.charCodeAt(i + 3) - 33) + (t.charCodeAt(i + 4) - 33), s.push(a & r >> 24, a & r >> 16, a & r >> 8, a & r);
|
|
172
172
|
return function(c, n) {
|
|
173
|
-
for (var
|
|
173
|
+
for (var o = n; o > 0; o--) c.pop();
|
|
174
174
|
}(s, e.length), f.fromCharCode.apply(f, s);
|
|
175
175
|
}
|
|
176
176
|
const D = (t = "") => {
|
|
177
177
|
const e = t, r = (s = "application/octet-stream") => {
|
|
178
178
|
const i = new Uint8Array(e.length);
|
|
179
|
-
for (let
|
|
180
|
-
i[
|
|
179
|
+
for (let a = 0; a < e.length; a++)
|
|
180
|
+
i[a] = e.charCodeAt(a);
|
|
181
181
|
const h = new Blob([i], { type: s });
|
|
182
182
|
return URL.createObjectURL(h);
|
|
183
183
|
};
|
|
@@ -241,32 +241,32 @@ const p = async (t, e, r = null, s = []) => {
|
|
|
241
241
|
const h = new FormData();
|
|
242
242
|
let f = !1;
|
|
243
243
|
if (r) {
|
|
244
|
-
const n = {},
|
|
244
|
+
const n = {}, o = {}, l = {};
|
|
245
245
|
let u = 0;
|
|
246
246
|
Object.entries(r).forEach(([d, _]) => {
|
|
247
247
|
if (_ instanceof Array && W(_)) {
|
|
248
248
|
f = !0;
|
|
249
249
|
let y = 0;
|
|
250
250
|
_.forEach((w) => {
|
|
251
|
-
w instanceof File && (n[d] = new k(d),
|
|
251
|
+
w instanceof File && (n[d] = new k(d), o[u] = ["variables." + d + "." + y], h.append(u.toString(), w), u++);
|
|
252
252
|
}), l[d] = "[Upload!]!";
|
|
253
|
-
} else _ instanceof File ? (f = !0, n[d] = new k(d),
|
|
254
|
-
w instanceof File ? (n[d][y] = new k(y),
|
|
253
|
+
} else _ instanceof File ? (f = !0, n[d] = new k(d), o[u] = ["variables." + d], h.append(u.toString(), _), l[d] = "Upload!", u++) : _ instanceof Object && $(_) ? (f = !0, n[d] = {}, Object.entries(_).forEach(([y, w]) => {
|
|
254
|
+
w instanceof File ? (n[d][y] = new k(y), o[u] = ["variables." + y], h.append(u.toString(), w), l[y] = "Upload!", u++) : n[d][y] = w;
|
|
255
255
|
})) : _ !== void 0 && (n[d] = _);
|
|
256
|
-
}), i[e].__args = n, i.__variables = l, f && h.append("map", JSON.stringify(
|
|
256
|
+
}), i[e].__args = n, i.__variables = l, f && h.append("map", JSON.stringify(o));
|
|
257
257
|
}
|
|
258
|
-
Object.entries(O(s)).forEach(([n,
|
|
259
|
-
i[e][n] =
|
|
258
|
+
Object.entries(O(s)).forEach(([n, o]) => {
|
|
259
|
+
i[e][n] = o;
|
|
260
260
|
}), Object.entries(i[e]).length === 0 && (i[e] = !0);
|
|
261
|
-
let
|
|
261
|
+
let a = null;
|
|
262
262
|
const c = E({ mutation: i });
|
|
263
263
|
if (f ? (h.append("operations", JSON.stringify({
|
|
264
264
|
query: c
|
|
265
|
-
})),
|
|
265
|
+
})), a = await t.post("", h)) : a = await t.post("", {
|
|
266
266
|
query: c
|
|
267
|
-
}),
|
|
268
|
-
throw new Error(
|
|
269
|
-
return
|
|
267
|
+
}), a.data.errors)
|
|
268
|
+
throw new Error(a.data.errors[0].message);
|
|
269
|
+
return a.data.data[e];
|
|
270
270
|
}, z = (t) => ({
|
|
271
271
|
uploadTempFile: (e) => p(t, "fsUploadTempFile", {
|
|
272
272
|
file: e
|
|
@@ -366,12 +366,12 @@ const p = async (t, e, r = null, s = []) => {
|
|
|
366
366
|
r[s] = null;
|
|
367
367
|
let h = {};
|
|
368
368
|
for (const f of Object.entries(i)) {
|
|
369
|
-
const [
|
|
370
|
-
h[
|
|
371
|
-
name: c.name ? c.name :
|
|
369
|
+
const [a, c] = f;
|
|
370
|
+
h[a] = () => ({
|
|
371
|
+
name: c.name ? c.name : a,
|
|
372
372
|
raw: c,
|
|
373
|
-
getName: () => c.name ? c.name :
|
|
374
|
-
getGQLField: () => c.gqlField !== void 0 ? c.gqlField : c.name ||
|
|
373
|
+
getName: () => c.name ? c.name : a,
|
|
374
|
+
getGQLField: () => c.gqlField !== void 0 ? c.gqlField : c.name || a,
|
|
375
375
|
getRaw() {
|
|
376
376
|
return c;
|
|
377
377
|
},
|
|
@@ -379,8 +379,8 @@ const p = async (t, e, r = null, s = []) => {
|
|
|
379
379
|
return c.field && typeof c.field == "function" ? c.field(n) : c.field && typeof c.field == "string" ? n[c.field] : n[this.getName()];
|
|
380
380
|
},
|
|
381
381
|
getFormattedValue(n) {
|
|
382
|
-
const
|
|
383
|
-
return c.format ? c.format(
|
|
382
|
+
const o = this.getValue(n);
|
|
383
|
+
return c.format ? c.format(o) : o;
|
|
384
384
|
}
|
|
385
385
|
});
|
|
386
386
|
}
|
|
@@ -505,8 +505,8 @@ j().macro("whereContains", function(t, e) {
|
|
|
505
505
|
g.prototype.fetchData = async function() {
|
|
506
506
|
try {
|
|
507
507
|
if (this._batchData) {
|
|
508
|
-
const
|
|
509
|
-
return this.meta =
|
|
508
|
+
const a = this._batchData;
|
|
509
|
+
return this.meta = a.meta, j(a.data);
|
|
510
510
|
}
|
|
511
511
|
let t = {
|
|
512
512
|
meta: {
|
|
@@ -518,16 +518,16 @@ g.prototype.fetchData = async function() {
|
|
|
518
518
|
t.__args = this.buildArgs(), t.data = this.fields, this.already_limit && (t.data.__args = t.data.__args || {}, t.data.__args.limit = this.limit), this.already_offset && (t.data.__args = t.data.__args || {}, t.data.__args.offset = this.offset);
|
|
519
519
|
const e = this.data_path.split(".");
|
|
520
520
|
let r = {}, s = r, i = e[e.length - 1];
|
|
521
|
-
for (const
|
|
522
|
-
if (
|
|
523
|
-
s[
|
|
521
|
+
for (const a of e) {
|
|
522
|
+
if (a === i) {
|
|
523
|
+
s[a] = t;
|
|
524
524
|
break;
|
|
525
525
|
}
|
|
526
|
-
s[
|
|
526
|
+
s[a] = {}, s = s[a];
|
|
527
527
|
}
|
|
528
528
|
let f = await m(this.axios, r);
|
|
529
|
-
for (const
|
|
530
|
-
f = f[
|
|
529
|
+
for (const a of e)
|
|
530
|
+
f = f[a];
|
|
531
531
|
return this.meta = f.meta, j(f.data);
|
|
532
532
|
} catch (t) {
|
|
533
533
|
throw console.error("Error fetching collection data:", t), t;
|
|
@@ -772,25 +772,30 @@ function tt(t) {
|
|
|
772
772
|
const C = tt();
|
|
773
773
|
function et(t, e, r) {
|
|
774
774
|
let s, i = [], h, f;
|
|
775
|
-
const
|
|
775
|
+
const a = (n) => !n || typeof n != "object" ? !1 : Object.values(n).some((o) => o && typeof o == "object" && Object.keys(o).some((l) => l.startsWith("_"))), c = () => i.length === 0 ? (i.unshift({}), i[0]) : (a(i[0]) && i.unshift({}), i[0]);
|
|
776
776
|
return {
|
|
777
|
+
async fetchFirst() {
|
|
778
|
+
return await this.limit(1).fetch().then((o) => Array.isArray(o) && o.length > 0 ? o[0] : null);
|
|
779
|
+
},
|
|
777
780
|
async fetchWithMeta() {
|
|
778
|
-
let
|
|
781
|
+
let o = await m(t, this.toQuery(!0));
|
|
779
782
|
if (f) {
|
|
780
783
|
const l = f.split(".");
|
|
781
784
|
for (const u of l)
|
|
782
|
-
|
|
785
|
+
o = o[u];
|
|
786
|
+
return o;
|
|
783
787
|
}
|
|
784
|
-
return
|
|
788
|
+
return o[`list${e}`];
|
|
785
789
|
},
|
|
786
790
|
async fetch() {
|
|
787
|
-
let
|
|
791
|
+
let o = await m(t, this.toQuery());
|
|
788
792
|
if (f) {
|
|
789
793
|
const l = f.split(".");
|
|
790
794
|
for (const u of l)
|
|
791
|
-
|
|
795
|
+
o = o[u];
|
|
796
|
+
return o.data;
|
|
792
797
|
}
|
|
793
|
-
return
|
|
798
|
+
return o[`list${e}`].data;
|
|
794
799
|
},
|
|
795
800
|
dataPath(n) {
|
|
796
801
|
return n && typeof n == "string" && (f = n), this;
|
|
@@ -804,7 +809,7 @@ function et(t, e, r) {
|
|
|
804
809
|
// where can be called as:
|
|
805
810
|
// where('key', value) -> exact match
|
|
806
811
|
// where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
|
|
807
|
-
where(n,
|
|
812
|
+
where(n, o, l) {
|
|
808
813
|
const u = (d, _, y) => {
|
|
809
814
|
const A = {
|
|
810
815
|
">": "_gt",
|
|
@@ -818,18 +823,18 @@ function et(t, e, r) {
|
|
|
818
823
|
A && i.push({ [d]: { [A]: y } });
|
|
819
824
|
};
|
|
820
825
|
if (l !== void 0)
|
|
821
|
-
u(n, String(
|
|
826
|
+
u(n, String(o), l);
|
|
822
827
|
else {
|
|
823
|
-
const d = c(), _ = C(d, { [n]:
|
|
828
|
+
const d = c(), _ = C(d, { [n]: o });
|
|
824
829
|
i[0] = _;
|
|
825
830
|
}
|
|
826
831
|
return this;
|
|
827
832
|
},
|
|
828
833
|
// whereContains adds a _contains filter for a specific field
|
|
829
834
|
// If the same field is used multiple times, it merges them into an array
|
|
830
|
-
whereContains(n,
|
|
835
|
+
whereContains(n, o) {
|
|
831
836
|
if (n && typeof n == "string") {
|
|
832
|
-
const l = c(), u = { _contains:
|
|
837
|
+
const l = c(), u = { _contains: o };
|
|
833
838
|
l[n] ? Array.isArray(l[n]) ? l[n].push(u) : l[n] = [l[n], u] : l[n] = [u], i[0] = l;
|
|
834
839
|
}
|
|
835
840
|
return this;
|
|
@@ -837,17 +842,17 @@ function et(t, e, r) {
|
|
|
837
842
|
// ...existing code...
|
|
838
843
|
// whereIn adds an _in filter for a specific field
|
|
839
844
|
// If the same field is used multiple times, it merges them into an array
|
|
840
|
-
whereIn(n,
|
|
841
|
-
if (n && typeof n == "string" && Array.isArray(
|
|
842
|
-
const l = c(), u = { _in:
|
|
845
|
+
whereIn(n, o) {
|
|
846
|
+
if (n && typeof n == "string" && Array.isArray(o)) {
|
|
847
|
+
const l = c(), u = { _in: o };
|
|
843
848
|
l[n] ? Array.isArray(l[n]) ? l[n].push(u) : l[n] = [l[n], u] : l[n] = [u], i[0] = l;
|
|
844
849
|
}
|
|
845
850
|
return this;
|
|
846
851
|
},
|
|
847
852
|
// whereBetween adds a _between filter for a specific field
|
|
848
|
-
whereBetween(n,
|
|
853
|
+
whereBetween(n, o, l) {
|
|
849
854
|
if (n && typeof n == "string") {
|
|
850
|
-
const u = c(), d = { _between: [
|
|
855
|
+
const u = c(), d = { _between: [o, l] };
|
|
851
856
|
u[n] ? Array.isArray(u[n]) ? u[n].push(d) : u[n] = [u[n], d] : u[n] = d, i[0] = u;
|
|
852
857
|
}
|
|
853
858
|
return this;
|
|
@@ -861,12 +866,12 @@ function et(t, e, r) {
|
|
|
861
866
|
return typeof n == "number" && Number.isFinite(n) && (s = C(s || {}, { offset: n })), this;
|
|
862
867
|
},
|
|
863
868
|
toQuery(n = !1) {
|
|
864
|
-
let
|
|
869
|
+
let o;
|
|
865
870
|
const l = i.length > 0 && Object.keys(i[0] || {}).length > 0, u = l ? 1 : 0, d = i.length > u;
|
|
866
|
-
l && d ?
|
|
871
|
+
l && d ? o = i : d ? o = i.slice(u) : l && (o = i[0]);
|
|
867
872
|
const _ = C(
|
|
868
873
|
h ? { sort: h } : {},
|
|
869
|
-
|
|
874
|
+
o ? { filters: o } : {}
|
|
870
875
|
), y = {
|
|
871
876
|
data: {
|
|
872
877
|
...r
|
|
@@ -898,20 +903,20 @@ const at = (t) => {
|
|
|
898
903
|
baseURL: t,
|
|
899
904
|
withCredentials: !0
|
|
900
905
|
});
|
|
901
|
-
e && (s.interceptors.request.use((
|
|
902
|
-
if (
|
|
903
|
-
const c =
|
|
904
|
-
r.forEach((
|
|
905
|
-
const l =
|
|
906
|
-
n.set(l,
|
|
907
|
-
}), c.forEach((
|
|
908
|
-
const l =
|
|
909
|
-
n.set(l,
|
|
906
|
+
e && (s.interceptors.request.use((a) => (a.withCredentials = !0, r.length > 0 && (a.headers.Cookie = r.join("; ")), a)), s.interceptors.response.use((a) => {
|
|
907
|
+
if (a.headers["set-cookie"]) {
|
|
908
|
+
const c = a.headers["set-cookie"].map((o) => o.split(";")[0]), n = /* @__PURE__ */ new Map();
|
|
909
|
+
r.forEach((o) => {
|
|
910
|
+
const l = o.split("=")[0];
|
|
911
|
+
n.set(l, o);
|
|
912
|
+
}), c.forEach((o) => {
|
|
913
|
+
const l = o.split("=")[0];
|
|
914
|
+
n.set(l, o);
|
|
910
915
|
}), r = Array.from(n.values());
|
|
911
916
|
}
|
|
912
|
-
return
|
|
917
|
+
return a;
|
|
913
918
|
}));
|
|
914
|
-
const i = (
|
|
919
|
+
const i = (a, c = null, n = []) => p(s, a, c, n), h = (a) => m(s, a), f = V(s);
|
|
915
920
|
return {
|
|
916
921
|
baseURL: t,
|
|
917
922
|
axios: s,
|
|
@@ -923,22 +928,22 @@ const at = (t) => {
|
|
|
923
928
|
users: K(s),
|
|
924
929
|
fs: z(s),
|
|
925
930
|
models: f,
|
|
926
|
-
model(
|
|
927
|
-
return f.get(
|
|
931
|
+
model(a) {
|
|
932
|
+
return f.get(a);
|
|
928
933
|
},
|
|
929
934
|
roles: H(s),
|
|
930
|
-
collect: (
|
|
931
|
-
const n = N(
|
|
932
|
-
return n.data_path = f.get(
|
|
935
|
+
collect: (a, c) => {
|
|
936
|
+
const n = N(a, s, c);
|
|
937
|
+
return n.data_path = f.get(a).getDataPath(), n;
|
|
933
938
|
},
|
|
934
|
-
list: (
|
|
935
|
-
drive(
|
|
936
|
-
return x(
|
|
939
|
+
list: (a, c) => et(s, a, c).dataPath(f.get(a).getDataPath()),
|
|
940
|
+
drive(a) {
|
|
941
|
+
return x(a, s);
|
|
937
942
|
},
|
|
938
|
-
async collects(
|
|
943
|
+
async collects(a) {
|
|
939
944
|
const c = {}, n = {};
|
|
940
|
-
for (const l in
|
|
941
|
-
const u =
|
|
945
|
+
for (const l in a) {
|
|
946
|
+
const u = a[l].getQueryPayload();
|
|
942
947
|
n[l] = u.data_path, c[l] = {};
|
|
943
948
|
const d = u.data_path.split(".");
|
|
944
949
|
let _ = d[d.length - 1], y = c[l];
|
|
@@ -951,19 +956,19 @@ const at = (t) => {
|
|
|
951
956
|
}
|
|
952
957
|
c[l].__aliasFor = d[0];
|
|
953
958
|
}
|
|
954
|
-
const
|
|
955
|
-
for (const l in
|
|
959
|
+
const o = await m(s, c);
|
|
960
|
+
for (const l in a) {
|
|
956
961
|
const u = n[l].split(".");
|
|
957
|
-
let d = u[u.length - 1], _ =
|
|
962
|
+
let d = u[u.length - 1], _ = o[l];
|
|
958
963
|
for (const y of u) {
|
|
959
964
|
if (y === d) {
|
|
960
|
-
|
|
965
|
+
a[l]._batchData = o[l][y];
|
|
961
966
|
break;
|
|
962
967
|
}
|
|
963
968
|
_[y] = _[y] || {};
|
|
964
969
|
}
|
|
965
970
|
}
|
|
966
|
-
return
|
|
971
|
+
return a;
|
|
967
972
|
}
|
|
968
973
|
};
|
|
969
974
|
};
|
package/dist/light.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(_,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],m):(_=typeof globalThis<"u"?globalThis:_||self,m(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,m,O,P){"use strict";var rt=Object.defineProperty;var st=(_,m,O)=>m in _?rt(_,m,{enumerable:!0,configurable:!0,writable:!0,value:O}):_[m]=O;var C=(_,m,O)=>st(_,typeof m!="symbol"?m+"":m,O);const q=t=>({assertion:async()=>{const{app:s}=await b(t,{app:{auth:{webAuthnRequestOptions:!0}}}),i=s.auth.webAuthnRequestOptions,h=PublicKeyCredential.parseRequestOptionsFromJSON(i);return await navigator.credentials.get({publicKey:h})},attestation:async()=>{const{app:s}=await b(t,{app:{auth:{webAuthnCreationOptions:!0}}}),i=PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:i})}}),L=t=>{const{assertion:e,attestation:r}=q(t);return{login:async()=>{const s=await e();await p(t,"webAuthnAssertion",{assertion:s.toJSON()})},register:async()=>{const s=await r();await p(t,"webAuthnRegister",{registration:s.toJSON()})}}},U=t=>({WebAuthn:L(t),google:{unlink:()=>p(t,"lightAuthUnlinkGoogle"),login:e=>p(t,"lightAuthLoginGoogle",{credential:e}),register:e=>p(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>p(t,"lightAuthUnlinkFacebook"),login:e=>p(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>p(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>p(t,"lightAuthUnlinkMicrosoft"),login:e=>p(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>p(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>p(t,"login",{username:e,password:r,code:s}),logout:()=>p(t,"logout"),changeExpiredPassword:(e,r,s)=>p(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>p(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>p(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>p(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return p(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await b(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}}),J=(t,e,r)=>{const s=e,i=t,h=r;let f="list"+e;const o=u=>h[u]?h[u]():null;return{field:o,$fields:h,setDataPath(u){return f=u,f},getDataPath(){return f},gqlFields(u){const n=[];for(const a of u)if(typeof a=="string"){const l=o(a);l&&n.push(l.getGQLField())}else typeof a=="object"&&n.push(a);return n},async update(u,n){return await p(i,"update"+s,{id:u,data:n})},async delete(u){return await p(i,"delete"+s,{id:u})},async add(u){return await p(i,"add"+s,{data:u})},fields(u){let n=[];for(let a of u){const l=o(a);l&&n.push(l)}return n},async get(u,n){const a=(await Promise.resolve().then(()=>R)).default,l=a(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.first()},async list(u,n){const a=(await Promise.resolve().then(()=>R)).default,l=a(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.all()}}};function M(t){t="<~"+t+"~>";var e,r,s,i,h,f=String,o=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],i=0,h=t.length;h>i;i+=5)r=52200625*(t.charCodeAt(i)-33)+614125*(t.charCodeAt(i+1)-33)+7225*(t.charCodeAt(i+2)-33)+85*(t.charCodeAt(i+3)-33)+(t.charCodeAt(i+4)-33),s.push(o&r>>24,o&r>>16,o&r>>8,o&r);return function(u,n){for(var a=n;a>0;a--)u.pop()}(s,e.length),f.fromCharCode.apply(f,s)}const D=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let o=0;o<e.length;o++)i[o]=e.charCodeAt(o);const h=new Blob([i],{type:s});return URL.createObjectURL(h)};return{getContent:()=>e,getURL:r,download:s=>{const i=document.createElement("a");i.download=s,i.href=r(),document.body.appendChild(i),i.click(),document.body.removeChild(i)},open:s=>{window.open(r(s),"_blank")}}},T={fromBase85:t=>D(M(t)),fromBase64:t=>D(atob(t)),fromString:t=>D(t)},S=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(S(r)).forEach(([s,i])=>{e[s]=i})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=S(s)}),e)},k=t=>S(t),b=async(t,e)=>{let r=m.jsonToGraphQLQuery(k(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function W(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function Q(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const p=async(t,e,r=null,s=[])=>{let i={[e]:{}};const h=new FormData;let f=!1;if(r){const n={},a={},l={};let c=0;Object.entries(r).forEach(([d,w])=>{if(w instanceof Array&&W(w)){f=!0;let y=0;w.forEach(A=>{A instanceof File&&(n[d]=new m.VariableType(d),a[c]=["variables."+d+"."+y],h.append(c.toString(),A),c++)}),l[d]="[Upload!]!"}else w instanceof File?(f=!0,n[d]=new m.VariableType(d),a[c]=["variables."+d],h.append(c.toString(),w),l[d]="Upload!",c++):w instanceof Object&&Q(w)?(f=!0,n[d]={},Object.entries(w).forEach(([y,A])=>{A instanceof File?(n[d][y]=new m.VariableType(y),a[c]=["variables."+y],h.append(c.toString(),A),l[y]="Upload!",c++):n[d][y]=A})):w!==void 0&&(n[d]=w)}),i[e].__args=n,i.__variables=l,f&&h.append("map",JSON.stringify(a))}Object.entries(k(s)).forEach(([n,a])=>{i[e][n]=a}),Object.entries(i[e]).length===0&&(i[e]=!0);let o=null;const u=m.jsonToGraphQLQuery({mutation:i});if(f?(h.append("operations",JSON.stringify({query:u})),o=await t.post("",h)):o=await t.post("",{query:u}),o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data[e]},$=t=>({uploadTempFile:e=>p(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await b(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>p(t,"fsCreateFolder",{path:e}),delete:e=>p(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>p(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await b(t,{app:{drive:{files:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}}}});return r.drive.files},read:async e=>{let{app:r}=await b(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>p(t,"fsWriteFile",{path:e,content:r}),delete:e=>p(t,"fsDeleteFile",{path:e}),rename:(e,r)=>p(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>p(t,"fsMoveFile",{source:e,target:r})}}),z=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),I=t=>({send:(e,r,s)=>p(t,"sendMail",{email:e,subject:r,message:s})}),K=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=j("Users",t,e);return r.data_path="app.users",r.all()}}),G=t=>{const e=t,r={};return{create(s,i){r[s]=null;let h={};for(const f of Object.entries(i)){const[o,u]=f;h[o]=()=>({name:u.name?u.name:o,raw:u,getName:()=>u.name?u.name:o,getGQLField:()=>u.gqlField!==void 0?u.gqlField:u.name||o,getRaw(){return u},getValue(n){return u.field&&typeof u.field=="function"?u.field(n):u.field&&typeof u.field=="string"?n[u.field]:n[this.getName()]},getFormattedValue(n){const a=this.getValue(n);return u.format?u.format(a):a}})}r[s]=J(e,s,h)},get(s){return r[s]||this.create(s,{}),r[s]}}},V=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await b(t,{app:{roles:e}});return r}}),H="list",X=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],Y=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition"];class g{constructor(e,r){C(this,"_batchData",null);C(this,"data_path","");C(this,"axios");C(this,"filters");C(this,"steps");C(this,"fields");C(this,"already_limit",!1);C(this,"already_offset",!1);C(this,"limit",null);C(this,"offset",null);C(this,"_sort",null);C(this,"_sortDesc",!1);C(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}g.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},g.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},g.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},g.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},P().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),g.prototype.fetchData=async function(){try{if(this._batchData){const o=this._batchData;return this.meta=o.meta,P(o.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,i=e[e.length-1];for(const o of e){if(o===i){s[o]=t;break}s[o]={},s=s[o]}let f=await b(this.axios,r);for(const o of e)f=f[o];return this.meta=f.meta,P(f.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},g.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},g.prototype.all=async function(){return(await this.processData()).all()};for(const t of X)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Y)g.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};g.prototype.average=g.prototype.avg,g.prototype.first=async function(){return this.take(1),(await this.processData()).first()},g.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},g.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],s=t[1],i=t[2];switch(s){case"==":this.filters[r]=i;break;case"<":this.filters[r]={lt:i};break;case"<=":this.filters[r]={lte:i};break;case">":this.filters[r]={gt:i};break;case">=":this.filters[r]={gte:i};break;case"!==":this.filters[r]={ne:i};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},g.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},g.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},g.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},g.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},g.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},g.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},g.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},g.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},g.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},g.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},g.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const j=(t,e,r)=>{const s=new g(r,e);return s.data_path=H+t,s},R=Object.freeze(Object.defineProperty({__proto__:null,default:j},Symbol.toStringTag,{value:"Module"})),Z=(t,e)=>({uploadTempFile:r=>p(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await b(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>p(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>p(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await b(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await b(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await b(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});if(!s.app.drive.file||!s.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${r}`);return typeof window<"u"&&window.atob?window.atob(s.app.drive.file.base64Content):s.app.drive.file.base64Content},write:(r,s)=>p(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>p(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>p(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}});function N(t){if(t===null||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null||Symbol.iterator in t?!1:Symbol.toStringTag in t?Object.prototype.toString.call(t)==="[object Module]":!0}function B(t,e,r=".",s){if(!N(e))return B(t,{},r,s);const i=Object.assign({},e);for(const h in t){if(h==="__proto__"||h==="constructor")continue;const f=t[h];f!=null&&(s&&s(i,h,f,r)||(Array.isArray(f)&&Array.isArray(i[h])?i[h]=[...f,...i[h]]:N(f)&&N(i[h])?i[h]=B(f,i[h],(r?`${r}.`:"")+h.toString(),s):i[h]=f))}return i}function x(t){return(...e)=>e.reduce((r,s)=>B(r,s,"",t),{})}const v=x();function tt(t,e,r){let s,i=[],h,f;const o=n=>!n||typeof n!="object"?!1:Object.values(n).some(a=>a&&typeof a=="object"&&Object.keys(a).some(l=>l.startsWith("_"))),u=()=>i.length===0?(i.unshift({}),i[0]):(o(i[0])&&i.unshift({}),i[0]);return{async fetchWithMeta(){let a=await b(t,this.toQuery(!0));if(f){const l=f.split(".");for(const c of l)a=a[c]}return a[`list${e}`]},async fetch(){let a=await b(t,this.toQuery());if(f){const l=f.split(".");for(const c of l)a=a[c]}return a[`list${e}`].data},dataPath(n){return n&&typeof n=="string"&&(f=n),this},sort(n){return n&&typeof n=="string"&&(h=n),this},filters(n){return n&&typeof n=="object"&&(i=[n]),this},where(n,a,l){const c=(d,w,y)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[w];F&&i.push({[d]:{[F]:y}})};if(l!==void 0)c(n,String(a),l);else{const d=u(),w=v(d,{[n]:a});i[0]=w}return this},whereContains(n,a){if(n&&typeof n=="string"){const l=u(),c={_contains:a};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereIn(n,a){if(n&&typeof n=="string"&&Array.isArray(a)){const l=u(),c={_in:a};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereBetween(n,a,l){if(n&&typeof n=="string"){const c=u(),d={_between:[a,l]};c[n]?Array.isArray(c[n])?c[n].push(d):c[n]=[c[n],d]:c[n]=d,i[0]=c}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{offset:n})),this},toQuery(n=!1){let a;const l=i.length>0&&Object.keys(i[0]||{}).length>0,c=l?1:0,d=i.length>c;l&&d?a=i:d?a=i.slice(c):l&&(a=i[0]);const w=v(h?{sort:h}:{},a?{filters:a}:{}),y={data:{...r}};if(s&&(y.data.__args=s),Object.keys(w).length>0&&(y.__args=w),n&&(y.meta={total:!0,key:!0,name:!0}),f){const A=f.split(".");let F=y;for(let E=A.length-1;E>=0;E--)F={[A[E]]:F};return F}return{[`list${e}`]:y}}}}const et=t=>{const e=typeof window>"u";let r=[];const s=O.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(o=>(o.withCredentials=!0,r.length>0&&(o.headers.Cookie=r.join("; ")),o)),s.interceptors.response.use(o=>{if(o.headers["set-cookie"]){const u=o.headers["set-cookie"].map(a=>a.split(";")[0]),n=new Map;r.forEach(a=>{const l=a.split("=")[0];n.set(l,a)}),u.forEach(a=>{const l=a.split("=")[0];n.set(l,a)}),r=Array.from(n.values())}return o}));const i=(o,u=null,n=[])=>p(s,o,u,n),h=o=>b(s,o),f=G(s);return{baseURL:t,axios:s,auth:U(s),mutation:i,query:h,config:z(h),mail:I(s),users:K(s),fs:$(s),models:f,model(o){return f.get(o)},roles:V(s),collect:(o,u)=>{const n=j(o,s,u);return n.data_path=f.get(o).getDataPath(),n},list:(o,u)=>tt(s,o,u).dataPath(f.get(o).getDataPath()),drive(o){return Z(o,s)},async collects(o){const u={},n={};for(const l in o){const c=o[l].getQueryPayload();n[l]=c.data_path,u[l]={};const d=c.data_path.split(".");let w=d[d.length-1],y=u[l];for(const A of d){if(A===w){y[A]=c.query;break}y[A]=y[A]||{}}u[l].__aliasFor=d[0]}const a=await b(s,u);for(const l in o){const c=n[l].split(".");let d=c[c.length-1],w=a[l];for(const y of c){if(y===d){o[l]._batchData=a[l][y];break}w[y]=w[y]||{}}}return o}}};_.File=T,_.createClient=et,_.createCollection=j,_.file=D,_.mutation=p,_.query=b,_.toQuery=k,_.useWebAuthn=q,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(_,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],m):(_=typeof globalThis<"u"?globalThis:_||self,m(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,m,O,P){"use strict";var rt=Object.defineProperty;var st=(_,m,O)=>m in _?rt(_,m,{enumerable:!0,configurable:!0,writable:!0,value:O}):_[m]=O;var C=(_,m,O)=>st(_,typeof m!="symbol"?m+"":m,O);const q=t=>({assertion:async()=>{const{app:s}=await b(t,{app:{auth:{webAuthnRequestOptions:!0}}}),i=s.auth.webAuthnRequestOptions,h=PublicKeyCredential.parseRequestOptionsFromJSON(i);return await navigator.credentials.get({publicKey:h})},attestation:async()=>{const{app:s}=await b(t,{app:{auth:{webAuthnCreationOptions:!0}}}),i=PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:i})}}),L=t=>{const{assertion:e,attestation:r}=q(t);return{login:async()=>{const s=await e();await p(t,"webAuthnAssertion",{assertion:s.toJSON()})},register:async()=>{const s=await r();await p(t,"webAuthnRegister",{registration:s.toJSON()})}}},U=t=>({WebAuthn:L(t),google:{unlink:()=>p(t,"lightAuthUnlinkGoogle"),login:e=>p(t,"lightAuthLoginGoogle",{credential:e}),register:e=>p(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>p(t,"lightAuthUnlinkFacebook"),login:e=>p(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>p(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>p(t,"lightAuthUnlinkMicrosoft"),login:e=>p(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>p(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>p(t,"login",{username:e,password:r,code:s}),logout:()=>p(t,"logout"),changeExpiredPassword:(e,r,s)=>p(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>p(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>p(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>p(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return p(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await b(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}}),J=(t,e,r)=>{const s=e,i=t,h=r;let f="list"+e;const o=u=>h[u]?h[u]():null;return{field:o,$fields:h,setDataPath(u){return f=u,f},getDataPath(){return f},gqlFields(u){const n=[];for(const a of u)if(typeof a=="string"){const l=o(a);l&&n.push(l.getGQLField())}else typeof a=="object"&&n.push(a);return n},async update(u,n){return await p(i,"update"+s,{id:u,data:n})},async delete(u){return await p(i,"delete"+s,{id:u})},async add(u){return await p(i,"add"+s,{data:u})},fields(u){let n=[];for(let a of u){const l=o(a);l&&n.push(l)}return n},async get(u,n){const a=(await Promise.resolve().then(()=>R)).default,l=a(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.first()},async list(u,n){const a=(await Promise.resolve().then(()=>R)).default,l=a(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.all()}}};function M(t){t="<~"+t+"~>";var e,r,s,i,h,f=String,o=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],i=0,h=t.length;h>i;i+=5)r=52200625*(t.charCodeAt(i)-33)+614125*(t.charCodeAt(i+1)-33)+7225*(t.charCodeAt(i+2)-33)+85*(t.charCodeAt(i+3)-33)+(t.charCodeAt(i+4)-33),s.push(o&r>>24,o&r>>16,o&r>>8,o&r);return function(u,n){for(var a=n;a>0;a--)u.pop()}(s,e.length),f.fromCharCode.apply(f,s)}const D=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let o=0;o<e.length;o++)i[o]=e.charCodeAt(o);const h=new Blob([i],{type:s});return URL.createObjectURL(h)};return{getContent:()=>e,getURL:r,download:s=>{const i=document.createElement("a");i.download=s,i.href=r(),document.body.appendChild(i),i.click(),document.body.removeChild(i)},open:s=>{window.open(r(s),"_blank")}}},T={fromBase85:t=>D(M(t)),fromBase64:t=>D(atob(t)),fromString:t=>D(t)},S=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(S(r)).forEach(([s,i])=>{e[s]=i})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=S(s)}),e)},k=t=>S(t),b=async(t,e)=>{let r=m.jsonToGraphQLQuery(k(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function W(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function Q(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const p=async(t,e,r=null,s=[])=>{let i={[e]:{}};const h=new FormData;let f=!1;if(r){const n={},a={},l={};let c=0;Object.entries(r).forEach(([d,w])=>{if(w instanceof Array&&W(w)){f=!0;let y=0;w.forEach(A=>{A instanceof File&&(n[d]=new m.VariableType(d),a[c]=["variables."+d+"."+y],h.append(c.toString(),A),c++)}),l[d]="[Upload!]!"}else w instanceof File?(f=!0,n[d]=new m.VariableType(d),a[c]=["variables."+d],h.append(c.toString(),w),l[d]="Upload!",c++):w instanceof Object&&Q(w)?(f=!0,n[d]={},Object.entries(w).forEach(([y,A])=>{A instanceof File?(n[d][y]=new m.VariableType(y),a[c]=["variables."+y],h.append(c.toString(),A),l[y]="Upload!",c++):n[d][y]=A})):w!==void 0&&(n[d]=w)}),i[e].__args=n,i.__variables=l,f&&h.append("map",JSON.stringify(a))}Object.entries(k(s)).forEach(([n,a])=>{i[e][n]=a}),Object.entries(i[e]).length===0&&(i[e]=!0);let o=null;const u=m.jsonToGraphQLQuery({mutation:i});if(f?(h.append("operations",JSON.stringify({query:u})),o=await t.post("",h)):o=await t.post("",{query:u}),o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data[e]},$=t=>({uploadTempFile:e=>p(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await b(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>p(t,"fsCreateFolder",{path:e}),delete:e=>p(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>p(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await b(t,{app:{drive:{files:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}}}});return r.drive.files},read:async e=>{let{app:r}=await b(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>p(t,"fsWriteFile",{path:e,content:r}),delete:e=>p(t,"fsDeleteFile",{path:e}),rename:(e,r)=>p(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>p(t,"fsMoveFile",{source:e,target:r})}}),z=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),I=t=>({send:(e,r,s)=>p(t,"sendMail",{email:e,subject:r,message:s})}),K=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=j("Users",t,e);return r.data_path="app.users",r.all()}}),G=t=>{const e=t,r={};return{create(s,i){r[s]=null;let h={};for(const f of Object.entries(i)){const[o,u]=f;h[o]=()=>({name:u.name?u.name:o,raw:u,getName:()=>u.name?u.name:o,getGQLField:()=>u.gqlField!==void 0?u.gqlField:u.name||o,getRaw(){return u},getValue(n){return u.field&&typeof u.field=="function"?u.field(n):u.field&&typeof u.field=="string"?n[u.field]:n[this.getName()]},getFormattedValue(n){const a=this.getValue(n);return u.format?u.format(a):a}})}r[s]=J(e,s,h)},get(s){return r[s]||this.create(s,{}),r[s]}}},V=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await b(t,{app:{roles:e}});return r}}),H="list",X=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],Y=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition"];class g{constructor(e,r){C(this,"_batchData",null);C(this,"data_path","");C(this,"axios");C(this,"filters");C(this,"steps");C(this,"fields");C(this,"already_limit",!1);C(this,"already_offset",!1);C(this,"limit",null);C(this,"offset",null);C(this,"_sort",null);C(this,"_sortDesc",!1);C(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}g.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},g.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},g.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},g.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},P().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),g.prototype.fetchData=async function(){try{if(this._batchData){const o=this._batchData;return this.meta=o.meta,P(o.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,i=e[e.length-1];for(const o of e){if(o===i){s[o]=t;break}s[o]={},s=s[o]}let f=await b(this.axios,r);for(const o of e)f=f[o];return this.meta=f.meta,P(f.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},g.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},g.prototype.all=async function(){return(await this.processData()).all()};for(const t of X)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Y)g.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};g.prototype.average=g.prototype.avg,g.prototype.first=async function(){return this.take(1),(await this.processData()).first()},g.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},g.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],s=t[1],i=t[2];switch(s){case"==":this.filters[r]=i;break;case"<":this.filters[r]={lt:i};break;case"<=":this.filters[r]={lte:i};break;case">":this.filters[r]={gt:i};break;case">=":this.filters[r]={gte:i};break;case"!==":this.filters[r]={ne:i};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},g.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},g.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},g.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},g.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},g.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},g.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},g.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},g.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},g.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},g.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},g.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const j=(t,e,r)=>{const s=new g(r,e);return s.data_path=H+t,s},R=Object.freeze(Object.defineProperty({__proto__:null,default:j},Symbol.toStringTag,{value:"Module"})),Z=(t,e)=>({uploadTempFile:r=>p(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await b(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>p(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>p(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await b(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await b(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await b(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});if(!s.app.drive.file||!s.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${r}`);return typeof window<"u"&&window.atob?window.atob(s.app.drive.file.base64Content):s.app.drive.file.base64Content},write:(r,s)=>p(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>p(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>p(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}});function N(t){if(t===null||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null||Symbol.iterator in t?!1:Symbol.toStringTag in t?Object.prototype.toString.call(t)==="[object Module]":!0}function B(t,e,r=".",s){if(!N(e))return B(t,{},r,s);const i=Object.assign({},e);for(const h in t){if(h==="__proto__"||h==="constructor")continue;const f=t[h];f!=null&&(s&&s(i,h,f,r)||(Array.isArray(f)&&Array.isArray(i[h])?i[h]=[...f,...i[h]]:N(f)&&N(i[h])?i[h]=B(f,i[h],(r?`${r}.`:"")+h.toString(),s):i[h]=f))}return i}function x(t){return(...e)=>e.reduce((r,s)=>B(r,s,"",t),{})}const v=x();function tt(t,e,r){let s,i=[],h,f;const o=n=>!n||typeof n!="object"?!1:Object.values(n).some(a=>a&&typeof a=="object"&&Object.keys(a).some(l=>l.startsWith("_"))),u=()=>i.length===0?(i.unshift({}),i[0]):(o(i[0])&&i.unshift({}),i[0]);return{async fetchFirst(){return await this.limit(1).fetch().then(a=>Array.isArray(a)&&a.length>0?a[0]:null)},async fetchWithMeta(){let a=await b(t,this.toQuery(!0));if(f){const l=f.split(".");for(const c of l)a=a[c];return a}return a[`list${e}`]},async fetch(){let a=await b(t,this.toQuery());if(f){const l=f.split(".");for(const c of l)a=a[c];return a.data}return a[`list${e}`].data},dataPath(n){return n&&typeof n=="string"&&(f=n),this},sort(n){return n&&typeof n=="string"&&(h=n),this},filters(n){return n&&typeof n=="object"&&(i=[n]),this},where(n,a,l){const c=(d,w,y)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[w];F&&i.push({[d]:{[F]:y}})};if(l!==void 0)c(n,String(a),l);else{const d=u(),w=v(d,{[n]:a});i[0]=w}return this},whereContains(n,a){if(n&&typeof n=="string"){const l=u(),c={_contains:a};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereIn(n,a){if(n&&typeof n=="string"&&Array.isArray(a)){const l=u(),c={_in:a};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereBetween(n,a,l){if(n&&typeof n=="string"){const c=u(),d={_between:[a,l]};c[n]?Array.isArray(c[n])?c[n].push(d):c[n]=[c[n],d]:c[n]=d,i[0]=c}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{offset:n})),this},toQuery(n=!1){let a;const l=i.length>0&&Object.keys(i[0]||{}).length>0,c=l?1:0,d=i.length>c;l&&d?a=i:d?a=i.slice(c):l&&(a=i[0]);const w=v(h?{sort:h}:{},a?{filters:a}:{}),y={data:{...r}};if(s&&(y.data.__args=s),Object.keys(w).length>0&&(y.__args=w),n&&(y.meta={total:!0,key:!0,name:!0}),f){const A=f.split(".");let F=y;for(let E=A.length-1;E>=0;E--)F={[A[E]]:F};return F}return{[`list${e}`]:y}}}}const et=t=>{const e=typeof window>"u";let r=[];const s=O.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(o=>(o.withCredentials=!0,r.length>0&&(o.headers.Cookie=r.join("; ")),o)),s.interceptors.response.use(o=>{if(o.headers["set-cookie"]){const u=o.headers["set-cookie"].map(a=>a.split(";")[0]),n=new Map;r.forEach(a=>{const l=a.split("=")[0];n.set(l,a)}),u.forEach(a=>{const l=a.split("=")[0];n.set(l,a)}),r=Array.from(n.values())}return o}));const i=(o,u=null,n=[])=>p(s,o,u,n),h=o=>b(s,o),f=G(s);return{baseURL:t,axios:s,auth:U(s),mutation:i,query:h,config:z(h),mail:I(s),users:K(s),fs:$(s),models:f,model(o){return f.get(o)},roles:V(s),collect:(o,u)=>{const n=j(o,s,u);return n.data_path=f.get(o).getDataPath(),n},list:(o,u)=>tt(s,o,u).dataPath(f.get(o).getDataPath()),drive(o){return Z(o,s)},async collects(o){const u={},n={};for(const l in o){const c=o[l].getQueryPayload();n[l]=c.data_path,u[l]={};const d=c.data_path.split(".");let w=d[d.length-1],y=u[l];for(const A of d){if(A===w){y[A]=c.query;break}y[A]=y[A]||{}}u[l].__aliasFor=d[0]}const a=await b(s,u);for(const l in o){const c=n[l].split(".");let d=c[c.length-1],w=a[l];for(const y of c){if(y===d){o[l]._batchData=a[l][y];break}w[y]=w[y]||{}}}return o}}};_.File=T,_.createClient=et,_.createCollection=j,_.file=D,_.mutation=p,_.query=b,_.toQuery=k,_.useWebAuthn=q,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
|