@infrab4a/connect 1.0.0-beta.18 → 1.0.0-beta.19
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/bundles/infrab4a-connect.umd.js +71 -53
- package/bundles/infrab4a-connect.umd.js.map +1 -1
- package/esm2015/infra/hasura-graphql/mixins/helpers/graphql-field.helper.js +4 -6
- package/esm2015/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.js +16 -2
- package/esm2015/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.js +4 -3
- package/esm2015/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.js +3 -3
- package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +4 -3
- package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +10 -8
- package/fesm2015/infrab4a-connect.js +34 -18
- package/fesm2015/infrab4a-connect.js.map +1 -1
- package/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.d.ts +1 -1
- package/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +2 -2
- package/package.json +1 -1
|
@@ -2863,9 +2863,7 @@
|
|
|
2863
2863
|
if (update === void 0) { update = false; }
|
|
2864
2864
|
var _a;
|
|
2865
2865
|
var data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
|
|
2866
|
-
return Object.keys(data)
|
|
2867
|
-
.filter(function (key) { return !lodash.isNil(data[key]); })
|
|
2868
|
-
.reduce(function (result, attributeName) {
|
|
2866
|
+
return Object.keys(data).reduce(function (result, attributeName) {
|
|
2869
2867
|
var _b, _c, _d;
|
|
2870
2868
|
var _e = AttributeOptionHelper.FindByAttribute(attributeName, fields), columnName = _e.columnName, attributeFields = _e.fields, foreignKeyColumn = _e.foreignKeyColumn, to = _e.to, bindPersistData = _e.bindPersistData;
|
|
2871
2869
|
if (bindPersistData)
|
|
@@ -2874,10 +2872,11 @@
|
|
|
2874
2872
|
return result;
|
|
2875
2873
|
if (!!foreignKeyColumn &&
|
|
2876
2874
|
!lodash.isEmpty(foreignKeyColumn) &&
|
|
2877
|
-
!Object.keys(foreignKeyColumn).filter(function (key) { return !data[attributeName][key]; }).length)
|
|
2875
|
+
!Object.keys(foreignKeyColumn).filter(function (key) { var _a; return !((_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[key]); }).length)
|
|
2878
2876
|
return Object.keys(foreignKeyColumn).reduce(function (object, current) {
|
|
2879
2877
|
var _b;
|
|
2880
|
-
|
|
2878
|
+
var _a;
|
|
2879
|
+
return (Object.assign(Object.assign({}, object), (_b = {}, _b[foreignKeyColumn[current]] = (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current], _b)));
|
|
2881
2880
|
}, Object.assign({}, result));
|
|
2882
2881
|
if (update && lodash.isObject(data[attributeName]) && !lodash.isNil(attributeFields) && !lodash.isDate(data[attributeName]))
|
|
2883
2882
|
return result;
|
|
@@ -2947,13 +2946,28 @@
|
|
|
2947
2946
|
};
|
|
2948
2947
|
CreateHasuraGraphQLMixin.prototype.save = function (data) {
|
|
2949
2948
|
return __awaiter(this, void 0, void 0, function () {
|
|
2950
|
-
var result;
|
|
2949
|
+
var primaryKeyColumns, foreignKeyColumns, result;
|
|
2951
2950
|
var _this = this;
|
|
2952
2951
|
return __generator(this, function (_a) {
|
|
2953
2952
|
switch (_a.label) {
|
|
2954
|
-
case 0:
|
|
2955
|
-
|
|
2956
|
-
|
|
2953
|
+
case 0:
|
|
2954
|
+
primaryKeyColumns = this.model.identifiersFields.map(function (field) { return AttributeOptionHelper.FindByAttribute(field, _this.fields).columnName; });
|
|
2955
|
+
foreignKeyColumns = this.fields
|
|
2956
|
+
.map(function (field) {
|
|
2957
|
+
var _a;
|
|
2958
|
+
var columnOptions = Object.values(field).shift();
|
|
2959
|
+
return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
|
|
2960
|
+
columnOptions.foreignKeyColumn && __spreadArray(__spreadArray([], __read(Object.values(columnOptions.foreignKeyColumn))), [
|
|
2961
|
+
(_a = {},
|
|
2962
|
+
_a[columnOptions.columnName] = Object.keys(columnOptions.foreignKeyColumn),
|
|
2963
|
+
_a),
|
|
2964
|
+
]));
|
|
2965
|
+
})
|
|
2966
|
+
.filter(Boolean)
|
|
2967
|
+
.reduce(function (keys, current) { return __spreadArray(__spreadArray([], __read(keys)), __read(current)); }, []);
|
|
2968
|
+
return [4 /*yield*/, this.mutation(this.insertGraphQLOperation, __spreadArray(__spreadArray([], __read(primaryKeyColumns)), __read(foreignKeyColumns)), {
|
|
2969
|
+
object: { type: this.insertGraphQLObjectType, required: true, value: this.convertDataToHasura(data) },
|
|
2970
|
+
})];
|
|
2957
2971
|
case 1:
|
|
2958
2972
|
result = _a.sent();
|
|
2959
2973
|
return [2 /*return*/, Object.assign(Object.assign({}, data.toPlain()), this.convertDataFromHasura(result[this.insertGraphQLOperation]).toPlain())];
|
|
@@ -3134,7 +3148,7 @@
|
|
|
3134
3148
|
return options.toPlain();
|
|
3135
3149
|
if (lodash.isNil(options.action))
|
|
3136
3150
|
return options;
|
|
3137
|
-
if (
|
|
3151
|
+
if ([exports.UpdateOptionActions.REMOVE_FIELD.toString(), exports.UpdateOptionActions.NULL.toString()].includes(options.action))
|
|
3138
3152
|
return null;
|
|
3139
3153
|
return options.value;
|
|
3140
3154
|
};
|
|
@@ -3182,7 +3196,7 @@
|
|
|
3182
3196
|
return params.toPlain();
|
|
3183
3197
|
return Object.keys(params).reduce(function (data, currentKey) {
|
|
3184
3198
|
var _b;
|
|
3185
|
-
return (Object.assign(Object.assign({}, data), (params[currentKey] && (_b = {}, _b[currentKey] = getValueByAction(params[currentKey]), _b))));
|
|
3199
|
+
return (Object.assign(Object.assign({}, data), (params[currentKey] !== undefined && (_b = {}, _b[currentKey] = getValueByAction(params[currentKey]), _b))));
|
|
3186
3200
|
}, {});
|
|
3187
3201
|
};
|
|
3188
3202
|
UpdateHasuraGraphQLMixin.prototype.getUpdateModelKeys = function (data) {
|
|
@@ -3220,24 +3234,25 @@
|
|
|
3220
3234
|
return __awaiter(this, void 0, void 0, function () {
|
|
3221
3235
|
var instance, result, data;
|
|
3222
3236
|
var _this = this;
|
|
3223
|
-
return __generator(this, function (
|
|
3224
|
-
switch (
|
|
3237
|
+
return __generator(this, function (_b) {
|
|
3238
|
+
switch (_b.label) {
|
|
3225
3239
|
case 0:
|
|
3226
3240
|
instance = this.model.toInstance(identifiers);
|
|
3227
3241
|
return [4 /*yield*/, this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce(function (ids, identifier) {
|
|
3242
|
+
var _b;
|
|
3228
3243
|
var _a;
|
|
3229
3244
|
if (lodash.isNil(instance[identifier]))
|
|
3230
3245
|
return ids;
|
|
3231
3246
|
var columnOption = AttributeOptionHelper.FindByAttribute(identifier, _this.fields);
|
|
3232
|
-
var value = columnOption.to(identifiers[identifier.toString()], instance);
|
|
3233
|
-
return Object.assign(Object.assign({}, ids), (
|
|
3247
|
+
var value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, identifiers[identifier.toString()], instance)) || identifiers[identifier.toString()];
|
|
3248
|
+
return Object.assign(Object.assign({}, ids), (_b = {}, _b[columnOption.columnName] = {
|
|
3234
3249
|
type: _this.getAttributeGraphQLTypeOf(columnOption.type || value),
|
|
3235
3250
|
value: value,
|
|
3236
3251
|
required: true,
|
|
3237
|
-
},
|
|
3252
|
+
}, _b));
|
|
3238
3253
|
}, {}))];
|
|
3239
3254
|
case 1:
|
|
3240
|
-
result =
|
|
3255
|
+
result = _b.sent();
|
|
3241
3256
|
data = result[this.getGraphQLOperation];
|
|
3242
3257
|
if (lodash.isNil(data))
|
|
3243
3258
|
throw new NotFoundError(instance.constructor.name + " not found");
|
|
@@ -3463,11 +3478,12 @@
|
|
|
3463
3478
|
conditions: {
|
|
3464
3479
|
columnName: 'tag_condition',
|
|
3465
3480
|
type: HasuraGraphQLColumnType.Jsonb,
|
|
3466
|
-
from: function (tags, row) { return ({ brand: row.brand_condition, tags: tags }); },
|
|
3481
|
+
from: function (tags, row) { return ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }); },
|
|
3467
3482
|
bindPersistData: function (value) {
|
|
3483
|
+
var _a, _b;
|
|
3468
3484
|
return {
|
|
3469
3485
|
brand_condition: value.brand,
|
|
3470
|
-
tag_condition: "{\"" + value.tags.join('","') + "\"}",
|
|
3486
|
+
tag_condition: "{\"" + (((_b = (_a = value === null || value === void 0 ? void 0 : value.tags) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '","')) || '') + "\"}",
|
|
3471
3487
|
};
|
|
3472
3488
|
},
|
|
3473
3489
|
bindFindFilter: function (sentence) {
|
|
@@ -3499,34 +3515,34 @@
|
|
|
3499
3515
|
});
|
|
3500
3516
|
var _a;
|
|
3501
3517
|
return __awaiter(this, void 0, void 0, function () {
|
|
3502
|
-
var
|
|
3503
|
-
return __generator(this, function (
|
|
3504
|
-
switch (
|
|
3518
|
+
var _c;
|
|
3519
|
+
return __generator(this, function (_d) {
|
|
3520
|
+
switch (_d.label) {
|
|
3505
3521
|
case 0:
|
|
3506
3522
|
if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
|
|
3507
3523
|
return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
|
|
3508
3524
|
case 1:
|
|
3509
|
-
|
|
3525
|
+
_c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
|
|
3510
3526
|
return [3 /*break*/, 3];
|
|
3511
3527
|
case 2:
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
case 3: return [2 /*return*/,
|
|
3528
|
+
_c = _super.get.call(this, identifiers);
|
|
3529
|
+
_d.label = 3;
|
|
3530
|
+
case 3: return [2 /*return*/, _c];
|
|
3515
3531
|
}
|
|
3516
3532
|
});
|
|
3517
3533
|
});
|
|
3518
3534
|
};
|
|
3519
3535
|
CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
|
|
3520
3536
|
return __awaiter(this, void 0, void 0, function () {
|
|
3521
|
-
var
|
|
3522
|
-
return __generator(this, function (
|
|
3523
|
-
switch (
|
|
3537
|
+
var _c, data, count;
|
|
3538
|
+
return __generator(this, function (_d) {
|
|
3539
|
+
switch (_d.label) {
|
|
3524
3540
|
case 0:
|
|
3525
3541
|
if (!slug)
|
|
3526
3542
|
return [2 /*return*/];
|
|
3527
3543
|
return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
|
|
3528
3544
|
case 1:
|
|
3529
|
-
|
|
3545
|
+
_c = _d.sent(), data = _c.data, count = _c.count;
|
|
3530
3546
|
if (count > 1)
|
|
3531
3547
|
throw new DuplicatedResultsError('Query returned duplicated values');
|
|
3532
3548
|
if (!count)
|
|
@@ -3539,33 +3555,33 @@
|
|
|
3539
3555
|
CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
|
|
3540
3556
|
if (limit === void 0) { limit = 4; }
|
|
3541
3557
|
return __awaiter(this, void 0, void 0, function () {
|
|
3542
|
-
var
|
|
3558
|
+
var _c, categories, count, homeSections;
|
|
3543
3559
|
var _this = this;
|
|
3544
|
-
return __generator(this, function (
|
|
3545
|
-
switch (
|
|
3560
|
+
return __generator(this, function (_d) {
|
|
3561
|
+
switch (_d.label) {
|
|
3546
3562
|
case 0: return [4 /*yield*/, this.find({
|
|
3547
3563
|
filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
|
|
3548
3564
|
})];
|
|
3549
3565
|
case 1:
|
|
3550
|
-
|
|
3566
|
+
_c = _d.sent(), categories = _c.data, count = _c.count;
|
|
3551
3567
|
if (!count)
|
|
3552
3568
|
throw new NotFoundError('Categories not found');
|
|
3553
3569
|
return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
3554
|
-
var
|
|
3555
|
-
return __generator(this, function (
|
|
3556
|
-
switch (
|
|
3570
|
+
var _c;
|
|
3571
|
+
return __generator(this, function (_d) {
|
|
3572
|
+
switch (_d.label) {
|
|
3557
3573
|
case 0:
|
|
3558
|
-
|
|
3574
|
+
_c = {
|
|
3559
3575
|
category: category
|
|
3560
3576
|
};
|
|
3561
3577
|
return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
|
|
3562
|
-
case 1: return [2 /*return*/, (
|
|
3563
|
-
|
|
3578
|
+
case 1: return [2 /*return*/, (_c.products = _d.sent(),
|
|
3579
|
+
_c)];
|
|
3564
3580
|
}
|
|
3565
3581
|
});
|
|
3566
3582
|
}); }))];
|
|
3567
3583
|
case 2:
|
|
3568
|
-
homeSections =
|
|
3584
|
+
homeSections = _d.sent();
|
|
3569
3585
|
return [2 /*return*/, homeSections];
|
|
3570
3586
|
}
|
|
3571
3587
|
});
|
|
@@ -3574,17 +3590,17 @@
|
|
|
3574
3590
|
CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
|
|
3575
3591
|
return __awaiter(this, void 0, void 0, function () {
|
|
3576
3592
|
var products, publishedField, productsData;
|
|
3577
|
-
var
|
|
3578
|
-
return __generator(this, function (
|
|
3579
|
-
switch (
|
|
3593
|
+
var _c;
|
|
3594
|
+
return __generator(this, function (_d) {
|
|
3595
|
+
switch (_d.label) {
|
|
3580
3596
|
case 0:
|
|
3581
3597
|
if (!category.products)
|
|
3582
3598
|
throw new RequiredArgumentError(['Category products is empty']);
|
|
3583
3599
|
products = [];
|
|
3584
3600
|
publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
|
|
3585
|
-
return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign((
|
|
3601
|
+
return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign((_c = { id: { operator: exports.Where.IN, value: category.products } }, _c[publishedField] = true, _c), ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
|
|
3586
3602
|
case 1:
|
|
3587
|
-
productsData = (
|
|
3603
|
+
productsData = (_d.sent()).data;
|
|
3588
3604
|
products.push.apply(products, __spreadArray([], __read(productsData)));
|
|
3589
3605
|
return [2 /*return*/, products];
|
|
3590
3606
|
}
|
|
@@ -3617,8 +3633,8 @@
|
|
|
3617
3633
|
},
|
|
3618
3634
|
},
|
|
3619
3635
|
{ hasVariants: { columnName: 'has_variants' } },
|
|
3620
|
-
{ images: { columnName: 'images', to: function (value) { return "{\"" + value.join("\",\"") + "\"}"; } } },
|
|
3621
|
-
{ miniatures: { columnName: 'miniatures', to: function (value) { return "{\"" + value.join("\",\"") + "\"}"; } } },
|
|
3636
|
+
{ images: { columnName: 'images', to: function (value) { var _a; return "{\"" + (((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, "\",\"")) || '') + "\"}"; } } },
|
|
3637
|
+
{ miniatures: { columnName: 'miniatures', to: function (value) { var _a; return "{\"" + (((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, "\",\"")) || '') + "\"}"; } } },
|
|
3622
3638
|
'name',
|
|
3623
3639
|
{
|
|
3624
3640
|
price: {
|
|
@@ -3634,15 +3650,17 @@
|
|
|
3634
3650
|
}, {}); },
|
|
3635
3651
|
bindFindFilter: function (sentence) {
|
|
3636
3652
|
var filters = Object.values(sentence).shift();
|
|
3637
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, ((filters === null || filters === void 0 ? void 0 : filters.price) && { price: filters.price })), (filters.fullPrice && { full_price: filters.fullPrice })), (filters.subscriberDiscountPercentage && {
|
|
3653
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, (((filters === null || filters === void 0 ? void 0 : filters.price) || (filters === null || filters === void 0 ? void 0 : filters.price) === 0) && { price: filters.price })), ((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice })), ((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
3638
3654
|
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
3639
|
-
})), (filters.subscriberPrice
|
|
3655
|
+
})), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
3656
|
+
subscriber_price: filters.subscriberPrice,
|
|
3657
|
+
}));
|
|
3640
3658
|
},
|
|
3641
3659
|
bindPersistData: function (value) {
|
|
3642
3660
|
var priceData = Object.values(value).shift();
|
|
3643
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) && { price: priceData.price })), (priceData.fullPrice && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage && {
|
|
3661
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) >= 0 && { price: priceData.price })), (priceData.fullPrice >= 0 && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage >= 0 && {
|
|
3644
3662
|
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
3645
|
-
})), (priceData.subscriberPrice && { subscriber_price: priceData.subscriberPrice }));
|
|
3663
|
+
})), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }));
|
|
3646
3664
|
},
|
|
3647
3665
|
},
|
|
3648
3666
|
},
|
|
@@ -3844,7 +3862,7 @@
|
|
|
3844
3862
|
type: '[product_kit_insert_input!]',
|
|
3845
3863
|
required: true,
|
|
3846
3864
|
value: plainData.kitProducts.map(function (kitProduct) { return ({
|
|
3847
|
-
kit_product_id: kitProduct.
|
|
3865
|
+
kit_product_id: kitProduct.productId || kitProduct.product.id,
|
|
3848
3866
|
product_id: productId,
|
|
3849
3867
|
quantity: kitProduct.quantity,
|
|
3850
3868
|
}); }),
|