@luminix/core 0.0.1-beta.2 → 0.0.1-beta.21
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 -3
- package/dist/contracts/Collection.d.ts +4 -6
- package/dist/contracts/ModelCollection.d.ts +1 -2
- package/dist/contracts/Plugin.d.ts +0 -1
- package/dist/contracts/PropertyBag.d.ts +0 -1
- package/dist/contracts/Relation/BelongsTo.d.ts +0 -1
- package/dist/contracts/Relation/BelongsToMany.d.ts +0 -1
- package/dist/contracts/Relation/HasMany.d.ts +0 -1
- package/dist/contracts/Relation/HasOne.d.ts +0 -1
- package/dist/contracts/Relation/HasOneOrMany.d.ts +0 -1
- package/dist/contracts/Relation/MorphMany.d.ts +0 -1
- package/dist/contracts/Relation/MorphOne.d.ts +0 -1
- package/dist/contracts/Relation/MorphOneOrMany.d.ts +0 -1
- package/dist/contracts/Relation/MorphTo.d.ts +0 -1
- package/dist/contracts/Relation/MorphToMany.d.ts +0 -1
- package/dist/contracts/Relation.d.ts +0 -1
- package/dist/core.js +906 -825
- package/dist/core.umd.cjs +4 -0
- 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 +9 -3
- package/dist/facades/Auth.d.ts +0 -1
- package/dist/facades/Error.d.ts +0 -1
- package/dist/facades/Log.d.ts +0 -1
- package/dist/facades/Model.d.ts +2 -4
- package/dist/facades/Route.d.ts +0 -1
- package/dist/helpers/app.d.ts +0 -1
- package/dist/helpers/auth.d.ts +0 -1
- package/dist/helpers/config.d.ts +0 -1
- package/dist/helpers/error.d.ts +0 -1
- package/dist/helpers/log.d.ts +0 -1
- package/dist/helpers/model.d.ts +0 -1
- package/dist/helpers/route.d.ts +0 -1
- package/dist/index.d.ts +2 -2
- package/dist/mixins/BaseModel.d.ts +2 -3
- package/dist/mixins/HasEvents.d.ts +1 -3
- package/dist/mixins/Reducible.d.ts +0 -1
- package/dist/support/collection.d.ts +0 -1
- package/dist/support/model.d.ts +0 -1
- package/dist/types/App.d.ts +10 -2
- package/dist/types/Auth.d.ts +0 -1
- package/dist/types/Builder.d.ts +4 -1
- package/dist/types/Collection.d.ts +3 -4
- package/dist/types/Config.d.ts +3 -1
- package/dist/types/Error.d.ts +0 -1
- package/dist/types/Event.d.ts +0 -1
- package/dist/types/Model.d.ts +32 -7
- package/dist/types/PropertyBag.d.ts +0 -1
- package/dist/types/Reducer.d.ts +0 -1
- package/dist/types/Relation.d.ts +0 -1
- package/dist/types/Route.d.ts +0 -1
- package/package.json +5 -3
- package/vite.config.js +5 -2
- 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 D = (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), L = (n, e, t) => e.has(n) || D("Cannot " + t);
|
|
7
|
+
var h = (n, e, t) => (L(n, e, "read from private field"), t ? t.call(n) : e.get(n)), k = (n, e, t) => e.has(n) ? D("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), J = (n, e, t, r) => (L(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), H = (n, e, t) => (L(n, e, "access private method"), t);
|
|
8
|
+
import d from "lodash";
|
|
9
|
+
import { produce as q, isDraftable as Pe } from "immer";
|
|
10
|
+
import j, { isAxiosError as Le } from "axios";
|
|
11
|
+
var Y, Z;
|
|
12
|
+
class ke extends (Z = Error, Y = Symbol.toStringTag, Z) {
|
|
13
|
+
constructor(t) {
|
|
14
|
+
super(`[Luminix] Facade "${t}" not found`);
|
|
15
|
+
m(this, Y, "FacadeNotFoundException");
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
class be {
|
|
18
|
+
class Qe {
|
|
18
19
|
constructor(e) {
|
|
19
|
-
|
|
20
|
+
m(this, "_user");
|
|
20
21
|
this.app = e;
|
|
21
22
|
}
|
|
22
23
|
attempt(e, t = !1, r) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
if (typeof
|
|
27
|
-
const
|
|
28
|
-
|
|
24
|
+
const i = document.createElement("form");
|
|
25
|
+
i.method = "post", i.action = this.app.make("route").url("login"), i.style.display = "none";
|
|
26
|
+
const s = this.app.make("config").get("auth.csrf");
|
|
27
|
+
if (typeof s == "string") {
|
|
28
|
+
const a = document.createElement("input");
|
|
29
|
+
a.type = "hidden", a.name = "_token", a.value = s, i.appendChild(a);
|
|
29
30
|
}
|
|
30
31
|
const u = document.createElement("input");
|
|
31
|
-
u.type = "email", u.name = "email", u.value = e.email,
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
const
|
|
35
|
-
|
|
32
|
+
u.type = "email", u.name = "email", u.value = e.email, i.appendChild(u);
|
|
33
|
+
const l = document.createElement("input");
|
|
34
|
+
if (l.type = "password", l.name = "password", l.value = e.password, i.appendChild(l), t) {
|
|
35
|
+
const a = document.createElement("input");
|
|
36
|
+
a.type = "checkbox", a.name = "remember", a.value = "1", a.checked = !0, i.appendChild(a);
|
|
36
37
|
}
|
|
37
|
-
r &&
|
|
38
|
+
r && i.addEventListener("submit", r), document.body.appendChild(i), i.submit();
|
|
38
39
|
}
|
|
39
40
|
check() {
|
|
40
41
|
return !!this.app.make("config").get("auth.user");
|
|
@@ -44,17 +45,17 @@ class be {
|
|
|
44
45
|
t.method = "post", t.action = this.app.make("route").url("logout"), t.style.display = "none";
|
|
45
46
|
const r = this.app.make("config").get("auth.csrf");
|
|
46
47
|
if (typeof r == "string") {
|
|
47
|
-
const
|
|
48
|
-
|
|
48
|
+
const i = document.createElement("input");
|
|
49
|
+
i.type = "hidden", i.name = "_token", i.value = r, t.appendChild(i);
|
|
49
50
|
}
|
|
50
51
|
document.body.appendChild(t), e && t.addEventListener("submit", e), t.submit();
|
|
51
52
|
}
|
|
52
53
|
user() {
|
|
53
54
|
if (!this._user) {
|
|
54
|
-
const { model: e, config: t } = this.app.make(), r = e.make("user"),
|
|
55
|
-
if (!
|
|
55
|
+
const { model: e, config: t } = this.app.make(), r = e.make("user"), i = t.get("auth.user");
|
|
56
|
+
if (!i)
|
|
56
57
|
return null;
|
|
57
|
-
this._user = new r(
|
|
58
|
+
this._user = new r(i);
|
|
58
59
|
}
|
|
59
60
|
return this._user;
|
|
60
61
|
}
|
|
@@ -63,7 +64,7 @@ class be {
|
|
|
63
64
|
return ((e = this.user()) == null ? void 0 : e.getKey()) || null;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
class
|
|
67
|
+
class Ce {
|
|
67
68
|
constructor(e) {
|
|
68
69
|
this._debug = e;
|
|
69
70
|
}
|
|
@@ -94,31 +95,31 @@ class Ee {
|
|
|
94
95
|
}
|
|
95
96
|
class v {
|
|
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 = q(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 = q(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 = q(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 = q(this.bag, (t) => {
|
|
162
|
+
d.unset(t, e);
|
|
162
163
|
}), this.emit("change", {
|
|
163
164
|
path: e,
|
|
164
165
|
value: null,
|
|
@@ -177,7 +178,7 @@ class v {
|
|
|
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) {
|
|
@@ -191,135 +192,136 @@ class v {
|
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
194
|
function A(n) {
|
|
194
|
-
var e, t, r,
|
|
195
|
+
var e, t, r, Ae, 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
|
+
k(this, r);
|
|
200
|
+
m(this, "emitter");
|
|
201
|
+
m(this, e, n.name);
|
|
202
|
+
this.emitter = H(this, r, Ae).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(), Ae = 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 W(...n) {
|
|
248
|
+
return n.reduce((e, t) => e.flatMap((r) => t.map((i) => [r, i].flat())));
|
|
248
249
|
}
|
|
249
|
-
function
|
|
250
|
+
function S(n) {
|
|
250
251
|
return !(typeof n != "object" || n === null || !Reflect.has(n, "constructor") || Reflect.get(n.constructor, "name") !== "Collection");
|
|
251
252
|
}
|
|
252
|
-
|
|
253
|
+
var z, O;
|
|
254
|
+
class b extends (O = Error, z = Symbol.toStringTag, O) {
|
|
253
255
|
constructor() {
|
|
254
256
|
super("[Luminix] Method not implemented.");
|
|
257
|
+
m(this, z, "MethodNotImplementedException");
|
|
255
258
|
}
|
|
256
259
|
}
|
|
257
|
-
|
|
258
|
-
function l(n = [], e = L) {
|
|
260
|
+
function c(n = [], e = Q) {
|
|
259
261
|
if (!Array.isArray(n))
|
|
260
262
|
throw new TypeError("collect() expects an array");
|
|
261
263
|
return new (A(e))([...n]);
|
|
262
264
|
}
|
|
263
|
-
const
|
|
265
|
+
const T = (n) => {
|
|
264
266
|
n.emit("change", {
|
|
265
267
|
items: n.all()
|
|
266
268
|
});
|
|
267
|
-
},
|
|
268
|
-
var
|
|
269
|
-
class
|
|
269
|
+
}, K = (n, e) => Array.isArray(n) ? n[e] ?? null : n.get(e);
|
|
270
|
+
var ee, te, o;
|
|
271
|
+
class Q {
|
|
270
272
|
constructor(e = []) {
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
// [Symbol.toStringTag] = 'Collection';
|
|
274
|
+
k(this, o);
|
|
275
|
+
m(this, ee, "Collection");
|
|
276
|
+
J(this, o, e);
|
|
275
277
|
}
|
|
276
278
|
get items() {
|
|
277
|
-
return [...
|
|
279
|
+
return [...h(this, o)];
|
|
278
280
|
}
|
|
279
|
-
[(
|
|
280
|
-
return
|
|
281
|
+
[(te = Symbol.iterator, ee = Symbol.toStringTag, te)]() {
|
|
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] = K(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(W(
|
|
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) && !S(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), T(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 W(...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) && !S(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([K(i, s - 1), K(i, s)]).avg() : K(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 (!S(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
|
+
S(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 T(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 T(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 T(this), t;
|
|
634
636
|
}
|
|
635
637
|
push(...e) {
|
|
636
|
-
const t =
|
|
637
|
-
return
|
|
638
|
+
const t = h(this, o).push(...e);
|
|
639
|
+
return T(this), t;
|
|
638
640
|
}
|
|
639
641
|
put(e, t) {
|
|
640
|
-
return
|
|
642
|
+
return h(this, o).splice(e, 1, t), 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 T(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,81 @@ 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 T(this), c(s);
|
|
752
754
|
}
|
|
753
755
|
split(e) {
|
|
754
756
|
const t = [];
|
|
755
757
|
for (let r = 0; r < e; r++) {
|
|
756
|
-
const
|
|
758
|
+
const i = 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 T(this), this;
|
|
806
808
|
}
|
|
807
809
|
unique(e) {
|
|
808
|
-
return
|
|
810
|
+
return c(
|
|
811
|
+
typeof e == "string" ? [...new Set(h(this, o).map((t) => t[e]))].map((t) => h(this, o).find((r) => r[e] == t)) : [...new Set(h(this, o))]
|
|
812
|
+
);
|
|
809
813
|
}
|
|
810
814
|
uniqueStrict(e) {
|
|
811
|
-
return
|
|
815
|
+
return c(
|
|
816
|
+
typeof e == "string" ? [...new Set(h(this, o).map((t) => t[e]))].map((t) => h(this, o).find((r) => r[e] === t)) : [...new Set(h(this, o))]
|
|
817
|
+
);
|
|
812
818
|
}
|
|
813
819
|
unless(e, t, r) {
|
|
814
820
|
return e ? typeof r == "function" && r(this) : t(this), this;
|
|
@@ -820,7 +826,7 @@ class L {
|
|
|
820
826
|
return this.whenEmpty(e, t);
|
|
821
827
|
}
|
|
822
828
|
value(e) {
|
|
823
|
-
return
|
|
829
|
+
return h(this, o).length === 0 ? null : h(this, o)[0][e];
|
|
824
830
|
}
|
|
825
831
|
when(e, t, r) {
|
|
826
832
|
return e ? t(this) : typeof r == "function" && r(this), this;
|
|
@@ -833,112 +839,117 @@ class L {
|
|
|
833
839
|
}
|
|
834
840
|
where(e, t, r) {
|
|
835
841
|
if (typeof r > "u")
|
|
836
|
-
return
|
|
842
|
+
return c(h(this, o).filter((s) => s[e] == t));
|
|
837
843
|
if (typeof t != "string")
|
|
838
844
|
throw new TypeError("The operator must be a string");
|
|
839
845
|
if (r === null)
|
|
840
|
-
return
|
|
841
|
-
const
|
|
842
|
-
"=": (
|
|
843
|
-
"!=": (
|
|
844
|
-
">": (
|
|
845
|
-
"<": (
|
|
846
|
-
">=": (
|
|
847
|
-
"<=": (
|
|
846
|
+
return c(h(this, o).filter((s) => s[e] === null));
|
|
847
|
+
const i = {
|
|
848
|
+
"=": (s) => s[e] == r,
|
|
849
|
+
"!=": (s) => s[e] != r,
|
|
850
|
+
">": (s) => s[e] > r,
|
|
851
|
+
"<": (s) => s[e] < r,
|
|
852
|
+
">=": (s) => s[e] >= r,
|
|
853
|
+
"<=": (s) => s[e] <= r
|
|
848
854
|
};
|
|
849
|
-
if (!(t in
|
|
855
|
+
if (!(t in i))
|
|
850
856
|
throw new Error("Unsupported operator");
|
|
851
|
-
return
|
|
857
|
+
return c(h(this, o).filter((s, u) => i[t](s, u, this)));
|
|
852
858
|
}
|
|
853
859
|
whereStrict(e, t, r) {
|
|
854
860
|
if (typeof r > "u")
|
|
855
|
-
return
|
|
861
|
+
return c(h(this, o).filter((s) => s[e] === t));
|
|
856
862
|
if (typeof t != "string")
|
|
857
863
|
throw new TypeError("The operator must be a string");
|
|
858
864
|
if (r === null)
|
|
859
|
-
return
|
|
860
|
-
const
|
|
861
|
-
"=": (
|
|
862
|
-
"!=": (
|
|
863
|
-
">": (
|
|
864
|
-
"<": (
|
|
865
|
-
">=": (
|
|
866
|
-
"<=": (
|
|
865
|
+
return c(h(this, o).filter((s) => s[e] === null));
|
|
866
|
+
const i = {
|
|
867
|
+
"=": (s) => s[e] === r,
|
|
868
|
+
"!=": (s) => s[e] !== r,
|
|
869
|
+
">": (s) => s[e] > r,
|
|
870
|
+
"<": (s) => s[e] < r,
|
|
871
|
+
">=": (s) => s[e] >= r,
|
|
872
|
+
"<=": (s) => s[e] <= r
|
|
867
873
|
};
|
|
868
|
-
if (!(t in
|
|
874
|
+
if (!(t in i))
|
|
869
875
|
throw new Error("Unsupported operator");
|
|
870
|
-
return
|
|
876
|
+
return c(h(this, o).filter((s, u) => i[t](s, u, this)));
|
|
871
877
|
}
|
|
872
878
|
whereBetween(e, [t, r]) {
|
|
873
|
-
return
|
|
879
|
+
return c(h(this, o).filter((i) => i[e] >= t && i[e] <= r));
|
|
874
880
|
}
|
|
875
881
|
whereIn(e, t) {
|
|
876
|
-
return
|
|
882
|
+
return c(h(this, o).filter((r) => t.includes(r[e])));
|
|
877
883
|
}
|
|
878
884
|
whereInstanceOf(e) {
|
|
879
|
-
return
|
|
885
|
+
return c(h(this, o).filter((t) => t instanceof e));
|
|
880
886
|
}
|
|
881
887
|
whereNotBetween(e, [t, r]) {
|
|
882
|
-
return
|
|
888
|
+
return c(h(this, o).filter((i) => i[e] < t || i[e] > r));
|
|
883
889
|
}
|
|
884
890
|
whereNotIn(e, t) {
|
|
885
|
-
return
|
|
891
|
+
return c(h(this, o).filter((r) => !t.includes(r[e])));
|
|
886
892
|
}
|
|
887
893
|
whereNotNull(e) {
|
|
888
|
-
return
|
|
894
|
+
return c(h(this, o).filter((t) => t[e] !== null));
|
|
889
895
|
}
|
|
890
896
|
whereNull(e) {
|
|
891
|
-
return
|
|
897
|
+
return c(h(this, o).filter((t) => t[e] === null));
|
|
892
898
|
}
|
|
893
899
|
zip(e) {
|
|
894
|
-
return Array.isArray(e) ?
|
|
895
|
-
|
|
896
|
-
) :
|
|
897
|
-
|
|
900
|
+
return Array.isArray(e) ? c(
|
|
901
|
+
h(this, o).map((t, r) => [t, e[r] ?? null])
|
|
902
|
+
) : c(
|
|
903
|
+
h(this, o).map((t, r) => [t, e.get(r)])
|
|
898
904
|
);
|
|
899
905
|
}
|
|
900
906
|
// HasEvents methods
|
|
901
907
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
902
908
|
on(e, t) {
|
|
903
|
-
throw new
|
|
909
|
+
throw new b();
|
|
904
910
|
}
|
|
905
911
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
906
912
|
once(e, t) {
|
|
907
|
-
throw new
|
|
913
|
+
throw new b();
|
|
908
914
|
}
|
|
909
915
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
910
916
|
emit(e, t) {
|
|
911
|
-
throw new
|
|
917
|
+
throw new b();
|
|
912
918
|
}
|
|
913
919
|
}
|
|
914
|
-
|
|
915
|
-
const
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
920
|
+
o = new WeakMap();
|
|
921
|
+
const C = A(Q);
|
|
922
|
+
var re, se;
|
|
923
|
+
class G extends (se = Q, re = Symbol.toStringTag, se) {
|
|
924
|
+
constructor() {
|
|
925
|
+
super(...arguments);
|
|
926
|
+
m(this, re, "Collection");
|
|
927
|
+
}
|
|
928
|
+
intersect(t) {
|
|
929
|
+
return this.filter((r) => t.some((i) => i.getKey() === r.getKey()));
|
|
919
930
|
}
|
|
920
931
|
}
|
|
921
|
-
|
|
922
|
-
const S = (...n) => {
|
|
932
|
+
const B = (...n) => {
|
|
923
933
|
const e = new URLSearchParams();
|
|
924
934
|
return n.forEach((t) => {
|
|
925
935
|
const [, ...r] = t.split("?");
|
|
926
|
-
new URLSearchParams(r.join("")).forEach((
|
|
927
|
-
e.set(u,
|
|
936
|
+
new URLSearchParams(r.join("")).forEach((s, u) => {
|
|
937
|
+
e.set(u, s);
|
|
928
938
|
});
|
|
929
939
|
}), e;
|
|
930
940
|
};
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
941
|
+
var ie, ne;
|
|
942
|
+
class Ue extends (ne = Error, ie = Symbol.toStringTag, ne) {
|
|
943
|
+
constructor(t) {
|
|
944
|
+
super(`[Luminix] Model "${t}" does not have a primary key`);
|
|
945
|
+
m(this, ie, "ModelWithoutPrimaryKeyException");
|
|
934
946
|
}
|
|
935
947
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
class _e {
|
|
948
|
+
const De = A(v);
|
|
949
|
+
class Je {
|
|
939
950
|
constructor(e, t, r = {}) {
|
|
940
|
-
|
|
941
|
-
this.facades = e, this.abstract = t, this.query = r, this.bag = new
|
|
951
|
+
m(this, "bag");
|
|
952
|
+
this.facades = e, this.abstract = t, this.query = r, this.bag = new De(r), this.bag.on("change", () => {
|
|
942
953
|
this.emit("change", {
|
|
943
954
|
data: this.bag
|
|
944
955
|
});
|
|
@@ -946,30 +957,30 @@ class _e {
|
|
|
946
957
|
}
|
|
947
958
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
948
959
|
on(e, t) {
|
|
949
|
-
throw new
|
|
960
|
+
throw new b();
|
|
950
961
|
}
|
|
951
962
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
952
963
|
once(e, t) {
|
|
953
|
-
throw new
|
|
964
|
+
throw new b();
|
|
954
965
|
}
|
|
955
966
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
956
967
|
emit(e, t) {
|
|
957
|
-
throw new
|
|
968
|
+
throw new b();
|
|
958
969
|
}
|
|
959
970
|
lock(e) {
|
|
960
971
|
this.bag.lock(e);
|
|
961
972
|
}
|
|
962
973
|
whereBetween(e, t) {
|
|
963
|
-
return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${
|
|
974
|
+
return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${d.camelCase(e)}Between`, t), this;
|
|
964
975
|
}
|
|
965
976
|
whereNotBetween(e, t) {
|
|
966
|
-
return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${
|
|
977
|
+
return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${d.camelCase(e)}NotBetween`, t), this;
|
|
967
978
|
}
|
|
968
979
|
whereNull(e) {
|
|
969
|
-
return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${
|
|
980
|
+
return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${d.camelCase(e)}Null`, !0), this;
|
|
970
981
|
}
|
|
971
982
|
whereNotNull(e) {
|
|
972
|
-
return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${
|
|
983
|
+
return this.bag.has("where") || this.bag.set("where", {}), this.bag.set(`where.${d.camelCase(e)}NotNull`, !0), this;
|
|
973
984
|
}
|
|
974
985
|
limit(e) {
|
|
975
986
|
return this.bag.set("per_page", e), this;
|
|
@@ -978,18 +989,33 @@ class _e {
|
|
|
978
989
|
if (this.bag.has("where") || this.bag.set("where", {}), typeof e == "function")
|
|
979
990
|
return e(this) || this;
|
|
980
991
|
if (typeof r > "u")
|
|
981
|
-
return this.bag.set(`where.${
|
|
992
|
+
return this.bag.set(`where.${d.camelCase(e)}`, t), this;
|
|
982
993
|
if (typeof t != "string")
|
|
983
994
|
throw new Error(`Invalid operator ${t} provided for where clause.`);
|
|
984
|
-
const
|
|
995
|
+
const s = {
|
|
985
996
|
"=": "",
|
|
986
997
|
"!=": "NotEquals",
|
|
987
998
|
">": "GreaterThan",
|
|
988
999
|
">=": "GreaterThanOrEquals",
|
|
989
1000
|
"<": "LessThan",
|
|
990
1001
|
"<=": "LessThanOrEquals"
|
|
991
|
-
}[t] ||
|
|
992
|
-
return this.bag.set(`where.${
|
|
1002
|
+
}[t] || d.upperFirst(d.camelCase(t));
|
|
1003
|
+
return this.bag.set(`where.${d.camelCase(e)}${s}`, r), this;
|
|
1004
|
+
}
|
|
1005
|
+
with(e) {
|
|
1006
|
+
const t = this.bag.get("with", []);
|
|
1007
|
+
return (Array.isArray(e) ? e : [e]).forEach((i) => {
|
|
1008
|
+
t.includes(i) || t.push(i);
|
|
1009
|
+
}), this.bag.set("with", t), this;
|
|
1010
|
+
}
|
|
1011
|
+
withOnly(e) {
|
|
1012
|
+
return this.bag.set("with", Array.isArray(e) ? e : [e]), this;
|
|
1013
|
+
}
|
|
1014
|
+
without(e) {
|
|
1015
|
+
const t = this.bag.get("with", []);
|
|
1016
|
+
return (Array.isArray(e) ? e : [e]).forEach((i) => {
|
|
1017
|
+
t.includes(i) && t.splice(t.indexOf(i), 1);
|
|
1018
|
+
}), this.bag.set("with", t), this;
|
|
993
1019
|
}
|
|
994
1020
|
orderBy(e, t = "asc") {
|
|
995
1021
|
return this.bag.set("order_by", `${e}:${t}`), this;
|
|
@@ -1003,6 +1029,11 @@ class _e {
|
|
|
1003
1029
|
unset(e) {
|
|
1004
1030
|
return this.bag.delete(e), this;
|
|
1005
1031
|
}
|
|
1032
|
+
include(e) {
|
|
1033
|
+
for (const [t, r] of e.entries())
|
|
1034
|
+
this.bag.set(t, r);
|
|
1035
|
+
return this;
|
|
1036
|
+
}
|
|
1006
1037
|
async exec(e = 1, t) {
|
|
1007
1038
|
try {
|
|
1008
1039
|
this.bag.set("page", e), this.emit("submit", {
|
|
@@ -1011,36 +1042,36 @@ class _e {
|
|
|
1011
1042
|
const { data: r } = await this.facades.route.call(`luminix.${this.abstract}.index`, {
|
|
1012
1043
|
params: this.bag.all(),
|
|
1013
1044
|
errorBag: `${this.abstract}.fetch`
|
|
1014
|
-
}),
|
|
1015
|
-
const
|
|
1016
|
-
return
|
|
1045
|
+
}), i = this.facades.model.make(this.abstract), s = c(r.data.map((u) => {
|
|
1046
|
+
const l = new i(u);
|
|
1047
|
+
return l.exists = !0, this.facades.model.emit("fetch", {
|
|
1017
1048
|
class: this.abstract,
|
|
1018
|
-
model:
|
|
1019
|
-
}),
|
|
1020
|
-
}),
|
|
1049
|
+
model: l
|
|
1050
|
+
}), l;
|
|
1051
|
+
}), G);
|
|
1021
1052
|
if (t) {
|
|
1022
1053
|
const [u] = t.split("?");
|
|
1023
1054
|
return {
|
|
1024
1055
|
...r,
|
|
1025
|
-
data:
|
|
1056
|
+
data: s,
|
|
1026
1057
|
links: {
|
|
1027
|
-
first: `${u}?${
|
|
1028
|
-
last: `${u}?${
|
|
1029
|
-
next: r.links.next && `${u}?${
|
|
1030
|
-
prev: r.links.prev && `${u}?${
|
|
1058
|
+
first: `${u}?${B(t, r.links.first).toString()}`,
|
|
1059
|
+
last: `${u}?${B(t, r.links.last).toString()}`,
|
|
1060
|
+
next: r.links.next && `${u}?${B(t, r.links.next).toString()}`,
|
|
1061
|
+
prev: r.links.prev && `${u}?${B(t, r.links.prev).toString()}`
|
|
1031
1062
|
},
|
|
1032
1063
|
meta: {
|
|
1033
1064
|
...r.meta,
|
|
1034
|
-
links: r.meta.links.map((
|
|
1035
|
-
...
|
|
1036
|
-
url:
|
|
1065
|
+
links: r.meta.links.map((l) => ({
|
|
1066
|
+
...l,
|
|
1067
|
+
url: l.url && `${u}?${B(t, l.url).toString()}`
|
|
1037
1068
|
}))
|
|
1038
1069
|
}
|
|
1039
1070
|
};
|
|
1040
1071
|
}
|
|
1041
1072
|
return {
|
|
1042
1073
|
...r,
|
|
1043
|
-
data:
|
|
1074
|
+
data: s
|
|
1044
1075
|
};
|
|
1045
1076
|
} catch (r) {
|
|
1046
1077
|
throw this.emit("error", {
|
|
@@ -1065,7 +1096,7 @@ class _e {
|
|
|
1065
1096
|
async find(e) {
|
|
1066
1097
|
const t = this.facades.model.schema(this.abstract).primaryKey;
|
|
1067
1098
|
if (!t)
|
|
1068
|
-
throw new
|
|
1099
|
+
throw new Ue(this.abstract);
|
|
1069
1100
|
const r = await this.where(t, e).limit(1).exec(1);
|
|
1070
1101
|
return this.emit("success", {
|
|
1071
1102
|
response: r,
|
|
@@ -1076,11 +1107,11 @@ class _e {
|
|
|
1076
1107
|
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
1108
|
if (r === 1)
|
|
1078
1109
|
return t.data;
|
|
1079
|
-
const
|
|
1080
|
-
|
|
1081
|
-
), u =
|
|
1082
|
-
|
|
1083
|
-
|
|
1110
|
+
const i = Array.from({ length: r - 1 }, (l, a) => a + 2), s = await Promise.all(
|
|
1111
|
+
i.map((l) => this.limit(e).exec(l))
|
|
1112
|
+
), u = c(
|
|
1113
|
+
s.reduce((l, a) => (l.push(...a.data), l), t.data).all(),
|
|
1114
|
+
G
|
|
1084
1115
|
);
|
|
1085
1116
|
return this.emit("success", {
|
|
1086
1117
|
response: {
|
|
@@ -1091,39 +1122,43 @@ class _e {
|
|
|
1091
1122
|
}), u;
|
|
1092
1123
|
}
|
|
1093
1124
|
}
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1125
|
+
const He = A(Je);
|
|
1126
|
+
var oe, he;
|
|
1127
|
+
class $ extends (he = Error, oe = Symbol.toStringTag, he) {
|
|
1128
|
+
constructor(t) {
|
|
1129
|
+
super(`[Luminix] Expected ${t} to be reducible.`);
|
|
1130
|
+
m(this, oe, "NotReducibleException");
|
|
1098
1131
|
}
|
|
1099
1132
|
}
|
|
1100
|
-
|
|
1101
|
-
class
|
|
1102
|
-
constructor(
|
|
1103
|
-
super(`[Luminix] "${
|
|
1133
|
+
var ue, ae;
|
|
1134
|
+
class M extends (ae = TypeError, ue = Symbol.toStringTag, ae) {
|
|
1135
|
+
constructor(t, r = "Model") {
|
|
1136
|
+
super(`[Luminix] "${t}" expects ${r}`);
|
|
1137
|
+
m(this, ue, "NotModelException");
|
|
1104
1138
|
}
|
|
1105
1139
|
}
|
|
1106
|
-
|
|
1107
|
-
class
|
|
1108
|
-
constructor(
|
|
1109
|
-
super(`[Luminix] Could not determine inverse relation for "${
|
|
1140
|
+
var le, ce;
|
|
1141
|
+
class We extends (ce = Error, le = Symbol.toStringTag, ce) {
|
|
1142
|
+
constructor(t, r, i, s) {
|
|
1143
|
+
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}".`);
|
|
1144
|
+
m(this, le, "NoInverseRelationException");
|
|
1110
1145
|
}
|
|
1111
1146
|
}
|
|
1112
|
-
|
|
1113
|
-
class
|
|
1114
|
-
constructor(
|
|
1115
|
-
super(`[Luminix] Relation "${
|
|
1147
|
+
var de, fe;
|
|
1148
|
+
class Ge extends (fe = Error, de = Symbol.toStringTag, fe) {
|
|
1149
|
+
constructor(t) {
|
|
1150
|
+
super(`[Luminix] Relation "${t}" is not supported`);
|
|
1151
|
+
m(this, de, "UnsupportedRelationException");
|
|
1116
1152
|
}
|
|
1117
1153
|
}
|
|
1118
|
-
|
|
1119
|
-
function w(n) {
|
|
1154
|
+
function E(n) {
|
|
1120
1155
|
return typeof n == "object" && n !== null && n.__isModel === !0;
|
|
1121
1156
|
}
|
|
1122
|
-
class
|
|
1123
|
-
constructor(e, t, r,
|
|
1124
|
-
|
|
1125
|
-
if (this.meta = e, this.facades = t, this.parent = r, this.items =
|
|
1126
|
-
throw new
|
|
1157
|
+
class P {
|
|
1158
|
+
constructor(e, t, r, i = null) {
|
|
1159
|
+
m(this, "unsubscribeQuery", null);
|
|
1160
|
+
if (this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !E(i) && !(S(i) && i.every(E)))
|
|
1161
|
+
throw new M("Relation.constructor()", "Model, Collection<Model> or null");
|
|
1127
1162
|
}
|
|
1128
1163
|
make(e) {
|
|
1129
1164
|
const t = this.getRelated();
|
|
@@ -1139,13 +1174,13 @@ class j {
|
|
|
1139
1174
|
if (this.isMultiple()) {
|
|
1140
1175
|
if (!Array.isArray(e))
|
|
1141
1176
|
throw new TypeError("Relation.make() expects an array");
|
|
1142
|
-
this.set(
|
|
1177
|
+
this.set(c(e.map((r) => new t(r))));
|
|
1143
1178
|
}
|
|
1144
1179
|
}
|
|
1145
1180
|
guessInverseRelation() {
|
|
1146
1181
|
const { relations: e } = this.getRelated().getSchema();
|
|
1147
1182
|
if (typeof this.facades.model.guessInverseRelation != "function")
|
|
1148
|
-
throw new
|
|
1183
|
+
throw new $("ModelFacade");
|
|
1149
1184
|
const t = this.getType(), r = this.facades.model.guessInverseRelation({
|
|
1150
1185
|
HasOne: ["BelongsTo"],
|
|
1151
1186
|
HasMany: ["BelongsTo"],
|
|
@@ -1157,18 +1192,18 @@ class j {
|
|
|
1157
1192
|
MorphToMany: ["MorphToMany"]
|
|
1158
1193
|
}, this.parent, t, this.getRelated());
|
|
1159
1194
|
if (!(t in r))
|
|
1160
|
-
throw new
|
|
1161
|
-
for (const
|
|
1162
|
-
const
|
|
1163
|
-
if ((
|
|
1164
|
-
return
|
|
1195
|
+
throw new Ge(t);
|
|
1196
|
+
for (const i in e) {
|
|
1197
|
+
const s = e[i];
|
|
1198
|
+
if ((s.model === this.parent.getType() || ["MorphOne", "MorphMany"].includes(t)) && r[t].includes(s.type))
|
|
1199
|
+
return i;
|
|
1165
1200
|
}
|
|
1166
|
-
throw new
|
|
1201
|
+
throw new We(this.parent.getType(), t, this.getRelated().getSchemaName(), r[t].join(" or "));
|
|
1167
1202
|
}
|
|
1168
1203
|
set(e) {
|
|
1169
|
-
if (e !== null && !
|
|
1170
|
-
throw new
|
|
1171
|
-
!this.items ||
|
|
1204
|
+
if (e !== null && !E(e) && !(S(e) && e.every(E)))
|
|
1205
|
+
throw new M("Relation.set()", "Model, Collection<Model> or null");
|
|
1206
|
+
!this.items || E(this.items) ? this.items = e : S(e) && this.items.splice(0, this.items.count(), ...e);
|
|
1172
1207
|
}
|
|
1173
1208
|
getForeignKey() {
|
|
1174
1209
|
return this.meta.foreignKey;
|
|
@@ -1198,10 +1233,10 @@ class j {
|
|
|
1198
1233
|
return this.items;
|
|
1199
1234
|
}
|
|
1200
1235
|
isSingle() {
|
|
1201
|
-
return
|
|
1236
|
+
return E(this.items);
|
|
1202
1237
|
}
|
|
1203
1238
|
isMultiple() {
|
|
1204
|
-
return
|
|
1239
|
+
return S(this.items);
|
|
1205
1240
|
}
|
|
1206
1241
|
getParent() {
|
|
1207
1242
|
return this.parent;
|
|
@@ -1246,71 +1281,68 @@ class j {
|
|
|
1246
1281
|
// return this.query().find(id);
|
|
1247
1282
|
// }
|
|
1248
1283
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
p(U, "name", "AttributeNotFillableException");
|
|
1255
|
-
class D extends Error {
|
|
1256
|
-
constructor(e, t) {
|
|
1257
|
-
super(`[Luminix] Model "${e}" must be persisted before calling "${t}"`);
|
|
1284
|
+
var me, pe;
|
|
1285
|
+
class Re extends (pe = Error, me = Symbol.toStringTag, pe) {
|
|
1286
|
+
constructor(t, r) {
|
|
1287
|
+
super(`[Luminix] Model "${t}" must be persisted before calling "${r}"`);
|
|
1288
|
+
m(this, me, "ModelNotPersistedException");
|
|
1258
1289
|
}
|
|
1259
1290
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1291
|
+
function Ve(n, e) {
|
|
1292
|
+
var r;
|
|
1293
|
+
r = Symbol.toStringTag;
|
|
1262
1294
|
class t {
|
|
1263
1295
|
constructor(s = {}) {
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1296
|
+
m(this, "_attributes", new v({}));
|
|
1297
|
+
m(this, "_original", {});
|
|
1298
|
+
m(this, "_relations", {});
|
|
1299
|
+
m(this, "_changedKeys", []);
|
|
1300
|
+
m(this, "exists", !1);
|
|
1301
|
+
m(this, "wasRecentlyCreated", !1);
|
|
1302
|
+
m(this, r, d.upperFirst(d.camelCase(e)));
|
|
1269
1303
|
this.makeRelations(), this.makeAttributes(s);
|
|
1270
1304
|
}
|
|
1271
|
-
cast(s,
|
|
1272
|
-
return s == null || !
|
|
1305
|
+
cast(s, u) {
|
|
1306
|
+
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
1307
|
}
|
|
1274
|
-
mutate(s,
|
|
1275
|
-
return s == null || !
|
|
1308
|
+
mutate(s, u) {
|
|
1309
|
+
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
1310
|
}
|
|
1277
1311
|
makeRelations() {
|
|
1278
|
-
const { relations: s } = n.model.schema(e);
|
|
1312
|
+
const { relations: s } = n.make("model").schema(e);
|
|
1279
1313
|
if (this._relations = {}, !s)
|
|
1280
1314
|
return;
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
{ name: u, ...a },
|
|
1288
|
-
n,
|
|
1315
|
+
const u = n.make("model").relationMap({}, e);
|
|
1316
|
+
Object.entries(s).forEach(([l, a]) => {
|
|
1317
|
+
const { type: f } = a, p = f in u ? u[f] : P;
|
|
1318
|
+
this._relations[l] = new p(
|
|
1319
|
+
{ name: l, ...a },
|
|
1320
|
+
n.make(),
|
|
1289
1321
|
this,
|
|
1290
1322
|
null
|
|
1291
1323
|
);
|
|
1292
1324
|
});
|
|
1293
1325
|
}
|
|
1294
1326
|
makeAttributes(s) {
|
|
1295
|
-
const { relations:
|
|
1296
|
-
if (this.fillable.filter((
|
|
1297
|
-
a[
|
|
1298
|
-
}),
|
|
1299
|
-
this.relation(
|
|
1327
|
+
const { relations: u } = n.make("model").schema(e), l = Object.keys(u || {}), a = d.omit(s, l);
|
|
1328
|
+
if (this.fillable.filter((f) => !(f in a)).forEach((f) => {
|
|
1329
|
+
a[f] = null;
|
|
1330
|
+
}), u && Object.keys(u).forEach((f) => {
|
|
1331
|
+
this.relation(d.camelCase(f)).make(s[f]);
|
|
1300
1332
|
}), !this.validateJsonObject(a)) {
|
|
1301
|
-
if (n.
|
|
1333
|
+
if (n.isProduction())
|
|
1302
1334
|
throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
|
|
1303
|
-
n.log.warning(`Invalid attributes for model "${e}".
|
|
1335
|
+
n.make("log").warning(`Invalid attributes for model "${e}".
|
|
1304
1336
|
This will throw an error in production.`, {
|
|
1305
1337
|
attributes: s,
|
|
1306
1338
|
abstract: e
|
|
1307
1339
|
});
|
|
1308
1340
|
}
|
|
1309
|
-
this._attributes
|
|
1341
|
+
this._attributes.set(".", a), this._original = a, this._changedKeys.splice(0, this._changedKeys.length);
|
|
1310
1342
|
}
|
|
1311
1343
|
makePrimaryKeyReplacer() {
|
|
1312
1344
|
return {
|
|
1313
|
-
[this.
|
|
1345
|
+
[this.getKeyName()]: this.getKey()
|
|
1314
1346
|
};
|
|
1315
1347
|
}
|
|
1316
1348
|
dispatchChangeEvent(s) {
|
|
@@ -1321,7 +1353,7 @@ function $e(n, e) {
|
|
|
1321
1353
|
dispatchCreateEvent(s) {
|
|
1322
1354
|
this.emit("create", {
|
|
1323
1355
|
value: s
|
|
1324
|
-
}), n.model.emit("create", {
|
|
1356
|
+
}), n.make("model").emit("create", {
|
|
1325
1357
|
class: e,
|
|
1326
1358
|
model: this
|
|
1327
1359
|
});
|
|
@@ -1329,7 +1361,7 @@ function $e(n, e) {
|
|
|
1329
1361
|
dispatchUpdateEvent(s) {
|
|
1330
1362
|
this.emit("update", {
|
|
1331
1363
|
value: s
|
|
1332
|
-
}), n.model.emit("update", {
|
|
1364
|
+
}), n.make("model").emit("update", {
|
|
1333
1365
|
class: e,
|
|
1334
1366
|
model: this
|
|
1335
1367
|
});
|
|
@@ -1337,7 +1369,7 @@ function $e(n, e) {
|
|
|
1337
1369
|
dispatchSaveEvent() {
|
|
1338
1370
|
this.emit("save", {
|
|
1339
1371
|
value: this.diff()
|
|
1340
|
-
}), n.model.emit("save", {
|
|
1372
|
+
}), n.make("model").emit("save", {
|
|
1341
1373
|
class: e,
|
|
1342
1374
|
model: this
|
|
1343
1375
|
});
|
|
@@ -1346,7 +1378,7 @@ function $e(n, e) {
|
|
|
1346
1378
|
this.emit("delete", {
|
|
1347
1379
|
force: s,
|
|
1348
1380
|
[this.getKeyName()]: this.getKey()
|
|
1349
|
-
}), n.model.emit("delete", {
|
|
1381
|
+
}), n.make("model").emit("delete", {
|
|
1350
1382
|
class: e,
|
|
1351
1383
|
model: this,
|
|
1352
1384
|
force: s
|
|
@@ -1355,28 +1387,28 @@ function $e(n, e) {
|
|
|
1355
1387
|
dispatchRestoreEvent() {
|
|
1356
1388
|
this.emit("restore", {
|
|
1357
1389
|
value: this.attributes
|
|
1358
|
-
}), n.model.emit("restore", {
|
|
1390
|
+
}), n.make("model").emit("restore", {
|
|
1359
1391
|
class: e,
|
|
1360
1392
|
model: this
|
|
1361
1393
|
});
|
|
1362
1394
|
}
|
|
1363
|
-
dispatchErrorEvent(s,
|
|
1395
|
+
dispatchErrorEvent(s, u) {
|
|
1364
1396
|
this.emit("error", {
|
|
1365
1397
|
error: s,
|
|
1366
|
-
operation:
|
|
1367
|
-
}), n.model.emit("error", {
|
|
1398
|
+
operation: u
|
|
1399
|
+
}), n.make("model").emit("error", {
|
|
1368
1400
|
class: e,
|
|
1369
1401
|
model: this,
|
|
1370
1402
|
error: s,
|
|
1371
|
-
operation:
|
|
1403
|
+
operation: u
|
|
1372
1404
|
});
|
|
1373
1405
|
}
|
|
1374
1406
|
updateChangedKeys(s) {
|
|
1375
|
-
const
|
|
1376
|
-
!this._changedKeys.includes(s) && !
|
|
1407
|
+
const u = (l, a) => typeof l == "object" && l !== null ? d.isEqual(l, a) : l == a;
|
|
1408
|
+
!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
1409
|
}
|
|
1378
1410
|
validateJsonObject(s) {
|
|
1379
|
-
return typeof s != "object" || s === null ? !1 : Object.entries(s).every(([,
|
|
1411
|
+
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
1412
|
}
|
|
1381
1413
|
get attributes() {
|
|
1382
1414
|
return this._attributes.all();
|
|
@@ -1388,20 +1420,20 @@ function $e(n, e) {
|
|
|
1388
1420
|
return this._relations;
|
|
1389
1421
|
}
|
|
1390
1422
|
get fillable() {
|
|
1391
|
-
return n.model.schema(e).fillable;
|
|
1423
|
+
return n.make("model").schema(e).fillable;
|
|
1392
1424
|
}
|
|
1393
1425
|
get primaryKey() {
|
|
1394
|
-
return n.model.schema(e).primaryKey;
|
|
1426
|
+
return n.make("model").schema(e).primaryKey;
|
|
1395
1427
|
}
|
|
1396
1428
|
get timestamps() {
|
|
1397
|
-
return n.model.schema(e).timestamps;
|
|
1429
|
+
return n.make("model").schema(e).timestamps;
|
|
1398
1430
|
}
|
|
1399
1431
|
// get softDeletes() {
|
|
1400
|
-
// return
|
|
1432
|
+
// return app.make('model').schema(abstract).softDeletes;
|
|
1401
1433
|
// }
|
|
1402
1434
|
get casts() {
|
|
1403
1435
|
return {
|
|
1404
|
-
...n.model.schema(e).casts,
|
|
1436
|
+
...n.make("model").schema(e).casts,
|
|
1405
1437
|
...this.timestamps ? { created_at: "datetime", updated_at: "datetime" } : {}
|
|
1406
1438
|
// ...this.softDeletes ? { deleted_at: 'datetime' } : {},
|
|
1407
1439
|
};
|
|
@@ -1410,35 +1442,28 @@ function $e(n, e) {
|
|
|
1410
1442
|
return this._changedKeys.length > 0;
|
|
1411
1443
|
}
|
|
1412
1444
|
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]),
|
|
1445
|
+
let u = this._attributes.get(s, null);
|
|
1446
|
+
s in this.casts && (u = this.cast(u, this.casts[s]));
|
|
1447
|
+
const l = n.make("model")[`model${d.upperFirst(d.camelCase(e))}Get${d.upperFirst(d.camelCase(s))}Attribute`];
|
|
1448
|
+
if (typeof l != "function")
|
|
1449
|
+
throw new $("ModelFacade");
|
|
1450
|
+
return l.bind(n.make("model"))(u, this);
|
|
1451
|
+
}
|
|
1452
|
+
setAttribute(s, u) {
|
|
1453
|
+
const l = n.make("model")[`model${d.upperFirst(d.camelCase(e))}Set${d.upperFirst(d.camelCase(s))}Attribute`];
|
|
1454
|
+
if (typeof l != "function")
|
|
1455
|
+
throw new $("ModelFacade");
|
|
1456
|
+
const a = l.bind(n.make("model"))(
|
|
1457
|
+
this.mutate(u, this.casts[s]),
|
|
1433
1458
|
this
|
|
1434
1459
|
);
|
|
1435
1460
|
if (!this.validateJsonObject({ [s]: a })) {
|
|
1436
|
-
if (n.
|
|
1461
|
+
if (n.isProduction())
|
|
1437
1462
|
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.
|
|
1463
|
+
n.make("log").warning(`Invalid type for attribute "${s}" in model "${e}" after mutation.
|
|
1439
1464
|
This will throw an error in production.`, {
|
|
1440
1465
|
key: s,
|
|
1441
|
-
value:
|
|
1466
|
+
value: u,
|
|
1442
1467
|
mutated: a,
|
|
1443
1468
|
cast: this.casts[s],
|
|
1444
1469
|
item: this.toJson()
|
|
@@ -1454,175 +1479,196 @@ function $e(n, e) {
|
|
|
1454
1479
|
return this.primaryKey;
|
|
1455
1480
|
}
|
|
1456
1481
|
fill(s) {
|
|
1457
|
-
const
|
|
1458
|
-
const
|
|
1459
|
-
if (typeof
|
|
1460
|
-
throw new
|
|
1461
|
-
return a[
|
|
1462
|
-
this.mutate(
|
|
1482
|
+
const u = d.pick(s, this.fillable), l = Object.entries(u).reduce((a, [f, p]) => {
|
|
1483
|
+
const w = n.make("model")[`model${d.upperFirst(d.camelCase(e))}Set${d.upperFirst(d.camelCase(f))}Attribute`];
|
|
1484
|
+
if (typeof w != "function")
|
|
1485
|
+
throw new $("ModelFacade");
|
|
1486
|
+
return a[f] = w.bind(n.make("model"))(
|
|
1487
|
+
this.mutate(p, this.casts[f]),
|
|
1463
1488
|
this
|
|
1464
1489
|
), a;
|
|
1465
1490
|
}, {});
|
|
1466
|
-
if (!this.validateJsonObject(
|
|
1467
|
-
if (n.
|
|
1491
|
+
if (!this.validateJsonObject(l)) {
|
|
1492
|
+
if (n.isProduction())
|
|
1468
1493
|
throw new TypeError(`[Luminix] Invalid attributes for model "${e}"`);
|
|
1469
|
-
n.log.warning(`Invalid attributes for model "${e}" after mutation.
|
|
1494
|
+
n.make("log").warning(`Invalid attributes for model "${e}" after mutation.
|
|
1470
1495
|
This will throw an error in production.`, {
|
|
1471
1496
|
attributes: s,
|
|
1472
|
-
mutatedAttributes:
|
|
1497
|
+
mutatedAttributes: l,
|
|
1473
1498
|
item: this.toJson(),
|
|
1474
1499
|
casts: this.casts
|
|
1475
1500
|
});
|
|
1476
1501
|
return;
|
|
1477
1502
|
}
|
|
1478
|
-
this._attributes.merge(".",
|
|
1503
|
+
this._attributes.merge(".", l), Object.keys(l).forEach((a) => this.updateChangedKeys(a)), this.dispatchChangeEvent(l);
|
|
1479
1504
|
}
|
|
1480
1505
|
dump() {
|
|
1481
|
-
n.log.info({
|
|
1506
|
+
n.make("log").info({
|
|
1482
1507
|
...this.toJson(),
|
|
1483
|
-
[Symbol.toStringTag]:
|
|
1508
|
+
[Symbol.toStringTag]: d.upperFirst(d.camelCase(e))
|
|
1484
1509
|
});
|
|
1485
1510
|
}
|
|
1486
1511
|
toJson() {
|
|
1487
|
-
const s = Object.entries(this.relations).reduce((
|
|
1488
|
-
if (typeof
|
|
1489
|
-
throw new
|
|
1490
|
-
return
|
|
1512
|
+
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`];
|
|
1513
|
+
if (typeof u != "function")
|
|
1514
|
+
throw new $("ModelFacade");
|
|
1515
|
+
return u.bind(n.make("model"))({
|
|
1491
1516
|
...this.attributes,
|
|
1492
1517
|
...s
|
|
1493
1518
|
}, this);
|
|
1494
1519
|
}
|
|
1495
1520
|
diff() {
|
|
1496
|
-
return this._changedKeys.reduce((s,
|
|
1521
|
+
return this._changedKeys.reduce((s, u) => (s[u] = this._attributes.get(u), s), {});
|
|
1497
1522
|
}
|
|
1498
1523
|
getType() {
|
|
1499
1524
|
return e;
|
|
1500
1525
|
}
|
|
1501
1526
|
relation(s) {
|
|
1502
|
-
if (s ===
|
|
1503
|
-
return this.relations[
|
|
1527
|
+
if (s === d.camelCase(s))
|
|
1528
|
+
return this.relations[d.snakeCase(s)];
|
|
1504
1529
|
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1530
|
+
getErrorBag(s) {
|
|
1531
|
+
return `${this.exists ? `${e}[${this.getKey()}].` : `${e}.`}${s}`;
|
|
1532
|
+
}
|
|
1533
|
+
getRouteForSave() {
|
|
1534
|
+
return this.exists ? [
|
|
1535
|
+
`luminix.${e}.update`,
|
|
1536
|
+
this.makePrimaryKeyReplacer()
|
|
1537
|
+
] : `luminix.${e}.store`;
|
|
1538
|
+
}
|
|
1539
|
+
getRouteForUpdate() {
|
|
1540
|
+
return [
|
|
1541
|
+
`luminix.${e}.update`,
|
|
1542
|
+
this.makePrimaryKeyReplacer()
|
|
1543
|
+
];
|
|
1544
|
+
}
|
|
1545
|
+
getRouteForDelete() {
|
|
1546
|
+
return [
|
|
1547
|
+
`luminix.${e}.destroy`,
|
|
1548
|
+
this.makePrimaryKeyReplacer()
|
|
1549
|
+
];
|
|
1550
|
+
}
|
|
1551
|
+
getRouteForRefresh() {
|
|
1552
|
+
return [
|
|
1509
1553
|
`luminix.${e}.show`,
|
|
1510
1554
|
this.makePrimaryKeyReplacer()
|
|
1511
|
-
]
|
|
1512
|
-
|
|
1513
|
-
|
|
1555
|
+
];
|
|
1556
|
+
}
|
|
1557
|
+
getLabel() {
|
|
1558
|
+
const { labeledBy: s } = n.make("model").schema(e);
|
|
1559
|
+
return this.getAttribute(s);
|
|
1560
|
+
}
|
|
1561
|
+
async refresh() {
|
|
1562
|
+
if (!this.exists)
|
|
1563
|
+
throw new Re(e, "refresh");
|
|
1564
|
+
const { data: s } = await n.make("route").call(
|
|
1565
|
+
this.getRouteForRefresh(),
|
|
1566
|
+
{ errorBag: this.getErrorBag("fetch") }
|
|
1567
|
+
);
|
|
1514
1568
|
this.makeAttributes(s);
|
|
1515
1569
|
}
|
|
1516
1570
|
async save(s = {}) {
|
|
1517
1571
|
try {
|
|
1518
1572
|
const {
|
|
1519
|
-
additionalPayload:
|
|
1520
|
-
sendsOnlyModifiedFields:
|
|
1521
|
-
} = s, a = this.exists,
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1573
|
+
additionalPayload: u = {},
|
|
1574
|
+
sendsOnlyModifiedFields: l = !0
|
|
1575
|
+
} = s, a = this.exists, f = {
|
|
1576
|
+
...d.pick(
|
|
1577
|
+
l && a ? this.diff() : this.attributes,
|
|
1578
|
+
this.fillable
|
|
1579
|
+
),
|
|
1580
|
+
...u
|
|
1581
|
+
};
|
|
1582
|
+
if (d.isEmpty(f))
|
|
1583
|
+
return;
|
|
1584
|
+
const p = await n.make("route").call(
|
|
1585
|
+
this.getRouteForSave(),
|
|
1526
1586
|
{
|
|
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`
|
|
1587
|
+
data: f,
|
|
1588
|
+
errorBag: this.getErrorBag(a ? "update" : "store")
|
|
1535
1589
|
}
|
|
1536
1590
|
);
|
|
1537
|
-
if ([200, 201].includes(
|
|
1538
|
-
return this.makeAttributes(
|
|
1539
|
-
throw
|
|
1540
|
-
} catch (
|
|
1541
|
-
throw
|
|
1591
|
+
if ([200, 201].includes(p.status))
|
|
1592
|
+
return this.makeAttributes(p.data), this.exists = !0, this.dispatchSaveEvent(), a ? this.dispatchUpdateEvent(p.data) : (this.wasRecentlyCreated = !0, this.dispatchCreateEvent(p.data)), p;
|
|
1593
|
+
throw p;
|
|
1594
|
+
} catch (u) {
|
|
1595
|
+
throw this.dispatchErrorEvent(u, "save"), u;
|
|
1542
1596
|
}
|
|
1543
1597
|
}
|
|
1544
1598
|
async push() {
|
|
1545
|
-
throw new
|
|
1599
|
+
throw new b();
|
|
1546
1600
|
}
|
|
1547
1601
|
async delete() {
|
|
1548
1602
|
try {
|
|
1549
|
-
const s = await n.route.call(
|
|
1550
|
-
|
|
1551
|
-
this.
|
|
1552
|
-
|
|
1553
|
-
errorBag: `${e}[${this.getKey()}].delete`
|
|
1554
|
-
});
|
|
1603
|
+
const s = await n.make("route").call(
|
|
1604
|
+
this.getRouteForDelete(),
|
|
1605
|
+
{ errorBag: this.getErrorBag("delete") }
|
|
1606
|
+
);
|
|
1555
1607
|
if (s.status === 204)
|
|
1556
1608
|
return this.dispatchDeleteEvent(), s;
|
|
1557
1609
|
throw s;
|
|
1558
1610
|
} catch (s) {
|
|
1559
|
-
throw
|
|
1611
|
+
throw this.dispatchErrorEvent(s, "delete"), s;
|
|
1560
1612
|
}
|
|
1561
1613
|
}
|
|
1562
1614
|
async update(s) {
|
|
1563
1615
|
try {
|
|
1564
|
-
const
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
if (
|
|
1572
|
-
this.makeAttributes(
|
|
1616
|
+
const u = await n.make("route").call(
|
|
1617
|
+
this.getRouteForUpdate(),
|
|
1618
|
+
{
|
|
1619
|
+
data: s,
|
|
1620
|
+
errorBag: this.getErrorBag("update")
|
|
1621
|
+
}
|
|
1622
|
+
);
|
|
1623
|
+
if (u.status === 200) {
|
|
1624
|
+
this.makeAttributes(u.data), this.dispatchUpdateEvent(u.data);
|
|
1573
1625
|
return;
|
|
1574
1626
|
}
|
|
1575
|
-
throw
|
|
1576
|
-
} catch (
|
|
1577
|
-
throw
|
|
1627
|
+
throw u;
|
|
1628
|
+
} catch (u) {
|
|
1629
|
+
throw this.dispatchErrorEvent(u, "save"), u;
|
|
1578
1630
|
}
|
|
1579
1631
|
}
|
|
1580
1632
|
async forceDelete() {
|
|
1581
1633
|
try {
|
|
1582
|
-
const s = await n.route.call(
|
|
1583
|
-
|
|
1584
|
-
`luminix.${e}.destroy`,
|
|
1585
|
-
this.makePrimaryKeyReplacer()
|
|
1586
|
-
],
|
|
1634
|
+
const s = await n.make("route").call(
|
|
1635
|
+
this.getRouteForDelete(),
|
|
1587
1636
|
{
|
|
1588
1637
|
params: { force: !0 },
|
|
1589
|
-
errorBag:
|
|
1638
|
+
errorBag: this.getErrorBag("forceDelete")
|
|
1590
1639
|
}
|
|
1591
1640
|
);
|
|
1592
1641
|
if (s.status === 204)
|
|
1593
1642
|
return this.dispatchDeleteEvent(!0), s;
|
|
1594
1643
|
throw s;
|
|
1595
1644
|
} catch (s) {
|
|
1596
|
-
throw
|
|
1645
|
+
throw this.dispatchErrorEvent(s, "forceDelete"), s;
|
|
1597
1646
|
}
|
|
1598
1647
|
}
|
|
1599
1648
|
async restore() {
|
|
1600
1649
|
try {
|
|
1601
|
-
const s = await n.route.call(
|
|
1602
|
-
|
|
1603
|
-
`luminix.${e}.update`,
|
|
1604
|
-
this.makePrimaryKeyReplacer()
|
|
1605
|
-
],
|
|
1650
|
+
const s = await n.make("route").call(
|
|
1651
|
+
this.getRouteForUpdate(),
|
|
1606
1652
|
{
|
|
1607
1653
|
params: { restore: !0 },
|
|
1608
|
-
errorBag:
|
|
1654
|
+
errorBag: this.getErrorBag("restore")
|
|
1609
1655
|
}
|
|
1610
1656
|
);
|
|
1611
1657
|
if (s.status === 200)
|
|
1612
1658
|
return this.dispatchRestoreEvent(), s;
|
|
1613
1659
|
throw s;
|
|
1614
1660
|
} catch (s) {
|
|
1615
|
-
throw
|
|
1661
|
+
throw this.dispatchErrorEvent(s, "restore"), s;
|
|
1616
1662
|
}
|
|
1617
1663
|
}
|
|
1618
1664
|
static getSchemaName() {
|
|
1619
1665
|
return e;
|
|
1620
1666
|
}
|
|
1621
1667
|
static getSchema() {
|
|
1622
|
-
return n.model.schema(e);
|
|
1668
|
+
return n.make("model").schema(e);
|
|
1623
1669
|
}
|
|
1624
1670
|
static query() {
|
|
1625
|
-
return new
|
|
1671
|
+
return new He(n.make(), e);
|
|
1626
1672
|
}
|
|
1627
1673
|
static where(...s) {
|
|
1628
1674
|
return this.query().where(...s);
|
|
@@ -1633,14 +1679,14 @@ function $e(n, e) {
|
|
|
1633
1679
|
static whereNotNull(s) {
|
|
1634
1680
|
return this.query().whereNotNull(s);
|
|
1635
1681
|
}
|
|
1636
|
-
static whereBetween(s,
|
|
1637
|
-
return this.query().whereBetween(s,
|
|
1682
|
+
static whereBetween(s, u) {
|
|
1683
|
+
return this.query().whereBetween(s, u);
|
|
1638
1684
|
}
|
|
1639
|
-
static whereNotBetween(s,
|
|
1640
|
-
return this.query().whereNotBetween(s,
|
|
1685
|
+
static whereNotBetween(s, u) {
|
|
1686
|
+
return this.query().whereNotBetween(s, u);
|
|
1641
1687
|
}
|
|
1642
|
-
static orderBy(s,
|
|
1643
|
-
return this.query().orderBy(s,
|
|
1688
|
+
static orderBy(s, u = "asc") {
|
|
1689
|
+
return this.query().orderBy(s, u);
|
|
1644
1690
|
}
|
|
1645
1691
|
static searchBy(s) {
|
|
1646
1692
|
return this.query().searchBy(s);
|
|
@@ -1651,8 +1697,8 @@ function $e(n, e) {
|
|
|
1651
1697
|
static limit(s) {
|
|
1652
1698
|
return this.query().limit(s);
|
|
1653
1699
|
}
|
|
1654
|
-
static get(s = 1,
|
|
1655
|
-
return this.query().get(s,
|
|
1700
|
+
static get(s = 1, u) {
|
|
1701
|
+
return this.query().get(s, u);
|
|
1656
1702
|
}
|
|
1657
1703
|
static find(s) {
|
|
1658
1704
|
return this.query().find(s);
|
|
@@ -1661,135 +1707,130 @@ function $e(n, e) {
|
|
|
1661
1707
|
return this.query().first();
|
|
1662
1708
|
}
|
|
1663
1709
|
static async create(s) {
|
|
1664
|
-
const
|
|
1665
|
-
return
|
|
1710
|
+
const u = n.make("model").make(e), l = new u();
|
|
1711
|
+
return l.fill(s), await l.save(), l;
|
|
1666
1712
|
}
|
|
1667
|
-
static async update(s,
|
|
1668
|
-
const
|
|
1669
|
-
return a.fill(
|
|
1713
|
+
static async update(s, u) {
|
|
1714
|
+
const l = n.make("model").make(e), a = new l({ id: s });
|
|
1715
|
+
return a.fill(u), a.exists = !0, await a.save(), a;
|
|
1670
1716
|
}
|
|
1671
1717
|
static delete(s) {
|
|
1672
1718
|
if (Array.isArray(s))
|
|
1673
|
-
return n.route.call(`luminix.${e}.destroyMany`, {
|
|
1719
|
+
return n.make("route").call(`luminix.${e}.destroyMany`, {
|
|
1674
1720
|
params: { ids: s },
|
|
1675
1721
|
errorBag: `${e}.deleteMany`
|
|
1676
1722
|
});
|
|
1677
|
-
const
|
|
1678
|
-
return new
|
|
1723
|
+
const u = n.make("model").make(e);
|
|
1724
|
+
return new u({ id: s }).delete();
|
|
1679
1725
|
}
|
|
1680
1726
|
static async restore(s) {
|
|
1681
1727
|
if (Array.isArray(s))
|
|
1682
|
-
return n.route.call(`luminix.${e}.restoreMany`, {
|
|
1728
|
+
return n.make("route").call(`luminix.${e}.restoreMany`, {
|
|
1683
1729
|
data: { ids: s },
|
|
1684
1730
|
errorBag: `${e}.restoreMany`
|
|
1685
1731
|
});
|
|
1686
|
-
const
|
|
1687
|
-
return new
|
|
1732
|
+
const u = n.make("model").make(e);
|
|
1733
|
+
return new u({ id: s }).restore();
|
|
1688
1734
|
}
|
|
1689
1735
|
static forceDelete(s) {
|
|
1690
1736
|
if (Array.isArray(s))
|
|
1691
|
-
return n.route.call(`luminix.${e}.destroyMany`, {
|
|
1737
|
+
return n.make("route").call(`luminix.${e}.destroyMany`, {
|
|
1692
1738
|
params: { ids: s, force: !0 },
|
|
1693
1739
|
errorBag: `${e}.forceDeleteMany`
|
|
1694
1740
|
});
|
|
1695
|
-
const
|
|
1696
|
-
return new
|
|
1741
|
+
const u = n.make("model").make(e);
|
|
1742
|
+
return new u({ id: s }).forceDelete();
|
|
1697
1743
|
}
|
|
1698
1744
|
static singular() {
|
|
1699
|
-
return n.model.schema(e).displayName.singular;
|
|
1745
|
+
return n.make("model").schema(e).displayName.singular;
|
|
1700
1746
|
}
|
|
1701
1747
|
static plural() {
|
|
1702
|
-
return n.model.schema(e).displayName.plural;
|
|
1748
|
+
return n.make("model").schema(e).displayName.plural;
|
|
1703
1749
|
}
|
|
1704
1750
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1705
|
-
on(s,
|
|
1706
|
-
throw new
|
|
1751
|
+
on(s, u) {
|
|
1752
|
+
throw new b();
|
|
1707
1753
|
}
|
|
1708
1754
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1709
|
-
once(s,
|
|
1710
|
-
throw new
|
|
1755
|
+
once(s, u) {
|
|
1756
|
+
throw new b();
|
|
1711
1757
|
}
|
|
1712
1758
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1713
|
-
emit(s,
|
|
1714
|
-
throw new
|
|
1759
|
+
emit(s, u) {
|
|
1760
|
+
throw new b();
|
|
1715
1761
|
}
|
|
1716
1762
|
}
|
|
1717
|
-
return
|
|
1763
|
+
return m(t, "name", d.upperFirst(d.camelCase(e))), A(t);
|
|
1718
1764
|
}
|
|
1719
|
-
function
|
|
1720
|
-
var r;
|
|
1721
|
-
return r =
|
|
1722
|
-
constructor(
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1765
|
+
function Xe(n, e, t) {
|
|
1766
|
+
var r, i;
|
|
1767
|
+
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
1768
|
+
constructor(u = {}) {
|
|
1769
|
+
super(u);
|
|
1770
|
+
m(this, r, d.upperFirst(d.camelCase(e)));
|
|
1771
|
+
return new Proxy(this, {
|
|
1772
|
+
get: (l, a) => {
|
|
1773
|
+
if (a === "__isModel")
|
|
1726
1774
|
return !0;
|
|
1727
|
-
if (
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
}
|
|
1731
|
-
if (u !== f.camelCase(u))
|
|
1775
|
+
if (a in l)
|
|
1776
|
+
return Reflect.get(l, a);
|
|
1777
|
+
if (a !== d.camelCase(a))
|
|
1732
1778
|
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
|
|
1779
|
+
const f = d.snakeCase(a);
|
|
1780
|
+
if (Object.keys(l.attributes).includes(f))
|
|
1781
|
+
return l.getAttribute(f);
|
|
1782
|
+
if (Object.keys(l.relations).includes(f))
|
|
1783
|
+
return l.relations[f].getLoadedItems();
|
|
1784
|
+
if (a.endsWith("Relation") && Object.keys(l.relations).includes(d.snakeCase(a.slice(0, -8))))
|
|
1785
|
+
return () => l.relation(a.slice(0, -8));
|
|
1786
|
+
if (n.model.hasReducer(`model${l.constructor.name}Get${d.upperFirst(a)}Attribute`)) {
|
|
1787
|
+
const p = n.model[`model${l.constructor.name}Get${d.upperFirst(a)}Attribute`];
|
|
1788
|
+
if (typeof p != "function")
|
|
1789
|
+
throw new $("ModelFacade");
|
|
1790
|
+
return p.bind(n.model)(void 0, l);
|
|
1745
1791
|
}
|
|
1746
|
-
return Reflect.get(
|
|
1792
|
+
return Reflect.get(l, a);
|
|
1747
1793
|
},
|
|
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
|
-
}
|
|
1794
|
+
set: (l, a, f) => a in l && typeof l[a] != "function" ? Reflect.set(l, a, f) : (l.setAttribute(
|
|
1795
|
+
d.snakeCase(a),
|
|
1796
|
+
f
|
|
1797
|
+
), !0)
|
|
1758
1798
|
});
|
|
1759
1799
|
}
|
|
1760
|
-
}
|
|
1800
|
+
};
|
|
1761
1801
|
}
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1802
|
+
var ge, ye;
|
|
1803
|
+
class Ye extends (ye = Error, ge = Symbol.toStringTag, ye) {
|
|
1804
|
+
constructor(t, r) {
|
|
1805
|
+
super(`[Luminix] Cannot create reducer '${t}' on '${r}' as it is a reserved property`);
|
|
1806
|
+
m(this, ge, "ReducerOverrideException");
|
|
1765
1807
|
}
|
|
1766
1808
|
}
|
|
1767
|
-
|
|
1768
|
-
function ie(n) {
|
|
1809
|
+
function ve(n) {
|
|
1769
1810
|
return class extends n {
|
|
1770
1811
|
constructor(...t) {
|
|
1771
1812
|
super(...t);
|
|
1772
|
-
|
|
1813
|
+
m(this, "reducers", {});
|
|
1773
1814
|
return new Proxy(this, {
|
|
1774
|
-
get(r,
|
|
1775
|
-
return typeof
|
|
1776
|
-
const { [
|
|
1777
|
-
return
|
|
1815
|
+
get(r, i, s) {
|
|
1816
|
+
return typeof i == "symbol" || i in r ? Reflect.get(r, i, s) : (u, ...l) => {
|
|
1817
|
+
const { [i]: a = c() } = r.reducers;
|
|
1818
|
+
return Pe(u) ? q(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
1819
|
};
|
|
1779
1820
|
}
|
|
1780
1821
|
});
|
|
1781
1822
|
}
|
|
1782
|
-
reducer(t, r,
|
|
1823
|
+
reducer(t, r, i = 10) {
|
|
1783
1824
|
if (t in this)
|
|
1784
|
-
throw new
|
|
1785
|
-
return this.reducers[t] || (this.reducers[t] =
|
|
1825
|
+
throw new Ye(t, this);
|
|
1826
|
+
return this.reducers[t] || (this.reducers[t] = c()), this.reducers[t].push({ callback: r, priority: i }), () => this.removeReducer(t, r);
|
|
1786
1827
|
}
|
|
1787
1828
|
removeReducer(t, r) {
|
|
1788
|
-
const
|
|
1789
|
-
|
|
1829
|
+
const i = this.reducers[t].search((s) => s.callback === r);
|
|
1830
|
+
i !== !1 && this.reducers[t].pull(i);
|
|
1790
1831
|
}
|
|
1791
1832
|
getReducer(t) {
|
|
1792
|
-
return this.reducers[t] || (this.reducers[t] =
|
|
1833
|
+
return this.reducers[t] || (this.reducers[t] = c()), this.reducers[t];
|
|
1793
1834
|
}
|
|
1794
1835
|
hasReducer(t) {
|
|
1795
1836
|
return !!this.reducers[t] && this.reducers[t].count() > 0;
|
|
@@ -1802,23 +1843,25 @@ function ie(n) {
|
|
|
1802
1843
|
}
|
|
1803
1844
|
};
|
|
1804
1845
|
}
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1846
|
+
var we, be;
|
|
1847
|
+
class V extends (be = Error, we = Symbol.toStringTag, be) {
|
|
1848
|
+
constructor(t) {
|
|
1849
|
+
super(`[Luminix] Model "${t}" not found`);
|
|
1850
|
+
m(this, we, "ModelNotFoundException");
|
|
1808
1851
|
}
|
|
1809
1852
|
}
|
|
1810
|
-
|
|
1811
|
-
class
|
|
1812
|
-
constructor(
|
|
1813
|
-
super(`[Luminix] "${
|
|
1853
|
+
var Ee, xe;
|
|
1854
|
+
class I extends (xe = TypeError, Ee = Symbol.toStringTag, xe) {
|
|
1855
|
+
constructor(t, r, i) {
|
|
1856
|
+
super(`[Luminix] "${t}" expects a related model of type "${r}". Received "${i}" instead.`);
|
|
1857
|
+
m(this, Ee, "ModelInvalidRelatedTypeException");
|
|
1814
1858
|
}
|
|
1815
1859
|
}
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
super(e, t, r, s), this.meta = e, this.facades = t, this.parent = r, this.items = s;
|
|
1860
|
+
class Ne extends P {
|
|
1861
|
+
constructor(e, t, r, i = null) {
|
|
1862
|
+
if (!E(i) && i !== null)
|
|
1863
|
+
throw new M("BelongsTo.constructor()", "Model or null");
|
|
1864
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1822
1865
|
}
|
|
1823
1866
|
isSingle() {
|
|
1824
1867
|
return !0;
|
|
@@ -1834,12 +1877,12 @@ class ne extends j {
|
|
|
1834
1877
|
return this.query().first();
|
|
1835
1878
|
}
|
|
1836
1879
|
async associate(e) {
|
|
1837
|
-
if (!
|
|
1838
|
-
throw new
|
|
1880
|
+
if (!E(e))
|
|
1881
|
+
throw new M("BelongsTo.associate()");
|
|
1839
1882
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1840
|
-
throw new
|
|
1883
|
+
throw new I("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
|
|
1841
1884
|
if (!e.exists)
|
|
1842
|
-
throw new
|
|
1885
|
+
throw new Re(this.getRelated().getSchemaName(), "save");
|
|
1843
1886
|
return this.parent.update({
|
|
1844
1887
|
[this.getForeignKey()]: e.getKey()
|
|
1845
1888
|
});
|
|
@@ -1850,11 +1893,11 @@ class ne extends j {
|
|
|
1850
1893
|
});
|
|
1851
1894
|
}
|
|
1852
1895
|
}
|
|
1853
|
-
class
|
|
1854
|
-
constructor(e, t, r,
|
|
1855
|
-
if (
|
|
1856
|
-
throw new
|
|
1857
|
-
super(e, t, r,
|
|
1896
|
+
class Be extends P {
|
|
1897
|
+
constructor(e, t, r, i = null) {
|
|
1898
|
+
if (i !== null && !(i instanceof C && i.every(E)))
|
|
1899
|
+
throw new M("BelongsToMany.constructor()", "Collection<Model> or null");
|
|
1900
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1858
1901
|
}
|
|
1859
1902
|
isSingle() {
|
|
1860
1903
|
return !1;
|
|
@@ -1892,10 +1935,10 @@ class oe extends j {
|
|
|
1892
1935
|
}
|
|
1893
1936
|
async attach(e, t = {}) {
|
|
1894
1937
|
if (await this.attachQuietly(e, t), this.items) {
|
|
1895
|
-
const r = this.items.search((
|
|
1896
|
-
if (!
|
|
1938
|
+
const r = this.items.search((s) => s.getKey() === e), i = await this.getRelated().find(e);
|
|
1939
|
+
if (!i)
|
|
1897
1940
|
return;
|
|
1898
|
-
r !== !1 ? this.items.put(r,
|
|
1941
|
+
r !== !1 ? this.items.put(r, i) : this.items.push(i);
|
|
1899
1942
|
} else
|
|
1900
1943
|
this.items = await this.all();
|
|
1901
1944
|
}
|
|
@@ -1955,24 +1998,24 @@ class oe extends j {
|
|
|
1955
1998
|
this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
|
|
1956
1999
|
}
|
|
1957
2000
|
}
|
|
1958
|
-
class
|
|
2001
|
+
class U extends P {
|
|
1959
2002
|
query() {
|
|
1960
2003
|
const e = super.query(), t = this.guessInverseRelation();
|
|
1961
2004
|
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
1962
2005
|
}
|
|
1963
2006
|
async saveQuietly(e) {
|
|
1964
|
-
if (!
|
|
1965
|
-
throw new
|
|
2007
|
+
if (!E(e))
|
|
2008
|
+
throw new M("HasOneOrMany.saveQuietly()");
|
|
1966
2009
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1967
|
-
throw new
|
|
2010
|
+
throw new I("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1968
2011
|
e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
|
|
1969
2012
|
}
|
|
1970
2013
|
}
|
|
1971
|
-
class
|
|
1972
|
-
constructor(e, t, r,
|
|
1973
|
-
if (!
|
|
1974
|
-
throw new
|
|
1975
|
-
super(e, t, r,
|
|
2014
|
+
class Ze extends U {
|
|
2015
|
+
constructor(e, t, r, i = null) {
|
|
2016
|
+
if (!E(i) && i !== null)
|
|
2017
|
+
throw new M("HasOne.constructor()", "Model or null");
|
|
2018
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1976
2019
|
}
|
|
1977
2020
|
isSingle() {
|
|
1978
2021
|
return !0;
|
|
@@ -1987,11 +2030,11 @@ class Ae extends H {
|
|
|
1987
2030
|
await this.saveQuietly(e), this.items = e;
|
|
1988
2031
|
}
|
|
1989
2032
|
}
|
|
1990
|
-
class
|
|
1991
|
-
constructor(e, t, r,
|
|
1992
|
-
if (
|
|
1993
|
-
throw new
|
|
1994
|
-
super(e, t, r,
|
|
2033
|
+
class ze extends U {
|
|
2034
|
+
constructor(e, t, r, i = null) {
|
|
2035
|
+
if (i !== null && !(i instanceof C && i.every(E)))
|
|
2036
|
+
throw new M("HasMany.constructor()", "Collection<Model> or null");
|
|
2037
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
1995
2038
|
}
|
|
1996
2039
|
isSingle() {
|
|
1997
2040
|
return !1;
|
|
@@ -2012,10 +2055,10 @@ class ve extends H {
|
|
|
2012
2055
|
return this.query().find(e);
|
|
2013
2056
|
}
|
|
2014
2057
|
async saveManyQuietly(e) {
|
|
2015
|
-
if (!Array.isArray(e) || !e.every(
|
|
2016
|
-
throw new
|
|
2058
|
+
if (!Array.isArray(e) || !e.every(E))
|
|
2059
|
+
throw new M("HasMany.saveManyQuietly()", "Model[]");
|
|
2017
2060
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
2018
|
-
throw new
|
|
2061
|
+
throw new I("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
2019
2062
|
await Promise.all(e.map((t) => (t.setAttribute(this.getForeignKey(), this.parent.getKey()), t.save())));
|
|
2020
2063
|
}
|
|
2021
2064
|
async saveMany(e) {
|
|
@@ -2027,7 +2070,7 @@ class ve extends H {
|
|
|
2027
2070
|
await this.saveQuietly(e), this.items === null ? this.items = await this.all() : this.items.push(e);
|
|
2028
2071
|
}
|
|
2029
2072
|
}
|
|
2030
|
-
class
|
|
2073
|
+
class qe extends U {
|
|
2031
2074
|
query() {
|
|
2032
2075
|
const e = this.getRelated().query();
|
|
2033
2076
|
e.once("success", (r) => {
|
|
@@ -2037,19 +2080,19 @@ class he extends H {
|
|
|
2037
2080
|
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
2081
|
}
|
|
2039
2082
|
async saveQuietly(e) {
|
|
2040
|
-
if (!
|
|
2041
|
-
throw new
|
|
2083
|
+
if (!E(e))
|
|
2084
|
+
throw new M("MorphOneOrMany.saveQuietly()");
|
|
2042
2085
|
if (e.getType() !== this.getRelated().getSchemaName())
|
|
2043
|
-
throw new
|
|
2086
|
+
throw new I("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
2044
2087
|
const t = this.guessInverseRelation();
|
|
2045
2088
|
e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
|
|
2046
2089
|
}
|
|
2047
2090
|
}
|
|
2048
|
-
class
|
|
2049
|
-
constructor(e, t, r,
|
|
2050
|
-
if (
|
|
2051
|
-
throw new
|
|
2052
|
-
super(e, t, r,
|
|
2091
|
+
class Oe extends qe {
|
|
2092
|
+
constructor(e, t, r, i = null) {
|
|
2093
|
+
if (i !== null && !(i instanceof C && i.every(E)))
|
|
2094
|
+
throw new M("MorphMany.constructor()", "Collection<Model> or null");
|
|
2095
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2053
2096
|
}
|
|
2054
2097
|
isSingle() {
|
|
2055
2098
|
return !1;
|
|
@@ -2070,10 +2113,10 @@ class Re extends he {
|
|
|
2070
2113
|
return this.query().find(e);
|
|
2071
2114
|
}
|
|
2072
2115
|
async saveManyQuietly(e) {
|
|
2073
|
-
if (!Array.isArray(e) || !e.every(
|
|
2074
|
-
throw new
|
|
2116
|
+
if (!Array.isArray(e) || !e.every(E))
|
|
2117
|
+
throw new M("MorphMany.saveManyQuietly()");
|
|
2075
2118
|
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
2076
|
-
throw new
|
|
2119
|
+
throw new I("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
2077
2120
|
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
2121
|
}
|
|
2079
2122
|
async save(e) {
|
|
@@ -2085,10 +2128,10 @@ class Re extends he {
|
|
|
2085
2128
|
this.items ? this.items.splice(0, this.items.count(), ...t) : this.items = t;
|
|
2086
2129
|
}
|
|
2087
2130
|
}
|
|
2088
|
-
class
|
|
2089
|
-
constructor(e, t, r,
|
|
2090
|
-
if (super(e, t, r,
|
|
2091
|
-
throw new
|
|
2131
|
+
class et extends qe {
|
|
2132
|
+
constructor(e, t, r, i = null) {
|
|
2133
|
+
if (super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i, i !== null && !E(i))
|
|
2134
|
+
throw new M("MorphOne.constructor()", "Model or null");
|
|
2092
2135
|
}
|
|
2093
2136
|
isSingle() {
|
|
2094
2137
|
return !0;
|
|
@@ -2103,7 +2146,7 @@ class Ne extends he {
|
|
|
2103
2146
|
await this.saveQuietly(e), this.items = e;
|
|
2104
2147
|
}
|
|
2105
2148
|
}
|
|
2106
|
-
class
|
|
2149
|
+
class tt extends Ne {
|
|
2107
2150
|
getRelated() {
|
|
2108
2151
|
return this.facades.model.make(
|
|
2109
2152
|
this.parent.getAttribute(this.getName() + "_type")
|
|
@@ -2118,8 +2161,8 @@ class Se extends ne {
|
|
|
2118
2161
|
// return super.query();
|
|
2119
2162
|
// }
|
|
2120
2163
|
async associate(e) {
|
|
2121
|
-
if (!
|
|
2122
|
-
throw new
|
|
2164
|
+
if (!E(e))
|
|
2165
|
+
throw new M("MorphTo.associate()");
|
|
2123
2166
|
return e.exists || await e.save(), this.parent.update({
|
|
2124
2167
|
[this.getName() + "_id"]: e.getKey(),
|
|
2125
2168
|
[this.getName() + "_type"]: e.getType()
|
|
@@ -2132,49 +2175,52 @@ class Se extends ne {
|
|
|
2132
2175
|
});
|
|
2133
2176
|
}
|
|
2134
2177
|
}
|
|
2135
|
-
class
|
|
2136
|
-
constructor(e, t, r,
|
|
2137
|
-
super(e, t, r,
|
|
2178
|
+
class rt extends Be {
|
|
2179
|
+
constructor(e, t, r, i = null) {
|
|
2180
|
+
super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
|
|
2138
2181
|
}
|
|
2139
2182
|
query() {
|
|
2140
2183
|
const e = super.query(), t = this.guessInverseRelation();
|
|
2141
2184
|
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
2185
|
}
|
|
2143
2186
|
}
|
|
2144
|
-
|
|
2187
|
+
var Me;
|
|
2188
|
+
Me = Symbol.toStringTag;
|
|
2189
|
+
class st {
|
|
2145
2190
|
constructor(e) {
|
|
2146
|
-
|
|
2191
|
+
m(this, "_models", {});
|
|
2192
|
+
m(this, Me, "ModelFacade");
|
|
2147
2193
|
this._schema = e;
|
|
2148
2194
|
}
|
|
2149
2195
|
boot(e) {
|
|
2150
2196
|
this._schema && (Object.keys(this._schema).forEach((t) => {
|
|
2151
|
-
const r = this[`model${
|
|
2197
|
+
const r = this[`model${d.upperFirst(d.camelCase(t))}`];
|
|
2152
2198
|
if (typeof this.model != "function" || typeof r != "function")
|
|
2153
|
-
throw new
|
|
2154
|
-
const
|
|
2155
|
-
|
|
2199
|
+
throw new $("ModelFacade");
|
|
2200
|
+
const i = this.model(
|
|
2201
|
+
Ve(e, t),
|
|
2156
2202
|
t
|
|
2157
|
-
),
|
|
2158
|
-
this._models[t] =
|
|
2203
|
+
), s = r(i);
|
|
2204
|
+
this._models[t] = Xe(e.make(), t, s);
|
|
2159
2205
|
}), this.reducer("relationMap", () => ({
|
|
2160
|
-
BelongsTo:
|
|
2161
|
-
BelongsToMany:
|
|
2162
|
-
HasOne:
|
|
2163
|
-
HasMany:
|
|
2164
|
-
MorphMany:
|
|
2165
|
-
MorphOne:
|
|
2166
|
-
MorphTo:
|
|
2167
|
-
MorphToMany:
|
|
2206
|
+
BelongsTo: Ne,
|
|
2207
|
+
BelongsToMany: Be,
|
|
2208
|
+
HasOne: Ze,
|
|
2209
|
+
HasMany: ze,
|
|
2210
|
+
MorphMany: Oe,
|
|
2211
|
+
MorphOne: et,
|
|
2212
|
+
MorphTo: tt,
|
|
2213
|
+
MorphToMany: rt
|
|
2168
2214
|
}), 0));
|
|
2169
2215
|
}
|
|
2170
2216
|
schema(e) {
|
|
2171
2217
|
if (!this._schema || e && !this._schema[e])
|
|
2172
|
-
throw new
|
|
2218
|
+
throw new V(e || "undefined");
|
|
2173
2219
|
return e ? this._schema[e] : this._schema;
|
|
2174
2220
|
}
|
|
2175
2221
|
make(e) {
|
|
2176
2222
|
if (e && !this._models[e])
|
|
2177
|
-
throw new
|
|
2223
|
+
throw new V(e);
|
|
2178
2224
|
return e ? this._models[e] : this._models;
|
|
2179
2225
|
}
|
|
2180
2226
|
toString() {
|
|
@@ -2182,68 +2228,68 @@ class ue {
|
|
|
2182
2228
|
}
|
|
2183
2229
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2184
2230
|
on(e, t) {
|
|
2185
|
-
throw new
|
|
2231
|
+
throw new b();
|
|
2186
2232
|
}
|
|
2187
2233
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2188
2234
|
once(e, t) {
|
|
2189
|
-
throw new
|
|
2235
|
+
throw new b();
|
|
2190
2236
|
}
|
|
2191
2237
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2192
2238
|
emit(e, t) {
|
|
2193
|
-
throw new
|
|
2239
|
+
throw new b();
|
|
2194
2240
|
}
|
|
2195
2241
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2196
2242
|
reducer(e, t, r) {
|
|
2197
|
-
throw new
|
|
2243
|
+
throw new b();
|
|
2198
2244
|
}
|
|
2199
2245
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2200
2246
|
removeReducer(e) {
|
|
2201
|
-
throw new
|
|
2247
|
+
throw new b();
|
|
2202
2248
|
}
|
|
2203
2249
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2204
2250
|
getReducer(e) {
|
|
2205
|
-
throw new
|
|
2251
|
+
throw new b();
|
|
2206
2252
|
}
|
|
2207
2253
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2208
2254
|
hasReducer(e) {
|
|
2209
|
-
throw new
|
|
2255
|
+
throw new b();
|
|
2210
2256
|
}
|
|
2211
2257
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2212
2258
|
clearReducer(e) {
|
|
2213
|
-
throw new
|
|
2259
|
+
throw new b();
|
|
2214
2260
|
}
|
|
2215
2261
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2216
2262
|
flushReducers() {
|
|
2217
|
-
throw new
|
|
2263
|
+
throw new b();
|
|
2218
2264
|
}
|
|
2219
2265
|
}
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
class
|
|
2266
|
+
const it = A(ve(st));
|
|
2267
|
+
var _e, Te;
|
|
2268
|
+
class nt extends (Te = Error, _e = Symbol.toStringTag, Te) {
|
|
2223
2269
|
constructor() {
|
|
2224
2270
|
super("[Luminix] Embed element not found. Make sure to include the `@luminixEmbed()` directive in your Blade template.");
|
|
2271
|
+
m(this, _e, "NoEmbedException");
|
|
2225
2272
|
}
|
|
2226
2273
|
}
|
|
2227
|
-
|
|
2228
|
-
const le = (n, e = "data") => {
|
|
2274
|
+
const Ie = (n, e = "data") => {
|
|
2229
2275
|
if (!document.querySelector("#luminix-embed"))
|
|
2230
|
-
throw new
|
|
2276
|
+
throw new nt();
|
|
2231
2277
|
const t = document.getElementById(`luminix-${e}::` + n);
|
|
2232
2278
|
return t ? t.dataset.json && t.dataset.value ? JSON.parse(t.dataset.value) : t.dataset.value : null;
|
|
2233
|
-
},
|
|
2234
|
-
let
|
|
2279
|
+
}, X = A(v), ot = (n) => Le(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;
|
|
2280
|
+
let ht = class {
|
|
2235
2281
|
constructor() {
|
|
2236
|
-
|
|
2282
|
+
m(this, "bags");
|
|
2237
2283
|
const e = {};
|
|
2238
2284
|
document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((r) => {
|
|
2239
|
-
const
|
|
2240
|
-
e[
|
|
2285
|
+
const s = r.id.replace("luminix-error::", "");
|
|
2286
|
+
e[s] = Ie(s, "error");
|
|
2241
2287
|
}), this.bags = {
|
|
2242
|
-
default: new
|
|
2288
|
+
default: new X(e)
|
|
2243
2289
|
};
|
|
2244
2290
|
}
|
|
2245
2291
|
bag(e = "default") {
|
|
2246
|
-
return this.bags[e] || (this.bags[e] = new
|
|
2292
|
+
return this.bags[e] || (this.bags[e] = new X({})), this.bags[e];
|
|
2247
2293
|
}
|
|
2248
2294
|
add(e, t, r = "default") {
|
|
2249
2295
|
this.bag(r).set(e, t);
|
|
@@ -2261,13 +2307,14 @@ let Ke = class {
|
|
|
2261
2307
|
this.bag(e).set(".", {});
|
|
2262
2308
|
}
|
|
2263
2309
|
};
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2310
|
+
var $e, Se;
|
|
2311
|
+
class ut extends (Se = Error, $e = Symbol.toStringTag, Se) {
|
|
2312
|
+
constructor(t) {
|
|
2313
|
+
super(`[Luminix] Route "${t}" not found`);
|
|
2314
|
+
m(this, $e, "RouteNotFoundException");
|
|
2267
2315
|
}
|
|
2268
2316
|
}
|
|
2269
|
-
|
|
2270
|
-
class je {
|
|
2317
|
+
class at {
|
|
2271
2318
|
constructor(e, t, r = "") {
|
|
2272
2319
|
this.routes = e, this.error = t, this.appUrl = r;
|
|
2273
2320
|
}
|
|
@@ -2277,8 +2324,8 @@ class je {
|
|
|
2277
2324
|
const [t, ...r] = e;
|
|
2278
2325
|
if (typeof t != "string")
|
|
2279
2326
|
return !1;
|
|
2280
|
-
const
|
|
2281
|
-
return !!r.every((
|
|
2327
|
+
const i = ["get", "post", "put", "patch", "delete"];
|
|
2328
|
+
return !!r.every((s) => i.includes(s));
|
|
2282
2329
|
}
|
|
2283
2330
|
extractGenerator(e) {
|
|
2284
2331
|
let t, r = !1;
|
|
@@ -2286,64 +2333,64 @@ class je {
|
|
|
2286
2333
|
}
|
|
2287
2334
|
get(e) {
|
|
2288
2335
|
if (!this.exists(e))
|
|
2289
|
-
throw new
|
|
2290
|
-
return
|
|
2336
|
+
throw new ut(e);
|
|
2337
|
+
return d.get(this.routes, e);
|
|
2291
2338
|
}
|
|
2292
2339
|
url(e) {
|
|
2293
|
-
const [t, r] = this.extractGenerator(e),
|
|
2340
|
+
const [t, r] = this.extractGenerator(e), i = this.get(t)[0].replace(/^\/|\/$/g, ""), s = /{([^}]+)}/g;
|
|
2294
2341
|
if (r === !1) {
|
|
2295
2342
|
if (typeof this.replaceRouteParams != "function")
|
|
2296
|
-
throw new
|
|
2297
|
-
return this.appUrl + this.replaceRouteParams(`/${
|
|
2343
|
+
throw new $("RouteFacade");
|
|
2344
|
+
return this.appUrl + this.replaceRouteParams(`/${i}`);
|
|
2298
2345
|
}
|
|
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 + `/${
|
|
2346
|
+
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));
|
|
2347
|
+
if (f.length > 0)
|
|
2348
|
+
throw new TypeError(`Missing values for parameter(s): ${f.join(", ")}`);
|
|
2349
|
+
if (p.length > 0)
|
|
2350
|
+
throw new TypeError(`Unexpected parameters: ${p.join(", ")}`);
|
|
2351
|
+
const w = l.reduce((x, _) => x.replace(`{${_}}`, `${r[_]}`), i);
|
|
2352
|
+
return this.appUrl + `/${w}`;
|
|
2306
2353
|
}
|
|
2307
2354
|
methods(e) {
|
|
2308
2355
|
const [t] = this.extractGenerator(e);
|
|
2309
2356
|
return this.get(t).slice(1);
|
|
2310
2357
|
}
|
|
2311
2358
|
exists(e) {
|
|
2312
|
-
return
|
|
2359
|
+
return d.has(this.routes, e) && this.isRouteTuple(d.get(this.routes, e));
|
|
2313
2360
|
}
|
|
2314
2361
|
async call(e, t = {}) {
|
|
2315
2362
|
if (typeof this.axiosOptions != "function" || typeof this.axiosError != "function")
|
|
2316
|
-
throw new
|
|
2317
|
-
const [r,
|
|
2318
|
-
this.error.clear(
|
|
2363
|
+
throw new $("RouteFacade");
|
|
2364
|
+
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;
|
|
2365
|
+
this.error.clear(f);
|
|
2319
2366
|
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:
|
|
2367
|
+
return ["get", "delete"].includes(a) ? await j[a](u, p) : await j[a](u, w, x);
|
|
2368
|
+
} catch (_) {
|
|
2369
|
+
if (ot(_)) {
|
|
2370
|
+
const { errors: F } = _.response.data;
|
|
2371
|
+
this.error.set(Object.entries(F).reduce((N, [y, Fe]) => (N[y] = Fe.join(" "), N), {}), f);
|
|
2372
|
+
} else j.isAxiosError(_) && this.error.set(
|
|
2373
|
+
this.axiosError({ axios: _.message }, {
|
|
2374
|
+
error: _,
|
|
2328
2375
|
name: r,
|
|
2329
|
-
replace:
|
|
2376
|
+
replace: i,
|
|
2330
2377
|
config: t
|
|
2331
2378
|
}),
|
|
2332
|
-
|
|
2379
|
+
f
|
|
2333
2380
|
);
|
|
2334
|
-
throw
|
|
2381
|
+
throw _;
|
|
2335
2382
|
}
|
|
2336
2383
|
}
|
|
2337
2384
|
toString() {
|
|
2338
2385
|
return "route";
|
|
2339
2386
|
}
|
|
2340
2387
|
}
|
|
2341
|
-
const
|
|
2342
|
-
class
|
|
2388
|
+
const lt = ve(at);
|
|
2389
|
+
class ct {
|
|
2343
2390
|
constructor() {
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2391
|
+
m(this, "facades", {});
|
|
2392
|
+
m(this, "booted", !1);
|
|
2393
|
+
m(this, "_plugins", []);
|
|
2347
2394
|
}
|
|
2348
2395
|
make(e = void 0) {
|
|
2349
2396
|
if (!e)
|
|
@@ -2361,41 +2408,67 @@ class Pe {
|
|
|
2361
2408
|
return this._plugins;
|
|
2362
2409
|
}
|
|
2363
2410
|
async boot(e = {}) {
|
|
2364
|
-
var
|
|
2411
|
+
var f, p, w, x, _, F, N;
|
|
2365
2412
|
if (this.booted)
|
|
2366
2413
|
throw new window.Error("[Luminix] App already booted");
|
|
2367
|
-
this.booted = !0, (
|
|
2368
|
-
register: (
|
|
2369
|
-
this._plugins.push(
|
|
2414
|
+
this.booted = !0, (f = e.app) != null && f.debug && console.log("[Luminix] Booting started..."), this.emit("init", {
|
|
2415
|
+
register: (y) => {
|
|
2416
|
+
this._plugins.push(y), typeof y.register == "function" && y.register(this);
|
|
2370
2417
|
}
|
|
2371
2418
|
});
|
|
2372
|
-
const t = (((
|
|
2373
|
-
if (
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2419
|
+
const t = (((p = e.app) == null ? void 0 : p.url) ?? "") + (((w = e.app) == null ? void 0 : w.bootUrl) ?? "/luminix-api/init");
|
|
2420
|
+
if (document.getElementById("luminix-data::config")) {
|
|
2421
|
+
if (document.getElementById("luminix-data::config")) {
|
|
2422
|
+
const y = Ie("config");
|
|
2423
|
+
y && typeof y == "object" && d.merge(e, y);
|
|
2424
|
+
}
|
|
2425
|
+
} else try {
|
|
2426
|
+
const { data: y } = await j.get(t);
|
|
2427
|
+
y && typeof y == "object" && d.merge(e, y);
|
|
2428
|
+
} catch (y) {
|
|
2429
|
+
(x = e.app) != null && x.debug && console.error(y);
|
|
2430
|
+
}
|
|
2431
|
+
this.bind("log", new Ce(!!((_ = e.app) != null && _.debug)));
|
|
2381
2432
|
const { log: r } = this.facades, {
|
|
2382
|
-
manifest: { routes:
|
|
2433
|
+
manifest: { routes: i = {}, models: s = {} } = {},
|
|
2383
2434
|
...u
|
|
2384
2435
|
} = e;
|
|
2385
|
-
this.bind("config", new v(u)), this.facades.config.has("auth.user") || this.facades.config.set("auth.user", null), this.facades.config.lock("auth.user")
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
for (const
|
|
2389
|
-
typeof
|
|
2436
|
+
this.bind("config", new v(u)), this.facades.config.has("auth.user") || this.facades.config.set("auth.user", null), this.facades.config.lock("auth.user");
|
|
2437
|
+
const l = new URL(((F = e.app) == null ? void 0 : F.url) ?? "http://localhost"), a = ((N = e.app) == null ? void 0 : N.port) ?? "";
|
|
2438
|
+
a && (l.port = `${a}`), this.bind("error", new ht()), this.bind("route", new lt(i, this.facades.error, d.trim(l.toString(), "/"))), this.bind("model", new it(s)), this.bind("auth", new Qe(this)), this.emit("booting");
|
|
2439
|
+
for (const y of Object.values(this.facades))
|
|
2440
|
+
typeof y == "object" && y !== null && "boot" in y && typeof y.boot == "function" && y.boot(this);
|
|
2441
|
+
for (const y of this._plugins)
|
|
2442
|
+
typeof y.boot == "function" && y.boot(this.facades);
|
|
2390
2443
|
return r.info("[Luminix] App boot completed", {
|
|
2391
2444
|
config: this.facades.config.all(),
|
|
2392
2445
|
plugins: this._plugins,
|
|
2393
2446
|
manifest: {
|
|
2394
|
-
routes:
|
|
2395
|
-
models:
|
|
2447
|
+
routes: i,
|
|
2448
|
+
models: s
|
|
2396
2449
|
}
|
|
2397
2450
|
}), this.emit("booted"), this.facades;
|
|
2398
2451
|
}
|
|
2452
|
+
environment(...e) {
|
|
2453
|
+
return e.length > 0 ? e.includes(this.facades.config.get("app.env", "production")) : this.facades.config.get("app.env", "production");
|
|
2454
|
+
}
|
|
2455
|
+
getLocale() {
|
|
2456
|
+
return this.facades.config.get("app.locale", "en");
|
|
2457
|
+
}
|
|
2458
|
+
getPlugin(e) {
|
|
2459
|
+
for (const t of this._plugins)
|
|
2460
|
+
if (t instanceof e)
|
|
2461
|
+
return t;
|
|
2462
|
+
}
|
|
2463
|
+
hasDebugModeEnabled() {
|
|
2464
|
+
return this.facades.config.get("app.debug", !1);
|
|
2465
|
+
}
|
|
2466
|
+
isLocal() {
|
|
2467
|
+
return this.facades.config.get("app.env", "production") === "local";
|
|
2468
|
+
}
|
|
2469
|
+
isProduction() {
|
|
2470
|
+
return this.facades.config.get("app.env", "production") === "production";
|
|
2471
|
+
}
|
|
2399
2472
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2400
2473
|
on(e, t) {
|
|
2401
2474
|
throw new window.Error("Method not implemented.");
|
|
@@ -2409,49 +2482,56 @@ class Pe {
|
|
|
2409
2482
|
throw new window.Error("Method not implemented.");
|
|
2410
2483
|
}
|
|
2411
2484
|
}
|
|
2412
|
-
const
|
|
2413
|
-
let
|
|
2485
|
+
const dt = A(ct);
|
|
2486
|
+
let g;
|
|
2414
2487
|
function R(n = void 0) {
|
|
2415
|
-
if (
|
|
2488
|
+
if (g || (g = new dt()), typeof n != "string")
|
|
2416
2489
|
return {
|
|
2417
|
-
boot:
|
|
2418
|
-
make:
|
|
2419
|
-
plugins:
|
|
2420
|
-
on:
|
|
2490
|
+
boot: g.boot.bind(g),
|
|
2491
|
+
make: g.make.bind(g),
|
|
2492
|
+
plugins: g.plugins.bind(g),
|
|
2493
|
+
on: g.once.bind(g),
|
|
2494
|
+
environment: g.environment.bind(g),
|
|
2495
|
+
getLocale: g.getLocale.bind(g),
|
|
2496
|
+
getPlugin: g.getPlugin.bind(g),
|
|
2497
|
+
hasDebugModeEnabled: g.hasDebugModeEnabled.bind(g),
|
|
2498
|
+
isLocal: g.isLocal.bind(g),
|
|
2499
|
+
isProduction: g.isProduction.bind(g),
|
|
2500
|
+
setInstance: (e) => g = e
|
|
2421
2501
|
};
|
|
2422
|
-
if (!
|
|
2423
|
-
throw new
|
|
2424
|
-
return
|
|
2502
|
+
if (!g.has(n))
|
|
2503
|
+
throw new ke(n);
|
|
2504
|
+
return g.make(n);
|
|
2425
2505
|
}
|
|
2426
|
-
function
|
|
2506
|
+
function bt() {
|
|
2427
2507
|
return R("auth");
|
|
2428
2508
|
}
|
|
2429
|
-
function
|
|
2430
|
-
return
|
|
2509
|
+
function Et(n) {
|
|
2510
|
+
return c(n);
|
|
2431
2511
|
}
|
|
2432
|
-
function
|
|
2512
|
+
function xt(n, e) {
|
|
2433
2513
|
const t = R("config");
|
|
2434
2514
|
return typeof n > "u" ? t : t.get(n, e);
|
|
2435
2515
|
}
|
|
2436
|
-
function
|
|
2516
|
+
function Mt(n, e = "default") {
|
|
2437
2517
|
return n ? R().make("error").get(n, e) : R().make("error");
|
|
2438
2518
|
}
|
|
2439
|
-
function
|
|
2519
|
+
function _t(...n) {
|
|
2440
2520
|
const e = R("log");
|
|
2441
2521
|
return n.length ? e.debug(...n) : e;
|
|
2442
2522
|
}
|
|
2443
|
-
function
|
|
2523
|
+
function Tt(n) {
|
|
2444
2524
|
const e = R("model");
|
|
2445
2525
|
return n ? e.make(n) : e;
|
|
2446
2526
|
}
|
|
2447
|
-
function
|
|
2527
|
+
function $t(n, e = !1) {
|
|
2448
2528
|
const t = R("route");
|
|
2449
2529
|
return n ? e ? t.url([n, e]) : t.url(n) : t;
|
|
2450
2530
|
}
|
|
2451
|
-
class
|
|
2531
|
+
class St {
|
|
2452
2532
|
constructor() {
|
|
2453
|
-
|
|
2454
|
-
|
|
2533
|
+
m(this, "name");
|
|
2534
|
+
m(this, "version");
|
|
2455
2535
|
}
|
|
2456
2536
|
register(e) {
|
|
2457
2537
|
}
|
|
@@ -2459,19 +2539,20 @@ class Oe {
|
|
|
2459
2539
|
}
|
|
2460
2540
|
}
|
|
2461
2541
|
export {
|
|
2542
|
+
dt as App,
|
|
2462
2543
|
A as HasEvents,
|
|
2463
|
-
|
|
2544
|
+
St as Plugin,
|
|
2464
2545
|
v as PropertyBag,
|
|
2465
|
-
|
|
2546
|
+
ve as Reducible,
|
|
2466
2547
|
R as app,
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2548
|
+
bt as auth,
|
|
2549
|
+
Et as collect,
|
|
2550
|
+
xt as config,
|
|
2551
|
+
Mt as error,
|
|
2552
|
+
S as isCollection,
|
|
2553
|
+
E as isModel,
|
|
2554
|
+
ot as isValidationError,
|
|
2555
|
+
_t as log,
|
|
2556
|
+
Tt as model,
|
|
2557
|
+
$t as route
|
|
2477
2558
|
};
|