remult 2.7.31 → 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.
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "2.7.31",
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": {
package/src/context.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ClassType } from '../classType.js';
2
2
  import type { DataProvider } from './data-interfaces.js';
3
- import type { EntityMetadata, EntityRef, FindOptions, Repository } from './remult3/remult3.js';
3
+ import type { EntityMetadata, EntityRef, FindOptions, RefSubscriber, Repository } from './remult3/remult3.js';
4
4
  import type { ExternalHttpProvider } from './buildRestDataProvider.js';
5
5
  import type { SubscriptionClient, Unsubscribe } from './live-query/SubscriptionChannel.js';
6
6
  import type { LiveQueryStorage, SubscriptionServer } from './live-query/SubscriptionServer.js';
@@ -36,8 +36,12 @@ export declare class Remult {
36
36
  * @param dataProvider - an optional alternative data provider to use. Useful for writing to offline storage or an alternative data provider
37
37
  */
38
38
  repo: <T>(entity: ClassType<T>, dataProvider?: DataProvider) => Repository<T>;
39
+ private _subscribers?;
40
+ subscribeAuth(listener: RefSubscriber): Unsubscribe;
41
+ private __user?;
39
42
  /** Returns the current user's info */
40
- user?: UserInfo;
43
+ get user(): UserInfo | undefined;
44
+ set user(user: UserInfo | undefined);
41
45
  /**
42
46
  * Fetches user information from the backend and updates the `remult.user` object.
43
47
  * Typically used during application initialization and user authentication.
package/src/context.js CHANGED
@@ -16,6 +16,7 @@ var buildRestDataProvider_js_1 = require("./buildRestDataProvider.js");
16
16
  var relationInfoMember_js_1 = require("./remult3/relationInfoMember.js");
17
17
  var remult_static_js_1 = require("./remult-static.js");
18
18
  var initDataProvider_js_1 = require("../server/initDataProvider.js");
19
+ var SubscribableImp_js_1 = require("./remult3/SubscribableImp.js");
19
20
  var RemultAsyncLocalStorage = /** @class */ (function () {
20
21
  function RemultAsyncLocalStorage(remultObjectStorage) {
21
22
  this.remultObjectStorage = remultObjectStorage;
@@ -133,6 +134,26 @@ var Remult = /** @class */ (function () {
133
134
  this.apiClient.wrapMessageHandling = apiClient.wrapMessageHandling;
134
135
  }
135
136
  }
137
+ Remult.prototype.subscribeAuth = function (listener) {
138
+ if (!this._subscribers)
139
+ this._subscribers = new SubscribableImp_js_1.SubscribableImp();
140
+ return this._subscribers.subscribe(listener);
141
+ };
142
+ Object.defineProperty(Remult.prototype, "user", {
143
+ /** Returns the current user's info */
144
+ get: function () {
145
+ var _a;
146
+ (_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportObserved();
147
+ return this.__user;
148
+ },
149
+ set: function (user) {
150
+ var _a;
151
+ this.__user = user;
152
+ (_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportChanged();
153
+ },
154
+ enumerable: false,
155
+ configurable: true
156
+ });
136
157
  /**
137
158
  * Fetches user information from the backend and updates the `remult.user` object.
138
159
  * Typically used during application initialization and user authentication.
@@ -285,6 +285,9 @@ var RemultProxy = /** @class */ (function () {
285
285
  enumerable: false,
286
286
  configurable: true
287
287
  });
288
+ RemultProxy.prototype.subscribeAuth = function (listener) {
289
+ return remult_static_js_1.remultStatic.remultFactory().subscribeAuth(listener);
290
+ };
288
291
  RemultProxy.prototype.initUser = function () {
289
292
  return remult_static_js_1.remultStatic.remultFactory().initUser();
290
293
  };
@@ -4,13 +4,14 @@ import type { FieldMetadata, FieldOptions, ValueConverter, ValueListItem } from
4
4
  import { Remult } from '../context.js';
5
5
  import type { EntityOptions } from '../entity.js';
6
6
  import { Filter } from '../filter/filter-interfaces.js';
7
- import { type GroupByOptions, type GroupByResult, type ControllerRef, type ControllerRefForControllerBase, type EntityFilter, type EntityMetadata, type EntityOrderBy, type EntityRef, type EntityRefForEntityBase, type FieldRef, type FieldsMetadata, type FieldsRef, type FieldsRefForEntityBase, type FindFirstOptions, type FindFirstOptionsBase, type FindOptions, type IdMetadata, type LiveQuery, type LoadOptions, type MembersOnly, type NumericKeys, type Repository, type RepositoryRelations, type Subscribable, type idType } from './remult3.js';
7
+ import { type GroupByOptions, type GroupByResult, type ControllerRef, type ControllerRefForControllerBase, type EntityFilter, type EntityMetadata, type EntityOrderBy, type EntityRef, type EntityRefForEntityBase, type FieldRef, type FieldsMetadata, type FieldsRef, type FieldsRefForEntityBase, type FindFirstOptions, type FindFirstOptionsBase, type FindOptions, type IdMetadata, type LiveQuery, type LoadOptions, type MembersOnly, type NumericKeys, type Repository, type RepositoryRelations, type idType } from './remult3.js';
8
8
  import type { QueryOptions, RefSubscriber, UpsertOptions } from './remult3.js';
9
9
  import type { entityEventListener } from '../__EntityValueProvider.js';
10
10
  import { type DataProvider, type EntityDataProvider, type EntityDataProviderGroupByOptions, type EntityDataProviderFindOptions, type ErrorInfo, EntityError } from '../data-interfaces.js';
11
11
  import type { Unsubscribe } from '../live-query/SubscriptionChannel.js';
12
12
  import { RelationLoader } from './relation-loader.js';
13
13
  import { type RepositoryInternal, getInternalKey } from './repository-internals.js';
14
+ import { SubscribableImp } from './SubscribableImp.js';
14
15
  export declare class RepositoryImplementation<entityType> implements Repository<entityType>, RepositoryInternal<entityType> {
15
16
  private _entity;
16
17
  _remult: Remult;
@@ -333,15 +334,6 @@ export declare class ControllerBase {
333
334
  get $(): FieldsRefForEntityBase<this>;
334
335
  get _(): ControllerRefForControllerBase<this>;
335
336
  }
336
- declare class SubscribableImp implements Subscribable {
337
- reportChanged(): void;
338
- reportObserved(): void;
339
- private _subscribers?;
340
- subscribe(listener: (() => void) | {
341
- reportChanged: () => void;
342
- reportObserved: () => void;
343
- }): Unsubscribe;
344
- }
345
337
  export declare function getEntityMetadata<entityType>(entity: EntityMetadataOverloads<entityType>): EntityMetadata<entityType>;
346
338
  export declare function getRepository<entityType>(entity: RepositoryOverloads<entityType>): Repository<entityType>;
347
339
  export type EntityMetadataOverloads<entityType> = Repository<entityType> | EntityMetadata<entityType> | ClassType<entityType>;
@@ -36,6 +36,7 @@ var validators_js_1 = require("../validators.js");
36
36
  var addValidator_js_1 = require("./addValidator.js");
37
37
  var isOfType_js_1 = require("../isOfType.js");
38
38
  var QueryResultImpl_js_1 = require("./QueryResultImpl.js");
39
+ var SubscribableImp_js_1 = require("./SubscribableImp.js");
39
40
  //import { remult } from "../remult-proxy";
40
41
  var classValidatorValidate = undefined;
41
42
  // import ("class-validator".toString())
@@ -1773,7 +1774,7 @@ var rowHelperBase = /** @class */ (function () {
1773
1774
  if (!refImpl_1) {
1774
1775
  refImpl_1 = _this.fields.find(col.key);
1775
1776
  if (!refImpl_1._subscribers) {
1776
- refImpl_1._subscribers = new SubscribableImp();
1777
+ refImpl_1._subscribers = new SubscribableImp_js_1.SubscribableImp();
1777
1778
  }
1778
1779
  }
1779
1780
  refImpl_1._subscribers.reportObserved();
@@ -1787,7 +1788,7 @@ var rowHelperBase = /** @class */ (function () {
1787
1788
  if (!refImpl_1) {
1788
1789
  refImpl_1 = _this.fields.find(col.key);
1789
1790
  if (!refImpl_1._subscribers) {
1790
- refImpl_1._subscribers = new SubscribableImp();
1791
+ refImpl_1._subscribers = new SubscribableImp_js_1.SubscribableImp();
1791
1792
  }
1792
1793
  }
1793
1794
  refImpl_1._subscribers.reportChanged();
@@ -1869,12 +1870,12 @@ var rowHelperBase = /** @class */ (function () {
1869
1870
  rowHelperBase.prototype.initSubscribers = function () {
1870
1871
  var e_28, _a;
1871
1872
  if (!this._subscribers) {
1872
- this._subscribers = new SubscribableImp();
1873
+ this._subscribers = new SubscribableImp_js_1.SubscribableImp();
1873
1874
  var safeSubscribers_1 = this._subscribers;
1874
1875
  var _loop_6 = function (col) {
1875
1876
  var ei = (0, getEntityRef_js_1.getEntitySettings)(col.valueType, false);
1876
1877
  var refImpl = this_3.fields.find(col.key);
1877
- refImpl._subscribers = new SubscribableImp();
1878
+ refImpl._subscribers = new SubscribableImp_js_1.SubscribableImp();
1878
1879
  if ((ei && this_3.remult) || (0, relationInfoMember_js_1.getRelationFieldInfo)(col)) {
1879
1880
  }
1880
1881
  else {
@@ -3977,37 +3978,6 @@ var cacheEntityInfo = /** @class */ (function () {
3977
3978
  }
3978
3979
  return cacheEntityInfo;
3979
3980
  }());
3980
- var SubscribableImp = /** @class */ (function () {
3981
- function SubscribableImp() {
3982
- }
3983
- SubscribableImp.prototype.reportChanged = function () {
3984
- if (this._subscribers)
3985
- this._subscribers.forEach(function (x) { return x.reportChanged(); });
3986
- };
3987
- SubscribableImp.prototype.reportObserved = function () {
3988
- if (this._subscribers)
3989
- this._subscribers.forEach(function (x) { return x.reportObserved(); });
3990
- };
3991
- SubscribableImp.prototype.subscribe = function (listener) {
3992
- var _this = this;
3993
- var list;
3994
- if (typeof listener === 'function')
3995
- list = {
3996
- reportChanged: function () { return listener(); },
3997
- reportObserved: function () { },
3998
- };
3999
- else
4000
- list = listener;
4001
- if (!this._subscribers) {
4002
- this._subscribers = [];
4003
- }
4004
- this._subscribers.push(list);
4005
- return function () {
4006
- return (_this._subscribers = _this._subscribers.filter(function (x) { return x != list; }));
4007
- };
4008
- };
4009
- return SubscribableImp;
4010
- }());
4011
3981
  function getEntityMetadata(entity) {
4012
3982
  if (entity.metadata)
4013
3983
  return entity.metadata;
@@ -0,0 +1,11 @@
1
+ import type { Unsubscribe } from '../live-query/SubscriptionChannel.js';
2
+ import type { Subscribable } from './remult3.js';
3
+ export declare class SubscribableImp implements Subscribable {
4
+ reportChanged(): void;
5
+ reportObserved(): void;
6
+ private _subscribers?;
7
+ subscribe(listener: (() => void) | {
8
+ reportChanged: () => void;
9
+ reportObserved: () => void;
10
+ }): Unsubscribe;
11
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubscribableImp = void 0;
4
+ var SubscribableImp = /** @class */ (function () {
5
+ function SubscribableImp() {
6
+ }
7
+ SubscribableImp.prototype.reportChanged = function () {
8
+ if (this._subscribers)
9
+ this._subscribers.forEach(function (x) { return x.reportChanged(); });
10
+ };
11
+ SubscribableImp.prototype.reportObserved = function () {
12
+ if (this._subscribers)
13
+ this._subscribers.forEach(function (x) { return x.reportObserved(); });
14
+ };
15
+ SubscribableImp.prototype.subscribe = function (listener) {
16
+ var _this = this;
17
+ var list;
18
+ if (typeof listener === 'function')
19
+ list = {
20
+ reportChanged: function () { return listener(); },
21
+ reportObserved: function () { },
22
+ };
23
+ else
24
+ list = listener;
25
+ if (!this._subscribers) {
26
+ this._subscribers = [];
27
+ }
28
+ this._subscribers.push(list);
29
+ return function () {
30
+ return (_this._subscribers = _this._subscribers.filter(function (x) { return x != list; }));
31
+ };
32
+ };
33
+ return SubscribableImp;
34
+ }());
35
+ exports.SubscribableImp = SubscribableImp;