remult 2.7.30 → 2.7.31

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
  }
@@ -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
  },