remult 0.14.2 → 0.14.5
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/assign.js +1 -5
- package/classType.js +1 -2
- package/graphql.js +84 -146
- package/index.d.ts +13 -0
- package/index.js +25 -55
- package/inputTypes.js +9 -16
- package/package.json +6 -1
- package/postgres/index.js +1 -4
- package/postgres/postgres-data-provider.js +165 -364
- package/postgres/postgresColumnSyntax.js +4 -8
- package/remult-express.js +6 -10
- package/remult-knex/index.js +300 -720
- package/remult-middleware.js +24 -30
- package/remult-mongo.js +172 -406
- package/server/JsonEntityFileStorage.js +10 -15
- package/server/expressBridge.js +383 -569
- package/server/index.js +4 -11
- package/server/register-actions-on-server.js +12 -38
- package/server/register-entities-on-server.js +9 -13
- package/src/__EntityValueProvider.js +1 -2
- package/src/__RowsOfDataForTesting.js +1 -2
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +72 -190
- package/src/backend-tests/my-test.backend-spec.js +45 -114
- package/src/column-interfaces.js +2 -6
- package/src/column.js +71 -113
- package/src/context.js +174 -330
- package/src/data-api.js +162 -326
- package/src/data-interfaces.js +7 -11
- package/src/data-providers/array-entity-data-provider.js +171 -286
- package/src/data-providers/in-memory-database.js +12 -27
- package/src/data-providers/json-data-provider.js +41 -77
- package/src/data-providers/rest-data-provider.js +102 -189
- package/src/data-providers/sql-database.js +223 -403
- package/src/data-providers/web-sql-data-provider.js +78 -139
- package/src/entity.js +1 -2
- package/src/filter/filter-consumer-bridge-to-sql-request.js +106 -248
- package/src/filter/filter-consumer-bridge-to-url-builder.js +1 -2
- package/src/filter/filter-interfaces.js +277 -440
- package/src/id-entity.js +8 -17
- package/src/remult3/RepositoryImplementation.js +1191 -2367
- package/src/remult3/index.js +2 -5
- package/src/remult3/remult3.js +1 -2
- package/src/server-action.js +294 -528
- package/src/shared-tests/db-tests-setup.js +49 -153
- package/src/shared-tests/db-tests.db-tests.js +660 -1566
- package/src/shared-tests/deleteAll.js +3 -20
- package/src/shared-tests/entityWithValidations.js +52 -79
- package/src/shared-tests/index.js +4 -6
- package/src/shared-tests/test-custom-id-column.spec.js +37 -85
- package/src/shared-tests/test-special-value.spec.js +64 -104
- package/src/shared-tests/test-update-with-null.spec.js +28 -49
- package/src/sort.js +38 -95
- package/src/sql-command.js +1 -2
- package/src/tests/Done.js +7 -13
- package/src/tests/TestDataApiResponse.js +15 -22
- package/src/tests/c.js +21 -27
- package/src/tests/createData.js +20 -48
- package/src/tests/d.js +19 -27
- package/src/tests/dWithPrefilter.js +31 -44
- package/src/tests/entityForCustomFilter.js +42 -66
- package/src/tests/entityWithValidationsOnColumn.js +21 -29
- package/src/tests/frontend-database-tests-setup.spec.js +35 -98
- package/src/tests/h.js +35 -44
- package/src/tests/remult-3-entities.js +71 -80
- package/src/tests/tasks.js +23 -29
- package/src/tests/testHelper.spec.js +170 -322
- package/src/tests/testModel/models.js +25 -33
- package/src/validators.js +32 -59
- package/urlBuilder.js +8 -14
- package/valueConverters.js +161 -160
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var valueConverters_1 = require("../../valueConverters");
|
|
11
|
-
var filter_interfaces_2 = require("../filter/filter-interfaces");
|
|
12
|
-
var assign_1 = require("../../assign");
|
|
13
|
-
var classValidatorValidate = undefined;
|
|
1
|
+
import { CompoundIdField, LookupColumn, makeTitle } from '../column';
|
|
2
|
+
import { allEntities, Remult, isBackend, queryConfig as queryConfig, setControllerSettings } from "../context";
|
|
3
|
+
import { entityFilterToJson, Filter } from "../filter/filter-interfaces";
|
|
4
|
+
import { Sort } from "../sort";
|
|
5
|
+
import { v4 as uuid } from 'uuid';
|
|
6
|
+
import { ValueConverters } from "../../valueConverters";
|
|
7
|
+
import { filterHelper } from "../filter/filter-interfaces";
|
|
8
|
+
import { assign } from "../../assign";
|
|
9
|
+
let classValidatorValidate = undefined;
|
|
14
10
|
// import("class-validator".toString())
|
|
15
11
|
// .then((v) => {
|
|
16
12
|
// classValidatorValidate = (item, ref) => {
|
|
@@ -28,8 +24,8 @@ var classValidatorValidate = undefined;
|
|
|
28
24
|
// })
|
|
29
25
|
// .catch(() => {
|
|
30
26
|
// });
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
export class RepositoryImplementation {
|
|
28
|
+
constructor(entity, remult, dataProvider) {
|
|
33
29
|
this.entity = entity;
|
|
34
30
|
this.remult = remult;
|
|
35
31
|
this.dataProvider = dataProvider;
|
|
@@ -37,627 +33,353 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
37
33
|
this.cache = new Map();
|
|
38
34
|
this._info = createOldEntity(entity, remult);
|
|
39
35
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
for (equalToColumn_1 = (e_3 = void 0, tslib_1.__values(equalToColumn)), equalToColumn_1_1 = equalToColumn_1.next(); !equalToColumn_1_1.done; equalToColumn_1_1 = equalToColumn_1.next()) {
|
|
77
|
-
c = equalToColumn_1_1.value;
|
|
78
|
-
f[c.key] = values.get(c.key);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
82
|
-
finally {
|
|
83
|
-
try {
|
|
84
|
-
if (equalToColumn_1_1 && !equalToColumn_1_1.done && (_g = equalToColumn_1.return)) _g.call(equalToColumn_1);
|
|
85
|
-
}
|
|
86
|
-
finally { if (e_3) throw e_3.error; }
|
|
87
|
-
}
|
|
88
|
-
equalToColumn.push(s.field);
|
|
89
|
-
if (s.isDescending) {
|
|
90
|
-
f[s.field.key] = { $lt: values.get(s.field.key) };
|
|
91
|
-
}
|
|
92
|
-
else
|
|
93
|
-
f[s.field.key] = { $gt: values.get(s.field.key) };
|
|
94
|
-
r.$or.push(f);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
98
|
-
finally {
|
|
99
|
-
try {
|
|
100
|
-
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
101
|
-
}
|
|
102
|
-
finally { if (e_2) throw e_2.error; }
|
|
103
|
-
}
|
|
104
|
-
return [2 /*return*/, r];
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
Object.defineProperty(RepositoryImplementation.prototype, "edp", {
|
|
109
|
-
get: function () {
|
|
110
|
-
return this.__edp ? this.__edp : this.__edp = this.dataProvider.getEntityDataProvider(this.metadata);
|
|
111
|
-
},
|
|
112
|
-
enumerable: false,
|
|
113
|
-
configurable: true
|
|
114
|
-
});
|
|
115
|
-
RepositoryImplementation.prototype.getCachedById = function (id) {
|
|
36
|
+
async createAfterFilter(orderBy, lastRow) {
|
|
37
|
+
let values = new Map();
|
|
38
|
+
for (const s of Sort.translateOrderByToSort(this.metadata, orderBy).Segments) {
|
|
39
|
+
let existingVal = lastRow[s.field.key];
|
|
40
|
+
// if (typeof existingVal !== "string" && typeof existingVal !== "number") {
|
|
41
|
+
// }
|
|
42
|
+
// else {
|
|
43
|
+
// let ei = getEntitySettings(s.field.valueType, false);
|
|
44
|
+
// if (ei) {
|
|
45
|
+
// existingVal = await this.remult.repo(s.field.valueType).findId(existingVal);
|
|
46
|
+
// }
|
|
47
|
+
// }
|
|
48
|
+
values.set(s.field.key, existingVal);
|
|
49
|
+
}
|
|
50
|
+
let r = { $or: [] };
|
|
51
|
+
let equalToColumn = [];
|
|
52
|
+
for (const s of Sort.translateOrderByToSort(this.metadata, orderBy).Segments) {
|
|
53
|
+
let ff = new filterHelper(s.field);
|
|
54
|
+
let f = {};
|
|
55
|
+
for (const c of equalToColumn) {
|
|
56
|
+
f[c.key] = values.get(c.key);
|
|
57
|
+
}
|
|
58
|
+
equalToColumn.push(s.field);
|
|
59
|
+
if (s.isDescending) {
|
|
60
|
+
f[s.field.key] = { $lt: values.get(s.field.key) };
|
|
61
|
+
}
|
|
62
|
+
else
|
|
63
|
+
f[s.field.key] = { $gt: values.get(s.field.key) };
|
|
64
|
+
r.$or.push(f);
|
|
65
|
+
}
|
|
66
|
+
return r;
|
|
67
|
+
}
|
|
68
|
+
get edp() {
|
|
69
|
+
return this.__edp ? this.__edp : this.__edp = this.dataProvider.getEntityDataProvider(this.metadata);
|
|
70
|
+
}
|
|
71
|
+
getCachedById(id) {
|
|
116
72
|
id = id + '';
|
|
117
73
|
this.getCachedByIdAsync(id);
|
|
118
|
-
|
|
74
|
+
let r = this.idCache.get(id);
|
|
119
75
|
if (r instanceof Promise)
|
|
120
76
|
return undefined;
|
|
121
77
|
return r;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
row = this.findId(id).then(function (row) {
|
|
141
|
-
if (row === undefined) {
|
|
142
|
-
r = null;
|
|
143
|
-
}
|
|
144
|
-
else
|
|
145
|
-
r = row;
|
|
146
|
-
_this.idCache.set(id, r);
|
|
147
|
-
return r;
|
|
148
|
-
});
|
|
149
|
-
this.idCache.set(id, row);
|
|
150
|
-
return [4 /*yield*/, row];
|
|
151
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
152
|
-
}
|
|
153
|
-
});
|
|
78
|
+
}
|
|
79
|
+
async getCachedByIdAsync(id) {
|
|
80
|
+
id = id + '';
|
|
81
|
+
let r = this.idCache.get(id);
|
|
82
|
+
if (r instanceof Promise)
|
|
83
|
+
return await r;
|
|
84
|
+
if (this.idCache.has(id)) {
|
|
85
|
+
return r;
|
|
86
|
+
}
|
|
87
|
+
this.idCache.set(id, undefined);
|
|
88
|
+
let row = this.findId(id).then(row => {
|
|
89
|
+
if (row === undefined) {
|
|
90
|
+
r = null;
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
r = row;
|
|
94
|
+
this.idCache.set(id, r);
|
|
95
|
+
return r;
|
|
154
96
|
});
|
|
155
|
-
|
|
156
|
-
|
|
97
|
+
this.idCache.set(id, row);
|
|
98
|
+
return await row;
|
|
99
|
+
}
|
|
100
|
+
addToCache(item) {
|
|
157
101
|
if (item)
|
|
158
102
|
this.idCache.set(this.getEntityRef(item).getId() + '', item);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
get: function () { return this._info; },
|
|
162
|
-
enumerable: false,
|
|
163
|
-
configurable: true
|
|
164
|
-
});
|
|
103
|
+
}
|
|
104
|
+
get metadata() { return this._info; }
|
|
165
105
|
;
|
|
166
|
-
|
|
167
|
-
var _this = this;
|
|
106
|
+
addEventListener(listener) {
|
|
168
107
|
if (!this.listeners)
|
|
169
108
|
this.listeners = [];
|
|
170
109
|
this.listeners.push(listener);
|
|
171
|
-
return
|
|
172
|
-
|
|
110
|
+
return () => {
|
|
111
|
+
this.listeners.splice(this.listeners.indexOf(listener), 1);
|
|
173
112
|
};
|
|
174
|
-
}
|
|
175
|
-
|
|
113
|
+
}
|
|
114
|
+
query(options) {
|
|
176
115
|
return new QueryResultImpl(options, this);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
116
|
+
}
|
|
117
|
+
getEntityRef(entity) {
|
|
118
|
+
let x = entity[entityMember];
|
|
180
119
|
if (!x) {
|
|
181
120
|
x = new rowHelperImplementation(this._info, entity, this, this.edp, this.remult, true);
|
|
182
121
|
Object.defineProperty(entity, entityMember, {
|
|
183
|
-
get:
|
|
122
|
+
get: () => x
|
|
184
123
|
});
|
|
185
124
|
x.saveOriginalData();
|
|
186
125
|
}
|
|
187
126
|
return x;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
RepositoryImplementation.prototype.insert = function (entity) {
|
|
202
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
203
|
-
var r, entity_1, entity_1_1, item, _a, _b, e_4_1, ref;
|
|
204
|
-
var e_4, _c;
|
|
205
|
-
return tslib_1.__generator(this, function (_d) {
|
|
206
|
-
switch (_d.label) {
|
|
207
|
-
case 0:
|
|
208
|
-
if (!Array.isArray(entity)) return [3 /*break*/, 9];
|
|
209
|
-
r = [];
|
|
210
|
-
_d.label = 1;
|
|
211
|
-
case 1:
|
|
212
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
213
|
-
entity_1 = tslib_1.__values(entity), entity_1_1 = entity_1.next();
|
|
214
|
-
_d.label = 2;
|
|
215
|
-
case 2:
|
|
216
|
-
if (!!entity_1_1.done) return [3 /*break*/, 5];
|
|
217
|
-
item = entity_1_1.value;
|
|
218
|
-
_b = (_a = r).push;
|
|
219
|
-
return [4 /*yield*/, this.insert(item)];
|
|
220
|
-
case 3:
|
|
221
|
-
_b.apply(_a, [_d.sent()]);
|
|
222
|
-
_d.label = 4;
|
|
223
|
-
case 4:
|
|
224
|
-
entity_1_1 = entity_1.next();
|
|
225
|
-
return [3 /*break*/, 2];
|
|
226
|
-
case 5: return [3 /*break*/, 8];
|
|
227
|
-
case 6:
|
|
228
|
-
e_4_1 = _d.sent();
|
|
229
|
-
e_4 = { error: e_4_1 };
|
|
230
|
-
return [3 /*break*/, 8];
|
|
231
|
-
case 7:
|
|
232
|
-
try {
|
|
233
|
-
if (entity_1_1 && !entity_1_1.done && (_c = entity_1.return)) _c.call(entity_1);
|
|
234
|
-
}
|
|
235
|
-
finally { if (e_4) throw e_4.error; }
|
|
236
|
-
return [7 /*endfinally*/];
|
|
237
|
-
case 8: return [2 /*return*/, r];
|
|
238
|
-
case 9:
|
|
239
|
-
ref = getEntityRef(entity, false);
|
|
240
|
-
if (!ref) return [3 /*break*/, 11];
|
|
241
|
-
if (!ref.isNew())
|
|
242
|
-
throw "Item is not new";
|
|
243
|
-
return [4 /*yield*/, ref.save()];
|
|
244
|
-
case 10: return [2 /*return*/, _d.sent()];
|
|
245
|
-
case 11: return [4 /*yield*/, this.getEntityRef(this.create(entity)).save()];
|
|
246
|
-
case 12: return [2 /*return*/, _d.sent()];
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
RepositoryImplementation.prototype.update = function (id, entity) {
|
|
252
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var ref;
|
|
254
|
-
return tslib_1.__generator(this, function (_a) {
|
|
255
|
-
switch (_a.label) {
|
|
256
|
-
case 0:
|
|
257
|
-
ref = this.getRefForExistingRow(entity, id);
|
|
258
|
-
return [4 /*yield*/, ref.save()];
|
|
259
|
-
case 1: return [2 /*return*/, (_a.sent())];
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
RepositoryImplementation.prototype.getRefForExistingRow = function (entity, id) {
|
|
265
|
-
var e_5, _a;
|
|
266
|
-
var ref = getEntityRef(entity, false);
|
|
267
|
-
if (!ref) {
|
|
268
|
-
var instance = new this.entity(this.remult);
|
|
269
|
-
try {
|
|
270
|
-
for (var _b = tslib_1.__values(this.fieldsOf(entity)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
271
|
-
var field = _c.value;
|
|
272
|
-
instance[field.key] = entity[field.key];
|
|
273
|
-
}
|
|
127
|
+
}
|
|
128
|
+
async delete(item) {
|
|
129
|
+
if (typeof item === "string" || typeof item === "number")
|
|
130
|
+
return this.edp.delete(item);
|
|
131
|
+
else {
|
|
132
|
+
return this.getRefForExistingRow(item, undefined).delete();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async insert(entity) {
|
|
136
|
+
if (Array.isArray(entity)) {
|
|
137
|
+
let r = [];
|
|
138
|
+
for (const item of entity) {
|
|
139
|
+
r.push(await this.insert(item));
|
|
274
140
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
141
|
+
return r;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
let ref = getEntityRef(entity, false);
|
|
145
|
+
if (ref) {
|
|
146
|
+
if (!ref.isNew())
|
|
147
|
+
throw "Item is not new";
|
|
148
|
+
return await ref.save();
|
|
281
149
|
}
|
|
282
|
-
|
|
150
|
+
else {
|
|
151
|
+
return await this.getEntityRef(this.create(entity)).save();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async update(id, entity) {
|
|
156
|
+
let ref = this.getRefForExistingRow(entity, id);
|
|
157
|
+
return (await ref.save());
|
|
158
|
+
}
|
|
159
|
+
getRefForExistingRow(entity, id) {
|
|
160
|
+
let ref = getEntityRef(entity, false);
|
|
161
|
+
if (!ref) {
|
|
162
|
+
const instance = new this.entity(this.remult);
|
|
163
|
+
for (const field of this.fieldsOf(entity)) {
|
|
164
|
+
instance[field.key] = entity[field.key];
|
|
165
|
+
}
|
|
166
|
+
let row = new rowHelperImplementation(this._info, instance, this, this.edp, this.remult, false);
|
|
283
167
|
if (id)
|
|
284
|
-
|
|
168
|
+
row.id = id;
|
|
285
169
|
else
|
|
286
|
-
|
|
287
|
-
ref =
|
|
170
|
+
row.id = row.getId();
|
|
171
|
+
ref = row;
|
|
288
172
|
Object.defineProperty(instance, entityMember, {
|
|
289
|
-
get:
|
|
173
|
+
get: () => row
|
|
290
174
|
});
|
|
291
175
|
}
|
|
292
176
|
return ref;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
ref = getEntityRef(entity, false);
|
|
305
|
-
if (!ref) return [3 /*break*/, 3];
|
|
306
|
-
return [4 /*yield*/, ref.save()];
|
|
307
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
308
|
-
case 3:
|
|
309
|
-
if (!(entity instanceof EntityBase)) return [3 /*break*/, 5];
|
|
310
|
-
return [4 /*yield*/, this.getEntityRef(entity).save()];
|
|
311
|
-
case 4: return [2 /*return*/, _a.sent()];
|
|
312
|
-
case 5:
|
|
313
|
-
id = entity[this.metadata.idMetadata.field.key];
|
|
314
|
-
if (id === undefined)
|
|
315
|
-
return [2 /*return*/, this.insert(entity)];
|
|
316
|
-
return [2 /*return*/, this.update(id, entity)];
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
};
|
|
321
|
-
RepositoryImplementation.prototype.find = function (options) {
|
|
322
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
323
|
-
function loadManyToOne(repo, toLoad) {
|
|
324
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
325
|
-
var rows, rows_1, rows_1_1, r;
|
|
326
|
-
var _a, e_8, _b;
|
|
327
|
-
return tslib_1.__generator(this, function (_c) {
|
|
328
|
-
switch (_c.label) {
|
|
329
|
-
case 0: return [4 /*yield*/, repo.find({ where: (_a = repo.metadata.idMetadata).getIdFilter.apply(_a, tslib_1.__spread(toLoad)) })];
|
|
330
|
-
case 1:
|
|
331
|
-
rows = _c.sent();
|
|
332
|
-
try {
|
|
333
|
-
for (rows_1 = tslib_1.__values(rows), rows_1_1 = rows_1.next(); !rows_1_1.done; rows_1_1 = rows_1.next()) {
|
|
334
|
-
r = rows_1_1.value;
|
|
335
|
-
repo.addToCache(r);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
339
|
-
finally {
|
|
340
|
-
try {
|
|
341
|
-
if (rows_1_1 && !rows_1_1.done && (_b = rows_1.return)) _b.call(rows_1);
|
|
342
|
-
}
|
|
343
|
-
finally { if (e_8) throw e_8.error; }
|
|
344
|
-
}
|
|
345
|
-
return [2 /*return*/];
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
});
|
|
177
|
+
}
|
|
178
|
+
async save(entity) {
|
|
179
|
+
if (Array.isArray(entity)) {
|
|
180
|
+
return Promise.all(entity.map(x => this.save(x)));
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
let ref = getEntityRef(entity, false);
|
|
184
|
+
if (ref)
|
|
185
|
+
return await ref.save();
|
|
186
|
+
else if (entity instanceof EntityBase) {
|
|
187
|
+
return await this.getEntityRef(entity).save();
|
|
349
188
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
if (!
|
|
387
|
-
|
|
388
|
-
if (loadFields !== undefined)
|
|
389
|
-
load = loadFields.includes(col);
|
|
390
|
-
if (!load) return [3 /*break*/, 6];
|
|
391
|
-
repo = this.remult.repo(col.valueType);
|
|
392
|
-
toLoad = [];
|
|
393
|
-
try {
|
|
394
|
-
for (rawRows_1 = (e_7 = void 0, tslib_1.__values(rawRows)), rawRows_1_1 = rawRows_1.next(); !rawRows_1_1.done; rawRows_1_1 = rawRows_1.next()) {
|
|
395
|
-
r = rawRows_1_1.value;
|
|
396
|
-
val = r[col.key];
|
|
397
|
-
if (val !== undefined && val !== null && !toLoad.includes(val) && !repo.idCache.has(val)) {
|
|
398
|
-
toLoad.push(val);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
403
|
-
finally {
|
|
404
|
-
try {
|
|
405
|
-
if (rawRows_1_1 && !rawRows_1_1.done && (_e = rawRows_1.return)) _e.call(rawRows_1);
|
|
406
|
-
}
|
|
407
|
-
finally { if (e_7) throw e_7.error; }
|
|
408
|
-
}
|
|
409
|
-
if (!(toLoad.length > 0)) return [3 /*break*/, 6];
|
|
410
|
-
return [4 /*yield*/, loadManyToOne(repo, toLoad)];
|
|
411
|
-
case 5:
|
|
412
|
-
_f.sent();
|
|
413
|
-
_f.label = 6;
|
|
414
|
-
case 6:
|
|
415
|
-
_c = _b.next();
|
|
416
|
-
return [3 /*break*/, 4];
|
|
417
|
-
case 7: return [3 /*break*/, 10];
|
|
418
|
-
case 8:
|
|
419
|
-
e_6_1 = _f.sent();
|
|
420
|
-
e_6 = { error: e_6_1 };
|
|
421
|
-
return [3 /*break*/, 10];
|
|
422
|
-
case 9:
|
|
423
|
-
try {
|
|
424
|
-
if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
|
|
189
|
+
else {
|
|
190
|
+
let id = entity[this.metadata.idMetadata.field.key];
|
|
191
|
+
if (id === undefined)
|
|
192
|
+
return this.insert(entity);
|
|
193
|
+
return this.update(id, entity);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async find(options) {
|
|
198
|
+
Remult.onFind(this._info, options);
|
|
199
|
+
let opt = {};
|
|
200
|
+
if (!options)
|
|
201
|
+
options = {};
|
|
202
|
+
opt = {};
|
|
203
|
+
if (!options.orderBy || Object.keys(options.orderBy).length === 0) {
|
|
204
|
+
options.orderBy = this._info.entityInfo.defaultOrderBy;
|
|
205
|
+
}
|
|
206
|
+
opt.where = await this.translateWhereToFilter(options.where);
|
|
207
|
+
opt.orderBy = Sort.translateOrderByToSort(this.metadata, options.orderBy);
|
|
208
|
+
opt.limit = options.limit;
|
|
209
|
+
opt.page = options.page;
|
|
210
|
+
let rawRows = await this.edp.find(opt);
|
|
211
|
+
let loadFields = undefined;
|
|
212
|
+
if (options.load)
|
|
213
|
+
loadFields = options.load(this.metadata.fields);
|
|
214
|
+
for (const col of this.metadata.fields) {
|
|
215
|
+
let ei = getEntitySettings(col.valueType, false);
|
|
216
|
+
if (ei) {
|
|
217
|
+
let load = !col.options.lazy;
|
|
218
|
+
if (loadFields !== undefined)
|
|
219
|
+
load = loadFields.includes(col);
|
|
220
|
+
if (load) {
|
|
221
|
+
let repo = this.remult.repo(col.valueType);
|
|
222
|
+
let toLoad = [];
|
|
223
|
+
for (const r of rawRows) {
|
|
224
|
+
let val = r[col.key];
|
|
225
|
+
if (val !== undefined && val !== null && !toLoad.includes(val) && !repo.idCache.has(val)) {
|
|
226
|
+
toLoad.push(val);
|
|
425
227
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
case 0: return [4 /*yield*/, this.mapRawDataToResult(r, loadFields)];
|
|
431
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
432
|
-
}
|
|
433
|
-
}); }); }))];
|
|
434
|
-
case 11:
|
|
435
|
-
result = _f.sent();
|
|
436
|
-
return [2 /*return*/, result];
|
|
228
|
+
}
|
|
229
|
+
if (toLoad.length > 0) {
|
|
230
|
+
await loadManyToOne(repo, toLoad);
|
|
231
|
+
}
|
|
437
232
|
}
|
|
438
|
-
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
let result = await Promise.all(rawRows.map(async (r) => await this.mapRawDataToResult(r, loadFields)));
|
|
236
|
+
return result;
|
|
237
|
+
async function loadManyToOne(repo, toLoad) {
|
|
238
|
+
let rows = await repo.find({ where: repo.metadata.idMetadata.getIdFilter(...toLoad) });
|
|
239
|
+
for (const r of rows) {
|
|
240
|
+
repo.addToCache(r);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async mapRawDataToResult(r, loadFields) {
|
|
245
|
+
if (!r)
|
|
246
|
+
return undefined;
|
|
247
|
+
let x = new this.entity(this.remult);
|
|
248
|
+
let helper = new rowHelperImplementation(this._info, x, this, this.edp, this.remult, false);
|
|
249
|
+
Object.defineProperty(x, entityMember, {
|
|
250
|
+
get: () => helper
|
|
439
251
|
});
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
return
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
252
|
+
await helper.loadDataFrom(r, loadFields);
|
|
253
|
+
helper.saveOriginalData();
|
|
254
|
+
return x;
|
|
255
|
+
}
|
|
256
|
+
async count(where) {
|
|
257
|
+
return this.edp.count(await this.translateWhereToFilter(where));
|
|
258
|
+
}
|
|
259
|
+
async findFirst(where, options) {
|
|
260
|
+
if (!options)
|
|
261
|
+
options = {};
|
|
262
|
+
if (where) {
|
|
263
|
+
if (options.where) {
|
|
264
|
+
let w = options.where;
|
|
265
|
+
options.where = {
|
|
266
|
+
$and: [
|
|
267
|
+
w,
|
|
268
|
+
where
|
|
269
|
+
]
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
else
|
|
273
|
+
options.where = where;
|
|
274
|
+
}
|
|
275
|
+
let r;
|
|
276
|
+
let cacheInfo;
|
|
277
|
+
if (options.useCache) {
|
|
278
|
+
let f = await entityFilterToJson(this.metadata, options.where);
|
|
279
|
+
let key = JSON.stringify(f);
|
|
280
|
+
cacheInfo = this.cache.get(key);
|
|
281
|
+
if (cacheInfo !== undefined) {
|
|
282
|
+
if (cacheInfo.value && this.getEntityRef(cacheInfo.value).wasDeleted()) {
|
|
283
|
+
cacheInfo = undefined;
|
|
284
|
+
this.cache.delete(key);
|
|
459
285
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
286
|
+
else
|
|
287
|
+
return this.cache.get(key).promise;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
cacheInfo = {
|
|
291
|
+
value: undefined,
|
|
292
|
+
promise: undefined
|
|
293
|
+
};
|
|
294
|
+
this.cache.set(key, cacheInfo);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
r = this.find({ ...options, limit: 1 }).then(async (items) => {
|
|
298
|
+
let r = undefined;
|
|
299
|
+
if (items.length > 0)
|
|
300
|
+
r = items[0];
|
|
301
|
+
if (!r && options.createIfNotFound) {
|
|
302
|
+
r = this.create();
|
|
303
|
+
if (options.where) {
|
|
304
|
+
await __updateEntityBasedOnWhere(this.metadata, options.where, r);
|
|
472
305
|
}
|
|
473
|
-
}
|
|
306
|
+
}
|
|
307
|
+
return r;
|
|
474
308
|
});
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
var _this = this;
|
|
480
|
-
return tslib_1.__generator(this, function (_a) {
|
|
481
|
-
switch (_a.label) {
|
|
482
|
-
case 0:
|
|
483
|
-
if (!options)
|
|
484
|
-
options = {};
|
|
485
|
-
if (where) {
|
|
486
|
-
if (options.where) {
|
|
487
|
-
w = options.where;
|
|
488
|
-
options.where = {
|
|
489
|
-
$and: [
|
|
490
|
-
w,
|
|
491
|
-
where
|
|
492
|
-
]
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
else
|
|
496
|
-
options.where = where;
|
|
497
|
-
}
|
|
498
|
-
if (!options.useCache) return [3 /*break*/, 2];
|
|
499
|
-
return [4 /*yield*/, filter_interfaces_1.entityFilterToJson(this.metadata, options.where)];
|
|
500
|
-
case 1:
|
|
501
|
-
f = _a.sent();
|
|
502
|
-
key = JSON.stringify(f);
|
|
503
|
-
cacheInfo = this.cache.get(key);
|
|
504
|
-
if (cacheInfo !== undefined) {
|
|
505
|
-
if (cacheInfo.value && this.getEntityRef(cacheInfo.value).wasDeleted()) {
|
|
506
|
-
cacheInfo = undefined;
|
|
507
|
-
this.cache.delete(key);
|
|
508
|
-
}
|
|
509
|
-
else
|
|
510
|
-
return [2 /*return*/, this.cache.get(key).promise];
|
|
511
|
-
}
|
|
512
|
-
else {
|
|
513
|
-
cacheInfo = {
|
|
514
|
-
value: undefined,
|
|
515
|
-
promise: undefined
|
|
516
|
-
};
|
|
517
|
-
this.cache.set(key, cacheInfo);
|
|
518
|
-
}
|
|
519
|
-
_a.label = 2;
|
|
520
|
-
case 2:
|
|
521
|
-
r = this.find(tslib_1.__assign(tslib_1.__assign({}, options), { limit: 1 })).then(function (items) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
522
|
-
var r;
|
|
523
|
-
return tslib_1.__generator(this, function (_a) {
|
|
524
|
-
switch (_a.label) {
|
|
525
|
-
case 0:
|
|
526
|
-
r = undefined;
|
|
527
|
-
if (items.length > 0)
|
|
528
|
-
r = items[0];
|
|
529
|
-
if (!(!r && options.createIfNotFound)) return [3 /*break*/, 2];
|
|
530
|
-
r = this.create();
|
|
531
|
-
if (!options.where) return [3 /*break*/, 2];
|
|
532
|
-
return [4 /*yield*/, __updateEntityBasedOnWhere(this.metadata, options.where, r)];
|
|
533
|
-
case 1:
|
|
534
|
-
_a.sent();
|
|
535
|
-
_a.label = 2;
|
|
536
|
-
case 2: return [2 /*return*/, r];
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
}); });
|
|
540
|
-
if (cacheInfo) {
|
|
541
|
-
cacheInfo.promise = r = r.then(function (r) {
|
|
542
|
-
cacheInfo.value = r;
|
|
543
|
-
return r;
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
return [2 /*return*/, r];
|
|
547
|
-
}
|
|
309
|
+
if (cacheInfo) {
|
|
310
|
+
cacheInfo.promise = r = r.then(r => {
|
|
311
|
+
cacheInfo.value = r;
|
|
312
|
+
return r;
|
|
548
313
|
});
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
314
|
+
}
|
|
315
|
+
return r;
|
|
316
|
+
}
|
|
317
|
+
fieldsOf(item) {
|
|
318
|
+
let keys = Object.keys(item);
|
|
319
|
+
return this.metadata.fields.toArray().filter(x => keys.includes(x.key));
|
|
320
|
+
}
|
|
321
|
+
create(item) {
|
|
322
|
+
let r = new this.entity(this.remult);
|
|
558
323
|
if (item)
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
var field = _c.value;
|
|
562
|
-
r[field.key] = item[field.key];
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
566
|
-
finally {
|
|
567
|
-
try {
|
|
568
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
569
|
-
}
|
|
570
|
-
finally { if (e_9) throw e_9.error; }
|
|
324
|
+
for (const field of this.fieldsOf(item)) {
|
|
325
|
+
r[field.key] = item[field.key];
|
|
571
326
|
}
|
|
572
|
-
|
|
327
|
+
let z = this.getEntityRef(r);
|
|
573
328
|
return r;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
finally {
|
|
593
|
-
try {
|
|
594
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
595
|
-
}
|
|
596
|
-
finally { if (e_10) throw e_10.error; }
|
|
597
|
-
}
|
|
598
|
-
if (!newRow) return [3 /*break*/, 2];
|
|
599
|
-
r = this.create();
|
|
600
|
-
helper = this.getEntityRef(r);
|
|
601
|
-
return [4 /*yield*/, helper.loadDataFrom(obj)];
|
|
602
|
-
case 1:
|
|
603
|
-
_d.sent();
|
|
604
|
-
return [2 /*return*/, r];
|
|
605
|
-
case 2: return [2 /*return*/, this.mapRawDataToResult(obj, undefined)];
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
};
|
|
610
|
-
RepositoryImplementation.prototype.findId = function (id, options) {
|
|
329
|
+
}
|
|
330
|
+
async fromJson(json, newRow) {
|
|
331
|
+
let obj = {};
|
|
332
|
+
for (const col of this.fieldsOf(json)) {
|
|
333
|
+
if (json[col.key] !== undefined) {
|
|
334
|
+
obj[col.key] = col.valueConverter.fromJson(json[col.key]);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (newRow) {
|
|
338
|
+
let r = this.create();
|
|
339
|
+
let helper = this.getEntityRef(r);
|
|
340
|
+
await helper.loadDataFrom(obj);
|
|
341
|
+
return r;
|
|
342
|
+
}
|
|
343
|
+
else
|
|
344
|
+
return this.mapRawDataToResult(obj, undefined);
|
|
345
|
+
}
|
|
346
|
+
findId(id, options) {
|
|
611
347
|
if (id === null || id === undefined)
|
|
612
348
|
return null;
|
|
613
349
|
if (typeof id !== "string" && typeof id !== "number")
|
|
614
350
|
throw new Error("id can be either number or string, but got: " + typeof (id));
|
|
615
|
-
return this.findFirst({},
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
var z, _a, r;
|
|
620
|
-
var _b;
|
|
621
|
-
return tslib_1.__generator(this, function (_c) {
|
|
622
|
-
switch (_c.label) {
|
|
623
|
-
case 0:
|
|
624
|
-
if (!(this.metadata.options.backendPrefilter && context_1.isBackend())) return [3 /*break*/, 2];
|
|
625
|
-
z = where;
|
|
626
|
-
_b = {};
|
|
627
|
-
_a = [z];
|
|
628
|
-
return [4 /*yield*/, filter_interfaces_1.Filter.resolve(this.metadata.options.backendPrefilter)];
|
|
629
|
-
case 1:
|
|
630
|
-
where = (_b.$and = _a.concat([
|
|
631
|
-
_c.sent()
|
|
632
|
-
]),
|
|
633
|
-
_b);
|
|
634
|
-
_c.label = 2;
|
|
635
|
-
case 2: return [4 /*yield*/, filter_interfaces_1.Filter.fromEntityFilter(this.metadata, where)];
|
|
636
|
-
case 3:
|
|
637
|
-
r = _c.sent();
|
|
638
|
-
if (!(r && !this.dataProvider.supportsCustomFilter)) return [3 /*break*/, 5];
|
|
639
|
-
return [4 /*yield*/, filter_interfaces_1.Filter.translateCustomWhere(r, this.metadata, this.remult)];
|
|
640
|
-
case 4:
|
|
641
|
-
r = _c.sent();
|
|
642
|
-
_c.label = 5;
|
|
643
|
-
case 5: return [2 /*return*/, r];
|
|
644
|
-
}
|
|
645
|
-
});
|
|
351
|
+
return this.findFirst({}, {
|
|
352
|
+
useCache: true,
|
|
353
|
+
...options,
|
|
354
|
+
where: this.metadata.idMetadata.getIdFilter(id),
|
|
646
355
|
});
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
356
|
+
}
|
|
357
|
+
async translateWhereToFilter(where) {
|
|
358
|
+
if (this.metadata.options.backendPrefilter && isBackend()) {
|
|
359
|
+
let z = where;
|
|
360
|
+
where = {
|
|
361
|
+
$and: [
|
|
362
|
+
z, await Filter.resolve(this.metadata.options.backendPrefilter)
|
|
363
|
+
]
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
let r = await Filter.fromEntityFilter(this.metadata, where);
|
|
367
|
+
if (r && !this.dataProvider.supportsCustomFilter) {
|
|
368
|
+
r = await Filter.translateCustomWhere(r, this.metadata, this.remult);
|
|
369
|
+
}
|
|
370
|
+
return r;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
export function __updateEntityBasedOnWhere(entityDefs, where, r) {
|
|
374
|
+
let w = Filter.fromEntityFilter(entityDefs, where);
|
|
375
|
+
const emptyFunction = () => { };
|
|
654
376
|
if (w) {
|
|
655
377
|
w.__applyToConsumer({
|
|
656
378
|
custom: emptyFunction,
|
|
657
379
|
databaseCustom: emptyFunction,
|
|
658
380
|
containsCaseInsensitive: emptyFunction,
|
|
659
381
|
isDifferentFrom: emptyFunction,
|
|
660
|
-
isEqualTo:
|
|
382
|
+
isEqualTo: (col, val) => {
|
|
661
383
|
r[col.key] = val;
|
|
662
384
|
},
|
|
663
385
|
isGreaterOrEqualTo: emptyFunction,
|
|
@@ -671,276 +393,178 @@ function __updateEntityBasedOnWhere(entityDefs, where, r) {
|
|
|
671
393
|
});
|
|
672
394
|
}
|
|
673
395
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
function getEntitySettings(entity, throwError) {
|
|
679
|
-
if (throwError === void 0) { throwError = true; }
|
|
396
|
+
export const entityInfo = Symbol("entityInfo");
|
|
397
|
+
export const entityInfo_key = Symbol("entityInfo_key");
|
|
398
|
+
const entityMember = Symbol("entityMember");
|
|
399
|
+
export function getEntitySettings(entity, throwError = true) {
|
|
680
400
|
if (entity === undefined)
|
|
681
401
|
if (throwError) {
|
|
682
402
|
throw new Error("Undefined is not an entity :)");
|
|
683
403
|
}
|
|
684
404
|
else
|
|
685
405
|
return undefined;
|
|
686
|
-
|
|
406
|
+
let info = Reflect.getMetadata(entityInfo, entity);
|
|
687
407
|
if (!info && throwError)
|
|
688
408
|
throw new Error(entity.prototype.constructor.name + " is not a known entity, did you forget to set @Entity() or did you forget to add the '@' before the call to Entity?");
|
|
689
409
|
return info;
|
|
690
410
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
return Reflect.getMetadata(exports.entityInfo_key, entity);
|
|
411
|
+
export function getEntityKey(entity) {
|
|
412
|
+
return Reflect.getMetadata(entityInfo_key, entity);
|
|
694
413
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
var _this = this;
|
|
699
|
-
var r = exports.columnsOfType.get(entity);
|
|
414
|
+
export const columnsOfType = new Map();
|
|
415
|
+
export function createOldEntity(entity, remult) {
|
|
416
|
+
let r = columnsOfType.get(entity);
|
|
700
417
|
if (!r)
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
var baseCols = exports.columnsOfType.get(base);
|
|
418
|
+
columnsOfType.set(entity, r = []);
|
|
419
|
+
let info = getEntitySettings(entity)(remult);
|
|
420
|
+
let key = getEntityKey(entity);
|
|
421
|
+
let base = Object.getPrototypeOf(entity);
|
|
422
|
+
while (base != null) {
|
|
423
|
+
let baseCols = columnsOfType.get(base);
|
|
708
424
|
if (baseCols) {
|
|
709
|
-
r.unshift
|
|
425
|
+
r.unshift(...baseCols.filter(x => !r.find(y => y.key == x.key)));
|
|
710
426
|
}
|
|
711
|
-
|
|
427
|
+
let baseSettingsFactory = getEntitySettings(base, false);
|
|
712
428
|
if (baseSettingsFactory) {
|
|
713
|
-
|
|
714
|
-
info =
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
if (
|
|
718
|
-
|
|
719
|
-
info[
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
case 1:
|
|
724
|
-
_a.sent();
|
|
725
|
-
return [4 /*yield*/, baseSettings_1[key_1](a, b)];
|
|
726
|
-
case 2:
|
|
727
|
-
_a.sent();
|
|
728
|
-
return [2 /*return*/];
|
|
729
|
-
}
|
|
730
|
-
});
|
|
731
|
-
}); };
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
try {
|
|
735
|
-
for (var _b = (e_11 = void 0, tslib_1.__values(functions)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
736
|
-
var key_1 = _c.value;
|
|
737
|
-
_loop_2(key_1);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
741
|
-
finally {
|
|
742
|
-
try {
|
|
743
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
429
|
+
let baseSettings = baseSettingsFactory(remult);
|
|
430
|
+
info = { ...baseSettings, ...info };
|
|
431
|
+
let functions = ["saving", "saved", "deleting", "deleted", "validation"];
|
|
432
|
+
for (const key of functions) {
|
|
433
|
+
if (baseSettings[key] && baseSettings[key] !== info[key]) {
|
|
434
|
+
let x = info[key];
|
|
435
|
+
info[key] = async (a, b) => {
|
|
436
|
+
await x(a, b);
|
|
437
|
+
await baseSettings[key](a, b);
|
|
438
|
+
};
|
|
744
439
|
}
|
|
745
|
-
finally { if (e_11) throw e_11.error; }
|
|
746
440
|
}
|
|
747
441
|
}
|
|
748
442
|
base = Object.getPrototypeOf(base);
|
|
749
|
-
};
|
|
750
|
-
while (base != null) {
|
|
751
|
-
_loop_1();
|
|
752
443
|
}
|
|
753
444
|
return new EntityFullInfo(prepareColumnInfo(r, remult), info, remult, entity, key);
|
|
754
445
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
function rowHelperBase(columnsInfo, instance, remult) {
|
|
758
|
-
var e_12, _a;
|
|
759
|
-
var _this = this;
|
|
446
|
+
class rowHelperBase {
|
|
447
|
+
constructor(columnsInfo, instance, remult) {
|
|
760
448
|
this.columnsInfo = columnsInfo;
|
|
761
449
|
this.instance = instance;
|
|
762
450
|
this.remult = remult;
|
|
763
451
|
this._isLoading = false;
|
|
764
452
|
this.lookups = new Map();
|
|
765
453
|
this.originalValues = {};
|
|
766
|
-
|
|
767
|
-
|
|
454
|
+
for (const col of columnsInfo) {
|
|
455
|
+
let ei = getEntitySettings(col.valueType, false);
|
|
768
456
|
if (ei && remult) {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
457
|
+
let lookup = new LookupColumn(remult.repo(col.valueType), undefined);
|
|
458
|
+
this.lookups.set(col.key, lookup);
|
|
459
|
+
let val = instance[col.key];
|
|
460
|
+
let refImpl;
|
|
773
461
|
Object.defineProperty(instance, col.key, {
|
|
774
|
-
get:
|
|
775
|
-
if (
|
|
776
|
-
|
|
777
|
-
if (!
|
|
778
|
-
|
|
779
|
-
if (!
|
|
780
|
-
|
|
462
|
+
get: () => {
|
|
463
|
+
if (this._subscribers) {
|
|
464
|
+
this._subscribers.reportObserved();
|
|
465
|
+
if (!refImpl) {
|
|
466
|
+
refImpl = this.fields.find(col.key);
|
|
467
|
+
if (!refImpl._subscribers) {
|
|
468
|
+
refImpl._subscribers = new SubscribableImp();
|
|
781
469
|
}
|
|
782
470
|
}
|
|
783
|
-
|
|
471
|
+
refImpl._subscribers.reportObserved();
|
|
784
472
|
}
|
|
785
|
-
return
|
|
473
|
+
return lookup.item;
|
|
786
474
|
},
|
|
787
|
-
set:
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
(
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
refImpl_1._subscribers = new SubscribableImp();
|
|
475
|
+
set: (val) => {
|
|
476
|
+
lookup.set(val);
|
|
477
|
+
this._subscribers?.reportChanged();
|
|
478
|
+
if (!refImpl) {
|
|
479
|
+
refImpl = this.fields.find(col.key);
|
|
480
|
+
if (!refImpl._subscribers) {
|
|
481
|
+
refImpl._subscribers = new SubscribableImp();
|
|
795
482
|
}
|
|
796
483
|
}
|
|
797
|
-
|
|
484
|
+
refImpl._subscribers.reportChanged();
|
|
798
485
|
},
|
|
799
486
|
enumerable: true
|
|
800
487
|
});
|
|
801
|
-
|
|
488
|
+
lookup.set(val);
|
|
802
489
|
}
|
|
803
490
|
else {
|
|
804
491
|
}
|
|
805
|
-
};
|
|
806
|
-
var this_1 = this;
|
|
807
|
-
try {
|
|
808
|
-
for (var columnsInfo_1 = tslib_1.__values(columnsInfo), columnsInfo_1_1 = columnsInfo_1.next(); !columnsInfo_1_1.done; columnsInfo_1_1 = columnsInfo_1.next()) {
|
|
809
|
-
var col = columnsInfo_1_1.value;
|
|
810
|
-
_loop_3(col);
|
|
811
|
-
}
|
|
812
492
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
var _a;
|
|
824
|
-
(_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportObserved();
|
|
825
|
-
return this._error;
|
|
826
|
-
},
|
|
827
|
-
set: function (val) {
|
|
828
|
-
var _a;
|
|
829
|
-
this._error = val;
|
|
830
|
-
(_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportChanged();
|
|
831
|
-
},
|
|
832
|
-
enumerable: false,
|
|
833
|
-
configurable: true
|
|
834
|
-
});
|
|
835
|
-
rowHelperBase.prototype.subscribe = function (listener) {
|
|
493
|
+
}
|
|
494
|
+
get error() {
|
|
495
|
+
this._subscribers?.reportObserved();
|
|
496
|
+
return this._error;
|
|
497
|
+
}
|
|
498
|
+
set error(val) {
|
|
499
|
+
this._error = val;
|
|
500
|
+
this._subscribers?.reportChanged();
|
|
501
|
+
}
|
|
502
|
+
subscribe(listener) {
|
|
836
503
|
this.initSubscribers();
|
|
837
504
|
return this._subscribers.subscribe(listener);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
var e_13, _a;
|
|
841
|
-
var _this = this;
|
|
505
|
+
}
|
|
506
|
+
initSubscribers() {
|
|
842
507
|
if (!this._subscribers) {
|
|
843
508
|
this._subscribers = new SubscribableImp();
|
|
844
509
|
;
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
510
|
+
for (const col of this.columnsInfo) {
|
|
511
|
+
let ei = getEntitySettings(col.valueType, false);
|
|
512
|
+
let refImpl = this.fields.find(col.key);
|
|
848
513
|
refImpl._subscribers = new SubscribableImp();
|
|
849
|
-
if (ei &&
|
|
514
|
+
if (ei && this.remult) {
|
|
850
515
|
}
|
|
851
516
|
else {
|
|
852
|
-
|
|
853
|
-
Object.defineProperty(
|
|
854
|
-
get:
|
|
855
|
-
|
|
517
|
+
let val = this.instance[col.key];
|
|
518
|
+
Object.defineProperty(this.instance, col.key, {
|
|
519
|
+
get: () => {
|
|
520
|
+
this._subscribers.reportObserved();
|
|
856
521
|
refImpl._subscribers.reportObserved();
|
|
857
|
-
return
|
|
522
|
+
return val;
|
|
858
523
|
},
|
|
859
|
-
set:
|
|
860
|
-
|
|
861
|
-
|
|
524
|
+
set: (value) => {
|
|
525
|
+
val = value;
|
|
526
|
+
this._subscribers.reportChanged();
|
|
862
527
|
refImpl._subscribers.reportChanged();
|
|
863
528
|
},
|
|
864
529
|
enumerable: true
|
|
865
530
|
});
|
|
866
531
|
}
|
|
867
|
-
};
|
|
868
|
-
var this_2 = this;
|
|
869
|
-
try {
|
|
870
|
-
for (var _b = tslib_1.__values(this.columnsInfo), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
871
|
-
var col = _c.value;
|
|
872
|
-
_loop_4(col);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
876
|
-
finally {
|
|
877
|
-
try {
|
|
878
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
879
|
-
}
|
|
880
|
-
finally { if (e_13) throw e_13.error; }
|
|
881
532
|
}
|
|
882
533
|
}
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
configurable: true
|
|
897
|
-
});
|
|
898
|
-
rowHelperBase.prototype.waitLoad = function () {
|
|
899
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
900
|
-
return tslib_1.__generator(this, function (_a) {
|
|
901
|
-
switch (_a.label) {
|
|
902
|
-
case 0: return [4 /*yield*/, Promise.all(tslib_1.__spread(this.lookups.values()).map(function (x) { return x.waitLoad(); }))];
|
|
903
|
-
case 1:
|
|
904
|
-
_a.sent();
|
|
905
|
-
return [2 /*return*/];
|
|
906
|
-
}
|
|
907
|
-
});
|
|
908
|
-
});
|
|
909
|
-
};
|
|
910
|
-
rowHelperBase.prototype.__assertValidity = function () {
|
|
911
|
-
var e_14, _a;
|
|
534
|
+
}
|
|
535
|
+
get isLoading() {
|
|
536
|
+
this._subscribers?.reportObserved();
|
|
537
|
+
return this._isLoading;
|
|
538
|
+
}
|
|
539
|
+
set isLoading(val) {
|
|
540
|
+
this._isLoading = val;
|
|
541
|
+
this._subscribers?.reportChanged();
|
|
542
|
+
}
|
|
543
|
+
async waitLoad() {
|
|
544
|
+
await Promise.all([...this.lookups.values()].map(x => x.waitLoad()));
|
|
545
|
+
}
|
|
546
|
+
__assertValidity() {
|
|
912
547
|
if (!this.hasErrors()) {
|
|
913
|
-
|
|
548
|
+
let error = {
|
|
914
549
|
modelState: Object.assign({}, this.errors),
|
|
915
550
|
message: this.error
|
|
916
551
|
};
|
|
917
552
|
if (!error.message) {
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
this.error = error.message;
|
|
924
|
-
break;
|
|
925
|
-
}
|
|
553
|
+
for (const col of this.columnsInfo) {
|
|
554
|
+
if (this.errors[col.key]) {
|
|
555
|
+
error.message = this.fields[col.key].metadata.caption + ": " + this.errors[col.key];
|
|
556
|
+
this.error = error.message;
|
|
557
|
+
break;
|
|
926
558
|
}
|
|
927
559
|
}
|
|
928
|
-
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
929
|
-
finally {
|
|
930
|
-
try {
|
|
931
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
932
|
-
}
|
|
933
|
-
finally { if (e_14) throw e_14.error; }
|
|
934
|
-
}
|
|
935
560
|
}
|
|
936
561
|
throw error;
|
|
937
562
|
}
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
var e = err;
|
|
563
|
+
}
|
|
564
|
+
catchSaveErrors(err) {
|
|
565
|
+
let e = err;
|
|
942
566
|
if (e instanceof Promise) {
|
|
943
|
-
return e.then(
|
|
567
|
+
return e.then(x => this.catchSaveErrors(x));
|
|
944
568
|
}
|
|
945
569
|
if (e.error) {
|
|
946
570
|
e = e.error;
|
|
@@ -951,836 +575,386 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
951
575
|
this.error = e.Message;
|
|
952
576
|
else
|
|
953
577
|
this.error = e;
|
|
954
|
-
|
|
578
|
+
let s = e.modelState;
|
|
955
579
|
if (!s)
|
|
956
580
|
s = e.ModelState;
|
|
957
581
|
if (s) {
|
|
958
582
|
this.errors = s;
|
|
959
583
|
}
|
|
960
584
|
throw err;
|
|
961
|
-
}
|
|
962
|
-
|
|
585
|
+
}
|
|
586
|
+
__clearErrorsAndReportChanged() {
|
|
963
587
|
this.errors = undefined;
|
|
964
588
|
this.error = undefined;
|
|
965
589
|
this._reportChangedToEntityAndFields();
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
var e_15, _a;
|
|
590
|
+
}
|
|
591
|
+
_reportChangedToEntityAndFields() {
|
|
969
592
|
if (this._subscribers) {
|
|
970
593
|
this._subscribers.reportChanged();
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
var ref = field;
|
|
975
|
-
ref._subscribers.reportChanged();
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
979
|
-
finally {
|
|
980
|
-
try {
|
|
981
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
982
|
-
}
|
|
983
|
-
finally { if (e_15) throw e_15.error; }
|
|
594
|
+
for (const field of this.fields) {
|
|
595
|
+
let ref = field;
|
|
596
|
+
ref._subscribers.reportChanged();
|
|
984
597
|
}
|
|
985
598
|
}
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
(_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportObserved();
|
|
599
|
+
}
|
|
600
|
+
hasErrors() {
|
|
601
|
+
this._subscribers?.reportObserved();
|
|
990
602
|
return !!!this.error && this.errors == undefined;
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
val = col.valueConverter.toJson(val);
|
|
1006
|
-
if (val !== undefined && val !== null)
|
|
1007
|
-
val = col.valueConverter.fromJson(JSON.parse(JSON.stringify(val)));
|
|
1008
|
-
}
|
|
1009
|
-
d[col.key] = val;
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
1013
|
-
finally {
|
|
1014
|
-
try {
|
|
1015
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
603
|
+
}
|
|
604
|
+
copyDataToObject() {
|
|
605
|
+
let d = {};
|
|
606
|
+
for (const col of this.columnsInfo) {
|
|
607
|
+
let lu = this.lookups.get(col.key);
|
|
608
|
+
let val = undefined;
|
|
609
|
+
if (lu)
|
|
610
|
+
val = lu.id;
|
|
611
|
+
else
|
|
612
|
+
val = this.instance[col.key];
|
|
613
|
+
if (val !== undefined) {
|
|
614
|
+
val = col.valueConverter.toJson(val);
|
|
615
|
+
if (val !== undefined && val !== null)
|
|
616
|
+
val = col.valueConverter.fromJson(JSON.parse(JSON.stringify(val)));
|
|
1016
617
|
}
|
|
1017
|
-
|
|
618
|
+
d[col.key] = val;
|
|
1018
619
|
}
|
|
1019
620
|
return d;
|
|
1020
|
-
}
|
|
1021
|
-
|
|
621
|
+
}
|
|
622
|
+
saveOriginalData() {
|
|
1022
623
|
this.originalValues = this.copyDataToObject();
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
case 2: return [4 /*yield*/, this.__performColumnAndEntityValidations()];
|
|
1057
|
-
case 3:
|
|
1058
|
-
_a.sent();
|
|
1059
|
-
this.__assertValidity();
|
|
1060
|
-
return [2 /*return*/];
|
|
1061
|
-
}
|
|
1062
|
-
});
|
|
1063
|
-
});
|
|
1064
|
-
};
|
|
1065
|
-
rowHelperBase.prototype.__performColumnAndEntityValidations = function () {
|
|
1066
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1067
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1068
|
-
return [2 /*return*/];
|
|
1069
|
-
});
|
|
1070
|
-
});
|
|
1071
|
-
};
|
|
1072
|
-
rowHelperBase.prototype.toApiJson = function () {
|
|
1073
|
-
var e_17, _a;
|
|
1074
|
-
var result = {};
|
|
1075
|
-
try {
|
|
1076
|
-
for (var _b = tslib_1.__values(this.columnsInfo), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1077
|
-
var col = _c.value;
|
|
1078
|
-
if (!this.remult || col.includeInApi === undefined || this.remult.isAllowed(col.includeInApi)) {
|
|
1079
|
-
var val = void 0;
|
|
1080
|
-
var lu = this.lookups.get(col.key);
|
|
1081
|
-
if (lu)
|
|
1082
|
-
val = lu.id;
|
|
1083
|
-
else {
|
|
1084
|
-
val = this.instance[col.key];
|
|
1085
|
-
if (!this.remult) {
|
|
1086
|
-
if (val) {
|
|
1087
|
-
var eo = getEntitySettings(val.constructor, false);
|
|
1088
|
-
if (eo) {
|
|
1089
|
-
val = getEntityRef(val).getId();
|
|
1090
|
-
}
|
|
624
|
+
}
|
|
625
|
+
async validate() {
|
|
626
|
+
this.__clearErrorsAndReportChanged();
|
|
627
|
+
if (classValidatorValidate)
|
|
628
|
+
await classValidatorValidate(this.instance, this);
|
|
629
|
+
await this.__performColumnAndEntityValidations();
|
|
630
|
+
let r = this.hasErrors();
|
|
631
|
+
return r;
|
|
632
|
+
}
|
|
633
|
+
async __validateEntity() {
|
|
634
|
+
this.__clearErrorsAndReportChanged();
|
|
635
|
+
if (classValidatorValidate)
|
|
636
|
+
await classValidatorValidate(this.instance, this);
|
|
637
|
+
await this.__performColumnAndEntityValidations();
|
|
638
|
+
this.__assertValidity();
|
|
639
|
+
}
|
|
640
|
+
async __performColumnAndEntityValidations() {
|
|
641
|
+
}
|
|
642
|
+
toApiJson() {
|
|
643
|
+
let result = {};
|
|
644
|
+
for (const col of this.columnsInfo) {
|
|
645
|
+
if (!this.remult || col.includeInApi === undefined || this.remult.isAllowed(col.includeInApi)) {
|
|
646
|
+
let val;
|
|
647
|
+
let lu = this.lookups.get(col.key);
|
|
648
|
+
if (lu)
|
|
649
|
+
val = lu.id;
|
|
650
|
+
else {
|
|
651
|
+
val = this.instance[col.key];
|
|
652
|
+
if (!this.remult) {
|
|
653
|
+
if (val) {
|
|
654
|
+
let eo = getEntitySettings(val.constructor, false);
|
|
655
|
+
if (eo) {
|
|
656
|
+
val = getEntityRef(val).getId();
|
|
1091
657
|
}
|
|
1092
658
|
}
|
|
1093
659
|
}
|
|
1094
|
-
result[col.key] = col.valueConverter.toJson(val);
|
|
1095
660
|
}
|
|
661
|
+
result[col.key] = col.valueConverter.toJson(val);
|
|
1096
662
|
}
|
|
1097
663
|
}
|
|
1098
|
-
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
1099
|
-
finally {
|
|
1100
|
-
try {
|
|
1101
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1102
|
-
}
|
|
1103
|
-
finally { if (e_17) throw e_17.error; }
|
|
1104
|
-
}
|
|
1105
664
|
return result;
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
if (col.includeInApi === undefined || this.remult.isAllowed(col.includeInApi)) {
|
|
1120
|
-
if (!this.remult || col.allowApiUpdate === undefined || this.remult.isAllowedForInstance(this.instance, col.allowApiUpdate)) {
|
|
1121
|
-
lu = this.lookups.get(col.key);
|
|
1122
|
-
if (lu)
|
|
1123
|
-
lu.id = body[col.key];
|
|
1124
|
-
else
|
|
1125
|
-
this.instance[col.key] = col.valueConverter.fromJson(body[col.key]);
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
1131
|
-
finally {
|
|
1132
|
-
try {
|
|
1133
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1134
|
-
}
|
|
1135
|
-
finally { if (e_18) throw e_18.error; }
|
|
1136
|
-
}
|
|
1137
|
-
return [4 /*yield*/, Promise.all(tslib_1.__spread(this.fields).map(function (x) { return x.load(); }))];
|
|
1138
|
-
case 1:
|
|
1139
|
-
_d.sent();
|
|
1140
|
-
return [2 /*return*/];
|
|
665
|
+
}
|
|
666
|
+
async _updateEntityBasedOnApi(body) {
|
|
667
|
+
let keys = Object.keys(body);
|
|
668
|
+
for (const col of this.columnsInfo) {
|
|
669
|
+
if (keys.includes(col.key))
|
|
670
|
+
if (col.includeInApi === undefined || this.remult.isAllowed(col.includeInApi)) {
|
|
671
|
+
if (!this.remult || col.allowApiUpdate === undefined || this.remult.isAllowedForInstance(this.instance, col.allowApiUpdate)) {
|
|
672
|
+
let lu = this.lookups.get(col.key);
|
|
673
|
+
if (lu)
|
|
674
|
+
lu.id = body[col.key];
|
|
675
|
+
else
|
|
676
|
+
this.instance[col.key] = col.valueConverter.fromJson(body[col.key]);
|
|
677
|
+
}
|
|
1141
678
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
_this._wasDeleted = false;
|
|
1157
|
-
_this._saving = false;
|
|
1158
|
-
_this.metadata = info;
|
|
679
|
+
}
|
|
680
|
+
await Promise.all([...this.fields].map(x => x.load()));
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
export class rowHelperImplementation extends rowHelperBase {
|
|
684
|
+
constructor(info, instance, repository, edp, remult, _isNew) {
|
|
685
|
+
super(info.columnsInfo, instance, remult);
|
|
686
|
+
this.info = info;
|
|
687
|
+
this.repository = repository;
|
|
688
|
+
this.edp = edp;
|
|
689
|
+
this._isNew = _isNew;
|
|
690
|
+
this._wasDeleted = false;
|
|
691
|
+
this._saving = false;
|
|
692
|
+
this.metadata = info;
|
|
1159
693
|
if (_isNew) {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
if (typeof col.defaultValue === "function") {
|
|
1165
|
-
instance[col.key] = col.defaultValue(instance);
|
|
1166
|
-
}
|
|
1167
|
-
else if (!instance[col.key])
|
|
1168
|
-
instance[col.key] = col.defaultValue;
|
|
694
|
+
for (const col of info.columnsInfo) {
|
|
695
|
+
if (col.defaultValue) {
|
|
696
|
+
if (typeof col.defaultValue === "function") {
|
|
697
|
+
instance[col.key] = col.defaultValue(instance);
|
|
1169
698
|
}
|
|
699
|
+
else if (!instance[col.key])
|
|
700
|
+
instance[col.key] = col.defaultValue;
|
|
1170
701
|
}
|
|
1171
702
|
}
|
|
1172
|
-
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
1173
|
-
finally {
|
|
1174
|
-
try {
|
|
1175
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1176
|
-
}
|
|
1177
|
-
finally { if (e_19) throw e_19.error; }
|
|
1178
|
-
}
|
|
1179
703
|
}
|
|
1180
|
-
if (
|
|
1181
|
-
|
|
1182
|
-
if (
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
});
|
|
1191
|
-
Object.defineProperty(rowHelperImplementation.prototype, "apiDeleteAllowed", {
|
|
1192
|
-
get: function () { return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiDelete); },
|
|
1193
|
-
enumerable: false,
|
|
1194
|
-
configurable: true
|
|
1195
|
-
});
|
|
1196
|
-
Object.defineProperty(rowHelperImplementation.prototype, "apiInsertAllowed", {
|
|
1197
|
-
get: function () { return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiInsert); },
|
|
1198
|
-
enumerable: false,
|
|
1199
|
-
configurable: true
|
|
1200
|
-
});
|
|
1201
|
-
rowHelperImplementation.prototype.getId = function () {
|
|
1202
|
-
if (this.info.idMetadata.field instanceof column_1.CompoundIdField)
|
|
704
|
+
if (this.info.options.entityRefInit)
|
|
705
|
+
this.info.options.entityRefInit(this, instance);
|
|
706
|
+
if (Remult.entityRefInit)
|
|
707
|
+
Remult.entityRefInit(this, instance);
|
|
708
|
+
}
|
|
709
|
+
get apiUpdateAllowed() { return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiUpdate); }
|
|
710
|
+
get apiDeleteAllowed() { return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiDelete); }
|
|
711
|
+
get apiInsertAllowed() { return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiInsert); }
|
|
712
|
+
getId() {
|
|
713
|
+
if (this.info.idMetadata.field instanceof CompoundIdField)
|
|
1203
714
|
return this.info.idMetadata.field.getId(this.instance);
|
|
1204
715
|
else
|
|
1205
716
|
return this.instance[this.info.idMetadata.field.key];
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
(_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportObserved();
|
|
717
|
+
}
|
|
718
|
+
wasDeleted() {
|
|
719
|
+
this._subscribers?.reportObserved();
|
|
1210
720
|
return this._wasDeleted;
|
|
1211
|
-
}
|
|
1212
|
-
|
|
721
|
+
}
|
|
722
|
+
undoChanges() {
|
|
1213
723
|
this.loadDataFrom(this.originalValues);
|
|
1214
724
|
this.__clearErrorsAndReportChanged();
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
switch (_a.label) {
|
|
1221
|
-
case 0: return [4 /*yield*/, this.edp.find({ where: this.getIdFilter() }).then(function (newData) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1222
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1223
|
-
switch (_a.label) {
|
|
1224
|
-
case 0: return [4 /*yield*/, this.loadDataFrom(newData[0])];
|
|
1225
|
-
case 1:
|
|
1226
|
-
_a.sent();
|
|
1227
|
-
this.saveOriginalData();
|
|
1228
|
-
return [2 /*return*/];
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
}); })];
|
|
1232
|
-
case 1:
|
|
1233
|
-
_a.sent();
|
|
1234
|
-
this._reportChangedToEntityAndFields();
|
|
1235
|
-
return [2 /*return*/, this.instance];
|
|
1236
|
-
}
|
|
1237
|
-
});
|
|
725
|
+
}
|
|
726
|
+
async reload() {
|
|
727
|
+
await this.edp.find({ where: this.getIdFilter() }).then(async (newData) => {
|
|
728
|
+
await this.loadDataFrom(newData[0]);
|
|
729
|
+
this.saveOriginalData();
|
|
1238
730
|
});
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
731
|
+
this._reportChangedToEntityAndFields();
|
|
732
|
+
return this.instance;
|
|
733
|
+
}
|
|
734
|
+
get fields() {
|
|
735
|
+
if (!this._columns) {
|
|
736
|
+
let _items = [];
|
|
737
|
+
let r = {
|
|
738
|
+
find: (c) => r[typeof c === "string" ? c : c.key],
|
|
739
|
+
[Symbol.iterator]: () => _items[Symbol.iterator](),
|
|
740
|
+
toArray: () => _items
|
|
741
|
+
};
|
|
742
|
+
for (const c of this.info.columnsInfo) {
|
|
743
|
+
_items.push(r[c.key] = new FieldRefImplementation(c, this.info.fields[c.key], this.instance, this, this));
|
|
744
|
+
}
|
|
745
|
+
this._columns = r;
|
|
746
|
+
}
|
|
747
|
+
return this._columns;
|
|
748
|
+
}
|
|
749
|
+
async save() {
|
|
750
|
+
try {
|
|
751
|
+
if (this._saving)
|
|
752
|
+
throw new Error("cannot save while entity is already saving");
|
|
753
|
+
this._saving = true;
|
|
754
|
+
if (this.wasDeleted())
|
|
755
|
+
throw new Error("cannot save a deleted row");
|
|
756
|
+
this.isLoading = true;
|
|
757
|
+
await this.__validateEntity();
|
|
758
|
+
let doNotSave = false;
|
|
759
|
+
for (const col of this.fields) {
|
|
760
|
+
if (col.metadata.options.saving)
|
|
761
|
+
await col.metadata.options.saving(this.instance, col);
|
|
762
|
+
}
|
|
763
|
+
if (this.info.entityInfo.saving) {
|
|
764
|
+
await this.info.entityInfo.saving(this.instance, () => doNotSave = true);
|
|
765
|
+
}
|
|
766
|
+
this.__assertValidity();
|
|
767
|
+
let d = this.copyDataToObject();
|
|
768
|
+
let ignoreKeys = [];
|
|
769
|
+
for (const field of this.metadata.fields) {
|
|
770
|
+
if (field.dbReadOnly) {
|
|
771
|
+
d[field.key] = undefined;
|
|
772
|
+
ignoreKeys.push(field.key);
|
|
773
|
+
let f = this.fields.find(field);
|
|
774
|
+
f.value = f.originalValue;
|
|
1263
775
|
}
|
|
1264
|
-
this._columns = r_1;
|
|
1265
776
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1274
|
-
var doNotSave_1, _b, _c, col, e_21_1, d, ignoreKeys, _d, _e, field, f, updatedRow, changesOnly, wasChanged, key, element, err_1;
|
|
1275
|
-
var e_21, _f, e_22, _g;
|
|
1276
|
-
return tslib_1.__generator(this, function (_h) {
|
|
1277
|
-
switch (_h.label) {
|
|
1278
|
-
case 0:
|
|
1279
|
-
_h.trys.push([0, , 25, 26]);
|
|
1280
|
-
if (this._saving)
|
|
1281
|
-
throw new Error("cannot save while entity is already saving");
|
|
1282
|
-
this._saving = true;
|
|
1283
|
-
if (this.wasDeleted())
|
|
1284
|
-
throw new Error("cannot save a deleted row");
|
|
1285
|
-
this.isLoading = true;
|
|
1286
|
-
return [4 /*yield*/, this.__validateEntity()];
|
|
1287
|
-
case 1:
|
|
1288
|
-
_h.sent();
|
|
1289
|
-
doNotSave_1 = false;
|
|
1290
|
-
_h.label = 2;
|
|
1291
|
-
case 2:
|
|
1292
|
-
_h.trys.push([2, 7, 8, 9]);
|
|
1293
|
-
_b = tslib_1.__values(this.fields), _c = _b.next();
|
|
1294
|
-
_h.label = 3;
|
|
1295
|
-
case 3:
|
|
1296
|
-
if (!!_c.done) return [3 /*break*/, 6];
|
|
1297
|
-
col = _c.value;
|
|
1298
|
-
if (!col.metadata.options.saving) return [3 /*break*/, 5];
|
|
1299
|
-
return [4 /*yield*/, col.metadata.options.saving(this.instance, col)];
|
|
1300
|
-
case 4:
|
|
1301
|
-
_h.sent();
|
|
1302
|
-
_h.label = 5;
|
|
1303
|
-
case 5:
|
|
1304
|
-
_c = _b.next();
|
|
1305
|
-
return [3 /*break*/, 3];
|
|
1306
|
-
case 6: return [3 /*break*/, 9];
|
|
1307
|
-
case 7:
|
|
1308
|
-
e_21_1 = _h.sent();
|
|
1309
|
-
e_21 = { error: e_21_1 };
|
|
1310
|
-
return [3 /*break*/, 9];
|
|
1311
|
-
case 8:
|
|
1312
|
-
try {
|
|
1313
|
-
if (_c && !_c.done && (_f = _b.return)) _f.call(_b);
|
|
1314
|
-
}
|
|
1315
|
-
finally { if (e_21) throw e_21.error; }
|
|
1316
|
-
return [7 /*endfinally*/];
|
|
1317
|
-
case 9:
|
|
1318
|
-
if (!this.info.entityInfo.saving) return [3 /*break*/, 11];
|
|
1319
|
-
return [4 /*yield*/, this.info.entityInfo.saving(this.instance, function () { return doNotSave_1 = true; })];
|
|
1320
|
-
case 10:
|
|
1321
|
-
_h.sent();
|
|
1322
|
-
_h.label = 11;
|
|
1323
|
-
case 11:
|
|
1324
|
-
this.__assertValidity();
|
|
1325
|
-
d = this.copyDataToObject();
|
|
1326
|
-
ignoreKeys = [];
|
|
1327
|
-
try {
|
|
1328
|
-
for (_d = tslib_1.__values(this.metadata.fields), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1329
|
-
field = _e.value;
|
|
1330
|
-
if (field.dbReadOnly) {
|
|
1331
|
-
d[field.key] = undefined;
|
|
1332
|
-
ignoreKeys.push(field.key);
|
|
1333
|
-
f = this.fields.find(field);
|
|
1334
|
-
f.value = f.originalValue;
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
1339
|
-
finally {
|
|
1340
|
-
try {
|
|
1341
|
-
if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
|
|
1342
|
-
}
|
|
1343
|
-
finally { if (e_22) throw e_22.error; }
|
|
1344
|
-
}
|
|
1345
|
-
if (this.info.idMetadata.field instanceof column_1.CompoundIdField)
|
|
1346
|
-
delete (d.id);
|
|
1347
|
-
updatedRow = void 0;
|
|
1348
|
-
_h.label = 12;
|
|
1349
|
-
case 12:
|
|
1350
|
-
_h.trys.push([12, 22, , 24]);
|
|
1351
|
-
(_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportChanged();
|
|
1352
|
-
if (!this.isNew()) return [3 /*break*/, 14];
|
|
1353
|
-
return [4 /*yield*/, this.edp.insert(d)];
|
|
1354
|
-
case 13:
|
|
1355
|
-
updatedRow = _h.sent();
|
|
1356
|
-
return [3 /*break*/, 18];
|
|
1357
|
-
case 14:
|
|
1358
|
-
changesOnly = {};
|
|
1359
|
-
wasChanged = false;
|
|
1360
|
-
for (key in d) {
|
|
1361
|
-
if (Object.prototype.hasOwnProperty.call(d, key)) {
|
|
1362
|
-
element = d[key];
|
|
1363
|
-
if (this.fields.find(key).valueChanged() && !ignoreKeys.includes(key)) {
|
|
1364
|
-
changesOnly[key] = element;
|
|
1365
|
-
wasChanged = true;
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
if (!wasChanged)
|
|
1370
|
-
return [2 /*return*/, this.instance];
|
|
1371
|
-
if (!doNotSave_1) return [3 /*break*/, 16];
|
|
1372
|
-
return [4 /*yield*/, this.edp.find({ where: this.getIdFilter() })];
|
|
1373
|
-
case 15:
|
|
1374
|
-
updatedRow = (_h.sent())[0];
|
|
1375
|
-
return [3 /*break*/, 18];
|
|
1376
|
-
case 16: return [4 /*yield*/, this.edp.update(this.id, changesOnly)];
|
|
1377
|
-
case 17:
|
|
1378
|
-
updatedRow = _h.sent();
|
|
1379
|
-
_h.label = 18;
|
|
1380
|
-
case 18: return [4 /*yield*/, this.loadDataFrom(updatedRow)];
|
|
1381
|
-
case 19:
|
|
1382
|
-
_h.sent();
|
|
1383
|
-
if (!this.info.entityInfo.saved) return [3 /*break*/, 21];
|
|
1384
|
-
return [4 /*yield*/, this.info.entityInfo.saved(this.instance)];
|
|
1385
|
-
case 20:
|
|
1386
|
-
_h.sent();
|
|
1387
|
-
_h.label = 21;
|
|
1388
|
-
case 21:
|
|
1389
|
-
this.saveOriginalData();
|
|
1390
|
-
this._isNew = false;
|
|
1391
|
-
return [2 /*return*/, this.instance];
|
|
1392
|
-
case 22:
|
|
1393
|
-
err_1 = _h.sent();
|
|
1394
|
-
return [4 /*yield*/, this.catchSaveErrors(err_1)];
|
|
1395
|
-
case 23:
|
|
1396
|
-
_h.sent();
|
|
1397
|
-
return [3 /*break*/, 24];
|
|
1398
|
-
case 24: return [3 /*break*/, 26];
|
|
1399
|
-
case 25:
|
|
1400
|
-
this.isLoading = false;
|
|
1401
|
-
this._reportChangedToEntityAndFields();
|
|
1402
|
-
this._saving = false;
|
|
1403
|
-
return [7 /*endfinally*/];
|
|
1404
|
-
case 26: return [2 /*return*/];
|
|
777
|
+
if (this.info.idMetadata.field instanceof CompoundIdField)
|
|
778
|
+
delete (d.id);
|
|
779
|
+
let updatedRow;
|
|
780
|
+
try {
|
|
781
|
+
this._subscribers?.reportChanged();
|
|
782
|
+
if (this.isNew()) {
|
|
783
|
+
updatedRow = await this.edp.insert(d);
|
|
1405
784
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
return tslib_1.__generator(this, function (_d) {
|
|
1417
|
-
switch (_d.label) {
|
|
1418
|
-
case 0:
|
|
1419
|
-
this.__clearErrorsAndReportChanged();
|
|
1420
|
-
if (!this.info.entityInfo.deleting) return [3 /*break*/, 2];
|
|
1421
|
-
return [4 /*yield*/, this.info.entityInfo.deleting(this.instance)];
|
|
1422
|
-
case 1:
|
|
1423
|
-
_d.sent();
|
|
1424
|
-
_d.label = 2;
|
|
1425
|
-
case 2:
|
|
1426
|
-
this.__assertValidity();
|
|
1427
|
-
_d.label = 3;
|
|
1428
|
-
case 3:
|
|
1429
|
-
_d.trys.push([3, 15, , 17]);
|
|
1430
|
-
return [4 /*yield*/, this.edp.delete(this.id)];
|
|
1431
|
-
case 4:
|
|
1432
|
-
_d.sent();
|
|
1433
|
-
if (!this.info.entityInfo.deleted) return [3 /*break*/, 6];
|
|
1434
|
-
return [4 /*yield*/, this.info.entityInfo.deleted(this.instance)];
|
|
1435
|
-
case 5:
|
|
1436
|
-
_d.sent();
|
|
1437
|
-
_d.label = 6;
|
|
1438
|
-
case 6:
|
|
1439
|
-
if (!this.repository.listeners) return [3 /*break*/, 14];
|
|
1440
|
-
_d.label = 7;
|
|
1441
|
-
case 7:
|
|
1442
|
-
_d.trys.push([7, 12, 13, 14]);
|
|
1443
|
-
_a = tslib_1.__values(this.repository.listeners.filter(function (x) { return x.deleted; })), _b = _a.next();
|
|
1444
|
-
_d.label = 8;
|
|
1445
|
-
case 8:
|
|
1446
|
-
if (!!_b.done) return [3 /*break*/, 11];
|
|
1447
|
-
listener = _b.value;
|
|
1448
|
-
return [4 /*yield*/, listener.deleted(this.instance)];
|
|
1449
|
-
case 9:
|
|
1450
|
-
_d.sent();
|
|
1451
|
-
_d.label = 10;
|
|
1452
|
-
case 10:
|
|
1453
|
-
_b = _a.next();
|
|
1454
|
-
return [3 /*break*/, 8];
|
|
1455
|
-
case 11: return [3 /*break*/, 14];
|
|
1456
|
-
case 12:
|
|
1457
|
-
e_23_1 = _d.sent();
|
|
1458
|
-
e_23 = { error: e_23_1 };
|
|
1459
|
-
return [3 /*break*/, 14];
|
|
1460
|
-
case 13:
|
|
1461
|
-
try {
|
|
1462
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
785
|
+
else {
|
|
786
|
+
let changesOnly = {};
|
|
787
|
+
let wasChanged = false;
|
|
788
|
+
for (const key in d) {
|
|
789
|
+
if (Object.prototype.hasOwnProperty.call(d, key)) {
|
|
790
|
+
const element = d[key];
|
|
791
|
+
if (this.fields.find(key).valueChanged() && !ignoreKeys.includes(key)) {
|
|
792
|
+
changesOnly[key] = element;
|
|
793
|
+
wasChanged = true;
|
|
794
|
+
}
|
|
1463
795
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
_d.sent();
|
|
1474
|
-
return [3 /*break*/, 17];
|
|
1475
|
-
case 17: return [2 /*return*/];
|
|
796
|
+
}
|
|
797
|
+
if (!wasChanged)
|
|
798
|
+
return this.instance;
|
|
799
|
+
if (doNotSave) {
|
|
800
|
+
updatedRow = (await this.edp.find({ where: this.getIdFilter() }))[0];
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
updatedRow = await this.edp.update(this.id, changesOnly);
|
|
804
|
+
}
|
|
1476
805
|
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
}
|
|
1525
|
-
finally { if (e_24) throw e_24.error; }
|
|
1526
|
-
return [7 /*endfinally*/];
|
|
1527
|
-
case 12: return [4 /*yield*/, this.calcServerExpression()];
|
|
1528
|
-
case 13:
|
|
1529
|
-
_d.sent();
|
|
1530
|
-
if (this.repository.metadata.idMetadata.field instanceof column_1.CompoundIdField) {
|
|
1531
|
-
this.id = this.repository.metadata.idMetadata.field.getId(this.instance);
|
|
1532
|
-
}
|
|
1533
|
-
else
|
|
1534
|
-
this.id = data[this.repository.metadata.idMetadata.field.key];
|
|
1535
|
-
return [2 /*return*/];
|
|
806
|
+
await this.loadDataFrom(updatedRow);
|
|
807
|
+
if (this.info.entityInfo.saved)
|
|
808
|
+
await this.info.entityInfo.saved(this.instance);
|
|
809
|
+
this.saveOriginalData();
|
|
810
|
+
this._isNew = false;
|
|
811
|
+
return this.instance;
|
|
812
|
+
}
|
|
813
|
+
catch (err) {
|
|
814
|
+
await this.catchSaveErrors(err);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
finally {
|
|
818
|
+
this.isLoading = false;
|
|
819
|
+
this._reportChangedToEntityAndFields();
|
|
820
|
+
this._saving = false;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
getIdFilter() {
|
|
824
|
+
return Filter.fromEntityFilter(this.metadata, this.repository.metadata.idMetadata.getIdFilter(this.id));
|
|
825
|
+
}
|
|
826
|
+
async delete() {
|
|
827
|
+
this.__clearErrorsAndReportChanged();
|
|
828
|
+
if (this.info.entityInfo.deleting)
|
|
829
|
+
await this.info.entityInfo.deleting(this.instance);
|
|
830
|
+
this.__assertValidity();
|
|
831
|
+
try {
|
|
832
|
+
await this.edp.delete(this.id);
|
|
833
|
+
if (this.info.entityInfo.deleted)
|
|
834
|
+
await this.info.entityInfo.deleted(this.instance);
|
|
835
|
+
if (this.repository.listeners)
|
|
836
|
+
for (const listener of this.repository.listeners.filter(x => x.deleted)) {
|
|
837
|
+
await listener.deleted(this.instance);
|
|
838
|
+
}
|
|
839
|
+
this._wasDeleted = true;
|
|
840
|
+
}
|
|
841
|
+
catch (err) {
|
|
842
|
+
await this.catchSaveErrors(err);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
async loadDataFrom(data, loadItems) {
|
|
846
|
+
for (const col of this.info.fields) {
|
|
847
|
+
let lu = this.lookups.get(col.key);
|
|
848
|
+
if (lu) {
|
|
849
|
+
lu.id = data[col.key];
|
|
850
|
+
if (loadItems === undefined) {
|
|
851
|
+
if (!col.options.lazy)
|
|
852
|
+
await lu.waitLoad();
|
|
1536
853
|
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
rowHelperImplementation.prototype.getOriginalId = function () {
|
|
1541
|
-
return this.id;
|
|
1542
|
-
};
|
|
1543
|
-
rowHelperImplementation.prototype.calcServerExpression = function () {
|
|
1544
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1545
|
-
var _a, _b, col, _c, _d, e_25_1;
|
|
1546
|
-
var e_25, _e;
|
|
1547
|
-
return tslib_1.__generator(this, function (_f) {
|
|
1548
|
-
switch (_f.label) {
|
|
1549
|
-
case 0:
|
|
1550
|
-
if (!context_1.isBackend()) return [3 /*break*/, 8];
|
|
1551
|
-
_f.label = 1;
|
|
1552
|
-
case 1:
|
|
1553
|
-
_f.trys.push([1, 6, 7, 8]);
|
|
1554
|
-
_a = tslib_1.__values(this.info.columnsInfo), _b = _a.next();
|
|
1555
|
-
_f.label = 2;
|
|
1556
|
-
case 2:
|
|
1557
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
1558
|
-
col = _b.value;
|
|
1559
|
-
if (!col.serverExpression) return [3 /*break*/, 4];
|
|
1560
|
-
_c = this.instance;
|
|
1561
|
-
_d = col.key;
|
|
1562
|
-
return [4 /*yield*/, col.serverExpression(this.instance)];
|
|
1563
|
-
case 3:
|
|
1564
|
-
_c[_d] = _f.sent();
|
|
1565
|
-
_f.label = 4;
|
|
1566
|
-
case 4:
|
|
1567
|
-
_b = _a.next();
|
|
1568
|
-
return [3 /*break*/, 2];
|
|
1569
|
-
case 5: return [3 /*break*/, 8];
|
|
1570
|
-
case 6:
|
|
1571
|
-
e_25_1 = _f.sent();
|
|
1572
|
-
e_25 = { error: e_25_1 };
|
|
1573
|
-
return [3 /*break*/, 8];
|
|
1574
|
-
case 7:
|
|
1575
|
-
try {
|
|
1576
|
-
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
1577
|
-
}
|
|
1578
|
-
finally { if (e_25) throw e_25.error; }
|
|
1579
|
-
return [7 /*endfinally*/];
|
|
1580
|
-
case 8: return [2 /*return*/];
|
|
854
|
+
else {
|
|
855
|
+
if (loadItems.includes(col))
|
|
856
|
+
await lu.waitLoad();
|
|
1581
857
|
}
|
|
1582
|
-
});
|
|
1583
|
-
});
|
|
1584
|
-
};
|
|
1585
|
-
rowHelperImplementation.prototype.isNew = function () {
|
|
1586
|
-
var _a;
|
|
1587
|
-
(_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportObserved();
|
|
1588
|
-
return this._isNew;
|
|
1589
|
-
};
|
|
1590
|
-
rowHelperImplementation.prototype.wasChanged = function () {
|
|
1591
|
-
var e_26, _a;
|
|
1592
|
-
var _b;
|
|
1593
|
-
(_b = this._subscribers) === null || _b === void 0 ? void 0 : _b.reportObserved();
|
|
1594
|
-
try {
|
|
1595
|
-
for (var _c = tslib_1.__values(this.fields), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1596
|
-
var col = _d.value;
|
|
1597
|
-
if (col.valueChanged())
|
|
1598
|
-
return true;
|
|
1599
858
|
}
|
|
859
|
+
else
|
|
860
|
+
this.instance[col.key] = data[col.key];
|
|
1600
861
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
862
|
+
await this.calcServerExpression();
|
|
863
|
+
if (this.repository.metadata.idMetadata.field instanceof CompoundIdField) {
|
|
864
|
+
this.id = this.repository.metadata.idMetadata.field.getId(this.instance);
|
|
865
|
+
}
|
|
866
|
+
else
|
|
867
|
+
this.id = data[this.repository.metadata.idMetadata.field.key];
|
|
868
|
+
}
|
|
869
|
+
getOriginalId() {
|
|
870
|
+
return this.id;
|
|
871
|
+
}
|
|
872
|
+
async calcServerExpression() {
|
|
873
|
+
if (isBackend())
|
|
874
|
+
for (const col of this.info.columnsInfo) {
|
|
875
|
+
if (col.serverExpression) {
|
|
876
|
+
this.instance[col.key] = await col.serverExpression(this.instance);
|
|
877
|
+
}
|
|
1605
878
|
}
|
|
1606
|
-
|
|
879
|
+
}
|
|
880
|
+
isNew() {
|
|
881
|
+
this._subscribers?.reportObserved();
|
|
882
|
+
return this._isNew;
|
|
883
|
+
}
|
|
884
|
+
wasChanged() {
|
|
885
|
+
this._subscribers?.reportObserved();
|
|
886
|
+
for (const col of this.fields) {
|
|
887
|
+
if (col.valueChanged())
|
|
888
|
+
return true;
|
|
1607
889
|
}
|
|
1608
890
|
return false;
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
case 2:
|
|
1627
|
-
_g.sent();
|
|
1628
|
-
_g.label = 3;
|
|
1629
|
-
case 3:
|
|
1630
|
-
_b = _a.next();
|
|
1631
|
-
return [3 /*break*/, 1];
|
|
1632
|
-
case 4: return [3 /*break*/, 7];
|
|
1633
|
-
case 5:
|
|
1634
|
-
e_27_1 = _g.sent();
|
|
1635
|
-
e_27 = { error: e_27_1 };
|
|
1636
|
-
return [3 /*break*/, 7];
|
|
1637
|
-
case 6:
|
|
1638
|
-
try {
|
|
1639
|
-
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
1640
|
-
}
|
|
1641
|
-
finally { if (e_27) throw e_27.error; }
|
|
1642
|
-
return [7 /*endfinally*/];
|
|
1643
|
-
case 7:
|
|
1644
|
-
if (!this.info.entityInfo.validation) return [3 /*break*/, 9];
|
|
1645
|
-
return [4 /*yield*/, this.info.entityInfo.validation(this.instance, this)];
|
|
1646
|
-
case 8:
|
|
1647
|
-
_g.sent();
|
|
1648
|
-
_g.label = 9;
|
|
1649
|
-
case 9:
|
|
1650
|
-
if (!this.repository.listeners) return [3 /*break*/, 17];
|
|
1651
|
-
_g.label = 10;
|
|
1652
|
-
case 10:
|
|
1653
|
-
_g.trys.push([10, 15, 16, 17]);
|
|
1654
|
-
_c = tslib_1.__values(this.repository.listeners.filter(function (x) { return x.validating; })), _d = _c.next();
|
|
1655
|
-
_g.label = 11;
|
|
1656
|
-
case 11:
|
|
1657
|
-
if (!!_d.done) return [3 /*break*/, 14];
|
|
1658
|
-
listener = _d.value;
|
|
1659
|
-
return [4 /*yield*/, listener.validating(this.instance)];
|
|
1660
|
-
case 12:
|
|
1661
|
-
_g.sent();
|
|
1662
|
-
_g.label = 13;
|
|
1663
|
-
case 13:
|
|
1664
|
-
_d = _c.next();
|
|
1665
|
-
return [3 /*break*/, 11];
|
|
1666
|
-
case 14: return [3 /*break*/, 17];
|
|
1667
|
-
case 15:
|
|
1668
|
-
e_28_1 = _g.sent();
|
|
1669
|
-
e_28 = { error: e_28_1 };
|
|
1670
|
-
return [3 /*break*/, 17];
|
|
1671
|
-
case 16:
|
|
1672
|
-
try {
|
|
1673
|
-
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
1674
|
-
}
|
|
1675
|
-
finally { if (e_28) throw e_28.error; }
|
|
1676
|
-
return [7 /*endfinally*/];
|
|
1677
|
-
case 17: return [2 /*return*/];
|
|
1678
|
-
}
|
|
1679
|
-
});
|
|
1680
|
-
});
|
|
1681
|
-
};
|
|
1682
|
-
return rowHelperImplementation;
|
|
1683
|
-
}(rowHelperBase));
|
|
1684
|
-
exports.rowHelperImplementation = rowHelperImplementation;
|
|
1685
|
-
var controllerColumns = Symbol("controllerColumns");
|
|
891
|
+
}
|
|
892
|
+
async __performColumnAndEntityValidations() {
|
|
893
|
+
for (const c of this.columnsInfo) {
|
|
894
|
+
if (c.validate) {
|
|
895
|
+
let col = new FieldRefImplementation(c, this.info.fields[c.key], this.instance, this, this);
|
|
896
|
+
await col.__performValidation();
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
if (this.info.entityInfo.validation)
|
|
900
|
+
await this.info.entityInfo.validation(this.instance, this);
|
|
901
|
+
if (this.repository.listeners)
|
|
902
|
+
for (const listener of this.repository.listeners.filter(x => x.validating)) {
|
|
903
|
+
await listener.validating(this.instance);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
const controllerColumns = Symbol("controllerColumns");
|
|
1686
908
|
function prepareColumnInfo(r, remult) {
|
|
1687
|
-
return r.map(
|
|
909
|
+
return r.map(x => decorateColumnSettings(x.settings(remult), remult));
|
|
1688
910
|
}
|
|
1689
|
-
function getFields(container, remult) {
|
|
911
|
+
export function getFields(container, remult) {
|
|
1690
912
|
return getControllerRef(container, remult).fields;
|
|
1691
913
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
var result = container[controllerColumns];
|
|
914
|
+
export function getControllerRef(container, remult) {
|
|
915
|
+
let result = container[controllerColumns];
|
|
1695
916
|
if (!result)
|
|
1696
917
|
result = container[entityMember];
|
|
1697
918
|
if (!result) {
|
|
1698
|
-
|
|
1699
|
-
if (!
|
|
1700
|
-
|
|
1701
|
-
|
|
919
|
+
let columnSettings = columnsOfType.get(container.constructor);
|
|
920
|
+
if (!columnSettings)
|
|
921
|
+
columnsOfType.set(container.constructor, columnSettings = []);
|
|
922
|
+
let base = Object.getPrototypeOf(container.constructor);
|
|
1702
923
|
while (base != null) {
|
|
1703
|
-
|
|
924
|
+
let baseCols = columnsOfType.get(base);
|
|
1704
925
|
if (baseCols) {
|
|
1705
|
-
|
|
926
|
+
columnSettings.unshift(...baseCols.filter(x => !columnSettings.find(y => y.key == x.key)));
|
|
1706
927
|
}
|
|
1707
928
|
base = Object.getPrototypeOf(base);
|
|
1708
929
|
}
|
|
1709
|
-
container[controllerColumns] = result = new controllerRefImpl(prepareColumnInfo(
|
|
930
|
+
container[controllerColumns] = result = new controllerRefImpl(prepareColumnInfo(columnSettings, remult), container, remult);
|
|
1710
931
|
}
|
|
1711
932
|
return result;
|
|
1712
933
|
}
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
_a.toArray = function () { return _items; },
|
|
1725
|
-
_a);
|
|
1726
|
-
try {
|
|
1727
|
-
for (var columnsInfo_2 = tslib_1.__values(columnsInfo), columnsInfo_2_1 = columnsInfo_2.next(); !columnsInfo_2_1.done; columnsInfo_2_1 = columnsInfo_2.next()) {
|
|
1728
|
-
var col = columnsInfo_2_1.value;
|
|
1729
|
-
_items.push(r[col.key] = new FieldRefImplementation(col, new columnDefsImpl(col, undefined, remult), instance, undefined, _this));
|
|
1730
|
-
}
|
|
934
|
+
export class controllerRefImpl extends rowHelperBase {
|
|
935
|
+
constructor(columnsInfo, instance, remult) {
|
|
936
|
+
super(columnsInfo, instance, remult);
|
|
937
|
+
let _items = [];
|
|
938
|
+
let r = {
|
|
939
|
+
find: (c) => r[typeof c === "string" ? c : c.key],
|
|
940
|
+
[Symbol.iterator]: () => _items[Symbol.iterator](),
|
|
941
|
+
toArray: () => _items
|
|
942
|
+
};
|
|
943
|
+
for (const col of columnsInfo) {
|
|
944
|
+
_items.push(r[col.key] = new FieldRefImplementation(col, new columnDefsImpl(col, undefined, remult), instance, undefined, this));
|
|
1731
945
|
}
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
946
|
+
this.fields = r;
|
|
947
|
+
}
|
|
948
|
+
async __performColumnAndEntityValidations() {
|
|
949
|
+
for (const col of this.fields) {
|
|
950
|
+
if (col instanceof FieldRefImplementation) {
|
|
951
|
+
await col.__performValidation();
|
|
1736
952
|
}
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
controllerRefImpl.prototype.__performColumnAndEntityValidations = function () {
|
|
1743
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1744
|
-
var _a, _b, col, e_30_1;
|
|
1745
|
-
var e_30, _c;
|
|
1746
|
-
return tslib_1.__generator(this, function (_d) {
|
|
1747
|
-
switch (_d.label) {
|
|
1748
|
-
case 0:
|
|
1749
|
-
_d.trys.push([0, 5, 6, 7]);
|
|
1750
|
-
_a = tslib_1.__values(this.fields), _b = _a.next();
|
|
1751
|
-
_d.label = 1;
|
|
1752
|
-
case 1:
|
|
1753
|
-
if (!!_b.done) return [3 /*break*/, 4];
|
|
1754
|
-
col = _b.value;
|
|
1755
|
-
if (!(col instanceof FieldRefImplementation)) return [3 /*break*/, 3];
|
|
1756
|
-
return [4 /*yield*/, col.__performValidation()];
|
|
1757
|
-
case 2:
|
|
1758
|
-
_d.sent();
|
|
1759
|
-
_d.label = 3;
|
|
1760
|
-
case 3:
|
|
1761
|
-
_b = _a.next();
|
|
1762
|
-
return [3 /*break*/, 1];
|
|
1763
|
-
case 4: return [3 /*break*/, 7];
|
|
1764
|
-
case 5:
|
|
1765
|
-
e_30_1 = _d.sent();
|
|
1766
|
-
e_30 = { error: e_30_1 };
|
|
1767
|
-
return [3 /*break*/, 7];
|
|
1768
|
-
case 6:
|
|
1769
|
-
try {
|
|
1770
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1771
|
-
}
|
|
1772
|
-
finally { if (e_30) throw e_30.error; }
|
|
1773
|
-
return [7 /*endfinally*/];
|
|
1774
|
-
case 7: return [2 /*return*/];
|
|
1775
|
-
}
|
|
1776
|
-
});
|
|
1777
|
-
});
|
|
1778
|
-
};
|
|
1779
|
-
return controllerRefImpl;
|
|
1780
|
-
}(rowHelperBase));
|
|
1781
|
-
exports.controllerRefImpl = controllerRefImpl;
|
|
1782
|
-
var FieldRefImplementation = /** @class */ (function () {
|
|
1783
|
-
function FieldRefImplementation(settings, metadata, container, helper, rowBase) {
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
export class FieldRefImplementation {
|
|
957
|
+
constructor(settings, metadata, container, helper, rowBase) {
|
|
1784
958
|
this.settings = settings;
|
|
1785
959
|
this.metadata = metadata;
|
|
1786
960
|
this.container = container;
|
|
@@ -1789,249 +963,166 @@ var FieldRefImplementation = /** @class */ (function () {
|
|
|
1789
963
|
this.target = this.settings.target;
|
|
1790
964
|
this.entityRef = this.helper;
|
|
1791
965
|
}
|
|
1792
|
-
|
|
966
|
+
subscribe(listener) {
|
|
1793
967
|
if (!this._subscribers) {
|
|
1794
968
|
this.rowBase.initSubscribers();
|
|
1795
969
|
}
|
|
1796
970
|
return this._subscribers.subscribe(listener);
|
|
1797
|
-
}
|
|
1798
|
-
|
|
971
|
+
}
|
|
972
|
+
valueIsNull() {
|
|
1799
973
|
this.reportObserved();
|
|
1800
|
-
|
|
974
|
+
let lu = this.rowBase.lookups.get(this.metadata.key);
|
|
1801
975
|
if (lu) {
|
|
1802
976
|
return lu.id === undefined || lu.id === null;
|
|
1803
977
|
}
|
|
1804
978
|
return this.value === null;
|
|
1805
|
-
}
|
|
1806
|
-
|
|
979
|
+
}
|
|
980
|
+
originalValueIsNull() {
|
|
1807
981
|
this.reportObserved();
|
|
1808
|
-
|
|
982
|
+
let lu = this.rowBase.lookups.get(this.metadata.key);
|
|
1809
983
|
return this.rawOriginalValue() === null;
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
case 0:
|
|
1817
|
-
lu = this.rowBase.lookups.get(this.metadata.key);
|
|
1818
|
-
if (!lu) return [3 /*break*/, 4];
|
|
1819
|
-
if (!this.valueChanged()) return [3 /*break*/, 2];
|
|
1820
|
-
return [4 /*yield*/, lu.waitLoadOf(this.rawOriginalValue())];
|
|
1821
|
-
case 1:
|
|
1822
|
-
_a.sent();
|
|
1823
|
-
_a.label = 2;
|
|
1824
|
-
case 2: return [4 /*yield*/, lu.waitLoad()];
|
|
1825
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
1826
|
-
case 4: return [2 /*return*/, this.value];
|
|
1827
|
-
}
|
|
1828
|
-
});
|
|
1829
|
-
});
|
|
1830
|
-
};
|
|
1831
|
-
FieldRefImplementation.prototype.reportObserved = function () {
|
|
1832
|
-
var _a, _b;
|
|
1833
|
-
(_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportObserved();
|
|
1834
|
-
(_b = this.rowBase._subscribers) === null || _b === void 0 ? void 0 : _b.reportObserved();
|
|
1835
|
-
};
|
|
1836
|
-
FieldRefImplementation.prototype.reportChanged = function () {
|
|
1837
|
-
var _a, _b;
|
|
1838
|
-
(_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportChanged();
|
|
1839
|
-
(_b = this.rowBase._subscribers) === null || _b === void 0 ? void 0 : _b.reportChanged();
|
|
1840
|
-
};
|
|
1841
|
-
Object.defineProperty(FieldRefImplementation.prototype, "error", {
|
|
1842
|
-
get: function () {
|
|
1843
|
-
this.reportObserved();
|
|
1844
|
-
if (!this.rowBase.errors)
|
|
1845
|
-
return undefined;
|
|
1846
|
-
return this.rowBase.errors[this.metadata.key];
|
|
1847
|
-
},
|
|
1848
|
-
set: function (error) {
|
|
1849
|
-
if (!this.rowBase.errors)
|
|
1850
|
-
this.rowBase.errors = {};
|
|
1851
|
-
this.rowBase.errors[this.metadata.key] = error;
|
|
1852
|
-
this.reportChanged();
|
|
1853
|
-
},
|
|
1854
|
-
enumerable: false,
|
|
1855
|
-
configurable: true
|
|
1856
|
-
});
|
|
1857
|
-
Object.defineProperty(FieldRefImplementation.prototype, "displayValue", {
|
|
1858
|
-
get: function () {
|
|
1859
|
-
this.reportObserved();
|
|
1860
|
-
if (this.value != undefined) {
|
|
1861
|
-
if (this.settings.displayValue)
|
|
1862
|
-
return this.settings.displayValue(this.container, this.value);
|
|
1863
|
-
else if (this.metadata.valueConverter.displayValue)
|
|
1864
|
-
return this.metadata.valueConverter.displayValue(this.value);
|
|
1865
|
-
else
|
|
1866
|
-
return this.value.toString();
|
|
984
|
+
}
|
|
985
|
+
async load() {
|
|
986
|
+
let lu = this.rowBase.lookups.get(this.metadata.key);
|
|
987
|
+
if (lu) {
|
|
988
|
+
if (this.valueChanged()) {
|
|
989
|
+
await lu.waitLoadOf(this.rawOriginalValue());
|
|
1867
990
|
}
|
|
1868
|
-
return
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
991
|
+
return await lu.waitLoad();
|
|
992
|
+
}
|
|
993
|
+
return this.value;
|
|
994
|
+
}
|
|
995
|
+
reportObserved() {
|
|
996
|
+
this._subscribers?.reportObserved();
|
|
997
|
+
this.rowBase._subscribers?.reportObserved();
|
|
998
|
+
}
|
|
999
|
+
reportChanged() {
|
|
1000
|
+
this._subscribers?.reportChanged();
|
|
1001
|
+
this.rowBase._subscribers?.reportChanged();
|
|
1002
|
+
}
|
|
1003
|
+
get error() {
|
|
1004
|
+
this.reportObserved();
|
|
1005
|
+
if (!this.rowBase.errors)
|
|
1006
|
+
return undefined;
|
|
1007
|
+
return this.rowBase.errors[this.metadata.key];
|
|
1008
|
+
}
|
|
1009
|
+
set error(error) {
|
|
1010
|
+
if (!this.rowBase.errors)
|
|
1011
|
+
this.rowBase.errors = {};
|
|
1012
|
+
this.rowBase.errors[this.metadata.key] = error;
|
|
1013
|
+
this.reportChanged();
|
|
1014
|
+
}
|
|
1015
|
+
get displayValue() {
|
|
1016
|
+
this.reportObserved();
|
|
1017
|
+
if (this.value != undefined) {
|
|
1018
|
+
if (this.settings.displayValue)
|
|
1019
|
+
return this.settings.displayValue(this.container, this.value);
|
|
1020
|
+
else if (this.metadata.valueConverter.displayValue)
|
|
1021
|
+
return this.metadata.valueConverter.displayValue(this.value);
|
|
1022
|
+
else
|
|
1023
|
+
return this.value.toString();
|
|
1024
|
+
}
|
|
1025
|
+
return "";
|
|
1026
|
+
}
|
|
1873
1027
|
;
|
|
1874
|
-
|
|
1875
|
-
get: function () { return this.container[this.metadata.key]; },
|
|
1876
|
-
set: function (value) { this.container[this.metadata.key] = value; },
|
|
1877
|
-
enumerable: false,
|
|
1878
|
-
configurable: true
|
|
1879
|
-
});
|
|
1028
|
+
get value() { return this.container[this.metadata.key]; }
|
|
1880
1029
|
;
|
|
1030
|
+
set value(value) { this.container[this.metadata.key] = value; }
|
|
1881
1031
|
;
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
},
|
|
1890
|
-
enumerable: false,
|
|
1891
|
-
configurable: true
|
|
1892
|
-
});
|
|
1032
|
+
get originalValue() {
|
|
1033
|
+
this.reportObserved();
|
|
1034
|
+
let lu = this.rowBase.lookups.get(this.metadata.key);
|
|
1035
|
+
if (lu)
|
|
1036
|
+
return lu.get(this.rawOriginalValue());
|
|
1037
|
+
return this.rowBase.originalValues[this.metadata.key];
|
|
1038
|
+
}
|
|
1893
1039
|
;
|
|
1894
|
-
|
|
1040
|
+
rawOriginalValue() {
|
|
1895
1041
|
return this.rowBase.originalValues[this.metadata.key];
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1042
|
+
}
|
|
1043
|
+
setId(id) {
|
|
1898
1044
|
this.value = id;
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
|
|
1045
|
+
}
|
|
1046
|
+
getId() {
|
|
1047
|
+
let lu = this.rowBase.lookups.get(this.metadata.key);
|
|
1902
1048
|
if (lu)
|
|
1903
1049
|
return lu.id != undefined ? lu.id : null;
|
|
1904
1050
|
return this.value;
|
|
1905
|
-
}
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
},
|
|
1922
|
-
enumerable: false,
|
|
1923
|
-
configurable: true
|
|
1924
|
-
});
|
|
1051
|
+
}
|
|
1052
|
+
get inputValue() {
|
|
1053
|
+
this.reportObserved();
|
|
1054
|
+
let lu = this.rowBase.lookups.get(this.metadata.key);
|
|
1055
|
+
if (lu)
|
|
1056
|
+
return lu.id != undefined ? lu.id.toString() : null;
|
|
1057
|
+
return this.metadata.valueConverter.toInput(this.value, this.settings.inputType);
|
|
1058
|
+
}
|
|
1059
|
+
set inputValue(val) {
|
|
1060
|
+
let lu = this.rowBase.lookups.get(this.metadata.key);
|
|
1061
|
+
if (lu) {
|
|
1062
|
+
lu.setId(val);
|
|
1063
|
+
}
|
|
1064
|
+
else
|
|
1065
|
+
this.value = this.metadata.valueConverter.fromInput(val, this.settings.inputType);
|
|
1066
|
+
}
|
|
1925
1067
|
;
|
|
1926
|
-
|
|
1068
|
+
valueChanged() {
|
|
1927
1069
|
this.reportObserved();
|
|
1928
|
-
|
|
1929
|
-
|
|
1070
|
+
let val = this.value;
|
|
1071
|
+
let lu = this.rowBase.lookups.get(this.metadata.key);
|
|
1930
1072
|
if (lu) {
|
|
1931
1073
|
val = lu.id;
|
|
1932
1074
|
}
|
|
1933
1075
|
return JSON.stringify(this.metadata.valueConverter.toJson(this.rowBase.originalValues[this.metadata.key])) != JSON.stringify(this.metadata.valueConverter.toJson(val));
|
|
1934
|
-
}
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
case 0:
|
|
1942
|
-
_d.trys.push([0, 12, , 13]);
|
|
1943
|
-
x = typeof (this.settings.validate);
|
|
1944
|
-
if (!Array.isArray(this.settings.validate)) return [3 /*break*/, 9];
|
|
1945
|
-
_d.label = 1;
|
|
1946
|
-
case 1:
|
|
1947
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
1948
|
-
_a = tslib_1.__values(this.settings.validate), _b = _a.next();
|
|
1949
|
-
_d.label = 2;
|
|
1950
|
-
case 2:
|
|
1951
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
1952
|
-
v = _b.value;
|
|
1953
|
-
return [4 /*yield*/, v(this.container, this)];
|
|
1954
|
-
case 3:
|
|
1955
|
-
_d.sent();
|
|
1956
|
-
_d.label = 4;
|
|
1957
|
-
case 4:
|
|
1958
|
-
_b = _a.next();
|
|
1959
|
-
return [3 /*break*/, 2];
|
|
1960
|
-
case 5: return [3 /*break*/, 8];
|
|
1961
|
-
case 6:
|
|
1962
|
-
e_31_1 = _d.sent();
|
|
1963
|
-
e_31 = { error: e_31_1 };
|
|
1964
|
-
return [3 /*break*/, 8];
|
|
1965
|
-
case 7:
|
|
1966
|
-
try {
|
|
1967
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1968
|
-
}
|
|
1969
|
-
finally { if (e_31) throw e_31.error; }
|
|
1970
|
-
return [7 /*endfinally*/];
|
|
1971
|
-
case 8: return [3 /*break*/, 11];
|
|
1972
|
-
case 9:
|
|
1973
|
-
if (!(typeof this.settings.validate === 'function')) return [3 /*break*/, 11];
|
|
1974
|
-
return [4 /*yield*/, this.settings.validate(this.container, this)];
|
|
1975
|
-
case 10:
|
|
1976
|
-
_d.sent();
|
|
1977
|
-
_d.label = 11;
|
|
1978
|
-
case 11: return [3 /*break*/, 13];
|
|
1979
|
-
case 12:
|
|
1980
|
-
error_1 = _d.sent();
|
|
1981
|
-
if (typeof error_1 === "string")
|
|
1982
|
-
this.error = error_1;
|
|
1983
|
-
else
|
|
1984
|
-
this.error = error_1.message;
|
|
1985
|
-
return [3 /*break*/, 13];
|
|
1986
|
-
case 13: return [2 /*return*/];
|
|
1987
|
-
}
|
|
1988
|
-
});
|
|
1989
|
-
});
|
|
1990
|
-
};
|
|
1991
|
-
FieldRefImplementation.prototype.validate = function () {
|
|
1992
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1993
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1994
|
-
switch (_a.label) {
|
|
1995
|
-
case 0: return [4 /*yield*/, this.__performValidation()];
|
|
1996
|
-
case 1:
|
|
1997
|
-
_a.sent();
|
|
1998
|
-
return [2 /*return*/, !!!this.error];
|
|
1076
|
+
}
|
|
1077
|
+
async __performValidation() {
|
|
1078
|
+
try {
|
|
1079
|
+
let x = typeof (this.settings.validate);
|
|
1080
|
+
if (Array.isArray(this.settings.validate)) {
|
|
1081
|
+
for (const v of this.settings.validate) {
|
|
1082
|
+
await v(this.container, this);
|
|
1999
1083
|
}
|
|
2000
|
-
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
1084
|
+
}
|
|
1085
|
+
else if (typeof this.settings.validate === 'function')
|
|
1086
|
+
await this.settings.validate(this.container, this);
|
|
1087
|
+
}
|
|
1088
|
+
catch (error) {
|
|
1089
|
+
if (typeof error === "string")
|
|
1090
|
+
this.error = error;
|
|
1091
|
+
else
|
|
1092
|
+
this.error = error.message;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
async validate() {
|
|
1096
|
+
await this.__performValidation();
|
|
1097
|
+
return !!!this.error;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
export function getEntityRef(entity, throwException = true) {
|
|
1101
|
+
let x = entity[entityMember];
|
|
2009
1102
|
if (!x && throwException)
|
|
2010
1103
|
throw new Error("item " + entity.constructor.name + " was not initialized using a context");
|
|
2011
1104
|
return x;
|
|
2012
1105
|
}
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
transformCaption: function (remult, key, caption) { return caption; }
|
|
1106
|
+
export const CaptionTransformer = {
|
|
1107
|
+
transformCaption: (remult, key, caption) => caption
|
|
2016
1108
|
};
|
|
2017
|
-
function buildCaption(caption, key, remult) {
|
|
2018
|
-
|
|
1109
|
+
export function buildCaption(caption, key, remult) {
|
|
1110
|
+
let result;
|
|
2019
1111
|
if (typeof (caption) === "function") {
|
|
2020
1112
|
if (remult)
|
|
2021
1113
|
result = caption(remult);
|
|
2022
1114
|
}
|
|
2023
1115
|
else if (caption)
|
|
2024
1116
|
result = caption;
|
|
2025
|
-
result =
|
|
1117
|
+
result = CaptionTransformer.transformCaption(remult, key, result);
|
|
2026
1118
|
if (result)
|
|
2027
1119
|
return result;
|
|
2028
1120
|
if (key)
|
|
2029
|
-
return
|
|
1121
|
+
return makeTitle(key);
|
|
2030
1122
|
return '';
|
|
2031
1123
|
}
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
function columnDefsImpl(settings, entityDefs, remult) {
|
|
1124
|
+
export class columnDefsImpl {
|
|
1125
|
+
constructor(settings, entityDefs, remult) {
|
|
2035
1126
|
this.settings = settings;
|
|
2036
1127
|
this.entityDefs = entityDefs;
|
|
2037
1128
|
this.options = this.settings;
|
|
@@ -2049,60 +1140,45 @@ var columnDefsImpl = /** @class */ (function () {
|
|
|
2049
1140
|
this.inputType = this.valueConverter.inputType;
|
|
2050
1141
|
this.caption = buildCaption(settings.caption, settings.key, remult);
|
|
2051
1142
|
}
|
|
2052
|
-
|
|
2053
|
-
var _this = this;
|
|
1143
|
+
getDbName() {
|
|
2054
1144
|
if (this.dbNamePromise)
|
|
2055
1145
|
return this.dbNamePromise;
|
|
2056
|
-
this.dbNamePromise = (
|
|
2057
|
-
return tslib_1.__generator(this, function (_a) {
|
|
2058
|
-
if (this.settings.sqlExpression) {
|
|
2059
|
-
if (typeof this.settings.sqlExpression === "function") {
|
|
2060
|
-
return [2 /*return*/, this.settings.sqlExpression(this.entityDefs)];
|
|
2061
|
-
}
|
|
2062
|
-
else
|
|
2063
|
-
return [2 /*return*/, this.settings.sqlExpression];
|
|
2064
|
-
}
|
|
2065
|
-
return [2 /*return*/, this.settings.dbName];
|
|
2066
|
-
});
|
|
2067
|
-
}); })().then(function (x) {
|
|
2068
|
-
if (x)
|
|
2069
|
-
return x;
|
|
2070
|
-
return _this.settings.dbName;
|
|
2071
|
-
});
|
|
2072
|
-
return this.dbNamePromise;
|
|
2073
|
-
};
|
|
2074
|
-
Object.defineProperty(columnDefsImpl.prototype, "dbName", {
|
|
2075
|
-
get: function () {
|
|
2076
|
-
var result;
|
|
1146
|
+
this.dbNamePromise = (async () => {
|
|
2077
1147
|
if (this.settings.sqlExpression) {
|
|
2078
1148
|
if (typeof this.settings.sqlExpression === "function") {
|
|
2079
|
-
|
|
1149
|
+
return this.settings.sqlExpression(this.entityDefs);
|
|
2080
1150
|
}
|
|
2081
1151
|
else
|
|
2082
|
-
|
|
1152
|
+
return this.settings.sqlExpression;
|
|
2083
1153
|
}
|
|
2084
|
-
if (result)
|
|
2085
|
-
return result;
|
|
2086
1154
|
return this.settings.dbName;
|
|
2087
|
-
}
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
1155
|
+
})().then(x => {
|
|
1156
|
+
if (x)
|
|
1157
|
+
return x;
|
|
1158
|
+
return this.settings.dbName;
|
|
1159
|
+
});
|
|
1160
|
+
return this.dbNamePromise;
|
|
1161
|
+
}
|
|
1162
|
+
get dbName() {
|
|
1163
|
+
let result;
|
|
1164
|
+
if (this.settings.sqlExpression) {
|
|
1165
|
+
if (typeof this.settings.sqlExpression === "function") {
|
|
1166
|
+
result = this.settings.sqlExpression(this.entityDefs);
|
|
1167
|
+
}
|
|
1168
|
+
else
|
|
1169
|
+
result = this.settings.sqlExpression;
|
|
1170
|
+
}
|
|
1171
|
+
if (result)
|
|
1172
|
+
return result;
|
|
1173
|
+
return this.settings.dbName;
|
|
1174
|
+
}
|
|
1175
|
+
get dbReadOnly() {
|
|
1176
|
+
return this.settings.dbReadOnly;
|
|
1177
|
+
}
|
|
2098
1178
|
;
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
var EntityFullInfo = /** @class */ (function () {
|
|
2103
|
-
function EntityFullInfo(columnsInfo, entityInfo, remult, entityType, key) {
|
|
2104
|
-
var _a, e_32, _b;
|
|
2105
|
-
var _this = this;
|
|
1179
|
+
}
|
|
1180
|
+
class EntityFullInfo {
|
|
1181
|
+
constructor(columnsInfo, entityInfo, remult, entityType, key) {
|
|
2106
1182
|
this.columnsInfo = columnsInfo;
|
|
2107
1183
|
this.entityInfo = entityInfo;
|
|
2108
1184
|
this.remult = remult;
|
|
@@ -2111,35 +1187,30 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
2111
1187
|
this.options = this.entityInfo;
|
|
2112
1188
|
this.idMetadata = {
|
|
2113
1189
|
field: undefined,
|
|
2114
|
-
createIdInFilter:
|
|
1190
|
+
createIdInFilter: (items) => {
|
|
2115
1191
|
if (items.length > 0)
|
|
2116
1192
|
return {
|
|
2117
|
-
$or: items.map(
|
|
1193
|
+
$or: items.map(x => this.idMetadata.getIdFilter(getEntityRef(x).getId()))
|
|
2118
1194
|
};
|
|
2119
1195
|
},
|
|
2120
|
-
isIdField:
|
|
2121
|
-
return col.key ==
|
|
1196
|
+
isIdField: (col) => {
|
|
1197
|
+
return col.key == this.idMetadata.field.key;
|
|
2122
1198
|
},
|
|
2123
|
-
getIdFilter:
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2127
|
-
ids[_i] = arguments[_i];
|
|
2128
|
-
}
|
|
2129
|
-
if (_this.idMetadata.field instanceof column_1.CompoundIdField) {
|
|
2130
|
-
var field_1 = _this.idMetadata.field;
|
|
1199
|
+
getIdFilter: (...ids) => {
|
|
1200
|
+
if (this.idMetadata.field instanceof CompoundIdField) {
|
|
1201
|
+
let field = this.idMetadata.field;
|
|
2131
1202
|
return {
|
|
2132
|
-
$or: ids.map(
|
|
1203
|
+
$or: ids.map(x => field.isEqualTo(x))
|
|
2133
1204
|
};
|
|
2134
1205
|
}
|
|
2135
1206
|
if (ids.length == 1)
|
|
2136
|
-
return
|
|
2137
|
-
|
|
2138
|
-
|
|
1207
|
+
return {
|
|
1208
|
+
[this.idMetadata.field.key]: ids[0]
|
|
1209
|
+
};
|
|
2139
1210
|
else
|
|
2140
|
-
return
|
|
2141
|
-
|
|
2142
|
-
|
|
1211
|
+
return {
|
|
1212
|
+
[this.idMetadata.field.key]: ids
|
|
1213
|
+
};
|
|
2143
1214
|
}
|
|
2144
1215
|
};
|
|
2145
1216
|
if (this.options.allowApiCrud !== undefined) {
|
|
@@ -2158,25 +1229,14 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
2158
1229
|
this.key = entityType.name;
|
|
2159
1230
|
if (!entityInfo.dbName)
|
|
2160
1231
|
entityInfo.dbName = this.key;
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
for (var columnsInfo_3 = tslib_1.__values(columnsInfo), columnsInfo_3_1 = columnsInfo_3.next(); !columnsInfo_3_1.done; columnsInfo_3_1 = columnsInfo_3.next()) {
|
|
2170
|
-
var x = columnsInfo_3_1.value;
|
|
2171
|
-
_items.push(r[x.key] = new columnDefsImpl(x, this, remult));
|
|
2172
|
-
}
|
|
2173
|
-
}
|
|
2174
|
-
catch (e_32_1) { e_32 = { error: e_32_1 }; }
|
|
2175
|
-
finally {
|
|
2176
|
-
try {
|
|
2177
|
-
if (columnsInfo_3_1 && !columnsInfo_3_1.done && (_b = columnsInfo_3.return)) _b.call(columnsInfo_3);
|
|
2178
|
-
}
|
|
2179
|
-
finally { if (e_32) throw e_32.error; }
|
|
1232
|
+
let _items = [];
|
|
1233
|
+
let r = {
|
|
1234
|
+
find: (c) => r[typeof c === "string" ? c : c.key],
|
|
1235
|
+
[Symbol.iterator]: () => _items[Symbol.iterator](),
|
|
1236
|
+
toArray: () => _items
|
|
1237
|
+
};
|
|
1238
|
+
for (const x of columnsInfo) {
|
|
1239
|
+
_items.push(r[x.key] = new columnDefsImpl(x, this, remult));
|
|
2180
1240
|
}
|
|
2181
1241
|
this.fields = r;
|
|
2182
1242
|
this.caption = buildCaption(entityInfo.caption, this.key, remult);
|
|
@@ -2187,31 +1247,14 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
2187
1247
|
if (this.fields["id"])
|
|
2188
1248
|
this.idMetadata.field = this.fields["id"];
|
|
2189
1249
|
else
|
|
2190
|
-
this.idMetadata.field =
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
Object.defineProperty(EntityFullInfo.prototype, "apiReadAllowed", {
|
|
2199
|
-
get: function () { return this.remult.isAllowed(this.options.allowApiRead); },
|
|
2200
|
-
enumerable: false,
|
|
2201
|
-
configurable: true
|
|
2202
|
-
});
|
|
2203
|
-
Object.defineProperty(EntityFullInfo.prototype, "apiDeleteAllowed", {
|
|
2204
|
-
get: function () { return this.remult.isAllowedForInstance(undefined, this.options.allowApiDelete); },
|
|
2205
|
-
enumerable: false,
|
|
2206
|
-
configurable: true
|
|
2207
|
-
});
|
|
2208
|
-
Object.defineProperty(EntityFullInfo.prototype, "apiInsertAllowed", {
|
|
2209
|
-
get: function () { return this.remult.isAllowedForInstance(undefined, this.options.allowApiInsert); },
|
|
2210
|
-
enumerable: false,
|
|
2211
|
-
configurable: true
|
|
2212
|
-
});
|
|
2213
|
-
EntityFullInfo.prototype.getDbName = function () {
|
|
2214
|
-
var _this = this;
|
|
1250
|
+
this.idMetadata.field = [...this.fields][0];
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
get apiUpdateAllowed() { return this.remult.isAllowedForInstance(undefined, this.options.allowApiUpdate); }
|
|
1254
|
+
get apiReadAllowed() { return this.remult.isAllowed(this.options.allowApiRead); }
|
|
1255
|
+
get apiDeleteAllowed() { return this.remult.isAllowedForInstance(undefined, this.options.allowApiDelete); }
|
|
1256
|
+
get apiInsertAllowed() { return this.remult.isAllowedForInstance(undefined, this.options.allowApiInsert); }
|
|
1257
|
+
getDbName() {
|
|
2215
1258
|
if (this.dbNamePromise)
|
|
2216
1259
|
return this.dbNamePromise;
|
|
2217
1260
|
if (!this.options.sqlExpression) {
|
|
@@ -2220,151 +1263,96 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
2220
1263
|
if (typeof this.options.sqlExpression === "string")
|
|
2221
1264
|
this.dbNamePromise = Promise.resolve(this.options.sqlExpression);
|
|
2222
1265
|
else if (typeof this.options.sqlExpression === "function") {
|
|
2223
|
-
|
|
1266
|
+
let r = this.options.sqlExpression(this.fields);
|
|
2224
1267
|
if (r instanceof Promise)
|
|
2225
1268
|
this.dbNamePromise = r;
|
|
2226
1269
|
else if (r)
|
|
2227
1270
|
this.dbNamePromise = Promise.resolve(r);
|
|
2228
1271
|
}
|
|
2229
|
-
this.dbNamePromise = this.dbNamePromise.then(
|
|
1272
|
+
this.dbNamePromise = this.dbNamePromise.then(x => {
|
|
2230
1273
|
if (!x)
|
|
2231
|
-
return
|
|
1274
|
+
return this.options.dbName;
|
|
2232
1275
|
return x;
|
|
2233
1276
|
});
|
|
2234
1277
|
return this.dbNamePromise;
|
|
2235
|
-
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
var options = [];
|
|
2240
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2241
|
-
options[_i] = arguments[_i];
|
|
2242
|
-
}
|
|
2243
|
-
return function (target) {
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
export function FieldType(...options) {
|
|
1281
|
+
return target => {
|
|
2244
1282
|
if (!options) {
|
|
2245
1283
|
options = [];
|
|
2246
1284
|
}
|
|
2247
1285
|
options.splice(0, 0, { valueType: target });
|
|
2248
|
-
Reflect.defineMetadata(
|
|
1286
|
+
Reflect.defineMetadata(storableMember, options, target);
|
|
2249
1287
|
return target;
|
|
2250
1288
|
};
|
|
2251
1289
|
}
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
1290
|
+
export class Fields {
|
|
1291
|
+
static object(...options) {
|
|
1292
|
+
return Field(undefined, ...options);
|
|
1293
|
+
}
|
|
1294
|
+
static dateOnly(...options) {
|
|
1295
|
+
return Field(() => Date, {
|
|
1296
|
+
valueConverter: ValueConverters.DateOnly
|
|
1297
|
+
}, ...options);
|
|
1298
|
+
}
|
|
1299
|
+
static date(...options) {
|
|
1300
|
+
return Field(() => Date, ...options);
|
|
1301
|
+
}
|
|
1302
|
+
static integer(...options) {
|
|
1303
|
+
return Field(() => Number, {
|
|
1304
|
+
valueConverter: ValueConverters.Integer
|
|
1305
|
+
}, ...options);
|
|
1306
|
+
}
|
|
1307
|
+
static autoIncrement(...options) {
|
|
1308
|
+
return Field(() => Number, {
|
|
1309
|
+
allowApiUpdate: false,
|
|
1310
|
+
dbReadOnly: true,
|
|
1311
|
+
valueConverter: { ...ValueConverters.Integer, fieldTypeInDb: 'autoincrement' }
|
|
1312
|
+
}, ...options);
|
|
1313
|
+
}
|
|
1314
|
+
static number(...options) {
|
|
1315
|
+
return Field(() => Number, ...options);
|
|
1316
|
+
}
|
|
1317
|
+
static uuid(...options) {
|
|
1318
|
+
return Field(() => String, {
|
|
1319
|
+
allowApiUpdate: false,
|
|
1320
|
+
defaultValue: () => uuid()
|
|
1321
|
+
}, ...options);
|
|
1322
|
+
}
|
|
1323
|
+
static string(...options) {
|
|
1324
|
+
return Field(() => String, ...options);
|
|
1325
|
+
}
|
|
1326
|
+
static boolean(...options) {
|
|
1327
|
+
return Field(() => Boolean, ...options);
|
|
2255
1328
|
}
|
|
2256
|
-
Fields.object = function () {
|
|
2257
|
-
var options = [];
|
|
2258
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2259
|
-
options[_i] = arguments[_i];
|
|
2260
|
-
}
|
|
2261
|
-
return Field.apply(void 0, tslib_1.__spread([undefined], options));
|
|
2262
|
-
};
|
|
2263
|
-
Fields.dateOnly = function () {
|
|
2264
|
-
var options = [];
|
|
2265
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2266
|
-
options[_i] = arguments[_i];
|
|
2267
|
-
}
|
|
2268
|
-
return Field.apply(void 0, tslib_1.__spread([function () { return Date; }, {
|
|
2269
|
-
valueConverter: valueConverters_1.ValueConverters.DateOnly
|
|
2270
|
-
}], options));
|
|
2271
|
-
};
|
|
2272
|
-
Fields.date = function () {
|
|
2273
|
-
var options = [];
|
|
2274
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2275
|
-
options[_i] = arguments[_i];
|
|
2276
|
-
}
|
|
2277
|
-
return Field.apply(void 0, tslib_1.__spread([function () { return Date; }], options));
|
|
2278
|
-
};
|
|
2279
|
-
Fields.integer = function () {
|
|
2280
|
-
var options = [];
|
|
2281
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2282
|
-
options[_i] = arguments[_i];
|
|
2283
|
-
}
|
|
2284
|
-
return Field.apply(void 0, tslib_1.__spread([function () { return Number; }, {
|
|
2285
|
-
valueConverter: valueConverters_1.ValueConverters.Integer
|
|
2286
|
-
}], options));
|
|
2287
|
-
};
|
|
2288
|
-
Fields.autoIncrement = function () {
|
|
2289
|
-
var options = [];
|
|
2290
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2291
|
-
options[_i] = arguments[_i];
|
|
2292
|
-
}
|
|
2293
|
-
return Field.apply(void 0, tslib_1.__spread([function () { return Number; }, {
|
|
2294
|
-
allowApiUpdate: false,
|
|
2295
|
-
dbReadOnly: true,
|
|
2296
|
-
valueConverter: tslib_1.__assign(tslib_1.__assign({}, valueConverters_1.ValueConverters.Integer), { fieldTypeInDb: 'autoincrement' })
|
|
2297
|
-
}], options));
|
|
2298
|
-
};
|
|
2299
|
-
Fields.number = function () {
|
|
2300
|
-
var options = [];
|
|
2301
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2302
|
-
options[_i] = arguments[_i];
|
|
2303
|
-
}
|
|
2304
|
-
return Field.apply(void 0, tslib_1.__spread([function () { return Number; }], options));
|
|
2305
|
-
};
|
|
2306
|
-
Fields.uuid = function () {
|
|
2307
|
-
var options = [];
|
|
2308
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2309
|
-
options[_i] = arguments[_i];
|
|
2310
|
-
}
|
|
2311
|
-
return Field.apply(void 0, tslib_1.__spread([function () { return String; }, {
|
|
2312
|
-
allowApiUpdate: false,
|
|
2313
|
-
defaultValue: function () { return uuid_1.v4(); }
|
|
2314
|
-
}], options));
|
|
2315
|
-
};
|
|
2316
|
-
Fields.string = function () {
|
|
2317
|
-
var options = [];
|
|
2318
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2319
|
-
options[_i] = arguments[_i];
|
|
2320
|
-
}
|
|
2321
|
-
return Field.apply(void 0, tslib_1.__spread([function () { return String; }], options));
|
|
2322
|
-
};
|
|
2323
|
-
Fields.boolean = function () {
|
|
2324
|
-
var options = [];
|
|
2325
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2326
|
-
options[_i] = arguments[_i];
|
|
2327
|
-
}
|
|
2328
|
-
return Field.apply(void 0, tslib_1.__spread([function () { return Boolean; }], options));
|
|
2329
|
-
};
|
|
2330
|
-
return Fields;
|
|
2331
|
-
}());
|
|
2332
|
-
exports.Fields = Fields;
|
|
2333
|
-
function isAutoIncrement(f) {
|
|
2334
|
-
var _a;
|
|
2335
|
-
return ((_a = f.options.valueConverter) === null || _a === void 0 ? void 0 : _a.fieldTypeInDb) === 'autoincrement';
|
|
2336
1329
|
}
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
o.displayValue = function (item, val) { return val.caption; };
|
|
2347
|
-
}], options))(type);
|
|
1330
|
+
export function isAutoIncrement(f) {
|
|
1331
|
+
return f.options.valueConverter?.fieldTypeInDb === 'autoincrement';
|
|
1332
|
+
}
|
|
1333
|
+
export function ValueListFieldType(...options) {
|
|
1334
|
+
return (type) => {
|
|
1335
|
+
FieldType(o => {
|
|
1336
|
+
o.valueConverter = ValueListInfo.get(type),
|
|
1337
|
+
o.displayValue = (item, val) => val.caption;
|
|
1338
|
+
}, ...options)(type);
|
|
2348
1339
|
};
|
|
2349
1340
|
}
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
function ValueListInfo(valueListType) {
|
|
2353
|
-
var e_33, _a, _b;
|
|
2354
|
-
var _this = this;
|
|
1341
|
+
export class ValueListInfo {
|
|
1342
|
+
constructor(valueListType) {
|
|
2355
1343
|
this.valueListType = valueListType;
|
|
2356
1344
|
this.byIdMap = new Map();
|
|
2357
1345
|
this.values = [];
|
|
2358
1346
|
this.isNumeric = false;
|
|
2359
|
-
for (
|
|
2360
|
-
|
|
1347
|
+
for (let member in this.valueListType) {
|
|
1348
|
+
let s = this.valueListType[member];
|
|
2361
1349
|
if (s instanceof this.valueListType) {
|
|
2362
1350
|
if (s.id === undefined)
|
|
2363
1351
|
s.id = member;
|
|
2364
1352
|
if (typeof s.id === 'number')
|
|
2365
1353
|
this.isNumeric = true;
|
|
2366
1354
|
if (s.caption === undefined)
|
|
2367
|
-
s.caption =
|
|
1355
|
+
s.caption = makeTitle(s.id !== undefined ? s.id.toString() : member);
|
|
2368
1356
|
this.byIdMap.set(s.id, s);
|
|
2369
1357
|
this.values.push(s);
|
|
2370
1358
|
}
|
|
@@ -2372,95 +1360,81 @@ var ValueListInfo = /** @class */ (function () {
|
|
|
2372
1360
|
if (this.isNumeric) {
|
|
2373
1361
|
this.fieldTypeInDb = 'integer';
|
|
2374
1362
|
}
|
|
2375
|
-
var options = Reflect.getMetadata(
|
|
1363
|
+
var options = Reflect.getMetadata(storableMember, this.valueListType);
|
|
2376
1364
|
if (options) {
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
_this.byIdMap.set(s.id, s);
|
|
2387
|
-
});
|
|
2388
|
-
}
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
catch (e_33_1) { e_33 = { error: e_33_1 }; }
|
|
2392
|
-
finally {
|
|
2393
|
-
try {
|
|
2394
|
-
if (options_1_1 && !options_1_1.done && (_a = options_1.return)) _a.call(options_1);
|
|
1365
|
+
for (const op of options) {
|
|
1366
|
+
if (op?.getValues) {
|
|
1367
|
+
this.values.splice(0, this.values.length, ...op.getValues());
|
|
1368
|
+
this.byIdMap.clear();
|
|
1369
|
+
this.values.forEach(s => {
|
|
1370
|
+
if (s.caption === undefined && s.id !== undefined)
|
|
1371
|
+
s.caption = makeTitle(s.id);
|
|
1372
|
+
this.byIdMap.set(s.id, s);
|
|
1373
|
+
});
|
|
2395
1374
|
}
|
|
2396
|
-
finally { if (e_33) throw e_33.error; }
|
|
2397
1375
|
}
|
|
2398
|
-
if (this.values.find(
|
|
2399
|
-
throw new Error(
|
|
1376
|
+
if (this.values.find(s => s.id === undefined))
|
|
1377
|
+
throw new Error(`ValueType ${this.valueListType} has values without an id`);
|
|
2400
1378
|
}
|
|
2401
1379
|
else
|
|
2402
|
-
throw new Error(
|
|
1380
|
+
throw new Error(`ValueType not yet initialized, did you forget to call @ValueListFieldType on ` + valueListType);
|
|
2403
1381
|
}
|
|
2404
|
-
|
|
2405
|
-
|
|
1382
|
+
static get(type) {
|
|
1383
|
+
let r = typeCache.get(type);
|
|
2406
1384
|
if (!r) {
|
|
2407
1385
|
r = new ValueListInfo(type);
|
|
2408
1386
|
typeCache.set(type, r);
|
|
2409
1387
|
}
|
|
2410
1388
|
return r;
|
|
2411
|
-
}
|
|
2412
|
-
|
|
1389
|
+
}
|
|
1390
|
+
getValues() {
|
|
2413
1391
|
return this.values;
|
|
2414
|
-
}
|
|
2415
|
-
|
|
1392
|
+
}
|
|
1393
|
+
byId(key) {
|
|
2416
1394
|
if (this.isNumeric)
|
|
2417
1395
|
key = +key;
|
|
2418
1396
|
return this.byIdMap.get(key);
|
|
2419
|
-
}
|
|
2420
|
-
|
|
1397
|
+
}
|
|
1398
|
+
fromJson(val) {
|
|
2421
1399
|
return this.byId(val);
|
|
2422
|
-
}
|
|
2423
|
-
|
|
1400
|
+
}
|
|
1401
|
+
toJson(val) {
|
|
2424
1402
|
if (!val)
|
|
2425
1403
|
return undefined;
|
|
2426
1404
|
return val.id;
|
|
2427
|
-
}
|
|
2428
|
-
|
|
1405
|
+
}
|
|
1406
|
+
fromDb(val) {
|
|
2429
1407
|
return this.fromJson(val);
|
|
2430
|
-
}
|
|
2431
|
-
|
|
1408
|
+
}
|
|
1409
|
+
toDb(val) {
|
|
2432
1410
|
return this.toJson(val);
|
|
2433
|
-
}
|
|
2434
|
-
|
|
1411
|
+
}
|
|
1412
|
+
toInput(val, inputType) {
|
|
2435
1413
|
return this.toJson(val);
|
|
2436
|
-
}
|
|
2437
|
-
|
|
1414
|
+
}
|
|
1415
|
+
fromInput(val, inputType) {
|
|
2438
1416
|
return this.fromJson(val);
|
|
2439
|
-
}
|
|
2440
|
-
|
|
1417
|
+
}
|
|
1418
|
+
displayValue(val) {
|
|
2441
1419
|
if (!val)
|
|
2442
1420
|
return '';
|
|
2443
1421
|
return val.caption;
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
var typeCache = new Map();
|
|
2449
|
-
function getValueList(type) {
|
|
2450
|
-
var _a, _b, _c;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
const typeCache = new Map();
|
|
1425
|
+
export function getValueList(type) {
|
|
2451
1426
|
{
|
|
2452
|
-
|
|
1427
|
+
const fr = type?.metadata?.valueType;
|
|
2453
1428
|
if (fr)
|
|
2454
1429
|
return ValueListInfo.get(fr).getValues();
|
|
2455
1430
|
}
|
|
2456
1431
|
{
|
|
2457
|
-
|
|
1432
|
+
const fr = type?.valueType;
|
|
2458
1433
|
if (fr)
|
|
2459
1434
|
return ValueListInfo.get(fr).getValues();
|
|
2460
1435
|
}
|
|
2461
1436
|
return ValueListInfo.get(type).getValues();
|
|
2462
1437
|
}
|
|
2463
|
-
exports.getValueList = getValueList;
|
|
2464
1438
|
/**Decorates fields that should be used as fields.
|
|
2465
1439
|
* for more info see: [Field Types](https://remult.dev/docs/field-types.html)
|
|
2466
1440
|
*
|
|
@@ -2474,14 +1448,10 @@ exports.getValueList = getValueList;
|
|
|
2474
1448
|
* @Fields.string((options,remult) => options.includeInApi = true)
|
|
2475
1449
|
* title='';
|
|
2476
1450
|
*/
|
|
2477
|
-
function Field(valueType) {
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
}
|
|
2482
|
-
return function (target, key, c) {
|
|
2483
|
-
var factory = function (remult) {
|
|
2484
|
-
var r = buildOptions(options, remult);
|
|
1451
|
+
export function Field(valueType, ...options) {
|
|
1452
|
+
return (target, key, c) => {
|
|
1453
|
+
let factory = (remult) => {
|
|
1454
|
+
let r = buildOptions(options, remult);
|
|
2485
1455
|
if (!r.valueType && valueType) {
|
|
2486
1456
|
r.valueType = valueType();
|
|
2487
1457
|
}
|
|
@@ -2490,7 +1460,7 @@ function Field(valueType) {
|
|
|
2490
1460
|
}
|
|
2491
1461
|
if (!r.dbName)
|
|
2492
1462
|
r.dbName = r.key;
|
|
2493
|
-
|
|
1463
|
+
let type = r.valueType;
|
|
2494
1464
|
if (!type) {
|
|
2495
1465
|
type = Reflect.getMetadata("design:type", target, key);
|
|
2496
1466
|
r.valueType = type;
|
|
@@ -2499,129 +1469,114 @@ function Field(valueType) {
|
|
|
2499
1469
|
r.target = target;
|
|
2500
1470
|
return r;
|
|
2501
1471
|
};
|
|
2502
|
-
|
|
1472
|
+
let names = columnsOfType.get(target.constructor);
|
|
2503
1473
|
if (!names) {
|
|
2504
1474
|
names = [];
|
|
2505
|
-
|
|
1475
|
+
columnsOfType.set(target.constructor, names);
|
|
2506
1476
|
}
|
|
2507
|
-
|
|
1477
|
+
let set = names.find(x => x.key == key);
|
|
2508
1478
|
if (!set)
|
|
2509
1479
|
names.push({
|
|
2510
|
-
key
|
|
1480
|
+
key,
|
|
2511
1481
|
settings: factory,
|
|
2512
1482
|
});
|
|
2513
1483
|
else {
|
|
2514
|
-
|
|
2515
|
-
set.settings =
|
|
2516
|
-
|
|
2517
|
-
|
|
1484
|
+
let prev = set.settings;
|
|
1485
|
+
set.settings = (c) => {
|
|
1486
|
+
let prevO = prev(c);
|
|
1487
|
+
let curr = factory(c);
|
|
2518
1488
|
return Object.assign(prevO, curr);
|
|
2519
1489
|
};
|
|
2520
1490
|
}
|
|
2521
1491
|
};
|
|
2522
1492
|
}
|
|
2523
|
-
|
|
2524
|
-
exports.storableMember = Symbol("storableMember");
|
|
1493
|
+
export const storableMember = Symbol("storableMember");
|
|
2525
1494
|
function buildOptions(options, remult) {
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
o(r, remult);
|
|
2534
|
-
else
|
|
2535
|
-
Object.assign(r, o);
|
|
2536
|
-
}
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
catch (e_34_1) { e_34 = { error: e_34_1 }; }
|
|
2540
|
-
finally {
|
|
2541
|
-
try {
|
|
2542
|
-
if (options_2_1 && !options_2_1.done && (_a = options_2.return)) _a.call(options_2);
|
|
1495
|
+
let r = {};
|
|
1496
|
+
for (const o of options) {
|
|
1497
|
+
if (o) {
|
|
1498
|
+
if (typeof o === "function")
|
|
1499
|
+
o(r, remult);
|
|
1500
|
+
else
|
|
1501
|
+
Object.assign(r, o);
|
|
2543
1502
|
}
|
|
2544
|
-
finally { if (e_34) throw e_34.error; }
|
|
2545
1503
|
}
|
|
2546
1504
|
return r;
|
|
2547
1505
|
}
|
|
2548
|
-
function decorateColumnSettings(settings, remult) {
|
|
1506
|
+
export function decorateColumnSettings(settings, remult) {
|
|
2549
1507
|
if (settings.valueType) {
|
|
2550
|
-
|
|
1508
|
+
let settingsOnTypeLevel = Reflect.getMetadata(storableMember, settings.valueType);
|
|
2551
1509
|
if (settingsOnTypeLevel) {
|
|
2552
|
-
settings =
|
|
1510
|
+
settings = {
|
|
1511
|
+
...buildOptions(settingsOnTypeLevel, remult),
|
|
1512
|
+
...settings
|
|
1513
|
+
};
|
|
2553
1514
|
}
|
|
2554
1515
|
}
|
|
2555
1516
|
if (settings.valueType == String) {
|
|
2556
|
-
|
|
1517
|
+
let x = settings;
|
|
2557
1518
|
if (!settings.valueConverter)
|
|
2558
1519
|
x.valueConverter = {
|
|
2559
|
-
toJson:
|
|
2560
|
-
fromJson:
|
|
1520
|
+
toJson: x => x,
|
|
1521
|
+
fromJson: x => x
|
|
2561
1522
|
};
|
|
2562
1523
|
}
|
|
2563
1524
|
if (settings.valueType == Number) {
|
|
2564
|
-
|
|
1525
|
+
let x = settings;
|
|
2565
1526
|
if (!settings.valueConverter)
|
|
2566
|
-
x.valueConverter =
|
|
1527
|
+
x.valueConverter = ValueConverters.Number;
|
|
2567
1528
|
}
|
|
2568
1529
|
if (settings.valueType == Date) {
|
|
2569
|
-
|
|
1530
|
+
let x = settings;
|
|
2570
1531
|
if (!settings.valueConverter) {
|
|
2571
|
-
x.valueConverter =
|
|
1532
|
+
x.valueConverter = ValueConverters.Date;
|
|
2572
1533
|
}
|
|
2573
1534
|
}
|
|
2574
1535
|
if (settings.valueType == Boolean) {
|
|
2575
|
-
|
|
1536
|
+
let x = settings;
|
|
2576
1537
|
if (!x.valueConverter)
|
|
2577
|
-
x.valueConverter =
|
|
1538
|
+
x.valueConverter = ValueConverters.Boolean;
|
|
2578
1539
|
}
|
|
2579
1540
|
if (!settings.valueConverter) {
|
|
2580
|
-
|
|
1541
|
+
let ei = getEntitySettings(settings.valueType, false);
|
|
2581
1542
|
if (ei) {
|
|
2582
1543
|
settings.valueConverter = {
|
|
2583
|
-
toDb:
|
|
2584
|
-
fromDb:
|
|
1544
|
+
toDb: x => x,
|
|
1545
|
+
fromDb: x => x
|
|
2585
1546
|
};
|
|
2586
1547
|
}
|
|
2587
1548
|
else
|
|
2588
|
-
settings.valueConverter =
|
|
1549
|
+
settings.valueConverter = ValueConverters.Default;
|
|
2589
1550
|
}
|
|
2590
1551
|
if (!settings.valueConverter.toJson) {
|
|
2591
|
-
settings.valueConverter.toJson =
|
|
1552
|
+
settings.valueConverter.toJson = x => x;
|
|
2592
1553
|
}
|
|
2593
1554
|
if (!settings.valueConverter.fromJson) {
|
|
2594
|
-
settings.valueConverter.fromJson =
|
|
1555
|
+
settings.valueConverter.fromJson = x => x;
|
|
2595
1556
|
}
|
|
2596
1557
|
if (!settings.valueConverter.toDb) {
|
|
2597
|
-
settings.valueConverter.toDb =
|
|
1558
|
+
settings.valueConverter.toDb = x => settings.valueConverter.toJson(x);
|
|
2598
1559
|
}
|
|
2599
1560
|
if (!settings.valueConverter.fromDb) {
|
|
2600
|
-
settings.valueConverter.fromDb =
|
|
1561
|
+
settings.valueConverter.fromDb = x => settings.valueConverter.fromJson(x);
|
|
2601
1562
|
}
|
|
2602
1563
|
if (!settings.valueConverter.toInput) {
|
|
2603
|
-
settings.valueConverter.toInput =
|
|
1564
|
+
settings.valueConverter.toInput = x => settings.valueConverter.toJson(x);
|
|
2604
1565
|
}
|
|
2605
1566
|
if (!settings.valueConverter.fromInput) {
|
|
2606
|
-
settings.valueConverter.fromInput =
|
|
1567
|
+
settings.valueConverter.fromInput = x => settings.valueConverter.fromJson(x);
|
|
2607
1568
|
}
|
|
2608
1569
|
return settings;
|
|
2609
1570
|
}
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
|
2614
|
-
options[_i - 3] = arguments[_i];
|
|
2615
|
-
}
|
|
2616
|
-
Entity.apply(void 0, tslib_1.__spread([key], options))(c);
|
|
2617
|
-
for (var fieldKey in fields) {
|
|
1571
|
+
export function BuildEntity(c, key, fields, ...options) {
|
|
1572
|
+
Entity(key, ...options)(c);
|
|
1573
|
+
for (const fieldKey in fields) {
|
|
2618
1574
|
if (Object.prototype.hasOwnProperty.call(fields, fieldKey)) {
|
|
2619
|
-
|
|
1575
|
+
const element = fields[fieldKey];
|
|
2620
1576
|
element(c.prototype, fieldKey);
|
|
2621
1577
|
}
|
|
2622
1578
|
}
|
|
2623
1579
|
}
|
|
2624
|
-
exports.BuildEntity = BuildEntity;
|
|
2625
1580
|
/**Decorates classes that should be used as entities.
|
|
2626
1581
|
* Receives a key and an array of EntityOptions.
|
|
2627
1582
|
* @example
|
|
@@ -2646,321 +1601,191 @@ exports.BuildEntity = BuildEntity;
|
|
|
2646
1601
|
* // as an arrow function that receives `remult` as a parameter
|
|
2647
1602
|
* @Entity("tasks", (options,remult) => options.allowApiCrud = true)
|
|
2648
1603
|
*/
|
|
2649
|
-
function Entity(key) {
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
options[_i - 1] = arguments[_i];
|
|
2653
|
-
}
|
|
2654
|
-
return function (target) {
|
|
2655
|
-
var _a;
|
|
2656
|
-
for (var customFilterMember in target) {
|
|
1604
|
+
export function Entity(key, ...options) {
|
|
1605
|
+
return target => {
|
|
1606
|
+
for (const customFilterMember in target) {
|
|
2657
1607
|
if (Object.prototype.hasOwnProperty.call(target, customFilterMember)) {
|
|
2658
|
-
|
|
2659
|
-
if (
|
|
1608
|
+
const element = target[customFilterMember];
|
|
1609
|
+
if (element?.customFilterInfo?.customFilterTranslator) {
|
|
2660
1610
|
if (!element.customFilterInfo.key)
|
|
2661
1611
|
element.customFilterInfo.key = customFilterMember;
|
|
2662
1612
|
}
|
|
2663
1613
|
}
|
|
2664
1614
|
}
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
o(r, remult);
|
|
2674
|
-
else
|
|
2675
|
-
Object.assign(r, o);
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
catch (e_35_1) { e_35 = { error: e_35_1 }; }
|
|
2680
|
-
finally {
|
|
2681
|
-
try {
|
|
2682
|
-
if (options_3_1 && !options_3_1.done && (_a = options_3.return)) _a.call(options_3);
|
|
1615
|
+
let factory = remult => {
|
|
1616
|
+
let r = {};
|
|
1617
|
+
for (const o of options) {
|
|
1618
|
+
if (o) {
|
|
1619
|
+
if (typeof o === "function")
|
|
1620
|
+
o(r, remult);
|
|
1621
|
+
else
|
|
1622
|
+
Object.assign(r, o);
|
|
2683
1623
|
}
|
|
2684
|
-
finally { if (e_35) throw e_35.error; }
|
|
2685
1624
|
}
|
|
2686
|
-
|
|
1625
|
+
let base = Object.getPrototypeOf(target);
|
|
2687
1626
|
if (base) {
|
|
2688
|
-
|
|
1627
|
+
let baseFactory = getEntitySettings(base, false);
|
|
2689
1628
|
if (baseFactory) {
|
|
2690
|
-
|
|
1629
|
+
let opt = baseFactory(remult);
|
|
2691
1630
|
if (opt) {
|
|
2692
|
-
r =
|
|
1631
|
+
r = {
|
|
1632
|
+
...opt,
|
|
1633
|
+
...r
|
|
1634
|
+
};
|
|
2693
1635
|
}
|
|
2694
1636
|
}
|
|
2695
1637
|
}
|
|
2696
1638
|
return r;
|
|
2697
1639
|
};
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
Reflect.defineMetadata(
|
|
2701
|
-
Reflect.defineMetadata(
|
|
1640
|
+
allEntities.push(target);
|
|
1641
|
+
setControllerSettings(target, { key });
|
|
1642
|
+
Reflect.defineMetadata(entityInfo, factory, target);
|
|
1643
|
+
Reflect.defineMetadata(entityInfo_key, key, target);
|
|
2702
1644
|
return target;
|
|
2703
1645
|
};
|
|
2704
1646
|
}
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
get: function () { return getEntityRef(this); },
|
|
2711
|
-
enumerable: false,
|
|
2712
|
-
configurable: true
|
|
2713
|
-
});
|
|
2714
|
-
EntityBase.prototype.save = function () { return this._.save(); };
|
|
2715
|
-
EntityBase.prototype.assign = function (values) {
|
|
2716
|
-
assign_1.assign(this, values);
|
|
1647
|
+
export class EntityBase {
|
|
1648
|
+
get _() { return getEntityRef(this); }
|
|
1649
|
+
save() { return this._.save(); }
|
|
1650
|
+
assign(values) {
|
|
1651
|
+
assign(this, values);
|
|
2717
1652
|
return this;
|
|
2718
|
-
}
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
});
|
|
2726
|
-
return EntityBase;
|
|
2727
|
-
}());
|
|
2728
|
-
exports.EntityBase = EntityBase;
|
|
2729
|
-
var ControllerBase = /** @class */ (function () {
|
|
2730
|
-
function ControllerBase(remult) {
|
|
1653
|
+
}
|
|
1654
|
+
delete() { return this._.delete(); }
|
|
1655
|
+
isNew() { return this._.isNew(); }
|
|
1656
|
+
get $() { return this._.fields; }
|
|
1657
|
+
}
|
|
1658
|
+
export class ControllerBase {
|
|
1659
|
+
constructor(remult) {
|
|
2731
1660
|
this.remult = remult;
|
|
2732
1661
|
}
|
|
2733
|
-
|
|
2734
|
-
|
|
1662
|
+
assign(values) {
|
|
1663
|
+
assign(this, values);
|
|
2735
1664
|
return this;
|
|
2736
|
-
}
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
Object.defineProperty(ControllerBase.prototype, "_", {
|
|
2743
|
-
get: function () { return getControllerRef(this); },
|
|
2744
|
-
enumerable: false,
|
|
2745
|
-
configurable: true
|
|
2746
|
-
});
|
|
2747
|
-
return ControllerBase;
|
|
2748
|
-
}());
|
|
2749
|
-
exports.ControllerBase = ControllerBase;
|
|
2750
|
-
var QueryResultImpl = /** @class */ (function () {
|
|
2751
|
-
function QueryResultImpl(options, repo) {
|
|
1665
|
+
}
|
|
1666
|
+
get $() { return getFields(this); }
|
|
1667
|
+
get _() { return getControllerRef(this); }
|
|
1668
|
+
}
|
|
1669
|
+
class QueryResultImpl {
|
|
1670
|
+
constructor(options, repo) {
|
|
2752
1671
|
this.options = options;
|
|
2753
1672
|
this.repo = repo;
|
|
2754
1673
|
this._count = undefined;
|
|
2755
1674
|
if (!this.options)
|
|
2756
1675
|
this.options = {};
|
|
2757
1676
|
if (!this.options.pageSize) {
|
|
2758
|
-
this.options.pageSize =
|
|
2759
|
-
}
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
page: page,
|
|
2771
|
-
load: this.options.load
|
|
2772
|
-
})];
|
|
2773
|
-
});
|
|
2774
|
-
});
|
|
2775
|
-
};
|
|
2776
|
-
QueryResultImpl.prototype.count = function () {
|
|
2777
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
2778
|
-
var _a;
|
|
2779
|
-
return tslib_1.__generator(this, function (_b) {
|
|
2780
|
-
switch (_b.label) {
|
|
2781
|
-
case 0:
|
|
2782
|
-
if (!(this._count === undefined)) return [3 /*break*/, 2];
|
|
2783
|
-
_a = this;
|
|
2784
|
-
return [4 /*yield*/, this.repo.count(this.options.where)];
|
|
2785
|
-
case 1:
|
|
2786
|
-
_a._count = _b.sent();
|
|
2787
|
-
_b.label = 2;
|
|
2788
|
-
case 2: return [2 /*return*/, this._count];
|
|
2789
|
-
}
|
|
2790
|
-
});
|
|
2791
|
-
});
|
|
2792
|
-
};
|
|
2793
|
-
QueryResultImpl.prototype.forEach = function (what) {
|
|
2794
|
-
var e_36, _a;
|
|
2795
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
2796
|
-
var i, _b, _c, x, e_36_1;
|
|
2797
|
-
return tslib_1.__generator(this, function (_d) {
|
|
2798
|
-
switch (_d.label) {
|
|
2799
|
-
case 0:
|
|
2800
|
-
i = 0;
|
|
2801
|
-
_d.label = 1;
|
|
2802
|
-
case 1:
|
|
2803
|
-
_d.trys.push([1, 7, 8, 13]);
|
|
2804
|
-
_b = tslib_1.__asyncValues(this);
|
|
2805
|
-
_d.label = 2;
|
|
2806
|
-
case 2: return [4 /*yield*/, _b.next()];
|
|
2807
|
-
case 3:
|
|
2808
|
-
if (!(_c = _d.sent(), !_c.done)) return [3 /*break*/, 6];
|
|
2809
|
-
x = _c.value;
|
|
2810
|
-
return [4 /*yield*/, what(x)];
|
|
2811
|
-
case 4:
|
|
2812
|
-
_d.sent();
|
|
2813
|
-
i++;
|
|
2814
|
-
_d.label = 5;
|
|
2815
|
-
case 5: return [3 /*break*/, 2];
|
|
2816
|
-
case 6: return [3 /*break*/, 13];
|
|
2817
|
-
case 7:
|
|
2818
|
-
e_36_1 = _d.sent();
|
|
2819
|
-
e_36 = { error: e_36_1 };
|
|
2820
|
-
return [3 /*break*/, 13];
|
|
2821
|
-
case 8:
|
|
2822
|
-
_d.trys.push([8, , 11, 12]);
|
|
2823
|
-
if (!(_c && !_c.done && (_a = _b.return))) return [3 /*break*/, 10];
|
|
2824
|
-
return [4 /*yield*/, _a.call(_b)];
|
|
2825
|
-
case 9:
|
|
2826
|
-
_d.sent();
|
|
2827
|
-
_d.label = 10;
|
|
2828
|
-
case 10: return [3 /*break*/, 12];
|
|
2829
|
-
case 11:
|
|
2830
|
-
if (e_36) throw e_36.error;
|
|
2831
|
-
return [7 /*endfinally*/];
|
|
2832
|
-
case 12: return [7 /*endfinally*/];
|
|
2833
|
-
case 13: return [2 /*return*/, i];
|
|
2834
|
-
}
|
|
2835
|
-
});
|
|
1677
|
+
this.options.pageSize = queryConfig.defaultPageSize;
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
async getPage(page) {
|
|
1681
|
+
if (page < 1)
|
|
1682
|
+
page = 1;
|
|
1683
|
+
return this.repo.find({
|
|
1684
|
+
where: this.options.where,
|
|
1685
|
+
orderBy: this.options.orderBy,
|
|
1686
|
+
limit: this.options.pageSize,
|
|
1687
|
+
page: page,
|
|
1688
|
+
load: this.options.load
|
|
2836
1689
|
});
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
case 2:
|
|
2859
|
-
nextPageFilter_1 = _a.sent();
|
|
2860
|
-
nextPage = function () { return _this.paginator(nextPageFilter_1); };
|
|
2861
|
-
_a.label = 3;
|
|
2862
|
-
case 3: return [2 /*return*/, {
|
|
2863
|
-
count: function () { return _this.count(); },
|
|
2864
|
-
hasNextPage: hasNextPage,
|
|
2865
|
-
items: items,
|
|
2866
|
-
nextPage: nextPage
|
|
2867
|
-
}];
|
|
2868
|
-
}
|
|
2869
|
-
});
|
|
1690
|
+
}
|
|
1691
|
+
async count() {
|
|
1692
|
+
if (this._count === undefined)
|
|
1693
|
+
this._count = await this.repo.count(this.options.where);
|
|
1694
|
+
return this._count;
|
|
1695
|
+
}
|
|
1696
|
+
async forEach(what) {
|
|
1697
|
+
let i = 0;
|
|
1698
|
+
for await (const x of this) {
|
|
1699
|
+
await what(x);
|
|
1700
|
+
i++;
|
|
1701
|
+
}
|
|
1702
|
+
return i;
|
|
1703
|
+
}
|
|
1704
|
+
async paginator(pNextPageFilter) {
|
|
1705
|
+
this.options.orderBy = Sort.createUniqueEntityOrderBy(this.repo.metadata, this.options.orderBy);
|
|
1706
|
+
let items = await this.repo.find({
|
|
1707
|
+
where: { $and: [this.options.where, pNextPageFilter] },
|
|
1708
|
+
orderBy: this.options.orderBy,
|
|
1709
|
+
limit: this.options.pageSize,
|
|
1710
|
+
load: this.options.load
|
|
2870
1711
|
});
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
1712
|
+
let nextPage = undefined;
|
|
1713
|
+
let hasNextPage = items.length == this.options.pageSize;
|
|
1714
|
+
if (hasNextPage) {
|
|
1715
|
+
let nextPageFilter = await this.repo.createAfterFilter(this.options.orderBy, items[items.length - 1]);
|
|
1716
|
+
nextPage = () => this.paginator(nextPageFilter);
|
|
1717
|
+
}
|
|
1718
|
+
return {
|
|
1719
|
+
count: () => this.count(),
|
|
1720
|
+
hasNextPage,
|
|
1721
|
+
items,
|
|
1722
|
+
nextPage
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
[Symbol.asyncIterator]() {
|
|
2874
1726
|
if (!this.options.where) {
|
|
2875
1727
|
this.options.where = {};
|
|
2876
1728
|
}
|
|
2877
|
-
|
|
2878
|
-
this.options.orderBy =
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
itStrategy =
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
return [2 /*return*/, { value: undefined, done: true }];
|
|
2899
|
-
prev = currentPage;
|
|
2900
|
-
if (!currentPage) return [3 /*break*/, 4];
|
|
2901
|
-
return [4 /*yield*/, currentPage.nextPage()];
|
|
2902
|
-
case 3:
|
|
2903
|
-
currentPage = _d.sent();
|
|
2904
|
-
return [3 /*break*/, 6];
|
|
2905
|
-
case 4: return [4 /*yield*/, this.paginator()];
|
|
2906
|
-
case 5:
|
|
2907
|
-
currentPage = _d.sent();
|
|
2908
|
-
_d.label = 6;
|
|
2909
|
-
case 6:
|
|
2910
|
-
itemIndex = 0;
|
|
2911
|
-
if (currentPage.items.length == 0) {
|
|
2912
|
-
return [2 /*return*/, { value: undefined, done: true }];
|
|
2913
|
-
}
|
|
2914
|
-
else {
|
|
2915
|
-
if ((prev === null || prev === void 0 ? void 0 : prev.items.length) > 0) {
|
|
2916
|
-
if (this.repo.getEntityRef(prev.items[0]).getId() == this.repo.getEntityRef(currentPage.items[0]).getId())
|
|
2917
|
-
throw new Error("pagination failure, returned same first row");
|
|
2918
|
-
}
|
|
2919
|
-
}
|
|
2920
|
-
_d.label = 7;
|
|
2921
|
-
case 7:
|
|
2922
|
-
if (itemIndex < currentPage.items.length)
|
|
2923
|
-
return [2 /*return*/, { value: currentPage.items[itemIndex++], done: false }];
|
|
2924
|
-
return [2 /*return*/];
|
|
1729
|
+
let ob = this.options.orderBy;
|
|
1730
|
+
this.options.orderBy = Sort.createUniqueEntityOrderBy(this.repo.metadata, ob);
|
|
1731
|
+
let itemIndex = -1;
|
|
1732
|
+
let currentPage = undefined;
|
|
1733
|
+
let itStrategy;
|
|
1734
|
+
let j = 0;
|
|
1735
|
+
itStrategy = async () => {
|
|
1736
|
+
if (this.options.progress) {
|
|
1737
|
+
this.options.progress.progress(j++ / await this.count());
|
|
1738
|
+
}
|
|
1739
|
+
if (currentPage === undefined || itemIndex == currentPage.items.length) {
|
|
1740
|
+
if (currentPage && !currentPage.hasNextPage)
|
|
1741
|
+
return { value: undefined, done: true };
|
|
1742
|
+
let prev = currentPage;
|
|
1743
|
+
if (currentPage)
|
|
1744
|
+
currentPage = await currentPage.nextPage();
|
|
1745
|
+
else
|
|
1746
|
+
currentPage = await this.paginator();
|
|
1747
|
+
itemIndex = 0;
|
|
1748
|
+
if (currentPage.items.length == 0) {
|
|
1749
|
+
return { value: undefined, done: true };
|
|
2925
1750
|
}
|
|
2926
|
-
|
|
2927
|
-
|
|
1751
|
+
else {
|
|
1752
|
+
if (prev?.items.length > 0) {
|
|
1753
|
+
if (this.repo.getEntityRef(prev.items[0]).getId() == this.repo.getEntityRef(currentPage.items[0]).getId())
|
|
1754
|
+
throw new Error("pagination failure, returned same first row");
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
if (itemIndex < currentPage.items.length)
|
|
1759
|
+
return { value: currentPage.items[itemIndex++], done: false };
|
|
1760
|
+
};
|
|
2928
1761
|
return {
|
|
2929
|
-
next:
|
|
2930
|
-
|
|
2931
|
-
return
|
|
2932
|
-
|
|
2933
|
-
return [2 /*return*/, r];
|
|
2934
|
-
});
|
|
2935
|
-
}); }
|
|
1762
|
+
next: async () => {
|
|
1763
|
+
let r = itStrategy();
|
|
1764
|
+
return r;
|
|
1765
|
+
}
|
|
2936
1766
|
};
|
|
2937
|
-
};
|
|
2938
|
-
return QueryResultImpl;
|
|
2939
|
-
}());
|
|
2940
|
-
var cacheEntityInfo = /** @class */ (function () {
|
|
2941
|
-
function cacheEntityInfo() {
|
|
2942
|
-
this.value = {};
|
|
2943
1767
|
}
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
1768
|
+
}
|
|
1769
|
+
class cacheEntityInfo {
|
|
1770
|
+
constructor() {
|
|
1771
|
+
this.value = {};
|
|
2948
1772
|
}
|
|
2949
|
-
|
|
1773
|
+
}
|
|
1774
|
+
class SubscribableImp {
|
|
1775
|
+
reportChanged() {
|
|
2950
1776
|
if (this._subscribers)
|
|
2951
|
-
this._subscribers.forEach(
|
|
2952
|
-
}
|
|
2953
|
-
|
|
1777
|
+
this._subscribers.forEach(x => x.reportChanged());
|
|
1778
|
+
}
|
|
1779
|
+
reportObserved() {
|
|
2954
1780
|
if (this._subscribers)
|
|
2955
|
-
this._subscribers.forEach(
|
|
2956
|
-
}
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
var list;
|
|
1781
|
+
this._subscribers.forEach(x => x.reportObserved());
|
|
1782
|
+
}
|
|
1783
|
+
subscribe(listener) {
|
|
1784
|
+
let list;
|
|
2960
1785
|
if (typeof listener === "function")
|
|
2961
1786
|
list = {
|
|
2962
|
-
reportChanged:
|
|
2963
|
-
reportObserved:
|
|
1787
|
+
reportChanged: () => listener(),
|
|
1788
|
+
reportObserved: () => { }
|
|
2964
1789
|
};
|
|
2965
1790
|
else
|
|
2966
1791
|
list = listener;
|
|
@@ -2968,7 +1793,6 @@ var SubscribableImp = /** @class */ (function () {
|
|
|
2968
1793
|
this._subscribers = [];
|
|
2969
1794
|
}
|
|
2970
1795
|
this._subscribers.push(list);
|
|
2971
|
-
return
|
|
2972
|
-
}
|
|
2973
|
-
|
|
2974
|
-
}());
|
|
1796
|
+
return () => this._subscribers = this._subscribers.filter(x => x != list);
|
|
1797
|
+
}
|
|
1798
|
+
}
|