remult 0.27.12 → 0.27.13

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.
@@ -1,12 +1,14 @@
1
1
  import { type RelationFields } from '../src/remult3/relationInfoMember.js';
2
2
  import type { ClassType } from '../classType.js';
3
3
  import type { Remult } from '../src/context.js';
4
+ import { EntityFilter } from '../src/remult3/remult3.js';
4
5
  export interface EntityUIInfo {
5
6
  key: string;
6
7
  caption: string;
7
8
  fields: FieldUIInfo[];
8
9
  ids: Record<string, true>;
9
10
  relations: EntityRelationToManyInfo[];
11
+ defaultOrderBy?: EntityFilter<any>;
10
12
  color?: string;
11
13
  }
12
14
  export interface EntityRelationToManyInfo extends RelationFields {
@@ -24,6 +26,7 @@ export interface FieldUIInfo {
24
26
  valFieldKey: string;
25
27
  caption: string;
26
28
  type: FieldUIInfoType;
29
+ inputType: string;
27
30
  relationToOne?: FieldRelationToOneInfo;
28
31
  }
29
32
  export interface FieldRelationToOneInfo extends RelationFields {
@@ -41,3 +44,4 @@ export interface DisplayOptions {
41
44
  }
42
45
  export default function remultAdminHtml(options: AdminOptions): string;
43
46
  export declare function buildEntityInfo(options: AdminOptions): EntityUIInfo[];
47
+ export type RelationsToOneValues = Record<string, Map<any, any>>;
@@ -13,24 +13,24 @@ function remultAdminHtml(options) {
13
13
  }
14
14
  function buildEntityInfo(options) {
15
15
  var e_1, _a, e_2, _b, e_3, _c;
16
- var _d;
16
+ var _d, _e;
17
17
  var entities = [];
18
18
  try {
19
- for (var _e = tslib_1.__values(options.entities.map(function (e) { return options.remult.repo(e).metadata; })), _f = _e.next(); !_f.done; _f = _e.next()) {
20
- var metadata = _f.value;
19
+ for (var _f = tslib_1.__values(options.entities.map(function (e) { return options.remult.repo(e).metadata; })), _g = _f.next(); !_g.done; _g = _f.next()) {
20
+ var metadata = _g.value;
21
21
  var fields = [];
22
22
  var relations = [];
23
23
  var ids = {};
24
24
  try {
25
- for (var _g = (e_2 = void 0, tslib_1.__values(metadata.idMetadata.fields)), _h = _g.next(); !_h.done; _h = _g.next()) {
26
- var f = _h.value;
25
+ for (var _h = (e_2 = void 0, tslib_1.__values(metadata.idMetadata.fields)), _j = _h.next(); !_j.done; _j = _h.next()) {
26
+ var f = _j.value;
27
27
  ids[f.key] = true;
28
28
  }
29
29
  }
30
30
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
31
31
  finally {
32
32
  try {
33
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
33
+ if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
34
34
  }
35
35
  finally { if (e_2) throw e_2.error; }
36
36
  }
@@ -77,6 +77,7 @@ function buildEntityInfo(options) {
77
77
  valFieldKey: valFieldKey,
78
78
  caption: x.caption,
79
79
  relationToOne: relation,
80
+ inputType: x.inputType,
80
81
  type: x.valueConverter.fieldTypeInDb == 'json'
81
82
  ? 'json'
82
83
  : x.valueType === Number
@@ -89,15 +90,15 @@ function buildEntityInfo(options) {
89
90
  });
90
91
  };
91
92
  try {
92
- for (var _j = (e_3 = void 0, tslib_1.__values(metadata.fields.toArray())), _k = _j.next(); !_k.done; _k = _j.next()) {
93
- var x = _k.value;
93
+ for (var _k = (e_3 = void 0, tslib_1.__values(metadata.fields.toArray())), _l = _k.next(); !_l.done; _l = _k.next()) {
94
+ var x = _l.value;
94
95
  _loop_1(x);
95
96
  }
96
97
  }
97
98
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
98
99
  finally {
99
100
  try {
100
- if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
101
+ if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
101
102
  }
102
103
  finally { if (e_3) throw e_3.error; }
103
104
  }
@@ -108,6 +109,7 @@ function buildEntityInfo(options) {
108
109
  ids: ids,
109
110
  fields: fields,
110
111
  relations: relations,
112
+ defaultOrderBy: (_e = metadata.options.defaultOrderBy) !== null && _e !== void 0 ? _e : { id: 'asc' },
111
113
  });
112
114
  }
113
115
  }
@@ -115,7 +117,7 @@ function buildEntityInfo(options) {
115
117
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
116
118
  finally {
117
119
  try {
118
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
120
+ if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
119
121
  }
120
122
  finally { if (e_1) throw e_1.error; }
121
123
  }
@@ -589,13 +589,13 @@ var RemultServerImplementation = /** @class */ (function () {
589
589
  return tslib_1.__generator(this, function (_a) {
590
590
  switch (_a.label) {
591
591
  case 0:
592
- if (!req) return [3 /*break*/, 8];
592
+ if (!req) return [3 /*break*/, 9];
593
593
  ;
594
594
  remult.context.request = req;
595
595
  remult_static_js_1.remultStatic.asyncContext.setInInitRequest(true);
596
596
  _a.label = 1;
597
597
  case 1:
598
- _a.trys.push([1, , 7, 8]);
598
+ _a.trys.push([1, , 8, 9]);
599
599
  user = void 0;
600
600
  if (!this.options.getUser) return [3 /*break*/, 3];
601
601
  return [4 /*yield*/, this.options.getUser(req)];
@@ -623,14 +623,14 @@ var RemultServerImplementation = /** @class */ (function () {
623
623
  case 5:
624
624
  _a.sent();
625
625
  _a.label = 6;
626
- case 6: return [3 /*break*/, 8];
626
+ case 6: return [4 /*yield*/, what(remult, myReq, myRes, genReq, origRes, req)];
627
627
  case 7:
628
+ _a.sent();
629
+ return [3 /*break*/, 9];
630
+ case 8:
628
631
  remult_static_js_1.remultStatic.asyncContext.setInInitRequest(false);
629
632
  return [7 /*endfinally*/];
630
- case 8: return [4 /*yield*/, what(remult, myReq, myRes, genReq, origRes, req)];
631
- case 9:
632
- _a.sent();
633
- return [2 /*return*/];
633
+ case 9: return [2 /*return*/];
634
634
  }
635
635
  });
636
636
  }); })];
@@ -738,65 +738,6 @@ var myDummySQLCommand = /** @class */ (function () {
738
738
  };
739
739
  return myDummySQLCommand;
740
740
  }());
741
- function bulkInsert(array, db) {
742
- return tslib_1.__awaiter(this, void 0, void 0, function () {
743
- var chunkSize, _loop_1, i;
744
- return tslib_1.__generator(this, function (_a) {
745
- switch (_a.label) {
746
- case 0:
747
- if (array.length == 0)
748
- return [2 /*return*/];
749
- chunkSize = 250;
750
- _loop_1 = function (i) {
751
- var items, c, sql, _b, _c;
752
- return tslib_1.__generator(this, function (_d) {
753
- switch (_d.label) {
754
- case 0:
755
- items = array.slice(i, i + chunkSize);
756
- c = db.createCommand();
757
- _b = 'insert into ';
758
- return [4 /*yield*/, items[0]._.metadata.dbName];
759
- case 1:
760
- _c = _b +
761
- (_d.sent()) +
762
- ' (';
763
- return [4 /*yield*/, Promise.all(items[0]._.metadata.fields.toArray().map(function (f) { return f.dbName; }))];
764
- case 2:
765
- sql = _c +
766
- (_d.sent()).join(',') +
767
- ') values ';
768
- sql += items
769
- .map(function (row) {
770
- return '(' +
771
- row.$.toArray()
772
- .map(function (f) { return c.param(f.metadata.valueConverter.toDb(f.value)); })
773
- .join(', ') +
774
- ')';
775
- })
776
- .join(',');
777
- return [4 /*yield*/, c.execute(sql)];
778
- case 3:
779
- _d.sent();
780
- return [2 /*return*/];
781
- }
782
- });
783
- };
784
- i = 0;
785
- _a.label = 1;
786
- case 1:
787
- if (!(i < array.length)) return [3 /*break*/, 4];
788
- return [5 /*yield**/, _loop_1(i)];
789
- case 2:
790
- _a.sent();
791
- _a.label = 3;
792
- case 3:
793
- i += chunkSize;
794
- return [3 /*break*/, 1];
795
- case 4: return [2 /*return*/];
796
- }
797
- });
798
- });
799
- }
800
741
  function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
801
742
  var idFilter = id !== undefined ? meta.idMetadata.getIdFilter(id) : {};
802
743
  return dataProvider
@@ -832,7 +773,7 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
832
773
  ? "count (distinct ".concat(dbName, ")")
833
774
  : "".concat(operator, "( ").concat(dbName, " )");
834
775
  }
835
- var select, groupBy, processResultRow, _loop_2, _a, _b, x, _loop_3, GroupByOperators_1, GroupByOperators_1_1, operator, e_8_1, where, _c, orderBy, _d, _e, x, field, _f, e_9_1, page, result;
776
+ var select, groupBy, processResultRow, _loop_1, _a, _b, x, _loop_2, GroupByOperators_1, GroupByOperators_1_1, operator, e_8_1, where, _c, orderBy, _d, _e, x, field, _f, e_9_1, page, result;
836
777
  var e_10, _g, e_8, _h, e_9, _j;
837
778
  return tslib_1.__generator(this, function (_k) {
838
779
  switch (_k.label) {
@@ -844,7 +785,7 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
844
785
  theResult[remult3_js_1.GroupByCountMember] = Number(sqlVal);
845
786
  });
846
787
  if (options === null || options === void 0 ? void 0 : options.group) {
847
- _loop_2 = function (x) {
788
+ _loop_1 = function (x) {
848
789
  if (x.isServerExpression) {
849
790
  }
850
791
  else {
@@ -864,7 +805,7 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
864
805
  try {
865
806
  for (_a = tslib_1.__values(options === null || options === void 0 ? void 0 : options.group), _b = _a.next(); !_b.done; _b = _a.next()) {
866
807
  x = _b.value;
867
- _loop_2(x);
808
+ _loop_1(x);
868
809
  }
869
810
  }
870
811
  catch (e_10_1) { e_10 = { error: e_10_1 }; }
@@ -875,15 +816,15 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
875
816
  finally { if (e_10) throw e_10.error; }
876
817
  }
877
818
  }
878
- _loop_3 = function (operator) {
879
- var fields, _loop_4, fields_1, fields_1_1, x, e_11_1;
819
+ _loop_2 = function (operator) {
820
+ var fields, _loop_3, fields_1, fields_1_1, x, e_11_1;
880
821
  var e_11, _l;
881
822
  return tslib_1.__generator(this, function (_m) {
882
823
  switch (_m.label) {
883
824
  case 0:
884
825
  fields = options === null || options === void 0 ? void 0 : options[operator];
885
826
  if (!fields) return [3 /*break*/, 8];
886
- _loop_4 = function (x) {
827
+ _loop_3 = function (x) {
887
828
  var dbName, turnToNumber;
888
829
  return tslib_1.__generator(this, function (_o) {
889
830
  switch (_o.label) {
@@ -915,7 +856,7 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
915
856
  case 2:
916
857
  if (!!fields_1_1.done) return [3 /*break*/, 5];
917
858
  x = fields_1_1.value;
918
- return [5 /*yield**/, _loop_4(x)];
859
+ return [5 /*yield**/, _loop_3(x)];
919
860
  case 3:
920
861
  _m.sent();
921
862
  _m.label = 4;
@@ -945,7 +886,7 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
945
886
  case 2:
946
887
  if (!!GroupByOperators_1_1.done) return [3 /*break*/, 5];
947
888
  operator = GroupByOperators_1_1.value;
948
- return [5 /*yield**/, _loop_3(operator)];
889
+ return [5 /*yield**/, _loop_2(operator)];
949
890
  case 3:
950
891
  _k.sent();
951
892
  _k.label = 4;
@@ -1012,9 +953,9 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
1012
953
  orderBy += ' desc';
1013
954
  if (orderByNullFirst) {
1014
955
  if (x.isDescending)
1015
- select += ' nulls last';
956
+ orderBy += ' nulls last';
1016
957
  else
1017
- select += ' nulls first';
958
+ orderBy += ' nulls first';
1018
959
  }
1019
960
  _k.label = 15;
1020
961
  case 15:
@@ -1203,7 +1203,9 @@ var RepositoryImplementation = /** @class */ (function () {
1203
1203
  //I've used define property to hide this member from console.lo g
1204
1204
  get: function () { return row_2; },
1205
1205
  });
1206
+ row_2.id = row_2.getId();
1206
1207
  row_2.saveOriginalData();
1208
+ row_2.originalId = row_2.id;
1207
1209
  return result;
1208
1210
  }
1209
1211
  };
@@ -2335,7 +2337,10 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2335
2337
  case 21:
2336
2338
  updatedRow = (_t.sent())[0];
2337
2339
  return [3 /*break*/, 24];
2338
- case 22: return [4 /*yield*/, this.edp.update(this.id, changesOnly)];
2340
+ case 22:
2341
+ if (this.id === undefined)
2342
+ throw new Error('Invalid operation, id is undefined');
2343
+ return [4 /*yield*/, this.edp.update(this.id, changesOnly)];
2339
2344
  case 23:
2340
2345
  updatedRow = _t.sent();
2341
2346
  _t.label = 24;
@@ -2497,6 +2502,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2497
2502
  case 3:
2498
2503
  _e.trys.push([3, 16, , 18]);
2499
2504
  if (!doDelete) return [3 /*break*/, 5];
2505
+ if (this.id === undefined)
2506
+ throw new Error('Invalid operation, id is undefined');
2500
2507
  return [4 /*yield*/, this.edp.delete(this.id)];
2501
2508
  case 4:
2502
2509
  _e.sent();