@websolutespa/bom-mixer-store 1.8.3 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/dist/index.d.ts +14 -4
- package/dist/index.js +63 -41
- package/dist/index.mjs +62 -41
- package/package.json +1 -1
- package/src/decorators/category.ts +53 -35
- package/src/decorators/consts.ts +2 -0
- package/src/decorators/index.ts +1 -1
- package/src/decorators/relation.ts +2 -3
- package/src/mock/mock-page.service.ts +10 -2
- package/src/mock/mock.service.ts +3 -3
- package/src/static/static.service.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
# @websolutespa/bom-mixer-store
|
|
2
2
|
|
|
3
|
+
## 1.8.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Modified: decorateCategory_
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @websolutespa/bom-core@1.8.11
|
|
10
|
+
|
|
3
11
|
## 1.8.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
6
14
|
|
|
7
|
-
- Removed:
|
|
15
|
+
- Removed: optimizeMany_
|
|
8
16
|
|
|
9
17
|
## 1.8.2
|
|
10
18
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FetchRequestOptions,
|
|
1
|
+
import { FetchRequestOptions, IEquatable, ICategory, IStore, QueryParams, ICategorized, IRoute, ISchema, IUndecoratedMenu, IMenu, IEntity, JsonService, IMemoryStore, IQuerable, IPagedResult } from '@websolutespa/bom-core';
|
|
2
2
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
3
3
|
import { NextRequest } from 'next/server';
|
|
4
4
|
import * as _websolutespa_bom_mixer_store from '@websolutespa/bom-mixer-store';
|
|
@@ -18,12 +18,23 @@ declare function errorHandler(error: any, response: NextApiResponse): NextApiRes
|
|
|
18
18
|
|
|
19
19
|
declare function fromCache<T = unknown>(callback: () => Promise<T>, key?: string): Promise<T>;
|
|
20
20
|
|
|
21
|
-
declare function decorateCategory_<T extends
|
|
21
|
+
declare function decorateCategory_<T extends {
|
|
22
|
+
category?: IEquatable | ICategory;
|
|
23
|
+
} = {
|
|
24
|
+
category?: IEquatable | ICategory;
|
|
25
|
+
}>(store: IStore, item: T, params?: QueryParams): Promise<T | (T & {
|
|
22
26
|
category: ICategory;
|
|
23
27
|
})>;
|
|
24
28
|
declare function decorateCategories_<T extends ICategorized = ICategorized>(store: IStore, items: T[], params?: QueryParams): Promise<(T | (T & {
|
|
25
29
|
category: ICategory;
|
|
26
30
|
}))[]>;
|
|
31
|
+
declare function collectCategory_<T extends {
|
|
32
|
+
category?: IEquatable | ICategory;
|
|
33
|
+
} = {
|
|
34
|
+
category?: IEquatable | ICategory;
|
|
35
|
+
}>(categories: ICategory[], routes: IRoute[], item: T, params: QueryParams | undefined, depth: number): Promise<T>;
|
|
36
|
+
|
|
37
|
+
declare const DEFAULT_DEPTH = 3;
|
|
27
38
|
|
|
28
39
|
declare function decorateHref_<T extends ISchema = ISchema>(store: IStore, item: T, params?: QueryParams): Promise<T | T & {
|
|
29
40
|
href: string | null;
|
|
@@ -51,7 +62,6 @@ declare function decorateNavs_<T extends ISchema = ISchema>(store: IStore, items
|
|
|
51
62
|
declare function optimizeOne_<T extends ICategorized = ICategorized>(item: T): Promise<T>;
|
|
52
63
|
declare function optimizeMany_<T extends ICategorized = ICategorized>(items: T[]): Promise<T[]>;
|
|
53
64
|
|
|
54
|
-
declare const SERVICE_DEFAULT_DEPTH = 3;
|
|
55
65
|
declare function decorateRelation_<T extends ISchema = ISchema>(store: IStore, item: T, params?: QueryParams): Promise<T>;
|
|
56
66
|
declare function decorateRelations_<T extends ISchema = ISchema>(store: IStore, items: T[], params?: QueryParams): Promise<T[]>;
|
|
57
67
|
type IPageResolvedRelation = {
|
|
@@ -242,4 +252,4 @@ declare function getStore<T extends IStore>(): Promise<T>;
|
|
|
242
252
|
|
|
243
253
|
declare function varsHandler(): _websolutespa_bom_mixer_store.IHandler<any>;
|
|
244
254
|
|
|
245
|
-
export { ApiRequestOptions, BuildStrategy, COLLECTIONS, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, REMOTE_API_SESSION, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy,
|
|
255
|
+
export { ApiRequestOptions, BuildStrategy, COLLECTIONS, DEFAULT_DEPTH, IApiHandler, ICrudMethod, IField, IHandler, IPageResolvedRelation, KNOWN_COLLECTIONS, MAX_INT, MOCK_COLLECTIONS, MapTo, MockMenuService, MockPageService, MockService, NextPhase, REMOTE_API_SESSION, RemoteMenuService, RemotePageService, RemoteService, RemoteServiceStrategy, STATIC_COLLECTIONS, StaticService, StaticServiceConfig, StaticServiceSrc, StoreStrategy, apiHandler, buildStrategy, collectCategory_, collectionDelete, collectionGet, collectionPatch, collectionPost, decorateCategories_, decorateCategory_, decorateHref_, decorateHrefs_, decorateLocalizable_, decorateLocalizables_, decorateMenu_, decorateMenus_, decorateNav_, decorateNavs_, decorateRelation_, decorateRelations_, decorateSchema_, decorateSchemas_, decorateStaticRelation_, decorateStaticRelations_, errorHandler, findRoute, fromCache, getLocalApiRequestOptions, getLocalApiUrl, getMockStore, getMockStoreFromData_, getRemoteApiRequestOptions, getRemoteApiUrl, getRemoteStore, getStore, isApiRequest, isNextRequest, isStaticRequest, localApiDelete, localApiFetch, localApiGet, localApiPatch, localApiPost, localApiPut, mockApiDelete, mockApiFetch, mockApiGet, mockApiPatch, mockApiPost, mockApiPut, mockHandler, nextPhase, optimizeMany_, optimizeOne_, remoteApiDelete, remoteApiFetch, remoteApiGet, remoteApiPatch, remoteApiPost, remoteApiPut, routePost, staticCollections, storeApiDelete, storeApiGet, storeApiPatch, storeApiPost, storeApiPut, storeCacheDuration, storeHandler, storeIndexHandler, storeStrategy, varsHandler };
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
BuildStrategy: () => BuildStrategy,
|
|
34
34
|
COLLECTIONS: () => COLLECTIONS,
|
|
35
|
+
DEFAULT_DEPTH: () => DEFAULT_DEPTH,
|
|
35
36
|
KNOWN_COLLECTIONS: () => KNOWN_COLLECTIONS,
|
|
36
37
|
MAX_INT: () => MAX_INT,
|
|
37
38
|
MOCK_COLLECTIONS: () => MOCK_COLLECTIONS,
|
|
@@ -44,12 +45,12 @@ __export(src_exports, {
|
|
|
44
45
|
RemotePageService: () => RemotePageService,
|
|
45
46
|
RemoteService: () => RemoteService,
|
|
46
47
|
RemoteServiceStrategy: () => RemoteServiceStrategy,
|
|
47
|
-
SERVICE_DEFAULT_DEPTH: () => SERVICE_DEFAULT_DEPTH,
|
|
48
48
|
STATIC_COLLECTIONS: () => STATIC_COLLECTIONS,
|
|
49
49
|
StaticService: () => StaticService,
|
|
50
50
|
StoreStrategy: () => StoreStrategy,
|
|
51
51
|
apiHandler: () => apiHandler,
|
|
52
52
|
buildStrategy: () => buildStrategy,
|
|
53
|
+
collectCategory_: () => collectCategory_,
|
|
53
54
|
collectionDelete: () => collectionDelete,
|
|
54
55
|
collectionGet: () => collectionGet,
|
|
55
56
|
collectionPatch: () => collectionPatch,
|
|
@@ -192,47 +193,60 @@ async function fromCache(callback, key) {
|
|
|
192
193
|
|
|
193
194
|
// src/decorators/category.ts
|
|
194
195
|
var import_bom_core = require("@websolutespa/bom-core");
|
|
196
|
+
|
|
197
|
+
// src/decorators/consts.ts
|
|
198
|
+
var DEFAULT_DEPTH = 3;
|
|
199
|
+
|
|
200
|
+
// src/decorators/category.ts
|
|
195
201
|
async function decorateCategory_(store, item, params = {}) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
203
|
+
if (depth === 0) {
|
|
204
|
+
return item;
|
|
205
|
+
}
|
|
206
|
+
const categories = await store.category.findMany({
|
|
207
|
+
market: params.market,
|
|
208
|
+
locale: params.locale,
|
|
209
|
+
depth: 0
|
|
210
|
+
});
|
|
211
|
+
const routes = await store.route.findMany();
|
|
212
|
+
const decoratedItem = await collectCategory_(categories, routes, item, params, depth);
|
|
213
|
+
return decoratedItem;
|
|
214
|
+
}
|
|
215
|
+
async function decorateCategories_(store, items, params = {}) {
|
|
216
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
217
|
+
if (depth === 0) {
|
|
218
|
+
return items;
|
|
219
|
+
}
|
|
220
|
+
const categories = await store.category.findMany({
|
|
221
|
+
market: params.market,
|
|
222
|
+
locale: params.locale,
|
|
223
|
+
depth: 0
|
|
224
|
+
});
|
|
225
|
+
const routes = await store.route.findMany();
|
|
226
|
+
const decoratedItems = [];
|
|
227
|
+
for (const item of items) {
|
|
228
|
+
const decoratedItem = await collectCategory_(categories, routes, item, params, depth);
|
|
229
|
+
decoratedItems.push(decoratedItem);
|
|
230
|
+
}
|
|
231
|
+
return decoratedItems;
|
|
232
|
+
}
|
|
233
|
+
async function collectCategory_(categories, routes, item, params = {}, depth) {
|
|
234
|
+
if (depth === 0) {
|
|
235
|
+
return item;
|
|
236
|
+
}
|
|
237
|
+
if ((0, import_bom_core.isUnresolvedCategory)(item.category)) {
|
|
238
|
+
const category = categories.find((x) => x.id === item.category);
|
|
239
|
+
if (category) {
|
|
207
240
|
const route = (0, import_bom_core.findRouteOfCategory)(routes, category.id, params.market, params.locale);
|
|
208
241
|
if (route) {
|
|
209
242
|
category.href = route.id;
|
|
210
243
|
}
|
|
211
|
-
|
|
244
|
+
const decoratedCategory = await collectCategory_(categories, routes, category, params, depth - 1);
|
|
245
|
+
return { ...item, category: decoratedCategory };
|
|
212
246
|
}
|
|
213
247
|
}
|
|
214
248
|
return item;
|
|
215
249
|
}
|
|
216
|
-
async function decorateCategories_(store, items, params = {}) {
|
|
217
|
-
const hasUndecoratedCategories = items.find((x) => typeof x.category === "string") !== void 0;
|
|
218
|
-
if (hasUndecoratedCategories) {
|
|
219
|
-
const categories = await store.category.findMany();
|
|
220
|
-
let routes = await store.route.findMany();
|
|
221
|
-
routes = routes.filter((x) => x.market === params.market && x.locale === params.locale);
|
|
222
|
-
return items.map((item) => {
|
|
223
|
-
const category = categories.find((x) => x.id === item.category);
|
|
224
|
-
if (category) {
|
|
225
|
-
const route = (0, import_bom_core.findRouteOfCategory)(routes, category.id);
|
|
226
|
-
if (route) {
|
|
227
|
-
category.href = route.id;
|
|
228
|
-
}
|
|
229
|
-
return { ...item, category };
|
|
230
|
-
}
|
|
231
|
-
return item;
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
return items;
|
|
235
|
-
}
|
|
236
250
|
|
|
237
251
|
// src/decorators/href.ts
|
|
238
252
|
async function decorateHref_(store, item, params = {}) {
|
|
@@ -591,9 +605,8 @@ async function optimizeMany_(items) {
|
|
|
591
605
|
|
|
592
606
|
// src/decorators/relation.ts
|
|
593
607
|
var import_bom_core5 = require("@websolutespa/bom-core");
|
|
594
|
-
var SERVICE_DEFAULT_DEPTH = 3;
|
|
595
608
|
async function decorateRelation_(store, item, params = {}) {
|
|
596
|
-
const depth = params.depth != null ? params.depth :
|
|
609
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
597
610
|
if (depth === 0) {
|
|
598
611
|
return item;
|
|
599
612
|
}
|
|
@@ -729,7 +742,7 @@ var MockService = class extends import_bom_core7.JsonService {
|
|
|
729
742
|
decoratedItem = await decorateRelation_(store, decoratedItem, {
|
|
730
743
|
market: params.market,
|
|
731
744
|
locale: params.locale,
|
|
732
|
-
depth: params.depth != null ? params.depth :
|
|
745
|
+
depth: params.depth != null ? params.depth : DEFAULT_DEPTH
|
|
733
746
|
});
|
|
734
747
|
return decoratedItem;
|
|
735
748
|
}
|
|
@@ -740,7 +753,7 @@ var MockService = class extends import_bom_core7.JsonService {
|
|
|
740
753
|
decoratedItems = await decorateRelations_(store, decoratedItems, {
|
|
741
754
|
market: params.market,
|
|
742
755
|
locale: params.locale,
|
|
743
|
-
depth: params.depth != null ? params.depth :
|
|
756
|
+
depth: params.depth != null ? params.depth : DEFAULT_DEPTH
|
|
744
757
|
});
|
|
745
758
|
return decoratedItems;
|
|
746
759
|
}
|
|
@@ -779,7 +792,11 @@ var MockPageService = class extends MockService {
|
|
|
779
792
|
async decorateOne_(item, params = {}) {
|
|
780
793
|
const store = this.store;
|
|
781
794
|
let decoratedItem = item;
|
|
782
|
-
decoratedItem = await decorateCategory_(store, decoratedItem,
|
|
795
|
+
decoratedItem = await decorateCategory_(store, decoratedItem, {
|
|
796
|
+
market: params.market,
|
|
797
|
+
locale: params.locale,
|
|
798
|
+
depth: params.depth
|
|
799
|
+
});
|
|
783
800
|
decoratedItem = await decorateLocalizable_(decoratedItem, params);
|
|
784
801
|
decoratedItem = await decorateHref_(store, decoratedItem, params);
|
|
785
802
|
decoratedItem = await decorateNav_(store, decoratedItem, params);
|
|
@@ -793,7 +810,11 @@ var MockPageService = class extends MockService {
|
|
|
793
810
|
async decorateMany_(items, params = {}) {
|
|
794
811
|
const store = this.store;
|
|
795
812
|
let decoratedItems = items;
|
|
796
|
-
decoratedItems = await decorateCategories_(store, decoratedItems,
|
|
813
|
+
decoratedItems = await decorateCategories_(store, decoratedItems, {
|
|
814
|
+
market: params.market,
|
|
815
|
+
locale: params.locale,
|
|
816
|
+
depth: params.depth
|
|
817
|
+
});
|
|
797
818
|
decoratedItems = await decorateLocalizables_(decoratedItems, params);
|
|
798
819
|
decoratedItems = await decorateHrefs_(store, decoratedItems, params);
|
|
799
820
|
decoratedItems = await decorateRelations_(store, decoratedItems, {
|
|
@@ -1233,7 +1254,7 @@ var StaticService = class extends import_bom_core9.JsonService {
|
|
|
1233
1254
|
}
|
|
1234
1255
|
};
|
|
1235
1256
|
async function decorateStaticRelation_(store, fields, item, params = {}) {
|
|
1236
|
-
const depth = params.depth != null ? params.depth :
|
|
1257
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
1237
1258
|
if (depth === 0) {
|
|
1238
1259
|
return item;
|
|
1239
1260
|
}
|
|
@@ -2378,6 +2399,7 @@ function varsHandler() {
|
|
|
2378
2399
|
0 && (module.exports = {
|
|
2379
2400
|
BuildStrategy,
|
|
2380
2401
|
COLLECTIONS,
|
|
2402
|
+
DEFAULT_DEPTH,
|
|
2381
2403
|
KNOWN_COLLECTIONS,
|
|
2382
2404
|
MAX_INT,
|
|
2383
2405
|
MOCK_COLLECTIONS,
|
|
@@ -2390,12 +2412,12 @@ function varsHandler() {
|
|
|
2390
2412
|
RemotePageService,
|
|
2391
2413
|
RemoteService,
|
|
2392
2414
|
RemoteServiceStrategy,
|
|
2393
|
-
SERVICE_DEFAULT_DEPTH,
|
|
2394
2415
|
STATIC_COLLECTIONS,
|
|
2395
2416
|
StaticService,
|
|
2396
2417
|
StoreStrategy,
|
|
2397
2418
|
apiHandler,
|
|
2398
2419
|
buildStrategy,
|
|
2420
|
+
collectCategory_,
|
|
2399
2421
|
collectionDelete,
|
|
2400
2422
|
collectionGet,
|
|
2401
2423
|
collectionPatch,
|
package/dist/index.mjs
CHANGED
|
@@ -76,48 +76,61 @@ async function fromCache(callback, key) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/decorators/category.ts
|
|
79
|
-
import { findRouteOfCategory } from "@websolutespa/bom-core";
|
|
79
|
+
import { findRouteOfCategory, isUnresolvedCategory } from "@websolutespa/bom-core";
|
|
80
|
+
|
|
81
|
+
// src/decorators/consts.ts
|
|
82
|
+
var DEFAULT_DEPTH = 3;
|
|
83
|
+
|
|
84
|
+
// src/decorators/category.ts
|
|
80
85
|
async function decorateCategory_(store, item, params = {}) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
87
|
+
if (depth === 0) {
|
|
88
|
+
return item;
|
|
89
|
+
}
|
|
90
|
+
const categories = await store.category.findMany({
|
|
91
|
+
market: params.market,
|
|
92
|
+
locale: params.locale,
|
|
93
|
+
depth: 0
|
|
94
|
+
});
|
|
95
|
+
const routes = await store.route.findMany();
|
|
96
|
+
const decoratedItem = await collectCategory_(categories, routes, item, params, depth);
|
|
97
|
+
return decoratedItem;
|
|
98
|
+
}
|
|
99
|
+
async function decorateCategories_(store, items, params = {}) {
|
|
100
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
101
|
+
if (depth === 0) {
|
|
102
|
+
return items;
|
|
103
|
+
}
|
|
104
|
+
const categories = await store.category.findMany({
|
|
105
|
+
market: params.market,
|
|
106
|
+
locale: params.locale,
|
|
107
|
+
depth: 0
|
|
108
|
+
});
|
|
109
|
+
const routes = await store.route.findMany();
|
|
110
|
+
const decoratedItems = [];
|
|
111
|
+
for (const item of items) {
|
|
112
|
+
const decoratedItem = await collectCategory_(categories, routes, item, params, depth);
|
|
113
|
+
decoratedItems.push(decoratedItem);
|
|
114
|
+
}
|
|
115
|
+
return decoratedItems;
|
|
116
|
+
}
|
|
117
|
+
async function collectCategory_(categories, routes, item, params = {}, depth) {
|
|
118
|
+
if (depth === 0) {
|
|
119
|
+
return item;
|
|
120
|
+
}
|
|
121
|
+
if (isUnresolvedCategory(item.category)) {
|
|
122
|
+
const category = categories.find((x) => x.id === item.category);
|
|
123
|
+
if (category) {
|
|
92
124
|
const route = findRouteOfCategory(routes, category.id, params.market, params.locale);
|
|
93
125
|
if (route) {
|
|
94
126
|
category.href = route.id;
|
|
95
127
|
}
|
|
96
|
-
|
|
128
|
+
const decoratedCategory = await collectCategory_(categories, routes, category, params, depth - 1);
|
|
129
|
+
return { ...item, category: decoratedCategory };
|
|
97
130
|
}
|
|
98
131
|
}
|
|
99
132
|
return item;
|
|
100
133
|
}
|
|
101
|
-
async function decorateCategories_(store, items, params = {}) {
|
|
102
|
-
const hasUndecoratedCategories = items.find((x) => typeof x.category === "string") !== void 0;
|
|
103
|
-
if (hasUndecoratedCategories) {
|
|
104
|
-
const categories = await store.category.findMany();
|
|
105
|
-
let routes = await store.route.findMany();
|
|
106
|
-
routes = routes.filter((x) => x.market === params.market && x.locale === params.locale);
|
|
107
|
-
return items.map((item) => {
|
|
108
|
-
const category = categories.find((x) => x.id === item.category);
|
|
109
|
-
if (category) {
|
|
110
|
-
const route = findRouteOfCategory(routes, category.id);
|
|
111
|
-
if (route) {
|
|
112
|
-
category.href = route.id;
|
|
113
|
-
}
|
|
114
|
-
return { ...item, category };
|
|
115
|
-
}
|
|
116
|
-
return item;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
return items;
|
|
120
|
-
}
|
|
121
134
|
|
|
122
135
|
// src/decorators/href.ts
|
|
123
136
|
async function decorateHref_(store, item, params = {}) {
|
|
@@ -486,9 +499,8 @@ async function optimizeMany_(items) {
|
|
|
486
499
|
|
|
487
500
|
// src/decorators/relation.ts
|
|
488
501
|
import { isArray as isArray2, isObject as isObject2, isUnresolvedRelation } from "@websolutespa/bom-core";
|
|
489
|
-
var SERVICE_DEFAULT_DEPTH = 3;
|
|
490
502
|
async function decorateRelation_(store, item, params = {}) {
|
|
491
|
-
const depth = params.depth != null ? params.depth :
|
|
503
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
492
504
|
if (depth === 0) {
|
|
493
505
|
return item;
|
|
494
506
|
}
|
|
@@ -624,7 +636,7 @@ var MockService = class extends JsonService {
|
|
|
624
636
|
decoratedItem = await decorateRelation_(store, decoratedItem, {
|
|
625
637
|
market: params.market,
|
|
626
638
|
locale: params.locale,
|
|
627
|
-
depth: params.depth != null ? params.depth :
|
|
639
|
+
depth: params.depth != null ? params.depth : DEFAULT_DEPTH
|
|
628
640
|
});
|
|
629
641
|
return decoratedItem;
|
|
630
642
|
}
|
|
@@ -635,7 +647,7 @@ var MockService = class extends JsonService {
|
|
|
635
647
|
decoratedItems = await decorateRelations_(store, decoratedItems, {
|
|
636
648
|
market: params.market,
|
|
637
649
|
locale: params.locale,
|
|
638
|
-
depth: params.depth != null ? params.depth :
|
|
650
|
+
depth: params.depth != null ? params.depth : DEFAULT_DEPTH
|
|
639
651
|
});
|
|
640
652
|
return decoratedItems;
|
|
641
653
|
}
|
|
@@ -674,7 +686,11 @@ var MockPageService = class extends MockService {
|
|
|
674
686
|
async decorateOne_(item, params = {}) {
|
|
675
687
|
const store = this.store;
|
|
676
688
|
let decoratedItem = item;
|
|
677
|
-
decoratedItem = await decorateCategory_(store, decoratedItem,
|
|
689
|
+
decoratedItem = await decorateCategory_(store, decoratedItem, {
|
|
690
|
+
market: params.market,
|
|
691
|
+
locale: params.locale,
|
|
692
|
+
depth: params.depth
|
|
693
|
+
});
|
|
678
694
|
decoratedItem = await decorateLocalizable_(decoratedItem, params);
|
|
679
695
|
decoratedItem = await decorateHref_(store, decoratedItem, params);
|
|
680
696
|
decoratedItem = await decorateNav_(store, decoratedItem, params);
|
|
@@ -688,7 +704,11 @@ var MockPageService = class extends MockService {
|
|
|
688
704
|
async decorateMany_(items, params = {}) {
|
|
689
705
|
const store = this.store;
|
|
690
706
|
let decoratedItems = items;
|
|
691
|
-
decoratedItems = await decorateCategories_(store, decoratedItems,
|
|
707
|
+
decoratedItems = await decorateCategories_(store, decoratedItems, {
|
|
708
|
+
market: params.market,
|
|
709
|
+
locale: params.locale,
|
|
710
|
+
depth: params.depth
|
|
711
|
+
});
|
|
692
712
|
decoratedItems = await decorateLocalizables_(decoratedItems, params);
|
|
693
713
|
decoratedItems = await decorateHrefs_(store, decoratedItems, params);
|
|
694
714
|
decoratedItems = await decorateRelations_(store, decoratedItems, {
|
|
@@ -1128,7 +1148,7 @@ var StaticService = class extends JsonService2 {
|
|
|
1128
1148
|
}
|
|
1129
1149
|
};
|
|
1130
1150
|
async function decorateStaticRelation_(store, fields, item, params = {}) {
|
|
1131
|
-
const depth = params.depth != null ? params.depth :
|
|
1151
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
1132
1152
|
if (depth === 0) {
|
|
1133
1153
|
return item;
|
|
1134
1154
|
}
|
|
@@ -2272,6 +2292,7 @@ function varsHandler() {
|
|
|
2272
2292
|
export {
|
|
2273
2293
|
BuildStrategy,
|
|
2274
2294
|
COLLECTIONS,
|
|
2295
|
+
DEFAULT_DEPTH,
|
|
2275
2296
|
KNOWN_COLLECTIONS,
|
|
2276
2297
|
MAX_INT,
|
|
2277
2298
|
MOCK_COLLECTIONS,
|
|
@@ -2284,12 +2305,12 @@ export {
|
|
|
2284
2305
|
RemotePageService,
|
|
2285
2306
|
RemoteService,
|
|
2286
2307
|
RemoteServiceStrategy,
|
|
2287
|
-
SERVICE_DEFAULT_DEPTH,
|
|
2288
2308
|
STATIC_COLLECTIONS,
|
|
2289
2309
|
StaticService,
|
|
2290
2310
|
StoreStrategy,
|
|
2291
2311
|
apiHandler,
|
|
2292
2312
|
buildStrategy,
|
|
2313
|
+
collectCategory_,
|
|
2293
2314
|
collectionDelete,
|
|
2294
2315
|
collectionGet,
|
|
2295
2316
|
collectionPatch,
|
package/package.json
CHANGED
|
@@ -1,44 +1,62 @@
|
|
|
1
|
-
import { ICategorized, ICategory, IRoute, IStore, QueryParams, findRouteOfCategory } from '@websolutespa/bom-core';
|
|
1
|
+
import { ICategorized, ICategory, IEquatable, IRoute, IStore, QueryParams, findRouteOfCategory, isUnresolvedCategory } from '@websolutespa/bom-core';
|
|
2
|
+
import { DEFAULT_DEPTH } from './consts';
|
|
2
3
|
|
|
3
|
-
export async function decorateCategory_<T extends
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
export async function decorateCategory_<T extends { category?: IEquatable | ICategory } = { category?: IEquatable | ICategory }>(store: IStore, item: T, params: QueryParams = {}): Promise<T | (T & { category: ICategory })> {
|
|
5
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
6
|
+
if (depth === 0) {
|
|
7
|
+
return item;
|
|
8
|
+
}
|
|
9
|
+
const categories = await store.category.findMany<ICategory>({
|
|
10
|
+
market: params.market,
|
|
11
|
+
locale: params.locale,
|
|
12
|
+
depth: 0,
|
|
13
|
+
});
|
|
14
|
+
const routes = await store.route.findMany<IRoute>();
|
|
15
|
+
const decoratedItem = await collectCategory_(categories, routes, item, params, depth);
|
|
16
|
+
return decoratedItem as T & { category: ICategory };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function decorateCategories_<T extends ICategorized = ICategorized>(store: IStore, items: T[], params: QueryParams = {}): Promise<(T | (T & { category: ICategory }))[]> {
|
|
20
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
21
|
+
if (depth === 0) {
|
|
22
|
+
return items;
|
|
23
|
+
}
|
|
24
|
+
const categories = await store.category.findMany<ICategory>({
|
|
25
|
+
market: params.market,
|
|
26
|
+
locale: params.locale,
|
|
27
|
+
depth: 0,
|
|
28
|
+
});
|
|
29
|
+
const routes = await store.route.findMany<IRoute>();
|
|
30
|
+
const decoratedItems = [];
|
|
31
|
+
for (const item of items) {
|
|
32
|
+
const decoratedItem = await collectCategory_(categories, routes, item, params, depth);
|
|
33
|
+
decoratedItems.push(decoratedItem);
|
|
34
|
+
}
|
|
35
|
+
return decoratedItems;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function collectCategory_<
|
|
39
|
+
T extends { category?: IEquatable | ICategory } = { category?: IEquatable | ICategory }
|
|
40
|
+
>(
|
|
41
|
+
categories: ICategory[],
|
|
42
|
+
routes: IRoute[],
|
|
43
|
+
item: T,
|
|
44
|
+
params: QueryParams = {},
|
|
45
|
+
depth: number
|
|
46
|
+
): Promise<T> {
|
|
47
|
+
if (depth === 0) {
|
|
48
|
+
return item;
|
|
49
|
+
}
|
|
50
|
+
if (isUnresolvedCategory(item.category)) {
|
|
51
|
+
const category = categories.find(x => x.id === item.category);
|
|
52
|
+
if (category) {
|
|
15
53
|
const route = findRouteOfCategory(routes, category.id, params.market, params.locale);
|
|
16
54
|
if (route) {
|
|
17
55
|
category.href = route.id;
|
|
18
56
|
}
|
|
19
|
-
|
|
57
|
+
const decoratedCategory = await collectCategory_(categories, routes, category, params, depth - 1);
|
|
58
|
+
return { ...item, category: decoratedCategory };
|
|
20
59
|
}
|
|
21
60
|
}
|
|
22
61
|
return item;
|
|
23
62
|
}
|
|
24
|
-
|
|
25
|
-
export async function decorateCategories_<T extends ICategorized = ICategorized>(store: IStore, items: T[], params: QueryParams = {}): Promise<(T | (T & { category: ICategory }))[]> {
|
|
26
|
-
const hasUndecoratedCategories = items.find(x => typeof x.category === 'string') !== undefined;
|
|
27
|
-
if (hasUndecoratedCategories) {
|
|
28
|
-
const categories = await store.category.findMany<ICategory>();
|
|
29
|
-
let routes = await store.route.findMany<IRoute>();
|
|
30
|
-
routes = routes.filter(x => x.market === params.market && x.locale === params.locale);
|
|
31
|
-
return items.map(item => {
|
|
32
|
-
const category = categories.find(x => x.id === item.category);
|
|
33
|
-
if (category) {
|
|
34
|
-
const route = findRouteOfCategory(routes, category.id);
|
|
35
|
-
if (route) {
|
|
36
|
-
category.href = route.id;
|
|
37
|
-
}
|
|
38
|
-
return { ...item, category };
|
|
39
|
-
}
|
|
40
|
-
return item;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return items;
|
|
44
|
-
}
|
package/src/decorators/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './category';
|
|
2
|
+
export * from './consts';
|
|
2
3
|
export * from './href';
|
|
3
4
|
export * from './localizable';
|
|
4
5
|
export * from './menu';
|
|
@@ -6,4 +7,3 @@ export * from './nav';
|
|
|
6
7
|
export * from './optimize';
|
|
7
8
|
export * from './relation';
|
|
8
9
|
export * from './schema';
|
|
9
|
-
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ICategorized, IEquatable, ISchema, IStore, QueryParams, isArray, isObject, isUnresolvedRelation } from '@websolutespa/bom-core';
|
|
2
|
-
|
|
3
|
-
export const SERVICE_DEFAULT_DEPTH = 3;
|
|
2
|
+
import { DEFAULT_DEPTH } from './consts';
|
|
4
3
|
|
|
5
4
|
export async function decorateRelation_<T extends ISchema = ISchema>(store: IStore, item: T, params: QueryParams = {}): Promise<T> {
|
|
6
|
-
const depth = params.depth != null ? params.depth :
|
|
5
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
7
6
|
if (depth === 0) {
|
|
8
7
|
return item;
|
|
9
8
|
}
|
|
@@ -7,7 +7,11 @@ export class MockPageService<T extends ICategorized = ICategorized> extends Mock
|
|
|
7
7
|
protected override async decorateOne_<B extends T = T>(item: B, params: QueryParams = {}): Promise<B> {
|
|
8
8
|
const store = this.store;
|
|
9
9
|
let decoratedItem = item;
|
|
10
|
-
decoratedItem = await decorateCategory_<B>(store, decoratedItem,
|
|
10
|
+
decoratedItem = await decorateCategory_<B>(store, decoratedItem, {
|
|
11
|
+
market: params.market,
|
|
12
|
+
locale: params.locale,
|
|
13
|
+
depth: params.depth,
|
|
14
|
+
});
|
|
11
15
|
decoratedItem = await decorateLocalizable_<B>(decoratedItem, params);
|
|
12
16
|
decoratedItem = await decorateHref_<B>(store, decoratedItem, params);
|
|
13
17
|
decoratedItem = await decorateNav_<B>(store, decoratedItem, params);
|
|
@@ -23,7 +27,11 @@ export class MockPageService<T extends ICategorized = ICategorized> extends Mock
|
|
|
23
27
|
const store = this.store;
|
|
24
28
|
let decoratedItems = items;
|
|
25
29
|
// decoratedItems = await optimizeMany_(decoratedItems);
|
|
26
|
-
decoratedItems = await decorateCategories_<B>(store, decoratedItems,
|
|
30
|
+
decoratedItems = await decorateCategories_<B>(store, decoratedItems, {
|
|
31
|
+
market: params.market,
|
|
32
|
+
locale: params.locale,
|
|
33
|
+
depth: params.depth,
|
|
34
|
+
});
|
|
27
35
|
decoratedItems = await decorateLocalizables_<B>(decoratedItems, params);
|
|
28
36
|
decoratedItems = await decorateHrefs_<B>(store, decoratedItems, params);
|
|
29
37
|
decoratedItems = await decorateRelations_<B>(store, decoratedItems, {
|
package/src/mock/mock.service.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IEntity, IStore, JsonService, QueryParams } from '@websolutespa/bom-core';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_DEPTH, decorateLocalizable_, decorateLocalizables_, decorateRelation_, decorateRelations_ } from '../decorators';
|
|
3
3
|
|
|
4
4
|
export class MockService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
5
5
|
store: IStore;
|
|
@@ -16,7 +16,7 @@ export class MockService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
|
16
16
|
decoratedItem = await decorateRelation_<B>(store, decoratedItem, {
|
|
17
17
|
market: params.market,
|
|
18
18
|
locale: params.locale,
|
|
19
|
-
depth: params.depth != null ? params.depth :
|
|
19
|
+
depth: params.depth != null ? params.depth : DEFAULT_DEPTH,
|
|
20
20
|
});
|
|
21
21
|
return decoratedItem;
|
|
22
22
|
}
|
|
@@ -28,7 +28,7 @@ export class MockService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
|
28
28
|
decoratedItems = await decorateRelations_<B>(store, decoratedItems, {
|
|
29
29
|
market: params.market,
|
|
30
30
|
locale: params.locale,
|
|
31
|
-
depth: params.depth != null ? params.depth :
|
|
31
|
+
depth: params.depth != null ? params.depth : DEFAULT_DEPTH,
|
|
32
32
|
});
|
|
33
33
|
return decoratedItems;
|
|
34
34
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IEntity, IEquatable, IStore, JsonService, QueryParams, httpGet } from '@websolutespa/bom-core';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_DEPTH, decorateLocalizable_, decorateLocalizables_ } from '../decorators';
|
|
3
3
|
import { IField, MapTo, StaticServiceConfig } from './static';
|
|
4
4
|
|
|
5
5
|
export class StaticService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
@@ -80,7 +80,7 @@ export class StaticService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
export async function decorateStaticRelation_<T>(store: IStore, fields: IField[], item: T, params: QueryParams = {}): Promise<T> {
|
|
83
|
-
const depth = params.depth != null ? params.depth :
|
|
83
|
+
const depth = params.depth != null ? params.depth : DEFAULT_DEPTH;
|
|
84
84
|
if (depth === 0) {
|
|
85
85
|
return item;
|
|
86
86
|
}
|