@hostlink/light 2.13.0 → 2.13.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 +166 -166
- package/dist/light.umd.cjs +1 -1
- package/dist/model.d.ts +5 -10
- package/package.json +1 -1
package/dist/light.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var U = Object.defineProperty;
|
|
2
2
|
var L = (t, e, r) => e in t ? U(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
3
|
var F = (t, e, r) => L(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
-
import { jsonToGraphQLQuery as
|
|
4
|
+
import { jsonToGraphQLQuery as B, VariableType as C } from "json-to-graphql-query";
|
|
5
5
|
import J from "axios";
|
|
6
6
|
import P from "collect.js";
|
|
7
7
|
const I = (t) => ({
|
|
@@ -12,7 +12,7 @@ const I = (t) => ({
|
|
|
12
12
|
webAuthnRequestOptions: !0
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
}),
|
|
15
|
+
}), i = s.auth.webAuthnRequestOptions, c = PublicKeyCredential.parseRequestOptionsFromJSON(i);
|
|
16
16
|
return await navigator.credentials.get({ publicKey: c });
|
|
17
17
|
},
|
|
18
18
|
attestation: async () => {
|
|
@@ -22,8 +22,8 @@ const I = (t) => ({
|
|
|
22
22
|
webAuthnCreationOptions: !0
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
}),
|
|
26
|
-
return await navigator.credentials.create({ publicKey:
|
|
25
|
+
}), i = PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);
|
|
26
|
+
return await navigator.credentials.create({ publicKey: i });
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
function D(t) {
|
|
@@ -35,19 +35,19 @@ function D(t) {
|
|
|
35
35
|
function v(t, e, r = ".", s) {
|
|
36
36
|
if (!D(e))
|
|
37
37
|
return v(t, {}, r, s);
|
|
38
|
-
const
|
|
38
|
+
const i = Object.assign({}, e);
|
|
39
39
|
for (const c in t) {
|
|
40
40
|
if (c === "__proto__" || c === "constructor")
|
|
41
41
|
continue;
|
|
42
42
|
const f = t[c];
|
|
43
|
-
f != null && (s && s(
|
|
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
44
|
f,
|
|
45
|
-
|
|
45
|
+
i[c],
|
|
46
46
|
(r ? `${r}.` : "") + c.toString(),
|
|
47
47
|
s
|
|
48
|
-
) :
|
|
48
|
+
) : i[c] = f));
|
|
49
49
|
}
|
|
50
|
-
return
|
|
50
|
+
return i;
|
|
51
51
|
}
|
|
52
52
|
function T(t) {
|
|
53
53
|
return (...e) => (
|
|
@@ -58,8 +58,8 @@ function T(t) {
|
|
|
58
58
|
const A = T(), M = (t) => {
|
|
59
59
|
let e = {};
|
|
60
60
|
return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
|
|
61
|
-
Object.entries(M(r)).forEach(([s,
|
|
62
|
-
e[s] =
|
|
61
|
+
Object.entries(M(r)).forEach(([s, i]) => {
|
|
62
|
+
e[s] = i;
|
|
63
63
|
});
|
|
64
64
|
}), e) : (Object.entries(t).forEach(([r, s]) => {
|
|
65
65
|
if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
|
|
@@ -73,7 +73,7 @@ const A = T(), M = (t) => {
|
|
|
73
73
|
e[r] = M(s);
|
|
74
74
|
}), e);
|
|
75
75
|
}, E = (t) => M(t), m = async (t, e) => {
|
|
76
|
-
let r =
|
|
76
|
+
let r = B(E(e));
|
|
77
77
|
const s = await t.post("", {
|
|
78
78
|
query: `{ ${r} }`
|
|
79
79
|
});
|
|
@@ -82,8 +82,8 @@ const A = T(), M = (t) => {
|
|
|
82
82
|
return s.data.data;
|
|
83
83
|
};
|
|
84
84
|
function S(t, e, r) {
|
|
85
|
-
let s,
|
|
86
|
-
const l = (
|
|
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]);
|
|
87
87
|
return {
|
|
88
88
|
first() {
|
|
89
89
|
return this.fetchFirst();
|
|
@@ -98,8 +98,8 @@ function S(t, e, r) {
|
|
|
98
98
|
async fetchWithMeta() {
|
|
99
99
|
let o = await m(t, this.toQuery(!0));
|
|
100
100
|
if (f) {
|
|
101
|
-
const
|
|
102
|
-
for (const u of
|
|
101
|
+
const a = f.split(".");
|
|
102
|
+
for (const u of a)
|
|
103
103
|
o = o[u];
|
|
104
104
|
return o;
|
|
105
105
|
}
|
|
@@ -108,27 +108,27 @@ function S(t, e, r) {
|
|
|
108
108
|
async fetch() {
|
|
109
109
|
let o = await m(t, this.toQuery());
|
|
110
110
|
if (f) {
|
|
111
|
-
const
|
|
112
|
-
for (const u of
|
|
111
|
+
const a = f.split(".");
|
|
112
|
+
for (const u of a)
|
|
113
113
|
o = o[u];
|
|
114
114
|
return o.data;
|
|
115
115
|
}
|
|
116
116
|
return o[`list${e}`].data;
|
|
117
117
|
},
|
|
118
|
-
dataPath(
|
|
119
|
-
return
|
|
118
|
+
dataPath(n) {
|
|
119
|
+
return n && typeof n == "string" && (f = n), this;
|
|
120
120
|
},
|
|
121
|
-
sort(
|
|
122
|
-
return
|
|
121
|
+
sort(n) {
|
|
122
|
+
return n && typeof n == "string" && (c = n), this;
|
|
123
123
|
},
|
|
124
|
-
filters(
|
|
125
|
-
return
|
|
124
|
+
filters(n) {
|
|
125
|
+
return n && typeof n == "object" && (i = [n]), this;
|
|
126
126
|
},
|
|
127
127
|
// where can be called as:
|
|
128
128
|
// where('key', value) -> exact match
|
|
129
129
|
// where('key', '>', value) -> operator-based (>, <, >=, <=, !=, in, contains)
|
|
130
|
-
where(
|
|
131
|
-
const u = (
|
|
130
|
+
where(n, o, a) {
|
|
131
|
+
const u = (h, g, y) => {
|
|
132
132
|
const b = {
|
|
133
133
|
">": "_gt",
|
|
134
134
|
"<": "_lt",
|
|
@@ -138,55 +138,55 @@ function S(t, e, r) {
|
|
|
138
138
|
in: "_in",
|
|
139
139
|
contains: "_contains"
|
|
140
140
|
}[g];
|
|
141
|
-
b &&
|
|
141
|
+
b && i.push({ [h]: { [b]: y } });
|
|
142
142
|
};
|
|
143
|
-
if (
|
|
144
|
-
u(
|
|
143
|
+
if (a !== void 0)
|
|
144
|
+
u(n, String(o), a);
|
|
145
145
|
else {
|
|
146
|
-
const
|
|
147
|
-
|
|
146
|
+
const h = p(), g = A(h, { [n]: o });
|
|
147
|
+
i[0] = g;
|
|
148
148
|
}
|
|
149
149
|
return this;
|
|
150
150
|
},
|
|
151
151
|
// whereContains adds a _contains filter for a specific field
|
|
152
152
|
// If the same field is used multiple times, it merges them into an array
|
|
153
|
-
whereContains(
|
|
154
|
-
if (
|
|
155
|
-
const
|
|
156
|
-
|
|
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;
|
|
157
157
|
}
|
|
158
158
|
return this;
|
|
159
159
|
},
|
|
160
160
|
// ...existing code...
|
|
161
161
|
// whereIn adds an _in filter for a specific field
|
|
162
162
|
// If the same field is used multiple times, it merges them into an array
|
|
163
|
-
whereIn(
|
|
164
|
-
if (
|
|
165
|
-
const
|
|
166
|
-
|
|
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;
|
|
167
167
|
}
|
|
168
168
|
return this;
|
|
169
169
|
},
|
|
170
170
|
// whereBetween adds a _between filter for a specific field
|
|
171
|
-
whereBetween(
|
|
172
|
-
if (
|
|
173
|
-
const u =
|
|
174
|
-
u[
|
|
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;
|
|
175
175
|
}
|
|
176
176
|
return this;
|
|
177
177
|
},
|
|
178
178
|
// limit sets paging/limit for the data selection
|
|
179
|
-
limit(
|
|
180
|
-
return typeof
|
|
179
|
+
limit(n) {
|
|
180
|
+
return typeof n == "number" && Number.isFinite(n) && (s = A(s || {}, { limit: n })), this;
|
|
181
181
|
},
|
|
182
182
|
// offset sets the starting index for the data selection
|
|
183
|
-
offset(
|
|
184
|
-
return typeof
|
|
183
|
+
offset(n) {
|
|
184
|
+
return typeof n == "number" && Number.isFinite(n) && (s = A(s || {}, { offset: n })), this;
|
|
185
185
|
},
|
|
186
|
-
toQuery(
|
|
186
|
+
toQuery(n = !1) {
|
|
187
187
|
let o;
|
|
188
|
-
const
|
|
189
|
-
|
|
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
190
|
const g = A(
|
|
191
191
|
c ? { sort: c } : {},
|
|
192
192
|
o ? { filters: o } : {}
|
|
@@ -195,7 +195,7 @@ function S(t, e, r) {
|
|
|
195
195
|
...r
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
|
-
if (s && (y.data.__args = s), Object.keys(g).length > 0 && (y.__args = g),
|
|
198
|
+
if (s && (y.data.__args = s), Object.keys(g).length > 0 && (y.__args = g), n && (y.meta = {
|
|
199
199
|
total: !0,
|
|
200
200
|
key: !0,
|
|
201
201
|
name: !0
|
|
@@ -214,60 +214,60 @@ function S(t, e, r) {
|
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
216
|
}
|
|
217
|
-
const
|
|
218
|
-
const s = e,
|
|
217
|
+
const N = (t, e, r) => {
|
|
218
|
+
const s = e, i = t, c = r;
|
|
219
219
|
let f = "list" + e;
|
|
220
|
-
const l = (
|
|
220
|
+
const l = (p) => c[p] ? c[p] : null;
|
|
221
221
|
return {
|
|
222
222
|
field: l,
|
|
223
223
|
$fields: c,
|
|
224
|
-
setDataPath(
|
|
225
|
-
return f =
|
|
224
|
+
setDataPath(p) {
|
|
225
|
+
return f = p, f;
|
|
226
226
|
},
|
|
227
227
|
getDataPath() {
|
|
228
228
|
return f;
|
|
229
229
|
},
|
|
230
|
-
gqlFields(
|
|
231
|
-
let
|
|
232
|
-
for (const o of
|
|
230
|
+
gqlFields(p) {
|
|
231
|
+
let n = {};
|
|
232
|
+
for (const o of p)
|
|
233
233
|
if (typeof o == "string") {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
} else typeof o == "object" && (
|
|
237
|
-
return
|
|
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;
|
|
238
238
|
},
|
|
239
|
-
async update(
|
|
240
|
-
return await d(
|
|
239
|
+
async update(p, n) {
|
|
240
|
+
return await d(i, "update" + s, { id: p, data: n });
|
|
241
241
|
},
|
|
242
|
-
async delete(
|
|
243
|
-
return await d(
|
|
242
|
+
async delete(p) {
|
|
243
|
+
return await d(i, "delete" + s, { id: p });
|
|
244
244
|
},
|
|
245
|
-
async add(
|
|
246
|
-
return await d(
|
|
245
|
+
async add(p) {
|
|
246
|
+
return await d(i, "add" + s, { data: p });
|
|
247
247
|
},
|
|
248
|
-
fields(
|
|
249
|
-
let
|
|
250
|
-
for (let o of
|
|
251
|
-
const
|
|
252
|
-
|
|
248
|
+
fields(p) {
|
|
249
|
+
let n = [];
|
|
250
|
+
for (let o of p) {
|
|
251
|
+
const a = l(o);
|
|
252
|
+
a && n.push(a);
|
|
253
253
|
}
|
|
254
|
-
return
|
|
254
|
+
return n;
|
|
255
255
|
},
|
|
256
|
-
async get(
|
|
257
|
-
const o = (await Promise.resolve().then(() => et)).default,
|
|
258
|
-
for (const [u,
|
|
259
|
-
|
|
260
|
-
return await
|
|
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();
|
|
261
261
|
},
|
|
262
|
-
list(
|
|
263
|
-
let
|
|
262
|
+
list(p) {
|
|
263
|
+
let n = p;
|
|
264
264
|
const o = {};
|
|
265
|
-
Object.entries(
|
|
266
|
-
c[
|
|
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]));
|
|
267
267
|
});
|
|
268
|
-
const
|
|
268
|
+
const a = S(i, s, n).dataPath(f), u = a.fetch.bind(a);
|
|
269
269
|
return {
|
|
270
|
-
...
|
|
270
|
+
...a,
|
|
271
271
|
async fetch() {
|
|
272
272
|
return (await u()).map((g) => {
|
|
273
273
|
const y = { ...g };
|
|
@@ -277,7 +277,7 @@ const q = (t, e, r) => {
|
|
|
277
277
|
});
|
|
278
278
|
},
|
|
279
279
|
async fetchFirst() {
|
|
280
|
-
const g = await
|
|
280
|
+
const g = await a.fetchFirst.bind(a)();
|
|
281
281
|
if (!g) return g;
|
|
282
282
|
const y = { ...g };
|
|
283
283
|
return Object.entries(o).forEach(([w, b]) => {
|
|
@@ -287,7 +287,7 @@ const q = (t, e, r) => {
|
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
};
|
|
290
|
-
}, O = {},
|
|
290
|
+
}, O = {}, q = (t, e = !1) => {
|
|
291
291
|
const r = t, s = {};
|
|
292
292
|
return {
|
|
293
293
|
/**
|
|
@@ -295,43 +295,43 @@ const q = (t, e, r) => {
|
|
|
295
295
|
* @param name 模型名稱
|
|
296
296
|
* @param fields 模型欄位定義
|
|
297
297
|
*/
|
|
298
|
-
create(
|
|
299
|
-
const f =
|
|
300
|
-
s[
|
|
298
|
+
create(i, c) {
|
|
299
|
+
const f = N(r, i, c);
|
|
300
|
+
s[i] = f, e && (O[i] = f);
|
|
301
301
|
},
|
|
302
302
|
/**
|
|
303
303
|
* 獲取模型
|
|
304
304
|
* @param name 模型名稱
|
|
305
305
|
* @returns 模型實例
|
|
306
306
|
*/
|
|
307
|
-
get(
|
|
308
|
-
return s[
|
|
307
|
+
get(i) {
|
|
308
|
+
return s[i] || (e && O[i] ? s[i] = O[i] : this.create(i, {})), s[i];
|
|
309
309
|
},
|
|
310
310
|
/**
|
|
311
311
|
* 檢查模型是否存在
|
|
312
312
|
* @param name 模型名稱
|
|
313
313
|
* @returns 是否存在
|
|
314
314
|
*/
|
|
315
|
-
has(
|
|
316
|
-
return !!s[
|
|
315
|
+
has(i) {
|
|
316
|
+
return !!s[i] || e && !!O[i];
|
|
317
317
|
},
|
|
318
318
|
/**
|
|
319
319
|
* 列出所有模型名稱
|
|
320
320
|
* @returns 模型名稱陣列
|
|
321
321
|
*/
|
|
322
322
|
list() {
|
|
323
|
-
const
|
|
324
|
-
return [.../* @__PURE__ */ new Set([...
|
|
323
|
+
const i = Object.keys(s), c = e ? Object.keys(O) : [];
|
|
324
|
+
return [.../* @__PURE__ */ new Set([...i, ...c])];
|
|
325
325
|
},
|
|
326
326
|
/**
|
|
327
327
|
* 清除所有模型
|
|
328
328
|
*/
|
|
329
329
|
clear() {
|
|
330
|
-
Object.keys(s).forEach((
|
|
330
|
+
Object.keys(s).forEach((i) => delete s[i]);
|
|
331
331
|
}
|
|
332
332
|
};
|
|
333
333
|
}, ot = (t) => {
|
|
334
|
-
const e =
|
|
334
|
+
const e = q(t, !1);
|
|
335
335
|
return {
|
|
336
336
|
// 暴露完整的管理器
|
|
337
337
|
manager: e,
|
|
@@ -355,13 +355,13 @@ const q = (t, e, r) => {
|
|
|
355
355
|
* @param models 模型定義對象
|
|
356
356
|
*/
|
|
357
357
|
defineModels(r) {
|
|
358
|
-
Object.entries(r).forEach(([s,
|
|
359
|
-
e.create(s,
|
|
358
|
+
Object.entries(r).forEach(([s, i]) => {
|
|
359
|
+
e.create(s, i);
|
|
360
360
|
});
|
|
361
361
|
}
|
|
362
362
|
};
|
|
363
363
|
}, lt = (t) => {
|
|
364
|
-
const e =
|
|
364
|
+
const e = q(t, !0);
|
|
365
365
|
return {
|
|
366
366
|
// 暴露完整的管理器
|
|
367
367
|
manager: e,
|
|
@@ -385,8 +385,8 @@ const q = (t, e, r) => {
|
|
|
385
385
|
* @param models 模型定義對象
|
|
386
386
|
*/
|
|
387
387
|
defineModels(r) {
|
|
388
|
-
Object.entries(r).forEach(([s,
|
|
389
|
-
e.create(s,
|
|
388
|
+
Object.entries(r).forEach(([s, i]) => {
|
|
389
|
+
e.create(s, i);
|
|
390
390
|
});
|
|
391
391
|
}
|
|
392
392
|
};
|
|
@@ -397,7 +397,7 @@ const q = (t, e, r) => {
|
|
|
397
397
|
* @param fields 模型欄位定義
|
|
398
398
|
*/
|
|
399
399
|
define(e, r) {
|
|
400
|
-
const s =
|
|
400
|
+
const s = N(t, e, r);
|
|
401
401
|
return O[e] = s, s;
|
|
402
402
|
},
|
|
403
403
|
/**
|
|
@@ -519,26 +519,26 @@ const q = (t, e, r) => {
|
|
|
519
519
|
});
|
|
520
520
|
function Q(t) {
|
|
521
521
|
t = "<~" + t + "~>";
|
|
522
|
-
var e, r, s,
|
|
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 = [],
|
|
524
|
-
return function(
|
|
525
|
-
for (var o =
|
|
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
526
|
}(s, e.length), f.fromCharCode.apply(f, s);
|
|
527
527
|
}
|
|
528
528
|
const k = (t = "") => {
|
|
529
529
|
const e = t, r = (s = "application/octet-stream") => {
|
|
530
|
-
const
|
|
530
|
+
const i = new Uint8Array(e.length);
|
|
531
531
|
for (let l = 0; l < e.length; l++)
|
|
532
|
-
|
|
533
|
-
const c = new Blob([
|
|
532
|
+
i[l] = e.charCodeAt(l);
|
|
533
|
+
const c = new Blob([i], { type: s });
|
|
534
534
|
return URL.createObjectURL(c);
|
|
535
535
|
};
|
|
536
536
|
return {
|
|
537
537
|
getContent: () => e,
|
|
538
538
|
getURL: r,
|
|
539
539
|
download: (s) => {
|
|
540
|
-
const
|
|
541
|
-
|
|
540
|
+
const i = document.createElement("a");
|
|
541
|
+
i.download = s, i.href = r(), document.body.appendChild(i), i.click(), document.body.removeChild(i);
|
|
542
542
|
},
|
|
543
543
|
open: (s) => {
|
|
544
544
|
window.open(r(s), "_blank");
|
|
@@ -562,35 +562,35 @@ function z(t) {
|
|
|
562
562
|
return !1;
|
|
563
563
|
}
|
|
564
564
|
const d = async (t, e, r = null, s = []) => {
|
|
565
|
-
let
|
|
565
|
+
let i = {
|
|
566
566
|
[e]: {}
|
|
567
567
|
};
|
|
568
568
|
const c = new FormData();
|
|
569
569
|
let f = !1;
|
|
570
570
|
if (r) {
|
|
571
|
-
const
|
|
571
|
+
const n = {}, o = {}, a = {};
|
|
572
572
|
let u = 0;
|
|
573
|
-
Object.entries(r).forEach(([
|
|
573
|
+
Object.entries(r).forEach(([h, g]) => {
|
|
574
574
|
if (g instanceof Array && K(g)) {
|
|
575
575
|
f = !0;
|
|
576
576
|
let y = 0;
|
|
577
577
|
g.forEach((w) => {
|
|
578
|
-
w instanceof File && (
|
|
579
|
-
}),
|
|
580
|
-
} else g instanceof File ? (f = !0,
|
|
581
|
-
w instanceof File ? (
|
|
582
|
-
})) : g !== void 0 && (
|
|
583
|
-
}),
|
|
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
584
|
}
|
|
585
|
-
Object.entries(E(s)).forEach(([
|
|
586
|
-
|
|
587
|
-
}), Object.entries(
|
|
585
|
+
Object.entries(E(s)).forEach(([n, o]) => {
|
|
586
|
+
i[e][n] = o;
|
|
587
|
+
}), Object.entries(i[e]).length === 0 && (i[e] = !0);
|
|
588
588
|
let l = null;
|
|
589
|
-
const
|
|
589
|
+
const p = B({ mutation: i });
|
|
590
590
|
if (f ? (c.append("operations", JSON.stringify({
|
|
591
|
-
query:
|
|
591
|
+
query: p
|
|
592
592
|
})), l = await t.post("", c)) : l = await t.post("", {
|
|
593
|
-
query:
|
|
593
|
+
query: p
|
|
594
594
|
}), l.data.errors)
|
|
595
595
|
throw new Error(l.data.errors[0].message);
|
|
596
596
|
return l.data.data[e];
|
|
@@ -810,9 +810,9 @@ _.prototype.fetchData = async function() {
|
|
|
810
810
|
};
|
|
811
811
|
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
812
|
const e = this.data_path.split(".");
|
|
813
|
-
let r = {}, s = r,
|
|
813
|
+
let r = {}, s = r, i = e[e.length - 1];
|
|
814
814
|
for (const l of e) {
|
|
815
|
-
if (l ===
|
|
815
|
+
if (l === i) {
|
|
816
816
|
s[l] = t;
|
|
817
817
|
break;
|
|
818
818
|
}
|
|
@@ -857,25 +857,25 @@ _.prototype.where = function(...t) {
|
|
|
857
857
|
if (t.length === 2)
|
|
858
858
|
this.filters[t[0]] = t[1];
|
|
859
859
|
else if (t.length === 3) {
|
|
860
|
-
const r = t[0], s = t[1],
|
|
860
|
+
const r = t[0], s = t[1], i = t[2];
|
|
861
861
|
switch (s) {
|
|
862
862
|
case "==":
|
|
863
|
-
this.filters[r] =
|
|
863
|
+
this.filters[r] = i;
|
|
864
864
|
break;
|
|
865
865
|
case "<":
|
|
866
|
-
this.filters[r] = { lt:
|
|
866
|
+
this.filters[r] = { lt: i };
|
|
867
867
|
break;
|
|
868
868
|
case "<=":
|
|
869
|
-
this.filters[r] = { lte:
|
|
869
|
+
this.filters[r] = { lte: i };
|
|
870
870
|
break;
|
|
871
871
|
case ">":
|
|
872
|
-
this.filters[r] = { gt:
|
|
872
|
+
this.filters[r] = { gt: i };
|
|
873
873
|
break;
|
|
874
874
|
case ">=":
|
|
875
|
-
this.filters[r] = { gte:
|
|
875
|
+
this.filters[r] = { gte: i };
|
|
876
876
|
break;
|
|
877
877
|
case "!==":
|
|
878
|
-
this.filters[r] = { ne:
|
|
878
|
+
this.filters[r] = { ne: i };
|
|
879
879
|
break;
|
|
880
880
|
default:
|
|
881
881
|
throw new Error(`Unsupported operator: ${s}`);
|
|
@@ -1041,23 +1041,23 @@ const R = (t, e, r) => {
|
|
|
1041
1041
|
});
|
|
1042
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
1043
|
if (l.headers["set-cookie"]) {
|
|
1044
|
-
const
|
|
1044
|
+
const p = l.headers["set-cookie"].map((o) => o.split(";")[0]), n = /* @__PURE__ */ new Map();
|
|
1045
1045
|
r.forEach((o) => {
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1048
|
-
}),
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1051
|
-
}), r = Array.from(
|
|
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());
|
|
1052
1052
|
}
|
|
1053
1053
|
return l;
|
|
1054
1054
|
}));
|
|
1055
|
-
const
|
|
1055
|
+
const i = (l, p = null, n = []) => d(s, l, p, n), c = (l) => m(s, l), f = q(s);
|
|
1056
1056
|
return {
|
|
1057
1057
|
baseURL: t,
|
|
1058
1058
|
axios: s,
|
|
1059
1059
|
auth: $(s),
|
|
1060
|
-
mutation:
|
|
1060
|
+
mutation: i,
|
|
1061
1061
|
query: c,
|
|
1062
1062
|
config: H(c),
|
|
1063
1063
|
mail: X(s),
|
|
@@ -1068,37 +1068,37 @@ const R = (t, e, r) => {
|
|
|
1068
1068
|
return f.get(l);
|
|
1069
1069
|
},
|
|
1070
1070
|
roles: Y(s),
|
|
1071
|
-
collect: (l,
|
|
1072
|
-
const
|
|
1073
|
-
return
|
|
1071
|
+
collect: (l, p) => {
|
|
1072
|
+
const n = R(l, s, p);
|
|
1073
|
+
return n.data_path = f.get(l).getDataPath(), n;
|
|
1074
1074
|
},
|
|
1075
|
-
list: (l,
|
|
1075
|
+
list: (l, p) => S(s, l, p).dataPath(f.get(l).getDataPath()),
|
|
1076
1076
|
drive(l) {
|
|
1077
1077
|
return rt(l, s);
|
|
1078
1078
|
},
|
|
1079
1079
|
async collects(l) {
|
|
1080
|
-
const
|
|
1081
|
-
for (const
|
|
1082
|
-
const u = l[
|
|
1083
|
-
a
|
|
1084
|
-
const
|
|
1085
|
-
let g =
|
|
1086
|
-
for (const w of
|
|
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];
|
|
1086
|
+
for (const w of h) {
|
|
1087
1087
|
if (w === g) {
|
|
1088
1088
|
y[w] = u.query;
|
|
1089
1089
|
break;
|
|
1090
1090
|
}
|
|
1091
1091
|
y[w] = y[w] || {};
|
|
1092
1092
|
}
|
|
1093
|
-
|
|
1093
|
+
p[a].__aliasFor = h[0];
|
|
1094
1094
|
}
|
|
1095
|
-
const o = await m(s,
|
|
1096
|
-
for (const
|
|
1097
|
-
const u = a
|
|
1098
|
-
let
|
|
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
1099
|
for (const y of u) {
|
|
1100
|
-
if (y ===
|
|
1101
|
-
l[
|
|
1100
|
+
if (y === h) {
|
|
1101
|
+
l[a]._batchData = o[a][y];
|
|
1102
1102
|
break;
|
|
1103
1103
|
}
|
|
1104
1104
|
g[y] = g[y] || {};
|
|
@@ -1113,7 +1113,7 @@ export {
|
|
|
1113
1113
|
ft as createClient,
|
|
1114
1114
|
R as createCollection,
|
|
1115
1115
|
S as createList,
|
|
1116
|
-
|
|
1116
|
+
q as createModelManager,
|
|
1117
1117
|
k as file,
|
|
1118
1118
|
d as mutation,
|
|
1119
1119
|
m as query,
|
package/dist/light.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(_,b){typeof exports=="object"&&typeof module<"u"?b(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"],b):(_=typeof globalThis<"u"?globalThis:_||self,b(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,b,D,E){"use strict";var at=Object.defineProperty;var ot=(_,b,D)=>b in _?at(_,b,{enumerable:!0,configurable:!0,writable:!0,value:D}):_[b]=D;var A=(_,b,D)=>ot(_,typeof b!="symbol"?b+"":b,D);const L=t=>({assertion:async()=>{const{app:s}=await O(t,{app:{auth:{webAuthnRequestOptions:!0}}}),n=s.auth.webAuthnRequestOptions,c=PublicKeyCredential.parseRequestOptionsFromJSON(n);return await navigator.credentials.get({publicKey:c})},attestation:async()=>{const{app:s}=await O(t,{app:{auth:{webAuthnCreationOptions:!0}}}),n=PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:n})}});function S(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 q(t,e,r=".",s){if(!S(e))return q(t,{},r,s);const n=Object.assign({},e);for(const c in t){if(c==="__proto__"||c==="constructor")continue;const f=t[c];f!=null&&(s&&s(n,c,f,r)||(Array.isArray(f)&&Array.isArray(n[c])?n[c]=[...f,...n[c]]:S(f)&&S(n[c])?n[c]=q(f,n[c],(r?`${r}.`:"")+c.toString(),s):n[c]=f))}return n}function J(t){return(...e)=>e.reduce((r,s)=>q(r,s,"",t),{})}const C=J(),B=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(B(r)).forEach(([s,n])=>{e[s]=n})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=B(s)}),e)},k=t=>B(t),O=async(t,e)=>{let r=b.jsonToGraphQLQuery(k(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function M(t,e,r){let s,n=[],c,f;const l=i=>!i||typeof i!="object"?!1:Object.values(i).some(o=>o&&typeof o=="object"&&Object.keys(o).some(a=>a.startsWith("_"))),h=()=>n.length===0?(n.unshift({}),n[0]):(l(n[0])&&n.unshift({}),n[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const o=await this.limit(1).fetch();return Array.isArray(o)&&o.length>0?o[0]:null},async fetchWithMeta(){let o=await O(t,this.toQuery(!0));if(f){const a=f.split(".");for(const u of a)o=o[u];return o}return o[`list${e}`]},async fetch(){let o=await O(t,this.toQuery());if(f){const a=f.split(".");for(const u of a)o=o[u];return o.data}return o[`list${e}`].data},dataPath(i){return i&&typeof i=="string"&&(f=i),this},sort(i){return i&&typeof i=="string"&&(c=i),this},filters(i){return i&&typeof i=="object"&&(n=[i]),this},where(i,o,a){const u=(p,g,y)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[g];F&&n.push({[p]:{[F]:y}})};if(a!==void 0)u(i,String(o),a);else{const p=h(),g=C(p,{[i]:o});n[0]=g}return this},whereContains(i,o){if(i&&typeof i=="string"){const a=h(),u={_contains:o};a[i]?Array.isArray(a[i])?a[i].push(u):a[i]=[a[i],u]:a[i]=[u],n[0]=a}return this},whereIn(i,o){if(i&&typeof i=="string"&&Array.isArray(o)){const a=h(),u={_in:o};a[i]?Array.isArray(a[i])?a[i].push(u):a[i]=[a[i],u]:a[i]=[u],n[0]=a}return this},whereBetween(i,o,a){if(i&&typeof i=="string"){const u=h(),p={_between:[o,a]};u[i]?Array.isArray(u[i])?u[i].push(p):u[i]=[u[i],p]:u[i]=p,n[0]=u}return this},limit(i){return typeof i=="number"&&Number.isFinite(i)&&(s=C(s||{},{limit:i})),this},offset(i){return typeof i=="number"&&Number.isFinite(i)&&(s=C(s||{},{offset:i})),this},toQuery(i=!1){let o;const a=n.length>0&&Object.keys(n[0]||{}).length>0,u=a?1:0,p=n.length>u;a&&p?o=n:p?o=n.slice(u):a&&(o=n[0]);const g=C(c?{sort:c}:{},o?{filters:o}:{}),y={data:{...r}};if(s&&(y.data.__args=s),Object.keys(g).length>0&&(y.__args=g),i&&(y.meta={total:!0,key:!0,name:!0}),f){const m=f.split(".");let F=y;for(let R=m.length-1;R>=0;R--)F={[m[R]]:F};return F}return{[`list${e}`]:y}}}}const U=(t,e,r)=>{const s=e,n=t,c=r;let f="list"+e;const l=h=>c[h]?c[h]:null;return{field:l,$fields:c,setDataPath(h){return f=h,f},getDataPath(){return f},gqlFields(h){let i={};for(const o of h)if(typeof o=="string"){const a=l(o);a&&(i=C(i,a.gqlField?typeof a.gqlField=="string"?{[a.gqlField]:!0}:a.gqlField:{[a.name||o]:!0}))}else typeof o=="object"&&(i=C(i,o));return i},async update(h,i){return await d(n,"update"+s,{id:h,data:i})},async delete(h){return await d(n,"delete"+s,{id:h})},async add(h){return await d(n,"add"+s,{data:h})},fields(h){let i=[];for(let o of h){const a=l(o);a&&i.push(a)}return i},async get(h,i){const o=(await Promise.resolve().then(()=>st)).default,a=o(s,n,k(i));for(const[u,p]of Object.entries(h))a.where(u,"==",p);return await a.first()},list(h){let i=h;const o={};Object.entries(h).forEach(([p])=>{c[p]&&(o[p]=c[p],c[p].gqlField&&(delete i[p],i=C(i,c[p].gqlField)))});const a=M(n,s,i).dataPath(f),u=a.fetch.bind(a);return{...a,async fetch(){return(await u()).map(g=>{const y={...g};return Object.entries(o).forEach(([m,F])=>{F.format&&typeof F.format=="function"&&(y[m]=F.format(g))}),y})},async fetchFirst(){const g=await a.fetchFirst.bind(a)();if(!g)return g;const y={...g};return Object.entries(o).forEach(([m,F])=>{F.format&&typeof F.format=="function"&&(y[m]=F.format(g))}),y}}}}},j={},P=(t,e=!1)=>{const r=t,s={};return{create(n,c){const f=U(r,n,c);s[n]=f,e&&(j[n]=f)},get(n){return s[n]||(e&&j[n]?s[n]=j[n]:this.create(n,{})),s[n]},has(n){return!!s[n]||e&&!!j[n]},list(){const n=Object.keys(s),c=e?Object.keys(j):[];return[...new Set([...n,...c])]},clear(){Object.keys(s).forEach(n=>delete s[n])}}},T=t=>{const e=P(t,!1);return{manager:e,createModel:e.create,getModel:e.get,hasModel:e.has,listModels:e.list,clearModels:e.clear,defineModel(r,s){return e.create(r,s),e.get(r)},defineModels(r){Object.entries(r).forEach(([s,n])=>{e.create(s,n)})}}},W=t=>{const e=P(t,!0);return{manager:e,createModel:e.create,getModel:e.get,hasModel:e.has,listModels:e.list,clearModels:e.clear,defineModel(r,s){return e.create(r,s),e.get(r)},defineModels(r){Object.entries(r).forEach(([s,n])=>{e.create(s,n)})}}},I=t=>({define(e,r){const s=U(t,e,r);return j[e]=s,s},get(e){return j[e]},has(e){return!!j[e]},list(){return Object.keys(j)},clear(){Object.keys(j).forEach(e=>delete j[e])}}),$=t=>{const{assertion:e,attestation:r}=L(t);return{login:async()=>{const s=await e();await d(t,"webAuthnAssertion",{assertion:s.toJSON()})},register:async()=>{const s=await r();await d(t,"webAuthnRegister",{registration:s.toJSON()})}}},Q=t=>({WebAuthn:$(t),google:{unlink:()=>d(t,"lightAuthUnlinkGoogle"),login:e=>d(t,"lightAuthLoginGoogle",{credential:e}),register:e=>d(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>d(t,"lightAuthUnlinkFacebook"),login:e=>d(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>d(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>d(t,"lightAuthUnlinkMicrosoft"),login:e=>d(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>d(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>d(t,"login",{username:e,password:r,code:s}),logout:()=>d(t,"logout"),changeExpiredPassword:(e,r,s)=>d(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>d(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>d(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>d(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return d(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await O(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}});function K(t){t="<~"+t+"~>";var e,r,s,n,c,f=String,l=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],n=0,c=t.length;c>n;n+=5)r=52200625*(t.charCodeAt(n)-33)+614125*(t.charCodeAt(n+1)-33)+7225*(t.charCodeAt(n+2)-33)+85*(t.charCodeAt(n+3)-33)+(t.charCodeAt(n+4)-33),s.push(l&r>>24,l&r>>16,l&r>>8,l&r);return function(h,i){for(var o=i;o>0;o--)h.pop()}(s,e.length),f.fromCharCode.apply(f,s)}const v=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const n=new Uint8Array(e.length);for(let l=0;l<e.length;l++)n[l]=e.charCodeAt(l);const c=new Blob([n],{type:s});return URL.createObjectURL(c)};return{getContent:()=>e,getURL:r,download:s=>{const n=document.createElement("a");n.download=s,n.href=r(),document.body.appendChild(n),n.click(),document.body.removeChild(n)},open:s=>{window.open(r(s),"_blank")}}},z={fromBase85:t=>v(K(t)),fromBase64:t=>v(atob(t)),fromString:t=>v(t)};function G(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function H(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const d=async(t,e,r=null,s=[])=>{let n={[e]:{}};const c=new FormData;let f=!1;if(r){const i={},o={},a={};let u=0;Object.entries(r).forEach(([p,g])=>{if(g instanceof Array&&G(g)){f=!0;let y=0;g.forEach(m=>{m instanceof File&&(i[p]=new b.VariableType(p),o[u]=["variables."+p+"."+y],c.append(u.toString(),m),u++)}),a[p]="[Upload!]!"}else g instanceof File?(f=!0,i[p]=new b.VariableType(p),o[u]=["variables."+p],c.append(u.toString(),g),a[p]="Upload!",u++):g instanceof Object&&H(g)?(f=!0,i[p]={},Object.entries(g).forEach(([y,m])=>{m instanceof File?(i[p][y]=new b.VariableType(y),o[u]=["variables."+y],c.append(u.toString(),m),a[y]="Upload!",u++):i[p][y]=m})):g!==void 0&&(i[p]=g)}),n[e].__args=i,n.__variables=a,f&&c.append("map",JSON.stringify(o))}Object.entries(k(s)).forEach(([i,o])=>{n[e][i]=o}),Object.entries(n[e]).length===0&&(n[e]=!0);let l=null;const h=b.jsonToGraphQLQuery({mutation:n});if(f?(c.append("operations",JSON.stringify({query:h})),l=await t.post("",c)):l=await t.post("",{query:h}),l.data.errors)throw new Error(l.data.errors[0].message);return l.data.data[e]},V=t=>({uploadTempFile:e=>d(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await O(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>d(t,"fsCreateFolder",{path:e}),delete:e=>d(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>d(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await O(t,{app:{drive:{files:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}}}});return r.drive.files},read:async e=>{let{app:r}=await O(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>d(t,"fsWriteFile",{path:e,content:r}),delete:e=>d(t,"fsDeleteFile",{path:e}),rename:(e,r)=>d(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>d(t,"fsMoveFile",{source:e,target:r})}}),X=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),Y=t=>({send:(e,r,s)=>d(t,"sendMail",{email:e,subject:r,message:s})}),Z=t=>({list:(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>M(t,"Users",e).dataPath("app.users")}),x=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await O(t,{app:{roles:e}});return r}}),tt="list",et=["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"],rt=["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 w{constructor(e,r){A(this,"_batchData",null);A(this,"data_path","");A(this,"axios");A(this,"filters");A(this,"steps");A(this,"fields");A(this,"already_limit",!1);A(this,"already_offset",!1);A(this,"limit",null);A(this,"offset",null);A(this,"_sort",null);A(this,"_sortDesc",!1);A(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}w.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}},w.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},w.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},w.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},E().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),w.prototype.fetchData=async function(){try{if(this._batchData){const l=this._batchData;return this.meta=l.meta,E(l.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,n=e[e.length-1];for(const l of e){if(l===n){s[l]=t;break}s[l]={},s=s[l]}let f=await O(this.axios,r);for(const l of e)f=f[l];return this.meta=f.meta,E(f.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},w.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},w.prototype.all=async function(){return(await this.processData()).all()};for(const t of et)w.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of rt)w.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};w.prototype.average=w.prototype.avg,w.prototype.first=async function(){return this.take(1),(await this.processData()).first()},w.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},w.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],s=t[1],n=t[2];switch(s){case"==":this.filters[r]=n;break;case"<":this.filters[r]={lt:n};break;case"<=":this.filters[r]={lte:n};break;case">":this.filters[r]={gt:n};break;case">=":this.filters[r]={gte:n};break;case"!==":this.filters[r]={ne:n};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},w.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},w.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)},w.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},w.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},w.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},w.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},w.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},w.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},w.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},w.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)},w.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 N=(t,e,r)=>{const s=new w(r,e);return s.data_path=tt+t,s},st=Object.freeze(Object.defineProperty({__proto__:null,default:N},Symbol.toStringTag,{value:"Module"})),nt=(t,e)=>({uploadTempFile:r=>d(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await O(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>d(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>d(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>d(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await O(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await O(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await O(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});if(!s.app.drive.file||!s.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${r}`);return typeof window<"u"&&window.atob?window.atob(s.app.drive.file.base64Content):s.app.drive.file.base64Content},write:(r,s)=>d(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>d(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>d(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>d(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),it=t=>{const e=typeof window>"u";let r=[];const s=D.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(l=>(l.withCredentials=!0,r.length>0&&(l.headers.Cookie=r.join("; ")),l)),s.interceptors.response.use(l=>{if(l.headers["set-cookie"]){const h=l.headers["set-cookie"].map(o=>o.split(";")[0]),i=new Map;r.forEach(o=>{const a=o.split("=")[0];i.set(a,o)}),h.forEach(o=>{const a=o.split("=")[0];i.set(a,o)}),r=Array.from(i.values())}return l}));const n=(l,h=null,i=[])=>d(s,l,h,i),c=l=>O(s,l),f=P(s);return{baseURL:t,axios:s,auth:Q(s),mutation:n,query:c,config:X(c),mail:Y(s),users:Z(s),fs:V(s),models:f,model(l){return f.get(l)},roles:x(s),collect:(l,h)=>{const i=N(l,s,h);return i.data_path=f.get(l).getDataPath(),i},list:(l,h)=>M(s,l,h).dataPath(f.get(l).getDataPath()),drive(l){return nt(l,s)},async collects(l){const h={},i={};for(const a in l){const u=l[a].getQueryPayload();i[a]=u.data_path,h[a]={};const p=u.data_path.split(".");let g=p[p.length-1],y=h[a];for(const m of p){if(m===g){y[m]=u.query;break}y[m]=y[m]||{}}h[a].__aliasFor=p[0]}const o=await O(s,h);for(const a in l){const u=i[a].split(".");let p=u[u.length-1],g=o[a];for(const y of u){if(y===p){l[a]._batchData=o[a][y];break}g[y]=g[y]||{}}}return l}}};_.File=z,_.createClient=it,_.createCollection=N,_.createList=M,_.createModelManager=P,_.file=v,_.mutation=d,_.query=O,_.toQuery=k,_.useGlobalModel=W,_.useGlobalModels=I,_.useModel=T,_.useWebAuthn=L,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(_,b){typeof exports=="object"&&typeof module<"u"?b(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"],b):(_=typeof globalThis<"u"?globalThis:_||self,b(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,b,D,E){"use strict";var at=Object.defineProperty;var ot=(_,b,D)=>b in _?at(_,b,{enumerable:!0,configurable:!0,writable:!0,value:D}):_[b]=D;var A=(_,b,D)=>ot(_,typeof b!="symbol"?b+"":b,D);const L=t=>({assertion:async()=>{const{app:s}=await O(t,{app:{auth:{webAuthnRequestOptions:!0}}}),i=s.auth.webAuthnRequestOptions,c=PublicKeyCredential.parseRequestOptionsFromJSON(i);return await navigator.credentials.get({publicKey:c})},attestation:async()=>{const{app:s}=await O(t,{app:{auth:{webAuthnCreationOptions:!0}}}),i=PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:i})}});function q(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=".",s){if(!q(e))return S(t,{},r,s);const i=Object.assign({},e);for(const c in t){if(c==="__proto__"||c==="constructor")continue;const f=t[c];f!=null&&(s&&s(i,c,f,r)||(Array.isArray(f)&&Array.isArray(i[c])?i[c]=[...f,...i[c]]:q(f)&&q(i[c])?i[c]=S(f,i[c],(r?`${r}.`:"")+c.toString(),s):i[c]=f))}return i}function J(t){return(...e)=>e.reduce((r,s)=>S(r,s,"",t),{})}const C=J(),B=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(B(r)).forEach(([s,i])=>{e[s]=i})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=B(s)}),e)},M=t=>B(t),O=async(t,e)=>{let r=b.jsonToGraphQLQuery(M(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function k(t,e,r){let s,i=[],c,f;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]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const o=await this.limit(1).fetch();return Array.isArray(o)&&o.length>0?o[0]:null},async fetchWithMeta(){let o=await O(t,this.toQuery(!0));if(f){const a=f.split(".");for(const u of a)o=o[u];return o}return o[`list${e}`]},async fetch(){let o=await O(t,this.toQuery());if(f){const a=f.split(".");for(const u of a)o=o[u];return o.data}return o[`list${e}`].data},dataPath(n){return n&&typeof n=="string"&&(f=n),this},sort(n){return n&&typeof n=="string"&&(c=n),this},filters(n){return n&&typeof n=="object"&&(i=[n]),this},where(n,o,a){const u=(h,g,y)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[g];F&&i.push({[h]:{[F]:y}})};if(a!==void 0)u(n,String(o),a);else{const h=p(),g=C(h,{[n]:o});i[0]=g}return this},whereContains(n,o){if(n&&typeof n=="string"){const a=p(),u={_contains:o};a[n]?Array.isArray(a[n])?a[n].push(u):a[n]=[a[n],u]:a[n]=[u],i[0]=a}return this},whereIn(n,o){if(n&&typeof n=="string"&&Array.isArray(o)){const a=p(),u={_in:o};a[n]?Array.isArray(a[n])?a[n].push(u):a[n]=[a[n],u]:a[n]=[u],i[0]=a}return this},whereBetween(n,o,a){if(n&&typeof n=="string"){const u=p(),h={_between:[o,a]};u[n]?Array.isArray(u[n])?u[n].push(h):u[n]=[u[n],h]:u[n]=h,i[0]=u}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(s=C(s||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(s=C(s||{},{offset:n})),this},toQuery(n=!1){let o;const a=i.length>0&&Object.keys(i[0]||{}).length>0,u=a?1:0,h=i.length>u;a&&h?o=i:h?o=i.slice(u):a&&(o=i[0]);const g=C(c?{sort:c}:{},o?{filters:o}:{}),y={data:{...r}};if(s&&(y.data.__args=s),Object.keys(g).length>0&&(y.__args=g),n&&(y.meta={total:!0,key:!0,name:!0}),f){const m=f.split(".");let F=y;for(let R=m.length-1;R>=0;R--)F={[m[R]]:F};return F}return{[`list${e}`]:y}}}}const U=(t,e,r)=>{const s=e,i=t,c=r;let f="list"+e;const l=p=>c[p]?c[p]:null;return{field:l,$fields:c,setDataPath(p){return f=p,f},getDataPath(){return f},gqlFields(p){let n={};for(const o of p)if(typeof o=="string"){const a=l(o);a&&(n=C(n,a.gqlField?typeof a.gqlField=="string"?{[a.gqlField]:!0}:a.gqlField:{[a.name||o]:!0}))}else typeof o=="object"&&(n=C(n,o));return n},async update(p,n){return await d(i,"update"+s,{id:p,data:n})},async delete(p){return await d(i,"delete"+s,{id:p})},async add(p){return await d(i,"add"+s,{data:p})},fields(p){let n=[];for(let o of p){const a=l(o);a&&n.push(a)}return n},async get(p,n){const o=(await Promise.resolve().then(()=>st)).default,a=o(s,i,M(n));for(const[u,h]of Object.entries(p))a.where(u,"==",h);return await a.first()},list(p){let n=p;const o={};Object.entries(p).forEach(([h])=>{c[h]&&(o[h]=c[h],c[h].gqlField&&(delete n[h],n=C(n,c[h].gqlField)),c[h].gql&&(n=C(n,c[h].gql),delete n[h]))});const a=k(i,s,n).dataPath(f),u=a.fetch.bind(a);return{...a,async fetch(){return(await u()).map(g=>{const y={...g};return Object.entries(o).forEach(([m,F])=>{F.format&&typeof F.format=="function"&&(y[m]=F.format(g))}),y})},async fetchFirst(){const g=await a.fetchFirst.bind(a)();if(!g)return g;const y={...g};return Object.entries(o).forEach(([m,F])=>{F.format&&typeof F.format=="function"&&(y[m]=F.format(g))}),y}}}}},j={},P=(t,e=!1)=>{const r=t,s={};return{create(i,c){const f=U(r,i,c);s[i]=f,e&&(j[i]=f)},get(i){return s[i]||(e&&j[i]?s[i]=j[i]:this.create(i,{})),s[i]},has(i){return!!s[i]||e&&!!j[i]},list(){const i=Object.keys(s),c=e?Object.keys(j):[];return[...new Set([...i,...c])]},clear(){Object.keys(s).forEach(i=>delete s[i])}}},T=t=>{const e=P(t,!1);return{manager:e,createModel:e.create,getModel:e.get,hasModel:e.has,listModels:e.list,clearModels:e.clear,defineModel(r,s){return e.create(r,s),e.get(r)},defineModels(r){Object.entries(r).forEach(([s,i])=>{e.create(s,i)})}}},W=t=>{const e=P(t,!0);return{manager:e,createModel:e.create,getModel:e.get,hasModel:e.has,listModels:e.list,clearModels:e.clear,defineModel(r,s){return e.create(r,s),e.get(r)},defineModels(r){Object.entries(r).forEach(([s,i])=>{e.create(s,i)})}}},I=t=>({define(e,r){const s=U(t,e,r);return j[e]=s,s},get(e){return j[e]},has(e){return!!j[e]},list(){return Object.keys(j)},clear(){Object.keys(j).forEach(e=>delete j[e])}}),$=t=>{const{assertion:e,attestation:r}=L(t);return{login:async()=>{const s=await e();await d(t,"webAuthnAssertion",{assertion:s.toJSON()})},register:async()=>{const s=await r();await d(t,"webAuthnRegister",{registration:s.toJSON()})}}},Q=t=>({WebAuthn:$(t),google:{unlink:()=>d(t,"lightAuthUnlinkGoogle"),login:e=>d(t,"lightAuthLoginGoogle",{credential:e}),register:e=>d(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>d(t,"lightAuthUnlinkFacebook"),login:e=>d(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>d(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>d(t,"lightAuthUnlinkMicrosoft"),login:e=>d(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>d(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>d(t,"login",{username:e,password:r,code:s}),logout:()=>d(t,"logout"),changeExpiredPassword:(e,r,s)=>d(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>d(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>d(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>d(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return d(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await O(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}});function K(t){t="<~"+t+"~>";var e,r,s,i,c,f=String,l=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],i=0,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);return function(p,n){for(var o=n;o>0;o--)p.pop()}(s,e.length),f.fromCharCode.apply(f,s)}const v=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let l=0;l<e.length;l++)i[l]=e.charCodeAt(l);const c=new Blob([i],{type:s});return URL.createObjectURL(c)};return{getContent:()=>e,getURL:r,download:s=>{const i=document.createElement("a");i.download=s,i.href=r(),document.body.appendChild(i),i.click(),document.body.removeChild(i)},open:s=>{window.open(r(s),"_blank")}}},z={fromBase85:t=>v(K(t)),fromBase64:t=>v(atob(t)),fromString:t=>v(t)};function G(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function H(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const d=async(t,e,r=null,s=[])=>{let i={[e]:{}};const c=new FormData;let f=!1;if(r){const n={},o={},a={};let u=0;Object.entries(r).forEach(([h,g])=>{if(g instanceof Array&&G(g)){f=!0;let y=0;g.forEach(m=>{m instanceof File&&(n[h]=new b.VariableType(h),o[u]=["variables."+h+"."+y],c.append(u.toString(),m),u++)}),a[h]="[Upload!]!"}else g instanceof File?(f=!0,n[h]=new b.VariableType(h),o[u]=["variables."+h],c.append(u.toString(),g),a[h]="Upload!",u++):g instanceof Object&&H(g)?(f=!0,n[h]={},Object.entries(g).forEach(([y,m])=>{m instanceof File?(n[h][y]=new b.VariableType(y),o[u]=["variables."+y],c.append(u.toString(),m),a[y]="Upload!",u++):n[h][y]=m})):g!==void 0&&(n[h]=g)}),i[e].__args=n,i.__variables=a,f&&c.append("map",JSON.stringify(o))}Object.entries(M(s)).forEach(([n,o])=>{i[e][n]=o}),Object.entries(i[e]).length===0&&(i[e]=!0);let l=null;const p=b.jsonToGraphQLQuery({mutation:i});if(f?(c.append("operations",JSON.stringify({query:p})),l=await t.post("",c)):l=await t.post("",{query:p}),l.data.errors)throw new Error(l.data.errors[0].message);return l.data.data[e]},V=t=>({uploadTempFile:e=>d(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await O(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>d(t,"fsCreateFolder",{path:e}),delete:e=>d(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>d(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await O(t,{app:{drive:{files:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}}}});return r.drive.files},read:async e=>{let{app:r}=await O(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>d(t,"fsWriteFile",{path:e,content:r}),delete:e=>d(t,"fsDeleteFile",{path:e}),rename:(e,r)=>d(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>d(t,"fsMoveFile",{source:e,target:r})}}),X=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),Y=t=>({send:(e,r,s)=>d(t,"sendMail",{email:e,subject:r,message:s})}),Z=t=>({list:(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>k(t,"Users",e).dataPath("app.users")}),x=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await O(t,{app:{roles:e}});return r}}),tt="list",et=["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"],rt=["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 w{constructor(e,r){A(this,"_batchData",null);A(this,"data_path","");A(this,"axios");A(this,"filters");A(this,"steps");A(this,"fields");A(this,"already_limit",!1);A(this,"already_offset",!1);A(this,"limit",null);A(this,"offset",null);A(this,"_sort",null);A(this,"_sortDesc",!1);A(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}w.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}},w.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},w.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},w.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},E().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),w.prototype.fetchData=async function(){try{if(this._batchData){const l=this._batchData;return this.meta=l.meta,E(l.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,i=e[e.length-1];for(const l of e){if(l===i){s[l]=t;break}s[l]={},s=s[l]}let f=await O(this.axios,r);for(const l of e)f=f[l];return this.meta=f.meta,E(f.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},w.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},w.prototype.all=async function(){return(await this.processData()).all()};for(const t of et)w.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of rt)w.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};w.prototype.average=w.prototype.avg,w.prototype.first=async function(){return this.take(1),(await this.processData()).first()},w.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},w.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],s=t[1],i=t[2];switch(s){case"==":this.filters[r]=i;break;case"<":this.filters[r]={lt:i};break;case"<=":this.filters[r]={lte:i};break;case">":this.filters[r]={gt:i};break;case">=":this.filters[r]={gte:i};break;case"!==":this.filters[r]={ne:i};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},w.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},w.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)},w.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},w.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},w.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},w.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},w.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},w.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},w.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},w.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)},w.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 N=(t,e,r)=>{const s=new w(r,e);return s.data_path=tt+t,s},st=Object.freeze(Object.defineProperty({__proto__:null,default:N},Symbol.toStringTag,{value:"Module"})),nt=(t,e)=>({uploadTempFile:r=>d(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await O(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>d(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>d(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>d(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await O(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await O(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await O(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});if(!s.app.drive.file||!s.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${r}`);return typeof window<"u"&&window.atob?window.atob(s.app.drive.file.base64Content):s.app.drive.file.base64Content},write:(r,s)=>d(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>d(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>d(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>d(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),it=t=>{const e=typeof window>"u";let r=[];const s=D.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(l=>(l.withCredentials=!0,r.length>0&&(l.headers.Cookie=r.join("; ")),l)),s.interceptors.response.use(l=>{if(l.headers["set-cookie"]){const p=l.headers["set-cookie"].map(o=>o.split(";")[0]),n=new Map;r.forEach(o=>{const a=o.split("=")[0];n.set(a,o)}),p.forEach(o=>{const a=o.split("=")[0];n.set(a,o)}),r=Array.from(n.values())}return l}));const i=(l,p=null,n=[])=>d(s,l,p,n),c=l=>O(s,l),f=P(s);return{baseURL:t,axios:s,auth:Q(s),mutation:i,query:c,config:X(c),mail:Y(s),users:Z(s),fs:V(s),models:f,model(l){return f.get(l)},roles:x(s),collect:(l,p)=>{const n=N(l,s,p);return n.data_path=f.get(l).getDataPath(),n},list:(l,p)=>k(s,l,p).dataPath(f.get(l).getDataPath()),drive(l){return nt(l,s)},async collects(l){const p={},n={};for(const a in l){const u=l[a].getQueryPayload();n[a]=u.data_path,p[a]={};const h=u.data_path.split(".");let g=h[h.length-1],y=p[a];for(const m of h){if(m===g){y[m]=u.query;break}y[m]=y[m]||{}}p[a].__aliasFor=h[0]}const o=await O(s,p);for(const a in l){const u=n[a].split(".");let h=u[u.length-1],g=o[a];for(const y of u){if(y===h){l[a]._batchData=o[a][y];break}g[y]=g[y]||{}}}return l}}};_.File=z,_.createClient=it,_.createCollection=N,_.createList=k,_.createModelManager=P,_.file=v,_.mutation=d,_.query=O,_.toQuery=M,_.useGlobalModel=W,_.useGlobalModels=I,_.useModel=T,_.useWebAuthn=L,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
|
package/dist/model.d.ts
CHANGED
|
@@ -3,22 +3,17 @@ import { Fields } from '.';
|
|
|
3
3
|
export type Field = {
|
|
4
4
|
label: string;
|
|
5
5
|
name?: string;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use gql instead
|
|
8
|
+
*/
|
|
6
9
|
gqlField?: string | object;
|
|
7
|
-
|
|
8
|
-
searchable?: boolean;
|
|
9
|
-
searchableType?: string;
|
|
10
|
-
align?: string;
|
|
10
|
+
gql?: Record<string, any>;
|
|
11
11
|
field?: any;
|
|
12
12
|
format?: any;
|
|
13
13
|
};
|
|
14
14
|
export type Model = {
|
|
15
15
|
name: string;
|
|
16
|
-
|
|
17
|
-
getName: () => string;
|
|
18
|
-
getGQLField: () => string | object;
|
|
19
|
-
getRaw: () => Field;
|
|
20
|
-
getValue: (model: object) => any;
|
|
21
|
-
getFormattedValue: (model: object) => any;
|
|
16
|
+
fields: Record<string, Field>;
|
|
22
17
|
};
|
|
23
18
|
declare const _default: (axios: AxiosInstance, name: string, fields: Record<string, Field>) => {
|
|
24
19
|
field: (f: string) => Field | null;
|