@hostlink/light 2.9.0 → 2.11.0

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.
@@ -10,6 +10,7 @@ import { default as model } from './model';
10
10
  import { default as roles } from './roles';
11
11
  import { default as createCollection } from './createCollection';
12
12
  import { default as drive } from './drive';
13
+ import { default as createList } from './createList';
13
14
  export interface LightClient {
14
15
  baseURL: string;
15
16
  axios: AxiosInstance;
@@ -32,6 +33,7 @@ export interface LightClient {
32
33
  }): Promise<{
33
34
  [key: string]: any;
34
35
  }>;
36
+ list(entity: string, fields: Fields): ReturnType<typeof createList>;
35
37
  }
36
38
  declare const _default: (baseURL: string) => LightClient;
37
39
  export default _default;
@@ -0,0 +1,17 @@
1
+ import { AxiosInstance } from 'axios';
2
+ type Fields = Record<string, any>;
3
+ export default function createList(axios: AxiosInstance, entity: string, fields: Fields): {
4
+ fetchWithMeta(): Promise<any>;
5
+ fetch(): Promise<any>;
6
+ dataPath(dataPath?: string): /*elided*/ any;
7
+ sort(sortStr: string): /*elided*/ any;
8
+ filters(filterObj: Record<string, any>): /*elided*/ any;
9
+ where(key: string, opOrVal?: any, maybeVal?: any): /*elided*/ any;
10
+ whereContains(field: string, val: any): /*elided*/ any;
11
+ whereIn(field: string, vals: any[]): /*elided*/ any;
12
+ whereBetween(field: string, min: any, max: any): /*elided*/ any;
13
+ limit(n: number): /*elided*/ any;
14
+ offset(n: number): /*elided*/ any;
15
+ toQuery(includeMeta?: boolean): any;
16
+ };
17
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/dist/light.js CHANGED
@@ -1,107 +1,107 @@
1
- var N = Object.defineProperty;
2
- var B = (t, e, r) => e in t ? N(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var m = (t, e, r) => B(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { jsonToGraphQLQuery as P, VariableType as F } from "json-to-graphql-query";
5
- import R from "axios";
6
- import D from "collect.js";
7
- const E = (t) => ({
1
+ var R = Object.defineProperty;
2
+ var q = (t, e, r) => e in t ? R(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var b = (t, e, r) => q(t, typeof e != "symbol" ? e + "" : e, r);
4
+ import { jsonToGraphQLQuery as E, VariableType as k } from "json-to-graphql-query";
5
+ import L from "axios";
6
+ import j from "collect.js";
7
+ const U = (t) => ({
8
8
  assertion: async () => {
9
- const { app: s } = await w(t, {
9
+ const { app: s } = await m(t, {
10
10
  app: {
11
11
  auth: {
12
12
  webAuthnRequestOptions: !0
13
13
  }
14
14
  }
15
- }), a = s.auth.webAuthnRequestOptions, h = PublicKeyCredential.parseRequestOptionsFromJSON(a);
15
+ }), i = s.auth.webAuthnRequestOptions, h = PublicKeyCredential.parseRequestOptionsFromJSON(i);
16
16
  return await navigator.credentials.get({ publicKey: h });
17
17
  },
18
18
  attestation: async () => {
19
- const { app: s } = await w(t, {
19
+ const { app: s } = await m(t, {
20
20
  app: {
21
21
  auth: {
22
22
  webAuthnCreationOptions: !0
23
23
  }
24
24
  }
25
- }), a = PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);
26
- return await navigator.credentials.create({ publicKey: a });
25
+ }), i = PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);
26
+ return await navigator.credentials.create({ publicKey: i });
27
27
  }
28
- }), j = (t) => {
29
- const { assertion: e, attestation: r } = E(t);
28
+ }), J = (t) => {
29
+ const { assertion: e, attestation: r } = U(t);
30
30
  return {
31
31
  login: async () => {
32
32
  const s = await e();
33
- await l(t, "webAuthnAssertion", {
33
+ await p(t, "webAuthnAssertion", {
34
34
  assertion: s.toJSON()
35
35
  });
36
36
  },
37
37
  register: async () => {
38
38
  const s = await r();
39
- await l(t, "webAuthnRegister", {
39
+ await p(t, "webAuthnRegister", {
40
40
  registration: s.toJSON()
41
41
  });
42
42
  }
43
43
  };
44
- }, S = (t) => ({
45
- WebAuthn: j(t),
44
+ }, M = (t) => ({
45
+ WebAuthn: J(t),
46
46
  google: {
47
- unlink: () => l(t, "lightAuthUnlinkGoogle"),
48
- login: (e) => l(t, "lightAuthLoginGoogle", {
47
+ unlink: () => p(t, "lightAuthUnlinkGoogle"),
48
+ login: (e) => p(t, "lightAuthLoginGoogle", {
49
49
  credential: e
50
50
  }),
51
- register: (e) => l(t, "lightAuthRegisterGoogle", {
51
+ register: (e) => p(t, "lightAuthRegisterGoogle", {
52
52
  credential: e
53
53
  })
54
54
  },
55
55
  facebook: {
56
- unlink: () => l(t, "lightAuthUnlinkFacebook"),
57
- login: (e) => l(t, "lightAuthLoginFacebook", {
56
+ unlink: () => p(t, "lightAuthUnlinkFacebook"),
57
+ login: (e) => p(t, "lightAuthLoginFacebook", {
58
58
  access_token: e
59
59
  }),
60
- register: (e) => l(t, "lightAuthRegisterFacebook", {
60
+ register: (e) => p(t, "lightAuthRegisterFacebook", {
61
61
  access_token: e
62
62
  })
63
63
  },
64
64
  microsoft: {
65
- unlink: () => l(t, "lightAuthUnlinkMicrosoft"),
66
- login: (e) => l(t, "lightAuthLoginMicrosoft", {
65
+ unlink: () => p(t, "lightAuthUnlinkMicrosoft"),
66
+ login: (e) => p(t, "lightAuthLoginMicrosoft", {
67
67
  access_token: e
68
68
  }),
69
- register: (e) => l(t, "lightAuthRegisterMicrosoft", {
69
+ register: (e) => p(t, "lightAuthRegisterMicrosoft", {
70
70
  account_id: e
71
71
  })
72
72
  },
73
- login: (e, r, s = "") => l(t, "login", {
73
+ login: (e, r, s = "") => p(t, "login", {
74
74
  username: e,
75
75
  password: r,
76
76
  code: s
77
77
  }),
78
- logout: () => l(t, "logout"),
79
- changeExpiredPassword: (e, r, s) => l(t, "changeExpiredPassword", {
78
+ logout: () => p(t, "logout"),
79
+ changeExpiredPassword: (e, r, s) => p(t, "changeExpiredPassword", {
80
80
  username: e,
81
81
  old_password: r,
82
82
  new_password: s
83
83
  }),
84
- updatePassword: (e, r) => l(t, "changeUserPassword", {
84
+ updatePassword: (e, r) => p(t, "changeUserPassword", {
85
85
  old_password: e,
86
86
  new_password: r
87
87
  }),
88
- resetPassword: (e, r, s) => l(t, "resetPassword", {
88
+ resetPassword: (e, r, s) => p(t, "resetPassword", {
89
89
  jwt: e,
90
90
  password: r,
91
91
  code: s
92
92
  }),
93
- forgetPassword: (e, r) => l(t, "forgetPassword", {
93
+ forgetPassword: (e, r) => p(t, "forgetPassword", {
94
94
  username: e,
95
95
  email: r
96
96
  }),
97
97
  verifyCode(e, r) {
98
- return l(t, "forgetPasswordVerifyCode", {
98
+ return p(t, "forgetPasswordVerifyCode", {
99
99
  jwt: e,
100
100
  code: r
101
101
  });
102
102
  },
103
103
  granted: async (e) => {
104
- const { my: r } = await w(t, {
104
+ const { my: r } = await m(t, {
105
105
  my: {
106
106
  grantedRights: {
107
107
  __args: {
@@ -112,95 +112,95 @@ const E = (t) => ({
112
112
  });
113
113
  return r.grantedRights;
114
114
  }
115
- }), q = (t, e, r) => {
116
- const s = e, a = t, h = r;
117
- let p = "list" + e;
118
- const n = (i) => h[i] ? h[i]() : null;
115
+ }), Q = (t, e, r) => {
116
+ const s = e, i = t, h = r;
117
+ let f = "list" + e;
118
+ const o = (u) => h[u] ? h[u]() : null;
119
119
  return {
120
- field: n,
120
+ field: o,
121
121
  $fields: h,
122
- setDataPath(i) {
123
- return p = i, p;
122
+ setDataPath(u) {
123
+ return f = u, f;
124
124
  },
125
125
  getDataPath() {
126
- return p;
126
+ return f;
127
127
  },
128
- gqlFields(i) {
129
- const o = [];
130
- for (const c of i)
131
- if (typeof c == "string") {
132
- const u = n(c);
133
- u && o.push(u.getGQLField());
134
- } else typeof c == "object" && o.push(c);
135
- return o;
128
+ gqlFields(u) {
129
+ const n = [];
130
+ for (const a of u)
131
+ if (typeof a == "string") {
132
+ const l = o(a);
133
+ l && n.push(l.getGQLField());
134
+ } else typeof a == "object" && n.push(a);
135
+ return n;
136
136
  },
137
- async update(i, o) {
138
- return await l(a, "update" + s, { id: i, data: o });
137
+ async update(u, n) {
138
+ return await p(i, "update" + s, { id: u, data: n });
139
139
  },
140
- async delete(i) {
141
- return await l(a, "delete" + s, { id: i });
140
+ async delete(u) {
141
+ return await p(i, "delete" + s, { id: u });
142
142
  },
143
- async add(i) {
144
- return await l(a, "add" + s, { data: i });
143
+ async add(u) {
144
+ return await p(i, "add" + s, { data: u });
145
145
  },
146
- fields(i) {
147
- let o = [];
148
- for (let c of i) {
149
- const u = n(c);
150
- u && o.push(u);
146
+ fields(u) {
147
+ let n = [];
148
+ for (let a of u) {
149
+ const l = o(a);
150
+ l && n.push(l);
151
151
  }
152
- return o;
152
+ return n;
153
153
  },
154
- async get(i, o) {
155
- const c = (await Promise.resolve().then(() => O)).default, u = c(s, a, C(o));
156
- for (const [d, g] of Object.entries(i))
157
- u.where(d, "==", g);
158
- return await u.first();
154
+ async get(u, n) {
155
+ const a = (await Promise.resolve().then(() => B)).default, l = a(s, i, O(n));
156
+ for (const [c, d] of Object.entries(u))
157
+ l.where(c, "==", d);
158
+ return await l.first();
159
159
  },
160
- async list(i, o) {
161
- const c = (await Promise.resolve().then(() => O)).default, u = c(s, a, C(o));
162
- for (const [d, g] of Object.entries(i))
163
- u.where(d, "==", g);
164
- return await u.all();
160
+ async list(u, n) {
161
+ const a = (await Promise.resolve().then(() => B)).default, l = a(s, i, O(n));
162
+ for (const [c, d] of Object.entries(u))
163
+ l.where(c, "==", d);
164
+ return await l.all();
165
165
  }
166
166
  };
167
167
  };
168
- function U(t) {
168
+ function T(t) {
169
169
  t = "<~" + t + "~>";
170
- var e, r, s, a, h, p = String, n = 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 = [], a = 0, h = t.length; h > a; a += 5) r = 52200625 * (t.charCodeAt(a) - 33) + 614125 * (t.charCodeAt(a + 1) - 33) + 7225 * (t.charCodeAt(a + 2) - 33) + 85 * (t.charCodeAt(a + 3) - 33) + (t.charCodeAt(a + 4) - 33), s.push(n & r >> 24, n & r >> 16, n & r >> 8, n & r);
172
- return function(i, o) {
173
- for (var c = o; c > 0; c--) i.pop();
174
- }(s, e.length), p.fromCharCode.apply(p, s);
170
+ var e, r, s, i, h, f = String, o = 255;
171
+ for (t.slice(0, 2) === "<~" && t.slice(-2), t = t.slice(2, -2).replace(/\s/g, "").replace("z", "!!!!!"), e = "uuuuu".slice(t.length % 5 || 5), t += e, s = [], i = 0, h = t.length; h > i; i += 5) r = 52200625 * (t.charCodeAt(i) - 33) + 614125 * (t.charCodeAt(i + 1) - 33) + 7225 * (t.charCodeAt(i + 2) - 33) + 85 * (t.charCodeAt(i + 3) - 33) + (t.charCodeAt(i + 4) - 33), s.push(o & r >> 24, o & r >> 16, o & r >> 8, o & r);
172
+ return function(u, n) {
173
+ for (var a = n; a > 0; a--) u.pop();
174
+ }(s, e.length), f.fromCharCode.apply(f, s);
175
175
  }
176
- const k = (t = "") => {
176
+ const D = (t = "") => {
177
177
  const e = t, r = (s = "application/octet-stream") => {
178
- const a = new Uint8Array(e.length);
179
- for (let n = 0; n < e.length; n++)
180
- a[n] = e.charCodeAt(n);
181
- const h = new Blob([a], { type: s });
178
+ const i = new Uint8Array(e.length);
179
+ for (let o = 0; o < e.length; o++)
180
+ i[o] = e.charCodeAt(o);
181
+ const h = new Blob([i], { type: s });
182
182
  return URL.createObjectURL(h);
183
183
  };
184
184
  return {
185
185
  getContent: () => e,
186
186
  getURL: r,
187
187
  download: (s) => {
188
- const a = document.createElement("a");
189
- a.download = s, a.href = r(), document.body.appendChild(a), a.click(), document.body.removeChild(a);
188
+ const i = document.createElement("a");
189
+ i.download = s, i.href = r(), document.body.appendChild(i), i.click(), document.body.removeChild(i);
190
190
  },
191
191
  open: (s) => {
192
192
  window.open(r(s), "_blank");
193
193
  }
194
194
  };
195
- }, x = {
196
- fromBase85: (t) => k(U(t)),
197
- fromBase64: (t) => k(atob(t)),
198
- fromString: (t) => k(t)
199
- }, v = (t) => {
195
+ }, ot = {
196
+ fromBase85: (t) => D(T(t)),
197
+ fromBase64: (t) => D(atob(t)),
198
+ fromString: (t) => D(t)
199
+ }, P = (t) => {
200
200
  let e = {};
201
201
  return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
202
- Object.entries(v(r)).forEach(([s, a]) => {
203
- e[s] = a;
202
+ Object.entries(P(r)).forEach(([s, i]) => {
203
+ e[s] = i;
204
204
  });
205
205
  }), e) : (Object.entries(t).forEach(([r, s]) => {
206
206
  if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
@@ -211,10 +211,10 @@ const k = (t = "") => {
211
211
  e[r] = s;
212
212
  return;
213
213
  }
214
- e[r] = v(s);
214
+ e[r] = P(s);
215
215
  }), e);
216
- }, C = (t) => v(t), w = async (t, e) => {
217
- let r = P(C(e));
216
+ }, O = (t) => P(t), m = async (t, e) => {
217
+ let r = E(O(e));
218
218
  const s = await t.post("", {
219
219
  query: `{ ${r} }`
220
220
  });
@@ -222,53 +222,53 @@ const k = (t = "") => {
222
222
  throw new Error(s.data.errors[0].message);
223
223
  return s.data.data;
224
224
  };
225
- function L(t) {
225
+ function W(t) {
226
226
  for (let e = 0; e < t.length; e++)
227
227
  if (t[e] instanceof File)
228
228
  return !0;
229
229
  return !1;
230
230
  }
231
- function J(t) {
231
+ function $(t) {
232
232
  for (let e in t)
233
233
  if (t[e] instanceof File)
234
234
  return !0;
235
235
  return !1;
236
236
  }
237
- const l = async (t, e, r = null, s = []) => {
238
- let a = {
237
+ const p = async (t, e, r = null, s = []) => {
238
+ let i = {
239
239
  [e]: {}
240
240
  };
241
241
  const h = new FormData();
242
- let p = !1;
242
+ let f = !1;
243
243
  if (r) {
244
- const o = {}, c = {}, u = {};
245
- let d = 0;
246
- Object.entries(r).forEach(([g, y]) => {
247
- if (y instanceof Array && L(y)) {
248
- p = !0;
249
- let _ = 0;
250
- y.forEach((b) => {
251
- b instanceof File && (o[g] = new F(g), c[d] = ["variables." + g + "." + _], h.append(d.toString(), b), d++);
252
- }), u[g] = "[Upload!]!";
253
- } else y instanceof File ? (p = !0, o[g] = new F(g), c[d] = ["variables." + g], h.append(d.toString(), y), u[g] = "Upload!", d++) : y instanceof Object && J(y) ? (p = !0, o[g] = {}, Object.entries(y).forEach(([_, b]) => {
254
- b instanceof File ? (o[g][_] = new F(_), c[d] = ["variables." + _], h.append(d.toString(), b), u[_] = "Upload!", d++) : o[g][_] = b;
255
- })) : y !== void 0 && (o[g] = y);
256
- }), a[e].__args = o, a.__variables = u, p && h.append("map", JSON.stringify(c));
244
+ const n = {}, a = {}, l = {};
245
+ let c = 0;
246
+ Object.entries(r).forEach(([d, _]) => {
247
+ if (_ instanceof Array && W(_)) {
248
+ f = !0;
249
+ let y = 0;
250
+ _.forEach((w) => {
251
+ w instanceof File && (n[d] = new k(d), a[c] = ["variables." + d + "." + y], h.append(c.toString(), w), c++);
252
+ }), l[d] = "[Upload!]!";
253
+ } else _ instanceof File ? (f = !0, n[d] = new k(d), a[c] = ["variables." + d], h.append(c.toString(), _), l[d] = "Upload!", c++) : _ instanceof Object && $(_) ? (f = !0, n[d] = {}, Object.entries(_).forEach(([y, w]) => {
254
+ w instanceof File ? (n[d][y] = new k(y), a[c] = ["variables." + y], h.append(c.toString(), w), l[y] = "Upload!", c++) : n[d][y] = w;
255
+ })) : _ !== void 0 && (n[d] = _);
256
+ }), i[e].__args = n, i.__variables = l, f && h.append("map", JSON.stringify(a));
257
257
  }
258
- Object.entries(C(s)).forEach(([o, c]) => {
259
- a[e][o] = c;
260
- }), Object.entries(a[e]).length === 0 && (a[e] = !0);
261
- let n = null;
262
- const i = P({ mutation: a });
263
- if (p ? (h.append("operations", JSON.stringify({
264
- query: i
265
- })), n = await t.post("", h)) : n = await t.post("", {
266
- query: i
267
- }), n.data.errors)
268
- throw new Error(n.data.errors[0].message);
269
- return n.data.data[e];
270
- }, T = (t) => ({
271
- uploadTempFile: (e) => l(t, "fsUploadTempFile", {
258
+ Object.entries(O(s)).forEach(([n, a]) => {
259
+ i[e][n] = a;
260
+ }), Object.entries(i[e]).length === 0 && (i[e] = !0);
261
+ let o = null;
262
+ const u = E({ mutation: i });
263
+ if (f ? (h.append("operations", JSON.stringify({
264
+ query: u
265
+ })), o = await t.post("", h)) : o = await t.post("", {
266
+ query: u
267
+ }), o.data.errors)
268
+ throw new Error(o.data.errors[0].message);
269
+ return o.data.data[e];
270
+ }, z = (t) => ({
271
+ uploadTempFile: (e) => p(t, "fsUploadTempFile", {
272
272
  file: e
273
273
  }, {
274
274
  name: !0,
@@ -277,7 +277,7 @@ const l = async (t, e, r = null, s = []) => {
277
277
  mime: !0
278
278
  }),
279
279
  folders: {
280
- list: async (e) => (await w(t, {
280
+ list: async (e) => (await m(t, {
281
281
  fsListFolders: {
282
282
  __args: {
283
283
  path: e
@@ -286,13 +286,13 @@ const l = async (t, e, r = null, s = []) => {
286
286
  path: !0
287
287
  }
288
288
  })).fsListFolders,
289
- create: (e) => l(t, "fsCreateFolder", { path: e }),
290
- delete: (e) => l(t, "fsDeleteFolder", { path: e }),
291
- rename: (e, r) => l(t, "fsRenameFolder", { path: e, name: r })
289
+ create: (e) => p(t, "fsCreateFolder", { path: e }),
290
+ delete: (e) => p(t, "fsDeleteFolder", { path: e }),
291
+ rename: (e, r) => p(t, "fsRenameFolder", { path: e, name: r })
292
292
  },
293
293
  files: {
294
294
  list: async (e) => {
295
- let { app: r } = await w(t, {
295
+ let { app: r } = await m(t, {
296
296
  app: {
297
297
  drive: {
298
298
  files: {
@@ -312,7 +312,7 @@ const l = async (t, e, r = null, s = []) => {
312
312
  return r.drive.files;
313
313
  },
314
314
  read: async (e) => {
315
- let { app: r } = await w(t, {
315
+ let { app: r } = await m(t, {
316
316
  app: {
317
317
  drive: {
318
318
  files: {
@@ -326,15 +326,15 @@ const l = async (t, e, r = null, s = []) => {
326
326
  });
327
327
  return window.atob(r.drive.files[0].base64Content);
328
328
  },
329
- write: (e, r) => l(t, "fsWriteFile", {
329
+ write: (e, r) => p(t, "fsWriteFile", {
330
330
  path: e,
331
331
  content: r
332
332
  }),
333
- delete: (e) => l(t, "fsDeleteFile", { path: e }),
334
- rename: (e, r) => l(t, "fsRenameFile", { path: e, name: r }),
335
- move: (e, r) => l(t, "fsMoveFile", { source: e, target: r })
333
+ delete: (e) => p(t, "fsDeleteFile", { path: e }),
334
+ rename: (e, r) => p(t, "fsRenameFile", { path: e, name: r }),
335
+ move: (e, r) => p(t, "fsMoveFile", { source: e, target: r })
336
336
  }
337
- }), M = (t) => ({
337
+ }), G = (t) => ({
338
338
  get: async (e) => (await t({
339
339
  config: {
340
340
  __args: {
@@ -342,13 +342,13 @@ const l = async (t, e, r = null, s = []) => {
342
342
  }
343
343
  }
344
344
  })).config
345
- }), W = (t) => ({
346
- send: (e, r, s) => l(t, "sendMail", {
345
+ }), I = (t) => ({
346
+ send: (e, r, s) => p(t, "sendMail", {
347
347
  email: e,
348
348
  subject: r,
349
349
  message: s
350
350
  })
351
- }), z = (t) => ({
351
+ }), K = (t) => ({
352
352
  list: async (e = {
353
353
  user_id: !0,
354
354
  username: !0,
@@ -356,52 +356,52 @@ const l = async (t, e, r = null, s = []) => {
356
356
  last_name: !0,
357
357
  status: !0
358
358
  }) => {
359
- const r = A("Users", t, e);
359
+ const r = N("Users", t, e);
360
360
  return r.data_path = "app.users", r.all();
361
361
  }
362
- }), G = (t) => {
362
+ }), V = (t) => {
363
363
  const e = t, r = {};
364
364
  return {
365
- create(s, a) {
365
+ create(s, i) {
366
366
  r[s] = null;
367
367
  let h = {};
368
- for (const p of Object.entries(a)) {
369
- const [n, i] = p;
370
- h[n] = () => ({
371
- name: i.name ? i.name : n,
372
- raw: i,
373
- getName: () => i.name ? i.name : n,
374
- getGQLField: () => i.gqlField !== void 0 ? i.gqlField : i.name || n,
368
+ for (const f of Object.entries(i)) {
369
+ const [o, u] = f;
370
+ h[o] = () => ({
371
+ name: u.name ? u.name : o,
372
+ raw: u,
373
+ getName: () => u.name ? u.name : o,
374
+ getGQLField: () => u.gqlField !== void 0 ? u.gqlField : u.name || o,
375
375
  getRaw() {
376
- return i;
376
+ return u;
377
377
  },
378
- getValue(o) {
379
- return i.field && typeof i.field == "function" ? i.field(o) : i.field && typeof i.field == "string" ? o[i.field] : o[this.getName()];
378
+ getValue(n) {
379
+ return u.field && typeof u.field == "function" ? u.field(n) : u.field && typeof u.field == "string" ? n[u.field] : n[this.getName()];
380
380
  },
381
- getFormattedValue(o) {
382
- const c = this.getValue(o);
383
- return i.format ? i.format(c) : c;
381
+ getFormattedValue(n) {
382
+ const a = this.getValue(n);
383
+ return u.format ? u.format(a) : a;
384
384
  }
385
385
  });
386
386
  }
387
- r[s] = q(e, s, h);
387
+ r[s] = Q(e, s, h);
388
388
  },
389
389
  get(s) {
390
390
  return r[s] || this.create(s, {}), r[s];
391
391
  }
392
392
  };
393
- }, Q = (t) => ({
393
+ }, H = (t) => ({
394
394
  list: async (e = {
395
395
  name: !0
396
396
  }) => {
397
- const { app: { roles: r } } = await w(t, {
397
+ const { app: { roles: r } } = await m(t, {
398
398
  app: {
399
399
  roles: e
400
400
  }
401
401
  });
402
402
  return r;
403
403
  }
404
- }), I = "list", $ = [
404
+ }), X = "list", Y = [
405
405
  "flatMap",
406
406
  "chunk",
407
407
  "shuffle",
@@ -427,7 +427,7 @@ const l = async (t, e, r = null, s = []) => {
427
427
  "slice",
428
428
  "tap",
429
429
  "sort"
430
- ], K = [
430
+ ], Z = [
431
431
  "avg",
432
432
  "count",
433
433
  "countBy",
@@ -455,25 +455,25 @@ const l = async (t, e, r = null, s = []) => {
455
455
  "implode",
456
456
  "partition"
457
457
  ];
458
- class f {
458
+ class g {
459
459
  constructor(e, r) {
460
- m(this, "_batchData", null);
461
- m(this, "data_path", "");
462
- m(this, "axios");
463
- m(this, "filters");
464
- m(this, "steps");
465
- m(this, "fields");
466
- m(this, "already_limit", !1);
467
- m(this, "already_offset", !1);
468
- m(this, "limit", null);
469
- m(this, "offset", null);
470
- m(this, "_sort", null);
471
- m(this, "_sortDesc", !1);
472
- m(this, "meta", {});
460
+ b(this, "_batchData", null);
461
+ b(this, "data_path", "");
462
+ b(this, "axios");
463
+ b(this, "filters");
464
+ b(this, "steps");
465
+ b(this, "fields");
466
+ b(this, "already_limit", !1);
467
+ b(this, "already_offset", !1);
468
+ b(this, "limit", null);
469
+ b(this, "offset", null);
470
+ b(this, "_sort", null);
471
+ b(this, "_sortDesc", !1);
472
+ b(this, "meta", {});
473
473
  this.axios = r, this.filters = {}, this.steps = [], this.fields = e;
474
474
  }
475
475
  }
476
- f.prototype.getQueryPayload = function() {
476
+ g.prototype.getQueryPayload = function() {
477
477
  let t = {
478
478
  meta: {
479
479
  total: !0,
@@ -487,26 +487,26 @@ f.prototype.getQueryPayload = function() {
487
487
  steps: this.steps
488
488
  };
489
489
  };
490
- f.prototype.dataPath = function(t) {
490
+ g.prototype.dataPath = function(t) {
491
491
  const e = this.clone();
492
492
  return e.data_path = t, e;
493
493
  };
494
- f.prototype.buildArgs = function() {
494
+ g.prototype.buildArgs = function() {
495
495
  let t = {};
496
496
  return Object.keys(this.filters).length > 0 && (t.filters = this.filters), this._sort && (t.sort = this._sort, this._sortDesc && (t.sort += ":desc")), t;
497
497
  };
498
- f.prototype.clone = function() {
498
+ g.prototype.clone = function() {
499
499
  const t = Object.create(this);
500
500
  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;
501
501
  };
502
- D().macro("whereContains", function(t, e) {
502
+ j().macro("whereContains", function(t, e) {
503
503
  return this.filter((r) => r[t].toLowerCase().includes(e.toLowerCase()));
504
504
  });
505
- f.prototype.fetchData = async function() {
505
+ g.prototype.fetchData = async function() {
506
506
  try {
507
507
  if (this._batchData) {
508
- const n = this._batchData;
509
- return this.meta = n.meta, D(n.data);
508
+ const o = this._batchData;
509
+ return this.meta = o.meta, j(o.data);
510
510
  }
511
511
  let t = {
512
512
  meta: {
@@ -517,72 +517,72 @@ f.prototype.fetchData = async function() {
517
517
  };
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
- let r = {}, s = r, a = e[e.length - 1];
521
- for (const n of e) {
522
- if (n === a) {
523
- s[n] = t;
520
+ let r = {}, s = r, i = e[e.length - 1];
521
+ for (const o of e) {
522
+ if (o === i) {
523
+ s[o] = t;
524
524
  break;
525
525
  }
526
- s[n] = {}, s = s[n];
526
+ s[o] = {}, s = s[o];
527
527
  }
528
- let p = await w(this.axios, r);
529
- for (const n of e)
530
- p = p[n];
531
- return this.meta = p.meta, D(p.data);
528
+ let f = await m(this.axios, r);
529
+ for (const o of e)
530
+ f = f[o];
531
+ return this.meta = f.meta, j(f.data);
532
532
  } catch (t) {
533
533
  throw console.error("Error fetching collection data:", t), t;
534
534
  }
535
535
  };
536
- f.prototype.processData = async function() {
536
+ g.prototype.processData = async function() {
537
537
  let t = await this.fetchData();
538
538
  for (const e of this.steps)
539
539
  t = t[e.type](...e.args);
540
540
  return t;
541
541
  };
542
- f.prototype.all = async function() {
542
+ g.prototype.all = async function() {
543
543
  return (await this.processData()).all();
544
544
  };
545
- for (const t of $)
546
- f.prototype[t] = function(...e) {
545
+ for (const t of Y)
546
+ g.prototype[t] = function(...e) {
547
547
  const r = this.clone();
548
548
  return r.steps.push({ type: t, args: e }), r;
549
549
  };
550
- for (const t of K)
551
- f.prototype[t] = async function(...e) {
550
+ for (const t of Z)
551
+ g.prototype[t] = async function(...e) {
552
552
  return (await this.clone().processData())[t](...e);
553
553
  };
554
- f.prototype.average = f.prototype.avg;
555
- f.prototype.first = async function() {
554
+ g.prototype.average = g.prototype.avg;
555
+ g.prototype.first = async function() {
556
556
  return this.take(1), (await this.processData()).first();
557
557
  };
558
- f.prototype._handleBatchData = function(t, e) {
558
+ g.prototype._handleBatchData = function(t, e) {
559
559
  return this._batchData ? (this.steps.push({ type: t, args: e }), this) : null;
560
560
  };
561
- f.prototype.where = function(...t) {
561
+ g.prototype.where = function(...t) {
562
562
  const e = this._handleBatchData("where", t);
563
563
  if (e) return e;
564
564
  if (t.length === 2)
565
565
  this.filters[t[0]] = t[1];
566
566
  else if (t.length === 3) {
567
- const r = t[0], s = t[1], a = t[2];
567
+ const r = t[0], s = t[1], i = t[2];
568
568
  switch (s) {
569
569
  case "==":
570
- this.filters[r] = a;
570
+ this.filters[r] = i;
571
571
  break;
572
572
  case "<":
573
- this.filters[r] = { lt: a };
573
+ this.filters[r] = { lt: i };
574
574
  break;
575
575
  case "<=":
576
- this.filters[r] = { lte: a };
576
+ this.filters[r] = { lte: i };
577
577
  break;
578
578
  case ">":
579
- this.filters[r] = { gt: a };
579
+ this.filters[r] = { gt: i };
580
580
  break;
581
581
  case ">=":
582
- this.filters[r] = { gte: a };
582
+ this.filters[r] = { gte: i };
583
583
  break;
584
584
  case "!==":
585
- this.filters[r] = { ne: a };
585
+ this.filters[r] = { ne: i };
586
586
  break;
587
587
  default:
588
588
  throw new Error(`Unsupported operator: ${s}`);
@@ -590,56 +590,56 @@ f.prototype.where = function(...t) {
590
590
  }
591
591
  return this;
592
592
  };
593
- f.prototype.whereContains = function(t, e) {
593
+ g.prototype.whereContains = function(t, e) {
594
594
  const r = this._handleBatchData("whereContains", [t, e]);
595
595
  return r || (this.filters[t] = { contains: e }, this);
596
596
  };
597
- f.prototype.forPage = function(t, e) {
597
+ g.prototype.forPage = function(t, e) {
598
598
  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);
599
599
  };
600
- f.prototype.whereIn = function(t, e) {
600
+ g.prototype.whereIn = function(t, e) {
601
601
  const r = this._handleBatchData("whereIn", [t, e]);
602
602
  return r || (this.filters[t] = { in: e }, this);
603
603
  };
604
- f.prototype.whereNotIn = function(t, e) {
604
+ g.prototype.whereNotIn = function(t, e) {
605
605
  const r = this._handleBatchData("whereNotIn", [t, e]);
606
606
  return r || (this.filters[t] = { nin: e }, this);
607
607
  };
608
- f.prototype.whereNotBetween = function(t, e) {
608
+ g.prototype.whereNotBetween = function(t, e) {
609
609
  const r = this._handleBatchData("whereNotBetween", [t, e]);
610
610
  return r || (this.filters[t] = { notBetween: e }, this);
611
611
  };
612
- f.prototype.whereBetween = function(t, e) {
612
+ g.prototype.whereBetween = function(t, e) {
613
613
  const r = this._handleBatchData("whereBetween", [t, e]);
614
614
  return r || (this.filters[t] = { between: e }, this);
615
615
  };
616
- f.prototype.sortBy = function(t) {
616
+ g.prototype.sortBy = function(t) {
617
617
  return this.steps.push({ type: "sortBy", args: [t] }), typeof t == "string" && (this._sort = t), this;
618
618
  };
619
- f.prototype.sortByDesc = function(t) {
619
+ g.prototype.sortByDesc = function(t) {
620
620
  return this.steps.push({ type: "sortByDesc", args: [t] }), typeof t == "string" && (this._sort = t, this._sortDesc = !0), this;
621
621
  };
622
- f.prototype.skip = function(t) {
622
+ g.prototype.skip = function(t) {
623
623
  if (t < 0)
624
624
  throw new Error("Offset must be non-negative");
625
625
  return this.already_offset && this.steps.push({ type: "skip", args: [t] }), this.offset = t, this.already_offset = !0, this;
626
626
  };
627
- f.prototype.take = function(t) {
627
+ g.prototype.take = function(t) {
628
628
  if (t < 0)
629
629
  throw new Error("Length must be non-negative");
630
630
  return this.already_limit ? (this.steps.push({ type: "take", args: [t] }), this) : (this.limit = t, this.already_limit = !0, this);
631
631
  };
632
- f.prototype.splice = function(t, e) {
632
+ g.prototype.splice = function(t, e) {
633
633
  return this.steps.push({ type: "splice", args: [t, e] }), this.offset = t, this.limit = e, this.already_limit = !0, this.already_offset = !0, this;
634
634
  };
635
- const A = (t, e, r) => {
636
- const s = new f(r, e);
637
- return s.data_path = I + t, s;
638
- }, O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
635
+ const N = (t, e, r) => {
636
+ const s = new g(r, e);
637
+ return s.data_path = X + t, s;
638
+ }, B = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
639
639
  __proto__: null,
640
- default: A
641
- }, Symbol.toStringTag, { value: "Module" })), V = (t, e) => ({
642
- uploadTempFile: (r) => l(e, "lightDriveUploadTempFile", {
640
+ default: N
641
+ }, Symbol.toStringTag, { value: "Module" })), x = (t, e) => ({
642
+ uploadTempFile: (r) => p(e, "lightDriveUploadTempFile", {
643
643
  index: t,
644
644
  file: r
645
645
  }, {
@@ -652,7 +652,7 @@ const A = (t, e, r) => {
652
652
  list: async (r, s = {
653
653
  name: !0,
654
654
  path: !0
655
- }) => (await w(e, {
655
+ }) => (await m(e, {
656
656
  app: {
657
657
  drive: {
658
658
  __args: {
@@ -667,9 +667,9 @@ const A = (t, e, r) => {
667
667
  }
668
668
  }
669
669
  })).app.drive.folders,
670
- create: (r) => l(e, "lightDriveCreateFolder", { index: t, path: r }),
671
- delete: (r) => l(e, "lightDriveDeleteFolder", { index: t, path: r }),
672
- rename: (r, s) => l(e, "lightDriveRenameFolder", { index: t, path: r, name: s })
670
+ create: (r) => p(e, "lightDriveCreateFolder", { index: t, path: r }),
671
+ delete: (r) => p(e, "lightDriveDeleteFolder", { index: t, path: r }),
672
+ rename: (r, s) => p(e, "lightDriveRenameFolder", { index: t, path: r, name: s })
673
673
  },
674
674
  files: {
675
675
  list: async (r, s = {
@@ -678,7 +678,7 @@ const A = (t, e, r) => {
678
678
  size: !0,
679
679
  mime: !0,
680
680
  url: !0
681
- }) => (await w(e, {
681
+ }) => (await m(e, {
682
682
  app: {
683
683
  drive: {
684
684
  __args: {
@@ -699,7 +699,7 @@ const A = (t, e, r) => {
699
699
  size: !0,
700
700
  mime: !0,
701
701
  url: !0
702
- }) => (await w(e, {
702
+ }) => (await m(e, {
703
703
  app: {
704
704
  drive: {
705
705
  __args: {
@@ -715,7 +715,7 @@ const A = (t, e, r) => {
715
715
  }
716
716
  })).app.drive.file,
717
717
  read: async (r) => {
718
- let s = await w(e, {
718
+ let s = await m(e, {
719
719
  app: {
720
720
  drive: {
721
721
  __args: {
@@ -734,90 +734,248 @@ const A = (t, e, r) => {
734
734
  throw new Error(`File not found or cannot read content: ${r}`);
735
735
  return typeof window < "u" && window.atob ? window.atob(s.app.drive.file.base64Content) : s.app.drive.file.base64Content;
736
736
  },
737
- write: (r, s) => l(e, "lightDriveWriteFile", { index: t, path: r, content: s }),
738
- delete: (r) => l(e, "lightDriveDeleteFile", { index: t, path: r }),
739
- rename: (r, s) => l(e, "lightDriveRenameFile", { index: t, path: r, name: s }),
740
- move: (r, s) => l(e, "lightDriveMoveFile", { index: t, source: r, destination: s })
737
+ write: (r, s) => p(e, "lightDriveWriteFile", { index: t, path: r, content: s }),
738
+ delete: (r) => p(e, "lightDriveDeleteFile", { index: t, path: r }),
739
+ rename: (r, s) => p(e, "lightDriveRenameFile", { index: t, path: r, name: s }),
740
+ move: (r, s) => p(e, "lightDriveMoveFile", { index: t, source: r, destination: s })
741
+ }
742
+ });
743
+ function v(t) {
744
+ if (t === null || typeof t != "object")
745
+ return !1;
746
+ const e = Object.getPrototypeOf(t);
747
+ 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;
748
+ }
749
+ function S(t, e, r = ".", s) {
750
+ if (!v(e))
751
+ return S(t, {}, r, s);
752
+ const i = Object.assign({}, e);
753
+ for (const h in t) {
754
+ if (h === "__proto__" || h === "constructor")
755
+ continue;
756
+ const f = t[h];
757
+ f != null && (s && s(i, h, f, r) || (Array.isArray(f) && Array.isArray(i[h]) ? i[h] = [...f, ...i[h]] : v(f) && v(i[h]) ? i[h] = S(
758
+ f,
759
+ i[h],
760
+ (r ? `${r}.` : "") + h.toString(),
761
+ s
762
+ ) : i[h] = f));
741
763
  }
742
- }), tt = (t) => {
764
+ return i;
765
+ }
766
+ function tt(t) {
767
+ return (...e) => (
768
+ // eslint-disable-next-line unicorn/no-array-reduce
769
+ e.reduce((r, s) => S(r, s, "", t), {})
770
+ );
771
+ }
772
+ const C = tt();
773
+ function et(t, e, r) {
774
+ let s, i = [], h, f;
775
+ const o = (n) => !n || typeof n != "object" ? !1 : Object.values(n).some((a) => a && typeof a == "object" && Object.keys(a).some((l) => l.startsWith("_"))), u = () => i.length === 0 ? (i.unshift({}), i[0]) : (o(i[0]) && i.unshift({}), i[0]);
776
+ return {
777
+ async fetchWithMeta() {
778
+ let a = await m(t, this.toQuery(!0));
779
+ if (f) {
780
+ const l = f.split(".");
781
+ for (const c of l)
782
+ a = a[c];
783
+ return a;
784
+ }
785
+ return a[`list${e}`];
786
+ },
787
+ async fetch() {
788
+ let a = await m(t, this.toQuery());
789
+ if (f) {
790
+ const l = f.split(".");
791
+ for (const c of l)
792
+ a = a[c];
793
+ return a.data;
794
+ }
795
+ return a[`list${e}`].data;
796
+ },
797
+ dataPath(n) {
798
+ return n && typeof n == "string" && (f = n), this;
799
+ },
800
+ sort(n) {
801
+ return n && typeof n == "string" && (h = n), this;
802
+ },
803
+ filters(n) {
804
+ return n && typeof n == "object" && (i = [n]), this;
805
+ },
806
+ // where can be called as:
807
+ // where('key', value) -> exact match
808
+ // where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
809
+ where(n, a, l) {
810
+ const c = (d, _, y) => {
811
+ const A = {
812
+ ">": "_gt",
813
+ "<": "_lt",
814
+ ">=": "_gte",
815
+ "<=": "_lte",
816
+ "!=": "_ne",
817
+ in: "_in",
818
+ contains: "_contains"
819
+ }[_];
820
+ A && i.push({ [d]: { [A]: y } });
821
+ };
822
+ if (l !== void 0)
823
+ c(n, String(a), l);
824
+ else {
825
+ const d = u(), _ = C(d, { [n]: a });
826
+ i[0] = _;
827
+ }
828
+ return this;
829
+ },
830
+ // whereContains adds a _contains filter for a specific field
831
+ // If the same field is used multiple times, it merges them into an array
832
+ whereContains(n, a) {
833
+ if (n && typeof n == "string") {
834
+ const l = u(), c = { _contains: a };
835
+ l[n] ? Array.isArray(l[n]) ? l[n].push(c) : l[n] = [l[n], c] : l[n] = [c], i[0] = l;
836
+ }
837
+ return this;
838
+ },
839
+ // ...existing code...
840
+ // whereIn adds an _in filter for a specific field
841
+ // If the same field is used multiple times, it merges them into an array
842
+ whereIn(n, a) {
843
+ if (n && typeof n == "string" && Array.isArray(a)) {
844
+ const l = u(), c = { _in: a };
845
+ l[n] ? Array.isArray(l[n]) ? l[n].push(c) : l[n] = [l[n], c] : l[n] = [c], i[0] = l;
846
+ }
847
+ return this;
848
+ },
849
+ // whereBetween adds a _between filter for a specific field
850
+ whereBetween(n, a, l) {
851
+ if (n && typeof n == "string") {
852
+ const c = u(), d = { _between: [a, l] };
853
+ c[n] ? Array.isArray(c[n]) ? c[n].push(d) : c[n] = [c[n], d] : c[n] = d, i[0] = c;
854
+ }
855
+ return this;
856
+ },
857
+ // limit sets paging/limit for the data selection
858
+ limit(n) {
859
+ return typeof n == "number" && Number.isFinite(n) && (s = C(s || {}, { limit: n })), this;
860
+ },
861
+ // offset sets the starting index for the data selection
862
+ offset(n) {
863
+ return typeof n == "number" && Number.isFinite(n) && (s = C(s || {}, { offset: n })), this;
864
+ },
865
+ toQuery(n = !1) {
866
+ let a;
867
+ const l = i.length > 0 && Object.keys(i[0] || {}).length > 0, c = l ? 1 : 0, d = i.length > c;
868
+ l && d ? a = i : d ? a = i.slice(c) : l && (a = i[0]);
869
+ const _ = C(
870
+ h ? { sort: h } : {},
871
+ a ? { filters: a } : {}
872
+ ), y = {
873
+ data: {
874
+ ...r
875
+ }
876
+ };
877
+ if (s && (y.data.__args = s), Object.keys(_).length > 0 && (y.__args = _), n && (y.meta = {
878
+ total: !0,
879
+ key: !0,
880
+ name: !0
881
+ }), f) {
882
+ const w = f.split(".");
883
+ let A = y;
884
+ for (let F = w.length - 1; F >= 0; F--)
885
+ A = {
886
+ [w[F]]: A
887
+ };
888
+ return A;
889
+ }
890
+ return {
891
+ [`list${e}`]: y
892
+ };
893
+ }
894
+ };
895
+ }
896
+ const at = (t) => {
743
897
  const e = typeof window > "u";
744
898
  let r = [];
745
- const s = R.create({
899
+ const s = L.create({
746
900
  baseURL: t,
747
901
  withCredentials: !0
748
902
  });
749
- e && (s.interceptors.request.use((n) => (n.withCredentials = !0, r.length > 0 && (n.headers.Cookie = r.join("; ")), n)), s.interceptors.response.use((n) => {
750
- if (n.headers["set-cookie"]) {
751
- const i = n.headers["set-cookie"].map((u) => u.split(";")[0]), o = r.map((u) => u.split("=")[0]), c = i.filter((u) => {
752
- const d = u.split("=")[0];
753
- return !o.includes(d);
754
- });
755
- r = [...r, ...c];
903
+ e && (s.interceptors.request.use((o) => (o.withCredentials = !0, r.length > 0 && (o.headers.Cookie = r.join("; ")), o)), s.interceptors.response.use((o) => {
904
+ if (o.headers["set-cookie"]) {
905
+ const u = o.headers["set-cookie"].map((a) => a.split(";")[0]), n = /* @__PURE__ */ new Map();
906
+ r.forEach((a) => {
907
+ const l = a.split("=")[0];
908
+ n.set(l, a);
909
+ }), u.forEach((a) => {
910
+ const l = a.split("=")[0];
911
+ n.set(l, a);
912
+ }), r = Array.from(n.values());
756
913
  }
757
- return n;
914
+ return o;
758
915
  }));
759
- const a = (n, i = null, o = []) => l(s, n, i, o), h = (n) => w(s, n), p = G(s);
916
+ const i = (o, u = null, n = []) => p(s, o, u, n), h = (o) => m(s, o), f = V(s);
760
917
  return {
761
918
  baseURL: t,
762
919
  axios: s,
763
- auth: S(s),
764
- mutation: a,
920
+ auth: M(s),
921
+ mutation: i,
765
922
  query: h,
766
- config: M(h),
767
- mail: W(s),
768
- users: z(s),
769
- fs: T(s),
770
- models: p,
771
- model(n) {
772
- return p.get(n);
923
+ config: G(h),
924
+ mail: I(s),
925
+ users: K(s),
926
+ fs: z(s),
927
+ models: f,
928
+ model(o) {
929
+ return f.get(o);
773
930
  },
774
- roles: Q(s),
775
- collect: (n, i) => {
776
- const o = A(n, s, i);
777
- return o.data_path = p.get(n).getDataPath(), o;
931
+ roles: H(s),
932
+ collect: (o, u) => {
933
+ const n = N(o, s, u);
934
+ return n.data_path = f.get(o).getDataPath(), n;
778
935
  },
779
- drive(n) {
780
- return V(n, s);
936
+ list: (o, u) => et(s, o, u).dataPath(f.get(o).getDataPath()),
937
+ drive(o) {
938
+ return x(o, s);
781
939
  },
782
- async collects(n) {
783
- const i = {}, o = {};
784
- for (const u in n) {
785
- const d = n[u].getQueryPayload();
786
- o[u] = d.data_path, i[u] = {};
787
- const g = d.data_path.split(".");
788
- let y = g[g.length - 1], _ = i[u];
789
- for (const b of g) {
790
- if (b === y) {
791
- _[b] = d.query;
940
+ async collects(o) {
941
+ const u = {}, n = {};
942
+ for (const l in o) {
943
+ const c = o[l].getQueryPayload();
944
+ n[l] = c.data_path, u[l] = {};
945
+ const d = c.data_path.split(".");
946
+ let _ = d[d.length - 1], y = u[l];
947
+ for (const w of d) {
948
+ if (w === _) {
949
+ y[w] = c.query;
792
950
  break;
793
951
  }
794
- _[b] = _[b] || {};
952
+ y[w] = y[w] || {};
795
953
  }
796
- i[u].__aliasFor = g[0];
954
+ u[l].__aliasFor = d[0];
797
955
  }
798
- const c = await w(s, i);
799
- for (const u in n) {
800
- const d = o[u].split(".");
801
- let g = d[d.length - 1], y = c[u];
802
- for (const _ of d) {
803
- if (_ === g) {
804
- n[u]._batchData = c[u][_];
956
+ const a = await m(s, u);
957
+ for (const l in o) {
958
+ const c = n[l].split(".");
959
+ let d = c[c.length - 1], _ = a[l];
960
+ for (const y of c) {
961
+ if (y === d) {
962
+ o[l]._batchData = a[l][y];
805
963
  break;
806
964
  }
807
- y[_] = y[_] || {};
965
+ _[y] = _[y] || {};
808
966
  }
809
967
  }
810
- return n;
968
+ return o;
811
969
  }
812
970
  };
813
971
  };
814
972
  export {
815
- x as File,
816
- tt as createClient,
817
- A as createCollection,
818
- k as file,
819
- l as mutation,
820
- w as query,
821
- C as toQuery,
822
- E as useWebAuthn
973
+ ot as File,
974
+ at as createClient,
975
+ N as createCollection,
976
+ D as file,
977
+ p as mutation,
978
+ m as query,
979
+ O as toQuery,
980
+ U as useWebAuthn
823
981
  };
@@ -1 +1 @@
1
- (function(_,y){typeof exports=="object"&&typeof module<"u"?y(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"],y):(_=typeof globalThis<"u"?globalThis:_||self,y(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,y,k,O){"use strict";var H=Object.defineProperty;var X=(_,y,k)=>y in _?H(_,y,{enumerable:!0,configurable:!0,writable:!0,value:k}):_[y]=k;var C=(_,y,k)=>X(_,typeof y!="symbol"?y+"":y,k);const j=t=>({assertion:async()=>{const{app:s}=await w(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 w(t,{app:{auth:{webAuthnCreationOptions:!0}}}),i=PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:i})}}),q=t=>{const{assertion:e,attestation:r}=j(t);return{login:async()=>{const s=await e();await o(t,"webAuthnAssertion",{assertion:s.toJSON()})},register:async()=>{const s=await r();await o(t,"webAuthnRegister",{registration:s.toJSON()})}}},B=t=>({WebAuthn:q(t),google:{unlink:()=>o(t,"lightAuthUnlinkGoogle"),login:e=>o(t,"lightAuthLoginGoogle",{credential:e}),register:e=>o(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>o(t,"lightAuthUnlinkFacebook"),login:e=>o(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>o(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>o(t,"lightAuthUnlinkMicrosoft"),login:e=>o(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>o(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>o(t,"login",{username:e,password:r,code:s}),logout:()=>o(t,"logout"),changeExpiredPassword:(e,r,s)=>o(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>o(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>o(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>o(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return o(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await w(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}}),R=(t,e,r)=>{const s=e,i=t,h=r;let p="list"+e;const n=a=>h[a]?h[a]():null;return{field:n,$fields:h,setDataPath(a){return p=a,p},getDataPath(){return p},gqlFields(a){const l=[];for(const c of a)if(typeof c=="string"){const u=n(c);u&&l.push(u.getGQLField())}else typeof c=="object"&&l.push(c);return l},async update(a,l){return await o(i,"update"+s,{id:a,data:l})},async delete(a){return await o(i,"delete"+s,{id:a})},async add(a){return await o(i,"add"+s,{data:a})},fields(a){let l=[];for(let c of a){const u=n(c);u&&l.push(u)}return l},async get(a,l){const c=(await Promise.resolve().then(()=>N)).default,u=c(s,i,D(l));for(const[d,g]of Object.entries(a))u.where(d,"==",g);return await u.first()},async list(a,l){const c=(await Promise.resolve().then(()=>N)).default,u=c(s,i,D(l));for(const[d,g]of Object.entries(a))u.where(d,"==",g);return await u.all()}}};function E(t){t="<~"+t+"~>";var e,r,s,i,h,p=String,n=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(n&r>>24,n&r>>16,n&r>>8,n&r);return function(a,l){for(var c=l;c>0;c--)a.pop()}(s,e.length),p.fromCharCode.apply(p,s)}const v=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let n=0;n<e.length;n++)i[n]=e.charCodeAt(n);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")}}},S={fromBase85:t=>v(E(t)),fromBase64:t=>v(atob(t)),fromString:t=>v(t)},P=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(P(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]=P(s)}),e)},D=t=>P(t),w=async(t,e)=>{let r=y.jsonToGraphQLQuery(D(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 L(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function U(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const o=async(t,e,r=null,s=[])=>{let i={[e]:{}};const h=new FormData;let p=!1;if(r){const l={},c={},u={};let d=0;Object.entries(r).forEach(([g,b])=>{if(b instanceof Array&&L(b)){p=!0;let m=0;b.forEach(F=>{F instanceof File&&(l[g]=new y.VariableType(g),c[d]=["variables."+g+"."+m],h.append(d.toString(),F),d++)}),u[g]="[Upload!]!"}else b instanceof File?(p=!0,l[g]=new y.VariableType(g),c[d]=["variables."+g],h.append(d.toString(),b),u[g]="Upload!",d++):b instanceof Object&&U(b)?(p=!0,l[g]={},Object.entries(b).forEach(([m,F])=>{F instanceof File?(l[g][m]=new y.VariableType(m),c[d]=["variables."+m],h.append(d.toString(),F),u[m]="Upload!",d++):l[g][m]=F})):b!==void 0&&(l[g]=b)}),i[e].__args=l,i.__variables=u,p&&h.append("map",JSON.stringify(c))}Object.entries(D(s)).forEach(([l,c])=>{i[e][l]=c}),Object.entries(i[e]).length===0&&(i[e]=!0);let n=null;const a=y.jsonToGraphQLQuery({mutation:i});if(p?(h.append("operations",JSON.stringify({query:a})),n=await t.post("",h)):n=await t.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data[e]},J=t=>({uploadTempFile:e=>o(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await w(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>o(t,"fsCreateFolder",{path:e}),delete:e=>o(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>o(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await w(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 w(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>o(t,"fsWriteFile",{path:e,content:r}),delete:e=>o(t,"fsDeleteFile",{path:e}),rename:(e,r)=>o(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>o(t,"fsMoveFile",{source:e,target:r})}}),T=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),M=t=>({send:(e,r,s)=>o(t,"sendMail",{email:e,subject:r,message:s})}),W=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=A("Users",t,e);return r.data_path="app.users",r.all()}}),z=t=>{const e=t,r={};return{create(s,i){r[s]=null;let h={};for(const p of Object.entries(i)){const[n,a]=p;h[n]=()=>({name:a.name?a.name:n,raw:a,getName:()=>a.name?a.name:n,getGQLField:()=>a.gqlField!==void 0?a.gqlField:a.name||n,getRaw(){return a},getValue(l){return a.field&&typeof a.field=="function"?a.field(l):a.field&&typeof a.field=="string"?l[a.field]:l[this.getName()]},getFormattedValue(l){const c=this.getValue(l);return a.format?a.format(c):c}})}r[s]=R(e,s,h)},get(s){return r[s]||this.create(s,{}),r[s]}}},Q=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await w(t,{app:{roles:e}});return r}}),V="list",I=["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"],$=["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 f{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}}f.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}},f.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},f.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},f.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},O().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),f.prototype.fetchData=async function(){try{if(this._batchData){const n=this._batchData;return this.meta=n.meta,O(n.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 n of e){if(n===i){s[n]=t;break}s[n]={},s=s[n]}let p=await w(this.axios,r);for(const n of e)p=p[n];return this.meta=p.meta,O(p.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},f.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},f.prototype.all=async function(){return(await this.processData()).all()};for(const t of I)f.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of $)f.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};f.prototype.average=f.prototype.avg,f.prototype.first=async function(){return this.take(1),(await this.processData()).first()},f.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},f.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},f.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},f.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)},f.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},f.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},f.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},f.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},f.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},f.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},f.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},f.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)},f.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 A=(t,e,r)=>{const s=new f(r,e);return s.data_path=V+t,s},N=Object.freeze(Object.defineProperty({__proto__:null,default:A},Symbol.toStringTag,{value:"Module"})),G=(t,e)=>({uploadTempFile:r=>o(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await w(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>o(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>o(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>o(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(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 w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await w(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)=>o(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>o(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>o(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>o(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),K=t=>{const e=typeof window>"u";let r=[];const s=k.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(n=>(n.withCredentials=!0,r.length>0&&(n.headers.Cookie=r.join("; ")),n)),s.interceptors.response.use(n=>{if(n.headers["set-cookie"]){const a=n.headers["set-cookie"].map(u=>u.split(";")[0]),l=r.map(u=>u.split("=")[0]),c=a.filter(u=>{const d=u.split("=")[0];return!l.includes(d)});r=[...r,...c]}return n}));const i=(n,a=null,l=[])=>o(s,n,a,l),h=n=>w(s,n),p=z(s);return{baseURL:t,axios:s,auth:B(s),mutation:i,query:h,config:T(h),mail:M(s),users:W(s),fs:J(s),models:p,model(n){return p.get(n)},roles:Q(s),collect:(n,a)=>{const l=A(n,s,a);return l.data_path=p.get(n).getDataPath(),l},drive(n){return G(n,s)},async collects(n){const a={},l={};for(const u in n){const d=n[u].getQueryPayload();l[u]=d.data_path,a[u]={};const g=d.data_path.split(".");let b=g[g.length-1],m=a[u];for(const F of g){if(F===b){m[F]=d.query;break}m[F]=m[F]||{}}a[u].__aliasFor=g[0]}const c=await w(s,a);for(const u in n){const d=l[u].split(".");let g=d[d.length-1],b=c[u];for(const m of d){if(m===g){n[u]._batchData=c[u][m];break}b[m]=b[m]||{}}}return n}}};_.File=S,_.createClient=K,_.createCollection=A,_.file=v,_.mutation=o,_.query=w,_.toQuery=D,_.useWebAuthn=j,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 a=u=>h[u]?h[u]():null;return{field:a,$fields:h,setDataPath(u){return f=u,f},getDataPath(){return f},gqlFields(u){const n=[];for(const o of u)if(typeof o=="string"){const l=a(o);l&&n.push(l.getGQLField())}else typeof o=="object"&&n.push(o);return n},async update(u,n){return await p(i,"update"+s,{id:u,data:n})},async delete(u){return await p(i,"delete"+s,{id:u})},async add(u){return await p(i,"add"+s,{data:u})},fields(u){let n=[];for(let o of u){const l=a(o);l&&n.push(l)}return n},async get(u,n){const o=(await Promise.resolve().then(()=>R)).default,l=o(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.first()},async list(u,n){const o=(await Promise.resolve().then(()=>R)).default,l=o(s,i,k(n));for(const[c,d]of Object.entries(u))l.where(c,"==",d);return await l.all()}}};function M(t){t="<~"+t+"~>";var e,r,s,i,h,f=String,a=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],i=0,h=t.length;h>i;i+=5)r=52200625*(t.charCodeAt(i)-33)+614125*(t.charCodeAt(i+1)-33)+7225*(t.charCodeAt(i+2)-33)+85*(t.charCodeAt(i+3)-33)+(t.charCodeAt(i+4)-33),s.push(a&r>>24,a&r>>16,a&r>>8,a&r);return function(u,n){for(var o=n;o>0;o--)u.pop()}(s,e.length),f.fromCharCode.apply(f,s)}const D=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let a=0;a<e.length;a++)i[a]=e.charCodeAt(a);const h=new Blob([i],{type:s});return URL.createObjectURL(h)};return{getContent:()=>e,getURL:r,download:s=>{const i=document.createElement("a");i.download=s,i.href=r(),document.body.appendChild(i),i.click(),document.body.removeChild(i)},open:s=>{window.open(r(s),"_blank")}}},T={fromBase85:t=>D(M(t)),fromBase64:t=>D(atob(t)),fromString:t=>D(t)},S=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(S(r)).forEach(([s,i])=>{e[s]=i})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=S(s)}),e)},k=t=>S(t),b=async(t,e)=>{let r=m.jsonToGraphQLQuery(k(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function W(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function Q(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const p=async(t,e,r=null,s=[])=>{let i={[e]:{}};const h=new FormData;let f=!1;if(r){const n={},o={},l={};let c=0;Object.entries(r).forEach(([d,w])=>{if(w instanceof Array&&W(w)){f=!0;let y=0;w.forEach(A=>{A instanceof File&&(n[d]=new m.VariableType(d),o[c]=["variables."+d+"."+y],h.append(c.toString(),A),c++)}),l[d]="[Upload!]!"}else w instanceof File?(f=!0,n[d]=new m.VariableType(d),o[c]=["variables."+d],h.append(c.toString(),w),l[d]="Upload!",c++):w instanceof Object&&Q(w)?(f=!0,n[d]={},Object.entries(w).forEach(([y,A])=>{A instanceof File?(n[d][y]=new m.VariableType(y),o[c]=["variables."+y],h.append(c.toString(),A),l[y]="Upload!",c++):n[d][y]=A})):w!==void 0&&(n[d]=w)}),i[e].__args=n,i.__variables=l,f&&h.append("map",JSON.stringify(o))}Object.entries(k(s)).forEach(([n,o])=>{i[e][n]=o}),Object.entries(i[e]).length===0&&(i[e]=!0);let a=null;const u=m.jsonToGraphQLQuery({mutation:i});if(f?(h.append("operations",JSON.stringify({query:u})),a=await t.post("",h)):a=await t.post("",{query:u}),a.data.errors)throw new Error(a.data.errors[0].message);return a.data.data[e]},$=t=>({uploadTempFile:e=>p(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await b(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>p(t,"fsCreateFolder",{path:e}),delete:e=>p(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>p(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await b(t,{app:{drive:{files:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}}}});return r.drive.files},read:async e=>{let{app:r}=await b(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>p(t,"fsWriteFile",{path:e,content:r}),delete:e=>p(t,"fsDeleteFile",{path:e}),rename:(e,r)=>p(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>p(t,"fsMoveFile",{source:e,target:r})}}),z=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),I=t=>({send:(e,r,s)=>p(t,"sendMail",{email:e,subject:r,message:s})}),K=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=j("Users",t,e);return r.data_path="app.users",r.all()}}),G=t=>{const e=t,r={};return{create(s,i){r[s]=null;let h={};for(const f of Object.entries(i)){const[a,u]=f;h[a]=()=>({name:u.name?u.name:a,raw:u,getName:()=>u.name?u.name:a,getGQLField:()=>u.gqlField!==void 0?u.gqlField:u.name||a,getRaw(){return u},getValue(n){return u.field&&typeof u.field=="function"?u.field(n):u.field&&typeof u.field=="string"?n[u.field]:n[this.getName()]},getFormattedValue(n){const o=this.getValue(n);return u.format?u.format(o):o}})}r[s]=J(e,s,h)},get(s){return r[s]||this.create(s,{}),r[s]}}},V=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await b(t,{app:{roles:e}});return r}}),H="list",X=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],Y=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition"];class g{constructor(e,r){C(this,"_batchData",null);C(this,"data_path","");C(this,"axios");C(this,"filters");C(this,"steps");C(this,"fields");C(this,"already_limit",!1);C(this,"already_offset",!1);C(this,"limit",null);C(this,"offset",null);C(this,"_sort",null);C(this,"_sortDesc",!1);C(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}g.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},g.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},g.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},g.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},P().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),g.prototype.fetchData=async function(){try{if(this._batchData){const a=this._batchData;return this.meta=a.meta,P(a.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,i=e[e.length-1];for(const a of e){if(a===i){s[a]=t;break}s[a]={},s=s[a]}let f=await b(this.axios,r);for(const a of e)f=f[a];return this.meta=f.meta,P(f.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},g.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},g.prototype.all=async function(){return(await this.processData()).all()};for(const t of X)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Y)g.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};g.prototype.average=g.prototype.avg,g.prototype.first=async function(){return this.take(1),(await this.processData()).first()},g.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},g.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],s=t[1],i=t[2];switch(s){case"==":this.filters[r]=i;break;case"<":this.filters[r]={lt:i};break;case"<=":this.filters[r]={lte:i};break;case">":this.filters[r]={gt:i};break;case">=":this.filters[r]={gte:i};break;case"!==":this.filters[r]={ne:i};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},g.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},g.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},g.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},g.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},g.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},g.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},g.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},g.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},g.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},g.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},g.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const j=(t,e,r)=>{const s=new g(r,e);return s.data_path=H+t,s},R=Object.freeze(Object.defineProperty({__proto__:null,default:j},Symbol.toStringTag,{value:"Module"})),Z=(t,e)=>({uploadTempFile:r=>p(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await b(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>p(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>p(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await b(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await b(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await b(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});if(!s.app.drive.file||!s.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${r}`);return typeof window<"u"&&window.atob?window.atob(s.app.drive.file.base64Content):s.app.drive.file.base64Content},write:(r,s)=>p(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>p(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>p(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>p(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}});function N(t){if(t===null||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null||Symbol.iterator in t?!1:Symbol.toStringTag in t?Object.prototype.toString.call(t)==="[object Module]":!0}function B(t,e,r=".",s){if(!N(e))return B(t,{},r,s);const i=Object.assign({},e);for(const h in t){if(h==="__proto__"||h==="constructor")continue;const f=t[h];f!=null&&(s&&s(i,h,f,r)||(Array.isArray(f)&&Array.isArray(i[h])?i[h]=[...f,...i[h]]:N(f)&&N(i[h])?i[h]=B(f,i[h],(r?`${r}.`:"")+h.toString(),s):i[h]=f))}return i}function x(t){return(...e)=>e.reduce((r,s)=>B(r,s,"",t),{})}const v=x();function tt(t,e,r){let s,i=[],h,f;const a=n=>!n||typeof n!="object"?!1:Object.values(n).some(o=>o&&typeof o=="object"&&Object.keys(o).some(l=>l.startsWith("_"))),u=()=>i.length===0?(i.unshift({}),i[0]):(a(i[0])&&i.unshift({}),i[0]);return{async fetchWithMeta(){let o=await b(t,this.toQuery(!0));if(f){const l=f.split(".");for(const c of l)o=o[c];return o}return o[`list${e}`]},async fetch(){let o=await b(t,this.toQuery());if(f){const l=f.split(".");for(const c of l)o=o[c];return o.data}return o[`list${e}`].data},dataPath(n){return n&&typeof n=="string"&&(f=n),this},sort(n){return n&&typeof n=="string"&&(h=n),this},filters(n){return n&&typeof n=="object"&&(i=[n]),this},where(n,o,l){const c=(d,w,y)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[w];F&&i.push({[d]:{[F]:y}})};if(l!==void 0)c(n,String(o),l);else{const d=u(),w=v(d,{[n]:o});i[0]=w}return this},whereContains(n,o){if(n&&typeof n=="string"){const l=u(),c={_contains:o};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereIn(n,o){if(n&&typeof n=="string"&&Array.isArray(o)){const l=u(),c={_in:o};l[n]?Array.isArray(l[n])?l[n].push(c):l[n]=[l[n],c]:l[n]=[c],i[0]=l}return this},whereBetween(n,o,l){if(n&&typeof n=="string"){const c=u(),d={_between:[o,l]};c[n]?Array.isArray(c[n])?c[n].push(d):c[n]=[c[n],d]:c[n]=d,i[0]=c}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(s=v(s||{},{offset:n})),this},toQuery(n=!1){let o;const l=i.length>0&&Object.keys(i[0]||{}).length>0,c=l?1:0,d=i.length>c;l&&d?o=i:d?o=i.slice(c):l&&(o=i[0]);const w=v(h?{sort:h}:{},o?{filters:o}:{}),y={data:{...r}};if(s&&(y.data.__args=s),Object.keys(w).length>0&&(y.__args=w),n&&(y.meta={total:!0,key:!0,name:!0}),f){const A=f.split(".");let F=y;for(let E=A.length-1;E>=0;E--)F={[A[E]]:F};return F}return{[`list${e}`]:y}}}}const et=t=>{const e=typeof window>"u";let r=[];const s=O.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(a=>(a.withCredentials=!0,r.length>0&&(a.headers.Cookie=r.join("; ")),a)),s.interceptors.response.use(a=>{if(a.headers["set-cookie"]){const u=a.headers["set-cookie"].map(o=>o.split(";")[0]),n=new Map;r.forEach(o=>{const l=o.split("=")[0];n.set(l,o)}),u.forEach(o=>{const l=o.split("=")[0];n.set(l,o)}),r=Array.from(n.values())}return a}));const i=(a,u=null,n=[])=>p(s,a,u,n),h=a=>b(s,a),f=G(s);return{baseURL:t,axios:s,auth:U(s),mutation:i,query:h,config:z(h),mail:I(s),users:K(s),fs:$(s),models:f,model(a){return f.get(a)},roles:V(s),collect:(a,u)=>{const n=j(a,s,u);return n.data_path=f.get(a).getDataPath(),n},list:(a,u)=>tt(s,a,u).dataPath(f.get(a).getDataPath()),drive(a){return Z(a,s)},async collects(a){const u={},n={};for(const l in a){const c=a[l].getQueryPayload();n[l]=c.data_path,u[l]={};const d=c.data_path.split(".");let w=d[d.length-1],y=u[l];for(const A of d){if(A===w){y[A]=c.query;break}y[A]=y[A]||{}}u[l].__aliasFor=d[0]}const o=await b(s,u);for(const l in a){const c=n[l].split(".");let d=c[c.length-1],w=o[l];for(const y of c){if(y===d){a[l]._batchData=o[l][y];break}w[y]=w[y]||{}}}return a}}};_.File=T,_.createClient=et,_.createCollection=j,_.file=D,_.mutation=p,_.query=b,_.toQuery=k,_.useWebAuthn=q,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "2.9.0",
3
+ "version": "2.11.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -31,6 +31,7 @@
31
31
  "dependencies": {
32
32
  "axios": "^1.11.0",
33
33
  "collect.js": "^4.36.1",
34
+ "defu": "^6.1.4",
34
35
  "json-to-graphql-query": "^2.3.0"
35
36
  }
36
37
  }