@luminix/core 0.0.1-beta.3 → 0.0.1-beta.5
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 +53 -0
- package/dist/contracts/Collection.d.ts +190 -0
- package/dist/contracts/ModelCollection.d.ts +9 -0
- package/dist/contracts/Plugin.d.ts +8 -0
- package/dist/contracts/PropertyBag.d.ts +21 -0
- package/dist/contracts/Relation/BelongsTo.d.ts +20 -0
- package/dist/contracts/Relation/BelongsToMany.d.ts +31 -0
- package/dist/contracts/Relation/HasMany.d.ts +21 -0
- package/dist/contracts/Relation/HasOne.d.ts +15 -0
- package/dist/contracts/Relation/HasOneOrMany.d.ts +10 -0
- package/dist/contracts/Relation/MorphMany.d.ts +21 -0
- package/dist/contracts/Relation/MorphOne.d.ts +15 -0
- package/dist/contracts/Relation/MorphOneOrMany.d.ts +10 -0
- package/dist/contracts/Relation/MorphTo.d.ts +8 -0
- package/dist/contracts/Relation/MorphToMany.d.ts +16 -0
- package/dist/contracts/Relation.d.ts +44 -0
- package/dist/core.js +712 -663
- package/dist/exceptions/AttributeNotFillableException.d.ts +4 -0
- package/dist/exceptions/FacadeNotFoundException.d.ts +4 -0
- package/dist/exceptions/MethodNotImplementedException.d.ts +4 -0
- package/dist/exceptions/ModelInvalidRelatedTypeException.d.ts +4 -0
- package/dist/exceptions/ModelNotFoundException.d.ts +4 -0
- package/dist/exceptions/ModelNotPersistedException.d.ts +4 -0
- package/dist/exceptions/ModelWithoutPrimaryKeyException.d.ts +4 -0
- package/dist/exceptions/NoEmbedException.d.ts +4 -0
- package/dist/exceptions/NoInverseRelationException.d.ts +4 -0
- package/dist/exceptions/NotModelException.d.ts +4 -0
- package/dist/exceptions/NotReducibleException.d.ts +4 -0
- package/dist/exceptions/ReducerOverrideException.d.ts +4 -0
- package/dist/exceptions/RouteNotFoundException.d.ts +4 -0
- package/dist/exceptions/UnsupportedRelationException.d.ts +4 -0
- package/dist/facades/App.d.ts +30 -0
- package/dist/facades/Auth.d.ts +14 -0
- package/dist/facades/Error.d.ts +15 -0
- package/dist/facades/Log.d.ts +14 -0
- package/dist/facades/Model.d.ts +41 -0
- package/dist/facades/Route.d.ts +32 -0
- package/dist/helpers/app.d.ts +5 -0
- package/dist/helpers/auth.d.ts +3 -0
- package/dist/helpers/collect.d.ts +1 -0
- package/dist/helpers/config.d.ts +5 -0
- package/dist/helpers/error.d.ts +4 -0
- package/dist/helpers/log.d.ts +5 -0
- package/dist/helpers/model.d.ts +6 -0
- package/dist/helpers/route.d.ts +5 -0
- package/dist/index.d.ts +24 -0
- package/dist/mixins/BaseModel.d.ts +5 -0
- package/dist/mixins/HasEvents.d.ts +15 -0
- package/dist/mixins/Reducible.d.ts +17 -0
- package/dist/support/collection.d.ts +4 -0
- package/dist/support/model.d.ts +3 -0
- package/dist/support/reader.d.ts +2 -0
- package/dist/support/searchParams.d.ts +1 -0
- package/dist/types/App.d.ts +72 -0
- package/dist/types/Auth.d.ts +13 -0
- package/dist/types/Builder.d.ts +51 -0
- package/dist/types/Collection.d.ts +1804 -0
- package/dist/types/Config.d.ts +29 -0
- package/dist/types/Error.d.ts +31 -0
- package/dist/types/Event.d.ts +14 -0
- package/dist/types/Log.d.ts +37 -0
- package/dist/types/Model.d.ts +165 -0
- package/dist/types/Plugin.d.ts +4 -0
- package/dist/types/PropertyBag.d.ts +25 -0
- package/dist/types/Reducer.d.ts +17 -0
- package/dist/types/Relation.d.ts +30 -0
- package/dist/types/Route.d.ts +22 -0
- package/dist/types/Support.d.ts +7 -0
- package/package.json +1 -1
- package/vite.config.js +2 -2
- package/graph.png +0 -0
package/dist/core.js
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var Qe = Object.defineProperty;
|
|
2
|
+
var U = (n) => {
|
|
3
3
|
throw TypeError(n);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var o = (n, e, t) => (F(n, e, "read from private field"), t ? t.call(n) : e.get(n)), q = (n, e, t) => e.has(n) ?
|
|
5
|
+
var Ce = (n, e, t) => e in n ? Qe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
6
|
+
var m = (n, e, t) => Ce(n, typeof e != "symbol" ? e + "" : e, t), F = (n, e, t) => e.has(n) || U("Cannot " + t);
|
|
7
|
+
var o = (n, e, t) => (F(n, e, "read from private field"), t ? t.call(n) : e.get(n)), q = (n, e, t) => e.has(n) ? U("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), P = (n, e, t, r) => (F(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), D = (n, e, t) => (F(n, e, "access private method"), t);
|
|
8
8
|
import f from "lodash";
|
|
9
|
-
import { produce as
|
|
10
|
-
import K, { isAxiosError as
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
import { produce as R, isDraftable as Le } from "immer";
|
|
10
|
+
import K, { isAxiosError as Je } from "axios";
|
|
11
|
+
var X, Y;
|
|
12
|
+
class Ue extends (Y = Error, X = Symbol.toStringTag, Y) {
|
|
13
|
+
constructor(t) {
|
|
14
|
+
super(`[Luminix] Facade "${t}" not found`);
|
|
15
|
+
m(this, X, "FacadeNotFoundException");
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
class be {
|
|
18
|
+
class De {
|
|
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 l = document.createElement("input");
|
|
29
|
+
l.type = "hidden", l.name = "_token", l.value = s, i.appendChild(l);
|
|
29
30
|
}
|
|
30
31
|
const u = document.createElement("input");
|
|
31
|
-
u.type = "email", u.name = "email", u.value = e.email,
|
|
32
|
+
u.type = "email", u.name = "email", u.value = e.email, i.appendChild(u);
|
|
32
33
|
const a = document.createElement("input");
|
|
33
|
-
if (a.type = "password", a.name = "password", a.value = e.password,
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
if (a.type = "password", a.name = "password", a.value = e.password, i.appendChild(a), t) {
|
|
35
|
+
const l = document.createElement("input");
|
|
36
|
+
l.type = "checkbox", l.name = "remember", l.value = "1", l.checked = !0, i.appendChild(l);
|
|
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 He {
|
|
67
68
|
constructor(e) {
|
|
68
69
|
this._debug = e;
|
|
69
70
|
}
|
|
@@ -92,9 +93,9 @@ class Ee {
|
|
|
92
93
|
this._debug && console.debug(...e);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
|
-
class
|
|
96
|
+
class S {
|
|
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) {
|
|
@@ -110,14 +111,14 @@ class v {
|
|
|
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 = R(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
|
+
this.bag = R(this.bag, (r) => {
|
|
121
122
|
f.set(r, e, t);
|
|
122
123
|
}), this.emit("change", {
|
|
123
124
|
path: e,
|
|
@@ -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) => f.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 = R(this.bag, (i) => ({
|
|
136
|
+
...i,
|
|
136
137
|
...t
|
|
137
138
|
})), this.emit("change", {
|
|
138
139
|
path: e,
|
|
@@ -157,7 +158,7 @@ class v {
|
|
|
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
|
+
this.bag = R(this.bag, (t) => {
|
|
161
162
|
f.unset(t, e);
|
|
162
163
|
}), this.emit("change", {
|
|
163
164
|
path: e,
|
|
@@ -171,7 +172,7 @@ class v {
|
|
|
171
172
|
this.locked.push(e);
|
|
172
173
|
}
|
|
173
174
|
clone() {
|
|
174
|
-
return new
|
|
175
|
+
return new S(this.bag);
|
|
175
176
|
}
|
|
176
177
|
all() {
|
|
177
178
|
return this.bag;
|
|
@@ -191,92 +192,93 @@ class v {
|
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
194
|
function A(n) {
|
|
194
|
-
var e, t, r,
|
|
195
|
-
return
|
|
195
|
+
var e, t, r, i, Se, u;
|
|
196
|
+
return u = class extends (t = n, e = Symbol.toStringTag, t) {
|
|
196
197
|
constructor(...d) {
|
|
197
198
|
super(...d);
|
|
198
199
|
q(this, i);
|
|
199
200
|
q(this, r);
|
|
200
|
-
|
|
201
|
-
P(this, r,
|
|
201
|
+
m(this, e, n.name);
|
|
202
|
+
P(this, r, D(this, i, Se).call(this));
|
|
202
203
|
}
|
|
203
|
-
on(d,
|
|
204
|
+
on(d, p) {
|
|
204
205
|
if (typeof d != "string")
|
|
205
206
|
throw new TypeError("event must be a string");
|
|
206
|
-
if (typeof
|
|
207
|
+
if (typeof p != "function")
|
|
207
208
|
throw new TypeError("callback must be a function");
|
|
208
|
-
return o(this, r).on(d,
|
|
209
|
+
return o(this, r).on(d, p);
|
|
209
210
|
}
|
|
210
|
-
once(d,
|
|
211
|
+
once(d, p) {
|
|
211
212
|
if (typeof d != "string")
|
|
212
213
|
throw new TypeError("event must be a string");
|
|
213
|
-
if (typeof
|
|
214
|
+
if (typeof p != "function")
|
|
214
215
|
throw new TypeError("callback must be a function");
|
|
215
|
-
const
|
|
216
|
-
|
|
216
|
+
const y = o(this, r).on(d, (w) => {
|
|
217
|
+
y(), p(w);
|
|
217
218
|
});
|
|
218
219
|
}
|
|
219
|
-
emit(d,
|
|
220
|
+
emit(d, p = {}) {
|
|
220
221
|
if (typeof d != "string")
|
|
221
222
|
throw new TypeError("event must be a string");
|
|
222
|
-
if (typeof
|
|
223
|
+
if (typeof p != "object")
|
|
223
224
|
throw new TypeError("data must be an object");
|
|
224
225
|
o(this, r).emit(d, {
|
|
225
|
-
...
|
|
226
|
+
...p,
|
|
226
227
|
source: this
|
|
227
228
|
});
|
|
228
229
|
}
|
|
229
|
-
}, r = new WeakMap(), i = new WeakSet(),
|
|
230
|
+
}, r = new WeakMap(), i = new WeakSet(), Se = function() {
|
|
230
231
|
return {
|
|
231
|
-
emit(d,
|
|
232
|
-
for (let
|
|
233
|
-
|
|
232
|
+
emit(d, p) {
|
|
233
|
+
for (let y = 0, w = this.events[d] || [], g = w.length; y < g; y++)
|
|
234
|
+
w[y](p);
|
|
234
235
|
},
|
|
235
236
|
events: {},
|
|
236
|
-
on(d,
|
|
237
|
-
var
|
|
238
|
-
return ((
|
|
239
|
-
var
|
|
240
|
-
this.events[d] = (
|
|
237
|
+
on(d, p) {
|
|
238
|
+
var y;
|
|
239
|
+
return ((y = this.events)[d] || (y[d] = [])).push(p), () => {
|
|
240
|
+
var w;
|
|
241
|
+
this.events[d] = (w = this.events[d]) == null ? void 0 : w.filter((g) => p !== g);
|
|
241
242
|
};
|
|
242
243
|
}
|
|
243
244
|
};
|
|
244
|
-
},
|
|
245
|
+
}, u;
|
|
245
246
|
}
|
|
246
|
-
function
|
|
247
|
-
return n.reduce((e, t) => e.flatMap((r) => t.map((
|
|
247
|
+
function H(...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 Z, z;
|
|
254
|
+
class b extends (z = Error, Z = Symbol.toStringTag, z) {
|
|
253
255
|
constructor() {
|
|
254
256
|
super("[Luminix] Method not implemented.");
|
|
257
|
+
m(this, Z, "MethodNotImplementedException");
|
|
255
258
|
}
|
|
256
259
|
}
|
|
257
|
-
|
|
258
|
-
function l(n = [], e = L) {
|
|
260
|
+
function c(n = [], e = Q) {
|
|
259
261
|
if (!Array.isArray(n))
|
|
260
262
|
throw new TypeError("collect() expects an array");
|
|
261
263
|
return new (A(e))([...n]);
|
|
262
264
|
}
|
|
263
|
-
const
|
|
265
|
+
const T = (n) => {
|
|
264
266
|
n.emit("change", {
|
|
265
267
|
items: n.all()
|
|
266
268
|
});
|
|
267
269
|
}, I = (n, e) => Array.isArray(n) ? n[e] ?? null : n.get(e);
|
|
268
|
-
var
|
|
269
|
-
class
|
|
270
|
+
var O, k, h;
|
|
271
|
+
class Q {
|
|
270
272
|
constructor(e = []) {
|
|
271
|
-
//
|
|
273
|
+
// [Symbol.toStringTag] = 'Collection';
|
|
272
274
|
q(this, h);
|
|
273
|
-
|
|
275
|
+
m(this, O, "Collection");
|
|
274
276
|
P(this, h, e);
|
|
275
277
|
}
|
|
276
278
|
get items() {
|
|
277
279
|
return [...o(this, h)];
|
|
278
280
|
}
|
|
279
|
-
[(
|
|
281
|
+
[(k = Symbol.iterator, O = Symbol.toStringTag, k)]() {
|
|
280
282
|
return o(this, h)[Symbol.iterator]();
|
|
281
283
|
}
|
|
282
284
|
all() {
|
|
@@ -292,34 +294,34 @@ class L {
|
|
|
292
294
|
const t = [];
|
|
293
295
|
for (let r = 0; r < o(this, h).length; r += e)
|
|
294
296
|
t.push(o(this, h).slice(r, r + e));
|
|
295
|
-
return
|
|
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(o(this, h)[
|
|
302
|
-
return r.count() > 0 && t.push(r),
|
|
301
|
+
let r = c();
|
|
302
|
+
for (let i = 0; i < o(this, h).length; i++)
|
|
303
|
+
e(o(this, h)[i], i, r) ? r.push(o(this, h)[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(o(this, h).flat());
|
|
306
308
|
}
|
|
307
309
|
collect() {
|
|
308
|
-
return
|
|
310
|
+
return c(o(this, h));
|
|
309
311
|
}
|
|
310
312
|
combine(e) {
|
|
311
313
|
const t = {};
|
|
312
|
-
return o(this, h).forEach((r,
|
|
314
|
+
return o(this, h).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] = I(e,
|
|
317
|
+
t[r] = I(e, i);
|
|
316
318
|
}), t;
|
|
317
319
|
}
|
|
318
320
|
concat(e) {
|
|
319
|
-
return Array.isArray(e) ?
|
|
321
|
+
return Array.isArray(e) ? c([...o(this, h), ...e]) : c([...o(this, h), ...e.all()]);
|
|
320
322
|
}
|
|
321
323
|
contains(e, t) {
|
|
322
|
-
return typeof e == "function" ? o(this, h).some((r,
|
|
324
|
+
return typeof e == "function" ? o(this, h).some((r, i) => e(r, i, this)) : o(this, h).some((r) => {
|
|
323
325
|
if (typeof t > "u")
|
|
324
326
|
return r == e;
|
|
325
327
|
if (typeof e != "string")
|
|
@@ -331,7 +333,7 @@ class L {
|
|
|
331
333
|
return o(this, h).length === 1;
|
|
332
334
|
}
|
|
333
335
|
containsStrict(e, t) {
|
|
334
|
-
return typeof e == "function" ? o(this, h).some((r,
|
|
336
|
+
return typeof e == "function" ? o(this, h).some((r, i) => e(r, i, this)) : o(this, h).some((r) => {
|
|
335
337
|
if (typeof t > "u")
|
|
336
338
|
return r === e;
|
|
337
339
|
if (typeof e != "string")
|
|
@@ -343,9 +345,9 @@ class L {
|
|
|
343
345
|
return o(this, h).length;
|
|
344
346
|
}
|
|
345
347
|
countBy(e) {
|
|
346
|
-
return typeof e == "function" ? o(this, h).reduce((t, r,
|
|
347
|
-
const
|
|
348
|
-
return t[
|
|
348
|
+
return typeof e == "function" ? o(this, h).reduce((t, r, i) => {
|
|
349
|
+
const s = e(r, i, this);
|
|
350
|
+
return t[s] = t[s] ? t[s] + 1 : 1, t;
|
|
349
351
|
}, {}) : o(this, h).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");
|
|
@@ -353,16 +355,16 @@ class L {
|
|
|
353
355
|
}, {});
|
|
354
356
|
}
|
|
355
357
|
crossJoin(...e) {
|
|
356
|
-
return
|
|
358
|
+
return c(H(
|
|
357
359
|
o(this, h),
|
|
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(o(this, h).filter((t) => !e.includes(t))) : c(o(this, h).filter((t) => !e.contains(t)));
|
|
363
365
|
}
|
|
364
366
|
doesntContain(e, t) {
|
|
365
|
-
return typeof e == "function" ? o(this, h).every((r,
|
|
367
|
+
return typeof e == "function" ? o(this, h).every((r, i) => !e(r, i, this)) : o(this, h).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" ? o(this, h).reduce((t, r, i) => (o(this, h).slice(i + 1).some((s) => s[e] == r[e]) && t.push(r[e]), t), []) : o(this, h).reduce((t, r, i) => (o(this, h).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" ? o(this, h).reduce((t, r, i) => (o(this, h).slice(i + 1).some((s) => s[e] === r[e]) && t.push(r[e]), t), []) : o(this, h).reduce((t, r, i) => (o(this, h).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,19 +402,19 @@ class L {
|
|
|
400
402
|
}
|
|
401
403
|
ensure(e) {
|
|
402
404
|
const t = Array.isArray(e) ? e : [e];
|
|
403
|
-
return o(this, h).forEach((r,
|
|
404
|
-
if (!t.some((
|
|
405
|
-
throw new TypeError(`The item at index ${
|
|
405
|
+
return o(this, h).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
411
|
return o(this, h).every((t, r) => e(t, r, this));
|
|
410
412
|
}
|
|
411
413
|
except(e) {
|
|
412
|
-
return
|
|
414
|
+
return c(o(this, h).filter((t, r) => !e.includes(r)));
|
|
413
415
|
}
|
|
414
416
|
filter(e) {
|
|
415
|
-
return
|
|
417
|
+
return c(o(this, h).filter((t, r) => typeof e != "function" ? !!t : e(t, r, this)));
|
|
416
418
|
}
|
|
417
419
|
first(e) {
|
|
418
420
|
return typeof e == "function" ? o(this, h).find((t, r) => e(t, r, this)) ?? null : o(this, h)[0] ?? null;
|
|
@@ -427,38 +429,38 @@ 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 o(this, h).find((
|
|
434
|
+
return o(this, h).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 ? o(this, h).find((
|
|
437
|
+
return r === null ? o(this, h).find((i) => i[e] === null) ?? null : o(this, h).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(o(this, h).flatMap((t, r) => e(t, r, this)));
|
|
456
458
|
}
|
|
457
459
|
forget(e) {
|
|
458
|
-
return o(this, h).splice(e, 1),
|
|
460
|
+
return o(this, h).splice(e, 1), T(this), this;
|
|
459
461
|
}
|
|
460
462
|
forPage(e, t) {
|
|
461
|
-
return
|
|
463
|
+
return c(o(this, h).slice((e - 1) * t, e * t));
|
|
462
464
|
}
|
|
463
465
|
get(e, t) {
|
|
464
466
|
if (typeof e != "number")
|
|
@@ -467,19 +469,19 @@ class L {
|
|
|
467
469
|
}
|
|
468
470
|
groupBy(e) {
|
|
469
471
|
const t = Array.isArray(e) ? e : [e];
|
|
470
|
-
return o(this, h).reduce((r,
|
|
471
|
-
const u = t.map((
|
|
472
|
-
if (typeof
|
|
473
|
-
const d =
|
|
472
|
+
return o(this, h).reduce((r, i, s) => {
|
|
473
|
+
const u = t.map((l) => {
|
|
474
|
+
if (typeof l == "function") {
|
|
475
|
+
const d = l(i, s, this);
|
|
474
476
|
return Array.isArray(d) ? d : [d];
|
|
475
477
|
}
|
|
476
|
-
return [String(
|
|
478
|
+
return [String(i[l])];
|
|
477
479
|
});
|
|
478
|
-
return
|
|
479
|
-
const d = Array.isArray(
|
|
480
|
+
return H(...u).forEach((l) => {
|
|
481
|
+
const d = Array.isArray(l) ? l.join(".") : l;
|
|
480
482
|
f.set(r, d, [
|
|
481
483
|
...f.get(r, d, []),
|
|
482
|
-
|
|
484
|
+
i
|
|
483
485
|
]);
|
|
484
486
|
}), r;
|
|
485
487
|
}, {});
|
|
@@ -499,7 +501,7 @@ class L {
|
|
|
499
501
|
return o(this, h).join(e);
|
|
500
502
|
}
|
|
501
503
|
if (typeof e == "function")
|
|
502
|
-
return o(this, h).map((r,
|
|
504
|
+
return o(this, h).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
507
|
if (!o(this, h).every((r) => typeof r == "object"))
|
|
@@ -507,7 +509,7 @@ class L {
|
|
|
507
509
|
return o(this, h).map((r) => r[e]).join(t);
|
|
508
510
|
}
|
|
509
511
|
intersect(e) {
|
|
510
|
-
return Array.isArray(e) ?
|
|
512
|
+
return Array.isArray(e) ? c(o(this, h).filter((t) => e.includes(t))) : c(o(this, h).filter((t) => e.contains(t)));
|
|
511
513
|
}
|
|
512
514
|
isEmpty() {
|
|
513
515
|
return o(this, h).length === 0;
|
|
@@ -520,7 +522,7 @@ class L {
|
|
|
520
522
|
}
|
|
521
523
|
keyBy(e) {
|
|
522
524
|
if (typeof e == "function")
|
|
523
|
-
return o(this, h).reduce((t, r,
|
|
525
|
+
return o(this, h).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
528
|
return o(this, h).reduce((t, r) => (t[String(r[e])] = r, t), {});
|
|
@@ -529,31 +531,31 @@ class L {
|
|
|
529
531
|
return typeof e == "function" ? o(this, h).toReversed().find((t, r) => e(t, r, this)) ?? null : o(this, h)[o(this, h).length - 1] ?? null;
|
|
530
532
|
}
|
|
531
533
|
map(e) {
|
|
532
|
-
return
|
|
534
|
+
return c(o(this, h).map((t, r) => e(t, r, this)));
|
|
533
535
|
}
|
|
534
536
|
mapInto(e) {
|
|
535
|
-
return
|
|
537
|
+
return c(o(this, h).map((t) => new e(t)));
|
|
536
538
|
}
|
|
537
539
|
mapSpread(e) {
|
|
538
|
-
return
|
|
539
|
-
if (!Array.isArray(t) &&
|
|
540
|
+
return c(o(this, h).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 o(this, h).reduce((t, r,
|
|
547
|
-
const
|
|
548
|
-
return Object.entries(
|
|
548
|
+
return o(this, h).reduce((t, r, i) => {
|
|
549
|
+
const s = e(r, i, this);
|
|
550
|
+
return Object.entries(s).forEach(([u, a]) => {
|
|
549
551
|
t[u] = t[u] ?? [], t[u].push(a);
|
|
550
552
|
}), t;
|
|
551
553
|
}, {});
|
|
552
554
|
}
|
|
553
555
|
mapWithKeys(e) {
|
|
554
|
-
return o(this, h).reduce((t, r,
|
|
555
|
-
const
|
|
556
|
-
return Object.entries(
|
|
556
|
+
return o(this, h).reduce((t, r, i) => {
|
|
557
|
+
const s = e(r, i, this);
|
|
558
|
+
return Object.entries(s).forEach(([u, a]) => {
|
|
557
559
|
t[u] = a;
|
|
558
560
|
}), t;
|
|
559
561
|
}, {});
|
|
@@ -563,33 +565,33 @@ class L {
|
|
|
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([I(i, s - 1), I(i, s)]).avg() : I(i, s);
|
|
568
570
|
}
|
|
569
571
|
const t = o(this, h).toSorted(), r = Math.floor(t.length / 2);
|
|
570
|
-
return t.length % 2 === 0 ?
|
|
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([...o(this, h), ...e]) : c([...o(this, h), ...e.all()]);
|
|
574
576
|
}
|
|
575
577
|
min(e) {
|
|
576
578
|
return typeof e == "string" ? o(this, h).reduce((t, r) => r[e] < t ? r[e] : t, o(this, h)[0][e]) : o(this, h).reduce((t, r) => r < t ? r : t, o(this, h)[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(o(this, h).filter((t, r) => e.includes(r)));
|
|
587
589
|
}
|
|
588
590
|
pad(e, t = null) {
|
|
589
591
|
const r = o(this, h).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 [
|
|
@@ -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
|
}
|
|
@@ -622,64 +624,64 @@ class L {
|
|
|
622
624
|
}
|
|
623
625
|
pop(e = 1) {
|
|
624
626
|
const t = o(this, h).splice(o(this, h).length - e, e);
|
|
625
|
-
return
|
|
627
|
+
return T(this), e === 1 ? t[0] ?? null : c(t);
|
|
626
628
|
}
|
|
627
629
|
prepend(e) {
|
|
628
630
|
const t = o(this, h).unshift(e);
|
|
629
|
-
return
|
|
631
|
+
return T(this), t;
|
|
630
632
|
}
|
|
631
633
|
pull(e) {
|
|
632
634
|
const t = o(this, h).splice(e, 1)[0] ?? null;
|
|
633
|
-
return
|
|
635
|
+
return T(this), t;
|
|
634
636
|
}
|
|
635
637
|
push(...e) {
|
|
636
638
|
const t = o(this, h).push(...e);
|
|
637
|
-
return
|
|
639
|
+
return T(this), t;
|
|
638
640
|
}
|
|
639
641
|
put(e, t) {
|
|
640
|
-
return o(this, h).splice(e, 1, t),
|
|
642
|
+
return o(this, h).splice(e, 1, t), T(this), this;
|
|
641
643
|
}
|
|
642
644
|
random(e = 1) {
|
|
643
645
|
if (o(this, h).length < e)
|
|
644
646
|
throw new Error("The collection has fewer items than the requested amount");
|
|
645
|
-
const t =
|
|
647
|
+
const t = c(f.sampleSize(o(this, h), e));
|
|
646
648
|
return e === 1 ? t.first() : t;
|
|
647
649
|
}
|
|
648
650
|
reduce(e, t = null) {
|
|
649
|
-
return o(this, h).reduce((r,
|
|
651
|
+
return o(this, h).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
657
|
const t = o(this, h).slice();
|
|
656
|
-
return Object.entries(e).forEach(([r,
|
|
657
|
-
t[parseInt(r)] =
|
|
658
|
-
}),
|
|
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(o(this, h).toReversed());
|
|
662
664
|
}
|
|
663
665
|
search(e, t = !1) {
|
|
664
|
-
if (typeof e != "function" || o(this, h).every((
|
|
665
|
-
const
|
|
666
|
-
return
|
|
666
|
+
if (typeof e != "function" || o(this, h).every((i) => typeof i == "function")) {
|
|
667
|
+
const i = o(this, h).findIndex((s) => t ? s === e : s == e);
|
|
668
|
+
return i === -1 ? !1 : i;
|
|
667
669
|
}
|
|
668
|
-
const r = o(this, h).findIndex((
|
|
670
|
+
const r = o(this, h).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
677
|
const t = o(this, h).splice(0, e);
|
|
676
|
-
return
|
|
678
|
+
return T(this), e === 1 ? t[0] ?? null : c(t);
|
|
677
679
|
}
|
|
678
680
|
shuffle() {
|
|
679
|
-
return
|
|
681
|
+
return c(f.shuffle(o(this, h)));
|
|
680
682
|
}
|
|
681
683
|
skip(e) {
|
|
682
|
-
return
|
|
684
|
+
return c(o(this, h).slice(e));
|
|
683
685
|
}
|
|
684
686
|
skipUntil(e) {
|
|
685
687
|
return typeof e == "function" ? this.skip(o(this, h).findIndex((t, r) => e(t, r, this))) : this.skip(o(this, h).findIndex((t) => t == e));
|
|
@@ -688,13 +690,13 @@ class L {
|
|
|
688
690
|
return typeof e == "function" ? this.skip(o(this, h).findIndex((t, r) => !e(t, r, this))) : this.skip(o(this, h).findIndex((t) => t != e));
|
|
689
691
|
}
|
|
690
692
|
slice(e, t) {
|
|
691
|
-
return
|
|
693
|
+
return c(typeof t > "u" ? o(this, h).slice(e) : typeof e > "u" ? o(this, h).slice(0, t) : o(this, h).slice(e, e + t));
|
|
692
694
|
}
|
|
693
695
|
sliding(e, t = 1) {
|
|
694
696
|
const r = [];
|
|
695
|
-
for (let
|
|
696
|
-
r.push(o(this, h).slice(
|
|
697
|
-
return
|
|
697
|
+
for (let i = 0; i < o(this, h).length && !(i + e > o(this, h).length); i += t)
|
|
698
|
+
r.push(o(this, h).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") {
|
|
@@ -711,26 +713,26 @@ class L {
|
|
|
711
713
|
return this.contains(...e);
|
|
712
714
|
}
|
|
713
715
|
sort(e) {
|
|
714
|
-
return
|
|
716
|
+
return c(o(this, h).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(o(this, h).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 a = r[
|
|
725
|
-
if (a >
|
|
724
|
+
return e.every((r) => Array.isArray(r)) ? c(o(this, h).toSorted((r, i) => {
|
|
725
|
+
for (const [s, u] of e) {
|
|
726
|
+
const a = r[s] ?? -1 / 0, l = i[s] ?? -1 / 0;
|
|
727
|
+
if (a > l)
|
|
726
728
|
return u === "asc" ? 1 : -1;
|
|
727
|
-
if (a <
|
|
729
|
+
if (a < l)
|
|
728
730
|
return u === "asc" ? -1 : 1;
|
|
729
731
|
}
|
|
730
732
|
return 0;
|
|
731
|
-
})) :
|
|
732
|
-
for (const
|
|
733
|
-
const u =
|
|
733
|
+
})) : c(o(this, h).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,31 +740,31 @@ 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(o(this, h).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 ? o(this, h).length : t, s = o(this, h).splice(e, i, ...r);
|
|
753
|
+
return T(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 = o(this, h).slice(
|
|
757
759
|
t.flat().length,
|
|
758
760
|
t.flat().length + Math.min(
|
|
759
761
|
Math.ceil((o(this, h).length - t.flat().length) / (e - r)),
|
|
760
762
|
o(this, h).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
770
|
const t = Math.ceil(o(this, h).length / e);
|
|
@@ -770,10 +772,10 @@ class L {
|
|
|
770
772
|
}
|
|
771
773
|
sum(e) {
|
|
772
774
|
return typeof e == "string" ? o(this, h).reduce((t, r) => {
|
|
773
|
-
const
|
|
774
|
-
if (typeof
|
|
775
|
+
const i = r[e];
|
|
776
|
+
if (typeof i != "number")
|
|
775
777
|
throw new TypeError("The items must be numbers");
|
|
776
|
-
return t +
|
|
778
|
+
return t + i;
|
|
777
779
|
}, 0) : o(this, h).reduce((t, r) => {
|
|
778
780
|
if (typeof r != "number")
|
|
779
781
|
throw new TypeError("The items must be numbers");
|
|
@@ -781,7 +783,7 @@ class L {
|
|
|
781
783
|
}, 0);
|
|
782
784
|
}
|
|
783
785
|
take(e) {
|
|
784
|
-
return
|
|
786
|
+
return c(o(this, h).slice(0, e));
|
|
785
787
|
}
|
|
786
788
|
takeUntil(e) {
|
|
787
789
|
return typeof e == "function" ? this.take(o(this, h).findIndex((t, r) => e(t, r, this))) : this.take(o(this, h).findIndex((t) => t == e));
|
|
@@ -802,13 +804,13 @@ class L {
|
|
|
802
804
|
transform(e) {
|
|
803
805
|
for (const [t, r] of o(this, h).entries())
|
|
804
806
|
o(this, h).splice(t, 1, e(r, t, this));
|
|
805
|
-
return
|
|
807
|
+
return T(this), this;
|
|
806
808
|
}
|
|
807
809
|
unique(e) {
|
|
808
|
-
return
|
|
810
|
+
return c(typeof e == "string" ? o(this, h).filter((t, r) => !o(this, h).some((i, s) => i[e] == t[e] && s !== r)) : [...new Set(o(this, h))]);
|
|
809
811
|
}
|
|
810
812
|
uniqueStrict(e) {
|
|
811
|
-
return
|
|
813
|
+
return c(typeof e == "string" ? o(this, h).filter((t, r) => !o(this, h).some((i, s) => i[e] === t[e] && s !== r)) : [...new Set(o(this, h))]);
|
|
812
814
|
}
|
|
813
815
|
unless(e, t, r) {
|
|
814
816
|
return e ? typeof r == "function" && r(this) : t(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(o(this, h).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(o(this, h).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(o(this, h).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(o(this, h).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(o(this, h).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(o(this, h).filter((s, u) => i[t](s, u, this)));
|
|
871
873
|
}
|
|
872
874
|
whereBetween(e, [t, r]) {
|
|
873
|
-
return
|
|
875
|
+
return c(o(this, h).filter((i) => i[e] >= t && i[e] <= r));
|
|
874
876
|
}
|
|
875
877
|
whereIn(e, t) {
|
|
876
|
-
return
|
|
878
|
+
return c(o(this, h).filter((r) => t.includes(r[e])));
|
|
877
879
|
}
|
|
878
880
|
whereInstanceOf(e) {
|
|
879
|
-
return
|
|
881
|
+
return c(o(this, h).filter((t) => t instanceof e));
|
|
880
882
|
}
|
|
881
883
|
whereNotBetween(e, [t, r]) {
|
|
882
|
-
return
|
|
884
|
+
return c(o(this, h).filter((i) => i[e] < t || i[e] > r));
|
|
883
885
|
}
|
|
884
886
|
whereNotIn(e, t) {
|
|
885
|
-
return
|
|
887
|
+
return c(o(this, h).filter((r) => !t.includes(r[e])));
|
|
886
888
|
}
|
|
887
889
|
whereNotNull(e) {
|
|
888
|
-
return
|
|
890
|
+
return c(o(this, h).filter((t) => t[e] !== null));
|
|
889
891
|
}
|
|
890
892
|
whereNull(e) {
|
|
891
|
-
return
|
|
893
|
+
return c(o(this, h).filter((t) => t[e] === null));
|
|
892
894
|
}
|
|
893
895
|
zip(e) {
|
|
894
|
-
return Array.isArray(e) ?
|
|
896
|
+
return Array.isArray(e) ? c(
|
|
895
897
|
o(this, h).map((t, r) => [t, e[r] ?? null])
|
|
896
|
-
) :
|
|
898
|
+
) : c(
|
|
897
899
|
o(this, h).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
916
|
h = new WeakMap();
|
|
915
|
-
const
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
917
|
+
const C = A(Q);
|
|
918
|
+
var ee, te;
|
|
919
|
+
class W extends (te = Q, 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 We 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 Ge = A(S);
|
|
945
|
+
class Ve {
|
|
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 Ge(r), this.bag.on("change", () => {
|
|
942
949
|
this.emit("change", {
|
|
943
950
|
data: this.bag
|
|
944
951
|
});
|
|
@@ -946,15 +953,15 @@ 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);
|
|
@@ -981,7 +988,7 @@ class _e {
|
|
|
981
988
|
return this.bag.set(`where.${f.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",
|
|
@@ -989,7 +996,22 @@ class _e {
|
|
|
989
996
|
"<": "LessThan",
|
|
990
997
|
"<=": "LessThanOrEquals"
|
|
991
998
|
}[t] || f.upperFirst(f.camelCase(t));
|
|
992
|
-
return this.bag.set(`where.${f.camelCase(e)}${
|
|
999
|
+
return this.bag.set(`where.${f.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 a = new
|
|
1041
|
+
}), i = this.facades.model.make(this.abstract), s = c(r.data.map((u) => {
|
|
1042
|
+
const a = new i(u);
|
|
1016
1043
|
return a.exists = !0, this.facades.model.emit("fetch", {
|
|
1017
1044
|
class: this.abstract,
|
|
1018
1045
|
model: a
|
|
1019
1046
|
}), a;
|
|
1020
|
-
}),
|
|
1047
|
+
}), W);
|
|
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
1061
|
links: r.meta.links.map((a) => ({
|
|
1035
1062
|
...a,
|
|
1036
|
-
url: a.url && `${u}?${
|
|
1063
|
+
url: a.url && `${u}?${v(t, a.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 We(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 }, (a, l) => l + 2), s = await Promise.all(
|
|
1107
|
+
i.map((a) => this.limit(e).exec(a))
|
|
1108
|
+
), u = c(
|
|
1109
|
+
s.reduce((a, l) => (a.push(...l.data), a), t.data).all(),
|
|
1110
|
+
W
|
|
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 Xe = A(Ve);
|
|
1122
|
+
var ie, ne;
|
|
1123
|
+
class _ 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 x 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 Ye 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 Ze 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
1153
|
class j {
|
|
1123
|
-
constructor(e, t, r,
|
|
1124
|
-
|
|
1125
|
-
if (this.meta = e, this.facades = t, this.parent = r, this.items =
|
|
1126
|
-
throw new
|
|
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 x("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 _("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 Ze(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 Ye(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 x("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,45 +1277,50 @@ class j {
|
|
|
1246
1277
|
// return this.query().find(id);
|
|
1247
1278
|
// }
|
|
1248
1279
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1280
|
+
var de, fe;
|
|
1281
|
+
class Ne extends (fe = Error, de = Symbol.toStringTag, fe) {
|
|
1282
|
+
constructor(t, r) {
|
|
1283
|
+
super(`[Luminix] Attribute "${r}" in model "${t}" is not fillable`);
|
|
1284
|
+
m(this, de, "AttributeNotFillableException");
|
|
1252
1285
|
}
|
|
1253
1286
|
}
|
|
1254
|
-
|
|
1255
|
-
class
|
|
1256
|
-
constructor(
|
|
1257
|
-
super(`[Luminix] Model "${
|
|
1287
|
+
var pe, me;
|
|
1288
|
+
class ve extends (me = Error, pe = Symbol.toStringTag, me) {
|
|
1289
|
+
constructor(t, r) {
|
|
1290
|
+
super(`[Luminix] Model "${t}" must be persisted before calling "${r}"`);
|
|
1291
|
+
m(this, pe, "ModelNotPersistedException");
|
|
1258
1292
|
}
|
|
1259
1293
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1294
|
+
function ze(n, e) {
|
|
1295
|
+
var r;
|
|
1296
|
+
r = Symbol.toStringTag;
|
|
1262
1297
|
class t {
|
|
1263
1298
|
constructor(s = {}) {
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1299
|
+
m(this, "_attributes", new S({}));
|
|
1300
|
+
m(this, "_original", {});
|
|
1301
|
+
m(this, "_relations", {});
|
|
1302
|
+
m(this, "_changedKeys", []);
|
|
1303
|
+
m(this, "exists", !1);
|
|
1304
|
+
m(this, r, f.upperFirst(f.camelCase(e)));
|
|
1269
1305
|
this.makeRelations(), this.makeAttributes(s);
|
|
1270
1306
|
}
|
|
1271
|
-
cast(s,
|
|
1272
|
-
return s == null || !
|
|
1307
|
+
cast(s, u) {
|
|
1308
|
+
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
1309
|
}
|
|
1274
|
-
mutate(s,
|
|
1275
|
-
return s == null || !
|
|
1310
|
+
mutate(s, u) {
|
|
1311
|
+
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
1312
|
}
|
|
1277
1313
|
makeRelations() {
|
|
1278
1314
|
const { relations: s } = n.model.schema(e);
|
|
1279
1315
|
if (this._relations = {}, !s)
|
|
1280
1316
|
return;
|
|
1281
1317
|
if (typeof n.model.relationMap != "function")
|
|
1282
|
-
throw new
|
|
1283
|
-
const
|
|
1284
|
-
Object.entries(s).forEach(([
|
|
1285
|
-
const { type:
|
|
1286
|
-
this._relations[
|
|
1287
|
-
{ name:
|
|
1318
|
+
throw new _("ModelFacade");
|
|
1319
|
+
const u = n.model.relationMap({}, e);
|
|
1320
|
+
Object.entries(s).forEach(([a, l]) => {
|
|
1321
|
+
const { type: d } = l, p = d in u ? u[d] : j;
|
|
1322
|
+
this._relations[a] = new p(
|
|
1323
|
+
{ name: a, ...l },
|
|
1288
1324
|
n,
|
|
1289
1325
|
this,
|
|
1290
1326
|
null
|
|
@@ -1292,12 +1328,12 @@ function $e(n, e) {
|
|
|
1292
1328
|
});
|
|
1293
1329
|
}
|
|
1294
1330
|
makeAttributes(s) {
|
|
1295
|
-
const { relations:
|
|
1296
|
-
if (this.fillable.filter((
|
|
1297
|
-
|
|
1298
|
-
}),
|
|
1299
|
-
this.relation(f.camelCase(
|
|
1300
|
-
}), !this.validateJsonObject(
|
|
1331
|
+
const { relations: u } = n.model.schema(e), a = Object.keys(u || {}), l = f.omit(s, a);
|
|
1332
|
+
if (this.fillable.filter((d) => !(d in l)).forEach((d) => {
|
|
1333
|
+
l[d] = null;
|
|
1334
|
+
}), u && Object.keys(u).forEach((d) => {
|
|
1335
|
+
this.relation(f.camelCase(d)).make(s[d]);
|
|
1336
|
+
}), !this.validateJsonObject(l)) {
|
|
1301
1337
|
if (n.config.get("app.env", "production") === "production")
|
|
1302
1338
|
throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
|
|
1303
1339
|
n.log.warning(`Invalid attributes for model "${e}".
|
|
@@ -1306,7 +1342,7 @@ function $e(n, e) {
|
|
|
1306
1342
|
abstract: e
|
|
1307
1343
|
});
|
|
1308
1344
|
}
|
|
1309
|
-
this._attributes = new
|
|
1345
|
+
this._attributes = new S(l), this._original = l, this._changedKeys = [];
|
|
1310
1346
|
}
|
|
1311
1347
|
makePrimaryKeyReplacer() {
|
|
1312
1348
|
return {
|
|
@@ -1360,23 +1396,23 @@ function $e(n, e) {
|
|
|
1360
1396
|
model: this
|
|
1361
1397
|
});
|
|
1362
1398
|
}
|
|
1363
|
-
dispatchErrorEvent(s,
|
|
1399
|
+
dispatchErrorEvent(s, u) {
|
|
1364
1400
|
this.emit("error", {
|
|
1365
1401
|
error: s,
|
|
1366
|
-
operation:
|
|
1402
|
+
operation: u
|
|
1367
1403
|
}), n.model.emit("error", {
|
|
1368
1404
|
class: e,
|
|
1369
1405
|
model: this,
|
|
1370
1406
|
error: s,
|
|
1371
|
-
operation:
|
|
1407
|
+
operation: u
|
|
1372
1408
|
});
|
|
1373
1409
|
}
|
|
1374
1410
|
updateChangedKeys(s) {
|
|
1375
|
-
const
|
|
1376
|
-
!this._changedKeys.includes(s) && !
|
|
1411
|
+
const u = (a, l) => typeof a == "object" && a !== null ? f.isEqual(a, l) : a == l;
|
|
1412
|
+
!this._changedKeys.includes(s) && !u(this._original[s], this._attributes.get("key")) ? this._changedKeys.push(s) : this._changedKeys.includes(s) && u(this._original[s], this._attributes.get("key")) && this._changedKeys.splice(this._changedKeys.indexOf(s), 1);
|
|
1377
1413
|
}
|
|
1378
1414
|
validateJsonObject(s) {
|
|
1379
|
-
return typeof s != "object" || s === null ? !1 : Object.entries(s).every(([,
|
|
1415
|
+
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((a) => this.validateJsonObject(a)));
|
|
1380
1416
|
}
|
|
1381
1417
|
get attributes() {
|
|
1382
1418
|
return this._attributes.all();
|
|
@@ -1410,42 +1446,42 @@ function $e(n, e) {
|
|
|
1410
1446
|
return this._changedKeys.length > 0;
|
|
1411
1447
|
}
|
|
1412
1448
|
getAttribute(s) {
|
|
1413
|
-
let
|
|
1414
|
-
s in this.casts && (
|
|
1415
|
-
const
|
|
1416
|
-
if (typeof
|
|
1417
|
-
throw new
|
|
1418
|
-
return
|
|
1419
|
-
}
|
|
1420
|
-
setAttribute(s,
|
|
1449
|
+
let u = this._attributes.get(s, null);
|
|
1450
|
+
s in this.casts && (u = this.cast(u, this.casts[s]));
|
|
1451
|
+
const a = n.model[`model${f.upperFirst(f.camelCase(e))}Get${f.upperFirst(f.camelCase(s))}Attribute`];
|
|
1452
|
+
if (typeof a != "function")
|
|
1453
|
+
throw new _("ModelFacade");
|
|
1454
|
+
return a.bind(n.model)(u, this);
|
|
1455
|
+
}
|
|
1456
|
+
setAttribute(s, u) {
|
|
1421
1457
|
if (!this.fillable.includes(s)) {
|
|
1422
1458
|
if (n.config.get("app.env", "production") === "production")
|
|
1423
|
-
throw new
|
|
1459
|
+
throw new Ne(e, s);
|
|
1424
1460
|
n.log.warning(`[Luminix] Trying to set a non-fillable attribute "${s}" in model "${e}".
|
|
1425
1461
|
This will throw an error in production.`);
|
|
1426
1462
|
return;
|
|
1427
1463
|
}
|
|
1428
|
-
const
|
|
1429
|
-
if (typeof
|
|
1430
|
-
throw new
|
|
1431
|
-
const
|
|
1432
|
-
this.mutate(
|
|
1464
|
+
const a = n.model[`model${f.upperFirst(f.camelCase(e))}Set${f.upperFirst(f.camelCase(s))}Attribute`];
|
|
1465
|
+
if (typeof a != "function")
|
|
1466
|
+
throw new _("ModelFacade");
|
|
1467
|
+
const l = a.bind(n.model)(
|
|
1468
|
+
this.mutate(u, this.casts[s]),
|
|
1433
1469
|
this
|
|
1434
1470
|
);
|
|
1435
|
-
if (!this.validateJsonObject({ [s]:
|
|
1471
|
+
if (!this.validateJsonObject({ [s]: l })) {
|
|
1436
1472
|
if (n.config.get("app.env", "production") === "production")
|
|
1437
1473
|
throw new TypeError(`[Luminix] Attribute "${s}" in model "${e}" must be a boolean, number, string or null`);
|
|
1438
1474
|
n.log.warning(`Invalid type for attribute "${s}" in model "${e}" after mutation.
|
|
1439
1475
|
This will throw an error in production.`, {
|
|
1440
1476
|
key: s,
|
|
1441
|
-
value:
|
|
1442
|
-
mutated:
|
|
1477
|
+
value: u,
|
|
1478
|
+
mutated: l,
|
|
1443
1479
|
cast: this.casts[s],
|
|
1444
1480
|
item: this.toJson()
|
|
1445
1481
|
});
|
|
1446
1482
|
return;
|
|
1447
1483
|
}
|
|
1448
|
-
this._attributes.set(s,
|
|
1484
|
+
this._attributes.set(s, l), this.updateChangedKeys(s), this.dispatchChangeEvent({ [s]: l });
|
|
1449
1485
|
}
|
|
1450
1486
|
getKey() {
|
|
1451
1487
|
return this.getAttribute(this.primaryKey);
|
|
@@ -1454,28 +1490,28 @@ function $e(n, e) {
|
|
|
1454
1490
|
return this.primaryKey;
|
|
1455
1491
|
}
|
|
1456
1492
|
fill(s) {
|
|
1457
|
-
const
|
|
1458
|
-
const
|
|
1459
|
-
if (typeof
|
|
1460
|
-
throw new
|
|
1461
|
-
return
|
|
1462
|
-
this.mutate(
|
|
1493
|
+
const u = f.pick(s, this.fillable), a = Object.entries(u).reduce((l, [d, p]) => {
|
|
1494
|
+
const y = n.model[`model${f.upperFirst(f.camelCase(e))}Set${f.upperFirst(f.camelCase(d))}Attribute`];
|
|
1495
|
+
if (typeof y != "function")
|
|
1496
|
+
throw new _("ModelFacade");
|
|
1497
|
+
return l[d] = y.bind(n.model)(
|
|
1498
|
+
this.mutate(p, this.casts[d]),
|
|
1463
1499
|
this
|
|
1464
|
-
),
|
|
1500
|
+
), l;
|
|
1465
1501
|
}, {});
|
|
1466
|
-
if (!this.validateJsonObject(
|
|
1502
|
+
if (!this.validateJsonObject(a)) {
|
|
1467
1503
|
if (n.config.get("app.env", "production") === "production")
|
|
1468
1504
|
throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
|
|
1469
1505
|
n.log.warning(`Invalid attributes for model "${e}" after mutation.
|
|
1470
1506
|
This will throw an error in production.`, {
|
|
1471
1507
|
attributes: s,
|
|
1472
|
-
mutatedAttributes:
|
|
1508
|
+
mutatedAttributes: a,
|
|
1473
1509
|
item: this.toJson(),
|
|
1474
1510
|
casts: this.casts
|
|
1475
1511
|
});
|
|
1476
1512
|
return;
|
|
1477
1513
|
}
|
|
1478
|
-
this._attributes.merge(".",
|
|
1514
|
+
this._attributes.merge(".", a), Object.keys(a).forEach((l) => this.updateChangedKeys(l)), this.dispatchChangeEvent(a);
|
|
1479
1515
|
}
|
|
1480
1516
|
dump() {
|
|
1481
1517
|
n.log.info({
|
|
@@ -1484,16 +1520,16 @@ function $e(n, e) {
|
|
|
1484
1520
|
});
|
|
1485
1521
|
}
|
|
1486
1522
|
toJson() {
|
|
1487
|
-
const s = Object.entries(this.relations).reduce((
|
|
1488
|
-
if (typeof
|
|
1489
|
-
throw new
|
|
1490
|
-
return
|
|
1523
|
+
const s = Object.entries(this.relations).reduce((a, [l, d]) => (d.isLoaded() && (d.isSingle() ? a[f.snakeCase(l)] = d.getLoadedItems().toJson() : d.isMultiple() && (a[f.snakeCase(l)] = d.getLoadedItems().map((p) => p.toJson()).all())), a), {}), u = n.model[`model${f.upperFirst(f.camelCase(e))}Json`];
|
|
1524
|
+
if (typeof u != "function")
|
|
1525
|
+
throw new _("ModelFacade");
|
|
1526
|
+
return u.bind(n.model)({
|
|
1491
1527
|
...this.attributes,
|
|
1492
1528
|
...s
|
|
1493
1529
|
}, this);
|
|
1494
1530
|
}
|
|
1495
1531
|
diff() {
|
|
1496
|
-
return this._changedKeys.reduce((s,
|
|
1532
|
+
return this._changedKeys.reduce((s, u) => (s[u] = this._attributes.get(u), s), {});
|
|
1497
1533
|
}
|
|
1498
1534
|
getType() {
|
|
1499
1535
|
return e;
|
|
@@ -1504,7 +1540,7 @@ function $e(n, e) {
|
|
|
1504
1540
|
}
|
|
1505
1541
|
async refresh() {
|
|
1506
1542
|
if (!this.exists)
|
|
1507
|
-
throw new
|
|
1543
|
+
throw new ve(e, "refresh");
|
|
1508
1544
|
const { data: s } = await n.route.call([
|
|
1509
1545
|
`luminix.${e}.show`,
|
|
1510
1546
|
this.makePrimaryKeyReplacer()
|
|
@@ -1516,33 +1552,33 @@ function $e(n, e) {
|
|
|
1516
1552
|
async save(s = {}) {
|
|
1517
1553
|
try {
|
|
1518
1554
|
const {
|
|
1519
|
-
additionalPayload:
|
|
1520
|
-
sendsOnlyModifiedFields:
|
|
1521
|
-
} = s,
|
|
1555
|
+
additionalPayload: u = {},
|
|
1556
|
+
sendsOnlyModifiedFields: a = !0
|
|
1557
|
+
} = s, l = this.exists, d = l ? [
|
|
1522
1558
|
`luminix.${e}.update`,
|
|
1523
1559
|
this.makePrimaryKeyReplacer()
|
|
1524
|
-
] : `luminix.${e}.store`,
|
|
1525
|
-
|
|
1560
|
+
] : `luminix.${e}.store`, p = await n.route.call(
|
|
1561
|
+
d,
|
|
1526
1562
|
{
|
|
1527
1563
|
data: {
|
|
1528
1564
|
...f.pick(
|
|
1529
|
-
|
|
1565
|
+
a && l ? this.diff() : this.attributes,
|
|
1530
1566
|
this.fillable
|
|
1531
1567
|
),
|
|
1532
|
-
...
|
|
1568
|
+
...u
|
|
1533
1569
|
},
|
|
1534
|
-
errorBag:
|
|
1570
|
+
errorBag: l ? `${e}[${this.getKey()}].update` : `${e}.store`
|
|
1535
1571
|
}
|
|
1536
1572
|
);
|
|
1537
|
-
if ([200, 201].includes(
|
|
1538
|
-
return this.makeAttributes(
|
|
1539
|
-
throw
|
|
1540
|
-
} catch (
|
|
1541
|
-
throw n.log.error(
|
|
1573
|
+
if ([200, 201].includes(p.status))
|
|
1574
|
+
return this.makeAttributes(p.data), this.exists = !0, this.dispatchSaveEvent(), l ? this.dispatchUpdateEvent(p.data) : this.dispatchCreateEvent(p.data), p;
|
|
1575
|
+
throw p;
|
|
1576
|
+
} catch (u) {
|
|
1577
|
+
throw n.log.error(u), this.dispatchErrorEvent(u, "save"), u;
|
|
1542
1578
|
}
|
|
1543
1579
|
}
|
|
1544
1580
|
async push() {
|
|
1545
|
-
throw new
|
|
1581
|
+
throw new b();
|
|
1546
1582
|
}
|
|
1547
1583
|
async delete() {
|
|
1548
1584
|
try {
|
|
@@ -1561,20 +1597,20 @@ function $e(n, e) {
|
|
|
1561
1597
|
}
|
|
1562
1598
|
async update(s) {
|
|
1563
1599
|
try {
|
|
1564
|
-
const
|
|
1600
|
+
const u = await n.route.call([
|
|
1565
1601
|
`luminix.${e}.update`,
|
|
1566
1602
|
this.makePrimaryKeyReplacer()
|
|
1567
1603
|
], {
|
|
1568
1604
|
data: s,
|
|
1569
1605
|
errorBag: `${e}[${this.getKey()}].update`
|
|
1570
1606
|
});
|
|
1571
|
-
if (
|
|
1572
|
-
this.makeAttributes(
|
|
1607
|
+
if (u.status === 200) {
|
|
1608
|
+
this.makeAttributes(u.data), this.dispatchUpdateEvent(u.data);
|
|
1573
1609
|
return;
|
|
1574
1610
|
}
|
|
1575
|
-
throw
|
|
1576
|
-
} catch (
|
|
1577
|
-
throw n.log.error(
|
|
1611
|
+
throw u;
|
|
1612
|
+
} catch (u) {
|
|
1613
|
+
throw n.log.error(u), this.dispatchErrorEvent(u, "save"), u;
|
|
1578
1614
|
}
|
|
1579
1615
|
}
|
|
1580
1616
|
async forceDelete() {
|
|
@@ -1622,7 +1658,7 @@ function $e(n, e) {
|
|
|
1622
1658
|
return n.model.schema(e);
|
|
1623
1659
|
}
|
|
1624
1660
|
static query() {
|
|
1625
|
-
return new
|
|
1661
|
+
return new Xe(n, e);
|
|
1626
1662
|
}
|
|
1627
1663
|
static where(...s) {
|
|
1628
1664
|
return this.query().where(...s);
|
|
@@ -1633,14 +1669,14 @@ function $e(n, e) {
|
|
|
1633
1669
|
static whereNotNull(s) {
|
|
1634
1670
|
return this.query().whereNotNull(s);
|
|
1635
1671
|
}
|
|
1636
|
-
static whereBetween(s,
|
|
1637
|
-
return this.query().whereBetween(s,
|
|
1672
|
+
static whereBetween(s, u) {
|
|
1673
|
+
return this.query().whereBetween(s, u);
|
|
1638
1674
|
}
|
|
1639
|
-
static whereNotBetween(s,
|
|
1640
|
-
return this.query().whereNotBetween(s,
|
|
1675
|
+
static whereNotBetween(s, u) {
|
|
1676
|
+
return this.query().whereNotBetween(s, u);
|
|
1641
1677
|
}
|
|
1642
|
-
static orderBy(s,
|
|
1643
|
-
return this.query().orderBy(s,
|
|
1678
|
+
static orderBy(s, u = "asc") {
|
|
1679
|
+
return this.query().orderBy(s, u);
|
|
1644
1680
|
}
|
|
1645
1681
|
static searchBy(s) {
|
|
1646
1682
|
return this.query().searchBy(s);
|
|
@@ -1651,8 +1687,8 @@ function $e(n, e) {
|
|
|
1651
1687
|
static limit(s) {
|
|
1652
1688
|
return this.query().limit(s);
|
|
1653
1689
|
}
|
|
1654
|
-
static get(s = 1,
|
|
1655
|
-
return this.query().get(s,
|
|
1690
|
+
static get(s = 1, u) {
|
|
1691
|
+
return this.query().get(s, u);
|
|
1656
1692
|
}
|
|
1657
1693
|
static find(s) {
|
|
1658
1694
|
return this.query().find(s);
|
|
@@ -1661,12 +1697,12 @@ function $e(n, e) {
|
|
|
1661
1697
|
return this.query().first();
|
|
1662
1698
|
}
|
|
1663
1699
|
static async create(s) {
|
|
1664
|
-
const
|
|
1665
|
-
return
|
|
1700
|
+
const u = n.model.make(e), a = new u();
|
|
1701
|
+
return a.fill(s), await a.save(), a;
|
|
1666
1702
|
}
|
|
1667
|
-
static async update(s,
|
|
1668
|
-
const
|
|
1669
|
-
return
|
|
1703
|
+
static async update(s, u) {
|
|
1704
|
+
const a = n.model.make(e), l = new a({ id: s });
|
|
1705
|
+
return l.fill(u), l.exists = !0, await l.save(), l;
|
|
1670
1706
|
}
|
|
1671
1707
|
static delete(s) {
|
|
1672
1708
|
if (Array.isArray(s))
|
|
@@ -1674,8 +1710,8 @@ function $e(n, e) {
|
|
|
1674
1710
|
params: { ids: s },
|
|
1675
1711
|
errorBag: `${e}.deleteMany`
|
|
1676
1712
|
});
|
|
1677
|
-
const
|
|
1678
|
-
return new
|
|
1713
|
+
const u = n.model.make(e);
|
|
1714
|
+
return new u({ id: s }).delete();
|
|
1679
1715
|
}
|
|
1680
1716
|
static async restore(s) {
|
|
1681
1717
|
if (Array.isArray(s))
|
|
@@ -1683,8 +1719,8 @@ function $e(n, e) {
|
|
|
1683
1719
|
data: { ids: s },
|
|
1684
1720
|
errorBag: `${e}.restoreMany`
|
|
1685
1721
|
});
|
|
1686
|
-
const
|
|
1687
|
-
return new
|
|
1722
|
+
const u = n.model.make(e);
|
|
1723
|
+
return new u({ id: s }).restore();
|
|
1688
1724
|
}
|
|
1689
1725
|
static forceDelete(s) {
|
|
1690
1726
|
if (Array.isArray(s))
|
|
@@ -1692,8 +1728,8 @@ function $e(n, e) {
|
|
|
1692
1728
|
params: { ids: s, force: !0 },
|
|
1693
1729
|
errorBag: `${e}.forceDeleteMany`
|
|
1694
1730
|
});
|
|
1695
|
-
const
|
|
1696
|
-
return new
|
|
1731
|
+
const u = n.model.make(e);
|
|
1732
|
+
return new u({ id: s }).forceDelete();
|
|
1697
1733
|
}
|
|
1698
1734
|
static singular() {
|
|
1699
1735
|
return n.model.schema(e).displayName.singular;
|
|
@@ -1702,94 +1738,97 @@ function $e(n, e) {
|
|
|
1702
1738
|
return n.model.schema(e).displayName.plural;
|
|
1703
1739
|
}
|
|
1704
1740
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1705
|
-
on(s,
|
|
1706
|
-
throw new
|
|
1741
|
+
on(s, u) {
|
|
1742
|
+
throw new b();
|
|
1707
1743
|
}
|
|
1708
1744
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1709
|
-
once(s,
|
|
1710
|
-
throw new
|
|
1745
|
+
once(s, u) {
|
|
1746
|
+
throw new b();
|
|
1711
1747
|
}
|
|
1712
1748
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1713
|
-
emit(s,
|
|
1714
|
-
throw new
|
|
1749
|
+
emit(s, u) {
|
|
1750
|
+
throw new b();
|
|
1715
1751
|
}
|
|
1716
1752
|
}
|
|
1717
|
-
return
|
|
1753
|
+
return A(t);
|
|
1718
1754
|
}
|
|
1719
|
-
function
|
|
1720
|
-
var r;
|
|
1721
|
-
return r =
|
|
1722
|
-
constructor(
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1755
|
+
function Oe(n, e, t) {
|
|
1756
|
+
var r, i;
|
|
1757
|
+
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
1758
|
+
constructor(u = {}) {
|
|
1759
|
+
super(u);
|
|
1760
|
+
m(this, r, f.upperFirst(f.camelCase(e)));
|
|
1761
|
+
return new Proxy(this, {
|
|
1762
|
+
get: (a, l) => {
|
|
1763
|
+
if (l === "__isModel")
|
|
1726
1764
|
return !0;
|
|
1727
|
-
if (
|
|
1728
|
-
const
|
|
1729
|
-
return typeof
|
|
1765
|
+
if (l in a) {
|
|
1766
|
+
const p = a[l];
|
|
1767
|
+
return typeof p == "function" ? p.bind(a) : p;
|
|
1730
1768
|
}
|
|
1731
|
-
if (
|
|
1769
|
+
if (l !== f.camelCase(l))
|
|
1732
1770
|
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
|
|
1771
|
+
const d = f.snakeCase(l);
|
|
1772
|
+
if (Object.keys(a.relations).includes(d))
|
|
1773
|
+
return a.relations[d].getLoadedItems();
|
|
1774
|
+
if (l.endsWith("Relation") && Object.keys(a.relations).includes(f.snakeCase(l.slice(0, -8))))
|
|
1775
|
+
return () => a.relation(l.slice(0, -8));
|
|
1776
|
+
if (Object.keys(a.attributes).includes(d))
|
|
1777
|
+
return a.getAttribute(d);
|
|
1778
|
+
if (n.model.hasReducer(`model${a.constructor.name}Get${f.upperFirst(l)}Attribute`)) {
|
|
1779
|
+
const p = n.model[`model${a.constructor.name}Get${f.upperFirst(l)}Attribute`];
|
|
1780
|
+
if (typeof p != "function")
|
|
1781
|
+
throw new _("ModelFacade");
|
|
1782
|
+
return p.bind(n.model)(void 0, a);
|
|
1745
1783
|
}
|
|
1746
|
-
return Reflect.get(
|
|
1784
|
+
return Reflect.get(a, l);
|
|
1747
1785
|
},
|
|
1748
|
-
set: (
|
|
1749
|
-
if (
|
|
1750
|
-
return Reflect.set(
|
|
1751
|
-
if (
|
|
1752
|
-
return
|
|
1753
|
-
f.snakeCase(
|
|
1754
|
-
|
|
1786
|
+
set: (a, l, d) => {
|
|
1787
|
+
if (l in a && typeof a[l] != "function")
|
|
1788
|
+
return Reflect.set(a, l, d);
|
|
1789
|
+
if (a.fillable.includes(f.snakeCase(l)))
|
|
1790
|
+
return a.setAttribute(
|
|
1791
|
+
f.snakeCase(l),
|
|
1792
|
+
d
|
|
1755
1793
|
), !0;
|
|
1756
|
-
throw new
|
|
1794
|
+
throw new Ne(e, f.snakeCase(l));
|
|
1757
1795
|
}
|
|
1758
1796
|
});
|
|
1759
1797
|
}
|
|
1760
|
-
}
|
|
1798
|
+
};
|
|
1761
1799
|
}
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1800
|
+
var ge, ye;
|
|
1801
|
+
class ke extends (ye = Error, ge = Symbol.toStringTag, ye) {
|
|
1802
|
+
constructor(t, r) {
|
|
1803
|
+
super(`[Luminix] Cannot create reducer '${t}' on '${r}' as it is a reserved property`);
|
|
1804
|
+
m(this, ge, "ReducerOverrideException");
|
|
1765
1805
|
}
|
|
1766
1806
|
}
|
|
1767
|
-
|
|
1768
|
-
function ie(n) {
|
|
1807
|
+
function Re(n) {
|
|
1769
1808
|
return class extends n {
|
|
1770
1809
|
constructor(...t) {
|
|
1771
1810
|
super(...t);
|
|
1772
|
-
|
|
1811
|
+
m(this, "reducers", {});
|
|
1773
1812
|
return new Proxy(this, {
|
|
1774
|
-
get(r,
|
|
1775
|
-
return typeof
|
|
1776
|
-
const { [
|
|
1777
|
-
return
|
|
1813
|
+
get(r, i, s) {
|
|
1814
|
+
return typeof i == "symbol" || i in r ? Reflect.get(r, i, s) : (u, ...a) => {
|
|
1815
|
+
const { [i]: l = c() } = r.reducers;
|
|
1816
|
+
return Le(u) ? R(u, (d) => l.sortBy("priority").reduce((p, y) => y.callback(p, ...a), d)) : l.sortBy("priority").reduce((d, p) => p.callback(d, ...a), u);
|
|
1778
1817
|
};
|
|
1779
1818
|
}
|
|
1780
1819
|
});
|
|
1781
1820
|
}
|
|
1782
|
-
reducer(t, r,
|
|
1821
|
+
reducer(t, r, i = 10) {
|
|
1783
1822
|
if (t in this)
|
|
1784
|
-
throw new
|
|
1785
|
-
return this.reducers[t] || (this.reducers[t] =
|
|
1823
|
+
throw new ke(t, this);
|
|
1824
|
+
return this.reducers[t] || (this.reducers[t] = c()), this.reducers[t].push({ callback: r, priority: i }), () => this.removeReducer(t, r);
|
|
1786
1825
|
}
|
|
1787
1826
|
removeReducer(t, r) {
|
|
1788
|
-
const
|
|
1789
|
-
|
|
1827
|
+
const i = this.reducers[t].search((s) => s.callback === r);
|
|
1828
|
+
i !== !1 && this.reducers[t].pull(i);
|
|
1790
1829
|
}
|
|
1791
1830
|
getReducer(t) {
|
|
1792
|
-
return this.reducers[t] || (this.reducers[t] =
|
|
1831
|
+
return this.reducers[t] || (this.reducers[t] = c()), this.reducers[t];
|
|
1793
1832
|
}
|
|
1794
1833
|
hasReducer(t) {
|
|
1795
1834
|
return !!this.reducers[t] && this.reducers[t].count() > 0;
|
|
@@ -1802,23 +1841,25 @@ function ie(n) {
|
|
|
1802
1841
|
}
|
|
1803
1842
|
};
|
|
1804
1843
|
}
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1844
|
+
var we, be;
|
|
1845
|
+
class G extends (be = Error, we = Symbol.toStringTag, be) {
|
|
1846
|
+
constructor(t) {
|
|
1847
|
+
super(`[Luminix] Model "${t}" not found`);
|
|
1848
|
+
m(this, we, "ModelNotFoundException");
|
|
1808
1849
|
}
|
|
1809
1850
|
}
|
|
1810
|
-
|
|
1811
|
-
class
|
|
1812
|
-
constructor(
|
|
1813
|
-
super(`[Luminix] "${
|
|
1851
|
+
var Ee, xe;
|
|
1852
|
+
class B extends (xe = TypeError, Ee = Symbol.toStringTag, xe) {
|
|
1853
|
+
constructor(t, r, i) {
|
|
1854
|
+
super(`[Luminix] "${t}" expects a related model of type "${r}". Received "${i}" instead.`);
|
|
1855
|
+
m(this, Ee, "ModelInvalidRelatedTypeException");
|
|
1814
1856
|
}
|
|
1815
1857
|
}
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
super(e, t, r, s), this.meta = e, this.facades = t, this.parent = r, this.items = s;
|
|
1858
|
+
class Be extends j {
|
|
1859
|
+
constructor(e, t, r, i = null) {
|
|
1860
|
+
if (!E(i) && i !== null)
|
|
1861
|
+
throw new x("BelongsTo.constructor()", "Model or null");
|
|
1862
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1822
1863
|
}
|
|
1823
1864
|
isSingle() {
|
|
1824
1865
|
return !0;
|
|
@@ -1834,12 +1875,12 @@ class ne extends j {
|
|
|
1834
1875
|
return this.query().first();
|
|
1835
1876
|
}
|
|
1836
1877
|
async associate(e) {
|
|
1837
|
-
if (!
|
|
1838
|
-
throw new
|
|
1878
|
+
if (!E(e))
|
|
1879
|
+
throw new x("BelongsTo.associate()");
|
|
1839
1880
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1840
|
-
throw new
|
|
1881
|
+
throw new B("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
|
|
1841
1882
|
if (!e.exists)
|
|
1842
|
-
throw new
|
|
1883
|
+
throw new ve(this.getRelated().getSchemaName(), "save");
|
|
1843
1884
|
return this.parent.update({
|
|
1844
1885
|
[this.getForeignKey()]: e.getKey()
|
|
1845
1886
|
});
|
|
@@ -1850,11 +1891,11 @@ class ne extends j {
|
|
|
1850
1891
|
});
|
|
1851
1892
|
}
|
|
1852
1893
|
}
|
|
1853
|
-
class
|
|
1854
|
-
constructor(e, t, r,
|
|
1855
|
-
if (
|
|
1856
|
-
throw new
|
|
1857
|
-
super(e, t, r,
|
|
1894
|
+
class qe extends j {
|
|
1895
|
+
constructor(e, t, r, i = null) {
|
|
1896
|
+
if (i !== null && !(i instanceof C && i.every(E)))
|
|
1897
|
+
throw new x("BelongsToMany.constructor()", "Collection<Model> or null");
|
|
1898
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1858
1899
|
}
|
|
1859
1900
|
isSingle() {
|
|
1860
1901
|
return !1;
|
|
@@ -1892,10 +1933,10 @@ class oe extends j {
|
|
|
1892
1933
|
}
|
|
1893
1934
|
async attach(e, t = {}) {
|
|
1894
1935
|
if (await this.attachQuietly(e, t), this.items) {
|
|
1895
|
-
const r = this.items.search((
|
|
1896
|
-
if (!
|
|
1936
|
+
const r = this.items.search((s) => s.getKey() === e), i = await this.getRelated().find(e);
|
|
1937
|
+
if (!i)
|
|
1897
1938
|
return;
|
|
1898
|
-
r !== !1 ? this.items.put(r,
|
|
1939
|
+
r !== !1 ? this.items.put(r, i) : this.items.push(i);
|
|
1899
1940
|
} else
|
|
1900
1941
|
this.items = await this.all();
|
|
1901
1942
|
}
|
|
@@ -1955,24 +1996,24 @@ class oe extends j {
|
|
|
1955
1996
|
this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
|
|
1956
1997
|
}
|
|
1957
1998
|
}
|
|
1958
|
-
class
|
|
1999
|
+
class L extends j {
|
|
1959
2000
|
query() {
|
|
1960
2001
|
const e = super.query(), t = this.guessInverseRelation();
|
|
1961
2002
|
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
1962
2003
|
}
|
|
1963
2004
|
async saveQuietly(e) {
|
|
1964
|
-
if (!
|
|
1965
|
-
throw new
|
|
2005
|
+
if (!E(e))
|
|
2006
|
+
throw new x("HasOneOrMany.saveQuietly()");
|
|
1966
2007
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1967
|
-
throw new
|
|
2008
|
+
throw new B("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1968
2009
|
e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
|
|
1969
2010
|
}
|
|
1970
2011
|
}
|
|
1971
|
-
class
|
|
1972
|
-
constructor(e, t, r,
|
|
1973
|
-
if (!
|
|
1974
|
-
throw new
|
|
1975
|
-
super(e, t, r,
|
|
2012
|
+
class et extends L {
|
|
2013
|
+
constructor(e, t, r, i = null) {
|
|
2014
|
+
if (!E(i) && i !== null)
|
|
2015
|
+
throw new x("HasOne.constructor()", "Model or null");
|
|
2016
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1976
2017
|
}
|
|
1977
2018
|
isSingle() {
|
|
1978
2019
|
return !0;
|
|
@@ -1987,11 +2028,11 @@ class Ae extends H {
|
|
|
1987
2028
|
await this.saveQuietly(e), this.items = e;
|
|
1988
2029
|
}
|
|
1989
2030
|
}
|
|
1990
|
-
class
|
|
1991
|
-
constructor(e, t, r,
|
|
1992
|
-
if (
|
|
1993
|
-
throw new
|
|
1994
|
-
super(e, t, r,
|
|
2031
|
+
class tt extends L {
|
|
2032
|
+
constructor(e, t, r, i = null) {
|
|
2033
|
+
if (i !== null && !(i instanceof C && i.every(E)))
|
|
2034
|
+
throw new x("HasMany.constructor()", "Collection<Model> or null");
|
|
2035
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1995
2036
|
}
|
|
1996
2037
|
isSingle() {
|
|
1997
2038
|
return !1;
|
|
@@ -2012,10 +2053,10 @@ class ve extends H {
|
|
|
2012
2053
|
return this.query().find(e);
|
|
2013
2054
|
}
|
|
2014
2055
|
async saveManyQuietly(e) {
|
|
2015
|
-
if (!Array.isArray(e) || !e.every(
|
|
2016
|
-
throw new
|
|
2056
|
+
if (!Array.isArray(e) || !e.every(E))
|
|
2057
|
+
throw new x("HasMany.saveManyQuietly()", "Model[]");
|
|
2017
2058
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
2018
|
-
throw new
|
|
2059
|
+
throw new B("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
2019
2060
|
await Promise.all(e.map((t) => (t.setAttribute(this.getForeignKey(), this.parent.getKey()), t.save())));
|
|
2020
2061
|
}
|
|
2021
2062
|
async saveMany(e) {
|
|
@@ -2027,7 +2068,7 @@ class ve extends H {
|
|
|
2027
2068
|
await this.saveQuietly(e), this.items === null ? this.items = await this.all() : this.items.push(e);
|
|
2028
2069
|
}
|
|
2029
2070
|
}
|
|
2030
|
-
class
|
|
2071
|
+
class Ie extends L {
|
|
2031
2072
|
query() {
|
|
2032
2073
|
const e = this.getRelated().query();
|
|
2033
2074
|
e.once("success", (r) => {
|
|
@@ -2037,19 +2078,19 @@ class he extends H {
|
|
|
2037
2078
|
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
2079
|
}
|
|
2039
2080
|
async saveQuietly(e) {
|
|
2040
|
-
if (!
|
|
2041
|
-
throw new
|
|
2081
|
+
if (!E(e))
|
|
2082
|
+
throw new x("MorphOneOrMany.saveQuietly()");
|
|
2042
2083
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
2043
|
-
throw new
|
|
2084
|
+
throw new B("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
2044
2085
|
const t = this.guessInverseRelation();
|
|
2045
2086
|
e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
|
|
2046
2087
|
}
|
|
2047
2088
|
}
|
|
2048
|
-
class
|
|
2049
|
-
constructor(e, t, r,
|
|
2050
|
-
if (
|
|
2051
|
-
throw new
|
|
2052
|
-
super(e, t, r,
|
|
2089
|
+
class rt extends Ie {
|
|
2090
|
+
constructor(e, t, r, i = null) {
|
|
2091
|
+
if (i !== null && !(i instanceof C && i.every(E)))
|
|
2092
|
+
throw new x("MorphMany.constructor()", "Collection<Model> or null");
|
|
2093
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2053
2094
|
}
|
|
2054
2095
|
isSingle() {
|
|
2055
2096
|
return !1;
|
|
@@ -2070,10 +2111,10 @@ class Re extends he {
|
|
|
2070
2111
|
return this.query().find(e);
|
|
2071
2112
|
}
|
|
2072
2113
|
async saveManyQuietly(e) {
|
|
2073
|
-
if (!Array.isArray(e) || !e.every(
|
|
2074
|
-
throw new
|
|
2114
|
+
if (!Array.isArray(e) || !e.every(E))
|
|
2115
|
+
throw new x("MorphMany.saveManyQuietly()");
|
|
2075
2116
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
2076
|
-
throw new
|
|
2117
|
+
throw new B("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
2077
2118
|
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
2119
|
}
|
|
2079
2120
|
async save(e) {
|
|
@@ -2085,10 +2126,10 @@ class Re extends he {
|
|
|
2085
2126
|
this.items ? this.items.splice(0, this.items.count(), ...t) : this.items = t;
|
|
2086
2127
|
}
|
|
2087
2128
|
}
|
|
2088
|
-
class
|
|
2089
|
-
constructor(e, t, r,
|
|
2090
|
-
if (super(e, t, r,
|
|
2091
|
-
throw new
|
|
2129
|
+
class st extends Ie {
|
|
2130
|
+
constructor(e, t, r, i = null) {
|
|
2131
|
+
if (super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !E(i))
|
|
2132
|
+
throw new x("MorphOne.constructor()", "Model or null");
|
|
2092
2133
|
}
|
|
2093
2134
|
isSingle() {
|
|
2094
2135
|
return !0;
|
|
@@ -2103,7 +2144,7 @@ class Ne extends he {
|
|
|
2103
2144
|
await this.saveQuietly(e), this.items = e;
|
|
2104
2145
|
}
|
|
2105
2146
|
}
|
|
2106
|
-
class
|
|
2147
|
+
class it extends Be {
|
|
2107
2148
|
getRelated() {
|
|
2108
2149
|
return this.facades.model.make(
|
|
2109
2150
|
this.parent.getAttribute(this.getName() + "_type")
|
|
@@ -2118,8 +2159,8 @@ class Se extends ne {
|
|
|
2118
2159
|
// return super.query();
|
|
2119
2160
|
// }
|
|
2120
2161
|
async associate(e) {
|
|
2121
|
-
if (!
|
|
2122
|
-
throw new
|
|
2162
|
+
if (!E(e))
|
|
2163
|
+
throw new x("MorphTo.associate()");
|
|
2123
2164
|
return e.exists || await e.save(), this.parent.update({
|
|
2124
2165
|
[this.getName() + "_id"]: e.getKey(),
|
|
2125
2166
|
[this.getName() + "_type"]: e.getType()
|
|
@@ -2132,49 +2173,52 @@ class Se extends ne {
|
|
|
2132
2173
|
});
|
|
2133
2174
|
}
|
|
2134
2175
|
}
|
|
2135
|
-
class
|
|
2136
|
-
constructor(e, t, r,
|
|
2137
|
-
super(e, t, r,
|
|
2176
|
+
class nt extends qe {
|
|
2177
|
+
constructor(e, t, r, i = null) {
|
|
2178
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2138
2179
|
}
|
|
2139
2180
|
query() {
|
|
2140
2181
|
const e = super.query(), t = this.guessInverseRelation();
|
|
2141
2182
|
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
2183
|
}
|
|
2143
2184
|
}
|
|
2144
|
-
|
|
2185
|
+
var Me;
|
|
2186
|
+
Me = Symbol.toStringTag;
|
|
2187
|
+
class ot {
|
|
2145
2188
|
constructor(e) {
|
|
2146
|
-
|
|
2189
|
+
m(this, "_models", {});
|
|
2190
|
+
m(this, Me, "ModelFacade");
|
|
2147
2191
|
this._schema = e;
|
|
2148
2192
|
}
|
|
2149
2193
|
boot(e) {
|
|
2150
2194
|
this._schema && (Object.keys(this._schema).forEach((t) => {
|
|
2151
2195
|
const r = this[`model${f.upperFirst(f.camelCase(t))}`];
|
|
2152
2196
|
if (typeof this.model != "function" || typeof r != "function")
|
|
2153
|
-
throw new
|
|
2154
|
-
const
|
|
2155
|
-
|
|
2197
|
+
throw new _("ModelFacade");
|
|
2198
|
+
const i = this.model(
|
|
2199
|
+
ze(e.make(), t),
|
|
2156
2200
|
t
|
|
2157
|
-
),
|
|
2158
|
-
this._models[t] =
|
|
2201
|
+
), s = r(i);
|
|
2202
|
+
this._models[t] = Oe(e.make(), t, s);
|
|
2159
2203
|
}), this.reducer("relationMap", () => ({
|
|
2160
|
-
BelongsTo:
|
|
2161
|
-
BelongsToMany:
|
|
2162
|
-
HasOne:
|
|
2163
|
-
HasMany:
|
|
2164
|
-
MorphMany:
|
|
2165
|
-
MorphOne:
|
|
2166
|
-
MorphTo:
|
|
2167
|
-
MorphToMany:
|
|
2204
|
+
BelongsTo: Be,
|
|
2205
|
+
BelongsToMany: qe,
|
|
2206
|
+
HasOne: et,
|
|
2207
|
+
HasMany: tt,
|
|
2208
|
+
MorphMany: rt,
|
|
2209
|
+
MorphOne: st,
|
|
2210
|
+
MorphTo: it,
|
|
2211
|
+
MorphToMany: nt
|
|
2168
2212
|
}), 0));
|
|
2169
2213
|
}
|
|
2170
2214
|
schema(e) {
|
|
2171
2215
|
if (!this._schema || e && !this._schema[e])
|
|
2172
|
-
throw new
|
|
2216
|
+
throw new G(e || "undefined");
|
|
2173
2217
|
return e ? this._schema[e] : this._schema;
|
|
2174
2218
|
}
|
|
2175
2219
|
make(e) {
|
|
2176
2220
|
if (e && !this._models[e])
|
|
2177
|
-
throw new
|
|
2221
|
+
throw new G(e);
|
|
2178
2222
|
return e ? this._models[e] : this._models;
|
|
2179
2223
|
}
|
|
2180
2224
|
toString() {
|
|
@@ -2182,68 +2226,68 @@ class ue {
|
|
|
2182
2226
|
}
|
|
2183
2227
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2184
2228
|
on(e, t) {
|
|
2185
|
-
throw new
|
|
2229
|
+
throw new b();
|
|
2186
2230
|
}
|
|
2187
2231
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2188
2232
|
once(e, t) {
|
|
2189
|
-
throw new
|
|
2233
|
+
throw new b();
|
|
2190
2234
|
}
|
|
2191
2235
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2192
2236
|
emit(e, t) {
|
|
2193
|
-
throw new
|
|
2237
|
+
throw new b();
|
|
2194
2238
|
}
|
|
2195
2239
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2196
2240
|
reducer(e, t, r) {
|
|
2197
|
-
throw new
|
|
2241
|
+
throw new b();
|
|
2198
2242
|
}
|
|
2199
2243
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2200
2244
|
removeReducer(e) {
|
|
2201
|
-
throw new
|
|
2245
|
+
throw new b();
|
|
2202
2246
|
}
|
|
2203
2247
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2204
2248
|
getReducer(e) {
|
|
2205
|
-
throw new
|
|
2249
|
+
throw new b();
|
|
2206
2250
|
}
|
|
2207
2251
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2208
2252
|
hasReducer(e) {
|
|
2209
|
-
throw new
|
|
2253
|
+
throw new b();
|
|
2210
2254
|
}
|
|
2211
2255
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2212
2256
|
clearReducer(e) {
|
|
2213
|
-
throw new
|
|
2257
|
+
throw new b();
|
|
2214
2258
|
}
|
|
2215
2259
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2216
2260
|
flushReducers() {
|
|
2217
|
-
throw new
|
|
2261
|
+
throw new b();
|
|
2218
2262
|
}
|
|
2219
2263
|
}
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
class
|
|
2264
|
+
const ht = A(Re(ot));
|
|
2265
|
+
var _e, Te;
|
|
2266
|
+
class ut extends (Te = Error, _e = Symbol.toStringTag, Te) {
|
|
2223
2267
|
constructor() {
|
|
2224
2268
|
super("[Luminix] Embed element not found. Make sure to include the `@luminixEmbed()` directive in your Blade template.");
|
|
2269
|
+
m(this, _e, "NoEmbedException");
|
|
2225
2270
|
}
|
|
2226
2271
|
}
|
|
2227
|
-
|
|
2228
|
-
const le = (n, e = "data") => {
|
|
2272
|
+
const Ke = (n, e = "data") => {
|
|
2229
2273
|
if (!document.querySelector("#luminix-embed"))
|
|
2230
|
-
throw new
|
|
2274
|
+
throw new ut();
|
|
2231
2275
|
const t = document.getElementById(`luminix-${e}::` + n);
|
|
2232
2276
|
return t ? t.dataset.json && t.dataset.value ? JSON.parse(t.dataset.value) : t.dataset.value : null;
|
|
2233
|
-
},
|
|
2234
|
-
let
|
|
2277
|
+
}, V = A(S), at = (n) => Je(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;
|
|
2278
|
+
let lt = class {
|
|
2235
2279
|
constructor() {
|
|
2236
|
-
|
|
2280
|
+
m(this, "bags");
|
|
2237
2281
|
const e = {};
|
|
2238
2282
|
document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((r) => {
|
|
2239
|
-
const
|
|
2240
|
-
e[
|
|
2283
|
+
const s = r.id.replace("luminix-error::", "");
|
|
2284
|
+
e[s] = Ke(s, "error");
|
|
2241
2285
|
}), this.bags = {
|
|
2242
|
-
default: new
|
|
2286
|
+
default: new V(e)
|
|
2243
2287
|
};
|
|
2244
2288
|
}
|
|
2245
2289
|
bag(e = "default") {
|
|
2246
|
-
return this.bags[e] || (this.bags[e] = new
|
|
2290
|
+
return this.bags[e] || (this.bags[e] = new V({})), this.bags[e];
|
|
2247
2291
|
}
|
|
2248
2292
|
add(e, t, r = "default") {
|
|
2249
2293
|
this.bag(r).set(e, t);
|
|
@@ -2261,13 +2305,14 @@ let Ke = class {
|
|
|
2261
2305
|
this.bag(e).set(".", {});
|
|
2262
2306
|
}
|
|
2263
2307
|
};
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2308
|
+
var $e, Ae;
|
|
2309
|
+
class ct extends (Ae = Error, $e = Symbol.toStringTag, Ae) {
|
|
2310
|
+
constructor(t) {
|
|
2311
|
+
super(`[Luminix] Route "${t}" not found`);
|
|
2312
|
+
m(this, $e, "RouteNotFoundException");
|
|
2267
2313
|
}
|
|
2268
2314
|
}
|
|
2269
|
-
|
|
2270
|
-
class je {
|
|
2315
|
+
class dt {
|
|
2271
2316
|
constructor(e, t, r = "") {
|
|
2272
2317
|
this.routes = e, this.error = t, this.appUrl = r;
|
|
2273
2318
|
}
|
|
@@ -2277,8 +2322,8 @@ class je {
|
|
|
2277
2322
|
const [t, ...r] = e;
|
|
2278
2323
|
if (typeof t != "string")
|
|
2279
2324
|
return !1;
|
|
2280
|
-
const
|
|
2281
|
-
return !!r.every((
|
|
2325
|
+
const i = ["get", "post", "put", "patch", "delete"];
|
|
2326
|
+
return !!r.every((s) => i.includes(s));
|
|
2282
2327
|
}
|
|
2283
2328
|
extractGenerator(e) {
|
|
2284
2329
|
let t, r = !1;
|
|
@@ -2286,23 +2331,23 @@ class je {
|
|
|
2286
2331
|
}
|
|
2287
2332
|
get(e) {
|
|
2288
2333
|
if (!this.exists(e))
|
|
2289
|
-
throw new
|
|
2334
|
+
throw new ct(e);
|
|
2290
2335
|
return f.get(this.routes, e);
|
|
2291
2336
|
}
|
|
2292
2337
|
url(e) {
|
|
2293
|
-
const [t, r] = this.extractGenerator(e),
|
|
2338
|
+
const [t, r] = this.extractGenerator(e), i = this.get(t)[0].replace(/^\/|\/$/g, ""), s = /{([^}]+)}/g;
|
|
2294
2339
|
if (r === !1) {
|
|
2295
2340
|
if (typeof this.replaceRouteParams != "function")
|
|
2296
|
-
throw new
|
|
2297
|
-
return this.appUrl + this.replaceRouteParams(`/${
|
|
2341
|
+
throw new _("RouteFacade");
|
|
2342
|
+
return this.appUrl + this.replaceRouteParams(`/${i}`);
|
|
2298
2343
|
}
|
|
2299
|
-
const u =
|
|
2344
|
+
const u = i.match(s), a = u ? u.map((w) => w.slice(1, -1)) : [], l = Object.keys(r), d = a.filter((w) => !l.includes(w)), p = l.filter((w) => !a.includes(w));
|
|
2300
2345
|
if (d.length > 0)
|
|
2301
2346
|
throw new TypeError(`Missing values for parameter(s): ${d.join(", ")}`);
|
|
2302
|
-
if (
|
|
2303
|
-
throw new TypeError(`Unexpected parameters: ${
|
|
2304
|
-
const
|
|
2305
|
-
return this.appUrl + `/${
|
|
2347
|
+
if (p.length > 0)
|
|
2348
|
+
throw new TypeError(`Unexpected parameters: ${p.join(", ")}`);
|
|
2349
|
+
const y = a.reduce((w, g) => w.replace(`{${g}}`, `${r[g]}`), i);
|
|
2350
|
+
return this.appUrl + `/${y}`;
|
|
2306
2351
|
}
|
|
2307
2352
|
methods(e) {
|
|
2308
2353
|
const [t] = this.extractGenerator(e);
|
|
@@ -2313,37 +2358,37 @@ class je {
|
|
|
2313
2358
|
}
|
|
2314
2359
|
async call(e, t = {}) {
|
|
2315
2360
|
if (typeof this.axiosOptions != "function" || typeof this.axiosError != "function")
|
|
2316
|
-
throw new
|
|
2317
|
-
const [r,
|
|
2361
|
+
throw new _("RouteFacade");
|
|
2362
|
+
const [r, i] = this.extractGenerator(e), [, ...s] = this.get(r), u = this.url(i ? [r, i] : r), a = this.axiosOptions(t, r), { method: l = s[0], errorBag: d = "route.call", ...p } = a, { data: y, ...w } = p;
|
|
2318
2363
|
this.error.clear(d);
|
|
2319
2364
|
try {
|
|
2320
|
-
return ["get", "delete"].includes(
|
|
2321
|
-
} catch (
|
|
2322
|
-
if (
|
|
2323
|
-
const { errors:
|
|
2324
|
-
this.error.set(Object.entries(
|
|
2325
|
-
} else K.isAxiosError(
|
|
2326
|
-
this.axiosError({ axios:
|
|
2327
|
-
error:
|
|
2365
|
+
return ["get", "delete"].includes(l) ? await K[l](u, p) : await K[l](u, y, w);
|
|
2366
|
+
} catch (g) {
|
|
2367
|
+
if (at(g)) {
|
|
2368
|
+
const { errors: je } = g.response.data;
|
|
2369
|
+
this.error.set(Object.entries(je).reduce((J, [Fe, Pe]) => (J[Fe] = Pe.join(" "), J), {}));
|
|
2370
|
+
} else K.isAxiosError(g) && this.error.set(
|
|
2371
|
+
this.axiosError({ axios: g.message }, {
|
|
2372
|
+
error: g,
|
|
2328
2373
|
name: r,
|
|
2329
|
-
replace:
|
|
2374
|
+
replace: i,
|
|
2330
2375
|
config: t
|
|
2331
2376
|
}),
|
|
2332
2377
|
d
|
|
2333
2378
|
);
|
|
2334
|
-
throw
|
|
2379
|
+
throw g;
|
|
2335
2380
|
}
|
|
2336
2381
|
}
|
|
2337
2382
|
toString() {
|
|
2338
2383
|
return "route";
|
|
2339
2384
|
}
|
|
2340
2385
|
}
|
|
2341
|
-
const
|
|
2342
|
-
class
|
|
2386
|
+
const ft = Re(dt);
|
|
2387
|
+
class pt {
|
|
2343
2388
|
constructor() {
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2389
|
+
m(this, "facades", {});
|
|
2390
|
+
m(this, "booted", !1);
|
|
2391
|
+
m(this, "_plugins", []);
|
|
2347
2392
|
}
|
|
2348
2393
|
make(e = void 0) {
|
|
2349
2394
|
if (!e)
|
|
@@ -2361,38 +2406,42 @@ class Pe {
|
|
|
2361
2406
|
return this._plugins;
|
|
2362
2407
|
}
|
|
2363
2408
|
async boot(e = {}) {
|
|
2364
|
-
var a,
|
|
2409
|
+
var a, l, d, p, y, w;
|
|
2365
2410
|
if (this.booted)
|
|
2366
2411
|
throw new window.Error("[Luminix] App already booted");
|
|
2367
2412
|
this.booted = !0, (a = e.app) != null && a.debug && console.log("[Luminix] Booting started..."), this.emit("init", {
|
|
2368
|
-
register: (
|
|
2369
|
-
this._plugins.push(
|
|
2413
|
+
register: (g) => {
|
|
2414
|
+
this._plugins.push(g), typeof g.register == "function" && g.register(this);
|
|
2370
2415
|
}
|
|
2371
2416
|
});
|
|
2372
|
-
const t = (((
|
|
2373
|
-
if (
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2417
|
+
const t = (((l = e.app) == null ? void 0 : l.url) ?? "") + (((d = e.app) == null ? void 0 : d.bootUrl) ?? "/luminix-api/init");
|
|
2418
|
+
if (document.getElementById("luminix-data::config")) {
|
|
2419
|
+
if (document.getElementById("luminix-data::config")) {
|
|
2420
|
+
const g = Ke("config");
|
|
2421
|
+
g && typeof g == "object" && f.merge(e, g);
|
|
2422
|
+
}
|
|
2423
|
+
} else try {
|
|
2424
|
+
const { data: g } = await K.get(t);
|
|
2425
|
+
g && typeof g == "object" && f.merge(e, g);
|
|
2426
|
+
} catch (g) {
|
|
2427
|
+
(p = e.app) != null && p.debug && console.error(g);
|
|
2428
|
+
}
|
|
2429
|
+
this.bind("log", new He(!!((y = e.app) != null && y.debug)));
|
|
2381
2430
|
const { log: r } = this.facades, {
|
|
2382
|
-
manifest: { routes:
|
|
2431
|
+
manifest: { routes: i = {}, models: s = {} } = {},
|
|
2383
2432
|
...u
|
|
2384
2433
|
} = e;
|
|
2385
|
-
this.bind("config", new
|
|
2386
|
-
for (const
|
|
2387
|
-
typeof
|
|
2388
|
-
for (const
|
|
2389
|
-
typeof
|
|
2434
|
+
this.bind("config", new S(u)), this.facades.config.has("auth.user") || this.facades.config.set("auth.user", null), this.facades.config.lock("auth.user"), this.bind("error", new lt()), this.bind("route", new ft(i, this.facades.error, ((w = e.app) == null ? void 0 : w.url) ?? "")), this.bind("model", new ht(s)), this.bind("auth", new De(this)), this.emit("booting");
|
|
2435
|
+
for (const g of Object.values(this.facades))
|
|
2436
|
+
typeof g == "object" && g !== null && "boot" in g && typeof g.boot == "function" && g.boot(this);
|
|
2437
|
+
for (const g of this._plugins)
|
|
2438
|
+
typeof g.boot == "function" && g.boot(this.facades);
|
|
2390
2439
|
return r.info("[Luminix] App boot completed", {
|
|
2391
2440
|
config: this.facades.config.all(),
|
|
2392
2441
|
plugins: this._plugins,
|
|
2393
2442
|
manifest: {
|
|
2394
|
-
routes:
|
|
2395
|
-
models:
|
|
2443
|
+
routes: i,
|
|
2444
|
+
models: s
|
|
2396
2445
|
}
|
|
2397
2446
|
}), this.emit("booted"), this.facades;
|
|
2398
2447
|
}
|
|
@@ -2409,49 +2458,49 @@ class Pe {
|
|
|
2409
2458
|
throw new window.Error("Method not implemented.");
|
|
2410
2459
|
}
|
|
2411
2460
|
}
|
|
2412
|
-
const
|
|
2413
|
-
let
|
|
2414
|
-
function
|
|
2415
|
-
if (
|
|
2461
|
+
const mt = A(pt);
|
|
2462
|
+
let M;
|
|
2463
|
+
function N(n = void 0) {
|
|
2464
|
+
if (M || (M = new mt()), typeof n != "string")
|
|
2416
2465
|
return {
|
|
2417
|
-
boot:
|
|
2418
|
-
make:
|
|
2419
|
-
plugins:
|
|
2420
|
-
on:
|
|
2466
|
+
boot: M.boot.bind(M),
|
|
2467
|
+
make: M.make.bind(M),
|
|
2468
|
+
plugins: M.plugins.bind(M),
|
|
2469
|
+
on: M.once.bind(M)
|
|
2421
2470
|
};
|
|
2422
|
-
if (!
|
|
2423
|
-
throw new
|
|
2424
|
-
return
|
|
2471
|
+
if (!M.has(n))
|
|
2472
|
+
throw new Ue(n);
|
|
2473
|
+
return M.make(n);
|
|
2425
2474
|
}
|
|
2426
|
-
function
|
|
2427
|
-
return
|
|
2475
|
+
function Mt() {
|
|
2476
|
+
return N("auth");
|
|
2428
2477
|
}
|
|
2429
|
-
function
|
|
2430
|
-
return
|
|
2478
|
+
function _t(n) {
|
|
2479
|
+
return c(n);
|
|
2431
2480
|
}
|
|
2432
|
-
function
|
|
2433
|
-
const t =
|
|
2481
|
+
function Tt(n, e) {
|
|
2482
|
+
const t = N("config");
|
|
2434
2483
|
return typeof n > "u" ? t : t.get(n, e);
|
|
2435
2484
|
}
|
|
2436
|
-
function
|
|
2437
|
-
return n ?
|
|
2485
|
+
function $t(n, e = "default") {
|
|
2486
|
+
return n ? N().make("error").get(n, e) : N().make("error");
|
|
2438
2487
|
}
|
|
2439
|
-
function
|
|
2440
|
-
const e =
|
|
2488
|
+
function At(...n) {
|
|
2489
|
+
const e = N("log");
|
|
2441
2490
|
return n.length ? e.debug(...n) : e;
|
|
2442
2491
|
}
|
|
2443
|
-
function
|
|
2444
|
-
const e =
|
|
2492
|
+
function St(n) {
|
|
2493
|
+
const e = N("model");
|
|
2445
2494
|
return n ? e.make(n) : e;
|
|
2446
2495
|
}
|
|
2447
|
-
function
|
|
2448
|
-
const t =
|
|
2496
|
+
function Nt(n, e = !1) {
|
|
2497
|
+
const t = N("route");
|
|
2449
2498
|
return n ? e ? t.url([n, e]) : t.url(n) : t;
|
|
2450
2499
|
}
|
|
2451
|
-
class
|
|
2500
|
+
class vt {
|
|
2452
2501
|
constructor() {
|
|
2453
|
-
|
|
2454
|
-
|
|
2502
|
+
m(this, "name");
|
|
2503
|
+
m(this, "version");
|
|
2455
2504
|
}
|
|
2456
2505
|
register(e) {
|
|
2457
2506
|
}
|
|
@@ -2460,18 +2509,18 @@ class Oe {
|
|
|
2460
2509
|
}
|
|
2461
2510
|
export {
|
|
2462
2511
|
A as HasEvents,
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2512
|
+
vt as Plugin,
|
|
2513
|
+
S as PropertyBag,
|
|
2514
|
+
Re as Reducible,
|
|
2515
|
+
N as app,
|
|
2516
|
+
Mt as auth,
|
|
2517
|
+
_t as collect,
|
|
2518
|
+
Tt as config,
|
|
2519
|
+
$t as error,
|
|
2520
|
+
$ as isCollection,
|
|
2521
|
+
E as isModel,
|
|
2522
|
+
at as isValidationError,
|
|
2523
|
+
At as log,
|
|
2524
|
+
St as model,
|
|
2525
|
+
Nt as route
|
|
2477
2526
|
};
|