remult 0.23.0-exp.2 → 0.23.0-exp.21

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.
Files changed (92) hide show
  1. package/README.md +26 -27
  2. package/esm/graphql.js +7 -1
  3. package/esm/index.d.ts +16 -3
  4. package/esm/index.js +17 -2
  5. package/esm/internals.d.ts +2 -1
  6. package/esm/internals.js +1 -1
  7. package/esm/remult-express.js +1 -1
  8. package/esm/remult-knex/index.js +2 -1
  9. package/esm/remult-mongo.js +2 -1
  10. package/esm/server/JsonEntityFileStorage.js +1 -1
  11. package/esm/server/expressBridge.js +1 -1
  12. package/esm/src/CompoundIdField.d.ts +1 -1
  13. package/esm/src/CompoundIdField.js +3 -1
  14. package/esm/src/buildRestDataProvider.d.ts +1 -2
  15. package/esm/src/column-interfaces.d.ts +19 -7
  16. package/esm/src/column.d.ts +4 -18
  17. package/esm/src/column.js +10 -44
  18. package/esm/src/context.d.ts +1 -1
  19. package/esm/src/context.js +5 -1
  20. package/esm/src/data-interfaces.js +1 -2
  21. package/esm/src/data-providers/array-entity-data-provider.d.ts +1 -1
  22. package/esm/src/data-providers/array-entity-data-provider.js +6 -6
  23. package/esm/src/data-providers/sql-database.js +2 -1
  24. package/esm/src/data-providers/web-sql-data-provider.js +3 -3
  25. package/esm/src/entity.d.ts +48 -17
  26. package/esm/src/filter/filter-interfaces.d.ts +2 -16
  27. package/esm/src/filter/filter-interfaces.js +87 -6
  28. package/esm/src/live-query/LiveQueryClient.js +2 -1
  29. package/esm/src/live-query/SubscriptionChannel.js +4 -3
  30. package/esm/src/remult-proxy.js +10 -2
  31. package/esm/src/remult3/Fields.d.ts +140 -21
  32. package/esm/src/remult3/Fields.js +26 -30
  33. package/esm/src/remult3/RepositoryImplementation.d.ts +10 -16
  34. package/esm/src/remult3/RepositoryImplementation.js +165 -48
  35. package/esm/src/remult3/entity.d.ts +1 -1
  36. package/esm/src/remult3/entity.js +0 -1
  37. package/esm/src/remult3/getEntityRef.d.ts +1 -1
  38. package/esm/src/remult3/getEntityRef.js +1 -1
  39. package/esm/src/remult3/relation-loader.js +4 -1
  40. package/esm/src/remult3/remult3.d.ts +132 -7
  41. package/esm/src/remult3/remult3.js +30 -0
  42. package/esm/src/remult3/repository-internals.d.ts +14 -0
  43. package/esm/src/remult3/repository-internals.js +7 -0
  44. package/esm/src/server-action.js +1 -1
  45. package/esm/src/sort.d.ts +3 -3
  46. package/esm/src/sort.js +36 -8
  47. package/graphql.js +10 -2
  48. package/index.d.ts +16 -3
  49. package/index.js +19 -3
  50. package/internals.d.ts +2 -1
  51. package/internals.js +3 -1
  52. package/package.json +1 -1
  53. package/remult-express.js +1 -1
  54. package/remult-knex/index.js +2 -1
  55. package/remult-mongo.js +2 -1
  56. package/server/JsonEntityFileStorage.js +1 -1
  57. package/server/expressBridge.js +1 -1
  58. package/src/CompoundIdField.d.ts +1 -1
  59. package/src/CompoundIdField.js +3 -0
  60. package/src/buildRestDataProvider.d.ts +1 -2
  61. package/src/column-interfaces.d.ts +19 -7
  62. package/src/column.d.ts +4 -18
  63. package/src/column.js +10 -56
  64. package/src/context.d.ts +1 -1
  65. package/src/context.js +5 -1
  66. package/src/data-interfaces.js +1 -2
  67. package/src/data-providers/array-entity-data-provider.d.ts +1 -1
  68. package/src/data-providers/array-entity-data-provider.js +5 -6
  69. package/src/data-providers/sql-database.js +2 -1
  70. package/src/data-providers/web-sql-data-provider.js +3 -3
  71. package/src/entity.d.ts +48 -17
  72. package/src/filter/filter-interfaces.d.ts +2 -16
  73. package/src/filter/filter-interfaces.js +101 -9
  74. package/src/live-query/LiveQueryClient.js +2 -1
  75. package/src/live-query/SubscriptionChannel.js +4 -3
  76. package/src/remult-proxy.js +43 -29
  77. package/src/remult3/Fields.d.ts +140 -21
  78. package/src/remult3/Fields.js +32 -32
  79. package/src/remult3/RepositoryImplementation.d.ts +10 -16
  80. package/src/remult3/RepositoryImplementation.js +286 -163
  81. package/src/remult3/entity.d.ts +1 -1
  82. package/src/remult3/entity.js +0 -1
  83. package/src/remult3/getEntityRef.d.ts +1 -1
  84. package/src/remult3/getEntityRef.js +2 -1
  85. package/src/remult3/relation-loader.js +4 -1
  86. package/src/remult3/remult3.d.ts +132 -7
  87. package/src/remult3/remult3.js +30 -0
  88. package/src/remult3/repository-internals.d.ts +14 -0
  89. package/src/remult3/repository-internals.js +11 -0
  90. package/src/server-action.js +1 -1
  91. package/src/sort.d.ts +3 -3
  92. package/src/sort.js +43 -11
@@ -8,7 +8,6 @@ var context_1 = require("../context");
8
8
  var filter_interfaces_1 = require("../filter/filter-interfaces");
9
9
  var sort_1 = require("../sort");
10
10
  var assign_1 = require("../../assign");
11
- var filter_interfaces_2 = require("../filter/filter-interfaces");
12
11
  var valueConverters_1 = require("../valueConverters");
13
12
  var rest_data_provider_1 = require("../data-providers/rest-data-provider");
14
13
  var remult_proxy_1 = require("../remult-proxy");
@@ -16,6 +15,7 @@ var getEntityRef_1 = require("./getEntityRef");
16
15
  var __updateEntityBasedOnWhere_1 = require("./__updateEntityBasedOnWhere");
17
16
  var relationInfoMember_1 = require("./relationInfoMember");
18
17
  var relation_loader_1 = require("./relation-loader");
18
+ var repository_internals_1 = require("./repository-internals");
19
19
  //import { remult } from "../remult-proxy";
20
20
  var classValidatorValidate = undefined;
21
21
  // import ("class-validator".toString())
@@ -45,9 +45,12 @@ var RepositoryImplementation = /** @class */ (function () {
45
45
  this.idCache = new Map();
46
46
  this.cache = new Map();
47
47
  }
48
+ RepositoryImplementation.prototype[repository_internals_1.getInternalKey] = function () {
49
+ return this;
50
+ };
48
51
  RepositoryImplementation.prototype.createAfterFilter = function (orderBy, lastRow) {
49
52
  return tslib_1.__awaiter(this, void 0, void 0, function () {
50
- var values, _a, _b, s, existingVal, r, equalToColumn, _c, _d, s, ff, f, equalToColumn_1, equalToColumn_1_1, c;
53
+ var values, _a, _b, s, existingVal, r, equalToColumn, _c, _d, s, f, equalToColumn_1, equalToColumn_1_1, c;
51
54
  var e_1, _e, e_2, _f, e_3, _g;
52
55
  return tslib_1.__generator(this, function (_h) {
53
56
  values = new Map();
@@ -80,7 +83,6 @@ var RepositoryImplementation = /** @class */ (function () {
80
83
  for (_c = tslib_1.__values(sort_1.Sort.translateOrderByToSort(this.metadata, orderBy)
81
84
  .Segments), _d = _c.next(); !_d.done; _d = _c.next()) {
82
85
  s = _d.value;
83
- ff = new filter_interfaces_2.filterHelper(s.field);
84
86
  f = {};
85
87
  try {
86
88
  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()) {
@@ -385,6 +387,8 @@ var RepositoryImplementation = /** @class */ (function () {
385
387
  for (key in entity) {
386
388
  if (Object.prototype.hasOwnProperty.call(entity, key)) {
387
389
  f = ref.fields[key];
390
+ if (entity[key] === undefined && (0, relationInfoMember_1.getRelationInfo)(f.metadata.options))
391
+ continue;
388
392
  if (f)
389
393
  r[key] = entity[key];
390
394
  }
@@ -490,7 +494,6 @@ var RepositoryImplementation = /** @class */ (function () {
490
494
  case 0:
491
495
  if (!options)
492
496
  options = {};
493
- context_1.Remult.onFind(this._info, options);
494
497
  if (this.defaultFindOptions) {
495
498
  options = tslib_1.__assign(tslib_1.__assign({}, this.defaultFindOptions), options);
496
499
  }
@@ -501,6 +504,7 @@ var RepositoryImplementation = /** @class */ (function () {
501
504
  delete opt.orderBy;
502
505
  delete opt.limit;
503
506
  }
507
+ context_1.Remult.onFind(this._info, options);
504
508
  return [4 /*yield*/, this.edp.find(opt)];
505
509
  case 2:
506
510
  rawRows = _a.sent();
@@ -546,9 +550,12 @@ var RepositoryImplementation = /** @class */ (function () {
546
550
  return [4 /*yield*/, this.translateWhereToFilter(options.where)];
547
551
  case 1:
548
552
  _a.where = _b.sent();
549
- opt.orderBy = sort_1.Sort.translateOrderByToSort(this.metadata, options.orderBy);
550
- opt.limit = options.limit;
551
- opt.page = options.page;
553
+ if (options.orderBy !== undefined)
554
+ opt.orderBy = sort_1.Sort.translateOrderByToSort(this.metadata, options.orderBy);
555
+ if (options.limit !== undefined)
556
+ opt.limit = options.limit;
557
+ if (options.page !== undefined)
558
+ opt.page = options.page;
552
559
  return [2 /*return*/, opt];
553
560
  }
554
561
  });
@@ -641,13 +648,9 @@ var RepositoryImplementation = /** @class */ (function () {
641
648
  if (!ei) return [3 /*break*/, 5];
642
649
  isRelation = (_a = col.options) === null || _a === void 0 ? void 0 : _a[relationInfoMember_1.relationInfoMember];
643
650
  if (!!isRelation) return [3 /*break*/, 4];
644
- load = isRelation
645
- ? (_b = col.options) === null || _b === void 0 ? void 0 : _b.defaultIncluded
646
- : !col.options.lazy;
651
+ load = !col.options.lazy;
647
652
  if (loadFields !== undefined)
648
653
  load = loadFields.includes(col);
649
- if (loadOptions.include)
650
- load = loadOptions.include[col.key];
651
654
  if (!load) return [3 /*break*/, 4];
652
655
  repo = this.remult.repo(col.valueType);
653
656
  toLoad = [];
@@ -658,7 +661,7 @@ var RepositoryImplementation = /** @class */ (function () {
658
661
  if (val !== undefined &&
659
662
  val !== null &&
660
663
  !toLoad.includes(val) &&
661
- !repo.idCache.has(val)) {
664
+ !repo.idCache.has(val + '')) {
662
665
  toLoad.push(val);
663
666
  }
664
667
  }
@@ -709,7 +712,7 @@ var RepositoryImplementation = /** @class */ (function () {
709
712
  var rel = (0, relationInfoMember_1.getRelationInfo)(col.options);
710
713
  var incl = col.options
711
714
  .defaultIncluded;
712
- if (loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.include) {
715
+ if (((_b = loadOptions === null || loadOptions === void 0 ? void 0 : loadOptions.include) === null || _b === void 0 ? void 0 : _b[col.key]) !== undefined) {
713
716
  incl = loadOptions.include[col.key];
714
717
  }
715
718
  if (rel && incl) {
@@ -731,7 +734,7 @@ var RepositoryImplementation = /** @class */ (function () {
731
734
  row[col.key] =
732
735
  rel.type !== 'toMany'
733
736
  ? result.length == 0
734
- ? undefined
737
+ ? null
735
738
  : result[0]
736
739
  : result;
737
740
  });
@@ -773,7 +776,7 @@ var RepositoryImplementation = /** @class */ (function () {
773
776
  };
774
777
  /*@internal */
775
778
  RepositoryImplementation.prototype.findOptionsBasedOnRelation = function (rel, field, moreFindOptions, row, otherRepo) {
776
- var e_13, _a, e_14, _b, _c, _d;
779
+ var e_13, _a, e_14, _b, e_15, _c, _d, _e;
777
780
  var returnNull = false;
778
781
  var where = [];
779
782
  var findOptions = {};
@@ -793,12 +796,12 @@ var RepositoryImplementation = /** @class */ (function () {
793
796
  if (source.where)
794
797
  where.push(source.where);
795
798
  try {
796
- for (var _e = (e_14 = void 0, tslib_1.__values([
799
+ for (var _f = (e_14 = void 0, tslib_1.__values([
797
800
  'limit',
798
801
  'include',
799
802
  'orderBy',
800
- ])), _f = _e.next(); !_f.done; _f = _e.next()) {
801
- var key = _f.value;
803
+ ])), _g = _f.next(); !_g.done; _g = _f.next()) {
804
+ var key = _g.value;
802
805
  //@ts-ignore
803
806
  if (source[key])
804
807
  findOptions[key] = source[key];
@@ -807,7 +810,7 @@ var RepositoryImplementation = /** @class */ (function () {
807
810
  catch (e_14_1) { e_14 = { error: e_14_1 }; }
808
811
  finally {
809
812
  try {
810
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
813
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
811
814
  }
812
815
  finally { if (e_14) throw e_14.error; }
813
816
  }
@@ -820,26 +823,81 @@ var RepositoryImplementation = /** @class */ (function () {
820
823
  }
821
824
  finally { if (e_13) throw e_13.error; }
822
825
  }
826
+ function buildError(what) {
827
+ return Error("Error for relation: \"".concat(field.key, "\" to \"").concat(otherRepo.metadata.key, "\": ") +
828
+ what);
829
+ }
830
+ var hasFields = function () { return options.field || options.fields; };
831
+ if (rel.type === 'toMany' && !hasFields()) {
832
+ try {
833
+ for (var _h = tslib_1.__values(otherRepo.fields.toArray()), _j = _h.next(); !_j.done; _j = _h.next()) {
834
+ var fieldInOtherRepo = _j.value;
835
+ if (!hasFields()) {
836
+ var reverseRel = (0, relationInfoMember_1.getRelationInfo)(fieldInOtherRepo.options);
837
+ var relOp = fieldInOtherRepo.options;
838
+ if (reverseRel)
839
+ if (reverseRel.toType() === this.entity)
840
+ if (reverseRel.type === 'reference') {
841
+ options = tslib_1.__assign(tslib_1.__assign({}, findOptions), { field: fieldInOtherRepo.key });
842
+ }
843
+ else if (reverseRel.type === 'toOne') {
844
+ if (relOp.field) {
845
+ options = tslib_1.__assign(tslib_1.__assign({}, options), { field: relOp.field });
846
+ }
847
+ else if (relOp.fields) {
848
+ var fields = {};
849
+ for (var key in relOp.fields) {
850
+ if (Object.prototype.hasOwnProperty.call(relOp.fields, key)) {
851
+ var keyInMyTable = relOp.fields[key];
852
+ fields[keyInMyTable] = key;
853
+ }
854
+ }
855
+ options = tslib_1.__assign(tslib_1.__assign({}, options), { fields: fields });
856
+ }
857
+ }
858
+ }
859
+ }
860
+ }
861
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
862
+ finally {
863
+ try {
864
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
865
+ }
866
+ finally { if (e_15) throw e_15.error; }
867
+ }
868
+ if (!hasFields())
869
+ throw buildError("No matching field found on target. Please specify field/fields");
870
+ }
871
+ function requireField(field, meta) {
872
+ var result = meta.fields.find(field);
873
+ if (!result)
874
+ throw buildError("Field \"".concat(field, "\" was not found in \"").concat(meta.key, "\"."));
875
+ return result;
876
+ }
823
877
  if (options.field) {
824
878
  if (rel.type === 'toOne') {
879
+ requireField(options.field, this.metadata);
825
880
  where.push(otherRepo.metadata.idMetadata.getIdFilter(row[options.field]));
826
881
  }
827
882
  else {
828
- where.push((_c = {},
829
- _c[options.field] = this.metadata.idMetadata.getId(row),
830
- _c));
883
+ requireField(options.field, otherRepo.metadata);
884
+ where.push((_d = {},
885
+ _d[options.field] = this.metadata.idMetadata.getId(row),
886
+ _d));
831
887
  }
832
888
  }
833
889
  else if (options.fields) {
834
890
  for (var key in options.fields) {
835
891
  if (Object.prototype.hasOwnProperty.call(options.fields, key)) {
836
- where.push((_d = {}, _d[key] = row[options.fields[key]], _d));
892
+ requireField(options.fields[key], this.metadata);
893
+ requireField(key, otherRepo.metadata);
894
+ where.push((_e = {}, _e[key] = row[options.fields[key]], _e));
837
895
  }
838
896
  }
839
897
  }
840
898
  else if (rel.type === 'toOne' || rel.type === 'reference') {
841
899
  var val = rel.type === 'reference'
842
- ? (0, getEntityRef_1.getEntityRef)(row).fields.find(field.key).getId()
900
+ ? (0, getEntityRef_1.getEntityRef)(row).fields.find(requireField(field.key, this.metadata)).getId()
843
901
  : row[field.key];
844
902
  if (val === null)
845
903
  returnNull = true;
@@ -889,7 +947,7 @@ var RepositoryImplementation = /** @class */ (function () {
889
947
  return this.getEntityRef(item).toApiJson(true);
890
948
  };
891
949
  RepositoryImplementation.prototype.fromJson = function (json, newRow) {
892
- var e_15, _a;
950
+ var e_16, _a;
893
951
  var _this = this;
894
952
  if (json === null || json === undefined)
895
953
  return json;
@@ -912,12 +970,12 @@ var RepositoryImplementation = /** @class */ (function () {
912
970
  }
913
971
  }
914
972
  }
915
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
973
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
916
974
  finally {
917
975
  try {
918
976
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
919
977
  }
920
- finally { if (e_15) throw e_15.error; }
978
+ finally { if (e_16) throw e_16.error; }
921
979
  }
922
980
  this.fixTypes(result);
923
981
  if (newRow) {
@@ -1019,7 +1077,7 @@ var RepositoryImplementation = /** @class */ (function () {
1019
1077
  return this.metadata.fields.toArray().filter(function (x) { return keys.includes(x.key); });
1020
1078
  };
1021
1079
  RepositoryImplementation.prototype.create = function (item) {
1022
- var e_16, _a;
1080
+ var e_17, _a;
1023
1081
  var _b;
1024
1082
  var r = new this.entity(this.remult);
1025
1083
  if (item) {
@@ -1029,12 +1087,12 @@ var RepositoryImplementation = /** @class */ (function () {
1029
1087
  r[field.key] = item[field.key];
1030
1088
  }
1031
1089
  }
1032
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
1090
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
1033
1091
  finally {
1034
1092
  try {
1035
1093
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1036
1094
  }
1037
- finally { if (e_16) throw e_16.error; }
1095
+ finally { if (e_17) throw e_17.error; }
1038
1096
  }
1039
1097
  this.fixTypes(r);
1040
1098
  }
@@ -1048,7 +1106,7 @@ var RepositoryImplementation = /** @class */ (function () {
1048
1106
  RepositoryImplementation.prototype.fixTypes = function (item) {
1049
1107
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1050
1108
  var _a, _b, field, val, _c, _d, _e, type, typeName;
1051
- var e_17, _f, e_18, _g;
1109
+ var e_18, _f, e_19, _g;
1052
1110
  return tslib_1.__generator(this, function (_h) {
1053
1111
  try {
1054
1112
  for (_a = tslib_1.__values(this.fieldsOf(item)), _b = _a.next(); !_b.done; _b = _a.next()) {
@@ -1059,7 +1117,7 @@ var RepositoryImplementation = /** @class */ (function () {
1059
1117
  item[field.key] = field.valueConverter.fromJson(field.valueConverter.toJson(val));
1060
1118
  else
1061
1119
  try {
1062
- for (_c = (e_18 = void 0, tslib_1.__values([
1120
+ for (_c = (e_19 = void 0, tslib_1.__values([
1063
1121
  [String, 'string'],
1064
1122
  [Number, 'number'],
1065
1123
  [Boolean, 'boolean'],
@@ -1069,22 +1127,22 @@ var RepositoryImplementation = /** @class */ (function () {
1069
1127
  item[field.key] = field.valueConverter.fromJson(field.valueConverter.toJson(val));
1070
1128
  }
1071
1129
  }
1072
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
1130
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
1073
1131
  finally {
1074
1132
  try {
1075
1133
  if (_d && !_d.done && (_g = _c.return)) _g.call(_c);
1076
1134
  }
1077
- finally { if (e_18) throw e_18.error; }
1135
+ finally { if (e_19) throw e_19.error; }
1078
1136
  }
1079
1137
  }
1080
1138
  }
1081
1139
  }
1082
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
1140
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
1083
1141
  finally {
1084
1142
  try {
1085
1143
  if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
1086
1144
  }
1087
- finally { if (e_17) throw e_17.error; }
1145
+ finally { if (e_18) throw e_18.error; }
1088
1146
  }
1089
1147
  return [2 /*return*/, item];
1090
1148
  });
@@ -1149,7 +1207,7 @@ function createOldEntity(entity, remult) {
1149
1207
  var key = (0, getEntityRef_1.getEntityKey)(entity);
1150
1208
  var base = Object.getPrototypeOf(entity);
1151
1209
  var _loop_3 = function () {
1152
- var e_19, _a;
1210
+ var e_20, _a;
1153
1211
  var baseCols = exports.columnsOfType.get(base);
1154
1212
  if (baseCols) {
1155
1213
  r.unshift.apply(r, tslib_1.__spreadArray([], tslib_1.__read(baseCols.filter(function (x) { return !r.find(function (y) { return y.key == x.key; }); })), false));
@@ -1184,17 +1242,17 @@ function createOldEntity(entity, remult) {
1184
1242
  }
1185
1243
  };
1186
1244
  try {
1187
- for (var _b = (e_19 = void 0, tslib_1.__values(functions)), _c = _b.next(); !_c.done; _c = _b.next()) {
1245
+ for (var _b = (e_20 = void 0, tslib_1.__values(functions)), _c = _b.next(); !_c.done; _c = _b.next()) {
1188
1246
  var key_1 = _c.value;
1189
1247
  _loop_4(key_1);
1190
1248
  }
1191
1249
  }
1192
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
1250
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
1193
1251
  finally {
1194
1252
  try {
1195
1253
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1196
1254
  }
1197
- finally { if (e_19) throw e_19.error; }
1255
+ finally { if (e_20) throw e_20.error; }
1198
1256
  }
1199
1257
  }
1200
1258
  base = Object.getPrototypeOf(base);
@@ -1206,12 +1264,14 @@ function createOldEntity(entity, remult) {
1206
1264
  }
1207
1265
  exports.createOldEntity = createOldEntity;
1208
1266
  var rowHelperBase = /** @class */ (function () {
1209
- function rowHelperBase(columnsInfo, instance, remult) {
1210
- var e_20, _a;
1267
+ function rowHelperBase(columnsInfo, instance, remult, isNewRow) {
1268
+ var e_21, _a;
1211
1269
  var _this = this;
1270
+ var _b;
1212
1271
  this.columnsInfo = columnsInfo;
1213
1272
  this.instance = instance;
1214
1273
  this.remult = remult;
1274
+ this.isNewRow = isNewRow;
1215
1275
  this._isLoading = false;
1216
1276
  this.lookups = new Map();
1217
1277
  this.originalValues = {};
@@ -1258,7 +1318,38 @@ var rowHelperBase = /** @class */ (function () {
1258
1318
  });
1259
1319
  lookup_1.set(val);
1260
1320
  }
1261
- else {
1321
+ else if (((_b = (0, relationInfoMember_1.getRelationInfo)(col)) === null || _b === void 0 ? void 0 : _b.type) === 'toOne') {
1322
+ var hasVal = instance.hasOwnProperty(col.key);
1323
+ var val_1 = instance[col.key];
1324
+ if (isNewRow && !val_1)
1325
+ hasVal = false;
1326
+ Object.defineProperty(instance, col.key, {
1327
+ get: function () {
1328
+ return val_1;
1329
+ },
1330
+ set: function (newVal) {
1331
+ val_1 = newVal;
1332
+ if (newVal === undefined)
1333
+ return;
1334
+ var op = col;
1335
+ if (op.field) {
1336
+ _this.instance[op.field] = _this.remult
1337
+ .repo((0, relationInfoMember_1.getRelationInfo)(col).toType())
1338
+ .metadata.idMetadata.getId(newVal);
1339
+ }
1340
+ if (op.fields) {
1341
+ for (var key in op.fields) {
1342
+ if (Object.prototype.hasOwnProperty.call(op.fields, key)) {
1343
+ var element = op.fields[key];
1344
+ _this.instance[element] = newVal[key];
1345
+ }
1346
+ }
1347
+ }
1348
+ },
1349
+ enumerable: true,
1350
+ });
1351
+ if (hasVal)
1352
+ instance[col.key] = val_1;
1262
1353
  }
1263
1354
  };
1264
1355
  var this_2 = this;
@@ -1268,12 +1359,12 @@ var rowHelperBase = /** @class */ (function () {
1268
1359
  _loop_5(col);
1269
1360
  }
1270
1361
  }
1271
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
1362
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
1272
1363
  finally {
1273
1364
  try {
1274
1365
  if (columnsInfo_1_1 && !columnsInfo_1_1.done && (_a = columnsInfo_1.return)) _a.call(columnsInfo_1);
1275
1366
  }
1276
- finally { if (e_20) throw e_20.error; }
1367
+ finally { if (e_21) throw e_21.error; }
1277
1368
  }
1278
1369
  }
1279
1370
  Object.defineProperty(rowHelperBase.prototype, "error", {
@@ -1295,7 +1386,7 @@ var rowHelperBase = /** @class */ (function () {
1295
1386
  return this._subscribers.subscribe(listener);
1296
1387
  };
1297
1388
  rowHelperBase.prototype.initSubscribers = function () {
1298
- var e_21, _a;
1389
+ var e_22, _a;
1299
1390
  var _this = this;
1300
1391
  if (!this._subscribers) {
1301
1392
  this._subscribers = new SubscribableImp();
@@ -1306,15 +1397,15 @@ var rowHelperBase = /** @class */ (function () {
1306
1397
  if (ei && this_3.remult) {
1307
1398
  }
1308
1399
  else {
1309
- var val_1 = this_3.instance[col.key];
1400
+ var val_2 = this_3.instance[col.key];
1310
1401
  Object.defineProperty(this_3.instance, col.key, {
1311
1402
  get: function () {
1312
1403
  _this._subscribers.reportObserved();
1313
1404
  refImpl._subscribers.reportObserved();
1314
- return val_1;
1405
+ return val_2;
1315
1406
  },
1316
1407
  set: function (value) {
1317
- val_1 = value;
1408
+ val_2 = value;
1318
1409
  _this._subscribers.reportChanged();
1319
1410
  refImpl._subscribers.reportChanged();
1320
1411
  },
@@ -1329,12 +1420,12 @@ var rowHelperBase = /** @class */ (function () {
1329
1420
  _loop_6(col);
1330
1421
  }
1331
1422
  }
1332
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
1423
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
1333
1424
  finally {
1334
1425
  try {
1335
1426
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1336
1427
  }
1337
- finally { if (e_21) throw e_21.error; }
1428
+ finally { if (e_22) throw e_22.error; }
1338
1429
  }
1339
1430
  }
1340
1431
  };
@@ -1369,7 +1460,7 @@ var rowHelperBase = /** @class */ (function () {
1369
1460
  throw this.buildErrorInfoObject();
1370
1461
  };
1371
1462
  rowHelperBase.prototype.buildErrorInfoObject = function () {
1372
- var e_22, _a;
1463
+ var e_23, _a;
1373
1464
  var error = {
1374
1465
  modelState: Object.assign({}, this.errors),
1375
1466
  message: this.error,
@@ -1386,12 +1477,12 @@ var rowHelperBase = /** @class */ (function () {
1386
1477
  }
1387
1478
  }
1388
1479
  }
1389
- catch (e_22_1) { e_22 = { error: e_22_1 }; }
1480
+ catch (e_23_1) { e_23 = { error: e_23_1 }; }
1390
1481
  finally {
1391
1482
  try {
1392
1483
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1393
1484
  }
1394
- finally { if (e_22) throw e_22.error; }
1485
+ finally { if (e_23) throw e_23.error; }
1395
1486
  }
1396
1487
  }
1397
1488
  return error;
@@ -1425,7 +1516,7 @@ var rowHelperBase = /** @class */ (function () {
1425
1516
  this._reportChangedToEntityAndFields();
1426
1517
  };
1427
1518
  rowHelperBase.prototype._reportChangedToEntityAndFields = function () {
1428
- var e_23, _a;
1519
+ var e_24, _a;
1429
1520
  if (this._subscribers) {
1430
1521
  this._subscribers.reportChanged();
1431
1522
  try {
@@ -1435,12 +1526,12 @@ var rowHelperBase = /** @class */ (function () {
1435
1526
  ref._subscribers.reportChanged();
1436
1527
  }
1437
1528
  }
1438
- catch (e_23_1) { e_23 = { error: e_23_1 }; }
1529
+ catch (e_24_1) { e_24 = { error: e_24_1 }; }
1439
1530
  finally {
1440
1531
  try {
1441
1532
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1442
1533
  }
1443
- finally { if (e_23) throw e_23.error; }
1534
+ finally { if (e_24) throw e_24.error; }
1444
1535
  }
1445
1536
  }
1446
1537
  };
@@ -1450,7 +1541,7 @@ var rowHelperBase = /** @class */ (function () {
1450
1541
  return !!!this.error && this.errors == undefined;
1451
1542
  };
1452
1543
  rowHelperBase.prototype.copyDataToObject = function () {
1453
- var e_24, _a;
1544
+ var e_25, _a;
1454
1545
  var d = {};
1455
1546
  try {
1456
1547
  for (var _b = tslib_1.__values(this.columnsInfo), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -1466,15 +1557,17 @@ var rowHelperBase = /** @class */ (function () {
1466
1557
  if (val !== undefined && val !== null)
1467
1558
  val = col.valueConverter.fromJson(JSON.parse(JSON.stringify(val)));
1468
1559
  }
1469
- d[col.key] = val;
1560
+ var rel = (0, relationInfoMember_1.getRelationInfo)(col);
1561
+ if (!rel || rel.type === 'reference')
1562
+ d[col.key] = val;
1470
1563
  }
1471
1564
  }
1472
- catch (e_24_1) { e_24 = { error: e_24_1 }; }
1565
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
1473
1566
  finally {
1474
1567
  try {
1475
1568
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1476
1569
  }
1477
- finally { if (e_24) throw e_24.error; }
1570
+ finally { if (e_25) throw e_25.error; }
1478
1571
  }
1479
1572
  return d;
1480
1573
  };
@@ -1534,7 +1627,7 @@ var rowHelperBase = /** @class */ (function () {
1534
1627
  }); });
1535
1628
  };
1536
1629
  rowHelperBase.prototype.toApiJson = function (includeRelatedEntities) {
1537
- var e_25, _a;
1630
+ var e_26, _a;
1538
1631
  if (includeRelatedEntities === void 0) { includeRelatedEntities = false; }
1539
1632
  var result = {};
1540
1633
  try {
@@ -1542,7 +1635,7 @@ var rowHelperBase = /** @class */ (function () {
1542
1635
  var col = _c.value;
1543
1636
  if (!this.remult ||
1544
1637
  col.includeInApi === undefined ||
1545
- this.remult.isAllowed(col.includeInApi)) {
1638
+ this.remult.isAllowedForInstance(this.instance, col.includeInApi)) {
1546
1639
  var val = void 0;
1547
1640
  var lu = this.lookups.get(col.key);
1548
1641
  var disable = false;
@@ -1570,19 +1663,20 @@ var rowHelperBase = /** @class */ (function () {
1570
1663
  }
1571
1664
  }
1572
1665
  }
1573
- catch (e_25_1) { e_25 = { error: e_25_1 }; }
1666
+ catch (e_26_1) { e_26 = { error: e_26_1 }; }
1574
1667
  finally {
1575
1668
  try {
1576
1669
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1577
1670
  }
1578
- finally { if (e_25) throw e_25.error; }
1671
+ finally { if (e_26) throw e_26.error; }
1579
1672
  }
1580
1673
  return result;
1581
1674
  };
1582
- rowHelperBase.prototype._updateEntityBasedOnApi = function (body) {
1675
+ rowHelperBase.prototype._updateEntityBasedOnApi = function (body, ignoreApiAllowed) {
1676
+ if (ignoreApiAllowed === void 0) { ignoreApiAllowed = false; }
1583
1677
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1584
1678
  var keys, _a, _b, col, lu;
1585
- var e_26, _c;
1679
+ var e_27, _c;
1586
1680
  return tslib_1.__generator(this, function (_d) {
1587
1681
  switch (_d.label) {
1588
1682
  case 0:
@@ -1592,8 +1686,9 @@ var rowHelperBase = /** @class */ (function () {
1592
1686
  col = _b.value;
1593
1687
  if (keys.includes(col.key))
1594
1688
  if (col.includeInApi === undefined ||
1595
- this.remult.isAllowed(col.includeInApi)) {
1689
+ this.remult.isAllowedForInstance(this.instance, col.includeInApi)) {
1596
1690
  if (!this.remult ||
1691
+ ignoreApiAllowed ||
1597
1692
  col.allowApiUpdate === undefined ||
1598
1693
  this.remult.isAllowedForInstance(this.instance, col.allowApiUpdate)) {
1599
1694
  lu = this.lookups.get(col.key);
@@ -1605,12 +1700,12 @@ var rowHelperBase = /** @class */ (function () {
1605
1700
  }
1606
1701
  }
1607
1702
  }
1608
- catch (e_26_1) { e_26 = { error: e_26_1 }; }
1703
+ catch (e_27_1) { e_27 = { error: e_27_1 }; }
1609
1704
  finally {
1610
1705
  try {
1611
1706
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1612
1707
  }
1613
- finally { if (e_26) throw e_26.error; }
1708
+ finally { if (e_27) throw e_27.error; }
1614
1709
  }
1615
1710
  return [4 /*yield*/, Promise.all(tslib_1.__spreadArray([], tslib_1.__read(this.fields), false).map(function (x) { return x.load(); }))];
1616
1711
  case 1:
@@ -1625,8 +1720,8 @@ var rowHelperBase = /** @class */ (function () {
1625
1720
  var rowHelperImplementation = /** @class */ (function (_super) {
1626
1721
  tslib_1.__extends(rowHelperImplementation, _super);
1627
1722
  function rowHelperImplementation(info, instance, repository, edp, remult, _isNew) {
1628
- var e_27, _a;
1629
- var _this = _super.call(this, info.columnsInfo, instance, remult) || this;
1723
+ var e_28, _a;
1724
+ var _this = _super.call(this, info.columnsInfo, instance, remult, _isNew) || this;
1630
1725
  _this.info = info;
1631
1726
  _this.repository = repository;
1632
1727
  _this.edp = edp;
@@ -1647,12 +1742,12 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1647
1742
  }
1648
1743
  }
1649
1744
  }
1650
- catch (e_27_1) { e_27 = { error: e_27_1 }; }
1745
+ catch (e_28_1) { e_28 = { error: e_28_1 }; }
1651
1746
  finally {
1652
1747
  try {
1653
1748
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1654
1749
  }
1655
- finally { if (e_27) throw e_27.error; }
1750
+ finally { if (e_28) throw e_28.error; }
1656
1751
  }
1657
1752
  }
1658
1753
  if (_this.info.options.entityRefInit)
@@ -1661,6 +1756,13 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1661
1756
  context_1.Remult.entityRefInit(_this, instance);
1662
1757
  return _this;
1663
1758
  }
1759
+ Object.defineProperty(rowHelperImplementation.prototype, "relations", {
1760
+ get: function () {
1761
+ return this.repository.relations(this.instance);
1762
+ },
1763
+ enumerable: false,
1764
+ configurable: true
1765
+ });
1664
1766
  Object.defineProperty(rowHelperImplementation.prototype, "apiUpdateAllowed", {
1665
1767
  get: function () {
1666
1768
  return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiUpdate);
@@ -1732,7 +1834,7 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1732
1834
  };
1733
1835
  Object.defineProperty(rowHelperImplementation.prototype, "fields", {
1734
1836
  get: function () {
1735
- var _a, e_28, _b;
1837
+ var _a, e_29, _b;
1736
1838
  if (!this._columns) {
1737
1839
  var _items_1 = [];
1738
1840
  var r_1 = (_a = {
@@ -1749,12 +1851,12 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1749
1851
  _items_1.push((r_1[c.key] = new FieldRefImplementation(c, this.info.fields[c.key], this.instance, this, this)));
1750
1852
  }
1751
1853
  }
1752
- catch (e_28_1) { e_28 = { error: e_28_1 }; }
1854
+ catch (e_29_1) { e_29 = { error: e_29_1 }; }
1753
1855
  finally {
1754
1856
  try {
1755
1857
  if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1756
1858
  }
1757
- finally { if (e_28) throw e_28.error; }
1859
+ finally { if (e_29) throw e_29.error; }
1758
1860
  }
1759
1861
  this._columns = r_1;
1760
1862
  }
@@ -1766,8 +1868,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1766
1868
  rowHelperImplementation.prototype.save = function (onlyTheseFieldsSentOnlyInTheCaseOfProxySaveWithPartialObject) {
1767
1869
  var _a;
1768
1870
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1769
- var doNotSave_1, _b, _c, col, e_29_1, d, ignoreKeys, _d, _e, field, f, updatedRow, isNew, changesOnly, wasChanged, key, element, _f, _g, listener, e_30_1, err_1;
1770
- var e_29, _h, e_31, _j, e_30, _k;
1871
+ var doNotSave_1, e, _b, _c, col, e_30_1, d, ignoreKeys, _d, _e, field, f, updatedRow, isNew, changesOnly, wasChanged, key, element, _f, _g, listener, e_31_1, err_1;
1872
+ var e_30, _h, e_32, _j, e_31, _k;
1771
1873
  return tslib_1.__generator(this, function (_l) {
1772
1874
  switch (_l.label) {
1773
1875
  case 0:
@@ -1788,6 +1890,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1788
1890
  _l.label = 2;
1789
1891
  case 2:
1790
1892
  doNotSave_1 = false;
1893
+ e = this.buildLifeCycleEvent(function () { return (doNotSave_1 = true); });
1894
+ if (!!this.remult.dataProvider.isProxy) return [3 /*break*/, 12];
1791
1895
  _l.label = 3;
1792
1896
  case 3:
1793
1897
  _l.trys.push([3, 8, 9, 10]);
@@ -1797,7 +1901,7 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1797
1901
  if (!!_c.done) return [3 /*break*/, 7];
1798
1902
  col = _c.value;
1799
1903
  if (!col.metadata.options.saving) return [3 /*break*/, 6];
1800
- return [4 /*yield*/, col.metadata.options.saving(this.instance, col)];
1904
+ return [4 /*yield*/, col.metadata.options.saving(this.instance, e, col)];
1801
1905
  case 5:
1802
1906
  _l.sent();
1803
1907
  _l.label = 6;
@@ -1806,18 +1910,18 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1806
1910
  return [3 /*break*/, 4];
1807
1911
  case 7: return [3 /*break*/, 10];
1808
1912
  case 8:
1809
- e_29_1 = _l.sent();
1810
- e_29 = { error: e_29_1 };
1913
+ e_30_1 = _l.sent();
1914
+ e_30 = { error: e_30_1 };
1811
1915
  return [3 /*break*/, 10];
1812
1916
  case 9:
1813
1917
  try {
1814
1918
  if (_c && !_c.done && (_h = _b.return)) _h.call(_b);
1815
1919
  }
1816
- finally { if (e_29) throw e_29.error; }
1920
+ finally { if (e_30) throw e_30.error; }
1817
1921
  return [7 /*endfinally*/];
1818
1922
  case 10:
1819
1923
  if (!this.info.entityInfo.saving) return [3 /*break*/, 12];
1820
- return [4 /*yield*/, this.info.entityInfo.saving(this.instance, function () { return (doNotSave_1 = true); })];
1924
+ return [4 /*yield*/, this.info.entityInfo.saving(this.instance, e)];
1821
1925
  case 11:
1822
1926
  _l.sent();
1823
1927
  _l.label = 12;
@@ -1839,15 +1943,13 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1839
1943
  }
1840
1944
  }
1841
1945
  }
1842
- catch (e_31_1) { e_31 = { error: e_31_1 }; }
1946
+ catch (e_32_1) { e_32 = { error: e_32_1 }; }
1843
1947
  finally {
1844
1948
  try {
1845
1949
  if (_e && !_e.done && (_j = _d.return)) _j.call(_d);
1846
1950
  }
1847
- finally { if (e_31) throw e_31.error; }
1951
+ finally { if (e_32) throw e_32.error; }
1848
1952
  }
1849
- if (this.info.idMetadata.field instanceof CompoundIdField_1.CompoundIdField)
1850
- delete d.id;
1851
1953
  updatedRow = void 0;
1852
1954
  isNew = this.isNew();
1853
1955
  _l.label = 13;
@@ -1886,8 +1988,9 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1886
1988
  case 19: return [4 /*yield*/, this.loadDataFrom(updatedRow)];
1887
1989
  case 20:
1888
1990
  _l.sent();
1991
+ if (!!this.remult.dataProvider.isProxy) return [3 /*break*/, 30];
1889
1992
  if (!this.info.entityInfo.saved) return [3 /*break*/, 22];
1890
- return [4 /*yield*/, this.info.entityInfo.saved(this.instance)];
1993
+ return [4 /*yield*/, this.info.entityInfo.saved(this.instance, e)];
1891
1994
  case 21:
1892
1995
  _l.sent();
1893
1996
  _l.label = 22;
@@ -1910,14 +2013,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1910
2013
  return [3 /*break*/, 24];
1911
2014
  case 27: return [3 /*break*/, 30];
1912
2015
  case 28:
1913
- e_30_1 = _l.sent();
1914
- e_30 = { error: e_30_1 };
2016
+ e_31_1 = _l.sent();
2017
+ e_31 = { error: e_31_1 };
1915
2018
  return [3 /*break*/, 30];
1916
2019
  case 29:
1917
2020
  try {
1918
2021
  if (_g && !_g.done && (_k = _f.return)) _k.call(_f);
1919
2022
  }
1920
- finally { if (e_30) throw e_30.error; }
2023
+ finally { if (e_31) throw e_31.error; }
1921
2024
  return [7 /*endfinally*/];
1922
2025
  case 30: return [4 /*yield*/, this.repository.remult.liveQueryPublisher.itemChanged(this.repository.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: false }])];
1923
2026
  case 31:
@@ -1942,19 +2045,35 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1942
2045
  });
1943
2046
  });
1944
2047
  };
2048
+ rowHelperImplementation.prototype.buildLifeCycleEvent = function (preventDefault) {
2049
+ if (preventDefault === void 0) { preventDefault = function () { }; }
2050
+ var self = this;
2051
+ return {
2052
+ isNew: self.isNew(),
2053
+ fields: self.fields,
2054
+ id: self.getId(),
2055
+ originalId: self.getOriginalId(),
2056
+ metadata: self.repository.metadata,
2057
+ repository: self.repository,
2058
+ preventDefault: function () { return preventDefault(); },
2059
+ relations: self.repository.relations(self.instance),
2060
+ };
2061
+ };
1945
2062
  rowHelperImplementation.prototype.getIdFilter = function () {
1946
2063
  return filter_interfaces_1.Filter.fromEntityFilter(this.metadata, this.repository.metadata.idMetadata.getIdFilter(this.id));
1947
2064
  };
1948
2065
  rowHelperImplementation.prototype.delete = function () {
1949
2066
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1950
- var _a, _b, listener, e_32_1, err_2;
1951
- var e_32, _c;
2067
+ var e, _a, _b, listener, e_33_1, err_2;
2068
+ var e_33, _c;
1952
2069
  return tslib_1.__generator(this, function (_d) {
1953
2070
  switch (_d.label) {
1954
2071
  case 0:
1955
2072
  this.__clearErrorsAndReportChanged();
2073
+ e = this.buildLifeCycleEvent();
2074
+ if (!!this.remult.dataProvider.isProxy) return [3 /*break*/, 2];
1956
2075
  if (!this.info.entityInfo.deleting) return [3 /*break*/, 2];
1957
- return [4 /*yield*/, this.info.entityInfo.deleting(this.instance)];
2076
+ return [4 /*yield*/, this.info.entityInfo.deleting(this.instance, e)];
1958
2077
  case 1:
1959
2078
  _d.sent();
1960
2079
  _d.label = 2;
@@ -1966,8 +2085,9 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1966
2085
  return [4 /*yield*/, this.edp.delete(this.id)];
1967
2086
  case 4:
1968
2087
  _d.sent();
2088
+ if (!!this.remult.dataProvider.isProxy) return [3 /*break*/, 6];
1969
2089
  if (!this.info.entityInfo.deleted) return [3 /*break*/, 6];
1970
- return [4 /*yield*/, this.info.entityInfo.deleted(this.instance)];
2090
+ return [4 /*yield*/, this.info.entityInfo.deleted(this.instance, e)];
1971
2091
  case 5:
1972
2092
  _d.sent();
1973
2093
  _d.label = 6;
@@ -1990,14 +2110,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1990
2110
  return [3 /*break*/, 8];
1991
2111
  case 11: return [3 /*break*/, 14];
1992
2112
  case 12:
1993
- e_32_1 = _d.sent();
1994
- e_32 = { error: e_32_1 };
2113
+ e_33_1 = _d.sent();
2114
+ e_33 = { error: e_33_1 };
1995
2115
  return [3 /*break*/, 14];
1996
2116
  case 13:
1997
2117
  try {
1998
2118
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1999
2119
  }
2000
- finally { if (e_32) throw e_32.error; }
2120
+ finally { if (e_33) throw e_33.error; }
2001
2121
  return [7 /*endfinally*/];
2002
2122
  case 14: return [4 /*yield*/, this.repository.remult.liveQueryPublisher.itemChanged(this.repository.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: true }])];
2003
2123
  case 15:
@@ -2017,8 +2137,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2017
2137
  };
2018
2138
  rowHelperImplementation.prototype.loadDataFrom = function (data, loadItems) {
2019
2139
  return tslib_1.__awaiter(this, void 0, void 0, function () {
2020
- var _a, _b, col, lu, e_33_1;
2021
- var e_33, _c;
2140
+ var _a, _b, col, lu, e_34_1;
2141
+ var e_34, _c;
2022
2142
  return tslib_1.__generator(this, function (_d) {
2023
2143
  switch (_d.label) {
2024
2144
  case 0:
@@ -2054,14 +2174,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2054
2174
  return [3 /*break*/, 1];
2055
2175
  case 9: return [3 /*break*/, 12];
2056
2176
  case 10:
2057
- e_33_1 = _d.sent();
2058
- e_33 = { error: e_33_1 };
2177
+ e_34_1 = _d.sent();
2178
+ e_34 = { error: e_34_1 };
2059
2179
  return [3 /*break*/, 12];
2060
2180
  case 11:
2061
2181
  try {
2062
2182
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2063
2183
  }
2064
- finally { if (e_33) throw e_33.error; }
2184
+ finally { if (e_34) throw e_34.error; }
2065
2185
  return [7 /*endfinally*/];
2066
2186
  case 12: return [4 /*yield*/, this.calcServerExpression()];
2067
2187
  case 13:
@@ -2077,8 +2197,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2077
2197
  };
2078
2198
  rowHelperImplementation.prototype.calcServerExpression = function () {
2079
2199
  return tslib_1.__awaiter(this, void 0, void 0, function () {
2080
- var _a, _b, col, _c, _d, e_34_1;
2081
- var e_34, _e;
2200
+ var _a, _b, col, _c, _d, e_35_1;
2201
+ var e_35, _e;
2082
2202
  return tslib_1.__generator(this, function (_f) {
2083
2203
  switch (_f.label) {
2084
2204
  case 0:
@@ -2103,14 +2223,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2103
2223
  return [3 /*break*/, 2];
2104
2224
  case 5: return [3 /*break*/, 8];
2105
2225
  case 6:
2106
- e_34_1 = _f.sent();
2107
- e_34 = { error: e_34_1 };
2226
+ e_35_1 = _f.sent();
2227
+ e_35 = { error: e_35_1 };
2108
2228
  return [3 /*break*/, 8];
2109
2229
  case 7:
2110
2230
  try {
2111
2231
  if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
2112
2232
  }
2113
- finally { if (e_34) throw e_34.error; }
2233
+ finally { if (e_35) throw e_35.error; }
2114
2234
  return [7 /*endfinally*/];
2115
2235
  case 8: return [2 /*return*/];
2116
2236
  }
@@ -2123,7 +2243,7 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2123
2243
  return this._isNew;
2124
2244
  };
2125
2245
  rowHelperImplementation.prototype.wasChanged = function () {
2126
- var e_35, _a;
2246
+ var e_36, _a;
2127
2247
  var _b;
2128
2248
  (_b = this._subscribers) === null || _b === void 0 ? void 0 : _b.reportObserved();
2129
2249
  try {
@@ -2133,19 +2253,19 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2133
2253
  return true;
2134
2254
  }
2135
2255
  }
2136
- catch (e_35_1) { e_35 = { error: e_35_1 }; }
2256
+ catch (e_36_1) { e_36 = { error: e_36_1 }; }
2137
2257
  finally {
2138
2258
  try {
2139
2259
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
2140
2260
  }
2141
- finally { if (e_35) throw e_35.error; }
2261
+ finally { if (e_36) throw e_36.error; }
2142
2262
  }
2143
2263
  return false;
2144
2264
  };
2145
2265
  rowHelperImplementation.prototype.__performColumnAndEntityValidations = function () {
2146
2266
  return tslib_1.__awaiter(this, void 0, void 0, function () {
2147
- var _a, _b, c, col, e_36_1, _c, _d, listener, e_37_1;
2148
- var e_36, _e, e_37, _f;
2267
+ var _a, _b, c, col, e_37_1, e, _c, _d, listener, e_38_1;
2268
+ var e_37, _e, e_38, _f;
2149
2269
  return tslib_1.__generator(this, function (_g) {
2150
2270
  switch (_g.label) {
2151
2271
  case 0:
@@ -2166,18 +2286,19 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2166
2286
  return [3 /*break*/, 1];
2167
2287
  case 4: return [3 /*break*/, 7];
2168
2288
  case 5:
2169
- e_36_1 = _g.sent();
2170
- e_36 = { error: e_36_1 };
2289
+ e_37_1 = _g.sent();
2290
+ e_37 = { error: e_37_1 };
2171
2291
  return [3 /*break*/, 7];
2172
2292
  case 6:
2173
2293
  try {
2174
2294
  if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
2175
2295
  }
2176
- finally { if (e_36) throw e_36.error; }
2296
+ finally { if (e_37) throw e_37.error; }
2177
2297
  return [7 /*endfinally*/];
2178
2298
  case 7:
2179
2299
  if (!this.info.entityInfo.validation) return [3 /*break*/, 9];
2180
- return [4 /*yield*/, this.info.entityInfo.validation(this.instance, this)];
2300
+ e = this.buildLifeCycleEvent(function () { });
2301
+ return [4 /*yield*/, this.info.entityInfo.validation(this.instance, e)];
2181
2302
  case 8:
2182
2303
  _g.sent();
2183
2304
  _g.label = 9;
@@ -2200,14 +2321,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2200
2321
  return [3 /*break*/, 11];
2201
2322
  case 14: return [3 /*break*/, 17];
2202
2323
  case 15:
2203
- e_37_1 = _g.sent();
2204
- e_37 = { error: e_37_1 };
2324
+ e_38_1 = _g.sent();
2325
+ e_38 = { error: e_38_1 };
2205
2326
  return [3 /*break*/, 17];
2206
2327
  case 16:
2207
2328
  try {
2208
2329
  if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
2209
2330
  }
2210
- finally { if (e_37) throw e_37.error; }
2331
+ finally { if (e_38) throw e_38.error; }
2211
2332
  return [7 /*endfinally*/];
2212
2333
  case 17: return [2 /*return*/];
2213
2334
  }
@@ -2250,8 +2371,8 @@ exports.getControllerRef = getControllerRef;
2250
2371
  var controllerRefImpl = /** @class */ (function (_super) {
2251
2372
  tslib_1.__extends(controllerRefImpl, _super);
2252
2373
  function controllerRefImpl(columnsInfo, instance, remult) {
2253
- var _a, e_38, _b;
2254
- var _this = _super.call(this, columnsInfo, instance, remult) || this;
2374
+ var _a, e_39, _b;
2375
+ var _this = _super.call(this, columnsInfo, instance, remult, false) || this;
2255
2376
  var _items = [];
2256
2377
  var r = (_a = {
2257
2378
  find: function (c) {
@@ -2267,20 +2388,20 @@ var controllerRefImpl = /** @class */ (function (_super) {
2267
2388
  _items.push((r[col.key] = new FieldRefImplementation(col, new columnDefsImpl(col, undefined, remult), instance, undefined, _this)));
2268
2389
  }
2269
2390
  }
2270
- catch (e_38_1) { e_38 = { error: e_38_1 }; }
2391
+ catch (e_39_1) { e_39 = { error: e_39_1 }; }
2271
2392
  finally {
2272
2393
  try {
2273
2394
  if (columnsInfo_2_1 && !columnsInfo_2_1.done && (_b = columnsInfo_2.return)) _b.call(columnsInfo_2);
2274
2395
  }
2275
- finally { if (e_38) throw e_38.error; }
2396
+ finally { if (e_39) throw e_39.error; }
2276
2397
  }
2277
2398
  _this.fields = r;
2278
2399
  return _this;
2279
2400
  }
2280
2401
  controllerRefImpl.prototype.__performColumnAndEntityValidations = function () {
2281
2402
  return tslib_1.__awaiter(this, void 0, void 0, function () {
2282
- var _a, _b, col, e_39_1;
2283
- var e_39, _c;
2403
+ var _a, _b, col, e_40_1;
2404
+ var e_40, _c;
2284
2405
  return tslib_1.__generator(this, function (_d) {
2285
2406
  switch (_d.label) {
2286
2407
  case 0:
@@ -2300,14 +2421,14 @@ var controllerRefImpl = /** @class */ (function (_super) {
2300
2421
  return [3 /*break*/, 1];
2301
2422
  case 4: return [3 /*break*/, 7];
2302
2423
  case 5:
2303
- e_39_1 = _d.sent();
2304
- e_39 = { error: e_39_1 };
2424
+ e_40_1 = _d.sent();
2425
+ e_40 = { error: e_40_1 };
2305
2426
  return [3 /*break*/, 7];
2306
2427
  case 6:
2307
2428
  try {
2308
2429
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2309
2430
  }
2310
- finally { if (e_39) throw e_39.error; }
2431
+ finally { if (e_40) throw e_40.error; }
2311
2432
  return [7 /*endfinally*/];
2312
2433
  case 7: return [2 /*return*/];
2313
2434
  }
@@ -2487,8 +2608,8 @@ var FieldRefImplementation = /** @class */ (function () {
2487
2608
  };
2488
2609
  FieldRefImplementation.prototype.__performValidation = function () {
2489
2610
  return tslib_1.__awaiter(this, void 0, void 0, function () {
2490
- var x, _a, _b, v, e_40_1, error_1;
2491
- var e_40, _c;
2611
+ var x, _a, _b, v, e_41_1, error_1;
2612
+ var e_41, _c;
2492
2613
  return tslib_1.__generator(this, function (_d) {
2493
2614
  switch (_d.label) {
2494
2615
  case 0:
@@ -2512,14 +2633,14 @@ var FieldRefImplementation = /** @class */ (function () {
2512
2633
  return [3 /*break*/, 2];
2513
2634
  case 5: return [3 /*break*/, 8];
2514
2635
  case 6:
2515
- e_40_1 = _d.sent();
2516
- e_40 = { error: e_40_1 };
2636
+ e_41_1 = _d.sent();
2637
+ e_41 = { error: e_41_1 };
2517
2638
  return [3 /*break*/, 8];
2518
2639
  case 7:
2519
2640
  try {
2520
2641
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2521
2642
  }
2522
- finally { if (e_40) throw e_40.error; }
2643
+ finally { if (e_41) throw e_41.error; }
2523
2644
  return [7 /*endfinally*/];
2524
2645
  case 8: return [3 /*break*/, 11];
2525
2646
  case 9:
@@ -2605,15 +2726,11 @@ var columnDefsImpl = /** @class */ (function () {
2605
2726
  .getEntityMetadataWithoutBreakingTheEntity(item)
2606
2727
  .fields.find(this.key).displayValue;
2607
2728
  };
2608
- Object.defineProperty(columnDefsImpl.prototype, "includedInApi", {
2609
- get: function () {
2610
- if (this.options.includeInApi === undefined)
2611
- return true;
2612
- return this.remult.isAllowed(this.options.includeInApi); //TODO 2- consolidate other code paths to go through here
2613
- },
2614
- enumerable: false,
2615
- configurable: true
2616
- });
2729
+ columnDefsImpl.prototype.includedInApi = function (item) {
2730
+ if (this.options.includeInApi === undefined)
2731
+ return true;
2732
+ return this.remult.isAllowedForInstance(item, this.options.includeInApi);
2733
+ };
2617
2734
  columnDefsImpl.prototype.toInput = function (value, inputType) {
2618
2735
  return this.valueConverter.toInput(value, inputType);
2619
2736
  };
@@ -2677,7 +2794,7 @@ var columnDefsImpl = /** @class */ (function () {
2677
2794
  exports.columnDefsImpl = columnDefsImpl;
2678
2795
  var EntityFullInfo = /** @class */ (function () {
2679
2796
  function EntityFullInfo(columnsInfo, entityInfo, remult, entityType, key) {
2680
- var _a, e_41, _b;
2797
+ var _a, e_42, _b;
2681
2798
  var _this = this;
2682
2799
  this.columnsInfo = columnsInfo;
2683
2800
  this.entityInfo = entityInfo;
@@ -2686,6 +2803,8 @@ var EntityFullInfo = /** @class */ (function () {
2686
2803
  this.key = key;
2687
2804
  this.idMetadata = {
2688
2805
  getId: function (item) {
2806
+ if (item === undefined || item === null)
2807
+ return item;
2689
2808
  var ref = (0, getEntityRef_1.getEntityRef)(item, false);
2690
2809
  if (ref)
2691
2810
  return ref.getId();
@@ -2765,17 +2884,19 @@ var EntityFullInfo = /** @class */ (function () {
2765
2884
  _items.push((r[x.key] = new columnDefsImpl(x, this, remult)));
2766
2885
  }
2767
2886
  }
2768
- catch (e_41_1) { e_41 = { error: e_41_1 }; }
2887
+ catch (e_42_1) { e_42 = { error: e_42_1 }; }
2769
2888
  finally {
2770
2889
  try {
2771
2890
  if (columnsInfo_3_1 && !columnsInfo_3_1.done && (_b = columnsInfo_3.return)) _b.call(columnsInfo_3);
2772
2891
  }
2773
- finally { if (e_41) throw e_41.error; }
2892
+ finally { if (e_42) throw e_42.error; }
2774
2893
  }
2775
2894
  this.fields = r;
2776
2895
  this.caption = buildCaption(entityInfo.caption, this.key, remult);
2777
2896
  if (entityInfo.id) {
2778
- var r_2 = entityInfo.id(this.fields);
2897
+ var r_2 = typeof entityInfo.id === 'function'
2898
+ ? entityInfo.id(this.fields)
2899
+ : Object.keys(entityInfo.id).map(function (x) { return _this.fields.find(x); });
2779
2900
  if (Array.isArray(r_2)) {
2780
2901
  if (r_2.length > 1)
2781
2902
  this.idMetadata.field = new (CompoundIdField_1.CompoundIdField.bind.apply(CompoundIdField_1.CompoundIdField, tslib_1.__spreadArray([void 0], tslib_1.__read(r_2), false)))();
@@ -2889,7 +3010,7 @@ function ValueListFieldType() {
2889
3010
  exports.ValueListFieldType = ValueListFieldType;
2890
3011
  var ValueListInfo = /** @class */ (function () {
2891
3012
  function ValueListInfo(valueListType) {
2892
- var e_42, _a, _b;
3013
+ var e_43, _a, _b;
2893
3014
  var _this = this;
2894
3015
  this.valueListType = valueListType;
2895
3016
  this.byIdMap = new Map();
@@ -2927,12 +3048,12 @@ var ValueListInfo = /** @class */ (function () {
2927
3048
  }
2928
3049
  }
2929
3050
  }
2930
- catch (e_42_1) { e_42 = { error: e_42_1 }; }
3051
+ catch (e_43_1) { e_43 = { error: e_43_1 }; }
2931
3052
  finally {
2932
3053
  try {
2933
3054
  if (options_1_1 && !options_1_1.done && (_a = options_1.return)) _a.call(options_1);
2934
3055
  }
2935
- finally { if (e_42) throw e_42.error; }
3056
+ finally { if (e_43) throw e_43.error; }
2936
3057
  }
2937
3058
  if (this.values.find(function (s) { return s.id === undefined; }))
2938
3059
  throw new Error("ValueType ".concat(this.valueListType, " has values without an id"));
@@ -3003,7 +3124,7 @@ function getValueList(type) {
3003
3124
  exports.getValueList = getValueList;
3004
3125
  exports.storableMember = Symbol('storableMember');
3005
3126
  function buildOptions(options, remult) {
3006
- var e_43, _a;
3127
+ var e_44, _a;
3007
3128
  var r = {};
3008
3129
  try {
3009
3130
  for (var options_2 = tslib_1.__values(options), options_2_1 = options_2.next(); !options_2_1.done; options_2_1 = options_2.next()) {
@@ -3016,12 +3137,12 @@ function buildOptions(options, remult) {
3016
3137
  }
3017
3138
  }
3018
3139
  }
3019
- catch (e_43_1) { e_43 = { error: e_43_1 }; }
3140
+ catch (e_44_1) { e_44 = { error: e_44_1 }; }
3020
3141
  finally {
3021
3142
  try {
3022
3143
  if (options_2_1 && !options_2_1.done && (_a = options_2.return)) _a.call(options_2);
3023
3144
  }
3024
- finally { if (e_43) throw e_43.error; }
3145
+ finally { if (e_44) throw e_44.error; }
3025
3146
  }
3026
3147
  return r;
3027
3148
  }
@@ -3064,7 +3185,7 @@ function decorateColumnSettings(settings, remult) {
3064
3185
  };
3065
3186
  settings.valueConverter = new Proxy(settings.valueConverter, {
3066
3187
  get: function (target, property) {
3067
- var e_44, _a;
3188
+ var e_45, _a;
3068
3189
  if (target[property] === undefined) {
3069
3190
  if (isIdNumeric_1 === undefined) {
3070
3191
  if (property === 'inputType')
@@ -3087,12 +3208,12 @@ function decorateColumnSettings(settings, remult) {
3087
3208
  : valueConverters_1.ValueConverters.String[key];
3088
3209
  }
3089
3210
  }
3090
- catch (e_44_1) { e_44 = { error: e_44_1 }; }
3211
+ catch (e_45_1) { e_45 = { error: e_45_1 }; }
3091
3212
  finally {
3092
3213
  try {
3093
3214
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3094
3215
  }
3095
- finally { if (e_44) throw e_44.error; }
3216
+ finally { if (e_45) throw e_45.error; }
3096
3217
  }
3097
3218
  }
3098
3219
  }
@@ -3211,6 +3332,7 @@ var QueryResultImpl = /** @class */ (function () {
3211
3332
  limit: this.options.pageSize,
3212
3333
  page: page,
3213
3334
  load: this.options.load,
3335
+ include: this.options.include,
3214
3336
  })];
3215
3337
  });
3216
3338
  });
@@ -3233,9 +3355,9 @@ var QueryResultImpl = /** @class */ (function () {
3233
3355
  });
3234
3356
  };
3235
3357
  QueryResultImpl.prototype.forEach = function (what) {
3236
- var _a, e_45, _b, _c;
3358
+ var _a, e_46, _b, _c;
3237
3359
  return tslib_1.__awaiter(this, void 0, void 0, function () {
3238
- var i, _d, _e, _f, x, e_45_1;
3360
+ var i, _d, _e, _f, x, e_46_1;
3239
3361
  return tslib_1.__generator(this, function (_g) {
3240
3362
  switch (_g.label) {
3241
3363
  case 0:
@@ -3261,8 +3383,8 @@ var QueryResultImpl = /** @class */ (function () {
3261
3383
  return [3 /*break*/, 2];
3262
3384
  case 6: return [3 /*break*/, 13];
3263
3385
  case 7:
3264
- e_45_1 = _g.sent();
3265
- e_45 = { error: e_45_1 };
3386
+ e_46_1 = _g.sent();
3387
+ e_46 = { error: e_46_1 };
3266
3388
  return [3 /*break*/, 13];
3267
3389
  case 8:
3268
3390
  _g.trys.push([8, , 11, 12]);
@@ -3273,7 +3395,7 @@ var QueryResultImpl = /** @class */ (function () {
3273
3395
  _g.label = 10;
3274
3396
  case 10: return [3 /*break*/, 12];
3275
3397
  case 11:
3276
- if (e_45) throw e_45.error;
3398
+ if (e_46) throw e_46.error;
3277
3399
  return [7 /*endfinally*/];
3278
3400
  case 12: return [7 /*endfinally*/];
3279
3401
  case 13: return [2 /*return*/, i];
@@ -3296,6 +3418,7 @@ var QueryResultImpl = /** @class */ (function () {
3296
3418
  orderBy: this.options.orderBy,
3297
3419
  limit: this.options.pageSize,
3298
3420
  load: this.options.load,
3421
+ include: this.options.include,
3299
3422
  })];
3300
3423
  case 1:
3301
3424
  items = _a.sent();