@hostlink/light 3.0.1 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/auth.d.ts CHANGED
@@ -8,7 +8,8 @@ export declare const updatePassword: (oldPassword: string, newPassword: string)
8
8
  export declare const resetPassword: (jwt: string, password: string, code: string) => Promise<boolean>;
9
9
  export declare const forgetPassword: (username: string, email: string) => Promise<string>;
10
10
  export declare const verifyCode: (jwt: string, code: string) => Promise<boolean>;
11
- export declare const granted: (rights: string[]) => Promise<string[]>;
11
+ export declare const isGranted: (right: string) => Promise<boolean>;
12
+ export declare const getGrantedRights: (rights: string[]) => Promise<string[]>;
12
13
  declare const _default: () => {
13
14
  getCurrentUser: (fields?: QueryUserFieldsUserFields) => Promise<any>;
14
15
  webAuthn: typeof webAuthn;
@@ -34,6 +35,7 @@ declare const _default: () => {
34
35
  resetPassword: (jwt: string, password: string, code: string) => Promise<boolean>;
35
36
  forgetPassword: (username: string, email: string) => Promise<string>;
36
37
  verifyCode: (jwt: string, code: string) => Promise<boolean>;
37
- granted: (rights: string[]) => Promise<string[]>;
38
+ grantedRights: (rights: string[]) => Promise<string[]>;
39
+ isGranted: (right: string) => Promise<boolean>;
38
40
  };
39
41
  export default _default;
package/dist/drive.d.ts CHANGED
@@ -26,6 +26,7 @@ export declare const getDrive: (index: number) => {
26
26
  files: {
27
27
  list: (path: string, fields?: import('./file').QueryFileFields) => Promise<any>;
28
28
  get: (path: string, fields?: import('./file').QueryFileFields) => Promise<any>;
29
+ readFileAsBase64(path: string): Promise<string>;
29
30
  read: (path: string) => Promise<any>;
30
31
  write: (path: string, content: string) => Promise<any>;
31
32
  delete: (path: string) => Promise<any>;
@@ -65,6 +66,7 @@ declare const _default: () => {
65
66
  files: {
66
67
  list: (path: string, fields?: import('./file').QueryFileFields) => Promise<any>;
67
68
  get: (path: string, fields?: import('./file').QueryFileFields) => Promise<any>;
69
+ readFileAsBase64(path: string): Promise<string>;
68
70
  read: (path: string) => Promise<any>;
69
71
  write: (path: string, content: string) => Promise<any>;
70
72
  delete: (path: string) => Promise<any>;
package/dist/file.d.ts CHANGED
@@ -7,9 +7,11 @@ export type FileFields = {
7
7
  };
8
8
  export type QueryFileFields = Partial<Record<keyof FileFields, boolean>>;
9
9
  export declare const listFiles: (index: number, path: string, fields?: QueryFileFields) => Promise<any>;
10
+ export declare const readFileAsBase64: (index: number, path: string) => Promise<string>;
10
11
  declare const _default: (index: number) => {
11
12
  list: (path: string, fields?: QueryFileFields) => Promise<any>;
12
13
  get: (path: string, fields?: QueryFileFields) => Promise<any>;
14
+ readFileAsBase64(path: string): Promise<string>;
13
15
  read: (path: string) => Promise<any>;
14
16
  write: (path: string, content: string) => Promise<any>;
15
17
  delete: (path: string) => Promise<any>;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { default as createList } from './createList';
1
2
  export { default as useModel, useGlobalModel, useGlobalModels, createModelManager } from './models';
2
3
  export type { ModelManager } from './models';
3
4
  export * from './permission';
@@ -5,6 +6,7 @@ export * as webAuthn from './webauthn';
5
6
  export * from './auth';
6
7
  export { default as auth } from './auth';
7
8
  export * from './drive';
9
+ export * from './folder';
8
10
  export * from './users';
9
11
  export * from './config';
10
12
  export * from './role';
@@ -19,5 +21,6 @@ export { default as createClient } from './createClient';
19
21
  export type { LightClient } from './createClient';
20
22
  export { default as createCollection } from './createCollection';
21
23
  export { default as createList } from './createList';
24
+ export declare const list: typeof createList;
22
25
  export type { RoleFields } from './role';
23
26
  export { setApiClient, getApiClient, getApiClientOptional } from './apiClient';
package/dist/light.js CHANGED
@@ -1,21 +1,21 @@
1
- import { jsonToGraphQLQuery as v, VariableType as F } from "json-to-graphql-query";
1
+ import { jsonToGraphQLQuery as q, VariableType as F } from "json-to-graphql-query";
2
2
  import H from "axios";
3
- import M from "collect.js";
4
- function P(t) {
3
+ import E from "collect.js";
4
+ function M(t) {
5
5
  if (t === null || typeof t != "object")
6
6
  return !1;
7
7
  const e = Object.getPrototypeOf(t);
8
8
  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;
9
9
  }
10
- function E(t, e, r = ".", n) {
11
- if (!P(e))
12
- return E(t, {}, r, n);
10
+ function S(t, e, r = ".", n) {
11
+ if (!M(e))
12
+ return S(t, {}, r, n);
13
13
  const i = Object.assign({}, e);
14
14
  for (const f in t) {
15
15
  if (f === "__proto__" || f === "constructor")
16
16
  continue;
17
17
  const a = t[f];
18
- a != null && (n && n(i, f, a, r) || (Array.isArray(a) && Array.isArray(i[f]) ? i[f] = [...a, ...i[f]] : P(a) && P(i[f]) ? i[f] = E(
18
+ a != null && (n && n(i, f, a, r) || (Array.isArray(a) && Array.isArray(i[f]) ? i[f] = [...a, ...i[f]] : M(a) && M(i[f]) ? i[f] = S(
19
19
  a,
20
20
  i[f],
21
21
  (r ? `${r}.` : "") + f.toString(),
@@ -27,7 +27,7 @@ function E(t, e, r = ".", n) {
27
27
  function X(t) {
28
28
  return (...e) => (
29
29
  // eslint-disable-next-line unicorn/no-array-reduce
30
- e.reduce((r, n) => E(r, n, "", t), {})
30
+ e.reduce((r, n) => S(r, n, "", t), {})
31
31
  );
32
32
  }
33
33
  const A = X();
@@ -38,7 +38,7 @@ const Y = (t) => {
38
38
  if (!k)
39
39
  throw new Error("Api client not initialized. Call setApiClient() first.");
40
40
  return k;
41
- }, Ut = () => k;
41
+ }, qt = () => k;
42
42
  function j(t) {
43
43
  for (let e = 0; e < t.length; e++)
44
44
  if (t[e] instanceof File)
@@ -69,8 +69,8 @@ function J(t, e, r, n, i) {
69
69
  if (h instanceof Array && j(h)) {
70
70
  s[o][l] = new F(l);
71
71
  let _ = 0;
72
- h.forEach((d) => {
73
- d instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + l + "." + _), n.append(i.current.toString(), d), i.current++, _++);
72
+ h.forEach((g) => {
73
+ g instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + l + "." + _), n.append(i.current.toString(), g), i.current++, _++);
74
74
  }), e[l] = "[Upload!]!";
75
75
  } else h instanceof File ? (s[o][l] = new F(l), r[i.current] = ["variables." + l], n.append(i.current.toString(), h), e[l] = "Upload!", i.current++) : s[o][l] = h;
76
76
  })) : c != null && (s[o] = c);
@@ -86,7 +86,7 @@ const y = async (t) => {
86
86
  const f = {}, a = {};
87
87
  J(r, f, a, n, { current: 0 }), i = Object.keys(f).length > 0, i && (r.__variables = f);
88
88
  let s = null;
89
- const c = v({ query: r });
89
+ const c = q({ query: r });
90
90
  if (i ? (n.append("map", JSON.stringify(a)), n.append("operations", JSON.stringify({
91
91
  query: c
92
92
  })), s = await e.axios.post("", n)) : s = await e.axios.post("", {
@@ -95,7 +95,7 @@ const y = async (t) => {
95
95
  throw new Error(s.data.errors[0].message);
96
96
  return s.data.data;
97
97
  };
98
- function U(t, e) {
98
+ function C(t, e) {
99
99
  let r, n = [], i, f;
100
100
  const a = (s) => !s || typeof s != "object" ? !1 : Object.values(s).some((o) => o && typeof o == "object" && Object.keys(o).some((c) => c.startsWith("_"))), u = () => n.length === 0 ? (n.unshift({}), n[0]) : (a(n[0]) && n.unshift({}), n[0]);
101
101
  return {
@@ -142,7 +142,7 @@ function U(t, e) {
142
142
  // where('key', value) -> exact match
143
143
  // where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
144
144
  where(s, o, c) {
145
- const l = (h, _, d) => {
145
+ const l = (h, _, g) => {
146
146
  const O = {
147
147
  ">": "_gt",
148
148
  "<": "_lt",
@@ -152,7 +152,7 @@ function U(t, e) {
152
152
  in: "_in",
153
153
  contains: "_contains"
154
154
  }[_];
155
- O && n.push({ [h]: { [O]: d } });
155
+ O && n.push({ [h]: { [O]: g } });
156
156
  };
157
157
  if (c !== void 0)
158
158
  l(s, String(o), c);
@@ -204,26 +204,26 @@ function U(t, e) {
204
204
  const _ = A(
205
205
  i ? { sort: i } : {},
206
206
  o ? { filters: o } : {}
207
- ), d = {
207
+ ), g = {
208
208
  data: {
209
209
  ...e
210
210
  }
211
211
  };
212
- if (r && (d.data.__args = r), Object.keys(_).length > 0 && (d.__args = _), s && (d.meta = {
212
+ if (r && (g.data.__args = r), Object.keys(_).length > 0 && (g.__args = _), s && (g.meta = {
213
213
  total: !0,
214
214
  key: !0,
215
215
  name: !0
216
216
  }), f) {
217
217
  const w = f.split(".");
218
- let O = d;
219
- for (let C = w.length - 1; C >= 0; C--)
218
+ let O = g;
219
+ for (let P = w.length - 1; P >= 0; P--)
220
220
  O = {
221
- [w[C]]: O
221
+ [w[P]]: O
222
222
  };
223
223
  return O;
224
224
  }
225
225
  return {
226
- [`list${t}`]: d
226
+ [`list${t}`]: g
227
227
  };
228
228
  }
229
229
  };
@@ -280,7 +280,7 @@ const L = (t, e) => {
280
280
  return u;
281
281
  },
282
282
  async get(a, u) {
283
- const s = (await Promise.resolve().then(() => Pt)).default, o = s(r, Dt(u));
283
+ const s = (await Promise.resolve().then(() => Et)).default, o = s(r, kt(u));
284
284
  for (const [c, l] of Object.entries(a))
285
285
  o.where(c, "==", l);
286
286
  return await o.first();
@@ -291,14 +291,14 @@ const L = (t, e) => {
291
291
  Object.entries(a).forEach(([l]) => {
292
292
  n[l] && (s[l] = n[l], n[l].gqlField && (delete u[l], u = A(u, n[l].gqlField)), n[l].gql && (u = A(u, n[l].gql), delete u[l]));
293
293
  });
294
- const o = U(r, u).dataPath(i), c = o.fetch.bind(o);
294
+ const o = C(r, u).dataPath(i), c = o.fetch.bind(o);
295
295
  return {
296
296
  ...o,
297
297
  async fetch() {
298
298
  return (await c()).map((h) => {
299
299
  const _ = { ...h };
300
- return Object.entries(s).forEach(([d, w]) => {
301
- w.format && typeof w.format == "function" && (_[d] = w.format(h));
300
+ return Object.entries(s).forEach(([g, w]) => {
301
+ w.format && typeof w.format == "function" && (_[g] = w.format(h));
302
302
  }), _;
303
303
  });
304
304
  },
@@ -306,14 +306,14 @@ const L = (t, e) => {
306
306
  const h = await o.fetchFirst.bind(o)();
307
307
  if (!h) return h;
308
308
  const _ = { ...h };
309
- return Object.entries(s).forEach(([d, w]) => {
310
- w.format && typeof w.format == "function" && (_[d] = w.format(h));
309
+ return Object.entries(s).forEach(([g, w]) => {
310
+ w.format && typeof w.format == "function" && (_[g] = w.format(h));
311
311
  }), _;
312
312
  }
313
313
  };
314
314
  }
315
315
  };
316
- }, b = {}, q = (t = !1) => {
316
+ }, b = {}, v = (t = !1) => {
317
317
  const e = {};
318
318
  return {
319
319
  /**
@@ -356,8 +356,8 @@ const L = (t, e) => {
356
356
  Object.keys(e).forEach((r) => delete e[r]);
357
357
  }
358
358
  };
359
- }, qt = () => {
360
- const t = q(!1);
359
+ }, Nt = () => {
360
+ const t = v(!1);
361
361
  return {
362
362
  // 暴露完整的管理器
363
363
  manager: t,
@@ -386,8 +386,8 @@ const L = (t, e) => {
386
386
  });
387
387
  }
388
388
  };
389
- }, vt = () => {
390
- const t = q(!0);
389
+ }, Bt = () => {
390
+ const t = v(!0);
391
391
  return {
392
392
  // 暴露完整的管理器
393
393
  manager: t,
@@ -416,7 +416,7 @@ const L = (t, e) => {
416
416
  });
417
417
  }
418
418
  };
419
- }, Nt = () => ({
419
+ }, Jt = () => ({
420
420
  /**
421
421
  * 創建全域模型
422
422
  * @param name 模型名稱
@@ -455,7 +455,7 @@ const L = (t, e) => {
455
455
  clear() {
456
456
  Object.keys(b).forEach((t) => delete b[t]);
457
457
  }
458
- }), Bt = () => y({
458
+ }), Lt = () => y({
459
459
  app: {
460
460
  permissions: !0
461
461
  }
@@ -497,7 +497,15 @@ const L = (t, e) => {
497
497
  attestation: T,
498
498
  login: Z,
499
499
  register: V
500
- }, Symbol.toStringTag, { value: "Module" })), I = (t = G) => y({ my: t }).then((e) => e.my), x = (t, e, r = "") => p({ login: { __args: { username: t, password: e, code: r } } }).then((n) => n.login), tt = () => p({ logout: !0 }).then((t) => t.logout), et = (t, e, r) => p({ changeExpiredPassword: { __args: { username: t, old_password: e, new_password: r } } }).then((n) => n.changeExpiredPassword), rt = (t, e) => p({ changeUserPassword: { __args: { old_password: t, new_password: e } } }).then((r) => r.changeUserPassword), st = (t, e, r) => p({ resetPassword: { __args: { jwt: t, password: e, code: r } } }).then((n) => n.resetPassword), nt = (t, e) => p({ forgetPassword: { __args: { username: t, email: e } } }).then((r) => r.forgetPassword), ot = (t, e) => p({ forgetPasswordVerifyCode: { __args: { jwt: t, code: e } } }).then((r) => r.forgetPasswordVerifyCode), it = (t) => y({
500
+ }, Symbol.toStringTag, { value: "Module" })), I = (t = W) => y({ my: t }).then((e) => e.my), x = (t, e, r = "") => p({ login: { __args: { username: t, password: e, code: r } } }).then((n) => n.login), tt = () => p({ logout: !0 }).then((t) => t.logout), et = (t, e, r) => p({ changeExpiredPassword: { __args: { username: t, old_password: e, new_password: r } } }).then((n) => n.changeExpiredPassword), rt = (t, e) => p({ changeUserPassword: { __args: { old_password: t, new_password: e } } }).then((r) => r.changeUserPassword), st = (t, e, r) => p({ resetPassword: { __args: { jwt: t, password: e, code: r } } }).then((n) => n.resetPassword), nt = (t, e) => p({ forgetPassword: { __args: { username: t, email: e } } }).then((r) => r.forgetPassword), ot = (t, e) => p({ forgetPasswordVerifyCode: { __args: { jwt: t, code: e } } }).then((r) => r.forgetPasswordVerifyCode), it = (t) => y({
501
+ my: {
502
+ granted: {
503
+ __args: {
504
+ right: t
505
+ }
506
+ }
507
+ }
508
+ }).then((e) => e.my.granted), at = (t) => y({
501
509
  my: {
502
510
  grantedRights: {
503
511
  __args: {
@@ -505,7 +513,7 @@ const L = (t, e) => {
505
513
  }
506
514
  }
507
515
  }
508
- }).then((e) => e.my.grantedRights), at = () => ({
516
+ }).then((e) => e.my.grantedRights), ct = () => ({
509
517
  getCurrentUser: I,
510
518
  webAuthn: K,
511
519
  google: {
@@ -530,14 +538,15 @@ const L = (t, e) => {
530
538
  resetPassword: st,
531
539
  forgetPassword: nt,
532
540
  verifyCode: ot,
533
- granted: it
541
+ grantedRights: at,
542
+ isGranted: it
534
543
  }), $ = {
535
544
  name: !0,
536
545
  path: !0,
537
546
  size: !0,
538
547
  mime: !0,
539
548
  url: !0
540
- }, ct = (t, e, r = $) => y({
549
+ }, lt = (t, e, r = $) => y({
541
550
  app: {
542
551
  drive: {
543
552
  __args: { index: t },
@@ -547,8 +556,22 @@ const L = (t, e) => {
547
556
  }
548
557
  }
549
558
  }
550
- }).then((n) => n.app.drive.files), m = (t) => ({
551
- list: (e, r = $) => ct(t, e, r),
559
+ }).then((n) => n.app.drive.files), ut = (t, e) => y({
560
+ app: {
561
+ drive: {
562
+ __args: {
563
+ index: t
564
+ },
565
+ file: {
566
+ __args: {
567
+ path: e
568
+ },
569
+ base64Content: !0
570
+ }
571
+ }
572
+ }
573
+ }).then((r) => r.app.drive?.file?.base64Content), m = (t) => ({
574
+ list: (e, r = $) => lt(t, e, r),
552
575
  get: (e, r = {
553
576
  name: !0,
554
577
  path: !0,
@@ -570,6 +593,9 @@ const L = (t, e) => {
570
593
  }
571
594
  }
572
595
  }).then((n) => n.app.drive.file),
596
+ readFileAsBase64(e) {
597
+ return ut(t, e);
598
+ },
573
599
  read: async (e) => {
574
600
  let r = await y({
575
601
  app: {
@@ -594,10 +620,10 @@ const L = (t, e) => {
594
620
  delete: (e) => p({ lightDriveDeleteFile: { __args: { index: t, path: e } } }).then((r) => r.lightDriveDeleteFile),
595
621
  rename: (e, r) => p({ lightDriveRenameFile: { __args: { index: t, path: e, name: r } } }).then((n) => n.lightDriveRenameFile),
596
622
  move: (e, r) => p({ lightDriveMoveFile: { __args: { index: t, source: e, destination: r } } }).then((n) => n.lightDriveMoveFile)
597
- }), W = {
623
+ }), G = {
598
624
  name: !0,
599
625
  path: !0
600
- }, lt = (t, e, r = W) => y({
626
+ }, ht = (t, e, r = G) => y({
601
627
  app: {
602
628
  drive: {
603
629
  __args: { index: t },
@@ -608,18 +634,18 @@ const L = (t, e) => {
608
634
  }
609
635
  }
610
636
  }).then((n) => n.app.drive.folders), D = (t) => ({
611
- list: (e, r = W) => lt(t, e, r),
637
+ list: (e, r = G) => ht(t, e, r),
612
638
  create: (e) => p({ lightDriveCreateFolder: { __args: { index: t, path: e } } }).then((r) => r.lightDriveCreateFolder),
613
639
  delete: (e) => p({ lightDriveDeleteFolder: { __args: { index: t, path: e } } }).then((r) => r.lightDriveDeleteFolder),
614
640
  rename: (e, r) => p({ lightDriveRenameFolder: { __args: { index: t, path: e, name: r } } }).then((n) => n.lightDriveRenameFolder)
615
- }), Jt = () => y({
641
+ }), Qt = () => y({
616
642
  app: {
617
643
  drives: {
618
644
  index: !0,
619
645
  name: !0
620
646
  }
621
647
  }
622
- }).then((t) => t.app.drives), ut = (t) => ({
648
+ }).then((t) => t.app.drives), ft = (t) => ({
623
649
  listFiles: m(t).list,
624
650
  getFile: m(t).get,
625
651
  readFile: m(t).read,
@@ -642,30 +668,30 @@ const L = (t, e) => {
642
668
  }).then((r) => r.lightDriveUploadTempFile),
643
669
  folders: D(t),
644
670
  files: m(t)
645
- }), G = {
671
+ }), W = {
646
672
  user_id: !0,
647
673
  username: !0,
648
674
  first_name: !0,
649
675
  last_name: !0,
650
676
  status: !0
651
- }, ht = (t) => p({
677
+ }, pt = (t) => p({
652
678
  addUser: {
653
679
  __args: t
654
680
  }
655
- }).then((e) => e.addUser), ft = (t) => p({
681
+ }).then((e) => e.addUser), gt = (t) => p({
656
682
  deleteUser: {
657
683
  __args: { id: t }
658
684
  }
659
- }).then((e) => e.deleteUser), pt = (t = G) => U("Users", t).dataPath("app.listUser").fetch(), dt = (t, e) => p({
685
+ }).then((e) => e.deleteUser), dt = (t = W) => C("Users", t).dataPath("app.listUser").fetch(), _t = (t, e) => p({
660
686
  updateUser: {
661
687
  __args: { id: t, data: e }
662
688
  }
663
- }).then((r) => r.updateUser), gt = () => ({
664
- list: pt,
665
- create: ht,
666
- delete: ft,
667
- update: dt
668
- }), _t = (t) => y({
689
+ }).then((r) => r.updateUser), yt = () => ({
690
+ list: dt,
691
+ create: pt,
692
+ delete: gt,
693
+ update: _t
694
+ }), wt = (t) => y({
669
695
  app: {
670
696
  listConfig: {
671
697
  __args: {
@@ -679,13 +705,13 @@ const L = (t, e) => {
679
705
  }
680
706
  }
681
707
  }
682
- }).then((e) => e.app.listConfig.data[0]?.value), yt = {
708
+ }).then((e) => e.app.listConfig.data[0]?.value), bt = {
683
709
  name: !0
684
- }, wt = (t = yt) => y({
710
+ }, mt = (t = bt) => y({
685
711
  app: {
686
712
  roles: t
687
713
  }
688
- }).then((e) => e.app.roles), bt = (t, e) => p({
714
+ }).then((e) => e.app.roles), Ft = (t, e) => p({
689
715
  addRole: {
690
716
  __args: {
691
717
  data: {
@@ -694,14 +720,14 @@ const L = (t, e) => {
694
720
  }
695
721
  }
696
722
  }
697
- }).then((r) => r.addRole), mt = (t) => p({
723
+ }).then((r) => r.addRole), At = (t) => p({
698
724
  deleteRole: {
699
725
  __args: { name: t }
700
726
  }
701
- }).then((e) => e.deleteRole), Ft = () => ({
702
- list: wt,
703
- create: bt,
704
- delete: mt
727
+ }).then((e) => e.deleteRole), Ot = () => ({
728
+ list: mt,
729
+ create: Ft,
730
+ delete: At
705
731
  });
706
732
  function z(t, e, r, n, i) {
707
733
  if (!(!t || typeof t != "object"))
@@ -721,8 +747,8 @@ function z(t, e, r, n, i) {
721
747
  if (h instanceof Array && j(h)) {
722
748
  s[o][l] = new F(l);
723
749
  let _ = 0;
724
- h.forEach((d) => {
725
- d instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + l + "." + _), n.append(i.current.toString(), d), i.current++, _++);
750
+ h.forEach((g) => {
751
+ g instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + l + "." + _), n.append(i.current.toString(), g), i.current++, _++);
726
752
  }), e[l] = "[Upload!]!";
727
753
  } else h instanceof File ? (s[o][l] = new F(l), r[i.current] = ["variables." + l], n.append(i.current.toString(), h), e[l] = "Upload!", i.current++) : s[o][l] = h;
728
754
  })) : c != null && (s[o] = c);
@@ -738,7 +764,7 @@ const p = async (t) => {
738
764
  const a = {}, u = {};
739
765
  z(n, a, u, i, { current: 0 }), f = Object.keys(a).length > 0, f && (n.__variables = a);
740
766
  let o = null;
741
- const l = v({ mutation: n });
767
+ const l = q({ mutation: n });
742
768
  if (f ? (i.append("map", JSON.stringify(u)), i.append("operations", JSON.stringify({
743
769
  query: l
744
770
  })), o = await r.post("", i)) : o = await r.post("", {
@@ -746,12 +772,12 @@ const p = async (t) => {
746
772
  }), o.data.errors)
747
773
  throw new Error(o.data.errors[0].message);
748
774
  return o.data.data;
749
- }, At = (t, e, r) => p({ sendMail: { __args: { email: t, subject: e, message: r } } }).then((n) => n.sendMail), Ot = {
750
- send: At
751
- }, S = (t) => {
775
+ }, Dt = (t, e, r) => p({ sendMail: { __args: { email: t, subject: e, message: r } } }).then((n) => n.sendMail), jt = {
776
+ send: Dt
777
+ }, U = (t) => {
752
778
  let e = {};
753
779
  return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
754
- Object.entries(S(r)).forEach(([n, i]) => {
780
+ Object.entries(U(r)).forEach(([n, i]) => {
755
781
  e[n] = i;
756
782
  });
757
783
  }), e) : (Object.entries(t).forEach(([r, n]) => {
@@ -763,9 +789,9 @@ const p = async (t) => {
763
789
  e[r] = n;
764
790
  return;
765
791
  }
766
- e[r] = S(n);
792
+ e[r] = U(n);
767
793
  }), e);
768
- }, Dt = (t) => S(t), jt = "list", kt = [
794
+ }, kt = (t) => U(t), Ct = "list", Pt = [
769
795
  "flatMap",
770
796
  "chunk",
771
797
  "shuffle",
@@ -791,7 +817,7 @@ const p = async (t) => {
791
817
  "slice",
792
818
  "tap",
793
819
  "sort"
794
- ], Ct = [
820
+ ], Mt = [
795
821
  "avg",
796
822
  "count",
797
823
  "countBy",
@@ -819,7 +845,7 @@ const p = async (t) => {
819
845
  "implode",
820
846
  "partition"
821
847
  ];
822
- class g {
848
+ class d {
823
849
  _batchData = null;
824
850
  data_path = "";
825
851
  filters;
@@ -836,7 +862,7 @@ class g {
836
862
  this.filters = {}, this.steps = [], this.fields = e;
837
863
  }
838
864
  }
839
- g.prototype.getQueryPayload = function() {
865
+ d.prototype.getQueryPayload = function() {
840
866
  let t = {
841
867
  meta: {
842
868
  total: !0,
@@ -850,26 +876,26 @@ g.prototype.getQueryPayload = function() {
850
876
  steps: this.steps
851
877
  };
852
878
  };
853
- g.prototype.dataPath = function(t) {
879
+ d.prototype.dataPath = function(t) {
854
880
  const e = this.clone();
855
881
  return e.data_path = t, e;
856
882
  };
857
- g.prototype.buildArgs = function() {
883
+ d.prototype.buildArgs = function() {
858
884
  let t = {};
859
885
  return Object.keys(this.filters).length > 0 && (t.filters = this.filters), this._sort && (t.sort = this._sort, this._sortDesc && (t.sort += ":desc")), t;
860
886
  };
861
- g.prototype.clone = function() {
887
+ d.prototype.clone = function() {
862
888
  const t = Object.create(this);
863
889
  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;
864
890
  };
865
- M().macro("whereContains", function(t, e) {
891
+ E().macro("whereContains", function(t, e) {
866
892
  return this.filter((r) => r[t].toLowerCase().includes(e.toLowerCase()));
867
893
  });
868
- g.prototype.fetchData = async function() {
894
+ d.prototype.fetchData = async function() {
869
895
  try {
870
896
  if (this._batchData) {
871
897
  const u = this._batchData;
872
- return this.meta = u.meta, M(u.data);
898
+ return this.meta = u.meta, E(u.data);
873
899
  }
874
900
  let t = {
875
901
  meta: {
@@ -891,37 +917,37 @@ g.prototype.fetchData = async function() {
891
917
  let a = await y(r);
892
918
  for (const u of e)
893
919
  a = a[u];
894
- return this.meta = a.meta, M(a.data);
920
+ return this.meta = a.meta, E(a.data);
895
921
  } catch (t) {
896
922
  throw console.error("Error fetching collection data:", t), t;
897
923
  }
898
924
  };
899
- g.prototype.processData = async function() {
925
+ d.prototype.processData = async function() {
900
926
  let t = await this.fetchData();
901
927
  for (const e of this.steps)
902
928
  t = t[e.type](...e.args);
903
929
  return t;
904
930
  };
905
- g.prototype.all = async function() {
931
+ d.prototype.all = async function() {
906
932
  return (await this.processData()).all();
907
933
  };
908
- for (const t of kt)
909
- g.prototype[t] = function(...e) {
934
+ for (const t of Pt)
935
+ d.prototype[t] = function(...e) {
910
936
  const r = this.clone();
911
937
  return r.steps.push({ type: t, args: e }), r;
912
938
  };
913
- for (const t of Ct)
914
- g.prototype[t] = async function(...e) {
939
+ for (const t of Mt)
940
+ d.prototype[t] = async function(...e) {
915
941
  return (await this.clone().processData())[t](...e);
916
942
  };
917
- g.prototype.average = g.prototype.avg;
918
- g.prototype.first = async function() {
943
+ d.prototype.average = d.prototype.avg;
944
+ d.prototype.first = async function() {
919
945
  return this.take(1), (await this.processData()).first();
920
946
  };
921
- g.prototype._handleBatchData = function(t, e) {
947
+ d.prototype._handleBatchData = function(t, e) {
922
948
  return this._batchData ? (this.steps.push({ type: t, args: e }), this) : null;
923
949
  };
924
- g.prototype.where = function(...t) {
950
+ d.prototype.where = function(...t) {
925
951
  const e = this._handleBatchData("where", t);
926
952
  if (e) return e;
927
953
  if (t.length === 2)
@@ -953,55 +979,55 @@ g.prototype.where = function(...t) {
953
979
  }
954
980
  return this;
955
981
  };
956
- g.prototype.whereContains = function(t, e) {
982
+ d.prototype.whereContains = function(t, e) {
957
983
  const r = this._handleBatchData("whereContains", [t, e]);
958
984
  return r || (this.filters[t] = { contains: e }, this);
959
985
  };
960
- g.prototype.forPage = function(t, e) {
986
+ d.prototype.forPage = function(t, e) {
961
987
  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);
962
988
  };
963
- g.prototype.whereIn = function(t, e) {
989
+ d.prototype.whereIn = function(t, e) {
964
990
  const r = this._handleBatchData("whereIn", [t, e]);
965
991
  return r || (this.filters[t] = { in: e }, this);
966
992
  };
967
- g.prototype.whereNotIn = function(t, e) {
993
+ d.prototype.whereNotIn = function(t, e) {
968
994
  const r = this._handleBatchData("whereNotIn", [t, e]);
969
995
  return r || (this.filters[t] = { nin: e }, this);
970
996
  };
971
- g.prototype.whereNotBetween = function(t, e) {
997
+ d.prototype.whereNotBetween = function(t, e) {
972
998
  const r = this._handleBatchData("whereNotBetween", [t, e]);
973
999
  return r || (this.filters[t] = { notBetween: e }, this);
974
1000
  };
975
- g.prototype.whereBetween = function(t, e) {
1001
+ d.prototype.whereBetween = function(t, e) {
976
1002
  const r = this._handleBatchData("whereBetween", [t, e]);
977
1003
  return r || (this.filters[t] = { between: e }, this);
978
1004
  };
979
- g.prototype.sortBy = function(t) {
1005
+ d.prototype.sortBy = function(t) {
980
1006
  return this.steps.push({ type: "sortBy", args: [t] }), typeof t == "string" && (this._sort = t), this;
981
1007
  };
982
- g.prototype.sortByDesc = function(t) {
1008
+ d.prototype.sortByDesc = function(t) {
983
1009
  return this.steps.push({ type: "sortByDesc", args: [t] }), typeof t == "string" && (this._sort = t, this._sortDesc = !0), this;
984
1010
  };
985
- g.prototype.skip = function(t) {
1011
+ d.prototype.skip = function(t) {
986
1012
  if (t < 0)
987
1013
  throw new Error("Offset must be non-negative");
988
1014
  return this.already_offset && this.steps.push({ type: "skip", args: [t] }), this.offset = t, this.already_offset = !0, this;
989
1015
  };
990
- g.prototype.take = function(t) {
1016
+ d.prototype.take = function(t) {
991
1017
  if (t < 0)
992
1018
  throw new Error("Length must be non-negative");
993
1019
  return this.already_limit ? (this.steps.push({ type: "take", args: [t] }), this) : (this.limit = t, this.already_limit = !0, this);
994
1020
  };
995
- g.prototype.splice = function(t, e) {
1021
+ d.prototype.splice = function(t, e) {
996
1022
  return this.steps.push({ type: "splice", args: [t, e] }), this.offset = t, this.limit = e, this.already_limit = !0, this.already_offset = !0, this;
997
1023
  };
998
1024
  const R = (t, e) => {
999
- const r = new g(e);
1000
- return r.data_path = jt + t, r;
1001
- }, Pt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1025
+ const r = new d(e);
1026
+ return r.data_path = Ct + t, r;
1027
+ }, Et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1002
1028
  __proto__: null,
1003
1029
  default: R
1004
- }, Symbol.toStringTag, { value: "Module" })), Lt = (t) => {
1030
+ }, Symbol.toStringTag, { value: "Module" })), Tt = (t) => {
1005
1031
  const e = typeof window > "u";
1006
1032
  let r = [];
1007
1033
  const n = H.create({
@@ -1021,40 +1047,40 @@ const R = (t, e) => {
1021
1047
  }
1022
1048
  return a;
1023
1049
  }));
1024
- const i = q(), f = {
1050
+ const i = v(), f = {
1025
1051
  post: n.post,
1026
1052
  baseURL: t,
1027
1053
  axios: n,
1028
- auth: at(),
1054
+ auth: ct(),
1029
1055
  mutation: p,
1030
1056
  query: y,
1031
- config: _t,
1032
- mail: Ot,
1033
- users: gt(),
1057
+ config: wt,
1058
+ mail: jt,
1059
+ users: yt(),
1034
1060
  models: i,
1035
1061
  model(a) {
1036
1062
  return i.get(a);
1037
1063
  },
1038
- roles: Ft(),
1064
+ roles: Ot(),
1039
1065
  collect: (a, u) => {
1040
1066
  const s = R(a, u);
1041
1067
  return s.data_path = i.get(a).getDataPath(), s;
1042
1068
  },
1043
- list: (a, u) => U(a, u).dataPath(i.get(a).getDataPath()),
1044
- drive: ut,
1069
+ list: (a, u) => C(a, u).dataPath(i.get(a).getDataPath()),
1070
+ drive: ft,
1045
1071
  async collects(a) {
1046
1072
  const u = {}, s = {};
1047
1073
  for (const c in a) {
1048
1074
  const l = a[c].getQueryPayload();
1049
1075
  s[c] = l.data_path, u[c] = {};
1050
1076
  const h = l.data_path.split(".");
1051
- let _ = h[h.length - 1], d = u[c];
1077
+ let _ = h[h.length - 1], g = u[c];
1052
1078
  for (const w of h) {
1053
1079
  if (w === _) {
1054
- d[w] = l.query;
1080
+ g[w] = l.query;
1055
1081
  break;
1056
1082
  }
1057
- d[w] = d[w] || {};
1083
+ g[w] = g[w] || {};
1058
1084
  }
1059
1085
  u[c].__aliasFor = h[0];
1060
1086
  }
@@ -1062,56 +1088,60 @@ const R = (t, e) => {
1062
1088
  for (const c in a) {
1063
1089
  const l = s[c].split(".");
1064
1090
  let h = l[l.length - 1], _ = o[c];
1065
- for (const d of l) {
1066
- if (d === h) {
1067
- a[c]._batchData = o[c][d];
1091
+ for (const g of l) {
1092
+ if (g === h) {
1093
+ a[c]._batchData = o[c][g];
1068
1094
  break;
1069
1095
  }
1070
- _[d] = _[d] || {};
1096
+ _[g] = _[g] || {};
1071
1097
  }
1072
1098
  }
1073
1099
  return a;
1074
1100
  }
1075
1101
  };
1076
1102
  return Y(f), f;
1077
- };
1103
+ }, $t = C;
1078
1104
  export {
1079
- at as auth,
1105
+ ct as auth,
1080
1106
  et as changeExpiredPassword,
1081
- Lt as createClient,
1107
+ Tt as createClient,
1082
1108
  R as createCollection,
1083
- U as createList,
1084
- q as createModelManager,
1085
- bt as createRole,
1086
- ht as createUser,
1087
- G as defaultUserFields,
1088
- mt as deleteRole,
1089
- ft as deleteUser,
1109
+ C as createList,
1110
+ v as createModelManager,
1111
+ Ft as createRole,
1112
+ pt as createUser,
1113
+ W as defaultUserFields,
1114
+ At as deleteRole,
1115
+ gt as deleteUser,
1090
1116
  nt as forgetPassword,
1091
1117
  N as getApiClient,
1092
- Ut as getApiClientOptional,
1093
- _t as getConfig,
1118
+ qt as getApiClientOptional,
1119
+ wt as getConfig,
1094
1120
  I as getCurrentUser,
1095
- ut as getDrive,
1096
- it as granted,
1097
- Jt as listDrives,
1098
- ct as listFiles,
1099
- Bt as listPermissions,
1100
- wt as listRoles,
1101
- pt as listUsers,
1121
+ ft as getDrive,
1122
+ at as getGrantedRights,
1123
+ it as isGranted,
1124
+ $t as list,
1125
+ Qt as listDrives,
1126
+ lt as listFiles,
1127
+ ht as listFolders,
1128
+ Lt as listPermissions,
1129
+ mt as listRoles,
1130
+ dt as listUsers,
1102
1131
  x as login,
1103
1132
  tt as logout,
1104
1133
  p as mutation,
1105
1134
  y as query,
1135
+ ut as readFileAsBase64,
1106
1136
  st as resetPassword,
1107
- At as sendMail,
1137
+ Dt as sendMail,
1108
1138
  Y as setApiClient,
1109
- Dt as toQuery,
1139
+ kt as toQuery,
1110
1140
  rt as updatePassword,
1111
- dt as updateUser,
1112
- vt as useGlobalModel,
1113
- Nt as useGlobalModels,
1114
- qt as useModel,
1141
+ _t as updateUser,
1142
+ Bt as useGlobalModel,
1143
+ Jt as useGlobalModels,
1144
+ Nt as useModel,
1115
1145
  ot as verifyCode,
1116
1146
  K as webAuthn
1117
1147
  };
@@ -1 +1 @@
1
- (function(h,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):(h=typeof globalThis<"u"?globalThis:h||self,m(h.light={},h.jsonToGraphqlQuery,h.axios,h.collect))})(this,(function(h,m,_t,U){"use strict";function E(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 S(t,e,r=".",n){if(!E(e))return S(t,{},r,n);const o=Object.assign({},e);for(const p in t){if(p==="__proto__"||p==="constructor")continue;const a=t[p];a!=null&&(n&&n(o,p,a,r)||(Array.isArray(a)&&Array.isArray(o[p])?o[p]=[...a,...o[p]]:E(a)&&E(o[p])?o[p]=S(a,o[p],(r?`${r}.`:"")+p.toString(),n):o[p]=a))}return o}function yt(t){return(...e)=>e.reduce((r,n)=>S(r,n,"",t),{})}const A=yt();let j=null;const L=t=>{j=t},v=()=>{if(!j)throw new Error("Api client not initialized. Call setApiClient() first.");return j},wt=()=>j;function C(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function T(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&C(t[e]))return!0;return!1}function $(t,e,r,n,o){if(!(!t||typeof t!="object"))for(let p in t){const a=t[p];if(a&&typeof a=="object"){if("__args"in a){const u=a.__args,s={};Object.entries(u).forEach(([i,c])=>{if(c instanceof Array&&C(c)){s[i]=new m.VariableType(i);let l=0;c.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),n.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else c instanceof File?(s[i]=new m.VariableType(i),r[o.current]=["variables."+i],n.append(o.current.toString(),c),e[i]="Upload!",o.current++):c instanceof Object&&T(c)?(s[i]={},Object.entries(c).forEach(([l,f])=>{if(f instanceof Array&&C(f)){s[i][l]=new m.VariableType(l);let y=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+y),n.append(o.current.toString(),_),o.current++,y++)}),e[l]="[Upload!]!"}else f instanceof File?(s[i][l]=new m.VariableType(l),r[o.current]=["variables."+l],n.append(o.current.toString(),f),e[l]="Upload!",o.current++):s[i][l]=f})):c!=null&&(s[i]=c)}),a.__args=s}$(a,e,r,n,o)}}}const w=async t=>{const e=v(),r=t,n=new FormData;let o=!1;const p={},a={};$(r,p,a,n,{current:0}),o=Object.keys(p).length>0,o&&(r.__variables=p);let s=null;const i={query:r},c=m.jsonToGraphQLQuery(i);if(o?(n.append("map",JSON.stringify(a)),n.append("operations",JSON.stringify({query:c})),s=await e.axios.post("",n)):s=await e.axios.post("",{query:c}),s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function M(t,e){let r,n=[],o,p;const a=s=>!s||typeof s!="object"?!1:Object.values(s).some(i=>i&&typeof i=="object"&&Object.keys(i).some(c=>c.startsWith("_"))),u=()=>n.length===0?(n.unshift({}),n[0]):(a(n[0])&&n.unshift({}),n[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const i=await this.limit(1).fetch();return Array.isArray(i)&&i.length>0?i[0]:null},async fetchWithMeta(){let i=await w(this.toQuery(!0));if(p){const c=p.split(".");for(const l of c)i=i[l];return i}return i[`list${t}`]},async fetch(){let i=await w(this.toQuery());if(p){const c=p.split(".");for(const l of c)i=i[l];return i.data}return i[`list${t}`].data},dataPath(s){return s&&typeof s=="string"&&(p=s),this},sort(s){return s&&typeof s=="string"&&(o=s),this},filters(s){return s&&typeof s=="object"&&(n=[s]),this},where(s,i,c){const l=(f,y,_)=>{const D={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[y];D&&n.push({[f]:{[D]:_}})};if(c!==void 0)l(s,String(i),c);else{const f=u(),y=A(f,{[s]:i});n[0]=y}return this},whereContains(s,i){if(s&&typeof s=="string"){const c=u(),l={_contains:i};c[s]?Array.isArray(c[s])?c[s].push(l):c[s]=[c[s],l]:c[s]=[l],n[0]=c}return this},whereIn(s,i){if(s&&typeof s=="string"&&Array.isArray(i)){const c=u(),l={_in:i};c[s]?Array.isArray(c[s])?c[s].push(l):c[s]=[c[s],l]:c[s]=[l],n[0]=c}return this},whereBetween(s,i,c){if(s&&typeof s=="string"){const l=u(),f={_between:[i,c]};l[s]?Array.isArray(l[s])?l[s].push(f):l[s]=[l[s],f]:l[s]=f,n[0]=l}return this},limit(s){return typeof s=="number"&&Number.isFinite(s)&&(r=A(r||{},{limit:s})),this},offset(s){return typeof s=="number"&&Number.isFinite(s)&&(r=A(r||{},{offset:s})),this},toQuery(s=!1){let i;const c=n.length>0&&Object.keys(n[0]||{}).length>0,l=c?1:0,f=n.length>l;c&&f?i=n:f?i=n.slice(l):c&&(i=n[0]);const y=A(o?{sort:o}:{},i?{filters:i}:{}),_={data:{...e}};if(r&&(_.data.__args=r),Object.keys(y).length>0&&(_.__args=y),s&&(_.meta={total:!0,key:!0,name:!0}),p){const b=p.split(".");let D=_;for(let J=b.length-1;J>=0;J--)D={[b[J]]:D};return D}return{[`list${t}`]:_}}}}const W=(t,e)=>{const r=t,n=e;let o="list"+t;const p=a=>n[a]?n[a]:null;return{field:p,$fields:n,setDataPath(a){return o=a,o},getDataPath(){return o},gqlFields(a){let u={};for(const s of a)if(typeof s=="string"){const i=p(s);i&&(u=A(u,i.gqlField?typeof i.gqlField=="string"?{[i.gqlField]:!0}:i.gqlField:{[i.name||s]:!0}))}else typeof s=="object"&&(u=A(u,s));return u},update(a,u){return d({["update"+r]:{__args:{id:a,data:u}}}).then(s=>s["update"+r])},async delete(a){return d({["delete"+r]:{__args:{id:a}}}).then(u=>u["delete"+r])},add(a){return d({["add"+r]:{__args:{data:a}}}).then(u=>u["add"+r])},fields(a){let u=[];for(let s of a){const i=p(s);i&&u.push(i)}return u},async get(a,u){const s=(await Promise.resolve().then(()=>St)).default,i=s(r,gt(u));for(const[c,l]of Object.entries(a))i.where(c,"==",l);return await i.first()},list(a){let u=a;const s={};Object.entries(a).forEach(([l])=>{n[l]&&(s[l]=n[l],n[l].gqlField&&(delete u[l],u=A(u,n[l].gqlField)),n[l].gql&&(u=A(u,n[l].gql),delete u[l]))});const i=M(r,u).dataPath(o),c=i.fetch.bind(i);return{...i,async fetch(){return(await c()).map(f=>{const y={...f};return Object.entries(s).forEach(([_,b])=>{b.format&&typeof b.format=="function"&&(y[_]=b.format(f))}),y})},async fetchFirst(){const f=await i.fetchFirst.bind(i)();if(!f)return f;const y={...f};return Object.entries(s).forEach(([_,b])=>{b.format&&typeof b.format=="function"&&(y[_]=b.format(f))}),y}}}}},F={},k=(t=!1)=>{const e={};return{create(r,n){const o=W(r,n);e[r]=o,t&&(F[r]=o)},get(r){return e[r]||(t&&F[r]?e[r]=F[r]:this.create(r,{})),e[r]},has(r){return!!e[r]||t&&!!F[r]},list(){const r=Object.keys(e),n=t?Object.keys(F):[];return[...new Set([...r,...n])]},clear(){Object.keys(e).forEach(r=>delete e[r])}}},bt=()=>{const t=k(!1);return{manager:t,createModel:t.create,getModel:t.get,hasModel:t.has,listModels:t.list,clearModels:t.clear,defineModel(e,r){return t.create(e,r),t.get(e)},defineModels(e){Object.entries(e).forEach(([r,n])=>{t.create(r,n)})}}},mt=()=>{const t=k(!0);return{manager:t,createModel:t.create,getModel:t.get,hasModel:t.has,listModels:t.list,clearModels:t.clear,defineModel(e,r){return t.create(e,r),t.get(e)},defineModels(e){Object.entries(e).forEach(([r,n])=>{t.create(r,n)})}}},Ft=()=>({define(t,e){const r=W(t,e);return F[t]=r,r},get(t){return F[t]},has(t){return!!F[t]},list(){return Object.keys(F)},clear(){Object.keys(F).forEach(t=>delete F[t])}}),At=()=>w({app:{permissions:!0}}).then(t=>t.app.permissions),z=async()=>{const{app:t}=await w({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},Q=async()=>{const{app:t}=await w({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},R=Object.freeze(Object.defineProperty({__proto__:null,assertion:z,attestation:Q,login:async()=>{const t=await z();return await d({webAuthnAssertion:{assertion:t.toJSON()}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await Q();return await d({webAuthnRegister:{registration:t.toJSON()}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),G=(t=q)=>w({my:t}).then(e=>e.my),H=(t,e,r="")=>d({login:{__args:{username:t,password:e,code:r}}}).then(n=>n.login),V=()=>d({logout:!0}).then(t=>t.logout),X=(t,e,r)=>d({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(n=>n.changeExpiredPassword),Y=(t,e)=>d({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),Z=(t,e,r)=>d({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(n=>n.resetPassword),K=(t,e)=>d({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),I=(t,e)=>d({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),x=t=>w({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),tt=()=>({getCurrentUser:G,webAuthn:R,google:{unlink:()=>d({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>d({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>d({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>d({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>d({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>d({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>d({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>d({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>d({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:H,logout:V,changeExpiredPassword:X,updatePassword:Y,resetPassword:Z,forgetPassword:K,verifyCode:I,granted:x}),et={name:!0,path:!0,size:!0,mime:!0,url:!0},rt=(t,e,r=et)=>w({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(n=>n.app.drive.files),O=t=>({list:(e,r=et)=>rt(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(n=>n.app.drive.file),read:async e=>{let r=await w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>d({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(n=>n.lightDriveWriteFile),delete:e=>d({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>d({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFile),move:(e,r)=>d({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(n=>n.lightDriveMoveFile)}),st={name:!0,path:!0},Ot=(t,e,r=st)=>w({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(n=>n.app.drive.folders),P=t=>({list:(e,r=st)=>Ot(t,e,r),create:e=>d({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>d({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>d({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFolder)}),Dt=()=>w({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),nt=t=>({listFiles:O(t).list,getFile:O(t).get,readFile:O(t).read,writeFile:O(t).write,deleteFile:O(t).delete,renameFile:O(t).rename,moveFile:O(t).move,listFolders:P(t).list,createFolder:P(t).create,deleteFolder:P(t).delete,renameFolder:P(t).rename,uploadTempFile:e=>d({lightDriveUploadTempFile:{__args:{index:t,file:e},name:!0,path:!0,size:!0,mime:!0}}).then(r=>r.lightDriveUploadTempFile),folders:P(t),files:O(t)}),q={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},it=t=>d({addUser:{__args:t}}).then(e=>e.addUser),ot=t=>d({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),at=(t=q)=>M("Users",t).dataPath("app.listUser").fetch(),ct=(t,e)=>d({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Ct=()=>({list:at,create:it,delete:ot,update:ct}),lt=t=>w({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Pt={name:!0},ut=(t=Pt)=>w({app:{roles:t}}).then(e=>e.app.roles),ht=(t,e)=>d({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),ft=t=>d({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),jt=()=>({list:ut,create:ht,delete:ft});function pt(t,e,r,n,o){if(!(!t||typeof t!="object"))for(let p in t){const a=t[p];if(a&&typeof a=="object"){if("__args"in a){const u=a.__args,s={};Object.entries(u).forEach(([i,c])=>{if(c instanceof Array&&C(c)){s[i]=new m.VariableType(i);let l=0;c.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),n.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else c instanceof File?(s[i]=new m.VariableType(i),r[o.current]=["variables."+i],n.append(o.current.toString(),c),e[i]="Upload!",o.current++):c instanceof Object&&T(c)?(s[i]={},Object.entries(c).forEach(([l,f])=>{if(f instanceof Array&&C(f)){s[i][l]=new m.VariableType(l);let y=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+y),n.append(o.current.toString(),_),o.current++,y++)}),e[l]="[Upload!]!"}else f instanceof File?(s[i][l]=new m.VariableType(l),r[o.current]=["variables."+l],n.append(o.current.toString(),f),e[l]="Upload!",o.current++):s[i][l]=f})):c!=null&&(s[i]=c)}),a.__args=s}pt(a,e,r,n,o)}}}const d=async t=>{const r=v().axios,n=t,o=new FormData;let p=!1;const a={},u={};pt(n,a,u,o,{current:0}),p=Object.keys(a).length>0,p&&(n.__variables=a);let i=null;const c={mutation:n},l=m.jsonToGraphQLQuery(c);if(p?(o.append("map",JSON.stringify(u)),o.append("operations",JSON.stringify({query:l})),i=await r.post("",o)):i=await r.post("",{query:l}),i.data.errors)throw new Error(i.data.errors[0].message);return i.data.data},dt=(t,e,r)=>d({sendMail:{__args:{email:t,subject:e,message:r}}}).then(n=>n.sendMail),Mt={send:dt},N=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(N(r)).forEach(([n,o])=>{e[n]=o})}),e):(Object.entries(t).forEach(([r,n])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=n;return}if(typeof n=="boolean"){e[r]=n;return}e[r]=N(n)}),e)},gt=t=>N(t),kt="list",Ut=["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"],Et=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition"];class g{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}g.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},g.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},g.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},g.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},U().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 u=this._batchData;return this.meta=u.meta,U(u.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},n=r,o=e[e.length-1];for(const u of e){if(u===o){n[u]=t;break}n[u]={},n=n[u]}let a=await w(r);for(const u of e)a=a[u];return this.meta=a.meta,U(a.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 Ut)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of Et)g.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};g.prototype.average=g.prototype.avg,g.prototype.first=async function(){return this.take(1),(await this.processData()).first()},g.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},g.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],n=t[1],o=t[2];switch(n){case"==":this.filters[r]=o;break;case"<":this.filters[r]={lt:o};break;case"<=":this.filters[r]={lte:o};break;case">":this.filters[r]={gt:o};break;case">=":this.filters[r]={gte:o};break;case"!==":this.filters[r]={ne:o};break;default:throw new Error(`Unsupported operator: ${n}`)}}return this},g.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},g.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},g.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},g.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},g.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},g.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},g.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},g.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},g.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},g.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},g.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const B=(t,e)=>{const r=new g(e);return r.data_path=kt+t,r},St=Object.freeze(Object.defineProperty({__proto__:null,default:B},Symbol.toStringTag,{value:"Module"})),vt=t=>{const e=typeof window>"u";let r=[];const n=_t.create({baseURL:t,withCredentials:!0});e&&(n.interceptors.request.use(a=>(a.withCredentials=!0,r.length>0&&(a.headers.Cookie=r.join("; ")),a)),n.interceptors.response.use(a=>{if(a.headers["set-cookie"]){const u=a.headers["set-cookie"].map(i=>i.split(";")[0]),s=new Map;r.forEach(i=>{const c=i.split("=")[0];s.set(c,i)}),u.forEach(i=>{const c=i.split("=")[0];s.set(c,i)}),r=Array.from(s.values())}return a}));const o=k(),p={post:n.post,baseURL:t,axios:n,auth:tt(),mutation:d,query:w,config:lt,mail:Mt,users:Ct(),models:o,model(a){return o.get(a)},roles:jt(),collect:(a,u)=>{const s=B(a,u);return s.data_path=o.get(a).getDataPath(),s},list:(a,u)=>M(a,u).dataPath(o.get(a).getDataPath()),drive:nt,async collects(a){const u={},s={};for(const c in a){const l=a[c].getQueryPayload();s[c]=l.data_path,u[c]={};const f=l.data_path.split(".");let y=f[f.length-1],_=u[c];for(const b of f){if(b===y){_[b]=l.query;break}_[b]=_[b]||{}}u[c].__aliasFor=f[0]}const i=await w(u);for(const c in a){const l=s[c].split(".");let f=l[l.length-1],y=i[c];for(const _ of l){if(_===f){a[c]._batchData=i[c][_];break}y[_]=y[_]||{}}}return a}};return L(p),p};h.auth=tt,h.changeExpiredPassword=X,h.createClient=vt,h.createCollection=B,h.createList=M,h.createModelManager=k,h.createRole=ht,h.createUser=it,h.defaultUserFields=q,h.deleteRole=ft,h.deleteUser=ot,h.forgetPassword=K,h.getApiClient=v,h.getApiClientOptional=wt,h.getConfig=lt,h.getCurrentUser=G,h.getDrive=nt,h.granted=x,h.listDrives=Dt,h.listFiles=rt,h.listPermissions=At,h.listRoles=ut,h.listUsers=at,h.login=H,h.logout=V,h.mutation=d,h.query=w,h.resetPassword=Z,h.sendMail=dt,h.setApiClient=L,h.toQuery=gt,h.updatePassword=Y,h.updateUser=ct,h.useGlobalModel=mt,h.useGlobalModels=Ft,h.useModel=bt,h.verifyCode=I,h.webAuthn=R,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(h,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],m):(h=typeof globalThis<"u"?globalThis:h||self,m(h.light={},h.jsonToGraphqlQuery,h.axios,h.collect))})(this,(function(h,m,bt,U){"use strict";function E(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 S(t,e,r=".",n){if(!E(e))return S(t,{},r,n);const o=Object.assign({},e);for(const p in t){if(p==="__proto__"||p==="constructor")continue;const a=t[p];a!=null&&(n&&n(o,p,a,r)||(Array.isArray(a)&&Array.isArray(o[p])?o[p]=[...a,...o[p]]:E(a)&&E(o[p])?o[p]=S(a,o[p],(r?`${r}.`:"")+p.toString(),n):o[p]=a))}return o}function mt(t){return(...e)=>e.reduce((r,n)=>S(r,n,"",t),{})}const A=mt();let M=null;const L=t=>{M=t},v=()=>{if(!M)throw new Error("Api client not initialized. Call setApiClient() first.");return M},Ft=()=>M;function C(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function T(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&C(t[e]))return!0;return!1}function $(t,e,r,n,o){if(!(!t||typeof t!="object"))for(let p in t){const a=t[p];if(a&&typeof a=="object"){if("__args"in a){const u=a.__args,s={};Object.entries(u).forEach(([i,c])=>{if(c instanceof Array&&C(c)){s[i]=new m.VariableType(i);let l=0;c.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),n.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else c instanceof File?(s[i]=new m.VariableType(i),r[o.current]=["variables."+i],n.append(o.current.toString(),c),e[i]="Upload!",o.current++):c instanceof Object&&T(c)?(s[i]={},Object.entries(c).forEach(([l,f])=>{if(f instanceof Array&&C(f)){s[i][l]=new m.VariableType(l);let y=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+y),n.append(o.current.toString(),_),o.current++,y++)}),e[l]="[Upload!]!"}else f instanceof File?(s[i][l]=new m.VariableType(l),r[o.current]=["variables."+l],n.append(o.current.toString(),f),e[l]="Upload!",o.current++):s[i][l]=f})):c!=null&&(s[i]=c)}),a.__args=s}$(a,e,r,n,o)}}}const w=async t=>{const e=v(),r=t,n=new FormData;let o=!1;const p={},a={};$(r,p,a,n,{current:0}),o=Object.keys(p).length>0,o&&(r.__variables=p);let s=null;const i={query:r},c=m.jsonToGraphQLQuery(i);if(o?(n.append("map",JSON.stringify(a)),n.append("operations",JSON.stringify({query:c})),s=await e.axios.post("",n)):s=await e.axios.post("",{query:c}),s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function P(t,e){let r,n=[],o,p;const a=s=>!s||typeof s!="object"?!1:Object.values(s).some(i=>i&&typeof i=="object"&&Object.keys(i).some(c=>c.startsWith("_"))),u=()=>n.length===0?(n.unshift({}),n[0]):(a(n[0])&&n.unshift({}),n[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const i=await this.limit(1).fetch();return Array.isArray(i)&&i.length>0?i[0]:null},async fetchWithMeta(){let i=await w(this.toQuery(!0));if(p){const c=p.split(".");for(const l of c)i=i[l];return i}return i[`list${t}`]},async fetch(){let i=await w(this.toQuery());if(p){const c=p.split(".");for(const l of c)i=i[l];return i.data}return i[`list${t}`].data},dataPath(s){return s&&typeof s=="string"&&(p=s),this},sort(s){return s&&typeof s=="string"&&(o=s),this},filters(s){return s&&typeof s=="object"&&(n=[s]),this},where(s,i,c){const l=(f,y,_)=>{const D={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[y];D&&n.push({[f]:{[D]:_}})};if(c!==void 0)l(s,String(i),c);else{const f=u(),y=A(f,{[s]:i});n[0]=y}return this},whereContains(s,i){if(s&&typeof s=="string"){const c=u(),l={_contains:i};c[s]?Array.isArray(c[s])?c[s].push(l):c[s]=[c[s],l]:c[s]=[l],n[0]=c}return this},whereIn(s,i){if(s&&typeof s=="string"&&Array.isArray(i)){const c=u(),l={_in:i};c[s]?Array.isArray(c[s])?c[s].push(l):c[s]=[c[s],l]:c[s]=[l],n[0]=c}return this},whereBetween(s,i,c){if(s&&typeof s=="string"){const l=u(),f={_between:[i,c]};l[s]?Array.isArray(l[s])?l[s].push(f):l[s]=[l[s],f]:l[s]=f,n[0]=l}return this},limit(s){return typeof s=="number"&&Number.isFinite(s)&&(r=A(r||{},{limit:s})),this},offset(s){return typeof s=="number"&&Number.isFinite(s)&&(r=A(r||{},{offset:s})),this},toQuery(s=!1){let i;const c=n.length>0&&Object.keys(n[0]||{}).length>0,l=c?1:0,f=n.length>l;c&&f?i=n:f?i=n.slice(l):c&&(i=n[0]);const y=A(o?{sort:o}:{},i?{filters:i}:{}),_={data:{...e}};if(r&&(_.data.__args=r),Object.keys(y).length>0&&(_.__args=y),s&&(_.meta={total:!0,key:!0,name:!0}),p){const b=p.split(".");let D=_;for(let J=b.length-1;J>=0;J--)D={[b[J]]:D};return D}return{[`list${t}`]:_}}}}const R=(t,e)=>{const r=t,n=e;let o="list"+t;const p=a=>n[a]?n[a]:null;return{field:p,$fields:n,setDataPath(a){return o=a,o},getDataPath(){return o},gqlFields(a){let u={};for(const s of a)if(typeof s=="string"){const i=p(s);i&&(u=A(u,i.gqlField?typeof i.gqlField=="string"?{[i.gqlField]:!0}:i.gqlField:{[i.name||s]:!0}))}else typeof s=="object"&&(u=A(u,s));return u},update(a,u){return d({["update"+r]:{__args:{id:a,data:u}}}).then(s=>s["update"+r])},async delete(a){return d({["delete"+r]:{__args:{id:a}}}).then(u=>u["delete"+r])},add(a){return d({["add"+r]:{__args:{data:a}}}).then(u=>u["add"+r])},fields(a){let u=[];for(let s of a){const i=p(s);i&&u.push(i)}return u},async get(a,u){const s=(await Promise.resolve().then(()=>qt)).default,i=s(r,wt(u));for(const[c,l]of Object.entries(a))i.where(c,"==",l);return await i.first()},list(a){let u=a;const s={};Object.entries(a).forEach(([l])=>{n[l]&&(s[l]=n[l],n[l].gqlField&&(delete u[l],u=A(u,n[l].gqlField)),n[l].gql&&(u=A(u,n[l].gql),delete u[l]))});const i=P(r,u).dataPath(o),c=i.fetch.bind(i);return{...i,async fetch(){return(await c()).map(f=>{const y={...f};return Object.entries(s).forEach(([_,b])=>{b.format&&typeof b.format=="function"&&(y[_]=b.format(f))}),y})},async fetchFirst(){const f=await i.fetchFirst.bind(i)();if(!f)return f;const y={...f};return Object.entries(s).forEach(([_,b])=>{b.format&&typeof b.format=="function"&&(y[_]=b.format(f))}),y}}}}},F={},k=(t=!1)=>{const e={};return{create(r,n){const o=R(r,n);e[r]=o,t&&(F[r]=o)},get(r){return e[r]||(t&&F[r]?e[r]=F[r]:this.create(r,{})),e[r]},has(r){return!!e[r]||t&&!!F[r]},list(){const r=Object.keys(e),n=t?Object.keys(F):[];return[...new Set([...r,...n])]},clear(){Object.keys(e).forEach(r=>delete e[r])}}},At=()=>{const t=k(!1);return{manager:t,createModel:t.create,getModel:t.get,hasModel:t.has,listModels:t.list,clearModels:t.clear,defineModel(e,r){return t.create(e,r),t.get(e)},defineModels(e){Object.entries(e).forEach(([r,n])=>{t.create(r,n)})}}},Ot=()=>{const t=k(!0);return{manager:t,createModel:t.create,getModel:t.get,hasModel:t.has,listModels:t.list,clearModels:t.clear,defineModel(e,r){return t.create(e,r),t.get(e)},defineModels(e){Object.entries(e).forEach(([r,n])=>{t.create(r,n)})}}},Dt=()=>({define(t,e){const r=R(t,e);return F[t]=r,r},get(t){return F[t]},has(t){return!!F[t]},list(){return Object.keys(F)},clear(){Object.keys(F).forEach(t=>delete F[t])}}),Ct=()=>w({app:{permissions:!0}}).then(t=>t.app.permissions),W=async()=>{const{app:t}=await w({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},z=async()=>{const{app:t}=await w({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},G=Object.freeze(Object.defineProperty({__proto__:null,assertion:W,attestation:z,login:async()=>{const t=await W();return await d({webAuthnAssertion:{assertion:t.toJSON()}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await z();return await d({webAuthnRegister:{registration:t.toJSON()}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),Q=(t=q)=>w({my:t}).then(e=>e.my),H=(t,e,r="")=>d({login:{__args:{username:t,password:e,code:r}}}).then(n=>n.login),V=()=>d({logout:!0}).then(t=>t.logout),X=(t,e,r)=>d({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(n=>n.changeExpiredPassword),Y=(t,e)=>d({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),Z=(t,e,r)=>d({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(n=>n.resetPassword),K=(t,e)=>d({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),I=(t,e)=>d({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),x=t=>w({my:{granted:{__args:{right:t}}}}).then(e=>e.my.granted),tt=t=>w({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),et=()=>({getCurrentUser:Q,webAuthn:G,google:{unlink:()=>d({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>d({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>d({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>d({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>d({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>d({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>d({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>d({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>d({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:H,logout:V,changeExpiredPassword:X,updatePassword:Y,resetPassword:Z,forgetPassword:K,verifyCode:I,grantedRights:tt,isGranted:x}),rt={name:!0,path:!0,size:!0,mime:!0,url:!0},st=(t,e,r=rt)=>w({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(n=>n.app.drive.files),nt=(t,e)=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}}).then(r=>r.app.drive?.file?.base64Content),O=t=>({list:(e,r=rt)=>st(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(n=>n.app.drive.file),readFileAsBase64(e){return nt(t,e)},read:async e=>{let r=await w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>d({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(n=>n.lightDriveWriteFile),delete:e=>d({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>d({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFile),move:(e,r)=>d({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(n=>n.lightDriveMoveFile)}),it={name:!0,path:!0},ot=(t,e,r=it)=>w({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(n=>n.app.drive.folders),j=t=>({list:(e,r=it)=>ot(t,e,r),create:e=>d({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>d({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>d({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(n=>n.lightDriveRenameFolder)}),Pt=()=>w({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),at=t=>({listFiles:O(t).list,getFile:O(t).get,readFile:O(t).read,writeFile:O(t).write,deleteFile:O(t).delete,renameFile:O(t).rename,moveFile:O(t).move,listFolders:j(t).list,createFolder:j(t).create,deleteFolder:j(t).delete,renameFolder:j(t).rename,uploadTempFile:e=>d({lightDriveUploadTempFile:{__args:{index:t,file:e},name:!0,path:!0,size:!0,mime:!0}}).then(r=>r.lightDriveUploadTempFile),folders:j(t),files:O(t)}),q={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},ct=t=>d({addUser:{__args:t}}).then(e=>e.addUser),lt=t=>d({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),ut=(t=q)=>P("Users",t).dataPath("app.listUser").fetch(),ht=(t,e)=>d({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),jt=()=>({list:ut,create:ct,delete:lt,update:ht}),ft=t=>w({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Mt={name:!0},pt=(t=Mt)=>w({app:{roles:t}}).then(e=>e.app.roles),dt=(t,e)=>d({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),gt=t=>d({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),kt=()=>({list:pt,create:dt,delete:gt});function _t(t,e,r,n,o){if(!(!t||typeof t!="object"))for(let p in t){const a=t[p];if(a&&typeof a=="object"){if("__args"in a){const u=a.__args,s={};Object.entries(u).forEach(([i,c])=>{if(c instanceof Array&&C(c)){s[i]=new m.VariableType(i);let l=0;c.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+l),n.append(o.current.toString(),f),o.current++,l++)}),e[i]="[Upload!]!"}else c instanceof File?(s[i]=new m.VariableType(i),r[o.current]=["variables."+i],n.append(o.current.toString(),c),e[i]="Upload!",o.current++):c instanceof Object&&T(c)?(s[i]={},Object.entries(c).forEach(([l,f])=>{if(f instanceof Array&&C(f)){s[i][l]=new m.VariableType(l);let y=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+l+"."+y),n.append(o.current.toString(),_),o.current++,y++)}),e[l]="[Upload!]!"}else f instanceof File?(s[i][l]=new m.VariableType(l),r[o.current]=["variables."+l],n.append(o.current.toString(),f),e[l]="Upload!",o.current++):s[i][l]=f})):c!=null&&(s[i]=c)}),a.__args=s}_t(a,e,r,n,o)}}}const d=async t=>{const r=v().axios,n=t,o=new FormData;let p=!1;const a={},u={};_t(n,a,u,o,{current:0}),p=Object.keys(a).length>0,p&&(n.__variables=a);let i=null;const c={mutation:n},l=m.jsonToGraphQLQuery(c);if(p?(o.append("map",JSON.stringify(u)),o.append("operations",JSON.stringify({query:l})),i=await r.post("",o)):i=await r.post("",{query:l}),i.data.errors)throw new Error(i.data.errors[0].message);return i.data.data},yt=(t,e,r)=>d({sendMail:{__args:{email:t,subject:e,message:r}}}).then(n=>n.sendMail),Ut={send:yt},N=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(N(r)).forEach(([n,o])=>{e[n]=o})}),e):(Object.entries(t).forEach(([r,n])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=n;return}if(typeof n=="boolean"){e[r]=n;return}e[r]=N(n)}),e)},wt=t=>N(t),Et="list",St=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],vt=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition"];class g{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}g.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},g.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},g.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},g.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},U().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 u=this._batchData;return this.meta=u.meta,U(u.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},n=r,o=e[e.length-1];for(const u of e){if(u===o){n[u]=t;break}n[u]={},n=n[u]}let a=await w(r);for(const u of e)a=a[u];return this.meta=a.meta,U(a.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 St)g.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of vt)g.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};g.prototype.average=g.prototype.avg,g.prototype.first=async function(){return this.take(1),(await this.processData()).first()},g.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},g.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],n=t[1],o=t[2];switch(n){case"==":this.filters[r]=o;break;case"<":this.filters[r]={lt:o};break;case"<=":this.filters[r]={lte:o};break;case">":this.filters[r]={gt:o};break;case">=":this.filters[r]={gte:o};break;case"!==":this.filters[r]={ne:o};break;default:throw new Error(`Unsupported operator: ${n}`)}}return this},g.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},g.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},g.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},g.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},g.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},g.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},g.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},g.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},g.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},g.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},g.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const B=(t,e)=>{const r=new g(e);return r.data_path=Et+t,r},qt=Object.freeze(Object.defineProperty({__proto__:null,default:B},Symbol.toStringTag,{value:"Module"})),Nt=t=>{const e=typeof window>"u";let r=[];const n=bt.create({baseURL:t,withCredentials:!0});e&&(n.interceptors.request.use(a=>(a.withCredentials=!0,r.length>0&&(a.headers.Cookie=r.join("; ")),a)),n.interceptors.response.use(a=>{if(a.headers["set-cookie"]){const u=a.headers["set-cookie"].map(i=>i.split(";")[0]),s=new Map;r.forEach(i=>{const c=i.split("=")[0];s.set(c,i)}),u.forEach(i=>{const c=i.split("=")[0];s.set(c,i)}),r=Array.from(s.values())}return a}));const o=k(),p={post:n.post,baseURL:t,axios:n,auth:et(),mutation:d,query:w,config:ft,mail:Ut,users:jt(),models:o,model(a){return o.get(a)},roles:kt(),collect:(a,u)=>{const s=B(a,u);return s.data_path=o.get(a).getDataPath(),s},list:(a,u)=>P(a,u).dataPath(o.get(a).getDataPath()),drive:at,async collects(a){const u={},s={};for(const c in a){const l=a[c].getQueryPayload();s[c]=l.data_path,u[c]={};const f=l.data_path.split(".");let y=f[f.length-1],_=u[c];for(const b of f){if(b===y){_[b]=l.query;break}_[b]=_[b]||{}}u[c].__aliasFor=f[0]}const i=await w(u);for(const c in a){const l=s[c].split(".");let f=l[l.length-1],y=i[c];for(const _ of l){if(_===f){a[c]._batchData=i[c][_];break}y[_]=y[_]||{}}}return a}};return L(p),p},Bt=P;h.auth=et,h.changeExpiredPassword=X,h.createClient=Nt,h.createCollection=B,h.createList=P,h.createModelManager=k,h.createRole=dt,h.createUser=ct,h.defaultUserFields=q,h.deleteRole=gt,h.deleteUser=lt,h.forgetPassword=K,h.getApiClient=v,h.getApiClientOptional=Ft,h.getConfig=ft,h.getCurrentUser=Q,h.getDrive=at,h.getGrantedRights=tt,h.isGranted=x,h.list=Bt,h.listDrives=Pt,h.listFiles=st,h.listFolders=ot,h.listPermissions=Ct,h.listRoles=pt,h.listUsers=ut,h.login=H,h.logout=V,h.mutation=d,h.query=w,h.readFileAsBase64=nt,h.resetPassword=Z,h.sendMail=yt,h.setApiClient=L,h.toQuery=wt,h.updatePassword=Y,h.updateUser=ht,h.useGlobalModel=Ot,h.useGlobalModels=Dt,h.useModel=At,h.verifyCode=I,h.webAuthn=G,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"