@websolutespa/bom-core 0.2.0 → 0.2.1
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 +38 -32
- package/dist/index.d.ts +15 -1
- package/dist/index.js +24 -2
- package/dist/index.mjs +22 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
|
-
# @websolutespa/bom-core
|
|
2
|
-
|
|
3
|
-
## 0.2.
|
|
4
|
-
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
## 0.
|
|
10
|
-
|
|
11
|
-
###
|
|
12
|
-
|
|
13
|
-
- Modified
|
|
14
|
-
|
|
15
|
-
## 0.1.
|
|
16
|
-
|
|
17
|
-
### Patch Changes
|
|
18
|
-
|
|
19
|
-
- Modified:
|
|
20
|
-
|
|
21
|
-
## 0.1.
|
|
22
|
-
|
|
23
|
-
###
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
- Added:
|
|
1
|
+
# @websolutespa/bom-core
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added: env ROOT_CATEGORY.
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- Modified routes, added redirects.
|
|
14
|
+
|
|
15
|
+
## 0.1.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Modified: MockMenuService.
|
|
20
|
+
|
|
21
|
+
## 0.1.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Modified: ILocalizable.
|
|
26
|
+
|
|
27
|
+
## 0.1.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- Added: splat routes.
|
|
32
|
+
- Added: variants.
|
|
33
|
+
|
|
34
|
+
## 0.0.1
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- Added: first release.
|
package/dist/index.d.ts
CHANGED
|
@@ -444,6 +444,7 @@ type ITemplate = {
|
|
|
444
444
|
|
|
445
445
|
declare function isCategory(value?: ICategory | IEquatable): value is ICategory;
|
|
446
446
|
declare function asCategoryId(value?: ICategory | IEquatable): string | undefined;
|
|
447
|
+
declare function getRootCategory(categories: ICategory[]): ICategory | undefined;
|
|
447
448
|
declare function getParentCategoriesById(id: string | undefined, categories: ICategory[]): ICategory[];
|
|
448
449
|
declare function getCategorySegments(item: ICategorized, categories: ICategory[]): ICategory[];
|
|
449
450
|
declare function getCategorySegmentsByCategory(item: ICategory, categories: ICategory[]): ICategory[];
|
|
@@ -519,6 +520,19 @@ declare function getRouteHref(segments: ICategory[], market: IMarket, locale: IL
|
|
|
519
520
|
|
|
520
521
|
declare function textToSlug(title: string): string;
|
|
521
522
|
|
|
523
|
+
type ListItem<T> = {
|
|
524
|
+
[K in keyof T]: {
|
|
525
|
+
readonly key: string;
|
|
526
|
+
readonly value: T[K];
|
|
527
|
+
};
|
|
528
|
+
}[keyof T];
|
|
529
|
+
/**
|
|
530
|
+
* Helper to produce an array of enum descriptors.
|
|
531
|
+
* @param enumeration Enumeration object.
|
|
532
|
+
* @param separatorRegex Regex that would catch the separator in your enum key.
|
|
533
|
+
*/
|
|
534
|
+
declare function enumToList<T extends Record<string, number | string>>(enumeration: T, separatorRegex?: RegExp): ListItem<T>[];
|
|
535
|
+
|
|
522
536
|
declare function getIsDevelopment(): boolean;
|
|
523
537
|
declare function getIsProduction(): boolean;
|
|
524
538
|
declare const isDevelopment: boolean;
|
|
@@ -531,4 +545,4 @@ declare function awaitAll(array: any, callback: (item: any, index: number) => Pr
|
|
|
531
545
|
declare function merge(target: any, source: any): any;
|
|
532
546
|
declare function deepCopy<T>(source: T): T;
|
|
533
547
|
|
|
534
|
-
export { FetchRequestOptions, FetchService, FindParams, FindWhereParams, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, 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, IPageResult, 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, Json, JsonService, LiteralUnion, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, collectRoutes, consoleWarn, deepCopy, deserializeKey, deserializeValue, eachCategorized, eachMarketLocale, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getIsDevelopment, getIsProduction, getParentCategoriesById, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isBrowser, isCategory, isDevelopment, isLocalizedString, isProduction, isStage, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, qsDeserialize, qsSerialize, textToSlug, toDisplayName, toFindParams, toPluralName, toTitleCase, toValidCollectionName, withSchema };
|
|
548
|
+
export { FetchRequestOptions, FetchService, FindParams, FindWhereParams, ICategorized, ICategory, ICategoryItem, IClassName, IClassNameCollection, IClassNameValue, ICollectionDescription, IConfig, IContextBaseParams, IContextParams, 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, IPageResult, 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, Json, JsonService, LiteralUnion, NextApiRequestCookies, Operator, PageProps, Pagination, PreviewData, QueryParams, RedirectReason, RouteStrategy, SchemaType, ServerSidePropsContext, StateValue, StaticPropsContext, ValueOf, Where, WhereAndOr, WhereBase, WhereField, asCategoryId, asEquatable, asServerProps, awaitAll, camelToSnakeCase, collectRoutes, consoleWarn, deepCopy, deserializeKey, deserializeValue, eachCategorized, eachMarketLocale, enumToList, getCategorySegments, getCategorySegmentsByCategory, getClassNames, getCollectionDescription, getIsDevelopment, getIsProduction, getParentCategoriesById, getRootCategory, getRouteHref, httpDelete, httpFetch, httpGet, httpPatch, httpPost, httpPut, isBrowser, isCategory, isDevelopment, isLocalizedString, isProduction, isStage, isValidCollectionDescription, localize, localizeItem, localizeValue, localizedToString, merge, qsDeserialize, qsSerialize, textToSlug, toDisplayName, toFindParams, toPluralName, toTitleCase, toValidCollectionName, withSchema };
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ __export(src_exports, {
|
|
|
45
45
|
deserializeValue: () => deserializeValue,
|
|
46
46
|
eachCategorized: () => eachCategorized,
|
|
47
47
|
eachMarketLocale: () => eachMarketLocale,
|
|
48
|
+
enumToList: () => enumToList,
|
|
48
49
|
getCategorySegments: () => getCategorySegments,
|
|
49
50
|
getCategorySegmentsByCategory: () => getCategorySegmentsByCategory,
|
|
50
51
|
getClassNames: () => getClassNames,
|
|
@@ -52,6 +53,7 @@ __export(src_exports, {
|
|
|
52
53
|
getIsDevelopment: () => getIsDevelopment,
|
|
53
54
|
getIsProduction: () => getIsProduction,
|
|
54
55
|
getParentCategoriesById: () => getParentCategoriesById,
|
|
56
|
+
getRootCategory: () => getRootCategory,
|
|
55
57
|
getRouteHref: () => getRouteHref,
|
|
56
58
|
httpDelete: () => httpDelete,
|
|
57
59
|
httpFetch: () => httpFetch,
|
|
@@ -90,6 +92,15 @@ function isCategory(value) {
|
|
|
90
92
|
function asCategoryId(value) {
|
|
91
93
|
return isCategory(value) ? value.id : value;
|
|
92
94
|
}
|
|
95
|
+
var ROOT_CATEGORY = process.env.ROOT_CATEGORY || "";
|
|
96
|
+
function getRootCategory(categories) {
|
|
97
|
+
const rootCategory = ROOT_CATEGORY && categories.find((x) => x.id == ROOT_CATEGORY);
|
|
98
|
+
if (rootCategory) {
|
|
99
|
+
return rootCategory;
|
|
100
|
+
} else {
|
|
101
|
+
return categories.find((x) => x.category == null);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
93
104
|
function getParentCategoriesById(id, categories) {
|
|
94
105
|
const routeCategories = [];
|
|
95
106
|
const segments = [];
|
|
@@ -239,6 +250,15 @@ function consoleWarn(message, component) {
|
|
|
239
250
|
console.warn(log);
|
|
240
251
|
}
|
|
241
252
|
|
|
253
|
+
// src/utils/enumToList.ts
|
|
254
|
+
function enumToList(enumeration, separatorRegex = /_/g) {
|
|
255
|
+
const array = Object.keys(enumeration);
|
|
256
|
+
return array.filter((key) => isNaN(Number(key))).filter((key) => typeof enumeration[key] === "number" || typeof enumeration[key] === "string").map((key) => ({
|
|
257
|
+
key: String(key).replace(separatorRegex, " "),
|
|
258
|
+
value: enumeration[key]
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
|
|
242
262
|
// src/utils/index.ts
|
|
243
263
|
function getIsDevelopment() {
|
|
244
264
|
return process && (!process.env.NODE_ENV || process.env.NODE_ENV === "development");
|
|
@@ -708,7 +728,7 @@ function qsDeserialize(query = "", deserializedParams = {}) {
|
|
|
708
728
|
function collectRoutes(store, categories, markets, locales) {
|
|
709
729
|
const routes = [];
|
|
710
730
|
if (locales.length > 0 && markets.length > 0) {
|
|
711
|
-
const
|
|
731
|
+
const rootCategory = getRootCategory(categories);
|
|
712
732
|
eachCategorized(store, (item, key) => {
|
|
713
733
|
const segments = getCategorySegments(item, categories);
|
|
714
734
|
eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
|
|
@@ -732,7 +752,7 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
732
752
|
routes.push(route);
|
|
733
753
|
}
|
|
734
754
|
});
|
|
735
|
-
if (
|
|
755
|
+
if (rootCategory && item.category === rootCategory.id) {
|
|
736
756
|
const defaultLocale = locales.find((x) => x.isDefault) || locales[0];
|
|
737
757
|
const defaultMarket = markets.find((x) => x.isDefault) || markets[0];
|
|
738
758
|
const defaultMarketLocale = defaultMarket && defaultMarket.defaultLanguage ? defaultMarket.defaultLanguage : defaultLocale.id;
|
|
@@ -860,6 +880,7 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
860
880
|
deserializeValue,
|
|
861
881
|
eachCategorized,
|
|
862
882
|
eachMarketLocale,
|
|
883
|
+
enumToList,
|
|
863
884
|
getCategorySegments,
|
|
864
885
|
getCategorySegmentsByCategory,
|
|
865
886
|
getClassNames,
|
|
@@ -867,6 +888,7 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
867
888
|
getIsDevelopment,
|
|
868
889
|
getIsProduction,
|
|
869
890
|
getParentCategoriesById,
|
|
891
|
+
getRootCategory,
|
|
870
892
|
getRouteHref,
|
|
871
893
|
httpDelete,
|
|
872
894
|
httpFetch,
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,15 @@ function isCategory(value) {
|
|
|
5
5
|
function asCategoryId(value) {
|
|
6
6
|
return isCategory(value) ? value.id : value;
|
|
7
7
|
}
|
|
8
|
+
var ROOT_CATEGORY = process.env.ROOT_CATEGORY || "";
|
|
9
|
+
function getRootCategory(categories) {
|
|
10
|
+
const rootCategory = ROOT_CATEGORY && categories.find((x) => x.id == ROOT_CATEGORY);
|
|
11
|
+
if (rootCategory) {
|
|
12
|
+
return rootCategory;
|
|
13
|
+
} else {
|
|
14
|
+
return categories.find((x) => x.category == null);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
8
17
|
function getParentCategoriesById(id, categories) {
|
|
9
18
|
const routeCategories = [];
|
|
10
19
|
const segments = [];
|
|
@@ -154,6 +163,15 @@ function consoleWarn(message, component) {
|
|
|
154
163
|
console.warn(log);
|
|
155
164
|
}
|
|
156
165
|
|
|
166
|
+
// src/utils/enumToList.ts
|
|
167
|
+
function enumToList(enumeration, separatorRegex = /_/g) {
|
|
168
|
+
const array = Object.keys(enumeration);
|
|
169
|
+
return array.filter((key) => isNaN(Number(key))).filter((key) => typeof enumeration[key] === "number" || typeof enumeration[key] === "string").map((key) => ({
|
|
170
|
+
key: String(key).replace(separatorRegex, " "),
|
|
171
|
+
value: enumeration[key]
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
|
|
157
175
|
// src/utils/index.ts
|
|
158
176
|
function getIsDevelopment() {
|
|
159
177
|
return process && (!process.env.NODE_ENV || process.env.NODE_ENV === "development");
|
|
@@ -623,7 +641,7 @@ function qsDeserialize(query = "", deserializedParams = {}) {
|
|
|
623
641
|
function collectRoutes(store, categories, markets, locales) {
|
|
624
642
|
const routes = [];
|
|
625
643
|
if (locales.length > 0 && markets.length > 0) {
|
|
626
|
-
const
|
|
644
|
+
const rootCategory = getRootCategory(categories);
|
|
627
645
|
eachCategorized(store, (item, key) => {
|
|
628
646
|
const segments = getCategorySegments(item, categories);
|
|
629
647
|
eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
|
|
@@ -647,7 +665,7 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
647
665
|
routes.push(route);
|
|
648
666
|
}
|
|
649
667
|
});
|
|
650
|
-
if (
|
|
668
|
+
if (rootCategory && item.category === rootCategory.id) {
|
|
651
669
|
const defaultLocale = locales.find((x) => x.isDefault) || locales[0];
|
|
652
670
|
const defaultMarket = markets.find((x) => x.isDefault) || markets[0];
|
|
653
671
|
const defaultMarketLocale = defaultMarket && defaultMarket.defaultLanguage ? defaultMarket.defaultLanguage : defaultLocale.id;
|
|
@@ -774,6 +792,7 @@ export {
|
|
|
774
792
|
deserializeValue,
|
|
775
793
|
eachCategorized,
|
|
776
794
|
eachMarketLocale,
|
|
795
|
+
enumToList,
|
|
777
796
|
getCategorySegments,
|
|
778
797
|
getCategorySegmentsByCategory,
|
|
779
798
|
getClassNames,
|
|
@@ -781,6 +800,7 @@ export {
|
|
|
781
800
|
getIsDevelopment,
|
|
782
801
|
getIsProduction,
|
|
783
802
|
getParentCategoriesById,
|
|
803
|
+
getRootCategory,
|
|
784
804
|
getRouteHref,
|
|
785
805
|
httpDelete,
|
|
786
806
|
httpFetch,
|