@luminix/core 0.3.8 → 0.4.0
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/babel.config.json +5 -0
- package/dist/core.js +711 -704
- package/package.json +9 -3
- package/types/contracts/Builder.d.ts +2 -2
- package/types/contracts/Relation/BelongsToMany.d.ts +3 -3
- package/types/contracts/Relation/HasMany.d.ts +2 -1
- package/types/contracts/Relation/MorphMany.d.ts +3 -2
- package/types/types/Builder.d.ts +5 -1
- package/types/types/Model.d.ts +2 -1
package/dist/core.js
CHANGED
|
@@ -1,340 +1,344 @@
|
|
|
1
1
|
var le = Object.defineProperty;
|
|
2
|
-
var ce = (o,
|
|
3
|
-
var p = (o,
|
|
4
|
-
import { reader as de, PropertyBag as _, EventSource as A, Collection as b, Query as S, Obj as d, Str as
|
|
2
|
+
var ce = (o, e, t) => e in o ? le(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var p = (o, e, t) => ce(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { reader as de, PropertyBag as _, EventSource as A, Collection as b, Query as S, Obj as d, Str as y, Reducible as re, isValidationError as pe, Macroable as ne, Client as ge, ServiceProvider as ye, MakeFacade as M, Application as me, Response as fe } from "@luminix/support";
|
|
5
5
|
class we {
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(e, t, r) {
|
|
7
7
|
p(this, "_user");
|
|
8
|
-
this.config =
|
|
8
|
+
this.config = e, this.model = t, this.route = r;
|
|
9
9
|
}
|
|
10
|
-
attempt(
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
if (typeof
|
|
10
|
+
attempt(e, t = !1, r) {
|
|
11
|
+
const i = document.createElement("form");
|
|
12
|
+
i.method = "post", i.action = this.route.url("login"), i.style.display = "none";
|
|
13
|
+
const l = this.config.get("auth.csrf");
|
|
14
|
+
if (typeof l == "string") {
|
|
15
15
|
const u = document.createElement("input");
|
|
16
|
-
u.type = "hidden", u.name = "_token", u.value =
|
|
16
|
+
u.type = "hidden", u.name = "_token", u.value = l, i.appendChild(u);
|
|
17
17
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
18
|
+
const m = document.createElement("input");
|
|
19
|
+
m.type = "email", m.name = "email", m.value = e.email, i.appendChild(m);
|
|
20
|
+
const c = document.createElement("input");
|
|
21
|
+
if (c.type = "password", c.name = "password", c.value = e.password, i.appendChild(c), t) {
|
|
22
22
|
const u = document.createElement("input");
|
|
23
|
-
u.type = "checkbox", u.name = "remember", u.value = "1", u.checked = !0,
|
|
23
|
+
u.type = "checkbox", u.name = "remember", u.value = "1", u.checked = !0, i.appendChild(u);
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
r && i.addEventListener("submit", r), document.body.appendChild(i), i.submit();
|
|
26
26
|
}
|
|
27
27
|
check() {
|
|
28
28
|
return !!this.config.get("auth.user");
|
|
29
29
|
}
|
|
30
|
-
logout(
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
if (typeof
|
|
35
|
-
const
|
|
36
|
-
|
|
30
|
+
logout(e) {
|
|
31
|
+
const t = document.createElement("form");
|
|
32
|
+
t.method = "post", t.action = this.route.url("logout"), t.style.display = "none";
|
|
33
|
+
const r = this.config.get("auth.csrf");
|
|
34
|
+
if (typeof r == "string") {
|
|
35
|
+
const i = document.createElement("input");
|
|
36
|
+
i.type = "hidden", i.name = "_token", i.value = r, t.appendChild(i);
|
|
37
37
|
}
|
|
38
|
-
document.body.appendChild(
|
|
38
|
+
document.body.appendChild(t), e && t.addEventListener("submit", e), t.submit();
|
|
39
39
|
}
|
|
40
40
|
user() {
|
|
41
41
|
if (!this._user) {
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
42
|
+
const e = this.model.make("user"), t = this.config.get("auth.user");
|
|
43
|
+
if (!t)
|
|
44
44
|
return;
|
|
45
|
-
this._user = new t
|
|
45
|
+
this._user = new e(t);
|
|
46
46
|
}
|
|
47
47
|
return this._user;
|
|
48
48
|
}
|
|
49
49
|
id() {
|
|
50
|
-
var
|
|
51
|
-
return ((
|
|
50
|
+
var e;
|
|
51
|
+
return ((e = this.user()) == null ? void 0 : e.getKey()) || null;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
class ve {
|
|
55
55
|
constructor() {
|
|
56
56
|
p(this, "bags");
|
|
57
|
-
const
|
|
58
|
-
document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((
|
|
59
|
-
const
|
|
60
|
-
|
|
57
|
+
const e = {};
|
|
58
|
+
document.querySelectorAll('#luminix-embed [id^="luminix-error"]').forEach((r) => {
|
|
59
|
+
const l = r.id.replace("luminix-error::", "");
|
|
60
|
+
e[l] = de(l, "error");
|
|
61
61
|
}), this.bags = {
|
|
62
|
-
default: new _(
|
|
62
|
+
default: new _(e)
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
bag(
|
|
66
|
-
return this.bags[
|
|
65
|
+
bag(e = "default") {
|
|
66
|
+
return this.bags[e] || (this.bags[e] = new _({})), this.bags[e];
|
|
67
67
|
}
|
|
68
|
-
add(
|
|
69
|
-
this.bag(
|
|
68
|
+
add(e, t, r = "default") {
|
|
69
|
+
this.bag(r).set(e, t);
|
|
70
70
|
}
|
|
71
|
-
set(
|
|
72
|
-
this.bag(
|
|
71
|
+
set(e, t = "default") {
|
|
72
|
+
this.bag(t).set(".", e);
|
|
73
73
|
}
|
|
74
|
-
all(
|
|
75
|
-
return this.bag(
|
|
74
|
+
all(e = "default") {
|
|
75
|
+
return this.bag(e).all();
|
|
76
76
|
}
|
|
77
|
-
get(
|
|
78
|
-
return this.bag(
|
|
77
|
+
get(e, t = "default") {
|
|
78
|
+
return this.bag(t).get(e, null);
|
|
79
79
|
}
|
|
80
|
-
clear(
|
|
81
|
-
this.bag(
|
|
80
|
+
clear(e = "default") {
|
|
81
|
+
this.bag(e).set(".", {});
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
class be {
|
|
85
|
-
constructor(
|
|
86
|
-
this._debug =
|
|
85
|
+
constructor(e) {
|
|
86
|
+
this._debug = e;
|
|
87
87
|
}
|
|
88
|
-
emergency(...
|
|
89
|
-
this._debug && console.error(...
|
|
88
|
+
emergency(...e) {
|
|
89
|
+
this._debug && console.error(...e);
|
|
90
90
|
}
|
|
91
|
-
alert(...
|
|
92
|
-
this._debug && console.error(...
|
|
91
|
+
alert(...e) {
|
|
92
|
+
this._debug && console.error(...e);
|
|
93
93
|
}
|
|
94
|
-
critical(...
|
|
95
|
-
this._debug && console.error(...
|
|
94
|
+
critical(...e) {
|
|
95
|
+
this._debug && console.error(...e);
|
|
96
96
|
}
|
|
97
|
-
error(...
|
|
98
|
-
this._debug && console.error(...
|
|
97
|
+
error(...e) {
|
|
98
|
+
this._debug && console.error(...e);
|
|
99
99
|
}
|
|
100
|
-
warning(...
|
|
101
|
-
this._debug && console.warn(...
|
|
100
|
+
warning(...e) {
|
|
101
|
+
this._debug && console.warn(...e);
|
|
102
102
|
}
|
|
103
|
-
notice(...
|
|
104
|
-
this._debug && console.info(...
|
|
103
|
+
notice(...e) {
|
|
104
|
+
this._debug && console.info(...e);
|
|
105
105
|
}
|
|
106
|
-
info(...
|
|
107
|
-
this._debug && console.info(...
|
|
106
|
+
info(...e) {
|
|
107
|
+
this._debug && console.info(...e);
|
|
108
108
|
}
|
|
109
|
-
debug(...
|
|
110
|
-
this._debug && console.debug(...
|
|
109
|
+
debug(...e) {
|
|
110
|
+
this._debug && console.debug(...e);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
var j, O;
|
|
114
114
|
class xe extends (O = Error, j = Symbol.toStringTag, O) {
|
|
115
|
-
constructor(
|
|
116
|
-
super(`[Luminix] Model "${
|
|
115
|
+
constructor(t) {
|
|
116
|
+
super(`[Luminix] Model "${t}" does not have a primary key`);
|
|
117
117
|
p(this, j, "ModelWithoutPrimaryKeyException");
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
class Me extends A {
|
|
121
|
-
constructor(
|
|
121
|
+
constructor(t, r, i = {}) {
|
|
122
122
|
super();
|
|
123
123
|
p(this, "bag");
|
|
124
|
-
this.services =
|
|
124
|
+
this.services = t, this.abstract = r, this.bag = new _(i), this.bag.on("change", () => {
|
|
125
125
|
this.emit("change", {
|
|
126
126
|
data: this.bag,
|
|
127
127
|
source: this
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
lock(
|
|
132
|
-
this.bag.lock(
|
|
131
|
+
lock(t) {
|
|
132
|
+
this.bag.lock(t);
|
|
133
133
|
}
|
|
134
|
-
whereBetween(
|
|
135
|
-
return this.where(
|
|
134
|
+
whereBetween(t, r) {
|
|
135
|
+
return this.where(t, "between", r);
|
|
136
136
|
}
|
|
137
|
-
whereNotBetween(
|
|
138
|
-
return this.where(
|
|
137
|
+
whereNotBetween(t, r) {
|
|
138
|
+
return this.where(t, "notBetween", r);
|
|
139
139
|
}
|
|
140
|
-
whereNull(
|
|
141
|
-
return this.where(
|
|
140
|
+
whereNull(t) {
|
|
141
|
+
return this.where(t, "null", null);
|
|
142
142
|
}
|
|
143
|
-
whereNotNull(
|
|
144
|
-
return this.where(
|
|
143
|
+
whereNotNull(t) {
|
|
144
|
+
return this.where(t, "notNull", null);
|
|
145
145
|
}
|
|
146
|
-
limit(
|
|
147
|
-
return this.bag.set("per_page",
|
|
148
|
-
}
|
|
149
|
-
where(
|
|
150
|
-
if (this.bag.has("where") || this.bag.set("where", {}), typeof
|
|
151
|
-
return
|
|
152
|
-
if (typeof
|
|
153
|
-
return this.bag.set(`where.${
|
|
154
|
-
if (typeof
|
|
155
|
-
throw new Error(`Invalid operator ${
|
|
156
|
-
const
|
|
146
|
+
limit(t) {
|
|
147
|
+
return this.bag.set("per_page", t), this;
|
|
148
|
+
}
|
|
149
|
+
where(t, r, i) {
|
|
150
|
+
if (this.bag.has("where") || this.bag.set("where", {}), typeof t == "function")
|
|
151
|
+
return t(this) || this;
|
|
152
|
+
if (typeof i > "u")
|
|
153
|
+
return this.bag.set(`where.${t}`, r), this;
|
|
154
|
+
if (typeof r != "string")
|
|
155
|
+
throw new Error(`Invalid operator ${r} provided for where clause.`);
|
|
156
|
+
const m = {
|
|
157
157
|
"=": "",
|
|
158
158
|
"!=": "notEquals",
|
|
159
159
|
">": "greaterThan",
|
|
160
160
|
">=": "greaterThanOrEquals",
|
|
161
161
|
"<": "lessThan",
|
|
162
162
|
"<=": "lessThanOrEquals"
|
|
163
|
-
}[
|
|
164
|
-
return this.bag.set(`where.${
|
|
163
|
+
}[r] || r;
|
|
164
|
+
return this.bag.set(`where.${t}:${m}`, i), this;
|
|
165
165
|
}
|
|
166
|
-
with(
|
|
167
|
-
const
|
|
168
|
-
return (Array.isArray(
|
|
169
|
-
|
|
170
|
-
}), this.bag.set("with",
|
|
166
|
+
with(t) {
|
|
167
|
+
const r = this.bag.get("with", []);
|
|
168
|
+
return (Array.isArray(t) ? t : [t]).forEach((l) => {
|
|
169
|
+
r.includes(l) || r.push(l);
|
|
170
|
+
}), this.bag.set("with", r), this;
|
|
171
171
|
}
|
|
172
|
-
withOnly(
|
|
173
|
-
return this.bag.set("with", Array.isArray(
|
|
172
|
+
withOnly(t) {
|
|
173
|
+
return this.bag.set("with", Array.isArray(t) ? t : [t]), this;
|
|
174
174
|
}
|
|
175
|
-
without(
|
|
176
|
-
const
|
|
177
|
-
return (Array.isArray(
|
|
178
|
-
|
|
179
|
-
}), this.bag.set("with",
|
|
175
|
+
without(t) {
|
|
176
|
+
const r = this.bag.get("with", []);
|
|
177
|
+
return (Array.isArray(t) ? t : [t]).forEach((l) => {
|
|
178
|
+
r.includes(l) && r.splice(r.indexOf(l), 1);
|
|
179
|
+
}), this.bag.set("with", r), this;
|
|
180
180
|
}
|
|
181
|
-
orderBy(
|
|
182
|
-
return this.bag.set("order_by", `${
|
|
181
|
+
orderBy(t, r = "asc") {
|
|
182
|
+
return this.bag.set("order_by", `${t}:${r}`), this;
|
|
183
183
|
}
|
|
184
|
-
searchBy(
|
|
185
|
-
return this.bag.set("q",
|
|
184
|
+
searchBy(t) {
|
|
185
|
+
return this.bag.set("q", t), this;
|
|
186
186
|
}
|
|
187
187
|
minified() {
|
|
188
188
|
return this.bag.set("minified", 1), this;
|
|
189
189
|
}
|
|
190
|
-
unset(
|
|
191
|
-
return this.bag.delete(
|
|
190
|
+
unset(t) {
|
|
191
|
+
return this.bag.delete(t), this;
|
|
192
192
|
}
|
|
193
|
-
include(
|
|
194
|
-
for (const [
|
|
195
|
-
this.bag.set(
|
|
193
|
+
include(t) {
|
|
194
|
+
for (const [r, i] of t.entries())
|
|
195
|
+
this.bag.set(r, i);
|
|
196
196
|
return this;
|
|
197
197
|
}
|
|
198
|
-
async exec(
|
|
198
|
+
async exec(t = {}) {
|
|
199
199
|
try {
|
|
200
|
-
|
|
200
|
+
const {
|
|
201
|
+
page: r = 1,
|
|
202
|
+
replaceLinks: i = !1
|
|
203
|
+
} = t;
|
|
204
|
+
this.bag.set("page", r), this.emit("submit", {
|
|
201
205
|
data: this.bag,
|
|
202
206
|
source: this
|
|
203
207
|
});
|
|
204
|
-
const
|
|
208
|
+
const l = await this.services.route.call(
|
|
205
209
|
`luminix.${this.abstract}.index`,
|
|
206
|
-
(
|
|
207
|
-
),
|
|
208
|
-
const
|
|
209
|
-
return
|
|
210
|
+
(u) => u.withQueryParameters(this.bag.all())
|
|
211
|
+
), m = this.services.model.make(this.abstract), c = new b(l.json("data").map((u) => {
|
|
212
|
+
const s = new m(u);
|
|
213
|
+
return s.exists = !0, this.services.model.emit("fetch", {
|
|
210
214
|
class: this.abstract,
|
|
211
|
-
model:
|
|
215
|
+
model: s,
|
|
212
216
|
source: this.services.model
|
|
213
|
-
}),
|
|
217
|
+
}), s;
|
|
214
218
|
}));
|
|
215
219
|
if (i) {
|
|
216
|
-
const [
|
|
220
|
+
const u = window.location.href, [s] = u.split("?");
|
|
217
221
|
return {
|
|
218
|
-
...
|
|
219
|
-
data:
|
|
222
|
+
...l.json(),
|
|
223
|
+
data: c,
|
|
220
224
|
links: {
|
|
221
|
-
first: `${
|
|
222
|
-
last: `${
|
|
223
|
-
next:
|
|
224
|
-
prev:
|
|
225
|
+
first: `${s}?${S.merge(u, l.json("links").first).toString()}`,
|
|
226
|
+
last: `${s}?${S.merge(u, l.json("links").last).toString()}`,
|
|
227
|
+
next: l.json("links").next && `${s}?${S.merge(u, l.json("links").next ?? "").toString()}`,
|
|
228
|
+
prev: l.json("links").prev && `${s}?${S.merge(u, l.json("links").prev ?? "").toString()}`
|
|
225
229
|
},
|
|
226
230
|
meta: {
|
|
227
|
-
...
|
|
228
|
-
links:
|
|
229
|
-
...
|
|
230
|
-
url:
|
|
231
|
+
...l.json("meta"),
|
|
232
|
+
links: l.json("meta").links.map((n) => ({
|
|
233
|
+
...n,
|
|
234
|
+
url: n.url && `${s}?${S.merge(u, n.url).toString()}`
|
|
231
235
|
}))
|
|
232
236
|
}
|
|
233
237
|
};
|
|
234
238
|
}
|
|
235
239
|
return {
|
|
236
|
-
...
|
|
237
|
-
data:
|
|
240
|
+
...l.json(),
|
|
241
|
+
data: c
|
|
238
242
|
};
|
|
239
|
-
} catch (
|
|
243
|
+
} catch (r) {
|
|
240
244
|
throw this.emit("error", {
|
|
241
|
-
error:
|
|
245
|
+
error: r,
|
|
242
246
|
source: this
|
|
243
|
-
}),
|
|
247
|
+
}), r;
|
|
244
248
|
}
|
|
245
249
|
}
|
|
246
|
-
async get(
|
|
247
|
-
const
|
|
250
|
+
async get(t = {}) {
|
|
251
|
+
const r = await this.exec(t);
|
|
248
252
|
return this.emit("success", {
|
|
249
|
-
response:
|
|
250
|
-
items:
|
|
253
|
+
response: r,
|
|
254
|
+
items: r.data,
|
|
251
255
|
source: this
|
|
252
|
-
}),
|
|
256
|
+
}), r;
|
|
253
257
|
}
|
|
254
258
|
async first() {
|
|
255
|
-
const
|
|
259
|
+
const t = await this.limit(1).exec();
|
|
256
260
|
return this.emit("success", {
|
|
257
|
-
response:
|
|
258
|
-
items:
|
|
261
|
+
response: t,
|
|
262
|
+
items: t.data.first(),
|
|
259
263
|
source: this
|
|
260
|
-
}),
|
|
264
|
+
}), t.data.first();
|
|
261
265
|
}
|
|
262
|
-
async find(
|
|
263
|
-
const
|
|
264
|
-
if (!
|
|
266
|
+
async find(t) {
|
|
267
|
+
const r = this.services.model.schema(this.abstract).primaryKey;
|
|
268
|
+
if (!r)
|
|
265
269
|
throw new xe(this.abstract);
|
|
266
|
-
const
|
|
270
|
+
const i = await this.where(r, t).limit(1).exec();
|
|
267
271
|
return this.emit("success", {
|
|
268
|
-
response:
|
|
269
|
-
items:
|
|
272
|
+
response: i,
|
|
273
|
+
items: i.data.sole(),
|
|
270
274
|
source: this
|
|
271
|
-
}),
|
|
275
|
+
}), i.data.sole();
|
|
272
276
|
}
|
|
273
277
|
async all() {
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
276
|
-
return
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
),
|
|
280
|
-
|
|
278
|
+
const t = this.services.config.get("luminix.backend.api.max_per_page", 150), r = await this.limit(t).exec(), i = r.meta.last_page;
|
|
279
|
+
if (i === 1)
|
|
280
|
+
return r.data;
|
|
281
|
+
const l = Array.from({ length: i - 1 }, (u, s) => s + 2), m = await Promise.all(
|
|
282
|
+
l.map((u) => this.limit(t).exec({ page: u }))
|
|
283
|
+
), c = new b(
|
|
284
|
+
m.reduce((u, s) => (u.push(...s.data), u), r.data).all()
|
|
281
285
|
);
|
|
282
286
|
return this.emit("success", {
|
|
283
287
|
response: {
|
|
284
|
-
...
|
|
285
|
-
data:
|
|
288
|
+
...r,
|
|
289
|
+
data: c
|
|
286
290
|
},
|
|
287
|
-
items:
|
|
291
|
+
items: c,
|
|
288
292
|
source: this
|
|
289
|
-
}),
|
|
293
|
+
}), c;
|
|
290
294
|
}
|
|
291
295
|
}
|
|
292
296
|
var B, C;
|
|
293
297
|
class f extends (C = TypeError, B = Symbol.toStringTag, C) {
|
|
294
|
-
constructor(
|
|
295
|
-
super(`[Luminix] "${
|
|
298
|
+
constructor(t, r = "Model") {
|
|
299
|
+
super(`[Luminix] "${t}" expects ${r}`);
|
|
296
300
|
p(this, B, "NotModelException");
|
|
297
301
|
}
|
|
298
302
|
}
|
|
299
303
|
var I, P;
|
|
300
304
|
class Ee extends (P = Error, I = Symbol.toStringTag, P) {
|
|
301
|
-
constructor(
|
|
302
|
-
super(`[Luminix] Could not determine inverse relation for "${
|
|
305
|
+
constructor(t, r, i, l) {
|
|
306
|
+
super(`[Luminix] Could not determine inverse relation for "${r}" in model "${t}". Please specify a relation in model "${i}" of type ${l} that points back to "${t}".`);
|
|
303
307
|
p(this, I, "NoInverseRelationException");
|
|
304
308
|
}
|
|
305
309
|
}
|
|
306
|
-
var Q,
|
|
307
|
-
class $e extends (
|
|
308
|
-
constructor(
|
|
309
|
-
super(`[Luminix] Relation "${
|
|
310
|
+
var Q, L;
|
|
311
|
+
class $e extends (L = Error, Q = Symbol.toStringTag, L) {
|
|
312
|
+
constructor(t) {
|
|
313
|
+
super(`[Luminix] Relation "${t}" is not supported`);
|
|
310
314
|
p(this, Q, "UnsupportedRelationException");
|
|
311
315
|
}
|
|
312
316
|
}
|
|
313
317
|
class R {
|
|
314
|
-
constructor(t,
|
|
318
|
+
constructor(e, t, r, i = null) {
|
|
315
319
|
p(this, "unsubscribeQuery", null);
|
|
316
|
-
if (this.services =
|
|
320
|
+
if (this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !d.isModel(i) && !(i instanceof b && i.every(d.isModel)))
|
|
317
321
|
throw new f("Relation.constructor()", "Model, Collection<Model> or null");
|
|
318
322
|
}
|
|
319
|
-
make(
|
|
320
|
-
const
|
|
321
|
-
if (
|
|
323
|
+
make(e) {
|
|
324
|
+
const t = this.getRelated();
|
|
325
|
+
if (e === null || typeof e > "u") {
|
|
322
326
|
this.set(null);
|
|
323
327
|
return;
|
|
324
328
|
}
|
|
325
329
|
if (this.isSingle()) {
|
|
326
|
-
if (typeof
|
|
330
|
+
if (typeof e != "object" || Array.isArray(e))
|
|
327
331
|
throw new TypeError("Relation.make() expects an object");
|
|
328
|
-
this.set(new e
|
|
332
|
+
this.set(new t(e));
|
|
329
333
|
}
|
|
330
334
|
if (this.isMultiple()) {
|
|
331
|
-
if (!Array.isArray(
|
|
335
|
+
if (!Array.isArray(e))
|
|
332
336
|
throw new TypeError("Relation.make() expects an array");
|
|
333
|
-
this.set(new b(
|
|
337
|
+
this.set(new b(e.map((r) => new t(r))));
|
|
334
338
|
}
|
|
335
339
|
}
|
|
336
340
|
guessInverseRelation() {
|
|
337
|
-
const { relations:
|
|
341
|
+
const { relations: e } = this.getRelated().getSchema(), t = this.getType(), r = this.services.model.guessInverseRelation({
|
|
338
342
|
HasOne: ["BelongsTo"],
|
|
339
343
|
HasMany: ["BelongsTo"],
|
|
340
344
|
BelongsTo: ["HasOne", "HasMany"],
|
|
@@ -343,20 +347,20 @@ class R {
|
|
|
343
347
|
MorphOne: ["MorphTo"],
|
|
344
348
|
MorphMany: ["MorphTo"],
|
|
345
349
|
MorphToMany: ["MorphToMany"]
|
|
346
|
-
}, this.parent,
|
|
347
|
-
if (!(
|
|
348
|
-
throw new $e(
|
|
349
|
-
for (const
|
|
350
|
-
const
|
|
351
|
-
if ((
|
|
352
|
-
return
|
|
353
|
-
}
|
|
354
|
-
throw new Ee(this.parent.getType(),
|
|
355
|
-
}
|
|
356
|
-
set(
|
|
357
|
-
if (
|
|
350
|
+
}, this.parent, t, this.getRelated());
|
|
351
|
+
if (!(t in r))
|
|
352
|
+
throw new $e(t);
|
|
353
|
+
for (const i in e) {
|
|
354
|
+
const l = e[i];
|
|
355
|
+
if ((l.model === this.parent.getType() || ["MorphOne", "MorphMany"].includes(t)) && r[t].includes(l.type))
|
|
356
|
+
return i;
|
|
357
|
+
}
|
|
358
|
+
throw new Ee(this.parent.getType(), t, this.getRelated().getSchemaName(), r[t].join(" or "));
|
|
359
|
+
}
|
|
360
|
+
set(e) {
|
|
361
|
+
if (e !== null && !d.isModel(e) && !(e instanceof b && e.every(d.isModel)))
|
|
358
362
|
throw new f("Relation.set()", "Model, Collection<Model> or null");
|
|
359
|
-
!this.items || d.isModel(this.items) ? this.items =
|
|
363
|
+
!this.items || d.isModel(this.items) ? this.items = e : e instanceof b && this.items.splice(0, this.items.count(), ...e);
|
|
360
364
|
}
|
|
361
365
|
getForeignKey() {
|
|
362
366
|
return this.meta.foreignKey;
|
|
@@ -374,10 +378,10 @@ class R {
|
|
|
374
378
|
return this.services.model.make(this.meta.model);
|
|
375
379
|
}
|
|
376
380
|
query() {
|
|
377
|
-
const
|
|
378
|
-
return this.unsubscribeQuery && this.unsubscribeQuery(), this.unsubscribeQuery =
|
|
379
|
-
this.items =
|
|
380
|
-
}),
|
|
381
|
+
const e = this.getRelated().query();
|
|
382
|
+
return this.unsubscribeQuery && this.unsubscribeQuery(), this.unsubscribeQuery = e.on("success", (t) => {
|
|
383
|
+
this.items = t.items;
|
|
384
|
+
}), e;
|
|
381
385
|
}
|
|
382
386
|
isLoaded() {
|
|
383
387
|
return this.items !== null;
|
|
@@ -394,32 +398,32 @@ class R {
|
|
|
394
398
|
getParent() {
|
|
395
399
|
return this.parent;
|
|
396
400
|
}
|
|
397
|
-
where(...
|
|
398
|
-
return this.query().where(...
|
|
401
|
+
where(...e) {
|
|
402
|
+
return this.query().where(...e);
|
|
399
403
|
}
|
|
400
|
-
whereNull(
|
|
401
|
-
return this.query().whereNull(
|
|
404
|
+
whereNull(e) {
|
|
405
|
+
return this.query().whereNull(e);
|
|
402
406
|
}
|
|
403
|
-
whereNotNull(
|
|
404
|
-
return this.query().whereNotNull(
|
|
407
|
+
whereNotNull(e) {
|
|
408
|
+
return this.query().whereNotNull(e);
|
|
405
409
|
}
|
|
406
|
-
whereBetween(
|
|
407
|
-
return this.query().whereBetween(
|
|
410
|
+
whereBetween(e, t) {
|
|
411
|
+
return this.query().whereBetween(e, t);
|
|
408
412
|
}
|
|
409
|
-
whereNotBetween(
|
|
410
|
-
return this.query().whereNotBetween(
|
|
413
|
+
whereNotBetween(e, t) {
|
|
414
|
+
return this.query().whereNotBetween(e, t);
|
|
411
415
|
}
|
|
412
|
-
orderBy(
|
|
413
|
-
return this.query().orderBy(
|
|
416
|
+
orderBy(e, t = "asc") {
|
|
417
|
+
return this.query().orderBy(e, t);
|
|
414
418
|
}
|
|
415
|
-
searchBy(
|
|
416
|
-
return this.query().searchBy(
|
|
419
|
+
searchBy(e) {
|
|
420
|
+
return this.query().searchBy(e);
|
|
417
421
|
}
|
|
418
422
|
minified() {
|
|
419
423
|
return this.query().minified();
|
|
420
424
|
}
|
|
421
|
-
limit(
|
|
422
|
-
return this.query().limit(
|
|
425
|
+
limit(e) {
|
|
426
|
+
return this.query().limit(e);
|
|
423
427
|
}
|
|
424
428
|
// get(page = 1, perPage = 15, replaceLinksWith?: string): Promise<ModelPaginatedResponse>
|
|
425
429
|
// {
|
|
@@ -434,11 +438,11 @@ class R {
|
|
|
434
438
|
// return this.query().find(id);
|
|
435
439
|
// }
|
|
436
440
|
}
|
|
437
|
-
var
|
|
438
|
-
class E extends (
|
|
439
|
-
constructor(
|
|
440
|
-
super(`[Luminix] Expected ${
|
|
441
|
-
p(this,
|
|
441
|
+
var D, H;
|
|
442
|
+
class E extends (H = Error, D = Symbol.toStringTag, H) {
|
|
443
|
+
constructor(t) {
|
|
444
|
+
super(`[Luminix] Expected ${t} to be reducible.`);
|
|
445
|
+
p(this, D, "NotReducibleException");
|
|
442
446
|
}
|
|
443
447
|
}
|
|
444
448
|
var J, U;
|
|
@@ -448,17 +452,17 @@ class Se extends (U = Error, J = Symbol.toStringTag, U) {
|
|
|
448
452
|
p(this, J, "MethodNotImplementedException");
|
|
449
453
|
}
|
|
450
454
|
}
|
|
451
|
-
var F,
|
|
452
|
-
class oe extends (
|
|
453
|
-
constructor(
|
|
454
|
-
super(`[Luminix] Model "${
|
|
455
|
+
var F, W;
|
|
456
|
+
class oe extends (W = Error, F = Symbol.toStringTag, W) {
|
|
457
|
+
constructor(t, r) {
|
|
458
|
+
super(`[Luminix] Model "${t}" must be persisted before calling "${r}"`);
|
|
455
459
|
p(this, F, "ModelNotPersistedException");
|
|
456
460
|
}
|
|
457
461
|
}
|
|
458
|
-
function _e(o, t,
|
|
459
|
-
var
|
|
460
|
-
return
|
|
461
|
-
constructor(
|
|
462
|
+
function _e(o, e, t, r, i) {
|
|
463
|
+
var l, m, c;
|
|
464
|
+
return c = class extends (m = A, l = Symbol.toStringTag, m) {
|
|
465
|
+
constructor(s = {}) {
|
|
462
466
|
super();
|
|
463
467
|
p(this, "_attributes", new _({}));
|
|
464
468
|
p(this, "_original", {});
|
|
@@ -466,43 +470,43 @@ function _e(o, t, e, i, s) {
|
|
|
466
470
|
p(this, "_changedKeys", []);
|
|
467
471
|
p(this, "exists", !1);
|
|
468
472
|
p(this, "wasRecentlyCreated", !1);
|
|
469
|
-
p(this,
|
|
470
|
-
this.makeRelations(), this.makeAttributes(
|
|
473
|
+
p(this, l, y.studly(i));
|
|
474
|
+
this.makeRelations(), this.makeAttributes(s);
|
|
471
475
|
}
|
|
472
|
-
cast(
|
|
473
|
-
return
|
|
476
|
+
cast(s, n) {
|
|
477
|
+
return s == null || !n ? s : ["boolean", "bool"].includes(n) ? !!s : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(n) && typeof s == "string" ? new Date(s) : ["float", "double", "integer", "int"].includes(n) || n.startsWith("decimal:") ? Number(s) : s;
|
|
474
478
|
}
|
|
475
|
-
mutate(
|
|
476
|
-
return
|
|
479
|
+
mutate(s, n) {
|
|
480
|
+
return s == null || !n ? s : ["boolean", "bool"].includes(n) ? !!s : ["date", "datetime", "immutable_date", "immutable_datetime"].includes(n) && s instanceof Date ? s.toISOString() : ["float", "double", "integer", "int"].includes(n) || n.startsWith("decimal:") ? Number(s) : s;
|
|
477
481
|
}
|
|
478
482
|
makeRelations() {
|
|
479
|
-
const { relations:
|
|
480
|
-
if (this._relations = {}, !
|
|
483
|
+
const { relations: s } = t.schema(i);
|
|
484
|
+
if (this._relations = {}, !s)
|
|
481
485
|
return;
|
|
482
|
-
const n =
|
|
483
|
-
Object.entries(
|
|
486
|
+
const n = t.getRelationConstructors(i);
|
|
487
|
+
Object.entries(s).forEach(([a, h]) => {
|
|
484
488
|
const { type: g } = h, w = g in n ? n[g] : R;
|
|
485
489
|
this._relations[a] = new w(
|
|
486
|
-
{ model:
|
|
490
|
+
{ model: t, route: r },
|
|
487
491
|
{ name: a, ...h },
|
|
488
492
|
this,
|
|
489
493
|
null
|
|
490
494
|
);
|
|
491
495
|
});
|
|
492
496
|
}
|
|
493
|
-
makeAttributes(
|
|
494
|
-
const { relations: n } =
|
|
497
|
+
makeAttributes(s) {
|
|
498
|
+
const { relations: n } = t.schema(i), a = Object.keys(n || {}), h = d.omit(s, ...a);
|
|
495
499
|
if (this.fillable.filter((g) => !(g in h)).forEach((g) => {
|
|
496
500
|
h[g] = null;
|
|
497
501
|
}), n && Object.keys(n).forEach((g) => {
|
|
498
|
-
this.relation(
|
|
502
|
+
this.relation(y.camel(g)).make(s[g]);
|
|
499
503
|
}), !this.validateJsonObject(h)) {
|
|
500
504
|
if (o.get("app.env", "production") === "production")
|
|
501
|
-
throw new TypeError(`[Luminix] Invalid attributes for model "${
|
|
502
|
-
|
|
505
|
+
throw new TypeError(`[Luminix] Invalid attributes for model "${i}"`);
|
|
506
|
+
e.warning(`Invalid attributes for model "${i}".
|
|
503
507
|
This will throw an error in production.`, {
|
|
504
|
-
attributes:
|
|
505
|
-
abstract:
|
|
508
|
+
attributes: s,
|
|
509
|
+
abstract: i
|
|
506
510
|
});
|
|
507
511
|
}
|
|
508
512
|
this._attributes.set(".", h), this._original = h, this._changedKeys.splice(0, this._changedKeys.length);
|
|
@@ -512,83 +516,83 @@ function _e(o, t, e, i, s) {
|
|
|
512
516
|
[this.getKeyName()]: this.getKey()
|
|
513
517
|
};
|
|
514
518
|
}
|
|
515
|
-
dispatchChangeEvent(
|
|
519
|
+
dispatchChangeEvent(s) {
|
|
516
520
|
this.emit("change", {
|
|
517
|
-
value:
|
|
521
|
+
value: s,
|
|
518
522
|
source: this
|
|
519
523
|
});
|
|
520
524
|
}
|
|
521
|
-
dispatchCreateEvent(
|
|
525
|
+
dispatchCreateEvent(s) {
|
|
522
526
|
this.emit("create", {
|
|
523
|
-
value:
|
|
527
|
+
value: s,
|
|
524
528
|
source: this
|
|
525
|
-
}),
|
|
526
|
-
class:
|
|
529
|
+
}), t.emit("create", {
|
|
530
|
+
class: i,
|
|
527
531
|
model: this,
|
|
528
|
-
source:
|
|
532
|
+
source: t
|
|
529
533
|
});
|
|
530
534
|
}
|
|
531
|
-
dispatchUpdateEvent(
|
|
535
|
+
dispatchUpdateEvent(s) {
|
|
532
536
|
this.emit("update", {
|
|
533
|
-
value:
|
|
537
|
+
value: s,
|
|
534
538
|
source: this
|
|
535
|
-
}),
|
|
536
|
-
class:
|
|
539
|
+
}), t.emit("update", {
|
|
540
|
+
class: i,
|
|
537
541
|
model: this,
|
|
538
|
-
source:
|
|
542
|
+
source: t
|
|
539
543
|
});
|
|
540
544
|
}
|
|
541
545
|
dispatchSaveEvent() {
|
|
542
546
|
this.emit("save", {
|
|
543
547
|
value: this.diff(),
|
|
544
548
|
source: this
|
|
545
|
-
}),
|
|
546
|
-
class:
|
|
549
|
+
}), t.emit("save", {
|
|
550
|
+
class: i,
|
|
547
551
|
model: this,
|
|
548
|
-
source:
|
|
552
|
+
source: t
|
|
549
553
|
});
|
|
550
554
|
}
|
|
551
|
-
dispatchDeleteEvent(
|
|
555
|
+
dispatchDeleteEvent(s = !1) {
|
|
552
556
|
this.emit("delete", {
|
|
553
|
-
force:
|
|
557
|
+
force: s,
|
|
554
558
|
[this.getKeyName()]: this.getKey(),
|
|
555
559
|
source: this
|
|
556
|
-
}),
|
|
557
|
-
class:
|
|
560
|
+
}), t.emit("delete", {
|
|
561
|
+
class: i,
|
|
558
562
|
model: this,
|
|
559
|
-
source:
|
|
560
|
-
force:
|
|
563
|
+
source: t,
|
|
564
|
+
force: s
|
|
561
565
|
});
|
|
562
566
|
}
|
|
563
567
|
dispatchRestoreEvent() {
|
|
564
568
|
this.emit("restore", {
|
|
565
569
|
value: this.attributes,
|
|
566
570
|
source: this
|
|
567
|
-
}),
|
|
568
|
-
class:
|
|
571
|
+
}), t.emit("restore", {
|
|
572
|
+
class: i,
|
|
569
573
|
model: this,
|
|
570
|
-
source:
|
|
574
|
+
source: t
|
|
571
575
|
});
|
|
572
576
|
}
|
|
573
|
-
dispatchErrorEvent(
|
|
577
|
+
dispatchErrorEvent(s, n) {
|
|
574
578
|
this.emit("error", {
|
|
575
|
-
error:
|
|
579
|
+
error: s,
|
|
576
580
|
operation: n,
|
|
577
581
|
source: this
|
|
578
|
-
}),
|
|
579
|
-
class:
|
|
582
|
+
}), t.emit("error", {
|
|
583
|
+
class: i,
|
|
580
584
|
model: this,
|
|
581
|
-
source:
|
|
582
|
-
error:
|
|
585
|
+
source: t,
|
|
586
|
+
error: s,
|
|
583
587
|
operation: n
|
|
584
588
|
});
|
|
585
589
|
}
|
|
586
|
-
updateChangedKeys(
|
|
590
|
+
updateChangedKeys(s) {
|
|
587
591
|
const n = (a, h) => typeof a == "object" && a !== null ? d.isEqual(a, h) : a == h;
|
|
588
|
-
!this._changedKeys.includes(
|
|
592
|
+
!this._changedKeys.includes(s) && !n(d.get(this._original, s), this._attributes.get(s)) ? this._changedKeys.push(s) : this._changedKeys.includes(s) && n(d.get(this._original, s), this._attributes.get(s)) && this._changedKeys.splice(this._changedKeys.indexOf(s), 1);
|
|
589
593
|
}
|
|
590
|
-
validateJsonObject(
|
|
591
|
-
return typeof
|
|
594
|
+
validateJsonObject(s) {
|
|
595
|
+
return typeof s != "object" || s === null ? !1 : Object.entries(s).every(([, n]) => ["boolean", "number", "string"].includes(typeof n) || n === null || this.validateJsonObject(n) || Array.isArray(n) && n.every((a) => this.validateJsonObject(a)));
|
|
592
596
|
}
|
|
593
597
|
get attributes() {
|
|
594
598
|
return this._attributes.all();
|
|
@@ -600,20 +604,20 @@ function _e(o, t, e, i, s) {
|
|
|
600
604
|
return this._relations;
|
|
601
605
|
}
|
|
602
606
|
get fillable() {
|
|
603
|
-
return
|
|
607
|
+
return t.schema(i).fillable;
|
|
604
608
|
}
|
|
605
609
|
get primaryKey() {
|
|
606
|
-
return
|
|
610
|
+
return t.schema(i).primaryKey;
|
|
607
611
|
}
|
|
608
612
|
get timestamps() {
|
|
609
|
-
return
|
|
613
|
+
return t.schema(i).timestamps;
|
|
610
614
|
}
|
|
611
615
|
// get softDeletes() {
|
|
612
616
|
// return ModelFacade.schema(abstract).softDeletes;
|
|
613
617
|
// }
|
|
614
618
|
get casts() {
|
|
615
619
|
return {
|
|
616
|
-
...
|
|
620
|
+
...t.schema(i).casts,
|
|
617
621
|
...this.timestamps ? { created_at: "datetime", updated_at: "datetime" } : {}
|
|
618
622
|
// ...this.softDeletes ? { deleted_at: 'datetime' } : {},
|
|
619
623
|
};
|
|
@@ -621,36 +625,37 @@ function _e(o, t, e, i, s) {
|
|
|
621
625
|
get isDirty() {
|
|
622
626
|
return this._changedKeys.length > 0;
|
|
623
627
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
+
/* * * * */
|
|
629
|
+
getAttribute(s) {
|
|
630
|
+
let n = this._attributes.get(s, null);
|
|
631
|
+
s in this.casts && (n = this.cast(n, this.casts[s]));
|
|
632
|
+
const a = t[`model${y.studly(i)}Get${y.studly(s)}Attribute`];
|
|
628
633
|
if (typeof a != "function")
|
|
629
634
|
throw new E("ModelFacade");
|
|
630
|
-
return a.bind(
|
|
635
|
+
return a.bind(t)(n, this);
|
|
631
636
|
}
|
|
632
|
-
setAttribute(
|
|
633
|
-
const a =
|
|
637
|
+
setAttribute(s, n) {
|
|
638
|
+
const a = t[`model${y.studly(i)}Set${y.studly(s)}Attribute`];
|
|
634
639
|
if (typeof a != "function")
|
|
635
640
|
throw new E("ModelFacade");
|
|
636
|
-
const h = a.bind(
|
|
637
|
-
this.mutate(n, this.casts[
|
|
641
|
+
const h = a.bind(t)(
|
|
642
|
+
this.mutate(n, this.casts[s]),
|
|
638
643
|
this
|
|
639
644
|
);
|
|
640
|
-
if (!this.validateJsonObject({ [
|
|
645
|
+
if (!this.validateJsonObject({ [s]: h })) {
|
|
641
646
|
if (o.get("app.env", "production") === "production")
|
|
642
|
-
throw new TypeError(`[Luminix] Attribute "${
|
|
643
|
-
|
|
647
|
+
throw new TypeError(`[Luminix] Attribute "${s}" in model "${i}" must be a boolean, number, string or null`);
|
|
648
|
+
e.warning(`Invalid type for attribute "${s}" in model "${i}" after mutation.
|
|
644
649
|
This will throw an error in production.`, {
|
|
645
|
-
key:
|
|
650
|
+
key: s,
|
|
646
651
|
value: n,
|
|
647
652
|
mutated: h,
|
|
648
|
-
cast: this.casts[
|
|
653
|
+
cast: this.casts[s],
|
|
649
654
|
item: this.toJson()
|
|
650
655
|
});
|
|
651
656
|
return;
|
|
652
657
|
}
|
|
653
|
-
this._attributes.set(
|
|
658
|
+
this._attributes.set(s, h), this.updateChangedKeys(s), this.dispatchChangeEvent({ [s]: h });
|
|
654
659
|
}
|
|
655
660
|
getKey() {
|
|
656
661
|
return this.getAttribute(this.primaryKey);
|
|
@@ -658,22 +663,22 @@ function _e(o, t, e, i, s) {
|
|
|
658
663
|
getKeyName() {
|
|
659
664
|
return this.primaryKey;
|
|
660
665
|
}
|
|
661
|
-
fill(
|
|
662
|
-
const n = d.pick(
|
|
663
|
-
const v =
|
|
666
|
+
fill(s) {
|
|
667
|
+
const n = d.pick(s, ...this.fillable), a = Object.entries(n).reduce((h, [g, w]) => {
|
|
668
|
+
const v = t[`model${y.studly(i)}Set${y.studly(g)}Attribute`];
|
|
664
669
|
if (typeof v != "function")
|
|
665
670
|
throw new E("ModelFacade");
|
|
666
|
-
return h[g] = v.bind(
|
|
671
|
+
return h[g] = v.bind(t)(
|
|
667
672
|
this.mutate(w, this.casts[g]),
|
|
668
673
|
this
|
|
669
674
|
), h;
|
|
670
675
|
}, {});
|
|
671
676
|
if (!this.validateJsonObject(a)) {
|
|
672
677
|
if (o.get("app.env", "production") === "production")
|
|
673
|
-
throw new TypeError(`[Luminix] Invalid attributes for model "${
|
|
674
|
-
|
|
678
|
+
throw new TypeError(`[Luminix] Invalid attributes for model "${i}"`);
|
|
679
|
+
e.warning(`Invalid attributes for model "${i}" after mutation.
|
|
675
680
|
This will throw an error in production.`, {
|
|
676
|
-
attributes:
|
|
681
|
+
attributes: s,
|
|
677
682
|
mutatedAttributes: a,
|
|
678
683
|
item: this.toJson(),
|
|
679
684
|
casts: this.casts
|
|
@@ -683,77 +688,78 @@ function _e(o, t, e, i, s) {
|
|
|
683
688
|
this._attributes.merge(".", a), Object.keys(a).forEach((h) => this.updateChangedKeys(h)), this.dispatchChangeEvent(a);
|
|
684
689
|
}
|
|
685
690
|
dump() {
|
|
686
|
-
|
|
691
|
+
e.info({
|
|
687
692
|
...this.toJson(),
|
|
688
|
-
[Symbol.toStringTag]:
|
|
693
|
+
[Symbol.toStringTag]: y.studly(i)
|
|
689
694
|
});
|
|
690
695
|
}
|
|
691
696
|
toJson() {
|
|
692
|
-
const
|
|
697
|
+
const s = Object.entries(this.relations).reduce((a, [h, g]) => (g.isLoaded() && (g.isSingle() ? a[y.snake(h)] = g.getLoadedItems().toJson() : g.isMultiple() && (a[y.snake(h)] = g.getLoadedItems().map((w) => w.toJson()).all())), a), {}), n = t[`model${y.studly(i)}Json`];
|
|
693
698
|
if (typeof n != "function")
|
|
694
699
|
throw new E("ModelFacade");
|
|
695
|
-
return n.bind(
|
|
700
|
+
return n.bind(t)({
|
|
696
701
|
...this.attributes,
|
|
697
|
-
...
|
|
702
|
+
...s
|
|
698
703
|
}, this);
|
|
699
704
|
}
|
|
700
705
|
diff() {
|
|
701
|
-
return this._changedKeys.reduce((
|
|
706
|
+
return this._changedKeys.reduce((s, n) => (s[n] = this._attributes.get(n), s), {});
|
|
702
707
|
}
|
|
703
708
|
getType() {
|
|
704
|
-
return
|
|
709
|
+
return i;
|
|
705
710
|
}
|
|
706
|
-
relation(
|
|
707
|
-
if (
|
|
708
|
-
return this.relations[
|
|
711
|
+
relation(s) {
|
|
712
|
+
if (s === y.camel(s))
|
|
713
|
+
return this.relations[y.snake(s)];
|
|
709
714
|
}
|
|
710
|
-
getErrorBag(
|
|
711
|
-
return `${this.exists ? `${
|
|
715
|
+
getErrorBag(s) {
|
|
716
|
+
return `${this.exists ? `${i}[${this.getKey()}].` : `${i}.`}${s}`;
|
|
712
717
|
}
|
|
713
718
|
getRouteForSave() {
|
|
714
719
|
return this.exists ? [
|
|
715
|
-
`luminix.${
|
|
720
|
+
`luminix.${i}.update`,
|
|
716
721
|
this.makePrimaryKeyReplacer()
|
|
717
|
-
] : `luminix.${
|
|
722
|
+
] : `luminix.${i}.store`;
|
|
718
723
|
}
|
|
719
724
|
getRouteForUpdate() {
|
|
720
725
|
return [
|
|
721
|
-
`luminix.${
|
|
726
|
+
`luminix.${i}.update`,
|
|
722
727
|
this.makePrimaryKeyReplacer()
|
|
723
728
|
];
|
|
724
729
|
}
|
|
725
730
|
getRouteForDelete() {
|
|
726
731
|
return [
|
|
727
|
-
`luminix.${
|
|
732
|
+
`luminix.${i}.destroy`,
|
|
728
733
|
this.makePrimaryKeyReplacer()
|
|
729
734
|
];
|
|
730
735
|
}
|
|
731
736
|
getRouteForRefresh() {
|
|
732
737
|
return [
|
|
733
|
-
`luminix.${
|
|
738
|
+
`luminix.${i}.show`,
|
|
734
739
|
this.makePrimaryKeyReplacer()
|
|
735
740
|
];
|
|
736
741
|
}
|
|
737
742
|
getLabel() {
|
|
738
|
-
const { labeledBy:
|
|
739
|
-
return this.getAttribute(
|
|
743
|
+
const { labeledBy: s } = t.schema(i);
|
|
744
|
+
return this.getAttribute(s);
|
|
740
745
|
}
|
|
741
|
-
|
|
746
|
+
/* * * * */
|
|
747
|
+
async refresh(s) {
|
|
742
748
|
if (!this.exists)
|
|
743
|
-
throw new oe(
|
|
744
|
-
const n = await
|
|
749
|
+
throw new oe(i, "refresh");
|
|
750
|
+
const n = await r.call(
|
|
745
751
|
this.getRouteForRefresh(),
|
|
746
|
-
|
|
752
|
+
s,
|
|
747
753
|
this.getErrorBag("fetch")
|
|
748
754
|
);
|
|
749
755
|
this.makeAttributes(n.json());
|
|
750
756
|
}
|
|
751
|
-
async save(
|
|
757
|
+
async save(s = {}, n) {
|
|
752
758
|
try {
|
|
753
759
|
const {
|
|
754
760
|
additionalPayload: a = {},
|
|
755
761
|
sendsOnlyModifiedFields: h = !0
|
|
756
|
-
} =
|
|
762
|
+
} = s, g = this.exists, w = {
|
|
757
763
|
...d.pick(
|
|
758
764
|
h && g ? this.diff() : this.attributes,
|
|
759
765
|
...this.fillable
|
|
@@ -762,9 +768,9 @@ function _e(o, t, e, i, s) {
|
|
|
762
768
|
};
|
|
763
769
|
if (d.isEmpty(w))
|
|
764
770
|
return;
|
|
765
|
-
const v = await
|
|
771
|
+
const v = await r.call(
|
|
766
772
|
this.getRouteForSave(),
|
|
767
|
-
(
|
|
773
|
+
(k) => n ? n(k.withData(w)) : k.withData(w),
|
|
768
774
|
this.getErrorBag(g ? "update" : "store")
|
|
769
775
|
);
|
|
770
776
|
if (v.successful())
|
|
@@ -779,23 +785,23 @@ function _e(o, t, e, i, s) {
|
|
|
779
785
|
}
|
|
780
786
|
async delete() {
|
|
781
787
|
try {
|
|
782
|
-
const
|
|
788
|
+
const s = await r.call(
|
|
783
789
|
this.getRouteForDelete(),
|
|
784
790
|
void 0,
|
|
785
791
|
this.getErrorBag("delete")
|
|
786
792
|
);
|
|
787
|
-
if (
|
|
788
|
-
return this.dispatchDeleteEvent(),
|
|
789
|
-
throw
|
|
790
|
-
} catch (
|
|
791
|
-
throw this.dispatchErrorEvent(
|
|
793
|
+
if (s.noContent())
|
|
794
|
+
return this.dispatchDeleteEvent(), s;
|
|
795
|
+
throw s;
|
|
796
|
+
} catch (s) {
|
|
797
|
+
throw this.dispatchErrorEvent(s, "delete"), s;
|
|
792
798
|
}
|
|
793
799
|
}
|
|
794
|
-
async update(
|
|
800
|
+
async update(s, n) {
|
|
795
801
|
try {
|
|
796
|
-
const a = await
|
|
802
|
+
const a = await r.call(
|
|
797
803
|
this.getRouteForUpdate(),
|
|
798
|
-
(h) => n ? n(h.withData(
|
|
804
|
+
(h) => n ? n(h.withData(s)) : h.withData(s),
|
|
799
805
|
this.getErrorBag("update")
|
|
800
806
|
);
|
|
801
807
|
if (a.ok()) {
|
|
@@ -809,179 +815,180 @@ function _e(o, t, e, i, s) {
|
|
|
809
815
|
}
|
|
810
816
|
async forceDelete() {
|
|
811
817
|
try {
|
|
812
|
-
const
|
|
818
|
+
const s = await r.call(
|
|
813
819
|
this.getRouteForDelete(),
|
|
814
820
|
(n) => n.withQueryParameters({ force: !0 }),
|
|
815
821
|
this.getErrorBag("forceDelete")
|
|
816
822
|
);
|
|
817
|
-
if (
|
|
818
|
-
return this.dispatchDeleteEvent(!0),
|
|
819
|
-
throw
|
|
820
|
-
} catch (
|
|
821
|
-
throw this.dispatchErrorEvent(
|
|
823
|
+
if (s.noContent())
|
|
824
|
+
return this.dispatchDeleteEvent(!0), s;
|
|
825
|
+
throw s;
|
|
826
|
+
} catch (s) {
|
|
827
|
+
throw this.dispatchErrorEvent(s, "forceDelete"), s;
|
|
822
828
|
}
|
|
823
829
|
}
|
|
824
830
|
async restore() {
|
|
825
831
|
try {
|
|
826
|
-
const
|
|
832
|
+
const s = await r.call(
|
|
827
833
|
this.getRouteForUpdate(),
|
|
828
834
|
(n) => n.withQueryParameters({ restore: !0 }),
|
|
829
835
|
this.getErrorBag("restore")
|
|
830
836
|
);
|
|
831
|
-
if (
|
|
832
|
-
return this.dispatchRestoreEvent(),
|
|
833
|
-
throw
|
|
834
|
-
} catch (
|
|
835
|
-
throw this.dispatchErrorEvent(
|
|
837
|
+
if (s.ok())
|
|
838
|
+
return this.dispatchRestoreEvent(), s;
|
|
839
|
+
throw s;
|
|
840
|
+
} catch (s) {
|
|
841
|
+
throw this.dispatchErrorEvent(s, "restore"), s;
|
|
836
842
|
}
|
|
837
843
|
}
|
|
844
|
+
/* * * * */
|
|
838
845
|
static getSchemaName() {
|
|
839
|
-
return
|
|
846
|
+
return i;
|
|
840
847
|
}
|
|
841
848
|
static getSchema() {
|
|
842
|
-
return
|
|
849
|
+
return t.schema(i);
|
|
843
850
|
}
|
|
844
851
|
static query() {
|
|
845
852
|
return new Me(
|
|
846
|
-
{ config: o, route:
|
|
847
|
-
|
|
853
|
+
{ config: o, route: r, model: t },
|
|
854
|
+
i
|
|
848
855
|
);
|
|
849
856
|
}
|
|
850
|
-
static where(...
|
|
851
|
-
return this.query().where(...
|
|
857
|
+
static where(...s) {
|
|
858
|
+
return this.query().where(...s);
|
|
852
859
|
}
|
|
853
|
-
static whereNull(
|
|
854
|
-
return this.query().whereNull(
|
|
860
|
+
static whereNull(s) {
|
|
861
|
+
return this.query().whereNull(s);
|
|
855
862
|
}
|
|
856
|
-
static whereNotNull(
|
|
857
|
-
return this.query().whereNotNull(
|
|
863
|
+
static whereNotNull(s) {
|
|
864
|
+
return this.query().whereNotNull(s);
|
|
858
865
|
}
|
|
859
|
-
static whereBetween(
|
|
860
|
-
return this.query().whereBetween(
|
|
866
|
+
static whereBetween(s, n) {
|
|
867
|
+
return this.query().whereBetween(s, n);
|
|
861
868
|
}
|
|
862
|
-
static whereNotBetween(
|
|
863
|
-
return this.query().whereNotBetween(
|
|
869
|
+
static whereNotBetween(s, n) {
|
|
870
|
+
return this.query().whereNotBetween(s, n);
|
|
864
871
|
}
|
|
865
|
-
static orderBy(
|
|
866
|
-
return this.query().orderBy(
|
|
872
|
+
static orderBy(s, n = "asc") {
|
|
873
|
+
return this.query().orderBy(s, n);
|
|
867
874
|
}
|
|
868
|
-
static searchBy(
|
|
869
|
-
return this.query().searchBy(
|
|
875
|
+
static searchBy(s) {
|
|
876
|
+
return this.query().searchBy(s);
|
|
870
877
|
}
|
|
871
878
|
static minified() {
|
|
872
879
|
return this.query().minified();
|
|
873
880
|
}
|
|
874
|
-
static limit(
|
|
875
|
-
return this.query().limit(
|
|
881
|
+
static limit(s) {
|
|
882
|
+
return this.query().limit(s);
|
|
876
883
|
}
|
|
877
|
-
static get(
|
|
878
|
-
return this.query().get(
|
|
884
|
+
static get(s) {
|
|
885
|
+
return this.query().get(s);
|
|
879
886
|
}
|
|
880
|
-
static find(
|
|
881
|
-
return this.query().find(
|
|
887
|
+
static find(s) {
|
|
888
|
+
return this.query().find(s);
|
|
882
889
|
}
|
|
883
890
|
static first() {
|
|
884
891
|
return this.query().first();
|
|
885
892
|
}
|
|
886
|
-
static async create(
|
|
887
|
-
const n =
|
|
888
|
-
return a.fill(
|
|
893
|
+
static async create(s) {
|
|
894
|
+
const n = t.make(i), a = new n();
|
|
895
|
+
return a.fill(s), await a.save(), a;
|
|
889
896
|
}
|
|
890
|
-
static async update(
|
|
891
|
-
const a =
|
|
897
|
+
static async update(s, n) {
|
|
898
|
+
const a = t.make(i), h = new a({ id: s });
|
|
892
899
|
return h.fill(n), h.exists = !0, await h.save(), h;
|
|
893
900
|
}
|
|
894
|
-
static delete(
|
|
895
|
-
if (Array.isArray(
|
|
896
|
-
return
|
|
897
|
-
`luminix.${
|
|
898
|
-
(h) => h.withQueryParameters({ ids:
|
|
899
|
-
`${
|
|
901
|
+
static delete(s) {
|
|
902
|
+
if (Array.isArray(s))
|
|
903
|
+
return r.call(
|
|
904
|
+
`luminix.${i}.destroyMany`,
|
|
905
|
+
(h) => h.withQueryParameters({ ids: s }),
|
|
906
|
+
`${i}.deleteMany`
|
|
900
907
|
);
|
|
901
|
-
const n =
|
|
902
|
-
return new n({ id:
|
|
903
|
-
}
|
|
904
|
-
static async restore(
|
|
905
|
-
if (Array.isArray(
|
|
906
|
-
return
|
|
907
|
-
`luminix.${
|
|
908
|
-
(h) => h.withData({ ids:
|
|
909
|
-
`${
|
|
908
|
+
const n = t.make(i);
|
|
909
|
+
return new n({ id: s }).delete();
|
|
910
|
+
}
|
|
911
|
+
static async restore(s) {
|
|
912
|
+
if (Array.isArray(s))
|
|
913
|
+
return r.call(
|
|
914
|
+
`luminix.${i}.restoreMany`,
|
|
915
|
+
(h) => h.withData({ ids: s }),
|
|
916
|
+
`${i}.restoreMany`
|
|
910
917
|
);
|
|
911
|
-
const n =
|
|
912
|
-
return new n({ id:
|
|
913
|
-
}
|
|
914
|
-
static forceDelete(
|
|
915
|
-
if (Array.isArray(
|
|
916
|
-
return
|
|
917
|
-
`luminix.${
|
|
918
|
-
(h) => h.withQueryParameters({ ids:
|
|
919
|
-
`${
|
|
918
|
+
const n = t.make(i);
|
|
919
|
+
return new n({ id: s }).restore();
|
|
920
|
+
}
|
|
921
|
+
static forceDelete(s) {
|
|
922
|
+
if (Array.isArray(s))
|
|
923
|
+
return r.call(
|
|
924
|
+
`luminix.${i}.destroyMany`,
|
|
925
|
+
(h) => h.withQueryParameters({ ids: s, force: !0 }),
|
|
926
|
+
`${i}.forceDeleteMany`
|
|
920
927
|
);
|
|
921
|
-
const n =
|
|
922
|
-
return new n({ id:
|
|
928
|
+
const n = t.make(i);
|
|
929
|
+
return new n({ id: s }).forceDelete();
|
|
923
930
|
}
|
|
924
931
|
static singular() {
|
|
925
|
-
return
|
|
932
|
+
return t.schema(i).displayName.singular;
|
|
926
933
|
}
|
|
927
934
|
static plural() {
|
|
928
|
-
return
|
|
935
|
+
return t.schema(i).displayName.plural;
|
|
929
936
|
}
|
|
930
|
-
}, p(
|
|
937
|
+
}, p(c, "name", y.studly(i)), c;
|
|
931
938
|
}
|
|
932
|
-
function Te(o,
|
|
933
|
-
var
|
|
934
|
-
return class extends (
|
|
935
|
-
constructor(
|
|
936
|
-
super(
|
|
937
|
-
p(this,
|
|
939
|
+
function Te(o, e, t) {
|
|
940
|
+
var r, i;
|
|
941
|
+
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
942
|
+
constructor(m = {}) {
|
|
943
|
+
super(m);
|
|
944
|
+
p(this, r, y.studly(e));
|
|
938
945
|
return new Proxy(this, {
|
|
939
|
-
get: (
|
|
946
|
+
get: (c, u) => {
|
|
940
947
|
if (u === "__isModel")
|
|
941
948
|
return !0;
|
|
942
|
-
if (Reflect.has(
|
|
943
|
-
return Reflect.get(
|
|
944
|
-
if (Object.keys(
|
|
945
|
-
return
|
|
946
|
-
if (Object.keys(
|
|
947
|
-
return
|
|
948
|
-
if (u.endsWith("Relation") && Object.keys(
|
|
949
|
-
return () =>
|
|
950
|
-
if (o.hasReducer(`model${
|
|
951
|
-
const
|
|
952
|
-
if (typeof
|
|
949
|
+
if (Reflect.has(c, u) || typeof u != "string")
|
|
950
|
+
return Reflect.get(c, u);
|
|
951
|
+
if (Object.keys(c.attributes).includes(u))
|
|
952
|
+
return c.getAttribute(u);
|
|
953
|
+
if (Object.keys(c.relations).includes(u))
|
|
954
|
+
return c.relations[u].getLoadedItems();
|
|
955
|
+
if (u.endsWith("Relation") && Object.keys(c.relations).includes(y.snake(u.slice(0, -8))))
|
|
956
|
+
return () => c.relation(u.slice(0, -8));
|
|
957
|
+
if (o.hasReducer(`model${y.studly(c.getType())}Get${y.studly(u)}Attribute`)) {
|
|
958
|
+
const s = o[`model${y.studly(c.getType())}Get${y.studly(u)}Attribute`];
|
|
959
|
+
if (typeof s != "function")
|
|
953
960
|
throw new E("ModelFacade");
|
|
954
|
-
return
|
|
961
|
+
return s.bind(o)(void 0, c);
|
|
955
962
|
}
|
|
956
|
-
return Reflect.get(
|
|
963
|
+
return Reflect.get(c, u);
|
|
957
964
|
},
|
|
958
|
-
set: (
|
|
959
|
-
|
|
960
|
-
|
|
965
|
+
set: (c, u, s) => u in c && typeof c[u] != "function" ? Reflect.set(c, u, s) : (c.setAttribute(
|
|
966
|
+
y.snake(u),
|
|
967
|
+
s
|
|
961
968
|
), !0)
|
|
962
969
|
});
|
|
963
970
|
}
|
|
964
971
|
};
|
|
965
972
|
}
|
|
966
|
-
var
|
|
967
|
-
class
|
|
968
|
-
constructor(
|
|
969
|
-
super(`[Luminix] Model "${
|
|
970
|
-
p(this,
|
|
973
|
+
var G, V;
|
|
974
|
+
class q extends (V = Error, G = Symbol.toStringTag, V) {
|
|
975
|
+
constructor(t) {
|
|
976
|
+
super(`[Luminix] Model "${t}" not found`);
|
|
977
|
+
p(this, G, "ModelNotFoundException");
|
|
971
978
|
}
|
|
972
979
|
}
|
|
973
980
|
var z, X;
|
|
974
981
|
class T extends (X = TypeError, z = Symbol.toStringTag, X) {
|
|
975
|
-
constructor(
|
|
976
|
-
super(`[Luminix] "${
|
|
982
|
+
constructor(t, r, i) {
|
|
983
|
+
super(`[Luminix] "${t}" expects a related model of type "${r}". Received "${i}" instead.`);
|
|
977
984
|
p(this, z, "ModelInvalidRelatedTypeException");
|
|
978
985
|
}
|
|
979
986
|
}
|
|
980
987
|
class ae extends R {
|
|
981
|
-
constructor(t,
|
|
982
|
-
if (!d.isModel(
|
|
988
|
+
constructor(e, t, r, i = null) {
|
|
989
|
+
if (!d.isModel(i) && i !== null)
|
|
983
990
|
throw new f("BelongsTo.constructor()", "Model or null");
|
|
984
|
-
super(t,
|
|
991
|
+
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
985
992
|
}
|
|
986
993
|
isSingle() {
|
|
987
994
|
return !0;
|
|
@@ -990,21 +997,21 @@ class ae extends R {
|
|
|
990
997
|
return !1;
|
|
991
998
|
}
|
|
992
999
|
query() {
|
|
993
|
-
const
|
|
994
|
-
return
|
|
1000
|
+
const e = super.query(), t = this.guessInverseRelation();
|
|
1001
|
+
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
995
1002
|
}
|
|
996
1003
|
get() {
|
|
997
1004
|
return this.query().first();
|
|
998
1005
|
}
|
|
999
|
-
async associate(
|
|
1000
|
-
if (!d.isModel(
|
|
1006
|
+
async associate(e) {
|
|
1007
|
+
if (!d.isModel(e))
|
|
1001
1008
|
throw new f("BelongsTo.associate()");
|
|
1002
|
-
if (
|
|
1003
|
-
throw new T("BelongsTo.associate()", this.getRelated().getSchemaName(),
|
|
1004
|
-
if (!
|
|
1009
|
+
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1010
|
+
throw new T("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
|
|
1011
|
+
if (!e.exists)
|
|
1005
1012
|
throw new oe(this.getRelated().getSchemaName(), "save");
|
|
1006
1013
|
return this.parent.update({
|
|
1007
|
-
[this.getForeignKey()]:
|
|
1014
|
+
[this.getForeignKey()]: e.getKey()
|
|
1008
1015
|
});
|
|
1009
1016
|
}
|
|
1010
1017
|
dissociate() {
|
|
@@ -1014,10 +1021,10 @@ class ae extends R {
|
|
|
1014
1021
|
}
|
|
1015
1022
|
}
|
|
1016
1023
|
class ue extends R {
|
|
1017
|
-
constructor(t,
|
|
1018
|
-
if (
|
|
1024
|
+
constructor(e, t, r, i = null) {
|
|
1025
|
+
if (i !== null && !(i instanceof b && i.every(d.isModel)))
|
|
1019
1026
|
throw new f("BelongsToMany.constructor()", "Collection<Model> or null");
|
|
1020
|
-
super(t,
|
|
1027
|
+
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1021
1028
|
}
|
|
1022
1029
|
isSingle() {
|
|
1023
1030
|
return !1;
|
|
@@ -1026,11 +1033,11 @@ class ue extends R {
|
|
|
1026
1033
|
return !0;
|
|
1027
1034
|
}
|
|
1028
1035
|
query() {
|
|
1029
|
-
const
|
|
1030
|
-
return
|
|
1036
|
+
const e = super.query(), t = this.guessInverseRelation();
|
|
1037
|
+
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
1031
1038
|
}
|
|
1032
|
-
get(
|
|
1033
|
-
return this.query().get(
|
|
1039
|
+
get(e) {
|
|
1040
|
+
return this.query().get(e);
|
|
1034
1041
|
}
|
|
1035
1042
|
all() {
|
|
1036
1043
|
return this.query().all();
|
|
@@ -1038,34 +1045,34 @@ class ue extends R {
|
|
|
1038
1045
|
first() {
|
|
1039
1046
|
return this.query().first();
|
|
1040
1047
|
}
|
|
1041
|
-
find(
|
|
1042
|
-
return this.query().find(
|
|
1048
|
+
find(e) {
|
|
1049
|
+
return this.query().find(e);
|
|
1043
1050
|
}
|
|
1044
|
-
attachQuietly(
|
|
1051
|
+
attachQuietly(e, t = {}) {
|
|
1045
1052
|
return this.services.route.call([
|
|
1046
1053
|
`luminix.${this.parent.getType()}.${this.getName()}:attach`,
|
|
1047
1054
|
{
|
|
1048
1055
|
[this.parent.getKeyName()]: this.parent.getKey(),
|
|
1049
|
-
itemId:
|
|
1056
|
+
itemId: e
|
|
1050
1057
|
}
|
|
1051
|
-
], (
|
|
1058
|
+
], (r) => r.withData(t));
|
|
1052
1059
|
}
|
|
1053
|
-
async attach(
|
|
1054
|
-
if (await this.attachQuietly(
|
|
1055
|
-
const
|
|
1056
|
-
if (!
|
|
1060
|
+
async attach(e, t = {}) {
|
|
1061
|
+
if (await this.attachQuietly(e, t), this.items) {
|
|
1062
|
+
const r = this.items.search((l) => l.getKey() === e), i = await this.getRelated().find(e);
|
|
1063
|
+
if (!i)
|
|
1057
1064
|
return;
|
|
1058
|
-
|
|
1065
|
+
r !== !1 ? this.items.put(r, i) : this.items.push(i);
|
|
1059
1066
|
} else
|
|
1060
1067
|
this.items = await this.all();
|
|
1061
1068
|
}
|
|
1062
|
-
async detachQuietly(
|
|
1069
|
+
async detachQuietly(e) {
|
|
1063
1070
|
await this.services.route.call(
|
|
1064
1071
|
[
|
|
1065
1072
|
`luminix.${this.parent.getType()}.${this.getName()}:detach`,
|
|
1066
1073
|
{
|
|
1067
1074
|
[this.parent.getKeyName()]: this.parent.getKey(),
|
|
1068
|
-
itemId:
|
|
1075
|
+
itemId: e
|
|
1069
1076
|
}
|
|
1070
1077
|
]
|
|
1071
1078
|
// {
|
|
@@ -1073,60 +1080,60 @@ class ue extends R {
|
|
|
1073
1080
|
// }
|
|
1074
1081
|
);
|
|
1075
1082
|
}
|
|
1076
|
-
async detach(
|
|
1077
|
-
if (await this.detachQuietly(
|
|
1078
|
-
const
|
|
1079
|
-
|
|
1083
|
+
async detach(e) {
|
|
1084
|
+
if (await this.detachQuietly(e), this.items) {
|
|
1085
|
+
const t = this.items.search((r) => r.getKey() === e);
|
|
1086
|
+
t !== !1 && this.items.pull(t);
|
|
1080
1087
|
}
|
|
1081
1088
|
}
|
|
1082
|
-
async syncQuietly(
|
|
1089
|
+
async syncQuietly(e) {
|
|
1083
1090
|
await this.services.route.call([
|
|
1084
1091
|
`luminix.${this.parent.getType()}.${this.getName()}:sync`,
|
|
1085
1092
|
{
|
|
1086
1093
|
[this.parent.getKeyName()]: this.parent.getKey()
|
|
1087
1094
|
}
|
|
1088
|
-
], (
|
|
1095
|
+
], (t) => t.withData(e));
|
|
1096
|
+
}
|
|
1097
|
+
async sync(e) {
|
|
1098
|
+
await this.syncQuietly(e);
|
|
1099
|
+
const t = await this.all();
|
|
1100
|
+
this.items ? this.items.splice(0, this.items.count(), ...t) : this.items = t;
|
|
1089
1101
|
}
|
|
1090
|
-
async syncWithPivotValuesQuietly(
|
|
1102
|
+
async syncWithPivotValuesQuietly(e, t) {
|
|
1091
1103
|
await this.services.route.call([
|
|
1092
1104
|
`luminix.${this.parent.getType()}.${this.getName()}:sync`,
|
|
1093
1105
|
{
|
|
1094
1106
|
[this.parent.getKeyName()]: this.parent.getKey()
|
|
1095
1107
|
}
|
|
1096
|
-
], (
|
|
1097
|
-
[this.getRelated().getSchema().primaryKey]:
|
|
1098
|
-
...
|
|
1108
|
+
], (r) => r.withData(e.map((i) => ({
|
|
1109
|
+
[this.getRelated().getSchema().primaryKey]: i,
|
|
1110
|
+
...t
|
|
1099
1111
|
}))));
|
|
1100
1112
|
}
|
|
1101
|
-
async
|
|
1102
|
-
await this.
|
|
1103
|
-
const
|
|
1104
|
-
this.items ? this.items.splice(0, this.items.count(), ...
|
|
1105
|
-
}
|
|
1106
|
-
async syncWithPivotValues(t, e) {
|
|
1107
|
-
await this.syncWithPivotValuesQuietly(t, e);
|
|
1108
|
-
const i = await this.all();
|
|
1109
|
-
this.items ? this.items.splice(0, this.items.count(), ...i) : this.items = i;
|
|
1113
|
+
async syncWithPivotValues(e, t) {
|
|
1114
|
+
await this.syncWithPivotValuesQuietly(e, t);
|
|
1115
|
+
const r = await this.all();
|
|
1116
|
+
this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
|
|
1110
1117
|
}
|
|
1111
1118
|
}
|
|
1112
1119
|
class N extends R {
|
|
1113
1120
|
query() {
|
|
1114
|
-
const
|
|
1115
|
-
return
|
|
1121
|
+
const e = super.query(), t = this.guessInverseRelation();
|
|
1122
|
+
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
1116
1123
|
}
|
|
1117
|
-
async saveQuietly(
|
|
1118
|
-
if (!d.isModel(
|
|
1124
|
+
async saveQuietly(e) {
|
|
1125
|
+
if (!d.isModel(e))
|
|
1119
1126
|
throw new f("HasOneOrMany.saveQuietly()");
|
|
1120
|
-
if (
|
|
1121
|
-
throw new T("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(),
|
|
1122
|
-
|
|
1127
|
+
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1128
|
+
throw new T("HasOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1129
|
+
e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
|
|
1123
1130
|
}
|
|
1124
1131
|
}
|
|
1125
1132
|
class Re extends N {
|
|
1126
|
-
constructor(t,
|
|
1127
|
-
if (!d.isModel(
|
|
1133
|
+
constructor(e, t, r, i = null) {
|
|
1134
|
+
if (!d.isModel(i) && i !== null)
|
|
1128
1135
|
throw new f("HasOne.constructor()", "Model or null");
|
|
1129
|
-
super(t,
|
|
1136
|
+
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1130
1137
|
}
|
|
1131
1138
|
isSingle() {
|
|
1132
1139
|
return !0;
|
|
@@ -1137,18 +1144,18 @@ class Re extends N {
|
|
|
1137
1144
|
get() {
|
|
1138
1145
|
return this.query().first();
|
|
1139
1146
|
}
|
|
1140
|
-
async save(
|
|
1141
|
-
await this.saveQuietly(
|
|
1147
|
+
async save(e) {
|
|
1148
|
+
await this.saveQuietly(e), this.items = e;
|
|
1142
1149
|
}
|
|
1143
1150
|
}
|
|
1144
|
-
function
|
|
1151
|
+
function K(o) {
|
|
1145
1152
|
return new b(o);
|
|
1146
1153
|
}
|
|
1147
1154
|
class Ae extends N {
|
|
1148
|
-
constructor(t,
|
|
1149
|
-
if (
|
|
1155
|
+
constructor(e, t, r, i = null) {
|
|
1156
|
+
if (i !== null && !(i instanceof b && i.every(d.isModel)))
|
|
1150
1157
|
throw new f("HasMany.constructor()", "Collection<Model> or null");
|
|
1151
|
-
super(t,
|
|
1158
|
+
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1152
1159
|
}
|
|
1153
1160
|
isSingle() {
|
|
1154
1161
|
return !1;
|
|
@@ -1156,8 +1163,8 @@ class Ae extends N {
|
|
|
1156
1163
|
isMultiple() {
|
|
1157
1164
|
return !0;
|
|
1158
1165
|
}
|
|
1159
|
-
get(
|
|
1160
|
-
return this.query().get(
|
|
1166
|
+
get(e) {
|
|
1167
|
+
return this.query().get(e);
|
|
1161
1168
|
}
|
|
1162
1169
|
all() {
|
|
1163
1170
|
return this.query().all();
|
|
@@ -1165,46 +1172,46 @@ class Ae extends N {
|
|
|
1165
1172
|
first() {
|
|
1166
1173
|
return this.query().first();
|
|
1167
1174
|
}
|
|
1168
|
-
find(
|
|
1169
|
-
return this.query().find(
|
|
1175
|
+
find(e) {
|
|
1176
|
+
return this.query().find(e);
|
|
1170
1177
|
}
|
|
1171
|
-
async saveManyQuietly(
|
|
1172
|
-
if (!Array.isArray(
|
|
1178
|
+
async saveManyQuietly(e) {
|
|
1179
|
+
if (!Array.isArray(e) || !e.every(d.isModel))
|
|
1173
1180
|
throw new f("HasMany.saveManyQuietly()", "Model[]");
|
|
1174
|
-
if (!
|
|
1175
|
-
throw new T("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(),
|
|
1176
|
-
await Promise.all(
|
|
1181
|
+
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
1182
|
+
throw new T("HasMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
1183
|
+
await Promise.all(e.map((t) => (t.setAttribute(this.getForeignKey(), this.parent.getKey()), t.save())));
|
|
1177
1184
|
}
|
|
1178
|
-
async saveMany(
|
|
1179
|
-
await this.saveManyQuietly(
|
|
1185
|
+
async saveMany(e) {
|
|
1186
|
+
await this.saveManyQuietly(e), this.items ? this.items.splice(0, this.items.count(), ...e) : this.items = K(e);
|
|
1180
1187
|
}
|
|
1181
|
-
async save(
|
|
1182
|
-
await this.saveQuietly(
|
|
1188
|
+
async save(e) {
|
|
1189
|
+
await this.saveQuietly(e), this.items === null ? this.items = K([e]) : this.items.push(e);
|
|
1183
1190
|
}
|
|
1184
1191
|
}
|
|
1185
1192
|
class he extends N {
|
|
1186
1193
|
query() {
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
this.items =
|
|
1194
|
+
const e = this.getRelated().query();
|
|
1195
|
+
e.once("success", (r) => {
|
|
1196
|
+
this.items = r.items;
|
|
1190
1197
|
});
|
|
1191
|
-
const
|
|
1192
|
-
return
|
|
1198
|
+
const t = this.guessInverseRelation();
|
|
1199
|
+
return e.where(t + "_id", this.parent.getKey()), e.where(t + "_type", this.getRelated().getSchemaName()), e.lock(`where.${t}_id`), e.lock(`where.${t}_type`), e;
|
|
1193
1200
|
}
|
|
1194
|
-
async saveQuietly(
|
|
1195
|
-
if (!d.isModel(
|
|
1201
|
+
async saveQuietly(e) {
|
|
1202
|
+
if (!d.isModel(e))
|
|
1196
1203
|
throw new f("MorphOneOrMany.saveQuietly()");
|
|
1197
|
-
if (
|
|
1198
|
-
throw new T("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(),
|
|
1199
|
-
const
|
|
1200
|
-
|
|
1204
|
+
if (e.getType() !== this.getRelated().getSchemaName())
|
|
1205
|
+
throw new T("MorphOneOrMany.saveQuietly()", this.getRelated().getSchemaName(), e.getType());
|
|
1206
|
+
const t = this.guessInverseRelation();
|
|
1207
|
+
e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
|
|
1201
1208
|
}
|
|
1202
1209
|
}
|
|
1203
1210
|
class Ne extends he {
|
|
1204
|
-
constructor(t,
|
|
1205
|
-
if (
|
|
1211
|
+
constructor(e, t, r, i = null) {
|
|
1212
|
+
if (i !== null && !(i instanceof b && i.every(d.isModel)))
|
|
1206
1213
|
throw new f("MorphMany.constructor()", "Collection<Model> or null");
|
|
1207
|
-
super(t,
|
|
1214
|
+
super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i;
|
|
1208
1215
|
}
|
|
1209
1216
|
isSingle() {
|
|
1210
1217
|
return !1;
|
|
@@ -1212,8 +1219,8 @@ class Ne extends he {
|
|
|
1212
1219
|
isMultiple() {
|
|
1213
1220
|
return !0;
|
|
1214
1221
|
}
|
|
1215
|
-
get(
|
|
1216
|
-
return this.query().get(
|
|
1222
|
+
get(e) {
|
|
1223
|
+
return this.query().get(e);
|
|
1217
1224
|
}
|
|
1218
1225
|
all() {
|
|
1219
1226
|
return this.query().all();
|
|
@@ -1221,28 +1228,28 @@ class Ne extends he {
|
|
|
1221
1228
|
first() {
|
|
1222
1229
|
return this.query().first();
|
|
1223
1230
|
}
|
|
1224
|
-
find(
|
|
1225
|
-
return this.query().find(
|
|
1231
|
+
find(e) {
|
|
1232
|
+
return this.query().find(e);
|
|
1226
1233
|
}
|
|
1227
|
-
async saveManyQuietly(
|
|
1228
|
-
if (!Array.isArray(
|
|
1234
|
+
async saveManyQuietly(e) {
|
|
1235
|
+
if (!Array.isArray(e) || !e.every(d.isModel))
|
|
1229
1236
|
throw new f("MorphMany.saveManyQuietly()");
|
|
1230
|
-
if (!
|
|
1231
|
-
throw new T("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(),
|
|
1232
|
-
await Promise.all(
|
|
1237
|
+
if (!e.every((t) => t.getType() === this.getRelated().getSchemaName()))
|
|
1238
|
+
throw new T("MorphMany.saveManyQuietly()", this.getRelated().getSchemaName(), e.map((t) => t.getType()).join(", "));
|
|
1239
|
+
await Promise.all(e.map((t) => (t.setAttribute(this.getName() + "_id", this.parent.getKey()), t.setAttribute(this.getName() + "_type", this.parent.getType()), t.save())));
|
|
1233
1240
|
}
|
|
1234
|
-
async
|
|
1235
|
-
await this.
|
|
1241
|
+
async saveMany(e) {
|
|
1242
|
+
await this.saveManyQuietly(e);
|
|
1243
|
+
const t = await this.all();
|
|
1244
|
+
this.items ? this.items.splice(0, this.items.count(), ...t) : this.items = t;
|
|
1236
1245
|
}
|
|
1237
|
-
async
|
|
1238
|
-
await this.
|
|
1239
|
-
const e = await this.all();
|
|
1240
|
-
this.items ? this.items.splice(0, this.items.count(), ...e) : this.items = e;
|
|
1246
|
+
async save(e) {
|
|
1247
|
+
await this.saveQuietly(e), this.items ? this.items.push(e) : this.items = await this.all();
|
|
1241
1248
|
}
|
|
1242
1249
|
}
|
|
1243
|
-
class
|
|
1244
|
-
constructor(t,
|
|
1245
|
-
if (super(t,
|
|
1250
|
+
class ke extends he {
|
|
1251
|
+
constructor(e, t, r, i = null) {
|
|
1252
|
+
if (super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !d.isModel(i))
|
|
1246
1253
|
throw new f("MorphOne.constructor()", "Model or null");
|
|
1247
1254
|
}
|
|
1248
1255
|
isSingle() {
|
|
@@ -1254,11 +1261,11 @@ class qe extends he {
|
|
|
1254
1261
|
get() {
|
|
1255
1262
|
return this.query().first();
|
|
1256
1263
|
}
|
|
1257
|
-
async save(
|
|
1258
|
-
await this.saveQuietly(
|
|
1264
|
+
async save(e) {
|
|
1265
|
+
await this.saveQuietly(e), this.items = e;
|
|
1259
1266
|
}
|
|
1260
1267
|
}
|
|
1261
|
-
class
|
|
1268
|
+
class qe extends ae {
|
|
1262
1269
|
getRelated() {
|
|
1263
1270
|
return this.services.model.make(
|
|
1264
1271
|
this.parent.getAttribute(this.getName() + "_type")
|
|
@@ -1272,12 +1279,12 @@ class Ke extends ae {
|
|
|
1272
1279
|
// this.of(this.parent.getAttribute(this.getName() + '_type') as string);
|
|
1273
1280
|
// return super.query();
|
|
1274
1281
|
// }
|
|
1275
|
-
async associate(
|
|
1276
|
-
if (!d.isModel(
|
|
1282
|
+
async associate(e) {
|
|
1283
|
+
if (!d.isModel(e))
|
|
1277
1284
|
throw new f("MorphTo.associate()");
|
|
1278
|
-
return
|
|
1279
|
-
[this.getName() + "_id"]:
|
|
1280
|
-
[this.getName() + "_type"]:
|
|
1285
|
+
return e.exists || await e.save(), this.parent.update({
|
|
1286
|
+
[this.getName() + "_id"]: e.getKey(),
|
|
1287
|
+
[this.getName() + "_type"]: e.getType()
|
|
1281
1288
|
});
|
|
1282
1289
|
}
|
|
1283
1290
|
dissociate() {
|
|
@@ -1287,135 +1294,135 @@ class Ke extends ae {
|
|
|
1287
1294
|
});
|
|
1288
1295
|
}
|
|
1289
1296
|
}
|
|
1290
|
-
class
|
|
1297
|
+
class Ke extends ue {
|
|
1291
1298
|
query() {
|
|
1292
|
-
const
|
|
1293
|
-
return
|
|
1299
|
+
const e = super.query(), t = this.guessInverseRelation();
|
|
1300
|
+
return e.where(t + "_id", this.parent.getKey()), e.where(t + "_type", this.parent.getType()), e.lock(`where.${t}_id`), e.lock(`where.${t}_type`), e;
|
|
1294
1301
|
}
|
|
1295
1302
|
}
|
|
1296
1303
|
var Y, Z;
|
|
1297
1304
|
class je extends (Z = A, Y = Symbol.toStringTag, Z) {
|
|
1298
|
-
constructor(
|
|
1305
|
+
constructor(t) {
|
|
1299
1306
|
super();
|
|
1300
1307
|
p(this, "_models", {});
|
|
1301
1308
|
p(this, Y, "ModelService");
|
|
1302
|
-
this._schema =
|
|
1309
|
+
this._schema = t;
|
|
1303
1310
|
}
|
|
1304
|
-
boot(
|
|
1305
|
-
this._schema && Object.keys(this._schema).forEach((
|
|
1306
|
-
const
|
|
1311
|
+
boot(t) {
|
|
1312
|
+
this._schema && Object.keys(this._schema).forEach((r) => {
|
|
1313
|
+
const i = this[`model${y.studly(r)}`], l = this.model(
|
|
1307
1314
|
_e(
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1315
|
+
t.make("config"),
|
|
1316
|
+
t.make("log"),
|
|
1317
|
+
t.make("model"),
|
|
1318
|
+
t.make("route"),
|
|
1319
|
+
r
|
|
1313
1320
|
),
|
|
1314
|
-
|
|
1315
|
-
),
|
|
1316
|
-
this._models[
|
|
1321
|
+
r
|
|
1322
|
+
), m = i(l);
|
|
1323
|
+
this._models[r] = Te(t.make("model"), r, m);
|
|
1317
1324
|
});
|
|
1318
1325
|
}
|
|
1319
|
-
schema(
|
|
1320
|
-
if (!this._schema ||
|
|
1321
|
-
throw new
|
|
1322
|
-
return
|
|
1326
|
+
schema(t) {
|
|
1327
|
+
if (!this._schema || t && !this._schema[t])
|
|
1328
|
+
throw new q(t || "undefined");
|
|
1329
|
+
return t ? this._schema[t] : this._schema;
|
|
1323
1330
|
}
|
|
1324
|
-
make(
|
|
1325
|
-
if (
|
|
1326
|
-
throw new
|
|
1327
|
-
return
|
|
1331
|
+
make(t) {
|
|
1332
|
+
if (t && !this._models[t])
|
|
1333
|
+
throw new q(t);
|
|
1334
|
+
return t ? this._models[t] : this._models;
|
|
1328
1335
|
}
|
|
1329
|
-
getRelationConstructors(
|
|
1336
|
+
getRelationConstructors(t) {
|
|
1330
1337
|
return this.relationMap({
|
|
1331
1338
|
BelongsTo: ae,
|
|
1332
1339
|
BelongsToMany: ue,
|
|
1333
1340
|
HasOne: Re,
|
|
1334
1341
|
HasMany: Ae,
|
|
1335
1342
|
MorphMany: Ne,
|
|
1336
|
-
MorphOne:
|
|
1337
|
-
MorphTo:
|
|
1338
|
-
MorphToMany:
|
|
1339
|
-
},
|
|
1343
|
+
MorphOne: ke,
|
|
1344
|
+
MorphTo: qe,
|
|
1345
|
+
MorphToMany: Ke
|
|
1346
|
+
}, t);
|
|
1340
1347
|
}
|
|
1341
1348
|
toString() {
|
|
1342
1349
|
return "model";
|
|
1343
1350
|
}
|
|
1344
1351
|
}
|
|
1345
|
-
const Oe =
|
|
1352
|
+
const Oe = re(je);
|
|
1346
1353
|
var ee, te;
|
|
1347
1354
|
class Be extends (te = Error, ee = Symbol.toStringTag, te) {
|
|
1348
|
-
constructor(
|
|
1349
|
-
super(`[Luminix] Route "${
|
|
1355
|
+
constructor(t) {
|
|
1356
|
+
super(`[Luminix] Route "${t}" not found`);
|
|
1350
1357
|
p(this, ee, "RouteNotFoundException");
|
|
1351
1358
|
}
|
|
1352
1359
|
}
|
|
1353
1360
|
class Ce {
|
|
1354
|
-
constructor(t,
|
|
1355
|
-
this.routes =
|
|
1361
|
+
constructor(e, t, r, i = "") {
|
|
1362
|
+
this.routes = e, this.error = t, this.http = r, this.appUrl = i;
|
|
1356
1363
|
}
|
|
1357
|
-
isRouteTuple(
|
|
1358
|
-
if (!Array.isArray(
|
|
1364
|
+
isRouteTuple(e) {
|
|
1365
|
+
if (!Array.isArray(e) || e.length < 2)
|
|
1359
1366
|
return !1;
|
|
1360
|
-
const [
|
|
1361
|
-
if (typeof
|
|
1367
|
+
const [t, ...r] = e;
|
|
1368
|
+
if (typeof t != "string")
|
|
1362
1369
|
return !1;
|
|
1363
|
-
const
|
|
1364
|
-
return !!
|
|
1370
|
+
const i = ["get", "post", "put", "patch", "delete"];
|
|
1371
|
+
return !!r.every((l) => i.includes(l));
|
|
1365
1372
|
}
|
|
1366
|
-
extractGenerator(
|
|
1367
|
-
let
|
|
1368
|
-
return Array.isArray(
|
|
1373
|
+
extractGenerator(e) {
|
|
1374
|
+
let t, r = !1;
|
|
1375
|
+
return Array.isArray(e) ? [t, r] = e : t = e, [t, r];
|
|
1369
1376
|
}
|
|
1370
|
-
get(
|
|
1371
|
-
if (!this.exists(
|
|
1372
|
-
throw new Be(
|
|
1373
|
-
return d.get(this.routes,
|
|
1377
|
+
get(e) {
|
|
1378
|
+
if (!this.exists(e))
|
|
1379
|
+
throw new Be(e);
|
|
1380
|
+
return d.get(this.routes, e);
|
|
1374
1381
|
}
|
|
1375
|
-
url(
|
|
1376
|
-
return this.appUrl + this.path(
|
|
1382
|
+
url(e) {
|
|
1383
|
+
return this.appUrl + this.path(e);
|
|
1377
1384
|
}
|
|
1378
|
-
path(
|
|
1379
|
-
const [
|
|
1380
|
-
if (
|
|
1385
|
+
path(e) {
|
|
1386
|
+
const [t, r] = this.extractGenerator(e), i = this.get(t)[0].replace(/^\/|\/$/g, ""), l = /{([^}]+)}/g;
|
|
1387
|
+
if (r === !1) {
|
|
1381
1388
|
if (typeof this.replaceRouteParams != "function")
|
|
1382
1389
|
throw new E("RouteFacade");
|
|
1383
|
-
return this.replaceRouteParams(`/${
|
|
1390
|
+
return this.replaceRouteParams(`/${i}`);
|
|
1384
1391
|
}
|
|
1385
|
-
const
|
|
1386
|
-
if (
|
|
1387
|
-
throw new TypeError(`Missing values for parameter(s): ${
|
|
1392
|
+
const m = i.match(l), c = m ? m.map((h) => h.slice(1, -1)) : [], u = Object.keys(r), s = c.filter((h) => !u.includes(h)), n = u.filter((h) => !c.includes(h));
|
|
1393
|
+
if (s.length > 0)
|
|
1394
|
+
throw new TypeError(`Missing values for parameter(s): ${s.join(", ")}`);
|
|
1388
1395
|
if (n.length > 0)
|
|
1389
1396
|
throw new TypeError(`Unexpected parameters: ${n.join(", ")}`);
|
|
1390
|
-
return `/${
|
|
1397
|
+
return `/${c.reduce((h, g) => h.replace(`{${g}}`, `${r[g]}`), i)}`;
|
|
1391
1398
|
}
|
|
1392
|
-
methods(
|
|
1393
|
-
const [
|
|
1394
|
-
return this.get(
|
|
1399
|
+
methods(e) {
|
|
1400
|
+
const [t] = this.extractGenerator(e);
|
|
1401
|
+
return this.get(t).slice(1);
|
|
1395
1402
|
}
|
|
1396
|
-
exists(
|
|
1397
|
-
return d.has(this.routes,
|
|
1403
|
+
exists(e) {
|
|
1404
|
+
return d.has(this.routes, e) && this.isRouteTuple(d.get(this.routes, e));
|
|
1398
1405
|
}
|
|
1399
1406
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1400
|
-
async call(
|
|
1407
|
+
async call(e, t = (i) => i, r = "default") {
|
|
1401
1408
|
if (typeof this.clientOptions != "function" || typeof this.clientError != "function")
|
|
1402
1409
|
throw new E("RouteFacade");
|
|
1403
|
-
const [
|
|
1404
|
-
d.isEmpty(
|
|
1405
|
-
const n =
|
|
1406
|
-
this.error.clear(
|
|
1407
|
-
const a = await u[n](
|
|
1410
|
+
const [i, l] = this.extractGenerator(e), [, ...m] = this.get(i), c = this.url(l ? [i, l] : i), u = t(this.http()), s = this.clientOptions({}, i);
|
|
1411
|
+
d.isEmpty(s) || u.withOptions(s);
|
|
1412
|
+
const n = m[0] ?? s.method;
|
|
1413
|
+
this.error.clear(r);
|
|
1414
|
+
const a = await u[n](c);
|
|
1408
1415
|
if (pe(a)) {
|
|
1409
1416
|
const h = a.json("errors");
|
|
1410
|
-
this.error.set(Object.entries(h).reduce((g, [w, v]) => (g[w] = v.join(" "), g), {}),
|
|
1417
|
+
this.error.set(Object.entries(h).reduce((g, [w, v]) => (g[w] = v.join(" "), g), {}), r);
|
|
1411
1418
|
} else a.failed() && this.error.set(
|
|
1412
1419
|
this.clientError({ axios: a.json("message") }, {
|
|
1413
1420
|
response: a,
|
|
1414
|
-
name:
|
|
1415
|
-
replace:
|
|
1421
|
+
name: i,
|
|
1422
|
+
replace: l,
|
|
1416
1423
|
client: u
|
|
1417
1424
|
}),
|
|
1418
|
-
|
|
1425
|
+
r
|
|
1419
1426
|
);
|
|
1420
1427
|
return a;
|
|
1421
1428
|
}
|
|
@@ -1423,65 +1430,65 @@ class Ce {
|
|
|
1423
1430
|
return "route";
|
|
1424
1431
|
}
|
|
1425
1432
|
}
|
|
1426
|
-
const Ie =
|
|
1433
|
+
const Ie = re(Ce);
|
|
1427
1434
|
class Pe {
|
|
1428
1435
|
getClient() {
|
|
1429
1436
|
return new ge();
|
|
1430
1437
|
}
|
|
1431
|
-
baseUrl(
|
|
1432
|
-
return this.getClient().baseUrl(
|
|
1438
|
+
baseUrl(e) {
|
|
1439
|
+
return this.getClient().baseUrl(e);
|
|
1433
1440
|
}
|
|
1434
1441
|
asForm() {
|
|
1435
1442
|
return this.getClient().asForm();
|
|
1436
1443
|
}
|
|
1437
|
-
accept(
|
|
1438
|
-
return this.getClient().accept(
|
|
1444
|
+
accept(e) {
|
|
1445
|
+
return this.getClient().accept(e);
|
|
1439
1446
|
}
|
|
1440
1447
|
acceptJson() {
|
|
1441
1448
|
return this.getClient().acceptJson();
|
|
1442
1449
|
}
|
|
1443
|
-
withHeaders(
|
|
1444
|
-
return this.getClient().withHeaders(
|
|
1450
|
+
withHeaders(e) {
|
|
1451
|
+
return this.getClient().withHeaders(e);
|
|
1445
1452
|
}
|
|
1446
|
-
withOptions(
|
|
1447
|
-
return this.getClient().withOptions(
|
|
1453
|
+
withOptions(e) {
|
|
1454
|
+
return this.getClient().withOptions(e);
|
|
1448
1455
|
}
|
|
1449
|
-
withData(
|
|
1450
|
-
return this.getClient().withData(
|
|
1456
|
+
withData(e) {
|
|
1457
|
+
return this.getClient().withData(e);
|
|
1451
1458
|
}
|
|
1452
|
-
withQueryParameters(
|
|
1453
|
-
return this.getClient().withQueryParameters(
|
|
1459
|
+
withQueryParameters(e) {
|
|
1460
|
+
return this.getClient().withQueryParameters(e);
|
|
1454
1461
|
}
|
|
1455
|
-
withBasicAuth(
|
|
1456
|
-
return this.getClient().withBasicAuth(
|
|
1462
|
+
withBasicAuth(e, t) {
|
|
1463
|
+
return this.getClient().withBasicAuth(e, t);
|
|
1457
1464
|
}
|
|
1458
|
-
withToken(
|
|
1459
|
-
return this.getClient().withToken(
|
|
1465
|
+
withToken(e) {
|
|
1466
|
+
return this.getClient().withToken(e);
|
|
1460
1467
|
}
|
|
1461
1468
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1462
|
-
get(
|
|
1463
|
-
return this.getClient().get(
|
|
1469
|
+
get(e, t) {
|
|
1470
|
+
return this.getClient().get(e, t);
|
|
1464
1471
|
}
|
|
1465
1472
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1466
|
-
post(
|
|
1467
|
-
return this.getClient().post(
|
|
1473
|
+
post(e, t) {
|
|
1474
|
+
return this.getClient().post(e, t);
|
|
1468
1475
|
}
|
|
1469
1476
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1470
|
-
put(
|
|
1471
|
-
return this.getClient().put(
|
|
1477
|
+
put(e, t) {
|
|
1478
|
+
return this.getClient().put(e, t);
|
|
1472
1479
|
}
|
|
1473
1480
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1474
|
-
patch(
|
|
1475
|
-
return this.getClient().patch(
|
|
1481
|
+
patch(e, t) {
|
|
1482
|
+
return this.getClient().patch(e, t);
|
|
1476
1483
|
}
|
|
1477
1484
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1478
|
-
delete(
|
|
1479
|
-
return this.getClient().delete(
|
|
1485
|
+
delete(e, t) {
|
|
1486
|
+
return this.getClient().delete(e, t);
|
|
1480
1487
|
}
|
|
1481
1488
|
}
|
|
1482
1489
|
const Qe = ne(Pe);
|
|
1483
|
-
var se,
|
|
1484
|
-
class
|
|
1490
|
+
var se, ie;
|
|
1491
|
+
class Le extends (ie = ye, se = Symbol.toStringTag, ie) {
|
|
1485
1492
|
constructor() {
|
|
1486
1493
|
super(...arguments);
|
|
1487
1494
|
p(this, se, "LuminixServiceProvider");
|
|
@@ -1500,86 +1507,86 @@ class De extends (re = ye, se = Symbol.toStringTag, re) {
|
|
|
1500
1507
|
this.app.make("model"),
|
|
1501
1508
|
this.app.make("route")
|
|
1502
1509
|
)), this.app.singleton("config", () => {
|
|
1503
|
-
const
|
|
1504
|
-
return
|
|
1510
|
+
const t = new _(d.omit(this.app.configuration, "manifest"));
|
|
1511
|
+
return t.has("auth.user") || t.set("auth.user", null), t.lock("auth.user"), t;
|
|
1505
1512
|
}), this.app.singleton("error", () => new ve()), this.app.singleton("http", () => new Qe()), this.app.singleton("log", () => {
|
|
1506
|
-
var
|
|
1507
|
-
return new be(((
|
|
1513
|
+
var t;
|
|
1514
|
+
return new be(((t = this.app.configuration.app) == null ? void 0 : t.debug) ?? !1);
|
|
1508
1515
|
}), this.app.singleton("model", () => {
|
|
1509
|
-
var
|
|
1516
|
+
var t;
|
|
1510
1517
|
return new Oe(
|
|
1511
|
-
((
|
|
1518
|
+
((t = this.app.configuration.manifest) == null ? void 0 : t.models) ?? {}
|
|
1512
1519
|
);
|
|
1513
1520
|
}), this.app.singleton("route", () => {
|
|
1514
|
-
var
|
|
1521
|
+
var t, r;
|
|
1515
1522
|
return new Ie(
|
|
1516
|
-
((
|
|
1523
|
+
((t = this.app.configuration.manifest) == null ? void 0 : t.routes) ?? {},
|
|
1517
1524
|
this.app.make("error"),
|
|
1518
1525
|
() => this.app.make("http"),
|
|
1519
|
-
(
|
|
1526
|
+
(r = this.app.configuration.app) == null ? void 0 : r.url
|
|
1520
1527
|
);
|
|
1521
1528
|
});
|
|
1522
1529
|
}
|
|
1523
1530
|
registerMacros() {
|
|
1524
|
-
this.app.macro("environment", (...
|
|
1525
|
-
return typeof
|
|
1531
|
+
this.app.macro("environment", (...t) => t.length > 0 ? t.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"), d.macro("isModel", function(t) {
|
|
1532
|
+
return typeof t == "object" && t !== null && t.__isModel === !0;
|
|
1526
1533
|
});
|
|
1527
1534
|
}
|
|
1528
1535
|
}
|
|
1529
|
-
class
|
|
1536
|
+
class De {
|
|
1530
1537
|
constructor() {
|
|
1531
1538
|
p(this, "app");
|
|
1532
1539
|
}
|
|
1533
1540
|
getFacadeAccessor() {
|
|
1534
1541
|
return this.app || (this.app = new (ne(me))([
|
|
1535
|
-
|
|
1542
|
+
Le
|
|
1536
1543
|
])), this.app;
|
|
1537
1544
|
}
|
|
1538
1545
|
down() {
|
|
1539
1546
|
this.app && (this.app.flush(), delete this.app);
|
|
1540
1547
|
}
|
|
1541
|
-
setInstance(
|
|
1542
|
-
this.down(), this.app =
|
|
1548
|
+
setInstance(e) {
|
|
1549
|
+
this.down(), this.app = e;
|
|
1543
1550
|
}
|
|
1544
1551
|
}
|
|
1545
|
-
const x = M(
|
|
1552
|
+
const x = M(De);
|
|
1546
1553
|
function $(o = void 0) {
|
|
1547
1554
|
return typeof o != "string" ? x : x.make(o);
|
|
1548
1555
|
}
|
|
1549
1556
|
function Ye() {
|
|
1550
1557
|
return $("auth");
|
|
1551
1558
|
}
|
|
1552
|
-
function Ze(o,
|
|
1553
|
-
const
|
|
1554
|
-
return typeof o > "u" ?
|
|
1559
|
+
function Ze(o, e) {
|
|
1560
|
+
const t = $("config");
|
|
1561
|
+
return typeof o > "u" ? t : t.get(o, e);
|
|
1555
1562
|
}
|
|
1556
|
-
function et(o,
|
|
1557
|
-
return o ? $().make("error").get(o,
|
|
1563
|
+
function et(o, e = "default") {
|
|
1564
|
+
return o ? $().make("error").get(o, e) : $().make("error");
|
|
1558
1565
|
}
|
|
1559
1566
|
function tt(...o) {
|
|
1560
|
-
const
|
|
1561
|
-
return o.length ?
|
|
1567
|
+
const e = $("log");
|
|
1568
|
+
return o.length ? e.debug(...o) : e;
|
|
1562
1569
|
}
|
|
1563
1570
|
function st(o) {
|
|
1564
|
-
const
|
|
1565
|
-
return o ?
|
|
1571
|
+
const e = $("model");
|
|
1572
|
+
return o ? e.make(o) : e;
|
|
1566
1573
|
}
|
|
1567
|
-
function
|
|
1568
|
-
const
|
|
1569
|
-
return o ?
|
|
1574
|
+
function it(o, e = !1) {
|
|
1575
|
+
const t = $("route");
|
|
1576
|
+
return o ? e ? t.url([o, e]) : t.url(o) : t;
|
|
1570
1577
|
}
|
|
1571
|
-
class
|
|
1578
|
+
class He {
|
|
1572
1579
|
getFacadeAccessor() {
|
|
1573
1580
|
return "auth";
|
|
1574
1581
|
}
|
|
1575
1582
|
}
|
|
1576
|
-
const
|
|
1583
|
+
const rt = M(He, x);
|
|
1577
1584
|
class Je {
|
|
1578
1585
|
getFacadeAccessor() {
|
|
1579
1586
|
return "config";
|
|
1580
1587
|
}
|
|
1581
1588
|
}
|
|
1582
|
-
const nt = M(Je, x), ot = (o) => o instanceof fe && o.unprocessableEntity() && typeof o.json("message") == "string" && typeof o.json("errors") == "object" && o.json("errors") !== null && Object.values(o.json("errors")).every((
|
|
1589
|
+
const nt = M(Je, x), ot = (o) => o instanceof fe && o.unprocessableEntity() && typeof o.json("message") == "string" && typeof o.json("errors") == "object" && o.json("errors") !== null && Object.values(o.json("errors")).every((e) => Array.isArray(e) && e.every((t) => typeof t == "string"));
|
|
1583
1590
|
class Ue {
|
|
1584
1591
|
getFacadeAccessor() {
|
|
1585
1592
|
return "error";
|
|
@@ -1592,37 +1599,37 @@ class Fe {
|
|
|
1592
1599
|
}
|
|
1593
1600
|
}
|
|
1594
1601
|
const ut = M(Fe, x);
|
|
1595
|
-
class
|
|
1602
|
+
class We {
|
|
1596
1603
|
getFacadeAccessor() {
|
|
1597
1604
|
return "log";
|
|
1598
1605
|
}
|
|
1599
1606
|
}
|
|
1600
|
-
const ht = M(
|
|
1601
|
-
class
|
|
1607
|
+
const ht = M(We, x);
|
|
1608
|
+
class Ge {
|
|
1602
1609
|
getFacadeAccessor() {
|
|
1603
1610
|
return "model";
|
|
1604
1611
|
}
|
|
1605
1612
|
}
|
|
1606
|
-
const lt = M(
|
|
1607
|
-
class
|
|
1613
|
+
const lt = M(Ge, x);
|
|
1614
|
+
class Ve {
|
|
1608
1615
|
getFacadeAccessor() {
|
|
1609
1616
|
return "route";
|
|
1610
1617
|
}
|
|
1611
1618
|
}
|
|
1612
|
-
const ct = M(
|
|
1619
|
+
const ct = M(Ve, x);
|
|
1613
1620
|
class dt {
|
|
1614
1621
|
constructor() {
|
|
1615
1622
|
p(this, "name");
|
|
1616
1623
|
p(this, "version");
|
|
1617
1624
|
}
|
|
1618
|
-
register(
|
|
1625
|
+
register(e) {
|
|
1619
1626
|
}
|
|
1620
|
-
boot(
|
|
1627
|
+
boot(e) {
|
|
1621
1628
|
}
|
|
1622
1629
|
}
|
|
1623
1630
|
export {
|
|
1624
1631
|
x as App,
|
|
1625
|
-
|
|
1632
|
+
rt as Auth,
|
|
1626
1633
|
nt as Config,
|
|
1627
1634
|
at as Error,
|
|
1628
1635
|
ut as Http,
|
|
@@ -1632,11 +1639,11 @@ export {
|
|
|
1632
1639
|
ct as Route,
|
|
1633
1640
|
$ as app,
|
|
1634
1641
|
Ye as auth,
|
|
1635
|
-
|
|
1642
|
+
K as collect,
|
|
1636
1643
|
Ze as config,
|
|
1637
1644
|
et as error,
|
|
1638
1645
|
ot as isValidationError,
|
|
1639
1646
|
tt as log,
|
|
1640
1647
|
st as model,
|
|
1641
|
-
|
|
1648
|
+
it as route
|
|
1642
1649
|
};
|