@websolutespa/bom-core 3.0.2 → 3.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 3.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: IRoutes schema
8
+ - Fixing: qsDeserialize
9
+
3
10
  ## 3.0.2
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -383,19 +383,25 @@ type IMarket = IEntity & {
383
383
  type IRoute = {
384
384
  category: IEquatable;
385
385
  id: string;
386
- isDefault?: boolean;
387
- isRoot?: boolean;
388
386
  locale: string;
389
387
  market: string;
390
- media?: IMedia;
391
- noindex?: boolean;
392
- order?: number;
393
388
  page: IEquatable;
394
389
  resolvedCategory: IEquatable;
395
390
  schema: string;
396
- template?: string;
397
391
  title: string;
398
- updatedAt?: Date;
392
+ _status?: 'published' | 'draft';
393
+ isDefault?: boolean;
394
+ isRoot?: boolean;
395
+ media?: {
396
+ url: string;
397
+ src?: string;
398
+ type: string;
399
+ updatedAt?: Date | string;
400
+ };
401
+ noindex?: boolean;
402
+ order?: number;
403
+ template?: string;
404
+ updatedAt?: Date | string;
399
405
  useSplat?: boolean;
400
406
  };
401
407
  type IRouteCanonical = IRoute & {
package/dist/index.js CHANGED
@@ -1441,7 +1441,7 @@ function qsDeserializeKey(value) {
1441
1441
  return value;
1442
1442
  }
1443
1443
  function qsDeserializeKeys(key) {
1444
- const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x));
1444
+ const keys = key.replace(/[\]]/g, "").split("[").map((x) => qsDeserializeKey(x)).filter((x) => Boolean(x));
1445
1445
  return keys;
1446
1446
  }
1447
1447
  function getNextKeyItem(key) {
@@ -1540,8 +1540,37 @@ function collectRoutes(store, categories, markets, locales, medias) {
1540
1540
  const routes = [];
1541
1541
  if (locales.length > 0 && markets.length > 0) {
1542
1542
  const rootCategory = getRootCategory(categories);
1543
+ const activeLocales = locales.filter((locale) => locale.isActive !== false);
1544
+ const activeMarkets = markets.filter((market) => market.isActive !== false);
1545
+ const categoryById = new Map(categories.filter((category) => typeof category.id === "string").map((category) => [category.id, category]));
1546
+ const localeById = new Map(activeLocales.filter((locale) => typeof locale.id === "string").map((locale) => [locale.id, locale]));
1547
+ const mediaById = new Map((medias || []).filter((media) => typeof media.id === "string").map((media) => [media.id, media]));
1548
+ const marketLocales = activeMarkets.flatMap((market) => {
1549
+ const localesForMarket = market.languages && market.languages.length > 0 ? market.languages.map((language) => localeById.get(String(asEntityId(language)))).filter((locale) => locale !== void 0) : activeLocales;
1550
+ return localesForMarket.map((locale) => ({ market, locale }));
1551
+ });
1552
+ const getSegments = (item) => {
1553
+ const routeCategories = [];
1554
+ const segments = [];
1555
+ let parentId = asCategoryId(item.category);
1556
+ while (parentId != null) {
1557
+ const parentCategory = categoryById.get(parentId);
1558
+ if (parentCategory) {
1559
+ segments.unshift({ ...parentCategory });
1560
+ routeCategories.push(parentId);
1561
+ parentId = asCategoryId(parentCategory.category);
1562
+ if (parentId && routeCategories.includes(parentId)) {
1563
+ console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
1564
+ parentId = void 0;
1565
+ }
1566
+ } else {
1567
+ parentId = void 0;
1568
+ }
1569
+ }
1570
+ return segments;
1571
+ };
1543
1572
  eachCategorized(store, (item, key) => {
1544
- const segments = getCategorySegments(categories, item);
1573
+ const segments = getSegments(item);
1545
1574
  const visibleSegments = segments.filter((x) => x.id !== rootCategory?.id && Boolean(x.isHidden) === false);
1546
1575
  const visibleCategory = visibleSegments.length > 0 ? visibleSegments[visibleSegments.length - 1] : rootCategory;
1547
1576
  if (visibleCategory) {
@@ -1550,10 +1579,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
1550
1579
  slugs.push({ slug: item.slug });
1551
1580
  }
1552
1581
  const isRootCategory = rootCategory && item.category === rootCategory.id && item.isDefault;
1553
- eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
1582
+ marketLocales.forEach(({ market, locale }) => {
1554
1583
  if (hasMarket(item, market)) {
1555
1584
  const title = localize(item.title, locale.id);
1556
- const id = getRouteHref(slugs, market, locale, markets2, locales2);
1585
+ const id = getRouteHref(slugs, market, locale, activeMarkets, activeLocales);
1557
1586
  const {
1558
1587
  _status,
1559
1588
  category,
@@ -1567,11 +1596,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
1567
1596
  const route = {
1568
1597
  _status,
1569
1598
  category,
1570
- // id: isDefaultRootCategory ? '/' : id,
1571
1599
  id,
1572
1600
  locale: locale.id,
1573
1601
  market: market.id,
1574
- media,
1602
+ media: routeMedia(media),
1575
1603
  page: item.id,
1576
1604
  resolvedCategory: visibleCategory.id,
1577
1605
  schema: key,
@@ -1596,10 +1624,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
1596
1624
  route.useSplat = true;
1597
1625
  }
1598
1626
  const mediaId = typeof item.media === "string" ? item.media : void 0;
1599
- if (Array.isArray(medias) && mediaId) {
1600
- const media2 = item.media && medias.find((x) => x.id === mediaId);
1627
+ if (mediaId) {
1628
+ const media2 = mediaById.get(mediaId);
1601
1629
  if (media2) {
1602
- route.media = media2;
1630
+ route.media = routeMedia(media2);
1603
1631
  }
1604
1632
  }
1605
1633
  routes.push(route);
@@ -1610,6 +1638,18 @@ function collectRoutes(store, categories, markets, locales, medias) {
1610
1638
  }
1611
1639
  return routes;
1612
1640
  }
1641
+ function routeMedia(media) {
1642
+ const url = media?.url || media?.src;
1643
+ return media && url ? {
1644
+ // createdAt: media.createdAt,
1645
+ updatedAt: media.updatedAt,
1646
+ // filename: media.filename,
1647
+ // mimeType: media.mimeType,
1648
+ // id: media.id,
1649
+ url,
1650
+ type: media.type
1651
+ } : void 0;
1652
+ }
1613
1653
  function eachMarketLocale(markets, locales, callback) {
1614
1654
  locales = locales.filter((x) => x.isActive !== false);
1615
1655
  markets = markets.filter((x) => x.isActive !== false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",