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