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