@luminix/core 0.0.1-beta.9 → 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.
Files changed (103) hide show
  1. package/README.md +0 -28
  2. package/dist/core.js +1042 -1925
  3. package/package.json +5 -9
  4. package/types/contracts/Builder.d.ts +46 -0
  5. package/types/contracts/ModelCollection.d.ts +7 -0
  6. package/{dist → types}/contracts/Plugin.d.ts +3 -3
  7. package/{dist → types}/contracts/Relation/BelongsTo.d.ts +3 -5
  8. package/{dist → types}/contracts/Relation/BelongsToMany.d.ts +7 -9
  9. package/{dist → types}/contracts/Relation/HasMany.d.ts +6 -7
  10. package/{dist → types}/contracts/Relation/HasOne.d.ts +3 -4
  11. package/{dist → types}/contracts/Relation/HasOneOrMany.d.ts +0 -1
  12. package/{dist → types}/contracts/Relation/MorphMany.d.ts +6 -7
  13. package/{dist → types}/contracts/Relation/MorphOne.d.ts +3 -4
  14. package/{dist → types}/contracts/Relation/MorphOneOrMany.d.ts +0 -1
  15. package/{dist → types}/contracts/Relation/MorphTo.d.ts +0 -1
  16. package/types/contracts/Relation/MorphToMany.d.ts +8 -0
  17. package/{dist → types}/contracts/Relation.d.ts +12 -9
  18. package/types/extensions.d.ts +10 -0
  19. package/types/facades/App.d.ts +8 -0
  20. package/types/facades/Auth.d.ts +7 -0
  21. package/types/facades/Config.d.ts +7 -0
  22. package/types/facades/Error.d.ts +10 -0
  23. package/types/facades/Http.d.ts +8 -0
  24. package/types/facades/Log.d.ts +7 -0
  25. package/types/facades/Model.d.ts +8 -0
  26. package/types/facades/Route.d.ts +8 -0
  27. package/types/helpers/app.d.ts +4 -0
  28. package/{dist → types}/helpers/auth.d.ts +0 -1
  29. package/types/helpers/collect.d.ts +2 -0
  30. package/{dist → types}/helpers/config.d.ts +0 -1
  31. package/{dist → types}/helpers/error.d.ts +0 -1
  32. package/types/helpers/log.d.ts +5 -0
  33. package/{dist → types}/helpers/model.d.ts +2 -3
  34. package/{dist → types}/helpers/route.d.ts +2 -2
  35. package/types/index.d.ts +26 -0
  36. package/types/mixins/BaseModel.d.ts +7 -0
  37. package/types/providers/LuminixServiceProvider.d.ts +8 -0
  38. package/types/services/AuthService.d.ts +18 -0
  39. package/{dist/facades/Error.d.ts → types/services/ErrorService.d.ts} +2 -6
  40. package/types/services/HttpService.d.ts +21 -0
  41. package/{dist/facades/Log.d.ts → types/services/LogService.d.ts} +2 -4
  42. package/types/services/ModelService.d.ts +21 -0
  43. package/types/services/RouteService.d.ts +21 -0
  44. package/{dist → types}/support/model.d.ts +1 -1
  45. package/types/types/App.d.ts +88 -0
  46. package/{dist → types}/types/Auth.d.ts +0 -1
  47. package/types/types/Builder.d.ts +46 -0
  48. package/{dist → types}/types/Config.d.ts +4 -2
  49. package/types/types/Error.d.ts +17 -0
  50. package/types/types/Http.d.ts +20 -0
  51. package/{dist → types}/types/Model.d.ts +61 -43
  52. package/{dist → types}/types/Relation.d.ts +1 -3
  53. package/types/types/Route.d.ts +28 -0
  54. package/{dist → types}/types/Support.d.ts +3 -2
  55. package/.eslintignore +0 -3
  56. package/.eslintrc.cjs +0 -39
  57. package/dist/contracts/Builder.d.ts +0 -53
  58. package/dist/contracts/Collection.d.ts +0 -190
  59. package/dist/contracts/ModelCollection.d.ts +0 -9
  60. package/dist/contracts/PropertyBag.d.ts +0 -21
  61. package/dist/contracts/Relation/MorphToMany.d.ts +0 -16
  62. package/dist/facades/App.d.ts +0 -37
  63. package/dist/facades/Auth.d.ts +0 -14
  64. package/dist/facades/Model.d.ts +0 -41
  65. package/dist/facades/Route.d.ts +0 -32
  66. package/dist/helpers/app.d.ts +0 -5
  67. package/dist/helpers/collect.d.ts +0 -1
  68. package/dist/helpers/log.d.ts +0 -5
  69. package/dist/index.d.ts +0 -24
  70. package/dist/mixins/BaseModel.d.ts +0 -5
  71. package/dist/mixins/HasEvents.d.ts +0 -15
  72. package/dist/mixins/Reducible.d.ts +0 -17
  73. package/dist/support/collection.d.ts +0 -4
  74. package/dist/support/reader.d.ts +0 -2
  75. package/dist/support/searchParams.d.ts +0 -1
  76. package/dist/types/App.d.ts +0 -79
  77. package/dist/types/Builder.d.ts +0 -51
  78. package/dist/types/Collection.d.ts +0 -1804
  79. package/dist/types/Error.d.ts +0 -31
  80. package/dist/types/Event.d.ts +0 -14
  81. package/dist/types/PropertyBag.d.ts +0 -25
  82. package/dist/types/Reducer.d.ts +0 -17
  83. package/dist/types/Route.d.ts +0 -22
  84. package/index.html +0 -13
  85. package/jest.config.js +0 -15
  86. package/tsconfig.json +0 -25
  87. package/vite.config.js +0 -20
  88. /package/{dist → types}/exceptions/AttributeNotFillableException.d.ts +0 -0
  89. /package/{dist → types}/exceptions/FacadeNotFoundException.d.ts +0 -0
  90. /package/{dist → types}/exceptions/MethodNotImplementedException.d.ts +0 -0
  91. /package/{dist → types}/exceptions/ModelInvalidRelatedTypeException.d.ts +0 -0
  92. /package/{dist → types}/exceptions/ModelNotFoundException.d.ts +0 -0
  93. /package/{dist → types}/exceptions/ModelNotPersistedException.d.ts +0 -0
  94. /package/{dist → types}/exceptions/ModelWithoutPrimaryKeyException.d.ts +0 -0
  95. /package/{dist → types}/exceptions/NoEmbedException.d.ts +0 -0
  96. /package/{dist → types}/exceptions/NoInverseRelationException.d.ts +0 -0
  97. /package/{dist → types}/exceptions/NotModelException.d.ts +0 -0
  98. /package/{dist → types}/exceptions/NotReducibleException.d.ts +0 -0
  99. /package/{dist → types}/exceptions/ReducerOverrideException.d.ts +0 -0
  100. /package/{dist → types}/exceptions/RouteNotFoundException.d.ts +0 -0
  101. /package/{dist → types}/exceptions/UnsupportedRelationException.d.ts +0 -0
  102. /package/{dist → types}/types/Log.d.ts +0 -0
  103. /package/{dist → types}/types/Plugin.d.ts +0 -0
package/dist/core.js CHANGED
@@ -1,1020 +1,185 @@
1
- var je = Object.defineProperty;
2
- var C = (n) => {
3
- throw TypeError(n);
4
- };
5
- var Fe = (n, e, t) => e in n ? je(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
6
- var m = (n, e, t) => Fe(n, typeof e != "symbol" ? e + "" : e, t), j = (n, e, t) => e.has(n) || C("Cannot " + t);
7
- var h = (n, e, t) => (j(n, e, "read from private field"), t ? t.call(n) : e.get(n)), F = (n, e, t) => e.has(n) ? C("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), J = (n, e, t, r) => (j(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), D = (n, e, t) => (j(n, e, "access private method"), t);
8
- import f from "lodash";
9
- import { produce as R, isDraftable as Pe } from "immer";
10
- import I, { isAxiosError as ke } from "axios";
11
- var V, X;
12
- class Qe extends (X = Error, V = Symbol.toStringTag, X) {
13
- constructor(t) {
14
- super(`[Luminix] Facade "${t}" not found`);
15
- m(this, V, "FacadeNotFoundException");
16
- }
17
- }
18
- class Le {
19
- constructor(e) {
20
- m(this, "_user");
21
- this.app = e;
22
- }
23
- attempt(e, t = !1, r) {
24
- const i = document.createElement("form");
25
- i.method = "post", i.action = this.app.make("route").url("login"), i.style.display = "none";
26
- const s = this.app.make("config").get("auth.csrf");
27
- if (typeof s == "string") {
28
- const a = document.createElement("input");
29
- a.type = "hidden", a.name = "_token", a.value = s, i.appendChild(a);
30
- }
31
- const u = document.createElement("input");
32
- u.type = "email", u.name = "email", u.value = e.email, i.appendChild(u);
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
+ constructor(t, e, i) {
7
+ p(this, "_user");
8
+ this.config = t, this.model = e, this.route = i;
9
+ }
10
+ attempt(t, e = !1, i) {
11
+ const s = document.createElement("form");
12
+ s.method = "post", s.action = this.route.url("login"), s.style.display = "none";
13
+ const c = this.config.get("auth.csrf");
14
+ if (typeof c == "string") {
15
+ const u = document.createElement("input");
16
+ u.type = "hidden", u.name = "_token", u.value = c, s.appendChild(u);
17
+ }
18
+ const g = document.createElement("input");
19
+ g.type = "email", g.name = "email", g.value = t.email, s.appendChild(g);
33
20
  const l = document.createElement("input");
34
- if (l.type = "password", l.name = "password", l.value = e.password, i.appendChild(l), t) {
35
- const a = document.createElement("input");
36
- a.type = "checkbox", a.name = "remember", a.value = "1", a.checked = !0, i.appendChild(a);
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);
37
24
  }
38
- r && i.addEventListener("submit", r), document.body.appendChild(i), i.submit();
25
+ i && s.addEventListener("submit", i), document.body.appendChild(s), s.submit();
39
26
  }
40
27
  check() {
41
- return !!this.app.make("config").get("auth.user");
28
+ return !!this.config.get("auth.user");
42
29
  }
43
- logout(e) {
44
- const t = document.createElement("form");
45
- t.method = "post", t.action = this.app.make("route").url("logout"), t.style.display = "none";
46
- const r = this.app.make("config").get("auth.csrf");
47
- if (typeof r == "string") {
48
- const i = document.createElement("input");
49
- i.type = "hidden", i.name = "_token", i.value = r, t.appendChild(i);
30
+ logout(t) {
31
+ const e = document.createElement("form");
32
+ e.method = "post", e.action = this.route.url("logout"), e.style.display = "none";
33
+ const i = this.config.get("auth.csrf");
34
+ if (typeof i == "string") {
35
+ const s = document.createElement("input");
36
+ s.type = "hidden", s.name = "_token", s.value = i, e.appendChild(s);
50
37
  }
51
- document.body.appendChild(t), e && t.addEventListener("submit", e), t.submit();
38
+ document.body.appendChild(e), t && e.addEventListener("submit", t), e.submit();
52
39
  }
53
40
  user() {
54
41
  if (!this._user) {
55
- const { model: e, config: t } = this.app.make(), r = e.make("user"), i = t.get("auth.user");
56
- if (!i)
57
- return null;
58
- this._user = new r(i);
42
+ const t = this.model.make("user"), e = this.config.get("auth.user");
43
+ if (!e)
44
+ return;
45
+ this._user = new t(e);
59
46
  }
60
47
  return this._user;
61
48
  }
62
49
  id() {
63
- var e;
64
- return ((e = this.user()) == null ? void 0 : e.getKey()) || null;
65
- }
66
- }
67
- class Ce {
68
- constructor(e) {
69
- this._debug = e;
70
- }
71
- emergency(...e) {
72
- this._debug && console.error(...e);
73
- }
74
- alert(...e) {
75
- this._debug && console.error(...e);
76
- }
77
- critical(...e) {
78
- this._debug && console.error(...e);
79
- }
80
- error(...e) {
81
- this._debug && console.error(...e);
82
- }
83
- warning(...e) {
84
- this._debug && console.warn(...e);
85
- }
86
- notice(...e) {
87
- this._debug && console.info(...e);
88
- }
89
- info(...e) {
90
- this._debug && console.info(...e);
91
- }
92
- debug(...e) {
93
- this._debug && console.debug(...e);
94
- }
95
- }
96
- class S {
97
- constructor(e) {
98
- m(this, "locked", []);
99
- this.bag = e, Object.freeze(this.bag);
100
- }
101
- get(e, t) {
102
- return f.get(this.bag, e, t);
103
- }
104
- set(e, t) {
105
- if (this.locked.some((r) => e.startsWith(r)))
106
- throw new Error(`Cannot set a locked path "${e}"`);
107
- if (typeof t == "object" && t !== null && this.locked.some((r) => f.has(t, r.slice(e.length + 1))))
108
- throw new Error(`Cannot set a path "${e}" that would override a locked path`);
109
- if (e === ".") {
110
- if (this.locked.length)
111
- throw new Error("Cannot set the root path when there are locked paths");
112
- if (typeof t != "object" || t === null)
113
- throw new TypeError("Value must be an object");
114
- this.bag = R(this.bag, () => t), this.emit("change", {
115
- path: e,
116
- value: t,
117
- type: "set"
118
- });
119
- return;
120
- }
121
- this.bag = R(this.bag, (r) => {
122
- f.set(r, e, t);
123
- }), this.emit("change", {
124
- path: e,
125
- value: t,
126
- type: "set"
127
- });
128
- }
129
- merge(e, t) {
130
- if (typeof t != "object" || t === null)
131
- throw new TypeError("Value must be an object");
132
- if (e === ".") {
133
- if (this.locked.some((i) => f.has(t, i)))
134
- throw new Error(`Cannot merge a path "${e}" that would override a locked path`);
135
- this.bag = R(this.bag, (i) => ({
136
- ...i,
137
- ...t
138
- })), this.emit("change", {
139
- path: e,
140
- value: t,
141
- type: "merge"
142
- });
143
- return;
144
- }
145
- const r = this.get(e);
146
- if (typeof r == "object" && r !== null)
147
- return this.set(e, {
148
- ...r,
149
- ...t
150
- });
151
- if (r === null || typeof r > "u")
152
- return this.set(e, t);
153
- throw new Error(`Cannot merge a non-object path "${e}"`);
154
- }
155
- has(e) {
156
- return f.has(this.bag, e);
157
- }
158
- delete(e) {
159
- if (this.locked.some((t) => e.startsWith(t)))
160
- throw new Error(`Cannot delete a locked path "${e}"`);
161
- this.bag = R(this.bag, (t) => {
162
- f.unset(t, e);
163
- }), this.emit("change", {
164
- path: e,
165
- value: null,
166
- type: "delete"
167
- });
168
- }
169
- lock(e) {
170
- if (!this.has(e))
171
- throw new Error(`Cannot lock a non-existing path "${e}"`);
172
- this.locked.push(e);
173
- }
174
- clone() {
175
- return new S(this.bag);
176
- }
177
- all() {
178
- return this.bag;
179
- }
180
- isEmpty() {
181
- return f.isEmpty(this.bag);
182
- }
183
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
184
- on(e, t) {
185
- return () => null;
186
- }
187
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
188
- once(e, t) {
189
- }
190
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
191
- emit(e, t) {
50
+ var t;
51
+ return ((t = this.user()) == null ? void 0 : t.getKey()) || null;
192
52
  }
193
53
  }
194
- function A(n) {
195
- var e, t, r, $e, s;
196
- return s = class extends (t = n, e = Symbol.toStringTag, t) {
197
- constructor(...a) {
198
- super(...a);
199
- F(this, r);
200
- m(this, "emitter");
201
- m(this, e, n.name);
202
- this.emitter = D(this, r, $e).call(this);
203
- }
204
- on(a, d) {
205
- if (typeof a != "string")
206
- throw new TypeError("event must be a string");
207
- if (typeof d != "function")
208
- throw new TypeError("callback must be a function");
209
- return this.emitter.on(a, d);
210
- }
211
- once(a, d) {
212
- if (typeof a != "string")
213
- throw new TypeError("event must be a string");
214
- if (typeof d != "function")
215
- throw new TypeError("callback must be a function");
216
- const p = this.emitter.on(a, (w) => {
217
- p(), d(w);
218
- });
219
- }
220
- emit(a, d = {}) {
221
- if (typeof a != "string")
222
- throw new TypeError("event must be a string");
223
- if (typeof d != "object")
224
- throw new TypeError("data must be an object");
225
- this.emitter.emit(a, {
226
- ...d,
227
- source: this
228
- });
229
- }
230
- }, r = new WeakSet(), $e = function() {
231
- return {
232
- emit(a, d) {
233
- for (let p = 0, w = this.events[a] || [], x = w.length; p < x; p++)
234
- w[p](d);
235
- },
236
- events: {},
237
- on(a, d) {
238
- var p;
239
- return ((p = this.events)[a] || (p[a] = [])).push(d), () => {
240
- var w;
241
- this.events[a] = (w = this.events[a]) == null ? void 0 : w.filter((x) => d !== x);
242
- };
243
- }
244
- };
245
- }, s;
246
- }
247
- function U(...n) {
248
- return n.reduce((e, t) => e.flatMap((r) => t.map((i) => [r, i].flat())));
249
- }
250
- function $(n) {
251
- return !(typeof n != "object" || n === null || !Reflect.has(n, "constructor") || Reflect.get(n.constructor, "name") !== "Collection");
252
- }
253
- var Y, Z;
254
- class b extends (Z = Error, Y = Symbol.toStringTag, Z) {
54
+ class be {
255
55
  constructor() {
256
- super("[Luminix] Method not implemented.");
257
- m(this, Y, "MethodNotImplementedException");
258
- }
259
- }
260
- function c(n = [], e = P) {
261
- if (!Array.isArray(n))
262
- throw new TypeError("collect() expects an array");
263
- return new (A(e))([...n]);
264
- }
265
- const _ = (n) => {
266
- n.emit("change", {
267
- items: n.all()
268
- });
269
- }, q = (n, e) => Array.isArray(n) ? n[e] ?? null : n.get(e);
270
- var z, O, o;
271
- class P {
272
- constructor(e = []) {
273
- // [Symbol.toStringTag] = 'Collection';
274
- F(this, o);
275
- m(this, z, "Collection");
276
- J(this, o, e);
277
- }
278
- get items() {
279
- return [...h(this, o)];
280
- }
281
- [(O = Symbol.iterator, z = Symbol.toStringTag, O)]() {
282
- return h(this, o)[Symbol.iterator]();
283
- }
284
- all() {
285
- return [...h(this, o)];
286
- }
287
- average(e) {
288
- return typeof e == "string" ? this.avg(e) : this.avg();
289
- }
290
- avg(e) {
291
- return typeof e == "string" ? this.sum(e) / h(this, o).length : this.sum() / h(this, o).length;
292
- }
293
- chunk(e) {
294
- const t = [];
295
- for (let r = 0; r < h(this, o).length; r += e)
296
- t.push(h(this, o).slice(r, r + e));
297
- return c(t.map((r) => c(r)));
298
- }
299
- chunkWhile(e) {
300
- const t = [];
301
- let r = c();
302
- for (let i = 0; i < h(this, o).length; i++)
303
- e(h(this, o)[i], i, r) ? r.push(h(this, o)[i]) : (t.push(r), r = c());
304
- return r.count() > 0 && t.push(r), c(t);
305
- }
306
- collapse() {
307
- return c(h(this, o).flat());
308
- }
309
- collect() {
310
- return c(h(this, o));
311
- }
312
- combine(e) {
56
+ p(this, "bags");
313
57
  const t = {};
314
- return h(this, o).forEach((r, i) => {
315
- if (typeof r != "string")
316
- throw new TypeError("The `combine` method expects the keys to be strings");
317
- t[r] = q(e, i);
318
- }), t;
319
- }
320
- concat(e) {
321
- return Array.isArray(e) ? c([...h(this, o), ...e]) : c([...h(this, o), ...e.all()]);
322
- }
323
- contains(e, t) {
324
- return typeof e == "function" ? h(this, o).some((r, i) => e(r, i, this)) : h(this, o).some((r) => {
325
- if (typeof t > "u")
326
- return r == e;
327
- if (typeof e != "string")
328
- throw new TypeError("The key must be a string");
329
- return r[e] == t;
330
- });
331
- }
332
- containsOneItem() {
333
- return h(this, o).length === 1;
334
- }
335
- containsStrict(e, t) {
336
- return typeof e == "function" ? h(this, o).some((r, i) => e(r, i, this)) : h(this, o).some((r) => {
337
- if (typeof t > "u")
338
- return r === e;
339
- if (typeof e != "string")
340
- throw new TypeError("The key must be a string");
341
- return r[e] === t;
342
- });
343
- }
344
- count() {
345
- return h(this, o).length;
346
- }
347
- countBy(e) {
348
- return typeof e == "function" ? h(this, o).reduce((t, r, i) => {
349
- const s = e(r, i, this);
350
- return t[s] = t[s] ? t[s] + 1 : 1, t;
351
- }, {}) : h(this, o).reduce((t, r) => {
352
- if (!["string", "number"].includes(typeof r))
353
- throw new TypeError("The countBy method expects the items to be strings or numbers");
354
- return t[String(r)] = t[String(r)] ? t[String(r)] + 1 : 1, t;
355
- }, {});
356
- }
357
- crossJoin(...e) {
358
- return c(U(
359
- h(this, o),
360
- ...e.map((t) => Array.isArray(t) ? t : t.all())
361
- ));
362
- }
363
- diff(e) {
364
- return Array.isArray(e) ? c(h(this, o).filter((t) => !e.includes(t))) : c(h(this, o).filter((t) => !e.contains(t)));
365
- }
366
- doesntContain(e, t) {
367
- return typeof e == "function" ? h(this, o).every((r, i) => !e(r, i, this)) : h(this, o).every((r) => {
368
- if (typeof t > "u")
369
- return r != e;
370
- if (typeof e != "string")
371
- throw new TypeError("The key must be a string");
372
- return r[e] != t;
373
- });
374
- }
375
- dump() {
376
- console.log(this.toArray());
377
- }
378
- duplicates(e) {
379
- return c(typeof e == "string" ? h(this, o).reduce((t, r, i) => (h(this, o).slice(i + 1).some((s) => s[e] == r[e]) && t.push(r[e]), t), []) : h(this, o).reduce((t, r, i) => (h(this, o).slice(i + 1).some((s) => s == r) && t.push(r), t), []));
380
- }
381
- duplicatesStrict(e) {
382
- return c(typeof e == "string" ? h(this, o).reduce((t, r, i) => (h(this, o).slice(i + 1).some((s) => s[e] === r[e]) && t.push(r[e]), t), []) : h(this, o).reduce((t, r, i) => (h(this, o).slice(i + 1).some((s) => s === r) && t.push(r), t), []));
383
- }
384
- each(e) {
385
- let t = 0;
386
- for (const r of this) {
387
- if (e(r, t, this) === !1)
388
- break;
389
- t++;
390
- }
391
- return this;
392
- }
393
- eachSpread(e) {
394
- for (const t of this) {
395
- if (!Array.isArray(t) && !$(t))
396
- throw new TypeError("The items in the collection must be arrays or collections");
397
- const r = Array.isArray(t) ? t : t.all();
398
- if (e(...r) === !1)
399
- break;
400
- }
401
- return this;
402
- }
403
- ensure(e) {
404
- const t = Array.isArray(e) ? e : [e];
405
- return h(this, o).forEach((r, i) => {
406
- if (!t.some((s) => typeof s == "string" ? typeof r === s : r instanceof s))
407
- throw new TypeError(`The item at index ${i} is not of the expected type`);
408
- }), this;
409
- }
410
- every(e) {
411
- return h(this, o).every((t, r) => e(t, r, this));
412
- }
413
- except(e) {
414
- return c(h(this, o).filter((t, r) => !e.includes(r)));
415
- }
416
- filter(e) {
417
- return c(h(this, o).filter((t, r) => typeof e != "function" ? !!t : e(t, r, this)));
418
- }
419
- first(e) {
420
- return typeof e == "function" ? h(this, o).find((t, r) => e(t, r, this)) ?? null : h(this, o)[0] ?? null;
421
- }
422
- firstOrFail(e) {
423
- const t = this.first(e);
424
- if (t === null)
425
- throw new Error("No matching item found");
426
- return t;
427
- }
428
- firstWhere(e, t, r) {
429
- if (typeof e != "string")
430
- throw new TypeError("The key must be a string");
431
- if (typeof t > "u")
432
- return this.first((i) => !!i[e]);
433
- if (typeof r > "u")
434
- return h(this, o).find((i) => i[e] == t) ?? null;
435
- if (typeof t != "string")
436
- throw new TypeError("The operator must be a string");
437
- return r === null ? h(this, o).find((i) => i[e] === null) ?? null : h(this, o).find((i) => {
438
- switch (t) {
439
- case "=":
440
- return i[e] == r;
441
- case "!=":
442
- return i[e] != r;
443
- case ">":
444
- return i[e] > r;
445
- case "<":
446
- return i[e] < r;
447
- case ">=":
448
- return i[e] >= r;
449
- case "<=":
450
- return i[e] <= r;
451
- default:
452
- throw new Error("Unsupported operator");
453
- }
454
- }) ?? null;
455
- }
456
- flatMap(e) {
457
- return c(h(this, o).flatMap((t, r) => e(t, r, this)));
458
- }
459
- forget(e) {
460
- return h(this, o).splice(e, 1), _(this), this;
461
- }
462
- forPage(e, t) {
463
- return c(h(this, o).slice((e - 1) * t, e * t));
464
- }
465
- get(e, t) {
466
- if (typeof e != "number")
467
- throw new TypeError("The key must be a number");
468
- return typeof t > "u" ? h(this, o)[e] ?? null : typeof t == "function" ? h(this, o)[e] ?? t() : h(this, o)[e] ?? t;
469
- }
470
- groupBy(e) {
471
- const t = Array.isArray(e) ? e : [e];
472
- return h(this, o).reduce((r, i, s) => {
473
- const u = t.map((a) => {
474
- if (typeof a == "function") {
475
- const d = a(i, s, this);
476
- return Array.isArray(d) ? d : [d];
477
- }
478
- return [String(i[a])];
479
- });
480
- return U(...u).forEach((a) => {
481
- const d = Array.isArray(a) ? a.join(".") : a;
482
- f.set(r, d, [
483
- ...f.get(r, d, []),
484
- i
485
- ]);
486
- }), r;
487
- }, {});
488
- }
489
- has(e) {
490
- return h(this, o).length > e;
491
- }
492
- hasAny(e) {
493
- return e.some((t) => this.has(t));
494
- }
495
- implode(e, t) {
496
- if (typeof t > "u") {
497
- if (typeof e != "string")
498
- throw new TypeError("The glue must be a string");
499
- if (!h(this, o).every((r) => ["string", "number"].includes(typeof r)))
500
- throw new TypeError("The items must be strings or numbers");
501
- return h(this, o).join(e);
502
- }
503
- if (typeof e == "function")
504
- return h(this, o).map((r, i) => e(r, i, this)).join(t);
505
- if (typeof e != "string")
506
- throw new TypeError("The key must be a string");
507
- if (!h(this, o).every((r) => typeof r == "object"))
508
- throw new TypeError("The items must be objects");
509
- return h(this, o).map((r) => r[e]).join(t);
510
- }
511
- intersect(e) {
512
- return Array.isArray(e) ? c(h(this, o).filter((t) => e.includes(t))) : c(h(this, o).filter((t) => e.contains(t)));
513
- }
514
- isEmpty() {
515
- return h(this, o).length === 0;
516
- }
517
- isNotEmpty() {
518
- return !this.isEmpty();
519
- }
520
- join(e, t) {
521
- return typeof t > "u" ? h(this, o).join(e) : h(this, o).slice(0, -1).join(e) + t + h(this, o)[h(this, o).length - 1];
522
- }
523
- keyBy(e) {
524
- if (typeof e == "function")
525
- return h(this, o).reduce((t, r, i) => (t[e(r, i, this)] = r, t), {});
526
- if (typeof e != "string")
527
- throw new TypeError("The key must be a string");
528
- return h(this, o).reduce((t, r) => (t[String(r[e])] = r, t), {});
529
- }
530
- last(e) {
531
- return typeof e == "function" ? h(this, o).toReversed().find((t, r) => e(t, r, this)) ?? null : h(this, o)[h(this, o).length - 1] ?? null;
532
- }
533
- map(e) {
534
- return c(h(this, o).map((t, r) => e(t, r, this)));
535
- }
536
- mapInto(e) {
537
- return c(h(this, o).map((t) => new e(t)));
538
- }
539
- mapSpread(e) {
540
- return c(h(this, o).map((t) => {
541
- if (!Array.isArray(t) && !$(t))
542
- throw new TypeError("The items in the collection must be arrays or collections");
543
- const r = Array.isArray(t) ? t : t.all();
544
- return e(...r);
545
- }));
546
- }
547
- mapToGroups(e) {
548
- return h(this, o).reduce((t, r, i) => {
549
- const s = e(r, i, this);
550
- return Object.entries(s).forEach(([u, l]) => {
551
- t[u] = t[u] ?? [], t[u].push(l);
552
- }), t;
553
- }, {});
554
- }
555
- mapWithKeys(e) {
556
- return h(this, o).reduce((t, r, i) => {
557
- const s = e(r, i, this);
558
- return Object.entries(s).forEach(([u, l]) => {
559
- t[u] = l;
560
- }), t;
561
- }, {});
562
- }
563
- max(e) {
564
- return typeof e == "string" ? h(this, o).reduce((t, r) => r[e] > t ? r[e] : t, h(this, o)[0][e]) : h(this, o).reduce((t, r) => r > t ? r : t, h(this, o)[0]);
565
- }
566
- median(e) {
567
- if (typeof e == "string") {
568
- const i = this.pluck(e).sort(), s = Math.floor(i.count() / 2);
569
- return i.count() % 2 === 0 ? c([q(i, s - 1), q(i, s)]).avg() : q(i, s);
570
- }
571
- const t = h(this, o).toSorted(), r = Math.floor(t.length / 2);
572
- return t.length % 2 === 0 ? c([t[r - 1], t[r]]).avg() : t[r] ?? null;
573
- }
574
- merge(e) {
575
- return Array.isArray(e) ? c([...h(this, o), ...e]) : c([...h(this, o), ...e.all()]);
576
- }
577
- min(e) {
578
- return typeof e == "string" ? h(this, o).reduce((t, r) => r[e] < t ? r[e] : t, h(this, o)[0][e]) : h(this, o).reduce((t, r) => r < t ? r : t, h(this, o)[0]);
579
- }
580
- mode(e) {
581
- const t = typeof e == "string" ? this.filter((i) => ["number", "string"].includes(typeof i[e])).countBy((i) => i[e]) : this.countBy(), r = Math.max(...Object.values(t));
582
- return Object.entries(t).filter(([, i]) => i === r).map(([i]) => i);
583
- }
584
- nth(e, t = 0) {
585
- return this.chunk(e).filter((r) => r.count() > t).map((r) => r.get(t));
586
- }
587
- only(e) {
588
- return c(h(this, o).filter((t, r) => e.includes(r)));
589
- }
590
- pad(e, t = null) {
591
- const r = h(this, o).slice();
592
- for (; r.length < Math.abs(e); )
593
- e > 0 ? r.push(t) : r.unshift(t);
594
- return c(r);
595
- }
596
- partition(e) {
597
- return [
598
- this.filter(e),
599
- this.reject(e)
600
- ];
601
- }
602
- percentage(e, t = 2) {
603
- return Math.round(
604
- 100 * (10 ^ t) * this.filter(e).count() / h(this, o).length
605
- ) / (10 ^ t);
606
- }
607
- pipe(e) {
608
- return e(this);
609
- }
610
- pipeInto(e) {
611
- return new e(this);
612
- }
613
- pipeThrough(e) {
614
- return e.reduce((t, r) => {
615
- if (!$(t) && !Array.isArray(t))
616
- throw new TypeError("The pipeline expects the carry to be a collection or an array");
617
- return r(
618
- $(t) ? t : c(t)
619
- );
620
- }, this);
621
- }
622
- pluck(e) {
623
- return this.map((t) => t[e]);
624
- }
625
- pop(e = 1) {
626
- const t = h(this, o).splice(h(this, o).length - e, e);
627
- return _(this), e === 1 ? t[0] ?? null : c(t);
628
- }
629
- prepend(e) {
630
- const t = h(this, o).unshift(e);
631
- return _(this), t;
632
- }
633
- pull(e) {
634
- const t = h(this, o).splice(e, 1)[0] ?? null;
635
- return _(this), t;
636
- }
637
- push(...e) {
638
- const t = h(this, o).push(...e);
639
- return _(this), t;
640
- }
641
- put(e, t) {
642
- return h(this, o).splice(e, 1, t), _(this), this;
643
- }
644
- random(e = 1) {
645
- if (h(this, o).length < e)
646
- throw new Error("The collection has fewer items than the requested amount");
647
- const t = c(f.sampleSize(h(this, o), e));
648
- return e === 1 ? t.first() : t;
649
- }
650
- reduce(e, t = null) {
651
- return h(this, o).reduce((r, i, s) => e(r, i, s, this), t);
652
- }
653
- reject(e) {
654
- return this.filter((t, r) => !e(t, r, this));
655
- }
656
- replace(e) {
657
- const t = h(this, o).slice();
658
- return Object.entries(e).forEach(([r, i]) => {
659
- t[parseInt(r)] = i;
660
- }), c(t);
661
- }
662
- reverse() {
663
- return c(h(this, o).toReversed());
664
- }
665
- search(e, t = !1) {
666
- if (typeof e != "function" || h(this, o).every((i) => typeof i == "function")) {
667
- const i = h(this, o).findIndex((s) => t ? s === e : s == e);
668
- return i === -1 ? !1 : i;
669
- }
670
- const r = h(this, o).findIndex((i, s) => e(i, s, this));
671
- return r === -1 ? !1 : r;
672
- }
673
- select(e) {
674
- return this.map((t) => e.reduce((r, i) => (r[i] = t[i], r), {}));
675
- }
676
- shift(e = 1) {
677
- const t = h(this, o).splice(0, e);
678
- return _(this), e === 1 ? t[0] ?? null : c(t);
679
- }
680
- shuffle() {
681
- return c(f.shuffle(h(this, o)));
682
- }
683
- skip(e) {
684
- return c(h(this, o).slice(e));
685
- }
686
- skipUntil(e) {
687
- return typeof e == "function" ? this.skip(h(this, o).findIndex((t, r) => e(t, r, this))) : this.skip(h(this, o).findIndex((t) => t == e));
688
- }
689
- skipWhile(e) {
690
- return typeof e == "function" ? this.skip(h(this, o).findIndex((t, r) => !e(t, r, this))) : this.skip(h(this, o).findIndex((t) => t != e));
691
- }
692
- slice(e, t) {
693
- return c(typeof t > "u" ? h(this, o).slice(e) : typeof e > "u" ? h(this, o).slice(0, t) : h(this, o).slice(e, e + t));
694
- }
695
- sliding(e, t = 1) {
696
- const r = [];
697
- for (let i = 0; i < h(this, o).length && !(i + e > h(this, o).length); i += t)
698
- r.push(h(this, o).slice(i, i + e));
699
- return c(r.map((i) => c(i)));
700
- }
701
- sole(e, t) {
702
- if (typeof e == "function") {
703
- const r = this.filter(e);
704
- return r.count() === 1 ? r.first() : null;
705
- }
706
- if (typeof e == "string") {
707
- const r = this.where(e, t);
708
- return r.count() === 1 ? r.first() : null;
709
- }
710
- return h(this, o).length === 1 ? this.first() : null;
711
- }
712
- some(...e) {
713
- return this.contains(...e);
58
+ document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((i) => {
59
+ const c = i.id.replace("luminix-error::", "");
60
+ t[c] = pe(c, "error");
61
+ }), this.bags = {
62
+ default: new R(t)
63
+ };
714
64
  }
715
- sort(e) {
716
- return c(h(this, o).toSorted(e));
65
+ bag(t = "default") {
66
+ return this.bags[t] || (this.bags[t] = new R({})), this.bags[t];
717
67
  }
718
- sortBy(e, t = "asc") {
719
- if (typeof e == "function") {
720
- let r = -1;
721
- return c(h(this, o).toSorted((i, s) => (r++, e(i, r, this) - e(s, r, this))));
722
- }
723
- if (Array.isArray(e))
724
- return e.every((r) => Array.isArray(r)) ? c(h(this, o).toSorted((r, i) => {
725
- for (const [s, u] of e) {
726
- const l = r[s] ?? -1 / 0, a = i[s] ?? -1 / 0;
727
- if (l > a)
728
- return u === "asc" ? 1 : -1;
729
- if (l < a)
730
- return u === "asc" ? -1 : 1;
731
- }
732
- return 0;
733
- })) : c(h(this, o).toSorted((r, i) => {
734
- for (const s of e) {
735
- const u = s(r, i);
736
- if (u !== 0)
737
- return u;
738
- }
739
- return 0;
740
- }));
741
- if (typeof e != "string")
742
- throw new TypeError("The key must be a string");
743
- return c(h(this, o).toSorted((r, i) => {
744
- const s = r[e] ?? -1 / 0, u = i[e] ?? -1 / 0;
745
- return s > u ? t === "asc" ? 1 : -1 : s < u ? t === "asc" ? -1 : 1 : 0;
746
- }));
747
- }
748
- sortDesc() {
749
- return this.sort((e, t) => e > t ? -1 : e < t ? 1 : 0);
750
- }
751
- splice(e, t, ...r) {
752
- const i = t === void 0 ? h(this, o).length : t, s = h(this, o).splice(e, i, ...r);
753
- return _(this), c(s);
754
- }
755
- split(e) {
756
- const t = [];
757
- for (let r = 0; r < e; r++) {
758
- const i = h(this, o).slice(
759
- t.flat().length,
760
- t.flat().length + Math.min(
761
- Math.ceil((h(this, o).length - t.flat().length) / (e - r)),
762
- h(this, o).length - t.flat().length
763
- )
764
- );
765
- t.push(c(i));
766
- }
767
- return c(t);
768
- }
769
- splitIn(e) {
770
- const t = Math.ceil(h(this, o).length / e);
771
- return this.chunk(t);
772
- }
773
- sum(e) {
774
- return typeof e == "string" ? h(this, o).reduce((t, r) => {
775
- const i = r[e];
776
- if (typeof i != "number")
777
- throw new TypeError("The items must be numbers");
778
- return t + i;
779
- }, 0) : h(this, o).reduce((t, r) => {
780
- if (typeof r != "number")
781
- throw new TypeError("The items must be numbers");
782
- return t + r;
783
- }, 0);
784
- }
785
- take(e) {
786
- return c(h(this, o).slice(0, e));
787
- }
788
- takeUntil(e) {
789
- return typeof e == "function" ? this.take(h(this, o).findIndex((t, r) => e(t, r, this))) : this.take(h(this, o).findIndex((t) => t == e));
790
- }
791
- takeWhile(e) {
792
- return typeof e == "function" ? this.take(h(this, o).findIndex((t, r) => !e(t, r, this))) : this.take(h(this, o).findIndex((t) => t != e));
793
- }
794
- tap(e) {
795
- return e(this), this;
796
- }
797
- toArray() {
798
- const e = (t) => typeof t != "object" ? t : Array.isArray(t) ? t.map(e) : t && "toArray" in t && typeof t.toArray == "function" ? t.toArray() : t && "toJson" in t && typeof t.toJson == "function" ? t.toJson() : t;
799
- return h(this, o).map(e);
800
- }
801
- toJson() {
802
- return JSON.stringify(h(this, o));
803
- }
804
- transform(e) {
805
- for (const [t, r] of h(this, o).entries())
806
- h(this, o).splice(t, 1, e(r, t, this));
807
- return _(this), this;
808
- }
809
- unique(e) {
810
- return c(typeof e == "string" ? h(this, o).filter((t, r) => !h(this, o).some((i, s) => i[e] == t[e] && s !== r)) : [...new Set(h(this, o))]);
811
- }
812
- uniqueStrict(e) {
813
- return c(typeof e == "string" ? h(this, o).filter((t, r) => !h(this, o).some((i, s) => i[e] === t[e] && s !== r)) : [...new Set(h(this, o))]);
814
- }
815
- unless(e, t, r) {
816
- return e ? typeof r == "function" && r(this) : t(this), this;
817
- }
818
- unlessEmpty(e, t) {
819
- return this.whenNotEmpty(e, t);
820
- }
821
- unlessNotEmpty(e, t) {
822
- return this.whenEmpty(e, t);
823
- }
824
- value(e) {
825
- return h(this, o).length === 0 ? null : h(this, o)[0][e];
826
- }
827
- when(e, t, r) {
828
- return e ? t(this) : typeof r == "function" && r(this), this;
829
- }
830
- whenEmpty(e, t) {
831
- return this.isEmpty() ? e(this) : typeof t == "function" && t(this), this;
832
- }
833
- whenNotEmpty(e, t) {
834
- return this.isNotEmpty() ? e(this) : typeof t == "function" && t(this), this;
835
- }
836
- where(e, t, r) {
837
- if (typeof r > "u")
838
- return c(h(this, o).filter((s) => s[e] == t));
839
- if (typeof t != "string")
840
- throw new TypeError("The operator must be a string");
841
- if (r === null)
842
- return c(h(this, o).filter((s) => s[e] === null));
843
- const i = {
844
- "=": (s) => s[e] == r,
845
- "!=": (s) => s[e] != r,
846
- ">": (s) => s[e] > r,
847
- "<": (s) => s[e] < r,
848
- ">=": (s) => s[e] >= r,
849
- "<=": (s) => s[e] <= r
850
- };
851
- if (!(t in i))
852
- throw new Error("Unsupported operator");
853
- return c(h(this, o).filter((s, u) => i[t](s, u, this)));
854
- }
855
- whereStrict(e, t, r) {
856
- if (typeof r > "u")
857
- return c(h(this, o).filter((s) => s[e] === t));
858
- if (typeof t != "string")
859
- throw new TypeError("The operator must be a string");
860
- if (r === null)
861
- return c(h(this, o).filter((s) => s[e] === null));
862
- const i = {
863
- "=": (s) => s[e] === r,
864
- "!=": (s) => s[e] !== r,
865
- ">": (s) => s[e] > r,
866
- "<": (s) => s[e] < r,
867
- ">=": (s) => s[e] >= r,
868
- "<=": (s) => s[e] <= r
869
- };
870
- if (!(t in i))
871
- throw new Error("Unsupported operator");
872
- return c(h(this, o).filter((s, u) => i[t](s, u, this)));
68
+ add(t, e, i = "default") {
69
+ this.bag(i).set(t, e);
873
70
  }
874
- whereBetween(e, [t, r]) {
875
- return c(h(this, o).filter((i) => i[e] >= t && i[e] <= r));
71
+ set(t, e = "default") {
72
+ this.bag(e).set(".", t);
876
73
  }
877
- whereIn(e, t) {
878
- return c(h(this, o).filter((r) => t.includes(r[e])));
74
+ all(t = "default") {
75
+ return this.bag(t).all();
879
76
  }
880
- whereInstanceOf(e) {
881
- return c(h(this, o).filter((t) => t instanceof e));
77
+ get(t, e = "default") {
78
+ return this.bag(e).get(t, null);
882
79
  }
883
- whereNotBetween(e, [t, r]) {
884
- return c(h(this, o).filter((i) => i[e] < t || i[e] > r));
80
+ clear(t = "default") {
81
+ this.bag(t).set(".", {});
885
82
  }
886
- whereNotIn(e, t) {
887
- return c(h(this, o).filter((r) => !t.includes(r[e])));
83
+ }
84
+ class xe {
85
+ constructor(t) {
86
+ this._debug = t;
888
87
  }
889
- whereNotNull(e) {
890
- return c(h(this, o).filter((t) => t[e] !== null));
88
+ emergency(...t) {
89
+ this._debug && console.error(...t);
891
90
  }
892
- whereNull(e) {
893
- return c(h(this, o).filter((t) => t[e] === null));
91
+ alert(...t) {
92
+ this._debug && console.error(...t);
894
93
  }
895
- zip(e) {
896
- return Array.isArray(e) ? c(
897
- h(this, o).map((t, r) => [t, e[r] ?? null])
898
- ) : c(
899
- h(this, o).map((t, r) => [t, e.get(r)])
900
- );
94
+ critical(...t) {
95
+ this._debug && console.error(...t);
901
96
  }
902
- // HasEvents methods
903
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
904
- on(e, t) {
905
- throw new b();
97
+ error(...t) {
98
+ this._debug && console.error(...t);
906
99
  }
907
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
908
- once(e, t) {
909
- throw new b();
100
+ warning(...t) {
101
+ this._debug && console.warn(...t);
910
102
  }
911
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
912
- emit(e, t) {
913
- throw new b();
103
+ notice(...t) {
104
+ this._debug && console.info(...t);
914
105
  }
915
- }
916
- o = new WeakMap();
917
- const k = A(P);
918
- var ee, te;
919
- class H extends (te = P, ee = Symbol.toStringTag, te) {
920
- constructor() {
921
- super(...arguments);
922
- m(this, ee, "Collection");
106
+ info(...t) {
107
+ this._debug && console.info(...t);
923
108
  }
924
- intersect(t) {
925
- return this.filter((r) => t.some((i) => i.getKey() === r.getKey()));
109
+ debug(...t) {
110
+ this._debug && console.debug(...t);
926
111
  }
927
112
  }
928
- const N = (...n) => {
929
- const e = new URLSearchParams();
930
- return n.forEach((t) => {
931
- const [, ...r] = t.split("?");
932
- new URLSearchParams(r.join("")).forEach((s, u) => {
933
- e.set(u, s);
934
- });
935
- }), e;
936
- };
937
- var re, se;
938
- class Je extends (se = Error, re = Symbol.toStringTag, se) {
939
- constructor(t) {
940
- super(`[Luminix] Model "${t}" does not have a primary key`);
941
- m(this, re, "ModelWithoutPrimaryKeyException");
113
+ var O, B;
114
+ class Me extends (B = Error, O = Symbol.toStringTag, B) {
115
+ constructor(e) {
116
+ super(`[Luminix] Model "${e}" does not have a primary key`);
117
+ p(this, O, "ModelWithoutPrimaryKeyException");
942
118
  }
943
119
  }
944
- const De = A(S);
945
- class Ue {
946
- constructor(e, t, r = {}) {
947
- m(this, "bag");
948
- this.facades = e, this.abstract = t, this.query = r, this.bag = new De(r), this.bag.on("change", () => {
120
+ class Ee extends q {
121
+ constructor(e, i, s = {}) {
122
+ super();
123
+ p(this, "bag");
124
+ this.services = e, this.abstract = i, this.query = s, this.bag = new R(s), this.bag.on("change", () => {
949
125
  this.emit("change", {
950
- data: this.bag
126
+ data: this.bag,
127
+ source: this
951
128
  });
952
129
  });
953
130
  }
954
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
955
- on(e, t) {
956
- throw new b();
957
- }
958
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
959
- once(e, t) {
960
- throw new b();
961
- }
962
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
963
- emit(e, t) {
964
- throw new b();
965
- }
966
131
  lock(e) {
967
132
  this.bag.lock(e);
968
133
  }
969
- whereBetween(e, t) {
970
- return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${f.camelCase(e)}Between`, t), this;
134
+ whereBetween(e, i) {
135
+ return this.where(e, "between", i);
971
136
  }
972
- whereNotBetween(e, t) {
973
- return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${f.camelCase(e)}NotBetween`, t), this;
137
+ whereNotBetween(e, i) {
138
+ return this.where(e, "notBetween", i);
974
139
  }
975
140
  whereNull(e) {
976
- return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${f.camelCase(e)}Null`, !0), this;
141
+ return this.where(e, "null", null);
977
142
  }
978
143
  whereNotNull(e) {
979
- return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${f.camelCase(e)}NotNull`, !0), this;
144
+ return this.where(e, "notNull", null);
980
145
  }
981
146
  limit(e) {
982
147
  return this.bag.set("per_page", e), this;
983
148
  }
984
- where(e, t, r) {
149
+ where(e, i, s) {
985
150
  if (this.bag.has("where") || this.bag.set("where", {}), typeof e == "function")
986
151
  return e(this) || this;
987
- if (typeof r > "u")
988
- return this.bag.set(`where.${f.camelCase(e)}`, t), this;
989
- if (typeof t != "string")
990
- throw new Error(`Invalid operator ${t} provided for where clause.`);
991
- const s = {
152
+ if (typeof s > "u")
153
+ return this.bag.set(`where.${e}`, i), this;
154
+ if (typeof i != "string")
155
+ throw new Error(`Invalid operator ${i} provided for where clause.`);
156
+ const g = {
992
157
  "=": "",
993
- "!=": "NotEquals",
994
- ">": "GreaterThan",
995
- ">=": "GreaterThanOrEquals",
996
- "<": "LessThan",
997
- "<=": "LessThanOrEquals"
998
- }[t] || f.upperFirst(f.camelCase(t));
999
- return this.bag.set(`where.${f.camelCase(e)}${s}`, r), this;
158
+ "!=": "notEquals",
159
+ ">": "greaterThan",
160
+ ">=": "greaterThanOrEquals",
161
+ "<": "lessThan",
162
+ "<=": "lessThanOrEquals"
163
+ }[i] || i;
164
+ return this.bag.set(`where.${e}:${g}`, s), this;
1000
165
  }
1001
166
  with(e) {
1002
- const t = this.bag.get("with", []);
1003
- return (Array.isArray(e) ? e : [e]).forEach((i) => {
1004
- t.includes(i) || t.push(i);
1005
- }), this.bag.set("with", t), this;
167
+ const i = this.bag.get("with", []);
168
+ return (Array.isArray(e) ? e : [e]).forEach((c) => {
169
+ i.includes(c) || i.push(c);
170
+ }), this.bag.set("with", i), this;
1006
171
  }
1007
172
  withOnly(e) {
1008
173
  return this.bag.set("with", Array.isArray(e) ? e : [e]), this;
1009
174
  }
1010
175
  without(e) {
1011
- const t = this.bag.get("with", []);
1012
- return (Array.isArray(e) ? e : [e]).forEach((i) => {
1013
- t.includes(i) && t.splice(t.indexOf(i), 1);
1014
- }), this.bag.set("with", t), this;
176
+ const i = this.bag.get("with", []);
177
+ return (Array.isArray(e) ? e : [e]).forEach((c) => {
178
+ i.includes(c) && i.splice(i.indexOf(c), 1);
179
+ }), this.bag.set("with", i), this;
1015
180
  }
1016
- orderBy(e, t = "asc") {
1017
- return this.bag.set("order_by", `${e}:${t}`), this;
181
+ orderBy(e, i = "asc") {
182
+ return this.bag.set("order_by", `${e}:${i}`), this;
1018
183
  }
1019
184
  searchBy(e) {
1020
185
  return this.bag.set("q", e), this;
@@ -1026,158 +191,153 @@ class Ue {
1026
191
  return this.bag.delete(e), this;
1027
192
  }
1028
193
  include(e) {
1029
- for (const [t, r] of e.entries())
1030
- this.bag.set(t, r);
194
+ for (const [i, s] of e.entries())
195
+ this.bag.set(i, s);
1031
196
  return this;
1032
197
  }
1033
- async exec(e = 1, t) {
198
+ async exec(e = 1, i) {
1034
199
  try {
1035
200
  this.bag.set("page", e), this.emit("submit", {
1036
- data: this.bag
201
+ data: this.bag,
202
+ source: this
1037
203
  });
1038
- const { data: r } = await this.facades.route.call(`luminix.${this.abstract}.index`, {
1039
- params: this.bag.all(),
1040
- errorBag: `${this.abstract}.fetch`
1041
- }), i = this.facades.model.make(this.abstract), s = c(r.data.map((u) => {
1042
- const l = new i(u);
1043
- return l.exists = !0, this.facades.model.emit("fetch", {
204
+ const s = await this.services.route.call(
205
+ `luminix.${this.abstract}.index`,
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", {
1044
210
  class: this.abstract,
1045
- model: l
1046
- }), l;
1047
- }), H);
1048
- if (t) {
1049
- const [u] = t.split("?");
211
+ model: u,
212
+ source: this.services.model
213
+ }), u;
214
+ }));
215
+ if (i) {
216
+ const [l] = i.split("?");
1050
217
  return {
1051
- ...r,
1052
- data: s,
218
+ ...s.json(),
219
+ data: g,
1053
220
  links: {
1054
- first: `${u}?${N(t, r.links.first).toString()}`,
1055
- last: `${u}?${N(t, r.links.last).toString()}`,
1056
- next: r.links.next && `${u}?${N(t, r.links.next).toString()}`,
1057
- prev: r.links.prev && `${u}?${N(t, r.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()}`
1058
225
  },
1059
226
  meta: {
1060
- ...r.meta,
1061
- links: r.meta.links.map((l) => ({
1062
- ...l,
1063
- url: l.url && `${u}?${N(t, l.url).toString()}`
227
+ ...s.json("meta"),
228
+ links: s.json("meta").links.map((u) => ({
229
+ ...u,
230
+ url: u.url && `${l}?${T.merge(i, u.url).toString()}`
1064
231
  }))
1065
232
  }
1066
233
  };
1067
234
  }
1068
235
  return {
1069
- ...r,
1070
- data: s
236
+ ...s.json(),
237
+ data: g
1071
238
  };
1072
- } catch (r) {
239
+ } catch (s) {
1073
240
  throw this.emit("error", {
1074
- error: r
1075
- }), r;
241
+ error: s,
242
+ source: this
243
+ }), s;
1076
244
  }
1077
245
  }
1078
- async get(e = 1, t) {
1079
- const r = await this.exec(e, t);
246
+ async get(e = 1, i) {
247
+ const s = await this.exec(e, i);
1080
248
  return this.emit("success", {
1081
- response: r,
1082
- items: r.data
1083
- }), r;
249
+ response: s,
250
+ items: s.data,
251
+ source: this
252
+ }), s;
1084
253
  }
1085
254
  async first() {
1086
255
  const e = await this.limit(1).exec(1);
1087
256
  return this.emit("success", {
1088
257
  response: e,
1089
- items: e.data.first()
258
+ items: e.data.first(),
259
+ source: this
1090
260
  }), e.data.first();
1091
261
  }
1092
262
  async find(e) {
1093
- const t = this.facades.model.schema(this.abstract).primaryKey;
1094
- if (!t)
1095
- throw new Je(this.abstract);
1096
- const r = await this.where(t, e).limit(1).exec(1);
263
+ const i = this.services.model.schema(this.abstract).primaryKey;
264
+ if (!i)
265
+ throw new Me(this.abstract);
266
+ const s = await this.where(i, e).limit(1).exec(1);
1097
267
  return this.emit("success", {
1098
- response: r,
1099
- items: r.data.sole()
1100
- }), r.data.sole();
268
+ response: s,
269
+ items: s.data.sole(),
270
+ source: this
271
+ }), s.data.sole();
1101
272
  }
1102
273
  async all() {
1103
- const e = this.facades.config.get("luminix.backend.api.max_per_page", 150), t = await this.limit(e).exec(1), r = t.meta.last_page;
1104
- if (r === 1)
1105
- return t.data;
1106
- const i = Array.from({ length: r - 1 }, (l, a) => a + 2), s = await Promise.all(
1107
- i.map((l) => this.limit(e).exec(l))
1108
- ), u = c(
1109
- s.reduce((l, a) => (l.push(...a.data), l), t.data).all(),
1110
- H
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
+ if (s === 1)
276
+ return i.data;
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()
1111
281
  );
1112
282
  return this.emit("success", {
1113
283
  response: {
1114
- ...t,
1115
- data: u
284
+ ...i,
285
+ data: l
1116
286
  },
1117
- items: u
1118
- }), u;
287
+ items: l,
288
+ source: this
289
+ }), l;
1119
290
  }
1120
291
  }
1121
- const He = A(Ue);
1122
- var ie, ne;
1123
- class T extends (ne = Error, ie = Symbol.toStringTag, ne) {
1124
- constructor(t) {
1125
- super(`[Luminix] Expected ${t} to be reducible.`);
1126
- m(this, ie, "NotReducibleException");
292
+ var C, I;
293
+ class w extends (I = TypeError, C = Symbol.toStringTag, I) {
294
+ constructor(e, i = "Model") {
295
+ super(`[Luminix] "${e}" expects ${i}`);
296
+ p(this, C, "NotModelException");
1127
297
  }
1128
298
  }
1129
- var oe, he;
1130
- class M extends (he = TypeError, oe = Symbol.toStringTag, he) {
1131
- constructor(t, r = "Model") {
1132
- super(`[Luminix] "${t}" expects ${r}`);
1133
- m(this, oe, "NotModelException");
299
+ var P, Q;
300
+ class $e extends (Q = Error, P = Symbol.toStringTag, Q) {
301
+ constructor(e, i, s, c) {
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");
1134
304
  }
1135
305
  }
1136
- var ue, ae;
1137
- class We extends (ae = Error, ue = Symbol.toStringTag, ae) {
1138
- constructor(t, r, i, s) {
1139
- super(`[Luminix] Could not determine inverse relation for "${r}" in model "${t}". Please specify a relation in model "${i}" of type ${s} that points back to "${t}".`);
1140
- m(this, ue, "NoInverseRelationException");
1141
- }
1142
- }
1143
- var le, ce;
1144
- class Ge extends (ce = Error, le = Symbol.toStringTag, ce) {
1145
- constructor(t) {
1146
- super(`[Luminix] Relation "${t}" is not supported`);
1147
- m(this, le, "UnsupportedRelationException");
306
+ var D, H;
307
+ class _e extends (H = Error, D = Symbol.toStringTag, H) {
308
+ constructor(e) {
309
+ super(`[Luminix] Relation "${e}" is not supported`);
310
+ p(this, D, "UnsupportedRelationException");
1148
311
  }
1149
312
  }
1150
- function E(n) {
313
+ function f(n) {
1151
314
  return typeof n == "object" && n !== null && n.__isModel === !0;
1152
315
  }
1153
- class K {
1154
- constructor(e, t, r, i = null) {
1155
- m(this, "unsubscribeQuery", null);
1156
- if (this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !E(i) && !($(i) && i.every(E)))
1157
- throw new M("Relation.constructor()", "Model, Collection<Model> or null");
1158
- }
1159
- make(e) {
1160
- const t = this.getRelated();
1161
- if (e === null || typeof e > "u") {
316
+ class N {
317
+ constructor(t, e, i, s = null) {
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
+ throw new w("Relation.constructor()", "Model, Collection<Model> or null");
321
+ }
322
+ make(t) {
323
+ const e = this.getRelated();
324
+ if (t === null || typeof t > "u") {
1162
325
  this.set(null);
1163
326
  return;
1164
327
  }
1165
328
  if (this.isSingle()) {
1166
- if (typeof e != "object" || Array.isArray(e))
329
+ if (typeof t != "object" || Array.isArray(t))
1167
330
  throw new TypeError("Relation.make() expects an object");
1168
- this.set(new t(e));
331
+ this.set(new e(t));
1169
332
  }
1170
333
  if (this.isMultiple()) {
1171
- if (!Array.isArray(e))
334
+ if (!Array.isArray(t))
1172
335
  throw new TypeError("Relation.make() expects an array");
1173
- this.set(c(e.map((r) => new t(r))));
336
+ this.set(new x(t.map((i) => new e(i))));
1174
337
  }
1175
338
  }
1176
339
  guessInverseRelation() {
1177
- const { relations: e } = this.getRelated().getSchema();
1178
- if (typeof this.facades.model.guessInverseRelation != "function")
1179
- throw new T("ModelFacade");
1180
- const t = this.getType(), r = this.facades.model.guessInverseRelation({
340
+ const { relations: t } = this.getRelated().getSchema(), e = this.getType(), i = this.services.model.guessInverseRelation({
1181
341
  HasOne: ["BelongsTo"],
1182
342
  HasMany: ["BelongsTo"],
1183
343
  BelongsTo: ["HasOne", "HasMany"],
@@ -1186,20 +346,20 @@ class K {
1186
346
  MorphOne: ["MorphTo"],
1187
347
  MorphMany: ["MorphTo"],
1188
348
  MorphToMany: ["MorphToMany"]
1189
- }, this.parent, t, this.getRelated());
1190
- if (!(t in r))
1191
- throw new Ge(t);
1192
- for (const i in e) {
1193
- const s = e[i];
1194
- if ((s.model === this.parent.getType() || ["MorphOne", "MorphMany"].includes(t)) && r[t].includes(s.type))
1195
- return i;
349
+ }, this.parent, e, this.getRelated());
350
+ if (!(e in i))
351
+ throw new _e(e);
352
+ for (const s in t) {
353
+ const c = t[s];
354
+ if ((c.model === this.parent.getType() || ["MorphOne", "MorphMany"].includes(e)) && i[e].includes(c.type))
355
+ return s;
1196
356
  }
1197
- throw new We(this.parent.getType(), t, this.getRelated().getSchemaName(), r[t].join(" or "));
357
+ throw new $e(this.parent.getType(), e, this.getRelated().getSchemaName(), i[e].join(" or "));
1198
358
  }
1199
- set(e) {
1200
- if (e !== null && !E(e) && !($(e) && e.every(E)))
1201
- throw new M("Relation.set()", "Model, Collection<Model> or null");
1202
- !this.items || E(this.items) ? this.items = e : $(e) && this.items.splice(0, this.items.count(), ...e);
359
+ 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);
1203
363
  }
1204
364
  getForeignKey() {
1205
365
  return this.meta.foreignKey;
@@ -1214,13 +374,13 @@ class K {
1214
374
  return this.meta.model;
1215
375
  }
1216
376
  getRelated() {
1217
- return this.facades.model.make(this.meta.model);
377
+ return this.services.model.make(this.meta.model);
1218
378
  }
1219
379
  query() {
1220
- const e = this.getRelated().query();
1221
- return this.unsubscribeQuery && this.unsubscribeQuery(), this.unsubscribeQuery = e.on("success", (t) => {
1222
- this.items = t.items;
1223
- }), e;
380
+ const t = this.getRelated().query();
381
+ return this.unsubscribeQuery && this.unsubscribeQuery(), this.unsubscribeQuery = t.on("success", (e) => {
382
+ this.items = e.items;
383
+ }), t;
1224
384
  }
1225
385
  isLoaded() {
1226
386
  return this.items !== null;
@@ -1229,40 +389,40 @@ class K {
1229
389
  return this.items;
1230
390
  }
1231
391
  isSingle() {
1232
- return E(this.items);
392
+ return f(this.items);
1233
393
  }
1234
394
  isMultiple() {
1235
- return $(this.items);
395
+ return this.items instanceof x;
1236
396
  }
1237
397
  getParent() {
1238
398
  return this.parent;
1239
399
  }
1240
- where(...e) {
1241
- return this.query().where(...e);
400
+ where(...t) {
401
+ return this.query().where(...t);
1242
402
  }
1243
- whereNull(e) {
1244
- return this.query().whereNull(e);
403
+ whereNull(t) {
404
+ return this.query().whereNull(t);
1245
405
  }
1246
- whereNotNull(e) {
1247
- return this.query().whereNotNull(e);
406
+ whereNotNull(t) {
407
+ return this.query().whereNotNull(t);
1248
408
  }
1249
- whereBetween(e, t) {
1250
- return this.query().whereBetween(e, t);
409
+ whereBetween(t, e) {
410
+ return this.query().whereBetween(t, e);
1251
411
  }
1252
- whereNotBetween(e, t) {
1253
- return this.query().whereNotBetween(e, t);
412
+ whereNotBetween(t, e) {
413
+ return this.query().whereNotBetween(t, e);
1254
414
  }
1255
- orderBy(e, t = "asc") {
1256
- return this.query().orderBy(e, t);
415
+ orderBy(t, e = "asc") {
416
+ return this.query().orderBy(t, e);
1257
417
  }
1258
- searchBy(e) {
1259
- return this.query().searchBy(e);
418
+ searchBy(t) {
419
+ return this.query().searchBy(t);
1260
420
  }
1261
421
  minified() {
1262
422
  return this.query().minified();
1263
423
  }
1264
- limit(e) {
1265
- return this.query().limit(e);
424
+ limit(t) {
425
+ return this.query().limit(t);
1266
426
  }
1267
427
  // get(page = 1, perPage = 15, replaceLinksWith?: string): Promise<ModelPaginatedResponse>
1268
428
  // {
@@ -1277,133 +437,161 @@ class K {
1277
437
  // return this.query().find(id);
1278
438
  // }
1279
439
  }
1280
- var de, fe;
1281
- class Ae extends (fe = Error, de = Symbol.toStringTag, fe) {
1282
- constructor(t, r) {
1283
- super(`[Luminix] Model "${t}" must be persisted before calling "${r}"`);
1284
- m(this, de, "ModelNotPersistedException");
440
+ var L, J;
441
+ class $ extends (J = Error, L = Symbol.toStringTag, J) {
442
+ constructor(e) {
443
+ super(`[Luminix] Expected ${e} to be reducible.`);
444
+ p(this, L, "NotReducibleException");
445
+ }
446
+ }
447
+ var U, F;
448
+ class Se extends (F = Error, U = Symbol.toStringTag, F) {
449
+ constructor() {
450
+ super("[Luminix] Method not implemented.");
451
+ p(this, U, "MethodNotImplementedException");
1285
452
  }
1286
453
  }
1287
- function Ve(n, e) {
1288
- var r;
1289
- r = Symbol.toStringTag;
1290
- class t {
1291
- constructor(s = {}) {
1292
- m(this, "_attributes", new S({}));
1293
- m(this, "_original", {});
1294
- m(this, "_relations", {});
1295
- m(this, "_changedKeys", []);
1296
- m(this, "exists", !1);
1297
- m(this, r, f.upperFirst(f.camelCase(e)));
1298
- this.makeRelations(), this.makeAttributes(s);
1299
- }
1300
- cast(s, u) {
1301
- return s == null || !u ? s : ["boolean", "bool"].includes(u) ? !!s : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(u) && typeof s == "string" ? new Date(s) : ["float", "double", "integer", "int"].includes(u) || u.startsWith("decimal:") ? Number(s) : s;
1302
- }
1303
- mutate(s, u) {
1304
- return s == null || !u ? s : ["boolean", "bool"].includes(u) ? !!s : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(u) && s instanceof Date ? s.toISOString() : ["float", "double", "integer", "int"].includes(u) || u.startsWith("decimal:") ? Number(s) : s;
454
+ var G, V;
455
+ class ae extends (V = Error, G = Symbol.toStringTag, V) {
456
+ constructor(e, i) {
457
+ super(`[Luminix] Model "${e}" must be persisted before calling "${i}"`);
458
+ p(this, G, "ModelNotPersistedException");
459
+ }
460
+ }
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
+ constructor(r = {}) {
465
+ super();
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
+ this.makeRelations(), this.makeAttributes(r);
474
+ }
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
+ }
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;
1305
480
  }
1306
481
  makeRelations() {
1307
- const { relations: s } = n.make("model").schema(e);
1308
- if (this._relations = {}, !s)
482
+ const { relations: r } = e.schema(s);
483
+ if (this._relations = {}, !r)
1309
484
  return;
1310
- const u = n.make("model").relationMap({}, e);
1311
- Object.entries(s).forEach(([l, a]) => {
1312
- const { type: d } = a, p = d in u ? u[d] : K;
1313
- this._relations[l] = new p(
1314
- { name: l, ...a },
1315
- n.make(),
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
+ { model: e, route: i },
490
+ { name: a, ...h },
1316
491
  this,
1317
492
  null
1318
493
  );
1319
494
  });
1320
495
  }
1321
- makeAttributes(s) {
1322
- const { relations: u } = n.make("model").schema(e), l = Object.keys(u || {}), a = f.omit(s, l);
1323
- if (this.fillable.filter((d) => !(d in a)).forEach((d) => {
1324
- a[d] = null;
1325
- }), u && Object.keys(u).forEach((d) => {
1326
- this.relation(f.camelCase(d)).make(s[d]);
1327
- }), !this.validateJsonObject(a)) {
1328
- if (n.isProduction())
1329
- throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
1330
- n.make("log").warning(`Invalid attributes for model "${e}".
496
+ 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]);
502
+ }), !this.validateJsonObject(h)) {
503
+ if (n.get("app.env", "production") === "production")
504
+ throw new TypeError(`[Luminix] Invalid attributes for model "${s}"`);
505
+ t.warning(`Invalid attributes for model "${s}".
1331
506
  This will throw an error in production.`, {
1332
- attributes: s,
1333
- abstract: e
507
+ attributes: r,
508
+ abstract: s
1334
509
  });
1335
510
  }
1336
- this._attributes = new S(a), this._original = a, this._changedKeys = [];
511
+ this._attributes.set(".", h), this._original = h, this._changedKeys.splice(0, this._changedKeys.length);
1337
512
  }
1338
513
  makePrimaryKeyReplacer() {
1339
514
  return {
1340
- [this.primaryKey]: this.getAttribute(this.primaryKey)
515
+ [this.getKeyName()]: this.getKey()
1341
516
  };
1342
517
  }
1343
- dispatchChangeEvent(s) {
518
+ dispatchChangeEvent(r) {
1344
519
  this.emit("change", {
1345
- value: s
520
+ value: r,
521
+ source: this
1346
522
  });
1347
523
  }
1348
- dispatchCreateEvent(s) {
524
+ dispatchCreateEvent(r) {
1349
525
  this.emit("create", {
1350
- value: s
1351
- }), n.make("model").emit("create", {
1352
- class: e,
1353
- model: this
526
+ value: r,
527
+ source: this
528
+ }), e.emit("create", {
529
+ class: s,
530
+ model: this,
531
+ source: e
1354
532
  });
1355
533
  }
1356
- dispatchUpdateEvent(s) {
534
+ dispatchUpdateEvent(r) {
1357
535
  this.emit("update", {
1358
- value: s
1359
- }), n.make("model").emit("update", {
1360
- class: e,
1361
- model: this
536
+ value: r,
537
+ source: this
538
+ }), e.emit("update", {
539
+ class: s,
540
+ model: this,
541
+ source: e
1362
542
  });
1363
543
  }
1364
544
  dispatchSaveEvent() {
1365
545
  this.emit("save", {
1366
- value: this.diff()
1367
- }), n.make("model").emit("save", {
1368
- class: e,
1369
- model: this
546
+ value: this.diff(),
547
+ source: this
548
+ }), e.emit("save", {
549
+ class: s,
550
+ model: this,
551
+ source: e
1370
552
  });
1371
553
  }
1372
- dispatchDeleteEvent(s = !1) {
554
+ dispatchDeleteEvent(r = !1) {
1373
555
  this.emit("delete", {
1374
- force: s,
1375
- [this.getKeyName()]: this.getKey()
1376
- }), n.make("model").emit("delete", {
1377
- class: e,
556
+ force: r,
557
+ [this.getKeyName()]: this.getKey(),
558
+ source: this
559
+ }), e.emit("delete", {
560
+ class: s,
1378
561
  model: this,
1379
- force: s
562
+ source: e,
563
+ force: r
1380
564
  });
1381
565
  }
1382
566
  dispatchRestoreEvent() {
1383
567
  this.emit("restore", {
1384
- value: this.attributes
1385
- }), n.make("model").emit("restore", {
1386
- class: e,
1387
- model: this
568
+ value: this.attributes,
569
+ source: this
570
+ }), e.emit("restore", {
571
+ class: s,
572
+ model: this,
573
+ source: e
1388
574
  });
1389
575
  }
1390
- dispatchErrorEvent(s, u) {
576
+ dispatchErrorEvent(r, o) {
1391
577
  this.emit("error", {
1392
- error: s,
1393
- operation: u
1394
- }), n.make("model").emit("error", {
1395
- class: e,
578
+ error: r,
579
+ operation: o,
580
+ source: this
581
+ }), e.emit("error", {
582
+ class: s,
1396
583
  model: this,
1397
- error: s,
1398
- operation: u
584
+ source: e,
585
+ error: r,
586
+ operation: o
1399
587
  });
1400
588
  }
1401
- updateChangedKeys(s) {
1402
- const u = (l, a) => typeof l == "object" && l !== null ? f.isEqual(l, a) : l == a;
1403
- !this._changedKeys.includes(s) && !u(this._original[s], this._attributes.get(s)) ? this._changedKeys.push(s) : this._changedKeys.includes(s) && u(this._original[s], this._attributes.get(s)) && this._changedKeys.splice(this._changedKeys.indexOf(s), 1);
589
+ 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);
1404
592
  }
1405
- validateJsonObject(s) {
1406
- return typeof s != "object" || s === null ? !1 : Object.entries(s).every(([, u]) => ["boolean", "number", "string"].includes(typeof u) || u === null || this.validateJsonObject(u) || Array.isArray(u) && u.every((l) => this.validateJsonObject(l)));
593
+ 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)));
1407
595
  }
1408
596
  get attributes() {
1409
597
  return this._attributes.all();
@@ -1415,20 +603,20 @@ function Ve(n, e) {
1415
603
  return this._relations;
1416
604
  }
1417
605
  get fillable() {
1418
- return n.make("model").schema(e).fillable;
606
+ return e.schema(s).fillable;
1419
607
  }
1420
608
  get primaryKey() {
1421
- return n.make("model").schema(e).primaryKey;
609
+ return e.schema(s).primaryKey;
1422
610
  }
1423
611
  get timestamps() {
1424
- return n.make("model").schema(e).timestamps;
612
+ return e.schema(s).timestamps;
1425
613
  }
1426
614
  // get softDeletes() {
1427
- // return app.make('model').schema(abstract).softDeletes;
615
+ // return ModelFacade.schema(abstract).softDeletes;
1428
616
  // }
1429
617
  get casts() {
1430
618
  return {
1431
- ...n.make("model").schema(e).casts,
619
+ ...e.schema(s).casts,
1432
620
  ...this.timestamps ? { created_at: "datetime", updated_at: "datetime" } : {}
1433
621
  // ...this.softDeletes ? { deleted_at: 'datetime' } : {},
1434
622
  };
@@ -1436,36 +624,36 @@ function Ve(n, e) {
1436
624
  get isDirty() {
1437
625
  return this._changedKeys.length > 0;
1438
626
  }
1439
- getAttribute(s) {
1440
- let u = this._attributes.get(s, null);
1441
- s in this.casts && (u = this.cast(u, this.casts[s]));
1442
- const l = n.make("model")[`model${f.upperFirst(f.camelCase(e))}Get${f.upperFirst(f.camelCase(s))}Attribute`];
1443
- if (typeof l != "function")
1444
- throw new T("ModelFacade");
1445
- return l.bind(n.make("model"))(u, this);
1446
- }
1447
- setAttribute(s, u) {
1448
- const l = n.make("model")[`model${f.upperFirst(f.camelCase(e))}Set${f.upperFirst(f.camelCase(s))}Attribute`];
1449
- if (typeof l != "function")
1450
- throw new T("ModelFacade");
1451
- const a = l.bind(n.make("model"))(
1452
- this.mutate(u, this.casts[s]),
627
+ 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`];
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]),
1453
641
  this
1454
642
  );
1455
- if (!this.validateJsonObject({ [s]: a })) {
1456
- if (n.isProduction())
1457
- throw new TypeError(`[Luminix] Attribute "${s}" in model "${e}" must be a boolean, number, string or null`);
1458
- n.make("log").warning(`Invalid type for attribute "${s}" in model "${e}" after mutation.
643
+ if (!this.validateJsonObject({ [r]: h })) {
644
+ if (n.get("app.env", "production") === "production")
645
+ throw new TypeError(`[Luminix] Attribute "${r}" in model "${s}" must be a boolean, number, string or null`);
646
+ t.warning(`Invalid type for attribute "${r}" in model "${s}" after mutation.
1459
647
  This will throw an error in production.`, {
1460
- key: s,
1461
- value: u,
1462
- mutated: a,
1463
- cast: this.casts[s],
648
+ key: r,
649
+ value: o,
650
+ mutated: h,
651
+ cast: this.casts[r],
1464
652
  item: this.toJson()
1465
653
  });
1466
654
  return;
1467
655
  }
1468
- this._attributes.set(s, a), this.updateChangedKeys(s), this.dispatchChangeEvent({ [s]: a });
656
+ this._attributes.set(r, h), this.updateChangedKeys(r), this.dispatchChangeEvent({ [r]: h });
1469
657
  }
1470
658
  getKey() {
1471
659
  return this.getAttribute(this.primaryKey);
@@ -1473,369 +661,330 @@ function Ve(n, e) {
1473
661
  getKeyName() {
1474
662
  return this.primaryKey;
1475
663
  }
1476
- fill(s) {
1477
- const u = f.pick(s, this.fillable), l = Object.entries(u).reduce((a, [d, p]) => {
1478
- const w = n.make("model")[`model${f.upperFirst(f.camelCase(e))}Set${f.upperFirst(f.camelCase(d))}Attribute`];
1479
- if (typeof w != "function")
1480
- throw new T("ModelFacade");
1481
- return a[d] = w.bind(n.make("model"))(
1482
- this.mutate(p, this.casts[d]),
664
+ 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]),
1483
671
  this
1484
- ), a;
672
+ ), h;
1485
673
  }, {});
1486
- if (!this.validateJsonObject(l)) {
1487
- if (n.isProduction())
1488
- throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
1489
- n.make("log").warning(`Invalid attributes for model "${e}" after mutation.
674
+ if (!this.validateJsonObject(a)) {
675
+ if (n.get("app.env", "production") === "production")
676
+ throw new TypeError(`[Luminix] Invalid attributes for model "${s}"`);
677
+ t.warning(`Invalid attributes for model "${s}" after mutation.
1490
678
  This will throw an error in production.`, {
1491
- attributes: s,
1492
- mutatedAttributes: l,
679
+ attributes: r,
680
+ mutatedAttributes: a,
1493
681
  item: this.toJson(),
1494
682
  casts: this.casts
1495
683
  });
1496
684
  return;
1497
685
  }
1498
- this._attributes.merge(".", l), Object.keys(l).forEach((a) => this.updateChangedKeys(a)), this.dispatchChangeEvent(l);
686
+ this._attributes.merge(".", a), Object.keys(a).forEach((h) => this.updateChangedKeys(h)), this.dispatchChangeEvent(a);
1499
687
  }
1500
688
  dump() {
1501
- n.make("log").info({
689
+ t.info({
1502
690
  ...this.toJson(),
1503
- [Symbol.toStringTag]: f.upperFirst(f.camelCase(e))
691
+ [Symbol.toStringTag]: y.studly(s)
1504
692
  });
1505
693
  }
1506
694
  toJson() {
1507
- const s = Object.entries(this.relations).reduce((l, [a, d]) => (d.isLoaded() && (d.isSingle() ? l[f.snakeCase(a)] = d.getLoadedItems().toJson() : d.isMultiple() && (l[f.snakeCase(a)] = d.getLoadedItems().map((p) => p.toJson()).all())), l), {}), u = n.make("model")[`model${f.upperFirst(f.camelCase(e))}Json`];
1508
- if (typeof u != "function")
1509
- throw new T("ModelFacade");
1510
- return u.bind(n.make("model"))({
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)({
1511
699
  ...this.attributes,
1512
- ...s
700
+ ...r
1513
701
  }, this);
1514
702
  }
1515
703
  diff() {
1516
- return this._changedKeys.reduce((s, u) => (s[u] = this._attributes.get(u), s), {});
704
+ return this._changedKeys.reduce((r, o) => (r[o] = this._attributes.get(o), r), {});
1517
705
  }
1518
706
  getType() {
1519
- return e;
707
+ return s;
1520
708
  }
1521
- relation(s) {
1522
- if (s === f.camelCase(s))
1523
- return this.relations[f.snakeCase(s)];
709
+ relation(r) {
710
+ if (r === y.camel(r))
711
+ return this.relations[y.snake(r)];
1524
712
  }
1525
- async refresh() {
1526
- if (!this.exists)
1527
- throw new Ae(e, "refresh");
1528
- const { data: s } = await n.make("route").call([
1529
- `luminix.${e}.show`,
713
+ getErrorBag(r) {
714
+ return `${this.exists ? `${s}[${this.getKey()}].` : `${s}.`}${r}`;
715
+ }
716
+ getRouteForSave() {
717
+ return this.exists ? [
718
+ `luminix.${s}.update`,
1530
719
  this.makePrimaryKeyReplacer()
1531
- ], {
1532
- errorBag: `${e}[${this.getKey()}].fetch`
1533
- });
1534
- this.makeAttributes(s);
720
+ ] : `luminix.${s}.store`;
1535
721
  }
1536
- async save(s = {}) {
722
+ getRouteForUpdate() {
723
+ return [
724
+ `luminix.${s}.update`,
725
+ this.makePrimaryKeyReplacer()
726
+ ];
727
+ }
728
+ getRouteForDelete() {
729
+ return [
730
+ `luminix.${s}.destroy`,
731
+ this.makePrimaryKeyReplacer()
732
+ ];
733
+ }
734
+ getRouteForRefresh() {
735
+ return [
736
+ `luminix.${s}.show`,
737
+ this.makePrimaryKeyReplacer()
738
+ ];
739
+ }
740
+ getLabel() {
741
+ const { labeledBy: r } = e.schema(s);
742
+ return this.getAttribute(r);
743
+ }
744
+ async refresh(r) {
745
+ if (!this.exists)
746
+ throw new ae(s, "refresh");
747
+ const o = await i.call(
748
+ this.getRouteForRefresh(),
749
+ r,
750
+ this.getErrorBag("fetch")
751
+ );
752
+ this.makeAttributes(o.json());
753
+ }
754
+ async save(r = {}, o) {
1537
755
  try {
1538
756
  const {
1539
- additionalPayload: u = {},
1540
- sendsOnlyModifiedFields: l = !0
1541
- } = s, a = this.exists, d = a ? [
1542
- `luminix.${e}.update`,
1543
- this.makePrimaryKeyReplacer()
1544
- ] : `luminix.${e}.store`, p = await n.make("route").call(
1545
- d,
1546
- {
1547
- data: {
1548
- ...f.pick(
1549
- l && a ? this.diff() : this.attributes,
1550
- this.fillable
1551
- ),
1552
- ...u
1553
- },
1554
- errorBag: a ? `${e}[${this.getKey()}].update` : `${e}.store`
1555
- }
757
+ additionalPayload: a = {},
758
+ sendsOnlyModifiedFields: h = !0
759
+ } = r, d = this.exists, v = {
760
+ ...m.pick(
761
+ h && d ? this.diff() : this.attributes,
762
+ ...this.fillable
763
+ ),
764
+ ...a
765
+ };
766
+ if (m.isEmpty(v))
767
+ return;
768
+ const b = await i.call(
769
+ this.getRouteForSave(),
770
+ (k) => o ? o(k.withData(v)) : k.withData(v),
771
+ this.getErrorBag(d ? "update" : "store")
1556
772
  );
1557
- if ([200, 201].includes(p.status))
1558
- return this.makeAttributes(p.data), this.exists = !0, this.dispatchSaveEvent(), a ? this.dispatchUpdateEvent(p.data) : this.dispatchCreateEvent(p.data), p;
1559
- throw p;
1560
- } catch (u) {
1561
- throw n.make("log").error(u), this.dispatchErrorEvent(u, "save"), u;
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;
1562
778
  }
1563
779
  }
1564
780
  async push() {
1565
- throw new b();
781
+ throw new Se();
1566
782
  }
1567
783
  async delete() {
1568
784
  try {
1569
- const s = await n.make("route").call([
1570
- `luminix.${e}.destroy`,
1571
- this.makePrimaryKeyReplacer()
1572
- ], {
1573
- errorBag: `${e}[${this.getKey()}].delete`
1574
- });
1575
- if (s.status === 204)
1576
- return this.dispatchDeleteEvent(), s;
1577
- throw s;
1578
- } catch (s) {
1579
- throw n.make("log").error(s), this.dispatchErrorEvent(s, "delete"), s;
785
+ const r = await i.call(
786
+ this.getRouteForDelete(),
787
+ void 0,
788
+ this.getErrorBag("delete")
789
+ );
790
+ if (r.noContent())
791
+ return this.dispatchDeleteEvent(), r;
792
+ throw r;
793
+ } catch (r) {
794
+ throw this.dispatchErrorEvent(r, "delete"), r;
1580
795
  }
1581
796
  }
1582
- async update(s) {
797
+ async update(r, o) {
1583
798
  try {
1584
- const u = await n.make("route").call([
1585
- `luminix.${e}.update`,
1586
- this.makePrimaryKeyReplacer()
1587
- ], {
1588
- data: s,
1589
- errorBag: `${e}[${this.getKey()}].update`
1590
- });
1591
- if (u.status === 200) {
1592
- this.makeAttributes(u.data), this.dispatchUpdateEvent(u.data);
799
+ const a = await i.call(
800
+ this.getRouteForUpdate(),
801
+ (h) => o ? o(h.withData(r)) : h.withData(r),
802
+ this.getErrorBag("update")
803
+ );
804
+ if (a.ok()) {
805
+ this.makeAttributes(a.json()), this.dispatchUpdateEvent(a.json());
1593
806
  return;
1594
807
  }
1595
- throw u;
1596
- } catch (u) {
1597
- throw n.make("log").error(u), this.dispatchErrorEvent(u, "save"), u;
808
+ throw a;
809
+ } catch (a) {
810
+ throw this.dispatchErrorEvent(a, "save"), a;
1598
811
  }
1599
812
  }
1600
813
  async forceDelete() {
1601
814
  try {
1602
- const s = await n.make("route").call(
1603
- [
1604
- `luminix.${e}.destroy`,
1605
- this.makePrimaryKeyReplacer()
1606
- ],
1607
- {
1608
- params: { force: !0 },
1609
- errorBag: `${e}[${this.getKey()}].forceDelete`
1610
- }
815
+ const r = await i.call(
816
+ this.getRouteForDelete(),
817
+ (o) => o.withQueryParameters({ force: !0 }),
818
+ this.getErrorBag("forceDelete")
1611
819
  );
1612
- if (s.status === 204)
1613
- return this.dispatchDeleteEvent(!0), s;
1614
- throw s;
1615
- } catch (s) {
1616
- throw n.make("log").error(s), this.dispatchErrorEvent(s, "forceDelete"), s;
820
+ if (r.noContent())
821
+ return this.dispatchDeleteEvent(!0), r;
822
+ throw r;
823
+ } catch (r) {
824
+ throw this.dispatchErrorEvent(r, "forceDelete"), r;
1617
825
  }
1618
826
  }
1619
827
  async restore() {
1620
828
  try {
1621
- const s = await n.make("route").call(
1622
- [
1623
- `luminix.${e}.update`,
1624
- this.makePrimaryKeyReplacer()
1625
- ],
1626
- {
1627
- params: { restore: !0 },
1628
- errorBag: `${e}[${this.getKey()}].restore`
1629
- }
829
+ const r = await i.call(
830
+ this.getRouteForUpdate(),
831
+ (o) => o.withQueryParameters({ restore: !0 }),
832
+ this.getErrorBag("restore")
1630
833
  );
1631
- if (s.status === 200)
1632
- return this.dispatchRestoreEvent(), s;
1633
- throw s;
1634
- } catch (s) {
1635
- throw n.make("log").error(s), this.dispatchErrorEvent(s, "restore"), s;
834
+ if (r.ok())
835
+ return this.dispatchRestoreEvent(), r;
836
+ throw r;
837
+ } catch (r) {
838
+ throw this.dispatchErrorEvent(r, "restore"), r;
1636
839
  }
1637
840
  }
1638
841
  static getSchemaName() {
1639
- return e;
842
+ return s;
1640
843
  }
1641
844
  static getSchema() {
1642
- return n.make("model").schema(e);
845
+ return e.schema(s);
1643
846
  }
1644
847
  static query() {
1645
- return new He(n.make(), e);
848
+ return new Ee(
849
+ { config: n, route: i, model: e },
850
+ s
851
+ );
1646
852
  }
1647
- static where(...s) {
1648
- return this.query().where(...s);
853
+ static where(...r) {
854
+ return this.query().where(...r);
1649
855
  }
1650
- static whereNull(s) {
1651
- return this.query().whereNull(s);
856
+ static whereNull(r) {
857
+ return this.query().whereNull(r);
1652
858
  }
1653
- static whereNotNull(s) {
1654
- return this.query().whereNotNull(s);
859
+ static whereNotNull(r) {
860
+ return this.query().whereNotNull(r);
1655
861
  }
1656
- static whereBetween(s, u) {
1657
- return this.query().whereBetween(s, u);
862
+ static whereBetween(r, o) {
863
+ return this.query().whereBetween(r, o);
1658
864
  }
1659
- static whereNotBetween(s, u) {
1660
- return this.query().whereNotBetween(s, u);
865
+ static whereNotBetween(r, o) {
866
+ return this.query().whereNotBetween(r, o);
1661
867
  }
1662
- static orderBy(s, u = "asc") {
1663
- return this.query().orderBy(s, u);
868
+ static orderBy(r, o = "asc") {
869
+ return this.query().orderBy(r, o);
1664
870
  }
1665
- static searchBy(s) {
1666
- return this.query().searchBy(s);
871
+ static searchBy(r) {
872
+ return this.query().searchBy(r);
1667
873
  }
1668
874
  static minified() {
1669
875
  return this.query().minified();
1670
876
  }
1671
- static limit(s) {
1672
- return this.query().limit(s);
877
+ static limit(r) {
878
+ return this.query().limit(r);
1673
879
  }
1674
- static get(s = 1, u) {
1675
- return this.query().get(s, u);
880
+ static get(r = 1, o) {
881
+ return this.query().get(r, o);
1676
882
  }
1677
- static find(s) {
1678
- return this.query().find(s);
883
+ static find(r) {
884
+ return this.query().find(r);
1679
885
  }
1680
886
  static first() {
1681
887
  return this.query().first();
1682
888
  }
1683
- static async create(s) {
1684
- const u = n.make("model").make(e), l = new u();
1685
- return l.fill(s), await l.save(), l;
889
+ static async create(r) {
890
+ const o = e.make(s), a = new o();
891
+ return a.fill(r), await a.save(), a;
1686
892
  }
1687
- static async update(s, u) {
1688
- const l = n.make("model").make(e), a = new l({ id: s });
1689
- return a.fill(u), a.exists = !0, await a.save(), a;
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;
1690
896
  }
1691
- static delete(s) {
1692
- if (Array.isArray(s))
1693
- return n.make("route").call(`luminix.${e}.destroyMany`, {
1694
- params: { ids: s },
1695
- errorBag: `${e}.deleteMany`
1696
- });
1697
- const u = n.make("model").make(e);
1698
- return new u({ id: s }).delete();
1699
- }
1700
- static async restore(s) {
1701
- if (Array.isArray(s))
1702
- return n.make("route").call(`luminix.${e}.restoreMany`, {
1703
- data: { ids: s },
1704
- errorBag: `${e}.restoreMany`
1705
- });
1706
- const u = n.make("model").make(e);
1707
- return new u({ id: s }).restore();
1708
- }
1709
- static forceDelete(s) {
1710
- if (Array.isArray(s))
1711
- return n.make("route").call(`luminix.${e}.destroyMany`, {
1712
- params: { ids: s, force: !0 },
1713
- errorBag: `${e}.forceDeleteMany`
1714
- });
1715
- const u = n.make("model").make(e);
1716
- return new u({ id: s }).forceDelete();
897
+ static delete(r) {
898
+ if (Array.isArray(r))
899
+ return i.call(
900
+ `luminix.${s}.destroyMany`,
901
+ (h) => h.withQueryParameters({ ids: r }),
902
+ `${s}.deleteMany`
903
+ );
904
+ const o = e.make(s);
905
+ return new o({ id: r }).delete();
906
+ }
907
+ static async restore(r) {
908
+ if (Array.isArray(r))
909
+ return i.call(
910
+ `luminix.${s}.restoreMany`,
911
+ (h) => h.withData({ ids: r }),
912
+ `${s}.restoreMany`
913
+ );
914
+ const o = e.make(s);
915
+ return new o({ id: r }).restore();
916
+ }
917
+ static forceDelete(r) {
918
+ if (Array.isArray(r))
919
+ return i.call(
920
+ `luminix.${s}.destroyMany`,
921
+ (h) => h.withQueryParameters({ ids: r, force: !0 }),
922
+ `${s}.forceDeleteMany`
923
+ );
924
+ const o = e.make(s);
925
+ return new o({ id: r }).forceDelete();
1717
926
  }
1718
927
  static singular() {
1719
- return n.make("model").schema(e).displayName.singular;
928
+ return e.schema(s).displayName.singular;
1720
929
  }
1721
930
  static plural() {
1722
- return n.make("model").schema(e).displayName.plural;
1723
- }
1724
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1725
- on(s, u) {
1726
- throw new b();
1727
- }
1728
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1729
- once(s, u) {
1730
- throw new b();
931
+ return e.schema(s).displayName.plural;
1731
932
  }
1732
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1733
- emit(s, u) {
1734
- throw new b();
1735
- }
1736
- }
1737
- return m(t, "name", f.upperFirst(f.camelCase(e))), A(t);
933
+ }, p(l, "name", y.studly(s)), l;
1738
934
  }
1739
- function Xe(n, e, t) {
1740
- var r, i;
1741
- return class extends (i = t, r = Symbol.toStringTag, i) {
1742
- constructor(u = {}) {
1743
- super(u);
1744
- m(this, r, f.upperFirst(f.camelCase(e)));
935
+ function Re(n, t, e) {
936
+ var i, s;
937
+ return class extends (s = e, i = Symbol.toStringTag, s) {
938
+ constructor(g = {}) {
939
+ super(g);
940
+ p(this, i, y.studly(t));
1745
941
  return new Proxy(this, {
1746
- get: (l, a) => {
1747
- if (a === "__isModel")
942
+ get: (l, u) => {
943
+ if (u === "__isModel")
1748
944
  return !0;
1749
- if (a in l)
1750
- return Reflect.get(l, a);
1751
- if (a !== f.camelCase(a))
1752
- return;
1753
- const d = f.snakeCase(a);
1754
- if (Object.keys(l.attributes).includes(d))
1755
- return l.getAttribute(d);
1756
- if (Object.keys(l.relations).includes(d))
1757
- return l.relations[d].getLoadedItems();
1758
- if (a.endsWith("Relation") && Object.keys(l.relations).includes(f.snakeCase(a.slice(0, -8))))
1759
- return () => l.relation(a.slice(0, -8));
1760
- if (n.model.hasReducer(`model${l.constructor.name}Get${f.upperFirst(a)}Attribute`)) {
1761
- const p = n.model[`model${l.constructor.name}Get${f.upperFirst(a)}Attribute`];
1762
- if (typeof p != "function")
1763
- throw new T("ModelFacade");
1764
- return p.bind(n.model)(void 0, l);
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`];
955
+ if (typeof r != "function")
956
+ throw new $("ModelFacade");
957
+ return r.bind(n)(void 0, l);
1765
958
  }
1766
- return Reflect.get(l, a);
959
+ return Reflect.get(l, u);
1767
960
  },
1768
- set: (l, a, d) => a in l && typeof l[a] != "function" ? Reflect.set(l, a, d) : (l.setAttribute(
1769
- f.snakeCase(a),
1770
- d
961
+ set: (l, u, r) => u in l && typeof l[u] != "function" ? Reflect.set(l, u, r) : (l.setAttribute(
962
+ y.snake(u),
963
+ r
1771
964
  ), !0)
1772
965
  });
1773
966
  }
1774
967
  };
1775
968
  }
1776
- var me, pe;
1777
- class Ye extends (pe = Error, me = Symbol.toStringTag, pe) {
1778
- constructor(t, r) {
1779
- super(`[Luminix] Cannot create reducer '${t}' on '${r}' as it is a reserved property`);
1780
- m(this, me, "ReducerOverrideException");
1781
- }
1782
- }
1783
- function Se(n) {
1784
- return class extends n {
1785
- constructor(...t) {
1786
- super(...t);
1787
- m(this, "reducers", {});
1788
- return new Proxy(this, {
1789
- get(r, i, s) {
1790
- return typeof i == "symbol" || i in r ? Reflect.get(r, i, s) : (u, ...l) => {
1791
- const { [i]: a = c() } = r.reducers;
1792
- return Pe(u) ? R(u, (d) => a.sortBy("priority").reduce((p, w) => w.callback(p, ...l), d)) : a.sortBy("priority").reduce((d, p) => p.callback(d, ...l), u);
1793
- };
1794
- }
1795
- });
1796
- }
1797
- reducer(t, r, i = 10) {
1798
- if (t in this)
1799
- throw new Ye(t, this);
1800
- return this.reducers[t] || (this.reducers[t] = c()), this.reducers[t].push({ callback: r, priority: i }), () => this.removeReducer(t, r);
1801
- }
1802
- removeReducer(t, r) {
1803
- const i = this.reducers[t].search((s) => s.callback === r);
1804
- i !== !1 && this.reducers[t].pull(i);
1805
- }
1806
- getReducer(t) {
1807
- return this.reducers[t] || (this.reducers[t] = c()), this.reducers[t];
1808
- }
1809
- hasReducer(t) {
1810
- return !!this.reducers[t] && this.reducers[t].count() > 0;
1811
- }
1812
- clearReducer(t) {
1813
- this.reducers[t].splice(0, this.reducers[t].count());
1814
- }
1815
- flushReducers() {
1816
- Object.values(this.reducers).forEach((t) => t.splice(0, t.count()));
1817
- }
1818
- };
1819
- }
1820
- var ge, ye;
1821
- class W extends (ye = Error, ge = Symbol.toStringTag, ye) {
1822
- constructor(t) {
1823
- super(`[Luminix] Model "${t}" not found`);
1824
- m(this, ge, "ModelNotFoundException");
969
+ var W, z;
970
+ class j extends (z = Error, W = Symbol.toStringTag, z) {
971
+ constructor(e) {
972
+ super(`[Luminix] Model "${e}" not found`);
973
+ p(this, W, "ModelNotFoundException");
1825
974
  }
1826
975
  }
1827
- var we, be;
1828
- class B extends (be = TypeError, we = Symbol.toStringTag, be) {
1829
- constructor(t, r, i) {
1830
- super(`[Luminix] "${t}" expects a related model of type "${r}". Received "${i}" instead.`);
1831
- m(this, we, "ModelInvalidRelatedTypeException");
976
+ var X, Y;
977
+ class A extends (Y = TypeError, X = Symbol.toStringTag, Y) {
978
+ constructor(e, i, s) {
979
+ super(`[Luminix] "${e}" expects a related model of type "${i}". Received "${s}" instead.`);
980
+ p(this, X, "ModelInvalidRelatedTypeException");
1832
981
  }
1833
982
  }
1834
- class ve extends K {
1835
- constructor(e, t, r, i = null) {
1836
- if (!E(i) && i !== null)
1837
- throw new M("BelongsTo.constructor()", "Model or null");
1838
- super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
983
+ class ue extends N {
984
+ constructor(t, e, i, s = null) {
985
+ if (!m.isModel(s) && s !== null)
986
+ throw new w("BelongsTo.constructor()", "Model or null");
987
+ super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
1839
988
  }
1840
989
  isSingle() {
1841
990
  return !0;
@@ -1844,21 +993,21 @@ class ve extends K {
1844
993
  return !1;
1845
994
  }
1846
995
  query() {
1847
- const e = super.query(), t = this.guessInverseRelation();
1848
- return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
996
+ const t = super.query(), e = this.guessInverseRelation();
997
+ return t.where(e, this.parent.getKey()), t.lock(`where.${e}`), t;
1849
998
  }
1850
999
  get() {
1851
1000
  return this.query().first();
1852
1001
  }
1853
- async associate(e) {
1854
- if (!E(e))
1855
- throw new M("BelongsTo.associate()");
1856
- if (e.getType() !== this.getRelated().getSchemaName())
1857
- throw new B("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
1858
- if (!e.exists)
1859
- throw new Ae(this.getRelated().getSchemaName(), "save");
1002
+ async associate(t) {
1003
+ if (!m.isModel(t))
1004
+ throw new w("BelongsTo.associate()");
1005
+ if (t.getType() !== this.getRelated().getSchemaName())
1006
+ throw new A("BelongsTo.associate()", this.getRelated().getSchemaName(), t.getType());
1007
+ if (!t.exists)
1008
+ throw new ae(this.getRelated().getSchemaName(), "save");
1860
1009
  return this.parent.update({
1861
- [this.getForeignKey()]: e.getKey()
1010
+ [this.getForeignKey()]: t.getKey()
1862
1011
  });
1863
1012
  }
1864
1013
  dissociate() {
@@ -1867,11 +1016,11 @@ class ve extends K {
1867
1016
  });
1868
1017
  }
1869
1018
  }
1870
- class Ne extends K {
1871
- constructor(e, t, r, i = null) {
1872
- if (i !== null && !(i instanceof k && i.every(E)))
1873
- throw new M("BelongsToMany.constructor()", "Collection<Model> or null");
1874
- super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
1019
+ class he extends N {
1020
+ 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");
1023
+ super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
1875
1024
  }
1876
1025
  isSingle() {
1877
1026
  return !1;
@@ -1880,11 +1029,11 @@ class Ne extends K {
1880
1029
  return !0;
1881
1030
  }
1882
1031
  query() {
1883
- const e = super.query(), t = this.guessInverseRelation();
1884
- return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
1032
+ const t = super.query(), e = this.guessInverseRelation();
1033
+ return t.where(e, this.parent.getKey()), t.lock(`where.${e}`), t;
1885
1034
  }
1886
- get(e = 1, t) {
1887
- return this.query().get(e, t);
1035
+ get(t = 1, e) {
1036
+ return this.query().get(t, e);
1888
1037
  }
1889
1038
  all() {
1890
1039
  return this.query().all();
@@ -1892,104 +1041,95 @@ class Ne extends K {
1892
1041
  first() {
1893
1042
  return this.query().first();
1894
1043
  }
1895
- find(e) {
1896
- return this.query().find(e);
1044
+ find(t) {
1045
+ return this.query().find(t);
1897
1046
  }
1898
- attachQuietly(e, t = {}) {
1899
- return this.facades.route.call([
1047
+ attachQuietly(t, e = {}) {
1048
+ return this.services.route.call([
1900
1049
  `luminix.${this.parent.getType()}.${this.getName()}:attach`,
1901
1050
  {
1902
1051
  [this.parent.getKeyName()]: this.parent.getKey(),
1903
- itemId: e
1052
+ itemId: t
1904
1053
  }
1905
- ], {
1906
- data: t,
1907
- errorBag: `${this.parent.getType()}[${this.parent.getKey()}].${this.getName()}:attach`
1908
- });
1054
+ ], (i) => i.withData(e));
1909
1055
  }
1910
- async attach(e, t = {}) {
1911
- if (await this.attachQuietly(e, t), this.items) {
1912
- const r = this.items.search((s) => s.getKey() === e), i = await this.getRelated().find(e);
1913
- if (!i)
1056
+ async attach(t, e = {}) {
1057
+ if (await this.attachQuietly(t, e), this.items) {
1058
+ const i = this.items.search((c) => c.getKey() === t), s = await this.getRelated().find(t);
1059
+ if (!s)
1914
1060
  return;
1915
- r !== !1 ? this.items.put(r, i) : this.items.push(i);
1061
+ i !== !1 ? this.items.put(i, s) : this.items.push(s);
1916
1062
  } else
1917
1063
  this.items = await this.all();
1918
1064
  }
1919
- async detachQuietly(e) {
1920
- await this.facades.route.call(
1065
+ async detachQuietly(t) {
1066
+ await this.services.route.call(
1921
1067
  [
1922
1068
  `luminix.${this.parent.getType()}.${this.getName()}:detach`,
1923
1069
  {
1924
1070
  [this.parent.getKeyName()]: this.parent.getKey(),
1925
- itemId: e
1071
+ itemId: t
1926
1072
  }
1927
- ],
1928
- {
1929
- errorBag: `${this.parent.getType()}[${this.parent.getKey()}].${this.getName()}:detach`
1930
- }
1073
+ ]
1074
+ // {
1075
+ // errorBag: `${this.parent.getType()}[${this.parent.getKey()}].${this.getName()}:detach`
1076
+ // }
1931
1077
  );
1932
1078
  }
1933
- async detach(e) {
1934
- if (await this.detachQuietly(e), this.items) {
1935
- const t = this.items.search((r) => r.getKey() === e);
1936
- t !== !1 && this.items.pull(t);
1079
+ async detach(t) {
1080
+ if (await this.detachQuietly(t), this.items) {
1081
+ const e = this.items.search((i) => i.getKey() === t);
1082
+ e !== !1 && this.items.pull(e);
1937
1083
  }
1938
1084
  }
1939
- async syncQuietly(e) {
1940
- await this.facades.route.call([
1085
+ async syncQuietly(t) {
1086
+ await this.services.route.call([
1941
1087
  `luminix.${this.parent.getType()}.${this.getName()}:sync`,
1942
1088
  {
1943
1089
  [this.parent.getKeyName()]: this.parent.getKey()
1944
1090
  }
1945
- ], {
1946
- data: e,
1947
- errorBag: `${this.parent.getType()}[${this.parent.getKey()}].${this.getName()}:sync`
1948
- });
1091
+ ], (e) => e.withData(t));
1949
1092
  }
1950
- async syncWithPivotValuesQuietly(e, t) {
1951
- await this.facades.route.call([
1093
+ async syncWithPivotValuesQuietly(t, e) {
1094
+ await this.services.route.call([
1952
1095
  `luminix.${this.parent.getType()}.${this.getName()}:sync`,
1953
1096
  {
1954
1097
  [this.parent.getKeyName()]: this.parent.getKey()
1955
1098
  }
1956
- ], {
1957
- data: e.map((r) => ({
1958
- [this.getRelated().getSchema().primaryKey]: r,
1959
- ...t
1960
- })),
1961
- errorBag: `${this.parent.getType()}[${this.parent.getKey()}].${this.getName()}:sync`
1962
- });
1099
+ ], (i) => i.withData(t.map((s) => ({
1100
+ [this.getRelated().getSchema().primaryKey]: s,
1101
+ ...e
1102
+ }))));
1963
1103
  }
1964
- async sync(e) {
1965
- await this.syncQuietly(e);
1966
- const t = await this.all();
1967
- this.items ? this.items.splice(0, this.items.count(), ...t) : this.items = t;
1104
+ async sync(t) {
1105
+ await this.syncQuietly(t);
1106
+ const e = await this.all();
1107
+ this.items ? this.items.splice(0, this.items.count(), ...e) : this.items = e;
1968
1108
  }
1969
- async syncWithPivotValues(e, t) {
1970
- await this.syncWithPivotValuesQuietly(e, t);
1971
- const r = await this.all();
1972
- this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
1109
+ async syncWithPivotValues(t, e) {
1110
+ await this.syncWithPivotValuesQuietly(t, e);
1111
+ const i = await this.all();
1112
+ this.items ? this.items.splice(0, this.items.count(), ...i) : this.items = i;
1973
1113
  }
1974
1114
  }
1975
- class Q extends K {
1115
+ class K extends N {
1976
1116
  query() {
1977
- const e = super.query(), t = this.guessInverseRelation();
1978
- return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
1117
+ const t = super.query(), e = this.guessInverseRelation();
1118
+ return t.where(e, this.parent.getKey()), t.lock(`where.${e}`), t;
1979
1119
  }
1980
- async saveQuietly(e) {
1981
- if (!E(e))
1982
- throw new M("HasOneOrMany.saveQuietly()");
1983
- if (e.getType() !== this.getRelated().getSchemaName())
1984
- throw new B("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
1985
- e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
1120
+ async saveQuietly(t) {
1121
+ if (!f(t))
1122
+ throw new w("HasOneOrMany.saveQuietly()");
1123
+ if (t.getType() !== this.getRelated().getSchemaName())
1124
+ throw new A("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), t.getType());
1125
+ t.setAttribute(this.getForeignKey(), this.parent.getKey()), await t.save();
1986
1126
  }
1987
1127
  }
1988
- class Ze extends Q {
1989
- constructor(e, t, r, i = null) {
1990
- if (!E(i) && i !== null)
1991
- throw new M("HasOne.constructor()", "Model or null");
1992
- super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
1128
+ class Ae extends K {
1129
+ constructor(t, e, i, s = null) {
1130
+ if (!f(s) && s !== null)
1131
+ throw new w("HasOne.constructor()", "Model or null");
1132
+ super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
1993
1133
  }
1994
1134
  isSingle() {
1995
1135
  return !0;
@@ -2000,15 +1140,15 @@ class Ze extends Q {
2000
1140
  get() {
2001
1141
  return this.query().first();
2002
1142
  }
2003
- async save(e) {
2004
- await this.saveQuietly(e), this.items = e;
1143
+ async save(t) {
1144
+ await this.saveQuietly(t), this.items = t;
2005
1145
  }
2006
1146
  }
2007
- class ze extends Q {
2008
- constructor(e, t, r, i = null) {
2009
- if (i !== null && !(i instanceof k && i.every(E)))
2010
- throw new M("HasMany.constructor()", "Collection<Model> or null");
2011
- super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
1147
+ class Ne extends K {
1148
+ 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");
1151
+ super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
2012
1152
  }
2013
1153
  isSingle() {
2014
1154
  return !1;
@@ -2016,8 +1156,8 @@ class ze extends Q {
2016
1156
  isMultiple() {
2017
1157
  return !0;
2018
1158
  }
2019
- get(e = 1, t) {
2020
- return this.query().get(e, t);
1159
+ get(t = 1, e) {
1160
+ return this.query().get(t, e);
2021
1161
  }
2022
1162
  all() {
2023
1163
  return this.query().all();
@@ -2025,48 +1165,48 @@ class ze extends Q {
2025
1165
  first() {
2026
1166
  return this.query().first();
2027
1167
  }
2028
- find(e) {
2029
- return this.query().find(e);
1168
+ find(t) {
1169
+ return this.query().find(t);
2030
1170
  }
2031
- async saveManyQuietly(e) {
2032
- if (!Array.isArray(e) || !e.every(E))
2033
- throw new M("HasMany.saveManyQuietly()", "Model[]");
2034
- if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
2035
- throw new B("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
2036
- await Promise.all(e.map((t) => (t.setAttribute(this.getForeignKey(), this.parent.getKey()), t.save())));
1171
+ async saveManyQuietly(t) {
1172
+ if (!Array.isArray(t) || !t.every(f))
1173
+ throw new w("HasMany.saveManyQuietly()", "Model[]");
1174
+ if (!t.every((e) => e.getType() === this.getRelated().getSchemaName()))
1175
+ throw new A("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), t.map((e) => e.getType()).join(", "));
1176
+ await Promise.all(t.map((e) => (e.setAttribute(this.getForeignKey(), this.parent.getKey()), e.save())));
2037
1177
  }
2038
- async saveMany(e) {
2039
- await this.saveManyQuietly(e);
2040
- const t = await this.all();
2041
- this.items ? this.items.splice(0, this.items.count(), ...t) : this.items = t;
1178
+ async saveMany(t) {
1179
+ await this.saveManyQuietly(t);
1180
+ const e = await this.all();
1181
+ this.items ? this.items.splice(0, this.items.count(), ...e) : this.items = e;
2042
1182
  }
2043
- async save(e) {
2044
- await this.saveQuietly(e), this.items === null ? this.items = await this.all() : this.items.push(e);
1183
+ async save(t) {
1184
+ await this.saveQuietly(t), this.items === null ? this.items = await this.all() : this.items.push(t);
2045
1185
  }
2046
1186
  }
2047
- class Re extends Q {
1187
+ class le extends K {
2048
1188
  query() {
2049
- const e = this.getRelated().query();
2050
- e.once("success", (r) => {
2051
- this.items = r.items;
1189
+ const t = this.getRelated().query();
1190
+ t.once("success", (i) => {
1191
+ this.items = i.items;
2052
1192
  });
2053
- const t = this.guessInverseRelation();
2054
- return e.where(t + "_id", this.parent.getKey()), e.where(t + "_type", this.getRelated().getSchemaName()), e.lock(`where.${t}_id`), e.lock(`where.${t}_type`), e;
1193
+ const e = this.guessInverseRelation();
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;
2055
1195
  }
2056
- async saveQuietly(e) {
2057
- if (!E(e))
2058
- throw new M("MorphOneOrMany.saveQuietly()");
2059
- if (e.getType() !== this.getRelated().getSchemaName())
2060
- throw new B("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
2061
- const t = this.guessInverseRelation();
2062
- e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
1196
+ async saveQuietly(t) {
1197
+ if (!f(t))
1198
+ throw new w("MorphOneOrMany.saveQuietly()");
1199
+ if (t.getType() !== this.getRelated().getSchemaName())
1200
+ throw new A("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), t.getType());
1201
+ const e = this.guessInverseRelation();
1202
+ t.setAttribute(e + "_id", this.parent.getKey()), t.setAttribute(e + "_type", this.parent.getType()), await t.save();
2063
1203
  }
2064
1204
  }
2065
- class Oe extends Re {
2066
- constructor(e, t, r, i = null) {
2067
- if (i !== null && !(i instanceof k && i.every(E)))
2068
- throw new M("MorphMany.constructor()", "Collection<Model> or null");
2069
- super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
1205
+ class qe extends le {
1206
+ 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");
1209
+ super(t, e, i, s), this.services = t, this.meta = e, this.parent = i, this.items = s;
2070
1210
  }
2071
1211
  isSingle() {
2072
1212
  return !1;
@@ -2074,8 +1214,8 @@ class Oe extends Re {
2074
1214
  isMultiple() {
2075
1215
  return !0;
2076
1216
  }
2077
- get(e = 1, t) {
2078
- return this.query().get(e, t);
1217
+ get(t = 1, e) {
1218
+ return this.query().get(t, e);
2079
1219
  }
2080
1220
  all() {
2081
1221
  return this.query().all();
@@ -2083,29 +1223,29 @@ class Oe extends Re {
2083
1223
  first() {
2084
1224
  return this.query().first();
2085
1225
  }
2086
- find(e) {
2087
- return this.query().find(e);
1226
+ find(t) {
1227
+ return this.query().find(t);
2088
1228
  }
2089
- async saveManyQuietly(e) {
2090
- if (!Array.isArray(e) || !e.every(E))
2091
- throw new M("MorphMany.saveManyQuietly()");
2092
- if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
2093
- throw new B("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
2094
- await Promise.all(e.map((t) => (t.setAttribute(this.getName() + "_id", this.parent.getKey()), t.setAttribute(this.getName() + "_type", this.parent.getType()), t.save())));
1229
+ async saveManyQuietly(t) {
1230
+ if (!Array.isArray(t) || !t.every(f))
1231
+ throw new w("MorphMany.saveManyQuietly()");
1232
+ if (!t.every((e) => e.getType() === this.getRelated().getSchemaName()))
1233
+ throw new A("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), t.map((e) => e.getType()).join(", "));
1234
+ await Promise.all(t.map((e) => (e.setAttribute(this.getName() + "_id", this.parent.getKey()), e.setAttribute(this.getName() + "_type", this.parent.getType()), e.save())));
2095
1235
  }
2096
- async save(e) {
2097
- await this.saveQuietly(e), this.items ? this.items.push(e) : this.items = await this.all();
1236
+ async save(t) {
1237
+ await this.saveQuietly(t), this.items ? this.items.push(t) : this.items = await this.all();
2098
1238
  }
2099
- async saveMany(e) {
2100
- await this.saveManyQuietly(e);
2101
- const t = await this.all();
2102
- this.items ? this.items.splice(0, this.items.count(), ...t) : this.items = t;
1239
+ async saveMany(t) {
1240
+ await this.saveManyQuietly(t);
1241
+ const e = await this.all();
1242
+ this.items ? this.items.splice(0, this.items.count(), ...e) : this.items = e;
2103
1243
  }
2104
1244
  }
2105
- class et extends Re {
2106
- constructor(e, t, r, i = null) {
2107
- if (super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !E(i))
2108
- throw new M("MorphOne.constructor()", "Model or null");
1245
+ class Ke extends le {
1246
+ 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");
2109
1249
  }
2110
1250
  isSingle() {
2111
1251
  return !0;
@@ -2116,13 +1256,13 @@ class et extends Re {
2116
1256
  get() {
2117
1257
  return this.query().first();
2118
1258
  }
2119
- async save(e) {
2120
- await this.saveQuietly(e), this.items = e;
1259
+ async save(t) {
1260
+ await this.saveQuietly(t), this.items = t;
2121
1261
  }
2122
1262
  }
2123
- class tt extends ve {
1263
+ class ke extends ue {
2124
1264
  getRelated() {
2125
- return this.facades.model.make(
1265
+ return this.services.model.make(
2126
1266
  this.parent.getAttribute(this.getName() + "_type")
2127
1267
  );
2128
1268
  }
@@ -2134,12 +1274,12 @@ class tt extends ve {
2134
1274
  // this.of(this.parent.getAttribute(this.getName() + '_type') as string);
2135
1275
  // return super.query();
2136
1276
  // }
2137
- async associate(e) {
2138
- if (!E(e))
2139
- throw new M("MorphTo.associate()");
2140
- return e.exists || await e.save(), this.parent.update({
2141
- [this.getName() + "_id"]: e.getKey(),
2142
- [this.getName() + "_type"]: e.getType()
1277
+ async associate(t) {
1278
+ if (!f(t))
1279
+ throw new w("MorphTo.associate()");
1280
+ return t.exists || await t.save(), this.parent.update({
1281
+ [this.getName() + "_id"]: t.getKey(),
1282
+ [this.getName() + "_type"]: t.getType()
2143
1283
  });
2144
1284
  }
2145
1285
  dissociate() {
@@ -2149,376 +1289,353 @@ class tt extends ve {
2149
1289
  });
2150
1290
  }
2151
1291
  }
2152
- class rt extends Ne {
2153
- constructor(e, t, r, i = null) {
2154
- super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
2155
- }
1292
+ class je extends he {
2156
1293
  query() {
2157
- const e = super.query(), t = this.guessInverseRelation();
2158
- return e.where(t + "_id", this.parent.getKey()), e.where(t + "_type", this.parent.getType()), e.lock(`where.${t}_id`), e.lock(`where.${t}_type`), e;
1294
+ const t = super.query(), e = this.guessInverseRelation();
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;
2159
1296
  }
2160
1297
  }
2161
- var Ee;
2162
- Ee = Symbol.toStringTag;
2163
- class st {
1298
+ var Z, ee;
1299
+ class Oe extends (ee = q, Z = Symbol.toStringTag, ee) {
2164
1300
  constructor(e) {
2165
- m(this, "_models", {});
2166
- m(this, Ee, "ModelFacade");
1301
+ super();
1302
+ p(this, "_models", {});
1303
+ p(this, Z, "ModelService");
2167
1304
  this._schema = e;
2168
1305
  }
2169
1306
  boot(e) {
2170
- this._schema && (Object.keys(this._schema).forEach((t) => {
2171
- const r = this[`model${f.upperFirst(f.camelCase(t))}`];
2172
- if (typeof this.model != "function" || typeof r != "function")
2173
- throw new T("ModelFacade");
2174
- const i = this.model(
2175
- Ve(e, t),
2176
- t
2177
- ), s = r(i);
2178
- this._models[t] = Xe(e.make(), t, s);
2179
- }), this.reducer("relationMap", () => ({
2180
- BelongsTo: ve,
2181
- BelongsToMany: Ne,
2182
- HasOne: Ze,
2183
- HasMany: ze,
2184
- MorphMany: Oe,
2185
- MorphOne: et,
2186
- MorphTo: tt,
2187
- MorphToMany: rt
2188
- }), 0));
1307
+ this._schema && Object.keys(this._schema).forEach((i) => {
1308
+ const s = this[`model${y.studly(i)}`], c = this.model(
1309
+ Te(
1310
+ e.make("config"),
1311
+ e.make("log"),
1312
+ e.make("model"),
1313
+ e.make("route"),
1314
+ i
1315
+ ),
1316
+ i
1317
+ ), g = s(c);
1318
+ this._models[i] = Re(e.make("model"), i, g);
1319
+ });
2189
1320
  }
2190
1321
  schema(e) {
2191
1322
  if (!this._schema || e && !this._schema[e])
2192
- throw new W(e || "undefined");
1323
+ throw new j(e || "undefined");
2193
1324
  return e ? this._schema[e] : this._schema;
2194
1325
  }
2195
1326
  make(e) {
2196
1327
  if (e && !this._models[e])
2197
- throw new W(e);
1328
+ throw new j(e);
2198
1329
  return e ? this._models[e] : this._models;
2199
1330
  }
1331
+ getRelationConstructors(e) {
1332
+ 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
1341
+ }, e);
1342
+ }
2200
1343
  toString() {
2201
1344
  return "model";
2202
1345
  }
2203
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2204
- on(e, t) {
2205
- throw new b();
2206
- }
2207
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2208
- once(e, t) {
2209
- throw new b();
2210
- }
2211
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2212
- emit(e, t) {
2213
- throw new b();
1346
+ }
1347
+ const Be = ne(Oe);
1348
+ var te, se;
1349
+ class Ce extends (se = Error, te = Symbol.toStringTag, se) {
1350
+ constructor(e) {
1351
+ super(`[Luminix] Route "${e}" not found`);
1352
+ p(this, te, "RouteNotFoundException");
2214
1353
  }
2215
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2216
- reducer(e, t, r) {
2217
- throw new b();
1354
+ }
1355
+ class Ie {
1356
+ constructor(t, e, i, s = "") {
1357
+ this.routes = t, this.error = e, this.http = i, this.appUrl = s;
2218
1358
  }
2219
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2220
- removeReducer(e) {
2221
- throw new b();
1359
+ isRouteTuple(t) {
1360
+ if (!Array.isArray(t) || t.length < 2)
1361
+ return !1;
1362
+ const [e, ...i] = t;
1363
+ if (typeof e != "string")
1364
+ return !1;
1365
+ const s = ["get", "post", "put", "patch", "delete"];
1366
+ return !!i.every((c) => s.includes(c));
2222
1367
  }
2223
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2224
- getReducer(e) {
2225
- throw new b();
1368
+ extractGenerator(t) {
1369
+ let e, i = !1;
1370
+ return Array.isArray(t) ? [e, i] = t : e = t, [e, i];
2226
1371
  }
2227
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2228
- hasReducer(e) {
2229
- throw new b();
1372
+ get(t) {
1373
+ if (!this.exists(t))
1374
+ throw new Ce(t);
1375
+ return m.get(this.routes, t);
2230
1376
  }
2231
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2232
- clearReducer(e) {
2233
- throw new b();
1377
+ url(t) {
1378
+ const [e, i] = this.extractGenerator(t), s = this.get(e)[0].replace(/^\/|\/$/g, ""), c = /{([^}]+)}/g;
1379
+ if (i === !1) {
1380
+ if (typeof this.replaceRouteParams != "function")
1381
+ throw new $("RouteFacade");
1382
+ return this.appUrl + this.replaceRouteParams(`/${s}`);
1383
+ }
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));
1385
+ if (r.length > 0)
1386
+ 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);
1390
+ return this.appUrl + `/${a}`;
1391
+ }
1392
+ methods(t) {
1393
+ const [e] = this.extractGenerator(t);
1394
+ return this.get(e).slice(1);
1395
+ }
1396
+ exists(t) {
1397
+ return m.has(this.routes, t) && this.isRouteTuple(m.get(this.routes, t));
1398
+ }
1399
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1400
+ async call(t, e = (s) => s, i = "default") {
1401
+ 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;
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
1417
+ }),
1418
+ i
1419
+ );
1420
+ return a;
2234
1421
  }
2235
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2236
- flushReducers() {
2237
- throw new b();
1422
+ toString() {
1423
+ return "route";
2238
1424
  }
2239
1425
  }
2240
- const it = A(Se(st));
2241
- var xe, Me;
2242
- class nt extends (Me = Error, xe = Symbol.toStringTag, Me) {
2243
- constructor() {
2244
- super("[Luminix] Embed element not found. Make sure to include the `@luminixEmbed()` directive in your Blade template.");
2245
- m(this, xe, "NoEmbedException");
1426
+ const Pe = ne(Ie);
1427
+ class Qe {
1428
+ getClient() {
1429
+ return new ye();
2246
1430
  }
2247
- }
2248
- const Be = (n, e = "data") => {
2249
- if (!document.querySelector("#luminix-embed"))
2250
- throw new nt();
2251
- const t = document.getElementById(`luminix-${e}::` + n);
2252
- return t ? t.dataset.json && t.dataset.value ? JSON.parse(t.dataset.value) : t.dataset.value : null;
2253
- }, G = A(S), ot = (n) => ke(n) && n.response !== void 0 && n.response.data !== null && "message" in n.response.data && typeof n.response.data.message == "string" && "errors" in n.response.data && typeof n.response.data.errors == "object" && n.response.data.errors !== null && Object.values(n.response.data.errors).every((e) => Array.isArray(e) && e.every((t) => typeof t == "string")) && n.response.status === 422;
2254
- let ht = class {
2255
- constructor() {
2256
- m(this, "bags");
2257
- const e = {};
2258
- document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((r) => {
2259
- const s = r.id.replace("luminix-error::", "");
2260
- e[s] = Be(s, "error");
2261
- }), this.bags = {
2262
- default: new G(e)
2263
- };
1431
+ baseUrl(t) {
1432
+ return this.getClient().baseUrl(t);
2264
1433
  }
2265
- bag(e = "default") {
2266
- return this.bags[e] || (this.bags[e] = new G({})), this.bags[e];
1434
+ asForm() {
1435
+ return this.getClient().asForm();
2267
1436
  }
2268
- add(e, t, r = "default") {
2269
- this.bag(r).set(e, t);
1437
+ accept(t) {
1438
+ return this.getClient().accept(t);
2270
1439
  }
2271
- set(e, t = "default") {
2272
- this.bag(t).set(".", e);
1440
+ acceptJson() {
1441
+ return this.getClient().acceptJson();
2273
1442
  }
2274
- all(e = "default") {
2275
- return this.bag(e).all();
1443
+ withHeaders(t) {
1444
+ return this.getClient().withHeaders(t);
2276
1445
  }
2277
- get(e, t = "default") {
2278
- return this.bag(t).get(e, null);
1446
+ withOptions(t) {
1447
+ return this.getClient().withOptions(t);
2279
1448
  }
2280
- clear(e = "default") {
2281
- this.bag(e).set(".", {});
1449
+ withData(t) {
1450
+ return this.getClient().withData(t);
2282
1451
  }
2283
- };
2284
- var _e, Te;
2285
- class ut extends (Te = Error, _e = Symbol.toStringTag, Te) {
2286
- constructor(t) {
2287
- super(`[Luminix] Route "${t}" not found`);
2288
- m(this, _e, "RouteNotFoundException");
1452
+ withQueryParameters(t) {
1453
+ return this.getClient().withQueryParameters(t);
2289
1454
  }
2290
- }
2291
- class at {
2292
- constructor(e, t, r = "") {
2293
- this.routes = e, this.error = t, this.appUrl = r;
1455
+ withBasicAuth(t, e) {
1456
+ return this.getClient().withBasicAuth(t, e);
2294
1457
  }
2295
- isRouteTuple(e) {
2296
- if (!Array.isArray(e) || e.length < 2)
2297
- return !1;
2298
- const [t, ...r] = e;
2299
- if (typeof t != "string")
2300
- return !1;
2301
- const i = ["get", "post", "put", "patch", "delete"];
2302
- return !!r.every((s) => i.includes(s));
1458
+ withToken(t) {
1459
+ return this.getClient().withToken(t);
2303
1460
  }
2304
- extractGenerator(e) {
2305
- let t, r = !1;
2306
- return Array.isArray(e) ? [t, r] = e : t = e, [t, r];
1461
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1462
+ get(t, e) {
1463
+ return this.getClient().get(t, e);
2307
1464
  }
2308
- get(e) {
2309
- if (!this.exists(e))
2310
- throw new ut(e);
2311
- return f.get(this.routes, e);
1465
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1466
+ post(t, e) {
1467
+ return this.getClient().post(t, e);
2312
1468
  }
2313
- url(e) {
2314
- const [t, r] = this.extractGenerator(e), i = this.get(t)[0].replace(/^\/|\/$/g, ""), s = /{([^}]+)}/g;
2315
- if (r === !1) {
2316
- if (typeof this.replaceRouteParams != "function")
2317
- throw new T("RouteFacade");
2318
- return this.appUrl + this.replaceRouteParams(`/${i}`);
2319
- }
2320
- const u = i.match(s), l = u ? u.map((x) => x.slice(1, -1)) : [], a = Object.keys(r), d = l.filter((x) => !a.includes(x)), p = a.filter((x) => !l.includes(x));
2321
- if (d.length > 0)
2322
- throw new TypeError(`Missing values for parameter(s): ${d.join(", ")}`);
2323
- if (p.length > 0)
2324
- throw new TypeError(`Unexpected parameters: ${p.join(", ")}`);
2325
- const w = l.reduce((x, g) => x.replace(`{${g}}`, `${r[g]}`), i);
2326
- return this.appUrl + `/${w}`;
2327
- }
2328
- methods(e) {
2329
- const [t] = this.extractGenerator(e);
2330
- return this.get(t).slice(1);
2331
- }
2332
- exists(e) {
2333
- return f.has(this.routes, e) && this.isRouteTuple(f.get(this.routes, e));
2334
- }
2335
- async call(e, t = {}) {
2336
- if (typeof this.axiosOptions != "function" || typeof this.axiosError != "function")
2337
- throw new T("RouteFacade");
2338
- const [r, i] = this.extractGenerator(e), [, ...s] = this.get(r), u = this.url(i ? [r, i] : r), l = this.axiosOptions(t, r), { method: a = s[0], errorBag: d = "route.call", ...p } = l, { data: w, ...x } = p;
2339
- this.error.clear(d);
2340
- try {
2341
- return ["get", "delete"].includes(a) ? await I[a](u, p) : await I[a](u, w, x);
2342
- } catch (g) {
2343
- if (ot(g)) {
2344
- const { errors: qe } = g.response.data;
2345
- this.error.set(Object.entries(qe).reduce((L, [Ie, Ke]) => (L[Ie] = Ke.join(" "), L), {}));
2346
- } else I.isAxiosError(g) && this.error.set(
2347
- this.axiosError({ axios: g.message }, {
2348
- error: g,
2349
- name: r,
2350
- replace: i,
2351
- config: t
2352
- }),
2353
- d
2354
- );
2355
- throw g;
2356
- }
1469
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1470
+ put(t, e) {
1471
+ return this.getClient().put(t, e);
2357
1472
  }
2358
- toString() {
2359
- return "route";
1473
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1474
+ patch(t, e) {
1475
+ return this.getClient().patch(t, e);
1476
+ }
1477
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1478
+ delete(t, e) {
1479
+ return this.getClient().delete(t, e);
2360
1480
  }
2361
1481
  }
2362
- const lt = Se(at);
2363
- class ct {
1482
+ const De = oe(Qe);
1483
+ var re, ie;
1484
+ class He extends (ie = me, re = Symbol.toStringTag, ie) {
2364
1485
  constructor() {
2365
- m(this, "facades", {});
2366
- m(this, "booted", !1);
2367
- m(this, "_plugins", []);
2368
- }
2369
- make(e = void 0) {
2370
- if (!e)
2371
- return this.facades;
2372
- if (e in this.facades)
2373
- return this.facades[e];
2374
- }
2375
- has(e) {
2376
- return !!this.facades[e];
2377
- }
2378
- bind(e, t) {
2379
- this.facades[e] || (this.facades[e] = t);
2380
- }
2381
- plugins() {
2382
- return this._plugins;
2383
- }
2384
- async boot(e = {}) {
2385
- var l, a, d, p, w, x;
2386
- if (this.booted)
2387
- throw new window.Error("[Luminix] App already booted");
2388
- this.booted = !0, (l = e.app) != null && l.debug && console.log("[Luminix] Booting started..."), this.emit("init", {
2389
- register: (g) => {
2390
- this._plugins.push(g), typeof g.register == "function" && g.register(this);
2391
- }
2392
- });
2393
- const t = (((a = e.app) == null ? void 0 : a.url) ?? "") + (((d = e.app) == null ? void 0 : d.bootUrl) ?? "/luminix-api/init");
2394
- if (document.getElementById("luminix-data::config")) {
2395
- if (document.getElementById("luminix-data::config")) {
2396
- const g = Be("config");
2397
- g && typeof g == "object" && f.merge(e, g);
2398
- }
2399
- } else try {
2400
- const { data: g } = await I.get(t);
2401
- g && typeof g == "object" && f.merge(e, g);
2402
- } catch (g) {
2403
- (p = e.app) != null && p.debug && console.error(g);
2404
- }
2405
- this.bind("log", new Ce(!!((w = e.app) != null && w.debug)));
2406
- const { log: r } = this.facades, {
2407
- manifest: { routes: i = {}, models: s = {} } = {},
2408
- ...u
2409
- } = e;
2410
- this.bind("config", new S(u)), this.facades.config.has("auth.user") || this.facades.config.set("auth.user", null), this.facades.config.lock("auth.user"), this.bind("error", new ht()), this.bind("route", new lt(i, this.facades.error, ((x = e.app) == null ? void 0 : x.url) ?? "")), this.bind("model", new it(s)), this.bind("auth", new Le(this)), this.emit("booting");
2411
- for (const g of Object.values(this.facades))
2412
- typeof g == "object" && g !== null && "boot" in g && typeof g.boot == "function" && g.boot(this);
2413
- for (const g of this._plugins)
2414
- typeof g.boot == "function" && g.boot(this.facades);
2415
- return r.info("[Luminix] App boot completed", {
2416
- config: this.facades.config.all(),
2417
- plugins: this._plugins,
2418
- manifest: {
2419
- routes: i,
2420
- models: s
2421
- }
2422
- }), this.emit("booted"), this.facades;
2423
- }
2424
- environment(...e) {
2425
- return e.length > 0 ? e.includes(this.facades.config.get("app.env", "production")) : this.facades.config.get("app.env", "production");
2426
- }
2427
- getPlugin(e) {
2428
- for (const t of this._plugins)
2429
- if (t instanceof e)
2430
- return t;
2431
- }
2432
- hasDebugModeEnabled() {
2433
- return this.facades.config.get("app.debug", !1);
1486
+ super(...arguments);
1487
+ p(this, re, "LuminixServiceProvider");
2434
1488
  }
2435
- isLocal() {
2436
- return this.facades.config.get("app.env", "production") === "local";
1489
+ register() {
1490
+ this.registerServices(), this.registerMacros(), this.app.on("ready", () => {
1491
+ this.app.dump("[Luminix] App boot completed");
1492
+ });
2437
1493
  }
2438
- isProduction() {
2439
- return this.facades.config.get("app.env", "production") === "production";
1494
+ boot() {
1495
+ this.app.make("model").boot(this.app);
1496
+ }
1497
+ registerServices() {
1498
+ this.app.singleton("auth", () => new ve(
1499
+ this.app.make("config"),
1500
+ this.app.make("model"),
1501
+ this.app.make("route")
1502
+ )), this.app.singleton("config", () => {
1503
+ const e = new R(m.omit(this.app.configuration, "manifest"));
1504
+ 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", () => {
1506
+ var e;
1507
+ return new xe(((e = this.app.configuration.app) == null ? void 0 : e.debug) ?? !1);
1508
+ }), this.app.singleton("model", () => {
1509
+ var e;
1510
+ return new Be(
1511
+ ((e = this.app.configuration.manifest) == null ? void 0 : e.models) ?? {}
1512
+ );
1513
+ }), this.app.singleton("route", () => {
1514
+ var e, i;
1515
+ return new Pe(
1516
+ ((e = this.app.configuration.manifest) == null ? void 0 : e.routes) ?? {},
1517
+ this.app.make("error"),
1518
+ () => this.app.make("http"),
1519
+ (i = this.app.configuration.app) == null ? void 0 : i.url
1520
+ );
1521
+ });
2440
1522
  }
2441
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2442
- on(e, t) {
2443
- throw new window.Error("Method not implemented.");
1523
+ 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) {
1525
+ return typeof e == "object" && e !== null && e.__isModel === !0;
1526
+ });
2444
1527
  }
2445
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2446
- once(e, t) {
2447
- throw new window.Error("Method not implemented.");
1528
+ }
1529
+ let S;
1530
+ class Le {
1531
+ getFacadeAccessor() {
1532
+ return S || (S = new (oe(fe))([
1533
+ He
1534
+ ])), S;
2448
1535
  }
2449
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2450
- emit(e, t) {
2451
- throw new window.Error("Method not implemented.");
1536
+ down() {
1537
+ S && (S.flush(), S = void 0);
2452
1538
  }
2453
1539
  }
2454
- const dt = A(ct);
2455
- let y;
2456
- function v(n = void 0) {
2457
- if (y || (y = new dt()), typeof n != "string")
2458
- return {
2459
- boot: y.boot.bind(y),
2460
- make: y.make.bind(y),
2461
- plugins: y.plugins.bind(y),
2462
- on: y.once.bind(y),
2463
- environment: y.environment.bind(y),
2464
- getPlugin: y.getPlugin.bind(y),
2465
- hasDebugModeEnabled: y.hasDebugModeEnabled.bind(y),
2466
- isLocal: y.isLocal.bind(y),
2467
- isProduction: y.isProduction.bind(y)
2468
- };
2469
- if (!y.has(n))
2470
- throw new Qe(n);
2471
- return y.make(n);
1540
+ const M = E(Le);
1541
+ function _(n = void 0) {
1542
+ return typeof n != "string" ? M : M.make(n);
1543
+ }
1544
+ function Ze() {
1545
+ return _("auth");
1546
+ }
1547
+ function et(n) {
1548
+ return new x(n);
1549
+ }
1550
+ function tt(n, t) {
1551
+ const e = _("config");
1552
+ return typeof n > "u" ? e : e.get(n, t);
2472
1553
  }
2473
- function bt() {
2474
- return v("auth");
1554
+ function st(n, t = "default") {
1555
+ return n ? _().make("error").get(n, t) : _().make("error");
1556
+ }
1557
+ function rt(...n) {
1558
+ const t = _("log");
1559
+ return n.length ? t.debug(...n) : t;
1560
+ }
1561
+ function it(n) {
1562
+ const t = _("model");
1563
+ return n ? t.make(n) : t;
1564
+ }
1565
+ function nt(n, t = !1) {
1566
+ const e = _("route");
1567
+ return n ? t ? e.url([n, t]) : e.url(n) : e;
1568
+ }
1569
+ class Je {
1570
+ getFacadeAccessor() {
1571
+ return "auth";
1572
+ }
2475
1573
  }
2476
- function Et(n) {
2477
- return c(n);
1574
+ const ot = E(Je, M);
1575
+ class Ue {
1576
+ getFacadeAccessor() {
1577
+ return "config";
1578
+ }
2478
1579
  }
2479
- function xt(n, e) {
2480
- const t = v("config");
2481
- return typeof n > "u" ? t : t.get(n, e);
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 {
1582
+ getFacadeAccessor() {
1583
+ return "error";
1584
+ }
2482
1585
  }
2483
- function Mt(n, e = "default") {
2484
- return n ? v().make("error").get(n, e) : v().make("error");
1586
+ const ht = E(Fe, M);
1587
+ class Ge {
1588
+ getFacadeAccessor() {
1589
+ return "http";
1590
+ }
2485
1591
  }
2486
- function _t(...n) {
2487
- const e = v("log");
2488
- return n.length ? e.debug(...n) : e;
1592
+ const lt = E(Ge, M);
1593
+ class Ve {
1594
+ getFacadeAccessor() {
1595
+ return "log";
1596
+ }
2489
1597
  }
2490
- function Tt(n) {
2491
- const e = v("model");
2492
- return n ? e.make(n) : e;
1598
+ const ct = E(Ve, M);
1599
+ class We {
1600
+ getFacadeAccessor() {
1601
+ return "model";
1602
+ }
2493
1603
  }
2494
- function $t(n, e = !1) {
2495
- const t = v("route");
2496
- return n ? e ? t.url([n, e]) : t.url(n) : t;
1604
+ const dt = E(We, M);
1605
+ class ze {
1606
+ getFacadeAccessor() {
1607
+ return "route";
1608
+ }
2497
1609
  }
2498
- class At {
1610
+ const pt = E(ze, M);
1611
+ class gt {
2499
1612
  constructor() {
2500
- m(this, "name");
2501
- m(this, "version");
1613
+ p(this, "name");
1614
+ p(this, "version");
2502
1615
  }
2503
- register(e) {
1616
+ register(t) {
2504
1617
  }
2505
- boot(e) {
1618
+ boot(t) {
2506
1619
  }
2507
1620
  }
2508
1621
  export {
2509
- A as HasEvents,
2510
- At as Plugin,
2511
- S as PropertyBag,
2512
- Se as Reducible,
2513
- v as app,
2514
- bt as auth,
2515
- Et as collect,
2516
- xt as config,
2517
- Mt as error,
2518
- $ as isCollection,
2519
- E as isModel,
2520
- ot as isValidationError,
2521
- _t as log,
2522
- Tt as model,
2523
- $t 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
2524
1641
  };