@luminix/core 0.4.4 → 0.4.5
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 +169 -178
- package/package.json +1 -1
- package/types/exceptions/AttributeNotFoundException.d.ts +0 -4
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 T, 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,
|
|
@@ -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 Se 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 Se(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 Te 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 S = a.find((
|
|
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 S = a.find((le) => le.name == f);
|
|
500
|
+
return S ? !(f in d) && S.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,13 +763,13 @@ 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(),
|
|
@@ -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 Te();
|
|
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,24 @@ class Be extends he {
|
|
|
1306
1297
|
});
|
|
1307
1298
|
}
|
|
1308
1299
|
}
|
|
1309
|
-
class
|
|
1300
|
+
class je extends ue {
|
|
1310
1301
|
query() {
|
|
1311
1302
|
const e = super.query(), t = this.guessInverseRelation();
|
|
1312
1303
|
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;
|
|
1313
1304
|
}
|
|
1314
1305
|
}
|
|
1315
|
-
var
|
|
1316
|
-
class
|
|
1306
|
+
var Y, Z;
|
|
1307
|
+
class Oe extends (Z = A, Y = Symbol.toStringTag, Z) {
|
|
1317
1308
|
constructor(t) {
|
|
1318
1309
|
super();
|
|
1319
|
-
|
|
1320
|
-
|
|
1310
|
+
g(this, "_models", {});
|
|
1311
|
+
g(this, Y, "ModelService");
|
|
1321
1312
|
this._schema = t;
|
|
1322
1313
|
}
|
|
1323
1314
|
boot(t) {
|
|
1324
1315
|
this._schema && Object.keys(this._schema).forEach((r) => {
|
|
1325
1316
|
const i = this[`model${y.studly(r)}`], l = this.model(
|
|
1326
|
-
|
|
1317
|
+
_e(
|
|
1327
1318
|
t.make("config"),
|
|
1328
1319
|
t.make("log"),
|
|
1329
1320
|
t.make("model"),
|
|
@@ -1332,7 +1323,7 @@ class Ie extends (te = N, ee = Symbol.toStringTag, te) {
|
|
|
1332
1323
|
),
|
|
1333
1324
|
r
|
|
1334
1325
|
), m = i(l);
|
|
1335
|
-
this._models[r] =
|
|
1326
|
+
this._models[r] = Re(t.make("model"), r, m);
|
|
1336
1327
|
});
|
|
1337
1328
|
}
|
|
1338
1329
|
schema(t) {
|
|
@@ -1347,29 +1338,29 @@ class Ie extends (te = N, ee = Symbol.toStringTag, te) {
|
|
|
1347
1338
|
}
|
|
1348
1339
|
getRelationConstructors(t) {
|
|
1349
1340
|
return this.relationMap({
|
|
1350
|
-
BelongsTo:
|
|
1351
|
-
BelongsToMany:
|
|
1352
|
-
HasOne:
|
|
1353
|
-
HasMany:
|
|
1354
|
-
MorphMany:
|
|
1355
|
-
MorphOne:
|
|
1356
|
-
MorphTo:
|
|
1357
|
-
MorphToMany:
|
|
1341
|
+
BelongsTo: ae,
|
|
1342
|
+
BelongsToMany: ue,
|
|
1343
|
+
HasOne: ke,
|
|
1344
|
+
HasMany: Ae,
|
|
1345
|
+
MorphMany: Ne,
|
|
1346
|
+
MorphOne: qe,
|
|
1347
|
+
MorphTo: Ke,
|
|
1348
|
+
MorphToMany: je
|
|
1358
1349
|
}, t);
|
|
1359
1350
|
}
|
|
1360
1351
|
toString() {
|
|
1361
1352
|
return "model";
|
|
1362
1353
|
}
|
|
1363
1354
|
}
|
|
1364
|
-
const
|
|
1365
|
-
var
|
|
1366
|
-
class
|
|
1355
|
+
const Be = re(Oe);
|
|
1356
|
+
var ee, te;
|
|
1357
|
+
class Ce extends (te = Error, ee = Symbol.toStringTag, te) {
|
|
1367
1358
|
constructor(t) {
|
|
1368
1359
|
super(`[Luminix] Route "${t}" not found`);
|
|
1369
|
-
|
|
1360
|
+
g(this, ee, "RouteNotFoundException");
|
|
1370
1361
|
}
|
|
1371
1362
|
}
|
|
1372
|
-
class
|
|
1363
|
+
class Ie {
|
|
1373
1364
|
constructor(e, t, r, i = "") {
|
|
1374
1365
|
this.routes = e, this.error = t, this.http = r, this.appUrl = i;
|
|
1375
1366
|
}
|
|
@@ -1388,8 +1379,8 @@ class Le {
|
|
|
1388
1379
|
}
|
|
1389
1380
|
get(e) {
|
|
1390
1381
|
if (!this.exists(e))
|
|
1391
|
-
throw new
|
|
1392
|
-
return
|
|
1382
|
+
throw new Ce(e);
|
|
1383
|
+
return p.get(this.routes, e);
|
|
1393
1384
|
}
|
|
1394
1385
|
url(e) {
|
|
1395
1386
|
return this.appUrl + this.path(e);
|
|
@@ -1413,18 +1404,18 @@ class Le {
|
|
|
1413
1404
|
return this.get(t).slice(1);
|
|
1414
1405
|
}
|
|
1415
1406
|
exists(e) {
|
|
1416
|
-
return
|
|
1407
|
+
return p.has(this.routes, e) && this.isRouteTuple(p.get(this.routes, e));
|
|
1417
1408
|
}
|
|
1418
1409
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1419
1410
|
async call(e, t = (i) => i, r = "default") {
|
|
1420
1411
|
if (typeof this.clientOptions != "function" || typeof this.clientError != "function")
|
|
1421
1412
|
throw new E("RouteFacade");
|
|
1422
1413
|
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
|
-
|
|
1414
|
+
p.isEmpty(s) || u.withOptions(s);
|
|
1424
1415
|
const n = m[0] ?? s.method;
|
|
1425
1416
|
this.error.clear(r);
|
|
1426
1417
|
const a = await u[n](c);
|
|
1427
|
-
if (
|
|
1418
|
+
if (ge(a)) {
|
|
1428
1419
|
const h = a.json("errors");
|
|
1429
1420
|
this.error.set(Object.entries(h).reduce((d, [v, f]) => (d[v] = f.join(" "), d), {}), r);
|
|
1430
1421
|
} else a.failed() && this.error.set(
|
|
@@ -1442,10 +1433,10 @@ class Le {
|
|
|
1442
1433
|
return "route";
|
|
1443
1434
|
}
|
|
1444
1435
|
}
|
|
1445
|
-
const
|
|
1446
|
-
class
|
|
1436
|
+
const Pe = re(Ie);
|
|
1437
|
+
class Qe {
|
|
1447
1438
|
getClient() {
|
|
1448
|
-
return new
|
|
1439
|
+
return new ye();
|
|
1449
1440
|
}
|
|
1450
1441
|
baseUrl(e) {
|
|
1451
1442
|
return this.getClient().baseUrl(e);
|
|
@@ -1498,12 +1489,12 @@ class He {
|
|
|
1498
1489
|
return this.getClient().delete(e, t);
|
|
1499
1490
|
}
|
|
1500
1491
|
}
|
|
1501
|
-
const
|
|
1502
|
-
var
|
|
1503
|
-
class
|
|
1492
|
+
const Le = ne(Qe);
|
|
1493
|
+
var se, ie;
|
|
1494
|
+
class De extends (ie = me, se = Symbol.toStringTag, ie) {
|
|
1504
1495
|
constructor() {
|
|
1505
1496
|
super(...arguments);
|
|
1506
|
-
|
|
1497
|
+
g(this, se, "LuminixServiceProvider");
|
|
1507
1498
|
}
|
|
1508
1499
|
register() {
|
|
1509
1500
|
this.registerServices(), this.registerMacros(), this.app.on("ready", () => {
|
|
@@ -1514,24 +1505,24 @@ class Fe extends (ne = we, re = Symbol.toStringTag, ne) {
|
|
|
1514
1505
|
this.app.make("model").boot(this.app);
|
|
1515
1506
|
}
|
|
1516
1507
|
registerServices() {
|
|
1517
|
-
this.app.singleton("auth", () => new
|
|
1508
|
+
this.app.singleton("auth", () => new ve(
|
|
1518
1509
|
this.app.make("config"),
|
|
1519
1510
|
this.app.make("model"),
|
|
1520
1511
|
this.app.make("route")
|
|
1521
1512
|
)), this.app.singleton("config", () => {
|
|
1522
|
-
const t = new _(
|
|
1513
|
+
const t = new _(p.omit(this.app.configuration, "manifest"));
|
|
1523
1514
|
return t.has("auth.user") || t.set("auth.user", null), t.lock("auth.user"), t;
|
|
1524
|
-
}), this.app.singleton("error", () => new
|
|
1515
|
+
}), this.app.singleton("error", () => new be()), this.app.singleton("http", () => new Le()), this.app.singleton("log", () => {
|
|
1525
1516
|
var t;
|
|
1526
|
-
return new
|
|
1517
|
+
return new xe(((t = this.app.configuration.app) == null ? void 0 : t.debug) ?? !1);
|
|
1527
1518
|
}), this.app.singleton("model", () => {
|
|
1528
1519
|
var t;
|
|
1529
|
-
return new
|
|
1520
|
+
return new Be(
|
|
1530
1521
|
((t = this.app.configuration.manifest) == null ? void 0 : t.models) ?? {}
|
|
1531
1522
|
);
|
|
1532
1523
|
}), this.app.singleton("route", () => {
|
|
1533
1524
|
var t, r;
|
|
1534
|
-
return new
|
|
1525
|
+
return new Pe(
|
|
1535
1526
|
((t = this.app.configuration.manifest) == null ? void 0 : t.routes) ?? {},
|
|
1536
1527
|
this.app.make("error"),
|
|
1537
1528
|
() => this.app.make("http"),
|
|
@@ -1540,18 +1531,18 @@ class Fe extends (ne = we, re = Symbol.toStringTag, ne) {
|
|
|
1540
1531
|
});
|
|
1541
1532
|
}
|
|
1542
1533
|
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"),
|
|
1534
|
+
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
1535
|
return typeof t == "object" && t !== null && t.__isModel === !0;
|
|
1545
1536
|
});
|
|
1546
1537
|
}
|
|
1547
1538
|
}
|
|
1548
|
-
class
|
|
1539
|
+
class He {
|
|
1549
1540
|
constructor() {
|
|
1550
|
-
|
|
1541
|
+
g(this, "app");
|
|
1551
1542
|
}
|
|
1552
1543
|
getFacadeAccessor() {
|
|
1553
|
-
return this.app || (this.app = new (
|
|
1554
|
-
|
|
1544
|
+
return this.app || (this.app = new (ne(fe))([
|
|
1545
|
+
De
|
|
1555
1546
|
])), this.app;
|
|
1556
1547
|
}
|
|
1557
1548
|
down() {
|
|
@@ -1561,78 +1552,78 @@ class Ue {
|
|
|
1561
1552
|
this.down(), this.app = e;
|
|
1562
1553
|
}
|
|
1563
1554
|
}
|
|
1564
|
-
const x = M(
|
|
1555
|
+
const x = M(He);
|
|
1565
1556
|
function $(o = void 0) {
|
|
1566
1557
|
return typeof o != "string" ? x : x.make(o);
|
|
1567
1558
|
}
|
|
1568
|
-
function
|
|
1559
|
+
function Ze() {
|
|
1569
1560
|
return $("auth");
|
|
1570
1561
|
}
|
|
1571
|
-
function
|
|
1562
|
+
function et(o, e) {
|
|
1572
1563
|
const t = $("config");
|
|
1573
1564
|
return typeof o > "u" ? t : t.get(o, e);
|
|
1574
1565
|
}
|
|
1575
|
-
function
|
|
1566
|
+
function tt(o, e = "default") {
|
|
1576
1567
|
return o ? $().make("error").get(o, e) : $().make("error");
|
|
1577
1568
|
}
|
|
1578
|
-
function
|
|
1569
|
+
function st(...o) {
|
|
1579
1570
|
const e = $("log");
|
|
1580
1571
|
return o.length ? e.debug(...o) : e;
|
|
1581
1572
|
}
|
|
1582
|
-
function
|
|
1573
|
+
function it(o) {
|
|
1583
1574
|
const e = $("model");
|
|
1584
1575
|
return o ? e.make(o) : e;
|
|
1585
1576
|
}
|
|
1586
|
-
function
|
|
1577
|
+
function rt(o, e = !1) {
|
|
1587
1578
|
const t = $("route");
|
|
1588
1579
|
return o ? e ? t.url([o, e]) : t.url(o) : t;
|
|
1589
1580
|
}
|
|
1590
|
-
class
|
|
1581
|
+
class Je {
|
|
1591
1582
|
getFacadeAccessor() {
|
|
1592
1583
|
return "auth";
|
|
1593
1584
|
}
|
|
1594
1585
|
}
|
|
1595
|
-
const
|
|
1596
|
-
class
|
|
1586
|
+
const nt = M(Je, x);
|
|
1587
|
+
class Ue {
|
|
1597
1588
|
getFacadeAccessor() {
|
|
1598
1589
|
return "config";
|
|
1599
1590
|
}
|
|
1600
1591
|
}
|
|
1601
|
-
const
|
|
1602
|
-
class
|
|
1592
|
+
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"));
|
|
1593
|
+
class Fe {
|
|
1603
1594
|
getFacadeAccessor() {
|
|
1604
1595
|
return "error";
|
|
1605
1596
|
}
|
|
1606
1597
|
}
|
|
1607
|
-
const
|
|
1608
|
-
class
|
|
1598
|
+
const ut = M(Fe, x);
|
|
1599
|
+
class We {
|
|
1609
1600
|
getFacadeAccessor() {
|
|
1610
1601
|
return "http";
|
|
1611
1602
|
}
|
|
1612
1603
|
}
|
|
1613
|
-
const
|
|
1614
|
-
class
|
|
1604
|
+
const ht = M(We, x);
|
|
1605
|
+
class Ge {
|
|
1615
1606
|
getFacadeAccessor() {
|
|
1616
1607
|
return "log";
|
|
1617
1608
|
}
|
|
1618
1609
|
}
|
|
1619
|
-
const
|
|
1620
|
-
class
|
|
1610
|
+
const lt = M(Ge, x);
|
|
1611
|
+
class Ve {
|
|
1621
1612
|
getFacadeAccessor() {
|
|
1622
1613
|
return "model";
|
|
1623
1614
|
}
|
|
1624
1615
|
}
|
|
1625
|
-
const
|
|
1626
|
-
class
|
|
1616
|
+
const ct = M(Ve, x);
|
|
1617
|
+
class ze {
|
|
1627
1618
|
getFacadeAccessor() {
|
|
1628
1619
|
return "route";
|
|
1629
1620
|
}
|
|
1630
1621
|
}
|
|
1631
|
-
const
|
|
1632
|
-
class
|
|
1622
|
+
const dt = M(ze, x);
|
|
1623
|
+
class pt {
|
|
1633
1624
|
constructor() {
|
|
1634
|
-
|
|
1635
|
-
|
|
1625
|
+
g(this, "name");
|
|
1626
|
+
g(this, "version");
|
|
1636
1627
|
}
|
|
1637
1628
|
register(e) {
|
|
1638
1629
|
}
|
|
@@ -1641,21 +1632,21 @@ class mt {
|
|
|
1641
1632
|
}
|
|
1642
1633
|
export {
|
|
1643
1634
|
x as App,
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1635
|
+
nt as Auth,
|
|
1636
|
+
ot as Config,
|
|
1637
|
+
ut as Error,
|
|
1638
|
+
ht as Http,
|
|
1639
|
+
lt as Log,
|
|
1640
|
+
ct as Model,
|
|
1641
|
+
pt as Plugin,
|
|
1642
|
+
dt as Route,
|
|
1652
1643
|
$ as app,
|
|
1653
|
-
|
|
1644
|
+
Ze as auth,
|
|
1654
1645
|
K as collect,
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1646
|
+
et as config,
|
|
1647
|
+
tt as error,
|
|
1648
|
+
at as isValidationError,
|
|
1649
|
+
st as log,
|
|
1650
|
+
it as model,
|
|
1651
|
+
rt as route
|
|
1661
1652
|
};
|
package/package.json
CHANGED