@websolutespa/bom-core 0.6.4 → 0.6.6
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 +108 -95
- package/dist/index.d.ts +27 -10
- package/dist/index.js +71 -17
- package/dist/index.mjs +69 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,95 +1,108 @@
|
|
|
1
|
-
# @websolutespa/bom-core
|
|
2
|
-
|
|
3
|
-
## 0.6.
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
## 0.6.
|
|
17
|
-
|
|
18
|
-
### Patch Changes
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
- Added:
|
|
40
|
-
|
|
41
|
-
## 0.
|
|
42
|
-
|
|
43
|
-
###
|
|
44
|
-
|
|
45
|
-
- Added
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
-
|
|
53
|
-
|
|
54
|
-
## 0.
|
|
55
|
-
|
|
56
|
-
###
|
|
57
|
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
-
|
|
90
|
-
|
|
91
|
-
## 0.
|
|
92
|
-
|
|
93
|
-
### Patch Changes
|
|
94
|
-
|
|
95
|
-
-
|
|
1
|
+
# @websolutespa/bom-core
|
|
2
|
+
|
|
3
|
+
## 0.6.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: collectRoutes
|
|
8
|
+
|
|
9
|
+
## 0.6.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Added: collectFeatureTypes, collectOptions
|
|
14
|
+
- Modified: Category, collectRoutes, getRouteHref, entity
|
|
15
|
+
|
|
16
|
+
## 0.6.4
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Added: typeGuards, IPagedResult
|
|
21
|
+
- Modified: IUndecoratedMenuCustom
|
|
22
|
+
|
|
23
|
+
## 0.6.3
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Added: isReservedCollectionDescription
|
|
28
|
+
|
|
29
|
+
## 0.6.2
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Modified: IMedia
|
|
34
|
+
|
|
35
|
+
## 0.6.1
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Added: defaultMarket, defaultLocale
|
|
40
|
+
|
|
41
|
+
## 0.6.0
|
|
42
|
+
|
|
43
|
+
### Minor Changes
|
|
44
|
+
|
|
45
|
+
- Added Logger, IPaginationResult
|
|
46
|
+
|
|
47
|
+
## 0.5.0
|
|
48
|
+
|
|
49
|
+
### Minor Changes
|
|
50
|
+
|
|
51
|
+
- Modified: JsonService, qs
|
|
52
|
+
- Added: asEquatable, cloneItem, typeGuards
|
|
53
|
+
|
|
54
|
+
## 0.4.1
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- Added: IAnchor, babelCase
|
|
59
|
+
- Modified: IApplication, IPageRelation
|
|
60
|
+
|
|
61
|
+
## 0.4.0
|
|
62
|
+
|
|
63
|
+
### Minor Changes
|
|
64
|
+
|
|
65
|
+
- Updating: next 13
|
|
66
|
+
|
|
67
|
+
## 0.3.0
|
|
68
|
+
|
|
69
|
+
### Minor Changes
|
|
70
|
+
|
|
71
|
+
- Modified: HttpService
|
|
72
|
+
|
|
73
|
+
## 0.2.1
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- Added: env ROOT_CATEGORY
|
|
78
|
+
|
|
79
|
+
## 0.2.0
|
|
80
|
+
|
|
81
|
+
### Minor Changes
|
|
82
|
+
|
|
83
|
+
- Modified routes, added redirects
|
|
84
|
+
|
|
85
|
+
## 0.1.2
|
|
86
|
+
|
|
87
|
+
### Patch Changes
|
|
88
|
+
|
|
89
|
+
- Modified: MockMenuService
|
|
90
|
+
|
|
91
|
+
## 0.1.1
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- Modified: ILocalizable
|
|
96
|
+
|
|
97
|
+
## 0.1.0
|
|
98
|
+
|
|
99
|
+
### Minor Changes
|
|
100
|
+
|
|
101
|
+
- Added: splat routes
|
|
102
|
+
- Added: variants
|
|
103
|
+
|
|
104
|
+
## 0.0.1
|
|
105
|
+
|
|
106
|
+
### Patch Changes
|
|
107
|
+
|
|
108
|
+
- 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
|
|
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
|
|
482
|
+
declare function asCategoryId(value: ICategory | IEquatable): string;
|
|
472
483
|
declare function getRootCategory(categories: ICategory[]): ICategory | undefined;
|
|
473
|
-
declare function getParentCategoriesById(id: string
|
|
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:
|
|
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)
|
|
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);
|
|
@@ -957,10 +1005,14 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
957
1005
|
const rootCategory = getRootCategory(categories);
|
|
958
1006
|
eachCategorized(store, (item, key) => {
|
|
959
1007
|
const segments = getCategorySegments(item, categories);
|
|
1008
|
+
const slugs = segments.map((x) => ({ slug: x.slug }));
|
|
1009
|
+
if (!item.isDefault) {
|
|
1010
|
+
slugs.push({ slug: item.slug });
|
|
1011
|
+
}
|
|
960
1012
|
eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
|
|
961
1013
|
if (!item.markets || item.markets.includes(market.id)) {
|
|
962
1014
|
const title = localize(item.title, locale.id);
|
|
963
|
-
const id = getRouteHref(
|
|
1015
|
+
const id = getRouteHref(slugs, market, locale, markets2, locales2);
|
|
964
1016
|
const route = {
|
|
965
1017
|
category: item.category,
|
|
966
1018
|
id,
|
|
@@ -1108,6 +1160,8 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
|
|
|
1108
1160
|
awaitAll,
|
|
1109
1161
|
camelToSnakeCase,
|
|
1110
1162
|
cloneItem,
|
|
1163
|
+
collectFeatureTypes,
|
|
1164
|
+
collectOptions,
|
|
1111
1165
|
collectRoutes,
|
|
1112
1166
|
consoleWarn,
|
|
1113
1167
|
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)
|
|
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);
|
|
@@ -842,10 +888,14 @@ function collectRoutes(store, categories, markets, locales) {
|
|
|
842
888
|
const rootCategory = getRootCategory(categories);
|
|
843
889
|
eachCategorized(store, (item, key) => {
|
|
844
890
|
const segments = getCategorySegments(item, categories);
|
|
891
|
+
const slugs = segments.map((x) => ({ slug: x.slug }));
|
|
892
|
+
if (!item.isDefault) {
|
|
893
|
+
slugs.push({ slug: item.slug });
|
|
894
|
+
}
|
|
845
895
|
eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
|
|
846
896
|
if (!item.markets || item.markets.includes(market.id)) {
|
|
847
897
|
const title = localize(item.title, locale.id);
|
|
848
|
-
const id = getRouteHref(
|
|
898
|
+
const id = getRouteHref(slugs, market, locale, markets2, locales2);
|
|
849
899
|
const route = {
|
|
850
900
|
category: item.category,
|
|
851
901
|
id,
|
|
@@ -992,6 +1042,8 @@ export {
|
|
|
992
1042
|
awaitAll,
|
|
993
1043
|
camelToSnakeCase,
|
|
994
1044
|
cloneItem,
|
|
1045
|
+
collectFeatureTypes,
|
|
1046
|
+
collectOptions,
|
|
995
1047
|
collectRoutes,
|
|
996
1048
|
consoleWarn,
|
|
997
1049
|
defaultLocale,
|