@luminix/core 0.4.8 → 1.0.1
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/README.md +63 -2
- package/dist/core.js +113 -140
- package/package.json +4 -5
- package/types/facades/Error.d.ts +1 -4
- package/types/index.d.ts +2 -3
- package/types/types/App.d.ts +0 -3
- package/babel.config.json +0 -5
- package/types/contracts/Plugin.d.ts +0 -8
- package/types/types/Plugin.d.ts +0 -4
package/README.md
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @luminix/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Biblioteca JavaScript fundamental do stack Luminix. Agnóstica de framework frontend — funciona com React, Vue, Svelte ou vanilla JS/TS.
|
|
4
|
+
|
|
5
|
+
## Posição no stack
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
@luminix/mui-cms ← CMS completo com Material UI
|
|
9
|
+
└── @luminix/react ← Integração com React
|
|
10
|
+
└── @luminix/core ← este pacote
|
|
11
|
+
└── @luminix/support
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## O que faz
|
|
15
|
+
|
|
16
|
+
- **Models** — API Eloquent-like para consumir os endpoints REST do `luminix/backend`
|
|
17
|
+
- **Facades** — `App`, `Auth`, `Config`, `Route`, `Http`, `Log`, `Error`
|
|
18
|
+
- **Plugins e Reducers** — para estender e customizar o comportamento
|
|
19
|
+
- **Helpers** — `app()`, `auth()`, `config()`, `model()`, `route()`, `log()`, `error()`, `collect()`
|
|
20
|
+
|
|
21
|
+
## Pré-requisitos
|
|
22
|
+
|
|
23
|
+
Uma aplicação Laravel 11 com:
|
|
24
|
+
- [`luminix/backend`](https://github.com/luminix-cms/backend) — gera a API REST automaticamente
|
|
25
|
+
- [`luminix/frontend`](https://github.com/luminix-cms/frontend) — injeta os dados de boot na página via `@luminixEmbed()`
|
|
26
|
+
|
|
27
|
+
## Instalação
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @luminix/core
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Uso rápido
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { App, model, auth, config } from '@luminix/core';
|
|
37
|
+
|
|
38
|
+
// Inicializa (lê config do @luminixEmbed() automaticamente)
|
|
39
|
+
App.create();
|
|
40
|
+
|
|
41
|
+
// Acessa dados de configuração
|
|
42
|
+
console.log(config('app.name'));
|
|
43
|
+
|
|
44
|
+
// Verifica autenticação
|
|
45
|
+
if (auth().check()) {
|
|
46
|
+
console.log(`Bem-vindo, ${auth().user()?.name}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Usa um model
|
|
50
|
+
const User = model('user');
|
|
51
|
+
const { data } = await User.where('role', 'admin').orderBy('name').get();
|
|
52
|
+
data.each((user) => console.log(user.name, user.email));
|
|
53
|
+
|
|
54
|
+
// Cria um registro
|
|
55
|
+
const post = await model('post').create({ title: 'Olá mundo', content: '...' });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Documentação
|
|
59
|
+
|
|
60
|
+
[Documentação completa (pt-BR) →](docs/pt-BR/README.md)
|
|
61
|
+
|
|
62
|
+
## Licença
|
|
63
|
+
|
|
64
|
+
MIT
|
package/dist/core.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var ce = Object.defineProperty;
|
|
2
2
|
var de = (o, e, t) => e in o ? ce(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
3
|
var g = (o, e, t) => de(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import { reader as pe, PropertyBag as _, EventSource as
|
|
5
|
-
class
|
|
4
|
+
import { reader as pe, PropertyBag as _, EventSource as k, Collection as b, Query as S, Obj as p, Str as y, Reducible as re, isValidationError as ge, Macroable as ne, Client as me, ServiceProvider as ye, MakeFacade as M, Application as fe } from "@luminix/support";
|
|
5
|
+
class we {
|
|
6
6
|
constructor(e, t, r) {
|
|
7
7
|
g(this, "_user");
|
|
8
8
|
this.config = e, this.model = t, this.route = r;
|
|
@@ -51,7 +51,7 @@ class ve {
|
|
|
51
51
|
return ((e = this.user()) == null ? void 0 : e.getKey()) || null;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
class
|
|
54
|
+
class ve {
|
|
55
55
|
constructor() {
|
|
56
56
|
g(this, "bags");
|
|
57
57
|
const e = {};
|
|
@@ -81,7 +81,7 @@ class be {
|
|
|
81
81
|
this.bag(e).set(".", {});
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
class
|
|
84
|
+
class be {
|
|
85
85
|
constructor(e) {
|
|
86
86
|
this._debug = e;
|
|
87
87
|
}
|
|
@@ -110,14 +110,14 @@ class xe {
|
|
|
110
110
|
this._debug && console.debug(...e);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
var
|
|
114
|
-
class
|
|
113
|
+
var O, j;
|
|
114
|
+
class xe extends (j = Error, O = Symbol.toStringTag, j) {
|
|
115
115
|
constructor(t) {
|
|
116
116
|
super(`[Luminix] Model "${t}" does not have a primary key`);
|
|
117
|
-
g(this,
|
|
117
|
+
g(this, O, "ModelWithoutPrimaryKeyException");
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
class
|
|
120
|
+
class Me extends k {
|
|
121
121
|
constructor(t, r, i = {}) {
|
|
122
122
|
super();
|
|
123
123
|
g(this, "bag");
|
|
@@ -266,7 +266,7 @@ class Ee extends A {
|
|
|
266
266
|
async find(t) {
|
|
267
267
|
const r = this.services.model.schema(this.abstract).primaryKey;
|
|
268
268
|
if (!r)
|
|
269
|
-
throw new
|
|
269
|
+
throw new xe(this.abstract);
|
|
270
270
|
const i = await this.where(r, t).limit(1).exec();
|
|
271
271
|
return this.emit("success", {
|
|
272
272
|
response: i,
|
|
@@ -301,20 +301,20 @@ class w extends (C = TypeError, B = Symbol.toStringTag, C) {
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
var I, P;
|
|
304
|
-
class
|
|
304
|
+
class Ee extends (P = Error, I = Symbol.toStringTag, P) {
|
|
305
305
|
constructor(t, r, i, l) {
|
|
306
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}".`);
|
|
307
307
|
g(this, I, "NoInverseRelationException");
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
var Q, L;
|
|
311
|
-
class
|
|
311
|
+
class $e extends (L = Error, Q = Symbol.toStringTag, L) {
|
|
312
312
|
constructor(t) {
|
|
313
313
|
super(`[Luminix] Relation "${t}" is not supported`);
|
|
314
314
|
g(this, Q, "UnsupportedRelationException");
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
|
-
class
|
|
317
|
+
class N {
|
|
318
318
|
constructor(e, t, r, i = null) {
|
|
319
319
|
g(this, "unsubscribeQuery", null);
|
|
320
320
|
if (this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !p.isModel(i) && !(i instanceof b && i.every(p.isModel)))
|
|
@@ -349,13 +349,13 @@ class k {
|
|
|
349
349
|
MorphToMany: ["MorphToMany"]
|
|
350
350
|
}, this.parent, t, this.getRelated());
|
|
351
351
|
if (!(t in r))
|
|
352
|
-
throw new
|
|
352
|
+
throw new $e(t);
|
|
353
353
|
for (const i in e) {
|
|
354
354
|
const l = e[i];
|
|
355
355
|
if ((l.model === this.parent.getType() || ["MorphOne", "MorphMany"].includes(t)) && r[t].includes(l.type))
|
|
356
356
|
return i;
|
|
357
357
|
}
|
|
358
|
-
throw new
|
|
358
|
+
throw new Ee(this.parent.getType(), t, this.getRelated().getSchemaName(), r[t].join(" or "));
|
|
359
359
|
}
|
|
360
360
|
set(e) {
|
|
361
361
|
if (e !== null && !p.isModel(e) && !(e instanceof b && e.every(p.isModel)))
|
|
@@ -439,14 +439,14 @@ class k {
|
|
|
439
439
|
// }
|
|
440
440
|
}
|
|
441
441
|
var D, H;
|
|
442
|
-
class
|
|
442
|
+
class $ extends (H = Error, D = Symbol.toStringTag, H) {
|
|
443
443
|
constructor(t) {
|
|
444
444
|
super(`[Luminix] Expected ${t} to be reducible.`);
|
|
445
445
|
g(this, D, "NotReducibleException");
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
448
|
var J, U;
|
|
449
|
-
class
|
|
449
|
+
class Te extends (U = Error, J = Symbol.toStringTag, U) {
|
|
450
450
|
constructor() {
|
|
451
451
|
super("[Luminix] Method not implemented.");
|
|
452
452
|
g(this, J, "MethodNotImplementedException");
|
|
@@ -459,9 +459,9 @@ class oe extends (W = Error, F = Symbol.toStringTag, W) {
|
|
|
459
459
|
g(this, F, "ModelNotPersistedException");
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
|
-
function
|
|
462
|
+
function Se(o, e, t, r, i) {
|
|
463
463
|
var l, m, c;
|
|
464
|
-
return c = class extends (m =
|
|
464
|
+
return c = class extends (m = k, l = Symbol.toStringTag, m) {
|
|
465
465
|
constructor(s = {}) {
|
|
466
466
|
super();
|
|
467
467
|
g(this, "_attributes", new _({}));
|
|
@@ -485,7 +485,7 @@ function _e(o, e, t, r, i) {
|
|
|
485
485
|
return;
|
|
486
486
|
const n = t.getRelationConstructors(i);
|
|
487
487
|
Object.entries(s).forEach(([a, h]) => {
|
|
488
|
-
const { type: d } = h, v = d in n ? n[d] :
|
|
488
|
+
const { type: d } = h, v = d in n ? n[d] : N;
|
|
489
489
|
this._relations[a] = new v(
|
|
490
490
|
{ model: t, route: r },
|
|
491
491
|
{ name: a, ...h },
|
|
@@ -495,7 +495,7 @@ function _e(o, e, t, r, i) {
|
|
|
495
495
|
});
|
|
496
496
|
}
|
|
497
497
|
makeAttributes(s) {
|
|
498
|
-
const { relations: n, attributes: a } = t.schema(i), h = Object.keys(n || {}), d = p.omit(s, ...h), v = (f) => {
|
|
498
|
+
const { relations: n, attributes: a = [] } = t.schema(i), h = Object.keys(n || {}), d = p.omit(s, ...h), v = (f) => {
|
|
499
499
|
const T = a.find((le) => le.name == f);
|
|
500
500
|
return T ? !(f in d) && T.nullable : !1;
|
|
501
501
|
};
|
|
@@ -634,14 +634,11 @@ function _e(o, e, t, r, i) {
|
|
|
634
634
|
s in this.casts && (n = this.cast(n, this.casts[s]));
|
|
635
635
|
const a = t[`model${y.studly(i)}Get${y.studly(s)}Attribute`];
|
|
636
636
|
if (typeof a != "function")
|
|
637
|
-
throw new
|
|
637
|
+
throw new $("ModelFacade");
|
|
638
638
|
return a.bind(t)(n, this);
|
|
639
639
|
}
|
|
640
640
|
setAttribute(s, n) {
|
|
641
|
-
const
|
|
642
|
-
if (typeof a != "function")
|
|
643
|
-
throw new E("ModelFacade");
|
|
644
|
-
const h = a.bind(t)(
|
|
641
|
+
const h = t[`model${y.studly(i)}Set${y.studly(s)}Attribute`].bind(t)(
|
|
645
642
|
this.mutate(n, this.casts[s]),
|
|
646
643
|
this
|
|
647
644
|
);
|
|
@@ -670,7 +667,7 @@ function _e(o, e, t, r, i) {
|
|
|
670
667
|
const n = p.pick(s, ...this.fillable), a = Object.entries(n).reduce((h, [d, v]) => {
|
|
671
668
|
const f = t[`model${y.studly(i)}Set${y.studly(d)}Attribute`];
|
|
672
669
|
if (typeof f != "function")
|
|
673
|
-
throw new
|
|
670
|
+
throw new $("ModelFacade");
|
|
674
671
|
return h[d] = f.bind(t)(
|
|
675
672
|
this.mutate(v, this.casts[d]),
|
|
676
673
|
this
|
|
@@ -699,7 +696,7 @@ function _e(o, e, t, r, i) {
|
|
|
699
696
|
toJson() {
|
|
700
697
|
const s = 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), {}), n = t[`model${y.studly(i)}Json`];
|
|
701
698
|
if (typeof n != "function")
|
|
702
|
-
throw new
|
|
699
|
+
throw new $("ModelFacade");
|
|
703
700
|
return n.bind(t)({
|
|
704
701
|
...this.attributes,
|
|
705
702
|
...s
|
|
@@ -776,15 +773,13 @@ function _e(o, e, t, r, i) {
|
|
|
776
773
|
(T) => n ? n(T.withData(v)) : T.withData(v),
|
|
777
774
|
this.getErrorBag(d ? "update" : "store")
|
|
778
775
|
);
|
|
779
|
-
|
|
780
|
-
return this.makeAttributes(f.json()), this.exists = !0, this.dispatchSaveEvent(), d ? this.dispatchUpdateEvent(f.json()) : (this.wasRecentlyCreated = !0, this.dispatchCreateEvent(f.json())), f;
|
|
781
|
-
throw f;
|
|
776
|
+
return f.throw(), this.makeAttributes(f.json()), this.exists = !0, this.dispatchSaveEvent(), d ? this.dispatchUpdateEvent(f.json()) : (this.wasRecentlyCreated = !0, this.dispatchCreateEvent(f.json())), f;
|
|
782
777
|
} catch (a) {
|
|
783
778
|
throw this.dispatchErrorEvent(a, "save"), a;
|
|
784
779
|
}
|
|
785
780
|
}
|
|
786
781
|
async push() {
|
|
787
|
-
throw new
|
|
782
|
+
throw new Te();
|
|
788
783
|
}
|
|
789
784
|
async delete() {
|
|
790
785
|
try {
|
|
@@ -793,9 +788,7 @@ function _e(o, e, t, r, i) {
|
|
|
793
788
|
void 0,
|
|
794
789
|
this.getErrorBag("delete")
|
|
795
790
|
);
|
|
796
|
-
|
|
797
|
-
return this.dispatchDeleteEvent(), s;
|
|
798
|
-
throw s;
|
|
791
|
+
return s.throw(), this.dispatchDeleteEvent(), s;
|
|
799
792
|
} catch (s) {
|
|
800
793
|
throw this.dispatchErrorEvent(s, "delete"), s;
|
|
801
794
|
}
|
|
@@ -807,11 +800,7 @@ function _e(o, e, t, r, i) {
|
|
|
807
800
|
(h) => n ? n(h.withData(s)) : h.withData(s),
|
|
808
801
|
this.getErrorBag("update")
|
|
809
802
|
);
|
|
810
|
-
|
|
811
|
-
this.makeAttributes(a.json()), this.dispatchUpdateEvent(a.json());
|
|
812
|
-
return;
|
|
813
|
-
}
|
|
814
|
-
throw a;
|
|
803
|
+
a.throw(), this.makeAttributes(a.json()), this.dispatchUpdateEvent(a.json());
|
|
815
804
|
} catch (a) {
|
|
816
805
|
throw this.dispatchErrorEvent(a, "save"), a;
|
|
817
806
|
}
|
|
@@ -823,9 +812,7 @@ function _e(o, e, t, r, i) {
|
|
|
823
812
|
(n) => n.withQueryParameters({ force: !0 }),
|
|
824
813
|
this.getErrorBag("forceDelete")
|
|
825
814
|
);
|
|
826
|
-
|
|
827
|
-
return this.dispatchDeleteEvent(!0), s;
|
|
828
|
-
throw s;
|
|
815
|
+
return s.throw(), this.dispatchDeleteEvent(!0), s;
|
|
829
816
|
} catch (s) {
|
|
830
817
|
throw this.dispatchErrorEvent(s, "forceDelete"), s;
|
|
831
818
|
}
|
|
@@ -837,9 +824,7 @@ function _e(o, e, t, r, i) {
|
|
|
837
824
|
(n) => n.withQueryParameters({ restore: !0 }),
|
|
838
825
|
this.getErrorBag("restore")
|
|
839
826
|
);
|
|
840
|
-
|
|
841
|
-
return this.dispatchRestoreEvent(), s;
|
|
842
|
-
throw s;
|
|
827
|
+
return s.throw(), this.dispatchRestoreEvent(), s;
|
|
843
828
|
} catch (s) {
|
|
844
829
|
throw this.dispatchErrorEvent(s, "restore"), s;
|
|
845
830
|
}
|
|
@@ -852,7 +837,7 @@ function _e(o, e, t, r, i) {
|
|
|
852
837
|
return t.schema(i);
|
|
853
838
|
}
|
|
854
839
|
static query() {
|
|
855
|
-
return new
|
|
840
|
+
return new Me(
|
|
856
841
|
{ config: o, route: r, model: t },
|
|
857
842
|
i
|
|
858
843
|
);
|
|
@@ -939,7 +924,7 @@ function _e(o, e, t, r, i) {
|
|
|
939
924
|
}
|
|
940
925
|
}, g(c, "name", y.studly(i)), c;
|
|
941
926
|
}
|
|
942
|
-
function
|
|
927
|
+
function _e(o, e, t) {
|
|
943
928
|
var r, i;
|
|
944
929
|
return class extends (i = t, r = Symbol.toStringTag, i) {
|
|
945
930
|
constructor(m = {}) {
|
|
@@ -960,13 +945,13 @@ function Re(o, e, t) {
|
|
|
960
945
|
if (o.hasReducer(`model${y.studly(c.getType())}Get${y.studly(u)}Attribute`)) {
|
|
961
946
|
const s = o[`model${y.studly(c.getType())}Get${y.studly(u)}Attribute`];
|
|
962
947
|
if (typeof s != "function")
|
|
963
|
-
throw new
|
|
948
|
+
throw new $("ModelFacade");
|
|
964
949
|
return s.bind(o)(void 0, c);
|
|
965
950
|
}
|
|
966
951
|
return Reflect.get(c, u);
|
|
967
952
|
},
|
|
968
953
|
set: (c, u, s) => u in c && typeof c[u] != "function" ? Reflect.set(c, u, s) : (c.setAttribute(
|
|
969
|
-
|
|
954
|
+
u,
|
|
970
955
|
s
|
|
971
956
|
), !0)
|
|
972
957
|
});
|
|
@@ -987,7 +972,7 @@ class R extends (X = TypeError, z = Symbol.toStringTag, X) {
|
|
|
987
972
|
g(this, z, "ModelInvalidRelatedTypeException");
|
|
988
973
|
}
|
|
989
974
|
}
|
|
990
|
-
class ae extends
|
|
975
|
+
class ae extends N {
|
|
991
976
|
constructor(e, t, r, i = null) {
|
|
992
977
|
if (!p.isModel(i) && i !== null)
|
|
993
978
|
throw new w("BelongsTo.constructor()", "Model or null");
|
|
@@ -1023,7 +1008,7 @@ class ae extends k {
|
|
|
1023
1008
|
});
|
|
1024
1009
|
}
|
|
1025
1010
|
}
|
|
1026
|
-
class ue extends
|
|
1011
|
+
class ue extends N {
|
|
1027
1012
|
constructor(e, t, r, i = null) {
|
|
1028
1013
|
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1029
1014
|
throw new w("BelongsToMany.constructor()", "Collection<Model> or null");
|
|
@@ -1119,7 +1104,7 @@ class ue extends k {
|
|
|
1119
1104
|
this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
|
|
1120
1105
|
}
|
|
1121
1106
|
}
|
|
1122
|
-
class
|
|
1107
|
+
class A extends N {
|
|
1123
1108
|
query() {
|
|
1124
1109
|
const e = super.query(), t = this.guessInverseRelation();
|
|
1125
1110
|
return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
|
|
@@ -1132,7 +1117,7 @@ class N extends k {
|
|
|
1132
1117
|
e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
|
|
1133
1118
|
}
|
|
1134
1119
|
}
|
|
1135
|
-
class
|
|
1120
|
+
class Re extends A {
|
|
1136
1121
|
constructor(e, t, r, i = null) {
|
|
1137
1122
|
if (!p.isModel(i) && i !== null)
|
|
1138
1123
|
throw new w("HasOne.constructor()", "Model or null");
|
|
@@ -1154,7 +1139,7 @@ class ke extends N {
|
|
|
1154
1139
|
function K(o) {
|
|
1155
1140
|
return new b(o);
|
|
1156
1141
|
}
|
|
1157
|
-
class
|
|
1142
|
+
class Ne extends A {
|
|
1158
1143
|
constructor(e, t, r, i = null) {
|
|
1159
1144
|
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1160
1145
|
throw new w("HasMany.constructor()", "Collection<Model> or null");
|
|
@@ -1192,7 +1177,7 @@ class Ae extends N {
|
|
|
1192
1177
|
await this.saveQuietly(e), this.items === null ? this.items = K([e]) : this.items.push(e);
|
|
1193
1178
|
}
|
|
1194
1179
|
}
|
|
1195
|
-
class he extends
|
|
1180
|
+
class he extends A {
|
|
1196
1181
|
query() {
|
|
1197
1182
|
const e = this.getRelated().query();
|
|
1198
1183
|
e.once("success", (r) => {
|
|
@@ -1210,7 +1195,7 @@ class he extends N {
|
|
|
1210
1195
|
e.setAttribute(t + "_id", this.parent.getKey()), e.setAttribute(t + "_type", this.parent.getType()), await e.save();
|
|
1211
1196
|
}
|
|
1212
1197
|
}
|
|
1213
|
-
class
|
|
1198
|
+
class ke extends he {
|
|
1214
1199
|
constructor(e, t, r, i = null) {
|
|
1215
1200
|
if (i !== null && !(i instanceof b && i.every(p.isModel)))
|
|
1216
1201
|
throw new w("MorphMany.constructor()", "Collection<Model> or null");
|
|
@@ -1250,7 +1235,7 @@ class Ne extends he {
|
|
|
1250
1235
|
await this.saveQuietly(e), this.items ? this.items.push(e) : this.items = await this.all();
|
|
1251
1236
|
}
|
|
1252
1237
|
}
|
|
1253
|
-
class
|
|
1238
|
+
class Ae extends he {
|
|
1254
1239
|
constructor(e, t, r, i = null) {
|
|
1255
1240
|
if (super(e, t, r, i), this.services = e, this.meta = t, this.parent = r, this.items = i, i !== null && !p.isModel(i))
|
|
1256
1241
|
throw new w("MorphOne.constructor()", "Model or null");
|
|
@@ -1268,7 +1253,7 @@ class qe extends he {
|
|
|
1268
1253
|
await this.saveQuietly(e), this.items = e;
|
|
1269
1254
|
}
|
|
1270
1255
|
}
|
|
1271
|
-
class
|
|
1256
|
+
class qe extends ae {
|
|
1272
1257
|
getRelated() {
|
|
1273
1258
|
return this.services.model.make(
|
|
1274
1259
|
this.parent.getAttribute(this.getName() + "_type")
|
|
@@ -1297,7 +1282,7 @@ class Ke extends ae {
|
|
|
1297
1282
|
});
|
|
1298
1283
|
}
|
|
1299
1284
|
}
|
|
1300
|
-
class
|
|
1285
|
+
class Ke extends ue {
|
|
1301
1286
|
query() {
|
|
1302
1287
|
var r;
|
|
1303
1288
|
const e = super.query(), t = `${(r = this.meta.morphType) == null ? void 0 : r.slice(0, -5)}_id`;
|
|
@@ -1305,7 +1290,7 @@ class je extends ue {
|
|
|
1305
1290
|
}
|
|
1306
1291
|
}
|
|
1307
1292
|
var Y, Z;
|
|
1308
|
-
class Oe extends (Z =
|
|
1293
|
+
class Oe extends (Z = k, Y = Symbol.toStringTag, Z) {
|
|
1309
1294
|
constructor(t) {
|
|
1310
1295
|
super();
|
|
1311
1296
|
g(this, "_models", {});
|
|
@@ -1315,7 +1300,7 @@ class Oe extends (Z = A, Y = Symbol.toStringTag, Z) {
|
|
|
1315
1300
|
boot(t) {
|
|
1316
1301
|
this._schema && Object.keys(this._schema).forEach((r) => {
|
|
1317
1302
|
const i = this[`model${y.studly(r)}`], l = this.model(
|
|
1318
|
-
|
|
1303
|
+
Se(
|
|
1319
1304
|
t.make("config"),
|
|
1320
1305
|
t.make("log"),
|
|
1321
1306
|
t.make("model"),
|
|
@@ -1324,7 +1309,7 @@ class Oe extends (Z = A, Y = Symbol.toStringTag, Z) {
|
|
|
1324
1309
|
),
|
|
1325
1310
|
r
|
|
1326
1311
|
), m = i(l);
|
|
1327
|
-
this._models[r] =
|
|
1312
|
+
this._models[r] = _e(t.make("model"), r, m);
|
|
1328
1313
|
});
|
|
1329
1314
|
}
|
|
1330
1315
|
schema(t) {
|
|
@@ -1341,27 +1326,27 @@ class Oe extends (Z = A, Y = Symbol.toStringTag, Z) {
|
|
|
1341
1326
|
return this.relationMap({
|
|
1342
1327
|
BelongsTo: ae,
|
|
1343
1328
|
BelongsToMany: ue,
|
|
1344
|
-
HasOne:
|
|
1345
|
-
HasMany:
|
|
1346
|
-
MorphMany:
|
|
1347
|
-
MorphOne:
|
|
1348
|
-
MorphTo:
|
|
1349
|
-
MorphToMany:
|
|
1329
|
+
HasOne: Re,
|
|
1330
|
+
HasMany: Ne,
|
|
1331
|
+
MorphMany: ke,
|
|
1332
|
+
MorphOne: Ae,
|
|
1333
|
+
MorphTo: qe,
|
|
1334
|
+
MorphToMany: Ke
|
|
1350
1335
|
}, t);
|
|
1351
1336
|
}
|
|
1352
1337
|
toString() {
|
|
1353
1338
|
return "model";
|
|
1354
1339
|
}
|
|
1355
1340
|
}
|
|
1356
|
-
const
|
|
1341
|
+
const je = re(Oe);
|
|
1357
1342
|
var ee, te;
|
|
1358
|
-
class
|
|
1343
|
+
class Be extends (te = Error, ee = Symbol.toStringTag, te) {
|
|
1359
1344
|
constructor(t) {
|
|
1360
1345
|
super(`[Luminix] Route "${t}" not found`);
|
|
1361
1346
|
g(this, ee, "RouteNotFoundException");
|
|
1362
1347
|
}
|
|
1363
1348
|
}
|
|
1364
|
-
class
|
|
1349
|
+
class Ce {
|
|
1365
1350
|
constructor(e, t, r, i = "") {
|
|
1366
1351
|
this.routes = e, this.error = t, this.http = r, this.appUrl = i;
|
|
1367
1352
|
}
|
|
@@ -1380,7 +1365,7 @@ class Ie {
|
|
|
1380
1365
|
}
|
|
1381
1366
|
get(e) {
|
|
1382
1367
|
if (!this.exists(e))
|
|
1383
|
-
throw new
|
|
1368
|
+
throw new Be(e);
|
|
1384
1369
|
return p.get(this.routes, e);
|
|
1385
1370
|
}
|
|
1386
1371
|
url(e) {
|
|
@@ -1390,7 +1375,7 @@ class Ie {
|
|
|
1390
1375
|
const [t, r] = this.extractGenerator(e), i = this.get(t)[0].replace(/^\/|\/$/g, ""), l = /{([^}]+)}/g;
|
|
1391
1376
|
if (r === !1) {
|
|
1392
1377
|
if (typeof this.replaceRouteParams != "function")
|
|
1393
|
-
throw new
|
|
1378
|
+
throw new $("RouteFacade");
|
|
1394
1379
|
return this.replaceRouteParams(`/${i}`);
|
|
1395
1380
|
}
|
|
1396
1381
|
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));
|
|
@@ -1410,7 +1395,7 @@ class Ie {
|
|
|
1410
1395
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1411
1396
|
async call(e, t = (i) => i, r = "default") {
|
|
1412
1397
|
if (typeof this.clientOptions != "function" || typeof this.clientError != "function")
|
|
1413
|
-
throw new
|
|
1398
|
+
throw new $("RouteFacade");
|
|
1414
1399
|
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);
|
|
1415
1400
|
p.isEmpty(s) || u.withOptions(s);
|
|
1416
1401
|
const n = m[0] ?? s.method;
|
|
@@ -1434,10 +1419,10 @@ class Ie {
|
|
|
1434
1419
|
return "route";
|
|
1435
1420
|
}
|
|
1436
1421
|
}
|
|
1437
|
-
const
|
|
1438
|
-
class
|
|
1422
|
+
const Ie = re(Ce);
|
|
1423
|
+
class Pe {
|
|
1439
1424
|
getClient() {
|
|
1440
|
-
return new
|
|
1425
|
+
return new me();
|
|
1441
1426
|
}
|
|
1442
1427
|
baseUrl(e) {
|
|
1443
1428
|
return this.getClient().baseUrl(e);
|
|
@@ -1490,9 +1475,9 @@ class Qe {
|
|
|
1490
1475
|
return this.getClient().delete(e, t);
|
|
1491
1476
|
}
|
|
1492
1477
|
}
|
|
1493
|
-
const
|
|
1478
|
+
const Qe = ne(Pe);
|
|
1494
1479
|
var se, ie;
|
|
1495
|
-
class
|
|
1480
|
+
class Le extends (ie = ye, se = Symbol.toStringTag, ie) {
|
|
1496
1481
|
constructor() {
|
|
1497
1482
|
super(...arguments);
|
|
1498
1483
|
g(this, se, "LuminixServiceProvider");
|
|
@@ -1506,24 +1491,24 @@ class De extends (ie = me, se = Symbol.toStringTag, ie) {
|
|
|
1506
1491
|
this.app.make("model").boot(this.app);
|
|
1507
1492
|
}
|
|
1508
1493
|
registerServices() {
|
|
1509
|
-
this.app.singleton("auth", () => new
|
|
1494
|
+
this.app.singleton("auth", () => new we(
|
|
1510
1495
|
this.app.make("config"),
|
|
1511
1496
|
this.app.make("model"),
|
|
1512
1497
|
this.app.make("route")
|
|
1513
1498
|
)), this.app.singleton("config", () => {
|
|
1514
1499
|
const t = new _(p.omit(this.app.configuration, "manifest"));
|
|
1515
1500
|
return t.has("auth.user") || t.set("auth.user", null), t.lock("auth.user"), t;
|
|
1516
|
-
}), this.app.singleton("error", () => new
|
|
1501
|
+
}), this.app.singleton("error", () => new ve()), this.app.singleton("http", () => new Qe()), this.app.singleton("log", () => {
|
|
1517
1502
|
var t;
|
|
1518
|
-
return new
|
|
1503
|
+
return new be(((t = this.app.configuration.app) == null ? void 0 : t.debug) ?? !1);
|
|
1519
1504
|
}), this.app.singleton("model", () => {
|
|
1520
1505
|
var t;
|
|
1521
|
-
return new
|
|
1506
|
+
return new je(
|
|
1522
1507
|
((t = this.app.configuration.manifest) == null ? void 0 : t.models) ?? {}
|
|
1523
1508
|
);
|
|
1524
1509
|
}), this.app.singleton("route", () => {
|
|
1525
1510
|
var t, r;
|
|
1526
|
-
return new
|
|
1511
|
+
return new Ie(
|
|
1527
1512
|
((t = this.app.configuration.manifest) == null ? void 0 : t.routes) ?? {},
|
|
1528
1513
|
this.app.make("error"),
|
|
1529
1514
|
() => this.app.make("http").getClient(),
|
|
@@ -1537,13 +1522,13 @@ class De extends (ie = me, se = Symbol.toStringTag, ie) {
|
|
|
1537
1522
|
});
|
|
1538
1523
|
}
|
|
1539
1524
|
}
|
|
1540
|
-
class
|
|
1525
|
+
class De {
|
|
1541
1526
|
constructor() {
|
|
1542
1527
|
g(this, "app");
|
|
1543
1528
|
}
|
|
1544
1529
|
getFacadeAccessor() {
|
|
1545
1530
|
return this.app || (this.app = new (ne(fe))([
|
|
1546
|
-
|
|
1531
|
+
Le
|
|
1547
1532
|
])), this.app;
|
|
1548
1533
|
}
|
|
1549
1534
|
down() {
|
|
@@ -1553,101 +1538,89 @@ class He {
|
|
|
1553
1538
|
this.down(), this.app = e;
|
|
1554
1539
|
}
|
|
1555
1540
|
}
|
|
1556
|
-
const x = M(
|
|
1557
|
-
function
|
|
1541
|
+
const x = M(De);
|
|
1542
|
+
function E(o = void 0) {
|
|
1558
1543
|
return typeof o != "string" ? x : x.make(o);
|
|
1559
1544
|
}
|
|
1560
|
-
function
|
|
1561
|
-
return
|
|
1545
|
+
function Ye() {
|
|
1546
|
+
return E("auth");
|
|
1562
1547
|
}
|
|
1563
|
-
function
|
|
1564
|
-
const t =
|
|
1548
|
+
function Ze(o, e) {
|
|
1549
|
+
const t = E("config");
|
|
1565
1550
|
return typeof o > "u" ? t : t.get(o, e);
|
|
1566
1551
|
}
|
|
1567
|
-
function
|
|
1568
|
-
return o ?
|
|
1552
|
+
function et(o, e = "default") {
|
|
1553
|
+
return o ? E().make("error").get(o, e) : E().make("error");
|
|
1569
1554
|
}
|
|
1570
|
-
function
|
|
1571
|
-
const e =
|
|
1555
|
+
function tt(...o) {
|
|
1556
|
+
const e = E("log");
|
|
1572
1557
|
return o.length ? e.debug(...o) : e;
|
|
1573
1558
|
}
|
|
1574
|
-
function
|
|
1575
|
-
const e =
|
|
1559
|
+
function st(o) {
|
|
1560
|
+
const e = E("model");
|
|
1576
1561
|
return o ? e.make(o) : e;
|
|
1577
1562
|
}
|
|
1578
|
-
function
|
|
1579
|
-
const t =
|
|
1563
|
+
function it(o, e = !1) {
|
|
1564
|
+
const t = E("route");
|
|
1580
1565
|
return o ? e ? t.url([o, e]) : t.url(o) : t;
|
|
1581
1566
|
}
|
|
1582
|
-
class
|
|
1567
|
+
class He {
|
|
1583
1568
|
getFacadeAccessor() {
|
|
1584
1569
|
return "auth";
|
|
1585
1570
|
}
|
|
1586
1571
|
}
|
|
1587
|
-
const
|
|
1588
|
-
class
|
|
1572
|
+
const rt = M(He, x);
|
|
1573
|
+
class Je {
|
|
1589
1574
|
getFacadeAccessor() {
|
|
1590
1575
|
return "config";
|
|
1591
1576
|
}
|
|
1592
1577
|
}
|
|
1593
|
-
const
|
|
1594
|
-
class
|
|
1578
|
+
const nt = M(Je, x);
|
|
1579
|
+
class Ue {
|
|
1595
1580
|
getFacadeAccessor() {
|
|
1596
1581
|
return "error";
|
|
1597
1582
|
}
|
|
1598
1583
|
}
|
|
1599
|
-
const
|
|
1600
|
-
class
|
|
1584
|
+
const ot = M(Ue, x);
|
|
1585
|
+
class Fe {
|
|
1601
1586
|
getFacadeAccessor() {
|
|
1602
1587
|
return "http";
|
|
1603
1588
|
}
|
|
1604
1589
|
}
|
|
1605
|
-
const
|
|
1606
|
-
class
|
|
1590
|
+
const at = M(Fe, x);
|
|
1591
|
+
class We {
|
|
1607
1592
|
getFacadeAccessor() {
|
|
1608
1593
|
return "log";
|
|
1609
1594
|
}
|
|
1610
1595
|
}
|
|
1611
|
-
const
|
|
1612
|
-
class
|
|
1596
|
+
const ut = M(We, x);
|
|
1597
|
+
class Ge {
|
|
1613
1598
|
getFacadeAccessor() {
|
|
1614
1599
|
return "model";
|
|
1615
1600
|
}
|
|
1616
1601
|
}
|
|
1617
|
-
const
|
|
1618
|
-
class
|
|
1602
|
+
const ht = M(Ge, x);
|
|
1603
|
+
class Ve {
|
|
1619
1604
|
getFacadeAccessor() {
|
|
1620
1605
|
return "route";
|
|
1621
1606
|
}
|
|
1622
1607
|
}
|
|
1623
|
-
const
|
|
1624
|
-
class pt {
|
|
1625
|
-
constructor() {
|
|
1626
|
-
g(this, "name");
|
|
1627
|
-
g(this, "version");
|
|
1628
|
-
}
|
|
1629
|
-
register(e) {
|
|
1630
|
-
}
|
|
1631
|
-
boot(e) {
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1608
|
+
const lt = M(Ve, x);
|
|
1634
1609
|
export {
|
|
1635
1610
|
x as App,
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
Ze as auth,
|
|
1611
|
+
rt as Auth,
|
|
1612
|
+
nt as Config,
|
|
1613
|
+
ot as Error,
|
|
1614
|
+
at as Http,
|
|
1615
|
+
ut as Log,
|
|
1616
|
+
ht as Model,
|
|
1617
|
+
lt as Route,
|
|
1618
|
+
E as app,
|
|
1619
|
+
Ye as auth,
|
|
1646
1620
|
K as collect,
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
st as
|
|
1651
|
-
it as
|
|
1652
|
-
rt as route
|
|
1621
|
+
Ze as config,
|
|
1622
|
+
et as error,
|
|
1623
|
+
tt as log,
|
|
1624
|
+
st as model,
|
|
1625
|
+
it as route
|
|
1653
1626
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luminix/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"main": "dist/core.js",
|
|
5
5
|
"module": "dist/core.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"repository": "luminix-cms/js-core",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"prebuild": "rm -rf types",
|
|
10
11
|
"build": "tsc && vite build",
|
|
@@ -12,12 +13,10 @@
|
|
|
12
13
|
"lint:fix": "eslint ./src ./tests --ext .ts --fix",
|
|
13
14
|
"test": "jest",
|
|
14
15
|
"test:coverage": "jest --coverage",
|
|
15
|
-
"ci": "npm run lint && npm run test"
|
|
16
|
-
"publish:beta": "npm run build && npm publish --tag beta"
|
|
16
|
+
"ci": "npm run lint && npm run test"
|
|
17
17
|
},
|
|
18
18
|
"author": "",
|
|
19
19
|
"license": "MIT",
|
|
20
|
-
"description": "> Projeto em desenvolvimento",
|
|
21
20
|
"devDependencies": {
|
|
22
21
|
"@babel/core": "^7.26.0",
|
|
23
22
|
"@babel/preset-env": "^7.26.0",
|
|
@@ -37,6 +36,6 @@
|
|
|
37
36
|
"vite-plugin-dts": "^4.0.0-beta.1"
|
|
38
37
|
},
|
|
39
38
|
"peerDependencies": {
|
|
40
|
-
"@luminix/support": "^0.
|
|
39
|
+
"@luminix/support": "^1.0.0"
|
|
41
40
|
}
|
|
42
41
|
}
|
package/types/facades/Error.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { HasFacadeAccessor
|
|
2
|
-
import { ValidationError } from '../types/Error';
|
|
1
|
+
import { HasFacadeAccessor } from '@luminix/support';
|
|
3
2
|
import { default as ErrorService } from '../services/ErrorService';
|
|
4
|
-
/** @deprecated */
|
|
5
|
-
export declare const isValidationError: (response: unknown) => response is Response<ValidationError, any>;
|
|
6
3
|
declare class ErrorFacade implements HasFacadeAccessor {
|
|
7
4
|
getFacadeAccessor(): string | object;
|
|
8
5
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -9,13 +9,12 @@ import { default as route } from './helpers/route';
|
|
|
9
9
|
import { default as App } from './facades/App';
|
|
10
10
|
import { default as Auth } from './facades/Auth';
|
|
11
11
|
import { default as Config } from './facades/Config';
|
|
12
|
-
import { default as Error
|
|
12
|
+
import { default as Error } from './facades/Error';
|
|
13
13
|
import { default as Http } from './facades/Http';
|
|
14
14
|
import { default as Log } from './facades/Log';
|
|
15
15
|
import { default as Model } from './facades/Model';
|
|
16
16
|
import { default as Route } from './facades/Route';
|
|
17
|
-
|
|
18
|
-
export { app, App, auth, Auth, collect, config, Config, error, Error, Http, log, Log, model, Model, route, Route, isValidationError, Plugin, };
|
|
17
|
+
export { app, App, auth, Auth, collect, config, Config, error, Error, Http, log, Log, model, Model, route, Route, };
|
|
19
18
|
export type { AppFacade, AppEvents, AppContainers } from './types/App';
|
|
20
19
|
export type { AuthFacade } from './types/Auth';
|
|
21
20
|
export type { BuilderInterface, Scope } from './types/Builder';
|
package/types/types/App.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EventSource, Event, ReducibleInterface, FacadeOf, HasFacadeAccessor, Application, MacroableInterface, Constructor } from '@luminix/support';
|
|
2
2
|
import { AppConfiguration, ConfigFacade } from './Config';
|
|
3
|
-
import { PluginInterface } from './Plugin';
|
|
4
3
|
import { LogFacade } from './Log';
|
|
5
4
|
import { BaseModel, Model, ModelPaginatedResponse, ModelReducers, ModelSchema, ModelSchemaAttributes } from './Model';
|
|
6
5
|
import { RouteFacade } from './Route';
|
|
@@ -8,7 +7,6 @@ import { ErrorFacade } from './Error';
|
|
|
8
7
|
import { RelationInterface } from './Relation';
|
|
9
8
|
import { AuthFacade } from './Auth';
|
|
10
9
|
import { HttpFacade } from './Http';
|
|
11
|
-
type Plugin = PluginInterface<AppFacade, AppContainers>;
|
|
12
10
|
export type GlobalModelEvents = {
|
|
13
11
|
'save': (e: ModelGlobalEvent) => void;
|
|
14
12
|
'delete': (e: ModelGlobalEvent) => void;
|
|
@@ -85,4 +83,3 @@ export type AppMacros = {
|
|
|
85
83
|
isLocal(): boolean;
|
|
86
84
|
isProduction(): boolean;
|
|
87
85
|
};
|
|
88
|
-
export {};
|
package/babel.config.json
DELETED
package/types/types/Plugin.d.ts
DELETED