@luminix/core 0.4.3 → 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 +147 -144
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var g = (o, e, t) =>
|
|
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;
|
|
@@ -51,13 +51,13 @@ class we {
|
|
|
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 ve {
|
|
|
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,13 +111,13 @@ class be {
|
|
|
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");
|
|
@@ -222,16 +222,16 @@ class Me extends k {
|
|
|
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}?${T.merge(u, l.json("links").first).toString()}`,
|
|
226
|
+
last: `${s}?${T.merge(u, l.json("links").last).toString()}`,
|
|
227
|
+
next: l.json("links").next && `${s}?${T.merge(u, l.json("links").next ?? "").toString()}`,
|
|
228
|
+
prev: l.json("links").prev && `${s}?${T.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}?${T.merge(u, n.url).toString()}`
|
|
235
235
|
}))
|
|
236
236
|
}
|
|
237
237
|
};
|
|
@@ -266,7 +266,7 @@ class Me extends k {
|
|
|
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,
|
|
@@ -294,31 +294,31 @@ class Me extends k {
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
var B, C;
|
|
297
|
-
class
|
|
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
319
|
g(this, "unsubscribeQuery", null);
|
|
320
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
|
-
throw new
|
|
321
|
+
throw new w("Relation.constructor()", "Model, Collection<Model> or null");
|
|
322
322
|
}
|
|
323
323
|
make(e) {
|
|
324
324
|
const t = this.getRelated();
|
|
@@ -349,17 +349,17 @@ class R {
|
|
|
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
361
|
if (e !== null && !p.isModel(e) && !(e instanceof b && e.every(p.isModel)))
|
|
362
|
-
throw new
|
|
362
|
+
throw new w("Relation.set()", "Model, Collection<Model> or null");
|
|
363
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() {
|
|
@@ -446,7 +446,7 @@ class E extends (H = Error, D = Symbol.toStringTag, H) {
|
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
448
|
var J, U;
|
|
449
|
-
class
|
|
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");
|
|
@@ -461,7 +461,7 @@ class oe extends (W = Error, F = Symbol.toStringTag, W) {
|
|
|
461
461
|
}
|
|
462
462
|
function _e(o, e, t, r, i) {
|
|
463
463
|
var l, m, c;
|
|
464
|
-
return c = class extends (m =
|
|
464
|
+
return c = class extends (m = A, l = Symbol.toStringTag, m) {
|
|
465
465
|
constructor(s = {}) {
|
|
466
466
|
super();
|
|
467
467
|
g(this, "_attributes", new _({}));
|
|
@@ -474,7 +474,7 @@ function _e(o, e, t, r, i) {
|
|
|
474
474
|
this.makeRelations(), this.makeAttributes(s);
|
|
475
475
|
}
|
|
476
476
|
cast(s, n) {
|
|
477
|
-
return s == null || !n ? s : ["boolean", "bool"].includes(n) ? !!s : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(n) && typeof s == "string" ? new Date(s) : ["float", "double", "integer", "int"].includes(n) || n.startsWith("decimal:") ? Number(s) : s;
|
|
477
|
+
return s == null || !n ? s : ["boolean", "bool"].includes(n) ? !!s && s !== "0" : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(n) && typeof s == "string" ? new Date(s) : ["float", "double", "integer", "int"].includes(n) || n.startsWith("decimal:") ? Number(s) : s;
|
|
478
478
|
}
|
|
479
479
|
mutate(s, n) {
|
|
480
480
|
return s == null || !n ? s : ["boolean", "bool"].includes(n) ? !!s : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(n) && s instanceof Date ? s.toISOString() : ["float", "double", "integer", "int"].includes(n) || n.startsWith("decimal:") ? Number(s) : s;
|
|
@@ -485,8 +485,8 @@ 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: d } = h,
|
|
489
|
-
this._relations[a] = new
|
|
488
|
+
const { type: d } = h, v = d in n ? n[d] : k;
|
|
489
|
+
this._relations[a] = new v(
|
|
490
490
|
{ model: t, route: r },
|
|
491
491
|
{ name: a, ...h },
|
|
492
492
|
this,
|
|
@@ -495,12 +495,15 @@ function _e(o, e, t, r, i) {
|
|
|
495
495
|
});
|
|
496
496
|
}
|
|
497
497
|
makeAttributes(s) {
|
|
498
|
-
const { relations: n } = t.schema(i),
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
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;
|
|
501
|
+
};
|
|
502
|
+
if (this.fillable.filter(v).forEach((f) => {
|
|
503
|
+
d[f] = null;
|
|
504
|
+
}), n && Object.keys(n).forEach((f) => {
|
|
505
|
+
this.relation(y.camel(f)).make(s[f]);
|
|
506
|
+
}), !this.validateJsonObject(d)) {
|
|
504
507
|
if (o.get("app.env", "production") === "production")
|
|
505
508
|
throw new TypeError(`[Luminix] Invalid attributes for model "${i}"`);
|
|
506
509
|
e.warning(`Invalid attributes for model "${i}".
|
|
@@ -509,7 +512,7 @@ function _e(o, e, t, r, i) {
|
|
|
509
512
|
abstract: i
|
|
510
513
|
});
|
|
511
514
|
}
|
|
512
|
-
this._attributes.set(".",
|
|
515
|
+
this._attributes.set(".", d), this._original = d, this._changedKeys.splice(0, this._changedKeys.length);
|
|
513
516
|
}
|
|
514
517
|
makePrimaryKeyReplacer() {
|
|
515
518
|
return {
|
|
@@ -664,12 +667,12 @@ function _e(o, e, t, r, i) {
|
|
|
664
667
|
return this.primaryKey;
|
|
665
668
|
}
|
|
666
669
|
fill(s) {
|
|
667
|
-
const n = p.pick(s, ...this.fillable), a = Object.entries(n).reduce((h, [d,
|
|
668
|
-
const
|
|
669
|
-
if (typeof
|
|
670
|
+
const n = p.pick(s, ...this.fillable), a = Object.entries(n).reduce((h, [d, v]) => {
|
|
671
|
+
const f = t[`model${y.studly(i)}Set${y.studly(d)}Attribute`];
|
|
672
|
+
if (typeof f != "function")
|
|
670
673
|
throw new E("ModelFacade");
|
|
671
|
-
return h[d] =
|
|
672
|
-
this.mutate(
|
|
674
|
+
return h[d] = f.bind(t)(
|
|
675
|
+
this.mutate(v, this.casts[d]),
|
|
673
676
|
this
|
|
674
677
|
), h;
|
|
675
678
|
}, {});
|
|
@@ -694,7 +697,7 @@ function _e(o, e, t, r, i) {
|
|
|
694
697
|
});
|
|
695
698
|
}
|
|
696
699
|
toJson() {
|
|
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((
|
|
700
|
+
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((v) => v.toJson()).all())), a), {}), n = t[`model${y.studly(i)}Json`];
|
|
698
701
|
if (typeof n != "function")
|
|
699
702
|
throw new E("ModelFacade");
|
|
700
703
|
return n.bind(t)({
|
|
@@ -759,29 +762,29 @@ function _e(o, e, t, r, i) {
|
|
|
759
762
|
const {
|
|
760
763
|
additionalPayload: a = {},
|
|
761
764
|
sendsOnlyModifiedFields: h = !0
|
|
762
|
-
} = s, d = this.exists,
|
|
765
|
+
} = s, d = this.exists, v = {
|
|
763
766
|
...p.pick(
|
|
764
767
|
h && d ? this.diff() : this.attributes,
|
|
765
768
|
...this.fillable
|
|
766
769
|
),
|
|
767
770
|
...a
|
|
768
771
|
};
|
|
769
|
-
if (p.isEmpty(
|
|
772
|
+
if (p.isEmpty(v))
|
|
770
773
|
return;
|
|
771
|
-
const
|
|
774
|
+
const f = await r.call(
|
|
772
775
|
this.getRouteForSave(),
|
|
773
|
-
(
|
|
776
|
+
(S) => n ? n(S.withData(v)) : S.withData(v),
|
|
774
777
|
this.getErrorBag(d ? "update" : "store")
|
|
775
778
|
);
|
|
776
|
-
if (
|
|
777
|
-
return this.makeAttributes(
|
|
778
|
-
throw
|
|
779
|
+
if (f.successful())
|
|
780
|
+
return this.makeAttributes(f.json()), this.exists = !0, this.dispatchSaveEvent(), d ? this.dispatchUpdateEvent(f.json()) : (this.wasRecentlyCreated = !0, this.dispatchCreateEvent(f.json())), f;
|
|
781
|
+
throw f;
|
|
779
782
|
} catch (a) {
|
|
780
783
|
throw this.dispatchErrorEvent(a, "save"), a;
|
|
781
784
|
}
|
|
782
785
|
}
|
|
783
786
|
async push() {
|
|
784
|
-
throw new
|
|
787
|
+
throw new Te();
|
|
785
788
|
}
|
|
786
789
|
async delete() {
|
|
787
790
|
try {
|
|
@@ -849,7 +852,7 @@ function _e(o, e, t, r, i) {
|
|
|
849
852
|
return t.schema(i);
|
|
850
853
|
}
|
|
851
854
|
static query() {
|
|
852
|
-
return new
|
|
855
|
+
return new Ee(
|
|
853
856
|
{ config: o, route: r, model: t },
|
|
854
857
|
i
|
|
855
858
|
);
|
|
@@ -936,7 +939,7 @@ function _e(o, e, t, r, i) {
|
|
|
936
939
|
}
|
|
937
940
|
}, g(c, "name", y.studly(i)), c;
|
|
938
941
|
}
|
|
939
|
-
function
|
|
942
|
+
function Re(o, e, t) {
|
|
940
943
|
var r, i;
|
|
941
944
|
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
942
945
|
constructor(m = {}) {
|
|
@@ -978,16 +981,16 @@ class q extends (V = Error, G = Symbol.toStringTag, V) {
|
|
|
978
981
|
}
|
|
979
982
|
}
|
|
980
983
|
var z, X;
|
|
981
|
-
class
|
|
984
|
+
class R extends (X = TypeError, z = Symbol.toStringTag, X) {
|
|
982
985
|
constructor(t, r, i) {
|
|
983
986
|
super(`[Luminix] "${t}" expects a related model of type "${r}". Received "${i}" instead.`);
|
|
984
987
|
g(this, z, "ModelInvalidRelatedTypeException");
|
|
985
988
|
}
|
|
986
989
|
}
|
|
987
|
-
class ae extends
|
|
990
|
+
class ae extends k {
|
|
988
991
|
constructor(e, t, r, i = null) {
|
|
989
992
|
if (!p.isModel(i) && i !== null)
|
|
990
|
-
throw new
|
|
993
|
+
throw new w("BelongsTo.constructor()", "Model or null");
|
|
991
994
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
992
995
|
}
|
|
993
996
|
isSingle() {
|
|
@@ -1005,9 +1008,9 @@ class ae extends R {
|
|
|
1005
1008
|
}
|
|
1006
1009
|
async associate(e) {
|
|
1007
1010
|
if (!p.isModel(e))
|
|
1008
|
-
throw new
|
|
1011
|
+
throw new w("BelongsTo.associate()");
|
|
1009
1012
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1010
|
-
throw new
|
|
1013
|
+
throw new R("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
|
|
1011
1014
|
if (!e.exists)
|
|
1012
1015
|
throw new oe(this.getRelated().getSchemaName(), "save");
|
|
1013
1016
|
return this.parent.update({
|
|
@@ -1020,10 +1023,10 @@ class ae extends R {
|
|
|
1020
1023
|
});
|
|
1021
1024
|
}
|
|
1022
1025
|
}
|
|
1023
|
-
class ue extends
|
|
1026
|
+
class ue extends k {
|
|
1024
1027
|
constructor(e, t, r, i = null) {
|
|
1025
1028
|
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1026
|
-
throw new
|
|
1029
|
+
throw new w("BelongsToMany.constructor()", "Collection<Model> or null");
|
|
1027
1030
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1028
1031
|
}
|
|
1029
1032
|
isSingle() {
|
|
@@ -1116,23 +1119,23 @@ class ue extends R {
|
|
|
1116
1119
|
this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
|
|
1117
1120
|
}
|
|
1118
1121
|
}
|
|
1119
|
-
class
|
|
1122
|
+
class N extends k {
|
|
1120
1123
|
query() {
|
|
1121
1124
|
const e = super.query(), t = this.guessInverseRelation();
|
|
1122
1125
|
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
1123
1126
|
}
|
|
1124
1127
|
async saveQuietly(e) {
|
|
1125
1128
|
if (!p.isModel(e))
|
|
1126
|
-
throw new
|
|
1129
|
+
throw new w("HasOneOrMany.saveQuietly()");
|
|
1127
1130
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1128
|
-
throw new
|
|
1131
|
+
throw new R("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1129
1132
|
e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
|
|
1130
1133
|
}
|
|
1131
1134
|
}
|
|
1132
|
-
class
|
|
1135
|
+
class ke extends N {
|
|
1133
1136
|
constructor(e, t, r, i = null) {
|
|
1134
1137
|
if (!p.isModel(i) && i !== null)
|
|
1135
|
-
throw new
|
|
1138
|
+
throw new w("HasOne.constructor()", "Model or null");
|
|
1136
1139
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1137
1140
|
}
|
|
1138
1141
|
isSingle() {
|
|
@@ -1151,10 +1154,10 @@ class Re extends A {
|
|
|
1151
1154
|
function K(o) {
|
|
1152
1155
|
return new b(o);
|
|
1153
1156
|
}
|
|
1154
|
-
class
|
|
1157
|
+
class Ae extends N {
|
|
1155
1158
|
constructor(e, t, r, i = null) {
|
|
1156
1159
|
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1157
|
-
throw new
|
|
1160
|
+
throw new w("HasMany.constructor()", "Collection<Model> or null");
|
|
1158
1161
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1159
1162
|
}
|
|
1160
1163
|
isSingle() {
|
|
@@ -1177,9 +1180,9 @@ class ke extends A {
|
|
|
1177
1180
|
}
|
|
1178
1181
|
async saveManyQuietly(e) {
|
|
1179
1182
|
if (!Array.isArray(e) || !e.every(p.isModel))
|
|
1180
|
-
throw new
|
|
1183
|
+
throw new w("HasMany.saveManyQuietly()", "Model[]");
|
|
1181
1184
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
1182
|
-
throw new
|
|
1185
|
+
throw new R("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
1183
1186
|
await Promise.all(e.map((t) => (t.setAttribute(this.getForeignKey(), this.parent.getKey()), t.save())));
|
|
1184
1187
|
}
|
|
1185
1188
|
async saveMany(e) {
|
|
@@ -1189,7 +1192,7 @@ class ke extends A {
|
|
|
1189
1192
|
await this.saveQuietly(e), this.items === null ? this.items = K([e]) : this.items.push(e);
|
|
1190
1193
|
}
|
|
1191
1194
|
}
|
|
1192
|
-
class he extends
|
|
1195
|
+
class he extends N {
|
|
1193
1196
|
query() {
|
|
1194
1197
|
const e = this.getRelated().query();
|
|
1195
1198
|
e.once("success", (r) => {
|
|
@@ -1200,17 +1203,17 @@ class he extends A {
|
|
|
1200
1203
|
}
|
|
1201
1204
|
async saveQuietly(e) {
|
|
1202
1205
|
if (!p.isModel(e))
|
|
1203
|
-
throw new
|
|
1206
|
+
throw new w("MorphOneOrMany.saveQuietly()");
|
|
1204
1207
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1205
|
-
throw new
|
|
1208
|
+
throw new R("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1206
1209
|
const t = this.guessInverseRelation();
|
|
1207
1210
|
e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
|
|
1208
1211
|
}
|
|
1209
1212
|
}
|
|
1210
|
-
class
|
|
1213
|
+
class Ne extends he {
|
|
1211
1214
|
constructor(e, t, r, i = null) {
|
|
1212
1215
|
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1213
|
-
throw new
|
|
1216
|
+
throw new w("MorphMany.constructor()", "Collection<Model> or null");
|
|
1214
1217
|
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1215
1218
|
}
|
|
1216
1219
|
isSingle() {
|
|
@@ -1233,9 +1236,9 @@ class Ae extends he {
|
|
|
1233
1236
|
}
|
|
1234
1237
|
async saveManyQuietly(e) {
|
|
1235
1238
|
if (!Array.isArray(e) || !e.every(p.isModel))
|
|
1236
|
-
throw new
|
|
1239
|
+
throw new w("MorphMany.saveManyQuietly()");
|
|
1237
1240
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
1238
|
-
throw new
|
|
1241
|
+
throw new R("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
1239
1242
|
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
1243
|
}
|
|
1241
1244
|
async saveMany(e) {
|
|
@@ -1247,10 +1250,10 @@ class Ae extends he {
|
|
|
1247
1250
|
await this.saveQuietly(e), this.items ? this.items.push(e) : this.items = await this.all();
|
|
1248
1251
|
}
|
|
1249
1252
|
}
|
|
1250
|
-
class
|
|
1253
|
+
class qe extends he {
|
|
1251
1254
|
constructor(e, t, r, i = null) {
|
|
1252
1255
|
if (super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !p.isModel(i))
|
|
1253
|
-
throw new
|
|
1256
|
+
throw new w("MorphOne.constructor()", "Model or null");
|
|
1254
1257
|
}
|
|
1255
1258
|
isSingle() {
|
|
1256
1259
|
return !0;
|
|
@@ -1265,7 +1268,7 @@ class Ne extends he {
|
|
|
1265
1268
|
await this.saveQuietly(e), this.items = e;
|
|
1266
1269
|
}
|
|
1267
1270
|
}
|
|
1268
|
-
class
|
|
1271
|
+
class Ke extends ae {
|
|
1269
1272
|
getRelated() {
|
|
1270
1273
|
return this.services.model.make(
|
|
1271
1274
|
this.parent.getAttribute(this.getName() + "_type")
|
|
@@ -1281,7 +1284,7 @@ class qe extends ae {
|
|
|
1281
1284
|
// }
|
|
1282
1285
|
async associate(e) {
|
|
1283
1286
|
if (!p.isModel(e))
|
|
1284
|
-
throw new
|
|
1287
|
+
throw new w("MorphTo.associate()");
|
|
1285
1288
|
return e.exists || await e.save(), this.parent.update({
|
|
1286
1289
|
[this.getName() + "_id"]: e.getKey(),
|
|
1287
1290
|
[this.getName() + "_type"]: e.getType()
|
|
@@ -1294,14 +1297,14 @@ class qe extends ae {
|
|
|
1294
1297
|
});
|
|
1295
1298
|
}
|
|
1296
1299
|
}
|
|
1297
|
-
class
|
|
1300
|
+
class je extends ue {
|
|
1298
1301
|
query() {
|
|
1299
1302
|
const e = super.query(), t = this.guessInverseRelation();
|
|
1300
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;
|
|
1301
1304
|
}
|
|
1302
1305
|
}
|
|
1303
1306
|
var Y, Z;
|
|
1304
|
-
class
|
|
1307
|
+
class Oe extends (Z = A, Y = Symbol.toStringTag, Z) {
|
|
1305
1308
|
constructor(t) {
|
|
1306
1309
|
super();
|
|
1307
1310
|
g(this, "_models", {});
|
|
@@ -1320,7 +1323,7 @@ class je extends (Z = k, Y = Symbol.toStringTag, Z) {
|
|
|
1320
1323
|
),
|
|
1321
1324
|
r
|
|
1322
1325
|
), m = i(l);
|
|
1323
|
-
this._models[r] =
|
|
1326
|
+
this._models[r] = Re(t.make("model"), r, m);
|
|
1324
1327
|
});
|
|
1325
1328
|
}
|
|
1326
1329
|
schema(t) {
|
|
@@ -1337,27 +1340,27 @@ class je extends (Z = k, Y = Symbol.toStringTag, Z) {
|
|
|
1337
1340
|
return this.relationMap({
|
|
1338
1341
|
BelongsTo: ae,
|
|
1339
1342
|
BelongsToMany: ue,
|
|
1340
|
-
HasOne:
|
|
1341
|
-
HasMany:
|
|
1342
|
-
MorphMany:
|
|
1343
|
-
MorphOne:
|
|
1344
|
-
MorphTo:
|
|
1345
|
-
MorphToMany:
|
|
1343
|
+
HasOne: ke,
|
|
1344
|
+
HasMany: Ae,
|
|
1345
|
+
MorphMany: Ne,
|
|
1346
|
+
MorphOne: qe,
|
|
1347
|
+
MorphTo: Ke,
|
|
1348
|
+
MorphToMany: je
|
|
1346
1349
|
}, t);
|
|
1347
1350
|
}
|
|
1348
1351
|
toString() {
|
|
1349
1352
|
return "model";
|
|
1350
1353
|
}
|
|
1351
1354
|
}
|
|
1352
|
-
const
|
|
1355
|
+
const Be = re(Oe);
|
|
1353
1356
|
var ee, te;
|
|
1354
|
-
class
|
|
1357
|
+
class Ce extends (te = Error, ee = Symbol.toStringTag, te) {
|
|
1355
1358
|
constructor(t) {
|
|
1356
1359
|
super(`[Luminix] Route "${t}" not found`);
|
|
1357
1360
|
g(this, ee, "RouteNotFoundException");
|
|
1358
1361
|
}
|
|
1359
1362
|
}
|
|
1360
|
-
class
|
|
1363
|
+
class Ie {
|
|
1361
1364
|
constructor(e, t, r, i = "") {
|
|
1362
1365
|
this.routes = e, this.error = t, this.http = r, this.appUrl = i;
|
|
1363
1366
|
}
|
|
@@ -1376,7 +1379,7 @@ class Ce {
|
|
|
1376
1379
|
}
|
|
1377
1380
|
get(e) {
|
|
1378
1381
|
if (!this.exists(e))
|
|
1379
|
-
throw new
|
|
1382
|
+
throw new Ce(e);
|
|
1380
1383
|
return p.get(this.routes, e);
|
|
1381
1384
|
}
|
|
1382
1385
|
url(e) {
|
|
@@ -1412,9 +1415,9 @@ class Ce {
|
|
|
1412
1415
|
const n = m[0] ?? s.method;
|
|
1413
1416
|
this.error.clear(r);
|
|
1414
1417
|
const a = await u[n](c);
|
|
1415
|
-
if (
|
|
1418
|
+
if (ge(a)) {
|
|
1416
1419
|
const h = a.json("errors");
|
|
1417
|
-
this.error.set(Object.entries(h).reduce((d, [
|
|
1420
|
+
this.error.set(Object.entries(h).reduce((d, [v, f]) => (d[v] = f.join(" "), d), {}), r);
|
|
1418
1421
|
} else a.failed() && this.error.set(
|
|
1419
1422
|
this.clientError({ axios: a.json("message") }, {
|
|
1420
1423
|
response: a,
|
|
@@ -1430,10 +1433,10 @@ class Ce {
|
|
|
1430
1433
|
return "route";
|
|
1431
1434
|
}
|
|
1432
1435
|
}
|
|
1433
|
-
const
|
|
1434
|
-
class
|
|
1436
|
+
const Pe = re(Ie);
|
|
1437
|
+
class Qe {
|
|
1435
1438
|
getClient() {
|
|
1436
|
-
return new
|
|
1439
|
+
return new ye();
|
|
1437
1440
|
}
|
|
1438
1441
|
baseUrl(e) {
|
|
1439
1442
|
return this.getClient().baseUrl(e);
|
|
@@ -1486,9 +1489,9 @@ class Pe {
|
|
|
1486
1489
|
return this.getClient().delete(e, t);
|
|
1487
1490
|
}
|
|
1488
1491
|
}
|
|
1489
|
-
const
|
|
1492
|
+
const Le = ne(Qe);
|
|
1490
1493
|
var se, ie;
|
|
1491
|
-
class
|
|
1494
|
+
class De extends (ie = me, se = Symbol.toStringTag, ie) {
|
|
1492
1495
|
constructor() {
|
|
1493
1496
|
super(...arguments);
|
|
1494
1497
|
g(this, se, "LuminixServiceProvider");
|
|
@@ -1502,24 +1505,24 @@ class Le extends (ie = ye, se = Symbol.toStringTag, ie) {
|
|
|
1502
1505
|
this.app.make("model").boot(this.app);
|
|
1503
1506
|
}
|
|
1504
1507
|
registerServices() {
|
|
1505
|
-
this.app.singleton("auth", () => new
|
|
1508
|
+
this.app.singleton("auth", () => new ve(
|
|
1506
1509
|
this.app.make("config"),
|
|
1507
1510
|
this.app.make("model"),
|
|
1508
1511
|
this.app.make("route")
|
|
1509
1512
|
)), this.app.singleton("config", () => {
|
|
1510
1513
|
const t = new _(p.omit(this.app.configuration, "manifest"));
|
|
1511
1514
|
return t.has("auth.user") || t.set("auth.user", null), t.lock("auth.user"), t;
|
|
1512
|
-
}), this.app.singleton("error", () => new
|
|
1515
|
+
}), this.app.singleton("error", () => new be()), this.app.singleton("http", () => new Le()), this.app.singleton("log", () => {
|
|
1513
1516
|
var t;
|
|
1514
|
-
return new
|
|
1517
|
+
return new xe(((t = this.app.configuration.app) == null ? void 0 : t.debug) ?? !1);
|
|
1515
1518
|
}), this.app.singleton("model", () => {
|
|
1516
1519
|
var t;
|
|
1517
|
-
return new
|
|
1520
|
+
return new Be(
|
|
1518
1521
|
((t = this.app.configuration.manifest) == null ? void 0 : t.models) ?? {}
|
|
1519
1522
|
);
|
|
1520
1523
|
}), this.app.singleton("route", () => {
|
|
1521
1524
|
var t, r;
|
|
1522
|
-
return new
|
|
1525
|
+
return new Pe(
|
|
1523
1526
|
((t = this.app.configuration.manifest) == null ? void 0 : t.routes) ?? {},
|
|
1524
1527
|
this.app.make("error"),
|
|
1525
1528
|
() => this.app.make("http"),
|
|
@@ -1533,13 +1536,13 @@ class Le extends (ie = ye, se = Symbol.toStringTag, ie) {
|
|
|
1533
1536
|
});
|
|
1534
1537
|
}
|
|
1535
1538
|
}
|
|
1536
|
-
class
|
|
1539
|
+
class He {
|
|
1537
1540
|
constructor() {
|
|
1538
1541
|
g(this, "app");
|
|
1539
1542
|
}
|
|
1540
1543
|
getFacadeAccessor() {
|
|
1541
|
-
return this.app || (this.app = new (ne(
|
|
1542
|
-
|
|
1544
|
+
return this.app || (this.app = new (ne(fe))([
|
|
1545
|
+
De
|
|
1543
1546
|
])), this.app;
|
|
1544
1547
|
}
|
|
1545
1548
|
down() {
|
|
@@ -1549,75 +1552,75 @@ class De {
|
|
|
1549
1552
|
this.down(), this.app = e;
|
|
1550
1553
|
}
|
|
1551
1554
|
}
|
|
1552
|
-
const x = M(
|
|
1555
|
+
const x = M(He);
|
|
1553
1556
|
function $(o = void 0) {
|
|
1554
1557
|
return typeof o != "string" ? x : x.make(o);
|
|
1555
1558
|
}
|
|
1556
|
-
function
|
|
1559
|
+
function Ze() {
|
|
1557
1560
|
return $("auth");
|
|
1558
1561
|
}
|
|
1559
|
-
function
|
|
1562
|
+
function et(o, e) {
|
|
1560
1563
|
const t = $("config");
|
|
1561
1564
|
return typeof o > "u" ? t : t.get(o, e);
|
|
1562
1565
|
}
|
|
1563
|
-
function
|
|
1566
|
+
function tt(o, e = "default") {
|
|
1564
1567
|
return o ? $().make("error").get(o, e) : $().make("error");
|
|
1565
1568
|
}
|
|
1566
|
-
function
|
|
1569
|
+
function st(...o) {
|
|
1567
1570
|
const e = $("log");
|
|
1568
1571
|
return o.length ? e.debug(...o) : e;
|
|
1569
1572
|
}
|
|
1570
|
-
function
|
|
1573
|
+
function it(o) {
|
|
1571
1574
|
const e = $("model");
|
|
1572
1575
|
return o ? e.make(o) : e;
|
|
1573
1576
|
}
|
|
1574
|
-
function
|
|
1577
|
+
function rt(o, e = !1) {
|
|
1575
1578
|
const t = $("route");
|
|
1576
1579
|
return o ? e ? t.url([o, e]) : t.url(o) : t;
|
|
1577
1580
|
}
|
|
1578
|
-
class He {
|
|
1579
|
-
getFacadeAccessor() {
|
|
1580
|
-
return "auth";
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
const rt = M(He, x);
|
|
1584
1581
|
class Je {
|
|
1585
1582
|
getFacadeAccessor() {
|
|
1586
|
-
return "
|
|
1583
|
+
return "auth";
|
|
1587
1584
|
}
|
|
1588
1585
|
}
|
|
1589
|
-
const nt = M(Je, x)
|
|
1586
|
+
const nt = M(Je, x);
|
|
1590
1587
|
class Ue {
|
|
1591
1588
|
getFacadeAccessor() {
|
|
1592
|
-
return "
|
|
1589
|
+
return "config";
|
|
1593
1590
|
}
|
|
1594
1591
|
}
|
|
1595
|
-
const
|
|
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"));
|
|
1596
1593
|
class Fe {
|
|
1597
1594
|
getFacadeAccessor() {
|
|
1598
|
-
return "
|
|
1595
|
+
return "error";
|
|
1599
1596
|
}
|
|
1600
1597
|
}
|
|
1601
1598
|
const ut = M(Fe, x);
|
|
1602
1599
|
class We {
|
|
1603
1600
|
getFacadeAccessor() {
|
|
1604
|
-
return "
|
|
1601
|
+
return "http";
|
|
1605
1602
|
}
|
|
1606
1603
|
}
|
|
1607
1604
|
const ht = M(We, x);
|
|
1608
1605
|
class Ge {
|
|
1609
1606
|
getFacadeAccessor() {
|
|
1610
|
-
return "
|
|
1607
|
+
return "log";
|
|
1611
1608
|
}
|
|
1612
1609
|
}
|
|
1613
1610
|
const lt = M(Ge, x);
|
|
1614
1611
|
class Ve {
|
|
1615
1612
|
getFacadeAccessor() {
|
|
1616
|
-
return "
|
|
1613
|
+
return "model";
|
|
1617
1614
|
}
|
|
1618
1615
|
}
|
|
1619
1616
|
const ct = M(Ve, x);
|
|
1620
|
-
class
|
|
1617
|
+
class ze {
|
|
1618
|
+
getFacadeAccessor() {
|
|
1619
|
+
return "route";
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
const dt = M(ze, x);
|
|
1623
|
+
class pt {
|
|
1621
1624
|
constructor() {
|
|
1622
1625
|
g(this, "name");
|
|
1623
1626
|
g(this, "version");
|
|
@@ -1629,21 +1632,21 @@ class dt {
|
|
|
1629
1632
|
}
|
|
1630
1633
|
export {
|
|
1631
1634
|
x as App,
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
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,
|
|
1640
1643
|
$ as app,
|
|
1641
|
-
|
|
1644
|
+
Ze as auth,
|
|
1642
1645
|
K as collect,
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1646
|
+
et as config,
|
|
1647
|
+
tt as error,
|
|
1648
|
+
at as isValidationError,
|
|
1649
|
+
st as log,
|
|
1650
|
+
it as model,
|
|
1651
|
+
rt as route
|
|
1649
1652
|
};
|