remult 0.26.23 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/SseSubscriptionServer.d.ts +3 -4
  2. package/assign.js +1 -2
  3. package/esm/graphql.js +1 -1
  4. package/esm/remult-hono.js +3 -1
  5. package/esm/remult-knex/index.js +3 -1
  6. package/esm/remult-sqlite3.js +4 -1
  7. package/esm/remult-sveltekit.js +1 -0
  8. package/esm/server/index.js +3 -2
  9. package/esm/server/initAsyncHooks.js +3 -3
  10. package/esm/server/remult-admin.js +1 -4
  11. package/esm/server/remult-api-server.js +47 -48
  12. package/esm/src/CompoundIdField.js +9 -9
  13. package/esm/src/data-api.js +1 -1
  14. package/esm/src/data-providers/json-entity-opfs-storage.js +9 -5
  15. package/esm/src/data-providers/sql-database.js +9 -9
  16. package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +3 -1
  17. package/esm/src/filter/filter-interfaces.js +1 -1
  18. package/esm/src/live-query/LiveQueryClient.js +0 -1
  19. package/esm/src/remult-proxy.js +1 -3
  20. package/esm/src/remult-static.js +1 -0
  21. package/esm/src/remult3/Fields.js +15 -7
  22. package/esm/src/remult3/RepositoryImplementation.js +165 -125
  23. package/esm/src/remult3/entity.js +1 -1
  24. package/esm/src/remult3/relation-loader.js +2 -2
  25. package/esm/src/remult3/remult3.js +15 -0
  26. package/esm/src/server-action.js +16 -12
  27. package/esm/src/sort.js +0 -2
  28. package/esm/src/validators.js +3 -3
  29. package/esm/src/valueConverters.js +2 -2
  30. package/graphql.js +3 -4
  31. package/index.js +2 -2
  32. package/live-query/data-provider-live-query-storage.js +6 -6
  33. package/migrations/compare-migration-snapshots.js +48 -49
  34. package/migrations/generate-migrations.js +1 -2
  35. package/migrations/migrate.js +2 -3
  36. package/migrations/migration-types.d.ts +1 -1
  37. package/migrations/migration-types.js +4 -4
  38. package/migrations/update-migrations-ts-file.js +1 -2
  39. package/myLog.js +1 -2
  40. package/package.json +1 -1
  41. package/postgres/postgres-data-provider.d.ts +2 -2
  42. package/postgres/postgres-data-provider.js +5 -5
  43. package/postgres/schema-builder.d.ts +1 -1
  44. package/postgres/schema-builder.js +3 -3
  45. package/remult-express.js +4 -3
  46. package/remult-fastify.js +4 -3
  47. package/remult-fresh.js +1 -2
  48. package/remult-hapi.js +4 -3
  49. package/remult-hono.js +6 -3
  50. package/remult-knex/index.d.ts +2 -2
  51. package/remult-knex/index.js +7 -5
  52. package/remult-mongo.d.ts +1 -1
  53. package/remult-next.d.ts +5 -6
  54. package/remult-next.js +11 -6
  55. package/remult-nuxt.js +1 -2
  56. package/remult-solid-start.js +1 -2
  57. package/remult-sqlite3.js +4 -1
  58. package/remult-sveltekit.d.ts +1 -1
  59. package/remult-sveltekit.js +33 -35
  60. package/server/JsonEntityFileStorage.d.ts +1 -1
  61. package/server/get-remult-admin-html.js +1 -2
  62. package/server/index.js +4 -3
  63. package/server/initAsyncHooks.d.ts +10 -10
  64. package/server/initAsyncHooks.js +5 -2
  65. package/server/initDataProvider.js +1 -2
  66. package/server/initDataProviderOrJson.js +1 -2
  67. package/server/remult-admin.js +3 -7
  68. package/server/remult-api-server.d.ts +21 -21
  69. package/server/remult-api-server.js +54 -48
  70. package/src/CompoundIdField.d.ts +2 -2
  71. package/src/CompoundIdField.js +9 -0
  72. package/src/buildRestDataProvider.d.ts +1 -1
  73. package/src/buildRestDataProvider.js +8 -8
  74. package/src/column-interfaces.d.ts +4 -4
  75. package/src/column-interfaces.js +1 -2
  76. package/src/column.d.ts +4 -4
  77. package/src/column.js +2 -2
  78. package/src/context.d.ts +4 -4
  79. package/src/context.js +5 -5
  80. package/src/data-api.d.ts +4 -4
  81. package/src/data-api.js +4 -4
  82. package/src/data-interfaces.d.ts +1 -1
  83. package/src/data-interfaces.js +1 -2
  84. package/src/data-providers/json-entity-opfs-storage.js +30 -16
  85. package/src/data-providers/rest-data-provider.d.ts +3 -3
  86. package/src/data-providers/rest-data-provider.js +4 -4
  87. package/src/data-providers/sql-database.d.ts +1 -1
  88. package/src/data-providers/sql-database.js +11 -11
  89. package/src/data-providers/web-sql-data-provider.d.ts +2 -2
  90. package/src/entity.d.ts +1 -1
  91. package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +3 -3
  92. package/src/filter/filter-consumer-bridge-to-sql-request.js +21 -19
  93. package/src/filter/filter-interfaces.d.ts +2 -1
  94. package/src/filter/filter-interfaces.js +10 -7
  95. package/src/isOfType.js +2 -3
  96. package/src/live-query/SubscriptionServer.js +95 -97
  97. package/src/remult-proxy.js +1 -3
  98. package/src/remult-static.d.ts +2 -2
  99. package/src/remult-static.js +7 -4
  100. package/src/remult3/Fields.d.ts +17 -17
  101. package/src/remult3/Fields.js +22 -13
  102. package/src/remult3/RepositoryImplementation.d.ts +51 -46
  103. package/src/remult3/RepositoryImplementation.js +421 -368
  104. package/src/remult3/__updateEntityBasedOnWhere.js +1 -2
  105. package/src/remult3/addValidator.d.ts +1 -1
  106. package/src/remult3/addValidator.js +1 -2
  107. package/src/remult3/classDescribers.d.ts +4 -4
  108. package/src/remult3/classDescribers.js +3 -4
  109. package/src/remult3/columnInfo.d.ts +1 -1
  110. package/src/remult3/entity.js +2 -4
  111. package/src/remult3/getEntityRef.js +4 -4
  112. package/src/remult3/relation-loader.d.ts +1 -1
  113. package/src/remult3/relationInfoMember.d.ts +3 -3
  114. package/src/remult3/relationInfoMember.js +4 -5
  115. package/src/remult3/remult3.d.ts +23 -20
  116. package/src/remult3/remult3.js +15 -0
  117. package/src/remult3/repository-internals.d.ts +3 -3
  118. package/src/remult3/repository-internals.js +2 -2
  119. package/src/server-action.d.ts +2 -2
  120. package/src/server-action.js +65 -58
  121. package/src/sort.d.ts +1 -1
  122. package/src/sort.js +0 -2
  123. package/src/sql-command.d.ts +1 -1
  124. package/src/validators.d.ts +1 -1
  125. package/src/validators.js +13 -11
  126. package/src/valueConverters.js +3 -2
@@ -333,7 +333,8 @@ export class RepositoryImplementation {
333
333
  if (!ref) {
334
334
  const instance = new this._entity(this._remult);
335
335
  for (const field of this._fieldsOf(entity)) {
336
- instance[field.key] = entity[field.key];
336
+ const key = field.key;
337
+ instance[key] = entity[key];
337
338
  }
338
339
  this._fixTypes(instance);
339
340
  let row = new rowHelperImplementation(this._info, instance, this, this._edp, this._remult, false);
@@ -386,7 +387,8 @@ export class RepositoryImplementation {
386
387
  }
387
388
  listener.error ??= () => { };
388
389
  listener.complete ??= () => { };
389
- return this._remult.liveQuerySubscriber.subscribe(this, options, listener);
390
+ return this._remult.liveQuerySubscriber.subscribe(//TODO - figure out why the type was required
391
+ this, options, listener);
390
392
  },
391
393
  };
392
394
  }
@@ -481,15 +483,17 @@ export class RepositoryImplementation {
481
483
  let rel = getRelationFieldInfo(col);
482
484
  let incl = col.options
483
485
  .defaultIncluded;
484
- if (loadOptions?.include?.[col.key] !== undefined) {
485
- incl = loadOptions.include[col.key];
486
+ const include = loadOptions?.include?.[col.key];
487
+ if (include !== undefined) {
488
+ incl = include;
486
489
  }
487
490
  if (rel && incl) {
488
491
  const otherRepo = rel.toRepo;
489
492
  for (const row of result) {
490
493
  let { findOptions, returnNull } = this._findOptionsBasedOnRelation(rel, col, incl, row, otherRepo);
494
+ const colKey = col.key;
491
495
  if (returnNull)
492
- row[col.key] = null;
496
+ row[colKey] = null;
493
497
  else {
494
498
  const entityType = rel.toEntity;
495
499
  const toRepo = otherRepo;
@@ -502,7 +506,7 @@ export class RepositoryImplementation {
502
506
  .then((result) => {
503
507
  if (result.length == 0 && rel.type == 'toOne')
504
508
  return;
505
- row[col.key] =
509
+ row[colKey] =
506
510
  rel.type !== 'toMany'
507
511
  ? result.length == 0
508
512
  ? null
@@ -580,8 +584,6 @@ export class RepositoryImplementation {
580
584
  return { findOptions, returnNull, returnUndefined };
581
585
  }
582
586
  async _mapRawDataToResult(r, loadFields) {
583
- if (!r)
584
- return undefined;
585
587
  let x = new this._entity(this._remult);
586
588
  let helper = new rowHelperImplementation(this._info, x, this, this._edp, this._remult, false);
587
589
  Object.defineProperty(x, entityMember, {
@@ -608,17 +610,18 @@ export class RepositoryImplementation {
608
610
  return json.map((item) => this.fromJson(item, newRow));
609
611
  let result = new this._entity(this._remult);
610
612
  for (const col of this._fieldsOf(json)) {
613
+ const colKey = col.key;
611
614
  let ei = getEntitySettings(col.valueType, false);
612
615
  if (ei) {
613
616
  let val = json[col.key];
614
617
  if (typeof val === 'string' || typeof val === 'number')
615
- result[col.key] = val;
618
+ result[colKey] = val;
616
619
  else
617
- result[col.key] = this._remult.repo(col.valueType).fromJson(val);
620
+ result[colKey] = this._remult.repo(col.valueType).fromJson(val);
618
621
  }
619
622
  else {
620
- if (json[col.key] !== undefined) {
621
- result[col.key] = col.valueConverter.fromJson(json[col.key]);
623
+ if (json[colKey] !== undefined) {
624
+ result[colKey] = col.valueConverter.fromJson(json[col.key]);
622
625
  }
623
626
  }
624
627
  }
@@ -654,11 +657,10 @@ export class RepositoryImplementation {
654
657
  }
655
658
  }
656
659
  _cache = new Map();
657
- async findOne(options, skipOrderByAndLimit = false) {
660
+ async findOne(pOptions, skipOrderByAndLimit = false) {
658
661
  let r;
659
662
  let cacheInfo;
660
- if (!options)
661
- options = {};
663
+ let options = pOptions ?? {};
662
664
  if (options.useCache) {
663
665
  let f = findOptionsToJson(options, this.metadata);
664
666
  let key = JSON.stringify(f);
@@ -670,7 +672,7 @@ export class RepositoryImplementation {
670
672
  this._cache.delete(key);
671
673
  }
672
674
  else
673
- return this._cache.get(key).promise;
675
+ return cacheInfo.promise;
674
676
  }
675
677
  else {
676
678
  cacheInfo = {
@@ -723,7 +725,8 @@ export class RepositoryImplementation {
723
725
  let r = new this._entity(this._remult);
724
726
  if (item) {
725
727
  for (const field of this._fieldsOf(item)) {
726
- r[field.key] = item[field.key];
728
+ const key = field.key;
729
+ r[key] = item[key];
727
730
  }
728
731
  this._fixTypes(r);
729
732
  }
@@ -755,7 +758,7 @@ export class RepositoryImplementation {
755
758
  }
756
759
  findId(id, options) {
757
760
  if (id === null || id === undefined)
758
- return null;
761
+ return Promise.resolve(null);
759
762
  if (typeof id !== 'string' && typeof id !== 'number')
760
763
  throw new Error('id can be either number or string, but got: ' + typeof id);
761
764
  return this.findFirst({}, {
@@ -764,24 +767,23 @@ export class RepositoryImplementation {
764
767
  }, true);
765
768
  }
766
769
  async _translateWhereToFilter(where) {
767
- if (!where)
768
- where = {};
770
+ let safeWhere = where ?? {};
769
771
  if (this._defaultFindOptions?.where) {
770
- let z = where;
771
- where = {
772
+ let z = safeWhere;
773
+ safeWhere = {
772
774
  $and: [z, this._defaultFindOptions?.where],
773
775
  };
774
776
  }
775
777
  if (!this._dataProvider.isProxy) {
776
778
  if (this.metadata.options.backendPreprocessFilter) {
777
- where = await this.metadata.options.backendPreprocessFilter(where, {
779
+ safeWhere = await this.metadata.options.backendPreprocessFilter(safeWhere, {
778
780
  metadata: this.metadata,
779
- getFilterPreciseValues: (filter) => Filter.getPreciseValues(this.metadata, filter || where),
781
+ getFilterPreciseValues: (filter) => Filter.getPreciseValues(this.metadata, filter || safeWhere),
780
782
  });
781
783
  }
782
784
  if (this.metadata.options.backendPrefilter) {
783
- let z = where;
784
- where = {
785
+ let z = safeWhere;
786
+ safeWhere = {
785
787
  $and: [
786
788
  z,
787
789
  await Filter.resolve(this.metadata.options.backendPrefilter),
@@ -789,7 +791,7 @@ export class RepositoryImplementation {
789
791
  };
790
792
  }
791
793
  }
792
- let r = await Filter.fromEntityFilter(this.metadata, where);
794
+ let r = await Filter.fromEntityFilter(this.metadata, safeWhere);
793
795
  if (r && !this._dataProvider.isProxy) {
794
796
  r = await Filter.translateCustomWhere(r, this.metadata, this._remult);
795
797
  }
@@ -822,8 +824,11 @@ export function createOldEntity(entity, remult) {
822
824
  for (const key of functions) {
823
825
  if (baseSettings[key] && baseSettings[key] !== info[key]) {
824
826
  let x = info[key];
827
+ //@ts-ignore
825
828
  info[key] = async (a, b) => {
829
+ //@ts-ignore
826
830
  await x(a, b);
831
+ //@ts-ignore
827
832
  await baseSettings[key](a, b);
828
833
  };
829
834
  }
@@ -894,37 +899,41 @@ class rowHelperBase {
894
899
  });
895
900
  lookup.set(val);
896
901
  }
897
- else if (getRelationFieldInfo(col)?.type === 'toOne') {
898
- let hasVal = instance.hasOwnProperty(col.key);
899
- let val = instance[col.key];
900
- if (isNewRow && !val)
901
- hasVal = false;
902
- Object.defineProperty(instance, col.key, {
903
- get: () => {
904
- return val;
905
- },
906
- set: (newVal) => {
907
- val = newVal;
908
- if (newVal === undefined)
909
- return;
910
- const op = col.options;
911
- if (op.field) {
912
- this.instance[op.field] =
913
- getRelationFieldInfo(col).toRepo.metadata.idMetadata.getId(newVal);
914
- }
915
- if (op.fields) {
916
- for (const key in op.fields) {
917
- if (Object.prototype.hasOwnProperty.call(op.fields, key)) {
918
- const element = op.fields[key];
919
- this.instance[element] = newVal == null ? null : newVal[key];
902
+ else {
903
+ const rel = getRelationFieldInfo(col);
904
+ if (rel?.type === 'toOne') {
905
+ let hasVal = instance.hasOwnProperty(col.key);
906
+ let val = instance[col.key];
907
+ if (isNewRow && !val)
908
+ hasVal = false;
909
+ Object.defineProperty(instance, col.key, {
910
+ get: () => {
911
+ return val;
912
+ },
913
+ set: (newVal) => {
914
+ val = newVal;
915
+ if (newVal === undefined)
916
+ return;
917
+ const op = col.options;
918
+ if (op.field) {
919
+ this.instance[op.field] =
920
+ rel.toRepo.metadata.idMetadata.getId(newVal);
921
+ }
922
+ if (op.fields) {
923
+ for (const key in op.fields) {
924
+ if (Object.prototype.hasOwnProperty.call(op.fields, key)) {
925
+ const element = op.fields[key];
926
+ this.instance[element] =
927
+ newVal == null ? null : newVal[key];
928
+ }
920
929
  }
921
930
  }
922
- }
923
- },
924
- enumerable: true,
925
- });
926
- if (hasVal)
927
- instance[col.key] = val;
931
+ },
932
+ enumerable: true,
933
+ });
934
+ if (hasVal)
935
+ instance[col.key] = val;
936
+ }
928
937
  }
929
938
  }
930
939
  }
@@ -937,6 +946,7 @@ class rowHelperBase {
937
946
  initSubscribers() {
938
947
  if (!this._subscribers) {
939
948
  this._subscribers = new SubscribableImp();
949
+ const safeSubscribers = this._subscribers;
940
950
  for (const col of this.fieldsMetadata) {
941
951
  let ei = getEntitySettings(col.valueType, false);
942
952
  let refImpl = this.fields.find(col.key);
@@ -947,13 +957,13 @@ class rowHelperBase {
947
957
  let val = this.instance[col.key];
948
958
  Object.defineProperty(this.instance, col.key, {
949
959
  get: () => {
950
- this._subscribers.reportObserved();
960
+ safeSubscribers.reportObserved();
951
961
  refImpl._subscribers.reportObserved();
952
962
  return val;
953
963
  },
954
964
  set: (value) => {
955
965
  val = value;
956
- this._subscribers.reportChanged();
966
+ safeSubscribers.reportChanged();
957
967
  refImpl._subscribers.reportChanged();
958
968
  },
959
969
  enumerable: true,
@@ -986,9 +996,11 @@ class rowHelperBase {
986
996
  };
987
997
  if (!error.message) {
988
998
  for (const col of this.fieldsMetadata) {
989
- if (this.errors[col.key]) {
999
+ if (this.errors?.[col.key]) {
990
1000
  error.message =
991
- this.fields[col.key].metadata.caption + ': ' + this.errors[col.key];
1001
+ this.fields[col.key].metadata.caption +
1002
+ ': ' +
1003
+ this.errors[col.key];
992
1004
  this.error = error.message;
993
1005
  break;
994
1006
  }
@@ -1149,38 +1161,41 @@ class rowHelperBase {
1149
1161
  }
1150
1162
  export class rowHelperImplementation extends rowHelperBase {
1151
1163
  info;
1152
- repository;
1164
+ repo;
1153
1165
  edp;
1154
1166
  _isNew;
1155
- constructor(info, instance, repository, edp, remult, _isNew) {
1167
+ constructor(info, instance, repo, edp, remult, _isNew) {
1156
1168
  super(info.fieldsMetadata, instance, remult, _isNew);
1157
1169
  this.info = info;
1158
- this.repository = repository;
1170
+ this.repo = repo;
1159
1171
  this.edp = edp;
1160
1172
  this._isNew = _isNew;
1173
+ this.repository = repo;
1161
1174
  this.metadata = info;
1162
1175
  if (_isNew) {
1163
1176
  for (const col of info.fieldsMetadata) {
1164
- if (col.options.defaultValue && instance[col.key] === undefined) {
1177
+ const colKey = col.key;
1178
+ if (col.options.defaultValue && instance[colKey] === undefined) {
1165
1179
  if (typeof col.options.defaultValue === 'function') {
1166
- instance[col.key] = col.options.defaultValue(instance);
1180
+ instance[colKey] = col.options.defaultValue(instance);
1167
1181
  }
1168
- else if (!instance[col.key])
1169
- instance[col.key] = col.options.defaultValue;
1182
+ else if (!instance[colKey])
1183
+ instance[colKey] = col.options.defaultValue;
1170
1184
  }
1171
1185
  }
1172
1186
  }
1173
- if (this.info.options.entityRefInit)
1174
- this.info.options.entityRefInit(this, instance);
1187
+ if (this.info.entityInfo.entityRefInit)
1188
+ this.info.entityInfo.entityRefInit(this, instance);
1175
1189
  if (Remult.entityRefInit)
1176
1190
  Remult.entityRefInit(this, instance);
1177
1191
  }
1192
+ repository;
1178
1193
  clone() {
1179
1194
  const data = this.toApiJson(true, true);
1180
- return this.repository.fromJson(data, this.isNew());
1195
+ return this.repo.fromJson(data, this.isNew());
1181
1196
  }
1182
1197
  get relations() {
1183
- return this.repository.relations(this.instance);
1198
+ return this.repo.relations(this.instance);
1184
1199
  }
1185
1200
  get apiUpdateAllowed() {
1186
1201
  return this.remult.isAllowedForInstance(this.instance, this.metadata.options.allowApiUpdate);
@@ -1220,7 +1235,7 @@ export class rowHelperImplementation extends rowHelperBase {
1220
1235
  .find({ where: await this.getIdFilter() })
1221
1236
  .then(async (newData) => {
1222
1237
  if (newData.length === 0)
1223
- throw this.repository._notFoundError(this.id);
1238
+ throw this.repo._notFoundError(this.id);
1224
1239
  await this.loadDataFrom(newData[0]);
1225
1240
  this.saveOriginalData();
1226
1241
  });
@@ -1232,12 +1247,17 @@ export class rowHelperImplementation extends rowHelperBase {
1232
1247
  if (!this._columns) {
1233
1248
  let _items = [];
1234
1249
  let r = {
1235
- find: (c) => r[typeof c === 'string' ? c : c.key],
1250
+ //@ts-ignore
1251
+ find: (c) =>
1252
+ //@ts-ignore
1253
+ r[typeof c === 'string' ? c : c.key],
1236
1254
  [Symbol.iterator]: () => _items[Symbol.iterator](),
1237
1255
  toArray: () => _items,
1238
1256
  };
1239
1257
  for (const c of this.info.fieldsMetadata) {
1240
- _items.push((r[c.key] = new FieldRefImplementation(c.options, c, this.instance, this, this)));
1258
+ _items.push(
1259
+ //@ts-ignore
1260
+ (r[c.key] = new FieldRefImplementation(c.options, c, this.instance, this, this)));
1241
1261
  }
1242
1262
  this._columns = r;
1243
1263
  }
@@ -1258,7 +1278,7 @@ export class rowHelperImplementation extends rowHelperBase {
1258
1278
  await this.__validateEntity();
1259
1279
  let doNotSave = false;
1260
1280
  let e = this.buildLifeCycleEvent(() => (doNotSave = true));
1261
- if (!this.repository._dataProvider.isProxy) {
1281
+ if (!this.repo._dataProvider.isProxy) {
1262
1282
  for (const col of this.fields) {
1263
1283
  if (col.metadata.options.saving)
1264
1284
  await col.metadata.options.saving(this.instance, col, e);
@@ -1320,21 +1340,21 @@ export class rowHelperImplementation extends rowHelperBase {
1320
1340
  if (updatedRow)
1321
1341
  await this.loadDataFrom(updatedRow);
1322
1342
  e.id = this.getId();
1323
- if (!this.repository._dataProvider.isProxy) {
1343
+ if (!this.repo._dataProvider.isProxy) {
1324
1344
  if (this.info.entityInfo.saved)
1325
1345
  await this.info.entityInfo.saved(this.instance, e);
1326
- if (this.repository.listeners)
1327
- for (const listener of this.repository.listeners.filter((x) => x.saved)) {
1328
- await listener.saved(this.instance, isNew);
1346
+ if (this.repo.listeners)
1347
+ for (const listener of this.repo.listeners) {
1348
+ await listener.saved?.(this.instance, isNew);
1329
1349
  }
1330
1350
  }
1331
- await this.repository._remult.liveQueryPublisher.itemChanged(this.repository.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: false }]);
1351
+ await this.repo._remult.liveQueryPublisher.itemChanged(this.repo.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: false }]);
1332
1352
  this.saveOriginalData();
1333
1353
  this._isNew = false;
1334
1354
  return this.instance;
1335
1355
  }
1336
1356
  catch (err) {
1337
- await this.catchSaveErrors(err);
1357
+ throw await this.catchSaveErrors(err);
1338
1358
  }
1339
1359
  }
1340
1360
  finally {
@@ -1371,20 +1391,20 @@ export class rowHelperImplementation extends rowHelperBase {
1371
1391
  fields: self.fields,
1372
1392
  id: self.getId(),
1373
1393
  originalId: self.getOriginalId(),
1374
- metadata: self.repository.metadata,
1375
- repository: self.repository,
1394
+ metadata: self.repo.metadata,
1395
+ repository: self.repo,
1376
1396
  preventDefault: () => preventDefault(),
1377
- relations: self.repository.relations(self.instance),
1397
+ relations: self.repo.relations(self.instance),
1378
1398
  };
1379
1399
  }
1380
1400
  async getIdFilter() {
1381
- return await this.repository._translateWhereToFilter(this.repository.metadata.idMetadata.getIdFilter(this.id));
1401
+ return await this.repo._translateWhereToFilter(this.repo.metadata.idMetadata.getIdFilter(this.id));
1382
1402
  }
1383
1403
  async delete() {
1384
1404
  this.__clearErrorsAndReportChanged();
1385
1405
  let doDelete = true;
1386
1406
  let e = this.buildLifeCycleEvent(() => (doDelete = false));
1387
- if (!this.repository._dataProvider.isProxy) {
1407
+ if (!this.repo._dataProvider.isProxy) {
1388
1408
  if (this.info.entityInfo.deleting)
1389
1409
  await this.info.entityInfo.deleting(this.instance, e);
1390
1410
  }
@@ -1392,19 +1412,19 @@ export class rowHelperImplementation extends rowHelperBase {
1392
1412
  try {
1393
1413
  if (doDelete)
1394
1414
  await this.edp.delete(this.id);
1395
- if (!this.repository._dataProvider.isProxy) {
1415
+ if (!this.repo._dataProvider.isProxy) {
1396
1416
  if (this.info.entityInfo.deleted)
1397
1417
  await this.info.entityInfo.deleted(this.instance, e);
1398
1418
  }
1399
- if (this.repository.listeners)
1400
- for (const listener of this.repository.listeners.filter((x) => x.deleted)) {
1401
- await listener.deleted(this.instance);
1419
+ if (this.repo.listeners)
1420
+ for (const listener of this.repo.listeners) {
1421
+ await listener.deleted?.(this.instance);
1402
1422
  }
1403
- await this.repository._remult.liveQueryPublisher.itemChanged(this.repository.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: true }]);
1423
+ await this.repo._remult.liveQueryPublisher.itemChanged(this.repo.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: true }]);
1404
1424
  this._wasDeleted = true;
1405
1425
  }
1406
1426
  catch (err) {
1407
- await this.catchSaveErrors(err);
1427
+ throw await this.catchSaveErrors(err);
1408
1428
  }
1409
1429
  }
1410
1430
  async loadDataFrom(data, loadItems) {
@@ -1437,7 +1457,8 @@ export class rowHelperImplementation extends rowHelperBase {
1437
1457
  //y2 should be changed to be based on data provider - consider naming
1438
1458
  for (const col of this.info.fieldsMetadata) {
1439
1459
  if (col.options.serverExpression) {
1440
- this.instance[col.key] = await col.options.serverExpression(this.instance);
1460
+ this.instance[col.key] =
1461
+ (await col.options.serverExpression(this.instance));
1441
1462
  }
1442
1463
  }
1443
1464
  }
@@ -1466,9 +1487,9 @@ export class rowHelperImplementation extends rowHelperBase {
1466
1487
  let e = this.buildLifeCycleEvent(() => { });
1467
1488
  await this.info.entityInfo.validation(this.instance, e);
1468
1489
  }
1469
- if (this.repository.listeners)
1470
- for (const listener of this.repository.listeners.filter((x) => x.validating)) {
1471
- await listener.validating(this.instance);
1490
+ if (this.repo.listeners)
1491
+ for (const listener of this.repo.listeners) {
1492
+ await listener.validating?.(this.instance);
1472
1493
  }
1473
1494
  }
1474
1495
  }
@@ -1481,7 +1502,9 @@ export function getFields(container, remult) {
1481
1502
  }
1482
1503
  export function getControllerRef(container, remultArg) {
1483
1504
  const remultVar = remultArg || defaultRemult;
1505
+ //@ts-ignore
1484
1506
  let result = container[controllerColumns];
1507
+ //@ts-ignore
1485
1508
  if (!result)
1486
1509
  result = container[entityMember];
1487
1510
  if (!result) {
@@ -1496,7 +1519,9 @@ export function getControllerRef(container, remultArg) {
1496
1519
  }
1497
1520
  base = Object.getPrototypeOf(base);
1498
1521
  }
1499
- container[controllerColumns] = result = new controllerRefImpl(prepareColumnInfo(columnSettings, remultVar).map((x) => new columnDefsImpl(x, undefined, remultVar)), container, remultVar);
1522
+ //@ts-ignore
1523
+ container[controllerColumns] = result = new controllerRefImpl(prepareColumnInfo(columnSettings, remultVar).map((x) => new columnDefsImpl(x, undefined, //TODO - not sure
1524
+ remultVar)), container, remultVar);
1500
1525
  }
1501
1526
  return result;
1502
1527
  }
@@ -1536,7 +1561,7 @@ export class FieldRefImplementation {
1536
1561
  this.helper = helper;
1537
1562
  this.rowBase = rowBase;
1538
1563
  this.target = this.settings.target;
1539
- this.entityRef = this.helper;
1564
+ this.entityRef = this.helper; //todo - I'm not sure this is correct in the case of ControllerInstance
1540
1565
  }
1541
1566
  _subscribers;
1542
1567
  subscribe(listener) {
@@ -1558,21 +1583,26 @@ export class FieldRefImplementation {
1558
1583
  let lu = this.rowBase.lookups.get(this.metadata.key);
1559
1584
  return this.rawOriginalValue() === null;
1560
1585
  }
1586
+ get key() {
1587
+ return this.metadata.key;
1588
+ }
1589
+ get repo() {
1590
+ return this.helper?.repository;
1591
+ }
1561
1592
  async load() {
1562
1593
  let lu = this.rowBase.lookups.get(this.metadata.key);
1563
1594
  let rel = getRelationFieldInfo(this.metadata);
1564
- if (rel) {
1595
+ if (rel && this.helper) {
1565
1596
  if (rel.type === 'toMany') {
1566
- return (this.container[this.metadata.key] = await this.helper.repository
1567
- .relations(this.container)[this.metadata.key].find());
1597
+ return (this.container[this.metadata.key] = await this.repo.relations(this.container)[this.key].find());
1568
1598
  }
1569
1599
  else {
1570
- let val = await this.helper.repository
1600
+ let val = await this.repo
1571
1601
  .relations(this.container)[this.metadata.key].findOne();
1572
1602
  if (val)
1573
1603
  this.container[this.metadata.key] = val;
1574
1604
  else
1575
- return null;
1605
+ return null; //TODO: check if this (!) is correct
1576
1606
  }
1577
1607
  }
1578
1608
  else if (lu) {
@@ -1686,7 +1716,7 @@ export class FieldRefImplementation {
1686
1716
  set error(value) {
1687
1717
  self.error = value;
1688
1718
  },
1689
- isNew: this.entityRef?.isNew(),
1719
+ isNew: this.entityRef?.isNew() ?? false,
1690
1720
  load: () => self.load(),
1691
1721
  metadata: self.metadata,
1692
1722
  originalValue: self.originalValue,
@@ -1709,7 +1739,7 @@ export class FieldRefImplementation {
1709
1739
  if (typeof error === 'string')
1710
1740
  this.error = error;
1711
1741
  else
1712
- this.error = error.message;
1742
+ this.error = error?.message;
1713
1743
  }
1714
1744
  }
1715
1745
  async validate() {
@@ -1723,14 +1753,14 @@ let tempCaptionTransformer = {
1723
1753
  export const CaptionTransformer = remultStatic.captionTransformer ||
1724
1754
  (remultStatic.captionTransformer = tempCaptionTransformer);
1725
1755
  export function buildCaption(caption, key, remult, metaData) {
1726
- let result;
1756
+ let result = undefined;
1727
1757
  if (typeof caption === 'function') {
1728
1758
  if (remult)
1729
1759
  result = caption(remult);
1730
1760
  }
1731
1761
  else if (caption)
1732
1762
  result = caption;
1733
- result = CaptionTransformer.transformCaption(remult, key, result, metaData);
1763
+ result = CaptionTransformer.transformCaption(remult, key, result ?? '', metaData);
1734
1764
  if (result)
1735
1765
  return result;
1736
1766
  if (key)
@@ -1747,7 +1777,7 @@ export class columnDefsImpl {
1747
1777
  this.remult = remult;
1748
1778
  this.options = this.settings;
1749
1779
  this.target = this.settings.target;
1750
- this.valueConverter = new Proxy(this.settings.valueConverter, {
1780
+ this.valueConverter = new Proxy(this.settings.valueConverter ?? {}, {
1751
1781
  get: (target, prop) => {
1752
1782
  let result = target[prop];
1753
1783
  if (typeof result === 'function') {
@@ -1810,7 +1840,7 @@ export class columnDefsImpl {
1810
1840
  }
1811
1841
  options;
1812
1842
  target;
1813
- readonly;
1843
+ readonly = false;
1814
1844
  valueConverter;
1815
1845
  allowNull;
1816
1846
  caption;
@@ -1818,9 +1848,9 @@ export class columnDefsImpl {
1818
1848
  inputType;
1819
1849
  key;
1820
1850
  get dbReadOnly() {
1821
- return this.settings.dbReadOnly;
1851
+ return Boolean(this.settings.dbReadOnly);
1822
1852
  }
1823
- isServerExpression;
1853
+ isServerExpression = false;
1824
1854
  valueType;
1825
1855
  }
1826
1856
  class EntityFullInfo {
@@ -1843,11 +1873,11 @@ class EntityFullInfo {
1843
1873
  else
1844
1874
  crud = this.options.allowApiCrud;
1845
1875
  if (this.options.allowApiDelete === undefined)
1846
- this.options.allowApiDelete = crud;
1876
+ this.entityInfo.allowApiDelete = crud;
1847
1877
  if (this.options.allowApiInsert === undefined)
1848
- this.options.allowApiInsert = crud;
1878
+ this.entityInfo.allowApiInsert = crud;
1849
1879
  if (this.options.allowApiUpdate === undefined)
1850
- this.options.allowApiUpdate = crud;
1880
+ this.entityInfo.allowApiUpdate = crud;
1851
1881
  if (this.options.allowApiRead === undefined)
1852
1882
  this.options.allowApiRead = this.options.allowApiCrud;
1853
1883
  }
@@ -1882,8 +1912,9 @@ class EntityFullInfo {
1882
1912
  this.idMetadata.field = r;
1883
1913
  }
1884
1914
  if (!this.idMetadata.field) {
1885
- if (this.fields['id'])
1886
- this.idMetadata.field = this.fields['id'];
1915
+ const idField = this.fields['id'];
1916
+ if (idField)
1917
+ this.idMetadata.field = idField;
1887
1918
  else
1888
1919
  this.idMetadata.field = [...this.fields][0];
1889
1920
  }
@@ -1946,6 +1977,10 @@ class EntityFullInfo {
1946
1977
  return {
1947
1978
  $or: items.map((x) => this.idMetadata.getIdFilter(getEntityRef(x).getId())),
1948
1979
  };
1980
+ else
1981
+ return {
1982
+ [this.fields.toArray()[0].key]: [],
1983
+ };
1949
1984
  },
1950
1985
  isIdField: (col) => {
1951
1986
  return col.key == this.idMetadata.field.key;
@@ -2001,7 +2036,7 @@ export function ValueListFieldType(...options) {
2001
2036
  }
2002
2037
  return Validators.in(values)(entity, ref);
2003
2038
  };
2004
- }, ...options)(type, context);
2039
+ }, ...options)(type);
2005
2040
  };
2006
2041
  }
2007
2042
  export class ValueListInfo {
@@ -2102,7 +2137,7 @@ export function getValueList(type) {
2102
2137
  if (options)
2103
2138
  return ValueListInfo.get(type).getValues();
2104
2139
  }
2105
- let optionalValues = meta?.options[fieldOptionalValuesFunctionKey];
2140
+ let optionalValues = (meta?.options)[fieldOptionalValuesFunctionKey];
2106
2141
  if (optionalValues)
2107
2142
  return optionalValues();
2108
2143
  return undefined;
@@ -2201,17 +2236,19 @@ export function decorateColumnSettings(settings, remult) {
2201
2236
  if (!settings.valueConverter.fromJson) {
2202
2237
  settings.valueConverter.fromJson = (x) => x;
2203
2238
  }
2239
+ const fromJson = settings.valueConverter.fromJson;
2240
+ const toJson = settings.valueConverter.toJson;
2204
2241
  if (!settings.valueConverter.toDb) {
2205
- settings.valueConverter.toDb = (x) => settings.valueConverter.toJson(x);
2242
+ settings.valueConverter.toDb = (x) => toJson(x);
2206
2243
  }
2207
2244
  if (!settings.valueConverter.fromDb) {
2208
- settings.valueConverter.fromDb = (x) => settings.valueConverter.fromJson(x);
2245
+ settings.valueConverter.fromDb = (x) => fromJson(x);
2209
2246
  }
2210
2247
  if (!settings.valueConverter.toInput) {
2211
- settings.valueConverter.toInput = (x) => settings.valueConverter.toJson(x);
2248
+ settings.valueConverter.toInput = (x) => toJson(x);
2212
2249
  }
2213
2250
  if (!settings.valueConverter.fromInput) {
2214
- settings.valueConverter.fromInput = (x) => settings.valueConverter.fromJson(x);
2251
+ settings.valueConverter.fromInput = (x) => fromJson(x);
2215
2252
  }
2216
2253
  return settings;
2217
2254
  }
@@ -2266,7 +2303,7 @@ class QueryResultImpl {
2266
2303
  }
2267
2304
  _count = undefined;
2268
2305
  async getPage(page) {
2269
- if (page < 1)
2306
+ if ((page ?? 0) < 1)
2270
2307
  page = 1;
2271
2308
  return this.repo.find({
2272
2309
  where: this.options.where,
@@ -2301,7 +2338,9 @@ class QueryResultImpl {
2301
2338
  load: this.options.load,
2302
2339
  include: this.options.include,
2303
2340
  });
2304
- let nextPage = undefined;
2341
+ let nextPage = () => {
2342
+ throw new Error('no more pages');
2343
+ };
2305
2344
  let hasNextPage = items.length == this.options.pageSize;
2306
2345
  if (hasNextPage) {
2307
2346
  let nextPageFilter = await this.repo._createAfterFilter(this.options.orderBy, items[items.length - 1]);
@@ -2341,7 +2380,7 @@ class QueryResultImpl {
2341
2380
  return { value: undefined, done: true };
2342
2381
  }
2343
2382
  else {
2344
- if (prev?.items.length > 0) {
2383
+ if (prev?.items.length ?? 0 > 0) {
2345
2384
  if (this.repo.getEntityRef(prev.items[0]).getId() ==
2346
2385
  this.repo.getEntityRef(currentPage.items[0]).getId())
2347
2386
  throw new Error('pagination failure, returned same first row');
@@ -2350,6 +2389,7 @@ class QueryResultImpl {
2350
2389
  }
2351
2390
  if (itemIndex < currentPage.items.length)
2352
2391
  return { value: currentPage.items[itemIndex++], done: false };
2392
+ return { done: true, value: undefined };
2353
2393
  };
2354
2394
  return {
2355
2395
  next: async () => {