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