remult 2.7.30 → 2.7.32-next.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.
@@ -93,9 +93,17 @@ export function buildEntityInfo(options) {
93
93
  }
94
94
  }
95
95
  if (metadata.apiReadAllowed) {
96
+ let superKey = metadata.key;
97
+ let caption = metadata.caption;
98
+ const nbOfEntities = entities.filter(e => e.key === metadata.key).length;
99
+ if (nbOfEntities > 0) {
100
+ superKey = metadata.key + '_ext_' + nbOfEntities;
101
+ caption = metadata.caption + '*'.repeat(nbOfEntities);
102
+ }
96
103
  entities.push({
104
+ superKey,
97
105
  key: metadata.key,
98
- caption: metadata.caption,
106
+ caption,
99
107
  ids,
100
108
  fields,
101
109
  relations,
@@ -8,6 +8,7 @@ import { buildRestDataProvider, isExternalHttpProvider, } from './buildRestDataP
8
8
  import { verifyFieldRelationInfo } from './remult3/relationInfoMember.js';
9
9
  import { remultStatic, resetFactory } from './remult-static.js';
10
10
  import { initDataProvider } from '../server/initDataProvider.js';
11
+ import { SubscribableImp } from './remult3/SubscribableImp.js';
11
12
  export class RemultAsyncLocalStorage {
12
13
  remultObjectStorage;
13
14
  static enable() {
@@ -75,8 +76,22 @@ export class Remult {
75
76
  }
76
77
  return r;
77
78
  };
79
+ _subscribers;
80
+ subscribeAuth(listener) {
81
+ if (!this._subscribers)
82
+ this._subscribers = new SubscribableImp();
83
+ return this._subscribers.subscribe(listener);
84
+ }
85
+ __user;
78
86
  /** Returns the current user's info */
79
- user;
87
+ get user() {
88
+ this._subscribers?.reportObserved();
89
+ return this.__user;
90
+ }
91
+ set user(user) {
92
+ this.__user = user;
93
+ this._subscribers?.reportChanged();
94
+ }
80
95
  /**
81
96
  * Fetches user information from the backend and updates the `remult.user` object.
82
97
  * Typically used during application initialization and user authentication.
@@ -28,6 +28,9 @@ export class RemultProxy {
28
28
  set liveQueryPublisher(val) {
29
29
  remultStatic.remultFactory().liveQueryPublisher = val;
30
30
  }
31
+ subscribeAuth(listener) {
32
+ return remultStatic.remultFactory().subscribeAuth(listener);
33
+ }
31
34
  initUser() {
32
35
  return remultStatic.remultFactory().initUser();
33
36
  }
@@ -20,6 +20,7 @@ import { Validators } from '../validators.js';
20
20
  import { addValidator } from './addValidator.js';
21
21
  import { isOfType } from '../isOfType.js';
22
22
  import { QueryResultImpl } from './QueryResultImpl.js';
23
+ import { SubscribableImp } from './SubscribableImp.js';
23
24
  //import { remult } from "../remult-proxy";
24
25
  let classValidatorValidate = undefined;
25
26
  // import ("class-validator".toString())
@@ -2502,32 +2503,6 @@ class cacheEntityInfo {
2502
2503
  value = {};
2503
2504
  promise;
2504
2505
  }
2505
- class SubscribableImp {
2506
- reportChanged() {
2507
- if (this._subscribers)
2508
- this._subscribers.forEach((x) => x.reportChanged());
2509
- }
2510
- reportObserved() {
2511
- if (this._subscribers)
2512
- this._subscribers.forEach((x) => x.reportObserved());
2513
- }
2514
- _subscribers;
2515
- subscribe(listener) {
2516
- let list;
2517
- if (typeof listener === 'function')
2518
- list = {
2519
- reportChanged: () => listener(),
2520
- reportObserved: () => { },
2521
- };
2522
- else
2523
- list = listener;
2524
- if (!this._subscribers) {
2525
- this._subscribers = [];
2526
- }
2527
- this._subscribers.push(list);
2528
- return () => (this._subscribers = this._subscribers.filter((x) => x != list));
2529
- }
2530
- }
2531
2506
  export function getEntityMetadata(entity) {
2532
2507
  if (entity.metadata)
2533
2508
  return entity.metadata;
@@ -0,0 +1,26 @@
1
+ export class SubscribableImp {
2
+ reportChanged() {
3
+ if (this._subscribers)
4
+ this._subscribers.forEach((x) => x.reportChanged());
5
+ }
6
+ reportObserved() {
7
+ if (this._subscribers)
8
+ this._subscribers.forEach((x) => x.reportObserved());
9
+ }
10
+ _subscribers;
11
+ subscribe(listener) {
12
+ let list;
13
+ if (typeof listener === 'function')
14
+ list = {
15
+ reportChanged: () => listener(),
16
+ reportObserved: () => { },
17
+ };
18
+ else
19
+ list = listener;
20
+ if (!this._subscribers) {
21
+ this._subscribers = [];
22
+ }
23
+ this._subscribers.push(list);
24
+ return () => (this._subscribers = this._subscribers.filter((x) => x != list));
25
+ }
26
+ }
@@ -136,7 +136,9 @@ export class ValueConverters {
136
136
  toJson: (value) => ValueConverters.Number.toDb(value),
137
137
  fromInput: (x, type) => {
138
138
  let r = +x;
139
- if (x === null || x === undefined)
139
+ if (x === null)
140
+ return null;
141
+ if (x === undefined)
140
142
  return undefined;
141
143
  return r;
142
144
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "2.7.30",
3
+ "version": "2.7.32-next.0",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {