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