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.
@@ -3,6 +3,7 @@ import type { ClassType } from '../classType.js';
3
3
  import type { Remult } from '../src/context.js';
4
4
  import { EntityFilter } from '../src/remult3/remult3.js';
5
5
  export interface EntityUIInfo {
6
+ superKey: string;
6
7
  key: string;
7
8
  caption: string;
8
9
  fields: FieldUIInfo[];
@@ -14,118 +14,130 @@ function remultAdminHtml(options) {
14
14
  .replace('<!--PLACE_HERE_BODY-->', "<script>\n window.optionsFromServer = ".concat(JSON.stringify({ rootPath: rootPath }), "\n</script>"));
15
15
  }
16
16
  function buildEntityInfo(options) {
17
- var e_1, _a, e_2, _b, e_3, _c;
18
- var _d, _e;
17
+ var e_1, _a;
18
+ var _b, _c;
19
19
  var entities = [];
20
- try {
21
- for (var _f = tslib_1.__values(options.entities.map(function (e) { return options.remult.repo(e).metadata; })), _g = _f.next(); !_g.done; _g = _f.next()) {
22
- var metadata = _g.value;
23
- var fields = [];
24
- var relations = [];
25
- var ids = {};
26
- try {
27
- for (var _h = (e_2 = void 0, tslib_1.__values(metadata.idMetadata.fields)), _j = _h.next(); !_j.done; _j = _h.next()) {
28
- var f = _j.value;
29
- ids[f.key] = true;
30
- }
20
+ var _loop_1 = function (metadata) {
21
+ var e_2, _f, e_3, _g;
22
+ var fields = [];
23
+ var relations = [];
24
+ var ids = {};
25
+ try {
26
+ for (var _h = (e_2 = void 0, tslib_1.__values(metadata.idMetadata.fields)), _j = _h.next(); !_j.done; _j = _h.next()) {
27
+ var f = _j.value;
28
+ ids[f.key] = true;
31
29
  }
32
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
33
- finally {
34
- try {
35
- if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
36
- }
37
- finally { if (e_2) throw e_2.error; }
30
+ }
31
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
32
+ finally {
33
+ try {
34
+ if (_j && !_j.done && (_f = _h.return)) _f.call(_h);
38
35
  }
39
- var _loop_1 = function (x) {
40
- if (!x.includedInApi(undefined))
41
- return "continue";
42
- try {
43
- var relation = void 0;
44
- var valFieldKey = x.key;
45
- var info = (0, relationInfoMember_js_1.getRelationFieldInfo)(x);
46
- if (info) {
47
- var relInfo = info.getFields();
48
- var relRepo = options.remult.repo(info.toEntity);
49
- var where = typeof info.options.findOptions === 'object' &&
50
- info.options.findOptions.where
51
- ? filter_interfaces_js_1.Filter.entityFilterToJson(relRepo.metadata, info.options.findOptions.where)
52
- : undefined;
53
- var idField_1 = relRepo.metadata.idMetadata.field.key;
54
- if (info.type === 'reference' || info.type === 'toOne') {
55
- if (info.type == 'toOne') {
56
- for (var key in relInfo.fields) {
57
- if (Object.prototype.hasOwnProperty.call(relInfo.fields, key)) {
58
- var element = relInfo.fields[key];
59
- valFieldKey = element;
60
- }
36
+ finally { if (e_2) throw e_2.error; }
37
+ }
38
+ var _loop_2 = function (x) {
39
+ if (!x.includedInApi(undefined))
40
+ return "continue";
41
+ try {
42
+ var relation = void 0;
43
+ var valFieldKey = x.key;
44
+ var info = (0, relationInfoMember_js_1.getRelationFieldInfo)(x);
45
+ if (info) {
46
+ var relInfo = info.getFields();
47
+ var relRepo = options.remult.repo(info.toEntity);
48
+ var where = typeof info.options.findOptions === 'object' &&
49
+ info.options.findOptions.where
50
+ ? filter_interfaces_js_1.Filter.entityFilterToJson(relRepo.metadata, info.options.findOptions.where)
51
+ : undefined;
52
+ var idField_1 = relRepo.metadata.idMetadata.field.key;
53
+ if (info.type === 'reference' || info.type === 'toOne') {
54
+ if (info.type == 'toOne') {
55
+ for (var key in relInfo.fields) {
56
+ if (Object.prototype.hasOwnProperty.call(relInfo.fields, key)) {
57
+ var element = relInfo.fields[key];
58
+ valFieldKey = element;
61
59
  }
62
60
  }
63
- if (relRepo.metadata.apiReadAllowed) {
64
- relation = tslib_1.__assign(tslib_1.__assign({}, relInfo), { where: where, entityKey: relRepo.metadata.key, idField: idField_1, captionField: (_d = relRepo.metadata.fields
65
- .toArray()
66
- .find(function (x) { return x.key != idField_1 && x.valueType == String; })) === null || _d === void 0 ? void 0 : _d.key });
67
- }
68
61
  }
69
- else if (info.type === 'toMany') {
70
- if (relRepo.metadata.apiReadAllowed) {
71
- relations.push(tslib_1.__assign(tslib_1.__assign({}, relInfo), { where: where, entityKey: relRepo.metadata.key, key: x.key, caption: x.caption }));
72
- }
73
- return "continue";
62
+ if (relRepo.metadata.apiReadAllowed) {
63
+ relation = tslib_1.__assign(tslib_1.__assign({}, relInfo), { where: where, entityKey: relRepo.metadata.key, idField: idField_1, captionField: (_b = relRepo.metadata.fields
64
+ .toArray()
65
+ .find(function (x) { return x.key != idField_1 && x.valueType == String; })) === null || _b === void 0 ? void 0 : _b.key });
74
66
  }
75
67
  }
76
- fields.push({
77
- key: x.key,
78
- readOnly: !x.apiUpdateAllowed(),
79
- values: (0, RepositoryImplementation_js_1.getValueList)(x),
80
- valFieldKey: valFieldKey,
81
- caption: x.caption,
82
- relationToOne: relation,
83
- inputType: x.inputType,
84
- type: x.valueConverter.fieldTypeInDb == 'json'
85
- ? 'json'
86
- : x.valueType === Number
87
- ? 'number'
88
- : x.valueType === Boolean
89
- ? 'boolean'
90
- : x.valueType === Date
91
- ? 'date'
92
- : 'string',
93
- });
94
- }
95
- catch (error) {
96
- console.error("[remult-admin] Error with ".concat(metadata.key, ".").concat(x.key, " field."));
97
- console.error("[remult-admin]", error);
98
- }
99
- };
100
- try {
101
- for (var _k = (e_3 = void 0, tslib_1.__values(metadata.fields.toArray())), _l = _k.next(); !_l.done; _l = _k.next()) {
102
- var x = _l.value;
103
- _loop_1(x);
68
+ else if (info.type === 'toMany') {
69
+ if (relRepo.metadata.apiReadAllowed) {
70
+ relations.push(tslib_1.__assign(tslib_1.__assign({}, relInfo), { where: where, entityKey: relRepo.metadata.key, key: x.key, caption: x.caption }));
71
+ }
72
+ return "continue";
73
+ }
104
74
  }
75
+ fields.push({
76
+ key: x.key,
77
+ readOnly: !x.apiUpdateAllowed(),
78
+ values: (0, RepositoryImplementation_js_1.getValueList)(x),
79
+ valFieldKey: valFieldKey,
80
+ caption: x.caption,
81
+ relationToOne: relation,
82
+ inputType: x.inputType,
83
+ type: x.valueConverter.fieldTypeInDb == 'json'
84
+ ? 'json'
85
+ : x.valueType === Number
86
+ ? 'number'
87
+ : x.valueType === Boolean
88
+ ? 'boolean'
89
+ : x.valueType === Date
90
+ ? 'date'
91
+ : 'string',
92
+ });
105
93
  }
106
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
107
- finally {
108
- try {
109
- if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
110
- }
111
- finally { if (e_3) throw e_3.error; }
94
+ catch (error) {
95
+ console.error("[remult-admin] Error with ".concat(metadata.key, ".").concat(x.key, " field."));
96
+ console.error("[remult-admin]", error);
112
97
  }
113
- if (metadata.apiReadAllowed) {
114
- entities.push({
115
- key: metadata.key,
116
- caption: metadata.caption,
117
- ids: ids,
118
- fields: fields,
119
- relations: relations,
120
- defaultOrderBy: (_e = metadata.options.defaultOrderBy) !== null && _e !== void 0 ? _e : { id: 'asc' },
121
- });
98
+ };
99
+ try {
100
+ for (var _k = (e_3 = void 0, tslib_1.__values(metadata.fields.toArray())), _l = _k.next(); !_l.done; _l = _k.next()) {
101
+ var x = _l.value;
102
+ _loop_2(x);
122
103
  }
123
104
  }
105
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
106
+ finally {
107
+ try {
108
+ if (_l && !_l.done && (_g = _k.return)) _g.call(_k);
109
+ }
110
+ finally { if (e_3) throw e_3.error; }
111
+ }
112
+ if (metadata.apiReadAllowed) {
113
+ var superKey = metadata.key;
114
+ var caption = metadata.caption;
115
+ var nbOfEntities = entities.filter(function (e) { return e.key === metadata.key; }).length;
116
+ if (nbOfEntities > 0) {
117
+ superKey = metadata.key + '_ext_' + nbOfEntities;
118
+ caption = metadata.caption + '*'.repeat(nbOfEntities);
119
+ }
120
+ entities.push({
121
+ superKey: superKey,
122
+ key: metadata.key,
123
+ caption: caption,
124
+ ids: ids,
125
+ fields: fields,
126
+ relations: relations,
127
+ defaultOrderBy: (_c = metadata.options.defaultOrderBy) !== null && _c !== void 0 ? _c : { id: 'asc' },
128
+ });
129
+ }
130
+ };
131
+ try {
132
+ for (var _d = tslib_1.__values(options.entities.map(function (e) { return options.remult.repo(e).metadata; })), _e = _d.next(); !_e.done; _e = _d.next()) {
133
+ var metadata = _e.value;
134
+ _loop_1(metadata);
135
+ }
124
136
  }
125
137
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
126
138
  finally {
127
139
  try {
128
- if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
140
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
129
141
  }
130
142
  finally { if (e_1) throw e_1.error; }
131
143
  }
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;
@@ -138,7 +138,9 @@ var ValueConverters = /** @class */ (function () {
138
138
  toJson: function (value) { return ValueConverters.Number.toDb(value); },
139
139
  fromInput: function (x, type) {
140
140
  var r = +x;
141
- if (x === null || x === undefined)
141
+ if (x === null)
142
+ return null;
143
+ if (x === undefined)
142
144
  return undefined;
143
145
  return r;
144
146
  },