@luminix/core 0.4.4 → 0.4.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
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { reader as
|
|
5
|
-
class
|
|
1
|
+
var ce = Object.defineProperty;
|
|
2
|
+
var de = (o, e, t) => e in o ? ce(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var g = (o, e, t) => de(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { reader as pe, PropertyBag as _, EventSource as A, Collection as b, Query as S, Obj as p, Str as y, Reducible as re, isValidationError as ge, Macroable as ne, Client as ye, ServiceProvider as me, MakeFacade as M, Application as fe, Response as we } from "@luminix/support";
|
|
5
|
+
class ve {
|
|
6
6
|
constructor(e, t, r) {
|
|
7
|
-
|
|
7
|
+
g(this, "_user");
|
|
8
8
|
this.config = e, this.model = t, this.route = r;
|
|
9
9
|
}
|
|
10
10
|
attempt(e, t = !1, r) {
|
|
@@ -51,13 +51,13 @@ class xe {
|
|
|
51
51
|
return ((e = this.user()) == null ? void 0 : e.getKey()) || null;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
class
|
|
54
|
+
class be {
|
|
55
55
|
constructor() {
|
|
56
|
-
|
|
56
|
+
g(this, "bags");
|
|
57
57
|
const e = {};
|
|
58
58
|
document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((r) => {
|
|
59
59
|
const l = r.id.replace("luminix-error::", "");
|
|
60
|
-
e[l] =
|
|
60
|
+
e[l] = pe(l, "error");
|
|
61
61
|
}), this.bags = {
|
|
62
62
|
default: new _(e)
|
|
63
63
|
};
|
|
@@ -81,7 +81,7 @@ class Me {
|
|
|
81
81
|
this.bag(e).set(".", {});
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
class
|
|
84
|
+
class xe {
|
|
85
85
|
constructor(e) {
|
|
86
86
|
this._debug = e;
|
|
87
87
|
}
|
|
@@ -111,16 +111,16 @@ class Ee {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
var j, O;
|
|
114
|
-
class
|
|
114
|
+
class Me extends (O = Error, j = Symbol.toStringTag, O) {
|
|
115
115
|
constructor(t) {
|
|
116
116
|
super(`[Luminix] Model "${t}" does not have a primary key`);
|
|
117
|
-
|
|
117
|
+
g(this, j, "ModelWithoutPrimaryKeyException");
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
class
|
|
120
|
+
class Ee extends A {
|
|
121
121
|
constructor(t, r, i = {}) {
|
|
122
122
|
super();
|
|
123
|
-
|
|
123
|
+
g(this, "bag");
|
|
124
124
|
this.services = t, this.abstract = r, this.bag = new _(i), this.bag.on("change", () => {
|
|
125
125
|
this.emit("change", {
|
|
126
126
|
data: this.bag,
|
|
@@ -222,16 +222,16 @@ class Se extends N {
|
|
|
222
222
|
...l.json(),
|
|
223
223
|
data: c,
|
|
224
224
|
links: {
|
|
225
|
-
first: `${s}?${
|
|
226
|
-
last: `${s}?${
|
|
227
|
-
next: l.json("links").next && `${s}?${
|
|
228
|
-
prev: l.json("links").prev && `${s}?${
|
|
225
|
+
first: `${s}?${S.merge(u, l.json("links").first).toString()}`,
|
|
226
|
+
last: `${s}?${S.merge(u, l.json("links").last).toString()}`,
|
|
227
|
+
next: l.json("links").next && `${s}?${S.merge(u, l.json("links").next ?? "").toString()}`,
|
|
228
|
+
prev: l.json("links").prev && `${s}?${S.merge(u, l.json("links").prev ?? "").toString()}`
|
|
229
229
|
},
|
|
230
230
|
meta: {
|
|
231
231
|
...l.json("meta"),
|
|
232
232
|
links: l.json("meta").links.map((n) => ({
|
|
233
233
|
...n,
|
|
234
|
-
url: n.url && `${s}?${
|
|
234
|
+
url: n.url && `${s}?${S.merge(u, n.url).toString()}`
|
|
235
235
|
}))
|
|
236
236
|
}
|
|
237
237
|
};
|
|
@@ -266,7 +266,7 @@ class Se extends N {
|
|
|
266
266
|
async find(t) {
|
|
267
267
|
const r = this.services.model.schema(this.abstract).primaryKey;
|
|
268
268
|
if (!r)
|
|
269
|
-
throw new
|
|
269
|
+
throw new Me(this.abstract);
|
|
270
270
|
const i = await this.where(r, t).limit(1).exec();
|
|
271
271
|
return this.emit("success", {
|
|
272
272
|
response: i,
|
|
@@ -297,27 +297,27 @@ var B, C;
|
|
|
297
297
|
class w extends (C = TypeError, B = Symbol.toStringTag, C) {
|
|
298
298
|
constructor(t, r = "Model") {
|
|
299
299
|
super(`[Luminix] "${t}" expects ${r}`);
|
|
300
|
-
|
|
300
|
+
g(this, B, "NotModelException");
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
var I, P;
|
|
304
|
-
class
|
|
304
|
+
class $e extends (P = Error, I = Symbol.toStringTag, P) {
|
|
305
305
|
constructor(t, r, i, l) {
|
|
306
306
|
super(`[Luminix] Could not determine inverse relation for "${r}" in model "${t}". Please specify a relation in model "${i}" of type ${l} that points back to "${t}".`);
|
|
307
|
-
|
|
307
|
+
g(this, I, "NoInverseRelationException");
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
var Q, L;
|
|
311
|
-
class
|
|
311
|
+
class Te extends (L = Error, Q = Symbol.toStringTag, L) {
|
|
312
312
|
constructor(t) {
|
|
313
313
|
super(`[Luminix] Relation "${t}" is not supported`);
|
|
314
|
-
|
|
314
|
+
g(this, Q, "UnsupportedRelationException");
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
|
-
class
|
|
317
|
+
class k {
|
|
318
318
|
constructor(e, t, r, i = null) {
|
|
319
|
-
|
|
320
|
-
if (this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !
|
|
319
|
+
g(this, "unsubscribeQuery", null);
|
|
320
|
+
if (this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !p.isModel(i) && !(i instanceof b && i.every(p.isModel)))
|
|
321
321
|
throw new w("Relation.constructor()", "Model, Collection<Model> or null");
|
|
322
322
|
}
|
|
323
323
|
make(e) {
|
|
@@ -349,18 +349,18 @@ class A {
|
|
|
349
349
|
MorphToMany: ["MorphToMany"]
|
|
350
350
|
}, this.parent, t, this.getRelated());
|
|
351
351
|
if (!(t in r))
|
|
352
|
-
throw new
|
|
352
|
+
throw new Te(t);
|
|
353
353
|
for (const i in e) {
|
|
354
354
|
const l = e[i];
|
|
355
355
|
if ((l.model === this.parent.getType() || ["MorphOne", "MorphMany"].includes(t)) && r[t].includes(l.type))
|
|
356
356
|
return i;
|
|
357
357
|
}
|
|
358
|
-
throw new
|
|
358
|
+
throw new $e(this.parent.getType(), t, this.getRelated().getSchemaName(), r[t].join(" or "));
|
|
359
359
|
}
|
|
360
360
|
set(e) {
|
|
361
|
-
if (e !== null && !
|
|
361
|
+
if (e !== null && !p.isModel(e) && !(e instanceof b && e.every(p.isModel)))
|
|
362
362
|
throw new w("Relation.set()", "Model, Collection<Model> or null");
|
|
363
|
-
!this.items ||
|
|
363
|
+
!this.items || p.isModel(this.items) ? this.items = e : e instanceof b && this.items.splice(0, this.items.count(), ...e);
|
|
364
364
|
}
|
|
365
365
|
getForeignKey() {
|
|
366
366
|
return this.meta.foreignKey;
|
|
@@ -390,7 +390,7 @@ class A {
|
|
|
390
390
|
return this.items;
|
|
391
391
|
}
|
|
392
392
|
isSingle() {
|
|
393
|
-
return
|
|
393
|
+
return p.isModel(this.items);
|
|
394
394
|
}
|
|
395
395
|
isMultiple() {
|
|
396
396
|
return this.items instanceof b;
|
|
@@ -442,42 +442,35 @@ var D, H;
|
|
|
442
442
|
class E extends (H = Error, D = Symbol.toStringTag, H) {
|
|
443
443
|
constructor(t) {
|
|
444
444
|
super(`[Luminix] Expected ${t} to be reducible.`);
|
|
445
|
-
|
|
445
|
+
g(this, D, "NotReducibleException");
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
|
-
var J,
|
|
449
|
-
class
|
|
448
|
+
var J, U;
|
|
449
|
+
class Se extends (U = Error, J = Symbol.toStringTag, U) {
|
|
450
450
|
constructor() {
|
|
451
451
|
super("[Luminix] Method not implemented.");
|
|
452
|
-
|
|
452
|
+
g(this, J, "MethodNotImplementedException");
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
|
-
var
|
|
456
|
-
class
|
|
455
|
+
var F, W;
|
|
456
|
+
class oe extends (W = Error, F = Symbol.toStringTag, W) {
|
|
457
457
|
constructor(t, r) {
|
|
458
458
|
super(`[Luminix] Model "${t}" must be persisted before calling "${r}"`);
|
|
459
|
-
|
|
459
|
+
g(this, F, "ModelNotPersistedException");
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
|
-
|
|
463
|
-
class Ae extends (V = Error, G = Symbol.toStringTag, V) {
|
|
464
|
-
constructor(t, r) {
|
|
465
|
-
super(`[Luminix] Attribute "${r}" not found in model "${t}". Check if your database is up to date.`);
|
|
466
|
-
p(this, G, "AttributeNotFoundException");
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
function Ne(o, e, t, r, i) {
|
|
462
|
+
function _e(o, e, t, r, i) {
|
|
470
463
|
var l, m, c;
|
|
471
|
-
return c = class extends (m =
|
|
464
|
+
return c = class extends (m = A, l = Symbol.toStringTag, m) {
|
|
472
465
|
constructor(s = {}) {
|
|
473
466
|
super();
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
467
|
+
g(this, "_attributes", new _({}));
|
|
468
|
+
g(this, "_original", {});
|
|
469
|
+
g(this, "_relations", {});
|
|
470
|
+
g(this, "_changedKeys", []);
|
|
471
|
+
g(this, "exists", !1);
|
|
472
|
+
g(this, "wasRecentlyCreated", !1);
|
|
473
|
+
g(this, l, y.studly(i));
|
|
481
474
|
this.makeRelations(), this.makeAttributes(s);
|
|
482
475
|
}
|
|
483
476
|
cast(s, n) {
|
|
@@ -492,7 +485,7 @@ function Ne(o, e, t, r, i) {
|
|
|
492
485
|
return;
|
|
493
486
|
const n = t.getRelationConstructors(i);
|
|
494
487
|
Object.entries(s).forEach(([a, h]) => {
|
|
495
|
-
const { type: d } = h, v = d in n ? n[d] :
|
|
488
|
+
const { type: d } = h, v = d in n ? n[d] : k;
|
|
496
489
|
this._relations[a] = new v(
|
|
497
490
|
{ model: t, route: r },
|
|
498
491
|
{ name: a, ...h },
|
|
@@ -502,11 +495,9 @@ function Ne(o, e, t, r, i) {
|
|
|
502
495
|
});
|
|
503
496
|
}
|
|
504
497
|
makeAttributes(s) {
|
|
505
|
-
const { relations: n, attributes: a } = t.schema(i), h = Object.keys(n || {}), d =
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
throw new Ae(i, f);
|
|
509
|
-
return !(f in d) && S.nullable;
|
|
498
|
+
const { relations: n, attributes: a } = t.schema(i), h = Object.keys(n || {}), d = p.omit(s, ...h), v = (f) => {
|
|
499
|
+
const T = a.find((le) => le.name == f);
|
|
500
|
+
return T ? !(f in d) && T.nullable : !1;
|
|
510
501
|
};
|
|
511
502
|
if (this.fillable.filter(v).forEach((f) => {
|
|
512
503
|
d[f] = null;
|
|
@@ -600,8 +591,8 @@ function Ne(o, e, t, r, i) {
|
|
|
600
591
|
});
|
|
601
592
|
}
|
|
602
593
|
updateChangedKeys(s) {
|
|
603
|
-
const n = (h, d) => typeof h == "object" && h !== null ?
|
|
604
|
-
!this._changedKeys.includes(a) && !n(
|
|
594
|
+
const n = (h, d) => typeof h == "object" && h !== null ? p.isEqual(h, d) : h == d, a = s.includes(".") || s.includes("[") ? s.split(/[.[]/)[0] : s;
|
|
595
|
+
!this._changedKeys.includes(a) && !n(p.get(this._original, a), this._attributes.get(a)) ? this._changedKeys.push(a) : this._changedKeys.includes(a) && n(p.get(this._original, a), this._attributes.get(a)) && this._changedKeys.splice(this._changedKeys.indexOf(a), 1);
|
|
605
596
|
}
|
|
606
597
|
validateJsonObject(s) {
|
|
607
598
|
return typeof s != "object" || s === null ? !1 : Object.entries(s).every(([, n]) => ["boolean", "number", "string"].includes(typeof n) || n === null || this.validateJsonObject(n) || Array.isArray(n) && n.every((a) => this.validateJsonObject(a)));
|
|
@@ -676,7 +667,7 @@ function Ne(o, e, t, r, i) {
|
|
|
676
667
|
return this.primaryKey;
|
|
677
668
|
}
|
|
678
669
|
fill(s) {
|
|
679
|
-
const n =
|
|
670
|
+
const n = p.pick(s, ...this.fillable), a = Object.entries(n).reduce((h, [d, v]) => {
|
|
680
671
|
const f = t[`model${y.studly(i)}Set${y.studly(d)}Attribute`];
|
|
681
672
|
if (typeof f != "function")
|
|
682
673
|
throw new E("ModelFacade");
|
|
@@ -758,7 +749,7 @@ function Ne(o, e, t, r, i) {
|
|
|
758
749
|
/* * * * */
|
|
759
750
|
async refresh(s) {
|
|
760
751
|
if (!this.exists)
|
|
761
|
-
throw new
|
|
752
|
+
throw new oe(i, "refresh");
|
|
762
753
|
const n = await r.call(
|
|
763
754
|
this.getRouteForRefresh(),
|
|
764
755
|
s,
|
|
@@ -772,17 +763,17 @@ function Ne(o, e, t, r, i) {
|
|
|
772
763
|
additionalPayload: a = {},
|
|
773
764
|
sendsOnlyModifiedFields: h = !0
|
|
774
765
|
} = s, d = this.exists, v = {
|
|
775
|
-
...
|
|
766
|
+
...p.pick(
|
|
776
767
|
h && d ? this.diff() : this.attributes,
|
|
777
768
|
...this.fillable
|
|
778
769
|
),
|
|
779
770
|
...a
|
|
780
771
|
};
|
|
781
|
-
if (
|
|
772
|
+
if (p.isEmpty(v))
|
|
782
773
|
return;
|
|
783
774
|
const f = await r.call(
|
|
784
775
|
this.getRouteForSave(),
|
|
785
|
-
(
|
|
776
|
+
(T) => n ? n(T.withData(v)) : T.withData(v),
|
|
786
777
|
this.getErrorBag(d ? "update" : "store")
|
|
787
778
|
);
|
|
788
779
|
if (f.successful())
|
|
@@ -793,7 +784,7 @@ function Ne(o, e, t, r, i) {
|
|
|
793
784
|
}
|
|
794
785
|
}
|
|
795
786
|
async push() {
|
|
796
|
-
throw new
|
|
787
|
+
throw new Se();
|
|
797
788
|
}
|
|
798
789
|
async delete() {
|
|
799
790
|
try {
|
|
@@ -861,7 +852,7 @@ function Ne(o, e, t, r, i) {
|
|
|
861
852
|
return t.schema(i);
|
|
862
853
|
}
|
|
863
854
|
static query() {
|
|
864
|
-
return new
|
|
855
|
+
return new Ee(
|
|
865
856
|
{ config: o, route: r, model: t },
|
|
866
857
|
i
|
|
867
858
|
);
|
|
@@ -946,14 +937,14 @@ function Ne(o, e, t, r, i) {
|
|
|
946
937
|
static plural() {
|
|
947
938
|
return t.schema(i).displayName.plural;
|
|
948
939
|
}
|
|
949
|
-
},
|
|
940
|
+
}, g(c, "name", y.studly(i)), c;
|
|
950
941
|
}
|
|
951
|
-
function
|
|
942
|
+
function Re(o, e, t) {
|
|
952
943
|
var r, i;
|
|
953
944
|
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
954
945
|
constructor(m = {}) {
|
|
955
946
|
super(m);
|
|
956
|
-
|
|
947
|
+
g(this, r, y.studly(e));
|
|
957
948
|
return new Proxy(this, {
|
|
958
949
|
get: (c, u) => {
|
|
959
950
|
if (u === "__isModel")
|
|
@@ -982,23 +973,23 @@ function ke(o, e, t) {
|
|
|
982
973
|
}
|
|
983
974
|
};
|
|
984
975
|
}
|
|
985
|
-
var
|
|
986
|
-
class q extends (
|
|
976
|
+
var G, V;
|
|
977
|
+
class q extends (V = Error, G = Symbol.toStringTag, V) {
|
|
987
978
|
constructor(t) {
|
|
988
979
|
super(`[Luminix] Model "${t}" not found`);
|
|
989
|
-
|
|
980
|
+
g(this, G, "ModelNotFoundException");
|
|
990
981
|
}
|
|
991
982
|
}
|
|
992
|
-
var
|
|
993
|
-
class R extends (
|
|
983
|
+
var z, X;
|
|
984
|
+
class R extends (X = TypeError, z = Symbol.toStringTag, X) {
|
|
994
985
|
constructor(t, r, i) {
|
|
995
986
|
super(`[Luminix] "${t}" expects a related model of type "${r}". Received "${i}" instead.`);
|
|
996
|
-
|
|
987
|
+
g(this, z, "ModelInvalidRelatedTypeException");
|
|
997
988
|
}
|
|
998
989
|
}
|
|
999
|
-
class
|
|
990
|
+
class ae extends k {
|
|
1000
991
|
constructor(e, t, r, i = null) {
|
|
1001
|
-
if (!
|
|
992
|
+
if (!p.isModel(i) && i !== null)
|
|
1002
993
|
throw new w("BelongsTo.constructor()", "Model or null");
|
|
1003
994
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1004
995
|
}
|
|
@@ -1016,12 +1007,12 @@ class he extends A {
|
|
|
1016
1007
|
return this.query().first();
|
|
1017
1008
|
}
|
|
1018
1009
|
async associate(e) {
|
|
1019
|
-
if (!
|
|
1010
|
+
if (!p.isModel(e))
|
|
1020
1011
|
throw new w("BelongsTo.associate()");
|
|
1021
1012
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1022
1013
|
throw new R("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
|
|
1023
1014
|
if (!e.exists)
|
|
1024
|
-
throw new
|
|
1015
|
+
throw new oe(this.getRelated().getSchemaName(), "save");
|
|
1025
1016
|
return this.parent.update({
|
|
1026
1017
|
[this.getForeignKey()]: e.getKey()
|
|
1027
1018
|
});
|
|
@@ -1032,9 +1023,9 @@ class he extends A {
|
|
|
1032
1023
|
});
|
|
1033
1024
|
}
|
|
1034
1025
|
}
|
|
1035
|
-
class
|
|
1026
|
+
class ue extends k {
|
|
1036
1027
|
constructor(e, t, r, i = null) {
|
|
1037
|
-
if (i !== null && !(i instanceof b && i.every(
|
|
1028
|
+
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1038
1029
|
throw new w("BelongsToMany.constructor()", "Collection<Model> or null");
|
|
1039
1030
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1040
1031
|
}
|
|
@@ -1128,22 +1119,22 @@ class le extends A {
|
|
|
1128
1119
|
this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
|
|
1129
1120
|
}
|
|
1130
1121
|
}
|
|
1131
|
-
class
|
|
1122
|
+
class N extends k {
|
|
1132
1123
|
query() {
|
|
1133
1124
|
const e = super.query(), t = this.guessInverseRelation();
|
|
1134
1125
|
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
1135
1126
|
}
|
|
1136
1127
|
async saveQuietly(e) {
|
|
1137
|
-
if (!
|
|
1128
|
+
if (!p.isModel(e))
|
|
1138
1129
|
throw new w("HasOneOrMany.saveQuietly()");
|
|
1139
1130
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1140
1131
|
throw new R("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1141
1132
|
e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
|
|
1142
1133
|
}
|
|
1143
1134
|
}
|
|
1144
|
-
class
|
|
1135
|
+
class ke extends N {
|
|
1145
1136
|
constructor(e, t, r, i = null) {
|
|
1146
|
-
if (!
|
|
1137
|
+
if (!p.isModel(i) && i !== null)
|
|
1147
1138
|
throw new w("HasOne.constructor()", "Model or null");
|
|
1148
1139
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1149
1140
|
}
|
|
@@ -1163,9 +1154,9 @@ class qe extends k {
|
|
|
1163
1154
|
function K(o) {
|
|
1164
1155
|
return new b(o);
|
|
1165
1156
|
}
|
|
1166
|
-
class
|
|
1157
|
+
class Ae extends N {
|
|
1167
1158
|
constructor(e, t, r, i = null) {
|
|
1168
|
-
if (i !== null && !(i instanceof b && i.every(
|
|
1159
|
+
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1169
1160
|
throw new w("HasMany.constructor()", "Collection<Model> or null");
|
|
1170
1161
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1171
1162
|
}
|
|
@@ -1188,7 +1179,7 @@ class Ke extends k {
|
|
|
1188
1179
|
return this.query().find(e);
|
|
1189
1180
|
}
|
|
1190
1181
|
async saveManyQuietly(e) {
|
|
1191
|
-
if (!Array.isArray(e) || !e.every(
|
|
1182
|
+
if (!Array.isArray(e) || !e.every(p.isModel))
|
|
1192
1183
|
throw new w("HasMany.saveManyQuietly()", "Model[]");
|
|
1193
1184
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
1194
1185
|
throw new R("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
@@ -1201,7 +1192,7 @@ class Ke extends k {
|
|
|
1201
1192
|
await this.saveQuietly(e), this.items === null ? this.items = K([e]) : this.items.push(e);
|
|
1202
1193
|
}
|
|
1203
1194
|
}
|
|
1204
|
-
class
|
|
1195
|
+
class he extends N {
|
|
1205
1196
|
query() {
|
|
1206
1197
|
const e = this.getRelated().query();
|
|
1207
1198
|
e.once("success", (r) => {
|
|
@@ -1211,7 +1202,7 @@ class ce extends k {
|
|
|
1211
1202
|
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;
|
|
1212
1203
|
}
|
|
1213
1204
|
async saveQuietly(e) {
|
|
1214
|
-
if (!
|
|
1205
|
+
if (!p.isModel(e))
|
|
1215
1206
|
throw new w("MorphOneOrMany.saveQuietly()");
|
|
1216
1207
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1217
1208
|
throw new R("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
@@ -1219,9 +1210,9 @@ class ce extends k {
|
|
|
1219
1210
|
e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
|
|
1220
1211
|
}
|
|
1221
1212
|
}
|
|
1222
|
-
class
|
|
1213
|
+
class Ne extends he {
|
|
1223
1214
|
constructor(e, t, r, i = null) {
|
|
1224
|
-
if (i !== null && !(i instanceof b && i.every(
|
|
1215
|
+
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1225
1216
|
throw new w("MorphMany.constructor()", "Collection<Model> or null");
|
|
1226
1217
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1227
1218
|
}
|
|
@@ -1244,7 +1235,7 @@ class je extends ce {
|
|
|
1244
1235
|
return this.query().find(e);
|
|
1245
1236
|
}
|
|
1246
1237
|
async saveManyQuietly(e) {
|
|
1247
|
-
if (!Array.isArray(e) || !e.every(
|
|
1238
|
+
if (!Array.isArray(e) || !e.every(p.isModel))
|
|
1248
1239
|
throw new w("MorphMany.saveManyQuietly()");
|
|
1249
1240
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
1250
1241
|
throw new R("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
@@ -1259,9 +1250,9 @@ class je extends ce {
|
|
|
1259
1250
|
await this.saveQuietly(e), this.items ? this.items.push(e) : this.items = await this.all();
|
|
1260
1251
|
}
|
|
1261
1252
|
}
|
|
1262
|
-
class
|
|
1253
|
+
class qe extends he {
|
|
1263
1254
|
constructor(e, t, r, i = null) {
|
|
1264
|
-
if (super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !
|
|
1255
|
+
if (super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !p.isModel(i))
|
|
1265
1256
|
throw new w("MorphOne.constructor()", "Model or null");
|
|
1266
1257
|
}
|
|
1267
1258
|
isSingle() {
|
|
@@ -1277,7 +1268,7 @@ class Oe extends ce {
|
|
|
1277
1268
|
await this.saveQuietly(e), this.items = e;
|
|
1278
1269
|
}
|
|
1279
1270
|
}
|
|
1280
|
-
class
|
|
1271
|
+
class Ke extends ae {
|
|
1281
1272
|
getRelated() {
|
|
1282
1273
|
return this.services.model.make(
|
|
1283
1274
|
this.parent.getAttribute(this.getName() + "_type")
|
|
@@ -1292,7 +1283,7 @@ class Be extends he {
|
|
|
1292
1283
|
// return super.query();
|
|
1293
1284
|
// }
|
|
1294
1285
|
async associate(e) {
|
|
1295
|
-
if (!
|
|
1286
|
+
if (!p.isModel(e))
|
|
1296
1287
|
throw new w("MorphTo.associate()");
|
|
1297
1288
|
return e.exists || await e.save(), this.parent.update({
|
|
1298
1289
|
[this.getName() + "_id"]: e.getKey(),
|
|
@@ -1306,24 +1297,25 @@ class Be extends he {
|
|
|
1306
1297
|
});
|
|
1307
1298
|
}
|
|
1308
1299
|
}
|
|
1309
|
-
class
|
|
1300
|
+
class je extends ue {
|
|
1310
1301
|
query() {
|
|
1311
|
-
|
|
1312
|
-
|
|
1302
|
+
var r;
|
|
1303
|
+
const e = super.query(), t = `${(r = this.meta.morphType) == null ? void 0 : r.slice(0, -5)}_id`;
|
|
1304
|
+
return e.where(t, this.parent.getKey()), e.where(this.meta.morphType, this.parent.getType()), e.lock(`where.${t}`), e.lock(`where.${this.meta.morphType}`), e;
|
|
1313
1305
|
}
|
|
1314
1306
|
}
|
|
1315
|
-
var
|
|
1316
|
-
class
|
|
1307
|
+
var Y, Z;
|
|
1308
|
+
class Oe extends (Z = A, Y = Symbol.toStringTag, Z) {
|
|
1317
1309
|
constructor(t) {
|
|
1318
1310
|
super();
|
|
1319
|
-
|
|
1320
|
-
|
|
1311
|
+
g(this, "_models", {});
|
|
1312
|
+
g(this, Y, "ModelService");
|
|
1321
1313
|
this._schema = t;
|
|
1322
1314
|
}
|
|
1323
1315
|
boot(t) {
|
|
1324
1316
|
this._schema && Object.keys(this._schema).forEach((r) => {
|
|
1325
1317
|
const i = this[`model${y.studly(r)}`], l = this.model(
|
|
1326
|
-
|
|
1318
|
+
_e(
|
|
1327
1319
|
t.make("config"),
|
|
1328
1320
|
t.make("log"),
|
|
1329
1321
|
t.make("model"),
|
|
@@ -1332,7 +1324,7 @@ class Ie extends (te = N, ee = Symbol.toStringTag, te) {
|
|
|
1332
1324
|
),
|
|
1333
1325
|
r
|
|
1334
1326
|
), m = i(l);
|
|
1335
|
-
this._models[r] =
|
|
1327
|
+
this._models[r] = Re(t.make("model"), r, m);
|
|
1336
1328
|
});
|
|
1337
1329
|
}
|
|
1338
1330
|
schema(t) {
|
|
@@ -1347,29 +1339,29 @@ class Ie extends (te = N, ee = Symbol.toStringTag, te) {
|
|
|
1347
1339
|
}
|
|
1348
1340
|
getRelationConstructors(t) {
|
|
1349
1341
|
return this.relationMap({
|
|
1350
|
-
BelongsTo:
|
|
1351
|
-
BelongsToMany:
|
|
1352
|
-
HasOne:
|
|
1353
|
-
HasMany:
|
|
1354
|
-
MorphMany:
|
|
1355
|
-
MorphOne:
|
|
1356
|
-
MorphTo:
|
|
1357
|
-
MorphToMany:
|
|
1342
|
+
BelongsTo: ae,
|
|
1343
|
+
BelongsToMany: ue,
|
|
1344
|
+
HasOne: ke,
|
|
1345
|
+
HasMany: Ae,
|
|
1346
|
+
MorphMany: Ne,
|
|
1347
|
+
MorphOne: qe,
|
|
1348
|
+
MorphTo: Ke,
|
|
1349
|
+
MorphToMany: je
|
|
1358
1350
|
}, t);
|
|
1359
1351
|
}
|
|
1360
1352
|
toString() {
|
|
1361
1353
|
return "model";
|
|
1362
1354
|
}
|
|
1363
1355
|
}
|
|
1364
|
-
const
|
|
1365
|
-
var
|
|
1366
|
-
class
|
|
1356
|
+
const Be = re(Oe);
|
|
1357
|
+
var ee, te;
|
|
1358
|
+
class Ce extends (te = Error, ee = Symbol.toStringTag, te) {
|
|
1367
1359
|
constructor(t) {
|
|
1368
1360
|
super(`[Luminix] Route "${t}" not found`);
|
|
1369
|
-
|
|
1361
|
+
g(this, ee, "RouteNotFoundException");
|
|
1370
1362
|
}
|
|
1371
1363
|
}
|
|
1372
|
-
class
|
|
1364
|
+
class Ie {
|
|
1373
1365
|
constructor(e, t, r, i = "") {
|
|
1374
1366
|
this.routes = e, this.error = t, this.http = r, this.appUrl = i;
|
|
1375
1367
|
}
|
|
@@ -1388,8 +1380,8 @@ class Le {
|
|
|
1388
1380
|
}
|
|
1389
1381
|
get(e) {
|
|
1390
1382
|
if (!this.exists(e))
|
|
1391
|
-
throw new
|
|
1392
|
-
return
|
|
1383
|
+
throw new Ce(e);
|
|
1384
|
+
return p.get(this.routes, e);
|
|
1393
1385
|
}
|
|
1394
1386
|
url(e) {
|
|
1395
1387
|
return this.appUrl + this.path(e);
|
|
@@ -1413,18 +1405,18 @@ class Le {
|
|
|
1413
1405
|
return this.get(t).slice(1);
|
|
1414
1406
|
}
|
|
1415
1407
|
exists(e) {
|
|
1416
|
-
return
|
|
1408
|
+
return p.has(this.routes, e) && this.isRouteTuple(p.get(this.routes, e));
|
|
1417
1409
|
}
|
|
1418
1410
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1419
1411
|
async call(e, t = (i) => i, r = "default") {
|
|
1420
1412
|
if (typeof this.clientOptions != "function" || typeof this.clientError != "function")
|
|
1421
1413
|
throw new E("RouteFacade");
|
|
1422
1414
|
const [i, l] = this.extractGenerator(e), [, ...m] = this.get(i), c = this.url(l ? [i, l] : i), u = t(this.http()), s = this.clientOptions({}, i);
|
|
1423
|
-
|
|
1415
|
+
p.isEmpty(s) || u.withOptions(s);
|
|
1424
1416
|
const n = m[0] ?? s.method;
|
|
1425
1417
|
this.error.clear(r);
|
|
1426
1418
|
const a = await u[n](c);
|
|
1427
|
-
if (
|
|
1419
|
+
if (ge(a)) {
|
|
1428
1420
|
const h = a.json("errors");
|
|
1429
1421
|
this.error.set(Object.entries(h).reduce((d, [v, f]) => (d[v] = f.join(" "), d), {}), r);
|
|
1430
1422
|
} else a.failed() && this.error.set(
|
|
@@ -1442,10 +1434,10 @@ class Le {
|
|
|
1442
1434
|
return "route";
|
|
1443
1435
|
}
|
|
1444
1436
|
}
|
|
1445
|
-
const
|
|
1446
|
-
class
|
|
1437
|
+
const Pe = re(Ie);
|
|
1438
|
+
class Qe {
|
|
1447
1439
|
getClient() {
|
|
1448
|
-
return new
|
|
1440
|
+
return new ye();
|
|
1449
1441
|
}
|
|
1450
1442
|
baseUrl(e) {
|
|
1451
1443
|
return this.getClient().baseUrl(e);
|
|
@@ -1498,12 +1490,12 @@ class He {
|
|
|
1498
1490
|
return this.getClient().delete(e, t);
|
|
1499
1491
|
}
|
|
1500
1492
|
}
|
|
1501
|
-
const
|
|
1502
|
-
var
|
|
1503
|
-
class
|
|
1493
|
+
const Le = ne(Qe);
|
|
1494
|
+
var se, ie;
|
|
1495
|
+
class De extends (ie = me, se = Symbol.toStringTag, ie) {
|
|
1504
1496
|
constructor() {
|
|
1505
1497
|
super(...arguments);
|
|
1506
|
-
|
|
1498
|
+
g(this, se, "LuminixServiceProvider");
|
|
1507
1499
|
}
|
|
1508
1500
|
register() {
|
|
1509
1501
|
this.registerServices(), this.registerMacros(), this.app.on("ready", () => {
|
|
@@ -1514,24 +1506,24 @@ class Fe extends (ne = we, re = Symbol.toStringTag, ne) {
|
|
|
1514
1506
|
this.app.make("model").boot(this.app);
|
|
1515
1507
|
}
|
|
1516
1508
|
registerServices() {
|
|
1517
|
-
this.app.singleton("auth", () => new
|
|
1509
|
+
this.app.singleton("auth", () => new ve(
|
|
1518
1510
|
this.app.make("config"),
|
|
1519
1511
|
this.app.make("model"),
|
|
1520
1512
|
this.app.make("route")
|
|
1521
1513
|
)), this.app.singleton("config", () => {
|
|
1522
|
-
const t = new _(
|
|
1514
|
+
const t = new _(p.omit(this.app.configuration, "manifest"));
|
|
1523
1515
|
return t.has("auth.user") || t.set("auth.user", null), t.lock("auth.user"), t;
|
|
1524
|
-
}), this.app.singleton("error", () => new
|
|
1516
|
+
}), this.app.singleton("error", () => new be()), this.app.singleton("http", () => new Le()), this.app.singleton("log", () => {
|
|
1525
1517
|
var t;
|
|
1526
|
-
return new
|
|
1518
|
+
return new xe(((t = this.app.configuration.app) == null ? void 0 : t.debug) ?? !1);
|
|
1527
1519
|
}), this.app.singleton("model", () => {
|
|
1528
1520
|
var t;
|
|
1529
|
-
return new
|
|
1521
|
+
return new Be(
|
|
1530
1522
|
((t = this.app.configuration.manifest) == null ? void 0 : t.models) ?? {}
|
|
1531
1523
|
);
|
|
1532
1524
|
}), this.app.singleton("route", () => {
|
|
1533
1525
|
var t, r;
|
|
1534
|
-
return new
|
|
1526
|
+
return new Pe(
|
|
1535
1527
|
((t = this.app.configuration.manifest) == null ? void 0 : t.routes) ?? {},
|
|
1536
1528
|
this.app.make("error"),
|
|
1537
1529
|
() => this.app.make("http"),
|
|
@@ -1540,18 +1532,18 @@ class Fe extends (ne = we, re = Symbol.toStringTag, ne) {
|
|
|
1540
1532
|
});
|
|
1541
1533
|
}
|
|
1542
1534
|
registerMacros() {
|
|
1543
|
-
this.app.macro("environment", (...t) => t.length > 0 ? t.includes(this.app.make("config").get("app.env", "production")) : this.app.make("config").get("app.env", "production")), this.app.macro("getLocale", () => this.app.make("config").get("app.locale", "en")), this.app.macro("hasDebugModeEnabled", () => this.app.make("config").get("app.debug", !1)), this.app.macro("isLocal", () => this.app.make("config").get("app.env", "production") === "local"), this.app.macro("isProduction", () => this.app.make("config").get("app.env", "production") === "production"),
|
|
1535
|
+
this.app.macro("environment", (...t) => t.length > 0 ? t.includes(this.app.make("config").get("app.env", "production")) : this.app.make("config").get("app.env", "production")), this.app.macro("getLocale", () => this.app.make("config").get("app.locale", "en")), this.app.macro("hasDebugModeEnabled", () => this.app.make("config").get("app.debug", !1)), this.app.macro("isLocal", () => this.app.make("config").get("app.env", "production") === "local"), this.app.macro("isProduction", () => this.app.make("config").get("app.env", "production") === "production"), p.macro("isModel", function(t) {
|
|
1544
1536
|
return typeof t == "object" && t !== null && t.__isModel === !0;
|
|
1545
1537
|
});
|
|
1546
1538
|
}
|
|
1547
1539
|
}
|
|
1548
|
-
class
|
|
1540
|
+
class He {
|
|
1549
1541
|
constructor() {
|
|
1550
|
-
|
|
1542
|
+
g(this, "app");
|
|
1551
1543
|
}
|
|
1552
1544
|
getFacadeAccessor() {
|
|
1553
|
-
return this.app || (this.app = new (
|
|
1554
|
-
|
|
1545
|
+
return this.app || (this.app = new (ne(fe))([
|
|
1546
|
+
De
|
|
1555
1547
|
])), this.app;
|
|
1556
1548
|
}
|
|
1557
1549
|
down() {
|
|
@@ -1561,78 +1553,78 @@ class Ue {
|
|
|
1561
1553
|
this.down(), this.app = e;
|
|
1562
1554
|
}
|
|
1563
1555
|
}
|
|
1564
|
-
const x = M(
|
|
1556
|
+
const x = M(He);
|
|
1565
1557
|
function $(o = void 0) {
|
|
1566
1558
|
return typeof o != "string" ? x : x.make(o);
|
|
1567
1559
|
}
|
|
1568
|
-
function
|
|
1560
|
+
function Ze() {
|
|
1569
1561
|
return $("auth");
|
|
1570
1562
|
}
|
|
1571
|
-
function
|
|
1563
|
+
function et(o, e) {
|
|
1572
1564
|
const t = $("config");
|
|
1573
1565
|
return typeof o > "u" ? t : t.get(o, e);
|
|
1574
1566
|
}
|
|
1575
|
-
function
|
|
1567
|
+
function tt(o, e = "default") {
|
|
1576
1568
|
return o ? $().make("error").get(o, e) : $().make("error");
|
|
1577
1569
|
}
|
|
1578
|
-
function
|
|
1570
|
+
function st(...o) {
|
|
1579
1571
|
const e = $("log");
|
|
1580
1572
|
return o.length ? e.debug(...o) : e;
|
|
1581
1573
|
}
|
|
1582
|
-
function
|
|
1574
|
+
function it(o) {
|
|
1583
1575
|
const e = $("model");
|
|
1584
1576
|
return o ? e.make(o) : e;
|
|
1585
1577
|
}
|
|
1586
|
-
function
|
|
1578
|
+
function rt(o, e = !1) {
|
|
1587
1579
|
const t = $("route");
|
|
1588
1580
|
return o ? e ? t.url([o, e]) : t.url(o) : t;
|
|
1589
1581
|
}
|
|
1590
|
-
class
|
|
1582
|
+
class Je {
|
|
1591
1583
|
getFacadeAccessor() {
|
|
1592
1584
|
return "auth";
|
|
1593
1585
|
}
|
|
1594
1586
|
}
|
|
1595
|
-
const
|
|
1596
|
-
class
|
|
1587
|
+
const nt = M(Je, x);
|
|
1588
|
+
class Ue {
|
|
1597
1589
|
getFacadeAccessor() {
|
|
1598
1590
|
return "config";
|
|
1599
1591
|
}
|
|
1600
1592
|
}
|
|
1601
|
-
const
|
|
1602
|
-
class
|
|
1593
|
+
const ot = M(Ue, x), at = (o) => o instanceof we && o.unprocessableEntity() && typeof o.json("message") == "string" && typeof o.json("errors") == "object" && o.json("errors") !== null && Object.values(o.json("errors")).every((e) => Array.isArray(e) && e.every((t) => typeof t == "string"));
|
|
1594
|
+
class Fe {
|
|
1603
1595
|
getFacadeAccessor() {
|
|
1604
1596
|
return "error";
|
|
1605
1597
|
}
|
|
1606
1598
|
}
|
|
1607
|
-
const
|
|
1608
|
-
class
|
|
1599
|
+
const ut = M(Fe, x);
|
|
1600
|
+
class We {
|
|
1609
1601
|
getFacadeAccessor() {
|
|
1610
1602
|
return "http";
|
|
1611
1603
|
}
|
|
1612
1604
|
}
|
|
1613
|
-
const
|
|
1614
|
-
class
|
|
1605
|
+
const ht = M(We, x);
|
|
1606
|
+
class Ge {
|
|
1615
1607
|
getFacadeAccessor() {
|
|
1616
1608
|
return "log";
|
|
1617
1609
|
}
|
|
1618
1610
|
}
|
|
1619
|
-
const
|
|
1620
|
-
class
|
|
1611
|
+
const lt = M(Ge, x);
|
|
1612
|
+
class Ve {
|
|
1621
1613
|
getFacadeAccessor() {
|
|
1622
1614
|
return "model";
|
|
1623
1615
|
}
|
|
1624
1616
|
}
|
|
1625
|
-
const
|
|
1626
|
-
class
|
|
1617
|
+
const ct = M(Ve, x);
|
|
1618
|
+
class ze {
|
|
1627
1619
|
getFacadeAccessor() {
|
|
1628
1620
|
return "route";
|
|
1629
1621
|
}
|
|
1630
1622
|
}
|
|
1631
|
-
const
|
|
1632
|
-
class
|
|
1623
|
+
const dt = M(ze, x);
|
|
1624
|
+
class pt {
|
|
1633
1625
|
constructor() {
|
|
1634
|
-
|
|
1635
|
-
|
|
1626
|
+
g(this, "name");
|
|
1627
|
+
g(this, "version");
|
|
1636
1628
|
}
|
|
1637
1629
|
register(e) {
|
|
1638
1630
|
}
|
|
@@ -1641,21 +1633,21 @@ class mt {
|
|
|
1641
1633
|
}
|
|
1642
1634
|
export {
|
|
1643
1635
|
x as App,
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1636
|
+
nt as Auth,
|
|
1637
|
+
ot as Config,
|
|
1638
|
+
ut as Error,
|
|
1639
|
+
ht as Http,
|
|
1640
|
+
lt as Log,
|
|
1641
|
+
ct as Model,
|
|
1642
|
+
pt as Plugin,
|
|
1643
|
+
dt as Route,
|
|
1652
1644
|
$ as app,
|
|
1653
|
-
|
|
1645
|
+
Ze as auth,
|
|
1654
1646
|
K as collect,
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1647
|
+
et as config,
|
|
1648
|
+
tt as error,
|
|
1649
|
+
at as isValidationError,
|
|
1650
|
+
st as log,
|
|
1651
|
+
it as model,
|
|
1652
|
+
rt as route
|
|
1661
1653
|
};
|
package/package.json
CHANGED
package/types/types/Model.d.ts
CHANGED
|
@@ -153,6 +153,7 @@ export interface RelationMetaData {
|
|
|
153
153
|
type: 'HasOne' | 'HasMany' | 'BelongsTo' | 'BelongsToMany' | 'MorphOne' | 'MorphMany' | 'MorphTo' | 'MorphToMany' | 'MorphedByMany';
|
|
154
154
|
foreignKey: string | null;
|
|
155
155
|
name: string;
|
|
156
|
+
morphType?: string;
|
|
156
157
|
}
|
|
157
158
|
export interface ModelSchema {
|
|
158
159
|
[abstract: string]: ModelSchemaAttributes;
|