@luminix/core 0.0.1-beta.10 → 0.0.1-beta.12

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.
@@ -47,9 +47,9 @@ export declare class Collection<T> implements CollectionInterface<T> {
47
47
  filter(callback?: CollectionIteratorCallback<T, boolean>): CollectionInterface<T>;
48
48
  first(callback?: CollectionIteratorCallback<T, boolean>): T | null;
49
49
  firstOrFail(callback?: CollectionIteratorCallback<T, boolean>): T;
50
- firstWhere(key: keyof T): T | null;
51
- firstWhere(key: keyof T, value: T): T | null;
52
- firstWhere(key: keyof T, operator: Operator, value: T): T | null;
50
+ firstWhere<K extends keyof T>(key: K): T | null;
51
+ firstWhere<K extends keyof T>(key: K, value: T[K]): T | null;
52
+ firstWhere<K extends keyof T>(key: K, operator: Operator, value: T[K]): T | null;
53
53
  flatMap<R>(callback: CollectionIteratorCallback<T, R | R[]>): CollectionInterface<R>;
54
54
  forget(key: number): this;
55
55
  forPage(page: number, perPage: number): CollectionInterface<T>;
package/dist/core.js CHANGED
@@ -1,10 +1,10 @@
1
1
  var Ke = Object.defineProperty;
2
- var C = (n) => {
2
+ var L = (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) || 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);
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);
8
8
  import d from "lodash";
9
9
  import { produce as N, isDraftable as Pe } from "immer";
10
10
  import I, { isAxiosError as ke } from "axios";
@@ -15,7 +15,7 @@ class Qe extends (X = Error, V = Symbol.toStringTag, X) {
15
15
  m(this, V, "FacadeNotFoundException");
16
16
  }
17
17
  }
18
- class Le {
18
+ class Ce {
19
19
  constructor(e) {
20
20
  m(this, "_user");
21
21
  this.app = e;
@@ -64,7 +64,7 @@ class Le {
64
64
  return ((e = this.user()) == null ? void 0 : e.getKey()) || null;
65
65
  }
66
66
  }
67
- class Ce {
67
+ class Le {
68
68
  constructor(e) {
69
69
  this._debug = e;
70
70
  }
@@ -1294,6 +1294,7 @@ function Ve(n, e) {
1294
1294
  m(this, "_relations", {});
1295
1295
  m(this, "_changedKeys", []);
1296
1296
  m(this, "exists", !1);
1297
+ m(this, "wasRecentlyCreated", !1);
1297
1298
  m(this, r, d.upperFirst(d.camelCase(e)));
1298
1299
  this.makeRelations(), this.makeAttributes(s);
1299
1300
  }
@@ -1337,7 +1338,7 @@ function Ve(n, e) {
1337
1338
  }
1338
1339
  makePrimaryKeyReplacer() {
1339
1340
  return {
1340
- [this.primaryKey]: this.getAttribute(this.primaryKey)
1341
+ [this.getKeyName()]: this.getKey()
1341
1342
  };
1342
1343
  }
1343
1344
  dispatchChangeEvent(s) {
@@ -1561,6 +1562,10 @@ function Ve(n, e) {
1561
1562
  this.makePrimaryKeyReplacer()
1562
1563
  ];
1563
1564
  }
1565
+ getLabel() {
1566
+ const { labeledBy: s } = n.make("model").schema(e);
1567
+ return this.getAttribute(s);
1568
+ }
1564
1569
  async refresh() {
1565
1570
  if (!this.exists)
1566
1571
  throw new Re(e, "refresh");
@@ -1592,7 +1597,7 @@ function Ve(n, e) {
1592
1597
  }
1593
1598
  );
1594
1599
  if ([200, 201].includes(p.status))
1595
- return this.makeAttributes(p.data), this.exists = !0, this.dispatchSaveEvent(), a ? this.dispatchUpdateEvent(p.data) : this.dispatchCreateEvent(p.data), p;
1600
+ return this.makeAttributes(p.data), this.exists = !0, this.dispatchSaveEvent(), a ? this.dispatchUpdateEvent(p.data) : (this.wasRecentlyCreated = !0, this.dispatchCreateEvent(p.data)), p;
1596
1601
  throw p;
1597
1602
  } catch (u) {
1598
1603
  throw this.dispatchErrorEvent(u, "save"), u;
@@ -2371,7 +2376,7 @@ class at {
2371
2376
  } catch (g) {
2372
2377
  if (ot(g)) {
2373
2378
  const { errors: qe } = g.response.data;
2374
- this.error.set(Object.entries(qe).reduce((L, [Ie, Fe]) => (L[Ie] = Fe.join(" "), L), {}), f);
2379
+ this.error.set(Object.entries(qe).reduce((C, [Ie, Fe]) => (C[Ie] = Fe.join(" "), C), {}), f);
2375
2380
  } else I.isAxiosError(g) && this.error.set(
2376
2381
  this.axiosError({ axios: g.message }, {
2377
2382
  error: g,
@@ -2431,12 +2436,12 @@ class ct {
2431
2436
  } catch (g) {
2432
2437
  (p = e.app) != null && p.debug && console.error(g);
2433
2438
  }
2434
- this.bind("log", new Ce(!!((w = e.app) != null && w.debug)));
2439
+ this.bind("log", new Le(!!((w = e.app) != null && w.debug)));
2435
2440
  const { log: r } = this.facades, {
2436
2441
  manifest: { routes: i = {}, models: s = {} } = {},
2437
2442
  ...u
2438
2443
  } = e;
2439
- 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 Le(this)), this.emit("booting");
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");
2440
2445
  for (const g of Object.values(this.facades))
2441
2446
  typeof g == "object" && g !== null && "boot" in g && typeof g.boot == "function" && g.boot(this);
2442
2447
  for (const g of this._plugins)
@@ -548,9 +548,9 @@ export type Collection<T = unknown> = EventSource<CollectionEvents<T>> & {
548
548
  * ```
549
549
  *
550
550
  */
551
- firstWhere(key: keyof T): T | null;
552
- firstWhere(key: keyof T, value: T): T | null;
553
- firstWhere(key: keyof T, operator: Operator, value: T): T | null;
551
+ firstWhere<K extends keyof T>(key: K): T | null;
552
+ firstWhere<K extends keyof T>(key: K, value: T[K]): T | null;
553
+ firstWhere<K extends keyof T>(key: K, operator: Operator, value: T[K]): T | null;
554
554
  /**
555
555
  *
556
556
  * Calls a defined callback function on each element of the collection. Then,
@@ -42,10 +42,12 @@ export declare class BaseModel implements EventSource<ModelEvents> {
42
42
  get isDirty(): boolean;
43
43
  get casts(): ModelSchemaAttributes['casts'];
44
44
  exists: boolean;
45
+ wasRecentlyCreated: boolean;
45
46
  getAttribute(key: string): unknown;
46
47
  setAttribute(key: string, value: unknown): void;
47
48
  getKey(): string | number;
48
49
  getKeyName(): string;
50
+ getLabel(): string;
49
51
  fill(attributes: object): void;
50
52
  toJson(): JsonObject;
51
53
  diff(): JsonObject;
@@ -114,22 +116,23 @@ export interface ModelTableColumnDefinition {
114
116
  label: string;
115
117
  sortable?: boolean;
116
118
  }
119
+ export type ModelAttribute = {
120
+ appended: true | null;
121
+ cast: string | null;
122
+ default: string | null;
123
+ fillable: boolean;
124
+ hidden: boolean;
125
+ increments: boolean;
126
+ name: string;
127
+ nullable: boolean;
128
+ phpType: string | null;
129
+ primary: boolean;
130
+ type: string | null;
131
+ unique: boolean;
132
+ virtual: boolean;
133
+ };
117
134
  export interface ModelSchemaAttributes {
118
- attributes: {
119
- appended: true | null;
120
- cast: string | null;
121
- default: string | null;
122
- fillable: boolean;
123
- hidden: boolean;
124
- increments: boolean;
125
- name: string;
126
- nullable: boolean;
127
- phpType: string | null;
128
- primary: boolean;
129
- type: string | null;
130
- unique: boolean;
131
- virtual: boolean;
132
- }[];
135
+ attributes: ModelAttribute[];
133
136
  displayName: {
134
137
  singular: string;
135
138
  plural: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luminix/core",
3
- "version": "0.0.1-beta.10",
3
+ "version": "0.0.1-beta.12",
4
4
  "description": "> Projeto em desenvolvimento",
5
5
  "main": "dist/core.js",
6
6
  "types": "dist/index.d.ts",