@websolutespa/bom-mixer-store 1.7.7 → 1.7.8

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,13 @@
1
1
  # @websolutespa/bom-mixer-store
2
2
 
3
+ ## 1.7.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: RouteService, MenuService to handle isHidden Category segments
8
+ - Updated dependencies
9
+ - @websolutespa/bom-core@1.7.12
10
+
3
11
  ## 1.7.7
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -184,6 +184,7 @@ async function fromCache(callback, key) {
184
184
  }
185
185
 
186
186
  // src/decorators/category.ts
187
+ var import_bom_core = require("@websolutespa/bom-core");
187
188
  async function decorateCategory_(store, item, params = {}) {
188
189
  if (typeof item.category === "string") {
189
190
  const categories = await store.category.findMany({
@@ -196,9 +197,7 @@ async function decorateCategory_(store, item, params = {}) {
196
197
  if (categories.length > 0) {
197
198
  const category = categories[0];
198
199
  const routes = await store.route.findMany();
199
- const route = routes.find(
200
- (x) => x.market === params.market && x.locale === params.locale && x.isDefault && x.category === category.id
201
- );
200
+ const route = (0, import_bom_core.findRouteOfCategory)(routes, category.id, params.market, params.locale);
202
201
  if (route) {
203
202
  category.href = route.id;
204
203
  }
@@ -216,7 +215,7 @@ async function decorateCategories_(store, items, params = {}) {
216
215
  return items.map((item) => {
217
216
  const category = categories.find((x) => x.id === item.category);
218
217
  if (category) {
219
- const route = routes.find((x) => x.isDefault && x.category === category.id);
218
+ const route = (0, import_bom_core.findRouteOfCategory)(routes, category.id);
220
219
  if (route) {
221
220
  category.href = route.id;
222
221
  }
@@ -278,25 +277,25 @@ async function decorateHrefs_(store, items, params = {}) {
278
277
  }
279
278
 
280
279
  // src/decorators/localizable.ts
281
- var import_bom_core = require("@websolutespa/bom-core");
280
+ var import_bom_core2 = require("@websolutespa/bom-core");
282
281
  async function decorateLocalizable_(item, params = {}) {
283
282
  if (params.locale) {
284
- return (0, import_bom_core.localizeItem)(item, params.locale);
283
+ return (0, import_bom_core2.localizeItem)(item, params.locale);
285
284
  } else {
286
- return (0, import_bom_core.cloneItem)(item);
285
+ return (0, import_bom_core2.cloneItem)(item);
287
286
  }
288
287
  }
289
288
  async function decorateLocalizables_(items, params = {}) {
290
289
  const decoratedItems = [];
291
290
  for (const item of items) {
292
- const decoratedItem = params.locale ? (0, import_bom_core.localizeItem)(item, params.locale) : (0, import_bom_core.cloneItem)(item);
291
+ const decoratedItem = params.locale ? (0, import_bom_core2.localizeItem)(item, params.locale) : (0, import_bom_core2.cloneItem)(item);
293
292
  decoratedItems.push(decoratedItem);
294
293
  }
295
294
  return decoratedItems;
296
295
  }
297
296
 
298
297
  // src/decorators/menu.ts
299
- var import_bom_core2 = require("@websolutespa/bom-core");
298
+ var import_bom_core3 = require("@websolutespa/bom-core");
300
299
  async function decorateMenu_(store, item, params) {
301
300
  const { market, locale } = params;
302
301
  const items = itemsFilteredByMarket_(item.items || [], market);
@@ -350,7 +349,7 @@ function itemHasMarket_(item, market) {
350
349
  }
351
350
  function collectUndecoratedCategories(items, undecoratedCategories = []) {
352
351
  items.forEach((item) => {
353
- if ((0, import_bom_core2.isUndecoratedMenuCategory)(item)) {
352
+ if ((0, import_bom_core3.isUndecoratedMenuCategory)(item)) {
354
353
  undecoratedCategories.push(item);
355
354
  }
356
355
  if (item.items) {
@@ -361,7 +360,7 @@ function collectUndecoratedCategories(items, undecoratedCategories = []) {
361
360
  }
362
361
  function collectUndecoratedPages(items, undecoratedPages = []) {
363
362
  items.forEach((item) => {
364
- if ((0, import_bom_core2.isUndecoratedMenuPage)(item)) {
363
+ if ((0, import_bom_core3.isUndecoratedMenuPage)(item)) {
365
364
  undecoratedPages.push(item);
366
365
  }
367
366
  if (item.items) {
@@ -377,17 +376,17 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
377
376
  category: "",
378
377
  customClass: item.customClass,
379
378
  href: "",
380
- id: item.id || "",
379
+ id: item.id || (0, import_bom_core3.uuidv4)(),
381
380
  items: [],
382
381
  title: "",
383
382
  type: item.type
384
383
  };
385
- const category = typeof item.category === "string" ? categories.find((x) => x.id === item.category) : item.category;
384
+ const category = (0, import_bom_core3.findCategoryInCategories)(categories, item.category);
386
385
  if (category) {
387
386
  decoratedItem.category = category.id;
388
387
  decoratedItem.title = item.title || category.title || "";
389
- decoratedItem.media = decoratedItem.media || category.media;
390
- const route = routes.find((x) => x.isDefault && x.category === category.id);
388
+ decoratedItem.media = item.media || category.media;
389
+ const route = (0, import_bom_core3.findRouteOfCategory)(routes, category.id);
391
390
  if (route) {
392
391
  decoratedItem.href = route.id;
393
392
  } else {
@@ -399,7 +398,7 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
399
398
  }
400
399
  maxDepth--;
401
400
  }
402
- const childCategories = categories.filter((x) => x.category && (typeof x.category === "object" ? x.category.id === category.id : x.category === category.id));
401
+ const childCategories = (0, import_bom_core3.findChildCategories)(categories, category.id).filter((x) => Boolean(x.isHidden) === false);
403
402
  if (childCategories.length) {
404
403
  childCategories.sort((a, b) => {
405
404
  return (a.order || MAX_INT) - (b.order || MAX_INT);
@@ -411,13 +410,15 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
411
410
  maxDepth,
412
411
  items: []
413
412
  }, categories, routes, market, depth + 1));
414
- } else {
415
- const childRoutes = routes.filter((x) => !x.isDefault && x.category === category.id);
416
- childRoutes.sort((a, b) => {
417
- return (a.order || MAX_INT) - (b.order || MAX_INT);
418
- });
419
- decoratedItem.items = childRoutes.map((x) => decorateMenuRoute_(x));
420
413
  }
414
+ const childRoutes = (0, import_bom_core3.findRoutesOfCategory)(routes, category.id, false);
415
+ childRoutes.sort((a, b) => {
416
+ return (a.order || MAX_INT) - (b.order || MAX_INT);
417
+ });
418
+ decoratedItem.items = [
419
+ ...decoratedItem.items || [],
420
+ ...childRoutes.map((x) => decorateMenuRoute_(x))
421
+ ];
421
422
  }
422
423
  return decoratedItem;
423
424
  }
@@ -435,13 +436,13 @@ function decorateMenuRoute_(item) {
435
436
  return decoratedItem;
436
437
  }
437
438
  async function decorateMenuPage_(item, routes, store, params = {}) {
438
- const id = (0, import_bom_core2.isEquatable)(item.page.value) ? item.page.value : item.page.value.id;
439
+ const id = (0, import_bom_core3.isEquatable)(item.page.value) ? item.page.value : item.page.value.id;
439
440
  const route = routes.find(
440
441
  (x) => x.schema === item.page.relationTo && x.page === id
441
442
  );
442
443
  const page = await store[item.page.relationTo].findOne(id, { ...params });
443
444
  const decoratedItem = {
444
- id: item.id || "",
445
+ id: item.id || (0, import_bom_core3.uuidv4)(),
445
446
  type: item.type,
446
447
  title: item.title || page?.title || "",
447
448
  abstract: item.abstract || page?.abstract || "",
@@ -456,7 +457,7 @@ async function decorateMenuPage_(item, routes, store, params = {}) {
456
457
  }
457
458
 
458
459
  // src/decorators/nav.ts
459
- var import_bom_core3 = require("@websolutespa/bom-core");
460
+ var import_bom_core4 = require("@websolutespa/bom-core");
460
461
  async function decorateNav_(store, item, params = {}, routes) {
461
462
  if (!routes) {
462
463
  routes = await store.route.findMany({
@@ -486,12 +487,12 @@ async function decorateNavs_(store, items, params = {}) {
486
487
  return items;
487
488
  }
488
489
  function collectNavs_(item, navs = []) {
489
- if ((0, import_bom_core3.isUndecoratedNav)(item)) {
490
+ if ((0, import_bom_core4.isUndecoratedNav)(item)) {
490
491
  navs.push(item);
491
492
  }
492
- if ((0, import_bom_core3.isArray)(item)) {
493
+ if ((0, import_bom_core4.isArray)(item)) {
493
494
  item.forEach((x) => collectNavs_(x, navs));
494
- } else if ((0, import_bom_core3.isObject)(item)) {
495
+ } else if ((0, import_bom_core4.isObject)(item)) {
495
496
  Object.values(item).forEach((value) => {
496
497
  collectNavs_(value, navs);
497
498
  });
@@ -521,7 +522,7 @@ function decorateNav__(item, routes) {
521
522
  }
522
523
 
523
524
  // src/decorators/optimize.ts
524
- var import_bom_core4 = require("@websolutespa/bom-core");
525
+ var import_bom_core5 = require("@websolutespa/bom-core");
525
526
  async function optimizeOne_(item) {
526
527
  const validEntries = Object.entries(item).filter(([key, value]) => {
527
528
  switch (key) {
@@ -529,7 +530,7 @@ async function optimizeOne_(item) {
529
530
  case "meta":
530
531
  return false;
531
532
  default:
532
- if ((0, import_bom_core4.isUnresolvedRelation)(value) || Array.isArray(value) && value.reduce((p, c) => p && (0, import_bom_core4.isUnresolvedRelation)(c), true)) {
533
+ if ((0, import_bom_core5.isUnresolvedRelation)(value) || Array.isArray(value) && value.reduce((p, c) => p && (0, import_bom_core5.isUnresolvedRelation)(c), true)) {
533
534
  return false;
534
535
  }
535
536
  }
@@ -547,7 +548,7 @@ async function optimizeMany_(items) {
547
548
  }
548
549
 
549
550
  // src/decorators/relation.ts
550
- var import_bom_core5 = require("@websolutespa/bom-core");
551
+ var import_bom_core6 = require("@websolutespa/bom-core");
551
552
  var SERVICE_DEFAULT_DEPTH = 3;
552
553
  async function decorateRelation_(store, item, params = {}) {
553
554
  const depth = params.depth != null ? params.depth : SERVICE_DEFAULT_DEPTH;
@@ -564,7 +565,7 @@ async function decorateRelations_(store, items, params = {}) {
564
565
  return items;
565
566
  }
566
567
  async function collectRelations_(context, item, relations = []) {
567
- if ((0, import_bom_core5.isUnresolvedRelation)(item)) {
568
+ if ((0, import_bom_core6.isUnresolvedRelation)(item)) {
568
569
  const index = relations.findIndex(
569
570
  (x) => x.relationTo === item.relationTo && x.value === item.value
570
571
  );
@@ -593,13 +594,13 @@ async function collectRelations_(context, item, relations = []) {
593
594
  } else {
594
595
  return relations[index].resolvedValue;
595
596
  }
596
- } else if ((0, import_bom_core5.isArray)(item)) {
597
+ } else if ((0, import_bom_core6.isArray)(item)) {
597
598
  const items = [];
598
599
  for (let i = 0; i < item.length; i++) {
599
600
  items[i] = await collectRelations_(context, item[i], relations);
600
601
  }
601
602
  return items;
602
- } else if ((0, import_bom_core5.isObject)(item)) {
603
+ } else if ((0, import_bom_core6.isObject)(item)) {
603
604
  for (const [key, value] of Object.entries(item)) {
604
605
  item[key] = await collectRelations_(context, value, relations);
605
606
  }
@@ -618,12 +619,12 @@ async function decorateSchemas_(store, items, schema) {
618
619
  }
619
620
 
620
621
  // src/local/local.api.ts
621
- var import_bom_core6 = require("@websolutespa/bom-core");
622
+ var import_bom_core7 = require("@websolutespa/bom-core");
622
623
  var API_URL = process.env.NEXT_PUBLIC_URL === "https://" ? process.env.NEXT_PUBLIC_MOCK_FALLBACK_URL : process.env.NEXT_PUBLIC_URL;
623
624
  var API_BASE = process.env.NEXT_PUBLIC_API || "/api";
624
625
  function getLocalApiUrl(pathname) {
625
- let url = `${import_bom_core6.isBrowser ? window.location.origin : API_URL}${API_BASE}${pathname}`;
626
- url = import_bom_core6.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
626
+ let url = `${import_bom_core7.isBrowser ? window.location.origin : API_URL}${API_BASE}${pathname}`;
627
+ url = import_bom_core7.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
627
628
  return url;
628
629
  }
629
630
  async function localApiFetch(pathname, options = {}, serviceOptions) {
@@ -632,9 +633,9 @@ async function localApiFetch(pathname, options = {}, serviceOptions) {
632
633
  url.searchParams.append("locale", serviceOptions.locale);
633
634
  url.searchParams.append("market", serviceOptions.market);
634
635
  }
635
- const apiOptions = (0, import_bom_core6.merge)({ ...getLocalApiRequestOptions() }, options);
636
+ const apiOptions = (0, import_bom_core7.merge)({ ...getLocalApiRequestOptions() }, options);
636
637
  console.log("localApiFetch", apiOptions.method, url.href);
637
- const apiResponse = await (0, import_bom_core6.httpFetch)(url.href, apiOptions);
638
+ const apiResponse = await (0, import_bom_core7.httpFetch)(url.href, apiOptions);
638
639
  return apiResponse;
639
640
  }
640
641
  async function localApiGet(url, options = {}, serviceOptions) {
@@ -673,8 +674,8 @@ function isApiRequest(request) {
673
674
  }
674
675
 
675
676
  // src/mock/mock.service.ts
676
- var import_bom_core7 = require("@websolutespa/bom-core");
677
- var MockService = class extends import_bom_core7.JsonService {
677
+ var import_bom_core8 = require("@websolutespa/bom-core");
678
+ var MockService = class extends import_bom_core8.JsonService {
678
679
  constructor(items, store) {
679
680
  super(items);
680
681
  this.store = store;
@@ -759,19 +760,19 @@ var MockPageService = class extends MockService {
759
760
  };
760
761
 
761
762
  // src/mock/mock.api.ts
762
- var import_bom_core8 = require("@websolutespa/bom-core");
763
+ var import_bom_core9 = require("@websolutespa/bom-core");
763
764
  var API_URL2 = process.env.NEXT_PUBLIC_URL;
764
765
  var API_BASE3 = process.env.NEXT_PUBLIC_API || "/api";
765
766
  function getMockApiUrl(pathname) {
766
767
  let url = `${API_URL2}${API_BASE3}/_mock${pathname}`;
767
- url = import_bom_core8.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
768
+ url = import_bom_core9.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
768
769
  return url;
769
770
  }
770
771
  async function mockApiFetch(pathname, options = {}) {
771
772
  const url = getMockApiUrl(pathname);
772
- const apiOptions = (0, import_bom_core8.merge)({ ...getLocalApiRequestOptions() }, options);
773
+ const apiOptions = (0, import_bom_core9.merge)({ ...getLocalApiRequestOptions() }, options);
773
774
  console.log("mockApiFetch", apiOptions.method, url);
774
- const apiResponse = await (0, import_bom_core8.httpFetch)(url, apiOptions);
775
+ const apiResponse = await (0, import_bom_core9.httpFetch)(url, apiOptions);
775
776
  return apiResponse;
776
777
  }
777
778
  async function mockApiGet(url, options = {}) {
@@ -791,7 +792,7 @@ async function mockApiDelete(url, options = {}) {
791
792
  }
792
793
 
793
794
  // src/store/store.handler.ts
794
- var import_bom_core14 = require("@websolutespa/bom-core");
795
+ var import_bom_core15 = require("@websolutespa/bom-core");
795
796
 
796
797
  // src/static/static.ts
797
798
  var staticCollections = [{
@@ -1066,7 +1067,7 @@ var KNOWN_COLLECTIONS = [
1066
1067
  var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
1067
1068
 
1068
1069
  // src/mock/mock.store.ts
1069
- var import_bom_core10 = require("@websolutespa/bom-core");
1070
+ var import_bom_core11 = require("@websolutespa/bom-core");
1070
1071
 
1071
1072
  // src/fs/fs.service.ts
1072
1073
  var fs = __toESM(require("fs"));
@@ -1094,8 +1095,8 @@ async function fsReadJson(pathname) {
1094
1095
  }
1095
1096
 
1096
1097
  // src/static/static.service.ts
1097
- var import_bom_core9 = require("@websolutespa/bom-core");
1098
- var StaticService = class extends import_bom_core9.JsonService {
1098
+ var import_bom_core10 = require("@websolutespa/bom-core");
1099
+ var StaticService = class extends import_bom_core10.JsonService {
1099
1100
  constructor(config, store) {
1100
1101
  super([]);
1101
1102
  this.loaded = false;
@@ -1123,7 +1124,7 @@ var StaticService = class extends import_bom_core9.JsonService {
1123
1124
  const config = this.config;
1124
1125
  const src = config.src;
1125
1126
  if (typeof src === "string") {
1126
- const response = await (0, import_bom_core9.httpGet)(src, {});
1127
+ const response = await (0, import_bom_core10.httpGet)(src, {});
1127
1128
  items = response.items;
1128
1129
  } else if (typeof src === "function") {
1129
1130
  if (src instanceof Promise) {
@@ -1239,7 +1240,7 @@ function getMockStoreFromData_(data) {
1239
1240
  return store;
1240
1241
  }
1241
1242
  async function getStoreData_() {
1242
- if (import_bom_core10.isDevelopment) {
1243
+ if (import_bom_core11.isDevelopment) {
1243
1244
  const path = require("path");
1244
1245
  const pathname = path.join(process.cwd(), ".mixer", "store.json");
1245
1246
  return await fsReadJson(pathname) || {};
@@ -1255,17 +1256,17 @@ async function getMockStore_() {
1255
1256
  }
1256
1257
  async function getMockStore() {
1257
1258
  return fromCache(async () => {
1258
- if (!import_bom_core10.isDevelopment) {
1259
+ if (!import_bom_core11.isDevelopment) {
1259
1260
  console.warn("getMockStore");
1260
1261
  }
1261
1262
  const store = await getMockStore_();
1262
1263
  return store;
1263
- }, import_bom_core10.isDevelopment ? void 0 : "STORE_MOCK_");
1264
+ }, import_bom_core11.isDevelopment ? void 0 : "STORE_MOCK_");
1264
1265
  }
1265
1266
 
1266
1267
  // src/cached/cached.service.ts
1267
- var import_bom_core11 = require("@websolutespa/bom-core");
1268
- var CachedService = class extends import_bom_core11.JsonService {
1268
+ var import_bom_core12 = require("@websolutespa/bom-core");
1269
+ var CachedService = class extends import_bom_core12.JsonService {
1269
1270
  constructor(service, options = {}) {
1270
1271
  super([]);
1271
1272
  this.cache_ = /* @__PURE__ */ new Map();
@@ -1304,7 +1305,7 @@ var CachedService = class extends import_bom_core11.JsonService {
1304
1305
  });
1305
1306
  }
1306
1307
  async findOne(id, params = {}) {
1307
- const serializedParams = (0, import_bom_core11.qsSerialize)(params);
1308
+ const serializedParams = (0, import_bom_core12.qsSerialize)(params);
1308
1309
  const key = `findOne[${id}]?${serializedParams}`;
1309
1310
  return await this.fromCache_(async () => {
1310
1311
  return await this.service_.findOne(id, params);
@@ -1313,7 +1314,7 @@ var CachedService = class extends import_bom_core11.JsonService {
1313
1314
  async findMany(params = {}) {
1314
1315
  if (storeStrategy === "decoratedApi" /* DecoratedApi */) {
1315
1316
  const { market, locale, ...otherParams } = params;
1316
- const serializedParams = (0, import_bom_core11.qsSerialize)({ market, locale });
1317
+ const serializedParams = (0, import_bom_core12.qsSerialize)({ market, locale });
1317
1318
  const key = `findMany?${serializedParams}`;
1318
1319
  let items = await this.fromCache_(async () => {
1319
1320
  return await this.service_.findMany({ market, locale });
@@ -1326,7 +1327,7 @@ var CachedService = class extends import_bom_core11.JsonService {
1326
1327
  }
1327
1328
  return items;
1328
1329
  } else {
1329
- const serializedParams = (0, import_bom_core11.qsSerialize)(params);
1330
+ const serializedParams = (0, import_bom_core12.qsSerialize)(params);
1330
1331
  const key = `findMany?${serializedParams}`;
1331
1332
  return await this.fromCache_(async () => {
1332
1333
  return await this.service_.findMany(params);
@@ -1334,7 +1335,7 @@ var CachedService = class extends import_bom_core11.JsonService {
1334
1335
  }
1335
1336
  }
1336
1337
  async findPaged(params = {}) {
1337
- const serializedParams = (0, import_bom_core11.qsSerialize)(params);
1338
+ const serializedParams = (0, import_bom_core12.qsSerialize)(params);
1338
1339
  const key = `findPaged?${serializedParams}`;
1339
1340
  return await this.fromCache_(async () => {
1340
1341
  return await this.service_.findPaged(params);
@@ -1352,22 +1353,22 @@ var CachedService = class extends import_bom_core11.JsonService {
1352
1353
  };
1353
1354
 
1354
1355
  // src/remote/remote.service.ts
1355
- var import_bom_core13 = require("@websolutespa/bom-core");
1356
+ var import_bom_core14 = require("@websolutespa/bom-core");
1356
1357
 
1357
1358
  // src/remote/remote.api.ts
1358
- var import_bom_core12 = require("@websolutespa/bom-core");
1359
+ var import_bom_core13 = require("@websolutespa/bom-core");
1359
1360
  var API_URL3 = process.env.STORE_URL;
1360
1361
  var API_BASE4 = process.env.STORE_API || "/api";
1361
1362
  function getRemoteApiUrl(pathname) {
1362
1363
  let url = `${API_URL3}${API_BASE4}${pathname}`;
1363
- url = import_bom_core12.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
1364
+ url = import_bom_core13.isBrowser ? url : url.replace("://localhost", "://127.0.0.1");
1364
1365
  return url;
1365
1366
  }
1366
1367
  async function remoteApiFetch(pathname, options = {}) {
1367
1368
  const url = getRemoteApiUrl(pathname);
1368
- const apiOptions = (0, import_bom_core12.merge)({ ...getRemoteApiRequestOptions() }, options);
1369
+ const apiOptions = (0, import_bom_core13.merge)({ ...getRemoteApiRequestOptions() }, options);
1369
1370
  console.log("remoteApiFetch", apiOptions.method, url);
1370
- const apiResponse = await (0, import_bom_core12.httpFetch)(url, apiOptions);
1371
+ const apiResponse = await (0, import_bom_core13.httpFetch)(url, apiOptions);
1371
1372
  return apiResponse;
1372
1373
  }
1373
1374
  async function remoteApiGet(url, options = {}) {
@@ -1404,7 +1405,7 @@ var RemoteService = class {
1404
1405
  async findOne(id, params = {}) {
1405
1406
  params.richText = String(params.richText) === "true" ? true : false;
1406
1407
  params.draft = RemoteServiceStrategy.draft;
1407
- const query = (0, import_bom_core13.qsSerialize)(params);
1408
+ const query = (0, import_bom_core14.qsSerialize)(params);
1408
1409
  const search = query ? `?${query}` : "";
1409
1410
  const url = `/${this.key}/${encodeURIComponent(id)}${search}`;
1410
1411
  const item = await remoteApiGet(url);
@@ -1417,7 +1418,7 @@ var RemoteService = class {
1417
1418
  params.richText = String(params.richText) === "true" ? true : false;
1418
1419
  params.draft = RemoteServiceStrategy.draft;
1419
1420
  params.pagination = false;
1420
- const query = (0, import_bom_core13.qsSerialize)(params);
1421
+ const query = (0, import_bom_core14.qsSerialize)(params);
1421
1422
  const search = query ? `?${query}` : "";
1422
1423
  const url = `/${this.key}${search}`;
1423
1424
  const response = await remoteApiGet(url);
@@ -1428,7 +1429,7 @@ var RemoteService = class {
1428
1429
  params.richText = String(params.richText) === "true" ? true : false;
1429
1430
  params.draft = RemoteServiceStrategy.draft;
1430
1431
  params.pagination = true;
1431
- const query = (0, import_bom_core13.qsSerialize)(params);
1432
+ const query = (0, import_bom_core14.qsSerialize)(params);
1432
1433
  const search = query ? `?${query}` : "";
1433
1434
  const url = `/${this.key}${search}`;
1434
1435
  const response = await remoteApiGet(url);
@@ -1457,7 +1458,7 @@ var RemoteService = class {
1457
1458
  }
1458
1459
  }
1459
1460
  };
1460
- const query = (0, import_bom_core13.qsSerialize)(params);
1461
+ const query = (0, import_bom_core14.qsSerialize)(params);
1461
1462
  const search = query ? `?${query}` : "";
1462
1463
  const url = `/${this.key}${search}`;
1463
1464
  const item = await remoteApiDelete(url);
@@ -1637,7 +1638,7 @@ function collectionGet(storePromise) {
1637
1638
  const collection = collections[0];
1638
1639
  const id = collections[1];
1639
1640
  const qs = Object.entries(query).map((kv) => kv.join("=")).join("&");
1640
- const params = (0, import_bom_core14.qsDeserialize)(qs);
1641
+ const params = (0, import_bom_core15.qsDeserialize)(qs);
1641
1642
  if (!COLLECTIONS.includes(collection)) {
1642
1643
  console.error("storeHandler.collectionGet", "method not allowed", collection);
1643
1644
  return response.status(405).send("method not allowed");
@@ -1649,7 +1650,7 @@ function collectionGet(storePromise) {
1649
1650
  return response.status(405).send("method not allowed");
1650
1651
  }
1651
1652
  if (id) {
1652
- const item = await service.findOne((0, import_bom_core14.asEquatable)(id), params);
1653
+ const item = await service.findOne((0, import_bom_core15.asEquatable)(id), params);
1653
1654
  if (item) {
1654
1655
  return response.status(200).json(item);
1655
1656
  } else {
@@ -1769,8 +1770,8 @@ function storeIndexHandler() {
1769
1770
  return apiHandler({
1770
1771
  get: async (request, response) => {
1771
1772
  try {
1772
- const market = import_bom_core14.defaultMarket;
1773
- const locale = import_bom_core14.defaultLocale;
1773
+ const market = import_bom_core15.defaultMarket;
1774
+ const locale = import_bom_core15.defaultLocale;
1774
1775
  if (!Array.isArray(COLLECTIONS) || COLLECTIONS?.length === 0) {
1775
1776
  console.error("apiHome.collectionGet", "collections not found", COLLECTIONS);
1776
1777
  return response.status(405).send("method not allowed");
@@ -2037,10 +2038,10 @@ async function storeApiDelete(url, options = {}) {
2037
2038
  }
2038
2039
 
2039
2040
  // src/vars/vars.handler.ts
2040
- var import_bom_core16 = require("@websolutespa/bom-core");
2041
+ var import_bom_core17 = require("@websolutespa/bom-core");
2041
2042
 
2042
2043
  // ../models/src/route/route.service.ts
2043
- var import_bom_core15 = require("@websolutespa/bom-core");
2044
+ var import_bom_core16 = require("@websolutespa/bom-core");
2044
2045
  async function getRouteLinkTree(market, locale) {
2045
2046
  const store = await getStore();
2046
2047
  const routes = await store.route.findMany({
@@ -2054,7 +2055,7 @@ async function getRouteLinkTree(market, locale) {
2054
2055
  }
2055
2056
  });
2056
2057
  const categories = await store.category.findMany();
2057
- const rootCategory = (0, import_bom_core15.getRootCategory)(categories);
2058
+ const rootCategory = (0, import_bom_core16.getRootCategory)(categories);
2058
2059
  if (rootCategory) {
2059
2060
  const root = categoryToRouteLink(routes, categories, rootCategory, locale);
2060
2061
  return root;
@@ -2062,15 +2063,13 @@ async function getRouteLinkTree(market, locale) {
2062
2063
  return void 0;
2063
2064
  }
2064
2065
  function categoryToRouteLink(routes, categories, category, locale) {
2065
- const route = routes.find(
2066
- (r) => r.category === category.id && r.isDefault
2067
- );
2066
+ const route = (0, import_bom_core16.findRouteOfCategory)(routes, category.id);
2068
2067
  if (!route) {
2069
2068
  return void 0;
2070
2069
  }
2071
- const rootCategory = (0, import_bom_core15.getRootCategory)(categories);
2070
+ const rootCategory = (0, import_bom_core16.getRootCategory)(categories);
2072
2071
  const childCategories = categories.filter((x) => {
2073
- const parentId = x.category ? (0, import_bom_core15.asCategoryId)(x.category) : null;
2072
+ const parentId = (0, import_bom_core16.asCategoryId)(x.category);
2074
2073
  return rootCategory && rootCategory.id === category.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
2075
2074
  });
2076
2075
  const routeLink = newRouteLink(category, route, locale);
@@ -2082,7 +2081,7 @@ function newRouteLink(category, route, locale) {
2082
2081
  const id = route?.page || category.id;
2083
2082
  const media = category.media || route?.media;
2084
2083
  const schema = route?.schema || category?.schema || "unknown";
2085
- const title = (0, import_bom_core15.localize)(category.title || route?.title || "untitled", locale);
2084
+ const title = (0, import_bom_core16.localize)(category.title || route?.title || "untitled", locale);
2086
2085
  const routeLink = {
2087
2086
  category: category.id,
2088
2087
  href,
@@ -2185,10 +2184,10 @@ function varsHandler() {
2185
2184
  const { locale = defaultLocale3, market = defaultMaket } = request.query || {};
2186
2185
  const layout = typeof locale === "string" && typeof market === "string" ? await getLayout(market, locale) : void 0;
2187
2186
  const info = {
2188
- production: import_bom_core16.isProduction,
2189
- development: import_bom_core16.isDevelopment,
2190
- origin: (0, import_bom_core16.getOrigin)(request.headers),
2191
- host: (0, import_bom_core16.getHost)(request.headers),
2187
+ production: import_bom_core17.isProduction,
2188
+ development: import_bom_core17.isDevelopment,
2189
+ origin: (0, import_bom_core17.getOrigin)(request.headers),
2190
+ host: (0, import_bom_core17.getHost)(request.headers),
2192
2191
  headers: { ...sortKeys(request.headers) },
2193
2192
  env: { ...getFilteredEnv(process.env) },
2194
2193
  layout: { ...sortKeys(layout) }
package/dist/index.mjs CHANGED
@@ -70,6 +70,7 @@ async function fromCache(callback, key) {
70
70
  }
71
71
 
72
72
  // src/decorators/category.ts
73
+ import { findRouteOfCategory } from "@websolutespa/bom-core";
73
74
  async function decorateCategory_(store, item, params = {}) {
74
75
  if (typeof item.category === "string") {
75
76
  const categories = await store.category.findMany({
@@ -82,9 +83,7 @@ async function decorateCategory_(store, item, params = {}) {
82
83
  if (categories.length > 0) {
83
84
  const category = categories[0];
84
85
  const routes = await store.route.findMany();
85
- const route = routes.find(
86
- (x) => x.market === params.market && x.locale === params.locale && x.isDefault && x.category === category.id
87
- );
86
+ const route = findRouteOfCategory(routes, category.id, params.market, params.locale);
88
87
  if (route) {
89
88
  category.href = route.id;
90
89
  }
@@ -102,7 +101,7 @@ async function decorateCategories_(store, items, params = {}) {
102
101
  return items.map((item) => {
103
102
  const category = categories.find((x) => x.id === item.category);
104
103
  if (category) {
105
- const route = routes.find((x) => x.isDefault && x.category === category.id);
104
+ const route = findRouteOfCategory(routes, category.id);
106
105
  if (route) {
107
106
  category.href = route.id;
108
107
  }
@@ -183,9 +182,14 @@ async function decorateLocalizables_(items, params = {}) {
183
182
 
184
183
  // src/decorators/menu.ts
185
184
  import {
185
+ findCategoryInCategories,
186
+ findChildCategories,
187
+ findRouteOfCategory as findRouteOfCategory2,
188
+ findRoutesOfCategory,
186
189
  isEquatable,
187
190
  isUndecoratedMenuCategory,
188
- isUndecoratedMenuPage
191
+ isUndecoratedMenuPage,
192
+ uuidv4
189
193
  } from "@websolutespa/bom-core";
190
194
  async function decorateMenu_(store, item, params) {
191
195
  const { market, locale } = params;
@@ -267,17 +271,17 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
267
271
  category: "",
268
272
  customClass: item.customClass,
269
273
  href: "",
270
- id: item.id || "",
274
+ id: item.id || uuidv4(),
271
275
  items: [],
272
276
  title: "",
273
277
  type: item.type
274
278
  };
275
- const category = typeof item.category === "string" ? categories.find((x) => x.id === item.category) : item.category;
279
+ const category = findCategoryInCategories(categories, item.category);
276
280
  if (category) {
277
281
  decoratedItem.category = category.id;
278
282
  decoratedItem.title = item.title || category.title || "";
279
- decoratedItem.media = decoratedItem.media || category.media;
280
- const route = routes.find((x) => x.isDefault && x.category === category.id);
283
+ decoratedItem.media = item.media || category.media;
284
+ const route = findRouteOfCategory2(routes, category.id);
281
285
  if (route) {
282
286
  decoratedItem.href = route.id;
283
287
  } else {
@@ -289,7 +293,7 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
289
293
  }
290
294
  maxDepth--;
291
295
  }
292
- const childCategories = categories.filter((x) => x.category && (typeof x.category === "object" ? x.category.id === category.id : x.category === category.id));
296
+ const childCategories = findChildCategories(categories, category.id).filter((x) => Boolean(x.isHidden) === false);
293
297
  if (childCategories.length) {
294
298
  childCategories.sort((a, b) => {
295
299
  return (a.order || MAX_INT) - (b.order || MAX_INT);
@@ -301,13 +305,15 @@ function decorateMenuCategory_(item, categories, routes, market, depth = 0) {
301
305
  maxDepth,
302
306
  items: []
303
307
  }, categories, routes, market, depth + 1));
304
- } else {
305
- const childRoutes = routes.filter((x) => !x.isDefault && x.category === category.id);
306
- childRoutes.sort((a, b) => {
307
- return (a.order || MAX_INT) - (b.order || MAX_INT);
308
- });
309
- decoratedItem.items = childRoutes.map((x) => decorateMenuRoute_(x));
310
308
  }
309
+ const childRoutes = findRoutesOfCategory(routes, category.id, false);
310
+ childRoutes.sort((a, b) => {
311
+ return (a.order || MAX_INT) - (b.order || MAX_INT);
312
+ });
313
+ decoratedItem.items = [
314
+ ...decoratedItem.items || [],
315
+ ...childRoutes.map((x) => decorateMenuRoute_(x))
316
+ ];
311
317
  }
312
318
  return decoratedItem;
313
319
  }
@@ -331,7 +337,7 @@ async function decorateMenuPage_(item, routes, store, params = {}) {
331
337
  );
332
338
  const page = await store[item.page.relationTo].findOne(id, { ...params });
333
339
  const decoratedItem = {
334
- id: item.id || "",
340
+ id: item.id || uuidv4(),
335
341
  type: item.type,
336
342
  title: item.title || page?.title || "",
337
343
  abstract: item.abstract || page?.abstract || "",
@@ -1930,7 +1936,7 @@ async function storeApiDelete(url, options = {}) {
1930
1936
  import { getHost, getOrigin, isDevelopment as isDevelopment2, isProduction } from "@websolutespa/bom-core";
1931
1937
 
1932
1938
  // ../models/src/route/route.service.ts
1933
- import { asCategoryId, defaultLocale as defaultLocale2, defaultMarket as defaultMarket2, getRootCategory, localize } from "@websolutespa/bom-core";
1939
+ import { asCategoryId, defaultLocale as defaultLocale2, defaultMarket as defaultMarket2, findRouteOfCategory as findRouteOfCategory3, getRootCategory, localize } from "@websolutespa/bom-core";
1934
1940
  async function getRouteLinkTree(market, locale) {
1935
1941
  const store = await getStore();
1936
1942
  const routes = await store.route.findMany({
@@ -1952,15 +1958,13 @@ async function getRouteLinkTree(market, locale) {
1952
1958
  return void 0;
1953
1959
  }
1954
1960
  function categoryToRouteLink(routes, categories, category, locale) {
1955
- const route = routes.find(
1956
- (r) => r.category === category.id && r.isDefault
1957
- );
1961
+ const route = findRouteOfCategory3(routes, category.id);
1958
1962
  if (!route) {
1959
1963
  return void 0;
1960
1964
  }
1961
1965
  const rootCategory = getRootCategory(categories);
1962
1966
  const childCategories = categories.filter((x) => {
1963
- const parentId = x.category ? asCategoryId(x.category) : null;
1967
+ const parentId = asCategoryId(x.category);
1964
1968
  return rootCategory && rootCategory.id === category.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
1965
1969
  });
1966
1970
  const routeLink = newRouteLink(category, route, locale);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-store",
3
- "version": "1.7.7",
3
+ "version": "1.7.8",
4
4
  "description": "Mixer Store module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "lint": "eslint *.ts*",
17
17
  "test": "jest",
18
- "test-watch": "npm test -- --watch",
18
+ "test-watch": "npm test -- --watch --silent=false",
19
19
  "coverage:integration": "npm run test -- --coverage",
20
20
  "coverage": "run-s -c --silent coverage:*",
21
21
  "compile": "tsup ./src/index.ts --format esm,cjs --dts",
@@ -1,4 +1,4 @@
1
- import { ICategorized, ICategory, IRoute, IStore, QueryParams } from '@websolutespa/bom-core';
1
+ import { ICategorized, ICategory, IRoute, IStore, QueryParams, findRouteOfCategory } from '@websolutespa/bom-core';
2
2
 
3
3
  export async function decorateCategory_<T extends ICategorized = ICategorized>(store: IStore, item: T, params: QueryParams = {}): Promise<T | (T & { category: ICategory })> {
4
4
  if (typeof item.category === 'string') {
@@ -12,12 +12,7 @@ export async function decorateCategory_<T extends ICategorized = ICategorized>(s
12
12
  if (categories.length > 0) {
13
13
  const category = categories[0];
14
14
  const routes = await store.route.findMany<IRoute>();
15
- const route = routes.find(x =>
16
- x.market === params.market &&
17
- x.locale === params.locale &&
18
- x.isDefault &&
19
- x.category === category.id
20
- );
15
+ const route = findRouteOfCategory(routes, category.id, params.market, params.locale);
21
16
  if (route) {
22
17
  category.href = route.id;
23
18
  }
@@ -36,7 +31,7 @@ export async function decorateCategories_<T extends ICategorized = ICategorized>
36
31
  return items.map(item => {
37
32
  const category = categories.find(x => x.id === item.category);
38
33
  if (category) {
39
- const route = routes.find(x => x.isDefault && x.category === category.id);
34
+ const route = findRouteOfCategory(routes, category.id);
40
35
  if (route) {
41
36
  category.href = route.id;
42
37
  }
@@ -1,7 +1,10 @@
1
1
  import {
2
- ICategorized, ICategory, IMenu, IMenuCategory, IMenuItem, IMenuPage, IMenuRoute, IRoute,
3
- IStore, IUndecoratedMenu, IUndecoratedMenuCategory, IUndecoratedMenuItem, IUndecoratedMenuPage,
4
- QueryParams, isEquatable, isUndecoratedMenuCategory, isUndecoratedMenuPage
2
+ ICategorized, ICategory, IMenu, IMenuCategory, IMenuItem, IMenuPage, IMenuRoute, IRoute, IStore,
3
+ IUndecoratedMenu, IUndecoratedMenuCategory, IUndecoratedMenuItem, IUndecoratedMenuPage, QueryParams,
4
+ findCategoryInCategories,
5
+ findChildCategories,
6
+ findRouteOfCategory, findRoutesOfCategory, isEquatable, isUndecoratedMenuCategory, isUndecoratedMenuPage,
7
+ uuidv4
5
8
  } from '@websolutespa/bom-core';
6
9
 
7
10
  export async function decorateMenu_(store: IStore, item: IUndecoratedMenu, params: { market: string, locale: string }): Promise<IMenu> {
@@ -100,21 +103,21 @@ function decorateMenuCategory_(
100
103
  category: '',
101
104
  customClass: item.customClass,
102
105
  href: '',
103
- id: item.id || '',
106
+ id: item.id || uuidv4(),
104
107
  items: [],
105
108
  title: '',
106
109
  type: item.type,
107
110
  };
108
- const category = (typeof item.category === 'string' ? categories.find(x => x.id === item.category) : item.category) as ICategory;
111
+ const category = findCategoryInCategories(categories, item.category);
109
112
  if (category) {
110
113
  // assigning category id
111
114
  decoratedItem.category = category.id;
112
115
  // assigning category title
113
116
  decoratedItem.title = item.title || category.title || '';
114
117
  // assigning current or category media
115
- decoratedItem.media = decoratedItem.media || category.media;
118
+ decoratedItem.media = item.media || category.media;
116
119
  // find category's index page route
117
- const route = routes.find(x => x.isDefault && x.category === category.id);
120
+ const route = findRouteOfCategory(routes, category.id);
118
121
  if (route) {
119
122
  // hasLink
120
123
  decoratedItem.href = route.id;
@@ -130,11 +133,7 @@ function decorateMenuCategory_(
130
133
  maxDepth--;
131
134
  }
132
135
  // search child categories
133
- const childCategories = categories.filter(x => (
134
- x.category && (typeof x.category === 'object' ?
135
- x.category.id === category.id :
136
- x.category === category.id)
137
- ));
136
+ const childCategories = findChildCategories(categories, category.id).filter(x => Boolean(x.isHidden) === false);
138
137
  if (childCategories.length) {
139
138
  // sort child categories
140
139
  childCategories.sort((a, b) => {
@@ -147,15 +146,18 @@ function decorateMenuCategory_(
147
146
  maxDepth,
148
147
  items: [],
149
148
  } as IUndecoratedMenuCategory, categories, routes, market, depth + 1));
150
- } else {
151
- // find child routes
152
- const childRoutes = routes.filter(x => !x.isDefault && x.category === category.id);
153
- // sort child routes
154
- childRoutes.sort((a, b) => {
155
- return (a.order || MAX_INT) - (b.order || MAX_INT);
156
- });
157
- decoratedItem.items = childRoutes.map(x => decorateMenuRoute_(x));
158
149
  }
150
+ // find child routes
151
+ const childRoutes = findRoutesOfCategory(routes, category.id, false);
152
+ // console.log('childRoutes', childRoutes, category.id);
153
+ // sort child routes
154
+ childRoutes.sort((a, b) => {
155
+ return (a.order || MAX_INT) - (b.order || MAX_INT);
156
+ });
157
+ decoratedItem.items = [
158
+ ...(decoratedItem.items || []),
159
+ ...childRoutes.map(x => decorateMenuRoute_(x)),
160
+ ];
159
161
  }
160
162
  return decoratedItem;
161
163
  }
@@ -189,7 +191,7 @@ async function decorateMenuPage_(
189
191
  );
190
192
  const page = await store[item.page.relationTo].findOne<ICategorized>(id, { ...params });
191
193
  const decoratedItem: IMenuPage = {
192
- id: item.id || '',
194
+ id: item.id || uuidv4(),
193
195
  type: item.type,
194
196
  title: item.title || page?.title || '',
195
197
  abstract: item.abstract || page?.abstract || '',