@luminix/core 1.0.1 → 1.0.3
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 +39 -39
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var ce = Object.defineProperty;
|
|
2
2
|
var de = (o, e, t) => e in o ? ce(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
3
|
var g = (o, e, t) => de(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import { reader as pe, PropertyBag as _, EventSource as k, Collection as b, Query as S, Obj as p, Str as
|
|
4
|
+
import { reader as pe, PropertyBag as _, EventSource as k, Collection as b, Query as S, Obj as p, Str as m, Reducible as re, isValidationError as ge, Macroable as ne, Client as ye, ServiceProvider as me, MakeFacade as M, Application as fe } from "@luminix/support";
|
|
5
5
|
class we {
|
|
6
6
|
constructor(e, t, r) {
|
|
7
7
|
g(this, "_user");
|
|
@@ -15,8 +15,8 @@ class we {
|
|
|
15
15
|
const u = document.createElement("input");
|
|
16
16
|
u.type = "hidden", u.name = "_token", u.value = l, i.appendChild(u);
|
|
17
17
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const y = document.createElement("input");
|
|
19
|
+
y.type = "email", y.name = "email", y.value = e.email, i.appendChild(y);
|
|
20
20
|
const c = document.createElement("input");
|
|
21
21
|
if (c.type = "password", c.name = "password", c.value = e.password, i.appendChild(c), t) {
|
|
22
22
|
const u = document.createElement("input");
|
|
@@ -153,7 +153,7 @@ class Me extends k {
|
|
|
153
153
|
return this.bag.set(`where.${t}`, r), this;
|
|
154
154
|
if (typeof r != "string")
|
|
155
155
|
throw new Error(`Invalid operator ${r} provided for where clause.`);
|
|
156
|
-
const
|
|
156
|
+
const y = {
|
|
157
157
|
"=": "",
|
|
158
158
|
"!=": "notEquals",
|
|
159
159
|
">": "greaterThan",
|
|
@@ -161,7 +161,7 @@ class Me extends k {
|
|
|
161
161
|
"<": "lessThan",
|
|
162
162
|
"<=": "lessThanOrEquals"
|
|
163
163
|
}[r] || r;
|
|
164
|
-
return this.bag.set(`where.${t}:${
|
|
164
|
+
return this.bag.set(`where.${t}:${y}`, i), this;
|
|
165
165
|
}
|
|
166
166
|
with(t) {
|
|
167
167
|
const r = this.bag.get("with", []);
|
|
@@ -182,7 +182,7 @@ class Me extends k {
|
|
|
182
182
|
return this.bag.set("order_by", `${t}:${r}`), this;
|
|
183
183
|
}
|
|
184
184
|
searchBy(t) {
|
|
185
|
-
return this.bag.set("q", t), this;
|
|
185
|
+
return t === "" ? (this.bag.delete("q"), this) : (this.bag.set("q", t), this);
|
|
186
186
|
}
|
|
187
187
|
minified() {
|
|
188
188
|
return this.bag.set("minified", 1), this;
|
|
@@ -208,8 +208,8 @@ class Me extends k {
|
|
|
208
208
|
const l = await this.services.route.call(
|
|
209
209
|
`luminix.${this.abstract}.index`,
|
|
210
210
|
(u) => u.withQueryParameters(this.bag.all())
|
|
211
|
-
),
|
|
212
|
-
const s = new
|
|
211
|
+
), y = this.services.model.make(this.abstract), c = new b(l.json("data").map((u) => {
|
|
212
|
+
const s = new y(u);
|
|
213
213
|
return s.exists = !0, this.services.model.emit("fetch", {
|
|
214
214
|
class: this.abstract,
|
|
215
215
|
model: s,
|
|
@@ -278,10 +278,10 @@ class Me extends k {
|
|
|
278
278
|
const t = this.services.config.get("luminix.backend.api.max_per_page", 150), r = await this.limit(t).exec(), i = r.meta.last_page;
|
|
279
279
|
if (i === 1)
|
|
280
280
|
return r.data;
|
|
281
|
-
const l = Array.from({ length: i - 1 }, (u, s) => s + 2),
|
|
281
|
+
const l = Array.from({ length: i - 1 }, (u, s) => s + 2), y = await Promise.all(
|
|
282
282
|
l.map((u) => this.limit(t).exec({ page: u }))
|
|
283
283
|
), c = new b(
|
|
284
|
-
|
|
284
|
+
y.reduce((u, s) => (u.push(...s.data), u), r.data).all()
|
|
285
285
|
);
|
|
286
286
|
return this.emit("success", {
|
|
287
287
|
response: {
|
|
@@ -321,11 +321,11 @@ class N {
|
|
|
321
321
|
throw new w("Relation.constructor()", "Model, Collection<Model> or null");
|
|
322
322
|
}
|
|
323
323
|
make(e) {
|
|
324
|
-
const t = this.getRelated();
|
|
325
324
|
if (e === null || typeof e > "u") {
|
|
326
325
|
this.set(null);
|
|
327
326
|
return;
|
|
328
327
|
}
|
|
328
|
+
const t = this.getRelated();
|
|
329
329
|
if (this.isSingle()) {
|
|
330
330
|
if (typeof e != "object" || Array.isArray(e))
|
|
331
331
|
throw new TypeError("Relation.make() expects an object");
|
|
@@ -460,8 +460,8 @@ class oe extends (W = Error, F = Symbol.toStringTag, W) {
|
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
462
|
function Se(o, e, t, r, i) {
|
|
463
|
-
var l,
|
|
464
|
-
return c = class extends (
|
|
463
|
+
var l, y, c;
|
|
464
|
+
return c = class extends (y = k, l = Symbol.toStringTag, y) {
|
|
465
465
|
constructor(s = {}) {
|
|
466
466
|
super();
|
|
467
467
|
g(this, "_attributes", new _({}));
|
|
@@ -470,7 +470,7 @@ function Se(o, e, t, r, i) {
|
|
|
470
470
|
g(this, "_changedKeys", []);
|
|
471
471
|
g(this, "exists", !1);
|
|
472
472
|
g(this, "wasRecentlyCreated", !1);
|
|
473
|
-
g(this, l,
|
|
473
|
+
g(this, l, m.studly(i));
|
|
474
474
|
this.makeRelations(), this.makeAttributes(s);
|
|
475
475
|
}
|
|
476
476
|
cast(s, n) {
|
|
@@ -501,8 +501,6 @@ function Se(o, e, t, r, i) {
|
|
|
501
501
|
};
|
|
502
502
|
if (this.fillable.filter(v).forEach((f) => {
|
|
503
503
|
d[f] = null;
|
|
504
|
-
}), n && Object.keys(n).forEach((f) => {
|
|
505
|
-
this.relation(y.camel(f)).make(s[f]);
|
|
506
504
|
}), !this.validateJsonObject(d)) {
|
|
507
505
|
if (o.get("app.env", "production") === "production")
|
|
508
506
|
throw new TypeError(`[Luminix] Invalid attributes for model "${i}"`);
|
|
@@ -512,7 +510,9 @@ function Se(o, e, t, r, i) {
|
|
|
512
510
|
abstract: i
|
|
513
511
|
});
|
|
514
512
|
}
|
|
515
|
-
this._attributes.set(".", d), this._original = d, this._changedKeys.splice(0, this._changedKeys.length)
|
|
513
|
+
this._attributes.set(".", d), this._original = d, this._changedKeys.splice(0, this._changedKeys.length), n && Object.keys(n).forEach((f) => {
|
|
514
|
+
this.relation(m.camel(f)).make(s[f]);
|
|
515
|
+
});
|
|
516
516
|
}
|
|
517
517
|
makePrimaryKeyReplacer() {
|
|
518
518
|
return {
|
|
@@ -632,13 +632,13 @@ function Se(o, e, t, r, i) {
|
|
|
632
632
|
getAttribute(s) {
|
|
633
633
|
let n = this._attributes.get(s, null);
|
|
634
634
|
s in this.casts && (n = this.cast(n, this.casts[s]));
|
|
635
|
-
const a = t[`model${
|
|
635
|
+
const a = t[`model${m.studly(i)}Get${m.studly(s)}Attribute`];
|
|
636
636
|
if (typeof a != "function")
|
|
637
637
|
throw new $("ModelFacade");
|
|
638
638
|
return a.bind(t)(n, this);
|
|
639
639
|
}
|
|
640
640
|
setAttribute(s, n) {
|
|
641
|
-
const h = t[`model${
|
|
641
|
+
const h = t[`model${m.studly(i)}Set${m.studly(s)}Attribute`].bind(t)(
|
|
642
642
|
this.mutate(n, this.casts[s]),
|
|
643
643
|
this
|
|
644
644
|
);
|
|
@@ -665,7 +665,7 @@ function Se(o, e, t, r, i) {
|
|
|
665
665
|
}
|
|
666
666
|
fill(s) {
|
|
667
667
|
const n = p.pick(s, ...this.fillable), a = Object.entries(n).reduce((h, [d, v]) => {
|
|
668
|
-
const f = t[`model${
|
|
668
|
+
const f = t[`model${m.studly(i)}Set${m.studly(d)}Attribute`];
|
|
669
669
|
if (typeof f != "function")
|
|
670
670
|
throw new $("ModelFacade");
|
|
671
671
|
return h[d] = f.bind(t)(
|
|
@@ -690,11 +690,11 @@ function Se(o, e, t, r, i) {
|
|
|
690
690
|
dump() {
|
|
691
691
|
e.info({
|
|
692
692
|
...this.toJson(),
|
|
693
|
-
[Symbol.toStringTag]:
|
|
693
|
+
[Symbol.toStringTag]: m.studly(i)
|
|
694
694
|
});
|
|
695
695
|
}
|
|
696
696
|
toJson() {
|
|
697
|
-
const s = Object.entries(this.relations).reduce((a, [h, d]) => (d.isLoaded() && (d.isSingle() ? a[
|
|
697
|
+
const s = Object.entries(this.relations).reduce((a, [h, d]) => (d.isLoaded() && (d.isSingle() ? a[m.snake(h)] = d.getLoadedItems().toJson() : d.isMultiple() && (a[m.snake(h)] = d.getLoadedItems().map((v) => v.toJson()).all())), a), {}), n = t[`model${m.studly(i)}Json`];
|
|
698
698
|
if (typeof n != "function")
|
|
699
699
|
throw new $("ModelFacade");
|
|
700
700
|
return n.bind(t)({
|
|
@@ -709,8 +709,8 @@ function Se(o, e, t, r, i) {
|
|
|
709
709
|
return i;
|
|
710
710
|
}
|
|
711
711
|
relation(s) {
|
|
712
|
-
if (s ===
|
|
713
|
-
return this.relations[
|
|
712
|
+
if (s === m.camel(s))
|
|
713
|
+
return this.relations[m.snake(s)];
|
|
714
714
|
}
|
|
715
715
|
getErrorBag(s) {
|
|
716
716
|
return `${this.exists ? `${i}[${this.getKey()}].` : `${i}.`}${s}`;
|
|
@@ -922,14 +922,14 @@ function Se(o, e, t, r, i) {
|
|
|
922
922
|
static plural() {
|
|
923
923
|
return t.schema(i).displayName.plural;
|
|
924
924
|
}
|
|
925
|
-
}, g(c, "name",
|
|
925
|
+
}, g(c, "name", m.studly(i)), c;
|
|
926
926
|
}
|
|
927
927
|
function _e(o, e, t) {
|
|
928
928
|
var r, i;
|
|
929
929
|
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
930
|
-
constructor(
|
|
931
|
-
super(
|
|
932
|
-
g(this, r,
|
|
930
|
+
constructor(y = {}) {
|
|
931
|
+
super(y);
|
|
932
|
+
g(this, r, m.studly(e));
|
|
933
933
|
return new Proxy(this, {
|
|
934
934
|
get: (c, u) => {
|
|
935
935
|
if (u === "__isModel")
|
|
@@ -940,10 +940,10 @@ function _e(o, e, t) {
|
|
|
940
940
|
return c.getAttribute(u);
|
|
941
941
|
if (Object.keys(c.relations).includes(u))
|
|
942
942
|
return c.relations[u].getLoadedItems();
|
|
943
|
-
if (u.endsWith("Relation") && Object.keys(c.relations).includes(
|
|
943
|
+
if (u.endsWith("Relation") && Object.keys(c.relations).includes(m.snake(u.slice(0, -8))))
|
|
944
944
|
return () => c.relation(u.slice(0, -8));
|
|
945
|
-
if (o.hasReducer(`model${
|
|
946
|
-
const s = o[`model${
|
|
945
|
+
if (o.hasReducer(`model${m.studly(c.getType())}Get${m.studly(u)}Attribute`)) {
|
|
946
|
+
const s = o[`model${m.studly(c.getType())}Get${m.studly(u)}Attribute`];
|
|
947
947
|
if (typeof s != "function")
|
|
948
948
|
throw new $("ModelFacade");
|
|
949
949
|
return s.bind(o)(void 0, c);
|
|
@@ -1299,7 +1299,7 @@ class Oe extends (Z = k, Y = Symbol.toStringTag, Z) {
|
|
|
1299
1299
|
}
|
|
1300
1300
|
boot(t) {
|
|
1301
1301
|
this._schema && Object.keys(this._schema).forEach((r) => {
|
|
1302
|
-
const i = this[`model${
|
|
1302
|
+
const i = this[`model${m.studly(r)}`], l = this.model(
|
|
1303
1303
|
Se(
|
|
1304
1304
|
t.make("config"),
|
|
1305
1305
|
t.make("log"),
|
|
@@ -1308,8 +1308,8 @@ class Oe extends (Z = k, Y = Symbol.toStringTag, Z) {
|
|
|
1308
1308
|
r
|
|
1309
1309
|
),
|
|
1310
1310
|
r
|
|
1311
|
-
),
|
|
1312
|
-
this._models[r] = _e(t.make("model"), r,
|
|
1311
|
+
), y = i(l);
|
|
1312
|
+
this._models[r] = _e(t.make("model"), r, y);
|
|
1313
1313
|
});
|
|
1314
1314
|
}
|
|
1315
1315
|
schema(t) {
|
|
@@ -1378,7 +1378,7 @@ class Ce {
|
|
|
1378
1378
|
throw new $("RouteFacade");
|
|
1379
1379
|
return this.replaceRouteParams(`/${i}`);
|
|
1380
1380
|
}
|
|
1381
|
-
const
|
|
1381
|
+
const y = i.match(l), c = y ? y.map((h) => h.slice(1, -1)) : [], u = Object.keys(r), s = c.filter((h) => !u.includes(h)), n = u.filter((h) => !c.includes(h));
|
|
1382
1382
|
if (s.length > 0)
|
|
1383
1383
|
throw new TypeError(`Missing values for parameter(s): ${s.join(", ")}`);
|
|
1384
1384
|
if (n.length > 0)
|
|
@@ -1396,9 +1396,9 @@ class Ce {
|
|
|
1396
1396
|
async call(e, t = (i) => i, r = "default") {
|
|
1397
1397
|
if (typeof this.clientOptions != "function" || typeof this.clientError != "function")
|
|
1398
1398
|
throw new $("RouteFacade");
|
|
1399
|
-
const [i, l] = this.extractGenerator(e), [, ...
|
|
1399
|
+
const [i, l] = this.extractGenerator(e), [, ...y] = this.get(i), c = this.url(l ? [i, l] : i), u = t(this.http()), s = this.clientOptions({}, i);
|
|
1400
1400
|
p.isEmpty(s) || u.withOptions(s);
|
|
1401
|
-
const n =
|
|
1401
|
+
const n = y[0] ?? s.method;
|
|
1402
1402
|
this.error.clear(r);
|
|
1403
1403
|
const a = await u[n](c);
|
|
1404
1404
|
if (ge(a)) {
|
|
@@ -1422,7 +1422,7 @@ class Ce {
|
|
|
1422
1422
|
const Ie = re(Ce);
|
|
1423
1423
|
class Pe {
|
|
1424
1424
|
getClient() {
|
|
1425
|
-
return new
|
|
1425
|
+
return new ye();
|
|
1426
1426
|
}
|
|
1427
1427
|
baseUrl(e) {
|
|
1428
1428
|
return this.getClient().baseUrl(e);
|
|
@@ -1477,7 +1477,7 @@ class Pe {
|
|
|
1477
1477
|
}
|
|
1478
1478
|
const Qe = ne(Pe);
|
|
1479
1479
|
var se, ie;
|
|
1480
|
-
class Le extends (ie =
|
|
1480
|
+
class Le extends (ie = me, se = Symbol.toStringTag, ie) {
|
|
1481
1481
|
constructor() {
|
|
1482
1482
|
super(...arguments);
|
|
1483
1483
|
g(this, se, "LuminixServiceProvider");
|