remult 0.13.17 → 0.13.20

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.
@@ -200,22 +200,49 @@ var RepositoryImplementation = /** @class */ (function () {
200
200
  };
201
201
  RepositoryImplementation.prototype.insert = function (entity) {
202
202
  return tslib_1.__awaiter(this, void 0, void 0, function () {
203
- var ref;
204
- var _this = this;
205
- return tslib_1.__generator(this, function (_a) {
206
- switch (_a.label) {
203
+ var entity_1, entity_1_1, item, e_4_1, ref;
204
+ var e_4, _a;
205
+ return tslib_1.__generator(this, function (_b) {
206
+ switch (_b.label) {
207
207
  case 0:
208
- if (!Array.isArray(entity)) return [3 /*break*/, 1];
209
- return [2 /*return*/, Promise.all(entity.map(function (x) { return _this.insert(x); }))];
208
+ if (!Array.isArray(entity)) return [3 /*break*/, 9];
209
+ _b.label = 1;
210
210
  case 1:
211
+ _b.trys.push([1, 6, 7, 8]);
212
+ entity_1 = tslib_1.__values(entity), entity_1_1 = entity_1.next();
213
+ _b.label = 2;
214
+ case 2:
215
+ if (!!entity_1_1.done) return [3 /*break*/, 5];
216
+ item = entity_1_1.value;
217
+ return [4 /*yield*/, this.insert(item)];
218
+ case 3:
219
+ _b.sent();
220
+ _b.label = 4;
221
+ case 4:
222
+ entity_1_1 = entity_1.next();
223
+ return [3 /*break*/, 2];
224
+ case 5: return [3 /*break*/, 8];
225
+ case 6:
226
+ e_4_1 = _b.sent();
227
+ e_4 = { error: e_4_1 };
228
+ return [3 /*break*/, 8];
229
+ case 7:
230
+ try {
231
+ if (entity_1_1 && !entity_1_1.done && (_a = entity_1.return)) _a.call(entity_1);
232
+ }
233
+ finally { if (e_4) throw e_4.error; }
234
+ return [7 /*endfinally*/];
235
+ case 8: return [3 /*break*/, 13];
236
+ case 9:
211
237
  ref = getEntityRef(entity, false);
212
- if (!ref) return [3 /*break*/, 3];
238
+ if (!ref) return [3 /*break*/, 11];
213
239
  if (!ref.isNew())
214
240
  throw "Item is not new";
215
241
  return [4 /*yield*/, ref.save()];
216
- case 2: return [2 /*return*/, _a.sent()];
217
- case 3: return [4 /*yield*/, this.getEntityRef(this.create(entity)).save()];
218
- case 4: return [2 /*return*/, _a.sent()];
242
+ case 10: return [2 /*return*/, _b.sent()];
243
+ case 11: return [4 /*yield*/, this.getEntityRef(this.create(entity)).save()];
244
+ case 12: return [2 /*return*/, _b.sent()];
245
+ case 13: return [2 /*return*/];
219
246
  }
220
247
  });
221
248
  });
@@ -234,7 +261,7 @@ var RepositoryImplementation = /** @class */ (function () {
234
261
  });
235
262
  };
236
263
  RepositoryImplementation.prototype.getRefForExistingRow = function (entity, id) {
237
- var e_4, _a;
264
+ var e_5, _a;
238
265
  var ref = getEntityRef(entity, false);
239
266
  if (!ref) {
240
267
  var instance = new this.entity(this.remult);
@@ -244,12 +271,12 @@ var RepositoryImplementation = /** @class */ (function () {
244
271
  instance[field.key] = entity[field.key];
245
272
  }
246
273
  }
247
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
274
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
248
275
  finally {
249
276
  try {
250
277
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
251
278
  }
252
- finally { if (e_4) throw e_4.error; }
279
+ finally { if (e_5) throw e_5.error; }
253
280
  }
254
281
  var row_1 = new rowHelperImplementation(this._info, instance, this, this.edp, this.remult, false);
255
282
  if (id)
@@ -295,7 +322,7 @@ var RepositoryImplementation = /** @class */ (function () {
295
322
  function loadManyToOne(repo, toLoad) {
296
323
  return tslib_1.__awaiter(this, void 0, void 0, function () {
297
324
  var rows, rows_1, rows_1_1, r;
298
- var _a, e_7, _b;
325
+ var _a, e_8, _b;
299
326
  return tslib_1.__generator(this, function (_c) {
300
327
  switch (_c.label) {
301
328
  case 0: return [4 /*yield*/, repo.find({ where: (_a = repo.metadata.idMetadata).getIdFilter.apply(_a, tslib_1.__spread(toLoad)) })];
@@ -307,26 +334,25 @@ var RepositoryImplementation = /** @class */ (function () {
307
334
  repo.addToCache(r);
308
335
  }
309
336
  }
310
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
337
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
311
338
  finally {
312
339
  try {
313
340
  if (rows_1_1 && !rows_1_1.done && (_b = rows_1.return)) _b.call(rows_1);
314
341
  }
315
- finally { if (e_7) throw e_7.error; }
342
+ finally { if (e_8) throw e_8.error; }
316
343
  }
317
344
  return [2 /*return*/];
318
345
  }
319
346
  });
320
347
  });
321
348
  }
322
- var opt, _a, rawRows, loadFields, _b, _c, col, ei, load, repo, toLoad, rawRows_1, rawRows_1_1, r, val, e_5_1, result;
323
- var e_5, _d, e_6, _e;
349
+ var opt, _a, rawRows, loadFields, _b, _c, col, ei, load, repo, toLoad, rawRows_1, rawRows_1_1, r, val, e_6_1, result;
350
+ var e_6, _d, e_7, _e;
324
351
  var _this = this;
325
352
  return tslib_1.__generator(this, function (_f) {
326
353
  switch (_f.label) {
327
354
  case 0:
328
355
  context_1.Remult.onFind(this._info, options);
329
- ;
330
356
  opt = {};
331
357
  if (!options)
332
358
  options = {};
@@ -364,7 +390,7 @@ var RepositoryImplementation = /** @class */ (function () {
364
390
  repo = this.remult.repo(col.valueType);
365
391
  toLoad = [];
366
392
  try {
367
- for (rawRows_1 = (e_6 = void 0, tslib_1.__values(rawRows)), rawRows_1_1 = rawRows_1.next(); !rawRows_1_1.done; rawRows_1_1 = rawRows_1.next()) {
393
+ 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()) {
368
394
  r = rawRows_1_1.value;
369
395
  val = r[col.key];
370
396
  if (val !== undefined && val !== null && !toLoad.includes(val) && !repo.idCache.has(val)) {
@@ -372,12 +398,12 @@ var RepositoryImplementation = /** @class */ (function () {
372
398
  }
373
399
  }
374
400
  }
375
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
401
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
376
402
  finally {
377
403
  try {
378
404
  if (rawRows_1_1 && !rawRows_1_1.done && (_e = rawRows_1.return)) _e.call(rawRows_1);
379
405
  }
380
- finally { if (e_6) throw e_6.error; }
406
+ finally { if (e_7) throw e_7.error; }
381
407
  }
382
408
  if (!(toLoad.length > 0)) return [3 /*break*/, 6];
383
409
  return [4 /*yield*/, loadManyToOne(repo, toLoad)];
@@ -389,14 +415,14 @@ var RepositoryImplementation = /** @class */ (function () {
389
415
  return [3 /*break*/, 4];
390
416
  case 7: return [3 /*break*/, 10];
391
417
  case 8:
392
- e_5_1 = _f.sent();
393
- e_5 = { error: e_5_1 };
418
+ e_6_1 = _f.sent();
419
+ e_6 = { error: e_6_1 };
394
420
  return [3 /*break*/, 10];
395
421
  case 9:
396
422
  try {
397
423
  if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
398
424
  }
399
- finally { if (e_5) throw e_5.error; }
425
+ finally { if (e_6) throw e_6.error; }
400
426
  return [7 /*endfinally*/];
401
427
  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) {
402
428
  switch (_a.label) {
@@ -526,7 +552,7 @@ var RepositoryImplementation = /** @class */ (function () {
526
552
  return this.metadata.fields.toArray().filter(function (x) { return keys.includes(x.key); });
527
553
  };
528
554
  RepositoryImplementation.prototype.create = function (item) {
529
- var e_8, _a;
555
+ var e_9, _a;
530
556
  var r = new this.entity(this.remult);
531
557
  if (item)
532
558
  try {
@@ -535,12 +561,12 @@ var RepositoryImplementation = /** @class */ (function () {
535
561
  r[field.key] = item[field.key];
536
562
  }
537
563
  }
538
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
564
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
539
565
  finally {
540
566
  try {
541
567
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
542
568
  }
543
- finally { if (e_8) throw e_8.error; }
569
+ finally { if (e_9) throw e_9.error; }
544
570
  }
545
571
  var z = this.getEntityRef(r);
546
572
  return r;
@@ -548,7 +574,7 @@ var RepositoryImplementation = /** @class */ (function () {
548
574
  RepositoryImplementation.prototype.fromJson = function (json, newRow) {
549
575
  return tslib_1.__awaiter(this, void 0, void 0, function () {
550
576
  var obj, _a, _b, col, r, helper;
551
- var e_9, _c;
577
+ var e_10, _c;
552
578
  return tslib_1.__generator(this, function (_d) {
553
579
  switch (_d.label) {
554
580
  case 0:
@@ -561,12 +587,12 @@ var RepositoryImplementation = /** @class */ (function () {
561
587
  }
562
588
  }
563
589
  }
564
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
590
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
565
591
  finally {
566
592
  try {
567
593
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
568
594
  }
569
- finally { if (e_9) throw e_9.error; }
595
+ finally { if (e_10) throw e_10.error; }
570
596
  }
571
597
  if (!newRow) return [3 /*break*/, 2];
572
598
  r = this.create();
@@ -675,7 +701,7 @@ function createOldEntity(entity, remult) {
675
701
  var key = getEntityKey(entity);
676
702
  var base = Object.getPrototypeOf(entity);
677
703
  var _loop_1 = function () {
678
- var e_10, _a;
704
+ var e_11, _a;
679
705
  var baseCols = exports.columnsOfType.get(base);
680
706
  if (baseCols) {
681
707
  r.unshift.apply(r, tslib_1.__spread(baseCols.filter(function (x) { return !r.find(function (y) { return y.key == x.key; }); })));
@@ -704,17 +730,17 @@ function createOldEntity(entity, remult) {
704
730
  }
705
731
  };
706
732
  try {
707
- for (var _b = (e_10 = void 0, tslib_1.__values(functions)), _c = _b.next(); !_c.done; _c = _b.next()) {
733
+ for (var _b = (e_11 = void 0, tslib_1.__values(functions)), _c = _b.next(); !_c.done; _c = _b.next()) {
708
734
  var key_1 = _c.value;
709
735
  _loop_2(key_1);
710
736
  }
711
737
  }
712
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
738
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
713
739
  finally {
714
740
  try {
715
741
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
716
742
  }
717
- finally { if (e_10) throw e_10.error; }
743
+ finally { if (e_11) throw e_11.error; }
718
744
  }
719
745
  }
720
746
  base = Object.getPrototypeOf(base);
@@ -727,7 +753,7 @@ function createOldEntity(entity, remult) {
727
753
  exports.createOldEntity = createOldEntity;
728
754
  var rowHelperBase = /** @class */ (function () {
729
755
  function rowHelperBase(columnsInfo, instance, remult) {
730
- var e_11, _a;
756
+ var e_12, _a;
731
757
  var _this = this;
732
758
  this.columnsInfo = columnsInfo;
733
759
  this.instance = instance;
@@ -782,12 +808,12 @@ var rowHelperBase = /** @class */ (function () {
782
808
  _loop_3(col);
783
809
  }
784
810
  }
785
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
811
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
786
812
  finally {
787
813
  try {
788
814
  if (columnsInfo_1_1 && !columnsInfo_1_1.done && (_a = columnsInfo_1.return)) _a.call(columnsInfo_1);
789
815
  }
790
- finally { if (e_11) throw e_11.error; }
816
+ finally { if (e_12) throw e_12.error; }
791
817
  }
792
818
  }
793
819
  Object.defineProperty(rowHelperBase.prototype, "error", {
@@ -809,7 +835,7 @@ var rowHelperBase = /** @class */ (function () {
809
835
  return this._subscribers.subscribe(listener);
810
836
  };
811
837
  rowHelperBase.prototype.initSubscribers = function () {
812
- var e_12, _a;
838
+ var e_13, _a;
813
839
  var _this = this;
814
840
  if (!this._subscribers) {
815
841
  this._subscribers = new SubscribableImp();
@@ -844,12 +870,12 @@ var rowHelperBase = /** @class */ (function () {
844
870
  _loop_4(col);
845
871
  }
846
872
  }
847
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
873
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
848
874
  finally {
849
875
  try {
850
876
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
851
877
  }
852
- finally { if (e_12) throw e_12.error; }
878
+ finally { if (e_13) throw e_13.error; }
853
879
  }
854
880
  }
855
881
  };
@@ -880,7 +906,7 @@ var rowHelperBase = /** @class */ (function () {
880
906
  });
881
907
  };
882
908
  rowHelperBase.prototype.__assertValidity = function () {
883
- var e_13, _a;
909
+ var e_14, _a;
884
910
  if (!this.hasErrors()) {
885
911
  var error = {
886
912
  modelState: Object.assign({}, this.errors),
@@ -897,12 +923,12 @@ var rowHelperBase = /** @class */ (function () {
897
923
  }
898
924
  }
899
925
  }
900
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
926
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
901
927
  finally {
902
928
  try {
903
929
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
904
930
  }
905
- finally { if (e_13) throw e_13.error; }
931
+ finally { if (e_14) throw e_14.error; }
906
932
  }
907
933
  }
908
934
  throw error;
@@ -937,7 +963,7 @@ var rowHelperBase = /** @class */ (function () {
937
963
  this._reportChangedToEntityAndFields();
938
964
  };
939
965
  rowHelperBase.prototype._reportChangedToEntityAndFields = function () {
940
- var e_14, _a;
966
+ var e_15, _a;
941
967
  if (this._subscribers) {
942
968
  this._subscribers.reportChanged();
943
969
  try {
@@ -947,12 +973,12 @@ var rowHelperBase = /** @class */ (function () {
947
973
  ref._subscribers.reportChanged();
948
974
  }
949
975
  }
950
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
976
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
951
977
  finally {
952
978
  try {
953
979
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
954
980
  }
955
- finally { if (e_14) throw e_14.error; }
981
+ finally { if (e_15) throw e_15.error; }
956
982
  }
957
983
  }
958
984
  };
@@ -962,7 +988,7 @@ var rowHelperBase = /** @class */ (function () {
962
988
  return !!!this.error && this.errors == undefined;
963
989
  };
964
990
  rowHelperBase.prototype.copyDataToObject = function () {
965
- var e_15, _a;
991
+ var e_16, _a;
966
992
  var d = {};
967
993
  try {
968
994
  for (var _b = tslib_1.__values(this.columnsInfo), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -981,12 +1007,12 @@ var rowHelperBase = /** @class */ (function () {
981
1007
  d[col.key] = val;
982
1008
  }
983
1009
  }
984
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
1010
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
985
1011
  finally {
986
1012
  try {
987
1013
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
988
1014
  }
989
- finally { if (e_15) throw e_15.error; }
1015
+ finally { if (e_16) throw e_16.error; }
990
1016
  }
991
1017
  return d;
992
1018
  };
@@ -1042,7 +1068,7 @@ var rowHelperBase = /** @class */ (function () {
1042
1068
  });
1043
1069
  };
1044
1070
  rowHelperBase.prototype.toApiJson = function () {
1045
- var e_16, _a;
1071
+ var e_17, _a;
1046
1072
  var result = {};
1047
1073
  try {
1048
1074
  for (var _b = tslib_1.__values(this.columnsInfo), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -1067,19 +1093,19 @@ var rowHelperBase = /** @class */ (function () {
1067
1093
  }
1068
1094
  }
1069
1095
  }
1070
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
1096
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
1071
1097
  finally {
1072
1098
  try {
1073
1099
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1074
1100
  }
1075
- finally { if (e_16) throw e_16.error; }
1101
+ finally { if (e_17) throw e_17.error; }
1076
1102
  }
1077
1103
  return result;
1078
1104
  };
1079
1105
  rowHelperBase.prototype._updateEntityBasedOnApi = function (body) {
1080
1106
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1081
1107
  var keys, _a, _b, col, lu;
1082
- var e_17, _c;
1108
+ var e_18, _c;
1083
1109
  return tslib_1.__generator(this, function (_d) {
1084
1110
  switch (_d.label) {
1085
1111
  case 0:
@@ -1099,12 +1125,12 @@ var rowHelperBase = /** @class */ (function () {
1099
1125
  }
1100
1126
  }
1101
1127
  }
1102
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
1128
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
1103
1129
  finally {
1104
1130
  try {
1105
1131
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1106
1132
  }
1107
- finally { if (e_17) throw e_17.error; }
1133
+ finally { if (e_18) throw e_18.error; }
1108
1134
  }
1109
1135
  return [4 /*yield*/, Promise.all(tslib_1.__spread(this.fields).map(function (x) { return x.load(); }))];
1110
1136
  case 1:
@@ -1119,7 +1145,7 @@ var rowHelperBase = /** @class */ (function () {
1119
1145
  var rowHelperImplementation = /** @class */ (function (_super) {
1120
1146
  tslib_1.__extends(rowHelperImplementation, _super);
1121
1147
  function rowHelperImplementation(info, instance, repository, edp, remult, _isNew) {
1122
- var e_18, _a;
1148
+ var e_19, _a;
1123
1149
  var _this = _super.call(this, info.columnsInfo, instance, remult) || this;
1124
1150
  _this.info = info;
1125
1151
  _this.repository = repository;
@@ -1141,12 +1167,12 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1141
1167
  }
1142
1168
  }
1143
1169
  }
1144
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
1170
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
1145
1171
  finally {
1146
1172
  try {
1147
1173
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1148
1174
  }
1149
- finally { if (e_18) throw e_18.error; }
1175
+ finally { if (e_19) throw e_19.error; }
1150
1176
  }
1151
1177
  }
1152
1178
  if (_this.info.options.entityRefInit)
@@ -1211,7 +1237,7 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1211
1237
  };
1212
1238
  Object.defineProperty(rowHelperImplementation.prototype, "fields", {
1213
1239
  get: function () {
1214
- var _a, e_19, _b;
1240
+ var _a, e_20, _b;
1215
1241
  if (!this._columns) {
1216
1242
  var _items_1 = [];
1217
1243
  var r_1 = (_a = {
@@ -1226,12 +1252,12 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1226
1252
  _items_1.push(r_1[c.key] = new FieldRefImplementation(c, this.info.fields[c.key], this.instance, this, this));
1227
1253
  }
1228
1254
  }
1229
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
1255
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
1230
1256
  finally {
1231
1257
  try {
1232
1258
  if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1233
1259
  }
1234
- finally { if (e_19) throw e_19.error; }
1260
+ finally { if (e_20) throw e_20.error; }
1235
1261
  }
1236
1262
  this._columns = r_1;
1237
1263
  }
@@ -1243,8 +1269,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1243
1269
  rowHelperImplementation.prototype.save = function () {
1244
1270
  var _a;
1245
1271
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1246
- var doNotSave_1, _b, _c, col, e_20_1, d, ignoreKeys, _d, _e, field, f, updatedRow, changesOnly, wasChanged, key, element, err_1;
1247
- var e_20, _f, e_21, _g;
1272
+ var doNotSave_1, _b, _c, col, e_21_1, d, ignoreKeys, _d, _e, field, f, updatedRow, changesOnly, wasChanged, key, element, err_1;
1273
+ var e_21, _f, e_22, _g;
1248
1274
  return tslib_1.__generator(this, function (_h) {
1249
1275
  switch (_h.label) {
1250
1276
  case 0:
@@ -1277,14 +1303,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1277
1303
  return [3 /*break*/, 3];
1278
1304
  case 6: return [3 /*break*/, 9];
1279
1305
  case 7:
1280
- e_20_1 = _h.sent();
1281
- e_20 = { error: e_20_1 };
1306
+ e_21_1 = _h.sent();
1307
+ e_21 = { error: e_21_1 };
1282
1308
  return [3 /*break*/, 9];
1283
1309
  case 8:
1284
1310
  try {
1285
1311
  if (_c && !_c.done && (_f = _b.return)) _f.call(_b);
1286
1312
  }
1287
- finally { if (e_20) throw e_20.error; }
1313
+ finally { if (e_21) throw e_21.error; }
1288
1314
  return [7 /*endfinally*/];
1289
1315
  case 9:
1290
1316
  if (!this.info.entityInfo.saving) return [3 /*break*/, 11];
@@ -1307,12 +1333,12 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1307
1333
  }
1308
1334
  }
1309
1335
  }
1310
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
1336
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
1311
1337
  finally {
1312
1338
  try {
1313
1339
  if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
1314
1340
  }
1315
- finally { if (e_21) throw e_21.error; }
1341
+ finally { if (e_22) throw e_22.error; }
1316
1342
  }
1317
1343
  if (this.info.idMetadata.field instanceof column_1.CompoundIdField)
1318
1344
  delete (d.id);
@@ -1383,8 +1409,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1383
1409
  };
1384
1410
  rowHelperImplementation.prototype.delete = function () {
1385
1411
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1386
- var _a, _b, listener, e_22_1, err_2;
1387
- var e_22, _c;
1412
+ var _a, _b, listener, e_23_1, err_2;
1413
+ var e_23, _c;
1388
1414
  return tslib_1.__generator(this, function (_d) {
1389
1415
  switch (_d.label) {
1390
1416
  case 0:
@@ -1426,14 +1452,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1426
1452
  return [3 /*break*/, 8];
1427
1453
  case 11: return [3 /*break*/, 14];
1428
1454
  case 12:
1429
- e_22_1 = _d.sent();
1430
- e_22 = { error: e_22_1 };
1455
+ e_23_1 = _d.sent();
1456
+ e_23 = { error: e_23_1 };
1431
1457
  return [3 /*break*/, 14];
1432
1458
  case 13:
1433
1459
  try {
1434
1460
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1435
1461
  }
1436
- finally { if (e_22) throw e_22.error; }
1462
+ finally { if (e_23) throw e_23.error; }
1437
1463
  return [7 /*endfinally*/];
1438
1464
  case 14:
1439
1465
  this._wasDeleted = true;
@@ -1451,8 +1477,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1451
1477
  };
1452
1478
  rowHelperImplementation.prototype.loadDataFrom = function (data, loadItems) {
1453
1479
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1454
- var _a, _b, col, lu, e_23_1;
1455
- var e_23, _c;
1480
+ var _a, _b, col, lu, e_24_1;
1481
+ var e_24, _c;
1456
1482
  return tslib_1.__generator(this, function (_d) {
1457
1483
  switch (_d.label) {
1458
1484
  case 0:
@@ -1487,14 +1513,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1487
1513
  return [3 /*break*/, 1];
1488
1514
  case 9: return [3 /*break*/, 12];
1489
1515
  case 10:
1490
- e_23_1 = _d.sent();
1491
- e_23 = { error: e_23_1 };
1516
+ e_24_1 = _d.sent();
1517
+ e_24 = { error: e_24_1 };
1492
1518
  return [3 /*break*/, 12];
1493
1519
  case 11:
1494
1520
  try {
1495
1521
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1496
1522
  }
1497
- finally { if (e_23) throw e_23.error; }
1523
+ finally { if (e_24) throw e_24.error; }
1498
1524
  return [7 /*endfinally*/];
1499
1525
  case 12: return [4 /*yield*/, this.calcServerExpression()];
1500
1526
  case 13:
@@ -1514,8 +1540,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1514
1540
  };
1515
1541
  rowHelperImplementation.prototype.calcServerExpression = function () {
1516
1542
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1517
- var _a, _b, col, _c, _d, e_24_1;
1518
- var e_24, _e;
1543
+ var _a, _b, col, _c, _d, e_25_1;
1544
+ var e_25, _e;
1519
1545
  return tslib_1.__generator(this, function (_f) {
1520
1546
  switch (_f.label) {
1521
1547
  case 0:
@@ -1540,14 +1566,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1540
1566
  return [3 /*break*/, 2];
1541
1567
  case 5: return [3 /*break*/, 8];
1542
1568
  case 6:
1543
- e_24_1 = _f.sent();
1544
- e_24 = { error: e_24_1 };
1569
+ e_25_1 = _f.sent();
1570
+ e_25 = { error: e_25_1 };
1545
1571
  return [3 /*break*/, 8];
1546
1572
  case 7:
1547
1573
  try {
1548
1574
  if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
1549
1575
  }
1550
- finally { if (e_24) throw e_24.error; }
1576
+ finally { if (e_25) throw e_25.error; }
1551
1577
  return [7 /*endfinally*/];
1552
1578
  case 8: return [2 /*return*/];
1553
1579
  }
@@ -1560,7 +1586,7 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1560
1586
  return this._isNew;
1561
1587
  };
1562
1588
  rowHelperImplementation.prototype.wasChanged = function () {
1563
- var e_25, _a;
1589
+ var e_26, _a;
1564
1590
  var _b;
1565
1591
  (_b = this._subscribers) === null || _b === void 0 ? void 0 : _b.reportObserved();
1566
1592
  try {
@@ -1570,19 +1596,19 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1570
1596
  return true;
1571
1597
  }
1572
1598
  }
1573
- catch (e_25_1) { e_25 = { error: e_25_1 }; }
1599
+ catch (e_26_1) { e_26 = { error: e_26_1 }; }
1574
1600
  finally {
1575
1601
  try {
1576
1602
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1577
1603
  }
1578
- finally { if (e_25) throw e_25.error; }
1604
+ finally { if (e_26) throw e_26.error; }
1579
1605
  }
1580
1606
  return false;
1581
1607
  };
1582
1608
  rowHelperImplementation.prototype.__performColumnAndEntityValidations = function () {
1583
1609
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1584
- var _a, _b, c, col, e_26_1, _c, _d, listener, e_27_1;
1585
- var e_26, _e, e_27, _f;
1610
+ var _a, _b, c, col, e_27_1, _c, _d, listener, e_28_1;
1611
+ var e_27, _e, e_28, _f;
1586
1612
  return tslib_1.__generator(this, function (_g) {
1587
1613
  switch (_g.label) {
1588
1614
  case 0:
@@ -1603,14 +1629,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1603
1629
  return [3 /*break*/, 1];
1604
1630
  case 4: return [3 /*break*/, 7];
1605
1631
  case 5:
1606
- e_26_1 = _g.sent();
1607
- e_26 = { error: e_26_1 };
1632
+ e_27_1 = _g.sent();
1633
+ e_27 = { error: e_27_1 };
1608
1634
  return [3 /*break*/, 7];
1609
1635
  case 6:
1610
1636
  try {
1611
1637
  if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
1612
1638
  }
1613
- finally { if (e_26) throw e_26.error; }
1639
+ finally { if (e_27) throw e_27.error; }
1614
1640
  return [7 /*endfinally*/];
1615
1641
  case 7:
1616
1642
  if (!this.info.entityInfo.validation) return [3 /*break*/, 9];
@@ -1637,14 +1663,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1637
1663
  return [3 /*break*/, 11];
1638
1664
  case 14: return [3 /*break*/, 17];
1639
1665
  case 15:
1640
- e_27_1 = _g.sent();
1641
- e_27 = { error: e_27_1 };
1666
+ e_28_1 = _g.sent();
1667
+ e_28 = { error: e_28_1 };
1642
1668
  return [3 /*break*/, 17];
1643
1669
  case 16:
1644
1670
  try {
1645
1671
  if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
1646
1672
  }
1647
- finally { if (e_27) throw e_27.error; }
1673
+ finally { if (e_28) throw e_28.error; }
1648
1674
  return [7 /*endfinally*/];
1649
1675
  case 17: return [2 /*return*/];
1650
1676
  }
@@ -1686,7 +1712,7 @@ exports.getControllerRef = getControllerRef;
1686
1712
  var controllerRefImpl = /** @class */ (function (_super) {
1687
1713
  tslib_1.__extends(controllerRefImpl, _super);
1688
1714
  function controllerRefImpl(columnsInfo, instance, remult) {
1689
- var _a, e_28, _b;
1715
+ var _a, e_29, _b;
1690
1716
  var _this = _super.call(this, columnsInfo, instance, remult) || this;
1691
1717
  var _items = [];
1692
1718
  var r = (_a = {
@@ -1701,20 +1727,20 @@ var controllerRefImpl = /** @class */ (function (_super) {
1701
1727
  _items.push(r[col.key] = new FieldRefImplementation(col, new columnDefsImpl(col, undefined, remult), instance, undefined, _this));
1702
1728
  }
1703
1729
  }
1704
- catch (e_28_1) { e_28 = { error: e_28_1 }; }
1730
+ catch (e_29_1) { e_29 = { error: e_29_1 }; }
1705
1731
  finally {
1706
1732
  try {
1707
1733
  if (columnsInfo_2_1 && !columnsInfo_2_1.done && (_b = columnsInfo_2.return)) _b.call(columnsInfo_2);
1708
1734
  }
1709
- finally { if (e_28) throw e_28.error; }
1735
+ finally { if (e_29) throw e_29.error; }
1710
1736
  }
1711
1737
  _this.fields = r;
1712
1738
  return _this;
1713
1739
  }
1714
1740
  controllerRefImpl.prototype.__performColumnAndEntityValidations = function () {
1715
1741
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1716
- var _a, _b, col, e_29_1;
1717
- var e_29, _c;
1742
+ var _a, _b, col, e_30_1;
1743
+ var e_30, _c;
1718
1744
  return tslib_1.__generator(this, function (_d) {
1719
1745
  switch (_d.label) {
1720
1746
  case 0:
@@ -1734,14 +1760,14 @@ var controllerRefImpl = /** @class */ (function (_super) {
1734
1760
  return [3 /*break*/, 1];
1735
1761
  case 4: return [3 /*break*/, 7];
1736
1762
  case 5:
1737
- e_29_1 = _d.sent();
1738
- e_29 = { error: e_29_1 };
1763
+ e_30_1 = _d.sent();
1764
+ e_30 = { error: e_30_1 };
1739
1765
  return [3 /*break*/, 7];
1740
1766
  case 6:
1741
1767
  try {
1742
1768
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1743
1769
  }
1744
- finally { if (e_29) throw e_29.error; }
1770
+ finally { if (e_30) throw e_30.error; }
1745
1771
  return [7 /*endfinally*/];
1746
1772
  case 7: return [2 /*return*/];
1747
1773
  }
@@ -1900,11 +1926,12 @@ var FieldRefImplementation = /** @class */ (function () {
1900
1926
  };
1901
1927
  FieldRefImplementation.prototype.__performValidation = function () {
1902
1928
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1903
- var x, _a, _b, v, e_30_1;
1904
- var e_30, _c;
1929
+ var x, _a, _b, v, e_31_1, error_1;
1930
+ var e_31, _c;
1905
1931
  return tslib_1.__generator(this, function (_d) {
1906
1932
  switch (_d.label) {
1907
1933
  case 0:
1934
+ _d.trys.push([0, 12, , 13]);
1908
1935
  x = typeof (this.settings.validate);
1909
1936
  if (!Array.isArray(this.settings.validate)) return [3 /*break*/, 9];
1910
1937
  _d.label = 1;
@@ -1924,14 +1951,14 @@ var FieldRefImplementation = /** @class */ (function () {
1924
1951
  return [3 /*break*/, 2];
1925
1952
  case 5: return [3 /*break*/, 8];
1926
1953
  case 6:
1927
- e_30_1 = _d.sent();
1928
- e_30 = { error: e_30_1 };
1954
+ e_31_1 = _d.sent();
1955
+ e_31 = { error: e_31_1 };
1929
1956
  return [3 /*break*/, 8];
1930
1957
  case 7:
1931
1958
  try {
1932
1959
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1933
1960
  }
1934
- finally { if (e_30) throw e_30.error; }
1961
+ finally { if (e_31) throw e_31.error; }
1935
1962
  return [7 /*endfinally*/];
1936
1963
  case 8: return [3 /*break*/, 11];
1937
1964
  case 9:
@@ -1940,7 +1967,15 @@ var FieldRefImplementation = /** @class */ (function () {
1940
1967
  case 10:
1941
1968
  _d.sent();
1942
1969
  _d.label = 11;
1943
- case 11: return [2 /*return*/];
1970
+ case 11: return [3 /*break*/, 13];
1971
+ case 12:
1972
+ error_1 = _d.sent();
1973
+ if (typeof error_1 === "string")
1974
+ this.error = error_1;
1975
+ else
1976
+ this.error = error_1.message;
1977
+ return [3 /*break*/, 13];
1978
+ case 13: return [2 /*return*/];
1944
1979
  }
1945
1980
  });
1946
1981
  });
@@ -2058,7 +2093,7 @@ var columnDefsImpl = /** @class */ (function () {
2058
2093
  exports.columnDefsImpl = columnDefsImpl;
2059
2094
  var EntityFullInfo = /** @class */ (function () {
2060
2095
  function EntityFullInfo(columnsInfo, entityInfo, remult, entityType, key) {
2061
- var _a, e_31, _b;
2096
+ var _a, e_32, _b;
2062
2097
  var _this = this;
2063
2098
  this.columnsInfo = columnsInfo;
2064
2099
  this.entityInfo = entityInfo;
@@ -2128,12 +2163,12 @@ var EntityFullInfo = /** @class */ (function () {
2128
2163
  _items.push(r[x.key] = new columnDefsImpl(x, this, remult));
2129
2164
  }
2130
2165
  }
2131
- catch (e_31_1) { e_31 = { error: e_31_1 }; }
2166
+ catch (e_32_1) { e_32 = { error: e_32_1 }; }
2132
2167
  finally {
2133
2168
  try {
2134
2169
  if (columnsInfo_3_1 && !columnsInfo_3_1.done && (_b = columnsInfo_3.return)) _b.call(columnsInfo_3);
2135
2170
  }
2136
- finally { if (e_31) throw e_31.error; }
2171
+ finally { if (e_32) throw e_32.error; }
2137
2172
  }
2138
2173
  this.fields = r;
2139
2174
  this.caption = buildCaption(entityInfo.caption, this.key, remult);
@@ -2307,7 +2342,7 @@ function ValueListFieldType() {
2307
2342
  exports.ValueListFieldType = ValueListFieldType;
2308
2343
  var ValueListInfo = /** @class */ (function () {
2309
2344
  function ValueListInfo(valueListType) {
2310
- var e_32, _a, _b;
2345
+ var e_33, _a, _b;
2311
2346
  var _this = this;
2312
2347
  this.valueListType = valueListType;
2313
2348
  this.byIdMap = new Map();
@@ -2345,12 +2380,12 @@ var ValueListInfo = /** @class */ (function () {
2345
2380
  }
2346
2381
  }
2347
2382
  }
2348
- catch (e_32_1) { e_32 = { error: e_32_1 }; }
2383
+ catch (e_33_1) { e_33 = { error: e_33_1 }; }
2349
2384
  finally {
2350
2385
  try {
2351
2386
  if (options_1_1 && !options_1_1.done && (_a = options_1.return)) _a.call(options_1);
2352
2387
  }
2353
- finally { if (e_32) throw e_32.error; }
2388
+ finally { if (e_33) throw e_33.error; }
2354
2389
  }
2355
2390
  if (this.values.find(function (s) { return s.id === undefined; }))
2356
2391
  throw new Error("ValueType " + this.valueListType + " has values without an id");
@@ -2418,6 +2453,19 @@ function getValueList(type) {
2418
2453
  return ValueListInfo.get(type).getValues();
2419
2454
  }
2420
2455
  exports.getValueList = getValueList;
2456
+ /**Decorates fields that should be used as fields.
2457
+ * for more info see: [Field Types](https://remult.dev/docs/field-types.html)
2458
+ *
2459
+ * FieldOptions can be set in two ways:
2460
+ * @example
2461
+ * // as an object
2462
+ * .@Fields.string({ includeInApi:false })
2463
+ * title='';
2464
+ * @example
2465
+ * // as an arrow function that receives `remult` as a parameter
2466
+ * .@Fields.string((options,remult) => options.includeInApi = true)
2467
+ * title='';
2468
+ */
2421
2469
  function Field(valueType) {
2422
2470
  var options = [];
2423
2471
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -2467,7 +2515,7 @@ function Field(valueType) {
2467
2515
  exports.Field = Field;
2468
2516
  exports.storableMember = Symbol("storableMember");
2469
2517
  function buildOptions(options, remult) {
2470
- var e_33, _a;
2518
+ var e_34, _a;
2471
2519
  var r = {};
2472
2520
  try {
2473
2521
  for (var options_2 = tslib_1.__values(options), options_2_1 = options_2.next(); !options_2_1.done; options_2_1 = options_2.next()) {
@@ -2480,12 +2528,12 @@ function buildOptions(options, remult) {
2480
2528
  }
2481
2529
  }
2482
2530
  }
2483
- catch (e_33_1) { e_33 = { error: e_33_1 }; }
2531
+ catch (e_34_1) { e_34 = { error: e_34_1 }; }
2484
2532
  finally {
2485
2533
  try {
2486
2534
  if (options_2_1 && !options_2_1.done && (_a = options_2.return)) _a.call(options_2);
2487
2535
  }
2488
- finally { if (e_33) throw e_33.error; }
2536
+ finally { if (e_34) throw e_34.error; }
2489
2537
  }
2490
2538
  return r;
2491
2539
  }
@@ -2566,6 +2614,29 @@ function BuildEntity(c, key, fields) {
2566
2614
  }
2567
2615
  }
2568
2616
  exports.BuildEntity = BuildEntity;
2617
+ /**Decorates classes that should be used as entities.
2618
+ * Receives a key and an array of EntityOptions.
2619
+ * @example
2620
+ * import { Entity, Fields } from "remult";
2621
+ * @Entity("tasks", {
2622
+ * allowApiCrud: true
2623
+ * })
2624
+ * export class Task {
2625
+ * @Fields.uuid()
2626
+ * id!: string;
2627
+ * @Fields.string()
2628
+ * title = '';
2629
+ * @Fields.boolean()
2630
+ * completed = false;
2631
+ * }
2632
+ * *EntityOptions can be set in two ways:*
2633
+ * @example
2634
+ * // as an object
2635
+ * .@Entity("tasks",{ allowApiCrud:true })
2636
+ * @example
2637
+ * // as an arrow function that receives `remult` as a parameter
2638
+ * .@Entity("tasks", (options,remult) => options.allowApiCrud = true)
2639
+ */
2569
2640
  function Entity(key) {
2570
2641
  var options = [];
2571
2642
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -2583,7 +2654,7 @@ function Entity(key) {
2583
2654
  }
2584
2655
  }
2585
2656
  var factory = function (remult) {
2586
- var e_34, _a;
2657
+ var e_35, _a;
2587
2658
  var r = {};
2588
2659
  try {
2589
2660
  for (var options_3 = tslib_1.__values(options), options_3_1 = options_3.next(); !options_3_1.done; options_3_1 = options_3.next()) {
@@ -2596,12 +2667,12 @@ function Entity(key) {
2596
2667
  }
2597
2668
  }
2598
2669
  }
2599
- catch (e_34_1) { e_34 = { error: e_34_1 }; }
2670
+ catch (e_35_1) { e_35 = { error: e_35_1 }; }
2600
2671
  finally {
2601
2672
  try {
2602
2673
  if (options_3_1 && !options_3_1.done && (_a = options_3.return)) _a.call(options_3);
2603
2674
  }
2604
- finally { if (e_34) throw e_34.error; }
2675
+ finally { if (e_35) throw e_35.error; }
2605
2676
  }
2606
2677
  var base = Object.getPrototypeOf(target);
2607
2678
  if (base) {
@@ -2707,9 +2778,9 @@ var QueryResultImpl = /** @class */ (function () {
2707
2778
  });
2708
2779
  };
2709
2780
  QueryResultImpl.prototype.forEach = function (what) {
2710
- var e_35, _a;
2781
+ var e_36, _a;
2711
2782
  return tslib_1.__awaiter(this, void 0, void 0, function () {
2712
- var i, _b, _c, x, e_35_1;
2783
+ var i, _b, _c, x, e_36_1;
2713
2784
  return tslib_1.__generator(this, function (_d) {
2714
2785
  switch (_d.label) {
2715
2786
  case 0:
@@ -2731,8 +2802,8 @@ var QueryResultImpl = /** @class */ (function () {
2731
2802
  case 5: return [3 /*break*/, 2];
2732
2803
  case 6: return [3 /*break*/, 13];
2733
2804
  case 7:
2734
- e_35_1 = _d.sent();
2735
- e_35 = { error: e_35_1 };
2805
+ e_36_1 = _d.sent();
2806
+ e_36 = { error: e_36_1 };
2736
2807
  return [3 /*break*/, 13];
2737
2808
  case 8:
2738
2809
  _d.trys.push([8, , 11, 12]);
@@ -2743,7 +2814,7 @@ var QueryResultImpl = /** @class */ (function () {
2743
2814
  _d.label = 10;
2744
2815
  case 10: return [3 /*break*/, 12];
2745
2816
  case 11:
2746
- if (e_35) throw e_35.error;
2817
+ if (e_36) throw e_36.error;
2747
2818
  return [7 /*endfinally*/];
2748
2819
  case 12: return [7 /*endfinally*/];
2749
2820
  case 13: return [2 /*return*/, i];