@luminix/core 0.0.1-beta.13 → 0.0.1-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -1,21 +1,21 @@
1
1
  var Ke = Object.defineProperty;
2
- var L = (n) => {
2
+ var C = (n) => {
3
3
  throw TypeError(n);
4
4
  };
5
5
  var je = (n, e, t) => e in n ? Ke(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
6
- var m = (n, e, t) => je(n, typeof e != "symbol" ? e + "" : e, t), K = (n, e, t) => e.has(n) || L("Cannot " + t);
7
- var h = (n, e, t) => (K(n, e, "read from private field"), t ? t.call(n) : e.get(n)), j = (n, e, t) => e.has(n) ? L("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), D = (n, e, t, r) => (K(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), U = (n, e, t) => (K(n, e, "access private method"), t);
6
+ var m = (n, e, t) => je(n, typeof e != "symbol" ? e + "" : e, t), K = (n, e, t) => e.has(n) || C("Cannot " + t);
7
+ var h = (n, e, t) => (K(n, e, "read from private field"), t ? t.call(n) : e.get(n)), j = (n, e, t) => e.has(n) ? C("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), D = (n, e, t, r) => (K(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), U = (n, e, t) => (K(n, e, "access private method"), t);
8
8
  import d from "lodash";
9
9
  import { produce as N, isDraftable as Pe } from "immer";
10
- import I, { isAxiosError as ke } from "axios";
10
+ import I, { isAxiosError as Le } from "axios";
11
11
  var V, X;
12
- class Qe extends (X = Error, V = Symbol.toStringTag, X) {
12
+ class ke extends (X = Error, V = Symbol.toStringTag, X) {
13
13
  constructor(t) {
14
14
  super(`[Luminix] Facade "${t}" not found`);
15
15
  m(this, V, "FacadeNotFoundException");
16
16
  }
17
17
  }
18
- class Ce {
18
+ class Qe {
19
19
  constructor(e) {
20
20
  m(this, "_user");
21
21
  this.app = e;
@@ -64,7 +64,7 @@ class Ce {
64
64
  return ((e = this.user()) == null ? void 0 : e.getKey()) || null;
65
65
  }
66
66
  }
67
- class Le {
67
+ class Ce {
68
68
  constructor(e) {
69
69
  this._debug = e;
70
70
  }
@@ -93,7 +93,7 @@ class Le {
93
93
  this._debug && console.debug(...e);
94
94
  }
95
95
  }
96
- class A {
96
+ class R {
97
97
  constructor(e) {
98
98
  m(this, "locked", []);
99
99
  this.bag = e, Object.freeze(this.bag);
@@ -172,7 +172,7 @@ class A {
172
172
  this.locked.push(e);
173
173
  }
174
174
  clone() {
175
- return new A(this.bag);
175
+ return new R(this.bag);
176
176
  }
177
177
  all() {
178
178
  return this.bag;
@@ -191,7 +191,7 @@ class A {
191
191
  emit(e, t) {
192
192
  }
193
193
  }
194
- function R(n) {
194
+ function S(n) {
195
195
  var e, t, r, $e, s;
196
196
  return s = class extends (t = n, e = Symbol.toStringTag, t) {
197
197
  constructor(...a) {
@@ -260,7 +260,7 @@ class b extends (Z = Error, Y = Symbol.toStringTag, Z) {
260
260
  function c(n = [], e = P) {
261
261
  if (!Array.isArray(n))
262
262
  throw new TypeError("collect() expects an array");
263
- return new (R(e))([...n]);
263
+ return new (S(e))([...n]);
264
264
  }
265
265
  const _ = (n) => {
266
266
  n.emit("change", {
@@ -807,10 +807,14 @@ class P {
807
807
  return _(this), this;
808
808
  }
809
809
  unique(e) {
810
- return c(typeof e == "string" ? h(this, o).filter((t, r) => !h(this, o).some((i, s) => i[e] == t[e] && s !== r)) : [...new Set(h(this, o))]);
810
+ return c(
811
+ typeof e == "string" ? [...new Set(h(this, o).map((t) => t[e]))].map((t) => h(this, o).find((r) => r[e] == t)) : [...new Set(h(this, o))]
812
+ );
811
813
  }
812
814
  uniqueStrict(e) {
813
- return c(typeof e == "string" ? h(this, o).filter((t, r) => !h(this, o).some((i, s) => i[e] === t[e] && s !== r)) : [...new Set(h(this, o))]);
815
+ return c(
816
+ typeof e == "string" ? [...new Set(h(this, o).map((t) => t[e]))].map((t) => h(this, o).find((r) => r[e] === t)) : [...new Set(h(this, o))]
817
+ );
814
818
  }
815
819
  unless(e, t, r) {
816
820
  return e ? typeof r == "function" && r(this) : t(this), this;
@@ -914,7 +918,7 @@ class P {
914
918
  }
915
919
  }
916
920
  o = new WeakMap();
917
- const k = R(P);
921
+ const L = S(P);
918
922
  var ee, te;
919
923
  class H extends (te = P, ee = Symbol.toStringTag, te) {
920
924
  constructor() {
@@ -941,7 +945,7 @@ class De extends (se = Error, re = Symbol.toStringTag, se) {
941
945
  m(this, re, "ModelWithoutPrimaryKeyException");
942
946
  }
943
947
  }
944
- const Ue = R(A);
948
+ const Ue = S(R);
945
949
  class Je {
946
950
  constructor(e, t, r = {}) {
947
951
  m(this, "bag");
@@ -1118,7 +1122,7 @@ class Je {
1118
1122
  }), u;
1119
1123
  }
1120
1124
  }
1121
- const He = R(Je);
1125
+ const He = S(Je);
1122
1126
  var ie, ne;
1123
1127
  class T extends (ne = Error, ie = Symbol.toStringTag, ne) {
1124
1128
  constructor(t) {
@@ -1278,7 +1282,7 @@ class F {
1278
1282
  // }
1279
1283
  }
1280
1284
  var de, fe;
1281
- class Re extends (fe = Error, de = Symbol.toStringTag, fe) {
1285
+ class Se extends (fe = Error, de = Symbol.toStringTag, fe) {
1282
1286
  constructor(t, r) {
1283
1287
  super(`[Luminix] Model "${t}" must be persisted before calling "${r}"`);
1284
1288
  m(this, de, "ModelNotPersistedException");
@@ -1289,7 +1293,7 @@ function Ve(n, e) {
1289
1293
  r = Symbol.toStringTag;
1290
1294
  class t {
1291
1295
  constructor(s = {}) {
1292
- m(this, "_attributes", new A({}));
1296
+ m(this, "_attributes", new R({}));
1293
1297
  m(this, "_original", {});
1294
1298
  m(this, "_relations", {});
1295
1299
  m(this, "_changedKeys", []);
@@ -1544,18 +1548,6 @@ function Ve(n, e) {
1544
1548
  this.makePrimaryKeyReplacer()
1545
1549
  ];
1546
1550
  }
1547
- getRouteForRestore() {
1548
- return [
1549
- `luminix.${e}.restore`,
1550
- this.makePrimaryKeyReplacer()
1551
- ];
1552
- }
1553
- getRouteForForceDelete() {
1554
- return [
1555
- `luminix.${e}.forceDelete`,
1556
- this.makePrimaryKeyReplacer()
1557
- ];
1558
- }
1559
1551
  getRouteForRefresh() {
1560
1552
  return [
1561
1553
  `luminix.${e}.show`,
@@ -1568,7 +1560,7 @@ function Ve(n, e) {
1568
1560
  }
1569
1561
  async refresh() {
1570
1562
  if (!this.exists)
1571
- throw new Re(e, "refresh");
1563
+ throw new Se(e, "refresh");
1572
1564
  const { data: s } = await n.make("route").call(
1573
1565
  this.getRouteForRefresh(),
1574
1566
  { errorBag: this.getErrorBag("fetch") }
@@ -1640,7 +1632,7 @@ function Ve(n, e) {
1640
1632
  async forceDelete() {
1641
1633
  try {
1642
1634
  const s = await n.make("route").call(
1643
- this.getRouteForForceDelete(),
1635
+ this.getRouteForDelete(),
1644
1636
  {
1645
1637
  params: { force: !0 },
1646
1638
  errorBag: this.getErrorBag("forceDelete")
@@ -1656,7 +1648,7 @@ function Ve(n, e) {
1656
1648
  async restore() {
1657
1649
  try {
1658
1650
  const s = await n.make("route").call(
1659
- this.getRouteForRestore(),
1651
+ this.getRouteForUpdate(),
1660
1652
  {
1661
1653
  params: { restore: !0 },
1662
1654
  errorBag: this.getErrorBag("restore")
@@ -1768,7 +1760,7 @@ function Ve(n, e) {
1768
1760
  throw new b();
1769
1761
  }
1770
1762
  }
1771
- return m(t, "name", d.upperFirst(d.camelCase(e))), R(t);
1763
+ return m(t, "name", d.upperFirst(d.camelCase(e))), S(t);
1772
1764
  }
1773
1765
  function Xe(n, e, t) {
1774
1766
  var r, i;
@@ -1814,7 +1806,7 @@ class Ye extends (pe = Error, me = Symbol.toStringTag, pe) {
1814
1806
  m(this, me, "ReducerOverrideException");
1815
1807
  }
1816
1808
  }
1817
- function Se(n) {
1809
+ function Ae(n) {
1818
1810
  return class extends n {
1819
1811
  constructor(...t) {
1820
1812
  super(...t);
@@ -1865,7 +1857,7 @@ class B extends (be = TypeError, we = Symbol.toStringTag, be) {
1865
1857
  m(this, we, "ModelInvalidRelatedTypeException");
1866
1858
  }
1867
1859
  }
1868
- class Ae extends F {
1860
+ class Re extends F {
1869
1861
  constructor(e, t, r, i = null) {
1870
1862
  if (!E(i) && i !== null)
1871
1863
  throw new M("BelongsTo.constructor()", "Model or null");
@@ -1890,7 +1882,7 @@ class Ae extends F {
1890
1882
  if (e.getType() !== this.getRelated().getSchemaName())
1891
1883
  throw new B("BelongsTo.associate()", this.getRelated().getSchemaName(), e.getType());
1892
1884
  if (!e.exists)
1893
- throw new Re(this.getRelated().getSchemaName(), "save");
1885
+ throw new Se(this.getRelated().getSchemaName(), "save");
1894
1886
  return this.parent.update({
1895
1887
  [this.getForeignKey()]: e.getKey()
1896
1888
  });
@@ -1903,7 +1895,7 @@ class Ae extends F {
1903
1895
  }
1904
1896
  class ve extends F {
1905
1897
  constructor(e, t, r, i = null) {
1906
- if (i !== null && !(i instanceof k && i.every(E)))
1898
+ if (i !== null && !(i instanceof L && i.every(E)))
1907
1899
  throw new M("BelongsToMany.constructor()", "Collection<Model> or null");
1908
1900
  super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
1909
1901
  }
@@ -2006,7 +1998,7 @@ class ve extends F {
2006
1998
  this.items ? this.items.splice(0, this.items.count(), ...r) : this.items = r;
2007
1999
  }
2008
2000
  }
2009
- class Q extends F {
2001
+ class k extends F {
2010
2002
  query() {
2011
2003
  const e = super.query(), t = this.guessInverseRelation();
2012
2004
  return e.where(t, this.parent.getKey()), e.lock(`where.${t}`), e;
@@ -2019,7 +2011,7 @@ class Q extends F {
2019
2011
  e.setAttribute(this.getForeignKey(), this.parent.getKey()), await e.save();
2020
2012
  }
2021
2013
  }
2022
- class Ze extends Q {
2014
+ class Ze extends k {
2023
2015
  constructor(e, t, r, i = null) {
2024
2016
  if (!E(i) && i !== null)
2025
2017
  throw new M("HasOne.constructor()", "Model or null");
@@ -2038,9 +2030,9 @@ class Ze extends Q {
2038
2030
  await this.saveQuietly(e), this.items = e;
2039
2031
  }
2040
2032
  }
2041
- class ze extends Q {
2033
+ class ze extends k {
2042
2034
  constructor(e, t, r, i = null) {
2043
- if (i !== null && !(i instanceof k && i.every(E)))
2035
+ if (i !== null && !(i instanceof L && i.every(E)))
2044
2036
  throw new M("HasMany.constructor()", "Collection<Model> or null");
2045
2037
  super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
2046
2038
  }
@@ -2078,7 +2070,7 @@ class ze extends Q {
2078
2070
  await this.saveQuietly(e), this.items === null ? this.items = await this.all() : this.items.push(e);
2079
2071
  }
2080
2072
  }
2081
- class Ne extends Q {
2073
+ class Ne extends k {
2082
2074
  query() {
2083
2075
  const e = this.getRelated().query();
2084
2076
  e.once("success", (r) => {
@@ -2098,7 +2090,7 @@ class Ne extends Q {
2098
2090
  }
2099
2091
  class Oe extends Ne {
2100
2092
  constructor(e, t, r, i = null) {
2101
- if (i !== null && !(i instanceof k && i.every(E)))
2093
+ if (i !== null && !(i instanceof L && i.every(E)))
2102
2094
  throw new M("MorphMany.constructor()", "Collection<Model> or null");
2103
2095
  super(e, t, r, i), this.meta = e, this.facades = t, this.parent = r, this.items = i;
2104
2096
  }
@@ -2154,7 +2146,7 @@ class et extends Ne {
2154
2146
  await this.saveQuietly(e), this.items = e;
2155
2147
  }
2156
2148
  }
2157
- class tt extends Ae {
2149
+ class tt extends Re {
2158
2150
  getRelated() {
2159
2151
  return this.facades.model.make(
2160
2152
  this.parent.getAttribute(this.getName() + "_type")
@@ -2211,7 +2203,7 @@ class st {
2211
2203
  ), s = r(i);
2212
2204
  this._models[t] = Xe(e.make(), t, s);
2213
2205
  }), this.reducer("relationMap", () => ({
2214
- BelongsTo: Ae,
2206
+ BelongsTo: Re,
2215
2207
  BelongsToMany: ve,
2216
2208
  HasOne: Ze,
2217
2209
  HasMany: ze,
@@ -2271,7 +2263,7 @@ class st {
2271
2263
  throw new b();
2272
2264
  }
2273
2265
  }
2274
- const it = R(Se(st));
2266
+ const it = S(Ae(st));
2275
2267
  var xe, Me;
2276
2268
  class nt extends (Me = Error, xe = Symbol.toStringTag, Me) {
2277
2269
  constructor() {
@@ -2284,7 +2276,7 @@ const Be = (n, e = "data") => {
2284
2276
  throw new nt();
2285
2277
  const t = document.getElementById(`luminix-${e}::` + n);
2286
2278
  return t ? t.dataset.json && t.dataset.value ? JSON.parse(t.dataset.value) : t.dataset.value : null;
2287
- }, G = R(A), ot = (n) => ke(n) && n.response !== void 0 && n.response.data !== null && "message" in n.response.data && typeof n.response.data.message == "string" && "errors" in n.response.data && typeof n.response.data.errors == "object" && n.response.data.errors !== null && Object.values(n.response.data.errors).every((e) => Array.isArray(e) && e.every((t) => typeof t == "string")) && n.response.status === 422;
2279
+ }, G = S(R), ot = (n) => Le(n) && n.response !== void 0 && n.response.data !== null && "message" in n.response.data && typeof n.response.data.message == "string" && "errors" in n.response.data && typeof n.response.data.errors == "object" && n.response.data.errors !== null && Object.values(n.response.data.errors).every((e) => Array.isArray(e) && e.every((t) => typeof t == "string")) && n.response.status === 422;
2288
2280
  let ht = class {
2289
2281
  constructor() {
2290
2282
  m(this, "bags");
@@ -2376,7 +2368,7 @@ class at {
2376
2368
  } catch (g) {
2377
2369
  if (ot(g)) {
2378
2370
  const { errors: qe } = g.response.data;
2379
- this.error.set(Object.entries(qe).reduce((C, [Ie, Fe]) => (C[Ie] = Fe.join(" "), C), {}), f);
2371
+ this.error.set(Object.entries(qe).reduce((Q, [Ie, Fe]) => (Q[Ie] = Fe.join(" "), Q), {}), f);
2380
2372
  } else I.isAxiosError(g) && this.error.set(
2381
2373
  this.axiosError({ axios: g.message }, {
2382
2374
  error: g,
@@ -2393,7 +2385,7 @@ class at {
2393
2385
  return "route";
2394
2386
  }
2395
2387
  }
2396
- const lt = Se(at);
2388
+ const lt = Ae(at);
2397
2389
  class ct {
2398
2390
  constructor() {
2399
2391
  m(this, "facades", {});
@@ -2436,12 +2428,12 @@ class ct {
2436
2428
  } catch (g) {
2437
2429
  (p = e.app) != null && p.debug && console.error(g);
2438
2430
  }
2439
- this.bind("log", new Le(!!((w = e.app) != null && w.debug)));
2431
+ this.bind("log", new Ce(!!((w = e.app) != null && w.debug)));
2440
2432
  const { log: r } = this.facades, {
2441
2433
  manifest: { routes: i = {}, models: s = {} } = {},
2442
2434
  ...u
2443
2435
  } = e;
2444
- this.bind("config", new A(u)), this.facades.config.has("auth.user") || this.facades.config.set("auth.user", null), this.facades.config.lock("auth.user"), this.bind("error", new ht()), this.bind("route", new lt(i, this.facades.error, ((x = e.app) == null ? void 0 : x.url) ?? "")), this.bind("model", new it(s)), this.bind("auth", new Ce(this)), this.emit("booting");
2436
+ this.bind("config", new R(u)), this.facades.config.has("auth.user") || this.facades.config.set("auth.user", null), this.facades.config.lock("auth.user"), this.bind("error", new ht()), this.bind("route", new lt(i, this.facades.error, ((x = e.app) == null ? void 0 : x.url) ?? "")), this.bind("model", new it(s)), this.bind("auth", new Qe(this)), this.emit("booting");
2445
2437
  for (const g of Object.values(this.facades))
2446
2438
  typeof g == "object" && g !== null && "boot" in g && typeof g.boot == "function" && g.boot(this);
2447
2439
  for (const g of this._plugins)
@@ -2458,6 +2450,9 @@ class ct {
2458
2450
  environment(...e) {
2459
2451
  return e.length > 0 ? e.includes(this.facades.config.get("app.env", "production")) : this.facades.config.get("app.env", "production");
2460
2452
  }
2453
+ getLocale() {
2454
+ return this.facades.config.get("app.locale", "en");
2455
+ }
2461
2456
  getPlugin(e) {
2462
2457
  for (const t of this._plugins)
2463
2458
  if (t instanceof e)
@@ -2485,9 +2480,9 @@ class ct {
2485
2480
  throw new window.Error("Method not implemented.");
2486
2481
  }
2487
2482
  }
2488
- const dt = R(ct);
2483
+ const dt = S(ct);
2489
2484
  let y;
2490
- function S(n = void 0) {
2485
+ function A(n = void 0) {
2491
2486
  if (y || (y = new dt()), typeof n != "string")
2492
2487
  return {
2493
2488
  boot: y.boot.bind(y),
@@ -2495,41 +2490,42 @@ function S(n = void 0) {
2495
2490
  plugins: y.plugins.bind(y),
2496
2491
  on: y.once.bind(y),
2497
2492
  environment: y.environment.bind(y),
2493
+ getLocale: y.getLocale.bind(y),
2498
2494
  getPlugin: y.getPlugin.bind(y),
2499
2495
  hasDebugModeEnabled: y.hasDebugModeEnabled.bind(y),
2500
2496
  isLocal: y.isLocal.bind(y),
2501
2497
  isProduction: y.isProduction.bind(y)
2502
2498
  };
2503
2499
  if (!y.has(n))
2504
- throw new Qe(n);
2500
+ throw new ke(n);
2505
2501
  return y.make(n);
2506
2502
  }
2507
2503
  function bt() {
2508
- return S("auth");
2504
+ return A("auth");
2509
2505
  }
2510
2506
  function Et(n) {
2511
2507
  return c(n);
2512
2508
  }
2513
2509
  function xt(n, e) {
2514
- const t = S("config");
2510
+ const t = A("config");
2515
2511
  return typeof n > "u" ? t : t.get(n, e);
2516
2512
  }
2517
2513
  function Mt(n, e = "default") {
2518
- return n ? S().make("error").get(n, e) : S().make("error");
2514
+ return n ? A().make("error").get(n, e) : A().make("error");
2519
2515
  }
2520
2516
  function _t(...n) {
2521
- const e = S("log");
2517
+ const e = A("log");
2522
2518
  return n.length ? e.debug(...n) : e;
2523
2519
  }
2524
2520
  function Tt(n) {
2525
- const e = S("model");
2521
+ const e = A("model");
2526
2522
  return n ? e.make(n) : e;
2527
2523
  }
2528
2524
  function $t(n, e = !1) {
2529
- const t = S("route");
2525
+ const t = A("route");
2530
2526
  return n ? e ? t.url([n, e]) : t.url(n) : t;
2531
2527
  }
2532
- class Rt {
2528
+ class St {
2533
2529
  constructor() {
2534
2530
  m(this, "name");
2535
2531
  m(this, "version");
@@ -2540,11 +2536,11 @@ class Rt {
2540
2536
  }
2541
2537
  }
2542
2538
  export {
2543
- R as HasEvents,
2544
- Rt as Plugin,
2545
- A as PropertyBag,
2546
- Se as Reducible,
2547
- S as app,
2539
+ S as HasEvents,
2540
+ St as Plugin,
2541
+ R as PropertyBag,
2542
+ Ae as Reducible,
2543
+ A as app,
2548
2544
  bt as auth,
2549
2545
  Et as collect,
2550
2546
  xt as config,
@@ -16,6 +16,7 @@ declare class App implements AppFacade {
16
16
  boot(configObject?: AppConfiguration): Promise<AppFacades>;
17
17
  environment(): string;
18
18
  environment(...environments: string[]): boolean;
19
+ getLocale(): string;
19
20
  getPlugin<T extends Plugin>(abstract: Constructor<T>): T | undefined;
20
21
  hasDebugModeEnabled(): boolean;
21
22
  isLocal(): boolean;
@@ -52,6 +52,7 @@ export type AppExternal = {
52
52
  environment(): string;
53
53
  environment(...environments: string[]): boolean;
54
54
  getPlugin<T extends Plugin>(abstract: Constructor<T>): T | undefined;
55
+ getLocale(): string;
55
56
  hasDebugModeEnabled(): boolean;
56
57
  isLocal(): boolean;
57
58
  isProduction(): boolean;
@@ -64,8 +64,6 @@ export declare class BaseModel implements EventSource<ModelEvents> {
64
64
  getRouteForSave(): RouteGenerator;
65
65
  getRouteForUpdate(): RouteGenerator;
66
66
  getRouteForDelete(): RouteGenerator;
67
- getRouteForRestore(): RouteGenerator;
68
- getRouteForForceDelete(): RouteGenerator;
69
67
  getRouteForRefresh(): RouteGenerator;
70
68
  static getSchemaName(): string;
71
69
  static getSchema(): ModelSchemaAttributes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luminix/core",
3
- "version": "0.0.1-beta.13",
3
+ "version": "0.0.1-beta.15",
4
4
  "description": "> Projeto em desenvolvimento",
5
5
  "main": "dist/core.js",
6
6
  "types": "dist/index.d.ts",