@luminix/core 0.4.0 → 0.4.2
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 +99 -99
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
package/dist/core.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var le = Object.defineProperty;
|
|
2
2
|
var ce = (o, e, t) => e in o ? le(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
-
var
|
|
4
|
-
import { reader as de, PropertyBag as
|
|
3
|
+
var g = (o, e, t) => ce(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { reader as de, PropertyBag as T, EventSource as k, Collection as b, Query as S, Obj as p, Str as y, Reducible as re, isValidationError as pe, Macroable as ne, Client as ge, ServiceProvider as ye, MakeFacade as M, Application as me, Response as fe } from "@luminix/support";
|
|
5
5
|
class we {
|
|
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) {
|
|
@@ -53,17 +53,17 @@ class we {
|
|
|
53
53
|
}
|
|
54
54
|
class ve {
|
|
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
60
|
e[l] = de(l, "error");
|
|
61
61
|
}), this.bags = {
|
|
62
|
-
default: new
|
|
62
|
+
default: new T(e)
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
bag(e = "default") {
|
|
66
|
-
return this.bags[e] || (this.bags[e] = new
|
|
66
|
+
return this.bags[e] || (this.bags[e] = new T({})), this.bags[e];
|
|
67
67
|
}
|
|
68
68
|
add(e, t, r = "default") {
|
|
69
69
|
this.bag(r).set(e, t);
|
|
@@ -114,14 +114,14 @@ var j, O;
|
|
|
114
114
|
class xe 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 Me extends
|
|
120
|
+
class Me extends k {
|
|
121
121
|
constructor(t, r, i = {}) {
|
|
122
122
|
super();
|
|
123
|
-
|
|
124
|
-
this.services = t, this.abstract = r, this.bag = new
|
|
123
|
+
g(this, "bag");
|
|
124
|
+
this.services = t, this.abstract = r, this.bag = new T(i), this.bag.on("change", () => {
|
|
125
125
|
this.emit("change", {
|
|
126
126
|
data: this.bag,
|
|
127
127
|
source: this
|
|
@@ -297,27 +297,27 @@ var B, C;
|
|
|
297
297
|
class f 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
304
|
class Ee 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
311
|
class $e 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
317
|
class R {
|
|
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 f("Relation.constructor()", "Model, Collection<Model> or null");
|
|
322
322
|
}
|
|
323
323
|
make(e) {
|
|
@@ -358,9 +358,9 @@ class R {
|
|
|
358
358
|
throw new Ee(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 f("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 R {
|
|
|
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,35 +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
448
|
var J, U;
|
|
449
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
455
|
var F, W;
|
|
456
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
|
-
function
|
|
462
|
+
function Te(o, e, t, r, i) {
|
|
463
463
|
var l, m, c;
|
|
464
|
-
return c = class extends (m =
|
|
464
|
+
return c = class extends (m = k, l = Symbol.toStringTag, m) {
|
|
465
465
|
constructor(s = {}) {
|
|
466
466
|
super();
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
467
|
+
g(this, "_attributes", new T({}));
|
|
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));
|
|
474
474
|
this.makeRelations(), this.makeAttributes(s);
|
|
475
475
|
}
|
|
476
476
|
cast(s, n) {
|
|
@@ -485,7 +485,7 @@ function _e(o, e, t, r, i) {
|
|
|
485
485
|
return;
|
|
486
486
|
const n = t.getRelationConstructors(i);
|
|
487
487
|
Object.entries(s).forEach(([a, h]) => {
|
|
488
|
-
const { type:
|
|
488
|
+
const { type: d } = h, w = d in n ? n[d] : R;
|
|
489
489
|
this._relations[a] = new w(
|
|
490
490
|
{ model: t, route: r },
|
|
491
491
|
{ name: a, ...h },
|
|
@@ -495,11 +495,11 @@ function _e(o, e, t, r, i) {
|
|
|
495
495
|
});
|
|
496
496
|
}
|
|
497
497
|
makeAttributes(s) {
|
|
498
|
-
const { relations: n } = t.schema(i), a = Object.keys(n || {}), h =
|
|
499
|
-
if (this.fillable.filter((
|
|
500
|
-
h[
|
|
501
|
-
}), n && Object.keys(n).forEach((
|
|
502
|
-
this.relation(y.camel(
|
|
498
|
+
const { relations: n } = t.schema(i), a = Object.keys(n || {}), h = p.omit(s, ...a);
|
|
499
|
+
if (this.fillable.filter((d) => !(d in h)).forEach((d) => {
|
|
500
|
+
h[d] = null;
|
|
501
|
+
}), n && Object.keys(n).forEach((d) => {
|
|
502
|
+
this.relation(y.camel(d)).make(s[d]);
|
|
503
503
|
}), !this.validateJsonObject(h)) {
|
|
504
504
|
if (o.get("app.env", "production") === "production")
|
|
505
505
|
throw new TypeError(`[Luminix] Invalid attributes for model "${i}"`);
|
|
@@ -588,8 +588,8 @@ function _e(o, e, t, r, i) {
|
|
|
588
588
|
});
|
|
589
589
|
}
|
|
590
590
|
updateChangedKeys(s) {
|
|
591
|
-
const n = (
|
|
592
|
-
!this._changedKeys.includes(
|
|
591
|
+
const n = (h, d) => typeof h == "object" && h !== null ? p.isEqual(h, d) : h == d, a = s.includes(".") || s.includes("[") ? s.split(/[.[]/)[0] : s;
|
|
592
|
+
!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);
|
|
593
593
|
}
|
|
594
594
|
validateJsonObject(s) {
|
|
595
595
|
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)));
|
|
@@ -664,12 +664,12 @@ function _e(o, e, t, r, i) {
|
|
|
664
664
|
return this.primaryKey;
|
|
665
665
|
}
|
|
666
666
|
fill(s) {
|
|
667
|
-
const n =
|
|
668
|
-
const v = t[`model${y.studly(i)}Set${y.studly(
|
|
667
|
+
const n = p.pick(s, ...this.fillable), a = Object.entries(n).reduce((h, [d, w]) => {
|
|
668
|
+
const v = t[`model${y.studly(i)}Set${y.studly(d)}Attribute`];
|
|
669
669
|
if (typeof v != "function")
|
|
670
670
|
throw new E("ModelFacade");
|
|
671
|
-
return h[
|
|
672
|
-
this.mutate(w, this.casts[
|
|
671
|
+
return h[d] = v.bind(t)(
|
|
672
|
+
this.mutate(w, this.casts[d]),
|
|
673
673
|
this
|
|
674
674
|
), h;
|
|
675
675
|
}, {});
|
|
@@ -694,7 +694,7 @@ function _e(o, e, t, r, i) {
|
|
|
694
694
|
});
|
|
695
695
|
}
|
|
696
696
|
toJson() {
|
|
697
|
-
const s = Object.entries(this.relations).reduce((a, [h,
|
|
697
|
+
const s = Object.entries(this.relations).reduce((a, [h, d]) => (d.isLoaded() && (d.isSingle() ? a[y.snake(h)] = d.getLoadedItems().toJson() : d.isMultiple() && (a[y.snake(h)] = d.getLoadedItems().map((w) => w.toJson()).all())), a), {}), n = t[`model${y.studly(i)}Json`];
|
|
698
698
|
if (typeof n != "function")
|
|
699
699
|
throw new E("ModelFacade");
|
|
700
700
|
return n.bind(t)({
|
|
@@ -759,22 +759,22 @@ function _e(o, e, t, r, i) {
|
|
|
759
759
|
const {
|
|
760
760
|
additionalPayload: a = {},
|
|
761
761
|
sendsOnlyModifiedFields: h = !0
|
|
762
|
-
} = s,
|
|
763
|
-
...
|
|
764
|
-
h &&
|
|
762
|
+
} = s, d = this.exists, w = {
|
|
763
|
+
...p.pick(
|
|
764
|
+
h && d ? this.diff() : this.attributes,
|
|
765
765
|
...this.fillable
|
|
766
766
|
),
|
|
767
767
|
...a
|
|
768
768
|
};
|
|
769
|
-
if (
|
|
769
|
+
if (p.isEmpty(w))
|
|
770
770
|
return;
|
|
771
771
|
const v = await r.call(
|
|
772
772
|
this.getRouteForSave(),
|
|
773
|
-
(
|
|
774
|
-
this.getErrorBag(
|
|
773
|
+
(N) => n ? n(N.withData(w)) : N.withData(w),
|
|
774
|
+
this.getErrorBag(d ? "update" : "store")
|
|
775
775
|
);
|
|
776
776
|
if (v.successful())
|
|
777
|
-
return this.makeAttributes(v.json()), this.exists = !0, this.dispatchSaveEvent(),
|
|
777
|
+
return this.makeAttributes(v.json()), this.exists = !0, this.dispatchSaveEvent(), d ? this.dispatchUpdateEvent(v.json()) : (this.wasRecentlyCreated = !0, this.dispatchCreateEvent(v.json())), v;
|
|
778
778
|
throw v;
|
|
779
779
|
} catch (a) {
|
|
780
780
|
throw this.dispatchErrorEvent(a, "save"), a;
|
|
@@ -934,14 +934,14 @@ function _e(o, e, t, r, i) {
|
|
|
934
934
|
static plural() {
|
|
935
935
|
return t.schema(i).displayName.plural;
|
|
936
936
|
}
|
|
937
|
-
},
|
|
937
|
+
}, g(c, "name", y.studly(i)), c;
|
|
938
938
|
}
|
|
939
|
-
function
|
|
939
|
+
function _e(o, e, t) {
|
|
940
940
|
var r, i;
|
|
941
941
|
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
942
942
|
constructor(m = {}) {
|
|
943
943
|
super(m);
|
|
944
|
-
|
|
944
|
+
g(this, r, y.studly(e));
|
|
945
945
|
return new Proxy(this, {
|
|
946
946
|
get: (c, u) => {
|
|
947
947
|
if (u === "__isModel")
|
|
@@ -974,19 +974,19 @@ var G, V;
|
|
|
974
974
|
class q extends (V = Error, G = Symbol.toStringTag, V) {
|
|
975
975
|
constructor(t) {
|
|
976
976
|
super(`[Luminix] Model "${t}" not found`);
|
|
977
|
-
|
|
977
|
+
g(this, G, "ModelNotFoundException");
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
var z, X;
|
|
981
|
-
class
|
|
981
|
+
class _ extends (X = TypeError, z = Symbol.toStringTag, X) {
|
|
982
982
|
constructor(t, r, i) {
|
|
983
983
|
super(`[Luminix] "${t}" expects a related model of type "${r}". Received "${i}" instead.`);
|
|
984
|
-
|
|
984
|
+
g(this, z, "ModelInvalidRelatedTypeException");
|
|
985
985
|
}
|
|
986
986
|
}
|
|
987
987
|
class ae extends R {
|
|
988
988
|
constructor(e, t, r, i = null) {
|
|
989
|
-
if (!
|
|
989
|
+
if (!p.isModel(i) && i !== null)
|
|
990
990
|
throw new f("BelongsTo.constructor()", "Model or null");
|
|
991
991
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
992
992
|
}
|
|
@@ -1004,10 +1004,10 @@ class ae extends R {
|
|
|
1004
1004
|
return this.query().first();
|
|
1005
1005
|
}
|
|
1006
1006
|
async associate(e) {
|
|
1007
|
-
if (!
|
|
1007
|
+
if (!p.isModel(e))
|
|
1008
1008
|
throw new f("BelongsTo.associate()");
|
|
1009
1009
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1010
|
-
throw new
|
|
1010
|
+
throw new _("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
|
|
1011
1011
|
if (!e.exists)
|
|
1012
1012
|
throw new oe(this.getRelated().getSchemaName(), "save");
|
|
1013
1013
|
return this.parent.update({
|
|
@@ -1022,7 +1022,7 @@ class ae extends R {
|
|
|
1022
1022
|
}
|
|
1023
1023
|
class ue extends R {
|
|
1024
1024
|
constructor(e, t, r, i = null) {
|
|
1025
|
-
if (i !== null && !(i instanceof b && i.every(
|
|
1025
|
+
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1026
1026
|
throw new f("BelongsToMany.constructor()", "Collection<Model> or null");
|
|
1027
1027
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1028
1028
|
}
|
|
@@ -1116,22 +1116,22 @@ class ue extends R {
|
|
|
1116
1116
|
this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
|
|
1117
1117
|
}
|
|
1118
1118
|
}
|
|
1119
|
-
class
|
|
1119
|
+
class A extends R {
|
|
1120
1120
|
query() {
|
|
1121
1121
|
const e = super.query(), t = this.guessInverseRelation();
|
|
1122
1122
|
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
1123
1123
|
}
|
|
1124
1124
|
async saveQuietly(e) {
|
|
1125
|
-
if (!
|
|
1125
|
+
if (!p.isModel(e))
|
|
1126
1126
|
throw new f("HasOneOrMany.saveQuietly()");
|
|
1127
1127
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1128
|
-
throw new
|
|
1128
|
+
throw new _("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1129
1129
|
e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
|
|
1130
1130
|
}
|
|
1131
1131
|
}
|
|
1132
|
-
class Re extends
|
|
1132
|
+
class Re extends A {
|
|
1133
1133
|
constructor(e, t, r, i = null) {
|
|
1134
|
-
if (!
|
|
1134
|
+
if (!p.isModel(i) && i !== null)
|
|
1135
1135
|
throw new f("HasOne.constructor()", "Model or null");
|
|
1136
1136
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1137
1137
|
}
|
|
@@ -1151,9 +1151,9 @@ class Re extends N {
|
|
|
1151
1151
|
function K(o) {
|
|
1152
1152
|
return new b(o);
|
|
1153
1153
|
}
|
|
1154
|
-
class
|
|
1154
|
+
class ke extends A {
|
|
1155
1155
|
constructor(e, t, r, i = null) {
|
|
1156
|
-
if (i !== null && !(i instanceof b && i.every(
|
|
1156
|
+
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1157
1157
|
throw new f("HasMany.constructor()", "Collection<Model> or null");
|
|
1158
1158
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1159
1159
|
}
|
|
@@ -1176,10 +1176,10 @@ class Ae extends N {
|
|
|
1176
1176
|
return this.query().find(e);
|
|
1177
1177
|
}
|
|
1178
1178
|
async saveManyQuietly(e) {
|
|
1179
|
-
if (!Array.isArray(e) || !e.every(
|
|
1179
|
+
if (!Array.isArray(e) || !e.every(p.isModel))
|
|
1180
1180
|
throw new f("HasMany.saveManyQuietly()", "Model[]");
|
|
1181
1181
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
1182
|
-
throw new
|
|
1182
|
+
throw new _("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
1183
1183
|
await Promise.all(e.map((t) => (t.setAttribute(this.getForeignKey(), this.parent.getKey()), t.save())));
|
|
1184
1184
|
}
|
|
1185
1185
|
async saveMany(e) {
|
|
@@ -1189,7 +1189,7 @@ class Ae extends N {
|
|
|
1189
1189
|
await this.saveQuietly(e), this.items === null ? this.items = K([e]) : this.items.push(e);
|
|
1190
1190
|
}
|
|
1191
1191
|
}
|
|
1192
|
-
class he extends
|
|
1192
|
+
class he extends A {
|
|
1193
1193
|
query() {
|
|
1194
1194
|
const e = this.getRelated().query();
|
|
1195
1195
|
e.once("success", (r) => {
|
|
@@ -1199,17 +1199,17 @@ class he extends N {
|
|
|
1199
1199
|
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;
|
|
1200
1200
|
}
|
|
1201
1201
|
async saveQuietly(e) {
|
|
1202
|
-
if (!
|
|
1202
|
+
if (!p.isModel(e))
|
|
1203
1203
|
throw new f("MorphOneOrMany.saveQuietly()");
|
|
1204
1204
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1205
|
-
throw new
|
|
1205
|
+
throw new _("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1206
1206
|
const t = this.guessInverseRelation();
|
|
1207
1207
|
e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
|
|
1208
1208
|
}
|
|
1209
1209
|
}
|
|
1210
|
-
class
|
|
1210
|
+
class Ae extends he {
|
|
1211
1211
|
constructor(e, t, r, i = null) {
|
|
1212
|
-
if (i !== null && !(i instanceof b && i.every(
|
|
1212
|
+
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1213
1213
|
throw new f("MorphMany.constructor()", "Collection<Model> or null");
|
|
1214
1214
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1215
1215
|
}
|
|
@@ -1232,10 +1232,10 @@ class Ne extends he {
|
|
|
1232
1232
|
return this.query().find(e);
|
|
1233
1233
|
}
|
|
1234
1234
|
async saveManyQuietly(e) {
|
|
1235
|
-
if (!Array.isArray(e) || !e.every(
|
|
1235
|
+
if (!Array.isArray(e) || !e.every(p.isModel))
|
|
1236
1236
|
throw new f("MorphMany.saveManyQuietly()");
|
|
1237
1237
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
1238
|
-
throw new
|
|
1238
|
+
throw new _("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
1239
1239
|
await Promise.all(e.map((t) => (t.setAttribute(this.getName() + "_id", this.parent.getKey()), t.setAttribute(this.getName() + "_type", this.parent.getType()), t.save())));
|
|
1240
1240
|
}
|
|
1241
1241
|
async saveMany(e) {
|
|
@@ -1247,9 +1247,9 @@ class Ne extends he {
|
|
|
1247
1247
|
await this.saveQuietly(e), this.items ? this.items.push(e) : this.items = await this.all();
|
|
1248
1248
|
}
|
|
1249
1249
|
}
|
|
1250
|
-
class
|
|
1250
|
+
class Ne extends he {
|
|
1251
1251
|
constructor(e, t, r, i = null) {
|
|
1252
|
-
if (super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !
|
|
1252
|
+
if (super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !p.isModel(i))
|
|
1253
1253
|
throw new f("MorphOne.constructor()", "Model or null");
|
|
1254
1254
|
}
|
|
1255
1255
|
isSingle() {
|
|
@@ -1280,7 +1280,7 @@ class qe extends ae {
|
|
|
1280
1280
|
// return super.query();
|
|
1281
1281
|
// }
|
|
1282
1282
|
async associate(e) {
|
|
1283
|
-
if (!
|
|
1283
|
+
if (!p.isModel(e))
|
|
1284
1284
|
throw new f("MorphTo.associate()");
|
|
1285
1285
|
return e.exists || await e.save(), this.parent.update({
|
|
1286
1286
|
[this.getName() + "_id"]: e.getKey(),
|
|
@@ -1301,17 +1301,17 @@ class Ke extends ue {
|
|
|
1301
1301
|
}
|
|
1302
1302
|
}
|
|
1303
1303
|
var Y, Z;
|
|
1304
|
-
class je extends (Z =
|
|
1304
|
+
class je extends (Z = k, Y = Symbol.toStringTag, Z) {
|
|
1305
1305
|
constructor(t) {
|
|
1306
1306
|
super();
|
|
1307
|
-
|
|
1308
|
-
|
|
1307
|
+
g(this, "_models", {});
|
|
1308
|
+
g(this, Y, "ModelService");
|
|
1309
1309
|
this._schema = t;
|
|
1310
1310
|
}
|
|
1311
1311
|
boot(t) {
|
|
1312
1312
|
this._schema && Object.keys(this._schema).forEach((r) => {
|
|
1313
1313
|
const i = this[`model${y.studly(r)}`], l = this.model(
|
|
1314
|
-
|
|
1314
|
+
Te(
|
|
1315
1315
|
t.make("config"),
|
|
1316
1316
|
t.make("log"),
|
|
1317
1317
|
t.make("model"),
|
|
@@ -1320,7 +1320,7 @@ class je extends (Z = A, Y = Symbol.toStringTag, Z) {
|
|
|
1320
1320
|
),
|
|
1321
1321
|
r
|
|
1322
1322
|
), m = i(l);
|
|
1323
|
-
this._models[r] =
|
|
1323
|
+
this._models[r] = _e(t.make("model"), r, m);
|
|
1324
1324
|
});
|
|
1325
1325
|
}
|
|
1326
1326
|
schema(t) {
|
|
@@ -1338,9 +1338,9 @@ class je extends (Z = A, Y = Symbol.toStringTag, Z) {
|
|
|
1338
1338
|
BelongsTo: ae,
|
|
1339
1339
|
BelongsToMany: ue,
|
|
1340
1340
|
HasOne: Re,
|
|
1341
|
-
HasMany:
|
|
1342
|
-
MorphMany:
|
|
1343
|
-
MorphOne:
|
|
1341
|
+
HasMany: ke,
|
|
1342
|
+
MorphMany: Ae,
|
|
1343
|
+
MorphOne: Ne,
|
|
1344
1344
|
MorphTo: qe,
|
|
1345
1345
|
MorphToMany: Ke
|
|
1346
1346
|
}, t);
|
|
@@ -1354,7 +1354,7 @@ var ee, te;
|
|
|
1354
1354
|
class Be extends (te = Error, ee = Symbol.toStringTag, te) {
|
|
1355
1355
|
constructor(t) {
|
|
1356
1356
|
super(`[Luminix] Route "${t}" not found`);
|
|
1357
|
-
|
|
1357
|
+
g(this, ee, "RouteNotFoundException");
|
|
1358
1358
|
}
|
|
1359
1359
|
}
|
|
1360
1360
|
class Ce {
|
|
@@ -1377,7 +1377,7 @@ class Ce {
|
|
|
1377
1377
|
get(e) {
|
|
1378
1378
|
if (!this.exists(e))
|
|
1379
1379
|
throw new Be(e);
|
|
1380
|
-
return
|
|
1380
|
+
return p.get(this.routes, e);
|
|
1381
1381
|
}
|
|
1382
1382
|
url(e) {
|
|
1383
1383
|
return this.appUrl + this.path(e);
|
|
@@ -1394,27 +1394,27 @@ class Ce {
|
|
|
1394
1394
|
throw new TypeError(`Missing values for parameter(s): ${s.join(", ")}`);
|
|
1395
1395
|
if (n.length > 0)
|
|
1396
1396
|
throw new TypeError(`Unexpected parameters: ${n.join(", ")}`);
|
|
1397
|
-
return `/${c.reduce((h,
|
|
1397
|
+
return `/${c.reduce((h, d) => h.replace(`{${d}}`, `${r[d]}`), i)}`;
|
|
1398
1398
|
}
|
|
1399
1399
|
methods(e) {
|
|
1400
1400
|
const [t] = this.extractGenerator(e);
|
|
1401
1401
|
return this.get(t).slice(1);
|
|
1402
1402
|
}
|
|
1403
1403
|
exists(e) {
|
|
1404
|
-
return
|
|
1404
|
+
return p.has(this.routes, e) && this.isRouteTuple(p.get(this.routes, e));
|
|
1405
1405
|
}
|
|
1406
1406
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1407
1407
|
async call(e, t = (i) => i, r = "default") {
|
|
1408
1408
|
if (typeof this.clientOptions != "function" || typeof this.clientError != "function")
|
|
1409
1409
|
throw new E("RouteFacade");
|
|
1410
1410
|
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);
|
|
1411
|
-
|
|
1411
|
+
p.isEmpty(s) || u.withOptions(s);
|
|
1412
1412
|
const n = m[0] ?? s.method;
|
|
1413
1413
|
this.error.clear(r);
|
|
1414
1414
|
const a = await u[n](c);
|
|
1415
1415
|
if (pe(a)) {
|
|
1416
1416
|
const h = a.json("errors");
|
|
1417
|
-
this.error.set(Object.entries(h).reduce((
|
|
1417
|
+
this.error.set(Object.entries(h).reduce((d, [w, v]) => (d[w] = v.join(" "), d), {}), r);
|
|
1418
1418
|
} else a.failed() && this.error.set(
|
|
1419
1419
|
this.clientError({ axios: a.json("message") }, {
|
|
1420
1420
|
response: a,
|
|
@@ -1491,7 +1491,7 @@ var se, ie;
|
|
|
1491
1491
|
class Le extends (ie = ye, se = Symbol.toStringTag, ie) {
|
|
1492
1492
|
constructor() {
|
|
1493
1493
|
super(...arguments);
|
|
1494
|
-
|
|
1494
|
+
g(this, se, "LuminixServiceProvider");
|
|
1495
1495
|
}
|
|
1496
1496
|
register() {
|
|
1497
1497
|
this.registerServices(), this.registerMacros(), this.app.on("ready", () => {
|
|
@@ -1507,7 +1507,7 @@ class Le extends (ie = ye, se = Symbol.toStringTag, ie) {
|
|
|
1507
1507
|
this.app.make("model"),
|
|
1508
1508
|
this.app.make("route")
|
|
1509
1509
|
)), this.app.singleton("config", () => {
|
|
1510
|
-
const t = new
|
|
1510
|
+
const t = new T(p.omit(this.app.configuration, "manifest"));
|
|
1511
1511
|
return t.has("auth.user") || t.set("auth.user", null), t.lock("auth.user"), t;
|
|
1512
1512
|
}), this.app.singleton("error", () => new ve()), this.app.singleton("http", () => new Qe()), this.app.singleton("log", () => {
|
|
1513
1513
|
var t;
|
|
@@ -1528,14 +1528,14 @@ class Le extends (ie = ye, se = Symbol.toStringTag, ie) {
|
|
|
1528
1528
|
});
|
|
1529
1529
|
}
|
|
1530
1530
|
registerMacros() {
|
|
1531
|
-
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"),
|
|
1531
|
+
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) {
|
|
1532
1532
|
return typeof t == "object" && t !== null && t.__isModel === !0;
|
|
1533
1533
|
});
|
|
1534
1534
|
}
|
|
1535
1535
|
}
|
|
1536
1536
|
class De {
|
|
1537
1537
|
constructor() {
|
|
1538
|
-
|
|
1538
|
+
g(this, "app");
|
|
1539
1539
|
}
|
|
1540
1540
|
getFacadeAccessor() {
|
|
1541
1541
|
return this.app || (this.app = new (ne(me))([
|
|
@@ -1619,8 +1619,8 @@ class Ve {
|
|
|
1619
1619
|
const ct = M(Ve, x);
|
|
1620
1620
|
class dt {
|
|
1621
1621
|
constructor() {
|
|
1622
|
-
|
|
1623
|
-
|
|
1622
|
+
g(this, "name");
|
|
1623
|
+
g(this, "version");
|
|
1624
1624
|
}
|
|
1625
1625
|
register(e) {
|
|
1626
1626
|
}
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -22,4 +22,5 @@ export type { BuilderInterface, Scope } from './types/Builder';
|
|
|
22
22
|
export type { AppConfiguration } from './types/Config';
|
|
23
23
|
export type { LogFacade } from './types/Log';
|
|
24
24
|
export type { Model as ModelType, BaseModel, ModelAttribute, ModelSaveOptions, ModelPaginatedResponse, ModelPaginatedLink } from './types/Model';
|
|
25
|
+
export type { RelationInterface as Relation } from './types/Relation';
|
|
25
26
|
export type { RouteFacade, RouteReducers, HttpMethod, RouteGenerator } from './types/Route';
|