@luminix/core 0.1.0-beta.0 → 0.2.0

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