@hostlink/light 2.13.2 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/light.js CHANGED
@@ -1,89 +1,103 @@
1
- var U = Object.defineProperty;
2
- var L = (t, e, r) => e in t ? U(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var F = (t, e, r) => L(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { jsonToGraphQLQuery as B, VariableType as C } from "json-to-graphql-query";
5
- import J from "axios";
6
- import P from "collect.js";
7
- const I = (t) => ({
8
- assertion: async () => {
9
- const { app: s } = await m(t, {
10
- app: {
11
- auth: {
12
- webAuthnRequestOptions: !0
13
- }
14
- }
15
- }), i = s.auth.webAuthnRequestOptions, c = PublicKeyCredential.parseRequestOptionsFromJSON(i);
16
- return await navigator.credentials.get({ publicKey: c });
17
- },
18
- attestation: async () => {
19
- const { app: s } = await m(t, {
20
- app: {
21
- auth: {
22
- webAuthnCreationOptions: !0
23
- }
24
- }
25
- }), i = PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);
26
- return await navigator.credentials.create({ publicKey: i });
27
- }
28
- });
29
- function D(t) {
1
+ import { jsonToGraphQLQuery as v, VariableType as F } from "json-to-graphql-query";
2
+ import H from "axios";
3
+ import M from "collect.js";
4
+ function P(t) {
30
5
  if (t === null || typeof t != "object")
31
6
  return !1;
32
7
  const e = Object.getPrototypeOf(t);
33
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;
34
9
  }
35
- function v(t, e, r = ".", s) {
36
- if (!D(e))
37
- return v(t, {}, r, s);
10
+ function E(t, e, r = ".", n) {
11
+ if (!P(e))
12
+ return E(t, {}, r, n);
38
13
  const i = Object.assign({}, e);
39
- for (const c in t) {
40
- if (c === "__proto__" || c === "constructor")
14
+ for (const f in t) {
15
+ if (f === "__proto__" || f === "constructor")
41
16
  continue;
42
- const f = t[c];
43
- f != null && (s && s(i, c, f, r) || (Array.isArray(f) && Array.isArray(i[c]) ? i[c] = [...f, ...i[c]] : D(f) && D(i[c]) ? i[c] = v(
44
- f,
45
- i[c],
46
- (r ? `${r}.` : "") + c.toString(),
47
- s
48
- ) : i[c] = f));
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(
19
+ a,
20
+ i[f],
21
+ (r ? `${r}.` : "") + f.toString(),
22
+ n
23
+ ) : i[f] = a));
49
24
  }
50
25
  return i;
51
26
  }
52
- function T(t) {
27
+ function X(t) {
53
28
  return (...e) => (
54
29
  // eslint-disable-next-line unicorn/no-array-reduce
55
- e.reduce((r, s) => v(r, s, "", t), {})
30
+ e.reduce((r, n) => E(r, n, "", t), {})
56
31
  );
57
32
  }
58
- const A = T(), M = (t) => {
59
- let e = {};
60
- return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
61
- Object.entries(M(r)).forEach(([s, i]) => {
62
- e[s] = i;
63
- });
64
- }), e) : (Object.entries(t).forEach(([r, s]) => {
65
- if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
66
- e[r] = s;
67
- return;
68
- }
69
- if (typeof s == "boolean") {
70
- e[r] = s;
71
- return;
33
+ const A = X();
34
+ let k = null;
35
+ const Y = (t) => {
36
+ k = t;
37
+ }, N = () => {
38
+ if (!k)
39
+ throw new Error("Api client not initialized. Call setApiClient() first.");
40
+ return k;
41
+ }, Ut = () => k;
42
+ function j(t) {
43
+ for (let e = 0; e < t.length; e++)
44
+ if (t[e] instanceof File)
45
+ return !0;
46
+ return !1;
47
+ }
48
+ function B(t) {
49
+ for (let e in t)
50
+ if (t[e] instanceof File || t[e] instanceof Array && j(t[e]))
51
+ return !0;
52
+ return !1;
53
+ }
54
+ function J(t, e, r, n, i) {
55
+ if (!(!t || typeof t != "object"))
56
+ for (let f in t) {
57
+ const a = t[f];
58
+ if (a && typeof a == "object") {
59
+ if ("__args" in a) {
60
+ const u = a.__args, s = {};
61
+ Object.entries(u).forEach(([o, c]) => {
62
+ if (c instanceof Array && j(c)) {
63
+ s[o] = new F(o);
64
+ let l = 0;
65
+ c.forEach((h) => {
66
+ h instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + o + "." + l), n.append(i.current.toString(), h), i.current++, l++);
67
+ }), e[o] = "[Upload!]!";
68
+ } else c instanceof File ? (s[o] = new F(o), r[i.current] = ["variables." + o], n.append(i.current.toString(), c), e[o] = "Upload!", i.current++) : c instanceof Object && B(c) ? (s[o] = {}, Object.entries(c).forEach(([l, h]) => {
69
+ if (h instanceof Array && j(h)) {
70
+ s[o][l] = new F(l);
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++, _++);
74
+ }), e[l] = "[Upload!]!";
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
+ })) : c != null && (s[o] = c);
77
+ }), a.__args = s;
78
+ }
79
+ J(a, e, r, n, i);
80
+ }
72
81
  }
73
- e[r] = M(s);
74
- }), e);
75
- }, E = (t) => M(t), m = async (t, e) => {
76
- let r = B(E(e));
77
- const s = await t.post("", {
78
- query: `{ ${r} }`
79
- });
80
- if (s.data.errors)
82
+ }
83
+ const y = async (t) => {
84
+ const e = N(), r = t, n = new FormData();
85
+ let i = !1;
86
+ const f = {}, a = {};
87
+ J(r, f, a, n, { current: 0 }), i = Object.keys(f).length > 0, i && (r.__variables = f);
88
+ let s = null;
89
+ const c = v({ query: r });
90
+ if (i ? (n.append("map", JSON.stringify(a)), n.append("operations", JSON.stringify({
91
+ query: c
92
+ })), s = await e.axios.post("", n)) : s = await e.axios.post("", {
93
+ query: c
94
+ }), s.data.errors)
81
95
  throw new Error(s.data.errors[0].message);
82
96
  return s.data.data;
83
97
  };
84
- function S(t, e, r) {
85
- let s, i = [], c, f;
86
- const l = (n) => !n || typeof n != "object" ? !1 : Object.values(n).some((o) => o && typeof o == "object" && Object.keys(o).some((a) => a.startsWith("_"))), p = () => i.length === 0 ? (i.unshift({}), i[0]) : (l(i[0]) && i.unshift({}), i[0]);
98
+ function U(t, e) {
99
+ let r, n = [], i, f;
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]);
87
101
  return {
88
102
  first() {
89
103
  return this.fetchFirst();
@@ -96,40 +110,40 @@ function S(t, e, r) {
96
110
  return Array.isArray(o) && o.length > 0 ? o[0] : null;
97
111
  },
98
112
  async fetchWithMeta() {
99
- let o = await m(t, this.toQuery(!0));
113
+ let o = await y(this.toQuery(!0));
100
114
  if (f) {
101
- const a = f.split(".");
102
- for (const u of a)
103
- o = o[u];
115
+ const c = f.split(".");
116
+ for (const l of c)
117
+ o = o[l];
104
118
  return o;
105
119
  }
106
- return o[`list${e}`];
120
+ return o[`list${t}`];
107
121
  },
108
122
  async fetch() {
109
- let o = await m(t, this.toQuery());
123
+ let o = await y(this.toQuery());
110
124
  if (f) {
111
- const a = f.split(".");
112
- for (const u of a)
113
- o = o[u];
125
+ const c = f.split(".");
126
+ for (const l of c)
127
+ o = o[l];
114
128
  return o.data;
115
129
  }
116
- return o[`list${e}`].data;
130
+ return o[`list${t}`].data;
117
131
  },
118
- dataPath(n) {
119
- return n && typeof n == "string" && (f = n), this;
132
+ dataPath(s) {
133
+ return s && typeof s == "string" && (f = s), this;
120
134
  },
121
- sort(n) {
122
- return n && typeof n == "string" && (c = n), this;
135
+ sort(s) {
136
+ return s && typeof s == "string" && (i = s), this;
123
137
  },
124
- filters(n) {
125
- return n && typeof n == "object" && (i = [n]), this;
138
+ filters(s) {
139
+ return s && typeof s == "object" && (n = [s]), this;
126
140
  },
127
141
  // where can be called as:
128
142
  // where('key', value) -> exact match
129
143
  // where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
130
- where(n, o, a) {
131
- const u = (h, g, y) => {
132
- const b = {
144
+ where(s, o, c) {
145
+ const l = (h, _, d) => {
146
+ const O = {
133
147
  ">": "_gt",
134
148
  "<": "_lt",
135
149
  ">=": "_gte",
@@ -137,564 +151,621 @@ function S(t, e, r) {
137
151
  "!=": "_ne",
138
152
  in: "_in",
139
153
  contains: "_contains"
140
- }[g];
141
- b && i.push({ [h]: { [b]: y } });
154
+ }[_];
155
+ O && n.push({ [h]: { [O]: d } });
142
156
  };
143
- if (a !== void 0)
144
- u(n, String(o), a);
157
+ if (c !== void 0)
158
+ l(s, String(o), c);
145
159
  else {
146
- const h = p(), g = A(h, { [n]: o });
147
- i[0] = g;
160
+ const h = u(), _ = A(h, { [s]: o });
161
+ n[0] = _;
148
162
  }
149
163
  return this;
150
164
  },
151
165
  // whereContains adds a _contains filter for a specific field
152
166
  // If the same field is used multiple times, it merges them into an array
153
- whereContains(n, o) {
154
- if (n && typeof n == "string") {
155
- const a = p(), u = { _contains: o };
156
- a[n] ? Array.isArray(a[n]) ? a[n].push(u) : a[n] = [a[n], u] : a[n] = [u], i[0] = a;
167
+ whereContains(s, o) {
168
+ if (s && typeof s == "string") {
169
+ const c = u(), l = { _contains: o };
170
+ c[s] ? Array.isArray(c[s]) ? c[s].push(l) : c[s] = [c[s], l] : c[s] = [l], n[0] = c;
157
171
  }
158
172
  return this;
159
173
  },
160
174
  // ...existing code...
161
175
  // whereIn adds an _in filter for a specific field
162
176
  // If the same field is used multiple times, it merges them into an array
163
- whereIn(n, o) {
164
- if (n && typeof n == "string" && Array.isArray(o)) {
165
- const a = p(), u = { _in: o };
166
- a[n] ? Array.isArray(a[n]) ? a[n].push(u) : a[n] = [a[n], u] : a[n] = [u], i[0] = a;
177
+ whereIn(s, o) {
178
+ if (s && typeof s == "string" && Array.isArray(o)) {
179
+ const c = u(), l = { _in: o };
180
+ c[s] ? Array.isArray(c[s]) ? c[s].push(l) : c[s] = [c[s], l] : c[s] = [l], n[0] = c;
167
181
  }
168
182
  return this;
169
183
  },
170
184
  // whereBetween adds a _between filter for a specific field
171
- whereBetween(n, o, a) {
172
- if (n && typeof n == "string") {
173
- const u = p(), h = { _between: [o, a] };
174
- u[n] ? Array.isArray(u[n]) ? u[n].push(h) : u[n] = [u[n], h] : u[n] = h, i[0] = u;
185
+ whereBetween(s, o, c) {
186
+ if (s && typeof s == "string") {
187
+ const l = u(), h = { _between: [o, c] };
188
+ l[s] ? Array.isArray(l[s]) ? l[s].push(h) : l[s] = [l[s], h] : l[s] = h, n[0] = l;
175
189
  }
176
190
  return this;
177
191
  },
178
192
  // limit sets paging/limit for the data selection
179
- limit(n) {
180
- return typeof n == "number" && Number.isFinite(n) && (s = A(s || {}, { limit: n })), this;
193
+ limit(s) {
194
+ return typeof s == "number" && Number.isFinite(s) && (r = A(r || {}, { limit: s })), this;
181
195
  },
182
196
  // offset sets the starting index for the data selection
183
- offset(n) {
184
- return typeof n == "number" && Number.isFinite(n) && (s = A(s || {}, { offset: n })), this;
197
+ offset(s) {
198
+ return typeof s == "number" && Number.isFinite(s) && (r = A(r || {}, { offset: s })), this;
185
199
  },
186
- toQuery(n = !1) {
200
+ toQuery(s = !1) {
187
201
  let o;
188
- const a = i.length > 0 && Object.keys(i[0] || {}).length > 0, u = a ? 1 : 0, h = i.length > u;
189
- a && h ? o = i : h ? o = i.slice(u) : a && (o = i[0]);
190
- const g = A(
191
- c ? { sort: c } : {},
202
+ const c = n.length > 0 && Object.keys(n[0] || {}).length > 0, l = c ? 1 : 0, h = n.length > l;
203
+ c && h ? o = n : h ? o = n.slice(l) : c && (o = n[0]);
204
+ const _ = A(
205
+ i ? { sort: i } : {},
192
206
  o ? { filters: o } : {}
193
- ), y = {
207
+ ), d = {
194
208
  data: {
195
- ...r
209
+ ...e
196
210
  }
197
211
  };
198
- if (s && (y.data.__args = s), Object.keys(g).length > 0 && (y.__args = g), n && (y.meta = {
212
+ if (r && (d.data.__args = r), Object.keys(_).length > 0 && (d.__args = _), s && (d.meta = {
199
213
  total: !0,
200
214
  key: !0,
201
215
  name: !0
202
216
  }), f) {
203
217
  const w = f.split(".");
204
- let b = y;
205
- for (let j = w.length - 1; j >= 0; j--)
206
- b = {
207
- [w[j]]: b
218
+ let O = d;
219
+ for (let C = w.length - 1; C >= 0; C--)
220
+ O = {
221
+ [w[C]]: O
208
222
  };
209
- return b;
223
+ return O;
210
224
  }
211
225
  return {
212
- [`list${e}`]: y
226
+ [`list${t}`]: d
213
227
  };
214
228
  }
215
229
  };
216
230
  }
217
- const N = (t, e, r) => {
218
- const s = e, i = t, c = r;
219
- let f = "list" + e;
220
- const l = (p) => c[p] ? c[p] : null;
231
+ const L = (t, e) => {
232
+ const r = t, n = e;
233
+ let i = "list" + t;
234
+ const f = (a) => n[a] ? n[a] : null;
221
235
  return {
222
- field: l,
223
- $fields: c,
224
- setDataPath(p) {
225
- return f = p, f;
236
+ field: f,
237
+ $fields: n,
238
+ setDataPath(a) {
239
+ return i = a, i;
226
240
  },
227
241
  getDataPath() {
228
- return f;
242
+ return i;
229
243
  },
230
- gqlFields(p) {
231
- let n = {};
232
- for (const o of p)
233
- if (typeof o == "string") {
234
- const a = l(o);
235
- a && (n = A(n, a.gqlField ? typeof a.gqlField == "string" ? { [a.gqlField]: !0 } : a.gqlField : { [a.name || o]: !0 }));
236
- } else typeof o == "object" && (n = A(n, o));
237
- return n;
244
+ gqlFields(a) {
245
+ let u = {};
246
+ for (const s of a)
247
+ if (typeof s == "string") {
248
+ const o = f(s);
249
+ o && (u = A(u, o.gqlField ? typeof o.gqlField == "string" ? { [o.gqlField]: !0 } : o.gqlField : { [o.name || s]: !0 }));
250
+ } else typeof s == "object" && (u = A(u, s));
251
+ return u;
238
252
  },
239
- async update(p, n) {
240
- return await d(i, "update" + s, { id: p, data: n });
253
+ update(a, u) {
254
+ return p({
255
+ ["update" + r]: {
256
+ __args: { id: a, data: u }
257
+ }
258
+ }).then((s) => s["update" + r]);
241
259
  },
242
- async delete(p) {
243
- return await d(i, "delete" + s, { id: p });
260
+ async delete(a) {
261
+ return p({
262
+ ["delete" + r]: {
263
+ __args: { id: a }
264
+ }
265
+ }).then((u) => u["delete" + r]);
244
266
  },
245
- async add(p) {
246
- return await d(i, "add" + s, { data: p });
267
+ add(a) {
268
+ return p({
269
+ ["add" + r]: {
270
+ __args: { data: a }
271
+ }
272
+ }).then((u) => u["add" + r]);
247
273
  },
248
- fields(p) {
249
- let n = [];
250
- for (let o of p) {
251
- const a = l(o);
252
- a && n.push(a);
274
+ fields(a) {
275
+ let u = [];
276
+ for (let s of a) {
277
+ const o = f(s);
278
+ o && u.push(o);
253
279
  }
254
- return n;
280
+ return u;
255
281
  },
256
- async get(p, n) {
257
- const o = (await Promise.resolve().then(() => et)).default, a = o(s, i, E(n));
258
- for (const [u, h] of Object.entries(p))
259
- a.where(u, "==", h);
260
- return await a.first();
282
+ async get(a, u) {
283
+ const s = (await Promise.resolve().then(() => Pt)).default, o = s(r, Dt(u));
284
+ for (const [c, l] of Object.entries(a))
285
+ o.where(c, "==", l);
286
+ return await o.first();
261
287
  },
262
- list(p) {
263
- let n = p;
264
- const o = {};
265
- Object.entries(p).forEach(([h]) => {
266
- c[h] && (o[h] = c[h], c[h].gqlField && (delete n[h], n = A(n, c[h].gqlField)), c[h].gql && (n = A(n, c[h].gql), delete n[h]));
288
+ list(a) {
289
+ let u = a;
290
+ const s = {};
291
+ Object.entries(a).forEach(([l]) => {
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]));
267
293
  });
268
- const a = S(i, s, n).dataPath(f), u = a.fetch.bind(a);
294
+ const o = U(r, u).dataPath(i), c = o.fetch.bind(o);
269
295
  return {
270
- ...a,
296
+ ...o,
271
297
  async fetch() {
272
- return (await u()).map((g) => {
273
- const y = { ...g };
274
- return Object.entries(o).forEach(([w, b]) => {
275
- b.format && typeof b.format == "function" && (y[w] = b.format(g));
276
- }), y;
298
+ return (await c()).map((h) => {
299
+ const _ = { ...h };
300
+ return Object.entries(s).forEach(([d, w]) => {
301
+ w.format && typeof w.format == "function" && (_[d] = w.format(h));
302
+ }), _;
277
303
  });
278
304
  },
279
305
  async fetchFirst() {
280
- const g = await a.fetchFirst.bind(a)();
281
- if (!g) return g;
282
- const y = { ...g };
283
- return Object.entries(o).forEach(([w, b]) => {
284
- b.format && typeof b.format == "function" && (y[w] = b.format(g));
285
- }), y;
306
+ const h = await o.fetchFirst.bind(o)();
307
+ if (!h) return h;
308
+ const _ = { ...h };
309
+ return Object.entries(s).forEach(([d, w]) => {
310
+ w.format && typeof w.format == "function" && (_[d] = w.format(h));
311
+ }), _;
286
312
  }
287
313
  };
288
314
  }
289
315
  };
290
- }, O = {}, q = (t, e = !1) => {
291
- const r = t, s = {};
316
+ }, b = {}, q = (t = !1) => {
317
+ const e = {};
292
318
  return {
293
319
  /**
294
320
  * 創建新模型
295
321
  * @param name 模型名稱
296
322
  * @param fields 模型欄位定義
297
323
  */
298
- create(i, c) {
299
- const f = N(r, i, c);
300
- s[i] = f, e && (O[i] = f);
324
+ create(r, n) {
325
+ const i = L(r, n);
326
+ e[r] = i, t && (b[r] = i);
301
327
  },
302
328
  /**
303
329
  * 獲取模型
304
330
  * @param name 模型名稱
305
331
  * @returns 模型實例
306
332
  */
307
- get(i) {
308
- return s[i] || (e && O[i] ? s[i] = O[i] : this.create(i, {})), s[i];
333
+ get(r) {
334
+ return e[r] || (t && b[r] ? e[r] = b[r] : this.create(r, {})), e[r];
309
335
  },
310
336
  /**
311
337
  * 檢查模型是否存在
312
338
  * @param name 模型名稱
313
339
  * @returns 是否存在
314
340
  */
315
- has(i) {
316
- return !!s[i] || e && !!O[i];
341
+ has(r) {
342
+ return !!e[r] || t && !!b[r];
317
343
  },
318
344
  /**
319
345
  * 列出所有模型名稱
320
346
  * @returns 模型名稱陣列
321
347
  */
322
348
  list() {
323
- const i = Object.keys(s), c = e ? Object.keys(O) : [];
324
- return [.../* @__PURE__ */ new Set([...i, ...c])];
349
+ const r = Object.keys(e), n = t ? Object.keys(b) : [];
350
+ return [.../* @__PURE__ */ new Set([...r, ...n])];
325
351
  },
326
352
  /**
327
353
  * 清除所有模型
328
354
  */
329
355
  clear() {
330
- Object.keys(s).forEach((i) => delete s[i]);
356
+ Object.keys(e).forEach((r) => delete e[r]);
331
357
  }
332
358
  };
333
- }, ot = (t) => {
334
- const e = q(t, !1);
359
+ }, qt = () => {
360
+ const t = q(!1);
335
361
  return {
336
362
  // 暴露完整的管理器
337
- manager: e,
363
+ manager: t,
338
364
  // 便利方法 - 直接暴露常用功能
339
- createModel: e.create,
340
- getModel: e.get,
341
- hasModel: e.has,
342
- listModels: e.list,
343
- clearModels: e.clear,
365
+ createModel: t.create,
366
+ getModel: t.get,
367
+ hasModel: t.has,
368
+ listModels: t.list,
369
+ clearModels: t.clear,
344
370
  /**
345
371
  * 快速創建並獲取模型
346
372
  * @param name 模型名稱
347
373
  * @param fields 模型欄位定義
348
374
  * @returns 模型實例
349
375
  */
350
- defineModel(r, s) {
351
- return e.create(r, s), e.get(r);
376
+ defineModel(e, r) {
377
+ return t.create(e, r), t.get(e);
352
378
  },
353
379
  /**
354
380
  * 批量創建模型
355
381
  * @param models 模型定義對象
356
382
  */
357
- defineModels(r) {
358
- Object.entries(r).forEach(([s, i]) => {
359
- e.create(s, i);
383
+ defineModels(e) {
384
+ Object.entries(e).forEach(([r, n]) => {
385
+ t.create(r, n);
360
386
  });
361
387
  }
362
388
  };
363
- }, lt = (t) => {
364
- const e = q(t, !0);
389
+ }, vt = () => {
390
+ const t = q(!0);
365
391
  return {
366
392
  // 暴露完整的管理器
367
- manager: e,
393
+ manager: t,
368
394
  // 便利方法 - 直接暴露常用功能
369
- createModel: e.create,
370
- getModel: e.get,
371
- hasModel: e.has,
372
- listModels: e.list,
373
- clearModels: e.clear,
395
+ createModel: t.create,
396
+ getModel: t.get,
397
+ hasModel: t.has,
398
+ listModels: t.list,
399
+ clearModels: t.clear,
374
400
  /**
375
401
  * 快速創建並獲取模型
376
402
  * @param name 模型名稱
377
403
  * @param fields 模型欄位定義
378
404
  * @returns 模型實例
379
405
  */
380
- defineModel(r, s) {
381
- return e.create(r, s), e.get(r);
406
+ defineModel(e, r) {
407
+ return t.create(e, r), t.get(e);
382
408
  },
383
409
  /**
384
410
  * 批量創建模型
385
411
  * @param models 模型定義對象
386
412
  */
387
- defineModels(r) {
388
- Object.entries(r).forEach(([s, i]) => {
389
- e.create(s, i);
413
+ defineModels(e) {
414
+ Object.entries(e).forEach(([r, n]) => {
415
+ t.create(r, n);
390
416
  });
391
417
  }
392
418
  };
393
- }, ct = (t) => ({
419
+ }, Nt = () => ({
394
420
  /**
395
421
  * 創建全域模型
396
422
  * @param name 模型名稱
397
423
  * @param fields 模型欄位定義
398
424
  */
399
- define(e, r) {
400
- const s = N(t, e, r);
401
- return O[e] = s, s;
425
+ define(t, e) {
426
+ const r = L(t, e);
427
+ return b[t] = r, r;
402
428
  },
403
429
  /**
404
430
  * 獲取全域模型
405
431
  * @param name 模型名稱
406
432
  * @returns 模型實例
407
433
  */
408
- get(e) {
409
- return O[e];
434
+ get(t) {
435
+ return b[t];
410
436
  },
411
437
  /**
412
438
  * 檢查全域模型是否存在
413
439
  * @param name 模型名稱
414
440
  * @returns 是否存在
415
441
  */
416
- has(e) {
417
- return !!O[e];
442
+ has(t) {
443
+ return !!b[t];
418
444
  },
419
445
  /**
420
446
  * 列出所有全域模型
421
447
  * @returns 模型名稱陣列
422
448
  */
423
449
  list() {
424
- return Object.keys(O);
450
+ return Object.keys(b);
425
451
  },
426
452
  /**
427
453
  * 清除所有全域模型
428
454
  */
429
455
  clear() {
430
- Object.keys(O).forEach((e) => delete O[e]);
456
+ Object.keys(b).forEach((t) => delete b[t]);
431
457
  }
432
- }), W = (t) => {
433
- const { assertion: e, attestation: r } = I(t);
434
- return {
435
- login: async () => {
436
- const s = await e();
437
- await d(t, "webAuthnAssertion", {
438
- assertion: s.toJSON()
439
- });
440
- },
441
- register: async () => {
442
- const s = await r();
443
- await d(t, "webAuthnRegister", {
444
- registration: s.toJSON()
445
- });
458
+ }), Bt = () => y({
459
+ app: {
460
+ permissions: !0
461
+ }
462
+ }).then((t) => t.app.permissions), Q = async () => {
463
+ const { app: t } = await y({
464
+ app: {
465
+ auth: {
466
+ webAuthnRequestOptions: !0
467
+ }
446
468
  }
447
- };
448
- }, $ = (t) => ({
449
- WebAuthn: W(t),
469
+ }), e = t.auth.webAuthnRequestOptions, r = PublicKeyCredential.parseRequestOptionsFromJSON(e);
470
+ return await navigator.credentials.get({ publicKey: r });
471
+ }, T = async () => {
472
+ const { app: t } = await y({
473
+ app: {
474
+ auth: {
475
+ webAuthnCreationOptions: !0
476
+ }
477
+ }
478
+ }), e = PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);
479
+ return await navigator.credentials.create({ publicKey: e });
480
+ }, Z = async () => {
481
+ const t = await Q();
482
+ return await p({
483
+ webAuthnAssertion: {
484
+ assertion: t.toJSON()
485
+ }
486
+ }).then((e) => e.webAuthnAssertion);
487
+ }, V = async () => {
488
+ const t = await T();
489
+ return await p({
490
+ webAuthnRegister: {
491
+ registration: t.toJSON()
492
+ }
493
+ }).then((e) => e.webAuthnRegister);
494
+ }, K = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
495
+ __proto__: null,
496
+ assertion: Q,
497
+ attestation: T,
498
+ login: Z,
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({
501
+ my: {
502
+ grantedRights: {
503
+ __args: {
504
+ rights: t
505
+ }
506
+ }
507
+ }
508
+ }).then((e) => e.my.grantedRights), at = () => ({
509
+ getCurrentUser: I,
510
+ webAuthn: K,
450
511
  google: {
451
- unlink: () => d(t, "lightAuthUnlinkGoogle"),
452
- login: (e) => d(t, "lightAuthLoginGoogle", {
453
- credential: e
454
- }),
455
- register: (e) => d(t, "lightAuthRegisterGoogle", {
456
- credential: e
457
- })
512
+ unlink: () => p({ lightAuthUnlinkGoogle: !0 }).then((t) => t.lightAuthUnlinkGoogle),
513
+ login: (t) => p({ lightAuthLoginGoogle: { __args: { credential: t } } }).then((e) => e.lightAuthLoginGoogle),
514
+ register: (t) => p({ lightAuthRegisterGoogle: { __args: { credential: t } } }).then((e) => e.lightAuthRegisterGoogle)
458
515
  },
459
516
  facebook: {
460
- unlink: () => d(t, "lightAuthUnlinkFacebook"),
461
- login: (e) => d(t, "lightAuthLoginFacebook", {
462
- access_token: e
463
- }),
464
- register: (e) => d(t, "lightAuthRegisterFacebook", {
465
- access_token: e
466
- })
517
+ unlink: () => p({ lightAuthUnlinkFacebook: !0 }).then((t) => t.lightAuthUnlinkFacebook),
518
+ login: (t) => p({ lightAuthLoginFacebook: { __args: { access_token: t } } }).then((e) => e.lightAuthLoginFacebook),
519
+ register: (t) => p({ lightAuthRegisterFacebook: { __args: { access_token: t } } }).then((e) => e.lightAuthRegisterFacebook)
467
520
  },
468
521
  microsoft: {
469
- unlink: () => d(t, "lightAuthUnlinkMicrosoft"),
470
- login: (e) => d(t, "lightAuthLoginMicrosoft", {
471
- access_token: e
472
- }),
473
- register: (e) => d(t, "lightAuthRegisterMicrosoft", {
474
- account_id: e
475
- })
522
+ unlink: () => p({ lightAuthUnlinkMicrosoft: !0 }).then((t) => t.lightAuthUnlinkMicrosoft),
523
+ login: (t) => p({ lightAuthLoginMicrosoft: { __args: { access_token: t } } }).then((e) => e.lightAuthLoginMicrosoft),
524
+ register: (t) => p({ lightAuthRegisterMicrosoft: { __args: { account_id: t } } }).then((e) => e.lightAuthRegisterMicrosoft)
476
525
  },
477
- login: (e, r, s = "") => d(t, "login", {
478
- username: e,
479
- password: r,
480
- code: s
481
- }),
482
- logout: () => d(t, "logout"),
483
- changeExpiredPassword: (e, r, s) => d(t, "changeExpiredPassword", {
484
- username: e,
485
- old_password: r,
486
- new_password: s
487
- }),
488
- updatePassword: (e, r) => d(t, "changeUserPassword", {
489
- old_password: e,
490
- new_password: r
491
- }),
492
- resetPassword: (e, r, s) => d(t, "resetPassword", {
493
- jwt: e,
494
- password: r,
495
- code: s
496
- }),
497
- forgetPassword: (e, r) => d(t, "forgetPassword", {
498
- username: e,
499
- email: r
500
- }),
501
- verifyCode(e, r) {
502
- return d(t, "forgetPasswordVerifyCode", {
503
- jwt: e,
504
- code: r
505
- });
506
- },
507
- granted: async (e) => {
508
- const { my: r } = await m(t, {
509
- my: {
510
- grantedRights: {
511
- __args: {
512
- rights: e
513
- }
514
- }
526
+ login: x,
527
+ logout: tt,
528
+ changeExpiredPassword: et,
529
+ updatePassword: rt,
530
+ resetPassword: st,
531
+ forgetPassword: nt,
532
+ verifyCode: ot,
533
+ granted: it
534
+ }), $ = {
535
+ name: !0,
536
+ path: !0,
537
+ size: !0,
538
+ mime: !0,
539
+ url: !0
540
+ }, ct = (t, e, r = $) => y({
541
+ app: {
542
+ drive: {
543
+ __args: { index: t },
544
+ files: {
545
+ __args: { path: e },
546
+ ...r
515
547
  }
516
- });
517
- return r.grantedRights;
518
- }
519
- });
520
- function Q(t) {
521
- t = "<~" + t + "~>";
522
- var e, r, s, i, c, f = String, l = 255;
523
- 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, c = t.length; c > i; i += 5) r = 52200625 * (t.charCodeAt(i) - 33) + 614125 * (t.charCodeAt(i + 1) - 33) + 7225 * (t.charCodeAt(i + 2) - 33) + 85 * (t.charCodeAt(i + 3) - 33) + (t.charCodeAt(i + 4) - 33), s.push(l & r >> 24, l & r >> 16, l & r >> 8, l & r);
524
- return function(p, n) {
525
- for (var o = n; o > 0; o--) p.pop();
526
- }(s, e.length), f.fromCharCode.apply(f, s);
527
- }
528
- const k = (t = "") => {
529
- const e = t, r = (s = "application/octet-stream") => {
530
- const i = new Uint8Array(e.length);
531
- for (let l = 0; l < e.length; l++)
532
- i[l] = e.charCodeAt(l);
533
- const c = new Blob([i], { type: s });
534
- return URL.createObjectURL(c);
535
- };
536
- return {
537
- getContent: () => e,
538
- getURL: r,
539
- download: (s) => {
540
- const i = document.createElement("a");
541
- i.download = s, i.href = r(), document.body.appendChild(i), i.click(), document.body.removeChild(i);
542
- },
543
- open: (s) => {
544
- window.open(r(s), "_blank");
545
548
  }
546
- };
547
- }, ut = {
548
- fromBase85: (t) => k(Q(t)),
549
- fromBase64: (t) => k(atob(t)),
550
- fromString: (t) => k(t)
551
- };
552
- function K(t) {
553
- for (let e = 0; e < t.length; e++)
554
- if (t[e] instanceof File)
555
- return !0;
556
- return !1;
557
- }
558
- function z(t) {
559
- for (let e in t)
560
- if (t[e] instanceof File)
561
- return !0;
562
- return !1;
563
- }
564
- const d = async (t, e, r = null, s = []) => {
565
- let i = {
566
- [e]: {}
567
- };
568
- const c = new FormData();
569
- let f = !1;
570
- if (r) {
571
- const n = {}, o = {}, a = {};
572
- let u = 0;
573
- Object.entries(r).forEach(([h, g]) => {
574
- if (g instanceof Array && K(g)) {
575
- f = !0;
576
- let y = 0;
577
- g.forEach((w) => {
578
- w instanceof File && (n[h] = new C(h), o[u] = ["variables." + h + "." + y], c.append(u.toString(), w), u++);
579
- }), a[h] = "[Upload!]!";
580
- } else g instanceof File ? (f = !0, n[h] = new C(h), o[u] = ["variables." + h], c.append(u.toString(), g), a[h] = "Upload!", u++) : g instanceof Object && z(g) ? (f = !0, n[h] = {}, Object.entries(g).forEach(([y, w]) => {
581
- w instanceof File ? (n[h][y] = new C(y), o[u] = ["variables." + y], c.append(u.toString(), w), a[y] = "Upload!", u++) : n[h][y] = w;
582
- })) : g !== void 0 && (n[h] = g);
583
- }), i[e].__args = n, i.__variables = a, f && c.append("map", JSON.stringify(o));
584
549
  }
585
- Object.entries(E(s)).forEach(([n, o]) => {
586
- i[e][n] = o;
587
- }), Object.entries(i[e]).length === 0 && (i[e] = !0);
588
- let l = null;
589
- const p = B({ mutation: i });
590
- if (f ? (c.append("operations", JSON.stringify({
591
- query: p
592
- })), l = await t.post("", c)) : l = await t.post("", {
593
- query: p
594
- }), l.data.errors)
595
- throw new Error(l.data.errors[0].message);
596
- return l.data.data[e];
597
- }, G = (t) => ({
598
- uploadTempFile: (e) => d(t, "fsUploadTempFile", {
599
- file: e
600
- }, {
550
+ }).then((n) => n.app.drive.files), m = (t) => ({
551
+ list: (e, r = $) => ct(t, e, r),
552
+ get: (e, r = {
601
553
  name: !0,
602
554
  path: !0,
603
555
  size: !0,
604
- mime: !0
605
- }),
606
- folders: {
607
- list: async (e) => (await m(t, {
608
- fsListFolders: {
556
+ mime: !0,
557
+ url: !0
558
+ }) => y({
559
+ app: {
560
+ drive: {
609
561
  __args: {
610
- path: e
562
+ index: t
611
563
  },
612
- name: !0,
613
- path: !0
614
- }
615
- })).fsListFolders,
616
- create: (e) => d(t, "fsCreateFolder", { path: e }),
617
- delete: (e) => d(t, "fsDeleteFolder", { path: e }),
618
- rename: (e, r) => d(t, "fsRenameFolder", { path: e, name: r })
619
- },
620
- files: {
621
- list: async (e) => {
622
- let { app: r } = await m(t, {
623
- app: {
624
- drive: {
625
- files: {
626
- __args: {
627
- path: e
628
- },
629
- name: !0,
630
- path: !0,
631
- size: !0,
632
- mime: !0,
633
- canPreview: !0,
634
- imagePath: !0
635
- }
636
- }
564
+ file: {
565
+ __args: {
566
+ path: e
567
+ },
568
+ ...r
637
569
  }
638
- });
639
- return r.drive.files;
640
- },
641
- read: async (e) => {
642
- let { app: r } = await m(t, {
643
- app: {
644
- drive: {
645
- files: {
646
- __args: {
647
- path: e
648
- },
649
- base64Content: !0
650
- }
570
+ }
571
+ }
572
+ }).then((n) => n.app.drive.file),
573
+ read: async (e) => {
574
+ let r = await y({
575
+ app: {
576
+ drive: {
577
+ __args: {
578
+ index: t
579
+ },
580
+ file: {
581
+ __args: {
582
+ path: e
583
+ },
584
+ base64Content: !0
651
585
  }
652
586
  }
653
- });
654
- return window.atob(r.drive.files[0].base64Content);
655
- },
656
- write: (e, r) => d(t, "fsWriteFile", {
657
- path: e,
658
- content: r
659
- }),
660
- delete: (e) => d(t, "fsDeleteFile", { path: e }),
661
- rename: (e, r) => d(t, "fsRenameFile", { path: e, name: r }),
662
- move: (e, r) => d(t, "fsMoveFile", { source: e, target: r })
587
+ }
588
+ });
589
+ if (!r.app.drive.file || !r.app.drive.file.base64Content)
590
+ throw new Error(`File not found or cannot read content: ${e}`);
591
+ return typeof window < "u" && window.atob ? window.atob(r.app.drive.file.base64Content) : r.app.drive.file.base64Content;
592
+ },
593
+ write: (e, r) => p({ lightDriveWriteFile: { __args: { index: t, path: e, content: r } } }).then((n) => n.lightDriveWriteFile),
594
+ delete: (e) => p({ lightDriveDeleteFile: { __args: { index: t, path: e } } }).then((r) => r.lightDriveDeleteFile),
595
+ rename: (e, r) => p({ lightDriveRenameFile: { __args: { index: t, path: e, name: r } } }).then((n) => n.lightDriveRenameFile),
596
+ move: (e, r) => p({ lightDriveMoveFile: { __args: { index: t, source: e, destination: r } } }).then((n) => n.lightDriveMoveFile)
597
+ }), W = {
598
+ name: !0,
599
+ path: !0
600
+ }, lt = (t, e, r = W) => y({
601
+ app: {
602
+ drive: {
603
+ __args: { index: t },
604
+ folders: {
605
+ __args: { path: e },
606
+ ...r
607
+ }
608
+ }
609
+ }
610
+ }).then((n) => n.app.drive.folders), D = (t) => ({
611
+ list: (e, r = W) => lt(t, e, r),
612
+ create: (e) => p({ lightDriveCreateFolder: { __args: { index: t, path: e } } }).then((r) => r.lightDriveCreateFolder),
613
+ delete: (e) => p({ lightDriveDeleteFolder: { __args: { index: t, path: e } } }).then((r) => r.lightDriveDeleteFolder),
614
+ rename: (e, r) => p({ lightDriveRenameFolder: { __args: { index: t, path: e, name: r } } }).then((n) => n.lightDriveRenameFolder)
615
+ }), Jt = () => y({
616
+ app: {
617
+ drives: {
618
+ index: !0,
619
+ name: !0
620
+ }
663
621
  }
664
- }), H = (t) => ({
665
- get: async (e) => (await t({
666
- config: {
622
+ }).then((t) => t.app.drives), ut = (t) => ({
623
+ listFiles: m(t).list,
624
+ getFile: m(t).get,
625
+ readFile: m(t).read,
626
+ writeFile: m(t).write,
627
+ deleteFile: m(t).delete,
628
+ renameFile: m(t).rename,
629
+ moveFile: m(t).move,
630
+ listFolders: D(t).list,
631
+ createFolder: D(t).create,
632
+ deleteFolder: D(t).delete,
633
+ renameFolder: D(t).rename,
634
+ uploadTempFile: (e) => p({
635
+ lightDriveUploadTempFile: {
636
+ __args: { index: t, file: e },
637
+ name: !0,
638
+ path: !0,
639
+ size: !0,
640
+ mime: !0
641
+ }
642
+ }).then((r) => r.lightDriveUploadTempFile),
643
+ folders: D(t),
644
+ files: m(t)
645
+ }), G = {
646
+ user_id: !0,
647
+ username: !0,
648
+ first_name: !0,
649
+ last_name: !0,
650
+ status: !0
651
+ }, ht = (t) => p({
652
+ addUser: {
653
+ __args: t
654
+ }
655
+ }).then((e) => e.addUser), ft = (t) => p({
656
+ deleteUser: {
657
+ __args: { id: t }
658
+ }
659
+ }).then((e) => e.deleteUser), pt = (t = G) => U("Users", t).dataPath("app.listUser").fetch(), dt = (t, e) => p({
660
+ updateUser: {
661
+ __args: { id: t, data: e }
662
+ }
663
+ }).then((r) => r.updateUser), gt = () => ({
664
+ list: pt,
665
+ create: ht,
666
+ delete: ft,
667
+ update: dt
668
+ }), _t = (t) => y({
669
+ app: {
670
+ listConfig: {
667
671
  __args: {
668
- name: e
672
+ filters: {
673
+ name: t
674
+ }
675
+ },
676
+ data: {
677
+ name: !0,
678
+ value: !0
669
679
  }
670
680
  }
671
- })).config
672
- }), X = (t) => ({
673
- send: (e, r, s) => d(t, "sendMail", {
674
- email: e,
675
- subject: r,
676
- message: s
677
- })
678
- }), V = (t) => ({
679
- list: (e = {
680
- user_id: !0,
681
- username: !0,
682
- first_name: !0,
683
- last_name: !0,
684
- status: !0
685
- }) => S(t, "Users", e).dataPath("app.users")
686
- }), Y = (t) => ({
687
- list: async (e = {
688
- name: !0
689
- }) => {
690
- const { app: { roles: r } } = await m(t, {
691
- app: {
692
- roles: e
681
+ }
682
+ }).then((e) => e.app.listConfig.data[0]?.value), yt = {
683
+ name: !0
684
+ }, wt = (t = yt) => y({
685
+ app: {
686
+ roles: t
687
+ }
688
+ }).then((e) => e.app.roles), bt = (t, e) => p({
689
+ addRole: {
690
+ __args: {
691
+ data: {
692
+ name: t,
693
+ childs: e
693
694
  }
694
- });
695
- return r;
695
+ }
696
+ }
697
+ }).then((r) => r.addRole), mt = (t) => p({
698
+ deleteRole: {
699
+ __args: { name: t }
696
700
  }
697
- }), Z = "list", x = [
701
+ }).then((e) => e.deleteRole), Ft = () => ({
702
+ list: wt,
703
+ create: bt,
704
+ delete: mt
705
+ });
706
+ function z(t, e, r, n, i) {
707
+ if (!(!t || typeof t != "object"))
708
+ for (let f in t) {
709
+ const a = t[f];
710
+ if (a && typeof a == "object") {
711
+ if ("__args" in a) {
712
+ const u = a.__args, s = {};
713
+ Object.entries(u).forEach(([o, c]) => {
714
+ if (c instanceof Array && j(c)) {
715
+ s[o] = new F(o);
716
+ let l = 0;
717
+ c.forEach((h) => {
718
+ h instanceof File && (r[i.current] || (r[i.current] = []), r[i.current].push("variables." + o + "." + l), n.append(i.current.toString(), h), i.current++, l++);
719
+ }), e[o] = "[Upload!]!";
720
+ } else c instanceof File ? (s[o] = new F(o), r[i.current] = ["variables." + o], n.append(i.current.toString(), c), e[o] = "Upload!", i.current++) : c instanceof Object && B(c) ? (s[o] = {}, Object.entries(c).forEach(([l, h]) => {
721
+ if (h instanceof Array && j(h)) {
722
+ s[o][l] = new F(l);
723
+ 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++, _++);
726
+ }), e[l] = "[Upload!]!";
727
+ } 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
+ })) : c != null && (s[o] = c);
729
+ }), a.__args = s;
730
+ }
731
+ z(a, e, r, n, i);
732
+ }
733
+ }
734
+ }
735
+ const p = async (t) => {
736
+ const r = N().axios, n = t, i = new FormData();
737
+ let f = !1;
738
+ const a = {}, u = {};
739
+ z(n, a, u, i, { current: 0 }), f = Object.keys(a).length > 0, f && (n.__variables = a);
740
+ let o = null;
741
+ const l = v({ mutation: n });
742
+ if (f ? (i.append("map", JSON.stringify(u)), i.append("operations", JSON.stringify({
743
+ query: l
744
+ })), o = await r.post("", i)) : o = await r.post("", {
745
+ query: l
746
+ }), o.data.errors)
747
+ throw new Error(o.data.errors[0].message);
748
+ 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) => {
752
+ let e = {};
753
+ return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
754
+ Object.entries(S(r)).forEach(([n, i]) => {
755
+ e[n] = i;
756
+ });
757
+ }), e) : (Object.entries(t).forEach(([r, n]) => {
758
+ if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
759
+ e[r] = n;
760
+ return;
761
+ }
762
+ if (typeof n == "boolean") {
763
+ e[r] = n;
764
+ return;
765
+ }
766
+ e[r] = S(n);
767
+ }), e);
768
+ }, Dt = (t) => S(t), jt = "list", kt = [
698
769
  "flatMap",
699
770
  "chunk",
700
771
  "shuffle",
@@ -720,7 +791,7 @@ const d = async (t, e, r = null, s = []) => {
720
791
  "slice",
721
792
  "tap",
722
793
  "sort"
723
- ], tt = [
794
+ ], Ct = [
724
795
  "avg",
725
796
  "count",
726
797
  "countBy",
@@ -748,25 +819,24 @@ const d = async (t, e, r = null, s = []) => {
748
819
  "implode",
749
820
  "partition"
750
821
  ];
751
- class _ {
752
- constructor(e, r) {
753
- F(this, "_batchData", null);
754
- F(this, "data_path", "");
755
- F(this, "axios");
756
- F(this, "filters");
757
- F(this, "steps");
758
- F(this, "fields");
759
- F(this, "already_limit", !1);
760
- F(this, "already_offset", !1);
761
- F(this, "limit", null);
762
- F(this, "offset", null);
763
- F(this, "_sort", null);
764
- F(this, "_sortDesc", !1);
765
- F(this, "meta", {});
766
- this.axios = r, this.filters = {}, this.steps = [], this.fields = e;
822
+ class g {
823
+ _batchData = null;
824
+ data_path = "";
825
+ filters;
826
+ steps;
827
+ fields;
828
+ already_limit = !1;
829
+ already_offset = !1;
830
+ limit = null;
831
+ offset = null;
832
+ _sort = null;
833
+ _sortDesc = !1;
834
+ meta = {};
835
+ constructor(e) {
836
+ this.filters = {}, this.steps = [], this.fields = e;
767
837
  }
768
838
  }
769
- _.prototype.getQueryPayload = function() {
839
+ g.prototype.getQueryPayload = function() {
770
840
  let t = {
771
841
  meta: {
772
842
  total: !0,
@@ -780,26 +850,26 @@ _.prototype.getQueryPayload = function() {
780
850
  steps: this.steps
781
851
  };
782
852
  };
783
- _.prototype.dataPath = function(t) {
853
+ g.prototype.dataPath = function(t) {
784
854
  const e = this.clone();
785
855
  return e.data_path = t, e;
786
856
  };
787
- _.prototype.buildArgs = function() {
857
+ g.prototype.buildArgs = function() {
788
858
  let t = {};
789
859
  return Object.keys(this.filters).length > 0 && (t.filters = this.filters), this._sort && (t.sort = this._sort, this._sortDesc && (t.sort += ":desc")), t;
790
860
  };
791
- _.prototype.clone = function() {
861
+ g.prototype.clone = function() {
792
862
  const t = Object.create(this);
793
863
  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;
794
864
  };
795
- P().macro("whereContains", function(t, e) {
865
+ M().macro("whereContains", function(t, e) {
796
866
  return this.filter((r) => r[t].toLowerCase().includes(e.toLowerCase()));
797
867
  });
798
- _.prototype.fetchData = async function() {
868
+ g.prototype.fetchData = async function() {
799
869
  try {
800
870
  if (this._batchData) {
801
- const l = this._batchData;
802
- return this.meta = l.meta, P(l.data);
871
+ const u = this._batchData;
872
+ return this.meta = u.meta, M(u.data);
803
873
  }
804
874
  let t = {
805
875
  meta: {
@@ -810,55 +880,55 @@ _.prototype.fetchData = async function() {
810
880
  };
811
881
  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);
812
882
  const e = this.data_path.split(".");
813
- let r = {}, s = r, i = e[e.length - 1];
814
- for (const l of e) {
815
- if (l === i) {
816
- s[l] = t;
883
+ let r = {}, n = r, i = e[e.length - 1];
884
+ for (const u of e) {
885
+ if (u === i) {
886
+ n[u] = t;
817
887
  break;
818
888
  }
819
- s[l] = {}, s = s[l];
889
+ n[u] = {}, n = n[u];
820
890
  }
821
- let f = await m(this.axios, r);
822
- for (const l of e)
823
- f = f[l];
824
- return this.meta = f.meta, P(f.data);
891
+ let a = await y(r);
892
+ for (const u of e)
893
+ a = a[u];
894
+ return this.meta = a.meta, M(a.data);
825
895
  } catch (t) {
826
896
  throw console.error("Error fetching collection data:", t), t;
827
897
  }
828
898
  };
829
- _.prototype.processData = async function() {
899
+ g.prototype.processData = async function() {
830
900
  let t = await this.fetchData();
831
901
  for (const e of this.steps)
832
902
  t = t[e.type](...e.args);
833
903
  return t;
834
904
  };
835
- _.prototype.all = async function() {
905
+ g.prototype.all = async function() {
836
906
  return (await this.processData()).all();
837
907
  };
838
- for (const t of x)
839
- _.prototype[t] = function(...e) {
908
+ for (const t of kt)
909
+ g.prototype[t] = function(...e) {
840
910
  const r = this.clone();
841
911
  return r.steps.push({ type: t, args: e }), r;
842
912
  };
843
- for (const t of tt)
844
- _.prototype[t] = async function(...e) {
913
+ for (const t of Ct)
914
+ g.prototype[t] = async function(...e) {
845
915
  return (await this.clone().processData())[t](...e);
846
916
  };
847
- _.prototype.average = _.prototype.avg;
848
- _.prototype.first = async function() {
917
+ g.prototype.average = g.prototype.avg;
918
+ g.prototype.first = async function() {
849
919
  return this.take(1), (await this.processData()).first();
850
920
  };
851
- _.prototype._handleBatchData = function(t, e) {
921
+ g.prototype._handleBatchData = function(t, e) {
852
922
  return this._batchData ? (this.steps.push({ type: t, args: e }), this) : null;
853
923
  };
854
- _.prototype.where = function(...t) {
924
+ g.prototype.where = function(...t) {
855
925
  const e = this._handleBatchData("where", t);
856
926
  if (e) return e;
857
927
  if (t.length === 2)
858
928
  this.filters[t[0]] = t[1];
859
929
  else if (t.length === 3) {
860
- const r = t[0], s = t[1], i = t[2];
861
- switch (s) {
930
+ const r = t[0], n = t[1], i = t[2];
931
+ switch (n) {
862
932
  case "==":
863
933
  this.filters[r] = i;
864
934
  break;
@@ -878,248 +948,170 @@ _.prototype.where = function(...t) {
878
948
  this.filters[r] = { ne: i };
879
949
  break;
880
950
  default:
881
- throw new Error(`Unsupported operator: ${s}`);
951
+ throw new Error(`Unsupported operator: ${n}`);
882
952
  }
883
953
  }
884
954
  return this;
885
955
  };
886
- _.prototype.whereContains = function(t, e) {
956
+ g.prototype.whereContains = function(t, e) {
887
957
  const r = this._handleBatchData("whereContains", [t, e]);
888
958
  return r || (this.filters[t] = { contains: e }, this);
889
959
  };
890
- _.prototype.forPage = function(t, e) {
960
+ g.prototype.forPage = function(t, e) {
891
961
  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);
892
962
  };
893
- _.prototype.whereIn = function(t, e) {
963
+ g.prototype.whereIn = function(t, e) {
894
964
  const r = this._handleBatchData("whereIn", [t, e]);
895
965
  return r || (this.filters[t] = { in: e }, this);
896
966
  };
897
- _.prototype.whereNotIn = function(t, e) {
967
+ g.prototype.whereNotIn = function(t, e) {
898
968
  const r = this._handleBatchData("whereNotIn", [t, e]);
899
969
  return r || (this.filters[t] = { nin: e }, this);
900
970
  };
901
- _.prototype.whereNotBetween = function(t, e) {
971
+ g.prototype.whereNotBetween = function(t, e) {
902
972
  const r = this._handleBatchData("whereNotBetween", [t, e]);
903
973
  return r || (this.filters[t] = { notBetween: e }, this);
904
974
  };
905
- _.prototype.whereBetween = function(t, e) {
975
+ g.prototype.whereBetween = function(t, e) {
906
976
  const r = this._handleBatchData("whereBetween", [t, e]);
907
977
  return r || (this.filters[t] = { between: e }, this);
908
978
  };
909
- _.prototype.sortBy = function(t) {
979
+ g.prototype.sortBy = function(t) {
910
980
  return this.steps.push({ type: "sortBy", args: [t] }), typeof t == "string" && (this._sort = t), this;
911
981
  };
912
- _.prototype.sortByDesc = function(t) {
982
+ g.prototype.sortByDesc = function(t) {
913
983
  return this.steps.push({ type: "sortByDesc", args: [t] }), typeof t == "string" && (this._sort = t, this._sortDesc = !0), this;
914
984
  };
915
- _.prototype.skip = function(t) {
985
+ g.prototype.skip = function(t) {
916
986
  if (t < 0)
917
987
  throw new Error("Offset must be non-negative");
918
988
  return this.already_offset && this.steps.push({ type: "skip", args: [t] }), this.offset = t, this.already_offset = !0, this;
919
989
  };
920
- _.prototype.take = function(t) {
990
+ g.prototype.take = function(t) {
921
991
  if (t < 0)
922
992
  throw new Error("Length must be non-negative");
923
993
  return this.already_limit ? (this.steps.push({ type: "take", args: [t] }), this) : (this.limit = t, this.already_limit = !0, this);
924
994
  };
925
- _.prototype.splice = function(t, e) {
995
+ g.prototype.splice = function(t, e) {
926
996
  return this.steps.push({ type: "splice", args: [t, e] }), this.offset = t, this.limit = e, this.already_limit = !0, this.already_offset = !0, this;
927
997
  };
928
- const R = (t, e, r) => {
929
- const s = new _(r, e);
930
- return s.data_path = Z + t, s;
931
- }, et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
998
+ 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({
932
1002
  __proto__: null,
933
1003
  default: R
934
- }, Symbol.toStringTag, { value: "Module" })), rt = (t, e) => ({
935
- uploadTempFile: (r) => d(e, "lightDriveUploadTempFile", {
936
- index: t,
937
- file: r
938
- }, {
939
- name: !0,
940
- path: !0,
941
- size: !0,
942
- mime: !0
943
- }),
944
- folders: {
945
- list: async (r, s = {
946
- name: !0,
947
- path: !0
948
- }) => (await m(e, {
949
- app: {
950
- drive: {
951
- __args: {
952
- index: t
953
- },
954
- folders: {
955
- __args: {
956
- path: r
957
- },
958
- ...s
959
- }
960
- }
961
- }
962
- })).app.drive.folders,
963
- create: (r) => d(e, "lightDriveCreateFolder", { index: t, path: r }),
964
- delete: (r) => d(e, "lightDriveDeleteFolder", { index: t, path: r }),
965
- rename: (r, s) => d(e, "lightDriveRenameFolder", { index: t, path: r, name: s })
966
- },
967
- files: {
968
- list: async (r, s = {
969
- name: !0,
970
- path: !0,
971
- size: !0,
972
- mime: !0,
973
- url: !0
974
- }) => (await m(e, {
975
- app: {
976
- drive: {
977
- __args: {
978
- index: t
979
- },
980
- files: {
981
- __args: {
982
- path: r
983
- },
984
- ...s
985
- }
986
- }
987
- }
988
- })).app.drive.files,
989
- get: async (r, s = {
990
- name: !0,
991
- path: !0,
992
- size: !0,
993
- mime: !0,
994
- url: !0
995
- }) => (await m(e, {
996
- app: {
997
- drive: {
998
- __args: {
999
- index: t
1000
- },
1001
- file: {
1002
- __args: {
1003
- path: r
1004
- },
1005
- ...s
1006
- }
1007
- }
1008
- }
1009
- })).app.drive.file,
1010
- read: async (r) => {
1011
- let s = await m(e, {
1012
- app: {
1013
- drive: {
1014
- __args: {
1015
- index: t
1016
- },
1017
- file: {
1018
- __args: {
1019
- path: r
1020
- },
1021
- base64Content: !0
1022
- }
1023
- }
1024
- }
1025
- });
1026
- if (!s.app.drive.file || !s.app.drive.file.base64Content)
1027
- throw new Error(`File not found or cannot read content: ${r}`);
1028
- return typeof window < "u" && window.atob ? window.atob(s.app.drive.file.base64Content) : s.app.drive.file.base64Content;
1029
- },
1030
- write: (r, s) => d(e, "lightDriveWriteFile", { index: t, path: r, content: s }),
1031
- delete: (r) => d(e, "lightDriveDeleteFile", { index: t, path: r }),
1032
- rename: (r, s) => d(e, "lightDriveRenameFile", { index: t, path: r, name: s }),
1033
- move: (r, s) => d(e, "lightDriveMoveFile", { index: t, source: r, destination: s })
1034
- }
1035
- }), ft = (t) => {
1004
+ }, Symbol.toStringTag, { value: "Module" })), Lt = (t) => {
1036
1005
  const e = typeof window > "u";
1037
1006
  let r = [];
1038
- const s = J.create({
1007
+ const n = H.create({
1039
1008
  baseURL: t,
1040
1009
  withCredentials: !0
1041
1010
  });
1042
- e && (s.interceptors.request.use((l) => (l.withCredentials = !0, r.length > 0 && (l.headers.Cookie = r.join("; ")), l)), s.interceptors.response.use((l) => {
1043
- if (l.headers["set-cookie"]) {
1044
- const p = l.headers["set-cookie"].map((o) => o.split(";")[0]), n = /* @__PURE__ */ new Map();
1011
+ e && (n.interceptors.request.use((a) => (a.withCredentials = !0, r.length > 0 && (a.headers.Cookie = r.join("; ")), a)), n.interceptors.response.use((a) => {
1012
+ if (a.headers["set-cookie"]) {
1013
+ const u = a.headers["set-cookie"].map((o) => o.split(";")[0]), s = /* @__PURE__ */ new Map();
1045
1014
  r.forEach((o) => {
1046
- const a = o.split("=")[0];
1047
- n.set(a, o);
1048
- }), p.forEach((o) => {
1049
- const a = o.split("=")[0];
1050
- n.set(a, o);
1051
- }), r = Array.from(n.values());
1015
+ const c = o.split("=")[0];
1016
+ s.set(c, o);
1017
+ }), u.forEach((o) => {
1018
+ const c = o.split("=")[0];
1019
+ s.set(c, o);
1020
+ }), r = Array.from(s.values());
1052
1021
  }
1053
- return l;
1022
+ return a;
1054
1023
  }));
1055
- const i = (l, p = null, n = []) => d(s, l, p, n), c = (l) => m(s, l), f = q(s);
1056
- return {
1024
+ const i = q(), f = {
1025
+ post: n.post,
1057
1026
  baseURL: t,
1058
- axios: s,
1059
- auth: $(s),
1060
- mutation: i,
1061
- query: c,
1062
- config: H(c),
1063
- mail: X(s),
1064
- users: V(s),
1065
- fs: G(s),
1066
- models: f,
1067
- model(l) {
1068
- return f.get(l);
1069
- },
1070
- roles: Y(s),
1071
- collect: (l, p) => {
1072
- const n = R(l, s, p);
1073
- return n.data_path = f.get(l).getDataPath(), n;
1027
+ axios: n,
1028
+ auth: at(),
1029
+ mutation: p,
1030
+ query: y,
1031
+ config: _t,
1032
+ mail: Ot,
1033
+ users: gt(),
1034
+ models: i,
1035
+ model(a) {
1036
+ return i.get(a);
1074
1037
  },
1075
- list: (l, p) => S(s, l, p).dataPath(f.get(l).getDataPath()),
1076
- drive(l) {
1077
- return rt(l, s);
1038
+ roles: Ft(),
1039
+ collect: (a, u) => {
1040
+ const s = R(a, u);
1041
+ return s.data_path = i.get(a).getDataPath(), s;
1078
1042
  },
1079
- async collects(l) {
1080
- const p = {}, n = {};
1081
- for (const a in l) {
1082
- const u = l[a].getQueryPayload();
1083
- n[a] = u.data_path, p[a] = {};
1084
- const h = u.data_path.split(".");
1085
- let g = h[h.length - 1], y = p[a];
1043
+ list: (a, u) => U(a, u).dataPath(i.get(a).getDataPath()),
1044
+ drive: ut,
1045
+ async collects(a) {
1046
+ const u = {}, s = {};
1047
+ for (const c in a) {
1048
+ const l = a[c].getQueryPayload();
1049
+ s[c] = l.data_path, u[c] = {};
1050
+ const h = l.data_path.split(".");
1051
+ let _ = h[h.length - 1], d = u[c];
1086
1052
  for (const w of h) {
1087
- if (w === g) {
1088
- y[w] = u.query;
1053
+ if (w === _) {
1054
+ d[w] = l.query;
1089
1055
  break;
1090
1056
  }
1091
- y[w] = y[w] || {};
1057
+ d[w] = d[w] || {};
1092
1058
  }
1093
- p[a].__aliasFor = h[0];
1059
+ u[c].__aliasFor = h[0];
1094
1060
  }
1095
- const o = await m(s, p);
1096
- for (const a in l) {
1097
- const u = n[a].split(".");
1098
- let h = u[u.length - 1], g = o[a];
1099
- for (const y of u) {
1100
- if (y === h) {
1101
- l[a]._batchData = o[a][y];
1061
+ const o = await y(u);
1062
+ for (const c in a) {
1063
+ const l = s[c].split(".");
1064
+ 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];
1102
1068
  break;
1103
1069
  }
1104
- g[y] = g[y] || {};
1070
+ _[d] = _[d] || {};
1105
1071
  }
1106
1072
  }
1107
- return l;
1073
+ return a;
1108
1074
  }
1109
1075
  };
1076
+ return Y(f), f;
1110
1077
  };
1111
1078
  export {
1112
- ut as File,
1113
- ft as createClient,
1079
+ at as auth,
1080
+ et as changeExpiredPassword,
1081
+ Lt as createClient,
1114
1082
  R as createCollection,
1115
- S as createList,
1083
+ U as createList,
1116
1084
  q as createModelManager,
1117
- k as file,
1118
- d as mutation,
1119
- m as query,
1120
- E as toQuery,
1121
- lt as useGlobalModel,
1122
- ct as useGlobalModels,
1123
- ot as useModel,
1124
- I as useWebAuthn
1085
+ bt as createRole,
1086
+ ht as createUser,
1087
+ G as defaultUserFields,
1088
+ mt as deleteRole,
1089
+ ft as deleteUser,
1090
+ nt as forgetPassword,
1091
+ N as getApiClient,
1092
+ Ut as getApiClientOptional,
1093
+ _t as getConfig,
1094
+ 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,
1102
+ x as login,
1103
+ tt as logout,
1104
+ p as mutation,
1105
+ y as query,
1106
+ st as resetPassword,
1107
+ At as sendMail,
1108
+ Y as setApiClient,
1109
+ Dt as toQuery,
1110
+ rt as updatePassword,
1111
+ dt as updateUser,
1112
+ vt as useGlobalModel,
1113
+ Nt as useGlobalModels,
1114
+ qt as useModel,
1115
+ ot as verifyCode,
1116
+ K as webAuthn
1125
1117
  };