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