@luminix/core 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -1,8 +1,8 @@
1
- var ce = Object.defineProperty;
2
- var de = (n, t, e) => t in n ? ce(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var p = (n, t, e) => de(n, typeof t != "symbol" ? t + "" : t, e);
4
- import { reader as pe, PropertyBag as R, EventSource as q, Collection as x, Query as T, Obj as m, Str as y, Reducible as ne, isValidationError as ge, Macroable as oe, Client as ye, ServiceProvider as me, MakeFacade as E, Application as fe, Response as we } from "@luminix/support";
5
- class ve {
1
+ var he = Object.defineProperty;
2
+ var le = (o, t, e) => t in o ? he(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
+ var p = (o, t, e) => le(o, typeof t != "symbol" ? t + "" : t, e);
4
+ import { reader as ce, PropertyBag as _, EventSource as A, Collection as b, Query as S, Obj as d, Str as m, Reducible as re, isValidationError as de, Macroable as ie, Client as pe, ServiceProvider as ge, MakeFacade as M, Application as ye, Response as me } from "@luminix/support";
5
+ class fe {
6
6
  constructor(t, e, i) {
7
7
  p(this, "_user");
8
8
  this.config = t, this.model = e, this.route = i;
@@ -15,8 +15,8 @@ class ve {
15
15
  const u = document.createElement("input");
16
16
  u.type = "hidden", u.name = "_token", u.value = c, s.appendChild(u);
17
17
  }
18
- const g = document.createElement("input");
19
- g.type = "email", g.name = "email", g.value = t.email, s.appendChild(g);
18
+ const y = document.createElement("input");
19
+ y.type = "email", y.name = "email", y.value = t.email, s.appendChild(y);
20
20
  const l = document.createElement("input");
21
21
  if (l.type = "password", l.name = "password", l.value = t.password, s.appendChild(l), e) {
22
22
  const u = document.createElement("input");
@@ -51,19 +51,19 @@ class ve {
51
51
  return ((t = this.user()) == null ? void 0 : t.getKey()) || null;
52
52
  }
53
53
  }
54
- class be {
54
+ class we {
55
55
  constructor() {
56
56
  p(this, "bags");
57
57
  const t = {};
58
58
  document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((i) => {
59
59
  const c = i.id.replace("luminix-error::", "");
60
- t[c] = pe(c, "error");
60
+ t[c] = ce(c, "error");
61
61
  }), this.bags = {
62
- default: new R(t)
62
+ default: new _(t)
63
63
  };
64
64
  }
65
65
  bag(t = "default") {
66
- return this.bags[t] || (this.bags[t] = new R({})), this.bags[t];
66
+ return this.bags[t] || (this.bags[t] = new _({})), this.bags[t];
67
67
  }
68
68
  add(t, e, i = "default") {
69
69
  this.bag(i).set(t, e);
@@ -81,7 +81,7 @@ class be {
81
81
  this.bag(t).set(".", {});
82
82
  }
83
83
  }
84
- class xe {
84
+ class ve {
85
85
  constructor(t) {
86
86
  this._debug = t;
87
87
  }
@@ -110,18 +110,18 @@ class xe {
110
110
  this._debug && console.debug(...t);
111
111
  }
112
112
  }
113
- var O, B;
114
- class Me extends (B = Error, O = Symbol.toStringTag, B) {
113
+ var k, j;
114
+ class be extends (j = Error, k = Symbol.toStringTag, j) {
115
115
  constructor(e) {
116
116
  super(`[Luminix] Model "${e}" does not have a primary key`);
117
- p(this, O, "ModelWithoutPrimaryKeyException");
117
+ p(this, k, "ModelWithoutPrimaryKeyException");
118
118
  }
119
119
  }
120
- class Ee extends q {
120
+ class xe extends A {
121
121
  constructor(e, i, s = {}) {
122
122
  super();
123
123
  p(this, "bag");
124
- this.services = e, this.abstract = i, this.query = s, this.bag = new R(s), this.bag.on("change", () => {
124
+ this.services = e, this.abstract = i, this.bag = new _(s), this.bag.on("change", () => {
125
125
  this.emit("change", {
126
126
  data: this.bag,
127
127
  source: this
@@ -153,7 +153,7 @@ class Ee extends q {
153
153
  return this.bag.set(`where.${e}`, i), this;
154
154
  if (typeof i != "string")
155
155
  throw new Error(`Invalid operator ${i} provided for where clause.`);
156
- const g = {
156
+ const y = {
157
157
  "=": "",
158
158
  "!=": "notEquals",
159
159
  ">": "greaterThan",
@@ -161,7 +161,7 @@ class Ee extends q {
161
161
  "<": "lessThan",
162
162
  "<=": "lessThanOrEquals"
163
163
  }[i] || i;
164
- return this.bag.set(`where.${e}:${g}`, s), this;
164
+ return this.bag.set(`where.${e}:${y}`, s), this;
165
165
  }
166
166
  with(e) {
167
167
  const i = this.bag.get("with", []);
@@ -204,7 +204,7 @@ class Ee extends q {
204
204
  const s = await this.services.route.call(
205
205
  `luminix.${this.abstract}.index`,
206
206
  (l) => l.withQueryParameters(this.bag.all())
207
- ), c = this.services.model.make(this.abstract), g = new x(s.json("data").map((l) => {
207
+ ), c = this.services.model.make(this.abstract), y = new b(s.json("data").map((l) => {
208
208
  const u = new c(l);
209
209
  return u.exists = !0, this.services.model.emit("fetch", {
210
210
  class: this.abstract,
@@ -216,25 +216,25 @@ class Ee extends q {
216
216
  const [l] = i.split("?");
217
217
  return {
218
218
  ...s.json(),
219
- data: g,
219
+ data: y,
220
220
  links: {
221
- first: `${l}?${T.merge(i, s.json("links").first).toString()}`,
222
- last: `${l}?${T.merge(i, s.json("links").last).toString()}`,
223
- next: s.json("links").next && `${l}?${T.merge(i, s.json("links").next ?? "").toString()}`,
224
- prev: s.json("links").prev && `${l}?${T.merge(i, s.json("links").prev ?? "").toString()}`
221
+ first: `${l}?${S.merge(i, s.json("links").first).toString()}`,
222
+ last: `${l}?${S.merge(i, s.json("links").last).toString()}`,
223
+ next: s.json("links").next && `${l}?${S.merge(i, s.json("links").next ?? "").toString()}`,
224
+ prev: s.json("links").prev && `${l}?${S.merge(i, s.json("links").prev ?? "").toString()}`
225
225
  },
226
226
  meta: {
227
227
  ...s.json("meta"),
228
228
  links: s.json("meta").links.map((u) => ({
229
229
  ...u,
230
- url: u.url && `${l}?${T.merge(i, u.url).toString()}`
230
+ url: u.url && `${l}?${S.merge(i, u.url).toString()}`
231
231
  }))
232
232
  }
233
233
  };
234
234
  }
235
235
  return {
236
236
  ...s.json(),
237
- data: g
237
+ data: y
238
238
  };
239
239
  } catch (s) {
240
240
  throw this.emit("error", {
@@ -262,7 +262,7 @@ class Ee extends q {
262
262
  async find(e) {
263
263
  const i = this.services.model.schema(this.abstract).primaryKey;
264
264
  if (!i)
265
- throw new Me(this.abstract);
265
+ throw new be(this.abstract);
266
266
  const s = await this.where(i, e).limit(1).exec(1);
267
267
  return this.emit("success", {
268
268
  response: s,
@@ -274,10 +274,10 @@ class Ee extends q {
274
274
  const e = this.services.config.get("luminix.backend.api.max_per_page", 150), i = await this.limit(e).exec(1), s = i.meta.last_page;
275
275
  if (s === 1)
276
276
  return i.data;
277
- const c = Array.from({ length: s - 1 }, (u, r) => r + 2), g = await Promise.all(
277
+ const c = Array.from({ length: s - 1 }, (u, r) => r + 2), y = await Promise.all(
278
278
  c.map((u) => this.limit(e).exec(u))
279
- ), l = new x(
280
- g.reduce((u, r) => (u.push(...r.data), u), i.data).all()
279
+ ), l = new b(
280
+ y.reduce((u, r) => (u.push(...r.data), u), i.data).all()
281
281
  );
282
282
  return this.emit("success", {
283
283
  response: {
@@ -289,35 +289,32 @@ class Ee extends q {
289
289
  }), l;
290
290
  }
291
291
  }
292
- var C, I;
293
- class w extends (I = TypeError, C = Symbol.toStringTag, I) {
292
+ var O, B;
293
+ class f extends (B = TypeError, O = Symbol.toStringTag, B) {
294
294
  constructor(e, i = "Model") {
295
295
  super(`[Luminix] "${e}" expects ${i}`);
296
- p(this, C, "NotModelException");
296
+ p(this, O, "NotModelException");
297
297
  }
298
298
  }
299
- var P, Q;
300
- class $e extends (Q = Error, P = Symbol.toStringTag, Q) {
299
+ var C, I;
300
+ class Me extends (I = Error, C = Symbol.toStringTag, I) {
301
301
  constructor(e, i, s, c) {
302
302
  super(`[Luminix] Could not determine inverse relation for "${i}" in model "${e}". Please specify a relation in model "${s}" of type ${c} that points back to "${e}".`);
303
- p(this, P, "NoInverseRelationException");
303
+ p(this, C, "NoInverseRelationException");
304
304
  }
305
305
  }
306
- var D, H;
307
- class _e extends (H = Error, D = Symbol.toStringTag, H) {
306
+ var P, Q;
307
+ class Ee extends (Q = Error, P = Symbol.toStringTag, Q) {
308
308
  constructor(e) {
309
309
  super(`[Luminix] Relation "${e}" is not supported`);
310
- p(this, D, "UnsupportedRelationException");
310
+ p(this, P, "UnsupportedRelationException");
311
311
  }
312
312
  }
313
- function f(n) {
314
- return typeof n == "object" && n !== null && n.__isModel === !0;
315
- }
316
- class N {
313
+ class R {
317
314
  constructor(t, e, i, s = null) {
318
315
  p(this, "unsubscribeQuery", null);
319
- if (this.services = t, this.meta = e, this.parent = i, this.items = s, s !== null && !m.isModel(s) && !(s instanceof x && s.every(f)))
320
- throw new w("Relation.constructor()", "Model, Collection<Model> or null");
316
+ if (this.services = t, this.meta = e, this.parent = i, this.items = s, s !== null && !d.isModel(s) && !(s instanceof b && s.every(d.isModel)))
317
+ throw new f("Relation.constructor()", "Model, Collection<Model> or null");
321
318
  }
322
319
  make(t) {
323
320
  const e = this.getRelated();
@@ -333,7 +330,7 @@ class N {
333
330
  if (this.isMultiple()) {
334
331
  if (!Array.isArray(t))
335
332
  throw new TypeError("Relation.make() expects an array");
336
- this.set(new x(t.map((i) => new e(i))));
333
+ this.set(new b(t.map((i) => new e(i))));
337
334
  }
338
335
  }
339
336
  guessInverseRelation() {
@@ -348,18 +345,18 @@ class N {
348
345
  MorphToMany: ["MorphToMany"]
349
346
  }, this.parent, e, this.getRelated());
350
347
  if (!(e in i))
351
- throw new _e(e);
348
+ throw new Ee(e);
352
349
  for (const s in t) {
353
350
  const c = t[s];
354
351
  if ((c.model === this.parent.getType() || ["MorphOne", "MorphMany"].includes(e)) && i[e].includes(c.type))
355
352
  return s;
356
353
  }
357
- throw new $e(this.parent.getType(), e, this.getRelated().getSchemaName(), i[e].join(" or "));
354
+ throw new Me(this.parent.getType(), e, this.getRelated().getSchemaName(), i[e].join(" or "));
358
355
  }
359
356
  set(t) {
360
- if (t !== null && !f(t) && !(t instanceof x && t.every(f)))
361
- throw new w("Relation.set()", "Model, Collection<Model> or null");
362
- !this.items || f(this.items) ? this.items = t : t instanceof x && this.items.splice(0, this.items.count(), ...t);
357
+ if (t !== null && !d.isModel(t) && !(t instanceof b && t.every(d.isModel)))
358
+ throw new f("Relation.set()", "Model, Collection<Model> or null");
359
+ !this.items || d.isModel(this.items) ? this.items = t : t instanceof b && this.items.splice(0, this.items.count(), ...t);
363
360
  }
364
361
  getForeignKey() {
365
362
  return this.meta.foreignKey;
@@ -389,10 +386,10 @@ class N {
389
386
  return this.items;
390
387
  }
391
388
  isSingle() {
392
- return f(this.items);
389
+ return d.isModel(this.items);
393
390
  }
394
391
  isMultiple() {
395
- return this.items instanceof x;
392
+ return this.items instanceof b;
396
393
  }
397
394
  getParent() {
398
395
  return this.parent;
@@ -437,55 +434,55 @@ class N {
437
434
  // return this.query().find(id);
438
435
  // }
439
436
  }
440
- var L, J;
441
- class $ extends (J = Error, L = Symbol.toStringTag, J) {
437
+ var D, H;
438
+ class E extends (H = Error, D = Symbol.toStringTag, H) {
442
439
  constructor(e) {
443
440
  super(`[Luminix] Expected ${e} to be reducible.`);
444
- p(this, L, "NotReducibleException");
441
+ p(this, D, "NotReducibleException");
445
442
  }
446
443
  }
447
- var U, F;
448
- class Se extends (F = Error, U = Symbol.toStringTag, F) {
444
+ var L, J;
445
+ class $e extends (J = Error, L = Symbol.toStringTag, J) {
449
446
  constructor() {
450
447
  super("[Luminix] Method not implemented.");
451
- p(this, U, "MethodNotImplementedException");
448
+ p(this, L, "MethodNotImplementedException");
452
449
  }
453
450
  }
454
- var G, V;
455
- class ae extends (V = Error, G = Symbol.toStringTag, V) {
451
+ var U, F;
452
+ class ne extends (F = Error, U = Symbol.toStringTag, F) {
456
453
  constructor(e, i) {
457
454
  super(`[Luminix] Model "${e}" must be persisted before calling "${i}"`);
458
- p(this, G, "ModelNotPersistedException");
455
+ p(this, U, "ModelNotPersistedException");
459
456
  }
460
457
  }
461
- function Te(n, t, e, i, s) {
462
- var c, g, l;
463
- return l = class extends (g = q, c = Symbol.toStringTag, g) {
458
+ function Se(o, t, e, i, s) {
459
+ var c, y, l;
460
+ return l = class extends (y = A, c = Symbol.toStringTag, y) {
464
461
  constructor(r = {}) {
465
462
  super();
466
- p(this, "_attributes", new R({}));
463
+ p(this, "_attributes", new _({}));
467
464
  p(this, "_original", {});
468
465
  p(this, "_relations", {});
469
466
  p(this, "_changedKeys", []);
470
467
  p(this, "exists", !1);
471
468
  p(this, "wasRecentlyCreated", !1);
472
- p(this, c, y.studly(s));
469
+ p(this, c, m.studly(s));
473
470
  this.makeRelations(), this.makeAttributes(r);
474
471
  }
475
- cast(r, o) {
476
- return r == null || !o ? r : ["boolean", "bool"].includes(o) ? !!r : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(o) && typeof r == "string" ? new Date(r) : ["float", "double", "integer", "int"].includes(o) || o.startsWith("decimal:") ? Number(r) : r;
472
+ cast(r, n) {
473
+ return r == null || !n ? r : ["boolean", "bool"].includes(n) ? !!r : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(n) && typeof r == "string" ? new Date(r) : ["float", "double", "integer", "int"].includes(n) || n.startsWith("decimal:") ? Number(r) : r;
477
474
  }
478
- mutate(r, o) {
479
- return r == null || !o ? r : ["boolean", "bool"].includes(o) ? !!r : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(o) && r instanceof Date ? r.toISOString() : ["float", "double", "integer", "int"].includes(o) || o.startsWith("decimal:") ? Number(r) : r;
475
+ mutate(r, n) {
476
+ return r == null || !n ? r : ["boolean", "bool"].includes(n) ? !!r : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(n) && r instanceof Date ? r.toISOString() : ["float", "double", "integer", "int"].includes(n) || n.startsWith("decimal:") ? Number(r) : r;
480
477
  }
481
478
  makeRelations() {
482
479
  const { relations: r } = e.schema(s);
483
480
  if (this._relations = {}, !r)
484
481
  return;
485
- const o = e.getRelationConstructors(s);
482
+ const n = e.getRelationConstructors(s);
486
483
  Object.entries(r).forEach(([a, h]) => {
487
- const { type: d } = h, v = d in o ? o[d] : N;
488
- this._relations[a] = new v(
484
+ const { type: g } = h, w = g in n ? n[g] : R;
485
+ this._relations[a] = new w(
489
486
  { model: e, route: i },
490
487
  { name: a, ...h },
491
488
  this,
@@ -494,13 +491,13 @@ function Te(n, t, e, i, s) {
494
491
  });
495
492
  }
496
493
  makeAttributes(r) {
497
- const { relations: o } = e.schema(s), a = Object.keys(o || {}), h = m.omit(r, ...a);
498
- if (this.fillable.filter((d) => !(d in h)).forEach((d) => {
499
- h[d] = null;
500
- }), o && Object.keys(o).forEach((d) => {
501
- this.relation(y.camel(d)).make(r[d]);
494
+ const { relations: n } = e.schema(s), a = Object.keys(n || {}), h = d.omit(r, ...a);
495
+ if (this.fillable.filter((g) => !(g in h)).forEach((g) => {
496
+ h[g] = null;
497
+ }), n && Object.keys(n).forEach((g) => {
498
+ this.relation(m.camel(g)).make(r[g]);
502
499
  }), !this.validateJsonObject(h)) {
503
- if (n.get("app.env", "production") === "production")
500
+ if (o.get("app.env", "production") === "production")
504
501
  throw new TypeError(`[Luminix] Invalid attributes for model "${s}"`);
505
502
  t.warning(`Invalid attributes for model "${s}".
506
503
  This will throw an error in production.`, {
@@ -573,25 +570,25 @@ function Te(n, t, e, i, s) {
573
570
  source: e
574
571
  });
575
572
  }
576
- dispatchErrorEvent(r, o) {
573
+ dispatchErrorEvent(r, n) {
577
574
  this.emit("error", {
578
575
  error: r,
579
- operation: o,
576
+ operation: n,
580
577
  source: this
581
578
  }), e.emit("error", {
582
579
  class: s,
583
580
  model: this,
584
581
  source: e,
585
582
  error: r,
586
- operation: o
583
+ operation: n
587
584
  });
588
585
  }
589
586
  updateChangedKeys(r) {
590
- const o = (a, h) => typeof a == "object" && a !== null ? m.isEqual(a, h) : a == h;
591
- !this._changedKeys.includes(r) && !o(m.get(this._original, r), this._attributes.get(r)) ? this._changedKeys.push(r) : this._changedKeys.includes(r) && o(m.get(this._original, r), this._attributes.get(r)) && this._changedKeys.splice(this._changedKeys.indexOf(r), 1);
587
+ const n = (a, h) => typeof a == "object" && a !== null ? d.isEqual(a, h) : a == h;
588
+ !this._changedKeys.includes(r) && !n(d.get(this._original, r), this._attributes.get(r)) ? this._changedKeys.push(r) : this._changedKeys.includes(r) && n(d.get(this._original, r), this._attributes.get(r)) && this._changedKeys.splice(this._changedKeys.indexOf(r), 1);
592
589
  }
593
590
  validateJsonObject(r) {
594
- return typeof r != "object" || r === null ? !1 : Object.entries(r).every(([, o]) => ["boolean", "number", "string"].includes(typeof o) || o === null || this.validateJsonObject(o) || Array.isArray(o) && o.every((a) => this.validateJsonObject(a)));
591
+ return typeof r != "object" || r === null ? !1 : Object.entries(r).every(([, n]) => ["boolean", "number", "string"].includes(typeof n) || n === null || this.validateJsonObject(n) || Array.isArray(n) && n.every((a) => this.validateJsonObject(a)));
595
592
  }
596
593
  get attributes() {
597
594
  return this._attributes.all();
@@ -625,28 +622,28 @@ function Te(n, t, e, i, s) {
625
622
  return this._changedKeys.length > 0;
626
623
  }
627
624
  getAttribute(r) {
628
- let o = this._attributes.get(r, null);
629
- r in this.casts && (o = this.cast(o, this.casts[r]));
630
- const a = e[`model${y.studly(s)}Get${y.studly(r)}Attribute`];
625
+ let n = this._attributes.get(r, null);
626
+ r in this.casts && (n = this.cast(n, this.casts[r]));
627
+ const a = e[`model${m.studly(s)}Get${m.studly(r)}Attribute`];
631
628
  if (typeof a != "function")
632
- throw new $("ModelFacade");
633
- return a.bind(e)(o, this);
629
+ throw new E("ModelFacade");
630
+ return a.bind(e)(n, this);
634
631
  }
635
- setAttribute(r, o) {
636
- const a = e[`model${y.studly(s)}Set${y.studly(r)}Attribute`];
632
+ setAttribute(r, n) {
633
+ const a = e[`model${m.studly(s)}Set${m.studly(r)}Attribute`];
637
634
  if (typeof a != "function")
638
- throw new $("ModelFacade");
635
+ throw new E("ModelFacade");
639
636
  const h = a.bind(e)(
640
- this.mutate(o, this.casts[r]),
637
+ this.mutate(n, this.casts[r]),
641
638
  this
642
639
  );
643
640
  if (!this.validateJsonObject({ [r]: h })) {
644
- if (n.get("app.env", "production") === "production")
641
+ if (o.get("app.env", "production") === "production")
645
642
  throw new TypeError(`[Luminix] Attribute "${r}" in model "${s}" must be a boolean, number, string or null`);
646
643
  t.warning(`Invalid type for attribute "${r}" in model "${s}" after mutation.
647
644
  This will throw an error in production.`, {
648
645
  key: r,
649
- value: o,
646
+ value: n,
650
647
  mutated: h,
651
648
  cast: this.casts[r],
652
649
  item: this.toJson()
@@ -662,17 +659,17 @@ function Te(n, t, e, i, s) {
662
659
  return this.primaryKey;
663
660
  }
664
661
  fill(r) {
665
- const o = m.pick(r, ...this.fillable), a = Object.entries(o).reduce((h, [d, v]) => {
666
- const b = e[`model${y.studly(s)}Set${y.studly(d)}Attribute`];
667
- if (typeof b != "function")
668
- throw new $("ModelFacade");
669
- return h[d] = b.bind(e)(
670
- this.mutate(v, this.casts[d]),
662
+ const n = d.pick(r, ...this.fillable), a = Object.entries(n).reduce((h, [g, w]) => {
663
+ const v = e[`model${m.studly(s)}Set${m.studly(g)}Attribute`];
664
+ if (typeof v != "function")
665
+ throw new E("ModelFacade");
666
+ return h[g] = v.bind(e)(
667
+ this.mutate(w, this.casts[g]),
671
668
  this
672
669
  ), h;
673
670
  }, {});
674
671
  if (!this.validateJsonObject(a)) {
675
- if (n.get("app.env", "production") === "production")
672
+ if (o.get("app.env", "production") === "production")
676
673
  throw new TypeError(`[Luminix] Invalid attributes for model "${s}"`);
677
674
  t.warning(`Invalid attributes for model "${s}" after mutation.
678
675
  This will throw an error in production.`, {
@@ -688,27 +685,27 @@ function Te(n, t, e, i, s) {
688
685
  dump() {
689
686
  t.info({
690
687
  ...this.toJson(),
691
- [Symbol.toStringTag]: y.studly(s)
688
+ [Symbol.toStringTag]: m.studly(s)
692
689
  });
693
690
  }
694
691
  toJson() {
695
- const r = 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), {}), o = e[`model${y.studly(s)}Json`];
696
- if (typeof o != "function")
697
- throw new $("ModelFacade");
698
- return o.bind(e)({
692
+ const r = Object.entries(this.relations).reduce((a, [h, g]) => (g.isLoaded() && (g.isSingle() ? a[m.snake(h)] = g.getLoadedItems().toJson() : g.isMultiple() && (a[m.snake(h)] = g.getLoadedItems().map((w) => w.toJson()).all())), a), {}), n = e[`model${m.studly(s)}Json`];
693
+ if (typeof n != "function")
694
+ throw new E("ModelFacade");
695
+ return n.bind(e)({
699
696
  ...this.attributes,
700
697
  ...r
701
698
  }, this);
702
699
  }
703
700
  diff() {
704
- return this._changedKeys.reduce((r, o) => (r[o] = this._attributes.get(o), r), {});
701
+ return this._changedKeys.reduce((r, n) => (r[n] = this._attributes.get(n), r), {});
705
702
  }
706
703
  getType() {
707
704
  return s;
708
705
  }
709
706
  relation(r) {
710
- if (r === y.camel(r))
711
- return this.relations[y.snake(r)];
707
+ if (r === m.camel(r))
708
+ return this.relations[m.snake(r)];
712
709
  }
713
710
  getErrorBag(r) {
714
711
  return `${this.exists ? `${s}[${this.getKey()}].` : `${s}.`}${r}`;
@@ -743,42 +740,42 @@ function Te(n, t, e, i, s) {
743
740
  }
744
741
  async refresh(r) {
745
742
  if (!this.exists)
746
- throw new ae(s, "refresh");
747
- const o = await i.call(
743
+ throw new ne(s, "refresh");
744
+ const n = await i.call(
748
745
  this.getRouteForRefresh(),
749
746
  r,
750
747
  this.getErrorBag("fetch")
751
748
  );
752
- this.makeAttributes(o.json());
749
+ this.makeAttributes(n.json());
753
750
  }
754
- async save(r = {}, o) {
751
+ async save(r = {}, n) {
755
752
  try {
756
753
  const {
757
754
  additionalPayload: a = {},
758
755
  sendsOnlyModifiedFields: h = !0
759
- } = r, d = this.exists, v = {
760
- ...m.pick(
761
- h && d ? this.diff() : this.attributes,
756
+ } = r, g = this.exists, w = {
757
+ ...d.pick(
758
+ h && g ? this.diff() : this.attributes,
762
759
  ...this.fillable
763
760
  ),
764
761
  ...a
765
762
  };
766
- if (m.isEmpty(v))
763
+ if (d.isEmpty(w))
767
764
  return;
768
- const b = await i.call(
765
+ const v = await i.call(
769
766
  this.getRouteForSave(),
770
- (k) => o ? o(k.withData(v)) : k.withData(v),
771
- this.getErrorBag(d ? "update" : "store")
767
+ (q) => n ? n(q.withData(w)) : q.withData(w),
768
+ this.getErrorBag(g ? "update" : "store")
772
769
  );
773
- if (b.successful())
774
- return this.makeAttributes(b.json()), this.exists = !0, this.dispatchSaveEvent(), d ? this.dispatchUpdateEvent(b.json()) : (this.wasRecentlyCreated = !0, this.dispatchCreateEvent(b.json())), b;
775
- throw b;
770
+ if (v.successful())
771
+ return this.makeAttributes(v.json()), this.exists = !0, this.dispatchSaveEvent(), g ? this.dispatchUpdateEvent(v.json()) : (this.wasRecentlyCreated = !0, this.dispatchCreateEvent(v.json())), v;
772
+ throw v;
776
773
  } catch (a) {
777
774
  throw this.dispatchErrorEvent(a, "save"), a;
778
775
  }
779
776
  }
780
777
  async push() {
781
- throw new Se();
778
+ throw new $e();
782
779
  }
783
780
  async delete() {
784
781
  try {
@@ -794,11 +791,11 @@ function Te(n, t, e, i, s) {
794
791
  throw this.dispatchErrorEvent(r, "delete"), r;
795
792
  }
796
793
  }
797
- async update(r, o) {
794
+ async update(r, n) {
798
795
  try {
799
796
  const a = await i.call(
800
797
  this.getRouteForUpdate(),
801
- (h) => o ? o(h.withData(r)) : h.withData(r),
798
+ (h) => n ? n(h.withData(r)) : h.withData(r),
802
799
  this.getErrorBag("update")
803
800
  );
804
801
  if (a.ok()) {
@@ -814,7 +811,7 @@ function Te(n, t, e, i, s) {
814
811
  try {
815
812
  const r = await i.call(
816
813
  this.getRouteForDelete(),
817
- (o) => o.withQueryParameters({ force: !0 }),
814
+ (n) => n.withQueryParameters({ force: !0 }),
818
815
  this.getErrorBag("forceDelete")
819
816
  );
820
817
  if (r.noContent())
@@ -828,7 +825,7 @@ function Te(n, t, e, i, s) {
828
825
  try {
829
826
  const r = await i.call(
830
827
  this.getRouteForUpdate(),
831
- (o) => o.withQueryParameters({ restore: !0 }),
828
+ (n) => n.withQueryParameters({ restore: !0 }),
832
829
  this.getErrorBag("restore")
833
830
  );
834
831
  if (r.ok())
@@ -845,8 +842,8 @@ function Te(n, t, e, i, s) {
845
842
  return e.schema(s);
846
843
  }
847
844
  static query() {
848
- return new Ee(
849
- { config: n, route: i, model: e },
845
+ return new xe(
846
+ { config: o, route: i, model: e },
850
847
  s
851
848
  );
852
849
  }
@@ -859,14 +856,14 @@ function Te(n, t, e, i, s) {
859
856
  static whereNotNull(r) {
860
857
  return this.query().whereNotNull(r);
861
858
  }
862
- static whereBetween(r, o) {
863
- return this.query().whereBetween(r, o);
859
+ static whereBetween(r, n) {
860
+ return this.query().whereBetween(r, n);
864
861
  }
865
- static whereNotBetween(r, o) {
866
- return this.query().whereNotBetween(r, o);
862
+ static whereNotBetween(r, n) {
863
+ return this.query().whereNotBetween(r, n);
867
864
  }
868
- static orderBy(r, o = "asc") {
869
- return this.query().orderBy(r, o);
865
+ static orderBy(r, n = "asc") {
866
+ return this.query().orderBy(r, n);
870
867
  }
871
868
  static searchBy(r) {
872
869
  return this.query().searchBy(r);
@@ -877,8 +874,8 @@ function Te(n, t, e, i, s) {
877
874
  static limit(r) {
878
875
  return this.query().limit(r);
879
876
  }
880
- static get(r = 1, o) {
881
- return this.query().get(r, o);
877
+ static get(r = 1, n) {
878
+ return this.query().get(r, n);
882
879
  }
883
880
  static find(r) {
884
881
  return this.query().find(r);
@@ -887,12 +884,12 @@ function Te(n, t, e, i, s) {
887
884
  return this.query().first();
888
885
  }
889
886
  static async create(r) {
890
- const o = e.make(s), a = new o();
887
+ const n = e.make(s), a = new n();
891
888
  return a.fill(r), await a.save(), a;
892
889
  }
893
- static async update(r, o) {
890
+ static async update(r, n) {
894
891
  const a = e.make(s), h = new a({ id: r });
895
- return h.fill(o), h.exists = !0, await h.save(), h;
892
+ return h.fill(n), h.exists = !0, await h.save(), h;
896
893
  }
897
894
  static delete(r) {
898
895
  if (Array.isArray(r))
@@ -901,8 +898,8 @@ function Te(n, t, e, i, s) {
901
898
  (h) => h.withQueryParameters({ ids: r }),
902
899
  `${s}.deleteMany`
903
900
  );
904
- const o = e.make(s);
905
- return new o({ id: r }).delete();
901
+ const n = e.make(s);
902
+ return new n({ id: r }).delete();
906
903
  }
907
904
  static async restore(r) {
908
905
  if (Array.isArray(r))
@@ -911,8 +908,8 @@ function Te(n, t, e, i, s) {
911
908
  (h) => h.withData({ ids: r }),
912
909
  `${s}.restoreMany`
913
910
  );
914
- const o = e.make(s);
915
- return new o({ id: r }).restore();
911
+ const n = e.make(s);
912
+ return new n({ id: r }).restore();
916
913
  }
917
914
  static forceDelete(r) {
918
915
  if (Array.isArray(r))
@@ -921,8 +918,8 @@ function Te(n, t, e, i, s) {
921
918
  (h) => h.withQueryParameters({ ids: r, force: !0 }),
922
919
  `${s}.forceDeleteMany`
923
920
  );
924
- const o = e.make(s);
925
- return new o({ id: r }).forceDelete();
921
+ const n = e.make(s);
922
+ return new n({ id: r }).forceDelete();
926
923
  }
927
924
  static singular() {
928
925
  return e.schema(s).displayName.singular;
@@ -930,60 +927,60 @@ function Te(n, t, e, i, s) {
930
927
  static plural() {
931
928
  return e.schema(s).displayName.plural;
932
929
  }
933
- }, p(l, "name", y.studly(s)), l;
930
+ }, p(l, "name", m.studly(s)), l;
934
931
  }
935
- function Re(n, t, e) {
932
+ function _e(o, t, e) {
936
933
  var i, s;
937
934
  return class extends (s = e, i = Symbol.toStringTag, s) {
938
- constructor(g = {}) {
939
- super(g);
940
- p(this, i, y.studly(t));
935
+ constructor(y = {}) {
936
+ super(y);
937
+ p(this, i, m.studly(t));
941
938
  return new Proxy(this, {
942
939
  get: (l, u) => {
943
940
  if (u === "__isModel")
944
941
  return !0;
945
- if (Reflect.has(l, u))
942
+ if (Reflect.has(l, u) || typeof u != "string")
946
943
  return Reflect.get(l, u);
947
944
  if (Object.keys(l.attributes).includes(u))
948
945
  return l.getAttribute(u);
949
946
  if (Object.keys(l.relations).includes(u))
950
947
  return l.relations[u].getLoadedItems();
951
- if (u.endsWith("Relation") && Object.keys(l.relations).includes(y.snake(u.slice(0, -8))))
948
+ if (u.endsWith("Relation") && Object.keys(l.relations).includes(m.snake(u.slice(0, -8))))
952
949
  return () => l.relation(u.slice(0, -8));
953
- if (n.hasReducer(`model${y.studly(l.getType())}Get${y.studly(u)}Attribute`)) {
954
- const r = n[`model${y.studly(l.getType())}Get${y.studly(u)}Attribute`];
950
+ if (o.hasReducer(`model${m.studly(l.getType())}Get${m.studly(u)}Attribute`)) {
951
+ const r = o[`model${m.studly(l.getType())}Get${m.studly(u)}Attribute`];
955
952
  if (typeof r != "function")
956
- throw new $("ModelFacade");
957
- return r.bind(n)(void 0, l);
953
+ throw new E("ModelFacade");
954
+ return r.bind(o)(void 0, l);
958
955
  }
959
956
  return Reflect.get(l, u);
960
957
  },
961
958
  set: (l, u, r) => u in l && typeof l[u] != "function" ? Reflect.set(l, u, r) : (l.setAttribute(
962
- y.snake(u),
959
+ m.snake(u),
963
960
  r
964
961
  ), !0)
965
962
  });
966
963
  }
967
964
  };
968
965
  }
969
- var W, z;
970
- class j extends (z = Error, W = Symbol.toStringTag, z) {
966
+ var G, V;
967
+ class K extends (V = Error, G = Symbol.toStringTag, V) {
971
968
  constructor(e) {
972
969
  super(`[Luminix] Model "${e}" not found`);
973
- p(this, W, "ModelNotFoundException");
970
+ p(this, G, "ModelNotFoundException");
974
971
  }
975
972
  }
976
- var X, Y;
977
- class A extends (Y = TypeError, X = Symbol.toStringTag, Y) {
973
+ var W, z;
974
+ class T extends (z = TypeError, W = Symbol.toStringTag, z) {
978
975
  constructor(e, i, s) {
979
976
  super(`[Luminix] "${e}" expects a related model of type "${i}". Received "${s}" instead.`);
980
- p(this, X, "ModelInvalidRelatedTypeException");
977
+ p(this, W, "ModelInvalidRelatedTypeException");
981
978
  }
982
979
  }
983
- class ue extends N {
980
+ class oe extends R {
984
981
  constructor(t, e, i, s = null) {
985
- if (!m.isModel(s) && s !== null)
986
- throw new w("BelongsTo.constructor()", "Model or null");
982
+ if (!d.isModel(s) && s !== null)
983
+ throw new f("BelongsTo.constructor()", "Model or null");
987
984
  super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
988
985
  }
989
986
  isSingle() {
@@ -1000,12 +997,12 @@ class ue extends N {
1000
997
  return this.query().first();
1001
998
  }
1002
999
  async associate(t) {
1003
- if (!m.isModel(t))
1004
- throw new w("BelongsTo.associate()");
1000
+ if (!d.isModel(t))
1001
+ throw new f("BelongsTo.associate()");
1005
1002
  if (t.getType() !== this.getRelated().getSchemaName())
1006
- throw new A("BelongsTo.associate()", this.getRelated().getSchemaName(), t.getType());
1003
+ throw new T("BelongsTo.associate()", this.getRelated().getSchemaName(), t.getType());
1007
1004
  if (!t.exists)
1008
- throw new ae(this.getRelated().getSchemaName(), "save");
1005
+ throw new ne(this.getRelated().getSchemaName(), "save");
1009
1006
  return this.parent.update({
1010
1007
  [this.getForeignKey()]: t.getKey()
1011
1008
  });
@@ -1016,10 +1013,10 @@ class ue extends N {
1016
1013
  });
1017
1014
  }
1018
1015
  }
1019
- class he extends N {
1016
+ class ae extends R {
1020
1017
  constructor(t, e, i, s = null) {
1021
- if (s !== null && !(s instanceof x && s.every(f)))
1022
- throw new w("BelongsToMany.constructor()", "Collection<Model> or null");
1018
+ if (s !== null && !(s instanceof b && s.every(d.isModel)))
1019
+ throw new f("BelongsToMany.constructor()", "Collection<Model> or null");
1023
1020
  super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
1024
1021
  }
1025
1022
  isSingle() {
@@ -1112,23 +1109,23 @@ class he extends N {
1112
1109
  this.items ? this.items.splice(0, this.items.count(), ...i) : this.items = i;
1113
1110
  }
1114
1111
  }
1115
- class K extends N {
1112
+ class N extends R {
1116
1113
  query() {
1117
1114
  const t = super.query(), e = this.guessInverseRelation();
1118
1115
  return t.where(e, this.parent.getKey()), t.lock(`where.${e}`), t;
1119
1116
  }
1120
1117
  async saveQuietly(t) {
1121
- if (!f(t))
1122
- throw new w("HasOneOrMany.saveQuietly()");
1118
+ if (!d.isModel(t))
1119
+ throw new f("HasOneOrMany.saveQuietly()");
1123
1120
  if (t.getType() !== this.getRelated().getSchemaName())
1124
- throw new A("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), t.getType());
1121
+ throw new T("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), t.getType());
1125
1122
  t.setAttribute(this.getForeignKey(), this.parent.getKey()), await t.save();
1126
1123
  }
1127
1124
  }
1128
- class Ae extends K {
1125
+ class Te extends N {
1129
1126
  constructor(t, e, i, s = null) {
1130
- if (!f(s) && s !== null)
1131
- throw new w("HasOne.constructor()", "Model or null");
1127
+ if (!d.isModel(s) && s !== null)
1128
+ throw new f("HasOne.constructor()", "Model or null");
1132
1129
  super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
1133
1130
  }
1134
1131
  isSingle() {
@@ -1144,10 +1141,10 @@ class Ae extends K {
1144
1141
  await this.saveQuietly(t), this.items = t;
1145
1142
  }
1146
1143
  }
1147
- class Ne extends K {
1144
+ class Re extends N {
1148
1145
  constructor(t, e, i, s = null) {
1149
- if (s !== null && !(s instanceof x && s.every(f)))
1150
- throw new w("HasMany.constructor()", "Collection<Model> or null");
1146
+ if (s !== null && !(s instanceof b && s.every(d.isModel)))
1147
+ throw new f("HasMany.constructor()", "Collection<Model> or null");
1151
1148
  super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
1152
1149
  }
1153
1150
  isSingle() {
@@ -1169,10 +1166,10 @@ class Ne extends K {
1169
1166
  return this.query().find(t);
1170
1167
  }
1171
1168
  async saveManyQuietly(t) {
1172
- if (!Array.isArray(t) || !t.every(f))
1173
- throw new w("HasMany.saveManyQuietly()", "Model[]");
1169
+ if (!Array.isArray(t) || !t.every(d.isModel))
1170
+ throw new f("HasMany.saveManyQuietly()", "Model[]");
1174
1171
  if (!t.every((e) => e.getType() === this.getRelated().getSchemaName()))
1175
- throw new A("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), t.map((e) => e.getType()).join(", "));
1172
+ throw new T("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), t.map((e) => e.getType()).join(", "));
1176
1173
  await Promise.all(t.map((e) => (e.setAttribute(this.getForeignKey(), this.parent.getKey()), e.save())));
1177
1174
  }
1178
1175
  async saveMany(t) {
@@ -1184,7 +1181,7 @@ class Ne extends K {
1184
1181
  await this.saveQuietly(t), this.items === null ? this.items = await this.all() : this.items.push(t);
1185
1182
  }
1186
1183
  }
1187
- class le extends K {
1184
+ class ue extends N {
1188
1185
  query() {
1189
1186
  const t = this.getRelated().query();
1190
1187
  t.once("success", (i) => {
@@ -1194,18 +1191,18 @@ class le extends K {
1194
1191
  return t.where(e + "_id", this.parent.getKey()), t.where(e + "_type", this.getRelated().getSchemaName()), t.lock(`where.${e}_id`), t.lock(`where.${e}_type`), t;
1195
1192
  }
1196
1193
  async saveQuietly(t) {
1197
- if (!f(t))
1198
- throw new w("MorphOneOrMany.saveQuietly()");
1194
+ if (!d.isModel(t))
1195
+ throw new f("MorphOneOrMany.saveQuietly()");
1199
1196
  if (t.getType() !== this.getRelated().getSchemaName())
1200
- throw new A("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), t.getType());
1197
+ throw new T("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), t.getType());
1201
1198
  const e = this.guessInverseRelation();
1202
1199
  t.setAttribute(e + "_id", this.parent.getKey()), t.setAttribute(e + "_type", this.parent.getType()), await t.save();
1203
1200
  }
1204
1201
  }
1205
- class qe extends le {
1202
+ class Ae extends ue {
1206
1203
  constructor(t, e, i, s = null) {
1207
- if (s !== null && !(s instanceof x && s.every(f)))
1208
- throw new w("MorphMany.constructor()", "Collection<Model> or null");
1204
+ if (s !== null && !(s instanceof b && s.every(d.isModel)))
1205
+ throw new f("MorphMany.constructor()", "Collection<Model> or null");
1209
1206
  super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
1210
1207
  }
1211
1208
  isSingle() {
@@ -1227,10 +1224,10 @@ class qe extends le {
1227
1224
  return this.query().find(t);
1228
1225
  }
1229
1226
  async saveManyQuietly(t) {
1230
- if (!Array.isArray(t) || !t.every(f))
1231
- throw new w("MorphMany.saveManyQuietly()");
1227
+ if (!Array.isArray(t) || !t.every(d.isModel))
1228
+ throw new f("MorphMany.saveManyQuietly()");
1232
1229
  if (!t.every((e) => e.getType() === this.getRelated().getSchemaName()))
1233
- throw new A("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), t.map((e) => e.getType()).join(", "));
1230
+ throw new T("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), t.map((e) => e.getType()).join(", "));
1234
1231
  await Promise.all(t.map((e) => (e.setAttribute(this.getName() + "_id", this.parent.getKey()), e.setAttribute(this.getName() + "_type", this.parent.getType()), e.save())));
1235
1232
  }
1236
1233
  async save(t) {
@@ -1242,10 +1239,10 @@ class qe extends le {
1242
1239
  this.items ? this.items.splice(0, this.items.count(), ...e) : this.items = e;
1243
1240
  }
1244
1241
  }
1245
- class Ke extends le {
1242
+ class Ne extends ue {
1246
1243
  constructor(t, e, i, s = null) {
1247
- if (super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s, s !== null && !f(s))
1248
- throw new w("MorphOne.constructor()", "Model or null");
1244
+ if (super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s, s !== null && !d.isModel(s))
1245
+ throw new f("MorphOne.constructor()", "Model or null");
1249
1246
  }
1250
1247
  isSingle() {
1251
1248
  return !0;
@@ -1260,7 +1257,7 @@ class Ke extends le {
1260
1257
  await this.saveQuietly(t), this.items = t;
1261
1258
  }
1262
1259
  }
1263
- class ke extends ue {
1260
+ class qe extends oe {
1264
1261
  getRelated() {
1265
1262
  return this.services.model.make(
1266
1263
  this.parent.getAttribute(this.getName() + "_type")
@@ -1275,8 +1272,8 @@ class ke extends ue {
1275
1272
  // return super.query();
1276
1273
  // }
1277
1274
  async associate(t) {
1278
- if (!f(t))
1279
- throw new w("MorphTo.associate()");
1275
+ if (!d.isModel(t))
1276
+ throw new f("MorphTo.associate()");
1280
1277
  return t.exists || await t.save(), this.parent.update({
1281
1278
  [this.getName() + "_id"]: t.getKey(),
1282
1279
  [this.getName() + "_type"]: t.getType()
@@ -1289,24 +1286,24 @@ class ke extends ue {
1289
1286
  });
1290
1287
  }
1291
1288
  }
1292
- class je extends he {
1289
+ class Ke extends ae {
1293
1290
  query() {
1294
1291
  const t = super.query(), e = this.guessInverseRelation();
1295
1292
  return t.where(e + "_id", this.parent.getKey()), t.where(e + "_type", this.parent.getType()), t.lock(`where.${e}_id`), t.lock(`where.${e}_type`), t;
1296
1293
  }
1297
1294
  }
1298
- var Z, ee;
1299
- class Oe extends (ee = q, Z = Symbol.toStringTag, ee) {
1295
+ var X, Y;
1296
+ class ke extends (Y = A, X = Symbol.toStringTag, Y) {
1300
1297
  constructor(e) {
1301
1298
  super();
1302
1299
  p(this, "_models", {});
1303
- p(this, Z, "ModelService");
1300
+ p(this, X, "ModelService");
1304
1301
  this._schema = e;
1305
1302
  }
1306
1303
  boot(e) {
1307
1304
  this._schema && Object.keys(this._schema).forEach((i) => {
1308
- const s = this[`model${y.studly(i)}`], c = this.model(
1309
- Te(
1305
+ const s = this[`model${m.studly(i)}`], c = this.model(
1306
+ Se(
1310
1307
  e.make("config"),
1311
1308
  e.make("log"),
1312
1309
  e.make("model"),
@@ -1314,45 +1311,45 @@ class Oe extends (ee = q, Z = Symbol.toStringTag, ee) {
1314
1311
  i
1315
1312
  ),
1316
1313
  i
1317
- ), g = s(c);
1318
- this._models[i] = Re(e.make("model"), i, g);
1314
+ ), y = s(c);
1315
+ this._models[i] = _e(e.make("model"), i, y);
1319
1316
  });
1320
1317
  }
1321
1318
  schema(e) {
1322
1319
  if (!this._schema || e && !this._schema[e])
1323
- throw new j(e || "undefined");
1320
+ throw new K(e || "undefined");
1324
1321
  return e ? this._schema[e] : this._schema;
1325
1322
  }
1326
1323
  make(e) {
1327
1324
  if (e && !this._models[e])
1328
- throw new j(e);
1325
+ throw new K(e);
1329
1326
  return e ? this._models[e] : this._models;
1330
1327
  }
1331
1328
  getRelationConstructors(e) {
1332
1329
  return this.relationMap({
1333
- BelongsTo: ue,
1334
- BelongsToMany: he,
1335
- HasOne: Ae,
1336
- HasMany: Ne,
1337
- MorphMany: qe,
1338
- MorphOne: Ke,
1339
- MorphTo: ke,
1340
- MorphToMany: je
1330
+ BelongsTo: oe,
1331
+ BelongsToMany: ae,
1332
+ HasOne: Te,
1333
+ HasMany: Re,
1334
+ MorphMany: Ae,
1335
+ MorphOne: Ne,
1336
+ MorphTo: qe,
1337
+ MorphToMany: Ke
1341
1338
  }, e);
1342
1339
  }
1343
1340
  toString() {
1344
1341
  return "model";
1345
1342
  }
1346
1343
  }
1347
- const Be = ne(Oe);
1348
- var te, se;
1349
- class Ce extends (se = Error, te = Symbol.toStringTag, se) {
1344
+ const je = re(ke);
1345
+ var Z, ee;
1346
+ class Oe extends (ee = Error, Z = Symbol.toStringTag, ee) {
1350
1347
  constructor(e) {
1351
1348
  super(`[Luminix] Route "${e}" not found`);
1352
- p(this, te, "RouteNotFoundException");
1349
+ p(this, Z, "RouteNotFoundException");
1353
1350
  }
1354
1351
  }
1355
- class Ie {
1352
+ class Be {
1356
1353
  constructor(t, e, i, s = "") {
1357
1354
  this.routes = t, this.error = e, this.http = i, this.appUrl = s;
1358
1355
  }
@@ -1371,22 +1368,22 @@ class Ie {
1371
1368
  }
1372
1369
  get(t) {
1373
1370
  if (!this.exists(t))
1374
- throw new Ce(t);
1375
- return m.get(this.routes, t);
1371
+ throw new Oe(t);
1372
+ return d.get(this.routes, t);
1376
1373
  }
1377
1374
  url(t) {
1378
1375
  const [e, i] = this.extractGenerator(t), s = this.get(e)[0].replace(/^\/|\/$/g, ""), c = /{([^}]+)}/g;
1379
1376
  if (i === !1) {
1380
1377
  if (typeof this.replaceRouteParams != "function")
1381
- throw new $("RouteFacade");
1378
+ throw new E("RouteFacade");
1382
1379
  return this.appUrl + this.replaceRouteParams(`/${s}`);
1383
1380
  }
1384
- const g = s.match(c), l = g ? g.map((h) => h.slice(1, -1)) : [], u = Object.keys(i), r = l.filter((h) => !u.includes(h)), o = u.filter((h) => !l.includes(h));
1381
+ const y = s.match(c), l = y ? y.map((h) => h.slice(1, -1)) : [], u = Object.keys(i), r = l.filter((h) => !u.includes(h)), n = u.filter((h) => !l.includes(h));
1385
1382
  if (r.length > 0)
1386
1383
  throw new TypeError(`Missing values for parameter(s): ${r.join(", ")}`);
1387
- if (o.length > 0)
1388
- throw new TypeError(`Unexpected parameters: ${o.join(", ")}`);
1389
- const a = l.reduce((h, d) => h.replace(`{${d}}`, `${i[d]}`), s);
1384
+ if (n.length > 0)
1385
+ throw new TypeError(`Unexpected parameters: ${n.join(", ")}`);
1386
+ const a = l.reduce((h, g) => h.replace(`{${g}}`, `${i[g]}`), s);
1390
1387
  return this.appUrl + `/${a}`;
1391
1388
  }
1392
1389
  methods(t) {
@@ -1394,20 +1391,20 @@ class Ie {
1394
1391
  return this.get(e).slice(1);
1395
1392
  }
1396
1393
  exists(t) {
1397
- return m.has(this.routes, t) && this.isRouteTuple(m.get(this.routes, t));
1394
+ return d.has(this.routes, t) && this.isRouteTuple(d.get(this.routes, t));
1398
1395
  }
1399
1396
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1400
1397
  async call(t, e = (s) => s, i = "default") {
1401
1398
  if (typeof this.clientOptions != "function" || typeof this.clientError != "function")
1402
- throw new $("RouteFacade");
1403
- const [s, c] = this.extractGenerator(t), [, ...g] = this.get(s), l = this.url(c ? [s, c] : s), u = e(this.http()), r = this.clientOptions({}, s);
1404
- m.isEmpty(r) || u.withOptions(r);
1405
- const o = g[0] ?? r.method;
1399
+ throw new E("RouteFacade");
1400
+ const [s, c] = this.extractGenerator(t), [, ...y] = this.get(s), l = this.url(c ? [s, c] : s), u = e(this.http()), r = this.clientOptions({}, s);
1401
+ d.isEmpty(r) || u.withOptions(r);
1402
+ const n = y[0] ?? r.method;
1406
1403
  this.error.clear(i);
1407
- const a = await u[o](l);
1408
- if (ge(a)) {
1404
+ const a = await u[n](l);
1405
+ if (de(a)) {
1409
1406
  const h = a.json("errors");
1410
- this.error.set(Object.entries(h).reduce((d, [v, b]) => (d[v] = b.join(" "), d), {}), i);
1407
+ this.error.set(Object.entries(h).reduce((g, [w, v]) => (g[w] = v.join(" "), g), {}), i);
1411
1408
  } else a.failed() && this.error.set(
1412
1409
  this.clientError({ axios: a.json("message") }, {
1413
1410
  response: a,
@@ -1423,10 +1420,10 @@ class Ie {
1423
1420
  return "route";
1424
1421
  }
1425
1422
  }
1426
- const Pe = ne(Ie);
1427
- class Qe {
1423
+ const Ce = re(Be);
1424
+ class Ie {
1428
1425
  getClient() {
1429
- return new ye();
1426
+ return new pe();
1430
1427
  }
1431
1428
  baseUrl(t) {
1432
1429
  return this.getClient().baseUrl(t);
@@ -1479,12 +1476,12 @@ class Qe {
1479
1476
  return this.getClient().delete(t, e);
1480
1477
  }
1481
1478
  }
1482
- const De = oe(Qe);
1483
- var re, ie;
1484
- class He extends (ie = me, re = Symbol.toStringTag, ie) {
1479
+ const Pe = ie(Ie);
1480
+ var te, se;
1481
+ class Qe extends (se = ge, te = Symbol.toStringTag, se) {
1485
1482
  constructor() {
1486
1483
  super(...arguments);
1487
- p(this, re, "LuminixServiceProvider");
1484
+ p(this, te, "LuminixServiceProvider");
1488
1485
  }
1489
1486
  register() {
1490
1487
  this.registerServices(), this.registerMacros(), this.app.on("ready", () => {
@@ -1495,24 +1492,24 @@ class He extends (ie = me, re = Symbol.toStringTag, ie) {
1495
1492
  this.app.make("model").boot(this.app);
1496
1493
  }
1497
1494
  registerServices() {
1498
- this.app.singleton("auth", () => new ve(
1495
+ this.app.singleton("auth", () => new fe(
1499
1496
  this.app.make("config"),
1500
1497
  this.app.make("model"),
1501
1498
  this.app.make("route")
1502
1499
  )), this.app.singleton("config", () => {
1503
- const e = new R(m.omit(this.app.configuration, "manifest"));
1500
+ const e = new _(d.omit(this.app.configuration, "manifest"));
1504
1501
  return e.has("auth.user") || e.set("auth.user", null), e.lock("auth.user"), e;
1505
- }), this.app.singleton("error", () => new be()), this.app.singleton("http", () => new De()), this.app.singleton("log", () => {
1502
+ }), this.app.singleton("error", () => new we()), this.app.singleton("http", () => new Pe()), this.app.singleton("log", () => {
1506
1503
  var e;
1507
- return new xe(((e = this.app.configuration.app) == null ? void 0 : e.debug) ?? !1);
1504
+ return new ve(((e = this.app.configuration.app) == null ? void 0 : e.debug) ?? !1);
1508
1505
  }), this.app.singleton("model", () => {
1509
1506
  var e;
1510
- return new Be(
1507
+ return new je(
1511
1508
  ((e = this.app.configuration.manifest) == null ? void 0 : e.models) ?? {}
1512
1509
  );
1513
1510
  }), this.app.singleton("route", () => {
1514
1511
  var e, i;
1515
- return new Pe(
1512
+ return new Ce(
1516
1513
  ((e = this.app.configuration.manifest) == null ? void 0 : e.routes) ?? {},
1517
1514
  this.app.make("error"),
1518
1515
  () => this.app.make("http"),
@@ -1521,94 +1518,96 @@ class He extends (ie = me, re = Symbol.toStringTag, ie) {
1521
1518
  });
1522
1519
  }
1523
1520
  registerMacros() {
1524
- this.app.macro("environment", (...e) => e.length > 0 ? e.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"), m.macro("isModel", function(e) {
1521
+ this.app.macro("environment", (...e) => e.length > 0 ? e.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"), d.macro("isModel", function(e) {
1525
1522
  return typeof e == "object" && e !== null && e.__isModel === !0;
1526
1523
  });
1527
1524
  }
1528
1525
  }
1529
- let S;
1530
- class Le {
1526
+ class De {
1527
+ constructor() {
1528
+ p(this, "app");
1529
+ }
1531
1530
  getFacadeAccessor() {
1532
- return S || (S = new (oe(fe))([
1533
- He
1534
- ])), S;
1531
+ return this.app || (this.app = new (ie(ye))([
1532
+ Qe
1533
+ ])), this.app;
1535
1534
  }
1536
1535
  down() {
1537
- S && (S.flush(), S = void 0);
1536
+ this.app && (this.app.flush(), delete this.app);
1538
1537
  }
1539
1538
  }
1540
- const M = E(Le);
1541
- function _(n = void 0) {
1542
- return typeof n != "string" ? M : M.make(n);
1539
+ const x = M(De);
1540
+ function $(o = void 0) {
1541
+ return typeof o != "string" ? x : x.make(o);
1543
1542
  }
1544
- function Ze() {
1545
- return _("auth");
1543
+ function Xe() {
1544
+ return $("auth");
1546
1545
  }
1547
- function et(n) {
1548
- return new x(n);
1546
+ function Ye(o) {
1547
+ return new b(o);
1549
1548
  }
1550
- function tt(n, t) {
1551
- const e = _("config");
1552
- return typeof n > "u" ? e : e.get(n, t);
1549
+ function Ze(o, t) {
1550
+ const e = $("config");
1551
+ return typeof o > "u" ? e : e.get(o, t);
1553
1552
  }
1554
- function st(n, t = "default") {
1555
- return n ? _().make("error").get(n, t) : _().make("error");
1553
+ function et(o, t = "default") {
1554
+ return o ? $().make("error").get(o, t) : $().make("error");
1556
1555
  }
1557
- function rt(...n) {
1558
- const t = _("log");
1559
- return n.length ? t.debug(...n) : t;
1556
+ function tt(...o) {
1557
+ const t = $("log");
1558
+ return o.length ? t.debug(...o) : t;
1560
1559
  }
1561
- function it(n) {
1562
- const t = _("model");
1563
- return n ? t.make(n) : t;
1560
+ function st(o) {
1561
+ const t = $("model");
1562
+ return o ? t.make(o) : t;
1564
1563
  }
1565
- function nt(n, t = !1) {
1566
- const e = _("route");
1567
- return n ? t ? e.url([n, t]) : e.url(n) : e;
1564
+ function rt(o, t = !1) {
1565
+ const e = $("route");
1566
+ return o ? t ? e.url([o, t]) : e.url(o) : e;
1568
1567
  }
1569
- class Je {
1568
+ class He {
1570
1569
  getFacadeAccessor() {
1571
1570
  return "auth";
1572
1571
  }
1573
1572
  }
1574
- const ot = E(Je, M);
1575
- class Ue {
1573
+ const it = M(He, x);
1574
+ class Le {
1576
1575
  getFacadeAccessor() {
1577
1576
  return "config";
1578
1577
  }
1579
1578
  }
1580
- const at = E(Ue, M), ut = (n) => n instanceof we && n.unprocessableEntity() && typeof n.json("message") == "string" && typeof n.json("errors") == "object" && n.json("errors") !== null && Object.values(n.json("errors")).every((t) => Array.isArray(t) && t.every((e) => typeof e == "string"));
1581
- class Fe {
1579
+ const nt = M(Le, x), ot = (o) => o instanceof me && o.unprocessableEntity() && typeof o.json("message") == "string" && typeof o.json("errors") == "object" && o.json("errors") !== null && Object.values(o.json("errors")).every((t) => Array.isArray(t) && t.every((e) => typeof e == "string"));
1580
+ class Je {
1582
1581
  getFacadeAccessor() {
1583
1582
  return "error";
1584
1583
  }
1585
1584
  }
1586
- const ht = E(Fe, M);
1587
- class Ge {
1585
+ const at = M(Je, x);
1586
+ class Ue {
1588
1587
  getFacadeAccessor() {
1589
1588
  return "http";
1590
1589
  }
1591
1590
  }
1592
- const lt = E(Ge, M);
1593
- class Ve {
1591
+ const ut = M(Ue, x);
1592
+ class Fe {
1594
1593
  getFacadeAccessor() {
1595
1594
  return "log";
1596
1595
  }
1597
1596
  }
1598
- const ct = E(Ve, M);
1599
- class We {
1597
+ const ht = M(Fe, x);
1598
+ class Ge {
1600
1599
  getFacadeAccessor() {
1601
1600
  return "model";
1602
1601
  }
1603
1602
  }
1604
- const dt = E(We, M);
1605
- class ze {
1603
+ const lt = M(Ge, x);
1604
+ class Ve {
1606
1605
  getFacadeAccessor() {
1607
1606
  return "route";
1608
1607
  }
1609
1608
  }
1610
- const pt = E(ze, M);
1611
- class gt {
1609
+ const ct = M(Ve, x);
1610
+ class dt {
1612
1611
  constructor() {
1613
1612
  p(this, "name");
1614
1613
  p(this, "version");
@@ -1619,23 +1618,22 @@ class gt {
1619
1618
  }
1620
1619
  }
1621
1620
  export {
1622
- M as App,
1623
- ot as Auth,
1624
- at as Config,
1625
- ht as Error,
1626
- lt as Http,
1627
- ct as Log,
1628
- dt as Model,
1629
- gt as Plugin,
1630
- pt as Route,
1631
- _ as app,
1632
- Ze as auth,
1633
- et as collect,
1634
- tt as config,
1635
- st as error,
1636
- f as isModel,
1637
- ut as isValidationError,
1638
- rt as log,
1639
- it as model,
1640
- nt as route
1621
+ x as App,
1622
+ it as Auth,
1623
+ nt as Config,
1624
+ at as Error,
1625
+ ut as Http,
1626
+ ht as Log,
1627
+ lt as Model,
1628
+ dt as Plugin,
1629
+ ct as Route,
1630
+ $ as app,
1631
+ Xe as auth,
1632
+ Ye as collect,
1633
+ Ze as config,
1634
+ et as error,
1635
+ ot as isValidationError,
1636
+ tt as log,
1637
+ st as model,
1638
+ rt as route
1641
1639
  };