@infrab4a/connect 4.17.1 → 4.17.2-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.
package/index.cjs.js CHANGED
@@ -4452,6 +4452,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
4452
4452
  return class FindHasuraGraphQLMixin extends MixinBase {
4453
4453
  constructor() {
4454
4454
  super(...arguments);
4455
+ this.lastDistinct = {};
4455
4456
  this.bindOrderByAttributes = (orderBy, fields) => Object.keys(orderBy).reduce((acc, current) => [
4456
4457
  ...acc,
4457
4458
  {
@@ -4487,9 +4488,10 @@ const withFindHasuraGraphQL = (MixinBase) => {
4487
4488
  });
4488
4489
  }
4489
4490
  async find(params) {
4490
- var _a, _b, _c, _d, _e, _f, _g, _h;
4491
+ var _a, _b, _c, _d, _e, _f, _g;
4491
4492
  this.logger = DebugHelper.from(this, 'find');
4492
4493
  const { filters, limits, orderBy, options } = params || {};
4494
+ const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
4493
4495
  const enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
4494
4496
  const variablesFilters = lodash.isNil(filters)
4495
4497
  ? {}
@@ -4540,8 +4542,8 @@ const withFindHasuraGraphQL = (MixinBase) => {
4540
4542
  },
4541
4543
  ]
4542
4544
  : []),
4543
- ...((!((_b = params.limits) === null || _b === void 0 ? void 0 : _b.offset) &&
4544
- ((_d = (_c = params.options) === null || _c === void 0 ? void 0 : _c.distinct) === null || _d === void 0 ? void 0 : _d.map((distinct) => {
4545
+ ...((!this.lastDistinct[tableFiltersNamed] &&
4546
+ ((_c = (_b = params.options) === null || _b === void 0 ? void 0 : _b.distinct) === null || _c === void 0 ? void 0 : _c.map((distinct) => {
4545
4547
  var _a, _b;
4546
4548
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
4547
4549
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
@@ -4562,28 +4564,27 @@ const withFindHasuraGraphQL = (MixinBase) => {
4562
4564
  []),
4563
4565
  ]);
4564
4566
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
4565
- return Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_e = options === null || options === void 0 ? void 0 : options.minimal) === null || _e === void 0 ? void 0 : _e.length)
4567
+ return Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_d = options === null || options === void 0 ? void 0 : options.minimal) === null || _d === void 0 ? void 0 : _d.length)
4566
4568
  ? {
4567
4569
  minimal: options.minimal.reduce((minimals, current) => {
4568
4570
  var _a;
4569
4571
  return (Object.assign(Object.assign({}, minimals), lodash.set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
4570
4572
  }, {}),
4571
4573
  }
4572
- : {})), (((_f = options === null || options === void 0 ? void 0 : options.maximum) === null || _f === void 0 ? void 0 : _f.length)
4574
+ : {})), (((_e = options === null || options === void 0 ? void 0 : options.maximum) === null || _e === void 0 ? void 0 : _e.length)
4573
4575
  ? {
4574
4576
  maximum: options.maximum.reduce((maximums, current) => {
4575
4577
  var _a;
4576
4578
  return (Object.assign(Object.assign({}, maximums), lodash.set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
4577
4579
  }, {}),
4578
4580
  }
4579
- : {})), (!((_g = params.limits) === null || _g === void 0 ? void 0 : _g.offset) &&
4580
- ((_h = options === null || options === void 0 ? void 0 : options.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
4581
- distinct: options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
4581
+ : {})), (((_f = options === null || options === void 0 ? void 0 : options.distinct) === null || _f === void 0 ? void 0 : _f.length) && {
4582
+ distinct: (_g = this.lastDistinct[tableFiltersNamed]) !== null && _g !== void 0 ? _g : (this.lastDistinct[tableFiltersNamed] = options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
4582
4583
  var _a, _b;
4583
4584
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
4584
4585
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
4585
4586
  return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
4586
- }, {}),
4587
+ }, {})),
4587
4588
  }));
4588
4589
  }
4589
4590
  };
package/index.esm.js CHANGED
@@ -4446,6 +4446,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
4446
4446
  return class FindHasuraGraphQLMixin extends MixinBase {
4447
4447
  constructor() {
4448
4448
  super(...arguments);
4449
+ this.lastDistinct = {};
4449
4450
  this.bindOrderByAttributes = (orderBy, fields) => Object.keys(orderBy).reduce((acc, current) => [
4450
4451
  ...acc,
4451
4452
  {
@@ -4481,9 +4482,10 @@ const withFindHasuraGraphQL = (MixinBase) => {
4481
4482
  });
4482
4483
  }
4483
4484
  async find(params) {
4484
- var _a, _b, _c, _d, _e, _f, _g, _h;
4485
+ var _a, _b, _c, _d, _e, _f, _g;
4485
4486
  this.logger = DebugHelper.from(this, 'find');
4486
4487
  const { filters, limits, orderBy, options } = params || {};
4488
+ const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
4487
4489
  const enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
4488
4490
  const variablesFilters = isNil(filters)
4489
4491
  ? {}
@@ -4534,8 +4536,8 @@ const withFindHasuraGraphQL = (MixinBase) => {
4534
4536
  },
4535
4537
  ]
4536
4538
  : []),
4537
- ...((!((_b = params.limits) === null || _b === void 0 ? void 0 : _b.offset) &&
4538
- ((_d = (_c = params.options) === null || _c === void 0 ? void 0 : _c.distinct) === null || _d === void 0 ? void 0 : _d.map((distinct) => {
4539
+ ...((!this.lastDistinct[tableFiltersNamed] &&
4540
+ ((_c = (_b = params.options) === null || _b === void 0 ? void 0 : _b.distinct) === null || _c === void 0 ? void 0 : _c.map((distinct) => {
4539
4541
  var _a, _b;
4540
4542
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
4541
4543
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
@@ -4556,28 +4558,27 @@ const withFindHasuraGraphQL = (MixinBase) => {
4556
4558
  []),
4557
4559
  ]);
4558
4560
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
4559
- return Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_e = options === null || options === void 0 ? void 0 : options.minimal) === null || _e === void 0 ? void 0 : _e.length)
4561
+ return Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_d = options === null || options === void 0 ? void 0 : options.minimal) === null || _d === void 0 ? void 0 : _d.length)
4560
4562
  ? {
4561
4563
  minimal: options.minimal.reduce((minimals, current) => {
4562
4564
  var _a;
4563
4565
  return (Object.assign(Object.assign({}, minimals), set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
4564
4566
  }, {}),
4565
4567
  }
4566
- : {})), (((_f = options === null || options === void 0 ? void 0 : options.maximum) === null || _f === void 0 ? void 0 : _f.length)
4568
+ : {})), (((_e = options === null || options === void 0 ? void 0 : options.maximum) === null || _e === void 0 ? void 0 : _e.length)
4567
4569
  ? {
4568
4570
  maximum: options.maximum.reduce((maximums, current) => {
4569
4571
  var _a;
4570
4572
  return (Object.assign(Object.assign({}, maximums), set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
4571
4573
  }, {}),
4572
4574
  }
4573
- : {})), (!((_g = params.limits) === null || _g === void 0 ? void 0 : _g.offset) &&
4574
- ((_h = options === null || options === void 0 ? void 0 : options.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
4575
- distinct: options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
4575
+ : {})), (((_f = options === null || options === void 0 ? void 0 : options.distinct) === null || _f === void 0 ? void 0 : _f.length) && {
4576
+ distinct: (_g = this.lastDistinct[tableFiltersNamed]) !== null && _g !== void 0 ? _g : (this.lastDistinct[tableFiltersNamed] = options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
4576
4577
  var _a, _b;
4577
4578
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
4578
4579
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
4579
4580
  return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
4580
- }, {}),
4581
+ }, {})),
4581
4582
  }));
4582
4583
  }
4583
4584
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.17.1",
3
+ "version": "4.17.2-beta.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -3,6 +3,7 @@ import { DebugHelper, MixinCtor } from '../../../utils';
3
3
  import { GraphQLParams, GraphQLRepository, HasuraGraphQLFields } from '../types';
4
4
  export declare const withFindHasuraGraphQL: <MBase extends ModelBaseStructure<MBase, MBase["identifiersFields"][number]>, TMixinBase extends MixinCtor<GraphQLRepository<MBase>, any[]>>(MixinBase: MixinCtor<GraphQLRepository<MBase>, any[]> & TMixinBase) => {
5
5
  new (...args: any[]): {
6
+ lastDistinct: Record<string, any>;
6
7
  find(params?: FindRepositoryParams<MBase>): Promise<RepositoryFindResult<MBase>>;
7
8
  bindOrderByAttributes: (orderBy: RepositoryOrderBy<MBase>, fields: HasuraGraphQLFields<MBase>) => any[];
8
9
  bindAggretageAttributes: (aggregates: {