@sumaris-net/ngx-components 0.13.12 → 0.13.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.
@@ -21780,8 +21780,8 @@
21780
21780
  fetchPolicy: opts && opts.fetchPolicy || undefined,
21781
21781
  error: { code: ErrorCodes$2.LOAD_DATA_ERROR, message: 'REFERENTIAL.ERROR.LOAD_DATA_ERROR' }
21782
21782
  })
21783
- .pipe(operators.map(function (_a) {
21784
- var data = _a.data;
21783
+ .pipe(operators.map(function (_b) {
21784
+ var data = _b.data;
21785
21785
  return (!opts || opts.toEntity !== false)
21786
21786
  ? (data && _this.fromObject(data))
21787
21787
  : data;
@@ -21790,8 +21790,8 @@
21790
21790
  BaseEntityService.prototype.load = function (id, opts) {
21791
21791
  return __awaiter(this, void 0, void 0, function () {
21792
21792
  var query, data;
21793
- return __generator(this, function (_a) {
21794
- switch (_a.label) {
21793
+ return __generator(this, function (_b) {
21794
+ switch (_b.label) {
21795
21795
  case 0:
21796
21796
  if (this._debug)
21797
21797
  console.debug(this._logPrefix + ("Loading " + this._logTypeName + " {" + id + "}..."));
@@ -21803,7 +21803,7 @@
21803
21803
  error: { code: ErrorCodes$2.LOAD_DATA_ERROR, message: 'REFERENTIAL.ERROR.LOAD_DATA_ERROR' }
21804
21804
  })];
21805
21805
  case 1:
21806
- data = (_a.sent()).data;
21806
+ data = (_b.sent()).data;
21807
21807
  // Convert to entity
21808
21808
  return [2 /*return*/, (!opts || opts.toEntity !== false)
21809
21809
  ? (data && this.fromObject(data))
@@ -21839,8 +21839,8 @@
21839
21839
  error: { code: ErrorCodes$2.LOAD_DATA_ERROR, message: 'REFERENTIAL.ERROR.LOAD_DATA_ERROR' },
21840
21840
  fetchPolicy: opts && opts.fetchPolicy || undefined
21841
21841
  })
21842
- .pipe(operators.map(function (_a) {
21843
- var data = _a.data, total = _a.total;
21842
+ .pipe(operators.map(function (_b) {
21843
+ var data = _b.data, total = _b.total;
21844
21844
  // Convert to entity (if need)
21845
21845
  var entities = (!opts || opts.toEntity !== false)
21846
21846
  ? (data || []).map(function (json) { return _this.fromObject(json); })
@@ -21854,10 +21854,10 @@
21854
21854
  };
21855
21855
  BaseEntityService.prototype.loadAll = function (offset, size, sortBy, sortDirection, filter, opts) {
21856
21856
  return __awaiter(this, void 0, void 0, function () {
21857
- var debug, variables, now, withTotal, query, _a, data, total, entities, res, nextOffset_1;
21857
+ var debug, variables, now, withTotal, query, _b, data, total, entities, res, nextOffset_1;
21858
21858
  var _this = this;
21859
- return __generator(this, function (_b) {
21860
- switch (_b.label) {
21859
+ return __generator(this, function (_c) {
21860
+ switch (_c.label) {
21861
21861
  case 0:
21862
21862
  debug = this._debug && (!opts || opts.debug !== false);
21863
21863
  filter = this.asFilter(filter);
@@ -21882,7 +21882,7 @@
21882
21882
  fetchPolicy: opts && opts.fetchPolicy || 'network-only'
21883
21883
  })];
21884
21884
  case 1:
21885
- _a = _b.sent(), data = _a.data, total = _a.total;
21885
+ _b = _c.sent(), data = _b.data, total = _b.total;
21886
21886
  entities = (!opts || opts.toEntity !== false) ?
21887
21887
  (data || []).map(function (json) { return _this.fromObject(json); }) :
21888
21888
  (data || []);
@@ -21904,12 +21904,44 @@
21904
21904
  });
21905
21905
  });
21906
21906
  };
21907
+ BaseEntityService.prototype.countAll = function (filter, opts) {
21908
+ var _a;
21909
+ return __awaiter(this, void 0, void 0, function () {
21910
+ var res;
21911
+ return __generator(this, function (_b) {
21912
+ switch (_b.label) {
21913
+ case 0:
21914
+ if (!!this.queries.countAll) return [3 /*break*/, 2];
21915
+ // Fail if no loadAll (cannot count)
21916
+ if (!this.queries.loadAllWithTotal)
21917
+ throw new Error('Not implemented');
21918
+ return [4 /*yield*/, this.loadAll(0, 1, null, null, filter, { withTotal: true })];
21919
+ case 1:
21920
+ // Use loadAll query, with size = 0;
21921
+ return [2 /*return*/, ((_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.total) || 0];
21922
+ case 2:
21923
+ filter = this.asFilter(filter);
21924
+ return [4 /*yield*/, this.graphql.query({
21925
+ query: this.queries.countAll,
21926
+ variables: {
21927
+ filter: filter && filter.asPodObject()
21928
+ },
21929
+ error: { code: ErrorCodes$2.LOAD_DATA_ERROR, message: 'ERROR.COUNT_DATA_ERROR' },
21930
+ fetchPolicy: opts && opts.fetchPolicy || 'network-only'
21931
+ })];
21932
+ case 3:
21933
+ res = _b.sent();
21934
+ return [2 /*return*/, res.total];
21935
+ }
21936
+ });
21937
+ });
21938
+ };
21907
21939
  BaseEntityService.prototype.saveAll = function (entities, opts) {
21908
21940
  return __awaiter(this, void 0, void 0, function () {
21909
21941
  var hasNewEntities, json, now;
21910
21942
  var _this = this;
21911
- return __generator(this, function (_a) {
21912
- switch (_a.label) {
21943
+ return __generator(this, function (_b) {
21944
+ switch (_b.label) {
21913
21945
  case 0:
21914
21946
  if (isEmptyArray(entities))
21915
21947
  return [2 /*return*/, entities]; // Nothing to save: skip
@@ -21937,8 +21969,8 @@
21937
21969
  data: json
21938
21970
  },
21939
21971
  error: { code: ErrorCodes$2.SAVE_DATA_ERROR, message: 'ERROR.SAVE_DATA_ERROR' },
21940
- update: function (proxy, _a) {
21941
- var data = _a.data;
21972
+ update: function (proxy, _b) {
21973
+ var data = _b.data;
21942
21974
  var savedEntities = data && data.data;
21943
21975
  if (savedEntities) {
21944
21976
  // Update entities (id and update date)
@@ -21962,7 +21994,7 @@
21962
21994
  }
21963
21995
  })];
21964
21996
  case 1:
21965
- _a.sent();
21997
+ _b.sent();
21966
21998
  return [2 /*return*/, entities];
21967
21999
  }
21968
22000
  });
@@ -21978,15 +22010,15 @@
21978
22010
  return __awaiter(this, void 0, void 0, function () {
21979
22011
  var data, json, isNew, now;
21980
22012
  var _this = this;
21981
- return __generator(this, function (_a) {
21982
- switch (_a.label) {
22013
+ return __generator(this, function (_b) {
22014
+ switch (_b.label) {
21983
22015
  case 0:
21984
22016
  if (!!this.mutations.save) return [3 /*break*/, 2];
21985
22017
  if (!this.mutations.saveAll)
21986
22018
  throw new Error('Not implemented');
21987
22019
  return [4 /*yield*/, this.saveAll([entity], opts)];
21988
22020
  case 1:
21989
- data = _a.sent();
22021
+ data = _b.sent();
21990
22022
  return [2 /*return*/, data && data[0]];
21991
22023
  case 2:
21992
22024
  // Fill default properties
@@ -22004,8 +22036,8 @@
22004
22036
  data: json
22005
22037
  },
22006
22038
  error: { code: ErrorCodes$2.SAVE_DATA_ERROR, message: 'ERROR.SAVE_DATA_ERROR' },
22007
- update: function (cache, _a) {
22008
- var data = _a.data;
22039
+ update: function (cache, _b) {
22040
+ var data = _b.data;
22009
22041
  // Update entity
22010
22042
  var savedEntity = data && data.data;
22011
22043
  _this.copyIdAndUpdateDate(savedEntity, entity);
@@ -22024,7 +22056,7 @@
22024
22056
  }
22025
22057
  })];
22026
22058
  case 3:
22027
- _a.sent();
22059
+ _b.sent();
22028
22060
  return [2 /*return*/, entity];
22029
22061
  }
22030
22062
  });
@@ -22037,8 +22069,8 @@
22037
22069
  return __awaiter(this, void 0, void 0, function () {
22038
22070
  var ids, now;
22039
22071
  var _this = this;
22040
- return __generator(this, function (_a) {
22041
- switch (_a.label) {
22072
+ return __generator(this, function (_b) {
22073
+ switch (_b.label) {
22042
22074
  case 0:
22043
22075
  if (!this.mutations.deleteAll) {
22044
22076
  if (!this.mutations.delete)
@@ -22078,7 +22110,7 @@
22078
22110
  }
22079
22111
  })];
22080
22112
  case 1:
22081
- _a.sent();
22113
+ _b.sent();
22082
22114
  return [2 /*return*/];
22083
22115
  }
22084
22116
  });
@@ -22091,15 +22123,15 @@
22091
22123
  return __awaiter(this, void 0, void 0, function () {
22092
22124
  var data, id, now;
22093
22125
  var _this = this;
22094
- return __generator(this, function (_a) {
22095
- switch (_a.label) {
22126
+ return __generator(this, function (_b) {
22127
+ switch (_b.label) {
22096
22128
  case 0:
22097
22129
  if (!!this.mutations.delete) return [3 /*break*/, 2];
22098
22130
  if (!this.mutations.deleteAll)
22099
22131
  throw new Error('Not implemented');
22100
22132
  return [4 /*yield*/, this.deleteAll([entity], opts)];
22101
22133
  case 1:
22102
- data = _a.sent();
22134
+ data = _b.sent();
22103
22135
  return [2 /*return*/, data && data[0]];
22104
22136
  case 2:
22105
22137
  // Nothing to save: skip
@@ -22131,7 +22163,7 @@
22131
22163
  }
22132
22164
  })];
22133
22165
  case 3:
22134
- _a.sent();
22166
+ _b.sent();
22135
22167
  return [2 /*return*/];
22136
22168
  }
22137
22169
  });
@@ -22157,8 +22189,8 @@
22157
22189
  message: 'ERROR.SUBSCRIBE_DATA_ERROR'
22158
22190
  }
22159
22191
  })
22160
- .pipe(operators.map(function (_a) {
22161
- var data = _a.data;
22192
+ .pipe(operators.map(function (_b) {
22193
+ var data = _b.data;
22162
22194
  var entity = (!opts || opts.toEntity !== false) ? data && _this.fromObject(data) : data;
22163
22195
  if (entity && _this._debug)
22164
22196
  console.debug(_this._logPrefix + ("[WS] Received changes on " + _this._logTypeName + " {" + id + "}"), entity);