@luminix/core 0.0.1-beta.5 → 0.0.1-beta.6
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/core.js +369 -371
- package/dist/facades/App.d.ts +7 -0
- package/dist/mixins/BaseModel.d.ts +2 -2
- package/dist/types/App.d.ts +7 -0
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var je = Object.defineProperty;
|
|
2
|
+
var J = (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 Fe = (n, e, t) => e in n ? je(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
6
|
+
var p = (n, e, t) => Fe(n, typeof e != "symbol" ? e + "" : e, t), F = (n, e, t) => e.has(n) || J("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) ? J("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 R, isDraftable as
|
|
10
|
-
import K, { isAxiosError as
|
|
11
|
-
var
|
|
12
|
-
class
|
|
9
|
+
import { produce as R, isDraftable as Pe } from "immer";
|
|
10
|
+
import K, { isAxiosError as ke } from "axios";
|
|
11
|
+
var V, X;
|
|
12
|
+
class Qe extends (X = Error, V = Symbol.toStringTag, X) {
|
|
13
13
|
constructor(t) {
|
|
14
14
|
super(`[Luminix] Facade "${t}" not found`);
|
|
15
|
-
|
|
15
|
+
p(this, V, "FacadeNotFoundException");
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
class
|
|
18
|
+
class Le {
|
|
19
19
|
constructor(e) {
|
|
20
|
-
|
|
20
|
+
p(this, "_user");
|
|
21
21
|
this.app = e;
|
|
22
22
|
}
|
|
23
23
|
attempt(e, t = !1, r) {
|
|
@@ -64,7 +64,7 @@ class De {
|
|
|
64
64
|
return ((e = this.user()) == null ? void 0 : e.getKey()) || null;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
class
|
|
67
|
+
class Ce {
|
|
68
68
|
constructor(e) {
|
|
69
69
|
this._debug = e;
|
|
70
70
|
}
|
|
@@ -95,7 +95,7 @@ class He {
|
|
|
95
95
|
}
|
|
96
96
|
class S {
|
|
97
97
|
constructor(e) {
|
|
98
|
-
|
|
98
|
+
p(this, "locked", []);
|
|
99
99
|
this.bag = e, Object.freeze(this.bag);
|
|
100
100
|
}
|
|
101
101
|
get(e, t) {
|
|
@@ -192,93 +192,93 @@ class S {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
function A(n) {
|
|
195
|
-
var e, t, r, i,
|
|
195
|
+
var e, t, r, i, $e, u;
|
|
196
196
|
return u = class extends (t = n, e = Symbol.toStringTag, t) {
|
|
197
197
|
constructor(...d) {
|
|
198
198
|
super(...d);
|
|
199
199
|
q(this, i);
|
|
200
200
|
q(this, r);
|
|
201
|
-
|
|
202
|
-
P(this, r, D(this, i,
|
|
201
|
+
p(this, e, n.name);
|
|
202
|
+
P(this, r, D(this, i, $e).call(this));
|
|
203
203
|
}
|
|
204
|
-
on(d,
|
|
204
|
+
on(d, m) {
|
|
205
205
|
if (typeof d != "string")
|
|
206
206
|
throw new TypeError("event must be a string");
|
|
207
|
-
if (typeof
|
|
207
|
+
if (typeof m != "function")
|
|
208
208
|
throw new TypeError("callback must be a function");
|
|
209
|
-
return o(this, r).on(d,
|
|
209
|
+
return o(this, r).on(d, m);
|
|
210
210
|
}
|
|
211
|
-
once(d,
|
|
211
|
+
once(d, m) {
|
|
212
212
|
if (typeof d != "string")
|
|
213
213
|
throw new TypeError("event must be a string");
|
|
214
|
-
if (typeof
|
|
214
|
+
if (typeof m != "function")
|
|
215
215
|
throw new TypeError("callback must be a function");
|
|
216
|
-
const
|
|
217
|
-
|
|
216
|
+
const w = o(this, r).on(d, (b) => {
|
|
217
|
+
w(), m(b);
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
|
-
emit(d,
|
|
220
|
+
emit(d, m = {}) {
|
|
221
221
|
if (typeof d != "string")
|
|
222
222
|
throw new TypeError("event must be a string");
|
|
223
|
-
if (typeof
|
|
223
|
+
if (typeof m != "object")
|
|
224
224
|
throw new TypeError("data must be an object");
|
|
225
225
|
o(this, r).emit(d, {
|
|
226
|
-
...
|
|
226
|
+
...m,
|
|
227
227
|
source: this
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
|
-
}, r = new WeakMap(), i = new WeakSet(),
|
|
230
|
+
}, r = new WeakMap(), i = new WeakSet(), $e = function() {
|
|
231
231
|
return {
|
|
232
|
-
emit(d,
|
|
233
|
-
for (let
|
|
234
|
-
w
|
|
232
|
+
emit(d, m) {
|
|
233
|
+
for (let w = 0, b = this.events[d] || [], g = b.length; w < g; w++)
|
|
234
|
+
b[w](m);
|
|
235
235
|
},
|
|
236
236
|
events: {},
|
|
237
|
-
on(d,
|
|
238
|
-
var
|
|
239
|
-
return ((
|
|
240
|
-
var
|
|
241
|
-
this.events[d] = (
|
|
237
|
+
on(d, m) {
|
|
238
|
+
var w;
|
|
239
|
+
return ((w = this.events)[d] || (w[d] = [])).push(m), () => {
|
|
240
|
+
var b;
|
|
241
|
+
this.events[d] = (b = this.events[d]) == null ? void 0 : b.filter((g) => m !== g);
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
245
|
}, u;
|
|
246
246
|
}
|
|
247
|
-
function
|
|
247
|
+
function U(...n) {
|
|
248
248
|
return n.reduce((e, t) => e.flatMap((r) => t.map((i) => [r, i].flat())));
|
|
249
249
|
}
|
|
250
250
|
function $(n) {
|
|
251
251
|
return !(typeof n != "object" || n === null || !Reflect.has(n, "constructor") || Reflect.get(n.constructor, "name") !== "Collection");
|
|
252
252
|
}
|
|
253
|
-
var
|
|
254
|
-
class
|
|
253
|
+
var Y, Z;
|
|
254
|
+
class E extends (Z = Error, Y = Symbol.toStringTag, Z) {
|
|
255
255
|
constructor() {
|
|
256
256
|
super("[Luminix] Method not implemented.");
|
|
257
|
-
|
|
257
|
+
p(this, Y, "MethodNotImplementedException");
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
function c(n = [], e =
|
|
260
|
+
function c(n = [], e = k) {
|
|
261
261
|
if (!Array.isArray(n))
|
|
262
262
|
throw new TypeError("collect() expects an array");
|
|
263
263
|
return new (A(e))([...n]);
|
|
264
264
|
}
|
|
265
|
-
const
|
|
265
|
+
const _ = (n) => {
|
|
266
266
|
n.emit("change", {
|
|
267
267
|
items: n.all()
|
|
268
268
|
});
|
|
269
269
|
}, I = (n, e) => Array.isArray(n) ? n[e] ?? null : n.get(e);
|
|
270
|
-
var
|
|
271
|
-
class
|
|
270
|
+
var z, O, h;
|
|
271
|
+
class k {
|
|
272
272
|
constructor(e = []) {
|
|
273
273
|
// [Symbol.toStringTag] = 'Collection';
|
|
274
274
|
q(this, h);
|
|
275
|
-
|
|
275
|
+
p(this, z, "Collection");
|
|
276
276
|
P(this, h, e);
|
|
277
277
|
}
|
|
278
278
|
get items() {
|
|
279
279
|
return [...o(this, h)];
|
|
280
280
|
}
|
|
281
|
-
[(
|
|
281
|
+
[(O = Symbol.iterator, z = Symbol.toStringTag, O)]() {
|
|
282
282
|
return o(this, h)[Symbol.iterator]();
|
|
283
283
|
}
|
|
284
284
|
all() {
|
|
@@ -355,7 +355,7 @@ class Q {
|
|
|
355
355
|
}, {});
|
|
356
356
|
}
|
|
357
357
|
crossJoin(...e) {
|
|
358
|
-
return c(
|
|
358
|
+
return c(U(
|
|
359
359
|
o(this, h),
|
|
360
360
|
...e.map((t) => Array.isArray(t) ? t : t.all())
|
|
361
361
|
));
|
|
@@ -457,7 +457,7 @@ class Q {
|
|
|
457
457
|
return c(o(this, h).flatMap((t, r) => e(t, r, this)));
|
|
458
458
|
}
|
|
459
459
|
forget(e) {
|
|
460
|
-
return o(this, h).splice(e, 1),
|
|
460
|
+
return o(this, h).splice(e, 1), _(this), this;
|
|
461
461
|
}
|
|
462
462
|
forPage(e, t) {
|
|
463
463
|
return c(o(this, h).slice((e - 1) * t, e * t));
|
|
@@ -477,7 +477,7 @@ class Q {
|
|
|
477
477
|
}
|
|
478
478
|
return [String(i[l])];
|
|
479
479
|
});
|
|
480
|
-
return
|
|
480
|
+
return U(...u).forEach((l) => {
|
|
481
481
|
const d = Array.isArray(l) ? l.join(".") : l;
|
|
482
482
|
f.set(r, d, [
|
|
483
483
|
...f.get(r, d, []),
|
|
@@ -624,22 +624,22 @@ class Q {
|
|
|
624
624
|
}
|
|
625
625
|
pop(e = 1) {
|
|
626
626
|
const t = o(this, h).splice(o(this, h).length - e, e);
|
|
627
|
-
return
|
|
627
|
+
return _(this), e === 1 ? t[0] ?? null : c(t);
|
|
628
628
|
}
|
|
629
629
|
prepend(e) {
|
|
630
630
|
const t = o(this, h).unshift(e);
|
|
631
|
-
return
|
|
631
|
+
return _(this), t;
|
|
632
632
|
}
|
|
633
633
|
pull(e) {
|
|
634
634
|
const t = o(this, h).splice(e, 1)[0] ?? null;
|
|
635
|
-
return
|
|
635
|
+
return _(this), t;
|
|
636
636
|
}
|
|
637
637
|
push(...e) {
|
|
638
638
|
const t = o(this, h).push(...e);
|
|
639
|
-
return
|
|
639
|
+
return _(this), t;
|
|
640
640
|
}
|
|
641
641
|
put(e, t) {
|
|
642
|
-
return o(this, h).splice(e, 1, t),
|
|
642
|
+
return o(this, h).splice(e, 1, t), _(this), this;
|
|
643
643
|
}
|
|
644
644
|
random(e = 1) {
|
|
645
645
|
if (o(this, h).length < e)
|
|
@@ -675,7 +675,7 @@ class Q {
|
|
|
675
675
|
}
|
|
676
676
|
shift(e = 1) {
|
|
677
677
|
const t = o(this, h).splice(0, e);
|
|
678
|
-
return
|
|
678
|
+
return _(this), e === 1 ? t[0] ?? null : c(t);
|
|
679
679
|
}
|
|
680
680
|
shuffle() {
|
|
681
681
|
return c(f.shuffle(o(this, h)));
|
|
@@ -750,7 +750,7 @@ class Q {
|
|
|
750
750
|
}
|
|
751
751
|
splice(e, t, ...r) {
|
|
752
752
|
const i = t === void 0 ? o(this, h).length : t, s = o(this, h).splice(e, i, ...r);
|
|
753
|
-
return
|
|
753
|
+
return _(this), c(s);
|
|
754
754
|
}
|
|
755
755
|
split(e) {
|
|
756
756
|
const t = [];
|
|
@@ -804,7 +804,7 @@ class Q {
|
|
|
804
804
|
transform(e) {
|
|
805
805
|
for (const [t, r] of o(this, h).entries())
|
|
806
806
|
o(this, h).splice(t, 1, e(r, t, this));
|
|
807
|
-
return
|
|
807
|
+
return _(this), this;
|
|
808
808
|
}
|
|
809
809
|
unique(e) {
|
|
810
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))]);
|
|
@@ -902,30 +902,30 @@ class Q {
|
|
|
902
902
|
// HasEvents methods
|
|
903
903
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
904
904
|
on(e, t) {
|
|
905
|
-
throw new
|
|
905
|
+
throw new E();
|
|
906
906
|
}
|
|
907
907
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
908
908
|
once(e, t) {
|
|
909
|
-
throw new
|
|
909
|
+
throw new E();
|
|
910
910
|
}
|
|
911
911
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
912
912
|
emit(e, t) {
|
|
913
|
-
throw new
|
|
913
|
+
throw new E();
|
|
914
914
|
}
|
|
915
915
|
}
|
|
916
916
|
h = new WeakMap();
|
|
917
|
-
const
|
|
917
|
+
const Q = A(k);
|
|
918
918
|
var ee, te;
|
|
919
|
-
class
|
|
919
|
+
class H extends (te = k, ee = Symbol.toStringTag, te) {
|
|
920
920
|
constructor() {
|
|
921
921
|
super(...arguments);
|
|
922
|
-
|
|
922
|
+
p(this, ee, "Collection");
|
|
923
923
|
}
|
|
924
924
|
intersect(t) {
|
|
925
925
|
return this.filter((r) => t.some((i) => i.getKey() === r.getKey()));
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
|
-
const
|
|
928
|
+
const N = (...n) => {
|
|
929
929
|
const e = new URLSearchParams();
|
|
930
930
|
return n.forEach((t) => {
|
|
931
931
|
const [, ...r] = t.split("?");
|
|
@@ -935,17 +935,17 @@ const v = (...n) => {
|
|
|
935
935
|
}), e;
|
|
936
936
|
};
|
|
937
937
|
var re, se;
|
|
938
|
-
class
|
|
938
|
+
class Je extends (se = Error, re = Symbol.toStringTag, se) {
|
|
939
939
|
constructor(t) {
|
|
940
940
|
super(`[Luminix] Model "${t}" does not have a primary key`);
|
|
941
|
-
|
|
941
|
+
p(this, re, "ModelWithoutPrimaryKeyException");
|
|
942
942
|
}
|
|
943
943
|
}
|
|
944
|
-
const
|
|
945
|
-
class
|
|
944
|
+
const De = A(S);
|
|
945
|
+
class Ue {
|
|
946
946
|
constructor(e, t, r = {}) {
|
|
947
|
-
|
|
948
|
-
this.facades = e, this.abstract = t, this.query = r, this.bag = new
|
|
947
|
+
p(this, "bag");
|
|
948
|
+
this.facades = e, this.abstract = t, this.query = r, this.bag = new De(r), this.bag.on("change", () => {
|
|
949
949
|
this.emit("change", {
|
|
950
950
|
data: this.bag
|
|
951
951
|
});
|
|
@@ -953,15 +953,15 @@ class Ve {
|
|
|
953
953
|
}
|
|
954
954
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
955
955
|
on(e, t) {
|
|
956
|
-
throw new
|
|
956
|
+
throw new E();
|
|
957
957
|
}
|
|
958
958
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
959
959
|
once(e, t) {
|
|
960
|
-
throw new
|
|
960
|
+
throw new E();
|
|
961
961
|
}
|
|
962
962
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
963
963
|
emit(e, t) {
|
|
964
|
-
throw new
|
|
964
|
+
throw new E();
|
|
965
965
|
}
|
|
966
966
|
lock(e) {
|
|
967
967
|
this.bag.lock(e);
|
|
@@ -1044,23 +1044,23 @@ class Ve {
|
|
|
1044
1044
|
class: this.abstract,
|
|
1045
1045
|
model: a
|
|
1046
1046
|
}), a;
|
|
1047
|
-
}),
|
|
1047
|
+
}), H);
|
|
1048
1048
|
if (t) {
|
|
1049
1049
|
const [u] = t.split("?");
|
|
1050
1050
|
return {
|
|
1051
1051
|
...r,
|
|
1052
1052
|
data: s,
|
|
1053
1053
|
links: {
|
|
1054
|
-
first: `${u}?${
|
|
1055
|
-
last: `${u}?${
|
|
1056
|
-
next: r.links.next && `${u}?${
|
|
1057
|
-
prev: r.links.prev && `${u}?${
|
|
1054
|
+
first: `${u}?${N(t, r.links.first).toString()}`,
|
|
1055
|
+
last: `${u}?${N(t, r.links.last).toString()}`,
|
|
1056
|
+
next: r.links.next && `${u}?${N(t, r.links.next).toString()}`,
|
|
1057
|
+
prev: r.links.prev && `${u}?${N(t, r.links.prev).toString()}`
|
|
1058
1058
|
},
|
|
1059
1059
|
meta: {
|
|
1060
1060
|
...r.meta,
|
|
1061
1061
|
links: r.meta.links.map((a) => ({
|
|
1062
1062
|
...a,
|
|
1063
|
-
url: a.url && `${u}?${
|
|
1063
|
+
url: a.url && `${u}?${N(t, a.url).toString()}`
|
|
1064
1064
|
}))
|
|
1065
1065
|
}
|
|
1066
1066
|
};
|
|
@@ -1092,7 +1092,7 @@ class Ve {
|
|
|
1092
1092
|
async find(e) {
|
|
1093
1093
|
const t = this.facades.model.schema(this.abstract).primaryKey;
|
|
1094
1094
|
if (!t)
|
|
1095
|
-
throw new
|
|
1095
|
+
throw new Je(this.abstract);
|
|
1096
1096
|
const r = await this.where(t, e).limit(1).exec(1);
|
|
1097
1097
|
return this.emit("success", {
|
|
1098
1098
|
response: r,
|
|
@@ -1107,7 +1107,7 @@ class Ve {
|
|
|
1107
1107
|
i.map((a) => this.limit(e).exec(a))
|
|
1108
1108
|
), u = c(
|
|
1109
1109
|
s.reduce((a, l) => (a.push(...l.data), a), t.data).all(),
|
|
1110
|
-
|
|
1110
|
+
H
|
|
1111
1111
|
);
|
|
1112
1112
|
return this.emit("success", {
|
|
1113
1113
|
response: {
|
|
@@ -1118,43 +1118,43 @@ class Ve {
|
|
|
1118
1118
|
}), u;
|
|
1119
1119
|
}
|
|
1120
1120
|
}
|
|
1121
|
-
const
|
|
1121
|
+
const He = A(Ue);
|
|
1122
1122
|
var ie, ne;
|
|
1123
|
-
class
|
|
1123
|
+
class T extends (ne = Error, ie = Symbol.toStringTag, ne) {
|
|
1124
1124
|
constructor(t) {
|
|
1125
1125
|
super(`[Luminix] Expected ${t} to be reducible.`);
|
|
1126
|
-
|
|
1126
|
+
p(this, ie, "NotReducibleException");
|
|
1127
1127
|
}
|
|
1128
1128
|
}
|
|
1129
1129
|
var oe, he;
|
|
1130
|
-
class
|
|
1130
|
+
class M extends (he = TypeError, oe = Symbol.toStringTag, he) {
|
|
1131
1131
|
constructor(t, r = "Model") {
|
|
1132
1132
|
super(`[Luminix] "${t}" expects ${r}`);
|
|
1133
|
-
|
|
1133
|
+
p(this, oe, "NotModelException");
|
|
1134
1134
|
}
|
|
1135
1135
|
}
|
|
1136
1136
|
var ue, ae;
|
|
1137
|
-
class
|
|
1137
|
+
class We extends (ae = Error, ue = Symbol.toStringTag, ae) {
|
|
1138
1138
|
constructor(t, r, i, s) {
|
|
1139
1139
|
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}".`);
|
|
1140
|
-
|
|
1140
|
+
p(this, ue, "NoInverseRelationException");
|
|
1141
1141
|
}
|
|
1142
1142
|
}
|
|
1143
1143
|
var le, ce;
|
|
1144
|
-
class
|
|
1144
|
+
class Ge extends (ce = Error, le = Symbol.toStringTag, ce) {
|
|
1145
1145
|
constructor(t) {
|
|
1146
1146
|
super(`[Luminix] Relation "${t}" is not supported`);
|
|
1147
|
-
|
|
1147
|
+
p(this, le, "UnsupportedRelationException");
|
|
1148
1148
|
}
|
|
1149
1149
|
}
|
|
1150
|
-
function
|
|
1150
|
+
function x(n) {
|
|
1151
1151
|
return typeof n == "object" && n !== null && n.__isModel === !0;
|
|
1152
1152
|
}
|
|
1153
1153
|
class j {
|
|
1154
1154
|
constructor(e, t, r, i = null) {
|
|
1155
|
-
|
|
1156
|
-
if (this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !
|
|
1157
|
-
throw new
|
|
1155
|
+
p(this, "unsubscribeQuery", null);
|
|
1156
|
+
if (this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !x(i) && !($(i) && i.every(x)))
|
|
1157
|
+
throw new M("Relation.constructor()", "Model, Collection<Model> or null");
|
|
1158
1158
|
}
|
|
1159
1159
|
make(e) {
|
|
1160
1160
|
const t = this.getRelated();
|
|
@@ -1176,7 +1176,7 @@ class j {
|
|
|
1176
1176
|
guessInverseRelation() {
|
|
1177
1177
|
const { relations: e } = this.getRelated().getSchema();
|
|
1178
1178
|
if (typeof this.facades.model.guessInverseRelation != "function")
|
|
1179
|
-
throw new
|
|
1179
|
+
throw new T("ModelFacade");
|
|
1180
1180
|
const t = this.getType(), r = this.facades.model.guessInverseRelation({
|
|
1181
1181
|
HasOne: ["BelongsTo"],
|
|
1182
1182
|
HasMany: ["BelongsTo"],
|
|
@@ -1188,18 +1188,18 @@ class j {
|
|
|
1188
1188
|
MorphToMany: ["MorphToMany"]
|
|
1189
1189
|
}, this.parent, t, this.getRelated());
|
|
1190
1190
|
if (!(t in r))
|
|
1191
|
-
throw new
|
|
1191
|
+
throw new Ge(t);
|
|
1192
1192
|
for (const i in e) {
|
|
1193
1193
|
const s = e[i];
|
|
1194
1194
|
if ((s.model === this.parent.getType() || ["MorphOne", "MorphMany"].includes(t)) && r[t].includes(s.type))
|
|
1195
1195
|
return i;
|
|
1196
1196
|
}
|
|
1197
|
-
throw new
|
|
1197
|
+
throw new We(this.parent.getType(), t, this.getRelated().getSchemaName(), r[t].join(" or "));
|
|
1198
1198
|
}
|
|
1199
1199
|
set(e) {
|
|
1200
|
-
if (e !== null && !
|
|
1201
|
-
throw new
|
|
1202
|
-
!this.items ||
|
|
1200
|
+
if (e !== null && !x(e) && !($(e) && e.every(x)))
|
|
1201
|
+
throw new M("Relation.set()", "Model, Collection<Model> or null");
|
|
1202
|
+
!this.items || x(this.items) ? this.items = e : $(e) && this.items.splice(0, this.items.count(), ...e);
|
|
1203
1203
|
}
|
|
1204
1204
|
getForeignKey() {
|
|
1205
1205
|
return this.meta.foreignKey;
|
|
@@ -1229,7 +1229,7 @@ class j {
|
|
|
1229
1229
|
return this.items;
|
|
1230
1230
|
}
|
|
1231
1231
|
isSingle() {
|
|
1232
|
-
return
|
|
1232
|
+
return x(this.items);
|
|
1233
1233
|
}
|
|
1234
1234
|
isMultiple() {
|
|
1235
1235
|
return $(this.items);
|
|
@@ -1278,30 +1278,23 @@ class j {
|
|
|
1278
1278
|
// }
|
|
1279
1279
|
}
|
|
1280
1280
|
var de, fe;
|
|
1281
|
-
class
|
|
1282
|
-
constructor(t, r) {
|
|
1283
|
-
super(`[Luminix] Attribute "${r}" in model "${t}" is not fillable`);
|
|
1284
|
-
m(this, de, "AttributeNotFillableException");
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
var pe, me;
|
|
1288
|
-
class ve extends (me = Error, pe = Symbol.toStringTag, me) {
|
|
1281
|
+
class Ae extends (fe = Error, de = Symbol.toStringTag, fe) {
|
|
1289
1282
|
constructor(t, r) {
|
|
1290
1283
|
super(`[Luminix] Model "${t}" must be persisted before calling "${r}"`);
|
|
1291
|
-
|
|
1284
|
+
p(this, de, "ModelNotPersistedException");
|
|
1292
1285
|
}
|
|
1293
1286
|
}
|
|
1294
|
-
function
|
|
1287
|
+
function Ve(n, e) {
|
|
1295
1288
|
var r;
|
|
1296
1289
|
r = Symbol.toStringTag;
|
|
1297
1290
|
class t {
|
|
1298
1291
|
constructor(s = {}) {
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1292
|
+
p(this, "_attributes", new S({}));
|
|
1293
|
+
p(this, "_original", {});
|
|
1294
|
+
p(this, "_relations", {});
|
|
1295
|
+
p(this, "_changedKeys", []);
|
|
1296
|
+
p(this, "exists", !1);
|
|
1297
|
+
p(this, r, f.upperFirst(f.camelCase(e)));
|
|
1305
1298
|
this.makeRelations(), this.makeAttributes(s);
|
|
1306
1299
|
}
|
|
1307
1300
|
cast(s, u) {
|
|
@@ -1311,32 +1304,30 @@ function ze(n, e) {
|
|
|
1311
1304
|
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;
|
|
1312
1305
|
}
|
|
1313
1306
|
makeRelations() {
|
|
1314
|
-
const { relations: s } = n.model.schema(e);
|
|
1307
|
+
const { relations: s } = n.make("model").schema(e);
|
|
1315
1308
|
if (this._relations = {}, !s)
|
|
1316
1309
|
return;
|
|
1317
|
-
|
|
1318
|
-
throw new _("ModelFacade");
|
|
1319
|
-
const u = n.model.relationMap({}, e);
|
|
1310
|
+
const u = n.make("model").relationMap({}, e);
|
|
1320
1311
|
Object.entries(s).forEach(([a, l]) => {
|
|
1321
|
-
const { type: d } = l,
|
|
1322
|
-
this._relations[a] = new
|
|
1312
|
+
const { type: d } = l, m = d in u ? u[d] : j;
|
|
1313
|
+
this._relations[a] = new m(
|
|
1323
1314
|
{ name: a, ...l },
|
|
1324
|
-
n,
|
|
1315
|
+
n.make(),
|
|
1325
1316
|
this,
|
|
1326
1317
|
null
|
|
1327
1318
|
);
|
|
1328
1319
|
});
|
|
1329
1320
|
}
|
|
1330
1321
|
makeAttributes(s) {
|
|
1331
|
-
const { relations: u } = n.model.schema(e), a = Object.keys(u || {}), l = f.omit(s, a);
|
|
1322
|
+
const { relations: u } = n.make("model").schema(e), a = Object.keys(u || {}), l = f.omit(s, a);
|
|
1332
1323
|
if (this.fillable.filter((d) => !(d in l)).forEach((d) => {
|
|
1333
1324
|
l[d] = null;
|
|
1334
1325
|
}), u && Object.keys(u).forEach((d) => {
|
|
1335
1326
|
this.relation(f.camelCase(d)).make(s[d]);
|
|
1336
1327
|
}), !this.validateJsonObject(l)) {
|
|
1337
|
-
if (n.
|
|
1328
|
+
if (n.isProduction())
|
|
1338
1329
|
throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
|
|
1339
|
-
n.log.warning(`Invalid attributes for model "${e}".
|
|
1330
|
+
n.make("log").warning(`Invalid attributes for model "${e}".
|
|
1340
1331
|
This will throw an error in production.`, {
|
|
1341
1332
|
attributes: s,
|
|
1342
1333
|
abstract: e
|
|
@@ -1357,7 +1348,7 @@ function ze(n, e) {
|
|
|
1357
1348
|
dispatchCreateEvent(s) {
|
|
1358
1349
|
this.emit("create", {
|
|
1359
1350
|
value: s
|
|
1360
|
-
}), n.model.emit("create", {
|
|
1351
|
+
}), n.make("model").emit("create", {
|
|
1361
1352
|
class: e,
|
|
1362
1353
|
model: this
|
|
1363
1354
|
});
|
|
@@ -1365,7 +1356,7 @@ function ze(n, e) {
|
|
|
1365
1356
|
dispatchUpdateEvent(s) {
|
|
1366
1357
|
this.emit("update", {
|
|
1367
1358
|
value: s
|
|
1368
|
-
}), n.model.emit("update", {
|
|
1359
|
+
}), n.make("model").emit("update", {
|
|
1369
1360
|
class: e,
|
|
1370
1361
|
model: this
|
|
1371
1362
|
});
|
|
@@ -1373,7 +1364,7 @@ function ze(n, e) {
|
|
|
1373
1364
|
dispatchSaveEvent() {
|
|
1374
1365
|
this.emit("save", {
|
|
1375
1366
|
value: this.diff()
|
|
1376
|
-
}), n.model.emit("save", {
|
|
1367
|
+
}), n.make("model").emit("save", {
|
|
1377
1368
|
class: e,
|
|
1378
1369
|
model: this
|
|
1379
1370
|
});
|
|
@@ -1382,7 +1373,7 @@ function ze(n, e) {
|
|
|
1382
1373
|
this.emit("delete", {
|
|
1383
1374
|
force: s,
|
|
1384
1375
|
[this.getKeyName()]: this.getKey()
|
|
1385
|
-
}), n.model.emit("delete", {
|
|
1376
|
+
}), n.make("model").emit("delete", {
|
|
1386
1377
|
class: e,
|
|
1387
1378
|
model: this,
|
|
1388
1379
|
force: s
|
|
@@ -1391,7 +1382,7 @@ function ze(n, e) {
|
|
|
1391
1382
|
dispatchRestoreEvent() {
|
|
1392
1383
|
this.emit("restore", {
|
|
1393
1384
|
value: this.attributes
|
|
1394
|
-
}), n.model.emit("restore", {
|
|
1385
|
+
}), n.make("model").emit("restore", {
|
|
1395
1386
|
class: e,
|
|
1396
1387
|
model: this
|
|
1397
1388
|
});
|
|
@@ -1400,7 +1391,7 @@ function ze(n, e) {
|
|
|
1400
1391
|
this.emit("error", {
|
|
1401
1392
|
error: s,
|
|
1402
1393
|
operation: u
|
|
1403
|
-
}), n.model.emit("error", {
|
|
1394
|
+
}), n.make("model").emit("error", {
|
|
1404
1395
|
class: e,
|
|
1405
1396
|
model: this,
|
|
1406
1397
|
error: s,
|
|
@@ -1424,20 +1415,20 @@ function ze(n, e) {
|
|
|
1424
1415
|
return this._relations;
|
|
1425
1416
|
}
|
|
1426
1417
|
get fillable() {
|
|
1427
|
-
return n.model.schema(e).fillable;
|
|
1418
|
+
return n.make("model").schema(e).fillable;
|
|
1428
1419
|
}
|
|
1429
1420
|
get primaryKey() {
|
|
1430
|
-
return n.model.schema(e).primaryKey;
|
|
1421
|
+
return n.make("model").schema(e).primaryKey;
|
|
1431
1422
|
}
|
|
1432
1423
|
get timestamps() {
|
|
1433
|
-
return n.model.schema(e).timestamps;
|
|
1424
|
+
return n.make("model").schema(e).timestamps;
|
|
1434
1425
|
}
|
|
1435
1426
|
// get softDeletes() {
|
|
1436
|
-
// return
|
|
1427
|
+
// return app.make('model').schema(abstract).softDeletes;
|
|
1437
1428
|
// }
|
|
1438
1429
|
get casts() {
|
|
1439
1430
|
return {
|
|
1440
|
-
...n.model.schema(e).casts,
|
|
1431
|
+
...n.make("model").schema(e).casts,
|
|
1441
1432
|
...this.timestamps ? { created_at: "datetime", updated_at: "datetime" } : {}
|
|
1442
1433
|
// ...this.softDeletes ? { deleted_at: 'datetime' } : {},
|
|
1443
1434
|
};
|
|
@@ -1448,30 +1439,23 @@ function ze(n, e) {
|
|
|
1448
1439
|
getAttribute(s) {
|
|
1449
1440
|
let u = this._attributes.get(s, null);
|
|
1450
1441
|
s in this.casts && (u = this.cast(u, this.casts[s]));
|
|
1451
|
-
const a = n.model[`model${f.upperFirst(f.camelCase(e))}Get${f.upperFirst(f.camelCase(s))}Attribute`];
|
|
1442
|
+
const a = n.make("model")[`model${f.upperFirst(f.camelCase(e))}Get${f.upperFirst(f.camelCase(s))}Attribute`];
|
|
1452
1443
|
if (typeof a != "function")
|
|
1453
|
-
throw new
|
|
1454
|
-
return a.bind(n.model)(u, this);
|
|
1444
|
+
throw new T("ModelFacade");
|
|
1445
|
+
return a.bind(n.make("model"))(u, this);
|
|
1455
1446
|
}
|
|
1456
1447
|
setAttribute(s, u) {
|
|
1457
|
-
|
|
1458
|
-
if (n.config.get("app.env", "production") === "production")
|
|
1459
|
-
throw new Ne(e, s);
|
|
1460
|
-
n.log.warning(`[Luminix] Trying to set a non-fillable attribute "${s}" in model "${e}".
|
|
1461
|
-
This will throw an error in production.`);
|
|
1462
|
-
return;
|
|
1463
|
-
}
|
|
1464
|
-
const a = n.model[`model${f.upperFirst(f.camelCase(e))}Set${f.upperFirst(f.camelCase(s))}Attribute`];
|
|
1448
|
+
const a = n.make("model")[`model${f.upperFirst(f.camelCase(e))}Set${f.upperFirst(f.camelCase(s))}Attribute`];
|
|
1465
1449
|
if (typeof a != "function")
|
|
1466
|
-
throw new
|
|
1467
|
-
const l = a.bind(n.model)(
|
|
1450
|
+
throw new T("ModelFacade");
|
|
1451
|
+
const l = a.bind(n.make("model"))(
|
|
1468
1452
|
this.mutate(u, this.casts[s]),
|
|
1469
1453
|
this
|
|
1470
1454
|
);
|
|
1471
1455
|
if (!this.validateJsonObject({ [s]: l })) {
|
|
1472
|
-
if (n.
|
|
1456
|
+
if (n.isProduction())
|
|
1473
1457
|
throw new TypeError(`[Luminix] Attribute "${s}" in model "${e}" must be a boolean, number, string or null`);
|
|
1474
|
-
n.log.warning(`Invalid type for attribute "${s}" in model "${e}" after mutation.
|
|
1458
|
+
n.make("log").warning(`Invalid type for attribute "${s}" in model "${e}" after mutation.
|
|
1475
1459
|
This will throw an error in production.`, {
|
|
1476
1460
|
key: s,
|
|
1477
1461
|
value: u,
|
|
@@ -1490,19 +1474,19 @@ function ze(n, e) {
|
|
|
1490
1474
|
return this.primaryKey;
|
|
1491
1475
|
}
|
|
1492
1476
|
fill(s) {
|
|
1493
|
-
const u = f.pick(s, this.fillable), a = Object.entries(u).reduce((l, [d,
|
|
1494
|
-
const
|
|
1495
|
-
if (typeof
|
|
1496
|
-
throw new
|
|
1497
|
-
return l[d] =
|
|
1498
|
-
this.mutate(
|
|
1477
|
+
const u = f.pick(s, this.fillable), a = Object.entries(u).reduce((l, [d, m]) => {
|
|
1478
|
+
const w = n.make("model")[`model${f.upperFirst(f.camelCase(e))}Set${f.upperFirst(f.camelCase(d))}Attribute`];
|
|
1479
|
+
if (typeof w != "function")
|
|
1480
|
+
throw new T("ModelFacade");
|
|
1481
|
+
return l[d] = w.bind(n.make("model"))(
|
|
1482
|
+
this.mutate(m, this.casts[d]),
|
|
1499
1483
|
this
|
|
1500
1484
|
), l;
|
|
1501
1485
|
}, {});
|
|
1502
1486
|
if (!this.validateJsonObject(a)) {
|
|
1503
|
-
if (n.
|
|
1487
|
+
if (n.isProduction())
|
|
1504
1488
|
throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
|
|
1505
|
-
n.log.warning(`Invalid attributes for model "${e}" after mutation.
|
|
1489
|
+
n.make("log").warning(`Invalid attributes for model "${e}" after mutation.
|
|
1506
1490
|
This will throw an error in production.`, {
|
|
1507
1491
|
attributes: s,
|
|
1508
1492
|
mutatedAttributes: a,
|
|
@@ -1514,16 +1498,16 @@ function ze(n, e) {
|
|
|
1514
1498
|
this._attributes.merge(".", a), Object.keys(a).forEach((l) => this.updateChangedKeys(l)), this.dispatchChangeEvent(a);
|
|
1515
1499
|
}
|
|
1516
1500
|
dump() {
|
|
1517
|
-
n.log.info({
|
|
1501
|
+
n.make("log").info({
|
|
1518
1502
|
...this.toJson(),
|
|
1519
1503
|
[Symbol.toStringTag]: f.upperFirst(f.camelCase(e))
|
|
1520
1504
|
});
|
|
1521
1505
|
}
|
|
1522
1506
|
toJson() {
|
|
1523
|
-
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((
|
|
1507
|
+
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((m) => m.toJson()).all())), a), {}), u = n.make("model")[`model${f.upperFirst(f.camelCase(e))}Json`];
|
|
1524
1508
|
if (typeof u != "function")
|
|
1525
|
-
throw new
|
|
1526
|
-
return u.bind(n.model)({
|
|
1509
|
+
throw new T("ModelFacade");
|
|
1510
|
+
return u.bind(n.make("model"))({
|
|
1527
1511
|
...this.attributes,
|
|
1528
1512
|
...s
|
|
1529
1513
|
}, this);
|
|
@@ -1540,8 +1524,8 @@ function ze(n, e) {
|
|
|
1540
1524
|
}
|
|
1541
1525
|
async refresh() {
|
|
1542
1526
|
if (!this.exists)
|
|
1543
|
-
throw new
|
|
1544
|
-
const { data: s } = await n.route.call([
|
|
1527
|
+
throw new Ae(e, "refresh");
|
|
1528
|
+
const { data: s } = await n.make("route").call([
|
|
1545
1529
|
`luminix.${e}.show`,
|
|
1546
1530
|
this.makePrimaryKeyReplacer()
|
|
1547
1531
|
], {
|
|
@@ -1557,7 +1541,7 @@ function ze(n, e) {
|
|
|
1557
1541
|
} = s, l = this.exists, d = l ? [
|
|
1558
1542
|
`luminix.${e}.update`,
|
|
1559
1543
|
this.makePrimaryKeyReplacer()
|
|
1560
|
-
] : `luminix.${e}.store`,
|
|
1544
|
+
] : `luminix.${e}.store`, m = await n.make("route").call(
|
|
1561
1545
|
d,
|
|
1562
1546
|
{
|
|
1563
1547
|
data: {
|
|
@@ -1570,19 +1554,19 @@ function ze(n, e) {
|
|
|
1570
1554
|
errorBag: l ? `${e}[${this.getKey()}].update` : `${e}.store`
|
|
1571
1555
|
}
|
|
1572
1556
|
);
|
|
1573
|
-
if ([200, 201].includes(
|
|
1574
|
-
return this.makeAttributes(
|
|
1575
|
-
throw
|
|
1557
|
+
if ([200, 201].includes(m.status))
|
|
1558
|
+
return this.makeAttributes(m.data), this.exists = !0, this.dispatchSaveEvent(), l ? this.dispatchUpdateEvent(m.data) : this.dispatchCreateEvent(m.data), m;
|
|
1559
|
+
throw m;
|
|
1576
1560
|
} catch (u) {
|
|
1577
|
-
throw n.log.error(u), this.dispatchErrorEvent(u, "save"), u;
|
|
1561
|
+
throw n.make("log").error(u), this.dispatchErrorEvent(u, "save"), u;
|
|
1578
1562
|
}
|
|
1579
1563
|
}
|
|
1580
1564
|
async push() {
|
|
1581
|
-
throw new
|
|
1565
|
+
throw new E();
|
|
1582
1566
|
}
|
|
1583
1567
|
async delete() {
|
|
1584
1568
|
try {
|
|
1585
|
-
const s = await n.route.call([
|
|
1569
|
+
const s = await n.make("route").call([
|
|
1586
1570
|
`luminix.${e}.destroy`,
|
|
1587
1571
|
this.makePrimaryKeyReplacer()
|
|
1588
1572
|
], {
|
|
@@ -1592,12 +1576,12 @@ function ze(n, e) {
|
|
|
1592
1576
|
return this.dispatchDeleteEvent(), s;
|
|
1593
1577
|
throw s;
|
|
1594
1578
|
} catch (s) {
|
|
1595
|
-
throw n.log.error(s), this.dispatchErrorEvent(s, "delete"), s;
|
|
1579
|
+
throw n.make("log").error(s), this.dispatchErrorEvent(s, "delete"), s;
|
|
1596
1580
|
}
|
|
1597
1581
|
}
|
|
1598
1582
|
async update(s) {
|
|
1599
1583
|
try {
|
|
1600
|
-
const u = await n.route.call([
|
|
1584
|
+
const u = await n.make("route").call([
|
|
1601
1585
|
`luminix.${e}.update`,
|
|
1602
1586
|
this.makePrimaryKeyReplacer()
|
|
1603
1587
|
], {
|
|
@@ -1610,12 +1594,12 @@ function ze(n, e) {
|
|
|
1610
1594
|
}
|
|
1611
1595
|
throw u;
|
|
1612
1596
|
} catch (u) {
|
|
1613
|
-
throw n.log.error(u), this.dispatchErrorEvent(u, "save"), u;
|
|
1597
|
+
throw n.make("log").error(u), this.dispatchErrorEvent(u, "save"), u;
|
|
1614
1598
|
}
|
|
1615
1599
|
}
|
|
1616
1600
|
async forceDelete() {
|
|
1617
1601
|
try {
|
|
1618
|
-
const s = await n.route.call(
|
|
1602
|
+
const s = await n.make("route").call(
|
|
1619
1603
|
[
|
|
1620
1604
|
`luminix.${e}.destroy`,
|
|
1621
1605
|
this.makePrimaryKeyReplacer()
|
|
@@ -1629,12 +1613,12 @@ function ze(n, e) {
|
|
|
1629
1613
|
return this.dispatchDeleteEvent(!0), s;
|
|
1630
1614
|
throw s;
|
|
1631
1615
|
} catch (s) {
|
|
1632
|
-
throw n.log.error(s), this.dispatchErrorEvent(s, "forceDelete"), s;
|
|
1616
|
+
throw n.make("log").error(s), this.dispatchErrorEvent(s, "forceDelete"), s;
|
|
1633
1617
|
}
|
|
1634
1618
|
}
|
|
1635
1619
|
async restore() {
|
|
1636
1620
|
try {
|
|
1637
|
-
const s = await n.route.call(
|
|
1621
|
+
const s = await n.make("route").call(
|
|
1638
1622
|
[
|
|
1639
1623
|
`luminix.${e}.update`,
|
|
1640
1624
|
this.makePrimaryKeyReplacer()
|
|
@@ -1648,17 +1632,17 @@ function ze(n, e) {
|
|
|
1648
1632
|
return this.dispatchRestoreEvent(), s;
|
|
1649
1633
|
throw s;
|
|
1650
1634
|
} catch (s) {
|
|
1651
|
-
throw n.log.error(s), this.dispatchErrorEvent(s, "restore"), s;
|
|
1635
|
+
throw n.make("log").error(s), this.dispatchErrorEvent(s, "restore"), s;
|
|
1652
1636
|
}
|
|
1653
1637
|
}
|
|
1654
1638
|
static getSchemaName() {
|
|
1655
1639
|
return e;
|
|
1656
1640
|
}
|
|
1657
1641
|
static getSchema() {
|
|
1658
|
-
return n.model.schema(e);
|
|
1642
|
+
return n.make("model").schema(e);
|
|
1659
1643
|
}
|
|
1660
1644
|
static query() {
|
|
1661
|
-
return new
|
|
1645
|
+
return new He(n.make(), e);
|
|
1662
1646
|
}
|
|
1663
1647
|
static where(...s) {
|
|
1664
1648
|
return this.query().where(...s);
|
|
@@ -1697,130 +1681,122 @@ function ze(n, e) {
|
|
|
1697
1681
|
return this.query().first();
|
|
1698
1682
|
}
|
|
1699
1683
|
static async create(s) {
|
|
1700
|
-
const u = n.model.make(e), a = new u();
|
|
1684
|
+
const u = n.make("model").make(e), a = new u();
|
|
1701
1685
|
return a.fill(s), await a.save(), a;
|
|
1702
1686
|
}
|
|
1703
1687
|
static async update(s, u) {
|
|
1704
|
-
const a = n.model.make(e), l = new a({ id: s });
|
|
1688
|
+
const a = n.make("model").make(e), l = new a({ id: s });
|
|
1705
1689
|
return l.fill(u), l.exists = !0, await l.save(), l;
|
|
1706
1690
|
}
|
|
1707
1691
|
static delete(s) {
|
|
1708
1692
|
if (Array.isArray(s))
|
|
1709
|
-
return n.route.call(`luminix.${e}.destroyMany`, {
|
|
1693
|
+
return n.make("route").call(`luminix.${e}.destroyMany`, {
|
|
1710
1694
|
params: { ids: s },
|
|
1711
1695
|
errorBag: `${e}.deleteMany`
|
|
1712
1696
|
});
|
|
1713
|
-
const u = n.model.make(e);
|
|
1697
|
+
const u = n.make("model").make(e);
|
|
1714
1698
|
return new u({ id: s }).delete();
|
|
1715
1699
|
}
|
|
1716
1700
|
static async restore(s) {
|
|
1717
1701
|
if (Array.isArray(s))
|
|
1718
|
-
return n.route.call(`luminix.${e}.restoreMany`, {
|
|
1702
|
+
return n.make("route").call(`luminix.${e}.restoreMany`, {
|
|
1719
1703
|
data: { ids: s },
|
|
1720
1704
|
errorBag: `${e}.restoreMany`
|
|
1721
1705
|
});
|
|
1722
|
-
const u = n.model.make(e);
|
|
1706
|
+
const u = n.make("model").make(e);
|
|
1723
1707
|
return new u({ id: s }).restore();
|
|
1724
1708
|
}
|
|
1725
1709
|
static forceDelete(s) {
|
|
1726
1710
|
if (Array.isArray(s))
|
|
1727
|
-
return n.route.call(`luminix.${e}.destroyMany`, {
|
|
1711
|
+
return n.make("route").call(`luminix.${e}.destroyMany`, {
|
|
1728
1712
|
params: { ids: s, force: !0 },
|
|
1729
1713
|
errorBag: `${e}.forceDeleteMany`
|
|
1730
1714
|
});
|
|
1731
|
-
const u = n.model.make(e);
|
|
1715
|
+
const u = n.make("model").make(e);
|
|
1732
1716
|
return new u({ id: s }).forceDelete();
|
|
1733
1717
|
}
|
|
1734
1718
|
static singular() {
|
|
1735
|
-
return n.model.schema(e).displayName.singular;
|
|
1719
|
+
return n.make("model").schema(e).displayName.singular;
|
|
1736
1720
|
}
|
|
1737
1721
|
static plural() {
|
|
1738
|
-
return n.model.schema(e).displayName.plural;
|
|
1722
|
+
return n.make("model").schema(e).displayName.plural;
|
|
1739
1723
|
}
|
|
1740
1724
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1741
1725
|
on(s, u) {
|
|
1742
|
-
throw new
|
|
1726
|
+
throw new E();
|
|
1743
1727
|
}
|
|
1744
1728
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1745
1729
|
once(s, u) {
|
|
1746
|
-
throw new
|
|
1730
|
+
throw new E();
|
|
1747
1731
|
}
|
|
1748
1732
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1749
1733
|
emit(s, u) {
|
|
1750
|
-
throw new
|
|
1734
|
+
throw new E();
|
|
1751
1735
|
}
|
|
1752
1736
|
}
|
|
1753
|
-
return A(t);
|
|
1737
|
+
return p(t, "name", f.upperFirst(f.camelCase(e))), A(t);
|
|
1754
1738
|
}
|
|
1755
|
-
function
|
|
1739
|
+
function Xe(n, e, t) {
|
|
1756
1740
|
var r, i;
|
|
1757
1741
|
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
1758
1742
|
constructor(u = {}) {
|
|
1759
1743
|
super(u);
|
|
1760
|
-
|
|
1744
|
+
p(this, r, f.upperFirst(f.camelCase(e)));
|
|
1761
1745
|
return new Proxy(this, {
|
|
1762
1746
|
get: (a, l) => {
|
|
1763
1747
|
if (l === "__isModel")
|
|
1764
1748
|
return !0;
|
|
1765
|
-
if (l in a)
|
|
1766
|
-
|
|
1767
|
-
return typeof p == "function" ? p.bind(a) : p;
|
|
1768
|
-
}
|
|
1749
|
+
if (l in a)
|
|
1750
|
+
return Reflect.get(a, l);
|
|
1769
1751
|
if (l !== f.camelCase(l))
|
|
1770
1752
|
return;
|
|
1771
1753
|
const d = f.snakeCase(l);
|
|
1754
|
+
if (Object.keys(a.attributes).includes(d))
|
|
1755
|
+
return a.getAttribute(d);
|
|
1772
1756
|
if (Object.keys(a.relations).includes(d))
|
|
1773
1757
|
return a.relations[d].getLoadedItems();
|
|
1774
1758
|
if (l.endsWith("Relation") && Object.keys(a.relations).includes(f.snakeCase(l.slice(0, -8))))
|
|
1775
1759
|
return () => a.relation(l.slice(0, -8));
|
|
1776
|
-
if (Object.keys(a.attributes).includes(d))
|
|
1777
|
-
return a.getAttribute(d);
|
|
1778
1760
|
if (n.model.hasReducer(`model${a.constructor.name}Get${f.upperFirst(l)}Attribute`)) {
|
|
1779
|
-
const
|
|
1780
|
-
if (typeof
|
|
1781
|
-
throw new
|
|
1782
|
-
return
|
|
1761
|
+
const m = n.model[`model${a.constructor.name}Get${f.upperFirst(l)}Attribute`];
|
|
1762
|
+
if (typeof m != "function")
|
|
1763
|
+
throw new T("ModelFacade");
|
|
1764
|
+
return m.bind(n.model)(void 0, a);
|
|
1783
1765
|
}
|
|
1784
1766
|
return Reflect.get(a, l);
|
|
1785
1767
|
},
|
|
1786
|
-
set: (a, l, d) =>
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
return a.setAttribute(
|
|
1791
|
-
f.snakeCase(l),
|
|
1792
|
-
d
|
|
1793
|
-
), !0;
|
|
1794
|
-
throw new Ne(e, f.snakeCase(l));
|
|
1795
|
-
}
|
|
1768
|
+
set: (a, l, d) => l in a && typeof a[l] != "function" ? Reflect.set(a, l, d) : (a.setAttribute(
|
|
1769
|
+
f.snakeCase(l),
|
|
1770
|
+
d
|
|
1771
|
+
), !0)
|
|
1796
1772
|
});
|
|
1797
1773
|
}
|
|
1798
1774
|
};
|
|
1799
1775
|
}
|
|
1800
|
-
var
|
|
1801
|
-
class
|
|
1776
|
+
var me, pe;
|
|
1777
|
+
class Ye extends (pe = Error, me = Symbol.toStringTag, pe) {
|
|
1802
1778
|
constructor(t, r) {
|
|
1803
1779
|
super(`[Luminix] Cannot create reducer '${t}' on '${r}' as it is a reserved property`);
|
|
1804
|
-
|
|
1780
|
+
p(this, me, "ReducerOverrideException");
|
|
1805
1781
|
}
|
|
1806
1782
|
}
|
|
1807
|
-
function
|
|
1783
|
+
function Se(n) {
|
|
1808
1784
|
return class extends n {
|
|
1809
1785
|
constructor(...t) {
|
|
1810
1786
|
super(...t);
|
|
1811
|
-
|
|
1787
|
+
p(this, "reducers", {});
|
|
1812
1788
|
return new Proxy(this, {
|
|
1813
1789
|
get(r, i, s) {
|
|
1814
1790
|
return typeof i == "symbol" || i in r ? Reflect.get(r, i, s) : (u, ...a) => {
|
|
1815
1791
|
const { [i]: l = c() } = r.reducers;
|
|
1816
|
-
return
|
|
1792
|
+
return Pe(u) ? R(u, (d) => l.sortBy("priority").reduce((m, w) => w.callback(m, ...a), d)) : l.sortBy("priority").reduce((d, m) => m.callback(d, ...a), u);
|
|
1817
1793
|
};
|
|
1818
1794
|
}
|
|
1819
1795
|
});
|
|
1820
1796
|
}
|
|
1821
1797
|
reducer(t, r, i = 10) {
|
|
1822
1798
|
if (t in this)
|
|
1823
|
-
throw new
|
|
1799
|
+
throw new Ye(t, this);
|
|
1824
1800
|
return this.reducers[t] || (this.reducers[t] = c()), this.reducers[t].push({ callback: r, priority: i }), () => this.removeReducer(t, r);
|
|
1825
1801
|
}
|
|
1826
1802
|
removeReducer(t, r) {
|
|
@@ -1841,24 +1817,24 @@ function Re(n) {
|
|
|
1841
1817
|
}
|
|
1842
1818
|
};
|
|
1843
1819
|
}
|
|
1844
|
-
var
|
|
1845
|
-
class
|
|
1820
|
+
var ge, ye;
|
|
1821
|
+
class W extends (ye = Error, ge = Symbol.toStringTag, ye) {
|
|
1846
1822
|
constructor(t) {
|
|
1847
1823
|
super(`[Luminix] Model "${t}" not found`);
|
|
1848
|
-
|
|
1824
|
+
p(this, ge, "ModelNotFoundException");
|
|
1849
1825
|
}
|
|
1850
1826
|
}
|
|
1851
|
-
var
|
|
1852
|
-
class B extends (
|
|
1827
|
+
var we, be;
|
|
1828
|
+
class B extends (be = TypeError, we = Symbol.toStringTag, be) {
|
|
1853
1829
|
constructor(t, r, i) {
|
|
1854
1830
|
super(`[Luminix] "${t}" expects a related model of type "${r}". Received "${i}" instead.`);
|
|
1855
|
-
|
|
1831
|
+
p(this, we, "ModelInvalidRelatedTypeException");
|
|
1856
1832
|
}
|
|
1857
1833
|
}
|
|
1858
|
-
class
|
|
1834
|
+
class ve extends j {
|
|
1859
1835
|
constructor(e, t, r, i = null) {
|
|
1860
|
-
if (!
|
|
1861
|
-
throw new
|
|
1836
|
+
if (!x(i) && i !== null)
|
|
1837
|
+
throw new M("BelongsTo.constructor()", "Model or null");
|
|
1862
1838
|
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1863
1839
|
}
|
|
1864
1840
|
isSingle() {
|
|
@@ -1875,12 +1851,12 @@ class Be extends j {
|
|
|
1875
1851
|
return this.query().first();
|
|
1876
1852
|
}
|
|
1877
1853
|
async associate(e) {
|
|
1878
|
-
if (!
|
|
1879
|
-
throw new
|
|
1854
|
+
if (!x(e))
|
|
1855
|
+
throw new M("BelongsTo.associate()");
|
|
1880
1856
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1881
1857
|
throw new B("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
|
|
1882
1858
|
if (!e.exists)
|
|
1883
|
-
throw new
|
|
1859
|
+
throw new Ae(this.getRelated().getSchemaName(), "save");
|
|
1884
1860
|
return this.parent.update({
|
|
1885
1861
|
[this.getForeignKey()]: e.getKey()
|
|
1886
1862
|
});
|
|
@@ -1891,10 +1867,10 @@ class Be extends j {
|
|
|
1891
1867
|
});
|
|
1892
1868
|
}
|
|
1893
1869
|
}
|
|
1894
|
-
class
|
|
1870
|
+
class Ne extends j {
|
|
1895
1871
|
constructor(e, t, r, i = null) {
|
|
1896
|
-
if (i !== null && !(i instanceof
|
|
1897
|
-
throw new
|
|
1872
|
+
if (i !== null && !(i instanceof Q && i.every(x)))
|
|
1873
|
+
throw new M("BelongsToMany.constructor()", "Collection<Model> or null");
|
|
1898
1874
|
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1899
1875
|
}
|
|
1900
1876
|
isSingle() {
|
|
@@ -2002,17 +1978,17 @@ class L extends j {
|
|
|
2002
1978
|
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
2003
1979
|
}
|
|
2004
1980
|
async saveQuietly(e) {
|
|
2005
|
-
if (!
|
|
2006
|
-
throw new
|
|
1981
|
+
if (!x(e))
|
|
1982
|
+
throw new M("HasOneOrMany.saveQuietly()");
|
|
2007
1983
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
2008
1984
|
throw new B("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
2009
1985
|
e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
|
|
2010
1986
|
}
|
|
2011
1987
|
}
|
|
2012
|
-
class
|
|
1988
|
+
class Ze extends L {
|
|
2013
1989
|
constructor(e, t, r, i = null) {
|
|
2014
|
-
if (!
|
|
2015
|
-
throw new
|
|
1990
|
+
if (!x(i) && i !== null)
|
|
1991
|
+
throw new M("HasOne.constructor()", "Model or null");
|
|
2016
1992
|
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2017
1993
|
}
|
|
2018
1994
|
isSingle() {
|
|
@@ -2028,10 +2004,10 @@ class et extends L {
|
|
|
2028
2004
|
await this.saveQuietly(e), this.items = e;
|
|
2029
2005
|
}
|
|
2030
2006
|
}
|
|
2031
|
-
class
|
|
2007
|
+
class ze extends L {
|
|
2032
2008
|
constructor(e, t, r, i = null) {
|
|
2033
|
-
if (i !== null && !(i instanceof
|
|
2034
|
-
throw new
|
|
2009
|
+
if (i !== null && !(i instanceof Q && i.every(x)))
|
|
2010
|
+
throw new M("HasMany.constructor()", "Collection<Model> or null");
|
|
2035
2011
|
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2036
2012
|
}
|
|
2037
2013
|
isSingle() {
|
|
@@ -2053,8 +2029,8 @@ class tt extends L {
|
|
|
2053
2029
|
return this.query().find(e);
|
|
2054
2030
|
}
|
|
2055
2031
|
async saveManyQuietly(e) {
|
|
2056
|
-
if (!Array.isArray(e) || !e.every(
|
|
2057
|
-
throw new
|
|
2032
|
+
if (!Array.isArray(e) || !e.every(x))
|
|
2033
|
+
throw new M("HasMany.saveManyQuietly()", "Model[]");
|
|
2058
2034
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
2059
2035
|
throw new B("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
2060
2036
|
await Promise.all(e.map((t) => (t.setAttribute(this.getForeignKey(), this.parent.getKey()), t.save())));
|
|
@@ -2068,7 +2044,7 @@ class tt extends L {
|
|
|
2068
2044
|
await this.saveQuietly(e), this.items === null ? this.items = await this.all() : this.items.push(e);
|
|
2069
2045
|
}
|
|
2070
2046
|
}
|
|
2071
|
-
class
|
|
2047
|
+
class Re extends L {
|
|
2072
2048
|
query() {
|
|
2073
2049
|
const e = this.getRelated().query();
|
|
2074
2050
|
e.once("success", (r) => {
|
|
@@ -2078,18 +2054,18 @@ class Ie extends L {
|
|
|
2078
2054
|
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;
|
|
2079
2055
|
}
|
|
2080
2056
|
async saveQuietly(e) {
|
|
2081
|
-
if (!
|
|
2082
|
-
throw new
|
|
2057
|
+
if (!x(e))
|
|
2058
|
+
throw new M("MorphOneOrMany.saveQuietly()");
|
|
2083
2059
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
2084
2060
|
throw new B("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
2085
2061
|
const t = this.guessInverseRelation();
|
|
2086
2062
|
e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
|
|
2087
2063
|
}
|
|
2088
2064
|
}
|
|
2089
|
-
class
|
|
2065
|
+
class Oe extends Re {
|
|
2090
2066
|
constructor(e, t, r, i = null) {
|
|
2091
|
-
if (i !== null && !(i instanceof
|
|
2092
|
-
throw new
|
|
2067
|
+
if (i !== null && !(i instanceof Q && i.every(x)))
|
|
2068
|
+
throw new M("MorphMany.constructor()", "Collection<Model> or null");
|
|
2093
2069
|
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2094
2070
|
}
|
|
2095
2071
|
isSingle() {
|
|
@@ -2111,8 +2087,8 @@ class rt extends Ie {
|
|
|
2111
2087
|
return this.query().find(e);
|
|
2112
2088
|
}
|
|
2113
2089
|
async saveManyQuietly(e) {
|
|
2114
|
-
if (!Array.isArray(e) || !e.every(
|
|
2115
|
-
throw new
|
|
2090
|
+
if (!Array.isArray(e) || !e.every(x))
|
|
2091
|
+
throw new M("MorphMany.saveManyQuietly()");
|
|
2116
2092
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
2117
2093
|
throw new B("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
2118
2094
|
await Promise.all(e.map((t) => (t.setAttribute(this.getName() + "_id", this.parent.getKey()), t.setAttribute(this.getName() + "_type", this.parent.getType()), t.save())));
|
|
@@ -2126,10 +2102,10 @@ class rt extends Ie {
|
|
|
2126
2102
|
this.items ? this.items.splice(0, this.items.count(), ...t) : this.items = t;
|
|
2127
2103
|
}
|
|
2128
2104
|
}
|
|
2129
|
-
class
|
|
2105
|
+
class et extends Re {
|
|
2130
2106
|
constructor(e, t, r, i = null) {
|
|
2131
|
-
if (super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !
|
|
2132
|
-
throw new
|
|
2107
|
+
if (super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !x(i))
|
|
2108
|
+
throw new M("MorphOne.constructor()", "Model or null");
|
|
2133
2109
|
}
|
|
2134
2110
|
isSingle() {
|
|
2135
2111
|
return !0;
|
|
@@ -2144,7 +2120,7 @@ class st extends Ie {
|
|
|
2144
2120
|
await this.saveQuietly(e), this.items = e;
|
|
2145
2121
|
}
|
|
2146
2122
|
}
|
|
2147
|
-
class
|
|
2123
|
+
class tt extends ve {
|
|
2148
2124
|
getRelated() {
|
|
2149
2125
|
return this.facades.model.make(
|
|
2150
2126
|
this.parent.getAttribute(this.getName() + "_type")
|
|
@@ -2159,8 +2135,8 @@ class it extends Be {
|
|
|
2159
2135
|
// return super.query();
|
|
2160
2136
|
// }
|
|
2161
2137
|
async associate(e) {
|
|
2162
|
-
if (!
|
|
2163
|
-
throw new
|
|
2138
|
+
if (!x(e))
|
|
2139
|
+
throw new M("MorphTo.associate()");
|
|
2164
2140
|
return e.exists || await e.save(), this.parent.update({
|
|
2165
2141
|
[this.getName() + "_id"]: e.getKey(),
|
|
2166
2142
|
[this.getName() + "_type"]: e.getType()
|
|
@@ -2173,7 +2149,7 @@ class it extends Be {
|
|
|
2173
2149
|
});
|
|
2174
2150
|
}
|
|
2175
2151
|
}
|
|
2176
|
-
class
|
|
2152
|
+
class rt extends Ne {
|
|
2177
2153
|
constructor(e, t, r, i = null) {
|
|
2178
2154
|
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2179
2155
|
}
|
|
@@ -2182,43 +2158,43 @@ class nt extends qe {
|
|
|
2182
2158
|
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;
|
|
2183
2159
|
}
|
|
2184
2160
|
}
|
|
2185
|
-
var
|
|
2186
|
-
|
|
2187
|
-
class
|
|
2161
|
+
var Ee;
|
|
2162
|
+
Ee = Symbol.toStringTag;
|
|
2163
|
+
class st {
|
|
2188
2164
|
constructor(e) {
|
|
2189
|
-
|
|
2190
|
-
|
|
2165
|
+
p(this, "_models", {});
|
|
2166
|
+
p(this, Ee, "ModelFacade");
|
|
2191
2167
|
this._schema = e;
|
|
2192
2168
|
}
|
|
2193
2169
|
boot(e) {
|
|
2194
2170
|
this._schema && (Object.keys(this._schema).forEach((t) => {
|
|
2195
2171
|
const r = this[`model${f.upperFirst(f.camelCase(t))}`];
|
|
2196
2172
|
if (typeof this.model != "function" || typeof r != "function")
|
|
2197
|
-
throw new
|
|
2173
|
+
throw new T("ModelFacade");
|
|
2198
2174
|
const i = this.model(
|
|
2199
|
-
|
|
2175
|
+
Ve(e, t),
|
|
2200
2176
|
t
|
|
2201
2177
|
), s = r(i);
|
|
2202
|
-
this._models[t] =
|
|
2178
|
+
this._models[t] = Xe(e.make(), t, s);
|
|
2203
2179
|
}), this.reducer("relationMap", () => ({
|
|
2204
|
-
BelongsTo:
|
|
2205
|
-
BelongsToMany:
|
|
2206
|
-
HasOne:
|
|
2207
|
-
HasMany:
|
|
2208
|
-
MorphMany:
|
|
2209
|
-
MorphOne:
|
|
2210
|
-
MorphTo:
|
|
2211
|
-
MorphToMany:
|
|
2180
|
+
BelongsTo: ve,
|
|
2181
|
+
BelongsToMany: Ne,
|
|
2182
|
+
HasOne: Ze,
|
|
2183
|
+
HasMany: ze,
|
|
2184
|
+
MorphMany: Oe,
|
|
2185
|
+
MorphOne: et,
|
|
2186
|
+
MorphTo: tt,
|
|
2187
|
+
MorphToMany: rt
|
|
2212
2188
|
}), 0));
|
|
2213
2189
|
}
|
|
2214
2190
|
schema(e) {
|
|
2215
2191
|
if (!this._schema || e && !this._schema[e])
|
|
2216
|
-
throw new
|
|
2192
|
+
throw new W(e || "undefined");
|
|
2217
2193
|
return e ? this._schema[e] : this._schema;
|
|
2218
2194
|
}
|
|
2219
2195
|
make(e) {
|
|
2220
2196
|
if (e && !this._models[e])
|
|
2221
|
-
throw new
|
|
2197
|
+
throw new W(e);
|
|
2222
2198
|
return e ? this._models[e] : this._models;
|
|
2223
2199
|
}
|
|
2224
2200
|
toString() {
|
|
@@ -2226,68 +2202,68 @@ class ot {
|
|
|
2226
2202
|
}
|
|
2227
2203
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2228
2204
|
on(e, t) {
|
|
2229
|
-
throw new
|
|
2205
|
+
throw new E();
|
|
2230
2206
|
}
|
|
2231
2207
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2232
2208
|
once(e, t) {
|
|
2233
|
-
throw new
|
|
2209
|
+
throw new E();
|
|
2234
2210
|
}
|
|
2235
2211
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2236
2212
|
emit(e, t) {
|
|
2237
|
-
throw new
|
|
2213
|
+
throw new E();
|
|
2238
2214
|
}
|
|
2239
2215
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2240
2216
|
reducer(e, t, r) {
|
|
2241
|
-
throw new
|
|
2217
|
+
throw new E();
|
|
2242
2218
|
}
|
|
2243
2219
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2244
2220
|
removeReducer(e) {
|
|
2245
|
-
throw new
|
|
2221
|
+
throw new E();
|
|
2246
2222
|
}
|
|
2247
2223
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2248
2224
|
getReducer(e) {
|
|
2249
|
-
throw new
|
|
2225
|
+
throw new E();
|
|
2250
2226
|
}
|
|
2251
2227
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2252
2228
|
hasReducer(e) {
|
|
2253
|
-
throw new
|
|
2229
|
+
throw new E();
|
|
2254
2230
|
}
|
|
2255
2231
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2256
2232
|
clearReducer(e) {
|
|
2257
|
-
throw new
|
|
2233
|
+
throw new E();
|
|
2258
2234
|
}
|
|
2259
2235
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2260
2236
|
flushReducers() {
|
|
2261
|
-
throw new
|
|
2237
|
+
throw new E();
|
|
2262
2238
|
}
|
|
2263
2239
|
}
|
|
2264
|
-
const
|
|
2265
|
-
var
|
|
2266
|
-
class
|
|
2240
|
+
const it = A(Se(st));
|
|
2241
|
+
var xe, Me;
|
|
2242
|
+
class nt extends (Me = Error, xe = Symbol.toStringTag, Me) {
|
|
2267
2243
|
constructor() {
|
|
2268
2244
|
super("[Luminix] Embed element not found. Make sure to include the `@luminixEmbed()` directive in your Blade template.");
|
|
2269
|
-
|
|
2245
|
+
p(this, xe, "NoEmbedException");
|
|
2270
2246
|
}
|
|
2271
2247
|
}
|
|
2272
|
-
const
|
|
2248
|
+
const Be = (n, e = "data") => {
|
|
2273
2249
|
if (!document.querySelector("#luminix-embed"))
|
|
2274
|
-
throw new
|
|
2250
|
+
throw new nt();
|
|
2275
2251
|
const t = document.getElementById(`luminix-${e}::` + n);
|
|
2276
2252
|
return t ? t.dataset.json && t.dataset.value ? JSON.parse(t.dataset.value) : t.dataset.value : null;
|
|
2277
|
-
},
|
|
2278
|
-
let
|
|
2253
|
+
}, G = A(S), ot = (n) => ke(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;
|
|
2254
|
+
let ht = class {
|
|
2279
2255
|
constructor() {
|
|
2280
|
-
|
|
2256
|
+
p(this, "bags");
|
|
2281
2257
|
const e = {};
|
|
2282
2258
|
document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((r) => {
|
|
2283
2259
|
const s = r.id.replace("luminix-error::", "");
|
|
2284
|
-
e[s] =
|
|
2260
|
+
e[s] = Be(s, "error");
|
|
2285
2261
|
}), this.bags = {
|
|
2286
|
-
default: new
|
|
2262
|
+
default: new G(e)
|
|
2287
2263
|
};
|
|
2288
2264
|
}
|
|
2289
2265
|
bag(e = "default") {
|
|
2290
|
-
return this.bags[e] || (this.bags[e] = new
|
|
2266
|
+
return this.bags[e] || (this.bags[e] = new G({})), this.bags[e];
|
|
2291
2267
|
}
|
|
2292
2268
|
add(e, t, r = "default") {
|
|
2293
2269
|
this.bag(r).set(e, t);
|
|
@@ -2305,14 +2281,14 @@ let lt = class {
|
|
|
2305
2281
|
this.bag(e).set(".", {});
|
|
2306
2282
|
}
|
|
2307
2283
|
};
|
|
2308
|
-
var
|
|
2309
|
-
class
|
|
2284
|
+
var _e, Te;
|
|
2285
|
+
class ut extends (Te = Error, _e = Symbol.toStringTag, Te) {
|
|
2310
2286
|
constructor(t) {
|
|
2311
2287
|
super(`[Luminix] Route "${t}" not found`);
|
|
2312
|
-
|
|
2288
|
+
p(this, _e, "RouteNotFoundException");
|
|
2313
2289
|
}
|
|
2314
2290
|
}
|
|
2315
|
-
class
|
|
2291
|
+
class at {
|
|
2316
2292
|
constructor(e, t, r = "") {
|
|
2317
2293
|
this.routes = e, this.error = t, this.appUrl = r;
|
|
2318
2294
|
}
|
|
@@ -2331,23 +2307,23 @@ class dt {
|
|
|
2331
2307
|
}
|
|
2332
2308
|
get(e) {
|
|
2333
2309
|
if (!this.exists(e))
|
|
2334
|
-
throw new
|
|
2310
|
+
throw new ut(e);
|
|
2335
2311
|
return f.get(this.routes, e);
|
|
2336
2312
|
}
|
|
2337
2313
|
url(e) {
|
|
2338
2314
|
const [t, r] = this.extractGenerator(e), i = this.get(t)[0].replace(/^\/|\/$/g, ""), s = /{([^}]+)}/g;
|
|
2339
2315
|
if (r === !1) {
|
|
2340
2316
|
if (typeof this.replaceRouteParams != "function")
|
|
2341
|
-
throw new
|
|
2317
|
+
throw new T("RouteFacade");
|
|
2342
2318
|
return this.appUrl + this.replaceRouteParams(`/${i}`);
|
|
2343
2319
|
}
|
|
2344
|
-
const u = i.match(s), a = u ? u.map((
|
|
2320
|
+
const u = i.match(s), a = u ? u.map((b) => b.slice(1, -1)) : [], l = Object.keys(r), d = a.filter((b) => !l.includes(b)), m = l.filter((b) => !a.includes(b));
|
|
2345
2321
|
if (d.length > 0)
|
|
2346
2322
|
throw new TypeError(`Missing values for parameter(s): ${d.join(", ")}`);
|
|
2347
|
-
if (
|
|
2348
|
-
throw new TypeError(`Unexpected parameters: ${
|
|
2349
|
-
const
|
|
2350
|
-
return this.appUrl + `/${
|
|
2323
|
+
if (m.length > 0)
|
|
2324
|
+
throw new TypeError(`Unexpected parameters: ${m.join(", ")}`);
|
|
2325
|
+
const w = a.reduce((b, g) => b.replace(`{${g}}`, `${r[g]}`), i);
|
|
2326
|
+
return this.appUrl + `/${w}`;
|
|
2351
2327
|
}
|
|
2352
2328
|
methods(e) {
|
|
2353
2329
|
const [t] = this.extractGenerator(e);
|
|
@@ -2358,15 +2334,15 @@ class dt {
|
|
|
2358
2334
|
}
|
|
2359
2335
|
async call(e, t = {}) {
|
|
2360
2336
|
if (typeof this.axiosOptions != "function" || typeof this.axiosError != "function")
|
|
2361
|
-
throw new
|
|
2362
|
-
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", ...
|
|
2337
|
+
throw new T("RouteFacade");
|
|
2338
|
+
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", ...m } = a, { data: w, ...b } = m;
|
|
2363
2339
|
this.error.clear(d);
|
|
2364
2340
|
try {
|
|
2365
|
-
return ["get", "delete"].includes(l) ? await K[l](u,
|
|
2341
|
+
return ["get", "delete"].includes(l) ? await K[l](u, m) : await K[l](u, w, b);
|
|
2366
2342
|
} catch (g) {
|
|
2367
|
-
if (
|
|
2368
|
-
const { errors:
|
|
2369
|
-
this.error.set(Object.entries(
|
|
2343
|
+
if (ot(g)) {
|
|
2344
|
+
const { errors: qe } = g.response.data;
|
|
2345
|
+
this.error.set(Object.entries(qe).reduce((C, [Ie, Ke]) => (C[Ie] = Ke.join(" "), C), {}));
|
|
2370
2346
|
} else K.isAxiosError(g) && this.error.set(
|
|
2371
2347
|
this.axiosError({ axios: g.message }, {
|
|
2372
2348
|
error: g,
|
|
@@ -2383,12 +2359,12 @@ class dt {
|
|
|
2383
2359
|
return "route";
|
|
2384
2360
|
}
|
|
2385
2361
|
}
|
|
2386
|
-
const
|
|
2387
|
-
class
|
|
2362
|
+
const lt = Se(at);
|
|
2363
|
+
class ct {
|
|
2388
2364
|
constructor() {
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2365
|
+
p(this, "facades", {});
|
|
2366
|
+
p(this, "booted", !1);
|
|
2367
|
+
p(this, "_plugins", []);
|
|
2392
2368
|
}
|
|
2393
2369
|
make(e = void 0) {
|
|
2394
2370
|
if (!e)
|
|
@@ -2406,7 +2382,7 @@ class pt {
|
|
|
2406
2382
|
return this._plugins;
|
|
2407
2383
|
}
|
|
2408
2384
|
async boot(e = {}) {
|
|
2409
|
-
var a, l, d,
|
|
2385
|
+
var a, l, d, m, w, b;
|
|
2410
2386
|
if (this.booted)
|
|
2411
2387
|
throw new window.Error("[Luminix] App already booted");
|
|
2412
2388
|
this.booted = !0, (a = e.app) != null && a.debug && console.log("[Luminix] Booting started..."), this.emit("init", {
|
|
@@ -2417,21 +2393,21 @@ class pt {
|
|
|
2417
2393
|
const t = (((l = e.app) == null ? void 0 : l.url) ?? "") + (((d = e.app) == null ? void 0 : d.bootUrl) ?? "/luminix-api/init");
|
|
2418
2394
|
if (document.getElementById("luminix-data::config")) {
|
|
2419
2395
|
if (document.getElementById("luminix-data::config")) {
|
|
2420
|
-
const g =
|
|
2396
|
+
const g = Be("config");
|
|
2421
2397
|
g && typeof g == "object" && f.merge(e, g);
|
|
2422
2398
|
}
|
|
2423
2399
|
} else try {
|
|
2424
2400
|
const { data: g } = await K.get(t);
|
|
2425
2401
|
g && typeof g == "object" && f.merge(e, g);
|
|
2426
2402
|
} catch (g) {
|
|
2427
|
-
(
|
|
2403
|
+
(m = e.app) != null && m.debug && console.error(g);
|
|
2428
2404
|
}
|
|
2429
|
-
this.bind("log", new
|
|
2405
|
+
this.bind("log", new Ce(!!((w = e.app) != null && w.debug)));
|
|
2430
2406
|
const { log: r } = this.facades, {
|
|
2431
2407
|
manifest: { routes: i = {}, models: s = {} } = {},
|
|
2432
2408
|
...u
|
|
2433
2409
|
} = e;
|
|
2434
|
-
this.bind("config", new S(u)), this.facades.config.has("auth.user") || this.facades.config.set("auth.user", null), this.facades.config.lock("auth.user"), this.bind("error", new
|
|
2410
|
+
this.bind("config", new S(u)), this.facades.config.has("auth.user") || this.facades.config.set("auth.user", null), this.facades.config.lock("auth.user"), this.bind("error", new ht()), this.bind("route", new lt(i, this.facades.error, ((b = e.app) == null ? void 0 : b.url) ?? "")), this.bind("model", new it(s)), this.bind("auth", new Le(this)), this.emit("booting");
|
|
2435
2411
|
for (const g of Object.values(this.facades))
|
|
2436
2412
|
typeof g == "object" && g !== null && "boot" in g && typeof g.boot == "function" && g.boot(this);
|
|
2437
2413
|
for (const g of this._plugins)
|
|
@@ -2445,6 +2421,23 @@ class pt {
|
|
|
2445
2421
|
}
|
|
2446
2422
|
}), this.emit("booted"), this.facades;
|
|
2447
2423
|
}
|
|
2424
|
+
environment(...e) {
|
|
2425
|
+
return e.length > 0 ? e.includes(this.facades.config.get("app.env", "production")) : this.facades.config.get("app.env", "production");
|
|
2426
|
+
}
|
|
2427
|
+
getPlugin(e) {
|
|
2428
|
+
for (const t of this._plugins)
|
|
2429
|
+
if (t instanceof e)
|
|
2430
|
+
return t;
|
|
2431
|
+
}
|
|
2432
|
+
hasDebugModeEnabled() {
|
|
2433
|
+
return this.facades.config.get("app.debug", !1);
|
|
2434
|
+
}
|
|
2435
|
+
isLocal() {
|
|
2436
|
+
return this.facades.config.get("app.env", "production") === "local";
|
|
2437
|
+
}
|
|
2438
|
+
isProduction() {
|
|
2439
|
+
return this.facades.config.get("app.env", "production") === "production";
|
|
2440
|
+
}
|
|
2448
2441
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2449
2442
|
on(e, t) {
|
|
2450
2443
|
throw new window.Error("Method not implemented.");
|
|
@@ -2458,49 +2451,54 @@ class pt {
|
|
|
2458
2451
|
throw new window.Error("Method not implemented.");
|
|
2459
2452
|
}
|
|
2460
2453
|
}
|
|
2461
|
-
const
|
|
2462
|
-
let
|
|
2463
|
-
function
|
|
2464
|
-
if (
|
|
2454
|
+
const dt = A(ct);
|
|
2455
|
+
let y;
|
|
2456
|
+
function v(n = void 0) {
|
|
2457
|
+
if (y || (y = new dt()), typeof n != "string")
|
|
2465
2458
|
return {
|
|
2466
|
-
boot:
|
|
2467
|
-
make:
|
|
2468
|
-
plugins:
|
|
2469
|
-
on:
|
|
2459
|
+
boot: y.boot.bind(y),
|
|
2460
|
+
make: y.make.bind(y),
|
|
2461
|
+
plugins: y.plugins.bind(y),
|
|
2462
|
+
on: y.once.bind(y),
|
|
2463
|
+
environment: y.environment.bind(y),
|
|
2464
|
+
getPlugin: y.getPlugin.bind(y),
|
|
2465
|
+
hasDebugModeEnabled: y.hasDebugModeEnabled.bind(y),
|
|
2466
|
+
isLocal: y.isLocal.bind(y),
|
|
2467
|
+
isProduction: y.isProduction.bind(y)
|
|
2470
2468
|
};
|
|
2471
|
-
if (!
|
|
2472
|
-
throw new
|
|
2473
|
-
return
|
|
2469
|
+
if (!y.has(n))
|
|
2470
|
+
throw new Qe(n);
|
|
2471
|
+
return y.make(n);
|
|
2474
2472
|
}
|
|
2475
|
-
function
|
|
2476
|
-
return
|
|
2473
|
+
function bt() {
|
|
2474
|
+
return v("auth");
|
|
2477
2475
|
}
|
|
2478
|
-
function
|
|
2476
|
+
function Et(n) {
|
|
2479
2477
|
return c(n);
|
|
2480
2478
|
}
|
|
2481
|
-
function
|
|
2482
|
-
const t =
|
|
2479
|
+
function xt(n, e) {
|
|
2480
|
+
const t = v("config");
|
|
2483
2481
|
return typeof n > "u" ? t : t.get(n, e);
|
|
2484
2482
|
}
|
|
2485
|
-
function
|
|
2486
|
-
return n ?
|
|
2483
|
+
function Mt(n, e = "default") {
|
|
2484
|
+
return n ? v().make("error").get(n, e) : v().make("error");
|
|
2487
2485
|
}
|
|
2488
|
-
function
|
|
2489
|
-
const e =
|
|
2486
|
+
function _t(...n) {
|
|
2487
|
+
const e = v("log");
|
|
2490
2488
|
return n.length ? e.debug(...n) : e;
|
|
2491
2489
|
}
|
|
2492
|
-
function
|
|
2493
|
-
const e =
|
|
2490
|
+
function Tt(n) {
|
|
2491
|
+
const e = v("model");
|
|
2494
2492
|
return n ? e.make(n) : e;
|
|
2495
2493
|
}
|
|
2496
|
-
function
|
|
2497
|
-
const t =
|
|
2494
|
+
function $t(n, e = !1) {
|
|
2495
|
+
const t = v("route");
|
|
2498
2496
|
return n ? e ? t.url([n, e]) : t.url(n) : t;
|
|
2499
2497
|
}
|
|
2500
|
-
class
|
|
2498
|
+
class At {
|
|
2501
2499
|
constructor() {
|
|
2502
|
-
|
|
2503
|
-
|
|
2500
|
+
p(this, "name");
|
|
2501
|
+
p(this, "version");
|
|
2504
2502
|
}
|
|
2505
2503
|
register(e) {
|
|
2506
2504
|
}
|
|
@@ -2509,18 +2507,18 @@ class vt {
|
|
|
2509
2507
|
}
|
|
2510
2508
|
export {
|
|
2511
2509
|
A as HasEvents,
|
|
2512
|
-
|
|
2510
|
+
At as Plugin,
|
|
2513
2511
|
S as PropertyBag,
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2512
|
+
Se as Reducible,
|
|
2513
|
+
v as app,
|
|
2514
|
+
bt as auth,
|
|
2515
|
+
Et as collect,
|
|
2516
|
+
xt as config,
|
|
2517
|
+
Mt as error,
|
|
2520
2518
|
$ as isCollection,
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2519
|
+
x as isModel,
|
|
2520
|
+
ot as isValidationError,
|
|
2521
|
+
_t as log,
|
|
2522
|
+
Tt as model,
|
|
2523
|
+
$t as route
|
|
2526
2524
|
};
|