@websolutespa/bom-core 0.6.4 → 0.6.5

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,95 +1,102 @@
1
1
  # @websolutespa/bom-core
2
2
 
3
+ ## 0.6.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Added: collectFeatureTypes, collectOptions
8
+ - Modified: Category, collectRoutes, getRouteHref, entity
9
+
3
10
  ## 0.6.4
4
11
 
5
12
  ### Patch Changes
6
13
 
7
- - Added: typeGuards, IPagedResult.
8
- - Modified: IUndecoratedMenuCustom.
14
+ - Added: typeGuards, IPagedResult
15
+ - Modified: IUndecoratedMenuCustom
9
16
 
10
17
  ## 0.6.3
11
18
 
12
19
  ### Patch Changes
13
20
 
14
- - Added: isReservedCollectionDescription.
21
+ - Added: isReservedCollectionDescription
15
22
 
16
23
  ## 0.6.2
17
24
 
18
25
  ### Patch Changes
19
26
 
20
- - Modified: IMedia.
27
+ - Modified: IMedia
21
28
 
22
29
  ## 0.6.1
23
30
 
24
31
  ### Patch Changes
25
32
 
26
- - Added: defaultMarket, defaultLocale.
33
+ - Added: defaultMarket, defaultLocale
27
34
 
28
35
  ## 0.6.0
29
36
 
30
37
  ### Minor Changes
31
38
 
32
- - Added Logger, IPaginationResult.
39
+ - Added Logger, IPaginationResult
33
40
 
34
41
  ## 0.5.0
35
42
 
36
43
  ### Minor Changes
37
44
 
38
- - Modified: JsonService, qs.
39
- - Added: asEquatable, cloneItem, typeGuards.
45
+ - Modified: JsonService, qs
46
+ - Added: asEquatable, cloneItem, typeGuards
40
47
 
41
48
  ## 0.4.1
42
49
 
43
50
  ### Patch Changes
44
51
 
45
- - Added: IAnchor, babelCase.
46
- - Modified: IApplication, IPageRelation.
52
+ - Added: IAnchor, babelCase
53
+ - Modified: IApplication, IPageRelation
47
54
 
48
55
  ## 0.4.0
49
56
 
50
57
  ### Minor Changes
51
58
 
52
- - Updating: next 13.
59
+ - Updating: next 13
53
60
 
54
61
  ## 0.3.0
55
62
 
56
63
  ### Minor Changes
57
64
 
58
- - Modified: HttpService.
65
+ - Modified: HttpService
59
66
 
60
67
  ## 0.2.1
61
68
 
62
69
  ### Patch Changes
63
70
 
64
- - Added: env ROOT_CATEGORY.
71
+ - Added: env ROOT_CATEGORY
65
72
 
66
73
  ## 0.2.0
67
74
 
68
75
  ### Minor Changes
69
76
 
70
- - Modified routes, added redirects.
77
+ - Modified routes, added redirects
71
78
 
72
79
  ## 0.1.2
73
80
 
74
81
  ### Patch Changes
75
82
 
76
- - Modified: MockMenuService.
83
+ - Modified: MockMenuService
77
84
 
78
85
  ## 0.1.1
79
86
 
80
87
  ### Patch Changes
81
88
 
82
- - Modified: ILocalizable.
89
+ - Modified: ILocalizable
83
90
 
84
91
  ## 0.1.0
85
92
 
86
93
  ### Minor Changes
87
94
 
88
- - Added: splat routes.
89
- - Added: variants.
95
+ - Added: splat routes
96
+ - Added: variants
90
97
 
91
98
  ## 0.0.1
92
99
 
93
100
  ### Patch Changes
94
101
 
95
- - Added: first release.
102
+ - Added: first release
package/dist/index.d.ts CHANGED
@@ -66,21 +66,32 @@ type IAnchor = {
66
66
 
67
67
  type IEquatable = number | string;
68
68
  type SchemaType = string;
69
- type IOption = Record<string, any> & {
70
- id: IEquatable;
71
- name: string;
72
- };
73
69
  type ISchema = {
74
70
  id: IEquatable;
75
71
  schema?: string;
76
72
  };
77
- type IEntity = Record<string, unknown> & ISchema;
73
+ type IEntity = ISchema & Record<string, unknown>;
78
74
  type INamedEntity = IEntity & {
79
75
  name: ILocalizable;
80
76
  };
81
77
  type ITitledEntity = IEntity & {
82
78
  title: ILocalizable;
83
79
  };
80
+ type IOption = Record<string, any> & {
81
+ id: IEquatable;
82
+ name: string;
83
+ };
84
+ type IFeature = Record<string, any> & {
85
+ id: IEquatable;
86
+ title: string;
87
+ };
88
+ type IFeatureType = {
89
+ id: string;
90
+ schema?: string;
91
+ title: string;
92
+ mode: string;
93
+ features?: IFeature[];
94
+ };
84
95
 
85
96
  type IMediaType = 'image' | 'video' | string;
86
97
  type IMedia = {
@@ -329,7 +340,7 @@ type IUndecoratedMenuCustom = Omit<IUndecoratedMenuBase, 'type'> & {
329
340
  blockType: string;
330
341
  };
331
342
  type IUndecoratedMenuItem = IUndecoratedMenuCategory | IUndecoratedMenuGroup | IUndecoratedMenuLink | IUndecoratedMenuPage | IUndecoratedMenuCustom;
332
- type IUndecoratedMenu = {
343
+ type IUndecoratedMenu = IEntity & {
333
344
  id: string;
334
345
  items: IUndecoratedMenuItem[];
335
346
  };
@@ -468,9 +479,9 @@ type ITemplate = {
468
479
  };
469
480
 
470
481
  declare function isCategory(value?: ICategory | IEquatable): value is ICategory;
471
- declare function asCategoryId(value?: ICategory | IEquatable): string | undefined;
482
+ declare function asCategoryId(value: ICategory | IEquatable): string;
472
483
  declare function getRootCategory(categories: ICategory[]): ICategory | undefined;
473
- declare function getParentCategoriesById(id: string | undefined, categories: ICategory[]): ICategory[];
484
+ declare function getParentCategoriesById(id: string, categories: ICategory[]): ICategory[];
474
485
  declare function getCategorySegments(item: ICategorized, categories: ICategory[]): ICategory[];
475
486
  declare function getCategorySegmentsByCategory(item: ICategory, categories: ICategory[]): ICategory[];
476
487
 
@@ -562,7 +573,9 @@ declare enum RouteStrategy {
562
573
  Default = "default",
563
574
  Manual = "manual"
564
575
  }
565
- declare function getRouteHref(segments: ICategory[], market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]): string;
576
+ declare function getRouteHref(segments: {
577
+ slug: ILocalizable;
578
+ }[], market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]): string;
566
579
 
567
580
  declare function textToSlug(title: string): string;
568
581
 
@@ -588,6 +601,10 @@ declare function toSnakeCase(unknownCase: string): string;
588
601
 
589
602
  declare function cloneItem<T = unknown>(item: T): T;
590
603
 
604
+ declare function collectFeatureTypes<T extends IEntity = IEntity>(items: T[], ...keys: string[]): Promise<IFeatureType[]>;
605
+
606
+ declare function collectOptions<T extends IEntity = IEntity>(items: T[], ...keys: string[]): Promise<Partial<Record<keyof T, IOption[]>>>;
607
+
591
608
  type ListItem<T> = {
592
609
  [K in keyof T]: {
593
610
  readonly key: string;
@@ -625,4 +642,4 @@ declare function asServerProps(props: any): any;
625
642
  declare function awaitAll(array: any, callback: (item: any, index: number) => Promise<any>): Promise<any[]>;
626
643
  declare function merge(target: any, source: any): any;
627
644
 
628
- export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, IDecoratedNav, IEntity, IEquatable, ILabel, ILayout, ILocale, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IPackages, IPage, IPageRelation, IPageRelationResult, IPageResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, IUndecoratedNav, Json, JsonService, LiteralUnion, Logger, LoggerLevel, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, collectRoutes, consoleWarn, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getIsDevelopment, getIsProduction, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isCategory, isDevelopment, isEntity, isEquatable, isLocalizedString, isNotNullString, isObject, isProduction, isRelation, isReservedCollectionDescription, isStage, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
645
+ export { FetchError, FetchRequestOptions, FetchService, FindParams, FindWhereParams, IAnchor, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, IDecoratedNav, IEntity, IEquatable, IFeature, IFeatureType, ILabel, ILayout, ILocale, ILocalizable, ILocalized, ILocalizedString, IMarket, IMedia, IMediaType, IMemoryStore, IMenu, IMenuBase, IMenuCategory, IMenuCustom, IMenuGroup, IMenuItem, IMenuLink, IMenuPage, IMenuRoute, INamedEntity, IOption, IOverride, IPackages, IPage, IPageRelation, IPageRelationResult, IPageResult, IPageUnresolvedRelation, IPagedResult, IPaginationResult, IPartial, IPrettify, IQuerable, IRedirect, IRoute, IRouteCanonical, IRouteLink, IRouteParams, ISchema, ISerializedCollection, ISerializedStore, IServerSideContext, IServerSideSplatContext, IStaticContext, IStore, ITemplate, ITitledEntity, IUndecoratedMenu, IUndecoratedMenuBase, IUndecoratedMenuCategory, IUndecoratedMenuCustom, IUndecoratedMenuGroup, IUndecoratedMenuItem, IUndecoratedMenuLink, IUndecoratedMenuPage, IUndecoratedNav, Json, JsonService, LiteralUnion, Logger, LoggerLevel, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, cloneItem, collectFeatureTypes, collectOptions, collectRoutes, consoleWarn, defaultLocale, defaultMarket, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getEnv, getIsDevelopment, getIsProduction, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isArray, isBrowser, isCategory, isDevelopment, isEntity, isEquatable, isLocalizedString, isNotNullString, isObject, isProduction, isRelation, isReservedCollectionDescription, isStage, isUndecoratedMenuCategory, isUndecoratedMenuItem, isUndecoratedMenuPage, isUndecoratedNav, isUnresolvedRelation, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, pascalCaseToCamelCase, pascalCaseToCharCase, pascalCaseToKebabCase, pascalCaseToSnakeCase, qsDeserialize, qsDeserializeRaw, qsSerialize, qsSerializeRaw, resolveMediaType, textToSlug, toCamelCase, toCharCase, toDisplayName, toFindParams, toKebabCase, toPascalCase, toPluralName, toSnakeCase, toTitleCase, toValidCollectionName, unknownCaseToPascalCase, withSchema };
package/dist/index.js CHANGED
@@ -41,6 +41,8 @@ __export(src_exports, {
41
41
  awaitAll: () => awaitAll,
42
42
  camelToSnakeCase: () => camelToSnakeCase,
43
43
  cloneItem: () => cloneItem,
44
+ collectFeatureTypes: () => collectFeatureTypes,
45
+ collectOptions: () => collectOptions,
44
46
  collectRoutes: () => collectRoutes,
45
47
  consoleWarn: () => consoleWarn,
46
48
  defaultLocale: () => defaultLocale,
@@ -141,7 +143,7 @@ function getParentCategoriesById(id, categories) {
141
143
  const segment = { ...parentCategory };
142
144
  segments.unshift(segment);
143
145
  }
144
- parentId = asCategoryId(parentCategory.category) || null;
146
+ parentId = parentCategory.category ? asCategoryId(parentCategory.category) : null;
145
147
  if (parentId) {
146
148
  if (routeCategories.includes(parentId)) {
147
149
  console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
@@ -159,24 +161,11 @@ function getParentCategoriesById(id, categories) {
159
161
  function getCategorySegments(item, categories) {
160
162
  const categoryId = asCategoryId(item.category);
161
163
  const segments = getParentCategoriesById(categoryId, categories);
162
- if (item.isDefault !== true) {
163
- const category = categories.find((x) => x.id === item.category);
164
- if (category) {
165
- const segment = {
166
- id: item.id,
167
- title: item.title,
168
- slug: item.slug,
169
- media: item.media || category.media,
170
- category
171
- };
172
- segments.push(segment);
173
- }
174
- }
175
164
  return segments;
176
165
  }
177
166
  function getCategorySegmentsByCategory(item, categories) {
178
- const categoryId = asCategoryId(item.category);
179
- const segments = getParentCategoriesById(categoryId, categories);
167
+ const categoryId = item.category ? asCategoryId(item.category) : null;
168
+ const segments = categoryId ? getParentCategoriesById(categoryId, categories) : [];
180
169
  segments.push(item);
181
170
  return segments;
182
171
  }
@@ -398,6 +387,65 @@ function cloneItem(item) {
398
387
  return item;
399
388
  }
400
389
 
390
+ // src/utils/collectFeatureTypes.ts
391
+ async function collectFeatureTypes(items, ...keys) {
392
+ const featureTypes = [];
393
+ if (keys.length > 0) {
394
+ items.forEach((item) => {
395
+ keys.forEach((key) => {
396
+ const value = item[key];
397
+ if (value) {
398
+ let featureType = featureTypes.find((x) => x.id === key);
399
+ if (!featureType) {
400
+ featureType = {
401
+ id: key,
402
+ schema: "featureType",
403
+ title: key,
404
+ mode: "or",
405
+ features: []
406
+ };
407
+ featureTypes.push(featureType);
408
+ }
409
+ const features = featureType.features;
410
+ if (features && !features.find((x) => x.id === value)) {
411
+ features.push({
412
+ id: value,
413
+ title: String(value)
414
+ });
415
+ }
416
+ }
417
+ });
418
+ });
419
+ }
420
+ return featureTypes;
421
+ }
422
+
423
+ // src/utils/collectOptions.ts
424
+ async function collectOptions(items, ...keys) {
425
+ const optionsGroup = {};
426
+ if (keys.length > 0) {
427
+ items.forEach((item) => {
428
+ keys.forEach((key) => {
429
+ const value = item[key];
430
+ if (value) {
431
+ let options = optionsGroup[key];
432
+ if (!options) {
433
+ options = [];
434
+ optionsGroup[key] = options;
435
+ }
436
+ if (!options.find((x) => x.id === value)) {
437
+ options.push({
438
+ id: value,
439
+ name: String(value)
440
+ });
441
+ }
442
+ }
443
+ });
444
+ });
445
+ }
446
+ return optionsGroup;
447
+ }
448
+
401
449
  // src/utils/enumToList.ts
402
450
  function enumToList(enumeration, separatorRegex = /_/g) {
403
451
  const array = Object.keys(enumeration);
@@ -960,7 +1008,7 @@ function collectRoutes(store, categories, markets, locales) {
960
1008
  eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
961
1009
  if (!item.markets || item.markets.includes(market.id)) {
962
1010
  const title = localize(item.title, locale.id);
963
- const id = getRouteHref(segments, market, locale, markets2, locales2);
1011
+ const id = getRouteHref([...segments, { slug: item.slug }], market, locale, markets2, locales2);
964
1012
  const route = {
965
1013
  category: item.category,
966
1014
  id,
@@ -1108,6 +1156,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
1108
1156
  awaitAll,
1109
1157
  camelToSnakeCase,
1110
1158
  cloneItem,
1159
+ collectFeatureTypes,
1160
+ collectOptions,
1111
1161
  collectRoutes,
1112
1162
  consoleWarn,
1113
1163
  defaultLocale,
package/dist/index.mjs CHANGED
@@ -26,7 +26,7 @@ function getParentCategoriesById(id, categories) {
26
26
  const segment = { ...parentCategory };
27
27
  segments.unshift(segment);
28
28
  }
29
- parentId = asCategoryId(parentCategory.category) || null;
29
+ parentId = parentCategory.category ? asCategoryId(parentCategory.category) : null;
30
30
  if (parentId) {
31
31
  if (routeCategories.includes(parentId)) {
32
32
  console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
@@ -44,24 +44,11 @@ function getParentCategoriesById(id, categories) {
44
44
  function getCategorySegments(item, categories) {
45
45
  const categoryId = asCategoryId(item.category);
46
46
  const segments = getParentCategoriesById(categoryId, categories);
47
- if (item.isDefault !== true) {
48
- const category = categories.find((x) => x.id === item.category);
49
- if (category) {
50
- const segment = {
51
- id: item.id,
52
- title: item.title,
53
- slug: item.slug,
54
- media: item.media || category.media,
55
- category
56
- };
57
- segments.push(segment);
58
- }
59
- }
60
47
  return segments;
61
48
  }
62
49
  function getCategorySegmentsByCategory(item, categories) {
63
- const categoryId = asCategoryId(item.category);
64
- const segments = getParentCategoriesById(categoryId, categories);
50
+ const categoryId = item.category ? asCategoryId(item.category) : null;
51
+ const segments = categoryId ? getParentCategoriesById(categoryId, categories) : [];
65
52
  segments.push(item);
66
53
  return segments;
67
54
  }
@@ -283,6 +270,65 @@ function cloneItem(item) {
283
270
  return item;
284
271
  }
285
272
 
273
+ // src/utils/collectFeatureTypes.ts
274
+ async function collectFeatureTypes(items, ...keys) {
275
+ const featureTypes = [];
276
+ if (keys.length > 0) {
277
+ items.forEach((item) => {
278
+ keys.forEach((key) => {
279
+ const value = item[key];
280
+ if (value) {
281
+ let featureType = featureTypes.find((x) => x.id === key);
282
+ if (!featureType) {
283
+ featureType = {
284
+ id: key,
285
+ schema: "featureType",
286
+ title: key,
287
+ mode: "or",
288
+ features: []
289
+ };
290
+ featureTypes.push(featureType);
291
+ }
292
+ const features = featureType.features;
293
+ if (features && !features.find((x) => x.id === value)) {
294
+ features.push({
295
+ id: value,
296
+ title: String(value)
297
+ });
298
+ }
299
+ }
300
+ });
301
+ });
302
+ }
303
+ return featureTypes;
304
+ }
305
+
306
+ // src/utils/collectOptions.ts
307
+ async function collectOptions(items, ...keys) {
308
+ const optionsGroup = {};
309
+ if (keys.length > 0) {
310
+ items.forEach((item) => {
311
+ keys.forEach((key) => {
312
+ const value = item[key];
313
+ if (value) {
314
+ let options = optionsGroup[key];
315
+ if (!options) {
316
+ options = [];
317
+ optionsGroup[key] = options;
318
+ }
319
+ if (!options.find((x) => x.id === value)) {
320
+ options.push({
321
+ id: value,
322
+ name: String(value)
323
+ });
324
+ }
325
+ }
326
+ });
327
+ });
328
+ }
329
+ return optionsGroup;
330
+ }
331
+
286
332
  // src/utils/enumToList.ts
287
333
  function enumToList(enumeration, separatorRegex = /_/g) {
288
334
  const array = Object.keys(enumeration);
@@ -845,7 +891,7 @@ function collectRoutes(store, categories, markets, locales) {
845
891
  eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
846
892
  if (!item.markets || item.markets.includes(market.id)) {
847
893
  const title = localize(item.title, locale.id);
848
- const id = getRouteHref(segments, market, locale, markets2, locales2);
894
+ const id = getRouteHref([...segments, { slug: item.slug }], market, locale, markets2, locales2);
849
895
  const route = {
850
896
  category: item.category,
851
897
  id,
@@ -992,6 +1038,8 @@ export {
992
1038
  awaitAll,
993
1039
  camelToSnakeCase,
994
1040
  cloneItem,
1041
+ collectFeatureTypes,
1042
+ collectOptions,
995
1043
  collectRoutes,
996
1044
  consoleWarn,
997
1045
  defaultLocale,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",