@websolutespa/bom-core 3.0.2 → 3.0.4

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,18 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 3.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixing: qsDeserializeKeys
8
+
9
+ ## 3.0.3
10
+
11
+ ### Patch Changes
12
+
13
+ - Modified: IRoutes schema
14
+ - Fixing: qsDeserialize
15
+
3
16
  ## 3.0.2
4
17
 
5
18
  ### 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,8 +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));
1445
- return keys;
1444
+ return key.replace(/[\]]/g, "").split("[").map((value) => qsDeserializeKey(value)).filter((value) => value !== "");
1446
1445
  }
1447
1446
  function getNextKeyItem(key) {
1448
1447
  if (typeof key === "number") {
@@ -1540,8 +1539,37 @@ function collectRoutes(store, categories, markets, locales, medias) {
1540
1539
  const routes = [];
1541
1540
  if (locales.length > 0 && markets.length > 0) {
1542
1541
  const rootCategory = getRootCategory(categories);
1542
+ const activeLocales = locales.filter((locale) => locale.isActive !== false);
1543
+ const activeMarkets = markets.filter((market) => market.isActive !== false);
1544
+ const categoryById = new Map(categories.filter((category) => typeof category.id === "string").map((category) => [category.id, category]));
1545
+ const localeById = new Map(activeLocales.filter((locale) => typeof locale.id === "string").map((locale) => [locale.id, locale]));
1546
+ const mediaById = new Map((medias || []).filter((media) => typeof media.id === "string").map((media) => [media.id, media]));
1547
+ const marketLocales = activeMarkets.flatMap((market) => {
1548
+ const localesForMarket = market.languages && market.languages.length > 0 ? market.languages.map((language) => localeById.get(String(asEntityId(language)))).filter((locale) => locale !== void 0) : activeLocales;
1549
+ return localesForMarket.map((locale) => ({ market, locale }));
1550
+ });
1551
+ const getSegments = (item) => {
1552
+ const routeCategories = [];
1553
+ const segments = [];
1554
+ let parentId = asCategoryId(item.category);
1555
+ while (parentId != null) {
1556
+ const parentCategory = categoryById.get(parentId);
1557
+ if (parentCategory) {
1558
+ segments.unshift({ ...parentCategory });
1559
+ routeCategories.push(parentId);
1560
+ parentId = asCategoryId(parentCategory.category);
1561
+ if (parentId && routeCategories.includes(parentId)) {
1562
+ console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
1563
+ parentId = void 0;
1564
+ }
1565
+ } else {
1566
+ parentId = void 0;
1567
+ }
1568
+ }
1569
+ return segments;
1570
+ };
1543
1571
  eachCategorized(store, (item, key) => {
1544
- const segments = getCategorySegments(categories, item);
1572
+ const segments = getSegments(item);
1545
1573
  const visibleSegments = segments.filter((x) => x.id !== rootCategory?.id && Boolean(x.isHidden) === false);
1546
1574
  const visibleCategory = visibleSegments.length > 0 ? visibleSegments[visibleSegments.length - 1] : rootCategory;
1547
1575
  if (visibleCategory) {
@@ -1550,10 +1578,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
1550
1578
  slugs.push({ slug: item.slug });
1551
1579
  }
1552
1580
  const isRootCategory = rootCategory && item.category === rootCategory.id && item.isDefault;
1553
- eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
1581
+ marketLocales.forEach(({ market, locale }) => {
1554
1582
  if (hasMarket(item, market)) {
1555
1583
  const title = localize(item.title, locale.id);
1556
- const id = getRouteHref(slugs, market, locale, markets2, locales2);
1584
+ const id = getRouteHref(slugs, market, locale, activeMarkets, activeLocales);
1557
1585
  const {
1558
1586
  _status,
1559
1587
  category,
@@ -1567,11 +1595,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
1567
1595
  const route = {
1568
1596
  _status,
1569
1597
  category,
1570
- // id: isDefaultRootCategory ? '/' : id,
1571
1598
  id,
1572
1599
  locale: locale.id,
1573
1600
  market: market.id,
1574
- media,
1601
+ media: routeMedia(media),
1575
1602
  page: item.id,
1576
1603
  resolvedCategory: visibleCategory.id,
1577
1604
  schema: key,
@@ -1596,10 +1623,10 @@ function collectRoutes(store, categories, markets, locales, medias) {
1596
1623
  route.useSplat = true;
1597
1624
  }
1598
1625
  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);
1626
+ if (mediaId) {
1627
+ const media2 = mediaById.get(mediaId);
1601
1628
  if (media2) {
1602
- route.media = media2;
1629
+ route.media = routeMedia(media2);
1603
1630
  }
1604
1631
  }
1605
1632
  routes.push(route);
@@ -1610,6 +1637,18 @@ function collectRoutes(store, categories, markets, locales, medias) {
1610
1637
  }
1611
1638
  return routes;
1612
1639
  }
1640
+ function routeMedia(media) {
1641
+ const url = media?.url || media?.src;
1642
+ return media && url ? {
1643
+ // createdAt: media.createdAt,
1644
+ updatedAt: media.updatedAt,
1645
+ // filename: media.filename,
1646
+ // mimeType: media.mimeType,
1647
+ // id: media.id,
1648
+ url,
1649
+ type: media.type
1650
+ } : void 0;
1651
+ }
1613
1652
  function eachMarketLocale(markets, locales, callback) {
1614
1653
  locales = locales.filter((x) => x.isActive !== false);
1615
1654
  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.4",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",