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