@michalrakus/x-react-web-lib 1.12.0 → 1.14.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.
- package/XFormCol.d.ts +3 -0
- package/XFormCol.js +5 -0
- package/XFormInlineRow.d.ts +3 -0
- package/XFormInlineRow.js +5 -0
- package/XFormRow.d.ts +3 -0
- package/XFormRow.js +5 -0
- package/XFormRowCol.d.ts +3 -0
- package/XFormRowCol.js +5 -0
- package/XUtilsConversions.d.ts +1 -1
- package/XUtilsConversions.js +1 -1
- package/XUtilsMetadataCommon.d.ts +3 -0
- package/XUtilsMetadataCommon.js +5 -0
- package/gulpfile.js +8 -2
- package/lib/components/XAutoComplete.d.ts +4 -2
- package/lib/components/XAutoComplete.js +13 -11
- package/lib/components/XAutoCompleteBase.d.ts +5 -0
- package/lib/components/XAutoCompleteBase.js +34 -3
- package/lib/components/XAutoCompleteDT.js +4 -4
- package/lib/components/XCalendar.js +1 -1
- package/lib/components/XDropdown.js +2 -2
- package/lib/components/XDropdownDT.js +4 -4
- package/lib/components/XDropdownDTFilter.d.ts +3 -0
- package/lib/components/XDropdownDTFilter.js +7 -6
- package/lib/components/XDropdownForEntity.js +2 -2
- package/lib/components/XEditBrowse.js +4 -3
- package/lib/components/XExportRowsDialog.js +1 -1
- package/lib/components/XFieldSelector.js +4 -4
- package/lib/components/XFormDataTable2.d.ts +15 -9
- package/lib/components/XFormDataTable2.js +42 -32
- package/lib/components/XFormRowCol/XFormCol.d.ts +8 -0
- package/lib/components/XFormRowCol/XFormCol.js +12 -0
- package/lib/components/XFormRowCol/XFormInlineRow.d.ts +8 -0
- package/lib/components/XFormRowCol/XFormInlineRow.js +12 -0
- package/lib/components/XFormRowCol/XFormRow.d.ts +8 -0
- package/lib/components/XFormRowCol/XFormRow.js +12 -0
- package/lib/components/XFormRowCol/XFormRowCol.d.ts +9 -0
- package/lib/components/XFormRowCol/XFormRowCol.js +30 -0
- package/lib/components/XFtsInput.js +1 -1
- package/lib/components/XInput.js +2 -2
- package/lib/components/XInputDT.js +2 -2
- package/lib/components/XInputDateDT.js +1 -1
- package/lib/components/XInputFileList.js +6 -6
- package/lib/components/XInputIntervalBase.js +1 -1
- package/lib/components/XInputText.js +1 -1
- package/lib/components/XInputTextDT.js +3 -3
- package/lib/components/XInputTextarea.js +1 -1
- package/lib/components/XLazyDataTable.d.ts +19 -1
- package/lib/components/XLazyDataTable.js +26 -45
- package/lib/components/XSearchButton.js +4 -4
- package/lib/components/XSearchButtonDT.js +3 -3
- package/lib/components/XSearchButtonOld.js +5 -5
- package/lib/components/XToOneAssocButton.js +3 -3
- package/lib/components/XUtils.d.ts +8 -0
- package/lib/components/XUtils.js +25 -2
- package/lib/components/XUtilsMetadata.d.ts +1 -19
- package/lib/components/XUtilsMetadata.js +8 -186
- package/lib/components/locale/x-en.json +4 -1
- package/lib/{components → serverApi}/XUtilsConversions.d.ts +18 -1
- package/lib/serverApi/XUtilsConversions.js +330 -0
- package/lib/serverApi/XUtilsMetadataCommon.d.ts +30 -0
- package/lib/serverApi/XUtilsMetadataCommon.js +208 -0
- package/package.json +2 -2
- package/lib/components/XUtilsConversions.js +0 -177
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.convertValue = exports.convertObject = exports.AsUIType = exports.booleanAsUIText = exports.intervalAsUI = exports.intervalFromUI = exports.datetimeFormatUI = exports.dateFormatCalendar = exports.dateFormatUI = exports.timeFromModel = exports.datetimeAsUI = exports.dateAsUI = exports.dateFromModel = exports.numberFromModel = exports.numberAsUI = exports.numberFromUI = exports.stringAsDB = exports.stringAsUI = exports.stringFromUI = void 0;
|
|
31
|
+
var XUtilsCommon_1 = require("./XUtilsCommon");
|
|
32
|
+
var XLocale_1 = require("../components/XLocale");
|
|
33
|
+
var XUtilsMetadataCommon_1 = require("./XUtilsMetadataCommon");
|
|
34
|
+
function stringFromUI(stringValue) {
|
|
35
|
+
var value;
|
|
36
|
+
if (stringValue === '') {
|
|
37
|
+
value = null;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
value = stringValue;
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
exports.stringFromUI = stringFromUI;
|
|
45
|
+
function stringAsUI(value) {
|
|
46
|
+
return value !== null ? value : "";
|
|
47
|
+
}
|
|
48
|
+
exports.stringAsUI = stringAsUI;
|
|
49
|
+
// aby sme sa vyhli sql injection problemu - tam kde je problematicke pouzivat klasicke params
|
|
50
|
+
function stringAsDB(value) {
|
|
51
|
+
return value !== null ? "'".concat(value.replaceAll("'", "''"), "'") : "NULL";
|
|
52
|
+
}
|
|
53
|
+
exports.stringAsDB = stringAsDB;
|
|
54
|
+
function numberFromUI(stringValue) {
|
|
55
|
+
var value;
|
|
56
|
+
if (stringValue === '') {
|
|
57
|
+
value = null;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
value = parseInt(stringValue, 10);
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
exports.numberFromUI = numberFromUI;
|
|
65
|
+
function numberAsUI(value, fractionDigits) {
|
|
66
|
+
if (fractionDigits === undefined) {
|
|
67
|
+
fractionDigits = 2; // default
|
|
68
|
+
}
|
|
69
|
+
if (value !== null) {
|
|
70
|
+
return value.toLocaleString('de-DE', { style: 'decimal', minimumFractionDigits: fractionDigits, maximumFractionDigits: fractionDigits });
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return "";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.numberAsUI = numberAsUI;
|
|
77
|
+
// v modeli na klientovi by mal byt vzdy number, teraz je tam niekedy string (z json-u zo servera) a niekedy number (z komponentu)
|
|
78
|
+
// provizorne zatial takato konverzia
|
|
79
|
+
function numberFromModel(value) {
|
|
80
|
+
var numberValue = null;
|
|
81
|
+
if (typeof value === 'string') {
|
|
82
|
+
numberValue = parseFloat(value);
|
|
83
|
+
}
|
|
84
|
+
else if (typeof value === 'number') {
|
|
85
|
+
numberValue = value;
|
|
86
|
+
}
|
|
87
|
+
return numberValue;
|
|
88
|
+
}
|
|
89
|
+
exports.numberFromModel = numberFromModel;
|
|
90
|
+
// v modeli na klientovi by mal byt vzdy Date, teraz je tam niekedy string (z json-u zo servera) a niekedy Date (z komponentu)
|
|
91
|
+
// provizorne zatial takato konverzia
|
|
92
|
+
function dateFromModel(value) {
|
|
93
|
+
var dateValue = null;
|
|
94
|
+
if (typeof value === 'string') {
|
|
95
|
+
dateValue = new Date(value);
|
|
96
|
+
}
|
|
97
|
+
else if (typeof value === 'object' && value instanceof Date) {
|
|
98
|
+
dateValue = value;
|
|
99
|
+
}
|
|
100
|
+
return dateValue;
|
|
101
|
+
}
|
|
102
|
+
exports.dateFromModel = dateFromModel;
|
|
103
|
+
function dateAsUI(value) {
|
|
104
|
+
if (value !== null) {
|
|
105
|
+
return (0, XUtilsCommon_1.dateFormat)(value, dateFormatUI());
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
return "";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.dateAsUI = dateAsUI;
|
|
112
|
+
function datetimeAsUI(value) {
|
|
113
|
+
if (value !== null) {
|
|
114
|
+
return (0, XUtilsCommon_1.dateFormat)(value, datetimeFormatUI());
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return "";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.datetimeAsUI = datetimeAsUI;
|
|
121
|
+
// provizorne zatial takato konverzia
|
|
122
|
+
function timeFromModel(value) {
|
|
123
|
+
var timeValue = null;
|
|
124
|
+
if (typeof value === 'string') {
|
|
125
|
+
// ak prichadza cas priamo z databazy, pride '19:30:00'
|
|
126
|
+
// ak prichadza reloadnuty objekt (napr. cez webservis saveRow), pride '2021-06-07 19:30:00'
|
|
127
|
+
var rowDataCasStr = value;
|
|
128
|
+
if (rowDataCasStr.length < 10) {
|
|
129
|
+
// mame '19:30:00' -> pridame hociaky rok aby sme skonvertovali na validny Date
|
|
130
|
+
rowDataCasStr = '1970-01-01 ' + rowDataCasStr;
|
|
131
|
+
}
|
|
132
|
+
// na safari nefunguje konverzia new Date('2021-06-07 19:30:00') - vrati NaN
|
|
133
|
+
// preto string prehodime na '2021-06-07T19:30:00+01:00'
|
|
134
|
+
// 19:30:00 je cas z timezony Central Europe (taka je nastavena na nodejs)), preto oznacime tento cas touto timezonou
|
|
135
|
+
// (spravne riesenie je posielat time cez json vzdy vo formate '2021-06-07T18:30:00Z', v tomto formate chodia aj datetime atributy)
|
|
136
|
+
rowDataCasStr = rowDataCasStr.replace(' ', 'T');
|
|
137
|
+
if (!rowDataCasStr.endsWith('Z') && rowDataCasStr.indexOf('+') === -1) {
|
|
138
|
+
rowDataCasStr += '+01:00'; // Central Europe timezone
|
|
139
|
+
}
|
|
140
|
+
timeValue = new Date(rowDataCasStr);
|
|
141
|
+
}
|
|
142
|
+
else if (typeof value === 'object' && value instanceof Date) {
|
|
143
|
+
timeValue = value;
|
|
144
|
+
}
|
|
145
|
+
return timeValue;
|
|
146
|
+
}
|
|
147
|
+
exports.timeFromModel = timeFromModel;
|
|
148
|
+
function dateFormatUI() {
|
|
149
|
+
return "dd.mm.yyyy";
|
|
150
|
+
}
|
|
151
|
+
exports.dateFormatUI = dateFormatUI;
|
|
152
|
+
function dateFormatCalendar() {
|
|
153
|
+
return "dd.mm.yy";
|
|
154
|
+
}
|
|
155
|
+
exports.dateFormatCalendar = dateFormatCalendar;
|
|
156
|
+
function datetimeFormatUI() {
|
|
157
|
+
return "dd.mm.yyyy HH:MM:ss";
|
|
158
|
+
}
|
|
159
|
+
exports.datetimeFormatUI = datetimeFormatUI;
|
|
160
|
+
function intervalFromUI(valueString) {
|
|
161
|
+
// convert e.target.value (e.g. 10:29) into IPostgresInterval (e.g. {hours: 10, minutes: 29})
|
|
162
|
+
// if stringValue is invalid, returns undefined
|
|
163
|
+
var valueInterval = undefined;
|
|
164
|
+
if (valueString === '') {
|
|
165
|
+
valueInterval = null;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
var posColon = valueString.indexOf(':');
|
|
169
|
+
if (posColon === -1) {
|
|
170
|
+
var minutes = parseInt(valueString);
|
|
171
|
+
if (!isNaN(minutes)) {
|
|
172
|
+
var hours = Math.floor(minutes / 60);
|
|
173
|
+
minutes = minutes - (hours * 60);
|
|
174
|
+
valueInterval = { hours: hours, minutes: minutes };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
var hours = parseInt(valueString.substring(0, posColon));
|
|
179
|
+
var minutes = parseInt(valueString.substring(posColon + 1));
|
|
180
|
+
if (!isNaN(hours) && !isNaN(minutes)) {
|
|
181
|
+
if (minutes >= 60) {
|
|
182
|
+
var hoursFromMinutes = Math.floor(minutes / 60);
|
|
183
|
+
hours += hoursFromMinutes;
|
|
184
|
+
minutes = minutes - (hoursFromMinutes * 60);
|
|
185
|
+
}
|
|
186
|
+
valueInterval = { hours: hours, minutes: minutes };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return valueInterval;
|
|
191
|
+
}
|
|
192
|
+
exports.intervalFromUI = intervalFromUI;
|
|
193
|
+
function intervalAsUI(valueInterval) {
|
|
194
|
+
var _a, _b;
|
|
195
|
+
// conversion e.g. {hours: 10, minutes: 29} => '10:29'
|
|
196
|
+
var valueString;
|
|
197
|
+
if (valueInterval !== null) {
|
|
198
|
+
var hours = (_a = valueInterval.hours) !== null && _a !== void 0 ? _a : 0;
|
|
199
|
+
var minutes = (_b = valueInterval.minutes) !== null && _b !== void 0 ? _b : 0;
|
|
200
|
+
//const seconds: number = value.seconds ?? 0;
|
|
201
|
+
if (valueInterval.days) {
|
|
202
|
+
hours += valueInterval.days * 24;
|
|
203
|
+
}
|
|
204
|
+
valueString = "".concat(hours.toString(), ":").concat(minutes.toString().padStart(2, '0'));
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
valueString = ''; // null
|
|
208
|
+
}
|
|
209
|
+
return valueString;
|
|
210
|
+
}
|
|
211
|
+
exports.intervalAsUI = intervalAsUI;
|
|
212
|
+
function booleanAsUIText(value) {
|
|
213
|
+
if (value !== null) {
|
|
214
|
+
return value ? (0, XLocale_1.xLocaleOption)('yes') : (0, XLocale_1.xLocaleOption)('no');
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
return "";
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.booleanAsUIText = booleanAsUIText;
|
|
221
|
+
var AsUIType;
|
|
222
|
+
(function (AsUIType) {
|
|
223
|
+
AsUIType[AsUIType["Form"] = 1] = "Form";
|
|
224
|
+
AsUIType[AsUIType["Text"] = 2] = "Text"; // reporty - boolean sa konvertuje na ano/nie
|
|
225
|
+
})(AsUIType = exports.AsUIType || (exports.AsUIType = {}));
|
|
226
|
+
/**
|
|
227
|
+
* converts values of object
|
|
228
|
+
*
|
|
229
|
+
* @param entity
|
|
230
|
+
* @param object
|
|
231
|
+
* @param fromModel
|
|
232
|
+
* @param asUI
|
|
233
|
+
*/
|
|
234
|
+
function convertObject(entity, object, fromModel, asUI) {
|
|
235
|
+
var e_1, _a, e_2, _b;
|
|
236
|
+
var xEntity = XUtilsMetadataCommon_1.XUtilsMetadataCommon.getXEntity(entity);
|
|
237
|
+
try {
|
|
238
|
+
for (var _c = __values(Object.entries(object)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
239
|
+
var _e = __read(_d.value, 2), field = _e[0], value = _e[1];
|
|
240
|
+
var xField = XUtilsMetadataCommon_1.XUtilsMetadataCommon.getXFieldBase(xEntity, field);
|
|
241
|
+
if (xField) {
|
|
242
|
+
object[field] = convertValue(xField, value, fromModel, asUI);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
// nenasli sme medzi fieldami, skusime hladat xAssoc
|
|
246
|
+
var xAssoc = XUtilsMetadataCommon_1.XUtilsMetadataCommon.getXAssocBase(xEntity, field);
|
|
247
|
+
if (xAssoc) {
|
|
248
|
+
if (value) {
|
|
249
|
+
if (xAssoc.relationType === "many-to-one" || xAssoc.relationType === "one-to-one") {
|
|
250
|
+
convertObject(xAssoc.entityName, value, fromModel, asUI);
|
|
251
|
+
}
|
|
252
|
+
else if (xAssoc.relationType === "one-to-many" || xAssoc.relationType === "many-to-many") {
|
|
253
|
+
if (!Array.isArray(value)) {
|
|
254
|
+
throw "Unexpected error: entity ".concat(entity, " - field ").concat(field, " is expected to be array");
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
for (var value_1 = (e_2 = void 0, __values(value)), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
|
|
258
|
+
var valueItem = value_1_1.value;
|
|
259
|
+
convertObject(xAssoc.entityName, valueItem, fromModel, asUI);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
263
|
+
finally {
|
|
264
|
+
try {
|
|
265
|
+
if (value_1_1 && !value_1_1.done && (_b = value_1.return)) _b.call(value_1);
|
|
266
|
+
}
|
|
267
|
+
finally { if (e_2) throw e_2.error; }
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
276
|
+
finally {
|
|
277
|
+
try {
|
|
278
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
279
|
+
}
|
|
280
|
+
finally { if (e_1) throw e_1.error; }
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
exports.convertObject = convertObject;
|
|
284
|
+
function convertValue(xField, value, fromModel, asUI) {
|
|
285
|
+
if (xField.type === "decimal") {
|
|
286
|
+
if (fromModel) {
|
|
287
|
+
value = numberFromModel(value);
|
|
288
|
+
}
|
|
289
|
+
if (asUI) {
|
|
290
|
+
value = numberAsUI(value, xField.scale);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
else if (xField.type === "date") {
|
|
294
|
+
if (fromModel) {
|
|
295
|
+
value = dateFromModel(value);
|
|
296
|
+
}
|
|
297
|
+
if (asUI) {
|
|
298
|
+
value = dateAsUI(value);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else if (xField.type === "datetime") {
|
|
302
|
+
if (fromModel) {
|
|
303
|
+
value = dateFromModel(value);
|
|
304
|
+
}
|
|
305
|
+
if (asUI) {
|
|
306
|
+
value = datetimeAsUI(value);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else if (xField.type === "interval") {
|
|
310
|
+
// konverziu z modelu (json objekt-u) netreba
|
|
311
|
+
if (asUI) {
|
|
312
|
+
value = intervalAsUI(value);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
else if (xField.type === "boolean") {
|
|
316
|
+
// konverziu z modelu (json objekt-u) netreba
|
|
317
|
+
// pre AsUIType.Form ponechame typ boolean (spracujeme neskor)
|
|
318
|
+
if (asUI === AsUIType.Text) {
|
|
319
|
+
value = booleanAsUIText(value);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
// vsetko ostatne
|
|
324
|
+
if (asUI) {
|
|
325
|
+
value = value ? value.toString() : "";
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return value;
|
|
329
|
+
}
|
|
330
|
+
exports.convertValue = convertValue;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { XAssoc, XEntity, XEntityMap, XField, XRelationType } from "./XEntityMetadata";
|
|
2
|
+
/**
|
|
3
|
+
* spolocna funkcionalita pre entity metadata vyuzivana na frontend-e aj backend-e
|
|
4
|
+
* vznikla na zaklade XEntityMetadataService
|
|
5
|
+
* tato funkcionalita by este mohla ist do tried XEntity, XField
|
|
6
|
+
*/
|
|
7
|
+
export declare class XUtilsMetadataCommon {
|
|
8
|
+
private static xEntityMap;
|
|
9
|
+
static getXEntityMap(): XEntityMap | undefined;
|
|
10
|
+
static setXEntityMap(xEntityMap: XEntityMap): void;
|
|
11
|
+
static getXEntity(entity: string): XEntity;
|
|
12
|
+
static getXFieldBase(xEntity: XEntity, field: string): XField | undefined;
|
|
13
|
+
static getXField(xEntity: XEntity, field: string): XField;
|
|
14
|
+
static getXFieldByPath(xEntity: XEntity, path: string): XField;
|
|
15
|
+
static getXFieldByPathStr(entity: string, path: string): XField;
|
|
16
|
+
static getXAssocBase(xEntity: XEntity, assocField: string): XAssoc | undefined;
|
|
17
|
+
static getXAssocByPath(xEntity: XEntity, path: string): XAssoc;
|
|
18
|
+
static getLastXAssocByPath(xEntity: XEntity, path: string): XAssoc;
|
|
19
|
+
static getXAssocToOne(xEntity: XEntity, assocField: string): XAssoc;
|
|
20
|
+
static getXAssocToMany(xEntity: XEntity, assocField: string): XAssoc;
|
|
21
|
+
static getXAssocToOneByAssocEntity(xEntity: XEntity, assocEntityName: string): XAssoc;
|
|
22
|
+
static getXAssocToManyByAssocEntity(xEntity: XEntity, assocEntityName: string): XAssoc;
|
|
23
|
+
static getXEntityForAssocToOne(xEntity: XEntity, assocField: string): XEntity;
|
|
24
|
+
static getXEntityForAssocToMany(xEntity: XEntity, assocField: string): XEntity;
|
|
25
|
+
static getXFieldList(xEntity: XEntity): XField[];
|
|
26
|
+
static getXAssocList(xEntity: XEntity, relationTypeList?: XRelationType[]): XAssoc[];
|
|
27
|
+
private static getXAssoc;
|
|
28
|
+
private static getXAssocByAssocEntity;
|
|
29
|
+
private static getXEntityForAssoc;
|
|
30
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __values = (this && this.__values) || function(o) {
|
|
19
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
20
|
+
if (m) return m.call(o);
|
|
21
|
+
if (o && typeof o.length === "number") return {
|
|
22
|
+
next: function () {
|
|
23
|
+
if (o && i >= o.length) o = void 0;
|
|
24
|
+
return { value: o && o[i++], done: !o };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.XUtilsMetadataCommon = void 0;
|
|
31
|
+
var XUtilsCommon_1 = require("./XUtilsCommon");
|
|
32
|
+
/**
|
|
33
|
+
* spolocna funkcionalita pre entity metadata vyuzivana na frontend-e aj backend-e
|
|
34
|
+
* vznikla na zaklade XEntityMetadataService
|
|
35
|
+
* tato funkcionalita by este mohla ist do tried XEntity, XField
|
|
36
|
+
*/
|
|
37
|
+
var XUtilsMetadataCommon = /** @class */ (function () {
|
|
38
|
+
function XUtilsMetadataCommon() {
|
|
39
|
+
}
|
|
40
|
+
XUtilsMetadataCommon.getXEntityMap = function () {
|
|
41
|
+
return XUtilsMetadataCommon.xEntityMap;
|
|
42
|
+
};
|
|
43
|
+
XUtilsMetadataCommon.setXEntityMap = function (xEntityMap) {
|
|
44
|
+
XUtilsMetadataCommon.xEntityMap = xEntityMap;
|
|
45
|
+
};
|
|
46
|
+
XUtilsMetadataCommon.getXEntity = function (entity) {
|
|
47
|
+
if (!XUtilsMetadataCommon.xEntityMap) {
|
|
48
|
+
throw "Unexpected error: XUtilsMetadataCommon.xEntityMap not initialised. Call XUtilsMetadataCommon.setXEntityMap first.";
|
|
49
|
+
}
|
|
50
|
+
var xEntity = XUtilsMetadataCommon.xEntityMap[entity];
|
|
51
|
+
if (xEntity === undefined) {
|
|
52
|
+
throw "Entity ".concat(entity, " was not found in entity metadata");
|
|
53
|
+
}
|
|
54
|
+
return xEntity;
|
|
55
|
+
};
|
|
56
|
+
XUtilsMetadataCommon.getXFieldBase = function (xEntity, field) {
|
|
57
|
+
// TODO - pozor, vo fieldMap su aj asociacie, trebalo by zmenit vytvaranie metadat tak aby tam tie asociacie neboli
|
|
58
|
+
return xEntity.fieldMap[field];
|
|
59
|
+
};
|
|
60
|
+
XUtilsMetadataCommon.getXField = function (xEntity, field) {
|
|
61
|
+
var xField = XUtilsMetadataCommon.getXFieldBase(xEntity, field);
|
|
62
|
+
if (xField === undefined) {
|
|
63
|
+
throw "Field ".concat(field, " was not found in entity ").concat(xEntity.name);
|
|
64
|
+
}
|
|
65
|
+
return xField;
|
|
66
|
+
};
|
|
67
|
+
XUtilsMetadataCommon.getXFieldByPath = function (xEntity, path) {
|
|
68
|
+
var _a = __read(XUtilsCommon_1.XUtilsCommon.getFieldAndRestPath(path), 2), field = _a[0], restPath = _a[1];
|
|
69
|
+
if (restPath === null) {
|
|
70
|
+
return XUtilsMetadataCommon.getXField(xEntity, field);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
var xAssoc = XUtilsMetadataCommon.getXAssoc(xEntity, field);
|
|
74
|
+
var xAssocEntity = XUtilsMetadataCommon.getXEntity(xAssoc.entityName);
|
|
75
|
+
return XUtilsMetadataCommon.getXFieldByPath(xAssocEntity, restPath);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
XUtilsMetadataCommon.getXFieldByPathStr = function (entity, path) {
|
|
79
|
+
return XUtilsMetadataCommon.getXFieldByPath(XUtilsMetadataCommon.getXEntity(entity), path);
|
|
80
|
+
};
|
|
81
|
+
XUtilsMetadataCommon.getXAssocBase = function (xEntity, assocField) {
|
|
82
|
+
return xEntity.assocMap[assocField];
|
|
83
|
+
};
|
|
84
|
+
XUtilsMetadataCommon.getXAssocByPath = function (xEntity, path) {
|
|
85
|
+
var _a = __read(XUtilsCommon_1.XUtilsCommon.getFieldAndRestPath(path), 2), field = _a[0], restPath = _a[1];
|
|
86
|
+
if (restPath === null) {
|
|
87
|
+
return XUtilsMetadataCommon.getXAssoc(xEntity, field);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
var xAssoc = XUtilsMetadataCommon.getXAssoc(xEntity, field);
|
|
91
|
+
var xAssocEntity = XUtilsMetadataCommon.getXEntity(xAssoc.entityName);
|
|
92
|
+
return XUtilsMetadataCommon.getXAssocByPath(xAssocEntity, restPath);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// for path assoc1.assoc2.field returns assoc2 (last assoc before field)
|
|
96
|
+
XUtilsMetadataCommon.getLastXAssocByPath = function (xEntity, path) {
|
|
97
|
+
var pathToAssoc = XUtilsCommon_1.XUtilsCommon.getPathToAssoc(path);
|
|
98
|
+
return XUtilsMetadataCommon.getXAssocByPath(xEntity, pathToAssoc);
|
|
99
|
+
};
|
|
100
|
+
XUtilsMetadataCommon.getXAssocToOne = function (xEntity, assocField) {
|
|
101
|
+
return XUtilsMetadataCommon.getXAssoc(xEntity, assocField, ["many-to-one", "one-to-one"]);
|
|
102
|
+
};
|
|
103
|
+
XUtilsMetadataCommon.getXAssocToMany = function (xEntity, assocField) {
|
|
104
|
+
return XUtilsMetadataCommon.getXAssoc(xEntity, assocField, ["one-to-many", "many-to-many"]);
|
|
105
|
+
};
|
|
106
|
+
XUtilsMetadataCommon.getXAssocToOneByAssocEntity = function (xEntity, assocEntityName) {
|
|
107
|
+
return XUtilsMetadataCommon.getXAssocByAssocEntity(xEntity, assocEntityName, ["many-to-one", "one-to-one"]);
|
|
108
|
+
};
|
|
109
|
+
XUtilsMetadataCommon.getXAssocToManyByAssocEntity = function (xEntity, assocEntityName) {
|
|
110
|
+
return XUtilsMetadataCommon.getXAssocByAssocEntity(xEntity, assocEntityName, ["one-to-many", "many-to-many"]);
|
|
111
|
+
};
|
|
112
|
+
XUtilsMetadataCommon.getXEntityForAssocToOne = function (xEntity, assocField) {
|
|
113
|
+
return XUtilsMetadataCommon.getXEntityForAssoc(XUtilsMetadataCommon.getXAssocToOne(xEntity, assocField));
|
|
114
|
+
};
|
|
115
|
+
XUtilsMetadataCommon.getXEntityForAssocToMany = function (xEntity, assocField) {
|
|
116
|
+
return XUtilsMetadataCommon.getXEntityForAssoc(XUtilsMetadataCommon.getXAssocToMany(xEntity, assocField));
|
|
117
|
+
};
|
|
118
|
+
XUtilsMetadataCommon.getXFieldList = function (xEntity) {
|
|
119
|
+
var e_1, _a;
|
|
120
|
+
var xFieldList = [];
|
|
121
|
+
try {
|
|
122
|
+
for (var _b = __values(Object.entries(xEntity.fieldMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
123
|
+
var _d = __read(_c.value, 2), key = _d[0], xField = _d[1];
|
|
124
|
+
// assoc fieldy sa nachadzaju aj v xEntity.fieldMap ako typ number (netusim preco), preto ich vyfiltrujeme
|
|
125
|
+
if (xEntity.assocMap[xField.name] === undefined) {
|
|
126
|
+
xFieldList.push(xField);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
131
|
+
finally {
|
|
132
|
+
try {
|
|
133
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
134
|
+
}
|
|
135
|
+
finally { if (e_1) throw e_1.error; }
|
|
136
|
+
}
|
|
137
|
+
return xFieldList;
|
|
138
|
+
};
|
|
139
|
+
XUtilsMetadataCommon.getXAssocList = function (xEntity, relationTypeList) {
|
|
140
|
+
var e_2, _a;
|
|
141
|
+
//const xAssocList: XAssoc[] = Array.from(xEntity.assocMap, (v: XAssoc, k: string) => v);
|
|
142
|
+
var xAssocList = [];
|
|
143
|
+
try {
|
|
144
|
+
for (var _b = __values(Object.entries(xEntity.assocMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
145
|
+
var _d = __read(_c.value, 2), key = _d[0], xAssoc = _d[1];
|
|
146
|
+
if (relationTypeList === undefined || relationTypeList.includes(xAssoc.relationType)) {
|
|
147
|
+
xAssocList.push(xAssoc);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
152
|
+
finally {
|
|
153
|
+
try {
|
|
154
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
155
|
+
}
|
|
156
|
+
finally { if (e_2) throw e_2.error; }
|
|
157
|
+
}
|
|
158
|
+
return xAssocList;
|
|
159
|
+
};
|
|
160
|
+
XUtilsMetadataCommon.getXAssoc = function (xEntity, assocField, relationTypeList) {
|
|
161
|
+
var xAssoc = XUtilsMetadataCommon.getXAssocBase(xEntity, assocField);
|
|
162
|
+
if (xAssoc === undefined) {
|
|
163
|
+
throw "Assoc ".concat(assocField, " was not found in entity = ").concat(xEntity.name);
|
|
164
|
+
}
|
|
165
|
+
// relationTypeList is optional and is only for check (not to get some unwanted type of assoc)
|
|
166
|
+
if (relationTypeList !== undefined && !relationTypeList.includes(xAssoc.relationType)) {
|
|
167
|
+
throw "Assoc ".concat(assocField, " in entity ").concat(xEntity.name, " is of type ").concat(xAssoc.relationType, " and required type is ").concat(JSON.stringify(relationTypeList));
|
|
168
|
+
}
|
|
169
|
+
return xAssoc;
|
|
170
|
+
};
|
|
171
|
+
XUtilsMetadataCommon.getXAssocByAssocEntity = function (xEntity, assocEntityName, relationTypeList) {
|
|
172
|
+
var e_3, _a;
|
|
173
|
+
var xAssocFound = undefined;
|
|
174
|
+
try {
|
|
175
|
+
for (var _b = __values(Object.entries(xEntity.assocMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
176
|
+
var _d = __read(_c.value, 2), key = _d[0], xAssoc = _d[1];
|
|
177
|
+
if (xAssoc.entityName === assocEntityName) {
|
|
178
|
+
if (xAssocFound === undefined) {
|
|
179
|
+
xAssocFound = xAssoc;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
throw "In entity ".concat(xEntity.name, " found more then 1 assoc for assocEntityName = ").concat(assocEntityName);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
188
|
+
finally {
|
|
189
|
+
try {
|
|
190
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
191
|
+
}
|
|
192
|
+
finally { if (e_3) throw e_3.error; }
|
|
193
|
+
}
|
|
194
|
+
if (xAssocFound === undefined) {
|
|
195
|
+
throw "Assoc for assocEntityName = ".concat(assocEntityName, " not found in entity ").concat(xEntity.name);
|
|
196
|
+
}
|
|
197
|
+
// relationTypeList is optional and is only for check (not to get some unwanted type of assoc)
|
|
198
|
+
if (relationTypeList !== undefined && !relationTypeList.includes(xAssocFound.relationType)) {
|
|
199
|
+
throw "Assoc for assocEntityName = ".concat(assocEntityName, " in entity ").concat(xEntity.name, " is of type ").concat(xAssocFound.relationType, " and required type is ").concat(JSON.stringify(relationTypeList));
|
|
200
|
+
}
|
|
201
|
+
return xAssocFound;
|
|
202
|
+
};
|
|
203
|
+
XUtilsMetadataCommon.getXEntityForAssoc = function (xAssoc) {
|
|
204
|
+
return XUtilsMetadataCommon.getXEntity(xAssoc.entityName);
|
|
205
|
+
};
|
|
206
|
+
return XUtilsMetadataCommon;
|
|
207
|
+
}());
|
|
208
|
+
exports.XUtilsMetadataCommon = XUtilsMetadataCommon;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michalrakus/x-react-web-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf lib",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@testing-library/react": "^14.0.0",
|
|
29
29
|
"@testing-library/user-event": "^14.4.3",
|
|
30
30
|
"@types/jest": "^29.5.0",
|
|
31
|
-
"@types/lodash": "^4.14.
|
|
31
|
+
"@types/lodash": "^4.14.202",
|
|
32
32
|
"@types/node": "^18.15.3",
|
|
33
33
|
"@types/react": "^18.0.28",
|
|
34
34
|
"@types/react-dom": "^18.0.11",
|