@infrab4a/connect 4.25.0-beta.4 → 4.25.0-beta.6

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
@@ -5098,19 +5098,19 @@ const withFindHasuraGraphQL = (MixinBase) => {
5098
5098
  });
5099
5099
  }
5100
5100
  async find(params, options) {
5101
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
5101
+ var _a, _b, _c, _d, _e, _f, _g, _h;
5102
5102
  this.logger = DebugHelper.from(this, 'find');
5103
- if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
5103
+ const { filters, limits, orderBy, options: findOptions } = params || {};
5104
+ const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
5105
+ const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
5106
+ if (((_b = this.cache) === null || _b === void 0 ? void 0 : _b.cacheAdapter) && ((_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.enabled)) {
5104
5107
  const cacheKey = generateCacheKey(this.model, params);
5105
5108
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
5106
5109
  if (cachedData) {
5107
5110
  this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
5108
- return JSON.parse(cachedData);
5111
+ return this.bindResult(JSON.parse(cachedData), { enableCount, findOptions, tableFiltersNamed });
5109
5112
  }
5110
5113
  }
5111
- const { filters, limits, orderBy, options: findOptions } = params || {};
5112
- const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
5113
- const enableCount = (_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _c !== void 0 ? _c : true;
5114
5114
  const variablesFilters = lodash.isNil(filters)
5115
5115
  ? {}
5116
5116
  : {
@@ -5181,38 +5181,42 @@ const withFindHasuraGraphQL = (MixinBase) => {
5181
5181
  }))) ||
5182
5182
  []),
5183
5183
  ]);
5184
+ if (((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) && ((_g = options === null || options === void 0 ? void 0 : options.cache) === null || _g === void 0 ? void 0 : _g.enabled)) {
5185
+ const cacheKey = generateCacheKey(this.model, params);
5186
+ await this.cache.cacheAdapter.set({
5187
+ key: cacheKey,
5188
+ data: JSON.stringify(result),
5189
+ expirationInSeconds: ((_h = options === null || options === void 0 ? void 0 : options.cache) === null || _h === void 0 ? void 0 : _h.ttl) || this.cache.ttlDefault,
5190
+ });
5191
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5192
+ }
5193
+ return this.bindResult(result, { enableCount, findOptions, tableFiltersNamed });
5194
+ }
5195
+ bindResult(result, { enableCount, findOptions, tableFiltersNamed, }) {
5196
+ var _a, _b, _c, _d;
5184
5197
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
5185
- const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_f = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _f === void 0 ? void 0 : _f.length)
5198
+ const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _a === void 0 ? void 0 : _a.length)
5186
5199
  ? {
5187
5200
  minimal: findOptions.minimal.reduce((minimals, current) => {
5188
5201
  var _a;
5189
5202
  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])));
5190
5203
  }, {}),
5191
5204
  }
5192
- : {})), (((_g = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _g === void 0 ? void 0 : _g.length)
5205
+ : {})), (((_b = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _b === void 0 ? void 0 : _b.length)
5193
5206
  ? {
5194
5207
  maximum: findOptions.maximum.reduce((maximums, current) => {
5195
5208
  var _a;
5196
5209
  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])));
5197
5210
  }, {}),
5198
5211
  }
5199
- : {})), (((_h = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
5200
- distinct: (_j = this.lastDistinct[tableFiltersNamed]) !== null && _j !== void 0 ? _j : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
5212
+ : {})), (((_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _c === void 0 ? void 0 : _c.length) && {
5213
+ distinct: (_d = this.lastDistinct[tableFiltersNamed]) !== null && _d !== void 0 ? _d : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
5201
5214
  var _a, _b;
5202
5215
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
5203
5216
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
5204
5217
  return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
5205
5218
  }, {})),
5206
5219
  }));
5207
- if (((_k = this.cache) === null || _k === void 0 ? void 0 : _k.cacheAdapter) && ((_l = options === null || options === void 0 ? void 0 : options.cache) === null || _l === void 0 ? void 0 : _l.enabled)) {
5208
- const cacheKey = generateCacheKey(this.model, params);
5209
- await this.cache.cacheAdapter.set({
5210
- key: cacheKey,
5211
- data: JSON.stringify(findResult),
5212
- expirationInSeconds: ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.ttl) || this.cache.ttlDefault,
5213
- });
5214
- this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5215
- }
5216
5220
  return findResult;
5217
5221
  }
5218
5222
  };
package/index.esm.js CHANGED
@@ -5092,19 +5092,19 @@ const withFindHasuraGraphQL = (MixinBase) => {
5092
5092
  });
5093
5093
  }
5094
5094
  async find(params, options) {
5095
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
5095
+ var _a, _b, _c, _d, _e, _f, _g, _h;
5096
5096
  this.logger = DebugHelper.from(this, 'find');
5097
- if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled)) {
5097
+ const { filters, limits, orderBy, options: findOptions } = params || {};
5098
+ const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
5099
+ const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
5100
+ if (((_b = this.cache) === null || _b === void 0 ? void 0 : _b.cacheAdapter) && ((_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.enabled)) {
5098
5101
  const cacheKey = generateCacheKey(this.model, params);
5099
5102
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
5100
5103
  if (cachedData) {
5101
5104
  this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
5102
- return JSON.parse(cachedData);
5105
+ return this.bindResult(JSON.parse(cachedData), { enableCount, findOptions, tableFiltersNamed });
5103
5106
  }
5104
5107
  }
5105
- const { filters, limits, orderBy, options: findOptions } = params || {};
5106
- const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
5107
- const enableCount = (_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _c !== void 0 ? _c : true;
5108
5108
  const variablesFilters = isNil(filters)
5109
5109
  ? {}
5110
5110
  : {
@@ -5175,38 +5175,42 @@ const withFindHasuraGraphQL = (MixinBase) => {
5175
5175
  }))) ||
5176
5176
  []),
5177
5177
  ]);
5178
+ if (((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) && ((_g = options === null || options === void 0 ? void 0 : options.cache) === null || _g === void 0 ? void 0 : _g.enabled)) {
5179
+ const cacheKey = generateCacheKey(this.model, params);
5180
+ await this.cache.cacheAdapter.set({
5181
+ key: cacheKey,
5182
+ data: JSON.stringify(result),
5183
+ expirationInSeconds: ((_h = options === null || options === void 0 ? void 0 : options.cache) === null || _h === void 0 ? void 0 : _h.ttl) || this.cache.ttlDefault,
5184
+ });
5185
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5186
+ }
5187
+ return this.bindResult(result, { enableCount, findOptions, tableFiltersNamed });
5188
+ }
5189
+ bindResult(result, { enableCount, findOptions, tableFiltersNamed, }) {
5190
+ var _a, _b, _c, _d;
5178
5191
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
5179
- const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_f = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _f === void 0 ? void 0 : _f.length)
5192
+ const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _a === void 0 ? void 0 : _a.length)
5180
5193
  ? {
5181
5194
  minimal: findOptions.minimal.reduce((minimals, current) => {
5182
5195
  var _a;
5183
5196
  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])));
5184
5197
  }, {}),
5185
5198
  }
5186
- : {})), (((_g = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _g === void 0 ? void 0 : _g.length)
5199
+ : {})), (((_b = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _b === void 0 ? void 0 : _b.length)
5187
5200
  ? {
5188
5201
  maximum: findOptions.maximum.reduce((maximums, current) => {
5189
5202
  var _a;
5190
5203
  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])));
5191
5204
  }, {}),
5192
5205
  }
5193
- : {})), (((_h = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
5194
- distinct: (_j = this.lastDistinct[tableFiltersNamed]) !== null && _j !== void 0 ? _j : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
5206
+ : {})), (((_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _c === void 0 ? void 0 : _c.length) && {
5207
+ distinct: (_d = this.lastDistinct[tableFiltersNamed]) !== null && _d !== void 0 ? _d : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
5195
5208
  var _a, _b;
5196
5209
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
5197
5210
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
5198
5211
  return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
5199
5212
  }, {})),
5200
5213
  }));
5201
- if (((_k = this.cache) === null || _k === void 0 ? void 0 : _k.cacheAdapter) && ((_l = options === null || options === void 0 ? void 0 : options.cache) === null || _l === void 0 ? void 0 : _l.enabled)) {
5202
- const cacheKey = generateCacheKey(this.model, params);
5203
- await this.cache.cacheAdapter.set({
5204
- key: cacheKey,
5205
- data: JSON.stringify(findResult),
5206
- expirationInSeconds: ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.ttl) || this.cache.ttlDefault,
5207
- });
5208
- this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5209
- }
5210
5214
  return findResult;
5211
5215
  }
5212
5216
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.25.0-beta.4",
3
+ "version": "4.25.0-beta.6",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -7,6 +7,22 @@ export declare const withFindHasuraGraphQL: <MBase extends ModelBaseStructure<MB
7
7
  find(params?: FindRepositoryParams<MBase>, options?: {
8
8
  cache?: RepositoryCacheOptions;
9
9
  }): Promise<RepositoryFindResult<MBase>>;
10
+ bindResult(result: any, { enableCount, findOptions, tableFiltersNamed, }: {
11
+ enableCount: boolean;
12
+ findOptions: {
13
+ enableCount?: boolean;
14
+ minimal?: ({} | NonFunctionAndIdentifierPropertyNames<MBase>)[];
15
+ maximum?: ({} | NonFunctionAndIdentifierPropertyNames<MBase>)[];
16
+ distinct?: ({} | NonFunctionAndIdentifierPropertyNames<MBase>)[];
17
+ };
18
+ tableFiltersNamed: string;
19
+ }): {
20
+ distinct: any;
21
+ maximum?: import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase> extends infer T extends import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase> ? { [key in keyof T]: import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase>[key]; } : never;
22
+ minimal?: import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase> extends infer T extends import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase> ? { [key in keyof T]: import("../../../domain").NonFunctionAndIdentifierPropertiesWithNoPartial<MBase>[key]; } : never;
23
+ data: MBase[];
24
+ count: any;
25
+ };
10
26
  bindOrderByAttributes: (orderBy: RepositoryOrderBy<MBase>, fields: HasuraGraphQLFields<MBase>) => any[];
11
27
  bindAggretageAttributes: (aggregates: {
12
28
  minimal?: ({} | NonFunctionAndIdentifierPropertyNames<MBase>)[];