pinelab-storefront-client
Advanced tools
Comparing version 0.42.1 to 0.42.2
@@ -23,2 +23,12 @@ import { | ||
getAvailableCountries(): Promise<Country[]>; | ||
/** | ||
* By default the collection graphql query returns all child and parent collections in one flat array. | ||
* This function sets the correct childCollections for each topLevel collection. | ||
* @param allCollections | ||
*/ | ||
unflatten(allCollections: Collection[]): Collection[]; | ||
/** | ||
* Recursively gets childCollections for given collection | ||
*/ | ||
private getChildCollection; | ||
} |
@@ -285,4 +285,65 @@ 'use strict'; | ||
}; | ||
/** | ||
* By default the collection graphql query returns all child and parent collections in one flat array. | ||
* This function sets the correct childCollections for each topLevel collection. | ||
* @param allCollections | ||
*/ | ||
GridsomeService.prototype.unflatten = function (allCollections) { | ||
var _this = this; | ||
// Get toplevel collections | ||
var collections = allCollections.filter(function (col) { | ||
var _a; | ||
return ( | ||
((_a = col.parent) === null || _a === void 0 ? void 0 : _a.name) === | ||
'__root_collection__' | ||
); | ||
}); | ||
// Find and set child collections, because queried children only have id and name fields | ||
return collections.map(function (collection) { | ||
return _this.getChildCollection(collection, allCollections); | ||
}); | ||
}; | ||
/** | ||
* Recursively gets childCollections for given collection | ||
*/ | ||
GridsomeService.prototype.getChildCollection = function ( | ||
collection, | ||
allCollections | ||
) { | ||
var _this = this; | ||
var _a; | ||
var fullChildren = | ||
(_a = collection.children) === null || _a === void 0 | ||
? void 0 | ||
: _a.map(function (originalChild) { | ||
var _a; | ||
var fullChildCollection = allCollections.find(function (c) { | ||
return c.id === originalChild.id; | ||
}); | ||
if (!fullChildCollection) { | ||
throw Error( | ||
'Child collection ' + | ||
originalChild.name + | ||
' is not in allCollections list' | ||
); | ||
} | ||
if ( | ||
(_a = | ||
fullChildCollection === null || fullChildCollection === void 0 | ||
? void 0 | ||
: fullChildCollection.children) === null || _a === void 0 | ||
? void 0 | ||
: _a.length | ||
) { | ||
fullChildCollection = _this.getChildCollection( | ||
fullChildCollection, | ||
allCollections | ||
); | ||
} | ||
return fullChildCollection; | ||
}); | ||
return __assign(__assign({}, collection), { children: fullChildren }); | ||
}; | ||
return GridsomeService; | ||
})(); | ||
exports.GridsomeService = GridsomeService; |
{ | ||
"name": "pinelab-storefront-client", | ||
"version": "0.42.1", | ||
"version": "0.42.2", | ||
"description": "Generates static html pages with Gridsome and suplied Vue components", | ||
@@ -46,3 +46,3 @@ "author": "Martijn van de Brug <martijn@pinelab.studio>", | ||
}, | ||
"gitHead": "f5ba163547842343d6e276db41b1622e66955f7c" | ||
"gitHead": "eb67ccdb7059214f9e2a59658486667291094b80" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
483896
3618