@infrab4a/connect 3.3.0 → 3.3.1-beta.1

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.
@@ -2028,35 +2028,37 @@
2028
2028
  };
2029
2029
  return _this;
2030
2030
  }
2031
- FindFirestore.prototype.find = function (_a) {
2032
- var _b = _a === void 0 ? {} : _a, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
2031
+ FindFirestore.prototype.find = function (_b) {
2032
+ var _c = _b === void 0 ? {} : _b, filters = _c.filters, limits = _c.limits, orderBy = _c.orderBy, options = _c.options;
2033
+ var _a;
2033
2034
  return __awaiter(this, void 0, void 0, function () {
2034
- var orderByKeys, query, filtersKeysWithUnordered, docs, data;
2035
- return __generator(this, function (_a) {
2036
- switch (_a.label) {
2035
+ var orderByKeys, enableCount, query, filtersKeysWithUnordered, docs, data;
2036
+ return __generator(this, function (_b) {
2037
+ switch (_b.label) {
2037
2038
  case 0:
2038
2039
  orderByKeys = Object.keys(orderBy || {});
2040
+ enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
2039
2041
  query = this.collection(this.buildCollectionPathForFind(filters || {}));
2040
2042
  query = this.makeFirestoreWhere(query, filters || {});
2041
2043
  if (orderByKeys.length) {
2042
2044
  filtersKeysWithUnordered = Object.keys(filters || {}).filter(function (filterKey) { return !orderByKeys.includes(filterKey); });
2043
2045
  if (filtersKeysWithUnordered.length)
2044
2046
  filtersKeysWithUnordered.forEach(function (filterKey) {
2045
- var _a;
2046
- return (orderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(filters[filterKey].operator) ? (_a = {}, _a[filterKey] = 'asc', _a) : {})), orderBy));
2047
+ var _b;
2048
+ return (orderBy = Object.assign(Object.assign({}, (![exports.Where.EQUALS].includes(filters[filterKey].operator) ? (_b = {}, _b[filterKey] = 'asc', _b) : {})), orderBy));
2047
2049
  });
2048
2050
  Object.keys(orderBy).forEach(function (fieldName) { return (query = query.orderBy(fieldName, orderBy[fieldName])); });
2049
2051
  }
2050
2052
  return [4 /*yield*/, this.defineLimits(query, filters, limits)];
2051
2053
  case 1:
2052
- query = _a.sent();
2054
+ query = _b.sent();
2053
2055
  return [4 /*yield*/, query.get()];
2054
2056
  case 2:
2055
- docs = _a.sent();
2057
+ docs = _b.sent();
2056
2058
  data = docs.docs.map(function (doc) { return doc.data(); });
2057
2059
  return [2 /*return*/, {
2058
2060
  data: data,
2059
- count: this.calculateCount(data, limits),
2061
+ count: enableCount ? this.calculateCount(data, limits) : Infinity,
2060
2062
  }];
2061
2063
  }
2062
2064
  });
@@ -2071,23 +2073,23 @@
2071
2073
  };
2072
2074
  FindFirestore.prototype.defineLimits = function (query, filters, limits) {
2073
2075
  return __awaiter(this, void 0, void 0, function () {
2074
- var _a, _b;
2075
- return __generator(this, function (_c) {
2076
- switch (_c.label) {
2076
+ var _b, _c;
2077
+ return __generator(this, function (_d) {
2078
+ switch (_d.label) {
2077
2079
  case 0:
2078
2080
  if (!(limits === null || limits === void 0 ? void 0 : limits.offset)) return [3 /*break*/, 3];
2079
2081
  if (!this.model.isModel(limits.offset)) return [3 /*break*/, 2];
2080
- _b = (_a = query).startAfter;
2082
+ _c = (_b = query).startAfter;
2081
2083
  return [4 /*yield*/, this.collection(this.buildCollectionPathForFind(filters))
2082
2084
  .doc(limits.offset[limits.offset.identifiersFields.shift()])
2083
2085
  .get()];
2084
2086
  case 1:
2085
- query = _b.apply(_a, [_c.sent()]);
2087
+ query = _c.apply(_b, [_d.sent()]);
2086
2088
  return [3 /*break*/, 3];
2087
2089
  case 2:
2088
2090
  if (lodash.isNumber(limits.offset) || lodash.isString(limits.offset))
2089
2091
  query = query.startAt(limits.offset);
2090
- _c.label = 3;
2092
+ _d.label = 3;
2091
2093
  case 3:
2092
2094
  if (limits === null || limits === void 0 ? void 0 : limits.limit)
2093
2095
  query = query.limit(limits.limit);
@@ -3593,14 +3595,16 @@
3593
3595
  function FindHasuraGraphQLMixin() {
3594
3596
  return _super !== null && _super.apply(this, arguments) || this;
3595
3597
  }
3596
- FindHasuraGraphQLMixin.prototype.find = function (options) {
3598
+ FindHasuraGraphQLMixin.prototype.find = function (params) {
3599
+ var _a;
3597
3600
  return __awaiter(this, void 0, void 0, function () {
3598
- var _b, filters, limits, orderBy, variablesCount, variables, result, data, count;
3601
+ var _b, filters, limits, orderBy, options, enableCount, variablesCount, variables, result, data, count;
3599
3602
  var _this = this;
3600
3603
  return __generator(this, function (_c) {
3601
3604
  switch (_c.label) {
3602
3605
  case 0:
3603
- _b = options || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
3606
+ _b = params || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy, options = _b.options;
3607
+ enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
3604
3608
  variablesCount = Object.assign(Object.assign({}, (lodash.isNil(orderBy) ? {} : { order_by: { type: this.tableName + "_order_by!", list: true, value: orderBy } })), (lodash.isNil(filters)
3605
3609
  ? {}
3606
3610
  : {
@@ -3611,11 +3615,11 @@
3611
3615
  },
3612
3616
  }));
3613
3617
  variables = Object.assign(Object.assign({}, (lodash.isNil(limits) ? {} : limits)), variablesCount);
3614
- return [4 /*yield*/, this.query([
3618
+ return [4 /*yield*/, this.query(__spreadArray([
3615
3619
  {
3616
3620
  operation: this.tableName,
3617
- fields: options.fields
3618
- ? options.fields
3621
+ fields: params.fields
3622
+ ? params.fields
3619
3623
  .map(function (fieldName) {
3620
3624
  var _a;
3621
3625
  return (_a = _this.fields.find(function (fieldOption) { return fieldOption === fieldName; })) !== null && _a !== void 0 ? _a : _this.fields.find(function (fieldOption) { return Object.keys(fieldOption).shift() === fieldName; });
@@ -3623,18 +3627,21 @@
3623
3627
  .filter(Boolean)
3624
3628
  : this.fields,
3625
3629
  variables: variables,
3626
- },
3627
- {
3628
- operation: this.tableName + "_aggregate",
3629
- fields: [{ aggregate: ['count'] }],
3630
- variables: variablesCount,
3631
- },
3632
- ])];
3630
+ }
3631
+ ], __read((enableCount
3632
+ ? []
3633
+ : [
3634
+ {
3635
+ operation: this.tableName + "_aggregate",
3636
+ fields: [{ aggregate: ['count'] }],
3637
+ variables: variablesCount,
3638
+ },
3639
+ ]))))];
3633
3640
  case 1:
3634
3641
  result = _c.sent();
3635
3642
  data = result[this.tableName].map(function (row) { return _this.convertDataFromHasura(row); });
3636
- count = result[this.tableName + "_aggregate"].aggregate.count;
3637
- return [2 /*return*/, { count: count, data: data }];
3643
+ count = enableCount && result[this.tableName + "_aggregate"].aggregate.count;
3644
+ return [2 /*return*/, { data: data, count: enableCount ? count : Infinity }];
3638
3645
  }
3639
3646
  });
3640
3647
  });
@@ -4341,21 +4348,21 @@
4341
4348
  ProductHasuraGraphQLRepository.prototype.getBySlug = function (slug) {
4342
4349
  var _a;
4343
4350
  return __awaiter(this, void 0, void 0, function () {
4344
- var result, product, _c;
4345
- return __generator(this, function (_d) {
4346
- switch (_d.label) {
4351
+ var result, product;
4352
+ return __generator(this, function (_c) {
4353
+ switch (_c.label) {
4347
4354
  case 0: return [4 /*yield*/, this.find({
4348
4355
  filters: {
4349
4356
  slug: slug,
4350
4357
  },
4358
+ fields: this.fields.map(function (field) { return typeof field === 'string' ? field : Object.keys(field).shift(); }),
4359
+ options: {
4360
+ enableCount: false,
4361
+ },
4351
4362
  })];
4352
4363
  case 1:
4353
- result = _d.sent();
4364
+ result = _c.sent();
4354
4365
  product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
4355
- _c = product;
4356
- return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
4357
- case 2:
4358
- _c.reviews = _d.sent();
4359
4366
  return [2 /*return*/, product];
4360
4367
  }
4361
4368
  });