@luminix/core 0.0.1-beta.2 → 0.0.1-beta.4
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/contracts/Builder.d.ts +0 -1
- package/dist/contracts/Collection.d.ts +0 -1
- package/dist/contracts/ModelCollection.d.ts +1 -1
- package/dist/core.js +678 -653
- package/dist/exceptions/AttributeNotFillableException.d.ts +1 -1
- package/dist/exceptions/FacadeNotFoundException.d.ts +1 -1
- package/dist/exceptions/MethodNotImplementedException.d.ts +1 -1
- package/dist/exceptions/ModelInvalidRelatedTypeException.d.ts +1 -1
- package/dist/exceptions/ModelNotFoundException.d.ts +1 -1
- package/dist/exceptions/ModelNotPersistedException.d.ts +1 -1
- package/dist/exceptions/ModelWithoutPrimaryKeyException.d.ts +1 -1
- package/dist/exceptions/NoEmbedException.d.ts +1 -1
- package/dist/exceptions/NoInverseRelationException.d.ts +1 -1
- package/dist/exceptions/NotModelException.d.ts +1 -1
- package/dist/exceptions/NotReducibleException.d.ts +1 -1
- package/dist/exceptions/ReducerOverrideException.d.ts +1 -1
- package/dist/exceptions/RouteNotFoundException.d.ts +1 -1
- package/dist/exceptions/UnsupportedRelationException.d.ts +1 -1
- package/dist/facades/App.d.ts +0 -1
- package/dist/facades/Model.d.ts +1 -2
- package/dist/mixins/HasEvents.d.ts +0 -1
- package/dist/types/Model.d.ts +1 -1
- package/package.json +1 -1
- package/vite.config.js +3 -1
package/dist/core.js
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var Qe = Object.defineProperty;
|
|
2
|
+
var U = (n) => {
|
|
3
3
|
throw TypeError(n);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var o = (n, e, t) => (F(n, e, "read from private field"), t ? t.call(n) : e.get(n)), q = (n, e, t) => e.has(n) ?
|
|
5
|
+
var Ce = (n, e, t) => e in n ? Qe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
6
|
+
var g = (n, e, t) => Ce(n, typeof e != "symbol" ? e + "" : e, t), F = (n, e, t) => e.has(n) || U("Cannot " + t);
|
|
7
|
+
var o = (n, e, t) => (F(n, e, "read from private field"), t ? t.call(n) : e.get(n)), q = (n, e, t) => e.has(n) ? U("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), P = (n, e, t, r) => (F(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), D = (n, e, t) => (F(n, e, "access private method"), t);
|
|
8
8
|
import f from "lodash";
|
|
9
|
-
import { produce as
|
|
10
|
-
import K, { isAxiosError as
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
import { produce as v, isDraftable as Le } from "immer";
|
|
10
|
+
import K, { isAxiosError as Je } from "axios";
|
|
11
|
+
var X, Y;
|
|
12
|
+
class Ue extends (Y = Error, X = Symbol.toStringTag, Y) {
|
|
13
|
+
constructor(t) {
|
|
14
|
+
super(`[Luminix] Facade "${t}" not found`);
|
|
15
|
+
g(this, X, "FacadeNotFoundException");
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
class be {
|
|
18
|
+
class De {
|
|
18
19
|
constructor(e) {
|
|
19
|
-
|
|
20
|
+
g(this, "_user");
|
|
20
21
|
this.app = e;
|
|
21
22
|
}
|
|
22
23
|
attempt(e, t = !1, r) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
if (typeof
|
|
27
|
-
const
|
|
28
|
-
|
|
24
|
+
const i = document.createElement("form");
|
|
25
|
+
i.method = "post", i.action = this.app.make("route").url("login"), i.style.display = "none";
|
|
26
|
+
const s = this.app.make("config").get("auth.csrf");
|
|
27
|
+
if (typeof s == "string") {
|
|
28
|
+
const l = document.createElement("input");
|
|
29
|
+
l.type = "hidden", l.name = "_token", l.value = s, i.appendChild(l);
|
|
29
30
|
}
|
|
30
31
|
const u = document.createElement("input");
|
|
31
|
-
u.type = "email", u.name = "email", u.value = e.email,
|
|
32
|
+
u.type = "email", u.name = "email", u.value = e.email, i.appendChild(u);
|
|
32
33
|
const a = document.createElement("input");
|
|
33
|
-
if (a.type = "password", a.name = "password", a.value = e.password,
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
if (a.type = "password", a.name = "password", a.value = e.password, i.appendChild(a), t) {
|
|
35
|
+
const l = document.createElement("input");
|
|
36
|
+
l.type = "checkbox", l.name = "remember", l.value = "1", l.checked = !0, i.appendChild(l);
|
|
36
37
|
}
|
|
37
|
-
r &&
|
|
38
|
+
r && i.addEventListener("submit", r), document.body.appendChild(i), i.submit();
|
|
38
39
|
}
|
|
39
40
|
check() {
|
|
40
41
|
return !!this.app.make("config").get("auth.user");
|
|
@@ -44,17 +45,17 @@ class be {
|
|
|
44
45
|
t.method = "post", t.action = this.app.make("route").url("logout"), t.style.display = "none";
|
|
45
46
|
const r = this.app.make("config").get("auth.csrf");
|
|
46
47
|
if (typeof r == "string") {
|
|
47
|
-
const
|
|
48
|
-
|
|
48
|
+
const i = document.createElement("input");
|
|
49
|
+
i.type = "hidden", i.name = "_token", i.value = r, t.appendChild(i);
|
|
49
50
|
}
|
|
50
51
|
document.body.appendChild(t), e && t.addEventListener("submit", e), t.submit();
|
|
51
52
|
}
|
|
52
53
|
user() {
|
|
53
54
|
if (!this._user) {
|
|
54
|
-
const { model: e, config: t } = this.app.make(), r = e.make("user"),
|
|
55
|
-
if (!
|
|
55
|
+
const { model: e, config: t } = this.app.make(), r = e.make("user"), i = t.get("auth.user");
|
|
56
|
+
if (!i)
|
|
56
57
|
return null;
|
|
57
|
-
this._user = new r(
|
|
58
|
+
this._user = new r(i);
|
|
58
59
|
}
|
|
59
60
|
return this._user;
|
|
60
61
|
}
|
|
@@ -63,7 +64,7 @@ class be {
|
|
|
63
64
|
return ((e = this.user()) == null ? void 0 : e.getKey()) || null;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
class
|
|
67
|
+
class He {
|
|
67
68
|
constructor(e) {
|
|
68
69
|
this._debug = e;
|
|
69
70
|
}
|
|
@@ -92,9 +93,9 @@ class Ee {
|
|
|
92
93
|
this._debug && console.debug(...e);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
|
-
class
|
|
96
|
+
class A {
|
|
96
97
|
constructor(e) {
|
|
97
|
-
|
|
98
|
+
g(this, "locked", []);
|
|
98
99
|
this.bag = e, Object.freeze(this.bag);
|
|
99
100
|
}
|
|
100
101
|
get(e, t) {
|
|
@@ -110,14 +111,14 @@ class v {
|
|
|
110
111
|
throw new Error("Cannot set the root path when there are locked paths");
|
|
111
112
|
if (typeof t != "object" || t === null)
|
|
112
113
|
throw new TypeError("Value must be an object");
|
|
113
|
-
this.bag =
|
|
114
|
+
this.bag = v(this.bag, () => t), this.emit("change", {
|
|
114
115
|
path: e,
|
|
115
116
|
value: t,
|
|
116
117
|
type: "set"
|
|
117
118
|
});
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
|
-
this.bag =
|
|
121
|
+
this.bag = v(this.bag, (r) => {
|
|
121
122
|
f.set(r, e, t);
|
|
122
123
|
}), this.emit("change", {
|
|
123
124
|
path: e,
|
|
@@ -129,10 +130,10 @@ class v {
|
|
|
129
130
|
if (typeof t != "object" || t === null)
|
|
130
131
|
throw new TypeError("Value must be an object");
|
|
131
132
|
if (e === ".") {
|
|
132
|
-
if (this.locked.some((
|
|
133
|
+
if (this.locked.some((i) => f.has(t, i)))
|
|
133
134
|
throw new Error(`Cannot merge a path "${e}" that would override a locked path`);
|
|
134
|
-
this.bag =
|
|
135
|
-
...
|
|
135
|
+
this.bag = v(this.bag, (i) => ({
|
|
136
|
+
...i,
|
|
136
137
|
...t
|
|
137
138
|
})), this.emit("change", {
|
|
138
139
|
path: e,
|
|
@@ -157,7 +158,7 @@ class v {
|
|
|
157
158
|
delete(e) {
|
|
158
159
|
if (this.locked.some((t) => e.startsWith(t)))
|
|
159
160
|
throw new Error(`Cannot delete a locked path "${e}"`);
|
|
160
|
-
this.bag =
|
|
161
|
+
this.bag = v(this.bag, (t) => {
|
|
161
162
|
f.unset(t, e);
|
|
162
163
|
}), this.emit("change", {
|
|
163
164
|
path: e,
|
|
@@ -171,7 +172,7 @@ class v {
|
|
|
171
172
|
this.locked.push(e);
|
|
172
173
|
}
|
|
173
174
|
clone() {
|
|
174
|
-
return new
|
|
175
|
+
return new A(this.bag);
|
|
175
176
|
}
|
|
176
177
|
all() {
|
|
177
178
|
return this.bag;
|
|
@@ -190,93 +191,94 @@ class v {
|
|
|
190
191
|
emit(e, t) {
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
|
-
function
|
|
194
|
-
var e, t, r,
|
|
195
|
-
return
|
|
194
|
+
function S(n) {
|
|
195
|
+
var e, t, r, i, Ae, u;
|
|
196
|
+
return u = class extends (t = n, e = Symbol.toStringTag, t) {
|
|
196
197
|
constructor(...d) {
|
|
197
198
|
super(...d);
|
|
198
199
|
q(this, i);
|
|
199
200
|
q(this, r);
|
|
200
|
-
|
|
201
|
-
P(this, r,
|
|
201
|
+
g(this, e, n.name);
|
|
202
|
+
P(this, r, D(this, i, Ae).call(this));
|
|
202
203
|
}
|
|
203
|
-
on(d,
|
|
204
|
+
on(d, p) {
|
|
204
205
|
if (typeof d != "string")
|
|
205
206
|
throw new TypeError("event must be a string");
|
|
206
|
-
if (typeof
|
|
207
|
+
if (typeof p != "function")
|
|
207
208
|
throw new TypeError("callback must be a function");
|
|
208
|
-
return o(this, r).on(d,
|
|
209
|
+
return o(this, r).on(d, p);
|
|
209
210
|
}
|
|
210
|
-
once(d,
|
|
211
|
+
once(d, p) {
|
|
211
212
|
if (typeof d != "string")
|
|
212
213
|
throw new TypeError("event must be a string");
|
|
213
|
-
if (typeof
|
|
214
|
+
if (typeof p != "function")
|
|
214
215
|
throw new TypeError("callback must be a function");
|
|
215
|
-
const
|
|
216
|
-
|
|
216
|
+
const y = o(this, r).on(d, (m) => {
|
|
217
|
+
y(), p(m);
|
|
217
218
|
});
|
|
218
219
|
}
|
|
219
|
-
emit(d,
|
|
220
|
+
emit(d, p = {}) {
|
|
220
221
|
if (typeof d != "string")
|
|
221
222
|
throw new TypeError("event must be a string");
|
|
222
|
-
if (typeof
|
|
223
|
+
if (typeof p != "object")
|
|
223
224
|
throw new TypeError("data must be an object");
|
|
224
225
|
o(this, r).emit(d, {
|
|
225
|
-
...
|
|
226
|
+
...p,
|
|
226
227
|
source: this
|
|
227
228
|
});
|
|
228
229
|
}
|
|
229
|
-
}, r = new WeakMap(), i = new WeakSet(),
|
|
230
|
+
}, r = new WeakMap(), i = new WeakSet(), Ae = function() {
|
|
230
231
|
return {
|
|
231
|
-
emit(d,
|
|
232
|
-
for (let
|
|
233
|
-
m[
|
|
232
|
+
emit(d, p) {
|
|
233
|
+
for (let y = 0, m = this.events[d] || [], E = m.length; y < E; y++)
|
|
234
|
+
m[y](p);
|
|
234
235
|
},
|
|
235
236
|
events: {},
|
|
236
|
-
on(d,
|
|
237
|
-
var
|
|
238
|
-
return ((
|
|
237
|
+
on(d, p) {
|
|
238
|
+
var y;
|
|
239
|
+
return ((y = this.events)[d] || (y[d] = [])).push(p), () => {
|
|
239
240
|
var m;
|
|
240
|
-
this.events[d] = (m = this.events[d]) == null ? void 0 : m.filter((
|
|
241
|
+
this.events[d] = (m = this.events[d]) == null ? void 0 : m.filter((E) => p !== E);
|
|
241
242
|
};
|
|
242
243
|
}
|
|
243
244
|
};
|
|
244
|
-
},
|
|
245
|
+
}, u;
|
|
245
246
|
}
|
|
246
|
-
function
|
|
247
|
-
return n.reduce((e, t) => e.flatMap((r) => t.map((
|
|
247
|
+
function H(...n) {
|
|
248
|
+
return n.reduce((e, t) => e.flatMap((r) => t.map((i) => [r, i].flat())));
|
|
248
249
|
}
|
|
249
|
-
function
|
|
250
|
+
function $(n) {
|
|
250
251
|
return !(typeof n != "object" || n === null || !Reflect.has(n, "constructor") || Reflect.get(n.constructor, "name") !== "Collection");
|
|
251
252
|
}
|
|
252
|
-
|
|
253
|
+
var Z, z;
|
|
254
|
+
class w extends (z = Error, Z = Symbol.toStringTag, z) {
|
|
253
255
|
constructor() {
|
|
254
256
|
super("[Luminix] Method not implemented.");
|
|
257
|
+
g(this, Z, "MethodNotImplementedException");
|
|
255
258
|
}
|
|
256
259
|
}
|
|
257
|
-
|
|
258
|
-
function l(n = [], e = L) {
|
|
260
|
+
function c(n = [], e = Q) {
|
|
259
261
|
if (!Array.isArray(n))
|
|
260
262
|
throw new TypeError("collect() expects an array");
|
|
261
|
-
return new (
|
|
263
|
+
return new (S(e))([...n]);
|
|
262
264
|
}
|
|
263
|
-
const
|
|
265
|
+
const T = (n) => {
|
|
264
266
|
n.emit("change", {
|
|
265
267
|
items: n.all()
|
|
266
268
|
});
|
|
267
269
|
}, I = (n, e) => Array.isArray(n) ? n[e] ?? null : n.get(e);
|
|
268
|
-
var
|
|
269
|
-
class
|
|
270
|
+
var O, k, h;
|
|
271
|
+
class Q {
|
|
270
272
|
constructor(e = []) {
|
|
271
|
-
//
|
|
273
|
+
// [Symbol.toStringTag] = 'Collection';
|
|
272
274
|
q(this, h);
|
|
273
|
-
|
|
275
|
+
g(this, O, "Collection");
|
|
274
276
|
P(this, h, e);
|
|
275
277
|
}
|
|
276
278
|
get items() {
|
|
277
279
|
return [...o(this, h)];
|
|
278
280
|
}
|
|
279
|
-
[(
|
|
281
|
+
[(k = Symbol.iterator, O = Symbol.toStringTag, k)]() {
|
|
280
282
|
return o(this, h)[Symbol.iterator]();
|
|
281
283
|
}
|
|
282
284
|
all() {
|
|
@@ -292,34 +294,34 @@ class L {
|
|
|
292
294
|
const t = [];
|
|
293
295
|
for (let r = 0; r < o(this, h).length; r += e)
|
|
294
296
|
t.push(o(this, h).slice(r, r + e));
|
|
295
|
-
return
|
|
297
|
+
return c(t.map((r) => c(r)));
|
|
296
298
|
}
|
|
297
299
|
chunkWhile(e) {
|
|
298
300
|
const t = [];
|
|
299
|
-
let r =
|
|
300
|
-
for (let
|
|
301
|
-
e(o(this, h)[
|
|
302
|
-
return r.count() > 0 && t.push(r),
|
|
301
|
+
let r = c();
|
|
302
|
+
for (let i = 0; i < o(this, h).length; i++)
|
|
303
|
+
e(o(this, h)[i], i, r) ? r.push(o(this, h)[i]) : (t.push(r), r = c());
|
|
304
|
+
return r.count() > 0 && t.push(r), c(t);
|
|
303
305
|
}
|
|
304
306
|
collapse() {
|
|
305
|
-
return
|
|
307
|
+
return c(o(this, h).flat());
|
|
306
308
|
}
|
|
307
309
|
collect() {
|
|
308
|
-
return
|
|
310
|
+
return c(o(this, h));
|
|
309
311
|
}
|
|
310
312
|
combine(e) {
|
|
311
313
|
const t = {};
|
|
312
|
-
return o(this, h).forEach((r,
|
|
314
|
+
return o(this, h).forEach((r, i) => {
|
|
313
315
|
if (typeof r != "string")
|
|
314
316
|
throw new TypeError("The `combine` method expects the keys to be strings");
|
|
315
|
-
t[r] = I(e,
|
|
317
|
+
t[r] = I(e, i);
|
|
316
318
|
}), t;
|
|
317
319
|
}
|
|
318
320
|
concat(e) {
|
|
319
|
-
return Array.isArray(e) ?
|
|
321
|
+
return Array.isArray(e) ? c([...o(this, h), ...e]) : c([...o(this, h), ...e.all()]);
|
|
320
322
|
}
|
|
321
323
|
contains(e, t) {
|
|
322
|
-
return typeof e == "function" ? o(this, h).some((r,
|
|
324
|
+
return typeof e == "function" ? o(this, h).some((r, i) => e(r, i, this)) : o(this, h).some((r) => {
|
|
323
325
|
if (typeof t > "u")
|
|
324
326
|
return r == e;
|
|
325
327
|
if (typeof e != "string")
|
|
@@ -331,7 +333,7 @@ class L {
|
|
|
331
333
|
return o(this, h).length === 1;
|
|
332
334
|
}
|
|
333
335
|
containsStrict(e, t) {
|
|
334
|
-
return typeof e == "function" ? o(this, h).some((r,
|
|
336
|
+
return typeof e == "function" ? o(this, h).some((r, i) => e(r, i, this)) : o(this, h).some((r) => {
|
|
335
337
|
if (typeof t > "u")
|
|
336
338
|
return r === e;
|
|
337
339
|
if (typeof e != "string")
|
|
@@ -343,9 +345,9 @@ class L {
|
|
|
343
345
|
return o(this, h).length;
|
|
344
346
|
}
|
|
345
347
|
countBy(e) {
|
|
346
|
-
return typeof e == "function" ? o(this, h).reduce((t, r,
|
|
347
|
-
const
|
|
348
|
-
return t[
|
|
348
|
+
return typeof e == "function" ? o(this, h).reduce((t, r, i) => {
|
|
349
|
+
const s = e(r, i, this);
|
|
350
|
+
return t[s] = t[s] ? t[s] + 1 : 1, t;
|
|
349
351
|
}, {}) : o(this, h).reduce((t, r) => {
|
|
350
352
|
if (!["string", "number"].includes(typeof r))
|
|
351
353
|
throw new TypeError("The countBy method expects the items to be strings or numbers");
|
|
@@ -353,16 +355,16 @@ class L {
|
|
|
353
355
|
}, {});
|
|
354
356
|
}
|
|
355
357
|
crossJoin(...e) {
|
|
356
|
-
return
|
|
358
|
+
return c(H(
|
|
357
359
|
o(this, h),
|
|
358
360
|
...e.map((t) => Array.isArray(t) ? t : t.all())
|
|
359
361
|
));
|
|
360
362
|
}
|
|
361
363
|
diff(e) {
|
|
362
|
-
return Array.isArray(e) ?
|
|
364
|
+
return Array.isArray(e) ? c(o(this, h).filter((t) => !e.includes(t))) : c(o(this, h).filter((t) => !e.contains(t)));
|
|
363
365
|
}
|
|
364
366
|
doesntContain(e, t) {
|
|
365
|
-
return typeof e == "function" ? o(this, h).every((r,
|
|
367
|
+
return typeof e == "function" ? o(this, h).every((r, i) => !e(r, i, this)) : o(this, h).every((r) => {
|
|
366
368
|
if (typeof t > "u")
|
|
367
369
|
return r != e;
|
|
368
370
|
if (typeof e != "string")
|
|
@@ -374,10 +376,10 @@ class L {
|
|
|
374
376
|
console.log(this.toArray());
|
|
375
377
|
}
|
|
376
378
|
duplicates(e) {
|
|
377
|
-
return
|
|
379
|
+
return c(typeof e == "string" ? o(this, h).reduce((t, r, i) => (o(this, h).slice(i + 1).some((s) => s[e] == r[e]) && t.push(r[e]), t), []) : o(this, h).reduce((t, r, i) => (o(this, h).slice(i + 1).some((s) => s == r) && t.push(r), t), []));
|
|
378
380
|
}
|
|
379
381
|
duplicatesStrict(e) {
|
|
380
|
-
return
|
|
382
|
+
return c(typeof e == "string" ? o(this, h).reduce((t, r, i) => (o(this, h).slice(i + 1).some((s) => s[e] === r[e]) && t.push(r[e]), t), []) : o(this, h).reduce((t, r, i) => (o(this, h).slice(i + 1).some((s) => s === r) && t.push(r), t), []));
|
|
381
383
|
}
|
|
382
384
|
each(e) {
|
|
383
385
|
let t = 0;
|
|
@@ -390,7 +392,7 @@ class L {
|
|
|
390
392
|
}
|
|
391
393
|
eachSpread(e) {
|
|
392
394
|
for (const t of this) {
|
|
393
|
-
if (!Array.isArray(t) &&
|
|
395
|
+
if (!Array.isArray(t) && !$(t))
|
|
394
396
|
throw new TypeError("The items in the collection must be arrays or collections");
|
|
395
397
|
const r = Array.isArray(t) ? t : t.all();
|
|
396
398
|
if (e(...r) === !1)
|
|
@@ -400,19 +402,19 @@ class L {
|
|
|
400
402
|
}
|
|
401
403
|
ensure(e) {
|
|
402
404
|
const t = Array.isArray(e) ? e : [e];
|
|
403
|
-
return o(this, h).forEach((r,
|
|
404
|
-
if (!t.some((
|
|
405
|
-
throw new TypeError(`The item at index ${
|
|
405
|
+
return o(this, h).forEach((r, i) => {
|
|
406
|
+
if (!t.some((s) => typeof s == "string" ? typeof r === s : r instanceof s))
|
|
407
|
+
throw new TypeError(`The item at index ${i} is not of the expected type`);
|
|
406
408
|
}), this;
|
|
407
409
|
}
|
|
408
410
|
every(e) {
|
|
409
411
|
return o(this, h).every((t, r) => e(t, r, this));
|
|
410
412
|
}
|
|
411
413
|
except(e) {
|
|
412
|
-
return
|
|
414
|
+
return c(o(this, h).filter((t, r) => !e.includes(r)));
|
|
413
415
|
}
|
|
414
416
|
filter(e) {
|
|
415
|
-
return
|
|
417
|
+
return c(o(this, h).filter((t, r) => typeof e != "function" ? !!t : e(t, r, this)));
|
|
416
418
|
}
|
|
417
419
|
first(e) {
|
|
418
420
|
return typeof e == "function" ? o(this, h).find((t, r) => e(t, r, this)) ?? null : o(this, h)[0] ?? null;
|
|
@@ -427,38 +429,38 @@ class L {
|
|
|
427
429
|
if (typeof e != "string")
|
|
428
430
|
throw new TypeError("The key must be a string");
|
|
429
431
|
if (typeof t > "u")
|
|
430
|
-
return this.first((
|
|
432
|
+
return this.first((i) => !!i[e]);
|
|
431
433
|
if (typeof r > "u")
|
|
432
|
-
return o(this, h).find((
|
|
434
|
+
return o(this, h).find((i) => i[e] == t) ?? null;
|
|
433
435
|
if (typeof t != "string")
|
|
434
436
|
throw new TypeError("The operator must be a string");
|
|
435
|
-
return r === null ? o(this, h).find((
|
|
437
|
+
return r === null ? o(this, h).find((i) => i[e] === null) ?? null : o(this, h).find((i) => {
|
|
436
438
|
switch (t) {
|
|
437
439
|
case "=":
|
|
438
|
-
return
|
|
440
|
+
return i[e] == r;
|
|
439
441
|
case "!=":
|
|
440
|
-
return
|
|
442
|
+
return i[e] != r;
|
|
441
443
|
case ">":
|
|
442
|
-
return
|
|
444
|
+
return i[e] > r;
|
|
443
445
|
case "<":
|
|
444
|
-
return
|
|
446
|
+
return i[e] < r;
|
|
445
447
|
case ">=":
|
|
446
|
-
return
|
|
448
|
+
return i[e] >= r;
|
|
447
449
|
case "<=":
|
|
448
|
-
return
|
|
450
|
+
return i[e] <= r;
|
|
449
451
|
default:
|
|
450
452
|
throw new Error("Unsupported operator");
|
|
451
453
|
}
|
|
452
454
|
}) ?? null;
|
|
453
455
|
}
|
|
454
456
|
flatMap(e) {
|
|
455
|
-
return
|
|
457
|
+
return c(o(this, h).flatMap((t, r) => e(t, r, this)));
|
|
456
458
|
}
|
|
457
459
|
forget(e) {
|
|
458
|
-
return o(this, h).splice(e, 1),
|
|
460
|
+
return o(this, h).splice(e, 1), T(this), this;
|
|
459
461
|
}
|
|
460
462
|
forPage(e, t) {
|
|
461
|
-
return
|
|
463
|
+
return c(o(this, h).slice((e - 1) * t, e * t));
|
|
462
464
|
}
|
|
463
465
|
get(e, t) {
|
|
464
466
|
if (typeof e != "number")
|
|
@@ -467,19 +469,19 @@ class L {
|
|
|
467
469
|
}
|
|
468
470
|
groupBy(e) {
|
|
469
471
|
const t = Array.isArray(e) ? e : [e];
|
|
470
|
-
return o(this, h).reduce((r,
|
|
471
|
-
const u = t.map((
|
|
472
|
-
if (typeof
|
|
473
|
-
const d =
|
|
472
|
+
return o(this, h).reduce((r, i, s) => {
|
|
473
|
+
const u = t.map((l) => {
|
|
474
|
+
if (typeof l == "function") {
|
|
475
|
+
const d = l(i, s, this);
|
|
474
476
|
return Array.isArray(d) ? d : [d];
|
|
475
477
|
}
|
|
476
|
-
return [String(
|
|
478
|
+
return [String(i[l])];
|
|
477
479
|
});
|
|
478
|
-
return
|
|
479
|
-
const d = Array.isArray(
|
|
480
|
+
return H(...u).forEach((l) => {
|
|
481
|
+
const d = Array.isArray(l) ? l.join(".") : l;
|
|
480
482
|
f.set(r, d, [
|
|
481
483
|
...f.get(r, d, []),
|
|
482
|
-
|
|
484
|
+
i
|
|
483
485
|
]);
|
|
484
486
|
}), r;
|
|
485
487
|
}, {});
|
|
@@ -499,7 +501,7 @@ class L {
|
|
|
499
501
|
return o(this, h).join(e);
|
|
500
502
|
}
|
|
501
503
|
if (typeof e == "function")
|
|
502
|
-
return o(this, h).map((r,
|
|
504
|
+
return o(this, h).map((r, i) => e(r, i, this)).join(t);
|
|
503
505
|
if (typeof e != "string")
|
|
504
506
|
throw new TypeError("The key must be a string");
|
|
505
507
|
if (!o(this, h).every((r) => typeof r == "object"))
|
|
@@ -507,7 +509,7 @@ class L {
|
|
|
507
509
|
return o(this, h).map((r) => r[e]).join(t);
|
|
508
510
|
}
|
|
509
511
|
intersect(e) {
|
|
510
|
-
return Array.isArray(e) ?
|
|
512
|
+
return Array.isArray(e) ? c(o(this, h).filter((t) => e.includes(t))) : c(o(this, h).filter((t) => e.contains(t)));
|
|
511
513
|
}
|
|
512
514
|
isEmpty() {
|
|
513
515
|
return o(this, h).length === 0;
|
|
@@ -520,7 +522,7 @@ class L {
|
|
|
520
522
|
}
|
|
521
523
|
keyBy(e) {
|
|
522
524
|
if (typeof e == "function")
|
|
523
|
-
return o(this, h).reduce((t, r,
|
|
525
|
+
return o(this, h).reduce((t, r, i) => (t[e(r, i, this)] = r, t), {});
|
|
524
526
|
if (typeof e != "string")
|
|
525
527
|
throw new TypeError("The key must be a string");
|
|
526
528
|
return o(this, h).reduce((t, r) => (t[String(r[e])] = r, t), {});
|
|
@@ -529,31 +531,31 @@ class L {
|
|
|
529
531
|
return typeof e == "function" ? o(this, h).toReversed().find((t, r) => e(t, r, this)) ?? null : o(this, h)[o(this, h).length - 1] ?? null;
|
|
530
532
|
}
|
|
531
533
|
map(e) {
|
|
532
|
-
return
|
|
534
|
+
return c(o(this, h).map((t, r) => e(t, r, this)));
|
|
533
535
|
}
|
|
534
536
|
mapInto(e) {
|
|
535
|
-
return
|
|
537
|
+
return c(o(this, h).map((t) => new e(t)));
|
|
536
538
|
}
|
|
537
539
|
mapSpread(e) {
|
|
538
|
-
return
|
|
539
|
-
if (!Array.isArray(t) &&
|
|
540
|
+
return c(o(this, h).map((t) => {
|
|
541
|
+
if (!Array.isArray(t) && !$(t))
|
|
540
542
|
throw new TypeError("The items in the collection must be arrays or collections");
|
|
541
543
|
const r = Array.isArray(t) ? t : t.all();
|
|
542
544
|
return e(...r);
|
|
543
545
|
}));
|
|
544
546
|
}
|
|
545
547
|
mapToGroups(e) {
|
|
546
|
-
return o(this, h).reduce((t, r,
|
|
547
|
-
const
|
|
548
|
-
return Object.entries(
|
|
548
|
+
return o(this, h).reduce((t, r, i) => {
|
|
549
|
+
const s = e(r, i, this);
|
|
550
|
+
return Object.entries(s).forEach(([u, a]) => {
|
|
549
551
|
t[u] = t[u] ?? [], t[u].push(a);
|
|
550
552
|
}), t;
|
|
551
553
|
}, {});
|
|
552
554
|
}
|
|
553
555
|
mapWithKeys(e) {
|
|
554
|
-
return o(this, h).reduce((t, r,
|
|
555
|
-
const
|
|
556
|
-
return Object.entries(
|
|
556
|
+
return o(this, h).reduce((t, r, i) => {
|
|
557
|
+
const s = e(r, i, this);
|
|
558
|
+
return Object.entries(s).forEach(([u, a]) => {
|
|
557
559
|
t[u] = a;
|
|
558
560
|
}), t;
|
|
559
561
|
}, {});
|
|
@@ -563,33 +565,33 @@ class L {
|
|
|
563
565
|
}
|
|
564
566
|
median(e) {
|
|
565
567
|
if (typeof e == "string") {
|
|
566
|
-
const
|
|
567
|
-
return
|
|
568
|
+
const i = this.pluck(e).sort(), s = Math.floor(i.count() / 2);
|
|
569
|
+
return i.count() % 2 === 0 ? c([I(i, s - 1), I(i, s)]).avg() : I(i, s);
|
|
568
570
|
}
|
|
569
571
|
const t = o(this, h).toSorted(), r = Math.floor(t.length / 2);
|
|
570
|
-
return t.length % 2 === 0 ?
|
|
572
|
+
return t.length % 2 === 0 ? c([t[r - 1], t[r]]).avg() : t[r] ?? null;
|
|
571
573
|
}
|
|
572
574
|
merge(e) {
|
|
573
|
-
return Array.isArray(e) ?
|
|
575
|
+
return Array.isArray(e) ? c([...o(this, h), ...e]) : c([...o(this, h), ...e.all()]);
|
|
574
576
|
}
|
|
575
577
|
min(e) {
|
|
576
578
|
return typeof e == "string" ? o(this, h).reduce((t, r) => r[e] < t ? r[e] : t, o(this, h)[0][e]) : o(this, h).reduce((t, r) => r < t ? r : t, o(this, h)[0]);
|
|
577
579
|
}
|
|
578
580
|
mode(e) {
|
|
579
|
-
const t = typeof e == "string" ? this.filter((
|
|
580
|
-
return Object.entries(t).filter(([,
|
|
581
|
+
const t = typeof e == "string" ? this.filter((i) => ["number", "string"].includes(typeof i[e])).countBy((i) => i[e]) : this.countBy(), r = Math.max(...Object.values(t));
|
|
582
|
+
return Object.entries(t).filter(([, i]) => i === r).map(([i]) => i);
|
|
581
583
|
}
|
|
582
584
|
nth(e, t = 0) {
|
|
583
585
|
return this.chunk(e).filter((r) => r.count() > t).map((r) => r.get(t));
|
|
584
586
|
}
|
|
585
587
|
only(e) {
|
|
586
|
-
return
|
|
588
|
+
return c(o(this, h).filter((t, r) => e.includes(r)));
|
|
587
589
|
}
|
|
588
590
|
pad(e, t = null) {
|
|
589
591
|
const r = o(this, h).slice();
|
|
590
592
|
for (; r.length < Math.abs(e); )
|
|
591
593
|
e > 0 ? r.push(t) : r.unshift(t);
|
|
592
|
-
return
|
|
594
|
+
return c(r);
|
|
593
595
|
}
|
|
594
596
|
partition(e) {
|
|
595
597
|
return [
|
|
@@ -610,10 +612,10 @@ class L {
|
|
|
610
612
|
}
|
|
611
613
|
pipeThrough(e) {
|
|
612
614
|
return e.reduce((t, r) => {
|
|
613
|
-
if (
|
|
615
|
+
if (!$(t) && !Array.isArray(t))
|
|
614
616
|
throw new TypeError("The pipeline expects the carry to be a collection or an array");
|
|
615
617
|
return r(
|
|
616
|
-
|
|
618
|
+
$(t) ? t : c(t)
|
|
617
619
|
);
|
|
618
620
|
}, this);
|
|
619
621
|
}
|
|
@@ -622,64 +624,64 @@ class L {
|
|
|
622
624
|
}
|
|
623
625
|
pop(e = 1) {
|
|
624
626
|
const t = o(this, h).splice(o(this, h).length - e, e);
|
|
625
|
-
return
|
|
627
|
+
return T(this), e === 1 ? t[0] ?? null : c(t);
|
|
626
628
|
}
|
|
627
629
|
prepend(e) {
|
|
628
630
|
const t = o(this, h).unshift(e);
|
|
629
|
-
return
|
|
631
|
+
return T(this), t;
|
|
630
632
|
}
|
|
631
633
|
pull(e) {
|
|
632
634
|
const t = o(this, h).splice(e, 1)[0] ?? null;
|
|
633
|
-
return
|
|
635
|
+
return T(this), t;
|
|
634
636
|
}
|
|
635
637
|
push(...e) {
|
|
636
638
|
const t = o(this, h).push(...e);
|
|
637
|
-
return
|
|
639
|
+
return T(this), t;
|
|
638
640
|
}
|
|
639
641
|
put(e, t) {
|
|
640
|
-
return o(this, h).splice(e, 1, t),
|
|
642
|
+
return o(this, h).splice(e, 1, t), T(this), this;
|
|
641
643
|
}
|
|
642
644
|
random(e = 1) {
|
|
643
645
|
if (o(this, h).length < e)
|
|
644
646
|
throw new Error("The collection has fewer items than the requested amount");
|
|
645
|
-
const t =
|
|
647
|
+
const t = c(f.sampleSize(o(this, h), e));
|
|
646
648
|
return e === 1 ? t.first() : t;
|
|
647
649
|
}
|
|
648
650
|
reduce(e, t = null) {
|
|
649
|
-
return o(this, h).reduce((r,
|
|
651
|
+
return o(this, h).reduce((r, i, s) => e(r, i, s, this), t);
|
|
650
652
|
}
|
|
651
653
|
reject(e) {
|
|
652
654
|
return this.filter((t, r) => !e(t, r, this));
|
|
653
655
|
}
|
|
654
656
|
replace(e) {
|
|
655
657
|
const t = o(this, h).slice();
|
|
656
|
-
return Object.entries(e).forEach(([r,
|
|
657
|
-
t[parseInt(r)] =
|
|
658
|
-
}),
|
|
658
|
+
return Object.entries(e).forEach(([r, i]) => {
|
|
659
|
+
t[parseInt(r)] = i;
|
|
660
|
+
}), c(t);
|
|
659
661
|
}
|
|
660
662
|
reverse() {
|
|
661
|
-
return
|
|
663
|
+
return c(o(this, h).toReversed());
|
|
662
664
|
}
|
|
663
665
|
search(e, t = !1) {
|
|
664
|
-
if (typeof e != "function" || o(this, h).every((
|
|
665
|
-
const
|
|
666
|
-
return
|
|
666
|
+
if (typeof e != "function" || o(this, h).every((i) => typeof i == "function")) {
|
|
667
|
+
const i = o(this, h).findIndex((s) => t ? s === e : s == e);
|
|
668
|
+
return i === -1 ? !1 : i;
|
|
667
669
|
}
|
|
668
|
-
const r = o(this, h).findIndex((
|
|
670
|
+
const r = o(this, h).findIndex((i, s) => e(i, s, this));
|
|
669
671
|
return r === -1 ? !1 : r;
|
|
670
672
|
}
|
|
671
673
|
select(e) {
|
|
672
|
-
return this.map((t) => e.reduce((r,
|
|
674
|
+
return this.map((t) => e.reduce((r, i) => (r[i] = t[i], r), {}));
|
|
673
675
|
}
|
|
674
676
|
shift(e = 1) {
|
|
675
677
|
const t = o(this, h).splice(0, e);
|
|
676
|
-
return
|
|
678
|
+
return T(this), e === 1 ? t[0] ?? null : c(t);
|
|
677
679
|
}
|
|
678
680
|
shuffle() {
|
|
679
|
-
return
|
|
681
|
+
return c(f.shuffle(o(this, h)));
|
|
680
682
|
}
|
|
681
683
|
skip(e) {
|
|
682
|
-
return
|
|
684
|
+
return c(o(this, h).slice(e));
|
|
683
685
|
}
|
|
684
686
|
skipUntil(e) {
|
|
685
687
|
return typeof e == "function" ? this.skip(o(this, h).findIndex((t, r) => e(t, r, this))) : this.skip(o(this, h).findIndex((t) => t == e));
|
|
@@ -688,13 +690,13 @@ class L {
|
|
|
688
690
|
return typeof e == "function" ? this.skip(o(this, h).findIndex((t, r) => !e(t, r, this))) : this.skip(o(this, h).findIndex((t) => t != e));
|
|
689
691
|
}
|
|
690
692
|
slice(e, t) {
|
|
691
|
-
return
|
|
693
|
+
return c(typeof t > "u" ? o(this, h).slice(e) : typeof e > "u" ? o(this, h).slice(0, t) : o(this, h).slice(e, e + t));
|
|
692
694
|
}
|
|
693
695
|
sliding(e, t = 1) {
|
|
694
696
|
const r = [];
|
|
695
|
-
for (let
|
|
696
|
-
r.push(o(this, h).slice(
|
|
697
|
-
return
|
|
697
|
+
for (let i = 0; i < o(this, h).length && !(i + e > o(this, h).length); i += t)
|
|
698
|
+
r.push(o(this, h).slice(i, i + e));
|
|
699
|
+
return c(r.map((i) => c(i)));
|
|
698
700
|
}
|
|
699
701
|
sole(e, t) {
|
|
700
702
|
if (typeof e == "function") {
|
|
@@ -711,26 +713,26 @@ class L {
|
|
|
711
713
|
return this.contains(...e);
|
|
712
714
|
}
|
|
713
715
|
sort(e) {
|
|
714
|
-
return
|
|
716
|
+
return c(o(this, h).toSorted(e));
|
|
715
717
|
}
|
|
716
718
|
sortBy(e, t = "asc") {
|
|
717
719
|
if (typeof e == "function") {
|
|
718
720
|
let r = -1;
|
|
719
|
-
return
|
|
721
|
+
return c(o(this, h).toSorted((i, s) => (r++, e(i, r, this) - e(s, r, this))));
|
|
720
722
|
}
|
|
721
723
|
if (Array.isArray(e))
|
|
722
|
-
return e.every((r) => Array.isArray(r)) ?
|
|
723
|
-
for (const [
|
|
724
|
-
const a = r[
|
|
725
|
-
if (a >
|
|
724
|
+
return e.every((r) => Array.isArray(r)) ? c(o(this, h).toSorted((r, i) => {
|
|
725
|
+
for (const [s, u] of e) {
|
|
726
|
+
const a = r[s] ?? -1 / 0, l = i[s] ?? -1 / 0;
|
|
727
|
+
if (a > l)
|
|
726
728
|
return u === "asc" ? 1 : -1;
|
|
727
|
-
if (a <
|
|
729
|
+
if (a < l)
|
|
728
730
|
return u === "asc" ? -1 : 1;
|
|
729
731
|
}
|
|
730
732
|
return 0;
|
|
731
|
-
})) :
|
|
732
|
-
for (const
|
|
733
|
-
const u =
|
|
733
|
+
})) : c(o(this, h).toSorted((r, i) => {
|
|
734
|
+
for (const s of e) {
|
|
735
|
+
const u = s(r, i);
|
|
734
736
|
if (u !== 0)
|
|
735
737
|
return u;
|
|
736
738
|
}
|
|
@@ -738,31 +740,31 @@ class L {
|
|
|
738
740
|
}));
|
|
739
741
|
if (typeof e != "string")
|
|
740
742
|
throw new TypeError("The key must be a string");
|
|
741
|
-
return
|
|
742
|
-
const
|
|
743
|
-
return
|
|
743
|
+
return c(o(this, h).toSorted((r, i) => {
|
|
744
|
+
const s = r[e] ?? -1 / 0, u = i[e] ?? -1 / 0;
|
|
745
|
+
return s > u ? t === "asc" ? 1 : -1 : s < u ? t === "asc" ? -1 : 1 : 0;
|
|
744
746
|
}));
|
|
745
747
|
}
|
|
746
748
|
sortDesc() {
|
|
747
749
|
return this.sort((e, t) => e > t ? -1 : e < t ? 1 : 0);
|
|
748
750
|
}
|
|
749
751
|
splice(e, t, ...r) {
|
|
750
|
-
const
|
|
751
|
-
return
|
|
752
|
+
const i = t === void 0 ? o(this, h).length : t, s = o(this, h).splice(e, i, ...r);
|
|
753
|
+
return T(this), c(s);
|
|
752
754
|
}
|
|
753
755
|
split(e) {
|
|
754
756
|
const t = [];
|
|
755
757
|
for (let r = 0; r < e; r++) {
|
|
756
|
-
const
|
|
758
|
+
const i = o(this, h).slice(
|
|
757
759
|
t.flat().length,
|
|
758
760
|
t.flat().length + Math.min(
|
|
759
761
|
Math.ceil((o(this, h).length - t.flat().length) / (e - r)),
|
|
760
762
|
o(this, h).length - t.flat().length
|
|
761
763
|
)
|
|
762
764
|
);
|
|
763
|
-
t.push(
|
|
765
|
+
t.push(c(i));
|
|
764
766
|
}
|
|
765
|
-
return
|
|
767
|
+
return c(t);
|
|
766
768
|
}
|
|
767
769
|
splitIn(e) {
|
|
768
770
|
const t = Math.ceil(o(this, h).length / e);
|
|
@@ -770,10 +772,10 @@ class L {
|
|
|
770
772
|
}
|
|
771
773
|
sum(e) {
|
|
772
774
|
return typeof e == "string" ? o(this, h).reduce((t, r) => {
|
|
773
|
-
const
|
|
774
|
-
if (typeof
|
|
775
|
+
const i = r[e];
|
|
776
|
+
if (typeof i != "number")
|
|
775
777
|
throw new TypeError("The items must be numbers");
|
|
776
|
-
return t +
|
|
778
|
+
return t + i;
|
|
777
779
|
}, 0) : o(this, h).reduce((t, r) => {
|
|
778
780
|
if (typeof r != "number")
|
|
779
781
|
throw new TypeError("The items must be numbers");
|
|
@@ -781,7 +783,7 @@ class L {
|
|
|
781
783
|
}, 0);
|
|
782
784
|
}
|
|
783
785
|
take(e) {
|
|
784
|
-
return
|
|
786
|
+
return c(o(this, h).slice(0, e));
|
|
785
787
|
}
|
|
786
788
|
takeUntil(e) {
|
|
787
789
|
return typeof e == "function" ? this.take(o(this, h).findIndex((t, r) => e(t, r, this))) : this.take(o(this, h).findIndex((t) => t == e));
|
|
@@ -802,13 +804,13 @@ class L {
|
|
|
802
804
|
transform(e) {
|
|
803
805
|
for (const [t, r] of o(this, h).entries())
|
|
804
806
|
o(this, h).splice(t, 1, e(r, t, this));
|
|
805
|
-
return
|
|
807
|
+
return T(this), this;
|
|
806
808
|
}
|
|
807
809
|
unique(e) {
|
|
808
|
-
return
|
|
810
|
+
return c(typeof e == "string" ? o(this, h).filter((t, r) => !o(this, h).some((i, s) => i[e] == t[e] && s !== r)) : [...new Set(o(this, h))]);
|
|
809
811
|
}
|
|
810
812
|
uniqueStrict(e) {
|
|
811
|
-
return
|
|
813
|
+
return c(typeof e == "string" ? o(this, h).filter((t, r) => !o(this, h).some((i, s) => i[e] === t[e] && s !== r)) : [...new Set(o(this, h))]);
|
|
812
814
|
}
|
|
813
815
|
unless(e, t, r) {
|
|
814
816
|
return e ? typeof r == "function" && r(this) : t(this), this;
|
|
@@ -833,112 +835,117 @@ class L {
|
|
|
833
835
|
}
|
|
834
836
|
where(e, t, r) {
|
|
835
837
|
if (typeof r > "u")
|
|
836
|
-
return
|
|
838
|
+
return c(o(this, h).filter((s) => s[e] == t));
|
|
837
839
|
if (typeof t != "string")
|
|
838
840
|
throw new TypeError("The operator must be a string");
|
|
839
841
|
if (r === null)
|
|
840
|
-
return
|
|
841
|
-
const
|
|
842
|
-
"=": (
|
|
843
|
-
"!=": (
|
|
844
|
-
">": (
|
|
845
|
-
"<": (
|
|
846
|
-
">=": (
|
|
847
|
-
"<=": (
|
|
842
|
+
return c(o(this, h).filter((s) => s[e] === null));
|
|
843
|
+
const i = {
|
|
844
|
+
"=": (s) => s[e] == r,
|
|
845
|
+
"!=": (s) => s[e] != r,
|
|
846
|
+
">": (s) => s[e] > r,
|
|
847
|
+
"<": (s) => s[e] < r,
|
|
848
|
+
">=": (s) => s[e] >= r,
|
|
849
|
+
"<=": (s) => s[e] <= r
|
|
848
850
|
};
|
|
849
|
-
if (!(t in
|
|
851
|
+
if (!(t in i))
|
|
850
852
|
throw new Error("Unsupported operator");
|
|
851
|
-
return
|
|
853
|
+
return c(o(this, h).filter((s, u) => i[t](s, u, this)));
|
|
852
854
|
}
|
|
853
855
|
whereStrict(e, t, r) {
|
|
854
856
|
if (typeof r > "u")
|
|
855
|
-
return
|
|
857
|
+
return c(o(this, h).filter((s) => s[e] === t));
|
|
856
858
|
if (typeof t != "string")
|
|
857
859
|
throw new TypeError("The operator must be a string");
|
|
858
860
|
if (r === null)
|
|
859
|
-
return
|
|
860
|
-
const
|
|
861
|
-
"=": (
|
|
862
|
-
"!=": (
|
|
863
|
-
">": (
|
|
864
|
-
"<": (
|
|
865
|
-
">=": (
|
|
866
|
-
"<=": (
|
|
861
|
+
return c(o(this, h).filter((s) => s[e] === null));
|
|
862
|
+
const i = {
|
|
863
|
+
"=": (s) => s[e] === r,
|
|
864
|
+
"!=": (s) => s[e] !== r,
|
|
865
|
+
">": (s) => s[e] > r,
|
|
866
|
+
"<": (s) => s[e] < r,
|
|
867
|
+
">=": (s) => s[e] >= r,
|
|
868
|
+
"<=": (s) => s[e] <= r
|
|
867
869
|
};
|
|
868
|
-
if (!(t in
|
|
870
|
+
if (!(t in i))
|
|
869
871
|
throw new Error("Unsupported operator");
|
|
870
|
-
return
|
|
872
|
+
return c(o(this, h).filter((s, u) => i[t](s, u, this)));
|
|
871
873
|
}
|
|
872
874
|
whereBetween(e, [t, r]) {
|
|
873
|
-
return
|
|
875
|
+
return c(o(this, h).filter((i) => i[e] >= t && i[e] <= r));
|
|
874
876
|
}
|
|
875
877
|
whereIn(e, t) {
|
|
876
|
-
return
|
|
878
|
+
return c(o(this, h).filter((r) => t.includes(r[e])));
|
|
877
879
|
}
|
|
878
880
|
whereInstanceOf(e) {
|
|
879
|
-
return
|
|
881
|
+
return c(o(this, h).filter((t) => t instanceof e));
|
|
880
882
|
}
|
|
881
883
|
whereNotBetween(e, [t, r]) {
|
|
882
|
-
return
|
|
884
|
+
return c(o(this, h).filter((i) => i[e] < t || i[e] > r));
|
|
883
885
|
}
|
|
884
886
|
whereNotIn(e, t) {
|
|
885
|
-
return
|
|
887
|
+
return c(o(this, h).filter((r) => !t.includes(r[e])));
|
|
886
888
|
}
|
|
887
889
|
whereNotNull(e) {
|
|
888
|
-
return
|
|
890
|
+
return c(o(this, h).filter((t) => t[e] !== null));
|
|
889
891
|
}
|
|
890
892
|
whereNull(e) {
|
|
891
|
-
return
|
|
893
|
+
return c(o(this, h).filter((t) => t[e] === null));
|
|
892
894
|
}
|
|
893
895
|
zip(e) {
|
|
894
|
-
return Array.isArray(e) ?
|
|
896
|
+
return Array.isArray(e) ? c(
|
|
895
897
|
o(this, h).map((t, r) => [t, e[r] ?? null])
|
|
896
|
-
) :
|
|
898
|
+
) : c(
|
|
897
899
|
o(this, h).map((t, r) => [t, e.get(r)])
|
|
898
900
|
);
|
|
899
901
|
}
|
|
900
902
|
// HasEvents methods
|
|
901
903
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
902
904
|
on(e, t) {
|
|
903
|
-
throw new
|
|
905
|
+
throw new w();
|
|
904
906
|
}
|
|
905
907
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
906
908
|
once(e, t) {
|
|
907
|
-
throw new
|
|
909
|
+
throw new w();
|
|
908
910
|
}
|
|
909
911
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
910
912
|
emit(e, t) {
|
|
911
|
-
throw new
|
|
913
|
+
throw new w();
|
|
912
914
|
}
|
|
913
915
|
}
|
|
914
916
|
h = new WeakMap();
|
|
915
|
-
const
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
917
|
+
const C = S(Q);
|
|
918
|
+
var ee, te;
|
|
919
|
+
class W extends (te = Q, ee = Symbol.toStringTag, te) {
|
|
920
|
+
constructor() {
|
|
921
|
+
super(...arguments);
|
|
922
|
+
g(this, ee, "Collection");
|
|
923
|
+
}
|
|
924
|
+
intersect(t) {
|
|
925
|
+
return this.filter((r) => t.some((i) => i.getKey() === r.getKey()));
|
|
919
926
|
}
|
|
920
927
|
}
|
|
921
|
-
|
|
922
|
-
const S = (...n) => {
|
|
928
|
+
const R = (...n) => {
|
|
923
929
|
const e = new URLSearchParams();
|
|
924
930
|
return n.forEach((t) => {
|
|
925
931
|
const [, ...r] = t.split("?");
|
|
926
|
-
new URLSearchParams(r.join("")).forEach((
|
|
927
|
-
e.set(u,
|
|
932
|
+
new URLSearchParams(r.join("")).forEach((s, u) => {
|
|
933
|
+
e.set(u, s);
|
|
928
934
|
});
|
|
929
935
|
}), e;
|
|
930
936
|
};
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
937
|
+
var re, se;
|
|
938
|
+
class We extends (se = Error, re = Symbol.toStringTag, se) {
|
|
939
|
+
constructor(t) {
|
|
940
|
+
super(`[Luminix] Model "${t}" does not have a primary key`);
|
|
941
|
+
g(this, re, "ModelWithoutPrimaryKeyException");
|
|
934
942
|
}
|
|
935
943
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
class _e {
|
|
944
|
+
const Ge = S(A);
|
|
945
|
+
class Ve {
|
|
939
946
|
constructor(e, t, r = {}) {
|
|
940
|
-
|
|
941
|
-
this.facades = e, this.abstract = t, this.query = r, this.bag = new
|
|
947
|
+
g(this, "bag");
|
|
948
|
+
this.facades = e, this.abstract = t, this.query = r, this.bag = new Ge(r), this.bag.on("change", () => {
|
|
942
949
|
this.emit("change", {
|
|
943
950
|
data: this.bag
|
|
944
951
|
});
|
|
@@ -946,15 +953,15 @@ class _e {
|
|
|
946
953
|
}
|
|
947
954
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
948
955
|
on(e, t) {
|
|
949
|
-
throw new
|
|
956
|
+
throw new w();
|
|
950
957
|
}
|
|
951
958
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
952
959
|
once(e, t) {
|
|
953
|
-
throw new
|
|
960
|
+
throw new w();
|
|
954
961
|
}
|
|
955
962
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
956
963
|
emit(e, t) {
|
|
957
|
-
throw new
|
|
964
|
+
throw new w();
|
|
958
965
|
}
|
|
959
966
|
lock(e) {
|
|
960
967
|
this.bag.lock(e);
|
|
@@ -981,7 +988,7 @@ class _e {
|
|
|
981
988
|
return this.bag.set(`where.${f.camelCase(e)}`, t), this;
|
|
982
989
|
if (typeof t != "string")
|
|
983
990
|
throw new Error(`Invalid operator ${t} provided for where clause.`);
|
|
984
|
-
const
|
|
991
|
+
const s = {
|
|
985
992
|
"=": "",
|
|
986
993
|
"!=": "NotEquals",
|
|
987
994
|
">": "GreaterThan",
|
|
@@ -989,7 +996,7 @@ class _e {
|
|
|
989
996
|
"<": "LessThan",
|
|
990
997
|
"<=": "LessThanOrEquals"
|
|
991
998
|
}[t] || f.upperFirst(f.camelCase(t));
|
|
992
|
-
return this.bag.set(`where.${f.camelCase(e)}${
|
|
999
|
+
return this.bag.set(`where.${f.camelCase(e)}${s}`, r), this;
|
|
993
1000
|
}
|
|
994
1001
|
orderBy(e, t = "asc") {
|
|
995
1002
|
return this.bag.set("order_by", `${e}:${t}`), this;
|
|
@@ -1011,36 +1018,36 @@ class _e {
|
|
|
1011
1018
|
const { data: r } = await this.facades.route.call(`luminix.${this.abstract}.index`, {
|
|
1012
1019
|
params: this.bag.all(),
|
|
1013
1020
|
errorBag: `${this.abstract}.fetch`
|
|
1014
|
-
}),
|
|
1015
|
-
const a = new
|
|
1021
|
+
}), i = this.facades.model.make(this.abstract), s = c(r.data.map((u) => {
|
|
1022
|
+
const a = new i(u);
|
|
1016
1023
|
return a.exists = !0, this.facades.model.emit("fetch", {
|
|
1017
1024
|
class: this.abstract,
|
|
1018
1025
|
model: a
|
|
1019
1026
|
}), a;
|
|
1020
|
-
}),
|
|
1027
|
+
}), W);
|
|
1021
1028
|
if (t) {
|
|
1022
1029
|
const [u] = t.split("?");
|
|
1023
1030
|
return {
|
|
1024
1031
|
...r,
|
|
1025
|
-
data:
|
|
1032
|
+
data: s,
|
|
1026
1033
|
links: {
|
|
1027
|
-
first: `${u}?${
|
|
1028
|
-
last: `${u}?${
|
|
1029
|
-
next: r.links.next && `${u}?${
|
|
1030
|
-
prev: r.links.prev && `${u}?${
|
|
1034
|
+
first: `${u}?${R(t, r.links.first).toString()}`,
|
|
1035
|
+
last: `${u}?${R(t, r.links.last).toString()}`,
|
|
1036
|
+
next: r.links.next && `${u}?${R(t, r.links.next).toString()}`,
|
|
1037
|
+
prev: r.links.prev && `${u}?${R(t, r.links.prev).toString()}`
|
|
1031
1038
|
},
|
|
1032
1039
|
meta: {
|
|
1033
1040
|
...r.meta,
|
|
1034
1041
|
links: r.meta.links.map((a) => ({
|
|
1035
1042
|
...a,
|
|
1036
|
-
url: a.url && `${u}?${
|
|
1043
|
+
url: a.url && `${u}?${R(t, a.url).toString()}`
|
|
1037
1044
|
}))
|
|
1038
1045
|
}
|
|
1039
1046
|
};
|
|
1040
1047
|
}
|
|
1041
1048
|
return {
|
|
1042
1049
|
...r,
|
|
1043
|
-
data:
|
|
1050
|
+
data: s
|
|
1044
1051
|
};
|
|
1045
1052
|
} catch (r) {
|
|
1046
1053
|
throw this.emit("error", {
|
|
@@ -1065,7 +1072,7 @@ class _e {
|
|
|
1065
1072
|
async find(e) {
|
|
1066
1073
|
const t = this.facades.model.schema(this.abstract).primaryKey;
|
|
1067
1074
|
if (!t)
|
|
1068
|
-
throw new
|
|
1075
|
+
throw new We(this.abstract);
|
|
1069
1076
|
const r = await this.where(t, e).limit(1).exec(1);
|
|
1070
1077
|
return this.emit("success", {
|
|
1071
1078
|
response: r,
|
|
@@ -1076,11 +1083,11 @@ class _e {
|
|
|
1076
1083
|
const e = this.facades.config.get("luminix.backend.api.max_per_page", 150), t = await this.limit(e).exec(1), r = t.meta.last_page;
|
|
1077
1084
|
if (r === 1)
|
|
1078
1085
|
return t.data;
|
|
1079
|
-
const
|
|
1080
|
-
|
|
1081
|
-
), u =
|
|
1082
|
-
|
|
1083
|
-
|
|
1086
|
+
const i = Array.from({ length: r - 1 }, (a, l) => l + 2), s = await Promise.all(
|
|
1087
|
+
i.map((a) => this.limit(e).exec(a))
|
|
1088
|
+
), u = c(
|
|
1089
|
+
s.reduce((a, l) => (a.push(...l.data), a), t.data).all(),
|
|
1090
|
+
W
|
|
1084
1091
|
);
|
|
1085
1092
|
return this.emit("success", {
|
|
1086
1093
|
response: {
|
|
@@ -1091,39 +1098,43 @@ class _e {
|
|
|
1091
1098
|
}), u;
|
|
1092
1099
|
}
|
|
1093
1100
|
}
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1101
|
+
const Xe = S(Ve);
|
|
1102
|
+
var ie, ne;
|
|
1103
|
+
class _ extends (ne = Error, ie = Symbol.toStringTag, ne) {
|
|
1104
|
+
constructor(t) {
|
|
1105
|
+
super(`[Luminix] Expected ${t} to be reducible.`);
|
|
1106
|
+
g(this, ie, "NotReducibleException");
|
|
1098
1107
|
}
|
|
1099
1108
|
}
|
|
1100
|
-
|
|
1101
|
-
class
|
|
1102
|
-
constructor(
|
|
1103
|
-
super(`[Luminix] "${
|
|
1109
|
+
var oe, he;
|
|
1110
|
+
class x extends (he = TypeError, oe = Symbol.toStringTag, he) {
|
|
1111
|
+
constructor(t, r = "Model") {
|
|
1112
|
+
super(`[Luminix] "${t}" expects ${r}`);
|
|
1113
|
+
g(this, oe, "NotModelException");
|
|
1104
1114
|
}
|
|
1105
1115
|
}
|
|
1106
|
-
|
|
1107
|
-
class
|
|
1108
|
-
constructor(
|
|
1109
|
-
super(`[Luminix] Could not determine inverse relation for "${
|
|
1116
|
+
var ue, ae;
|
|
1117
|
+
class Ye extends (ae = Error, ue = Symbol.toStringTag, ae) {
|
|
1118
|
+
constructor(t, r, i, s) {
|
|
1119
|
+
super(`[Luminix] Could not determine inverse relation for "${r}" in model "${t}". Please specify a relation in model "${i}" of type ${s} that points back to "${t}".`);
|
|
1120
|
+
g(this, ue, "NoInverseRelationException");
|
|
1110
1121
|
}
|
|
1111
1122
|
}
|
|
1112
|
-
|
|
1113
|
-
class
|
|
1114
|
-
constructor(
|
|
1115
|
-
super(`[Luminix] Relation "${
|
|
1123
|
+
var le, ce;
|
|
1124
|
+
class Ze extends (ce = Error, le = Symbol.toStringTag, ce) {
|
|
1125
|
+
constructor(t) {
|
|
1126
|
+
super(`[Luminix] Relation "${t}" is not supported`);
|
|
1127
|
+
g(this, le, "UnsupportedRelationException");
|
|
1116
1128
|
}
|
|
1117
1129
|
}
|
|
1118
|
-
|
|
1119
|
-
function w(n) {
|
|
1130
|
+
function b(n) {
|
|
1120
1131
|
return typeof n == "object" && n !== null && n.__isModel === !0;
|
|
1121
1132
|
}
|
|
1122
1133
|
class j {
|
|
1123
|
-
constructor(e, t, r,
|
|
1124
|
-
|
|
1125
|
-
if (this.meta = e, this.facades = t, this.parent = r, this.items =
|
|
1126
|
-
throw new
|
|
1134
|
+
constructor(e, t, r, i = null) {
|
|
1135
|
+
g(this, "unsubscribeQuery", null);
|
|
1136
|
+
if (this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !b(i) && !($(i) && i.every(b)))
|
|
1137
|
+
throw new x("Relation.constructor()", "Model, Collection<Model> or null");
|
|
1127
1138
|
}
|
|
1128
1139
|
make(e) {
|
|
1129
1140
|
const t = this.getRelated();
|
|
@@ -1139,13 +1150,13 @@ class j {
|
|
|
1139
1150
|
if (this.isMultiple()) {
|
|
1140
1151
|
if (!Array.isArray(e))
|
|
1141
1152
|
throw new TypeError("Relation.make() expects an array");
|
|
1142
|
-
this.set(
|
|
1153
|
+
this.set(c(e.map((r) => new t(r))));
|
|
1143
1154
|
}
|
|
1144
1155
|
}
|
|
1145
1156
|
guessInverseRelation() {
|
|
1146
1157
|
const { relations: e } = this.getRelated().getSchema();
|
|
1147
1158
|
if (typeof this.facades.model.guessInverseRelation != "function")
|
|
1148
|
-
throw new
|
|
1159
|
+
throw new _("ModelFacade");
|
|
1149
1160
|
const t = this.getType(), r = this.facades.model.guessInverseRelation({
|
|
1150
1161
|
HasOne: ["BelongsTo"],
|
|
1151
1162
|
HasMany: ["BelongsTo"],
|
|
@@ -1157,18 +1168,18 @@ class j {
|
|
|
1157
1168
|
MorphToMany: ["MorphToMany"]
|
|
1158
1169
|
}, this.parent, t, this.getRelated());
|
|
1159
1170
|
if (!(t in r))
|
|
1160
|
-
throw new
|
|
1161
|
-
for (const
|
|
1162
|
-
const
|
|
1163
|
-
if ((
|
|
1164
|
-
return
|
|
1171
|
+
throw new Ze(t);
|
|
1172
|
+
for (const i in e) {
|
|
1173
|
+
const s = e[i];
|
|
1174
|
+
if ((s.model === this.parent.getType() || ["MorphOne", "MorphMany"].includes(t)) && r[t].includes(s.type))
|
|
1175
|
+
return i;
|
|
1165
1176
|
}
|
|
1166
|
-
throw new
|
|
1177
|
+
throw new Ye(this.parent.getType(), t, this.getRelated().getSchemaName(), r[t].join(" or "));
|
|
1167
1178
|
}
|
|
1168
1179
|
set(e) {
|
|
1169
|
-
if (e !== null && !
|
|
1170
|
-
throw new
|
|
1171
|
-
!this.items ||
|
|
1180
|
+
if (e !== null && !b(e) && !($(e) && e.every(b)))
|
|
1181
|
+
throw new x("Relation.set()", "Model, Collection<Model> or null");
|
|
1182
|
+
!this.items || b(this.items) ? this.items = e : $(e) && this.items.splice(0, this.items.count(), ...e);
|
|
1172
1183
|
}
|
|
1173
1184
|
getForeignKey() {
|
|
1174
1185
|
return this.meta.foreignKey;
|
|
@@ -1198,10 +1209,10 @@ class j {
|
|
|
1198
1209
|
return this.items;
|
|
1199
1210
|
}
|
|
1200
1211
|
isSingle() {
|
|
1201
|
-
return
|
|
1212
|
+
return b(this.items);
|
|
1202
1213
|
}
|
|
1203
1214
|
isMultiple() {
|
|
1204
|
-
return
|
|
1215
|
+
return $(this.items);
|
|
1205
1216
|
}
|
|
1206
1217
|
getParent() {
|
|
1207
1218
|
return this.parent;
|
|
@@ -1246,45 +1257,50 @@ class j {
|
|
|
1246
1257
|
// return this.query().find(id);
|
|
1247
1258
|
// }
|
|
1248
1259
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1260
|
+
var de, fe;
|
|
1261
|
+
class Ne extends (fe = Error, de = Symbol.toStringTag, fe) {
|
|
1262
|
+
constructor(t, r) {
|
|
1263
|
+
super(`[Luminix] Attribute "${r}" in model "${t}" is not fillable`);
|
|
1264
|
+
g(this, de, "AttributeNotFillableException");
|
|
1252
1265
|
}
|
|
1253
1266
|
}
|
|
1254
|
-
|
|
1255
|
-
class
|
|
1256
|
-
constructor(
|
|
1257
|
-
super(`[Luminix] Model "${
|
|
1267
|
+
var pe, me;
|
|
1268
|
+
class Re extends (me = Error, pe = Symbol.toStringTag, me) {
|
|
1269
|
+
constructor(t, r) {
|
|
1270
|
+
super(`[Luminix] Model "${t}" must be persisted before calling "${r}"`);
|
|
1271
|
+
g(this, pe, "ModelNotPersistedException");
|
|
1258
1272
|
}
|
|
1259
1273
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1274
|
+
function ze(n, e) {
|
|
1275
|
+
var r;
|
|
1276
|
+
r = Symbol.toStringTag;
|
|
1262
1277
|
class t {
|
|
1263
1278
|
constructor(s = {}) {
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1279
|
+
g(this, "_attributes", new A({}));
|
|
1280
|
+
g(this, "_original", {});
|
|
1281
|
+
g(this, "_relations", {});
|
|
1282
|
+
g(this, "_changedKeys", []);
|
|
1283
|
+
g(this, "exists", !1);
|
|
1284
|
+
g(this, r, f.upperFirst(f.camelCase(e)));
|
|
1269
1285
|
this.makeRelations(), this.makeAttributes(s);
|
|
1270
1286
|
}
|
|
1271
|
-
cast(s,
|
|
1272
|
-
return s == null || !
|
|
1287
|
+
cast(s, u) {
|
|
1288
|
+
return s == null || !u ? s : ["boolean", "bool"].includes(u) ? !!s : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(u) && typeof s == "string" ? new Date(s) : ["float", "double", "integer", "int"].includes(u) || u.startsWith("decimal:") ? Number(s) : s;
|
|
1273
1289
|
}
|
|
1274
|
-
mutate(s,
|
|
1275
|
-
return s == null || !
|
|
1290
|
+
mutate(s, u) {
|
|
1291
|
+
return s == null || !u ? s : ["boolean", "bool"].includes(u) ? !!s : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(u) && s instanceof Date ? s.toISOString() : ["float", "double", "integer", "int"].includes(u) || u.startsWith("decimal:") ? Number(s) : s;
|
|
1276
1292
|
}
|
|
1277
1293
|
makeRelations() {
|
|
1278
1294
|
const { relations: s } = n.model.schema(e);
|
|
1279
1295
|
if (this._relations = {}, !s)
|
|
1280
1296
|
return;
|
|
1281
1297
|
if (typeof n.model.relationMap != "function")
|
|
1282
|
-
throw new
|
|
1283
|
-
const
|
|
1284
|
-
Object.entries(s).forEach(([
|
|
1285
|
-
const { type:
|
|
1286
|
-
this._relations[
|
|
1287
|
-
{ name:
|
|
1298
|
+
throw new _("ModelFacade");
|
|
1299
|
+
const u = n.model.relationMap({}, e);
|
|
1300
|
+
Object.entries(s).forEach(([a, l]) => {
|
|
1301
|
+
const { type: d } = l, p = d in u ? u[d] : j;
|
|
1302
|
+
this._relations[a] = new p(
|
|
1303
|
+
{ name: a, ...l },
|
|
1288
1304
|
n,
|
|
1289
1305
|
this,
|
|
1290
1306
|
null
|
|
@@ -1292,12 +1308,12 @@ function $e(n, e) {
|
|
|
1292
1308
|
});
|
|
1293
1309
|
}
|
|
1294
1310
|
makeAttributes(s) {
|
|
1295
|
-
const { relations:
|
|
1296
|
-
if (this.fillable.filter((
|
|
1297
|
-
|
|
1298
|
-
}),
|
|
1299
|
-
this.relation(f.camelCase(
|
|
1300
|
-
}), !this.validateJsonObject(
|
|
1311
|
+
const { relations: u } = n.model.schema(e), a = Object.keys(u || {}), l = f.omit(s, a);
|
|
1312
|
+
if (this.fillable.filter((d) => !(d in l)).forEach((d) => {
|
|
1313
|
+
l[d] = null;
|
|
1314
|
+
}), u && Object.keys(u).forEach((d) => {
|
|
1315
|
+
this.relation(f.camelCase(d)).make(s[d]);
|
|
1316
|
+
}), !this.validateJsonObject(l)) {
|
|
1301
1317
|
if (n.config.get("app.env", "production") === "production")
|
|
1302
1318
|
throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
|
|
1303
1319
|
n.log.warning(`Invalid attributes for model "${e}".
|
|
@@ -1306,7 +1322,7 @@ function $e(n, e) {
|
|
|
1306
1322
|
abstract: e
|
|
1307
1323
|
});
|
|
1308
1324
|
}
|
|
1309
|
-
this._attributes = new
|
|
1325
|
+
this._attributes = new A(l), this._original = l, this._changedKeys = [];
|
|
1310
1326
|
}
|
|
1311
1327
|
makePrimaryKeyReplacer() {
|
|
1312
1328
|
return {
|
|
@@ -1360,23 +1376,23 @@ function $e(n, e) {
|
|
|
1360
1376
|
model: this
|
|
1361
1377
|
});
|
|
1362
1378
|
}
|
|
1363
|
-
dispatchErrorEvent(s,
|
|
1379
|
+
dispatchErrorEvent(s, u) {
|
|
1364
1380
|
this.emit("error", {
|
|
1365
1381
|
error: s,
|
|
1366
|
-
operation:
|
|
1382
|
+
operation: u
|
|
1367
1383
|
}), n.model.emit("error", {
|
|
1368
1384
|
class: e,
|
|
1369
1385
|
model: this,
|
|
1370
1386
|
error: s,
|
|
1371
|
-
operation:
|
|
1387
|
+
operation: u
|
|
1372
1388
|
});
|
|
1373
1389
|
}
|
|
1374
1390
|
updateChangedKeys(s) {
|
|
1375
|
-
const
|
|
1376
|
-
!this._changedKeys.includes(s) && !
|
|
1391
|
+
const u = (a, l) => typeof a == "object" && a !== null ? f.isEqual(a, l) : a == l;
|
|
1392
|
+
!this._changedKeys.includes(s) && !u(this._original[s], this._attributes.get("key")) ? this._changedKeys.push(s) : this._changedKeys.includes(s) && u(this._original[s], this._attributes.get("key")) && this._changedKeys.splice(this._changedKeys.indexOf(s), 1);
|
|
1377
1393
|
}
|
|
1378
1394
|
validateJsonObject(s) {
|
|
1379
|
-
return typeof s != "object" || s === null ? !1 : Object.entries(s).every(([,
|
|
1395
|
+
return typeof s != "object" || s === null ? !1 : Object.entries(s).every(([, u]) => ["boolean", "number", "string"].includes(typeof u) || u === null || this.validateJsonObject(u) || Array.isArray(u) && u.every((a) => this.validateJsonObject(a)));
|
|
1380
1396
|
}
|
|
1381
1397
|
get attributes() {
|
|
1382
1398
|
return this._attributes.all();
|
|
@@ -1410,42 +1426,42 @@ function $e(n, e) {
|
|
|
1410
1426
|
return this._changedKeys.length > 0;
|
|
1411
1427
|
}
|
|
1412
1428
|
getAttribute(s) {
|
|
1413
|
-
let
|
|
1414
|
-
s in this.casts && (
|
|
1415
|
-
const
|
|
1416
|
-
if (typeof
|
|
1417
|
-
throw new
|
|
1418
|
-
return
|
|
1419
|
-
}
|
|
1420
|
-
setAttribute(s,
|
|
1429
|
+
let u = this._attributes.get(s, null);
|
|
1430
|
+
s in this.casts && (u = this.cast(u, this.casts[s]));
|
|
1431
|
+
const a = n.model[`model${f.upperFirst(f.camelCase(e))}Get${f.upperFirst(f.camelCase(s))}Attribute`];
|
|
1432
|
+
if (typeof a != "function")
|
|
1433
|
+
throw new _("ModelFacade");
|
|
1434
|
+
return a.bind(n.model)(u, this);
|
|
1435
|
+
}
|
|
1436
|
+
setAttribute(s, u) {
|
|
1421
1437
|
if (!this.fillable.includes(s)) {
|
|
1422
1438
|
if (n.config.get("app.env", "production") === "production")
|
|
1423
|
-
throw new
|
|
1439
|
+
throw new Ne(e, s);
|
|
1424
1440
|
n.log.warning(`[Luminix] Trying to set a non-fillable attribute "${s}" in model "${e}".
|
|
1425
1441
|
This will throw an error in production.`);
|
|
1426
1442
|
return;
|
|
1427
1443
|
}
|
|
1428
|
-
const
|
|
1429
|
-
if (typeof
|
|
1430
|
-
throw new
|
|
1431
|
-
const
|
|
1432
|
-
this.mutate(
|
|
1444
|
+
const a = n.model[`model${f.upperFirst(f.camelCase(e))}Set${f.upperFirst(f.camelCase(s))}Attribute`];
|
|
1445
|
+
if (typeof a != "function")
|
|
1446
|
+
throw new _("ModelFacade");
|
|
1447
|
+
const l = a.bind(n.model)(
|
|
1448
|
+
this.mutate(u, this.casts[s]),
|
|
1433
1449
|
this
|
|
1434
1450
|
);
|
|
1435
|
-
if (!this.validateJsonObject({ [s]:
|
|
1451
|
+
if (!this.validateJsonObject({ [s]: l })) {
|
|
1436
1452
|
if (n.config.get("app.env", "production") === "production")
|
|
1437
1453
|
throw new TypeError(`[Luminix] Attribute "${s}" in model "${e}" must be a boolean, number, string or null`);
|
|
1438
1454
|
n.log.warning(`Invalid type for attribute "${s}" in model "${e}" after mutation.
|
|
1439
1455
|
This will throw an error in production.`, {
|
|
1440
1456
|
key: s,
|
|
1441
|
-
value:
|
|
1442
|
-
mutated:
|
|
1457
|
+
value: u,
|
|
1458
|
+
mutated: l,
|
|
1443
1459
|
cast: this.casts[s],
|
|
1444
1460
|
item: this.toJson()
|
|
1445
1461
|
});
|
|
1446
1462
|
return;
|
|
1447
1463
|
}
|
|
1448
|
-
this._attributes.set(s,
|
|
1464
|
+
this._attributes.set(s, l), this.updateChangedKeys(s), this.dispatchChangeEvent({ [s]: l });
|
|
1449
1465
|
}
|
|
1450
1466
|
getKey() {
|
|
1451
1467
|
return this.getAttribute(this.primaryKey);
|
|
@@ -1454,28 +1470,28 @@ function $e(n, e) {
|
|
|
1454
1470
|
return this.primaryKey;
|
|
1455
1471
|
}
|
|
1456
1472
|
fill(s) {
|
|
1457
|
-
const
|
|
1458
|
-
const
|
|
1459
|
-
if (typeof
|
|
1460
|
-
throw new
|
|
1461
|
-
return
|
|
1462
|
-
this.mutate(
|
|
1473
|
+
const u = f.pick(s, this.fillable), a = Object.entries(u).reduce((l, [d, p]) => {
|
|
1474
|
+
const y = n.model[`model${f.upperFirst(f.camelCase(e))}Set${f.upperFirst(f.camelCase(d))}Attribute`];
|
|
1475
|
+
if (typeof y != "function")
|
|
1476
|
+
throw new _("ModelFacade");
|
|
1477
|
+
return l[d] = y.bind(n.model)(
|
|
1478
|
+
this.mutate(p, this.casts[d]),
|
|
1463
1479
|
this
|
|
1464
|
-
),
|
|
1480
|
+
), l;
|
|
1465
1481
|
}, {});
|
|
1466
|
-
if (!this.validateJsonObject(
|
|
1482
|
+
if (!this.validateJsonObject(a)) {
|
|
1467
1483
|
if (n.config.get("app.env", "production") === "production")
|
|
1468
1484
|
throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
|
|
1469
1485
|
n.log.warning(`Invalid attributes for model "${e}" after mutation.
|
|
1470
1486
|
This will throw an error in production.`, {
|
|
1471
1487
|
attributes: s,
|
|
1472
|
-
mutatedAttributes:
|
|
1488
|
+
mutatedAttributes: a,
|
|
1473
1489
|
item: this.toJson(),
|
|
1474
1490
|
casts: this.casts
|
|
1475
1491
|
});
|
|
1476
1492
|
return;
|
|
1477
1493
|
}
|
|
1478
|
-
this._attributes.merge(".",
|
|
1494
|
+
this._attributes.merge(".", a), Object.keys(a).forEach((l) => this.updateChangedKeys(l)), this.dispatchChangeEvent(a);
|
|
1479
1495
|
}
|
|
1480
1496
|
dump() {
|
|
1481
1497
|
n.log.info({
|
|
@@ -1484,16 +1500,16 @@ function $e(n, e) {
|
|
|
1484
1500
|
});
|
|
1485
1501
|
}
|
|
1486
1502
|
toJson() {
|
|
1487
|
-
const s = Object.entries(this.relations).reduce((
|
|
1488
|
-
if (typeof
|
|
1489
|
-
throw new
|
|
1490
|
-
return
|
|
1503
|
+
const s = Object.entries(this.relations).reduce((a, [l, d]) => (d.isLoaded() && (d.isSingle() ? a[f.snakeCase(l)] = d.getLoadedItems().toJson() : d.isMultiple() && (a[f.snakeCase(l)] = d.getLoadedItems().map((p) => p.toJson()).all())), a), {}), u = n.model[`model${f.upperFirst(f.camelCase(e))}Json`];
|
|
1504
|
+
if (typeof u != "function")
|
|
1505
|
+
throw new _("ModelFacade");
|
|
1506
|
+
return u.bind(n.model)({
|
|
1491
1507
|
...this.attributes,
|
|
1492
1508
|
...s
|
|
1493
1509
|
}, this);
|
|
1494
1510
|
}
|
|
1495
1511
|
diff() {
|
|
1496
|
-
return this._changedKeys.reduce((s,
|
|
1512
|
+
return this._changedKeys.reduce((s, u) => (s[u] = this._attributes.get(u), s), {});
|
|
1497
1513
|
}
|
|
1498
1514
|
getType() {
|
|
1499
1515
|
return e;
|
|
@@ -1504,7 +1520,7 @@ function $e(n, e) {
|
|
|
1504
1520
|
}
|
|
1505
1521
|
async refresh() {
|
|
1506
1522
|
if (!this.exists)
|
|
1507
|
-
throw new
|
|
1523
|
+
throw new Re(e, "refresh");
|
|
1508
1524
|
const { data: s } = await n.route.call([
|
|
1509
1525
|
`luminix.${e}.show`,
|
|
1510
1526
|
this.makePrimaryKeyReplacer()
|
|
@@ -1516,33 +1532,33 @@ function $e(n, e) {
|
|
|
1516
1532
|
async save(s = {}) {
|
|
1517
1533
|
try {
|
|
1518
1534
|
const {
|
|
1519
|
-
additionalPayload:
|
|
1520
|
-
sendsOnlyModifiedFields:
|
|
1521
|
-
} = s,
|
|
1535
|
+
additionalPayload: u = {},
|
|
1536
|
+
sendsOnlyModifiedFields: a = !0
|
|
1537
|
+
} = s, l = this.exists, d = l ? [
|
|
1522
1538
|
`luminix.${e}.update`,
|
|
1523
1539
|
this.makePrimaryKeyReplacer()
|
|
1524
|
-
] : `luminix.${e}.store`,
|
|
1525
|
-
|
|
1540
|
+
] : `luminix.${e}.store`, p = await n.route.call(
|
|
1541
|
+
d,
|
|
1526
1542
|
{
|
|
1527
1543
|
data: {
|
|
1528
1544
|
...f.pick(
|
|
1529
|
-
|
|
1545
|
+
a && l ? this.diff() : this.attributes,
|
|
1530
1546
|
this.fillable
|
|
1531
1547
|
),
|
|
1532
|
-
...
|
|
1548
|
+
...u
|
|
1533
1549
|
},
|
|
1534
|
-
errorBag:
|
|
1550
|
+
errorBag: l ? `${e}[${this.getKey()}].update` : `${e}.store`
|
|
1535
1551
|
}
|
|
1536
1552
|
);
|
|
1537
|
-
if ([200, 201].includes(
|
|
1538
|
-
return this.makeAttributes(
|
|
1539
|
-
throw
|
|
1540
|
-
} catch (
|
|
1541
|
-
throw n.log.error(
|
|
1553
|
+
if ([200, 201].includes(p.status))
|
|
1554
|
+
return this.makeAttributes(p.data), this.exists = !0, this.dispatchSaveEvent(), l ? this.dispatchUpdateEvent(p.data) : this.dispatchCreateEvent(p.data), p;
|
|
1555
|
+
throw p;
|
|
1556
|
+
} catch (u) {
|
|
1557
|
+
throw n.log.error(u), this.dispatchErrorEvent(u, "save"), u;
|
|
1542
1558
|
}
|
|
1543
1559
|
}
|
|
1544
1560
|
async push() {
|
|
1545
|
-
throw new
|
|
1561
|
+
throw new w();
|
|
1546
1562
|
}
|
|
1547
1563
|
async delete() {
|
|
1548
1564
|
try {
|
|
@@ -1561,20 +1577,20 @@ function $e(n, e) {
|
|
|
1561
1577
|
}
|
|
1562
1578
|
async update(s) {
|
|
1563
1579
|
try {
|
|
1564
|
-
const
|
|
1580
|
+
const u = await n.route.call([
|
|
1565
1581
|
`luminix.${e}.update`,
|
|
1566
1582
|
this.makePrimaryKeyReplacer()
|
|
1567
1583
|
], {
|
|
1568
1584
|
data: s,
|
|
1569
1585
|
errorBag: `${e}[${this.getKey()}].update`
|
|
1570
1586
|
});
|
|
1571
|
-
if (
|
|
1572
|
-
this.makeAttributes(
|
|
1587
|
+
if (u.status === 200) {
|
|
1588
|
+
this.makeAttributes(u.data), this.dispatchUpdateEvent(u.data);
|
|
1573
1589
|
return;
|
|
1574
1590
|
}
|
|
1575
|
-
throw
|
|
1576
|
-
} catch (
|
|
1577
|
-
throw n.log.error(
|
|
1591
|
+
throw u;
|
|
1592
|
+
} catch (u) {
|
|
1593
|
+
throw n.log.error(u), this.dispatchErrorEvent(u, "save"), u;
|
|
1578
1594
|
}
|
|
1579
1595
|
}
|
|
1580
1596
|
async forceDelete() {
|
|
@@ -1622,7 +1638,7 @@ function $e(n, e) {
|
|
|
1622
1638
|
return n.model.schema(e);
|
|
1623
1639
|
}
|
|
1624
1640
|
static query() {
|
|
1625
|
-
return new
|
|
1641
|
+
return new Xe(n, e);
|
|
1626
1642
|
}
|
|
1627
1643
|
static where(...s) {
|
|
1628
1644
|
return this.query().where(...s);
|
|
@@ -1633,14 +1649,14 @@ function $e(n, e) {
|
|
|
1633
1649
|
static whereNotNull(s) {
|
|
1634
1650
|
return this.query().whereNotNull(s);
|
|
1635
1651
|
}
|
|
1636
|
-
static whereBetween(s,
|
|
1637
|
-
return this.query().whereBetween(s,
|
|
1652
|
+
static whereBetween(s, u) {
|
|
1653
|
+
return this.query().whereBetween(s, u);
|
|
1638
1654
|
}
|
|
1639
|
-
static whereNotBetween(s,
|
|
1640
|
-
return this.query().whereNotBetween(s,
|
|
1655
|
+
static whereNotBetween(s, u) {
|
|
1656
|
+
return this.query().whereNotBetween(s, u);
|
|
1641
1657
|
}
|
|
1642
|
-
static orderBy(s,
|
|
1643
|
-
return this.query().orderBy(s,
|
|
1658
|
+
static orderBy(s, u = "asc") {
|
|
1659
|
+
return this.query().orderBy(s, u);
|
|
1644
1660
|
}
|
|
1645
1661
|
static searchBy(s) {
|
|
1646
1662
|
return this.query().searchBy(s);
|
|
@@ -1651,8 +1667,8 @@ function $e(n, e) {
|
|
|
1651
1667
|
static limit(s) {
|
|
1652
1668
|
return this.query().limit(s);
|
|
1653
1669
|
}
|
|
1654
|
-
static get(s = 1,
|
|
1655
|
-
return this.query().get(s,
|
|
1670
|
+
static get(s = 1, u) {
|
|
1671
|
+
return this.query().get(s, u);
|
|
1656
1672
|
}
|
|
1657
1673
|
static find(s) {
|
|
1658
1674
|
return this.query().find(s);
|
|
@@ -1661,12 +1677,12 @@ function $e(n, e) {
|
|
|
1661
1677
|
return this.query().first();
|
|
1662
1678
|
}
|
|
1663
1679
|
static async create(s) {
|
|
1664
|
-
const
|
|
1665
|
-
return
|
|
1680
|
+
const u = n.model.make(e), a = new u();
|
|
1681
|
+
return a.fill(s), await a.save(), a;
|
|
1666
1682
|
}
|
|
1667
|
-
static async update(s,
|
|
1668
|
-
const
|
|
1669
|
-
return
|
|
1683
|
+
static async update(s, u) {
|
|
1684
|
+
const a = n.model.make(e), l = new a({ id: s });
|
|
1685
|
+
return l.fill(u), l.exists = !0, await l.save(), l;
|
|
1670
1686
|
}
|
|
1671
1687
|
static delete(s) {
|
|
1672
1688
|
if (Array.isArray(s))
|
|
@@ -1674,8 +1690,8 @@ function $e(n, e) {
|
|
|
1674
1690
|
params: { ids: s },
|
|
1675
1691
|
errorBag: `${e}.deleteMany`
|
|
1676
1692
|
});
|
|
1677
|
-
const
|
|
1678
|
-
return new
|
|
1693
|
+
const u = n.model.make(e);
|
|
1694
|
+
return new u({ id: s }).delete();
|
|
1679
1695
|
}
|
|
1680
1696
|
static async restore(s) {
|
|
1681
1697
|
if (Array.isArray(s))
|
|
@@ -1683,8 +1699,8 @@ function $e(n, e) {
|
|
|
1683
1699
|
data: { ids: s },
|
|
1684
1700
|
errorBag: `${e}.restoreMany`
|
|
1685
1701
|
});
|
|
1686
|
-
const
|
|
1687
|
-
return new
|
|
1702
|
+
const u = n.model.make(e);
|
|
1703
|
+
return new u({ id: s }).restore();
|
|
1688
1704
|
}
|
|
1689
1705
|
static forceDelete(s) {
|
|
1690
1706
|
if (Array.isArray(s))
|
|
@@ -1692,8 +1708,8 @@ function $e(n, e) {
|
|
|
1692
1708
|
params: { ids: s, force: !0 },
|
|
1693
1709
|
errorBag: `${e}.forceDeleteMany`
|
|
1694
1710
|
});
|
|
1695
|
-
const
|
|
1696
|
-
return new
|
|
1711
|
+
const u = n.model.make(e);
|
|
1712
|
+
return new u({ id: s }).forceDelete();
|
|
1697
1713
|
}
|
|
1698
1714
|
static singular() {
|
|
1699
1715
|
return n.model.schema(e).displayName.singular;
|
|
@@ -1702,94 +1718,97 @@ function $e(n, e) {
|
|
|
1702
1718
|
return n.model.schema(e).displayName.plural;
|
|
1703
1719
|
}
|
|
1704
1720
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1705
|
-
on(s,
|
|
1706
|
-
throw new
|
|
1721
|
+
on(s, u) {
|
|
1722
|
+
throw new w();
|
|
1707
1723
|
}
|
|
1708
1724
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1709
|
-
once(s,
|
|
1710
|
-
throw new
|
|
1725
|
+
once(s, u) {
|
|
1726
|
+
throw new w();
|
|
1711
1727
|
}
|
|
1712
1728
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1713
|
-
emit(s,
|
|
1714
|
-
throw new
|
|
1729
|
+
emit(s, u) {
|
|
1730
|
+
throw new w();
|
|
1715
1731
|
}
|
|
1716
1732
|
}
|
|
1717
|
-
return
|
|
1733
|
+
return S(t);
|
|
1718
1734
|
}
|
|
1719
|
-
function
|
|
1720
|
-
var r;
|
|
1721
|
-
return r =
|
|
1722
|
-
constructor(
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1735
|
+
function Oe(n, e, t) {
|
|
1736
|
+
var r, i;
|
|
1737
|
+
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
1738
|
+
constructor(u = {}) {
|
|
1739
|
+
super(u);
|
|
1740
|
+
g(this, r, f.upperFirst(f.camelCase(e)));
|
|
1741
|
+
return new Proxy(this, {
|
|
1742
|
+
get: (a, l) => {
|
|
1743
|
+
if (l === "__isModel")
|
|
1726
1744
|
return !0;
|
|
1727
|
-
if (
|
|
1728
|
-
const
|
|
1729
|
-
return typeof
|
|
1745
|
+
if (l in a) {
|
|
1746
|
+
const p = a[l];
|
|
1747
|
+
return typeof p == "function" ? p.bind(a) : p;
|
|
1730
1748
|
}
|
|
1731
|
-
if (
|
|
1749
|
+
if (l !== f.camelCase(l))
|
|
1732
1750
|
return;
|
|
1733
|
-
const
|
|
1734
|
-
if (Object.keys(
|
|
1735
|
-
return
|
|
1736
|
-
if (
|
|
1737
|
-
return () =>
|
|
1738
|
-
if (Object.keys(
|
|
1739
|
-
return
|
|
1740
|
-
if (n.model.hasReducer(`model${
|
|
1741
|
-
const
|
|
1742
|
-
if (typeof
|
|
1743
|
-
throw new
|
|
1744
|
-
return
|
|
1751
|
+
const d = f.snakeCase(l);
|
|
1752
|
+
if (Object.keys(a.relations).includes(d))
|
|
1753
|
+
return a.relations[d].getLoadedItems();
|
|
1754
|
+
if (l.endsWith("Relation") && Object.keys(a.relations).includes(f.snakeCase(l.slice(0, -8))))
|
|
1755
|
+
return () => a.relation(l.slice(0, -8));
|
|
1756
|
+
if (Object.keys(a.attributes).includes(d))
|
|
1757
|
+
return a.getAttribute(d);
|
|
1758
|
+
if (n.model.hasReducer(`model${a.constructor.name}Get${f.upperFirst(l)}Attribute`)) {
|
|
1759
|
+
const p = n.model[`model${a.constructor.name}Get${f.upperFirst(l)}Attribute`];
|
|
1760
|
+
if (typeof p != "function")
|
|
1761
|
+
throw new _("ModelFacade");
|
|
1762
|
+
return p.bind(n.model)(void 0, a);
|
|
1745
1763
|
}
|
|
1746
|
-
return Reflect.get(
|
|
1764
|
+
return Reflect.get(a, l);
|
|
1747
1765
|
},
|
|
1748
|
-
set: (
|
|
1749
|
-
if (
|
|
1750
|
-
return Reflect.set(
|
|
1751
|
-
if (
|
|
1752
|
-
return
|
|
1753
|
-
f.snakeCase(
|
|
1754
|
-
|
|
1766
|
+
set: (a, l, d) => {
|
|
1767
|
+
if (l in a && typeof a[l] != "function")
|
|
1768
|
+
return Reflect.set(a, l, d);
|
|
1769
|
+
if (a.fillable.includes(f.snakeCase(l)))
|
|
1770
|
+
return a.setAttribute(
|
|
1771
|
+
f.snakeCase(l),
|
|
1772
|
+
d
|
|
1755
1773
|
), !0;
|
|
1756
|
-
throw new
|
|
1774
|
+
throw new Ne(e, f.snakeCase(l));
|
|
1757
1775
|
}
|
|
1758
1776
|
});
|
|
1759
1777
|
}
|
|
1760
|
-
}
|
|
1778
|
+
};
|
|
1761
1779
|
}
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1780
|
+
var ge, ye;
|
|
1781
|
+
class ke extends (ye = Error, ge = Symbol.toStringTag, ye) {
|
|
1782
|
+
constructor(t, r) {
|
|
1783
|
+
super(`[Luminix] Cannot create reducer '${t}' on '${r}' as it is a reserved property`);
|
|
1784
|
+
g(this, ge, "ReducerOverrideException");
|
|
1765
1785
|
}
|
|
1766
1786
|
}
|
|
1767
|
-
|
|
1768
|
-
function ie(n) {
|
|
1787
|
+
function ve(n) {
|
|
1769
1788
|
return class extends n {
|
|
1770
1789
|
constructor(...t) {
|
|
1771
1790
|
super(...t);
|
|
1772
|
-
|
|
1791
|
+
g(this, "reducers", {});
|
|
1773
1792
|
return new Proxy(this, {
|
|
1774
|
-
get(r,
|
|
1775
|
-
return typeof
|
|
1776
|
-
const { [
|
|
1777
|
-
return
|
|
1793
|
+
get(r, i, s) {
|
|
1794
|
+
return typeof i == "symbol" || i in r ? Reflect.get(r, i, s) : (u, ...a) => {
|
|
1795
|
+
const { [i]: l = c() } = r.reducers;
|
|
1796
|
+
return Le(u) ? v(u, (d) => l.sortBy("priority").reduce((p, y) => y.callback(p, ...a), d)) : l.sortBy("priority").reduce((d, p) => p.callback(d, ...a), u);
|
|
1778
1797
|
};
|
|
1779
1798
|
}
|
|
1780
1799
|
});
|
|
1781
1800
|
}
|
|
1782
|
-
reducer(t, r,
|
|
1801
|
+
reducer(t, r, i = 10) {
|
|
1783
1802
|
if (t in this)
|
|
1784
|
-
throw new
|
|
1785
|
-
return this.reducers[t] || (this.reducers[t] =
|
|
1803
|
+
throw new ke(t, this);
|
|
1804
|
+
return this.reducers[t] || (this.reducers[t] = c()), this.reducers[t].push({ callback: r, priority: i }), () => this.removeReducer(t, r);
|
|
1786
1805
|
}
|
|
1787
1806
|
removeReducer(t, r) {
|
|
1788
|
-
const
|
|
1789
|
-
|
|
1807
|
+
const i = this.reducers[t].search((s) => s.callback === r);
|
|
1808
|
+
i !== !1 && this.reducers[t].pull(i);
|
|
1790
1809
|
}
|
|
1791
1810
|
getReducer(t) {
|
|
1792
|
-
return this.reducers[t] || (this.reducers[t] =
|
|
1811
|
+
return this.reducers[t] || (this.reducers[t] = c()), this.reducers[t];
|
|
1793
1812
|
}
|
|
1794
1813
|
hasReducer(t) {
|
|
1795
1814
|
return !!this.reducers[t] && this.reducers[t].count() > 0;
|
|
@@ -1802,23 +1821,25 @@ function ie(n) {
|
|
|
1802
1821
|
}
|
|
1803
1822
|
};
|
|
1804
1823
|
}
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1824
|
+
var we, be;
|
|
1825
|
+
class G extends (be = Error, we = Symbol.toStringTag, be) {
|
|
1826
|
+
constructor(t) {
|
|
1827
|
+
super(`[Luminix] Model "${t}" not found`);
|
|
1828
|
+
g(this, we, "ModelNotFoundException");
|
|
1808
1829
|
}
|
|
1809
1830
|
}
|
|
1810
|
-
|
|
1811
|
-
class
|
|
1812
|
-
constructor(
|
|
1813
|
-
super(`[Luminix] "${
|
|
1831
|
+
var Ee, xe;
|
|
1832
|
+
class B extends (xe = TypeError, Ee = Symbol.toStringTag, xe) {
|
|
1833
|
+
constructor(t, r, i) {
|
|
1834
|
+
super(`[Luminix] "${t}" expects a related model of type "${r}". Received "${i}" instead.`);
|
|
1835
|
+
g(this, Ee, "ModelInvalidRelatedTypeException");
|
|
1814
1836
|
}
|
|
1815
1837
|
}
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
super(e, t, r, s), this.meta = e, this.facades = t, this.parent = r, this.items = s;
|
|
1838
|
+
class Be extends j {
|
|
1839
|
+
constructor(e, t, r, i = null) {
|
|
1840
|
+
if (!b(i) && i !== null)
|
|
1841
|
+
throw new x("BelongsTo.constructor()", "Model or null");
|
|
1842
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1822
1843
|
}
|
|
1823
1844
|
isSingle() {
|
|
1824
1845
|
return !0;
|
|
@@ -1834,12 +1855,12 @@ class ne extends j {
|
|
|
1834
1855
|
return this.query().first();
|
|
1835
1856
|
}
|
|
1836
1857
|
async associate(e) {
|
|
1837
|
-
if (!
|
|
1838
|
-
throw new
|
|
1858
|
+
if (!b(e))
|
|
1859
|
+
throw new x("BelongsTo.associate()");
|
|
1839
1860
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1840
|
-
throw new
|
|
1861
|
+
throw new B("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
|
|
1841
1862
|
if (!e.exists)
|
|
1842
|
-
throw new
|
|
1863
|
+
throw new Re(this.getRelated().getSchemaName(), "save");
|
|
1843
1864
|
return this.parent.update({
|
|
1844
1865
|
[this.getForeignKey()]: e.getKey()
|
|
1845
1866
|
});
|
|
@@ -1850,11 +1871,11 @@ class ne extends j {
|
|
|
1850
1871
|
});
|
|
1851
1872
|
}
|
|
1852
1873
|
}
|
|
1853
|
-
class
|
|
1854
|
-
constructor(e, t, r,
|
|
1855
|
-
if (
|
|
1856
|
-
throw new
|
|
1857
|
-
super(e, t, r,
|
|
1874
|
+
class qe extends j {
|
|
1875
|
+
constructor(e, t, r, i = null) {
|
|
1876
|
+
if (i !== null && !(i instanceof C && i.every(b)))
|
|
1877
|
+
throw new x("BelongsToMany.constructor()", "Collection<Model> or null");
|
|
1878
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1858
1879
|
}
|
|
1859
1880
|
isSingle() {
|
|
1860
1881
|
return !1;
|
|
@@ -1892,10 +1913,10 @@ class oe extends j {
|
|
|
1892
1913
|
}
|
|
1893
1914
|
async attach(e, t = {}) {
|
|
1894
1915
|
if (await this.attachQuietly(e, t), this.items) {
|
|
1895
|
-
const r = this.items.search((
|
|
1896
|
-
if (!
|
|
1916
|
+
const r = this.items.search((s) => s.getKey() === e), i = await this.getRelated().find(e);
|
|
1917
|
+
if (!i)
|
|
1897
1918
|
return;
|
|
1898
|
-
r !== !1 ? this.items.put(r,
|
|
1919
|
+
r !== !1 ? this.items.put(r, i) : this.items.push(i);
|
|
1899
1920
|
} else
|
|
1900
1921
|
this.items = await this.all();
|
|
1901
1922
|
}
|
|
@@ -1955,24 +1976,24 @@ class oe extends j {
|
|
|
1955
1976
|
this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
|
|
1956
1977
|
}
|
|
1957
1978
|
}
|
|
1958
|
-
class
|
|
1979
|
+
class L extends j {
|
|
1959
1980
|
query() {
|
|
1960
1981
|
const e = super.query(), t = this.guessInverseRelation();
|
|
1961
1982
|
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
1962
1983
|
}
|
|
1963
1984
|
async saveQuietly(e) {
|
|
1964
|
-
if (!
|
|
1965
|
-
throw new
|
|
1985
|
+
if (!b(e))
|
|
1986
|
+
throw new x("HasOneOrMany.saveQuietly()");
|
|
1966
1987
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1967
|
-
throw new
|
|
1988
|
+
throw new B("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1968
1989
|
e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
|
|
1969
1990
|
}
|
|
1970
1991
|
}
|
|
1971
|
-
class
|
|
1972
|
-
constructor(e, t, r,
|
|
1973
|
-
if (!
|
|
1974
|
-
throw new
|
|
1975
|
-
super(e, t, r,
|
|
1992
|
+
class et extends L {
|
|
1993
|
+
constructor(e, t, r, i = null) {
|
|
1994
|
+
if (!b(i) && i !== null)
|
|
1995
|
+
throw new x("HasOne.constructor()", "Model or null");
|
|
1996
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1976
1997
|
}
|
|
1977
1998
|
isSingle() {
|
|
1978
1999
|
return !0;
|
|
@@ -1987,11 +2008,11 @@ class Ae extends H {
|
|
|
1987
2008
|
await this.saveQuietly(e), this.items = e;
|
|
1988
2009
|
}
|
|
1989
2010
|
}
|
|
1990
|
-
class
|
|
1991
|
-
constructor(e, t, r,
|
|
1992
|
-
if (
|
|
1993
|
-
throw new
|
|
1994
|
-
super(e, t, r,
|
|
2011
|
+
class tt extends L {
|
|
2012
|
+
constructor(e, t, r, i = null) {
|
|
2013
|
+
if (i !== null && !(i instanceof C && i.every(b)))
|
|
2014
|
+
throw new x("HasMany.constructor()", "Collection<Model> or null");
|
|
2015
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1995
2016
|
}
|
|
1996
2017
|
isSingle() {
|
|
1997
2018
|
return !1;
|
|
@@ -2012,10 +2033,10 @@ class ve extends H {
|
|
|
2012
2033
|
return this.query().find(e);
|
|
2013
2034
|
}
|
|
2014
2035
|
async saveManyQuietly(e) {
|
|
2015
|
-
if (!Array.isArray(e) || !e.every(
|
|
2016
|
-
throw new
|
|
2036
|
+
if (!Array.isArray(e) || !e.every(b))
|
|
2037
|
+
throw new x("HasMany.saveManyQuietly()", "Model[]");
|
|
2017
2038
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
2018
|
-
throw new
|
|
2039
|
+
throw new B("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
2019
2040
|
await Promise.all(e.map((t) => (t.setAttribute(this.getForeignKey(), this.parent.getKey()), t.save())));
|
|
2020
2041
|
}
|
|
2021
2042
|
async saveMany(e) {
|
|
@@ -2027,7 +2048,7 @@ class ve extends H {
|
|
|
2027
2048
|
await this.saveQuietly(e), this.items === null ? this.items = await this.all() : this.items.push(e);
|
|
2028
2049
|
}
|
|
2029
2050
|
}
|
|
2030
|
-
class
|
|
2051
|
+
class Ie extends L {
|
|
2031
2052
|
query() {
|
|
2032
2053
|
const e = this.getRelated().query();
|
|
2033
2054
|
e.once("success", (r) => {
|
|
@@ -2037,19 +2058,19 @@ class he extends H {
|
|
|
2037
2058
|
return e.where(t + "_id", this.parent.getKey()), e.where(t + "_type", this.getRelated().getSchemaName()), e.lock(`where.${t}_id`), e.lock(`where.${t}_type`), e;
|
|
2038
2059
|
}
|
|
2039
2060
|
async saveQuietly(e) {
|
|
2040
|
-
if (!
|
|
2041
|
-
throw new
|
|
2061
|
+
if (!b(e))
|
|
2062
|
+
throw new x("MorphOneOrMany.saveQuietly()");
|
|
2042
2063
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
2043
|
-
throw new
|
|
2064
|
+
throw new B("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
2044
2065
|
const t = this.guessInverseRelation();
|
|
2045
2066
|
e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
|
|
2046
2067
|
}
|
|
2047
2068
|
}
|
|
2048
|
-
class
|
|
2049
|
-
constructor(e, t, r,
|
|
2050
|
-
if (
|
|
2051
|
-
throw new
|
|
2052
|
-
super(e, t, r,
|
|
2069
|
+
class rt extends Ie {
|
|
2070
|
+
constructor(e, t, r, i = null) {
|
|
2071
|
+
if (i !== null && !(i instanceof C && i.every(b)))
|
|
2072
|
+
throw new x("MorphMany.constructor()", "Collection<Model> or null");
|
|
2073
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2053
2074
|
}
|
|
2054
2075
|
isSingle() {
|
|
2055
2076
|
return !1;
|
|
@@ -2070,10 +2091,10 @@ class Re extends he {
|
|
|
2070
2091
|
return this.query().find(e);
|
|
2071
2092
|
}
|
|
2072
2093
|
async saveManyQuietly(e) {
|
|
2073
|
-
if (!Array.isArray(e) || !e.every(
|
|
2074
|
-
throw new
|
|
2094
|
+
if (!Array.isArray(e) || !e.every(b))
|
|
2095
|
+
throw new x("MorphMany.saveManyQuietly()");
|
|
2075
2096
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
2076
|
-
throw new
|
|
2097
|
+
throw new B("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
2077
2098
|
await Promise.all(e.map((t) => (t.setAttribute(this.getName() + "_id", this.parent.getKey()), t.setAttribute(this.getName() + "_type", this.parent.getType()), t.save())));
|
|
2078
2099
|
}
|
|
2079
2100
|
async save(e) {
|
|
@@ -2085,10 +2106,10 @@ class Re extends he {
|
|
|
2085
2106
|
this.items ? this.items.splice(0, this.items.count(), ...t) : this.items = t;
|
|
2086
2107
|
}
|
|
2087
2108
|
}
|
|
2088
|
-
class
|
|
2089
|
-
constructor(e, t, r,
|
|
2090
|
-
if (super(e, t, r,
|
|
2091
|
-
throw new
|
|
2109
|
+
class st extends Ie {
|
|
2110
|
+
constructor(e, t, r, i = null) {
|
|
2111
|
+
if (super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !b(i))
|
|
2112
|
+
throw new x("MorphOne.constructor()", "Model or null");
|
|
2092
2113
|
}
|
|
2093
2114
|
isSingle() {
|
|
2094
2115
|
return !0;
|
|
@@ -2103,7 +2124,7 @@ class Ne extends he {
|
|
|
2103
2124
|
await this.saveQuietly(e), this.items = e;
|
|
2104
2125
|
}
|
|
2105
2126
|
}
|
|
2106
|
-
class
|
|
2127
|
+
class it extends Be {
|
|
2107
2128
|
getRelated() {
|
|
2108
2129
|
return this.facades.model.make(
|
|
2109
2130
|
this.parent.getAttribute(this.getName() + "_type")
|
|
@@ -2118,8 +2139,8 @@ class Se extends ne {
|
|
|
2118
2139
|
// return super.query();
|
|
2119
2140
|
// }
|
|
2120
2141
|
async associate(e) {
|
|
2121
|
-
if (!
|
|
2122
|
-
throw new
|
|
2142
|
+
if (!b(e))
|
|
2143
|
+
throw new x("MorphTo.associate()");
|
|
2123
2144
|
return e.exists || await e.save(), this.parent.update({
|
|
2124
2145
|
[this.getName() + "_id"]: e.getKey(),
|
|
2125
2146
|
[this.getName() + "_type"]: e.getType()
|
|
@@ -2132,49 +2153,52 @@ class Se extends ne {
|
|
|
2132
2153
|
});
|
|
2133
2154
|
}
|
|
2134
2155
|
}
|
|
2135
|
-
class
|
|
2136
|
-
constructor(e, t, r,
|
|
2137
|
-
super(e, t, r,
|
|
2156
|
+
class nt extends qe {
|
|
2157
|
+
constructor(e, t, r, i = null) {
|
|
2158
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2138
2159
|
}
|
|
2139
2160
|
query() {
|
|
2140
2161
|
const e = super.query(), t = this.guessInverseRelation();
|
|
2141
2162
|
return e.where(t + "_id", this.parent.getKey()), e.where(t + "_type", this.parent.getType()), e.lock(`where.${t}_id`), e.lock(`where.${t}_type`), e;
|
|
2142
2163
|
}
|
|
2143
2164
|
}
|
|
2144
|
-
|
|
2165
|
+
var Me;
|
|
2166
|
+
Me = Symbol.toStringTag;
|
|
2167
|
+
class ot {
|
|
2145
2168
|
constructor(e) {
|
|
2146
|
-
|
|
2169
|
+
g(this, "_models", {});
|
|
2170
|
+
g(this, Me, "ModelFacade");
|
|
2147
2171
|
this._schema = e;
|
|
2148
2172
|
}
|
|
2149
2173
|
boot(e) {
|
|
2150
2174
|
this._schema && (Object.keys(this._schema).forEach((t) => {
|
|
2151
2175
|
const r = this[`model${f.upperFirst(f.camelCase(t))}`];
|
|
2152
2176
|
if (typeof this.model != "function" || typeof r != "function")
|
|
2153
|
-
throw new
|
|
2154
|
-
const
|
|
2155
|
-
|
|
2177
|
+
throw new _("ModelFacade");
|
|
2178
|
+
const i = this.model(
|
|
2179
|
+
ze(e.make(), t),
|
|
2156
2180
|
t
|
|
2157
|
-
),
|
|
2158
|
-
this._models[t] =
|
|
2181
|
+
), s = r(i);
|
|
2182
|
+
this._models[t] = Oe(e.make(), t, s);
|
|
2159
2183
|
}), this.reducer("relationMap", () => ({
|
|
2160
|
-
BelongsTo:
|
|
2161
|
-
BelongsToMany:
|
|
2162
|
-
HasOne:
|
|
2163
|
-
HasMany:
|
|
2164
|
-
MorphMany:
|
|
2165
|
-
MorphOne:
|
|
2166
|
-
MorphTo:
|
|
2167
|
-
MorphToMany:
|
|
2184
|
+
BelongsTo: Be,
|
|
2185
|
+
BelongsToMany: qe,
|
|
2186
|
+
HasOne: et,
|
|
2187
|
+
HasMany: tt,
|
|
2188
|
+
MorphMany: rt,
|
|
2189
|
+
MorphOne: st,
|
|
2190
|
+
MorphTo: it,
|
|
2191
|
+
MorphToMany: nt
|
|
2168
2192
|
}), 0));
|
|
2169
2193
|
}
|
|
2170
2194
|
schema(e) {
|
|
2171
2195
|
if (!this._schema || e && !this._schema[e])
|
|
2172
|
-
throw new
|
|
2196
|
+
throw new G(e || "undefined");
|
|
2173
2197
|
return e ? this._schema[e] : this._schema;
|
|
2174
2198
|
}
|
|
2175
2199
|
make(e) {
|
|
2176
2200
|
if (e && !this._models[e])
|
|
2177
|
-
throw new
|
|
2201
|
+
throw new G(e);
|
|
2178
2202
|
return e ? this._models[e] : this._models;
|
|
2179
2203
|
}
|
|
2180
2204
|
toString() {
|
|
@@ -2182,68 +2206,68 @@ class ue {
|
|
|
2182
2206
|
}
|
|
2183
2207
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2184
2208
|
on(e, t) {
|
|
2185
|
-
throw new
|
|
2209
|
+
throw new w();
|
|
2186
2210
|
}
|
|
2187
2211
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2188
2212
|
once(e, t) {
|
|
2189
|
-
throw new
|
|
2213
|
+
throw new w();
|
|
2190
2214
|
}
|
|
2191
2215
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2192
2216
|
emit(e, t) {
|
|
2193
|
-
throw new
|
|
2217
|
+
throw new w();
|
|
2194
2218
|
}
|
|
2195
2219
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2196
2220
|
reducer(e, t, r) {
|
|
2197
|
-
throw new
|
|
2221
|
+
throw new w();
|
|
2198
2222
|
}
|
|
2199
2223
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2200
2224
|
removeReducer(e) {
|
|
2201
|
-
throw new
|
|
2225
|
+
throw new w();
|
|
2202
2226
|
}
|
|
2203
2227
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2204
2228
|
getReducer(e) {
|
|
2205
|
-
throw new
|
|
2229
|
+
throw new w();
|
|
2206
2230
|
}
|
|
2207
2231
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2208
2232
|
hasReducer(e) {
|
|
2209
|
-
throw new
|
|
2233
|
+
throw new w();
|
|
2210
2234
|
}
|
|
2211
2235
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2212
2236
|
clearReducer(e) {
|
|
2213
|
-
throw new
|
|
2237
|
+
throw new w();
|
|
2214
2238
|
}
|
|
2215
2239
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2216
2240
|
flushReducers() {
|
|
2217
|
-
throw new
|
|
2241
|
+
throw new w();
|
|
2218
2242
|
}
|
|
2219
2243
|
}
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
class
|
|
2244
|
+
const ht = S(ve(ot));
|
|
2245
|
+
var _e, Te;
|
|
2246
|
+
class ut extends (Te = Error, _e = Symbol.toStringTag, Te) {
|
|
2223
2247
|
constructor() {
|
|
2224
2248
|
super("[Luminix] Embed element not found. Make sure to include the `@luminixEmbed()` directive in your Blade template.");
|
|
2249
|
+
g(this, _e, "NoEmbedException");
|
|
2225
2250
|
}
|
|
2226
2251
|
}
|
|
2227
|
-
|
|
2228
|
-
const le = (n, e = "data") => {
|
|
2252
|
+
const Ke = (n, e = "data") => {
|
|
2229
2253
|
if (!document.querySelector("#luminix-embed"))
|
|
2230
|
-
throw new
|
|
2254
|
+
throw new ut();
|
|
2231
2255
|
const t = document.getElementById(`luminix-${e}::` + n);
|
|
2232
2256
|
return t ? t.dataset.json && t.dataset.value ? JSON.parse(t.dataset.value) : t.dataset.value : null;
|
|
2233
|
-
},
|
|
2234
|
-
let
|
|
2257
|
+
}, V = S(A), at = (n) => Je(n) && n.response !== void 0 && n.response.data !== null && "message" in n.response.data && typeof n.response.data.message == "string" && "errors" in n.response.data && typeof n.response.data.errors == "object" && n.response.data.errors !== null && Object.values(n.response.data.errors).every((e) => Array.isArray(e) && e.every((t) => typeof t == "string")) && n.response.status === 422;
|
|
2258
|
+
let lt = class {
|
|
2235
2259
|
constructor() {
|
|
2236
|
-
|
|
2260
|
+
g(this, "bags");
|
|
2237
2261
|
const e = {};
|
|
2238
2262
|
document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((r) => {
|
|
2239
|
-
const
|
|
2240
|
-
e[
|
|
2263
|
+
const s = r.id.replace("luminix-error::", "");
|
|
2264
|
+
e[s] = Ke(s, "error");
|
|
2241
2265
|
}), this.bags = {
|
|
2242
|
-
default: new
|
|
2266
|
+
default: new V(e)
|
|
2243
2267
|
};
|
|
2244
2268
|
}
|
|
2245
2269
|
bag(e = "default") {
|
|
2246
|
-
return this.bags[e] || (this.bags[e] = new
|
|
2270
|
+
return this.bags[e] || (this.bags[e] = new V({})), this.bags[e];
|
|
2247
2271
|
}
|
|
2248
2272
|
add(e, t, r = "default") {
|
|
2249
2273
|
this.bag(r).set(e, t);
|
|
@@ -2261,13 +2285,14 @@ let Ke = class {
|
|
|
2261
2285
|
this.bag(e).set(".", {});
|
|
2262
2286
|
}
|
|
2263
2287
|
};
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2288
|
+
var $e, Se;
|
|
2289
|
+
class ct extends (Se = Error, $e = Symbol.toStringTag, Se) {
|
|
2290
|
+
constructor(t) {
|
|
2291
|
+
super(`[Luminix] Route "${t}" not found`);
|
|
2292
|
+
g(this, $e, "RouteNotFoundException");
|
|
2267
2293
|
}
|
|
2268
2294
|
}
|
|
2269
|
-
|
|
2270
|
-
class je {
|
|
2295
|
+
class dt {
|
|
2271
2296
|
constructor(e, t, r = "") {
|
|
2272
2297
|
this.routes = e, this.error = t, this.appUrl = r;
|
|
2273
2298
|
}
|
|
@@ -2277,8 +2302,8 @@ class je {
|
|
|
2277
2302
|
const [t, ...r] = e;
|
|
2278
2303
|
if (typeof t != "string")
|
|
2279
2304
|
return !1;
|
|
2280
|
-
const
|
|
2281
|
-
return !!r.every((
|
|
2305
|
+
const i = ["get", "post", "put", "patch", "delete"];
|
|
2306
|
+
return !!r.every((s) => i.includes(s));
|
|
2282
2307
|
}
|
|
2283
2308
|
extractGenerator(e) {
|
|
2284
2309
|
let t, r = !1;
|
|
@@ -2286,23 +2311,23 @@ class je {
|
|
|
2286
2311
|
}
|
|
2287
2312
|
get(e) {
|
|
2288
2313
|
if (!this.exists(e))
|
|
2289
|
-
throw new
|
|
2314
|
+
throw new ct(e);
|
|
2290
2315
|
return f.get(this.routes, e);
|
|
2291
2316
|
}
|
|
2292
2317
|
url(e) {
|
|
2293
|
-
const [t, r] = this.extractGenerator(e),
|
|
2318
|
+
const [t, r] = this.extractGenerator(e), i = this.get(t)[0].replace(/^\/|\/$/g, ""), s = /{([^}]+)}/g;
|
|
2294
2319
|
if (r === !1) {
|
|
2295
2320
|
if (typeof this.replaceRouteParams != "function")
|
|
2296
|
-
throw new
|
|
2297
|
-
return this.appUrl + this.replaceRouteParams(`/${
|
|
2321
|
+
throw new _("RouteFacade");
|
|
2322
|
+
return this.appUrl + this.replaceRouteParams(`/${i}`);
|
|
2298
2323
|
}
|
|
2299
|
-
const u =
|
|
2324
|
+
const u = i.match(s), a = u ? u.map((m) => m.slice(1, -1)) : [], l = Object.keys(r), d = a.filter((m) => !l.includes(m)), p = l.filter((m) => !a.includes(m));
|
|
2300
2325
|
if (d.length > 0)
|
|
2301
2326
|
throw new TypeError(`Missing values for parameter(s): ${d.join(", ")}`);
|
|
2302
|
-
if (
|
|
2303
|
-
throw new TypeError(`Unexpected parameters: ${
|
|
2304
|
-
const
|
|
2305
|
-
return this.appUrl + `/${
|
|
2327
|
+
if (p.length > 0)
|
|
2328
|
+
throw new TypeError(`Unexpected parameters: ${p.join(", ")}`);
|
|
2329
|
+
const y = a.reduce((m, E) => m.replace(`{${E}}`, `${r[E]}`), i);
|
|
2330
|
+
return this.appUrl + `/${y}`;
|
|
2306
2331
|
}
|
|
2307
2332
|
methods(e) {
|
|
2308
2333
|
const [t] = this.extractGenerator(e);
|
|
@@ -2313,37 +2338,37 @@ class je {
|
|
|
2313
2338
|
}
|
|
2314
2339
|
async call(e, t = {}) {
|
|
2315
2340
|
if (typeof this.axiosOptions != "function" || typeof this.axiosError != "function")
|
|
2316
|
-
throw new
|
|
2317
|
-
const [r,
|
|
2341
|
+
throw new _("RouteFacade");
|
|
2342
|
+
const [r, i] = this.extractGenerator(e), [, ...s] = this.get(r), u = this.url(i ? [r, i] : r), a = this.axiosOptions(t, r), { method: l = s[0], errorBag: d = "route.call", ...p } = a, { data: y, ...m } = p;
|
|
2318
2343
|
this.error.clear(d);
|
|
2319
2344
|
try {
|
|
2320
|
-
return ["get", "delete"].includes(
|
|
2321
|
-
} catch (
|
|
2322
|
-
if (
|
|
2323
|
-
const { errors:
|
|
2324
|
-
this.error.set(Object.entries(
|
|
2325
|
-
} else K.isAxiosError(
|
|
2326
|
-
this.axiosError({ axios:
|
|
2327
|
-
error:
|
|
2345
|
+
return ["get", "delete"].includes(l) ? await K[l](u, p) : await K[l](u, y, m);
|
|
2346
|
+
} catch (E) {
|
|
2347
|
+
if (at(E)) {
|
|
2348
|
+
const { errors: je } = E.response.data;
|
|
2349
|
+
this.error.set(Object.entries(je).reduce((J, [Fe, Pe]) => (J[Fe] = Pe.join(" "), J), {}));
|
|
2350
|
+
} else K.isAxiosError(E) && this.error.set(
|
|
2351
|
+
this.axiosError({ axios: E.message }, {
|
|
2352
|
+
error: E,
|
|
2328
2353
|
name: r,
|
|
2329
|
-
replace:
|
|
2354
|
+
replace: i,
|
|
2330
2355
|
config: t
|
|
2331
2356
|
}),
|
|
2332
2357
|
d
|
|
2333
2358
|
);
|
|
2334
|
-
throw
|
|
2359
|
+
throw E;
|
|
2335
2360
|
}
|
|
2336
2361
|
}
|
|
2337
2362
|
toString() {
|
|
2338
2363
|
return "route";
|
|
2339
2364
|
}
|
|
2340
2365
|
}
|
|
2341
|
-
const
|
|
2342
|
-
class
|
|
2366
|
+
const ft = ve(dt);
|
|
2367
|
+
class pt {
|
|
2343
2368
|
constructor() {
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2369
|
+
g(this, "facades", {});
|
|
2370
|
+
g(this, "booted", !1);
|
|
2371
|
+
g(this, "_plugins", []);
|
|
2347
2372
|
}
|
|
2348
2373
|
make(e = void 0) {
|
|
2349
2374
|
if (!e)
|
|
@@ -2361,7 +2386,7 @@ class Pe {
|
|
|
2361
2386
|
return this._plugins;
|
|
2362
2387
|
}
|
|
2363
2388
|
async boot(e = {}) {
|
|
2364
|
-
var a,
|
|
2389
|
+
var a, l, d, p, y;
|
|
2365
2390
|
if (this.booted)
|
|
2366
2391
|
throw new window.Error("[Luminix] App already booted");
|
|
2367
2392
|
this.booted = !0, (a = e.app) != null && a.debug && console.log("[Luminix] Booting started..."), this.emit("init", {
|
|
@@ -2369,20 +2394,20 @@ class Pe {
|
|
|
2369
2394
|
this._plugins.push(m), typeof m.register == "function" && m.register(this);
|
|
2370
2395
|
}
|
|
2371
2396
|
});
|
|
2372
|
-
const t = (((
|
|
2397
|
+
const t = (((l = e.app) == null ? void 0 : l.url) ?? "") + (((d = e.app) == null ? void 0 : d.bootUrl) ?? "/luminix-api/init");
|
|
2373
2398
|
if (typeof t == "string" && !document.getElementById("luminix-data::config")) {
|
|
2374
2399
|
const { data: m } = await K.get(t);
|
|
2375
2400
|
m && typeof m == "object" && f.merge(e, m);
|
|
2376
2401
|
} else if (document.getElementById("luminix-data::config")) {
|
|
2377
|
-
const m =
|
|
2402
|
+
const m = Ke("config");
|
|
2378
2403
|
m && typeof m == "object" && f.merge(e, m);
|
|
2379
2404
|
}
|
|
2380
|
-
this.bind("log", new
|
|
2405
|
+
this.bind("log", new He(!!((p = e.app) != null && p.debug)));
|
|
2381
2406
|
const { log: r } = this.facades, {
|
|
2382
|
-
manifest: { routes:
|
|
2407
|
+
manifest: { routes: i = {}, models: s = {} } = {},
|
|
2383
2408
|
...u
|
|
2384
2409
|
} = e;
|
|
2385
|
-
this.bind("config", new
|
|
2410
|
+
this.bind("config", new A(u)), this.facades.config.has("auth.user") || this.facades.config.set("auth.user", null), this.facades.config.lock("auth.user"), this.bind("error", new lt()), this.bind("route", new ft(i, this.facades.error, ((y = e.app) == null ? void 0 : y.url) ?? "")), this.bind("model", new ht(s)), this.bind("auth", new De(this)), this.emit("booting");
|
|
2386
2411
|
for (const m of Object.values(this.facades))
|
|
2387
2412
|
typeof m == "object" && m !== null && "boot" in m && typeof m.boot == "function" && m.boot(this);
|
|
2388
2413
|
for (const m of this._plugins)
|
|
@@ -2391,8 +2416,8 @@ class Pe {
|
|
|
2391
2416
|
config: this.facades.config.all(),
|
|
2392
2417
|
plugins: this._plugins,
|
|
2393
2418
|
manifest: {
|
|
2394
|
-
routes:
|
|
2395
|
-
models:
|
|
2419
|
+
routes: i,
|
|
2420
|
+
models: s
|
|
2396
2421
|
}
|
|
2397
2422
|
}), this.emit("booted"), this.facades;
|
|
2398
2423
|
}
|
|
@@ -2409,49 +2434,49 @@ class Pe {
|
|
|
2409
2434
|
throw new window.Error("Method not implemented.");
|
|
2410
2435
|
}
|
|
2411
2436
|
}
|
|
2412
|
-
const
|
|
2413
|
-
let
|
|
2414
|
-
function
|
|
2415
|
-
if (
|
|
2437
|
+
const mt = S(pt);
|
|
2438
|
+
let M;
|
|
2439
|
+
function N(n = void 0) {
|
|
2440
|
+
if (M || (M = new mt()), typeof n != "string")
|
|
2416
2441
|
return {
|
|
2417
|
-
boot:
|
|
2418
|
-
make:
|
|
2419
|
-
plugins:
|
|
2420
|
-
on:
|
|
2442
|
+
boot: M.boot.bind(M),
|
|
2443
|
+
make: M.make.bind(M),
|
|
2444
|
+
plugins: M.plugins.bind(M),
|
|
2445
|
+
on: M.once.bind(M)
|
|
2421
2446
|
};
|
|
2422
|
-
if (!
|
|
2423
|
-
throw new
|
|
2424
|
-
return
|
|
2447
|
+
if (!M.has(n))
|
|
2448
|
+
throw new Ue(n);
|
|
2449
|
+
return M.make(n);
|
|
2425
2450
|
}
|
|
2426
|
-
function
|
|
2427
|
-
return
|
|
2451
|
+
function Mt() {
|
|
2452
|
+
return N("auth");
|
|
2428
2453
|
}
|
|
2429
|
-
function
|
|
2430
|
-
return
|
|
2454
|
+
function _t(n) {
|
|
2455
|
+
return c(n);
|
|
2431
2456
|
}
|
|
2432
|
-
function
|
|
2433
|
-
const t =
|
|
2457
|
+
function Tt(n, e) {
|
|
2458
|
+
const t = N("config");
|
|
2434
2459
|
return typeof n > "u" ? t : t.get(n, e);
|
|
2435
2460
|
}
|
|
2436
|
-
function
|
|
2437
|
-
return n ?
|
|
2461
|
+
function $t(n, e = "default") {
|
|
2462
|
+
return n ? N().make("error").get(n, e) : N().make("error");
|
|
2438
2463
|
}
|
|
2439
|
-
function
|
|
2440
|
-
const e =
|
|
2464
|
+
function St(...n) {
|
|
2465
|
+
const e = N("log");
|
|
2441
2466
|
return n.length ? e.debug(...n) : e;
|
|
2442
2467
|
}
|
|
2443
|
-
function
|
|
2444
|
-
const e =
|
|
2468
|
+
function At(n) {
|
|
2469
|
+
const e = N("model");
|
|
2445
2470
|
return n ? e.make(n) : e;
|
|
2446
2471
|
}
|
|
2447
|
-
function
|
|
2448
|
-
const t =
|
|
2472
|
+
function Nt(n, e = !1) {
|
|
2473
|
+
const t = N("route");
|
|
2449
2474
|
return n ? e ? t.url([n, e]) : t.url(n) : t;
|
|
2450
2475
|
}
|
|
2451
|
-
class
|
|
2476
|
+
class Rt {
|
|
2452
2477
|
constructor() {
|
|
2453
|
-
|
|
2454
|
-
|
|
2478
|
+
g(this, "name");
|
|
2479
|
+
g(this, "version");
|
|
2455
2480
|
}
|
|
2456
2481
|
register(e) {
|
|
2457
2482
|
}
|
|
@@ -2459,19 +2484,19 @@ class Oe {
|
|
|
2459
2484
|
}
|
|
2460
2485
|
}
|
|
2461
2486
|
export {
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2487
|
+
S as HasEvents,
|
|
2488
|
+
Rt as Plugin,
|
|
2489
|
+
A as PropertyBag,
|
|
2490
|
+
ve as Reducible,
|
|
2491
|
+
N as app,
|
|
2492
|
+
Mt as auth,
|
|
2493
|
+
_t as collect,
|
|
2494
|
+
Tt as config,
|
|
2495
|
+
$t as error,
|
|
2496
|
+
$ as isCollection,
|
|
2497
|
+
b as isModel,
|
|
2498
|
+
at as isValidationError,
|
|
2499
|
+
St as log,
|
|
2500
|
+
At as model,
|
|
2501
|
+
Nt as route
|
|
2477
2502
|
};
|