@infrab4a/connect 4.17.0 → 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
|
|
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
|
-
...((!
|
|
4544
|
-
((
|
|
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 }, (((
|
|
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
|
-
: {})), (((
|
|
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
|
-
: {})), (
|
|
4580
|
-
(
|
|
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
|
};
|
|
@@ -4981,7 +4982,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
4981
4982
|
const mostRelevants = category.getMostRelevantByShop(shop);
|
|
4982
4983
|
const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
|
|
4983
4984
|
const products = [];
|
|
4984
|
-
const { data: productsData } = await this.productRepository.
|
|
4985
|
+
const { data: productsData } = await this.productRepository.findCatalog({
|
|
4985
4986
|
filters: {
|
|
4986
4987
|
id: { operator: exports.Where.IN, value: mostRelevantProductsIds },
|
|
4987
4988
|
published: true,
|
|
@@ -5020,13 +5021,13 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5020
5021
|
stock: 'desc',
|
|
5021
5022
|
name: 'asc',
|
|
5022
5023
|
},
|
|
5023
|
-
});
|
|
5024
|
+
}, shop === exports.Shops.MENSMARKET ? 'male' : 'female');
|
|
5024
5025
|
const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
|
|
5025
5026
|
const firstProducts = productsData
|
|
5026
5027
|
.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
5027
5028
|
.sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
|
|
5028
5029
|
const lastProducts = productsData
|
|
5029
|
-
.filter((product) => !mostRelevants.includes(product.id))
|
|
5030
|
+
.filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
5030
5031
|
.concat(mostRelevantWithouyStock);
|
|
5031
5032
|
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
5032
5033
|
const resultFinal = categoryMostRelevants.slice(0, options.limit);
|
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
|
|
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
|
-
...((!
|
|
4538
|
-
((
|
|
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 }, (((
|
|
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
|
-
: {})), (((
|
|
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
|
-
: {})), (
|
|
4574
|
-
(
|
|
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
|
};
|
|
@@ -4975,7 +4976,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
4975
4976
|
const mostRelevants = category.getMostRelevantByShop(shop);
|
|
4976
4977
|
const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
|
|
4977
4978
|
const products = [];
|
|
4978
|
-
const { data: productsData } = await this.productRepository.
|
|
4979
|
+
const { data: productsData } = await this.productRepository.findCatalog({
|
|
4979
4980
|
filters: {
|
|
4980
4981
|
id: { operator: Where.IN, value: mostRelevantProductsIds },
|
|
4981
4982
|
published: true,
|
|
@@ -5014,13 +5015,13 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
5014
5015
|
stock: 'desc',
|
|
5015
5016
|
name: 'asc',
|
|
5016
5017
|
},
|
|
5017
|
-
});
|
|
5018
|
+
}, shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
5018
5019
|
const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
|
|
5019
5020
|
const firstProducts = productsData
|
|
5020
5021
|
.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
5021
5022
|
.sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
|
|
5022
5023
|
const lastProducts = productsData
|
|
5023
|
-
.filter((product) => !mostRelevants.includes(product.id))
|
|
5024
|
+
.filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
5024
5025
|
.concat(mostRelevantWithouyStock);
|
|
5025
5026
|
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
5026
5027
|
const resultFinal = categoryMostRelevants.slice(0, options.limit);
|
package/package.json
CHANGED
|
@@ -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: {
|